xref: /illumos-gate/usr/src/lib/scsi/plugins/ses/ses2/common/ses2_impl.h (revision e0731422366620894c16c1ee6515551c5f00733d)
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 (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef	_PLUGIN_SES_IMPL_H
27 #define	_PLUGIN_SES_IMPL_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/scsi/impl/uscsi.h>
36 #include <sys/scsi/generic/commands.h>
37 #include <sys/scsi/impl/spc3_types.h>
38 #include <sys/ccompile.h>
39 #include <stdarg.h>
40 #include <libnvpair.h>
41 
42 #include <scsi/libscsi.h>
43 #include <scsi/libses_plugin.h>
44 
45 #pragma	pack(1)
46 
47 /*
48  * Generic IO timeout in seconds, from <sys/scsi/targets/ses.h>.
49  */
50 #define	SES2_TIMEOUT	60
51 
52 /*
53  * SES-2 Enclosure Descriptor Header (Table 8, 6.1.2.2)
54  */
55 typedef struct ses2_ed_hdr_impl {
56 	DECL_BITFIELD4(
57 	    sehi_n_esps		:3,
58 	    _reserved1		:1,
59 	    sehi_rel_esp_id	:3,
60 	    _reserved2		:1);
61 	uint8_t sehi_subenclosure_id;
62 	uint8_t sehi_n_etd_hdrs;
63 	uint8_t sehi_ed_len;
64 } ses2_ed_hdr_impl_t;
65 
66 /*
67  * SES-2 Enclosure Descriptor (Table 8, 6.1.2.2)
68  */
69 typedef struct ses2_ed_impl {
70 	ses2_ed_hdr_impl_t st_hdr;
71 	spc3_naa_id_8_impl_t st_logical_id;
72 	char st_vendor_id[8];
73 	char st_product_id[16];
74 	char st_product_revision[4];
75 	uint8_t st_priv[1];
76 } ses2_ed_impl_t;
77 
78 /*
79  * SES-2 Type Descriptor Header (Table 9, 6.1.2.3)
80  */
81 typedef struct ses2_td_hdr_impl {
82 	uint8_t sthi_element_type;
83 	uint8_t sthi_max_elements;
84 	uint8_t sthi_subenclosure_id;
85 	uint8_t sthi_text_len;
86 } ses2_td_hdr_impl_t;
87 
88 /*
89  * SES-2 Configuration diagnostic page (Table 7, 6.1.2.1)
90  */
91 typedef struct ses2_config_page_impl {
92 	uint8_t scpi_page_code;
93 	uint8_t scpi_n_subenclosures;
94 	uint16_t scpi_page_length;
95 	uint32_t scpi_generation_code;
96 	uint8_t scpi_data[1];
97 } ses2_config_page_impl_t;
98 
99 /*
100  * Logically we should be able to use 4 or 8 bytes for a minimum allocation;
101  * however, it seems at least some devices will fail the request in that case.
102  */
103 #define	SES2_MIN_DIAGPAGE_ALLOC 512
104 
105 /*
106  * SES-2 Element Control and Overall Control fields (Table 59, 7.2.2)
107  */
108 typedef struct ses2_cmn_elem_ctl_impl {
109 	DECL_BITFIELD5(
110 	    _reserved1		:4,
111 	    seci_rst_swap	:1,
112 	    seci_disable	:1,
113 	    seci_prdfail	:1,
114 	    seci_select		:1);
115 } ses2_cmn_elem_ctl_impl_t;
116 
117 typedef struct ses2_elem_ctl_impl {
118 	ses2_cmn_elem_ctl_impl_t seci_common;
119 	uint8_t seci_data[3];
120 } ses2_elem_ctl_impl_t;
121 
122 /*
123  * SES-2 Element Status and Overall Status fields (Table 60, 7.2.3)
124  */
125 typedef struct ses2_cmn_elem_status_impl {
126 	DECL_BITFIELD5(
127 	    sesi_status_code	:4,
128 	    sesi_swap		:1,
129 	    sesi_disabled	:1,
130 	    sesi_prdfail	:1,
131 	    _reserved1		:1);
132 } ses2_cmn_elem_status_impl_t;
133 
134 typedef struct ses2_elem_status_impl {
135 	ses2_cmn_elem_status_impl_t sesi_common;
136 	uint8_t sesi_data[3];
137 } ses2_elem_status_impl_t;
138 
139 /*
140  * SES-2 Device element for the Enclosure Control diagnostic page.
141  */
142 typedef struct ses2_device_ctl_impl {
143 	ses2_cmn_elem_ctl_impl_t sdci_common;
144 	uint8_t _reserved1;
145 	DECL_BITFIELD8(
146 	    _reserved2		:1,
147 	    sdci_rqst_ident	:1,
148 	    sdci_rqst_remove	:1,
149 	    sdci_rqst_insert	:1,
150 	    sdci_rqst_missing	:1,
151 	    _reserved3		:1,
152 	    sdci_do_not_remove	:1,
153 	    sdci_rqst_active	:1);
154 	DECL_BITFIELD6(
155 	    _reserved4		:2,
156 	    sdci_enable_byp_b	:1,
157 	    sdci_enable_byp_a	:1,
158 	    sdci_device_off	:1,
159 	    sdci_rqst_fault	:1,
160 	    _reserved5		:2);
161 } ses2_device_ctl_impl_t;
162 
163 /*
164  * SES-2 Device element for the Enclosure Status diagnostic page
165  * (Table 64, 7.3.2).
166  */
167 typedef struct ses2_device_status_impl {
168 	ses2_cmn_elem_status_impl_t sdsi_common;
169 	uint8_t sdsi_slot_addr;
170 	DECL_BITFIELD8(
171 	    sdsi_report			:1,
172 	    sdsi_ident			:1,
173 	    sdsi_rmv			:1,
174 	    sdsi_ready_to_insert	:1,
175 	    sdsi_enclosure_bypassed_b	:1,
176 	    sdsi_enclosure_bypassed_a	:1,
177 	    sdsi_do_not_remove		:1,
178 	    sdsi_app_client_bypassed_a	:1);
179 	DECL_BITFIELD8(
180 	    sdsi_device_bypassed_b	:1,
181 	    sdsi_device_bypassed_a	:1,
182 	    sdsi_bypassed_b		:1,
183 	    sdsi_bypassed_a		:1,
184 	    sdsi_device_off		:1,
185 	    sdsi_fault_reqstd		:1,
186 	    sdsi_fault_sensed		:1,
187 	    sdsi_app_client_bypassed_b	:1);
188 } ses2_device_status_impl_t;
189 
190 typedef struct ses2_array_device_ctl_impl {
191 	ses2_cmn_elem_ctl_impl_t sadci_common;
192 	DECL_BITFIELD8(
193 	    sadci_rqst_rr_abort		:1,
194 	    sadci_rqst_rebuild		:1,
195 	    sadci_rqst_in_failed_array	:1,
196 	    sadci_rqst_in_crit_array	:1,
197 	    sadci_rqst_cons_check	:1,
198 	    sadci_rqst_hot_spare	:1,
199 	    sadci_rqst_rsvd_device	:1,
200 	    sadci_rqst_ok		:1);
201 	DECL_BITFIELD8(
202 	    _reserved1		:1,
203 	    sadci_rqst_ident	:1,
204 	    sadci_rqst_remove	:1,
205 	    sadci_rqst_insert	:1,
206 	    sadci_rqst_missing	:1,
207 	    _reserved2		:1,
208 	    sadci_do_not_remove	:1,
209 	    sadci_rqst_active	:1);
210 	DECL_BITFIELD6(
211 	    _reserved3		:2,
212 	    sadci_enable_byp_b	:1,
213 	    sadci_enable_byp_a	:1,
214 	    sadci_device_off	:1,
215 	    sadci_rqst_fault	:1,
216 	    _reserved4		:2);
217 } ses2_array_device_ctl_impl_t;
218 
219 /*
220  * SES-2 Array Device element for the Enclosure Status diagnostic page
221  * (Table 66, 7.3.3)
222  */
223 typedef struct ses2_array_device_status_impl {
224 	ses2_cmn_elem_status_impl_t sadsi_common;
225 	DECL_BITFIELD8(
226 	    sadsi_rr_abort		:1,
227 	    sadsi_rebuild		:1,
228 	    sadsi_in_failed_array	:1,
229 	    sadsi_in_crit_array		:1,
230 	    sadsi_cons_chk		:1,
231 	    sadsi_hot_spare		:1,
232 	    sadsi_rsvd_device		:1,
233 	    sadsi_ok			:1);
234 	DECL_BITFIELD8(
235 	    sadsi_report		:1,
236 	    sadsi_ident			:1,
237 	    sadsi_rmv			:1,
238 	    sadsi_ready_to_insert	:1,
239 	    sadsi_enclosure_bypassed_b	:1,
240 	    sadsi_enclosure_bypassed_a	:1,
241 	    sadsi_do_not_remove		:1,
242 	    sadsi_app_client_bypassed_a	:1);
243 	DECL_BITFIELD8(
244 	    sadsi_device_bypassed_b	:1,
245 	    sadsi_device_bypassed_a	:1,
246 	    sadsi_bypassed_b		:1,
247 	    sadsi_bypassed_a		:1,
248 	    sadsi_device_off		:1,
249 	    sadsi_fault_reqstd		:1,
250 	    sadsi_fault_sensed		:1,
251 	    sadsi_app_client_bypassed_b	:1);
252 } ses2_array_device_status_impl_t;
253 
254 /*
255  * SES-2 Power Supply element for control-type diagnostic pages (T68).
256  */
257 typedef struct ses2_psu_ctl_impl {
258 	ses2_cmn_elem_ctl_impl_t spci_common;
259 	DECL_BITFIELD2(
260 	    _reserved1		:7,
261 	    spci_rqst_ident	:1);
262 	uint8_t _reserved2;
263 	DECL_BITFIELD4(
264 	    _reserved3		:5,
265 	    spci_rqst_on	:1,
266 	    spci_rqst_fail	:1,
267 	    _reserved4		:1);
268 } ses2_psu_ctl_impl_t;
269 
270 /*
271  * SES-2 Power Supply element for status-type diagnostic pages (Table 69, 7.3.4)
272  */
273 typedef struct ses2_psu_status_impl {
274 	ses2_cmn_elem_status_impl_t spsi_common;
275 	DECL_BITFIELD2(
276 	    _reserved1	:7,
277 	    spsi_ident	:1);
278 	DECL_BITFIELD5(
279 	    _reserved2			:1,
280 	    spsi_dc_over_current	:1,
281 	    spsi_dc_under_voltage	:1,
282 	    spsi_dc_over_voltage	:1,
283 	    _reserved3			:4);
284 	DECL_BITFIELD8(
285 	    spsi_dc_fail		:1,
286 	    spsi_ac_fail		:1,
287 	    spsi_temp_warn		:1,
288 	    spsi_overtmp_fail		:1,
289 	    spsi_off			:1,
290 	    spsi_rqsted_on		:1,
291 	    spsi_fail			:1,
292 	    spsi_hot_swap		:1);
293 } ses2_psu_status_impl_t;
294 
295 /*
296  * SES-2 Cooling element for control-type diagnostic pages (Table 70).
297  */
298 typedef struct ses2_cooling_ctl_impl {
299 	ses2_cmn_elem_ctl_impl_t scci_common;
300 	DECL_BITFIELD2(
301 	    _reserved1		:7,
302 	    scci_rqst_ident	:1);
303 	uint8_t _reserved2;
304 	DECL_BITFIELD5(
305 	    scci_requested_speed_code	:3,
306 	    _reserved3			:2,
307 	    scci_rqst_on		:1,
308 	    scci_rqst_fail		:1,
309 	    _reserved4			:1);
310 } ses2_cooling_ctl_impl_t;
311 
312 /*
313  * SES-2 Cooling element for status-type diagnostic pages (Table 71, 7.3.5)
314  */
315 typedef struct ses2_cooling_status_impl {
316 	ses2_cmn_elem_status_impl_t scsi_common;
317 	DECL_BITFIELD3(
318 	    scsi_fan_speed_ms3	:3,
319 	    _reserved1		:4,
320 	    scsi_ident		:1);
321 	uint8_t scsi_fan_speed_lsb;
322 	DECL_BITFIELD6(
323 	    scsi_actual_speed_code	:3,
324 	    _reserved2			:1,
325 	    scsi_off			:1,
326 	    scsi_requested_on		:1,
327 	    scsi_fail			:1,
328 	    _reserved3			:1);
329 } ses2_cooling_status_impl_t;
330 
331 /*
332  * The fan_speed fields are multiplied by this factor to obtain the actual
333  * number of RPMs.
334  */
335 #define	SES2_ES_COOLING_SPEED_FACTOR	10
336 
337 #define	SES2_ES_COOLING_ST_FAN_SPEED(csip)	\
338 	(((((uint16_t)(csip)->scsi_fan_speed_ms3) << 8) |	\
339 	    ((uint16_t)(csip)->scsi_fan_speed_lsb)) * \
340 	    (uint16_t)SES2_ES_COOLING_SPEED_FACTOR)
341 
342 /*
343  * SES-2 Temperature Sensor element for control-type diagnostic pages (T74).
344  */
345 typedef struct ses2_temp_ctl_impl {
346 	ses2_cmn_elem_ctl_impl_t stci_common;
347 	DECL_BITFIELD3(
348 	    _reserved1		:6,
349 	    stci_rqst_fail	:1,
350 	    stci_rqst_ident	:1);
351 	uint8_t _reserved2[2];
352 } ses2_temp_ctl_impl_t;
353 
354 /*
355  * SES-2 Temperature Sensor element for status-type diagnostic pages
356  * (Table 74, 7.3.6)
357  */
358 typedef struct ses2_temp_status_impl {
359 	ses2_cmn_elem_status_impl_t stsi_common;
360 	DECL_BITFIELD3(
361 	    _reserved1	:6,
362 	    stsi_fail	:1,
363 	    stsi_ident	:1);
364 	uint8_t stsi_temperature;
365 	DECL_BITFIELD4(
366 	    stsi_ut_warn	:1,
367 	    stsi_ut_fail	:1,
368 	    stsi_ot_warn	:1,
369 	    stsi_ot_fail	:1);
370 } ses2_temp_status_impl_t;
371 
372 #define	SES2_ES_TEMP_OFFSET	(-20)
373 
374 #define	SES2_ES_TEMP_ST_TEMPERATURE(tsip)	\
375 	((tsip)->stsi_temperature + SES2_ES_TEMP_OFFSET)
376 
377 /*
378  * SES-2 Door Lock element for control-type diagnostic pages (T76).
379  */
380 typedef struct ses2_lock_ctl_impl {
381 	ses2_cmn_elem_ctl_impl_t slci_common;
382 	DECL_BITFIELD3(
383 	    _reserved1		:6,
384 	    slci_rqst_fail	:1,
385 	    slci_rqst_ident	:1);
386 	uint8_t _reserved2;
387 	DECL_BITFIELD2(
388 	    slci_unlock	:1,
389 	    _reserved3	:7);
390 } ses2_lock_ctl_impl_t;
391 
392 /*
393  * SES-2 Door Lock element for status-type diagnostic pages (Table 77, 7.3.7)
394  */
395 typedef struct ses2_lock_status_impl {
396 	ses2_cmn_elem_status_impl_t slsi_common;
397 	DECL_BITFIELD3(
398 	    _reserved1	:6,
399 	    slsi_fail	:1,
400 	    slsi_ident	:1);
401 	uint8_t _reserved2;
402 	DECL_BITFIELD2(
403 	    slsi_unlocked	:1,
404 	    _reserved3		:7);
405 } ses2_lock_status_impl_t;
406 
407 /*
408  * SES-2 Audible Alarm element for control-type diagnostic pages (T78).
409  */
410 typedef struct ses2_alarm_ctl_impl {
411 	ses2_cmn_elem_ctl_impl_t saci_common;
412 	DECL_BITFIELD3(
413 	    _reserved1		:6,
414 	    saci_rqst_fail	:1,
415 	    saci_rqst_ident	:1);
416 	uint8_t _reserved2;
417 	DECL_BITFIELD8(
418 	    saci_unrecov	:1,
419 	    saci_crit		:1,
420 	    saci_noncrit	:1,
421 	    saci_info		:1,
422 	    saci_set_remind	:1,
423 	    _reserved3		:1,
424 	    saci_set_mute	:1,
425 	    _reserved4		:1);
426 } ses2_alarm_ctl_impl_t;
427 
428 /*
429  * SES-2 Audible Alarm element for status-type diagnostic pages
430  * (Table 79, 7.3.8)
431  */
432 typedef struct ses2_alarm_status_impl {
433 	ses2_cmn_elem_status_impl_t sasi_common;
434 	DECL_BITFIELD3(
435 	    _reserved1	:6,
436 	    sasi_fail	:1,
437 	    sasi_ident	:1);
438 	uint8_t _reserved2;
439 	DECL_BITFIELD8(
440 	    sasi_unrecov	:1,
441 	    sasi_crit		:1,
442 	    sasi_noncrit	:1,
443 	    sasi_info		:1,
444 	    sasi_remind		:1,
445 	    _reserved3		:1,
446 	    sasi_muted		:1,
447 	    sasi_rqst_mute	:1);
448 } ses2_alarm_status_impl_t;
449 
450 /*
451  * SES-2 Enclosure Services Controller Electronics element for control-type
452  * diagnostic pages (Table 80, 7.3.9).
453  */
454 typedef struct ses2_controller_ctl_impl {
455 	ses2_cmn_elem_ctl_impl_t scci_common;
456 	DECL_BITFIELD3(
457 	    _reserved1		:6,
458 	    scci_rqst_fail	:1,
459 	    scci_rqst_ident	:1);
460 	DECL_BITFIELD2(
461 	    scci_select_element	:1,
462 	    _reserved2		:7);
463 	uint8_t _reserved3;
464 } ses2_controller_ctl_impl_t;
465 
466 /*
467  * SES-2 Enclosure Services Controller Electronics element for status-type
468  * diagnostic pages (Table 81, 7.3.9),
469  */
470 typedef struct ses2_controller_status_impl {
471 	ses2_cmn_elem_status_impl_t scsi_common;
472 	DECL_BITFIELD3(
473 	    _reserved1	:6,
474 	    scsi_fail	:1,
475 	    scsi_ident	:1);
476 	DECL_BITFIELD2(
477 	    scsi_report	:1,
478 	    _reserved2	:7);
479 	DECL_BITFIELD2(
480 	    _reserved3		:7,
481 	    scsi_hot_swap	:1);
482 } ses2_controller_status_impl_t;
483 
484 /*
485  * SES-2 SCC Controller Electronics element for control-type diagnostic pages
486  * (Table 82, 7.3.10).
487  */
488 typedef struct ses2_scc_ctl_impl {
489 	ses2_cmn_elem_ctl_impl_t ssci_common;
490 	DECL_BITFIELD3(
491 	    _reserved1		:6,
492 	    ssci_rqst_fail	:1,
493 	    ssci_rqst_ident	:1);
494 	uint8_t _reserved2[2];
495 } ses2_scc_ctl_impl_t;
496 
497 /*
498  * SES-2 SCC Controller Electronics element for status-type diagnostic pages
499  * (Table 83, 7.3.10)
500  */
501 typedef struct ses2_scc_status_impl {
502 	ses2_cmn_elem_status_impl_t sss_common;
503 	DECL_BITFIELD3(
504 	    _reserved1	:6,
505 	    sss_fail	:1,
506 	    sss_ident	:1);
507 	DECL_BITFIELD2(
508 	    sss_report	:1,
509 	    _reserved2	:7);
510 	uint8_t _reserved3;
511 } ses2_scc_status_impl_t;
512 
513 /*
514  * SES-2 Nonvolatile Cache element for control-type diagnostic pages
515  * (Table 84, 7.3.11).
516  */
517 typedef struct ses2_nvcache_ctl_impl {
518 	ses2_cmn_elem_ctl_impl_t snci_common;
519 	DECL_BITFIELD3(
520 	    _reserved1		:6,
521 	    snci_rqst_fail	:1,
522 	    snci_rqst_ident	:1);
523 	uint8_t _reserved2[2];
524 } ses2_nvcache_ctl_impl_t;
525 
526 /*
527  * SES-2 Nonvolatile Cache element for status-type diagnostic pages (Table 85,
528  * 7.3.11)
529  */
530 typedef struct ses2_nvcache_status_impl {
531 	ses2_cmn_elem_status_impl_t snsi_common;
532 	DECL_BITFIELD4(
533 	    snsi_size_multiplier	:2,
534 	    _reserved1			:4,
535 	    snsi_fail			:1,
536 	    snsi_ident			:1);
537 	uint16_t snsi_nvcache_size;
538 } ses2_nvcache_status_impl_t;
539 
540 /*
541  * Ibid., Table 86 defines the size multipliers as follows:
542  *
543  * 00b	- bytes
544  * 01b	- 1<<10 bytes
545  * 10b	- 1<<20 bytes
546  * 11b	- 1<<30 bytes
547  *
548  * We will calculate the actual size in bytes by doing
549  *
550  * nvcache_size << (SES2_NVCACHE_SHIFT * multiplier)
551  */
552 #define	SES2_NVCACHE_SHIFT	10
553 #define	SES2_NVCACHE_SIZE(nsip)	\
554 	((uint64_t)SCSI_READ16(&(nsip)->snsi_nvcache_size) << \
555 	    (SES2_NVCACHE_SHIFT * (nsip)->snsi_size_multiplier))
556 
557 /*
558  * SES-2 Invalid Operation Reason element for status-type diagnostic pages
559  * (Table 88, 7.3.12)
560  */
561 typedef struct ses2_invop_reason_status_impl {
562 	ses2_cmn_elem_status_impl_t sirsi_common;
563 	DECL_BITFIELD2(
564 	    sirsi_priv_ms6	:6,
565 	    sirsi_invop_type	:2);
566 	uint8_t sirsi_priv[2];
567 } ses2_invop_reason_status_impl_t;
568 
569 /*
570  * Ibid., Invop Type values (Table 89)
571  */
572 typedef enum ses2_invop_type {
573 	SES2_INVOP_SEND_PAGE_CODE = 0x0,
574 	SES2_INVOP_SEND_PAGE_FORMAT = 0x1,
575 	SES2_INVOP_VENDOR_SPECIFIC = 0x3
576 } ses2_invop_type_t;
577 
578 /*
579  * Ibid., Invalid Operation Reason element for status-type diagnostic pages
580  * with Invop Type of 00b (Table 90)
581  */
582 typedef struct ses2_invop_code_status_impl {
583 	ses2_cmn_elem_status_impl_t sicsi_common;
584 	DECL_BITFIELD3(
585 	    sicsi_page_not_supported	:1,
586 	    _reserved1			:5,
587 	    sicsi_invop_type		:2);
588 	uint8_t _reserved2[2];
589 } ses2_invop_code_status_impl_t;
590 
591 /*
592  * Ibid., Invalid Operation Reason element for status-type diagnostic pages
593  * with Invop Type of 01b (Table 91)
594  */
595 typedef struct ses2_invop_format_status_impl {
596 	ses2_cmn_elem_status_impl_t sifsi_common;
597 	DECL_BITFIELD3(
598 	    sifsi_bit_number	:3,
599 	    _reserved1		:3,
600 	    sifsi_invop_type	:2);
601 	uint16_t sifsi_byte_offset[2];
602 } ses2_invop_format_status_impl_t;
603 
604 /*
605  * SES-2 Uninterruptible Power Supply element for control-type diagnostic
606  * pages (Table 93, 7.3.13)
607  */
608 typedef struct ses2_ups_ctl_impl {
609 	ses2_cmn_elem_ctl_impl_t suci_common;
610 	uint8_t _reserved1[2];
611 	DECL_BITFIELD3(
612 	    _reserved2		:6,
613 	    suci_rqst_fail	:1,
614 	    suci_rqst_ident	:1);
615 } ses2_ups_ctl_impl_t;
616 
617 /*
618  * SES-2 Uninterruptible Power Supply element for status-type diagnostic pages
619  * (Table 94, 7.3.13)
620  */
621 typedef struct ses2_ups_status_impl {
622 	ses2_cmn_elem_status_impl_t susi_common;
623 	uint8_t susi_battery_status;	/* Time remaining in minutes */
624 	DECL_BITFIELD8(
625 	    susi_intf_fail	:1,
626 	    susi_warn		:1,
627 	    susi_ups_fail	:1,
628 	    susi_dc_fail	:1,
629 	    susi_ac_fail	:1,
630 	    susi_ac_qual	:1,
631 	    susi_ac_hi		:1,
632 	    susi_ac_lo		:1);
633 	DECL_BITFIELD5(
634 	    susi_bpf		:1,
635 	    susi_batt_fail	:1,
636 	    _reserved1		:4,
637 	    susi_fail		:1,
638 	    susi_ident		:1);
639 } ses2_ups_status_impl_t;
640 
641 /*
642  * SES-2 Display element for control-type diagnostic pages (Table 95, 7.3.14)
643  */
644 typedef struct ses2_display_ctl_impl {
645 	ses2_cmn_elem_ctl_impl_t sdci_common;
646 	DECL_BITFIELD4(
647 	    sdci_display_mode	:2,
648 	    _reserved1		:4,
649 	    sdci_rqst_fail	:1,
650 	    sdci_rqst_ident	:1);
651 	uint16_t sdci_display_character;
652 } ses2_display_ctl_impl_t;
653 
654 /*
655  * SES-2 Display element for status-type diagnostic pages (Table 97, 7.3.14)
656  */
657 typedef struct ses2_display_status_impl {
658 	ses2_cmn_elem_status_impl_t sdsi_common;
659 	DECL_BITFIELD4(
660 	    sdsi_display_mode_status	:2,
661 	    _reserved1			:3,
662 	    sdsi_fail			:1,
663 	    sdsi_ident			:1);
664 	uint16_t sdsi_display_character_status;
665 } ses2_display_status_impl_t;
666 
667 /*
668  * SES-2 Key Pad Entry element for control-type diagnostic pages (Table 99).
669  */
670 typedef struct ses2_keypad_ctl_impl {
671 	ses2_cmn_elem_ctl_impl_t skci_common;
672 	DECL_BITFIELD3(
673 	    _reserved1		:6,
674 	    skci_rqst_fail	:1,
675 	    skci_rqst_ident	:1);
676 	uint8_t _reserved2[2];
677 } ses2_keypad_ctl_impl_t;
678 
679 /*
680  * SES-2 Key Pad Entry element for status-type diagnostic pages (Table 100,
681  * 7.3.15)
682  */
683 typedef struct ses2_keypad_status_impl {
684 	ses2_cmn_elem_status_impl_t sksi_common;
685 	DECL_BITFIELD3(
686 	    _reserved1	:6,
687 	    sksi_fail	:1,
688 	    sksi_ident	:1);
689 	uint8_t _reserved2[2];
690 } ses2_keypad_status_impl_t;
691 
692 /*
693  * SES-2 Enclosure element for control-type diagnostic pages (Table 101).
694  */
695 typedef struct ses2_enclosure_ctl_impl {
696 	ses2_cmn_elem_ctl_impl_t seci_common;
697 	DECL_BITFIELD2(
698 	    _reserved1		:7,
699 	    seci_rqst_ident	:1);
700 	DECL_BITFIELD2(
701 	    seci_power_cycle_delay	:6,
702 	    seci_power_cycle_request	:2);
703 	DECL_BITFIELD3(
704 	    seci_request_warning	:1,
705 	    seci_request_failure	:1,
706 	    seci_power_off_duration	:6);
707 } ses2_enclosure_ctl_impl_t;
708 
709 /*
710  * SES-2 Enclosure element for status-type diagnostic pages (Table 101, 7.3.16)
711  */
712 typedef struct ses2_enclosure_status_impl {
713 	ses2_cmn_elem_status_impl_t sesi_common;
714 	DECL_BITFIELD2(
715 	    _reserved1	:7,
716 	    sesi_ident	:1);
717 	DECL_BITFIELD3(
718 	    sesi_warning_indication	:1,
719 	    sesi_failure_indication	:1,
720 	    sesi_power_delay		:6);
721 	DECL_BITFIELD3(
722 	    sesi_warning_requested	:1,
723 	    sesi_failure_requested	:1,
724 	    sesi_power_duration		:6);
725 } ses2_enclosure_status_impl_t;
726 
727 /*
728  * SES-2 SCSI Port/Transceiver element for control-type diagnostic pages (T103)
729  */
730 typedef struct ses2_port_ctl_impl {
731 	ses2_cmn_elem_ctl_impl_t spci_common;
732 	DECL_BITFIELD3(
733 	    _reserved1		:6,
734 	    spci_rqst_fail	:1,
735 	    spci_rqst_ident	:1);
736 	uint8_t _reserved2;
737 	DECL_BITFIELD3(
738 	    _reserved3		:4,
739 	    spci_disable	:1,
740 	    _reserved4		:3);
741 } ses2_port_ctl_impl_t;
742 
743 /*
744  * SES-2 SCSI Port/Transceiver element for status-type diagnostic pages
745  * (Table 104, 7.3.17)
746  */
747 typedef struct ses2_port_status_impl {
748 	ses2_cmn_elem_status_impl_t spsi_common;
749 	DECL_BITFIELD3(
750 	    _reserved1	:6,
751 	    spsi_fail	:1,
752 	    spsi_ident	:1);
753 	DECL_BITFIELD2(
754 	    spsi_report	:1,
755 	    _reserved2	:7);
756 	DECL_BITFIELD5(
757 	    spsi_xmit_fail	:1,
758 	    spsi_lol		:1,
759 	    _reserved3		:2,
760 	    spsi_disabled	:1,
761 	    _reserved4		:3);
762 } ses2_port_status_impl_t;
763 
764 /*
765  * SES-2 Language element for control-type diagnostic pages (T105)
766  */
767 typedef struct ses2_lang_ctl_impl {
768 	ses2_cmn_elem_ctl_impl_t slci_common;
769 	DECL_BITFIELD2(
770 	    _reserved1		:7,
771 	    slci_rqst_ident	:1);
772 	uint16_t slci_language_code;
773 } ses2_lang_ctl_impl_t;
774 
775 /*
776  * SES-2 Language element for status-type diagnostic pages (Table 105, 7.3.18)
777  */
778 typedef struct ses2_lang_status_impl {
779 	ses2_cmn_elem_status_impl_t slsi_common;
780 	DECL_BITFIELD2(
781 	    _reserved1	:7,
782 	    slsi_ident	:1);
783 	uint16_t slsi_language_code;
784 } ses2_lang_status_impl_t;
785 
786 /*
787  * SES-2 Communication Port element for control-type diagnostic pages
788  * (Table 107, 7.3.19).
789  */
790 typedef struct ses2_comm_ctl_impl {
791 	ses2_cmn_elem_ctl_impl_t scci_common;
792 	DECL_BITFIELD3(
793 	    _reserved1		:6,
794 	    scci_rqst_fail	:1,
795 	    scci_rqst_ident	:1);
796 	uint8_t _reserved2;
797 	DECL_BITFIELD2(
798 	    scci_disable	:1,
799 	    _reserved3		:7);
800 } ses2_comm_ctl_impl_t;
801 
802 /*
803  * SES-2 Communication Port element for status-type diagnostic pages
804  * (Table 108, 7.3.19)
805  */
806 typedef struct ses2_comm_status_impl {
807 	ses2_cmn_elem_status_impl_t scsi_common;
808 	DECL_BITFIELD3(
809 	    _reserved1	:6,
810 	    scsi_fail	:1,
811 	    scsi_ident	:1);
812 	uint8_t _reserved2;
813 	DECL_BITFIELD2(
814 	    scsi_disabled	:1,
815 	    _reserved3		:7);
816 } ses2_comm_status_impl_t;
817 
818 /*
819  * SES-2 Voltage Sensor element for control-type diagnostic pages
820  * (Table 109, 7.3.20).
821  */
822 typedef struct ses2_voltage_ctl_impl {
823 	ses2_cmn_elem_ctl_impl_t svci_common;
824 	DECL_BITFIELD3(
825 	    _reserved1		:6,
826 	    svci_rqst_fail	:1,
827 	    svci_rqst_ident	:1);
828 	uint8_t _reserved2[2];
829 } ses2_voltage_ctl_impl_t;
830 
831 /*
832  * SES-2 Voltage Sensor element for status-type diagnostic pages
833  * (Table 110, 7.3.20).
834  */
835 typedef struct ses2_voltage_status_impl {
836 	ses2_cmn_elem_status_impl_t svsi_common;
837 	DECL_BITFIELD7(
838 	    svsi_crit_under	:1,
839 	    svsi_crit_over	:1,
840 	    svsi_warn_under	:1,
841 	    svsi_warn_over	:1,
842 	    _reserved1		:2,
843 	    svsi_fail		:1,
844 	    svsi_ident		:1);
845 	uint16_t svsi_voltage;
846 } ses2_voltage_status_impl_t;
847 
848 /*
849  * Ibid. defines the svsi_voltage field as a 16-bit signed 2's complement
850  * integer, represented in units of 10 mV.  AC voltages are RMS.
851  */
852 #define	SES2_VOLTAGE_MULTIPLIER	(0.01)
853 #define	SES2_VOLTAGE(vsip)	\
854 	(SCSI_READ16(&(vsip)->svsi_voltage) * SES2_VOLTAGE_MULTIPLIER)
855 
856 /*
857  * SES-2 Current Sensor element for control-type diagnostic pages
858  * (Table 111, 7.3.21).
859  */
860 typedef struct ses2_current_ctl_impl {
861 	ses2_cmn_elem_ctl_impl_t scci_common;
862 	DECL_BITFIELD3(
863 	    _reserved1		:6,
864 	    scci_rqst_fail	:1,
865 	    scci_rqst_ident	:1);
866 	uint8_t _reserved2[2];
867 } ses2_current_ctl_impl_t;
868 
869 /*
870  * SES-2 Current Sensor element for status-type diagnostic pages
871  * (Table 112, 7.3.21)
872  */
873 typedef struct ses2_current_status_impl {
874 	ses2_cmn_elem_status_impl_t scsi_common;
875 	DECL_BITFIELD7(
876 	    _reserved1		:1,
877 	    scsi_crit_over	:1,
878 	    _reserved2		:1,
879 	    scsi_warn_over	:1,
880 	    _reserved3		:2,
881 	    scsi_fail		:1,
882 	    scsi_ident		:1);
883 	uint16_t scsi_current;
884 } ses2_current_status_impl_t;
885 
886 /*
887  * Ibid. defines the scsi_voltage field in the same way as for voltage above.
888  * Units here are 10 mA.  AC amperages are RMS.
889  */
890 #define	SES2_CURRENT_MULTIPLIER	(0.01)
891 #define	SES2_CURRENT(csip)	\
892 	(SCSI_READ16(&(csip)->scsi_current) * SES2_CURRENT_MULTIPLIER)
893 
894 /*
895  * SES-2 SCSI Target Port element for control-type diagnostic pages
896  * (Table 113, 7.3.22), SCSI Initiator Port element for control-type
897  * diagnostic pages (Table 115, 7.3.23).
898  */
899 typedef struct ses2_itp_ctl_impl {
900 	ses2_cmn_elem_ctl_impl_t sici_common;
901 	DECL_BITFIELD3(
902 	    _reserved1		:6,
903 	    sici_rqst_fail	:1,
904 	    sici_rqst_ident	:1);
905 	uint8_t _reserved2;
906 	DECL_BITFIELD2(
907 	    sici_enable	:1,
908 	    _reserved3	:7);
909 } ses2_itp_ctl_impl_t;
910 
911 /*
912  * SES-2 SCSI Target Port element for status-type diagnostic pages (Table 114,
913  * 7.3.22), SCSI Initiator Port element for status-type diagnostic pages
914  * (Table 116, 7.3.23)
915  */
916 typedef struct ses2_itp_status_impl {
917 	ses2_cmn_elem_status_impl_t sisi_common;
918 	DECL_BITFIELD3(
919 	    _reserved1	:6,
920 	    sisi_fail	:1,
921 	    sisi_ident	:1);
922 	DECL_BITFIELD2(
923 	    sisi_report	:1,
924 	    _reserved2	:7);
925 	DECL_BITFIELD2(
926 	    sisi_enabled	:1,
927 	    _reserved3		:7);
928 } ses2_itp_status_impl_t;
929 
930 /*
931  * SES-2 Simple Subenclosure element for control-type diagnostic pages
932  * (Table 117, 7.3.24).
933  */
934 typedef struct ses2_ss_ctl_impl {
935 	ses2_cmn_elem_ctl_impl_t ssci_common;
936 	DECL_BITFIELD3(
937 	    _reserved1		:6,
938 	    ssci_rqst_fail	:1,
939 	    ssci_rqst_ident	:1);
940 	uint8_t _reserved2[2];
941 } ses2_ss_ctl_impl_t;
942 
943 /*
944  * SES-2 Simple Subenclosure element for status-type diagnostic pages
945  * (Table 117, 7.3.24)
946  */
947 typedef struct ses2_ss_status_impl {
948 	ses2_cmn_elem_status_impl_t sss_common;
949 	DECL_BITFIELD3(
950 	    _reserved1	:6,
951 	    sss_fail	:1,
952 	    sss_ident	:1);
953 	uint8_t _reserved2;
954 	uint8_t sss_short_status;
955 } ses2_ss_status_impl_t;
956 
957 /*
958  * SES-2 SAS Expander element for control-type diagnostic pages
959  * (Table 119, 7.3.25).
960  */
961 typedef struct ses2_expander_ctl_impl {
962 	ses2_cmn_elem_ctl_impl_t seci_common;
963 	DECL_BITFIELD3(
964 	    _reserved1		:6,
965 	    seci_rqst_fail	:1,
966 	    seci_rqst_ident	:1);
967 	uint8_t _reserved2[2];
968 } ses2_expander_ctl_impl_t;
969 
970 /*
971  * SES-2 SAS Expander element for status-type diagnostic pages (Table 120,
972  * 7.3.25)
973  */
974 typedef struct ses2_expander_status_impl {
975 	ses2_cmn_elem_status_impl_t sesi_common;
976 	DECL_BITFIELD3(
977 	    _reserved1	:6,
978 	    sesi_fail	:1,
979 	    sesi_ident	:1);
980 	uint8_t _reserved2[2];
981 } ses2_expander_status_impl_t;
982 
983 /*
984  * SES-2 SAS Connector element for control-type diagnostic pages (Table 121,
985  * 7.3.26).
986  */
987 typedef struct ses2_sasconn_ctl_impl {
988 	ses2_cmn_elem_ctl_impl_t ssci_common;
989 	DECL_BITFIELD2(
990 	    _reserved1		:7,
991 	    ssci_rqst_ident	:1);
992 	uint8_t _reserved2;
993 	DECL_BITFIELD3(
994 	    _reserved3		:6,
995 	    ssci_rqst_fail	:1,
996 	    _reserved4		:1);
997 } ses2_sasconn_ctl_impl_t;
998 
999 /*
1000  * SES-2 SAS Connector element for status-type diagnostic pages (Table 122,
1001  * 7.3.26)
1002  */
1003 typedef struct ses2_sasconn_status_impl {
1004 	ses2_cmn_elem_status_impl_t sss_common;
1005 	DECL_BITFIELD2(
1006 	    sss_connector_type	:7,
1007 	    sss_ident		:1);
1008 	uint8_t sss_connector_physical_link;
1009 	DECL_BITFIELD3(
1010 	    _reserved1	:6,
1011 	    sss_fail	:1,
1012 	    _reserved2	:1);
1013 } ses2_sasconn_status_impl_t;
1014 
1015 /*
1016  * SES-2 Enclosure Control diagnostic page (Table 10, 6.1.3)
1017  */
1018 typedef struct ses2_control_page_impl {
1019 	uint8_t scpi_page_code;
1020 	DECL_BITFIELD5(
1021 	    scpi_unrecov	:1,
1022 	    scpi_crit		:1,
1023 	    scpi_noncrit	:1,
1024 	    scpi_info		:1,
1025 	    _reserved1		:4);
1026 	uint16_t scpi_page_length;
1027 	uint32_t scpi_generation_code;
1028 	ses2_elem_ctl_impl_t scpi_data[1];
1029 } ses2_control_page_impl_t;
1030 
1031 /*
1032  * SES-2 Enclosure Status (Table 11, 6.1.4)
1033  */
1034 typedef struct ses2_status_page_impl {
1035 	uint8_t sspi_page_code;
1036 	DECL_BITFIELD6(
1037 	    sspi_unrecov	:1,
1038 	    sspi_crit		:1,
1039 	    sspi_noncrit	:1,
1040 	    sspi_info		:1,
1041 	    sspi_invop		:1,
1042 	    _reserved1		:3);
1043 	uint16_t sspi_page_length;
1044 	uint32_t sspi_generation_code;
1045 	uint8_t sspi_data[1];
1046 } ses2_status_page_impl_t;
1047 
1048 /*
1049  * SES-2 Help Text diagnostic page (Table 13, 6.1.5).
1050  */
1051 typedef struct ses2_help_page_impl {
1052 	uint8_t shpi_page_code;
1053 	uint8_t _reserved1;
1054 	uint16_t shpi_page_length;
1055 	char shpi_help_text[1];
1056 } ses2_help_page_impl_t;
1057 
1058 /*
1059  * SES-2 String Out diagnostic page (Table 14, 6.1.6).
1060  */
1061 typedef struct ses2_string_out_page_impl {
1062 	uint8_t ssopi_page_code;
1063 	uint8_t _reserved1;
1064 	uint16_t ssopi_page_length;
1065 	uint8_t ssopi_data[1];
1066 } ses2_string_out_page_impl_t;
1067 
1068 /*
1069  * SES-2 String In diagnostic page (Table 15, 6.1.7).
1070  */
1071 typedef struct ses2_string_in_page_impl {
1072 	uint8_t ssipi_page_code;
1073 	uint8_t _reserved1;
1074 	uint16_t ssipi_page_length;
1075 	uint8_t ssipi_data[1];
1076 } ses2_string_in_page_impl_t;
1077 
1078 /*
1079  * SES-2 Threshold fields - (Table 17, 6.1.8), (Table 19, 6.1.9).
1080  */
1081 typedef struct ses2_threshold_impl {
1082 	uint8_t sti_high_crit;
1083 	uint8_t sti_high_warn;
1084 	uint8_t sti_low_warn;
1085 	uint8_t sti_low_crit;
1086 } ses2_threshold_impl_t;
1087 
1088 /*
1089  * SES-2 Threshold Out diagnostic page (Table 16, 6.1.8).
1090  */
1091 typedef struct ses2_threshold_out_page_impl {
1092 	uint8_t stopi_page_code;
1093 	uint8_t _reserved1;
1094 	uint16_t stopi_page_length;
1095 	uint32_t stopi_generation_code;
1096 	ses2_threshold_impl_t stopi_thresholds[1];
1097 } ses2_threshold_out_page_impl_t;
1098 
1099 /*
1100  * SES-2 Threshold In diagnostic page (Table 18, 6.1.9).
1101  */
1102 typedef struct ses2_threshold_in_page_impl {
1103 	uint8_t stipi_page_code;
1104 	DECL_BITFIELD3(
1105 	    _reserved1	:4,
1106 	    stipi_invop	:1,
1107 	    _reserved2	:3);
1108 	uint16_t stipi_page_length;
1109 	uint32_t stipi_generation_code;
1110 	ses2_threshold_impl_t stipi_thresholds[1];
1111 } ses2_threshold_in_page_impl_t;
1112 
1113 /*
1114  * SES-2 Element Descriptor diagnostic page (Table 20, 6.1.10).
1115  */
1116 typedef struct ses2_elem_desc_page_impl {
1117 	uint8_t sedpi_page_code;
1118 	uint8_t _reserved1;
1119 	uint16_t sedpi_page_length;
1120 	uint32_t sedpi_generation_code;
1121 	uint8_t sedpi_data[1];
1122 } ses2_elem_desc_page_impl_t;
1123 
1124 /*
1125  * SES-2 Overall/element descriptor format (Table 22, 6.1.10).
1126  */
1127 typedef struct ses2_elem_descriptor_impl {
1128 	uint8_t _reserved1[2];
1129 	uint16_t sedi_descriptor_length;
1130 	char sedi_descriptor[1];
1131 } ses2_elem_descriptor_impl_t;
1132 
1133 /*
1134  * SES-2 Short Enclosure Status diagnostic page (Table 23, 6.1.11).
1135  */
1136 typedef struct ses2_short_status_page_impl {
1137 	uint8_t ssspi_page_code;
1138 	uint8_t ssspi_short_status;
1139 	uint16_t ssspi_page_length;
1140 } ses2_short_status_page_impl_t;
1141 
1142 /*
1143  * SES-2 Enclosure Busy diagnostic page (Table 24, 6.1.12).
1144  */
1145 typedef struct ses2_enclosure_busy_page_impl {
1146 	uint8_t sebpi_page_code;
1147 	DECL_BITFIELD2(
1148 	    sebpi_busy		:1,
1149 	    sebpi_vs_1_1	:7);
1150 	uint16_t sebpi_page_length;
1151 } ses2_enclosure_busy_page_impl_t;
1152 
1153 /*
1154  * SES-2 Additional Element Status diagnostic page (Table 25, 6.1.13).
1155  */
1156 typedef struct ses2_aes_page_impl {
1157 	uint8_t sapi_page_code;
1158 	uint8_t _reserved1;
1159 	uint16_t sapi_page_length;
1160 	uint32_t sapi_generation_code;
1161 	uint8_t sapi_data[1];
1162 } ses2_aes_page_impl_t;
1163 
1164 /*
1165  * SES-2 Additional Element Status descriptor (EIP == 1) (Table 26, 6.1.13).
1166  */
1167 typedef struct ses2_aes_descr_eip_impl {
1168 	DECL_BITFIELD4(
1169 	    sadei_protocol_identifier	:4,
1170 	    sadei_eip			:1,
1171 	    _reserved1			:2,
1172 	    sadei_invalid		:1);
1173 	uint8_t sadei_length;
1174 	uint8_t _reserved2;
1175 	uint8_t sadei_element_index;
1176 	uint8_t sadei_protocol_specific[1];
1177 } ses2_aes_descr_eip_impl_t;
1178 
1179 /*
1180  * SES-2 Additional Element Status descriptor (EIP == 0) (Table 27, 6.1.13).
1181  */
1182 typedef struct ses2_aes_descr_impl {
1183 	DECL_BITFIELD4(
1184 	    sadei_protocol_identifier	:4,
1185 	    sadei_eip			:1,
1186 	    _reserved1			:2,
1187 	    sadei_invalid		:1);
1188 	uint8_t sadei_length;
1189 	uint8_t sadei_protocol_specific[1];
1190 } ses2_aes_descr_impl_t;
1191 
1192 /*
1193  * SES-2 Port descriptor (Table 30, 6.1.13.2).
1194  */
1195 typedef struct ses2_aes_port_descr_impl {
1196 	uint8_t sapdi_port_loop_position;
1197 	uint8_t _reserved1[3];
1198 	uint8_t sapdi_port_requested_hard_address;
1199 	uint8_t sapdi_n_port_identifier[3];
1200 	uint64_t sapdi_n_port_name;
1201 } ses2_aes_port_descr_impl_t;
1202 
1203 /*
1204  * SES-2 Additional Element Status descriptor for FC (Table 28, 6.1.13.2).
1205  */
1206 typedef struct ses2_aes_descr_fc_eip_impl {
1207 	uint8_t sadfi_n_ports;
1208 	uint8_t _reserved1[2];
1209 	uint8_t sadfi_bay_number;
1210 	uint64_t sadfi_node_name;
1211 	ses2_aes_port_descr_impl_t sadfi_ports[1];
1212 } ses2_aes_descr_fc_eip_impl_t;
1213 
1214 /*
1215  * SES-2 Additional Element Status descriptor for FC (EIP == 0)
1216  * (Table 29, 6.1.13.2).
1217  */
1218 typedef struct ses2_aes_descr_fc_impl {
1219 	uint8_t sadfi_n_ports;
1220 	uint8_t _reserved1;
1221 	uint64_t sadfi_node_name;
1222 	ses2_aes_port_descr_impl_t sadfi_ports[1];
1223 } ses2_aes_descr_fc_impl_t;
1224 
1225 /*
1226  * SES-2 Additional Element Status descriptor for SAS (Table 31, 6.1.13.3).
1227  */
1228 typedef struct ses2_aes_descr_sas_impl {
1229 	uint8_t _specific1;
1230 	DECL_BITFIELD2(
1231 	    _specific2			:6,
1232 	    sadsi_descriptor_type	:2);
1233 	uint8_t _specific3[1];
1234 } ses2_aes_descr_sas_impl_t;
1235 
1236 typedef enum ses2_aes_descr_sas_type {
1237 	SES2_AESD_SAS_DEVICE = 0,
1238 	SES2_AESD_SAS_OTHER = 1
1239 } ses2_aes_descr_sas_type_t;
1240 
1241 typedef struct ses2_aes_phy0_descr_impl {
1242 	DECL_BITFIELD3(
1243 	    _reserved1		:4,
1244 	    sapdi_device_type	:3,
1245 	    _reserved2		:1);
1246 	uint8_t _reserved3;
1247 	DECL_BITFIELD5(
1248 	    _reserved4			:1,
1249 	    sapdi_smp_initiator_port	:1,
1250 	    sapdi_stp_initiator_port	:1,
1251 	    sapdi_ssp_initiator_port	:1,
1252 	    _reserved5			:4);
1253 	DECL_BITFIELD6(
1254 	    sapdi_sata_device		:1,
1255 	    sapdi_smp_target_port	:1,
1256 	    sapdi_stp_target_port	:1,
1257 	    sapdi_ssp_target_port	:1,
1258 	    _reserved6			:3,
1259 	    sapdi_sata_port_selector	:1);
1260 	uint64_t sapdi_attached_sas_address;
1261 	uint64_t sapdi_sas_address;
1262 	uint8_t sapdi_phy_identifier;
1263 	uint8_t _reserved7[7];
1264 } ses2_aes_phy0_descr_impl_t;
1265 
1266 typedef struct ses2_aes_descr_sas0_eip_impl {
1267 	uint8_t sadsi_n_phy_descriptors;
1268 	DECL_BITFIELD3(
1269 	    sadsi_not_all_phys		:1,
1270 	    _reserved1			:5,
1271 	    sadsi_descriptor_type	:2);
1272 	uint8_t _reserved2;
1273 	uint8_t sadsi_bay_number;
1274 	ses2_aes_phy0_descr_impl_t sadsi_phys[1];
1275 } ses2_aes_descr_sas0_eip_impl_t;
1276 
1277 typedef struct ses2_aes_descr_sas0_impl {
1278 	uint8_t sadsi_n_phy_descriptors;
1279 	DECL_BITFIELD3(
1280 	    sadsi_not_all_phys		:1,
1281 	    _reserved1			:5,
1282 	    sadsi_descriptor_type	:2);
1283 	ses2_aes_phy0_descr_impl_t sadsi_phys[1];
1284 } ses2_aes_descr_sas0_impl_t;
1285 
1286 /*
1287  * SES-2 Additional Element Status for SAS Expander elements
1288  * (Table 36, 6.1.13.3.3).
1289  */
1290 typedef struct ses2_aes_exp_phy_descr_impl {
1291 	uint8_t saepdi_connector_element_index;
1292 	uint8_t saepdi_other_element_index;
1293 } ses2_aes_exp_phy_descr_impl_t;
1294 
1295 typedef struct ses2_aes_descr_exp_impl {
1296 	uint8_t sadei_n_exp_phy_descriptors;
1297 	DECL_BITFIELD2(
1298 	    _reserved1			:6,
1299 	    sadei_descriptor_type	:2);
1300 	uint8_t _reserved2[2];
1301 	uint64_t sadei_sas_address;
1302 	ses2_aes_exp_phy_descr_impl_t sadei_phys[1];
1303 } ses2_aes_descr_exp_impl_t;
1304 
1305 /*
1306  * SES-2 Additional Element Status for SCSI Initiator/Target Port and
1307  * Enclosure Services Controller Electronics elements (Table 38, 6.1.13.3.4).
1308  */
1309 typedef struct ses2_aes_phy1_descr_impl {
1310 	uint8_t sapdi_phy_identifier;
1311 	uint8_t _reserved1;
1312 	uint8_t sapdi_connector_element_index;
1313 	uint8_t sapdi_other_element_index;
1314 	uint64_t sapdi_sas_address;
1315 } ses2_aes_phy1_descr_impl_t;
1316 
1317 typedef struct ses2_aes_descr_sas1_impl {
1318 	uint8_t sadsi_n_phy_descriptors;
1319 	DECL_BITFIELD2(
1320 	    _reserved1			:6,
1321 	    sadsi_descriptor_type	:2);
1322 	uint8_t _reserved2[2];
1323 	ses2_aes_phy1_descr_impl_t sadsi_phys[1];
1324 } ses2_aes_descr_sas1_impl_t;
1325 
1326 /*
1327  * SES-2 Subenclosure Help Text diagnostic page (Table 40, 6.1.14).
1328  */
1329 typedef struct ses2_subhelp_page_impl {
1330 	uint8_t sspi_page_code;
1331 	uint8_t sspi_n_subenclosures;
1332 	uint16_t sspi_page_length;
1333 	uint32_t sspi_generation_code;
1334 	uint8_t sspi_data[1];
1335 } ses2_subhelp_page_impl_t;
1336 
1337 /*
1338  * SES-2 Subenclosure help text format (Table 41, 6.1.14).
1339  */
1340 typedef struct ses2_subhelp_text_impl {
1341 	uint8_t _reserved1;
1342 	uint8_t ssti_subenclosure_identifier;
1343 	uint16_t ssti_subenclosure_help_text_length;
1344 	char ssti_subenclosure_help_text[1];
1345 } ses2_subhelp_text_impl_t;
1346 
1347 #define	SES2_SUBHELP_LEN(stip)	\
1348 	(SCSI_READ16(&(stip)->ssti_subenclosure_help_text_length) + \
1349 	    offsetof(ses2_subhelp_text_impl_t, ssti_subenclosure_help_text[0]))
1350 /*
1351  * SES-2 Subenclosure String Out diagnostic page (Table 42, 6.1.15).
1352  */
1353 typedef struct ses2_substring_out_page_impl {
1354 	uint8_t ssopi_page_code;
1355 	uint8_t ssopi_subenclosure_identifier;
1356 	uint16_t ssopi_page_length;
1357 	uint32_t ssopi_generation_code;
1358 	uint8_t ssopi_data[1];
1359 } ses2_substring_out_page_impl_t;
1360 
1361 /*
1362  * SES-2 Subenclosure String In diagnostic page (Table 43, 6.1.16).
1363  */
1364 typedef struct ses2_substring_in_page_impl {
1365 	uint8_t ssipi_page_code;
1366 	uint8_t ssipi_n_subenclosures;
1367 	uint16_t ssipi_page_length;
1368 	uint32_t ssipi_generation_code;
1369 	uint8_t ssipi_data[1];
1370 } ses2_substring_in_page_impl_t;
1371 
1372 /*
1373  * SES-2 Subenclosure string in data format (Table 44, 6.1.16).
1374  */
1375 typedef struct ses2_substring_in_data_impl {
1376 	uint8_t _reserved1;
1377 	uint8_t ssidi_subenclosure_identifier;
1378 	uint16_t ssidi_substring_data_length;
1379 	uint8_t ssidi_data[1];
1380 } ses2_substring_in_data_impl_t;
1381 
1382 #define	SES2_SUBSTR_LEN(sdip)	\
1383 	(SCSI_READ16(&(sdip)->ssidi_substring_data_length) + \
1384 	    offsetof(ses2_substring_in_data_impl_t, ssidi_data[0]))
1385 
1386 /*
1387  * SES-2 Supported SES Diagnostic Pages diagnostic page (Table 45, 6.1.17).
1388  */
1389 typedef struct ses2_supported_ses_diag_page_impl {
1390 	uint8_t sssdpi_page_code;
1391 	uint8_t _reserved1;
1392 	uint16_t sssdpi_page_length;
1393 	uint8_t sssdpi_pages[1];
1394 } ses2_supported_ses_diag_page_impl_t;
1395 
1396 /*
1397  * SES-2 Download Microcode Control diagnostic page (Table 46, 6.1.18).
1398  */
1399 typedef struct ses2_ucode_ctl_page_impl {
1400 	uint8_t sucpi_page_code;
1401 	uint8_t sucpi_subenclosure_identifier;
1402 	uint16_t sucpi_page_length;
1403 	uint32_t sucpi_generation_code;
1404 	uint8_t sucpi_dl_ucode_mode;
1405 	uint8_t _reserved1[2];
1406 	uint8_t sucpi_buffer_id;
1407 	uint32_t sucpi_buffer_offset;
1408 	uint32_t sucpi_ucode_image_length;
1409 	uint32_t sucpi_ucode_data_length;
1410 	uint8_t sucpi_ucode_data[1];
1411 } ses2_ucode_ctl_page_impl_t;
1412 
1413 /*
1414  * SES-2 Download Microcode Status diagnostic page (Table 48-49, 6.1.19).
1415  */
1416 typedef struct ses2_ucode_status_descr_impl {
1417 	uint8_t _reserved1;
1418 	uint8_t susdi_subenclosure_identifier;
1419 	uint8_t susdi_subenclosure_dl_status;
1420 	uint8_t susdi_subenclosure_dl_addl_status;
1421 	uint32_t susdi_subenclosure_dl_max_size;
1422 	uint8_t _reserved2[3];
1423 	uint8_t susdi_subenclosure_dl_buffer_id;
1424 	uint32_t susdi_subenclosure_dl_buffer_offset;
1425 } ses2_ucode_status_descr_impl_t;
1426 
1427 typedef struct ses2_ucode_status_page_impl {
1428 	uint8_t suspi_page_code;
1429 	uint8_t suspi_n_subenclosures;
1430 	uint16_t suspi_page_length;
1431 	uint32_t suspi_generation_code;
1432 	ses2_ucode_status_descr_impl_t suspi_descriptors[1];
1433 } ses2_ucode_status_page_impl_t;
1434 
1435 /*
1436  * SES-2 Subenclosure Nickname Control diagnostic page (Table 51, 6.1.20).
1437  */
1438 typedef struct ses2_subnick_ctl_page_impl {
1439 	uint8_t sscpi_page_code;
1440 	uint8_t sspci_subenclosure_identifier;
1441 	uint16_t sspci_page_length;
1442 	uint32_t sspci_generation_code;
1443 	char sspci_subenclosure_nickname[32];
1444 } ses2_subnick_ctl_page_impl_t;
1445 
1446 /*
1447  * SES-2 Subenclosure Nickname Status diagnostic page (Table 52-53, 6.1.21).
1448  */
1449 typedef struct ses2_subnick_descr_impl {
1450 	uint8_t _reserved1;
1451 	uint8_t ssdi_subenclosure_identifier;
1452 	uint8_t ssdi_subenclosure_nick_status;
1453 	uint8_t ssdi_subenclosure_nick_addl_status;
1454 	uint8_t _reserved2[2];
1455 	uint16_t ssdi_subenclosure_nick_lang_code;
1456 	char ssdi_subenclosure_nickname[32];
1457 } ses2_subnick_descr_impl_t;
1458 
1459 typedef struct ses2_subnick_status_page_impl {
1460 	uint8_t sspsi_page_code;
1461 	uint8_t sspci_n_subenclosures;
1462 	uint16_t sspci_page_length;
1463 	uint32_t sspci_generation_code;
1464 	ses2_subnick_descr_impl_t sspci_subnicks[1];
1465 } ses2_subnick_status_page_impl_t;
1466 
1467 /*
1468  * SES-2 Mode page code for enclosure services devices (Table 57, 6.3.2).
1469  */
1470 typedef struct ses2_esm_mode_page_impl {
1471 	DECL_BITFIELD3(
1472 	    sempi_page_code	:6,
1473 	    _reserved1		:1,
1474 	    sempi_ps		:1);
1475 	uint8_t sempi_page_length;
1476 	uint8_t _reserved2[3];
1477 	DECL_BITFIELD2(
1478 	    sempi_enbltc	:1,
1479 	    _reserved3		:7);
1480 	uint16_t sempi_max_task_completion_time;
1481 } ses2_esm_mode_page_impl_t;
1482 
1483 #pragma pack()
1484 
1485 extern ses_pagedesc_t ses2_pages[];
1486 
1487 extern int ses2_fill_element_node(ses_plugin_t *, ses_node_t *);
1488 extern int ses2_fill_enclosure_node(ses_plugin_t *, ses_node_t *);
1489 
1490 typedef int (*ses2_setprop_f)(ses_plugin_t *, ses_node_t *, ses2_diag_page_t,
1491     nvpair_t *);
1492 
1493 typedef struct ses2_ctl_prop {
1494 	const char *scp_name;
1495 	data_type_t scp_type;
1496 	ses2_diag_page_t scp_num;
1497 	ses2_setprop_f scp_setprop;
1498 } ses2_ctl_prop_t;
1499 
1500 typedef int (*ses2_setdef_f)(ses_node_t *, ses2_diag_page_t, void *);
1501 
1502 extern int ses2_ctl_common_setprop(ses_plugin_t *sp, ses_node_t *,
1503     ses2_diag_page_t, nvpair_t *);
1504 
1505 #define	SES_COMMON_CTL_PROPS	\
1506 {	\
1507 	.scp_name = SES_PROP_SWAP,	\
1508 	.scp_type = DATA_TYPE_BOOLEAN_VALUE,	\
1509 	.scp_num = SES2_DIAGPAGE_ENCLOSURE_CTL_STATUS,	\
1510 	.scp_setprop = ses2_ctl_common_setprop	\
1511 },	\
1512 {	\
1513 	.scp_name = SES_PROP_DISABLED,	\
1514 	.scp_type = DATA_TYPE_BOOLEAN_VALUE,	\
1515 	.scp_num = SES2_DIAGPAGE_ENCLOSURE_CTL_STATUS,	\
1516 	.scp_setprop = ses2_ctl_common_setprop	\
1517 },	\
1518 {	\
1519 	.scp_name = SES_PROP_PRDFAIL,	\
1520 	.scp_type = DATA_TYPE_BOOLEAN_VALUE,	\
1521 	.scp_num = SES2_DIAGPAGE_ENCLOSURE_CTL_STATUS,	\
1522 	.scp_setprop = ses2_ctl_common_setprop	\
1523 }
1524 
1525 typedef struct ses2_ctl_desc {
1526 	ses2_element_type_t scd_et;
1527 	const ses2_ctl_prop_t *scd_props;
1528 	ses2_setdef_f scd_setdef;
1529 } ses2_ctl_desc_t;
1530 
1531 extern int ses2_setprop(ses_plugin_t *, ses_node_t *, const ses2_ctl_prop_t *,
1532     nvlist_t *);
1533 
1534 extern int ses2_element_setdef(ses_node_t *, ses2_diag_page_t, void *);
1535 extern int ses2_enclosure_setdef(ses_node_t *, ses2_diag_page_t, void *);
1536 
1537 extern int ses2_element_ctl(ses_plugin_t *, ses_node_t *, const char *,
1538     nvlist_t *);
1539 extern int ses2_enclosure_ctl(ses_plugin_t *, ses_node_t *, const char *,
1540     nvlist_t *);
1541 
1542 #ifdef	__cplusplus
1543 }
1544 #endif
1545 
1546 #endif	/* _PLUGIN_SES_IMPL_H */
1547