1 #include <linux/types.h>
3 #include <linux/blkdev.h>
4 #include <linux/init.h>
5 #include <linux/interrupt.h>
9 #include <asm/pgtable.h>
10 #include <asm/amigaints.h>
11 #include <asm/amigahw.h>
12 #include <linux/zorro.h>
14 #include <linux/spinlock.h>
17 #include <scsi/scsi_host.h>
21 #include<linux/stat.h>
23 #define DMA(ptr) ((a2091_scsiregs *)((ptr)->base))
24 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
26 static irqreturn_t a2091_intr (int irq, void *_instance)
30 struct Scsi_Host *instance = (struct Scsi_Host *)_instance;
32 status = DMA(instance)->ISTR;
33 if (!(status & (ISTR_INT_F|ISTR_INT_P)) || !(status & ISTR_INTS))
36 spin_lock_irqsave(instance->host_lock, flags);
37 wd33c93_intr(instance);
38 spin_unlock_irqrestore(instance->host_lock, flags);
42 static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
44 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
45 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
46 struct Scsi_Host *instance = cmd->device->host;
48 /* don't allow DMA if the physical address is bad */
49 if (addr & A2091_XFER_MASK ||
50 (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
52 HDATA(instance)->dma_bounce_len = (cmd->SCp.this_residual + 511)
54 HDATA(instance)->dma_bounce_buffer =
55 kmalloc (HDATA(instance)->dma_bounce_len, GFP_KERNEL);
57 /* can't allocate memory; use PIO */
58 if (!HDATA(instance)->dma_bounce_buffer) {
59 HDATA(instance)->dma_bounce_len = 0;
63 /* get the physical address of the bounce buffer */
64 addr = virt_to_bus(HDATA(instance)->dma_bounce_buffer);
66 /* the bounce buffer may not be in the first 16M of physmem */
67 if (addr & A2091_XFER_MASK) {
68 /* we could use chipmem... maybe later */
69 kfree (HDATA(instance)->dma_bounce_buffer);
70 HDATA(instance)->dma_bounce_buffer = NULL;
71 HDATA(instance)->dma_bounce_len = 0;
76 /* copy to bounce buffer for a write */
79 panic ("scsi%ddma: incomplete s/g support",
82 memcpy (HDATA(instance)->dma_bounce_buffer,
83 cmd->SCp.ptr, cmd->SCp.this_residual);
86 memcpy (HDATA(instance)->dma_bounce_buffer,
87 cmd->request_buffer, cmd->request_bufflen);
91 /* setup dma direction */
95 /* remember direction */
96 HDATA(cmd->device->host)->dma_dir = dir_in;
98 DMA(cmd->device->host)->CNTR = cntr;
100 /* setup DMA *physical* address */
101 DMA(cmd->device->host)->ACR = addr;
104 /* invalidate any cache */
105 cache_clear (addr, cmd->SCp.this_residual);
107 /* push any dirty cache */
108 cache_push (addr, cmd->SCp.this_residual);
111 DMA(cmd->device->host)->ST_DMA = 1;
117 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
120 /* disable SCSI interrupts */
121 unsigned short cntr = CNTR_PDMD;
123 if (!HDATA(instance)->dma_dir)
126 /* disable SCSI interrupts */
127 DMA(instance)->CNTR = cntr;
129 /* flush if we were reading */
130 if (HDATA(instance)->dma_dir) {
131 DMA(instance)->FLUSH = 1;
132 while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
136 /* clear a possible interrupt */
137 DMA(instance)->CINT = 1;
140 DMA(instance)->SP_DMA = 1;
142 /* restore the CONTROL bits (minus the direction flag) */
143 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
145 /* copy from a bounce buffer, if necessary */
146 if (status && HDATA(instance)->dma_bounce_buffer) {
147 if (SCpnt && SCpnt->use_sg) {
149 panic ("scsi%d: incomplete s/g support",
152 if( HDATA(instance)->dma_dir )
153 memcpy (SCpnt->SCp.ptr,
154 HDATA(instance)->dma_bounce_buffer,
155 SCpnt->SCp.this_residual);
156 kfree (HDATA(instance)->dma_bounce_buffer);
157 HDATA(instance)->dma_bounce_buffer = NULL;
158 HDATA(instance)->dma_bounce_len = 0;
162 if (HDATA(instance)->dma_dir && SCpnt)
163 memcpy (SCpnt->request_buffer,
164 HDATA(instance)->dma_bounce_buffer,
165 SCpnt->request_bufflen);
167 kfree (HDATA(instance)->dma_bounce_buffer);
168 HDATA(instance)->dma_bounce_buffer = NULL;
169 HDATA(instance)->dma_bounce_len = 0;
174 int __init a2091_detect(struct scsi_host_template *tpnt)
176 static unsigned char called = 0;
177 struct Scsi_Host *instance;
178 unsigned long address;
179 struct zorro_dev *z = NULL;
183 if (!MACH_IS_AMIGA || called)
187 tpnt->proc_name = "A2091";
188 tpnt->proc_info = &wd33c93_proc_info;
190 while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
191 if (z->id != ZORRO_PROD_CBM_A590_A2091_1 &&
192 z->id != ZORRO_PROD_CBM_A590_A2091_2)
194 address = z->resource.start;
195 if (!request_mem_region(address, 256, "wd33c93"))
198 instance = scsi_register (tpnt, sizeof (struct WD33C93_hostdata));
199 if (instance == NULL) {
200 release_mem_region(address, 256);
203 instance->base = ZTWO_VADDR(address);
204 instance->irq = IRQ_AMIGA_PORTS;
205 instance->unique_id = z->slotaddr;
206 DMA(instance)->DAWR = DAWR_A2091;
207 regs.SASR = &(DMA(instance)->SASR);
208 regs.SCMD = &(DMA(instance)->SCMD);
209 wd33c93_init(instance, regs, dma_setup, dma_stop, WD33C93_FS_8_10);
210 request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, "A2091 SCSI",
212 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
219 static int a2091_bus_reset(struct scsi_cmnd *cmd)
221 /* FIXME perform bus-specific reset */
223 /* FIXME 2: kill this function, and let midlayer fall back
224 to the same action, calling wd33c93_host_reset() */
226 spin_lock_irq(cmd->device->host->host_lock);
227 wd33c93_host_reset(cmd);
228 spin_unlock_irq(cmd->device->host->host_lock);
235 static struct scsi_host_template driver_template = {
236 .proc_name = "A2901",
237 .name = "Commodore A2091/A590 SCSI",
238 .detect = a2091_detect,
239 .release = a2091_release,
240 .queuecommand = wd33c93_queuecommand,
241 .eh_abort_handler = wd33c93_abort,
242 .eh_bus_reset_handler = a2091_bus_reset,
243 .eh_host_reset_handler = wd33c93_host_reset,
244 .can_queue = CAN_QUEUE,
246 .sg_tablesize = SG_ALL,
247 .cmd_per_lun = CMD_PER_LUN,
248 .use_clustering = DISABLE_CLUSTERING
252 #include "scsi_module.c"
254 int a2091_release(struct Scsi_Host *instance)
257 DMA(instance)->CNTR = 0;
258 release_mem_region(ZTWO_PADDR(instance->base), 256);
259 free_irq(IRQ_AMIGA_PORTS, instance);
265 MODULE_LICENSE("GPL");