diff options
Diffstat (limited to 'drivers/scsi/a2091.c')
-rw-r--r-- | drivers/scsi/a2091.c | 245 |
1 files changed, 135 insertions, 110 deletions
diff --git a/drivers/scsi/a2091.c b/drivers/scsi/a2091.c index 308541ff85cf..1bb5d3f0e260 100644 --- a/drivers/scsi/a2091.c +++ b/drivers/scsi/a2091.c | |||
@@ -1,34 +1,31 @@ | |||
1 | #include <linux/types.h> | 1 | #include <linux/types.h> |
2 | #include <linux/mm.h> | ||
3 | #include <linux/slab.h> | ||
4 | #include <linux/blkdev.h> | ||
5 | #include <linux/init.h> | 2 | #include <linux/init.h> |
6 | #include <linux/interrupt.h> | 3 | #include <linux/interrupt.h> |
4 | #include <linux/mm.h> | ||
5 | #include <linux/slab.h> | ||
6 | #include <linux/spinlock.h> | ||
7 | #include <linux/zorro.h> | ||
7 | 8 | ||
8 | #include <asm/setup.h> | ||
9 | #include <asm/page.h> | 9 | #include <asm/page.h> |
10 | #include <asm/pgtable.h> | 10 | #include <asm/pgtable.h> |
11 | #include <asm/amigaints.h> | 11 | #include <asm/amigaints.h> |
12 | #include <asm/amigahw.h> | 12 | #include <asm/amigahw.h> |
13 | #include <linux/zorro.h> | ||
14 | #include <asm/irq.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | 13 | ||
17 | #include "scsi.h" | 14 | #include "scsi.h" |
18 | #include <scsi/scsi_host.h> | ||
19 | #include "wd33c93.h" | 15 | #include "wd33c93.h" |
20 | #include "a2091.h" | 16 | #include "a2091.h" |
21 | 17 | ||
22 | #include <linux/stat.h> | ||
23 | |||
24 | 18 | ||
25 | static int a2091_release(struct Scsi_Host *instance); | 19 | struct a2091_hostdata { |
20 | struct WD33C93_hostdata wh; | ||
21 | struct a2091_scsiregs *regs; | ||
22 | }; | ||
26 | 23 | ||
27 | static irqreturn_t a2091_intr(int irq, void *data) | 24 | static irqreturn_t a2091_intr(int irq, void *data) |
28 | { | 25 | { |
29 | struct Scsi_Host *instance = data; | 26 | struct Scsi_Host *instance = data; |
30 | a2091_scsiregs *regs = (a2091_scsiregs *)(instance->base); | 27 | struct a2091_hostdata *hdata = shost_priv(instance); |
31 | unsigned int status = regs->ISTR; | 28 | unsigned int status = hdata->regs->ISTR; |
32 | unsigned long flags; | 29 | unsigned long flags; |
33 | 30 | ||
34 | if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS)) | 31 | if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS)) |
@@ -43,38 +40,39 @@ static irqreturn_t a2091_intr(int irq, void *data) | |||
43 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) | 40 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
44 | { | 41 | { |
45 | struct Scsi_Host *instance = cmd->device->host; | 42 | struct Scsi_Host *instance = cmd->device->host; |
46 | struct WD33C93_hostdata *hdata = shost_priv(instance); | 43 | struct a2091_hostdata *hdata = shost_priv(instance); |
47 | a2091_scsiregs *regs = (a2091_scsiregs *)(instance->base); | 44 | struct WD33C93_hostdata *wh = &hdata->wh; |
45 | struct a2091_scsiregs *regs = hdata->regs; | ||
48 | unsigned short cntr = CNTR_PDMD | CNTR_INTEN; | 46 | unsigned short cntr = CNTR_PDMD | CNTR_INTEN; |
49 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); | 47 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); |
50 | 48 | ||
51 | /* don't allow DMA if the physical address is bad */ | 49 | /* don't allow DMA if the physical address is bad */ |
52 | if (addr & A2091_XFER_MASK) { | 50 | if (addr & A2091_XFER_MASK) { |
53 | hdata->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; | 51 | wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
54 | hdata->dma_bounce_buffer = kmalloc(hdata->dma_bounce_len, | 52 | wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len, |
55 | GFP_KERNEL); | 53 | GFP_KERNEL); |
56 | 54 | ||
57 | /* can't allocate memory; use PIO */ | 55 | /* can't allocate memory; use PIO */ |
58 | if (!hdata->dma_bounce_buffer) { | 56 | if (!wh->dma_bounce_buffer) { |
59 | hdata->dma_bounce_len = 0; | 57 | wh->dma_bounce_len = 0; |
60 | return 1; | 58 | return 1; |
61 | } | 59 | } |
62 | 60 | ||
63 | /* get the physical address of the bounce buffer */ | 61 | /* get the physical address of the bounce buffer */ |
64 | addr = virt_to_bus(hdata->dma_bounce_buffer); | 62 | addr = virt_to_bus(wh->dma_bounce_buffer); |
65 | 63 | ||
66 | /* the bounce buffer may not be in the first 16M of physmem */ | 64 | /* the bounce buffer may not be in the first 16M of physmem */ |
67 | if (addr & A2091_XFER_MASK) { | 65 | if (addr & A2091_XFER_MASK) { |
68 | /* we could use chipmem... maybe later */ | 66 | /* we could use chipmem... maybe later */ |
69 | kfree(hdata->dma_bounce_buffer); | 67 | kfree(wh->dma_bounce_buffer); |
70 | hdata->dma_bounce_buffer = NULL; | 68 | wh->dma_bounce_buffer = NULL; |
71 | hdata->dma_bounce_len = 0; | 69 | wh->dma_bounce_len = 0; |
72 | return 1; | 70 | return 1; |
73 | } | 71 | } |
74 | 72 | ||
75 | if (!dir_in) { | 73 | if (!dir_in) { |
76 | /* copy to bounce buffer for a write */ | 74 | /* copy to bounce buffer for a write */ |
77 | memcpy(hdata->dma_bounce_buffer, cmd->SCp.ptr, | 75 | memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr, |
78 | cmd->SCp.this_residual); | 76 | cmd->SCp.this_residual); |
79 | } | 77 | } |
80 | } | 78 | } |
@@ -84,7 +82,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) | |||
84 | cntr |= CNTR_DDIR; | 82 | cntr |= CNTR_DDIR; |
85 | 83 | ||
86 | /* remember direction */ | 84 | /* remember direction */ |
87 | hdata->dma_dir = dir_in; | 85 | wh->dma_dir = dir_in; |
88 | 86 | ||
89 | regs->CNTR = cntr; | 87 | regs->CNTR = cntr; |
90 | 88 | ||
@@ -108,20 +106,21 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in) | |||
108 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, | 106 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
109 | int status) | 107 | int status) |
110 | { | 108 | { |
111 | struct WD33C93_hostdata *hdata = shost_priv(instance); | 109 | struct a2091_hostdata *hdata = shost_priv(instance); |
112 | a2091_scsiregs *regs = (a2091_scsiregs *)(instance->base); | 110 | struct WD33C93_hostdata *wh = &hdata->wh; |
111 | struct a2091_scsiregs *regs = hdata->regs; | ||
113 | 112 | ||
114 | /* disable SCSI interrupts */ | 113 | /* disable SCSI interrupts */ |
115 | unsigned short cntr = CNTR_PDMD; | 114 | unsigned short cntr = CNTR_PDMD; |
116 | 115 | ||
117 | if (!hdata->dma_dir) | 116 | if (!wh->dma_dir) |
118 | cntr |= CNTR_DDIR; | 117 | cntr |= CNTR_DDIR; |
119 | 118 | ||
120 | /* disable SCSI interrupts */ | 119 | /* disable SCSI interrupts */ |
121 | regs->CNTR = cntr; | 120 | regs->CNTR = cntr; |
122 | 121 | ||
123 | /* flush if we were reading */ | 122 | /* flush if we were reading */ |
124 | if (hdata->dma_dir) { | 123 | if (wh->dma_dir) { |
125 | regs->FLUSH = 1; | 124 | regs->FLUSH = 1; |
126 | while (!(regs->ISTR & ISTR_FE_FLG)) | 125 | while (!(regs->ISTR & ISTR_FE_FLG)) |
127 | ; | 126 | ; |
@@ -137,95 +136,37 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, | |||
137 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; | 136 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; |
138 | 137 | ||
139 | /* copy from a bounce buffer, if necessary */ | 138 | /* copy from a bounce buffer, if necessary */ |
140 | if (status && hdata->dma_bounce_buffer) { | 139 | if (status && wh->dma_bounce_buffer) { |
141 | if (hdata->dma_dir) | 140 | if (wh->dma_dir) |
142 | memcpy(SCpnt->SCp.ptr, hdata->dma_bounce_buffer, | 141 | memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer, |
143 | SCpnt->SCp.this_residual); | 142 | SCpnt->SCp.this_residual); |
144 | kfree(hdata->dma_bounce_buffer); | 143 | kfree(wh->dma_bounce_buffer); |
145 | hdata->dma_bounce_buffer = NULL; | 144 | wh->dma_bounce_buffer = NULL; |
146 | hdata->dma_bounce_len = 0; | 145 | wh->dma_bounce_len = 0; |
147 | } | ||
148 | } | ||
149 | |||
150 | static int __init a2091_detect(struct scsi_host_template *tpnt) | ||
151 | { | ||
152 | static unsigned char called = 0; | ||
153 | struct Scsi_Host *instance; | ||
154 | unsigned long address; | ||
155 | struct zorro_dev *z = NULL; | ||
156 | wd33c93_regs wdregs; | ||
157 | a2091_scsiregs *regs; | ||
158 | struct WD33C93_hostdata *hdata; | ||
159 | int num_a2091 = 0; | ||
160 | |||
161 | if (!MACH_IS_AMIGA || called) | ||
162 | return 0; | ||
163 | called = 1; | ||
164 | |||
165 | tpnt->proc_name = "A2091"; | ||
166 | tpnt->proc_info = &wd33c93_proc_info; | ||
167 | |||
168 | while ((z = zorro_find_device(ZORRO_WILDCARD, z))) { | ||
169 | if (z->id != ZORRO_PROD_CBM_A590_A2091_1 && | ||
170 | z->id != ZORRO_PROD_CBM_A590_A2091_2) | ||
171 | continue; | ||
172 | address = z->resource.start; | ||
173 | if (!request_mem_region(address, 256, "wd33c93")) | ||
174 | continue; | ||
175 | |||
176 | instance = scsi_register(tpnt, sizeof(struct WD33C93_hostdata)); | ||
177 | if (instance == NULL) | ||
178 | goto release; | ||
179 | instance->base = ZTWO_VADDR(address); | ||
180 | instance->irq = IRQ_AMIGA_PORTS; | ||
181 | instance->unique_id = z->slotaddr; | ||
182 | regs = (a2091_scsiregs *)(instance->base); | ||
183 | regs->DAWR = DAWR_A2091; | ||
184 | wdregs.SASR = ®s->SASR; | ||
185 | wdregs.SCMD = ®s->SCMD; | ||
186 | hdata = shost_priv(instance); | ||
187 | hdata->no_sync = 0xff; | ||
188 | hdata->fast = 0; | ||
189 | hdata->dma_mode = CTRL_DMA; | ||
190 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, | ||
191 | WD33C93_FS_8_10); | ||
192 | if (request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, | ||
193 | "A2091 SCSI", instance)) | ||
194 | goto unregister; | ||
195 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; | ||
196 | num_a2091++; | ||
197 | continue; | ||
198 | |||
199 | unregister: | ||
200 | scsi_unregister(instance); | ||
201 | release: | ||
202 | release_mem_region(address, 256); | ||
203 | } | 146 | } |
204 | |||
205 | return num_a2091; | ||
206 | } | 147 | } |
207 | 148 | ||
208 | static int a2091_bus_reset(struct scsi_cmnd *cmd) | 149 | static int a2091_bus_reset(struct scsi_cmnd *cmd) |
209 | { | 150 | { |
151 | struct Scsi_Host *instance = cmd->device->host; | ||
152 | |||
210 | /* FIXME perform bus-specific reset */ | 153 | /* FIXME perform bus-specific reset */ |
211 | 154 | ||
212 | /* FIXME 2: kill this function, and let midlayer fall back | 155 | /* FIXME 2: kill this function, and let midlayer fall back |
213 | to the same action, calling wd33c93_host_reset() */ | 156 | to the same action, calling wd33c93_host_reset() */ |
214 | 157 | ||
215 | spin_lock_irq(cmd->device->host->host_lock); | 158 | spin_lock_irq(instance->host_lock); |
216 | wd33c93_host_reset(cmd); | 159 | wd33c93_host_reset(cmd); |
217 | spin_unlock_irq(cmd->device->host->host_lock); | 160 | spin_unlock_irq(instance->host_lock); |
218 | 161 | ||
219 | return SUCCESS; | 162 | return SUCCESS; |
220 | } | 163 | } |
221 | 164 | ||
222 | #define HOSTS_C | 165 | static struct scsi_host_template a2091_scsi_template = { |
223 | 166 | .module = THIS_MODULE, | |
224 | static struct scsi_host_template driver_template = { | ||
225 | .proc_name = "A2901", | ||
226 | .name = "Commodore A2091/A590 SCSI", | 167 | .name = "Commodore A2091/A590 SCSI", |
227 | .detect = a2091_detect, | 168 | .proc_info = wd33c93_proc_info, |
228 | .release = a2091_release, | 169 | .proc_name = "A2901", |
229 | .queuecommand = wd33c93_queuecommand, | 170 | .queuecommand = wd33c93_queuecommand, |
230 | .eh_abort_handler = wd33c93_abort, | 171 | .eh_abort_handler = wd33c93_abort, |
231 | .eh_bus_reset_handler = a2091_bus_reset, | 172 | .eh_bus_reset_handler = a2091_bus_reset, |
@@ -237,19 +178,103 @@ static struct scsi_host_template driver_template = { | |||
237 | .use_clustering = DISABLE_CLUSTERING | 178 | .use_clustering = DISABLE_CLUSTERING |
238 | }; | 179 | }; |
239 | 180 | ||
181 | static int __devinit a2091_probe(struct zorro_dev *z, | ||
182 | const struct zorro_device_id *ent) | ||
183 | { | ||
184 | struct Scsi_Host *instance; | ||
185 | int error; | ||
186 | struct a2091_scsiregs *regs; | ||
187 | wd33c93_regs wdregs; | ||
188 | struct a2091_hostdata *hdata; | ||
240 | 189 | ||
241 | #include "scsi_module.c" | 190 | if (!request_mem_region(z->resource.start, 256, "wd33c93")) |
191 | return -EBUSY; | ||
242 | 192 | ||
243 | static int a2091_release(struct Scsi_Host *instance) | 193 | instance = scsi_host_alloc(&a2091_scsi_template, |
194 | sizeof(struct a2091_hostdata)); | ||
195 | if (!instance) { | ||
196 | error = -ENOMEM; | ||
197 | goto fail_alloc; | ||
198 | } | ||
199 | |||
200 | instance->irq = IRQ_AMIGA_PORTS; | ||
201 | instance->unique_id = z->slotaddr; | ||
202 | |||
203 | regs = (struct a2091_scsiregs *)ZTWO_VADDR(z->resource.start); | ||
204 | regs->DAWR = DAWR_A2091; | ||
205 | |||
206 | wdregs.SASR = ®s->SASR; | ||
207 | wdregs.SCMD = ®s->SCMD; | ||
208 | |||
209 | hdata = shost_priv(instance); | ||
210 | hdata->wh.no_sync = 0xff; | ||
211 | hdata->wh.fast = 0; | ||
212 | hdata->wh.dma_mode = CTRL_DMA; | ||
213 | hdata->regs = regs; | ||
214 | |||
215 | wd33c93_init(instance, wdregs, dma_setup, dma_stop, WD33C93_FS_8_10); | ||
216 | error = request_irq(IRQ_AMIGA_PORTS, a2091_intr, IRQF_SHARED, | ||
217 | "A2091 SCSI", instance); | ||
218 | if (error) | ||
219 | goto fail_irq; | ||
220 | |||
221 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; | ||
222 | |||
223 | error = scsi_add_host(instance, NULL); | ||
224 | if (error) | ||
225 | goto fail_host; | ||
226 | |||
227 | zorro_set_drvdata(z, instance); | ||
228 | |||
229 | scsi_scan_host(instance); | ||
230 | return 0; | ||
231 | |||
232 | fail_host: | ||
233 | free_irq(IRQ_AMIGA_PORTS, instance); | ||
234 | fail_irq: | ||
235 | scsi_host_put(instance); | ||
236 | fail_alloc: | ||
237 | release_mem_region(z->resource.start, 256); | ||
238 | return error; | ||
239 | } | ||
240 | |||
241 | static void __devexit a2091_remove(struct zorro_dev *z) | ||
244 | { | 242 | { |
245 | #ifdef MODULE | 243 | struct Scsi_Host *instance = zorro_get_drvdata(z); |
246 | a2091_scsiregs *regs = (a2091_scsiregs *)(instance->base); | 244 | struct a2091_hostdata *hdata = shost_priv(instance); |
247 | 245 | ||
248 | regs->CNTR = 0; | 246 | hdata->regs->CNTR = 0; |
249 | release_mem_region(ZTWO_PADDR(instance->base), 256); | 247 | scsi_remove_host(instance); |
250 | free_irq(IRQ_AMIGA_PORTS, instance); | 248 | free_irq(IRQ_AMIGA_PORTS, instance); |
251 | #endif | 249 | scsi_host_put(instance); |
252 | return 1; | 250 | release_mem_region(z->resource.start, 256); |
251 | } | ||
252 | |||
253 | static struct zorro_device_id a2091_zorro_tbl[] __devinitdata = { | ||
254 | { ZORRO_PROD_CBM_A590_A2091_1 }, | ||
255 | { ZORRO_PROD_CBM_A590_A2091_2 }, | ||
256 | { 0 } | ||
257 | }; | ||
258 | MODULE_DEVICE_TABLE(zorro, a2091_zorro_tbl); | ||
259 | |||
260 | static struct zorro_driver a2091_driver = { | ||
261 | .name = "a2091", | ||
262 | .id_table = a2091_zorro_tbl, | ||
263 | .probe = a2091_probe, | ||
264 | .remove = __devexit_p(a2091_remove), | ||
265 | }; | ||
266 | |||
267 | static int __init a2091_init(void) | ||
268 | { | ||
269 | return zorro_register_driver(&a2091_driver); | ||
270 | } | ||
271 | module_init(a2091_init); | ||
272 | |||
273 | static void __exit a2091_exit(void) | ||
274 | { | ||
275 | zorro_unregister_driver(&a2091_driver); | ||
253 | } | 276 | } |
277 | module_exit(a2091_exit); | ||
254 | 278 | ||
279 | MODULE_DESCRIPTION("Commodore A2091/A590 SCSI"); | ||
255 | MODULE_LICENSE("GPL"); | 280 | MODULE_LICENSE("GPL"); |