xref: /onnv-gate/usr/src/uts/common/sys/scsi/targets/sddef.h (revision 12916:b59c892bdcf4)
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
51489Swebaker  * Common Development and Distribution License (the "License").
61489Swebaker  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2212208SBo.Zhou@Sun.COM  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_SDDEF_H
260Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_SDDEF_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
290Sstevel@tonic-gate #include <sys/note.h>
300Sstevel@tonic-gate #include <sys/mhd.h>
313525Sshidokht #include <sys/cmlb.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifdef	__cplusplus
340Sstevel@tonic-gate extern "C" {
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate 
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #define	SD_SUCCESS		0
420Sstevel@tonic-gate #define	SD_FAILURE		(-1)
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #if defined(TRUE)
450Sstevel@tonic-gate #undef TRUE
460Sstevel@tonic-gate #endif
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #if defined(FALSE)
490Sstevel@tonic-gate #undef FALSE
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #define	TRUE			1
530Sstevel@tonic-gate #define	FALSE			0
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #if defined(VERBOSE)
560Sstevel@tonic-gate #undef VERBOSE
570Sstevel@tonic-gate #endif
580Sstevel@tonic-gate 
590Sstevel@tonic-gate #if defined(SILENT)
600Sstevel@tonic-gate #undef SILENT
610Sstevel@tonic-gate #endif
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /*
650Sstevel@tonic-gate  *  Fault Injection Flag for Inclusion of Code
660Sstevel@tonic-gate  *
670Sstevel@tonic-gate  *  This should only be defined when SDDEBUG is defined
680Sstevel@tonic-gate  * #if DEBUG || lint
690Sstevel@tonic-gate  * #define	SD_FAULT_INJECTION
700Sstevel@tonic-gate  * #endif
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate 
737570SDavid.Zhang@Sun.COM #if DEBUG || lint
747570SDavid.Zhang@Sun.COM #define	SD_FAULT_INJECTION
757570SDavid.Zhang@Sun.COM #endif
760Sstevel@tonic-gate #define	VERBOSE			1
770Sstevel@tonic-gate #define	SILENT			0
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * Structures for recording whether a device is fully open or closed.
810Sstevel@tonic-gate  * Assumptions:
820Sstevel@tonic-gate  *
830Sstevel@tonic-gate  *	+ There are only 8 (sparc) or 16 (x86) disk slices possible.
840Sstevel@tonic-gate  *	+ BLK, MNT, CHR, SWP don't change in some future release!
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate 
870Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
880Sstevel@tonic-gate 
890Sstevel@tonic-gate #define	SDUNIT_SHIFT	3
900Sstevel@tonic-gate #define	SDPART_MASK	7
910Sstevel@tonic-gate #define	NSDMAP		NDKMAP
920Sstevel@tonic-gate 
930Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
940Sstevel@tonic-gate 
9510021SSheshadri.Vasudevan@Sun.COM /*
9610021SSheshadri.Vasudevan@Sun.COM  * XXX - NSDMAP has multiple definitions, one more in cmlb_impl.h
9710021SSheshadri.Vasudevan@Sun.COM  * If they are coalesced into one, this definition will follow suit.
9810021SSheshadri.Vasudevan@Sun.COM  * FDISK partitions - 4 primary and MAX_EXT_PARTS number of Extended
9910021SSheshadri.Vasudevan@Sun.COM  * Partitions.
10010021SSheshadri.Vasudevan@Sun.COM  */
10110021SSheshadri.Vasudevan@Sun.COM #define	FDISK_PARTS		(FD_NUMPART + MAX_EXT_PARTS)
10210021SSheshadri.Vasudevan@Sun.COM 
1030Sstevel@tonic-gate #define	SDUNIT_SHIFT	6
1040Sstevel@tonic-gate #define	SDPART_MASK	63
10510021SSheshadri.Vasudevan@Sun.COM #define	NSDMAP		(NDKMAP + FDISK_PARTS + 1)
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #else
1080Sstevel@tonic-gate #error "No VTOC format defined."
1090Sstevel@tonic-gate #endif
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate #define	SDUNIT(dev)	(getminor((dev)) >> SDUNIT_SHIFT)
1130Sstevel@tonic-gate #define	SDPART(dev)	(getminor((dev)) &  SDPART_MASK)
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * maximum number of partitions the driver keeps track of; with
1170Sstevel@tonic-gate  * EFI this can be larger than the number of partitions accessible
1180Sstevel@tonic-gate  * through the minor nodes.  It won't be used for keeping track
1190Sstevel@tonic-gate  * of open counts, partition kstats, etc.
1200Sstevel@tonic-gate  */
1210Sstevel@tonic-gate #define	MAXPART		(NSDMAP + 1)
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate  * Macro to retrieve the DDI instance number from the given buf struct.
1250Sstevel@tonic-gate  * The instance number is encoded in the minor device number.
1260Sstevel@tonic-gate  */
12710131SJane.Chu@Sun.COM #define	SD_GET_INSTANCE_FROM_BUF(bp)				\
1280Sstevel@tonic-gate 	(getminor((bp)->b_edev) >> SDUNIT_SHIFT)
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate struct ocinfo {
1330Sstevel@tonic-gate 	/*
1340Sstevel@tonic-gate 	 * Types BLK, MNT, CHR, SWP,
1350Sstevel@tonic-gate 	 * assumed to be types 0-3.
1360Sstevel@tonic-gate 	 */
137433Sgz161490 	uint64_t  lyr_open[NSDMAP];
138433Sgz161490 	uint64_t  reg_open[OTYPCNT - 1];
1390Sstevel@tonic-gate };
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #define	OCSIZE  sizeof (struct ocinfo)
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate union ocmap {
1440Sstevel@tonic-gate 	uchar_t chkd[OCSIZE];
1450Sstevel@tonic-gate 	struct ocinfo rinfo;
1460Sstevel@tonic-gate };
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #define	lyropen rinfo.lyr_open
1490Sstevel@tonic-gate #define	regopen rinfo.reg_open
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate #define	SD_CDB_GROUP0		0
1530Sstevel@tonic-gate #define	SD_CDB_GROUP1		1
1540Sstevel@tonic-gate #define	SD_CDB_GROUP5		2
1550Sstevel@tonic-gate #define	SD_CDB_GROUP4		3
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate struct sd_cdbinfo {
1580Sstevel@tonic-gate 	uchar_t	 sc_grpcode;	/* CDB group code */
1590Sstevel@tonic-gate 	uchar_t  sc_grpmask;	/* CDB group code mask (for cmd opcode) */
1600Sstevel@tonic-gate 	uint64_t sc_maxlba;	/* Maximum logical block addr. supported */
1610Sstevel@tonic-gate 	uint32_t sc_maxlen;	/* Maximum transfer length supported */
1620Sstevel@tonic-gate };
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate /*
1670Sstevel@tonic-gate  * The following declaration are for Non-512 byte block support for the
1680Sstevel@tonic-gate  * removable devices. (ex - DVD RAM, MO).
1690Sstevel@tonic-gate  * wm_state: This is an enumeration for the different states for
1700Sstevel@tonic-gate  * manipalating write range list during the read-modify-write-operation.
1710Sstevel@tonic-gate  */
1720Sstevel@tonic-gate typedef enum {
1730Sstevel@tonic-gate 	SD_WM_CHK_LIST,		/* Check list for overlapping writes */
1740Sstevel@tonic-gate 	SD_WM_WAIT_MAP,		/* Wait for an overlapping I/O to complete */
1750Sstevel@tonic-gate 	SD_WM_LOCK_RANGE,	/* Lock the range of lba to be written */
1760Sstevel@tonic-gate 	SD_WM_DONE		/* I/O complete */
1770Sstevel@tonic-gate } wm_state;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate /*
1800Sstevel@tonic-gate  * sd_w_map: Every write I/O will get one w_map allocated for it which will tell
1810Sstevel@tonic-gate  * the range on the media which is being written for that request.
1820Sstevel@tonic-gate  */
1830Sstevel@tonic-gate struct sd_w_map {
1840Sstevel@tonic-gate 	uint_t		wm_start;	/* Write start location */
1850Sstevel@tonic-gate 	uint_t		wm_end;		/* Write end location */
1860Sstevel@tonic-gate 	ushort_t	wm_flags;	/* State of the wmap */
1870Sstevel@tonic-gate 	ushort_t	wm_wanted_count; /* # of threads waiting for region */
1880Sstevel@tonic-gate 	void		*wm_private;	/* Used to store bp->b_private */
1890Sstevel@tonic-gate 	struct buf	*wm_bufp;	/* to store buf pointer */
1900Sstevel@tonic-gate 	struct sd_w_map	*wm_next;	/* Forward pointed to sd_w_map */
1910Sstevel@tonic-gate 	struct sd_w_map	*wm_prev;	/* Back pointer to sd_w_map */
1920Sstevel@tonic-gate 	kcondvar_t	wm_avail;	/* Sleep on this, while not available */
1930Sstevel@tonic-gate };
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_w_map::wm_flags))
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate /*
1990Sstevel@tonic-gate  * This is the struct for the layer-private data area for the
2000Sstevel@tonic-gate  * mapblocksize layer.
2010Sstevel@tonic-gate  */
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate struct sd_mapblocksize_info {
2040Sstevel@tonic-gate 	void		*mbs_oprivate;	/* saved value of xb_private */
2050Sstevel@tonic-gate 	struct buf	*mbs_orig_bp;	/* ptr to original bp */
2060Sstevel@tonic-gate 	struct sd_w_map	*mbs_wmp;	/* ptr to write-map struct for RMW */
2070Sstevel@tonic-gate 	ssize_t		mbs_copy_offset;
2080Sstevel@tonic-gate 	int		mbs_layer_index;	/* chain index for RMW */
2090Sstevel@tonic-gate };
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_mapblocksize_info))
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * sd_lun: The main data structure for a scsi logical unit.
2160Sstevel@tonic-gate  * Stored as the softstate structure for each device.
2170Sstevel@tonic-gate  */
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate struct sd_lun {
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 	/* Back ptr to the SCSA scsi_device struct for this LUN */
2220Sstevel@tonic-gate 	struct scsi_device	*un_sd;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 	/*
2250Sstevel@tonic-gate 	 * Support for Auto-Request sense capability
2260Sstevel@tonic-gate 	 */
2270Sstevel@tonic-gate 	struct buf	*un_rqs_bp;	/* ptr to request sense bp */
2280Sstevel@tonic-gate 	struct scsi_pkt	*un_rqs_pktp;	/* ptr to request sense scsi_pkt */
2290Sstevel@tonic-gate 	int	un_sense_isbusy;	/* Busy flag for RQS buf */
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 	/*
2320Sstevel@tonic-gate 	 * These specify the layering chains to use with this instance. These
2330Sstevel@tonic-gate 	 * are initialized according to the values in the sd_chain_index_map[]
2340Sstevel@tonic-gate 	 * array. See the description of sd_chain_index_map[] for details.
2350Sstevel@tonic-gate 	 */
2360Sstevel@tonic-gate 	int un_buf_chain_type;
2370Sstevel@tonic-gate 	int un_uscsi_chain_type;
2380Sstevel@tonic-gate 	int un_direct_chain_type;
2390Sstevel@tonic-gate 	int un_priority_chain_type;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	/* Head & tail ptrs to the queue of bufs awaiting transport */
2420Sstevel@tonic-gate 	struct buf	*un_waitq_headp;
2430Sstevel@tonic-gate 	struct buf	*un_waitq_tailp;
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	/* Ptr to the buf currently being retried (NULL if none) */
2460Sstevel@tonic-gate 	struct buf	*un_retry_bp;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	/* This tracks the last kstat update for the un_retry_bp buf */
2490Sstevel@tonic-gate 	void		(*un_retry_statp)(kstat_io_t *);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	void		*un_xbuf_attr;	/* xbuf attribute struct */
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 	/* System logical block size, in bytes. (defaults to DEV_BSIZE.) */
2550Sstevel@tonic-gate 	uint32_t	un_sys_blocksize;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/* The size of a logical block on the target, in bytes. */
2580Sstevel@tonic-gate 	uint32_t	un_tgt_blocksize;
2590Sstevel@tonic-gate 
26012208SBo.Zhou@Sun.COM 	/* The size of a physical block on the target, in bytes. */
26112208SBo.Zhou@Sun.COM 	uint32_t	un_phy_blocksize;
26212208SBo.Zhou@Sun.COM 
2630Sstevel@tonic-gate 	/*
2640Sstevel@tonic-gate 	 * The number of logical blocks on the target. This is adjusted
2650Sstevel@tonic-gate 	 * to be in terms of the block size specified by un_sys_blocksize
2660Sstevel@tonic-gate 	 * (ie, the system block size).
2670Sstevel@tonic-gate 	 */
2680Sstevel@tonic-gate 	uint64_t	un_blockcount;
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	/*
2710Sstevel@tonic-gate 	 * Various configuration data
2720Sstevel@tonic-gate 	 */
2730Sstevel@tonic-gate 	uchar_t	un_ctype;		/* Controller type */
2740Sstevel@tonic-gate 	char 	*un_node_type;		/* minor node type */
2750Sstevel@tonic-gate 	uchar_t	un_interconnect_type;	/* Interconnect for underlying HBA */
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	uint_t	un_notready_retry_count; /* Per disk notready retry count */
2780Sstevel@tonic-gate 	uint_t	un_busy_retry_count;	/* Per disk BUSY retry count */
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 	uint_t	un_retry_count;		/* Per disk retry count */
2810Sstevel@tonic-gate 	uint_t	un_victim_retry_count;	/* Per disk victim retry count */
2820Sstevel@tonic-gate 
2830Sstevel@tonic-gate 	/* (4356701, 4367306) */
2840Sstevel@tonic-gate 	uint_t	un_reset_retry_count; /* max io retries before issuing reset */
2850Sstevel@tonic-gate 	ushort_t un_reserve_release_time; /* reservation release timeout */
2860Sstevel@tonic-gate 
2870Sstevel@tonic-gate 	uchar_t	un_reservation_type;	/* SCSI-3 or SCSI-2 */
2880Sstevel@tonic-gate 	uint_t	un_max_xfer_size;	/* Maximum DMA transfer size */
2895595Slh195018 	int	un_partial_dma_supported;
2908551SPeng.L@Sun.COM 	int	un_buf_breakup_supported;
2910Sstevel@tonic-gate 
2920Sstevel@tonic-gate 	int	un_mincdb;		/* Smallest CDB to use */
2930Sstevel@tonic-gate 	int	un_maxcdb;		/* Largest CDB to use */
2941960Slh195018 	int	un_max_hba_cdb;		/* Largest CDB supported by HBA */
2950Sstevel@tonic-gate 	int	un_status_len;
2960Sstevel@tonic-gate 	int	un_pkt_flags;
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	/*
2990Sstevel@tonic-gate 	 * Note: un_uscsi_timeout is a "mirror" of un_cmd_timeout, adjusted
3000Sstevel@tonic-gate 	 * for ISCD().  Any updates to un_cmd_timeout MUST be reflected
3010Sstevel@tonic-gate 	 * in un_uscsi_timeout as well!
3020Sstevel@tonic-gate 	 */
3030Sstevel@tonic-gate 	ushort_t un_cmd_timeout;	/* Timeout for completion */
3040Sstevel@tonic-gate 	ushort_t un_uscsi_timeout;	/* Timeout for USCSI completion */
3057339SNikko He 	ushort_t un_busy_timeout;	/* Timeout for busy retry */
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	/*
3080Sstevel@tonic-gate 	 * Info on current states, statuses, etc. (Updated frequently)
3090Sstevel@tonic-gate 	 */
3100Sstevel@tonic-gate 	uchar_t	un_state;		/* current state */
3110Sstevel@tonic-gate 	uchar_t	un_last_state;		/* last state */
3120Sstevel@tonic-gate 	uchar_t	un_last_pkt_reason;	/* used to suppress multiple msgs */
3130Sstevel@tonic-gate 	int	un_tagflags;		/* Pkt Flags for Tagged Queueing  */
3140Sstevel@tonic-gate 	short	un_resvd_status;	/* Reservation Status */
3150Sstevel@tonic-gate 	ulong_t	un_detach_count;	/* !0 if executing detach routine */
3160Sstevel@tonic-gate 	ulong_t	un_layer_count;		/* Current total # of layered opens */
3170Sstevel@tonic-gate 	ulong_t un_opens_in_progress;	/* Current # of threads in sdopen */
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	ksema_t	un_semoclose;		/* serialize opens/closes */
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 	/*
3220Sstevel@tonic-gate 	 * Control & status info for command throttling
3230Sstevel@tonic-gate 	 */
3240Sstevel@tonic-gate 	long	un_ncmds_in_driver;	/* number of cmds in driver */
3250Sstevel@tonic-gate 	short	un_ncmds_in_transport;	/* number of cmds in transport */
3260Sstevel@tonic-gate 	short	un_throttle;		/* max #cmds allowed in transport */
3270Sstevel@tonic-gate 	short	un_saved_throttle;	/* saved value of un_throttle */
3280Sstevel@tonic-gate 	short	un_busy_throttle;	/* saved un_throttle for BUSY */
3290Sstevel@tonic-gate 	short	un_min_throttle;	/* min value of un_throttle */
3300Sstevel@tonic-gate 	timeout_id_t	un_reset_throttle_timeid; /* timeout(9F) handle */
3310Sstevel@tonic-gate 
3320Sstevel@tonic-gate 	/*
3330Sstevel@tonic-gate 	 * Multi-host (clustering) support
3340Sstevel@tonic-gate 	 */
3350Sstevel@tonic-gate 	opaque_t	un_mhd_token;		/* scsi watch request */
3360Sstevel@tonic-gate 	timeout_id_t	un_resvd_timeid;	/* for resvd recover */
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 	/* Event callback resources (photon) */
3390Sstevel@tonic-gate 	ddi_eventcookie_t un_insert_event;	/* insert event */
3400Sstevel@tonic-gate 	ddi_callback_id_t un_insert_cb_id;	/* insert callback */
3410Sstevel@tonic-gate 	ddi_eventcookie_t un_remove_event;	/* remove event */
3420Sstevel@tonic-gate 	ddi_callback_id_t un_remove_cb_id;	/* remove callback */
3430Sstevel@tonic-gate 
3440Sstevel@tonic-gate 	uint_t		un_start_stop_cycle_page;	/* Saves start/stop */
3450Sstevel@tonic-gate 							/* cycle page */
3460Sstevel@tonic-gate 	timeout_id_t	un_dcvb_timeid;		/* dlyd cv broadcast */
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate 	/*
3490Sstevel@tonic-gate 	 * Data structures for open counts, partition info, VTOC,
3500Sstevel@tonic-gate 	 * stats, and other such bookkeeping info.
3510Sstevel@tonic-gate 	 */
3520Sstevel@tonic-gate 	union	ocmap	un_ocmap;		/* open partition map */
3530Sstevel@tonic-gate 	struct	kstat	*un_pstats[NSDMAP];	/* partition statistics */
3540Sstevel@tonic-gate 	struct	kstat	*un_stats;		/* disk statistics */
3550Sstevel@tonic-gate 	kstat_t		*un_errstats;		/* for error statistics */
356433Sgz161490 	uint64_t	un_exclopen;		/* exclusive open bitmask */
3570Sstevel@tonic-gate 	ddi_devid_t	un_devid;		/* device id */
3580Sstevel@tonic-gate 	uint_t		un_vpd_page_mask;	/* Supported VPD pages */
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	/*
3610Sstevel@tonic-gate 	 * Bit fields for various configuration/state/status info.
3620Sstevel@tonic-gate 	 * Comments indicate the condition if the value of the
363173Scth 	 * variable is TRUE (nonzero).
3640Sstevel@tonic-gate 	 */
3650Sstevel@tonic-gate 	uint32_t
3660Sstevel@tonic-gate 	    un_f_arq_enabled		:1,	/* Auto request sense is */
3670Sstevel@tonic-gate 						/* currently enabled */
3680Sstevel@tonic-gate 	    un_f_blockcount_is_valid	:1,	/* The un_blockcount */
3690Sstevel@tonic-gate 						/* value is currently valid */
3700Sstevel@tonic-gate 	    un_f_tgt_blocksize_is_valid	:1,	/* The un_tgt_blocksize */
3710Sstevel@tonic-gate 						/* value is currently valid */
3720Sstevel@tonic-gate 	    un_f_allow_bus_device_reset	:1,	/* Driver may issue a BDR as */
3730Sstevel@tonic-gate 						/* a part of error recovery. */
3740Sstevel@tonic-gate 	    un_f_is_fibre		:1,	/* The device supports fibre */
3750Sstevel@tonic-gate 						/* channel */
3761415Scg149915 	    un_f_sync_cache_supported	:1,	/* sync cache cmd supported */
377789Sahrens 						/* supported */
3780Sstevel@tonic-gate 	    un_f_format_in_progress	:1,	/* The device is currently */
3790Sstevel@tonic-gate 						/* executing a FORMAT cmd. */
3800Sstevel@tonic-gate 	    un_f_opt_queueing		:1,	/* Enable Command Queuing to */
3810Sstevel@tonic-gate 						/* Host Adapter */
3820Sstevel@tonic-gate 	    un_f_opt_fab_devid		:1,	/* Disk has no valid/unique */
3830Sstevel@tonic-gate 						/* serial number.  */
3840Sstevel@tonic-gate 	    un_f_opt_disable_cache	:1,	/* Read/Write disk cache is */
3850Sstevel@tonic-gate 						/* disabled.  */
3860Sstevel@tonic-gate 	    un_f_cfg_is_atapi		:1,	/* This is an ATAPI device.  */
387789Sahrens 	    un_f_write_cache_enabled	:1,	/* device return success on */
388789Sahrens 						/* writes before transfer to */
389789Sahrens 						/* physical media complete */
3900Sstevel@tonic-gate 	    un_f_cfg_playmsf_bcd	:1,	/* Play Audio, BCD params. */
3910Sstevel@tonic-gate 	    un_f_cfg_readsub_bcd	:1,	/* READ SUBCHANNEL BCD resp. */
3920Sstevel@tonic-gate 	    un_f_cfg_read_toc_trk_bcd	:1,	/* track # is BCD */
3930Sstevel@tonic-gate 	    un_f_cfg_read_toc_addr_bcd	:1,	/* address is BCD */
3940Sstevel@tonic-gate 	    un_f_cfg_no_read_header	:1,	/* READ HEADER not supported */
3950Sstevel@tonic-gate 	    un_f_cfg_read_cd_xd4	:1,	/* READ CD opcode is 0xd4 */
3960Sstevel@tonic-gate 	    un_f_mmc_cap		:1,	/* Device is MMC compliant */
3970Sstevel@tonic-gate 	    un_f_mmc_writable_media	:1,	/* writable media in device */
3980Sstevel@tonic-gate 	    un_f_dvdram_writable_device	:1,	/* DVDRAM device is writable */
3990Sstevel@tonic-gate 	    un_f_cfg_cdda		:1,	/* READ CDDA supported */
4000Sstevel@tonic-gate 	    un_f_cfg_tur_check		:1,	/* verify un_ncmds before tur */
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 	    un_f_use_adaptive_throttle	:1,	/* enable/disable adaptive */
4030Sstevel@tonic-gate 						/* throttling */
4040Sstevel@tonic-gate 	    un_f_pm_is_enabled		:1,	/* PM is enabled on this */
4050Sstevel@tonic-gate 						/* instance */
4060Sstevel@tonic-gate 	    un_f_watcht_stopped		:1,	/* media watch thread flag */
4070Sstevel@tonic-gate 	    un_f_pkstats_enabled	:1,	/* Flag to determine if */
4080Sstevel@tonic-gate 						/* partition kstats are */
4090Sstevel@tonic-gate 						/* enabled. */
4100Sstevel@tonic-gate 	    un_f_disksort_disabled	:1,	/* Flag to disable disksort */
4110Sstevel@tonic-gate 	    un_f_lun_reset_enabled	:1,	/* Set if target supports */
4120Sstevel@tonic-gate 						/* SCSI Logical Unit Reset */
4130Sstevel@tonic-gate 	    un_f_doorlock_supported	:1,	/* Device supports Doorlock */
4143525Sshidokht 	    un_f_start_stop_supported	:1,	/* device has motor */
4153525Sshidokht 	    un_f_reserved1		:1;
4160Sstevel@tonic-gate 
4171415Scg149915 	uint32_t
4181415Scg149915 	    un_f_mboot_supported	:1,	/* mboot supported */
4191415Scg149915 	    un_f_is_hotpluggable	:1,	/* hotpluggable */
4201415Scg149915 	    un_f_has_removable_media	:1,	/* has removable media */
4211415Scg149915 	    un_f_non_devbsize_supported	:1,	/* non-512 blocksize */
4221415Scg149915 	    un_f_devid_supported	:1,	/* device ID supported */
4231415Scg149915 	    un_f_eject_media_supported	:1,	/* media can be ejected */
4241415Scg149915 	    un_f_chk_wp_open		:1,	/* check if write-protected */
4251415Scg149915 						/* when being opened */
4261415Scg149915 	    un_f_descr_format_supported	:1,	/* support descriptor format */
4271415Scg149915 						/* for sense data */
4281415Scg149915 	    un_f_check_start_stop	:1,	/* needs to check if */
4291415Scg149915 						/* START-STOP command is */
4301415Scg149915 						/* supported by hardware */
4311415Scg149915 						/* before issuing it */
4321415Scg149915 	    un_f_monitor_media_state	:1,	/* need a watch thread to */
4331415Scg149915 						/* monitor device state */
4341415Scg149915 	    un_f_attach_spinup		:1,	/* spin up once the */
4351415Scg149915 						/* device is attached */
4361415Scg149915 	    un_f_log_sense_supported	:1,	/* support log sense */
4371415Scg149915 	    un_f_pm_supported		:1, 	/* support power-management */
4381489Swebaker 	    un_f_cfg_is_lsi		:1,	/* Is LSI device, */
4391489Swebaker 						/* default to NO */
4401489Swebaker 	    un_f_wcc_inprog		:1,	/* write cache change in */
4411489Swebaker 						/* progress */
4423475Szk194757 	    un_f_ejecting		:1,	/* media is ejecting */
4435065Sgz161490 	    un_f_suppress_cache_flush	:1,	/* supress flush on */
4445065Sgz161490 						/* write cache */
4455065Sgz161490 	    un_f_sync_nv_supported	:1,	/* SYNC_NV */
4465065Sgz161490 						/* bit is supported */
4477355SSheshadri.Vasudevan@Sun.COM 	    un_f_sync_cache_required	:1,	/* flag to check if */
4487355SSheshadri.Vasudevan@Sun.COM 						/* SYNC CACHE needs to be */
4497355SSheshadri.Vasudevan@Sun.COM 						/* sent in sdclose */
4509066SPrasad.Singamsetty@Sun.COM 	    un_f_devid_transport_defined :1,	/* devid defined by transport */
4519889SLarry.Liu@Sun.COM 	    un_f_rmw_type		 :2,	/* RMW type */
45210131SJane.Chu@Sun.COM 	    un_f_power_condition_disabled :1,	/* power condition disabled */
45310131SJane.Chu@Sun.COM 						/* through sd configuration */
45410131SJane.Chu@Sun.COM 	    un_f_power_condition_supported :1,	/* support power condition */
45510131SJane.Chu@Sun.COM 						/* field by hardware */
45610131SJane.Chu@Sun.COM 	    un_f_pm_log_sense_smart	:1,	/* log sense support SMART */
45710131SJane.Chu@Sun.COM 						/* feature attribute */
45810320SLarry.Liu@Sun.COM 	    un_f_is_solid_state		:1,	/* has solid state media */
45910459SArtem.Kachitchkin@Sun.COM 	    un_f_mmc_gesn_polling	:1,	/* use GET EVENT STATUS */
46010459SArtem.Kachitchkin@Sun.COM 						/* NOTIFICATION for polling */
46112208SBo.Zhou@Sun.COM 	    un_f_enable_rmw		:1,	/* Force RMW in sd driver */
46212318SEric.Taylor@Sun.COM 	    un_f_expnevent		:1,
46312318SEric.Taylor@Sun.COM 	    un_f_reserved		:3;
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	/* Ptr to table of strings for ASC/ASCQ error message printing */
4660Sstevel@tonic-gate 	struct scsi_asq_key_strings	*un_additional_codes;
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	/*
4690Sstevel@tonic-gate 	 * Power Management support.
4700Sstevel@tonic-gate 	 *
4710Sstevel@tonic-gate 	 * un_pm_mutex protects, un_pm_count, un_pm_timeid, un_pm_busy,
4720Sstevel@tonic-gate 	 * un_pm_busy_cv, and un_pm_idle_timeid.
4730Sstevel@tonic-gate 	 * It's not required that SD_MUTEX be acquired before acquiring
4740Sstevel@tonic-gate 	 * un_pm_mutex, however if they must both be held
4750Sstevel@tonic-gate 	 * then acquire SD_MUTEX first.
4760Sstevel@tonic-gate 	 *
4770Sstevel@tonic-gate 	 * un_pm_count is used to indicate PM state as follows:
4780Sstevel@tonic-gate 	 *	less than 0 the device is powered down,
4790Sstevel@tonic-gate 	 *	transition from 0 ==> 1, mark the device as busy via DDI
4800Sstevel@tonic-gate 	 *	transition from 1 ==> 0, mark the device as idle via DDI
4810Sstevel@tonic-gate 	 */
4820Sstevel@tonic-gate 	kmutex_t	un_pm_mutex;
4830Sstevel@tonic-gate 	int		un_pm_count;		/* indicates pm state */
4840Sstevel@tonic-gate 	timeout_id_t	un_pm_timeid;		/* timeout id for pm */
4850Sstevel@tonic-gate 	uint_t		un_pm_busy;
4860Sstevel@tonic-gate 	kcondvar_t	un_pm_busy_cv;
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 */
5029889SLarry.Liu@Sun.COM 	uint64_t	un_rmw_incre_count;	/* count I/O */
5039889SLarry.Liu@Sun.COM 	timeout_id_t	un_rmw_msg_timeid;	/* for RMW message control */
5040Sstevel@tonic-gate 
5050Sstevel@tonic-gate 	/* For timeout callback to issue a START STOP UNIT command */
5060Sstevel@tonic-gate 	timeout_id_t	un_startstop_timeid;
5070Sstevel@tonic-gate 
5080Sstevel@tonic-gate 	/* Timeout callback handle for SD_PATH_DIRECT_PRIORITY cmd restarts */
5090Sstevel@tonic-gate 	timeout_id_t	un_direct_priority_timeid;
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 	/* TRAN_FATAL_ERROR count. Cleared by TRAN_ACCEPT from scsi_transport */
5120Sstevel@tonic-gate 	ulong_t		un_tran_fatal_count;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	timeout_id_t	un_retry_timeid;
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	time_t		un_pm_idle_time;
5170Sstevel@tonic-gate 	timeout_id_t	un_pm_idle_timeid;
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate 	/*
5200Sstevel@tonic-gate 	 * Count to determine if a Sonoma controller is in the process of
5210Sstevel@tonic-gate 	 * failing over, and how many I/O's are failed with the 05/94/01
5220Sstevel@tonic-gate 	 * sense code.
5230Sstevel@tonic-gate 	 */
5240Sstevel@tonic-gate 	uint_t		un_sonoma_failure_count;
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate 	/*
5270Sstevel@tonic-gate 	 * Support for failfast operation.
5280Sstevel@tonic-gate 	 */
5290Sstevel@tonic-gate 	struct buf	*un_failfast_bp;
5300Sstevel@tonic-gate 	struct buf	*un_failfast_headp;
5310Sstevel@tonic-gate 	struct buf	*un_failfast_tailp;
5320Sstevel@tonic-gate 	uint32_t	un_failfast_state;
5330Sstevel@tonic-gate 	/* Callback routine active counter */
5340Sstevel@tonic-gate 	short		un_in_callback;
5350Sstevel@tonic-gate 
5361489Swebaker 	kcondvar_t	un_wcc_cv;	/* synchronize changes to */
5371489Swebaker 					/* un_f_write_cache_enabled */
538313Sts143224 
5390Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
5400Sstevel@tonic-gate 	/* SD Fault Injection */
5410Sstevel@tonic-gate #define	SD_FI_MAX_BUF 65536
5420Sstevel@tonic-gate #define	SD_FI_MAX_ERROR 1024
5430Sstevel@tonic-gate 	kmutex_t			un_fi_mutex;
5440Sstevel@tonic-gate 	uint_t				sd_fi_buf_len;
5450Sstevel@tonic-gate 	char				sd_fi_log[SD_FI_MAX_BUF];
5460Sstevel@tonic-gate 	struct sd_fi_pkt	*sd_fi_fifo_pkt[SD_FI_MAX_ERROR];
5470Sstevel@tonic-gate 	struct sd_fi_xb		*sd_fi_fifo_xb[SD_FI_MAX_ERROR];
5480Sstevel@tonic-gate 	struct sd_fi_un		*sd_fi_fifo_un[SD_FI_MAX_ERROR];
5490Sstevel@tonic-gate 	struct sd_fi_arq	*sd_fi_fifo_arq[SD_FI_MAX_ERROR];
5500Sstevel@tonic-gate 	uint_t				sd_fi_fifo_start;
5510Sstevel@tonic-gate 	uint_t				sd_fi_fifo_end;
5520Sstevel@tonic-gate 	uint_t				sd_injection_mask;
5533525Sshidokht 
5540Sstevel@tonic-gate #endif
5550Sstevel@tonic-gate 
5563525Sshidokht 	cmlb_handle_t	un_cmlbhandle;
5577570SDavid.Zhang@Sun.COM 
5587570SDavid.Zhang@Sun.COM 	/*
5597570SDavid.Zhang@Sun.COM 	 * Pointer to internal struct sd_fm_internal in which
5607570SDavid.Zhang@Sun.COM 	 * will pass necessary information for FMA ereport posting.
5617570SDavid.Zhang@Sun.COM 	 */
5627570SDavid.Zhang@Sun.COM 	void		*un_fm_private;
5630Sstevel@tonic-gate };
5640Sstevel@tonic-gate 
5653525Sshidokht #define	SD_IS_VALID_LABEL(un)  (cmlb_is_valid(un->un_cmlbhandle))
5660Sstevel@tonic-gate 
5670Sstevel@tonic-gate /*
5680Sstevel@tonic-gate  * Macros for conversions between "target" and "system" block sizes, and
5690Sstevel@tonic-gate  * for conversion between block counts and byte counts.  As used here,
5700Sstevel@tonic-gate  * "system" block size refers to the block size used by the kernel/
5710Sstevel@tonic-gate  * filesystem (this includes the disk label). The "target" block size
572173Scth  * is the block size returned by the SCSI READ CAPACITY command.
5730Sstevel@tonic-gate  *
5740Sstevel@tonic-gate  * Note: These macros will round up to the next largest blocksize to accomodate
5750Sstevel@tonic-gate  * the number of blocks specified.
5760Sstevel@tonic-gate  */
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate /* Convert a byte count to a number of target blocks */
5790Sstevel@tonic-gate #define	SD_BYTES2TGTBLOCKS(un, bytecount)				\
5800Sstevel@tonic-gate 	((bytecount + (un->un_tgt_blocksize - 1))/un->un_tgt_blocksize)
5810Sstevel@tonic-gate 
58212208SBo.Zhou@Sun.COM /* Convert a byte count to a number of physical blocks */
58312208SBo.Zhou@Sun.COM #define	SD_BYTES2PHYBLOCKS(un, bytecount)				\
58412208SBo.Zhou@Sun.COM 	((bytecount + (un->un_phy_blocksize - 1))/un->un_phy_blocksize)
58512208SBo.Zhou@Sun.COM 
5860Sstevel@tonic-gate /* Convert a target block count to a number of bytes */
5870Sstevel@tonic-gate #define	SD_TGTBLOCKS2BYTES(un, blockcount)				\
5880Sstevel@tonic-gate 	(blockcount * (un)->un_tgt_blocksize)
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate /* Convert a byte count to a number of system blocks */
5919889SLarry.Liu@Sun.COM #define	SD_BYTES2SYSBLOCKS(bytecount)				\
5929889SLarry.Liu@Sun.COM 	((bytecount + (DEV_BSIZE - 1))/DEV_BSIZE)
5930Sstevel@tonic-gate 
5940Sstevel@tonic-gate /* Convert a system block count to a number of bytes */
5959889SLarry.Liu@Sun.COM #define	SD_SYSBLOCKS2BYTES(blockcount)				\
5969889SLarry.Liu@Sun.COM 	(blockcount * DEV_BSIZE)
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate /*
5990Sstevel@tonic-gate  * Calculate the number of bytes needed to hold the requested number of bytes
6000Sstevel@tonic-gate  * based upon the native target sector/block size
6010Sstevel@tonic-gate  */
6020Sstevel@tonic-gate #define	SD_REQBYTES2TGTBYTES(un, bytecount)				\
6030Sstevel@tonic-gate 	(SD_BYTES2TGTBLOCKS(un, bytecount) * (un)->un_tgt_blocksize)
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate  * Calculate the byte offset from the beginning of the target block
6070Sstevel@tonic-gate  * to the system block location.
6080Sstevel@tonic-gate  */
6090Sstevel@tonic-gate #define	SD_TGTBYTEOFFSET(un, sysblk, tgtblk)				\
6109889SLarry.Liu@Sun.COM 	(SD_SYSBLOCKS2BYTES(sysblk) - SD_TGTBLOCKS2BYTES(un, tgtblk))
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate /*
6130Sstevel@tonic-gate  * Calculate the target block location from the system block location
6140Sstevel@tonic-gate  */
6150Sstevel@tonic-gate #define	SD_SYS2TGTBLOCK(un, blockcnt)					\
6169889SLarry.Liu@Sun.COM 	(blockcnt / ((un)->un_tgt_blocksize / DEV_BSIZE))
6179889SLarry.Liu@Sun.COM 
6189889SLarry.Liu@Sun.COM /*
6199889SLarry.Liu@Sun.COM  * Calculate the target block location from the system block location
6209889SLarry.Liu@Sun.COM  */
6219889SLarry.Liu@Sun.COM #define	SD_TGT2SYSBLOCK(un, blockcnt)					\
6229889SLarry.Liu@Sun.COM 	(blockcnt * ((un)->un_tgt_blocksize / DEV_BSIZE))
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate /*
6250Sstevel@tonic-gate  * SD_DEFAULT_MAX_XFER_SIZE is the default value to bound the max xfer
6260Sstevel@tonic-gate  * for physio, for devices without tagged queuing enabled.
6270Sstevel@tonic-gate  * The default for devices with tagged queuing enabled is SD_MAX_XFER_SIZE
6280Sstevel@tonic-gate  */
6290Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
6300Sstevel@tonic-gate #define	SD_DEFAULT_MAX_XFER_SIZE	(256 * 1024)
6310Sstevel@tonic-gate #endif
6320Sstevel@tonic-gate #define	SD_MAX_XFER_SIZE		(1024 * 1024)
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate /*
6350Sstevel@tonic-gate  * Warlock annotations
6360Sstevel@tonic-gate  */
6370Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_lun))
6380Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(sd_lun::un_sd))
6390Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_reservation_type))
640609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_mincdb))
641609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_maxcdb))
6422003Slh195018 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_max_hba_cdb))
643609Sbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_status_len))
6440Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_f_arq_enabled))
6450Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_ctype))
6463525Sshidokht _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_cmlbhandle))
6478086SXiao.L@Sun.COM _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_fm_private))
6483525Sshidokht 
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("safe sharing",
6510Sstevel@tonic-gate 	sd_lun::un_mhd_token
6520Sstevel@tonic-gate 	sd_lun::un_state
6530Sstevel@tonic-gate 	sd_lun::un_tagflags
6540Sstevel@tonic-gate 	sd_lun::un_f_format_in_progress
6550Sstevel@tonic-gate 	sd_lun::un_resvd_timeid
6560Sstevel@tonic-gate 	sd_lun::un_reset_throttle_timeid
6570Sstevel@tonic-gate 	sd_lun::un_startstop_timeid
6580Sstevel@tonic-gate 	sd_lun::un_dcvb_timeid
6590Sstevel@tonic-gate 	sd_lun::un_f_allow_bus_device_reset
6600Sstevel@tonic-gate 	sd_lun::un_sys_blocksize
6617570SDavid.Zhang@Sun.COM 	sd_lun::un_tgt_blocksize
662*12916SBo.Zhou@Sun.COM 	sd_lun::un_phy_blocksize
6637570SDavid.Zhang@Sun.COM 	sd_lun::un_additional_codes))
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
6685595Slh195018 	sd_lun::un_partial_dma_supported
6698551SPeng.L@Sun.COM 	sd_lun::un_buf_breakup_supported
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
6767079Syl194034 	sd_lun::un_xbuf_attr
6777079Syl194034 	sd_lun::un_cmd_timeout
6787079Syl194034 	sd_lun::un_pkt_flags))
6790Sstevel@tonic-gate 
6800Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data",
6810Sstevel@tonic-gate 	block_descriptor
6820Sstevel@tonic-gate 	buf
6830Sstevel@tonic-gate 	cdrom_subchnl
6840Sstevel@tonic-gate 	cdrom_tocentry
6850Sstevel@tonic-gate 	cdrom_tochdr
6860Sstevel@tonic-gate 	cdrom_read
6870Sstevel@tonic-gate 	dk_cinfo
6880Sstevel@tonic-gate 	dk_devid
6890Sstevel@tonic-gate 	dk_label
6900Sstevel@tonic-gate 	dk_map
6910Sstevel@tonic-gate 	dk_temperature
6920Sstevel@tonic-gate 	mhioc_inkeys
6930Sstevel@tonic-gate 	mhioc_inresvs
6941886Scg149915 	mode_caching
6950Sstevel@tonic-gate 	mode_header
6960Sstevel@tonic-gate 	mode_speed
6970Sstevel@tonic-gate 	scsi_cdb
6980Sstevel@tonic-gate 	scsi_arq_status
6990Sstevel@tonic-gate 	scsi_extended_sense
7000Sstevel@tonic-gate 	scsi_inquiry
7010Sstevel@tonic-gate 	scsi_pkt
7020Sstevel@tonic-gate 	uio
7030Sstevel@tonic-gate 	uscsi_cmd))
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate 
7060Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device dk_cinfo))
7070Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", scsi_status scsi_cdb))
7080Sstevel@tonic-gate 
7090Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_pm_mutex, sd_lun::un_pm_count
7100Sstevel@tonic-gate 	sd_lun::un_pm_timeid sd_lun::un_pm_busy sd_lun::un_pm_busy_cv
7110Sstevel@tonic-gate 	sd_lun::un_pm_idle_timeid))
7120Sstevel@tonic-gate 
7130Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
7140Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_fi_mutex,
7150Sstevel@tonic-gate 	sd_lun::sd_fi_buf_len sd_lun::sd_fi_log))
7160Sstevel@tonic-gate #endif
7170Sstevel@tonic-gate 
7180Sstevel@tonic-gate /* _NOTE(LOCK_ORDER(sd_lun::un_sd.sd_mutex sd_lun::un_pm_mutex)) */
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate /*
7230Sstevel@tonic-gate  * Referenced for frequently-accessed members of the unit structure
7240Sstevel@tonic-gate  */
7250Sstevel@tonic-gate #define	SD_SCSI_DEVP(un)	((un)->un_sd)
7260Sstevel@tonic-gate #define	SD_DEVINFO(un)		((un)->un_sd->sd_dev)
7270Sstevel@tonic-gate #define	SD_INQUIRY(un)		((un)->un_sd->sd_inq)
7280Sstevel@tonic-gate #define	SD_MUTEX(un)		(&((un)->un_sd->sd_mutex))
7290Sstevel@tonic-gate #define	SD_ADDRESS(un)		(&((un)->un_sd->sd_address))
7300Sstevel@tonic-gate #define	SD_GET_DEV(un)		(sd_make_device(SD_DEVINFO(un)))
7318086SXiao.L@Sun.COM #define	SD_FM_LOG(un)		(((struct sd_fm_internal *)\
7328086SXiao.L@Sun.COM 				((un)->un_fm_private))->fm_log_level)
7330Sstevel@tonic-gate 
7340Sstevel@tonic-gate 
7350Sstevel@tonic-gate /*
7360Sstevel@tonic-gate  * Values for un_ctype
7370Sstevel@tonic-gate  */
7380Sstevel@tonic-gate #define	CTYPE_CDROM		0
7390Sstevel@tonic-gate #define	CTYPE_MD21		1	/* Obsolete! */
7400Sstevel@tonic-gate #define	CTYPE_CCS		2
7410Sstevel@tonic-gate #define	CTYPE_ROD		3
7420Sstevel@tonic-gate #define	CTYPE_PXRE		4	/* Obsolete! */
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate #define	ISCD(un)		((un)->un_ctype == CTYPE_CDROM)
7450Sstevel@tonic-gate #define	ISROD(un)		((un)->un_ctype == CTYPE_ROD)
7460Sstevel@tonic-gate #define	ISPXRE(un)		((un)->un_ctype == CTYPE_PXRE)
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate /*
7490Sstevel@tonic-gate  * This macro checks the vendor of the device to see if it is LSI. Because
7500Sstevel@tonic-gate  * LSI has some devices out there that return 'Symbios' or 'SYMBIOS', we
7510Sstevel@tonic-gate  * need to check for those also.
7520Sstevel@tonic-gate  *
7530Sstevel@tonic-gate  * This is used in some vendor specific checks.
7540Sstevel@tonic-gate  */
755313Sts143224 #define	SD_IS_LSI(un)	((un)->un_f_cfg_is_lsi == TRUE)
7560Sstevel@tonic-gate 
7570Sstevel@tonic-gate /*
7580Sstevel@tonic-gate  * Macros to check if the lun is a Sun T3 or a T4
7590Sstevel@tonic-gate  */
7600Sstevel@tonic-gate #define	SD_IS_T3(un) \
7610Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7620Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T3", 2) == 0))
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate #define	SD_IS_T4(un) \
7650Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7660Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T4", 2) == 0))
7670Sstevel@tonic-gate 
7680Sstevel@tonic-gate /*
7690Sstevel@tonic-gate  * Macros for non-512 byte writes to removable devices.
7700Sstevel@tonic-gate  */
7710Sstevel@tonic-gate #define	NOT_DEVBSIZE(un)	\
7721415Scg149915 	((un)->un_tgt_blocksize != (un)->un_sys_blocksize)
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate /*
7750Sstevel@tonic-gate  * Check that a write map, used for locking lba ranges for writes, is in
7760Sstevel@tonic-gate  * the linked list.
7770Sstevel@tonic-gate  */
7780Sstevel@tonic-gate #define	ONLIST(un, wmp)		\
7790Sstevel@tonic-gate 	(((un)->un_wm == (wmp)) || ((wmp)->wm_prev != NULL))
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate /*
7820Sstevel@tonic-gate  * Free a write map which is on list. Basically make sure that nobody is
7830Sstevel@tonic-gate  * sleeping on it before freeing it.
7840Sstevel@tonic-gate  */
7850Sstevel@tonic-gate #define	FREE_ONLIST_WMAP(un, wmp)				\
7860Sstevel@tonic-gate 	if (!(wmp)->wm_wanted_count) {				\
7870Sstevel@tonic-gate 		sd_free_inlist_wmap((un), (wmp));		\
7880Sstevel@tonic-gate 		(wmp) = NULL;					\
7890Sstevel@tonic-gate 	}
7900Sstevel@tonic-gate 
7910Sstevel@tonic-gate #define	CHK_N_FREEWMP(un, wmp)					\
7920Sstevel@tonic-gate 	if (!ONLIST((un), (wmp))) {				\
7930Sstevel@tonic-gate 		kmem_cache_free((un)->un_wm_cache, (wmp));	\
7940Sstevel@tonic-gate 		(wmp) = NULL;					\
7950Sstevel@tonic-gate 	} else {						\
7960Sstevel@tonic-gate 		FREE_ONLIST_WMAP((un), (wmp));			\
7970Sstevel@tonic-gate 	}
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate /*
8000Sstevel@tonic-gate  * Values used to in wm_flags field of sd_w_map.
8010Sstevel@tonic-gate  */
8020Sstevel@tonic-gate #define	SD_WTYPE_SIMPLE	0x001	/* Write aligned at blksize boundary */
8030Sstevel@tonic-gate #define	SD_WTYPE_RMW	0x002	/* Write requires read-modify-write */
8040Sstevel@tonic-gate #define	SD_WM_BUSY		0x100	/* write-map is busy */
8050Sstevel@tonic-gate 
8069889SLarry.Liu@Sun.COM /*
8079889SLarry.Liu@Sun.COM  * RMW type
8089889SLarry.Liu@Sun.COM  */
8099889SLarry.Liu@Sun.COM #define	SD_RMW_TYPE_DEFAULT	0	/* do rmw with warning message */
8109889SLarry.Liu@Sun.COM #define	SD_RMW_TYPE_NO_WARNING	1	/* do rmw without warning message */
8119889SLarry.Liu@Sun.COM #define	SD_RMW_TYPE_RETURN_ERROR	2	/* rmw disabled */
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate /* Device error kstats */
8140Sstevel@tonic-gate struct sd_errstats {
8150Sstevel@tonic-gate 	struct kstat_named	sd_softerrs;
8160Sstevel@tonic-gate 	struct kstat_named	sd_harderrs;
8170Sstevel@tonic-gate 	struct kstat_named	sd_transerrs;
8180Sstevel@tonic-gate 	struct kstat_named	sd_vid;
8190Sstevel@tonic-gate 	struct kstat_named	sd_pid;
8200Sstevel@tonic-gate 	struct kstat_named	sd_revision;
8210Sstevel@tonic-gate 	struct kstat_named	sd_serial;
8220Sstevel@tonic-gate 	struct kstat_named	sd_capacity;
8230Sstevel@tonic-gate 	struct kstat_named	sd_rq_media_err;
8240Sstevel@tonic-gate 	struct kstat_named	sd_rq_ntrdy_err;
8250Sstevel@tonic-gate 	struct kstat_named	sd_rq_nodev_err;
8260Sstevel@tonic-gate 	struct kstat_named	sd_rq_recov_err;
8270Sstevel@tonic-gate 	struct kstat_named	sd_rq_illrq_err;
8280Sstevel@tonic-gate 	struct kstat_named	sd_rq_pfa_err;
8290Sstevel@tonic-gate };
8300Sstevel@tonic-gate 
8310Sstevel@tonic-gate 
8320Sstevel@tonic-gate /*
8330Sstevel@tonic-gate  * Structs and definitions for SCSI-3 Persistent Reservation
8340Sstevel@tonic-gate  */
8350Sstevel@tonic-gate typedef struct sd_prin_readkeys {
8360Sstevel@tonic-gate 	uint32_t	generation;
8370Sstevel@tonic-gate 	uint32_t	len;
8380Sstevel@tonic-gate 	mhioc_resv_key_t *keylist;
8390Sstevel@tonic-gate } sd_prin_readkeys_t;
8400Sstevel@tonic-gate 
8410Sstevel@tonic-gate typedef struct sd_readresv_desc {
8420Sstevel@tonic-gate 	mhioc_resv_key_t	resvkey;
8430Sstevel@tonic-gate 	uint32_t		scope_specific_addr;
8440Sstevel@tonic-gate 	uint8_t			reserved_1;
8450Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8460Sstevel@tonic-gate 	uint8_t			type:4,
8470Sstevel@tonic-gate 				scope:4;
8480Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8490Sstevel@tonic-gate 	uint8_t			scope:4,
8500Sstevel@tonic-gate 				type:4;
8510Sstevel@tonic-gate #else
8520Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8530Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8540Sstevel@tonic-gate 	uint8_t			reserved_2;
8550Sstevel@tonic-gate 	uint8_t			reserved_3;
8560Sstevel@tonic-gate } sd_readresv_desc_t;
8570Sstevel@tonic-gate 
8580Sstevel@tonic-gate typedef struct sd_prin_readresv {
8590Sstevel@tonic-gate 	uint32_t		generation;
8600Sstevel@tonic-gate 	uint32_t		len;
8610Sstevel@tonic-gate 	sd_readresv_desc_t	*readresv_desc;
8620Sstevel@tonic-gate } sd_prin_readresv_t;
8630Sstevel@tonic-gate 
8640Sstevel@tonic-gate typedef struct sd_prout {
8650Sstevel@tonic-gate 	uchar_t		res_key[MHIOC_RESV_KEY_SIZE];
8660Sstevel@tonic-gate 	uchar_t		service_key[MHIOC_RESV_KEY_SIZE];
8670Sstevel@tonic-gate 	uint32_t	scope_address;
8680Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8690Sstevel@tonic-gate 	uchar_t		aptpl:1,
8700Sstevel@tonic-gate 			reserved:7;
8710Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8720Sstevel@tonic-gate 	uchar_t		reserved:7,
8730Sstevel@tonic-gate 			aptpl:1;
8740Sstevel@tonic-gate #else
8750Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8760Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8770Sstevel@tonic-gate 	uchar_t		reserved_1;
8780Sstevel@tonic-gate 	uint16_t	ext_len;
8790Sstevel@tonic-gate } sd_prout_t;
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate #define	SD_READ_KEYS			0x00
8820Sstevel@tonic-gate #define	SD_READ_RESV			0x01
8830Sstevel@tonic-gate 
8840Sstevel@tonic-gate #define	SD_SCSI3_REGISTER		0x00
8850Sstevel@tonic-gate #define	SD_SCSI3_RESERVE		0x01
8860Sstevel@tonic-gate #define	SD_SCSI3_RELEASE		0x02
8870Sstevel@tonic-gate #define	SD_SCSI3_PREEMPTANDABORT	0x05
8880Sstevel@tonic-gate #define	SD_SCSI3_REGISTERANDIGNOREKEY	0x06
8890Sstevel@tonic-gate 
8900Sstevel@tonic-gate /*
8910Sstevel@tonic-gate  * Note: The default init of un_reservation_type is to the value of '0'
8920Sstevel@tonic-gate  * (from the ddi_softs_state_zalloc) which means it is defaulting to SCSI-3
8930Sstevel@tonic-gate  * reservation type. This is ok because during attach we use a SCSI-3
8940Sstevel@tonic-gate  * PRIORITY RESERVE IN command to determine the reservation type, and set
8950Sstevel@tonic-gate  * un_reservation_type for all cases.
8960Sstevel@tonic-gate  */
8970Sstevel@tonic-gate #define	SD_SCSI3_RESERVATION		0x0
8980Sstevel@tonic-gate #define	SD_SCSI2_RESERVATION		0x1
8990Sstevel@tonic-gate #define	SCSI3_RESV_DESC_LEN		16
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate /*
9020Sstevel@tonic-gate  * Reservation Status's
9030Sstevel@tonic-gate  */
9040Sstevel@tonic-gate #define	SD_RELEASE			0x0000
9050Sstevel@tonic-gate #define	SD_RESERVE			0x0001
9060Sstevel@tonic-gate #define	SD_TKOWN			0x0002
9070Sstevel@tonic-gate #define	SD_LOST_RESERVE			0x0004
9080Sstevel@tonic-gate #define	SD_FAILFAST			0x0080
9090Sstevel@tonic-gate #define	SD_WANT_RESERVE			0x0100
9100Sstevel@tonic-gate #define	SD_RESERVATION_CONFLICT		0x0200
9110Sstevel@tonic-gate #define	SD_PRIORITY_RESERVE		0x0400
9120Sstevel@tonic-gate 
9130Sstevel@tonic-gate #define	SD_TARGET_IS_UNRESERVED		0
9140Sstevel@tonic-gate #define	SD_TARGET_IS_RESERVED		1
9150Sstevel@tonic-gate 
9160Sstevel@tonic-gate /*
9170Sstevel@tonic-gate  * Save page in mode_select
9180Sstevel@tonic-gate  */
9190Sstevel@tonic-gate #define	SD_DONTSAVE_PAGE		0
9200Sstevel@tonic-gate #define	SD_SAVE_PAGE			1
9210Sstevel@tonic-gate 
9220Sstevel@tonic-gate /*
9230Sstevel@tonic-gate  * Delay before reclaiming reservation is 6 seconds, in units of micro seconds
9240Sstevel@tonic-gate  */
9250Sstevel@tonic-gate #define	SD_REINSTATE_RESV_DELAY		6000000
9260Sstevel@tonic-gate 
9270Sstevel@tonic-gate #define	SD_MODE2_BLKSIZE		2336	/* bytes */
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate /*
93012208SBo.Zhou@Sun.COM  * Solid State Drive default sector size
93112208SBo.Zhou@Sun.COM  */
93212208SBo.Zhou@Sun.COM #define	SSD_SECSIZE			4096
93312208SBo.Zhou@Sun.COM 
93412208SBo.Zhou@Sun.COM /*
9350Sstevel@tonic-gate  * Resource type definitions for multi host control operations. Specifically,
9360Sstevel@tonic-gate  * queue and request definitions for reservation request handling between the
9370Sstevel@tonic-gate  * scsi facility callback function (sd_mhd_watch_cb) and the reservation
9380Sstevel@tonic-gate  * reclaim thread (sd_resv_reclaim_thread)
9390Sstevel@tonic-gate  */
9400Sstevel@tonic-gate struct sd_thr_request {
9410Sstevel@tonic-gate 	dev_t	dev;
9420Sstevel@tonic-gate 	struct	sd_thr_request	*sd_thr_req_next;
9430Sstevel@tonic-gate };
9440Sstevel@tonic-gate 
9450Sstevel@tonic-gate struct sd_resv_reclaim_request {
9460Sstevel@tonic-gate 	kthread_t		*srq_resv_reclaim_thread;
9470Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_req_head;
9480Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_cur_req;
9490Sstevel@tonic-gate 	kcondvar_t		srq_inprocess_cv;
9500Sstevel@tonic-gate 	kmutex_t		srq_resv_reclaim_mutex;
9510Sstevel@tonic-gate 	kcondvar_t		srq_resv_reclaim_cv;
9520Sstevel@tonic-gate };
9530Sstevel@tonic-gate 
9540Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_resv_reclaim_request::srq_resv_reclaim_mutex,
9550Sstevel@tonic-gate     sd_resv_reclaim_request))
9560Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_thr_request))
9570Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_prout))
9580Sstevel@tonic-gate 
9590Sstevel@tonic-gate 
9600Sstevel@tonic-gate 
9610Sstevel@tonic-gate /*
9620Sstevel@tonic-gate  * Driver Logging Components
9630Sstevel@tonic-gate  *
9640Sstevel@tonic-gate  * These components cover the functional entry points and areas of the
9650Sstevel@tonic-gate  * driver.  A component value is used for the entry point and utility
9660Sstevel@tonic-gate  * functions used by the entry point. The common component value is used
9670Sstevel@tonic-gate  * in those routines that are called from many areas of the driver.
9680Sstevel@tonic-gate  *
9690Sstevel@tonic-gate  * This can be done by adding the following two lines to /etc/system:
9700Sstevel@tonic-gate  * set sd:sd_component_mask=0x00080000
9710Sstevel@tonic-gate  * set sd:sd_level_mask=0x00000008
9720Sstevel@tonic-gate  */
9730Sstevel@tonic-gate #define	SD_LOG_PROBE			0x00000001
9740Sstevel@tonic-gate #define	SD_LOG_ATTACH_DETACH		0x00000002
9750Sstevel@tonic-gate #define	SD_LOG_OPEN_CLOSE		0x00000004
9760Sstevel@tonic-gate #define	SD_LOG_READ_WRITE		0x00000008
9770Sstevel@tonic-gate #define	SD_LOG_POWER			0x00000010
9780Sstevel@tonic-gate #define	SD_LOG_IOCTL			0x00000020
9790Sstevel@tonic-gate #define	SD_LOG_IOCTL_MHD		0x00000040
9800Sstevel@tonic-gate #define	SD_LOG_IOCTL_RMMEDIA		0x00000080
9810Sstevel@tonic-gate #define	SD_LOG_IOCTL_DKIO		0x00000100
9820Sstevel@tonic-gate #define	SD_LOG_IO			0x00000200
9830Sstevel@tonic-gate #define	SD_LOG_IO_CORE			0x00000400
9840Sstevel@tonic-gate #define	SD_LOG_IO_DISKSORT		0x00000800
9850Sstevel@tonic-gate #define	SD_LOG_IO_PARTITION		0x00001000
9860Sstevel@tonic-gate #define	SD_LOG_IO_RMMEDIA		0x00002000
9870Sstevel@tonic-gate #define	SD_LOG_IO_CHKSUM		0x00004000
9880Sstevel@tonic-gate #define	SD_LOG_IO_SDIOCTL		0x00008000
9890Sstevel@tonic-gate #define	SD_LOG_IO_PM			0x00010000
9900Sstevel@tonic-gate #define	SD_LOG_ERROR			0x00020000
9910Sstevel@tonic-gate #define	SD_LOG_DUMP			0x00040000
9920Sstevel@tonic-gate #define	SD_LOG_COMMON			0x00080000
9930Sstevel@tonic-gate #define	SD_LOG_SDTEST			0x00100000
9940Sstevel@tonic-gate #define	SD_LOG_IOERR			0x00200000
9950Sstevel@tonic-gate #define	SD_LOG_IO_FAILFAST		0x00400000
9960Sstevel@tonic-gate 
9970Sstevel@tonic-gate /* Driver Logging Levels */
9980Sstevel@tonic-gate #define	SD_LOGMASK_ERROR		0x00000001
9990Sstevel@tonic-gate #define	SD_LOGMASK_DUMP_MEM		0x00000002
10000Sstevel@tonic-gate #define	SD_LOGMASK_INFO			0x00000004
10010Sstevel@tonic-gate #define	SD_LOGMASK_TRACE		0x00000008
10020Sstevel@tonic-gate #define	SD_LOGMASK_DIAG			0x00000010
10030Sstevel@tonic-gate 
10040Sstevel@tonic-gate /* Driver Logging Formats */
10050Sstevel@tonic-gate #define	SD_LOG_HEX			0x00000001
10060Sstevel@tonic-gate #define	SD_LOG_CHAR			0x00000002
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate /*
10090Sstevel@tonic-gate  * The following macros should be used to log driver debug information
10100Sstevel@tonic-gate  * only. The output is filtered according to the component and level mask
10110Sstevel@tonic-gate  * values. Non-debug information, such as driver warnings intended for
10120Sstevel@tonic-gate  * the user should be logged via the scsi_log facility to ensure that
10130Sstevel@tonic-gate  * they are not filtered.
10140Sstevel@tonic-gate  */
10150Sstevel@tonic-gate #if DEBUG || lint
10160Sstevel@tonic-gate #define	SDDEBUG
10170Sstevel@tonic-gate 
10180Sstevel@tonic-gate /* SD_ERROR is called to log driver error conditions */
10190Sstevel@tonic-gate #define	SD_ERROR	sd_log_err
10200Sstevel@tonic-gate 
10210Sstevel@tonic-gate /* SD_TRACE is called to log driver trace conditions (function entry/exit) */
10220Sstevel@tonic-gate #define	SD_TRACE	sd_log_trace
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate /* SD_INFO is called to log general purpose driver info */
10250Sstevel@tonic-gate #define	SD_INFO		sd_log_info
10260Sstevel@tonic-gate 
10270Sstevel@tonic-gate /* SD_DUMP_MEMORY is called to dump a data buffer to the log */
10280Sstevel@tonic-gate #define	SD_DUMP_MEMORY	sd_dump_memory
10290Sstevel@tonic-gate 
10300Sstevel@tonic-gate /* RESET/ABORTS testing ioctls */
10310Sstevel@tonic-gate #define	DKIOCRESET	(DKIOC|14)
10320Sstevel@tonic-gate #define	DKIOCABORT	(DKIOC|15)
10330Sstevel@tonic-gate 
10340Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
10350Sstevel@tonic-gate /*
1036173Scth  * sd_fi_pkt replicates the variables that are exposed through pkt
10370Sstevel@tonic-gate  *
1038173Scth  * sd_fi_xb replicates the variables that are exposed through xb
10390Sstevel@tonic-gate  *
1040173Scth  * sd_fi_un replicates the variables that are exposed through un
10410Sstevel@tonic-gate  *
1042173Scth  * sd_fi_arq replicates the variables that are
10430Sstevel@tonic-gate  *           exposed for Auto-Reqeust-Sense
10440Sstevel@tonic-gate  *
10450Sstevel@tonic-gate  */
10460Sstevel@tonic-gate struct sd_fi_pkt {
10470Sstevel@tonic-gate 	uint_t  pkt_flags;			/* flags */
10480Sstevel@tonic-gate 	uchar_t pkt_scbp;			/* pointer to status block */
10490Sstevel@tonic-gate 	uchar_t pkt_cdbp;			/* pointer to command block */
10500Sstevel@tonic-gate 	uint_t  pkt_state;			/* state of command */
10510Sstevel@tonic-gate 	uint_t  pkt_statistics;		/* statistics */
10520Sstevel@tonic-gate 	uchar_t pkt_reason;			/* reason completion called */
10530Sstevel@tonic-gate };
10540Sstevel@tonic-gate 
10550Sstevel@tonic-gate struct sd_fi_xb {
10560Sstevel@tonic-gate 	daddr_t xb_blkno;
10570Sstevel@tonic-gate 	ssize_t xb_dma_resid;
10580Sstevel@tonic-gate 	short	xb_retry_count;
10590Sstevel@tonic-gate 	short	xb_victim_retry_count;
10600Sstevel@tonic-gate 	uchar_t xb_sense_status;
10610Sstevel@tonic-gate 	uint_t  xb_sense_state;
10620Sstevel@tonic-gate 	ssize_t xb_sense_resid;
10630Sstevel@tonic-gate 	uchar_t xb_sense_data[SENSE_LENGTH];
10640Sstevel@tonic-gate 	uchar_t es_code;
10650Sstevel@tonic-gate 	uchar_t es_key;
10660Sstevel@tonic-gate 	uchar_t es_add_code;
10670Sstevel@tonic-gate 	uchar_t es_qual_code;
10680Sstevel@tonic-gate };
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate struct sd_fi_un {
10710Sstevel@tonic-gate 	uchar_t inq_rmb;
10720Sstevel@tonic-gate 	uchar_t un_ctype;
10730Sstevel@tonic-gate 	uint_t  un_notready_retry_count;
10740Sstevel@tonic-gate 	uint_t  un_reset_retry_count;
10750Sstevel@tonic-gate 	uchar_t un_reservation_type;
10760Sstevel@tonic-gate 	ushort_t un_notrdy_delay;
10770Sstevel@tonic-gate 	short   un_resvd_status;
10780Sstevel@tonic-gate 	uint32_t
10790Sstevel@tonic-gate 		un_f_arq_enabled,
10800Sstevel@tonic-gate 		un_f_allow_bus_device_reset,
10810Sstevel@tonic-gate 		un_f_opt_queueing;
10820Sstevel@tonic-gate 	timeout_id_t    un_restart_timeid;
10830Sstevel@tonic-gate };
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate struct sd_fi_arq {
10860Sstevel@tonic-gate 	struct scsi_status	sts_status;
10870Sstevel@tonic-gate 	struct scsi_status	sts_rqpkt_status;
10880Sstevel@tonic-gate 	uchar_t				sts_rqpkt_reason;
10890Sstevel@tonic-gate 	uchar_t				sts_rqpkt_resid;
10900Sstevel@tonic-gate 	uint_t				sts_rqpkt_state;
10910Sstevel@tonic-gate 	uint_t				sts_rqpkt_statistics;
10920Sstevel@tonic-gate 	struct scsi_extended_sense	sts_sensedata;
10930Sstevel@tonic-gate };
10940Sstevel@tonic-gate 
10957570SDavid.Zhang@Sun.COM /*
10967570SDavid.Zhang@Sun.COM  * Conditional set def
10977570SDavid.Zhang@Sun.COM  */
10987570SDavid.Zhang@Sun.COM #define	SD_CONDSET(a, b, c, d)			\
10997570SDavid.Zhang@Sun.COM 	{ \
11007570SDavid.Zhang@Sun.COM 	a->c = ((fi_ ## b)->c);			\
11017570SDavid.Zhang@Sun.COM 	SD_INFO(SD_LOG_IOERR, un,		\
11027570SDavid.Zhang@Sun.COM 			"sd_fault_injection:"	\
11037570SDavid.Zhang@Sun.COM 			"setting %s to %d\n", 	\
11047570SDavid.Zhang@Sun.COM 			d, ((fi_ ## b)->c)); 	\
11057570SDavid.Zhang@Sun.COM 	}
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate /* SD FaultInjection ioctls */
11080Sstevel@tonic-gate #define	SDIOC			('T'<<8)
11090Sstevel@tonic-gate #define	SDIOCSTART		(SDIOC|1)
11100Sstevel@tonic-gate #define	SDIOCSTOP		(SDIOC|2)
11110Sstevel@tonic-gate #define	SDIOCINSERTPKT	(SDIOC|3)
11120Sstevel@tonic-gate #define	SDIOCINSERTXB	(SDIOC|4)
11130Sstevel@tonic-gate #define	SDIOCINSERTUN	(SDIOC|5)
11140Sstevel@tonic-gate #define	SDIOCINSERTARQ	(SDIOC|6)
11150Sstevel@tonic-gate #define	SDIOCPUSH		(SDIOC|7)
11160Sstevel@tonic-gate #define	SDIOCRETRIEVE	(SDIOC|8)
11170Sstevel@tonic-gate #define	SDIOCRUN		(SDIOC|9)
11180Sstevel@tonic-gate #endif
11190Sstevel@tonic-gate 
11200Sstevel@tonic-gate #else
11210Sstevel@tonic-gate 
11220Sstevel@tonic-gate #undef	SDDEBUG
11230Sstevel@tonic-gate #define	SD_ERROR	{ if (0) sd_log_err; }
11240Sstevel@tonic-gate #define	SD_TRACE	{ if (0) sd_log_trace; }
11250Sstevel@tonic-gate #define	SD_INFO		{ if (0) sd_log_info; }
11260Sstevel@tonic-gate #define	SD_DUMP_MEMORY	{ if (0) sd_dump_memory; }
11270Sstevel@tonic-gate #endif
11280Sstevel@tonic-gate 
11290Sstevel@tonic-gate 
11300Sstevel@tonic-gate /*
11310Sstevel@tonic-gate  * Miscellaneous macros
11320Sstevel@tonic-gate  */
11330Sstevel@tonic-gate 
11340Sstevel@tonic-gate #define	SD_USECTOHZ(x)			(drv_usectohz((x)*1000000))
11350Sstevel@tonic-gate #define	SD_GET_PKT_STATUS(pktp)		((*(pktp)->pkt_scbp) & STATUS_MASK)
11360Sstevel@tonic-gate 
11370Sstevel@tonic-gate #define	SD_BIOERROR(bp, errcode)					\
11380Sstevel@tonic-gate 	if ((bp)->b_resid == 0) {					\
11390Sstevel@tonic-gate 		(bp)->b_resid = (bp)->b_bcount;				\
11400Sstevel@tonic-gate 	}								\
11410Sstevel@tonic-gate 	if ((bp)->b_error == 0) {					\
11420Sstevel@tonic-gate 		bioerror(bp, errcode);					\
11430Sstevel@tonic-gate 	}								\
11442003Slh195018 	(bp)->b_flags |= B_ERROR;
11450Sstevel@tonic-gate 
1146159Sjongkis #define	SD_FILL_SCSI1_LUN_CDB(lunp, cdbp)				\
1147159Sjongkis 	if (! (lunp)->un_f_is_fibre &&					\
1148159Sjongkis 	    SD_INQUIRY((lunp))->inq_ansi == 0x01) {			\
1149159Sjongkis 		int _lun = ddi_prop_get_int(DDI_DEV_T_ANY,		\
1150159Sjongkis 		    SD_DEVINFO((lunp)), DDI_PROP_DONTPASS,		\
1151159Sjongkis 		    SCSI_ADDR_PROP_LUN, 0);				\
1152159Sjongkis 		if (_lun > 0) {						\
1153159Sjongkis 			(cdbp)->scc_lun = _lun;				\
1154159Sjongkis 		}							\
11550Sstevel@tonic-gate 	}
11560Sstevel@tonic-gate 
1157159Sjongkis #define	SD_FILL_SCSI1_LUN(lunp, pktp)					\
1158159Sjongkis 	SD_FILL_SCSI1_LUN_CDB((lunp), (union scsi_cdb *)(pktp)->pkt_cdbp)
1159159Sjongkis 
11600Sstevel@tonic-gate /*
11610Sstevel@tonic-gate  * Disk driver states
11620Sstevel@tonic-gate  */
11630Sstevel@tonic-gate 
11640Sstevel@tonic-gate #define	SD_STATE_NORMAL		0
11650Sstevel@tonic-gate #define	SD_STATE_OFFLINE	1
11660Sstevel@tonic-gate #define	SD_STATE_RWAIT		2
11670Sstevel@tonic-gate #define	SD_STATE_DUMPING	3
11680Sstevel@tonic-gate #define	SD_STATE_SUSPENDED	4
11690Sstevel@tonic-gate #define	SD_STATE_PM_CHANGING	5
11700Sstevel@tonic-gate 
11710Sstevel@tonic-gate /*
11720Sstevel@tonic-gate  * The table is to be interpreted as follows: The rows lists all the states
11730Sstevel@tonic-gate  * and each column is a state that a state in each row *can* reach. The entries
11740Sstevel@tonic-gate  * in the table list the event that cause that transition to take place.
11750Sstevel@tonic-gate  * For e.g.: To go from state RWAIT to SUSPENDED, event (d)-- which is the
11760Sstevel@tonic-gate  * invocation of DDI_SUSPEND-- has to take place. Note the same event could
11770Sstevel@tonic-gate  * cause the transition from one state to two different states. e.g., from
11780Sstevel@tonic-gate  * state SUSPENDED, when we get a DDI_RESUME, we just go back to the *last
11790Sstevel@tonic-gate  * state* whatever that might be. (NORMAL or OFFLINE).
11800Sstevel@tonic-gate  *
11810Sstevel@tonic-gate  *
11820Sstevel@tonic-gate  * State Transition Table:
11830Sstevel@tonic-gate  *
11840Sstevel@tonic-gate  *                    NORMAL  OFFLINE  RWAIT  DUMPING  SUSPENDED  PM_SUSPENDED
11850Sstevel@tonic-gate  *
11860Sstevel@tonic-gate  *   NORMAL              -      (a)      (b)     (c)      (d)       (h)
11870Sstevel@tonic-gate  *
11880Sstevel@tonic-gate  *   OFFLINE            (e)      -       (e)     (c)      (d)       NP
11890Sstevel@tonic-gate  *
11900Sstevel@tonic-gate  *   RWAIT              (f)     NP        -      (c)      (d)       (h)
11910Sstevel@tonic-gate  *
11920Sstevel@tonic-gate  *   DUMPING            NP      NP        NP      -        NP       NP
11930Sstevel@tonic-gate  *
11940Sstevel@tonic-gate  *   SUSPENDED          (g)     (g)       (b)     NP*      -        NP
11950Sstevel@tonic-gate  *
11960Sstevel@tonic-gate  *   PM_SUSPENDED       (i)     NP        (b)    (c)      (d)       -
11970Sstevel@tonic-gate  *
11980Sstevel@tonic-gate  *   NP :       Not Possible.
11990Sstevel@tonic-gate  *   (a):       Disk does not respond.
12000Sstevel@tonic-gate  *   (b):       Packet Allocation Fails
12010Sstevel@tonic-gate  *   (c):       Panic - Crash dump
12020Sstevel@tonic-gate  *   (d):       DDI_SUSPEND is called.
12030Sstevel@tonic-gate  *   (e):       Disk has a successful I/O completed.
12040Sstevel@tonic-gate  *   (f):       sdrunout() calls sdstart() which sets it NORMAL
12050Sstevel@tonic-gate  *   (g):       DDI_RESUME is called.
12060Sstevel@tonic-gate  *   (h):	Device threshold exceeded pm framework called power
12070Sstevel@tonic-gate  *		entry point or pm_lower_power called in detach.
12080Sstevel@tonic-gate  *   (i):	When new I/O come in.
12090Sstevel@tonic-gate  *    * :       When suspended, we dont change state during panic dump
12100Sstevel@tonic-gate  */
12110Sstevel@tonic-gate 
12120Sstevel@tonic-gate 
12130Sstevel@tonic-gate #define	SD_MAX_THROTTLE		256
12140Sstevel@tonic-gate #define	SD_MIN_THROTTLE		8
12150Sstevel@tonic-gate /*
12160Sstevel@tonic-gate  * Lowest valid max. and min. throttle value.
12170Sstevel@tonic-gate  * This is set to 2 because if un_min_throttle were allowed to be 1 then
12180Sstevel@tonic-gate  * un_throttle would never get set to a value less than un_min_throttle
12190Sstevel@tonic-gate  * (0 is a special case) which means it would never get set back to
12200Sstevel@tonic-gate  * un_saved_throttle in routine sd_restore_throttle().
12210Sstevel@tonic-gate  */
12220Sstevel@tonic-gate #define	SD_LOWEST_VALID_THROTTLE	2
12230Sstevel@tonic-gate 
12240Sstevel@tonic-gate 
12250Sstevel@tonic-gate 
12260Sstevel@tonic-gate /* Return codes for sd_send_polled_cmd() and sd_scsi_poll() */
12270Sstevel@tonic-gate #define	SD_CMD_SUCCESS			0
12280Sstevel@tonic-gate #define	SD_CMD_FAILURE			1
12290Sstevel@tonic-gate #define	SD_CMD_RESERVATION_CONFLICT	2
12300Sstevel@tonic-gate #define	SD_CMD_ILLEGAL_REQUEST		3
12310Sstevel@tonic-gate #define	SD_CMD_BECOMING_READY		4
12320Sstevel@tonic-gate #define	SD_CMD_CHECK_CONDITION		5
12330Sstevel@tonic-gate 
12340Sstevel@tonic-gate /* Return codes for sd_ready_and_valid */
12350Sstevel@tonic-gate #define	SD_READY_VALID			0
12360Sstevel@tonic-gate #define	SD_NOT_READY_VALID		1
12373525Sshidokht #define	SD_RESERVED_BY_OTHERS		2
12380Sstevel@tonic-gate 
12390Sstevel@tonic-gate #define	SD_PATH_STANDARD		0
12400Sstevel@tonic-gate #define	SD_PATH_DIRECT			1
12410Sstevel@tonic-gate #define	SD_PATH_DIRECT_PRIORITY		2
12420Sstevel@tonic-gate 
12430Sstevel@tonic-gate #define	SD_UNIT_ATTENTION_RETRY		40
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate /*
12460Sstevel@tonic-gate  * The following three are bit flags passed into sd_send_scsi_TEST_UNIT_READY
12470Sstevel@tonic-gate  * to control specific behavior.
12480Sstevel@tonic-gate  */
12490Sstevel@tonic-gate #define	SD_CHECK_FOR_MEDIA		0x01
12500Sstevel@tonic-gate #define	SD_DONT_RETRY_TUR		0x02
12510Sstevel@tonic-gate #define	SD_BYPASS_PM			0x04
12520Sstevel@tonic-gate 
12532148Spd144616 #define	SD_GROUP0_MAX_ADDRESS	(0x1fffff)
12540Sstevel@tonic-gate #define	SD_GROUP0_MAXCOUNT	(0xff)
12552148Spd144616 #define	SD_GROUP1_MAX_ADDRESS	(0xffffffff)
12560Sstevel@tonic-gate #define	SD_GROUP1_MAXCOUNT	(0xffff)
12570Sstevel@tonic-gate 
12580Sstevel@tonic-gate #define	SD_BECOMING_ACTIVE	0x01
12590Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW	0
12600Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT	1
12610Sstevel@tonic-gate 
12620Sstevel@tonic-gate #define	SD_GET_PKT_OPCODE(pktp)	\
12630Sstevel@tonic-gate 	(((union scsi_cdb *)((pktp)->pkt_cdbp))->cdb_un.cmd)
12640Sstevel@tonic-gate 
12650Sstevel@tonic-gate 
12660Sstevel@tonic-gate #define	SD_NO_RETRY_ISSUED		0
12670Sstevel@tonic-gate #define	SD_DELAYED_RETRY_ISSUED		1
12680Sstevel@tonic-gate #define	SD_IMMEDIATE_RETRY_ISSUED	2
12690Sstevel@tonic-gate 
12700Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
12710Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12720Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid + (SD_GET_XBUF(bp)->xb_dma_resid))
12730Sstevel@tonic-gate #else
12740Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12750Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid)
12760Sstevel@tonic-gate #endif
12770Sstevel@tonic-gate 
12780Sstevel@tonic-gate 
12790Sstevel@tonic-gate #define	SD_RETRIES_MASK		0x00FF
12800Sstevel@tonic-gate #define	SD_RETRIES_NOCHECK	0x0000
12810Sstevel@tonic-gate #define	SD_RETRIES_STANDARD	0x0001
12820Sstevel@tonic-gate #define	SD_RETRIES_VICTIM	0x0002
12830Sstevel@tonic-gate #define	SD_RETRIES_BUSY		0x0003
12840Sstevel@tonic-gate #define	SD_RETRIES_UA		0x0004
12850Sstevel@tonic-gate #define	SD_RETRIES_ISOLATE	0x8000
12860Sstevel@tonic-gate #define	SD_RETRIES_FAILFAST	0x4000
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate #define	SD_UPDATE_RESERVATION_STATUS(un, pktp)				\
12890Sstevel@tonic-gate if (((pktp)->pkt_reason == CMD_RESET) ||				\
12900Sstevel@tonic-gate 	((pktp)->pkt_statistics & (STAT_BUS_RESET | STAT_DEV_RESET))) { \
12910Sstevel@tonic-gate 	if (((un)->un_resvd_status & SD_RESERVE) == SD_RESERVE) {	\
12920Sstevel@tonic-gate 		(un)->un_resvd_status |=				\
12930Sstevel@tonic-gate 		    (SD_LOST_RESERVE | SD_WANT_RESERVE);		\
12940Sstevel@tonic-gate 	}								\
12950Sstevel@tonic-gate }
12960Sstevel@tonic-gate 
12970Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_VALID		0
12980Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_INVALID	1
12990Sstevel@tonic-gate 
13000Sstevel@tonic-gate /*
13010Sstevel@tonic-gate  * Delay (in seconds) before restoring the "throttle limit" back
13020Sstevel@tonic-gate  * to its maximum value.
1303666Sts143224  * 60 seconds is what we will wait for to reset the
1304666Sts143224  * throttle back to it SD_MAX_THROTTLE for TRAN_BUSY.
1305666Sts143224  * 10 seconds for STATUS_QFULL because QFULL will incrementally
1306666Sts143224  * increase the throttle limit until it reaches max value.
13070Sstevel@tonic-gate  */
13080Sstevel@tonic-gate #define	SD_RESET_THROTTLE_TIMEOUT	60
1309666Sts143224 #define	SD_QFULL_THROTTLE_TIMEOUT	10
13100Sstevel@tonic-gate 
13110Sstevel@tonic-gate #define	SD_THROTTLE_TRAN_BUSY		0
13120Sstevel@tonic-gate #define	SD_THROTTLE_QFULL		1
13130Sstevel@tonic-gate 
13140Sstevel@tonic-gate #define	SD_THROTTLE_RESET_INTERVAL	\
13150Sstevel@tonic-gate 	(sd_reset_throttle_timeout * drv_usectohz(1000000))
13160Sstevel@tonic-gate 
1317666Sts143224 #define	SD_QFULL_THROTTLE_RESET_INTERVAL	\
1318666Sts143224 	(sd_qfull_throttle_timeout * drv_usectohz(1000000))
1319666Sts143224 
13200Sstevel@tonic-gate 
13210Sstevel@tonic-gate /*
13220Sstevel@tonic-gate  * xb_pkt_flags defines
13230Sstevel@tonic-gate  * SD_XB_DMA_FREED indicates the scsi_pkt has had its DMA resources freed
13240Sstevel@tonic-gate  * by a call to scsi_dmafree(9F). The resources must be reallocated before
13250Sstevel@tonic-gate  *   before a call to scsi_transport can be made again.
13267570SDavid.Zhang@Sun.COM  * SD_XB_USCSICMD indicates the scsi request is a uscsi request
13270Sstevel@tonic-gate  * SD_XB_INITPKT_MASK: since this field is also used to store flags for
13280Sstevel@tonic-gate  *   a scsi_init_pkt(9F) call, we need a mask to make sure that we don't
13290Sstevel@tonic-gate  *   pass any unintended bits to scsi_init_pkt(9F) (ugly hack).
13300Sstevel@tonic-gate  */
13317570SDavid.Zhang@Sun.COM #define	SD_XB_DMA_FREED		0x20000000
13320Sstevel@tonic-gate #define	SD_XB_USCSICMD		0x40000000
13330Sstevel@tonic-gate #define	SD_XB_INITPKT_MASK	(PKT_CONSISTENT | PKT_DMA_PARTIAL)
13340Sstevel@tonic-gate 
13350Sstevel@tonic-gate /*
13360Sstevel@tonic-gate  * Extension for the buf(9s) struct that we receive from a higher
13370Sstevel@tonic-gate  * layer. Located by b_private in the buf(9S).  (The previous contents
13380Sstevel@tonic-gate  * of b_private are saved & restored before calling biodone(9F).)
13390Sstevel@tonic-gate  */
13400Sstevel@tonic-gate struct sd_xbuf {
13410Sstevel@tonic-gate 
13420Sstevel@tonic-gate 	struct sd_lun	*xb_un;		/* Ptr to associated sd_lun */
13430Sstevel@tonic-gate 	struct scsi_pkt	*xb_pktp;	/* Ptr to associated scsi_pkt */
13440Sstevel@tonic-gate 
13450Sstevel@tonic-gate 	/*
13460Sstevel@tonic-gate 	 * xb_pktinfo points to any optional data that may be needed
13470Sstevel@tonic-gate 	 * by the initpkt and/or destroypkt functions.  Typical
13480Sstevel@tonic-gate 	 * use might be to point to a struct uscsi_cmd.
13490Sstevel@tonic-gate 	 */
13500Sstevel@tonic-gate 	void	*xb_pktinfo;
13510Sstevel@tonic-gate 
13520Sstevel@tonic-gate 	/*
13530Sstevel@tonic-gate 	 * Layer-private data area. This may be used by any layer to store
13540Sstevel@tonic-gate 	 * layer-specific data on a per-IO basis. Typical usage is for an
13550Sstevel@tonic-gate 	 * iostart routine to save some info here for later use by its
13560Sstevel@tonic-gate 	 * partner iodone routine.  This area may be used to hold data or
13570Sstevel@tonic-gate 	 * a pointer to a data block that is allocated/freed by the layer's
13580Sstevel@tonic-gate 	 * iostart/iodone routines. Allocation & management policy for the
13590Sstevel@tonic-gate 	 * layer-private area is defined & implemented by each specific
13600Sstevel@tonic-gate 	 * layer as required.
13610Sstevel@tonic-gate 	 *
13620Sstevel@tonic-gate 	 * IMPORTANT: Since a higher layer may depend on the value in the
13630Sstevel@tonic-gate 	 * xb_private field, each layer must ensure that it returns the
13640Sstevel@tonic-gate 	 * buf/xbuf to the next higher layer (via SD_NEXT_IODONE()) with
13650Sstevel@tonic-gate 	 * the SAME VALUE in xb_private as when the buf/xbuf was first
13660Sstevel@tonic-gate 	 * received by the layer's iostart routine. Typically this is done
13670Sstevel@tonic-gate 	 * by the iostart routine saving the contents of xb_private into
13680Sstevel@tonic-gate 	 * a place in the layer-private data area, and the iodone routine
13690Sstevel@tonic-gate 	 * restoring the value of xb_private before deallocating the
13700Sstevel@tonic-gate 	 * layer-private data block and calling SD_NEXT_IODONE(). Of course,
13710Sstevel@tonic-gate 	 * if a layer never modifies xb_private in a buf/xbuf from a higher
13720Sstevel@tonic-gate 	 * layer, there will be no need to restore the value.
13730Sstevel@tonic-gate 	 *
13740Sstevel@tonic-gate 	 * Note that in the case where a layer _creates_ a buf/xbuf (such as
13750Sstevel@tonic-gate 	 * by calling sd_shadow_buf_alloc()) to pass to a lower layer, it is
13760Sstevel@tonic-gate 	 * not necessary to preserve the contents of xb_private as there is
13770Sstevel@tonic-gate 	 * no higher layer dependency on the value of xb_private. Such a
13780Sstevel@tonic-gate 	 * buf/xbuf must be deallocated by the layer that allocated it and
13790Sstevel@tonic-gate 	 * must *NEVER* be passed up to a higher layer.
13800Sstevel@tonic-gate 	 */
13810Sstevel@tonic-gate 	void	*xb_private;	/* Layer-private data block */
13820Sstevel@tonic-gate 
13830Sstevel@tonic-gate 	/*
13840Sstevel@tonic-gate 	 * We do not use the b_blkno provided in the buf(9S), as we need to
13850Sstevel@tonic-gate 	 * make adjustments to it in the driver, but it is not a field that
13860Sstevel@tonic-gate 	 * the driver owns or is free to modify.
13870Sstevel@tonic-gate 	 */
13880Sstevel@tonic-gate 	daddr_t	xb_blkno;		/* Absolute block # on target */
13897570SDavid.Zhang@Sun.COM 	uint64_t xb_ena;		/* ena for a specific SCSI command */
13900Sstevel@tonic-gate 
13910Sstevel@tonic-gate 	int	xb_chain_iostart;	/* iostart side index */
13920Sstevel@tonic-gate 	int	xb_chain_iodone;	/* iodone side index */
13930Sstevel@tonic-gate 	int	xb_pkt_flags;		/* Flags for scsi_init_pkt() */
13940Sstevel@tonic-gate 	ssize_t	xb_dma_resid;
13950Sstevel@tonic-gate 	short	xb_retry_count;
13960Sstevel@tonic-gate 	short	xb_victim_retry_count;
13970Sstevel@tonic-gate 	short	xb_ua_retry_count;	/* unit_attention retry counter */
13984786Slh195018 	short	xb_nr_retry_count;	/* not ready retry counter */
13990Sstevel@tonic-gate 
14000Sstevel@tonic-gate 	/*
14010Sstevel@tonic-gate 	 * Various status and data used when a RQS command is run on
14020Sstevel@tonic-gate 	 * the behalf of this command.
14030Sstevel@tonic-gate 	 */
14040Sstevel@tonic-gate 	struct buf	*xb_sense_bp;	/* back ptr to buf, for RQS */
14050Sstevel@tonic-gate 	uint_t	xb_sense_state;		/* scsi_pkt state of RQS command */
14060Sstevel@tonic-gate 	ssize_t	xb_sense_resid;		/* residual of RQS command */
14070Sstevel@tonic-gate 	uchar_t	xb_sense_status;	/* scsi status byte of RQS command */
14080Sstevel@tonic-gate 	uchar_t	xb_sense_data[SENSE_LENGTH];	/* sense data from RQS cmd */
14095597Slh195018 	/*
14105597Slh195018 	 * Extra sense larger than SENSE_LENGTH will be allocated
14115597Slh195018 	 * right after xb_sense_data[SENSE_LENGTH]. Please do not
14125597Slh195018 	 * add any new field after it.
14135597Slh195018 	 */
14140Sstevel@tonic-gate };
14150Sstevel@tonic-gate 
14160Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", sd_xbuf))
14170Sstevel@tonic-gate 
14180Sstevel@tonic-gate #define	SD_PKT_ALLOC_SUCCESS			0
14190Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE			1
14200Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_NO_DMA		2
14210Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_PKT_TOO_SMALL	3
14220Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL	4
14230Sstevel@tonic-gate 
14240Sstevel@tonic-gate #define	SD_GET_XBUF(bp)		((struct sd_xbuf *)((bp)->b_private))
14250Sstevel@tonic-gate #define	SD_GET_UN(bp)		((SD_GET_XBUF(bp))->xb_un)
14260Sstevel@tonic-gate #define	SD_GET_PKTP(bp)		((SD_GET_XBUF(bp))->xb_pktp)
14270Sstevel@tonic-gate #define	SD_GET_BLKNO(bp)	((SD_GET_XBUF(bp))->xb_blkno)
14280Sstevel@tonic-gate 
14290Sstevel@tonic-gate /*
14300Sstevel@tonic-gate  * Special-purpose struct for sd_send_scsi_cmd() to pass command-specific
14310Sstevel@tonic-gate  * data through the layering chains to sd_initpkt_for_uscsi().
14320Sstevel@tonic-gate  */
14330Sstevel@tonic-gate struct sd_uscsi_info {
14340Sstevel@tonic-gate 	int			ui_flags;
14350Sstevel@tonic-gate 	struct uscsi_cmd	*ui_cmdp;
1436789Sahrens 	/*
1437789Sahrens 	 * ui_dkc is used by sd_send_scsi_SYNCHRONIZE_CACHE() to allow
1438789Sahrens 	 * for async completion notification.
1439789Sahrens 	 */
1440789Sahrens 	struct dk_callback	ui_dkc;
14417570SDavid.Zhang@Sun.COM 	/*
14427570SDavid.Zhang@Sun.COM 	 * The following fields are to be used for FMA ereport generation.
14437570SDavid.Zhang@Sun.COM 	 */
14447570SDavid.Zhang@Sun.COM 	uchar_t			ui_pkt_reason;
14457570SDavid.Zhang@Sun.COM 	uint32_t		ui_pkt_state;
14467570SDavid.Zhang@Sun.COM 	uint32_t		ui_pkt_statistics;
14477570SDavid.Zhang@Sun.COM 	uint64_t		ui_lba;
14487570SDavid.Zhang@Sun.COM 	uint64_t		ui_ena;
14490Sstevel@tonic-gate };
14500Sstevel@tonic-gate 
14510Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_uscsi_info))
14520Sstevel@tonic-gate 
14537570SDavid.Zhang@Sun.COM /*
14547570SDavid.Zhang@Sun.COM  * This structure is used to issue 'internal' command sequences from the
14557570SDavid.Zhang@Sun.COM  * driver's attach(9E)/open(9E)/etc entry points. It provides a common context
14567570SDavid.Zhang@Sun.COM  * for issuing command sequences, with the ability to issue a command
14577570SDavid.Zhang@Sun.COM  * and provide expected/unexpected assessment of results at any code
14587570SDavid.Zhang@Sun.COM  * level within the sd_ssc_t scope and preserve the information needed
14597570SDavid.Zhang@Sun.COM  * produce telemetry for the problem, when needed, from a single
14607570SDavid.Zhang@Sun.COM  * outer-most-scope point.
14617570SDavid.Zhang@Sun.COM  *
14627570SDavid.Zhang@Sun.COM  * The sd_ssc_t abstraction should result in well-structured code where
14637570SDavid.Zhang@Sun.COM  * the basic code structure is not jeprodized by future localized improvement.
14647570SDavid.Zhang@Sun.COM  *
14657570SDavid.Zhang@Sun.COM  *   o  Scope for a sequence of commands.
14667570SDavid.Zhang@Sun.COM  *   o  Within a scoped sequence of commands, provides a single top-level
14677570SDavid.Zhang@Sun.COM  *      location for initiating telementry generation from captured data.
14687570SDavid.Zhang@Sun.COM  *   o  Provide a common place to capture command execution data and driver
14697570SDavid.Zhang@Sun.COM  *      assessment information for delivery to telemetry generation point.
14707570SDavid.Zhang@Sun.COM  *   o  Mechanism to get device-as-detector (dad) and transport telemetry
14717570SDavid.Zhang@Sun.COM  *      information from interrupt context (sdintr) back to the internal
14727570SDavid.Zhang@Sun.COM  *      command 'driver-assessment' code.
14737570SDavid.Zhang@Sun.COM  *   o  Ability to record assessment, and return information back to
14747570SDavid.Zhang@Sun.COM  *      top-level telemetry generation code when an unexpected condition
14757570SDavid.Zhang@Sun.COM  *      occurs.
14767570SDavid.Zhang@Sun.COM  *   o  For code paths were an command itself was successful but
14777570SDavid.Zhang@Sun.COM  *      the data returned looks suspect, the ability to record
14787570SDavid.Zhang@Sun.COM  *      'unexpected data' conditions.
14797570SDavid.Zhang@Sun.COM  *   o  Record assessment of issuing the command and interpreting
14807570SDavid.Zhang@Sun.COM  *      the returned data for consumption by top-level ereport telemetry
14817570SDavid.Zhang@Sun.COM  *      generation code.
14827570SDavid.Zhang@Sun.COM  *   o  All data required to produce telemetry available off single data
14837570SDavid.Zhang@Sun.COM  *      structure.
14847570SDavid.Zhang@Sun.COM  */
14857570SDavid.Zhang@Sun.COM typedef struct {
14867570SDavid.Zhang@Sun.COM 	struct sd_lun		*ssc_un;
14877570SDavid.Zhang@Sun.COM 	struct uscsi_cmd	*ssc_uscsi_cmd;
14887570SDavid.Zhang@Sun.COM 	struct sd_uscsi_info	*ssc_uscsi_info;
14897570SDavid.Zhang@Sun.COM 	int			ssc_flags; /* Bits for flags */
14908086SXiao.L@Sun.COM 	char			ssc_info[1024]; /* Buffer holding for info */
14917570SDavid.Zhang@Sun.COM } sd_ssc_t;
14927570SDavid.Zhang@Sun.COM 
14937570SDavid.Zhang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_ssc_t))
14947570SDavid.Zhang@Sun.COM 
14957570SDavid.Zhang@Sun.COM /*
14967570SDavid.Zhang@Sun.COM  * This struct switch different 'type-of-assessment'
14977570SDavid.Zhang@Sun.COM  * as an input argument for sd_ssc_assessment
14987570SDavid.Zhang@Sun.COM  *
14997570SDavid.Zhang@Sun.COM  *
15007570SDavid.Zhang@Sun.COM  * in sd_send_scsi_XXX or upper-level
15017570SDavid.Zhang@Sun.COM  *
15027570SDavid.Zhang@Sun.COM  * - SD_FMT_IGNORE
15037570SDavid.Zhang@Sun.COM  *   when send uscsi command failed, and
15047570SDavid.Zhang@Sun.COM  *   the following code check sense data properly.
15057570SDavid.Zhang@Sun.COM  *   we use 'ignore' to let sd_ssc_assessment
15067570SDavid.Zhang@Sun.COM  *   trust current and do not do additional
15077570SDavid.Zhang@Sun.COM  *   checking for the uscsi command.
15087570SDavid.Zhang@Sun.COM  *
15097570SDavid.Zhang@Sun.COM  * - SD_FMT_IGNORE_COMPROMISE
15107570SDavid.Zhang@Sun.COM  *   when send uscsi command failed, and
15117570SDavid.Zhang@Sun.COM  *   the code does not check sense data or we don't
15127570SDavid.Zhang@Sun.COM  *   think the checking is 100% coverage. We mark it
15137570SDavid.Zhang@Sun.COM  *   as 'compromise' to indicate that we need to
15147570SDavid.Zhang@Sun.COM  *   enhance current code in the future.
15157570SDavid.Zhang@Sun.COM  *
15167570SDavid.Zhang@Sun.COM  * - SD_FMT_STATUS_CHECK
15177570SDavid.Zhang@Sun.COM  *   when send uscsi command failed and cause sd entries
15187570SDavid.Zhang@Sun.COM  *   failed finally, we need to send out real reason against
15197570SDavid.Zhang@Sun.COM  *   status of uscsi command no matter if there is sense back
15207570SDavid.Zhang@Sun.COM  *   or not.
15217570SDavid.Zhang@Sun.COM  *
15227570SDavid.Zhang@Sun.COM  * - SD_FMT_STANDARD
15237570SDavid.Zhang@Sun.COM  *   when send uscsi command succeeded, and
15247570SDavid.Zhang@Sun.COM  *   the code does not check sense data, we need to check
15257570SDavid.Zhang@Sun.COM  *   it to make sure there is no 'fault'.
15267570SDavid.Zhang@Sun.COM  */
15277570SDavid.Zhang@Sun.COM enum sd_type_assessment {
15287570SDavid.Zhang@Sun.COM 	SD_FMT_IGNORE = 0,
15297570SDavid.Zhang@Sun.COM 	SD_FMT_IGNORE_COMPROMISE,
15307570SDavid.Zhang@Sun.COM 	SD_FMT_STATUS_CHECK,
15317570SDavid.Zhang@Sun.COM 	SD_FMT_STANDARD
15327570SDavid.Zhang@Sun.COM };
15337570SDavid.Zhang@Sun.COM 
15347570SDavid.Zhang@Sun.COM /*
15357570SDavid.Zhang@Sun.COM  * The following declaration are used as hints of severities when posting
15367570SDavid.Zhang@Sun.COM  * SCSI FMA ereport.
15377570SDavid.Zhang@Sun.COM  * - SD_FM_DRV_FATAL
15387570SDavid.Zhang@Sun.COM  *   When posting ereport with SD_FM_DRV_FATAL, the payload
15397570SDavid.Zhang@Sun.COM  *   "driver-assessment" will be "fail" or "fatal" depending on the
15407570SDavid.Zhang@Sun.COM  *   sense-key value. If driver-assessment is "fail", it will be
15417570SDavid.Zhang@Sun.COM  *   propagated to an upset, otherwise, a fault will be propagated.
15427570SDavid.Zhang@Sun.COM  * - SD_FM_DRV_RETRY
15437570SDavid.Zhang@Sun.COM  *   When posting ereport with SD_FM_DRV_RETRY, the payload
15447570SDavid.Zhang@Sun.COM  *   "driver-assessment" will be "retry", and it will be propagated to an
15457570SDavid.Zhang@Sun.COM  *   upset.
15467570SDavid.Zhang@Sun.COM  * - SD_FM_DRV_RECOVERY
15477570SDavid.Zhang@Sun.COM  *   When posting ereport with SD_FM_DRV_RECOVERY, the payload
15487570SDavid.Zhang@Sun.COM  *   "driver-assessment" will be "recovered", and it will be propagated to
15497570SDavid.Zhang@Sun.COM  *   an upset.
15507570SDavid.Zhang@Sun.COM  * - SD_FM_DRV_NOTICE
15517570SDavid.Zhang@Sun.COM  *   When posting ereport with SD_FM_DRV_NOTICE, the payload
15527570SDavid.Zhang@Sun.COM  *   "driver-assessment" will be "info", and it will be propagated to an
15537570SDavid.Zhang@Sun.COM  *   upset.
15547570SDavid.Zhang@Sun.COM  */
15557570SDavid.Zhang@Sun.COM enum sd_driver_assessment {
15567570SDavid.Zhang@Sun.COM 	SD_FM_DRV_FATAL = 0,
15577570SDavid.Zhang@Sun.COM 	SD_FM_DRV_RETRY,
15587570SDavid.Zhang@Sun.COM 	SD_FM_DRV_RECOVERY,
15597570SDavid.Zhang@Sun.COM 	SD_FM_DRV_NOTICE
15607570SDavid.Zhang@Sun.COM };
15617570SDavid.Zhang@Sun.COM 
15627570SDavid.Zhang@Sun.COM /*
15637570SDavid.Zhang@Sun.COM  * The following structure is used as a buffer when posting SCSI FMA
15647570SDavid.Zhang@Sun.COM  * ereport for raw i/o. It will be allocated per sd_lun when entering
15657570SDavid.Zhang@Sun.COM  * sd_unit_attach and will be deallocated when entering sd_unit_detach.
15667570SDavid.Zhang@Sun.COM  */
15677570SDavid.Zhang@Sun.COM struct sd_fm_internal {
15687570SDavid.Zhang@Sun.COM 	sd_ssc_t fm_ssc;
15697570SDavid.Zhang@Sun.COM 	struct uscsi_cmd fm_ucmd;
15707570SDavid.Zhang@Sun.COM 	struct sd_uscsi_info fm_uinfo;
15718086SXiao.L@Sun.COM 	int fm_log_level;
15727570SDavid.Zhang@Sun.COM };
15737570SDavid.Zhang@Sun.COM 
15747570SDavid.Zhang@Sun.COM /*
15757570SDavid.Zhang@Sun.COM  * Bits in ssc_flags
15767570SDavid.Zhang@Sun.COM  * sd_ssc_init will mark ssc_flags = SSC_FLAGS_UNKNOWN
15777570SDavid.Zhang@Sun.COM  * sd_ssc_send will mark ssc_flags = SSC_FLAGS_CMD_ISSUED &
15787570SDavid.Zhang@Sun.COM  *                                   SSC_FLAGS_NEED_ASSESSMENT
15797570SDavid.Zhang@Sun.COM  * sd_ssc_assessment will clear SSC_FLAGS_CMD_ISSUED and
15807570SDavid.Zhang@Sun.COM  * SSC_FLAGS_NEED_ASSESSMENT bits of ssc_flags.
15817570SDavid.Zhang@Sun.COM  * SSC_FLAGS_CMD_ISSUED is to indicate whether the SCSI command has been
15827570SDavid.Zhang@Sun.COM  * sent out.
15837570SDavid.Zhang@Sun.COM  * SSC_FLAGS_NEED_ASSESSMENT is to guarantee we will not miss any
15847570SDavid.Zhang@Sun.COM  * assessment point.
15857570SDavid.Zhang@Sun.COM  */
15867570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_UNKNOWN		0x00000000
15877570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_CMD_ISSUED		0x00000001
15887570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_NEED_ASSESSMENT	0x00000002
15897570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_TRAN_ABORT		0x00000004
15907570SDavid.Zhang@Sun.COM 
15917570SDavid.Zhang@Sun.COM /*
15927570SDavid.Zhang@Sun.COM  * The following bits in ssc_flags are for detecting unexpected data.
15937570SDavid.Zhang@Sun.COM  */
15947570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_INVALID_PKT_REASON	0x00000010
15957570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_INVALID_STATUS	0x00000020
15967570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_INVALID_SENSE		0x00000040
15977570SDavid.Zhang@Sun.COM #define		SSC_FLAGS_INVALID_DATA		0x00000080
15980Sstevel@tonic-gate 
15990Sstevel@tonic-gate /*
16008086SXiao.L@Sun.COM  * The following are the values available for sd_fm_internal::fm_log_level.
16018086SXiao.L@Sun.COM  * SD_FM_LOG_NSUP	The driver will log things in traditional way as if
16028086SXiao.L@Sun.COM  * 			the SCSI FMA feature is unavailable.
16038086SXiao.L@Sun.COM  * SD_FM_LOG_SILENT	The driver will not print out syslog for FMA error
16048086SXiao.L@Sun.COM  * 			telemetry, all the error telemetries will go into
16058086SXiao.L@Sun.COM  * 			FMA error log.
16068086SXiao.L@Sun.COM  * SD_FM_LOG_EREPORT	The driver will both print the FMA error telemetry
16078086SXiao.L@Sun.COM  * 			and post the error report, but the traditional
16088086SXiao.L@Sun.COM  * 			syslog for error telemetry will be suppressed.
16098086SXiao.L@Sun.COM  */
16108086SXiao.L@Sun.COM #define		SD_FM_LOG_NSUP		0
16118086SXiao.L@Sun.COM #define		SD_FM_LOG_SILENT	1
16128086SXiao.L@Sun.COM #define		SD_FM_LOG_EREPORT	2
16138086SXiao.L@Sun.COM 
16148086SXiao.L@Sun.COM /*
16150Sstevel@tonic-gate  * Macros and definitions for driver kstats and errstats
16160Sstevel@tonic-gate  *
16170Sstevel@tonic-gate  * Some third-party layered drivers (they know who they are) do not maintain
16180Sstevel@tonic-gate  * their open/close counts correctly which causes our kstat reporting to get
16190Sstevel@tonic-gate  * messed up & results in panics. These macros will update the driver kstats
16200Sstevel@tonic-gate  * only if the counts are valid.
16210Sstevel@tonic-gate  */
16220Sstevel@tonic-gate #define	SD_UPDATE_COMMON_KSTATS(kstat_function, kstatp)			\
16230Sstevel@tonic-gate 	if ((kstat_function)  == kstat_runq_exit ||			\
16240Sstevel@tonic-gate 	    ((kstat_function) == kstat_runq_back_to_waitq)) { 		\
16250Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->rcnt) {			\
16260Sstevel@tonic-gate 			kstat_function((kstatp));			\
16270Sstevel@tonic-gate 		} else {						\
16280Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
16290Sstevel@tonic-gate 		"kstat rcnt == 0 when exiting runq, please check\n");	\
16300Sstevel@tonic-gate 		}							\
16310Sstevel@tonic-gate 	} else if ((kstat_function) == kstat_waitq_exit ||		\
16320Sstevel@tonic-gate 	    ((kstat_function) == kstat_waitq_to_runq)) {		\
16330Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->wcnt) {			\
16340Sstevel@tonic-gate 			kstat_function(kstatp);				\
16350Sstevel@tonic-gate 		} else {						\
16360Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
16370Sstevel@tonic-gate 		"kstat wcnt == 0 when exiting waitq, please check\n");	\
16380Sstevel@tonic-gate 		}							\
16390Sstevel@tonic-gate 	} else {							\
16400Sstevel@tonic-gate 		kstat_function(kstatp);					\
16410Sstevel@tonic-gate 	}
16420Sstevel@tonic-gate 
16430Sstevel@tonic-gate #define	SD_UPDATE_KSTATS(un, kstat_function, bp)			\
16440Sstevel@tonic-gate 	ASSERT(SD_GET_XBUF(bp) != NULL);				\
16450Sstevel@tonic-gate 	if (SD_IS_BUFIO(SD_GET_XBUF(bp))) {				\
16460Sstevel@tonic-gate 		struct kstat *pksp =					\
16470Sstevel@tonic-gate 			(un)->un_pstats[SDPART((bp)->b_edev)];		\
16480Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
16490Sstevel@tonic-gate 		if ((un)->un_stats != NULL) {				\
16500Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);	\
16510Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
16520Sstevel@tonic-gate 		}							\
16530Sstevel@tonic-gate 		if (pksp != NULL) {					\
16540Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR(pksp);		\
16550Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
16560Sstevel@tonic-gate 		}							\
16570Sstevel@tonic-gate 	}
16580Sstevel@tonic-gate 
16590Sstevel@tonic-gate #define	SD_UPDATE_ERRSTATS(un, x)					\
16600Sstevel@tonic-gate 	if ((un)->un_errstats != NULL) {				\
16610Sstevel@tonic-gate 		struct sd_errstats *stp;				\
16620Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
16630Sstevel@tonic-gate 		stp = (struct sd_errstats *)(un)->un_errstats->ks_data;	\
16640Sstevel@tonic-gate 		stp->x.value.ui32++;					\
16650Sstevel@tonic-gate 	}
16660Sstevel@tonic-gate 
16670Sstevel@tonic-gate #define	SD_UPDATE_RDWR_STATS(un, bp)					\
16680Sstevel@tonic-gate 	if ((un)->un_stats != NULL) {					\
16690Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);		\
16700Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
16710Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
16720Sstevel@tonic-gate 			kip->reads++;					\
16730Sstevel@tonic-gate 			kip->nread += n_done;				\
16740Sstevel@tonic-gate 		} else {						\
16750Sstevel@tonic-gate 			kip->writes++;					\
16760Sstevel@tonic-gate 			kip->nwritten += n_done;			\
16770Sstevel@tonic-gate 		}							\
16780Sstevel@tonic-gate 	}
16790Sstevel@tonic-gate 
16800Sstevel@tonic-gate #define	SD_UPDATE_PARTITION_STATS(un, bp)				\
16810Sstevel@tonic-gate {									\
16820Sstevel@tonic-gate 	struct kstat *pksp = (un)->un_pstats[SDPART((bp)->b_edev)];	\
16830Sstevel@tonic-gate 	if (pksp != NULL) {						\
16840Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR(pksp);			\
16850Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
16860Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
16870Sstevel@tonic-gate 			kip->reads++;					\
16880Sstevel@tonic-gate 			kip->nread += n_done;				\
16890Sstevel@tonic-gate 		} else {						\
16900Sstevel@tonic-gate 			kip->writes++;					\
16910Sstevel@tonic-gate 			kip->nwritten += n_done;			\
16920Sstevel@tonic-gate 		}							\
16930Sstevel@tonic-gate 	}								\
16940Sstevel@tonic-gate }
16950Sstevel@tonic-gate 
16960Sstevel@tonic-gate 
16970Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
16980Sstevel@tonic-gate 
16990Sstevel@tonic-gate 
17000Sstevel@tonic-gate /*
17010Sstevel@tonic-gate  * 60 seconds is a *very* reasonable amount of time for most slow CD
17020Sstevel@tonic-gate  * operations.
17030Sstevel@tonic-gate  */
17040Sstevel@tonic-gate #define	SD_IO_TIME			60
17050Sstevel@tonic-gate 
17060Sstevel@tonic-gate /*
17070Sstevel@tonic-gate  * 2 hours is an excessively reasonable amount of time for format operations.
17080Sstevel@tonic-gate  */
17090Sstevel@tonic-gate #define	SD_FMT_TIME			(120 * 60)
17100Sstevel@tonic-gate 
17110Sstevel@tonic-gate /*
17120Sstevel@tonic-gate  * 5 seconds is what we'll wait if we get a Busy Status back
17130Sstevel@tonic-gate  */
17140Sstevel@tonic-gate #define	SD_BSY_TIMEOUT			(drv_usectohz(5 * 1000000))
17150Sstevel@tonic-gate 
17160Sstevel@tonic-gate /*
17170Sstevel@tonic-gate  * 100 msec. is what we'll wait if we get Unit Attention.
17180Sstevel@tonic-gate  */
17190Sstevel@tonic-gate #define	SD_UA_RETRY_DELAY		(drv_usectohz((clock_t)100000))
17200Sstevel@tonic-gate 
17210Sstevel@tonic-gate /*
17220Sstevel@tonic-gate  * 100 msec. is what we'll wait for restarted commands.
17230Sstevel@tonic-gate  */
17240Sstevel@tonic-gate #define	SD_RESTART_TIMEOUT		(drv_usectohz((clock_t)100000))
17250Sstevel@tonic-gate 
17260Sstevel@tonic-gate /*
17279889SLarry.Liu@Sun.COM  * 10s misaligned I/O warning message interval
17289889SLarry.Liu@Sun.COM  */
17299889SLarry.Liu@Sun.COM #define	SD_RMW_MSG_PRINT_TIMEOUT	(drv_usectohz((clock_t)10000000))
17309889SLarry.Liu@Sun.COM 
17319889SLarry.Liu@Sun.COM /*
17320Sstevel@tonic-gate  * 100 msec. is what we'll wait for certain retries for fibre channel
17330Sstevel@tonic-gate  * targets, 0 msec for parallel SCSI.
17340Sstevel@tonic-gate  */
17350Sstevel@tonic-gate #if defined(__fibre)
17360Sstevel@tonic-gate #define	SD_RETRY_DELAY			(drv_usectohz(100000))
17370Sstevel@tonic-gate #else
17380Sstevel@tonic-gate #define	SD_RETRY_DELAY			((clock_t)0)
17390Sstevel@tonic-gate #endif
17400Sstevel@tonic-gate 
17410Sstevel@tonic-gate /*
17420Sstevel@tonic-gate  * 60 seconds is what we will wait for to reset the
17430Sstevel@tonic-gate  * throttle back to it SD_MAX_THROTTLE.
17440Sstevel@tonic-gate  */
17450Sstevel@tonic-gate #define	SD_RESET_THROTTLE_TIMEOUT	60
17460Sstevel@tonic-gate 
17470Sstevel@tonic-gate /*
17480Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
17490Sstevel@tonic-gate  *
17500Sstevel@tonic-gate  * This includes retries due to transport failure
17510Sstevel@tonic-gate  * (need to distinguish between Target and Transport failure)
17520Sstevel@tonic-gate  *
17530Sstevel@tonic-gate  */
17540Sstevel@tonic-gate #if defined(__fibre)
17550Sstevel@tonic-gate #define	SD_RETRY_COUNT			3
17560Sstevel@tonic-gate #else
17570Sstevel@tonic-gate #define	SD_RETRY_COUNT			5
17580Sstevel@tonic-gate #endif
17590Sstevel@tonic-gate 
17600Sstevel@tonic-gate /*
17610Sstevel@tonic-gate  * Number of times we will retry for unit attention.
17620Sstevel@tonic-gate  */
17630Sstevel@tonic-gate #define	SD_UA_RETRY_COUNT		600
17640Sstevel@tonic-gate 
17650Sstevel@tonic-gate #define	SD_VICTIM_RETRY_COUNT(un)	(un->un_victim_retry_count)
17660Sstevel@tonic-gate #define	CD_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count * 2)
17670Sstevel@tonic-gate #define	DISK_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count / 2)
17680Sstevel@tonic-gate 
17690Sstevel@tonic-gate 
17700Sstevel@tonic-gate /*
17710Sstevel@tonic-gate  * Maximum number of units we can support
17720Sstevel@tonic-gate  * (controlled by room in minor device byte)
17730Sstevel@tonic-gate  *
17740Sstevel@tonic-gate  * Note: this value is out of date.
17750Sstevel@tonic-gate  */
17760Sstevel@tonic-gate #define	SD_MAXUNIT			32
17770Sstevel@tonic-gate 
17780Sstevel@tonic-gate /*
17790Sstevel@tonic-gate  * 30 seconds is what we will wait for the IO to finish
17800Sstevel@tonic-gate  * before we fail the DDI_SUSPEND
17810Sstevel@tonic-gate  */
17820Sstevel@tonic-gate #define	SD_WAIT_CMDS_COMPLETE		30
17830Sstevel@tonic-gate 
17840Sstevel@tonic-gate /*
17850Sstevel@tonic-gate  * Prevent/allow media removal flags
17860Sstevel@tonic-gate  */
17870Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW		0
17880Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT		1
17890Sstevel@tonic-gate 
17900Sstevel@tonic-gate 
17910Sstevel@tonic-gate /*
17920Sstevel@tonic-gate  * Drive Types (and characteristics)
17930Sstevel@tonic-gate  */
17940Sstevel@tonic-gate #define	VIDMAX				8
17950Sstevel@tonic-gate #define	PIDMAX				16
17960Sstevel@tonic-gate 
17970Sstevel@tonic-gate 
17980Sstevel@tonic-gate /*
17990Sstevel@tonic-gate  * The following #defines and type definitions for the property
18000Sstevel@tonic-gate  * processing component of the sd driver.
18010Sstevel@tonic-gate  */
18020Sstevel@tonic-gate 
18030Sstevel@tonic-gate 
18040Sstevel@tonic-gate /* Miscellaneous Definitions */
18050Sstevel@tonic-gate #define	SD_CONF_VERSION_1		1
18060Sstevel@tonic-gate #define	SD_CONF_NOT_USED		32
18070Sstevel@tonic-gate 
18080Sstevel@tonic-gate /*
180910131SJane.Chu@Sun.COM  * "pm-capable" property values and macros
18100Sstevel@tonic-gate  */
18110Sstevel@tonic-gate #define	SD_PM_CAPABLE_UNDEFINED		-1
181210131SJane.Chu@Sun.COM 
181310131SJane.Chu@Sun.COM #define	SD_PM_CAPABLE_IS_UNDEFINED(pm_cap)	\
181410131SJane.Chu@Sun.COM 	(pm_cap == SD_PM_CAPABLE_UNDEFINED)
181510131SJane.Chu@Sun.COM 
181610131SJane.Chu@Sun.COM #define	SD_PM_CAPABLE_IS_FALSE(pm_cap)	\
181710131SJane.Chu@Sun.COM 	((pm_cap & PM_CAPABLE_PM_MASK) == 0)
181810131SJane.Chu@Sun.COM 
181910131SJane.Chu@Sun.COM #define	SD_PM_CAPABLE_IS_TRUE(pm_cap)	\
182010131SJane.Chu@Sun.COM 	(!SD_PM_CAPABLE_IS_UNDEFINED(pm_cap) && \
182110131SJane.Chu@Sun.COM 	    ((pm_cap & PM_CAPABLE_PM_MASK) > 0))
182210131SJane.Chu@Sun.COM 
182310131SJane.Chu@Sun.COM #define	SD_PM_CAPABLE_IS_SPC_4(pm_cap)	\
182410131SJane.Chu@Sun.COM 	((pm_cap & PM_CAPABLE_PM_MASK) == PM_CAPABLE_SPC4)
182510131SJane.Chu@Sun.COM 
182610131SJane.Chu@Sun.COM #define	SD_PM_CAP_LOG_SUPPORTED(pm_cap)	\
182710131SJane.Chu@Sun.COM 	((pm_cap & PM_CAPABLE_LOG_SUPPORTED) ? TRUE : FALSE)
182810131SJane.Chu@Sun.COM 
182910131SJane.Chu@Sun.COM #define	SD_PM_CAP_SMART_LOG(pm_cap)	\
183010131SJane.Chu@Sun.COM 	((pm_cap & PM_CAPABLE_SMART_LOG) ? TRUE : FALSE)
18310Sstevel@tonic-gate 
18320Sstevel@tonic-gate /*
18330Sstevel@tonic-gate  * Property data values used in static configuration table
18340Sstevel@tonic-gate  * These are all based on device characteristics.
18350Sstevel@tonic-gate  * For fibre channel devices, the throttle value is usually
18360Sstevel@tonic-gate  * derived from the devices cmd Q depth divided by the number
18370Sstevel@tonic-gate  * of supported initiators.
18380Sstevel@tonic-gate  */
18390Sstevel@tonic-gate #define	ELITE_THROTTLE_VALUE		10
18400Sstevel@tonic-gate #define	SEAGATE_THROTTLE_VALUE		15
18410Sstevel@tonic-gate #define	IBM_THROTTLE_VALUE		15
18420Sstevel@tonic-gate #define	ST31200N_THROTTLE_VALUE		8
18430Sstevel@tonic-gate #define	FUJITSU_THROTTLE_VALUE		15
18440Sstevel@tonic-gate #define	SYMBIOS_THROTTLE_VALUE		16
18450Sstevel@tonic-gate #define	SYMBIOS_NOTREADY_RETRIES	24
18460Sstevel@tonic-gate #define	LSI_THROTTLE_VALUE		16
18470Sstevel@tonic-gate #define	LSI_NOTREADY_RETRIES		24
18480Sstevel@tonic-gate #define	LSI_OEM_NOTREADY_RETRIES	36
18490Sstevel@tonic-gate #define	PURPLE_THROTTLE_VALUE		64
18500Sstevel@tonic-gate #define	PURPLE_BUSY_RETRIES		60
18510Sstevel@tonic-gate #define	PURPLE_RESET_RETRY_COUNT	36
18520Sstevel@tonic-gate #define	PURPLE_RESERVE_RELEASE_TIME	60
18530Sstevel@tonic-gate #define	SVE_BUSY_RETRIES		60
18540Sstevel@tonic-gate #define	SVE_RESET_RETRY_COUNT		36
18550Sstevel@tonic-gate #define	SVE_RESERVE_RELEASE_TIME	60
18560Sstevel@tonic-gate #define	SVE_THROTTLE_VALUE		10
18570Sstevel@tonic-gate #define	SVE_MIN_THROTTLE_VALUE		2
18580Sstevel@tonic-gate #define	SVE_DISKSORT_DISABLED_FLAG	1
18590Sstevel@tonic-gate #define	MASERATI_DISKSORT_DISABLED_FLAG	1
18600Sstevel@tonic-gate #define	MASERATI_LUN_RESET_ENABLED_FLAG	1
18610Sstevel@tonic-gate #define	PIRUS_THROTTLE_VALUE		64
18620Sstevel@tonic-gate #define	PIRUS_NRR_COUNT			60
18630Sstevel@tonic-gate #define	PIRUS_BUSY_RETRIES		60
18640Sstevel@tonic-gate #define	PIRUS_RESET_RETRY_COUNT		36
18650Sstevel@tonic-gate #define	PIRUS_MIN_THROTTLE_VALUE	16
18660Sstevel@tonic-gate #define	PIRUS_DISKSORT_DISABLED_FLAG	0
18670Sstevel@tonic-gate #define	PIRUS_LUN_RESET_ENABLED_FLAG	1
18680Sstevel@tonic-gate 
18690Sstevel@tonic-gate /*
18700Sstevel@tonic-gate  * Driver Property Bit Flag definitions
18710Sstevel@tonic-gate  *
1872173Scth  * Unfortunately, for historical reasons, the bit-flag definitions are
18730Sstevel@tonic-gate  * different on SPARC, INTEL, & FIBRE platforms.
18740Sstevel@tonic-gate  */
18750Sstevel@tonic-gate 
18760Sstevel@tonic-gate /*
18770Sstevel@tonic-gate  * Bit flag telling driver to set throttle from sd.conf sd-config-list
18780Sstevel@tonic-gate  * and driver table.
18790Sstevel@tonic-gate  *
18800Sstevel@tonic-gate  * The max throttle (q-depth) property implementation is for support of
18810Sstevel@tonic-gate  * fibre channel devices that can drop an i/o request when a queue fills
18820Sstevel@tonic-gate  * up. The number of commands sent to the disk from this driver is
18830Sstevel@tonic-gate  * regulated such that queue overflows are avoided.
18840Sstevel@tonic-gate  */
18850Sstevel@tonic-gate #define	SD_CONF_SET_THROTTLE		0
18860Sstevel@tonic-gate #define	SD_CONF_BSET_THROTTLE		(1 << SD_CONF_SET_THROTTLE)
18870Sstevel@tonic-gate 
18880Sstevel@tonic-gate /*
18890Sstevel@tonic-gate  * Bit flag telling driver to set the controller type from sd.conf
18900Sstevel@tonic-gate  * sd-config-list and driver table.
18910Sstevel@tonic-gate  */
18920Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
18930Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
18940Sstevel@tonic-gate #elif defined(__fibre)
18950Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		5
18960Sstevel@tonic-gate #else
18970Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
18980Sstevel@tonic-gate #endif
18990Sstevel@tonic-gate #define	SD_CONF_BSET_CTYPE		(1 << SD_CONF_SET_CTYPE)
19000Sstevel@tonic-gate 
19010Sstevel@tonic-gate /*
19020Sstevel@tonic-gate  * Bit flag telling driver to set the not ready retry count for a device from
19030Sstevel@tonic-gate  * sd.conf sd-config-list and driver table.
19040Sstevel@tonic-gate  */
19050Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19060Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	10
19070Sstevel@tonic-gate #elif defined(__fibre)
19080Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	1
19090Sstevel@tonic-gate #else
19100Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	2
19110Sstevel@tonic-gate #endif
19120Sstevel@tonic-gate #define	SD_CONF_BSET_NRR_COUNT		(1 << SD_CONF_SET_NOTREADY_RETRIES)
19130Sstevel@tonic-gate 
19140Sstevel@tonic-gate /*
19150Sstevel@tonic-gate  * Bit flag telling driver to set SCSI status BUSY Retries from sd.conf
19160Sstevel@tonic-gate  * sd-config-list and driver table.
19170Sstevel@tonic-gate  */
19180Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19190Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	11
19200Sstevel@tonic-gate #elif defined(__fibre)
19210Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	2
19220Sstevel@tonic-gate #else
19230Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	5
19240Sstevel@tonic-gate #endif
19250Sstevel@tonic-gate #define	SD_CONF_BSET_BSY_RETRY_COUNT	(1 << SD_CONF_SET_BUSY_RETRIES)
19260Sstevel@tonic-gate 
19270Sstevel@tonic-gate /*
19280Sstevel@tonic-gate  * Bit flag telling driver that device does not have a valid/unique serial
19290Sstevel@tonic-gate  * number.
19300Sstevel@tonic-gate  */
19310Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19320Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		2
19330Sstevel@tonic-gate #else
19340Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		3
19350Sstevel@tonic-gate #endif
19360Sstevel@tonic-gate #define	SD_CONF_BSET_FAB_DEVID   	(1 << SD_CONF_SET_FAB_DEVID)
19370Sstevel@tonic-gate 
19380Sstevel@tonic-gate /*
19390Sstevel@tonic-gate  * Bit flag telling driver to disable all caching for disk device.
19400Sstevel@tonic-gate  */
19410Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19420Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		3
19430Sstevel@tonic-gate #else
19440Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		4
19450Sstevel@tonic-gate #endif
19460Sstevel@tonic-gate #define	SD_CONF_BSET_NOCACHE		(1 << SD_CONF_SET_NOCACHE)
19470Sstevel@tonic-gate 
19480Sstevel@tonic-gate /*
19490Sstevel@tonic-gate  * Bit flag telling driver that the PLAY AUDIO command requires parms in BCD
19500Sstevel@tonic-gate  * format rather than binary.
19510Sstevel@tonic-gate  */
19520Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19530Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		4
19540Sstevel@tonic-gate #else
19550Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		6
19560Sstevel@tonic-gate #endif
19570Sstevel@tonic-gate #define	SD_CONF_BSET_PLAYMSF_BCD    	(1 << SD_CONF_SET_PLAYMSF_BCD)
19580Sstevel@tonic-gate 
19590Sstevel@tonic-gate /*
19600Sstevel@tonic-gate  * Bit flag telling driver that the response from the READ SUBCHANNEL command
19610Sstevel@tonic-gate  * has BCD fields rather than binary.
19620Sstevel@tonic-gate  */
19630Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19640Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		5
19650Sstevel@tonic-gate #else
19660Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		7
19670Sstevel@tonic-gate #endif
19680Sstevel@tonic-gate #define	SD_CONF_BSET_READSUB_BCD	(1 << SD_CONF_SET_READSUB_BCD)
19690Sstevel@tonic-gate 
19700Sstevel@tonic-gate /*
19710Sstevel@tonic-gate  * Bit in flags telling driver that the track number fields in the READ TOC
19720Sstevel@tonic-gate  * request and respone are in BCD rather than binary.
19730Sstevel@tonic-gate  */
19740Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19750Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	6
19760Sstevel@tonic-gate #else
19770Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	8
19780Sstevel@tonic-gate #endif
19790Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_TRK_BCD	(1 << SD_CONF_SET_READ_TOC_TRK_BCD)
19800Sstevel@tonic-gate 
19810Sstevel@tonic-gate /*
19820Sstevel@tonic-gate  * Bit flag telling driver that the address fields in the READ TOC request and
19830Sstevel@tonic-gate  * respone are in BCD rather than binary.
19840Sstevel@tonic-gate  */
19850Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19860Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	7
19870Sstevel@tonic-gate #else
19880Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	9
19890Sstevel@tonic-gate #endif
19900Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_ADDR_BCD	(1 << SD_CONF_SET_READ_TOC_ADDR_BCD)
19910Sstevel@tonic-gate 
19920Sstevel@tonic-gate /*
19930Sstevel@tonic-gate  * Bit flag telling the driver that the device doesn't support the READ HEADER
19940Sstevel@tonic-gate  * command.
19950Sstevel@tonic-gate  */
19960Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19970Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	8
19980Sstevel@tonic-gate #else
19990Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	10
20000Sstevel@tonic-gate #endif
20010Sstevel@tonic-gate #define	SD_CONF_BSET_NO_READ_HEADER 	(1 << SD_CONF_SET_NO_READ_HEADER)
20020Sstevel@tonic-gate 
20030Sstevel@tonic-gate /*
20040Sstevel@tonic-gate  * Bit flag telling the driver that for the READ CD command the device uses
20050Sstevel@tonic-gate  * opcode 0xd4 rather than 0xbe.
20060Sstevel@tonic-gate  */
20070Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
20080Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4		9
20090Sstevel@tonic-gate #else
20100Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4 	11
20110Sstevel@tonic-gate #endif
20120Sstevel@tonic-gate #define	SD_CONF_BSET_READ_CD_XD4	(1 << SD_CONF_SET_READ_CD_XD4)
20130Sstevel@tonic-gate 
20140Sstevel@tonic-gate /*
20150Sstevel@tonic-gate  * Bit flag telling the driver to set SCSI status Reset Retries
20160Sstevel@tonic-gate  * (un_reset_retry_count) from sd.conf sd-config-list and driver table (4356701)
20170Sstevel@tonic-gate  */
20180Sstevel@tonic-gate #define	SD_CONF_SET_RST_RETRIES		12
20190Sstevel@tonic-gate #define	SD_CONF_BSET_RST_RETRIES	(1 << SD_CONF_SET_RST_RETRIES)
20200Sstevel@tonic-gate 
20210Sstevel@tonic-gate /*
20220Sstevel@tonic-gate  * Bit flag telling the driver to set the reservation release timeout value
20230Sstevel@tonic-gate  * from sd.conf sd-config-list and driver table. (4367306)
20240Sstevel@tonic-gate  */
20250Sstevel@tonic-gate #define	SD_CONF_SET_RSV_REL_TIME	13
20260Sstevel@tonic-gate #define	SD_CONF_BSET_RSV_REL_TIME	(1 << SD_CONF_SET_RSV_REL_TIME)
20270Sstevel@tonic-gate 
20280Sstevel@tonic-gate /*
20290Sstevel@tonic-gate  * Bit flag telling the driver to verify that no commands are pending for a
20300Sstevel@tonic-gate  * device before issuing a Test Unit Ready. This is a fw workaround for Seagate
20310Sstevel@tonic-gate  * eliteI drives. (4392016)
20320Sstevel@tonic-gate  */
20330Sstevel@tonic-gate #define	SD_CONF_SET_TUR_CHECK		14
20340Sstevel@tonic-gate #define	SD_CONF_BSET_TUR_CHECK		(1 << SD_CONF_SET_TUR_CHECK)
20350Sstevel@tonic-gate 
20360Sstevel@tonic-gate /*
20370Sstevel@tonic-gate  * Bit in flags telling driver to set min. throttle from ssd.conf
20380Sstevel@tonic-gate  * ssd-config-list and driver table.
20390Sstevel@tonic-gate  */
20400Sstevel@tonic-gate #define	SD_CONF_SET_MIN_THROTTLE	15
20410Sstevel@tonic-gate #define	SD_CONF_BSET_MIN_THROTTLE	(1 << SD_CONF_SET_MIN_THROTTLE)
20420Sstevel@tonic-gate 
20430Sstevel@tonic-gate /*
20440Sstevel@tonic-gate  * Bit in flags telling driver to set disksort disable flag from ssd.conf
20450Sstevel@tonic-gate  * ssd-config-list and driver table.
20460Sstevel@tonic-gate  */
20470Sstevel@tonic-gate #define	SD_CONF_SET_DISKSORT_DISABLED	16
20480Sstevel@tonic-gate #define	SD_CONF_BSET_DISKSORT_DISABLED	(1 << SD_CONF_SET_DISKSORT_DISABLED)
20490Sstevel@tonic-gate 
20500Sstevel@tonic-gate /*
20510Sstevel@tonic-gate  * Bit in flags telling driver to set LUN Reset enable flag from [s]sd.conf
20520Sstevel@tonic-gate  * [s]sd-config-list and driver table.
20530Sstevel@tonic-gate  */
20540Sstevel@tonic-gate #define	SD_CONF_SET_LUN_RESET_ENABLED	17
20550Sstevel@tonic-gate #define	SD_CONF_BSET_LUN_RESET_ENABLED	(1 << SD_CONF_SET_LUN_RESET_ENABLED)
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate /*
20585065Sgz161490  * Bit in flags telling driver that the write cache on the device is
20595065Sgz161490  * non-volatile.
20605065Sgz161490  */
20615065Sgz161490 #define	SD_CONF_SET_CACHE_IS_NV	18
20625065Sgz161490 #define	SD_CONF_BSET_CACHE_IS_NV	(1 << SD_CONF_SET_CACHE_IS_NV)
20635065Sgz161490 
20645065Sgz161490 /*
206510131SJane.Chu@Sun.COM  * Bit in flags telling driver that the power condition flag from [s]sd.conf
206610131SJane.Chu@Sun.COM  * [s]sd-config-list and driver table.
206710131SJane.Chu@Sun.COM  */
206810131SJane.Chu@Sun.COM #define	SD_CONF_SET_PC_DISABLED	19
206910131SJane.Chu@Sun.COM #define	SD_CONF_BSET_PC_DISABLED	(1 << SD_CONF_SET_PC_DISABLED)
207010131SJane.Chu@Sun.COM 
207110131SJane.Chu@Sun.COM /*
20720Sstevel@tonic-gate  * This is the number of items currently settable in the sd.conf
20730Sstevel@tonic-gate  * sd-config-list.  The mask value is defined for parameter checking. The
20740Sstevel@tonic-gate  * item count and mask should be updated when new properties are added.
20750Sstevel@tonic-gate  */
20765065Sgz161490 #define	SD_CONF_MAX_ITEMS		19
20775065Sgz161490 #define	SD_CONF_BIT_MASK		0x0007FFFF
20780Sstevel@tonic-gate 
20790Sstevel@tonic-gate typedef struct {
20800Sstevel@tonic-gate 	int sdt_throttle;
20810Sstevel@tonic-gate 	int sdt_ctype;
20820Sstevel@tonic-gate 	int sdt_not_rdy_retries;
20830Sstevel@tonic-gate 	int sdt_busy_retries;
20840Sstevel@tonic-gate 	int sdt_reset_retries;
20850Sstevel@tonic-gate 	int sdt_reserv_rel_time;
20860Sstevel@tonic-gate 	int sdt_min_throttle;
20870Sstevel@tonic-gate 	int sdt_disk_sort_dis;
20880Sstevel@tonic-gate 	int sdt_lun_reset_enable;
20895065Sgz161490 	int sdt_suppress_cache_flush;
209010131SJane.Chu@Sun.COM 	int sdt_power_condition_dis;
20910Sstevel@tonic-gate } sd_tunables;
20920Sstevel@tonic-gate 
20930Sstevel@tonic-gate /* Type definition for static configuration table entries */
20940Sstevel@tonic-gate typedef struct sd_disk_config {
20950Sstevel@tonic-gate 	char	device_id[25];
20960Sstevel@tonic-gate 	uint_t	flags;
20970Sstevel@tonic-gate 	sd_tunables *properties;
20980Sstevel@tonic-gate } sd_disk_config_t;
20990Sstevel@tonic-gate 
21000Sstevel@tonic-gate /*
210110131SJane.Chu@Sun.COM  * first 2 bits of byte 4 options for 1bh command
21020Sstevel@tonic-gate  */
21030Sstevel@tonic-gate #define	SD_TARGET_STOP			0x00
21040Sstevel@tonic-gate #define	SD_TARGET_START			0x01
21050Sstevel@tonic-gate #define	SD_TARGET_EJECT			0x02
21060Sstevel@tonic-gate #define	SD_TARGET_CLOSE			0x03
21070Sstevel@tonic-gate 
210810131SJane.Chu@Sun.COM /*
210910131SJane.Chu@Sun.COM  * power condition of byte 4 for 1bh command
211010131SJane.Chu@Sun.COM  */
211110131SJane.Chu@Sun.COM #define	SD_TARGET_START_VALID		0x00
211210131SJane.Chu@Sun.COM #define	SD_TARGET_ACTIVE		0x01
211310131SJane.Chu@Sun.COM #define	SD_TARGET_IDLE			0x02
211410131SJane.Chu@Sun.COM #define	SD_TARGET_STANDBY		0x03
211510131SJane.Chu@Sun.COM 
21160Sstevel@tonic-gate 
21170Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_CODE	0x03
21180Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_CODE	0x04
21190Sstevel@tonic-gate 
21200Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_LENGTH					\
21210Sstevel@tonic-gate 	(sizeof (struct mode_format) + MODE_PARAM_LENGTH)
21220Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_LENGTH					\
21230Sstevel@tonic-gate 	(sizeof (struct mode_geometry) + MODE_PARAM_LENGTH)
21240Sstevel@tonic-gate 
21250Sstevel@tonic-gate /*
21260Sstevel@tonic-gate  * These command codes need to be moved to sys/scsi/generic/commands.h
21270Sstevel@tonic-gate  */
21280Sstevel@tonic-gate 
21290Sstevel@tonic-gate /* Both versions of the Read CD command */
21300Sstevel@tonic-gate 
21310Sstevel@tonic-gate /* the official SCMD_READ_CD now comes from cdio.h */
21320Sstevel@tonic-gate #define	SCMD_READ_CDD4		0xd4	/* the one used by some first */
21330Sstevel@tonic-gate 					/* generation ATAPI CD drives */
21340Sstevel@tonic-gate 
21350Sstevel@tonic-gate /* expected sector type filter values for Play and Read CD CDBs */
21360Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_CDDA		(1<<2)	/* IEC 908:1987 (CDDA) */
21370Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE1		(2<<2)	/* Yellow book 2048 bytes */
21380Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2		(3<<2)	/* Yellow book 2335 bytes */
21390Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM1	(4<<2)	/* 2048 bytes */
21400Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM2	(5<<2)	/* 2324 bytes */
21410Sstevel@tonic-gate 
21420Sstevel@tonic-gate /* READ CD filter bits (cdb[9]) */
21430Sstevel@tonic-gate #define	CDROM_READ_CD_SYNC	0x80	/* read sync field */
21440Sstevel@tonic-gate #define	CDROM_READ_CD_HDR	0x20	/* read four byte header */
21450Sstevel@tonic-gate #define	CDROM_READ_CD_SUBHDR	0x40	/* read sub-header */
21460Sstevel@tonic-gate #define	CDROM_READ_CD_ALLHDRS	0x60	/* read header and sub-header */
21470Sstevel@tonic-gate #define	CDROM_READ_CD_USERDATA	0x10	/* read user data */
21480Sstevel@tonic-gate #define	CDROM_READ_CD_EDC_ECC	0x08	/* read EDC and ECC field */
21490Sstevel@tonic-gate #define	CDROM_READ_CD_C2	0x02	/* read C2 error data */
21500Sstevel@tonic-gate #define	CDROM_READ_CD_C2_BEB	0x04	/* read C2 and Block Error Bits */
21510Sstevel@tonic-gate 
21520Sstevel@tonic-gate 
21530Sstevel@tonic-gate /*
21540Sstevel@tonic-gate  * These belong in sys/scsi/generic/mode.h
21550Sstevel@tonic-gate  */
21560Sstevel@tonic-gate 
21570Sstevel@tonic-gate /*
21580Sstevel@tonic-gate  * Mode Sense/Select Header response for Group 2 CDB.
21590Sstevel@tonic-gate  */
21600Sstevel@tonic-gate 
21610Sstevel@tonic-gate struct mode_header_grp2 {
21620Sstevel@tonic-gate 	uchar_t length_msb;		/* MSB - number of bytes following */
21630Sstevel@tonic-gate 	uchar_t length_lsb;
21640Sstevel@tonic-gate 	uchar_t medium_type;		/* device specific */
21650Sstevel@tonic-gate 	uchar_t device_specific;	/* device specfic parameters */
21660Sstevel@tonic-gate 	uchar_t resv[2];		/* reserved */
21670Sstevel@tonic-gate 	uchar_t bdesc_length_hi;	/* length of block descriptor(s) */
21680Sstevel@tonic-gate 					/* (if any) */
21690Sstevel@tonic-gate 	uchar_t bdesc_length_lo;
21700Sstevel@tonic-gate };
21710Sstevel@tonic-gate 
21720Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", mode_header_grp2))
21730Sstevel@tonic-gate 
21740Sstevel@tonic-gate /*
21750Sstevel@tonic-gate  * Length of the Mode Parameter Header for the Group 2 Mode Select command
21760Sstevel@tonic-gate  */
21770Sstevel@tonic-gate #define	MODE_HEADER_LENGTH_GRP2	(sizeof (struct mode_header_grp2))
21780Sstevel@tonic-gate #define	MODE_PARAM_LENGTH_GRP2 (MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
21790Sstevel@tonic-gate 
21800Sstevel@tonic-gate /*
21810Sstevel@tonic-gate  * Mode Page 1 - Error Recovery Page
21820Sstevel@tonic-gate  */
21830Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOVER		1
21840Sstevel@tonic-gate 
21850Sstevel@tonic-gate /*
21860Sstevel@tonic-gate  * The following buffer length define is 8 bytes for the Group 2 mode page
21870Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 26 bytes for the cdrom
21880Sstevel@tonic-gate  * capabilities page (per MMC-2)
21890Sstevel@tonic-gate  */
21900Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP		0x2A
21910Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP_LEN		26
21920Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_CAP		(MODEPAGE_CDROM_CAP_LEN + \
21930Sstevel@tonic-gate 	MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
21940Sstevel@tonic-gate 
21950Sstevel@tonic-gate 
21960Sstevel@tonic-gate /*
21970Sstevel@tonic-gate  * Power management defines
21980Sstevel@tonic-gate  */
21990Sstevel@tonic-gate #define	SD_SPINDLE_UNINIT	(-1)
22000Sstevel@tonic-gate #define	SD_SPINDLE_OFF		0
22010Sstevel@tonic-gate #define	SD_SPINDLE_ON		1
220210131SJane.Chu@Sun.COM #define	SD_SPINDLE_STOPPED	0
220310131SJane.Chu@Sun.COM #define	SD_SPINDLE_STANDBY	1
220410131SJane.Chu@Sun.COM #define	SD_SPINDLE_IDLE		2
220510131SJane.Chu@Sun.COM #define	SD_SPINDLE_ACTIVE	3
220610131SJane.Chu@Sun.COM #define	SD_PM_NOT_SUPPORTED	4
220710131SJane.Chu@Sun.COM 
220810131SJane.Chu@Sun.COM /*
220910131SJane.Chu@Sun.COM  * Power method flag
221010131SJane.Chu@Sun.COM  */
221110131SJane.Chu@Sun.COM #define	SD_START_STOP		0
221210131SJane.Chu@Sun.COM #define	SD_POWER_CONDITION	1
221310131SJane.Chu@Sun.COM 
221410131SJane.Chu@Sun.COM 
221510131SJane.Chu@Sun.COM /*
221610131SJane.Chu@Sun.COM  * Number of power level for start stop or power condition
221710131SJane.Chu@Sun.COM  */
221810131SJane.Chu@Sun.COM #define	SD_PM_NUM_LEVEL_SSU_SS	2
221910131SJane.Chu@Sun.COM #define	SD_PM_NUM_LEVEL_SSU_PC	4
222010131SJane.Chu@Sun.COM 
222110131SJane.Chu@Sun.COM /*
222210131SJane.Chu@Sun.COM  * SD internal power state change flag
222310131SJane.Chu@Sun.COM  */
222410131SJane.Chu@Sun.COM #define	SD_PM_STATE_CHANGE	0
222510131SJane.Chu@Sun.COM #define	SD_PM_STATE_ROLLBACK	1
222610131SJane.Chu@Sun.COM 
222710131SJane.Chu@Sun.COM /*
222810131SJane.Chu@Sun.COM  * Power attribute table
222910131SJane.Chu@Sun.COM  */
223010131SJane.Chu@Sun.COM typedef struct disk_power_attr_ss {
223110131SJane.Chu@Sun.COM 	char *pm_comp[SD_PM_NUM_LEVEL_SSU_SS + 2];	/* pm component */
223210131SJane.Chu@Sun.COM 	int ran_perf[SD_PM_NUM_LEVEL_SSU_SS];		/* random performance */
223310131SJane.Chu@Sun.COM 	int pwr_saving[SD_PM_NUM_LEVEL_SSU_SS];		/* power saving */
223410131SJane.Chu@Sun.COM 	int latency[SD_PM_NUM_LEVEL_SSU_SS];		/* latency */
223510131SJane.Chu@Sun.COM }sd_power_attr_ss;
223610131SJane.Chu@Sun.COM 
223710131SJane.Chu@Sun.COM typedef struct disk_power_attr_pc {
223810131SJane.Chu@Sun.COM 	char *pm_comp[SD_PM_NUM_LEVEL_SSU_PC + 2];	/* pm component */
223910131SJane.Chu@Sun.COM 	int ran_perf[SD_PM_NUM_LEVEL_SSU_PC];		/* random performance */
224010131SJane.Chu@Sun.COM 	int pwr_saving[SD_PM_NUM_LEVEL_SSU_PC];		/* power saving */
224110131SJane.Chu@Sun.COM 	int latency[SD_PM_NUM_LEVEL_SSU_PC];		/* latency */
224210131SJane.Chu@Sun.COM }sd_power_attr_pc;
22430Sstevel@tonic-gate 
22440Sstevel@tonic-gate 
22450Sstevel@tonic-gate /*
22460Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
22470Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
22480Sstevel@tonic-gate  * the device active.
22490Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
22500Sstevel@tonic-gate  * the token is NULLed so check for this condition.
22510Sstevel@tonic-gate  * If there's a thread that can be resumed, ie. token is not NULL, then
22520Sstevel@tonic-gate  * it can be resumed.
22530Sstevel@tonic-gate  */
22540Sstevel@tonic-gate #define	SD_OK_TO_RESUME_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
22550Sstevel@tonic-gate /*
22560Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
22570Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
22580Sstevel@tonic-gate  * the device active.
22590Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
22600Sstevel@tonic-gate  * the token is NULLed so check for this condition.
22610Sstevel@tonic-gate  */
22620Sstevel@tonic-gate #define	SD_OK_TO_SUSPEND_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
22630Sstevel@tonic-gate #define	SD_DEVICE_IS_IN_LOW_POWER(un)		((un->un_f_pm_is_enabled) && \
22640Sstevel@tonic-gate 						    (un->un_pm_count < 0))
226510131SJane.Chu@Sun.COM #define	SD_PM_STATE_ACTIVE(un)				\
226610131SJane.Chu@Sun.COM 		(un->un_f_power_condition_supported ?	\
226710131SJane.Chu@Sun.COM 		SD_SPINDLE_ACTIVE : SD_SPINDLE_ON)
226810131SJane.Chu@Sun.COM #define	SD_PM_STATE_STOPPED(un)				\
226910131SJane.Chu@Sun.COM 		(un->un_f_power_condition_supported ?	\
227010131SJane.Chu@Sun.COM 		SD_SPINDLE_STOPPED : SD_SPINDLE_OFF)
227110131SJane.Chu@Sun.COM #define	SD_PM_IS_LEVEL_VALID(un, level)			\
227210131SJane.Chu@Sun.COM 		((un->un_f_power_condition_supported &&	\
227310131SJane.Chu@Sun.COM 		level >= SD_SPINDLE_STOPPED &&		\
227410131SJane.Chu@Sun.COM 		level <= SD_SPINDLE_ACTIVE) ||		\
227510131SJane.Chu@Sun.COM 		(!un->un_f_power_condition_supported &&	\
227610131SJane.Chu@Sun.COM 		level >= SD_SPINDLE_OFF &&		\
227710131SJane.Chu@Sun.COM 		level <= SD_SPINDLE_ON))
227810131SJane.Chu@Sun.COM #define	SD_PM_IS_IO_CAPABLE(un, level)			\
227910131SJane.Chu@Sun.COM 		((un->un_f_power_condition_supported &&	\
228010131SJane.Chu@Sun.COM 		sd_pwr_pc.ran_perf[level] > 0) ||	\
228110131SJane.Chu@Sun.COM 		(!un->un_f_power_condition_supported &&	\
228210131SJane.Chu@Sun.COM 		sd_pwr_ss.ran_perf[level] > 0))
228310131SJane.Chu@Sun.COM #define	SD_PM_STOP_MOTOR_NEEDED(un, level)		\
228410131SJane.Chu@Sun.COM 		((un->un_f_power_condition_supported &&	\
228510131SJane.Chu@Sun.COM 		level <= SD_SPINDLE_STANDBY) ||		\
228610131SJane.Chu@Sun.COM 		(!un->un_f_power_condition_supported &&	\
228710131SJane.Chu@Sun.COM 		level == SD_SPINDLE_OFF))
228810131SJane.Chu@Sun.COM 
22890Sstevel@tonic-gate /*
22900Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
22910Sstevel@tonic-gate  * But for now let it live here.
22920Sstevel@tonic-gate  */
22930Sstevel@tonic-gate #define	START_STOP_CYCLE_COUNTER_PAGE_SIZE	0x28
22940Sstevel@tonic-gate #define	START_STOP_CYCLE_PAGE			0x0E
22950Sstevel@tonic-gate #define	START_STOP_CYCLE_VU_PAGE		0x31
22960Sstevel@tonic-gate 
22970Sstevel@tonic-gate /* CD-ROM Error Recovery Parameters page (0x01) */
22980Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOV	0x1
22990Sstevel@tonic-gate #define	BUFLEN_CHG_BLK_MODE	MODE_HEADER_LENGTH + MODE_BLK_DESC_LENGTH
23000Sstevel@tonic-gate 
23010Sstevel@tonic-gate /*
23020Sstevel@tonic-gate  * Vendor Specific (Toshiba) CD-ROM Speed page (0x31)
23030Sstevel@tonic-gate  *
23040Sstevel@tonic-gate  * The following buffer length define is 4 bytes for the Group 0 mode page
23050Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 4 bytes for the mode speed page.
23060Sstevel@tonic-gate  */
23070Sstevel@tonic-gate #define	MODEPAGE_CDROM_SPEED_LEN	4
23080Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_SPEED		MODEPAGE_CDROM_SPEED_LEN +\
23090Sstevel@tonic-gate 					MODE_HEADER_LENGTH +\
23100Sstevel@tonic-gate 					MODE_BLK_DESC_LENGTH
23110Sstevel@tonic-gate #define	SD_SPEED_1X			176
23120Sstevel@tonic-gate 
23130Sstevel@tonic-gate /* CD-ROM Audio Control Parameters page (0x0E) */
23140Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL		0x0E
23150Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL_LEN		16
23160Sstevel@tonic-gate 
23170Sstevel@tonic-gate /* CD-ROM Sony Read Offset Defines */
23180Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_LEN		12
23190Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_KEY		0x40
23200Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_VALID	0x0a
23210Sstevel@tonic-gate 
23220Sstevel@tonic-gate /*
23230Sstevel@tonic-gate  * CD-ROM Write Protect Defines
23240Sstevel@tonic-gate  *
23250Sstevel@tonic-gate  * Bit 7 of the device specific field of the mode page header is the write
23260Sstevel@tonic-gate  * protect bit.
23270Sstevel@tonic-gate  */
23280Sstevel@tonic-gate #define	WRITE_PROTECT 0x80
23290Sstevel@tonic-gate 
23300Sstevel@tonic-gate /*
23310Sstevel@tonic-gate  * Define for the length of a profile header returned in response to the
23320Sstevel@tonic-gate  * GET CONFIGURATION command
23330Sstevel@tonic-gate  */
23340Sstevel@tonic-gate #define	SD_PROFILE_HEADER_LEN		8	/* bytes */
23350Sstevel@tonic-gate 
23360Sstevel@tonic-gate /*
2337270Sphitran  * Define the length of the data in response to the GET CONFIGURATION
2338270Sphitran  * command.  The 3rd byte of the feature descriptor contains the
2339270Sphitran  * current feature field that is of interest.  This field begins
2340270Sphitran  * after the feature header which is 8 bytes.  This variable length
2341270Sphitran  * was increased in size from 11 to 24 because some devices became
2342270Sphitran  * unresponsive with the smaller size.
23430Sstevel@tonic-gate  */
2344270Sphitran #define	SD_CURRENT_FEATURE_LEN		24	/* bytes */
23450Sstevel@tonic-gate 
23460Sstevel@tonic-gate /*
23470Sstevel@tonic-gate  * Feature codes associated with GET CONFIGURATION command for supported
23480Sstevel@tonic-gate  * devices.
23490Sstevel@tonic-gate  */
23500Sstevel@tonic-gate #define	RANDOM_WRITABLE			0x20
23510Sstevel@tonic-gate #define	HARDWARE_DEFECT_MANAGEMENT	0x24
23520Sstevel@tonic-gate 
23530Sstevel@tonic-gate /*
23540Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
23550Sstevel@tonic-gate  * But for now let it live here.
23560Sstevel@tonic-gate  */
23570Sstevel@tonic-gate #define	TEMPERATURE_PAGE			0x0D
23580Sstevel@tonic-gate #define	TEMPERATURE_PAGE_SIZE			16	/* bytes */
23590Sstevel@tonic-gate 
23600Sstevel@tonic-gate /* delay time used for sd_media_watch_cb delayed cv broadcast */
23610Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 2000000
23620Sstevel@tonic-gate 
23630Sstevel@tonic-gate 
23640Sstevel@tonic-gate /* SCSI power on or bus device reset additional sense code */
23650Sstevel@tonic-gate #define	SD_SCSI_RESET_SENSE_CODE	0x29
23660Sstevel@tonic-gate 
23670Sstevel@tonic-gate /*
23680Sstevel@tonic-gate  * These defines are for the Vital Product Data Pages in the inquiry command.
23690Sstevel@tonic-gate  * They are the bits in the un_vpd_page mask, telling the supported pages.
23700Sstevel@tonic-gate  */
23710Sstevel@tonic-gate #define	SD_VPD_SUPPORTED_PG	0x01	/* 0x00 - Supported VPD pages */
23720Sstevel@tonic-gate #define	SD_VPD_UNIT_SERIAL_PG	0x02	/* 0x80 - Unit Serial Number */
23730Sstevel@tonic-gate #define	SD_VPD_OPERATING_PG	0x04	/* 0x81 - Implemented Op Defs */
23740Sstevel@tonic-gate #define	SD_VPD_ASCII_OP_PG	0x08	/* 0x82 - ASCII Op Defs */
23750Sstevel@tonic-gate #define	SD_VPD_DEVID_WWN_PG	0x10	/* 0x83 - Device Identification */
23765065Sgz161490 #define	SD_VPD_EXTENDED_DATA_PG	0x80	/* 0x86 - Extended data about the lun */
237710320SLarry.Liu@Sun.COM #define	SD_VPD_DEV_CHARACTER_PG	0x400	/* 0xB1 - Device Characteristics */
23785065Sgz161490 
23795065Sgz161490 /*
23805065Sgz161490  * Non-volatile cache support
23815065Sgz161490  *
23825065Sgz161490  * Bit 1 of the byte 6 in the Extended INQUIRY data VPD page
23835065Sgz161490  * is NV_SUP bit: An NV_SUP bit set to one indicates that
23845065Sgz161490  * the device server supports a non-volatile cache.  An
23855065Sgz161490  * NV_SUP bit set to zero indicates that the device
23865065Sgz161490  * server may or may not support a non-volatile cache.
23875065Sgz161490  *
23885065Sgz161490  * Bit 2 of the byte 1 in the SYNC CACHE command is SYNC_NV
23895065Sgz161490  * bit: The SYNC_NV bit specifies whether the device server
23905065Sgz161490  * is required to synchronize volatile and non-volatile
23915065Sgz161490  * caches.
23925065Sgz161490  */
23935065Sgz161490 #define	SD_VPD_NV_SUP	0x02
23945065Sgz161490 #define	SD_SYNC_NV_BIT 0x04
23950Sstevel@tonic-gate 
23960Sstevel@tonic-gate /*
23970Sstevel@tonic-gate  * Addition from sddef.intel.h
23980Sstevel@tonic-gate  */
23990Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
24000Sstevel@tonic-gate 
24010Sstevel@tonic-gate #define	P0_RAW_DISK	(NDKMAP)
24020Sstevel@tonic-gate #define	FDISK_P1	(NDKMAP+1)
24030Sstevel@tonic-gate #define	FDISK_P2	(NDKMAP+2)
24040Sstevel@tonic-gate #define	FDISK_P3	(NDKMAP+3)
24050Sstevel@tonic-gate #define	FDISK_P4	(NDKMAP+4)
24060Sstevel@tonic-gate 
24070Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
24080Sstevel@tonic-gate 
24090Sstevel@tonic-gate #ifdef	__cplusplus
24100Sstevel@tonic-gate }
24110Sstevel@tonic-gate #endif
24120Sstevel@tonic-gate 
24130Sstevel@tonic-gate 
24140Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_SDDEF_H */
2415