Eddie James | fa1f5c0 | 2020-09-17 15:12:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Jeremy Kerr | 7f7c085 | 2024-08-08 11:32:55 +0800 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | |
| 5 | #include <optional> |
Eddie James | fa1f5c0 | 2020-09-17 15:12:46 -0500 | [diff] [blame] | 6 | #include <span> |
Jeremy Kerr | 8a76d89 | 2024-07-26 17:19:57 +0800 | [diff] [blame] | 7 | #include <string> |
Jeremy Kerr | 7f7c085 | 2024-08-08 11:32:55 +0800 | [diff] [blame] | 8 | #include <vector> |
Eddie James | fa1f5c0 | 2020-09-17 15:12:46 -0500 | [diff] [blame] | 9 | |
Ratan Gupta | bbe4579 | 2018-03-23 00:22:55 +0530 | [diff] [blame] | 10 | namespace phosphor |
| 11 | { |
| 12 | namespace network |
| 13 | { |
| 14 | namespace ncsi |
| 15 | { |
| 16 | |
Ratan Gupta | ed5d7ff | 2018-03-23 00:27:52 +0530 | [diff] [blame] | 17 | constexpr auto DEFAULT_VALUE = -1; |
| 18 | constexpr auto NONE = 0; |
Jeremy Kerr | b788524 | 2024-09-16 12:43:36 +0800 | [diff] [blame] | 19 | constexpr uint8_t CHANNEL_ID_NONE = 0x1f; |
Ratan Gupta | ed5d7ff | 2018-03-23 00:27:52 +0530 | [diff] [blame] | 20 | |
Jeremy Kerr | 7f7c085 | 2024-08-08 11:32:55 +0800 | [diff] [blame] | 21 | struct ChannelInfo |
| 22 | { |
| 23 | uint32_t id; |
| 24 | bool active; |
| 25 | bool forced; |
| 26 | uint32_t version_major, version_minor; |
| 27 | std::string version; |
| 28 | uint32_t link_state; |
| 29 | std::vector<uint16_t> vlan_ids; |
| 30 | }; |
| 31 | |
| 32 | struct PackageInfo |
| 33 | { |
| 34 | uint32_t id; |
| 35 | bool forced; |
| 36 | std::vector<ChannelInfo> channels; |
| 37 | }; |
| 38 | |
| 39 | struct InterfaceInfo |
| 40 | { |
| 41 | std::vector<PackageInfo> packages; |
| 42 | }; |
| 43 | |
Jeremy Kerr | b788524 | 2024-09-16 12:43:36 +0800 | [diff] [blame] | 44 | struct NCSICommand |
| 45 | { |
| 46 | /* constructs a message; the payload span is copied into the internal |
| 47 | * command vector */ |
| 48 | NCSICommand(uint8_t opcode, uint8_t package, std::optional<uint8_t> channel, |
| 49 | std::span<unsigned char> payload); |
| 50 | |
| 51 | uint8_t getChannel(); |
| 52 | |
| 53 | uint8_t opcode; |
| 54 | uint8_t package; |
| 55 | std::optional<uint8_t> channel; |
| 56 | std::vector<unsigned char> payload; |
| 57 | }; |
| 58 | |
| 59 | struct NCSIResponse |
| 60 | { |
| 61 | uint8_t opcode; |
| 62 | uint8_t response, reason; |
| 63 | std::span<unsigned char> payload; |
| 64 | std::vector<unsigned char> full_payload; |
| 65 | |
| 66 | /* Given an incoming response with full_payload set, check that we have |
| 67 | * enough data for a correct response, and populate the rest of the struct |
| 68 | * to suit |
| 69 | */ |
| 70 | int parseFullPayload(); |
| 71 | }; |
| 72 | |
Jeremy Kerr | 8d9af02 | 2024-07-26 16:47:16 +0800 | [diff] [blame] | 73 | struct Interface |
| 74 | { |
Jeremy Kerr | bc22f81 | 2024-07-29 17:43:35 +0800 | [diff] [blame] | 75 | /* @brief This function will ask underlying NCSI driver |
| 76 | * to send an OEM command (command type 0x50) with |
| 77 | * the specified payload as the OEM data. |
| 78 | * This function talks with the NCSI driver over |
| 79 | * netlink messages. |
| 80 | * @param[in] package - NCSI Package. |
| 81 | * @param[in] channel - Channel number with in the package. |
| 82 | * @param[in] opcode - NCSI Send Command sub-operation |
| 83 | * @param[in] payload - OEM data to send. |
Jeremy Kerr | 147086d | 2024-08-27 13:46:38 +0800 | [diff] [blame] | 84 | * @returns the NCSI response message to this command, or no value on error. |
Jeremy Kerr | bc22f81 | 2024-07-29 17:43:35 +0800 | [diff] [blame] | 85 | */ |
Jeremy Kerr | 2d0b48d | 2024-09-16 13:03:26 +0800 | [diff] [blame^] | 86 | virtual std::optional<NCSIResponse> sendCommand(NCSICommand& cmd) = 0; |
| 87 | |
| 88 | /** |
| 89 | * @brief Create a string representation of this interface |
| 90 | * |
| 91 | * @returns a string containing an interface identifier, for logging |
| 92 | */ |
| 93 | virtual std::string toString() = 0; |
| 94 | |
| 95 | /* virtual destructor for vtable */ |
| 96 | virtual ~Interface() {}; |
| 97 | }; |
| 98 | |
| 99 | std::string to_string(Interface& interface); |
| 100 | |
| 101 | struct NetlinkInterface : Interface |
| 102 | { |
| 103 | /* implementations for Interface */ |
Jeremy Kerr | b788524 | 2024-09-16 12:43:36 +0800 | [diff] [blame] | 104 | std::optional<NCSIResponse> sendCommand(NCSICommand& cmd); |
Jeremy Kerr | 2d0b48d | 2024-09-16 13:03:26 +0800 | [diff] [blame^] | 105 | std::string toString(); |
Jeremy Kerr | bc22f81 | 2024-07-29 17:43:35 +0800 | [diff] [blame] | 106 | |
| 107 | /* @brief This function will ask underlying NCSI driver |
| 108 | * to set a specific package or package/channel |
| 109 | * combination as the preferred choice. |
| 110 | * This function talks with the NCSI driver over |
| 111 | * netlink messages. |
| 112 | * @param[in] package - NCSI Package. |
| 113 | * @param[in] channel - Channel number with in the package. |
| 114 | * @returns 0 on success and negative value for failure. |
| 115 | */ |
| 116 | int setChannel(int package, int channel); |
| 117 | |
| 118 | /* @brief This function will ask underlying NCSI driver |
| 119 | * to clear any preferred setting from the interface. |
| 120 | * This function talks with the NCSI driver over |
| 121 | * netlink messages. |
| 122 | * @returns 0 on success and negative value for failure. |
| 123 | */ |
| 124 | int clearInterface(); |
| 125 | |
| 126 | /* @brief This function is used to dump all the info |
| 127 | * of the package and the channels underlying |
Jeremy Kerr | 7f7c085 | 2024-08-08 11:32:55 +0800 | [diff] [blame] | 128 | * the package, or all packages if DEFAULT_VALUE |
| 129 | * is passed |
| 130 | * @param[in] package - NCSI Package |
| 131 | * @returns an InterfaceInfo with package data the specified pacakge, |
| 132 | * or all packages if none is specified. |
Jeremy Kerr | bc22f81 | 2024-07-29 17:43:35 +0800 | [diff] [blame] | 133 | */ |
Jeremy Kerr | 7f7c085 | 2024-08-08 11:32:55 +0800 | [diff] [blame] | 134 | std::optional<InterfaceInfo> getInfo(int package); |
Jeremy Kerr | bc22f81 | 2024-07-29 17:43:35 +0800 | [diff] [blame] | 135 | |
| 136 | /* @brief This function assigns a mask controlling responses to AEN from a |
| 137 | * package. |
| 138 | * @param[in] mask - A 32-bit mask integer |
| 139 | * @returns 0 on success and negative value for failure. |
| 140 | */ |
| 141 | int setPackageMask(unsigned int mask); |
| 142 | |
| 143 | /* @brief This function sets the AEN mask for the channels inside the |
| 144 | * selected package. |
| 145 | * @param[in] package - NCSI Package. |
| 146 | * @param[in] mask - A 32-bit mask integer |
| 147 | * @returns 0 on success and negative value for failure. |
| 148 | */ |
| 149 | int setChannelMask(int package, unsigned int mask); |
| 150 | |
Jeremy Kerr | 2d0b48d | 2024-09-16 13:03:26 +0800 | [diff] [blame^] | 151 | NetlinkInterface(int ifindex); |
| 152 | |
Jeremy Kerr | 8d9af02 | 2024-07-26 16:47:16 +0800 | [diff] [blame] | 153 | int ifindex; |
| 154 | }; |
| 155 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 156 | } // namespace ncsi |
| 157 | } // namespace network |
| 158 | } // namespace phosphor |