arxescsi.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * linux/drivers/scsi/arm/arxescsi.c
  3. *
  4. * Copyright (C) 1997-2000 Russell King, Stefan Hanske
  5. *
  6. * This driver is based on experimentation. Hence, it may have made
  7. * assumptions about the particular card that I have available, and
  8. * may not be reliable!
  9. *
  10. * Changelog:
  11. * 30-08-1997 RMK 0.0.0 Created, READONLY version as cumana_2.c
  12. * 22-01-1998 RMK 0.0.1 Updated to 2.1.80
  13. * 15-04-1998 RMK 0.0.1 Only do PIO if FAS216 will allow it.
  14. * 11-06-1998 SH 0.0.2 Changed to support ARXE 16-bit SCSI card
  15. * enabled writing
  16. * 01-01-2000 SH 0.1.0 Added *real* pseudo dma writing
  17. * (arxescsi_pseudo_dma_write)
  18. * 02-04-2000 RMK 0.1.1 Updated for new error handling code.
  19. * 22-10-2000 SH Updated for new registering scheme.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/kernel.h>
  24. #include <linux/string.h>
  25. #include <linux/ioport.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/unistd.h>
  28. #include <linux/stat.h>
  29. #include <linux/delay.h>
  30. #include <linux/init.h>
  31. #include <linux/interrupt.h>
  32. #include <asm/dma.h>
  33. #include <asm/io.h>
  34. #include <asm/ecard.h>
  35. #include "../scsi.h"
  36. #include <scsi/scsi_host.h>
  37. #include "fas216.h"
  38. struct arxescsi_info {
  39. FAS216_Info info;
  40. struct expansion_card *ec;
  41. void __iomem *base;
  42. };
  43. #define DMADATA_OFFSET (0x200)
  44. #define DMASTAT_OFFSET (0x600)
  45. #define DMASTAT_DRQ (1 << 0)
  46. #define CSTATUS_IRQ (1 << 0)
  47. #define VERSION "1.10 (23/01/2003 2.5.57)"
  48. /*
  49. * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
  50. * Purpose : initialises DMA/PIO
  51. * Params : host - host
  52. * SCpnt - command
  53. * direction - DMA on to/off of card
  54. * min_type - minimum DMA support that we must have for this transfer
  55. * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
  56. */
  57. static fasdmatype_t
  58. arxescsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
  59. fasdmadir_t direction, fasdmatype_t min_type)
  60. {
  61. /*
  62. * We don't do real DMA
  63. */
  64. return fasdma_pseudo;
  65. }
  66. static void arxescsi_pseudo_dma_write(unsigned char *addr, void __iomem *base)
  67. {
  68. __asm__ __volatile__(
  69. " stmdb sp!, {r0-r12}\n"
  70. " mov r3, %0\n"
  71. " mov r1, %1\n"
  72. " add r2, r1, #512\n"
  73. " mov r4, #256\n"
  74. ".loop_1: ldmia r3!, {r6, r8, r10, r12}\n"
  75. " mov r5, r6, lsl #16\n"
  76. " mov r7, r8, lsl #16\n"
  77. ".loop_2: ldrb r0, [r1, #1536]\n"
  78. " tst r0, #1\n"
  79. " beq .loop_2\n"
  80. " stmia r2, {r5-r8}\n\t"
  81. " mov r9, r10, lsl #16\n"
  82. " mov r11, r12, lsl #16\n"
  83. ".loop_3: ldrb r0, [r1, #1536]\n"
  84. " tst r0, #1\n"
  85. " beq .loop_3\n"
  86. " stmia r2, {r9-r12}\n"
  87. " subs r4, r4, #16\n"
  88. " bne .loop_1\n"
  89. " ldmia sp!, {r0-r12}\n"
  90. :
  91. : "r" (addr), "r" (base));
  92. }
  93. /*
  94. * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
  95. * Purpose : handles pseudo DMA
  96. * Params : host - host
  97. * SCpnt - command
  98. * direction - DMA on to/off of card
  99. * transfer - minimum number of bytes we expect to transfer
  100. */
  101. static void
  102. arxescsi_dma_pseudo(struct Scsi_Host *host, struct scsi_pointer *SCp,
  103. fasdmadir_t direction, int transfer)
  104. {
  105. struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
  106. unsigned int length, error = 0;
  107. void __iomem *base = info->info.scsi.io_base;
  108. unsigned char *addr;
  109. length = SCp->this_residual;
  110. addr = SCp->ptr;
  111. if (direction == DMA_OUT) {
  112. unsigned int word;
  113. while (length > 256) {
  114. if (readb(base + 0x80) & STAT_INT) {
  115. error = 1;
  116. break;
  117. }
  118. arxescsi_pseudo_dma_write(addr, base);
  119. addr += 256;
  120. length -= 256;
  121. }
  122. if (!error)
  123. while (length > 0) {
  124. if (readb(base + 0x80) & STAT_INT)
  125. break;
  126. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  127. continue;
  128. word = *addr | *(addr + 1) << 8;
  129. writew(word, base + DMADATA_OFFSET);
  130. if (length > 1) {
  131. addr += 2;
  132. length -= 2;
  133. } else {
  134. addr += 1;
  135. length -= 1;
  136. }
  137. }
  138. }
  139. else {
  140. if (transfer && (transfer & 255)) {
  141. while (length >= 256) {
  142. if (readb(base + 0x80) & STAT_INT) {
  143. error = 1;
  144. break;
  145. }
  146. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  147. continue;
  148. readsw(base + DMADATA_OFFSET, addr, 256 >> 1);
  149. addr += 256;
  150. length -= 256;
  151. }
  152. }
  153. if (!(error))
  154. while (length > 0) {
  155. unsigned long word;
  156. if (readb(base + 0x80) & STAT_INT)
  157. break;
  158. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  159. continue;
  160. word = readw(base + DMADATA_OFFSET);
  161. *addr++ = word;
  162. if (--length > 0) {
  163. *addr++ = word >> 8;
  164. length --;
  165. }
  166. }
  167. }
  168. }
  169. /*
  170. * Function: int arxescsi_dma_stop(host, SCpnt)
  171. * Purpose : stops DMA/PIO
  172. * Params : host - host
  173. * SCpnt - command
  174. */
  175. static void arxescsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
  176. {
  177. /*
  178. * no DMA to stop
  179. */
  180. }
  181. /*
  182. * Function: const char *arxescsi_info(struct Scsi_Host * host)
  183. * Purpose : returns a descriptive string about this interface,
  184. * Params : host - driver host structure to return info for.
  185. * Returns : pointer to a static buffer containing null terminated string.
  186. */
  187. static const char *arxescsi_info(struct Scsi_Host *host)
  188. {
  189. struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
  190. static char string[150];
  191. sprintf(string, "%s (%s) in slot %d v%s",
  192. host->hostt->name, info->info.scsi.type, info->ec->slot_no,
  193. VERSION);
  194. return string;
  195. }
  196. static int
  197. arxescsi_show_info(struct seq_file *m, struct Scsi_Host *host)
  198. {
  199. struct arxescsi_info *info;
  200. info = (struct arxescsi_info *)host->hostdata;
  201. seq_printf(m, "ARXE 16-bit SCSI driver v%s\n", VERSION);
  202. fas216_print_host(&info->info, m);
  203. fas216_print_stats(&info->info, m);
  204. fas216_print_devices(&info->info, m);
  205. return 0;
  206. }
  207. static struct scsi_host_template arxescsi_template = {
  208. .show_info = arxescsi_show_info,
  209. .name = "ARXE SCSI card",
  210. .info = arxescsi_info,
  211. .queuecommand = fas216_noqueue_command,
  212. .eh_host_reset_handler = fas216_eh_host_reset,
  213. .eh_bus_reset_handler = fas216_eh_bus_reset,
  214. .eh_device_reset_handler = fas216_eh_device_reset,
  215. .eh_abort_handler = fas216_eh_abort,
  216. .can_queue = 0,
  217. .this_id = 7,
  218. .sg_tablesize = SG_ALL,
  219. .use_clustering = DISABLE_CLUSTERING,
  220. .proc_name = "arxescsi",
  221. };
  222. static int arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  223. {
  224. struct Scsi_Host *host;
  225. struct arxescsi_info *info;
  226. void __iomem *base;
  227. int ret;
  228. ret = ecard_request_resources(ec);
  229. if (ret)
  230. goto out;
  231. base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
  232. if (!base) {
  233. ret = -ENOMEM;
  234. goto out_region;
  235. }
  236. host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info));
  237. if (!host) {
  238. ret = -ENOMEM;
  239. goto out_region;
  240. }
  241. info = (struct arxescsi_info *)host->hostdata;
  242. info->ec = ec;
  243. info->base = base;
  244. info->info.scsi.io_base = base + 0x2000;
  245. info->info.scsi.irq = 0;
  246. info->info.scsi.dma = NO_DMA;
  247. info->info.scsi.io_shift = 5;
  248. info->info.ifcfg.clockrate = 24; /* MHz */
  249. info->info.ifcfg.select_timeout = 255;
  250. info->info.ifcfg.asyncperiod = 200; /* ns */
  251. info->info.ifcfg.sync_max_depth = 0;
  252. info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
  253. info->info.ifcfg.disconnect_ok = 0;
  254. info->info.ifcfg.wide_max_size = 0;
  255. info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
  256. info->info.dma.setup = arxescsi_dma_setup;
  257. info->info.dma.pseudo = arxescsi_dma_pseudo;
  258. info->info.dma.stop = arxescsi_dma_stop;
  259. ec->irqaddr = base;
  260. ec->irqmask = CSTATUS_IRQ;
  261. ret = fas216_init(host);
  262. if (ret)
  263. goto out_unregister;
  264. ret = fas216_add(host, &ec->dev);
  265. if (ret == 0)
  266. goto out;
  267. fas216_release(host);
  268. out_unregister:
  269. scsi_host_put(host);
  270. out_region:
  271. ecard_release_resources(ec);
  272. out:
  273. return ret;
  274. }
  275. static void arxescsi_remove(struct expansion_card *ec)
  276. {
  277. struct Scsi_Host *host = ecard_get_drvdata(ec);
  278. ecard_set_drvdata(ec, NULL);
  279. fas216_remove(host);
  280. fas216_release(host);
  281. scsi_host_put(host);
  282. ecard_release_resources(ec);
  283. }
  284. static const struct ecard_id arxescsi_cids[] = {
  285. { MANU_ARXE, PROD_ARXE_SCSI },
  286. { 0xffff, 0xffff },
  287. };
  288. static struct ecard_driver arxescsi_driver = {
  289. .probe = arxescsi_probe,
  290. .remove = arxescsi_remove,
  291. .id_table = arxescsi_cids,
  292. .drv = {
  293. .name = "arxescsi",
  294. },
  295. };
  296. static int __init init_arxe_scsi_driver(void)
  297. {
  298. return ecard_register_driver(&arxescsi_driver);
  299. }
  300. static void __exit exit_arxe_scsi_driver(void)
  301. {
  302. ecard_remove_driver(&arxescsi_driver);
  303. }
  304. module_init(init_arxe_scsi_driver);
  305. module_exit(exit_arxe_scsi_driver);
  306. MODULE_AUTHOR("Stefan Hanske");
  307. MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
  308. MODULE_LICENSE("GPL");