]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/a3000.c
tg3: Remove tg3_config_info definition
[net-next-2.6.git] / drivers / scsi / a3000.c
CommitLineData
1da177e4
LT
1#include <linux/types.h>
2#include <linux/mm.h>
1da177e4
LT
3#include <linux/ioport.h>
4#include <linux/init.h>
c2a24a4c 5#include <linux/slab.h>
1da177e4
LT
6#include <linux/spinlock.h>
7#include <linux/interrupt.h>
c2a24a4c 8#include <linux/platform_device.h>
1da177e4 9
1da177e4
LT
10#include <asm/page.h>
11#include <asm/pgtable.h>
12#include <asm/amigaints.h>
13#include <asm/amigahw.h>
1da177e4
LT
14
15#include "scsi.h"
1da177e4
LT
16#include "wd33c93.h"
17#include "a3000.h"
18
9387edbe 19
2b21d5e4
GU
20struct a3000_hostdata {
21 struct WD33C93_hostdata wh;
22 struct a3000_scsiregs *regs;
23};
24
a8169e60 25static irqreturn_t a3000_intr(int irq, void *data)
1da177e4 26{
a8169e60 27 struct Scsi_Host *instance = data;
2b21d5e4
GU
28 struct a3000_hostdata *hdata = shost_priv(instance);
29 unsigned int status = hdata->regs->ISTR;
1da177e4 30 unsigned long flags;
1da177e4
LT
31
32 if (!(status & ISTR_INT_P))
33 return IRQ_NONE;
21351013 34 if (status & ISTR_INTS) {
a8169e60
GU
35 spin_lock_irqsave(instance->host_lock, flags);
36 wd33c93_intr(instance);
37 spin_unlock_irqrestore(instance->host_lock, flags);
1da177e4
LT
38 return IRQ_HANDLED;
39 }
c2a24a4c 40 pr_warning("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
1da177e4
LT
41 return IRQ_NONE;
42}
43
65396410 44static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
1da177e4 45{
a8169e60 46 struct Scsi_Host *instance = cmd->device->host;
2b21d5e4
GU
47 struct a3000_hostdata *hdata = shost_priv(instance);
48 struct WD33C93_hostdata *wh = &hdata->wh;
49 struct a3000_scsiregs *regs = hdata->regs;
21351013
GU
50 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
51 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
52
53 /*
54 * if the physical address has the wrong alignment, or if
55 * physical address is bad, or if it is a write and at the
56 * end of a physical memory chunk, then allocate a bounce
57 * buffer
58 */
59 if (addr & A3000_XFER_MASK) {
2b21d5e4
GU
60 wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
61 wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len,
62 GFP_KERNEL);
21351013
GU
63
64 /* can't allocate memory; use PIO */
2b21d5e4
GU
65 if (!wh->dma_bounce_buffer) {
66 wh->dma_bounce_len = 0;
21351013
GU
67 return 1;
68 }
69
70 if (!dir_in) {
71 /* copy to bounce buffer for a write */
2b21d5e4 72 memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr,
afdbbc16 73 cmd->SCp.this_residual);
21351013
GU
74 }
75
2b21d5e4 76 addr = virt_to_bus(wh->dma_bounce_buffer);
1da177e4
LT
77 }
78
21351013
GU
79 /* setup dma direction */
80 if (!dir_in)
81 cntr |= CNTR_DDIR;
1da177e4 82
21351013 83 /* remember direction */
2b21d5e4 84 wh->dma_dir = dir_in;
1da177e4 85
d753722e 86 regs->CNTR = cntr;
1da177e4 87
21351013 88 /* setup DMA *physical* address */
d753722e 89 regs->ACR = addr;
1da177e4 90
21351013
GU
91 if (dir_in) {
92 /* invalidate any cache */
93 cache_clear(addr, cmd->SCp.this_residual);
94 } else {
95 /* push any dirty cache */
96 cache_push(addr, cmd->SCp.this_residual);
97 }
1da177e4 98
21351013
GU
99 /* start DMA */
100 mb(); /* make sure setup is completed */
d753722e 101 regs->ST_DMA = 1;
21351013 102 mb(); /* make sure DMA has started before next IO */
1da177e4 103
21351013
GU
104 /* return success */
105 return 0;
1da177e4
LT
106}
107
65396410
HK
108static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
109 int status)
1da177e4 110{
2b21d5e4
GU
111 struct a3000_hostdata *hdata = shost_priv(instance);
112 struct WD33C93_hostdata *wh = &hdata->wh;
113 struct a3000_scsiregs *regs = hdata->regs;
afdbbc16 114
21351013
GU
115 /* disable SCSI interrupts */
116 unsigned short cntr = CNTR_PDMD;
117
2b21d5e4 118 if (!wh->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 */
2b21d5e4 125 if (wh->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 */
2b21d5e4 148 if (status && wh->dma_bounce_buffer) {
21351013 149 if (SCpnt) {
2b21d5e4
GU
150 if (wh->dma_dir && SCpnt)
151 memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer,
21351013 152 SCpnt->SCp.this_residual);
2b21d5e4
GU
153 kfree(wh->dma_bounce_buffer);
154 wh->dma_bounce_buffer = NULL;
155 wh->dma_bounce_len = 0;
21351013 156 } else {
2b21d5e4
GU
157 kfree(wh->dma_bounce_buffer);
158 wh->dma_bounce_buffer = NULL;
159 wh->dma_bounce_len = 0;
21351013 160 }
1da177e4 161 }
1da177e4
LT
162}
163
c2a24a4c
GU
164static int a3000_bus_reset(struct scsi_cmnd *cmd)
165{
166 struct Scsi_Host *instance = cmd->device->host;
167
168 /* FIXME perform bus-specific reset */
169
170 /* FIXME 2: kill this entire function, which should
171 cause mid-layer to call wd33c93_host_reset anyway? */
172
173 spin_lock_irq(instance->host_lock);
174 wd33c93_host_reset(cmd);
175 spin_unlock_irq(instance->host_lock);
176
177 return SUCCESS;
178}
179
180static struct scsi_host_template amiga_a3000_scsi_template = {
181 .module = THIS_MODULE,
182 .name = "Amiga 3000 built-in SCSI",
183 .proc_info = wd33c93_proc_info,
184 .proc_name = "A3000",
185 .queuecommand = wd33c93_queuecommand,
186 .eh_abort_handler = wd33c93_abort,
187 .eh_bus_reset_handler = a3000_bus_reset,
188 .eh_host_reset_handler = wd33c93_host_reset,
189 .can_queue = CAN_QUEUE,
190 .this_id = 7,
191 .sg_tablesize = SG_ALL,
192 .cmd_per_lun = CMD_PER_LUN,
193 .use_clustering = ENABLE_CLUSTERING
194};
195
196static int __init amiga_a3000_scsi_probe(struct platform_device *pdev)
1da177e4 197{
c2a24a4c 198 struct resource *res;
a8169e60 199 struct Scsi_Host *instance;
c2a24a4c 200 int error;
c57c1cab 201 struct a3000_scsiregs *regs;
c2a24a4c 202 wd33c93_regs wdregs;
2b21d5e4 203 struct a3000_hostdata *hdata;
21351013 204
c2a24a4c
GU
205 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
206 if (!res)
207 return -ENODEV;
21351013 208
c2a24a4c
GU
209 if (!request_mem_region(res->start, resource_size(res), "wd33c93"))
210 return -EBUSY;
21351013 211
c2a24a4c 212 instance = scsi_host_alloc(&amiga_a3000_scsi_template,
2b21d5e4 213 sizeof(struct a3000_hostdata));
c2a24a4c
GU
214 if (!instance) {
215 error = -ENOMEM;
216 goto fail_alloc;
217 }
21351013 218
a8169e60 219 instance->irq = IRQ_AMIGA_PORTS;
c2a24a4c 220
2b21d5e4 221 regs = (struct a3000_scsiregs *)ZTWO_VADDR(res->start);
d753722e 222 regs->DAWR = DAWR_A3000;
c2a24a4c 223
d753722e
GU
224 wdregs.SASR = &regs->SASR;
225 wdregs.SCMD = &regs->SCMD;
c2a24a4c 226
a8169e60 227 hdata = shost_priv(instance);
2b21d5e4
GU
228 hdata->wh.no_sync = 0xff;
229 hdata->wh.fast = 0;
230 hdata->wh.dma_mode = CTRL_DMA;
231 hdata->regs = regs;
c2a24a4c 232
a8169e60 233 wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_12_15);
c2a24a4c
GU
234 error = request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED,
235 "A3000 SCSI", instance);
236 if (error)
21351013 237 goto fail_irq;
c2a24a4c 238
d753722e 239 regs->CNTR = CNTR_PDMD | CNTR_INTEN;
21351013 240
c2a24a4c
GU
241 error = scsi_add_host(instance, NULL);
242 if (error)
243 goto fail_host;
1da177e4 244
c2a24a4c
GU
245 platform_set_drvdata(pdev, instance);
246
247 scsi_scan_host(instance);
21351013 248 return 0;
c2a24a4c
GU
249
250fail_host:
251 free_irq(IRQ_AMIGA_PORTS, instance);
252fail_irq:
253 scsi_host_put(instance);
254fail_alloc:
255 release_mem_region(res->start, resource_size(res));
256 return error;
1da177e4
LT
257}
258
c2a24a4c 259static int __exit amiga_a3000_scsi_remove(struct platform_device *pdev)
1da177e4 260{
c2a24a4c 261 struct Scsi_Host *instance = platform_get_drvdata(pdev);
2b21d5e4 262 struct a3000_hostdata *hdata = shost_priv(instance);
c2a24a4c 263 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
68b3aa7c 264
2b21d5e4 265 hdata->regs->CNTR = 0;
c2a24a4c
GU
266 scsi_remove_host(instance);
267 free_irq(IRQ_AMIGA_PORTS, instance);
268 scsi_host_put(instance);
269 release_mem_region(res->start, resource_size(res));
270 return 0;
1da177e4
LT
271}
272
c2a24a4c
GU
273static struct platform_driver amiga_a3000_scsi_driver = {
274 .remove = __exit_p(amiga_a3000_scsi_remove),
275 .driver = {
276 .name = "amiga-a3000-scsi",
277 .owner = THIS_MODULE,
278 },
1da177e4
LT
279};
280
c2a24a4c 281static int __init amiga_a3000_scsi_init(void)
1da177e4 282{
c2a24a4c
GU
283 return platform_driver_probe(&amiga_a3000_scsi_driver,
284 amiga_a3000_scsi_probe);
285}
286module_init(amiga_a3000_scsi_init);
d753722e 287
c2a24a4c
GU
288static void __exit amiga_a3000_scsi_exit(void)
289{
290 platform_driver_unregister(&amiga_a3000_scsi_driver);
1da177e4 291}
c2a24a4c 292module_exit(amiga_a3000_scsi_exit);
1da177e4 293
c2a24a4c 294MODULE_DESCRIPTION("Amiga 3000 built-in SCSI");
1da177e4 295MODULE_LICENSE("GPL");
c2a24a4c 296MODULE_ALIAS("platform:amiga-a3000-scsi");