xref: /titanic_52/usr/src/uts/common/sys/scsi/targets/sddef.h (revision f0426ccceb59cf1dfbb2b1ec53d11dee536f423c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5bef6b7d2Swebaker  * Common Development and Distribution License (the "License").
6bef6b7d2Swebaker  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22f13665b7Sbo zhou - Sun Microsystems - Beijing China  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
2411472db1Sgalibern cyril /*
2511472db1Sgalibern cyril  * Copyright 2011 cyril.galibern@opensvc.com
26*35d37d44SJeffry Molanus  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
2711472db1Sgalibern cyril  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_SCSI_TARGETS_SDDEF_H
307c478bd9Sstevel@tonic-gate #define	_SYS_SCSI_TARGETS_SDDEF_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
337c478bd9Sstevel@tonic-gate #include <sys/note.h>
347c478bd9Sstevel@tonic-gate #include <sys/mhd.h>
35e8fb11a1Sshidokht #include <sys/cmlb.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	SD_SUCCESS		0
467c478bd9Sstevel@tonic-gate #define	SD_FAILURE		(-1)
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #if defined(TRUE)
497c478bd9Sstevel@tonic-gate #undef TRUE
507c478bd9Sstevel@tonic-gate #endif
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #if defined(FALSE)
537c478bd9Sstevel@tonic-gate #undef FALSE
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	TRUE			1
577c478bd9Sstevel@tonic-gate #define	FALSE			0
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #if defined(VERBOSE)
607c478bd9Sstevel@tonic-gate #undef VERBOSE
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #if defined(SILENT)
647c478bd9Sstevel@tonic-gate #undef SILENT
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  *  Fault Injection Flag for Inclusion of Code
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  *  This should only be defined when SDDEBUG is defined
727c478bd9Sstevel@tonic-gate  * #if DEBUG || lint
737c478bd9Sstevel@tonic-gate  * #define	SD_FAULT_INJECTION
747c478bd9Sstevel@tonic-gate  * #endif
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate 
779e1c849eSDavid Zhang - Sun Microsystems - Beijing China #if DEBUG || lint
789e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define	SD_FAULT_INJECTION
799e1c849eSDavid Zhang - Sun Microsystems - Beijing China #endif
807c478bd9Sstevel@tonic-gate #define	VERBOSE			1
817c478bd9Sstevel@tonic-gate #define	SILENT			0
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * Structures for recording whether a device is fully open or closed.
857c478bd9Sstevel@tonic-gate  * Assumptions:
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  *	+ There are only 8 (sparc) or 16 (x86) disk slices possible.
887c478bd9Sstevel@tonic-gate  *	+ BLK, MNT, CHR, SWP don't change in some future release!
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #define	SDUNIT_SHIFT	3
947c478bd9Sstevel@tonic-gate #define	SDPART_MASK	7
957c478bd9Sstevel@tonic-gate #define	NSDMAP		NDKMAP
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
987c478bd9Sstevel@tonic-gate 
99aa1b14e7SSheshadri Vasudevan /*
100aa1b14e7SSheshadri Vasudevan  * XXX - NSDMAP has multiple definitions, one more in cmlb_impl.h
101aa1b14e7SSheshadri Vasudevan  * If they are coalesced into one, this definition will follow suit.
102aa1b14e7SSheshadri Vasudevan  * FDISK partitions - 4 primary and MAX_EXT_PARTS number of Extended
103aa1b14e7SSheshadri Vasudevan  * Partitions.
104aa1b14e7SSheshadri Vasudevan  */
105aa1b14e7SSheshadri Vasudevan #define	FDISK_PARTS		(FD_NUMPART + MAX_EXT_PARTS)
106aa1b14e7SSheshadri Vasudevan 
1077c478bd9Sstevel@tonic-gate #define	SDUNIT_SHIFT	6
1087c478bd9Sstevel@tonic-gate #define	SDPART_MASK	63
109aa1b14e7SSheshadri Vasudevan #define	NSDMAP		(NDKMAP + FDISK_PARTS + 1)
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #else
1127c478bd9Sstevel@tonic-gate #error "No VTOC format defined."
1137c478bd9Sstevel@tonic-gate #endif
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	SDUNIT(dev)	(getminor((dev)) >> SDUNIT_SHIFT)
1177c478bd9Sstevel@tonic-gate #define	SDPART(dev)	(getminor((dev)) &  SDPART_MASK)
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * maximum number of partitions the driver keeps track of; with
1217c478bd9Sstevel@tonic-gate  * EFI this can be larger than the number of partitions accessible
1227c478bd9Sstevel@tonic-gate  * through the minor nodes.  It won't be used for keeping track
1237c478bd9Sstevel@tonic-gate  * of open counts, partition kstats, etc.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	MAXPART		(NSDMAP + 1)
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate  * Macro to retrieve the DDI instance number from the given buf struct.
1297c478bd9Sstevel@tonic-gate  * The instance number is encoded in the minor device number.
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate #define	SD_GET_INSTANCE_FROM_BUF(bp)				\
1327c478bd9Sstevel@tonic-gate 	(getminor((bp)->b_edev) >> SDUNIT_SHIFT)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate struct ocinfo {
1377c478bd9Sstevel@tonic-gate 	/*
1387c478bd9Sstevel@tonic-gate 	 * Types BLK, MNT, CHR, SWP,
1397c478bd9Sstevel@tonic-gate 	 * assumed to be types 0-3.
1407c478bd9Sstevel@tonic-gate 	 */
1413d6ab94aSgz161490 	uint64_t  lyr_open[NSDMAP];
1423d6ab94aSgz161490 	uint64_t  reg_open[OTYPCNT - 1];
1437c478bd9Sstevel@tonic-gate };
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #define	OCSIZE  sizeof (struct ocinfo)
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate union ocmap {
1487c478bd9Sstevel@tonic-gate 	uchar_t chkd[OCSIZE];
1497c478bd9Sstevel@tonic-gate 	struct ocinfo rinfo;
1507c478bd9Sstevel@tonic-gate };
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #define	lyropen rinfo.lyr_open
1537c478bd9Sstevel@tonic-gate #define	regopen rinfo.reg_open
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #define	SD_CDB_GROUP0		0
1577c478bd9Sstevel@tonic-gate #define	SD_CDB_GROUP1		1
1587c478bd9Sstevel@tonic-gate #define	SD_CDB_GROUP5		2
1597c478bd9Sstevel@tonic-gate #define	SD_CDB_GROUP4		3
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate struct sd_cdbinfo {
1627c478bd9Sstevel@tonic-gate 	uchar_t	 sc_grpcode;	/* CDB group code */
1637c478bd9Sstevel@tonic-gate 	uchar_t  sc_grpmask;	/* CDB group code mask (for cmd opcode) */
1647c478bd9Sstevel@tonic-gate 	uint64_t sc_maxlba;	/* Maximum logical block addr. supported */
1657c478bd9Sstevel@tonic-gate 	uint32_t sc_maxlen;	/* Maximum transfer length supported */
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * The following declaration are for Non-512 byte block support for the
1727c478bd9Sstevel@tonic-gate  * removable devices. (ex - DVD RAM, MO).
1737c478bd9Sstevel@tonic-gate  * wm_state: This is an enumeration for the different states for
1747c478bd9Sstevel@tonic-gate  * manipalating write range list during the read-modify-write-operation.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate typedef enum {
1777c478bd9Sstevel@tonic-gate 	SD_WM_CHK_LIST,		/* Check list for overlapping writes */
1787c478bd9Sstevel@tonic-gate 	SD_WM_WAIT_MAP,		/* Wait for an overlapping I/O to complete */
1797c478bd9Sstevel@tonic-gate 	SD_WM_LOCK_RANGE,	/* Lock the range of lba to be written */
1807c478bd9Sstevel@tonic-gate 	SD_WM_DONE		/* I/O complete */
1817c478bd9Sstevel@tonic-gate } wm_state;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate  * sd_w_map: Every write I/O will get one w_map allocated for it which will tell
1857c478bd9Sstevel@tonic-gate  * the range on the media which is being written for that request.
1867c478bd9Sstevel@tonic-gate  */
1877c478bd9Sstevel@tonic-gate struct sd_w_map {
1887c478bd9Sstevel@tonic-gate 	uint_t		wm_start;	/* Write start location */
1897c478bd9Sstevel@tonic-gate 	uint_t		wm_end;		/* Write end location */
1907c478bd9Sstevel@tonic-gate 	ushort_t	wm_flags;	/* State of the wmap */
1917c478bd9Sstevel@tonic-gate 	ushort_t	wm_wanted_count; /* # of threads waiting for region */
1927c478bd9Sstevel@tonic-gate 	void		*wm_private;	/* Used to store bp->b_private */
1937c478bd9Sstevel@tonic-gate 	struct buf	*wm_bufp;	/* to store buf pointer */
1947c478bd9Sstevel@tonic-gate 	struct sd_w_map	*wm_next;	/* Forward pointed to sd_w_map */
1957c478bd9Sstevel@tonic-gate 	struct sd_w_map	*wm_prev;	/* Back pointer to sd_w_map */
1967c478bd9Sstevel@tonic-gate 	kcondvar_t	wm_avail;	/* Sleep on this, while not available */
1977c478bd9Sstevel@tonic-gate };
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_w_map::wm_flags))
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * This is the struct for the layer-private data area for the
2047c478bd9Sstevel@tonic-gate  * mapblocksize layer.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate struct sd_mapblocksize_info {
2087c478bd9Sstevel@tonic-gate 	void		*mbs_oprivate;	/* saved value of xb_private */
2097c478bd9Sstevel@tonic-gate 	struct buf	*mbs_orig_bp;	/* ptr to original bp */
2107c478bd9Sstevel@tonic-gate 	struct sd_w_map	*mbs_wmp;	/* ptr to write-map struct for RMW */
2117c478bd9Sstevel@tonic-gate 	ssize_t		mbs_copy_offset;
2127c478bd9Sstevel@tonic-gate 	int		mbs_layer_index;	/* chain index for RMW */
2137c478bd9Sstevel@tonic-gate };
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_mapblocksize_info))
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * sd_lun: The main data structure for a scsi logical unit.
2207c478bd9Sstevel@tonic-gate  * Stored as the softstate structure for each device.
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate struct sd_lun {
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	/* Back ptr to the SCSA scsi_device struct for this LUN */
2267c478bd9Sstevel@tonic-gate 	struct scsi_device	*un_sd;
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * Support for Auto-Request sense capability
2307c478bd9Sstevel@tonic-gate 	 */
2317c478bd9Sstevel@tonic-gate 	struct buf	*un_rqs_bp;	/* ptr to request sense bp */
2327c478bd9Sstevel@tonic-gate 	struct scsi_pkt	*un_rqs_pktp;	/* ptr to request sense scsi_pkt */
2337c478bd9Sstevel@tonic-gate 	int	un_sense_isbusy;	/* Busy flag for RQS buf */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * These specify the layering chains to use with this instance. These
2377c478bd9Sstevel@tonic-gate 	 * are initialized according to the values in the sd_chain_index_map[]
2387c478bd9Sstevel@tonic-gate 	 * array. See the description of sd_chain_index_map[] for details.
2397c478bd9Sstevel@tonic-gate 	 */
2407c478bd9Sstevel@tonic-gate 	int un_buf_chain_type;
2417c478bd9Sstevel@tonic-gate 	int un_uscsi_chain_type;
2427c478bd9Sstevel@tonic-gate 	int un_direct_chain_type;
2437c478bd9Sstevel@tonic-gate 	int un_priority_chain_type;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	/* Head & tail ptrs to the queue of bufs awaiting transport */
2467c478bd9Sstevel@tonic-gate 	struct buf	*un_waitq_headp;
2477c478bd9Sstevel@tonic-gate 	struct buf	*un_waitq_tailp;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	/* Ptr to the buf currently being retried (NULL if none) */
2507c478bd9Sstevel@tonic-gate 	struct buf	*un_retry_bp;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	/* This tracks the last kstat update for the un_retry_bp buf */
2537c478bd9Sstevel@tonic-gate 	void		(*un_retry_statp)(kstat_io_t *);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	void		*un_xbuf_attr;	/* xbuf attribute struct */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	/* System logical block size, in bytes. (defaults to DEV_BSIZE.) */
2597c478bd9Sstevel@tonic-gate 	uint32_t	un_sys_blocksize;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/* The size of a logical block on the target, in bytes. */
2627c478bd9Sstevel@tonic-gate 	uint32_t	un_tgt_blocksize;
2637c478bd9Sstevel@tonic-gate 
264f13665b7Sbo zhou - Sun Microsystems - Beijing China 	/* The size of a physical block on the target, in bytes. */
265f13665b7Sbo zhou - Sun Microsystems - Beijing China 	uint32_t	un_phy_blocksize;
266f13665b7Sbo zhou - Sun Microsystems - Beijing China 
2677c478bd9Sstevel@tonic-gate 	/*
2687c478bd9Sstevel@tonic-gate 	 * The number of logical blocks on the target. This is adjusted
2697c478bd9Sstevel@tonic-gate 	 * to be in terms of the block size specified by un_sys_blocksize
2707c478bd9Sstevel@tonic-gate 	 * (ie, the system block size).
2717c478bd9Sstevel@tonic-gate 	 */
2727c478bd9Sstevel@tonic-gate 	uint64_t	un_blockcount;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	/*
2757c478bd9Sstevel@tonic-gate 	 * Various configuration data
2767c478bd9Sstevel@tonic-gate 	 */
2777c478bd9Sstevel@tonic-gate 	uchar_t	un_ctype;		/* Controller type */
2787c478bd9Sstevel@tonic-gate 	char 	*un_node_type;		/* minor node type */
2797c478bd9Sstevel@tonic-gate 	uchar_t	un_interconnect_type;	/* Interconnect for underlying HBA */
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	uint_t	un_notready_retry_count; /* Per disk notready retry count */
2827c478bd9Sstevel@tonic-gate 	uint_t	un_busy_retry_count;	/* Per disk BUSY retry count */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	uint_t	un_retry_count;		/* Per disk retry count */
2857c478bd9Sstevel@tonic-gate 	uint_t	un_victim_retry_count;	/* Per disk victim retry count */
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/* (4356701, 4367306) */
2887c478bd9Sstevel@tonic-gate 	uint_t	un_reset_retry_count; /* max io retries before issuing reset */
2897c478bd9Sstevel@tonic-gate 	ushort_t un_reserve_release_time; /* reservation release timeout */
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	uchar_t	un_reservation_type;	/* SCSI-3 or SCSI-2 */
2927c478bd9Sstevel@tonic-gate 	uint_t	un_max_xfer_size;	/* Maximum DMA transfer size */
293611e78b1Slh195018 	int	un_partial_dma_supported;
29472888e72Speng liu - Sun Microsystems - Beijing China 	int	un_buf_breakup_supported;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	int	un_mincdb;		/* Smallest CDB to use */
2977c478bd9Sstevel@tonic-gate 	int	un_maxcdb;		/* Largest CDB to use */
2982439af76Slh195018 	int	un_max_hba_cdb;		/* Largest CDB supported by HBA */
2997c478bd9Sstevel@tonic-gate 	int	un_status_len;
3007c478bd9Sstevel@tonic-gate 	int	un_pkt_flags;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/*
3037c478bd9Sstevel@tonic-gate 	 * Note: un_uscsi_timeout is a "mirror" of un_cmd_timeout, adjusted
3047c478bd9Sstevel@tonic-gate 	 * for ISCD().  Any updates to un_cmd_timeout MUST be reflected
3057c478bd9Sstevel@tonic-gate 	 * in un_uscsi_timeout as well!
3067c478bd9Sstevel@tonic-gate 	 */
3077c478bd9Sstevel@tonic-gate 	ushort_t un_cmd_timeout;	/* Timeout for completion */
3087c478bd9Sstevel@tonic-gate 	ushort_t un_uscsi_timeout;	/* Timeout for USCSI completion */
309b7c7b08dSNikko He 	ushort_t un_busy_timeout;	/* Timeout for busy retry */
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	/*
3127c478bd9Sstevel@tonic-gate 	 * Info on current states, statuses, etc. (Updated frequently)
3137c478bd9Sstevel@tonic-gate 	 */
3147c478bd9Sstevel@tonic-gate 	uchar_t	un_state;		/* current state */
3157c478bd9Sstevel@tonic-gate 	uchar_t	un_last_state;		/* last state */
3167c478bd9Sstevel@tonic-gate 	uchar_t	un_last_pkt_reason;	/* used to suppress multiple msgs */
3177c478bd9Sstevel@tonic-gate 	int	un_tagflags;		/* Pkt Flags for Tagged Queueing  */
3187c478bd9Sstevel@tonic-gate 	short	un_resvd_status;	/* Reservation Status */
3197c478bd9Sstevel@tonic-gate 	ulong_t	un_detach_count;	/* !0 if executing detach routine */
3207c478bd9Sstevel@tonic-gate 	ulong_t	un_layer_count;		/* Current total # of layered opens */
3217c478bd9Sstevel@tonic-gate 	ulong_t un_opens_in_progress;	/* Current # of threads in sdopen */
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	ksema_t	un_semoclose;		/* serialize opens/closes */
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	/*
3267c478bd9Sstevel@tonic-gate 	 * Control & status info for command throttling
3277c478bd9Sstevel@tonic-gate 	 */
3287c478bd9Sstevel@tonic-gate 	long	un_ncmds_in_driver;	/* number of cmds in driver */
3297c478bd9Sstevel@tonic-gate 	short	un_ncmds_in_transport;	/* number of cmds in transport */
3307c478bd9Sstevel@tonic-gate 	short	un_throttle;		/* max #cmds allowed in transport */
3317c478bd9Sstevel@tonic-gate 	short	un_saved_throttle;	/* saved value of un_throttle */
3327c478bd9Sstevel@tonic-gate 	short	un_busy_throttle;	/* saved un_throttle for BUSY */
3337c478bd9Sstevel@tonic-gate 	short	un_min_throttle;	/* min value of un_throttle */
3347c478bd9Sstevel@tonic-gate 	timeout_id_t	un_reset_throttle_timeid; /* timeout(9F) handle */
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	/*
3377c478bd9Sstevel@tonic-gate 	 * Multi-host (clustering) support
3387c478bd9Sstevel@tonic-gate 	 */
3397c478bd9Sstevel@tonic-gate 	opaque_t	un_mhd_token;		/* scsi watch request */
3407c478bd9Sstevel@tonic-gate 	timeout_id_t	un_resvd_timeid;	/* for resvd recover */
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	/* Event callback resources (photon) */
3437c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t un_insert_event;	/* insert event */
3447c478bd9Sstevel@tonic-gate 	ddi_callback_id_t un_insert_cb_id;	/* insert callback */
3457c478bd9Sstevel@tonic-gate 	ddi_eventcookie_t un_remove_event;	/* remove event */
3467c478bd9Sstevel@tonic-gate 	ddi_callback_id_t un_remove_cb_id;	/* remove callback */
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	uint_t		un_start_stop_cycle_page;	/* Saves start/stop */
3497c478bd9Sstevel@tonic-gate 							/* cycle page */
3507c478bd9Sstevel@tonic-gate 	timeout_id_t	un_dcvb_timeid;		/* dlyd cv broadcast */
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	/*
3537c478bd9Sstevel@tonic-gate 	 * Data structures for open counts, partition info, VTOC,
3547c478bd9Sstevel@tonic-gate 	 * stats, and other such bookkeeping info.
3557c478bd9Sstevel@tonic-gate 	 */
3567c478bd9Sstevel@tonic-gate 	union	ocmap	un_ocmap;		/* open partition map */
3577c478bd9Sstevel@tonic-gate 	struct	kstat	*un_pstats[NSDMAP];	/* partition statistics */
3587c478bd9Sstevel@tonic-gate 	struct	kstat	*un_stats;		/* disk statistics */
3597c478bd9Sstevel@tonic-gate 	kstat_t		*un_errstats;		/* for error statistics */
3603d6ab94aSgz161490 	uint64_t	un_exclopen;		/* exclusive open bitmask */
3617c478bd9Sstevel@tonic-gate 	ddi_devid_t	un_devid;		/* device id */
3627c478bd9Sstevel@tonic-gate 	uint_t		un_vpd_page_mask;	/* Supported VPD pages */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	/*
3657c478bd9Sstevel@tonic-gate 	 * Bit fields for various configuration/state/status info.
3667c478bd9Sstevel@tonic-gate 	 * Comments indicate the condition if the value of the
36730a83a24Scth 	 * variable is TRUE (nonzero).
3687c478bd9Sstevel@tonic-gate 	 */
3697c478bd9Sstevel@tonic-gate 	uint32_t
3707c478bd9Sstevel@tonic-gate 	    un_f_arq_enabled		:1,	/* Auto request sense is */
3717c478bd9Sstevel@tonic-gate 						/* currently enabled */
3727c478bd9Sstevel@tonic-gate 	    un_f_blockcount_is_valid	:1,	/* The un_blockcount */
3737c478bd9Sstevel@tonic-gate 						/* value is currently valid */
3747c478bd9Sstevel@tonic-gate 	    un_f_tgt_blocksize_is_valid	:1,	/* The un_tgt_blocksize */
3757c478bd9Sstevel@tonic-gate 						/* value is currently valid */
3767c478bd9Sstevel@tonic-gate 	    un_f_allow_bus_device_reset	:1,	/* Driver may issue a BDR as */
3777c478bd9Sstevel@tonic-gate 						/* a part of error recovery. */
3787c478bd9Sstevel@tonic-gate 	    un_f_is_fibre		:1,	/* The device supports fibre */
3797c478bd9Sstevel@tonic-gate 						/* channel */
3800167b58cScg149915 	    un_f_sync_cache_supported	:1,	/* sync cache cmd supported */
381fa9e4066Sahrens 						/* supported */
3827c478bd9Sstevel@tonic-gate 	    un_f_format_in_progress	:1,	/* The device is currently */
3837c478bd9Sstevel@tonic-gate 						/* executing a FORMAT cmd. */
3847c478bd9Sstevel@tonic-gate 	    un_f_opt_queueing		:1,	/* Enable Command Queuing to */
3857c478bd9Sstevel@tonic-gate 						/* Host Adapter */
3867c478bd9Sstevel@tonic-gate 	    un_f_opt_fab_devid		:1,	/* Disk has no valid/unique */
3877c478bd9Sstevel@tonic-gate 						/* serial number.  */
3887c478bd9Sstevel@tonic-gate 	    un_f_opt_disable_cache	:1,	/* Read/Write disk cache is */
3897c478bd9Sstevel@tonic-gate 						/* disabled.  */
3907c478bd9Sstevel@tonic-gate 	    un_f_cfg_is_atapi		:1,	/* This is an ATAPI device.  */
391fa9e4066Sahrens 	    un_f_write_cache_enabled	:1,	/* device return success on */
392fa9e4066Sahrens 						/* writes before transfer to */
393fa9e4066Sahrens 						/* physical media complete */
3947c478bd9Sstevel@tonic-gate 	    un_f_cfg_playmsf_bcd	:1,	/* Play Audio, BCD params. */
3957c478bd9Sstevel@tonic-gate 	    un_f_cfg_readsub_bcd	:1,	/* READ SUBCHANNEL BCD resp. */
3967c478bd9Sstevel@tonic-gate 	    un_f_cfg_read_toc_trk_bcd	:1,	/* track # is BCD */
3977c478bd9Sstevel@tonic-gate 	    un_f_cfg_read_toc_addr_bcd	:1,	/* address is BCD */
3987c478bd9Sstevel@tonic-gate 	    un_f_cfg_no_read_header	:1,	/* READ HEADER not supported */
3997c478bd9Sstevel@tonic-gate 	    un_f_cfg_read_cd_xd4	:1,	/* READ CD opcode is 0xd4 */
4007c478bd9Sstevel@tonic-gate 	    un_f_mmc_cap		:1,	/* Device is MMC compliant */
4017c478bd9Sstevel@tonic-gate 	    un_f_mmc_writable_media	:1,	/* writable media in device */
4027c478bd9Sstevel@tonic-gate 	    un_f_dvdram_writable_device	:1,	/* DVDRAM device is writable */
4037c478bd9Sstevel@tonic-gate 	    un_f_cfg_cdda		:1,	/* READ CDDA supported */
4047c478bd9Sstevel@tonic-gate 	    un_f_cfg_tur_check		:1,	/* verify un_ncmds before tur */
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	    un_f_use_adaptive_throttle	:1,	/* enable/disable adaptive */
4077c478bd9Sstevel@tonic-gate 						/* throttling */
4087c478bd9Sstevel@tonic-gate 	    un_f_pm_is_enabled		:1,	/* PM is enabled on this */
4097c478bd9Sstevel@tonic-gate 						/* instance */
4107c478bd9Sstevel@tonic-gate 	    un_f_watcht_stopped		:1,	/* media watch thread flag */
4117c478bd9Sstevel@tonic-gate 	    un_f_pkstats_enabled	:1,	/* Flag to determine if */
4127c478bd9Sstevel@tonic-gate 						/* partition kstats are */
4137c478bd9Sstevel@tonic-gate 						/* enabled. */
4147c478bd9Sstevel@tonic-gate 	    un_f_disksort_disabled	:1,	/* Flag to disable disksort */
4157c478bd9Sstevel@tonic-gate 	    un_f_lun_reset_enabled	:1,	/* Set if target supports */
4167c478bd9Sstevel@tonic-gate 						/* SCSI Logical Unit Reset */
4177c478bd9Sstevel@tonic-gate 	    un_f_doorlock_supported	:1,	/* Device supports Doorlock */
418e8fb11a1Sshidokht 	    un_f_start_stop_supported	:1,	/* device has motor */
419e8fb11a1Sshidokht 	    un_f_reserved1		:1;
4207c478bd9Sstevel@tonic-gate 
4210167b58cScg149915 	uint32_t
4220167b58cScg149915 	    un_f_mboot_supported	:1,	/* mboot supported */
4230167b58cScg149915 	    un_f_is_hotpluggable	:1,	/* hotpluggable */
4240167b58cScg149915 	    un_f_has_removable_media	:1,	/* has removable media */
4250167b58cScg149915 	    un_f_non_devbsize_supported	:1,	/* non-512 blocksize */
4260167b58cScg149915 	    un_f_devid_supported	:1,	/* device ID supported */
4270167b58cScg149915 	    un_f_eject_media_supported	:1,	/* media can be ejected */
4280167b58cScg149915 	    un_f_chk_wp_open		:1,	/* check if write-protected */
4290167b58cScg149915 						/* when being opened */
4300167b58cScg149915 	    un_f_descr_format_supported	:1,	/* support descriptor format */
4310167b58cScg149915 						/* for sense data */
4320167b58cScg149915 	    un_f_check_start_stop	:1,	/* needs to check if */
4330167b58cScg149915 						/* START-STOP command is */
4340167b58cScg149915 						/* supported by hardware */
4350167b58cScg149915 						/* before issuing it */
4360167b58cScg149915 	    un_f_monitor_media_state	:1,	/* need a watch thread to */
4370167b58cScg149915 						/* monitor device state */
4380167b58cScg149915 	    un_f_attach_spinup		:1,	/* spin up once the */
4390167b58cScg149915 						/* device is attached */
4400167b58cScg149915 	    un_f_log_sense_supported	:1,	/* support log sense */
4410167b58cScg149915 	    un_f_pm_supported		:1, 	/* support power-management */
442bef6b7d2Swebaker 	    un_f_cfg_is_lsi		:1,	/* Is LSI device, */
443bef6b7d2Swebaker 						/* default to NO */
444bef6b7d2Swebaker 	    un_f_wcc_inprog		:1,	/* write cache change in */
445bef6b7d2Swebaker 						/* progress */
446f1d732ecSzk194757 	    un_f_ejecting		:1,	/* media is ejecting */
447a84224b3Sgz161490 	    un_f_suppress_cache_flush	:1,	/* supress flush on */
448a84224b3Sgz161490 						/* write cache */
449a84224b3Sgz161490 	    un_f_sync_nv_supported	:1,	/* SYNC_NV */
450a84224b3Sgz161490 						/* bit is supported */
4519e42605dSSheshadri Vasudevan 	    un_f_sync_cache_required	:1,	/* flag to check if */
4529e42605dSSheshadri Vasudevan 						/* SYNC CACHE needs to be */
4539e42605dSSheshadri Vasudevan 						/* sent in sdclose */
454470452aaSPrasad Singamsetty 	    un_f_devid_transport_defined :1,	/* devid defined by transport */
45565908c77Syu, larry liu - Sun Microsystems - Beijing China 	    un_f_rmw_type		 :2,	/* RMW type */
4562ee4dfc7SJane Chu 	    un_f_power_condition_disabled :1,	/* power condition disabled */
4572ee4dfc7SJane Chu 						/* through sd configuration */
4582ee4dfc7SJane Chu 	    un_f_power_condition_supported :1,	/* support power condition */
4592ee4dfc7SJane Chu 						/* field by hardware */
4602ee4dfc7SJane Chu 	    un_f_pm_log_sense_smart	:1,	/* log sense support SMART */
4612ee4dfc7SJane Chu 						/* feature attribute */
462b081f1c4Syu, larry liu - Sun Microsystems - Beijing China 	    un_f_is_solid_state		:1,	/* has solid state media */
463b2b61b8fSYuri Pankov 	    un_f_is_rotational		:1,	/* spinning rust */
46497ddcdceSArtem Kachitchkine 	    un_f_mmc_gesn_polling	:1,	/* use GET EVENT STATUS */
46597ddcdceSArtem Kachitchkine 						/* NOTIFICATION for polling */
466f13665b7Sbo zhou - Sun Microsystems - Beijing China 	    un_f_enable_rmw		:1,	/* Force RMW in sd driver */
467b98131cfSEric Taylor 	    un_f_expnevent		:1,
468*35d37d44SJeffry Molanus 	    un_f_cache_mode_changeable	:1,	/* can change cache mode */
469*35d37d44SJeffry Molanus 	    un_f_reserved		:1;
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	/* Ptr to table of strings for ASC/ASCQ error message printing */
4727c478bd9Sstevel@tonic-gate 	struct scsi_asq_key_strings	*un_additional_codes;
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	/*
4757c478bd9Sstevel@tonic-gate 	 * Power Management support.
4767c478bd9Sstevel@tonic-gate 	 *
4777c478bd9Sstevel@tonic-gate 	 * un_pm_mutex protects, un_pm_count, un_pm_timeid, un_pm_busy,
4787c478bd9Sstevel@tonic-gate 	 * un_pm_busy_cv, and un_pm_idle_timeid.
4797c478bd9Sstevel@tonic-gate 	 * It's not required that SD_MUTEX be acquired before acquiring
4807c478bd9Sstevel@tonic-gate 	 * un_pm_mutex, however if they must both be held
4817c478bd9Sstevel@tonic-gate 	 * then acquire SD_MUTEX first.
4827c478bd9Sstevel@tonic-gate 	 *
4837c478bd9Sstevel@tonic-gate 	 * un_pm_count is used to indicate PM state as follows:
4847c478bd9Sstevel@tonic-gate 	 *	less than 0 the device is powered down,
4857c478bd9Sstevel@tonic-gate 	 *	transition from 0 ==> 1, mark the device as busy via DDI
4867c478bd9Sstevel@tonic-gate 	 *	transition from 1 ==> 0, mark the device as idle via DDI
4877c478bd9Sstevel@tonic-gate 	 */
4887c478bd9Sstevel@tonic-gate 	kmutex_t	un_pm_mutex;
4897c478bd9Sstevel@tonic-gate 	int		un_pm_count;		/* indicates pm state */
4907c478bd9Sstevel@tonic-gate 	timeout_id_t	un_pm_timeid;		/* timeout id for pm */
4917c478bd9Sstevel@tonic-gate 	uint_t		un_pm_busy;
4927c478bd9Sstevel@tonic-gate 	kcondvar_t	un_pm_busy_cv;
4937c478bd9Sstevel@tonic-gate 	short		un_power_level;		/* Power Level */
4947c478bd9Sstevel@tonic-gate 	uchar_t		un_save_state;
4957c478bd9Sstevel@tonic-gate 	kcondvar_t	un_suspend_cv;		/* power management */
4967c478bd9Sstevel@tonic-gate 	kcondvar_t	un_disk_busy_cv;	/* wait for IO completion */
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 	/* Resources used for media change callback support */
4997c478bd9Sstevel@tonic-gate 	kcondvar_t	un_state_cv;		/* Cond Var on mediastate */
5007c478bd9Sstevel@tonic-gate 	enum dkio_state un_mediastate;		/* current media state */
5017c478bd9Sstevel@tonic-gate 	enum dkio_state un_specified_mediastate; /* expected state */
5027c478bd9Sstevel@tonic-gate 	opaque_t	un_swr_token;		/* scsi_watch request token */
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	/* Non-512 byte block support */
5057c478bd9Sstevel@tonic-gate 	struct kmem_cache *un_wm_cache;	/* fast alloc in non-512 write case */
5067c478bd9Sstevel@tonic-gate 	uint_t		un_rmw_count;	/* count of read-modify-writes */
5077c478bd9Sstevel@tonic-gate 	struct sd_w_map	*un_wm;		/* head of sd_w_map chain */
50865908c77Syu, larry liu - Sun Microsystems - Beijing China 	uint64_t	un_rmw_incre_count;	/* count I/O */
50965908c77Syu, larry liu - Sun Microsystems - Beijing China 	timeout_id_t	un_rmw_msg_timeid;	/* for RMW message control */
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate 	/* For timeout callback to issue a START STOP UNIT command */
5127c478bd9Sstevel@tonic-gate 	timeout_id_t	un_startstop_timeid;
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	/* Timeout callback handle for SD_PATH_DIRECT_PRIORITY cmd restarts */
5157c478bd9Sstevel@tonic-gate 	timeout_id_t	un_direct_priority_timeid;
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	/* TRAN_FATAL_ERROR count. Cleared by TRAN_ACCEPT from scsi_transport */
5187c478bd9Sstevel@tonic-gate 	ulong_t		un_tran_fatal_count;
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	timeout_id_t	un_retry_timeid;
5217c478bd9Sstevel@tonic-gate 
5227c64340fSJosef 'Jeff' Sipek 	hrtime_t	un_pm_idle_time;
5237c478bd9Sstevel@tonic-gate 	timeout_id_t	un_pm_idle_timeid;
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	/*
5267c478bd9Sstevel@tonic-gate 	 * Count to determine if a Sonoma controller is in the process of
5277c478bd9Sstevel@tonic-gate 	 * failing over, and how many I/O's are failed with the 05/94/01
5287c478bd9Sstevel@tonic-gate 	 * sense code.
5297c478bd9Sstevel@tonic-gate 	 */
5307c478bd9Sstevel@tonic-gate 	uint_t		un_sonoma_failure_count;
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate 	/*
5337c478bd9Sstevel@tonic-gate 	 * Support for failfast operation.
5347c478bd9Sstevel@tonic-gate 	 */
5357c478bd9Sstevel@tonic-gate 	struct buf	*un_failfast_bp;
5367c478bd9Sstevel@tonic-gate 	struct buf	*un_failfast_headp;
5377c478bd9Sstevel@tonic-gate 	struct buf	*un_failfast_tailp;
5387c478bd9Sstevel@tonic-gate 	uint32_t	un_failfast_state;
5397c478bd9Sstevel@tonic-gate 	/* Callback routine active counter */
5407c478bd9Sstevel@tonic-gate 	short		un_in_callback;
5417c478bd9Sstevel@tonic-gate 
542bef6b7d2Swebaker 	kcondvar_t	un_wcc_cv;	/* synchronize changes to */
543bef6b7d2Swebaker 					/* un_f_write_cache_enabled */
54413ec8d54Sts143224 
5457c478bd9Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
5467c478bd9Sstevel@tonic-gate 	/* SD Fault Injection */
5477c478bd9Sstevel@tonic-gate #define	SD_FI_MAX_BUF 65536
5487c478bd9Sstevel@tonic-gate #define	SD_FI_MAX_ERROR 1024
5497c478bd9Sstevel@tonic-gate 	kmutex_t			un_fi_mutex;
5507c478bd9Sstevel@tonic-gate 	uint_t				sd_fi_buf_len;
5517c478bd9Sstevel@tonic-gate 	char				sd_fi_log[SD_FI_MAX_BUF];
5527c478bd9Sstevel@tonic-gate 	struct sd_fi_pkt	*sd_fi_fifo_pkt[SD_FI_MAX_ERROR];
5537c478bd9Sstevel@tonic-gate 	struct sd_fi_xb		*sd_fi_fifo_xb[SD_FI_MAX_ERROR];
5547c478bd9Sstevel@tonic-gate 	struct sd_fi_un		*sd_fi_fifo_un[SD_FI_MAX_ERROR];
5557c478bd9Sstevel@tonic-gate 	struct sd_fi_arq	*sd_fi_fifo_arq[SD_FI_MAX_ERROR];
5567c478bd9Sstevel@tonic-gate 	uint_t				sd_fi_fifo_start;
5577c478bd9Sstevel@tonic-gate 	uint_t				sd_fi_fifo_end;
5587c478bd9Sstevel@tonic-gate 	uint_t				sd_injection_mask;
559e8fb11a1Sshidokht 
5607c478bd9Sstevel@tonic-gate #endif
5617c478bd9Sstevel@tonic-gate 
562e8fb11a1Sshidokht 	cmlb_handle_t	un_cmlbhandle;
5639e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
5649e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	/*
5659e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	 * Pointer to internal struct sd_fm_internal in which
5669e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	 * will pass necessary information for FMA ereport posting.
5679e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	 */
5689e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	void		*un_fm_private;
5697c478bd9Sstevel@tonic-gate };
5707c478bd9Sstevel@tonic-gate 
571e8fb11a1Sshidokht #define	SD_IS_VALID_LABEL(un)  (cmlb_is_valid(un->un_cmlbhandle))
5727c478bd9Sstevel@tonic-gate 
5737c478bd9Sstevel@tonic-gate /*
5747c478bd9Sstevel@tonic-gate  * Macros for conversions between "target" and "system" block sizes, and
5757c478bd9Sstevel@tonic-gate  * for conversion between block counts and byte counts.  As used here,
5767c478bd9Sstevel@tonic-gate  * "system" block size refers to the block size used by the kernel/
5777c478bd9Sstevel@tonic-gate  * filesystem (this includes the disk label). The "target" block size
57830a83a24Scth  * is the block size returned by the SCSI READ CAPACITY command.
5797c478bd9Sstevel@tonic-gate  *
5807c478bd9Sstevel@tonic-gate  * Note: These macros will round up to the next largest blocksize to accomodate
5817c478bd9Sstevel@tonic-gate  * the number of blocks specified.
5827c478bd9Sstevel@tonic-gate  */
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate /* Convert a byte count to a number of target blocks */
5857c478bd9Sstevel@tonic-gate #define	SD_BYTES2TGTBLOCKS(un, bytecount)				\
5867c478bd9Sstevel@tonic-gate 	((bytecount + (un->un_tgt_blocksize - 1))/un->un_tgt_blocksize)
5877c478bd9Sstevel@tonic-gate 
588f13665b7Sbo zhou - Sun Microsystems - Beijing China /* Convert a byte count to a number of physical blocks */
589f13665b7Sbo zhou - Sun Microsystems - Beijing China #define	SD_BYTES2PHYBLOCKS(un, bytecount)				\
590f13665b7Sbo zhou - Sun Microsystems - Beijing China 	((bytecount + (un->un_phy_blocksize - 1))/un->un_phy_blocksize)
591f13665b7Sbo zhou - Sun Microsystems - Beijing China 
5927c478bd9Sstevel@tonic-gate /* Convert a target block count to a number of bytes */
5937c478bd9Sstevel@tonic-gate #define	SD_TGTBLOCKS2BYTES(un, blockcount)				\
5947c478bd9Sstevel@tonic-gate 	(blockcount * (un)->un_tgt_blocksize)
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate /* Convert a byte count to a number of system blocks */
59765908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_BYTES2SYSBLOCKS(bytecount)				\
59865908c77Syu, larry liu - Sun Microsystems - Beijing China 	((bytecount + (DEV_BSIZE - 1))/DEV_BSIZE)
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /* Convert a system block count to a number of bytes */
60165908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_SYSBLOCKS2BYTES(blockcount)				\
60265908c77Syu, larry liu - Sun Microsystems - Beijing China 	(blockcount * DEV_BSIZE)
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate  * Calculate the number of bytes needed to hold the requested number of bytes
6067c478bd9Sstevel@tonic-gate  * based upon the native target sector/block size
6077c478bd9Sstevel@tonic-gate  */
6087c478bd9Sstevel@tonic-gate #define	SD_REQBYTES2TGTBYTES(un, bytecount)				\
6097c478bd9Sstevel@tonic-gate 	(SD_BYTES2TGTBLOCKS(un, bytecount) * (un)->un_tgt_blocksize)
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate /*
6127c478bd9Sstevel@tonic-gate  * Calculate the byte offset from the beginning of the target block
6137c478bd9Sstevel@tonic-gate  * to the system block location.
6147c478bd9Sstevel@tonic-gate  */
6157c478bd9Sstevel@tonic-gate #define	SD_TGTBYTEOFFSET(un, sysblk, tgtblk)				\
61665908c77Syu, larry liu - Sun Microsystems - Beijing China 	(SD_SYSBLOCKS2BYTES(sysblk) - SD_TGTBLOCKS2BYTES(un, tgtblk))
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate /*
6197c478bd9Sstevel@tonic-gate  * Calculate the target block location from the system block location
6207c478bd9Sstevel@tonic-gate  */
6217c478bd9Sstevel@tonic-gate #define	SD_SYS2TGTBLOCK(un, blockcnt)					\
62265908c77Syu, larry liu - Sun Microsystems - Beijing China 	(blockcnt / ((un)->un_tgt_blocksize / DEV_BSIZE))
62365908c77Syu, larry liu - Sun Microsystems - Beijing China 
62465908c77Syu, larry liu - Sun Microsystems - Beijing China /*
62565908c77Syu, larry liu - Sun Microsystems - Beijing China  * Calculate the target block location from the system block location
62665908c77Syu, larry liu - Sun Microsystems - Beijing China  */
62765908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_TGT2SYSBLOCK(un, blockcnt)					\
62865908c77Syu, larry liu - Sun Microsystems - Beijing China 	(blockcnt * ((un)->un_tgt_blocksize / DEV_BSIZE))
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate /*
6317c478bd9Sstevel@tonic-gate  * SD_DEFAULT_MAX_XFER_SIZE is the default value to bound the max xfer
6327c478bd9Sstevel@tonic-gate  * for physio, for devices without tagged queuing enabled.
6337c478bd9Sstevel@tonic-gate  * The default for devices with tagged queuing enabled is SD_MAX_XFER_SIZE
6347c478bd9Sstevel@tonic-gate  */
6357c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
6367c478bd9Sstevel@tonic-gate #define	SD_DEFAULT_MAX_XFER_SIZE	(256 * 1024)
6377c478bd9Sstevel@tonic-gate #endif
6387c478bd9Sstevel@tonic-gate #define	SD_MAX_XFER_SIZE		(1024 * 1024)
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate /*
6417c478bd9Sstevel@tonic-gate  * Warlock annotations
6427c478bd9Sstevel@tonic-gate  */
6437c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsi_device::sd_mutex, sd_lun))
6447c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(sd_lun::un_sd))
6457c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_reservation_type))
646f5689c9eSbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_mincdb))
647f5689c9eSbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_maxcdb))
648e5243e60Slh195018 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_max_hba_cdb))
649f5689c9eSbg159949 _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_status_len))
6507c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_f_arq_enabled))
6517c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_ctype))
652e8fb11a1Sshidokht _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_cmlbhandle))
653c460faf0SXiao Raymond Li _NOTE(DATA_READABLE_WITHOUT_LOCK(sd_lun::un_fm_private))
654e8fb11a1Sshidokht 
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("safe sharing",
6577c478bd9Sstevel@tonic-gate 	sd_lun::un_mhd_token
6587c478bd9Sstevel@tonic-gate 	sd_lun::un_state
6597c478bd9Sstevel@tonic-gate 	sd_lun::un_tagflags
6607c478bd9Sstevel@tonic-gate 	sd_lun::un_f_format_in_progress
6617c478bd9Sstevel@tonic-gate 	sd_lun::un_resvd_timeid
6627c478bd9Sstevel@tonic-gate 	sd_lun::un_reset_throttle_timeid
6637c478bd9Sstevel@tonic-gate 	sd_lun::un_startstop_timeid
6647c478bd9Sstevel@tonic-gate 	sd_lun::un_dcvb_timeid
6657c478bd9Sstevel@tonic-gate 	sd_lun::un_f_allow_bus_device_reset
6667c478bd9Sstevel@tonic-gate 	sd_lun::un_sys_blocksize
6679e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	sd_lun::un_tgt_blocksize
668d0607dafSbo zhou - Sun Microsystems - Beijing China 	sd_lun::un_phy_blocksize
6699e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	sd_lun::un_additional_codes))
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data",
6727c478bd9Sstevel@tonic-gate 	sd_lun::un_reserve_release_time
6737c478bd9Sstevel@tonic-gate 	sd_lun::un_max_xfer_size
674611e78b1Slh195018 	sd_lun::un_partial_dma_supported
67572888e72Speng liu - Sun Microsystems - Beijing China 	sd_lun::un_buf_breakup_supported
6767c478bd9Sstevel@tonic-gate 	sd_lun::un_f_is_fibre
6777c478bd9Sstevel@tonic-gate 	sd_lun::un_node_type
6787c478bd9Sstevel@tonic-gate 	sd_lun::un_buf_chain_type
6797c478bd9Sstevel@tonic-gate 	sd_lun::un_uscsi_chain_type
6807c478bd9Sstevel@tonic-gate 	sd_lun::un_direct_chain_type
6817c478bd9Sstevel@tonic-gate 	sd_lun::un_priority_chain_type
682d5723702Syl194034 	sd_lun::un_xbuf_attr
683d5723702Syl194034 	sd_lun::un_cmd_timeout
684d5723702Syl194034 	sd_lun::un_pkt_flags))
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data",
6877c478bd9Sstevel@tonic-gate 	block_descriptor
6887c478bd9Sstevel@tonic-gate 	buf
6897c478bd9Sstevel@tonic-gate 	cdrom_subchnl
6907c478bd9Sstevel@tonic-gate 	cdrom_tocentry
6917c478bd9Sstevel@tonic-gate 	cdrom_tochdr
6927c478bd9Sstevel@tonic-gate 	cdrom_read
6937c478bd9Sstevel@tonic-gate 	dk_cinfo
6947c478bd9Sstevel@tonic-gate 	dk_devid
6957c478bd9Sstevel@tonic-gate 	dk_label
6967c478bd9Sstevel@tonic-gate 	dk_map
6977c478bd9Sstevel@tonic-gate 	dk_temperature
6987c478bd9Sstevel@tonic-gate 	mhioc_inkeys
6997c478bd9Sstevel@tonic-gate 	mhioc_inresvs
700f8d8d7b3Scg149915 	mode_caching
7017c478bd9Sstevel@tonic-gate 	mode_header
7027c478bd9Sstevel@tonic-gate 	mode_speed
7037c478bd9Sstevel@tonic-gate 	scsi_cdb
7047c478bd9Sstevel@tonic-gate 	scsi_arq_status
7057c478bd9Sstevel@tonic-gate 	scsi_extended_sense
7067c478bd9Sstevel@tonic-gate 	scsi_inquiry
7077c478bd9Sstevel@tonic-gate 	scsi_pkt
7087c478bd9Sstevel@tonic-gate 	uio
7097c478bd9Sstevel@tonic-gate 	uscsi_cmd))
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsi_device dk_cinfo))
7137c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", scsi_status scsi_cdb))
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_pm_mutex, sd_lun::un_pm_count
7167c478bd9Sstevel@tonic-gate 	sd_lun::un_pm_timeid sd_lun::un_pm_busy sd_lun::un_pm_busy_cv
7177c478bd9Sstevel@tonic-gate 	sd_lun::un_pm_idle_timeid))
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
7207c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_lun::un_fi_mutex,
7217c478bd9Sstevel@tonic-gate 	sd_lun::sd_fi_buf_len sd_lun::sd_fi_log))
7227c478bd9Sstevel@tonic-gate #endif
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate /* _NOTE(LOCK_ORDER(sd_lun::un_sd.sd_mutex sd_lun::un_pm_mutex)) */
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 
7287c478bd9Sstevel@tonic-gate /*
7297c478bd9Sstevel@tonic-gate  * Referenced for frequently-accessed members of the unit structure
7307c478bd9Sstevel@tonic-gate  */
7317c478bd9Sstevel@tonic-gate #define	SD_SCSI_DEVP(un)	((un)->un_sd)
7327c478bd9Sstevel@tonic-gate #define	SD_DEVINFO(un)		((un)->un_sd->sd_dev)
7337c478bd9Sstevel@tonic-gate #define	SD_INQUIRY(un)		((un)->un_sd->sd_inq)
7347c478bd9Sstevel@tonic-gate #define	SD_MUTEX(un)		(&((un)->un_sd->sd_mutex))
7357c478bd9Sstevel@tonic-gate #define	SD_ADDRESS(un)		(&((un)->un_sd->sd_address))
7367c478bd9Sstevel@tonic-gate #define	SD_GET_DEV(un)		(sd_make_device(SD_DEVINFO(un)))
737c460faf0SXiao Raymond Li #define	SD_FM_LOG(un)		(((struct sd_fm_internal *)\
738c460faf0SXiao Raymond Li 				((un)->un_fm_private))->fm_log_level)
7397c478bd9Sstevel@tonic-gate 
7407c478bd9Sstevel@tonic-gate 
7417c478bd9Sstevel@tonic-gate /*
7427c478bd9Sstevel@tonic-gate  * Values for un_ctype
7437c478bd9Sstevel@tonic-gate  */
7447c478bd9Sstevel@tonic-gate #define	CTYPE_CDROM		0
7457c478bd9Sstevel@tonic-gate #define	CTYPE_MD21		1	/* Obsolete! */
7467c478bd9Sstevel@tonic-gate #define	CTYPE_CCS		2
7477c478bd9Sstevel@tonic-gate #define	CTYPE_ROD		3
7487c478bd9Sstevel@tonic-gate #define	CTYPE_PXRE		4	/* Obsolete! */
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate #define	ISCD(un)		((un)->un_ctype == CTYPE_CDROM)
7517c478bd9Sstevel@tonic-gate #define	ISROD(un)		((un)->un_ctype == CTYPE_ROD)
7527c478bd9Sstevel@tonic-gate #define	ISPXRE(un)		((un)->un_ctype == CTYPE_PXRE)
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate /*
7557c478bd9Sstevel@tonic-gate  * This macro checks the vendor of the device to see if it is LSI. Because
7567c478bd9Sstevel@tonic-gate  * LSI has some devices out there that return 'Symbios' or 'SYMBIOS', we
7577c478bd9Sstevel@tonic-gate  * need to check for those also.
7587c478bd9Sstevel@tonic-gate  *
7597c478bd9Sstevel@tonic-gate  * This is used in some vendor specific checks.
7607c478bd9Sstevel@tonic-gate  */
76113ec8d54Sts143224 #define	SD_IS_LSI(un)	((un)->un_f_cfg_is_lsi == TRUE)
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate /*
7647c478bd9Sstevel@tonic-gate  * Macros to check if the lun is a Sun T3 or a T4
7657c478bd9Sstevel@tonic-gate  */
7667c478bd9Sstevel@tonic-gate #define	SD_IS_T3(un) \
7677c478bd9Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7687c478bd9Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T3", 2) == 0))
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate #define	SD_IS_T4(un) \
7717c478bd9Sstevel@tonic-gate 	((bcmp(SD_INQUIRY(un)->inq_vid, "SUN", 3) == 0) && \
7727c478bd9Sstevel@tonic-gate 	(bcmp(SD_INQUIRY(un)->inq_pid, "T4", 2) == 0))
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate /*
7757c478bd9Sstevel@tonic-gate  * Macros for non-512 byte writes to removable devices.
7767c478bd9Sstevel@tonic-gate  */
7777c478bd9Sstevel@tonic-gate #define	NOT_DEVBSIZE(un)	\
7780167b58cScg149915 	((un)->un_tgt_blocksize != (un)->un_sys_blocksize)
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate /*
7817c478bd9Sstevel@tonic-gate  * Check that a write map, used for locking lba ranges for writes, is in
7827c478bd9Sstevel@tonic-gate  * the linked list.
7837c478bd9Sstevel@tonic-gate  */
7847c478bd9Sstevel@tonic-gate #define	ONLIST(un, wmp)		\
7857c478bd9Sstevel@tonic-gate 	(((un)->un_wm == (wmp)) || ((wmp)->wm_prev != NULL))
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate /*
7887c478bd9Sstevel@tonic-gate  * Free a write map which is on list. Basically make sure that nobody is
7897c478bd9Sstevel@tonic-gate  * sleeping on it before freeing it.
7907c478bd9Sstevel@tonic-gate  */
7917c478bd9Sstevel@tonic-gate #define	FREE_ONLIST_WMAP(un, wmp)				\
7927c478bd9Sstevel@tonic-gate 	if (!(wmp)->wm_wanted_count) {				\
7937c478bd9Sstevel@tonic-gate 		sd_free_inlist_wmap((un), (wmp));		\
7947c478bd9Sstevel@tonic-gate 		(wmp) = NULL;					\
7957c478bd9Sstevel@tonic-gate 	}
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate #define	CHK_N_FREEWMP(un, wmp)					\
7987c478bd9Sstevel@tonic-gate 	if (!ONLIST((un), (wmp))) {				\
7997c478bd9Sstevel@tonic-gate 		kmem_cache_free((un)->un_wm_cache, (wmp));	\
8007c478bd9Sstevel@tonic-gate 		(wmp) = NULL;					\
8017c478bd9Sstevel@tonic-gate 	} else {						\
8027c478bd9Sstevel@tonic-gate 		FREE_ONLIST_WMAP((un), (wmp));			\
8037c478bd9Sstevel@tonic-gate 	}
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate  * Values used to in wm_flags field of sd_w_map.
8077c478bd9Sstevel@tonic-gate  */
8087c478bd9Sstevel@tonic-gate #define	SD_WTYPE_SIMPLE	0x001	/* Write aligned at blksize boundary */
8097c478bd9Sstevel@tonic-gate #define	SD_WTYPE_RMW	0x002	/* Write requires read-modify-write */
8107c478bd9Sstevel@tonic-gate #define	SD_WM_BUSY		0x100	/* write-map is busy */
8117c478bd9Sstevel@tonic-gate 
81265908c77Syu, larry liu - Sun Microsystems - Beijing China /*
81365908c77Syu, larry liu - Sun Microsystems - Beijing China  * RMW type
81465908c77Syu, larry liu - Sun Microsystems - Beijing China  */
81565908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_RMW_TYPE_DEFAULT	0	/* do rmw with warning message */
81665908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_RMW_TYPE_NO_WARNING	1	/* do rmw without warning message */
81765908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_RMW_TYPE_RETURN_ERROR	2	/* rmw disabled */
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate /* Device error kstats */
8207c478bd9Sstevel@tonic-gate struct sd_errstats {
8217c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_softerrs;
8227c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_harderrs;
8237c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_transerrs;
8247c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_vid;
8257c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_pid;
8267c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_revision;
8277c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_serial;
8287c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_capacity;
8297c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_media_err;
8307c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_ntrdy_err;
8317c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_nodev_err;
8327c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_recov_err;
8337c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_illrq_err;
8347c478bd9Sstevel@tonic-gate 	struct kstat_named	sd_rq_pfa_err;
8357c478bd9Sstevel@tonic-gate };
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate /*
8397c478bd9Sstevel@tonic-gate  * Structs and definitions for SCSI-3 Persistent Reservation
8407c478bd9Sstevel@tonic-gate  */
8417c478bd9Sstevel@tonic-gate typedef struct sd_prin_readkeys {
8427c478bd9Sstevel@tonic-gate 	uint32_t	generation;
8437c478bd9Sstevel@tonic-gate 	uint32_t	len;
8447c478bd9Sstevel@tonic-gate 	mhioc_resv_key_t *keylist;
8457c478bd9Sstevel@tonic-gate } sd_prin_readkeys_t;
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate typedef struct sd_readresv_desc {
8487c478bd9Sstevel@tonic-gate 	mhioc_resv_key_t	resvkey;
8497c478bd9Sstevel@tonic-gate 	uint32_t		scope_specific_addr;
8507c478bd9Sstevel@tonic-gate 	uint8_t			reserved_1;
8517c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8527c478bd9Sstevel@tonic-gate 	uint8_t			type:4,
8537c478bd9Sstevel@tonic-gate 				scope:4;
8547c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8557c478bd9Sstevel@tonic-gate 	uint8_t			scope:4,
8567c478bd9Sstevel@tonic-gate 				type:4;
8577c478bd9Sstevel@tonic-gate #else
8587c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8597c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8607c478bd9Sstevel@tonic-gate 	uint8_t			reserved_2;
8617c478bd9Sstevel@tonic-gate 	uint8_t			reserved_3;
8627c478bd9Sstevel@tonic-gate } sd_readresv_desc_t;
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate typedef struct sd_prin_readresv {
8657c478bd9Sstevel@tonic-gate 	uint32_t		generation;
8667c478bd9Sstevel@tonic-gate 	uint32_t		len;
8677c478bd9Sstevel@tonic-gate 	sd_readresv_desc_t	*readresv_desc;
8687c478bd9Sstevel@tonic-gate } sd_prin_readresv_t;
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate typedef struct sd_prout {
8717c478bd9Sstevel@tonic-gate 	uchar_t		res_key[MHIOC_RESV_KEY_SIZE];
8727c478bd9Sstevel@tonic-gate 	uchar_t		service_key[MHIOC_RESV_KEY_SIZE];
8737c478bd9Sstevel@tonic-gate 	uint32_t	scope_address;
8747c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
8757c478bd9Sstevel@tonic-gate 	uchar_t		aptpl:1,
8767c478bd9Sstevel@tonic-gate 			reserved:7;
8777c478bd9Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
8787c478bd9Sstevel@tonic-gate 	uchar_t		reserved:7,
8797c478bd9Sstevel@tonic-gate 			aptpl:1;
8807c478bd9Sstevel@tonic-gate #else
8817c478bd9Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
8827c478bd9Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
8837c478bd9Sstevel@tonic-gate 	uchar_t		reserved_1;
8847c478bd9Sstevel@tonic-gate 	uint16_t	ext_len;
8857c478bd9Sstevel@tonic-gate } sd_prout_t;
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate #define	SD_READ_KEYS			0x00
8887c478bd9Sstevel@tonic-gate #define	SD_READ_RESV			0x01
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate #define	SD_SCSI3_REGISTER		0x00
8917c478bd9Sstevel@tonic-gate #define	SD_SCSI3_RESERVE		0x01
8927c478bd9Sstevel@tonic-gate #define	SD_SCSI3_RELEASE		0x02
89311472db1Sgalibern cyril #define	SD_SCSI3_CLEAR			0x03
8947c478bd9Sstevel@tonic-gate #define	SD_SCSI3_PREEMPTANDABORT	0x05
8957c478bd9Sstevel@tonic-gate #define	SD_SCSI3_REGISTERANDIGNOREKEY	0x06
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate /*
8987c478bd9Sstevel@tonic-gate  * Note: The default init of un_reservation_type is to the value of '0'
8997c478bd9Sstevel@tonic-gate  * (from the ddi_softs_state_zalloc) which means it is defaulting to SCSI-3
9007c478bd9Sstevel@tonic-gate  * reservation type. This is ok because during attach we use a SCSI-3
9017c478bd9Sstevel@tonic-gate  * PRIORITY RESERVE IN command to determine the reservation type, and set
9027c478bd9Sstevel@tonic-gate  * un_reservation_type for all cases.
9037c478bd9Sstevel@tonic-gate  */
9047c478bd9Sstevel@tonic-gate #define	SD_SCSI3_RESERVATION		0x0
9057c478bd9Sstevel@tonic-gate #define	SD_SCSI2_RESERVATION		0x1
9067c478bd9Sstevel@tonic-gate #define	SCSI3_RESV_DESC_LEN		16
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate /*
9097c478bd9Sstevel@tonic-gate  * Reservation Status's
9107c478bd9Sstevel@tonic-gate  */
9117c478bd9Sstevel@tonic-gate #define	SD_RELEASE			0x0000
9127c478bd9Sstevel@tonic-gate #define	SD_RESERVE			0x0001
9137c478bd9Sstevel@tonic-gate #define	SD_TKOWN			0x0002
9147c478bd9Sstevel@tonic-gate #define	SD_LOST_RESERVE			0x0004
9157c478bd9Sstevel@tonic-gate #define	SD_FAILFAST			0x0080
9167c478bd9Sstevel@tonic-gate #define	SD_WANT_RESERVE			0x0100
9177c478bd9Sstevel@tonic-gate #define	SD_RESERVATION_CONFLICT		0x0200
9187c478bd9Sstevel@tonic-gate #define	SD_PRIORITY_RESERVE		0x0400
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate #define	SD_TARGET_IS_UNRESERVED		0
9217c478bd9Sstevel@tonic-gate #define	SD_TARGET_IS_RESERVED		1
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate /*
9247c478bd9Sstevel@tonic-gate  * Save page in mode_select
9257c478bd9Sstevel@tonic-gate  */
9267c478bd9Sstevel@tonic-gate #define	SD_DONTSAVE_PAGE		0
9277c478bd9Sstevel@tonic-gate #define	SD_SAVE_PAGE			1
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate /*
9307c478bd9Sstevel@tonic-gate  * Delay before reclaiming reservation is 6 seconds, in units of micro seconds
9317c478bd9Sstevel@tonic-gate  */
9327c478bd9Sstevel@tonic-gate #define	SD_REINSTATE_RESV_DELAY		6000000
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate #define	SD_MODE2_BLKSIZE		2336	/* bytes */
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate /*
937f13665b7Sbo zhou - Sun Microsystems - Beijing China  * Solid State Drive default sector size
938f13665b7Sbo zhou - Sun Microsystems - Beijing China  */
939f13665b7Sbo zhou - Sun Microsystems - Beijing China #define	SSD_SECSIZE			4096
940f13665b7Sbo zhou - Sun Microsystems - Beijing China 
941f13665b7Sbo zhou - Sun Microsystems - Beijing China /*
9427c478bd9Sstevel@tonic-gate  * Resource type definitions for multi host control operations. Specifically,
9437c478bd9Sstevel@tonic-gate  * queue and request definitions for reservation request handling between the
9447c478bd9Sstevel@tonic-gate  * scsi facility callback function (sd_mhd_watch_cb) and the reservation
9457c478bd9Sstevel@tonic-gate  * reclaim thread (sd_resv_reclaim_thread)
9467c478bd9Sstevel@tonic-gate  */
9477c478bd9Sstevel@tonic-gate struct sd_thr_request {
9487c478bd9Sstevel@tonic-gate 	dev_t	dev;
9497c478bd9Sstevel@tonic-gate 	struct	sd_thr_request	*sd_thr_req_next;
9507c478bd9Sstevel@tonic-gate };
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate struct sd_resv_reclaim_request {
9537c478bd9Sstevel@tonic-gate 	kthread_t		*srq_resv_reclaim_thread;
9547c478bd9Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_req_head;
9557c478bd9Sstevel@tonic-gate 	struct	sd_thr_request	*srq_thr_cur_req;
9567c478bd9Sstevel@tonic-gate 	kcondvar_t		srq_inprocess_cv;
9577c478bd9Sstevel@tonic-gate 	kmutex_t		srq_resv_reclaim_mutex;
9587c478bd9Sstevel@tonic-gate 	kcondvar_t		srq_resv_reclaim_cv;
9597c478bd9Sstevel@tonic-gate };
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(sd_resv_reclaim_request::srq_resv_reclaim_mutex,
9627c478bd9Sstevel@tonic-gate     sd_resv_reclaim_request))
9637c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unshared data", sd_thr_request))
9647c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_prout))
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * Driver Logging Components
9707c478bd9Sstevel@tonic-gate  *
9717c478bd9Sstevel@tonic-gate  * These components cover the functional entry points and areas of the
9727c478bd9Sstevel@tonic-gate  * driver.  A component value is used for the entry point and utility
9737c478bd9Sstevel@tonic-gate  * functions used by the entry point. The common component value is used
9747c478bd9Sstevel@tonic-gate  * in those routines that are called from many areas of the driver.
9757c478bd9Sstevel@tonic-gate  *
9767c478bd9Sstevel@tonic-gate  * This can be done by adding the following two lines to /etc/system:
9777c478bd9Sstevel@tonic-gate  * set sd:sd_component_mask=0x00080000
9787c478bd9Sstevel@tonic-gate  * set sd:sd_level_mask=0x00000008
9797c478bd9Sstevel@tonic-gate  */
9807c478bd9Sstevel@tonic-gate #define	SD_LOG_PROBE			0x00000001
9817c478bd9Sstevel@tonic-gate #define	SD_LOG_ATTACH_DETACH		0x00000002
9827c478bd9Sstevel@tonic-gate #define	SD_LOG_OPEN_CLOSE		0x00000004
9837c478bd9Sstevel@tonic-gate #define	SD_LOG_READ_WRITE		0x00000008
9847c478bd9Sstevel@tonic-gate #define	SD_LOG_POWER			0x00000010
9857c478bd9Sstevel@tonic-gate #define	SD_LOG_IOCTL			0x00000020
9867c478bd9Sstevel@tonic-gate #define	SD_LOG_IOCTL_MHD		0x00000040
9877c478bd9Sstevel@tonic-gate #define	SD_LOG_IOCTL_RMMEDIA		0x00000080
9887c478bd9Sstevel@tonic-gate #define	SD_LOG_IOCTL_DKIO		0x00000100
9897c478bd9Sstevel@tonic-gate #define	SD_LOG_IO			0x00000200
9907c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_CORE			0x00000400
9917c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_DISKSORT		0x00000800
9927c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_PARTITION		0x00001000
9937c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_RMMEDIA		0x00002000
9947c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_CHKSUM		0x00004000
9957c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_SDIOCTL		0x00008000
9967c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_PM			0x00010000
9977c478bd9Sstevel@tonic-gate #define	SD_LOG_ERROR			0x00020000
9987c478bd9Sstevel@tonic-gate #define	SD_LOG_DUMP			0x00040000
9997c478bd9Sstevel@tonic-gate #define	SD_LOG_COMMON			0x00080000
10007c478bd9Sstevel@tonic-gate #define	SD_LOG_SDTEST			0x00100000
10017c478bd9Sstevel@tonic-gate #define	SD_LOG_IOERR			0x00200000
10027c478bd9Sstevel@tonic-gate #define	SD_LOG_IO_FAILFAST		0x00400000
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate /* Driver Logging Levels */
10057c478bd9Sstevel@tonic-gate #define	SD_LOGMASK_ERROR		0x00000001
10067c478bd9Sstevel@tonic-gate #define	SD_LOGMASK_DUMP_MEM		0x00000002
10077c478bd9Sstevel@tonic-gate #define	SD_LOGMASK_INFO			0x00000004
10087c478bd9Sstevel@tonic-gate #define	SD_LOGMASK_TRACE		0x00000008
10097c478bd9Sstevel@tonic-gate #define	SD_LOGMASK_DIAG			0x00000010
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate /* Driver Logging Formats */
10127c478bd9Sstevel@tonic-gate #define	SD_LOG_HEX			0x00000001
10137c478bd9Sstevel@tonic-gate #define	SD_LOG_CHAR			0x00000002
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate /*
10167c478bd9Sstevel@tonic-gate  * The following macros should be used to log driver debug information
10177c478bd9Sstevel@tonic-gate  * only. The output is filtered according to the component and level mask
10187c478bd9Sstevel@tonic-gate  * values. Non-debug information, such as driver warnings intended for
10197c478bd9Sstevel@tonic-gate  * the user should be logged via the scsi_log facility to ensure that
10207c478bd9Sstevel@tonic-gate  * they are not filtered.
10217c478bd9Sstevel@tonic-gate  */
10227c478bd9Sstevel@tonic-gate #if DEBUG || lint
10237c478bd9Sstevel@tonic-gate #define	SDDEBUG
10247c478bd9Sstevel@tonic-gate 
10257c478bd9Sstevel@tonic-gate /* SD_ERROR is called to log driver error conditions */
10267c478bd9Sstevel@tonic-gate #define	SD_ERROR	sd_log_err
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate /* SD_TRACE is called to log driver trace conditions (function entry/exit) */
10297c478bd9Sstevel@tonic-gate #define	SD_TRACE	sd_log_trace
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate /* SD_INFO is called to log general purpose driver info */
10327c478bd9Sstevel@tonic-gate #define	SD_INFO		sd_log_info
10337c478bd9Sstevel@tonic-gate 
10347c478bd9Sstevel@tonic-gate /* SD_DUMP_MEMORY is called to dump a data buffer to the log */
10357c478bd9Sstevel@tonic-gate #define	SD_DUMP_MEMORY	sd_dump_memory
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate /* RESET/ABORTS testing ioctls */
10387c478bd9Sstevel@tonic-gate #define	DKIOCRESET	(DKIOC|14)
10397c478bd9Sstevel@tonic-gate #define	DKIOCABORT	(DKIOC|15)
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate #ifdef SD_FAULT_INJECTION
10427c478bd9Sstevel@tonic-gate /*
104330a83a24Scth  * sd_fi_pkt replicates the variables that are exposed through pkt
10447c478bd9Sstevel@tonic-gate  *
104530a83a24Scth  * sd_fi_xb replicates the variables that are exposed through xb
10467c478bd9Sstevel@tonic-gate  *
104730a83a24Scth  * sd_fi_un replicates the variables that are exposed through un
10487c478bd9Sstevel@tonic-gate  *
104930a83a24Scth  * sd_fi_arq replicates the variables that are
10507c478bd9Sstevel@tonic-gate  *           exposed for Auto-Reqeust-Sense
10517c478bd9Sstevel@tonic-gate  *
10527c478bd9Sstevel@tonic-gate  */
10537c478bd9Sstevel@tonic-gate struct sd_fi_pkt {
10547c478bd9Sstevel@tonic-gate 	uint_t  pkt_flags;			/* flags */
10557c478bd9Sstevel@tonic-gate 	uchar_t pkt_scbp;			/* pointer to status block */
10567c478bd9Sstevel@tonic-gate 	uchar_t pkt_cdbp;			/* pointer to command block */
10577c478bd9Sstevel@tonic-gate 	uint_t  pkt_state;			/* state of command */
10587c478bd9Sstevel@tonic-gate 	uint_t  pkt_statistics;		/* statistics */
10597c478bd9Sstevel@tonic-gate 	uchar_t pkt_reason;			/* reason completion called */
10607c478bd9Sstevel@tonic-gate };
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate struct sd_fi_xb {
10637c478bd9Sstevel@tonic-gate 	daddr_t xb_blkno;
10647c478bd9Sstevel@tonic-gate 	ssize_t xb_dma_resid;
10657c478bd9Sstevel@tonic-gate 	short	xb_retry_count;
10667c478bd9Sstevel@tonic-gate 	short	xb_victim_retry_count;
10677c478bd9Sstevel@tonic-gate 	uchar_t xb_sense_status;
10687c478bd9Sstevel@tonic-gate 	uint_t  xb_sense_state;
10697c478bd9Sstevel@tonic-gate 	ssize_t xb_sense_resid;
10707c478bd9Sstevel@tonic-gate 	uchar_t xb_sense_data[SENSE_LENGTH];
10717c478bd9Sstevel@tonic-gate 	uchar_t es_code;
10727c478bd9Sstevel@tonic-gate 	uchar_t es_key;
10737c478bd9Sstevel@tonic-gate 	uchar_t es_add_code;
10747c478bd9Sstevel@tonic-gate 	uchar_t es_qual_code;
10757c478bd9Sstevel@tonic-gate };
10767c478bd9Sstevel@tonic-gate 
10777c478bd9Sstevel@tonic-gate struct sd_fi_un {
10787c478bd9Sstevel@tonic-gate 	uchar_t inq_rmb;
10797c478bd9Sstevel@tonic-gate 	uchar_t un_ctype;
10807c478bd9Sstevel@tonic-gate 	uint_t  un_notready_retry_count;
10817c478bd9Sstevel@tonic-gate 	uint_t  un_reset_retry_count;
10827c478bd9Sstevel@tonic-gate 	uchar_t un_reservation_type;
10837c478bd9Sstevel@tonic-gate 	ushort_t un_notrdy_delay;
10847c478bd9Sstevel@tonic-gate 	short   un_resvd_status;
10857c478bd9Sstevel@tonic-gate 	uint32_t
10867c478bd9Sstevel@tonic-gate 		un_f_arq_enabled,
10877c478bd9Sstevel@tonic-gate 		un_f_allow_bus_device_reset,
10887c478bd9Sstevel@tonic-gate 		un_f_opt_queueing;
10897c478bd9Sstevel@tonic-gate 	timeout_id_t    un_restart_timeid;
10907c478bd9Sstevel@tonic-gate };
10917c478bd9Sstevel@tonic-gate 
10927c478bd9Sstevel@tonic-gate struct sd_fi_arq {
10937c478bd9Sstevel@tonic-gate 	struct scsi_status	sts_status;
10947c478bd9Sstevel@tonic-gate 	struct scsi_status	sts_rqpkt_status;
10957c478bd9Sstevel@tonic-gate 	uchar_t				sts_rqpkt_reason;
10967c478bd9Sstevel@tonic-gate 	uchar_t				sts_rqpkt_resid;
10977c478bd9Sstevel@tonic-gate 	uint_t				sts_rqpkt_state;
10987c478bd9Sstevel@tonic-gate 	uint_t				sts_rqpkt_statistics;
10997c478bd9Sstevel@tonic-gate 	struct scsi_extended_sense	sts_sensedata;
11007c478bd9Sstevel@tonic-gate };
11017c478bd9Sstevel@tonic-gate 
11029e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
11039e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * Conditional set def
11049e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
11057c478bd9Sstevel@tonic-gate #define	SD_CONDSET(a, b, c, d)			\
11069e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	{ \
11077c478bd9Sstevel@tonic-gate 	a->c = ((fi_ ## b)->c);			\
11087c478bd9Sstevel@tonic-gate 	SD_INFO(SD_LOG_IOERR, un,		\
11097c478bd9Sstevel@tonic-gate 			"sd_fault_injection:"	\
11107c478bd9Sstevel@tonic-gate 			"setting %s to %d\n", 	\
11119e1c849eSDavid Zhang - Sun Microsystems - Beijing China 			d, ((fi_ ## b)->c)); 	\
11129e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	}
11137c478bd9Sstevel@tonic-gate 
11147c478bd9Sstevel@tonic-gate /* SD FaultInjection ioctls */
11157c478bd9Sstevel@tonic-gate #define	SDIOC			('T'<<8)
11167c478bd9Sstevel@tonic-gate #define	SDIOCSTART		(SDIOC|1)
11177c478bd9Sstevel@tonic-gate #define	SDIOCSTOP		(SDIOC|2)
11187c478bd9Sstevel@tonic-gate #define	SDIOCINSERTPKT	(SDIOC|3)
11197c478bd9Sstevel@tonic-gate #define	SDIOCINSERTXB	(SDIOC|4)
11207c478bd9Sstevel@tonic-gate #define	SDIOCINSERTUN	(SDIOC|5)
11217c478bd9Sstevel@tonic-gate #define	SDIOCINSERTARQ	(SDIOC|6)
11227c478bd9Sstevel@tonic-gate #define	SDIOCPUSH		(SDIOC|7)
11237c478bd9Sstevel@tonic-gate #define	SDIOCRETRIEVE	(SDIOC|8)
11247c478bd9Sstevel@tonic-gate #define	SDIOCRUN		(SDIOC|9)
11257c478bd9Sstevel@tonic-gate #endif
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate #else
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate #undef	SDDEBUG
11307c478bd9Sstevel@tonic-gate #define	SD_ERROR	{ if (0) sd_log_err; }
11317c478bd9Sstevel@tonic-gate #define	SD_TRACE	{ if (0) sd_log_trace; }
11327c478bd9Sstevel@tonic-gate #define	SD_INFO		{ if (0) sd_log_info; }
11337c478bd9Sstevel@tonic-gate #define	SD_DUMP_MEMORY	{ if (0) sd_dump_memory; }
11347c478bd9Sstevel@tonic-gate #endif
11357c478bd9Sstevel@tonic-gate 
11367c478bd9Sstevel@tonic-gate 
11377c478bd9Sstevel@tonic-gate /*
11387c478bd9Sstevel@tonic-gate  * Miscellaneous macros
11397c478bd9Sstevel@tonic-gate  */
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate #define	SD_USECTOHZ(x)			(drv_usectohz((x)*1000000))
11427c478bd9Sstevel@tonic-gate #define	SD_GET_PKT_STATUS(pktp)		((*(pktp)->pkt_scbp) & STATUS_MASK)
11437c478bd9Sstevel@tonic-gate 
11447c478bd9Sstevel@tonic-gate #define	SD_BIOERROR(bp, errcode)					\
11457c478bd9Sstevel@tonic-gate 	if ((bp)->b_resid == 0) {					\
11467c478bd9Sstevel@tonic-gate 		(bp)->b_resid = (bp)->b_bcount;				\
11477c478bd9Sstevel@tonic-gate 	}								\
11487c478bd9Sstevel@tonic-gate 	if ((bp)->b_error == 0) {					\
11497c478bd9Sstevel@tonic-gate 		bioerror(bp, errcode);					\
11507c478bd9Sstevel@tonic-gate 	}								\
1151e5243e60Slh195018 	(bp)->b_flags |= B_ERROR;
11527c478bd9Sstevel@tonic-gate 
1153f3f5a4ddSjongkis #define	SD_FILL_SCSI1_LUN_CDB(lunp, cdbp)				\
1154f3f5a4ddSjongkis 	if (! (lunp)->un_f_is_fibre &&					\
1155f3f5a4ddSjongkis 	    SD_INQUIRY((lunp))->inq_ansi == 0x01) {			\
1156f3f5a4ddSjongkis 		int _lun = ddi_prop_get_int(DDI_DEV_T_ANY,		\
1157f3f5a4ddSjongkis 		    SD_DEVINFO((lunp)), DDI_PROP_DONTPASS,		\
1158f3f5a4ddSjongkis 		    SCSI_ADDR_PROP_LUN, 0);				\
1159f3f5a4ddSjongkis 		if (_lun > 0) {						\
1160f3f5a4ddSjongkis 			(cdbp)->scc_lun = _lun;				\
1161f3f5a4ddSjongkis 		}							\
11627c478bd9Sstevel@tonic-gate 	}
11637c478bd9Sstevel@tonic-gate 
1164f3f5a4ddSjongkis #define	SD_FILL_SCSI1_LUN(lunp, pktp)					\
1165f3f5a4ddSjongkis 	SD_FILL_SCSI1_LUN_CDB((lunp), (union scsi_cdb *)(pktp)->pkt_cdbp)
1166f3f5a4ddSjongkis 
11677c478bd9Sstevel@tonic-gate /*
11687c478bd9Sstevel@tonic-gate  * Disk driver states
11697c478bd9Sstevel@tonic-gate  */
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate #define	SD_STATE_NORMAL		0
11727c478bd9Sstevel@tonic-gate #define	SD_STATE_OFFLINE	1
11737c478bd9Sstevel@tonic-gate #define	SD_STATE_RWAIT		2
11747c478bd9Sstevel@tonic-gate #define	SD_STATE_DUMPING	3
11757c478bd9Sstevel@tonic-gate #define	SD_STATE_SUSPENDED	4
11767c478bd9Sstevel@tonic-gate #define	SD_STATE_PM_CHANGING	5
11777c478bd9Sstevel@tonic-gate 
11787c478bd9Sstevel@tonic-gate /*
11797c478bd9Sstevel@tonic-gate  * The table is to be interpreted as follows: The rows lists all the states
11807c478bd9Sstevel@tonic-gate  * and each column is a state that a state in each row *can* reach. The entries
11817c478bd9Sstevel@tonic-gate  * in the table list the event that cause that transition to take place.
11827c478bd9Sstevel@tonic-gate  * For e.g.: To go from state RWAIT to SUSPENDED, event (d)-- which is the
11837c478bd9Sstevel@tonic-gate  * invocation of DDI_SUSPEND-- has to take place. Note the same event could
11847c478bd9Sstevel@tonic-gate  * cause the transition from one state to two different states. e.g., from
11857c478bd9Sstevel@tonic-gate  * state SUSPENDED, when we get a DDI_RESUME, we just go back to the *last
11867c478bd9Sstevel@tonic-gate  * state* whatever that might be. (NORMAL or OFFLINE).
11877c478bd9Sstevel@tonic-gate  *
11887c478bd9Sstevel@tonic-gate  *
11897c478bd9Sstevel@tonic-gate  * State Transition Table:
11907c478bd9Sstevel@tonic-gate  *
11917c478bd9Sstevel@tonic-gate  *                    NORMAL  OFFLINE  RWAIT  DUMPING  SUSPENDED  PM_SUSPENDED
11927c478bd9Sstevel@tonic-gate  *
11937c478bd9Sstevel@tonic-gate  *   NORMAL              -      (a)      (b)     (c)      (d)       (h)
11947c478bd9Sstevel@tonic-gate  *
11957c478bd9Sstevel@tonic-gate  *   OFFLINE            (e)      -       (e)     (c)      (d)       NP
11967c478bd9Sstevel@tonic-gate  *
11977c478bd9Sstevel@tonic-gate  *   RWAIT              (f)     NP        -      (c)      (d)       (h)
11987c478bd9Sstevel@tonic-gate  *
11997c478bd9Sstevel@tonic-gate  *   DUMPING            NP      NP        NP      -        NP       NP
12007c478bd9Sstevel@tonic-gate  *
12017c478bd9Sstevel@tonic-gate  *   SUSPENDED          (g)     (g)       (b)     NP*      -        NP
12027c478bd9Sstevel@tonic-gate  *
12037c478bd9Sstevel@tonic-gate  *   PM_SUSPENDED       (i)     NP        (b)    (c)      (d)       -
12047c478bd9Sstevel@tonic-gate  *
12057c478bd9Sstevel@tonic-gate  *   NP :       Not Possible.
12067c478bd9Sstevel@tonic-gate  *   (a):       Disk does not respond.
12077c478bd9Sstevel@tonic-gate  *   (b):       Packet Allocation Fails
12087c478bd9Sstevel@tonic-gate  *   (c):       Panic - Crash dump
12097c478bd9Sstevel@tonic-gate  *   (d):       DDI_SUSPEND is called.
12107c478bd9Sstevel@tonic-gate  *   (e):       Disk has a successful I/O completed.
12117c478bd9Sstevel@tonic-gate  *   (f):       sdrunout() calls sdstart() which sets it NORMAL
12127c478bd9Sstevel@tonic-gate  *   (g):       DDI_RESUME is called.
12137c478bd9Sstevel@tonic-gate  *   (h):	Device threshold exceeded pm framework called power
12147c478bd9Sstevel@tonic-gate  *		entry point or pm_lower_power called in detach.
12157c478bd9Sstevel@tonic-gate  *   (i):	When new I/O come in.
12167c478bd9Sstevel@tonic-gate  *    * :       When suspended, we dont change state during panic dump
12177c478bd9Sstevel@tonic-gate  */
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 
12207c478bd9Sstevel@tonic-gate #define	SD_MAX_THROTTLE		256
12217c478bd9Sstevel@tonic-gate #define	SD_MIN_THROTTLE		8
12227c478bd9Sstevel@tonic-gate /*
12237c478bd9Sstevel@tonic-gate  * Lowest valid max. and min. throttle value.
12247c478bd9Sstevel@tonic-gate  * This is set to 2 because if un_min_throttle were allowed to be 1 then
12257c478bd9Sstevel@tonic-gate  * un_throttle would never get set to a value less than un_min_throttle
12267c478bd9Sstevel@tonic-gate  * (0 is a special case) which means it would never get set back to
12277c478bd9Sstevel@tonic-gate  * un_saved_throttle in routine sd_restore_throttle().
12287c478bd9Sstevel@tonic-gate  */
12297c478bd9Sstevel@tonic-gate #define	SD_LOWEST_VALID_THROTTLE	2
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate 
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate /* Return codes for sd_send_polled_cmd() and sd_scsi_poll() */
12347c478bd9Sstevel@tonic-gate #define	SD_CMD_SUCCESS			0
12357c478bd9Sstevel@tonic-gate #define	SD_CMD_FAILURE			1
12367c478bd9Sstevel@tonic-gate #define	SD_CMD_RESERVATION_CONFLICT	2
12377c478bd9Sstevel@tonic-gate #define	SD_CMD_ILLEGAL_REQUEST		3
12387c478bd9Sstevel@tonic-gate #define	SD_CMD_BECOMING_READY		4
12397c478bd9Sstevel@tonic-gate #define	SD_CMD_CHECK_CONDITION		5
12407c478bd9Sstevel@tonic-gate 
12417c478bd9Sstevel@tonic-gate /* Return codes for sd_ready_and_valid */
12427c478bd9Sstevel@tonic-gate #define	SD_READY_VALID			0
12437c478bd9Sstevel@tonic-gate #define	SD_NOT_READY_VALID		1
1244e8fb11a1Sshidokht #define	SD_RESERVED_BY_OTHERS		2
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate #define	SD_PATH_STANDARD		0
12477c478bd9Sstevel@tonic-gate #define	SD_PATH_DIRECT			1
12487c478bd9Sstevel@tonic-gate #define	SD_PATH_DIRECT_PRIORITY		2
12497c478bd9Sstevel@tonic-gate 
12507c478bd9Sstevel@tonic-gate #define	SD_UNIT_ATTENTION_RETRY		40
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate /*
12537c478bd9Sstevel@tonic-gate  * The following three are bit flags passed into sd_send_scsi_TEST_UNIT_READY
12547c478bd9Sstevel@tonic-gate  * to control specific behavior.
12557c478bd9Sstevel@tonic-gate  */
12567c478bd9Sstevel@tonic-gate #define	SD_CHECK_FOR_MEDIA		0x01
12577c478bd9Sstevel@tonic-gate #define	SD_DONT_RETRY_TUR		0x02
12587c478bd9Sstevel@tonic-gate #define	SD_BYPASS_PM			0x04
12597c478bd9Sstevel@tonic-gate 
12605c46c6a0Spd144616 #define	SD_GROUP0_MAX_ADDRESS	(0x1fffff)
12617c478bd9Sstevel@tonic-gate #define	SD_GROUP0_MAXCOUNT	(0xff)
12625c46c6a0Spd144616 #define	SD_GROUP1_MAX_ADDRESS	(0xffffffff)
12637c478bd9Sstevel@tonic-gate #define	SD_GROUP1_MAXCOUNT	(0xffff)
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate #define	SD_BECOMING_ACTIVE	0x01
12667c478bd9Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW	0
12677c478bd9Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT	1
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate #define	SD_GET_PKT_OPCODE(pktp)	\
12707c478bd9Sstevel@tonic-gate 	(((union scsi_cdb *)((pktp)->pkt_cdbp))->cdb_un.cmd)
12717c478bd9Sstevel@tonic-gate 
12727c478bd9Sstevel@tonic-gate 
12737c478bd9Sstevel@tonic-gate #define	SD_NO_RETRY_ISSUED		0
12747c478bd9Sstevel@tonic-gate #define	SD_DELAYED_RETRY_ISSUED		1
12757c478bd9Sstevel@tonic-gate #define	SD_IMMEDIATE_RETRY_ISSUED	2
12767c478bd9Sstevel@tonic-gate 
12777c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
12787c478bd9Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12797c478bd9Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid + (SD_GET_XBUF(bp)->xb_dma_resid))
12807c478bd9Sstevel@tonic-gate #else
12817c478bd9Sstevel@tonic-gate #define	SD_UPDATE_B_RESID(bp, pktp)	\
12827c478bd9Sstevel@tonic-gate 	((bp)->b_resid += (pktp)->pkt_resid)
12837c478bd9Sstevel@tonic-gate #endif
12847c478bd9Sstevel@tonic-gate 
12857c478bd9Sstevel@tonic-gate 
12867c478bd9Sstevel@tonic-gate #define	SD_RETRIES_MASK		0x00FF
12877c478bd9Sstevel@tonic-gate #define	SD_RETRIES_NOCHECK	0x0000
12887c478bd9Sstevel@tonic-gate #define	SD_RETRIES_STANDARD	0x0001
12897c478bd9Sstevel@tonic-gate #define	SD_RETRIES_VICTIM	0x0002
12907c478bd9Sstevel@tonic-gate #define	SD_RETRIES_BUSY		0x0003
12917c478bd9Sstevel@tonic-gate #define	SD_RETRIES_UA		0x0004
12927c478bd9Sstevel@tonic-gate #define	SD_RETRIES_ISOLATE	0x8000
12937c478bd9Sstevel@tonic-gate #define	SD_RETRIES_FAILFAST	0x4000
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate #define	SD_UPDATE_RESERVATION_STATUS(un, pktp)				\
12967c478bd9Sstevel@tonic-gate if (((pktp)->pkt_reason == CMD_RESET) ||				\
12977c478bd9Sstevel@tonic-gate 	((pktp)->pkt_statistics & (STAT_BUS_RESET | STAT_DEV_RESET))) { \
12987c478bd9Sstevel@tonic-gate 	if (((un)->un_resvd_status & SD_RESERVE) == SD_RESERVE) {	\
12997c478bd9Sstevel@tonic-gate 		(un)->un_resvd_status |=				\
13007c478bd9Sstevel@tonic-gate 		    (SD_LOST_RESERVE | SD_WANT_RESERVE);		\
13017c478bd9Sstevel@tonic-gate 	}								\
13027c478bd9Sstevel@tonic-gate }
13037c478bd9Sstevel@tonic-gate 
13047c478bd9Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_VALID		0
13057c478bd9Sstevel@tonic-gate #define	SD_SENSE_DATA_IS_INVALID	1
13067c478bd9Sstevel@tonic-gate 
13077c478bd9Sstevel@tonic-gate /*
13087c478bd9Sstevel@tonic-gate  * Delay (in seconds) before restoring the "throttle limit" back
13097c478bd9Sstevel@tonic-gate  * to its maximum value.
1310eed59cc4Sts143224  * 60 seconds is what we will wait for to reset the
1311eed59cc4Sts143224  * throttle back to it SD_MAX_THROTTLE for TRAN_BUSY.
1312eed59cc4Sts143224  * 10 seconds for STATUS_QFULL because QFULL will incrementally
1313eed59cc4Sts143224  * increase the throttle limit until it reaches max value.
13147c478bd9Sstevel@tonic-gate  */
13157c478bd9Sstevel@tonic-gate #define	SD_RESET_THROTTLE_TIMEOUT	60
1316eed59cc4Sts143224 #define	SD_QFULL_THROTTLE_TIMEOUT	10
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate #define	SD_THROTTLE_TRAN_BUSY		0
13197c478bd9Sstevel@tonic-gate #define	SD_THROTTLE_QFULL		1
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate #define	SD_THROTTLE_RESET_INTERVAL	\
13227c478bd9Sstevel@tonic-gate 	(sd_reset_throttle_timeout * drv_usectohz(1000000))
13237c478bd9Sstevel@tonic-gate 
1324eed59cc4Sts143224 #define	SD_QFULL_THROTTLE_RESET_INTERVAL	\
1325eed59cc4Sts143224 	(sd_qfull_throttle_timeout * drv_usectohz(1000000))
1326eed59cc4Sts143224 
13277c478bd9Sstevel@tonic-gate 
13287c478bd9Sstevel@tonic-gate /*
13297c478bd9Sstevel@tonic-gate  * xb_pkt_flags defines
13307c478bd9Sstevel@tonic-gate  * SD_XB_DMA_FREED indicates the scsi_pkt has had its DMA resources freed
13317c478bd9Sstevel@tonic-gate  * by a call to scsi_dmafree(9F). The resources must be reallocated before
13327c478bd9Sstevel@tonic-gate  *   before a call to scsi_transport can be made again.
13339e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * SD_XB_USCSICMD indicates the scsi request is a uscsi request
13347c478bd9Sstevel@tonic-gate  * SD_XB_INITPKT_MASK: since this field is also used to store flags for
13357c478bd9Sstevel@tonic-gate  *   a scsi_init_pkt(9F) call, we need a mask to make sure that we don't
13367c478bd9Sstevel@tonic-gate  *   pass any unintended bits to scsi_init_pkt(9F) (ugly hack).
13377c478bd9Sstevel@tonic-gate  */
13387c478bd9Sstevel@tonic-gate #define	SD_XB_DMA_FREED		0x20000000
13399e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define	SD_XB_USCSICMD		0x40000000
13407c478bd9Sstevel@tonic-gate #define	SD_XB_INITPKT_MASK	(PKT_CONSISTENT | PKT_DMA_PARTIAL)
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate /*
13437c478bd9Sstevel@tonic-gate  * Extension for the buf(9s) struct that we receive from a higher
13447c478bd9Sstevel@tonic-gate  * layer. Located by b_private in the buf(9S).  (The previous contents
13457c478bd9Sstevel@tonic-gate  * of b_private are saved & restored before calling biodone(9F).)
13467c478bd9Sstevel@tonic-gate  */
13477c478bd9Sstevel@tonic-gate struct sd_xbuf {
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	struct sd_lun	*xb_un;		/* Ptr to associated sd_lun */
13507c478bd9Sstevel@tonic-gate 	struct scsi_pkt	*xb_pktp;	/* Ptr to associated scsi_pkt */
13517c478bd9Sstevel@tonic-gate 
13527c478bd9Sstevel@tonic-gate 	/*
13537c478bd9Sstevel@tonic-gate 	 * xb_pktinfo points to any optional data that may be needed
13547c478bd9Sstevel@tonic-gate 	 * by the initpkt and/or destroypkt functions.  Typical
13557c478bd9Sstevel@tonic-gate 	 * use might be to point to a struct uscsi_cmd.
13567c478bd9Sstevel@tonic-gate 	 */
13577c478bd9Sstevel@tonic-gate 	void	*xb_pktinfo;
13587c478bd9Sstevel@tonic-gate 
13597c478bd9Sstevel@tonic-gate 	/*
13607c478bd9Sstevel@tonic-gate 	 * Layer-private data area. This may be used by any layer to store
13617c478bd9Sstevel@tonic-gate 	 * layer-specific data on a per-IO basis. Typical usage is for an
13627c478bd9Sstevel@tonic-gate 	 * iostart routine to save some info here for later use by its
13637c478bd9Sstevel@tonic-gate 	 * partner iodone routine.  This area may be used to hold data or
13647c478bd9Sstevel@tonic-gate 	 * a pointer to a data block that is allocated/freed by the layer's
13657c478bd9Sstevel@tonic-gate 	 * iostart/iodone routines. Allocation & management policy for the
13667c478bd9Sstevel@tonic-gate 	 * layer-private area is defined & implemented by each specific
13677c478bd9Sstevel@tonic-gate 	 * layer as required.
13687c478bd9Sstevel@tonic-gate 	 *
13697c478bd9Sstevel@tonic-gate 	 * IMPORTANT: Since a higher layer may depend on the value in the
13707c478bd9Sstevel@tonic-gate 	 * xb_private field, each layer must ensure that it returns the
13717c478bd9Sstevel@tonic-gate 	 * buf/xbuf to the next higher layer (via SD_NEXT_IODONE()) with
13727c478bd9Sstevel@tonic-gate 	 * the SAME VALUE in xb_private as when the buf/xbuf was first
13737c478bd9Sstevel@tonic-gate 	 * received by the layer's iostart routine. Typically this is done
13747c478bd9Sstevel@tonic-gate 	 * by the iostart routine saving the contents of xb_private into
13757c478bd9Sstevel@tonic-gate 	 * a place in the layer-private data area, and the iodone routine
13767c478bd9Sstevel@tonic-gate 	 * restoring the value of xb_private before deallocating the
13777c478bd9Sstevel@tonic-gate 	 * layer-private data block and calling SD_NEXT_IODONE(). Of course,
13787c478bd9Sstevel@tonic-gate 	 * if a layer never modifies xb_private in a buf/xbuf from a higher
13797c478bd9Sstevel@tonic-gate 	 * layer, there will be no need to restore the value.
13807c478bd9Sstevel@tonic-gate 	 *
13817c478bd9Sstevel@tonic-gate 	 * Note that in the case where a layer _creates_ a buf/xbuf (such as
13827c478bd9Sstevel@tonic-gate 	 * by calling sd_shadow_buf_alloc()) to pass to a lower layer, it is
13837c478bd9Sstevel@tonic-gate 	 * not necessary to preserve the contents of xb_private as there is
13847c478bd9Sstevel@tonic-gate 	 * no higher layer dependency on the value of xb_private. Such a
13857c478bd9Sstevel@tonic-gate 	 * buf/xbuf must be deallocated by the layer that allocated it and
13867c478bd9Sstevel@tonic-gate 	 * must *NEVER* be passed up to a higher layer.
13877c478bd9Sstevel@tonic-gate 	 */
13887c478bd9Sstevel@tonic-gate 	void	*xb_private;	/* Layer-private data block */
13897c478bd9Sstevel@tonic-gate 
13907c478bd9Sstevel@tonic-gate 	/*
13917c478bd9Sstevel@tonic-gate 	 * We do not use the b_blkno provided in the buf(9S), as we need to
13927c478bd9Sstevel@tonic-gate 	 * make adjustments to it in the driver, but it is not a field that
13937c478bd9Sstevel@tonic-gate 	 * the driver owns or is free to modify.
13947c478bd9Sstevel@tonic-gate 	 */
13957c478bd9Sstevel@tonic-gate 	daddr_t	xb_blkno;		/* Absolute block # on target */
13969e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uint64_t xb_ena;		/* ena for a specific SCSI command */
13977c478bd9Sstevel@tonic-gate 
13987c478bd9Sstevel@tonic-gate 	int	xb_chain_iostart;	/* iostart side index */
13997c478bd9Sstevel@tonic-gate 	int	xb_chain_iodone;	/* iodone side index */
14007c478bd9Sstevel@tonic-gate 	int	xb_pkt_flags;		/* Flags for scsi_init_pkt() */
14017c478bd9Sstevel@tonic-gate 	ssize_t	xb_dma_resid;
14027c478bd9Sstevel@tonic-gate 	short	xb_retry_count;
14037c478bd9Sstevel@tonic-gate 	short	xb_victim_retry_count;
14047c478bd9Sstevel@tonic-gate 	short	xb_ua_retry_count;	/* unit_attention retry counter */
140503509b53Slh195018 	short	xb_nr_retry_count;	/* not ready retry counter */
14067c478bd9Sstevel@tonic-gate 
14077c478bd9Sstevel@tonic-gate 	/*
14087c478bd9Sstevel@tonic-gate 	 * Various status and data used when a RQS command is run on
14097c478bd9Sstevel@tonic-gate 	 * the behalf of this command.
14107c478bd9Sstevel@tonic-gate 	 */
14117c478bd9Sstevel@tonic-gate 	struct buf	*xb_sense_bp;	/* back ptr to buf, for RQS */
14127c478bd9Sstevel@tonic-gate 	uint_t	xb_sense_state;		/* scsi_pkt state of RQS command */
14137c478bd9Sstevel@tonic-gate 	ssize_t	xb_sense_resid;		/* residual of RQS command */
14147c478bd9Sstevel@tonic-gate 	uchar_t	xb_sense_status;	/* scsi status byte of RQS command */
14157c478bd9Sstevel@tonic-gate 	uchar_t	xb_sense_data[SENSE_LENGTH];	/* sense data from RQS cmd */
141630ab6db6Slh195018 	/*
141730ab6db6Slh195018 	 * Extra sense larger than SENSE_LENGTH will be allocated
141830ab6db6Slh195018 	 * right after xb_sense_data[SENSE_LENGTH]. Please do not
141930ab6db6Slh195018 	 * add any new field after it.
142030ab6db6Slh195018 	 */
14217c478bd9Sstevel@tonic-gate };
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per pkt", sd_xbuf))
14247c478bd9Sstevel@tonic-gate 
14257c478bd9Sstevel@tonic-gate #define	SD_PKT_ALLOC_SUCCESS			0
14267c478bd9Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE			1
14277c478bd9Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_NO_DMA		2
14287c478bd9Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_PKT_TOO_SMALL	3
14297c478bd9Sstevel@tonic-gate #define	SD_PKT_ALLOC_FAILURE_CDB_TOO_SMALL	4
14307c478bd9Sstevel@tonic-gate 
14317c478bd9Sstevel@tonic-gate #define	SD_GET_XBUF(bp)		((struct sd_xbuf *)((bp)->b_private))
14327c478bd9Sstevel@tonic-gate #define	SD_GET_UN(bp)		((SD_GET_XBUF(bp))->xb_un)
14337c478bd9Sstevel@tonic-gate #define	SD_GET_PKTP(bp)		((SD_GET_XBUF(bp))->xb_pktp)
14347c478bd9Sstevel@tonic-gate #define	SD_GET_BLKNO(bp)	((SD_GET_XBUF(bp))->xb_blkno)
14357c478bd9Sstevel@tonic-gate 
14367c478bd9Sstevel@tonic-gate /*
14377c478bd9Sstevel@tonic-gate  * Special-purpose struct for sd_send_scsi_cmd() to pass command-specific
14387c478bd9Sstevel@tonic-gate  * data through the layering chains to sd_initpkt_for_uscsi().
14397c478bd9Sstevel@tonic-gate  */
14407c478bd9Sstevel@tonic-gate struct sd_uscsi_info {
14417c478bd9Sstevel@tonic-gate 	int			ui_flags;
14427c478bd9Sstevel@tonic-gate 	struct uscsi_cmd	*ui_cmdp;
1443fa9e4066Sahrens 	/*
1444fa9e4066Sahrens 	 * ui_dkc is used by sd_send_scsi_SYNCHRONIZE_CACHE() to allow
1445fa9e4066Sahrens 	 * for async completion notification.
1446fa9e4066Sahrens 	 */
1447fa9e4066Sahrens 	struct dk_callback	ui_dkc;
14489e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	/*
14499e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	 * The following fields are to be used for FMA ereport generation.
14509e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	 */
14519e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uchar_t			ui_pkt_reason;
14529e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uint32_t		ui_pkt_state;
14539e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uint32_t		ui_pkt_statistics;
14549e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uint64_t		ui_lba;
14559e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	uint64_t		ui_ena;
14567c478bd9Sstevel@tonic-gate };
14577c478bd9Sstevel@tonic-gate 
14587c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_uscsi_info))
14597c478bd9Sstevel@tonic-gate 
14609e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
14619e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * This structure is used to issue 'internal' command sequences from the
14629e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * driver's attach(9E)/open(9E)/etc entry points. It provides a common context
14639e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * for issuing command sequences, with the ability to issue a command
14649e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * and provide expected/unexpected assessment of results at any code
14659e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * level within the sd_ssc_t scope and preserve the information needed
14669e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * produce telemetry for the problem, when needed, from a single
14679e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * outer-most-scope point.
14689e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
14699e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * The sd_ssc_t abstraction should result in well-structured code where
14709e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * the basic code structure is not jeprodized by future localized improvement.
14719e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
14729e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Scope for a sequence of commands.
14739e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Within a scoped sequence of commands, provides a single top-level
14749e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      location for initiating telementry generation from captured data.
14759e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Provide a common place to capture command execution data and driver
14769e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      assessment information for delivery to telemetry generation point.
14779e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Mechanism to get device-as-detector (dad) and transport telemetry
14789e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      information from interrupt context (sdintr) back to the internal
14799e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      command 'driver-assessment' code.
14809e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Ability to record assessment, and return information back to
14819e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      top-level telemetry generation code when an unexpected condition
14829e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      occurs.
14839e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  For code paths were an command itself was successful but
14849e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      the data returned looks suspect, the ability to record
14859e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      'unexpected data' conditions.
14869e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  Record assessment of issuing the command and interpreting
14879e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      the returned data for consumption by top-level ereport telemetry
14889e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      generation code.
14899e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   o  All data required to produce telemetry available off single data
14909e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *      structure.
14919e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
14929e1c849eSDavid Zhang - Sun Microsystems - Beijing China typedef struct {
14939e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	struct sd_lun		*ssc_un;
14949e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	struct uscsi_cmd	*ssc_uscsi_cmd;
14959e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	struct sd_uscsi_info	*ssc_uscsi_info;
14969e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	int			ssc_flags; /* Bits for flags */
1497c460faf0SXiao Raymond Li 	char			ssc_info[1024]; /* Buffer holding for info */
14989e1c849eSDavid Zhang - Sun Microsystems - Beijing China } sd_ssc_t;
14999e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15009e1c849eSDavid Zhang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", sd_ssc_t))
15019e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15029e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
15039e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * This struct switch different 'type-of-assessment'
15049e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * as an input argument for sd_ssc_assessment
15059e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15069e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15079e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * in sd_send_scsi_XXX or upper-level
15089e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15099e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FMT_IGNORE
15109e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   when send uscsi command failed, and
15119e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   the following code check sense data properly.
15129e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   we use 'ignore' to let sd_ssc_assessment
15139e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   trust current and do not do additional
15149e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   checking for the uscsi command.
15159e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15169e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FMT_IGNORE_COMPROMISE
15179e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   when send uscsi command failed, and
15189e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   the code does not check sense data or we don't
15199e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   think the checking is 100% coverage. We mark it
15209e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   as 'compromise' to indicate that we need to
15219e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   enhance current code in the future.
15229e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15239e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FMT_STATUS_CHECK
15249e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   when send uscsi command failed and cause sd entries
15259e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   failed finally, we need to send out real reason against
15269e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   status of uscsi command no matter if there is sense back
15279e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   or not.
15289e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *
15299e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FMT_STANDARD
15309e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   when send uscsi command succeeded, and
15319e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   the code does not check sense data, we need to check
15329e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   it to make sure there is no 'fault'.
15339e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
15349e1c849eSDavid Zhang - Sun Microsystems - Beijing China enum sd_type_assessment {
15359e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FMT_IGNORE = 0,
15369e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FMT_IGNORE_COMPROMISE,
15379e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FMT_STATUS_CHECK,
15389e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FMT_STANDARD
15399e1c849eSDavid Zhang - Sun Microsystems - Beijing China };
15409e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15419e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
15429e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * The following declaration are used as hints of severities when posting
15439e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * SCSI FMA ereport.
15449e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FM_DRV_FATAL
15459e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   When posting ereport with SD_FM_DRV_FATAL, the payload
15469e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   "driver-assessment" will be "fail" or "fatal" depending on the
15479e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   sense-key value. If driver-assessment is "fail", it will be
15489e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   propagated to an upset, otherwise, a fault will be propagated.
15499e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FM_DRV_RETRY
15509e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   When posting ereport with SD_FM_DRV_RETRY, the payload
15519e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   "driver-assessment" will be "retry", and it will be propagated to an
15529e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   upset.
15539e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FM_DRV_RECOVERY
15549e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   When posting ereport with SD_FM_DRV_RECOVERY, the payload
15559e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   "driver-assessment" will be "recovered", and it will be propagated to
15569e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   an upset.
15579e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * - SD_FM_DRV_NOTICE
15589e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   When posting ereport with SD_FM_DRV_NOTICE, the payload
15599e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   "driver-assessment" will be "info", and it will be propagated to an
15609e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *   upset.
15619e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
15629e1c849eSDavid Zhang - Sun Microsystems - Beijing China enum sd_driver_assessment {
15639e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FM_DRV_FATAL = 0,
15649e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FM_DRV_RETRY,
15659e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FM_DRV_RECOVERY,
15669e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	SD_FM_DRV_NOTICE
15679e1c849eSDavid Zhang - Sun Microsystems - Beijing China };
15689e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15699e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
15709e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * The following structure is used as a buffer when posting SCSI FMA
15719e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * ereport for raw i/o. It will be allocated per sd_lun when entering
15729e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * sd_unit_attach and will be deallocated when entering sd_unit_detach.
15739e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
15749e1c849eSDavid Zhang - Sun Microsystems - Beijing China struct sd_fm_internal {
15759e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	sd_ssc_t fm_ssc;
15769e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	struct uscsi_cmd fm_ucmd;
15779e1c849eSDavid Zhang - Sun Microsystems - Beijing China 	struct sd_uscsi_info fm_uinfo;
1578c460faf0SXiao Raymond Li 	int fm_log_level;
15799e1c849eSDavid Zhang - Sun Microsystems - Beijing China };
15809e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15819e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
15829e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * Bits in ssc_flags
15839e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * sd_ssc_init will mark ssc_flags = SSC_FLAGS_UNKNOWN
15849e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * sd_ssc_send will mark ssc_flags = SSC_FLAGS_CMD_ISSUED &
15859e1c849eSDavid Zhang - Sun Microsystems - Beijing China  *                                   SSC_FLAGS_NEED_ASSESSMENT
15869e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * sd_ssc_assessment will clear SSC_FLAGS_CMD_ISSUED and
15879e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * SSC_FLAGS_NEED_ASSESSMENT bits of ssc_flags.
15889e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * SSC_FLAGS_CMD_ISSUED is to indicate whether the SCSI command has been
15899e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * sent out.
15909e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * SSC_FLAGS_NEED_ASSESSMENT is to guarantee we will not miss any
15919e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * assessment point.
15929e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
15939e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_UNKNOWN		0x00000000
15949e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_CMD_ISSUED		0x00000001
15959e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_NEED_ASSESSMENT	0x00000002
15969e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_TRAN_ABORT		0x00000004
15979e1c849eSDavid Zhang - Sun Microsystems - Beijing China 
15989e1c849eSDavid Zhang - Sun Microsystems - Beijing China /*
15999e1c849eSDavid Zhang - Sun Microsystems - Beijing China  * The following bits in ssc_flags are for detecting unexpected data.
16009e1c849eSDavid Zhang - Sun Microsystems - Beijing China  */
16019e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_INVALID_PKT_REASON	0x00000010
16029e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_INVALID_STATUS	0x00000020
16039e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_INVALID_SENSE		0x00000040
16049e1c849eSDavid Zhang - Sun Microsystems - Beijing China #define		SSC_FLAGS_INVALID_DATA		0x00000080
16057c478bd9Sstevel@tonic-gate 
16067c478bd9Sstevel@tonic-gate /*
1607c460faf0SXiao Raymond Li  * The following are the values available for sd_fm_internal::fm_log_level.
1608c460faf0SXiao Raymond Li  * SD_FM_LOG_NSUP	The driver will log things in traditional way as if
1609c460faf0SXiao Raymond Li  * 			the SCSI FMA feature is unavailable.
1610c460faf0SXiao Raymond Li  * SD_FM_LOG_SILENT	The driver will not print out syslog for FMA error
1611c460faf0SXiao Raymond Li  * 			telemetry, all the error telemetries will go into
1612c460faf0SXiao Raymond Li  * 			FMA error log.
1613c460faf0SXiao Raymond Li  * SD_FM_LOG_EREPORT	The driver will both print the FMA error telemetry
1614c460faf0SXiao Raymond Li  * 			and post the error report, but the traditional
1615c460faf0SXiao Raymond Li  * 			syslog for error telemetry will be suppressed.
1616c460faf0SXiao Raymond Li  */
1617c460faf0SXiao Raymond Li #define		SD_FM_LOG_NSUP		0
1618c460faf0SXiao Raymond Li #define		SD_FM_LOG_SILENT	1
1619c460faf0SXiao Raymond Li #define		SD_FM_LOG_EREPORT	2
1620c460faf0SXiao Raymond Li 
1621c460faf0SXiao Raymond Li /*
16227c478bd9Sstevel@tonic-gate  * Macros and definitions for driver kstats and errstats
16237c478bd9Sstevel@tonic-gate  *
16247c478bd9Sstevel@tonic-gate  * Some third-party layered drivers (they know who they are) do not maintain
16257c478bd9Sstevel@tonic-gate  * their open/close counts correctly which causes our kstat reporting to get
16267c478bd9Sstevel@tonic-gate  * messed up & results in panics. These macros will update the driver kstats
16277c478bd9Sstevel@tonic-gate  * only if the counts are valid.
16287c478bd9Sstevel@tonic-gate  */
16297c478bd9Sstevel@tonic-gate #define	SD_UPDATE_COMMON_KSTATS(kstat_function, kstatp)			\
16307c478bd9Sstevel@tonic-gate 	if ((kstat_function)  == kstat_runq_exit ||			\
16317c478bd9Sstevel@tonic-gate 	    ((kstat_function) == kstat_runq_back_to_waitq)) { 		\
16327c478bd9Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->rcnt) {			\
16337c478bd9Sstevel@tonic-gate 			kstat_function((kstatp));			\
16347c478bd9Sstevel@tonic-gate 		} else {						\
16357c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
16367c478bd9Sstevel@tonic-gate 		"kstat rcnt == 0 when exiting runq, please check\n");	\
16377c478bd9Sstevel@tonic-gate 		}							\
16387c478bd9Sstevel@tonic-gate 	} else if ((kstat_function) == kstat_waitq_exit ||		\
16397c478bd9Sstevel@tonic-gate 	    ((kstat_function) == kstat_waitq_to_runq)) {		\
16407c478bd9Sstevel@tonic-gate 		if (((kstat_io_t *)(kstatp))->wcnt) {			\
16417c478bd9Sstevel@tonic-gate 			kstat_function(kstatp);				\
16427c478bd9Sstevel@tonic-gate 		} else {						\
16437c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,				\
16447c478bd9Sstevel@tonic-gate 		"kstat wcnt == 0 when exiting waitq, please check\n");	\
16457c478bd9Sstevel@tonic-gate 		}							\
16467c478bd9Sstevel@tonic-gate 	} else {							\
16477c478bd9Sstevel@tonic-gate 		kstat_function(kstatp);					\
16487c478bd9Sstevel@tonic-gate 	}
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate #define	SD_UPDATE_KSTATS(un, kstat_function, bp)			\
16517c478bd9Sstevel@tonic-gate 	ASSERT(SD_GET_XBUF(bp) != NULL);				\
16527c478bd9Sstevel@tonic-gate 	if (SD_IS_BUFIO(SD_GET_XBUF(bp))) {				\
16537c478bd9Sstevel@tonic-gate 		struct kstat *pksp =					\
16547c478bd9Sstevel@tonic-gate 			(un)->un_pstats[SDPART((bp)->b_edev)];		\
16557c478bd9Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
16567c478bd9Sstevel@tonic-gate 		if ((un)->un_stats != NULL) {				\
16577c478bd9Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);	\
16587c478bd9Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
16597c478bd9Sstevel@tonic-gate 		}							\
16607c478bd9Sstevel@tonic-gate 		if (pksp != NULL) {					\
16617c478bd9Sstevel@tonic-gate 			kstat_io_t *kip = KSTAT_IO_PTR(pksp);		\
16627c478bd9Sstevel@tonic-gate 			SD_UPDATE_COMMON_KSTATS(kstat_function, kip);	\
16637c478bd9Sstevel@tonic-gate 		}							\
16647c478bd9Sstevel@tonic-gate 	}
16657c478bd9Sstevel@tonic-gate 
16667c478bd9Sstevel@tonic-gate #define	SD_UPDATE_ERRSTATS(un, x)					\
16677c478bd9Sstevel@tonic-gate 	if ((un)->un_errstats != NULL) {				\
16687c478bd9Sstevel@tonic-gate 		struct sd_errstats *stp;				\
16697c478bd9Sstevel@tonic-gate 		ASSERT(mutex_owned(SD_MUTEX(un)));			\
16707c478bd9Sstevel@tonic-gate 		stp = (struct sd_errstats *)(un)->un_errstats->ks_data;	\
16717c478bd9Sstevel@tonic-gate 		stp->x.value.ui32++;					\
16727c478bd9Sstevel@tonic-gate 	}
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate #define	SD_UPDATE_RDWR_STATS(un, bp)					\
16757c478bd9Sstevel@tonic-gate 	if ((un)->un_stats != NULL) {					\
16767c478bd9Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR((un)->un_stats);		\
16777c478bd9Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
16787c478bd9Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
16797c478bd9Sstevel@tonic-gate 			kip->reads++;					\
16807c478bd9Sstevel@tonic-gate 			kip->nread += n_done;				\
16817c478bd9Sstevel@tonic-gate 		} else {						\
16827c478bd9Sstevel@tonic-gate 			kip->writes++;					\
16837c478bd9Sstevel@tonic-gate 			kip->nwritten += n_done;			\
16847c478bd9Sstevel@tonic-gate 		}							\
16857c478bd9Sstevel@tonic-gate 	}
16867c478bd9Sstevel@tonic-gate 
16877c478bd9Sstevel@tonic-gate #define	SD_UPDATE_PARTITION_STATS(un, bp)				\
16887c478bd9Sstevel@tonic-gate {									\
16897c478bd9Sstevel@tonic-gate 	struct kstat *pksp = (un)->un_pstats[SDPART((bp)->b_edev)];	\
16907c478bd9Sstevel@tonic-gate 	if (pksp != NULL) {						\
16917c478bd9Sstevel@tonic-gate 		kstat_io_t *kip = KSTAT_IO_PTR(pksp);			\
16927c478bd9Sstevel@tonic-gate 		size_t n_done = (bp)->b_bcount - (bp)->b_resid;		\
16937c478bd9Sstevel@tonic-gate 		if ((bp)->b_flags & B_READ) {				\
16947c478bd9Sstevel@tonic-gate 			kip->reads++;					\
16957c478bd9Sstevel@tonic-gate 			kip->nread += n_done;				\
16967c478bd9Sstevel@tonic-gate 		} else {						\
16977c478bd9Sstevel@tonic-gate 			kip->writes++;					\
16987c478bd9Sstevel@tonic-gate 			kip->nwritten += n_done;			\
16997c478bd9Sstevel@tonic-gate 		}							\
17007c478bd9Sstevel@tonic-gate 	}								\
17017c478bd9Sstevel@tonic-gate }
17027c478bd9Sstevel@tonic-gate 
17037c478bd9Sstevel@tonic-gate 
17047c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
17057c478bd9Sstevel@tonic-gate 
17067c478bd9Sstevel@tonic-gate 
17077c478bd9Sstevel@tonic-gate /*
17087c478bd9Sstevel@tonic-gate  * 60 seconds is a *very* reasonable amount of time for most slow CD
17097c478bd9Sstevel@tonic-gate  * operations.
17107c478bd9Sstevel@tonic-gate  */
17117c478bd9Sstevel@tonic-gate #define	SD_IO_TIME			60
17127c478bd9Sstevel@tonic-gate 
17137c478bd9Sstevel@tonic-gate /*
17147c478bd9Sstevel@tonic-gate  * 2 hours is an excessively reasonable amount of time for format operations.
17157c478bd9Sstevel@tonic-gate  */
17167c478bd9Sstevel@tonic-gate #define	SD_FMT_TIME			(120 * 60)
17177c478bd9Sstevel@tonic-gate 
17187c478bd9Sstevel@tonic-gate /*
17197c478bd9Sstevel@tonic-gate  * 5 seconds is what we'll wait if we get a Busy Status back
17207c478bd9Sstevel@tonic-gate  */
17217c478bd9Sstevel@tonic-gate #define	SD_BSY_TIMEOUT			(drv_usectohz(5 * 1000000))
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate /*
17247c478bd9Sstevel@tonic-gate  * 100 msec. is what we'll wait if we get Unit Attention.
17257c478bd9Sstevel@tonic-gate  */
17267c478bd9Sstevel@tonic-gate #define	SD_UA_RETRY_DELAY		(drv_usectohz((clock_t)100000))
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate /*
17297c478bd9Sstevel@tonic-gate  * 100 msec. is what we'll wait for restarted commands.
17307c478bd9Sstevel@tonic-gate  */
17317c478bd9Sstevel@tonic-gate #define	SD_RESTART_TIMEOUT		(drv_usectohz((clock_t)100000))
17327c478bd9Sstevel@tonic-gate 
17337c478bd9Sstevel@tonic-gate /*
173465908c77Syu, larry liu - Sun Microsystems - Beijing China  * 10s misaligned I/O warning message interval
173565908c77Syu, larry liu - Sun Microsystems - Beijing China  */
173665908c77Syu, larry liu - Sun Microsystems - Beijing China #define	SD_RMW_MSG_PRINT_TIMEOUT	(drv_usectohz((clock_t)10000000))
173765908c77Syu, larry liu - Sun Microsystems - Beijing China 
173865908c77Syu, larry liu - Sun Microsystems - Beijing China /*
17397c478bd9Sstevel@tonic-gate  * 100 msec. is what we'll wait for certain retries for fibre channel
17407c478bd9Sstevel@tonic-gate  * targets, 0 msec for parallel SCSI.
17417c478bd9Sstevel@tonic-gate  */
17427c478bd9Sstevel@tonic-gate #if defined(__fibre)
17437c478bd9Sstevel@tonic-gate #define	SD_RETRY_DELAY			(drv_usectohz(100000))
17447c478bd9Sstevel@tonic-gate #else
17457c478bd9Sstevel@tonic-gate #define	SD_RETRY_DELAY			((clock_t)0)
17467c478bd9Sstevel@tonic-gate #endif
17477c478bd9Sstevel@tonic-gate 
17487c478bd9Sstevel@tonic-gate /*
17497c478bd9Sstevel@tonic-gate  * Number of times we'll retry a normal operation.
17507c478bd9Sstevel@tonic-gate  *
17517c478bd9Sstevel@tonic-gate  * This includes retries due to transport failure
17527c478bd9Sstevel@tonic-gate  * (need to distinguish between Target and Transport failure)
17537c478bd9Sstevel@tonic-gate  *
17547c478bd9Sstevel@tonic-gate  */
17557c478bd9Sstevel@tonic-gate #if defined(__fibre)
17567c478bd9Sstevel@tonic-gate #define	SD_RETRY_COUNT			3
17577c478bd9Sstevel@tonic-gate #else
17587c478bd9Sstevel@tonic-gate #define	SD_RETRY_COUNT			5
17597c478bd9Sstevel@tonic-gate #endif
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate /*
17627c478bd9Sstevel@tonic-gate  * Number of times we will retry for unit attention.
17637c478bd9Sstevel@tonic-gate  */
17647c478bd9Sstevel@tonic-gate #define	SD_UA_RETRY_COUNT		600
17657c478bd9Sstevel@tonic-gate 
17667c478bd9Sstevel@tonic-gate #define	SD_VICTIM_RETRY_COUNT(un)	(un->un_victim_retry_count)
17677c478bd9Sstevel@tonic-gate #define	CD_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count * 2)
17687c478bd9Sstevel@tonic-gate #define	DISK_NOT_READY_RETRY_COUNT(un)	(un->un_retry_count / 2)
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate /*
17727c478bd9Sstevel@tonic-gate  * Maximum number of units we can support
17737c478bd9Sstevel@tonic-gate  * (controlled by room in minor device byte)
17747c478bd9Sstevel@tonic-gate  *
17757c478bd9Sstevel@tonic-gate  * Note: this value is out of date.
17767c478bd9Sstevel@tonic-gate  */
17777c478bd9Sstevel@tonic-gate #define	SD_MAXUNIT			32
17787c478bd9Sstevel@tonic-gate 
17797c478bd9Sstevel@tonic-gate /*
17807c478bd9Sstevel@tonic-gate  * 30 seconds is what we will wait for the IO to finish
17817c478bd9Sstevel@tonic-gate  * before we fail the DDI_SUSPEND
17827c478bd9Sstevel@tonic-gate  */
17837c478bd9Sstevel@tonic-gate #define	SD_WAIT_CMDS_COMPLETE		30
17847c478bd9Sstevel@tonic-gate 
17857c478bd9Sstevel@tonic-gate /*
17867c478bd9Sstevel@tonic-gate  * Prevent/allow media removal flags
17877c478bd9Sstevel@tonic-gate  */
17887c478bd9Sstevel@tonic-gate #define	SD_REMOVAL_ALLOW		0
17897c478bd9Sstevel@tonic-gate #define	SD_REMOVAL_PREVENT		1
17907c478bd9Sstevel@tonic-gate 
17917c478bd9Sstevel@tonic-gate 
17927c478bd9Sstevel@tonic-gate /*
17937c478bd9Sstevel@tonic-gate  * Drive Types (and characteristics)
17947c478bd9Sstevel@tonic-gate  */
17957c478bd9Sstevel@tonic-gate #define	VIDMAX				8
17967c478bd9Sstevel@tonic-gate #define	PIDMAX				16
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 
17997c478bd9Sstevel@tonic-gate /*
18007c478bd9Sstevel@tonic-gate  * The following #defines and type definitions for the property
18017c478bd9Sstevel@tonic-gate  * processing component of the sd driver.
18027c478bd9Sstevel@tonic-gate  */
18037c478bd9Sstevel@tonic-gate 
18047c478bd9Sstevel@tonic-gate 
18057c478bd9Sstevel@tonic-gate /* Miscellaneous Definitions */
18067c478bd9Sstevel@tonic-gate #define	SD_CONF_VERSION_1		1
18077c478bd9Sstevel@tonic-gate #define	SD_CONF_NOT_USED		32
18087c478bd9Sstevel@tonic-gate 
18097c478bd9Sstevel@tonic-gate /*
18102ee4dfc7SJane Chu  * "pm-capable" property values and macros
18117c478bd9Sstevel@tonic-gate  */
18127c478bd9Sstevel@tonic-gate #define	SD_PM_CAPABLE_UNDEFINED		-1
18132ee4dfc7SJane Chu 
18142ee4dfc7SJane Chu #define	SD_PM_CAPABLE_IS_UNDEFINED(pm_cap)	\
18152ee4dfc7SJane Chu 	(pm_cap == SD_PM_CAPABLE_UNDEFINED)
18162ee4dfc7SJane Chu 
18172ee4dfc7SJane Chu #define	SD_PM_CAPABLE_IS_FALSE(pm_cap)	\
18182ee4dfc7SJane Chu 	((pm_cap & PM_CAPABLE_PM_MASK) == 0)
18192ee4dfc7SJane Chu 
18202ee4dfc7SJane Chu #define	SD_PM_CAPABLE_IS_TRUE(pm_cap)	\
18212ee4dfc7SJane Chu 	(!SD_PM_CAPABLE_IS_UNDEFINED(pm_cap) && \
18222ee4dfc7SJane Chu 	    ((pm_cap & PM_CAPABLE_PM_MASK) > 0))
18232ee4dfc7SJane Chu 
18242ee4dfc7SJane Chu #define	SD_PM_CAPABLE_IS_SPC_4(pm_cap)	\
18252ee4dfc7SJane Chu 	((pm_cap & PM_CAPABLE_PM_MASK) == PM_CAPABLE_SPC4)
18262ee4dfc7SJane Chu 
18272ee4dfc7SJane Chu #define	SD_PM_CAP_LOG_SUPPORTED(pm_cap)	\
18282ee4dfc7SJane Chu 	((pm_cap & PM_CAPABLE_LOG_SUPPORTED) ? TRUE : FALSE)
18292ee4dfc7SJane Chu 
18302ee4dfc7SJane Chu #define	SD_PM_CAP_SMART_LOG(pm_cap)	\
18312ee4dfc7SJane Chu 	((pm_cap & PM_CAPABLE_SMART_LOG) ? TRUE : FALSE)
18327c478bd9Sstevel@tonic-gate 
18337c478bd9Sstevel@tonic-gate /*
18347c478bd9Sstevel@tonic-gate  * Property data values used in static configuration table
18357c478bd9Sstevel@tonic-gate  * These are all based on device characteristics.
18367c478bd9Sstevel@tonic-gate  * For fibre channel devices, the throttle value is usually
18377c478bd9Sstevel@tonic-gate  * derived from the devices cmd Q depth divided by the number
18387c478bd9Sstevel@tonic-gate  * of supported initiators.
18397c478bd9Sstevel@tonic-gate  */
18407c478bd9Sstevel@tonic-gate #define	ELITE_THROTTLE_VALUE		10
18417c478bd9Sstevel@tonic-gate #define	SEAGATE_THROTTLE_VALUE		15
18427c478bd9Sstevel@tonic-gate #define	IBM_THROTTLE_VALUE		15
18437c478bd9Sstevel@tonic-gate #define	ST31200N_THROTTLE_VALUE		8
18447c478bd9Sstevel@tonic-gate #define	FUJITSU_THROTTLE_VALUE		15
18457c478bd9Sstevel@tonic-gate #define	SYMBIOS_THROTTLE_VALUE		16
18467c478bd9Sstevel@tonic-gate #define	SYMBIOS_NOTREADY_RETRIES	24
18477c478bd9Sstevel@tonic-gate #define	LSI_THROTTLE_VALUE		16
18487c478bd9Sstevel@tonic-gate #define	LSI_NOTREADY_RETRIES		24
18497c478bd9Sstevel@tonic-gate #define	LSI_OEM_NOTREADY_RETRIES	36
18507c478bd9Sstevel@tonic-gate #define	PURPLE_THROTTLE_VALUE		64
18517c478bd9Sstevel@tonic-gate #define	PURPLE_BUSY_RETRIES		60
18527c478bd9Sstevel@tonic-gate #define	PURPLE_RESET_RETRY_COUNT	36
18537c478bd9Sstevel@tonic-gate #define	PURPLE_RESERVE_RELEASE_TIME	60
18547c478bd9Sstevel@tonic-gate #define	SVE_BUSY_RETRIES		60
18557c478bd9Sstevel@tonic-gate #define	SVE_RESET_RETRY_COUNT		36
18567c478bd9Sstevel@tonic-gate #define	SVE_RESERVE_RELEASE_TIME	60
18577c478bd9Sstevel@tonic-gate #define	SVE_THROTTLE_VALUE		10
18587c478bd9Sstevel@tonic-gate #define	SVE_MIN_THROTTLE_VALUE		2
18597c478bd9Sstevel@tonic-gate #define	SVE_DISKSORT_DISABLED_FLAG	1
18607c478bd9Sstevel@tonic-gate #define	MASERATI_DISKSORT_DISABLED_FLAG	1
18617c478bd9Sstevel@tonic-gate #define	MASERATI_LUN_RESET_ENABLED_FLAG	1
18627c478bd9Sstevel@tonic-gate #define	PIRUS_THROTTLE_VALUE		64
18637c478bd9Sstevel@tonic-gate #define	PIRUS_NRR_COUNT			60
18647c478bd9Sstevel@tonic-gate #define	PIRUS_BUSY_RETRIES		60
18657c478bd9Sstevel@tonic-gate #define	PIRUS_RESET_RETRY_COUNT		36
18667c478bd9Sstevel@tonic-gate #define	PIRUS_MIN_THROTTLE_VALUE	16
18677c478bd9Sstevel@tonic-gate #define	PIRUS_DISKSORT_DISABLED_FLAG	0
18687c478bd9Sstevel@tonic-gate #define	PIRUS_LUN_RESET_ENABLED_FLAG	1
18697c478bd9Sstevel@tonic-gate 
18707c478bd9Sstevel@tonic-gate /*
18717c478bd9Sstevel@tonic-gate  * Driver Property Bit Flag definitions
18727c478bd9Sstevel@tonic-gate  *
187330a83a24Scth  * Unfortunately, for historical reasons, the bit-flag definitions are
18747c478bd9Sstevel@tonic-gate  * different on SPARC, INTEL, & FIBRE platforms.
18757c478bd9Sstevel@tonic-gate  */
18767c478bd9Sstevel@tonic-gate 
18777c478bd9Sstevel@tonic-gate /*
18787c478bd9Sstevel@tonic-gate  * Bit flag telling driver to set throttle from sd.conf sd-config-list
18797c478bd9Sstevel@tonic-gate  * and driver table.
18807c478bd9Sstevel@tonic-gate  *
18817c478bd9Sstevel@tonic-gate  * The max throttle (q-depth) property implementation is for support of
18827c478bd9Sstevel@tonic-gate  * fibre channel devices that can drop an i/o request when a queue fills
18837c478bd9Sstevel@tonic-gate  * up. The number of commands sent to the disk from this driver is
18847c478bd9Sstevel@tonic-gate  * regulated such that queue overflows are avoided.
18857c478bd9Sstevel@tonic-gate  */
18867c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_THROTTLE		0
18877c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_THROTTLE		(1 << SD_CONF_SET_THROTTLE)
18887c478bd9Sstevel@tonic-gate 
18897c478bd9Sstevel@tonic-gate /*
18907c478bd9Sstevel@tonic-gate  * Bit flag telling driver to set the controller type from sd.conf
18917c478bd9Sstevel@tonic-gate  * sd-config-list and driver table.
18927c478bd9Sstevel@tonic-gate  */
18937c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
18947c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
18957c478bd9Sstevel@tonic-gate #elif defined(__fibre)
18967c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		5
18977c478bd9Sstevel@tonic-gate #else
18987c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_CTYPE		1
18997c478bd9Sstevel@tonic-gate #endif
19007c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_CTYPE		(1 << SD_CONF_SET_CTYPE)
19017c478bd9Sstevel@tonic-gate 
19027c478bd9Sstevel@tonic-gate /*
19037c478bd9Sstevel@tonic-gate  * Bit flag telling driver to set the not ready retry count for a device from
19047c478bd9Sstevel@tonic-gate  * sd.conf sd-config-list and driver table.
19057c478bd9Sstevel@tonic-gate  */
19067c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19077c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	10
19087c478bd9Sstevel@tonic-gate #elif defined(__fibre)
19097c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	1
19107c478bd9Sstevel@tonic-gate #else
19117c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NOTREADY_RETRIES	2
19127c478bd9Sstevel@tonic-gate #endif
19137c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_NRR_COUNT		(1 << SD_CONF_SET_NOTREADY_RETRIES)
19147c478bd9Sstevel@tonic-gate 
19157c478bd9Sstevel@tonic-gate /*
19167c478bd9Sstevel@tonic-gate  * Bit flag telling driver to set SCSI status BUSY Retries from sd.conf
19177c478bd9Sstevel@tonic-gate  * sd-config-list and driver table.
19187c478bd9Sstevel@tonic-gate  */
19197c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19207c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	11
19217c478bd9Sstevel@tonic-gate #elif defined(__fibre)
19227c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	2
19237c478bd9Sstevel@tonic-gate #else
19247c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_BUSY_RETRIES 	5
19257c478bd9Sstevel@tonic-gate #endif
19267c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_BSY_RETRY_COUNT	(1 << SD_CONF_SET_BUSY_RETRIES)
19277c478bd9Sstevel@tonic-gate 
19287c478bd9Sstevel@tonic-gate /*
19297c478bd9Sstevel@tonic-gate  * Bit flag telling driver that device does not have a valid/unique serial
19307c478bd9Sstevel@tonic-gate  * number.
19317c478bd9Sstevel@tonic-gate  */
19327c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19337c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		2
19347c478bd9Sstevel@tonic-gate #else
19357c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_FAB_DEVID		3
19367c478bd9Sstevel@tonic-gate #endif
19377c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_FAB_DEVID   	(1 << SD_CONF_SET_FAB_DEVID)
19387c478bd9Sstevel@tonic-gate 
19397c478bd9Sstevel@tonic-gate /*
19407c478bd9Sstevel@tonic-gate  * Bit flag telling driver to disable all caching for disk device.
19417c478bd9Sstevel@tonic-gate  */
19427c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19437c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		3
19447c478bd9Sstevel@tonic-gate #else
19457c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NOCACHE		4
19467c478bd9Sstevel@tonic-gate #endif
19477c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_NOCACHE		(1 << SD_CONF_SET_NOCACHE)
19487c478bd9Sstevel@tonic-gate 
19497c478bd9Sstevel@tonic-gate /*
19507c478bd9Sstevel@tonic-gate  * Bit flag telling driver that the PLAY AUDIO command requires parms in BCD
19517c478bd9Sstevel@tonic-gate  * format rather than binary.
19527c478bd9Sstevel@tonic-gate  */
19537c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19547c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		4
19557c478bd9Sstevel@tonic-gate #else
19567c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_PLAYMSF_BCD		6
19577c478bd9Sstevel@tonic-gate #endif
19587c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_PLAYMSF_BCD    	(1 << SD_CONF_SET_PLAYMSF_BCD)
19597c478bd9Sstevel@tonic-gate 
19607c478bd9Sstevel@tonic-gate /*
19617c478bd9Sstevel@tonic-gate  * Bit flag telling driver that the response from the READ SUBCHANNEL command
19627c478bd9Sstevel@tonic-gate  * has BCD fields rather than binary.
19637c478bd9Sstevel@tonic-gate  */
19647c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19657c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		5
19667c478bd9Sstevel@tonic-gate #else
19677c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READSUB_BCD		7
19687c478bd9Sstevel@tonic-gate #endif
19697c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_READSUB_BCD	(1 << SD_CONF_SET_READSUB_BCD)
19707c478bd9Sstevel@tonic-gate 
19717c478bd9Sstevel@tonic-gate /*
19727c478bd9Sstevel@tonic-gate  * Bit in flags telling driver that the track number fields in the READ TOC
19737c478bd9Sstevel@tonic-gate  * request and respone are in BCD rather than binary.
19747c478bd9Sstevel@tonic-gate  */
19757c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19767c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	6
19777c478bd9Sstevel@tonic-gate #else
19787c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_TRK_BCD	8
19797c478bd9Sstevel@tonic-gate #endif
19807c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_TRK_BCD	(1 << SD_CONF_SET_READ_TOC_TRK_BCD)
19817c478bd9Sstevel@tonic-gate 
19827c478bd9Sstevel@tonic-gate /*
19837c478bd9Sstevel@tonic-gate  * Bit flag telling driver that the address fields in the READ TOC request and
19847c478bd9Sstevel@tonic-gate  * respone are in BCD rather than binary.
19857c478bd9Sstevel@tonic-gate  */
19867c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19877c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	7
19887c478bd9Sstevel@tonic-gate #else
19897c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_TOC_ADDR_BCD	9
19907c478bd9Sstevel@tonic-gate #endif
19917c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_READ_TOC_ADDR_BCD	(1 << SD_CONF_SET_READ_TOC_ADDR_BCD)
19927c478bd9Sstevel@tonic-gate 
19937c478bd9Sstevel@tonic-gate /*
19947c478bd9Sstevel@tonic-gate  * Bit flag telling the driver that the device doesn't support the READ HEADER
19957c478bd9Sstevel@tonic-gate  * command.
19967c478bd9Sstevel@tonic-gate  */
19977c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
19987c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	8
19997c478bd9Sstevel@tonic-gate #else
20007c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_NO_READ_HEADER	10
20017c478bd9Sstevel@tonic-gate #endif
20027c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_NO_READ_HEADER 	(1 << SD_CONF_SET_NO_READ_HEADER)
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate /*
20057c478bd9Sstevel@tonic-gate  * Bit flag telling the driver that for the READ CD command the device uses
20067c478bd9Sstevel@tonic-gate  * opcode 0xd4 rather than 0xbe.
20077c478bd9Sstevel@tonic-gate  */
20087c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
20097c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4		9
20107c478bd9Sstevel@tonic-gate #else
20117c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_READ_CD_XD4 	11
20127c478bd9Sstevel@tonic-gate #endif
20137c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_READ_CD_XD4	(1 << SD_CONF_SET_READ_CD_XD4)
20147c478bd9Sstevel@tonic-gate 
20157c478bd9Sstevel@tonic-gate /*
20167c478bd9Sstevel@tonic-gate  * Bit flag telling the driver to set SCSI status Reset Retries
20177c478bd9Sstevel@tonic-gate  * (un_reset_retry_count) from sd.conf sd-config-list and driver table (4356701)
20187c478bd9Sstevel@tonic-gate  */
20197c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_RST_RETRIES		12
20207c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_RST_RETRIES	(1 << SD_CONF_SET_RST_RETRIES)
20217c478bd9Sstevel@tonic-gate 
20227c478bd9Sstevel@tonic-gate /*
20237c478bd9Sstevel@tonic-gate  * Bit flag telling the driver to set the reservation release timeout value
20247c478bd9Sstevel@tonic-gate  * from sd.conf sd-config-list and driver table. (4367306)
20257c478bd9Sstevel@tonic-gate  */
20267c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_RSV_REL_TIME	13
20277c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_RSV_REL_TIME	(1 << SD_CONF_SET_RSV_REL_TIME)
20287c478bd9Sstevel@tonic-gate 
20297c478bd9Sstevel@tonic-gate /*
20307c478bd9Sstevel@tonic-gate  * Bit flag telling the driver to verify that no commands are pending for a
20317c478bd9Sstevel@tonic-gate  * device before issuing a Test Unit Ready. This is a fw workaround for Seagate
20327c478bd9Sstevel@tonic-gate  * eliteI drives. (4392016)
20337c478bd9Sstevel@tonic-gate  */
20347c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_TUR_CHECK		14
20357c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_TUR_CHECK		(1 << SD_CONF_SET_TUR_CHECK)
20367c478bd9Sstevel@tonic-gate 
20377c478bd9Sstevel@tonic-gate /*
20387c478bd9Sstevel@tonic-gate  * Bit in flags telling driver to set min. throttle from ssd.conf
20397c478bd9Sstevel@tonic-gate  * ssd-config-list and driver table.
20407c478bd9Sstevel@tonic-gate  */
20417c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_MIN_THROTTLE	15
20427c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_MIN_THROTTLE	(1 << SD_CONF_SET_MIN_THROTTLE)
20437c478bd9Sstevel@tonic-gate 
20447c478bd9Sstevel@tonic-gate /*
20457c478bd9Sstevel@tonic-gate  * Bit in flags telling driver to set disksort disable flag from ssd.conf
20467c478bd9Sstevel@tonic-gate  * ssd-config-list and driver table.
20477c478bd9Sstevel@tonic-gate  */
20487c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_DISKSORT_DISABLED	16
20497c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_DISKSORT_DISABLED	(1 << SD_CONF_SET_DISKSORT_DISABLED)
20507c478bd9Sstevel@tonic-gate 
20517c478bd9Sstevel@tonic-gate /*
20527c478bd9Sstevel@tonic-gate  * Bit in flags telling driver to set LUN Reset enable flag from [s]sd.conf
20537c478bd9Sstevel@tonic-gate  * [s]sd-config-list and driver table.
20547c478bd9Sstevel@tonic-gate  */
20557c478bd9Sstevel@tonic-gate #define	SD_CONF_SET_LUN_RESET_ENABLED	17
20567c478bd9Sstevel@tonic-gate #define	SD_CONF_BSET_LUN_RESET_ENABLED	(1 << SD_CONF_SET_LUN_RESET_ENABLED)
20577c478bd9Sstevel@tonic-gate 
20587c478bd9Sstevel@tonic-gate /*
2059a84224b3Sgz161490  * Bit in flags telling driver that the write cache on the device is
2060a84224b3Sgz161490  * non-volatile.
2061a84224b3Sgz161490  */
2062a84224b3Sgz161490 #define	SD_CONF_SET_CACHE_IS_NV	18
2063a84224b3Sgz161490 #define	SD_CONF_BSET_CACHE_IS_NV	(1 << SD_CONF_SET_CACHE_IS_NV)
2064a84224b3Sgz161490 
2065a84224b3Sgz161490 /*
20662ee4dfc7SJane Chu  * Bit in flags telling driver that the power condition flag from [s]sd.conf
20672ee4dfc7SJane Chu  * [s]sd-config-list and driver table.
20682ee4dfc7SJane Chu  */
20692ee4dfc7SJane Chu #define	SD_CONF_SET_PC_DISABLED	19
20702ee4dfc7SJane Chu #define	SD_CONF_BSET_PC_DISABLED	(1 << SD_CONF_SET_PC_DISABLED)
20712ee4dfc7SJane Chu 
20722ee4dfc7SJane Chu /*
20737c478bd9Sstevel@tonic-gate  * This is the number of items currently settable in the sd.conf
20747c478bd9Sstevel@tonic-gate  * sd-config-list.  The mask value is defined for parameter checking. The
20757c478bd9Sstevel@tonic-gate  * item count and mask should be updated when new properties are added.
20767c478bd9Sstevel@tonic-gate  */
2077a84224b3Sgz161490 #define	SD_CONF_MAX_ITEMS		19
2078a84224b3Sgz161490 #define	SD_CONF_BIT_MASK		0x0007FFFF
20797c478bd9Sstevel@tonic-gate 
20807c478bd9Sstevel@tonic-gate typedef struct {
20817c478bd9Sstevel@tonic-gate 	int sdt_throttle;
20827c478bd9Sstevel@tonic-gate 	int sdt_ctype;
20837c478bd9Sstevel@tonic-gate 	int sdt_not_rdy_retries;
20847c478bd9Sstevel@tonic-gate 	int sdt_busy_retries;
20857c478bd9Sstevel@tonic-gate 	int sdt_reset_retries;
20867c478bd9Sstevel@tonic-gate 	int sdt_reserv_rel_time;
20877c478bd9Sstevel@tonic-gate 	int sdt_min_throttle;
20887c478bd9Sstevel@tonic-gate 	int sdt_disk_sort_dis;
20897c478bd9Sstevel@tonic-gate 	int sdt_lun_reset_enable;
2090a84224b3Sgz161490 	int sdt_suppress_cache_flush;
20912ee4dfc7SJane Chu 	int sdt_power_condition_dis;
20927c478bd9Sstevel@tonic-gate } sd_tunables;
20937c478bd9Sstevel@tonic-gate 
20947c478bd9Sstevel@tonic-gate /* Type definition for static configuration table entries */
20957c478bd9Sstevel@tonic-gate typedef struct sd_disk_config {
20967c478bd9Sstevel@tonic-gate 	char	device_id[25];
20977c478bd9Sstevel@tonic-gate 	uint_t	flags;
20987c478bd9Sstevel@tonic-gate 	sd_tunables *properties;
20997c478bd9Sstevel@tonic-gate } sd_disk_config_t;
21007c478bd9Sstevel@tonic-gate 
21017c478bd9Sstevel@tonic-gate /*
21022ee4dfc7SJane Chu  * first 2 bits of byte 4 options for 1bh command
21037c478bd9Sstevel@tonic-gate  */
21047c478bd9Sstevel@tonic-gate #define	SD_TARGET_STOP			0x00
21057c478bd9Sstevel@tonic-gate #define	SD_TARGET_START			0x01
21067c478bd9Sstevel@tonic-gate #define	SD_TARGET_EJECT			0x02
21077c478bd9Sstevel@tonic-gate #define	SD_TARGET_CLOSE			0x03
21087c478bd9Sstevel@tonic-gate 
21092ee4dfc7SJane Chu /*
21102ee4dfc7SJane Chu  * power condition of byte 4 for 1bh command
21112ee4dfc7SJane Chu  */
21122ee4dfc7SJane Chu #define	SD_TARGET_START_VALID		0x00
21132ee4dfc7SJane Chu #define	SD_TARGET_ACTIVE		0x01
21142ee4dfc7SJane Chu #define	SD_TARGET_IDLE			0x02
21152ee4dfc7SJane Chu #define	SD_TARGET_STANDBY		0x03
21162ee4dfc7SJane Chu 
21177c478bd9Sstevel@tonic-gate 
21187c478bd9Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_CODE	0x03
21197c478bd9Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_CODE	0x04
21207c478bd9Sstevel@tonic-gate 
21217c478bd9Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE3_LENGTH					\
21227c478bd9Sstevel@tonic-gate 	(sizeof (struct mode_format) + MODE_PARAM_LENGTH)
21237c478bd9Sstevel@tonic-gate #define	SD_MODE_SENSE_PAGE4_LENGTH					\
21247c478bd9Sstevel@tonic-gate 	(sizeof (struct mode_geometry) + MODE_PARAM_LENGTH)
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate /*
21277c478bd9Sstevel@tonic-gate  * These command codes need to be moved to sys/scsi/generic/commands.h
21287c478bd9Sstevel@tonic-gate  */
21297c478bd9Sstevel@tonic-gate 
21307c478bd9Sstevel@tonic-gate /* Both versions of the Read CD command */
21317c478bd9Sstevel@tonic-gate 
21327c478bd9Sstevel@tonic-gate /* the official SCMD_READ_CD now comes from cdio.h */
21337c478bd9Sstevel@tonic-gate #define	SCMD_READ_CDD4		0xd4	/* the one used by some first */
21347c478bd9Sstevel@tonic-gate 					/* generation ATAPI CD drives */
21357c478bd9Sstevel@tonic-gate 
21367c478bd9Sstevel@tonic-gate /* expected sector type filter values for Play and Read CD CDBs */
21377c478bd9Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_CDDA		(1<<2)	/* IEC 908:1987 (CDDA) */
21387c478bd9Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE1		(2<<2)	/* Yellow book 2048 bytes */
21397c478bd9Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2		(3<<2)	/* Yellow book 2335 bytes */
21407c478bd9Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM1	(4<<2)	/* 2048 bytes */
21417c478bd9Sstevel@tonic-gate #define	CDROM_SECTOR_TYPE_MODE2_FORM2	(5<<2)	/* 2324 bytes */
21427c478bd9Sstevel@tonic-gate 
21437c478bd9Sstevel@tonic-gate /* READ CD filter bits (cdb[9]) */
21447c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_SYNC	0x80	/* read sync field */
21457c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_HDR	0x20	/* read four byte header */
21467c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_SUBHDR	0x40	/* read sub-header */
21477c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_ALLHDRS	0x60	/* read header and sub-header */
21487c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_USERDATA	0x10	/* read user data */
21497c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_EDC_ECC	0x08	/* read EDC and ECC field */
21507c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_C2	0x02	/* read C2 error data */
21517c478bd9Sstevel@tonic-gate #define	CDROM_READ_CD_C2_BEB	0x04	/* read C2 and Block Error Bits */
21527c478bd9Sstevel@tonic-gate 
21537c478bd9Sstevel@tonic-gate 
21547c478bd9Sstevel@tonic-gate /*
21557c478bd9Sstevel@tonic-gate  * These belong in sys/scsi/generic/mode.h
21567c478bd9Sstevel@tonic-gate  */
21577c478bd9Sstevel@tonic-gate 
21587c478bd9Sstevel@tonic-gate /*
21597c478bd9Sstevel@tonic-gate  * Mode Sense/Select Header response for Group 2 CDB.
21607c478bd9Sstevel@tonic-gate  */
21617c478bd9Sstevel@tonic-gate 
21627c478bd9Sstevel@tonic-gate struct mode_header_grp2 {
21637c478bd9Sstevel@tonic-gate 	uchar_t length_msb;		/* MSB - number of bytes following */
21647c478bd9Sstevel@tonic-gate 	uchar_t length_lsb;
21657c478bd9Sstevel@tonic-gate 	uchar_t medium_type;		/* device specific */
21667c478bd9Sstevel@tonic-gate 	uchar_t device_specific;	/* device specfic parameters */
21677c478bd9Sstevel@tonic-gate 	uchar_t resv[2];		/* reserved */
21687c478bd9Sstevel@tonic-gate 	uchar_t bdesc_length_hi;	/* length of block descriptor(s) */
21697c478bd9Sstevel@tonic-gate 					/* (if any) */
21707c478bd9Sstevel@tonic-gate 	uchar_t bdesc_length_lo;
21717c478bd9Sstevel@tonic-gate };
21727c478bd9Sstevel@tonic-gate 
21737c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Unshared data", mode_header_grp2))
21747c478bd9Sstevel@tonic-gate 
21757c478bd9Sstevel@tonic-gate /*
21767c478bd9Sstevel@tonic-gate  * Length of the Mode Parameter Header for the Group 2 Mode Select command
21777c478bd9Sstevel@tonic-gate  */
21787c478bd9Sstevel@tonic-gate #define	MODE_HEADER_LENGTH_GRP2	(sizeof (struct mode_header_grp2))
21797c478bd9Sstevel@tonic-gate #define	MODE_PARAM_LENGTH_GRP2 (MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
21807c478bd9Sstevel@tonic-gate 
21817c478bd9Sstevel@tonic-gate /*
21827c478bd9Sstevel@tonic-gate  * Mode Page 1 - Error Recovery Page
21837c478bd9Sstevel@tonic-gate  */
21847c478bd9Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOVER		1
21857c478bd9Sstevel@tonic-gate 
21867c478bd9Sstevel@tonic-gate /*
21877c478bd9Sstevel@tonic-gate  * The following buffer length define is 8 bytes for the Group 2 mode page
21887c478bd9Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 26 bytes for the cdrom
21897c478bd9Sstevel@tonic-gate  * capabilities page (per MMC-2)
21907c478bd9Sstevel@tonic-gate  */
21917c478bd9Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP		0x2A
21927c478bd9Sstevel@tonic-gate #define	MODEPAGE_CDROM_CAP_LEN		26
21937c478bd9Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_CAP		(MODEPAGE_CDROM_CAP_LEN + \
21947c478bd9Sstevel@tonic-gate 	MODE_HEADER_LENGTH_GRP2 + MODE_BLK_DESC_LENGTH)
21957c478bd9Sstevel@tonic-gate 
21967c478bd9Sstevel@tonic-gate 
21977c478bd9Sstevel@tonic-gate /*
21987c478bd9Sstevel@tonic-gate  * Power management defines
21997c478bd9Sstevel@tonic-gate  */
22007c478bd9Sstevel@tonic-gate #define	SD_SPINDLE_UNINIT	(-1)
22017c478bd9Sstevel@tonic-gate #define	SD_SPINDLE_OFF		0
22027c478bd9Sstevel@tonic-gate #define	SD_SPINDLE_ON		1
22032ee4dfc7SJane Chu #define	SD_SPINDLE_STOPPED	0
22042ee4dfc7SJane Chu #define	SD_SPINDLE_STANDBY	1
22052ee4dfc7SJane Chu #define	SD_SPINDLE_IDLE		2
22062ee4dfc7SJane Chu #define	SD_SPINDLE_ACTIVE	3
22072ee4dfc7SJane Chu #define	SD_PM_NOT_SUPPORTED	4
22082ee4dfc7SJane Chu 
22092ee4dfc7SJane Chu /*
22102ee4dfc7SJane Chu  * Power method flag
22112ee4dfc7SJane Chu  */
22122ee4dfc7SJane Chu #define	SD_START_STOP		0
22132ee4dfc7SJane Chu #define	SD_POWER_CONDITION	1
22142ee4dfc7SJane Chu 
22152ee4dfc7SJane Chu 
22162ee4dfc7SJane Chu /*
22172ee4dfc7SJane Chu  * Number of power level for start stop or power condition
22182ee4dfc7SJane Chu  */
22192ee4dfc7SJane Chu #define	SD_PM_NUM_LEVEL_SSU_SS	2
22202ee4dfc7SJane Chu #define	SD_PM_NUM_LEVEL_SSU_PC	4
22212ee4dfc7SJane Chu 
22222ee4dfc7SJane Chu /*
22232ee4dfc7SJane Chu  * SD internal power state change flag
22242ee4dfc7SJane Chu  */
22252ee4dfc7SJane Chu #define	SD_PM_STATE_CHANGE	0
22262ee4dfc7SJane Chu #define	SD_PM_STATE_ROLLBACK	1
22272ee4dfc7SJane Chu 
22282ee4dfc7SJane Chu /*
22292ee4dfc7SJane Chu  * Power attribute table
22302ee4dfc7SJane Chu  */
22312ee4dfc7SJane Chu typedef struct disk_power_attr_ss {
22322ee4dfc7SJane Chu 	char *pm_comp[SD_PM_NUM_LEVEL_SSU_SS + 2];	/* pm component */
22332ee4dfc7SJane Chu 	int ran_perf[SD_PM_NUM_LEVEL_SSU_SS];		/* random performance */
22342ee4dfc7SJane Chu 	int pwr_saving[SD_PM_NUM_LEVEL_SSU_SS];		/* power saving */
22352ee4dfc7SJane Chu 	int latency[SD_PM_NUM_LEVEL_SSU_SS];		/* latency */
22362ee4dfc7SJane Chu }sd_power_attr_ss;
22372ee4dfc7SJane Chu 
22382ee4dfc7SJane Chu typedef struct disk_power_attr_pc {
22392ee4dfc7SJane Chu 	char *pm_comp[SD_PM_NUM_LEVEL_SSU_PC + 2];	/* pm component */
22402ee4dfc7SJane Chu 	int ran_perf[SD_PM_NUM_LEVEL_SSU_PC];		/* random performance */
22412ee4dfc7SJane Chu 	int pwr_saving[SD_PM_NUM_LEVEL_SSU_PC];		/* power saving */
22422ee4dfc7SJane Chu 	int latency[SD_PM_NUM_LEVEL_SSU_PC];		/* latency */
22432ee4dfc7SJane Chu }sd_power_attr_pc;
22447c478bd9Sstevel@tonic-gate 
22457c478bd9Sstevel@tonic-gate 
22467c478bd9Sstevel@tonic-gate /*
22477c478bd9Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
22487c478bd9Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
22497c478bd9Sstevel@tonic-gate  * the device active.
22507c478bd9Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
22517c478bd9Sstevel@tonic-gate  * the token is NULLed so check for this condition.
22527c478bd9Sstevel@tonic-gate  * If there's a thread that can be resumed, ie. token is not NULL, then
22537c478bd9Sstevel@tonic-gate  * it can be resumed.
22547c478bd9Sstevel@tonic-gate  */
22557c478bd9Sstevel@tonic-gate #define	SD_OK_TO_RESUME_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
22567c478bd9Sstevel@tonic-gate /*
22577c478bd9Sstevel@tonic-gate  * No Need to resume if already in PM_SUSPEND state because the thread
22587c478bd9Sstevel@tonic-gate  * was suspended in sdpower. It will be resumed when sdpower is invoked to make
22597c478bd9Sstevel@tonic-gate  * the device active.
22607c478bd9Sstevel@tonic-gate  * When the thread is suspended, the watch thread is terminated and
22617c478bd9Sstevel@tonic-gate  * the token is NULLed so check for this condition.
22627c478bd9Sstevel@tonic-gate  */
22637c478bd9Sstevel@tonic-gate #define	SD_OK_TO_SUSPEND_SCSI_WATCHER(un)	(un->un_swr_token != NULL)
22647c478bd9Sstevel@tonic-gate #define	SD_DEVICE_IS_IN_LOW_POWER(un)		((un->un_f_pm_is_enabled) && \
22657c478bd9Sstevel@tonic-gate 						    (un->un_pm_count < 0))
22662ee4dfc7SJane Chu #define	SD_PM_STATE_ACTIVE(un)				\
22672ee4dfc7SJane Chu 		(un->un_f_power_condition_supported ?	\
22682ee4dfc7SJane Chu 		SD_SPINDLE_ACTIVE : SD_SPINDLE_ON)
22692ee4dfc7SJane Chu #define	SD_PM_STATE_STOPPED(un)				\
22702ee4dfc7SJane Chu 		(un->un_f_power_condition_supported ?	\
22712ee4dfc7SJane Chu 		SD_SPINDLE_STOPPED : SD_SPINDLE_OFF)
22722ee4dfc7SJane Chu #define	SD_PM_IS_LEVEL_VALID(un, level)			\
22732ee4dfc7SJane Chu 		((un->un_f_power_condition_supported &&	\
22742ee4dfc7SJane Chu 		level >= SD_SPINDLE_STOPPED &&		\
22752ee4dfc7SJane Chu 		level <= SD_SPINDLE_ACTIVE) ||		\
22762ee4dfc7SJane Chu 		(!un->un_f_power_condition_supported &&	\
22772ee4dfc7SJane Chu 		level >= SD_SPINDLE_OFF &&		\
22782ee4dfc7SJane Chu 		level <= SD_SPINDLE_ON))
22792ee4dfc7SJane Chu #define	SD_PM_IS_IO_CAPABLE(un, level)			\
22802ee4dfc7SJane Chu 		((un->un_f_power_condition_supported &&	\
22812ee4dfc7SJane Chu 		sd_pwr_pc.ran_perf[level] > 0) ||	\
22822ee4dfc7SJane Chu 		(!un->un_f_power_condition_supported &&	\
22832ee4dfc7SJane Chu 		sd_pwr_ss.ran_perf[level] > 0))
22842ee4dfc7SJane Chu #define	SD_PM_STOP_MOTOR_NEEDED(un, level)		\
22852ee4dfc7SJane Chu 		((un->un_f_power_condition_supported &&	\
22862ee4dfc7SJane Chu 		level <= SD_SPINDLE_STANDBY) ||		\
22872ee4dfc7SJane Chu 		(!un->un_f_power_condition_supported &&	\
22882ee4dfc7SJane Chu 		level == SD_SPINDLE_OFF))
22892ee4dfc7SJane Chu 
22907c478bd9Sstevel@tonic-gate /*
22917c478bd9Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
22927c478bd9Sstevel@tonic-gate  * But for now let it live here.
22937c478bd9Sstevel@tonic-gate  */
22947c478bd9Sstevel@tonic-gate #define	START_STOP_CYCLE_COUNTER_PAGE_SIZE	0x28
22957c478bd9Sstevel@tonic-gate #define	START_STOP_CYCLE_PAGE			0x0E
22967c478bd9Sstevel@tonic-gate #define	START_STOP_CYCLE_VU_PAGE		0x31
22977c478bd9Sstevel@tonic-gate 
22987c478bd9Sstevel@tonic-gate /* CD-ROM Error Recovery Parameters page (0x01) */
22997c478bd9Sstevel@tonic-gate #define	MODEPAGE_ERR_RECOV	0x1
23007c478bd9Sstevel@tonic-gate #define	BUFLEN_CHG_BLK_MODE	MODE_HEADER_LENGTH + MODE_BLK_DESC_LENGTH
23017c478bd9Sstevel@tonic-gate 
23027c478bd9Sstevel@tonic-gate /*
23037c478bd9Sstevel@tonic-gate  * Vendor Specific (Toshiba) CD-ROM Speed page (0x31)
23047c478bd9Sstevel@tonic-gate  *
23057c478bd9Sstevel@tonic-gate  * The following buffer length define is 4 bytes for the Group 0 mode page
23067c478bd9Sstevel@tonic-gate  * header, 8 bytes for the block descriptor and 4 bytes for the mode speed page.
23077c478bd9Sstevel@tonic-gate  */
23087c478bd9Sstevel@tonic-gate #define	MODEPAGE_CDROM_SPEED_LEN	4
23097c478bd9Sstevel@tonic-gate #define	BUFLEN_MODE_CDROM_SPEED		MODEPAGE_CDROM_SPEED_LEN +\
23107c478bd9Sstevel@tonic-gate 					MODE_HEADER_LENGTH +\
23117c478bd9Sstevel@tonic-gate 					MODE_BLK_DESC_LENGTH
23127c478bd9Sstevel@tonic-gate #define	SD_SPEED_1X			176
23137c478bd9Sstevel@tonic-gate 
23147c478bd9Sstevel@tonic-gate /* CD-ROM Audio Control Parameters page (0x0E) */
23157c478bd9Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL		0x0E
23167c478bd9Sstevel@tonic-gate #define	MODEPAGE_AUDIO_CTRL_LEN		16
23177c478bd9Sstevel@tonic-gate 
23187c478bd9Sstevel@tonic-gate /* CD-ROM Sony Read Offset Defines */
23197c478bd9Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_LEN		12
23207c478bd9Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_KEY		0x40
23217c478bd9Sstevel@tonic-gate #define	SONY_SESSION_OFFSET_VALID	0x0a
23227c478bd9Sstevel@tonic-gate 
23237c478bd9Sstevel@tonic-gate /*
23247c478bd9Sstevel@tonic-gate  * CD-ROM Write Protect Defines
23257c478bd9Sstevel@tonic-gate  *
23267c478bd9Sstevel@tonic-gate  * Bit 7 of the device specific field of the mode page header is the write
23277c478bd9Sstevel@tonic-gate  * protect bit.
23287c478bd9Sstevel@tonic-gate  */
23297c478bd9Sstevel@tonic-gate #define	WRITE_PROTECT 0x80
23307c478bd9Sstevel@tonic-gate 
23317c478bd9Sstevel@tonic-gate /*
23327c478bd9Sstevel@tonic-gate  * Define for the length of a profile header returned in response to the
23337c478bd9Sstevel@tonic-gate  * GET CONFIGURATION command
23347c478bd9Sstevel@tonic-gate  */
23357c478bd9Sstevel@tonic-gate #define	SD_PROFILE_HEADER_LEN		8	/* bytes */
23367c478bd9Sstevel@tonic-gate 
23377c478bd9Sstevel@tonic-gate /*
2338fb252d2eSphitran  * Define the length of the data in response to the GET CONFIGURATION
2339fb252d2eSphitran  * command.  The 3rd byte of the feature descriptor contains the
2340fb252d2eSphitran  * current feature field that is of interest.  This field begins
2341fb252d2eSphitran  * after the feature header which is 8 bytes.  This variable length
2342fb252d2eSphitran  * was increased in size from 11 to 24 because some devices became
2343fb252d2eSphitran  * unresponsive with the smaller size.
23447c478bd9Sstevel@tonic-gate  */
2345fb252d2eSphitran #define	SD_CURRENT_FEATURE_LEN		24	/* bytes */
23467c478bd9Sstevel@tonic-gate 
23477c478bd9Sstevel@tonic-gate /*
23487c478bd9Sstevel@tonic-gate  * Feature codes associated with GET CONFIGURATION command for supported
23497c478bd9Sstevel@tonic-gate  * devices.
23507c478bd9Sstevel@tonic-gate  */
23517c478bd9Sstevel@tonic-gate #define	RANDOM_WRITABLE			0x20
23527c478bd9Sstevel@tonic-gate #define	HARDWARE_DEFECT_MANAGEMENT	0x24
23537c478bd9Sstevel@tonic-gate 
23547c478bd9Sstevel@tonic-gate /*
23557c478bd9Sstevel@tonic-gate  * Could move this define to some thing like log sense.h in SCSA headers
23567c478bd9Sstevel@tonic-gate  * But for now let it live here.
23577c478bd9Sstevel@tonic-gate  */
23587c478bd9Sstevel@tonic-gate #define	TEMPERATURE_PAGE			0x0D
23597c478bd9Sstevel@tonic-gate #define	TEMPERATURE_PAGE_SIZE			16	/* bytes */
23607c478bd9Sstevel@tonic-gate 
23617c478bd9Sstevel@tonic-gate /* delay time used for sd_media_watch_cb delayed cv broadcast */
23627c478bd9Sstevel@tonic-gate #define	MEDIA_ACCESS_DELAY 2000000
23637c478bd9Sstevel@tonic-gate 
23647c478bd9Sstevel@tonic-gate 
23657c478bd9Sstevel@tonic-gate /* SCSI power on or bus device reset additional sense code */
23667c478bd9Sstevel@tonic-gate #define	SD_SCSI_RESET_SENSE_CODE	0x29
23677c478bd9Sstevel@tonic-gate 
23687c478bd9Sstevel@tonic-gate /*
23697c478bd9Sstevel@tonic-gate  * These defines are for the Vital Product Data Pages in the inquiry command.
23707c478bd9Sstevel@tonic-gate  * They are the bits in the un_vpd_page mask, telling the supported pages.
23717c478bd9Sstevel@tonic-gate  */
23727c478bd9Sstevel@tonic-gate #define	SD_VPD_SUPPORTED_PG	0x01	/* 0x00 - Supported VPD pages */
23737c478bd9Sstevel@tonic-gate #define	SD_VPD_UNIT_SERIAL_PG	0x02	/* 0x80 - Unit Serial Number */
23747c478bd9Sstevel@tonic-gate #define	SD_VPD_OPERATING_PG	0x04	/* 0x81 - Implemented Op Defs */
23757c478bd9Sstevel@tonic-gate #define	SD_VPD_ASCII_OP_PG	0x08	/* 0x82 - ASCII Op Defs */
23767c478bd9Sstevel@tonic-gate #define	SD_VPD_DEVID_WWN_PG	0x10	/* 0x83 - Device Identification */
2377a84224b3Sgz161490 #define	SD_VPD_EXTENDED_DATA_PG	0x80	/* 0x86 - Extended data about the lun */
2378b081f1c4Syu, larry liu - Sun Microsystems - Beijing China #define	SD_VPD_DEV_CHARACTER_PG	0x400	/* 0xB1 - Device Characteristics */
2379a84224b3Sgz161490 
2380a84224b3Sgz161490 /*
2381a84224b3Sgz161490  * Non-volatile cache support
2382a84224b3Sgz161490  *
2383a84224b3Sgz161490  * Bit 1 of the byte 6 in the Extended INQUIRY data VPD page
2384a84224b3Sgz161490  * is NV_SUP bit: An NV_SUP bit set to one indicates that
2385a84224b3Sgz161490  * the device server supports a non-volatile cache.  An
2386a84224b3Sgz161490  * NV_SUP bit set to zero indicates that the device
2387a84224b3Sgz161490  * server may or may not support a non-volatile cache.
2388a84224b3Sgz161490  *
2389a84224b3Sgz161490  * Bit 2 of the byte 1 in the SYNC CACHE command is SYNC_NV
2390a84224b3Sgz161490  * bit: The SYNC_NV bit specifies whether the device server
2391a84224b3Sgz161490  * is required to synchronize volatile and non-volatile
2392a84224b3Sgz161490  * caches.
2393a84224b3Sgz161490  */
2394a84224b3Sgz161490 #define	SD_VPD_NV_SUP	0x02
2395a84224b3Sgz161490 #define	SD_SYNC_NV_BIT 0x04
23967c478bd9Sstevel@tonic-gate 
23977c478bd9Sstevel@tonic-gate /*
23987c478bd9Sstevel@tonic-gate  * Addition from sddef.intel.h
23997c478bd9Sstevel@tonic-gate  */
24007c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
24017c478bd9Sstevel@tonic-gate 
24027c478bd9Sstevel@tonic-gate #define	P0_RAW_DISK	(NDKMAP)
24037c478bd9Sstevel@tonic-gate #define	FDISK_P1	(NDKMAP+1)
24047c478bd9Sstevel@tonic-gate #define	FDISK_P2	(NDKMAP+2)
24057c478bd9Sstevel@tonic-gate #define	FDISK_P3	(NDKMAP+3)
24067c478bd9Sstevel@tonic-gate #define	FDISK_P4	(NDKMAP+4)
24077c478bd9Sstevel@tonic-gate 
24087c478bd9Sstevel@tonic-gate #endif	/* __i386 || __amd64 */
24097c478bd9Sstevel@tonic-gate 
24107c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
24117c478bd9Sstevel@tonic-gate }
24127c478bd9Sstevel@tonic-gate #endif
24137c478bd9Sstevel@tonic-gate 
24147c478bd9Sstevel@tonic-gate 
24157c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_TARGETS_SDDEF_H */
2416