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