dtc.c 13 KB

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