1*275c9da8Seschrock /*
2*275c9da8Seschrock  * CDDL HEADER START
3*275c9da8Seschrock  *
4*275c9da8Seschrock  * The contents of this file are subject to the terms of the
5*275c9da8Seschrock  * Common Development and Distribution License (the "License").
6*275c9da8Seschrock  * You may not use this file except in compliance with the License.
7*275c9da8Seschrock  *
8*275c9da8Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*275c9da8Seschrock  * or http://www.opensolaris.org/os/licensing.
10*275c9da8Seschrock  * See the License for the specific language governing permissions
11*275c9da8Seschrock  * and limitations under the License.
12*275c9da8Seschrock  *
13*275c9da8Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
14*275c9da8Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*275c9da8Seschrock  * If applicable, add the following below this CDDL HEADER, with the
16*275c9da8Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
17*275c9da8Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18*275c9da8Seschrock  *
19*275c9da8Seschrock  * CDDL HEADER END
20*275c9da8Seschrock  */
21*275c9da8Seschrock 
22*275c9da8Seschrock /*
23*275c9da8Seschrock  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*275c9da8Seschrock  * Use is subject to license terms.
25*275c9da8Seschrock  */
26*275c9da8Seschrock 
27*275c9da8Seschrock #include <scsi/libses.h>
28*275c9da8Seschrock #include <scsi/libses_plugin.h>
29*275c9da8Seschrock 
30*275c9da8Seschrock #include "libses_impl.h"
31*275c9da8Seschrock 
32*275c9da8Seschrock /*ARGSUSED*/
33*275c9da8Seschrock static int
libses_parse_node(ses_plugin_t * sp,ses_node_t * np)34*275c9da8Seschrock libses_parse_node(ses_plugin_t *sp, ses_node_t *np)
35*275c9da8Seschrock {
36*275c9da8Seschrock 	nvlist_t *lid;
37*275c9da8Seschrock 	nvlist_t *props;
38*275c9da8Seschrock 	uint64_t id, type;
39*275c9da8Seschrock 	char csn[17];
40*275c9da8Seschrock 	const char *name;
41*275c9da8Seschrock 	int nverr;
42*275c9da8Seschrock 
43*275c9da8Seschrock 	props = ses_node_props(np);
44*275c9da8Seschrock 
45*275c9da8Seschrock 	if (nvlist_lookup_uint64(props, SES_PROP_ELEMENT_TYPE,
46*275c9da8Seschrock 	    &type) == 0 &&
47*275c9da8Seschrock 	    (name = ses_element_type_name(type)) != NULL) {
48*275c9da8Seschrock 		/*
49*275c9da8Seschrock 		 * Add a standard human-readable name for the element type.
50*275c9da8Seschrock 		 */
51*275c9da8Seschrock 		SES_NV_ADD(string, nverr, props,
52*275c9da8Seschrock 		    LIBSES_PROP_ELEMENT_TYPE_NAME, name);
53*275c9da8Seschrock 	}
54*275c9da8Seschrock 
55*275c9da8Seschrock 	if (ses_node_type(np) != SES_NODE_ENCLOSURE)
56*275c9da8Seschrock 		return (0);
57*275c9da8Seschrock 
58*275c9da8Seschrock 	/*
59*275c9da8Seschrock 	 * The only thing we do for all targets is fill in the default chassis
60*275c9da8Seschrock 	 * number from the enclosure logical ID.
61*275c9da8Seschrock 	 */
62*275c9da8Seschrock 	if (nvlist_lookup_nvlist(props, SES_EN_PROP_LID, &lid) != 0)
63*275c9da8Seschrock 		return (0);
64*275c9da8Seschrock 
65*275c9da8Seschrock 	VERIFY(nvlist_lookup_uint64(lid, SPC3_NAA_INT, &id) == 0);
66*275c9da8Seschrock 
67*275c9da8Seschrock 	(void) snprintf(csn, sizeof (csn), "%llx", id);
68*275c9da8Seschrock 	SES_NV_ADD(string, nverr, props, LIBSES_EN_PROP_CSN, csn);
69*275c9da8Seschrock 
70*275c9da8Seschrock 	return (0);
71*275c9da8Seschrock }
72*275c9da8Seschrock 
73*275c9da8Seschrock int
_ses_init(ses_plugin_t * sp)74*275c9da8Seschrock _ses_init(ses_plugin_t *sp)
75*275c9da8Seschrock {
76*275c9da8Seschrock 	ses_plugin_config_t config = {
77*275c9da8Seschrock 		.spc_node_parse = libses_parse_node
78*275c9da8Seschrock 	};
79*275c9da8Seschrock 
80*275c9da8Seschrock 	return (ses_plugin_register(sp, LIBSES_PLUGIN_VERSION,
81*275c9da8Seschrock 	    &config) != 0);
82*275c9da8Seschrock }
83*275c9da8Seschrock 
84*275c9da8Seschrock /*
85*275c9da8Seschrock  * libses must be loaded after ses2.
86*275c9da8Seschrock  */
87*275c9da8Seschrock int
_ses_priority(void)88*275c9da8Seschrock _ses_priority(void)
89*275c9da8Seschrock {
90*275c9da8Seschrock 	return (1);
91*275c9da8Seschrock }
92