⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aha1740.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  $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 *   *  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. */#ifdef MODULE#include <linux/module.h>#endif#include <linux/kernel.h>#include <linux/types.h>#include <linux/string.h>#include <linux/ioport.h>#include <linux/proc_fs.h>#include <linux/sched.h>#include <asm/dma.h>#include <asm/system.h>#include <asm/io.h>#include <linux/blk.h>#include "scsi.h"#include "hosts.h"#include "sd.h"#include "aha1740.h"#include<linux/stat.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)#endif/*static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/aha1740.c,v 1.1 1992/07/24 06:27:38 root Exp root $";*/struct aha1740_hostdata {    unsigned int slot;    unsigned int translation;    unsigned int last_ecb_used;    struct ecb ecb[AHA1740_ECBS];};#define HOSTDATA(host) ((struct aha1740_hostdata *) &host->hostdata)/* One for each IRQ level (9-15) */static struct Scsi_Host * aha_host[8] = {NULL, };int aha1740_proc_info(char *buffer, char **start, off_t offset,		      int length, int hostno, int inout){    int len;    struct Scsi_Host * shpnt;    struct aha1740_hostdata *host;    if (inout)	return(-ENOSYS);    for (len = 0; len < 8; len++) {	shpnt = aha_host[len];	if (shpnt && shpnt->host_no == hostno)	    break;    }    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->slot,		  host->translation ? "en" : "dis");    if (offset > len) {	*start = buffer;	return 0;    }    *start = buffer + offset;    len -= offset;    if (len > length)	len = length;    return len;}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 )	    {		retval = DID_ERROR; /* Didn't find a better 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;}int aha1740_test_port(unsigned int base){    char name[4], tmp;    /* Okay, look for the EISA ID's */    name[0]= 'A' -1 + ((tmp = inb(HID0(base))) >> 2); /* First character */    name[1]= 'A' -1 + ((tmp & 3) << 3);    name[1]+= ((tmp = inb(HID1(base))) >> 5)&0x7;	/* Second Character */    name[2]= 'A' -1 + (tmp & 0x1f);		/* Third Character */    name[3]=0;    tmp = inb(HID2(base));    if ( strcmp ( name, HID_MFG ) || inb(HID2(base)) != HID_PRD )	return 0;   /* Not an Adaptec 174x *//*  if ( inb(HID3(base)) != HID_REV )	printk("aha174x: Warning; board revision of %d; expected %d\n",	    inb(HID3(base)),HID_REV); */    if ( inb(EBCNTRL(base)) != EBCNTRL_VALUE )    {	printk("aha174x: Board detected, but EBCNTRL = %x, so disabled it.\n",	    inb(EBCNTRL(base)));	return 0;    }    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 */void aha1740_intr_handle(int irq, void *dev_id, struct pt_regs * regs){    void (*my_done)(Scsi_Cmnd *);    int errstatus, adapstat;    int number_serviced;    struct ecb *ecbptr;    Scsi_Cmnd *SCtmp;    unsigned int base;    unsigned long flags;    spin_lock_irqsave(&io_request_lock, flags);    if (!aha_host[irq - 9])	panic("aha1740.c: Irq from unknown host!\n");    base = aha_host[irq - 9]->io_port;    number_serviced = 0;    while(inb(G2STAT(base)) & G2STAT_INTPEND)    {	DEB(printk("aha1740_intr top of loop.\n"));	adapstat = inb(G2INTST(base));	ecbptr = (struct ecb *) bus_to_virt(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;	    }	    if (SCtmp->host_scribble)		scsi_free(SCtmp->host_scribble, 512);	    /* 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(&io_request_lock, flags);}int aha1740_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *)){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -