a3000.c 6.6 KB

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