2 * linux/drivers/acorn/scsi/cumana_2.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.
11 * 30-08-1997 RMK 0.0.0 Created, READONLY version.
12 * 22-01-1998 RMK 0.0.1 Updated to 2.1.80.
13 * 15-04-1998 RMK 0.0.1 Only do PIO if FAS216 will allow it.
14 * 02-05-1998 RMK 0.0.2 Updated & added DMA support.
15 * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
16 * 18-08-1998 RMK 0.0.3 Fixed synchronous transfer depth.
17 * 02-04-2000 RMK 0.0.4 Updated for new error handling code.
19 #include <linux/module.h>
20 #include <linux/blk.h>
21 #include <linux/kernel.h>
22 #include <linux/string.h>
23 #include <linux/ioport.h>
24 #include <linux/sched.h>
25 #include <linux/proc_fs.h>
26 #include <linux/unistd.h>
27 #include <linux/stat.h>
28 #include <linux/delay.h>
29 #include <linux/pci.h>
30 #include <linux/init.h>
33 #include <asm/ecard.h>
36 #include <asm/pgtable.h>
38 #include "../../scsi/sd.h"
39 #include "../../scsi/hosts.h"
42 #include <scsi/scsicam.h>
45 #define CUMANASCSI2_XTALFREQ 40
46 #define CUMANASCSI2_ASYNC_PERIOD 200
47 #define CUMANASCSI2_SYNC_DEPTH 7
50 * List of devices that the driver will recognise
52 #define CUMANASCSI2_LIST { MANU_CUMANA, PROD_CUMANA_SCSI_2 }
54 #define CUMANASCSI2_STATUS (0)
55 #define STATUS_INT (1 << 0)
56 #define STATUS_DRQ (1 << 1)
57 #define STATUS_LATCHED (1 << 3)
59 #define CUMANASCSI2_ALATCH (5)
60 #define ALATCH_ENA_INT (3)
61 #define ALATCH_DIS_INT (2)
62 #define ALATCH_ENA_TERM (5)
63 #define ALATCH_DIS_TERM (4)
64 #define ALATCH_ENA_BIT32 (11)
65 #define ALATCH_DIS_BIT32 (10)
66 #define ALATCH_ENA_DMA (13)
67 #define ALATCH_DIS_DMA (12)
68 #define ALATCH_DMA_OUT (15)
69 #define ALATCH_DMA_IN (14)
71 #define CUMANASCSI2_PSEUDODMA (0x80)
73 #define CUMANASCSI2_FAS216_OFFSET (0xc0)
74 #define CUMANASCSI2_FAS216_SHIFT 0
83 static struct expansion_card *ecs[MAX_ECARDS];
86 * Use term=0,1,0,0,0 to turn terminators on/off
88 static int term[MAX_ECARDS] = { 1, 1, 1, 1, 1, 1, 1, 1 };
96 unsigned int status; /* card status register */
97 unsigned int alatch; /* Control register */
98 unsigned int terms; /* Terminator state */
99 unsigned int dmaarea; /* Pseudo DMA area */
100 struct scatterlist sg[NR_SG]; /* Scatter DMA list */
103 #define CSTATUS_IRQ (1 << 0)
104 #define CSTATUS_DRQ (1 << 1)
106 /* Prototype: void cumanascsi_2_irqenable(ec, irqnr)
107 * Purpose : Enable interrupts on Cumana SCSI 2 card
108 * Params : ec - expansion card structure
109 * : irqnr - interrupt number
112 cumanascsi_2_irqenable(struct expansion_card *ec, int irqnr)
114 unsigned int port = (unsigned int)ec->irq_data;
115 outb(ALATCH_ENA_INT, port);
118 /* Prototype: void cumanascsi_2_irqdisable(ec, irqnr)
119 * Purpose : Disable interrupts on Cumana SCSI 2 card
120 * Params : ec - expansion card structure
121 * : irqnr - interrupt number
124 cumanascsi_2_irqdisable(struct expansion_card *ec, int irqnr)
126 unsigned int port = (unsigned int)ec->irq_data;
127 outb(ALATCH_DIS_INT, port);
130 static const expansioncard_ops_t cumanascsi_2_ops = {
131 cumanascsi_2_irqenable,
132 cumanascsi_2_irqdisable,
139 /* Prototype: void cumanascsi_2_terminator_ctl(host, on_off)
140 * Purpose : Turn the Cumana SCSI 2 terminators on or off
141 * Params : host - card to turn on/off
142 * : on_off - !0 to turn on, 0 to turn off
145 cumanascsi_2_terminator_ctl(struct Scsi_Host *host, int on_off)
147 CumanaScsi2_Info *info = (CumanaScsi2_Info *)host->hostdata;
151 outb (ALATCH_ENA_TERM, info->alatch);
154 outb (ALATCH_DIS_TERM, info->alatch);
158 /* Prototype: void cumanascsi_2_intr(irq, *dev_id, *regs)
159 * Purpose : handle interrupts from Cumana SCSI 2 card
160 * Params : irq - interrupt number
161 * dev_id - user-defined (Scsi_Host structure)
162 * regs - processor registers at interrupt
165 cumanascsi_2_intr(int irq, void *dev_id, struct pt_regs *regs)
167 struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
172 /* Prototype: fasdmatype_t cumanascsi_2_dma_setup(host, SCpnt, direction, min_type)
173 * Purpose : initialises DMA/PIO
174 * Params : host - host
176 * direction - DMA on to/off of card
177 * min_type - minimum DMA support that we must have for this transfer
178 * Returns : type of transfer to be performed
181 cumanascsi_2_dma_setup(struct Scsi_Host *host, Scsi_Pointer *SCp,
182 fasdmadir_t direction, fasdmatype_t min_type)
184 CumanaScsi2_Info *info = (CumanaScsi2_Info *)host->hostdata;
185 int dmach = host->dma_channel;
187 outb(ALATCH_DIS_DMA, info->alatch);
189 if (dmach != NO_DMA &&
190 (min_type == fasdma_real_all || SCp->this_residual >= 512)) {
191 int bufs = SCp->buffers_residual;
192 int pci_dir, dma_dir, alatch_dir;
195 memcpy(info->sg + 1, SCp->buffer + 1,
196 sizeof(struct scatterlist) * bufs);
197 info->sg[0].address = SCp->ptr;
198 info->sg[0].page = NULL;
199 info->sg[0].length = SCp->this_residual;
201 if (direction == DMA_OUT)
202 pci_dir = PCI_DMA_TODEVICE,
203 dma_dir = DMA_MODE_WRITE,
204 alatch_dir = ALATCH_DMA_OUT;
206 pci_dir = PCI_DMA_FROMDEVICE,
207 dma_dir = DMA_MODE_READ,
208 alatch_dir = ALATCH_DMA_IN;
210 pci_map_sg(NULL, info->sg, bufs + 1, pci_dir);
213 set_dma_sg(dmach, info->sg, bufs + 1);
214 outb(alatch_dir, info->alatch);
215 set_dma_mode(dmach, dma_dir);
217 outb(ALATCH_ENA_DMA, info->alatch);
218 outb(ALATCH_DIS_BIT32, info->alatch);
219 return fasdma_real_all;
223 * If we're not doing DMA,
224 * we'll do pseudo DMA
230 * Prototype: void cumanascsi_2_dma_pseudo(host, SCpnt, direction, transfer)
231 * Purpose : handles pseudo DMA
232 * Params : host - host
234 * direction - DMA on to/off of card
235 * transfer - minimum number of bytes we expect to transfer
238 cumanascsi_2_dma_pseudo(struct Scsi_Host *host, Scsi_Pointer *SCp,
239 fasdmadir_t direction, int transfer)
241 CumanaScsi2_Info *info = (CumanaScsi2_Info *)host->hostdata;
245 length = SCp->this_residual;
248 if (direction == DMA_OUT)
252 unsigned int status = inb(info->status);
254 if (status & STATUS_INT)
257 if (!(status & STATUS_DRQ))
260 word = *addr | *(addr + 1) << 8;
261 outw (info->dmaarea);
266 printk ("PSEUDO_OUT???\n");
269 if (transfer && (transfer & 255)) {
270 while (length >= 256) {
271 unsigned int status = inb(info->status);
273 if (status & STATUS_INT)
276 if (!(status & STATUS_DRQ))
279 insw(info->dmaarea, addr, 256 >> 1);
287 unsigned int status = inb(info->status);
289 if (status & STATUS_INT)
292 if (!(status & STATUS_DRQ))
295 word = inw (info->dmaarea);
307 /* Prototype: int cumanascsi_2_dma_stop(host, SCpnt)
308 * Purpose : stops DMA/PIO
309 * Params : host - host
313 cumanascsi_2_dma_stop(struct Scsi_Host *host, Scsi_Pointer *SCp)
315 CumanaScsi2_Info *info = (CumanaScsi2_Info *)host->hostdata;
316 if (host->dma_channel != NO_DMA) {
317 outb(ALATCH_DIS_DMA, info->alatch);
318 disable_dma(host->dma_channel);
322 /* Prototype: int cumanascsi_2_detect(Scsi_Host_Template * tpnt)
323 * Purpose : initialises Cumana SCSI 2 driver
324 * Params : tpnt - template for this SCSI adapter
325 * Returns : >0 if host found, 0 otherwise.
328 cumanascsi_2_detect(Scsi_Host_Template *tpnt)
330 static const card_ids cumanascsi_2_cids[] =
331 { CUMANASCSI2_LIST, { 0xffff, 0xffff} };
333 struct Scsi_Host *host;
335 tpnt->proc_name = "cumanascs2";
336 memset(ecs, 0, sizeof (ecs));
341 CumanaScsi2_Info *info;
343 ecs[count] = ecard_find(0, cumanascsi_2_cids);
347 ecard_claim(ecs[count]);
349 host = scsi_register(tpnt, sizeof (CumanaScsi2_Info));
351 ecard_release(ecs[count]);
355 host->io_port = ecard_address(ecs[count], ECARD_MEMC, 0);
356 host->irq = ecs[count]->irq;
357 host->dma_channel = ecs[count]->dma;
358 info = (CumanaScsi2_Info *)host->hostdata;
360 info->terms = term[count] ? 1 : 0;
361 cumanascsi_2_terminator_ctl(host, info->terms);
363 info->info.scsi.io_port = host->io_port + CUMANASCSI2_FAS216_OFFSET;
364 info->info.scsi.io_shift = CUMANASCSI2_FAS216_SHIFT;
365 info->info.scsi.irq = host->irq;
366 info->info.ifcfg.clockrate = CUMANASCSI2_XTALFREQ;
367 info->info.ifcfg.select_timeout = 255;
368 info->info.ifcfg.asyncperiod = CUMANASCSI2_ASYNC_PERIOD;
369 info->info.ifcfg.sync_max_depth = CUMANASCSI2_SYNC_DEPTH;
370 info->info.ifcfg.cntl3 = CNTL3_BS8 | CNTL3_FASTSCSI | CNTL3_FASTCLK;
371 info->info.ifcfg.disconnect_ok = 1;
372 info->info.ifcfg.wide_max_size = 0;
373 info->info.dma.setup = cumanascsi_2_dma_setup;
374 info->info.dma.pseudo = cumanascsi_2_dma_pseudo;
375 info->info.dma.stop = cumanascsi_2_dma_stop;
376 info->dmaarea = host->io_port + CUMANASCSI2_PSEUDODMA;
377 info->status = host->io_port + CUMANASCSI2_STATUS;
378 info->alatch = host->io_port + CUMANASCSI2_ALATCH;
380 ecs[count]->irqaddr = (unsigned char *)ioaddr(info->status);
381 ecs[count]->irqmask = STATUS_INT;
382 ecs[count]->irq_data = (void *)info->alatch;
383 ecs[count]->ops = (expansioncard_ops_t *)&cumanascsi_2_ops;
385 request_region(host->io_port + CUMANASCSI2_FAS216_OFFSET,
386 16 << CUMANASCSI2_FAS216_SHIFT, "cumanascsi2-fas");
388 if (host->irq != NO_IRQ &&
389 request_irq(host->irq, cumanascsi_2_intr,
390 SA_INTERRUPT, "cumanascsi2", host)) {
391 printk("scsi%d: IRQ%d not free, interrupts disabled\n",
392 host->host_no, host->irq);
394 info->info.scsi.irq = NO_IRQ;
397 if (host->dma_channel != NO_DMA &&
398 request_dma(host->dma_channel, "cumanascsi2")) {
399 printk("scsi%d: DMA%d not free, DMA disabled\n",
400 host->host_no, host->dma_channel);
401 host->dma_channel = NO_DMA;
410 /* Prototype: int cumanascsi_2_release(struct Scsi_Host * host)
411 * Purpose : releases all resources used by this adapter
412 * Params : host - driver host structure to return info for.
414 int cumanascsi_2_release(struct Scsi_Host *host)
418 fas216_release(host);
420 if (host->irq != NO_IRQ)
421 free_irq(host->irq, host);
422 if (host->dma_channel != NO_DMA)
423 free_dma(host->dma_channel);
424 release_region(host->io_port + CUMANASCSI2_FAS216_OFFSET,
425 16 << CUMANASCSI2_FAS216_SHIFT);
427 for (i = 0; i < MAX_ECARDS; i++)
428 if (ecs[i] && host->io_port == ecard_address (ecs[i], ECARD_MEMC, 0))
429 ecard_release (ecs[i]);
433 /* Prototype: const char *cumanascsi_2_info(struct Scsi_Host * host)
434 * Purpose : returns a descriptive string about this interface,
435 * Params : host - driver host structure to return info for.
436 * Returns : pointer to a static buffer containing null terminated string.
438 const char *cumanascsi_2_info(struct Scsi_Host *host)
440 CumanaScsi2_Info *info = (CumanaScsi2_Info *)host->hostdata;
441 static char string[100], *p;
444 p += sprintf(p, "%s ", host->hostt->name);
445 p += fas216_info(&info->info, p);
446 p += sprintf(p, "v%d.%d.%d terminators o%s",
447 VER_MAJOR, VER_MINOR, VER_PATCH,
448 info->terms ? "n" : "ff");
453 /* Prototype: int cumanascsi_2_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
454 * Purpose : Set a driver specific function
455 * Params : host - host to setup
456 * : buffer - buffer containing string describing operation
457 * : length - length of string
458 * Returns : -EINVAL, or 0
461 cumanascsi_2_set_proc_info(struct Scsi_Host *host, char *buffer, int length)
465 if (length >= 11 && strcmp(buffer, "CUMANASCSI2") == 0) {
469 if (length >= 5 && strncmp(buffer, "term=", 5) == 0) {
470 if (buffer[5] == '1')
471 cumanascsi_2_terminator_ctl(host, 1);
472 else if (buffer[5] == '0')
473 cumanascsi_2_terminator_ctl(host, 0);
484 /* Prototype: int cumanascsi_2_proc_info(char *buffer, char **start, off_t offset,
485 * int length, int host_no, int inout)
486 * Purpose : Return information about the driver to a user process accessing
487 * the /proc filesystem.
488 * Params : buffer - a buffer to write information to
489 * start - a pointer into this buffer set by this routine to the start
490 * of the required information.
491 * offset - offset into information that we have read upto.
492 * length - length of buffer
493 * host_no - host number to return information for
494 * inout - 0 for reading, 1 for writing.
495 * Returns : length of data written to buffer.
497 int cumanascsi_2_proc_info (char *buffer, char **start, off_t offset,
498 int length, int host_no, int inout)
501 struct Scsi_Host *host = scsi_hostlist;
502 CumanaScsi2_Info *info;
506 if (host->host_no == host_no)
514 return cumanascsi_2_set_proc_info(host, buffer, length);
516 info = (CumanaScsi2_Info *)host->hostdata;
519 pos = sprintf(buffer,
520 "Cumana SCSI II driver version %d.%d.%d\n",
521 VER_MAJOR, VER_MINOR, VER_PATCH);
523 pos += fas216_print_host(&info->info, buffer + pos);
524 pos += sprintf(buffer + pos, "Term : o%s\n",
525 info->terms ? "n" : "ff");
527 pos += fas216_print_stats(&info->info, buffer + pos);
529 pos += sprintf(buffer+pos, "\nAttached devices:\n");
531 for (scd = host->host_queue; scd; scd = scd->next) {
534 proc_print_scsidevice(scd, buffer, &len, pos);
536 pos += sprintf(buffer+pos, "Extensions: ");
537 if (scd->tagged_supported)
538 pos += sprintf(buffer+pos, "TAG %sabled [%d] ",
539 scd->tagged_queue ? "en" : "dis",
541 pos += sprintf(buffer+pos, "\n");
543 if (pos + begin < offset) {
547 if (pos + begin > offset + length)
551 *start = buffer + (offset - begin);
552 pos -= offset - begin;
559 static Scsi_Host_Template cumanascsi2_template = {
561 proc_info: cumanascsi_2_proc_info,
562 name: "Cumana SCSI II",
563 detect: cumanascsi_2_detect,
564 release: cumanascsi_2_release,
565 info: cumanascsi_2_info,
566 bios_param: scsicam_bios_param,
569 sg_tablesize: SG_ALL,
571 use_clustering: DISABLE_CLUSTERING,
572 command: fas216_command,
573 queuecommand: fas216_queue_command,
574 eh_host_reset_handler: fas216_eh_host_reset,
575 eh_bus_reset_handler: fas216_eh_bus_reset,
576 eh_device_reset_handler: fas216_eh_device_reset,
577 eh_abort_handler: fas216_eh_abort,
581 static int __init cumanascsi2_init(void)
583 scsi_register_module(MODULE_SCSI_HA, &cumanascsi2_template);
584 if (cumanascsi2_template.present)
587 scsi_unregister_module(MODULE_SCSI_HA, &cumanascsi2_template);
591 static void __exit cumanascsi2_exit(void)
593 scsi_unregister_module(MODULE_SCSI_HA, &cumanascsi2_template);
596 module_init(cumanascsi2_init);
597 module_exit(cumanascsi2_exit);
599 MODULE_AUTHOR("Russell King");
600 MODULE_DESCRIPTION("Cumana SCSI-2 driver for Acorn machines");
601 MODULE_PARM(term, "1-8i");
602 MODULE_PARM_DESC(term, "SCSI bus termination");
603 MODULE_LICENSE("GPL");