a3000.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/slab.h>
  4. #include <linux/blkdev.h>
  5. #include <linux/ioport.h>
  6. #include <linux/init.h>
  7. #include <linux/spinlock.h>
  8. #include <linux/interrupt.h>
  9. #include <asm/setup.h>
  10. #include <asm/page.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/amigaints.h>
  13. #include <asm/amigahw.h>
  14. #include <asm/irq.h>
  15. #include "scsi.h"
  16. #include <scsi/scsi_host.h>
  17. #include "wd33c93.h"
  18. #include "a3000.h"
  19. #include <linux/stat.h>
  20. static int a3000_release(struct Scsi_Host *instance);
  21. static irqreturn_t a3000_intr(int irq, void *data)
  22. {
  23. struct Scsi_Host *instance = data;
  24. struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
  25. unsigned int status = regs->ISTR;
  26. unsigned long flags;
  27. if (!(status & ISTR_INT_P))
  28. return IRQ_NONE;
  29. if (status & ISTR_INTS) {
  30. spin_lock_irqsave(instance->host_lock, flags);
  31. wd33c93_intr(instance);
  32. spin_unlock_irqrestore(instance->host_lock, flags);
  33. return IRQ_HANDLED;
  34. }
  35. printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
  36. return IRQ_NONE;
  37. }
  38. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  39. {
  40. struct Scsi_Host *instance = cmd->device->host;
  41. struct WD33C93_hostdata *hdata = shost_priv(instance);
  42. struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
  43. unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
  44. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  45. /*
  46. * if the physical address has the wrong alignment, or if
  47. * physical address is bad, or if it is a write and at the
  48. * end of a physical memory chunk, then allocate a bounce
  49. * buffer
  50. */
  51. if (addr & A3000_XFER_MASK) {
  52. hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
  53. hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len,
  54. GFP_KERNEL);
  55. /* can't allocate memory; use PIO */
  56. if (!hdata->dma_bounce_buffer) {
  57. hdata->dma_bounce_len = 0;
  58. return 1;
  59. }
  60. if (!dir_in) {
  61. /* copy to bounce buffer for a write */
  62. memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
  63. cmd->SCp.this_residual);
  64. }
  65. addr = virt_to_bus(hdata->dma_bounce_buffer);
  66. }
  67. /* setup dma direction */
  68. if (!dir_in)
  69. cntr |= CNTR_DDIR;
  70. /* remember direction */
  71. hdata->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. mb(); /* make sure setup is completed */
  84. regs->ST_DMA = 1;
  85. mb(); /* make sure DMA has started before next IO */
  86. /* return success */
  87. return 0;
  88. }
  89. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  90. int status)
  91. {
  92. struct WD33C93_hostdata *hdata = shost_priv(instance);
  93. struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
  94. /* disable SCSI interrupts */
  95. unsigned short cntr = CNTR_PDMD;
  96. if (!hdata->dma_dir)
  97. cntr |= CNTR_DDIR;
  98. regs->CNTR = cntr;
  99. mb(); /* make sure CNTR is updated before next IO */
  100. /* flush if we were reading */
  101. if (hdata->dma_dir) {
  102. regs->FLUSH = 1;
  103. mb(); /* don't allow prefetch */
  104. while (!(regs->ISTR & ISTR_FE_FLG))
  105. barrier();
  106. mb(); /* no IO until FLUSH is done */
  107. }
  108. /* clear a possible interrupt */
  109. /* I think that this CINT is only necessary if you are
  110. * using the terminal count features. HM 7 Mar 1994
  111. */
  112. regs->CINT = 1;
  113. /* stop DMA */
  114. regs->SP_DMA = 1;
  115. mb(); /* make sure DMA is stopped before next IO */
  116. /* restore the CONTROL bits (minus the direction flag) */
  117. regs->CNTR = CNTR_PDMD | CNTR_INTEN;
  118. mb(); /* make sure CNTR is updated before next IO */
  119. /* copy from a bounce buffer, if necessary */
  120. if (status && hdata->dma_bounce_buffer) {
  121. if (SCpnt) {
  122. if (hdata->dma_dir && SCpnt)
  123. memcpy(SCpnt->SCp.ptr,
  124. hdata->dma_bounce_buffer,
  125. SCpnt->SCp.this_residual);
  126. kfree(hdata->dma_bounce_buffer);
  127. hdata->dma_bounce_buffer = NULL;
  128. hdata->dma_bounce_len = 0;
  129. } else {
  130. kfree(hdata->dma_bounce_buffer);
  131. hdata->dma_bounce_buffer = NULL;
  132. hdata->dma_bounce_len = 0;
  133. }
  134. }
  135. }
  136. static int __init a3000_detect(struct scsi_host_template *tpnt)
  137. {
  138. struct Scsi_Host *instance;
  139. wd33c93_regs wdregs;
  140. struct a3000_scsiregs *regs;
  141. struct WD33C93_hostdata *hdata;
  142. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
  143. return 0;
  144. if (!request_mem_region(0xDD0000, 256, "wd33c93"))
  145. return 0;
  146. tpnt->proc_name = "A3000";
  147. tpnt->proc_info = &wd33c93_proc_info;
  148. instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
  149. if (instance == NULL)
  150. goto fail_register;
  151. instance->base = ZTWO_VADDR(0xDD0000);
  152. instance->irq = IRQ_AMIGA_PORTS;
  153. regs = (struct a3000_scsiregs *)(instance->base);
  154. regs->DAWR = DAWR_A3000;
  155. wdregs.SASR = &regs->SASR;
  156. wdregs.SCMD = &regs->SCMD;
  157. hdata = shost_priv(instance);
  158. hdata->no_sync = 0xff;
  159. hdata->fast = 0;
  160. hdata->dma_mode = CTRL_DMA;
  161. wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_12_15);
  162. if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED, "A3000 SCSI",
  163. instance))
  164. goto fail_irq;
  165. regs->CNTR = CNTR_PDMD | CNTR_INTEN;
  166. return 1;
  167. fail_irq:
  168. scsi_unregister(instance);
  169. fail_register:
  170. release_mem_region(0xDD0000, 256);
  171. return 0;
  172. }
  173. static int a3000_bus_reset(struct scsi_cmnd *cmd)
  174. {
  175. /* FIXME perform bus-specific reset */
  176. /* FIXME 2: kill this entire function, which should
  177. cause mid-layer to call wd33c93_host_reset anyway? */
  178. spin_lock_irq(cmd->device->host->host_lock);
  179. wd33c93_host_reset(cmd);
  180. spin_unlock_irq(cmd->device->host->host_lock);
  181. return SUCCESS;
  182. }
  183. #define HOSTS_C
  184. static struct scsi_host_template driver_template = {
  185. .proc_name = "A3000",
  186. .name = "Amiga 3000 built-in SCSI",
  187. .detect = a3000_detect,
  188. .release = a3000_release,
  189. .queuecommand = wd33c93_queuecommand,
  190. .eh_abort_handler = wd33c93_abort,
  191. .eh_bus_reset_handler = a3000_bus_reset,
  192. .eh_host_reset_handler = wd33c93_host_reset,
  193. .can_queue = CAN_QUEUE,
  194. .this_id = 7,
  195. .sg_tablesize = SG_ALL,
  196. .cmd_per_lun = CMD_PER_LUN,
  197. .use_clustering = ENABLE_CLUSTERING
  198. };
  199. #include "scsi_module.c"
  200. static int a3000_release(struct Scsi_Host *instance)
  201. {
  202. struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
  203. regs->CNTR = 0;
  204. release_mem_region(0xDD0000, 256);
  205. free_irq(IRQ_AMIGA_PORTS, a3000_intr);
  206. return 1;
  207. }
  208. MODULE_LICENSE("GPL");