cumana_1.c 8.1 KB

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