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