blob: b3fac2ca3894964bbd4c7b07da093b3bca16246e [file] [log] [blame]
Patrick Venture0b02be92018-08-31 11:55:55 -07001#include <malloc.h>
2#include <stdint.h>
Chris Austen8a45e7c2015-10-15 00:31:46 -05003#include <stdio.h>
4#include <string.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07005
Chris Austen10ccc0f2015-12-10 18:27:04 -06006#include "sensorhandler.h"
Chris Austen8a45e7c2015-10-15 00:31:46 -05007
Emily Shaffer391f3302017-04-03 10:27:08 -07008extern uint8_t find_type_for_sensor_number(uint8_t);
Chris Austen0130d6e2015-10-15 22:32:36 -05009
Patrick Venture0b02be92018-08-31 11:55:55 -070010struct sensorRES_t
11{
12 uint8_t sensor_number;
13 uint8_t operation;
14 uint8_t sensor_reading;
15 uint8_t assert_state7_0;
16 uint8_t assert_state14_8;
17 uint8_t deassert_state7_0;
18 uint8_t deassert_state14_8;
19 uint8_t event_data1;
20 uint8_t event_data2;
21 uint8_t event_data3;
22} __attribute__((packed));
Chris Austen0130d6e2015-10-15 22:32:36 -050023
Patrick Venture0b02be92018-08-31 11:55:55 -070024#define ISBITSET(x, y) (((x) >> (y)) & 0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050025#define ASSERTINDEX 0
26#define DEASSERTINDEX 1
27
Patrick Venture0b02be92018-08-31 11:55:55 -070028// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert
29// value
30struct lookup_t
31{
32 uint8_t sensor_type;
33 uint8_t offset;
34 int (*func)(const sensorRES_t*, const lookup_t*, const char*);
35 char member[16];
36 char assertion[64];
37 char deassertion[64];
Chris Austen8a45e7c2015-10-15 00:31:46 -050038};
39
Patrick Venture0b02be92018-08-31 11:55:55 -070040extern int updateDbusInterface(uint8_t, const char*, const char*);
Chris Austen0130d6e2015-10-15 22:32:36 -050041
Patrick Venture0b02be92018-08-31 11:55:55 -070042int set_sensor_dbus_state_simple(const sensorRES_t* pRec,
43 const lookup_t* pTable, const char* value)
44{
Chris Austen0130d6e2015-10-15 22:32:36 -050045
Patrick Venture0b02be92018-08-31 11:55:55 -070046 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value);
Chris Austen0130d6e2015-10-15 22:32:36 -050047}
48
Patrick Venture0b02be92018-08-31 11:55:55 -070049struct event_data_t
50{
51 uint8_t data;
52 char text[64];
Chris Austen0130d6e2015-10-15 22:32:36 -050053};
54
Patrick Venture0b02be92018-08-31 11:55:55 -070055event_data_t g_fwprogress02h[] = {{0x00, "Unspecified"},
56 {0x01, "Memory Init"},
57 {0x02, "HD Init"},
58 {0x03, "Secondary Proc Init"},
59 {0x04, "User Authentication"},
60 {0x05, "User init system setup"},
61 {0x06, "USB configuration"},
62 {0x07, "PCI configuration"},
63 {0x08, "Option ROM Init"},
64 {0x09, "Video Init"},
65 {0x0A, "Cache Init"},
66 {0x0B, "SM Bus init"},
67 {0x0C, "Keyboard Init"},
68 {0x0D, "Embedded ctrl init"},
69 {0x0E, "Docking station attachment"},
70 {0x0F, "Enable docking station"},
71 {0x10, "Docking station ejection"},
72 {0x11, "Disabling docking station"},
73 {0x12, "Calling OS Wakeup"},
74 {0x13, "Starting OS"},
75 {0x14, "Baseboard Init"},
76 {0x15, ""},
77 {0x16, "Floppy Init"},
78 {0x17, "Keyboard Test"},
79 {0x18, "Pointing Device Test"},
80 {0x19, "Primary Proc Init"},
81 {0xFF, "Unknown"}};
Chris Austen0130d6e2015-10-15 22:32:36 -050082
Chris Austend7cf0e42015-11-07 14:27:12 -060083event_data_t g_fwprogress00h[] = {
Patrick Venture0b02be92018-08-31 11:55:55 -070084 {0x00, "Unspecified."},
85 {0x01, "No system memory detected"},
86 {0x02, "No usable system memory"},
87 {0x03, "Unrecoverable hard-disk/ATAPI/IDE"},
88 {0x04, "Unrecoverable system-board"},
89 {0x05, "Unrecoverable diskette"},
90 {0x06, "Unrecoverable hard-disk controller"},
91 {0x07, "Unrecoverable PS/2 or USB keyboard"},
92 {0x08, "Removable boot media not found"},
93 {0x09, "Unrecoverable video controller"},
94 {0x0A, "No video device detected"},
95 {0x0B, "Firmware ROM corruption detected"},
96 {0x0C, "CPU voltage mismatch"},
97 {0x0D, "CPU speed matching"},
98 {0xFF, "unknown"},
Chris Austend7cf0e42015-11-07 14:27:12 -060099};
Chris Austen0130d6e2015-10-15 22:32:36 -0500100
Patrick Venture0b02be92018-08-31 11:55:55 -0700101char* event_data_lookup(event_data_t* p, uint8_t b)
102{
Chris Austen0130d6e2015-10-15 22:32:36 -0500103
Patrick Venture0b02be92018-08-31 11:55:55 -0700104 while (p->data != 0xFF)
105 {
106 if (p->data == b)
107 {
108 break;
109 }
110 p++;
111 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500112
Patrick Venture0b02be92018-08-31 11:55:55 -0700113 return p->text;
Chris Austen0130d6e2015-10-15 22:32:36 -0500114}
Chris Austend7cf0e42015-11-07 14:27:12 -0600115
Patrick Venture0b02be92018-08-31 11:55:55 -0700116// The fw progress sensor contains some additional information that needs to be
117// processed prior to calling the dbus code.
118int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec,
119 const lookup_t* pTable, const char* value)
120{
Chris Austend7cf0e42015-11-07 14:27:12 -0600121
Patrick Venture0b02be92018-08-31 11:55:55 -0700122 char valuestring[128];
123 char* p = valuestring;
Chris Austend7cf0e42015-11-07 14:27:12 -0600124
Patrick Venture0b02be92018-08-31 11:55:55 -0700125 switch (pTable->offset)
126 {
Chris Austen0130d6e2015-10-15 22:32:36 -0500127
Patrick Venture0b02be92018-08-31 11:55:55 -0700128 case 0x00:
129 snprintf(p, sizeof(valuestring), "POST Error, %s",
130 event_data_lookup(g_fwprogress00h, pRec->event_data2));
131 break;
132 case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the
133 ipmi spec says to do */
134 snprintf(p, sizeof(valuestring), "FW Hang, %s",
135 event_data_lookup(g_fwprogress02h, pRec->event_data2));
136 break;
137 case 0x02:
138 snprintf(p, sizeof(valuestring), "FW Progress, %s",
139 event_data_lookup(g_fwprogress02h, pRec->event_data2));
140 break;
141 default:
142 snprintf(p, sizeof(valuestring),
143 "Internal warning, fw_progres offset unknown (0x%02x)",
144 pTable->offset);
145 break;
146 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500147
Patrick Venture0b02be92018-08-31 11:55:55 -0700148 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
Chris Austen0130d6e2015-10-15 22:32:36 -0500149}
150
Patrick Venture0b02be92018-08-31 11:55:55 -0700151// Handling this special OEM sensor by coping what is in byte 4. I also think
152// that is odd considering byte 3 is for sensor reading. This seems like a
153// misuse of the IPMI spec
154int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec,
155 const lookup_t* pTable, const char* value)
156{
157 return set_sensor_dbus_state_y(pRec->sensor_number, "setValue",
Chris Austen10ccc0f2015-12-10 18:27:04 -0600158 pRec->assert_state7_0);
Chris Austen0a4e2472015-10-18 12:19:40 -0500159}
160
Patrick Venture0b02be92018-08-31 11:55:55 -0700161int set_sensor_dbus_state_system_event(const sensorRES_t* pRec,
162 const lookup_t* pTable,
163 const char* value)
164{
165 char valuestring[128];
166 char* p = valuestring;
Chris Austen800ba712015-12-03 15:31:00 -0600167
Patrick Venture0b02be92018-08-31 11:55:55 -0700168 switch (pTable->offset)
169 {
Chris Austen800ba712015-12-03 15:31:00 -0600170
Patrick Venture0b02be92018-08-31 11:55:55 -0700171 case 0x00:
172 snprintf(p, sizeof(valuestring), "System Reconfigured");
173 break;
174 case 0x01:
175 snprintf(p, sizeof(valuestring), "OEM Boot Event");
176 break;
177 case 0x02:
178 snprintf(p, sizeof(valuestring),
179 "Undetermined System Hardware Failure");
180 break;
181 case 0x03:
182 snprintf(p, sizeof(valuestring),
183 "System Failure see error log for more details (0x%02x)",
184 pRec->event_data2);
185 break;
186 case 0x04:
187 snprintf(
188 p, sizeof(valuestring),
189 "System Failure see PEF error log for more details (0x%02x)",
190 pRec->event_data2);
191 break;
192 default:
193 snprintf(p, sizeof(valuestring),
194 "Internal warning, system_event offset unknown (0x%02x)",
195 pTable->offset);
196 break;
197 }
Chris Austen800ba712015-12-03 15:31:00 -0600198
Patrick Venture0b02be92018-08-31 11:55:55 -0700199 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
Chris Austen800ba712015-12-03 15:31:00 -0600200}
Chris Austen0130d6e2015-10-15 22:32:36 -0500201
Chris Austen8a45e7c2015-10-15 00:31:46 -0500202// This table lists only senors we care about telling dbus about.
Chris Austen0012e9b2015-10-22 01:37:46 -0500203// Offset definition cab be found in section 42.2 of the IPMI 2.0
Chris Austen8a45e7c2015-10-15 00:31:46 -0500204// spec. Add more if/when there are more items of interest.
Chris Austen0130d6e2015-10-15 22:32:36 -0500205lookup_t g_ipmidbuslookup[] = {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500206
Patrick Venture0b02be92018-08-31 11:55:55 -0700207 {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled",
208 ""}, // OCC Inactive 0
209 {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled",
210 ""}, // OCC Active 1
211 // Turbo Allowed
212 {0xda, 0x00, set_sensor_dbus_state_simple, "setValue", "True", "False"},
213 // Power Supply Derating
214 {0xb4, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
215 // Power Cap
216 {0xC2, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
217 {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
218 {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"},
219 {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
220 {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"},
221 {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
222 {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
223 {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
224 {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"},
225 {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "", ""},
226 {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue",
227 "Boot completed (00)", ""},
228 {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue",
229 "Boot completed (01)", ""},
230 {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed",
231 ""},
232 {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue",
233 "Diagnostic boot completed", ""},
234 {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue",
235 "CD-ROM boot completed", ""},
236 {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed",
237 ""},
238 {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue",
239 "Boot completed (06)", ""},
240 {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""},
241 {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""},
242 {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""},
243 {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""},
244 {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""},
245 {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""},
246 {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""},
247 {0xFF, 0xFF, NULL, "", "", ""}};
Chris Austen8a45e7c2015-10-15 00:31:46 -0500248
Patrick Venture0b02be92018-08-31 11:55:55 -0700249void reportSensorEventAssert(sensorRES_t* pRec, int index)
250{
251 lookup_t* pTable = &g_ipmidbuslookup[index];
252 (*pTable->func)(pRec, pTable, pTable->assertion);
Chris Austen0130d6e2015-10-15 22:32:36 -0500253}
Patrick Venture0b02be92018-08-31 11:55:55 -0700254void reportSensorEventDeassert(sensorRES_t* pRec, int index)
255{
256 lookup_t* pTable = &g_ipmidbuslookup[index];
257 (*pTable->func)(pRec, pTable, pTable->deassertion);
Chris Austen0130d6e2015-10-15 22:32:36 -0500258}
259
Patrick Venture0b02be92018-08-31 11:55:55 -0700260int findindex(const uint8_t sensor_type, int offset, int* index)
261{
Chris Austen0130d6e2015-10-15 22:32:36 -0500262
Patrick Venture0b02be92018-08-31 11:55:55 -0700263 int i = 0, rc = 0;
264 lookup_t* pTable = g_ipmidbuslookup;
Gunnar Millsd8249ee2018-04-12 16:33:53 -0500265
Patrick Venture0b02be92018-08-31 11:55:55 -0700266 do
267 {
268 if (((pTable + i)->sensor_type == sensor_type) &&
269 ((pTable + i)->offset == offset))
270 {
271 rc = 1;
272 *index = i;
273 break;
274 }
275 i++;
276 } while ((pTable + i)->sensor_type != 0xFF);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500277
Patrick Venture0b02be92018-08-31 11:55:55 -0700278 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500279}
280
Patrick Venture0b02be92018-08-31 11:55:55 -0700281bool shouldReport(uint8_t sensorType, int offset, int* index)
282{
Chris Austen8a45e7c2015-10-15 00:31:46 -0500283
Patrick Venture0b02be92018-08-31 11:55:55 -0700284 bool rc = false;
Chris Austen0a4e2472015-10-18 12:19:40 -0500285
Patrick Venture0b02be92018-08-31 11:55:55 -0700286 if (findindex(sensorType, offset, index))
287 {
288 rc = true;
289 }
290 if (rc == false)
291 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530292#ifdef __IPMI_DEBUG__
293 log<level::DEBUG>("LOOKATME: Sensor should not be reported",
Patrick Venture0b02be92018-08-31 11:55:55 -0700294 entry("SENSORTYPE=0x%02x", sensorType),
295 entry("OFFSET=0x%02x", offset));
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530296#endif
Patrick Venture0b02be92018-08-31 11:55:55 -0700297 }
Chris Austen0a4e2472015-10-18 12:19:40 -0500298
Patrick Venture0b02be92018-08-31 11:55:55 -0700299 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500300}
301
Patrick Venture0b02be92018-08-31 11:55:55 -0700302int updateSensorRecordFromSSRAESC(const void* record)
303{
Chris Austen8a45e7c2015-10-15 00:31:46 -0500304
Patrick Venture0b02be92018-08-31 11:55:55 -0700305 sensorRES_t* pRec = (sensorRES_t*)record;
306 uint8_t stype;
307 int index, i = 0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500308
Patrick Venture0b02be92018-08-31 11:55:55 -0700309 stype = find_type_for_sensor_number(pRec->sensor_number);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500310
Patrick Venture0b02be92018-08-31 11:55:55 -0700311 // 0xC3 types use the assertion7_0 for the value to be set
312 // so skip the reseach and call the correct event reporting
313 // function
314 if (stype == 0xC3)
315 {
Chris Austen0012e9b2015-10-22 01:37:46 -0500316
Patrick Venture0b02be92018-08-31 11:55:55 -0700317 shouldReport(stype, 0x00, &index);
318 reportSensorEventAssert(pRec, index);
319 }
320 else
321 {
322 // Scroll through each bit position . Determine
323 // if any bit is either asserted or Deasserted.
324 for (i = 0; i < 8; i++)
325 {
Chris Austen0012e9b2015-10-22 01:37:46 -0500326
Patrick Venture0b02be92018-08-31 11:55:55 -0700327 if ((ISBITSET(pRec->assert_state7_0, i)) &&
328 (shouldReport(stype, i, &index)))
329 {
330 reportSensorEventAssert(pRec, index);
331 }
332 if ((ISBITSET(pRec->assert_state14_8, i)) &&
333 (shouldReport(stype, i + 8, &index)))
334 {
335 reportSensorEventAssert(pRec, index);
336 }
337 if ((ISBITSET(pRec->deassert_state7_0, i)) &&
338 (shouldReport(stype, i, &index)))
339 {
340 reportSensorEventDeassert(pRec, index);
341 }
342 if ((ISBITSET(pRec->deassert_state14_8, i)) &&
343 (shouldReport(stype, i + 8, &index)))
344 {
345 reportSensorEventDeassert(pRec, index);
346 }
347 }
348 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500349
Patrick Venture0b02be92018-08-31 11:55:55 -0700350 return 0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500351}