Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 3 | #include <ipmid-host/cmd-utils.hpp> |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 4 | #include <sdbusplus/bus.hpp> |
Matt Spinler | 15309ef | 2018-06-27 13:01:25 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus/match.hpp> |
Vernon Mauery | 1181af7 | 2018-10-08 12:05:00 -0700 | [diff] [blame] | 6 | #include <sdbusplus/timer.hpp> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 7 | |
| 8 | #include <queue> |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 9 | #include <tuple> |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace host |
| 14 | { |
| 15 | namespace command |
| 16 | { |
| 17 | |
| 18 | /** @class |
| 19 | * @brief Manages commands that are to be sent to Host |
| 20 | */ |
| 21 | class Manager |
| 22 | { |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 23 | public: |
| 24 | Manager() = delete; |
| 25 | ~Manager() = default; |
| 26 | Manager(const Manager&) = delete; |
| 27 | Manager& operator=(const Manager&) = delete; |
| 28 | Manager(Manager&&) = delete; |
| 29 | Manager& operator=(Manager&&) = delete; |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 30 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 31 | /** @brief Constructs Manager object |
| 32 | * |
| 33 | * @param[in] bus - dbus handler |
| 34 | * @param[in] event - pointer to sd_event |
| 35 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 36 | explicit Manager(sdbusplus::bus_t& bus); |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 37 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 38 | /** @brief Extracts the next entry in the queue and returns |
| 39 | * Command and data part of it. |
| 40 | * |
| 41 | * @detail Also calls into the registered handlers so that they can now |
| 42 | * send the CommandComplete signal since the interface contract |
| 43 | * is that we emit this signal once the message has been |
| 44 | * passed to the host (which is required when calling this) |
| 45 | * |
| 46 | * Also, if the queue has more commands, then it will alert the |
| 47 | * host |
| 48 | */ |
| 49 | IpmiCmdData getNextCommand(); |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 50 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 51 | /** @brief Pushes the command onto the queue. |
| 52 | * |
| 53 | * @detail If the queue is empty, then it alerts the Host. If not, |
| 54 | * then it returns and the API documented above will handle |
| 55 | * the commands in Queue. |
| 56 | * |
| 57 | * @param[in] command - tuple of <IPMI command, data, callback> |
| 58 | */ |
| 59 | void execute(CommandHandler command); |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 60 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 61 | private: |
| 62 | /** @brief Check if anything in queue and alert host if so */ |
| 63 | void checkQueueAndAlertHost(); |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 64 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 65 | /** @brief Call back interface on message timeouts to host. |
| 66 | * |
| 67 | * @detail When this happens, a failure message would be sent |
| 68 | * to all the commands that are in the Queue and queue |
| 69 | * will be purged |
| 70 | */ |
| 71 | void hostTimeout(); |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 72 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 73 | /** @brief Clears the command queue |
| 74 | * |
| 75 | * @detail Clears the command queue and calls all callbacks |
| 76 | * specifying the command wasn't successful. |
| 77 | */ |
| 78 | void clearQueue(); |
Matt Spinler | 15309ef | 2018-06-27 13:01:25 -0500 | [diff] [blame] | 79 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 80 | /** @brief Clears the command queue on a power on |
| 81 | * |
| 82 | * @detail The properties changed handler for the |
| 83 | * RequestedHostTransition property. When this property |
| 84 | * changes to 'On', this function will purge the command |
| 85 | * queue. |
| 86 | * |
| 87 | * This is done to avoid having commands that were issued |
| 88 | * before the host powers on from getting sent to the host, |
| 89 | * either due to race conditions around state transitions |
| 90 | * or from a user doing something like requesting an already |
| 91 | * powered off system to power off again and then immediately |
| 92 | * requesting a power on. |
| 93 | * |
| 94 | * @param[in] msg - the sdbusplus message containing the property |
| 95 | */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 96 | void clearQueueOnPowerOn(sdbusplus::message_t& msg); |
Matt Spinler | 15309ef | 2018-06-27 13:01:25 -0500 | [diff] [blame] | 97 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 98 | /** @brief Reference to the dbus handler */ |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 99 | sdbusplus::bus_t& bus; |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 100 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 101 | /** @brief Queue to store the requested commands */ |
| 102 | std::queue<CommandHandler> workQueue{}; |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 103 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 104 | /** @brief Timer for commands to host */ |
Patrick Williams | 9565522 | 2023-12-05 12:45:02 -0600 | [diff] [blame] | 105 | sdbusplus::Timer timer; |
Matt Spinler | 15309ef | 2018-06-27 13:01:25 -0500 | [diff] [blame] | 106 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 107 | /** @brief Match handler for the requested host state */ |
| 108 | sdbusplus::bus::match_t hostTransitionMatch; |
Vishwanatha Subbanna | ac149a9 | 2017-07-11 18:16:50 +0530 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | } // namespace command |
| 112 | } // namespace host |
| 113 | } // namespace phosphor |