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) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include <stddef.h>
27 #include <strings.h>
28 
29 #include <scsi/libses.h>
30 #include <scsi/libses_plugin.h>
31 #include <scsi/plugins/ses/vendor/sun.h>
32 #include <scsi/plugins/ses/vendor/sun_impl.h>
33 
34 /*ARGSUSED*/
35 static void *
sun_fruid_index(ses_plugin_t * sp,ses_node_t * np,void * data,size_t pagelen,size_t * len)36 sun_fruid_index(ses_plugin_t *sp, ses_node_t *np, void *data,
37     size_t pagelen, size_t *len)
38 {
39 	uint64_t index;
40 	nvlist_t *props = ses_node_props(np);
41 	sun_fruid_page_impl_t *sfpip = data;
42 	sun_fru_descr_impl_t *sfdip;
43 	uint16_t *addr;
44 
45 	if (ses_node_type(np) != SES_NODE_ELEMENT &&
46 	    ses_node_type(np) != SES_NODE_ENCLOSURE)
47 		return (NULL);
48 
49 	if (nvlist_lookup_uint64(props, SES_PROP_ELEMENT_ONLY_INDEX,
50 	    &index) != 0)
51 		return (NULL);
52 
53 	addr = &sfpip->sfpi_descr_addrs[index];
54 	if (!SES_WITHIN_PAGE_STRUCT(addr, data, pagelen))
55 		return (NULL);
56 
57 	sfdip = (sun_fru_descr_impl_t *)((uint8_t *)sfpip + SCSI_READ16(addr));
58 	if (!SES_WITHIN_PAGE_STRUCT(sfdip, data, pagelen))
59 		return (NULL);
60 
61 	*len = MIN(((uint8_t *)sfpip - (uint8_t *)sfdip) + pagelen,
62 	    SCSI_READ16(&sfdip->sfdi_fru_data_length) +
63 	    offsetof(sun_fru_descr_impl_t, sfdi_fru_data));
64 
65 	return (sfdip);
66 }
67 
68 ses_pagedesc_t sun_pages[] = {
69 {
70 	.spd_pagenum = SUN_DIAGPAGE_FRUID,
71 	.spd_index = sun_fruid_index,
72 	.spd_req = SES_REQ_OPTIONAL_STANDARD,
73 	.spd_gcoff = offsetof(sun_fruid_page_impl_t, sfpi_generation_code)
74 },
75 {
76 	.spd_pagenum = -1,
77 	.spd_gcoff = -1
78 }
79 };
80