cumana_1.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * Generic Generic NCR5380 driver
  3. *
  4. * Copyright 1995-2002, Russell King
  5. */
  6. #include <linux/module.h>
  7. #include <linux/signal.h>
  8. #include <linux/ioport.h>
  9. #include <linux/delay.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/init.h>
  12. #include <asm/ecard.h>
  13. #include <asm/io.h>
  14. #include "../scsi.h"
  15. #include <scsi/scsi_host.h>
  16. #include <scsi/scsicam.h>
  17. #define AUTOSENSE
  18. #define PSEUDO_DMA
  19. #define CUMANASCSI_PUBLIC_RELEASE 1
  20. #define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
  21. #define NCR5380_local_declare() struct Scsi_Host *_instance
  22. #define NCR5380_setup(instance) _instance = instance
  23. #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
  24. #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
  25. #define NCR5380_intr cumanascsi_intr
  26. #define NCR5380_queue_command cumanascsi_queue_command
  27. #define NCR5380_implementation_fields \
  28. unsigned ctrl; \
  29. void __iomem *base; \
  30. void __iomem *dma
  31. #include "../NCR5380.h"
  32. void cumanascsi_setup(char *str, int *ints)
  33. {
  34. }
  35. const char *cumanascsi_info(struct Scsi_Host *spnt)
  36. {
  37. return "";
  38. }
  39. #define CTRL 0x16fc
  40. #define STAT 0x2004
  41. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  42. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  43. static inline int
  44. NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
  45. {
  46. unsigned long *laddr;
  47. void __iomem *dma = priv(host)->dma + 0x2000;
  48. if(!len) return 0;
  49. writeb(0x02, priv(host)->base + CTRL);
  50. laddr = (unsigned long *)addr;
  51. while(len >= 32)
  52. {
  53. unsigned int status;
  54. unsigned long v;
  55. status = readb(priv(host)->base + STAT);
  56. if(status & 0x80)
  57. goto end;
  58. if(!(status & 0x40))
  59. continue;
  60. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  61. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  62. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  63. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  64. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  65. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  66. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  67. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  68. len -= 32;
  69. if(len == 0)
  70. break;
  71. }
  72. addr = (unsigned char *)laddr;
  73. writeb(0x12, priv(host)->base + CTRL);
  74. while(len > 0)
  75. {
  76. unsigned int status;
  77. status = readb(priv(host)->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. status = readb(priv(host)->base + STAT);
  87. if(status & 0x80)
  88. goto end;
  89. if(status & 0x40)
  90. {
  91. writeb(*addr++, dma);
  92. if(--len == 0)
  93. break;
  94. }
  95. }
  96. end:
  97. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  98. return len;
  99. }
  100. static inline int
  101. NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
  102. {
  103. unsigned long *laddr;
  104. void __iomem *dma = priv(host)->dma + 0x2000;
  105. if(!len) return 0;
  106. writeb(0x00, priv(host)->base + CTRL);
  107. laddr = (unsigned long *)addr;
  108. while(len >= 32)
  109. {
  110. unsigned int status;
  111. status = readb(priv(host)->base + STAT);
  112. if(status & 0x80)
  113. goto end;
  114. if(!(status & 0x40))
  115. continue;
  116. *laddr++ = readw(dma) | (readw(dma) << 16);
  117. *laddr++ = readw(dma) | (readw(dma) << 16);
  118. *laddr++ = readw(dma) | (readw(dma) << 16);
  119. *laddr++ = readw(dma) | (readw(dma) << 16);
  120. *laddr++ = readw(dma) | (readw(dma) << 16);
  121. *laddr++ = readw(dma) | (readw(dma) << 16);
  122. *laddr++ = readw(dma) | (readw(dma) << 16);
  123. *laddr++ = readw(dma) | (readw(dma) << 16);
  124. len -= 32;
  125. if(len == 0)
  126. break;
  127. }
  128. addr = (unsigned char *)laddr;
  129. writeb(0x10, priv(host)->base + CTRL);
  130. while(len > 0)
  131. {
  132. unsigned int status;
  133. status = readb(priv(host)->base + STAT);
  134. if(status & 0x80)
  135. goto end;
  136. if(status & 0x40)
  137. {
  138. *addr++ = readb(dma);
  139. if(--len == 0)
  140. break;
  141. }
  142. status = readb(priv(host)->base + STAT);
  143. if(status & 0x80)
  144. goto end;
  145. if(status & 0x40)
  146. {
  147. *addr++ = readb(dma);
  148. if(--len == 0)
  149. break;
  150. }
  151. }
  152. end:
  153. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  154. return len;
  155. }
  156. static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
  157. {
  158. void __iomem *base = priv(host)->base;
  159. unsigned char val;
  160. writeb(0, base + CTRL);
  161. val = readb(base + 0x2100 + (reg << 2));
  162. priv(host)->ctrl = 0x40;
  163. writeb(0x40, base + CTRL);
  164. return val;
  165. }
  166. static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
  167. {
  168. void __iomem *base = priv(host)->base;
  169. writeb(0, base + CTRL);
  170. writeb(value, base + 0x2100 + (reg << 2));
  171. priv(host)->ctrl = 0x40;
  172. writeb(0x40, base + CTRL);
  173. }
  174. #include "../NCR5380.c"
  175. static struct scsi_host_template cumanascsi_template = {
  176. .module = THIS_MODULE,
  177. .name = "Cumana 16-bit SCSI",
  178. .info = cumanascsi_info,
  179. .queuecommand = cumanascsi_queue_command,
  180. .eh_abort_handler = NCR5380_abort,
  181. .eh_bus_reset_handler = NCR5380_bus_reset,
  182. .can_queue = 16,
  183. .this_id = 7,
  184. .sg_tablesize = SG_ALL,
  185. .cmd_per_lun = 2,
  186. .use_clustering = DISABLE_CLUSTERING,
  187. .proc_name = "CumanaSCSI-1",
  188. };
  189. static int cumanascsi1_probe(struct expansion_card *ec,
  190. const struct ecard_id *id)
  191. {
  192. struct Scsi_Host *host;
  193. int ret;
  194. ret = ecard_request_resources(ec);
  195. if (ret)
  196. goto out;
  197. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  198. if (!host) {
  199. ret = -ENOMEM;
  200. goto out_release;
  201. }
  202. priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
  203. ecard_resource_len(ec, ECARD_RES_IOCSLOW));
  204. priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  205. ecard_resource_len(ec, ECARD_RES_MEMC));
  206. if (!priv(host)->base || !priv(host)->dma) {
  207. ret = -ENOMEM;
  208. goto out_unmap;
  209. }
  210. host->irq = ec->irq;
  211. NCR5380_init(host, 0);
  212. priv(host)->ctrl = 0;
  213. writeb(0, priv(host)->base + CTRL);
  214. host->n_io_port = 255;
  215. if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
  216. ret = -EBUSY;
  217. goto out_unmap;
  218. }
  219. ret = request_irq(host->irq, cumanascsi_intr, 0,
  220. "CumanaSCSI-1", host);
  221. if (ret) {
  222. printk("scsi%d: IRQ%d not free: %d\n",
  223. host->host_no, host->irq, ret);
  224. goto out_unmap;
  225. }
  226. printk("scsi%d: at port 0x%08lx irq %d",
  227. host->host_no, host->io_port, host->irq);
  228. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  229. host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
  230. printk("\nscsi%d:", host->host_no);
  231. NCR5380_print_options(host);
  232. printk("\n");
  233. ret = scsi_add_host(host, &ec->dev);
  234. if (ret)
  235. goto out_free_irq;
  236. scsi_scan_host(host);
  237. goto out;
  238. out_free_irq:
  239. free_irq(host->irq, host);
  240. out_unmap:
  241. iounmap(priv(host)->base);
  242. iounmap(priv(host)->dma);
  243. scsi_host_put(host);
  244. out_release:
  245. ecard_release_resources(ec);
  246. out:
  247. return ret;
  248. }
  249. static void cumanascsi1_remove(struct expansion_card *ec)
  250. {
  251. struct Scsi_Host *host = ecard_get_drvdata(ec);
  252. ecard_set_drvdata(ec, NULL);
  253. scsi_remove_host(host);
  254. free_irq(host->irq, host);
  255. NCR5380_exit(host);
  256. iounmap(priv(host)->base);
  257. iounmap(priv(host)->dma);
  258. scsi_host_put(host);
  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");