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
206
209enum ethernet_config_type {
210 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
211 ETHERNET_CONFIG_TYPE_QAV_PARAM,
212 ETHERNET_CONFIG_TYPE_QBV_PARAM,
213 ETHERNET_CONFIG_TYPE_QBU_PARAM,
214 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
215 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
216 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
217 ETHERNET_CONFIG_TYPE_FILTER,
218 ETHERNET_CONFIG_TYPE_PORTS_NUM,
219 ETHERNET_CONFIG_TYPE_T1S_PARAM,
220 ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
221 ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
222 ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT,
223 ETHERNET_CONFIG_TYPE_EXTRA_TX_PKT_HEADROOM,
224};
225
226enum ethernet_qav_param_type {
227 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
228 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
229 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
230 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
231 ETHERNET_QAV_PARAM_TYPE_STATUS,
232};
233
234enum ethernet_t1s_param_type {
235 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
236};
237
243 enum ethernet_t1s_param_type type;
244 union {
268 struct {
270 bool enable;
282 };
283};
284
290 enum ethernet_qav_param_type type;
291 union {
295 unsigned int delta_bandwidth;
297 unsigned int idle_slope;
299 unsigned int oper_idle_slope;
301 unsigned int traffic_class;
302 };
303};
304
307enum ethernet_qbv_param_type {
308 ETHERNET_QBV_PARAM_TYPE_STATUS,
309 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
310 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
311 ETHERNET_QBV_PARAM_TYPE_TIME,
312};
313
314enum ethernet_qbv_state_type {
315 ETHERNET_QBV_STATE_TYPE_ADMIN,
316 ETHERNET_QBV_STATE_TYPE_OPER,
317};
318
319enum ethernet_gate_state_operation {
320 ETHERNET_SET_GATE_STATE,
321 ETHERNET_SET_AND_HOLD_MAC_STATE,
322 ETHERNET_SET_AND_RELEASE_MAC_STATE,
323};
324
332 enum ethernet_qbv_param_type type;
334 enum ethernet_qbv_state_type state;
335 union {
338
340 struct {
342 bool gate_status[NET_TC_TX_COUNT];
343
345 enum ethernet_gate_state_operation operation;
346
349
353
356
361 struct {
364
367
370 };
371 };
372};
373
376enum ethernet_qbu_param_type {
377 ETHERNET_QBU_PARAM_TYPE_STATUS,
378 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
379 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
380 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
381
382 /* Some preemption settings are from Qbr spec. */
383 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
384 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
385};
386
387enum ethernet_qbu_preempt_status {
388 ETHERNET_QBU_STATUS_EXPRESS,
389 ETHERNET_QBU_STATUS_PREEMPTABLE
390} __packed;
391
399 enum ethernet_qbu_param_type type;
400 union {
403
406
408 enum ethernet_qbu_preempt_status
409 frame_preempt_statuses[NET_TC_TX_COUNT];
410
413
416
422 };
423};
424
427enum ethernet_filter_type {
428 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
429 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
430};
431
442
446 enum ethernet_filter_type type;
450 bool set;
451};
452
455enum ethernet_txtime_param_type {
456 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
457};
458
464 enum ethernet_txtime_param_type type;
469};
470
474 ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
476 ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
478 ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
480 ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
482 ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
484 ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
486 ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
487};
488
491struct ethernet_config {
492 union {
493 bool promisc_mode;
494 bool txinjection_mode;
495
496 struct net_eth_addr mac_address;
497
498 struct ethernet_t1s_param t1s_param;
499 struct ethernet_qav_param qav_param;
500 struct ethernet_qbv_param qbv_param;
501 struct ethernet_qbu_param qbu_param;
502 struct ethernet_txtime_param txtime_param;
503
504 int priority_queues_num;
505 int ports_num;
506
507 enum ethernet_checksum_support chksum_support;
508
509 struct ethernet_filter filter;
510
511 uint16_t extra_tx_pkt_headroom;
512 };
513};
514
523 struct net_if_api iface_api;
524
529#if defined(CONFIG_NET_STATISTICS_ETHERNET)
530 struct net_stats_eth *(*get_stats)(const struct device *dev);
531#endif
532
534 int (*start)(const struct device *dev);
535
537 int (*stop)(const struct device *dev);
538
540 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
541
543 int (*set_config)(const struct device *dev,
544 enum ethernet_config_type type,
545 const struct ethernet_config *config);
546
548 int (*get_config)(const struct device *dev,
549 enum ethernet_config_type type,
550 struct ethernet_config *config);
551
557#if defined(CONFIG_NET_VLAN)
558 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
559 uint16_t tag, bool enable);
560#endif /* CONFIG_NET_VLAN */
561
563#if defined(CONFIG_PTP_CLOCK)
564 const struct device *(*get_ptp_clock)(const struct device *dev);
565#endif /* CONFIG_PTP_CLOCK */
566
568 const struct device *(*get_phy)(const struct device *dev);
569
571 int (*send)(const struct device *dev, struct net_pkt *pkt);
572};
573
576/* Make sure that the network interface API is properly setup inside
577 * Ethernet API struct (it is the first one).
578 */
579BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
580
581struct net_eth_hdr {
582 struct net_eth_addr dst;
583 struct net_eth_addr src;
584 uint16_t type;
585} __packed;
586
587struct ethernet_vlan {
589 struct net_if *iface;
590
592 uint16_t tag;
593};
594
595#if defined(CONFIG_NET_VLAN_COUNT)
596#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
597#else
598#define NET_VLAN_MAX_COUNT 0
599#endif
600
629
632enum ethernet_flags {
633 ETH_CARRIER_UP,
634};
635
637struct ethernet_context {
642
643#if defined(CONFIG_NET_ETHERNET_BRIDGE)
644 struct net_if *bridge;
645#endif
646
653 struct k_work carrier_work;
654
656 struct net_if *iface;
657
658#if defined(CONFIG_NET_LLDP)
659#if NET_VLAN_MAX_COUNT > 0
660#define NET_LLDP_MAX_COUNT NET_VLAN_MAX_COUNT
661#else
662#define NET_LLDP_MAX_COUNT 1
663#endif /* NET_VLAN_MAX_COUNT > 0 */
664
666 struct ethernet_lldp lldp[NET_LLDP_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_DEPRECATED)
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
697#elif defined(CONFIG_NET_DSA)
699 enum dsa_port_type dsa_port;
700
702 struct dsa_switch_context *dsa_switch_ctx;
703#endif
704
706 bool is_net_carrier_up : 1;
707
709 bool is_init : 1;
710
712 enum ethernet_if_types eth_if_type;
713};
714
720void ethernet_init(struct net_if *iface);
721
722#define ETHERNET_L2_CTX_TYPE struct ethernet_context
723
724/* Separate header for VLAN as some of device interfaces might not
725 * support VLAN.
726 */
727struct net_eth_vlan_hdr {
728 struct net_eth_addr dst;
729 struct net_eth_addr src;
730 struct {
731 uint16_t tpid; /* tag protocol id */
732 uint16_t tci; /* tag control info */
733 } vlan;
734 uint16_t type;
735} __packed;
736
746static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
747{
748 if (addr->addr[0] == 0xff &&
749 addr->addr[1] == 0xff &&
750 addr->addr[2] == 0xff &&
751 addr->addr[3] == 0xff &&
752 addr->addr[4] == 0xff &&
753 addr->addr[5] == 0xff) {
754 return true;
755 }
756
757 return false;
758}
759
767static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
768{
769 if (addr->addr[0] == 0x00 &&
770 addr->addr[1] == 0x00 &&
771 addr->addr[2] == 0x00 &&
772 addr->addr[3] == 0x00 &&
773 addr->addr[4] == 0x00 &&
774 addr->addr[5] == 0x00) {
775 return true;
776 }
777
778 return false;
779}
780
788static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
789{
790 if (addr->addr[0] == 0x00 &&
791 addr->addr[1] == 0x00 &&
792 addr->addr[2] == 0x00 &&
793 addr->addr[3] == 0x00 &&
794 addr->addr[4] == 0x00 &&
795 addr->addr[5] == 0x00) {
796 return true;
797 }
798
799 return false;
800}
801
809static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
810{
811#if defined(CONFIG_NET_IPV6)
812 if (addr->addr[0] == 0x33 &&
813 addr->addr[1] == 0x33) {
814 return true;
815 }
816#endif
817
818#if defined(CONFIG_NET_IPV4)
819 if (addr->addr[0] == 0x01 &&
820 addr->addr[1] == 0x00 &&
821 addr->addr[2] == 0x5e) {
822 return true;
823 }
824#endif
825
826 return false;
827}
828
836static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
837{
838 return addr->addr[0] & 0x01;
839}
840
848static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
849{
851}
852
860static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
861{
862#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
863 if (addr->addr[0] == 0x01 &&
864 addr->addr[1] == 0x80 &&
865 addr->addr[2] == 0xc2 &&
866 addr->addr[3] == 0x00 &&
867 addr->addr[4] == 0x00 &&
868 addr->addr[5] == 0x0e) {
869 return true;
870 }
871#else
872 ARG_UNUSED(addr);
873#endif
874
875 return false;
876}
877
885static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
886{
887#if defined(CONFIG_NET_GPTP)
888 if (addr->addr[0] == 0x01 &&
889 addr->addr[1] == 0x1b &&
890 addr->addr[2] == 0x19 &&
891 addr->addr[3] == 0x00 &&
892 addr->addr[4] == 0x00 &&
893 addr->addr[5] == 0x00) {
894 return true;
895 }
896#else
897 ARG_UNUSED(addr);
898#endif
899
900 return false;
901}
902
909
916void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
917 struct net_eth_addr *mac_addr);
918
925void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
926 struct net_eth_addr *mac_addr);
927
935static inline
937{
938 const struct device *dev = net_if_get_device(iface);
939 const struct ethernet_api *api = (struct ethernet_api *)dev->api;
940 enum ethernet_hw_caps caps = (enum ethernet_hw_caps)0;
941#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
942 struct ethernet_context *eth_ctx = net_if_l2_data(iface);
943
944 if (eth_ctx->dsa_port == DSA_CONDUIT_PORT) {
946 } else if (eth_ctx->dsa_port == DSA_USER_PORT) {
948 }
949#endif
950 if (api == NULL || api->get_capabilities == NULL) {
951 return caps;
952 }
953
954 return (enum ethernet_hw_caps)(caps | api->get_capabilities(dev));
955}
956
966static inline
967int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
968 struct ethernet_config *config)
969{
970 const struct ethernet_api *eth =
971 (struct ethernet_api *)net_if_get_device(iface)->api;
972
973 if (!eth->get_config) {
974 return -ENOTSUP;
975 }
976
977 return eth->get_config(net_if_get_device(iface), type, config);
978}
979
980
989#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
990int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
991#else
992static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
993{
994 ARG_UNUSED(iface);
995 ARG_UNUSED(tag);
996
997 return -EINVAL;
998}
999#endif
1000
1009#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1010int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
1011#else
1012static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
1013{
1014 ARG_UNUSED(iface);
1015 ARG_UNUSED(tag);
1016
1017 return -EINVAL;
1018}
1019#endif
1020
1032#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1033uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1034#else
1035static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1036{
1037 ARG_UNUSED(iface);
1038
1039 return NET_VLAN_TAG_UNSPEC;
1040}
1041#endif
1042
1052#if defined(CONFIG_NET_VLAN)
1053struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1054#else
1055static inline
1057{
1058 ARG_UNUSED(iface);
1059 ARG_UNUSED(tag);
1060
1061 return NULL;
1062}
1063#endif
1064
1074#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1075struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1076#else
1077static inline
1079{
1080 ARG_UNUSED(iface);
1081
1082 return NULL;
1083}
1084#endif
1085
1099#if defined(CONFIG_NET_VLAN)
1100bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1101 struct net_if *iface);
1102#else
1103static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1104 struct net_if *iface)
1105{
1106 ARG_UNUSED(ctx);
1107 ARG_UNUSED(iface);
1108
1109 return false;
1110}
1111#endif
1112
1120#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1121bool net_eth_get_vlan_status(struct net_if *iface);
1122#else
1123static inline bool net_eth_get_vlan_status(struct net_if *iface)
1124{
1125 ARG_UNUSED(iface);
1126
1127 return false;
1128}
1129#endif
1130
1138#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
1139bool net_eth_is_vlan_interface(struct net_if *iface);
1140#else
1141static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1142{
1143 ARG_UNUSED(iface);
1144
1145 return false;
1146}
1147#endif
1148
1151#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1152
1153#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1154 init_fn, pm, data, config, prio, \
1155 api, mtu) \
1156 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1157 init_fn, pm, data, config, prio, \
1158 api, ETHERNET_L2, \
1159 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1160
1161#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1162
1163#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1164 init_fn, pm, data, config, prio, \
1165 api, mtu) \
1166 Z_DEVICE_STATE_DEFINE(dev_id); \
1167 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, NULL, \
1168 Z_DEVICE_DT_FLAGS(node_id), pm, data, \
1169 config, POST_KERNEL, prio, api, \
1170 &Z_DEVICE_STATE_NAME(dev_id));
1171
1172#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1173
1174#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1175 config, prio, api, mtu) \
1176 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1177 init_fn, pm, data, config, prio, \
1178 api, mtu)
1179
1199#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1200 prio, api, mtu) \
1201 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1202 pm, data, config, prio, api, mtu)
1203
1226#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1227 pm, data, config, prio, api, mtu) \
1228 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1229 instance, init_fn, pm, data, \
1230 config, prio, api, mtu)
1231
1248#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1249 prio, api, mtu) \
1250 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1251 DEVICE_DT_NAME(node_id), init_fn, pm, \
1252 data, config, prio, api, mtu)
1253
1263#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1264 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1265
1273#define ETH_NET_L3_REGISTER(name, ptype, handler) \
1274 NET_L3_REGISTER(&NET_L2_GET_NAME(ETHERNET), name, ptype, handler)
1275
1282void net_eth_carrier_on(struct net_if *iface);
1283
1290void net_eth_carrier_off(struct net_if *iface);
1291
1301int net_eth_promisc_mode(struct net_if *iface, bool enable);
1302
1312int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1313
1324int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1325 enum ethernet_filter_type type, bool enable);
1326
1334const struct device *net_eth_get_phy(struct net_if *iface);
1335
1344#if defined(CONFIG_PTP_CLOCK)
1345const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1346#else
1347static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1348{
1349 ARG_UNUSED(iface);
1350
1351 return NULL;
1352}
1353#endif
1354
1364__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1365
1373#if defined(CONFIG_NET_L2_PTP)
1374int net_eth_get_ptp_port(struct net_if *iface);
1375#else
1376static inline int net_eth_get_ptp_port(struct net_if *iface)
1377{
1378 ARG_UNUSED(iface);
1379
1380 return -ENODEV;
1381}
1382#endif /* CONFIG_NET_L2_PTP */
1383
1390#if defined(CONFIG_NET_L2_PTP)
1391void net_eth_set_ptp_port(struct net_if *iface, int port);
1392#else
1393static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1394{
1395 ARG_UNUSED(iface);
1396 ARG_UNUSED(port);
1397}
1398#endif /* CONFIG_NET_L2_PTP */
1399
1407static inline bool net_eth_type_is_wifi(struct net_if *iface)
1408{
1409 const struct ethernet_context *ctx = (struct ethernet_context *)
1410 net_if_l2_data(iface);
1411
1412 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1413}
1414
1419#ifdef __cplusplus
1420}
1421#endif
1422
1423#include <zephyr/syscalls/ethernet.h>
1424
1425#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:1078
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:967
ethernet_if_types
Types of Ethernet L2.
Definition ethernet.h:435
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition ethernet.h:1393
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition ethernet.h:992
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:767
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:809
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition ethernet.h:1376
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:1347
#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:1035
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:1407
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:746
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:1123
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:836
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:788
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition ethernet.h:1141
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:936
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition ethernet.h:1012
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:472
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:1103
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:1056
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:860
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:885
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition ethernet.h:848
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:437
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition ethernet.h:440
@ 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_HW_VLAN_TAG_STRIP
VLAN Tag stripping.
Definition ethernet.h:186
@ ETHERNET_LINK_100BASE
100 Mbits link supported
Definition ethernet.h:156
@ ETHERNET_DSA_CONDUIT_PORT
DSA switch conduit port.
Definition ethernet.h:192
@ ETHERNET_LINK_10BASE
10 Mbits link supported
Definition ethernet.h:153
@ ETHERNET_HW_FILTERING
MAC address filtering supported.
Definition ethernet.h:180
@ ETHERNET_LINK_1000BASE
1 Gbits link supported
Definition ethernet.h:159
@ 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_LINK_5000BASE
5 Gbits link supported
Definition ethernet.h:165
@ 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:162
@ ETHERNET_CHECKSUM_SUPPORT_UDP
Device supports UDP checksum offloading for all supported IP protocols.
Definition ethernet.h:486
@ ETHERNET_CHECKSUM_SUPPORT_TCP
Device supports TCP checksum offloading for all supported IP protocols.
Definition ethernet.h:484
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER
Device supports checksum offloading for the IPv6 header.
Definition ethernet.h:480
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP
Device supports checksum offloading for ICMPv4 payload (implies IPv4 header)
Definition ethernet.h:478
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER
Device supports checksum offloading for the IPv4 header.
Definition ethernet.h:476
@ ETHERNET_CHECKSUM_SUPPORT_NONE
Device does not support any L3/L4 checksum offloading.
Definition ethernet.h:474
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP
Device supports checksum offloading for ICMPv6 payload (implies IPv6 header)
Definition ethernet.h:482
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:1035
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:1051
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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
DSA switch context data.
Definition dsa_core.h:79
Ethernet L2 API operations.
Definition ethernet.h:518
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:523
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition ethernet.h:534
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition ethernet.h:548
int(* stop)(const struct device *dev)
Stop the device.
Definition ethernet.h:537
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition ethernet.h:540
int(* send)(const struct device *dev, struct net_pkt *pkt)
Send a network packet.
Definition ethernet.h:571
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition ethernet.h:543
Ethernet filter description.
Definition ethernet.h:444
struct net_eth_addr mac_address
MAC address to filter.
Definition ethernet.h:448
bool set
Set (true) or unset (false) the filter.
Definition ethernet.h:450
enum ethernet_filter_type type
Type of filter.
Definition ethernet.h:446
Ethernet LLDP specific parameters.
Definition ethernet.h:604
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition ethernet.h:612
sys_snode_t node
Used for track timers.
Definition ethernet.h:606
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition ethernet.h:627
size_t optional_len
Length of the optional Data Unit TLVs.
Definition ethernet.h:615
struct net_if * iface
Network interface that has LLDP supported.
Definition ethernet.h:618
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition ethernet.h:609
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition ethernet.h:624
int64_t tx_timer_start
LLDP TX timer start time.
Definition ethernet.h:621
Ethernet Qav specific parameters.
Definition ethernet.h:286
bool enabled
True if Qav is enabled for queue.
Definition ethernet.h:293
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition ethernet.h:299
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition ethernet.h:290
unsigned int traffic_class
Traffic class the queue is bound to.
Definition ethernet.h:301
int queue_id
ID of the priority queue to use.
Definition ethernet.h:288
unsigned int idle_slope
Idle Slope (bits per second)
Definition ethernet.h:297
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition ethernet.h:295
Ethernet Qbu specific parameters.
Definition ethernet.h:395
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition ethernet.h:408
uint32_t release_advance
Release advance (nanoseconds)
Definition ethernet.h:405
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition ethernet.h:399
uint32_t hold_advance
Hold advance (nanoseconds)
Definition ethernet.h:402
bool enabled
True if Qbu is enabled or not.
Definition ethernet.h:412
bool link_partner_status
Link partner status (from Qbr)
Definition ethernet.h:415
int port_id
Port id.
Definition ethernet.h:397
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition ethernet.h:421
Ethernet Qbv specific parameters.
Definition ethernet.h:328
int port_id
Port id.
Definition ethernet.h:330
bool enabled
True if Qbv is enabled or not.
Definition ethernet.h:337
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition ethernet.h:332
uint16_t row
Gate control list row.
Definition ethernet.h:351
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition ethernet.h:334
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition ethernet.h:342
struct net_ptp_extended_time base_time
Base time.
Definition ethernet.h:363
uint32_t extension_time
Extension time (nanoseconds)
Definition ethernet.h:369
enum ethernet_gate_state_operation operation
GateState operation.
Definition ethernet.h:345
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition ethernet.h:348
struct ethernet_qbv_param::@372::@374 gate_control
Gate control information.
struct net_ptp_time cycle_time
Cycle time.
Definition ethernet.h:366
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition ethernet.h:355
Ethernet T1S specific parameters.
Definition ethernet.h:241
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition ethernet.h:276
struct ethernet_t1s_param::@367::@369 plca
PLCA is the Physical Layer (PHY) Collision Avoidance technique employed with multidrop 10Base-T1S sta...
uint8_t node_count
T1S PLCA node count range: 1 to 255.
Definition ethernet.h:274
uint8_t to_timer
T1S PLCA TO value.
Definition ethernet.h:280
uint8_t burst_timer
T1S PLCA burst timer.
Definition ethernet.h:278
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition ethernet.h:272
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition ethernet.h:243
bool enable
T1S PLCA enabled.
Definition ethernet.h:270
Ethernet TXTIME specific parameters.
Definition ethernet.h:462
bool enable_txtime
Enable or disable TXTIME per queue.
Definition ethernet.h:468
int queue_id
Queue number for configuring TXTIME.
Definition ethernet.h:466
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition ethernet.h:464
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:4073
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:726
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.