arxescsi.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * linux/arch/arm/drivers/scsi/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/sched.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/unistd.h>
  29. #include <linux/stat.h>
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/interrupt.h>
  33. #include <asm/dma.h>
  34. #include <asm/io.h>
  35. #include <asm/irq.h>
  36. #include <asm/ecard.h>
  37. #include "../scsi.h"
  38. #include <scsi/scsi_host.h>
  39. #include "fas216.h"
  40. struct arxescsi_info {
  41. FAS216_Info info;
  42. struct expansion_card *ec;
  43. void __iomem *base;
  44. };
  45. #define DMADATA_OFFSET (0x200)
  46. #define DMASTAT_OFFSET (0x600)
  47. #define DMASTAT_DRQ (1 << 0)
  48. #define CSTATUS_IRQ (1 << 0)
  49. #define VERSION "1.10 (23/01/2003 2.5.57)"
  50. /*
  51. * Function: int arxescsi_dma_setup(host, SCpnt, direction, min_type)
  52. * Purpose : initialises DMA/PIO
  53. * Params : host - host
  54. * SCpnt - command
  55. * direction - DMA on to/off of card
  56. * min_type - minimum DMA support that we must have for this transfer
  57. * Returns : 0 if we should not set CMD_WITHDMA for transfer info command
  58. */
  59. static fasdmatype_t
  60. arxescsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
  61. fasdmadir_t direction, fasdmatype_t min_type)
  62. {
  63. /*
  64. * We don't do real DMA
  65. */
  66. return fasdma_pseudo;
  67. }
  68. static void arxescsi_pseudo_dma_write(unsigned char *addr, void __iomem *base)
  69. {
  70. __asm__ __volatile__(
  71. " stmdb sp!, {r0-r12}\n"
  72. " mov r3, %0\n"
  73. " mov r1, %1\n"
  74. " add r2, r1, #512\n"
  75. " mov r4, #256\n"
  76. ".loop_1: ldmia r3!, {r6, r8, r10, r12}\n"
  77. " mov r5, r6, lsl #16\n"
  78. " mov r7, r8, lsl #16\n"
  79. ".loop_2: ldrb r0, [r1, #1536]\n"
  80. " tst r0, #1\n"
  81. " beq .loop_2\n"
  82. " stmia r2, {r5-r8}\n\t"
  83. " mov r9, r10, lsl #16\n"
  84. " mov r11, r12, lsl #16\n"
  85. ".loop_3: ldrb r0, [r1, #1536]\n"
  86. " tst r0, #1\n"
  87. " beq .loop_3\n"
  88. " stmia r2, {r9-r12}\n"
  89. " subs r4, r4, #16\n"
  90. " bne .loop_1\n"
  91. " ldmia sp!, {r0-r12}\n"
  92. :
  93. : "r" (addr), "r" (base));
  94. }
  95. /*
  96. * Function: int arxescsi_dma_pseudo(host, SCpnt, direction, transfer)
  97. * Purpose : handles pseudo DMA
  98. * Params : host - host
  99. * SCpnt - command
  100. * direction - DMA on to/off of card
  101. * transfer - minimum number of bytes we expect to transfer
  102. */
  103. static void
  104. arxescsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
  105. fasdmadir_t direction, int transfer)
  106. {
  107. struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
  108. unsigned int length, error = 0;
  109. void __iomem *base = info->info.scsi.io_base;
  110. unsigned char *addr;
  111. length = SCp->this_residual;
  112. addr = SCp->ptr;
  113. if (direction == DMA_OUT) {
  114. unsigned int word;
  115. while (length > 256) {
  116. if (readb(base + 0x80) & STAT_INT) {
  117. error = 1;
  118. break;
  119. }
  120. arxescsi_pseudo_dma_write(addr, base);
  121. addr += 256;
  122. length -= 256;
  123. }
  124. if (!error)
  125. while (length > 0) {
  126. if (readb(base + 0x80) & STAT_INT)
  127. break;
  128. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  129. continue;
  130. word = *addr | *(addr + 1) << 8;
  131. writew(word, base + DMADATA_OFFSET);
  132. if (length > 1) {
  133. addr += 2;
  134. length -= 2;
  135. } else {
  136. addr += 1;
  137. length -= 1;
  138. }
  139. }
  140. }
  141. else {
  142. if (transfer && (transfer & 255)) {
  143. while (length >= 256) {
  144. if (readb(base + 0x80) & STAT_INT) {
  145. error = 1;
  146. break;
  147. }
  148. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  149. continue;
  150. readsw(base + DMADATA_OFFSET, addr, 256 >> 1);
  151. addr += 256;
  152. length -= 256;
  153. }
  154. }
  155. if (!(error))
  156. while (length > 0) {
  157. unsigned long word;
  158. if (readb(base + 0x80) & STAT_INT)
  159. break;
  160. if (!(readb(base + DMASTAT_OFFSET) & DMASTAT_DRQ))
  161. continue;
  162. word = readw(base + DMADATA_OFFSET);
  163. *addr++ = word;
  164. if (--length > 0) {
  165. *addr++ = word >> 8;
  166. length --;
  167. }
  168. }
  169. }
  170. }
  171. /*
  172. * Function: int arxescsi_dma_stop(host, SCpnt)
  173. * Purpose : stops DMA/PIO
  174. * Params : host - host
  175. * SCpnt - command
  176. */
  177. static void arxescsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
  178. {
  179. /*
  180. * no DMA to stop
  181. */
  182. }
  183. /*
  184. * Function: const char *arxescsi_info(struct Scsi_Host * host)
  185. * Purpose : returns a descriptive string about this interface,
  186. * Params : host - driver host structure to return info for.
  187. * Returns : pointer to a static buffer containing null terminated string.
  188. */
  189. static const char *arxescsi_info(struct Scsi_Host *host)
  190. {
  191. struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
  192. static char string[150];
  193. sprintf(string, "%s (%s) in slot %d v%s",
  194. host->hostt->name, info->info.scsi.type, info->ec->slot_no,
  195. VERSION);
  196. return string;
  197. }
  198. /*
  199. * Function: int arxescsi_proc_info(char *buffer, char **start, off_t offset,
  200. * int length, int host_no, int inout)
  201. * Purpose : Return information about the driver to a user process accessing
  202. * the /proc filesystem.
  203. * Params : buffer - a buffer to write information to
  204. * start - a pointer into this buffer set by this routine to the start
  205. * of the required information.
  206. * offset - offset into information that we have read upto.
  207. * length - length of buffer
  208. * host_no - host number to return information for
  209. * inout - 0 for reading, 1 for writing.
  210. * Returns : length of data written to buffer.
  211. */
  212. static int
  213. arxescsi_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length,
  214. int inout)
  215. {
  216. struct arxescsi_info *info;
  217. char *p = buffer;
  218. int pos;
  219. info = (struct arxescsi_info *)host->hostdata;
  220. if (inout == 1)
  221. return -EINVAL;
  222. p += sprintf(p, "ARXE 16-bit SCSI driver v%s\n", VERSION);
  223. p += fas216_print_host(&info->info, p);
  224. p += fas216_print_stats(&info->info, p);
  225. p += fas216_print_devices(&info->info, p);
  226. *start = buffer + offset;
  227. pos = p - buffer - offset;
  228. if (pos > length)
  229. pos = length;
  230. return pos;
  231. }
  232. static Scsi_Host_Template arxescsi_template = {
  233. .proc_info = arxescsi_proc_info,
  234. .name = "ARXE SCSI card",
  235. .info = arxescsi_info,
  236. .queuecommand = fas216_noqueue_command,
  237. .eh_host_reset_handler = fas216_eh_host_reset,
  238. .eh_bus_reset_handler = fas216_eh_bus_reset,
  239. .eh_device_reset_handler = fas216_eh_device_reset,
  240. .eh_abort_handler = fas216_eh_abort,
  241. .can_queue = 0,
  242. .this_id = 7,
  243. .sg_tablesize = SG_ALL,
  244. .cmd_per_lun = 1,
  245. .use_clustering = DISABLE_CLUSTERING,
  246. .proc_name = "arxescsi",
  247. };
  248. static int __devinit
  249. arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  250. {
  251. struct Scsi_Host *host;
  252. struct arxescsi_info *info;
  253. unsigned long resbase, reslen;
  254. void __iomem *base;
  255. int ret;
  256. ret = ecard_request_resources(ec);
  257. if (ret)
  258. goto out;
  259. resbase = ecard_resource_start(ec, ECARD_RES_MEMC);
  260. reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
  261. base = ioremap(resbase, reslen);
  262. if (!base) {
  263. ret = -ENOMEM;
  264. goto out_region;
  265. }
  266. host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info));
  267. if (!host) {
  268. ret = -ENOMEM;
  269. goto out_unmap;
  270. }
  271. info = (struct arxescsi_info *)host->hostdata;
  272. info->ec = ec;
  273. info->base = base;
  274. info->info.scsi.io_base = base + 0x2000;
  275. info->info.scsi.irq = NO_IRQ;
  276. info->info.scsi.dma = NO_DMA;
  277. info->info.scsi.io_shift = 5;
  278. info->info.ifcfg.clockrate = 24; /* MHz */
  279. info->info.ifcfg.select_timeout = 255;
  280. info->info.ifcfg.asyncperiod = 200; /* ns */
  281. info->info.ifcfg.sync_max_depth = 0;
  282. info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
  283. info->info.ifcfg.disconnect_ok = 0;
  284. info->info.ifcfg.wide_max_size = 0;
  285. info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
  286. info->info.dma.setup = arxescsi_dma_setup;
  287. info->info.dma.pseudo = arxescsi_dma_pseudo;
  288. info->info.dma.stop = arxescsi_dma_stop;
  289. ec->irqaddr = base;
  290. ec->irqmask = CSTATUS_IRQ;
  291. ret = fas216_init(host);
  292. if (ret)
  293. goto out_unregister;
  294. ret = fas216_add(host, &ec->dev);
  295. if (ret == 0)
  296. goto out;
  297. fas216_release(host);
  298. out_unregister:
  299. scsi_host_put(host);
  300. out_unmap:
  301. iounmap(base);
  302. out_region:
  303. ecard_release_resources(ec);
  304. out:
  305. return ret;
  306. }
  307. static void __devexit arxescsi_remove(struct expansion_card *ec)
  308. {
  309. struct Scsi_Host *host = ecard_get_drvdata(ec);
  310. struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
  311. ecard_set_drvdata(ec, NULL);
  312. fas216_remove(host);
  313. iounmap(info->base);
  314. fas216_release(host);
  315. scsi_host_put(host);
  316. ecard_release_resources(ec);
  317. }
  318. static const struct ecard_id arxescsi_cids[] = {
  319. { MANU_ARXE, PROD_ARXE_SCSI },
  320. { 0xffff, 0xffff },
  321. };
  322. static struct ecard_driver arxescsi_driver = {
  323. .probe = arxescsi_probe,
  324. .remove = __devexit_p(arxescsi_remove),
  325. .id_table = arxescsi_cids,
  326. .drv = {
  327. .name = "arxescsi",
  328. },
  329. };
  330. static int __init init_arxe_scsi_driver(void)
  331. {
  332. return ecard_register_driver(&arxescsi_driver);
  333. }
  334. static void __exit exit_arxe_scsi_driver(void)
  335. {
  336. ecard_remove_driver(&arxescsi_driver);
  337. }
  338. module_init(init_arxe_scsi_driver);
  339. module_exit(exit_arxe_scsi_driver);
  340. MODULE_AUTHOR("Stefan Hanske");
  341. MODULE_DESCRIPTION("ARXESCSI driver for Acorn machines");
  342. MODULE_LICENSE("GPL");