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