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
5602ca9eaScth  * Common Development and Distribution License (the "License").
6602ca9eaScth  * 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 /*
22c40ba10dSReed  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
231e32c0dcScth  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25b89e420aSGarrett D'Amore /*
26b89e420aSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
27b89e420aSGarrett D'Amore  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * SCSI device structure.
317c478bd9Sstevel@tonic-gate  *
3253a7b6b6SChris Horne  * All SCSI target drivers will have one of these per target/lun/sfunc.
3353a7b6b6SChris Horne  * It is allocated and initialized by the framework SCSA HBA nexus code
3453a7b6b6SChris Horne  * for each SCSI target dev_info_t node during HBA nexus DDI_CTLOPS_INITCHILD
3553a7b6b6SChris Horne  * processing of a child device node just prior to tran_tgt_init(9E).  A
3653a7b6b6SChris Horne  * pointer the the scsi_device(9S) structure is stored in the
3753a7b6b6SChris Horne  * driver-private data field of the target device's dev_info_t node (in
3853a7b6b6SChris Horne  * 'devi_driver_data') and can be retrieved by ddi_get_driver_private(9F).
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate #ifndef	_SYS_SCSI_CONF_DEVICE_H
417c478bd9Sstevel@tonic-gate #define	_SYS_SCSI_CONF_DEVICE_H
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi_types.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
467c478bd9Sstevel@tonic-gate extern "C" {
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate struct scsi_device {
507c478bd9Sstevel@tonic-gate 	/*
5153a7b6b6SChris Horne 	 * Routing information for a SCSI device (target/lun/sfunc).
5253a7b6b6SChris Horne 	 *
5353a7b6b6SChris Horne 	 * The scsi_address(9S) structure contains a pointer to the
5453a7b6b6SChris Horne 	 * scsi_hba_tran(9S) of the transport.
5553a7b6b6SChris Horne 	 *
5653a7b6b6SChris Horne 	 * For devices below an HBA that uses SCSI_HBA_ADDR_SPI
5753a7b6b6SChris Horne 	 * unit-addressing, the scsi_address(9S) information contains
5853a7b6b6SChris Horne 	 * decoded target/lun addressing information.
5953a7b6b6SChris Horne 	 *
6053a7b6b6SChris Horne 	 * For devices below an HBA that uses SCSI_HBA_ADDR_COMPLEX
6153a7b6b6SChris Horne 	 * unit-addressing, the scsi_address(9S) information contains a
6253a7b6b6SChris Horne 	 * pointer to the scsi_device(9S) structure and the HBA can maintain
6353a7b6b6SChris Horne 	 * its private per-unit-address/per-scsi_device information using
6453a7b6b6SChris Horne 	 * scsi_address_device(9F) and scsi_device_hba_private_[gs]et(9F).
6553a7b6b6SChris Horne 	 *
6653a7b6b6SChris Horne 	 * NOTE: The scsi_address(9S) structure gets structure-copied into
6753a7b6b6SChris Horne 	 * the scsi_pkt(9S) 'pkt_address' field. Having a pointer to the
6853a7b6b6SChris Horne 	 * scsi_device(9S) structure within the scsi_address(9S) allows
6953a7b6b6SChris Horne 	 * the SCSA framework to reflect generic changes in device state
7053a7b6b6SChris Horne 	 * at scsi_pkt_comp(9F) time (given just a scsi_pkt(9S) pointer).
7153a7b6b6SChris Horne 	 *
7253a7b6b6SChris Horne 	 * NOTE: The older SCSI_HBA_TRAN_CLONE method of supporting
7353a7b6b6SChris Horne 	 * SCSI-3 devices is still supported, but use is discouraged.
747c478bd9Sstevel@tonic-gate 	 */
757c478bd9Sstevel@tonic-gate 	struct scsi_address	sd_address;
767c478bd9Sstevel@tonic-gate 
7753a7b6b6SChris Horne 	/* Cross-reference to target device's dev_info_t. */
787c478bd9Sstevel@tonic-gate 	dev_info_t		*sd_dev;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	/*
8153a7b6b6SChris Horne 	 * Target driver mutex for this device. Initialized by SCSA HBA
8253a7b6b6SChris Horne 	 * framework code prior to probe(9E) or attach(9E) of scsi_device.
837c478bd9Sstevel@tonic-gate 	 */
847c478bd9Sstevel@tonic-gate 	kmutex_t		sd_mutex;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	/*
8753a7b6b6SChris Horne 	 * SCSA private: use is associated with implementation of
8853a7b6b6SChris Horne 	 * SCSI_HBA_ADDR_COMPLEX scsi_device_hba_private_[gs]et(9F).
8953a7b6b6SChris Horne 	 * The HBA driver can store a pointer to per-scsi_device(9S)
9053a7b6b6SChris Horne 	 * HBA private data during its tran_tgt_init(9E) implementation
9153a7b6b6SChris Horne 	 * by calling scsi_device_hba_private_set(9F), and free that
9253a7b6b6SChris Horne 	 * pointer during tran_tgt_fini(9E). At tran_send(9E) time, the
9353a7b6b6SChris Horne 	 * HBA driver can use scsi_address_device(9F) to obtain a pointer
9453a7b6b6SChris Horne 	 * to the scsi_device(9S) structure, and then gain access to
9553a7b6b6SChris Horne 	 * its per-scsi_device(9S) hba private data by calling
9653a7b6b6SChris Horne 	 * scsi_device_hba_private_get(9F).
977c478bd9Sstevel@tonic-gate 	 */
9853a7b6b6SChris Horne 	void			*sd_hba_private;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/*
10153a7b6b6SChris Horne 	 * If scsi_slave is used to probe out this device, a scsi_inquiry data
10253a7b6b6SChris Horne 	 * structure will be allocated and an INQUIRY command will be run to
10353a7b6b6SChris Horne 	 * fill it in.
1047c478bd9Sstevel@tonic-gate 	 *
10553a7b6b6SChris Horne 	 * The inquiry data is allocated/refreshed by scsi_probe/scsi_slave
10653a7b6b6SChris Horne 	 * and freed by uninitchild (inquiry data is no longer freed by
10753a7b6b6SChris Horne 	 * scsi_unprobe/scsi_unslave).
1081e32c0dcScth 	 *
10953a7b6b6SChris Horne 	 * NOTE: Additional device identity information may be available
1101e32c0dcScth 	 * as properties of sd_dev.
1117c478bd9Sstevel@tonic-gate 	 */
1127c478bd9Sstevel@tonic-gate 	struct scsi_inquiry	*sd_inq;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	/*
1157c478bd9Sstevel@tonic-gate 	 * Place to point to an extended request sense buffer.
1167c478bd9Sstevel@tonic-gate 	 * The target driver is responsible for managing this.
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	struct scsi_extended_sense	*sd_sense;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	/*
12153a7b6b6SChris Horne 	 * Target driver 'private' information. Typically a pointer to target
12253a7b6b6SChris Horne 	 * driver private ddi_soft_state(9F) information for the device.  This
12353a7b6b6SChris Horne 	 * information is typically established in target driver attach(9E),
12453a7b6b6SChris Horne 	 * and freed in the target driver detach(9E).
12553a7b6b6SChris Horne 	 *
12653a7b6b6SChris Horne 	 * LEGACY: For a scsi_device structure allocated by scsi_vhci during
12753a7b6b6SChris Horne 	 * online of a path, this was set by scsi_vhci to point to the
12853a7b6b6SChris Horne 	 * pathinfo node. Please use sd_pathinfo instead.
1297c478bd9Sstevel@tonic-gate 	 */
13053a7b6b6SChris Horne 	void			*sd_private;
131602ca9eaScth 
132602ca9eaScth 	/*
133602ca9eaScth 	 * FMA capabilities of scsi_device.
134602ca9eaScth 	 */
135602ca9eaScth 	int			sd_fm_capable;
136602ca9eaScth 
13753a7b6b6SChris Horne 	/*
13853a7b6b6SChris Horne 	 * mdi_pathinfo_t pointer to pathinfo node for scsi_device structure
13953a7b6b6SChris Horne 	 * allocated by the scsi_vhci for transport to a specific pHCI path.
14053a7b6b6SChris Horne 	 */
14153a7b6b6SChris Horne 	void			*sd_pathinfo;
14253a7b6b6SChris Horne 
1434c06356bSdh 	/*
144c40ba10dSReed 	 * sd_uninit_prevent - Counter that prevents demotion of
145c40ba10dSReed 	 * DS_INITIALIZED node (esp loss of devi_addr) by causing
146c40ba10dSReed 	 * DDI_CTLOPS_UNINITCHILD failure - devi_ref will not protect
147c40ba10dSReed 	 * demotion of DS_INITIALIZED node.
148c40ba10dSReed 	 *
149c40ba10dSReed 	 * sd_tran_tgt_free_done - in some cases SCSA will call
150c40ba10dSReed 	 * tran_tgt_free(9E) independent of devinfo node state, this means
151c40ba10dSReed 	 * that uninitchild code should not call tran_tgt_free(9E).
1524c06356bSdh 	 */
153*e6e1c9deSJosef 'Jeff' Sipek 	unsigned		sd_uninit_prevent:16,
154c40ba10dSReed 				sd_tran_tgt_free_done:1,
155c40ba10dSReed 				sd_flags_pad:15;
1564c06356bSdh 
15753a7b6b6SChris Horne 	/*
15853a7b6b6SChris Horne 	 * The 'sd_tran_safe' field is a grotty hack that allows direct-access
15953a7b6b6SChris Horne 	 * (non-scsa) drivers (like chs, ata, and mlx - which all make cmdk
16053a7b6b6SChris Horne 	 * children) to *illegally* put their own vector in the scsi_address(9S)
16153a7b6b6SChris Horne 	 * 'a_hba_tran' field. When all the drivers that overwrite
16253a7b6b6SChris Horne 	 * 'a_hba_tran' are fixed, we can remove sd_tran_safe (and make
16353a7b6b6SChris Horne 	 * scsi_hba.c code trust that the 'sd_address.a_hba_tran' established
16453a7b6b6SChris Horne 	 * during initchild is still valid when uninitchild occurs).
16553a7b6b6SChris Horne 	 *
16653a7b6b6SChris Horne 	 * NOTE: This hack is also shows up in the DEVP_TO_TRAN implementation
16753a7b6b6SChris Horne 	 * in scsi_confsubr.c.
16853a7b6b6SChris Horne 	 *
16953a7b6b6SChris Horne 	 * NOTE: The 'sd_tran_safe' field is only referenced by SCSA framework
17053a7b6b6SChris Horne 	 * code, so always keeping it at the end of the scsi_device structure
17153a7b6b6SChris Horne 	 * (until it can be removed) is OK.  It use to be called 'sd_reserved'.
17253a7b6b6SChris Horne 	 */
17353a7b6b6SChris Horne 	struct scsi_hba_tran	*sd_tran_safe;
17453a7b6b6SChris Horne 
175602ca9eaScth #ifdef	SCSI_SIZE_CLEAN_VERIFY
176602ca9eaScth 	/*
177602ca9eaScth 	 * Must be last: Building a driver with-and-without
178602ca9eaScth 	 * -DSCSI_SIZE_CLEAN_VERIFY, and checking driver modules for
179602ca9eaScth 	 * differences with a tools like 'wsdiff' allows a developer to verify
180602ca9eaScth 	 * that their driver has no dependencies on scsi*(9S) size.
181602ca9eaScth 	 */
182602ca9eaScth 	int			_pad[8];
183602ca9eaScth #endif	/* SCSI_SIZE_CLEAN_VERIFY */
1847c478bd9Sstevel@tonic-gate };
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
18735666b87SChris Horne 
18835666b87SChris Horne /* ==== The following interfaces are public ==== */
18935666b87SChris Horne 
19053a7b6b6SChris Horne int	scsi_probe(struct scsi_device *sd, int (*callback)(void));
19153a7b6b6SChris Horne void	scsi_unprobe(struct scsi_device *sd);
19253a7b6b6SChris Horne 
19335666b87SChris Horne /* ==== The following interfaces are private (currently) ==== */
19435666b87SChris Horne 
19535666b87SChris Horne char	*scsi_device_unit_address(struct scsi_device *sd);
19653a7b6b6SChris Horne 
19735666b87SChris Horne /*
19835666b87SChris Horne  * scsi_device_prop_*() property interfaces: flags
19935666b87SChris Horne  *
20035666b87SChris Horne  *   SCSI_DEVICE_PROP_PATH: property of path-to-device.
20135666b87SChris Horne  *	The property is associated with the sd_pathinfo pathinfo node
20235666b87SChris Horne  *	as established by scsi_vhci. If sd_pathinfo is NULL then the
20335666b87SChris Horne  *	property is associated with the sd_dev devinfo node.
20435666b87SChris Horne  *	Implementation uses mdi_prop_*() interfaces applied to
20535666b87SChris Horne  *	mdi_pathinfo_t (sd_pathinfo) nodes.
20635666b87SChris Horne  *
20735666b87SChris Horne  *   SCSI_DEVICE_PROP_DEVICE: property of device.
20835666b87SChris Horne  *	The property is always associated with the sd_dev devinfo
20935666b87SChris Horne  *	node.  Implementation uses ndi_prop_*() interfaces applied
21035666b87SChris Horne  *	dev_info_t (sd_dev) nodes.
21135666b87SChris Horne  */
21235666b87SChris Horne #define	SCSI_DEVICE_PROP_PATH		0x1	/* type is property-of-path */
21335666b87SChris Horne #define	SCSI_DEVICE_PROP_DEVICE		0x2	/* type is property-of-device */
21435666b87SChris Horne #define	SCSI_DEVICE_PROP_TYPE_MSK	0xF
21535666b87SChris Horne 
21635666b87SChris Horne int	scsi_device_prop_get_int(struct scsi_device *sd,
21735666b87SChris Horne 	    uint_t flags, char *name, int defvalue);
21835666b87SChris Horne int64_t	scsi_device_prop_get_int64(struct scsi_device *,
21935666b87SChris Horne 	    uint_t flags, char *name, int64_t defvalue);
22035666b87SChris Horne 
22135666b87SChris Horne int	scsi_device_prop_lookup_byte_array(struct scsi_device *sd,
22235666b87SChris Horne 	    uint_t flags, char *name, uchar_t **, uint_t *);
22335666b87SChris Horne int	scsi_device_prop_lookup_int_array(struct scsi_device *sd,
22435666b87SChris Horne 	    uint_t flags, char *name, int **, uint_t *);
22535666b87SChris Horne int	scsi_device_prop_lookup_string(struct scsi_device *sd,
22635666b87SChris Horne 	    uint_t flags, char *name, char **);
22735666b87SChris Horne int	scsi_device_prop_lookup_string_array(struct scsi_device *sd,
22835666b87SChris Horne 	    uint_t flags, char *name, char ***, uint_t *);
22935666b87SChris Horne 
23035666b87SChris Horne int	scsi_device_prop_update_byte_array(struct scsi_device *sd,
23135666b87SChris Horne 	    uint_t flags, char *name, uchar_t *, uint_t);
23235666b87SChris Horne int	scsi_device_prop_update_int(struct scsi_device *sd,
23335666b87SChris Horne 	    uint_t flags, char *name, int);
23435666b87SChris Horne int	scsi_device_prop_update_int64(struct scsi_device *sd,
23535666b87SChris Horne 	    uint_t flags, char *name, int64_t);
23635666b87SChris Horne int	scsi_device_prop_update_int_array(struct scsi_device *sd,
23735666b87SChris Horne 	    uint_t flags, char *name, int *, uint_t);
23835666b87SChris Horne int	scsi_device_prop_update_string(struct scsi_device *sd,
23935666b87SChris Horne 	    uint_t flags, char *name, char *);
24035666b87SChris Horne int	scsi_device_prop_update_string_array(struct scsi_device *sd,
24135666b87SChris Horne 	    uint_t flags, char *name, char **, uint_t);
24235666b87SChris Horne 
24335666b87SChris Horne int	scsi_device_prop_remove(struct scsi_device *sd,
24435666b87SChris Horne 	    uint_t flags, char *name);
24535666b87SChris Horne void	scsi_device_prop_free(struct scsi_device *sd,
24635666b87SChris Horne 	    uint_t flags, void *data);
24735666b87SChris Horne 
24835666b87SChris Horne /* SCSI_HBA_ADDR_COMPLEX interfaces */
24953a7b6b6SChris Horne struct scsi_device	*scsi_address_device(struct scsi_address *sa);
25053a7b6b6SChris Horne void	scsi_device_hba_private_set(struct scsi_device *sd, void *data);
25153a7b6b6SChris Horne void	*scsi_device_hba_private_get(struct scsi_device *sd);
25253a7b6b6SChris Horne 
25335666b87SChris Horne /* ==== The following interfaces are private ==== */
25435666b87SChris Horne 
25535666b87SChris Horne size_t	scsi_device_size();
25635666b87SChris Horne 
25735666b87SChris Horne /* ==== The following interfaces are obsolete ==== */
25835666b87SChris Horne 
25953a7b6b6SChris Horne int	scsi_slave(struct scsi_device *sd, int (*callback)(void));
26053a7b6b6SChris Horne void	scsi_unslave(struct scsi_device *sd);
26135666b87SChris Horne 
2627c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate #endif
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate #endif	/* _SYS_SCSI_CONF_DEVICE_H */
269