1 #include <linux/types.h>
3 #include <linux/blkdev.h>
4 #include <linux/ioport.h>
5 #include <linux/init.h>
6 #include <linux/spinlock.h>
7 #include <linux/interrupt.h>
11 #include <asm/pgtable.h>
12 #include <asm/amigaints.h>
13 #include <asm/amigahw.h>
17 #include <scsi/scsi_host.h>
21 #include<linux/stat.h>
23 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
24 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
26 static struct Scsi_Host
*a3000_host
= NULL
;
28 static irqreturn_t
a3000_intr (int irq
, void *dummy
)
31 unsigned int status
= DMA(a3000_host
)->ISTR
;
33 if (!(status
& ISTR_INT_P
))
35 if (status
& ISTR_INTS
)
37 spin_lock_irqsave(a3000_host
->host_lock
, flags
);
38 wd33c93_intr (a3000_host
);
39 spin_unlock_irqrestore(a3000_host
->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 unsigned short cntr
= CNTR_PDMD
| CNTR_INTEN
;
49 unsigned long addr
= virt_to_bus(cmd
->SCp
.ptr
);
52 * if the physical address has the wrong alignment, or if
53 * physical address is bad, or if it is a write and at the
54 * end of a physical memory chunk, then allocate a bounce
57 if (addr
& A3000_XFER_MASK
||
58 (!dir_in
&& mm_end_of_chunk (addr
, cmd
->SCp
.this_residual
)))
60 HDATA(a3000_host
)->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511)
62 HDATA(a3000_host
)->dma_bounce_buffer
=
63 kmalloc (HDATA(a3000_host
)->dma_bounce_len
, GFP_KERNEL
);
65 /* can't allocate memory; use PIO */
66 if (!HDATA(a3000_host
)->dma_bounce_buffer
) {
67 HDATA(a3000_host
)->dma_bounce_len
= 0;
72 /* copy to bounce buffer for a write */
74 memcpy (HDATA(a3000_host
)->dma_bounce_buffer
,
75 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
77 memcpy (HDATA(a3000_host
)->dma_bounce_buffer
,
78 cmd
->request_buffer
, cmd
->request_bufflen
);
81 addr
= virt_to_bus(HDATA(a3000_host
)->dma_bounce_buffer
);
84 /* setup dma direction */
88 /* remember direction */
89 HDATA(a3000_host
)->dma_dir
= dir_in
;
91 DMA(a3000_host
)->CNTR
= cntr
;
93 /* setup DMA *physical* address */
94 DMA(a3000_host
)->ACR
= addr
;
97 /* invalidate any cache */
98 cache_clear (addr
, cmd
->SCp
.this_residual
);
100 /* push any dirty cache */
101 cache_push (addr
, cmd
->SCp
.this_residual
);
104 mb(); /* make sure setup is completed */
105 DMA(a3000_host
)->ST_DMA
= 1;
106 mb(); /* make sure DMA has started before next IO */
112 static void dma_stop(struct Scsi_Host
*instance
, struct scsi_cmnd
*SCpnt
,
115 /* disable SCSI interrupts */
116 unsigned short cntr
= CNTR_PDMD
;
118 if (!HDATA(instance
)->dma_dir
)
121 DMA(instance
)->CNTR
= cntr
;
122 mb(); /* make sure CNTR is updated before next IO */
124 /* flush if we were reading */
125 if (HDATA(instance
)->dma_dir
) {
126 DMA(instance
)->FLUSH
= 1;
127 mb(); /* don't allow prefetch */
128 while (!(DMA(instance
)->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
137 DMA(instance
)->CINT
= 1;
140 DMA(instance
)->SP_DMA
= 1;
141 mb(); /* make sure DMA is stopped before next IO */
143 /* restore the CONTROL bits (minus the direction flag) */
144 DMA(instance
)->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(instance
)->dma_bounce_buffer
) {
149 if (SCpnt
&& SCpnt
->use_sg
) {
150 if (HDATA(instance
)->dma_dir
&& SCpnt
)
151 memcpy (SCpnt
->SCp
.ptr
,
152 HDATA(instance
)->dma_bounce_buffer
,
153 SCpnt
->SCp
.this_residual
);
154 kfree (HDATA(instance
)->dma_bounce_buffer
);
155 HDATA(instance
)->dma_bounce_buffer
= NULL
;
156 HDATA(instance
)->dma_bounce_len
= 0;
158 if (HDATA(instance
)->dma_dir
&& SCpnt
)
159 memcpy (SCpnt
->request_buffer
,
160 HDATA(instance
)->dma_bounce_buffer
,
161 SCpnt
->request_bufflen
);
163 kfree (HDATA(instance
)->dma_bounce_buffer
);
164 HDATA(instance
)->dma_bounce_buffer
= NULL
;
165 HDATA(instance
)->dma_bounce_len
= 0;
170 int __init
a3000_detect(struct scsi_host_template
*tpnt
)
174 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(A3000_SCSI
))
176 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
179 tpnt
->proc_name
= "A3000";
180 tpnt
->proc_info
= &wd33c93_proc_info
;
182 a3000_host
= scsi_register (tpnt
, sizeof(struct WD33C93_hostdata
));
183 if (a3000_host
== NULL
)
186 a3000_host
->base
= ZTWO_VADDR(0xDD0000);
187 a3000_host
->irq
= IRQ_AMIGA_PORTS
;
188 DMA(a3000_host
)->DAWR
= DAWR_A3000
;
189 regs
.SASR
= &(DMA(a3000_host
)->SASR
);
190 regs
.SCMD
= &(DMA(a3000_host
)->SCMD
);
191 wd33c93_init(a3000_host
, regs
, dma_setup
, dma_stop
, WD33C93_FS_12_15
);
192 if (request_irq(IRQ_AMIGA_PORTS
, a3000_intr
, IRQF_SHARED
, "A3000 SCSI",
195 DMA(a3000_host
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
201 scsi_unregister(a3000_host
);
203 release_mem_region(0xDD0000, 256);
207 static int a3000_bus_reset(struct scsi_cmnd
*cmd
)
209 /* FIXME perform bus-specific reset */
211 /* FIXME 2: kill this entire function, which should
212 cause mid-layer to call wd33c93_host_reset anyway? */
214 spin_lock_irq(cmd
->device
->host
->host_lock
);
215 wd33c93_host_reset(cmd
);
216 spin_unlock_irq(cmd
->device
->host
->host_lock
);
223 static struct scsi_host_template driver_template
= {
224 .proc_name
= "A3000",
225 .name
= "Amiga 3000 built-in SCSI",
226 .detect
= a3000_detect
,
227 .release
= a3000_release
,
228 .queuecommand
= wd33c93_queuecommand
,
229 .eh_abort_handler
= wd33c93_abort
,
230 .eh_bus_reset_handler
= a3000_bus_reset
,
231 .eh_host_reset_handler
= wd33c93_host_reset
,
232 .can_queue
= CAN_QUEUE
,
234 .sg_tablesize
= SG_ALL
,
235 .cmd_per_lun
= CMD_PER_LUN
,
236 .use_clustering
= ENABLE_CLUSTERING
240 #include "scsi_module.c"
242 int a3000_release(struct Scsi_Host
*instance
)
245 DMA(instance
)->CNTR
= 0;
246 release_mem_region(0xDD0000, 256);
247 free_irq(IRQ_AMIGA_PORTS
, a3000_intr
);
251 MODULE_LICENSE("GPL");