a2091.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #include <linux/types.h>
  2. #include <linux/init.h>
  3. #include <linux/interrupt.h>
  4. #include <linux/mm.h>
  5. #include <linux/slab.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/zorro.h>
  8. #include <asm/page.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/amigaints.h>
  11. #include <asm/amigahw.h>
  12. #include "scsi.h"
  13. #include "wd33c93.h"
  14. #include "a2091.h"
  15. struct a2091_hostdata {
  16. struct WD33C93_hostdata wh;
  17. struct a2091_scsiregs *regs;
  18. };
  19. static irqreturn_t a2091_intr(int irq, void *data)
  20. {
  21. struct Scsi_Host *instance = data;
  22. struct a2091_hostdata *hdata = shost_priv(instance);
  23. unsigned int status = hdata->regs->ISTR;
  24. unsigned long flags;
  25. if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS))
  26. return IRQ_NONE;
  27. spin_lock_irqsave(instance->host_lock, flags);
  28. wd33c93_intr(instance);
  29. spin_unlock_irqrestore(instance->host_lock, flags);
  30. return IRQ_HANDLED;
  31. }
  32. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  33. {
  34. struct Scsi_Host *instance = cmd->device->host;
  35. struct a2091_hostdata *hdata = shost_priv(instance);
  36. struct WD33C93_hostdata *wh = &hdata->wh;
  37. struct a2091_scsiregs *regs = hdata->regs;
  38. unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
  39. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  40. /* don't allow DMA if the physical address is bad */
  41. if (addr & A2091_XFER_MASK) {
  42. wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
  43. wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len,
  44. GFP_KERNEL);
  45. /* can't allocate memory; use PIO */
  46. if (!wh->dma_bounce_buffer) {
  47. wh->dma_bounce_len = 0;
  48. return 1;
  49. }
  50. /* get the physical address of the bounce buffer */
  51. addr = virt_to_bus(wh->dma_bounce_buffer);
  52. /* the bounce buffer may not be in the first 16M of physmem */
  53. if (addr & A2091_XFER_MASK) {
  54. /* we could use chipmem... maybe later */
  55. kfree(wh->dma_bounce_buffer);
  56. wh->dma_bounce_buffer = NULL;
  57. wh->dma_bounce_len = 0;
  58. return 1;
  59. }
  60. if (!dir_in) {
  61. /* copy to bounce buffer for a write */
  62. memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr,
  63. cmd->SCp.this_residual);
  64. }
  65. }
  66. /* setup dma direction */
  67. if (!dir_in)
  68. cntr |= CNTR_DDIR;
  69. /* remember direction */
  70. wh->dma_dir = dir_in;
  71. regs->CNTR = cntr;
  72. /* setup DMA *physical* address */
  73. regs->ACR = addr;
  74. if (dir_in) {
  75. /* invalidate any cache */
  76. cache_clear(addr, cmd->SCp.this_residual);
  77. } else {
  78. /* push any dirty cache */
  79. cache_push(addr, cmd->SCp.this_residual);
  80. }
  81. /* start DMA */
  82. regs->ST_DMA = 1;
  83. /* return success */
  84. return 0;
  85. }
  86. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  87. int status)
  88. {
  89. struct a2091_hostdata *hdata = shost_priv(instance);
  90. struct WD33C93_hostdata *wh = &hdata->wh;
  91. struct a2091_scsiregs *regs = hdata->regs;
  92. /* disable SCSI interrupts */
  93. unsigned short cntr = CNTR_PDMD;
  94. if (!wh->dma_dir)
  95. cntr |= CNTR_DDIR;
  96. /* disable SCSI interrupts */
  97. regs->CNTR = cntr;
  98. /* flush if we were reading */
  99. if (wh->dma_dir) {
  100. regs->FLUSH = 1;
  101. while (!(regs->ISTR & ISTR_FE_FLG))
  102. ;
  103. }
  104. /* clear a possible interrupt */
  105. regs->CINT = 1;
  106. /* stop DMA */
  107. regs->SP_DMA = 1;
  108. /* restore the CONTROL bits (minus the direction flag) */
  109. regs->CNTR = CNTR_PDMD | CNTR_INTEN;
  110. /* copy from a bounce buffer, if necessary */
  111. if (status && wh->dma_bounce_buffer) {
  112. if (wh->dma_dir)
  113. memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer,
  114. SCpnt->SCp.this_residual);
  115. kfree(wh->dma_bounce_buffer);
  116. wh->dma_bounce_buffer = NULL;
  117. wh->dma_bounce_len = 0;
  118. }
  119. }
  120. static int a2091_bus_reset(struct scsi_cmnd *cmd)
  121. {
  122. struct Scsi_Host *instance = cmd->device->host;
  123. /* FIXME perform bus-specific reset */
  124. /* FIXME 2: kill this function, and let midlayer fall back
  125. to the same action, calling wd33c93_host_reset() */
  126. spin_lock_irq(instance->host_lock);
  127. wd33c93_host_reset(cmd);
  128. spin_unlock_irq(instance->host_lock);
  129. return SUCCESS;
  130. }
  131. static struct scsi_host_template a2091_scsi_template = {
  132. .module = THIS_MODULE,
  133. .name = "Commodore A2091/A590 SCSI",
  134. .proc_info = wd33c93_proc_info,
  135. .proc_name = "A2901",
  136. .queuecommand = wd33c93_queuecommand,
  137. .eh_abort_handler = wd33c93_abort,
  138. .eh_bus_reset_handler = a2091_bus_reset,
  139. .eh_host_reset_handler = wd33c93_host_reset,
  140. .can_queue = CAN_QUEUE,
  141. .this_id = 7,
  142. .sg_tablesize = SG_ALL,
  143. .cmd_per_lun = CMD_PER_LUN,
  144. .use_clustering = DISABLE_CLUSTERING
  145. };
  146. static int __devinit a2091_probe(struct zorro_dev *z,
  147. const struct zorro_device_id *ent)
  148. {
  149. struct Scsi_Host *instance;
  150. int error;
  151. struct a2091_scsiregs *regs;
  152. wd33c93_regs wdregs;
  153. struct a2091_hostdata *hdata;
  154. if (!request_mem_region(z->resource.start, 256, "wd33c93"))
  155. return -EBUSY;
  156. instance = scsi_host_alloc(&a2091_scsi_template,
  157. sizeof(struct a2091_hostdata));
  158. if (!instance) {
  159. error = -ENOMEM;
  160. goto fail_alloc;
  161. }
  162. instance->irq = IRQ_AMIGA_PORTS;
  163. instance->unique_id = z->slotaddr;
  164. regs = (struct a2091_scsiregs *)ZTWO_VADDR(z->resource.start);
  165. regs->DAWR = DAWR_A2091;
  166. wdregs.SASR = &regs->SASR;
  167. wdregs.SCMD = &regs->SCMD;
  168. hdata = shost_priv(instance);
  169. hdata->wh.no_sync = 0xff;
  170. hdata->wh.fast = 0;
  171. hdata->wh.dma_mode = CTRL_DMA;
  172. hdata->regs = regs;
  173. wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_8_10);
  174. error = request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED,
  175. "A2091 SCSI", instance);
  176. if (error)
  177. goto fail_irq;
  178. regs->CNTR = CNTR_PDMD | CNTR_INTEN;
  179. error = scsi_add_host(instance, NULL);
  180. if (error)
  181. goto fail_host;
  182. zorro_set_drvdata(z, instance);
  183. scsi_scan_host(instance);
  184. return 0;
  185. fail_host:
  186. free_irq(IRQ_AMIGA_PORTS, instance);
  187. fail_irq:
  188. scsi_host_put(instance);
  189. fail_alloc:
  190. release_mem_region(z->resource.start, 256);
  191. return error;
  192. }
  193. static void __devexit a2091_remove(struct zorro_dev *z)
  194. {
  195. struct Scsi_Host *instance = zorro_get_drvdata(z);
  196. struct a2091_hostdata *hdata = shost_priv(instance);
  197. hdata->regs->CNTR = 0;
  198. scsi_remove_host(instance);
  199. free_irq(IRQ_AMIGA_PORTS, instance);
  200. scsi_host_put(instance);
  201. release_mem_region(z->resource.start, 256);
  202. }
  203. static struct zorro_device_id a2091_zorro_tbl[] __devinitdata = {
  204. { ZORRO_PROD_CBM_A590_A2091_1 },
  205. { ZORRO_PROD_CBM_A590_A2091_2 },
  206. { 0 }
  207. };
  208. MODULE_DEVICE_TABLE(zorro, a2091_zorro_tbl);
  209. static struct zorro_driver a2091_driver = {
  210. .name = "a2091",
  211. .id_table = a2091_zorro_tbl,
  212. .probe = a2091_probe,
  213. .remove = __devexit_p(a2091_remove),
  214. };
  215. static int __init a2091_init(void)
  216. {
  217. return zorro_register_driver(&a2091_driver);
  218. }
  219. module_init(a2091_init);
  220. static void __exit a2091_exit(void)
  221. {
  222. zorro_unregister_driver(&a2091_driver);
  223. }
  224. module_exit(a2091_exit);
  225. MODULE_DESCRIPTION("Commodore A2091/A590 SCSI");
  226. MODULE_LICENSE("GPL");