/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: tg.h 1.9 89/08/07 $"

#ifndef	_SYS_TG_H_

/*
 * tg.h
 *	HP 88780 SCSI  tape driver structure definitions.
 */

/* $Log:	tg.h,v $
 */

#define	INF	(daddr_t)1000000
/*
 * Information structure definition.  One of these per 
 * tape drive.
 */

struct	tg_info {
	sema_t usrsync;			/* Sync. system call entries */
	sema_t gensync;			/* Termination sync for SCSI ops */
	spl_t	spl;			/* Saved priority level */
	scac_t cmd;			/* SCSI command information */
	ulong term_id;			/* Saved magic cookie identifying
					 * this command when it terminates. */
	int status;			/* Command completion status */
	long resid;			/* Command completion residual count */
	lock_t	lock;			/* Lock access to this structure */
	char	access;			/* State of unit accessibility */
	unchar	sflags;			/* State modifier flags for driver */
	tgdev_t *dev;			/* Device descriptor from auto-conf */
	ulong iocount;			/* Bytes read/written for statistics */
	struct tape_stats *stats;	/* Other statistical info */
	daddr_t blkno;			/* Current tape block number */
	daddr_t	nxrec;			/* position of end of tape, if known */
};

/* Values taken by tg_info.access */
#define	TGA_CLOSED	0		/* Device is not open */
#define	TGA_OPEN	1		/* Device is open to a process */
#define	TGA_RWNDCLS	2		/* Device is rewinding, but closed */

/* State modifier flags for tg_info.sflags  */
#define	TGF_EOM		0x1		/* End of media encountered */
#define	TGF_FAIL	0x2		/* Operation failed */
#define	TGF_LASTIOW	0x4		/* Last I/O was a WRITE. Write
					 * a filemark upon closing. */
#define	TGF_LASTPOS	0x8		/* Last operation positioned the
					 * media; a subsequent close should
					 * not forward to next file. */
#define	TGF_EOF		0x10		/* End of file encountered */
#define TGF_UNLOAD	0x20		/* Tape was just unloaded */

#define TG_UNITMAX	0x07		/* Maximum device unit number */
#define TG_MAXMINOR	MT_MINOR(TG_UNITMAX, MTF_NOREWFLAG, MTD_COMPRESS)

/*
 * Other miscellaneous definitions used by the driver.
 */
#define TG_SPL		SPL5		/* spl priority on locks and semas */
#define TG_VARIABLE	0		/* 'fixed' bit value for I/O commands */
#define TG_DENS_NOOP 	0x7f		/* Use front-panel density */

/*
 * Binary configuration tuning parameters 
 * for individual driver units.  Leave as
 * a structure flexibility in event of
 * future expansion.
 */
struct tg_bconf {
	unchar cflags;			/* Flags for configurable behaviors */
};

/* Flag definitions for tg_bconf.cflags */
#define	TGC_PRSENSE	0x01		/* Print all sense info */
#define	TGC_OPENFAIL	0x02		/* Fail opens if no memory */
#define	TGC_AUTORET	0x04		/* Auto retension */
#define	TGC_RSENSE	0x08		/* Print sense info associated 
					 * with read commands */
#define	TGC_WSENSE	0x10		/* Print sense info associated 
					 * with write commands */
#define	TGC_SSENSE	0x20		/* Print sense info associated 
					 * with space commands */

/* 
 * Drive dependent information for locating
 * supported drives and drive dependent 
 * functions/data for managing them.  
 */
struct tg_drive_info {
	char *vendor;			/* Vendor i.d. string */
	char *product;			/* Product i.d. string */
	unchar embedded;		/* Target adapter type */
	unchar slen;			/* Amount of request sense buffer
					 * to use for drive type */
	unchar mlen;			/* Amount of mode select buffer
					 * to use for drive type */
	void (*mode_select)();		/* drive dependent mode-select
					 * code */
	int (*recerrs)();		/* drive dependent request-sense
					 * code for retreiving the count
					 * of recoverable errors. */
};

/* For tg_drive_info.embedded */
#define TGD_NONEMBED	0		/* Target adapter type is nonembedded */
#define TGD_EMBED	1		/* Target adapter type is embedded */

#ifdef INKERNEL

/*
 * Global references.
 */
extern struct tg_bconf tg_bconf[];	/* Binary configuration table.
					 * Declared in tg_space.c */
extern int tg_max_ndevs;		/* Number of entries in tg_bconf.
					 * Declared in tg_space.c */
extern struct tg_drive_info tg_drives[]; /* Drive i.d. table.
					 * Declared in tg_space.c */
extern int tg_drives_len;		/* Number of entries in tg_drives.
					 * Declared in tg_space.c */
/* Interface to tg.c */
extern tgioctl();

#ifndef i386
extern gate_t tg_gate;			/* Declared in tg_space.c */
#endif 

extern unchar tg_bin;
extern int tg_probe();
extern void tg_init(), tg_intr();

#endif /* INKERNEL */

#define	_SYS_TG_H_
#endif	/* _SYS_TG_H_ */
