cumana_1.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 <asm/system.h>
  15. #include "../scsi.h"
  16. #include <scsi/scsi_host.h>
  17. #include <scsi/scsicam.h>
  18. #define AUTOSENSE
  19. #define PSEUDO_DMA
  20. #define CUMANASCSI_PUBLIC_RELEASE 1
  21. #define NCR5380_implementation_fields int port, ctrl
  22. #define NCR5380_local_declare() struct Scsi_Host *_instance
  23. #define NCR5380_setup(instance) _instance = instance
  24. #define NCR5380_read(reg) cumanascsi_read(_instance, reg)
  25. #define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
  26. #define NCR5380_intr cumanascsi_intr
  27. #define NCR5380_queue_command cumanascsi_queue_command
  28. #define NCR5380_proc_info cumanascsi_proc_info
  29. #define BOARD_NORMAL 0
  30. #define BOARD_NCR53C400 1
  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. #ifdef NOT_EFFICIENT
  40. #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
  41. #define STAT(p) inb((p)+1)
  42. #define IN(p) inb((p))
  43. #define OUT(v,p) outb((v), (p))
  44. #else
  45. #define CTRL(p,v) (p[-2308] = (*ctrl = (v)))
  46. #define STAT(p) (p[4])
  47. #define IN(p) (*(p))
  48. #define IN2(p) ((unsigned short)(*(volatile unsigned long *)(p)))
  49. #define OUT(v,p) (*(p) = (v))
  50. #define OUT2(v,p) (*((volatile unsigned long *)(p)) = (v))
  51. #endif
  52. #define L(v) (((v)<<16)|((v) & 0x0000ffff))
  53. #define H(v) (((v)>>16)|((v) & 0xffff0000))
  54. static inline int
  55. NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr, int len)
  56. {
  57. int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
  58. int oldctrl = *ctrl;
  59. unsigned long *laddr;
  60. #ifdef NOT_EFFICIENT
  61. int iobase = instance->io_port;
  62. int dma_io = iobase & ~(0x3C0000>>2);
  63. #else
  64. volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
  65. volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
  66. #endif
  67. if(!len) return 0;
  68. CTRL(iobase, 0x02);
  69. laddr = (unsigned long *)addr;
  70. while(len >= 32)
  71. {
  72. int status;
  73. unsigned long v;
  74. status = STAT(iobase);
  75. if(status & 0x80)
  76. goto end;
  77. if(!(status & 0x40))
  78. continue;
  79. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  80. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  81. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  82. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  83. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  84. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  85. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  86. v=*laddr++; OUT2(L(v),dma_io); OUT2(H(v),dma_io);
  87. len -= 32;
  88. if(len == 0)
  89. break;
  90. }
  91. addr = (unsigned char *)laddr;
  92. CTRL(iobase, 0x12);
  93. while(len > 0)
  94. {
  95. int status;
  96. status = STAT(iobase);
  97. if(status & 0x80)
  98. goto end;
  99. if(status & 0x40)
  100. {
  101. OUT(*addr++, dma_io);
  102. if(--len == 0)
  103. break;
  104. }
  105. status = STAT(iobase);
  106. if(status & 0x80)
  107. goto end;
  108. if(status & 0x40)
  109. {
  110. OUT(*addr++, dma_io);
  111. if(--len == 0)
  112. break;
  113. }
  114. }
  115. end:
  116. CTRL(iobase, oldctrl|0x40);
  117. return len;
  118. }
  119. static inline int
  120. NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr, int len)
  121. {
  122. int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
  123. int oldctrl = *ctrl;
  124. unsigned long *laddr;
  125. #ifdef NOT_EFFICIENT
  126. int iobase = instance->io_port;
  127. int dma_io = iobase & ~(0x3C0000>>2);
  128. #else
  129. volatile unsigned char *iobase = (unsigned char *)ioaddr(instance->io_port);
  130. volatile unsigned char *dma_io = (unsigned char *)((int)iobase & ~0x3C0000);
  131. #endif
  132. if(!len) return 0;
  133. CTRL(iobase, 0x00);
  134. laddr = (unsigned long *)addr;
  135. while(len >= 32)
  136. {
  137. int status;
  138. status = STAT(iobase);
  139. if(status & 0x80)
  140. goto end;
  141. if(!(status & 0x40))
  142. continue;
  143. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  144. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  145. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  146. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  147. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  148. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  149. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  150. *laddr++ = IN2(dma_io)|(IN2(dma_io)<<16);
  151. len -= 32;
  152. if(len == 0)
  153. break;
  154. }
  155. addr = (unsigned char *)laddr;
  156. CTRL(iobase, 0x10);
  157. while(len > 0)
  158. {
  159. int status;
  160. status = STAT(iobase);
  161. if(status & 0x80)
  162. goto end;
  163. if(status & 0x40)
  164. {
  165. *addr++ = IN(dma_io);
  166. if(--len == 0)
  167. break;
  168. }
  169. status = STAT(iobase);
  170. if(status & 0x80)
  171. goto end;
  172. if(status & 0x40)
  173. {
  174. *addr++ = IN(dma_io);
  175. if(--len == 0)
  176. break;
  177. }
  178. }
  179. end:
  180. CTRL(iobase, oldctrl|0x40);
  181. return len;
  182. }
  183. #undef STAT
  184. #undef CTRL
  185. #undef IN
  186. #undef OUT
  187. #define CTRL(p,v) outb(*ctrl = (v), (p) - 577)
  188. static char cumanascsi_read(struct Scsi_Host *instance, int reg)
  189. {
  190. unsigned int iobase = instance->io_port;
  191. int i;
  192. int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
  193. CTRL(iobase, 0);
  194. i = inb(iobase + 64 + reg);
  195. CTRL(iobase, 0x40);
  196. return i;
  197. }
  198. static void cumanascsi_write(struct Scsi_Host *instance, int reg, int value)
  199. {
  200. int iobase = instance->io_port;
  201. int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
  202. CTRL(iobase, 0);
  203. outb(value, iobase + 64 + reg);
  204. CTRL(iobase, 0x40);
  205. }
  206. #undef CTRL
  207. #include "../NCR5380.c"
  208. static struct scsi_host_template cumanascsi_template = {
  209. .module = THIS_MODULE,
  210. .name = "Cumana 16-bit SCSI",
  211. .info = cumanascsi_info,
  212. .queuecommand = cumanascsi_queue_command,
  213. .eh_abort_handler = NCR5380_abort,
  214. .eh_bus_reset_handler = NCR5380_bus_reset,
  215. .can_queue = 16,
  216. .this_id = 7,
  217. .sg_tablesize = SG_ALL,
  218. .cmd_per_lun = 2,
  219. .unchecked_isa_dma = 0,
  220. .use_clustering = DISABLE_CLUSTERING,
  221. .proc_name = "CumanaSCSI-1",
  222. };
  223. static int __devinit
  224. cumanascsi1_probe(struct expansion_card *ec, const struct ecard_id *id)
  225. {
  226. struct Scsi_Host *host;
  227. int ret = -ENOMEM;
  228. host = scsi_host_alloc(&cumanascsi_template, sizeof(struct NCR5380_hostdata));
  229. if (!host)
  230. goto out;
  231. host->io_port = ecard_address(ec, ECARD_IOC, ECARD_SLOW) + 0x800;
  232. host->irq = ec->irq;
  233. NCR5380_init(host, 0);
  234. host->n_io_port = 255;
  235. if (!(request_region(host->io_port, host->n_io_port, "CumanaSCSI-1"))) {
  236. ret = -EBUSY;
  237. goto out_free;
  238. }
  239. ((struct NCR5380_hostdata *)host->hostdata)->ctrl = 0;
  240. outb(0x00, host->io_port - 577);
  241. ret = request_irq(host->irq, cumanascsi_intr, IRQF_DISABLED,
  242. "CumanaSCSI-1", host);
  243. if (ret) {
  244. printk("scsi%d: IRQ%d not free: %d\n",
  245. host->host_no, host->irq, ret);
  246. goto out_release;
  247. }
  248. printk("scsi%d: at port 0x%08lx irq %d",
  249. host->host_no, host->io_port, host->irq);
  250. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  251. host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
  252. printk("\nscsi%d:", host->host_no);
  253. NCR5380_print_options(host);
  254. printk("\n");
  255. ret = scsi_add_host(host, &ec->dev);
  256. if (ret)
  257. goto out_free_irq;
  258. scsi_scan_host(host);
  259. goto out;
  260. out_free_irq:
  261. free_irq(host->irq, host);
  262. out_release:
  263. release_region(host->io_port, host->n_io_port);
  264. out_free:
  265. scsi_host_put(host);
  266. out:
  267. return ret;
  268. }
  269. static void __devexit cumanascsi1_remove(struct expansion_card *ec)
  270. {
  271. struct Scsi_Host *host = ecard_get_drvdata(ec);
  272. ecard_set_drvdata(ec, NULL);
  273. scsi_remove_host(host);
  274. free_irq(host->irq, host);
  275. NCR5380_exit(host);
  276. release_region(host->io_port, host->n_io_port);
  277. scsi_host_put(host);
  278. }
  279. static const struct ecard_id cumanascsi1_cids[] = {
  280. { MANU_CUMANA, PROD_CUMANA_SCSI_1 },
  281. { 0xffff, 0xffff }
  282. };
  283. static struct ecard_driver cumanascsi1_driver = {
  284. .probe = cumanascsi1_probe,
  285. .remove = __devexit_p(cumanascsi1_remove),
  286. .id_table = cumanascsi1_cids,
  287. .drv = {
  288. .name = "cumanascsi1",
  289. },
  290. };
  291. static int __init cumanascsi_init(void)
  292. {
  293. return ecard_register_driver(&cumanascsi1_driver);
  294. }
  295. static void __exit cumanascsi_exit(void)
  296. {
  297. ecard_remove_driver(&cumanascsi1_driver);
  298. }
  299. module_init(cumanascsi_init);
  300. module_exit(cumanascsi_exit);
  301. MODULE_DESCRIPTION("Cumana SCSI-1 driver for Acorn machines");
  302. MODULE_LICENSE("GPL");