xref: /onnv-gate/usr/src/uts/common/sys/scsi/conf/device.h (revision 11556:99144956c627)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
56640Scth  * Common Development and Distribution License (the "License").
66640Scth  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11556SReed.Liu@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23176Scth  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * SCSI device structure.
280Sstevel@tonic-gate  *
298335SChris.Horne@Sun.COM  * All SCSI target drivers will have one of these per target/lun/sfunc.
308335SChris.Horne@Sun.COM  * It is allocated and initialized by the framework SCSA HBA nexus code
318335SChris.Horne@Sun.COM  * for each SCSI target dev_info_t node during HBA nexus DDI_CTLOPS_INITCHILD
328335SChris.Horne@Sun.COM  * processing of a child device node just prior to tran_tgt_init(9E).  A
338335SChris.Horne@Sun.COM  * pointer the the scsi_device(9S) structure is stored in the
348335SChris.Horne@Sun.COM  * driver-private data field of the target device's dev_info_t node (in
358335SChris.Horne@Sun.COM  * 'devi_driver_data') and can be retrieved by ddi_get_driver_private(9F).
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate #ifndef	_SYS_SCSI_CONF_DEVICE_H
380Sstevel@tonic-gate #define	_SYS_SCSI_CONF_DEVICE_H
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
410Sstevel@tonic-gate 
420Sstevel@tonic-gate #ifdef	__cplusplus
430Sstevel@tonic-gate extern "C" {
440Sstevel@tonic-gate #endif
450Sstevel@tonic-gate 
460Sstevel@tonic-gate struct scsi_device {
470Sstevel@tonic-gate 	/*
488335SChris.Horne@Sun.COM 	 * Routing information for a SCSI device (target/lun/sfunc).
498335SChris.Horne@Sun.COM 	 *
508335SChris.Horne@Sun.COM 	 * The scsi_address(9S) structure contains a pointer to the
518335SChris.Horne@Sun.COM 	 * scsi_hba_tran(9S) of the transport.
528335SChris.Horne@Sun.COM 	 *
538335SChris.Horne@Sun.COM 	 * For devices below an HBA that uses SCSI_HBA_ADDR_SPI
548335SChris.Horne@Sun.COM 	 * unit-addressing, the scsi_address(9S) information contains
558335SChris.Horne@Sun.COM 	 * decoded target/lun addressing information.
568335SChris.Horne@Sun.COM 	 *
578335SChris.Horne@Sun.COM 	 * For devices below an HBA that uses SCSI_HBA_ADDR_COMPLEX
588335SChris.Horne@Sun.COM 	 * unit-addressing, the scsi_address(9S) information contains a
598335SChris.Horne@Sun.COM 	 * pointer to the scsi_device(9S) structure and the HBA can maintain
608335SChris.Horne@Sun.COM 	 * its private per-unit-address/per-scsi_device information using
618335SChris.Horne@Sun.COM 	 * scsi_address_device(9F) and scsi_device_hba_private_[gs]et(9F).
628335SChris.Horne@Sun.COM 	 *
638335SChris.Horne@Sun.COM 	 * NOTE: The scsi_address(9S) structure gets structure-copied into
648335SChris.Horne@Sun.COM 	 * the scsi_pkt(9S) 'pkt_address' field. Having a pointer to the
658335SChris.Horne@Sun.COM 	 * scsi_device(9S) structure within the scsi_address(9S) allows
668335SChris.Horne@Sun.COM 	 * the SCSA framework to reflect generic changes in device state
678335SChris.Horne@Sun.COM 	 * at scsi_pkt_comp(9F) time (given just a scsi_pkt(9S) pointer).
688335SChris.Horne@Sun.COM 	 *
698335SChris.Horne@Sun.COM 	 * NOTE: The older SCSI_HBA_TRAN_CLONE method of supporting
708335SChris.Horne@Sun.COM 	 * SCSI-3 devices is still supported, but use is discouraged.
710Sstevel@tonic-gate 	 */
720Sstevel@tonic-gate 	struct scsi_address	sd_address;
730Sstevel@tonic-gate 
748335SChris.Horne@Sun.COM 	/* Cross-reference to target device's dev_info_t. */
750Sstevel@tonic-gate 	dev_info_t		*sd_dev;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	/*
788335SChris.Horne@Sun.COM 	 * Target driver mutex for this device. Initialized by SCSA HBA
798335SChris.Horne@Sun.COM 	 * framework code prior to probe(9E) or attach(9E) of scsi_device.
800Sstevel@tonic-gate 	 */
810Sstevel@tonic-gate 	kmutex_t		sd_mutex;
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	/*
848335SChris.Horne@Sun.COM 	 * SCSA private: use is associated with implementation of
858335SChris.Horne@Sun.COM 	 * SCSI_HBA_ADDR_COMPLEX scsi_device_hba_private_[gs]et(9F).
868335SChris.Horne@Sun.COM 	 * The HBA driver can store a pointer to per-scsi_device(9S)
878335SChris.Horne@Sun.COM 	 * HBA private data during its tran_tgt_init(9E) implementation
888335SChris.Horne@Sun.COM 	 * by calling scsi_device_hba_private_set(9F), and free that
898335SChris.Horne@Sun.COM 	 * pointer during tran_tgt_fini(9E). At tran_send(9E) time, the
908335SChris.Horne@Sun.COM 	 * HBA driver can use scsi_address_device(9F) to obtain a pointer
918335SChris.Horne@Sun.COM 	 * to the scsi_device(9S) structure, and then gain access to
928335SChris.Horne@Sun.COM 	 * its per-scsi_device(9S) hba private data by calling
938335SChris.Horne@Sun.COM 	 * scsi_device_hba_private_get(9F).
940Sstevel@tonic-gate 	 */
958335SChris.Horne@Sun.COM 	void			*sd_hba_private;
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	/*
988335SChris.Horne@Sun.COM 	 * If scsi_slave is used to probe out this device, a scsi_inquiry data
998335SChris.Horne@Sun.COM 	 * structure will be allocated and an INQUIRY command will be run to
1008335SChris.Horne@Sun.COM 	 * fill it in.
1010Sstevel@tonic-gate 	 *
1028335SChris.Horne@Sun.COM 	 * The allocation will be done via ddi_iopb_alloc, so any manual
1038335SChris.Horne@Sun.COM 	 * freeing may be done by ddi_iopb_free.
104176Scth 	 *
1058335SChris.Horne@Sun.COM 	 * The inquiry data is allocated/refreshed by scsi_probe/scsi_slave
1068335SChris.Horne@Sun.COM 	 * and freed by uninitchild (inquiry data is no longer freed by
1078335SChris.Horne@Sun.COM 	 * scsi_unprobe/scsi_unslave).
108176Scth 	 *
1098335SChris.Horne@Sun.COM 	 * NOTE: Additional device identity information may be available
110176Scth 	 * as properties of sd_dev.
1110Sstevel@tonic-gate 	 */
1120Sstevel@tonic-gate 	struct scsi_inquiry	*sd_inq;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 	/*
1150Sstevel@tonic-gate 	 * Place to point to an extended request sense buffer.
1160Sstevel@tonic-gate 	 * The target driver is responsible for managing this.
1170Sstevel@tonic-gate 	 */
1180Sstevel@tonic-gate 	struct scsi_extended_sense	*sd_sense;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	/*
1218335SChris.Horne@Sun.COM 	 * Target driver 'private' information. Typically a pointer to target
1228335SChris.Horne@Sun.COM 	 * driver private ddi_soft_state(9F) information for the device.  This
1238335SChris.Horne@Sun.COM 	 * information is typically established in target driver attach(9E),
1248335SChris.Horne@Sun.COM 	 * and freed in the target driver detach(9E).
1258335SChris.Horne@Sun.COM 	 *
1268335SChris.Horne@Sun.COM 	 * LEGACY: For a scsi_device structure allocated by scsi_vhci during
1278335SChris.Horne@Sun.COM 	 * online of a path, this was set by scsi_vhci to point to the
1288335SChris.Horne@Sun.COM 	 * pathinfo node. Please use sd_pathinfo instead.
1290Sstevel@tonic-gate 	 */
1308335SChris.Horne@Sun.COM 	void			*sd_private;
1316640Scth 
1326640Scth 	/*
1336640Scth 	 * FMA capabilities of scsi_device.
1346640Scth 	 */
1356640Scth 	int			sd_fm_capable;
1366640Scth 
1378335SChris.Horne@Sun.COM 	/*
1388335SChris.Horne@Sun.COM 	 * mdi_pathinfo_t pointer to pathinfo node for scsi_device structure
1398335SChris.Horne@Sun.COM 	 * allocated by the scsi_vhci for transport to a specific pHCI path.
1408335SChris.Horne@Sun.COM 	 */
1418335SChris.Horne@Sun.COM 	void			*sd_pathinfo;
1428335SChris.Horne@Sun.COM 
1438335SChris.Horne@Sun.COM 	/*
144*11556SReed.Liu@Sun.COM 	 * sd_uninit_prevent - Counter that prevents demotion of
145*11556SReed.Liu@Sun.COM 	 * DS_INITIALIZED node (esp loss of devi_addr) by causing
146*11556SReed.Liu@Sun.COM 	 * DDI_CTLOPS_UNINITCHILD failure - devi_ref will not protect
147*11556SReed.Liu@Sun.COM 	 * demotion of DS_INITIALIZED node.
148*11556SReed.Liu@Sun.COM 	 *
149*11556SReed.Liu@Sun.COM 	 * sd_tran_tgt_free_done - in some cases SCSA will call
150*11556SReed.Liu@Sun.COM 	 * tran_tgt_free(9E) independent of devinfo node state, this means
151*11556SReed.Liu@Sun.COM 	 * that uninitchild code should not call tran_tgt_free(9E).
15210696SDavid.Hollister@Sun.COM 	 */
153*11556SReed.Liu@Sun.COM 	int			sd_uninit_prevent:16,
154*11556SReed.Liu@Sun.COM 				sd_tran_tgt_free_done:1,
155*11556SReed.Liu@Sun.COM 				sd_flags_pad:15;
15610696SDavid.Hollister@Sun.COM 
15710696SDavid.Hollister@Sun.COM 	/*
1588335SChris.Horne@Sun.COM 	 * The 'sd_tran_safe' field is a grotty hack that allows direct-access
1598335SChris.Horne@Sun.COM 	 * (non-scsa) drivers (like chs, ata, and mlx - which all make cmdk
1608335SChris.Horne@Sun.COM 	 * children) to *illegally* put their own vector in the scsi_address(9S)
1618335SChris.Horne@Sun.COM 	 * 'a_hba_tran' field. When all the drivers that overwrite
1628335SChris.Horne@Sun.COM 	 * 'a_hba_tran' are fixed, we can remove sd_tran_safe (and make
1638335SChris.Horne@Sun.COM 	 * scsi_hba.c code trust that the 'sd_address.a_hba_tran' established
1648335SChris.Horne@Sun.COM 	 * during initchild is still valid when uninitchild occurs).
1658335SChris.Horne@Sun.COM 	 *
1668335SChris.Horne@Sun.COM 	 * NOTE: This hack is also shows up in the DEVP_TO_TRAN implementation
1678335SChris.Horne@Sun.COM 	 * in scsi_confsubr.c.
1688335SChris.Horne@Sun.COM 	 *
1698335SChris.Horne@Sun.COM 	 * NOTE: The 'sd_tran_safe' field is only referenced by SCSA framework
1708335SChris.Horne@Sun.COM 	 * code, so always keeping it at the end of the scsi_device structure
1718335SChris.Horne@Sun.COM 	 * (until it can be removed) is OK.  It use to be called 'sd_reserved'.
1728335SChris.Horne@Sun.COM 	 */
1738335SChris.Horne@Sun.COM 	struct scsi_hba_tran	*sd_tran_safe;
1748335SChris.Horne@Sun.COM 
1756640Scth #ifdef	SCSI_SIZE_CLEAN_VERIFY
1766640Scth 	/*
1776640Scth 	 * Must be last: Building a driver with-and-without
1786640Scth 	 * -DSCSI_SIZE_CLEAN_VERIFY, and checking driver modules for
1796640Scth 	 * differences with a tools like 'wsdiff' allows a developer to verify
1806640Scth 	 * that their driver has no dependencies on scsi*(9S) size.
1816640Scth 	 */
1826640Scth 	int			_pad[8];
1836640Scth #endif	/* SCSI_SIZE_CLEAN_VERIFY */
1840Sstevel@tonic-gate };
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate #ifdef	_KERNEL
1878916SChris.Horne@Sun.COM 
1888916SChris.Horne@Sun.COM /* ==== The following interfaces are public ==== */
1898916SChris.Horne@Sun.COM 
1908335SChris.Horne@Sun.COM int	scsi_probe(struct scsi_device *sd, int (*callback)(void));
1918335SChris.Horne@Sun.COM void	scsi_unprobe(struct scsi_device *sd);
1928335SChris.Horne@Sun.COM 
1938916SChris.Horne@Sun.COM /* ==== The following interfaces are private (currently) ==== */
1948916SChris.Horne@Sun.COM 
1958916SChris.Horne@Sun.COM char	*scsi_device_unit_address(struct scsi_device *sd);
1968916SChris.Horne@Sun.COM 
1978916SChris.Horne@Sun.COM /*
1988916SChris.Horne@Sun.COM  * scsi_device_prop_*() property interfaces: flags
1998916SChris.Horne@Sun.COM  *
2008916SChris.Horne@Sun.COM  *   SCSI_DEVICE_PROP_PATH: property of path-to-device.
2018916SChris.Horne@Sun.COM  *	The property is associated with the sd_pathinfo pathinfo node
2028916SChris.Horne@Sun.COM  *	as established by scsi_vhci. If sd_pathinfo is NULL then the
2038916SChris.Horne@Sun.COM  *	property is associated with the sd_dev devinfo node.
2048916SChris.Horne@Sun.COM  *	Implementation uses mdi_prop_*() interfaces applied to
2058916SChris.Horne@Sun.COM  *	mdi_pathinfo_t (sd_pathinfo) nodes.
2068916SChris.Horne@Sun.COM  *
2078916SChris.Horne@Sun.COM  *   SCSI_DEVICE_PROP_DEVICE: property of device.
2088916SChris.Horne@Sun.COM  *	The property is always associated with the sd_dev devinfo
2098916SChris.Horne@Sun.COM  *	node.  Implementation uses ndi_prop_*() interfaces applied
2108916SChris.Horne@Sun.COM  *	dev_info_t (sd_dev) nodes.
2118916SChris.Horne@Sun.COM  */
2128916SChris.Horne@Sun.COM #define	SCSI_DEVICE_PROP_PATH		0x1	/* type is property-of-path */
2138916SChris.Horne@Sun.COM #define	SCSI_DEVICE_PROP_DEVICE		0x2	/* type is property-of-device */
2148916SChris.Horne@Sun.COM #define	SCSI_DEVICE_PROP_TYPE_MSK	0xF
2158916SChris.Horne@Sun.COM 
2168916SChris.Horne@Sun.COM int	scsi_device_prop_get_int(struct scsi_device *sd,
2178916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int defvalue);
2188916SChris.Horne@Sun.COM int64_t	scsi_device_prop_get_int64(struct scsi_device *,
2198916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int64_t defvalue);
2208335SChris.Horne@Sun.COM 
2218916SChris.Horne@Sun.COM int	scsi_device_prop_lookup_byte_array(struct scsi_device *sd,
2228916SChris.Horne@Sun.COM 	    uint_t flags, char *name, uchar_t **, uint_t *);
2238916SChris.Horne@Sun.COM int	scsi_device_prop_lookup_int_array(struct scsi_device *sd,
2248916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int **, uint_t *);
2258916SChris.Horne@Sun.COM int	scsi_device_prop_lookup_string(struct scsi_device *sd,
2268916SChris.Horne@Sun.COM 	    uint_t flags, char *name, char **);
2278916SChris.Horne@Sun.COM int	scsi_device_prop_lookup_string_array(struct scsi_device *sd,
2288916SChris.Horne@Sun.COM 	    uint_t flags, char *name, char ***, uint_t *);
2298916SChris.Horne@Sun.COM 
2308916SChris.Horne@Sun.COM int	scsi_device_prop_update_byte_array(struct scsi_device *sd,
2318916SChris.Horne@Sun.COM 	    uint_t flags, char *name, uchar_t *, uint_t);
2328916SChris.Horne@Sun.COM int	scsi_device_prop_update_int(struct scsi_device *sd,
2338916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int);
2348916SChris.Horne@Sun.COM int	scsi_device_prop_update_int64(struct scsi_device *sd,
2358916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int64_t);
2368916SChris.Horne@Sun.COM int	scsi_device_prop_update_int_array(struct scsi_device *sd,
2378916SChris.Horne@Sun.COM 	    uint_t flags, char *name, int *, uint_t);
2388916SChris.Horne@Sun.COM int	scsi_device_prop_update_string(struct scsi_device *sd,
2398916SChris.Horne@Sun.COM 	    uint_t flags, char *name, char *);
2408916SChris.Horne@Sun.COM int	scsi_device_prop_update_string_array(struct scsi_device *sd,
2418916SChris.Horne@Sun.COM 	    uint_t flags, char *name, char **, uint_t);
2428916SChris.Horne@Sun.COM 
2438916SChris.Horne@Sun.COM int	scsi_device_prop_remove(struct scsi_device *sd,
2448916SChris.Horne@Sun.COM 	    uint_t flags, char *name);
2458916SChris.Horne@Sun.COM void	scsi_device_prop_free(struct scsi_device *sd,
2468916SChris.Horne@Sun.COM 	    uint_t flags, void *data);
2478916SChris.Horne@Sun.COM 
2488916SChris.Horne@Sun.COM /* SCSI_HBA_ADDR_COMPLEX interfaces */
2498335SChris.Horne@Sun.COM struct scsi_device	*scsi_address_device(struct scsi_address *sa);
2508335SChris.Horne@Sun.COM void	scsi_device_hba_private_set(struct scsi_device *sd, void *data);
2518335SChris.Horne@Sun.COM void	*scsi_device_hba_private_get(struct scsi_device *sd);
2528335SChris.Horne@Sun.COM 
2538916SChris.Horne@Sun.COM /* ==== The following interfaces are private ==== */
2548916SChris.Horne@Sun.COM 
2558916SChris.Horne@Sun.COM size_t	scsi_device_size();
2568916SChris.Horne@Sun.COM 
2578916SChris.Horne@Sun.COM /* ==== The following interfaces are obsolete ==== */
2588916SChris.Horne@Sun.COM 
2598335SChris.Horne@Sun.COM int	scsi_slave(struct scsi_device *sd, int (*callback)(void));
2608335SChris.Horne@Sun.COM void	scsi_unslave(struct scsi_device *sd);
2618916SChris.Horne@Sun.COM 
2620Sstevel@tonic-gate #endif	/* _KERNEL */
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate #ifdef	__cplusplus
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate #endif
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate #endif	/* _SYS_SCSI_CONF_DEVICE_H */
269