Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ethernet.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2016 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_ETHERNET_H_
14#define ZEPHYR_INCLUDE_NET_ETHERNET_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/types.h>
18#include <stdbool.h>
19#include <zephyr/sys/atomic.h>
20
21#include <zephyr/net/net_ip.h>
22#include <zephyr/net/net_pkt.h>
23#include <zephyr/net/lldp.h>
24#include <zephyr/sys/util.h>
25#include <zephyr/net/net_if.h>
27#include <zephyr/net/ptp_time.h>
28
29#if defined(CONFIG_NET_DSA)
30#include <zephyr/net/dsa.h>
31#endif
32
33#if defined(CONFIG_NET_ETHERNET_BRIDGE)
35#endif
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
48#define NET_ETH_ADDR_LEN 6U
53};
54
57#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
58
59#define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
60#define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
61#define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
62#define NET_ETH_PTYPE_ARP 0x0806
63#define NET_ETH_PTYPE_IP 0x0800
64#define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
65#define NET_ETH_PTYPE_IPV6 0x86dd
66#define NET_ETH_PTYPE_VLAN 0x8100
67#define NET_ETH_PTYPE_PTP 0x88f7
68#define NET_ETH_PTYPE_LLDP 0x88cc
69#define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
70#define NET_ETH_PTYPE_ECAT 0x88a4
71#define NET_ETH_PTYPE_EAPOL 0x888e
72#define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
73
74#if !defined(ETH_P_ALL)
75#define ETH_P_ALL NET_ETH_PTYPE_ALL
76#endif
77#if !defined(ETH_P_IP)
78#define ETH_P_IP NET_ETH_PTYPE_IP
79#endif
80#if !defined(ETH_P_ARP)
81#define ETH_P_ARP NET_ETH_PTYPE_ARP
82#endif
83#if !defined(ETH_P_IPV6)
84#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
85#endif
86#if !defined(ETH_P_8021Q)
87#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
88#endif
89#if !defined(ETH_P_TSN)
90#define ETH_P_TSN NET_ETH_PTYPE_TSN
91#endif
92#if !defined(ETH_P_ECAT)
93#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
94#endif
95#if !defined(ETH_P_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};
222
223enum ethernet_qav_param_type {
224 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
225 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
226 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
227 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
228 ETHERNET_QAV_PARAM_TYPE_STATUS,
229};
230
231enum ethernet_t1s_param_type {
232 ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
233};
234
240 enum ethernet_t1s_param_type type;
241 union {
265 struct {
267 bool enable;
279 };
280};
281
287 enum ethernet_qav_param_type type;
288 union {
292 unsigned int delta_bandwidth;
294 unsigned int idle_slope;
296 unsigned int oper_idle_slope;
298 unsigned int traffic_class;
299 };
300};
301
304enum ethernet_qbv_param_type {
305 ETHERNET_QBV_PARAM_TYPE_STATUS,
306 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
307 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
308 ETHERNET_QBV_PARAM_TYPE_TIME,
309};
310
311enum ethernet_qbv_state_type {
312 ETHERNET_QBV_STATE_TYPE_ADMIN,
313 ETHERNET_QBV_STATE_TYPE_OPER,
314};
315
316enum ethernet_gate_state_operation {
317 ETHERNET_SET_GATE_STATE,
318 ETHERNET_SET_AND_HOLD_MAC_STATE,
319 ETHERNET_SET_AND_RELEASE_MAC_STATE,
320};
321
329 enum ethernet_qbv_param_type type;
331 enum ethernet_qbv_state_type state;
332 union {
335
337 struct {
339 bool gate_status[NET_TC_TX_COUNT];
340
342 enum ethernet_gate_state_operation operation;
343
346
350
353
358 struct {
361
364
367 };
368 };
369};
370
373enum ethernet_qbu_param_type {
374 ETHERNET_QBU_PARAM_TYPE_STATUS,
375 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
376 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
377 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
378
379 /* Some preemption settings are from Qbr spec. */
380 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
381 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
382};
383
384enum ethernet_qbu_preempt_status {
385 ETHERNET_QBU_STATUS_EXPRESS,
386 ETHERNET_QBU_STATUS_PREEMPTABLE
387} __packed;
388
396 enum ethernet_qbu_param_type type;
397 union {
400
403
405 enum ethernet_qbu_preempt_status
406 frame_preempt_statuses[NET_TC_TX_COUNT];
407
410
413
419 };
420};
421
424enum ethernet_filter_type {
425 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
426 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
427};
428
435
438} __packed;
439
443 enum ethernet_filter_type type;
447 bool set;
448};
449
452enum ethernet_txtime_param_type {
453 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
454};
455
461 enum ethernet_txtime_param_type type;
466};
467
470struct ethernet_config {
471 union {
472 bool auto_negotiation;
473 bool full_duplex;
474 bool promisc_mode;
475 bool txinjection_mode;
476
477 struct {
478 bool link_10bt;
479 bool link_100bt;
480 bool link_1000bt;
481 } l;
482
483 struct net_eth_addr mac_address;
484
485 struct ethernet_t1s_param t1s_param;
486 struct ethernet_qav_param qav_param;
487 struct ethernet_qbv_param qbv_param;
488 struct ethernet_qbu_param qbu_param;
489 struct ethernet_txtime_param txtime_param;
490
491 int priority_queues_num;
492 int ports_num;
493
494 struct ethernet_filter filter;
495 };
496};
497
506 struct net_if_api iface_api;
507
512#if defined(CONFIG_NET_STATISTICS_ETHERNET)
513 struct net_stats_eth *(*get_stats)(const struct device *dev);
514#endif
515
517 int (*start)(const struct device *dev);
518
520 int (*stop)(const struct device *dev);
521
523 enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
524
526 int (*set_config)(const struct device *dev,
527 enum ethernet_config_type type,
528 const struct ethernet_config *config);
529
531 int (*get_config)(const struct device *dev,
532 enum ethernet_config_type type,
533 struct ethernet_config *config);
534
540#if defined(CONFIG_NET_VLAN)
541 int (*vlan_setup)(const struct device *dev, struct net_if *iface,
542 uint16_t tag, bool enable);
543#endif /* CONFIG_NET_VLAN */
544
546#if defined(CONFIG_PTP_CLOCK)
547 const struct device *(*get_ptp_clock)(const struct device *dev);
548#endif /* CONFIG_PTP_CLOCK */
549
551 int (*send)(const struct device *dev, struct net_pkt *pkt);
552};
553
556/* Make sure that the network interface API is properly setup inside
557 * Ethernet API struct (it is the first one).
558 */
559BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
560
561struct net_eth_hdr {
562 struct net_eth_addr dst;
563 struct net_eth_addr src;
564 uint16_t type;
565} __packed;
566
567struct ethernet_vlan {
569 struct net_if *iface;
570
572 uint16_t tag;
573};
574
575#if defined(CONFIG_NET_VLAN_COUNT)
576#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
577#else
578/* Even thou there are no VLAN support, the minimum count must be set to 1.
579 */
580#define NET_VLAN_MAX_COUNT 1
581#endif
582
589
591 const struct net_lldpdu *lldpdu;
592
595
598
600 struct net_if *iface;
601
604
607
610};
611
614enum ethernet_flags {
615 ETH_CARRIER_UP,
616};
617
619struct ethernet_context {
624
625#if defined(CONFIG_NET_ETHERNET_BRIDGE)
626 struct eth_bridge_iface_context bridge;
627#endif
628
635 struct k_work carrier_work;
636
638 struct net_if *iface;
639
640#if defined(CONFIG_NET_LLDP)
641 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
642#endif
643
647 enum net_l2_flags ethernet_l2_flags;
648
649#if defined(CONFIG_NET_L2_PTP)
654 int port;
655#endif
656
657#if defined(CONFIG_NET_DSA)
661 dsa_net_recv_cb_t dsa_recv_cb;
662
664 uint8_t dsa_port_idx;
665
667 struct dsa_context *dsa_ctx;
668
670 dsa_send_t dsa_send;
671#endif
672
674 bool is_net_carrier_up : 1;
675
677 bool is_init : 1;
678
680 enum ethernet_if_types eth_if_type;
681};
682
688void ethernet_init(struct net_if *iface);
689
690#define ETHERNET_L2_CTX_TYPE struct ethernet_context
691
692/* Separate header for VLAN as some of device interfaces might not
693 * support VLAN.
694 */
695struct net_eth_vlan_hdr {
696 struct net_eth_addr dst;
697 struct net_eth_addr src;
698 struct {
699 uint16_t tpid; /* tag protocol id */
700 uint16_t tci; /* tag control info */
701 } vlan;
702 uint16_t type;
703} __packed;
704
714static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
715{
716 if (addr->addr[0] == 0xff &&
717 addr->addr[1] == 0xff &&
718 addr->addr[2] == 0xff &&
719 addr->addr[3] == 0xff &&
720 addr->addr[4] == 0xff &&
721 addr->addr[5] == 0xff) {
722 return true;
723 }
724
725 return false;
726}
727
735static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
736{
737 if (addr->addr[0] == 0x00 &&
738 addr->addr[1] == 0x00 &&
739 addr->addr[2] == 0x00 &&
740 addr->addr[3] == 0x00 &&
741 addr->addr[4] == 0x00 &&
742 addr->addr[5] == 0x00) {
743 return true;
744 }
745
746 return false;
747}
748
756static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
757{
758#if defined(CONFIG_NET_IPV6)
759 if (addr->addr[0] == 0x33 &&
760 addr->addr[1] == 0x33) {
761 return true;
762 }
763#endif
764
765#if defined(CONFIG_NET_IPV4)
766 if (addr->addr[0] == 0x01 &&
767 addr->addr[1] == 0x00 &&
768 addr->addr[2] == 0x5e) {
769 return true;
770 }
771#endif
772
773 return false;
774}
775
783static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
784{
785 return addr->addr[0] & 0x01;
786}
787
795static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
796{
798}
799
807static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
808{
809#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
810 if (addr->addr[0] == 0x01 &&
811 addr->addr[1] == 0x80 &&
812 addr->addr[2] == 0xc2 &&
813 addr->addr[3] == 0x00 &&
814 addr->addr[4] == 0x00 &&
815 addr->addr[5] == 0x0e) {
816 return true;
817 }
818#else
819 ARG_UNUSED(addr);
820#endif
821
822 return false;
823}
824
832static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
833{
834#if defined(CONFIG_NET_GPTP)
835 if (addr->addr[0] == 0x01 &&
836 addr->addr[1] == 0x1b &&
837 addr->addr[2] == 0x19 &&
838 addr->addr[3] == 0x00 &&
839 addr->addr[4] == 0x00 &&
840 addr->addr[5] == 0x00) {
841 return true;
842 }
843#else
844 ARG_UNUSED(addr);
845#endif
846
847 return false;
848}
849
856
863void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
864 struct net_eth_addr *mac_addr);
865
872void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
873 struct net_eth_addr *mac_addr);
874
882static inline
884{
885 const struct ethernet_api *eth =
886 (struct ethernet_api *)net_if_get_device(iface)->api;
887
888 if (!eth->get_capabilities) {
889 return (enum ethernet_hw_caps)0;
890 }
891
892 return eth->get_capabilities(net_if_get_device(iface));
893}
894
903#if defined(CONFIG_NET_VLAN)
904int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
905#else
906static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
907{
908 ARG_UNUSED(iface);
909 ARG_UNUSED(tag);
910
911 return -EINVAL;
912}
913#endif
914
923#if defined(CONFIG_NET_VLAN)
924int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
925#else
926static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
927{
928 ARG_UNUSED(iface);
929 ARG_UNUSED(tag);
930
931 return -EINVAL;
932}
933#endif
934
946#if defined(CONFIG_NET_VLAN)
948#else
949static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
950{
951 ARG_UNUSED(iface);
952
953 return NET_VLAN_TAG_UNSPEC;
954}
955#endif
956
966#if defined(CONFIG_NET_VLAN)
967struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
968#else
969static inline
970struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
971{
972 ARG_UNUSED(iface);
973 ARG_UNUSED(tag);
974
975 return NULL;
976}
977#endif
978
988#if defined(CONFIG_NET_VLAN)
989struct net_if *net_eth_get_vlan_main(struct net_if *iface);
990#else
991static inline
992struct net_if *net_eth_get_vlan_main(struct net_if *iface)
993{
994 ARG_UNUSED(iface);
995
996 return NULL;
997}
998#endif
999
1013#if defined(CONFIG_NET_VLAN)
1014bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1015 struct net_if *iface);
1016#else
1017static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
1018 struct net_if *iface)
1019{
1020 ARG_UNUSED(ctx);
1021 ARG_UNUSED(iface);
1022
1023 return false;
1024}
1025#endif
1026
1034#if defined(CONFIG_NET_VLAN)
1035bool net_eth_get_vlan_status(struct net_if *iface);
1036#else
1037static inline bool net_eth_get_vlan_status(struct net_if *iface)
1038{
1039 ARG_UNUSED(iface);
1040
1041 return false;
1042}
1043#endif
1044
1052#if defined(CONFIG_NET_VLAN)
1053bool net_eth_is_vlan_interface(struct net_if *iface);
1054#else
1055static inline bool net_eth_is_vlan_interface(struct net_if *iface)
1056{
1057 ARG_UNUSED(iface);
1058
1059 return false;
1060}
1061#endif
1062
1065#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
1066
1067#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1068 init_fn, pm, data, config, prio, \
1069 api, mtu) \
1070 Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1071 init_fn, pm, data, config, prio, \
1072 api, ETHERNET_L2, \
1073 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
1074
1075#else /* CONFIG_ETH_DRIVER_RAW_MODE */
1076
1077#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
1078 init_fn, pm, data, config, prio, \
1079 api, mtu) \
1080 Z_DEVICE_STATE_DEFINE(dev_id); \
1081 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
1082 config, POST_KERNEL, prio, api, \
1083 &Z_DEVICE_STATE_NAME(dev_id));
1084
1085#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
1086
1087#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
1088 config, prio, api, mtu) \
1089 Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
1090 init_fn, pm, data, config, prio, \
1091 api, mtu)
1092
1112#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
1113 prio, api, mtu) \
1114 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
1115 pm, data, config, prio, api, mtu)
1116
1139#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
1140 pm, data, config, prio, api, mtu) \
1141 Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
1142 instance, init_fn, pm, data, \
1143 config, prio, api, mtu)
1144
1161#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
1162 prio, api, mtu) \
1163 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
1164 DEVICE_DT_NAME(node_id), init_fn, pm, \
1165 data, config, prio, api, mtu)
1166
1176#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
1177 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
1178
1185void net_eth_carrier_on(struct net_if *iface);
1186
1193void net_eth_carrier_off(struct net_if *iface);
1194
1204int net_eth_promisc_mode(struct net_if *iface, bool enable);
1205
1215int net_eth_txinjection_mode(struct net_if *iface, bool enable);
1216
1227int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
1228 enum ethernet_filter_type type, bool enable);
1237#if defined(CONFIG_PTP_CLOCK)
1238const struct device *net_eth_get_ptp_clock(struct net_if *iface);
1239#else
1240static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
1241{
1242 ARG_UNUSED(iface);
1243
1244 return NULL;
1245}
1246#endif
1247
1257__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
1258
1266#if defined(CONFIG_NET_L2_PTP)
1267int net_eth_get_ptp_port(struct net_if *iface);
1268#else
1269static inline int net_eth_get_ptp_port(struct net_if *iface)
1270{
1271 ARG_UNUSED(iface);
1272
1273 return -ENODEV;
1274}
1275#endif /* CONFIG_NET_L2_PTP */
1276
1283#if defined(CONFIG_NET_L2_PTP)
1284void net_eth_set_ptp_port(struct net_if *iface, int port);
1285#else
1286static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
1287{
1288 ARG_UNUSED(iface);
1289 ARG_UNUSED(port);
1290}
1291#endif /* CONFIG_NET_L2_PTP */
1292
1300static inline bool net_eth_type_is_wifi(struct net_if *iface)
1301{
1302 const struct ethernet_context *ctx = (struct ethernet_context *)
1303 net_if_l2_data(iface);
1304
1305 return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
1306}
1307
1312#ifdef __cplusplus
1313}
1314#endif
1315
1316#include <syscalls/ethernet.h>
1317
1318#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:992
ethernet_if_types
Types of Ethernet L2.
Definition: ethernet.h:432
static void net_eth_set_ptp_port(struct net_if *iface, int port)
Set PTP port number attached to this interface.
Definition: ethernet.h:1286
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition: ethernet.h:906
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:756
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition: ethernet.h:1269
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:1240
#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:949
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:1300
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:714
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:1037
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:783
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:735
static bool net_eth_is_vlan_interface(struct net_if *iface)
Check if the given interface is a VLAN interface.
Definition: ethernet.h:1055
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:883
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:926
void net_eth_carrier_on(struct net_if *iface)
Inform ethernet L2 driver that ethernet carrier is detected.
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:1017
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:970
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:807
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:832
static bool net_eth_is_addr_valid(struct net_eth_addr *addr)
Check if the Ethernet MAC address is valid.
Definition: ethernet.h:795
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:434
@ L2_ETH_IF_TYPE_WIFI
IEEE 802.11 Wi-Fi.
Definition: ethernet.h:437
@ 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
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:923
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition: net_if.h:938
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 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:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405
Ethernet L2 API operations.
Definition: ethernet.h:501
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:506
int(* start)(const struct device *dev)
Collect optional ethernet specific statistics.
Definition: ethernet.h:517
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Get hardware specific configuration.
Definition: ethernet.h:531
int(* stop)(const struct device *dev)
Stop the device.
Definition: ethernet.h:520
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Get the device capabilities.
Definition: ethernet.h:523
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:551
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Set specific hardware configuration.
Definition: ethernet.h:526
Ethernet filter description.
Definition: ethernet.h:441
struct net_eth_addr mac_address
MAC address to filter.
Definition: ethernet.h:445
bool set
Set (true) or unset (false) the filter.
Definition: ethernet.h:447
enum ethernet_filter_type type
Type of filter.
Definition: ethernet.h:443
Ethernet LLDP specific parameters.
Definition: ethernet.h:586
const uint8_t * optional_du
LLDP Data Unit optional TLVs for the interface.
Definition: ethernet.h:594
sys_snode_t node
Used for track timers.
Definition: ethernet.h:588
net_lldp_recv_cb_t cb
LLDP RX callback function.
Definition: ethernet.h:609
size_t optional_len
Length of the optional Data Unit TLVs.
Definition: ethernet.h:597
struct net_if * iface
Network interface that has LLDP supported.
Definition: ethernet.h:600
const struct net_lldpdu * lldpdu
LLDP Data Unit mandatory TLVs for the interface.
Definition: ethernet.h:591
uint32_t tx_timer_timeout
LLDP TX timeout.
Definition: ethernet.h:606
int64_t tx_timer_start
LLDP TX timer start time.
Definition: ethernet.h:603
Ethernet Qav specific parameters.
Definition: ethernet.h:283
bool enabled
True if Qav is enabled for queue.
Definition: ethernet.h:290
unsigned int oper_idle_slope
Oper Idle Slope (bits per second)
Definition: ethernet.h:296
enum ethernet_qav_param_type type
Type of Qav parameter.
Definition: ethernet.h:287
unsigned int traffic_class
Traffic class the queue is bound to.
Definition: ethernet.h:298
int queue_id
ID of the priority queue to use.
Definition: ethernet.h:285
unsigned int idle_slope
Idle Slope (bits per second)
Definition: ethernet.h:294
unsigned int delta_bandwidth
Delta Bandwidth (percentage of bandwidth)
Definition: ethernet.h:292
Ethernet Qbu specific parameters.
Definition: ethernet.h:392
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
sequence of framePreemptionAdminStatus values
Definition: ethernet.h:405
uint32_t release_advance
Release advance (nanoseconds)
Definition: ethernet.h:402
enum ethernet_qbu_param_type type
Type of Qbu parameter.
Definition: ethernet.h:396
uint32_t hold_advance
Hold advance (nanoseconds)
Definition: ethernet.h:399
bool enabled
True if Qbu is enabled or not.
Definition: ethernet.h:409
bool link_partner_status
Link partner status (from Qbr)
Definition: ethernet.h:412
int port_id
Port id.
Definition: ethernet.h:394
uint8_t additional_fragment_size
Additional fragment size (from Qbr).
Definition: ethernet.h:418
Ethernet Qbv specific parameters.
Definition: ethernet.h:325
int port_id
Port id.
Definition: ethernet.h:327
bool enabled
True if Qbv is enabled or not.
Definition: ethernet.h:334
struct ethernet_qbv_param::@290::@292 gate_control
Gate control information.
enum ethernet_qbv_param_type type
Type of Qbv parameter.
Definition: ethernet.h:329
uint16_t row
Gate control list row.
Definition: ethernet.h:348
enum ethernet_qbv_state_type state
What state (Admin/Oper) parameters are these.
Definition: ethernet.h:331
bool gate_status[NET_TC_TX_COUNT]
True = open, False = closed.
Definition: ethernet.h:339
struct net_ptp_extended_time base_time
Base time.
Definition: ethernet.h:360
uint32_t extension_time
Extension time (nanoseconds)
Definition: ethernet.h:366
enum ethernet_gate_state_operation operation
GateState operation.
Definition: ethernet.h:342
uint32_t time_interval
Time interval ticks (nanoseconds)
Definition: ethernet.h:345
struct net_ptp_time cycle_time
Cycle time.
Definition: ethernet.h:363
uint32_t gate_control_list_len
Number of entries in gate control list.
Definition: ethernet.h:352
Ethernet T1S specific parameters.
Definition: ethernet.h:238
uint8_t burst_count
T1S PLCA burst count range: 0x0 to 0xFF.
Definition: ethernet.h:273
struct ethernet_t1s_param::@285::@287 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:271
uint8_t to_timer
T1S PLCA TO value.
Definition: ethernet.h:277
uint8_t burst_timer
T1S PLCA burst timer.
Definition: ethernet.h:275
uint8_t node_id
T1S PLCA node id range: 0 to 254.
Definition: ethernet.h:269
enum ethernet_t1s_param_type type
Type of T1S parameter.
Definition: ethernet.h:240
bool enable
T1S PLCA enabled.
Definition: ethernet.h:267
Ethernet TXTIME specific parameters.
Definition: ethernet.h:459
bool enable_txtime
Enable or disable TXTIME per queue.
Definition: ethernet.h:465
int queue_id
Queue number for configuring TXTIME.
Definition: ethernet.h:463
enum ethernet_txtime_param_type type
Type of TXTIME parameter.
Definition: ethernet.h:461
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:3875
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:675
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.