cumana_1.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. #define BOARD_NORMAL 0
  32. #define BOARD_NCR53C400 1
  33. #include "../NCR5380.h"
  34. void cumanascsi_setup(char *str, int *ints)
  35. {
  36. }
  37. const char *cumanascsi_info(struct Scsi_Host *spnt)
  38. {
  39. return "";
  40. }
  41. #define CTRL 0x16fc
  42. #define STAT 0x2004
  43. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  44. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  45. static inline int
  46. NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr, int len)
  47. {
  48. unsigned long *laddr;
  49. void __iomem *dma = priv(host)->dma + 0x2000;
  50. if(!len) return 0;
  51. writeb(0x02, priv(host)->base + CTRL);
  52. laddr = (unsigned long *)addr;
  53. while(len >= 32)
  54. {
  55. unsigned int status;
  56. unsigned long v;
  57. status = readb(priv(host)->base + STAT);
  58. if(status & 0x80)
  59. goto end;
  60. if(!(status & 0x40))
  61. continue;
  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. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  69. v=*laddr++; writew(L(v), dma); writew(H(v), dma);
  70. len -= 32;
  71. if(len == 0)
  72. break;
  73. }
  74. addr = (unsigned char *)laddr;
  75. writeb(0x12, priv(host)->base + CTRL);
  76. while(len > 0)
  77. {
  78. unsigned int status;
  79. status = readb(priv(host)->base + STAT);
  80. if(status & 0x80)
  81. goto end;
  82. if(status & 0x40)
  83. {
  84. writeb(*addr++, dma);
  85. if(--len == 0)
  86. break;
  87. }
  88. status = readb(priv(host)->base + STAT);
  89. if(status & 0x80)
  90. goto end;
  91. if(status & 0x40)
  92. {
  93. writeb(*addr++, dma);
  94. if(--len == 0)
  95. break;
  96. }
  97. }
  98. end:
  99. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  100. return len;
  101. }
  102. static inline int
  103. NCR5380_pread(struct Scsi_Host *host, unsigned char *addr, int len)
  104. {
  105. unsigned long *laddr;
  106. void __iomem *dma = priv(host)->dma + 0x2000;
  107. if(!len) return 0;
  108. writeb(0x00, priv(host)->base + CTRL);
  109. laddr = (unsigned long *)addr;
  110. while(len >= 32)
  111. {
  112. unsigned int status;
  113. status = readb(priv(host)->base + STAT);
  114. if(status & 0x80)
  115. goto end;
  116. if(!(status & 0x40))
  117. continue;
  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. *laddr++ = readw(dma) | (readw(dma) << 16);
  125. *laddr++ = readw(dma) | (readw(dma) << 16);
  126. len -= 32;
  127. if(len == 0)
  128. break;
  129. }
  130. addr = (unsigned char *)laddr;
  131. writeb(0x10, priv(host)->base + CTRL);
  132. while(len > 0)
  133. {
  134. unsigned int status;
  135. status = readb(priv(host)->base + STAT);
  136. if(status & 0x80)
  137. goto end;
  138. if(status & 0x40)
  139. {
  140. *addr++ = readb(dma);
  141. if(--len == 0)
  142. break;
  143. }
  144. status = readb(priv(host)->base + STAT);
  145. if(status & 0x80)
  146. goto end;
  147. if(status & 0x40)
  148. {
  149. *addr++ = readb(dma);
  150. if(--len == 0)
  151. break;
  152. }
  153. }
  154. end:
  155. writeb(priv(host)->ctrl | 0x40, priv(host)->base + CTRL);
  156. return len;
  157. }
  158. static unsigned char cumanascsi_read(struct Scsi_Host *host, unsigned int reg)
  159. {
  160. void __iomem *base = priv(host)->base;
  161. unsigned char val;
  162. writeb(0, base + CTRL);
  163. val = readb(base + 0x2100 + (reg << 2));
  164. priv(host)->ctrl = 0x40;
  165. writeb(0x40, base + CTRL);
  166. return val;
  167. }
  168. static void cumanascsi_write(struct Scsi_Host *host, unsigned int reg, unsigned int value)
  169. {
  170. void __iomem *base = priv(host)->base;
  171. writeb(0, base + CTRL);
  172. writeb(value, base + 0x2100 + (reg << 2));
  173. priv(host)->ctrl = 0x40;
  174. writeb(0x40, base + CTRL);
  175. }
  176. #include "../NCR5380.c"
  177. static struct scsi_host_template cumanascsi_template = {
  178. .module = THIS_MODULE,
  179. .name = "Cumana 16-bit SCSI",
  180. .info = cumanascsi_info,
  181. .queuecommand = cumanascsi_queue_command,
  182. .eh_abort_handler = NCR5380_abort,
  183. .eh_bus_reset_handler = NCR5380_bus_reset,
  184. .can_queue = 16,
  185. .this_id = 7,
  186. .sg_tablesize = SG_ALL,
  187. .cmd_per_lun = 2,
  188. .use_clustering = DISABLE_CLUSTERING,
  189. .proc_name = "CumanaSCSI-1",
  190. };
  191. static int cumanascsi1_probe(struct expansion_card *ec,
  192. const struct ecard_id *id)
  193. {
  194. struct Scsi_Host *host;
  195. int ret;
  196. ret = ecard_request_resources(ec);
  197. if (ret)
  198. goto out;
  199. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  200. if (!host) {
  201. ret = -ENOMEM;
  202. goto out_release;
  203. }
  204. priv(host)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCSLOW),
  205. ecard_resource_len(ec, ECARD_RES_IOCSLOW));
  206. priv(host)->dma = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  207. ecard_resource_len(ec, ECARD_RES_MEMC));
  208. if (!priv(host)->base || !priv(host)->dma) {
  209. ret = -ENOMEM;
  210. goto out_unmap;
  211. }
  212. host->irq = ec->irq;
  213. NCR5380_init(host, 0);
  214. priv(host)->ctrl = 0;
  215. writeb(0, priv(host)->base + CTRL);
  216. host->n_io_port = 255;
  217. if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
  218. ret = -EBUSY;
  219. goto out_unmap;
  220. }
  221. ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
  222. "CumanaSCSI-1", host);
  223. if (ret) {
  224. printk("scsi%d: IRQ%d not free: %d\n",
  225. host->host_no, host->irq, ret);
  226. goto out_unmap;
  227. }
  228. printk("scsi%d: at port 0x%08lx irq %d",
  229. host->host_no, host->io_port, host->irq);
  230. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  231. host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
  232. printk("\nscsi%d:", host->host_no);
  233. NCR5380_print_options(host);
  234. printk("\n");
  235. ret = scsi_add_host(host, &ec->dev);
  236. if (ret)
  237. goto out_free_irq;
  238. scsi_scan_host(host);
  239. goto out;
  240. out_free_irq:
  241. free_irq(host->irq, host);
  242. out_unmap:
  243. iounmap(priv(host)->base);
  244. iounmap(priv(host)->dma);
  245. scsi_host_put(host);
  246. out_release:
  247. ecard_release_resources(ec);
  248. out:
  249. return ret;
  250. }
  251. static void cumanascsi1_remove(struct expansion_card *ec)
  252. {
  253. struct Scsi_Host *host = ecard_get_drvdata(ec);
  254. ecard_set_drvdata(ec, NULL);
  255. scsi_remove_host(host);
  256. free_irq(host->irq, host);
  257. NCR5380_exit(host);
  258. iounmap(priv(host)->base);
  259. iounmap(priv(host)->dma);
  260. scsi_host_put(host);
  261. ecard_release_resources(ec);
  262. }
  263. static const struct ecard_id cumanascsi1_cids[] = {
  264. { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
  265. { 0xffff, 0xffff }
  266. };
  267. static struct ecard_driver cumanascsi1_driver = {
  268. .probe = cumanascsi1_probe,
  269. .remove = cumanascsi1_remove,
  270. .id_table = cumanascsi1_cids,
  271. .drv = {
  272. .name = "cumanascsi1",
  273. },
  274. };
  275. static int __init cumanascsi_init(void)
  276. {
  277. return ecard_register_driver(&cumanascsi1_driver);
  278. }
  279. static void __exit cumanascsi_exit(void)
  280. {
  281. ecard_remove_driver(&cumanascsi1_driver);
  282. }
  283. module_init(cumanascsi_init);
  284. module_exit(cumanascsi_exit);
  285. MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
  286. MODULE_LICENSE("GPL");