Zephyr Project API 4.0.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
50#define NET_ETH_ADDR_LEN 6U
56
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
119#define NET_ETH_MINIMAL_FRAME_SIZE 60
120#define NET_ETH_MTU 1500
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 * Extend the max frame size for DSA (KSZ8794) by one byte (to 1519) to
133 * store tail tag.
134 */
135#if defined(CONFIG_NET_DSA)
136#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
137#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
138#else
139#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
140#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
141#endif
142
143#define NET_ETH_VLAN_HDR_SIZE 4
144
218
221enum ethernet_config_type {
222 ETHERNET_CONFIG_TYPE_AUTO_NEG,
223 ETHERNET_CONFIG_TYPE_LINK,
224 ETHERNET_CONFIG_TYPE_DUPLEX,
225 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
226 ETHERNET_CONFIG_TYPE_QAV_PARAM,
227 ETHERNET_CONFIG_TYPE_QBV_PARAM,
228 ETHERNET_CONFIG_TYPE_QBU_PARAM,
229 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
230 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
231 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
232 ETHERNET_CONFIG_TYPE_FILTER,
233 ETHERNET_CONFIG_TYPE_PORTS_NUM,
234 ETHERNET_CONFIG_TYPE_T1S_PARAM,
235 ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
236 ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
237 ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
238 ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
239};
240
241enum ethernet_qav_param_type {
242 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
243 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
244 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
245 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
246 ETHERNET_QAV_PARAM_TYPE_STATUS,
247};
248
249enum ethernet_t1s_param_type {
250 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
251};
252
258 enum ethernet_t1s_param_type type;
259 union {
283 struct {
285 bool enable;
297 };
298};
299
305 enum ethernet_qav_param_type type;
306 union {
310 unsigned int delta_bandwidth;
312 unsigned int idle_slope;
314 unsigned int oper_idle_slope;
316 unsigned int traffic_class;
317 };
318};
319
322enum ethernet_qbv_param_type {
323 ETHERNET_QBV_PARAM_TYPE_STATUS,
324 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
325 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
326 ETHERNET_QBV_PARAM_TYPE_TIME,
327};
328
329enum ethernet_qbv_state_type {
330 ETHERNET_QBV_STATE_TYPE_ADMIN,
331 ETHERNET_QBV_STATE_TYPE_OPER,
332};
333
334enum ethernet_gate_state_operation {
335 ETHERNET_SET_GATE_STATE,
336 ETHERNET_SET_AND_HOLD_MAC_STATE,
337 ETHERNET_SET_AND_RELEASE_MAC_STATE,
338};
339
347 enum ethernet_qbv_param_type type;
349 enum ethernet_qbv_state_type state;
350 union {
353
355 struct {
357 bool gate_status[NET_TC_TX_COUNT];
358
360 enum ethernet_gate_state_operation operation;
361
364
368
371
376 struct {
379
382
385 };
386 };
387};
388
391enum ethernet_qbu_param_type {
392 ETHERNET_QBU_PARAM_TYPE_STATUS,
393 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
394 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
395 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
396
397 /* Some preemption settings are from Qbr spec. */
398 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
399 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
400};
401
402enum ethernet_qbu_preempt_status {
403 ETHERNET_QBU_STATUS_EXPRESS,
404 ETHERNET_QBU_STATUS_PREEMPTABLE
405} __packed;
406
414 enum ethernet_qbu_param_type type;
415 union {
418
421
423 enum ethernet_qbu_preempt_status
424 frame_preempt_statuses[NET_TC_TX_COUNT];
425
428
431
437 };
438};
439
442enum ethernet_filter_type {
443 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
444 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
445};
446
457
461 enum ethernet_filter_type type;
465 bool set;
466};
467
470enum ethernet_txtime_param_type {
471 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
472};
473
479 enum ethernet_txtime_param_type type;
484};
485
489 ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
491 ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
493 ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
495 ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
497 ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
499 ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
501 ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
502};
503
506struct ethernet_config {
507 union {
508 bool auto_negotiation;
509 bool full_duplex;
510 bool promisc_mode;
511 bool txinjection_mode;
512
513 struct {
514 bool link_10bt;
515 bool link_100bt;
516 bool link_1000bt;
517 } l;
518
519 struct net_eth_addr mac_address;
520
521 struct ethernet_t1s_param t1s_param;
522 struct ethernet_qav_param qav_param;
523 struct ethernet_qbv_param qbv_param;
524 struct ethernet_qbu_param qbu_param;
525 struct ethernet_txtime_param txtime_param;
526
527 int priority_queues_num;
528 int ports_num;
529
530 enum ethernet_checksum_support chksum_support;
531
532 struct ethernet_filter filter;
533
534 uint16_t extra_tx_pkt_headroom;
535 };
536};
537
546 struct net_if_api iface_api;
547
552#if defined(CONFIG_NET_STATISTICS_ETHERNET)
553 struct net_stats_eth *(*get_stats)(const struct device *dev);
554#endif
555
557 int (*start)(const struct device *dev);
558
560 int (*stop)(const struct device *dev);
561
563 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
564
566 int (*set_config)(const struct device *dev,
567 enum ethernet_config_type type,
568 const struct ethernet_config *config);
569
571 int (*get_config)(const struct device *dev,
572 enum ethernet_config_type type,
573 struct ethernet_config *config);
574
580#if defined(CONFIG_NET_VLAN)
581 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
582 uint16_t tag, bool enable);
583#endif /* CONFIG_NET_VLAN */
584
586#if defined(CONFIG_PTP_CLOCK)
587 const struct device *(*get_ptp_clock)(const struct device *dev);
588#endif /* CONFIG_PTP_CLOCK */
589
591 const struct device *(*get_phy)(const struct device *dev);
592
594 int (*send)(const struct device *dev, struct net_pkt *pkt);
595};
596
599/* Make sure that the network interface API is properly setup inside
600 * Ethernet API struct (it is the first one).
601 */
602BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
603
604struct net_eth_hdr {
605 struct net_eth_addr dst;
606 struct net_eth_addr src;
607 uint16_t type;
608} __packed;
609
610struct ethernet_vlan {
612 struct net_if *iface;
613
615 uint16_t tag;
616};
617
618#if defined(CONFIG_NET_VLAN_COUNT)
619#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
620#else
621#define NET_VLAN_MAX_COUNT 0
622#endif
623
652
655enum ethernet_flags {
656 ETH_CARRIER_UP,
657};
658
660struct ethernet_context {
665
666#if defined(CONFIG_NET_ETHERNET_BRIDGE)
667 struct net_if *bridge;
668#endif
669
676 struct k_work carrier_work;
677
679 struct net_if *iface;
680
681#if defined(CONFIG_NET_LLDP)
682#if NET_VLAN_MAX_COUNT > 0
683#define NET_LLDP_MAX_COUNT NET_VLAN_MAX_COUNT
684#else
685#define NET_LLDP_MAX_COUNT 1
686#endif /* NET_VLAN_MAX_COUNT > 0 */
687
689 struct ethernet_lldp lldp[NET_LLDP_MAX_COUNT];
690#endif
691
695 enum net_l2_flags ethernet_l2_flags;
696
697#if defined(CONFIG_NET_L2_PTP)
702 int port;
703#endif
704
705#if defined(CONFIG_NET_DSA)
709 dsa_net_recv_cb_t dsa_recv_cb;
710
712 uint8_t dsa_port_idx;
713
715 struct dsa_context *dsa_ctx;
716
718 dsa_send_t dsa_send;
719#endif
720
722 bool is_net_carrier_up : 1;
723
725 bool is_init : 1;
726
728 enum ethernet_if_types eth_if_type;
729};
730
736void ethernet_init(struct net_if *iface);
737
738#define ETHERNET_L2_CTX_TYPE struct ethernet_context
739
740/* Separate header for VLAN as some of device interfaces might not
741 * support VLAN.
742 */
743struct net_eth_vlan_hdr {
744 struct net_eth_addr dst;
745 struct net_eth_addr src;
746 struct {
747 uint16_t tpid; /* tag protocol id */
748 uint16_t tci; /* tag control info */
749 } vlan;
750 uint16_t type;
751} __packed;
752
762static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
763{
764 if (addr->addr[0] == 0xff &&
765 addr->addr[1] == 0xff &&
766 addr->addr[2] == 0xff &&
767 addr->addr[3] == 0xff &&
768 addr->addr[4] == 0xff &&
769 addr->addr[5] == 0xff) {
770 return true;
771 }
772
773 return false;
774}
775
783static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
784{
785 if (addr->addr[0] == 0x00 &&
786 addr->addr[1] == 0x00 &&
787 addr->addr[2] == 0x00 &&
788 addr->addr[3] == 0x00 &&
789 addr->addr[4] == 0x00 &&
790 addr->addr[5] == 0x00) {
791 return true;
792 }
793
794 return false;
795}
796
804static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
805{
806 if (addr->addr[0] == 0x00 &&
807 addr->addr[1] == 0x00 &&
808 addr->addr[2] == 0x00 &&
809 addr->addr[3] == 0x00 &&
810 addr->addr[4] == 0x00 &&
811 addr->addr[5] == 0x00) {
812 return true;
813 }
814
815 return false;
816}
817
825static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
826{
827#if defined(CONFIG_NET_IPV6)
828 if (addr->addr[0] == 0x33 &&
829 addr->addr[1] == 0x33) {
830 return true;
831 }
832#endif
833
834#if defined(CONFIG_NET_IPV4)
835 if (addr->addr[0] == 0x01 &&
836 addr->addr[1] == 0x00 &&
837 addr->addr[2] == 0x5e) {
838 return true;
839 }
840#endif
841
842 return false;
843}
844
852static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
853{
854 return addr->addr[0] & 0x01;
855}
856
864static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
865{
867}
868
876static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
877{
878#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
879 if (addr->addr[0] == 0x01 &&
880 addr->addr[1] == 0x80 &&
881 addr->addr[2] == 0xc2 &&
882 addr->addr[3] == 0x00 &&
883 addr->addr[4] == 0x00 &&
884 addr->addr[5] == 0x0e) {
885 return true;
886 }
887#else
888 ARG_UNUSED(addr);
889#endif
890
891 return false;
892}
893
901static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
902{
903#if defined(CONFIG_NET_GPTP)
904 if (addr->addr[0] == 0x01 &&
905 addr->addr[1] == 0x1b &&
906 addr->addr[2] == 0x19 &&
907 addr->addr[3] == 0x00 &&
908 addr->addr[4] == 0x00 &&
909 addr->addr[5] == 0x00) {
910 return true;
911 }
912#else
913 ARG_UNUSED(addr);
914#endif
915
916 return false;
917}
918
925
932void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
933 struct net_eth_addr *mac_addr);
934
941void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
942 struct net_eth_addr *mac_addr);
943
951static inline
953{
954 const struct device *dev = net_if_get_device(iface);
955 const struct ethernet_api *api = (struct ethernet_api *)dev->api;
956
957 if (!api || !api->get_capabilities) {
958 return (enum ethernet_hw_caps)0;
959 }
960
961 return api->get_capabilities(dev);
962}
963
973static inline
974int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
975 struct ethernet_config *config)
976{
977 const struct ethernet_api *eth =
978 (struct ethernet_api *)net_if_get_device(iface)->api;
979
980 if (!eth->get_config) {
981 return -ENOTSUP;
982 }
983
984 return eth->get_config(net_if_get_device(iface), type, config);
985}
986
987
996#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
997int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
998#else
999static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
1000{
1001 ARG_UNUSED(iface);
1002 ARG_UNUSED(tag);
1003
1004 return -EINVAL;
1005}
1006#endif
1007
1016#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1017int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
1018#else
1019static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
1020{
1021 ARG_UNUSED(iface);
1022 ARG_UNUSED(tag);
1023
1024 return -EINVAL;
1025}
1026#endif
1027
1039#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1040uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1041#else
1042static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1043{
1044 ARG_UNUSED(iface);
1045
1046 return NET_VLAN_TAG_UNSPEC;
1047}
1048#endif
1049
1059#if defined(CONFIG_NET_VLAN)
1060struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1061#else
1062static inline
1064{
1065 ARG_UNUSED(iface);
1066 ARG_UNUSED(tag);
1067
1068 return NULL;
1069}
1070#endif
1071
1081#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1082struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1083#else
1084static inline
1086{
1087 ARG_UNUSED(iface);
1088
1089 return NULL;
1090}
1091#endif
1092
1106#if defined(CONFIG_NET_VLAN)
1107bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1108 struct net_if *iface);
1109#else
1110static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1111 struct net_if *iface)
1112{
1113 ARG_UNUSED(ctx);
1114 ARG_UNUSED(iface);
1115
1116 return false;
1117}
1118#endif
1119
1127#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1128bool net_eth_get_vlan_status(struct net_if *iface);
1129#else
1130static inline bool net_eth_get_vlan_status(struct net_if *iface)
1131{
1132 ARG_UNUSED(iface);
1133
1134 return false;
1135}
1136#endif
1137
1145#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1146bool net_eth_is_vlan_interface(struct net_if *iface);
1147#else
1148static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1149{
1150 ARG_UNUSED(iface);
1151
1152 return false;
1153}
1154#endif
1155
1158#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1159
1160#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1161 init_fn, pm, data, config, prio, \
1162 api, mtu) \
1163 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1164 init_fn, pm, data, config, prio, \
1165 api, ETHERNET_L2, \
1166 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1167
1168#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1169
1170#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1171 init_fn, pm, data, config, prio, \
1172 api, mtu) \
1173 Z_DEVICE_STATE_DEFINE(dev_id); \
1174 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
1175 config, POST_KERNEL, prio, api, \
1176 &Z_DEVICE_STATE_NAME(dev_id));
1177
1178#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1179
1180#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1181 config, prio, api, mtu) \
1182 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1183 init_fn, pm, data, config, prio, \
1184 api, mtu)
1185
1205#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1206 prio, api, mtu) \
1207 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1208 pm, data, config, prio, api, mtu)
1209
1232#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1233 pm, data, config, prio, api, mtu) \
1234 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1235 instance, init_fn, pm, data, \
1236 config, prio, api, mtu)
1237
1254#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1255 prio, api, mtu) \
1256 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1257 DEVICE_DT_NAME(node_id), init_fn, pm, \
1258 data, config, prio, api, mtu)
1259
1269#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1270 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1271
1279#define ETH_NET_L3_REGISTER(name, ptype, handler) \
1280 NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
1281
1288void net_eth_carrier_on(struct net_if *iface);
1289
1296void net_eth_carrier_off(struct net_if *iface);
1297
1307int net_eth_promisc_mode(struct net_if *iface, bool enable);
1308
1318int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1319
1330int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1331 enum ethernet_filter_type type, bool enable);
1332
1340const struct device *net_eth_get_phy(struct net_if *iface);
1341
1350#if defined(CONFIG_PTP_CLOCK)
1351const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1352#else
1353static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1354{
1355 ARG_UNUSED(iface);
1356
1357 return NULL;
1358}
1359#endif
1360
1370__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1371
1379#if defined(CONFIG_NET_L2_PTP)
1380int net_eth_get_ptp_port(struct net_if *iface);
1381#else
1382static inline int net_eth_get_ptp_port(struct net_if *iface)
1383{
1384 ARG_UNUSED(iface);
1385
1386 return -ENODEV;
1387}
1388#endif /* CONFIG_NET_L2_PTP */
1389
1396#if defined(CONFIG_NET_L2_PTP)
1397void net_eth_set_ptp_port(struct net_if *iface, int port);
1398#else
1399static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1400{
1401 ARG_UNUSED(iface);
1402 ARG_UNUSED(port);
1403}
1404#endif /* CONFIG_NET_L2_PTP */
1405
1413static inline bool net_eth_type_is_wifi(struct net_if *iface)
1414{
1415 const struct ethernet_context *ctx = (struct ethernet_context *)
1416 net_if_l2_data(iface);
1417
1418 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1419}
1420
1425#ifdef __cplusplus
1426}
1427#endif
1428
1429#include <zephyr/syscalls/ethernet.h>
1430
1431#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:70
int(* dsa_send_t)(const struct device *dev, struct net_pkt *pkt)
Pointer to master interface send function.
Definition dsa.h:96
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:1085
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:974
ethernet_if_types
Types of Ethernet L2.
Definition ethernet.h:450
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition ethernet.h:1399
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition ethernet.h:999
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:783
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:825
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition ethernet.h:1382
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:1353
#define NET_ETH_ADDR_LEN
Ethernet MAC address length.
Definition ethernet.h:50
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:1042
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:1413
const struct device * net_eth_get_phy(struct net_if *iface)
Return the PHY device that is tied to this ethernet network interface.
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:762
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:1130
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:852
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:804
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition ethernet.h:1148
ethernet_hw_caps
Ethernet hardware capabilities.
Definition ethernet.h:148
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:952
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition ethernet.h:1019
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:487
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:1110
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:1063
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:876
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:901
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition ethernet.h:864
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:452
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition ethernet.h:455
@ ETHERNET_HW_VLAN
VLAN supported.
Definition ethernet.h:156
@ ETHERNET_PRIORITY_QUEUES
Priority queues available.
Definition ethernet.h:183
@ ETHERNET_DUPLEX_SET
Changing duplex (half/full) supported.
Definition ethernet.h:171
@ ETHERNET_HW_VLAN_TAG_STRIP
VLAN Tag stripping.
Definition ethernet.h:192
@ ETHERNET_LINK_10BASE_T
10 Mbits link supported
Definition ethernet.h:162
@ ETHERNET_HW_FILTERING
MAC address filtering supported.
Definition ethernet.h:186
@ ETHERNET_PTP
IEEE 802.1AS (gPTP) clock supported.
Definition ethernet.h:174
@ ETHERNET_LINK_2500BASE_T
2.5 Gbits link supported
Definition ethernet.h:213
@ ETHERNET_QBU
IEEE 802.1Qbu (frame preemption) supported.
Definition ethernet.h:204
@ ETHERNET_LINK_100BASE_T
100 Mbits link supported
Definition ethernet.h:165
@ ETHERNET_DSA_MASTER_PORT
DSA switch master port.
Definition ethernet.h:198
@ ETHERNET_DSA_SLAVE_PORT
DSA switch slave port.
Definition ethernet.h:195
@ ETHERNET_TXINJECTION_MODE
TX-Injection supported.
Definition ethernet.h:210
@ ETHERNET_QAV
IEEE 802.1Qav (credit-based shaping) supported.
Definition ethernet.h:177
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
RX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition ethernet.h:153
@ ETHERNET_LINK_1000BASE_T
1 Gbits link supported
Definition ethernet.h:168
@ ETHERNET_LLDP
Link Layer Discovery Protocol supported.
Definition ethernet.h:189
@ ETHERNET_AUTO_NEGOTIATION_SET
Enabling/disabling auto negotiation supported.
Definition ethernet.h:159
@ ETHERNET_LINK_5000BASE_T
5 Gbits link supported
Definition ethernet.h:216
@ ETHERNET_TXTIME
TXTIME supported.
Definition ethernet.h:207
@ ETHERNET_QBV
IEEE 802.1Qbv (scheduled traffic) supported.
Definition ethernet.h:201
@ ETHERNET_PROMISC_MODE
Promiscuous mode supported.
Definition ethernet.h:180
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
TX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition ethernet.h:150
@ ETHERNET_CHECKSUM_SUPPORT_UDP
Device supports UDP checksum offloading for all supported IP protocols.
Definition ethernet.h:501
@ ETHERNET_CHECKSUM_SUPPORT_TCP
Device supports TCP checksum offloading for all supported IP protocols.
Definition ethernet.h:499
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER
Device supports checksum offloading for the IPv6 header.
Definition ethernet.h:495
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP
Device supports checksum offloading for ICMPv4 payload (implies IPv4 header)
Definition ethernet.h:493
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER
Device supports checksum offloading for the IPv4 header.
Definition ethernet.h:491
@ ETHERNET_CHECKSUM_SUPPORT_NONE
Device does not support any L3/L4 checksum offloading.
Definition ethernet.h:489
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP
Device supports checksum offloading for ICMPv6 payload (implies IPv6 header)
Definition ethernet.h:497
enum net_verdict(* net_lldp_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
LLDP Receive packet callback.
Definition lldp.h:215
static void * net_if_l2_data(struct net_if *iface)
Get a pointer to the interface L2 private data.
Definition net_if.h:954
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:970
net_l2_flags
L2 flags.
Definition net_l2.h:37
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:32
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:97
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:453
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:459
Ethernet L2 API operations.
Definition ethernet.h:541
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:546
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition ethernet.h:557
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition ethernet.h:571
int(* stop)(const struct device *dev)
Stop the device.
Definition ethernet.h:560
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition ethernet.h:563
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition ethernet.h:594
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition ethernet.h:566
Ethernet filter description.
Definition ethernet.h:459
struct net_eth_addr mac_address
MAC address to filter.
Definition ethernet.h:463
bool set
Set (true) or unset (false) the filter.
Definition ethernet.h:465
enum ethernet_filter_type type
Type of filter.
Definition ethernet.h:461
Ethernet LLDP specific parameters.
Definition ethernet.h:627
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition ethernet.h:635
sys_snode_t node
Used for track timers.
Definition ethernet.h:629
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition ethernet.h:650
size_t optional_len
Length of the optional Data Unit TLVs.
Definition ethernet.h:638
struct net_if * iface
Network interface that has LLDP supported.
Definition ethernet.h:641
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition ethernet.h:632
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition ethernet.h:647
int64_t tx_timer_start
LLDP TX timer start time.
Definition ethernet.h:644
Ethernet Qav specific parameters.
Definition ethernet.h:301
bool enabled
True if Qav is enabled for queue.
Definition ethernet.h:308
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition ethernet.h:314
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition ethernet.h:305
unsigned int traffic_class
Traffic class the queue is bound to.
Definition ethernet.h:316
int queue_id
ID of the priority queue to use.
Definition ethernet.h:303
unsigned int idle_slope
Idle Slope (bits per second)
Definition ethernet.h:312
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition ethernet.h:310
Ethernet Qbu specific parameters.
Definition ethernet.h:410
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition ethernet.h:423
uint32_t release_advance
Release advance (nanoseconds)
Definition ethernet.h:420
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition ethernet.h:414
uint32_t hold_advance
Hold advance (nanoseconds)
Definition ethernet.h:417
bool enabled
True if Qbu is enabled or not.
Definition ethernet.h:427
bool link_partner_status
Link partner status (from Qbr)
Definition ethernet.h:430
int port_id
Port id.
Definition ethernet.h:412
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition ethernet.h:436
Ethernet Qbv specific parameters.
Definition ethernet.h:343
int port_id
Port id.
Definition ethernet.h:345
bool enabled
True if Qbv is enabled or not.
Definition ethernet.h:352
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition ethernet.h:347
uint16_t row
Gate control list row.
Definition ethernet.h:366
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition ethernet.h:349
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition ethernet.h:357
struct net_ptp_extended_time base_time
Base time.
Definition ethernet.h:378
uint32_t extension_time
Extension time (nanoseconds)
Definition ethernet.h:384
enum ethernet_gate_state_operation operation
GateState operation.
Definition ethernet.h:360
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition ethernet.h:363
struct net_ptp_time cycle_time
Cycle time.
Definition ethernet.h:381
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition ethernet.h:370
struct ethernet_qbv_param::@352::@354 gate_control
Gate control information.
Ethernet T1S specific parameters.
Definition ethernet.h:256
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition ethernet.h:291
uint8_t node_count
T1S PLCA node count range: 1 to 255.
Definition ethernet.h:289
uint8_t to_timer
T1S PLCA TO value.
Definition ethernet.h:295
uint8_t burst_timer
T1S PLCA burst timer.
Definition ethernet.h:293
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition ethernet.h:287
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition ethernet.h:258
struct ethernet_t1s_param::@347::@349 plca
PLCA is the Physical Layer (PHY) Collision Avoidance technique employed with multidrop 10Base-T1S sta...
bool enable
T1S PLCA enabled.
Definition ethernet.h:285
Ethernet TXTIME specific parameters.
Definition ethernet.h:477
bool enable_txtime
Enable or disable TXTIME per queue.
Definition ethernet.h:483
int queue_id
Queue number for configuring TXTIME.
Definition ethernet.h:481
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition ethernet.h:479
IPv6 address struct.
Definition net_ip.h:143
IPv4 address struct.
Definition net_ip.h:155
A structure used to submit work.
Definition kernel.h:4006
Ethernet address.
Definition ethernet.h:53
uint8_t addr[6U]
Buffer storing the address.
Definition ethernet.h:54
Network Interface structure.
Definition net_if.h:698
LLDP Data Unit (LLDPDU) shall contain the following ordered TLVs as stated in "8.2 LLDPDU format" fro...
Definition lldp.h:169
Network packet.
Definition net_pkt.h:91
Generalized Precision Time Protocol Extended Timestamp format.
Definition ptp_time.h:154
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
All Ethernet specific statistics.
Definition net_stats.h:593
Misc utilities.