1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/acorn/scsi/powertec.c
5 * Copyright (C) 1997-2005 Russell King
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>
20 #include <asm/ecard.h>
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>
32 #include <scsi/scsicam.h>
34 #define POWERTEC_FAS216_OFFSET 0x3000
35 #define POWERTEC_FAS216_SHIFT 6
37 #define POWERTEC_INTR_STATUS 0x2000
38 #define POWERTEC_INTR_BIT 0x80
40 #define POWERTEC_RESET_CONTROL 0x1018
41 #define POWERTEC_RESET_BIT 1
43 #define POWERTEC_TERM_CONTROL 0x2018
44 #define POWERTEC_TERM_ENABLE 1
46 #define POWERTEC_INTR_CONTROL 0x101c
47 #define POWERTEC_INTR_ENABLE 1
48 #define POWERTEC_INTR_DISABLE 0
50 #define VERSION "1.10 (19/01/2003 2.5.59)"
53 * Use term=0,1,0,0,0 to turn terminators on/off.
56 static int term
[MAX_ECARDS
] = { 1, 1, 1, 1, 1, 1, 1, 1 };
60 struct powertec_info
{
62 struct expansion_card
*ec
;
64 unsigned int term_ctl
;
65 struct scatterlist sg
[NR_SG
];
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
74 powertecscsi_irqenable(struct expansion_card
*ec
, int irqnr
)
76 struct powertec_info
*info
= ec
->irq_data
;
77 writeb(POWERTEC_INTR_ENABLE
, info
->base
+ POWERTEC_INTR_CONTROL
);
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
86 powertecscsi_irqdisable(struct expansion_card
*ec
, int irqnr
)
88 struct powertec_info
*info
= ec
->irq_data
;
89 writeb(POWERTEC_INTR_DISABLE
, info
->base
+ POWERTEC_INTR_CONTROL
);
92 static const expansioncard_ops_t powertecscsi_ops
= {
93 .irqenable
= powertecscsi_irqenable
,
94 .irqdisable
= powertecscsi_irqdisable
,
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
103 powertecscsi_terminator_ctl(struct Scsi_Host
*host
, int on_off
)
105 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
107 info
->term_ctl
= on_off
? POWERTEC_TERM_ENABLE
: 0;
108 writeb(info
->term_ctl
, info
->base
+ POWERTEC_TERM_CONTROL
);
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)
116 static irqreturn_t
powertecscsi_intr(int irq
, void *dev_id
)
118 struct powertec_info
*info
= dev_id
;
120 return fas216_intr(&info
->info
);
123 /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
124 * Purpose : initialises DMA/PIO
125 * Params : host - host
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
132 powertecscsi_dma_setup(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
,
133 fasdmadir_t direction
, fasdmatype_t min_type
)
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
;
139 if (info
->info
.ifcfg
.capabilities
& FASCAP_DMA
&&
140 min_type
== fasdma_real_all
) {
141 int bufs
, map_dir
, dma_dir
;
143 bufs
= copy_SCp_to_sg(&info
->sg
[0], SCp
, NR_SG
);
145 if (direction
== DMA_OUT
) {
146 map_dir
= DMA_TO_DEVICE
;
147 dma_dir
= DMA_MODE_WRITE
;
149 map_dir
= DMA_FROM_DEVICE
;
150 dma_dir
= DMA_MODE_READ
;
153 dma_map_sg(dev
, info
->sg
, bufs
, map_dir
);
156 set_dma_sg(dmach
, info
->sg
, bufs
);
157 set_dma_mode(dmach
, dma_dir
);
159 return fasdma_real_all
;
163 * If we're not doing DMA,
169 /* Prototype: int powertecscsi_dma_stop(host, SCpnt)
170 * Purpose : stops DMA/PIO
171 * Params : host - host
175 powertecscsi_dma_stop(struct Scsi_Host
*host
, struct scsi_pointer
*SCp
)
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
);
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.
187 static const char *powertecscsi_info(struct Scsi_Host
*host
)
189 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
190 static char string
[150];
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");
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
207 powertecscsi_set_proc_info(struct Scsi_Host
*host
, char *buffer
, int length
)
211 if (length
>= 12 && strncmp(buffer
, "POWERTECSCSI", 12) == 0) {
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);
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.
242 static int powertecscsi_show_info(struct seq_file
*m
, struct Scsi_Host
*host
)
244 struct powertec_info
*info
;
246 info
= (struct powertec_info
*)host
->hostdata
;
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");
253 fas216_print_stats(&info
->info
, m
);
254 fas216_print_devices(&info
->info
, m
);
258 static ssize_t
powertecscsi_show_term(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
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
;
264 return sprintf(buf
, "%d\n", info
->term_ctl
? 1 : 0);
268 powertecscsi_store_term(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t len
)
270 struct expansion_card
*ec
= ECARD_DEV(dev
);
271 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
274 powertecscsi_terminator_ctl(host
, buf
[0] != '0');
279 static DEVICE_ATTR(bus_term
, S_IRUGO
| S_IWUSR
,
280 powertecscsi_show_term
, powertecscsi_store_term
);
282 static 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
),
296 .sg_tablesize
= SG_MAX_SEGMENTS
,
297 .dma_boundary
= IOMD_DMA_BOUNDARY
,
299 .proc_name
= "powertec",
302 static int powertecscsi_probe(struct expansion_card
*ec
,
303 const struct ecard_id
*id
)
305 struct Scsi_Host
*host
;
306 struct powertec_info
*info
;
310 ret
= ecard_request_resources(ec
);
314 base
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
320 host
= scsi_host_alloc(&powertecscsi_template
,
321 sizeof (struct powertec_info
));
327 ecard_set_drvdata(ec
, host
);
329 info
= (struct powertec_info
*)host
->hostdata
;
331 powertecscsi_terminator_ctl(host
, term
[ec
->slot_no
]);
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
;
350 ec
->irqaddr
= base
+ POWERTEC_INTR_STATUS
;
351 ec
->irqmask
= POWERTEC_INTR_BIT
;
353 ecard_setirq(ec
, &powertecscsi_ops
, info
);
355 device_create_file(&ec
->dev
, &dev_attr_bus_term
);
357 ret
= fas216_init(host
);
361 ret
= request_irq(ec
->irq
, powertecscsi_intr
,
362 0, "powertec", info
);
364 printk("scsi%d: IRQ%d not free: %d\n",
365 host
->host_no
, ec
->irq
, ret
);
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
;
375 set_dma_speed(info
->info
.scsi
.dma
, 180);
376 info
->info
.ifcfg
.capabilities
|= FASCAP_DMA
;
380 ret
= fas216_add(host
, &ec
->dev
);
384 if (info
->info
.scsi
.dma
!= NO_DMA
)
385 free_dma(info
->info
.scsi
.dma
);
386 free_irq(ec
->irq
, info
);
389 fas216_release(host
);
392 device_remove_file(&ec
->dev
, &dev_attr_bus_term
);
396 ecard_release_resources(ec
);
402 static void powertecscsi_remove(struct expansion_card
*ec
)
404 struct Scsi_Host
*host
= ecard_get_drvdata(ec
);
405 struct powertec_info
*info
= (struct powertec_info
*)host
->hostdata
;
407 ecard_set_drvdata(ec
, NULL
);
410 device_remove_file(&ec
->dev
, &dev_attr_bus_term
);
412 if (info
->info
.scsi
.dma
!= NO_DMA
)
413 free_dma(info
->info
.scsi
.dma
);
414 free_irq(ec
->irq
, info
);
416 fas216_release(host
);
418 ecard_release_resources(ec
);
421 static const struct ecard_id powertecscsi_cids
[] = {
422 { MANU_ALSYSTEMS
, PROD_ALSYS_SCSIATAPI
},
426 static struct ecard_driver powertecscsi_driver
= {
427 .probe
= powertecscsi_probe
,
428 .remove
= powertecscsi_remove
,
429 .id_table
= powertecscsi_cids
,
431 .name
= "powertecscsi",
435 static int __init
powertecscsi_init(void)
437 return ecard_register_driver(&powertecscsi_driver
);
440 static void __exit
powertecscsi_exit(void)
442 ecard_remove_driver(&powertecscsi_driver
);
445 module_init(powertecscsi_init
);
446 module_exit(powertecscsi_exit
);
448 MODULE_AUTHOR("Russell King");
449 MODULE_DESCRIPTION("Powertec SCSI driver");
450 module_param_array(term
, int, NULL
, 0);
451 MODULE_PARM_DESC(term
, "SCSI bus termination");
452 MODULE_LICENSE("GPL");