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