xref: /titanic_44/usr/src/lib/libipmi/common/ipmi_sel.c (revision 2d6b5ea734bb47d251c82670646fde46af15fd69)
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 <libipmi.h>
30 #include <stddef.h>
31 #include <string.h>
32 #include <strings.h>
33 
34 #include "ipmi_impl.h"
35 
36 /*
37  * 31.2 Get SEL Info Command.
38  */
39 ipmi_sel_info_t *
40 ipmi_sel_get_info(ipmi_handle_t *ihp)
41 {
42 	ipmi_cmd_t cmd, *rsp;
43 	ipmi_sel_info_t *ip;
44 	uint16_t tmp16;
45 	uint32_t tmp32;
46 
47 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
48 	cmd.ic_lun = 0;
49 	cmd.ic_cmd = IPMI_CMD_GET_SEL_INFO;
50 	cmd.ic_dlen = 0;
51 	cmd.ic_data = NULL;
52 
53 	if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
54 		return (NULL);
55 
56 	ip = (ipmi_sel_info_t *)rsp->ic_data;
57 
58 	tmp16 = LE_IN16(&ip->isel_entries);
59 	(void) memcpy(&ip->isel_entries, &tmp16, sizeof (tmp16));
60 	tmp16 = LE_IN16(&ip->isel_free);
61 	(void) memcpy(&ip->isel_free, &tmp16, sizeof (tmp16));
62 	tmp32 = LE_IN32(&ip->isel_add_ts);
63 	(void) memcpy(&ip->isel_add_ts, &tmp32, sizeof (tmp32));
64 	tmp32 = LE_IN32(&ip->isel_erase_ts);
65 	(void) memcpy(&ip->isel_erase_ts, &tmp32, sizeof (tmp32));
66 
67 	return (ip);
68 }
69 
70 typedef struct ipmi_cmd_get_sel_entry {
71 	uint16_t	ic_sel_ent_resid;
72 	uint16_t	ic_sel_ent_recid;
73 	uint8_t		ic_sel_ent_offset;
74 	uint8_t		ic_sel_ent_bytes;
75 } ipmi_cmd_get_sel_entry_t;
76 
77 ipmi_sel_event_t *
78 ipmi_sel_get_entry(ipmi_handle_t *ihp, uint16_t id)
79 {
80 	ipmi_cmd_t cmd, *rsp;
81 	ipmi_sel_event_t *evp;
82 	ipmi_cmd_get_sel_entry_t data;
83 	uint32_t tmp;
84 
85 	data.ic_sel_ent_resid = 0;
86 	data.ic_sel_ent_recid = LE_16(id);
87 	data.ic_sel_ent_offset = 0;
88 	data.ic_sel_ent_bytes = 0xFF;
89 
90 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
91 	cmd.ic_lun = 0;
92 	cmd.ic_cmd = IPMI_CMD_GET_SEL_ENTRY;
93 	cmd.ic_dlen = sizeof (data);
94 	cmd.ic_data = &data;
95 
96 	if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
97 		return (NULL);
98 
99 	if (rsp->ic_dlen < sizeof (ipmi_sel_event_t)) {
100 		(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
101 		return (NULL);
102 	}
103 
104 	evp = (ipmi_sel_event_t *)rsp->ic_data;
105 
106 	evp->isel_ev_next = LE_IN16(&evp->isel_ev_next);
107 	evp->isel_ev_recid = LE_IN16(&evp->isel_ev_recid);
108 	if (evp->isel_ev_rectype == IPMI_SEL_SYSTEM ||
109 	    evp->isel_ev_rectype >= IPMI_SEL_OEM_LO) {
110 
111 		tmp = LE_IN32(&evp->isel_ev_ts);
112 		(void) memcpy(&evp->isel_ev_ts, &tmp, sizeof (tmp));
113 	}
114 	return (evp);
115 }
116 
117 /*
118  * SEL time management.  For the purposes of libipmi we assume that the SDR
119  * repository and SEL share the same timebase, even though the spec allows for
120  * separate time sources.  Hence no function to set the SDR repository time.
121  */
122 int
123 ipmi_sel_get_time(ipmi_handle_t *ihp, uint32_t *tp)
124 {
125 	ipmi_cmd_t cmd, *rsp;
126 
127 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
128 	cmd.ic_lun = 0;
129 	cmd.ic_cmd = IPMI_CMD_GET_SEL_TIME;
130 	cmd.ic_dlen = 0;
131 	cmd.ic_data = NULL;
132 
133 	if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
134 		return (-1);
135 
136 	if (rsp->ic_dlen < sizeof (uint32_t))
137 		return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
138 
139 	*tp = LE_IN32(rsp->ic_data);
140 
141 	return (0);
142 }
143 
144 int
145 ipmi_sel_set_time(ipmi_handle_t *ihp, uint32_t t)
146 {
147 	ipmi_cmd_t cmd;
148 
149 	t = LE_32(t);
150 
151 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
152 	cmd.ic_lun = 0;
153 	cmd.ic_cmd = IPMI_CMD_SET_SEL_TIME;
154 	cmd.ic_dlen = sizeof (t);
155 	cmd.ic_data = &t;
156 
157 	if (ipmi_send(ihp, &cmd) == NULL)
158 		return (-1);
159 
160 	return (0);
161 }
162 
163 int
164 ipmi_sel_get_utc_offset(ipmi_handle_t *ihp, int *offp)
165 {
166 	ipmi_cmd_t cmd, *rsp;
167 	int16_t off16;
168 
169 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
170 	cmd.ic_lun = 0;
171 	cmd.ic_cmd = IPMI_CMD_GET_SEL_UTC_OFFSET;
172 	cmd.ic_dlen = 0;
173 	cmd.ic_data = NULL;
174 
175 	if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
176 		return (-1);
177 
178 	if (rsp->ic_dlen < sizeof (uint16_t))
179 		return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
180 
181 	off16 = LE_IN16(rsp->ic_data);
182 	*offp = off16;
183 
184 	return (0);
185 }
186 
187 int
188 ipmi_sel_set_utc_offset(ipmi_handle_t *ihp, int off)
189 {
190 	ipmi_cmd_t cmd;
191 	int16_t off16 = off;
192 
193 	off16 = LE_16(off16);
194 
195 	cmd.ic_netfn = IPMI_NETFN_STORAGE;
196 	cmd.ic_lun = 0;
197 	cmd.ic_cmd = IPMI_CMD_SET_SEL_UTC_OFFSET;
198 	cmd.ic_dlen = sizeof (off16);
199 	cmd.ic_data = &off16;
200 
201 	if (ipmi_send(ihp, &cmd) == NULL)
202 		return (-1);
203 
204 	return (0);
205 }
206