/* $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: sd.h 1.18 89/08/07 $"

#ifndef	_SYS_SD_H_

/*
 * sd.h
 *	SCSI driver definitions.
 */

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

/*
 * Information structure - one per channel.
 */
struct sd_info{
	/*
	 * flags, states, etc...
	 */
	int	sd_stat;		/* low memory area for return status */
	int	sd_flags;		/* Local state flags */
	int	sd_nopen;		/* number of opens */
	daddr_t sd_capacity;		/* total disk space */

	int	sd_retrys;		/* Configuration - max retrys */
	struct sec_dev_prog *sd_savedp;	/* saved error'd device program ptr */
	unchar	sd_lun;			/* Correct lun for this unit */

	/*
	 * Partition tables.
	 */
	struct scsid_partition *sd_part;	/* Straight from configuration */

	/*
	 * Configuration information copied out at boot time.
	 */
	int	 sd_thresh;		/* Max to take off queue in sdstart */
	int	 sd_low;		/* When to recall start from intr */
	struct	 seddc	*sd_dc;		/* Device queues and controls */
	struct	 sec_dev *sd_desc;	/* device descriptor for ta */
	unchar	 *sd_sensebuf;		/* error sense buffer */
	unchar	 *sd_sensebufptr;	/* iat of error sense buffer */

	/*
	 * Buffers real and fiction.
	 */
	char	*sd_rawbuf;		/* set at boot time to ..[sdrawsz] */
	struct	buf sd_bufh;		/* Header for strat */
	struct	buf sd_bp;		/* Header for start */
	struct	buf sd_rbufh;		/* Header for raw */

	/*
	 * Statistics.
	 */
	struct	disk_stats *sd_dstats;	/* stats pointer */

	/*
	 * Local data descriptors to the hardware.
	 * Allocated and initialized at boot time.
	 */
	lock_t	sd_lock;
	sema_t	sd_sema;
	struct	sec_req_sense sd_statb;
};

/*
 * Configuration structures.
 */
struct sd_bconf {
	int bc_rawbuf_sz;		/* internal raw ioctl buf size */
	struct scsid_partition  *bc_part;	/* partition table pointer */
	int bc_num_iat;			/* number of iat's per channel */
	int bc_low;			/* Max number before start slows */
	int bc_thresh;			/* Maximum to get off queue each start*/
	long bc_blks_per_sec;		/* transfer rate in blocks per second */
	int bc_res1;			/* reserved */
};

/*
 * misc
 */
#define SD_ANYBIN	4		/* Only used during probe */
#define SD_BASE		32		/* Start of units for SCSI */
#define SDSPL		SPL5		/* spl priority on locks and semas */
#define SD_ADDRALIGN	16		/* RAWIO must start on 16 byte bound */


/*
 * The following macros are only for readability and are only
 * used in isolated cases. Driver changes that bring up new problems
 * should suspect these after verifing code correctness.
 */
#define SD_CHANNEL(sd)	((sd)->sd_chan) /* disk  # */

/*
 * Scsi Device States and flags
 */
#define SDS_IDLE		0		/* bufh == idle */
#define SDS_PROBE		1		/* device is probing */
#define SDS_BUSY		2		/* queue on bufh */

#define SDF_SENSE		0x01		/* obtaining sense info */
#define SDF_NOSTART		0x02		/* slow device stuffing a bit */
#define SDF_EXCLUSIVE		0x04		/* device accessed exclusively */

/*
 * Additional masks
 */
#define SDLUNMSK		0xe0		/* LUN data in SCSI cmd */

#define SD_DONE			0		/* stop */
#define SD_NOTDONE		1		/* continue */

/*
 * flags for sdreadc routine
 */
#define USABLE			0		/* size minus diagnostic trks */
#define ENTIRE			1		/* actual size */

/*
 * Ioctl commands.
 */
#define SDI_STATS		1
#define SDI_CMD			2


/*
 * macros for extracting the LBA from extended and non-extended Request
 * sense bytes.
 */

#define XgetLBA(b) \
	(uint) (((((b[3] << 8) | b[4]) << 8) | b[5]) << 8) | b[6]

#define getLBA(b) \
	(uint) (((b[1]<< 8) | b[2]) << 8) | b[3]

extern int sd_req_size, sd_doneq_size, sd_flags;
extern unchar sd_bin;

extern int sd_probe();
extern void sd_init(), sd_intr();

#define	_SYS_SD_H_
#endif	/* _SYS_SD_H_ */
