1*ac88567aSHyon Kim /*
2*ac88567aSHyon Kim  * CDDL HEADER START
3*ac88567aSHyon Kim  *
4*ac88567aSHyon Kim  * The contents of this file are subject to the terms of the
5*ac88567aSHyon Kim  * Common Development and Distribution License (the "License").
6*ac88567aSHyon Kim  * You may not use this file except in compliance with the License.
7*ac88567aSHyon Kim  *
8*ac88567aSHyon Kim  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*ac88567aSHyon Kim  * or http://www.opensolaris.org/os/licensing.
10*ac88567aSHyon Kim  * See the License for the specific language governing permissions
11*ac88567aSHyon Kim  * and limitations under the License.
12*ac88567aSHyon Kim  *
13*ac88567aSHyon Kim  * When distributing Covered Code, include this CDDL HEADER in each
14*ac88567aSHyon Kim  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*ac88567aSHyon Kim  * If applicable, add the following below this CDDL HEADER, with the
16*ac88567aSHyon Kim  * fields enclosed by brackets "[]" replaced with your own identifying
17*ac88567aSHyon Kim  * information: Portions Copyright [yyyy] [name of copyright owner]
18*ac88567aSHyon Kim  *
19*ac88567aSHyon Kim  * CDDL HEADER END
20*ac88567aSHyon Kim  */
21*ac88567aSHyon Kim 
22*ac88567aSHyon Kim /*
23*ac88567aSHyon Kim  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*ac88567aSHyon Kim  */
25*ac88567aSHyon Kim 
26*ac88567aSHyon Kim #include <stddef.h>
27*ac88567aSHyon Kim #include <strings.h>
28*ac88567aSHyon Kim 
29*ac88567aSHyon Kim #include <scsi/libses.h>
30*ac88567aSHyon Kim #include <scsi/libses_plugin.h>
31*ac88567aSHyon Kim #include <scsi/plugins/ses/vendor/sun.h>
32*ac88567aSHyon Kim #include <scsi/plugins/ses/vendor/sun_impl.h>
33*ac88567aSHyon Kim 
34*ac88567aSHyon Kim /*ARGSUSED*/
35*ac88567aSHyon Kim static void *
sun_fruid_index(ses_plugin_t * sp,ses_node_t * np,void * data,size_t pagelen,size_t * len)36*ac88567aSHyon Kim sun_fruid_index(ses_plugin_t *sp, ses_node_t *np, void *data,
37*ac88567aSHyon Kim     size_t pagelen, size_t *len)
38*ac88567aSHyon Kim {
39*ac88567aSHyon Kim 	uint64_t index;
40*ac88567aSHyon Kim 	nvlist_t *props = ses_node_props(np);
41*ac88567aSHyon Kim 	sun_fruid_page_impl_t *sfpip = data;
42*ac88567aSHyon Kim 	sun_fru_descr_impl_t *sfdip;
43*ac88567aSHyon Kim 	uint16_t *addr;
44*ac88567aSHyon Kim 
45*ac88567aSHyon Kim 	if (ses_node_type(np) != SES_NODE_ELEMENT &&
46*ac88567aSHyon Kim 	    ses_node_type(np) != SES_NODE_ENCLOSURE)
47*ac88567aSHyon Kim 		return (NULL);
48*ac88567aSHyon Kim 
49*ac88567aSHyon Kim 	if (nvlist_lookup_uint64(props, SES_PROP_ELEMENT_ONLY_INDEX,
50*ac88567aSHyon Kim 	    &index) != 0)
51*ac88567aSHyon Kim 		return (NULL);
52*ac88567aSHyon Kim 
53*ac88567aSHyon Kim 	addr = &sfpip->sfpi_descr_addrs[index];
54*ac88567aSHyon Kim 	if (!SES_WITHIN_PAGE_STRUCT(addr, data, pagelen))
55*ac88567aSHyon Kim 		return (NULL);
56*ac88567aSHyon Kim 
57*ac88567aSHyon Kim 	sfdip = (sun_fru_descr_impl_t *)((uint8_t *)sfpip + SCSI_READ16(addr));
58*ac88567aSHyon Kim 	if (!SES_WITHIN_PAGE_STRUCT(sfdip, data, pagelen))
59*ac88567aSHyon Kim 		return (NULL);
60*ac88567aSHyon Kim 
61*ac88567aSHyon Kim 	*len = MIN(((uint8_t *)sfpip - (uint8_t *)sfdip) + pagelen,
62*ac88567aSHyon Kim 	    SCSI_READ16(&sfdip->sfdi_fru_data_length) +
63*ac88567aSHyon Kim 	    offsetof(sun_fru_descr_impl_t, sfdi_fru_data));
64*ac88567aSHyon Kim 
65*ac88567aSHyon Kim 	return (sfdip);
66*ac88567aSHyon Kim }
67*ac88567aSHyon Kim 
68*ac88567aSHyon Kim ses_pagedesc_t sun_pages[] = {
69*ac88567aSHyon Kim {
70*ac88567aSHyon Kim 	.spd_pagenum = SUN_DIAGPAGE_FRUID,
71*ac88567aSHyon Kim 	.spd_index = sun_fruid_index,
72*ac88567aSHyon Kim 	.spd_req = SES_REQ_OPTIONAL_STANDARD,
73*ac88567aSHyon Kim 	.spd_gcoff = offsetof(sun_fruid_page_impl_t, sfpi_generation_code)
74*ac88567aSHyon Kim },
75*ac88567aSHyon Kim {
76*ac88567aSHyon Kim 	.spd_pagenum = -1,
77*ac88567aSHyon Kim 	.spd_gcoff = -1
78*ac88567aSHyon Kim }
79*ac88567aSHyon Kim };
80