*#ident	"$Revision: 1.18 $
*
* SCSI
*
*FLAG	PREFIX	SOFT	#DEV	DEPENDENCIES
ns	scsi_	-	-	

$$$
/* NOTE: the initialized array below that describes the various tpsc tape types,
 * etc., has been moved to this file from master.d/tpsc, to allow the
 * tpsc driver to be excluded, and possibly a loadable driver in the
 * future.  The remainder of this file is tpsc specific.
*/
#include "sys/param.h"
#include "sys/scsi.h"
#include "sys/mtio.h"
#include "sys/tpsc.h"
#include "sys/invent.h"


/* Used to set tape type from the inquiry cmd.
 * This allows SGI and users to add new tape drives of known types without
 * re-compiling the driver.  The assumption is that the SCSI commands,
 * capabilities, and request sense info are constant within
 * a type.  This is rarely completely true, but is often close enough
 * to allow a drive to work.  Note that when no additional info (id_ailen
 * field) is returned on the inquiry, the driver sets the vendor id (id_vid)
 * to "CIPHER" and id_pid to "540S" before checking this table.
 *
 * See also sys/mtio.h for definitions of the MTCAN_* bits.
 *
 * Note that this does not quite allow arbitrary drives to be
 * connected, since interpretation of the request sense results,
 * and the modeselect that is done is based on the tp_type field.
 * That field must be set to match one of the known types, or a
 * drive must not appear in this table at all, in which case it is
 * treated as an unknown type, and the tpsc_generic structure (below)
 * is used.  However, if a drive is of an unknown type, but the inquiry
 * command indicates SCSI 2 compliance, the error codes and additional
 * sense info are decoded according to SCSI 2.
 *
 * Also note that a similar list is built into the PROMs and standalone
 * drivers, so changes to this are only effective for use under unix.
 * Furthermore, miniroot kernels will not have any local changes made
 * to this file, which may be important to people attempting system
 * recover with "unknown" tape drives.  If such drives are your only
 * tape device, it is best to make a backup using the fixed block
 * device with 512 byte blocks, of at least enough files to allow you
 * to boot a customized kernel.
 *
 * This structure is defined in sys/tpsc.h - read the comments there for
 * the meanings of fields, and their units, where applicable (search for
 * the tpsc_types structure definition).
 *
 * NOTE:  After adding (or changing) an entry for a drive that was
 * previously 'unknown', reconfiguring the kernel with /etc/autoconfig,
 * and rebooting, you should run the following commands to be sure
 * that you have the correct tape devices (you may wish to first note
 * the existing *tape* links in /dev, or rename them first):
 *		su
 *		cd /dev; rm *tape*; ./MAKEDEV tape
*/
struct tpsc_types tpsc_types[] = {
	{ CIPHER540, TPQIC24, 6, 4, "CIPHER", "540S",  1, "", {0},
	  MTCAN_PREV|MTCAN_SPEOD, 20, 150, 18*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	/* the array avoids a compiler warning about not enough
	 * room for the null.  This is really just "TANDBERG" */
	{ TANDBERG3660, TPQIC150, 8, 8, {'T','A','N','D','B','E','R','G'},
	  " TDC 3660",
	  /* set read/write thresholds and buffer size for better performance */
	  12, "\0\20\20\200\0\0\10\10\0\4", {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  20, 150, 18*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	{ VIPER150, TPQIC150, 7, 9, "ARCHIVE", "VIPER 150", 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  40, 150, 27*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	{ VIPER60, TPQIC24, 7, 8, "ARCHIVE", "VIPER 60", 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  40, 150, 27*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	/* use VIPER150 for internal type, for error decoding, etc. */
	{ VIPER150, TPQIC1000, 7, 10, "ARCHIVE", "ANCDA 2750", 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  40, 150, 27*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	/* use VIPER150 for internal type, for error decoding, etc. */
	{ VIPER150, TPQIC1000, 7, 5, "WANGTEK", "51000", 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  40, 150, 27*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	/* use TANDBERG3660, for error decoding, etc. */
	{ TANDBERG3660, TPQIC1000, 8, 6, {'T','A','N','D','B','E','R','G'},
		" TDC 4", 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_SEEK,
	  40, 150, 27*60, 5*60, 512, 400*512, 0, (u_char *)0 },

	{ DATTAPE, TPDAT, 7, 12, "ARCHIVE", "Python 25601" /*DDS1*/, 0, 0, {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_APPEND|MTCAN_SETMK|MTCAN_PART|MTCAN_PREV|
	    MTCAN_SYNC|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_AUDIO|MTCAN_SEEK|MTCAN_CHTYPEANY,
	  /* minimum delay on i/o is 4 minutes, because when a retry is
	   * performed, the drive retries a number of times, and then
	   * rewinds to BOT, repositions, and tries again.  */
	  40, 4*60, 4*60, 5*60, 512, 512*512, 0, (u_char *)0 },

	{ DATTAPE, TPDAT, 7, 12, "ARCHIVE", "Python 01931" /*DDS2*/, 0, 0, {0},
		/* note: this drive uses modeselect page 0xf for compression control;
		 * most of the other drives supporting compression use page 0x10 */
	  MTCAN_BSF|MTCAN_BSR|MTCAN_APPEND|MTCAN_SETMK|MTCAN_PART|MTCAN_PREV|
	    MTCAN_SYNC|MTCAN_SPEOD|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_AUDIO|MTCAN_SEEK|MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	  /* minimum delay on i/o is 4 minutes, because when a retry is
	   * performed, the drive retries a number of times, and then
	   * rewinds to BOT, repositions, and tries again.  */
	  40, 4*60, 4*60, 5*60, 512, 512*512, 0, (u_char *)0 },

	/* 016 is even byte disconnect and parity check enabled.  
	 * Even though erases can take up to 2.5 hours, the rewtimeo is still 
	 * fairly low.  The driver recognizes this special case (for type
	 * EXABYTE*) and uses 2.5 hours plus rewtimeo.  Minimum delay is set
	 * somewhat high because of the long startup time after idle, and
	 * because FM's take a long time to write. */
	{ EXABYTE8200, TP8MM_8200, 7, 8, "EXABYTE", "EXB-8200", 1, "\16",
	  {0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_CHTYPEANY,
	  80, 4*60, 25*60, 5*60, 1024, 128*1024, 0, (u_char *)0 },

	/* There are 2 densities, 8500 mode and 8200.
	 * The inventory string sets the drive up exactly like the 8200. */
	{ EXABYTE8500, TP8MM_8500, 7, 8, "EXABYTE", "EXB-8500", 6, "\40\4\16\0\200\7",
	  {0x0, 0x14, 0x0, 0x0},
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_CHTYPEANY|MTCAN_SETDEN|MTCAN_SPEOD|MTCAN_SYNC|
		MTCAN_SEEK,
	  80, 4*60, 25*60, 5*60, 1024, 128*1024, 0, (u_char *)0 },

	/* There are 4 densities, 8500 mode and 8200, and compression in each;
	 * The 8200C isn't listed here, but 8200 compressed mode can be written
	 * from the 850{0C,5} series.
	 * The 8505 and the 8500C are functionally the same; the 8x05 drives
	 * are the half height versions.  They all show up as 8500 in hinv. */
	{ EXABYTE8500, TP8MM_8500, 7, 8, "EXABYTE", "EXB-8505", 6, "\40\4\16\0\200\7",
	  {0x15 /*8500*/, 0x14 /*8200*/, 0x8c /*8500C*/, 0x90 /*8200C*/ },
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_CHTYPEANY|MTCAN_SETDEN|MTCAN_SPEOD|MTCAN_SYNC|
		MTCAN_SEEK,
	  80, 4*60, 25*60, 5*60, 1024, 128*1024, 0, (u_char *)0},

	{ EXABYTE8500, TP8MM_8500, 7, 8, "EXABYTE", "EXB8500C", 6, "\40\4\16\0\200\7",
	  {0x15 /*8500*/, 0x14 /*8200*/, 0x8c /*8500C*/, 0x90 /*8200C*/ },
	  MTCAN_BSF|MTCAN_BSR|MTCAN_PREV|MTCAN_CHKRDY|MTCAN_VAR|MTCAN_SETSZ|
	    MTCAN_SILI|MTCAN_CHTYPEANY|MTCAN_SETDEN|MTCAN_SPEOD|MTCAN_SYNC|
		MTCAN_SEEK,
	  80, 4*60, 25*60, 5*60, 1024, 128*1024, 0, (u_char *)0 },

	/* NOTE: xfrtimeo is for the 800 bpi (slowest transfer rate) */
	{ KENNEDY96X2, TP9TRACK, 7, 9, "KENNEDY", "96X2 TAPE", 0, 0,
	   {3, 6, 2, 1}, MTCAN_BSF|MTCAN_BSR|MTCAN_APPEND|MTCAN_LEOD |
	     MTCAN_CHKRDY|MTCAN_VAR| MTCAN_SETSZ|MTCAN_SETSP|MTCAN_SETDEN|
		 MTCAN_SYNC|MTCANT_RET|MTCANT_IMM,
	  20, 150, 20*60, 5*60, 512, 60*512, 0, (u_char *)0 },

	/* DEC THZxx DLT drive */
	{ DECDLT, TPDLT, 3, 7, "SGI", "DLT2000", 0, 0,
	   {0}, MTCAN_BSF|MTCAN_BSR|MTCAN_APPEND|MTCAN_SPEOD |
	     MTCAN_CHKRDY|MTCAN_VAR| MTCAN_SETSZ|MTCAN_SILI|MTCAN_SEEK|
		 MTCAN_SYNC|MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	  20, 8*60, 20*60, 5*60, 4096, 64*1024, 0, (u_char *)0 },

	/* DEC THZxx DLT drive */
	{ DECDLT, TPDLTSTACKER, 3, 7, "SGI", "DLT2700", 0, 0,
	   {0}, MTCAN_BSF|MTCAN_BSR|MTCAN_APPEND|MTCAN_SPEOD |
	     MTCAN_CHKRDY|MTCAN_VAR| MTCAN_SETSZ|MTCAN_SILI|MTCAN_SEEK|
		 MTCAN_SYNC|MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	  20, 8*60, 20*60, 5*60, 4096, 64*1024, 0, (u_char *)0 },

	/* IBM NTP drive */
	{ IBMNTP, TPNTP, 3, 8, "IBM", "03590B1A", 0, 0, {0, 0, 0, 0},
	   MTCAN_BSF|MTCAN_BSR|MTCAN_SPEOD|MTCANT_RET|MTCAN_CHKRDY|
	    MTCAN_PREV|MTCAN_SEEK|MTCAN_APPEND|MTCAN_SILI|MTCAN_VAR|
	     MTCAN_SETSZ|MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	      20, 14*60, 25*60, 6*60, 16384, 512*1024, 0, (u_char *)0 },

	/* IBM NTPSTACKER drive */
	{ IBMNTP, TPNTPSTACKER, 3, 8, "IBM", "03590B11", 0, 0, {0, 0, 0, 0},
	   MTCAN_BSF|MTCAN_BSR|MTCAN_SPEOD|MTCANT_RET|MTCAN_CHKRDY|
	    MTCAN_PREV|MTCAN_SEEK|MTCAN_APPEND|MTCAN_SILI|MTCAN_VAR|
	     MTCAN_SETSZ|MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	      20, 14*60, 25*60, 6*60, 16384, 512*1024, 0, (u_char *)0 },
	
	/* STK 9490 drive */
	{ STK90, TPSTK9490, 3, 4, "STK", "9490", 0, 0, {0, 0, 0, 0},
	   MTCAN_BSF|MTCAN_BSR|MTCANT_RET|MTCAN_CHKRDY|MTCAN_PREV|
	    MTCAN_SEEK|MTCAN_APPEND|MTCAN_SILI|MTCAN_VAR|MTCAN_SETSZ|
	     MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	      20, 8*60, 10*60, 3*60, 16384, 256*1024, 0, (u_char *)0 },
	
	/* STK SD3 drive */
	{ STKSD, TPSTKSD3, 3, 4, "STK", "SD-3", 0, 0, {0, 0, 0, 0},
	   MTCAN_BSF|MTCAN_BSR|MTCANT_RET|MTCAN_CHKRDY|MTCAN_PREV|
	    MTCAN_SEEK|MTCAN_APPEND|MTCAN_SILI|MTCAN_VAR|MTCAN_SETSZ|
	     MTCAN_CHTYPEANY|MTCAN_COMPRESS,
	      20, 100*60, 10*60, 9*60, 16384, 256*1024, 0, (u_char *)0 }
};

/* numtypes doesn't include the generic entry */
int tpsc_numtypes = sizeof(tpsc_types)/sizeof(tpsc_types[0]);

/* this entry is used for all tapes not matching any of the entries
 * in tpsc_types.  It basicly assumes a limited QIC set of capablities. */
struct tpsc_types tpsc_generic = {
	TPUNKNOWN, TPUNKNOWN, 0, 0, "", "", 0, 0, {0},
	MTCAN_SPEOD, 20, 150, 18*60, 5*60, 512, 400*512, 0, (u_char *)0
};

/* if non-zero, rewinds are done with the immediate bit set, which
 * means that the rewind ioctl will return as soon as the drive
 * has accepted the command (rewinds are *always* immediate when
 * in AUDIO mode, so that programs may poll the drive as to the
 * current position, which works only in audio mode).  If a drive
 * description has the MTCANT_IMM bit set, the setting of this variable
 * is ignored for that drive (for drives that do not handle immediate
 * mode rewinds, or do not return the correct "error" codes while an
 * immediate mode operation is in progress.
 * This variable also effects the MTRET  ioctl with the exception
 * of drives which have the MTCANT_RET capability flag in their description,
 * since they need to have the retension command emulated; it partially
 * works for these drives, since the emulation is 'space to eom, unload'
 * NOTE: This doesn't affect the MTUNLOAD or MTOFFL ioctls.
 *
 * The value of 0 is the way releases previous to IRIX 5 worked,
 * where programs were unkillable until the rewind completed.
 * This variable also affects the rewind the driver does when
 * the rewind device is closed, so that the close of the rewind
 * and no-rewind devices will both return immediately if this variable
 * is set.
 *
 * If the drive is closed (e.g., when doing 'mt rewind'), subsequent opens
 * will block until the rewind has completed. If programs use the rewind
 * ioctl, and want to know when it is done, The MTIOCGET ioctl will block
 * until the rewind is completed; other tape commands will fail with EBUSY
 * until the rewind completes.
 */
int tpsc_immediate_rewind = 1;

/*
 * The following variable is used to enable/disable printing a message
 * when the illegal length indicator is enabled (the default state).
 * Such messages are of the form:
 *   NOTICE: SCSI tape #0,7 blocksize mismatch; blocksize on tape is 4096 bytes
 * If tpsc_print_ili is cleared, these messages will not be printed to
 * the console or spooled SYSLOG.
 */
int tpsc_print_ili = 1;

/*
 * The following table is used to ensure that all CD-ROM drives are
 * so identified in the hardware inventory. The SGI supplied CD-ROM
 * drives (and possibly those from some other vendors) identify themselves
 * as hard disk drives at poweron, and after SCSI bus resets, until
 * issued a vendor specific command (0xc9).  This is done because older
 * systems would otherwise be unable to boot and load miniroots from CD, due
 * to their design (they attempted to protect the user from booting from
 * "ridiculous" devices, long before CD-ROM drives existed).  The SGI drives
 * are sent a command to "revert" to CD-ROM inquiry information during boot
 * if on a SCSI bus handled by the PROM, but not all possible buses are
 * handled by all PROMs; additionally, a SCSI bus reset causes the CD-ROM
 * drives to revert to the poweron default, and this could happen before
 * the hardware inventory code in the kernel runs, if there are SCSI
 * problems.  The table of strings below is used identify CD-ROM drives by
 * doing a strstr() with each the strings below on the vendor and product
 * fields of the data returned by the the inquiry command.  A match on
 * any of them will cause the device to be added to the hardware inventory
 * as a CD-ROM, for the wd93, wd95, and jag SCSI drivers.
 */
char *cdrom_inq_strings[] = {
	"CDROM", "CD-ROM", "CD ROM", NULL
};
