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 * @since 1.12
26 * @version 0.8.0
27 * @ingroup networking
28 * @{
29 */
30
31 /** @cond INTERNAL_HIDDEN */
32
33 #define _NET_ETHERNET_LAYER NET_MGMT_LAYER_L2
34 #define _NET_ETHERNET_CODE 0x208
35 #define _NET_ETHERNET_BASE (NET_MGMT_IFACE_BIT | \
36 NET_MGMT_LAYER(_NET_ETHERNET_LAYER) | \
37 NET_MGMT_LAYER_CODE(_NET_ETHERNET_CODE))
38 #define _NET_ETHERNET_EVENT (_NET_ETHERNET_BASE | NET_MGMT_EVENT_BIT)
39
40 enum net_request_ethernet_cmd {
41 NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION = 1,
42 NET_REQUEST_ETHERNET_CMD_SET_LINK,
43 NET_REQUEST_ETHERNET_CMD_SET_DUPLEX,
44 NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS,
45 NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM,
46 NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM,
47 NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM,
48 NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM,
49 NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE,
50 NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM,
51 NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM,
52 NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM,
53 NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM,
54 NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM,
55 NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM,
56 NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM,
57 NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE,
58 NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE,
59 NET_REQUEST_ETHERNET_CMD_SET_MAC_FILTER,
60 };
61
62 #define NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION \
63 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_AUTO_NEGOTIATION)
64
65 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_AUTO_NEGOTIATION);
66
67 #define NET_REQUEST_ETHERNET_SET_LINK \
68 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_LINK)
69
70 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_LINK);
71
72 #define NET_REQUEST_ETHERNET_SET_DUPLEX \
73 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_DUPLEX)
74
75 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_DUPLEX);
76
77 #define NET_REQUEST_ETHERNET_SET_MAC_ADDRESS \
78 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_MAC_ADDRESS)
79
80 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS);
81
82 #define NET_REQUEST_ETHERNET_SET_QAV_PARAM \
83 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QAV_PARAM)
84
85 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QAV_PARAM);
86
87 #define NET_REQUEST_ETHERNET_GET_PORTS_NUM \
88 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PORTS_NUM)
89
90 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PORTS_NUM);
91
92 #define NET_REQUEST_ETHERNET_SET_QBV_PARAM \
93 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBV_PARAM)
94
95 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBV_PARAM);
96
97 #define NET_REQUEST_ETHERNET_SET_QBU_PARAM \
98 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_QBU_PARAM)
99
100 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_QBU_PARAM);
101
102 #define NET_REQUEST_ETHERNET_SET_TXTIME_PARAM \
103 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXTIME_PARAM)
104
105 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXTIME_PARAM);
106
107 #define NET_REQUEST_ETHERNET_SET_PROMISC_MODE \
108 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_PROMISC_MODE)
109
110 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_PROMISC_MODE);
111
112 #define NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM \
113 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_PRIORITY_QUEUES_NUM)
114
115 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_PRIORITY_QUEUES_NUM);
116
117 #define NET_REQUEST_ETHERNET_GET_QAV_PARAM \
118 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QAV_PARAM)
119
120 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QAV_PARAM);
121
122 #define NET_REQUEST_ETHERNET_GET_QBV_PARAM \
123 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBV_PARAM)
124
125 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBV_PARAM);
126
127 #define NET_REQUEST_ETHERNET_GET_QBU_PARAM \
128 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_QBU_PARAM)
129
130 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_QBU_PARAM);
131
132 #define NET_REQUEST_ETHERNET_GET_TXTIME_PARAM \
133 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXTIME_PARAM)
134
135 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXTIME_PARAM);
136
137 #define NET_REQUEST_ETHERNET_SET_T1S_PARAM \
138 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_T1S_PARAM)
139
140 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_T1S_PARAM);
141
142 #define NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE \
143 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_TXINJECTION_MODE)
144
145 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_TXINJECTION_MODE);
146
147 #define NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE \
148 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_GET_TXINJECTION_MODE)
149
150 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_GET_TXINJECTION_MODE);
151
152 #define NET_REQUEST_ETHERNET_SET_MAC_FILTER \
153 (_NET_ETHERNET_BASE | NET_REQUEST_ETHERNET_CMD_SET_MAC_FILTER)
154
155 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_ETHERNET_SET_MAC_FILTER);
156
157 struct net_eth_addr;
158 struct ethernet_qav_param;
159 struct ethernet_qbv_param;
160 struct ethernet_qbu_param;
161 struct ethernet_txtime_param;
162
163 struct ethernet_req_params {
164 union {
165 bool auto_negotiation;
166 bool full_duplex;
167 bool promisc_mode;
168 bool txinjection_mode;
169
170 struct {
171 bool link_10bt;
172 bool link_100bt;
173 bool link_1000bt;
174 } l;
175
176 struct net_eth_addr mac_address;
177
178 struct ethernet_qav_param qav_param;
179 struct ethernet_qbv_param qbv_param;
180 struct ethernet_qbu_param qbu_param;
181 struct ethernet_txtime_param txtime_param;
182 struct ethernet_t1s_param t1s_param;
183
184 struct ethernet_filter filter;
185
186 int priority_queues_num;
187 int ports_num;
188 };
189 };
190
191 enum net_event_ethernet_cmd {
192 NET_EVENT_ETHERNET_CMD_CARRIER_ON = 1,
193 NET_EVENT_ETHERNET_CMD_CARRIER_OFF,
194 NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED,
195 NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED,
196 };
197
198 #define NET_EVENT_ETHERNET_CARRIER_ON \
199 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_ON)
200
201 #define NET_EVENT_ETHERNET_CARRIER_OFF \
202 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_CARRIER_OFF)
203
204 #define NET_EVENT_ETHERNET_VLAN_TAG_ENABLED \
205 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_ENABLED)
206
207 #define NET_EVENT_ETHERNET_VLAN_TAG_DISABLED \
208 (_NET_ETHERNET_EVENT | NET_EVENT_ETHERNET_CMD_VLAN_TAG_DISABLED)
209
210 struct net_if;
211
212 /** @endcond */
213
214 /**
215 * @brief Raise CARRIER_ON event when Ethernet is connected.
216 *
217 * @param iface Ethernet network interface.
218 */
219 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
220 void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface);
221 #else
ethernet_mgmt_raise_carrier_on_event(struct net_if * iface)222 static inline void ethernet_mgmt_raise_carrier_on_event(struct net_if *iface)
223 {
224 ARG_UNUSED(iface);
225 }
226 #endif
227
228 /**
229 * @brief Raise CARRIER_OFF event when Ethernet is disconnected.
230 *
231 * @param iface Ethernet network interface.
232 */
233 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
234 void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface);
235 #else
ethernet_mgmt_raise_carrier_off_event(struct net_if * iface)236 static inline void ethernet_mgmt_raise_carrier_off_event(struct net_if *iface)
237 {
238 ARG_UNUSED(iface);
239 }
240 #endif
241
242 /**
243 * @brief Raise VLAN_ENABLED event when VLAN is enabled.
244 *
245 * @param iface Ethernet network interface.
246 * @param tag VLAN tag which is enabled.
247 */
248 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
249 void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface, uint16_t tag);
250 #else
ethernet_mgmt_raise_vlan_enabled_event(struct net_if * iface,uint16_t tag)251 static inline void ethernet_mgmt_raise_vlan_enabled_event(struct net_if *iface,
252 uint16_t tag)
253 {
254 ARG_UNUSED(iface);
255 ARG_UNUSED(tag);
256 }
257 #endif
258
259 /**
260 * @brief Raise VLAN_DISABLED event when VLAN is disabled.
261 *
262 * @param iface Ethernet network interface.
263 * @param tag VLAN tag which is disabled.
264 */
265 #if defined(CONFIG_NET_L2_ETHERNET_MGMT)
266 void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
267 uint16_t tag);
268 #else
ethernet_mgmt_raise_vlan_disabled_event(struct net_if * iface,uint16_t tag)269 static inline void ethernet_mgmt_raise_vlan_disabled_event(struct net_if *iface,
270 uint16_t tag)
271 {
272 ARG_UNUSED(iface);
273 ARG_UNUSED(tag);
274 }
275 #endif
276
277 /**
278 * @}
279 */
280
281 #ifdef __cplusplus
282 }
283 #endif
284
285 #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_MGMT_H_ */
286