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