a2091.c 6.8 KB

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