xref: /illumos-gate/usr/src/lib/scsi/plugins/ses/ses2/common/ses2.c (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
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 #include <string.h>
32 #include <strings.h>
33 
34 #include "ses2_impl.h"
35 
36 /*
37  * Given an nvlist of properties and an array of property handlers, invoke the
38  * appropriate handler for all supported properties.
39  */
40 int
41 ses2_setprop(ses_plugin_t *sp, ses_node_t *np,
42     const ses2_ctl_prop_t *ctlprops, nvlist_t *props)
43 {
44 	const ses2_ctl_prop_t *cpp;
45 	nvpair_t *nvp, *next;
46 
47 	for (nvp = nvlist_next_nvpair(props, NULL); nvp != NULL;
48 	    nvp = next) {
49 		next = nvlist_next_nvpair(props, nvp);
50 		for (cpp = ctlprops; cpp->scp_name != NULL; cpp++)
51 			if (strcmp(cpp->scp_name, nvpair_name(nvp)) == 0)
52 				break;
53 		if (cpp->scp_name == NULL)
54 			continue;
55 
56 		if (cpp->scp_setprop(sp, np, cpp->scp_num, nvp) != 0)
57 			return (-1);
58 
59 		(void) nvlist_remove(props, nvpair_name(nvp),
60 		    nvpair_type(nvp));
61 	}
62 
63 	return (0);
64 }
65 
66 int
67 ses2_ctl_common_setprop(ses_plugin_t *sp, ses_node_t *np, ses2_diag_page_t page,
68     nvpair_t *nvp)
69 {
70 	ses2_cmn_elem_ctl_impl_t *eip;
71 	const char *name;
72 	boolean_t v;
73 
74 	ASSERT(page == SES2_DIAGPAGE_ENCLOSURE_CTL_STATUS);
75 
76 	if ((eip = ses_plugin_ctlpage_lookup(sp, ses_node_snapshot(np),
77 	    page, 0, np, B_FALSE)) == NULL)
78 		return (-1);
79 
80 	name = nvpair_name(nvp);
81 	(void) nvpair_value_boolean_value(nvp, &v);
82 
83 	if (strcmp(name, SES_PROP_SWAP) == 0)
84 		eip->seci_rst_swap = !v;
85 	else if (strcmp(name, SES_PROP_DISABLED) == 0)
86 		eip->seci_disable = v;
87 	else if (strcmp(name, SES_PROP_PRDFAIL) == 0)
88 		eip->seci_prdfail = v;
89 	else
90 		ses_panic("Bad property %s", name);
91 
92 	return (0);
93 }
94 
95 static int
96 ses2_node_parse(ses_plugin_t *sp, ses_node_t *np)
97 {
98 	switch (ses_node_type(np)) {
99 	case SES_NODE_ENCLOSURE:
100 		return (ses2_fill_enclosure_node(sp, np));
101 
102 	case SES_NODE_AGGREGATE:
103 	case SES_NODE_ELEMENT:
104 		return (ses2_fill_element_node(sp, np));
105 
106 	default:
107 		return (0);
108 	}
109 }
110 
111 static int
112 ses2_node_ctl(ses_plugin_t *sp, ses_node_t *np, const char *op,
113     nvlist_t *nvl)
114 {
115 	switch (ses_node_type(np)) {
116 	case SES_NODE_ENCLOSURE:
117 		return (ses2_enclosure_ctl(sp, np, op, nvl));
118 
119 	case SES_NODE_AGGREGATE:
120 	case SES_NODE_ELEMENT:
121 		return (ses2_element_ctl(sp, np, op, nvl));
122 	}
123 
124 	return (0);
125 }
126 
127 int
128 _ses_init(ses_plugin_t *sp)
129 {
130 	ses_plugin_config_t config = {
131 		.spc_pages = ses2_pages,
132 		.spc_node_parse = ses2_node_parse,
133 		.spc_node_ctl = ses2_node_ctl
134 	};
135 
136 	return (ses_plugin_register(sp, LIBSES_PLUGIN_VERSION,
137 	    &config) != 0);
138 }
139