a3000.c 6.5 KB

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