xref: /illumos-gate/usr/src/lib/fm/topo/libtopo/common/topo_protocol.c (revision 503609a9497e27f206d815a06ce90a747d2ce573)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <assert.h>
27 #include <pthread.h>
28 #include <strings.h>
29 #include <sys/fm/protocol.h>
30 
31 #include <topo_alloc.h>
32 #include <topo_error.h>
33 #include <topo_method.h>
34 #include <topo_prop.h>
35 #include <topo_protocol.h>
36 #include <topo_subr.h>
37 
38 #include <libtopo.h>
39 
40 int
41 topo_node_asru(tnode_t *node, nvlist_t **asru, nvlist_t *priv, int *err)
42 {
43 	nvlist_t *prop, *ap;
44 
45 	if (topo_prop_getprop(node, TOPO_PGROUP_PROTOCOL,
46 	    TOPO_PROP_ASRU, priv, &prop, err) < 0)
47 		return (-1);
48 
49 	if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &ap) != 0 ||
50 	    topo_hdl_nvdup(node->tn_hdl, ap, asru) < 0) {
51 		*err = ETOPO_PROP_NVL;
52 		nvlist_free(prop);
53 		return (-1);
54 	}
55 
56 	nvlist_free(prop);
57 
58 	return (0);
59 }
60 
61 int
62 topo_node_fru(tnode_t *node, nvlist_t **fru, nvlist_t *priv, int *err)
63 {
64 	nvlist_t *prop, *fp;
65 
66 	if (topo_prop_getprop(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
67 	    priv, &prop, err) < 0)
68 		return (-1);
69 
70 	if (nvlist_lookup_nvlist(prop, TOPO_PROP_VAL_VAL, &fp) != 0 ||
71 	    topo_hdl_nvdup(node->tn_hdl, fp, fru) < 0) {
72 		*err = ETOPO_PROP_NVL;
73 		nvlist_free(prop);
74 		return (-1);
75 	}
76 
77 	nvlist_free(prop);
78 
79 	return (0);
80 }
81 
82 int
83 topo_node_resource(tnode_t *node, nvlist_t **resource, int *err)
84 {
85 
86 	return (topo_prop_get_fmri(node, TOPO_PGROUP_PROTOCOL,
87 	    TOPO_PROP_RESOURCE, resource, err));
88 }
89 
90 int
91 topo_node_label(tnode_t *node, char **label, int *err)
92 {
93 
94 	return (topo_prop_get_string(node, TOPO_PGROUP_PROTOCOL,
95 	    TOPO_PROP_LABEL, label, err));
96 }
97 
98 int
99 topo_node_asru_set(tnode_t *node, nvlist_t *asru, int flag, int *err)
100 {
101 	/*
102 	 * Inherit ASRU property from our parent if asru not specified
103 	 */
104 	if (asru == NULL) {
105 		if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL,
106 		    TOPO_PROP_ASRU, err) < 0) {
107 			return (-1);
108 		}
109 
110 		return (0);
111 	}
112 
113 	if (flag & TOPO_ASRU_COMPUTE) {
114 		if (topo_prop_method_register(node, TOPO_PGROUP_PROTOCOL,
115 		    TOPO_PROP_ASRU, TOPO_TYPE_FMRI, TOPO_METH_ASRU_COMPUTE,
116 		    asru, err) < 0)
117 			return (-1);
118 	} else {
119 		if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL,
120 		    TOPO_PROP_ASRU, TOPO_PROP_IMMUTABLE, asru, err) < 0)
121 			return (-1);
122 	}
123 
124 	return (0);
125 }
126 
127 int
128 topo_node_fru_set(tnode_t *node, nvlist_t *fru, int flag, int *err)
129 {
130 
131 	/*
132 	 * Inherit FRU property from our parent if not specified
133 	 */
134 	if (fru == NULL) {
135 		if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL, TOPO_PROP_FRU,
136 		    err) < 0) {
137 			return (-1);
138 		}
139 	} else if (flag & TOPO_FRU_COMPUTE) {
140 		if (topo_prop_method_register(node, TOPO_PGROUP_PROTOCOL,
141 		    TOPO_PROP_FRU, TOPO_TYPE_FMRI, TOPO_METH_FRU_COMPUTE,
142 		    fru, err) < 0)
143 			return (-1);
144 	} else {
145 		if (topo_prop_set_fmri(node, TOPO_PGROUP_PROTOCOL,
146 		    TOPO_PROP_FRU, TOPO_PROP_IMMUTABLE, fru, err) < 0)
147 			return (-1);
148 	}
149 
150 
151 	return (0);
152 }
153 
154 int
155 topo_node_label_set(tnode_t *node, char *label, int *err)
156 {
157 
158 	/*
159 	 * Inherit FRU property from our parent if * not specified
160 	 */
161 	if (label == NULL) {
162 		if (topo_prop_inherit(node, TOPO_PGROUP_PROTOCOL,
163 		    TOPO_PROP_LABEL, err) < 0) {
164 			return (-1);
165 		}
166 	} else {
167 		if (topo_prop_set_string(node, TOPO_PGROUP_PROTOCOL,
168 		    TOPO_PROP_LABEL, TOPO_PROP_IMMUTABLE, label, err) < 0)
169 			return (-1);
170 	}
171 
172 	return (0);
173 }
174