Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 1 | #pragma once |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 2 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 3 | #include "inband_code_update.hpp" |
| 4 | #include "libpldmresponder/oem_handler.hpp" |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 5 | #include "libpldmresponder/pdr_utils.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 6 | #include "libpldmresponder/platform.hpp" |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 7 | #include "requester/handler.hpp" |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 8 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 9 | #include <libpldm/entity.h> |
Andrew Jeffery | 21f128d | 2024-01-15 15:34:26 +1030 | [diff] [blame] | 10 | #include <libpldm/oem/ibm/state_set.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 11 | #include <libpldm/platform.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 12 | |
Christian Geddes | 7f9523c | 2021-08-03 13:44:38 -0500 | [diff] [blame] | 13 | typedef ibm_oem_pldm_state_set_firmware_update_state_values CodeUpdateState; |
| 14 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 15 | namespace pldm |
| 16 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 17 | namespace responder |
| 18 | { |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 19 | namespace oem_ibm_platform |
| 20 | { |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 21 | constexpr uint16_t ENTITY_INSTANCE_0 = 0; |
| 22 | constexpr uint16_t ENTITY_INSTANCE_1 = 1; |
| 23 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 24 | constexpr uint32_t BMC_PDR_START_RANGE = 0x00000000; |
| 25 | constexpr uint32_t BMC_PDR_END_RANGE = 0x00FFFFFF; |
| 26 | constexpr uint32_t HOST_PDR_START_RANGE = 0x01000000; |
| 27 | constexpr uint32_t HOST_PDR_END_RANGE = 0x01FFFFFF; |
| 28 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 29 | enum SetEventReceiverCount |
| 30 | { |
| 31 | SET_EVENT_RECEIVER_SENT = 0x2, |
| 32 | }; |
| 33 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 34 | class Handler : public oem_platform::Handler |
| 35 | { |
| 36 | public: |
| 37 | Handler(const pldm::utils::DBusHandler* dBusIntf, |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 38 | pldm::responder::CodeUpdate* codeUpdate, int mctp_fd, |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 39 | uint8_t mctp_eid, pldm::InstanceIdDb& instanceIdDb, |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 40 | sdeventplus::Event& event, |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 41 | pldm::requester::Handler<pldm::requester::Request>* handler) : |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 42 | oem_platform::Handler(dBusIntf), |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 43 | codeUpdate(codeUpdate), platformHandler(nullptr), mctp_fd(mctp_fd), |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 44 | mctp_eid(mctp_eid), instanceIdDb(instanceIdDb), event(event), |
| 45 | handler(handler) |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 46 | { |
| 47 | codeUpdate->setVersions(); |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 48 | setEventReceiverCnt = 0; |
| 49 | |
| 50 | using namespace sdbusplus::bus::match::rules; |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 51 | hostOffMatch = std::make_unique<sdbusplus::bus::match_t>( |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 52 | pldm::utils::DBusHandler::getBus(), |
| 53 | propertiesChanged("/xyz/openbmc_project/state/host0", |
| 54 | "xyz.openbmc_project.State.Host"), |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 55 | [this](sdbusplus::message_t& msg) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 56 | pldm::utils::DbusChangedProps props{}; |
| 57 | std::string intf; |
| 58 | msg.read(intf, props); |
| 59 | const auto itr = props.find("CurrentHostState"); |
| 60 | if (itr != props.end()) |
| 61 | { |
| 62 | pldm::utils::PropertyValue value = itr->second; |
| 63 | auto propVal = std::get<std::string>(value); |
| 64 | if (propVal == "xyz.openbmc_project.State.Host.HostState.Off") |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 65 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 66 | hostOff = true; |
| 67 | setEventReceiverCnt = 0; |
| 68 | disableWatchDogTimer(); |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 69 | } |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 70 | else if (propVal == |
| 71 | "xyz.openbmc_project.State.Host.HostState.Running") |
| 72 | { |
| 73 | hostOff = false; |
| 74 | } |
| 75 | } |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 76 | }); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int getOemStateSensorReadingsHandler( |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 80 | EntityType entityType, pldm::pdr::EntityInstance entityInstance, |
| 81 | pldm::pdr::StateSetId stateSetId, |
| 82 | pldm::pdr::CompositeCount compSensorCnt, |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 83 | std::vector<get_sensor_state_field>& stateField); |
| 84 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 85 | int oemSetStateEffecterStatesHandler( |
Varsha Kaverappa | 3fbd39e | 2020-09-28 01:40:22 -0500 | [diff] [blame] | 86 | uint16_t entityType, uint16_t entityInstance, uint16_t stateSetId, |
| 87 | uint8_t compEffecterCnt, |
| 88 | std::vector<set_effecter_state_field>& stateField, uint16_t effecterId); |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 89 | |
| 90 | /** @brief Method to set the platform handler in the |
| 91 | * oem_ibm_handler class |
| 92 | * @param[in] handler - pointer to PLDM platform handler |
| 93 | */ |
| 94 | void setPlatformHandler(pldm::responder::platform::Handler* handler); |
| 95 | |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 96 | /** @brief Method to fetch the effecter ID of the code update PDRs |
| 97 | * |
| 98 | * @return platformHandler->getNextEffecterId() - returns the |
| 99 | * effecter ID from the platform handler |
| 100 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 101 | virtual uint16_t getNextEffecterId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 102 | { |
| 103 | return platformHandler->getNextEffecterId(); |
| 104 | } |
| 105 | |
| 106 | /** @brief Method to fetch the sensor ID of the code update PDRs |
| 107 | * |
| 108 | * @return platformHandler->getNextSensorId() - returns the |
| 109 | * Sensor ID from the platform handler |
| 110 | */ |
Manojkiran Eda | 6b1d883 | 2021-03-27 11:25:06 +0530 | [diff] [blame] | 111 | virtual uint16_t getNextSensorId() |
Sagar Srinivas | 78a225a | 2020-08-27 00:52:20 -0500 | [diff] [blame] | 112 | { |
| 113 | return platformHandler->getNextSensorId(); |
| 114 | } |
| 115 | |
| 116 | /** @brief Method to Generate the OEM PDRs |
| 117 | * |
| 118 | * @param[in] repo - instance of concrete implementation of Repo |
| 119 | */ |
| 120 | void buildOEMPDR(pdr_utils::Repo& repo); |
| 121 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 122 | /** @brief Method to send code update event to host |
| 123 | * @param[in] sensorId - sendor ID |
| 124 | * @param[in] sensorEventClass - event class of sensor |
| 125 | * @param[in] sensorOffset - sensor offset |
| 126 | * @param[in] eventState - new code update event state |
| 127 | * @param[in] prevEventState - previous code update event state |
| 128 | * @return none |
| 129 | */ |
| 130 | void sendStateSensorEvent(uint16_t sensorId, |
| 131 | enum sensor_event_class_states sensorEventClass, |
| 132 | uint8_t sensorOffset, uint8_t eventState, |
| 133 | uint8_t prevEventState); |
| 134 | |
| 135 | /** @brief Method to send encoded request msg of code update event to host |
| 136 | * @param[in] requestMsg - encoded request msg |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 137 | * @param[in] instanceId - instance id of the message |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 138 | * @return PLDM status code |
| 139 | */ |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 140 | int sendEventToHost(std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 141 | |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 142 | /** @brief _processEndUpdate processes the actual work that needs |
| 143 | * to be carried out after EndUpdate effecter is set. This is done async |
| 144 | * after sending response for EndUpdate set effecter |
| 145 | * @param[in] source - sdeventplus event source |
| 146 | */ |
| 147 | void _processEndUpdate(sdeventplus::source::EventBase& source); |
| 148 | |
| 149 | /** @brief _processStartUpdate processes the actual work that needs |
| 150 | * to be carried out after StartUpdate effecter is set. This is done async |
| 151 | * after sending response for StartUpdate set effecter |
| 152 | * @param[in] source - sdeventplus event source |
| 153 | */ |
| 154 | void _processStartUpdate(sdeventplus::source::EventBase& source); |
| 155 | |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 156 | /** @brief _processSystemReboot processes the actual work that needs to be |
| 157 | * carried out after the System Power State effecter is set to reboot |
| 158 | * the system |
| 159 | * @param[in] source - sdeventplus event source |
| 160 | */ |
| 161 | void _processSystemReboot(sdeventplus::source::EventBase& source); |
| 162 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 163 | /*keeps track how many times setEventReceiver is sent */ |
| 164 | void countSetEventReceiver() |
| 165 | { |
| 166 | setEventReceiverCnt++; |
| 167 | } |
| 168 | |
| 169 | /* disables watchdog if running and Host is up */ |
| 170 | void checkAndDisableWatchDog(); |
| 171 | |
Sagar Srinivas | 79669c9 | 2021-04-28 15:43:30 -0500 | [diff] [blame] | 172 | /** @brief To check if the watchdog app is running |
| 173 | * |
| 174 | * @return the running status of watchdog app |
| 175 | */ |
| 176 | bool watchDogRunning(); |
| 177 | |
| 178 | /** @brief Method to reset the Watchdog timer on receiving platform Event |
| 179 | * Message for heartbeat elapsed time from Hostboot |
| 180 | */ |
| 181 | void resetWatchDogTimer(); |
| 182 | |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 183 | /** @brief To disable to the watchdog timer on host poweron completion*/ |
| 184 | void disableWatchDogTimer(); |
| 185 | |
Pavithra Barithaya | 99854a7 | 2021-09-29 06:58:11 -0500 | [diff] [blame] | 186 | /** @brief to check the BMC state*/ |
| 187 | int checkBMCState(); |
| 188 | |
Kamalkumar Patel | 15ce5a1 | 2024-05-07 11:45:11 -0500 | [diff] [blame^] | 189 | /** @brief update the dbus object paths */ |
| 190 | void updateOemDbusPaths(std::string& dbusPath); |
| 191 | |
Sagar Srinivas | 3687e2b | 2023-04-10 05:08:28 -0500 | [diff] [blame] | 192 | /** @brief Method to fetch the last BMC record from the PDR repo |
| 193 | * |
| 194 | * @param[in] repo - pointer to BMC's primary PDR repo |
| 195 | * |
| 196 | * @return the last BMC record from the repo |
| 197 | */ |
| 198 | const pldm_pdr_record* fetchLastBMCRecord(const pldm_pdr* repo); |
| 199 | |
| 200 | /** @brief Method to check if the record handle passed is in remote PDR |
| 201 | * record handle range |
| 202 | * |
| 203 | * @param[in] record_handle - record handle of the PDR |
| 204 | * |
| 205 | * @return true if record handle passed is in host PDR record handle range |
| 206 | */ |
| 207 | bool checkRecordHandleInRange(const uint32_t& record_handle); |
| 208 | |
Sagar Srinivas | 90314a3 | 2023-10-17 10:38:03 -0500 | [diff] [blame] | 209 | /** *brief Method to call the setEventReceiver command*/ |
| 210 | void processSetEventReceiver(); |
| 211 | |
| 212 | /** @brief Method to call the setEventReceiver through the platform |
| 213 | * handler |
| 214 | */ |
| 215 | virtual void setEventReceiver() |
| 216 | { |
| 217 | platformHandler->setEventReceiver(); |
| 218 | } |
| 219 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 220 | ~Handler() = default; |
| 221 | |
| 222 | pldm::responder::CodeUpdate* codeUpdate; //!< pointer to CodeUpdate object |
| 223 | pldm::responder::platform::Handler* |
| 224 | platformHandler; //!< pointer to PLDM platform handler |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 225 | |
| 226 | /** @brief fd of MCTP communications socket */ |
| 227 | int mctp_fd; |
| 228 | |
| 229 | /** @brief MCTP EID of host firmware */ |
| 230 | uint8_t mctp_eid; |
| 231 | |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 232 | /** @brief reference to an InstanceIdDb object, used to obtain a PLDM |
| 233 | * instance id. */ |
| 234 | pldm::InstanceIdDb& instanceIdDb; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 235 | /** @brief sdeventplus event source */ |
| 236 | std::unique_ptr<sdeventplus::source::Defer> assembleImageEvent; |
| 237 | std::unique_ptr<sdeventplus::source::Defer> startUpdateEvent; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 238 | std::unique_ptr<sdeventplus::source::Defer> systemRebootEvent; |
Sampa Misra | 3a0e3b9 | 2020-10-21 05:58:00 -0500 | [diff] [blame] | 239 | |
| 240 | /** @brief reference of main event loop of pldmd, primarily used to schedule |
| 241 | * work |
| 242 | */ |
| 243 | sdeventplus::Event& event; |
Sagar Srinivas | 9a64b4a | 2021-02-09 07:55:38 -0600 | [diff] [blame] | 244 | |
| 245 | private: |
| 246 | /** @brief D-Bus property changed signal match for CurrentPowerState*/ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 247 | std::unique_ptr<sdbusplus::bus::match_t> chassisOffMatch; |
Sampa Misra | c0c7948 | 2021-06-02 08:01:54 -0500 | [diff] [blame] | 248 | |
| 249 | /** @brief PLDM request handler */ |
| 250 | pldm::requester::Handler<pldm::requester::Request>* handler; |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 251 | |
| 252 | /** @brief D-Bus property changed signal match */ |
Patrick Williams | 84b790c | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 253 | std::unique_ptr<sdbusplus::bus::match_t> hostOffMatch; |
Sagar Srinivas | 7f760b3 | 2021-05-12 07:46:56 -0500 | [diff] [blame] | 254 | |
| 255 | bool hostOff = true; |
| 256 | |
| 257 | int setEventReceiverCnt = 0; |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 258 | }; |
| 259 | |
Varsha Kaverappa | bb585b2 | 2020-09-10 06:15:42 -0500 | [diff] [blame] | 260 | /** @brief Method to encode code update event msg |
| 261 | * @param[in] eventType - type of event |
| 262 | * @param[in] eventDataVec - vector of event data to be sent to host |
| 263 | * @param[in/out] requestMsg - request msg to be encoded |
| 264 | * @param[in] instanceId - instance ID |
| 265 | * @return PLDM status code |
| 266 | */ |
| 267 | int encodeEventMsg(uint8_t eventType, const std::vector<uint8_t>& eventDataVec, |
| 268 | std::vector<uint8_t>& requestMsg, uint8_t instanceId); |
| 269 | |
Sampa Misra | aea5dde | 2020-08-31 08:33:47 -0500 | [diff] [blame] | 270 | } // namespace oem_ibm_platform |
| 271 | |
| 272 | } // namespace responder |
| 273 | |
| 274 | } // namespace pldm |