1
2
3
4
5
6
7#include <linux/module.h>
8#include <linux/blkdev.h>
9#include <linux/kernel.h>
10#include <linux/string.h>
11#include <linux/ioport.h>
12#include <linux/proc_fs.h>
13#include <linux/delay.h>
14#include <linux/interrupt.h>
15#include <linux/init.h>
16#include <linux/dma-mapping.h>
17#include <linux/pgtable.h>
18
19#include <asm/dma.h>
20#include <asm/ecard.h>
21#include <asm/io.h>
22
23#include "../scsi.h"
24#include <scsi/scsi_host.h>
25#include "fas216.h"
26#include "scsi.h"
27
28#include <scsi/scsicam.h>
29
30#define POWERTEC_FAS216_OFFSET 0x3000
31#define POWERTEC_FAS216_SHIFT 6
32
33#define POWERTEC_INTR_STATUS 0x2000
34#define POWERTEC_INTR_BIT 0x80
35
36#define POWERTEC_RESET_CONTROL 0x1018
37#define POWERTEC_RESET_BIT 1
38
39#define POWERTEC_TERM_CONTROL 0x2018
40#define POWERTEC_TERM_ENABLE 1
41
42#define POWERTEC_INTR_CONTROL 0x101c
43#define POWERTEC_INTR_ENABLE 1
44#define POWERTEC_INTR_DISABLE 0
45
46#define VERSION "1.10 (19/01/2003 2.5.59)"
47
48
49
50
51
52static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
53
54#define NR_SG 256
55
56struct powertec_info {
57 FAS216_Info info;
58 struct expansion_card *ec;
59 void __iomem *base;
60 unsigned int term_ctl;
61 struct scatterlist sg[NR_SG];
62};
63
64
65
66
67
68
69static void
70powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
71{
72 struct powertec_info *info = ec->irq_data;
73 writeb(POWERTEC_INTR_ENABLE, info->base + POWERTEC_INTR_CONTROL);
74}
75
76
77
78
79
80
81static void
82powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
83{
84 struct powertec_info *info = ec->irq_data;
85 writeb(POWERTEC_INTR_DISABLE, info->base + POWERTEC_INTR_CONTROL);
86}
87
88static const expansioncard_ops_t powertecscsi_ops = {
89 .irqenable = powertecscsi_irqenable,
90 .irqdisable = powertecscsi_irqdisable,
91};
92
93
94
95
96
97
98static void
99powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
100{
101 struct powertec_info *info = (struct powertec_info *)host->hostdata;
102
103 info->term_ctl = on_off ? POWERTEC_TERM_ENABLE : 0;
104 writeb(info->term_ctl, info->base + POWERTEC_TERM_CONTROL);
105}
106
107
108
109
110
111
112static irqreturn_t powertecscsi_intr(int irq, void *dev_id)
113{
114 struct powertec_info *info = dev_id;
115
116 return fas216_intr(&info->info);
117}
118
119
120
121
122
123
124
125
126
127static fasdmatype_t
128powertecscsi_dma_setup(struct Scsi_Host *host, struct scsi_pointer *SCp,
129 fasdmadir_t direction, fasdmatype_t min_type)
130{
131 struct powertec_info *info = (struct powertec_info *)host->hostdata;
132 struct device *dev = scsi_get_device(host);
133 int dmach = info->info.scsi.dma;
134
135 if (info->info.ifcfg.capabilities & FASCAP_DMA &&
136 min_type == fasdma_real_all) {
137 int bufs, map_dir, dma_dir;
138
139 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
140
141 if (direction == DMA_OUT) {
142 map_dir = DMA_TO_DEVICE;
143 dma_dir = DMA_MODE_WRITE;
144 } else {
145 map_dir = DMA_FROM_DEVICE;
146 dma_dir = DMA_MODE_READ;
147 }
148
149 dma_map_sg(dev, info->sg, bufs, map_dir);
150
151 disable_dma(dmach);
152 set_dma_sg(dmach, info->sg, bufs);
153 set_dma_mode(dmach, dma_dir);
154 enable_dma(dmach);
155 return fasdma_real_all;
156 }
157
158
159
160
161
162 return fasdma_pio;
163}
164
165
166
167
168
169
170static void
171powertecscsi_dma_stop(struct Scsi_Host *host, struct scsi_pointer *SCp)
172{
173 struct powertec_info *info = (struct powertec_info *)host->hostdata;
174 if (info->info.scsi.dma != NO_DMA)
175 disable_dma(info->info.scsi.dma);
176}
177
178
179
180
181
182
183const char *powertecscsi_info(struct Scsi_Host *host)
184{
185 struct powertec_info *info = (struct powertec_info *)host->hostdata;
186 static char string[150];
187
188 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
189 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
190 VERSION, info->term_ctl ? "n" : "ff");
191
192 return string;
193}
194
195
196
197
198
199
200
201
202static int
203powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
204{
205 int ret = length;
206
207 if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
208 buffer += 12;
209 length -= 12;
210
211 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
212 if (buffer[5] == '1')
213 powertecscsi_terminator_ctl(host, 1);
214 else if (buffer[5] == '0')
215 powertecscsi_terminator_ctl(host, 0);
216 else
217 ret = -EINVAL;
218 } else
219 ret = -EINVAL;
220 } else
221 ret = -EINVAL;
222
223 return ret;
224}
225
226
227
228
229
230
231
232
233
234
235
236
237
238static int powertecscsi_show_info(struct seq_file *m, struct Scsi_Host *host)
239{
240 struct powertec_info *info;
241
242 info = (struct powertec_info *)host->hostdata;
243
244 seq_printf(m, "PowerTec SCSI driver v%s\n", VERSION);
245 fas216_print_host(&info->info, m);
246 seq_printf(m, "Term : o%s\n",
247 info->term_ctl ? "n" : "ff");
248
249 fas216_print_stats(&info->info, m);
250 fas216_print_devices(&info->info, m);
251 return 0;
252}
253
254static ssize_t powertecscsi_show_term(struct device *dev, struct device_attribute *attr, char *buf)
255{
256 struct expansion_card *ec = ECARD_DEV(dev);
257 struct Scsi_Host *host = ecard_get_drvdata(ec);
258 struct powertec_info *info = (struct powertec_info *)host->hostdata;
259
260 return sprintf(buf, "%d\n", info->term_ctl ? 1 : 0);
261}
262
263static ssize_t
264powertecscsi_store_term(struct device *dev, struct device_attribute *attr, const char *buf, size_t len)
265{
266 struct expansion_card *ec = ECARD_DEV(dev);
267 struct Scsi_Host *host = ecard_get_drvdata(ec);
268
269 if (len > 1)
270 powertecscsi_terminator_ctl(host, buf[0] != '0');
271
272 return len;
273}
274
275static DEVICE_ATTR(bus_term, S_IRUGO | S_IWUSR,
276 powertecscsi_show_term, powertecscsi_store_term);
277
278static struct scsi_host_template powertecscsi_template = {
279 .module = THIS_MODULE,
280 .show_info = powertecscsi_show_info,
281 .write_info = powertecscsi_set_proc_info,
282 .name = "PowerTec SCSI",
283 .info = powertecscsi_info,
284 .queuecommand = fas216_queue_command,
285 .eh_host_reset_handler = fas216_eh_host_reset,
286 .eh_bus_reset_handler = fas216_eh_bus_reset,
287 .eh_device_reset_handler = fas216_eh_device_reset,
288 .eh_abort_handler = fas216_eh_abort,
289
290 .can_queue = 8,
291 .this_id = 7,
292 .sg_tablesize = SG_MAX_SEGMENTS,
293 .dma_boundary = IOMD_DMA_BOUNDARY,
294 .cmd_per_lun = 2,
295 .proc_name = "powertec",
296};
297
298static int powertecscsi_probe(struct expansion_card *ec,
299 const struct ecard_id *id)
300{
301 struct Scsi_Host *host;
302 struct powertec_info *info;
303 void __iomem *base;
304 int ret;
305
306 ret = ecard_request_resources(ec);
307 if (ret)
308 goto out;
309
310 base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
311 if (!base) {
312 ret = -ENOMEM;
313 goto out_region;
314 }
315
316 host = scsi_host_alloc(&powertecscsi_template,
317 sizeof (struct powertec_info));
318 if (!host) {
319 ret = -ENOMEM;
320 goto out_region;
321 }
322
323 ecard_set_drvdata(ec, host);
324
325 info = (struct powertec_info *)host->hostdata;
326 info->base = base;
327 powertecscsi_terminator_ctl(host, term[ec->slot_no]);
328
329 info->ec = ec;
330 info->info.scsi.io_base = base + POWERTEC_FAS216_OFFSET;
331 info->info.scsi.io_shift = POWERTEC_FAS216_SHIFT;
332 info->info.scsi.irq = ec->irq;
333 info->info.scsi.dma = ec->dma;
334 info->info.ifcfg.clockrate = 40;
335 info->info.ifcfg.select_timeout = 255;
336 info->info.ifcfg.asyncperiod = 200;
337 info->info.ifcfg.sync_max_depth = 7;
338 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
339 info->info.ifcfg.disconnect_ok = 1;
340 info->info.ifcfg.wide_max_size = 0;
341 info->info.ifcfg.capabilities = 0;
342 info->info.dma.setup = powertecscsi_dma_setup;
343 info->info.dma.pseudo = NULL;
344 info->info.dma.stop = powertecscsi_dma_stop;
345
346 ec->irqaddr = base + POWERTEC_INTR_STATUS;
347 ec->irqmask = POWERTEC_INTR_BIT;
348
349 ecard_setirq(ec, &powertecscsi_ops, info);
350
351 device_create_file(&ec->dev, &dev_attr_bus_term);
352
353 ret = fas216_init(host);
354 if (ret)
355 goto out_free;
356
357 ret = request_irq(ec->irq, powertecscsi_intr,
358 0, "powertec", info);
359 if (ret) {
360 printk("scsi%d: IRQ%d not free: %d\n",
361 host->host_no, ec->irq, ret);
362 goto out_release;
363 }
364
365 if (info->info.scsi.dma != NO_DMA) {
366 if (request_dma(info->info.scsi.dma, "powertec")) {
367 printk("scsi%d: DMA%d not free, using PIO\n",
368 host->host_no, info->info.scsi.dma);
369 info->info.scsi.dma = NO_DMA;
370 } else {
371 set_dma_speed(info->info.scsi.dma, 180);
372 info->info.ifcfg.capabilities |= FASCAP_DMA;
373 }
374 }
375
376 ret = fas216_add(host, &ec->dev);
377 if (ret == 0)
378 goto out;
379
380 if (info->info.scsi.dma != NO_DMA)
381 free_dma(info->info.scsi.dma);
382 free_irq(ec->irq, info);
383
384 out_release:
385 fas216_release(host);
386
387 out_free:
388 device_remove_file(&ec->dev, &dev_attr_bus_term);
389 scsi_host_put(host);
390
391 out_region:
392 ecard_release_resources(ec);
393
394 out:
395 return ret;
396}
397
398static void powertecscsi_remove(struct expansion_card *ec)
399{
400 struct Scsi_Host *host = ecard_get_drvdata(ec);
401 struct powertec_info *info = (struct powertec_info *)host->hostdata;
402
403 ecard_set_drvdata(ec, NULL);
404 fas216_remove(host);
405
406 device_remove_file(&ec->dev, &dev_attr_bus_term);
407
408 if (info->info.scsi.dma != NO_DMA)
409 free_dma(info->info.scsi.dma);
410 free_irq(ec->irq, info);
411
412 fas216_release(host);
413 scsi_host_put(host);
414 ecard_release_resources(ec);
415}
416
417static const struct ecard_id powertecscsi_cids[] = {
418 { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI },
419 { 0xffff, 0xffff },
420};
421
422static struct ecard_driver powertecscsi_driver = {
423 .probe = powertecscsi_probe,
424 .remove = powertecscsi_remove,
425 .id_table = powertecscsi_cids,
426 .drv = {
427 .name = "powertecscsi",
428 },
429};
430
431static int __init powertecscsi_init(void)
432{
433 return ecard_register_driver(&powertecscsi_driver);
434}
435
436static void __exit powertecscsi_exit(void)
437{
438 ecard_remove_driver(&powertecscsi_driver);
439}
440
441module_init(powertecscsi_init);
442module_exit(powertecscsi_exit);
443
444MODULE_AUTHOR("Russell King");
445MODULE_DESCRIPTION("Powertec SCSI driver");
446module_param_array(term, int, NULL, 0);
447MODULE_PARM_DESC(term, "SCSI bus termination");
448MODULE_LICENSE("GPL");
449