g_NCR5380.c 25 KB

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