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 /*
23  * Copyright 2009 Emulex.  All rights reserved.
24  * Use is subject to License terms.
25  */
26 
27 
28 #ifndef _EMLXS_SDAPI_H
29 #define	_EMLXS_SDAPI_H
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Although information in this file can be used by app, libdfc or driver,
37  * its purpose is for communication between app and libdfc.
38  * Its content come from the SAN Diag API Specification.
39  */
40 
41 
42 /* Define for refering SCSI_IO_LATENCY */
43 #define	SD_SCSI_IO_LATENCY_TYPE		0x01
44 
45 #define	SD_IO_LATENCY_MAX_BUCKETS	20	/* Size of array range */
46 
47 /* Masks for ELS Commands */
48 #define	SD_ELS_SUBCATEGORY_PLOGI_RCV	0x01
49 #define	SD_ELS_SUBCATEGORY_PRLO_RCV	0x02
50 #define	SD_ELS_SUBCATEGORY_ADISC_RCV	0x04
51 #define	SD_ELS_SUBCATEGORY_LSRJT_RCV	0x08
52 #define	SD_ELS_SUBCATEGORY_LOGO_RCV	0x10
53 #define	SD_ELS_SUBCATEGORY_RSCN_RCV	0x20
54 
55 /* Masks for Fabric events */
56 #define	SD_FABRIC_SUBCATEGORY_FABRIC_BUSY	0x01
57 #define	SD_FABRIC_SUBCATEGORY_PORT_BUSY		0x02
58 #define	SD_FABRIC_SUBCATEGORY_FCPRDCHKERR	0x04
59 
60 /* Masks for SCSI events */
61 #define	SD_SCSI_SUBCATEGORY_QFULL			0x0001
62 #define	SD_SCSI_SUBCATEGORY_DEVBSY			0x0002
63 #define	SD_SCSI_SUBCATEGORY_CHECKCONDITION		0x0004
64 #define	SD_SCSI_SUBCATEGORY_LUNRESET			0x0008
65 #define	SD_SCSI_SUBCATEGORY_TGTRESET			0x0010
66 #define	SD_SCSI_SUBCATEGORY_BUSRESET			0x0020
67 #define	SD_SCSI_SUBCATEGORY_VARQUEDEPTH			0x0040
68 
69 /* Masks for Board Events */
70 #define	SD_BOARD_SUBCATEGORY_PORTINTERR		0x01
71 #define	SD_BOARD_SUBCATEGORY_LINKATTE		0x02
72 
73 /* Masks for Adapter Events */
74 #define	SD_ADAPTER_SUBCATEGORY_ARRIVAL		0x01
75 #define	SD_ADAPTER_SUBCATEGORY_DEPARTURE	0x02
76 
77 /* Struct to hold SCSI IO Latency statistics per bucket */
78 struct SD_time_stats_v0 {
79 	int sd_tstats_bucket_count;
80 };
81 
82 /* Struct per target for SCSI IO Latency */
83 struct SD_IO_Latency_Response {
84 	HBA_WWN sd_iolatency_target_wwpn;
85 	/* Size of array depends on range size */
86 	struct SD_time_stats_v0 sd_time_stats_array[SD_IO_LATENCY_MAX_BUCKETS];
87 };
88 
89 /* Return Codes */
90 enum SD_RETURN_CODES {
91 	SD_OK,
92 	SD_ERROR_GENERIC,
93 	SD_ERROR_ARG,
94 	SD_ERROR_INVALID_BOARD_ID,
95 	SD_ERROR_INVALID_VPORT,
96 	SD_ERROR_NOT_SUPPORTED,
97 	SD_ERROR_CATEGORY_NOT_SUPPORTED,
98 	SD_ERROR_SUBCATEGORY_NOT_SUPPORTED,
99 	SD_ERROR_MORE_DATA_AVAILABLE,
100 	SD_ERROR_EVENT_ALREADY_REGISTERED,
101 	SD_ERROR_NO_ACTIVE_REGISTRATION,
102 	SD_ERROR_ARG_MISSING,
103 	SD_ERROR_NO_MEMORY,
104 	SD_ERROR_BUCKET_NOTSET,
105 	SD_ERROR_REG_HANDLE,
106 	SD_ERROR_INVALID_SEARCH_TYPE,
107 	SD_ERROR_FUNCTION_NOT_SUPPORTED,
108 	SD_ERROR_OUT_OF_HANDLES,
109 	SD_ERROR_LIB_NOT_INIT,
110 	SD_ERROR_DATA_COLLECTION_ACTIVE,
111 	SD_ERROR_DATA_COLLECTION_NOT_ACTIVE,
112 	SD_MAX_RETURN_CODES
113 };
114 
115 
116 #define	SD_SEARCH_LINEAR	0x01
117 #define	SD_SEARCH_POWER_2	0x02
118 
119 
120 extern uint32_t	DFC_SD_Get_Granularity(void);
121 
122 extern int32_t	DFC_SD_Set_Bucket(uint16_t type,
123 				uint16_t search_type,
124 				uint32_t base,
125 				uint32_t step);
126 
127 extern int32_t	DFC_SD_Destroy_Bucket(uint16_t type);
128 
129 extern int32_t	DFC_SD_Get_Bucket(uint16_t type,
130 				uint16_t *search_type,
131 				uint32_t *base,
132 				uint32_t *step,
133 				uint64_t *values);
134 
135 extern int32_t	DFC_SD_Start_Data_Collection(uint32_t board,
136 				HBA_WWN port_id,
137 				uint16_t type,
138 				void *arg);
139 
140 extern int32_t	DFC_SD_Stop_Data_Collection(uint32_t board,
141 				HBA_WWN port_id,
142 				uint16_t type);
143 
144 extern int32_t	DFC_SD_Reset_Data_Collection(uint32_t board,
145 				HBA_WWN port_id,
146 				uint16_t type);
147 
148 extern int32_t	DFC_SD_Get_Data(uint32_t board,
149 				HBA_WWN port_id,
150 				uint16_t type,
151 				uint16_t *target,
152 				uint32_t buf_size,
153 				void *buff);
154 
155 #define	SD_REG_ELS_EVENT	0x01
156 #define	SD_REG_FABRIC_EVENT	0x02
157 #define	SD_REG_SCSI_EVENT	0x04
158 #define	SD_REG_BOARD_EVENT	0x08
159 #define	SD_REG_ADAPTER_EVENT	0x10
160 
161 
162 #define	SD_ELS_SUBCATEGORY_VALID_MASK	(SD_ELS_SUBCATEGORY_PLOGI_RCV | \
163 	SD_ELS_SUBCATEGORY_PRLO_RCV | SD_ELS_SUBCATEGORY_ADISC_RCV | \
164 	SD_ELS_SUBCATEGORY_LSRJT_RCV | SD_ELS_SUBCATEGORY_LOGO_RCV | \
165 	SD_ELS_SUBCATEGORY_RSCN_RCV)
166 
167 
168 /* Generic Payload */
169 struct sd_event {
170 	uint32_t	sd_evt_version;
171 	size_t		sd_evt_size;
172 	void		*sd_evt_payload;
173 };
174 
175 
176 struct sd_els_event_details_v0 {
177 	uint32_t	sd_elsevt_version;
178 	void		*sd_elsevt_payload;
179 };
180 
181 
182 struct sd_plogi_rcv_v0 {
183 	uint32_t	sd_plogir_version;
184 	HBA_WWN		sd_plogir_portname;
185 	HBA_WWN		sd_plogir_nodename;
186 };
187 
188 
189 struct sd_prlo_rcv_v0 {
190 	uint32_t	sd_prlor_version;
191 	HBA_WWN		sd_prlor_remoteport;
192 };
193 
194 
195 struct sd_lsrjt_rcv_v0 {
196 	uint32_t	sd_lsrjtr_version;
197 	HBA_WWN		sd_lsrjtr_remoteport;
198 	uint32_t	sd_lsrjtr_original_cmd;
199 	uint32_t	sd_lsrjtr_reasoncode;
200 	uint32_t	sd_lsrjtr_reasoncodeexpl;
201 };
202 
203 
204 struct sd_adisc_rcv_v0 {
205 	uint32_t	sd_adiscr_version;
206 	HBA_WWN		sd_adiscr_portname;
207 	HBA_WWN		sd_adiscr_nodename;
208 };
209 
210 
211 #define	SD_FABRIC_SUBCATEGORY_VALID_MASK	(\
212 	SD_FABRIC_SUBCATEGORY_FABRIC_BUSY | SD_FABRIC_SUBCATEGORY_PORT_BUSY | \
213 	SD_FABRIC_SUBCATEGORY_FCPRDCHKERR)
214 
215 
216 struct sd_fabric_event_details_v0 {
217 	uint32_t	sd_fabric_evt_version;
218 	void		*sd_fabric_evt_payload;
219 };
220 
221 
222 struct sd_pbsy_rcv_v0 {
223 	uint32_t	sd_pbsyr_evt_version;
224 	HBA_WWN		sd_pbsyr_rport;
225 };
226 
227 
228 struct sd_fcprdchkerr_v0 {
229 	uint32_t	sd_fcprdchkerr_version;
230 	HBA_WWN		sd_fcprdchkerr_rport;
231 	uint32_t	sd_fcprdchkerr_lun;
232 	uint32_t	sd_fcprdchkerr_opcode;
233 	uint32_t	sd_fcprdchkerr_fcpiparam;
234 };
235 
236 
237 #define	SD_SCSI_SUBCATEGORY_VALID_MASK	(\
238 	SD_SCSI_SUBCATEGORY_QFULL | SD_SCSI_SUBCATEGORY_DEVBSY | \
239 	SD_SCSI_SUBCATEGORY_CHECKCONDITION | SD_SCSI_SUBCATEGORY_LUNRESET | \
240 	SD_SCSI_SUBCATEGORY_TGTRESET | SD_SCSI_SUBCATEGORY_BUSRESET | \
241 	SD_SCSI_SUBCATEGORY_VARQUEDEPTH)
242 
243 struct sd_scsi_event_details_v0 {
244 	uint32_t	sd_scsi_evt_version;
245 	void		*sd_scsi_evt_payload;
246 };
247 
248 
249 struct sd_scsi_generic_v0 {
250 	uint32_t	sd_scsi_generic_version;
251 	HBA_WWN		sd_scsi_generic_rport;
252 	int32_t		sd_scsi_generic_lun;
253 };
254 
255 
256 struct sd_scsi_checkcond_v0 {
257 	uint32_t	sd_scsi_checkcond_version;
258 	HBA_WWN		sd_scsi_checkcond_rport;
259 	uint32_t	sd_scsi_checkcond_lun;
260 	uint32_t	sd_scsi_checkcond_cmdcode;
261 	uint32_t	sd_scsi_checkcond_sensekey;
262 	uint32_t	sd_scsi_checkcond_asc;
263 	uint32_t	sd_scsi_checkcond_ascq;
264 };
265 
266 
267 struct sd_scsi_varquedepth_v0 {
268 	uint32_t	sd_varquedepth_version;
269 	HBA_WWN		sd_varquedepth_rport;
270 	int32_t		sd_varquedepth_lun;
271 	uint32_t	sd_varquedepth_oldval;
272 	uint32_t	sd_varquedepth_newval;
273 };
274 
275 
276 /* Prototype for callback */
277 typedef void sd_callback(uint32_t board_id,
278 			HBA_WWN 	ort_id,
279 			uint32_t	category,
280 			uint32_t	subcategory,
281 			void		*context,
282 			struct sd_event	*sd_data);
283 
284 /* Register for event */
285 extern int32_t DFC_SD_RegisterForEvent(uint32_t board_id,
286 				HBA_WWN		port_id,
287 				uint32_t	category,
288 				uint32_t	subcategory,
289 				void		*context,
290 				uint32_t	*reg_handle,
291 				sd_callback	*func);
292 
293 
294 /* Deregister a event */
295 extern int32_t DFC_SD_unRegisterForEvent(uint32_t board_id,
296 				HBA_WWN		vport_id,
297 				uint32_t	reg_handle);
298 
299 
300 #ifdef	__cplusplus
301 }
302 #endif
303 
304 #endif	/* _EMLXS_SDAPI_H */
305