blob: 513e4852b4795b2d904a5a4c1005416edffdd401 [file] [log] [blame]
Chris Austen8a45e7c2015-10-15 00:31:46 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
4
5
Chris Austen0012e9b2015-10-22 01:37:46 -05006extern uint8_t find_sensor(uint8_t);
Chris Austen0130d6e2015-10-15 22:32:36 -05007extern int set_sensor_dbus_state_v(uint8_t , const char *, char *);
8
9
Chris Austen8a45e7c2015-10-15 00:31:46 -050010struct sensorRES_t {
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));
22
Chris Austen0130d6e2015-10-15 22:32:36 -050023#define ISBITSET(x,y) (((x)>>(y))&0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050024#define ASSERTINDEX 0
25#define DEASSERTINDEX 1
26
Chris Austen8a45e7c2015-10-15 00:31:46 -050027// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value
28struct lookup_t {
29 uint8_t sensor_type;
30 uint8_t offset;
Chris Austen0130d6e2015-10-15 22:32:36 -050031 int (*func)(const sensorRES_t *, const lookup_t *, const char *);
Chris Austen8a45e7c2015-10-15 00:31:46 -050032 char method[16];
33 char assertion[16];
34 char deassertion[16];
35};
36
37
Chris Austen0130d6e2015-10-15 22:32:36 -050038extern int updateDbusInterface(uint8_t , const char *, const char *) ;
39extern int set_sensor_dbus_state(uint8_t ,const char *, const char *);
40
41
42int set_sensor_dbus_state_simple(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
43
44 return set_sensor_dbus_state(pRec->sensor_number, pTable->method, value);
45}
46
47struct event_data_t {
48 uint8_t data;
49 char text[32];
50};
51
52event_data_t g_fwprogress02h[] = {
53 {0x00, "Unspecified"},
54 {0x01, "Memory Init"},
55 {0x02, "HD Init"},
56 {0x03, "Secondary Proc Init"},
57 {0x04, "User Authentication"},
58 {0x05, "User init system setup"},
59 {0x06, "USB configuration"},
60 {0x07, "PCI configuration"},
61 {0x08, "Option ROM Init"},
62 {0x09, "Video Init"},
63 {0x0A, "Cache Init"},
64 {0x0B, "SM Bus init"},
65 {0x0C, "Keyboard Init"},
66 {0x0D, "Embedded ctrl init"},
67 {0x0E, "Docking station attachment"},
68 {0x0F, "Enable docking station"},
69 {0x10, "Docking station ejection"},
70 {0x11, "Disabling docking station"},
71 {0x12, "Calling OS Wakeup"},
72 {0x13, "Starting OS"},
73 {0x14, "Baseboard Init"},
74 {0x15, ""},
75 {0x16, "Floppy Init"},
76 {0x17, "Keyboard Test"},
77 {0x18, "Pointing Device Test"},
78 {0x19, "Primary Proc Init"},
79 {0xFF, "Unknown"}
80};
81
82
83char *getfw02string(uint8_t b) {
84
Chris Austen0130d6e2015-10-15 22:32:36 -050085 event_data_t *p = g_fwprogress02h;
86
Chris Austen5a9f0b42015-10-21 20:32:19 -050087 while(p->data != 0xFF) {
88 if (p->data == b) {
Chris Austen0130d6e2015-10-15 22:32:36 -050089 break;
Chris Austen0012e9b2015-10-22 01:37:46 -050090 }
Chris Austen5a9f0b42015-10-21 20:32:19 -050091 p++;
92 }
Chris Austen0130d6e2015-10-15 22:32:36 -050093
Chris Austen5a9f0b42015-10-21 20:32:19 -050094 return p->text;
Chris Austen0130d6e2015-10-15 22:32:36 -050095}
96// The fw progress sensor contains some additional information that needs to be processed
97// prior to calling the dbus code.
98int set_sensor_dbus_state_fwprogress(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
99
Chris Austen0012e9b2015-10-22 01:37:46 -0500100 char valuestring[64];
101 char* p = valuestring;
Chris Austen0130d6e2015-10-15 22:32:36 -0500102
103 switch (pTable->offset) {
104
Chris Austen0012e9b2015-10-22 01:37:46 -0500105 case 0x00 : snprintf(p, sizeof(valuestring), "POST Error, 0x%02x", pRec->event_data2);
Chris Austen0130d6e2015-10-15 22:32:36 -0500106 break;
Chris Austen0012e9b2015-10-22 01:37:46 -0500107 case 0x01 : snprintf(p, sizeof(valuestring), "FW Hang, 0x%02x", pRec->event_data2);
Chris Austen0130d6e2015-10-15 22:32:36 -0500108 break;
Chris Austen0012e9b2015-10-22 01:37:46 -0500109 case 0x02 : snprintf(p, sizeof(valuestring), "FW Progress, %s", getfw02string(pRec->event_data2));
110 break;
Chris Austen0130d6e2015-10-15 22:32:36 -0500111 }
112
Chris Austen0012e9b2015-10-22 01:37:46 -0500113 return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, p);
Chris Austen0130d6e2015-10-15 22:32:36 -0500114}
115
Chris Austen0a4e2472015-10-18 12:19:40 -0500116// Handling this special OEM sensor by coping what is in byte 4. I also think that is odd
117// considering byte 3 is for sensor reading. This seems like a misuse of the IPMI spec
118int set_sensor_dbus_state_osboot(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
119 char valuestring[32];
120 char* pStr = valuestring;
121
122 sprintf(valuestring, "%d", pRec->assert_state7_0);
123
124 return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, pStr);
125}
126
Chris Austen0130d6e2015-10-15 22:32:36 -0500127
Chris Austen8a45e7c2015-10-15 00:31:46 -0500128// This table lists only senors we care about telling dbus about.
Chris Austen0012e9b2015-10-22 01:37:46 -0500129// Offset definition cab be found in section 42.2 of the IPMI 2.0
Chris Austen8a45e7c2015-10-15 00:31:46 -0500130// spec. Add more if/when there are more items of interest.
Chris Austen0130d6e2015-10-15 22:32:36 -0500131lookup_t g_ipmidbuslookup[] = {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500132
Chris Austen0012e9b2015-10-22 01:37:46 -0500133 {0x07, 0x00, set_sensor_dbus_state_simple, "setPresent", "False", "False"}, // OCC Inactive 0
Chris Austenf3644f12015-10-31 12:46:39 -0500134 {0x07, 0x01, set_sensor_dbus_state_simple, "setPresent", "True", "True"}, // OCC Active 1
Chris Austen0130d6e2015-10-15 22:32:36 -0500135 {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
Chris Austenf3644f12015-10-31 12:46:39 -0500136 {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", ""},
Chris Austen0130d6e2015-10-15 22:32:36 -0500137 {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
Chris Austenf3644f12015-10-31 12:46:39 -0500138 {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", ""},
Chris Austen0130d6e2015-10-15 22:32:36 -0500139 {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
140 {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
141 {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
Chris Austenf3644f12015-10-31 12:46:39 -0500142 {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", ""},
Chris Austen0a4e2472015-10-18 12:19:40 -0500143 {0xc3, 0x00, set_sensor_dbus_state_osboot, "setValue", "" ,""},
Chris Austen0130d6e2015-10-15 22:32:36 -0500144
145 {0xFF, 0xFF, NULL, "", "", ""}
Chris Austen8a45e7c2015-10-15 00:31:46 -0500146};
147
Chris Austen0130d6e2015-10-15 22:32:36 -0500148
149
150void reportSensorEventAssert(sensorRES_t *pRec, int index) {
151 lookup_t *pTable = &g_ipmidbuslookup[index];
152 (*pTable->func)(pRec, pTable, pTable->assertion);
153}
154void reportSensorEventDeassert(sensorRES_t *pRec, int index) {
155 lookup_t *pTable = &g_ipmidbuslookup[index];
156 (*pTable->func)(pRec, pTable, pTable->deassertion);
157}
158
159
Chris Austen8a45e7c2015-10-15 00:31:46 -0500160int findindex(const uint8_t sensor_type, int offset, int *index) {
161
162 int i=0, rc=0;
Chris Austen0130d6e2015-10-15 22:32:36 -0500163 lookup_t *pTable = g_ipmidbuslookup;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500164
165 do {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500166 if ( ((pTable+i)->sensor_type == sensor_type) &&
Chris Austen0130d6e2015-10-15 22:32:36 -0500167 ((pTable+i)->offset == offset) ) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500168 rc = 1;
169 *index = i;
170 break;
171 }
172 i++;
173 } while ((pTable+i)->sensor_type != 0xFF);
174
175 return rc;
176}
177
Chris Austen0a4e2472015-10-18 12:19:40 -0500178void debug_print_ok_to_dont_care(uint8_t stype, int offset)
179{
Chris Austen0012e9b2015-10-22 01:37:46 -0500180 printf("LOOKATME: Sensor should not be reported: Type 0x%02x, Offset 0x%02x\n",
Chris Austen0a4e2472015-10-18 12:19:40 -0500181 stype, offset);
182}
183
Chris Austen0130d6e2015-10-15 22:32:36 -0500184bool shouldReport(uint8_t sensorType, int offset, int *index) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500185
Chris Austen0130d6e2015-10-15 22:32:36 -0500186 bool rc = false;
Chris Austen0a4e2472015-10-18 12:19:40 -0500187
Chris Austen0130d6e2015-10-15 22:32:36 -0500188 if (findindex(sensorType, offset, index)) { rc = true; }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500189
Chris Austen0a4e2472015-10-18 12:19:40 -0500190 if (rc==false) { debug_print_ok_to_dont_care(sensorType, offset); }
191
Chris Austen0130d6e2015-10-15 22:32:36 -0500192 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500193}
194
195
196int updateSensorRecordFromSSRAESC(const void *record) {
197
198 sensorRES_t *pRec = (sensorRES_t *) record;
Chris Austen0012e9b2015-10-22 01:37:46 -0500199 uint8_t stype;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500200 int index, i=0;
Chris Austen0012e9b2015-10-22 01:37:46 -0500201 stype = find_sensor(pRec->sensor_number);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500202
Chris Austen0012e9b2015-10-22 01:37:46 -0500203
204 // 0xC3 types use the assertion7_0 for the value to be set
205 // so skip the reseach and call the correct event reporting
206 // function
207 if (stype == 0xC3) {
208
209 shouldReport(stype, 0x00, &index);
210 reportSensorEventAssert(pRec, index);
211
212 } else {
213 // Scroll through each bit position . Determine
214 // if any bit is either asserted or Deasserted.
215 for(i=0;i<8;i++) {
216 if ((ISBITSET(pRec->assert_state7_0,i)) &&
217 (shouldReport(stype, i, &index)))
218 {
219 reportSensorEventAssert(pRec, index);
220 }
221 if ((ISBITSET(pRec->assert_state14_8,i)) &&
222 (shouldReport(stype, i+8, &index)))
223 {
224 reportSensorEventAssert(pRec, index);
225 }
226 if ((ISBITSET(pRec->deassert_state7_0,i)) &&
227 (shouldReport(stype, i, &index)))
228 {
229 reportSensorEventDeassert(pRec, index);
230 }
231 if ((ISBITSET(pRec->deassert_state14_8,i)) &&
232 (shouldReport(stype, i+8, &index)))
233 {
234 reportSensorEventDeassert(pRec, index);
235 }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500236 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500237
Chris Austen8a45e7c2015-10-15 00:31:46 -0500238 }
239
Chris Austen0012e9b2015-10-22 01:37:46 -0500240
Chris Austen8a45e7c2015-10-15 00:31:46 -0500241 return 0;
242}