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>
47 #include <asm/macintosh.h>
48 #include <asm/macints.h>
49 #include <asm/mac_via.h>
52 #include <scsi/scsi_host.h>
55 /* These control the behaviour of the generic 5380 core */
62 #define NDEBUG (NDEBUG_INTR | NDEBUG_PSEUDO_DMA | NDEBUG_ARBITRATION | NDEBUG_SELECTION | NDEBUG_RESELECTION)
64 #define NDEBUG (NDEBUG_ABORT)
70 extern void via_scsi_clear(void);
73 static void mac_scsi_reset_boot(struct Scsi_Host
*instance
);
76 static int setup_called
= 0;
77 static int setup_can_queue
= -1;
78 static int setup_cmd_per_lun
= -1;
79 static int setup_sg_tablesize
= -1;
80 static int setup_use_pdma
= -1;
82 static int setup_use_tagged_queuing
= -1;
84 static int setup_hostid
= -1;
86 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
87 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
88 * need ten times the standard value... */
92 #define AFTER_RESET_DELAY (5*HZ/2)
94 #define AFTER_RESET_DELAY (HZ/2)
97 static volatile unsigned char *mac_scsi_regp
= NULL
;
98 static volatile unsigned char *mac_scsi_drq
= NULL
;
99 static volatile unsigned char *mac_scsi_nodrq
= NULL
;
103 * NCR 5380 register access functions
108 #define CTRL(p,v) (*ctrl = (v))
110 static char macscsi_read(struct Scsi_Host
*instance
, int reg
)
112 int iobase
= instance
->io_port
;
114 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
117 i
= in_8(iobase
+ (reg
<<4));
123 static void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
125 int iobase
= instance
->io_port
;
126 int *ctrl
= &((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
;
129 out_8(iobase
+ (reg
<<4), value
);
135 static __inline__
char macscsi_read(struct Scsi_Host
*instance
, int reg
)
137 return in_8(instance
->io_port
+ (reg
<<4));
140 static __inline__
void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
142 out_8(instance
->io_port
+ (reg
<<4), value
);
148 * Function : mac_scsi_setup(char *str)
150 * Purpose : booter command line initialization of the overrides array,
152 * Inputs : str - comma delimited list of options
156 static int __init
mac_scsi_setup(char *str
) {
160 (void)get_options( str
, ARRAY_SIZE(ints
), ints
);
162 if (setup_called
++ || ints
[0] < 1 || ints
[0] > 6) {
163 printk(KERN_WARNING
"scsi: <mac5380>"
164 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
165 printk(KERN_ALERT
"scsi: <mac5380> Bad Penguin parameters?\n");
171 /* no limits on this, just > 0 */
172 setup_can_queue
= ints
[1];
176 setup_cmd_per_lun
= ints
[2];
180 setup_sg_tablesize
= ints
[3];
181 /* Must be <= SG_ALL (255) */
182 if (setup_sg_tablesize
> SG_ALL
)
183 setup_sg_tablesize
= SG_ALL
;
187 /* Must be between 0 and 7 */
188 if (ints
[4] >= 0 && ints
[4] <= 7)
189 setup_hostid
= ints
[4];
190 else if (ints
[4] > 7)
191 printk(KERN_WARNING
"mac_scsi_setup: invalid host ID %d !\n", ints
[4] );
196 setup_use_tagged_queuing
= !!ints
[5];
201 setup_use_pdma
= ints
[6];
206 setup_use_pdma
= ints
[5];
208 #endif /* SUPPORT_TAGS */
210 #endif /* DRIVER_SETUP */
214 __setup("mac5380=", mac_scsi_setup
);
217 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
219 * Purpose : initializes mac NCR5380 driver based on the
220 * command line / compile time port and irq definitions.
222 * Inputs : tpnt - template for this SCSI adapter.
224 * Returns : 1 if a host adapter was found, 0 if not.
228 int __init
macscsi_detect(struct scsi_host_template
* tpnt
)
230 static int called
= 0;
232 struct Scsi_Host
*instance
;
234 if (!MACH_IS_MAC
|| called
)
237 if (macintosh_config
->scsi_type
!= MAC_SCSI_OLD
)
240 /* setup variables */
242 (setup_can_queue
> 0) ? setup_can_queue
: CAN_QUEUE
;
244 (setup_cmd_per_lun
> 0) ? setup_cmd_per_lun
: CMD_PER_LUN
;
246 (setup_sg_tablesize
>= 0) ? setup_sg_tablesize
: SG_TABLESIZE
;
248 if (setup_hostid
>= 0)
249 tpnt
->this_id
= setup_hostid
;
251 /* use 7 as default */
256 if (setup_use_tagged_queuing
< 0)
257 setup_use_tagged_queuing
= USE_TAGGED_QUEUING
;
260 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
261 something different here */
262 instance
= scsi_register (tpnt
, sizeof(struct NCR5380_hostdata
));
263 if (instance
== NULL
)
266 if (macintosh_config
->ident
== MAC_MODEL_IIFX
) {
267 mac_scsi_regp
= via1
+0x8000;
268 mac_scsi_drq
= via1
+0xE000;
269 mac_scsi_nodrq
= via1
+0xC000;
270 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
271 flags
= FLAG_NO_PSEUDO_DMA
;
273 mac_scsi_regp
= via1
+0x10000;
274 mac_scsi_drq
= via1
+0x6000;
275 mac_scsi_nodrq
= via1
+0x12000;
278 if (! setup_use_pdma
)
279 flags
= FLAG_NO_PSEUDO_DMA
;
281 instance
->io_port
= (unsigned long) mac_scsi_regp
;
282 instance
->irq
= IRQ_MAC_SCSI
;
285 mac_scsi_reset_boot(instance
);
288 NCR5380_init(instance
, flags
);
290 instance
->n_io_port
= 255;
292 ((struct NCR5380_hostdata
*)instance
->hostdata
)->ctrl
= 0;
294 if (instance
->irq
!= SCSI_IRQ_NONE
)
295 if (request_irq(instance
->irq
, NCR5380_intr
, 0, "ncr5380", instance
)) {
296 printk(KERN_WARNING
"scsi%d: IRQ%d not free, interrupts disabled\n",
297 instance
->host_no
, instance
->irq
);
298 instance
->irq
= SCSI_IRQ_NONE
;
301 printk(KERN_INFO
"scsi%d: generic 5380 at port %lX irq", instance
->host_no
, instance
->io_port
);
302 if (instance
->irq
== SCSI_IRQ_NONE
)
303 printk (KERN_INFO
"s disabled");
305 printk (KERN_INFO
" %d", instance
->irq
);
306 printk(KERN_INFO
" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
307 instance
->can_queue
, instance
->cmd_per_lun
, MACSCSI_PUBLIC_RELEASE
);
308 printk(KERN_INFO
"\nscsi%d:", instance
->host_no
);
309 NCR5380_print_options(instance
);
315 int macscsi_release (struct Scsi_Host
*shpnt
)
317 if (shpnt
->irq
!= SCSI_IRQ_NONE
)
318 free_irq(shpnt
->irq
, shpnt
);
326 * Our 'bus reset on boot' function
329 static void mac_scsi_reset_boot(struct Scsi_Host
*instance
)
333 NCR5380_local_declare();
334 NCR5380_setup(instance
);
337 * Do a SCSI reset to clean up the bus during initialization. No messing
338 * with the queues, interrupts, or locks necessary here.
341 printk(KERN_INFO
"Macintosh SCSI: resetting the SCSI bus..." );
344 NCR5380_write( TARGET_COMMAND_REG
,
345 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG
) ));
348 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
| ICR_ASSERT_RST
);
349 /* The min. reset hold time is 25us, so 40us should be enough */
351 /* reset RST and interrupt */
352 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
);
353 NCR5380_read( RESET_PARITY_INTERRUPT_REG
);
355 for( end
= jiffies
+ AFTER_RESET_DELAY
; time_before(jiffies
, end
); )
358 printk(KERN_INFO
" done\n" );
362 const char * macscsi_info (struct Scsi_Host
*spnt
) {
367 Pseudo-DMA: (Ove Edlund)
368 The code attempts to catch bus errors that occur if one for example
369 "trips over the cable".
370 XXX: Since bus errors in the PDMA routines never happen on my
371 computer, the bus error code is untested.
372 If the code works as intended, a bus error results in Pseudo-DMA
373 beeing disabled, meaning that the driver switches to slow handshake.
374 If bus errors are NOT extremely rare, this has to be changed.
377 #define CP_IO_TO_MEM(s,d,len) \
378 __asm__ __volatile__ \
381 " move.w %1,%%d0\n" \
386 " 1: move.b (%0),(%1)+\n" \
387 " 2: dbf %%d0,1b\n" \
388 " move.w %2,%%d0\n" \
391 " 3: move.l (%0),(%1)+\n" \
392 "31: move.l (%0),(%1)+\n" \
393 "32: move.l (%0),(%1)+\n" \
394 "33: move.l (%0),(%1)+\n" \
395 "34: move.l (%0),(%1)+\n" \
396 "35: move.l (%0),(%1)+\n" \
397 "36: move.l (%0),(%1)+\n" \
398 "37: move.l (%0),(%1)+\n" \
399 " 4: dbf %%d0,3b\n" \
400 " move.w %2,%%d0\n" \
404 " 5: move.l (%0),(%1)+\n" \
405 " 6: dbf %%d0,5b\n" \
408 " 7: move.b (%0),(%1)+\n" \
410 " moveq.l #0, %2\n" \
412 ".section .fixup,\"ax\"\n" \
414 "90: moveq.l #1, %2\n" \
417 ".section __ex_table,\"a\"\n" \
431 : "=a"(s), "=a"(d), "=d"(len) \
432 : "0"(s), "1"(d), "2"(len) \
436 static int macscsi_pread (struct Scsi_Host
*instance
,
437 unsigned char *dst
, int len
)
440 volatile unsigned char *s
;
442 NCR5380_local_declare();
443 NCR5380_setup(instance
);
445 s
= mac_scsi_drq
+0x60;
448 /* These conditions are derived from MacOS */
450 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
451 && !(NCR5380_read(STATUS_REG
) & SR_REQ
))
453 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
454 && (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)) {
455 printk(KERN_ERR
"Error in macscsi_pread\n");
459 CP_IO_TO_MEM(s
, d
, len
);
462 printk(KERN_NOTICE
"Bus error in macscsi_pread\n");
470 #define CP_MEM_TO_IO(s,d,len) \
471 __asm__ __volatile__ \
474 " move.w %0,%%d0\n" \
479 " 1: move.b (%0)+,(%1)\n" \
480 " 2: dbf %%d0,1b\n" \
481 " move.w %2,%%d0\n" \
484 " 3: move.l (%0)+,(%1)\n" \
485 "31: move.l (%0)+,(%1)\n" \
486 "32: move.l (%0)+,(%1)\n" \
487 "33: move.l (%0)+,(%1)\n" \
488 "34: move.l (%0)+,(%1)\n" \
489 "35: move.l (%0)+,(%1)\n" \
490 "36: move.l (%0)+,(%1)\n" \
491 "37: move.l (%0)+,(%1)\n" \
492 " 4: dbf %%d0,3b\n" \
493 " move.w %2,%%d0\n" \
497 " 5: move.l (%0)+,(%1)\n" \
498 " 6: dbf %%d0,5b\n" \
501 " 7: move.b (%0)+,(%1)\n" \
503 " moveq.l #0, %2\n" \
505 ".section .fixup,\"ax\"\n" \
507 "90: moveq.l #1, %2\n" \
510 ".section __ex_table,\"a\"\n" \
524 : "=a"(s), "=a"(d), "=d"(len) \
525 : "0"(s), "1"(d), "2"(len) \
528 static int macscsi_pwrite (struct Scsi_Host
*instance
,
529 unsigned char *src
, int len
)
532 volatile unsigned char *d
;
534 NCR5380_local_declare();
535 NCR5380_setup(instance
);
540 /* These conditions are derived from MacOS */
542 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
543 && (!(NCR5380_read(STATUS_REG
) & SR_REQ
)
544 || (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)))
546 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)) {
547 printk(KERN_ERR
"Error in macscsi_pwrite\n");
551 CP_MEM_TO_IO(s
, d
, len
);
554 printk(KERN_NOTICE
"Bus error in macscsi_pwrite\n");
564 static struct scsi_host_template driver_template
= {
565 .proc_name
= "Mac5380",
566 .show_info
= macscsi_show_info
,
567 .write_info
= macscsi_write_info
,
568 .name
= "Macintosh NCR5380 SCSI",
569 .detect
= macscsi_detect
,
570 .release
= macscsi_release
,
571 .info
= macscsi_info
,
572 .queuecommand
= macscsi_queue_command
,
573 .eh_abort_handler
= macscsi_abort
,
574 .eh_bus_reset_handler
= macscsi_bus_reset
,
575 .can_queue
= CAN_QUEUE
,
577 .sg_tablesize
= SG_ALL
,
578 .cmd_per_lun
= CMD_PER_LUN
,
579 .use_clustering
= DISABLE_CLUSTERING
583 #include "scsi_module.c"