a2091.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/slab.h>
  4. #include <linux/blkdev.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 int a2091_release(struct Scsi_Host *instance);
  23. static irqreturn_t a2091_intr (int irq, void *_instance)
  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(struct 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. {
  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. memcpy (HDATA(instance)->dma_bounce_buffer,
  66. cmd->SCp.ptr, cmd->SCp.this_residual);
  67. }
  68. }
  69. /* setup dma direction */
  70. if (!dir_in)
  71. cntr |= CNTR_DDIR;
  72. /* remember direction */
  73. HDATA(cmd->device->host)->dma_dir = dir_in;
  74. DMA(cmd->device->host)->CNTR = cntr;
  75. /* setup DMA *physical* address */
  76. DMA(cmd->device->host)->ACR = addr;
  77. if (dir_in){
  78. /* invalidate any cache */
  79. cache_clear (addr, cmd->SCp.this_residual);
  80. }else{
  81. /* push any dirty cache */
  82. cache_push (addr, cmd->SCp.this_residual);
  83. }
  84. /* start DMA */
  85. DMA(cmd->device->host)->ST_DMA = 1;
  86. /* return success */
  87. return 0;
  88. }
  89. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  90. int status)
  91. {
  92. /* disable SCSI interrupts */
  93. unsigned short cntr = CNTR_PDMD;
  94. if (!HDATA(instance)->dma_dir)
  95. cntr |= CNTR_DDIR;
  96. /* disable SCSI interrupts */
  97. DMA(instance)->CNTR = cntr;
  98. /* flush if we were reading */
  99. if (HDATA(instance)->dma_dir) {
  100. DMA(instance)->FLUSH = 1;
  101. while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
  102. ;
  103. }
  104. /* clear a possible interrupt */
  105. DMA(instance)->CINT = 1;
  106. /* stop DMA */
  107. DMA(instance)->SP_DMA = 1;
  108. /* restore the CONTROL bits (minus the direction flag) */
  109. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  110. /* copy from a bounce buffer, if necessary */
  111. if (status && HDATA(instance)->dma_bounce_buffer) {
  112. if( HDATA(instance)->dma_dir )
  113. memcpy (SCpnt->SCp.ptr,
  114. HDATA(instance)->dma_bounce_buffer,
  115. SCpnt->SCp.this_residual);
  116. kfree (HDATA(instance)->dma_bounce_buffer);
  117. HDATA(instance)->dma_bounce_buffer = NULL;
  118. HDATA(instance)->dma_bounce_len = 0;
  119. }
  120. }
  121. static int __init a2091_detect(struct scsi_host_template *tpnt)
  122. {
  123. static unsigned char called = 0;
  124. struct Scsi_Host *instance;
  125. unsigned long address;
  126. struct zorro_dev *z = NULL;
  127. wd33c93_regs regs;
  128. int num_a2091 = 0;
  129. if (!MACH_IS_AMIGA || called)
  130. return 0;
  131. called = 1;
  132. tpnt->proc_name = "A2091";
  133. tpnt->proc_info = &wd33c93_proc_info;
  134. while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
  135. if (z->id != ZORRO_PROD_CBM_A590_A2091_1 &&
  136. z->id != ZORRO_PROD_CBM_A590_A2091_2)
  137. continue;
  138. address = z->resource.start;
  139. if (!request_mem_region(address, 256, "wd33c93"))
  140. continue;
  141. instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
  142. if (instance == NULL)
  143. goto release;
  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. if (request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, "A2091 SCSI",
  155. instance))
  156. goto unregister;
  157. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  158. num_a2091++;
  159. continue;
  160. unregister:
  161. scsi_unregister(instance);
  162. wd33c93_release();
  163. release:
  164. release_mem_region(address, 256);
  165. }
  166. return num_a2091;
  167. }
  168. static int a2091_bus_reset(struct scsi_cmnd *cmd)
  169. {
  170. /* FIXME perform bus-specific reset */
  171. /* FIXME 2: kill this function, and let midlayer fall back
  172. to the same action, calling wd33c93_host_reset() */
  173. spin_lock_irq(cmd->device->host->host_lock);
  174. wd33c93_host_reset(cmd);
  175. spin_unlock_irq(cmd->device->host->host_lock);
  176. return SUCCESS;
  177. }
  178. #define HOSTS_C
  179. static struct scsi_host_template driver_template = {
  180. .proc_name = "A2901",
  181. .name = "Commodore A2091/A590 SCSI",
  182. .detect = a2091_detect,
  183. .release = a2091_release,
  184. .queuecommand = wd33c93_queuecommand,
  185. .eh_abort_handler = wd33c93_abort,
  186. .eh_bus_reset_handler = a2091_bus_reset,
  187. .eh_host_reset_handler = wd33c93_host_reset,
  188. .can_queue = CAN_QUEUE,
  189. .this_id = 7,
  190. .sg_tablesize = SG_ALL,
  191. .cmd_per_lun = CMD_PER_LUN,
  192. .use_clustering = DISABLE_CLUSTERING
  193. };
  194. #include "scsi_module.c"
  195. static int a2091_release(struct Scsi_Host *instance)
  196. {
  197. #ifdef MODULE
  198. DMA(instance)->CNTR = 0;
  199. release_mem_region(ZTWO_PADDR(instance->base), 256);
  200. free_irq(IRQ_AMIGA_PORTS, instance);
  201. wd33c93_release();
  202. #endif
  203. return 1;
  204. }
  205. MODULE_LICENSE("GPL");