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
15 * For more information, please consult
18 * SCSI Protocol Controller
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
29 * $Log: mac_NCR5380.c,v $
32 #include <linux/types.h>
33 #include <linux/stddef.h>
34 #include <linux/ctype.h>
35 #include <linux/delay.h>
37 #include <linux/module.h>
38 #include <linux/signal.h>
39 #include <linux/ioport.h>
40 #include <linux/init.h>
41 #include <linux/blkdev.h>
42 #include <linux/interrupt.h>
46 #include <asm/system.h>
48 #include <asm/macintosh.h>
49 #include <asm/macints.h>
50 #include <asm/mac_via.h>
53 #include <scsi/scsi_host.h>
56 /* These control the behaviour of the generic 5380 core */
63 #define NDEBUG (NDEBUG_INTR | NDEBUG_PSEUDO_DMA | NDEBUG_ARBITRATION | NDEBUG_SELECTION | NDEBUG_RESELECTION)
65 #define NDEBUG (NDEBUG_ABORT)
71 extern void via_scsi_clear(void);
74 static void mac_scsi_reset_boot(struct Scsi_Host
*instance
);
77 static int setup_called
= 0;
78 static int setup_can_queue
= -1;
79 static int setup_cmd_per_lun
= -1;
80 static int setup_sg_tablesize
= -1;
81 static int setup_use_pdma
= -1;
83 static int setup_use_tagged_queuing
= -1;
85 static int setup_hostid
= -1;
87 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
88 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
89 * need ten times the standard value... */
93 #define AFTER_RESET_DELAY (5*HZ/2)
95 #define AFTER_RESET_DELAY (HZ/2)
98 static volatile unsigned char *mac_scsi_regp
= NULL
;
99 static volatile unsigned char *mac_scsi_drq
= NULL
;
100 static volatile unsigned char *mac_scsi_nodrq
= NULL
;
104 * NCR 5380 register access functions
109 #define CTRL(p,v) (*ctrl = (v))
111 static char macscsi_read(struct Scsi_Host
*instance
, int reg
)
113 int iobase
= instance
->io_port
;
115 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
118 i
= in_8(iobase
+ (reg
<<4));
124 static void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
126 int iobase
= instance
->io_port
;
127 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
130 out_8(iobase
+ (reg
<<4), value
);
136 static __inline__
char macscsi_read(struct Scsi_Host
*instance
, int reg
)
138 return in_8(instance
->io_port
+ (reg
<<4));
141 static __inline__
void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
143 out_8(instance
->io_port
+ (reg
<<4), value
);
149 * Function : mac_scsi_setup(char *str)
151 * Purpose : booter command line initialization of the overrides array,
153 * Inputs : str - comma delimited list of options
157 static int __init
mac_scsi_setup(char *str
) {
161 (void)get_options( str
, ARRAY_SIZE(ints
), ints
);
163 if (setup_called
++ || ints
[0] < 1 || ints
[0] > 6) {
164 printk(KERN_WARNING
"scsi: <mac5380>"
165 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
166 printk(KERN_ALERT
"scsi: <mac5380> Bad Penguin parameters?\n");
172 /* no limits on this, just > 0 */
173 setup_can_queue
= ints
[1];
177 setup_cmd_per_lun
= ints
[2];
181 setup_sg_tablesize
= ints
[3];
182 /* Must be <= SG_ALL (255) */
183 if (setup_sg_tablesize
> SG_ALL
)
184 setup_sg_tablesize
= SG_ALL
;
188 /* Must be between 0 and 7 */
189 if (ints
[4] >= 0 && ints
[4] <= 7)
190 setup_hostid
= ints
[4];
191 else if (ints
[4] > 7)
192 printk(KERN_WARNING
"mac_scsi_setup: invalid host ID %d !\n", ints
[4] );
197 setup_use_tagged_queuing
= !!ints
[5];
202 setup_use_pdma
= ints
[6];
207 setup_use_pdma
= ints
[5];
209 #endif /* SUPPORT_TAGS */
211 #endif /* DRIVER_SETUP */
215 __setup("mac5380=", mac_scsi_setup
);
218 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
220 * Purpose : initializes mac NCR5380 driver based on the
221 * command line / compile time port and irq definitions.
223 * Inputs : tpnt - template for this SCSI adapter.
225 * Returns : 1 if a host adapter was found, 0 if not.
229 int __init
macscsi_detect(struct scsi_host_template
* tpnt
)
231 static int called
= 0;
233 struct Scsi_Host
*instance
;
235 if (!MACH_IS_MAC
|| called
)
238 if (macintosh_config
->scsi_type
!= MAC_SCSI_OLD
)
241 /* setup variables */
243 (setup_can_queue
> 0) ? setup_can_queue
: CAN_QUEUE
;
245 (setup_cmd_per_lun
> 0) ? setup_cmd_per_lun
: CMD_PER_LUN
;
247 (setup_sg_tablesize
>= 0) ? setup_sg_tablesize
: SG_TABLESIZE
;
249 if (setup_hostid
>= 0)
250 tpnt
->this_id
= setup_hostid
;
252 /* use 7 as default */
257 if (setup_use_tagged_queuing
< 0)
258 setup_use_tagged_queuing
= USE_TAGGED_QUEUING
;
261 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
262 something different here */
263 instance
= scsi_register (tpnt
, sizeof(struct NCR5380_hostdata
));
265 if (macintosh_config
->ident
== MAC_MODEL_IIFX
) {
266 mac_scsi_regp
= via1
+0x8000;
267 mac_scsi_drq
= via1
+0xE000;
268 mac_scsi_nodrq
= via1
+0xC000;
269 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
270 flags
= FLAG_NO_PSEUDO_DMA
;
272 mac_scsi_regp
= via1
+0x10000;
273 mac_scsi_drq
= via1
+0x6000;
274 mac_scsi_nodrq
= via1
+0x12000;
277 if (! setup_use_pdma
)
278 flags
= FLAG_NO_PSEUDO_DMA
;
280 instance
->io_port
= (unsigned long) mac_scsi_regp
;
281 instance
->irq
= IRQ_MAC_SCSI
;
284 mac_scsi_reset_boot(instance
);
287 NCR5380_init(instance
, flags
);
289 instance
->n_io_port
= 255;
291 ((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
= 0;
293 if (instance
->irq
!= SCSI_IRQ_NONE
)
294 if (request_irq(instance
->irq
, NCR5380_intr
, 0, "ncr5380", instance
)) {
295 printk(KERN_WARNING
"scsi%d: IRQ%d not free, interrupts disabled\n",
296 instance
->host_no
, instance
->irq
);
297 instance
->irq
= SCSI_IRQ_NONE
;
300 printk(KERN_INFO
"scsi%d: generic 5380 at port %lX irq", instance
->host_no
, instance
->io_port
);
301 if (instance
->irq
== SCSI_IRQ_NONE
)
302 printk (KERN_INFO
"s disabled");
304 printk (KERN_INFO
" %d", instance
->irq
);
305 printk(KERN_INFO
" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
306 instance
->can_queue
, instance
->cmd_per_lun
, MACSCSI_PUBLIC_RELEASE
);
307 printk(KERN_INFO
"\nscsi%d:", instance
->host_no
);
308 NCR5380_print_options(instance
);
314 int macscsi_release (struct Scsi_Host
*shpnt
)
316 if (shpnt
->irq
!= SCSI_IRQ_NONE
)
317 free_irq(shpnt
->irq
, shpnt
);
325 * Our 'bus reset on boot' function
328 static void mac_scsi_reset_boot(struct Scsi_Host
*instance
)
332 NCR5380_local_declare();
333 NCR5380_setup(instance
);
336 * Do a SCSI reset to clean up the bus during initialization. No messing
337 * with the queues, interrupts, or locks necessary here.
340 printk(KERN_INFO
"Macintosh SCSI: resetting the SCSI bus..." );
342 /* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */
343 disable_irq(IRQ_MAC_SCSI
);
346 NCR5380_write( TARGET_COMMAND_REG
,
347 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG
) ));
350 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
| ICR_ASSERT_RST
);
351 /* The min. reset hold time is 25us, so 40us should be enough */
353 /* reset RST and interrupt */
354 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
);
355 NCR5380_read( RESET_PARITY_INTERRUPT_REG
);
357 for( end
= jiffies
+ AFTER_RESET_DELAY
; time_before(jiffies
, end
); )
360 /* switch on SCSI IRQ again */
361 enable_irq(IRQ_MAC_SCSI
);
363 printk(KERN_INFO
" done\n" );
367 const char * macscsi_info (struct Scsi_Host
*spnt
) {
372 Pseudo-DMA: (Ove Edlund)
373 The code attempts to catch bus errors that occur if one for example
374 "trips over the cable".
375 XXX: Since bus errors in the PDMA routines never happen on my
376 computer, the bus error code is untested.
377 If the code works as intended, a bus error results in Pseudo-DMA
378 beeing disabled, meaning that the driver switches to slow handshake.
379 If bus errors are NOT extremely rare, this has to be changed.
382 #define CP_IO_TO_MEM(s,d,len) \
383 __asm__ __volatile__ \
386 " move.w %1,%%d0\n" \
391 " 1: move.b (%0),(%1)+\n" \
392 " 2: dbf %%d0,1b\n" \
393 " move.w %2,%%d0\n" \
396 " 3: move.l (%0),(%1)+\n" \
397 "31: move.l (%0),(%1)+\n" \
398 "32: move.l (%0),(%1)+\n" \
399 "33: move.l (%0),(%1)+\n" \
400 "34: move.l (%0),(%1)+\n" \
401 "35: move.l (%0),(%1)+\n" \
402 "36: move.l (%0),(%1)+\n" \
403 "37: move.l (%0),(%1)+\n" \
404 " 4: dbf %%d0,3b\n" \
405 " move.w %2,%%d0\n" \
409 " 5: move.l (%0),(%1)+\n" \
410 " 6: dbf %%d0,5b\n" \
413 " 7: move.b (%0),(%1)+\n" \
415 " moveq.l #0, %2\n" \
417 ".section .fixup,\"ax\"\n" \
419 "90: moveq.l #1, %2\n" \
422 ".section __ex_table,\"a\"\n" \
436 : "=a"(s), "=a"(d), "=d"(len) \
437 : "0"(s), "1"(d), "2"(len) \
441 static int macscsi_pread (struct Scsi_Host
*instance
,
442 unsigned char *dst
, int len
)
445 volatile unsigned char *s
;
447 NCR5380_local_declare();
448 NCR5380_setup(instance
);
450 s
= mac_scsi_drq
+0x60;
453 /* These conditions are derived from MacOS */
455 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
456 && !(NCR5380_read(STATUS_REG
) & SR_REQ
))
458 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
459 && (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)) {
460 printk(KERN_ERR
"Error in macscsi_pread\n");
464 CP_IO_TO_MEM(s
, d
, len
);
467 printk(KERN_NOTICE
"Bus error in macscsi_pread\n");
475 #define CP_MEM_TO_IO(s,d,len) \
476 __asm__ __volatile__ \
479 " move.w %0,%%d0\n" \
484 " 1: move.b (%0)+,(%1)\n" \
485 " 2: dbf %%d0,1b\n" \
486 " move.w %2,%%d0\n" \
489 " 3: move.l (%0)+,(%1)\n" \
490 "31: move.l (%0)+,(%1)\n" \
491 "32: move.l (%0)+,(%1)\n" \
492 "33: move.l (%0)+,(%1)\n" \
493 "34: move.l (%0)+,(%1)\n" \
494 "35: move.l (%0)+,(%1)\n" \
495 "36: move.l (%0)+,(%1)\n" \
496 "37: move.l (%0)+,(%1)\n" \
497 " 4: dbf %%d0,3b\n" \
498 " move.w %2,%%d0\n" \
502 " 5: move.l (%0)+,(%1)\n" \
503 " 6: dbf %%d0,5b\n" \
506 " 7: move.b (%0)+,(%1)\n" \
508 " moveq.l #0, %2\n" \
510 ".section .fixup,\"ax\"\n" \
512 "90: moveq.l #1, %2\n" \
515 ".section __ex_table,\"a\"\n" \
529 : "=a"(s), "=a"(d), "=d"(len) \
530 : "0"(s), "1"(d), "2"(len) \
533 static int macscsi_pwrite (struct Scsi_Host
*instance
,
534 unsigned char *src
, int len
)
537 volatile unsigned char *d
;
539 NCR5380_local_declare();
540 NCR5380_setup(instance
);
545 /* These conditions are derived from MacOS */
547 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
548 && (!(NCR5380_read(STATUS_REG
) & SR_REQ
)
549 || (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)))
551 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)) {
552 printk(KERN_ERR
"Error in macscsi_pwrite\n");
556 CP_MEM_TO_IO(s
, d
, len
);
559 printk(KERN_NOTICE
"Bus error in macscsi_pwrite\n");
569 static struct scsi_host_template driver_template
= {
570 .proc_name
= "Mac5380",
571 .proc_info
= macscsi_proc_info
,
572 .name
= "Macintosh NCR5380 SCSI",
573 .detect
= macscsi_detect
,
574 .release
= macscsi_release
,
575 .info
= macscsi_info
,
576 .queuecommand
= macscsi_queue_command
,
577 .eh_abort_handler
= macscsi_abort
,
578 .eh_bus_reset_handler
= macscsi_bus_reset
,
579 .can_queue
= CAN_QUEUE
,
581 .sg_tablesize
= SG_ALL
,
582 .cmd_per_lun
= CMD_PER_LUN
,
583 .use_clustering
= DISABLE_CLUSTERING
587 #include "scsi_module.c"