blob: 55e4914e15266a5da70ee937b65da4438bb001f1 [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
George Liu5e72ce92024-07-19 09:26:40 +08005#include <phosphor-logging/lg2.hpp>
6
Emily Shaffer391f3302017-04-03 10:27:08 -07007extern uint8_t find_type_for_sensor_number(uint8_t);
Chris Austen0130d6e2015-10-15 22:32:36 -05008
Patrick Venture0b02be92018-08-31 11:55:55 -07009struct sensorRES_t
10{
11 uint8_t sensor_number;
12 uint8_t operation;
13 uint8_t sensor_reading;
14 uint8_t assert_state7_0;
15 uint8_t assert_state14_8;
16 uint8_t deassert_state7_0;
17 uint8_t deassert_state14_8;
18 uint8_t event_data1;
19 uint8_t event_data2;
20 uint8_t event_data3;
21} __attribute__((packed));
Chris Austen0130d6e2015-10-15 22:32:36 -050022
Patrick Venture0b02be92018-08-31 11:55:55 -070023#define ISBITSET(x, y) (((x) >> (y)) & 0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050024#define ASSERTINDEX 0
25#define DEASSERTINDEX 1
26
Patrick Venture0b02be92018-08-31 11:55:55 -070027// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert
28// value
29struct lookup_t
30{
31 uint8_t sensor_type;
32 uint8_t offset;
33 int (*func)(const sensorRES_t*, const lookup_t*, const char*);
34 char member[16];
35 char assertion[64];
36 char deassertion[64];
Chris Austen8a45e7c2015-10-15 00:31:46 -050037};
38
Patrick Venture0b02be92018-08-31 11:55:55 -070039extern int updateDbusInterface(uint8_t, const char*, const char*);
Chris Austen0130d6e2015-10-15 22:32:36 -050040
Patrick Venture0b02be92018-08-31 11:55:55 -070041int set_sensor_dbus_state_simple(const sensorRES_t* pRec,
42 const lookup_t* pTable, const char* value)
43{
Patrick Venture0b02be92018-08-31 11:55:55 -070044 return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value);
Chris Austen0130d6e2015-10-15 22:32:36 -050045}
46
Patrick Venture0b02be92018-08-31 11:55:55 -070047struct event_data_t
48{
49 uint8_t data;
50 char text[64];
Chris Austen0130d6e2015-10-15 22:32:36 -050051};
52
Patrick Williams1318a5e2024-08-16 15:19:54 -040053event_data_t g_fwprogress02h[] = {
54 {0x00, "Unspecified"},
55 {0x01, "Memory Init"},
56 {0x02, "HD Init"},
57 {0x03, "Secondary Proc Init"},
58 {0x04, "User Authentication"},
59 {0x05, "User init system setup"},
60 {0x06, "USB configuration"},
61 {0x07, "PCI configuration"},
62 {0x08, "Option ROM Init"},
63 {0x09, "Video Init"},
64 {0x0A, "Cache Init"},
65 {0x0B, "SM Bus init"},
66 {0x0C, "Keyboard Init"},
67 {0x0D, "Embedded ctrl init"},
68 {0x0E, "Docking station attachment"},
69 {0x0F, "Enable docking station"},
70 {0x10, "Docking station ejection"},
71 {0x11, "Disabling docking station"},
72 {0x12, "Calling OS Wakeup"},
73 {0x13, "Starting OS"},
74 {0x14, "Baseboard Init"},
75 {0x15, ""},
76 {0x16, "Floppy Init"},
77 {0x17, "Keyboard Test"},
78 {0x18, "Pointing Device Test"},
79 {0x19, "Primary Proc Init"},
80 {0xFF, "Unknown"}};
Chris Austen0130d6e2015-10-15 22:32:36 -050081
Chris Austend7cf0e42015-11-07 14:27:12 -060082event_data_t g_fwprogress00h[] = {
Patrick Venture0b02be92018-08-31 11:55:55 -070083 {0x00, "Unspecified."},
84 {0x01, "No system memory detected"},
85 {0x02, "No usable system memory"},
86 {0x03, "Unrecoverable hard-disk/ATAPI/IDE"},
87 {0x04, "Unrecoverable system-board"},
88 {0x05, "Unrecoverable diskette"},
89 {0x06, "Unrecoverable hard-disk controller"},
90 {0x07, "Unrecoverable PS/2 or USB keyboard"},
91 {0x08, "Removable boot media not found"},
92 {0x09, "Unrecoverable video controller"},
93 {0x0A, "No video device detected"},
94 {0x0B, "Firmware ROM corruption detected"},
95 {0x0C, "CPU voltage mismatch"},
96 {0x0D, "CPU speed matching"},
97 {0xFF, "unknown"},
Chris Austend7cf0e42015-11-07 14:27:12 -060098};
Chris Austen0130d6e2015-10-15 22:32:36 -050099
Patrick Venture0b02be92018-08-31 11:55:55 -0700100char* event_data_lookup(event_data_t* p, uint8_t b)
101{
Patrick Venture0b02be92018-08-31 11:55:55 -0700102 while (p->data != 0xFF)
103 {
104 if (p->data == b)
105 {
106 break;
107 }
108 p++;
109 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500110
Patrick Venture0b02be92018-08-31 11:55:55 -0700111 return p->text;
Chris Austen0130d6e2015-10-15 22:32:36 -0500112}
Chris Austend7cf0e42015-11-07 14:27:12 -0600113
Patrick Venture0b02be92018-08-31 11:55:55 -0700114// The fw progress sensor contains some additional information that needs to be
115// processed prior to calling the dbus code.
116int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec,
Willy Tu11d68892022-01-20 10:37:34 -0800117 const lookup_t* pTable, const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700118{
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 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700124 case 0x00:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700125 std::snprintf(
126 p, sizeof(valuestring), "POST Error, %s",
127 event_data_lookup(g_fwprogress00h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700128 break;
129 case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the
130 ipmi spec says to do */
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700131 std::snprintf(
132 p, sizeof(valuestring), "FW Hang, %s",
133 event_data_lookup(g_fwprogress02h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700134 break;
135 case 0x02:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700136 std::snprintf(
137 p, sizeof(valuestring), "FW Progress, %s",
138 event_data_lookup(g_fwprogress02h, pRec->event_data2));
Patrick Venture0b02be92018-08-31 11:55:55 -0700139 break;
140 default:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700141 std::snprintf(
142 p, sizeof(valuestring),
143 "Internal warning, fw_progres offset unknown (0x%02x)",
144 pTable->offset);
Patrick Venture0b02be92018-08-31 11:55:55 -0700145 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
Willy Tu11d68892022-01-20 10:37:34 -0800154int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, const lookup_t*,
155 const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700156{
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,
Willy Tu11d68892022-01-20 10:37:34 -0800162 const lookup_t* pTable, const char*)
Patrick Venture0b02be92018-08-31 11:55:55 -0700163{
164 char valuestring[128];
165 char* p = valuestring;
Chris Austen800ba712015-12-03 15:31:00 -0600166
Patrick Venture0b02be92018-08-31 11:55:55 -0700167 switch (pTable->offset)
168 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700169 case 0x00:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700170 std::snprintf(p, sizeof(valuestring), "System Reconfigured");
Patrick Venture0b02be92018-08-31 11:55:55 -0700171 break;
172 case 0x01:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700173 std::snprintf(p, sizeof(valuestring), "OEM Boot Event");
Patrick Venture0b02be92018-08-31 11:55:55 -0700174 break;
175 case 0x02:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700176 std::snprintf(p, sizeof(valuestring),
177 "Undetermined System Hardware Failure");
Patrick Venture0b02be92018-08-31 11:55:55 -0700178 break;
179 case 0x03:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700180 std::snprintf(
181 p, sizeof(valuestring),
182 "System Failure see error log for more details (0x%02x)",
183 pRec->event_data2);
Patrick Venture0b02be92018-08-31 11:55:55 -0700184 break;
185 case 0x04:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700186 std::snprintf(
Patrick Venture0b02be92018-08-31 11:55:55 -0700187 p, sizeof(valuestring),
188 "System Failure see PEF error log for more details (0x%02x)",
189 pRec->event_data2);
190 break;
191 default:
Patrick Ventureb51bf9c2018-09-10 15:53:14 -0700192 std::snprintf(
193 p, sizeof(valuestring),
194 "Internal warning, system_event offset unknown (0x%02x)",
195 pTable->offset);
Patrick Venture0b02be92018-08-31 11:55:55 -0700196 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 Ventured99148b2018-10-13 10:06:13 -0700249void reportSensorEventAssert(const sensorRES_t* pRec, int index)
Patrick Venture0b02be92018-08-31 11:55:55 -0700250{
251 lookup_t* pTable = &g_ipmidbuslookup[index];
252 (*pTable->func)(pRec, pTable, pTable->assertion);
Chris Austen0130d6e2015-10-15 22:32:36 -0500253}
Patrick Ventured99148b2018-10-13 10:06:13 -0700254void reportSensorEventDeassert(const sensorRES_t* pRec, int index)
Patrick Venture0b02be92018-08-31 11:55:55 -0700255{
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{
Patrick Venture0b02be92018-08-31 11:55:55 -0700262 int i = 0, rc = 0;
263 lookup_t* pTable = g_ipmidbuslookup;
Gunnar Millsd8249ee2018-04-12 16:33:53 -0500264
Patrick Venture0b02be92018-08-31 11:55:55 -0700265 do
266 {
267 if (((pTable + i)->sensor_type == sensor_type) &&
268 ((pTable + i)->offset == offset))
269 {
270 rc = 1;
271 *index = i;
272 break;
273 }
274 i++;
275 } while ((pTable + i)->sensor_type != 0xFF);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500276
Patrick Venture0b02be92018-08-31 11:55:55 -0700277 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500278}
279
Patrick Venture0b02be92018-08-31 11:55:55 -0700280bool shouldReport(uint8_t sensorType, int offset, int* index)
281{
Patrick Venture0b02be92018-08-31 11:55:55 -0700282 bool rc = false;
Chris Austen0a4e2472015-10-18 12:19:40 -0500283
Patrick Venture0b02be92018-08-31 11:55:55 -0700284 if (findindex(sensorType, offset, index))
285 {
286 rc = true;
287 }
288 if (rc == false)
289 {
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530290#ifdef __IPMI_DEBUG__
George Liu5e72ce92024-07-19 09:26:40 +0800291 lg2::debug("LOOKATME: Sensor should not be reported, "
292 "sensor type: {SENSORTYPE}, offset: {OFFSET}",
293 SENSORTYPE, lg2::hex, sensorType, "OFFSET", lg2::hex,
294 offset);
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530295#endif
Patrick Venture0b02be92018-08-31 11:55:55 -0700296 }
Chris Austen0a4e2472015-10-18 12:19:40 -0500297
Patrick Venture0b02be92018-08-31 11:55:55 -0700298 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500299}
300
Patrick Venture0b02be92018-08-31 11:55:55 -0700301int updateSensorRecordFromSSRAESC(const void* record)
302{
Patrick Ventured99148b2018-10-13 10:06:13 -0700303 auto pRec = static_cast<const sensorRES_t*>(record);
Patrick Venture0b02be92018-08-31 11:55:55 -0700304 uint8_t stype;
Patrick Venture4491a462018-10-13 13:00:42 -0700305 int index;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500306
Patrick Venture0b02be92018-08-31 11:55:55 -0700307 stype = find_type_for_sensor_number(pRec->sensor_number);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500308
Patrick Venture0b02be92018-08-31 11:55:55 -0700309 // 0xC3 types use the assertion7_0 for the value to be set
310 // so skip the reseach and call the correct event reporting
311 // function
312 if (stype == 0xC3)
313 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700314 shouldReport(stype, 0x00, &index);
315 reportSensorEventAssert(pRec, index);
316 }
317 else
318 {
319 // Scroll through each bit position . Determine
320 // if any bit is either asserted or Deasserted.
Patrick Venture4491a462018-10-13 13:00:42 -0700321 for (int i = 0; i < 8; i++)
Patrick Venture0b02be92018-08-31 11:55:55 -0700322 {
Patrick Venture0b02be92018-08-31 11:55:55 -0700323 if ((ISBITSET(pRec->assert_state7_0, i)) &&
324 (shouldReport(stype, i, &index)))
325 {
326 reportSensorEventAssert(pRec, index);
327 }
328 if ((ISBITSET(pRec->assert_state14_8, i)) &&
329 (shouldReport(stype, i + 8, &index)))
330 {
331 reportSensorEventAssert(pRec, index);
332 }
333 if ((ISBITSET(pRec->deassert_state7_0, i)) &&
334 (shouldReport(stype, i, &index)))
335 {
336 reportSensorEventDeassert(pRec, index);
337 }
338 if ((ISBITSET(pRec->deassert_state14_8, i)) &&
339 (shouldReport(stype, i + 8, &index)))
340 {
341 reportSensorEventDeassert(pRec, index);
342 }
343 }
344 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500345
Patrick Venture0b02be92018-08-31 11:55:55 -0700346 return 0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500347}