arxescsi.c 9.0 KB

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