Blame view
drivers/scsi/sgiwd93.c
8.1 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 |
/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * |
79add6277 update David Mill... |
6 |
* Copyright (C) 1996 David S. Miller (davem@davemloft.net) |
1da177e4c Linux-2.6.12-rc2 |
7 8 |
* Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu) * Copyright (C) 2001 Florian Lohoff (flo@rfc822.org) |
df9f54084 Convert SGI IP22 ... |
9 |
* Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org) |
1da177e4c Linux-2.6.12-rc2 |
10 11 12 |
* * (In all truth, Jed Schimmel wrote all this code.) */ |
df9f54084 Convert SGI IP22 ... |
13 14 |
#undef DEBUG |
1da177e4c Linux-2.6.12-rc2 |
15 16 |
#include <linux/delay.h> #include <linux/dma-mapping.h> |
df9f54084 Convert SGI IP22 ... |
17 18 19 20 21 22 23 |
#include <linux/gfp.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/types.h> #include <linux/module.h> #include <linux/platform_device.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
#include <linux/spinlock.h> |
1da177e4c Linux-2.6.12-rc2 |
25 26 |
#include <asm/sgi/hpc3.h> #include <asm/sgi/ip22.h> |
df9f54084 Convert SGI IP22 ... |
27 |
#include <asm/sgi/wd.h> |
1da177e4c Linux-2.6.12-rc2 |
28 29 |
#include "scsi.h" |
1da177e4c Linux-2.6.12-rc2 |
30 |
#include "wd33c93.h" |
1da177e4c Linux-2.6.12-rc2 |
31 |
|
1da177e4c Linux-2.6.12-rc2 |
32 33 |
struct ip22_hostdata { struct WD33C93_hostdata wh; |
2adbfa333 [SCSI] sgiwd93: u... |
34 35 36 |
dma_addr_t dma; void *cpu; struct device *dev; |
1da177e4c Linux-2.6.12-rc2 |
37 |
}; |
df9f54084 Convert SGI IP22 ... |
38 |
#define host_to_hostdata(host) ((struct ip22_hostdata *)((host)->hostdata)) |
1da177e4c Linux-2.6.12-rc2 |
39 40 41 42 |
struct hpc_chunk { struct hpc_dma_desc desc; u32 _padding; /* align to quadword boundary */ }; |
2adbfa333 [SCSI] sgiwd93: u... |
43 44 45 46 |
/* space for hpc dma descriptors */ #define HPC_DMA_SIZE PAGE_SIZE #define DMA_DIR(d) ((d == DATA_OUT_DIR) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) |
7d12e780e IRQ: Maintain reg... |
47 |
static irqreturn_t sgiwd93_intr(int irq, void *dev_id) |
1da177e4c Linux-2.6.12-rc2 |
48 |
{ |
df9f54084 Convert SGI IP22 ... |
49 |
struct Scsi_Host * host = dev_id; |
1da177e4c Linux-2.6.12-rc2 |
50 51 52 53 54 55 56 57 58 59 |
unsigned long flags; spin_lock_irqsave(host->host_lock, flags); wd33c93_intr(host); spin_unlock_irqrestore(host->host_lock, flags); return IRQ_HANDLED; } static inline |
2adbfa333 [SCSI] sgiwd93: u... |
60 |
void fill_hpc_entries(struct ip22_hostdata *hd, struct scsi_cmnd *cmd, int din) |
1da177e4c Linux-2.6.12-rc2 |
61 62 63 64 65 |
{ unsigned long len = cmd->SCp.this_residual; void *addr = cmd->SCp.ptr; dma_addr_t physaddr; unsigned long count; |
2adbfa333 [SCSI] sgiwd93: u... |
66 |
struct hpc_chunk *hcp; |
1da177e4c Linux-2.6.12-rc2 |
67 |
|
2adbfa333 [SCSI] sgiwd93: u... |
68 |
physaddr = dma_map_single(hd->dev, addr, len, DMA_DIR(din)); |
1da177e4c Linux-2.6.12-rc2 |
69 |
cmd->SCp.dma_handle = physaddr; |
2adbfa333 [SCSI] sgiwd93: u... |
70 |
hcp = hd->cpu; |
1da177e4c Linux-2.6.12-rc2 |
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
while (len) { /* * even cntinfo could be up to 16383, without * magic only 8192 works correctly */ count = len > 8192 ? 8192 : len; hcp->desc.pbuf = physaddr; hcp->desc.cntinfo = count; hcp++; len -= count; physaddr += count; } /* * To make sure, if we trip an HPC bug, that we transfer every single * byte, we tag on an extra zero length dma descriptor at the end of * the chain. */ hcp->desc.pbuf = 0; hcp->desc.cntinfo = HPCDMA_EOX; |
2adbfa333 [SCSI] sgiwd93: u... |
92 93 94 |
dma_cache_sync(hd->dev, hd->cpu, (unsigned long)(hcp + 1) - (unsigned long)hd->cpu, DMA_TO_DEVICE); |
1da177e4c Linux-2.6.12-rc2 |
95 |
} |
65396410a [SCSI] wd33c93: S... |
96 |
static int dma_setup(struct scsi_cmnd *cmd, int datainp) |
1da177e4c Linux-2.6.12-rc2 |
97 |
{ |
df9f54084 Convert SGI IP22 ... |
98 |
struct ip22_hostdata *hdata = host_to_hostdata(cmd->device->host); |
1da177e4c Linux-2.6.12-rc2 |
99 100 |
struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) cmd->device->host->base; |
1da177e4c Linux-2.6.12-rc2 |
101 |
|
2adbfa333 [SCSI] sgiwd93: u... |
102 |
pr_debug("dma_setup: datainp<%d> hcp<%p> ", datainp, hdata->cpu); |
1da177e4c Linux-2.6.12-rc2 |
103 104 105 106 107 108 109 110 111 112 113 |
hdata->wh.dma_dir = datainp; /* * wd33c93 shouldn't pass us bogus dma_setups, but it does:-( The * other wd33c93 drivers deal with it the same way (which isn't that * obvious). IMHO a better fix would be, not to do these dma setups * in the first place. */ if (cmd->SCp.ptr == NULL || cmd->SCp.this_residual == 0) return 1; |
2adbfa333 [SCSI] sgiwd93: u... |
114 |
fill_hpc_entries(hdata, cmd, datainp); |
1da177e4c Linux-2.6.12-rc2 |
115 |
|
df9f54084 Convert SGI IP22 ... |
116 117 |
pr_debug(" HPCGO "); |
1da177e4c Linux-2.6.12-rc2 |
118 119 |
/* Start up the HPC. */ |
2adbfa333 [SCSI] sgiwd93: u... |
120 |
hregs->ndptr = hdata->dma; |
1da177e4c Linux-2.6.12-rc2 |
121 122 123 124 125 126 127 |
if (datainp) hregs->ctrl = HPC3_SCTRL_ACTIVE; else hregs->ctrl = HPC3_SCTRL_ACTIVE | HPC3_SCTRL_DIR; return 0; } |
65396410a [SCSI] wd33c93: S... |
128 |
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
1da177e4c Linux-2.6.12-rc2 |
129 130 |
int status) { |
df9f54084 Convert SGI IP22 ... |
131 |
struct ip22_hostdata *hdata = host_to_hostdata(instance); |
1da177e4c Linux-2.6.12-rc2 |
132 133 134 135 |
struct hpc3_scsiregs *hregs; if (!SCpnt) return; |
2adbfa333 [SCSI] sgiwd93: u... |
136 137 |
if (SCpnt->SCp.ptr == NULL || SCpnt->SCp.this_residual == 0) return; |
1da177e4c Linux-2.6.12-rc2 |
138 |
hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base; |
df9f54084 Convert SGI IP22 ... |
139 |
pr_debug("dma_stop: status<%d> ", status); |
1da177e4c Linux-2.6.12-rc2 |
140 141 142 143 144 145 146 147 |
/* First stop the HPC and flush it's FIFO. */ if (hdata->wh.dma_dir) { hregs->ctrl |= HPC3_SCTRL_FLUSH; while (hregs->ctrl & HPC3_SCTRL_ACTIVE) barrier(); } hregs->ctrl = 0; |
2adbfa333 [SCSI] sgiwd93: u... |
148 149 150 |
dma_unmap_single(hdata->dev, SCpnt->SCp.dma_handle, SCpnt->SCp.this_residual, DMA_DIR(hdata->wh.dma_dir)); |
1da177e4c Linux-2.6.12-rc2 |
151 |
|
df9f54084 Convert SGI IP22 ... |
152 153 |
pr_debug(" "); |
1da177e4c Linux-2.6.12-rc2 |
154 155 156 157 158 159 160 161 162 163 |
} void sgiwd93_reset(unsigned long base) { struct hpc3_scsiregs *hregs = (struct hpc3_scsiregs *) base; hregs->ctrl = HPC3_SCTRL_CRESET; udelay(50); hregs->ctrl = 0; } |
fc9b51188 [SCSI] sgiwd93: e... |
164 |
EXPORT_SYMBOL_GPL(sgiwd93_reset); |
1da177e4c Linux-2.6.12-rc2 |
165 |
|
2adbfa333 [SCSI] sgiwd93: u... |
166 |
static inline void init_hpc_chain(struct ip22_hostdata *hdata) |
1da177e4c Linux-2.6.12-rc2 |
167 |
{ |
2adbfa333 [SCSI] sgiwd93: u... |
168 169 |
struct hpc_chunk *hcp = (struct hpc_chunk *)hdata->cpu; dma_addr_t dma = hdata->dma; |
1da177e4c Linux-2.6.12-rc2 |
170 171 172 |
unsigned long start, end; start = (unsigned long) hcp; |
2adbfa333 [SCSI] sgiwd93: u... |
173 |
end = start + HPC_DMA_SIZE; |
1da177e4c Linux-2.6.12-rc2 |
174 |
while (start < end) { |
2adbfa333 [SCSI] sgiwd93: u... |
175 |
hcp->desc.pnext = (u32) (dma + sizeof(struct hpc_chunk)); |
1da177e4c Linux-2.6.12-rc2 |
176 |
hcp->desc.cntinfo = HPCDMA_EOX; |
2adbfa333 [SCSI] sgiwd93: u... |
177 178 |
hcp++; dma += sizeof(struct hpc_chunk); |
1da177e4c Linux-2.6.12-rc2 |
179 180 181 |
start += sizeof(struct hpc_chunk); }; hcp--; |
2adbfa333 [SCSI] sgiwd93: u... |
182 |
hcp->desc.pnext = hdata->dma; |
1da177e4c Linux-2.6.12-rc2 |
183 |
} |
df9f54084 Convert SGI IP22 ... |
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
static int sgiwd93_bus_reset(struct scsi_cmnd *cmd) { /* FIXME perform bus-specific reset */ /* FIXME 2: kill this function, and let midlayer fallback to the same result, calling wd33c93_host_reset() */ spin_lock_irq(cmd->device->host->host_lock); wd33c93_host_reset(cmd); spin_unlock_irq(cmd->device->host->host_lock); return SUCCESS; } /* * Kludge alert - the SCSI code calls the abort and reset method with int * arguments not with pointers. So this is going to blow up beautyfully * on 64-bit systems with memory outside the compat address spaces. */ static struct scsi_host_template sgiwd93_template = { .module = THIS_MODULE, .proc_name = "SGIWD93", .name = "SGI WD93", .queuecommand = wd33c93_queuecommand, .eh_abort_handler = wd33c93_abort, .eh_bus_reset_handler = sgiwd93_bus_reset, .eh_host_reset_handler = wd33c93_host_reset, .can_queue = 16, .this_id = 7, .sg_tablesize = SG_ALL, .cmd_per_lun = 8, .use_clustering = DISABLE_CLUSTERING, }; |
6f0397905 Drivers: scsi: re... |
217 |
static int sgiwd93_probe(struct platform_device *pdev) |
1da177e4c Linux-2.6.12-rc2 |
218 |
{ |
df9f54084 Convert SGI IP22 ... |
219 220 221 |
struct sgiwd93_platform_data *pd = pdev->dev.platform_data; unsigned char *wdregs = pd->wdregs; struct hpc3_scsiregs *hregs = pd->hregs; |
1da177e4c Linux-2.6.12-rc2 |
222 223 224 |
struct ip22_hostdata *hdata; struct Scsi_Host *host; wd33c93_regs regs; |
df9f54084 Convert SGI IP22 ... |
225 226 227 228 229 230 231 232 233 |
unsigned int unit = pd->unit; unsigned int irq = pd->irq; int err; host = scsi_host_alloc(&sgiwd93_template, sizeof(struct ip22_hostdata)); if (!host) { err = -ENOMEM; goto out; } |
1da177e4c Linux-2.6.12-rc2 |
234 235 236 |
host->base = (unsigned long) hregs; host->irq = irq; |
df9f54084 Convert SGI IP22 ... |
237 |
hdata = host_to_hostdata(host); |
2adbfa333 [SCSI] sgiwd93: u... |
238 239 240 241 |
hdata->dev = &pdev->dev; hdata->cpu = dma_alloc_noncoherent(&pdev->dev, HPC_DMA_SIZE, &hdata->dma, GFP_KERNEL); if (!hdata->cpu) { |
1da177e4c Linux-2.6.12-rc2 |
242 243 244 |
printk(KERN_WARNING "sgiwd93: Could not allocate memory for " "host %d buffer. ", unit); |
df9f54084 Convert SGI IP22 ... |
245 246 |
err = -ENOMEM; goto out_put; |
1da177e4c Linux-2.6.12-rc2 |
247 |
} |
df9f54084 Convert SGI IP22 ... |
248 |
|
2adbfa333 [SCSI] sgiwd93: u... |
249 |
init_hpc_chain(hdata); |
1da177e4c Linux-2.6.12-rc2 |
250 251 252 |
regs.SASR = wdregs + 3; regs.SCMD = wdregs + 7; |
be3cb3d84 [SCSI] WD33C93: l... |
253 254 255 |
hdata->wh.no_sync = 0; hdata->wh.fast = 1; hdata->wh.dma_mode = CTRL_BURST; |
1da177e4c Linux-2.6.12-rc2 |
256 |
|
be3cb3d84 [SCSI] WD33C93: l... |
257 |
wd33c93_init(host, regs, dma_setup, dma_stop, WD33C93_FS_MHZ(20)); |
1da177e4c Linux-2.6.12-rc2 |
258 |
|
df9f54084 Convert SGI IP22 ... |
259 260 |
err = request_irq(irq, sgiwd93_intr, 0, "SGI WD93", host); if (err) { |
1da177e4c Linux-2.6.12-rc2 |
261 262 263 264 265 |
printk(KERN_WARNING "sgiwd93: Could not register irq %d " "for host %d. ", irq, unit); goto out_free; } |
1da177e4c Linux-2.6.12-rc2 |
266 |
|
df9f54084 Convert SGI IP22 ... |
267 |
platform_set_drvdata(pdev, host); |
1da177e4c Linux-2.6.12-rc2 |
268 |
|
df9f54084 Convert SGI IP22 ... |
269 270 271 |
err = scsi_add_host(host, NULL); if (err) goto out_irq; |
1da177e4c Linux-2.6.12-rc2 |
272 |
|
df9f54084 Convert SGI IP22 ... |
273 |
scsi_scan_host(host); |
1da177e4c Linux-2.6.12-rc2 |
274 |
|
df9f54084 Convert SGI IP22 ... |
275 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
276 |
|
df9f54084 Convert SGI IP22 ... |
277 278 279 |
out_irq: free_irq(irq, host); out_free: |
2adbfa333 [SCSI] sgiwd93: u... |
280 |
dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma); |
df9f54084 Convert SGI IP22 ... |
281 282 283 |
out_put: scsi_host_put(host); out: |
1da177e4c Linux-2.6.12-rc2 |
284 |
|
df9f54084 Convert SGI IP22 ... |
285 |
return err; |
1da177e4c Linux-2.6.12-rc2 |
286 |
} |
b99b4c67d [SCSI] sgiwd93: F... |
287 |
static int __exit sgiwd93_remove(struct platform_device *pdev) |
1da177e4c Linux-2.6.12-rc2 |
288 |
{ |
df9f54084 Convert SGI IP22 ... |
289 290 291 292 293 294 |
struct Scsi_Host *host = platform_get_drvdata(pdev); struct ip22_hostdata *hdata = (struct ip22_hostdata *) host->hostdata; struct sgiwd93_platform_data *pd = pdev->dev.platform_data; scsi_remove_host(host); free_irq(pd->irq, host); |
2adbfa333 [SCSI] sgiwd93: u... |
295 |
dma_free_noncoherent(&pdev->dev, HPC_DMA_SIZE, hdata->cpu, hdata->dma); |
df9f54084 Convert SGI IP22 ... |
296 |
scsi_host_put(host); |
b99b4c67d [SCSI] sgiwd93: F... |
297 |
return 0; |
df9f54084 Convert SGI IP22 ... |
298 |
} |
68b3aa7c9 [SCSI] allow slee... |
299 |
|
df9f54084 Convert SGI IP22 ... |
300 301 |
static struct platform_driver sgiwd93_driver = { .probe = sgiwd93_probe, |
6f0397905 Drivers: scsi: re... |
302 |
.remove = sgiwd93_remove, |
df9f54084 Convert SGI IP22 ... |
303 |
.driver = { |
ecc1241e8 [SCSI] jazz_esp, ... |
304 |
.name = "sgiwd93", |
df9f54084 Convert SGI IP22 ... |
305 306 |
} }; |
df0ae2497 [SCSI] allow slee... |
307 |
|
df9f54084 Convert SGI IP22 ... |
308 309 310 311 |
static int __init sgiwd93_module_init(void) { return platform_driver_register(&sgiwd93_driver); } |
68b3aa7c9 [SCSI] allow slee... |
312 |
|
df9f54084 Convert SGI IP22 ... |
313 314 315 |
static void __exit sgiwd93_module_exit(void) { return platform_driver_unregister(&sgiwd93_driver); |
1da177e4c Linux-2.6.12-rc2 |
316 |
} |
df9f54084 Convert SGI IP22 ... |
317 318 319 320 321 322 |
module_init(sgiwd93_module_init); module_exit(sgiwd93_module_exit); MODULE_DESCRIPTION("SGI WD33C93 driver"); MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>"); MODULE_LICENSE("GPL"); |
ecc1241e8 [SCSI] jazz_esp, ... |
323 |
MODULE_ALIAS("platform:sgiwd93"); |