Line data Source code
1 1 : /** @file
2 : @brief Ethernet
3 :
4 : This is not to be included by the application.
5 : */
6 :
7 : /*
8 : * Copyright (c) 2016 Intel Corporation
9 : *
10 : * SPDX-License-Identifier: Apache-2.0
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_NET_ETHERNET_H_
14 : #define ZEPHYR_INCLUDE_NET_ETHERNET_H_
15 :
16 : #include <zephyr/kernel.h>
17 : #include <zephyr/types.h>
18 : #include <stdbool.h>
19 : #include <zephyr/sys/atomic.h>
20 :
21 : #include <zephyr/net/net_ip.h>
22 : #include <zephyr/net/net_pkt.h>
23 : #include <zephyr/net/lldp.h>
24 : #include <zephyr/sys/util.h>
25 : #include <zephyr/net/net_if.h>
26 : #include <zephyr/net/ethernet_vlan.h>
27 : #include <zephyr/net/ptp_time.h>
28 :
29 : #if defined(CONFIG_NET_DSA_DEPRECATED)
30 : #include <zephyr/net/dsa.h>
31 : #endif
32 :
33 : #if defined(CONFIG_NET_ETHERNET_BRIDGE)
34 : #include <zephyr/net/ethernet_bridge.h>
35 : #endif
36 :
37 : #ifdef __cplusplus
38 : extern "C" {
39 : #endif
40 :
41 : /**
42 : * @brief Ethernet support functions
43 : * @defgroup ethernet Ethernet Support Functions
44 : * @since 1.0
45 : * @version 0.8.0
46 : * @ingroup networking
47 : * @{
48 : */
49 :
50 1 : #define NET_ETH_ADDR_LEN 6U /**< Ethernet MAC address length */
51 :
52 : /** Ethernet address */
53 1 : struct net_eth_addr {
54 1 : uint8_t addr[NET_ETH_ADDR_LEN]; /**< Buffer storing the address */
55 : };
56 :
57 : /** @cond INTERNAL_HIDDEN */
58 :
59 : #define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
60 :
61 : /* zephyr-keep-sorted-start */
62 : #define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
63 : #define NET_ETH_PTYPE_ARP 0x0806
64 : #define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
65 : #define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
66 : #define NET_ETH_PTYPE_EAPOL 0x888e
67 : #define NET_ETH_PTYPE_ECAT 0x88a4
68 : #define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
69 : #define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
70 : #define NET_ETH_PTYPE_IP 0x0800
71 : #define NET_ETH_PTYPE_IPV6 0x86dd
72 : #define NET_ETH_PTYPE_LLDP 0x88cc
73 : #define NET_ETH_PTYPE_PTP 0x88f7
74 : #define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
75 : #define NET_ETH_PTYPE_VLAN 0x8100
76 : /* zephyr-keep-sorted-stop */
77 :
78 : /* zephyr-keep-sorted-start re(^#define) */
79 : #if !defined(ETH_P_8021Q)
80 : #define ETH_P_8021Q NET_ETH_PTYPE_VLAN
81 : #endif
82 : #if !defined(ETH_P_ALL)
83 : #define ETH_P_ALL NET_ETH_PTYPE_ALL
84 : #endif
85 : #if !defined(ETH_P_ARP)
86 : #define ETH_P_ARP NET_ETH_PTYPE_ARP
87 : #endif
88 : #if !defined(ETH_P_CAN)
89 : #define ETH_P_CAN NET_ETH_PTYPE_CAN
90 : #endif
91 : #if !defined(ETH_P_CANFD)
92 : #define ETH_P_CANFD NET_ETH_PTYPE_CANFD
93 : #endif
94 : #if !defined(ETH_P_EAPOL)
95 : #define ETH_P_EAPOL NET_ETH_PTYPE_EAPOL
96 : #endif
97 : #if !defined(ETH_P_ECAT)
98 : #define ETH_P_ECAT NET_ETH_PTYPE_ECAT
99 : #endif
100 : #if !defined(ETH_P_HDLC)
101 : #define ETH_P_HDLC NET_ETH_PTYPE_HDLC
102 : #endif
103 : #if !defined(ETH_P_IEEE802154)
104 : #define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
105 : #endif
106 : #if !defined(ETH_P_IP)
107 : #define ETH_P_IP NET_ETH_PTYPE_IP
108 : #endif
109 : #if !defined(ETH_P_IPV6)
110 : #define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
111 : #endif
112 : #if !defined(ETH_P_TSN)
113 : #define ETH_P_TSN NET_ETH_PTYPE_TSN
114 : #endif
115 : /* zephyr-keep-sorted-stop */
116 :
117 : /** @endcond */
118 :
119 1 : #define NET_ETH_MINIMAL_FRAME_SIZE 60 /**< Minimum Ethernet frame size */
120 1 : #define NET_ETH_MTU 1500 /**< Ethernet MTU size */
121 :
122 : /** @cond INTERNAL_HIDDEN */
123 :
124 : #if defined(CONFIG_NET_VLAN)
125 : #define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_vlan_hdr))
126 : #else
127 : #define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
128 : #endif
129 :
130 : #define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + _NET_ETH_MAX_HDR_SIZE)
131 :
132 : #if defined(CONFIG_DSA_TAG_SIZE)
133 : #define DSA_TAG_SIZE CONFIG_DSA_TAG_SIZE
134 : #else
135 : #define DSA_TAG_SIZE 0
136 : #endif
137 :
138 : #define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
139 : #define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
140 :
141 : #define NET_ETH_VLAN_HDR_SIZE 4
142 :
143 : /** @endcond */
144 :
145 : /** @brief Ethernet hardware capabilities */
146 1 : enum ethernet_hw_caps {
147 : /** TX Checksum offloading supported for all of IPv4, UDP, TCP */
148 : ETHERNET_HW_TX_CHKSUM_OFFLOAD = BIT(0),
149 :
150 : /** RX Checksum offloading supported for all of IPv4, UDP, TCP */
151 : ETHERNET_HW_RX_CHKSUM_OFFLOAD = BIT(1),
152 :
153 : /** VLAN supported */
154 : ETHERNET_HW_VLAN = BIT(2),
155 :
156 : /** 10 Mbits link supported */
157 : ETHERNET_LINK_10BASE = BIT(3),
158 :
159 : /** 100 Mbits link supported */
160 : ETHERNET_LINK_100BASE = BIT(4),
161 :
162 : /** 1 Gbits link supported */
163 : ETHERNET_LINK_1000BASE = BIT(5),
164 :
165 : /** 2.5 Gbits link supported */
166 : ETHERNET_LINK_2500BASE = BIT(6),
167 :
168 : /** 5 Gbits link supported */
169 : ETHERNET_LINK_5000BASE = BIT(7),
170 :
171 : /** IEEE 802.1AS (gPTP) clock supported */
172 : ETHERNET_PTP = BIT(8),
173 :
174 : /** IEEE 802.1Qav (credit-based shaping) supported */
175 : ETHERNET_QAV = BIT(9),
176 :
177 : /** Promiscuous mode supported */
178 : ETHERNET_PROMISC_MODE = BIT(10),
179 :
180 : /** Priority queues available */
181 : ETHERNET_PRIORITY_QUEUES = BIT(11),
182 :
183 : /** MAC address filtering supported */
184 : ETHERNET_HW_FILTERING = BIT(12),
185 :
186 : /** Link Layer Discovery Protocol supported */
187 : ETHERNET_LLDP = BIT(13),
188 :
189 : /** VLAN Tag stripping */
190 : ETHERNET_HW_VLAN_TAG_STRIP = BIT(14),
191 :
192 : /** DSA switch user port */
193 : ETHERNET_DSA_USER_PORT = BIT(15),
194 :
195 : /** DSA switch conduit port */
196 : ETHERNET_DSA_CONDUIT_PORT = BIT(16),
197 :
198 : /** IEEE 802.1Qbv (scheduled traffic) supported */
199 : ETHERNET_QBV = BIT(17),
200 :
201 : /** IEEE 802.1Qbu (frame preemption) supported */
202 : ETHERNET_QBU = BIT(18),
203 :
204 : /** TXTIME supported */
205 : ETHERNET_TXTIME = BIT(19),
206 :
207 : /** TX-Injection supported */
208 : ETHERNET_TXINJECTION_MODE = BIT(20),
209 : };
210 :
211 : /** @cond INTERNAL_HIDDEN */
212 :
213 : #if !defined(CONFIG_NET_DSA_DEPRECATED)
214 : enum dsa_port_type {
215 : NON_DSA_PORT,
216 : DSA_CONDUIT_PORT,
217 : DSA_USER_PORT,
218 : DSA_CPU_PORT,
219 : DSA_PORT,
220 : };
221 : #endif
222 :
223 : enum ethernet_config_type {
224 : ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
225 : ETHERNET_CONFIG_TYPE_QAV_PARAM,
226 : ETHERNET_CONFIG_TYPE_QBV_PARAM,
227 : ETHERNET_CONFIG_TYPE_QBU_PARAM,
228 : ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
229 : ETHERNET_CONFIG_TYPE_PROMISC_MODE,
230 : ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
231 : ETHERNET_CONFIG_TYPE_FILTER,
232 : ETHERNET_CONFIG_TYPE_PORTS_NUM,
233 : ETHERNET_CONFIG_TYPE_T1S_PARAM,
234 : ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
235 : ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
236 : ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
237 : ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
238 : };
239 :
240 : enum ethernet_qav_param_type {
241 : ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
242 : ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
243 : ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
244 : ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
245 : ETHERNET_QAV_PARAM_TYPE_STATUS,
246 : };
247 :
248 : enum ethernet_t1s_param_type {
249 : ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
250 : };
251 :
252 : /** @endcond */
253 :
254 : /** Ethernet T1S specific parameters */
255 1 : struct ethernet_t1s_param {
256 : /** Type of T1S parameter */
257 1 : enum ethernet_t1s_param_type type;
258 : union {
259 : /**
260 : * PLCA is the Physical Layer (PHY) Collision
261 : * Avoidance technique employed with multidrop
262 : * 10Base-T1S standard.
263 : *
264 : * The PLCA parameters are described in standard [1]
265 : * as registers in memory map 4 (MMS = 4) (point 9.6).
266 : *
267 : * IDVER (PLCA ID Version)
268 : * CTRL0 (PLCA Control 0)
269 : * CTRL1 (PLCA Control 1)
270 : * STATUS (PLCA Status)
271 : * TOTMR (PLCA TO Control)
272 : * BURST (PLCA Burst Control)
273 : *
274 : * Those registers are implemented by each OA TC6
275 : * compliant vendor (like for e.g. LAN865x - e.g. [2]).
276 : *
277 : * Documents:
278 : * [1] - "OPEN Alliance 10BASE-T1x MAC-PHY Serial
279 : * Interface" (ver. 1.1)
280 : * [2] - "DS60001734C" - LAN865x data sheet
281 : */
282 : struct {
283 : /** T1S PLCA enabled */
284 1 : bool enable;
285 : /** T1S PLCA node id range: 0 to 254 */
286 1 : uint8_t node_id;
287 : /** T1S PLCA node count range: 1 to 255 */
288 1 : uint8_t node_count;
289 : /** T1S PLCA burst count range: 0x0 to 0xFF */
290 1 : uint8_t burst_count;
291 : /** T1S PLCA burst timer */
292 1 : uint8_t burst_timer;
293 : /** T1S PLCA TO value */
294 1 : uint8_t to_timer;
295 1 : } plca;
296 0 : };
297 : };
298 :
299 : /** Ethernet Qav specific parameters */
300 1 : struct ethernet_qav_param {
301 : /** ID of the priority queue to use */
302 1 : int queue_id;
303 : /** Type of Qav parameter */
304 1 : enum ethernet_qav_param_type type;
305 : union {
306 : /** True if Qav is enabled for queue */
307 1 : bool enabled;
308 : /** Delta Bandwidth (percentage of bandwidth) */
309 1 : unsigned int delta_bandwidth;
310 : /** Idle Slope (bits per second) */
311 1 : unsigned int idle_slope;
312 : /** Oper Idle Slope (bits per second) */
313 1 : unsigned int oper_idle_slope;
314 : /** Traffic class the queue is bound to */
315 1 : unsigned int traffic_class;
316 0 : };
317 : };
318 :
319 : /** @cond INTERNAL_HIDDEN */
320 :
321 : enum ethernet_qbv_param_type {
322 : ETHERNET_QBV_PARAM_TYPE_STATUS,
323 : ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
324 : ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
325 : ETHERNET_QBV_PARAM_TYPE_TIME,
326 : };
327 :
328 : enum ethernet_qbv_state_type {
329 : ETHERNET_QBV_STATE_TYPE_ADMIN,
330 : ETHERNET_QBV_STATE_TYPE_OPER,
331 : };
332 :
333 : enum ethernet_gate_state_operation {
334 : ETHERNET_SET_GATE_STATE,
335 : ETHERNET_SET_AND_HOLD_MAC_STATE,
336 : ETHERNET_SET_AND_RELEASE_MAC_STATE,
337 : };
338 :
339 : /** @endcond */
340 :
341 : /** Ethernet Qbv specific parameters */
342 1 : struct ethernet_qbv_param {
343 : /** Port id */
344 1 : int port_id;
345 : /** Type of Qbv parameter */
346 1 : enum ethernet_qbv_param_type type;
347 : /** What state (Admin/Oper) parameters are these */
348 1 : enum ethernet_qbv_state_type state;
349 : union {
350 : /** True if Qbv is enabled or not */
351 1 : bool enabled;
352 :
353 : /** Gate control information */
354 : struct {
355 : /** True = open, False = closed */
356 1 : bool gate_status[NET_TC_TX_COUNT];
357 :
358 : /** GateState operation */
359 1 : enum ethernet_gate_state_operation operation;
360 :
361 : /** Time interval ticks (nanoseconds) */
362 1 : uint32_t time_interval;
363 :
364 : /** Gate control list row */
365 1 : uint16_t row;
366 1 : } gate_control;
367 :
368 : /** Number of entries in gate control list */
369 1 : uint32_t gate_control_list_len;
370 :
371 : /**
372 : * The time values are set in one go when type is set to
373 : * ETHERNET_QBV_PARAM_TYPE_TIME
374 : */
375 : struct {
376 : /** Base time */
377 1 : struct net_ptp_extended_time base_time;
378 :
379 : /** Cycle time */
380 1 : struct net_ptp_time cycle_time;
381 :
382 : /** Extension time (nanoseconds) */
383 1 : uint32_t extension_time;
384 : };
385 0 : };
386 : };
387 :
388 : /** @cond INTERNAL_HIDDEN */
389 :
390 : enum ethernet_qbu_param_type {
391 : ETHERNET_QBU_PARAM_TYPE_STATUS,
392 : ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
393 : ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
394 : ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
395 :
396 : /* Some preemption settings are from Qbr spec. */
397 : ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
398 : ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
399 : };
400 :
401 : enum ethernet_qbu_preempt_status {
402 : ETHERNET_QBU_STATUS_EXPRESS,
403 : ETHERNET_QBU_STATUS_PREEMPTABLE
404 : } __packed;
405 :
406 : /** @endcond */
407 :
408 : /** Ethernet Qbu specific parameters */
409 1 : struct ethernet_qbu_param {
410 : /** Port id */
411 1 : int port_id;
412 : /** Type of Qbu parameter */
413 1 : enum ethernet_qbu_param_type type;
414 : union {
415 : /** Hold advance (nanoseconds) */
416 1 : uint32_t hold_advance;
417 :
418 : /** Release advance (nanoseconds) */
419 1 : uint32_t release_advance;
420 :
421 : /** sequence of framePreemptionAdminStatus values */
422 : enum ethernet_qbu_preempt_status
423 1 : frame_preempt_statuses[NET_TC_TX_COUNT];
424 :
425 : /** True if Qbu is enabled or not */
426 1 : bool enabled;
427 :
428 : /** Link partner status (from Qbr) */
429 1 : bool link_partner_status;
430 :
431 : /**
432 : * Additional fragment size (from Qbr). The minimum non-final
433 : * fragment size is (additional_fragment_size + 1) * 64 octets
434 : */
435 1 : uint8_t additional_fragment_size : 2;
436 0 : };
437 : };
438 :
439 : /** @cond INTERNAL_HIDDEN */
440 :
441 : enum ethernet_filter_type {
442 : ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
443 : ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
444 : };
445 :
446 : /** @endcond */
447 :
448 : /** Types of Ethernet L2 */
449 1 : enum ethernet_if_types {
450 : /** IEEE 802.3 Ethernet (default) */
451 : L2_ETH_IF_TYPE_ETHERNET,
452 :
453 : /** IEEE 802.11 Wi-Fi*/
454 : L2_ETH_IF_TYPE_WIFI,
455 : } __packed;
456 :
457 : /** Ethernet filter description */
458 1 : struct ethernet_filter {
459 : /** Type of filter */
460 1 : enum ethernet_filter_type type;
461 : /** MAC address to filter */
462 1 : struct net_eth_addr mac_address;
463 : /** Set (true) or unset (false) the filter */
464 1 : bool set;
465 : };
466 :
467 : /** @cond INTERNAL_HIDDEN */
468 :
469 : enum ethernet_txtime_param_type {
470 : ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
471 : };
472 :
473 : /** @endcond */
474 :
475 : /** Ethernet TXTIME specific parameters */
476 1 : struct ethernet_txtime_param {
477 : /** Type of TXTIME parameter */
478 1 : enum ethernet_txtime_param_type type;
479 : /** Queue number for configuring TXTIME */
480 1 : int queue_id;
481 : /** Enable or disable TXTIME per queue */
482 1 : bool enable_txtime;
483 : };
484 :
485 : /** Protocols that are supported by checksum offloading */
486 1 : enum ethernet_checksum_support {
487 : /** Device does not support any L3/L4 checksum offloading */
488 : ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
489 : /** Device supports checksum offloading for the IPv4 header */
490 : ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
491 : /** Device supports checksum offloading for ICMPv4 payload (implies IPv4 header) */
492 : ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
493 : /** Device supports checksum offloading for the IPv6 header */
494 : ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
495 : /** Device supports checksum offloading for ICMPv6 payload (implies IPv6 header) */
496 : ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
497 : /** Device supports TCP checksum offloading for all supported IP protocols */
498 : ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
499 : /** Device supports UDP checksum offloading for all supported IP protocols */
500 : ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
501 : };
502 :
503 : /** @cond INTERNAL_HIDDEN */
504 :
505 : struct ethernet_config {
506 : union {
507 : bool promisc_mode;
508 : bool txinjection_mode;
509 :
510 : struct net_eth_addr mac_address;
511 :
512 : struct ethernet_t1s_param t1s_param;
513 : struct ethernet_qav_param qav_param;
514 : struct ethernet_qbv_param qbv_param;
515 : struct ethernet_qbu_param qbu_param;
516 : struct ethernet_txtime_param txtime_param;
517 :
518 : int priority_queues_num;
519 : int ports_num;
520 :
521 : enum ethernet_checksum_support chksum_support;
522 :
523 : struct ethernet_filter filter;
524 :
525 : uint16_t extra_tx_pkt_headroom;
526 : };
527 : };
528 :
529 : /** @endcond */
530 :
531 : /** Ethernet L2 API operations. */
532 1 : struct ethernet_api {
533 : /**
534 : * The net_if_api must be placed in first position in this
535 : * struct so that we are compatible with network interface API.
536 : */
537 1 : struct net_if_api iface_api;
538 :
539 : /** Collect optional ethernet specific statistics. This pointer
540 : * should be set by driver if statistics needs to be collected
541 : * for that driver.
542 : */
543 : #if defined(CONFIG_NET_STATISTICS_ETHERNET)
544 : struct net_stats_eth *(*get_stats)(const struct device *dev);
545 : #endif
546 :
547 : /** Start the device */
548 1 : int (*start)(const struct device *dev);
549 :
550 : /** Stop the device */
551 1 : int (*stop)(const struct device *dev);
552 :
553 : /** Get the device capabilities */
554 : enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
555 :
556 : /** Set specific hardware configuration */
557 1 : int (*set_config)(const struct device *dev,
558 : enum ethernet_config_type type,
559 : const struct ethernet_config *config);
560 :
561 : /** Get hardware specific configuration */
562 1 : int (*get_config)(const struct device *dev,
563 : enum ethernet_config_type type,
564 : struct ethernet_config *config);
565 :
566 : /** The IP stack will call this function when a VLAN tag is enabled
567 : * or disabled. If enable is set to true, then the VLAN tag was added,
568 : * if it is false then the tag was removed. The driver can utilize
569 : * this information if needed.
570 : */
571 : #if defined(CONFIG_NET_VLAN)
572 : int (*vlan_setup)(const struct device *dev, struct net_if *iface,
573 : uint16_t tag, bool enable);
574 : #endif /* CONFIG_NET_VLAN */
575 :
576 : /** Return ptp_clock device that is tied to this ethernet device */
577 : #if defined(CONFIG_PTP_CLOCK)
578 : const struct device *(*get_ptp_clock)(const struct device *dev);
579 : #endif /* CONFIG_PTP_CLOCK */
580 :
581 : /** Return PHY device that is tied to this ethernet device */
582 : const struct device *(*get_phy)(const struct device *dev);
583 :
584 : /** Send a network packet */
585 1 : int (*send)(const struct device *dev, struct net_pkt *pkt);
586 : };
587 :
588 : /** @cond INTERNAL_HIDDEN */
589 :
590 : /* Make sure that the network interface API is properly setup inside
591 : * Ethernet API struct (it is the first one).
592 : */
593 : BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
594 :
595 : struct net_eth_hdr {
596 : struct net_eth_addr dst;
597 : struct net_eth_addr src;
598 : uint16_t type;
599 : } __packed;
600 :
601 : struct ethernet_vlan {
602 : /** Network interface that has VLAN enabled */
603 : struct net_if *iface;
604 :
605 : /** VLAN tag */
606 : uint16_t tag;
607 : };
608 :
609 : #if defined(CONFIG_NET_VLAN_COUNT)
610 : #define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
611 : #else
612 : #define NET_VLAN_MAX_COUNT 0
613 : #endif
614 :
615 : /** @endcond */
616 :
617 : /** Ethernet LLDP specific parameters */
618 1 : struct ethernet_lldp {
619 : /** Used for track timers */
620 1 : sys_snode_t node;
621 :
622 : /** LLDP Data Unit mandatory TLVs for the interface. */
623 1 : const struct net_lldpdu *lldpdu;
624 :
625 : /** LLDP Data Unit optional TLVs for the interface */
626 1 : const uint8_t *optional_du;
627 :
628 : /** Length of the optional Data Unit TLVs */
629 1 : size_t optional_len;
630 :
631 : /** Network interface that has LLDP supported. */
632 1 : struct net_if *iface;
633 :
634 : /** LLDP TX timer start time */
635 1 : int64_t tx_timer_start;
636 :
637 : /** LLDP TX timeout */
638 1 : uint32_t tx_timer_timeout;
639 :
640 : /** LLDP RX callback function */
641 1 : net_lldp_recv_cb_t cb;
642 : };
643 :
644 : /** @cond INTERNAL_HIDDEN */
645 :
646 : enum ethernet_flags {
647 : ETH_CARRIER_UP,
648 : };
649 :
650 : /** Ethernet L2 context that is needed for VLAN */
651 : struct ethernet_context {
652 : /** Flags representing ethernet state, which are accessed from multiple
653 : * threads.
654 : */
655 : atomic_t flags;
656 :
657 : #if defined(CONFIG_NET_ETHERNET_BRIDGE)
658 : struct net_if *bridge;
659 : #endif
660 :
661 : /** Carrier ON/OFF handler worker. This is used to create
662 : * network interface UP/DOWN event when ethernet L2 driver
663 : * notices carrier ON/OFF situation. We must not create another
664 : * network management event from inside management handler thus
665 : * we use worker thread to trigger the UP/DOWN event.
666 : */
667 : struct k_work carrier_work;
668 :
669 : /** Network interface. */
670 : struct net_if *iface;
671 :
672 : #if defined(CONFIG_NET_LLDP)
673 : #if NET_VLAN_MAX_COUNT > 0
674 : #define NET_LLDP_MAX_COUNT NET_VLAN_MAX_COUNT
675 : #else
676 : #define NET_LLDP_MAX_COUNT 1
677 : #endif /* NET_VLAN_MAX_COUNT > 0 */
678 :
679 : /** LLDP specific parameters */
680 : struct ethernet_lldp lldp[NET_LLDP_MAX_COUNT];
681 : #endif
682 :
683 : /**
684 : * This tells what L2 features does ethernet support.
685 : */
686 : enum net_l2_flags ethernet_l2_flags;
687 :
688 : #if defined(CONFIG_NET_L2_PTP)
689 : /** The PTP port number for this network device. We need to store the
690 : * port number here so that we do not need to fetch it for every
691 : * incoming PTP packet.
692 : */
693 : int port;
694 : #endif
695 :
696 : #if defined(CONFIG_NET_DSA_DEPRECATED)
697 : /** DSA RX callback function - for custom processing - like e.g.
698 : * redirecting packets when MAC address is caught
699 : */
700 : dsa_net_recv_cb_t dsa_recv_cb;
701 :
702 : /** Switch physical port number */
703 : uint8_t dsa_port_idx;
704 :
705 : /** DSA context pointer */
706 : struct dsa_context *dsa_ctx;
707 :
708 : /** Send a network packet via DSA master port */
709 : dsa_send_t dsa_send;
710 :
711 : #elif defined(CONFIG_NET_DSA)
712 : /** DSA port tpye */
713 : enum dsa_port_type dsa_port;
714 :
715 : /** DSA switch context pointer */
716 : void *dsa_switch_ctx;
717 : #endif
718 :
719 : /** Is network carrier up */
720 : bool is_net_carrier_up : 1;
721 :
722 : /** Is this context already initialized */
723 : bool is_init : 1;
724 :
725 : /** Types of Ethernet network interfaces */
726 : enum ethernet_if_types eth_if_type;
727 : };
728 :
729 : /**
730 : * @brief Initialize Ethernet L2 stack for a given interface
731 : *
732 : * @param iface A valid pointer to a network interface
733 : */
734 : void ethernet_init(struct net_if *iface);
735 :
736 : #define ETHERNET_L2_CTX_TYPE struct ethernet_context
737 :
738 : /* Separate header for VLAN as some of device interfaces might not
739 : * support VLAN.
740 : */
741 : struct net_eth_vlan_hdr {
742 : struct net_eth_addr dst;
743 : struct net_eth_addr src;
744 : struct {
745 : uint16_t tpid; /* tag protocol id */
746 : uint16_t tci; /* tag control info */
747 : } vlan;
748 : uint16_t type;
749 : } __packed;
750 :
751 : /** @endcond */
752 :
753 : /**
754 : * @brief Check if the Ethernet MAC address is a broadcast address.
755 : *
756 : * @param addr A valid pointer to a Ethernet MAC address.
757 : *
758 : * @return true if address is a broadcast address, false if not
759 : */
760 1 : static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
761 : {
762 : if (addr->addr[0] == 0xff &&
763 : addr->addr[1] == 0xff &&
764 : addr->addr[2] == 0xff &&
765 : addr->addr[3] == 0xff &&
766 : addr->addr[4] == 0xff &&
767 : addr->addr[5] == 0xff) {
768 : return true;
769 : }
770 :
771 : return false;
772 : }
773 :
774 : /**
775 : * @brief Check if the Ethernet MAC address is a all zeroes address.
776 : *
777 : * @param addr A valid pointer to an Ethernet MAC address.
778 : *
779 : * @return true if address is an all zeroes address, false if not
780 : */
781 1 : static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
782 : {
783 : if (addr->addr[0] == 0x00 &&
784 : addr->addr[1] == 0x00 &&
785 : addr->addr[2] == 0x00 &&
786 : addr->addr[3] == 0x00 &&
787 : addr->addr[4] == 0x00 &&
788 : addr->addr[5] == 0x00) {
789 : return true;
790 : }
791 :
792 : return false;
793 : }
794 :
795 : /**
796 : * @brief Check if the Ethernet MAC address is unspecified.
797 : *
798 : * @param addr A valid pointer to a Ethernet MAC address.
799 : *
800 : * @return true if address is unspecified, false if not
801 : */
802 1 : static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
803 : {
804 : if (addr->addr[0] == 0x00 &&
805 : addr->addr[1] == 0x00 &&
806 : addr->addr[2] == 0x00 &&
807 : addr->addr[3] == 0x00 &&
808 : addr->addr[4] == 0x00 &&
809 : addr->addr[5] == 0x00) {
810 : return true;
811 : }
812 :
813 : return false;
814 : }
815 :
816 : /**
817 : * @brief Check if the Ethernet MAC address is a multicast address.
818 : *
819 : * @param addr A valid pointer to a Ethernet MAC address.
820 : *
821 : * @return true if address is a multicast address, false if not
822 : */
823 1 : static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
824 : {
825 : #if defined(CONFIG_NET_IPV6)
826 : if (addr->addr[0] == 0x33 &&
827 : addr->addr[1] == 0x33) {
828 : return true;
829 : }
830 : #endif
831 :
832 : #if defined(CONFIG_NET_IPV4)
833 : if (addr->addr[0] == 0x01 &&
834 : addr->addr[1] == 0x00 &&
835 : addr->addr[2] == 0x5e) {
836 : return true;
837 : }
838 : #endif
839 :
840 : return false;
841 : }
842 :
843 : /**
844 : * @brief Check if the Ethernet MAC address is a group address.
845 : *
846 : * @param addr A valid pointer to a Ethernet MAC address.
847 : *
848 : * @return true if address is a group address, false if not
849 : */
850 1 : static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
851 : {
852 : return addr->addr[0] & 0x01;
853 : }
854 :
855 : /**
856 : * @brief Check if the Ethernet MAC address is valid.
857 : *
858 : * @param addr A valid pointer to a Ethernet MAC address.
859 : *
860 : * @return true if address is valid, false if not
861 : */
862 1 : static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
863 : {
864 : return !net_eth_is_addr_unspecified(addr) && !net_eth_is_addr_group(addr);
865 : }
866 :
867 : /**
868 : * @brief Check if the Ethernet MAC address is a LLDP multicast address.
869 : *
870 : * @param addr A valid pointer to a Ethernet MAC address.
871 : *
872 : * @return true if address is a LLDP multicast address, false if not
873 : */
874 1 : static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
875 : {
876 : #if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
877 : if (addr->addr[0] == 0x01 &&
878 : addr->addr[1] == 0x80 &&
879 : addr->addr[2] == 0xc2 &&
880 : addr->addr[3] == 0x00 &&
881 : addr->addr[4] == 0x00 &&
882 : addr->addr[5] == 0x0e) {
883 : return true;
884 : }
885 : #else
886 : ARG_UNUSED(addr);
887 : #endif
888 :
889 : return false;
890 : }
891 :
892 : /**
893 : * @brief Check if the Ethernet MAC address is a PTP multicast address.
894 : *
895 : * @param addr A valid pointer to a Ethernet MAC address.
896 : *
897 : * @return true if address is a PTP multicast address, false if not
898 : */
899 1 : static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
900 : {
901 : #if defined(CONFIG_NET_GPTP)
902 : if (addr->addr[0] == 0x01 &&
903 : addr->addr[1] == 0x1b &&
904 : addr->addr[2] == 0x19 &&
905 : addr->addr[3] == 0x00 &&
906 : addr->addr[4] == 0x00 &&
907 : addr->addr[5] == 0x00) {
908 : return true;
909 : }
910 : #else
911 : ARG_UNUSED(addr);
912 : #endif
913 :
914 : return false;
915 : }
916 :
917 : /**
918 : * @brief Return Ethernet broadcast address.
919 : *
920 : * @return Ethernet broadcast address.
921 : */
922 1 : const struct net_eth_addr *net_eth_broadcast_addr(void);
923 :
924 : /**
925 : * @brief Convert IPv4 multicast address to Ethernet address.
926 : *
927 : * @param ipv4_addr IPv4 multicast address
928 : * @param mac_addr Output buffer for Ethernet address
929 : */
930 1 : void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
931 : struct net_eth_addr *mac_addr);
932 :
933 : /**
934 : * @brief Convert IPv6 multicast address to Ethernet address.
935 : *
936 : * @param ipv6_addr IPv6 multicast address
937 : * @param mac_addr Output buffer for Ethernet address
938 : */
939 1 : void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
940 : struct net_eth_addr *mac_addr);
941 :
942 : /**
943 : * @brief Return ethernet device hardware capability information.
944 : *
945 : * @param iface Network interface
946 : *
947 : * @return Hardware capabilities
948 : */
949 : static inline
950 1 : enum ethernet_hw_caps net_eth_get_hw_capabilities(struct net_if *iface)
951 : {
952 : const struct device *dev = net_if_get_device(iface);
953 : const struct ethernet_api *api = (struct ethernet_api *)dev->api;
954 : enum ethernet_hw_caps caps = (enum ethernet_hw_caps)0;
955 : #if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
956 : struct ethernet_context *eth_ctx = net_if_l2_data(iface);
957 :
958 : if (eth_ctx->dsa_port == DSA_CONDUIT_PORT) {
959 : caps |= ETHERNET_DSA_CONDUIT_PORT;
960 : } else if (eth_ctx->dsa_port == DSA_USER_PORT) {
961 : caps |= ETHERNET_DSA_USER_PORT;
962 : }
963 : #endif
964 : if (api == NULL || api->get_capabilities == NULL) {
965 : return caps;
966 : }
967 :
968 : return (enum ethernet_hw_caps)(caps | api->get_capabilities(dev));
969 : }
970 :
971 : /**
972 : * @brief Return ethernet device hardware configuration information.
973 : *
974 : * @param iface Network interface
975 : * @param type configuration type
976 : * @param config Ethernet configuration
977 : *
978 : * @return 0 if ok, <0 if error
979 : */
980 : static inline
981 1 : int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
982 : struct ethernet_config *config)
983 : {
984 : const struct ethernet_api *eth =
985 : (struct ethernet_api *)net_if_get_device(iface)->api;
986 :
987 : if (!eth->get_config) {
988 : return -ENOTSUP;
989 : }
990 :
991 : return eth->get_config(net_if_get_device(iface), type, config);
992 : }
993 :
994 :
995 : /**
996 : * @brief Add VLAN tag to the interface.
997 : *
998 : * @param iface Interface to use.
999 : * @param tag VLAN tag to add
1000 : *
1001 : * @return 0 if ok, <0 if error
1002 : */
1003 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1004 : int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
1005 : #else
1006 1 : static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
1007 : {
1008 : ARG_UNUSED(iface);
1009 : ARG_UNUSED(tag);
1010 :
1011 : return -EINVAL;
1012 : }
1013 : #endif
1014 :
1015 : /**
1016 : * @brief Remove VLAN tag from the interface.
1017 : *
1018 : * @param iface Interface to use.
1019 : * @param tag VLAN tag to remove
1020 : *
1021 : * @return 0 if ok, <0 if error
1022 : */
1023 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1024 : int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
1025 : #else
1026 1 : static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
1027 : {
1028 : ARG_UNUSED(iface);
1029 : ARG_UNUSED(tag);
1030 :
1031 : return -EINVAL;
1032 : }
1033 : #endif
1034 :
1035 : /**
1036 : * @brief Return VLAN tag specified to network interface.
1037 : *
1038 : * Note that the interface parameter must be the VLAN interface,
1039 : * and not the Ethernet one.
1040 : *
1041 : * @param iface VLAN network interface.
1042 : *
1043 : * @return VLAN tag for this interface or NET_VLAN_TAG_UNSPEC if VLAN
1044 : * is not configured for that interface.
1045 : */
1046 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1047 : uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1048 : #else
1049 1 : static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1050 : {
1051 : ARG_UNUSED(iface);
1052 :
1053 : return NET_VLAN_TAG_UNSPEC;
1054 : }
1055 : #endif
1056 :
1057 : /**
1058 : * @brief Return network interface related to this VLAN tag
1059 : *
1060 : * @param iface Main network interface (not the VLAN one).
1061 : * @param tag VLAN tag
1062 : *
1063 : * @return Network interface related to this tag or NULL if no such interface
1064 : * exists.
1065 : */
1066 : #if defined(CONFIG_NET_VLAN)
1067 : struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1068 : #else
1069 : static inline
1070 1 : struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
1071 : {
1072 : ARG_UNUSED(iface);
1073 : ARG_UNUSED(tag);
1074 :
1075 : return NULL;
1076 : }
1077 : #endif
1078 :
1079 : /**
1080 : * @brief Return main network interface that is attached to this VLAN tag.
1081 : *
1082 : * @param iface VLAN network interface. This is used to get the
1083 : * pointer to ethernet L2 context
1084 : *
1085 : * @return Network interface related to this tag or NULL if no such interface
1086 : * exists.
1087 : */
1088 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1089 : struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1090 : #else
1091 : static inline
1092 1 : struct net_if *net_eth_get_vlan_main(struct net_if *iface)
1093 : {
1094 : ARG_UNUSED(iface);
1095 :
1096 : return NULL;
1097 : }
1098 : #endif
1099 :
1100 : /**
1101 : * @brief Check if there are any VLAN interfaces enabled to this specific
1102 : * Ethernet network interface.
1103 : *
1104 : * Note that the iface must be the actual Ethernet interface and not the
1105 : * virtual VLAN interface.
1106 : *
1107 : * @param ctx Ethernet context
1108 : * @param iface Ethernet network interface
1109 : *
1110 : * @return True if there are enabled VLANs for this network interface,
1111 : * false if not.
1112 : */
1113 : #if defined(CONFIG_NET_VLAN)
1114 : bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1115 : struct net_if *iface);
1116 : #else
1117 1 : static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1118 : struct net_if *iface)
1119 : {
1120 : ARG_UNUSED(ctx);
1121 : ARG_UNUSED(iface);
1122 :
1123 : return false;
1124 : }
1125 : #endif
1126 :
1127 : /**
1128 : * @brief Get VLAN status for a given network interface (enabled or not).
1129 : *
1130 : * @param iface Network interface
1131 : *
1132 : * @return True if VLAN is enabled for this network interface, false if not.
1133 : */
1134 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1135 : bool net_eth_get_vlan_status(struct net_if *iface);
1136 : #else
1137 1 : static inline bool net_eth_get_vlan_status(struct net_if *iface)
1138 : {
1139 : ARG_UNUSED(iface);
1140 :
1141 : return false;
1142 : }
1143 : #endif
1144 :
1145 : /**
1146 : * @brief Check if the given interface is a VLAN interface.
1147 : *
1148 : * @param iface Network interface
1149 : *
1150 : * @return True if this network interface is VLAN one, false if not.
1151 : */
1152 : #if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1153 : bool net_eth_is_vlan_interface(struct net_if *iface);
1154 : #else
1155 1 : static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1156 : {
1157 : ARG_UNUSED(iface);
1158 :
1159 : return false;
1160 : }
1161 : #endif
1162 :
1163 : /** @cond INTERNAL_HIDDEN */
1164 :
1165 : #if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1166 :
1167 : #define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1168 : init_fn, pm, data, config, prio, \
1169 : api, mtu) \
1170 : Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1171 : init_fn, pm, data, config, prio, \
1172 : api, ETHERNET_L2, \
1173 : NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1174 :
1175 : #else /* CONFIG_ETH_DRIVER_RAW_MODE */
1176 :
1177 : #define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1178 : init_fn, pm, data, config, prio, \
1179 : api, mtu) \
1180 : Z_DEVICE_STATE_DEFINE(dev_id); \
1181 : Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL, \
1182 : Z_DEVICE_DT_FLAGS(node_id), pm, data, \
1183 : config, POST_KERNEL, prio, api, \
1184 : &Z_DEVICE_STATE_NAME(dev_id));
1185 :
1186 : #endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1187 :
1188 : #define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1189 : config, prio, api, mtu) \
1190 : Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1191 : init_fn, pm, data, config, prio, \
1192 : api, mtu)
1193 :
1194 : /** @endcond */
1195 :
1196 : /**
1197 : * @brief Create an Ethernet network interface and bind it to network device.
1198 : *
1199 : * @param dev_id Network device id.
1200 : * @param name The name this instance of the driver exposes to
1201 : * the system.
1202 : * @param init_fn Address to the init function of the driver.
1203 : * @param pm Reference to struct pm_device associated with the device.
1204 : * (optional).
1205 : * @param data Pointer to the device's private data.
1206 : * @param config The address to the structure containing the
1207 : * configuration information for this instance of the driver.
1208 : * @param prio The initialization level at which configuration occurs.
1209 : * @param api Provides an initial pointer to the API function struct
1210 : * used by the driver. Can be NULL.
1211 : * @param mtu Maximum transfer unit in bytes for this network interface.
1212 : */
1213 : #define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1214 1 : prio, api, mtu) \
1215 : Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1216 : pm, data, config, prio, api, mtu)
1217 :
1218 : /**
1219 : * @brief Create multiple Ethernet network interfaces and bind them to network
1220 : * devices.
1221 : * If your network device needs more than one instance of a network interface,
1222 : * use this macro below and provide a different instance suffix each time
1223 : * (0, 1, 2, ... or a, b, c ... whatever works for you)
1224 : *
1225 : * @param dev_id Network device id.
1226 : * @param name The name this instance of the driver exposes to
1227 : * the system.
1228 : * @param instance Instance identifier.
1229 : * @param init_fn Address to the init function of the driver.
1230 : * @param pm Reference to struct pm_device associated with the device.
1231 : * (optional).
1232 : * @param data Pointer to the device's private data.
1233 : * @param config The address to the structure containing the
1234 : * configuration information for this instance of the driver.
1235 : * @param prio The initialization level at which configuration occurs.
1236 : * @param api Provides an initial pointer to the API function struct
1237 : * used by the driver. Can be NULL.
1238 : * @param mtu Maximum transfer unit in bytes for this network interface.
1239 : */
1240 : #define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1241 1 : pm, data, config, prio, api, mtu) \
1242 : Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1243 : instance, init_fn, pm, data, \
1244 : config, prio, api, mtu)
1245 :
1246 : /**
1247 : * @brief Like ETH_NET_DEVICE_INIT but taking metadata from a devicetree.
1248 : * Create an Ethernet network interface and bind it to network device.
1249 : *
1250 : * @param node_id The devicetree node identifier.
1251 : * @param init_fn Address to the init function of the driver.
1252 : * @param pm Reference to struct pm_device associated with the device.
1253 : * (optional).
1254 : * @param data Pointer to the device's private data.
1255 : * @param config The address to the structure containing the
1256 : * configuration information for this instance of the driver.
1257 : * @param prio The initialization level at which configuration occurs.
1258 : * @param api Provides an initial pointer to the API function struct
1259 : * used by the driver. Can be NULL.
1260 : * @param mtu Maximum transfer unit in bytes for this network interface.
1261 : */
1262 : #define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1263 1 : prio, api, mtu) \
1264 : Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1265 : DEVICE_DT_NAME(node_id), init_fn, pm, \
1266 : data, config, prio, api, mtu)
1267 :
1268 : /**
1269 : * @brief Like ETH_NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT
1270 : * compatible
1271 : *
1272 : * @param inst instance number. This is replaced by
1273 : * <tt>DT_DRV_COMPAT(inst)</tt> in the call to ETH_NET_DEVICE_DT_DEFINE.
1274 : *
1275 : * @param ... other parameters as expected by ETH_NET_DEVICE_DT_DEFINE.
1276 : */
1277 1 : #define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1278 : ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1279 :
1280 : /**
1281 : * @brief Ethernet L3 protocol register macro.
1282 : *
1283 : * @param name Name of the L3 protocol.
1284 : * @param ptype Ethernet protocol type.
1285 : * @param handler Handler function for this protocol type.
1286 : */
1287 1 : #define ETH_NET_L3_REGISTER(name, ptype, handler) \
1288 : NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
1289 :
1290 : /**
1291 : * @brief Inform ethernet L2 driver that ethernet carrier is detected.
1292 : * This happens when cable is connected.
1293 : *
1294 : * @param iface Network interface
1295 : */
1296 1 : void net_eth_carrier_on(struct net_if *iface);
1297 :
1298 : /**
1299 : * @brief Inform ethernet L2 driver that ethernet carrier was lost.
1300 : * This happens when cable is disconnected.
1301 : *
1302 : * @param iface Network interface
1303 : */
1304 1 : void net_eth_carrier_off(struct net_if *iface);
1305 :
1306 : /**
1307 : * @brief Set promiscuous mode either ON or OFF.
1308 : *
1309 : * @param iface Network interface
1310 : *
1311 : * @param enable on (true) or off (false)
1312 : *
1313 : * @return 0 if mode set or unset was successful, <0 otherwise.
1314 : */
1315 1 : int net_eth_promisc_mode(struct net_if *iface, bool enable);
1316 :
1317 : /**
1318 : * @brief Set TX-Injection mode either ON or OFF.
1319 : *
1320 : * @param iface Network interface
1321 : *
1322 : * @param enable on (true) or off (false)
1323 : *
1324 : * @return 0 if mode set or unset was successful, <0 otherwise.
1325 : */
1326 1 : int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1327 :
1328 : /**
1329 : * @brief Set or unset HW filtering for MAC address @p mac.
1330 : *
1331 : * @param iface Network interface
1332 : * @param mac Pointer to an ethernet MAC address
1333 : * @param type Filter type, either source or destination
1334 : * @param enable Set (true) or unset (false)
1335 : *
1336 : * @return 0 if filter set or unset was successful, <0 otherwise.
1337 : */
1338 1 : int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1339 : enum ethernet_filter_type type, bool enable);
1340 :
1341 : /**
1342 : * @brief Return the PHY device that is tied to this ethernet network interface.
1343 : *
1344 : * @param iface Network interface
1345 : *
1346 : * @return Pointer to PHY device if found, NULL if not found.
1347 : */
1348 1 : const struct device *net_eth_get_phy(struct net_if *iface);
1349 :
1350 : /**
1351 : * @brief Return PTP clock that is tied to this ethernet network interface.
1352 : *
1353 : * @param iface Network interface
1354 : *
1355 : * @return Pointer to PTP clock if found, NULL if not found or if this
1356 : * ethernet interface does not support PTP.
1357 : */
1358 : #if defined(CONFIG_PTP_CLOCK)
1359 : const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1360 : #else
1361 1 : static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1362 : {
1363 : ARG_UNUSED(iface);
1364 :
1365 : return NULL;
1366 : }
1367 : #endif
1368 :
1369 : /**
1370 : * @brief Return PTP clock that is tied to this ethernet network interface
1371 : * index.
1372 : *
1373 : * @param index Network interface index
1374 : *
1375 : * @return Pointer to PTP clock if found, NULL if not found or if this
1376 : * ethernet interface index does not support PTP.
1377 : */
1378 1 : __syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1379 :
1380 : /**
1381 : * @brief Return PTP port number attached to this interface.
1382 : *
1383 : * @param iface Network interface
1384 : *
1385 : * @return Port number, no such port if < 0
1386 : */
1387 : #if defined(CONFIG_NET_L2_PTP)
1388 : int net_eth_get_ptp_port(struct net_if *iface);
1389 : #else
1390 1 : static inline int net_eth_get_ptp_port(struct net_if *iface)
1391 : {
1392 : ARG_UNUSED(iface);
1393 :
1394 : return -ENODEV;
1395 : }
1396 : #endif /* CONFIG_NET_L2_PTP */
1397 :
1398 : /**
1399 : * @brief Set PTP port number attached to this interface.
1400 : *
1401 : * @param iface Network interface
1402 : * @param port Port number to set
1403 : */
1404 : #if defined(CONFIG_NET_L2_PTP)
1405 : void net_eth_set_ptp_port(struct net_if *iface, int port);
1406 : #else
1407 1 : static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1408 : {
1409 : ARG_UNUSED(iface);
1410 : ARG_UNUSED(port);
1411 : }
1412 : #endif /* CONFIG_NET_L2_PTP */
1413 :
1414 : /**
1415 : * @brief Check if the Ethernet L2 network interface can perform Wi-Fi.
1416 : *
1417 : * @param iface Pointer to network interface
1418 : *
1419 : * @return True if interface supports Wi-Fi, False otherwise.
1420 : */
1421 1 : static inline bool net_eth_type_is_wifi(struct net_if *iface)
1422 : {
1423 : const struct ethernet_context *ctx = (struct ethernet_context *)
1424 : net_if_l2_data(iface);
1425 :
1426 : return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1427 : }
1428 :
1429 : /**
1430 : * @}
1431 : */
1432 :
1433 : #ifdef __cplusplus
1434 : }
1435 : #endif
1436 :
1437 : #include <zephyr/syscalls/ethernet.h>
1438 :
1439 : #endif /* ZEPHYR_INCLUDE_NET_ETHERNET_H_ */
|