Zephyr Project API 4.1.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_DEPRECATED)
30#include <zephyr/net/dsa.h>
31#else
32#include <zephyr/net/dsa_core.h>
33#endif
34
35#if defined(CONFIG_NET_ETHERNET_BRIDGE)
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
52#define NET_ETH_ADDR_LEN 6U
58
61#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
62
63/* zephyr-keep-sorted-start */
64#define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
65#define NET_ETH_PTYPE_ARP 0x0806
66#define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
67#define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
68#define NET_ETH_PTYPE_EAPOL 0x888e
69#define NET_ETH_PTYPE_ECAT 0x88a4
70#define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
71#define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
72#define NET_ETH_PTYPE_IP 0x0800
73#define NET_ETH_PTYPE_IPV6 0x86dd
74#define NET_ETH_PTYPE_LLDP 0x88cc
75#define NET_ETH_PTYPE_PTP 0x88f7
76#define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
77#define NET_ETH_PTYPE_VLAN 0x8100
78/* zephyr-keep-sorted-stop */
79
80/* zephyr-keep-sorted-start re(^#define) */
81#if !defined(ETH_P_8021Q)
82#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
83#endif
84#if !defined(ETH_P_ALL)
85#define ETH_P_ALL NET_ETH_PTYPE_ALL
86#endif
87#if !defined(ETH_P_ARP)
88#define ETH_P_ARP NET_ETH_PTYPE_ARP
89#endif
90#if !defined(ETH_P_CAN)
91#define ETH_P_CAN NET_ETH_PTYPE_CAN
92#endif
93#if !defined(ETH_P_CANFD)
94#define ETH_P_CANFD NET_ETH_PTYPE_CANFD
95#endif
96#if !defined(ETH_P_EAPOL)
97#define ETH_P_EAPOL NET_ETH_PTYPE_EAPOL
98#endif
99#if !defined(ETH_P_ECAT)
100#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
101#endif
102#if !defined(ETH_P_HDLC)
103#define ETH_P_HDLC NET_ETH_PTYPE_HDLC
104#endif
105#if !defined(ETH_P_IEEE802154)
106#define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
107#endif
108#if !defined(ETH_P_IP)
109#define ETH_P_IP NET_ETH_PTYPE_IP
110#endif
111#if !defined(ETH_P_IPV6)
112#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
113#endif
114#if !defined(ETH_P_TSN)
115#define ETH_P_TSN NET_ETH_PTYPE_TSN
116#endif
117/* zephyr-keep-sorted-stop */
118
121#define NET_ETH_MINIMAL_FRAME_SIZE 60
122#define NET_ETH_MTU 1500
126#if defined(CONFIG_NET_VLAN)
127#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_vlan_hdr))
128#else
129#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
130#endif
131
132#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + _NET_ETH_MAX_HDR_SIZE)
133
134#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
135#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
136
137#define NET_ETH_VLAN_HDR_SIZE 4
138
212
215enum ethernet_config_type {
216 ETHERNET_CONFIG_TYPE_AUTO_NEG,
217 ETHERNET_CONFIG_TYPE_LINK,
218 ETHERNET_CONFIG_TYPE_DUPLEX,
219 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
220 ETHERNET_CONFIG_TYPE_QAV_PARAM,
221 ETHERNET_CONFIG_TYPE_QBV_PARAM,
222 ETHERNET_CONFIG_TYPE_QBU_PARAM,
223 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
224 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
225 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
226 ETHERNET_CONFIG_TYPE_FILTER,
227 ETHERNET_CONFIG_TYPE_PORTS_NUM,
228 ETHERNET_CONFIG_TYPE_T1S_PARAM,
229 ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
230 ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
231 ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
232 ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
233};
234
235enum ethernet_qav_param_type {
236 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
237 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
238 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
239 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
240 ETHERNET_QAV_PARAM_TYPE_STATUS,
241};
242
243enum ethernet_t1s_param_type {
244 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
245};
246
252 enum ethernet_t1s_param_type type;
253 union {
277 struct {
279 bool enable;
291 };
292};
293
299 enum ethernet_qav_param_type type;
300 union {
304 unsigned int delta_bandwidth;
306 unsigned int idle_slope;
308 unsigned int oper_idle_slope;
310 unsigned int traffic_class;
311 };
312};
313
316enum ethernet_qbv_param_type {
317 ETHERNET_QBV_PARAM_TYPE_STATUS,
318 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
319 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
320 ETHERNET_QBV_PARAM_TYPE_TIME,
321};
322
323enum ethernet_qbv_state_type {
324 ETHERNET_QBV_STATE_TYPE_ADMIN,
325 ETHERNET_QBV_STATE_TYPE_OPER,
326};
327
328enum ethernet_gate_state_operation {
329 ETHERNET_SET_GATE_STATE,
330 ETHERNET_SET_AND_HOLD_MAC_STATE,
331 ETHERNET_SET_AND_RELEASE_MAC_STATE,
332};
333
341 enum ethernet_qbv_param_type type;
343 enum ethernet_qbv_state_type state;
344 union {
347
349 struct {
351 bool gate_status[NET_TC_TX_COUNT];
352
354 enum ethernet_gate_state_operation operation;
355
358
362
365
370 struct {
373
376
379 };
380 };
381};
382
385enum ethernet_qbu_param_type {
386 ETHERNET_QBU_PARAM_TYPE_STATUS,
387 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
388 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
389 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
390
391 /* Some preemption settings are from Qbr spec. */
392 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
393 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
394};
395
396enum ethernet_qbu_preempt_status {
397 ETHERNET_QBU_STATUS_EXPRESS,
398 ETHERNET_QBU_STATUS_PREEMPTABLE
399} __packed;
400
408 enum ethernet_qbu_param_type type;
409 union {
412
415
417 enum ethernet_qbu_preempt_status
418 frame_preempt_statuses[NET_TC_TX_COUNT];
419
422
425
431 };
432};
433
436enum ethernet_filter_type {
437 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
438 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
439};
440
451
455 enum ethernet_filter_type type;
459 bool set;
460};
461
464enum ethernet_txtime_param_type {
465 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
466};
467
473 enum ethernet_txtime_param_type type;
478};
479
483 ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
485 ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
487 ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
489 ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
491 ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
493 ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
495 ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
496};
497
500struct ethernet_config {
501 union {
502 bool auto_negotiation;
503 bool full_duplex;
504 bool promisc_mode;
505 bool txinjection_mode;
506
507 struct {
508 bool link_10bt;
509 bool link_100bt;
510 bool link_1000bt;
511 } l;
512
513 struct net_eth_addr mac_address;
514
515 struct ethernet_t1s_param t1s_param;
516 struct ethernet_qav_param qav_param;
517 struct ethernet_qbv_param qbv_param;
518 struct ethernet_qbu_param qbu_param;
519 struct ethernet_txtime_param txtime_param;
520
521 int priority_queues_num;
522 int ports_num;
523
524 enum ethernet_checksum_support chksum_support;
525
526 struct ethernet_filter filter;
527
528 uint16_t extra_tx_pkt_headroom;
529 };
530};
531
540 struct net_if_api iface_api;
541
546#if defined(CONFIG_NET_STATISTICS_ETHERNET)
547 struct net_stats_eth *(*get_stats)(const struct device *dev);
548#endif
549
551 int (*start)(const struct device *dev);
552
554 int (*stop)(const struct device *dev);
555
557 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
558
560 int (*set_config)(const struct device *dev,
561 enum ethernet_config_type type,
562 const struct ethernet_config *config);
563
565 int (*get_config)(const struct device *dev,
566 enum ethernet_config_type type,
567 struct ethernet_config *config);
568
574#if defined(CONFIG_NET_VLAN)
575 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
576 uint16_t tag, bool enable);
577#endif /* CONFIG_NET_VLAN */
578
580#if defined(CONFIG_PTP_CLOCK)
581 const struct device *(*get_ptp_clock)(const struct device *dev);
582#endif /* CONFIG_PTP_CLOCK */
583
585 const struct device *(*get_phy)(const struct device *dev);
586
588 int (*send)(const struct device *dev, struct net_pkt *pkt);
589};
590
593/* Make sure that the network interface API is properly setup inside
594 * Ethernet API struct (it is the first one).
595 */
596BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
597
598struct net_eth_hdr {
599 struct net_eth_addr dst;
600 struct net_eth_addr src;
601 uint16_t type;
602} __packed;
603
604struct ethernet_vlan {
606 struct net_if *iface;
607
609 uint16_t tag;
610};
611
612#if defined(CONFIG_NET_VLAN_COUNT)
613#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
614#else
615#define NET_VLAN_MAX_COUNT 0
616#endif
617
646
649enum ethernet_flags {
650 ETH_CARRIER_UP,
651};
652
654struct ethernet_context {
659
660#if defined(CONFIG_NET_ETHERNET_BRIDGE)
661 struct net_if *bridge;
662#endif
663
670 struct k_work carrier_work;
671
673 struct net_if *iface;
674
675#if defined(CONFIG_NET_LLDP)
676#if NET_VLAN_MAX_COUNT > 0
677#define NET_LLDP_MAX_COUNT NET_VLAN_MAX_COUNT
678#else
679#define NET_LLDP_MAX_COUNT 1
680#endif /* NET_VLAN_MAX_COUNT > 0 */
681
683 struct ethernet_lldp lldp[NET_LLDP_MAX_COUNT];
684#endif
685
689 enum net_l2_flags ethernet_l2_flags;
690
691#if defined(CONFIG_NET_L2_PTP)
696 int port;
697#endif
698
699#if defined(CONFIG_NET_DSA_DEPRECATED)
703 dsa_net_recv_cb_t dsa_recv_cb;
704
706 uint8_t dsa_port_idx;
707
709 struct dsa_context *dsa_ctx;
710
712 dsa_send_t dsa_send;
713
714#elif defined(CONFIG_NET_DSA)
716 enum dsa_port_type dsa_port;
717
719 struct dsa_switch_context *dsa_switch_ctx;
720#endif
721
723 bool is_net_carrier_up : 1;
724
726 bool is_init : 1;
727
729 enum ethernet_if_types eth_if_type;
730};
731
737void ethernet_init(struct net_if *iface);
738
739#define ETHERNET_L2_CTX_TYPE struct ethernet_context
740
741/* Separate header for VLAN as some of device interfaces might not
742 * support VLAN.
743 */
744struct net_eth_vlan_hdr {
745 struct net_eth_addr dst;
746 struct net_eth_addr src;
747 struct {
748 uint16_t tpid; /* tag protocol id */
749 uint16_t tci; /* tag control info */
750 } vlan;
751 uint16_t type;
752} __packed;
753
763static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
764{
765 if (addr->addr[0] == 0xff &&
766 addr->addr[1] == 0xff &&
767 addr->addr[2] == 0xff &&
768 addr->addr[3] == 0xff &&
769 addr->addr[4] == 0xff &&
770 addr->addr[5] == 0xff) {
771 return true;
772 }
773
774 return false;
775}
776
784static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
785{
786 if (addr->addr[0] == 0x00 &&
787 addr->addr[1] == 0x00 &&
788 addr->addr[2] == 0x00 &&
789 addr->addr[3] == 0x00 &&
790 addr->addr[4] == 0x00 &&
791 addr->addr[5] == 0x00) {
792 return true;
793 }
794
795 return false;
796}
797
805static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
806{
807 if (addr->addr[0] == 0x00 &&
808 addr->addr[1] == 0x00 &&
809 addr->addr[2] == 0x00 &&
810 addr->addr[3] == 0x00 &&
811 addr->addr[4] == 0x00 &&
812 addr->addr[5] == 0x00) {
813 return true;
814 }
815
816 return false;
817}
818
826static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
827{
828#if defined(CONFIG_NET_IPV6)
829 if (addr->addr[0] == 0x33 &&
830 addr->addr[1] == 0x33) {
831 return true;
832 }
833#endif
834
835#if defined(CONFIG_NET_IPV4)
836 if (addr->addr[0] == 0x01 &&
837 addr->addr[1] == 0x00 &&
838 addr->addr[2] == 0x5e) {
839 return true;
840 }
841#endif
842
843 return false;
844}
845
853static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
854{
855 return addr->addr[0] & 0x01;
856}
857
865static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
866{
868}
869
877static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
878{
879#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
880 if (addr->addr[0] == 0x01 &&
881 addr->addr[1] == 0x80 &&
882 addr->addr[2] == 0xc2 &&
883 addr->addr[3] == 0x00 &&
884 addr->addr[4] == 0x00 &&
885 addr->addr[5] == 0x0e) {
886 return true;
887 }
888#else
889 ARG_UNUSED(addr);
890#endif
891
892 return false;
893}
894
902static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
903{
904#if defined(CONFIG_NET_GPTP)
905 if (addr->addr[0] == 0x01 &&
906 addr->addr[1] == 0x1b &&
907 addr->addr[2] == 0x19 &&
908 addr->addr[3] == 0x00 &&
909 addr->addr[4] == 0x00 &&
910 addr->addr[5] == 0x00) {
911 return true;
912 }
913#else
914 ARG_UNUSED(addr);
915#endif
916
917 return false;
918}
919
926
933void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
934 struct net_eth_addr *mac_addr);
935
942void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
943 struct net_eth_addr *mac_addr);
944
952static inline
954{
955 const struct device *dev = net_if_get_device(iface);
956 const struct ethernet_api *api = (struct ethernet_api *)dev->api;
957 enum ethernet_hw_caps caps = (enum ethernet_hw_caps)0;
958#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
959 struct ethernet_context *eth_ctx = net_if_l2_data(iface);
960
961 if (eth_ctx->dsa_port == DSA_CONDUIT_PORT) {
963 } else if (eth_ctx->dsa_port == DSA_USER_PORT) {
965 }
966#endif
967 if (api == NULL || api->get_capabilities == NULL) {
968 return caps;
969 }
970
971 return (enum ethernet_hw_caps)(caps | api->get_capabilities(dev));
972}
973
983static inline
984int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
985 struct ethernet_config *config)
986{
987 const struct ethernet_api *eth =
988 (struct ethernet_api *)net_if_get_device(iface)->api;
989
990 if (!eth->get_config) {
991 return -ENOTSUP;
992 }
993
994 return eth->get_config(net_if_get_device(iface), type, config);
995}
996
997
1006#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1007int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
1008#else
1009static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
1010{
1011 ARG_UNUSED(iface);
1012 ARG_UNUSED(tag);
1013
1014 return -EINVAL;
1015}
1016#endif
1017
1026#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1027int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
1028#else
1029static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
1030{
1031 ARG_UNUSED(iface);
1032 ARG_UNUSED(tag);
1033
1034 return -EINVAL;
1035}
1036#endif
1037
1049#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1050uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1051#else
1052static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1053{
1054 ARG_UNUSED(iface);
1055
1056 return NET_VLAN_TAG_UNSPEC;
1057}
1058#endif
1059
1069#if defined(CONFIG_NET_VLAN)
1070struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1071#else
1072static inline
1074{
1075 ARG_UNUSED(iface);
1076 ARG_UNUSED(tag);
1077
1078 return NULL;
1079}
1080#endif
1081
1091#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1092struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1093#else
1094static inline
1096{
1097 ARG_UNUSED(iface);
1098
1099 return NULL;
1100}
1101#endif
1102
1116#if defined(CONFIG_NET_VLAN)
1117bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1118 struct net_if *iface);
1119#else
1120static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1121 struct net_if *iface)
1122{
1123 ARG_UNUSED(ctx);
1124 ARG_UNUSED(iface);
1125
1126 return false;
1127}
1128#endif
1129
1137#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1138bool net_eth_get_vlan_status(struct net_if *iface);
1139#else
1140static inline bool net_eth_get_vlan_status(struct net_if *iface)
1141{
1142 ARG_UNUSED(iface);
1143
1144 return false;
1145}
1146#endif
1147
1155#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1156bool net_eth_is_vlan_interface(struct net_if *iface);
1157#else
1158static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1159{
1160 ARG_UNUSED(iface);
1161
1162 return false;
1163}
1164#endif
1165
1168#if !defined(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_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1174 init_fn, pm, data, config, prio, \
1175 api, ETHERNET_L2, \
1176 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1177
1178#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1179
1180#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1181 init_fn, pm, data, config, prio, \
1182 api, mtu) \
1183 Z_DEVICE_STATE_DEFINE(dev_id); \
1184 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL, \
1185 Z_DEVICE_DT_FLAGS(node_id), pm, data, \
1186 config, POST_KERNEL, prio, api, \
1187 &Z_DEVICE_STATE_NAME(dev_id));
1188
1189#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1190
1191#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1192 config, prio, api, mtu) \
1193 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1194 init_fn, pm, data, config, prio, \
1195 api, mtu)
1196
1216#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1217 prio, api, mtu) \
1218 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1219 pm, data, config, prio, api, mtu)
1220
1243#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1244 pm, data, config, prio, api, mtu) \
1245 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1246 instance, init_fn, pm, data, \
1247 config, prio, api, mtu)
1248
1265#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1266 prio, api, mtu) \
1267 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1268 DEVICE_DT_NAME(node_id), init_fn, pm, \
1269 data, config, prio, api, mtu)
1270
1280#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1281 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1282
1290#define ETH_NET_L3_REGISTER(name, ptype, handler) \
1291 NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
1292
1299void net_eth_carrier_on(struct net_if *iface);
1300
1307void net_eth_carrier_off(struct net_if *iface);
1308
1318int net_eth_promisc_mode(struct net_if *iface, bool enable);
1319
1329int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1330
1341int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1342 enum ethernet_filter_type type, bool enable);
1343
1351const struct device *net_eth_get_phy(struct net_if *iface);
1352
1361#if defined(CONFIG_PTP_CLOCK)
1362const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1363#else
1364static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1365{
1366 ARG_UNUSED(iface);
1367
1368 return NULL;
1369}
1370#endif
1371
1381__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1382
1390#if defined(CONFIG_NET_L2_PTP)
1391int net_eth_get_ptp_port(struct net_if *iface);
1392#else
1393static inline int net_eth_get_ptp_port(struct net_if *iface)
1394{
1395 ARG_UNUSED(iface);
1396
1397 return -ENODEV;
1398}
1399#endif /* CONFIG_NET_L2_PTP */
1400
1407#if defined(CONFIG_NET_L2_PTP)
1408void net_eth_set_ptp_port(struct net_if *iface, int port);
1409#else
1410static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1411{
1412 ARG_UNUSED(iface);
1413 ARG_UNUSED(port);
1414}
1415#endif /* CONFIG_NET_L2_PTP */
1416
1424static inline bool net_eth_type_is_wifi(struct net_if *iface)
1425{
1426 const struct ethernet_context *ctx = (struct ethernet_context *)
1427 net_if_l2_data(iface);
1428
1429 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1430}
1431
1436#ifdef __cplusplus
1437}
1438#endif
1439
1440#include <zephyr/syscalls/ethernet.h>
1441
1442#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_H_ */
long atomic_t
Definition atomic_types.h:15
DSA definitions and handlers.
Distributed Switch Architecture (DSA)
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:1095
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:984
ethernet_if_types
Types of Ethernet L2.
Definition ethernet.h:444
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition ethernet.h:1410
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition ethernet.h:1009
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:784
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:826
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition ethernet.h:1393
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:1364
#define NET_ETH_ADDR_LEN
Ethernet MAC address length.
Definition ethernet.h:52
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:1052
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:1424
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:763
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:1140
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:853
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:805
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition ethernet.h:1158
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:953
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition ethernet.h:1029
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:481
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:1120
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:1073
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:877
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:902
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition ethernet.h:865
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:446
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition ethernet.h:449
@ ETHERNET_HW_VLAN
VLAN supported.
Definition ethernet.h:150
@ ETHERNET_DSA_USER_PORT
DSA switch user port.
Definition ethernet.h:189
@ 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_100BASE
100 Mbits link supported
Definition ethernet.h:159
@ ETHERNET_DSA_CONDUIT_PORT
DSA switch conduit port.
Definition ethernet.h:192
@ ETHERNET_LINK_10BASE
10 Mbits link supported
Definition ethernet.h:156
@ ETHERNET_HW_FILTERING
MAC address filtering supported.
Definition ethernet.h:180
@ ETHERNET_LINK_1000BASE
1 Gbits link supported
Definition ethernet.h:162
@ 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_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_LLDP
Link Layer Discovery Protocol supported.
Definition ethernet.h:183
@ ETHERNET_AUTO_NEGOTIATION_SET
Enabling/disabling auto negotiation supported.
Definition ethernet.h:153
@ ETHERNET_LINK_5000BASE
5 Gbits link supported
Definition ethernet.h:210
@ 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_LINK_2500BASE
2.5 Gbits link supported
Definition ethernet.h:207
@ ETHERNET_CHECKSUM_SUPPORT_UDP
Device supports UDP checksum offloading for all supported IP protocols.
Definition ethernet.h:495
@ ETHERNET_CHECKSUM_SUPPORT_TCP
Device supports TCP checksum offloading for all supported IP protocols.
Definition ethernet.h:493
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER
Device supports checksum offloading for the IPv6 header.
Definition ethernet.h:489
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP
Device supports checksum offloading for ICMPv4 payload (implies IPv4 header)
Definition ethernet.h:487
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER
Device supports checksum offloading for the IPv4 header.
Definition ethernet.h:485
@ ETHERNET_CHECKSUM_SUPPORT_NONE
Device does not support any L3/L4 checksum offloading.
Definition ethernet.h:483
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP
Device supports checksum offloading for ICMPv6 payload (implies IPv6 header)
Definition ethernet.h:491
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:989
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:1005
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
#define NULL
Definition iar_missing_defs.h:20
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:504
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510
DSA switch context data.
Definition dsa_core.h:79
Ethernet L2 API operations.
Definition ethernet.h:535
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:540
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition ethernet.h:551
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition ethernet.h:565
int(* stop)(const struct device *dev)
Stop the device.
Definition ethernet.h:554
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition ethernet.h:557
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition ethernet.h:588
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition ethernet.h:560
Ethernet filter description.
Definition ethernet.h:453
struct net_eth_addr mac_address
MAC address to filter.
Definition ethernet.h:457
bool set
Set (true) or unset (false) the filter.
Definition ethernet.h:459
enum ethernet_filter_type type
Type of filter.
Definition ethernet.h:455
Ethernet LLDP specific parameters.
Definition ethernet.h:621
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition ethernet.h:629
sys_snode_t node
Used for track timers.
Definition ethernet.h:623
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition ethernet.h:644
size_t optional_len
Length of the optional Data Unit TLVs.
Definition ethernet.h:632
struct net_if * iface
Network interface that has LLDP supported.
Definition ethernet.h:635
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition ethernet.h:626
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition ethernet.h:641
int64_t tx_timer_start
LLDP TX timer start time.
Definition ethernet.h:638
Ethernet Qav specific parameters.
Definition ethernet.h:295
bool enabled
True if Qav is enabled for queue.
Definition ethernet.h:302
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition ethernet.h:308
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition ethernet.h:299
unsigned int traffic_class
Traffic class the queue is bound to.
Definition ethernet.h:310
int queue_id
ID of the priority queue to use.
Definition ethernet.h:297
unsigned int idle_slope
Idle Slope (bits per second)
Definition ethernet.h:306
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition ethernet.h:304
Ethernet Qbu specific parameters.
Definition ethernet.h:404
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition ethernet.h:417
uint32_t release_advance
Release advance (nanoseconds)
Definition ethernet.h:414
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition ethernet.h:408
uint32_t hold_advance
Hold advance (nanoseconds)
Definition ethernet.h:411
bool enabled
True if Qbu is enabled or not.
Definition ethernet.h:421
bool link_partner_status
Link partner status (from Qbr)
Definition ethernet.h:424
int port_id
Port id.
Definition ethernet.h:406
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition ethernet.h:430
Ethernet Qbv specific parameters.
Definition ethernet.h:337
int port_id
Port id.
Definition ethernet.h:339
bool enabled
True if Qbv is enabled or not.
Definition ethernet.h:346
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition ethernet.h:341
uint16_t row
Gate control list row.
Definition ethernet.h:360
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition ethernet.h:343
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition ethernet.h:351
struct net_ptp_extended_time base_time
Base time.
Definition ethernet.h:372
uint32_t extension_time
Extension time (nanoseconds)
Definition ethernet.h:378
enum ethernet_gate_state_operation operation
GateState operation.
Definition ethernet.h:354
struct ethernet_qbv_param::@360::@362 gate_control
Gate control information.
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition ethernet.h:357
struct net_ptp_time cycle_time
Cycle time.
Definition ethernet.h:375
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition ethernet.h:364
Ethernet T1S specific parameters.
Definition ethernet.h:250
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition ethernet.h:285
uint8_t node_count
T1S PLCA node count range: 1 to 255.
Definition ethernet.h:283
uint8_t to_timer
T1S PLCA TO value.
Definition ethernet.h:289
uint8_t burst_timer
T1S PLCA burst timer.
Definition ethernet.h:287
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition ethernet.h:281
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition ethernet.h:252
bool enable
T1S PLCA enabled.
Definition ethernet.h:279
struct ethernet_t1s_param::@355::@357 plca
PLCA is the Physical Layer (PHY) Collision Avoidance technique employed with multidrop 10Base-T1S sta...
Ethernet TXTIME specific parameters.
Definition ethernet.h:471
bool enable_txtime
Enable or disable TXTIME per queue.
Definition ethernet.h:477
int queue_id
Queue number for configuring TXTIME.
Definition ethernet.h:475
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition ethernet.h:473
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:4051
Ethernet address.
Definition ethernet.h:55
uint8_t addr[6U]
Buffer storing the address.
Definition ethernet.h:56
Network Interface structure.
Definition net_if.h:714
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:625
Misc utilities.