xref: /illumos-gate/usr/src/lib/scsi/plugins/ses/libses/common/libses.c (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <scsi/libses.h>
28 #include <scsi/libses_plugin.h>
29 
30 #include "libses_impl.h"
31 
32 /*ARGSUSED*/
33 static int
34 libses_parse_node(ses_plugin_t *sp, ses_node_t *np)
35 {
36 	nvlist_t *lid;
37 	nvlist_t *props;
38 	uint64_t id, type;
39 	char csn[17];
40 	const char *name;
41 	int nverr;
42 
43 	props = ses_node_props(np);
44 
45 	if (nvlist_lookup_uint64(props, SES_PROP_ELEMENT_TYPE,
46 	    &type) == 0 &&
47 	    (name = ses_element_type_name(type)) != NULL) {
48 		/*
49 		 * Add a standard human-readable name for the element type.
50 		 */
51 		SES_NV_ADD(string, nverr, props,
52 		    LIBSES_PROP_ELEMENT_TYPE_NAME, name);
53 	}
54 
55 	if (ses_node_type(np) != SES_NODE_ENCLOSURE)
56 		return (0);
57 
58 	/*
59 	 * The only thing we do for all targets is fill in the default chassis
60 	 * number from the enclosure logical ID.
61 	 */
62 	if (nvlist_lookup_nvlist(props, SES_EN_PROP_LID, &lid) != 0)
63 		return (0);
64 
65 	VERIFY(nvlist_lookup_uint64(lid, SPC3_NAA_INT, &id) == 0);
66 
67 	(void) snprintf(csn, sizeof (csn), "%llx", id);
68 	SES_NV_ADD(string, nverr, props, LIBSES_EN_PROP_CSN, csn);
69 
70 	return (0);
71 }
72 
73 int
74 _ses_init(ses_plugin_t *sp)
75 {
76 	ses_plugin_config_t config = {
77 		.spc_node_parse = libses_parse_node
78 	};
79 
80 	return (ses_plugin_register(sp, LIBSES_PLUGIN_VERSION,
81 	    &config) != 0);
82 }
83 
84 /*
85  * libses must be loaded after ses2.
86  */
87 int
88 _ses_priority(void)
89 {
90 	return (1);
91 }
92