a2091.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/sched.h>
  5. #include <linux/init.h>
  6. #include <linux/interrupt.h>
  7. #include <asm/setup.h>
  8. #include <asm/page.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/amigaints.h>
  11. #include <asm/amigahw.h>
  12. #include <linux/zorro.h>
  13. #include <asm/irq.h>
  14. #include <linux/spinlock.h>
  15. #include "scsi.h"
  16. #include <scsi/scsi_host.h>
  17. #include "wd33c93.h"
  18. #include "a2091.h"
  19. #include<linux/stat.h>
  20. #define DMA(ptr) ((a2091_scsiregs *)((ptr)->base))
  21. #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
  22. static irqreturn_t a2091_intr (int irq, void *_instance, struct pt_regs *fp)
  23. {
  24. unsigned long flags;
  25. unsigned int status;
  26. struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
  27. status = DMA(instance)->ISTR;
  28. if (!(status & (ISTR_INT_F|ISTR_INT_P)) || !(status & ISTR_INTS))
  29. return IRQ_NONE;
  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. static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
  36. {
  37. unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
  38. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  39. struct Scsi_Host *instance = cmd->device->host;
  40. /* don't allow DMA if the physical address is bad */
  41. if (addr & A2091_XFER_MASK ||
  42. (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
  43. {
  44. HDATA(instance)->dma_bounce_len = (cmd->SCp.this_residual + 511)
  45. & ~0x1ff;
  46. HDATA(instance)->dma_bounce_buffer =
  47. kmalloc (HDATA(instance)->dma_bounce_len, GFP_KERNEL);
  48. /* can't allocate memory; use PIO */
  49. if (!HDATA(instance)->dma_bounce_buffer) {
  50. HDATA(instance)->dma_bounce_len = 0;
  51. return 1;
  52. }
  53. /* get the physical address of the bounce buffer */
  54. addr = virt_to_bus(HDATA(instance)->dma_bounce_buffer);
  55. /* the bounce buffer may not be in the first 16M of physmem */
  56. if (addr & A2091_XFER_MASK) {
  57. /* we could use chipmem... maybe later */
  58. kfree (HDATA(instance)->dma_bounce_buffer);
  59. HDATA(instance)->dma_bounce_buffer = NULL;
  60. HDATA(instance)->dma_bounce_len = 0;
  61. return 1;
  62. }
  63. if (!dir_in) {
  64. /* copy to bounce buffer for a write */
  65. if (cmd->use_sg)
  66. #if 0
  67. panic ("scsi%ddma: incomplete s/g support",
  68. instance->host_no);
  69. #else
  70. memcpy (HDATA(instance)->dma_bounce_buffer,
  71. cmd->SCp.ptr, cmd->SCp.this_residual);
  72. #endif
  73. else
  74. memcpy (HDATA(instance)->dma_bounce_buffer,
  75. cmd->request_buffer, cmd->request_bufflen);
  76. }
  77. }
  78. /* setup dma direction */
  79. if (!dir_in)
  80. cntr |= CNTR_DDIR;
  81. /* remember direction */
  82. HDATA(cmd->device->host)->dma_dir = dir_in;
  83. DMA(cmd->device->host)->CNTR = cntr;
  84. /* setup DMA *physical* address */
  85. DMA(cmd->device->host)->ACR = addr;
  86. if (dir_in){
  87. /* invalidate any cache */
  88. cache_clear (addr, cmd->SCp.this_residual);
  89. }else{
  90. /* push any dirty cache */
  91. cache_push (addr, cmd->SCp.this_residual);
  92. }
  93. /* start DMA */
  94. DMA(cmd->device->host)->ST_DMA = 1;
  95. /* return success */
  96. return 0;
  97. }
  98. static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
  99. int status)
  100. {
  101. /* disable SCSI interrupts */
  102. unsigned short cntr = CNTR_PDMD;
  103. if (!HDATA(instance)->dma_dir)
  104. cntr |= CNTR_DDIR;
  105. /* disable SCSI interrupts */
  106. DMA(instance)->CNTR = cntr;
  107. /* flush if we were reading */
  108. if (HDATA(instance)->dma_dir) {
  109. DMA(instance)->FLUSH = 1;
  110. while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
  111. ;
  112. }
  113. /* clear a possible interrupt */
  114. DMA(instance)->CINT = 1;
  115. /* stop DMA */
  116. DMA(instance)->SP_DMA = 1;
  117. /* restore the CONTROL bits (minus the direction flag) */
  118. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  119. /* copy from a bounce buffer, if necessary */
  120. if (status && HDATA(instance)->dma_bounce_buffer) {
  121. if (SCpnt && SCpnt->use_sg) {
  122. #if 0
  123. panic ("scsi%d: incomplete s/g support",
  124. instance->host_no);
  125. #else
  126. if( HDATA(instance)->dma_dir )
  127. memcpy (SCpnt->SCp.ptr,
  128. HDATA(instance)->dma_bounce_buffer,
  129. SCpnt->SCp.this_residual);
  130. kfree (HDATA(instance)->dma_bounce_buffer);
  131. HDATA(instance)->dma_bounce_buffer = NULL;
  132. HDATA(instance)->dma_bounce_len = 0;
  133. #endif
  134. } else {
  135. if (HDATA(instance)->dma_dir && SCpnt)
  136. memcpy (SCpnt->request_buffer,
  137. HDATA(instance)->dma_bounce_buffer,
  138. SCpnt->request_bufflen);
  139. kfree (HDATA(instance)->dma_bounce_buffer);
  140. HDATA(instance)->dma_bounce_buffer = NULL;
  141. HDATA(instance)->dma_bounce_len = 0;
  142. }
  143. }
  144. }
  145. int __init a2091_detect(struct scsi_host_template *tpnt)
  146. {
  147. static unsigned char called = 0;
  148. struct Scsi_Host *instance;
  149. unsigned long address;
  150. struct zorro_dev *z = NULL;
  151. wd33c93_regs regs;
  152. int num_a2091 = 0;
  153. if (!MACH_IS_AMIGA || called)
  154. return 0;
  155. called = 1;
  156. tpnt->proc_name = "A2091";
  157. tpnt->proc_info = &wd33c93_proc_info;
  158. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  159. if (z->id != ZORRO_PROD_CBM_A590_A2091_1 &&
  160. z->id != ZORRO_PROD_CBM_A590_A2091_2)
  161. continue;
  162. address = z->resource.start;
  163. if (!request_mem_region(address, 256, "wd33c93"))
  164. continue;
  165. instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
  166. if (instance == NULL) {
  167. release_mem_region(address, 256);
  168. continue;
  169. }
  170. instance->base = ZTWO_VADDR(address);
  171. instance->irq = IRQ_AMIGA_PORTS;
  172. instance->unique_id = z->slotaddr;
  173. DMA(instance)->DAWR = DAWR_A2091;
  174. regs.SASR = &(DMA(instance)->SASR);
  175. regs.SCMD = &(DMA(instance)->SCMD);
  176. wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  177. request_irq(IRQ_AMIGA_PORTS, a2091_intr, SA_SHIRQ, "A2091 SCSI",
  178. instance);
  179. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  180. num_a2091++;
  181. }
  182. return num_a2091;
  183. }
  184. static int a2091_bus_reset(Scsi_Cmnd *cmd)
  185. {
  186. /* FIXME perform bus-specific reset */
  187. /* FIXME 2: kill this function, and let midlayer fall back
  188. to the same action, calling wd33c93_host_reset() */
  189. spin_lock_irq(cmd->device->host->host_lock);
  190. wd33c93_host_reset(cmd);
  191. spin_unlock_irq(cmd->device->host->host_lock);
  192. return SUCCESS;
  193. }
  194. #define HOSTS_C
  195. static struct scsi_host_template driver_template = {
  196. .proc_name = "A2901",
  197. .name = "Commodore A2091/A590 SCSI",
  198. .detect = a2091_detect,
  199. .release = a2091_release,
  200. .queuecommand = wd33c93_queuecommand,
  201. .eh_abort_handler = wd33c93_abort,
  202. .eh_bus_reset_handler = a2091_bus_reset,
  203. .eh_host_reset_handler = wd33c93_host_reset,
  204. .can_queue = CAN_QUEUE,
  205. .this_id = 7,
  206. .sg_tablesize = SG_ALL,
  207. .cmd_per_lun = CMD_PER_LUN,
  208. .use_clustering = DISABLE_CLUSTERING
  209. };
  210. #include "scsi_module.c"
  211. int a2091_release(struct Scsi_Host *instance)
  212. {
  213. #ifdef MODULE
  214. DMA(instance)->CNTR = 0;
  215. release_mem_region(ZTWO_PADDR(instance->base), 256);
  216. free_irq(IRQ_AMIGA_PORTS, instance);
  217. wd33c93_release();
  218. #endif
  219. return 1;
  220. }
  221. MODULE_LICENSE("GPL");