blob: 048bb7124393c9782d2a4c4ee1acb76e113410f3 [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;
19
Jeremy Kerr7f7c0852024-08-08 11:32:55 +080020struct ChannelInfo
21{
22 uint32_t id;
23 bool active;
24 bool forced;
25 uint32_t version_major, version_minor;
26 std::string version;
27 uint32_t link_state;
28 std::vector<uint16_t> vlan_ids;
29};
30
31struct PackageInfo
32{
33 uint32_t id;
34 bool forced;
35 std::vector<ChannelInfo> channels;
36};
37
38struct InterfaceInfo
39{
40 std::vector<PackageInfo> packages;
41};
42
Jeremy Kerr8d9af022024-07-26 16:47:16 +080043struct Interface
44{
Jeremy Kerr147086d2024-08-27 13:46:38 +080045 using ncsiMessage = std::span<const unsigned char>;
46
Jeremy Kerrbc22f812024-07-29 17:43:35 +080047 /* @brief This function will ask underlying NCSI driver
48 * to send an OEM command (command type 0x50) with
49 * the specified payload as the OEM data.
50 * This function talks with the NCSI driver over
51 * netlink messages.
52 * @param[in] package - NCSI Package.
53 * @param[in] channel - Channel number with in the package.
54 * @param[in] opcode - NCSI Send Command sub-operation
55 * @param[in] payload - OEM data to send.
Jeremy Kerr147086d2024-08-27 13:46:38 +080056 * @returns the NCSI response message to this command, or no value on error.
Jeremy Kerrbc22f812024-07-29 17:43:35 +080057 */
Jeremy Kerr147086d2024-08-27 13:46:38 +080058 std::optional<std::vector<unsigned char>> sendOemCommand(
59 int package, int channel, int opcode, ncsiMessage payload);
Jeremy Kerrbc22f812024-07-29 17:43:35 +080060
61 /* @brief This function will ask underlying NCSI driver
62 * to set a specific package or package/channel
63 * combination as the preferred choice.
64 * This function talks with the NCSI driver over
65 * netlink messages.
66 * @param[in] package - NCSI Package.
67 * @param[in] channel - Channel number with in the package.
68 * @returns 0 on success and negative value for failure.
69 */
70 int setChannel(int package, int channel);
71
72 /* @brief This function will ask underlying NCSI driver
73 * to clear any preferred setting from the interface.
74 * This function talks with the NCSI driver over
75 * netlink messages.
76 * @returns 0 on success and negative value for failure.
77 */
78 int clearInterface();
79
80 /* @brief This function is used to dump all the info
81 * of the package and the channels underlying
Jeremy Kerr7f7c0852024-08-08 11:32:55 +080082 * the package, or all packages if DEFAULT_VALUE
83 * is passed
84 * @param[in] package - NCSI Package
85 * @returns an InterfaceInfo with package data the specified pacakge,
86 * or all packages if none is specified.
Jeremy Kerrbc22f812024-07-29 17:43:35 +080087 */
Jeremy Kerr7f7c0852024-08-08 11:32:55 +080088 std::optional<InterfaceInfo> getInfo(int package);
Jeremy Kerrbc22f812024-07-29 17:43:35 +080089
90 /* @brief This function assigns a mask controlling responses to AEN from a
91 * package.
92 * @param[in] mask - A 32-bit mask integer
93 * @returns 0 on success and negative value for failure.
94 */
95 int setPackageMask(unsigned int mask);
96
97 /* @brief This function sets the AEN mask for the channels inside the
98 * selected package.
99 * @param[in] package - NCSI Package.
100 * @param[in] mask - A 32-bit mask integer
101 * @returns 0 on success and negative value for failure.
102 */
103 int setChannelMask(int package, unsigned int mask);
104
Jeremy Kerr8d9af022024-07-26 16:47:16 +0800105 int ifindex;
106};
107
Jeremy Kerr8a76d892024-07-26 17:19:57 +0800108std::string to_string(Interface& interface);
109
Gunnar Mills57d9c502018-09-14 14:42:34 -0500110} // namespace ncsi
111} // namespace network
112} // namespace phosphor