]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | #include <linux/types.h> |
1da177e4 LT |
2 | #include <linux/init.h> |
3 | #include <linux/interrupt.h> | |
c737e22c GU |
4 | #include <linux/mm.h> |
5 | #include <linux/slab.h> | |
6 | #include <linux/spinlock.h> | |
7 | #include <linux/zorro.h> | |
1da177e4 | 8 | |
1da177e4 LT |
9 | #include <asm/page.h> |
10 | #include <asm/pgtable.h> | |
11 | #include <asm/amigaints.h> | |
12 | #include <asm/amigahw.h> | |
1da177e4 LT |
13 | |
14 | #include "scsi.h" | |
1da177e4 LT |
15 | #include "wd33c93.h" |
16 | #include "a2091.h" | |
17 | ||
5880f486 | 18 | |
65c2784a GU |
19 | struct a2091_hostdata { |
20 | struct WD33C93_hostdata wh; | |
21 | struct a2091_scsiregs *regs; | |
22 | }; | |
23 | ||
b1de6ab7 | 24 | static irqreturn_t a2091_intr(int irq, void *data) |
1da177e4 | 25 | { |
b1de6ab7 | 26 | struct Scsi_Host *instance = data; |
65c2784a GU |
27 | struct a2091_hostdata *hdata = shost_priv(instance); |
28 | unsigned int status = hdata->regs->ISTR; | |
09bc85b0 | 29 | unsigned long flags; |
09bc85b0 | 30 | |
09bc85b0 GU |
31 | if (!(status & (ISTR_INT_F | ISTR_INT_P)) || !(status & ISTR_INTS)) |
32 | return IRQ_NONE; | |
33 | ||
34 | spin_lock_irqsave(instance->host_lock, flags); | |
35 | wd33c93_intr(instance); | |
36 | spin_unlock_irqrestore(instance->host_lock, flags); | |
37 | return IRQ_HANDLED; | |
1da177e4 LT |
38 | } |
39 | ||
65396410 | 40 | static int dma_setup(struct scsi_cmnd *cmd, int dir_in) |
1da177e4 | 41 | { |
6d1d5d43 | 42 | struct Scsi_Host *instance = cmd->device->host; |
65c2784a GU |
43 | struct a2091_hostdata *hdata = shost_priv(instance); |
44 | struct WD33C93_hostdata *wh = &hdata->wh; | |
45 | struct a2091_scsiregs *regs = hdata->regs; | |
09bc85b0 GU |
46 | unsigned short cntr = CNTR_PDMD | CNTR_INTEN; |
47 | unsigned long addr = virt_to_bus(cmd->SCp.ptr); | |
1da177e4 | 48 | |
09bc85b0 | 49 | /* don't allow DMA if the physical address is bad */ |
1da177e4 | 50 | if (addr & A2091_XFER_MASK) { |
65c2784a GU |
51 | wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff; |
52 | wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len, | |
53 | GFP_KERNEL); | |
09bc85b0 GU |
54 | |
55 | /* can't allocate memory; use PIO */ | |
65c2784a GU |
56 | if (!wh->dma_bounce_buffer) { |
57 | wh->dma_bounce_len = 0; | |
09bc85b0 GU |
58 | return 1; |
59 | } | |
60 | ||
61 | /* get the physical address of the bounce buffer */ | |
65c2784a | 62 | addr = virt_to_bus(wh->dma_bounce_buffer); |
09bc85b0 GU |
63 | |
64 | /* the bounce buffer may not be in the first 16M of physmem */ | |
65 | if (addr & A2091_XFER_MASK) { | |
66 | /* we could use chipmem... maybe later */ | |
65c2784a GU |
67 | kfree(wh->dma_bounce_buffer); |
68 | wh->dma_bounce_buffer = NULL; | |
69 | wh->dma_bounce_len = 0; | |
09bc85b0 GU |
70 | return 1; |
71 | } | |
72 | ||
73 | if (!dir_in) { | |
74 | /* copy to bounce buffer for a write */ | |
65c2784a | 75 | memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr, |
6d1d5d43 | 76 | cmd->SCp.this_residual); |
09bc85b0 | 77 | } |
1da177e4 | 78 | } |
1da177e4 | 79 | |
09bc85b0 GU |
80 | /* setup dma direction */ |
81 | if (!dir_in) | |
82 | cntr |= CNTR_DDIR; | |
1da177e4 | 83 | |
09bc85b0 | 84 | /* remember direction */ |
65c2784a | 85 | wh->dma_dir = dir_in; |
1da177e4 | 86 | |
b1de6ab7 | 87 | regs->CNTR = cntr; |
1da177e4 | 88 | |
09bc85b0 | 89 | /* setup DMA *physical* address */ |
b1de6ab7 | 90 | regs->ACR = addr; |
1da177e4 | 91 | |
09bc85b0 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 | } | |
99 | /* start DMA */ | |
b1de6ab7 | 100 | regs->ST_DMA = 1; |
1da177e4 | 101 | |
09bc85b0 GU |
102 | /* return success */ |
103 | return 0; | |
1da177e4 LT |
104 | } |
105 | ||
65396410 | 106 | static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, |
09bc85b0 | 107 | int status) |
1da177e4 | 108 | { |
65c2784a GU |
109 | struct a2091_hostdata *hdata = shost_priv(instance); |
110 | struct WD33C93_hostdata *wh = &hdata->wh; | |
111 | struct a2091_scsiregs *regs = hdata->regs; | |
6d1d5d43 | 112 | |
09bc85b0 GU |
113 | /* disable SCSI interrupts */ |
114 | unsigned short cntr = CNTR_PDMD; | |
115 | ||
65c2784a | 116 | if (!wh->dma_dir) |
09bc85b0 GU |
117 | cntr |= CNTR_DDIR; |
118 | ||
119 | /* disable SCSI interrupts */ | |
b1de6ab7 | 120 | regs->CNTR = cntr; |
09bc85b0 GU |
121 | |
122 | /* flush if we were reading */ | |
65c2784a | 123 | if (wh->dma_dir) { |
b1de6ab7 GU |
124 | regs->FLUSH = 1; |
125 | while (!(regs->ISTR & ISTR_FE_FLG)) | |
09bc85b0 GU |
126 | ; |
127 | } | |
128 | ||
129 | /* clear a possible interrupt */ | |
b1de6ab7 | 130 | regs->CINT = 1; |
09bc85b0 GU |
131 | |
132 | /* stop DMA */ | |
b1de6ab7 | 133 | regs->SP_DMA = 1; |
09bc85b0 GU |
134 | |
135 | /* restore the CONTROL bits (minus the direction flag) */ | |
b1de6ab7 | 136 | regs->CNTR = CNTR_PDMD | CNTR_INTEN; |
09bc85b0 GU |
137 | |
138 | /* copy from a bounce buffer, if necessary */ | |
65c2784a GU |
139 | if (status && wh->dma_bounce_buffer) { |
140 | if (wh->dma_dir) | |
141 | memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer, | |
09bc85b0 | 142 | SCpnt->SCp.this_residual); |
65c2784a GU |
143 | kfree(wh->dma_bounce_buffer); |
144 | wh->dma_bounce_buffer = NULL; | |
145 | wh->dma_bounce_len = 0; | |
09bc85b0 | 146 | } |
1da177e4 LT |
147 | } |
148 | ||
65396410 | 149 | static int a2091_bus_reset(struct scsi_cmnd *cmd) |
1da177e4 | 150 | { |
c737e22c GU |
151 | struct Scsi_Host *instance = cmd->device->host; |
152 | ||
1da177e4 | 153 | /* FIXME perform bus-specific reset */ |
68b3aa7c | 154 | |
df0ae249 JG |
155 | /* FIXME 2: kill this function, and let midlayer fall back |
156 | to the same action, calling wd33c93_host_reset() */ | |
157 | ||
c737e22c | 158 | spin_lock_irq(instance->host_lock); |
1da177e4 | 159 | wd33c93_host_reset(cmd); |
c737e22c | 160 | spin_unlock_irq(instance->host_lock); |
68b3aa7c | 161 | |
1da177e4 LT |
162 | return SUCCESS; |
163 | } | |
164 | ||
c737e22c GU |
165 | static struct scsi_host_template a2091_scsi_template = { |
166 | .module = THIS_MODULE, | |
1da177e4 | 167 | .name = "Commodore A2091/A590 SCSI", |
c737e22c GU |
168 | .proc_info = wd33c93_proc_info, |
169 | .proc_name = "A2901", | |
1da177e4 LT |
170 | .queuecommand = wd33c93_queuecommand, |
171 | .eh_abort_handler = wd33c93_abort, | |
172 | .eh_bus_reset_handler = a2091_bus_reset, | |
173 | .eh_host_reset_handler = wd33c93_host_reset, | |
174 | .can_queue = CAN_QUEUE, | |
175 | .this_id = 7, | |
176 | .sg_tablesize = SG_ALL, | |
177 | .cmd_per_lun = CMD_PER_LUN, | |
178 | .use_clustering = DISABLE_CLUSTERING | |
179 | }; | |
180 | ||
c737e22c GU |
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; | |
65c2784a | 188 | struct a2091_hostdata *hdata; |
c737e22c GU |
189 | |
190 | if (!request_mem_region(z->resource.start, 256, "wd33c93")) | |
191 | return -EBUSY; | |
192 | ||
193 | instance = scsi_host_alloc(&a2091_scsi_template, | |
65c2784a | 194 | sizeof(struct a2091_hostdata)); |
c737e22c GU |
195 | if (!instance) { |
196 | error = -ENOMEM; | |
197 | goto fail_alloc; | |
198 | } | |
199 | ||
c737e22c GU |
200 | instance->irq = IRQ_AMIGA_PORTS; |
201 | instance->unique_id = z->slotaddr; | |
202 | ||
65c2784a | 203 | regs = (struct a2091_scsiregs *)ZTWO_VADDR(z->resource.start); |
c737e22c GU |
204 | regs->DAWR = DAWR_A2091; |
205 | ||
206 | wdregs.SASR = ®s->SASR; | |
207 | wdregs.SCMD = ®s->SCMD; | |
1da177e4 | 208 | |
c737e22c | 209 | hdata = shost_priv(instance); |
65c2784a GU |
210 | hdata->wh.no_sync = 0xff; |
211 | hdata->wh.fast = 0; | |
212 | hdata->wh.dma_mode = CTRL_DMA; | |
213 | hdata->regs = regs; | |
c737e22c GU |
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; | |
1da177e4 | 231 | |
c737e22c GU |
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) | |
1da177e4 | 242 | { |
c737e22c | 243 | struct Scsi_Host *instance = zorro_get_drvdata(z); |
65c2784a | 244 | struct a2091_hostdata *hdata = shost_priv(instance); |
b1de6ab7 | 245 | |
65c2784a | 246 | hdata->regs->CNTR = 0; |
c737e22c | 247 | scsi_remove_host(instance); |
1da177e4 | 248 | free_irq(IRQ_AMIGA_PORTS, instance); |
c737e22c GU |
249 | scsi_host_put(instance); |
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); | |
1da177e4 | 276 | } |
c737e22c | 277 | module_exit(a2091_exit); |
1da177e4 | 278 | |
c737e22c | 279 | MODULE_DESCRIPTION("Commodore A2091/A590 SCSI"); |
1da177e4 | 280 | MODULE_LICENSE("GPL"); |