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>
24 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
25 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
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
)
40 spin_lock_irqsave(a3000_host
->host_lock
, flags
);
41 wd33c93_intr (a3000_host
);
42 spin_unlock_irqrestore(a3000_host
->host_lock
, flags
);
45 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status
);
49 static int dma_setup(struct scsi_cmnd
*cmd
, int dir_in
)
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
)
62 HDATA(a3000_host
)->dma_bounce_len
= (cmd
->SCp
.this_residual
+ 511)
64 HDATA(a3000_host
)->dma_bounce_buffer
=
65 kmalloc (HDATA(a3000_host
)->dma_bounce_len
, GFP_KERNEL
);
67 /* can't allocate memory; use PIO */
68 if (!HDATA(a3000_host
)->dma_bounce_buffer
) {
69 HDATA(a3000_host
)->dma_bounce_len
= 0;
74 /* copy to bounce buffer for a write */
75 memcpy (HDATA(a3000_host
)->dma_bounce_buffer
,
76 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
79 addr
= virt_to_bus(HDATA(a3000_host
)->dma_bounce_buffer
);
82 /* setup dma direction */
86 /* remember direction */
87 HDATA(a3000_host
)->dma_dir
= dir_in
;
89 DMA(a3000_host
)->CNTR
= cntr
;
91 /* setup DMA *physical* address */
92 DMA(a3000_host
)->ACR
= addr
;
95 /* invalidate any cache */
96 cache_clear (addr
, cmd
->SCp
.this_residual
);
98 /* push any dirty cache */
99 cache_push (addr
, cmd
->SCp
.this_residual
);
102 mb(); /* make sure setup is completed */
103 DMA(a3000_host
)->ST_DMA
= 1;
104 mb(); /* make sure DMA has started before next IO */
110 static void dma_stop(struct Scsi_Host
*instance
, struct scsi_cmnd
*SCpnt
,
113 /* disable SCSI interrupts */
114 unsigned short cntr
= CNTR_PDMD
;
116 if (!HDATA(instance
)->dma_dir
)
119 DMA(instance
)->CNTR
= cntr
;
120 mb(); /* make sure CNTR is updated before next IO */
122 /* flush if we were reading */
123 if (HDATA(instance
)->dma_dir
) {
124 DMA(instance
)->FLUSH
= 1;
125 mb(); /* don't allow prefetch */
126 while (!(DMA(instance
)->ISTR
& ISTR_FE_FLG
))
128 mb(); /* no IO until FLUSH is done */
131 /* clear a possible interrupt */
132 /* I think that this CINT is only necessary if you are
133 * using the terminal count features. HM 7 Mar 1994
135 DMA(instance
)->CINT
= 1;
138 DMA(instance
)->SP_DMA
= 1;
139 mb(); /* make sure DMA is stopped before next IO */
141 /* restore the CONTROL bits (minus the direction flag) */
142 DMA(instance
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
143 mb(); /* make sure CNTR is updated before next IO */
145 /* copy from a bounce buffer, if necessary */
146 if (status
&& HDATA(instance
)->dma_bounce_buffer
) {
148 if (HDATA(instance
)->dma_dir
&& SCpnt
)
149 memcpy (SCpnt
->SCp
.ptr
,
150 HDATA(instance
)->dma_bounce_buffer
,
151 SCpnt
->SCp
.this_residual
);
152 kfree (HDATA(instance
)->dma_bounce_buffer
);
153 HDATA(instance
)->dma_bounce_buffer
= NULL
;
154 HDATA(instance
)->dma_bounce_len
= 0;
156 kfree (HDATA(instance
)->dma_bounce_buffer
);
157 HDATA(instance
)->dma_bounce_buffer
= NULL
;
158 HDATA(instance
)->dma_bounce_len
= 0;
163 static int __init
a3000_detect(struct scsi_host_template
*tpnt
)
167 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(A3000_SCSI
))
169 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
172 tpnt
->proc_name
= "A3000";
173 tpnt
->proc_info
= &wd33c93_proc_info
;
175 a3000_host
= scsi_register (tpnt
, sizeof(struct WD33C93_hostdata
));
176 if (a3000_host
== NULL
)
179 a3000_host
->base
= ZTWO_VADDR(0xDD0000);
180 a3000_host
->irq
= IRQ_AMIGA_PORTS
;
181 DMA(a3000_host
)->DAWR
= DAWR_A3000
;
182 regs
.SASR
= &(DMA(a3000_host
)->SASR
);
183 regs
.SCMD
= &(DMA(a3000_host
)->SCMD
);
184 HDATA(a3000_host
)->no_sync
= 0xff;
185 HDATA(a3000_host
)->fast
= 0;
186 HDATA(a3000_host
)->dma_mode
= CTRL_DMA
;
187 wd33c93_init(a3000_host
, regs
, dma_setup
, dma_stop
, WD33C93_FS_12_15
);
188 if (request_irq(IRQ_AMIGA_PORTS
, a3000_intr
, IRQF_SHARED
, "A3000 SCSI",
191 DMA(a3000_host
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
197 scsi_unregister(a3000_host
);
199 release_mem_region(0xDD0000, 256);
203 static int a3000_bus_reset(struct scsi_cmnd
*cmd
)
205 /* FIXME perform bus-specific reset */
207 /* FIXME 2: kill this entire function, which should
208 cause mid-layer to call wd33c93_host_reset anyway? */
210 spin_lock_irq(cmd
->device
->host
->host_lock
);
211 wd33c93_host_reset(cmd
);
212 spin_unlock_irq(cmd
->device
->host
->host_lock
);
219 static struct scsi_host_template driver_template
= {
220 .proc_name
= "A3000",
221 .name
= "Amiga 3000 built-in SCSI",
222 .detect
= a3000_detect
,
223 .release
= a3000_release
,
224 .queuecommand
= wd33c93_queuecommand
,
225 .eh_abort_handler
= wd33c93_abort
,
226 .eh_bus_reset_handler
= a3000_bus_reset
,
227 .eh_host_reset_handler
= wd33c93_host_reset
,
228 .can_queue
= CAN_QUEUE
,
230 .sg_tablesize
= SG_ALL
,
231 .cmd_per_lun
= CMD_PER_LUN
,
232 .use_clustering
= ENABLE_CLUSTERING
236 #include "scsi_module.c"
238 static int a3000_release(struct Scsi_Host
*instance
)
241 DMA(instance
)->CNTR
= 0;
242 release_mem_region(0xDD0000, 256);
243 free_irq(IRQ_AMIGA_PORTS
, a3000_intr
);
247 MODULE_LICENSE("GPL");