blob: 593f8a81c4c7ec12bc4fe378a0a37ecea0e9d460 [file] [log] [blame]
Patrick Venture46470a32018-09-07 19:26:25 -07001#include "sensorhandler.hpp"
2
Patrick Venture0b02be92018-08-31 11:55:55 -07003#include <malloc.h>
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Emily Shaffer391f3302017-04-03 10:27:08 -07005extern uint8_t find_type_for_sensor_number(uint8_t);
Chris Austen0130d6e2015-10-15 22:32:36 -05006
Patrick Venture0b02be92018-08-31 11:55:55 -07007struct sensorRES_t
8{
9 uint8_t sensor_number;
10 uint8_t operation;
11 uint8_t sensor_reading;
12 uint8_t assert_state7_0;
13 uint8_t assert_state14_8;
14 uint8_t deassert_state7_0;
15 uint8_t deassert_state14_8;
16 uint8_t event_data1;
17 uint8_t event_data2;
18 uint8_t event_data3;
19} __attribute__((packed));
Chris Austen0130d6e2015-10-15 22:32:36 -050020
Patrick Venture0b02be92018-08-31 11:55:55 -070021#define ISBITSET(x, y) (((x) >> (y)) & 0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050022#define ASSERTINDEX 0
23#define DEASSERTINDEX 1
24
Patrick Venture0b02be92018-08-31 11:55:55 -070025// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert
26// value
27struct lookup_t
28{
29 uint8_t sensor_type;
30 uint8_t offset;
31 int (*func)(const sensorRES_t*, const lookup_t*, const char*);
32 char member[16];
33 char assertion[64];
34 char deassertion[64];
Chris Austen8a45e7c2015-10-15 00:31:46 -050035};
36
Patrick Venture0b02be92018-08-31 11:55:55 -070037extern int updateDbusInterface(uint8_t, const char*, const char*);
Chris Austen0130d6e2015-10-15 22:32:36 -050038
Patrick Venture0b02be92018-08-31 11:55:55 -070039int set_sensor_dbus_state_simple(const sensorRES_t* pRec,
40 const lookup_t* pTable, const char* value)
41{
Chris Austen0130d6e2015-10-15 22:32:36 -050042
Patrick Venture0b02be92018-08-31 11:55:55 -070043 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value);
Chris Austen0130d6e2015-10-15 22:32:36 -050044}
45
Patrick Venture0b02be92018-08-31 11:55:55 -070046struct event_data_t
47{
48 uint8_t data;
49 char text[64];
Chris Austen0130d6e2015-10-15 22:32:36 -050050};
51
Patrick Venture0b02be92018-08-31 11:55:55 -070052event_data_t g_fwprogress02h[] = {{0x00, "Unspecified"},
53 {0x01, "Memory Init"},
54 {0x02, "HD Init"},
55 {0x03, "Secondary Proc Init"},
56 {0x04, "User Authentication"},
57 {0x05, "User init system setup"},
58 {0x06, "USB configuration"},
59 {0x07, "PCI configuration"},
60 {0x08, "Option ROM Init"},
61 {0x09, "Video Init"},
62 {0x0A, "Cache Init"},
63 {0x0B, "SM Bus init"},
64 {0x0C, "Keyboard Init"},
65 {0x0D, "Embedded ctrl init"},
66 {0x0E, "Docking station attachment"},
67 {0x0F, "Enable docking station"},
68 {0x10, "Docking station ejection"},
69 {0x11, "Disabling docking station"},
70 {0x12, "Calling OS Wakeup"},
71 {0x13, "Starting OS"},
72 {0x14, "Baseboard Init"},
73 {0x15, ""},
74 {0x16, "Floppy Init"},
75 {0x17, "Keyboard Test"},
76 {0x18, "Pointing Device Test"},
77 {0x19, "Primary Proc Init"},
78 {0xFF, "Unknown"}};
Chris Austen0130d6e2015-10-15 22:32:36 -050079
Chris Austend7cf0e42015-11-07 14:27:12 -060080event_data_t g_fwprogress00h[] = {
Patrick Venture0b02be92018-08-31 11:55:55 -070081 {0x00, "Unspecified."},
82 {0x01, "No system memory detected"},
83 {0x02, "No usable system memory"},
84 {0x03, "Unrecoverable hard-disk/ATAPI/IDE"},
85 {0x04, "Unrecoverable system-board"},
86 {0x05, "Unrecoverable diskette"},
87 {0x06, "Unrecoverable hard-disk controller"},
88 {0x07, "Unrecoverable PS/2 or USB keyboard"},
89 {0x08, "Removable boot media not found"},
90 {0x09, "Unrecoverable video controller"},
91 {0x0A, "No video device detected"},
92 {0x0B, "Firmware ROM corruption detected"},
93 {0x0C, "CPU voltage mismatch"},
94 {0x0D, "CPU speed matching"},
95 {0xFF, "unknown"},
Chris Austend7cf0e42015-11-07 14:27:12 -060096};
Chris Austen0130d6e2015-10-15 22:32:36 -050097
Patrick Venture0b02be92018-08-31 11:55:55 -070098char* event_data_lookup(event_data_t* p, uint8_t b)
99{
Chris Austen0130d6e2015-10-15 22:32:36 -0500100
Patrick Venture0b02be92018-08-31 11:55:55 -0700101 while (p->data != 0xFF)
102 {
103 if (p->data == b)
104 {
105 break;
106 }
107 p++;
108 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500109
Patrick Venture0b02be92018-08-31 11:55:55 -0700110 return p->text;
Chris Austen0130d6e2015-10-15 22:32:36 -0500111}
Chris Austend7cf0e42015-11-07 14:27:12 -0600112
Patrick Venture0b02be92018-08-31 11:55:55 -0700113// The fw progress sensor contains some additional information that needs to be
114// processed prior to calling the dbus code.
115int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec,
Willy Tu11d68892022-01-20 10:37:34 -0800116 const lookup_t* pTable, const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700117{
Chris Austend7cf0e42015-11-07 14:27:12 -0600118
Patrick Venture0b02be92018-08-31 11:55:55 -0700119 char valuestring[128];
120 char* p = valuestring;
Chris Austend7cf0e42015-11-07 14:27:12 -0600121
Patrick Venture0b02be92018-08-31 11:55:55 -0700122 switch (pTable->offset)
123 {
Chris Austen0130d6e2015-10-15 22:32:36 -0500124
Patrick Venture0b02be92018-08-31 11:55:55 -0700125 case 0x00:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700126 std::snprintf(
127 p, sizeof(valuestring), "POST Error, %s",
128 event_data_lookup(g_fwprogress00h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700129 break;
130 case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the
131 ipmi spec says to do */
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700132 std::snprintf(
133 p, sizeof(valuestring), "FW Hang, %s",
134 event_data_lookup(g_fwprogress02h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700135 break;
136 case 0x02:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700137 std::snprintf(
138 p, sizeof(valuestring), "FW Progress, %s",
139 event_data_lookup(g_fwprogress02h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700140 break;
141 default:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700142 std::snprintf(
143 p, sizeof(valuestring),
144 "Internal warning, fw_progres offset unknown (0x%02x)",
145 pTable->offset);
Patrick Venture0b02be92018-08-31 11:55:55 -0700146 break;
147 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500148
Patrick Venture0b02be92018-08-31 11:55:55 -0700149 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
Chris Austen0130d6e2015-10-15 22:32:36 -0500150}
151
Patrick Venture0b02be92018-08-31 11:55:55 -0700152// Handling this special OEM sensor by coping what is in byte 4. I also think
153// that is odd considering byte 3 is for sensor reading. This seems like a
154// misuse of the IPMI spec
Willy Tu11d68892022-01-20 10:37:34 -0800155int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, const lookup_t*,
156 const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700157{
158 return set_sensor_dbus_state_y(pRec->sensor_number, "setValue",
Chris Austen10ccc0f2015-12-10 18:27:04 -0600159 pRec->assert_state7_0);
Chris Austen0a4e2472015-10-18 12:19:40 -0500160}
161
Patrick Venture0b02be92018-08-31 11:55:55 -0700162int set_sensor_dbus_state_system_event(const sensorRES_t* pRec,
Willy Tu11d68892022-01-20 10:37:34 -0800163 const lookup_t* pTable, const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700164{
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:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700172 std::snprintf(p, sizeof(valuestring), "System Reconfigured");
Patrick Venture0b02be92018-08-31 11:55:55 -0700173 break;
174 case 0x01:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700175 std::snprintf(p, sizeof(valuestring), "OEM Boot Event");
Patrick Venture0b02be92018-08-31 11:55:55 -0700176 break;
177 case 0x02:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700178 std::snprintf(p, sizeof(valuestring),
179 "Undetermined System Hardware Failure");
Patrick Venture0b02be92018-08-31 11:55:55 -0700180 break;
181 case 0x03:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700182 std::snprintf(
183 p, sizeof(valuestring),
184 "System Failure see error log for more details (0x%02x)",
185 pRec->event_data2);
Patrick Venture0b02be92018-08-31 11:55:55 -0700186 break;
187 case 0x04:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700188 std::snprintf(
Patrick Venture0b02be92018-08-31 11:55:55 -0700189 p, sizeof(valuestring),
190 "System Failure see PEF error log for more details (0x%02x)",
191 pRec->event_data2);
192 break;
193 default:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700194 std::snprintf(
195 p, sizeof(valuestring),
196 "Internal warning, system_event offset unknown (0x%02x)",
197 pTable->offset);
Patrick Venture0b02be92018-08-31 11:55:55 -0700198 break;
199 }
Chris Austen800ba712015-12-03 15:31:00 -0600200
Patrick Venture0b02be92018-08-31 11:55:55 -0700201 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
Chris Austen800ba712015-12-03 15:31:00 -0600202}
Chris Austen0130d6e2015-10-15 22:32:36 -0500203
Chris Austen8a45e7c2015-10-15 00:31:46 -0500204// This table lists only senors we care about telling dbus about.
Chris Austen0012e9b2015-10-22 01:37:46 -0500205// Offset definition cab be found in section 42.2 of the IPMI 2.0
Chris Austen8a45e7c2015-10-15 00:31:46 -0500206// spec. Add more if/when there are more items of interest.
Chris Austen0130d6e2015-10-15 22:32:36 -0500207lookup_t g_ipmidbuslookup[] = {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500208
Patrick Venture0b02be92018-08-31 11:55:55 -0700209 {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled",
210 ""}, // OCC Inactive 0
211 {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled",
212 ""}, // OCC Active 1
213 // Turbo Allowed
214 {0xda, 0x00, set_sensor_dbus_state_simple, "setValue", "True", "False"},
215 // Power Supply Derating
216 {0xb4, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
217 // Power Cap
218 {0xC2, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
219 {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
220 {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"},
221 {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
222 {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"},
223 {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
224 {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
225 {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
226 {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"},
227 {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "", ""},
228 {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue",
229 "Boot completed (00)", ""},
230 {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue",
231 "Boot completed (01)", ""},
232 {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed",
233 ""},
234 {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue",
235 "Diagnostic boot completed", ""},
236 {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue",
237 "CD-ROM boot completed", ""},
238 {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed",
239 ""},
240 {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue",
241 "Boot completed (06)", ""},
242 {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""},
243 {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""},
244 {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""},
245 {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""},
246 {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""},
247 {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""},
248 {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""},
249 {0xFF, 0xFF, NULL, "", "", ""}};
Chris Austen8a45e7c2015-10-15 00:31:46 -0500250
Patrick Ventured99148b2018-10-13 10:06:13 -0700251void reportSensorEventAssert(const sensorRES_t* pRec, int index)
Patrick Venture0b02be92018-08-31 11:55:55 -0700252{
253 lookup_t* pTable = &g_ipmidbuslookup[index];
254 (*pTable->func)(pRec, pTable, pTable->assertion);
Chris Austen0130d6e2015-10-15 22:32:36 -0500255}
Patrick Ventured99148b2018-10-13 10:06:13 -0700256void reportSensorEventDeassert(const sensorRES_t* pRec, int index)
Patrick Venture0b02be92018-08-31 11:55:55 -0700257{
258 lookup_t* pTable = &g_ipmidbuslookup[index];
259 (*pTable->func)(pRec, pTable, pTable->deassertion);
Chris Austen0130d6e2015-10-15 22:32:36 -0500260}
261
Patrick Venture0b02be92018-08-31 11:55:55 -0700262int findindex(const uint8_t sensor_type, int offset, int* index)
263{
Chris Austen0130d6e2015-10-15 22:32:36 -0500264
Patrick Venture0b02be92018-08-31 11:55:55 -0700265 int i = 0, rc = 0;
266 lookup_t* pTable = g_ipmidbuslookup;
Gunnar Millsd8249ee2018-04-12 16:33:53 -0500267
Patrick Venture0b02be92018-08-31 11:55:55 -0700268 do
269 {
270 if (((pTable + i)->sensor_type == sensor_type) &&
271 ((pTable + i)->offset == offset))
272 {
273 rc = 1;
274 *index = i;
275 break;
276 }
277 i++;
278 } while ((pTable + i)->sensor_type != 0xFF);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500279
Patrick Venture0b02be92018-08-31 11:55:55 -0700280 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500281}
282
Patrick Venture0b02be92018-08-31 11:55:55 -0700283bool shouldReport(uint8_t sensorType, int offset, int* index)
284{
Patrick Venture0b02be92018-08-31 11:55:55 -0700285 bool rc = false;
Chris Austen0a4e2472015-10-18 12:19:40 -0500286
Patrick Venture0b02be92018-08-31 11:55:55 -0700287 if (findindex(sensorType, offset, index))
288 {
289 rc = true;
290 }
291 if (rc == false)
292 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530293#ifdef __IPMI_DEBUG__
294 log<level::DEBUG>("LOOKATME: Sensor should not be reported",
Patrick Venture0b02be92018-08-31 11:55:55 -0700295 entry("SENSORTYPE=0x%02x", sensorType),
296 entry("OFFSET=0x%02x", offset));
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530297#endif
Patrick Venture0b02be92018-08-31 11:55:55 -0700298 }
Chris Austen0a4e2472015-10-18 12:19:40 -0500299
Patrick Venture0b02be92018-08-31 11:55:55 -0700300 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500301}
302
Patrick Venture0b02be92018-08-31 11:55:55 -0700303int updateSensorRecordFromSSRAESC(const void* record)
304{
Patrick Ventured99148b2018-10-13 10:06:13 -0700305 auto pRec = static_cast<const sensorRES_t*>(record);
Patrick Venture0b02be92018-08-31 11:55:55 -0700306 uint8_t stype;
Patrick Venture4491a462018-10-13 13:00:42 -0700307 int index;
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 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700316 shouldReport(stype, 0x00, &index);
317 reportSensorEventAssert(pRec, index);
318 }
319 else
320 {
321 // Scroll through each bit position . Determine
322 // if any bit is either asserted or Deasserted.
Patrick Venture4491a462018-10-13 13:00:42 -0700323 for (int i = 0; i < 8; i++)
Patrick Venture0b02be92018-08-31 11:55:55 -0700324 {
Chris Austen0012e9b2015-10-22 01:37:46 -0500325
Patrick Venture0b02be92018-08-31 11:55:55 -0700326 if ((ISBITSET(pRec->assert_state7_0, i)) &&
327 (shouldReport(stype, i, &index)))
328 {
329 reportSensorEventAssert(pRec, index);
330 }
331 if ((ISBITSET(pRec->assert_state14_8, i)) &&
332 (shouldReport(stype, i + 8, &index)))
333 {
334 reportSensorEventAssert(pRec, index);
335 }
336 if ((ISBITSET(pRec->deassert_state7_0, i)) &&
337 (shouldReport(stype, i, &index)))
338 {
339 reportSensorEventDeassert(pRec, index);
340 }
341 if ((ISBITSET(pRec->deassert_state14_8, i)) &&
342 (shouldReport(stype, i + 8, &index)))
343 {
344 reportSensorEventDeassert(pRec, index);
345 }
346 }
347 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500348
Patrick Venture0b02be92018-08-31 11:55:55 -0700349 return 0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500350}