dtc.c 13 KB

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