a2091.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 int a2091_release(struct Scsi_Host *instance);
  22. static irqreturn_t a2091_intr (int irq, void *_instance)
  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(struct 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. {
  43. HDATA(instance)->dma_bounce_len = (cmd->SCp.this_residual + 511)
  44. & ~0x1ff;
  45. HDATA(instance)->dma_bounce_buffer =
  46. kmalloc (HDATA(instance)->dma_bounce_len, GFP_KERNEL);
  47. /* can't allocate memory; use PIO */
  48. if (!HDATA(instance)->dma_bounce_buffer) {
  49. HDATA(instance)->dma_bounce_len = 0;
  50. return 1;
  51. }
  52. /* get the physical address of the bounce buffer */
  53. addr = virt_to_bus(HDATA(instance)->dma_bounce_buffer);
  54. /* the bounce buffer may not be in the first 16M of physmem */
  55. if (addr & A2091_XFER_MASK) {
  56. /* we could use chipmem... maybe later */
  57. kfree (HDATA(instance)->dma_bounce_buffer);
  58. HDATA(instance)->dma_bounce_buffer = NULL;
  59. HDATA(instance)->dma_bounce_len = 0;
  60. return 1;
  61. }
  62. if (!dir_in) {
  63. /* copy to bounce buffer for a write */
  64. memcpy (HDATA(instance)->dma_bounce_buffer,
  65. cmd->SCp.ptr, cmd->SCp.this_residual);
  66. }
  67. }
  68. /* setup dma direction */
  69. if (!dir_in)
  70. cntr |= CNTR_DDIR;
  71. /* remember direction */
  72. HDATA(cmd->device->host)->dma_dir = dir_in;
  73. DMA(cmd->device->host)->CNTR = cntr;
  74. /* setup DMA *physical* address */
  75. DMA(cmd->device->host)->ACR = addr;
  76. if (dir_in){
  77. /* invalidate any cache */
  78. cache_clear (addr, cmd->SCp.this_residual);
  79. }else{
  80. /* push any dirty cache */
  81. cache_push (addr, cmd->SCp.this_residual);
  82. }
  83. /* start DMA */
  84. DMA(cmd->device->host)->ST_DMA = 1;
  85. /* return success */
  86. return 0;
  87. }
  88. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  89. int status)
  90. {
  91. /* disable SCSI interrupts */
  92. unsigned short cntr = CNTR_PDMD;
  93. if (!HDATA(instance)->dma_dir)
  94. cntr |= CNTR_DDIR;
  95. /* disable SCSI interrupts */
  96. DMA(instance)->CNTR = cntr;
  97. /* flush if we were reading */
  98. if (HDATA(instance)->dma_dir) {
  99. DMA(instance)->FLUSH = 1;
  100. while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
  101. ;
  102. }
  103. /* clear a possible interrupt */
  104. DMA(instance)->CINT = 1;
  105. /* stop DMA */
  106. DMA(instance)->SP_DMA = 1;
  107. /* restore the CONTROL bits (minus the direction flag) */
  108. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  109. /* copy from a bounce buffer, if necessary */
  110. if (status && HDATA(instance)->dma_bounce_buffer) {
  111. if( HDATA(instance)->dma_dir )
  112. memcpy (SCpnt->SCp.ptr,
  113. HDATA(instance)->dma_bounce_buffer,
  114. SCpnt->SCp.this_residual);
  115. kfree (HDATA(instance)->dma_bounce_buffer);
  116. HDATA(instance)->dma_bounce_buffer = NULL;
  117. HDATA(instance)->dma_bounce_len = 0;
  118. }
  119. }
  120. static int __init a2091_detect(struct scsi_host_template *tpnt)
  121. {
  122. static unsigned char called = 0;
  123. struct Scsi_Host *instance;
  124. unsigned long address;
  125. struct zorro_dev *z = NULL;
  126. wd33c93_regs regs;
  127. int num_a2091 = 0;
  128. if (!MACH_IS_AMIGA || called)
  129. return 0;
  130. called = 1;
  131. tpnt->proc_name = "A2091";
  132. tpnt->proc_info = &wd33c93_proc_info;
  133. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  134. if (z->id != ZORRO_PROD_CBM_A590_A2091_1 &&
  135. z->id != ZORRO_PROD_CBM_A590_A2091_2)
  136. continue;
  137. address = z->resource.start;
  138. if (!request_mem_region(address, 256, "wd33c93"))
  139. continue;
  140. instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
  141. if (instance == NULL)
  142. goto release;
  143. instance->base = ZTWO_VADDR(address);
  144. instance->irq = IRQ_AMIGA_PORTS;
  145. instance->unique_id = z->slotaddr;
  146. DMA(instance)->DAWR = DAWR_A2091;
  147. regs.SASR = &(DMA(instance)->SASR);
  148. regs.SCMD = &(DMA(instance)->SCMD);
  149. HDATA(instance)->no_sync = 0xff;
  150. HDATA(instance)->fast = 0;
  151. HDATA(instance)->dma_mode = CTRL_DMA;
  152. wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
  153. if (request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, "A2091 SCSI",
  154. instance))
  155. goto unregister;
  156. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  157. num_a2091++;
  158. continue;
  159. unregister:
  160. scsi_unregister(instance);
  161. wd33c93_release();
  162. release:
  163. release_mem_region(address, 256);
  164. }
  165. return num_a2091;
  166. }
  167. static int a2091_bus_reset(struct scsi_cmnd *cmd)
  168. {
  169. /* FIXME perform bus-specific reset */
  170. /* FIXME 2: kill this function, and let midlayer fall back
  171. to the same action, calling wd33c93_host_reset() */
  172. spin_lock_irq(cmd->device->host->host_lock);
  173. wd33c93_host_reset(cmd);
  174. spin_unlock_irq(cmd->device->host->host_lock);
  175. return SUCCESS;
  176. }
  177. #define HOSTS_C
  178. static struct scsi_host_template driver_template = {
  179. .proc_name = "A2901",
  180. .name = "Commodore A2091/A590 SCSI",
  181. .detect = a2091_detect,
  182. .release = a2091_release,
  183. .queuecommand = wd33c93_queuecommand,
  184. .eh_abort_handler = wd33c93_abort,
  185. .eh_bus_reset_handler = a2091_bus_reset,
  186. .eh_host_reset_handler = wd33c93_host_reset,
  187. .can_queue = CAN_QUEUE,
  188. .this_id = 7,
  189. .sg_tablesize = SG_ALL,
  190. .cmd_per_lun = CMD_PER_LUN,
  191. .use_clustering = DISABLE_CLUSTERING
  192. };
  193. #include "scsi_module.c"
  194. static int a2091_release(struct Scsi_Host *instance)
  195. {
  196. #ifdef MODULE
  197. DMA(instance)->CNTR = 0;
  198. release_mem_region(ZTWO_PADDR(instance->base), 256);
  199. free_irq(IRQ_AMIGA_PORTS, instance);
  200. wd33c93_release();
  201. #endif
  202. return 1;
  203. }
  204. MODULE_LICENSE("GPL");