6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / lib / libipmi / common / ipmi_sel.c
blob528be3546319c6f4ffed26a385ac4724b163d7d2
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <libipmi.h>
30 #include <stddef.h>
31 #include <string.h>
32 #include <strings.h>
34 #include "ipmi_impl.h"
37 * 31.2 Get SEL Info Command.
39 ipmi_sel_info_t *
40 ipmi_sel_get_info(ipmi_handle_t *ihp)
42 ipmi_cmd_t cmd, *rsp;
43 ipmi_sel_info_t *ip;
44 uint16_t tmp16;
45 uint32_t tmp32;
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;
53 if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
54 return (NULL);
56 ip = (ipmi_sel_info_t *)rsp->ic_data;
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));
67 return (ip);
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;
77 ipmi_sel_event_t *
78 ipmi_sel_get_entry(ipmi_handle_t *ihp, uint16_t id)
80 ipmi_cmd_t cmd, *rsp;
81 ipmi_sel_event_t *evp;
82 ipmi_cmd_get_sel_entry_t data;
83 uint32_t tmp;
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;
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;
96 if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
97 return (NULL);
99 if (rsp->ic_dlen < sizeof (ipmi_sel_event_t)) {
100 (void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
101 return (NULL);
104 evp = (ipmi_sel_event_t *)rsp->ic_data;
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) {
111 tmp = LE_IN32(&evp->isel_ev_ts);
112 (void) memcpy(&evp->isel_ev_ts, &tmp, sizeof (tmp));
114 return (evp);
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.
123 ipmi_sel_get_time(ipmi_handle_t *ihp, uint32_t *tp)
125 ipmi_cmd_t cmd, *rsp;
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;
133 if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
134 return (-1);
136 if (rsp->ic_dlen < sizeof (uint32_t))
137 return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
139 *tp = LE_IN32(rsp->ic_data);
141 return (0);
145 ipmi_sel_set_time(ipmi_handle_t *ihp, uint32_t t)
147 ipmi_cmd_t cmd;
149 t = LE_32(t);
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;
157 if (ipmi_send(ihp, &cmd) == NULL)
158 return (-1);
160 return (0);
164 ipmi_sel_get_utc_offset(ipmi_handle_t *ihp, int *offp)
166 ipmi_cmd_t cmd, *rsp;
167 int16_t off16;
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;
175 if ((rsp = ipmi_send(ihp, &cmd)) == NULL)
176 return (-1);
178 if (rsp->ic_dlen < sizeof (uint16_t))
179 return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
181 off16 = LE_IN16(rsp->ic_data);
182 *offp = off16;
184 return (0);
188 ipmi_sel_set_utc_offset(ipmi_handle_t *ihp, int off)
190 ipmi_cmd_t cmd;
191 int16_t off16 = off;
193 off16 = LE_16(off16);
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;
201 if (ipmi_send(ihp, &cmd) == NULL)
202 return (-1);
204 return (0);