1*46470a38SPatrick Venture #include "sensorhandler.hpp" 2*46470a38SPatrick Venture 30b02be92SPatrick Venture #include <malloc.h> 40b02be92SPatrick Venture #include <stdint.h> 598a23840SMatthew Barth #include <stdio.h> 698a23840SMatthew Barth #include <string.h> 70b02be92SPatrick Venture 8391f3303SEmily Shaffer extern uint8_t find_type_for_sensor_number(uint8_t); 998a23840SMatthew Barth 100b02be92SPatrick Venture struct sensorRES_t 110b02be92SPatrick 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 280b02be92SPatrick Venture // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert 290b02be92SPatrick Venture // value 300b02be92SPatrick Venture struct lookup_t 310b02be92SPatrick 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 420b02be92SPatrick Venture int set_sensor_dbus_state_simple(const sensorRES_t* pRec, 430b02be92SPatrick Venture const lookup_t* pTable, const char* value) 440b02be92SPatrick Venture { 4598a23840SMatthew Barth 460b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value); 4798a23840SMatthew Barth } 4898a23840SMatthew Barth 490b02be92SPatrick Venture struct event_data_t 500b02be92SPatrick Venture { 5198a23840SMatthew Barth uint8_t data; 5298a23840SMatthew Barth char text[64]; 5398a23840SMatthew Barth }; 5498a23840SMatthew Barth 550b02be92SPatrick 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"}, 810b02be92SPatrick 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 1010b02be92SPatrick Venture char* event_data_lookup(event_data_t* p, uint8_t b) 1020b02be92SPatrick Venture { 10398a23840SMatthew Barth 1040b02be92SPatrick Venture while (p->data != 0xFF) 1050b02be92SPatrick Venture { 1060b02be92SPatrick Venture if (p->data == b) 1070b02be92SPatrick Venture { 10898a23840SMatthew Barth break; 10998a23840SMatthew Barth } 11098a23840SMatthew Barth p++; 11198a23840SMatthew Barth } 11298a23840SMatthew Barth 11398a23840SMatthew Barth return p->text; 11498a23840SMatthew Barth } 11598a23840SMatthew Barth 1160b02be92SPatrick Venture // The fw progress sensor contains some additional information that needs to be 1170b02be92SPatrick Venture // processed prior to calling the dbus code. 1180b02be92SPatrick Venture int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec, 1190b02be92SPatrick Venture const lookup_t* pTable, const char* value) 1200b02be92SPatrick Venture { 12198a23840SMatthew Barth 12298a23840SMatthew Barth char valuestring[128]; 12398a23840SMatthew Barth char* p = valuestring; 12498a23840SMatthew Barth 1250b02be92SPatrick Venture switch (pTable->offset) 1260b02be92SPatrick Venture { 12798a23840SMatthew Barth 1280b02be92SPatrick Venture case 0x00: 1290b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "POST Error, %s", 1300b02be92SPatrick Venture event_data_lookup(g_fwprogress00h, pRec->event_data2)); 13198a23840SMatthew Barth break; 1320b02be92SPatrick Venture case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the 1330b02be92SPatrick Venture ipmi spec says to do */ 1340b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "FW Hang, %s", 1350b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 13698a23840SMatthew Barth break; 1370b02be92SPatrick Venture case 0x02: 1380b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "FW Progress, %s", 1390b02be92SPatrick Venture event_data_lookup(g_fwprogress02h, pRec->event_data2)); 14098a23840SMatthew Barth break; 1410b02be92SPatrick Venture default: 1420b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 1430b02be92SPatrick Venture "Internal warning, fw_progres offset unknown (0x%02x)", 1440b02be92SPatrick Venture pTable->offset); 14598a23840SMatthew Barth break; 14698a23840SMatthew Barth } 14798a23840SMatthew Barth 1480b02be92SPatrick Venture return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p); 14998a23840SMatthew Barth } 15098a23840SMatthew Barth 1510b02be92SPatrick Venture // Handling this special OEM sensor by coping what is in byte 4. I also think 1520b02be92SPatrick Venture // that is odd considering byte 3 is for sensor reading. This seems like a 1530b02be92SPatrick Venture // misuse of the IPMI spec 1540b02be92SPatrick Venture int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, 1550b02be92SPatrick Venture const lookup_t* pTable, const char* value) 1560b02be92SPatrick Venture { 1570b02be92SPatrick Venture return set_sensor_dbus_state_y(pRec->sensor_number, "setValue", 15898a23840SMatthew Barth pRec->assert_state7_0); 15998a23840SMatthew Barth } 16098a23840SMatthew Barth 1610b02be92SPatrick Venture int set_sensor_dbus_state_system_event(const sensorRES_t* pRec, 1620b02be92SPatrick Venture const lookup_t* pTable, 1630b02be92SPatrick Venture const char* value) 1640b02be92SPatrick Venture { 16598a23840SMatthew Barth char valuestring[128]; 16698a23840SMatthew Barth char* p = valuestring; 16798a23840SMatthew Barth 1680b02be92SPatrick Venture switch (pTable->offset) 1690b02be92SPatrick Venture { 17098a23840SMatthew Barth 1710b02be92SPatrick Venture case 0x00: 1720b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "System Reconfigured"); 17398a23840SMatthew Barth break; 1740b02be92SPatrick Venture case 0x01: 1750b02be92SPatrick Venture snprintf(p, sizeof(valuestring), "OEM Boot Event"); 17698a23840SMatthew Barth break; 1770b02be92SPatrick Venture case 0x02: 1780b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 1790b02be92SPatrick Venture "Undetermined System Hardware Failure"); 18098a23840SMatthew Barth break; 1810b02be92SPatrick Venture case 0x03: 1820b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 1830b02be92SPatrick Venture "System Failure see error log for more details (0x%02x)", 1840b02be92SPatrick Venture pRec->event_data2); 18598a23840SMatthew Barth break; 1860b02be92SPatrick Venture case 0x04: 1870b02be92SPatrick Venture snprintf( 1880b02be92SPatrick Venture p, sizeof(valuestring), 1890b02be92SPatrick Venture "System Failure see PEF error log for more details (0x%02x)", 1900b02be92SPatrick Venture pRec->event_data2); 19198a23840SMatthew Barth break; 1920b02be92SPatrick Venture default: 1930b02be92SPatrick Venture snprintf(p, sizeof(valuestring), 1940b02be92SPatrick Venture "Internal warning, system_event offset unknown (0x%02x)", 1950b02be92SPatrick Venture pTable->offset); 19698a23840SMatthew Barth break; 19798a23840SMatthew Barth } 19898a23840SMatthew Barth 1990b02be92SPatrick 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 2070b02be92SPatrick Venture {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", 2080b02be92SPatrick Venture ""}, // OCC Inactive 0 2090b02be92SPatrick Venture {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", 2100b02be92SPatrick 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", "", ""}, 2260b02be92SPatrick Venture {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue", 2270b02be92SPatrick Venture "Boot completed (00)", ""}, 2280b02be92SPatrick Venture {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue", 2290b02be92SPatrick Venture "Boot completed (01)", ""}, 2300b02be92SPatrick Venture {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed", 2310b02be92SPatrick Venture ""}, 2320b02be92SPatrick Venture {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue", 2330b02be92SPatrick Venture "Diagnostic boot completed", ""}, 2340b02be92SPatrick Venture {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue", 2350b02be92SPatrick Venture "CD-ROM boot completed", ""}, 2360b02be92SPatrick Venture {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed", 2370b02be92SPatrick Venture ""}, 2380b02be92SPatrick Venture {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue", 2390b02be92SPatrick 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", ""}, 2470b02be92SPatrick Venture {0xFF, 0xFF, NULL, "", "", ""}}; 24898a23840SMatthew Barth 2490b02be92SPatrick Venture void reportSensorEventAssert(sensorRES_t* pRec, int index) 2500b02be92SPatrick Venture { 25198a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 25298a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->assertion); 25398a23840SMatthew Barth } 2540b02be92SPatrick Venture void reportSensorEventDeassert(sensorRES_t* pRec, int index) 2550b02be92SPatrick Venture { 25698a23840SMatthew Barth lookup_t* pTable = &g_ipmidbuslookup[index]; 25798a23840SMatthew Barth (*pTable->func)(pRec, pTable, pTable->deassertion); 25898a23840SMatthew Barth } 25998a23840SMatthew Barth 2600b02be92SPatrick Venture int findindex(const uint8_t sensor_type, int offset, int* index) 2610b02be92SPatrick Venture { 26298a23840SMatthew Barth 26398a23840SMatthew Barth int i = 0, rc = 0; 26498a23840SMatthew Barth lookup_t* pTable = g_ipmidbuslookup; 26598a23840SMatthew Barth 2660b02be92SPatrick Venture do 2670b02be92SPatrick Venture { 26898a23840SMatthew Barth if (((pTable + i)->sensor_type == sensor_type) && 2690b02be92SPatrick Venture ((pTable + i)->offset == offset)) 2700b02be92SPatrick 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 2810b02be92SPatrick Venture bool shouldReport(uint8_t sensorType, int offset, int* index) 2820b02be92SPatrick Venture { 28398a23840SMatthew Barth 28498a23840SMatthew Barth bool rc = false; 28598a23840SMatthew Barth 2860b02be92SPatrick Venture if (findindex(sensorType, offset, index)) 2870b02be92SPatrick Venture { 2880b02be92SPatrick Venture rc = true; 2890b02be92SPatrick Venture } 2900b02be92SPatrick Venture if (rc == false) 2910b02be92SPatrick 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 3020b02be92SPatrick Venture int updateSensorRecordFromSSRAESC(const void* record) 3030b02be92SPatrick 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 3140b02be92SPatrick Venture if (stype == 0xC3) 3150b02be92SPatrick Venture { 31698a23840SMatthew Barth 31798a23840SMatthew Barth shouldReport(stype, 0x00, &index); 31898a23840SMatthew Barth reportSensorEventAssert(pRec, index); 3190b02be92SPatrick Venture } 3200b02be92SPatrick Venture else 3210b02be92SPatrick Venture { 32298a23840SMatthew Barth // Scroll through each bit position . Determine 32398a23840SMatthew Barth // if any bit is either asserted or Deasserted. 3240b02be92SPatrick Venture for (i = 0; i < 8; i++) 3250b02be92SPatrick 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