dtc.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. #define AUTOSENSE
  2. #define PSEUDO_DMA
  3. #define DONT_USE_INTR
  4. #define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */
  5. #define DMA_WORKS_RIGHT
  6. /*
  7. * DTC 3180/3280 driver, by
  8. * Ray Van Tassle rayvt@comm.mot.com
  9. *
  10. * taken from ...
  11. * Trantor T128/T128F/T228 driver by...
  12. *
  13. * Drew Eckhardt
  14. * Visionary Computing
  15. * (Unix and Linux consulting and custom programming)
  16. * drew@colorado.edu
  17. * +1 (303) 440-4894
  18. *
  19. * DISTRIBUTION RELEASE 1.
  20. *
  21. * For more information, please consult
  22. *
  23. * NCR 5380 Family
  24. * SCSI Protocol Controller
  25. * Databook
  26. */
  27. /*
  28. * Options :
  29. * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  30. * for commands that return with a CHECK CONDITION status.
  31. *
  32. * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
  33. * increase compared to polled I/O.
  34. *
  35. * PARITY - enable parity checking. Not supported.
  36. *
  37. * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.
  38. * You probably want this.
  39. *
  40. * The card is detected and initialized in one of several ways :
  41. * 1. Autoprobe (default) - since the board is memory mapped,
  42. * a BIOS signature is scanned for to locate the registers.
  43. * An interrupt is triggered to autoprobe for the interrupt
  44. * line.
  45. *
  46. * 2. With command line overrides - dtc=address,irq may be
  47. * used on the LILO command line to override the defaults.
  48. *
  49. */
  50. /*----------------------------------------------------------------*/
  51. /* the following will set the monitor border color (useful to find
  52. where something crashed or gets stuck at */
  53. /* 1 = blue
  54. 2 = green
  55. 3 = cyan
  56. 4 = red
  57. 5 = magenta
  58. 6 = yellow
  59. 7 = white
  60. */
  61. #if 0
  62. #define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);}
  63. #else
  64. #define rtrc(i) {}
  65. #endif
  66. #include <linux/module.h>
  67. #include <linux/signal.h>
  68. #include <linux/blkdev.h>
  69. #include <linux/delay.h>
  70. #include <linux/stat.h>
  71. #include <linux/string.h>
  72. #include <linux/init.h>
  73. #include <linux/interrupt.h>
  74. #include <linux/io.h>
  75. #include "scsi.h"
  76. #include <scsi/scsi_host.h>
  77. #include "dtc.h"
  78. #define AUTOPROBE_IRQ
  79. #include "NCR5380.h"
  80. #define DTC_PUBLIC_RELEASE 2
  81. /*
  82. * The DTC3180 & 3280 boards are memory mapped.
  83. *
  84. */
  85. /*
  86. */
  87. /* Offset from DTC_5380_OFFSET */
  88. #define DTC_CONTROL_REG 0x100 /* rw */
  89. #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */
  90. #define CSR_DIR_READ 0x40 /* rw direction, 1 = read 0 = write */
  91. #define CSR_RESET 0x80 /* wo Resets 53c400 */
  92. #define CSR_5380_REG 0x80 /* ro 5380 registers can be accessed */
  93. #define CSR_TRANS_DIR 0x40 /* rw Data transfer direction */
  94. #define CSR_SCSI_BUFF_INTR 0x20 /* rw Enable int on transfer ready */
  95. #define CSR_5380_INTR 0x10 /* rw Enable 5380 interrupts */
  96. #define CSR_SHARED_INTR 0x08 /* rw Interrupt sharing */
  97. #define CSR_HOST_BUF_NOT_RDY 0x04 /* ro Host buffer not ready */
  98. #define CSR_SCSI_BUF_RDY 0x02 /* ro SCSI buffer ready */
  99. #define CSR_GATED_5380_IRQ 0x01 /* ro Last block xferred */
  100. #define CSR_INT_BASE (CSR_SCSI_BUFF_INTR | CSR_5380_INTR)
  101. #define DTC_BLK_CNT 0x101 /* rw
  102. * # of 128-byte blocks to transfer */
  103. #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */
  104. #define DTC_SWITCH_REG 0x3982 /* ro - DIP switches */
  105. #define DTC_RESUME_XFER 0x3982 /* wo - resume data xfer
  106. * after disconnect/reconnect*/
  107. #define DTC_5380_OFFSET 0x3880 /* 8 registers here, see NCR5380.h */
  108. /*!!!! for dtc, it's a 128 byte buffer at 3900 !!! */
  109. #define DTC_DATA_BUF 0x3900 /* rw 128 bytes long */
  110. static struct override {
  111. unsigned int address;
  112. int irq;
  113. } overrides
  114. #ifdef OVERRIDE
  115. [] __initdata = OVERRIDE;
  116. #else
  117. [4] __initdata = {
  118. { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }
  119. };
  120. #endif
  121. #define NO_OVERRIDES ARRAY_SIZE(overrides)
  122. static struct base {
  123. unsigned long address;
  124. int noauto;
  125. } bases[] __initdata = {
  126. { 0xcc000, 0 },
  127. { 0xc8000, 0 },
  128. { 0xdc000, 0 },
  129. { 0xd8000, 0 }
  130. };
  131. #define NO_BASES ARRAY_SIZE(bases)
  132. static const struct signature {
  133. const char *string;
  134. int offset;
  135. } signatures[] = {
  136. {"DATA TECHNOLOGY CORPORATION BIOS", 0x25},
  137. };
  138. #define NO_SIGNATURES ARRAY_SIZE(signatures)
  139. #ifndef MODULE
  140. /*
  141. * Function : dtc_setup(char *str, int *ints)
  142. *
  143. * Purpose : LILO command line initialization of the overrides array,
  144. *
  145. * Inputs : str - unused, ints - array of integer parameters with ints[0]
  146. * equal to the number of ints.
  147. *
  148. */
  149. static void __init dtc_setup(char *str, int *ints)
  150. {
  151. static int commandline_current = 0;
  152. int i;
  153. if (ints[0] != 2)
  154. printk("dtc_setup: usage dtc=address,irq\n");
  155. else if (commandline_current < NO_OVERRIDES) {
  156. overrides[commandline_current].address = ints[1];
  157. overrides[commandline_current].irq = ints[2];
  158. for (i = 0; i < NO_BASES; ++i)
  159. if (bases[i].address == ints[1]) {
  160. bases[i].noauto = 1;
  161. break;
  162. }
  163. ++commandline_current;
  164. }
  165. }
  166. #endif
  167. /*
  168. * Function : int dtc_detect(struct scsi_host_template * tpnt)
  169. *
  170. * Purpose : detects and initializes DTC 3180/3280 controllers
  171. * that were autoprobed, overridden on the LILO command line,
  172. * or specified at compile time.
  173. *
  174. * Inputs : tpnt - template for this SCSI adapter.
  175. *
  176. * Returns : 1 if a host adapter was found, 0 if not.
  177. *
  178. */
  179. static int __init dtc_detect(struct scsi_host_template * tpnt)
  180. {
  181. static int current_override = 0, current_base = 0;
  182. struct Scsi_Host *instance;
  183. unsigned int addr;
  184. void __iomem *base;
  185. int sig, count;
  186. tpnt->proc_name = "dtc3x80";
  187. tpnt->show_info = dtc_show_info;
  188. tpnt->write_info = dtc_write_info;
  189. for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
  190. addr = 0;
  191. base = NULL;
  192. if (overrides[current_override].address) {
  193. addr = overrides[current_override].address;
  194. base = ioremap(addr, 0x2000);
  195. if (!base)
  196. addr = 0;
  197. } else
  198. for (; !addr && (current_base < NO_BASES); ++current_base) {
  199. #if (DTCDEBUG & DTCDEBUG_INIT)
  200. printk(KERN_DEBUG "scsi-dtc : probing address %08x\n", bases[current_base].address);
  201. #endif
  202. if (bases[current_base].noauto)
  203. continue;
  204. base = ioremap(bases[current_base].address, 0x2000);
  205. if (!base)
  206. continue;
  207. for (sig = 0; sig < NO_SIGNATURES; ++sig) {
  208. if (check_signature(base + signatures[sig].offset, signatures[sig].string, strlen(signatures[sig].string))) {
  209. addr = bases[current_base].address;
  210. #if (DTCDEBUG & DTCDEBUG_INIT)
  211. printk(KERN_DEBUG "scsi-dtc : detected board.\n");
  212. #endif
  213. goto found;
  214. }
  215. }
  216. iounmap(base);
  217. }
  218. #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT)
  219. printk(KERN_DEBUG "scsi-dtc : base = %08x\n", addr);
  220. #endif
  221. if (!addr)
  222. break;
  223. found:
  224. instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
  225. if (instance == NULL)
  226. break;
  227. instance->base = addr;
  228. ((struct NCR5380_hostdata *)(instance)->hostdata)->base = base;
  229. NCR5380_init(instance, 0);
  230. NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); /* Enable int's */
  231. if (overrides[current_override].irq != IRQ_AUTO)
  232. instance->irq = overrides[current_override].irq;
  233. else
  234. instance->irq = NCR5380_probe_irq(instance, DTC_IRQS);
  235. #ifndef DONT_USE_INTR
  236. /* With interrupts enabled, it will sometimes hang when doing heavy
  237. * reads. So better not enable them until I finger it out. */
  238. if (instance->irq != SCSI_IRQ_NONE)
  239. if (request_irq(instance->irq, dtc_intr, 0,
  240. "dtc", instance)) {
  241. printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
  242. instance->irq = SCSI_IRQ_NONE;
  243. }
  244. if (instance->irq == SCSI_IRQ_NONE) {
  245. printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
  246. printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
  247. }
  248. #else
  249. if (instance->irq != SCSI_IRQ_NONE)
  250. printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no);
  251. instance->irq = SCSI_IRQ_NONE;
  252. #endif
  253. #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT)
  254. printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
  255. #endif
  256. printk(KERN_INFO "scsi%d : at 0x%05X", instance->host_no, (int) instance->base);
  257. if (instance->irq == SCSI_IRQ_NONE)
  258. printk(" interrupts disabled");
  259. else
  260. printk(" irq %d", instance->irq);
  261. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, DTC_PUBLIC_RELEASE);
  262. NCR5380_print_options(instance);
  263. printk("\n");
  264. ++current_override;
  265. ++count;
  266. }
  267. return count;
  268. }
  269. /*
  270. * Function : int dtc_biosparam(Disk * disk, struct block_device *dev, int *ip)
  271. *
  272. * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
  273. * the specified device / size.
  274. *
  275. * Inputs : size = size of device in sectors (512 bytes), dev = block device
  276. * major / minor, ip[] = {heads, sectors, cylinders}
  277. *
  278. * Returns : always 0 (success), initializes ip
  279. *
  280. */
  281. /*
  282. * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
  283. * using hard disks on a trantor should verify that this mapping corresponds
  284. * to that used by the BIOS / ASPI driver by running the linux fdisk program
  285. * and matching the H_C_S coordinates to what DOS uses.
  286. */
  287. static int dtc_biosparam(struct scsi_device *sdev, struct block_device *dev,
  288. sector_t capacity, int *ip)
  289. {
  290. int size = capacity;
  291. ip[0] = 64;
  292. ip[1] = 32;
  293. ip[2] = size >> 11;
  294. return 0;
  295. }
  296. /****************************************************************
  297. * Function : int NCR5380_pread (struct Scsi_Host *instance,
  298. * unsigned char *dst, int len)
  299. *
  300. * Purpose : Fast 5380 pseudo-dma read function, reads len bytes to
  301. * dst
  302. *
  303. * Inputs : dst = destination, len = length in bytes
  304. *
  305. * Returns : 0 on success, non zero on a failure such as a watchdog
  306. * timeout.
  307. */
  308. static int dtc_maxi = 0;
  309. static int dtc_wmaxi = 0;
  310. static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
  311. {
  312. unsigned char *d = dst;
  313. int i; /* For counting time spent in the poll-loop */
  314. NCR5380_local_declare();
  315. NCR5380_setup(instance);
  316. i = 0;
  317. NCR5380_read(RESET_PARITY_INTERRUPT_REG);
  318. NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
  319. if (instance->irq == SCSI_IRQ_NONE)
  320. NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ);
  321. else
  322. NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE);
  323. NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */
  324. rtrc(1);
  325. while (len > 0) {
  326. rtrc(2);
  327. while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY)
  328. ++i;
  329. rtrc(3);
  330. memcpy_fromio(d, base + DTC_DATA_BUF, 128);
  331. d += 128;
  332. len -= 128;
  333. rtrc(7);
  334. /*** with int's on, it sometimes hangs after here.
  335. * Looks like something makes HBNR go away. */
  336. }
  337. rtrc(4);
  338. while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS))
  339. ++i;
  340. NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
  341. rtrc(0);
  342. NCR5380_read(RESET_PARITY_INTERRUPT_REG);
  343. if (i > dtc_maxi)
  344. dtc_maxi = i;
  345. return (0);
  346. }
  347. /****************************************************************
  348. * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
  349. * unsigned char *src, int len)
  350. *
  351. * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
  352. * src
  353. *
  354. * Inputs : src = source, len = length in bytes
  355. *
  356. * Returns : 0 on success, non zero on a failure such as a watchdog
  357. * timeout.
  358. */
  359. static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
  360. {
  361. int i;
  362. NCR5380_local_declare();
  363. NCR5380_setup(instance);
  364. NCR5380_read(RESET_PARITY_INTERRUPT_REG);
  365. NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
  366. /* set direction (write) */
  367. if (instance->irq == SCSI_IRQ_NONE)
  368. NCR5380_write(DTC_CONTROL_REG, 0);
  369. else
  370. NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR);
  371. NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */
  372. for (i = 0; len > 0; ++i) {
  373. rtrc(5);
  374. /* Poll until the host buffer can accept data. */
  375. while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY)
  376. ++i;
  377. rtrc(3);
  378. memcpy_toio(base + DTC_DATA_BUF, src, 128);
  379. src += 128;
  380. len -= 128;
  381. }
  382. rtrc(4);
  383. while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS))
  384. ++i;
  385. rtrc(6);
  386. /* Wait until the last byte has been sent to the disk */
  387. while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
  388. ++i;
  389. rtrc(7);
  390. /* Check for parity error here. fixme. */
  391. NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
  392. rtrc(0);
  393. if (i > dtc_wmaxi)
  394. dtc_wmaxi = i;
  395. return (0);
  396. }
  397. MODULE_LICENSE("GPL");
  398. #include "NCR5380.c"
  399. static int dtc_release(struct Scsi_Host *shost)
  400. {
  401. NCR5380_local_declare();
  402. NCR5380_setup(shost);
  403. if (shost->irq)
  404. free_irq(shost->irq, shost);
  405. NCR5380_exit(shost);
  406. if (shost->io_port && shost->n_io_port)
  407. release_region(shost->io_port, shost->n_io_port);
  408. scsi_unregister(shost);
  409. iounmap(base);
  410. return 0;
  411. }
  412. static struct scsi_host_template driver_template = {
  413. .name = "DTC 3180/3280 ",
  414. .detect = dtc_detect,
  415. .release = dtc_release,
  416. .queuecommand = dtc_queue_command,
  417. .eh_abort_handler = dtc_abort,
  418. .eh_bus_reset_handler = dtc_bus_reset,
  419. .bios_param = dtc_biosparam,
  420. .can_queue = CAN_QUEUE,
  421. .this_id = 7,
  422. .sg_tablesize = SG_ALL,
  423. .cmd_per_lun = CMD_PER_LUN,
  424. .use_clustering = DISABLE_CLUSTERING,
  425. };
  426. #include "scsi_module.c"