xref: /illumos-gate/usr/src/uts/common/sys/scsi/impl/scsi_sas.h (revision 60aabb4ce92352f01733c518d6b6bb69e60b9113)
196c4a178SChris Horne /*
296c4a178SChris Horne  * CDDL HEADER START
396c4a178SChris Horne  *
496c4a178SChris Horne  * The contents of this file are subject to the terms of the
596c4a178SChris Horne  * Common Development and Distribution License (the "License").
696c4a178SChris Horne  * You may not use this file except in compliance with the License.
796c4a178SChris Horne  *
896c4a178SChris Horne  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
996c4a178SChris Horne  * or http://www.opensolaris.org/os/licensing.
1096c4a178SChris Horne  * See the License for the specific language governing permissions
1196c4a178SChris Horne  * and limitations under the License.
1296c4a178SChris Horne  *
1396c4a178SChris Horne  * When distributing Covered Code, include this CDDL HEADER in each
1496c4a178SChris Horne  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1596c4a178SChris Horne  * If applicable, add the following below this CDDL HEADER, with the
1696c4a178SChris Horne  * fields enclosed by brackets "[]" replaced with your own identifying
1796c4a178SChris Horne  * information: Portions Copyright [yyyy] [name of copyright owner]
1896c4a178SChris Horne  *
1996c4a178SChris Horne  * CDDL HEADER END
2096c4a178SChris Horne  */
2196c4a178SChris Horne /*
22658280b6SDavid Hollister  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
2396c4a178SChris Horne  */
2496c4a178SChris Horne 
2596c4a178SChris Horne #ifndef _SYS_SCSI_IMPL_SCSI_SAS_H
2696c4a178SChris Horne #define	_SYS_SCSI_IMPL_SCSI_SAS_H
2796c4a178SChris Horne 
2896c4a178SChris Horne #include <sys/types.h>
2996c4a178SChris Horne #include <sys/scsi/impl/usmp.h>
3096c4a178SChris Horne 
3196c4a178SChris Horne #ifdef	__cplusplus
3296c4a178SChris Horne extern "C" {
3396c4a178SChris Horne #endif
3496c4a178SChris Horne 
3596c4a178SChris Horne #if defined(_KERNEL)
3696c4a178SChris Horne /*
3796c4a178SChris Horne  * Phymap support
3896c4a178SChris Horne  */
3996c4a178SChris Horne typedef struct __sas_phymap    sas_phymap_t;
4096c4a178SChris Horne typedef enum { PHYMAP_MODE_SIMPLE } sas_phymap_mode_t;
4196c4a178SChris Horne typedef void (*sas_phymap_activate_cb_t)
4296c4a178SChris Horne 		(void *phymap_priv, char *ua, void **ua_privp);
4396c4a178SChris Horne typedef void (*sas_phymap_deactivate_cb_t)
4496c4a178SChris Horne 		(void *phymap_priv, char *ua, void *ua_priv);
4596c4a178SChris Horne 
4696c4a178SChris Horne extern int	sas_phymap_create(dev_info_t		*hba_dip,
47*60aabb4cSChris Horne 				int			settle_usec,
4896c4a178SChris Horne 				sas_phymap_mode_t	mode,
4996c4a178SChris Horne 				void			*mode_argument,
5096c4a178SChris Horne 				void			*phymap_priv,
5196c4a178SChris Horne 				sas_phymap_activate_cb_t activate_cb,
5296c4a178SChris Horne 				sas_phymap_deactivate_cb_t deactivate_cb,
5396c4a178SChris Horne 				sas_phymap_t		**phymapp);
5496c4a178SChris Horne void		sas_phymap_destroy(sas_phymap_t		*phymap);
5596c4a178SChris Horne 
5696c4a178SChris Horne extern int	sas_phymap_phy_add(sas_phymap_t		*phymap,
5796c4a178SChris Horne 				int			phy,
5896c4a178SChris Horne 				uint64_t		local_sas_address,
5996c4a178SChris Horne 				uint64_t		remote_sas_address);
6096c4a178SChris Horne extern int	sas_phymap_phy_rem(sas_phymap_t		*phymap,
6196c4a178SChris Horne 				int			phy);
6296c4a178SChris Horne 
6396c4a178SChris Horne extern char	*sas_phymap_lookup_ua(sas_phymap_t	*phymap,
6496c4a178SChris Horne 				uint64_t		local_sas_address,
6596c4a178SChris Horne 				uint64_t		remote_sas_address);
6696c4a178SChris Horne extern void	*sas_phymap_lookup_uapriv(sas_phymap_t	*phymap,
6796c4a178SChris Horne 				char			*ua);
6896c4a178SChris Horne 
6996c4a178SChris Horne extern char	*sas_phymap_phy2ua(sas_phymap_t		*phymap,
7096c4a178SChris Horne 				int			phy);
7196c4a178SChris Horne void		sas_phymap_ua_free(char	*);
7296c4a178SChris Horne 
7396c4a178SChris Horne extern int	sas_phymap_uahasphys(sas_phymap_t	*phymap,
7496c4a178SChris Horne 				char			*ua);
7596c4a178SChris Horne 
7696c4a178SChris Horne typedef struct __sas_phymap_phys	sas_phymap_phys_t;
7796c4a178SChris Horne extern sas_phymap_phys_t *sas_phymap_ua2phys(sas_phymap_t *phymap,
7896c4a178SChris Horne 				char			*ua);
7996c4a178SChris Horne extern int	sas_phymap_phys_next(sas_phymap_phys_t	*phys);
8096c4a178SChris Horne void		sas_phymap_phys_free(sas_phymap_phys_t	*phys);
8196c4a178SChris Horne #endif /* defined(_KERNEL) */
8296c4a178SChris Horne 
8396c4a178SChris Horne 
8496c4a178SChris Horne 
8596c4a178SChris Horne #define	KSTAT_SAS_PHY_CLASS	"SAS_phy_stat"
8696c4a178SChris Horne /*
8796c4a178SChris Horne  * Format of the ks_name field for SAS Phy Stat
8896c4a178SChris Horne  *
8996c4a178SChris Horne  * driver_name.initiator_port_SAS_address.initiator_port_instance_number.phyid
9096c4a178SChris Horne  * Example: pmcs.5000c50000d756aa.2.0
9196c4a178SChris Horne  *
9296c4a178SChris Horne  * driver_name:
9396c4a178SChris Horne  *     driver name from di_driver_name() on SAS initiator port devinfo node.
9496c4a178SChris Horne  *
9596c4a178SChris Horne  * initiator_port_SAS_address:
9696c4a178SChris Horne  *     SAS address of the initiator port that phy stat is reported for.
9796c4a178SChris Horne  *
9896c4a178SChris Horne  * initiator_port_instance_number:
9996c4a178SChris Horne  *     instance number of the initiator port that phy stat is reported for.
10096c4a178SChris Horne  *
10196c4a178SChris Horne  * phyid:
10296c4a178SChris Horne  *     prop phyIdentifier under initiator port node.
10396c4a178SChris Horne  */
10496c4a178SChris Horne 
10596c4a178SChris Horne /* Port Protocol - kstat structure definition */
10696c4a178SChris Horne typedef struct sas_port_protocol_stats {
10796c4a178SChris Horne 	kstat_named_t	seconds_since_last_reset;
10896c4a178SChris Horne 	kstat_named_t	input_requests;
10996c4a178SChris Horne 	kstat_named_t	output_requests;
11096c4a178SChris Horne 	kstat_named_t	control_requests;
11196c4a178SChris Horne 	kstat_named_t	input_megabytes;
11296c4a178SChris Horne 	kstat_named_t	output_megabytes;
11396c4a178SChris Horne } sas_port_protocol_stats_t;
11496c4a178SChris Horne 
11596c4a178SChris Horne /* Port - kstat structure definition */
11696c4a178SChris Horne typedef struct sas_port_stats {
11796c4a178SChris Horne 	kstat_named_t	seconds_since_last_reset;
11896c4a178SChris Horne 	kstat_named_t	tx_frames;
11996c4a178SChris Horne 	kstat_named_t	tx_words;
12096c4a178SChris Horne 	kstat_named_t	rx_frames;
12196c4a178SChris Horne 	kstat_named_t	rx_words;
12296c4a178SChris Horne } sas_port_stats_t;
12396c4a178SChris Horne 
12496c4a178SChris Horne /* PHY - kstat structure definition */
12596c4a178SChris Horne typedef struct sas_phy_stats {
12696c4a178SChris Horne 	kstat_named_t	seconds_since_last_reset;
12796c4a178SChris Horne 	kstat_named_t	tx_frames;
12896c4a178SChris Horne 	kstat_named_t	tx_words;
12996c4a178SChris Horne 	kstat_named_t	rx_frames;
13096c4a178SChris Horne 	kstat_named_t	rx_words;
13196c4a178SChris Horne 	kstat_named_t	invalid_dword_count;
13296c4a178SChris Horne 	kstat_named_t	running_disparity_error_count;
13396c4a178SChris Horne 	kstat_named_t	loss_of_dword_sync_count;
13496c4a178SChris Horne 	kstat_named_t	phy_reset_problem_count;
13596c4a178SChris Horne } sas_phy_stats_t;
13696c4a178SChris Horne 
13796c4a178SChris Horne /*
13896c4a178SChris Horne  * Supported Protocol property
13996c4a178SChris Horne  */
14096c4a178SChris Horne #define	SAS_PROTOCOL_SSP	0x00000001
14196c4a178SChris Horne #define	SAS_PROTOCOL_STP	0x00000010
14296c4a178SChris Horne #define	SAS_PROTOCOL_SMP	0x00000100
14396c4a178SChris Horne #define	SAS_PROTOCOL_SATA	0x00001000
14496c4a178SChris Horne 
14596c4a178SChris Horne 
14696c4a178SChris Horne /*
14796c4a178SChris Horne  * Definition - Negotiated Physical Link Rate
14896c4a178SChris Horne  * Based on Table 288 (Section 10.4.3.10) of the spec (SAS-2 r-15), these
14996c4a178SChris Horne  * constants represent "Negotiated physical link rate"
15096c4a178SChris Horne  * (and implicitly the State of the phy).
15196c4a178SChris Horne  */
15296c4a178SChris Horne #define	SAS_LINK_RATE_UNKNOWN		0x0 /* Phy is enabled. */
15396c4a178SChris Horne 					    /* Speed is unknown */
15496c4a178SChris Horne #define	SAS_LINK_RATE_DISABLED		0x1 /* Phy is disabled. */
15596c4a178SChris Horne 					    /* Speed is undefined */
15696c4a178SChris Horne #define	SAS_LINK_RATE_FAILED		0x2 /* Phy is enabled. */
15796c4a178SChris Horne 					    /* Failed speed negotiation. */
15896c4a178SChris Horne #define	SAS_LINK_RATE_SATASPINUP	0x3 /* Phy is enabled. */
15996c4a178SChris Horne 					    /* Detected a SATA device and */
16096c4a178SChris Horne 					    /* entered the SATA Spinup hold */
16196c4a178SChris Horne 					    /* state */
16296c4a178SChris Horne #define	SAS_LINK_RATE_SATAPORTSEL	0x4 /* Phy enabled. */
16396c4a178SChris Horne 					    /* The phy is attached to a */
16496c4a178SChris Horne 					    /* Port Selector (SATA-2.6). */
16596c4a178SChris Horne #define	SAS_LINK_RATE_RESET_IN_PROGRESS	0x5 /* Phy is enabled. */
16696c4a178SChris Horne 					    /* Expander is performing SMP */
16796c4a178SChris Horne 					    /* PHY CONTROL Link/Hard Reset */
16896c4a178SChris Horne #define	SAS_LINK_RATE_PHY_UNSUPPORTED	0x6 /* Phy is enabled. */
16996c4a178SChris Horne 					    /* Unsupported phy settings */
17096c4a178SChris Horne #define	SAS_LINK_RATE_RESERVED		0x7 /* Undefined. Reserved. */
17196c4a178SChris Horne #define	SAS_LINK_RATE_1_5GBIT		0x8 /* Phy enabled at 1.5 GBit/sec */
17296c4a178SChris Horne #define	SAS_LINK_RATE_3GBIT		0x9 /* Phy enabled at 3 GBit/sec */
17396c4a178SChris Horne #define	SAS_LINK_RATE_6GBIT		0xA /* Phy enabled at 6 GBit/sec. */
17496c4a178SChris Horne 
17596c4a178SChris Horne 
17696c4a178SChris Horne /*
17796c4a178SChris Horne  * Definition - "phy-info" property
17896c4a178SChris Horne  *
17996c4a178SChris Horne  * The property is an nvlist_array that represents an array of the
18096c4a178SChris Horne  * nvlists on a per HBA basis. The individual elements of the array
18196c4a178SChris Horne  * (the nvlists) represent the following properties for each phy of the HBA
18296c4a178SChris Horne  */
18396c4a178SChris Horne #define	SAS_PHY_INFO		"phy-info"		/* Phy property name */
18496c4a178SChris Horne #define	SAS_PHY_INFO_NVL	"phy-info-nvl"		/* NVL array name */
18596c4a178SChris Horne 
18696c4a178SChris Horne #define	SAS_PHY_ID		"PhyIdentifier"		/* DATA_TYPE_UINT8 */
18796c4a178SChris Horne #define	SAS_NEG_LINK_RATE	"NegotiatedLinkRate"	/* DATA_TYPE_INT8 */
18896c4a178SChris Horne #define	SAS_PROG_MIN_LINK_RATE	"ProgrammedMinLinkRate"	/* DATA_TYPE_INT8 */
18996c4a178SChris Horne #define	SAS_HW_MIN_LINK_RATE	"HardwareMinLinkRate"	/* DATA_TYPE_INT8 */
19096c4a178SChris Horne #define	SAS_PROG_MAX_LINK_RATE	"ProgrammedMaxLinkRate"	/* DATA_TYPE_INT8 */
19196c4a178SChris Horne #define	SAS_HW_MAX_LINK_RATE	"HardwareMaxLinkRate"	/* DATA_TYPE_INT8 */
19296c4a178SChris Horne 
19396c4a178SChris Horne 
19496c4a178SChris Horne /*
195658280b6SDavid Hollister  * Phy-mask property names for the target port, attached port and receptacle
196499cfd15SDavid Hollister  */
197499cfd15SDavid Hollister #define	SCSI_ADDR_PROP_TARGET_PORT_PM	"target-port-pm"
198499cfd15SDavid Hollister #define	SCSI_ADDR_PROP_ATTACHED_PORT_PM	"attached-port-pm"
199658280b6SDavid Hollister #define	SCSI_HBA_PROP_RECEPTACLE_PM	"receptacle-pm"
200658280b6SDavid Hollister 
201658280b6SDavid Hollister /*
202658280b6SDavid Hollister  * Target port depth property names - Indicates the number of expanders
203658280b6SDavid Hollister  * between the initiator port and the target port
204658280b6SDavid Hollister  */
205658280b6SDavid Hollister #define	SCSI_ADDR_PROP_TARGET_PORT_DEPTH	"target-port-depth"
206499cfd15SDavid Hollister 
207499cfd15SDavid Hollister 
208499cfd15SDavid Hollister /*
20996c4a178SChris Horne  * Event definitions
21096c4a178SChris Horne  */
21196c4a178SChris Horne /* Event Class */
21296c4a178SChris Horne #define	EC_HBA				"EC_hba"
21396c4a178SChris Horne 
21496c4a178SChris Horne /* Event Sub-Class */
21596c4a178SChris Horne #define	ESC_SAS_HBA_PORT_BROADCAST	"ESC_sas_hba_port_broadcast"
21696c4a178SChris Horne /* Event Types for above Subclass */
21796c4a178SChris Horne #define	SAS_PORT_BROADCAST_CHANGE	"port_broadcast_change"
21896c4a178SChris Horne #define	SAS_PORT_BROADCAST_SES		"port_broadcast_ses"
21996c4a178SChris Horne #define	SAS_PORT_BROADCAST_D24_0	"port_broadcast_d24_0"
22096c4a178SChris Horne #define	SAS_PORT_BROADCAST_D27_4	"port_broadcast_d27_4"
22196c4a178SChris Horne #define	SAS_PORT_BROADCAST_D01_4	"port_broadcast_d01_4"
22296c4a178SChris Horne #define	SAS_PORT_BROADCAST_D04_7	"port_broadcast_d04_7"
22396c4a178SChris Horne #define	SAS_PORT_BROADCAST_D16_7	"port_broadcast_d16_7"
22496c4a178SChris Horne #define	SAS_PORT_BROADCAST_D29_7	"port_broadcast_d29_7"
22596c4a178SChris Horne 
22696c4a178SChris Horne /* Event Sub-Class */
22796c4a178SChris Horne #define	ESC_SAS_PHY_EVENT		"ESC_sas_phy_event"
22896c4a178SChris Horne /* Event Types for above Subclass */
22996c4a178SChris Horne #define	SAS_PHY_ONLINE			"port_online"
23096c4a178SChris Horne #define	SAS_PHY_OFFLINE			"port_offline"
23196c4a178SChris Horne #define	SAS_PHY_REMOVE			"port_remove"
23296c4a178SChris Horne 
23396c4a178SChris Horne /* Event Payload Names */
23496c4a178SChris Horne #define	SAS_DRV_INST			"driver_instance"
23596c4a178SChris Horne #define	SAS_PORT_ADDR			"port_address"
23696c4a178SChris Horne #define	SAS_DEVFS_PATH			"devfs_path"
23796c4a178SChris Horne #define	SAS_EVENT_TYPE			"event_type"
23896c4a178SChris Horne #define	SAS_LINK_RATE			"link_rate"
23996c4a178SChris Horne /* SAS_PHY_ID - Defined Above */
24096c4a178SChris Horne 
24196c4a178SChris Horne #ifdef	__cplusplus
24296c4a178SChris Horne }
24396c4a178SChris Horne #endif
24496c4a178SChris Horne 
24596c4a178SChris Horne #endif	/* _SYS_SCSI_IMPL_SCSI_SAS_H */
246