ncr53c8xx.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 2,351 行 · 第 1/5 页

C
2,351
字号
/********************************************************************************  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@free.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**     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.**********************************************************************************//***	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:**		53C720		(Wide,   Fast SCSI-2, intfly problems)****	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-3.4.3f"#define SCSI_NCR_DEBUG_FLAGS	(0)/*==========================================================****      Include files****==========================================================*/#include <linux/blkdev.h>#include <linux/delay.h>#include <linux/dma-mapping.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/interrupt.h>#include <linux/ioport.h>#include <linux/mm.h>#include <linux/module.h>#include <linux/sched.h>#include <linux/signal.h>#include <linux/spinlock.h>#include <linux/stat.h>#include <linux/string.h>#include <linux/time.h>#include <linux/timer.h>#include <linux/types.h>#include <asm/dma.h>#include <asm/io.h>#include <asm/system.h>#include "scsi.h"#include <scsi/scsi_host.h>#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 < KERNEL_VERSION(2,3,0) */#if 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 u64 tagmap_t;#elsetypedef u32 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)/***	Other definitions*/#define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))static void ncr53c8xx_timeout(unsigned long np);static int ncr53c8xx_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,			int length, int func);#define initverbose (driver_setup.verbose)#define bootverbose (np->verbose)/*==========================================================****	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_INTFLY		(18)#define	SIR_MAX			(18)/*==========================================================****	Extended error codes.**	xerr_status field of struct ccb.****==========================================================*/#define	XE_OK		(0)#define	XE_EXTRA_DATA	(1)	/* unexpected data phase */#define	XE_BAD_PHASE	(2)	/* illegal phase (4/5)   *//*==========================================================****	Negotiation status.**	nego_status field	of struct ccb.****==========================================================*/#define NS_NOCHANGE	(0)#define NS_SYNC		(1)#define NS_WIDE		(2)#define NS_PPR		(4)/*==========================================================****	"Special features" of targets.**	quirks field		of struct tcb.**	actualquirks field	of struct ccb.****==========================================================*/#define	QUIRK_AUTOSAVE	(0x01)#define	QUIRK_NOMSG	(0x02)#define QUIRK_NOSYNC	(0x10)#define QUIRK_NOWIDE16	(0x20)/*==========================================================****	Capability bits in Inquire response byte 7.****==========================================================*/#define	INQ7_QUEUE	(0x02)#define	INQ7_SYNC	(0x10)#define	INQ7_WIDE16	(0x20)/*==========================================================****	Misc.****==========================================================*/#define CCB_MAGIC	(0xf2691ad2)/*==========================================================****	Declaration of structs.****==========================================================*/struct tcb;struct lcb;struct ccb;struct ncb;struct script;struct link {	ncrcmd	l_cmd;	ncrcmd	l_paddr;};struct	usrcmd {	u_long	target;	u_long	lun;	u_long	data;

⌨️ 快捷键说明

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