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