1*0b02be92SPatrick Venture #include <malloc.h> 2*0b02be92SPatrick Venture #include <stdint.h> 398a23840SMatthew Barth #include <stdio.h> 498a23840SMatthew Barth #include <string.h> 5*0b02be92SPatrick Venture 698a23840SMatthew Barth #include "sensorhandler.h" 798a23840SMatthew Barth 8391f3303SEmily Shaffer extern uint8_t find_type_for_sensor_number(uint8_t); 998a23840SMatthew Barth 10*0b02be92SPatrick Venture struct sensorRES_t 11*0b02be92SPatrick Venture { 1298a23840SMatthew Barth uint8_t sensor_number; 1398a23840SMatthew Barth uint8_t operation; 1498a23840SMatthew Barth uint8_t sensor_reading; 1598a23840SMatthew Barth uint8_t assert_state7_0; 1698a23840SMatthew Barth uint8_t assert_state14_8; 1798a23840SMatthew Barth uint8_t deassert_state7_0; 1898a23840SMatthew Barth uint8_t deassert_state14_8; 1998a23840SMatthew Barth uint8_t event_data1; 2098a23840SMatthew Barth uint8_t event_data2; 2198a23840SMatthew Barth uint8_t event_data3; 2298a23840SMatthew Barth } __attribute__((packed)); 2398a23840SMatthew Barth 2498a23840SMatthew Barth #define ISBITSET(x, y) (((x) >> (y)) & 0x01) 2598a23840SMatthew Barth #define ASSERTINDEX 0 2698a23840SMatthew Barth #define DEASSERTINDEX 1 2798a23840SMatthew Barth 28*0b02be92SPatrick Venture // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert 29*0b02be92SPatrick Venture // value 30*0b02be92SPatrick Venture struct lookup_t 31*0b02be92SPatrick Venture { 3298a23840SMatthew Barth uint8_t sensor_type; 3398a23840SMatthew Barth uint8_t offset; 3498a23840SMatthew Barth int (*func)(const sensorRES_t*, const lookup_t*, const char*); 3598a23840SMatthew Barth char member[16]; 3698a23840SMatthew Barth char assertion[64]; 3798a23840SMatthew Barth char deassertion[64]; 3898a23840SMatthew Barth }; 3998a23840SMatthew Barth 4098a23840SMatthew Barth extern int updateDbusInterface(uint8_t, const char*, const char*); 4198a23840SMatthew Barth 42*0b02be92SPatrick Venture int set_sensor_dbus_state_simple(const sensorRES_t* pRec, 43*0b02be92SPatrick Venture const lookup_t* pTable, const char* value) 44*0b02be92SPatrick Venture { 4598a23840SMatthew Barth 46*0b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value); 4798a23840SMatthew Barth } 4898a23840SMatthew Barth 49*0b02be92SPatrick Venture struct event_data_t 50*0b02be92SPatrick Venture { 5198a23840SMatthew Barth uint8_t data; 5298a23840SMatthew Barth char text[64]; 5398a23840SMatthew Barth }; 5498a23840SMatthew Barth 55*0b02be92SPatrick Venture event_data_t g_fwprogress02h[] = {{0x00, "Unspecified"}, 5698a23840SMatthew Barth {0x01, "Memory Init"}, 5798a23840SMatthew Barth {0x02, "HD Init"}, 5898a23840SMatthew Barth {0x03, "Secondary Proc Init"}, 5998a23840SMatthew Barth {0x04, "User Authentication"}, 6098a23840SMatthew Barth {0x05, "User init system setup"}, 6198a23840SMatthew Barth {0x06, "USB configuration"}, 6298a23840SMatthew Barth {0x07, "PCI configuration"}, 6398a23840SMatthew Barth {0x08, "Option ROM Init"}, 6498a23840SMatthew Barth {0x09, "Video Init"}, 6598a23840SMatthew Barth {0x0A, "Cache Init"}, 6698a23840SMatthew Barth {0x0B, "SM Bus init"}, 6798a23840SMatthew Barth {0x0C, "Keyboard Init"}, 6898a23840SMatthew Barth {0x0D, "Embedded ctrl init"}, 6998a23840SMatthew Barth {0x0E, "Docking station attachment"}, 7098a23840SMatthew Barth {0x0F, "Enable docking station"}, 7198a23840SMatthew Barth {0x10, "Docking station ejection"}, 7298a23840SMatthew Barth {0x11, "Disabling docking station"}, 7398a23840SMatthew Barth {0x12, "Calling OS Wakeup"}, 7498a23840SMatthew Barth {0x13, "Starting OS"}, 7598a23840SMatthew Barth {0x14, "Baseboard Init"}, 7698a23840SMatthew Barth {0x15, ""}, 7798a23840SMatthew Barth {0x16, "Floppy Init"}, 7898a23840SMatthew Barth {0x17, "Keyboard Test"}, 7998a23840SMatthew Barth {0x18, "Pointing Device Test"}, 8098a23840SMatthew Barth {0x19, "Primary Proc Init"}, 81*0b02be92SPatrick Venture {0xFF, "Unknown"}}; 8298a23840SMatthew Barth 8398a23840SMatthew Barth event_data_t g_fwprogress00h[] = { 8498a23840SMatthew Barth {0x00, "Unspecified."}, 8598a23840SMatthew Barth {0x01, "No system memory detected"}, 8698a23840SMatthew Barth {0x02, "No usable system memory"}, 8798a23840SMatthew Barth {0x03, "Unrecoverable hard-disk/ATAPI/IDE"}, 8898a23840SMatthew Barth {0x04, "Unrecoverable system-board"}, 8998a23840SMatthew Barth {0x05, "Unrecoverable diskette"}, 9098a23840SMatthew Barth {0x06, "Unrecoverable hard-disk controller"}, 9198a23840SMatthew Barth {0x07, "Unrecoverable PS/2 or USB keyboard"}, 9298a23840SMatthew Barth {0x08, "Removable boot media not found"}, 9398a23840SMatthew Barth {0x09, "Unrecoverable video controller"}, 9498a23840SMatthew Barth {0x0A, "No video device detected"}, 9598a23840SMatthew Barth {0x0B, "Firmware ROM corruption detected"}, 9698a23840SMatthew Barth {0x0C, "CPU voltage mismatch"}, 9798a23840SMatthew Barth {0x0D, "CPU speed matching"}, 9898a23840SMatthew Barth {0xFF, "unknown"}, 9998a23840SMatthew Barth }; 10098a23840SMatthew Barth 101*0b02be92SPatrick Venture char* event_data_lookup(event_data_t* p, uint8_t b) 102*0b02be92SPatrick Venture { 10398a23840SMatthew Barth 104*0b02be92SPatrick Venture while (p->data != 0xFF) 105*0b02be92SPatrick Venture { 106*0b02be92SPatrick Venture if (p->data == b) 107*0b02be92SPatrick Venture { 10898a23840SMatthew Barth break; 10998a23840SMatthew Barth } 11098a23840SMatthew Barth p++; 11198a23840SMatthew Barth } 11298a23840SMatthew Barth 11398a23840SMatthew Barth return p->text; 11498a23840SMatthew Barth } 11598a23840SMatthew Barth 116*0b02be92SPatrick Venture // The fw progress sensor contains some additional information that needs to be 117*0b02be92SPatrick Venture // processed prior to calling the dbus code. 118*0b02be92SPatrick Venture int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec, 119*0b02be92SPatrick Venture const lookup_t* pTable, const char* value) 120*0b02be92SPatrick Venture { 12198a23840SMatthew Barth 12298a23840SMatthew Barth char valuestring[128]; 12398a23840SMatthew Barth char* p = valuestring; 12498a23840SMatthew Barth 125*0b02be92SPatrick Venture switch (pTable->offset) 126*0b02be92SPatrick Venture { 12798a23840SMatthew Barth 128*0b02be92SPatrick Venture case 0x00: 129*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "POST Error, %s", 130*0b02be92SPatrick Venture event_data_lookup(g_fwprogress00h, pRec->event_data2)); 13198a23840SMatthew Barth break; 132*0b02be92SPatrick Venture case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the 133*0b02be92SPatrick Venture ipmi spec says to do */ 134*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "FW Hang, %s", 135*0b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 13698a23840SMatthew Barth break; 137*0b02be92SPatrick Venture case 0x02: 138*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "FW Progress, %s", 139*0b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 14098a23840SMatthew Barth break; 141*0b02be92SPatrick Venture default: 142*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 143*0b02be92SPatrick Venture "Internal warning, fw_progres offset unknown (0x%02x)", 144*0b02be92SPatrick Venture pTable->offset); 14598a23840SMatthew Barth break; 14698a23840SMatthew Barth } 14798a23840SMatthew Barth 148*0b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p); 14998a23840SMatthew Barth } 15098a23840SMatthew Barth 151*0b02be92SPatrick Venture // Handling this special OEM sensor by coping what is in byte 4. I also think 152*0b02be92SPatrick Venture // that is odd considering byte 3 is for sensor reading. This seems like a 153*0b02be92SPatrick Venture // misuse of the IPMI spec 154*0b02be92SPatrick Venture int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, 155*0b02be92SPatrick Venture const lookup_t* pTable, const char* value) 156*0b02be92SPatrick Venture { 157*0b02be92SPatrick Venture return set_sensor_dbus_state_y(pRec->sensor_number, "setValue", 15898a23840SMatthew Barth pRec->assert_state7_0); 15998a23840SMatthew Barth } 16098a23840SMatthew Barth 161*0b02be92SPatrick Venture int set_sensor_dbus_state_system_event(const sensorRES_t* pRec, 162*0b02be92SPatrick Venture const lookup_t* pTable, 163*0b02be92SPatrick Venture const char* value) 164*0b02be92SPatrick Venture { 16598a23840SMatthew Barth char valuestring[128]; 16698a23840SMatthew Barth char* p = valuestring; 16798a23840SMatthew Barth 168*0b02be92SPatrick Venture switch (pTable->offset) 169*0b02be92SPatrick Venture { 17098a23840SMatthew Barth 171*0b02be92SPatrick Venture case 0x00: 172*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "System Reconfigured"); 17398a23840SMatthew Barth break; 174*0b02be92SPatrick Venture case 0x01: 175*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "OEM Boot Event"); 17698a23840SMatthew Barth break; 177*0b02be92SPatrick Venture case 0x02: 178*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 179*0b02be92SPatrick Venture "Undetermined System Hardware Failure"); 18098a23840SMatthew Barth break; 181*0b02be92SPatrick Venture case 0x03: 182*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 183*0b02be92SPatrick Venture "System Failure see error log for more details (0x%02x)", 184*0b02be92SPatrick Venture pRec->event_data2); 18598a23840SMatthew Barth break; 186*0b02be92SPatrick Venture case 0x04: 187*0b02be92SPatrick Venture snprintf( 188*0b02be92SPatrick Venture p, sizeof(valuestring), 189*0b02be92SPatrick Venture "System Failure see PEF error log for more details (0x%02x)", 190*0b02be92SPatrick Venture pRec->event_data2); 19198a23840SMatthew Barth break; 192*0b02be92SPatrick Venture default: 193*0b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 194*0b02be92SPatrick Venture "Internal warning, system_event offset unknown (0x%02x)", 195*0b02be92SPatrick Venture pTable->offset); 19698a23840SMatthew Barth break; 19798a23840SMatthew Barth } 19898a23840SMatthew Barth 199*0b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p); 20098a23840SMatthew Barth } 20198a23840SMatthew Barth 20298a23840SMatthew Barth // This table lists only senors we care about telling dbus about. 20398a23840SMatthew Barth // Offset definition cab be found in section 42.2 of the IPMI 2.0 20498a23840SMatthew Barth // spec. Add more if/when there are more items of interest. 20598a23840SMatthew Barth lookup_t g_ipmidbuslookup[] = { 20698a23840SMatthew Barth 207*0b02be92SPatrick Venture {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", 208*0b02be92SPatrick Venture ""}, // OCC Inactive 0 209*0b02be92SPatrick Venture {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", 210*0b02be92SPatrick Venture ""}, // OCC Active 1 2110661beb1SJayanth Othayoth // Turbo Allowed 21200f0815bSTom Joseph {0xda, 0x00, set_sensor_dbus_state_simple, "setValue", "True", "False"}, 213d5b2ac0eSJayanth Othayoth // Power Supply Derating 214d5b2ac0eSJayanth Othayoth {0xb4, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""}, 2155422e0e9SJayanth Othayoth // Power Cap 2165422e0e9SJayanth Othayoth {0xC2, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""}, 21798a23840SMatthew Barth {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, 21898a23840SMatthew Barth {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 21998a23840SMatthew Barth {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, 22098a23840SMatthew Barth {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 22198a23840SMatthew Barth {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22298a23840SMatthew Barth {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22398a23840SMatthew Barth {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22498a23840SMatthew Barth {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 22598a23840SMatthew Barth {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "", ""}, 226*0b02be92SPatrick Venture {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue", 227*0b02be92SPatrick Venture "Boot completed (00)", ""}, 228*0b02be92SPatrick Venture {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue", 229*0b02be92SPatrick Venture "Boot completed (01)", ""}, 230*0b02be92SPatrick Venture {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed", 231*0b02be92SPatrick Venture ""}, 232*0b02be92SPatrick Venture {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue", 233*0b02be92SPatrick Venture "Diagnostic boot completed", ""}, 234*0b02be92SPatrick Venture {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue", 235*0b02be92SPatrick Venture "CD-ROM boot completed", ""}, 236*0b02be92SPatrick Venture {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed", 237*0b02be92SPatrick Venture ""}, 238*0b02be92SPatrick Venture {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue", 239*0b02be92SPatrick Venture "Boot completed (06)", ""}, 24098a23840SMatthew Barth {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24198a23840SMatthew Barth {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24298a23840SMatthew Barth {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24398a23840SMatthew Barth {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24498a23840SMatthew Barth {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""}, 2456244f93dSDhruvaraj Subhashchandran {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""}, 2466244f93dSDhruvaraj Subhashchandran {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""}, 247*0b02be92SPatrick Venture {0xFF, 0xFF, NULL, "", "", ""}}; 24898a23840SMatthew Barth 249*0b02be92SPatrick Venture void reportSensorEventAssert(sensorRES_t* pRec, int index) 250*0b02be92SPatrick Venture { 25198a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 25298a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->assertion); 25398a23840SMatthew Barth } 254*0b02be92SPatrick Venture void reportSensorEventDeassert(sensorRES_t* pRec, int index) 255*0b02be92SPatrick Venture { 25698a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 25798a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->deassertion); 25898a23840SMatthew Barth } 25998a23840SMatthew Barth 260*0b02be92SPatrick Venture int findindex(const uint8_t sensor_type, int offset, int* index) 261*0b02be92SPatrick Venture { 26298a23840SMatthew Barth 26398a23840SMatthew Barth int i = 0, rc = 0; 26498a23840SMatthew Barth lookup_t* pTable = g_ipmidbuslookup; 26598a23840SMatthew Barth 266*0b02be92SPatrick Venture do 267*0b02be92SPatrick Venture { 26898a23840SMatthew Barth if (((pTable + i)->sensor_type == sensor_type) && 269*0b02be92SPatrick Venture ((pTable + i)->offset == offset)) 270*0b02be92SPatrick Venture { 27198a23840SMatthew Barth rc = 1; 27298a23840SMatthew Barth *index = i; 27398a23840SMatthew Barth break; 27498a23840SMatthew Barth } 27598a23840SMatthew Barth i++; 27698a23840SMatthew Barth } while ((pTable + i)->sensor_type != 0xFF); 27798a23840SMatthew Barth 27898a23840SMatthew Barth return rc; 27998a23840SMatthew Barth } 28098a23840SMatthew Barth 281*0b02be92SPatrick Venture bool shouldReport(uint8_t sensorType, int offset, int* index) 282*0b02be92SPatrick Venture { 28398a23840SMatthew Barth 28498a23840SMatthew Barth bool rc = false; 28598a23840SMatthew Barth 286*0b02be92SPatrick Venture if (findindex(sensorType, offset, index)) 287*0b02be92SPatrick Venture { 288*0b02be92SPatrick Venture rc = true; 289*0b02be92SPatrick Venture } 290*0b02be92SPatrick Venture if (rc == false) 291*0b02be92SPatrick Venture { 2925fb14603SAditya Saripalli #ifdef __IPMI_DEBUG__ 2935fb14603SAditya Saripalli log<level::DEBUG>("LOOKATME: Sensor should not be reported", 2945fb14603SAditya Saripalli entry("SENSORTYPE=0x%02x", sensorType), 2955fb14603SAditya Saripalli entry("OFFSET=0x%02x", offset)); 2965fb14603SAditya Saripalli #endif 2975fb14603SAditya Saripalli } 29898a23840SMatthew Barth 29998a23840SMatthew Barth return rc; 30098a23840SMatthew Barth } 30198a23840SMatthew Barth 302*0b02be92SPatrick Venture int updateSensorRecordFromSSRAESC(const void* record) 303*0b02be92SPatrick Venture { 30498a23840SMatthew Barth 30598a23840SMatthew Barth sensorRES_t* pRec = (sensorRES_t*)record; 30698a23840SMatthew Barth uint8_t stype; 30798a23840SMatthew Barth int index, i = 0; 30898a23840SMatthew Barth 309391f3303SEmily Shaffer stype = find_type_for_sensor_number(pRec->sensor_number); 31098a23840SMatthew Barth 31198a23840SMatthew Barth // 0xC3 types use the assertion7_0 for the value to be set 31298a23840SMatthew Barth // so skip the reseach and call the correct event reporting 31398a23840SMatthew Barth // function 314*0b02be92SPatrick Venture if (stype == 0xC3) 315*0b02be92SPatrick Venture { 31698a23840SMatthew Barth 31798a23840SMatthew Barth shouldReport(stype, 0x00, &index); 31898a23840SMatthew Barth reportSensorEventAssert(pRec, index); 319*0b02be92SPatrick Venture } 320*0b02be92SPatrick Venture else 321*0b02be92SPatrick Venture { 32298a23840SMatthew Barth // Scroll through each bit position . Determine 32398a23840SMatthew Barth // if any bit is either asserted or Deasserted. 324*0b02be92SPatrick Venture for (i = 0; i < 8; i++) 325*0b02be92SPatrick Venture { 32698a23840SMatthew Barth 32798a23840SMatthew Barth if ((ISBITSET(pRec->assert_state7_0, i)) && 32898a23840SMatthew Barth (shouldReport(stype, i, &index))) 32998a23840SMatthew Barth { 33098a23840SMatthew Barth reportSensorEventAssert(pRec, index); 33198a23840SMatthew Barth } 33298a23840SMatthew Barth if ((ISBITSET(pRec->assert_state14_8, i)) && 33398a23840SMatthew Barth (shouldReport(stype, i + 8, &index))) 33498a23840SMatthew Barth { 33598a23840SMatthew Barth reportSensorEventAssert(pRec, index); 33698a23840SMatthew Barth } 33798a23840SMatthew Barth if ((ISBITSET(pRec->deassert_state7_0, i)) && 33898a23840SMatthew Barth (shouldReport(stype, i, &index))) 33998a23840SMatthew Barth { 34098a23840SMatthew Barth reportSensorEventDeassert(pRec, index); 34198a23840SMatthew Barth } 34298a23840SMatthew Barth if ((ISBITSET(pRec->deassert_state14_8, i)) && 34398a23840SMatthew Barth (shouldReport(stype, i + 8, &index))) 34498a23840SMatthew Barth { 34598a23840SMatthew Barth reportSensorEventDeassert(pRec, index); 34698a23840SMatthew Barth } 34798a23840SMatthew Barth } 34898a23840SMatthew Barth } 34998a23840SMatthew Barth 35098a23840SMatthew Barth return 0; 35198a23840SMatthew Barth } 352