dtc.c 13 KB

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