blob: f60db1840f5e4f21456d2e4be2dff3f7316b3088 [file] [log] [blame]
Chris Austen8a45e7c2015-10-15 00:31:46 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
4
5
6extern unsigned char findSensor(char);
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
85 int i = 0;
86 event_data_t *p = g_fwprogress02h;
87
88 do {
89
90 if ((p+i)->data == b)
91 break;
92 i++;
93 } while ((p+i)->data != 0xFF);
94
Chris Austen0a4e2472015-10-18 12:19:40 -050095 return (p+i)->text;
Chris Austen0130d6e2015-10-15 22:32:36 -050096}
97// The fw progress sensor contains some additional information that needs to be processed
98// prior to calling the dbus code.
99int set_sensor_dbus_state_fwprogress(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) {
100
101 char valuestring[32];
102 char* pStr = valuestring;
103
104 switch (pTable->offset) {
105
106 case 0x00 : sprintf(valuestring, "POST Error, 0x%02x", pRec->event_data2);
107 break;
108 case 0x01 : sprintf(valuestring, "FW Hang, 0x%02x", pRec->event_data2);
109 break;
Chris Austen0a4e2472015-10-18 12:19:40 -0500110 case 0x02 : sprintf(valuestring, "FW Progress, %s", getfw02string(pRec->event_data2));
Chris Austen0130d6e2015-10-15 22:32:36 -0500111 }
112
113 return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, pStr);
114}
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.
129// Offset definition cab be found in section 42.2 of the IPMI 2.0
130// 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 Austen0130d6e2015-10-15 22:32:36 -0500133 {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
134 {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"},
135 {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
136 {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"},
137 {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
138 {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
139 {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
Chris Austen0a4e2472015-10-18 12:19:40 -0500140 {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"},
141 {0x07, 0x00, set_sensor_dbus_state_simple, "setPresent", "False", "False"}, // OCC Inactive 0
142 {0x07, 0x01, set_sensor_dbus_state_simple, "setPresent", "True", "True"}, // OCC Active 1
143 {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{
180 printf("Sensor should not be reported: Type 0x%02x, Offset 0x%02x\n",
181 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;
199 unsigned char stype;
200 int index, i=0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500201 stype = findSensor(pRec->sensor_number);
202
203 // Scroll through each bit position . Determine
204 // if any bit is either asserted or Deasserted.
205 for(i=0;i<8;i++) {
Chris Austen0130d6e2015-10-15 22:32:36 -0500206 if ((ISBITSET(pRec->assert_state7_0,i)) &&
207 (shouldReport(stype, i, &index)))
208 {
209 reportSensorEventAssert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500210 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500211 if ((ISBITSET(pRec->assert_state14_8,i+8)) &&
212 (shouldReport(stype, i+8, &index)))
213 {
214 reportSensorEventAssert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500215 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500216 if ((ISBITSET(pRec->deassert_state7_0,i)) &&
217 (shouldReport(stype, i, &index)))
218 {
219 reportSensorEventDeassert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500220 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500221 if ((ISBITSET(pRec->deassert_state14_8,i+8)) &&
222 (shouldReport(stype, i+8, &index)))
223 {
224 reportSensorEventDeassert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500225 }
226 }
227
228 return 0;
229}