GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / mac_scsi.c
blob772d375a78d696a56ea3d363ace81f8189e7474e
1 /*
2 * Generic Macintosh NCR5380 driver
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
6 * derived in part from:
7 */
8 /*
9 * Generic Generic NCR5380 driver
11 * Copyright 1995, Russell King
13 * ALPHA RELEASE 1.
15 * For more information, please consult
17 * NCR 5380 Family
18 * SCSI Protocol Controller
19 * Databook
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
24 * 1+ (719) 578-3400
25 * 1+ (800) 334-5454
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>
44 #include <asm/io.h>
45 #include <asm/irq.h>
46 #include <asm/system.h>
48 #include <asm/macintosh.h>
49 #include <asm/macints.h>
50 #include <asm/mac_via.h>
52 #include "scsi.h"
53 #include <scsi/scsi_host.h>
54 #include "mac_scsi.h"
56 /* These control the behaviour of the generic 5380 core */
57 #define AUTOSENSE
58 #define PSEUDO_DMA
60 #include "NCR5380.h"
62 #define NDEBUG (NDEBUG_ABORT)
64 #define RESET_BOOT
65 #define DRIVER_SETUP
67 extern void via_scsi_clear(void);
69 #ifdef RESET_BOOT
70 static void mac_scsi_reset_boot(struct Scsi_Host *instance);
71 #endif
73 static int setup_called = 0;
74 static int setup_can_queue = -1;
75 static int setup_cmd_per_lun = -1;
76 static int setup_sg_tablesize = -1;
77 static int setup_use_pdma = -1;
78 #ifdef SUPPORT_TAGS
79 static int setup_use_tagged_queuing = -1;
80 #endif
81 static int setup_hostid = -1;
83 /* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
84 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
85 * need ten times the standard value... */
86 #define TOSHIBA_DELAY
88 #ifdef TOSHIBA_DELAY
89 #define AFTER_RESET_DELAY (5*HZ/2)
90 #else
91 #define AFTER_RESET_DELAY (HZ/2)
92 #endif
94 static volatile unsigned char *mac_scsi_regp = NULL;
95 static volatile unsigned char *mac_scsi_drq = NULL;
96 static volatile unsigned char *mac_scsi_nodrq = NULL;
100 * NCR 5380 register access functions
104 /* Fast versions */
105 static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
107 return in_8(instance->io_port + (reg<<4));
110 static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value)
112 out_8(instance->io_port + (reg<<4), value);
117 * Function : mac_scsi_setup(char *str)
119 * Purpose : booter command line initialization of the overrides array,
121 * Inputs : str - comma delimited list of options
125 static int __init mac_scsi_setup(char *str) {
126 #ifdef DRIVER_SETUP
127 int ints[7];
129 (void)get_options( str, ARRAY_SIZE(ints), ints);
131 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
132 printk(KERN_WARNING "scsi: <mac5380>"
133 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
134 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
135 return 0;
138 if (ints[0] >= 1) {
139 if (ints[1] > 0)
140 /* no limits on this, just > 0 */
141 setup_can_queue = ints[1];
143 if (ints[0] >= 2) {
144 if (ints[2] > 0)
145 setup_cmd_per_lun = ints[2];
147 if (ints[0] >= 3) {
148 if (ints[3] >= 0) {
149 setup_sg_tablesize = ints[3];
150 /* Must be <= SG_ALL (255) */
151 if (setup_sg_tablesize > SG_ALL)
152 setup_sg_tablesize = SG_ALL;
155 if (ints[0] >= 4) {
156 /* Must be between 0 and 7 */
157 if (ints[4] >= 0 && ints[4] <= 7)
158 setup_hostid = ints[4];
159 else if (ints[4] > 7)
160 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
162 #ifdef SUPPORT_TAGS
163 if (ints[0] >= 5) {
164 if (ints[5] >= 0)
165 setup_use_tagged_queuing = !!ints[5];
168 if (ints[0] == 6) {
169 if (ints[6] >= 0)
170 setup_use_pdma = ints[6];
172 #else
173 if (ints[0] == 5) {
174 if (ints[5] >= 0)
175 setup_use_pdma = ints[5];
177 #endif /* SUPPORT_TAGS */
179 #endif /* DRIVER_SETUP */
180 return 1;
183 __setup("mac5380=", mac_scsi_setup);
186 * If you want to find the instance with (k)gdb ...
188 #if NDEBUG
189 static struct Scsi_Host *default_instance;
190 #endif
193 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
195 * Purpose : initializes mac NCR5380 driver based on the
196 * command line / compile time port and irq definitions.
198 * Inputs : tpnt - template for this SCSI adapter.
200 * Returns : 1 if a host adapter was found, 0 if not.
204 int macscsi_detect(struct scsi_host_template * tpnt)
206 static int called = 0;
207 int flags = 0;
208 struct Scsi_Host *instance;
210 if (!MACH_IS_MAC || called)
211 return( 0 );
213 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
214 return( 0 );
216 /* setup variables */
217 tpnt->can_queue =
218 (setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
219 tpnt->cmd_per_lun =
220 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
221 tpnt->sg_tablesize =
222 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
224 if (setup_hostid >= 0)
225 tpnt->this_id = setup_hostid;
226 else {
227 /* use 7 as default */
228 tpnt->this_id = 7;
231 #ifdef SUPPORT_TAGS
232 if (setup_use_tagged_queuing < 0)
233 setup_use_tagged_queuing = USE_TAGGED_QUEUING;
234 #endif
236 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
237 something different here */
238 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
239 #if NDEBUG
240 default_instance = instance;
241 #endif
243 if (macintosh_config->ident == MAC_MODEL_IIFX) {
244 mac_scsi_regp = via1+0x8000;
245 mac_scsi_drq = via1+0xE000;
246 mac_scsi_nodrq = via1+0xC000;
247 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
248 flags = FLAG_NO_PSEUDO_DMA;
249 } else {
250 mac_scsi_regp = via1+0x10000;
251 mac_scsi_drq = via1+0x6000;
252 mac_scsi_nodrq = via1+0x12000;
255 if (! setup_use_pdma)
256 flags = FLAG_NO_PSEUDO_DMA;
258 instance->io_port = (unsigned long) mac_scsi_regp;
259 instance->irq = IRQ_MAC_SCSI;
261 #ifdef RESET_BOOT
262 mac_scsi_reset_boot(instance);
263 #endif
265 NCR5380_init(instance, flags);
267 instance->n_io_port = 255;
269 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
271 if (instance->irq != SCSI_IRQ_NONE)
272 if (request_irq(instance->irq, NCR5380_intr, IRQ_FLG_SLOW,
273 "ncr5380", instance)) {
274 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
275 instance->host_no, instance->irq);
276 instance->irq = SCSI_IRQ_NONE;
279 printk(KERN_INFO "scsi%d: generic 5380 at port %lX irq", instance->host_no, instance->io_port);
280 if (instance->irq == SCSI_IRQ_NONE)
281 printk (KERN_INFO "s disabled");
282 else
283 printk (KERN_INFO " %d", instance->irq);
284 printk(KERN_INFO " options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
285 instance->can_queue, instance->cmd_per_lun, MACSCSI_PUBLIC_RELEASE);
286 printk(KERN_INFO "\nscsi%d:", instance->host_no);
287 NCR5380_print_options(instance);
288 printk("\n");
289 called = 1;
290 return 1;
293 int macscsi_release (struct Scsi_Host *shpnt)
295 if (shpnt->irq != SCSI_IRQ_NONE)
296 free_irq(shpnt->irq, shpnt);
297 NCR5380_exit(shpnt);
299 return 0;
302 #ifdef RESET_BOOT
304 * Our 'bus reset on boot' function
307 static void mac_scsi_reset_boot(struct Scsi_Host *instance)
309 unsigned long end;
311 NCR5380_local_declare();
312 NCR5380_setup(instance);
315 * Do a SCSI reset to clean up the bus during initialization. No messing
316 * with the queues, interrupts, or locks necessary here.
319 printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." );
321 /* switch off SCSI IRQ - catch an interrupt without IRQ bit set else */
322 disable_irq(IRQ_MAC_SCSI);
324 /* get in phase */
325 NCR5380_write( TARGET_COMMAND_REG,
326 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
328 /* assert RST */
329 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
330 /* The min. reset hold time is 25us, so 40us should be enough */
331 udelay( 50 );
332 /* reset RST and interrupt */
333 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
334 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
336 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
337 barrier();
339 /* switch on SCSI IRQ again */
340 enable_irq(IRQ_MAC_SCSI);
342 printk(KERN_INFO " done\n" );
344 #endif
346 const char * macscsi_info (struct Scsi_Host *spnt) {
347 return "";
351 #define CP_IO_TO_MEM(s,d,len) \
352 __asm__ __volatile__ \
353 (" cmp.w #4,%2\n" \
354 " bls 8f\n" \
355 " move.w %1,%%d0\n" \
356 " neg.b %%d0\n" \
357 " and.w #3,%%d0\n" \
358 " sub.w %%d0,%2\n" \
359 " bra 2f\n" \
360 " 1: move.b (%0),(%1)+\n" \
361 " 2: dbf %%d0,1b\n" \
362 " move.w %2,%%d0\n" \
363 " lsr.w #5,%%d0\n" \
364 " bra 4f\n" \
365 " 3: move.l (%0),(%1)+\n" \
366 "31: move.l (%0),(%1)+\n" \
367 "32: move.l (%0),(%1)+\n" \
368 "33: move.l (%0),(%1)+\n" \
369 "34: move.l (%0),(%1)+\n" \
370 "35: move.l (%0),(%1)+\n" \
371 "36: move.l (%0),(%1)+\n" \
372 "37: move.l (%0),(%1)+\n" \
373 " 4: dbf %%d0,3b\n" \
374 " move.w %2,%%d0\n" \
375 " lsr.w #2,%%d0\n" \
376 " and.w #7,%%d0\n" \
377 " bra 6f\n" \
378 " 5: move.l (%0),(%1)+\n" \
379 " 6: dbf %%d0,5b\n" \
380 " and.w #3,%2\n" \
381 " bra 8f\n" \
382 " 7: move.b (%0),(%1)+\n" \
383 " 8: dbf %2,7b\n" \
384 " moveq.l #0, %2\n" \
385 " 9: \n" \
386 ".section .fixup,\"ax\"\n" \
387 " .even\n" \
388 "90: moveq.l #1, %2\n" \
389 " jra 9b\n" \
390 ".previous\n" \
391 ".section __ex_table,\"a\"\n" \
392 " .align 4\n" \
393 " .long 1b,90b\n" \
394 " .long 3b,90b\n" \
395 " .long 31b,90b\n" \
396 " .long 32b,90b\n" \
397 " .long 33b,90b\n" \
398 " .long 34b,90b\n" \
399 " .long 35b,90b\n" \
400 " .long 36b,90b\n" \
401 " .long 37b,90b\n" \
402 " .long 5b,90b\n" \
403 " .long 7b,90b\n" \
404 ".previous" \
405 : "=a"(s), "=a"(d), "=d"(len) \
406 : "0"(s), "1"(d), "2"(len) \
407 : "d0")
410 static int macscsi_pread (struct Scsi_Host *instance,
411 unsigned char *dst, int len)
413 unsigned char *d;
414 volatile unsigned char *s;
416 NCR5380_local_declare();
417 NCR5380_setup(instance);
419 s = mac_scsi_drq+0x60;
420 d = dst;
422 /* These conditions are derived from MacOS */
424 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
425 && !(NCR5380_read(STATUS_REG) & SR_REQ))
427 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
428 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
429 printk(KERN_ERR "Error in macscsi_pread\n");
430 return -1;
433 CP_IO_TO_MEM(s, d, len);
435 if (len != 0) {
436 printk(KERN_NOTICE "Bus error in macscsi_pread\n");
437 return -1;
440 return 0;
444 #define CP_MEM_TO_IO(s,d,len) \
445 __asm__ __volatile__ \
446 (" cmp.w #4,%2\n" \
447 " bls 8f\n" \
448 " move.w %0,%%d0\n" \
449 " neg.b %%d0\n" \
450 " and.w #3,%%d0\n" \
451 " sub.w %%d0,%2\n" \
452 " bra 2f\n" \
453 " 1: move.b (%0)+,(%1)\n" \
454 " 2: dbf %%d0,1b\n" \
455 " move.w %2,%%d0\n" \
456 " lsr.w #5,%%d0\n" \
457 " bra 4f\n" \
458 " 3: move.l (%0)+,(%1)\n" \
459 "31: move.l (%0)+,(%1)\n" \
460 "32: move.l (%0)+,(%1)\n" \
461 "33: move.l (%0)+,(%1)\n" \
462 "34: move.l (%0)+,(%1)\n" \
463 "35: move.l (%0)+,(%1)\n" \
464 "36: move.l (%0)+,(%1)\n" \
465 "37: move.l (%0)+,(%1)\n" \
466 " 4: dbf %%d0,3b\n" \
467 " move.w %2,%%d0\n" \
468 " lsr.w #2,%%d0\n" \
469 " and.w #7,%%d0\n" \
470 " bra 6f\n" \
471 " 5: move.l (%0)+,(%1)\n" \
472 " 6: dbf %%d0,5b\n" \
473 " and.w #3,%2\n" \
474 " bra 8f\n" \
475 " 7: move.b (%0)+,(%1)\n" \
476 " 8: dbf %2,7b\n" \
477 " moveq.l #0, %2\n" \
478 " 9: \n" \
479 ".section .fixup,\"ax\"\n" \
480 " .even\n" \
481 "90: moveq.l #1, %2\n" \
482 " jra 9b\n" \
483 ".previous\n" \
484 ".section __ex_table,\"a\"\n" \
485 " .align 4\n" \
486 " .long 1b,90b\n" \
487 " .long 3b,90b\n" \
488 " .long 31b,90b\n" \
489 " .long 32b,90b\n" \
490 " .long 33b,90b\n" \
491 " .long 34b,90b\n" \
492 " .long 35b,90b\n" \
493 " .long 36b,90b\n" \
494 " .long 37b,90b\n" \
495 " .long 5b,90b\n" \
496 " .long 7b,90b\n" \
497 ".previous" \
498 : "=a"(s), "=a"(d), "=d"(len) \
499 : "0"(s), "1"(d), "2"(len) \
500 : "d0")
502 static int macscsi_pwrite (struct Scsi_Host *instance,
503 unsigned char *src, int len)
505 unsigned char *s;
506 volatile unsigned char *d;
508 NCR5380_local_declare();
509 NCR5380_setup(instance);
511 s = src;
512 d = mac_scsi_drq;
514 /* These conditions are derived from MacOS */
516 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
517 && (!(NCR5380_read(STATUS_REG) & SR_REQ)
518 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
520 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
521 printk(KERN_ERR "Error in macscsi_pwrite\n");
522 return -1;
525 CP_MEM_TO_IO(s, d, len);
527 if (len != 0) {
528 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n");
529 return -1;
532 return 0;
536 #include "NCR5380.c"
538 static struct scsi_host_template driver_template = {
539 .proc_name = "Mac5380",
540 .proc_info = macscsi_proc_info,
541 .name = "Macintosh NCR5380 SCSI",
542 .detect = macscsi_detect,
543 .release = macscsi_release,
544 .info = macscsi_info,
545 .queuecommand = macscsi_queue_command,
546 .eh_abort_handler = macscsi_abort,
547 .eh_bus_reset_handler = macscsi_bus_reset,
548 .can_queue = CAN_QUEUE,
549 .this_id = 7,
550 .sg_tablesize = SG_ALL,
551 .cmd_per_lun = CMD_PER_LUN,
552 .use_clustering = DISABLE_CLUSTERING
556 #include "scsi_module.c"