a2091.c 6.1 KB

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