blob: 0ca0df1306ec1f3423043fc76ff4ade85b346c95 [file] [log] [blame]
Eddie Jamesfa1f5c02020-09-17 15:12:46 -05001#pragma once
2
Jeremy Kerr7f7c0852024-08-08 11:32:55 +08003#include <stdint.h>
4
5#include <optional>
Eddie Jamesfa1f5c02020-09-17 15:12:46 -05006#include <span>
Jeremy Kerr8a76d892024-07-26 17:19:57 +08007#include <string>
Jeremy Kerr7f7c0852024-08-08 11:32:55 +08008#include <vector>
Eddie Jamesfa1f5c02020-09-17 15:12:46 -05009
Ratan Guptabbe45792018-03-23 00:22:55 +053010namespace phosphor
11{
12namespace network
13{
14namespace ncsi
15{
16
Ratan Guptaed5d7ff2018-03-23 00:27:52 +053017constexpr auto DEFAULT_VALUE = -1;
18constexpr auto NONE = 0;
Jeremy Kerrb7885242024-09-16 12:43:36 +080019constexpr uint8_t CHANNEL_ID_NONE = 0x1f;
Ratan Guptaed5d7ff2018-03-23 00:27:52 +053020
Jeremy Kerr7f7c0852024-08-08 11:32:55 +080021struct 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
32struct PackageInfo
33{
34 uint32_t id;
35 bool forced;
36 std::vector<ChannelInfo> channels;
37};
38
39struct InterfaceInfo
40{
41 std::vector<PackageInfo> packages;
42};
43
Jeremy Kerrb7885242024-09-16 12:43:36 +080044struct 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
59struct 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 Kerr8d9af022024-07-26 16:47:16 +080073struct Interface
74{
Jeremy Kerrbc22f812024-07-29 17:43:35 +080075 /* @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 Kerr147086d2024-08-27 13:46:38 +080084 * @returns the NCSI response message to this command, or no value on error.
Jeremy Kerrbc22f812024-07-29 17:43:35 +080085 */
Jeremy Kerrb7885242024-09-16 12:43:36 +080086 std::optional<NCSIResponse> sendCommand(NCSICommand& cmd);
Jeremy Kerrbc22f812024-07-29 17:43:35 +080087
88 /* @brief This function will ask underlying NCSI driver
89 * to set a specific package or package/channel
90 * combination as the preferred choice.
91 * This function talks with the NCSI driver over
92 * netlink messages.
93 * @param[in] package - NCSI Package.
94 * @param[in] channel - Channel number with in the package.
95 * @returns 0 on success and negative value for failure.
96 */
97 int setChannel(int package, int channel);
98
99 /* @brief This function will ask underlying NCSI driver
100 * to clear any preferred setting from the interface.
101 * This function talks with the NCSI driver over
102 * netlink messages.
103 * @returns 0 on success and negative value for failure.
104 */
105 int clearInterface();
106
107 /* @brief This function is used to dump all the info
108 * of the package and the channels underlying
Jeremy Kerr7f7c0852024-08-08 11:32:55 +0800109 * the package, or all packages if DEFAULT_VALUE
110 * is passed
111 * @param[in] package - NCSI Package
112 * @returns an InterfaceInfo with package data the specified pacakge,
113 * or all packages if none is specified.
Jeremy Kerrbc22f812024-07-29 17:43:35 +0800114 */
Jeremy Kerr7f7c0852024-08-08 11:32:55 +0800115 std::optional<InterfaceInfo> getInfo(int package);
Jeremy Kerrbc22f812024-07-29 17:43:35 +0800116
117 /* @brief This function assigns a mask controlling responses to AEN from a
118 * package.
119 * @param[in] mask - A 32-bit mask integer
120 * @returns 0 on success and negative value for failure.
121 */
122 int setPackageMask(unsigned int mask);
123
124 /* @brief This function sets the AEN mask for the channels inside the
125 * selected package.
126 * @param[in] package - NCSI Package.
127 * @param[in] mask - A 32-bit mask integer
128 * @returns 0 on success and negative value for failure.
129 */
130 int setChannelMask(int package, unsigned int mask);
131
Jeremy Kerr8d9af022024-07-26 16:47:16 +0800132 int ifindex;
133};
134
Jeremy Kerr8a76d892024-07-26 17:19:57 +0800135std::string to_string(Interface& interface);
136
Gunnar Mills57d9c502018-09-14 14:42:34 -0500137} // namespace ncsi
138} // namespace network
139} // namespace phosphor