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 | |
| 6 | extern unsigned char findSensor(char); |
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 | |
| 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 Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 95 | return (p+i)->text; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 96 | } |
| 97 | // The fw progress sensor contains some additional information that needs to be processed |
| 98 | // prior to calling the dbus code. |
| 99 | int 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 Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 110 | case 0x02 : sprintf(valuestring, "FW Progress, %s", getfw02string(pRec->event_data2)); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, pStr); |
| 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. |
| 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 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 | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 133 | {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 Austen | 0a4e247 | 2015-10-18 12:19:40 -0500 | [diff] [blame] | 140 | {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 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 | { |
| 180 | printf("Sensor should not be reported: Type 0x%02x, Offset 0x%02x\n", |
| 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; |
| 199 | unsigned char stype; |
| 200 | int index, i=0; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 201 | 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 Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 206 | if ((ISBITSET(pRec->assert_state7_0,i)) && |
| 207 | (shouldReport(stype, i, &index))) |
| 208 | { |
| 209 | reportSensorEventAssert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 210 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 211 | if ((ISBITSET(pRec->assert_state14_8,i+8)) && |
| 212 | (shouldReport(stype, i+8, &index))) |
| 213 | { |
| 214 | reportSensorEventAssert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 215 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 216 | if ((ISBITSET(pRec->deassert_state7_0,i)) && |
| 217 | (shouldReport(stype, i, &index))) |
| 218 | { |
| 219 | reportSensorEventDeassert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 220 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame] | 221 | if ((ISBITSET(pRec->deassert_state14_8,i+8)) && |
| 222 | (shouldReport(stype, i+8, &index))) |
| 223 | { |
| 224 | reportSensorEventDeassert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |