blob: b6927ac947fd6dd8fb6998d56a784815fba5d0c0 [file] [log] [blame]
Chris Austen8a45e7c2015-10-15 00:31:46 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
Chris Austend7cf0e42015-11-07 14:27:12 -06004#include <malloc.h>
Chris Austen10ccc0f2015-12-10 18:27:04 -06005#include <ipmid.H>
6#include "sensorhandler.h"
Chris Austen8a45e7c2015-10-15 00:31:46 -05007
Chris Austen0012e9b2015-10-22 01:37:46 -05008extern uint8_t find_sensor(uint8_t);
Chris Austen0130d6e2015-10-15 22:32:36 -05009
10
Chris Austen8a45e7c2015-10-15 00:31:46 -050011struct sensorRES_t {
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));
23
Chris Austen0130d6e2015-10-15 22:32:36 -050024#define ISBITSET(x,y) (((x)>>(y))&0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050025#define ASSERTINDEX 0
26#define DEASSERTINDEX 1
27
Chris Austen8a45e7c2015-10-15 00:31:46 -050028// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value
29struct lookup_t {
30 uint8_t sensor_type;
31 uint8_t offset;
Chris Austen0130d6e2015-10-15 22:32:36 -050032 int (*func)(const sensorRES_t *, const lookup_t *, const char *);
Chris Austen10ccc0f2015-12-10 18:27:04 -060033 char member[16];
Chris Austend7cf0e42015-11-07 14:27:12 -060034 char assertion[64];
35 char deassertion[64];
Chris Austen8a45e7c2015-10-15 00:31:46 -050036};
37
Chris Austen10ccc0f2015-12-10 18:27:04 -060038extern int updateDbusInterface(uint8_t , const char *, const char *);
39extern int find_openbmc_path(const char *, const uint8_t , dbus_interface_t *) ;
Chris Austen0130d6e2015-10-15 22:32:36 -050040
41
42int set_sensor_dbus_state_simple(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
43
Chris Austen10ccc0f2015-12-10 18:27:04 -060044 return set_sensor_dbus_state_s(pRec->sensor_number,
45 pTable->member,
46 value);
Chris Austen0130d6e2015-10-15 22:32:36 -050047}
48
49struct event_data_t {
50 uint8_t data;
Chris Austend7cf0e42015-11-07 14:27:12 -060051 char text[64];
Chris Austen0130d6e2015-10-15 22:32:36 -050052};
53
54event_data_t g_fwprogress02h[] = {
55 {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"}
82};
83
Chris Austend7cf0e42015-11-07 14:27:12 -060084event_data_t g_fwprogress00h[] = {
85 {0x00, "Unspecified."},
86 {0x01, "No system memory detected"},
87 {0x02, "No usable system memory"},
88 {0x03, "Unrecoverable hard-disk/ATAPI/IDE"},
89 {0x04, "Unrecoverable system-board"},
90 {0x05, "Unrecoverable diskette"},
91 {0x06, "Unrecoverable hard-disk controller"},
92 {0x07, "Unrecoverable PS/2 or USB keyboard"},
93 {0x08, "Removable boot media not found"},
94 {0x09, "Unrecoverable video controller"},
95 {0x0A, "No video device detected"},
96 {0x0B, "Firmware ROM corruption detected"},
97 {0x0C, "CPU voltage mismatch"},
98 {0x0D, "CPU speed matching"},
99 {0xFF, "unknown"},
100};
Chris Austen0130d6e2015-10-15 22:32:36 -0500101
Chris Austen0130d6e2015-10-15 22:32:36 -0500102
Chris Austend7cf0e42015-11-07 14:27:12 -0600103char *event_data_lookup(event_data_t *p, uint8_t b) {
Chris Austen0130d6e2015-10-15 22:32:36 -0500104
Chris Austen5a9f0b42015-10-21 20:32:19 -0500105 while(p->data != 0xFF) {
106 if (p->data == b) {
Chris Austen0130d6e2015-10-15 22:32:36 -0500107 break;
Chris Austen0012e9b2015-10-22 01:37:46 -0500108 }
Chris Austen5a9f0b42015-10-21 20:32:19 -0500109 p++;
110 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500111
Chris Austen5a9f0b42015-10-21 20:32:19 -0500112 return p->text;
Chris Austen0130d6e2015-10-15 22:32:36 -0500113}
Chris Austend7cf0e42015-11-07 14:27:12 -0600114
115
116
Chris Austen0130d6e2015-10-15 22:32:36 -0500117// The fw progress sensor contains some additional information that needs to be processed
118// prior to calling the dbus code.
119int set_sensor_dbus_state_fwprogress(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
120
Chris Austend7cf0e42015-11-07 14:27:12 -0600121 char valuestring[128];
Chris Austen0012e9b2015-10-22 01:37:46 -0500122 char* p = valuestring;
Chris Austen0130d6e2015-10-15 22:32:36 -0500123
124 switch (pTable->offset) {
125
Chris Austend7cf0e42015-11-07 14:27:12 -0600126 case 0x00 : snprintf(p, sizeof(valuestring), "POST Error, %s", event_data_lookup(g_fwprogress00h, pRec->event_data2));
Chris Austen0130d6e2015-10-15 22:32:36 -0500127 break;
Chris Austend7cf0e42015-11-07 14:27:12 -0600128 case 0x01 : /* Using g_fwprogress02h for 0x01 because thats what the ipmi spec says to do */
129 snprintf(p, sizeof(valuestring), "FW Hang, %s", event_data_lookup(g_fwprogress02h, pRec->event_data2));
Chris Austen0130d6e2015-10-15 22:32:36 -0500130 break;
Chris Austend7cf0e42015-11-07 14:27:12 -0600131 case 0x02 : snprintf(p, sizeof(valuestring), "FW Progress, %s", event_data_lookup(g_fwprogress02h, pRec->event_data2));
Chris Austen0012e9b2015-10-22 01:37:46 -0500132 break;
Chris Austen800ba712015-12-03 15:31:00 -0600133 default : snprintf(p, sizeof(valuestring), "Internal warning, fw_progres offset unknown (0x%02x)", pTable->offset);
134 break;
Chris Austen0130d6e2015-10-15 22:32:36 -0500135 }
136
Chris Austen10ccc0f2015-12-10 18:27:04 -0600137 return set_sensor_dbus_state_s(pRec->sensor_number,
138 pTable->member,
139 p);
Chris Austen0130d6e2015-10-15 22:32:36 -0500140}
141
Chris Austen0a4e2472015-10-18 12:19:40 -0500142// Handling this special OEM sensor by coping what is in byte 4. I also think that is odd
143// considering byte 3 is for sensor reading. This seems like a misuse of the IPMI spec
Chris Austend7cf0e42015-11-07 14:27:12 -0600144int set_sensor_dbus_state_osbootcount(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
Chris Austen10ccc0f2015-12-10 18:27:04 -0600145 return set_sensor_dbus_state_y(pRec->sensor_number,
146 "setValue",
147 pRec->assert_state7_0);
Chris Austen0a4e2472015-10-18 12:19:40 -0500148}
149
Chris Austen800ba712015-12-03 15:31:00 -0600150int set_sensor_dbus_state_system_event(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
151 char valuestring[128];
152 char* p = valuestring;
153
154 switch (pTable->offset) {
155
156 case 0x00 : snprintf(p, sizeof(valuestring), "System Reconfigured");
157 break;
158 case 0x01 : snprintf(p, sizeof(valuestring), "OEM Boot Event");
159 break;
160 case 0x02 : snprintf(p, sizeof(valuestring), "Undetermine System Hardware Failure");
161 break;
162 case 0x03 : snprintf(p, sizeof(valuestring), "System Failure see error log for more details (0x%02x)", pRec->event_data2);
163 break;
164 case 0x04 : snprintf(p, sizeof(valuestring), "System Failure see PEF error log for more details (0x%02x)", pRec->event_data2);
165 break;
166 default : snprintf(p, sizeof(valuestring), "Internal warning, system_event offset unknown (0x%02x)", pTable->offset);
167 break;
168 }
169
Chris Austen10ccc0f2015-12-10 18:27:04 -0600170 return set_sensor_dbus_state_s(pRec->sensor_number,
171 pTable->member,
172 p);
Chris Austen800ba712015-12-03 15:31:00 -0600173}
Chris Austen0130d6e2015-10-15 22:32:36 -0500174
Chris Austend7cf0e42015-11-07 14:27:12 -0600175
Chris Austen8a45e7c2015-10-15 00:31:46 -0500176// This table lists only senors we care about telling dbus about.
Chris Austen0012e9b2015-10-22 01:37:46 -0500177// Offset definition cab be found in section 42.2 of the IPMI 2.0
Chris Austen8a45e7c2015-10-15 00:31:46 -0500178// spec. Add more if/when there are more items of interest.
Chris Austen0130d6e2015-10-15 22:32:36 -0500179lookup_t g_ipmidbuslookup[] = {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500180
Chris Austend7cf0e42015-11-07 14:27:12 -0600181 {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""}, // OCC Inactive 0
182 {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""}, // OCC Active 1
Chris Austen0130d6e2015-10-15 22:32:36 -0500183 {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
Chris Austen800ba712015-12-03 15:31:00 -0600184 {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"},
Chris Austen0130d6e2015-10-15 22:32:36 -0500185 {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
Chris Austen800ba712015-12-03 15:31:00 -0600186 {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"},
Chris Austen0130d6e2015-10-15 22:32:36 -0500187 {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
188 {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
189 {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
Chris Austen800ba712015-12-03 15:31:00 -0600190 {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"},
Chris Austend7cf0e42015-11-07 14:27:12 -0600191 {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "" ,""},
192 {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue", "Boot completed (00)", ""},
193 {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue", "Boot completed (01)", ""},
194 {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed", ""},
195 {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue", "Diagnostic boot completed", ""},
196 {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue", "CD-ROM boot completed", ""},
197 {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed", ""},
198 {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue", "Boot completed (06)", ""},
Chris Austen800ba712015-12-03 15:31:00 -0600199 {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""},
200 {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""},
201 {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""},
202 {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""},
203 {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""},
Chris Austen0130d6e2015-10-15 22:32:36 -0500204
205 {0xFF, 0xFF, NULL, "", "", ""}
Chris Austen8a45e7c2015-10-15 00:31:46 -0500206};
207
Chris Austen0130d6e2015-10-15 22:32:36 -0500208
Chris Austen0130d6e2015-10-15 22:32:36 -0500209void reportSensorEventAssert(sensorRES_t *pRec, int index) {
210 lookup_t *pTable = &g_ipmidbuslookup[index];
211 (*pTable->func)(pRec, pTable, pTable->assertion);
212}
213void reportSensorEventDeassert(sensorRES_t *pRec, int index) {
214 lookup_t *pTable = &g_ipmidbuslookup[index];
215 (*pTable->func)(pRec, pTable, pTable->deassertion);
216}
217
218
Chris Austen8a45e7c2015-10-15 00:31:46 -0500219int findindex(const uint8_t sensor_type, int offset, int *index) {
220
221 int i=0, rc=0;
Chris Austen0130d6e2015-10-15 22:32:36 -0500222 lookup_t *pTable = g_ipmidbuslookup;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500223
224 do {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500225 if ( ((pTable+i)->sensor_type == sensor_type) &&
Chris Austen0130d6e2015-10-15 22:32:36 -0500226 ((pTable+i)->offset == offset) ) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500227 rc = 1;
228 *index = i;
229 break;
230 }
231 i++;
232 } while ((pTable+i)->sensor_type != 0xFF);
233
234 return rc;
235}
236
Chris Austen0a4e2472015-10-18 12:19:40 -0500237void debug_print_ok_to_dont_care(uint8_t stype, int offset)
238{
Chris Austen0012e9b2015-10-22 01:37:46 -0500239 printf("LOOKATME: Sensor should not be reported: Type 0x%02x, Offset 0x%02x\n",
Chris Austen0a4e2472015-10-18 12:19:40 -0500240 stype, offset);
241}
242
Chris Austen0130d6e2015-10-15 22:32:36 -0500243bool shouldReport(uint8_t sensorType, int offset, int *index) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500244
Chris Austen0130d6e2015-10-15 22:32:36 -0500245 bool rc = false;
Chris Austen0a4e2472015-10-18 12:19:40 -0500246
Chris Austen0130d6e2015-10-15 22:32:36 -0500247 if (findindex(sensorType, offset, index)) { rc = true; }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500248
Chris Austen0a4e2472015-10-18 12:19:40 -0500249 if (rc==false) { debug_print_ok_to_dont_care(sensorType, offset); }
250
Chris Austen0130d6e2015-10-15 22:32:36 -0500251 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500252}
253
254
255int updateSensorRecordFromSSRAESC(const void *record) {
256
257 sensorRES_t *pRec = (sensorRES_t *) record;
Chris Austen0012e9b2015-10-22 01:37:46 -0500258 uint8_t stype;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500259 int index, i=0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500260
Chris Austend7cf0e42015-11-07 14:27:12 -0600261 stype = find_sensor(pRec->sensor_number);
Chris Austen0012e9b2015-10-22 01:37:46 -0500262
263 // 0xC3 types use the assertion7_0 for the value to be set
264 // so skip the reseach and call the correct event reporting
265 // function
266 if (stype == 0xC3) {
267
268 shouldReport(stype, 0x00, &index);
269 reportSensorEventAssert(pRec, index);
270
271 } else {
272 // Scroll through each bit position . Determine
273 // if any bit is either asserted or Deasserted.
274 for(i=0;i<8;i++) {
Chris Austend7cf0e42015-11-07 14:27:12 -0600275
Chris Austen0012e9b2015-10-22 01:37:46 -0500276 if ((ISBITSET(pRec->assert_state7_0,i)) &&
277 (shouldReport(stype, i, &index)))
278 {
279 reportSensorEventAssert(pRec, index);
280 }
281 if ((ISBITSET(pRec->assert_state14_8,i)) &&
282 (shouldReport(stype, i+8, &index)))
283 {
284 reportSensorEventAssert(pRec, index);
285 }
286 if ((ISBITSET(pRec->deassert_state7_0,i)) &&
287 (shouldReport(stype, i, &index)))
288 {
289 reportSensorEventDeassert(pRec, index);
290 }
291 if ((ISBITSET(pRec->deassert_state14_8,i)) &&
292 (shouldReport(stype, i+8, &index)))
293 {
294 reportSensorEventDeassert(pRec, index);
295 }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500296 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500297
Chris Austen8a45e7c2015-10-15 00:31:46 -0500298 }
299
Chris Austen0012e9b2015-10-22 01:37:46 -0500300
Chris Austen8a45e7c2015-10-15 00:31:46 -0500301 return 0;
302}