xref: /onnv-gate/usr/src/uts/common/sys/scsi/targets/sddef.h (revision 609:6c4397e1569b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_SDDEF_H
280Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_SDDEF_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
340Sstevel@tonic-gate #include <sys/note.h>
350Sstevel@tonic-gate #include <sys/mhd.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #ifdef	__cplusplus
380Sstevel@tonic-gate extern "C" {
390Sstevel@tonic-gate #endif
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #define	SD_SUCCESS		0
460Sstevel@tonic-gate #define	SD_FAILURE		(-1)
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #if defined(TRUE)
490Sstevel@tonic-gate #undef TRUE
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #if defined(FALSE)
530Sstevel@tonic-gate #undef FALSE
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #define	TRUE			1
570Sstevel@tonic-gate #define	FALSE			0
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #if defined(VERBOSE)
600Sstevel@tonic-gate #undef VERBOSE
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate 
630Sstevel@tonic-gate #if defined(SILENT)
640Sstevel@tonic-gate #undef SILENT
650Sstevel@tonic-gate #endif
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  *  Fault Injection Flag for Inclusion of Code
700Sstevel@tonic-gate  *
710Sstevel@tonic-gate  *  This should only be defined when SDDEBUG is defined
720Sstevel@tonic-gate  * #if DEBUG || lint
730Sstevel@tonic-gate  * #define	SD_FAULT_INJECTION
740Sstevel@tonic-gate  * #endif
750Sstevel@tonic-gate  */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #define	VERBOSE			1
780Sstevel@tonic-gate #define	SILENT			0
790Sstevel@tonic-gate 
800Sstevel@tonic-gate /*
810Sstevel@tonic-gate  * Structures for recording whether a device is fully open or closed.
820Sstevel@tonic-gate  * Assumptions:
830Sstevel@tonic-gate  *
840Sstevel@tonic-gate  *	+ There are only 8 (sparc) or 16 (x86) disk slices possible.
850Sstevel@tonic-gate  *	+ BLK, MNT, CHR, SWP don't change in some future release!
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	SDUNIT_SHIFT	3
910Sstevel@tonic-gate #define	SDPART_MASK	7
920Sstevel@tonic-gate #define	NSDMAP		NDKMAP
930Sstevel@tonic-gate 
940Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
950Sstevel@tonic-gate 
960Sstevel@tonic-gate #define	SDUNIT_SHIFT	6
970Sstevel@tonic-gate #define	SDPART_MASK	63
980Sstevel@tonic-gate #define	NSDMAP		(NDKMAP + FD_NUMPART + 1)
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate #else
1010Sstevel@tonic-gate #error "No VTOC format defined."
1020Sstevel@tonic-gate #endif
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate #define	SDUNIT(dev)	(getminor((dev)) >> SDUNIT_SHIFT)
1060Sstevel@tonic-gate #define	SDPART(dev)	(getminor((dev)) &  SDPART_MASK)
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate  * maximum number of partitions the driver keeps track of; with
1100Sstevel@tonic-gate  * EFI this can be larger than the number of partitions accessible
1110Sstevel@tonic-gate  * through the minor nodes.  It won't be used for keeping track
1120Sstevel@tonic-gate  * of open counts, partition kstats, etc.
1130Sstevel@tonic-gate  */
1140Sstevel@tonic-gate #define	MAXPART		(NSDMAP + 1)
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  * Macro to retrieve the DDI instance number from the given buf struct.
1180Sstevel@tonic-gate  * The instance number is encoded in the minor device number.
1190Sstevel@tonic-gate  */
1200Sstevel@tonic-gate #define	SD_GET_INSTANCE_FROM_BUF(bp)					\
1210Sstevel@tonic-gate 	(getminor((bp)->b_edev) >> SDUNIT_SHIFT)
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate struct ocinfo {
1260Sstevel@tonic-gate 	/*
1270Sstevel@tonic-gate 	 * Types BLK, MNT, CHR, SWP,
1280Sstevel@tonic-gate 	 * assumed to be types 0-3.
1290Sstevel@tonic-gate 	 */
130433Sgz161490 	uint64_t  lyr_open[NSDMAP];
131433Sgz161490 	uint64_t  reg_open[OTYPCNT - 1];
1320Sstevel@tonic-gate };
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate #define	OCSIZE  sizeof (struct ocinfo)
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate union ocmap {
1370Sstevel@tonic-gate 	uchar_t chkd[OCSIZE];
1380Sstevel@tonic-gate 	struct ocinfo rinfo;
1390Sstevel@tonic-gate };
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #define	lyropen rinfo.lyr_open
1420Sstevel@tonic-gate #define	regopen rinfo.reg_open
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate  * fdisk partition mapping structure
1470Sstevel@tonic-gate  */
1480Sstevel@tonic-gate struct fmap {
1490Sstevel@tonic-gate 	daddr_t fmap_start;		/* starting block number */
1500Sstevel@tonic-gate 	daddr_t fmap_nblk;		/* number of blocks */
1510Sstevel@tonic-gate };
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /*
1540Sstevel@tonic-gate  * cache structure for saving geometry from target and HBA.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate struct geom_cache {
1570Sstevel@tonic-gate 	unsigned int	g_ncyl;
1580Sstevel@tonic-gate 	unsigned short	g_acyl;
1590Sstevel@tonic-gate 	unsigned short	g_nhead;
1600Sstevel@tonic-gate 	unsigned short	g_nsect;
1610Sstevel@tonic-gate 	unsigned short	g_secsize;
1620Sstevel@tonic-gate 	unsigned int	g_capacity;
1630Sstevel@tonic-gate 	unsigned short	g_intrlv;
1640Sstevel@tonic-gate 	unsigned short	g_rpm;
1650Sstevel@tonic-gate };
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	SD_CDB_GROUP0		0
1690Sstevel@tonic-gate #define	SD_CDB_GROUP1		1
1700Sstevel@tonic-gate #define	SD_CDB_GROUP5		2
1710Sstevel@tonic-gate #define	SD_CDB_GROUP4		3
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate struct sd_cdbinfo {
1740Sstevel@tonic-gate 	uchar_t	 sc_grpcode;	/* CDB group code */
1750Sstevel@tonic-gate 	uchar_t  sc_grpmask;	/* CDB group code mask (for cmd opcode) */
1760Sstevel@tonic-gate 	uint64_t sc_maxlba;	/* Maximum logical block addr. supported */
1770Sstevel@tonic-gate 	uint32_t sc_maxlen;	/* Maximum transfer length supported */
1780Sstevel@tonic-gate };
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate /*
1830Sstevel@tonic-gate  * The following declaration are for Non-512 byte block support for the
1840Sstevel@tonic-gate  * removable devices. (ex - DVD RAM, MO).
1850Sstevel@tonic-gate  * wm_state: This is an enumeration for the different states for
1860Sstevel@tonic-gate  * manipalating write range list during the read-modify-write-operation.
1870Sstevel@tonic-gate  */
1880Sstevel@tonic-gate typedef enum {
1890Sstevel@tonic-gate 	SD_WM_CHK_LIST,		/* Check list for overlapping writes */
1900Sstevel@tonic-gate 	SD_WM_WAIT_MAP,		/* Wait for an overlapping I/O to complete */
1910Sstevel@tonic-gate 	SD_WM_LOCK_RANGE,	/* Lock the range of lba to be written */
1920Sstevel@tonic-gate 	SD_WM_DONE		/* I/O complete */
1930Sstevel@tonic-gate } wm_state;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /*
1960Sstevel@tonic-gate  * sd_w_map: Every write I/O will get one w_map allocated for it which will tell
1970Sstevel@tonic-gate  * the range on the media which is being written for that request.
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate struct sd_w_map {
2000Sstevel@tonic-gate 	uint_t		wm_start;	/* Write start location */
2010Sstevel@tonic-gate 	uint_t		wm_end;		/* Write end location */
2020Sstevel@tonic-gate 	ushort_t	wm_flags;	/* State of the wmap */
2030Sstevel@tonic-gate 	ushort_t	wm_wanted_count; /* # of threads waiting for region */
2040Sstevel@tonic-gate 	void		*wm_private;	/* Used to store bp->b_private */
2050Sstevel@tonic-gate 	struct buf	*wm_bufp;	/* to store buf pointer */
2060Sstevel@tonic-gate 	struct sd_w_map	*wm_next;	/* Forward pointed to sd_w_map */
2070Sstevel@tonic-gate 	struct sd_w_map	*wm_prev;	/* Back pointer to sd_w_map */
2080Sstevel@tonic-gate 	kcondvar_t	wm_avail;	/* Sleep on this, while not available */
2090Sstevel@tonic-gate };
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_w_map::wm_flags))
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * This is the struct for the layer-private data area for the
2160Sstevel@tonic-gate  * mapblocksize layer.
2170Sstevel@tonic-gate  */
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate struct sd_mapblocksize_info {
2200Sstevel@tonic-gate 	void		*mbs_oprivate;	/* saved value of xb_private */
2210Sstevel@tonic-gate 	struct buf	*mbs_orig_bp;	/* ptr to original bp */
2220Sstevel@tonic-gate 	struct sd_w_map	*mbs_wmp;	/* ptr to write-map struct for RMW */
2230Sstevel@tonic-gate 	ssize_t		mbs_copy_offset;
2240Sstevel@tonic-gate 	int		mbs_layer_index;	/* chain index for RMW */
2250Sstevel@tonic-gate };
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_mapblocksize_info))
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate  * sd_lun: The main data structure for a scsi logical unit.
2320Sstevel@tonic-gate  * Stored as the softstate structure for each device.
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate struct sd_lun {
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	/* Back ptr to the SCSA scsi_device struct for this LUN */
2380Sstevel@tonic-gate 	struct scsi_device	*un_sd;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	/*
2410Sstevel@tonic-gate 	 * Support for Auto-Request sense capability
2420Sstevel@tonic-gate 	 */
2430Sstevel@tonic-gate 	struct buf	*un_rqs_bp;	/* ptr to request sense bp */
2440Sstevel@tonic-gate 	struct scsi_pkt	*un_rqs_pktp;	/* ptr to request sense scsi_pkt */
2450Sstevel@tonic-gate 	int	un_sense_isbusy;	/* Busy flag for RQS buf */
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	/*
2480Sstevel@tonic-gate 	 * These specify the layering chains to use with this instance. These
2490Sstevel@tonic-gate 	 * are initialized according to the values in the sd_chain_index_map[]
2500Sstevel@tonic-gate 	 * array. See the description of sd_chain_index_map[] for details.
2510Sstevel@tonic-gate 	 */
2520Sstevel@tonic-gate 	int un_buf_chain_type;
2530Sstevel@tonic-gate 	int un_uscsi_chain_type;
2540Sstevel@tonic-gate 	int un_direct_chain_type;
2550Sstevel@tonic-gate 	int un_priority_chain_type;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/* Head & tail ptrs to the queue of bufs awaiting transport */
2580Sstevel@tonic-gate 	struct buf	*un_waitq_headp;
2590Sstevel@tonic-gate 	struct buf	*un_waitq_tailp;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	/* Ptr to the buf currently being retried (NULL if none) */
2620Sstevel@tonic-gate 	struct buf	*un_retry_bp;
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	/* This tracks the last kstat update for the un_retry_bp buf */
2650Sstevel@tonic-gate 	void		(*un_retry_statp)(kstat_io_t *);
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	void		*un_xbuf_attr;	/* xbuf attribute struct */
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	/* System logical block size, in bytes. (defaults to DEV_BSIZE.) */
2710Sstevel@tonic-gate 	uint32_t	un_sys_blocksize;
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	/* The size of a logical block on the target, in bytes. */
2740Sstevel@tonic-gate 	uint32_t	un_tgt_blocksize;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	/*
2770Sstevel@tonic-gate 	 * The number of logical blocks on the target. This is adjusted
2780Sstevel@tonic-gate 	 * to be in terms of the block size specified by un_sys_blocksize
2790Sstevel@tonic-gate 	 * (ie, the system block size).
2800Sstevel@tonic-gate 	 */
2810Sstevel@tonic-gate 	uint64_t	un_blockcount;
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	/*
2840Sstevel@tonic-gate 	 * Various configuration data
2850Sstevel@tonic-gate 	 */
2860Sstevel@tonic-gate 	uchar_t	un_ctype;		/* Controller type */
2870Sstevel@tonic-gate 	char 	*un_node_type;		/* minor node type */
2880Sstevel@tonic-gate 	uchar_t	un_interconnect_type;	/* Interconnect for underlying HBA */
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	uint_t	un_notready_retry_count; /* Per disk notready retry count */
2910Sstevel@tonic-gate 	uint_t	un_busy_retry_count;	/* Per disk BUSY retry count */
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	uint_t	un_retry_count;		/* Per disk retry count */
2940Sstevel@tonic-gate 	uint_t	un_victim_retry_count;	/* Per disk victim retry count */
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate 	/* (4356701, 4367306) */
2970Sstevel@tonic-gate 	uint_t	un_reset_retry_count; /* max io retries before issuing reset */
2980Sstevel@tonic-gate 	ushort_t un_reserve_release_time; /* reservation release timeout */
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	uchar_t	un_reservation_type;	/* SCSI-3 or SCSI-2 */
3010Sstevel@tonic-gate 	uint_t	un_max_xfer_size;	/* Maximum DMA transfer size */
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 	int	un_mincdb;		/* Smallest CDB to use */
3040Sstevel@tonic-gate 	int	un_maxcdb;		/* Largest CDB to use */
3050Sstevel@tonic-gate 	int	un_status_len;
3060Sstevel@tonic-gate 	int	un_pkt_flags;
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	/*
3090Sstevel@tonic-gate 	 * Note: un_uscsi_timeout is a "mirror" of un_cmd_timeout, adjusted
3100Sstevel@tonic-gate 	 * for ISCD().  Any updates to un_cmd_timeout MUST be reflected
3110Sstevel@tonic-gate 	 * in un_uscsi_timeout as well!
3120Sstevel@tonic-gate 	 */
3130Sstevel@tonic-gate 	ushort_t un_cmd_timeout;	/* Timeout for completion */
3140Sstevel@tonic-gate 	ushort_t un_uscsi_timeout;	/* Timeout for USCSI completion */
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 	/*
3170Sstevel@tonic-gate 	 * Info on current states, statuses, etc. (Updated frequently)
3180Sstevel@tonic-gate 	 */
3190Sstevel@tonic-gate 	uchar_t	un_state;		/* current state */
3200Sstevel@tonic-gate 	uchar_t	un_last_state;		/* last state */
3210Sstevel@tonic-gate 	uchar_t	un_last_pkt_reason;	/* used to suppress multiple msgs */
3220Sstevel@tonic-gate 	int	un_tagflags;		/* Pkt Flags for Tagged Queueing  */
3230Sstevel@tonic-gate 	short	un_resvd_status;	/* Reservation Status */
3240Sstevel@tonic-gate 	ulong_t	un_detach_count;	/* !0 if executing detach routine */
3250Sstevel@tonic-gate 	ulong_t	un_layer_count;		/* Current total # of layered opens */
3260Sstevel@tonic-gate 	ulong_t un_opens_in_progress;	/* Current # of threads in sdopen */
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	ksema_t	un_semoclose;		/* serialize opens/closes */
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	/*
3310Sstevel@tonic-gate 	 * Control & status info for command throttling
3320Sstevel@tonic-gate 	 */
3330Sstevel@tonic-gate 	long	un_ncmds_in_driver;	/* number of cmds in driver */
3340Sstevel@tonic-gate 	short	un_ncmds_in_transport;	/* number of cmds in transport */
3350Sstevel@tonic-gate 	short	un_throttle;		/* max #cmds allowed in transport */
3360Sstevel@tonic-gate 	short	un_saved_throttle;	/* saved value of un_throttle */
3370Sstevel@tonic-gate 	short	un_busy_throttle;	/* saved un_throttle for BUSY */
3380Sstevel@tonic-gate 	short	un_min_throttle;	/* min value of un_throttle */
3390Sstevel@tonic-gate 	timeout_id_t	un_reset_throttle_timeid; /* timeout(9F) handle */
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 	/*
3420Sstevel@tonic-gate 	 * Multi-host (clustering) support
3430Sstevel@tonic-gate 	 */
3440Sstevel@tonic-gate 	opaque_t	un_mhd_token;		/* scsi watch request */
3450Sstevel@tonic-gate 	timeout_id_t	un_resvd_timeid;	/* for resvd recover */
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 	/* Event callback resources (photon) */
3480Sstevel@tonic-gate 	ddi_eventcookie_t un_insert_event;	/* insert event */
3490Sstevel@tonic-gate 	ddi_callback_id_t un_insert_cb_id;	/* insert callback */
3500Sstevel@tonic-gate 	ddi_eventcookie_t un_remove_event;	/* remove event */
3510Sstevel@tonic-gate 	ddi_callback_id_t un_remove_cb_id;	/* remove callback */
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 	uint_t		un_start_stop_cycle_page;	/* Saves start/stop */
3540Sstevel@tonic-gate 							/* cycle page */
3550Sstevel@tonic-gate 	timeout_id_t	un_dcvb_timeid;		/* dlyd cv broadcast */
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	/*
3580Sstevel@tonic-gate 	 * Data structures for open counts, partition info, VTOC,
3590Sstevel@tonic-gate 	 * stats, and other such bookkeeping info.
3600Sstevel@tonic-gate 	 */
3610Sstevel@tonic-gate 	union	ocmap	un_ocmap;		/* open partition map */
3620Sstevel@tonic-gate 	struct	dk_map	un_map[MAXPART];	/* logical partitions */
3630Sstevel@tonic-gate 	diskaddr_t	un_offset[MAXPART];	/* partition start blocks */
3640Sstevel@tonic-gate 	struct	kstat	*un_pstats[NSDMAP];	/* partition statistics */
3650Sstevel@tonic-gate 	struct	dk_vtoc un_vtoc;		/* disk VTOC */
3660Sstevel@tonic-gate 	struct	dk_geom un_g;			/* disk geometry */
3670Sstevel@tonic-gate 	struct	kstat	*un_stats;		/* disk statistics */
3680Sstevel@tonic-gate 	kstat_t		*un_errstats;		/* for error statistics */
369433Sgz161490 	uint64_t	un_exclopen;		/* exclusive open bitmask */
3700Sstevel@tonic-gate 	ddi_devid_t	un_devid;		/* device id */
3710Sstevel@tonic-gate 	uint_t		un_vpd_page_mask;	/* Supported VPD pages */
3720Sstevel@tonic-gate 	uchar_t		un_asciilabel[LEN_DKL_ASCII];	/* Disk ASCII label */
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	/*
3750Sstevel@tonic-gate 	 * Support for drives with 'fdisk' type partitions. (See fdisk.h)
3760Sstevel@tonic-gate 	 *
3770Sstevel@tonic-gate 	 * On a drive with an fdisk-type of partition table, un_blockcount
3780Sstevel@tonic-gate 	 * will specify the size of the entire disk, and un_solaris_size
3790Sstevel@tonic-gate 	 * denotes the size of the fdisk partition where Solaris resides.
3800Sstevel@tonic-gate 	 * Also un_solaris_offset specifies the offset from block 0 on the
3810Sstevel@tonic-gate 	 * drive to the first block of the Solaris partiton.
3820Sstevel@tonic-gate 	 *
3830Sstevel@tonic-gate 	 * If the disk does not have an fdisk partition table, then
3840Sstevel@tonic-gate 	 * un_blockcount and un_solaris_size should be identical.
3850Sstevel@tonic-gate 	 *
3860Sstevel@tonic-gate 	 * Note that under this scheme, only a single active Solaris
3870Sstevel@tonic-gate 	 * partition can be supported at any one time.
3880Sstevel@tonic-gate 	 */
3890Sstevel@tonic-gate 	daddr_t		un_solaris_size;	/* size of Solaris partition */
3900Sstevel@tonic-gate 	uint_t		un_solaris_offset;	/* offset to Solaris part. */
3910Sstevel@tonic-gate 	ushort_t	un_dkg_skew;		/* skew */
3920Sstevel@tonic-gate 	struct fmap	un_fmap[FD_NUMPART];	/* fdisk partitions */
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	/*
3950Sstevel@tonic-gate 	 * This is the HBAs current notion of the geometry of the drive,
3960Sstevel@tonic-gate 	 * for HBAs that support the "geometry" property.
3970Sstevel@tonic-gate 	 */
3980Sstevel@tonic-gate 	struct geom_cache	un_lgeom;
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 	/*
4010Sstevel@tonic-gate 	 * This is the geometry of the device as reported by the MODE SENSE,
4020Sstevel@tonic-gate 	 * command, Page 3 (Format Device Page) and Page 4 (Rigid Disk Drive
4030Sstevel@tonic-gate 	 * Geometry Page), assuming MODE SENSE is supported by the target.
4040Sstevel@tonic-gate 	 */
4050Sstevel@tonic-gate 	struct geom_cache	un_pgeom;
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate 	/*
4080Sstevel@tonic-gate 	 * Bit fields for various configuration/state/status info.
4090Sstevel@tonic-gate 	 * Comments indicate the condition if the value of the
410173Scth 	 * variable is TRUE (nonzero).
4110Sstevel@tonic-gate 	 */
4120Sstevel@tonic-gate 	uint32_t
4130Sstevel@tonic-gate 	    un_f_arq_enabled		:1,	/* Auto request sense is */
4140Sstevel@tonic-gate 						/* currently enabled */
4150Sstevel@tonic-gate 	    un_f_blockcount_is_valid	:1,	/* The un_blockcount */
4160Sstevel@tonic-gate 						/* value is currently valid */
4170Sstevel@tonic-gate 	    un_f_tgt_blocksize_is_valid	:1,	/* The un_tgt_blocksize */
4180Sstevel@tonic-gate 						/* value is currently valid */
4190Sstevel@tonic-gate 	    un_f_geometry_is_valid	:1,	/* The geometry of the */
4200Sstevel@tonic-gate 						/* target is currently valid */
4210Sstevel@tonic-gate 	    un_f_allow_bus_device_reset	:1,	/* Driver may issue a BDR as */
4220Sstevel@tonic-gate 						/* a part of error recovery. */
4230Sstevel@tonic-gate 	    un_f_is_fibre		:1,	/* The device supports fibre */
4240Sstevel@tonic-gate 						/* channel */
4250Sstevel@tonic-gate 	    un_f_available		:1,	/* Not use */
4260Sstevel@tonic-gate 						/* available */
4270Sstevel@tonic-gate 	    un_f_format_in_progress	:1,	/* The device is currently */
4280Sstevel@tonic-gate 						/* executing a FORMAT cmd. */
4290Sstevel@tonic-gate 	    un_f_opt_queueing		:1,	/* Enable Command Queuing to */
4300Sstevel@tonic-gate 						/* Host Adapter */
4310Sstevel@tonic-gate 	    un_f_opt_fab_devid		:1,	/* Disk has no valid/unique */
4320Sstevel@tonic-gate 						/* serial number.  */
4330Sstevel@tonic-gate 	    un_f_opt_disable_cache	:1,	/* Read/Write disk cache is */
4340Sstevel@tonic-gate 						/* disabled.  */
4350Sstevel@tonic-gate 	    un_f_cfg_is_atapi		:1,	/* This is an ATAPI device.  */
4360Sstevel@tonic-gate 	    un_f_cfg_obsolete		:1,	/* available for reuse  */
4370Sstevel@tonic-gate 	    un_f_cfg_playmsf_bcd	:1,	/* Play Audio, BCD params. */
4380Sstevel@tonic-gate 	    un_f_cfg_readsub_bcd	:1,	/* READ SUBCHANNEL BCD resp. */
4390Sstevel@tonic-gate 	    un_f_cfg_read_toc_trk_bcd	:1,	/* track # is BCD */
4400Sstevel@tonic-gate 	    un_f_cfg_read_toc_addr_bcd	:1,	/* address is BCD */
4410Sstevel@tonic-gate 	    un_f_cfg_no_read_header	:1,	/* READ HEADER not supported */
4420Sstevel@tonic-gate 	    un_f_cfg_read_cd_xd4	:1,	/* READ CD opcode is 0xd4 */
4430Sstevel@tonic-gate 	    un_f_mmc_cap		:1,	/* Device is MMC compliant */
4440Sstevel@tonic-gate 	    un_f_mmc_writable_media	:1,	/* writable media in device */
4450Sstevel@tonic-gate 	    un_f_dvdram_writable_device	:1,	/* DVDRAM device is writable */
4460Sstevel@tonic-gate 	    un_f_cfg_cdda		:1,	/* READ CDDA supported */
4470Sstevel@tonic-gate 	    un_f_cfg_tur_check		:1,	/* verify un_ncmds before tur */
4480Sstevel@tonic-gate 
4490Sstevel@tonic-gate 	    un_f_use_adaptive_throttle	:1,	/* enable/disable adaptive */
4500Sstevel@tonic-gate 						/* throttling */
4510Sstevel@tonic-gate 	    un_f_pm_is_enabled		:1,	/* PM is enabled on this */
4520Sstevel@tonic-gate 						/* instance */
4530Sstevel@tonic-gate 	    un_f_watcht_stopped		:1,	/* media watch thread flag */
4540Sstevel@tonic-gate 	    un_f_pkstats_enabled	:1,	/* Flag to determine if */
4550Sstevel@tonic-gate 						/* partition kstats are */
4560Sstevel@tonic-gate 						/* enabled. */
4570Sstevel@tonic-gate 	    un_f_disksort_disabled	:1,	/* Flag to disable disksort */
4580Sstevel@tonic-gate 	    un_f_lun_reset_enabled	:1,	/* Set if target supports */
4590Sstevel@tonic-gate 						/* SCSI Logical Unit Reset */
4600Sstevel@tonic-gate 	    un_f_doorlock_supported	:1,	/* Device supports Doorlock */
4610Sstevel@tonic-gate 	    un_f_start_stop_supported	:1;	/* device has motor */
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	/* Ptr to table of strings for ASC/ASCQ error message printing */
4650Sstevel@tonic-gate 	struct scsi_asq_key_strings	*un_additional_codes;
4660Sstevel@tonic-gate 
4670Sstevel@tonic-gate 	/*
4680Sstevel@tonic-gate 	 * Power Management support.
4690Sstevel@tonic-gate 	 *
4700Sstevel@tonic-gate 	 * un_pm_mutex protects, un_pm_count, un_pm_timeid, un_pm_busy,
4710Sstevel@tonic-gate 	 * un_pm_busy_cv, and un_pm_idle_timeid.
4720Sstevel@tonic-gate 	 * It's not required that SD_MUTEX be acquired before acquiring
4730Sstevel@tonic-gate 	 * un_pm_mutex, however if they must both be held
4740Sstevel@tonic-gate 	 * then acquire SD_MUTEX first.
4750Sstevel@tonic-gate 	 *
4760Sstevel@tonic-gate 	 * un_pm_count is used to indicate PM state as follows:
4770Sstevel@tonic-gate 	 *	less than 0 the device is powered down,
4780Sstevel@tonic-gate 	 *	transition from 0 ==> 1, mark the device as busy via DDI
4790Sstevel@tonic-gate 	 *	transition from 1 ==> 0, mark the device as idle via DDI
4800Sstevel@tonic-gate 	 */
4810Sstevel@tonic-gate 	kmutex_t	un_pm_mutex;
4820Sstevel@tonic-gate 	int		un_pm_count;		/* indicates pm state */
4830Sstevel@tonic-gate 	timeout_id_t	un_pm_timeid;		/* timeout id for pm */
4840Sstevel@tonic-gate 	uint_t		un_pm_busy;
4850Sstevel@tonic-gate 	kcondvar_t	un_pm_busy_cv;
4860Sstevel@tonic-gate 	int		un_pm_capable_prop;	/* "pm-capable" prop value */
4870Sstevel@tonic-gate 	short		un_power_level;		/* Power Level */
4880Sstevel@tonic-gate 	uchar_t		un_save_state;
4890Sstevel@tonic-gate 	kcondvar_t	un_suspend_cv;		/* power management */
4900Sstevel@tonic-gate 	kcondvar_t	un_disk_busy_cv;	/* wait for IO completion */
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	/* Resources used for media change callback support */
4930Sstevel@tonic-gate 	kcondvar_t	un_state_cv;		/* Cond Var on mediastate */
4940Sstevel@tonic-gate 	enum dkio_state un_mediastate;		/* current media state */
4950Sstevel@tonic-gate 	enum dkio_state un_specified_mediastate; /* expected state */
4960Sstevel@tonic-gate 	opaque_t	un_swr_token;		/* scsi_watch request token */
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate 	/* Non-512 byte block support */
4990Sstevel@tonic-gate 	struct kmem_cache *un_wm_cache;	/* fast alloc in non-512 write case */
5000Sstevel@tonic-gate 	uint_t		un_rmw_count;	/* count of read-modify-writes */
5010Sstevel@tonic-gate 	struct sd_w_map	*un_wm;		/* head of sd_w_map chain */
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 	/* For timeout callback to issue a START STOP UNIT command */
5040Sstevel@tonic-gate 	timeout_id_t	un_startstop_timeid;
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 	/* Timeout callback handle for SD_PATH_DIRECT_PRIORITY cmd restarts */
5070Sstevel@tonic-gate 	timeout_id_t	un_direct_priority_timeid;
5080Sstevel@tonic-gate 
5090Sstevel@tonic-gate 	/* TRAN_FATAL_ERROR count. Cleared by TRAN_ACCEPT from scsi_transport */
5100Sstevel@tonic-gate 	ulong_t		un_tran_fatal_count;
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate 	timeout_id_t	un_retry_timeid;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	time_t		un_pm_idle_time;
5150Sstevel@tonic-gate 	timeout_id_t	un_pm_idle_timeid;
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 	/*
5180Sstevel@tonic-gate 	 * Count to determine if a Sonoma controller is in the process of
5190Sstevel@tonic-gate 	 * failing over, and how many I/O's are failed with the 05/94/01
5200Sstevel@tonic-gate 	 * sense code.
5210Sstevel@tonic-gate 	 */
5220Sstevel@tonic-gate 	uint_t		un_sonoma_failure_count;
5230Sstevel@tonic-gate 	int		un_reserved;	/* reserved partition # */
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate 	/*
5260Sstevel@tonic-gate 	 * Support for failfast operation.
5270Sstevel@tonic-gate 	 */
5280Sstevel@tonic-gate 	struct buf	*un_failfast_bp;
5290Sstevel@tonic-gate 	struct buf	*un_failfast_headp;
5300Sstevel@tonic-gate 	struct buf	*un_failfast_tailp;
5310Sstevel@tonic-gate 	uint32_t	un_failfast_state;
5320Sstevel@tonic-gate 	/* Callback routine active counter */
5330Sstevel@tonic-gate 	short		un_in_callback;
5340Sstevel@tonic-gate 
535313Sts143224 	/*
536313Sts143224 	 * Another bit fields for various configuration/state/status info.
537313Sts143224 	 * Comments indicate the condition if the value of the
538313Sts143224 	 * variable is TRUE (nonzero).
539313Sts143224 	 */
540313Sts143224 	uint32_t
541313Sts143224 		un_f_cfg_is_lsi	:1,	/* Is LSI device, default to NO */
542313Sts143224 		un_f_pad_uint32	:1;	/* padding, 31 bits available */
543313Sts143224 
5440Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
5450Sstevel@tonic-gate 	/* SD Fault Injection */
5460Sstevel@tonic-gate #define	SD_FI_MAX_BUF 65536
5470Sstevel@tonic-gate #define	SD_FI_MAX_ERROR 1024
5480Sstevel@tonic-gate 	kmutex_t			un_fi_mutex;
5490Sstevel@tonic-gate 	uint_t				sd_fi_buf_len;
5500Sstevel@tonic-gate 	char				sd_fi_log[SD_FI_MAX_BUF];
5510Sstevel@tonic-gate 	struct sd_fi_pkt	*sd_fi_fifo_pkt[SD_FI_MAX_ERROR];
5520Sstevel@tonic-gate 	struct sd_fi_xb		*sd_fi_fifo_xb[SD_FI_MAX_ERROR];
5530Sstevel@tonic-gate 	struct sd_fi_un		*sd_fi_fifo_un[SD_FI_MAX_ERROR];
5540Sstevel@tonic-gate 	struct sd_fi_arq	*sd_fi_fifo_arq[SD_FI_MAX_ERROR];
5550Sstevel@tonic-gate 	uint_t				sd_fi_fifo_start;
5560Sstevel@tonic-gate 	uint_t				sd_fi_fifo_end;
5570Sstevel@tonic-gate 	uint_t				sd_injection_mask;
5580Sstevel@tonic-gate #endif
5590Sstevel@tonic-gate 
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate };
5620Sstevel@tonic-gate 
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate /*
5650Sstevel@tonic-gate  * Macros for conversions between "target" and "system" block sizes, and
5660Sstevel@tonic-gate  * for conversion between block counts and byte counts.  As used here,
5670Sstevel@tonic-gate  * "system" block size refers to the block size used by the kernel/
5680Sstevel@tonic-gate  * filesystem (this includes the disk label). The "target" block size
569173Scth  * is the block size returned by the SCSI READ CAPACITY command.
5700Sstevel@tonic-gate  *
5710Sstevel@tonic-gate  * Note: These macros will round up to the next largest blocksize to accomodate
5720Sstevel@tonic-gate  * the number of blocks specified.
5730Sstevel@tonic-gate  */
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate /* Convert a byte count to a number of target blocks */
5760Sstevel@tonic-gate #define	SD_BYTES2TGTBLOCKS(un, bytecount)				\
5770Sstevel@tonic-gate 	((bytecount + (un->un_tgt_blocksize - 1))/un->un_tgt_blocksize)
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate /* Convert a target block count to a number of bytes */
5800Sstevel@tonic-gate #define	SD_TGTBLOCKS2BYTES(un, blockcount)				\
5810Sstevel@tonic-gate 	(blockcount * (un)->un_tgt_blocksize)
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate /* Convert a byte count to a number of system blocks */
5840Sstevel@tonic-gate #define	SD_BYTES2SYSBLOCKS(un, bytecount)				\
5850Sstevel@tonic-gate 	((bytecount + (un->un_sys_blocksize - 1))/un->un_sys_blocksize)
5860Sstevel@tonic-gate 
5870Sstevel@tonic-gate /* Convert a system block count to a number of bytes */
5880Sstevel@tonic-gate #define	SD_SYSBLOCKS2BYTES(un, blockcount)				\
5890Sstevel@tonic-gate 	(blockcount * (un)->un_sys_blocksize)
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate /*
5920Sstevel@tonic-gate  * Calculate the number of bytes needed to hold the requested number of bytes
5930Sstevel@tonic-gate  * based upon the native target sector/block size
5940Sstevel@tonic-gate  */
5950Sstevel@tonic-gate #define	SD_REQBYTES2TGTBYTES(un, bytecount)				\
5960Sstevel@tonic-gate 	(SD_BYTES2TGTBLOCKS(un, bytecount) * (un)->un_tgt_blocksize)
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate /*
5990Sstevel@tonic-gate  * Calculate the byte offset from the beginning of the target block
6000Sstevel@tonic-gate  * to the system block location.
6010Sstevel@tonic-gate  */
6020Sstevel@tonic-gate #define	SD_TGTBYTEOFFSET(un, sysblk, tgtblk)				\
6030Sstevel@tonic-gate 	(SD_SYSBLOCKS2BYTES(un, sysblk) - SD_TGTBLOCKS2BYTES(un, tgtblk))
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate  * Calculate the target block location from the system block location
6070Sstevel@tonic-gate  */
6080Sstevel@tonic-gate #define	SD_SYS2TGTBLOCK(un, blockcnt)					\
6090Sstevel@tonic-gate 	((blockcnt * un->un_sys_blocksize) / un->un_tgt_blocksize)
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate  * SD_DEFAULT_MAX_XFER_SIZE is the default value to bound the max xfer
6130Sstevel@tonic-gate  * for physio, for devices without tagged queuing enabled.
6140Sstevel@tonic-gate  * The default for devices with tagged queuing enabled is SD_MAX_XFER_SIZE
6150Sstevel@tonic-gate  */
6160Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
6170Sstevel@tonic-gate #define	SD_DEFAULT_MAX_XFER_SIZE	(256 * 1024)
6180Sstevel@tonic-gate #endif
6190Sstevel@tonic-gate #define	SD_MAX_XFER_SIZE		(1024 * 1024)
6200Sstevel@tonic-gate 
6210Sstevel@tonic-gate 
6220Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
6230Sstevel@tonic-gate #ifndef _lock_lint
6240Sstevel@tonic-gate #undef _NOTE
6250Sstevel@tonic-gate #define	_NOTE(s)
6260Sstevel@tonic-gate #endif
6270Sstevel@tonic-gate #endif
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 
6300Sstevel@tonic-gate /*
6310Sstevel@tonic-gate  * Warlock annotations
6320Sstevel@tonic-gate  */
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_lun))
6350Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(sd_lun::un_sd))
6360Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_reservation_type))
637*609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_pm_capable_prop))
638*609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_mincdb))
639*609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_maxcdb))
640*609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_status_len))
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
6440Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(sd_lun::un_f_arq_enabled))
6450Sstevel@tonic-gate #else
6460Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_f_arq_enabled))
6470Sstevel@tonic-gate #endif
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_ctype))
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("safe sharing",
6520Sstevel@tonic-gate 	sd_lun::un_mhd_token
6530Sstevel@tonic-gate 	sd_lun::un_state
6540Sstevel@tonic-gate 	sd_lun::un_tagflags
6550Sstevel@tonic-gate 	sd_lun::un_f_format_in_progress
6560Sstevel@tonic-gate 	sd_lun::un_f_geometry_is_valid
6570Sstevel@tonic-gate 	sd_lun::un_resvd_timeid
6580Sstevel@tonic-gate 	sd_lun::un_reset_throttle_timeid
6590Sstevel@tonic-gate 	sd_lun::un_startstop_timeid
6600Sstevel@tonic-gate 	sd_lun::un_dcvb_timeid
6610Sstevel@tonic-gate 	sd_lun::un_f_allow_bus_device_reset
6620Sstevel@tonic-gate 	sd_lun::un_sys_blocksize
6630Sstevel@tonic-gate 	sd_lun::un_tgt_blocksize))
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data",
6660Sstevel@tonic-gate 	sd_lun::un_reserve_release_time
6670Sstevel@tonic-gate 	sd_lun::un_max_xfer_size
6680Sstevel@tonic-gate 	sd_lun::un_offset
6690Sstevel@tonic-gate 	sd_lun::un_map
6700Sstevel@tonic-gate 	sd_lun::un_f_is_fibre
6710Sstevel@tonic-gate 	sd_lun::un_node_type
6720Sstevel@tonic-gate 	sd_lun::un_buf_chain_type
6730Sstevel@tonic-gate 	sd_lun::un_uscsi_chain_type
6740Sstevel@tonic-gate 	sd_lun::un_direct_chain_type
6750Sstevel@tonic-gate 	sd_lun::un_priority_chain_type
6760Sstevel@tonic-gate 	sd_lun::un_xbuf_attr))
6770Sstevel@tonic-gate 
6780Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data",
6790Sstevel@tonic-gate 	block_descriptor
6800Sstevel@tonic-gate 	buf
6810Sstevel@tonic-gate 	cdrom_subchnl
6820Sstevel@tonic-gate 	cdrom_tocentry
6830Sstevel@tonic-gate 	cdrom_tochdr
6840Sstevel@tonic-gate 	cdrom_read
6850Sstevel@tonic-gate 	dk_cinfo
6860Sstevel@tonic-gate 	dk_devid
6870Sstevel@tonic-gate 	dk_geom
6880Sstevel@tonic-gate 	dk_label
6890Sstevel@tonic-gate 	dk_map
6900Sstevel@tonic-gate 	dk_temperature
6910Sstevel@tonic-gate 	geom_cache
6920Sstevel@tonic-gate 	mhioc_inkeys
6930Sstevel@tonic-gate 	mhioc_inresvs
6940Sstevel@tonic-gate 	mode_header
6950Sstevel@tonic-gate 	mode_speed
6960Sstevel@tonic-gate 	scsi_cdb
6970Sstevel@tonic-gate 	scsi_arq_status
6980Sstevel@tonic-gate 	scsi_extended_sense
6990Sstevel@tonic-gate 	scsi_inquiry
7000Sstevel@tonic-gate 	scsi_pkt
7010Sstevel@tonic-gate 	uio
7020Sstevel@tonic-gate 	uscsi_cmd))
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device dk_cinfo))
7060Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", scsi_status scsi_cdb))
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_pm_mutex, sd_lun::un_pm_count
7090Sstevel@tonic-gate 	sd_lun::un_pm_timeid sd_lun::un_pm_busy sd_lun::un_pm_busy_cv
7100Sstevel@tonic-gate 	sd_lun::un_pm_idle_timeid))
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
7130Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_fi_mutex,
7140Sstevel@tonic-gate 	sd_lun::sd_fi_buf_len sd_lun::sd_fi_log))
7150Sstevel@tonic-gate #endif
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate /* _NOTE(LOCK_ORDER(sd_lun::un_sd.sd_mutex sd_lun::un_pm_mutex)) */
7180Sstevel@tonic-gate 
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate /*
7220Sstevel@tonic-gate  * Referenced for frequently-accessed members of the unit structure
7230Sstevel@tonic-gate  */
7240Sstevel@tonic-gate #define	SD_SCSI_DEVP(un)	((un)->un_sd)
7250Sstevel@tonic-gate #define	SD_DEVINFO(un)		((un)->un_sd->sd_dev)
7260Sstevel@tonic-gate #define	SD_INQUIRY(un)		((un)->un_sd->sd_inq)
7270Sstevel@tonic-gate #define	SD_MUTEX(un)		(&((un)->un_sd->sd_mutex))
7280Sstevel@tonic-gate #define	SD_ADDRESS(un)		(&((un)->un_sd->sd_address))
7290Sstevel@tonic-gate #define	SD_GET_DEV(un)		(sd_make_device(SD_DEVINFO(un)))
7300Sstevel@tonic-gate 
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate /*
7330Sstevel@tonic-gate  * Values for un_ctype
7340Sstevel@tonic-gate  */
7350Sstevel@tonic-gate #define	CTYPE_CDROM		0
7360Sstevel@tonic-gate #define	CTYPE_MD21		1	/* Obsolete! */
7370Sstevel@tonic-gate #define	CTYPE_CCS		2
7380Sstevel@tonic-gate #define	CTYPE_ROD		3
7390Sstevel@tonic-gate #define	CTYPE_PXRE		4	/* Obsolete! */
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate #define	ISCD(un)		((un)->un_ctype == CTYPE_CDROM)
7420Sstevel@tonic-gate #define	ISROD(un)		((un)->un_ctype == CTYPE_ROD)
7430Sstevel@tonic-gate #define	ISPXRE(un)		((un)->un_ctype == CTYPE_PXRE)
7440Sstevel@tonic-gate #define	ISREMOVABLE(un)		(ISCD(un) || (un)->un_sd->sd_inq->inq_rmb)
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate /*
7470Sstevel@tonic-gate  * This macro checks the vendor of the device to see if it is LSI. Because
7480Sstevel@tonic-gate  * LSI has some devices out there that return 'Symbios' or 'SYMBIOS', we
7490Sstevel@tonic-gate  * need to check for those also.
7500Sstevel@tonic-gate  *
7510Sstevel@tonic-gate  * This is used in some vendor specific checks.
7520Sstevel@tonic-gate  */
753313Sts143224 #define	SD_IS_LSI(un)	((un)->un_f_cfg_is_lsi == TRUE)
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate /*
7560Sstevel@tonic-gate  * Macros to check if the lun is a Sun T3 or a T4
7570Sstevel@tonic-gate  */
7580Sstevel@tonic-gate #define	SD_IS_T3(un) \
7590Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7600Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T3", 2) == 0))
7610Sstevel@tonic-gate 
7620Sstevel@tonic-gate #define	SD_IS_T4(un) \
7630Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7640Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T4", 2) == 0))
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate /*
7670Sstevel@tonic-gate  * Macros for non-512 byte writes to removable devices.
7680Sstevel@tonic-gate  */
7690Sstevel@tonic-gate #define	NOT_DEVBSIZE(un)	\
7700Sstevel@tonic-gate 	(ISREMOVABLE(un) && ((un)->un_tgt_blocksize != (un)->un_sys_blocksize))
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate /*
7730Sstevel@tonic-gate  * Check that a write map, used for locking lba ranges for writes, is in
7740Sstevel@tonic-gate  * the linked list.
7750Sstevel@tonic-gate  */
7760Sstevel@tonic-gate #define	ONLIST(un, wmp)		\
7770Sstevel@tonic-gate 	(((un)->un_wm == (wmp)) || ((wmp)->wm_prev != NULL))
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate /*
7800Sstevel@tonic-gate  * Free a write map which is on list. Basically make sure that nobody is
7810Sstevel@tonic-gate  * sleeping on it before freeing it.
7820Sstevel@tonic-gate  */
7830Sstevel@tonic-gate #define	FREE_ONLIST_WMAP(un, wmp)				\
7840Sstevel@tonic-gate 	if (!(wmp)->wm_wanted_count) {				\
7850Sstevel@tonic-gate 		sd_free_inlist_wmap((un), (wmp));		\
7860Sstevel@tonic-gate 		(wmp) = NULL;					\
7870Sstevel@tonic-gate 	}
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate #define	CHK_N_FREEWMP(un, wmp)					\
7900Sstevel@tonic-gate 	if (!ONLIST((un), (wmp))) {				\
7910Sstevel@tonic-gate 		kmem_cache_free((un)->un_wm_cache, (wmp));	\
7920Sstevel@tonic-gate 		(wmp) = NULL;					\
7930Sstevel@tonic-gate 	} else {						\
7940Sstevel@tonic-gate 		FREE_ONLIST_WMAP((un), (wmp));			\
7950Sstevel@tonic-gate 	}
7960Sstevel@tonic-gate 
7970Sstevel@tonic-gate /*
7980Sstevel@tonic-gate  * Values used to in wm_flags field of sd_w_map.
7990Sstevel@tonic-gate  */
8000Sstevel@tonic-gate #define	SD_WTYPE_SIMPLE	0x001	/* Write aligned at blksize boundary */
8010Sstevel@tonic-gate #define	SD_WTYPE_RMW	0x002	/* Write requires read-modify-write */
8020Sstevel@tonic-gate #define	SD_WM_BUSY		0x100	/* write-map is busy */
8030Sstevel@tonic-gate 
8040Sstevel@tonic-gate 
8050Sstevel@tonic-gate /* Device error kstats */
8060Sstevel@tonic-gate struct sd_errstats {
8070Sstevel@tonic-gate 	struct kstat_named	sd_softerrs;
8080Sstevel@tonic-gate 	struct kstat_named	sd_harderrs;
8090Sstevel@tonic-gate 	struct kstat_named	sd_transerrs;
8100Sstevel@tonic-gate 	struct kstat_named	sd_vid;
8110Sstevel@tonic-gate 	struct kstat_named	sd_pid;
8120Sstevel@tonic-gate 	struct kstat_named	sd_revision;
8130Sstevel@tonic-gate 	struct kstat_named	sd_serial;
8140Sstevel@tonic-gate 	struct kstat_named	sd_capacity;
8150Sstevel@tonic-gate 	struct kstat_named	sd_rq_media_err;
8160Sstevel@tonic-gate 	struct kstat_named	sd_rq_ntrdy_err;
8170Sstevel@tonic-gate 	struct kstat_named	sd_rq_nodev_err;
8180Sstevel@tonic-gate 	struct kstat_named	sd_rq_recov_err;
8190Sstevel@tonic-gate 	struct kstat_named	sd_rq_illrq_err;
8200Sstevel@tonic-gate 	struct kstat_named	sd_rq_pfa_err;
8210Sstevel@tonic-gate };
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 
8240Sstevel@tonic-gate /*
8250Sstevel@tonic-gate  * Structs and definitions for SCSI-3 Persistent Reservation
8260Sstevel@tonic-gate  */
8270Sstevel@tonic-gate typedef struct sd_prin_readkeys {
8280Sstevel@tonic-gate 	uint32_t	generation;
8290Sstevel@tonic-gate 	uint32_t	len;
8300Sstevel@tonic-gate 	mhioc_resv_key_t *keylist;
8310Sstevel@tonic-gate } sd_prin_readkeys_t;
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate typedef struct sd_readresv_desc {
8340Sstevel@tonic-gate 	mhioc_resv_key_t	resvkey;
8350Sstevel@tonic-gate 	uint32_t		scope_specific_addr;
8360Sstevel@tonic-gate 	uint8_t			reserved_1;
8370Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8380Sstevel@tonic-gate 	uint8_t			type:4,
8390Sstevel@tonic-gate 				scope:4;
8400Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8410Sstevel@tonic-gate 	uint8_t			scope:4,
8420Sstevel@tonic-gate 				type:4;
8430Sstevel@tonic-gate #else
8440Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8450Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8460Sstevel@tonic-gate 	uint8_t			reserved_2;
8470Sstevel@tonic-gate 	uint8_t			reserved_3;
8480Sstevel@tonic-gate } sd_readresv_desc_t;
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate typedef struct sd_prin_readresv {
8510Sstevel@tonic-gate 	uint32_t		generation;
8520Sstevel@tonic-gate 	uint32_t		len;
8530Sstevel@tonic-gate 	sd_readresv_desc_t	*readresv_desc;
8540Sstevel@tonic-gate } sd_prin_readresv_t;
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate typedef struct sd_prout {
8570Sstevel@tonic-gate 	uchar_t		res_key[MHIOC_RESV_KEY_SIZE];
8580Sstevel@tonic-gate 	uchar_t		service_key[MHIOC_RESV_KEY_SIZE];
8590Sstevel@tonic-gate 	uint32_t	scope_address;
8600Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8610Sstevel@tonic-gate 	uchar_t		aptpl:1,
8620Sstevel@tonic-gate 			reserved:7;
8630Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8640Sstevel@tonic-gate 	uchar_t		reserved:7,
8650Sstevel@tonic-gate 			aptpl:1;
8660Sstevel@tonic-gate #else
8670Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8680Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8690Sstevel@tonic-gate 	uchar_t		reserved_1;
8700Sstevel@tonic-gate 	uint16_t	ext_len;
8710Sstevel@tonic-gate } sd_prout_t;
8720Sstevel@tonic-gate 
8730Sstevel@tonic-gate #define	SD_READ_KEYS			0x00
8740Sstevel@tonic-gate #define	SD_READ_RESV			0x01
8750Sstevel@tonic-gate 
8760Sstevel@tonic-gate #define	SD_SCSI3_REGISTER		0x00
8770Sstevel@tonic-gate #define	SD_SCSI3_RESERVE		0x01
8780Sstevel@tonic-gate #define	SD_SCSI3_RELEASE		0x02
8790Sstevel@tonic-gate #define	SD_SCSI3_PREEMPTANDABORT	0x05
8800Sstevel@tonic-gate #define	SD_SCSI3_REGISTERANDIGNOREKEY	0x06
8810Sstevel@tonic-gate 
8820Sstevel@tonic-gate /*
8830Sstevel@tonic-gate  * Note: The default init of un_reservation_type is to the value of '0'
8840Sstevel@tonic-gate  * (from the ddi_softs_state_zalloc) which means it is defaulting to SCSI-3
8850Sstevel@tonic-gate  * reservation type. This is ok because during attach we use a SCSI-3
8860Sstevel@tonic-gate  * PRIORITY RESERVE IN command to determine the reservation type, and set
8870Sstevel@tonic-gate  * un_reservation_type for all cases.
8880Sstevel@tonic-gate  */
8890Sstevel@tonic-gate #define	SD_SCSI3_RESERVATION		0x0
8900Sstevel@tonic-gate #define	SD_SCSI2_RESERVATION		0x1
8910Sstevel@tonic-gate #define	SCSI3_RESV_DESC_LEN		16
8920Sstevel@tonic-gate 
8930Sstevel@tonic-gate /*
8940Sstevel@tonic-gate  * Reservation Status's
8950Sstevel@tonic-gate  */
8960Sstevel@tonic-gate #define	SD_RELEASE			0x0000
8970Sstevel@tonic-gate #define	SD_RESERVE			0x0001
8980Sstevel@tonic-gate #define	SD_TKOWN			0x0002
8990Sstevel@tonic-gate #define	SD_LOST_RESERVE			0x0004
9000Sstevel@tonic-gate #define	SD_FAILFAST			0x0080
9010Sstevel@tonic-gate #define	SD_WANT_RESERVE			0x0100
9020Sstevel@tonic-gate #define	SD_RESERVATION_CONFLICT		0x0200
9030Sstevel@tonic-gate #define	SD_PRIORITY_RESERVE		0x0400
9040Sstevel@tonic-gate 
9050Sstevel@tonic-gate #define	SD_TARGET_IS_UNRESERVED		0
9060Sstevel@tonic-gate #define	SD_TARGET_IS_RESERVED		1
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate /*
9090Sstevel@tonic-gate  * Save page in mode_select
9100Sstevel@tonic-gate  */
9110Sstevel@tonic-gate #define	SD_DONTSAVE_PAGE		0
9120Sstevel@tonic-gate #define	SD_SAVE_PAGE			1
9130Sstevel@tonic-gate 
9140Sstevel@tonic-gate /*
9150Sstevel@tonic-gate  * Delay before reclaiming reservation is 6 seconds, in units of micro seconds
9160Sstevel@tonic-gate  */
9170Sstevel@tonic-gate #define	SD_REINSTATE_RESV_DELAY		6000000
9180Sstevel@tonic-gate 
9190Sstevel@tonic-gate #define	SD_MODE2_BLKSIZE		2336	/* bytes */
9200Sstevel@tonic-gate 
9210Sstevel@tonic-gate /*
9220Sstevel@tonic-gate  * Resource type definitions for multi host control operations. Specifically,
9230Sstevel@tonic-gate  * queue and request definitions for reservation request handling between the
9240Sstevel@tonic-gate  * scsi facility callback function (sd_mhd_watch_cb) and the reservation
9250Sstevel@tonic-gate  * reclaim thread (sd_resv_reclaim_thread)
9260Sstevel@tonic-gate  */
9270Sstevel@tonic-gate struct sd_thr_request {
9280Sstevel@tonic-gate 	dev_t	dev;
9290Sstevel@tonic-gate 	struct	sd_thr_request	*sd_thr_req_next;
9300Sstevel@tonic-gate };
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate struct sd_resv_reclaim_request {
9330Sstevel@tonic-gate 	kthread_t		*srq_resv_reclaim_thread;
9340Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_req_head;
9350Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_cur_req;
9360Sstevel@tonic-gate 	kcondvar_t		srq_inprocess_cv;
9370Sstevel@tonic-gate 	kmutex_t		srq_resv_reclaim_mutex;
9380Sstevel@tonic-gate 	kcondvar_t		srq_resv_reclaim_cv;
9390Sstevel@tonic-gate };
9400Sstevel@tonic-gate 
9410Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_resv_reclaim_request::srq_resv_reclaim_mutex,
9420Sstevel@tonic-gate     sd_resv_reclaim_request))
9430Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_thr_request))
9440Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_prout))
9450Sstevel@tonic-gate 
9460Sstevel@tonic-gate 
9470Sstevel@tonic-gate 
9480Sstevel@tonic-gate /*
9490Sstevel@tonic-gate  * Driver Logging Components
9500Sstevel@tonic-gate  *
9510Sstevel@tonic-gate  * These components cover the functional entry points and areas of the
9520Sstevel@tonic-gate  * driver.  A component value is used for the entry point and utility
9530Sstevel@tonic-gate  * functions used by the entry point. The common component value is used
9540Sstevel@tonic-gate  * in those routines that are called from many areas of the driver.
9550Sstevel@tonic-gate  *
9560Sstevel@tonic-gate  * This can be done by adding the following two lines to /etc/system:
9570Sstevel@tonic-gate  * set sd:sd_component_mask=0x00080000
9580Sstevel@tonic-gate  * set sd:sd_level_mask=0x00000008
9590Sstevel@tonic-gate  */
9600Sstevel@tonic-gate #define	SD_LOG_PROBE			0x00000001
9610Sstevel@tonic-gate #define	SD_LOG_ATTACH_DETACH		0x00000002
9620Sstevel@tonic-gate #define	SD_LOG_OPEN_CLOSE		0x00000004
9630Sstevel@tonic-gate #define	SD_LOG_READ_WRITE		0x00000008
9640Sstevel@tonic-gate #define	SD_LOG_POWER			0x00000010
9650Sstevel@tonic-gate #define	SD_LOG_IOCTL			0x00000020
9660Sstevel@tonic-gate #define	SD_LOG_IOCTL_MHD		0x00000040
9670Sstevel@tonic-gate #define	SD_LOG_IOCTL_RMMEDIA		0x00000080
9680Sstevel@tonic-gate #define	SD_LOG_IOCTL_DKIO		0x00000100
9690Sstevel@tonic-gate #define	SD_LOG_IO			0x00000200
9700Sstevel@tonic-gate #define	SD_LOG_IO_CORE			0x00000400
9710Sstevel@tonic-gate #define	SD_LOG_IO_DISKSORT		0x00000800
9720Sstevel@tonic-gate #define	SD_LOG_IO_PARTITION		0x00001000
9730Sstevel@tonic-gate #define	SD_LOG_IO_RMMEDIA		0x00002000
9740Sstevel@tonic-gate #define	SD_LOG_IO_CHKSUM		0x00004000
9750Sstevel@tonic-gate #define	SD_LOG_IO_SDIOCTL		0x00008000
9760Sstevel@tonic-gate #define	SD_LOG_IO_PM			0x00010000
9770Sstevel@tonic-gate #define	SD_LOG_ERROR			0x00020000
9780Sstevel@tonic-gate #define	SD_LOG_DUMP			0x00040000
9790Sstevel@tonic-gate #define	SD_LOG_COMMON			0x00080000
9800Sstevel@tonic-gate #define	SD_LOG_SDTEST			0x00100000
9810Sstevel@tonic-gate #define	SD_LOG_IOERR			0x00200000
9820Sstevel@tonic-gate #define	SD_LOG_IO_FAILFAST		0x00400000
9830Sstevel@tonic-gate 
9840Sstevel@tonic-gate /* Driver Logging Levels */
9850Sstevel@tonic-gate #define	SD_LOGMASK_ERROR		0x00000001
9860Sstevel@tonic-gate #define	SD_LOGMASK_DUMP_MEM		0x00000002
9870Sstevel@tonic-gate #define	SD_LOGMASK_INFO			0x00000004
9880Sstevel@tonic-gate #define	SD_LOGMASK_TRACE		0x00000008
9890Sstevel@tonic-gate #define	SD_LOGMASK_DIAG			0x00000010
9900Sstevel@tonic-gate 
9910Sstevel@tonic-gate /* Driver Logging Formats */
9920Sstevel@tonic-gate #define	SD_LOG_HEX			0x00000001
9930Sstevel@tonic-gate #define	SD_LOG_CHAR			0x00000002
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate /*
9960Sstevel@tonic-gate  * The following macros should be used to log driver debug information
9970Sstevel@tonic-gate  * only. The output is filtered according to the component and level mask
9980Sstevel@tonic-gate  * values. Non-debug information, such as driver warnings intended for
9990Sstevel@tonic-gate  * the user should be logged via the scsi_log facility to ensure that
10000Sstevel@tonic-gate  * they are not filtered.
10010Sstevel@tonic-gate  */
10020Sstevel@tonic-gate #if DEBUG || lint
10030Sstevel@tonic-gate #define	SDDEBUG
10040Sstevel@tonic-gate 
10050Sstevel@tonic-gate /* SD_ERROR is called to log driver error conditions */
10060Sstevel@tonic-gate #define	SD_ERROR	sd_log_err
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate /* SD_TRACE is called to log driver trace conditions (function entry/exit) */
10090Sstevel@tonic-gate #define	SD_TRACE	sd_log_trace
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate /* SD_INFO is called to log general purpose driver info */
10120Sstevel@tonic-gate #define	SD_INFO		sd_log_info
10130Sstevel@tonic-gate 
10140Sstevel@tonic-gate /* SD_DUMP_MEMORY is called to dump a data buffer to the log */
10150Sstevel@tonic-gate #define	SD_DUMP_MEMORY	sd_dump_memory
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate /* RESET/ABORTS testing ioctls */
10180Sstevel@tonic-gate #define	DKIOCRESET	(DKIOC|14)
10190Sstevel@tonic-gate #define	DKIOCABORT	(DKIOC|15)
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
10220Sstevel@tonic-gate /*
1023173Scth  * sd_fi_pkt replicates the variables that are exposed through pkt
10240Sstevel@tonic-gate  *
1025173Scth  * sd_fi_xb replicates the variables that are exposed through xb
10260Sstevel@tonic-gate  *
1027173Scth  * sd_fi_un replicates the variables that are exposed through un
10280Sstevel@tonic-gate  *
1029173Scth  * sd_fi_arq replicates the variables that are
10300Sstevel@tonic-gate  *           exposed for Auto-Reqeust-Sense
10310Sstevel@tonic-gate  *
10320Sstevel@tonic-gate  */
10330Sstevel@tonic-gate struct sd_fi_pkt {
10340Sstevel@tonic-gate 	uint_t  pkt_flags;			/* flags */
10350Sstevel@tonic-gate 	uchar_t pkt_scbp;			/* pointer to status block */
10360Sstevel@tonic-gate 	uchar_t pkt_cdbp;			/* pointer to command block */
10370Sstevel@tonic-gate 	uint_t  pkt_state;			/* state of command */
10380Sstevel@tonic-gate 	uint_t  pkt_statistics;		/* statistics */
10390Sstevel@tonic-gate 	uchar_t pkt_reason;			/* reason completion called */
10400Sstevel@tonic-gate };
10410Sstevel@tonic-gate 
10420Sstevel@tonic-gate struct sd_fi_xb {
10430Sstevel@tonic-gate 	daddr_t xb_blkno;
10440Sstevel@tonic-gate 	ssize_t xb_dma_resid;
10450Sstevel@tonic-gate 	short	xb_retry_count;
10460Sstevel@tonic-gate 	short	xb_victim_retry_count;
10470Sstevel@tonic-gate 	uchar_t xb_sense_status;
10480Sstevel@tonic-gate 	uint_t  xb_sense_state;
10490Sstevel@tonic-gate 	ssize_t xb_sense_resid;
10500Sstevel@tonic-gate 	uchar_t xb_sense_data[SENSE_LENGTH];
10510Sstevel@tonic-gate 	uchar_t es_code;
10520Sstevel@tonic-gate 	uchar_t es_key;
10530Sstevel@tonic-gate 	uchar_t es_add_code;
10540Sstevel@tonic-gate 	uchar_t es_qual_code;
10550Sstevel@tonic-gate };
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate struct sd_fi_un {
10580Sstevel@tonic-gate 	uchar_t inq_rmb;
10590Sstevel@tonic-gate 	uchar_t un_ctype;
10600Sstevel@tonic-gate 	uint_t  un_notready_retry_count;
10610Sstevel@tonic-gate 	uint_t  un_reset_retry_count;
10620Sstevel@tonic-gate 	uchar_t un_reservation_type;
10630Sstevel@tonic-gate 	ushort_t un_notrdy_delay;
10640Sstevel@tonic-gate 	short   un_resvd_status;
10650Sstevel@tonic-gate 	uint32_t
10660Sstevel@tonic-gate 		un_f_arq_enabled,
10670Sstevel@tonic-gate 		un_f_geometry_is_valid,
10680Sstevel@tonic-gate 		un_f_allow_bus_device_reset,
10690Sstevel@tonic-gate 		un_f_opt_queueing;
10700Sstevel@tonic-gate 	timeout_id_t    un_restart_timeid;
10710Sstevel@tonic-gate };
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate struct sd_fi_arq {
10740Sstevel@tonic-gate 	struct scsi_status	sts_status;
10750Sstevel@tonic-gate 	struct scsi_status	sts_rqpkt_status;
10760Sstevel@tonic-gate 	uchar_t				sts_rqpkt_reason;
10770Sstevel@tonic-gate 	uchar_t				sts_rqpkt_resid;
10780Sstevel@tonic-gate 	uint_t				sts_rqpkt_state;
10790Sstevel@tonic-gate 	uint_t				sts_rqpkt_statistics;
10800Sstevel@tonic-gate 	struct scsi_extended_sense	sts_sensedata;
10810Sstevel@tonic-gate };
10820Sstevel@tonic-gate 
10830Sstevel@tonic-gate /* Conditional set def */
10840Sstevel@tonic-gate #define	SD_CONDSET(a, b, c, d) 					\
10850Sstevel@tonic-gate 	if ((((fi_ ## b)->c) != 0xFF) && 			\
10860Sstevel@tonic-gate 		(((fi_ ## b)->c) != 0xFFFF) &&		\
10870Sstevel@tonic-gate 		(((fi_ ## b)->c) != 0xFFFFFFFF)) {	\
10880Sstevel@tonic-gate 			a->c = ((fi_ ## b)->c); 		\
10890Sstevel@tonic-gate 			SD_INFO(SD_LOG_IOERR, un,			\
10900Sstevel@tonic-gate 					"sd_fault_injection:"		\
10910Sstevel@tonic-gate 					"setting %s to %d\n", 		\
10920Sstevel@tonic-gate 					d, ((fi_ ## b)->c)); }
10930Sstevel@tonic-gate 
10940Sstevel@tonic-gate /* SD FaultInjection ioctls */
10950Sstevel@tonic-gate #define	SDIOC			('T'<<8)
10960Sstevel@tonic-gate #define	SDIOCSTART		(SDIOC|1)
10970Sstevel@tonic-gate #define	SDIOCSTOP		(SDIOC|2)
10980Sstevel@tonic-gate #define	SDIOCINSERTPKT	(SDIOC|3)
10990Sstevel@tonic-gate #define	SDIOCINSERTXB	(SDIOC|4)
11000Sstevel@tonic-gate #define	SDIOCINSERTUN	(SDIOC|5)
11010Sstevel@tonic-gate #define	SDIOCINSERTARQ	(SDIOC|6)
11020Sstevel@tonic-gate #define	SDIOCPUSH		(SDIOC|7)
11030Sstevel@tonic-gate #define	SDIOCRETRIEVE	(SDIOC|8)
11040Sstevel@tonic-gate #define	SDIOCRUN		(SDIOC|9)
11050Sstevel@tonic-gate #endif
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate #else
11080Sstevel@tonic-gate 
11090Sstevel@tonic-gate #undef	SDDEBUG
11100Sstevel@tonic-gate #define	SD_ERROR	{ if (0) sd_log_err; }
11110Sstevel@tonic-gate #define	SD_TRACE	{ if (0) sd_log_trace; }
11120Sstevel@tonic-gate #define	SD_INFO		{ if (0) sd_log_info; }
11130Sstevel@tonic-gate #define	SD_DUMP_MEMORY	{ if (0) sd_dump_memory; }
11140Sstevel@tonic-gate #endif
11150Sstevel@tonic-gate 
11160Sstevel@tonic-gate 
11170Sstevel@tonic-gate /*
11180Sstevel@tonic-gate  * Miscellaneous macros
11190Sstevel@tonic-gate  */
11200Sstevel@tonic-gate 
11210Sstevel@tonic-gate #define	SD_USECTOHZ(x)			(drv_usectohz((x)*1000000))
11220Sstevel@tonic-gate #define	SD_GET_PKT_STATUS(pktp)		((*(pktp)->pkt_scbp) & STATUS_MASK)
11230Sstevel@tonic-gate 
11240Sstevel@tonic-gate #define	SD_BIOERROR(bp, errcode)					\
11250Sstevel@tonic-gate 	if ((bp)->b_resid == 0) {					\
11260Sstevel@tonic-gate 		(bp)->b_resid = (bp)->b_bcount;				\
11270Sstevel@tonic-gate 	}								\
11280Sstevel@tonic-gate 	if ((bp)->b_error == 0) {					\
11290Sstevel@tonic-gate 		bioerror(bp, errcode);					\
11300Sstevel@tonic-gate 	}								\
11310Sstevel@tonic-gate 	(bp)->b_flags |= B_ERROR;					\
11320Sstevel@tonic-gate 
1133159Sjongkis #define	SD_FILL_SCSI1_LUN_CDB(lunp, cdbp)				\
1134159Sjongkis 	if (! (lunp)->un_f_is_fibre &&					\
1135159Sjongkis 	    SD_INQUIRY((lunp))->inq_ansi == 0x01) {			\
1136159Sjongkis 		int _lun = ddi_prop_get_int(DDI_DEV_T_ANY,		\
1137159Sjongkis 		    SD_DEVINFO((lunp)), DDI_PROP_DONTPASS,		\
1138159Sjongkis 		    SCSI_ADDR_PROP_LUN, 0);				\
1139159Sjongkis 		if (_lun > 0) {						\
1140159Sjongkis 			(cdbp)->scc_lun = _lun;				\
1141159Sjongkis 		}							\
11420Sstevel@tonic-gate 	}
11430Sstevel@tonic-gate 
1144159Sjongkis #define	SD_FILL_SCSI1_LUN(lunp, pktp)					\
1145159Sjongkis 	SD_FILL_SCSI1_LUN_CDB((lunp), (union scsi_cdb *)(pktp)->pkt_cdbp)
1146159Sjongkis 
11470Sstevel@tonic-gate /*
11480Sstevel@tonic-gate  * Disk driver states
11490Sstevel@tonic-gate  */
11500Sstevel@tonic-gate 
11510Sstevel@tonic-gate #define	SD_STATE_NORMAL		0
11520Sstevel@tonic-gate #define	SD_STATE_OFFLINE	1
11530Sstevel@tonic-gate #define	SD_STATE_RWAIT		2
11540Sstevel@tonic-gate #define	SD_STATE_DUMPING	3
11550Sstevel@tonic-gate #define	SD_STATE_SUSPENDED	4
11560Sstevel@tonic-gate #define	SD_STATE_PM_CHANGING	5
11570Sstevel@tonic-gate 
11580Sstevel@tonic-gate /*
11590Sstevel@tonic-gate  * The table is to be interpreted as follows: The rows lists all the states
11600Sstevel@tonic-gate  * and each column is a state that a state in each row *can* reach. The entries
11610Sstevel@tonic-gate  * in the table list the event that cause that transition to take place.
11620Sstevel@tonic-gate  * For e.g.: To go from state RWAIT to SUSPENDED, event (d)-- which is the
11630Sstevel@tonic-gate  * invocation of DDI_SUSPEND-- has to take place. Note the same event could
11640Sstevel@tonic-gate  * cause the transition from one state to two different states. e.g., from
11650Sstevel@tonic-gate  * state SUSPENDED, when we get a DDI_RESUME, we just go back to the *last
11660Sstevel@tonic-gate  * state* whatever that might be. (NORMAL or OFFLINE).
11670Sstevel@tonic-gate  *
11680Sstevel@tonic-gate  *
11690Sstevel@tonic-gate  * State Transition Table:
11700Sstevel@tonic-gate  *
11710Sstevel@tonic-gate  *                    NORMAL  OFFLINE  RWAIT  DUMPING  SUSPENDED  PM_SUSPENDED
11720Sstevel@tonic-gate  *
11730Sstevel@tonic-gate  *   NORMAL              -      (a)      (b)     (c)      (d)       (h)
11740Sstevel@tonic-gate  *
11750Sstevel@tonic-gate  *   OFFLINE            (e)      -       (e)     (c)      (d)       NP
11760Sstevel@tonic-gate  *
11770Sstevel@tonic-gate  *   RWAIT              (f)     NP        -      (c)      (d)       (h)
11780Sstevel@tonic-gate  *
11790Sstevel@tonic-gate  *   DUMPING            NP      NP        NP      -        NP       NP
11800Sstevel@tonic-gate  *
11810Sstevel@tonic-gate  *   SUSPENDED          (g)     (g)       (b)     NP*      -        NP
11820Sstevel@tonic-gate  *
11830Sstevel@tonic-gate  *   PM_SUSPENDED       (i)     NP        (b)    (c)      (d)       -
11840Sstevel@tonic-gate  *
11850Sstevel@tonic-gate  *   NP :       Not Possible.
11860Sstevel@tonic-gate  *   (a):       Disk does not respond.
11870Sstevel@tonic-gate  *   (b):       Packet Allocation Fails
11880Sstevel@tonic-gate  *   (c):       Panic - Crash dump
11890Sstevel@tonic-gate  *   (d):       DDI_SUSPEND is called.
11900Sstevel@tonic-gate  *   (e):       Disk has a successful I/O completed.
11910Sstevel@tonic-gate  *   (f):       sdrunout() calls sdstart() which sets it NORMAL
11920Sstevel@tonic-gate  *   (g):       DDI_RESUME is called.
11930Sstevel@tonic-gate  *   (h):	Device threshold exceeded pm framework called power
11940Sstevel@tonic-gate  *		entry point or pm_lower_power called in detach.
11950Sstevel@tonic-gate  *   (i):	When new I/O come in.
11960Sstevel@tonic-gate  *    * :       When suspended, we dont change state during panic dump
11970Sstevel@tonic-gate  */
11980Sstevel@tonic-gate 
11990Sstevel@tonic-gate 
12000Sstevel@tonic-gate #define	SD_MAX_THROTTLE		256
12010Sstevel@tonic-gate #define	SD_MIN_THROTTLE		8
12020Sstevel@tonic-gate /*
12030Sstevel@tonic-gate  * Lowest valid max. and min. throttle value.
12040Sstevel@tonic-gate  * This is set to 2 because if un_min_throttle were allowed to be 1 then
12050Sstevel@tonic-gate  * un_throttle would never get set to a value less than un_min_throttle
12060Sstevel@tonic-gate  * (0 is a special case) which means it would never get set back to
12070Sstevel@tonic-gate  * un_saved_throttle in routine sd_restore_throttle().
12080Sstevel@tonic-gate  */
12090Sstevel@tonic-gate #define	SD_LOWEST_VALID_THROTTLE	2
12100Sstevel@tonic-gate 
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 
12130Sstevel@tonic-gate /* Return codes for sd_send_polled_cmd() and sd_scsi_poll() */
12140Sstevel@tonic-gate #define	SD_CMD_SUCCESS			0
12150Sstevel@tonic-gate #define	SD_CMD_FAILURE			1
12160Sstevel@tonic-gate #define	SD_CMD_RESERVATION_CONFLICT	2
12170Sstevel@tonic-gate #define	SD_CMD_ILLEGAL_REQUEST		3
12180Sstevel@tonic-gate #define	SD_CMD_BECOMING_READY		4
12190Sstevel@tonic-gate #define	SD_CMD_CHECK_CONDITION		5
12200Sstevel@tonic-gate 
12210Sstevel@tonic-gate /* Return codes for sd_ready_and_valid */
12220Sstevel@tonic-gate #define	SD_READY_VALID			0
12230Sstevel@tonic-gate #define	SD_NOT_READY_VALID		1
12240Sstevel@tonic-gate #define	SD_READY_NOT_VALID		2
12250Sstevel@tonic-gate 
12260Sstevel@tonic-gate #define	SD_PATH_STANDARD		0
12270Sstevel@tonic-gate #define	SD_PATH_DIRECT			1
12280Sstevel@tonic-gate #define	SD_PATH_DIRECT_PRIORITY		2
12290Sstevel@tonic-gate 
12300Sstevel@tonic-gate #define	SD_UNIT_ATTENTION_RETRY		40
12310Sstevel@tonic-gate 
12320Sstevel@tonic-gate /*
12330Sstevel@tonic-gate  * The following three are bit flags passed into sd_send_scsi_TEST_UNIT_READY
12340Sstevel@tonic-gate  * to control specific behavior.
12350Sstevel@tonic-gate  */
12360Sstevel@tonic-gate #define	SD_CHECK_FOR_MEDIA		0x01
12370Sstevel@tonic-gate #define	SD_DONT_RETRY_TUR		0x02
12380Sstevel@tonic-gate #define	SD_BYPASS_PM			0x04
12390Sstevel@tonic-gate 
12400Sstevel@tonic-gate #define	SD_GROUP0_MAXADDR	(2 << 20)
12410Sstevel@tonic-gate #define	SD_GROUP0_MAXCOUNT	(0xff)
12420Sstevel@tonic-gate #define	SD_GROUP1_MAXCOUNT	(0xffff)
12430Sstevel@tonic-gate 
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate #define	SD_BECOMING_ACTIVE	0x01
12460Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW	0
12470Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT	1
12480Sstevel@tonic-gate 
12490Sstevel@tonic-gate #define	SD_GET_PKT_OPCODE(pktp)	\
12500Sstevel@tonic-gate 	(((union scsi_cdb *)((pktp)->pkt_cdbp))->cdb_un.cmd)
12510Sstevel@tonic-gate 
12520Sstevel@tonic-gate 
12530Sstevel@tonic-gate #define	SD_NO_RETRY_ISSUED		0
12540Sstevel@tonic-gate #define	SD_DELAYED_RETRY_ISSUED		1
12550Sstevel@tonic-gate #define	SD_IMMEDIATE_RETRY_ISSUED	2
12560Sstevel@tonic-gate 
12570Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
12580Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12590Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid + (SD_GET_XBUF(bp)->xb_dma_resid))
12600Sstevel@tonic-gate #else
12610Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12620Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid)
12630Sstevel@tonic-gate #endif
12640Sstevel@tonic-gate 
12650Sstevel@tonic-gate 
12660Sstevel@tonic-gate #define	SD_RETRIES_MASK		0x00FF
12670Sstevel@tonic-gate #define	SD_RETRIES_NOCHECK	0x0000
12680Sstevel@tonic-gate #define	SD_RETRIES_STANDARD	0x0001
12690Sstevel@tonic-gate #define	SD_RETRIES_VICTIM	0x0002
12700Sstevel@tonic-gate #define	SD_RETRIES_BUSY		0x0003
12710Sstevel@tonic-gate #define	SD_RETRIES_UA		0x0004
12720Sstevel@tonic-gate #define	SD_RETRIES_ISOLATE	0x8000
12730Sstevel@tonic-gate #define	SD_RETRIES_FAILFAST	0x4000
12740Sstevel@tonic-gate 
12750Sstevel@tonic-gate #define	SD_UPDATE_RESERVATION_STATUS(un, pktp)				\
12760Sstevel@tonic-gate if (((pktp)->pkt_reason == CMD_RESET) ||				\
12770Sstevel@tonic-gate 	((pktp)->pkt_statistics & (STAT_BUS_RESET | STAT_DEV_RESET))) { \
12780Sstevel@tonic-gate 	if (((un)->un_resvd_status & SD_RESERVE) == SD_RESERVE) {	\
12790Sstevel@tonic-gate 		(un)->un_resvd_status |=				\
12800Sstevel@tonic-gate 		    (SD_LOST_RESERVE | SD_WANT_RESERVE);		\
12810Sstevel@tonic-gate 	}								\
12820Sstevel@tonic-gate }
12830Sstevel@tonic-gate 
12840Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_VALID		0
12850Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_INVALID	1
12860Sstevel@tonic-gate 
12870Sstevel@tonic-gate /*
12880Sstevel@tonic-gate  * Delay (in seconds) before restoring the "throttle limit" back
12890Sstevel@tonic-gate  * to its maximum value.
12900Sstevel@tonic-gate  */
12910Sstevel@tonic-gate #define	SD_RESET_THROTTLE_TIMEOUT	60
12920Sstevel@tonic-gate 
12930Sstevel@tonic-gate #define	SD_THROTTLE_TRAN_BUSY		0
12940Sstevel@tonic-gate #define	SD_THROTTLE_QFULL		1
12950Sstevel@tonic-gate 
12960Sstevel@tonic-gate #define	SD_THROTTLE_RESET_INTERVAL	\
12970Sstevel@tonic-gate 	(sd_reset_throttle_timeout * drv_usectohz(1000000))
12980Sstevel@tonic-gate 
12990Sstevel@tonic-gate 
13000Sstevel@tonic-gate /*
13010Sstevel@tonic-gate  * xb_pkt_flags defines
13020Sstevel@tonic-gate  * SD_XB_USCSICMD indicates the scsi request is a uscsi request
13030Sstevel@tonic-gate  * SD_XB_DMA_FREED indicates the scsi_pkt has had its DMA resources freed
13040Sstevel@tonic-gate  * by a call to scsi_dmafree(9F). The resources must be reallocated before
13050Sstevel@tonic-gate  *   before a call to scsi_transport can be made again.
13060Sstevel@tonic-gate  * SD_XB_INITPKT_MASK: since this field is also used to store flags for
13070Sstevel@tonic-gate  *   a scsi_init_pkt(9F) call, we need a mask to make sure that we don't
13080Sstevel@tonic-gate  *   pass any unintended bits to scsi_init_pkt(9F) (ugly hack).
13090Sstevel@tonic-gate  */
13100Sstevel@tonic-gate #define	SD_XB_USCSICMD		0x40000000
13110Sstevel@tonic-gate #define	SD_XB_DMA_FREED		0x20000000
13120Sstevel@tonic-gate #define	SD_XB_INITPKT_MASK	(PKT_CONSISTENT | PKT_DMA_PARTIAL)
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate /*
13150Sstevel@tonic-gate  * Extension for the buf(9s) struct that we receive from a higher
13160Sstevel@tonic-gate  * layer. Located by b_private in the buf(9S).  (The previous contents
13170Sstevel@tonic-gate  * of b_private are saved & restored before calling biodone(9F).)
13180Sstevel@tonic-gate  */
13190Sstevel@tonic-gate struct sd_xbuf {
13200Sstevel@tonic-gate 
13210Sstevel@tonic-gate 	struct sd_lun	*xb_un;		/* Ptr to associated sd_lun */
13220Sstevel@tonic-gate 	struct scsi_pkt	*xb_pktp;	/* Ptr to associated scsi_pkt */
13230Sstevel@tonic-gate 
13240Sstevel@tonic-gate 	/*
13250Sstevel@tonic-gate 	 * xb_pktinfo points to any optional data that may be needed
13260Sstevel@tonic-gate 	 * by the initpkt and/or destroypkt functions.  Typical
13270Sstevel@tonic-gate 	 * use might be to point to a struct uscsi_cmd.
13280Sstevel@tonic-gate 	 */
13290Sstevel@tonic-gate 	void	*xb_pktinfo;
13300Sstevel@tonic-gate 
13310Sstevel@tonic-gate 	/*
13320Sstevel@tonic-gate 	 * Layer-private data area. This may be used by any layer to store
13330Sstevel@tonic-gate 	 * layer-specific data on a per-IO basis. Typical usage is for an
13340Sstevel@tonic-gate 	 * iostart routine to save some info here for later use by its
13350Sstevel@tonic-gate 	 * partner iodone routine.  This area may be used to hold data or
13360Sstevel@tonic-gate 	 * a pointer to a data block that is allocated/freed by the layer's
13370Sstevel@tonic-gate 	 * iostart/iodone routines. Allocation & management policy for the
13380Sstevel@tonic-gate 	 * layer-private area is defined & implemented by each specific
13390Sstevel@tonic-gate 	 * layer as required.
13400Sstevel@tonic-gate 	 *
13410Sstevel@tonic-gate 	 * IMPORTANT: Since a higher layer may depend on the value in the
13420Sstevel@tonic-gate 	 * xb_private field, each layer must ensure that it returns the
13430Sstevel@tonic-gate 	 * buf/xbuf to the next higher layer (via SD_NEXT_IODONE()) with
13440Sstevel@tonic-gate 	 * the SAME VALUE in xb_private as when the buf/xbuf was first
13450Sstevel@tonic-gate 	 * received by the layer's iostart routine. Typically this is done
13460Sstevel@tonic-gate 	 * by the iostart routine saving the contents of xb_private into
13470Sstevel@tonic-gate 	 * a place in the layer-private data area, and the iodone routine
13480Sstevel@tonic-gate 	 * restoring the value of xb_private before deallocating the
13490Sstevel@tonic-gate 	 * layer-private data block and calling SD_NEXT_IODONE(). Of course,
13500Sstevel@tonic-gate 	 * if a layer never modifies xb_private in a buf/xbuf from a higher
13510Sstevel@tonic-gate 	 * layer, there will be no need to restore the value.
13520Sstevel@tonic-gate 	 *
13530Sstevel@tonic-gate 	 * Note that in the case where a layer _creates_ a buf/xbuf (such as
13540Sstevel@tonic-gate 	 * by calling sd_shadow_buf_alloc()) to pass to a lower layer, it is
13550Sstevel@tonic-gate 	 * not necessary to preserve the contents of xb_private as there is
13560Sstevel@tonic-gate 	 * no higher layer dependency on the value of xb_private. Such a
13570Sstevel@tonic-gate 	 * buf/xbuf must be deallocated by the layer that allocated it and
13580Sstevel@tonic-gate 	 * must *NEVER* be passed up to a higher layer.
13590Sstevel@tonic-gate 	 */
13600Sstevel@tonic-gate 	void	*xb_private;	/* Layer-private data block */
13610Sstevel@tonic-gate 
13620Sstevel@tonic-gate 	/*
13630Sstevel@tonic-gate 	 * We do not use the b_blkno provided in the buf(9S), as we need to
13640Sstevel@tonic-gate 	 * make adjustments to it in the driver, but it is not a field that
13650Sstevel@tonic-gate 	 * the driver owns or is free to modify.
13660Sstevel@tonic-gate 	 */
13670Sstevel@tonic-gate 	daddr_t	xb_blkno;		/* Absolute block # on target */
13680Sstevel@tonic-gate 
13690Sstevel@tonic-gate 	int	xb_chain_iostart;	/* iostart side index */
13700Sstevel@tonic-gate 	int	xb_chain_iodone;	/* iodone side index */
13710Sstevel@tonic-gate 	int	xb_pkt_flags;		/* Flags for scsi_init_pkt() */
13720Sstevel@tonic-gate 	ssize_t	xb_dma_resid;
13730Sstevel@tonic-gate 	short	xb_retry_count;
13740Sstevel@tonic-gate 	short	xb_victim_retry_count;
13750Sstevel@tonic-gate 	short	xb_ua_retry_count;	/* unit_attention retry counter */
13760Sstevel@tonic-gate 
13770Sstevel@tonic-gate 	/*
13780Sstevel@tonic-gate 	 * Various status and data used when a RQS command is run on
13790Sstevel@tonic-gate 	 * the behalf of this command.
13800Sstevel@tonic-gate 	 */
13810Sstevel@tonic-gate 	struct buf	*xb_sense_bp;	/* back ptr to buf, for RQS */
13820Sstevel@tonic-gate 	uint_t	xb_sense_state;		/* scsi_pkt state of RQS command */
13830Sstevel@tonic-gate 	ssize_t	xb_sense_resid;		/* residual of RQS command */
13840Sstevel@tonic-gate 	uchar_t	xb_sense_status;	/* scsi status byte of RQS command */
13850Sstevel@tonic-gate 	uchar_t	xb_sense_data[SENSE_LENGTH];	/* sense data from RQS cmd */
13860Sstevel@tonic-gate };
13870Sstevel@tonic-gate 
13880Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", sd_xbuf))
13890Sstevel@tonic-gate 
13900Sstevel@tonic-gate #define	SD_PKT_ALLOC_SUCCESS			0
13910Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE			1
13920Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_NO_DMA		2
13930Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_PKT_TOO_SMALL	3
13940Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL	4
13950Sstevel@tonic-gate 
13960Sstevel@tonic-gate #define	SD_GET_XBUF(bp)		((struct sd_xbuf *)((bp)->b_private))
13970Sstevel@tonic-gate #define	SD_GET_UN(bp)		((SD_GET_XBUF(bp))->xb_un)
13980Sstevel@tonic-gate #define	SD_GET_PKTP(bp)		((SD_GET_XBUF(bp))->xb_pktp)
13990Sstevel@tonic-gate #define	SD_GET_BLKNO(bp)	((SD_GET_XBUF(bp))->xb_blkno)
14000Sstevel@tonic-gate 
14010Sstevel@tonic-gate 
14020Sstevel@tonic-gate /*
14030Sstevel@tonic-gate  * Special-purpose struct for sd_send_scsi_cmd() to pass command-specific
14040Sstevel@tonic-gate  * data through the layering chains to sd_initpkt_for_uscsi().
14050Sstevel@tonic-gate  */
14060Sstevel@tonic-gate struct sd_uscsi_info {
14070Sstevel@tonic-gate 	int			ui_flags;
14080Sstevel@tonic-gate 	struct uscsi_cmd	*ui_cmdp;
14090Sstevel@tonic-gate };
14100Sstevel@tonic-gate 
14110Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_uscsi_info))
14120Sstevel@tonic-gate 
14130Sstevel@tonic-gate 
14140Sstevel@tonic-gate /*
14150Sstevel@tonic-gate  * Macros and definitions for driver kstats and errstats
14160Sstevel@tonic-gate  *
14170Sstevel@tonic-gate  * Some third-party layered drivers (they know who they are) do not maintain
14180Sstevel@tonic-gate  * their open/close counts correctly which causes our kstat reporting to get
14190Sstevel@tonic-gate  * messed up & results in panics. These macros will update the driver kstats
14200Sstevel@tonic-gate  * only if the counts are valid.
14210Sstevel@tonic-gate  */
14220Sstevel@tonic-gate #define	SD_UPDATE_COMMON_KSTATS(kstat_function, kstatp)			\
14230Sstevel@tonic-gate 	if ((kstat_function)  == kstat_runq_exit ||			\
14240Sstevel@tonic-gate 	    ((kstat_function) == kstat_runq_back_to_waitq)) { 		\
14250Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->rcnt) {			\
14260Sstevel@tonic-gate 			kstat_function((kstatp));			\
14270Sstevel@tonic-gate 		} else {						\
14280Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
14290Sstevel@tonic-gate 		"kstat rcnt == 0 when exiting runq, please check\n");	\
14300Sstevel@tonic-gate 		}							\
14310Sstevel@tonic-gate 	} else if ((kstat_function) == kstat_waitq_exit ||		\
14320Sstevel@tonic-gate 	    ((kstat_function) == kstat_waitq_to_runq)) {		\
14330Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->wcnt) {			\
14340Sstevel@tonic-gate 			kstat_function(kstatp);				\
14350Sstevel@tonic-gate 		} else {						\
14360Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
14370Sstevel@tonic-gate 		"kstat wcnt == 0 when exiting waitq, please check\n");	\
14380Sstevel@tonic-gate 		}							\
14390Sstevel@tonic-gate 	} else {							\
14400Sstevel@tonic-gate 		kstat_function(kstatp);					\
14410Sstevel@tonic-gate 	}
14420Sstevel@tonic-gate 
14430Sstevel@tonic-gate #define	SD_UPDATE_KSTATS(un, kstat_function, bp)			\
14440Sstevel@tonic-gate 	ASSERT(SD_GET_XBUF(bp) != NULL);				\
14450Sstevel@tonic-gate 	if (SD_IS_BUFIO(SD_GET_XBUF(bp))) {				\
14460Sstevel@tonic-gate 		struct kstat *pksp =					\
14470Sstevel@tonic-gate 			(un)->un_pstats[SDPART((bp)->b_edev)];		\
14480Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
14490Sstevel@tonic-gate 		if ((un)->un_stats != NULL) {				\
14500Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);	\
14510Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
14520Sstevel@tonic-gate 		}							\
14530Sstevel@tonic-gate 		if (pksp != NULL) {					\
14540Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR(pksp);		\
14550Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
14560Sstevel@tonic-gate 		}							\
14570Sstevel@tonic-gate 	}
14580Sstevel@tonic-gate 
14590Sstevel@tonic-gate #define	SD_UPDATE_ERRSTATS(un, x)					\
14600Sstevel@tonic-gate 	if ((un)->un_errstats != NULL) {				\
14610Sstevel@tonic-gate 		struct sd_errstats *stp;				\
14620Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
14630Sstevel@tonic-gate 		stp = (struct sd_errstats *)(un)->un_errstats->ks_data;	\
14640Sstevel@tonic-gate 		stp->x.value.ui32++;					\
14650Sstevel@tonic-gate 	}
14660Sstevel@tonic-gate 
14670Sstevel@tonic-gate #define	SD_UPDATE_RDWR_STATS(un, bp)					\
14680Sstevel@tonic-gate 	if ((un)->un_stats != NULL) {					\
14690Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);		\
14700Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
14710Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
14720Sstevel@tonic-gate 			kip->reads++;					\
14730Sstevel@tonic-gate 			kip->nread += n_done;				\
14740Sstevel@tonic-gate 		} else {						\
14750Sstevel@tonic-gate 			kip->writes++;					\
14760Sstevel@tonic-gate 			kip->nwritten += n_done;			\
14770Sstevel@tonic-gate 		}							\
14780Sstevel@tonic-gate 	}
14790Sstevel@tonic-gate 
14800Sstevel@tonic-gate #define	SD_UPDATE_PARTITION_STATS(un, bp)				\
14810Sstevel@tonic-gate {									\
14820Sstevel@tonic-gate 	struct kstat *pksp = (un)->un_pstats[SDPART((bp)->b_edev)];	\
14830Sstevel@tonic-gate 	if (pksp != NULL) {						\
14840Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR(pksp);			\
14850Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
14860Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
14870Sstevel@tonic-gate 			kip->reads++;					\
14880Sstevel@tonic-gate 			kip->nread += n_done;				\
14890Sstevel@tonic-gate 		} else {						\
14900Sstevel@tonic-gate 			kip->writes++;					\
14910Sstevel@tonic-gate 			kip->nwritten += n_done;			\
14920Sstevel@tonic-gate 		}							\
14930Sstevel@tonic-gate 	}								\
14940Sstevel@tonic-gate }
14950Sstevel@tonic-gate 
14960Sstevel@tonic-gate 
14970Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
14980Sstevel@tonic-gate 
14990Sstevel@tonic-gate 
15000Sstevel@tonic-gate /*
15010Sstevel@tonic-gate  * 60 seconds is a *very* reasonable amount of time for most slow CD
15020Sstevel@tonic-gate  * operations.
15030Sstevel@tonic-gate  */
15040Sstevel@tonic-gate #define	SD_IO_TIME			60
15050Sstevel@tonic-gate 
15060Sstevel@tonic-gate /*
15070Sstevel@tonic-gate  * 2 hours is an excessively reasonable amount of time for format operations.
15080Sstevel@tonic-gate  */
15090Sstevel@tonic-gate #define	SD_FMT_TIME			(120 * 60)
15100Sstevel@tonic-gate 
15110Sstevel@tonic-gate /*
15120Sstevel@tonic-gate  * 5 seconds is what we'll wait if we get a Busy Status back
15130Sstevel@tonic-gate  */
15140Sstevel@tonic-gate #define	SD_BSY_TIMEOUT			(drv_usectohz(5 * 1000000))
15150Sstevel@tonic-gate 
15160Sstevel@tonic-gate /*
15170Sstevel@tonic-gate  * 100 msec. is what we'll wait if we get Unit Attention.
15180Sstevel@tonic-gate  */
15190Sstevel@tonic-gate #define	SD_UA_RETRY_DELAY		(drv_usectohz((clock_t)100000))
15200Sstevel@tonic-gate 
15210Sstevel@tonic-gate /*
15220Sstevel@tonic-gate  * 100 msec. is what we'll wait for restarted commands.
15230Sstevel@tonic-gate  */
15240Sstevel@tonic-gate #define	SD_RESTART_TIMEOUT		(drv_usectohz((clock_t)100000))
15250Sstevel@tonic-gate 
15260Sstevel@tonic-gate /*
15270Sstevel@tonic-gate  * 100 msec. is what we'll wait for certain retries for fibre channel
15280Sstevel@tonic-gate  * targets, 0 msec for parallel SCSI.
15290Sstevel@tonic-gate  */
15300Sstevel@tonic-gate #if defined(__fibre)
15310Sstevel@tonic-gate #define	SD_RETRY_DELAY			(drv_usectohz(100000))
15320Sstevel@tonic-gate #else
15330Sstevel@tonic-gate #define	SD_RETRY_DELAY			((clock_t)0)
15340Sstevel@tonic-gate #endif
15350Sstevel@tonic-gate 
15360Sstevel@tonic-gate /*
15370Sstevel@tonic-gate  * 60 seconds is what we will wait for to reset the
15380Sstevel@tonic-gate  * throttle back to it SD_MAX_THROTTLE.
15390Sstevel@tonic-gate  */
15400Sstevel@tonic-gate #define	SD_RESET_THROTTLE_TIMEOUT	60
15410Sstevel@tonic-gate 
15420Sstevel@tonic-gate /*
15430Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
15440Sstevel@tonic-gate  *
15450Sstevel@tonic-gate  * This includes retries due to transport failure
15460Sstevel@tonic-gate  * (need to distinguish between Target and Transport failure)
15470Sstevel@tonic-gate  *
15480Sstevel@tonic-gate  */
15490Sstevel@tonic-gate #if defined(__fibre)
15500Sstevel@tonic-gate #define	SD_RETRY_COUNT			3
15510Sstevel@tonic-gate #else
15520Sstevel@tonic-gate #define	SD_RETRY_COUNT			5
15530Sstevel@tonic-gate #endif
15540Sstevel@tonic-gate 
15550Sstevel@tonic-gate /*
15560Sstevel@tonic-gate  * Number of times we will retry for unit attention.
15570Sstevel@tonic-gate  */
15580Sstevel@tonic-gate #define	SD_UA_RETRY_COUNT		600
15590Sstevel@tonic-gate 
15600Sstevel@tonic-gate #define	SD_VICTIM_RETRY_COUNT(un)	(un->un_victim_retry_count)
15610Sstevel@tonic-gate #define	CD_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count * 2)
15620Sstevel@tonic-gate #define	DISK_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count / 2)
15630Sstevel@tonic-gate 
15640Sstevel@tonic-gate 
15650Sstevel@tonic-gate /*
15660Sstevel@tonic-gate  * Maximum number of units we can support
15670Sstevel@tonic-gate  * (controlled by room in minor device byte)
15680Sstevel@tonic-gate  *
15690Sstevel@tonic-gate  * Note: this value is out of date.
15700Sstevel@tonic-gate  */
15710Sstevel@tonic-gate #define	SD_MAXUNIT			32
15720Sstevel@tonic-gate 
15730Sstevel@tonic-gate /*
15740Sstevel@tonic-gate  * 30 seconds is what we will wait for the IO to finish
15750Sstevel@tonic-gate  * before we fail the DDI_SUSPEND
15760Sstevel@tonic-gate  */
15770Sstevel@tonic-gate #define	SD_WAIT_CMDS_COMPLETE		30
15780Sstevel@tonic-gate 
15790Sstevel@tonic-gate /*
15800Sstevel@tonic-gate  * Prevent/allow media removal flags
15810Sstevel@tonic-gate  */
15820Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW		0
15830Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT		1
15840Sstevel@tonic-gate 
15850Sstevel@tonic-gate 
15860Sstevel@tonic-gate /*
15870Sstevel@tonic-gate  * Drive Types (and characteristics)
15880Sstevel@tonic-gate  */
15890Sstevel@tonic-gate #define	VIDMAX				8
15900Sstevel@tonic-gate #define	PIDMAX				16
15910Sstevel@tonic-gate 
15920Sstevel@tonic-gate 
15930Sstevel@tonic-gate /*
15940Sstevel@tonic-gate  * The following #defines and type definitions for the property
15950Sstevel@tonic-gate  * processing component of the sd driver.
15960Sstevel@tonic-gate  */
15970Sstevel@tonic-gate 
15980Sstevel@tonic-gate 
15990Sstevel@tonic-gate /* Miscellaneous Definitions */
16000Sstevel@tonic-gate #define	SD_CONF_VERSION_1		1
16010Sstevel@tonic-gate #define	SD_CONF_NOT_USED		32
16020Sstevel@tonic-gate 
16030Sstevel@tonic-gate /*
16040Sstevel@tonic-gate  * Return values from "pm-capable" property
16050Sstevel@tonic-gate  */
16060Sstevel@tonic-gate #define	SD_PM_CAPABLE_UNDEFINED		-1
16070Sstevel@tonic-gate #define	SD_PM_CAPABLE_FALSE		0
16080Sstevel@tonic-gate #define	SD_PM_CAPABLE_TRUE		1
16090Sstevel@tonic-gate 
16100Sstevel@tonic-gate /*
16110Sstevel@tonic-gate  * Property data values used in static configuration table
16120Sstevel@tonic-gate  * These are all based on device characteristics.
16130Sstevel@tonic-gate  * For fibre channel devices, the throttle value is usually
16140Sstevel@tonic-gate  * derived from the devices cmd Q depth divided by the number
16150Sstevel@tonic-gate  * of supported initiators.
16160Sstevel@tonic-gate  */
16170Sstevel@tonic-gate #define	ELITE_THROTTLE_VALUE		10
16180Sstevel@tonic-gate #define	SEAGATE_THROTTLE_VALUE		15
16190Sstevel@tonic-gate #define	IBM_THROTTLE_VALUE		15
16200Sstevel@tonic-gate #define	ST31200N_THROTTLE_VALUE		8
16210Sstevel@tonic-gate #define	FUJITSU_THROTTLE_VALUE		15
16220Sstevel@tonic-gate #define	SYMBIOS_THROTTLE_VALUE		16
16230Sstevel@tonic-gate #define	SYMBIOS_NOTREADY_RETRIES	24
16240Sstevel@tonic-gate #define	LSI_THROTTLE_VALUE		16
16250Sstevel@tonic-gate #define	LSI_NOTREADY_RETRIES		24
16260Sstevel@tonic-gate #define	LSI_OEM_NOTREADY_RETRIES	36
16270Sstevel@tonic-gate #define	PURPLE_THROTTLE_VALUE		64
16280Sstevel@tonic-gate #define	PURPLE_BUSY_RETRIES		60
16290Sstevel@tonic-gate #define	PURPLE_RESET_RETRY_COUNT	36
16300Sstevel@tonic-gate #define	PURPLE_RESERVE_RELEASE_TIME	60
16310Sstevel@tonic-gate #define	SVE_BUSY_RETRIES		60
16320Sstevel@tonic-gate #define	SVE_RESET_RETRY_COUNT		36
16330Sstevel@tonic-gate #define	SVE_RESERVE_RELEASE_TIME	60
16340Sstevel@tonic-gate #define	SVE_THROTTLE_VALUE		10
16350Sstevel@tonic-gate #define	SVE_MIN_THROTTLE_VALUE		2
16360Sstevel@tonic-gate #define	SVE_DISKSORT_DISABLED_FLAG	1
16370Sstevel@tonic-gate #define	MASERATI_DISKSORT_DISABLED_FLAG	1
16380Sstevel@tonic-gate #define	MASERATI_LUN_RESET_ENABLED_FLAG	1
16390Sstevel@tonic-gate #define	PIRUS_THROTTLE_VALUE		64
16400Sstevel@tonic-gate #define	PIRUS_NRR_COUNT			60
16410Sstevel@tonic-gate #define	PIRUS_BUSY_RETRIES		60
16420Sstevel@tonic-gate #define	PIRUS_RESET_RETRY_COUNT		36
16430Sstevel@tonic-gate #define	PIRUS_MIN_THROTTLE_VALUE	16
16440Sstevel@tonic-gate #define	PIRUS_DISKSORT_DISABLED_FLAG	0
16450Sstevel@tonic-gate #define	PIRUS_LUN_RESET_ENABLED_FLAG	1
16460Sstevel@tonic-gate 
16470Sstevel@tonic-gate /*
16480Sstevel@tonic-gate  * Driver Property Bit Flag definitions
16490Sstevel@tonic-gate  *
1650173Scth  * Unfortunately, for historical reasons, the bit-flag definitions are
16510Sstevel@tonic-gate  * different on SPARC, INTEL, & FIBRE platforms.
16520Sstevel@tonic-gate  */
16530Sstevel@tonic-gate 
16540Sstevel@tonic-gate /*
16550Sstevel@tonic-gate  * Bit flag telling driver to set throttle from sd.conf sd-config-list
16560Sstevel@tonic-gate  * and driver table.
16570Sstevel@tonic-gate  *
16580Sstevel@tonic-gate  * The max throttle (q-depth) property implementation is for support of
16590Sstevel@tonic-gate  * fibre channel devices that can drop an i/o request when a queue fills
16600Sstevel@tonic-gate  * up. The number of commands sent to the disk from this driver is
16610Sstevel@tonic-gate  * regulated such that queue overflows are avoided.
16620Sstevel@tonic-gate  */
16630Sstevel@tonic-gate #define	SD_CONF_SET_THROTTLE		0
16640Sstevel@tonic-gate #define	SD_CONF_BSET_THROTTLE		(1 << SD_CONF_SET_THROTTLE)
16650Sstevel@tonic-gate 
16660Sstevel@tonic-gate /*
16670Sstevel@tonic-gate  * Bit flag telling driver to set the controller type from sd.conf
16680Sstevel@tonic-gate  * sd-config-list and driver table.
16690Sstevel@tonic-gate  */
16700Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
16710Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
16720Sstevel@tonic-gate #elif defined(__fibre)
16730Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		5
16740Sstevel@tonic-gate #else
16750Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
16760Sstevel@tonic-gate #endif
16770Sstevel@tonic-gate #define	SD_CONF_BSET_CTYPE		(1 << SD_CONF_SET_CTYPE)
16780Sstevel@tonic-gate 
16790Sstevel@tonic-gate /*
16800Sstevel@tonic-gate  * Bit flag telling driver to set the not ready retry count for a device from
16810Sstevel@tonic-gate  * sd.conf sd-config-list and driver table.
16820Sstevel@tonic-gate  */
16830Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
16840Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	10
16850Sstevel@tonic-gate #elif defined(__fibre)
16860Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	1
16870Sstevel@tonic-gate #else
16880Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	2
16890Sstevel@tonic-gate #endif
16900Sstevel@tonic-gate #define	SD_CONF_BSET_NRR_COUNT		(1 << SD_CONF_SET_NOTREADY_RETRIES)
16910Sstevel@tonic-gate 
16920Sstevel@tonic-gate /*
16930Sstevel@tonic-gate  * Bit flag telling driver to set SCSI status BUSY Retries from sd.conf
16940Sstevel@tonic-gate  * sd-config-list and driver table.
16950Sstevel@tonic-gate  */
16960Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
16970Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	11
16980Sstevel@tonic-gate #elif defined(__fibre)
16990Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	2
17000Sstevel@tonic-gate #else
17010Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	5
17020Sstevel@tonic-gate #endif
17030Sstevel@tonic-gate #define	SD_CONF_BSET_BSY_RETRY_COUNT	(1 << SD_CONF_SET_BUSY_RETRIES)
17040Sstevel@tonic-gate 
17050Sstevel@tonic-gate /*
17060Sstevel@tonic-gate  * Bit flag telling driver that device does not have a valid/unique serial
17070Sstevel@tonic-gate  * number.
17080Sstevel@tonic-gate  */
17090Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17100Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		2
17110Sstevel@tonic-gate #else
17120Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		3
17130Sstevel@tonic-gate #endif
17140Sstevel@tonic-gate #define	SD_CONF_BSET_FAB_DEVID   	(1 << SD_CONF_SET_FAB_DEVID)
17150Sstevel@tonic-gate 
17160Sstevel@tonic-gate /*
17170Sstevel@tonic-gate  * Bit flag telling driver to disable all caching for disk device.
17180Sstevel@tonic-gate  */
17190Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17200Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		3
17210Sstevel@tonic-gate #else
17220Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		4
17230Sstevel@tonic-gate #endif
17240Sstevel@tonic-gate #define	SD_CONF_BSET_NOCACHE		(1 << SD_CONF_SET_NOCACHE)
17250Sstevel@tonic-gate 
17260Sstevel@tonic-gate /*
17270Sstevel@tonic-gate  * Bit flag telling driver that the PLAY AUDIO command requires parms in BCD
17280Sstevel@tonic-gate  * format rather than binary.
17290Sstevel@tonic-gate  */
17300Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17310Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		4
17320Sstevel@tonic-gate #else
17330Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		6
17340Sstevel@tonic-gate #endif
17350Sstevel@tonic-gate #define	SD_CONF_BSET_PLAYMSF_BCD    	(1 << SD_CONF_SET_PLAYMSF_BCD)
17360Sstevel@tonic-gate 
17370Sstevel@tonic-gate /*
17380Sstevel@tonic-gate  * Bit flag telling driver that the response from the READ SUBCHANNEL command
17390Sstevel@tonic-gate  * has BCD fields rather than binary.
17400Sstevel@tonic-gate  */
17410Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17420Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		5
17430Sstevel@tonic-gate #else
17440Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		7
17450Sstevel@tonic-gate #endif
17460Sstevel@tonic-gate #define	SD_CONF_BSET_READSUB_BCD	(1 << SD_CONF_SET_READSUB_BCD)
17470Sstevel@tonic-gate 
17480Sstevel@tonic-gate /*
17490Sstevel@tonic-gate  * Bit in flags telling driver that the track number fields in the READ TOC
17500Sstevel@tonic-gate  * request and respone are in BCD rather than binary.
17510Sstevel@tonic-gate  */
17520Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17530Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	6
17540Sstevel@tonic-gate #else
17550Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	8
17560Sstevel@tonic-gate #endif
17570Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_TRK_BCD	(1 << SD_CONF_SET_READ_TOC_TRK_BCD)
17580Sstevel@tonic-gate 
17590Sstevel@tonic-gate /*
17600Sstevel@tonic-gate  * Bit flag telling driver that the address fields in the READ TOC request and
17610Sstevel@tonic-gate  * respone are in BCD rather than binary.
17620Sstevel@tonic-gate  */
17630Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17640Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	7
17650Sstevel@tonic-gate #else
17660Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	9
17670Sstevel@tonic-gate #endif
17680Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_ADDR_BCD	(1 << SD_CONF_SET_READ_TOC_ADDR_BCD)
17690Sstevel@tonic-gate 
17700Sstevel@tonic-gate /*
17710Sstevel@tonic-gate  * Bit flag telling the driver that the device doesn't support the READ HEADER
17720Sstevel@tonic-gate  * command.
17730Sstevel@tonic-gate  */
17740Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17750Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	8
17760Sstevel@tonic-gate #else
17770Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	10
17780Sstevel@tonic-gate #endif
17790Sstevel@tonic-gate #define	SD_CONF_BSET_NO_READ_HEADER 	(1 << SD_CONF_SET_NO_READ_HEADER)
17800Sstevel@tonic-gate 
17810Sstevel@tonic-gate /*
17820Sstevel@tonic-gate  * Bit flag telling the driver that for the READ CD command the device uses
17830Sstevel@tonic-gate  * opcode 0xd4 rather than 0xbe.
17840Sstevel@tonic-gate  */
17850Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
17860Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4		9
17870Sstevel@tonic-gate #else
17880Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4 	11
17890Sstevel@tonic-gate #endif
17900Sstevel@tonic-gate #define	SD_CONF_BSET_READ_CD_XD4	(1 << SD_CONF_SET_READ_CD_XD4)
17910Sstevel@tonic-gate 
17920Sstevel@tonic-gate /*
17930Sstevel@tonic-gate  * Bit flag telling the driver to set SCSI status Reset Retries
17940Sstevel@tonic-gate  * (un_reset_retry_count) from sd.conf sd-config-list and driver table (4356701)
17950Sstevel@tonic-gate  */
17960Sstevel@tonic-gate #define	SD_CONF_SET_RST_RETRIES		12
17970Sstevel@tonic-gate #define	SD_CONF_BSET_RST_RETRIES	(1 << SD_CONF_SET_RST_RETRIES)
17980Sstevel@tonic-gate 
17990Sstevel@tonic-gate /*
18000Sstevel@tonic-gate  * Bit flag telling the driver to set the reservation release timeout value
18010Sstevel@tonic-gate  * from sd.conf sd-config-list and driver table. (4367306)
18020Sstevel@tonic-gate  */
18030Sstevel@tonic-gate #define	SD_CONF_SET_RSV_REL_TIME	13
18040Sstevel@tonic-gate #define	SD_CONF_BSET_RSV_REL_TIME	(1 << SD_CONF_SET_RSV_REL_TIME)
18050Sstevel@tonic-gate 
18060Sstevel@tonic-gate /*
18070Sstevel@tonic-gate  * Bit flag telling the driver to verify that no commands are pending for a
18080Sstevel@tonic-gate  * device before issuing a Test Unit Ready. This is a fw workaround for Seagate
18090Sstevel@tonic-gate  * eliteI drives. (4392016)
18100Sstevel@tonic-gate  */
18110Sstevel@tonic-gate #define	SD_CONF_SET_TUR_CHECK		14
18120Sstevel@tonic-gate #define	SD_CONF_BSET_TUR_CHECK		(1 << SD_CONF_SET_TUR_CHECK)
18130Sstevel@tonic-gate 
18140Sstevel@tonic-gate /*
18150Sstevel@tonic-gate  * Bit in flags telling driver to set min. throttle from ssd.conf
18160Sstevel@tonic-gate  * ssd-config-list and driver table.
18170Sstevel@tonic-gate  */
18180Sstevel@tonic-gate #define	SD_CONF_SET_MIN_THROTTLE	15
18190Sstevel@tonic-gate #define	SD_CONF_BSET_MIN_THROTTLE	(1 << SD_CONF_SET_MIN_THROTTLE)
18200Sstevel@tonic-gate 
18210Sstevel@tonic-gate /*
18220Sstevel@tonic-gate  * Bit in flags telling driver to set disksort disable flag from ssd.conf
18230Sstevel@tonic-gate  * ssd-config-list and driver table.
18240Sstevel@tonic-gate  */
18250Sstevel@tonic-gate #define	SD_CONF_SET_DISKSORT_DISABLED	16
18260Sstevel@tonic-gate #define	SD_CONF_BSET_DISKSORT_DISABLED	(1 << SD_CONF_SET_DISKSORT_DISABLED)
18270Sstevel@tonic-gate 
18280Sstevel@tonic-gate /*
18290Sstevel@tonic-gate  * Bit in flags telling driver to set LUN Reset enable flag from [s]sd.conf
18300Sstevel@tonic-gate  * [s]sd-config-list and driver table.
18310Sstevel@tonic-gate  */
18320Sstevel@tonic-gate #define	SD_CONF_SET_LUN_RESET_ENABLED	17
18330Sstevel@tonic-gate #define	SD_CONF_BSET_LUN_RESET_ENABLED	(1 << SD_CONF_SET_LUN_RESET_ENABLED)
18340Sstevel@tonic-gate 
18350Sstevel@tonic-gate /*
18360Sstevel@tonic-gate  * This is the number of items currently settable in the sd.conf
18370Sstevel@tonic-gate  * sd-config-list.  The mask value is defined for parameter checking. The
18380Sstevel@tonic-gate  * item count and mask should be updated when new properties are added.
18390Sstevel@tonic-gate  */
18400Sstevel@tonic-gate #define	SD_CONF_MAX_ITEMS		18
18410Sstevel@tonic-gate #define	SD_CONF_BIT_MASK		0x0003FFFF
18420Sstevel@tonic-gate 
18430Sstevel@tonic-gate typedef struct {
18440Sstevel@tonic-gate 	int sdt_throttle;
18450Sstevel@tonic-gate 	int sdt_ctype;
18460Sstevel@tonic-gate 	int sdt_not_rdy_retries;
18470Sstevel@tonic-gate 	int sdt_busy_retries;
18480Sstevel@tonic-gate 	int sdt_reset_retries;
18490Sstevel@tonic-gate 	int sdt_reserv_rel_time;
18500Sstevel@tonic-gate 	int sdt_min_throttle;
18510Sstevel@tonic-gate 	int sdt_disk_sort_dis;
18520Sstevel@tonic-gate 	int sdt_lun_reset_enable;
18530Sstevel@tonic-gate } sd_tunables;
18540Sstevel@tonic-gate 
18550Sstevel@tonic-gate /* Type definition for static configuration table entries */
18560Sstevel@tonic-gate typedef struct sd_disk_config {
18570Sstevel@tonic-gate 	char	device_id[25];
18580Sstevel@tonic-gate 	uint_t	flags;
18590Sstevel@tonic-gate 	sd_tunables *properties;
18600Sstevel@tonic-gate } sd_disk_config_t;
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate /*
18630Sstevel@tonic-gate  * byte 4 options for 1bh command
18640Sstevel@tonic-gate  */
18650Sstevel@tonic-gate #define	SD_TARGET_STOP			0x00
18660Sstevel@tonic-gate #define	SD_TARGET_START			0x01
18670Sstevel@tonic-gate #define	SD_TARGET_EJECT			0x02
18680Sstevel@tonic-gate #define	SD_TARGET_CLOSE			0x03
18690Sstevel@tonic-gate 
18700Sstevel@tonic-gate 
18710Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_CODE	0x03
18720Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_CODE	0x04
18730Sstevel@tonic-gate 
18740Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_LENGTH					\
18750Sstevel@tonic-gate 	(sizeof (struct mode_format) + MODE_PARAM_LENGTH)
18760Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_LENGTH					\
18770Sstevel@tonic-gate 	(sizeof (struct mode_geometry) + MODE_PARAM_LENGTH)
18780Sstevel@tonic-gate 
18790Sstevel@tonic-gate /*
18800Sstevel@tonic-gate  * These command codes need to be moved to sys/scsi/generic/commands.h
18810Sstevel@tonic-gate  */
18820Sstevel@tonic-gate 
18830Sstevel@tonic-gate /* Both versions of the Read CD command */
18840Sstevel@tonic-gate 
18850Sstevel@tonic-gate /* the official SCMD_READ_CD now comes from cdio.h */
18860Sstevel@tonic-gate #define	SCMD_READ_CDD4		0xd4	/* the one used by some first */
18870Sstevel@tonic-gate 					/* generation ATAPI CD drives */
18880Sstevel@tonic-gate 
18890Sstevel@tonic-gate /* expected sector type filter values for Play and Read CD CDBs */
18900Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_CDDA		(1<<2)	/* IEC 908:1987 (CDDA) */
18910Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE1		(2<<2)	/* Yellow book 2048 bytes */
18920Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2		(3<<2)	/* Yellow book 2335 bytes */
18930Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM1	(4<<2)	/* 2048 bytes */
18940Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM2	(5<<2)	/* 2324 bytes */
18950Sstevel@tonic-gate 
18960Sstevel@tonic-gate /* READ CD filter bits (cdb[9]) */
18970Sstevel@tonic-gate #define	CDROM_READ_CD_SYNC	0x80	/* read sync field */
18980Sstevel@tonic-gate #define	CDROM_READ_CD_HDR	0x20	/* read four byte header */
18990Sstevel@tonic-gate #define	CDROM_READ_CD_SUBHDR	0x40	/* read sub-header */
19000Sstevel@tonic-gate #define	CDROM_READ_CD_ALLHDRS	0x60	/* read header and sub-header */
19010Sstevel@tonic-gate #define	CDROM_READ_CD_USERDATA	0x10	/* read user data */
19020Sstevel@tonic-gate #define	CDROM_READ_CD_EDC_ECC	0x08	/* read EDC and ECC field */
19030Sstevel@tonic-gate #define	CDROM_READ_CD_C2	0x02	/* read C2 error data */
19040Sstevel@tonic-gate #define	CDROM_READ_CD_C2_BEB	0x04	/* read C2 and Block Error Bits */
19050Sstevel@tonic-gate 
19060Sstevel@tonic-gate 
19070Sstevel@tonic-gate /*
19080Sstevel@tonic-gate  * These belong in sys/scsi/generic/mode.h
19090Sstevel@tonic-gate  */
19100Sstevel@tonic-gate 
19110Sstevel@tonic-gate /*
19120Sstevel@tonic-gate  * Mode Sense/Select Header response for Group 2 CDB.
19130Sstevel@tonic-gate  */
19140Sstevel@tonic-gate 
19150Sstevel@tonic-gate struct mode_header_grp2 {
19160Sstevel@tonic-gate 	uchar_t length_msb;		/* MSB - number of bytes following */
19170Sstevel@tonic-gate 	uchar_t length_lsb;
19180Sstevel@tonic-gate 	uchar_t medium_type;		/* device specific */
19190Sstevel@tonic-gate 	uchar_t device_specific;	/* device specfic parameters */
19200Sstevel@tonic-gate 	uchar_t resv[2];		/* reserved */
19210Sstevel@tonic-gate 	uchar_t bdesc_length_hi;	/* length of block descriptor(s) */
19220Sstevel@tonic-gate 					/* (if any) */
19230Sstevel@tonic-gate 	uchar_t bdesc_length_lo;
19240Sstevel@tonic-gate };
19250Sstevel@tonic-gate 
19260Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", mode_header_grp2))
19270Sstevel@tonic-gate 
19280Sstevel@tonic-gate /*
19290Sstevel@tonic-gate  * Length of the Mode Parameter Header for the Group 2 Mode Select command
19300Sstevel@tonic-gate  */
19310Sstevel@tonic-gate #define	MODE_HEADER_LENGTH_GRP2	(sizeof (struct mode_header_grp2))
19320Sstevel@tonic-gate #define	MODE_PARAM_LENGTH_GRP2 (MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
19330Sstevel@tonic-gate 
19340Sstevel@tonic-gate /*
19350Sstevel@tonic-gate  * Mode Page 1 - Error Recovery Page
19360Sstevel@tonic-gate  */
19370Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOVER		1
19380Sstevel@tonic-gate 
19390Sstevel@tonic-gate /*
19400Sstevel@tonic-gate  * The following buffer length define is 8 bytes for the Group 2 mode page
19410Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 26 bytes for the cdrom
19420Sstevel@tonic-gate  * capabilities page (per MMC-2)
19430Sstevel@tonic-gate  */
19440Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP		0x2A
19450Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP_LEN		26
19460Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_CAP		(MODEPAGE_CDROM_CAP_LEN + \
19470Sstevel@tonic-gate 	MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
19480Sstevel@tonic-gate 
19490Sstevel@tonic-gate 
19500Sstevel@tonic-gate /*
19510Sstevel@tonic-gate  * Power management defines
19520Sstevel@tonic-gate  */
19530Sstevel@tonic-gate #define	SD_SPINDLE_UNINIT	(-1)
19540Sstevel@tonic-gate #define	SD_SPINDLE_OFF		0
19550Sstevel@tonic-gate #define	SD_SPINDLE_ON		1
19560Sstevel@tonic-gate #define	SD_PM_NOT_SUPPORTED	2
19570Sstevel@tonic-gate 
19580Sstevel@tonic-gate 
19590Sstevel@tonic-gate /*
19600Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
19610Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
19620Sstevel@tonic-gate  * the device active.
19630Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
19640Sstevel@tonic-gate  * the token is NULLed so check for this condition.
19650Sstevel@tonic-gate  * If there's a thread that can be resumed, ie. token is not NULL, then
19660Sstevel@tonic-gate  * it can be resumed.
19670Sstevel@tonic-gate  */
19680Sstevel@tonic-gate #define	SD_OK_TO_RESUME_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
19690Sstevel@tonic-gate /*
19700Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
19710Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
19720Sstevel@tonic-gate  * the device active.
19730Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
19740Sstevel@tonic-gate  * the token is NULLed so check for this condition.
19750Sstevel@tonic-gate  */
19760Sstevel@tonic-gate #define	SD_OK_TO_SUSPEND_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
19770Sstevel@tonic-gate #define	SD_DEVICE_IS_IN_LOW_POWER(un)		((un->un_f_pm_is_enabled) && \
19780Sstevel@tonic-gate 						    (un->un_pm_count < 0))
19790Sstevel@tonic-gate /*
19800Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
19810Sstevel@tonic-gate  * But for now let it live here.
19820Sstevel@tonic-gate  */
19830Sstevel@tonic-gate #define	START_STOP_CYCLE_COUNTER_PAGE_SIZE	0x28
19840Sstevel@tonic-gate #define	START_STOP_CYCLE_PAGE			0x0E
19850Sstevel@tonic-gate #define	START_STOP_CYCLE_VU_PAGE		0x31
19860Sstevel@tonic-gate 
19870Sstevel@tonic-gate /* CD-ROM Error Recovery Parameters page (0x01) */
19880Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOV	0x1
19890Sstevel@tonic-gate #define	BUFLEN_CHG_BLK_MODE	MODE_HEADER_LENGTH + MODE_BLK_DESC_LENGTH
19900Sstevel@tonic-gate 
19910Sstevel@tonic-gate /*
19920Sstevel@tonic-gate  * Vendor Specific (Toshiba) CD-ROM Speed page (0x31)
19930Sstevel@tonic-gate  *
19940Sstevel@tonic-gate  * The following buffer length define is 4 bytes for the Group 0 mode page
19950Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 4 bytes for the mode speed page.
19960Sstevel@tonic-gate  */
19970Sstevel@tonic-gate #define	MODEPAGE_CDROM_SPEED_LEN	4
19980Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_SPEED		MODEPAGE_CDROM_SPEED_LEN +\
19990Sstevel@tonic-gate 					MODE_HEADER_LENGTH +\
20000Sstevel@tonic-gate 					MODE_BLK_DESC_LENGTH
20010Sstevel@tonic-gate #define	SD_SPEED_1X			176
20020Sstevel@tonic-gate 
20030Sstevel@tonic-gate /* CD-ROM Audio Control Parameters page (0x0E) */
20040Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL		0x0E
20050Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL_LEN		16
20060Sstevel@tonic-gate 
20070Sstevel@tonic-gate /* CD-ROM Sony Read Offset Defines */
20080Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_LEN		12
20090Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_KEY		0x40
20100Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_VALID	0x0a
20110Sstevel@tonic-gate 
20120Sstevel@tonic-gate /*
20130Sstevel@tonic-gate  * CD-ROM Write Protect Defines
20140Sstevel@tonic-gate  *
20150Sstevel@tonic-gate  * Bit 7 of the device specific field of the mode page header is the write
20160Sstevel@tonic-gate  * protect bit.
20170Sstevel@tonic-gate  */
20180Sstevel@tonic-gate #define	WRITE_PROTECT 0x80
20190Sstevel@tonic-gate 
20200Sstevel@tonic-gate /*
20210Sstevel@tonic-gate  * Define for the length of a profile header returned in response to the
20220Sstevel@tonic-gate  * GET CONFIGURATION command
20230Sstevel@tonic-gate  */
20240Sstevel@tonic-gate #define	SD_PROFILE_HEADER_LEN		8	/* bytes */
20250Sstevel@tonic-gate 
20260Sstevel@tonic-gate /*
2027270Sphitran  * Define the length of the data in response to the GET CONFIGURATION
2028270Sphitran  * command.  The 3rd byte of the feature descriptor contains the
2029270Sphitran  * current feature field that is of interest.  This field begins
2030270Sphitran  * after the feature header which is 8 bytes.  This variable length
2031270Sphitran  * was increased in size from 11 to 24 because some devices became
2032270Sphitran  * unresponsive with the smaller size.
20330Sstevel@tonic-gate  */
2034270Sphitran #define	SD_CURRENT_FEATURE_LEN		24	/* bytes */
20350Sstevel@tonic-gate 
20360Sstevel@tonic-gate /*
20370Sstevel@tonic-gate  * Feature codes associated with GET CONFIGURATION command for supported
20380Sstevel@tonic-gate  * devices.
20390Sstevel@tonic-gate  */
20400Sstevel@tonic-gate #define	RANDOM_WRITABLE			0x20
20410Sstevel@tonic-gate #define	HARDWARE_DEFECT_MANAGEMENT	0x24
20420Sstevel@tonic-gate 
20430Sstevel@tonic-gate /*
20440Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
20450Sstevel@tonic-gate  * But for now let it live here.
20460Sstevel@tonic-gate  */
20470Sstevel@tonic-gate #define	TEMPERATURE_PAGE			0x0D
20480Sstevel@tonic-gate #define	TEMPERATURE_PAGE_SIZE			16	/* bytes */
20490Sstevel@tonic-gate 
20500Sstevel@tonic-gate /* delay time used for sd_media_watch_cb delayed cv broadcast */
20510Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 2000000
20520Sstevel@tonic-gate 
20530Sstevel@tonic-gate 
20540Sstevel@tonic-gate /* SCSI power on or bus device reset additional sense code */
20550Sstevel@tonic-gate #define	SD_SCSI_RESET_SENSE_CODE	0x29
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate /*
20580Sstevel@tonic-gate  * These defines are for the Vital Product Data Pages in the inquiry command.
20590Sstevel@tonic-gate  * They are the bits in the un_vpd_page mask, telling the supported pages.
20600Sstevel@tonic-gate  */
20610Sstevel@tonic-gate #define	SD_VPD_SUPPORTED_PG	0x01	/* 0x00 - Supported VPD pages */
20620Sstevel@tonic-gate #define	SD_VPD_UNIT_SERIAL_PG	0x02	/* 0x80 - Unit Serial Number */
20630Sstevel@tonic-gate #define	SD_VPD_OPERATING_PG	0x04	/* 0x81 - Implemented Op Defs */
20640Sstevel@tonic-gate #define	SD_VPD_ASCII_OP_PG	0x08	/* 0x82 - ASCII Op Defs */
20650Sstevel@tonic-gate #define	SD_VPD_DEVID_WWN_PG	0x10	/* 0x83 - Device Identification */
20660Sstevel@tonic-gate 
20670Sstevel@tonic-gate /*
20680Sstevel@tonic-gate  * Addition from sddef.intel.h
20690Sstevel@tonic-gate  */
20700Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
20710Sstevel@tonic-gate 
20720Sstevel@tonic-gate #define	P0_RAW_DISK	(NDKMAP)
20730Sstevel@tonic-gate #define	FDISK_P1	(NDKMAP+1)
20740Sstevel@tonic-gate #define	FDISK_P2	(NDKMAP+2)
20750Sstevel@tonic-gate #define	FDISK_P3	(NDKMAP+3)
20760Sstevel@tonic-gate #define	FDISK_P4	(NDKMAP+4)
20770Sstevel@tonic-gate 
20780Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
20790Sstevel@tonic-gate 
20800Sstevel@tonic-gate #ifdef	__cplusplus
20810Sstevel@tonic-gate }
20820Sstevel@tonic-gate #endif
20830Sstevel@tonic-gate 
20840Sstevel@tonic-gate 
20850Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_SDDEF_H */
2086