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
16 #include <linux/types.h>
17 #include <linux/stddef.h>
18 #include <linux/ctype.h>
19 #include <linux/delay.h>
21 #include <linux/module.h>
22 #include <linux/signal.h>
23 #include <linux/ioport.h>
24 #include <linux/init.h>
25 #include <linux/blkdev.h>
26 #include <linux/interrupt.h>
31 #include <asm/macintosh.h>
32 #include <asm/macints.h>
33 #include <asm/mac_via.h>
36 #include <scsi/scsi_host.h>
46 static void mac_scsi_reset_boot(struct Scsi_Host *instance);
49 static int setup_called = 0;
50 static int setup_can_queue = -1;
51 static int setup_cmd_per_lun = -1;
52 static int setup_sg_tablesize = -1;
53 static int setup_use_pdma = -1;
55 static int setup_use_tagged_queuing = -1;
57 static int setup_hostid = -1;
59 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
60 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
61 * need ten times the standard value... */
65 #define AFTER_RESET_DELAY (5*HZ/2)
67 #define AFTER_RESET_DELAY (HZ/2)
70 static volatile unsigned char *mac_scsi_regp = NULL;
71 static volatile unsigned char *mac_scsi_drq = NULL;
72 static volatile unsigned char *mac_scsi_nodrq = NULL;
76 * NCR 5380 register access functions
79 static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
81 return in_8(instance->io_port + (reg<<4));
84 static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value)
86 out_8(instance->io_port + (reg<<4), value);
90 * Function : mac_scsi_setup(char *str)
92 * Purpose : booter command line initialization of the overrides array,
94 * Inputs : str - comma delimited list of options
98 static int __init mac_scsi_setup(char *str) {
101 (void)get_options( str, ARRAY_SIZE(ints), ints);
103 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
104 printk(KERN_WARNING "scsi: <mac5380>"
105 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
106 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
112 /* no limits on this, just > 0 */
113 setup_can_queue = ints[1];
117 setup_cmd_per_lun = ints[2];
121 setup_sg_tablesize = ints[3];
122 /* Must be <= SG_ALL (255) */
123 if (setup_sg_tablesize > SG_ALL)
124 setup_sg_tablesize = SG_ALL;
128 /* Must be between 0 and 7 */
129 if (ints[4] >= 0 && ints[4] <= 7)
130 setup_hostid = ints[4];
131 else if (ints[4] > 7)
132 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
137 setup_use_tagged_queuing = !!ints[5];
142 setup_use_pdma = ints[6];
147 setup_use_pdma = ints[5];
149 #endif /* SUPPORT_TAGS */
154 __setup("mac5380=", mac_scsi_setup);
157 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
159 * Purpose : initializes mac NCR5380 driver based on the
160 * command line / compile time port and irq definitions.
162 * Inputs : tpnt - template for this SCSI adapter.
164 * Returns : 1 if a host adapter was found, 0 if not.
168 int __init macscsi_detect(struct scsi_host_template * tpnt)
170 static int called = 0;
172 struct Scsi_Host *instance;
174 if (!MACH_IS_MAC || called)
177 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
180 if (setup_can_queue > 0)
181 tpnt->can_queue = setup_can_queue;
182 if (setup_cmd_per_lun > 0)
183 tpnt->cmd_per_lun = setup_cmd_per_lun;
184 if (setup_sg_tablesize >= 0)
185 tpnt->sg_tablesize = setup_sg_tablesize;
187 if (setup_hostid >= 0)
188 tpnt->this_id = setup_hostid;
190 /* use 7 as default */
195 if (setup_use_tagged_queuing < 0)
196 setup_use_tagged_queuing = 0;
199 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
200 something different here */
201 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
202 if (instance == NULL)
205 if (macintosh_config->ident == MAC_MODEL_IIFX) {
206 mac_scsi_regp = via1+0x8000;
207 mac_scsi_drq = via1+0xE000;
208 mac_scsi_nodrq = via1+0xC000;
209 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
210 flags = FLAG_NO_PSEUDO_DMA;
212 mac_scsi_regp = via1+0x10000;
213 mac_scsi_drq = via1+0x6000;
214 mac_scsi_nodrq = via1+0x12000;
217 if (! setup_use_pdma)
218 flags = FLAG_NO_PSEUDO_DMA;
220 instance->io_port = (unsigned long) mac_scsi_regp;
221 instance->irq = IRQ_MAC_SCSI;
224 mac_scsi_reset_boot(instance);
227 NCR5380_init(instance, flags);
229 instance->n_io_port = 255;
231 if (instance->irq != NO_IRQ)
232 if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) {
233 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
234 instance->host_no, instance->irq);
235 instance->irq = NO_IRQ;
242 int macscsi_release (struct Scsi_Host *shpnt)
244 if (shpnt->irq != NO_IRQ)
245 free_irq(shpnt->irq, shpnt);
253 * Our 'bus reset on boot' function
256 static void mac_scsi_reset_boot(struct Scsi_Host *instance)
260 NCR5380_local_declare();
261 NCR5380_setup(instance);
264 * Do a SCSI reset to clean up the bus during initialization. No messing
265 * with the queues, interrupts, or locks necessary here.
268 printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." );
271 NCR5380_write( TARGET_COMMAND_REG,
272 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
275 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
276 /* The min. reset hold time is 25us, so 40us should be enough */
278 /* reset RST and interrupt */
279 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
280 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
282 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
285 printk(KERN_INFO " done\n" );
290 Pseudo-DMA: (Ove Edlund)
291 The code attempts to catch bus errors that occur if one for example
292 "trips over the cable".
293 XXX: Since bus errors in the PDMA routines never happen on my
294 computer, the bus error code is untested.
295 If the code works as intended, a bus error results in Pseudo-DMA
296 beeing disabled, meaning that the driver switches to slow handshake.
297 If bus errors are NOT extremely rare, this has to be changed.
300 #define CP_IO_TO_MEM(s,d,len) \
301 __asm__ __volatile__ \
304 " move.w %1,%%d0\n" \
309 " 1: move.b (%0),(%1)+\n" \
310 " 2: dbf %%d0,1b\n" \
311 " move.w %2,%%d0\n" \
314 " 3: move.l (%0),(%1)+\n" \
315 "31: move.l (%0),(%1)+\n" \
316 "32: move.l (%0),(%1)+\n" \
317 "33: move.l (%0),(%1)+\n" \
318 "34: move.l (%0),(%1)+\n" \
319 "35: move.l (%0),(%1)+\n" \
320 "36: move.l (%0),(%1)+\n" \
321 "37: move.l (%0),(%1)+\n" \
322 " 4: dbf %%d0,3b\n" \
323 " move.w %2,%%d0\n" \
327 " 5: move.l (%0),(%1)+\n" \
328 " 6: dbf %%d0,5b\n" \
331 " 7: move.b (%0),(%1)+\n" \
333 " moveq.l #0, %2\n" \
335 ".section .fixup,\"ax\"\n" \
337 "90: moveq.l #1, %2\n" \
340 ".section __ex_table,\"a\"\n" \
354 : "=a"(s), "=a"(d), "=d"(len) \
355 : "0"(s), "1"(d), "2"(len) \
359 static int macscsi_pread (struct Scsi_Host *instance,
360 unsigned char *dst, int len)
363 volatile unsigned char *s;
365 NCR5380_local_declare();
366 NCR5380_setup(instance);
368 s = mac_scsi_drq+0x60;
371 /* These conditions are derived from MacOS */
373 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
374 && !(NCR5380_read(STATUS_REG) & SR_REQ))
376 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
377 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
378 printk(KERN_ERR "Error in macscsi_pread\n");
382 CP_IO_TO_MEM(s, d, len);
385 printk(KERN_NOTICE "Bus error in macscsi_pread\n");
393 #define CP_MEM_TO_IO(s,d,len) \
394 __asm__ __volatile__ \
397 " move.w %0,%%d0\n" \
402 " 1: move.b (%0)+,(%1)\n" \
403 " 2: dbf %%d0,1b\n" \
404 " move.w %2,%%d0\n" \
407 " 3: move.l (%0)+,(%1)\n" \
408 "31: move.l (%0)+,(%1)\n" \
409 "32: move.l (%0)+,(%1)\n" \
410 "33: move.l (%0)+,(%1)\n" \
411 "34: move.l (%0)+,(%1)\n" \
412 "35: move.l (%0)+,(%1)\n" \
413 "36: move.l (%0)+,(%1)\n" \
414 "37: move.l (%0)+,(%1)\n" \
415 " 4: dbf %%d0,3b\n" \
416 " move.w %2,%%d0\n" \
420 " 5: move.l (%0)+,(%1)\n" \
421 " 6: dbf %%d0,5b\n" \
424 " 7: move.b (%0)+,(%1)\n" \
426 " moveq.l #0, %2\n" \
428 ".section .fixup,\"ax\"\n" \
430 "90: moveq.l #1, %2\n" \
433 ".section __ex_table,\"a\"\n" \
447 : "=a"(s), "=a"(d), "=d"(len) \
448 : "0"(s), "1"(d), "2"(len) \
451 static int macscsi_pwrite (struct Scsi_Host *instance,
452 unsigned char *src, int len)
455 volatile unsigned char *d;
457 NCR5380_local_declare();
458 NCR5380_setup(instance);
463 /* These conditions are derived from MacOS */
465 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
466 && (!(NCR5380_read(STATUS_REG) & SR_REQ)
467 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
469 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
470 printk(KERN_ERR "Error in macscsi_pwrite\n");
474 CP_MEM_TO_IO(s, d, len);
477 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n");
487 static struct scsi_host_template driver_template = {
488 .proc_name = "Mac5380",
489 .show_info = macscsi_show_info,
490 .write_info = macscsi_write_info,
491 .name = "Macintosh NCR5380 SCSI",
492 .detect = macscsi_detect,
493 .release = macscsi_release,
494 .info = macscsi_info,
495 .queuecommand = macscsi_queue_command,
496 .eh_abort_handler = macscsi_abort,
497 .eh_bus_reset_handler = macscsi_bus_reset,
500 .sg_tablesize = SG_ALL,
502 .use_clustering = DISABLE_CLUSTERING
506 #include "scsi_module.c"