Zephyr API Documentation  3.7.0-rc1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ethernet.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2016 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_ETHERNET_H_
14#define ZEPHYR_INCLUDE_NET_ETHERNET_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/types.h>
18#include <stdbool.h>
19#include <zephyr/sys/atomic.h>
20
21#include <zephyr/net/net_ip.h>
22#include <zephyr/net/net_pkt.h>
23#include <zephyr/net/lldp.h>
24#include <zephyr/sys/util.h>
25#include <zephyr/net/net_if.h>
27#include <zephyr/net/ptp_time.h>
28
29#if defined(CONFIG_NET_DSA)
30#include <zephyr/net/dsa.h>
31#endif
32
33#if defined(CONFIG_NET_ETHERNET_BRIDGE)
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
48#define NET_ETH_ADDR_LEN 6U
53};
54
57#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
58
59#define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
60#define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
61#define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
62#define NET_ETH_PTYPE_ARP 0x0806
63#define NET_ETH_PTYPE_IP 0x0800
64#define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
65#define NET_ETH_PTYPE_IPV6 0x86dd
66#define NET_ETH_PTYPE_VLAN 0x8100
67#define NET_ETH_PTYPE_PTP 0x88f7
68#define NET_ETH_PTYPE_LLDP 0x88cc
69#define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
70#define NET_ETH_PTYPE_ECAT 0x88a4
71#define NET_ETH_PTYPE_EAPOL 0x888e
72#define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
73
74#if !defined(ETH_P_ALL)
75#define ETH_P_ALL NET_ETH_PTYPE_ALL
76#endif
77#if !defined(ETH_P_IP)
78#define ETH_P_IP NET_ETH_PTYPE_IP
79#endif
80#if !defined(ETH_P_ARP)
81#define ETH_P_ARP NET_ETH_PTYPE_ARP
82#endif
83#if !defined(ETH_P_IPV6)
84#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
85#endif
86#if !defined(ETH_P_8021Q)
87#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
88#endif
89#if !defined(ETH_P_TSN)
90#define ETH_P_TSN NET_ETH_PTYPE_TSN
91#endif
92#if !defined(ETH_P_ECAT)
93#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
94#endif
95#if !defined(ETH_P_IEEE802154)
96#define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
97#endif
98#if !defined(ETH_P_CAN)
99#define ETH_P_CAN NET_ETH_PTYPE_CAN
100#endif
101#if !defined(ETH_P_CANFD)
102#define ETH_P_CANFD NET_ETH_PTYPE_CANFD
103#endif
104#if !defined(ETH_P_HDLC)
105#define ETH_P_HDLC NET_ETH_PTYPE_HDLC
106#endif
107
110#define NET_ETH_MINIMAL_FRAME_SIZE 60
111#define NET_ETH_MTU 1500
115#if defined(CONFIG_NET_VLAN)
116#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_vlan_hdr))
117#else
118#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
119#endif
120
121#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + _NET_ETH_MAX_HDR_SIZE)
122/*
123 * Extend the max frame size for DSA (KSZ8794) by one byte (to 1519) to
124 * store tail tag.
125 */
126#if defined(CONFIG_NET_DSA)
127#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
128#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
129#else
130#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
131#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
132#endif
133
134#define NET_ETH_VLAN_HDR_SIZE 4
135
142
145
148
151
154
157
160
163
166
169
172
175
178
181
184
187
190
193
196
199
202};
203
206enum ethernet_config_type {
207 ETHERNET_CONFIG_TYPE_AUTO_NEG,
208 ETHERNET_CONFIG_TYPE_LINK,
209 ETHERNET_CONFIG_TYPE_DUPLEX,
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};
224
225enum ethernet_qav_param_type {
226 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
227 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
228 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
229 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
230 ETHERNET_QAV_PARAM_TYPE_STATUS,
231};
232
233enum ethernet_t1s_param_type {
234 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
235};
236
242 enum ethernet_t1s_param_type type;
243 union {
267 struct {
269 bool enable;
281 };
282};
283
289 enum ethernet_qav_param_type type;
290 union {
294 unsigned int delta_bandwidth;
296 unsigned int idle_slope;
298 unsigned int oper_idle_slope;
300 unsigned int traffic_class;
301 };
302};
303
306enum ethernet_qbv_param_type {
307 ETHERNET_QBV_PARAM_TYPE_STATUS,
308 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
309 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
310 ETHERNET_QBV_PARAM_TYPE_TIME,
311};
312
313enum ethernet_qbv_state_type {
314 ETHERNET_QBV_STATE_TYPE_ADMIN,
315 ETHERNET_QBV_STATE_TYPE_OPER,
316};
317
318enum ethernet_gate_state_operation {
319 ETHERNET_SET_GATE_STATE,
320 ETHERNET_SET_AND_HOLD_MAC_STATE,
321 ETHERNET_SET_AND_RELEASE_MAC_STATE,
322};
323
331 enum ethernet_qbv_param_type type;
333 enum ethernet_qbv_state_type state;
334 union {
337
339 struct {
341 bool gate_status[NET_TC_TX_COUNT];
342
344 enum ethernet_gate_state_operation operation;
345
348
352
355
360 struct {
363
366
369 };
370 };
371};
372
375enum ethernet_qbu_param_type {
376 ETHERNET_QBU_PARAM_TYPE_STATUS,
377 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
378 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
379 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
380
381 /* Some preemption settings are from Qbr spec. */
382 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
383 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
384};
385
386enum ethernet_qbu_preempt_status {
387 ETHERNET_QBU_STATUS_EXPRESS,
388 ETHERNET_QBU_STATUS_PREEMPTABLE
389} __packed;
390
398 enum ethernet_qbu_param_type type;
399 union {
402
405
407 enum ethernet_qbu_preempt_status
408 frame_preempt_statuses[NET_TC_TX_COUNT];
409
412
415
421 };
422};
423
426enum ethernet_filter_type {
427 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
428 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
429};
430
437
440} __packed;
441
445 enum ethernet_filter_type type;
449 bool set;
450};
451
454enum ethernet_txtime_param_type {
455 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
456};
457
463 enum ethernet_txtime_param_type type;
468};
469
473 ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
475 ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
477 ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
479 ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
481 ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
483 ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
485 ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
486};
487
490struct ethernet_config {
491 union {
492 bool auto_negotiation;
493 bool full_duplex;
494 bool promisc_mode;
495 bool txinjection_mode;
496
497 struct {
498 bool link_10bt;
499 bool link_100bt;
500 bool link_1000bt;
501 } l;
502
503 struct net_eth_addr mac_address;
504
505 struct ethernet_t1s_param t1s_param;
506 struct ethernet_qav_param qav_param;
507 struct ethernet_qbv_param qbv_param;
508 struct ethernet_qbu_param qbu_param;
509 struct ethernet_txtime_param txtime_param;
510
511 int priority_queues_num;
512 int ports_num;
513
514 enum ethernet_checksum_support chksum_support;
515
516 struct ethernet_filter filter;
517 };
518};
519
528 struct net_if_api iface_api;
529
534#if defined(CONFIG_NET_STATISTICS_ETHERNET)
535 struct net_stats_eth *(*get_stats)(const struct device *dev);
536#endif
537
539 int (*start)(const struct device *dev);
540
542 int (*stop)(const struct device *dev);
543
545 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
546
548 int (*set_config)(const struct device *dev,
549 enum ethernet_config_type type,
550 const struct ethernet_config *config);
551
553 int (*get_config)(const struct device *dev,
554 enum ethernet_config_type type,
555 struct ethernet_config *config);
556
562#if defined(CONFIG_NET_VLAN)
563 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
564 uint16_t tag, bool enable);
565#endif /* CONFIG_NET_VLAN */
566
568#if defined(CONFIG_PTP_CLOCK)
569 const struct device *(*get_ptp_clock)(const struct device *dev);
570#endif /* CONFIG_PTP_CLOCK */
571
573 int (*send)(const struct device *dev, struct net_pkt *pkt);
574};
575
578/* Make sure that the network interface API is properly setup inside
579 * Ethernet API struct (it is the first one).
580 */
581BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
582
583struct net_eth_hdr {
584 struct net_eth_addr dst;
585 struct net_eth_addr src;
586 uint16_t type;
587} __packed;
588
589struct ethernet_vlan {
591 struct net_if *iface;
592
594 uint16_t tag;
595};
596
597#if defined(CONFIG_NET_VLAN_COUNT)
598#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
599#else
600/* Even thou there are no VLAN support, the minimum count must be set to 1.
601 */
602#define NET_VLAN_MAX_COUNT 1
603#endif
604
611
613 const struct net_lldpdu *lldpdu;
614
617
620
622 struct net_if *iface;
623
626
629
632};
633
636enum ethernet_flags {
637 ETH_CARRIER_UP,
638};
639
641struct ethernet_context {
646
647#if defined(CONFIG_NET_ETHERNET_BRIDGE)
648 struct eth_bridge_iface_context bridge;
649#endif
650
657 struct k_work carrier_work;
658
660 struct net_if *iface;
661
662#if defined(CONFIG_NET_LLDP)
663 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
664#endif
665
669 enum net_l2_flags ethernet_l2_flags;
670
671#if defined(CONFIG_NET_L2_PTP)
676 int port;
677#endif
678
679#if defined(CONFIG_NET_DSA)
683 dsa_net_recv_cb_t dsa_recv_cb;
684
686 uint8_t dsa_port_idx;
687
689 struct dsa_context *dsa_ctx;
690
692 dsa_send_t dsa_send;
693#endif
694
696 bool is_net_carrier_up : 1;
697
699 bool is_init : 1;
700
702 enum ethernet_if_types eth_if_type;
703};
704
710void ethernet_init(struct net_if *iface);
711
712#define ETHERNET_L2_CTX_TYPE struct ethernet_context
713
714/* Separate header for VLAN as some of device interfaces might not
715 * support VLAN.
716 */
717struct net_eth_vlan_hdr {
718 struct net_eth_addr dst;
719 struct net_eth_addr src;
720 struct {
721 uint16_t tpid; /* tag protocol id */
722 uint16_t tci; /* tag control info */
723 } vlan;
724 uint16_t type;
725} __packed;
726
736static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
737{
738 if (addr->addr[0] == 0xff &&
739 addr->addr[1] == 0xff &&
740 addr->addr[2] == 0xff &&
741 addr->addr[3] == 0xff &&
742 addr->addr[4] == 0xff &&
743 addr->addr[5] == 0xff) {
744 return true;
745 }
746
747 return false;
748}
749
757static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
758{
759 if (addr->addr[0] == 0x00 &&
760 addr->addr[1] == 0x00 &&
761 addr->addr[2] == 0x00 &&
762 addr->addr[3] == 0x00 &&
763 addr->addr[4] == 0x00 &&
764 addr->addr[5] == 0x00) {
765 return true;
766 }
767
768 return false;
769}
770
778static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
779{
780 if (addr->addr[0] == 0x00 &&
781 addr->addr[1] == 0x00 &&
782 addr->addr[2] == 0x00 &&
783 addr->addr[3] == 0x00 &&
784 addr->addr[4] == 0x00 &&
785 addr->addr[5] == 0x00) {
786 return true;
787 }
788
789 return false;
790}
791
799static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
800{
801#if defined(CONFIG_NET_IPV6)
802 if (addr->addr[0] == 0x33 &&
803 addr->addr[1] == 0x33) {
804 return true;
805 }
806#endif
807
808#if defined(CONFIG_NET_IPV4)
809 if (addr->addr[0] == 0x01 &&
810 addr->addr[1] == 0x00 &&
811 addr->addr[2] == 0x5e) {
812 return true;
813 }
814#endif
815
816 return false;
817}
818
826static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
827{
828 return addr->addr[0] & 0x01;
829}
830
838static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
839{
841}
842
850static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
851{
852#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
853 if (addr->addr[0] == 0x01 &&
854 addr->addr[1] == 0x80 &&
855 addr->addr[2] == 0xc2 &&
856 addr->addr[3] == 0x00 &&
857 addr->addr[4] == 0x00 &&
858 addr->addr[5] == 0x0e) {
859 return true;
860 }
861#else
862 ARG_UNUSED(addr);
863#endif
864
865 return false;
866}
867
875static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
876{
877#if defined(CONFIG_NET_GPTP)
878 if (addr->addr[0] == 0x01 &&
879 addr->addr[1] == 0x1b &&
880 addr->addr[2] == 0x19 &&
881 addr->addr[3] == 0x00 &&
882 addr->addr[4] == 0x00 &&
883 addr->addr[5] == 0x00) {
884 return true;
885 }
886#else
887 ARG_UNUSED(addr);
888#endif
889
890 return false;
891}
892
899
906void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
907 struct net_eth_addr *mac_addr);
908
915void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
916 struct net_eth_addr *mac_addr);
917
925static inline
927{
928 const struct ethernet_api *eth =
929 (struct ethernet_api *)net_if_get_device(iface)->api;
930
931 if (!eth->get_capabilities) {
932 return (enum ethernet_hw_caps)0;
933 }
934
935 return eth->get_capabilities(net_if_get_device(iface));
936}
937
947static inline
948int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
949 struct ethernet_config *config)
950{
951 const struct ethernet_api *eth =
952 (struct ethernet_api *)net_if_get_device(iface)->api;
953
954 if (!eth->get_config) {
955 return -ENOTSUP;
956 }
957
958 return eth->get_config(net_if_get_device(iface), type, config);
959}
960
961
970#if defined(CONFIG_NET_VLAN)
971int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
972#else
973static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
974{
975 ARG_UNUSED(iface);
976 ARG_UNUSED(tag);
977
978 return -EINVAL;
979}
980#endif
981
990#if defined(CONFIG_NET_VLAN)
991int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
992#else
993static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
994{
995 ARG_UNUSED(iface);
996 ARG_UNUSED(tag);
997
998 return -EINVAL;
999}
1000#endif
1001
1013#if defined(CONFIG_NET_VLAN)
1014uint16_t net_eth_get_vlan_tag(struct net_if *iface);
1015#else
1016static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
1017{
1018 ARG_UNUSED(iface);
1019
1020 return NET_VLAN_TAG_UNSPEC;
1021}
1022#endif
1023
1033#if defined(CONFIG_NET_VLAN)
1034struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
1035#else
1036static inline
1038{
1039 ARG_UNUSED(iface);
1040 ARG_UNUSED(tag);
1041
1042 return NULL;
1043}
1044#endif
1045
1055#if defined(CONFIG_NET_VLAN)
1056struct net_if *net_eth_get_vlan_main(struct net_if *iface);
1057#else
1058static inline
1060{
1061 ARG_UNUSED(iface);
1062
1063 return NULL;
1064}
1065#endif
1066
1080#if defined(CONFIG_NET_VLAN)
1081bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1082 struct net_if *iface);
1083#else
1084static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1085 struct net_if *iface)
1086{
1087 ARG_UNUSED(ctx);
1088 ARG_UNUSED(iface);
1089
1090 return false;
1091}
1092#endif
1093
1101#if defined(CONFIG_NET_VLAN)
1102bool net_eth_get_vlan_status(struct net_if *iface);
1103#else
1104static inline bool net_eth_get_vlan_status(struct net_if *iface)
1105{
1106 ARG_UNUSED(iface);
1107
1108 return false;
1109}
1110#endif
1111
1119#if defined(CONFIG_NET_VLAN)
1120bool net_eth_is_vlan_interface(struct net_if *iface);
1121#else
1122static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1123{
1124 ARG_UNUSED(iface);
1125
1126 return false;
1127}
1128#endif
1129
1132#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1133
1134#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1135 init_fn, pm, data, config, prio, \
1136 api, mtu) \
1137 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1138 init_fn, pm, data, config, prio, \
1139 api, ETHERNET_L2, \
1140 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1141
1142#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1143
1144#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1145 init_fn, pm, data, config, prio, \
1146 api, mtu) \
1147 Z_DEVICE_STATE_DEFINE(dev_id); \
1148 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
1149 config, POST_KERNEL, prio, api, \
1150 &Z_DEVICE_STATE_NAME(dev_id));
1151
1152#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1153
1154#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1155 config, prio, api, mtu) \
1156 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1157 init_fn, pm, data, config, prio, \
1158 api, mtu)
1159
1179#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1180 prio, api, mtu) \
1181 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1182 pm, data, config, prio, api, mtu)
1183
1206#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1207 pm, data, config, prio, api, mtu) \
1208 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1209 instance, init_fn, pm, data, \
1210 config, prio, api, mtu)
1211
1228#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1229 prio, api, mtu) \
1230 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1231 DEVICE_DT_NAME(node_id), init_fn, pm, \
1232 data, config, prio, api, mtu)
1233
1243#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1244 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1245
1252void net_eth_carrier_on(struct net_if *iface);
1253
1260void net_eth_carrier_off(struct net_if *iface);
1261
1271int net_eth_promisc_mode(struct net_if *iface, bool enable);
1272
1282int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1283
1294int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1295 enum ethernet_filter_type type, bool enable);
1304#if defined(CONFIG_PTP_CLOCK)
1305const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1306#else
1307static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1308{
1309 ARG_UNUSED(iface);
1310
1311 return NULL;
1312}
1313#endif
1314
1324__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1325
1333#if defined(CONFIG_NET_L2_PTP)
1334int net_eth_get_ptp_port(struct net_if *iface);
1335#else
1336static inline int net_eth_get_ptp_port(struct net_if *iface)
1337{
1338 ARG_UNUSED(iface);
1339
1340 return -ENODEV;
1341}
1342#endif /* CONFIG_NET_L2_PTP */
1343
1350#if defined(CONFIG_NET_L2_PTP)
1351void net_eth_set_ptp_port(struct net_if *iface, int port);
1352#else
1353static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1354{
1355 ARG_UNUSED(iface);
1356 ARG_UNUSED(port);
1357}
1358#endif /* CONFIG_NET_L2_PTP */
1359
1367static inline bool net_eth_type_is_wifi(struct net_if *iface)
1368{
1369 const struct ethernet_context *ctx = (struct ethernet_context *)
1370 net_if_l2_data(iface);
1371
1372 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1373}
1374
1379#ifdef __cplusplus
1380}
1381#endif
1382
1383#include <zephyr/syscalls/ethernet.h>
1384
1385#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_H_ */
long atomic_t
Definition: atomic_types.h:15
DSA definitions and handlers.
Ethernet Bridge public header file.
VLAN specific definitions.
enum net_verdict(* dsa_net_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
DSA (MGMT) Receive packet callback.
Definition: dsa.h:72
int(* dsa_send_t)(const struct device *dev, struct net_pkt *pkt)
Pointer to master interface send function.
Definition: dsa.h:98
static struct net_if * net_eth_get_vlan_main(struct net_if *iface)
Return main network interface that is attached to this VLAN tag.
Definition: ethernet.h:1059
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:948
ethernet_if_types
Types of Ethernet L2.
Definition: ethernet.h:434
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition: ethernet.h:1353
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition: ethernet.h:973
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:757
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:799
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition: ethernet.h:1336
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:1307
#define NET_ETH_ADDR_LEN
Ethernet MAC address length.
Definition: ethernet.h:48
int net_eth_promisc_mode(struct net_if *iface, bool enable)
Set promiscuous mode either ON or OFF.
void net_eth_carrier_off(struct net_if *iface)
Inform ethernet L2 driver that ethernet carrier was lost.
static uint16_t net_eth_get_vlan_tag(struct net_if *iface)
Return VLAN tag specified to network interface.
Definition: ethernet.h:1016
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:1367
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:736
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:1104
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:826
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:778
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition: ethernet.h:1122
ethernet_hw_caps
Ethernet hardware capabilities.
Definition: ethernet.h:139
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:926
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:993
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:471
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:1084
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:1037
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:850
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:875
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition: ethernet.h:838
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:436
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition: ethernet.h:439
@ ETHERNET_HW_VLAN
VLAN supported.
Definition: ethernet.h:147
@ ETHERNET_PRIORITY_QUEUES
Priority queues available.
Definition: ethernet.h:174
@ ETHERNET_DUPLEX_SET
Changing duplex (half/full) supported.
Definition: ethernet.h:162
@ ETHERNET_HW_VLAN_TAG_STRIP
VLAN Tag stripping.
Definition: ethernet.h:183
@ ETHERNET_LINK_10BASE_T
10 Mbits link supported
Definition: ethernet.h:153
@ ETHERNET_HW_FILTERING
MAC address filtering supported.
Definition: ethernet.h:177
@ ETHERNET_PTP
IEEE 802.1AS (gPTP) clock supported.
Definition: ethernet.h:165
@ ETHERNET_QBU
IEEE 802.1Qbu (frame preemption) supported.
Definition: ethernet.h:195
@ ETHERNET_LINK_100BASE_T
100 Mbits link supported
Definition: ethernet.h:156
@ ETHERNET_DSA_MASTER_PORT
DSA switch master port.
Definition: ethernet.h:189
@ ETHERNET_DSA_SLAVE_PORT
DSA switch slave port.
Definition: ethernet.h:186
@ ETHERNET_TXINJECTION_MODE
TX-Injection supported.
Definition: ethernet.h:201
@ ETHERNET_QAV
IEEE 802.1Qav (credit-based shaping) supported.
Definition: ethernet.h:168
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
RX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition: ethernet.h:144
@ ETHERNET_LINK_1000BASE_T
1 Gbits link supported
Definition: ethernet.h:159
@ ETHERNET_LLDP
Link Layer Discovery Protocol supported.
Definition: ethernet.h:180
@ ETHERNET_AUTO_NEGOTIATION_SET
Enabling/disabling auto negotiation supported.
Definition: ethernet.h:150
@ ETHERNET_TXTIME
TXTIME supported.
Definition: ethernet.h:198
@ ETHERNET_QBV
IEEE 802.1Qbv (scheduled traffic) supported.
Definition: ethernet.h:192
@ ETHERNET_PROMISC_MODE
Promiscuous mode supported.
Definition: ethernet.h:171
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
TX Checksum offloading supported for all of IPv4, UDP, TCP.
Definition: ethernet.h:141
@ ETHERNET_CHECKSUM_SUPPORT_UDP
Device supports UDP checksum offloading for all supported IP protocols.
Definition: ethernet.h:485
@ ETHERNET_CHECKSUM_SUPPORT_TCP
Device supports TCP checksum offloading for all supported IP protocols.
Definition: ethernet.h:483
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER
Device supports checksum offloading for the IPv6 header.
Definition: ethernet.h:479
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP
Device supports checksum offloading for ICMPv4 payload (implies IPv4 header)
Definition: ethernet.h:477
@ ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER
Device supports checksum offloading for the IPv4 header.
Definition: ethernet.h:475
@ ETHERNET_CHECKSUM_SUPPORT_NONE
Device does not support any L3/L4 checksum offloading.
Definition: ethernet.h:473
@ ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP
Device supports checksum offloading for ICMPv6 payload (implies IPv6 header)
Definition: ethernet.h:481
enum net_verdict(* net_lldp_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
LLDP Receive packet callback.
Definition: lldp.h:213
static void * net_if_l2_data(struct net_if *iface)
Get a pointer to the interface L2 private data.
Definition: net_if.h:926
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition: net_if.h:941
net_l2_flags
L2 flags.
Definition: net_l2.h:34
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define EINVAL
Invalid argument.
Definition: errno.h:61
#define ENOTSUP
Unsupported value.
Definition: errno.h:115
#define ENODEV
No such device.
Definition: errno.h:58
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition: ethernet_vlan.h:30
Public kernel APIs.
LLDP definitions and handler.
Public API for network interface.
IPv6 and IPv4 definitions.
Network packet buffer descriptor API.
flags
Definition: parser.h:96
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT64_TYPE__ int64_t
Definition: stdint.h:75
Runtime device structure (in ROM) per driver instance.
Definition: device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
Ethernet L2 API operations.
Definition: ethernet.h:523
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:528
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition: ethernet.h:539
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition: ethernet.h:553
int(* stop)(const struct device *dev)
Stop the device.
Definition: ethernet.h:542
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition: ethernet.h:545
int(* send)(const struct device *dev, struct net_pkt *pkt)
The IP stack will call this function when a VLAN tag is enabled or disabled.
Definition: ethernet.h:573
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition: ethernet.h:548
Ethernet filter description.
Definition: ethernet.h:443
struct net_eth_addr mac_address
MAC address to filter.
Definition: ethernet.h:447
bool set
Set (true) or unset (false) the filter.
Definition: ethernet.h:449
enum ethernet_filter_type type
Type of filter.
Definition: ethernet.h:445
Ethernet LLDP specific parameters.
Definition: ethernet.h:608
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition: ethernet.h:616
sys_snode_t node
Used for track timers.
Definition: ethernet.h:610
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition: ethernet.h:631
size_t optional_len
Length of the optional Data Unit TLVs.
Definition: ethernet.h:619
struct net_if * iface
Network interface that has LLDP supported.
Definition: ethernet.h:622
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition: ethernet.h:613
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition: ethernet.h:628
int64_t tx_timer_start
LLDP TX timer start time.
Definition: ethernet.h:625
Ethernet Qav specific parameters.
Definition: ethernet.h:285
bool enabled
True if Qav is enabled for queue.
Definition: ethernet.h:292
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition: ethernet.h:298
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition: ethernet.h:289
unsigned int traffic_class
Traffic class the queue is bound to.
Definition: ethernet.h:300
int queue_id
ID of the priority queue to use.
Definition: ethernet.h:287
unsigned int idle_slope
Idle Slope (bits per second)
Definition: ethernet.h:296
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition: ethernet.h:294
Ethernet Qbu specific parameters.
Definition: ethernet.h:394
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition: ethernet.h:407
uint32_t release_advance
Release advance (nanoseconds)
Definition: ethernet.h:404
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition: ethernet.h:398
uint32_t hold_advance
Hold advance (nanoseconds)
Definition: ethernet.h:401
bool enabled
True if Qbu is enabled or not.
Definition: ethernet.h:411
bool link_partner_status
Link partner status (from Qbr)
Definition: ethernet.h:414
int port_id
Port id.
Definition: ethernet.h:396
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition: ethernet.h:420
Ethernet Qbv specific parameters.
Definition: ethernet.h:327
int port_id
Port id.
Definition: ethernet.h:329
bool enabled
True if Qbv is enabled or not.
Definition: ethernet.h:336
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition: ethernet.h:331
uint16_t row
Gate control list row.
Definition: ethernet.h:350
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition: ethernet.h:333
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition: ethernet.h:341
struct net_ptp_extended_time base_time
Base time.
Definition: ethernet.h:362
uint32_t extension_time
Extension time (nanoseconds)
Definition: ethernet.h:368
enum ethernet_gate_state_operation operation
GateState operation.
Definition: ethernet.h:344
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition: ethernet.h:347
struct net_ptp_time cycle_time
Cycle time.
Definition: ethernet.h:365
struct ethernet_qbv_param::@295::@297 gate_control
Gate control information.
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition: ethernet.h:354
Ethernet T1S specific parameters.
Definition: ethernet.h:240
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition: ethernet.h:275
uint8_t node_count
T1S PLCA node count range: 1 to 255.
Definition: ethernet.h:273
uint8_t to_timer
T1S PLCA TO value.
Definition: ethernet.h:279
struct ethernet_t1s_param::@290::@292 plca
PLCA is the Physical Layer (PHY) Collision Avoidance technique employed with multidrop 10Base-T1S sta...
uint8_t burst_timer
T1S PLCA burst timer.
Definition: ethernet.h:277
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition: ethernet.h:271
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition: ethernet.h:242
bool enable
T1S PLCA enabled.
Definition: ethernet.h:269
Ethernet TXTIME specific parameters.
Definition: ethernet.h:461
bool enable_txtime
Enable or disable TXTIME per queue.
Definition: ethernet.h:467
int queue_id
Queue number for configuring TXTIME.
Definition: ethernet.h:465
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition: ethernet.h:463
IPv6 address struct.
Definition: net_ip.h:139
IPv4 address struct.
Definition: net_ip.h:151
A structure used to submit work.
Definition: kernel.h:3877
Ethernet address.
Definition: ethernet.h:51
uint8_t addr[6U]
Buffer storing the address.
Definition: ethernet.h:52
Network Interface structure.
Definition: net_if.h:678
LLDP Data Unit (LLDPDU) shall contain the following ordered TLVs as stated in "8.2 LLDPDU format" fro...
Definition: lldp.h:167
Network packet.
Definition: net_pkt.h:67
Generalized Precision Time Protocol Extended Timestamp format.
Definition: ptp_time.h:152
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
All Ethernet specific statistics.
Definition: net_stats.h:523
Misc utilities.