t128.c 12 KB

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