t128.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. #define AUTOSENSE
  2. #define PSEUDO_DMA
  3. /*
  4. * Trantor T128/T128F/T228 driver
  5. * Note : architecturally, the T100 and T130 are different and won't
  6. * work
  7. *
  8. * Copyright 1993, Drew Eckhardt
  9. * Visionary Computing
  10. * (Unix and Linux consulting and custom programming)
  11. * drew@colorado.edu
  12. * +1 (303) 440-4894
  13. *
  14. * DISTRIBUTION RELEASE 3.
  15. *
  16. * For more information, please consult
  17. *
  18. * Trantor Systems, Ltd.
  19. * T128/T128F/T228 SCSI Host Adapter
  20. * Hardware Specifications
  21. *
  22. * Trantor Systems, Ltd.
  23. * 5415 Randall Place
  24. * Fremont, CA 94538
  25. * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
  26. *
  27. * and
  28. *
  29. * NCR 5380 Family
  30. * SCSI Protocol Controller
  31. * Databook
  32. *
  33. * NCR Microelectronics
  34. * 1635 Aeroplaza Drive
  35. * Colorado Springs, CO 80916
  36. * 1+ (719) 578-3400
  37. * 1+ (800) 334-5454
  38. */
  39. /*
  40. * Options :
  41. * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  42. * for commands that return with a CHECK CONDITION status.
  43. *
  44. * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
  45. * increase compared to polled I/O.
  46. *
  47. * PARITY - enable parity checking. Not supported.
  48. *
  49. * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
  50. *
  51. *
  52. * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. You
  53. * only really want to use this if you're having a problem with
  54. * dropped characters during high speed communications, and even
  55. * then, you're going to be better off twiddling with transfersize.
  56. *
  57. * USLEEP - enable support for devices that don't disconnect. Untested.
  58. *
  59. * The card is detected and initialized in one of several ways :
  60. * 1. Autoprobe (default) - since the board is memory mapped,
  61. * a BIOS signature is scanned for to locate the registers.
  62. * An interrupt is triggered to autoprobe for the interrupt
  63. * line.
  64. *
  65. * 2. With command line overrides - t128=address,irq may be
  66. * used on the LILO command line to override the defaults.
  67. *
  68. * 3. With the T128_OVERRIDE compile time define. This is
  69. * specified as an array of address, irq tuples. Ie, for
  70. * one board at the default 0xcc000 address, IRQ5, I could say
  71. * -DT128_OVERRIDE={{0xcc000, 5}}
  72. *
  73. * Note that if the override methods are used, place holders must
  74. * be specified for other boards in the system.
  75. *
  76. * T128/T128F jumper/dipswitch settings (note : on my sample, the switches
  77. * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) :
  78. *
  79. * T128 Sw7 Sw8 Sw6 = 0ws Sw5 = boot
  80. * T128F Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable
  81. * cc000 off off
  82. * c8000 off on
  83. * dc000 on off
  84. * d8000 on on
  85. *
  86. *
  87. * Interrupts
  88. * There is a 12 pin jumper block, jp1, numbered as follows :
  89. * T128 (JP1) T128F (J5)
  90. * 2 4 6 8 10 12 11 9 7 5 3 1
  91. * 1 3 5 7 9 11 12 10 8 6 4 2
  92. *
  93. * 3 2-4
  94. * 5 1-3
  95. * 7 3-5
  96. * T128F only
  97. * 10 8-10
  98. * 12 7-9
  99. * 14 10-12
  100. * 15 9-11
  101. */
  102. /*
  103. * $Log: t128.c,v $
  104. */
  105. #include <linux/signal.h>
  106. #include <linux/io.h>
  107. #include <linux/blkdev.h>
  108. #include <linux/interrupt.h>
  109. #include <linux/stat.h>
  110. #include <linux/init.h>
  111. #include <linux/module.h>
  112. #include <linux/delay.h>
  113. #include "scsi.h"
  114. #include <scsi/scsi_host.h>
  115. #include "t128.h"
  116. #define AUTOPROBE_IRQ
  117. #include "NCR5380.h"
  118. static struct override {
  119. unsigned long address;
  120. int irq;
  121. } overrides
  122. #ifdef T128_OVERRIDE
  123. [] __initdata = T128_OVERRIDE;
  124. #else
  125. [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
  126. {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
  127. #endif
  128. #define NO_OVERRIDES ARRAY_SIZE(overrides)
  129. static struct base {
  130. unsigned int address;
  131. int noauto;
  132. } bases[] __initdata = {
  133. { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
  134. };
  135. #define NO_BASES ARRAY_SIZE(bases)
  136. static struct signature {
  137. const char *string;
  138. int offset;
  139. } signatures[] __initdata = {
  140. {"TSROM: SCSI BIOS, Version 1.12", 0x36},
  141. };
  142. #define NO_SIGNATURES ARRAY_SIZE(signatures)
  143. /*
  144. * Function : t128_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. void __init t128_setup(char *str, int *ints){
  153. static int commandline_current = 0;
  154. int i;
  155. if (ints[0] != 2)
  156. printk("t128_setup : usage t128=address,irq\n");
  157. else
  158. 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. /*
  170. * Function : int t128_detect(struct scsi_host_template * tpnt)
  171. *
  172. * Purpose : detects and initializes T128,T128F, or T228 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. int __init t128_detect(struct scsi_host_template * tpnt){
  182. static int current_override = 0, current_base = 0;
  183. struct Scsi_Host *instance;
  184. unsigned long base;
  185. void __iomem *p;
  186. int sig, count;
  187. tpnt->proc_name = "t128";
  188. tpnt->proc_info = &t128_proc_info;
  189. for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
  190. base = 0;
  191. p = NULL;
  192. if (overrides[current_override].address) {
  193. base = overrides[current_override].address;
  194. p = ioremap(bases[current_base].address, 0x2000);
  195. if (!p)
  196. base = 0;
  197. } else
  198. for (; !base && (current_base < NO_BASES); ++current_base) {
  199. #if (TDEBUG & TDEBUG_INIT)
  200. printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
  201. #endif
  202. if (bases[current_base].noauto)
  203. continue;
  204. p = ioremap(bases[current_base].address, 0x2000);
  205. if (!p)
  206. continue;
  207. for (sig = 0; sig < NO_SIGNATURES; ++sig)
  208. if (check_signature(p + signatures[sig].offset,
  209. signatures[sig].string,
  210. strlen(signatures[sig].string))) {
  211. base = bases[current_base].address;
  212. #if (TDEBUG & TDEBUG_INIT)
  213. printk("scsi-t128 : detected board.\n");
  214. #endif
  215. goto found;
  216. }
  217. iounmap(p);
  218. }
  219. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  220. printk("scsi-t128 : base = %08x\n", (unsigned int) base);
  221. #endif
  222. if (!base)
  223. break;
  224. found:
  225. instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
  226. if(instance == NULL)
  227. break;
  228. instance->base = base;
  229. ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
  230. NCR5380_init(instance, 0);
  231. if (overrides[current_override].irq != IRQ_AUTO)
  232. instance->irq = overrides[current_override].irq;
  233. else
  234. instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
  235. if (instance->irq != SCSI_IRQ_NONE)
  236. if (request_irq(instance->irq, t128_intr, IRQF_DISABLED, "t128",
  237. instance)) {
  238. printk("scsi%d : IRQ%d not free, interrupts disabled\n",
  239. instance->host_no, instance->irq);
  240. instance->irq = SCSI_IRQ_NONE;
  241. }
  242. if (instance->irq == SCSI_IRQ_NONE) {
  243. printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
  244. printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
  245. }
  246. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  247. printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
  248. #endif
  249. printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
  250. if (instance->irq == SCSI_IRQ_NONE)
  251. printk (" interrupts disabled");
  252. else
  253. printk (" irq %d", instance->irq);
  254. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  255. CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
  256. NCR5380_print_options(instance);
  257. printk("\n");
  258. ++current_override;
  259. ++count;
  260. }
  261. return count;
  262. }
  263. static int t128_release(struct Scsi_Host *shost)
  264. {
  265. NCR5380_local_declare();
  266. NCR5380_setup(shost);
  267. if (shost->irq)
  268. free_irq(shost->irq, shost);
  269. NCR5380_exit(shost);
  270. if (shost->io_port && shost->n_io_port)
  271. release_region(shost->io_port, shost->n_io_port);
  272. scsi_unregister(shost);
  273. iounmap(base);
  274. return 0;
  275. }
  276. /*
  277. * Function : int t128_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. int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  295. sector_t capacity, int * ip)
  296. {
  297. ip[0] = 64;
  298. ip[1] = 32;
  299. ip[2] = capacity >> 11;
  300. return 0;
  301. }
  302. /*
  303. * Function : int NCR5380_pread (struct Scsi_Host *instance,
  304. * unsigned char *dst, int len)
  305. *
  306. * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to
  307. * dst
  308. *
  309. * Inputs : dst = destination, len = length in bytes
  310. *
  311. * Returns : 0 on success, non zero on a failure such as a watchdog
  312. * timeout.
  313. */
  314. static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
  315. int len) {
  316. NCR5380_local_declare();
  317. void __iomem *reg;
  318. unsigned char *d = dst;
  319. register int i = len;
  320. NCR5380_setup(instance);
  321. reg = base + T_DATA_REG_OFFSET;
  322. #if 0
  323. for (; i; --i) {
  324. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  325. #else
  326. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  327. for (; i; --i) {
  328. #endif
  329. *d++ = readb(reg);
  330. }
  331. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  332. unsigned char tmp;
  333. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  334. tmp = readb(foo);
  335. writeb(tmp | T_CR_CT, foo);
  336. writeb(tmp, foo);
  337. printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
  338. instance->host_no);
  339. return -1;
  340. } else
  341. return 0;
  342. }
  343. /*
  344. * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
  345. * unsigned char *src, int len)
  346. *
  347. * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
  348. * src
  349. *
  350. * Inputs : src = source, len = length in bytes
  351. *
  352. * Returns : 0 on success, non zero on a failure such as a watchdog
  353. * timeout.
  354. */
  355. static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
  356. int len) {
  357. NCR5380_local_declare();
  358. void __iomem *reg;
  359. unsigned char *s = src;
  360. register int i = len;
  361. NCR5380_setup(instance);
  362. reg = base + T_DATA_REG_OFFSET;
  363. #if 0
  364. for (; i; --i) {
  365. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  366. #else
  367. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  368. for (; i; --i) {
  369. #endif
  370. writeb(*s++, reg);
  371. }
  372. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  373. unsigned char tmp;
  374. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  375. tmp = readb(foo);
  376. writeb(tmp | T_CR_CT, foo);
  377. writeb(tmp, foo);
  378. printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
  379. instance->host_no);
  380. return -1;
  381. } else
  382. return 0;
  383. }
  384. MODULE_LICENSE("GPL");
  385. #include "NCR5380.c"
  386. static struct scsi_host_template driver_template = {
  387. .name = "Trantor T128/T128F/T228",
  388. .detect = t128_detect,
  389. .release = t128_release,
  390. .queuecommand = t128_queue_command,
  391. .eh_abort_handler = t128_abort,
  392. .eh_bus_reset_handler = t128_bus_reset,
  393. .bios_param = t128_biosparam,
  394. .can_queue = CAN_QUEUE,
  395. .this_id = 7,
  396. .sg_tablesize = SG_ALL,
  397. .cmd_per_lun = CMD_PER_LUN,
  398. .use_clustering = DISABLE_CLUSTERING,
  399. };
  400. #include "scsi_module.c"