📄 scsi_sii.c
字号:
#ifndef lintstatic char *sccsid = "@(#)scsi_sii.c 4.6 (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_sii.c 17-Aug-88 * * VAX SCSI device driver (SII 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. * * 09/26/90 Robin Miller * Fixed problem introduced in 8/29/90 edit. I inadvertantly left * off the target ID index when referencing the SII DMA count field * (sc_siidmacount[targid]) on disconnect phases. This problem was * causing a "Panic: Protection Fault" when booting. * * 08/30/90 Robin Miller * Added check in probe routine to recognize RX26 device type * and setup accordingly for floppy device. * * 08/29/90 Robin T. Miller * Changed the check made in sii_msgin() to set the SZ_DMA_DISCON * flag (disconnect occured during dma) when there is residual dma * count for this target. Previously, this flag was only set if * the previous phase was a data in or a data out. This check was * insufficient for our CDROMs, broke both the RRD40 & RRD42, since * the previous two phases were message in. * * 08-Aug_90 Bill Dallas * Got rid of the -2 of the modsns len for disks. This was * causing problems when we got rid of hard define for MODSNS_LEN * which was 14 ( tapes). Caused problems on booting. In * sii_startdma is where the changed was made. * * 05-Jul-90 Bill Dallas * Added support for the new device option table * Got rid of hard define * * 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 L. Schank * During the message in phase, if an unsupported extended message * is received, ATN is asserted before the last message byte * is acknowledged. Remove refrences to SII, replaced with nSII. * * 08-Oct-89 Fred Canter * Removed error log #ifdef OLDWAY. * * 07-Oct-89 Fred Canter * Save removable media bit from inquiry data in sz_softc. * * 17-Aug-89 Janet L. Schank * sii_scsistart now uses sz_opcode as an index into the sz_timetable. * This was done since pseudo-opcode values aren't in his table. A * check is also being done on the sz_opcode to make sure its in the * table. * * 23-Jul-89 Fred Canter * RX33 support. * * 16-Jul-89 Fred Canter * Bug fix - mode sense byte was not set correctly. * Allows mode sense to get disk geometry. * * 14-Jul-89 Fred Canter * Merged Dynamic BBR and error log changes. * * 28-Jun-89 Fred Canter * Convert error messages from printf to scsi_logerr(). * * 23-Jun-89 Fred Canter * Save status byte for current command for error log. * * 23-Jun-89 John A. Gallant * Added the initialization of the completion code routine pointers. In * the start dma code added support for the read/write long commands. * * 20-Jun-89 Fred Canter * Convert to scsi_devtab. * * 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. * * 06-Apr-89 Fred Canter * Added b_comand to replace b_command for local command buffers. * Use b_gid instead of b_resid to store command. * No longer need to restore bp->b_command on error retry. * * 22-Feb-89 Alan Frechette * A few minor probe changes. Fixed BUS DEVICE RESET handling. * Added the routine "sii_restart_target()" to restart driver * activity for a particular target after a BUS DEVICE RESET * occurred on that particular target. * * 13-Feb-89 Alan Frechette * Added in function headers for all subroutines. Allow an * additional retry of the inquiry command in "sii_probe()" * in the case that SZ_RET_ABORT is returned. Added an * additional check in "sii_intr()" when checking for DMA * transfers ">8K". * * 12-Feb-89 Fred Canter * Removed some comments which no longer apply. * * 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. * * 5-Feb-89 Fred Canter * Remove rz_max_xfer, cz_max_xfer, and tz_max_xfer. * * 27-Dec-88 Alan Frechette * Made a change to break out of the (SZWAIT_UNTIL) loop in the * routines "sii_recvdata()" and "sii_senddata()" during a DMA * transfer if either the (SII_MIS) or (SII_DNE) bits are set. * * Added debug printf's (PRINTD) to track timing of spin loops. * * We no longer spin wait for phase changes in the routines * "sii_scsistart()" and "sii_intr()". We now wait for the * interrupt to occur. We only spin wait for the "msgout" and * "command" phases. All other phases we wait for the interrupt. * * Changed "scsi_completed" variable to be an array. It is now * defined as "short scsi_completed[NDPS]". * * 19-Dec-88 Alan Frechette * Added a small spinwait in "sii_state_change()" to wait for * the (SII_CON) bit in the CSTAT REGISTER to be asserted if * the SII was expecting to be connected to a target. This is * needed because the connect bit (SII_CON) can be asserted much * later than the reselect bit (SII_DST_ONBUS) on the SII. * * Removed all the include files that were surrounded by the * "#ifdef notdef" and "#endif notdef" construct. * * Zero out ram buffer location in "sii_probe()" before issuing * the inquiry command. This is needed to clear out any previous * data in the ram buffer. * * 17-Dec-88 Fred Canter * Added pseudo commands to resolve the conflict between * SZ_UNLOAD and SZ_SSUNIT both being opcode 0x1b. * * 06-Dec-88 Alan Frechette * Changed the select wait count in "sii_select_target()" to be * 2500 instead of 10000. Increased number of retries from 2 to 3. * Fixed the sending of the DISCONNECT command in this routine * also. The DISCONNECT command should only be sent if a selection * attempt failed and the selection in progress bit (SII_SIP) is * set in the CSTAT REGISTER. The new select wait count is based * on the Selection Timeout Delay in the scsi specification. The * selection timeout value is 250 milliseconds. * * Fixed probe to allow 64K transfers for the disk. Probe was * allowing only (64K - 512) as the maximum disk transfer size. * * 01-Dec-88 Alan Frechette * Had to make a change due to new firmware in CDROM. The CDROM * now sends a message reject message and then disconnects from * the bus when you send it an Extended Synchronous Data Tranfer * Request Message. This is now handled correctly. * * Clear sent synchronous message flags "sc->sc_siisentsync[]" * in "sii_reset()" when operating in scsi polled mode during * boot up. If we get a reset we must clear these flags or else * the system will not come up. * * Reworked the debugging for the SII. Improved it considerably. * * 03-Nov-88 Alan Frechette * Added in support for disk maintainence. Added the commands * FORMAT UNIT, REASSIGN BLOCK, READ DEFECT DATA and VERIFY DATA. * Made changes to MODE SENSE and MODE SELECT. Made some more * performance improvements to the SII. I now pass "targid" to * every subroutine I call and got rid of the useless subroutine * "sii_getactive_target()". * * Add in support for non-DEC disks. This is done in the probe * routine and the non-DEC disks are designated by "RZxx". Also * removed "#define SZDEBUG" from this file. * * Changed the spin loops for PHASE CHANGES. If a PHASE CHANGE * does not occur within the spin loop time period then the code * will return and wait for the PHASE CHANGE interrupt from the SII. * * Added scsi command timeout logic to the SII. The routine * "sii_timer()" handles the command timeout logic. The SII * uses the command timeout table "sz_timetable[]" defined * in the file "scsi.c". * * Made a change to handle devices that do not support scsi * Extended Messages in "sii_msgout()". If a scsi command * did not have good status then return the value "SZ_RET_ERR" * in "sii_scsistart()" otherwise return "SZ_SUCCESS". This * was a nasty bug. * * Implemented the Bus Device Reset message to reset only a * particular SCSI device and not the entire SCSI bus. Also * implemented the Abort message to abort the current command * due to an error. * * Fixed the routine "sii_clear_discon_io_requests()" to not * return an IO error on the disconnected IO request after a * reset occurred on the SCSI bus. * * Fixed the entire "reset" handling throughout this driver. * * 08-Sep-88 Alan Frechette * Fixed the handling of spurious interrupts on the SII. The * interrupt routine will ignore all spurious interrupts from * the SII and will simply return. * * The following fixes were made to support the CDROM device: * 1: Fixed the handling of the Synchronous Data Transfer Request * message with the CDROM device. The CDROM device would switch * phase before it would recieve the last byte of this message. * * 2: Ignore the second disconnect if we get back-to-back * disconnects from the CDROM device. * * 3: Rewrote the routine "sii_select_target" to handle the * slower CDROM device. Wait for the connect bit (SII_CON) * after we get the state change bit (SII_SCH). Corrected * some of the logic in this routine. * * 01-Sep-88 Alan Frechette * Save the value of the DMA Length Of Transfer Count register * in "sii_msgin". Since the SII now uses DMA for all information * transfers we must save the this value in case the message * is a SAVE DATA POINTER message. Otherwise we will lose the * true state of the DMA for that target and how much data was * actually transfered. * * Made a fix to "sii_senddata" when using programmed io. Added * the setting of the "attn" variable when setting the Command * register in the SII. * * 23-Aug-88 Alan Frechette * Fixed the GENERIC kernel boot problem for SII systems. * The GENERIC kernel now boots off an SII based workstation. * * Added support to handle SYNCHRONOUS and ASYNCHRONOUS devices * at the same time. I simply save the req/ack offset for each * SCSI device out on the bus after issuing the Synchronous Data * Transfer Request extended message. The req/ack offset is used * to set the DMA Control Register of the SII for synchronous or * asynchronous data transfers. * * Fixed a few bugs in the SII interrupt routine dealing with * reselects and handle quick reselects there rather then wait * for another interrupt. * * 17-Aug-88 Fred Canter * Created this file by moving the SCSI SII specific files * from the old combined driver (scsi.c) to scsi_sii.c. * The SII code was written by Darrell Dunnuck and Alan Frechette. * ***********************************************************************/#include "../data/scsi_data.c"#ifdef SZDEBUG/********************************************************************* * NOTE ON HOW DEBUGGING WORKS FOR SII DRIVER * * The scsi debug variable "siidebug" controls the level of debugging * and is defined as follows: * * bit 0: prints out only scsi bus phase/state values. (siidebug=0x1) * bit 1: prints out only the expansion of commands. (siidebug=0x2) * bit 2: prints out only errors encountered. (siidebug=0x4) * bit 3: prints out only code flow through routines. (siidebug=0x8) * bit 4: prints out only spurious interrupts. (siidebug=0x10) * bit 5: prints out only timer values of spin loops. (siidebug=0x20) * * The scsi target variable "siitarget" controls the debugging of a * specific target only. * * bit 0: prints out only debugging for target 0 (siitarget=0x1) * bit 1: prints out only debugging for target 1 (siitarget=0x2) * bit 2: prints out only debugging for target 2 (siitarget=0x4) * bit 3: prints out only debugging for target 3 (siitarget=0x8) * bit 4: prints out only debugging for target 4 (siitarget=0x10) * bit 5: prints out only debugging for target 5 (siitarget=0x20) * bit 6: prints out only debugging for target 6 (siitarget=0x40) * bit 7: prints out only debugging for target 7 (siitarget=0x80) * all : prints out debugging for all targets (siitarget=-1) * * * EXAMPLE: Debug (target 3) with bitmask (bit0|bit1|bit2) * * adb -w -k /vmunix /dev/mem * siitarget/W 8 (Set to target 3) * siidebug/W 7 (Set debug bitmask to 7) * $q * ********************************************************************/int siidebug = 0;int siitarget = 0;#define PRINTD(T,F,X) { \ if(siidebug & F) { \ if((siitarget & (1<<T)) || siitarget == -1 || T == -1) \ cprintf X; \ } \}#endif SZDEBUG/* * Number of seconds to wait for SCSI devices * to come ready enough to respond to inquiry * after a 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;int sii_wait_after_inquiry = 1000;/* * More external declarations for the SII. */extern char cvqmsi[] [512*NBPG];/* The SII registers in IO SPACE */extern char cvqmsirb[]; /* The 128K RAM buffer for the SII */extern char szbufmap[]; /* Holds PTE's from get_sys_ptes() */extern short sz_timetable[]; /* Command timeout table for SII chip */extern int szp_nrz; /* Number of RZ disks found */extern int szp_ntz; /* Number of TZ tapes found */extern int szp_ncz; /* Number of CDROM optical disks found */extern int szp_nrx; /* Number of CDROM optical disks found */extern struct scsi_devtab szp_rz_udt;extern struct scsi_devtab szp_tz_udt;extern struct scsi_devtab szp_cz_udt;extern int sii_scsistart(); /* SII scsi start routine */extern int sii_reset(); /* SII scsi reset routine */int sii_restart_target(); /* SII scsi restart target routine */int sz_strncmp();int sz_strcmp();extern int rzcomplete();extern int tzcomplete();extern int sz_cdb_length();/********************************************************************** * * Name: sii_probe * * Abstract: The SII probe entry point routine from auto-configure * code. Determine if the SII controller exists. Reset the * SCSI bus. Size the number and type of targets on the * SCSI bus. Set up the "sz_softc" structure and the 128K * hardware buffer. * * Inputs: * reg SCSI bus controller CSR address (not used). * cntlr SCSI bus controller number (0 = bus A, 1 = bus B). *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -