t128.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. #define PSEUDO_DMA
  2. /*
  3. * Trantor T128/T128F/T228 driver
  4. * Note : architecturally, the T100 and T130 are different and won't
  5. * work
  6. *
  7. * Copyright 1993, Drew Eckhardt
  8. * Visionary Computing
  9. * (Unix and Linux consulting and custom programming)
  10. * drew@colorado.edu
  11. * +1 (303) 440-4894
  12. *
  13. * For more information, please consult
  14. *
  15. * Trantor Systems, Ltd.
  16. * T128/T128F/T228 SCSI Host Adapter
  17. * Hardware Specifications
  18. *
  19. * Trantor Systems, Ltd.
  20. * 5415 Randall Place
  21. * Fremont, CA 94538
  22. * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
  23. */
  24. /*
  25. * The card is detected and initialized in one of several ways :
  26. * 1. Autoprobe (default) - since the board is memory mapped,
  27. * a BIOS signature is scanned for to locate the registers.
  28. * An interrupt is triggered to autoprobe for the interrupt
  29. * line.
  30. *
  31. * 2. With command line overrides - t128=address,irq may be
  32. * used on the LILO command line to override the defaults.
  33. *
  34. * 3. With the T128_OVERRIDE compile time define. This is
  35. * specified as an array of address, irq tuples. Ie, for
  36. * one board at the default 0xcc000 address, IRQ5, I could say
  37. * -DT128_OVERRIDE={{0xcc000, 5}}
  38. *
  39. * Note that if the override methods are used, place holders must
  40. * be specified for other boards in the system.
  41. *
  42. * T128/T128F jumper/dipswitch settings (note : on my sample, the switches
  43. * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) :
  44. *
  45. * T128 Sw7 Sw8 Sw6 = 0ws Sw5 = boot
  46. * T128F Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable
  47. * cc000 off off
  48. * c8000 off on
  49. * dc000 on off
  50. * d8000 on on
  51. *
  52. *
  53. * Interrupts
  54. * There is a 12 pin jumper block, jp1, numbered as follows :
  55. * T128 (JP1) T128F (J5)
  56. * 2 4 6 8 10 12 11 9 7 5 3 1
  57. * 1 3 5 7 9 11 12 10 8 6 4 2
  58. *
  59. * 3 2-4
  60. * 5 1-3
  61. * 7 3-5
  62. * T128F only
  63. * 10 8-10
  64. * 12 7-9
  65. * 14 10-12
  66. * 15 9-11
  67. */
  68. #include <linux/signal.h>
  69. #include <linux/io.h>
  70. #include <linux/blkdev.h>
  71. #include <linux/interrupt.h>
  72. #include <linux/stat.h>
  73. #include <linux/init.h>
  74. #include <linux/module.h>
  75. #include <linux/delay.h>
  76. #include <scsi/scsi_host.h>
  77. #include "t128.h"
  78. #define AUTOPROBE_IRQ
  79. #include "NCR5380.h"
  80. static struct override {
  81. unsigned long address;
  82. int irq;
  83. } overrides
  84. #ifdef T128_OVERRIDE
  85. [] __initdata = T128_OVERRIDE;
  86. #else
  87. [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
  88. {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
  89. #endif
  90. #define NO_OVERRIDES ARRAY_SIZE(overrides)
  91. static struct base {
  92. unsigned int address;
  93. int noauto;
  94. } bases[] __initdata = {
  95. { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
  96. };
  97. #define NO_BASES ARRAY_SIZE(bases)
  98. static struct signature {
  99. const char *string;
  100. int offset;
  101. } signatures[] __initdata = {
  102. {"TSROM: SCSI BIOS, Version 1.12", 0x36},
  103. };
  104. #define NO_SIGNATURES ARRAY_SIZE(signatures)
  105. #ifndef MODULE
  106. /*
  107. * Function : t128_setup(char *str, int *ints)
  108. *
  109. * Purpose : LILO command line initialization of the overrides array,
  110. *
  111. * Inputs : str - unused, ints - array of integer parameters with ints[0]
  112. * equal to the number of ints.
  113. *
  114. */
  115. static int __init t128_setup(char *str)
  116. {
  117. static int commandline_current = 0;
  118. int i;
  119. int ints[10];
  120. get_options(str, ARRAY_SIZE(ints), ints);
  121. if (ints[0] != 2)
  122. printk("t128_setup : usage t128=address,irq\n");
  123. else
  124. if (commandline_current < NO_OVERRIDES) {
  125. overrides[commandline_current].address = ints[1];
  126. overrides[commandline_current].irq = ints[2];
  127. for (i = 0; i < NO_BASES; ++i)
  128. if (bases[i].address == ints[1]) {
  129. bases[i].noauto = 1;
  130. break;
  131. }
  132. ++commandline_current;
  133. }
  134. return 1;
  135. }
  136. __setup("t128=", t128_setup);
  137. #endif
  138. /*
  139. * Function : int t128_detect(struct scsi_host_template * tpnt)
  140. *
  141. * Purpose : detects and initializes T128,T128F, or T228 controllers
  142. * that were autoprobed, overridden on the LILO command line,
  143. * or specified at compile time.
  144. *
  145. * Inputs : tpnt - template for this SCSI adapter.
  146. *
  147. * Returns : 1 if a host adapter was found, 0 if not.
  148. *
  149. */
  150. static int __init t128_detect(struct scsi_host_template *tpnt)
  151. {
  152. static int current_override = 0, current_base = 0;
  153. struct Scsi_Host *instance;
  154. unsigned long base;
  155. void __iomem *p;
  156. int sig, count;
  157. for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
  158. base = 0;
  159. p = NULL;
  160. if (overrides[current_override].address) {
  161. base = overrides[current_override].address;
  162. p = ioremap(bases[current_base].address, 0x2000);
  163. if (!p)
  164. base = 0;
  165. } else
  166. for (; !base && (current_base < NO_BASES); ++current_base) {
  167. #if (TDEBUG & TDEBUG_INIT)
  168. printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
  169. #endif
  170. if (bases[current_base].noauto)
  171. continue;
  172. p = ioremap(bases[current_base].address, 0x2000);
  173. if (!p)
  174. continue;
  175. for (sig = 0; sig < NO_SIGNATURES; ++sig)
  176. if (check_signature(p + signatures[sig].offset,
  177. signatures[sig].string,
  178. strlen(signatures[sig].string))) {
  179. base = bases[current_base].address;
  180. #if (TDEBUG & TDEBUG_INIT)
  181. printk("scsi-t128 : detected board.\n");
  182. #endif
  183. goto found;
  184. }
  185. iounmap(p);
  186. }
  187. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  188. printk("scsi-t128 : base = %08x\n", (unsigned int) base);
  189. #endif
  190. if (!base)
  191. break;
  192. found:
  193. instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
  194. if(instance == NULL)
  195. break;
  196. instance->base = base;
  197. ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
  198. NCR5380_init(instance, 0);
  199. if (overrides[current_override].irq != IRQ_AUTO)
  200. instance->irq = overrides[current_override].irq;
  201. else
  202. instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
  203. /* Compatibility with documented NCR5380 kernel parameters */
  204. if (instance->irq == 255)
  205. instance->irq = NO_IRQ;
  206. if (instance->irq != NO_IRQ)
  207. if (request_irq(instance->irq, t128_intr, 0, "t128",
  208. instance)) {
  209. printk("scsi%d : IRQ%d not free, interrupts disabled\n",
  210. instance->host_no, instance->irq);
  211. instance->irq = NO_IRQ;
  212. }
  213. if (instance->irq == NO_IRQ) {
  214. printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
  215. printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
  216. }
  217. #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
  218. printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
  219. #endif
  220. ++current_override;
  221. ++count;
  222. }
  223. return count;
  224. }
  225. static int t128_release(struct Scsi_Host *shost)
  226. {
  227. NCR5380_local_declare();
  228. NCR5380_setup(shost);
  229. if (shost->irq != NO_IRQ)
  230. free_irq(shost->irq, shost);
  231. NCR5380_exit(shost);
  232. if (shost->io_port && shost->n_io_port)
  233. release_region(shost->io_port, shost->n_io_port);
  234. scsi_unregister(shost);
  235. iounmap(base);
  236. return 0;
  237. }
  238. /*
  239. * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip)
  240. *
  241. * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
  242. * the specified device / size.
  243. *
  244. * Inputs : size = size of device in sectors (512 bytes), dev = block device
  245. * major / minor, ip[] = {heads, sectors, cylinders}
  246. *
  247. * Returns : always 0 (success), initializes ip
  248. *
  249. */
  250. /*
  251. * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
  252. * using hard disks on a trantor should verify that this mapping corresponds
  253. * to that used by the BIOS / ASPI driver by running the linux fdisk program
  254. * and matching the H_C_S coordinates to what DOS uses.
  255. */
  256. static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  257. sector_t capacity, int *ip)
  258. {
  259. ip[0] = 64;
  260. ip[1] = 32;
  261. ip[2] = capacity >> 11;
  262. return 0;
  263. }
  264. /*
  265. * Function : int NCR5380_pread (struct Scsi_Host *instance,
  266. * unsigned char *dst, int len)
  267. *
  268. * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to
  269. * dst
  270. *
  271. * Inputs : dst = destination, len = length in bytes
  272. *
  273. * Returns : 0 on success, non zero on a failure such as a watchdog
  274. * timeout.
  275. */
  276. static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
  277. int len) {
  278. NCR5380_local_declare();
  279. void __iomem *reg;
  280. unsigned char *d = dst;
  281. register int i = len;
  282. NCR5380_setup(instance);
  283. reg = base + T_DATA_REG_OFFSET;
  284. #if 0
  285. for (; i; --i) {
  286. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  287. #else
  288. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  289. for (; i; --i) {
  290. #endif
  291. *d++ = readb(reg);
  292. }
  293. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  294. unsigned char tmp;
  295. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  296. tmp = readb(foo);
  297. writeb(tmp | T_CR_CT, foo);
  298. writeb(tmp, foo);
  299. printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
  300. instance->host_no);
  301. return -1;
  302. } else
  303. return 0;
  304. }
  305. /*
  306. * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
  307. * unsigned char *src, int len)
  308. *
  309. * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
  310. * src
  311. *
  312. * Inputs : src = source, len = length in bytes
  313. *
  314. * Returns : 0 on success, non zero on a failure such as a watchdog
  315. * timeout.
  316. */
  317. static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
  318. int len) {
  319. NCR5380_local_declare();
  320. void __iomem *reg;
  321. unsigned char *s = src;
  322. register int i = len;
  323. NCR5380_setup(instance);
  324. reg = base + T_DATA_REG_OFFSET;
  325. #if 0
  326. for (; i; --i) {
  327. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  328. #else
  329. while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
  330. for (; i; --i) {
  331. #endif
  332. writeb(*s++, reg);
  333. }
  334. if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
  335. unsigned char tmp;
  336. void __iomem *foo = base + T_CONTROL_REG_OFFSET;
  337. tmp = readb(foo);
  338. writeb(tmp | T_CR_CT, foo);
  339. writeb(tmp, foo);
  340. printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
  341. instance->host_no);
  342. return -1;
  343. } else
  344. return 0;
  345. }
  346. MODULE_LICENSE("GPL");
  347. #include "NCR5380.c"
  348. static struct scsi_host_template driver_template = {
  349. .name = "Trantor T128/T128F/T228",
  350. .detect = t128_detect,
  351. .release = t128_release,
  352. .proc_name = "t128",
  353. .show_info = t128_show_info,
  354. .write_info = t128_write_info,
  355. .info = t128_info,
  356. .queuecommand = t128_queue_command,
  357. .eh_abort_handler = t128_abort,
  358. .eh_bus_reset_handler = t128_bus_reset,
  359. .bios_param = t128_biosparam,
  360. .can_queue = CAN_QUEUE,
  361. .this_id = 7,
  362. .sg_tablesize = SG_ALL,
  363. .cmd_per_lun = CMD_PER_LUN,
  364. .use_clustering = DISABLE_CLUSTERING,
  365. };
  366. #include "scsi_module.c"