arxescsi.c 10.0 KB

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