xref: /illumos-gate/usr/src/uts/common/sys/scsi/impl/scsi_sas.h (revision 56f33205c9ed776c3c909e07d52e94610a675740)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_SCSI_IMPL_SCSI_SAS_H
27 #define	_SYS_SCSI_IMPL_SCSI_SAS_H
28 
29 #include <sys/types.h>
30 #include <sys/scsi/impl/usmp.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #if defined(_KERNEL)
37 /*
38  * Phymap support
39  */
40 typedef struct __sas_phymap    sas_phymap_t;
41 typedef enum { PHYMAP_MODE_SIMPLE } sas_phymap_mode_t;
42 typedef void (*sas_phymap_activate_cb_t)
43 		(void *phymap_priv, char *ua, void **ua_privp);
44 typedef void (*sas_phymap_deactivate_cb_t)
45 		(void *phymap_priv, char *ua, void *ua_priv);
46 
47 extern int	sas_phymap_create(dev_info_t		*hba_dip,
48 				clock_t			settle_us,
49 				sas_phymap_mode_t	mode,
50 				void			*mode_argument,
51 				void			*phymap_priv,
52 				sas_phymap_activate_cb_t activate_cb,
53 				sas_phymap_deactivate_cb_t deactivate_cb,
54 				sas_phymap_t		**phymapp);
55 void		sas_phymap_destroy(sas_phymap_t		*phymap);
56 
57 extern int	sas_phymap_phy_add(sas_phymap_t		*phymap,
58 				int			phy,
59 				uint64_t		local_sas_address,
60 				uint64_t		remote_sas_address);
61 extern int	sas_phymap_phy_rem(sas_phymap_t		*phymap,
62 				int			phy);
63 
64 extern char	*sas_phymap_lookup_ua(sas_phymap_t	*phymap,
65 				uint64_t		local_sas_address,
66 				uint64_t		remote_sas_address);
67 extern void	*sas_phymap_lookup_uapriv(sas_phymap_t	*phymap,
68 				char			*ua);
69 
70 extern char	*sas_phymap_phy2ua(sas_phymap_t		*phymap,
71 				int			phy);
72 void		sas_phymap_ua_free(char	*);
73 
74 extern int	sas_phymap_uahasphys(sas_phymap_t	*phymap,
75 				char			*ua);
76 
77 typedef struct __sas_phymap_phys	sas_phymap_phys_t;
78 extern sas_phymap_phys_t *sas_phymap_ua2phys(sas_phymap_t *phymap,
79 				char			*ua);
80 extern int	sas_phymap_phys_next(sas_phymap_phys_t	*phys);
81 void		sas_phymap_phys_free(sas_phymap_phys_t	*phys);
82 #endif /* defined(_KERNEL) */
83 
84 
85 
86 #define	KSTAT_SAS_PHY_CLASS	"SAS_phy_stat"
87 /*
88  * Format of the ks_name field for SAS Phy Stat
89  *
90  * driver_name.initiator_port_SAS_address.initiator_port_instance_number.phyid
91  * Example: pmcs.5000c50000d756aa.2.0
92  *
93  * driver_name:
94  *     driver name from di_driver_name() on SAS initiator port devinfo node.
95  *
96  * initiator_port_SAS_address:
97  *     SAS address of the initiator port that phy stat is reported for.
98  *
99  * initiator_port_instance_number:
100  *     instance number of the initiator port that phy stat is reported for.
101  *
102  * phyid:
103  *     prop phyIdentifier under initiator port node.
104  */
105 
106 /* Port Protocol - kstat structure definition */
107 typedef struct sas_port_protocol_stats {
108 	kstat_named_t	seconds_since_last_reset;
109 	kstat_named_t	input_requests;
110 	kstat_named_t	output_requests;
111 	kstat_named_t	control_requests;
112 	kstat_named_t	input_megabytes;
113 	kstat_named_t	output_megabytes;
114 } sas_port_protocol_stats_t;
115 
116 /* Port - kstat structure definition */
117 typedef struct sas_port_stats {
118 	kstat_named_t	seconds_since_last_reset;
119 	kstat_named_t	tx_frames;
120 	kstat_named_t	tx_words;
121 	kstat_named_t	rx_frames;
122 	kstat_named_t	rx_words;
123 } sas_port_stats_t;
124 
125 /* PHY - kstat structure definition */
126 typedef struct sas_phy_stats {
127 	kstat_named_t	seconds_since_last_reset;
128 	kstat_named_t	tx_frames;
129 	kstat_named_t	tx_words;
130 	kstat_named_t	rx_frames;
131 	kstat_named_t	rx_words;
132 	kstat_named_t	invalid_dword_count;
133 	kstat_named_t	running_disparity_error_count;
134 	kstat_named_t	loss_of_dword_sync_count;
135 	kstat_named_t	phy_reset_problem_count;
136 } sas_phy_stats_t;
137 
138 /*
139  * Supported Protocol property
140  */
141 #define	SAS_PROTOCOL_SSP	0x00000001
142 #define	SAS_PROTOCOL_STP	0x00000010
143 #define	SAS_PROTOCOL_SMP	0x00000100
144 #define	SAS_PROTOCOL_SATA	0x00001000
145 
146 
147 /*
148  * Definition - Negotiated Physical Link Rate
149  * Based on Table 288 (Section 10.4.3.10) of the spec (SAS-2 r-15), these
150  * constants represent "Negotiated physical link rate"
151  * (and implicitly the State of the phy).
152  */
153 #define	SAS_LINK_RATE_UNKNOWN		0x0 /* Phy is enabled. */
154 					    /* Speed is unknown */
155 #define	SAS_LINK_RATE_DISABLED		0x1 /* Phy is disabled. */
156 					    /* Speed is undefined */
157 #define	SAS_LINK_RATE_FAILED		0x2 /* Phy is enabled. */
158 					    /* Failed speed negotiation. */
159 #define	SAS_LINK_RATE_SATASPINUP	0x3 /* Phy is enabled. */
160 					    /* Detected a SATA device and */
161 					    /* entered the SATA Spinup hold */
162 					    /* state */
163 #define	SAS_LINK_RATE_SATAPORTSEL	0x4 /* Phy enabled. */
164 					    /* The phy is attached to a */
165 					    /* Port Selector (SATA-2.6). */
166 #define	SAS_LINK_RATE_RESET_IN_PROGRESS	0x5 /* Phy is enabled. */
167 					    /* Expander is performing SMP */
168 					    /* PHY CONTROL Link/Hard Reset */
169 #define	SAS_LINK_RATE_PHY_UNSUPPORTED	0x6 /* Phy is enabled. */
170 					    /* Unsupported phy settings */
171 #define	SAS_LINK_RATE_RESERVED		0x7 /* Undefined. Reserved. */
172 #define	SAS_LINK_RATE_1_5GBIT		0x8 /* Phy enabled at 1.5 GBit/sec */
173 #define	SAS_LINK_RATE_3GBIT		0x9 /* Phy enabled at 3 GBit/sec */
174 #define	SAS_LINK_RATE_6GBIT		0xA /* Phy enabled at 6 GBit/sec. */
175 
176 
177 /*
178  * Definition - "phy-info" property
179  *
180  * The property is an nvlist_array that represents an array of the
181  * nvlists on a per HBA basis. The individual elements of the array
182  * (the nvlists) represent the following properties for each phy of the HBA
183  */
184 #define	SAS_PHY_INFO		"phy-info"		/* Phy property name */
185 #define	SAS_PHY_INFO_NVL	"phy-info-nvl"		/* NVL array name */
186 
187 #define	SAS_PHY_ID		"PhyIdentifier"		/* DATA_TYPE_UINT8 */
188 #define	SAS_NEG_LINK_RATE	"NegotiatedLinkRate"	/* DATA_TYPE_INT8 */
189 #define	SAS_PROG_MIN_LINK_RATE	"ProgrammedMinLinkRate"	/* DATA_TYPE_INT8 */
190 #define	SAS_HW_MIN_LINK_RATE	"HardwareMinLinkRate"	/* DATA_TYPE_INT8 */
191 #define	SAS_PROG_MAX_LINK_RATE	"ProgrammedMaxLinkRate"	/* DATA_TYPE_INT8 */
192 #define	SAS_HW_MAX_LINK_RATE	"HardwareMaxLinkRate"	/* DATA_TYPE_INT8 */
193 
194 
195 /*
196  * Phy-mask property names for the target port and attached port
197  */
198 #define	SCSI_ADDR_PROP_TARGET_PORT_PM	"target-port-pm"
199 #define	SCSI_ADDR_PROP_ATTACHED_PORT_PM	"attached-port-pm"
200 
201 
202 /*
203  * Event definitions
204  */
205 /* Event Class */
206 #define	EC_HBA				"EC_hba"
207 
208 /* Event Sub-Class */
209 #define	ESC_SAS_HBA_PORT_BROADCAST	"ESC_sas_hba_port_broadcast"
210 /* Event Types for above Subclass */
211 #define	SAS_PORT_BROADCAST_CHANGE	"port_broadcast_change"
212 #define	SAS_PORT_BROADCAST_SES		"port_broadcast_ses"
213 #define	SAS_PORT_BROADCAST_D24_0	"port_broadcast_d24_0"
214 #define	SAS_PORT_BROADCAST_D27_4	"port_broadcast_d27_4"
215 #define	SAS_PORT_BROADCAST_D01_4	"port_broadcast_d01_4"
216 #define	SAS_PORT_BROADCAST_D04_7	"port_broadcast_d04_7"
217 #define	SAS_PORT_BROADCAST_D16_7	"port_broadcast_d16_7"
218 #define	SAS_PORT_BROADCAST_D29_7	"port_broadcast_d29_7"
219 
220 /* Event Sub-Class */
221 #define	ESC_SAS_PHY_EVENT		"ESC_sas_phy_event"
222 /* Event Types for above Subclass */
223 #define	SAS_PHY_ONLINE			"port_online"
224 #define	SAS_PHY_OFFLINE			"port_offline"
225 #define	SAS_PHY_REMOVE			"port_remove"
226 
227 /* Event Payload Names */
228 #define	SAS_DRV_INST			"driver_instance"
229 #define	SAS_PORT_ADDR			"port_address"
230 #define	SAS_DEVFS_PATH			"devfs_path"
231 #define	SAS_EVENT_TYPE			"event_type"
232 #define	SAS_LINK_RATE			"link_rate"
233 /* SAS_PHY_ID - Defined Above */
234 
235 #ifdef	__cplusplus
236 }
237 #endif
238 
239 #endif	/* _SYS_SCSI_IMPL_SCSI_SAS_H */
240