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