Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 6 | extern uint8_t find_sensor(uint8_t); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 7 | extern int set_sensor_dbus_state_v(uint8_t , const char *, char *); |
| 8 | |
| 9 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 10 | struct 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 Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 23 | #define ISBITSET(x,y) (((x)>>(y))&0x01) |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 24 | #define ASSERTINDEX 0 |
| 25 | #define DEASSERTINDEX 1 |
| 26 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 27 | // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value |
| 28 | struct lookup_t { |
| 29 | uint8_t sensor_type; |
| 30 | uint8_t offset; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 31 | int (*func)(const sensorRES_t *, const lookup_t *, const char *); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 32 | char method[16]; |
| 33 | char assertion[16]; |
| 34 | char deassertion[16]; |
| 35 | }; |
| 36 | |
| 37 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 38 | extern int updateDbusInterface(uint8_t , const char *, const char *) ; |
| 39 | extern int set_sensor_dbus_state(uint8_t ,const char *, const char *); |
| 40 | |
| 41 | |
| 42 | int 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 | |
| 47 | struct event_data_t { |
| 48 | uint8_t data; |
| 49 | char text[32]; |
| 50 | }; |
| 51 | |
| 52 | event_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 | |
| 83 | char *getfw02string(uint8_t b) { |
| 84 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 85 | event_data_t *p = g_fwprogress02h; |
| 86 | |
Chris Austen | 5a9f0b4 | 2015-10-21 20:32:19 -0500 | [diff] [blame] | 87 | while(p->data != 0xFF) { |
| 88 | if (p->data == b) { |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 89 | break; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 90 | } |
Chris Austen | 5a9f0b4 | 2015-10-21 20:32:19 -0500 | [diff] [blame] | 91 | p++; |
| 92 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 93 | |
Chris Austen | 5a9f0b4 | 2015-10-21 20:32:19 -0500 | [diff] [blame] | 94 | return p->text; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 95 | } |
| 96 | // The fw progress sensor contains some additional information that needs to be processed |
| 97 | // prior to calling the dbus code. |
| 98 | int set_sensor_dbus_state_fwprogress(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) { |
| 99 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 100 | char valuestring[64]; |
| 101 | char* p = valuestring; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 102 | |
| 103 | switch (pTable->offset) { |
| 104 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 105 | case 0x00 : snprintf(p, sizeof(valuestring), "POST Error, 0x%02x", pRec->event_data2); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 106 | break; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 107 | case 0x01 : snprintf(p, sizeof(valuestring), "FW Hang, 0x%02x", pRec->event_data2); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 108 | break; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 109 | case 0x02 : snprintf(p, sizeof(valuestring), "FW Progress, %s", getfw02string(pRec->event_data2)); |
| 110 | break; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 113 | return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, p); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 116 | // 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 |
| 118 | int 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 Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 127 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 128 | // This table lists only senors we care about telling dbus about. |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 129 | // Offset definition cab be found in section 42.2 of the IPMI 2.0 |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 130 | // spec. Add more if/when there are more items of interest. |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 131 | lookup_t g_ipmidbuslookup[] = { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 132 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 133 | {0x07, 0x00, set_sensor_dbus_state_simple, "setPresent", "False", "False"}, // OCC Inactive 0 |
Chris Austen | f3644f1 | 2015-10-31 12:46:39 -0500 | [diff] [blame] | 134 | {0x07, 0x01, set_sensor_dbus_state_simple, "setPresent", "True", "True"}, // OCC Active 1 |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 135 | {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, |
Chris Austen | f3644f1 | 2015-10-31 12:46:39 -0500 | [diff] [blame] | 136 | {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", ""}, |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 137 | {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, |
Chris Austen | f3644f1 | 2015-10-31 12:46:39 -0500 | [diff] [blame] | 138 | {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", ""}, |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 139 | {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 Austen | f3644f1 | 2015-10-31 12:46:39 -0500 | [diff] [blame] | 142 | {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", ""}, |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 143 | {0xc3, 0x00, set_sensor_dbus_state_osboot, "setValue", "" ,""}, |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 144 | |
| 145 | {0xFF, 0xFF, NULL, "", "", ""} |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 146 | }; |
| 147 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 148 | |
| 149 | |
| 150 | void reportSensorEventAssert(sensorRES_t *pRec, int index) { |
| 151 | lookup_t *pTable = &g_ipmidbuslookup[index]; |
| 152 | (*pTable->func)(pRec, pTable, pTable->assertion); |
| 153 | } |
| 154 | void reportSensorEventDeassert(sensorRES_t *pRec, int index) { |
| 155 | lookup_t *pTable = &g_ipmidbuslookup[index]; |
| 156 | (*pTable->func)(pRec, pTable, pTable->deassertion); |
| 157 | } |
| 158 | |
| 159 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 160 | int findindex(const uint8_t sensor_type, int offset, int *index) { |
| 161 | |
| 162 | int i=0, rc=0; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 163 | lookup_t *pTable = g_ipmidbuslookup; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 164 | |
| 165 | do { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 166 | if ( ((pTable+i)->sensor_type == sensor_type) && |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 167 | ((pTable+i)->offset == offset) ) { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 168 | rc = 1; |
| 169 | *index = i; |
| 170 | break; |
| 171 | } |
| 172 | i++; |
| 173 | } while ((pTable+i)->sensor_type != 0xFF); |
| 174 | |
| 175 | return rc; |
| 176 | } |
| 177 | |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 178 | void debug_print_ok_to_dont_care(uint8_t stype, int offset) |
| 179 | { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 180 | printf("LOOKATME: Sensor should not be reported: Type 0x%02x, Offset 0x%02x\n", |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 181 | stype, offset); |
| 182 | } |
| 183 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 184 | bool shouldReport(uint8_t sensorType, int offset, int *index) { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 185 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 186 | bool rc = false; |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 187 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 188 | if (findindex(sensorType, offset, index)) { rc = true; } |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 189 | |
Chris Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 190 | if (rc==false) { debug_print_ok_to_dont_care(sensorType, offset); } |
| 191 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 192 | return rc; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | |
| 196 | int updateSensorRecordFromSSRAESC(const void *record) { |
| 197 | |
| 198 | sensorRES_t *pRec = (sensorRES_t *) record; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 199 | uint8_t stype; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 200 | int index, i=0; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 201 | stype = find_sensor(pRec->sensor_number); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 202 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 203 | |
| 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 Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 236 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 237 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 240 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 241 | return 0; |
| 242 | } |