1 /*
2 * Copyright (c) 2018 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * @brief Ethernet Management interface public header
10 */
11
12 #ifndef ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_
13 #define ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_
14
15 #include <zephyr/net/ethernet.h>
16 #include <zephyr/net/net_mgmt.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /**
23 * @brief Ethernet library
24 * @defgroup ethernet_mgmt Ethernet Library
25 * @ingroup networking
26 * @{
27 */
28
29 /** @cond INTERNAL_HIDDEN */
30
31 #define _NET_ETHERNET_LAYER NET_MGMT_LAYER_L2
32 #define _NET_ETHERNET_CODE 0x208
33 #define _NET_ETHERNET_BASE (NET_MGMT_IFACE_BIT | \
34 NET_MGMT_LAYER(_NET_ETHERNET_LAYER) | \
35 NET_MGMT_LAYER_CODE(_NET_ETHERNET_CODE))
36 #define _NET_ETHERNET_EVENT (_NET_ETHERNET_BASE | NET_MGMT_EVENT_BIT)
37
38 enum net_request_ethernet_cmd {
39 NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION = 1,
40 NET_REQUEST_ETHERNET_CMD_SET_LINK,
41 NET_REQUEST_ETHERNET_CMD_SET_DUPLEX,
42 NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS,
43 NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM,
44 NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM,
45 NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM,
46 NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM,
47 NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE,
48 NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM,
49 NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM,
50 NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM,
51 NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM,
52 NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM,
53 NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM,
54 };
55
56 #define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION \
57 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION)
58
59 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION);
60
61 #define NET_REQUEST_ETHERNET_SET_LINK \
62 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_LINK)
63
64 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_LINK);
65
66 #define NET_REQUEST_ETHERNET_SET_DUPLEX \
67 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_DUPLEX)
68
69 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_DUPLEX);
70
71 #define NET_REQUEST_ETHERNET_SET_MAC_ADDRESS \
72 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS)
73
74 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS);
75
76 #define NET_REQUEST_ETHERNET_SET_QAV_PARAM \
77 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM)
78
79 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QAV_PARAM);
80
81 #define NET_REQUEST_ETHERNET_GET_PORTS_NUM \
82 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM)
83
84 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PORTS_NUM);
85
86 #define NET_REQUEST_ETHERNET_SET_QBV_PARAM \
87 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM)
88
89 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBV_PARAM);
90
91 #define NET_REQUEST_ETHERNET_SET_QBU_PARAM \
92 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM)
93
94 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBU_PARAM);
95
96 #define NET_REQUEST_ETHERNET_SET_TXTIME_PARAM \
97 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM)
98
99 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXTIME_PARAM);
100
101 #define NET_REQUEST_ETHERNET_SET_PROMISC_MODE \
102 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE)
103
104 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE);
105
106 #define NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM \
107 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM)
108
109 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM);
110
111 #define NET_REQUEST_ETHERNET_GET_QAV_PARAM \
112 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM)
113
114 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QAV_PARAM);
115
116 #define NET_REQUEST_ETHERNET_GET_QBV_PARAM \
117 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM)
118
119 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBV_PARAM);
120
121 #define NET_REQUEST_ETHERNET_GET_QBU_PARAM \
122 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM)
123
124 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM);
125
126 #define NET_REQUEST_ETHERNET_GET_TXTIME_PARAM \
127 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM)
128
129 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM);
130
131 struct net_eth_addr;
132 struct ethernet_qav_param;
133 struct ethernet_qbv_param;
134 struct ethernet_qbu_param;
135 struct ethernet_txtime_param;
136
137 struct ethernet_req_params {
138 union {
139 bool auto_negotiation;
140 bool full_duplex;
141 bool promisc_mode;
142
143 struct {
144 bool link_10bt;
145 bool link_100bt;
146 bool link_1000bt;
147 } l;
148
149 struct net_eth_addr mac_address;
150
151 struct ethernet_qav_param qav_param;
152 struct ethernet_qbv_param qbv_param;
153 struct ethernet_qbu_param qbu_param;
154 struct ethernet_txtime_param txtime_param;
155
156 int priority_queues_num;
157 int ports_num;
158 };
159 };
160
161 enum net_event_ethernet_cmd {
162 NET_EVENT_ETHERNET_CMD_CARRIER_ON = 1,
163 NET_EVENT_ETHERNET_CMD_CARRIER_OFF,
164 NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED,
165 NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED,
166 };
167
168 #define NET_EVENT_ETHERNET_CARRIER_ON \
169 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_ON)
170
171 #define NET_EVENT_ETHERNET_CARRIER_OFF \
172 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_OFF)
173
174 #define NET_EVENT_ETHERNET_VLAN_TAG_ENABLED \
175 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED)
176
177 #define NET_EVENT_ETHERNET_VLAN_TAG_DISABLED \
178 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED)
179
180 struct net_if;
181
182 /** @endcond */
183
184 /**
185 * @brief Raise CARRIER_ON event when Ethernet is connected.
186 *
187 * @param iface Ethernet network interface.
188 */
189 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
190 void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface);
191 #else
ethernet_mgmt_raise_carrier_on_event(struct net_if * iface)192 static inline void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface)
193 {
194 ARG_UNUSED(iface);
195 }
196 #endif
197
198 /**
199 * @brief Raise CARRIER_OFF event when Ethernet is disconnected.
200 *
201 * @param iface Ethernet network interface.
202 */
203 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
204 void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface);
205 #else
ethernet_mgmt_raise_carrier_off_event(struct net_if * iface)206 static inline void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface)
207 {
208 ARG_UNUSED(iface);
209 }
210 #endif
211
212 /**
213 * @brief Raise VLAN_ENABLED event when VLAN is enabled.
214 *
215 * @param iface Ethernet network interface.
216 * @param tag VLAN tag which is enabled.
217 */
218 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
219 void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface, uint16_t tag);
220 #else
ethernet_mgmt_raise_vlan_enabled_event(struct net_if * iface,uint16_t tag)221 static inline void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface,
222 uint16_t tag)
223 {
224 ARG_UNUSED(iface);
225 ARG_UNUSED(tag);
226 }
227 #endif
228
229 /**
230 * @brief Raise VLAN_DISABLED event when VLAN is disabled.
231 *
232 * @param iface Ethernet network interface.
233 * @param tag VLAN tag which is disabled.
234 */
235 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
236 void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
237 uint16_t tag);
238 #else
ethernet_mgmt_raise_vlan_disabled_event(struct net_if * iface,uint16_t tag)239 static inline void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
240 uint16_t tag)
241 {
242 ARG_UNUSED(iface);
243 ARG_UNUSED(tag);
244 }
245 #endif
246
247 /**
248 * @}
249 */
250
251 #ifdef __cplusplus
252 }
253 #endif
254
255 #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_ */
256