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 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
27 static struct Scsi_Host
*a3000_host
= NULL
;
29 static int a3000_release(struct Scsi_Host
*instance
);
31 static irqreturn_t
a3000_intr(int irq
, void *dummy
)
34 unsigned int status
= DMA(a3000_host
)->ISTR
;
36 if (!(status
& ISTR_INT_P
))
38 if (status
& ISTR_INTS
) {
39 spin_lock_irqsave(a3000_host
->host_lock
, flags
);
40 wd33c93_intr(a3000_host
);
41 spin_unlock_irqrestore(a3000_host
->host_lock
, flags
);
44 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status
);
48 static int dma_setup(struct scsi_cmnd
*cmd
, int dir_in
)
50 struct WD33C93_hostdata
*hdata
= shost_priv(a3000_host
);
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
;
87 DMA(a3000_host
)->CNTR
= cntr
;
89 /* setup DMA *physical* address */
90 DMA(a3000_host
)->ACR
= addr
;
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 */
102 DMA(a3000_host
)->ST_DMA
= 1;
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
);
114 /* disable SCSI interrupts */
115 unsigned short cntr
= CNTR_PDMD
;
120 DMA(instance
)->CNTR
= cntr
;
121 mb(); /* make sure CNTR is updated before next IO */
123 /* flush if we were reading */
124 if (hdata
->dma_dir
) {
125 DMA(instance
)->FLUSH
= 1;
126 mb(); /* don't allow prefetch */
127 while (!(DMA(instance
)->ISTR
& ISTR_FE_FLG
))
129 mb(); /* no IO until FLUSH is done */
132 /* clear a possible interrupt */
133 /* I think that this CINT is only necessary if you are
134 * using the terminal count features. HM 7 Mar 1994
136 DMA(instance
)->CINT
= 1;
139 DMA(instance
)->SP_DMA
= 1;
140 mb(); /* make sure DMA is stopped before next IO */
142 /* restore the CONTROL bits (minus the direction flag) */
143 DMA(instance
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
144 mb(); /* make sure CNTR is updated before next IO */
146 /* copy from a bounce buffer, if necessary */
147 if (status
&& hdata
->dma_bounce_buffer
) {
149 if (hdata
->dma_dir
&& SCpnt
)
150 memcpy(SCpnt
->SCp
.ptr
,
151 hdata
->dma_bounce_buffer
,
152 SCpnt
->SCp
.this_residual
);
153 kfree(hdata
->dma_bounce_buffer
);
154 hdata
->dma_bounce_buffer
= NULL
;
155 hdata
->dma_bounce_len
= 0;
157 kfree(hdata
->dma_bounce_buffer
);
158 hdata
->dma_bounce_buffer
= NULL
;
159 hdata
->dma_bounce_len
= 0;
164 static int __init
a3000_detect(struct scsi_host_template
*tpnt
)
167 struct WD33C93_hostdata
*hdata
;
169 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(A3000_SCSI
))
171 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
174 tpnt
->proc_name
= "A3000";
175 tpnt
->proc_info
= &wd33c93_proc_info
;
177 a3000_host
= scsi_register(tpnt
, sizeof(struct WD33C93_hostdata
));
178 if (a3000_host
== NULL
)
181 a3000_host
->base
= ZTWO_VADDR(0xDD0000);
182 a3000_host
->irq
= IRQ_AMIGA_PORTS
;
183 DMA(a3000_host
)->DAWR
= DAWR_A3000
;
184 regs
.SASR
= &(DMA(a3000_host
)->SASR
);
185 regs
.SCMD
= &(DMA(a3000_host
)->SCMD
);
186 hdata
= shost_priv(a3000_host
);
187 hdata
->no_sync
= 0xff;
189 hdata
->dma_mode
= CTRL_DMA
;
190 wd33c93_init(a3000_host
, regs
, dma_setup
, dma_stop
, WD33C93_FS_12_15
);
191 if (request_irq(IRQ_AMIGA_PORTS
, a3000_intr
, IRQF_SHARED
, "A3000 SCSI",
194 DMA(a3000_host
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
199 scsi_unregister(a3000_host
);
201 release_mem_region(0xDD0000, 256);
205 static int a3000_bus_reset(struct scsi_cmnd
*cmd
)
207 /* FIXME perform bus-specific reset */
209 /* FIXME 2: kill this entire function, which should
210 cause mid-layer to call wd33c93_host_reset anyway? */
212 spin_lock_irq(cmd
->device
->host
->host_lock
);
213 wd33c93_host_reset(cmd
);
214 spin_unlock_irq(cmd
->device
->host
->host_lock
);
221 static struct scsi_host_template driver_template
= {
222 .proc_name
= "A3000",
223 .name
= "Amiga 3000 built-in SCSI",
224 .detect
= a3000_detect
,
225 .release
= a3000_release
,
226 .queuecommand
= wd33c93_queuecommand
,
227 .eh_abort_handler
= wd33c93_abort
,
228 .eh_bus_reset_handler
= a3000_bus_reset
,
229 .eh_host_reset_handler
= wd33c93_host_reset
,
230 .can_queue
= CAN_QUEUE
,
232 .sg_tablesize
= SG_ALL
,
233 .cmd_per_lun
= CMD_PER_LUN
,
234 .use_clustering
= ENABLE_CLUSTERING
238 #include "scsi_module.c"
240 static int a3000_release(struct Scsi_Host
*instance
)
242 DMA(instance
)->CNTR
= 0;
243 release_mem_region(0xDD0000, 256);
244 free_irq(IRQ_AMIGA_PORTS
, a3000_intr
);
248 MODULE_LICENSE("GPL");