2 * Generic Macintosh NCR5380 driver
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
6 * derived in part from:
9 * Generic Generic NCR5380 driver
11 * Copyright 1995, Russell King
14 #include <linux/types.h>
15 #include <linux/stddef.h>
16 #include <linux/ctype.h>
17 #include <linux/delay.h>
19 #include <linux/module.h>
20 #include <linux/signal.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <linux/blkdev.h>
24 #include <linux/interrupt.h>
29 #include <asm/macintosh.h>
30 #include <asm/macints.h>
31 #include <asm/mac_via.h>
33 #include <scsi/scsi_host.h>
35 /* Definitions for the core NCR5380 driver. */
39 #define NCR5380_implementation_fields /* none */
40 #define NCR5380_local_declare() struct Scsi_Host *_instance
41 #define NCR5380_setup(instance) _instance = instance
43 #define NCR5380_read(reg) macscsi_read(_instance, reg)
44 #define NCR5380_write(reg, value) macscsi_write(_instance, reg, value)
46 #define NCR5380_pread macscsi_pread
47 #define NCR5380_pwrite macscsi_pwrite
49 #define NCR5380_intr macscsi_intr
50 #define NCR5380_queue_command macscsi_queue_command
51 #define NCR5380_abort macscsi_abort
52 #define NCR5380_bus_reset macscsi_bus_reset
53 #define NCR5380_info macscsi_info
54 #define NCR5380_show_info macscsi_show_info
55 #define NCR5380_write_info macscsi_write_info
62 static void mac_scsi_reset_boot(struct Scsi_Host *instance);
65 static int setup_called = 0;
66 static int setup_can_queue = -1;
67 static int setup_cmd_per_lun = -1;
68 static int setup_sg_tablesize = -1;
69 static int setup_use_pdma = -1;
71 static int setup_use_tagged_queuing = -1;
73 static int setup_hostid = -1;
75 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
76 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
77 * need ten times the standard value... */
81 #define AFTER_RESET_DELAY (5*HZ/2)
83 #define AFTER_RESET_DELAY (HZ/2)
86 static volatile unsigned char *mac_scsi_regp = NULL;
87 static volatile unsigned char *mac_scsi_drq = NULL;
88 static volatile unsigned char *mac_scsi_nodrq = NULL;
92 * NCR 5380 register access functions
95 static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
97 return in_8(instance->io_port + (reg<<4));
100 static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value)
102 out_8(instance->io_port + (reg<<4), value);
106 * Function : mac_scsi_setup(char *str)
108 * Purpose : booter command line initialization of the overrides array,
110 * Inputs : str - comma delimited list of options
114 static int __init mac_scsi_setup(char *str) {
117 (void)get_options( str, ARRAY_SIZE(ints), ints);
119 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
120 printk(KERN_WARNING "scsi: <mac5380>"
121 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
122 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
128 /* no limits on this, just > 0 */
129 setup_can_queue = ints[1];
133 setup_cmd_per_lun = ints[2];
137 setup_sg_tablesize = ints[3];
138 /* Must be <= SG_ALL (255) */
139 if (setup_sg_tablesize > SG_ALL)
140 setup_sg_tablesize = SG_ALL;
144 /* Must be between 0 and 7 */
145 if (ints[4] >= 0 && ints[4] <= 7)
146 setup_hostid = ints[4];
147 else if (ints[4] > 7)
148 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
153 setup_use_tagged_queuing = !!ints[5];
158 setup_use_pdma = ints[6];
163 setup_use_pdma = ints[5];
165 #endif /* SUPPORT_TAGS */
170 __setup("mac5380=", mac_scsi_setup);
173 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
175 * Purpose : initializes mac NCR5380 driver based on the
176 * command line / compile time port and irq definitions.
178 * Inputs : tpnt - template for this SCSI adapter.
180 * Returns : 1 if a host adapter was found, 0 if not.
184 int __init macscsi_detect(struct scsi_host_template * tpnt)
186 static int called = 0;
188 struct Scsi_Host *instance;
190 if (!MACH_IS_MAC || called)
193 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
196 if (setup_can_queue > 0)
197 tpnt->can_queue = setup_can_queue;
198 if (setup_cmd_per_lun > 0)
199 tpnt->cmd_per_lun = setup_cmd_per_lun;
200 if (setup_sg_tablesize >= 0)
201 tpnt->sg_tablesize = setup_sg_tablesize;
203 if (setup_hostid >= 0)
204 tpnt->this_id = setup_hostid;
206 /* use 7 as default */
211 if (setup_use_tagged_queuing < 0)
212 setup_use_tagged_queuing = 0;
215 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
216 something different here */
217 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
218 if (instance == NULL)
221 if (macintosh_config->ident == MAC_MODEL_IIFX) {
222 mac_scsi_regp = via1+0x8000;
223 mac_scsi_drq = via1+0xE000;
224 mac_scsi_nodrq = via1+0xC000;
225 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
226 flags = FLAG_NO_PSEUDO_DMA;
228 mac_scsi_regp = via1+0x10000;
229 mac_scsi_drq = via1+0x6000;
230 mac_scsi_nodrq = via1+0x12000;
233 if (! setup_use_pdma)
234 flags = FLAG_NO_PSEUDO_DMA;
236 instance->io_port = (unsigned long) mac_scsi_regp;
237 instance->irq = IRQ_MAC_SCSI;
240 mac_scsi_reset_boot(instance);
243 NCR5380_init(instance, flags);
245 instance->n_io_port = 255;
247 if (instance->irq != NO_IRQ)
248 if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) {
249 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
250 instance->host_no, instance->irq);
251 instance->irq = NO_IRQ;
258 int macscsi_release (struct Scsi_Host *shpnt)
260 if (shpnt->irq != NO_IRQ)
261 free_irq(shpnt->irq, shpnt);
269 * Our 'bus reset on boot' function
272 static void mac_scsi_reset_boot(struct Scsi_Host *instance)
276 NCR5380_local_declare();
277 NCR5380_setup(instance);
280 * Do a SCSI reset to clean up the bus during initialization. No messing
281 * with the queues, interrupts, or locks necessary here.
284 printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." );
287 NCR5380_write( TARGET_COMMAND_REG,
288 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
291 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
292 /* The min. reset hold time is 25us, so 40us should be enough */
294 /* reset RST and interrupt */
295 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
296 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
298 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
301 printk(KERN_INFO " done\n" );
306 Pseudo-DMA: (Ove Edlund)
307 The code attempts to catch bus errors that occur if one for example
308 "trips over the cable".
309 XXX: Since bus errors in the PDMA routines never happen on my
310 computer, the bus error code is untested.
311 If the code works as intended, a bus error results in Pseudo-DMA
312 beeing disabled, meaning that the driver switches to slow handshake.
313 If bus errors are NOT extremely rare, this has to be changed.
316 #define CP_IO_TO_MEM(s,d,len) \
317 __asm__ __volatile__ \
320 " move.w %1,%%d0\n" \
325 " 1: move.b (%0),(%1)+\n" \
326 " 2: dbf %%d0,1b\n" \
327 " move.w %2,%%d0\n" \
330 " 3: move.l (%0),(%1)+\n" \
331 "31: move.l (%0),(%1)+\n" \
332 "32: move.l (%0),(%1)+\n" \
333 "33: move.l (%0),(%1)+\n" \
334 "34: move.l (%0),(%1)+\n" \
335 "35: move.l (%0),(%1)+\n" \
336 "36: move.l (%0),(%1)+\n" \
337 "37: move.l (%0),(%1)+\n" \
338 " 4: dbf %%d0,3b\n" \
339 " move.w %2,%%d0\n" \
343 " 5: move.l (%0),(%1)+\n" \
344 " 6: dbf %%d0,5b\n" \
347 " 7: move.b (%0),(%1)+\n" \
349 " moveq.l #0, %2\n" \
351 ".section .fixup,\"ax\"\n" \
353 "90: moveq.l #1, %2\n" \
356 ".section __ex_table,\"a\"\n" \
370 : "=a"(s), "=a"(d), "=d"(len) \
371 : "0"(s), "1"(d), "2"(len) \
375 static int macscsi_pread (struct Scsi_Host *instance,
376 unsigned char *dst, int len)
379 volatile unsigned char *s;
381 NCR5380_local_declare();
382 NCR5380_setup(instance);
384 s = mac_scsi_drq+0x60;
387 /* These conditions are derived from MacOS */
389 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
390 && !(NCR5380_read(STATUS_REG) & SR_REQ))
392 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
393 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
394 printk(KERN_ERR "Error in macscsi_pread\n");
398 CP_IO_TO_MEM(s, d, len);
401 printk(KERN_NOTICE "Bus error in macscsi_pread\n");
409 #define CP_MEM_TO_IO(s,d,len) \
410 __asm__ __volatile__ \
413 " move.w %0,%%d0\n" \
418 " 1: move.b (%0)+,(%1)\n" \
419 " 2: dbf %%d0,1b\n" \
420 " move.w %2,%%d0\n" \
423 " 3: move.l (%0)+,(%1)\n" \
424 "31: move.l (%0)+,(%1)\n" \
425 "32: move.l (%0)+,(%1)\n" \
426 "33: move.l (%0)+,(%1)\n" \
427 "34: move.l (%0)+,(%1)\n" \
428 "35: move.l (%0)+,(%1)\n" \
429 "36: move.l (%0)+,(%1)\n" \
430 "37: move.l (%0)+,(%1)\n" \
431 " 4: dbf %%d0,3b\n" \
432 " move.w %2,%%d0\n" \
436 " 5: move.l (%0)+,(%1)\n" \
437 " 6: dbf %%d0,5b\n" \
440 " 7: move.b (%0)+,(%1)\n" \
442 " moveq.l #0, %2\n" \
444 ".section .fixup,\"ax\"\n" \
446 "90: moveq.l #1, %2\n" \
449 ".section __ex_table,\"a\"\n" \
463 : "=a"(s), "=a"(d), "=d"(len) \
464 : "0"(s), "1"(d), "2"(len) \
467 static int macscsi_pwrite (struct Scsi_Host *instance,
468 unsigned char *src, int len)
471 volatile unsigned char *d;
473 NCR5380_local_declare();
474 NCR5380_setup(instance);
479 /* These conditions are derived from MacOS */
481 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
482 && (!(NCR5380_read(STATUS_REG) & SR_REQ)
483 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
485 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
486 printk(KERN_ERR "Error in macscsi_pwrite\n");
490 CP_MEM_TO_IO(s, d, len);
493 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n");
503 static struct scsi_host_template driver_template = {
504 .proc_name = "Mac5380",
505 .show_info = macscsi_show_info,
506 .write_info = macscsi_write_info,
507 .name = "Macintosh NCR5380 SCSI",
508 .detect = macscsi_detect,
509 .release = macscsi_release,
510 .info = macscsi_info,
511 .queuecommand = macscsi_queue_command,
512 .eh_abort_handler = macscsi_abort,
513 .eh_bus_reset_handler = macscsi_bus_reset,
516 .sg_tablesize = SG_ALL,
518 .use_clustering = DISABLE_CLUSTERING
522 #include "scsi_module.c"