Zephyr API Documentation  3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ethernet.h
Go to the documentation of this file.
1
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>
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)
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
48#define NET_ETH_ADDR_LEN 6U
53};
54
57#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
58
59#define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
60#define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
61#define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
62#define NET_ETH_PTYPE_ARP 0x0806
63#define NET_ETH_PTYPE_IP 0x0800
64#define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
65#define NET_ETH_PTYPE_IPV6 0x86dd
66#define NET_ETH_PTYPE_VLAN 0x8100
67#define NET_ETH_PTYPE_PTP 0x88f7
68#define NET_ETH_PTYPE_LLDP 0x88cc
69#define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
70#define NET_ETH_PTYPE_ECAT 0x88a4
71#define NET_ETH_PTYPE_EAPOL 0x888e
72#define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
73
74#if !defined(ETH_P_ALL)
75#define ETH_P_ALL NET_ETH_PTYPE_ALL
76#endif
77#if !defined(ETH_P_IP)
78#define ETH_P_IP NET_ETH_PTYPE_IP
79#endif
80#if !defined(ETH_P_ARP)
81#define ETH_P_ARP NET_ETH_PTYPE_ARP
82#endif
83#if !defined(ETH_P_IPV6)
84#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
85#endif
86#if !defined(ETH_P_8021Q)
87#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
88#endif
89#if !defined(ETH_P_TSN)
90#define ETH_P_TSN NET_ETH_PTYPE_TSN
91#endif
92#if !defined(ETH_P_ECAT)
93#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
94#endif
95#if !defined(ETH_P_EAPOL)
96#define ETH_P_EAPOL NET_ETH_PTYPE_EAPOL
97#endif
98#if !defined(ETH_P_IEEE802154)
99#define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
100#endif
101#if !defined(ETH_P_CAN)
102#define ETH_P_CAN NET_ETH_PTYPE_CAN
103#endif
104#if !defined(ETH_P_CANFD)
105#define ETH_P_CANFD NET_ETH_PTYPE_CANFD
106#endif
107#if !defined(ETH_P_HDLC)
108#define ETH_P_HDLC NET_ETH_PTYPE_HDLC
109#endif
110
113#define NET_ETH_MINIMAL_FRAME_SIZE 60
114#define NET_ETH_MTU 1500
118#if defined(CONFIG_NET_VLAN)
119#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_vlan_hdr))
120#else
121#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
122#endif
123
124#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + _NET_ETH_MAX_HDR_SIZE)
125/*
126 * Extend the max frame size for DSA (KSZ8794) by one byte (to 1519) to
127 * store tail tag.
128 */
129#if defined(CONFIG_NET_DSA)
130#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
131#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
132#else
133#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
134#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
135#endif
136
137#define NET_ETH_VLAN_HDR_SIZE 4
138
145
148
151
154
157
160
163
166
169
172
175
178
181
184
187
190
193
196
199
202
205};
206
209enum ethernet_config_type {
210 ETHERNET_CONFIG_TYPE_AUTO_NEG,
211 ETHERNET_CONFIG_TYPE_LINK,
212 ETHERNET_CONFIG_TYPE_DUPLEX,
213 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
214 ETHERNET_CONFIG_TYPE_QAV_PARAM,
215 ETHERNET_CONFIG_TYPE_QBV_PARAM,
216 ETHERNET_CONFIG_TYPE_QBU_PARAM,
217 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
218 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
219 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
220 ETHERNET_CONFIG_TYPE_FILTER,
221 ETHERNET_CONFIG_TYPE_PORTS_NUM,
222 ETHERNET_CONFIG_TYPE_T1S_PARAM,
223 ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
224 ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
225 ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT
226};
227
228enum ethernet_qav_param_type {
229 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
230 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
231 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
232 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
233 ETHERNET_QAV_PARAM_TYPE_STATUS,
234};
235
236enum ethernet_t1s_param_type {
237 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
238};
239
245 enum ethernet_t1s_param_type type;
246 union {
270 struct {
272 bool enable;
284 };
285};
286
292 enum ethernet_qav_param_type type;
293 union {
297 unsigned int delta_bandwidth;
299 unsigned int idle_slope;
301 unsigned int oper_idle_slope;
303 unsigned int traffic_class;
304 };
305};
306
309enum ethernet_qbv_param_type {
310 ETHERNET_QBV_PARAM_TYPE_STATUS,
311 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
312 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
313 ETHERNET_QBV_PARAM_TYPE_TIME,
314};
315
316enum ethernet_qbv_state_type {
317 ETHERNET_QBV_STATE_TYPE_ADMIN,
318 ETHERNET_QBV_STATE_TYPE_OPER,
319};
320
321enum ethernet_gate_state_operation {
322 ETHERNET_SET_GATE_STATE,
323 ETHERNET_SET_AND_HOLD_MAC_STATE,
324 ETHERNET_SET_AND_RELEASE_MAC_STATE,
325};
326
334 enum ethernet_qbv_param_type type;
336 enum ethernet_qbv_state_type state;
337 union {
340
342 struct {
344 bool gate_status[NET_TC_TX_COUNT];
345
347 enum ethernet_gate_state_operation operation;
348
351
355
358
363 struct {
366
369
372 };
373 };
374};
375
378enum ethernet_qbu_param_type {
379 ETHERNET_QBU_PARAM_TYPE_STATUS,
380 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
381 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
382 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
383
384 /* Some preemption settings are from Qbr spec. */
385 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
386 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
387};
388
389enum ethernet_qbu_preempt_status {
390 ETHERNET_QBU_STATUS_EXPRESS,
391 ETHERNET_QBU_STATUS_PREEMPTABLE
392} __packed;
393
401 enum ethernet_qbu_param_type type;
402 union {
405
408
410 enum ethernet_qbu_preempt_status
411 frame_preempt_statuses[NET_TC_TX_COUNT];
412
415
418
424 };
425};
426
429enum ethernet_filter_type {
430 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
431 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
432};
433
440
443} __packed;
444
448 enum ethernet_filter_type type;
452 bool set;
453};
454
457enum ethernet_txtime_param_type {
458 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
459};
460
466 enum ethernet_txtime_param_type type;
471};
472
476 ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
478 ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
480 ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
482 ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
484 ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
486 ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
488 ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
489};
490
493struct ethernet_config {
494 union {
495 bool auto_negotiation;
496 bool full_duplex;
497 bool promisc_mode;
498 bool txinjection_mode;
499
500 struct {
501 bool link_10bt;
502 bool link_100bt;
503 bool link_1000bt;
504 } l;
505
506 struct net_eth_addr mac_address;
507
508 struct ethernet_t1s_param t1s_param;
509 struct ethernet_qav_param qav_param;
510 struct ethernet_qbv_param qbv_param;
511 struct ethernet_qbu_param qbu_param;
512 struct ethernet_txtime_param txtime_param;
513
514 int priority_queues_num;
515 int ports_num;
516
517 enum ethernet_checksum_support chksum_support;
518
519 struct ethernet_filter filter;
520 };
521};
522
531 struct net_if_api iface_api;
532
537#if defined(CONFIG_NET_STATISTICS_ETHERNET)
538 struct net_stats_eth *(*get_stats)(const struct device *dev);
539#endif
540
542 int (*start)(const struct device *dev);
543
545 int (*stop)(const struct device *dev);
546
548 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
549
551 int (*set_config)(const struct device *dev,
552 enum ethernet_config_type type,
553 const struct ethernet_config *config);
554
556 int (*get_config)(const struct device *dev,
557 enum ethernet_config_type type,
558 struct ethernet_config *config);
559
565#if defined(CONFIG_NET_VLAN)
566 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
567 uint16_t tag, bool enable);
568#endif /* CONFIG_NET_VLAN */
569
571#if defined(CONFIG_PTP_CLOCK)
572 const struct device *(*get_ptp_clock)(const struct device *dev);
573#endif /* CONFIG_PTP_CLOCK */
574
576 int (*send)(const struct device *dev, struct net_pkt *pkt);
577};
578
581/* Make sure that the network interface API is properly setup inside
582 * Ethernet API struct (it is the first one).
583 */
584BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
585
586struct net_eth_hdr {
587 struct net_eth_addr dst;
588 struct net_eth_addr src;
589 uint16_t type;
590} __packed;
591
592struct ethernet_vlan {
594 struct net_if *iface;
595
597 uint16_t tag;
598};
599
600#if defined(CONFIG_NET_VLAN_COUNT)
601#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
602#else
603/* Even thou there are no VLAN support, the minimum count must be set to 1.
604 */
605#define NET_VLAN_MAX_COUNT 1
606#endif
607
614
616 const struct net_lldpdu *lldpdu;
617
620
623
625 struct net_if *iface;
626
629
632
635};
636
639enum ethernet_flags {
640 ETH_CARRIER_UP,
641};
642
644struct ethernet_context {
649
650#if defined(CONFIG_NET_ETHERNET_BRIDGE)
651 struct eth_bridge_iface_context bridge;
652#endif
653
660 struct k_work carrier_work;
661
663 struct net_if *iface;
664
665#if defined(CONFIG_NET_LLDP)
666 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
667#endif
668
672 enum net_l2_flags ethernet_l2_flags;
673
674#if defined(CONFIG_NET_L2_PTP)
679 int port;
680#endif
681
682#if defined(CONFIG_NET_DSA)
686 dsa_net_recv_cb_t dsa_recv_cb;
687
689 uint8_t dsa_port_idx;
690
692 struct dsa_context *dsa_ctx;
693
695 dsa_send_t dsa_send;
696#endif
697
699 bool is_net_carrier_up : 1;
700
702 bool is_init : 1;
703
705 enum ethernet_if_types eth_if_type;
706};
707
713void ethernet_init(struct net_if *iface);
714
715#define ETHERNET_L2_CTX_TYPE struct ethernet_context
716
717/* Separate header for VLAN as some of device interfaces might not
718 * support VLAN.
719 */
720struct net_eth_vlan_hdr {
721 struct net_eth_addr dst;
722 struct net_eth_addr src;
723 struct {
724 uint16_t tpid; /* tag protocol id */
725 uint16_t tci; /* tag control info */
726 } vlan;
727 uint16_t type;
728} __packed;
729
739static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
740{
741 if (addr->addr[0] == 0xff &&
742 addr->addr[1] == 0xff &&
743 addr->addr[2] == 0xff &&
744 addr->addr[3] == 0xff &&
745 addr->addr[4] == 0xff &&
746 addr->addr[5] == 0xff) {
747 return true;
748 }
749
750 return false;
751}
752
760static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
761{
762 if (addr->addr[0] == 0x00 &&
763 addr->addr[1] == 0x00 &&
764 addr->addr[2] == 0x00 &&
765 addr->addr[3] == 0x00 &&
766 addr->addr[4] == 0x00 &&
767 addr->addr[5] == 0x00) {
768 return true;
769 }
770
771 return false;
772}
773
781static inline bool net_eth_is_addr_unspecified(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
802static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
803{
804#if defined(CONFIG_NET_IPV6)
805 if (addr->addr[0] == 0x33 &&
806 addr->addr[1] == 0x33) {
807 return true;
808 }
809#endif
810
811#if defined(CONFIG_NET_IPV4)
812 if (addr->addr[0] == 0x01 &&
813 addr->addr[1] == 0x00 &&
814 addr->addr[2] == 0x5e) {
815 return true;
816 }
817#endif
818
819 return false;
820}
821
829static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
830{
831 return addr->addr[0] & 0x01;
832}
833
841static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
842{
844}
845
853static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
854{
855#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
856 if (addr->addr[0] == 0x01 &&
857 addr->addr[1] == 0x80 &&
858 addr->addr[2] == 0xc2 &&
859 addr->addr[3] == 0x00 &&
860 addr->addr[4] == 0x00 &&
861 addr->addr[5] == 0x0e) {
862 return true;
863 }
864#else
865 ARG_UNUSED(addr);
866#endif
867
868 return false;
869}
870
878static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
879{
880#if defined(CONFIG_NET_GPTP)
881 if (addr->addr[0] == 0x01 &&
882 addr->addr[1] == 0x1b &&
883 addr->addr[2] == 0x19 &&
884 addr->addr[3] == 0x00 &&
885 addr->addr[4] == 0x00 &&
886 addr->addr[5] == 0x00) {
887 return true;
888 }
889#else
890 ARG_UNUSED(addr);
891#endif
892
893 return false;
894}
895
902
909void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
910 struct net_eth_addr *mac_addr);
911
918void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
919 struct net_eth_addr *mac_addr);
920
928static inline
930{
931 const struct ethernet_api *eth =
932 (struct ethernet_api *)net_if_get_device(iface)->api;
933
934 if (!eth->get_capabilities) {
935 return (enum ethernet_hw_caps)0;
936 }
937
938 return eth->get_capabilities(net_if_get_device(iface));
939}
940
950static inline
951int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
952 struct ethernet_config *config)
953{
954 const struct ethernet_api *eth =
955 (struct ethernet_api *)net_if_get_device(iface)->api;
956
957 if (!eth->get_config) {
958 return -ENOTSUP;
959 }
960
961 return eth->get_config(net_if_get_device(iface), type, config);
962}
963
964
973#if defined(CONFIG_NET_VLAN)
974int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
975#else
976static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
977{
978 ARG_UNUSED(iface);
979 ARG_UNUSED(tag);
980
981 return -EINVAL;
982}
983#endif
984
993#if defined(CONFIG_NET_VLAN)
994int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
995#else
996static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
997{
998 ARG_UNUSED(iface);
999 ARG_UNUSED(tag);
1000
1001 return -EINVAL;
1002}
1003#endif
1004
1016#if defined(CONFIG_NET_VLAN)
1017uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1018#else
1019static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1020{
1021 ARG_UNUSED(iface);
1022
1023 return NET_VLAN_TAG_UNSPEC;
1024}
1025#endif
1026
1036#if defined(CONFIG_NET_VLAN)
1037struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1038#else
1039static inline
1041{
1042 ARG_UNUSED(iface);
1043 ARG_UNUSED(tag);
1044
1045 return NULL;
1046}
1047#endif
1048
1058#if defined(CONFIG_NET_VLAN)
1059struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1060#else
1061static inline
1063{
1064 ARG_UNUSED(iface);
1065
1066 return NULL;
1067}
1068#endif
1069
1083#if defined(CONFIG_NET_VLAN)
1084bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1085 struct net_if *iface);
1086#else
1087static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1088 struct net_if *iface)
1089{
1090 ARG_UNUSED(ctx);
1091 ARG_UNUSED(iface);
1092
1093 return false;
1094}
1095#endif
1096
1104#if defined(CONFIG_NET_VLAN)
1105bool net_eth_get_vlan_status(struct net_if *iface);
1106#else
1107static inline bool net_eth_get_vlan_status(struct net_if *iface)
1108{
1109 ARG_UNUSED(iface);
1110
1111 return false;
1112}
1113#endif
1114
1122#if defined(CONFIG_NET_VLAN)
1123bool net_eth_is_vlan_interface(struct net_if *iface);
1124#else
1125static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1126{
1127 ARG_UNUSED(iface);
1128
1129 return false;
1130}
1131#endif
1132
1135#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1136
1137#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1138 init_fn, pm, data, config, prio, \
1139 api, mtu) \
1140 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1141 init_fn, pm, data, config, prio, \
1142 api, ETHERNET_L2, \
1143 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1144
1145#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1146
1147#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1148 init_fn, pm, data, config, prio, \
1149 api, mtu) \
1150 Z_DEVICE_STATE_DEFINE(dev_id); \
1151 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
1152 config, POST_KERNEL, prio, api, \
1153 &Z_DEVICE_STATE_NAME(dev_id));
1154
1155#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1156
1157#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1158 config, prio, api, mtu) \
1159 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1160 init_fn, pm, data, config, prio, \
1161 api, mtu)
1162
1182#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1183 prio, api, mtu) \
1184 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1185 pm, data, config, prio, api, mtu)
1186
1209#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1210 pm, data, config, prio, api, mtu) \
1211 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1212 instance, init_fn, pm, data, \
1213 config, prio, api, mtu)
1214
1231#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1232 prio, api, mtu) \
1233 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1234 DEVICE_DT_NAME(node_id), init_fn, pm, \
1235 data, config, prio, api, mtu)
1236
1246#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1247 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1248
1255void net_eth_carrier_on(struct net_if *iface);
1256
1263void net_eth_carrier_off(struct net_if *iface);
1264
1274int net_eth_promisc_mode(struct net_if *iface, bool enable);
1275
1285int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1286
1297int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1298 enum ethernet_filter_type type, bool enable);
1307#if defined(CONFIG_PTP_CLOCK)
1308const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1309#else
1310static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1311{
1312 ARG_UNUSED(iface);
1313
1314 return NULL;
1315}
1316#endif
1317
1327__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1328
1336#if defined(CONFIG_NET_L2_PTP)
1337int net_eth_get_ptp_port(struct net_if *iface);
1338#else
1339static inline int net_eth_get_ptp_port(struct net_if *iface)
1340{
1341 ARG_UNUSED(iface);
1342
1343 return -ENODEV;
1344}
1345#endif /* CONFIG_NET_L2_PTP */
1346
1353#if defined(CONFIG_NET_L2_PTP)
1354void net_eth_set_ptp_port(struct net_if *iface, int port);
1355#else
1356static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1357{
1358 ARG_UNUSED(iface);
1359 ARG_UNUSED(port);
1360}
1361#endif /* CONFIG_NET_L2_PTP */
1362
1370static inline bool net_eth_type_is_wifi(struct net_if *iface)
1371{
1372 const struct ethernet_context *ctx = (struct ethernet_context *)
1373 net_if_l2_data(iface);
1374
1375 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1376}
1377
1382#ifdef __cplusplus
1383}
1384#endif
1385
1386#include <zephyr/syscalls/ethernet.h>
1387
1388#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_H_ */
long atomic_t
Definition: atomic_types.h:15
DSA definitions and handlers.
Ethernet Bridge public header file.
VLAN specific definitions.
enum net_verdict(* dsa_net_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
DSA (MGMT) Receive packet callback.
Definition: dsa.h:72
int(* dsa_send_t)(const struct device *dev, struct net_pkt *pkt)
Pointer to master interface send function.
Definition: dsa.h:98
static struct net_if * net_eth_get_vlan_main(struct net_if *iface)
Return main network interface that is attached to this VLAN tag.
Definition: ethernet.h:1062
static int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type, struct ethernet_config *config)
Return ethernet device hardware configuration information.
Definition: ethernet.h:951
ethernet_if_types
Types of Ethernet L2.
Definition: ethernet.h:437
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition: ethernet.h:1356
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition: ethernet.h:976
static bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a all zeroes address.
Definition: ethernet.h:760
static bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a multicast address.
Definition: ethernet.h:802
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition: ethernet.h:1339
static const struct device * net_eth_get_ptp_clock(struct net_if *iface)
Return PTP clock that is tied to this ethernet network interface.
Definition: ethernet.h:1310
#define NET_ETH_ADDR_LEN
Ethernet MAC address length.
Definition: ethernet.h:48
int net_eth_promisc_mode(struct net_if *iface, bool enable)
Set promiscuous mode either ON or OFF.
void net_eth_carrier_off(struct net_if *iface)
Inform ethernet L2 driver that ethernet carrier was lost.
static uint16_t net_eth_get_vlan_tag(struct net_if *iface)
Return VLAN tag specified to network interface.
Definition: ethernet.h:1019
static bool net_eth_type_is_wifi(struct net_if *iface)
Check if the Ethernet L2 network interface can perform Wi-Fi.
Definition: ethernet.h:1370
static bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a broadcast address.
Definition: ethernet.h:739
static bool net_eth_get_vlan_status(struct net_if *iface)
Get VLAN status for a given network interface (enabled or not).
Definition: ethernet.h:1107
static bool net_eth_is_addr_group(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a group address.
Definition: ethernet.h:829
const struct device * net_eth_get_ptp_clock_by_index(int index)
Return PTP clock that is tied to this ethernet network interface index.
static bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
Check if the Ethernet MAC address is unspecified.
Definition: ethernet.h:781
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition: ethernet.h:1125
ethernet_hw_caps
Ethernet hardware capabilities.
Definition: ethernet.h:142
int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac, enum ethernet_filter_type type, bool enable)
Set or unset HW filtering for MAC address mac.
void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr, struct net_eth_addr *mac_addr)
Convert IPv6 multicast address to Ethernet address.
static enum ethernet_hw_caps net_eth_get_hw_capabilities(struct net_if *iface)
Return ethernet device hardware capability information.
Definition: ethernet.h:929
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:996
void net_eth_carrier_on(struct net_if *iface)
Inform ethernet L2 driver that ethernet carrier is detected.
ethernet_checksum_support
Protocols that are supported by checksum offloading.
Definition: ethernet.h:474
static bool net_eth_is_vlan_enabled(struct ethernet_context *ctx, struct net_if *iface)
Check if there are any VLAN interfaces enabled to this specific Ethernet network interface.
Definition: ethernet.h:1087
static struct net_if * net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
Return network interface related to this VLAN tag.
Definition: ethernet.h:1040
void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr, struct net_eth_addr *mac_addr)
Convert IPv4 multicast address to Ethernet address.
const struct net_eth_addr * net_eth_broadcast_addr(void)
Return Ethernet broadcast address.
static bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a LLDP multicast address.
Definition: ethernet.h:853
static bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
Check if the Ethernet MAC address is a PTP multicast address.
Definition: ethernet.h:878
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition: ethernet.h:841
int net_eth_txinjection_mode(struct net_if *iface, bool enable)
Set TX-Injection mode either ON or OFF.
@ L2_ETH_IF_TYPE_ETHERNET
IEEE 802.3 Ethernet (default)
Definition: ethernet.h:439
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition: ethernet.h:442
@ ETHERNET_HW_VLAN
VLAN supported.
Definition: ethernet.h:150
@ ETHERNET_PRIORITY_QUEUES
Priority queues available.
Definition: ethernet.h:177
@ ETHERNET_DUPLEX_SET
Changing duplex (half/full) supported.
Definition: ethernet.h:165
@ ETHERNET_HW_VLAN_TAG_STRIP
VLAN Tag stripping.
Definition: ethernet.h:186
@ ETHERNET_LINK_10BASE_T
10 Mbits link supported
Definition: ethernet.h:156
@ ETHERNET_HW_FILTERING
MAC address filtering supported.
Definition: ethernet.h:180
@ ETHERNET_PTP
IEEE 802.1AS (gPTP) clock supported.
Definition: ethernet.h:168
@ ETHERNET_QBU
IEEE 802.1Qbu (frame preemption) supported.
Definition: ethernet.h:198
@ ETHERNET_LINK_100BASE_T
100 Mbits link supported
Definition: ethernet.h:159
@ ETHERNET_DSA_MASTER_PORT
DSA switch master port.
Definition: ethernet.h:192
@ ETHERNET_DSA_SLAVE_PORT
DSA switch slave port.
Definition: ethernet.h:189
@ ETHERNET_TXINJECTION_MODE
TX-Injection supported.
Definition: ethernet.h:204
@ ETHERNET_QAV
IEEE 802.1Qav (credit-based shaping) supported.
Definition: ethernet.h:171
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
RX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition: ethernet.h:147
@ ETHERNET_LINK_1000BASE_T
1 Gbits link supported
Definition: ethernet.h:162
@ ETHERNET_LLDP
Link Layer Discovery Protocol supported.
Definition: ethernet.h:183
@ ETHERNET_AUTO_NEGOTIATION_SET
Enabling/disabling auto negotiation supported.
Definition: ethernet.h:153
@ ETHERNET_TXTIME
TXTIME supported.
Definition: ethernet.h:201
@ ETHERNET_QBV
IEEE 802.1Qbv (scheduled traffic) supported.
Definition: ethernet.h:195
@ ETHERNET_PROMISC_MODE
Promiscuous mode supported.
Definition: ethernet.h:174
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
TX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition: ethernet.h:144
@ ETHERNET_CHECKSUM_SUPPORT_UDP
Device supports UDP checksum offloading for all supported IP protocols.
Definition: ethernet.h:488
@ ETHERNET_CHECKSUM_SUPPORT_TCP
Device supports TCP checksum offloading for all supported IP protocols.
Definition: ethernet.h:486
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER
Device supports checksum offloading for the IPv6 header.
Definition: ethernet.h:482
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP
Device supports checksum offloading for ICMPv4 payload (implies IPv4 header)
Definition: ethernet.h:480
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER
Device supports checksum offloading for the IPv4 header.
Definition: ethernet.h:478
@ ETHERNET_CHECKSUM_SUPPORT_NONE
Device does not support any L3/L4 checksum offloading.
Definition: ethernet.h:476
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP
Device supports checksum offloading for ICMPv6 payload (implies IPv6 header)
Definition: ethernet.h:484
enum net_verdict(* net_lldp_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
LLDP Receive packet callback.
Definition: lldp.h:213
static void * net_if_l2_data(struct net_if *iface)
Get a pointer to the interface L2 private data.
Definition: net_if.h:926
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition: net_if.h:941
net_l2_flags
L2 flags.
Definition: net_l2.h:34
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define EINVAL
Invalid argument.
Definition: errno.h:60
#define ENOTSUP
Unsupported value.
Definition: errno.h:114
#define ENODEV
No such device.
Definition: errno.h:57
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition: ethernet_vlan.h:30
Public kernel APIs.
LLDP definitions and handler.
Public API for network interface.
IPv6 and IPv4 definitions.
Network packet buffer descriptor API.
flags
Definition: parser.h:96
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT64_TYPE__ int64_t
Definition: stdint.h:75
Runtime device structure (in ROM) per driver instance.
Definition: device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
Ethernet L2 API operations.
Definition: ethernet.h:526
struct net_if_api iface_api
The net_if_api must be placed in first position in this struct so that we are compatible with network...
Definition: ethernet.h:531
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition: ethernet.h:542
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition: ethernet.h:556
int(* stop)(const struct device *dev)
Stop the device.
Definition: ethernet.h:545
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition: ethernet.h:548
int(* send)(const struct device *dev, struct net_pkt *pkt)
The IP stack will call this function when a VLAN tag is enabled or disabled.
Definition: ethernet.h:576
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition: ethernet.h:551
Ethernet filter description.
Definition: ethernet.h:446
struct net_eth_addr mac_address
MAC address to filter.
Definition: ethernet.h:450
bool set
Set (true) or unset (false) the filter.
Definition: ethernet.h:452
enum ethernet_filter_type type
Type of filter.
Definition: ethernet.h:448
Ethernet LLDP specific parameters.
Definition: ethernet.h:611
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition: ethernet.h:619
sys_snode_t node
Used for track timers.
Definition: ethernet.h:613
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition: ethernet.h:634
size_t optional_len
Length of the optional Data Unit TLVs.
Definition: ethernet.h:622
struct net_if * iface
Network interface that has LLDP supported.
Definition: ethernet.h:625
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition: ethernet.h:616
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition: ethernet.h:631
int64_t tx_timer_start
LLDP TX timer start time.
Definition: ethernet.h:628
Ethernet Qav specific parameters.
Definition: ethernet.h:288
bool enabled
True if Qav is enabled for queue.
Definition: ethernet.h:295
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition: ethernet.h:301
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition: ethernet.h:292
unsigned int traffic_class
Traffic class the queue is bound to.
Definition: ethernet.h:303
int queue_id
ID of the priority queue to use.
Definition: ethernet.h:290
unsigned int idle_slope
Idle Slope (bits per second)
Definition: ethernet.h:299
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition: ethernet.h:297
Ethernet Qbu specific parameters.
Definition: ethernet.h:397
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition: ethernet.h:410
uint32_t release_advance
Release advance (nanoseconds)
Definition: ethernet.h:407
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition: ethernet.h:401
uint32_t hold_advance
Hold advance (nanoseconds)
Definition: ethernet.h:404
bool enabled
True if Qbu is enabled or not.
Definition: ethernet.h:414
bool link_partner_status
Link partner status (from Qbr)
Definition: ethernet.h:417
int port_id
Port id.
Definition: ethernet.h:399
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition: ethernet.h:423
Ethernet Qbv specific parameters.
Definition: ethernet.h:330
int port_id
Port id.
Definition: ethernet.h:332
bool enabled
True if Qbv is enabled or not.
Definition: ethernet.h:339
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition: ethernet.h:334
uint16_t row
Gate control list row.
Definition: ethernet.h:353
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition: ethernet.h:336
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition: ethernet.h:344
struct net_ptp_extended_time base_time
Base time.
Definition: ethernet.h:365
uint32_t extension_time
Extension time (nanoseconds)
Definition: ethernet.h:371
enum ethernet_gate_state_operation operation
GateState operation.
Definition: ethernet.h:347
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition: ethernet.h:350
struct net_ptp_time cycle_time
Cycle time.
Definition: ethernet.h:368
struct ethernet_qbv_param::@292::@294 gate_control
Gate control information.
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition: ethernet.h:357
Ethernet T1S specific parameters.
Definition: ethernet.h:243
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition: ethernet.h:278
uint8_t node_count
T1S PLCA node count range: 1 to 255.
Definition: ethernet.h:276
uint8_t to_timer
T1S PLCA TO value.
Definition: ethernet.h:282
uint8_t burst_timer
T1S PLCA burst timer.
Definition: ethernet.h:280
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition: ethernet.h:274
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition: ethernet.h:245
bool enable
T1S PLCA enabled.
Definition: ethernet.h:272
struct ethernet_t1s_param::@287::@289 plca
PLCA is the Physical Layer (PHY) Collision Avoidance technique employed with multidrop 10Base-T1S sta...
Ethernet TXTIME specific parameters.
Definition: ethernet.h:464
bool enable_txtime
Enable or disable TXTIME per queue.
Definition: ethernet.h:470
int queue_id
Queue number for configuring TXTIME.
Definition: ethernet.h:468
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition: ethernet.h:466
IPv6 address struct.
Definition: net_ip.h:139
IPv4 address struct.
Definition: net_ip.h:151
A structure used to submit work.
Definition: kernel.h:3880
Ethernet address.
Definition: ethernet.h:51
uint8_t addr[6U]
Buffer storing the address.
Definition: ethernet.h:52
Network Interface structure.
Definition: net_if.h:678
LLDP Data Unit (LLDPDU) shall contain the following ordered TLVs as stated in "8.2 LLDPDU format" fro...
Definition: lldp.h:167
Network packet.
Definition: net_pkt.h:67
Generalized Precision Time Protocol Extended Timestamp format.
Definition: ptp_time.h:152
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
All Ethernet specific statistics.
Definition: net_stats.h:523
Misc utilities.