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_can_queue
= -1;
66 module_param(setup_can_queue
, int, 0);
67 static int setup_cmd_per_lun
= -1;
68 module_param(setup_cmd_per_lun
, int, 0);
69 static int setup_sg_tablesize
= -1;
70 module_param(setup_sg_tablesize
, int, 0);
71 static int setup_use_pdma
= -1;
72 module_param(setup_use_pdma
, int, 0);
73 static int setup_use_tagged_queuing
= -1;
74 module_param(setup_use_tagged_queuing
, int, 0);
75 static int setup_hostid
= -1;
76 module_param(setup_hostid
, int, 0);
78 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
79 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
80 * need ten times the standard value... */
84 #define AFTER_RESET_DELAY (5*HZ/2)
86 #define AFTER_RESET_DELAY (HZ/2)
89 static volatile unsigned char *mac_scsi_regp
= NULL
;
90 static volatile unsigned char *mac_scsi_drq
= NULL
;
91 static volatile unsigned char *mac_scsi_nodrq
= NULL
;
95 * NCR 5380 register access functions
98 static __inline__
char macscsi_read(struct Scsi_Host
*instance
, int reg
)
100 return in_8(instance
->io_port
+ (reg
<<4));
103 static __inline__
void macscsi_write(struct Scsi_Host
*instance
, int reg
, int value
)
105 out_8(instance
->io_port
+ (reg
<<4), value
);
109 static int __init
mac_scsi_setup(char *str
)
113 (void)get_options(str
, ARRAY_SIZE(ints
), ints
);
115 if (ints
[0] < 1 || ints
[0] > 6) {
116 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>]]]]]\n");
120 setup_can_queue
= ints
[1];
122 setup_cmd_per_lun
= ints
[2];
124 setup_sg_tablesize
= ints
[3];
126 setup_hostid
= ints
[4];
128 setup_use_tagged_queuing
= ints
[5];
130 setup_use_pdma
= ints
[6];
134 __setup("mac5380=", mac_scsi_setup
);
138 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
140 * Purpose : initializes mac NCR5380 driver based on the
141 * command line / compile time port and irq definitions.
143 * Inputs : tpnt - template for this SCSI adapter.
145 * Returns : 1 if a host adapter was found, 0 if not.
149 int __init
macscsi_detect(struct scsi_host_template
* tpnt
)
151 static int called
= 0;
153 struct Scsi_Host
*instance
;
155 if (!MACH_IS_MAC
|| called
)
158 if (macintosh_config
->scsi_type
!= MAC_SCSI_OLD
)
161 if (setup_can_queue
> 0)
162 tpnt
->can_queue
= setup_can_queue
;
163 if (setup_cmd_per_lun
> 0)
164 tpnt
->cmd_per_lun
= setup_cmd_per_lun
;
165 if (setup_sg_tablesize
>= 0)
166 tpnt
->sg_tablesize
= setup_sg_tablesize
;
167 if (setup_hostid
>= 0)
168 tpnt
->this_id
= setup_hostid
& 7;
171 if (setup_use_tagged_queuing
< 0)
172 setup_use_tagged_queuing
= 0;
175 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
176 something different here */
177 instance
= scsi_register (tpnt
, sizeof(struct NCR5380_hostdata
));
178 if (instance
== NULL
)
181 if (macintosh_config
->ident
== MAC_MODEL_IIFX
) {
182 mac_scsi_regp
= (unsigned char *) VIA1_BASE
+ 0x8000;
183 mac_scsi_drq
= (unsigned char *) VIA1_BASE
+ 0xE000;
184 mac_scsi_nodrq
= (unsigned char *) VIA1_BASE
+ 0xC000;
185 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
186 flags
= FLAG_NO_PSEUDO_DMA
;
188 mac_scsi_regp
= (unsigned char *) VIA1_BASE
+ 0x10000;
189 mac_scsi_drq
= (unsigned char *) VIA1_BASE
+ 0x6000;
190 mac_scsi_nodrq
= (unsigned char *) VIA1_BASE
+ 0x12000;
193 if (! setup_use_pdma
)
194 flags
= FLAG_NO_PSEUDO_DMA
;
196 instance
->io_port
= (unsigned long) mac_scsi_regp
;
197 instance
->irq
= IRQ_MAC_SCSI
;
200 mac_scsi_reset_boot(instance
);
203 NCR5380_init(instance
, flags
);
205 instance
->n_io_port
= 255;
207 if (instance
->irq
!= NO_IRQ
)
208 if (request_irq(instance
->irq
, NCR5380_intr
, 0, "ncr5380", instance
)) {
209 printk(KERN_WARNING
"scsi%d: IRQ%d not free, interrupts disabled\n",
210 instance
->host_no
, instance
->irq
);
211 instance
->irq
= NO_IRQ
;
218 int macscsi_release (struct Scsi_Host
*shpnt
)
220 if (shpnt
->irq
!= NO_IRQ
)
221 free_irq(shpnt
->irq
, shpnt
);
229 * Our 'bus reset on boot' function
232 static void mac_scsi_reset_boot(struct Scsi_Host
*instance
)
236 NCR5380_local_declare();
237 NCR5380_setup(instance
);
240 * Do a SCSI reset to clean up the bus during initialization. No messing
241 * with the queues, interrupts, or locks necessary here.
244 printk(KERN_INFO
"Macintosh SCSI: resetting the SCSI bus..." );
247 NCR5380_write( TARGET_COMMAND_REG
,
248 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG
) ));
251 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
| ICR_ASSERT_RST
);
252 /* The min. reset hold time is 25us, so 40us should be enough */
254 /* reset RST and interrupt */
255 NCR5380_write( INITIATOR_COMMAND_REG
, ICR_BASE
);
256 NCR5380_read( RESET_PARITY_INTERRUPT_REG
);
258 for( end
= jiffies
+ AFTER_RESET_DELAY
; time_before(jiffies
, end
); )
261 printk(KERN_INFO
" done\n" );
266 Pseudo-DMA: (Ove Edlund)
267 The code attempts to catch bus errors that occur if one for example
268 "trips over the cable".
269 XXX: Since bus errors in the PDMA routines never happen on my
270 computer, the bus error code is untested.
271 If the code works as intended, a bus error results in Pseudo-DMA
272 beeing disabled, meaning that the driver switches to slow handshake.
273 If bus errors are NOT extremely rare, this has to be changed.
276 #define CP_IO_TO_MEM(s,d,len) \
277 __asm__ __volatile__ \
280 " move.w %1,%%d0\n" \
285 " 1: move.b (%0),(%1)+\n" \
286 " 2: dbf %%d0,1b\n" \
287 " move.w %2,%%d0\n" \
290 " 3: move.l (%0),(%1)+\n" \
291 "31: move.l (%0),(%1)+\n" \
292 "32: move.l (%0),(%1)+\n" \
293 "33: move.l (%0),(%1)+\n" \
294 "34: move.l (%0),(%1)+\n" \
295 "35: move.l (%0),(%1)+\n" \
296 "36: move.l (%0),(%1)+\n" \
297 "37: move.l (%0),(%1)+\n" \
298 " 4: dbf %%d0,3b\n" \
299 " move.w %2,%%d0\n" \
303 " 5: move.l (%0),(%1)+\n" \
304 " 6: dbf %%d0,5b\n" \
307 " 7: move.b (%0),(%1)+\n" \
309 " moveq.l #0, %2\n" \
311 ".section .fixup,\"ax\"\n" \
313 "90: moveq.l #1, %2\n" \
316 ".section __ex_table,\"a\"\n" \
330 : "=a"(s), "=a"(d), "=d"(len) \
331 : "0"(s), "1"(d), "2"(len) \
335 static int macscsi_pread (struct Scsi_Host
*instance
,
336 unsigned char *dst
, int len
)
339 volatile unsigned char *s
;
341 NCR5380_local_declare();
342 NCR5380_setup(instance
);
344 s
= mac_scsi_drq
+0x60;
347 /* These conditions are derived from MacOS */
349 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
350 && !(NCR5380_read(STATUS_REG
) & SR_REQ
))
352 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
353 && (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)) {
354 printk(KERN_ERR
"Error in macscsi_pread\n");
358 CP_IO_TO_MEM(s
, d
, len
);
361 printk(KERN_NOTICE
"Bus error in macscsi_pread\n");
369 #define CP_MEM_TO_IO(s,d,len) \
370 __asm__ __volatile__ \
373 " move.w %0,%%d0\n" \
378 " 1: move.b (%0)+,(%1)\n" \
379 " 2: dbf %%d0,1b\n" \
380 " move.w %2,%%d0\n" \
383 " 3: move.l (%0)+,(%1)\n" \
384 "31: move.l (%0)+,(%1)\n" \
385 "32: move.l (%0)+,(%1)\n" \
386 "33: move.l (%0)+,(%1)\n" \
387 "34: move.l (%0)+,(%1)\n" \
388 "35: move.l (%0)+,(%1)\n" \
389 "36: move.l (%0)+,(%1)\n" \
390 "37: move.l (%0)+,(%1)\n" \
391 " 4: dbf %%d0,3b\n" \
392 " move.w %2,%%d0\n" \
396 " 5: move.l (%0)+,(%1)\n" \
397 " 6: dbf %%d0,5b\n" \
400 " 7: move.b (%0)+,(%1)\n" \
402 " moveq.l #0, %2\n" \
404 ".section .fixup,\"ax\"\n" \
406 "90: moveq.l #1, %2\n" \
409 ".section __ex_table,\"a\"\n" \
423 : "=a"(s), "=a"(d), "=d"(len) \
424 : "0"(s), "1"(d), "2"(len) \
427 static int macscsi_pwrite (struct Scsi_Host
*instance
,
428 unsigned char *src
, int len
)
431 volatile unsigned char *d
;
433 NCR5380_local_declare();
434 NCR5380_setup(instance
);
439 /* These conditions are derived from MacOS */
441 while (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)
442 && (!(NCR5380_read(STATUS_REG
) & SR_REQ
)
443 || (NCR5380_read(BUS_AND_STATUS_REG
) & BASR_PHASE_MATCH
)))
445 if (!(NCR5380_read(BUS_AND_STATUS_REG
) & BASR_DRQ
)) {
446 printk(KERN_ERR
"Error in macscsi_pwrite\n");
450 CP_MEM_TO_IO(s
, d
, len
);
453 printk(KERN_NOTICE
"Bus error in macscsi_pwrite\n");
463 static struct scsi_host_template driver_template
= {
464 .proc_name
= "Mac5380",
465 .show_info
= macscsi_show_info
,
466 .write_info
= macscsi_write_info
,
467 .name
= "Macintosh NCR5380 SCSI",
468 .detect
= macscsi_detect
,
469 .release
= macscsi_release
,
470 .info
= macscsi_info
,
471 .queuecommand
= macscsi_queue_command
,
472 .eh_abort_handler
= macscsi_abort
,
473 .eh_bus_reset_handler
= macscsi_bus_reset
,
476 .sg_tablesize
= SG_ALL
,
478 .use_clustering
= DISABLE_CLUSTERING
482 #include "scsi_module.c"
484 MODULE_LICENSE("GPL");