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