1ac149a94SVishwanatha Subbanna #pragma once 2ac149a94SVishwanatha Subbanna 3194375f2SWilliam A. Kennington III #include <ipmid-host/cmd-utils.hpp> 4ac149a94SVishwanatha Subbanna #include <sdbusplus/bus.hpp> 515309efcSMatt Spinler #include <sdbusplus/bus/match.hpp> 61181af74SVernon Mauery #include <sdbusplus/timer.hpp> 7fbc6c9d7SPatrick Williams 8fbc6c9d7SPatrick Williams #include <queue> 90b02be92SPatrick Venture #include <tuple> 10ac149a94SVishwanatha Subbanna 11ac149a94SVishwanatha Subbanna namespace phosphor 12ac149a94SVishwanatha Subbanna { 13ac149a94SVishwanatha Subbanna namespace host 14ac149a94SVishwanatha Subbanna { 15ac149a94SVishwanatha Subbanna namespace command 16ac149a94SVishwanatha Subbanna { 17ac149a94SVishwanatha Subbanna 18ac149a94SVishwanatha Subbanna /** @class 19ac149a94SVishwanatha Subbanna * @brief Manages commands that are to be sent to Host 20ac149a94SVishwanatha Subbanna */ 21ac149a94SVishwanatha Subbanna class Manager 22ac149a94SVishwanatha Subbanna { 23ac149a94SVishwanatha Subbanna public: 24ac149a94SVishwanatha Subbanna Manager() = delete; 25ac149a94SVishwanatha Subbanna ~Manager() = default; 26ac149a94SVishwanatha Subbanna Manager(const Manager&) = delete; 27ac149a94SVishwanatha Subbanna Manager& operator=(const Manager&) = delete; 28ac149a94SVishwanatha Subbanna Manager(Manager&&) = delete; 29ac149a94SVishwanatha Subbanna Manager& operator=(Manager&&) = delete; 30ac149a94SVishwanatha Subbanna 31ac149a94SVishwanatha Subbanna /** @brief Constructs Manager object 32ac149a94SVishwanatha Subbanna * 33ac149a94SVishwanatha Subbanna * @param[in] bus - dbus handler 34ac149a94SVishwanatha Subbanna * @param[in] event - pointer to sd_event 35ac149a94SVishwanatha Subbanna */ 365d82f474SPatrick Williams explicit Manager(sdbusplus::bus_t& bus); 37ac149a94SVishwanatha Subbanna 38ac149a94SVishwanatha Subbanna /** @brief Extracts the next entry in the queue and returns 39ac149a94SVishwanatha Subbanna * Command and data part of it. 40ac149a94SVishwanatha Subbanna * 41ac149a94SVishwanatha Subbanna * @detail Also calls into the registered handlers so that they can now 42ac149a94SVishwanatha Subbanna * send the CommandComplete signal since the interface contract 43ac149a94SVishwanatha Subbanna * is that we emit this signal once the message has been 44ac149a94SVishwanatha Subbanna * passed to the host (which is required when calling this) 45ac149a94SVishwanatha Subbanna * 46ac149a94SVishwanatha Subbanna * Also, if the queue has more commands, then it will alert the 47ac149a94SVishwanatha Subbanna * host 48ac149a94SVishwanatha Subbanna */ 49ac149a94SVishwanatha Subbanna IpmiCmdData getNextCommand(); 50ac149a94SVishwanatha Subbanna 51ac149a94SVishwanatha Subbanna /** @brief Pushes the command onto the queue. 52ac149a94SVishwanatha Subbanna * 53ac149a94SVishwanatha Subbanna * @detail If the queue is empty, then it alerts the Host. If not, 54ac149a94SVishwanatha Subbanna * then it returns and the API documented above will handle 55ac149a94SVishwanatha Subbanna * the commands in Queue. 56ac149a94SVishwanatha Subbanna * 57ac149a94SVishwanatha Subbanna * @param[in] command - tuple of <IPMI command, data, callback> 58ac149a94SVishwanatha Subbanna */ 59ac149a94SVishwanatha Subbanna void execute(CommandHandler command); 60ac149a94SVishwanatha Subbanna 61ac149a94SVishwanatha Subbanna private: 62ac149a94SVishwanatha Subbanna /** @brief Check if anything in queue and alert host if so */ 63ac149a94SVishwanatha Subbanna void checkQueueAndAlertHost(); 64ac149a94SVishwanatha Subbanna 65ac149a94SVishwanatha Subbanna /** @brief Call back interface on message timeouts to host. 66ac149a94SVishwanatha Subbanna * 67ac149a94SVishwanatha Subbanna * @detail When this happens, a failure message would be sent 68ac149a94SVishwanatha Subbanna * to all the commands that are in the Queue and queue 69ac149a94SVishwanatha Subbanna * will be purged 70ac149a94SVishwanatha Subbanna */ 71ac149a94SVishwanatha Subbanna void hostTimeout(); 72ac149a94SVishwanatha Subbanna 7315309efcSMatt Spinler /** @brief Clears the command queue 7415309efcSMatt Spinler * 7515309efcSMatt Spinler * @detail Clears the command queue and calls all callbacks 7615309efcSMatt Spinler * specifying the command wasn't successful. 7715309efcSMatt Spinler */ 7815309efcSMatt Spinler void clearQueue(); 7915309efcSMatt Spinler 8015309efcSMatt Spinler /** @brief Clears the command queue on a power on 8115309efcSMatt Spinler * 8215309efcSMatt Spinler * @detail The properties changed handler for the 8315309efcSMatt Spinler * RequestedHostTransition property. When this property 8415309efcSMatt Spinler * changes to 'On', this function will purge the command 8515309efcSMatt Spinler * queue. 8615309efcSMatt Spinler * 8715309efcSMatt Spinler * This is done to avoid having commands that were issued 8815309efcSMatt Spinler * before the host powers on from getting sent to the host, 8915309efcSMatt Spinler * either due to race conditions around state transitions 9015309efcSMatt Spinler * or from a user doing something like requesting an already 9115309efcSMatt Spinler * powered off system to power off again and then immediately 9215309efcSMatt Spinler * requesting a power on. 9315309efcSMatt Spinler * 9415309efcSMatt Spinler * @param[in] msg - the sdbusplus message containing the property 9515309efcSMatt Spinler */ 965d82f474SPatrick Williams void clearQueueOnPowerOn(sdbusplus::message_t& msg); 9715309efcSMatt Spinler 98ac149a94SVishwanatha Subbanna /** @brief Reference to the dbus handler */ 995d82f474SPatrick Williams sdbusplus::bus_t& bus; 100ac149a94SVishwanatha Subbanna 101ac149a94SVishwanatha Subbanna /** @brief Queue to store the requested commands */ 102ac149a94SVishwanatha Subbanna std::queue<CommandHandler> workQueue{}; 103ac149a94SVishwanatha Subbanna 104ac149a94SVishwanatha Subbanna /** @brief Timer for commands to host */ 105*95655220SPatrick Williams sdbusplus::Timer timer; 10615309efcSMatt Spinler 10715309efcSMatt Spinler /** @brief Match handler for the requested host state */ 10815309efcSMatt Spinler sdbusplus::bus::match_t hostTransitionMatch; 109ac149a94SVishwanatha Subbanna }; 110ac149a94SVishwanatha Subbanna 111ac149a94SVishwanatha Subbanna } // namespace command 112ac149a94SVishwanatha Subbanna } // namespace host 113ac149a94SVishwanatha Subbanna } // namespace phosphor 114