cumana_1.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * Generic Generic NCR5380 driver
  3. *
  4. * Copyright 1995-2002, Russell King
  5. */
  6. #include <linux/module.h>
  7. #include <linux/ioport.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/init.h>
  10. #include <asm/ecard.h>
  11. #include <asm/io.h>
  12. #include <scsi/scsi_host.h>
  13. #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
  14. #define NCR5380_read(reg) cumanascsi_read(hostdata, reg)
  15. #define NCR5380_write(reg, value) cumanascsi_write(hostdata, reg, value)
  16. #define NCR5380_dma_xfer_len cumanascsi_dma_xfer_len
  17. #define NCR5380_dma_recv_setup cumanascsi_pread
  18. #define NCR5380_dma_send_setup cumanascsi_pwrite
  19. #define NCR5380_dma_residual NCR5380_dma_residual_none
  20. #define NCR5380_intr cumanascsi_intr
  21. #define NCR5380_queue_command cumanascsi_queue_command
  22. #define NCR5380_info cumanascsi_info
  23. #define NCR5380_implementation_fields \
  24. unsigned ctrl
  25. struct NCR5380_hostdata;
  26. static u8 cumanascsi_read(struct NCR5380_hostdata *, unsigned int);
  27. static void cumanascsi_write(struct NCR5380_hostdata *, unsigned int, u8);
  28. #include "../NCR5380.h"
  29. #define CTRL 0x16fc
  30. #define STAT 0x2004
  31. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  32. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  33. static inline int cumanascsi_pwrite(struct NCR5380_hostdata *hostdata,
  34. unsigned char *addr, int len)
  35. {
  36. unsigned long *laddr;
  37. u8 __iomem *base = hostdata->io;
  38. u8 __iomem *dma = hostdata->pdma_io + 0x2000;
  39. if(!len) return 0;
  40. writeb(0x02, base + CTRL);
  41. laddr = (unsigned long *)addr;
  42. while(len >= 32)
  43. {
  44. unsigned int status;
  45. unsigned long v;
  46. status = readb(base + STAT);
  47. if(status & 0x80)
  48. goto end;
  49. if(!(status & 0x40))
  50. continue;
  51. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  52. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  53. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  54. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  55. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  56. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  57. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  58. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  59. len -= 32;
  60. if(len == 0)
  61. break;
  62. }
  63. addr = (unsigned char *)laddr;
  64. writeb(0x12, base + CTRL);
  65. while(len > 0)
  66. {
  67. unsigned int status;
  68. status = readb(base + STAT);
  69. if(status & 0x80)
  70. goto end;
  71. if(status & 0x40)
  72. {
  73. writeb(*addr++, dma);
  74. if(--len == 0)
  75. break;
  76. }
  77. status = readb(base + STAT);
  78. if(status & 0x80)
  79. goto end;
  80. if(status & 0x40)
  81. {
  82. writeb(*addr++, dma);
  83. if(--len == 0)
  84. break;
  85. }
  86. }
  87. end:
  88. writeb(hostdata->ctrl | 0x40, base + CTRL);
  89. if (len)
  90. return -1;
  91. return 0;
  92. }
  93. static inline int cumanascsi_pread(struct NCR5380_hostdata *hostdata,
  94. unsigned char *addr, int len)
  95. {
  96. unsigned long *laddr;
  97. u8 __iomem *base = hostdata->io;
  98. u8 __iomem *dma = hostdata->pdma_io + 0x2000;
  99. if(!len) return 0;
  100. writeb(0x00, base + CTRL);
  101. laddr = (unsigned long *)addr;
  102. while(len >= 32)
  103. {
  104. unsigned int status;
  105. status = readb(base + STAT);
  106. if(status & 0x80)
  107. goto end;
  108. if(!(status & 0x40))
  109. continue;
  110. *laddr++ = readw(dma) | (readw(dma) << 16);
  111. *laddr++ = readw(dma) | (readw(dma) << 16);
  112. *laddr++ = readw(dma) | (readw(dma) << 16);
  113. *laddr++ = readw(dma) | (readw(dma) << 16);
  114. *laddr++ = readw(dma) | (readw(dma) << 16);
  115. *laddr++ = readw(dma) | (readw(dma) << 16);
  116. *laddr++ = readw(dma) | (readw(dma) << 16);
  117. *laddr++ = readw(dma) | (readw(dma) << 16);
  118. len -= 32;
  119. if(len == 0)
  120. break;
  121. }
  122. addr = (unsigned char *)laddr;
  123. writeb(0x10, base + CTRL);
  124. while(len > 0)
  125. {
  126. unsigned int status;
  127. status = readb(base + STAT);
  128. if(status & 0x80)
  129. goto end;
  130. if(status & 0x40)
  131. {
  132. *addr++ = readb(dma);
  133. if(--len == 0)
  134. break;
  135. }
  136. status = readb(base + STAT);
  137. if(status & 0x80)
  138. goto end;
  139. if(status & 0x40)
  140. {
  141. *addr++ = readb(dma);
  142. if(--len == 0)
  143. break;
  144. }
  145. }
  146. end:
  147. writeb(hostdata->ctrl | 0x40, base + CTRL);
  148. if (len)
  149. return -1;
  150. return 0;
  151. }
  152. static int cumanascsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
  153. struct scsi_cmnd *cmd)
  154. {
  155. return cmd->transfersize;
  156. }
  157. static u8 cumanascsi_read(struct NCR5380_hostdata *hostdata,
  158. unsigned int reg)
  159. {
  160. u8 __iomem *base = hostdata->io;
  161. u8 val;
  162. writeb(0, base + CTRL);
  163. val = readb(base + 0x2100 + (reg << 2));
  164. hostdata->ctrl = 0x40;
  165. writeb(0x40, base + CTRL);
  166. return val;
  167. }
  168. static void cumanascsi_write(struct NCR5380_hostdata *hostdata,
  169. unsigned int reg, u8 value)
  170. {
  171. u8 __iomem *base = hostdata->io;
  172. writeb(0, base + CTRL);
  173. writeb(value, base + 0x2100 + (reg << 2));
  174. hostdata->ctrl = 0x40;
  175. writeb(0x40, base + CTRL);
  176. }
  177. #include "../NCR5380.c"
  178. static struct scsi_host_template cumanascsi_template = {
  179. .module = THIS_MODULE,
  180. .name = "Cumana 16-bit SCSI",
  181. .info = cumanascsi_info,
  182. .queuecommand = cumanascsi_queue_command,
  183. .eh_abort_handler = NCR5380_abort,
  184. .eh_host_reset_handler = NCR5380_host_reset,
  185. .can_queue = 16,
  186. .this_id = 7,
  187. .sg_tablesize = SG_ALL,
  188. .cmd_per_lun = 2,
  189. .use_clustering = DISABLE_CLUSTERING,
  190. .proc_name = "CumanaSCSI-1",
  191. .cmd_size = NCR5380_CMD_SIZE,
  192. .max_sectors = 128,
  193. };
  194. static int cumanascsi1_probe(struct expansion_card *ec,
  195. const struct ecard_id *id)
  196. {
  197. struct Scsi_Host *host;
  198. int ret;
  199. ret = ecard_request_resources(ec);
  200. if (ret)
  201. goto out;
  202. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  203. if (!host) {
  204. ret = -ENOMEM;
  205. goto out_release;
  206. }
  207. priv(host)->io = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
  208. ecard_resource_len(ec, ECARD_RES_IOCSLOW));
  209. priv(host)->pdma_io = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  210. ecard_resource_len(ec, ECARD_RES_MEMC));
  211. if (!priv(host)->io || !priv(host)->pdma_io) {
  212. ret = -ENOMEM;
  213. goto out_unmap;
  214. }
  215. host->irq = ec->irq;
  216. ret = NCR5380_init(host, FLAG_DMA_FIXUP | FLAG_LATE_DMA_SETUP);
  217. if (ret)
  218. goto out_unmap;
  219. NCR5380_maybe_reset_bus(host);
  220. priv(host)->ctrl = 0;
  221. writeb(0, priv(host)->io + CTRL);
  222. ret = request_irq(host->irq, cumanascsi_intr, 0,
  223. "CumanaSCSI-1", host);
  224. if (ret) {
  225. printk("scsi%d: IRQ%d not free: %d\n",
  226. host->host_no, host->irq, ret);
  227. goto out_exit;
  228. }
  229. ret = scsi_add_host(host, &ec->dev);
  230. if (ret)
  231. goto out_free_irq;
  232. scsi_scan_host(host);
  233. goto out;
  234. out_free_irq:
  235. free_irq(host->irq, host);
  236. out_exit:
  237. NCR5380_exit(host);
  238. out_unmap:
  239. iounmap(priv(host)->io);
  240. iounmap(priv(host)->pdma_io);
  241. scsi_host_put(host);
  242. out_release:
  243. ecard_release_resources(ec);
  244. out:
  245. return ret;
  246. }
  247. static void cumanascsi1_remove(struct expansion_card *ec)
  248. {
  249. struct Scsi_Host *host = ecard_get_drvdata(ec);
  250. void __iomem *base = priv(host)->io;
  251. void __iomem *dma = priv(host)->pdma_io;
  252. ecard_set_drvdata(ec, NULL);
  253. scsi_remove_host(host);
  254. free_irq(host->irq, host);
  255. NCR5380_exit(host);
  256. scsi_host_put(host);
  257. iounmap(base);
  258. iounmap(dma);
  259. ecard_release_resources(ec);
  260. }
  261. static const struct ecard_id cumanascsi1_cids[] = {
  262. { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
  263. { 0xffff, 0xffff }
  264. };
  265. static struct ecard_driver cumanascsi1_driver = {
  266. .probe = cumanascsi1_probe,
  267. .remove = cumanascsi1_remove,
  268. .id_table = cumanascsi1_cids,
  269. .drv = {
  270. .name = "cumanascsi1",
  271. },
  272. };
  273. static int __init cumanascsi_init(void)
  274. {
  275. return ecard_register_driver(&cumanascsi1_driver);
  276. }
  277. static void __exit cumanascsi_exit(void)
  278. {
  279. ecard_remove_driver(&cumanascsi1_driver);
  280. }
  281. module_init(cumanascsi_init);
  282. module_exit(cumanascsi_exit);
  283. MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
  284. MODULE_LICENSE("GPL");