dtc.c 12 KB

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