2 * linux/drivers/acorn/scsi/powertec.c
4 * Copyright (C) 1997-2000 Russell King
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.
10 * This driver is based on experimentation. Hence, it may have made
11 * assumptions about the particular card that I have available, and
12 * may not be reliable!
15 * 01-10-1997 RMK Created, READONLY version.
16 * 15-02-1998 RMK Added DMA support and hardware definitions.
17 * 15-04-1998 RMK Only do PIO if FAS216 will allow it.
18 * 02-05-1998 RMK Moved DMA sg list into per-interface structure.
19 * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
20 * 02-04-2000 RMK Updated for new error handling code.
22 #include <linux/module.h>
23 #include <linux/blk.h>
24 #include <linux/kernel.h>
25 #include <linux/string.h>
26 #include <linux/ioport.h>
27 #include <linux/sched.h>
28 #include <linux/proc_fs.h>
29 #include <linux/unistd.h>
30 #include <linux/stat.h>
31 #include <linux/delay.h>
32 #include <linux/pci.h>
33 #include <linux/init.h>
36 #include <asm/ecard.h>
39 #include <asm/pgtable.h>
41 #include "../../scsi/sd.h"
42 #include "../../scsi/hosts.h"
45 #include <scsi/scsicam.h>
48 #define POWERTEC_XTALFREQ 40
49 #define POWERTEC_ASYNC_PERIOD 200
50 #define POWERTEC_SYNC_DEPTH 7
53 * List of devices that the driver will recognise
55 #define POWERTECSCSI_LIST { MANU_ALSYSTEMS, PROD_ALSYS_SCSIATAPI }
57 #define POWERTEC_FAS216_OFFSET 0xc00
58 #define POWERTEC_FAS216_SHIFT 4
60 #define POWERTEC_INTR_STATUS 0x800
61 #define POWERTEC_INTR_BIT 0x80
63 #define POWERTEC_RESET_CONTROL 0x406
64 #define POWERTEC_RESET_BIT 1
66 #define POWERTEC_TERM_CONTROL 0x806
67 #define POWERTEC_TERM_ENABLE 1
69 #define POWERTEC_INTR_CONTROL 0x407
70 #define POWERTEC_INTR_ENABLE 1
71 #define POWERTEC_INTR_DISABLE 0
80 static struct expansion_card *ecs[MAX_ECARDS];
83 * Use term=0,1,0,0,0 to turn terminators on/off
85 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
93 unsigned int term_port;
98 struct scatterlist sg[NR_SG]; /* Scatter DMA list */
101 /* Prototype: void powertecscsi_irqenable(ec, irqnr)
102 * Purpose : Enable interrupts on Powertec SCSI card
103 * Params : ec - expansion card structure
104 * : irqnr - interrupt number
107 powertecscsi_irqenable(struct expansion_card *ec, int irqnr)
109 unsigned int port = (unsigned int)ec->irq_data;
110 outb(POWERTEC_INTR_ENABLE, port);
113 /* Prototype: void powertecscsi_irqdisable(ec, irqnr)
114 * Purpose : Disable interrupts on Powertec SCSI card
115 * Params : ec - expansion card structure
116 * : irqnr - interrupt number
119 powertecscsi_irqdisable(struct expansion_card *ec, int irqnr)
121 unsigned int port = (unsigned int)ec->irq_data;
122 outb(POWERTEC_INTR_DISABLE, port);
125 static const expansioncard_ops_t powertecscsi_ops = {
126 powertecscsi_irqenable,
127 powertecscsi_irqdisable,
134 /* Prototype: void powertecscsi_terminator_ctl(host, on_off)
135 * Purpose : Turn the Powertec SCSI terminators on or off
136 * Params : host - card to turn on/off
137 * : on_off - !0 to turn on, 0 to turn off
140 powertecscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
142 PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
145 info->control.terms = POWERTEC_TERM_ENABLE;
147 info->control.terms = 0;
149 outb(info->control.terms, info->control.term_port);
152 /* Prototype: void powertecscsi_intr(irq, *dev_id, *regs)
153 * Purpose : handle interrupts from Powertec SCSI card
154 * Params : irq - interrupt number
155 * dev_id - user-defined (Scsi_Host structure)
156 * regs - processor registers at interrupt
159 powertecscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
161 struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
166 /* Prototype: fasdmatype_t powertecscsi_dma_setup(host, SCpnt, direction, min_type)
167 * Purpose : initialises DMA/PIO
168 * Params : host - host
170 * direction - DMA on to/off of card
171 * min_type - minimum DMA support that we must have for this transfer
172 * Returns : type of transfer to be performed
175 powertecscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
176 fasdmadir_t direction, fasdmatype_t min_type)
178 PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
179 int dmach = host->dma_channel;
181 if (dmach != NO_DMA &&
182 (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
183 int bufs = SCp->buffers_residual;
184 int pci_dir, dma_dir;
187 memcpy(info->sg + 1, SCp->buffer + 1,
188 sizeof(struct scatterlist) * bufs);
189 info->sg[0].address = SCp->ptr;
190 info->sg[0].page = NULL;
191 info->sg[0].length = SCp->this_residual;
193 if (direction == DMA_OUT)
194 pci_dir = PCI_DMA_TODEVICE,
195 dma_dir = DMA_MODE_WRITE;
197 pci_dir = PCI_DMA_FROMDEVICE,
198 dma_dir = DMA_MODE_READ;
200 pci_map_sg(NULL, info->sg, bufs + 1, pci_dir);
203 set_dma_sg(dmach, info->sg, bufs + 1);
204 set_dma_mode(dmach, dma_dir);
206 return fasdma_real_all;
210 * If we're not doing DMA,
216 /* Prototype: int powertecscsi_dma_stop(host, SCpnt)
217 * Purpose : stops DMA/PIO
218 * Params : host - host
222 powertecscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
224 if (host->dma_channel != NO_DMA)
225 disable_dma(host->dma_channel);
228 /* Prototype: int powertecscsi_detect(Scsi_Host_Template * tpnt)
229 * Purpose : initialises PowerTec SCSI driver
230 * Params : tpnt - template for this SCSI adapter
231 * Returns : >0 if host found, 0 otherwise.
234 powertecscsi_detect(Scsi_Host_Template *tpnt)
236 static const card_ids powertecscsi_cids[] =
237 { POWERTECSCSI_LIST, { 0xffff, 0xffff} };
239 struct Scsi_Host *host;
241 tpnt->proc_name = "powertec";
242 memset(ecs, 0, sizeof (ecs));
247 PowerTecScsi_Info *info;
249 ecs[count] = ecard_find(0, powertecscsi_cids);
253 ecard_claim(ecs[count]);
255 host = scsi_register(tpnt, sizeof (PowerTecScsi_Info));
257 ecard_release(ecs[count]);
261 host->io_port = ecard_address(ecs[count], ECARD_IOC, ECARD_FAST);
262 host->irq = ecs[count]->irq;
263 host->dma_channel = ecs[count]->dma;
264 info = (PowerTecScsi_Info *)host->hostdata;
266 if (host->dma_channel != NO_DMA)
267 set_dma_speed(host->dma_channel, 180);
269 info->control.term_port = host->io_port + POWERTEC_TERM_CONTROL;
270 info->control.terms = term[count] ? POWERTEC_TERM_ENABLE : 0;
271 powertecscsi_terminator_ctl(host, info->control.terms);
273 info->info.scsi.io_port =
274 host->io_port + POWERTEC_FAS216_OFFSET;
275 info->info.scsi.io_shift= POWERTEC_FAS216_SHIFT;
276 info->info.scsi.irq = host->irq;
277 info->info.ifcfg.clockrate = POWERTEC_XTALFREQ;
278 info->info.ifcfg.select_timeout = 255;
279 info->info.ifcfg.asyncperiod = POWERTEC_ASYNC_PERIOD;
280 info->info.ifcfg.sync_max_depth = POWERTEC_SYNC_DEPTH;
281 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
282 info->info.ifcfg.disconnect_ok = 1;
283 info->info.ifcfg.wide_max_size = 0;
284 info->info.dma.setup = powertecscsi_dma_setup;
285 info->info.dma.pseudo = NULL;
286 info->info.dma.stop = powertecscsi_dma_stop;
288 ecs[count]->irqaddr = (unsigned char *)
289 ioaddr(host->io_port + POWERTEC_INTR_STATUS);
290 ecs[count]->irqmask = POWERTEC_INTR_BIT;
291 ecs[count]->irq_data = (void *)
292 (host->io_port + POWERTEC_INTR_CONTROL);
293 ecs[count]->ops = (expansioncard_ops_t *)&powertecscsi_ops;
295 request_region(host->io_port + POWERTEC_FAS216_OFFSET,
296 16 << POWERTEC_FAS216_SHIFT, "powertec2-fas");
298 if (host->irq != NO_IRQ &&
299 request_irq(host->irq, powertecscsi_intr,
300 SA_INTERRUPT, "powertec", host)) {
301 printk("scsi%d: IRQ%d not free, interrupts disabled\n",
302 host->host_no, host->irq);
304 info->info.scsi.irq = NO_IRQ;
307 if (host->dma_channel != NO_DMA &&
308 request_dma(host->dma_channel, "powertec")) {
309 printk("scsi%d: DMA%d not free, DMA disabled\n",
310 host->host_no, host->dma_channel);
311 host->dma_channel = NO_DMA;
320 /* Prototype: int powertecscsi_release(struct Scsi_Host * host)
321 * Purpose : releases all resources used by this adapter
322 * Params : host - driver host structure to return info for.
324 int powertecscsi_release(struct Scsi_Host *host)
328 fas216_release(host);
330 if (host->irq != NO_IRQ)
331 free_irq(host->irq, host);
332 if (host->dma_channel != NO_DMA)
333 free_dma(host->dma_channel);
334 release_region(host->io_port + POWERTEC_FAS216_OFFSET,
335 16 << POWERTEC_FAS216_SHIFT);
337 for (i = 0; i < MAX_ECARDS; i++)
339 host->io_port == ecard_address(ecs[i], ECARD_IOC, ECARD_FAST))
340 ecard_release(ecs[i]);
344 /* Prototype: const char *powertecscsi_info(struct Scsi_Host * host)
345 * Purpose : returns a descriptive string about this interface,
346 * Params : host - driver host structure to return info for.
347 * Returns : pointer to a static buffer containing null terminated string.
349 const char *powertecscsi_info(struct Scsi_Host *host)
351 PowerTecScsi_Info *info = (PowerTecScsi_Info *)host->hostdata;
352 static char string[100], *p;
355 p += sprintf(p, "%s ", host->hostt->name);
356 p += fas216_info(&info->info, p);
357 p += sprintf(p, "v%d.%d.%d terminators o%s",
358 VER_MAJOR, VER_MINOR, VER_PATCH,
359 info->control.terms ? "n" : "ff");
364 /* Prototype: int powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
365 * Purpose : Set a driver specific function
366 * Params : host - host to setup
367 * : buffer - buffer containing string describing operation
368 * : length - length of string
369 * Returns : -EINVAL, or 0
372 powertecscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
376 if (length >= 12 && strncmp(buffer, "POWERTECSCSI", 12) == 0) {
380 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
381 if (buffer[5] == '1')
382 powertecscsi_terminator_ctl(host, 1);
383 else if (buffer[5] == '0')
384 powertecscsi_terminator_ctl(host, 0);
395 /* Prototype: int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
396 * int length, int host_no, int inout)
397 * Purpose : Return information about the driver to a user process accessing
398 * the /proc filesystem.
399 * Params : buffer - a buffer to write information to
400 * start - a pointer into this buffer set by this routine to the start
401 * of the required information.
402 * offset - offset into information that we have read upto.
403 * length - length of buffer
404 * host_no - host number to return information for
405 * inout - 0 for reading, 1 for writing.
406 * Returns : length of data written to buffer.
408 int powertecscsi_proc_info(char *buffer, char **start, off_t offset,
409 int length, int host_no, int inout)
412 struct Scsi_Host *host = scsi_hostlist;
413 PowerTecScsi_Info *info;
417 if (host->host_no == host_no)
425 return powertecscsi_set_proc_info(host, buffer, length);
427 info = (PowerTecScsi_Info *)host->hostdata;
430 pos = sprintf(buffer,
431 "PowerTec SCSI driver version %d.%d.%d\n",
432 VER_MAJOR, VER_MINOR, VER_PATCH);
434 pos += fas216_print_host(&info->info, buffer + pos);
435 pos += sprintf(buffer + pos, "Term : o%s\n",
436 info->control.terms ? "n" : "ff");
438 pos += fas216_print_stats(&info->info, buffer + pos);
440 pos += sprintf(buffer+pos, "\nAttached devices:\n");
442 for (scd = host->host_queue; scd; scd = scd->next) {
443 pos += fas216_print_device(&info->info, scd, buffer + pos);
445 if (pos + begin < offset) {
449 if (pos + begin > offset + length)
453 *start = buffer + (offset - begin);
454 pos -= offset - begin;
461 static Scsi_Host_Template powertecscsi_template = {
463 proc_info: powertecscsi_proc_info,
464 name: "PowerTec SCSI",
465 detect: powertecscsi_detect,
466 release: powertecscsi_release,
467 info: powertecscsi_info,
468 bios_param: scsicam_bios_param,
471 sg_tablesize: SG_ALL,
473 use_clustering: ENABLE_CLUSTERING,
474 command: fas216_command,
475 queuecommand: fas216_queue_command,
476 eh_host_reset_handler: fas216_eh_host_reset,
477 eh_bus_reset_handler: fas216_eh_bus_reset,
478 eh_device_reset_handler: fas216_eh_device_reset,
479 eh_abort_handler: fas216_eh_abort,
483 static int __init powertecscsi_init(void)
485 scsi_register_module(MODULE_SCSI_HA, &powertecscsi_template);
486 if (powertecscsi_template.present)
489 scsi_unregister_module(MODULE_SCSI_HA, &powertecscsi_template);
493 static void __exit powertecscsi_exit(void)
495 scsi_unregister_module(MODULE_SCSI_HA, &powertecscsi_template);
498 module_init(powertecscsi_init);
499 module_exit(powertecscsi_exit);
501 MODULE_AUTHOR("Russell King");
502 MODULE_DESCRIPTION("Powertec SCSI driver");
503 MODULE_PARM(term, "1-8i");
504 MODULE_PARM_DESC(term, "SCSI bus termination");
505 MODULE_LICENSE("GPL");