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