a2091.c 6.1 KB

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