146470a38SPatrick Venture #include "sensorhandler.hpp" 246470a38SPatrick Venture 30b02be92SPatrick Venture #include <malloc.h> 40b02be92SPatrick Venture 5391f3303SEmily Shaffer extern uint8_t find_type_for_sensor_number(uint8_t); 698a23840SMatthew Barth 70b02be92SPatrick Venture struct sensorRES_t 80b02be92SPatrick Venture { 998a23840SMatthew Barth uint8_t sensor_number; 1098a23840SMatthew Barth uint8_t operation; 1198a23840SMatthew Barth uint8_t sensor_reading; 1298a23840SMatthew Barth uint8_t assert_state7_0; 1398a23840SMatthew Barth uint8_t assert_state14_8; 1498a23840SMatthew Barth uint8_t deassert_state7_0; 1598a23840SMatthew Barth uint8_t deassert_state14_8; 1698a23840SMatthew Barth uint8_t event_data1; 1798a23840SMatthew Barth uint8_t event_data2; 1898a23840SMatthew Barth uint8_t event_data3; 1998a23840SMatthew Barth } __attribute__((packed)); 2098a23840SMatthew Barth 2198a23840SMatthew Barth #define ISBITSET(x, y) (((x) >> (y)) & 0x01) 2298a23840SMatthew Barth #define ASSERTINDEX 0 2398a23840SMatthew Barth #define DEASSERTINDEX 1 2498a23840SMatthew Barth 250b02be92SPatrick Venture // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert 260b02be92SPatrick Venture // value 270b02be92SPatrick Venture struct lookup_t 280b02be92SPatrick Venture { 2998a23840SMatthew Barth uint8_t sensor_type; 3098a23840SMatthew Barth uint8_t offset; 3198a23840SMatthew Barth int (*func)(const sensorRES_t*, const lookup_t*, const char*); 3298a23840SMatthew Barth char member[16]; 3398a23840SMatthew Barth char assertion[64]; 3498a23840SMatthew Barth char deassertion[64]; 3598a23840SMatthew Barth }; 3698a23840SMatthew Barth 3798a23840SMatthew Barth extern int updateDbusInterface(uint8_t, const char*, const char*); 3898a23840SMatthew Barth 390b02be92SPatrick Venture int set_sensor_dbus_state_simple(const sensorRES_t* pRec, 400b02be92SPatrick Venture const lookup_t* pTable, const char* value) 410b02be92SPatrick Venture { 4298a23840SMatthew Barth 430b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value); 4498a23840SMatthew Barth } 4598a23840SMatthew Barth 460b02be92SPatrick Venture struct event_data_t 470b02be92SPatrick Venture { 4898a23840SMatthew Barth uint8_t data; 4998a23840SMatthew Barth char text[64]; 5098a23840SMatthew Barth }; 5198a23840SMatthew Barth 520b02be92SPatrick Venture event_data_t g_fwprogress02h[] = {{0x00, "Unspecified"}, 5398a23840SMatthew Barth {0x01, "Memory Init"}, 5498a23840SMatthew Barth {0x02, "HD Init"}, 5598a23840SMatthew Barth {0x03, "Secondary Proc Init"}, 5698a23840SMatthew Barth {0x04, "User Authentication"}, 5798a23840SMatthew Barth {0x05, "User init system setup"}, 5898a23840SMatthew Barth {0x06, "USB configuration"}, 5998a23840SMatthew Barth {0x07, "PCI configuration"}, 6098a23840SMatthew Barth {0x08, "Option ROM Init"}, 6198a23840SMatthew Barth {0x09, "Video Init"}, 6298a23840SMatthew Barth {0x0A, "Cache Init"}, 6398a23840SMatthew Barth {0x0B, "SM Bus init"}, 6498a23840SMatthew Barth {0x0C, "Keyboard Init"}, 6598a23840SMatthew Barth {0x0D, "Embedded ctrl init"}, 6698a23840SMatthew Barth {0x0E, "Docking station attachment"}, 6798a23840SMatthew Barth {0x0F, "Enable docking station"}, 6898a23840SMatthew Barth {0x10, "Docking station ejection"}, 6998a23840SMatthew Barth {0x11, "Disabling docking station"}, 7098a23840SMatthew Barth {0x12, "Calling OS Wakeup"}, 7198a23840SMatthew Barth {0x13, "Starting OS"}, 7298a23840SMatthew Barth {0x14, "Baseboard Init"}, 7398a23840SMatthew Barth {0x15, ""}, 7498a23840SMatthew Barth {0x16, "Floppy Init"}, 7598a23840SMatthew Barth {0x17, "Keyboard Test"}, 7698a23840SMatthew Barth {0x18, "Pointing Device Test"}, 7798a23840SMatthew Barth {0x19, "Primary Proc Init"}, 780b02be92SPatrick Venture {0xFF, "Unknown"}}; 7998a23840SMatthew Barth 8098a23840SMatthew Barth event_data_t g_fwprogress00h[] = { 8198a23840SMatthew Barth {0x00, "Unspecified."}, 8298a23840SMatthew Barth {0x01, "No system memory detected"}, 8398a23840SMatthew Barth {0x02, "No usable system memory"}, 8498a23840SMatthew Barth {0x03, "Unrecoverable hard-disk/ATAPI/IDE"}, 8598a23840SMatthew Barth {0x04, "Unrecoverable system-board"}, 8698a23840SMatthew Barth {0x05, "Unrecoverable diskette"}, 8798a23840SMatthew Barth {0x06, "Unrecoverable hard-disk controller"}, 8898a23840SMatthew Barth {0x07, "Unrecoverable PS/2 or USB keyboard"}, 8998a23840SMatthew Barth {0x08, "Removable boot media not found"}, 9098a23840SMatthew Barth {0x09, "Unrecoverable video controller"}, 9198a23840SMatthew Barth {0x0A, "No video device detected"}, 9298a23840SMatthew Barth {0x0B, "Firmware ROM corruption detected"}, 9398a23840SMatthew Barth {0x0C, "CPU voltage mismatch"}, 9498a23840SMatthew Barth {0x0D, "CPU speed matching"}, 9598a23840SMatthew Barth {0xFF, "unknown"}, 9698a23840SMatthew Barth }; 9798a23840SMatthew Barth 980b02be92SPatrick Venture char* event_data_lookup(event_data_t* p, uint8_t b) 990b02be92SPatrick Venture { 10098a23840SMatthew Barth 1010b02be92SPatrick Venture while (p->data != 0xFF) 1020b02be92SPatrick Venture { 1030b02be92SPatrick Venture if (p->data == b) 1040b02be92SPatrick Venture { 10598a23840SMatthew Barth break; 10698a23840SMatthew Barth } 10798a23840SMatthew Barth p++; 10898a23840SMatthew Barth } 10998a23840SMatthew Barth 11098a23840SMatthew Barth return p->text; 11198a23840SMatthew Barth } 11298a23840SMatthew Barth 1130b02be92SPatrick Venture // The fw progress sensor contains some additional information that needs to be 1140b02be92SPatrick Venture // processed prior to calling the dbus code. 1150b02be92SPatrick Venture int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec, 1160b02be92SPatrick Venture const lookup_t* pTable, const char* value) 1170b02be92SPatrick Venture { 11898a23840SMatthew Barth 11998a23840SMatthew Barth char valuestring[128]; 12098a23840SMatthew Barth char* p = valuestring; 12198a23840SMatthew Barth 1220b02be92SPatrick Venture switch (pTable->offset) 1230b02be92SPatrick Venture { 12498a23840SMatthew Barth 1250b02be92SPatrick Venture case 0x00: 126*b51bf9c8SPatrick Venture std::snprintf( 127*b51bf9c8SPatrick Venture p, sizeof(valuestring), "POST Error, %s", 1280b02be92SPatrick Venture event_data_lookup(g_fwprogress00h, pRec->event_data2)); 12998a23840SMatthew Barth break; 1300b02be92SPatrick Venture case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the 1310b02be92SPatrick Venture ipmi spec says to do */ 132*b51bf9c8SPatrick Venture std::snprintf( 133*b51bf9c8SPatrick Venture p, sizeof(valuestring), "FW Hang, %s", 1340b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 13598a23840SMatthew Barth break; 1360b02be92SPatrick Venture case 0x02: 137*b51bf9c8SPatrick Venture std::snprintf( 138*b51bf9c8SPatrick Venture p, sizeof(valuestring), "FW Progress, %s", 1390b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 14098a23840SMatthew Barth break; 1410b02be92SPatrick Venture default: 142*b51bf9c8SPatrick Venture std::snprintf( 143*b51bf9c8SPatrick Venture p, sizeof(valuestring), 1440b02be92SPatrick Venture "Internal warning, fw_progres offset unknown (0x%02x)", 1450b02be92SPatrick Venture pTable->offset); 14698a23840SMatthew Barth break; 14798a23840SMatthew Barth } 14898a23840SMatthew Barth 1490b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p); 15098a23840SMatthew Barth } 15198a23840SMatthew Barth 1520b02be92SPatrick Venture // Handling this special OEM sensor by coping what is in byte 4. I also think 1530b02be92SPatrick Venture // that is odd considering byte 3 is for sensor reading. This seems like a 1540b02be92SPatrick Venture // misuse of the IPMI spec 1550b02be92SPatrick Venture int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, 1560b02be92SPatrick Venture const lookup_t* pTable, const char* value) 1570b02be92SPatrick Venture { 1580b02be92SPatrick Venture return set_sensor_dbus_state_y(pRec->sensor_number, "setValue", 15998a23840SMatthew Barth pRec->assert_state7_0); 16098a23840SMatthew Barth } 16198a23840SMatthew Barth 1620b02be92SPatrick Venture int set_sensor_dbus_state_system_event(const sensorRES_t* pRec, 1630b02be92SPatrick Venture const lookup_t* pTable, 1640b02be92SPatrick Venture const char* value) 1650b02be92SPatrick Venture { 16698a23840SMatthew Barth char valuestring[128]; 16798a23840SMatthew Barth char* p = valuestring; 16898a23840SMatthew Barth 1690b02be92SPatrick Venture switch (pTable->offset) 1700b02be92SPatrick Venture { 17198a23840SMatthew Barth 1720b02be92SPatrick Venture case 0x00: 173*b51bf9c8SPatrick Venture std::snprintf(p, sizeof(valuestring), "System Reconfigured"); 17498a23840SMatthew Barth break; 1750b02be92SPatrick Venture case 0x01: 176*b51bf9c8SPatrick Venture std::snprintf(p, sizeof(valuestring), "OEM Boot Event"); 17798a23840SMatthew Barth break; 1780b02be92SPatrick Venture case 0x02: 179*b51bf9c8SPatrick Venture std::snprintf(p, sizeof(valuestring), 1800b02be92SPatrick Venture "Undetermined System Hardware Failure"); 18198a23840SMatthew Barth break; 1820b02be92SPatrick Venture case 0x03: 183*b51bf9c8SPatrick Venture std::snprintf( 184*b51bf9c8SPatrick Venture p, sizeof(valuestring), 1850b02be92SPatrick Venture "System Failure see error log for more details (0x%02x)", 1860b02be92SPatrick Venture pRec->event_data2); 18798a23840SMatthew Barth break; 1880b02be92SPatrick Venture case 0x04: 189*b51bf9c8SPatrick Venture std::snprintf( 1900b02be92SPatrick Venture p, sizeof(valuestring), 1910b02be92SPatrick Venture "System Failure see PEF error log for more details (0x%02x)", 1920b02be92SPatrick Venture pRec->event_data2); 19398a23840SMatthew Barth break; 1940b02be92SPatrick Venture default: 195*b51bf9c8SPatrick Venture std::snprintf( 196*b51bf9c8SPatrick Venture p, sizeof(valuestring), 1970b02be92SPatrick Venture "Internal warning, system_event offset unknown (0x%02x)", 1980b02be92SPatrick Venture pTable->offset); 19998a23840SMatthew Barth break; 20098a23840SMatthew Barth } 20198a23840SMatthew Barth 2020b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p); 20398a23840SMatthew Barth } 20498a23840SMatthew Barth 20598a23840SMatthew Barth // This table lists only senors we care about telling dbus about. 20698a23840SMatthew Barth // Offset definition cab be found in section 42.2 of the IPMI 2.0 20798a23840SMatthew Barth // spec. Add more if/when there are more items of interest. 20898a23840SMatthew Barth lookup_t g_ipmidbuslookup[] = { 20998a23840SMatthew Barth 2100b02be92SPatrick Venture {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", 2110b02be92SPatrick Venture ""}, // OCC Inactive 0 2120b02be92SPatrick Venture {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", 2130b02be92SPatrick Venture ""}, // OCC Active 1 2140661beb1SJayanth Othayoth // Turbo Allowed 21500f0815bSTom Joseph {0xda, 0x00, set_sensor_dbus_state_simple, "setValue", "True", "False"}, 216d5b2ac0eSJayanth Othayoth // Power Supply Derating 217d5b2ac0eSJayanth Othayoth {0xb4, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""}, 2185422e0e9SJayanth Othayoth // Power Cap 2195422e0e9SJayanth Othayoth {0xC2, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""}, 22098a23840SMatthew Barth {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, 22198a23840SMatthew Barth {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 22298a23840SMatthew Barth {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, 22398a23840SMatthew Barth {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 22498a23840SMatthew Barth {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22598a23840SMatthew Barth {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22698a23840SMatthew Barth {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, 22798a23840SMatthew Barth {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"}, 22898a23840SMatthew Barth {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "", ""}, 2290b02be92SPatrick Venture {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue", 2300b02be92SPatrick Venture "Boot completed (00)", ""}, 2310b02be92SPatrick Venture {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue", 2320b02be92SPatrick Venture "Boot completed (01)", ""}, 2330b02be92SPatrick Venture {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed", 2340b02be92SPatrick Venture ""}, 2350b02be92SPatrick Venture {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue", 2360b02be92SPatrick Venture "Diagnostic boot completed", ""}, 2370b02be92SPatrick Venture {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue", 2380b02be92SPatrick Venture "CD-ROM boot completed", ""}, 2390b02be92SPatrick Venture {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed", 2400b02be92SPatrick Venture ""}, 2410b02be92SPatrick Venture {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue", 2420b02be92SPatrick Venture "Boot completed (06)", ""}, 24398a23840SMatthew Barth {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24498a23840SMatthew Barth {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24598a23840SMatthew Barth {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24698a23840SMatthew Barth {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""}, 24798a23840SMatthew Barth {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""}, 2486244f93dSDhruvaraj Subhashchandran {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""}, 2496244f93dSDhruvaraj Subhashchandran {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""}, 2500b02be92SPatrick Venture {0xFF, 0xFF, NULL, "", "", ""}}; 25198a23840SMatthew Barth 2520b02be92SPatrick Venture void reportSensorEventAssert(sensorRES_t* pRec, int index) 2530b02be92SPatrick Venture { 25498a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 25598a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->assertion); 25698a23840SMatthew Barth } 2570b02be92SPatrick Venture void reportSensorEventDeassert(sensorRES_t* pRec, int index) 2580b02be92SPatrick Venture { 25998a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 26098a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->deassertion); 26198a23840SMatthew Barth } 26298a23840SMatthew Barth 2630b02be92SPatrick Venture int findindex(const uint8_t sensor_type, int offset, int* index) 2640b02be92SPatrick Venture { 26598a23840SMatthew Barth 26698a23840SMatthew Barth int i = 0, rc = 0; 26798a23840SMatthew Barth lookup_t* pTable = g_ipmidbuslookup; 26898a23840SMatthew Barth 2690b02be92SPatrick Venture do 2700b02be92SPatrick Venture { 27198a23840SMatthew Barth if (((pTable + i)->sensor_type == sensor_type) && 2720b02be92SPatrick Venture ((pTable + i)->offset == offset)) 2730b02be92SPatrick Venture { 27498a23840SMatthew Barth rc = 1; 27598a23840SMatthew Barth *index = i; 27698a23840SMatthew Barth break; 27798a23840SMatthew Barth } 27898a23840SMatthew Barth i++; 27998a23840SMatthew Barth } while ((pTable + i)->sensor_type != 0xFF); 28098a23840SMatthew Barth 28198a23840SMatthew Barth return rc; 28298a23840SMatthew Barth } 28398a23840SMatthew Barth 2840b02be92SPatrick Venture bool shouldReport(uint8_t sensorType, int offset, int* index) 2850b02be92SPatrick Venture { 28698a23840SMatthew Barth 28798a23840SMatthew Barth bool rc = false; 28898a23840SMatthew Barth 2890b02be92SPatrick Venture if (findindex(sensorType, offset, index)) 2900b02be92SPatrick Venture { 2910b02be92SPatrick Venture rc = true; 2920b02be92SPatrick Venture } 2930b02be92SPatrick Venture if (rc == false) 2940b02be92SPatrick Venture { 2955fb14603SAditya Saripalli #ifdef __IPMI_DEBUG__ 2965fb14603SAditya Saripalli log<level::DEBUG>("LOOKATME: Sensor should not be reported", 2975fb14603SAditya Saripalli entry("SENSORTYPE=0x%02x", sensorType), 2985fb14603SAditya Saripalli entry("OFFSET=0x%02x", offset)); 2995fb14603SAditya Saripalli #endif 3005fb14603SAditya Saripalli } 30198a23840SMatthew Barth 30298a23840SMatthew Barth return rc; 30398a23840SMatthew Barth } 30498a23840SMatthew Barth 3050b02be92SPatrick Venture int updateSensorRecordFromSSRAESC(const void* record) 3060b02be92SPatrick Venture { 30798a23840SMatthew Barth 30898a23840SMatthew Barth sensorRES_t* pRec = (sensorRES_t*)record; 30998a23840SMatthew Barth uint8_t stype; 31098a23840SMatthew Barth int index, i = 0; 31198a23840SMatthew Barth 312391f3303SEmily Shaffer stype = find_type_for_sensor_number(pRec->sensor_number); 31398a23840SMatthew Barth 31498a23840SMatthew Barth // 0xC3 types use the assertion7_0 for the value to be set 31598a23840SMatthew Barth // so skip the reseach and call the correct event reporting 31698a23840SMatthew Barth // function 3170b02be92SPatrick Venture if (stype == 0xC3) 3180b02be92SPatrick Venture { 31998a23840SMatthew Barth 32098a23840SMatthew Barth shouldReport(stype, 0x00, &index); 32198a23840SMatthew Barth reportSensorEventAssert(pRec, index); 3220b02be92SPatrick Venture } 3230b02be92SPatrick Venture else 3240b02be92SPatrick Venture { 32598a23840SMatthew Barth // Scroll through each bit position . Determine 32698a23840SMatthew Barth // if any bit is either asserted or Deasserted. 3270b02be92SPatrick Venture for (i = 0; i < 8; i++) 3280b02be92SPatrick Venture { 32998a23840SMatthew Barth 33098a23840SMatthew Barth if ((ISBITSET(pRec->assert_state7_0, i)) && 33198a23840SMatthew Barth (shouldReport(stype, i, &index))) 33298a23840SMatthew Barth { 33398a23840SMatthew Barth reportSensorEventAssert(pRec, index); 33498a23840SMatthew Barth } 33598a23840SMatthew Barth if ((ISBITSET(pRec->assert_state14_8, i)) && 33698a23840SMatthew Barth (shouldReport(stype, i + 8, &index))) 33798a23840SMatthew Barth { 33898a23840SMatthew Barth reportSensorEventAssert(pRec, index); 33998a23840SMatthew Barth } 34098a23840SMatthew Barth if ((ISBITSET(pRec->deassert_state7_0, i)) && 34198a23840SMatthew Barth (shouldReport(stype, i, &index))) 34298a23840SMatthew Barth { 34398a23840SMatthew Barth reportSensorEventDeassert(pRec, index); 34498a23840SMatthew Barth } 34598a23840SMatthew Barth if ((ISBITSET(pRec->deassert_state14_8, i)) && 34698a23840SMatthew Barth (shouldReport(stype, i + 8, &index))) 34798a23840SMatthew Barth { 34898a23840SMatthew Barth reportSensorEventDeassert(pRec, index); 34998a23840SMatthew Barth } 35098a23840SMatthew Barth } 35198a23840SMatthew Barth } 35298a23840SMatthew Barth 35398a23840SMatthew Barth return 0; 35498a23840SMatthew Barth } 355