]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/scsi/g_NCR5380.c
ncr5380: Remove NCR5380_STATS
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / g_NCR5380.c
1 /*
2 * Generic Generic NCR5380 driver
3 *
4 * Copyright 1993, Drew Eckhardt
5 * Visionary Computing
6 * (Unix and Linux consulting and custom programming)
7 * drew@colorado.edu
8 * +1 (303) 440-4894
9 *
10 * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin
11 * K.Lentin@cs.monash.edu.au
12 *
13 * NCR53C400A extensions (c) 1996, Ingmar Baumgart
14 * ingmar@gonzo.schwaben.de
15 *
16 * DTC3181E extensions (c) 1997, Ronald van Cuijlenborg
17 * ronald.van.cuijlenborg@tip.nl or nutty@dds.nl
18 *
19 * Added ISAPNP support for DTC436 adapters,
20 * Thomas Sailer, sailer@ife.ee.ethz.ch
21 *
22 * ALPHA RELEASE 1.
23 */
24
25 /*
26 * TODO : flesh out DMA support, find some one actually using this (I have
27 * a memory mapped Trantor board that works fine)
28 */
29
30 /*
31 * The card is detected and initialized in one of several ways :
32 * 1. With command line overrides - NCR5380=port,irq may be
33 * used on the LILO command line to override the defaults.
34 *
35 * 2. With the GENERIC_NCR5380_OVERRIDE compile time define. This is
36 * specified as an array of address, irq, dma, board tuples. Ie, for
37 * one board at 0x350, IRQ5, no dma, I could say
38 * -DGENERIC_NCR5380_OVERRIDE={{0xcc000, 5, DMA_NONE, BOARD_NCR5380}}
39 *
40 * -1 should be specified for no or DMA interrupt, -2 to autoprobe for an
41 * IRQ line if overridden on the command line.
42 *
43 * 3. When included as a module, with arguments passed on the command line:
44 * ncr_irq=xx the interrupt
45 * ncr_addr=xx the port or base address (for port or memory
46 * mapped, resp.)
47 * ncr_dma=xx the DMA
48 * ncr_5380=1 to set up for a NCR5380 board
49 * ncr_53c400=1 to set up for a NCR53C400 board
50 * e.g.
51 * modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_5380=1
52 * for a port mapped NCR5380 board or
53 * modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1
54 * for a memory mapped NCR53C400 board with interrupts disabled.
55 *
56 * 255 should be specified for no or DMA interrupt, 254 to autoprobe for an
57 * IRQ line if overridden on the command line.
58 *
59 */
60
61 /* settings for DTC3181E card with only Mustek scanner attached */
62 #define USLEEP_POLL 1
63 #define USLEEP_SLEEP 20
64 #define USLEEP_WAITLONG 500
65
66 #define AUTOPROBE_IRQ
67
68 #ifdef CONFIG_SCSI_GENERIC_NCR53C400
69 #define NCR53C400_PSEUDO_DMA 1
70 #define PSEUDO_DMA
71 #define NCR53C400
72 #endif
73
74 #include <asm/io.h>
75 #include <linux/signal.h>
76 #include <linux/blkdev.h>
77 #include "scsi.h"
78 #include <scsi/scsi_host.h>
79 #include "g_NCR5380.h"
80 #include "NCR5380.h"
81 #include <linux/stat.h>
82 #include <linux/init.h>
83 #include <linux/ioport.h>
84 #include <linux/isapnp.h>
85 #include <linux/delay.h>
86 #include <linux/interrupt.h>
87
88 #define NCR_NOT_SET 0
89 static int ncr_irq = NCR_NOT_SET;
90 static int ncr_dma = NCR_NOT_SET;
91 static int ncr_addr = NCR_NOT_SET;
92 static int ncr_5380 = NCR_NOT_SET;
93 static int ncr_53c400 = NCR_NOT_SET;
94 static int ncr_53c400a = NCR_NOT_SET;
95 static int dtc_3181e = NCR_NOT_SET;
96
97 static struct override {
98 NCR5380_map_type NCR5380_map_name;
99 int irq;
100 int dma;
101 int board; /* Use NCR53c400, Ricoh, etc. extensions ? */
102 } overrides
103 #ifdef GENERIC_NCR5380_OVERRIDE
104 [] __initdata = GENERIC_NCR5380_OVERRIDE;
105 #else
106 [1] __initdata = { { 0,},};
107 #endif
108
109 #define NO_OVERRIDES ARRAY_SIZE(overrides)
110
111 #ifndef MODULE
112
113 /**
114 * internal_setup - handle lilo command string override
115 * @board: BOARD_* identifier for the board
116 * @str: unused
117 * @ints: numeric parameters
118 *
119 * Do LILO command line initialization of the overrides array. Display
120 * errors when needed
121 *
122 * Locks: none
123 */
124
125 static void __init internal_setup(int board, char *str, int *ints)
126 {
127 static int commandline_current = 0;
128 switch (board) {
129 case BOARD_NCR5380:
130 if (ints[0] != 2 && ints[0] != 3) {
131 printk(KERN_ERR "generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n");
132 return;
133 }
134 break;
135 case BOARD_NCR53C400:
136 if (ints[0] != 2) {
137 printk(KERN_ERR "generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n");
138 return;
139 }
140 break;
141 case BOARD_NCR53C400A:
142 if (ints[0] != 2) {
143 printk(KERN_ERR "generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n");
144 return;
145 }
146 break;
147 case BOARD_DTC3181E:
148 if (ints[0] != 2) {
149 printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n");
150 return;
151 }
152 break;
153 }
154
155 if (commandline_current < NO_OVERRIDES) {
156 overrides[commandline_current].NCR5380_map_name = (NCR5380_map_type) ints[1];
157 overrides[commandline_current].irq = ints[2];
158 if (ints[0] == 3)
159 overrides[commandline_current].dma = ints[3];
160 else
161 overrides[commandline_current].dma = DMA_NONE;
162 overrides[commandline_current].board = board;
163 ++commandline_current;
164 }
165 }
166
167
168 /**
169 * do_NCR53C80_setup - set up entry point
170 * @str: unused
171 *
172 * Setup function invoked at boot to parse the ncr5380= command
173 * line.
174 */
175
176 static int __init do_NCR5380_setup(char *str)
177 {
178 int ints[10];
179
180 get_options(str, ARRAY_SIZE(ints), ints);
181 internal_setup(BOARD_NCR5380, str, ints);
182 return 1;
183 }
184
185 /**
186 * do_NCR53C400_setup - set up entry point
187 * @str: unused
188 * @ints: integer parameters from kernel setup code
189 *
190 * Setup function invoked at boot to parse the ncr53c400= command
191 * line.
192 */
193
194 static int __init do_NCR53C400_setup(char *str)
195 {
196 int ints[10];
197
198 get_options(str, ARRAY_SIZE(ints), ints);
199 internal_setup(BOARD_NCR53C400, str, ints);
200 return 1;
201 }
202
203 /**
204 * do_NCR53C400A_setup - set up entry point
205 * @str: unused
206 * @ints: integer parameters from kernel setup code
207 *
208 * Setup function invoked at boot to parse the ncr53c400a= command
209 * line.
210 */
211
212 static int __init do_NCR53C400A_setup(char *str)
213 {
214 int ints[10];
215
216 get_options(str, ARRAY_SIZE(ints), ints);
217 internal_setup(BOARD_NCR53C400A, str, ints);
218 return 1;
219 }
220
221 /**
222 * do_DTC3181E_setup - set up entry point
223 * @str: unused
224 * @ints: integer parameters from kernel setup code
225 *
226 * Setup function invoked at boot to parse the dtc3181e= command
227 * line.
228 */
229
230 static int __init do_DTC3181E_setup(char *str)
231 {
232 int ints[10];
233
234 get_options(str, ARRAY_SIZE(ints), ints);
235 internal_setup(BOARD_DTC3181E, str, ints);
236 return 1;
237 }
238
239 #endif
240
241 /**
242 * generic_NCR5380_detect - look for NCR5380 controllers
243 * @tpnt: the scsi template
244 *
245 * Scan for the present of NCR5380, NCR53C400, NCR53C400A, DTC3181E
246 * and DTC436(ISAPnP) controllers. If overrides have been set we use
247 * them.
248 *
249 * The caller supplied NCR5380_init function is invoked from here, before
250 * the interrupt line is taken.
251 *
252 * Locks: none
253 */
254
255 static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt)
256 {
257 static int current_override = 0;
258 int count;
259 unsigned int *ports;
260 #ifndef SCSI_G_NCR5380_MEM
261 int i;
262 unsigned long region_size = 16;
263 #endif
264 static unsigned int __initdata ncr_53c400a_ports[] = {
265 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
266 };
267 static unsigned int __initdata dtc_3181e_ports[] = {
268 0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0
269 };
270 int flags = 0;
271 struct Scsi_Host *instance;
272 #ifdef SCSI_G_NCR5380_MEM
273 unsigned long base;
274 void __iomem *iomem;
275 #endif
276
277 if (ncr_irq != NCR_NOT_SET)
278 overrides[0].irq = ncr_irq;
279 if (ncr_dma != NCR_NOT_SET)
280 overrides[0].dma = ncr_dma;
281 if (ncr_addr != NCR_NOT_SET)
282 overrides[0].NCR5380_map_name = (NCR5380_map_type) ncr_addr;
283 if (ncr_5380 != NCR_NOT_SET)
284 overrides[0].board = BOARD_NCR5380;
285 else if (ncr_53c400 != NCR_NOT_SET)
286 overrides[0].board = BOARD_NCR53C400;
287 else if (ncr_53c400a != NCR_NOT_SET)
288 overrides[0].board = BOARD_NCR53C400A;
289 else if (dtc_3181e != NCR_NOT_SET)
290 overrides[0].board = BOARD_DTC3181E;
291 #ifndef SCSI_G_NCR5380_MEM
292 if (!current_override && isapnp_present()) {
293 struct pnp_dev *dev = NULL;
294 count = 0;
295 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) {
296 if (count >= NO_OVERRIDES)
297 break;
298 if (pnp_device_attach(dev) < 0)
299 continue;
300 if (pnp_activate_dev(dev) < 0) {
301 printk(KERN_ERR "dtc436e probe: activate failed\n");
302 pnp_device_detach(dev);
303 continue;
304 }
305 if (!pnp_port_valid(dev, 0)) {
306 printk(KERN_ERR "dtc436e probe: no valid port\n");
307 pnp_device_detach(dev);
308 continue;
309 }
310 if (pnp_irq_valid(dev, 0))
311 overrides[count].irq = pnp_irq(dev, 0);
312 else
313 overrides[count].irq = NO_IRQ;
314 if (pnp_dma_valid(dev, 0))
315 overrides[count].dma = pnp_dma(dev, 0);
316 else
317 overrides[count].dma = DMA_NONE;
318 overrides[count].NCR5380_map_name = (NCR5380_map_type) pnp_port_start(dev, 0);
319 overrides[count].board = BOARD_DTC3181E;
320 count++;
321 }
322 }
323 #endif
324 tpnt->proc_name = "g_NCR5380";
325
326 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
327 if (!(overrides[current_override].NCR5380_map_name))
328 continue;
329
330 ports = NULL;
331 switch (overrides[current_override].board) {
332 case BOARD_NCR5380:
333 flags = FLAG_NO_PSEUDO_DMA;
334 break;
335 case BOARD_NCR53C400:
336 flags = FLAG_NCR53C400;
337 break;
338 case BOARD_NCR53C400A:
339 flags = FLAG_NO_PSEUDO_DMA;
340 ports = ncr_53c400a_ports;
341 break;
342 case BOARD_DTC3181E:
343 flags = FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E;
344 ports = dtc_3181e_ports;
345 break;
346 }
347
348 #ifndef SCSI_G_NCR5380_MEM
349 if (ports) {
350 /* wakeup sequence for the NCR53C400A and DTC3181E */
351
352 /* Disable the adapter and look for a free io port */
353 outb(0x59, 0x779);
354 outb(0xb9, 0x379);
355 outb(0xc5, 0x379);
356 outb(0xae, 0x379);
357 outb(0xa6, 0x379);
358 outb(0x00, 0x379);
359
360 if (overrides[current_override].NCR5380_map_name != PORT_AUTO)
361 for (i = 0; ports[i]; i++) {
362 if (!request_region(ports[i], 16, "ncr53c80"))
363 continue;
364 if (overrides[current_override].NCR5380_map_name == ports[i])
365 break;
366 release_region(ports[i], 16);
367 } else
368 for (i = 0; ports[i]; i++) {
369 if (!request_region(ports[i], 16, "ncr53c80"))
370 continue;
371 if (inb(ports[i]) == 0xff)
372 break;
373 release_region(ports[i], 16);
374 }
375 if (ports[i]) {
376 /* At this point we have our region reserved */
377 outb(0x59, 0x779);
378 outb(0xb9, 0x379);
379 outb(0xc5, 0x379);
380 outb(0xae, 0x379);
381 outb(0xa6, 0x379);
382 outb(0x80 | i, 0x379); /* set io port to be used */
383 outb(0xc0, ports[i] + 9);
384 if (inb(ports[i] + 9) != 0x80)
385 continue;
386 else
387 overrides[current_override].NCR5380_map_name = ports[i];
388 } else
389 continue;
390 }
391 else
392 {
393 /* Not a 53C400A style setup - just grab */
394 if(!(request_region(overrides[current_override].NCR5380_map_name, NCR5380_region_size, "ncr5380")))
395 continue;
396 region_size = NCR5380_region_size;
397 }
398 #else
399 base = overrides[current_override].NCR5380_map_name;
400 if (!request_mem_region(base, NCR5380_region_size, "ncr5380"))
401 continue;
402 iomem = ioremap(base, NCR5380_region_size);
403 if (!iomem) {
404 release_mem_region(base, NCR5380_region_size);
405 continue;
406 }
407 #endif
408 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
409 if (instance == NULL) {
410 #ifndef SCSI_G_NCR5380_MEM
411 release_region(overrides[current_override].NCR5380_map_name, region_size);
412 #else
413 iounmap(iomem);
414 release_mem_region(base, NCR5380_region_size);
415 #endif
416 continue;
417 }
418
419 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
420 #ifndef SCSI_G_NCR5380_MEM
421 instance->n_io_port = region_size;
422 #else
423 ((struct NCR5380_hostdata *)instance->hostdata)->iomem = iomem;
424 #endif
425
426 NCR5380_init(instance, flags);
427
428 if (overrides[current_override].irq != IRQ_AUTO)
429 instance->irq = overrides[current_override].irq;
430 else
431 instance->irq = NCR5380_probe_irq(instance, 0xffff);
432
433 /* Compatibility with documented NCR5380 kernel parameters */
434 if (instance->irq == 255)
435 instance->irq = NO_IRQ;
436
437 if (instance->irq != NO_IRQ)
438 if (request_irq(instance->irq, generic_NCR5380_intr,
439 0, "NCR5380", instance)) {
440 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
441 instance->irq = NO_IRQ;
442 }
443
444 if (instance->irq == NO_IRQ) {
445 printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
446 printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
447 }
448
449 printk(KERN_INFO "scsi%d : at " STRVAL(NCR5380_map_name) " 0x%x", instance->host_no, (unsigned int) instance->NCR5380_instance_name);
450 if (instance->irq == NO_IRQ)
451 printk(" interrupts disabled");
452 else
453 printk(" irq %d", instance->irq);
454 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, GENERIC_NCR5380_PUBLIC_RELEASE);
455 NCR5380_print_options(instance);
456 printk("\n");
457
458 ++current_override;
459 ++count;
460 }
461 return count;
462 }
463
464 /**
465 * generic_NCR5380_info - reporting string
466 * @host: NCR5380 to report on
467 *
468 * Report driver information for the NCR5380
469 */
470
471 static const char *generic_NCR5380_info(struct Scsi_Host *host)
472 {
473 static const char string[] = "Generic NCR5380/53C400 Driver";
474 return string;
475 }
476
477 /**
478 * generic_NCR5380_release_resources - free resources
479 * @instance: host adapter to clean up
480 *
481 * Free the generic interface resources from this adapter.
482 *
483 * Locks: none
484 */
485
486 static int generic_NCR5380_release_resources(struct Scsi_Host *instance)
487 {
488 NCR5380_local_declare();
489 NCR5380_setup(instance);
490
491 if (instance->irq != NO_IRQ)
492 free_irq(instance->irq, instance);
493 NCR5380_exit(instance);
494
495 #ifndef SCSI_G_NCR5380_MEM
496 release_region(instance->NCR5380_instance_name, instance->n_io_port);
497 #else
498 iounmap(((struct NCR5380_hostdata *)instance->hostdata)->iomem);
499 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size);
500 #endif
501
502
503 return 0;
504 }
505
506 #ifdef BIOSPARAM
507 /**
508 * generic_NCR5380_biosparam
509 * @disk: disk to compute geometry for
510 * @dev: device identifier for this disk
511 * @ip: sizes to fill in
512 *
513 * Generates a BIOS / DOS compatible H-C-S mapping for the specified
514 * device / size.
515 *
516 * XXX Most SCSI boards use this mapping, I could be incorrect. Someone
517 * using hard disks on a trantor should verify that this mapping
518 * corresponds to that used by the BIOS / ASPI driver by running the linux
519 * fdisk program and matching the H_C_S coordinates to what DOS uses.
520 *
521 * Locks: none
522 */
523
524 static int
525 generic_NCR5380_biosparam(struct scsi_device *sdev, struct block_device *bdev,
526 sector_t capacity, int *ip)
527 {
528 ip[0] = 64;
529 ip[1] = 32;
530 ip[2] = capacity >> 11;
531 return 0;
532 }
533 #endif
534
535 #ifdef NCR53C400_PSEUDO_DMA
536
537 /**
538 * NCR5380_pread - pseudo DMA read
539 * @instance: adapter to read from
540 * @dst: buffer to read into
541 * @len: buffer length
542 *
543 * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
544 * controller
545 */
546
547 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
548 {
549 int blocks = len / 128;
550 int start = 0;
551 int bl;
552
553 NCR5380_local_declare();
554 NCR5380_setup(instance);
555
556 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE | CSR_TRANS_DIR);
557 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
558 while (1) {
559 if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
560 break;
561 }
562 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
563 printk(KERN_ERR "53C400r: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
564 return -1;
565 }
566 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY);
567
568 #ifndef SCSI_G_NCR5380_MEM
569 {
570 int i;
571 for (i = 0; i < 128; i++)
572 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
573 }
574 #else
575 /* implies SCSI_G_NCR5380_MEM */
576 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
577 #endif
578 start += 128;
579 blocks--;
580 }
581
582 if (blocks) {
583 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
584 {
585 // FIXME - no timeout
586 }
587
588 #ifndef SCSI_G_NCR5380_MEM
589 {
590 int i;
591 for (i = 0; i < 128; i++)
592 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
593 }
594 #else
595 /* implies SCSI_G_NCR5380_MEM */
596 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
597 #endif
598 start += 128;
599 blocks--;
600 }
601
602 if (!(NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
603 printk("53C400r: no 53C80 gated irq after transfer");
604
605 #if 0
606 /*
607 * DON'T DO THIS - THEY NEVER ARRIVE!
608 */
609 printk("53C400r: Waiting for 53C80 registers\n");
610 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG)
611 ;
612 #endif
613 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER))
614 printk(KERN_ERR "53C400r: no end dma signal\n");
615
616 NCR5380_write(MODE_REG, MR_BASE);
617 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
618 return 0;
619 }
620
621 /**
622 * NCR5380_write - pseudo DMA write
623 * @instance: adapter to read from
624 * @dst: buffer to read into
625 * @len: buffer length
626 *
627 * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
628 * controller
629 */
630
631 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
632 {
633 int blocks = len / 128;
634 int start = 0;
635 int bl;
636 int i;
637
638 NCR5380_local_declare();
639 NCR5380_setup(instance);
640
641 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE);
642 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
643 while (1) {
644 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
645 printk(KERN_ERR "53C400w: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
646 return -1;
647 }
648
649 if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
650 break;
651 }
652 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
653 ; // FIXME - timeout
654 #ifndef SCSI_G_NCR5380_MEM
655 {
656 for (i = 0; i < 128; i++)
657 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
658 }
659 #else
660 /* implies SCSI_G_NCR5380_MEM */
661 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
662 #endif
663 start += 128;
664 blocks--;
665 }
666 if (blocks) {
667 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
668 ; // FIXME - no timeout
669
670 #ifndef SCSI_G_NCR5380_MEM
671 {
672 for (i = 0; i < 128; i++)
673 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
674 }
675 #else
676 /* implies SCSI_G_NCR5380_MEM */
677 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
678 #endif
679 start += 128;
680 blocks--;
681 }
682
683 #if 0
684 printk("53C400w: waiting for registers to be available\n");
685 THEY NEVER DO ! while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG);
686 printk("53C400w: Got em\n");
687 #endif
688
689 /* Let's wait for this instead - could be ugly */
690 /* All documentation says to check for this. Maybe my hardware is too
691 * fast. Waiting for it seems to work fine! KLL
692 */
693 while (!(i = NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
694 ; // FIXME - no timeout
695
696 /*
697 * I know. i is certainly != 0 here but the loop is new. See previous
698 * comment.
699 */
700 if (i) {
701 if (!((i = NCR5380_read(BUS_AND_STATUS_REG)) & BASR_END_DMA_TRANSFER))
702 printk(KERN_ERR "53C400w: No END OF DMA bit - WHOOPS! BASR=%0x\n", i);
703 } else
704 printk(KERN_ERR "53C400w: no 53C80 gated irq after transfer (last block)\n");
705
706 #if 0
707 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) {
708 printk(KERN_ERR "53C400w: no end dma signal\n");
709 }
710 #endif
711 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
712 ; // TIMEOUT
713 return 0;
714 }
715 #endif /* PSEUDO_DMA */
716
717 /*
718 * Include the NCR5380 core code that we build our driver around
719 */
720
721 #include "NCR5380.c"
722
723 #define PRINTP(x) seq_printf(m, x)
724 #define ANDP ,
725
726 static void sprint_opcode(struct seq_file *m, int opcode)
727 {
728 PRINTP("0x%02x " ANDP opcode);
729 }
730
731 static void sprint_command(struct seq_file *m, unsigned char *command)
732 {
733 int i, s;
734 sprint_opcode(m, command[0]);
735 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
736 PRINTP("%02x " ANDP command[i]);
737 PRINTP("\n");
738 }
739
740 /**
741 * sprintf_Scsi_Cmnd - print a scsi command
742 * @m: seq_fil to print into
743 * @cmd: SCSI command block
744 *
745 * Print out the target and command data in hex
746 */
747
748 static void sprint_Scsi_Cmnd(struct seq_file *m, Scsi_Cmnd * cmd)
749 {
750 PRINTP("host number %d destination target %d, lun %llu\n" ANDP cmd->device->host->host_no ANDP cmd->device->id ANDP cmd->device->lun);
751 PRINTP(" command = ");
752 sprint_command(m, cmd->cmnd);
753 }
754
755 /**
756 * generic_NCR5380_proc_info - /proc for NCR5380 driver
757 * @buffer: buffer to print into
758 * @start: start position
759 * @offset: offset into buffer
760 * @len: length
761 * @hostno: instance to affect
762 * @inout: read/write
763 *
764 * Provide the procfs information for the 5380 controller. We fill
765 * this with useful debugging information including the commands
766 * being executed, disconnected command queue and the statistical
767 * data
768 *
769 * Locks: global cli/lock for queue walk
770 */
771
772 static int generic_NCR5380_show_info(struct seq_file *m, struct Scsi_Host *scsi_ptr)
773 {
774 NCR5380_local_declare();
775 unsigned long flags;
776 unsigned char status;
777 int i;
778 Scsi_Cmnd *ptr;
779 struct NCR5380_hostdata *hostdata;
780
781 NCR5380_setup(scsi_ptr);
782 hostdata = (struct NCR5380_hostdata *) scsi_ptr->hostdata;
783
784 spin_lock_irqsave(scsi_ptr->host_lock, flags);
785 PRINTP("SCSI host number %d : %s\n" ANDP scsi_ptr->host_no ANDP scsi_ptr->hostt->name);
786 PRINTP("Generic NCR5380 driver version %d\n" ANDP GENERIC_NCR5380_PUBLIC_RELEASE);
787 PRINTP("NCR5380 core version %d\n" ANDP NCR5380_PUBLIC_RELEASE);
788 #ifdef NCR53C400
789 PRINTP("NCR53C400 extension version %d\n" ANDP NCR53C400_PUBLIC_RELEASE);
790 PRINTP("NCR53C400 card%s detected\n" ANDP(((struct NCR5380_hostdata *) scsi_ptr->hostdata)->flags & FLAG_NCR53C400) ? "" : " not");
791 # if NCR53C400_PSEUDO_DMA
792 PRINTP("NCR53C400 pseudo DMA used\n");
793 # endif
794 #else
795 PRINTP("NO NCR53C400 driver extensions\n");
796 #endif
797 PRINTP("Using %s mapping at %s 0x%lx, " ANDP STRVAL(NCR5380_map_config) ANDP STRVAL(NCR5380_map_name) ANDP scsi_ptr->NCR5380_instance_name);
798 if (scsi_ptr->irq == NO_IRQ)
799 PRINTP("no interrupt\n");
800 else
801 PRINTP("on interrupt %d\n" ANDP scsi_ptr->irq);
802
803 status = NCR5380_read(STATUS_REG);
804 if (!(status & SR_REQ))
805 PRINTP("REQ not asserted, phase unknown.\n");
806 else {
807 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && (phases[i].value != (status & PHASE_MASK)); ++i);
808 PRINTP("Phase %s\n" ANDP phases[i].name);
809 }
810
811 if (!hostdata->connected) {
812 PRINTP("No currently connected command\n");
813 } else {
814 sprint_Scsi_Cmnd(m, (Scsi_Cmnd *) hostdata->connected);
815 }
816
817 PRINTP("issue_queue\n");
818
819 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
820 sprint_Scsi_Cmnd(m, ptr);
821
822 PRINTP("disconnected_queue\n");
823
824 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
825 sprint_Scsi_Cmnd(m, ptr);
826
827 spin_unlock_irqrestore(scsi_ptr->host_lock, flags);
828 return 0;
829 }
830
831 #undef PRINTP
832 #undef ANDP
833
834 static struct scsi_host_template driver_template = {
835 .show_info = generic_NCR5380_show_info,
836 .name = "Generic NCR5380/NCR53C400 Scsi Driver",
837 .detect = generic_NCR5380_detect,
838 .release = generic_NCR5380_release_resources,
839 .info = generic_NCR5380_info,
840 .queuecommand = generic_NCR5380_queue_command,
841 .eh_abort_handler = generic_NCR5380_abort,
842 .eh_bus_reset_handler = generic_NCR5380_bus_reset,
843 .bios_param = NCR5380_BIOSPARAM,
844 .can_queue = CAN_QUEUE,
845 .this_id = 7,
846 .sg_tablesize = SG_ALL,
847 .cmd_per_lun = CMD_PER_LUN,
848 .use_clustering = DISABLE_CLUSTERING,
849 };
850 #include <linux/module.h>
851 #include "scsi_module.c"
852
853 module_param(ncr_irq, int, 0);
854 module_param(ncr_dma, int, 0);
855 module_param(ncr_addr, int, 0);
856 module_param(ncr_5380, int, 0);
857 module_param(ncr_53c400, int, 0);
858 module_param(ncr_53c400a, int, 0);
859 module_param(dtc_3181e, int, 0);
860 MODULE_LICENSE("GPL");
861
862 #ifndef SCSI_G_NCR5380_MEM
863 static struct isapnp_device_id id_table[] = {
864 {
865 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
866 ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e),
867 0},
868 {0}
869 };
870
871 MODULE_DEVICE_TABLE(isapnp, id_table);
872 #endif
873
874 __setup("ncr5380=", do_NCR5380_setup);
875 __setup("ncr53c400=", do_NCR53C400_setup);
876 __setup("ncr53c400a=", do_NCR53C400A_setup);
877 __setup("dtc3181e=", do_DTC3181E_setup);