dtc.c 13 KB

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