2 * Generic Macintosh NCR5380 driver
6 * derived in part from:
9 * Generic Generic NCR5380 driver
11 * Copyright 1995, Russell King
15 * For more information, please consult
18 * SCSI Protocol Controller
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
28 #include <linux/types.h>
29 #include <linux/stddef.h>
30 #include <linux/ctype.h>
31 #include <linux/delay.h>
33 #include <linux/module.h>
34 #include <linux/signal.h>
35 #include <linux/ioport.h>
36 #include <linux/init.h>
37 #include <linux/blkdev.h>
38 #include <linux/interrupt.h>
43 #include <asm/macintosh.h>
44 #include <asm/macints.h>
45 #include <asm/mac_via.h>
48 #include <scsi/scsi_host.h>
51 /* These control the behaviour of the generic 5380 core */
60 extern void via_scsi_clear(void);
63 static void mac_scsi_reset_boot(struct Scsi_Host *instance);
66 static int setup_called = 0;
67 static int setup_can_queue = -1;
68 static int setup_cmd_per_lun = -1;
69 static int setup_sg_tablesize = -1;
70 static int setup_use_pdma = -1;
72 static int setup_use_tagged_queuing = -1;
74 static int setup_hostid = -1;
76 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
77 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
78 * need ten times the standard value... */
82 #define AFTER_RESET_DELAY (5*HZ/2)
84 #define AFTER_RESET_DELAY (HZ/2)
87 static volatile unsigned char *mac_scsi_regp = NULL;
88 static volatile unsigned char *mac_scsi_drq = NULL;
89 static volatile unsigned char *mac_scsi_nodrq = NULL;
93 * NCR 5380 register access functions
98 #define CTRL(p,v) (*ctrl = (v))
100 static char macscsi_read(struct Scsi_Host *instance, int reg)
102 int iobase = instance->io_port;
104 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
107 i = in_8(iobase + (reg<<4));
113 static void macscsi_write(struct Scsi_Host *instance, int reg, int value)
115 int iobase = instance->io_port;
116 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
119 out_8(iobase + (reg<<4), value);
125 static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
127 return in_8(instance->io_port + (reg<<4));
130 static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value)
132 out_8(instance->io_port + (reg<<4), value);
138 * Function : mac_scsi_setup(char *str)
140 * Purpose : booter command line initialization of the overrides array,
142 * Inputs : str - comma delimited list of options
146 static int __init mac_scsi_setup(char *str) {
150 (void)get_options( str, ARRAY_SIZE(ints), ints);
152 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
153 printk(KERN_WARNING "scsi: <mac5380>"
154 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
155 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
161 /* no limits on this, just > 0 */
162 setup_can_queue = ints[1];
166 setup_cmd_per_lun = ints[2];
170 setup_sg_tablesize = ints[3];
171 /* Must be <= SG_ALL (255) */
172 if (setup_sg_tablesize > SG_ALL)
173 setup_sg_tablesize = SG_ALL;
177 /* Must be between 0 and 7 */
178 if (ints[4] >= 0 && ints[4] <= 7)
179 setup_hostid = ints[4];
180 else if (ints[4] > 7)
181 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
186 setup_use_tagged_queuing = !!ints[5];
191 setup_use_pdma = ints[6];
196 setup_use_pdma = ints[5];
198 #endif /* SUPPORT_TAGS */
200 #endif /* DRIVER_SETUP */
204 __setup("mac5380=", mac_scsi_setup);
207 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
209 * Purpose : initializes mac NCR5380 driver based on the
210 * command line / compile time port and irq definitions.
212 * Inputs : tpnt - template for this SCSI adapter.
214 * Returns : 1 if a host adapter was found, 0 if not.
218 int __init macscsi_detect(struct scsi_host_template * tpnt)
220 static int called = 0;
222 struct Scsi_Host *instance;
224 if (!MACH_IS_MAC || called)
227 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
230 /* setup variables */
232 (setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
234 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
236 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
238 if (setup_hostid >= 0)
239 tpnt->this_id = setup_hostid;
241 /* use 7 as default */
246 if (setup_use_tagged_queuing < 0)
247 setup_use_tagged_queuing = USE_TAGGED_QUEUING;
250 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
251 something different here */
252 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
253 if (instance == NULL)
256 if (macintosh_config->ident == MAC_MODEL_IIFX) {
257 mac_scsi_regp = via1+0x8000;
258 mac_scsi_drq = via1+0xE000;
259 mac_scsi_nodrq = via1+0xC000;
260 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
261 flags = FLAG_NO_PSEUDO_DMA;
263 mac_scsi_regp = via1+0x10000;
264 mac_scsi_drq = via1+0x6000;
265 mac_scsi_nodrq = via1+0x12000;
268 if (! setup_use_pdma)
269 flags = FLAG_NO_PSEUDO_DMA;
271 instance->io_port = (unsigned long) mac_scsi_regp;
272 instance->irq = IRQ_MAC_SCSI;
275 mac_scsi_reset_boot(instance);
278 NCR5380_init(instance, flags);
280 instance->n_io_port = 255;
282 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
284 if (instance->irq != SCSI_IRQ_NONE)
285 if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) {
286 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
287 instance->host_no, instance->irq);
288 instance->irq = SCSI_IRQ_NONE;
291 printk(KERN_INFO "scsi%d: generic 5380 at port %lX irq", instance->host_no, instance->io_port);
292 if (instance->irq == SCSI_IRQ_NONE)
293 printk (KERN_INFO "s disabled");
295 printk (KERN_INFO " %d", instance->irq);
296 printk(KERN_INFO " options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
297 instance->can_queue, instance->cmd_per_lun, MACSCSI_PUBLIC_RELEASE);
298 printk(KERN_INFO "\nscsi%d:", instance->host_no);
299 NCR5380_print_options(instance);
305 int macscsi_release (struct Scsi_Host *shpnt)
307 if (shpnt->irq != SCSI_IRQ_NONE)
308 free_irq(shpnt->irq, shpnt);
316 * Our 'bus reset on boot' function
319 static void mac_scsi_reset_boot(struct Scsi_Host *instance)
323 NCR5380_local_declare();
324 NCR5380_setup(instance);
327 * Do a SCSI reset to clean up the bus during initialization. No messing
328 * with the queues, interrupts, or locks necessary here.
331 printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." );
334 NCR5380_write( TARGET_COMMAND_REG,
335 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
338 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
339 /* The min. reset hold time is 25us, so 40us should be enough */
341 /* reset RST and interrupt */
342 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
343 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
345 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
348 printk(KERN_INFO " done\n" );
352 const char * macscsi_info (struct Scsi_Host *spnt) {
357 Pseudo-DMA: (Ove Edlund)
358 The code attempts to catch bus errors that occur if one for example
359 "trips over the cable".
360 XXX: Since bus errors in the PDMA routines never happen on my
361 computer, the bus error code is untested.
362 If the code works as intended, a bus error results in Pseudo-DMA
363 beeing disabled, meaning that the driver switches to slow handshake.
364 If bus errors are NOT extremely rare, this has to be changed.
367 #define CP_IO_TO_MEM(s,d,len) \
368 __asm__ __volatile__ \
371 " move.w %1,%%d0\n" \
376 " 1: move.b (%0),(%1)+\n" \
377 " 2: dbf %%d0,1b\n" \
378 " move.w %2,%%d0\n" \
381 " 3: move.l (%0),(%1)+\n" \
382 "31: move.l (%0),(%1)+\n" \
383 "32: move.l (%0),(%1)+\n" \
384 "33: move.l (%0),(%1)+\n" \
385 "34: move.l (%0),(%1)+\n" \
386 "35: move.l (%0),(%1)+\n" \
387 "36: move.l (%0),(%1)+\n" \
388 "37: move.l (%0),(%1)+\n" \
389 " 4: dbf %%d0,3b\n" \
390 " move.w %2,%%d0\n" \
394 " 5: move.l (%0),(%1)+\n" \
395 " 6: dbf %%d0,5b\n" \
398 " 7: move.b (%0),(%1)+\n" \
400 " moveq.l #0, %2\n" \
402 ".section .fixup,\"ax\"\n" \
404 "90: moveq.l #1, %2\n" \
407 ".section __ex_table,\"a\"\n" \
421 : "=a"(s), "=a"(d), "=d"(len) \
422 : "0"(s), "1"(d), "2"(len) \
426 static int macscsi_pread (struct Scsi_Host *instance,
427 unsigned char *dst, int len)
430 volatile unsigned char *s;
432 NCR5380_local_declare();
433 NCR5380_setup(instance);
435 s = mac_scsi_drq+0x60;
438 /* These conditions are derived from MacOS */
440 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
441 && !(NCR5380_read(STATUS_REG) & SR_REQ))
443 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
444 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
445 printk(KERN_ERR "Error in macscsi_pread\n");
449 CP_IO_TO_MEM(s, d, len);
452 printk(KERN_NOTICE "Bus error in macscsi_pread\n");
460 #define CP_MEM_TO_IO(s,d,len) \
461 __asm__ __volatile__ \
464 " move.w %0,%%d0\n" \
469 " 1: move.b (%0)+,(%1)\n" \
470 " 2: dbf %%d0,1b\n" \
471 " move.w %2,%%d0\n" \
474 " 3: move.l (%0)+,(%1)\n" \
475 "31: move.l (%0)+,(%1)\n" \
476 "32: move.l (%0)+,(%1)\n" \
477 "33: move.l (%0)+,(%1)\n" \
478 "34: move.l (%0)+,(%1)\n" \
479 "35: move.l (%0)+,(%1)\n" \
480 "36: move.l (%0)+,(%1)\n" \
481 "37: move.l (%0)+,(%1)\n" \
482 " 4: dbf %%d0,3b\n" \
483 " move.w %2,%%d0\n" \
487 " 5: move.l (%0)+,(%1)\n" \
488 " 6: dbf %%d0,5b\n" \
491 " 7: move.b (%0)+,(%1)\n" \
493 " moveq.l #0, %2\n" \
495 ".section .fixup,\"ax\"\n" \
497 "90: moveq.l #1, %2\n" \
500 ".section __ex_table,\"a\"\n" \
514 : "=a"(s), "=a"(d), "=d"(len) \
515 : "0"(s), "1"(d), "2"(len) \
518 static int macscsi_pwrite (struct Scsi_Host *instance,
519 unsigned char *src, int len)
522 volatile unsigned char *d;
524 NCR5380_local_declare();
525 NCR5380_setup(instance);
530 /* These conditions are derived from MacOS */
532 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
533 && (!(NCR5380_read(STATUS_REG) & SR_REQ)
534 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
536 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
537 printk(KERN_ERR "Error in macscsi_pwrite\n");
541 CP_MEM_TO_IO(s, d, len);
544 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n");
554 static struct scsi_host_template driver_template = {
555 .proc_name = "Mac5380",
556 .show_info = macscsi_show_info,
557 .write_info = macscsi_write_info,
558 .name = "Macintosh NCR5380 SCSI",
559 .detect = macscsi_detect,
560 .release = macscsi_release,
561 .info = macscsi_info,
562 .queuecommand = macscsi_queue_command,
563 .eh_abort_handler = macscsi_abort,
564 .eh_bus_reset_handler = macscsi_bus_reset,
565 .can_queue = CAN_QUEUE,
567 .sg_tablesize = SG_ALL,
568 .cmd_per_lun = CMD_PER_LUN,
569 .use_clustering = DISABLE_CLUSTERING
573 #include "scsi_module.c"