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

📄 scsi_5380.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 5 页
字号:
#ifndef lintstatic	char	*sccsid = "@(#)scsi_5380.c	4.4  (ULTRIX)        1/3/91";#endif lint/************************************************************************ *									* *			Copyright (c) 1984,86,87,88,89 by		* *		Digital Equipment Corporation, Maynard, MA		* *			All rights reserved.				* *									* *   This software is furnished under a license and may be used and	* *   copied  only  in accordance with the terms of such license and	* *   with the  inclusion  of  the  above  copyright  notice.   This	* *   software  or  any	other copies thereof may not be provided or	* *   otherwise made available to any other person.  No title to and	* *   ownership of the software is hereby transferred.			* *									* *   This software is  derived	from  software	received  from	the	* *   University    of	California,   Berkeley,   and	from   Bell	* *   Laboratories.  Use, duplication, or disclosure is	subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   The information in this software is subject to change  without	* *   notice  and should not be construed as a commitment by Digital	* *   Equipment Corporation.						* *									* *   Digital assumes no responsibility for the use  or	reliability	* *   of its software on equipment which is not supplied by Digital.	* *									* ************************************************************************//************************************************************************ * * scsi_5380.c	17-Aug-88 * * VAX SCSI device driver (NCR 5380 routines) * * Modification history: * *   11/21/90	Robin Miller *	o  Added support for 10-byte Read/Write CDB's. *	o  Removed '#ifdef FORMAT' conditionalization, since this special *	   interface is always desired. *	o  Use function sz_cdb_length() to obtain the Command *	   Descriptor Block (CDB) length. * *   08/30/90	Robin Miller *	Added check in probe routine to recognize RX26 device type *	and setup accordingly for floppy device. * *   05-Jul-90	Bill Dallas *	Added support for the TZK10 and the new device option table * *   01-Mar-90  Janet Schank / Fred Canter *      Added retries on busy in the probe routine. * *   02-Dec-89	Fred Canter *	Calculate the number of PTEs needed to double map the user's *	buffer in a machine independant way (no more magic numbers). * *   13-Nov-89  Janet Schank *      scsi_data.c has moved from data/vax/scsi_data.c to data/scsi_data.c * *   08-Oct-89	Fred Canter *	Remove error log #ifdef OLDWAY. * *   07-Oct-89	Fred Canter *	Save removable media bit from inquiry data in sz_softc. * *   01-Oct-89	Fred Canter *	Added error log debug code (#ifdef ELDEBUG). This allows the *	driver to produce most error types for uerf debuging. * *   23-Jul-89	Fred Canter *	RX33 support. * *   14-Jul-89	Fred Canter *	Merged Dynamic BBR and error log changes. * *   24-Jun-89	Fred Canter *	Convert printf/mprintf error messages to scsi_logerr() calls. * *   23-Jun-89	Fred Canter *	Save status byte for current command for error log. * *   22-Jun-89	John A. Gallant *	Added the driver completion routine pieces. * *   18-Jun-89	Fred Canter *	Convert to scsi_devtab. * *   10-Jun-89	Fred Canter *	Added #ifdef SZ_BT_DEBUG around disconnect BSY timing debug code. * *   03-Jun-89	Fred Canter *	Move soft copy of scs_selena register to sz_softc. * *   02-Jun-89	Fred Canter *	Fixed a latent bug in the probe routine which cuased a panic *	during booting if the second SCSI controller was not present. * *   29-May-89	Fred Canter *	Changed disconnect timeout (timer2) from 4 seconds to 10 seconds *	for hard disks and 30 seconds for floppy disks. * *   24-May-89	Fred Canter *	Changes to match the new, more general rzdisk utility. *	Changed the mode select data structures so an address and *	length are passed with the ioctl. This allows pages to be *	added to rzdisk without requiring a kernel rebuild. * *   24-Apr-89	Fred Canter *	Added support for the RX23s SCSI floppy. * *   23-Apr-89	Fred Canter *	If already in the interrupt routine, then don't take another *	interrupt when a target disconnects, unless its slow dropping BSY. * *   06-Apr-89	Fred Canter *	Added TZxx (EXABYTE) support: *		Add TZxx code to szprobe(). *		Don't send VU bits with mode select (modsel.pll = 12). *		Handle target returning busy status (EXABYTE does this). * *	Check for hung bus after SSUNIT in szprobe. Reset bus if hung. *	Done so inquiry for next device will not fail. * *	Only timeout disconnect on disk read, write, and read capacity *	commands. Disk start unit takes much longer than 4 seconds. * *	Added the capability to do extended mode select for TZxx tapes. * *   11-Feb-89	Fred Canter *	Fixed yet another bug with 64KB transfers. Use blkcpy instead *	of bcopy (bcopy max byte count is 64KB -1 ) for copying *	data to and from the users' buffer. * *   09-Feb-89	Fred Canter *	Fixed a bug which cause an inquiry command to hang in data in *	phase when executed from rzdisk (DMA data in). The byte count *	was never setup. Only worked by luck previously. *	Fixed minor typo (SCS_PARCK | SCS_PARCK) in two places. * *   08-Feb-89	Fred Canter *	Changed sc_sel_retry (select timeout retry count) to per target. * *   07-Feb-89	Fred Canter *	Add function header comments for each routine. * *   06-Feb-89	Fred Canter *	Remove rz_max_xfer, cz_max_xfer, and tz_max_xfer. *	Cleanup comments and minor code rearranement. * *   04-Feb-89	Fred Canter *	Modified 128KB hardware DMA buffer allocation scheme: *	    Allocate in 512 byte chunks instead of 1024 byte chunks. *	    Don't use last page (5380 1 byte prefetch on DMA write). *	    Allocate fragment to a disk (use all of the buffer). * *	Fixed a panic caused by transferring odd byte counts, like *	8193 to a tape. The 5380 prefetching an extra byte on the *	DMA write caused the saved count to be 0 when it should have *	been -1 (really one byte left to transfer). * *   30-Dec-88	Fred Canter *	Added szreset() to reset SCSI controllers before calling the *	VMB boot drive to write out a crash dump. * *   21-Dec-88	Fred Canter *	Fixed bug in the save data pointer code which reset the sc_savcnt *	if the previous phase was not data out. This made the defect *	list appear trashed. * *   18-Dec-88	Fred Canter *	Added implied save data pointer to disconnect (only if target *	disconnects without sending a save data pointer nmessage first). * *   17-Dec-88	Fred Canter *	Added pseudo commands to resolve the conflict between *	SZ_UNLOAD and SZ_SSUNIT both being opcode 0x1b. * *   16-Dec-88	Fred Canter *	Restructure the lost arbitration code to simplify bus reset *	detection and improve readability. *	Removed sz_ss_oldsel debug code (spin instead of time select). *	Close (almost completely) the window for missing detection *	of a bus reset in the sz_scsistart() arbitration code. * *   11-Dec-88	Fred Canter *	Modified parity checking and bus reset detection so that we *	don't read any of the SCSI controller registers while a DMA *	is in progress. Under the old method (using INTPAR) a parity *	error on a read would cause a read of the scs_status register *	in szintr. Now use PARCK being cleared for bus reset detection. *	PARCK is now always on (except during arbitration). * *	Slight change in select timing to it in line with SCSI spec, *	i.e., drop IDs from data bus at same time drop SEL. * *   04-Dec-88	Fred Canter *	Remove hack which limited maximum transfer to 64KB - 512. *	64KB transfers used to fail (or so I thought), but work now. *	Added debug variable to allow selected target(s) to be ignored. * *   03-Dec-88	Fred Canter *	Don't do the 4 second disconnect timeout on RZSPECIAL commands *	(format, reassign, vfy_data, and rdd). * *   03-Nov-88	Alan Frechette *	Added in support for disk maintainence. Added the commands *	FORMAT UNIT, REASSIGN BLOCK, READ DEFECT DATA, and VERIFY  *	DATA. Modified MODE SELECT and MODE SENSE. Figured out a *	better way to determine the length of a SCSI command in *	"sz_scsistart()" and "szintr()" during the COMMAND PHASE. *	Made the DATA OUT phase in "sz_scsistart()" and "szintr()" *	into a switch statement. * *   16-Oct-88 -- Fred Canter *	Massive code and comment cleanup. *	Moved #define SZDEBUG to scsireg.h. *	Add variable to control width of bus reset. *	Add RZxx (non-DEC) disk support. *	Fixed a bug in the selection timeout code and *	added retires of select failures. *	Take a phase mismatch interrupt instead of spinning *	waiting for phase changes (critical ones only). *	Put #ifdefs arount spin stats code. *	Added delay after write to scd_adr register to *	work around SCSI/SCSI controller hardware bug. *	Modified arbitration and selection code to work around *	the latest NCR 5380 chip problem. *	Clean up code which waits for BSY to drop after command complete. * *   28-Sep-88 -- Fred Canter *	Clean up comments. *	Clean up code and comments for device failed to select timeout. *	Remove work around code for hardware loosing interrupts. *	Bug fix - waited for 1 second after abort for bus to free up, *	changed to 1 MS. *	The sz_timer1() is now used as a background timer to catch *	bus hangs when the drive is not active. *	Dump SCSI registers on CMDCPT BSY held too long error. *	Modify order of DMA address and direction register writes *	when starting DMA. Also add 3 Usec delay after write to *	address register, This works around a bug in SCSI/SCSI chip. *	which hangs the SCSI/SCSI controller. *	Don't do reselect timeout (timer2) on RRD40. It tries the *	reselect for ever. * *   13-Sep-88 -- Fred Canter *	Only check parity on DMA in and read of current data register. *	Add spl6() around critical code segment in szintr reselect. *	All BSY checks now three times (wire or glitch). *	New routine to dump SCSI registers. * *   21-Aug-88 -- Fred Canter *	Improved device failed to select error handling. Spin for a *	short time. Use a timeout for the remaining time. *	Insure all messages accounted for in unknown/unsupported *	message error (MESSI:). *	Added sz_reset() and other support for bus reset. * * 17-Aug-88	Fred Canter *	Created this file by moving the SCSI NCR 5380 specific files *	from the old combined driver (scsi.c) to scsi_5380.c. * ***********************************************************************//* *********************************************************************** * * NOTES: * *  1.	SCSI controller registers must not be accessed while a DMA *	is in progress. Hardware engineering says the scd_adr & scd_cnt *	registers can be accessed safely, but this has not been verified. *	They also say all registers can be accessed during a DMA on *	the SCSI/SCSI controller. This also has not been verified. * *  2.	Reading the SCSI bus data bits (scs_curdata) when the signals *	are not driven can (and most likely will) cause a psrity error. *	In general the signals are not driven when BSY is false. One *	exception to this is when a disconnected target reselects the *	initator (VS3100 system). BSY is false but the signals are driven. * *  3.	The ANSI SCSI spec calls for a 250 MS selection timeout. The *	timeout is implemented in scsistart and any routines which *	call scsistart. If scsistart is called from the probe routine, *	we spin for 250 MS in scsistart. Calling scsistart from the *	probe routine is always a special case. *	On normal calls to scsistart, we spin for 20 MS in scsistart *	and if BSY does not set we start a series of timeours (timer3). *	We do one 30 MS timeout then four 50 MS timeouts. The messy *	part of this is that the routine calling scsistart must *	unwind its call and be prepared to be called back when the *	timer decides the selection completed or timed out. * *  4.	The RST (bus reset) bit in the cur_stat register is not latched. *	So, the bus reset condition my be gone by the time we get the *	interrupt. We always have PARCK set in the mode register. *	If PARCK ever gets cleared, we assume a bus reset was the cause.	PARCK is cleared during arbitration, so the resetting of the	ARB bit is used to detect a bus reset during arbitration. * *  5.	This driver contains many code sequences like the following: * *		if (((szaddr->scs_curstat & SCS_BSY) == 0) && *		    ((szaddr->scs_curstat & SCS_BSY) == 0) && *		    ((szaddr->scs_curstat & SCS_BSY) == 0)) { *			do_something_wonderfull....... *		} * *	Checking a bus signal three times takes into account the 400 *	nanosecond bus settle delay (wired or glitch). * *  6.	The 5380 detects parity errors on DMA input and CPU reads of *	the scs_curdata register. We read this register during programmed *	I/O input, reselection, and arbitration. Parity checking (PARCK *	bit in mode register) must be disabled during arbitration. This *	is because several targets can be driving the bus data lines *	during arbitration. This can (in fact does) cause parity errors! * * *  7.	When checking for a hung bus, must realize that any target *	on the bus can arbitrate and assert BSY when the target (or *	initator) who currently has BSY asserted releases BSY. The *	time between one target droping BSY and another target *	asserting BSY can be very short (faster than the driver can *	detect with a spin loop). If BSY is asserted the bus is *	probably hung. However, if SEL and I/O are asserted some *	target is doing a reselect (bus not hung). * *********************************************************************** */#include "../data/scsi_data.c"/* * Define ELDEBUG to create error for uerf debuging. * NOTE: must not be defined at submit time (performance hit). *//*#define	ELDEBUG	*//* * The #define for SZDEBUG is in scsireg.h. */#ifdef SZDEBUGextern int szdebug;#define printd if(szdebug)printf#define printd1 if (szdebug > 1) printf#define printd2 if (szdebug > 2) printf#define printd3 if (szdebug > 3) printf#define printd4 if (szdebug > 4) printf#define printd5 if (szdebug > 5) printf#define printd6 if (szdebug > 6) printf#endif SZDEBUG/* * Controls debug code whichs makes sure each * command does a status phase. This bug was fixed * but the code hangs around just in case. *//*#define	SZ_DSP_DEBUG*//* * DEBUG - normally not defined. * Number of 10 Usec increments each device * held BSY after command complete. * CAUTION - must increase array size if NSCSI > 2 *//* #define	SZ_BSYCC_STATS	*/#ifdef	SZ_BSYCC_STATSint	sz_i_bsycc[16];int	sz_ss_bsycc[16];#endif	SZ_BSYCC_STATSu_char	inicmd_tmp;		/* use to write scs_inicmd reg (can't |= ) *//* * NOTE: *	The probe routine is called before cache(s) *	are enabled. Microdelay() now deals with this. *	Turning cache on broke the ST506 disk driver (sdc.c). *	It failed during read if XBNs (DO NOT KNOW WHY). */int	sz_strncmp();int	sz_strcmp();extern int rzcomplete();	/* disk driver completion routine */extern int tzcomplete();	/* tape driver completion routine */extern int sz_cdb_length();extern struct nexus nexus[];extern	int	cpu;/* * Number of seconds to wait for SCSI devices * to come ready enough to respond to inquiry * after bus reset. Needs to be a variable so * users can change it (I am such a nice guy). * Factory default is 7 seconds (in scsi_data.c). */extern int sz_wait_for_devices;extern int sz_max_wait_for_devices;/* * Number of microseconds we wait after each inquiry * command. Just to be absolutely sure the bus is free. * This is delay may not be necessary, but at one point * it appeared the RRD40 held the bus after inquiry. */int	sz_wait_after_inquiry = 1000;int	sz_scsistart();int	sz_reset();int	sz_timer1();/* * Next four variables defined in scsi.c because * they are shared between scsi_5380.c and scsi_sii.c. */extern int szp_firstcall;	/* first call to probe routine */

⌨️ 快捷键说明

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