]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/scsi/mac_scsi.c
dmx3191d: Use NO_IRQ
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / mac_scsi.c
CommitLineData
1da177e4
LT
1/*
2 * Generic Macintosh NCR5380 driver
3 *
4 * Copyright 1998, Michael Schmitz <mschmitz@lbl.gov>
5 *
6 * derived in part from:
7 */
8/*
9 * Generic Generic NCR5380 driver
10 *
11 * Copyright 1995, Russell King
1da177e4
LT
12 */
13
1da177e4
LT
14#include <linux/types.h>
15#include <linux/stddef.h>
16#include <linux/ctype.h>
17#include <linux/delay.h>
18
19#include <linux/module.h>
20#include <linux/signal.h>
1da177e4
LT
21#include <linux/ioport.h>
22#include <linux/init.h>
23#include <linux/blkdev.h>
24#include <linux/interrupt.h>
25
26#include <asm/io.h>
27#include <asm/irq.h>
1da177e4
LT
28
29#include <asm/macintosh.h>
30#include <asm/macints.h>
1da177e4
LT
31#include <asm/mac_via.h>
32
1da177e4
LT
33#include <scsi/scsi_host.h>
34#include "mac_scsi.h"
e744fdea 35
e744fdea
BH
36#define PSEUDO_DMA
37
1da177e4
LT
38#include "NCR5380.h"
39
1da177e4 40#define RESET_BOOT
1da177e4 41
1da177e4
LT
42#ifdef RESET_BOOT
43static void mac_scsi_reset_boot(struct Scsi_Host *instance);
44#endif
45
46static int setup_called = 0;
47static int setup_can_queue = -1;
48static int setup_cmd_per_lun = -1;
49static int setup_sg_tablesize = -1;
50static int setup_use_pdma = -1;
51#ifdef SUPPORT_TAGS
52static int setup_use_tagged_queuing = -1;
53#endif
54static int setup_hostid = -1;
55
56/* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
57 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
58 * need ten times the standard value... */
59#define TOSHIBA_DELAY
60
61#ifdef TOSHIBA_DELAY
62#define AFTER_RESET_DELAY (5*HZ/2)
63#else
64#define AFTER_RESET_DELAY (HZ/2)
65#endif
66
67static volatile unsigned char *mac_scsi_regp = NULL;
68static volatile unsigned char *mac_scsi_drq = NULL;
69static volatile unsigned char *mac_scsi_nodrq = NULL;
70
71
72/*
73 * NCR 5380 register access functions
74 */
75
1da177e4
LT
76static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
77{
78 return in_8(instance->io_port + (reg<<4));
79}
80
81static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value)
82{
83 out_8(instance->io_port + (reg<<4), value);
84}
1da177e4
LT
85
86/*
87 * Function : mac_scsi_setup(char *str)
88 *
89 * Purpose : booter command line initialization of the overrides array,
90 *
91 * Inputs : str - comma delimited list of options
92 *
93 */
94
95static int __init mac_scsi_setup(char *str) {
1da177e4
LT
96 int ints[7];
97
98 (void)get_options( str, ARRAY_SIZE(ints), ints);
99
100 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
101 printk(KERN_WARNING "scsi: <mac5380>"
102 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
103 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
104 return 0;
105 }
106
107 if (ints[0] >= 1) {
108 if (ints[1] > 0)
109 /* no limits on this, just > 0 */
110 setup_can_queue = ints[1];
111 }
112 if (ints[0] >= 2) {
113 if (ints[2] > 0)
114 setup_cmd_per_lun = ints[2];
115 }
116 if (ints[0] >= 3) {
117 if (ints[3] >= 0) {
118 setup_sg_tablesize = ints[3];
119 /* Must be <= SG_ALL (255) */
120 if (setup_sg_tablesize > SG_ALL)
121 setup_sg_tablesize = SG_ALL;
122 }
123 }
124 if (ints[0] >= 4) {
125 /* Must be between 0 and 7 */
126 if (ints[4] >= 0 && ints[4] <= 7)
127 setup_hostid = ints[4];
128 else if (ints[4] > 7)
129 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
130 }
131#ifdef SUPPORT_TAGS
132 if (ints[0] >= 5) {
133 if (ints[5] >= 0)
134 setup_use_tagged_queuing = !!ints[5];
135 }
136
137 if (ints[0] == 6) {
138 if (ints[6] >= 0)
139 setup_use_pdma = ints[6];
140 }
141#else
142 if (ints[0] == 5) {
143 if (ints[5] >= 0)
144 setup_use_pdma = ints[5];
145 }
146#endif /* SUPPORT_TAGS */
147
1da177e4
LT
148 return 1;
149}
150
151__setup("mac5380=", mac_scsi_setup);
152
1da177e4 153/*
d0be4a7d 154 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
1da177e4
LT
155 *
156 * Purpose : initializes mac NCR5380 driver based on the
157 * command line / compile time port and irq definitions.
158 *
159 * Inputs : tpnt - template for this SCSI adapter.
160 *
161 * Returns : 1 if a host adapter was found, 0 if not.
162 *
163 */
164
70c26cf3 165int __init macscsi_detect(struct scsi_host_template * tpnt)
1da177e4
LT
166{
167 static int called = 0;
168 int flags = 0;
169 struct Scsi_Host *instance;
170
171 if (!MACH_IS_MAC || called)
172 return( 0 );
173
174 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
175 return( 0 );
176
d572f65f
FT
177 if (setup_can_queue > 0)
178 tpnt->can_queue = setup_can_queue;
179 if (setup_cmd_per_lun > 0)
180 tpnt->cmd_per_lun = setup_cmd_per_lun;
181 if (setup_sg_tablesize >= 0)
182 tpnt->sg_tablesize = setup_sg_tablesize;
1da177e4
LT
183
184 if (setup_hostid >= 0)
185 tpnt->this_id = setup_hostid;
186 else {
187 /* use 7 as default */
188 tpnt->this_id = 7;
189 }
190
191#ifdef SUPPORT_TAGS
192 if (setup_use_tagged_queuing < 0)
d572f65f 193 setup_use_tagged_queuing = 0;
1da177e4
LT
194#endif
195
196 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
197 something different here */
198 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
603f202e
A
199 if (instance == NULL)
200 return 0;
5db5c505 201
1da177e4
LT
202 if (macintosh_config->ident == MAC_MODEL_IIFX) {
203 mac_scsi_regp = via1+0x8000;
204 mac_scsi_drq = via1+0xE000;
205 mac_scsi_nodrq = via1+0xC000;
206 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
207 flags = FLAG_NO_PSEUDO_DMA;
208 } else {
209 mac_scsi_regp = via1+0x10000;
210 mac_scsi_drq = via1+0x6000;
211 mac_scsi_nodrq = via1+0x12000;
212 }
213
214 if (! setup_use_pdma)
215 flags = FLAG_NO_PSEUDO_DMA;
216
217 instance->io_port = (unsigned long) mac_scsi_regp;
218 instance->irq = IRQ_MAC_SCSI;
219
220#ifdef RESET_BOOT
221 mac_scsi_reset_boot(instance);
222#endif
223
224 NCR5380_init(instance, flags);
225
226 instance->n_io_port = 255;
227
22f5f10d 228 if (instance->irq != NO_IRQ)
dddaaf79 229 if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) {
1da177e4
LT
230 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
231 instance->host_no, instance->irq);
22f5f10d 232 instance->irq = NO_IRQ;
1da177e4
LT
233 }
234
1da177e4
LT
235 called = 1;
236 return 1;
237}
238
239int macscsi_release (struct Scsi_Host *shpnt)
240{
22f5f10d 241 if (shpnt->irq != NO_IRQ)
1e641664 242 free_irq(shpnt->irq, shpnt);
1da177e4
LT
243 NCR5380_exit(shpnt);
244
245 return 0;
246}
247
248#ifdef RESET_BOOT
249/*
250 * Our 'bus reset on boot' function
251 */
252
253static void mac_scsi_reset_boot(struct Scsi_Host *instance)
254{
255 unsigned long end;
256
257 NCR5380_local_declare();
258 NCR5380_setup(instance);
259
260 /*
261 * Do a SCSI reset to clean up the bus during initialization. No messing
262 * with the queues, interrupts, or locks necessary here.
263 */
264
265 printk(KERN_INFO "Macintosh SCSI: resetting the SCSI bus..." );
266
1da177e4
LT
267 /* get in phase */
268 NCR5380_write( TARGET_COMMAND_REG,
269 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
270
271 /* assert RST */
272 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
273 /* The min. reset hold time is 25us, so 40us should be enough */
274 udelay( 50 );
275 /* reset RST and interrupt */
276 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
277 NCR5380_read( RESET_PARITY_INTERRUPT_REG );
278
279 for( end = jiffies + AFTER_RESET_DELAY; time_before(jiffies, end); )
280 barrier();
281
1da177e4
LT
282 printk(KERN_INFO " done\n" );
283}
284#endif
285
1da177e4
LT
286/*
287 Pseudo-DMA: (Ove Edlund)
288 The code attempts to catch bus errors that occur if one for example
289 "trips over the cable".
290 XXX: Since bus errors in the PDMA routines never happen on my
291 computer, the bus error code is untested.
292 If the code works as intended, a bus error results in Pseudo-DMA
293 beeing disabled, meaning that the driver switches to slow handshake.
294 If bus errors are NOT extremely rare, this has to be changed.
295*/
296
297#define CP_IO_TO_MEM(s,d,len) \
298__asm__ __volatile__ \
299 (" cmp.w #4,%2\n" \
300 " bls 8f\n" \
301 " move.w %1,%%d0\n" \
302 " neg.b %%d0\n" \
303 " and.w #3,%%d0\n" \
304 " sub.w %%d0,%2\n" \
305 " bra 2f\n" \
306 " 1: move.b (%0),(%1)+\n" \
307 " 2: dbf %%d0,1b\n" \
308 " move.w %2,%%d0\n" \
309 " lsr.w #5,%%d0\n" \
310 " bra 4f\n" \
311 " 3: move.l (%0),(%1)+\n" \
312 "31: move.l (%0),(%1)+\n" \
313 "32: move.l (%0),(%1)+\n" \
314 "33: move.l (%0),(%1)+\n" \
315 "34: move.l (%0),(%1)+\n" \
316 "35: move.l (%0),(%1)+\n" \
317 "36: move.l (%0),(%1)+\n" \
318 "37: move.l (%0),(%1)+\n" \
319 " 4: dbf %%d0,3b\n" \
320 " move.w %2,%%d0\n" \
321 " lsr.w #2,%%d0\n" \
322 " and.w #7,%%d0\n" \
323 " bra 6f\n" \
324 " 5: move.l (%0),(%1)+\n" \
325 " 6: dbf %%d0,5b\n" \
326 " and.w #3,%2\n" \
327 " bra 8f\n" \
328 " 7: move.b (%0),(%1)+\n" \
329 " 8: dbf %2,7b\n" \
330 " moveq.l #0, %2\n" \
331 " 9: \n" \
332 ".section .fixup,\"ax\"\n" \
333 " .even\n" \
334 "90: moveq.l #1, %2\n" \
335 " jra 9b\n" \
336 ".previous\n" \
337 ".section __ex_table,\"a\"\n" \
338 " .align 4\n" \
339 " .long 1b,90b\n" \
340 " .long 3b,90b\n" \
341 " .long 31b,90b\n" \
342 " .long 32b,90b\n" \
343 " .long 33b,90b\n" \
344 " .long 34b,90b\n" \
345 " .long 35b,90b\n" \
346 " .long 36b,90b\n" \
347 " .long 37b,90b\n" \
348 " .long 5b,90b\n" \
349 " .long 7b,90b\n" \
350 ".previous" \
351 : "=a"(s), "=a"(d), "=d"(len) \
352 : "0"(s), "1"(d), "2"(len) \
353 : "d0")
354
355
356static int macscsi_pread (struct Scsi_Host *instance,
357 unsigned char *dst, int len)
358{
359 unsigned char *d;
360 volatile unsigned char *s;
361
362 NCR5380_local_declare();
363 NCR5380_setup(instance);
364
365 s = mac_scsi_drq+0x60;
366 d = dst;
367
368/* These conditions are derived from MacOS */
369
370 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
371 && !(NCR5380_read(STATUS_REG) & SR_REQ))
372 ;
373 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
374 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
375 printk(KERN_ERR "Error in macscsi_pread\n");
376 return -1;
377 }
378
379 CP_IO_TO_MEM(s, d, len);
380
381 if (len != 0) {
382 printk(KERN_NOTICE "Bus error in macscsi_pread\n");
383 return -1;
384 }
385
386 return 0;
387}
388
389
390#define CP_MEM_TO_IO(s,d,len) \
391__asm__ __volatile__ \
392 (" cmp.w #4,%2\n" \
393 " bls 8f\n" \
394 " move.w %0,%%d0\n" \
395 " neg.b %%d0\n" \
396 " and.w #3,%%d0\n" \
397 " sub.w %%d0,%2\n" \
398 " bra 2f\n" \
399 " 1: move.b (%0)+,(%1)\n" \
400 " 2: dbf %%d0,1b\n" \
401 " move.w %2,%%d0\n" \
402 " lsr.w #5,%%d0\n" \
403 " bra 4f\n" \
404 " 3: move.l (%0)+,(%1)\n" \
405 "31: move.l (%0)+,(%1)\n" \
406 "32: move.l (%0)+,(%1)\n" \
407 "33: move.l (%0)+,(%1)\n" \
408 "34: move.l (%0)+,(%1)\n" \
409 "35: move.l (%0)+,(%1)\n" \
410 "36: move.l (%0)+,(%1)\n" \
411 "37: move.l (%0)+,(%1)\n" \
412 " 4: dbf %%d0,3b\n" \
413 " move.w %2,%%d0\n" \
414 " lsr.w #2,%%d0\n" \
415 " and.w #7,%%d0\n" \
416 " bra 6f\n" \
417 " 5: move.l (%0)+,(%1)\n" \
418 " 6: dbf %%d0,5b\n" \
419 " and.w #3,%2\n" \
420 " bra 8f\n" \
421 " 7: move.b (%0)+,(%1)\n" \
422 " 8: dbf %2,7b\n" \
423 " moveq.l #0, %2\n" \
424 " 9: \n" \
425 ".section .fixup,\"ax\"\n" \
426 " .even\n" \
427 "90: moveq.l #1, %2\n" \
428 " jra 9b\n" \
429 ".previous\n" \
430 ".section __ex_table,\"a\"\n" \
431 " .align 4\n" \
432 " .long 1b,90b\n" \
433 " .long 3b,90b\n" \
434 " .long 31b,90b\n" \
435 " .long 32b,90b\n" \
436 " .long 33b,90b\n" \
437 " .long 34b,90b\n" \
438 " .long 35b,90b\n" \
439 " .long 36b,90b\n" \
440 " .long 37b,90b\n" \
441 " .long 5b,90b\n" \
442 " .long 7b,90b\n" \
443 ".previous" \
444 : "=a"(s), "=a"(d), "=d"(len) \
445 : "0"(s), "1"(d), "2"(len) \
446 : "d0")
447
448static int macscsi_pwrite (struct Scsi_Host *instance,
449 unsigned char *src, int len)
450{
451 unsigned char *s;
452 volatile unsigned char *d;
453
454 NCR5380_local_declare();
455 NCR5380_setup(instance);
456
457 s = src;
458 d = mac_scsi_drq;
459
460/* These conditions are derived from MacOS */
461
462 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)
463 && (!(NCR5380_read(STATUS_REG) & SR_REQ)
464 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
465 ;
466 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
467 printk(KERN_ERR "Error in macscsi_pwrite\n");
468 return -1;
469 }
470
471 CP_MEM_TO_IO(s, d, len);
472
473 if (len != 0) {
474 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n");
475 return -1;
476 }
477
478 return 0;
479}
480
481
1da177e4
LT
482#include "NCR5380.c"
483
d0be4a7d 484static struct scsi_host_template driver_template = {
1da177e4 485 .proc_name = "Mac5380",
dd7ab71b
AV
486 .show_info = macscsi_show_info,
487 .write_info = macscsi_write_info,
1da177e4
LT
488 .name = "Macintosh NCR5380 SCSI",
489 .detect = macscsi_detect,
490 .release = macscsi_release,
491 .info = macscsi_info,
492 .queuecommand = macscsi_queue_command,
493 .eh_abort_handler = macscsi_abort,
494 .eh_bus_reset_handler = macscsi_bus_reset,
d572f65f 495 .can_queue = 16,
1da177e4
LT
496 .this_id = 7,
497 .sg_tablesize = SG_ALL,
d572f65f 498 .cmd_per_lun = 2,
1da177e4
LT
499 .use_clustering = DISABLE_CLUSTERING
500};
501
502
503#include "scsi_module.c"