1 #include <phosphor-logging/log.hpp> 2 #include "occ_status.hpp" 3 #include "occ_sensor.hpp" 4 #include "utils.hpp" 5 namespace open_power 6 { 7 namespace occ 8 { 9 10 // Handles updates to occActive property 11 bool Status::occActive(bool value) 12 { 13 if (value != this->occActive()) 14 { 15 if (value) 16 { 17 // Bind the device 18 device.bind(); 19 20 // Call into Manager to let know that we have bound 21 // TODO: openbmc/openbmc#2285 22 /* if (this->callBack) 23 { 24 this->callBack(value); 25 }*/ 26 } 27 else 28 { 29 // Call into Manager to let know that we will unbind. 30 // Need to do this before doing un-bind since it will 31 // result in slave error if Master is un-bound 32 /*if (this->callBack) 33 { 34 this->callBack(value); 35 }*/ 36 37 // Do the unbind. 38 device.unBind(); 39 } 40 } 41 return Base::Status::occActive(value); 42 } 43 44 // Callback handler when a device error is reported. 45 void Status::deviceErrorHandler() 46 { 47 // This would deem OCC inactive 48 this->occActive(false); 49 50 // Reset the OCC 51 this->resetOCC(); 52 } 53 54 // Sends message to host control command handler to reset OCC 55 void Status::resetOCC() 56 { 57 using namespace phosphor::logging; 58 constexpr auto CONTROL_HOST_PATH = "/org/open_power/control/host0"; 59 constexpr auto CONTROL_HOST_INTF = "org.open_power.Control.Host"; 60 61 // This will throw exception on failure 62 auto service = getService(bus, CONTROL_HOST_PATH, CONTROL_HOST_INTF); 63 64 auto method = bus.new_method_call(service.c_str(), 65 CONTROL_HOST_PATH, 66 CONTROL_HOST_INTF, 67 "Execute"); 68 // OCC Reset control command 69 method.append(convertForMessage( 70 Control::Host::Command::OCCReset).c_str()); 71 72 // OCC Sensor ID for callout reasons 73 method.append(sdbusplus::message::variant<uint8_t>( 74 sensorMap.at(instance))); 75 bus.call_noreply(method); 76 return; 77 } 78 79 // Handler called by Host control command handler to convey the 80 // status of the executed command 81 void Status::hostControlEvent(sdbusplus::message::message& msg) 82 { 83 using namespace phosphor::logging; 84 85 std::string cmdCompleted{}; 86 std::string cmdStatus{}; 87 88 msg.read(cmdCompleted, cmdStatus); 89 90 log<level::DEBUG>("Host control signal values", 91 entry("COMMAND=%s",cmdCompleted.c_str()), 92 entry("STATUS=%s",cmdStatus.c_str())); 93 94 if(Control::Host::convertResultFromString(cmdStatus) != 95 Control::Host::Result::Success) 96 { 97 if(Control::Host::convertCommandFromString(cmdCompleted) == 98 Control::Host::Command::OCCReset) 99 { 100 // Must be a Timeout. Log an Erorr trace 101 log<level::ERR>("Error resetting the OCC.", 102 entry("PATH=%s", path.c_str()), 103 entry("SensorID=0x%X",sensorMap.at(instance))); 104 } 105 } 106 return; 107 } 108 109 } // namespace occ 110 } // namespace open_power 111