/kern_oII/drivers/scsi/g_NCR5380.c

http://omnia2droid.googlecode.com/ · C · 956 lines · 618 code · 107 blank · 231 comment · 130 complexity · 99c9a23c482da06133625f80d854dd22 MD5 · raw file

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