m68k/scsi: gvp11 - Kill gvp11_scsiregs typedef
[deliverable/linux.git] / drivers / scsi / a3000.c
CommitLineData
1da177e4
LT
1#include <linux/types.h>
2#include <linux/mm.h>
5a0e3ad6 3#include <linux/slab.h>
1da177e4 4#include <linux/blkdev.h>
1da177e4
LT
5#include <linux/ioport.h>
6#include <linux/init.h>
7#include <linux/spinlock.h>
8#include <linux/interrupt.h>
9
10#include <asm/setup.h>
11#include <asm/page.h>
12#include <asm/pgtable.h>
13#include <asm/amigaints.h>
14#include <asm/amigahw.h>
15#include <asm/irq.h>
16
17#include "scsi.h"
18#include <scsi/scsi_host.h>
19#include "wd33c93.h"
20#include "a3000.h"
21
21351013 22#include <linux/stat.h>
1da177e4 23
21351013 24
9387edbe
AB
25static int a3000_release(struct Scsi_Host *instance);
26
a8169e60 27static irqreturn_t a3000_intr(int irq, void *data)
1da177e4 28{
a8169e60
GU
29 struct Scsi_Host *instance = data;
30 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base);
d753722e 31 unsigned int status = regs->ISTR;
1da177e4 32 unsigned long flags;
1da177e4
LT
33
34 if (!(status & ISTR_INT_P))
35 return IRQ_NONE;
21351013 36 if (status & ISTR_INTS) {
a8169e60
GU
37 spin_lock_irqsave(instance->host_lock, flags);
38 wd33c93_intr(instance);
39 spin_unlock_irqrestore(instance->host_lock, flags);
1da177e4
LT
40 return IRQ_HANDLED;
41 }
42 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
43 return IRQ_NONE;
44}
45
65396410 46static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
1da177e4 47{
a8169e60
GU
48 struct Scsi_Host *instance = cmd->device->host;
49 struct WD33C93_hostdata *hdata = shost_priv(instance);
50 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base);
21351013
GU
51 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
52 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
53
54 /*
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
58 * buffer
59 */
60 if (addr & A3000_XFER_MASK) {
afdbbc16
GU
61 hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
62 hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len,
63 GFP_KERNEL);
21351013
GU
64
65 /* can't allocate memory; use PIO */
afdbbc16
GU
66 if (!hdata->dma_bounce_buffer) {
67 hdata->dma_bounce_len = 0;
21351013
GU
68 return 1;
69 }
70
71 if (!dir_in) {
72 /* copy to bounce buffer for a write */
afdbbc16
GU
73 memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr,
74 cmd->SCp.this_residual);
21351013
GU
75 }
76
afdbbc16 77 addr = virt_to_bus(hdata->dma_bounce_buffer);
1da177e4
LT
78 }
79
21351013
GU
80 /* setup dma direction */
81 if (!dir_in)
82 cntr |= CNTR_DDIR;
1da177e4 83
21351013 84 /* remember direction */
afdbbc16 85 hdata->dma_dir = dir_in;
1da177e4 86
d753722e 87 regs->CNTR = cntr;
1da177e4 88
21351013 89 /* setup DMA *physical* address */
d753722e 90 regs->ACR = addr;
1da177e4 91
21351013
GU
92 if (dir_in) {
93 /* invalidate any cache */
94 cache_clear(addr, cmd->SCp.this_residual);
95 } else {
96 /* push any dirty cache */
97 cache_push(addr, cmd->SCp.this_residual);
98 }
1da177e4 99
21351013
GU
100 /* start DMA */
101 mb(); /* make sure setup is completed */
d753722e 102 regs->ST_DMA = 1;
21351013 103 mb(); /* make sure DMA has started before next IO */
1da177e4 104
21351013
GU
105 /* return success */
106 return 0;
1da177e4
LT
107}
108
65396410
HK
109static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
110 int status)
1da177e4 111{
afdbbc16 112 struct WD33C93_hostdata *hdata = shost_priv(instance);
d753722e 113 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base);
afdbbc16 114
21351013
GU
115 /* disable SCSI interrupts */
116 unsigned short cntr = CNTR_PDMD;
117
afdbbc16 118 if (!hdata->dma_dir)
21351013
GU
119 cntr |= CNTR_DDIR;
120
d753722e 121 regs->CNTR = cntr;
21351013
GU
122 mb(); /* make sure CNTR is updated before next IO */
123
124 /* flush if we were reading */
afdbbc16 125 if (hdata->dma_dir) {
d753722e 126 regs->FLUSH = 1;
21351013 127 mb(); /* don't allow prefetch */
d753722e 128 while (!(regs->ISTR & ISTR_FE_FLG))
21351013
GU
129 barrier();
130 mb(); /* no IO until FLUSH is done */
131 }
132
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
136 */
d753722e 137 regs->CINT = 1;
21351013
GU
138
139 /* stop DMA */
d753722e 140 regs->SP_DMA = 1;
21351013
GU
141 mb(); /* make sure DMA is stopped before next IO */
142
143 /* restore the CONTROL bits (minus the direction flag) */
d753722e 144 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
21351013
GU
145 mb(); /* make sure CNTR is updated before next IO */
146
147 /* copy from a bounce buffer, if necessary */
afdbbc16 148 if (status && hdata->dma_bounce_buffer) {
21351013 149 if (SCpnt) {
afdbbc16 150 if (hdata->dma_dir && SCpnt)
21351013 151 memcpy(SCpnt->SCp.ptr,
afdbbc16 152 hdata->dma_bounce_buffer,
21351013 153 SCpnt->SCp.this_residual);
afdbbc16
GU
154 kfree(hdata->dma_bounce_buffer);
155 hdata->dma_bounce_buffer = NULL;
156 hdata->dma_bounce_len = 0;
21351013 157 } else {
afdbbc16
GU
158 kfree(hdata->dma_bounce_buffer);
159 hdata->dma_bounce_buffer = NULL;
160 hdata->dma_bounce_len = 0;
21351013 161 }
1da177e4 162 }
1da177e4
LT
163}
164
9387edbe 165static int __init a3000_detect(struct scsi_host_template *tpnt)
1da177e4 166{
a8169e60 167 struct Scsi_Host *instance;
d753722e
GU
168 wd33c93_regs wdregs;
169 a3000_scsiregs *regs;
afdbbc16 170 struct WD33C93_hostdata *hdata;
21351013
GU
171
172 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
173 return 0;
174 if (!request_mem_region(0xDD0000, 256, "wd33c93"))
175 return 0;
176
177 tpnt->proc_name = "A3000";
178 tpnt->proc_info = &wd33c93_proc_info;
179
a8169e60
GU
180 instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata));
181 if (instance == NULL)
21351013
GU
182 goto fail_register;
183
a8169e60
GU
184 instance->base = ZTWO_VADDR(0xDD0000);
185 instance->irq = IRQ_AMIGA_PORTS;
186 regs = (a3000_scsiregs *)(instance->base);
d753722e
GU
187 regs->DAWR = DAWR_A3000;
188 wdregs.SASR = &regs->SASR;
189 wdregs.SCMD = &regs->SCMD;
a8169e60 190 hdata = shost_priv(instance);
afdbbc16
GU
191 hdata->no_sync = 0xff;
192 hdata->fast = 0;
193 hdata->dma_mode = CTRL_DMA;
a8169e60 194 wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_12_15);
21351013 195 if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED, "A3000 SCSI",
a8169e60 196 instance))
21351013 197 goto fail_irq;
d753722e 198 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
21351013
GU
199
200 return 1;
1da177e4
LT
201
202fail_irq:
a8169e60 203 scsi_unregister(instance);
1da177e4 204fail_register:
21351013
GU
205 release_mem_region(0xDD0000, 256);
206 return 0;
1da177e4
LT
207}
208
65396410 209static int a3000_bus_reset(struct scsi_cmnd *cmd)
1da177e4
LT
210{
211 /* FIXME perform bus-specific reset */
21351013 212
df0ae249
JG
213 /* FIXME 2: kill this entire function, which should
214 cause mid-layer to call wd33c93_host_reset anyway? */
68b3aa7c
JG
215
216 spin_lock_irq(cmd->device->host->host_lock);
1da177e4 217 wd33c93_host_reset(cmd);
68b3aa7c
JG
218 spin_unlock_irq(cmd->device->host->host_lock);
219
1da177e4
LT
220 return SUCCESS;
221}
222
223#define HOSTS_C
224
d0be4a7d 225static struct scsi_host_template driver_template = {
1da177e4
LT
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,
235 .this_id = 7,
236 .sg_tablesize = SG_ALL,
237 .cmd_per_lun = CMD_PER_LUN,
238 .use_clustering = ENABLE_CLUSTERING
239};
240
241
242#include "scsi_module.c"
243
9387edbe 244static int a3000_release(struct Scsi_Host *instance)
1da177e4 245{
d753722e
GU
246 a3000_scsiregs *regs = (a3000_scsiregs *)(instance->base);
247
248 regs->CNTR = 0;
21351013
GU
249 release_mem_region(0xDD0000, 256);
250 free_irq(IRQ_AMIGA_PORTS, a3000_intr);
251 return 1;
1da177e4
LT
252}
253
254MODULE_LICENSE("GPL");
This page took 0.967719 seconds and 5 git commands to generate.