1 #include <linux/types.h>
3 #include <linux/slab.h>
4 #include <linux/blkdev.h>
5 #include <linux/ioport.h>
6 #include <linux/init.h>
7 #include <linux/spinlock.h>
8 #include <linux/interrupt.h>
10 #include <asm/setup.h>
12 #include <asm/pgtable.h>
13 #include <asm/amigaints.h>
14 #include <asm/amigahw.h>
18 #include <scsi/scsi_host.h>
22 #include <linux/stat.h>
25 static int a3000_release(struct Scsi_Host *instance);
27 static irqreturn_t a3000_intr(int irq, void *data)
29 struct Scsi_Host *instance = data;
30 struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
31 unsigned int status = regs->ISTR;
34 if (!(status & ISTR_INT_P))
36 if (status & ISTR_INTS) {
37 spin_lock_irqsave(instance->host_lock, flags);
38 wd33c93_intr(instance);
39 spin_unlock_irqrestore(instance->host_lock, flags);
42 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
46 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
48 struct Scsi_Host *instance = cmd->device->host;
49 struct WD33C93_hostdata *hdata = shost_priv(instance);
50 struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
51 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
52 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
55 * if the physical address has the wrong alignment, or if
56 * physical address is bad, or if it is a write and at the
57 * end of a physical memory chunk, then allocate a bounce
60 if (addr & A3000_XFER_MASK) {
61 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
62 hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len,
65 /* can't allocate memory; use PIO */
66 if (!hdata->dma_bounce_buffer) {
67 hdata->dma_bounce_len = 0;
72 /* copy to bounce buffer for a write */
73 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
74 cmd->SCp.this_residual);
77 addr = virt_to_bus(hdata->dma_bounce_buffer);
80 /* setup dma direction */
84 /* remember direction */
85 hdata->dma_dir = dir_in;
89 /* setup DMA *physical* address */
93 /* invalidate any cache */
94 cache_clear(addr, cmd->SCp.this_residual);
96 /* push any dirty cache */
97 cache_push(addr, cmd->SCp.this_residual);
101 mb(); /* make sure setup is completed */
103 mb(); /* make sure DMA has started before next IO */
109 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
112 struct WD33C93_hostdata *hdata = shost_priv(instance);
113 struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
115 /* disable SCSI interrupts */
116 unsigned short cntr = CNTR_PDMD;
122 mb(); /* make sure CNTR is updated before next IO */
124 /* flush if we were reading */
125 if (hdata->dma_dir) {
127 mb(); /* don't allow prefetch */
128 while (!(regs->ISTR & ISTR_FE_FLG))
130 mb(); /* no IO until FLUSH is done */
133 /* clear a possible interrupt */
134 /* I think that this CINT is only necessary if you are
135 * using the terminal count features. HM 7 Mar 1994
141 mb(); /* make sure DMA is stopped before next IO */
143 /* restore the CONTROL bits (minus the direction flag) */
144 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
145 mb(); /* make sure CNTR is updated before next IO */
147 /* copy from a bounce buffer, if necessary */
148 if (status && hdata->dma_bounce_buffer) {
150 if (hdata->dma_dir && SCpnt)
151 memcpy(SCpnt->SCp.ptr,
152 hdata->dma_bounce_buffer,
153 SCpnt->SCp.this_residual);
154 kfree(hdata->dma_bounce_buffer);
155 hdata->dma_bounce_buffer = NULL;
156 hdata->dma_bounce_len = 0;
158 kfree(hdata->dma_bounce_buffer);
159 hdata->dma_bounce_buffer = NULL;
160 hdata->dma_bounce_len = 0;
165 static int __init a3000_detect(struct scsi_host_template *tpnt)
167 struct Scsi_Host *instance;
169 struct a3000_scsiregs *regs;
170 struct WD33C93_hostdata *hdata;
172 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
174 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
177 tpnt->proc_name = "A3000";
178 tpnt->proc_info = &wd33c93_proc_info;
180 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
181 if (instance == NULL)
184 instance->base = ZTWO_VADDR(0xDD0000);
185 instance->irq = IRQ_AMIGA_PORTS;
186 regs = (struct a3000_scsiregs *)(instance->base);
187 regs->DAWR = DAWR_A3000;
188 wdregs.SASR = ®s->SASR;
189 wdregs.SCMD = ®s->SCMD;
190 hdata = shost_priv(instance);
191 hdata->no_sync = 0xff;
193 hdata->dma_mode = CTRL_DMA;
194 wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_12_15);
195 if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED, "A3000 SCSI",
198 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
203 scsi_unregister(instance);
205 release_mem_region(0xDD0000, 256);
209 static int a3000_bus_reset(struct scsi_cmnd *cmd)
211 /* FIXME perform bus-specific reset */
213 /* FIXME 2: kill this entire function, which should
214 cause mid-layer to call wd33c93_host_reset anyway? */
216 spin_lock_irq(cmd->device->host->host_lock);
217 wd33c93_host_reset(cmd);
218 spin_unlock_irq(cmd->device->host->host_lock);
225 static struct scsi_host_template driver_template = {
226 .proc_name = "A3000",
227 .name = "Amiga 3000 built-in SCSI",
228 .detect = a3000_detect,
229 .release = a3000_release,
230 .queuecommand = wd33c93_queuecommand,
231 .eh_abort_handler = wd33c93_abort,
232 .eh_bus_reset_handler = a3000_bus_reset,
233 .eh_host_reset_handler = wd33c93_host_reset,
234 .can_queue = CAN_QUEUE,
236 .sg_tablesize = SG_ALL,
237 .cmd_per_lun = CMD_PER_LUN,
238 .use_clustering = ENABLE_CLUSTERING
242 #include "scsi_module.c"
244 static int a3000_release(struct Scsi_Host *instance)
246 struct a3000_scsiregs *regs = (struct a3000_scsiregs *)(instance->base);
249 release_mem_region(0xDD0000, 256);
250 free_irq(IRQ_AMIGA_PORTS, a3000_intr);
254 MODULE_LICENSE("GPL");