a2091.c 6.5 KB

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