/*----------------------------------------------------------------*/ /* Qlogic linux driver - work in progress. No Warranty express or implied. Use at your own risk. Support Tort Reform so you won't have to read all these silly disclaimers.
Copyright 1994, Tom Zerucha. tz@execpc.com
Additional Code, and much appreciated help by Michael A. Griffith grif@cs.ucr.edu
Thanks to Eric Youngdale and Dave Hinds for loadable module and PCMCIA help respectively, and for suffering through my foolishness during the debugging process.
Reference Qlogic FAS408 Technical Manual, 53408-510-00A, May 10, 1994 (you can reference it, but it is incomplete and inaccurate in places)
Version 0.46 1/30/97 - kernel 1.2.0+
Functions as standalone, loadable, and PCMCIA driver, the latter from Dave Hinds' PCMCIA package.
Cleaned up 26/10/2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> as part of the 2.5 SCSI driver cleanup and audit. This driver still needs work on the following - Non terminating hardware waits - Some layering violations with its pcmcia stub
Redistributable under terms of the GNU General Public License
For the avoidance of doubt the "preferred form" of this code is one which is in an open non patent encumbered format. Where cryptographic key signing forms part of the process of creating an executable the information including keys needed to generate an equivalently functional executable are deemed to be part of the source code.
*/
#include <linux/module.h> #include <linux/blkdev.h> /* to get disk capacity */ #include <linux/kernel.h> #include <linux/string.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/proc_fs.h> #include <linux/unistd.h> #include <linux/spinlock.h> #include <linux/stat.h>
/* * Process scsi command - usually after interrupt
*/
staticvoid ql_pcmd(struct scsi_cmnd *cmd)
{ unsignedint i, j; unsignedlong k; unsignedint status; /* scsi returned status */ unsignedint message; /* scsi returned message */ unsignedint phase; /* recorded scsi phase */ unsignedint reqlen; /* total length of transfer */ char *buf; struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd); int qbase = priv->qbase; int int_type = priv->int_type;
rtrc(1)
j = inb(qbase + 6);
i = inb(qbase + 5); if (i == 0x20) {
set_host_byte(cmd, DID_NO_CONNECT); return;
}
i |= inb(qbase + 5); /* the 0x10 bit can be set after the 0x08 */ if (i != 0x18) {
printk(KERN_ERR "Ql:Bad Interrupt status:%02x\n", i);
ql_zap(priv);
set_host_byte(cmd, DID_BAD_INTR); return;
}
j &= 7; /* j = inb( qbase + 7 ) >> 5; */
/* correct status is supposed to be step 4 */ /* it sometimes returns step 3 but with 0 bytes left to send */ /* We can try stuffing the FIFO with the max each time, but we will get a
sequence of 3 if any bytes are left (but we do flush the FIFO anyway */
if (j != 3 && j != 4) {
printk(KERN_ERR "Ql:Bad sequence for command %d, int %02X, cmdleft = %d\n",
j, i, inb(qbase + 7) & 0x1f);
ql_zap(priv);
set_host_byte(cmd, DID_ERROR); return;
}
if (inb(qbase + 7) & 0x1f) /* if some bytes in fifo */
outb(1, qbase + 3); /* clear fifo */ /* note that request_bufflen is the total xfer size when sg is used */
reqlen = scsi_bufflen(cmd); /* note that it won't work if transfers > 16M are requested */ if (reqlen && !((phase = inb(qbase + 4)) & 6)) { /* data phase */ struct scatterlist *sg;
rtrc(2)
outb(reqlen, qbase); /* low-mid xfer cnt */
outb(reqlen >> 8, qbase + 1); /* low-mid xfer cnt */
outb(reqlen >> 16, qbase + 0xe); /* high xfer cnt */
outb(0x90, qbase + 3); /* command do xfer */ /* PIO pseudo DMA to buffer or sglist */
REG1;
scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) { if (priv->qabort) {
REG0;
set_host_byte(cmd,
priv->qabort == 1 ?
DID_ABORT : DID_RESET);
}
buf = sg_virt(sg); if (ql_pdma(priv, phase, buf, sg->length)) break;
}
REG0;
rtrc(2); /* * Wait for irq (split into second state of irq handler * if this can take time)
*/ if ((k = ql_wai(priv))) {
set_host_byte(cmd, k); return;
}
k = inb(qbase + 5); /* should be 0x10, bus service */
}
/* * Enter Status (and Message In) Phase
*/
k = jiffies + WATCHDOG;
while (time_before(jiffies, k) && !priv->qabort &&
!(inb(qbase + 4) & 6))
cpu_relax(); /* wait for status phase */
if (time_after_eq(jiffies, k)) {
ql_zap(priv);
set_host_byte(cmd, DID_TIME_OUT); return;
}
outb(0x11, qbase + 3); /* get status and message */ if ((k = ql_wai(priv))) {
set_host_byte(cmd, k); return;
}
i = inb(qbase + 5); /* get chip irq stat */
j = inb(qbase + 7) & 0x1f; /* and bytes rec'd */
status = inb(qbase + 2);
message = inb(qbase + 2);
/* * Should get function complete int if Status and message, else * bus serv if only status
*/ if (!((i == 8 && j == 2) || (i == 0x10 && j == 1))) {
printk(KERN_ERR "Ql:Error during status phase, int=%02X, %d bytes recd\n", i, j);
set_host_byte(cmd, DID_ERROR);
}
outb(0x12, qbase + 3); /* done, disconnect */
rtrc(1); if ((k = ql_wai(priv))) {
set_host_byte(cmd, k); return;
}
/* * Should get bus service interrupt and disconnect interrupt
*/
i = inb(qbase + 5); /* should be bus service */ while (!priv->qabort && ((i & 0x20) != 0x20)) {
barrier();
cpu_relax();
i |= inb(qbase + 5);
}
rtrc(0);
if (priv->qlcmd == NULL) { /* no command to process? */ int i;
i = 16; while (i-- && inb(qbase + 5)); /* maybe also ql_zap() */ return;
}
icmd = priv->qlcmd;
ql_pcmd(icmd);
priv->qlcmd = NULL; /* * If result is CHECK CONDITION done calls qcommand to request * sense
*/
scsi_done(icmd);
}
MODULE_AUTHOR("Tom Zerucha, Michael Griffith");
MODULE_DESCRIPTION("Driver for the Qlogic FAS SCSI controllers");
MODULE_LICENSE("GPL");
module_init(qlogicfas408_init);
module_exit(qlogicfas408_exit);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.