2 * linux/drivers/acorn/scsi/eesox.c
4 * Copyright (C) 1997-2003 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 READ/WRITE version
17 * added DMA support and hardware definitions
18 * 14-03-1998 RMK Updated DMA support
19 * Added terminator control
20 * 15-04-1998 RMK Only do PIO if FAS216 will allow it.
21 * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
22 * 02-04-2000 RMK 0.0.3 Fixed NO_IRQ/NO_DMA problem, updated for new
23 * error handling code.
25 #include <linux/module.h>
26 #include <linux/blk.h>
27 #include <linux/kernel.h>
28 #include <linux/string.h>
29 #include <linux/ioport.h>
30 #include <linux/sched.h>
31 #include <linux/proc_fs.h>
32 #include <linux/delay.h>
33 #include <linux/pci.h>
34 #include <linux/init.h>
39 #include <asm/ecard.h>
40 #include <asm/pgtable.h>
42 #include "../../scsi/sd.h"
43 #include "../../scsi/hosts.h"
47 #include <scsi/scsicam.h>
50 * List of devices that the driver will recognise
52 #define EESOXSCSI_LIST { MANU_EESOX, PROD_EESOX_SCSI2 }
54 #define EESOX_FAS216_OFFSET 0xc00
55 #define EESOX_FAS216_SHIFT 3
57 #define EESOX_DMASTAT 0xa00
58 #define EESOX_STAT_INTR 0x01
59 #define EESOX_STAT_DMA 0x02
61 #define EESOX_CONTROL 0xa00
62 #define EESOX_INTR_ENABLE 0x04
63 #define EESOX_TERM_ENABLE 0x02
64 #define EESOX_RESET 0x01
66 #define EESOX_DMADATA 0xe00
71 #define VERSION "1.10 (22/01/2003 2.4.19-rmk5)"
74 * Use term=0,1,0,0,0 to turn terminators on/off
76 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
80 struct eesoxscsi_info {
82 struct expansion_card *ec;
84 unsigned int ctl_port;
86 struct scatterlist sg[NR_SG]; /* Scatter DMA list */
89 /* Prototype: void eesoxscsi_irqenable(ec, irqnr)
90 * Purpose : Enable interrupts on EESOX SCSI card
91 * Params : ec - expansion card structure
92 * : irqnr - interrupt number
95 eesoxscsi_irqenable(struct expansion_card *ec, int irqnr)
97 struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
99 info->control |= EESOX_INTR_ENABLE;
101 outb(info->control, info->ctl_port);
104 /* Prototype: void eesoxscsi_irqdisable(ec, irqnr)
105 * Purpose : Disable interrupts on EESOX SCSI card
106 * Params : ec - expansion card structure
107 * : irqnr - interrupt number
110 eesoxscsi_irqdisable(struct expansion_card *ec, int irqnr)
112 struct eesoxscsi_info *info = (struct eesoxscsi_info *)ec->irq_data;
114 info->control &= ~EESOX_INTR_ENABLE;
116 outb(info->control, info->ctl_port);
119 static const expansioncard_ops_t eesoxscsi_ops = {
120 .irqenable = eesoxscsi_irqenable,
121 .irqdisable = eesoxscsi_irqdisable,
124 /* Prototype: void eesoxscsi_terminator_ctl(*host, on_off)
125 * Purpose : Turn the EESOX SCSI terminators on or off
126 * Params : host - card to turn on/off
127 * : on_off - !0 to turn on, 0 to turn off
130 eesoxscsi_terminator_ctl(struct Scsi_Host *host, int on_off)
132 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
135 save_flags_cli(flags);
137 info->control |= EESOX_TERM_ENABLE;
139 info->control &= ~EESOX_TERM_ENABLE;
141 outb(info->control, info->ctl_port);
142 restore_flags(flags);
145 /* Prototype: void eesoxscsi_intr(irq, *dev_id, *regs)
146 * Purpose : handle interrupts from EESOX SCSI card
147 * Params : irq - interrupt number
148 * dev_id - user-defined (Scsi_Host structure)
149 * regs - processor registers at interrupt
152 eesoxscsi_intr(int irq, void *dev_id, struct pt_regs *regs)
157 /* Prototype: fasdmatype_t eesoxscsi_dma_setup(host, SCpnt, direction, min_type)
158 * Purpose : initialises DMA/PIO
159 * Params : host - host
161 * direction - DMA on to/off of card
162 * min_type - minimum DMA support that we must have for this transfer
163 * Returns : type of transfer to be performed
166 eesoxscsi_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
167 fasdmadir_t direction, fasdmatype_t min_type)
169 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
170 int dmach = host->dma_channel;
172 if (dmach != NO_DMA &&
173 (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
174 int bufs, map_dir, dma_dir;
176 bufs = copy_SCp_to_sg(&info->sg[0], SCp, NR_SG);
178 if (direction == DMA_OUT)
179 map_dir = PCI_DMA_TODEVICE,
180 dma_dir = DMA_MODE_WRITE;
182 map_dir = PCI_DMA_FROMDEVICE,
183 dma_dir = DMA_MODE_READ;
185 pci_map_sg(NULL, info->sg, bufs, map_dir);
188 set_dma_sg(dmach, info->sg, bufs);
189 set_dma_mode(dmach, dma_dir);
191 return fasdma_real_all;
194 * We don't do DMA, we only do slow PIO
196 * Some day, we will do Pseudo DMA
198 return fasdma_pseudo;
201 static void eesoxscsi_buffer_in(void *buf, int length, unsigned long base)
203 const unsigned long reg_fas = base + EESOX_FAS216_OFFSET;
204 const unsigned long reg_dmastat = base + EESOX_DMASTAT;
205 const unsigned long reg_dmadata = base + EESOX_DMADATA;
213 status = inb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
214 if (status & STAT_INT)
218 * DMA request active?
220 status = inb(reg_dmastat);
221 if (!(status & EESOX_STAT_DMA))
225 * Get number of bytes in FIFO
227 status = inb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
236 if (((u32)buf) & 2 && status >= 2) {
237 *((u16 *)buf)++ = inw(reg_dmadata);
243 unsigned long l1, l2;
245 l1 = inw(reg_dmadata);
246 l1 |= inw(reg_dmadata) << 16;
247 l2 = inw(reg_dmadata);
248 l2 |= inw(reg_dmadata) << 16;
249 *((u32 *)buf)++ = l1;
250 *((u32 *)buf)++ = l2;
258 l1 = inw(reg_dmadata);
259 l1 |= inw(reg_dmadata) << 16;
260 *((u32 *)buf)++ = l1;
266 *((u16 *)buf)++ = inw(reg_dmadata);
272 static void eesoxscsi_buffer_out(void *buf, int length, unsigned long base)
274 const unsigned long reg_fas = base + EESOX_FAS216_OFFSET;
275 const unsigned long reg_dmastat = base + EESOX_DMASTAT;
276 const unsigned long reg_dmadata = base + EESOX_DMADATA;
284 status = inb(reg_fas + (REG_STAT << EESOX_FAS216_SHIFT));
285 if (status & STAT_INT)
289 * DMA request active?
291 status = inb(reg_dmastat);
292 if (!(status & EESOX_STAT_DMA))
296 * Get number of bytes in FIFO
298 status = inb(reg_fas + (REG_CFIS << EESOX_FAS216_SHIFT)) & CFIS_CF;
301 status = 16 - status;
308 if (((u32)buf) & 2 && status >= 2) {
309 outw(*((u16 *)buf)++, reg_dmadata);
315 unsigned long l1, l2;
317 l1 = *((u32 *)buf)++;
318 l2 = *((u32 *)buf)++;
320 outw(l1, reg_dmadata);
321 outw(l1 >> 16, reg_dmadata);
322 outw(l2, reg_dmadata);
323 outw(l2 >> 16, reg_dmadata);
332 l1 = *((u32 *)buf)++;
333 outw(l1, reg_dmadata);
334 outw(l1 >> 16, reg_dmadata);
341 outw(*((u16 *)buf)++, reg_dmadata);
348 eesoxscsi_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
349 fasdmadir_t dir, int transfer_size)
351 unsigned int base = host->io_port;
353 eesoxscsi_buffer_in(SCp->ptr, SCp->this_residual, base);
355 eesoxscsi_buffer_out(SCp->ptr, SCp->this_residual, base);
359 /* Prototype: int eesoxscsi_dma_stop(host, SCpnt)
360 * Purpose : stops DMA/PIO
361 * Params : host - host
365 eesoxscsi_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
367 if (host->dma_channel != NO_DMA)
368 disable_dma(host->dma_channel);
371 /* Prototype: const char *eesoxscsi_info(struct Scsi_Host * host)
372 * Purpose : returns a descriptive string about this interface,
373 * Params : host - driver host structure to return info for.
374 * Returns : pointer to a static buffer containing null terminated string.
376 const char *eesoxscsi_info(struct Scsi_Host *host)
378 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
379 static char string[150];
381 sprintf(string, "%s (%s) in slot %d v%s terminators o%s",
382 host->hostt->name, info->info.scsi.type, info->ec->slot_no,
383 VERSION, info->control & EESOX_TERM_ENABLE ? "n" : "ff");
388 /* Prototype: int eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
389 * Purpose : Set a driver specific function
390 * Params : host - host to setup
391 * : buffer - buffer containing string describing operation
392 * : length - length of string
393 * Returns : -EINVAL, or 0
396 eesoxscsi_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
400 if (length >= 9 && strncmp(buffer, "EESOXSCSI", 9) == 0) {
404 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
405 if (buffer[5] == '1')
406 eesoxscsi_terminator_ctl(host, 1);
407 else if (buffer[5] == '0')
408 eesoxscsi_terminator_ctl(host, 0);
419 /* Prototype: int eesoxscsi_proc_info(char *buffer, char **start, off_t offset,
420 * int length, int host_no, int inout)
421 * Purpose : Return information about the driver to a user process accessing
422 * the /proc filesystem.
423 * Params : buffer - a buffer to write information to
424 * start - a pointer into this buffer set by this routine to the start
425 * of the required information.
426 * offset - offset into information that we have read upto.
427 * length - length of buffer
428 * host_no - host number to return information for
429 * inout - 0 for reading, 1 for writing.
430 * Returns : length of data written to buffer.
432 int eesoxscsi_proc_info(char *buffer, char **start, off_t offset,
433 int length, int host_no, int inout)
436 struct Scsi_Host *host;
437 struct eesoxscsi_info *info;
440 host = scsi_host_hn_get(host_no);
445 return eesoxscsi_set_proc_info(host, buffer, length);
447 info = (struct eesoxscsi_info *)host->hostdata;
450 pos = sprintf(buffer, "EESOX SCSI driver v%s\n", VERSION);
451 pos += fas216_print_host(&info->info, buffer + pos);
452 pos += sprintf(buffer + pos, "Term : o%s\n",
453 info->control & EESOX_TERM_ENABLE ? "n" : "ff");
455 pos += fas216_print_stats(&info->info, buffer + pos);
457 pos += sprintf(buffer+pos, "\nAttached devices:\n");
459 for (scd = host->host_queue; scd; scd = scd->next) {
462 proc_print_scsidevice(scd, buffer, &len, pos);
464 pos += sprintf(buffer+pos, "Extensions: ");
465 if (scd->tagged_supported)
466 pos += sprintf(buffer+pos, "TAG %sabled [%d] ",
467 scd->tagged_queue ? "en" : "dis",
469 pos += sprintf (buffer+pos, "\n");
471 if (pos + begin < offset) {
476 *start = buffer + (offset - begin);
477 pos -= offset - begin;
484 static int eesoxscsi_probe(struct expansion_card *ec);
486 /* Prototype: int eesoxscsi_detect(Scsi_Host_Template * tpnt)
487 * Purpose : initialises EESOX SCSI driver
488 * Params : tpnt - template for this SCSI adapter
489 * Returns : >0 if host found, 0 otherwise.
491 static int eesoxscsi_detect(Scsi_Host_Template *tpnt)
493 static const card_ids eesoxscsi_cids[] =
494 { EESOXSCSI_LIST, { 0xffff, 0xffff} };
495 struct expansion_card *ec;
501 ec = ecard_find(0, eesoxscsi_cids);
507 ret = eesoxscsi_probe(ec);
517 static void eesoxscsi_remove(struct Scsi_Host *host);
519 /* Prototype: int eesoxscsi_release(struct Scsi_Host * host)
520 * Purpose : releases all resources used by this adapter
521 * Params : host - driver host structure to return info for.
523 static int eesoxscsi_release(struct Scsi_Host *host)
525 eesoxscsi_remove(host);
529 static Scsi_Host_Template eesox_template = {
530 .module = THIS_MODULE,
531 .proc_info = eesoxscsi_proc_info,
532 .name = "EESOX SCSI",
533 .detect = eesoxscsi_detect,
534 .release = eesoxscsi_release,
535 .info = eesoxscsi_info,
536 .bios_param = scsicam_bios_param,
537 .command = fas216_command,
538 .queuecommand = fas216_queue_command,
539 .eh_host_reset_handler = fas216_eh_host_reset,
540 .eh_bus_reset_handler = fas216_eh_bus_reset,
541 .eh_device_reset_handler = fas216_eh_device_reset,
542 .eh_abort_handler = fas216_eh_abort,
543 .use_new_eh_code = 1,
547 .sg_tablesize = SG_ALL,
549 .use_clustering = DISABLE_CLUSTERING,
550 .proc_name = "eesox",
554 eesoxscsi_probe(struct expansion_card *ec)
556 struct Scsi_Host *host;
557 struct eesoxscsi_info *info;
561 base = ecard_address(ec, ECARD_IOC, ECARD_FAST);
563 if (!request_region(base + EESOX_FAS216_OFFSET,
564 16 << EESOX_FAS216_SHIFT, "eesox2-fas")) {
569 host = scsi_register(&eesox_template,
570 sizeof(struct eesoxscsi_info));
576 host->io_port = base;
578 host->dma_channel = ec->dma;
580 info = (struct eesoxscsi_info *)host->hostdata;
582 info->ctl_port = base + EESOX_CONTROL;
583 info->control = term[ec->slot_no] ? EESOX_TERM_ENABLE : 0;
584 outb(info->control, info->ctl_port);
586 ec->irqaddr = (unsigned char *)ioaddr(base + EESOX_DMASTAT);
587 ec->irqmask = EESOX_STAT_INTR;
589 ec->ops = (expansioncard_ops_t *)&eesoxscsi_ops;
591 info->info.scsi.io_port = base + EESOX_FAS216_OFFSET;
592 info->info.scsi.io_shift = EESOX_FAS216_SHIFT;
593 info->info.scsi.irq = host->irq;
594 info->info.ifcfg.clockrate = 40; /* MHz */
595 info->info.ifcfg.select_timeout = 255;
596 info->info.ifcfg.asyncperiod = 200; /* ns */
597 info->info.ifcfg.sync_max_depth = 7;
598 info->info.ifcfg.cntl3 = CNTL3_FASTSCSI | CNTL3_FASTCLK;
599 info->info.ifcfg.disconnect_ok = 1;
600 info->info.ifcfg.wide_max_size = 0;
601 info->info.ifcfg.capabilities = FASCAP_PSEUDODMA;
602 info->info.dma.setup = eesoxscsi_dma_setup;
603 info->info.dma.pseudo = eesoxscsi_dma_pseudo;
604 info->info.dma.stop = eesoxscsi_dma_stop;
606 ret = fas216_init(host);
610 ret = request_irq(host->irq, eesoxscsi_intr, 0, "eesox", &info->info);
612 printk("scsi%d: IRQ%d not free: %d\n",
613 host->host_no, host->irq, ret);
617 if (host->dma_channel != NO_DMA) {
618 if (request_dma(host->dma_channel, "eesox")) {
619 printk("scsi%d: DMA%d not free, DMA disabled\n",
620 host->host_no, host->dma_channel);
621 host->dma_channel = NO_DMA;
623 set_dma_speed(host->dma_channel, 180);
624 info->info.ifcfg.capabilities |= FASCAP_DMA;
625 info->info.ifcfg.cntl3 |= CNTL3_BS8;
629 ret = fas216_add(host);
633 if (host->dma_channel != NO_DMA)
634 free_dma(host->dma_channel);
635 free_irq(host->irq, host);
641 scsi_unregister(host);
644 release_region(base + EESOX_FAS216_OFFSET, 16 << EESOX_FAS216_SHIFT);
650 static void eesoxscsi_remove(struct Scsi_Host *host)
652 struct eesoxscsi_info *info = (struct eesoxscsi_info *)host->hostdata;
656 if (host->dma_channel != NO_DMA)
657 free_dma(host->dma_channel);
658 free_irq(host->irq, host);
660 release_region(host->io_port + EESOX_FAS216_OFFSET, 16 << EESOX_FAS216_SHIFT);
662 fas216_release(host);
663 ecard_release(info->ec);
666 static int __init eesox_init(void)
668 scsi_register_module(MODULE_SCSI_HA, &eesox_template);
669 if (eesox_template.present)
672 scsi_unregister_module(MODULE_SCSI_HA, &eesox_template);
676 static void __exit eesox_exit(void)
678 scsi_unregister_module(MODULE_SCSI_HA, &eesox_template);
681 module_init(eesox_init);
682 module_exit(eesox_exit);
684 MODULE_AUTHOR("Russell King");
685 MODULE_DESCRIPTION("EESOX 'Fast' SCSI driver for Acorn machines");
686 MODULE_PARM(term, "1-8i");
687 MODULE_PARM_DESC(term, "SCSI bus termination");
688 MODULE_LICENSE("GPL");