t128.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. #include <linux/signal.h>
  103. #include <linux/io.h>
  104. #include <linux/blkdev.h>
  105. #include <linux/interrupt.h>
  106. #include <linux/stat.h>
  107. #include <linux/init.h>
  108. #include <linux/module.h>
  109. #include <linux/delay.h>
  110. #include "scsi.h"
  111. #include <scsi/scsi_host.h>
  112. #include "t128.h"
  113. #define AUTOPROBE_IRQ
  114. #include "NCR5380.h"
  115. static struct override {
  116. unsigned long address;
  117. int irq;
  118. } overrides
  119. #ifdef T128_OVERRIDE
  120. [] __initdata = T128_OVERRIDE;
  121. #else
  122. [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
  123. {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
  124. #endif
  125. #define NO_OVERRIDES ARRAY_SIZE(overrides)
  126. static struct base {
  127. unsigned int address;
  128. int noauto;
  129. } bases[] __initdata = {
  130. { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
  131. };
  132. #define NO_BASES ARRAY_SIZE(bases)
  133. static struct signature {
  134. const char *string;
  135. int offset;
  136. } signatures[] __initdata = {
  137. {"TSROM: SCSI BIOS, Version 1.12", 0x36},
  138. };
  139. #define NO_SIGNATURES ARRAY_SIZE(signatures)
  140. /*
  141. * Function : t128_setup(char *str, int *ints)
  142. *
  143. * Purpose : LILO command line initialization of the overrides array,
  144. *
  145. * Inputs : str - unused, ints - array of integer parameters with ints[0]
  146. * equal to the number of ints.
  147. *
  148. */
  149. void __init t128_setup(char *str, int *ints){
  150. static int commandline_current = 0;
  151. int i;
  152. if (ints[0] != 2)
  153. printk("t128_setup : usage t128=address,irq\n");
  154. else
  155. if (commandline_current < NO_OVERRIDES) {
  156. overrides[commandline_current].address = ints[1];
  157. overrides[commandline_current].irq = ints[2];
  158. for (i = 0; i < NO_BASES; ++i)
  159. if (bases[i].address == ints[1]) {
  160. bases[i].noauto = 1;
  161. break;
  162. }
  163. ++commandline_current;
  164. }
  165. }
  166. /*
  167. * Function : int t128_detect(struct scsi_host_template * tpnt)
  168. *
  169. * Purpose : detects and initializes T128,T128F, or T228 controllers
  170. * that were autoprobed, overridden on the LILO command line,
  171. * or specified at compile time.
  172. *
  173. * Inputs : tpnt - template for this SCSI adapter.
  174. *
  175. * Returns : 1 if a host adapter was found, 0 if not.
  176. *
  177. */
  178. int __init t128_detect(struct scsi_host_template * tpnt){
  179. static int current_override = 0, current_base = 0;
  180. struct Scsi_Host *instance;
  181. unsigned long base;
  182. void __iomem *p;
  183. int sig, count;
  184. tpnt->proc_name = "t128";
  185. tpnt->show_info = t128_show_info;
  186. tpnt->write_info = t128_write_info;
  187. for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
  188. base = 0;
  189. p = NULL;
  190. if (overrides[current_override].address) {
  191. base = overrides[current_override].address;
  192. p = ioremap(bases[current_base].address, 0x2000);
  193. if (!p)
  194. base = 0;
  195. } else
  196. for (; !base && (current_base < NO_BASES); ++current_base) {
  197. #if (TDEBUG & TDEBUG_INIT)
  198. printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
  199. #endif
  200. if (bases[current_base].noauto)
  201. continue;
  202. p = ioremap(bases[current_base].address, 0x2000);
  203. if (!p)
  204. continue;
  205. for (sig = 0; sig < NO_SIGNATURES; ++sig)
  206. if (check_signature(p + signatures[sig].offset,
  207. signatures[sig].string,
  208. strlen(signatures[sig].string))) {
  209. base = bases[current_base].address;
  210. #if (TDEBUG & TDEBUG_INIT)
  211. printk("scsi-t128 : detected board.\n");
  212. #endif
  213. goto found;
  214. }
  215. iounmap(p);
  216. }
  217. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  218. printk("scsi-t128 : base = %08x\n", (unsigned int) base);
  219. #endif
  220. if (!base)
  221. break;
  222. found:
  223. instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
  224. if(instance == NULL)
  225. break;
  226. instance->base = base;
  227. ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
  228. NCR5380_init(instance, 0);
  229. if (overrides[current_override].irq != IRQ_AUTO)
  230. instance->irq = overrides[current_override].irq;
  231. else
  232. instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
  233. if (instance->irq != SCSI_IRQ_NONE)
  234. if (request_irq(instance->irq, t128_intr, 0, "t128",
  235. instance)) {
  236. printk("scsi%d : IRQ%d not free, interrupts disabled\n",
  237. instance->host_no, instance->irq);
  238. instance->irq = SCSI_IRQ_NONE;
  239. }
  240. if (instance->irq == SCSI_IRQ_NONE) {
  241. printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
  242. printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
  243. }
  244. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  245. printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
  246. #endif
  247. printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
  248. if (instance->irq == SCSI_IRQ_NONE)
  249. printk (" interrupts disabled");
  250. else
  251. printk (" irq %d", instance->irq);
  252. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  253. CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
  254. NCR5380_print_options(instance);
  255. printk("\n");
  256. ++current_override;
  257. ++count;
  258. }
  259. return count;
  260. }
  261. static int t128_release(struct Scsi_Host *shost)
  262. {
  263. NCR5380_local_declare();
  264. NCR5380_setup(shost);
  265. if (shost->irq)
  266. free_irq(shost->irq, shost);
  267. NCR5380_exit(shost);
  268. if (shost->io_port && shost->n_io_port)
  269. release_region(shost->io_port, shost->n_io_port);
  270. scsi_unregister(shost);
  271. iounmap(base);
  272. return 0;
  273. }
  274. /*
  275. * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip)
  276. *
  277. * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
  278. * the specified device / size.
  279. *
  280. * Inputs : size = size of device in sectors (512 bytes), dev = block device
  281. * major / minor, ip[] = {heads, sectors, cylinders}
  282. *
  283. * Returns : always 0 (success), initializes ip
  284. *
  285. */
  286. /*
  287. * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
  288. * using hard disks on a trantor should verify that this mapping corresponds
  289. * to that used by the BIOS / ASPI driver by running the linux fdisk program
  290. * and matching the H_C_S coordinates to what DOS uses.
  291. */
  292. int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  293. sector_t capacity, int * ip)
  294. {
  295. ip[0] = 64;
  296. ip[1] = 32;
  297. ip[2] = capacity >> 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, transfers 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 inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
  313. int len) {
  314. NCR5380_local_declare();
  315. void __iomem *reg;
  316. unsigned char *d = dst;
  317. register int i = len;
  318. NCR5380_setup(instance);
  319. reg = base + T_DATA_REG_OFFSET;
  320. #if 0
  321. for (; i; --i) {
  322. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  323. #else
  324. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  325. for (; i; --i) {
  326. #endif
  327. *d++ = readb(reg);
  328. }
  329. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  330. unsigned char tmp;
  331. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  332. tmp = readb(foo);
  333. writeb(tmp | T_CR_CT, foo);
  334. writeb(tmp, foo);
  335. printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
  336. instance->host_no);
  337. return -1;
  338. } else
  339. return 0;
  340. }
  341. /*
  342. * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
  343. * unsigned char *src, int len)
  344. *
  345. * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
  346. * src
  347. *
  348. * Inputs : src = source, len = length in bytes
  349. *
  350. * Returns : 0 on success, non zero on a failure such as a watchdog
  351. * timeout.
  352. */
  353. static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
  354. int len) {
  355. NCR5380_local_declare();
  356. void __iomem *reg;
  357. unsigned char *s = src;
  358. register int i = len;
  359. NCR5380_setup(instance);
  360. reg = base + T_DATA_REG_OFFSET;
  361. #if 0
  362. for (; i; --i) {
  363. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  364. #else
  365. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  366. for (; i; --i) {
  367. #endif
  368. writeb(*s++, reg);
  369. }
  370. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  371. unsigned char tmp;
  372. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  373. tmp = readb(foo);
  374. writeb(tmp | T_CR_CT, foo);
  375. writeb(tmp, foo);
  376. printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
  377. instance->host_no);
  378. return -1;
  379. } else
  380. return 0;
  381. }
  382. MODULE_LICENSE("GPL");
  383. #include "NCR5380.c"
  384. static struct scsi_host_template driver_template = {
  385. .name = "Trantor T128/T128F/T228",
  386. .detect = t128_detect,
  387. .release = t128_release,
  388. .queuecommand = t128_queue_command,
  389. .eh_abort_handler = t128_abort,
  390. .eh_bus_reset_handler = t128_bus_reset,
  391. .bios_param = t128_biosparam,
  392. .can_queue = CAN_QUEUE,
  393. .this_id = 7,
  394. .sg_tablesize = SG_ALL,
  395. .cmd_per_lun = CMD_PER_LUN,
  396. .use_clustering = DISABLE_CLUSTERING,
  397. };
  398. #include "scsi_module.c"