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

📄 ncr53c8xx.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/********************************************************************************  Device driver for the PCI-SCSI NCR538XX controller family.****  Copyright (C) 1994  Wolfgang Stanglmeier****  This program is free software; you can redistribute it and/or modify**  it under the terms of the GNU General Public License as published by**  the Free Software Foundation; either version 2 of the License, or**  (at your option) any later version.****  This program is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the**  GNU General Public License for more details.****  You should have received a copy of the GNU General Public License**  along with this program; if not, write to the Free Software**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.****-----------------------------------------------------------------------------****  This driver has been ported to Linux from the FreeBSD NCR53C8XX driver**  and is currently maintained by****          Gerard Roudier              <groudier@club-internet.fr>****  Being given that this driver originates from the FreeBSD version, and**  in order to keep synergy on both, any suggested enhancements and corrections**  received on Linux are automatically a potential candidate for the FreeBSD **  version.****  The original driver has been written for 386bsd and FreeBSD by**          Wolfgang Stanglmeier        <wolf@cologne.de>**          Stefan Esser                <se@mi.Uni-Koeln.de>****  And has been ported to NetBSD by**          Charles M. Hannum           <mycroft@gnu.ai.mit.edu>****-----------------------------------------------------------------------------****                     Brief history****  December 10 1995 by Gerard Roudier:**     Initial port to Linux.****  June 23 1996 by Gerard Roudier:**     Support for 64 bits architectures (Alpha).****  November 30 1996 by Gerard Roudier:**     Support for Fast-20 scsi.**     Support for large DMA fifo and 128 dwords bursting.****  February 27 1997 by Gerard Roudier:**     Support for Fast-40 scsi.**     Support for on-Board RAM.****  May 3 1997 by Gerard Roudier:**     Full support for scsi scripts instructions pre-fetching.****  May 19 1997 by Richard Waltham <dormouse@farsrobt.demon.co.uk>:**     Support for NvRAM detection and reading.****  August 18 1997 by Cort <cort@cs.nmt.edu>:**     Support for Power/PC (Big Endian).****  June 20 1998 by Gerard Roudier <groudier@club-internet.fr>:**     Support for up to 64 tags per lun.**     O(1) everywhere (C and SCRIPTS) for normal cases.**     Low PCI traffic for command handling when on-chip RAM is present.**     Aggressive SCSI SCRIPTS optimizations.**********************************************************************************//***	May 11 2000, version 3.3b****	Supported SCSI-II features:**	    Synchronous negotiation**	    Wide negotiation        (depends on the NCR Chip)**	    Enable disconnection**	    Tagged command queuing**	    Parity checking**	    Etc...****	Supported NCR/SYMBIOS chips:**		53C810		(8 bits, Fast SCSI-2, no rom BIOS) **		53C815		(8 bits, Fast SCSI-2, on board rom BIOS)**		53C820		(Wide,   Fast SCSI-2, no rom BIOS)**		53C825		(Wide,   Fast SCSI-2, on board rom BIOS)**		53C860		(8 bits, Fast 20,     no rom BIOS)**		53C875		(Wide,   Fast 20,     on board rom BIOS)**		53C895		(Wide,   Fast 40,     on board rom BIOS)**		53C895A		(Wide,   Fast 40,     on board rom BIOS)**		53C896		(Wide,   Fast 40,     on board rom BIOS)**		53C897		(Wide,   Fast 40,     on board rom BIOS)**		53C1510D	(Wide,   Fast 40,     on board rom BIOS)****	Other features:**		Memory mapped IO (linux-1.3.X and above only)**		Module**		Shared IRQ (since linux-1.3.72)*//***	Name and version of the driver*/#define SCSI_NCR_DRIVER_NAME	"ncr53c8xx - version 3.3b"#define SCSI_NCR_DEBUG_FLAGS	(0)/*==========================================================****      Include files****==========================================================*/#define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))#ifdef MODULE#include <linux/module.h>#endif#include <asm/dma.h>#include <asm/io.h>#include <asm/system.h>#if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,17)#include <linux/spinlock.h>#elif LINUX_VERSION_CODE >= LinuxVersionCode(2,1,93)#include <asm/spinlock.h>#endif#include <linux/delay.h>#include <linux/signal.h>#include <linux/sched.h>#include <linux/errno.h>#include <linux/pci.h>#include <linux/string.h>#include <linux/malloc.h>#include <linux/mm.h>#include <linux/ioport.h>#include <linux/time.h>#include <linux/timer.h>#include <linux/stat.h>#include <linux/version.h>#include <linux/blk.h>#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,35)#include <linux/init.h>#endif#ifndef	__init#define	__init#endif#ifndef	__initdata#define	__initdata#endif#if LINUX_VERSION_CODE <= LinuxVersionCode(2,1,92)#include <linux/bios32.h>#endif#include "scsi.h"#include "hosts.h"#include "constants.h"#include "sd.h"#include <linux/types.h>/***	Define BITS_PER_LONG for earlier linux versions.*/#ifndef	BITS_PER_LONG#if (~0UL) == 0xffffffffUL#define	BITS_PER_LONG	32#else#define	BITS_PER_LONG	64#endif#endif/***	Define the BSD style u_int32 and u_int64 type.**	Are in fact u_int32_t and u_int64_t :-)*/typedef u32 u_int32;typedef u64 u_int64;typedef	u_long		vm_offset_t;#include "ncr53c8xx.h"/***	Donnot compile integrity checking code for Linux-2.3.0 **	and above since SCSI data structures are not ready yet.*/#if LINUX_VERSION_CODE < LinuxVersionCode(2,3,0)#define	SCSI_NCR_INTEGRITY_CHECKING#endif#define NAME53C			"ncr53c"#define NAME53C8XX		"ncr53c8xx"#define DRIVER_SMP_LOCK		ncr53c8xx_lock#include "sym53c8xx_comm.h"/*==========================================================****	The CCB done queue uses an array of CCB virtual **	addresses. Empty entries are flagged using the bogus **	virtual address 0xffffffff.****	Since PCI ensures that only aligned DWORDs are accessed **	atomically, 64 bit little-endian architecture requires **	to test the high order DWORD of the entry to determine **	if it is empty or valid.****	BTW, I will make things differently as soon as I will **	have a better idea, but this is simple and should work.****==========================================================*/ #define SCSI_NCR_CCB_DONE_SUPPORT#ifdef  SCSI_NCR_CCB_DONE_SUPPORT#define MAX_DONE 24#define CCB_DONE_EMPTY 0xffffffffUL/* All 32 bit architectures */#if BITS_PER_LONG == 32#define CCB_DONE_VALID(cp)  (((u_long) cp) != CCB_DONE_EMPTY)/* All > 32 bit (64 bit) architectures regardless endian-ness */#else#define CCB_DONE_VALID(cp)  \	((((u_long) cp) & 0xffffffff00000000ul) && 	\	 (((u_long) cp) & 0xfffffffful) != CCB_DONE_EMPTY)#endif#endif /* SCSI_NCR_CCB_DONE_SUPPORT *//*==========================================================****	Configuration and Debugging****==========================================================*//***    SCSI address of this device.**    The boot routines should have set it.**    If not, use this.*/#ifndef SCSI_NCR_MYADDR#define SCSI_NCR_MYADDR      (7)#endif/***    The maximum number of tags per logic unit.**    Used only for disk devices that support tags.*/#ifndef SCSI_NCR_MAX_TAGS#define SCSI_NCR_MAX_TAGS    (8)#endif/***    TAGS are actually limited to 64 tags/lun.**    We need to deal with power of 2, for alignment constraints.*/#if	SCSI_NCR_MAX_TAGS > 64#define	MAX_TAGS (64)#else#define	MAX_TAGS SCSI_NCR_MAX_TAGS#endif#define NO_TAG	(255)/***	Choose appropriate type for tag bitmap.*/#if	MAX_TAGS > 32typedef u_int64 tagmap_t;#elsetypedef u_int32 tagmap_t;#endif/***    Number of targets supported by the driver.**    n permits target numbers 0..n-1.**    Default is 16, meaning targets #0..#15.**    #7 .. is myself.*/#ifdef SCSI_NCR_MAX_TARGET#define MAX_TARGET  (SCSI_NCR_MAX_TARGET)#else#define MAX_TARGET  (16)#endif/***    Number of logic units supported by the driver.**    n enables logic unit numbers 0..n-1.**    The common SCSI devices require only**    one lun, so take 1 as the default.*/#ifdef SCSI_NCR_MAX_LUN#define MAX_LUN    SCSI_NCR_MAX_LUN#else#define MAX_LUN    (1)#endif/***    Asynchronous pre-scaler (ns). Shall be 40*/ #ifndef SCSI_NCR_MIN_ASYNC#define SCSI_NCR_MIN_ASYNC (40)#endif/***    The maximum number of jobs scheduled for starting.**    There should be one slot per target, and one slot**    for each tag of each target in use.**    The calculation below is actually quite silly ...*/#ifdef SCSI_NCR_CAN_QUEUE#define MAX_START   (SCSI_NCR_CAN_QUEUE + 4)#else#define MAX_START   (MAX_TARGET + 7 * MAX_TAGS)#endif/***   We limit the max number of pending IO to 250.**   since we donnot want to allocate more than 1 **   PAGE for 'scripth'.*/#if	MAX_START > 250#undef	MAX_START#define	MAX_START 250#endif/***    The maximum number of segments a transfer is split into.**    We support up to 127 segments for both read and write.**    The data scripts are broken into 2 sub-scripts.**    80 (MAX_SCATTERL) segments are moved from a sub-script **    in on-chip RAM. This makes data transfers shorter than **    80k (assuming 1k fs) as fast as possible.*/#define MAX_SCATTER (SCSI_NCR_MAX_SCATTER)#if (MAX_SCATTER > 80)#define MAX_SCATTERL	80#define	MAX_SCATTERH	(MAX_SCATTER - MAX_SCATTERL)#else#define MAX_SCATTERL	(MAX_SCATTER-1)#define	MAX_SCATTERH	1#endif/***	other*/#define NCR_SNOOP_TIMEOUT (1000000)/***	Head of list of NCR boards****	For kernel version < 1.3.70, host is retrieved by its irq level.**	For later kernels, the internal host control block address **	(struct ncb) is used as device id parameter of the irq stuff.*/static struct Scsi_Host		*first_host	= NULL;static Scsi_Host_Template	*the_template	= NULL;	/***	Other definitions*/#define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))static void ncr53c8xx_select_queue_depths(	struct Scsi_Host *host, struct scsi_device *devlist);static void ncr53c8xx_intr(int irq, void *dev_id, struct pt_regs * regs);static void ncr53c8xx_timeout(unsigned long np);#define initverbose (driver_setup.verbose)#define bootverbose (np->verbose)#ifdef SCSI_NCR_NVRAM_SUPPORTstatic u_char Tekram_sync[16] __initdata =	{25,31,37,43, 50,62,75,125, 12,15,18,21, 6,7,9,10};#endif /* SCSI_NCR_NVRAM_SUPPORT *//*==========================================================****	Command control block states.****==========================================================*/#define HS_IDLE		(0)#define HS_BUSY		(1)#define HS_NEGOTIATE	(2)	/* sync/wide data transfer*/#define HS_DISCONNECT	(3)	/* Disconnected by target */#define HS_DONEMASK	(0x80)#define HS_COMPLETE	(4|HS_DONEMASK)#define HS_SEL_TIMEOUT	(5|HS_DONEMASK)	/* Selection timeout      */#define HS_RESET	(6|HS_DONEMASK)	/* SCSI reset	          */#define HS_ABORTED	(7|HS_DONEMASK)	/* Transfer aborted       */#define HS_TIMEOUT	(8|HS_DONEMASK)	/* Software timeout       */#define HS_FAIL		(9|HS_DONEMASK)	/* SCSI or PCI bus errors */#define HS_UNEXPECTED	(10|HS_DONEMASK)/* Unexpected disconnect  *//***	Invalid host status values used by the SCRIPTS processor **	when the nexus is not fully identified.**	Shall never appear in a CCB.*/#define HS_INVALMASK	(0x40)#define	HS_SELECTING	(0|HS_INVALMASK)#define	HS_IN_RESELECT	(1|HS_INVALMASK)#define	HS_STARTING	(2|HS_INVALMASK)/***	Flags set by the SCRIPT processor for commands **	that have been skipped.*/#define HS_SKIPMASK	(0x20)/*==========================================================****	Software Interrupt Codes****==========================================================*/#define	SIR_BAD_STATUS		(1)#define	SIR_XXXXXXXXXX		(2)#define	SIR_NEGO_SYNC		(3)#define	SIR_NEGO_WIDE		(4)#define	SIR_NEGO_FAILED		(5)#define	SIR_NEGO_PROTO		(6)#define	SIR_REJECT_RECEIVED	(7)#define	SIR_REJECT_SENT		(8)#define	SIR_IGN_RESIDUE		(9)#define	SIR_MISSING_SAVE	(10)#define	SIR_RESEL_NO_MSG_IN	(11)#define	SIR_RESEL_NO_IDENTIFY	(12)#define	SIR_RESEL_BAD_LUN	(13)#define	SIR_RESEL_BAD_TARGET	(14)#define	SIR_RESEL_BAD_I_T_L	(15)#define	SIR_RESEL_BAD_I_T_L_Q	(16)#define	SIR_DONE_OVERFLOW	(17)#define	SIR_MAX			(17)/*==========================================================****	Extended error codes.**	xerr_status field of struct ccb.****==========================================================*/

⌨️ 快捷键说明

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