GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / sgiwd93.c
blob99cae923aa6e3d84002f72bca485a5a442809bac
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
7 * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
8 * Copyright (C) 2001 Florian Lohoff (flo@rfc822.org)
9 * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
11 * (In all truth, Jed Schimmel wrote all this code.)
14 #undef DEBUG
16 #include <linux/delay.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/gfp.h>
19 #include <linux/interrupt.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/spinlock.h>
27 #include <asm/sgi/hpc3.h>
28 #include <asm/sgi/ip22.h>
29 #include <asm/sgi/wd.h>
31 #include "scsi.h"
32 #include "wd33c93.h"
34 struct ip22_hostdata {
35 struct WD33C93_hostdata wh;
36 dma_addr_t dma;
37 void *cpu;
38 struct device *dev;
41 #define host_to_hostdata(host) ((struct ip22_hostdata *)((host)->hostdata))
43 struct hpc_chunk {
44 struct hpc_dma_desc desc;
45 u32 _padding; /* align to quadword boundary */
48 /* space for hpc dma descriptors */
49 #define HPC_DMA_SIZE PAGE_SIZE
51 #define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)
53 static irqreturn_t sgiwd93_intr(int irq, void *dev_id)
55 struct Scsi_Host * host = dev_id;
56 unsigned long flags;
58 spin_lock_irqsave(host->host_lock, flags);
59 wd33c93_intr(host);
60 spin_unlock_irqrestore(host->host_lock, flags);
62 return IRQ_HANDLED;
65 static inline
66 void fill_hpc_entries(struct ip22_hostdata *hd, struct scsi_cmnd *cmd, int din)
68 unsigned long len = cmd->SCp.this_residual;
69 void *addr = cmd->SCp.ptr;
70 dma_addr_t physaddr;
71 unsigned long count;
72 struct hpc_chunk *hcp;
74 physaddr = dma_map_single(hd->dev, addr, len, DMA_DIR(din));
75 cmd->SCp.dma_handle = physaddr;
76 hcp = hd->cpu;
78 while (len) {
80 * even cntinfo could be up to 16383, without
81 * magic only 8192 works correctly
83 count = len > 8192 ? 8192 : len;
84 hcp->desc.pbuf = physaddr;
85 hcp->desc.cntinfo = count;
86 hcp++;
87 len -= count;
88 physaddr += count;
92 * To make sure, if we trip an HPC bug, that we transfer every single
93 * byte, we tag on an extra zero length dma descriptor at the end of
94 * the chain.
96 hcp->desc.pbuf = 0;
97 hcp->desc.cntinfo = HPCDMA_EOX;
98 dma_cache_sync(hd->dev, hd->cpu,
99 (unsigned long)(hcp + 1) - (unsigned long)hd->cpu,
100 DMA_TO_DEVICE);
103 static int dma_setup(struct scsi_cmnd *cmd, int datainp)
105 struct ip22_hostdata *hdata = host_to_hostdata(cmd->device->host);
106 struct hpc3_scsiregs *hregs =
107 (struct hpc3_scsiregs *) cmd->device->host->base;
109 pr_debug("dma_setup: datainp<%d> hcp<%p> ", datainp, hdata->cpu);
111 hdata->wh.dma_dir = datainp;
114 * wd33c93 shouldn't pass us bogus dma_setups, but it does:-( The
115 * other wd33c93 drivers deal with it the same way (which isn't that
116 * obvious). IMHO a better fix would be, not to do these dma setups
117 * in the first place.
119 if (cmd->SCp.ptr == NULL || cmd->SCp.this_residual == 0)
120 return 1;
122 fill_hpc_entries(hdata, cmd, datainp);
124 pr_debug(" HPCGO\n");
126 /* Start up the HPC. */
127 hregs->ndptr = hdata->dma;
128 if (datainp)
129 hregs->ctrl = HPC3_SCTRL_ACTIVE;
130 else
131 hregs->ctrl = HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR;
133 return 0;
136 static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
137 int status)
139 struct ip22_hostdata *hdata = host_to_hostdata(instance);
140 struct hpc3_scsiregs *hregs;
142 if (!SCpnt)
143 return;
145 if (SCpnt->SCp.ptr == NULL || SCpnt->SCp.this_residual == 0)
146 return;
148 hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base;
150 pr_debug("dma_stop: status<%d> ", status);
152 /* First stop the HPC and flush it's FIFO. */
153 if (hdata->wh.dma_dir) {
154 hregs->ctrl |= HPC3_SCTRL_FLUSH;
155 while (hregs->ctrl & HPC3_SCTRL_ACTIVE)
156 barrier();
158 hregs->ctrl = 0;
159 dma_unmap_single(hdata->dev, SCpnt->SCp.dma_handle,
160 SCpnt->SCp.this_residual,
161 DMA_DIR(hdata->wh.dma_dir));
163 pr_debug("\n");
166 void sgiwd93_reset(unsigned long base)
168 struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base;
170 hregs->ctrl = HPC3_SCTRL_CRESET;
171 udelay(50);
172 hregs->ctrl = 0;
174 EXPORT_SYMBOL_GPL(sgiwd93_reset);
176 static inline void init_hpc_chain(struct ip22_hostdata *hdata)
178 struct hpc_chunk *hcp = (struct hpc_chunk *)hdata->cpu;
179 dma_addr_t dma = hdata->dma;
180 unsigned long start, end;
182 start = (unsigned long) hcp;
183 end = start + HPC_DMA_SIZE;
184 while (start < end) {
185 hcp->desc.pnext = (u32) (dma + sizeof(struct hpc_chunk));
186 hcp->desc.cntinfo = HPCDMA_EOX;
187 hcp++;
188 dma += sizeof(struct hpc_chunk);
189 start += sizeof(struct hpc_chunk);
191 hcp--;
192 hcp->desc.pnext = hdata->dma;
195 static int sgiwd93_bus_reset(struct scsi_cmnd *cmd)
199 spin_lock_irq(cmd->device->host->host_lock);
200 wd33c93_host_reset(cmd);
201 spin_unlock_irq(cmd->device->host->host_lock);
203 return SUCCESS;
207 * Kludge alert - the SCSI code calls the abort and reset method with int
208 * arguments not with pointers. So this is going to blow up beautyfully
209 * on 64-bit systems with memory outside the compat address spaces.
211 static struct scsi_host_template sgiwd93_template = {
212 .module = THIS_MODULE,
213 .proc_name = "SGIWD93",
214 .name = "SGI WD93",
215 .queuecommand = wd33c93_queuecommand,
216 .eh_abort_handler = wd33c93_abort,
217 .eh_bus_reset_handler = sgiwd93_bus_reset,
218 .eh_host_reset_handler = wd33c93_host_reset,
219 .can_queue = 16,
220 .this_id = 7,
221 .sg_tablesize = SG_ALL,
222 .cmd_per_lun = 8,
223 .use_clustering = DISABLE_CLUSTERING,
226 static int __devinit sgiwd93_probe(struct platform_device *pdev)
228 struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
229 unsigned char *wdregs = pd->wdregs;
230 struct hpc3_scsiregs *hregs = pd->hregs;
231 struct ip22_hostdata *hdata;
232 struct Scsi_Host *host;
233 wd33c93_regs regs;
234 unsigned int unit = pd->unit;
235 unsigned int irq = pd->irq;
236 int err;
238 host = scsi_host_alloc(&sgiwd93_template, sizeof(struct ip22_hostdata));
239 if (!host) {
240 err = -ENOMEM;
241 goto out;
244 host->base = (unsigned long) hregs;
245 host->irq = irq;
247 hdata = host_to_hostdata(host);
248 hdata->dev = &pdev->dev;
249 hdata->cpu = dma_alloc_noncoherent(&pdev->dev, HPC_DMA_SIZE,
250 &hdata->dma, GFP_KERNEL);
251 if (!hdata->cpu) {
252 printk(KERN_WARNING "sgiwd93: Could not allocate memory for "
253 "host %d buffer.\n", unit);
254 err = -ENOMEM;
255 goto out_put;
258 init_hpc_chain(hdata);
260 regs.SASR = wdregs + 3;
261 regs.SCMD = wdregs + 7;
263 hdata->wh.no_sync = 0;
264 hdata->wh.fast = 1;
265 hdata->wh.dma_mode = CTRL_BURST;
267 wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_MHZ(20));
269 err = request_irq(irq, sgiwd93_intr, 0, "SGI WD93", host);
270 if (err) {
271 printk(KERN_WARNING "sgiwd93: Could not register irq %d "
272 "for host %d.\n", irq, unit);
273 goto out_free;
276 platform_set_drvdata(pdev, host);
278 err = scsi_add_host(host, NULL);
279 if (err)
280 goto out_irq;
282 scsi_scan_host(host);
284 return 0;
286 out_irq:
287 free_irq(irq, host);
288 out_free:
289 dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma);
290 out_put:
291 scsi_host_put(host);
292 out:
294 return err;
297 static int __exit sgiwd93_remove(struct platform_device *pdev)
299 struct Scsi_Host *host = platform_get_drvdata(pdev);
300 struct ip22_hostdata *hdata = (struct ip22_hostdata *) host->hostdata;
301 struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
303 scsi_remove_host(host);
304 free_irq(pd->irq, host);
305 dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma);
306 scsi_host_put(host);
307 return 0;
310 static struct platform_driver sgiwd93_driver = {
311 .probe = sgiwd93_probe,
312 .remove = __devexit_p(sgiwd93_remove),
313 .driver = {
314 .name = "sgiwd93",
315 .owner = THIS_MODULE,
319 static int __init sgiwd93_module_init(void)
321 return platform_driver_register(&sgiwd93_driver);
324 static void __exit sgiwd93_module_exit(void)
326 return platform_driver_unregister(&sgiwd93_driver);
329 module_init(sgiwd93_module_init);
330 module_exit(sgiwd93_module_exit);
332 MODULE_DESCRIPTION("SGI WD33C93 driver");
333 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
334 MODULE_LICENSE("GPL");
335 MODULE_ALIAS("platform:sgiwd93");