g_NCR5380.c 26 KB

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