cumana_1.c 8.2 KB

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