aha1740.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 708 行 · 第 1/2 页
C
708 行
/* $Id$ * 1993/03/31 * linux/kernel/aha1740.c * * Based loosely on aha1542.c which is * Copyright (C) 1992 Tommy Thorn and * Modified by Eric Youngdale * * This file is aha1740.c, written and * Copyright (C) 1992,1993 Brad McLean * brad@saturn.gaylord.com or brad@bradpc.gaylord.com. * * Modifications to makecode and queuecommand * for proper handling of multiple devices courteously * provided by Michael Weller, March, 1993 * * Multiple adapter support, extended translation detection, * update to current scsi subsystem changes, proc fs support, * working (!) module support based on patches from Andreas Arens, * by Andreas Degert <ad@papyrus.hamburg.com>, 2/1997 * * aha1740_makecode may still need even more work * if it doesn't work for your devices, take a look. * * Reworked for new_eh and new locking by Alan Cox <alan@redhat.com> * * Converted to EISA and generic DMA APIs by Marc Zyngier * <maz@wild-wind.fr.eu.org>, 4/2003. * * Shared interrupt support added by Rask Ingemann Lambertsen * <rask@sygehus.dk>, 10/2003 * * 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/blkdev.h>#include <linux/interrupt.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/proc_fs.h>#include <linux/stat.h>#include <linux/init.h>#include <linux/device.h>#include <linux/eisa.h>#include <linux/dma-mapping.h>#include <asm/dma.h>#include <asm/system.h>#include <asm/io.h>#include "scsi.h"#include <scsi/scsi_host.h>#include "aha1740.h"/* IF YOU ARE HAVING PROBLEMS WITH THIS DRIVER, AND WANT TO WATCH IT WORK, THEN:#define DEBUG*/#ifdef DEBUG#define DEB(x) x#else#define DEB(x)#endifstruct aha1740_hostdata { struct eisa_device *edev; unsigned int translation; unsigned int last_ecb_used; dma_addr_t ecb_dma_addr; struct ecb ecb[AHA1740_ECBS];};struct aha1740_sg { struct aha1740_chain sg_chain[AHA1740_SCATTER]; dma_addr_t sg_dma_addr; dma_addr_t buf_dma_addr;};#define HOSTDATA(host) ((struct aha1740_hostdata *) &host->hostdata)static inline struct ecb *ecb_dma_to_cpu (struct Scsi_Host *host, dma_addr_t dma){ struct aha1740_hostdata *hdata = HOSTDATA (host); dma_addr_t offset; offset = dma - hdata->ecb_dma_addr; return (struct ecb *)(((char *) hdata->ecb) + (unsigned int) offset);}static inline dma_addr_t ecb_cpu_to_dma (struct Scsi_Host *host, void *cpu){ struct aha1740_hostdata *hdata = HOSTDATA (host); dma_addr_t offset; offset = (char *) cpu - (char *) hdata->ecb; return hdata->ecb_dma_addr + offset;}static int aha1740_proc_info(struct Scsi_Host *shpnt, char *buffer, char **start, off_t offset, int length, int inout){ int len; struct aha1740_hostdata *host; if (inout) return-ENOSYS; host = HOSTDATA(shpnt); len = sprintf(buffer, "aha174x at IO:%lx, IRQ %d, SLOT %d.\n" "Extended translation %sabled.\n", shpnt->io_port, shpnt->irq, host->edev->slot, host->translation ? "en" : "dis"); if (offset > len) { *start = buffer; return 0; } *start = buffer + offset; len -= offset; if (len > length) len = length; return len;}static int aha1740_makecode(unchar *sense, unchar *status){ struct statusword { ushort don:1, /* Command Done - No Error */ du:1, /* Data underrun */ :1, qf:1, /* Queue full */ sc:1, /* Specification Check */ dor:1, /* Data overrun */ ch:1, /* Chaining Halted */ intr:1, /* Interrupt issued */ asa:1, /* Additional Status Available */ sns:1, /* Sense information Stored */ :1, ini:1, /* Initialization Required */ me:1, /* Major error or exception */ :1, eca:1, /* Extended Contingent alliance */ :1; } status_word; int retval = DID_OK; status_word = * (struct statusword *) status;#ifdef DEBUG printk("makecode from %x,%x,%x,%x %x,%x,%x,%x", status[0], status[1], status[2], status[3], sense[0], sense[1], sense[2], sense[3]);#endif if (!status_word.don) { /* Anything abnormal was detected */ if ( (status[1]&0x18) || status_word.sc ) { /*Additional info available*/ /* Use the supplied info for further diagnostics */ switch ( status[2] ) { case 0x12: if ( status_word.dor ) retval=DID_ERROR; /* It's an Overrun */ /* If not overrun, assume underrun and * ignore it! */ case 0x00: /* No info, assume no error, should * not occur */ break; case 0x11: case 0x21: retval=DID_TIME_OUT; break; case 0x0a: retval=DID_BAD_TARGET; break; case 0x04: case 0x05: retval=DID_ABORT; /* Either by this driver or the * AHA1740 itself */ break; default: retval=DID_ERROR; /* No further * diagnostics * possible */ } } else { /* Michael suggests, and Brad concurs: */ if ( status_word.qf ) { retval = DID_TIME_OUT; /* forces a redo */ /* I think this specific one should * not happen -Brad */ printk("aha1740.c: WARNING: AHA1740 queue overflow!\n"); } else if ( status[0]&0x60 ) { /* Didn't find a better error */ retval = DID_ERROR; } /* In any other case return DID_OK so for example CONDITION_CHECKS make it through to the appropriate device driver */ } } /* Under all circumstances supply the target status -Michael */ return status[3] | retval << 16;}static int aha1740_test_port(unsigned int base){ if ( inb(PORTADR(base)) & PORTADDR_ENH ) return 1; /* Okay, we're all set */ printk("aha174x: Board detected, but not in enhanced mode, so disabled it.\n"); return 0;}/* A "high" level interrupt handler */static irqreturn_t aha1740_intr_handle(int irq, void *dev_id, struct pt_regs *regs){ struct Scsi_Host *host = (struct Scsi_Host *) dev_id; void (*my_done)(Scsi_Cmnd *); int errstatus, adapstat; int number_serviced; struct ecb *ecbptr; Scsi_Cmnd *SCtmp; unsigned int base; unsigned long flags; int handled = 0; struct aha1740_sg *sgptr; struct eisa_device *edev; if (!host) panic("aha1740.c: Irq from unknown host!\n"); spin_lock_irqsave(host->host_lock, flags); base = host->io_port; number_serviced = 0; edev = HOSTDATA(host)->edev; while(inb(G2STAT(base)) & G2STAT_INTPEND) { handled = 1; DEB(printk("aha1740_intr top of loop.\n")); adapstat = inb(G2INTST(base)); ecbptr = ecb_dma_to_cpu (host, inl(MBOXIN0(base))); outb(G2CNTRL_IRST,G2CNTRL(base)); /* interrupt reset */ switch ( adapstat & G2INTST_MASK ) { case G2INTST_CCBRETRY: case G2INTST_CCBERROR: case G2INTST_CCBGOOD: /* Host Ready -> Mailbox in complete */ outb(G2CNTRL_HRDY,G2CNTRL(base)); if (!ecbptr) { printk("Aha1740 null ecbptr in interrupt (%x,%x,%x,%d)\n", inb(G2STAT(base)),adapstat, inb(G2INTST(base)), number_serviced++); continue; } SCtmp = ecbptr->SCpnt; if (!SCtmp) { printk("Aha1740 null SCtmp in interrupt (%x,%x,%x,%d)\n", inb(G2STAT(base)),adapstat, inb(G2INTST(base)), number_serviced++); continue; } sgptr = (struct aha1740_sg *) SCtmp->host_scribble; if (SCtmp->use_sg) { /* We used scatter-gather. Do the unmapping dance. */ dma_unmap_sg (&edev->dev, (struct scatterlist *) SCtmp->request_buffer, SCtmp->use_sg, SCtmp->sc_data_direction); } else { dma_unmap_single (&edev->dev, sgptr->buf_dma_addr, SCtmp->request_bufflen, DMA_BIDIRECTIONAL); } /* Free the sg block */ dma_free_coherent (&edev->dev, sizeof (struct aha1740_sg), SCtmp->host_scribble, sgptr->sg_dma_addr); /* Fetch the sense data, and tuck it away, in the required slot. The Adaptec automatically fetches it, and there is no guarantee that we will still have it in the cdb when we come back */ if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) { memcpy(SCtmp->sense_buffer, ecbptr->sense, sizeof(SCtmp->sense_buffer)); errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status); } else errstatus = 0; DEB(if (errstatus) printk("aha1740_intr_handle: returning %6x\n", errstatus)); SCtmp->result = errstatus; my_done = ecbptr->done; memset(ecbptr,0,sizeof(struct ecb)); if ( my_done ) my_done(SCtmp); break; case G2INTST_HARDFAIL: printk(KERN_ALERT "aha1740 hardware failure!\n"); panic("aha1740.c"); /* Goodbye */ case G2INTST_ASNEVENT: printk("aha1740 asynchronous event: %02x %02x %02x %02x %02x\n", adapstat, inb(MBOXIN0(base)), inb(MBOXIN1(base)), inb(MBOXIN2(base)), inb(MBOXIN3(base))); /* Say What? */ /* Host Ready -> Mailbox in complete */ outb(G2CNTRL_HRDY,G2CNTRL(base)); break; case G2INTST_CMDGOOD: /* set immediate command success flag here: */ break; case G2INTST_CMDERROR: /* Set immediate command failure flag here: */ break; } number_serviced++; } spin_unlock_irqrestore(host->host_lock, flags); return IRQ_RETVAL(handled);}static int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *)){ unchar direction; unchar *cmd = (unchar *) SCpnt->cmnd; unchar target = SCpnt->device->id; struct aha1740_hostdata *host = HOSTDATA(SCpnt->device->host); unsigned long flags; void *buff = SCpnt->request_buffer; int bufflen = SCpnt->request_bufflen;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?