13#ifndef ZEPHYR_INCLUDE_NET_ETHERNET_H_
14#define ZEPHYR_INCLUDE_NET_ETHERNET_H_
24#if defined(CONFIG_NET_LLDP)
33#if defined(CONFIG_NET_DSA)
37#if defined(CONFIG_NET_ETHERNET_BRIDGE)
58#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
60#define NET_ETH_PTYPE_ARP 0x0806
61#define NET_ETH_PTYPE_IP 0x0800
62#define NET_ETH_PTYPE_TSN 0x22f0
63#define NET_ETH_PTYPE_IPV6 0x86dd
64#define NET_ETH_PTYPE_VLAN 0x8100
65#define NET_ETH_PTYPE_PTP 0x88f7
66#define NET_ETH_PTYPE_LLDP 0x88cc
67#define NET_ETH_PTYPE_ALL 0x0003
68#define NET_ETH_PTYPE_ECAT 0x88a4
69#define NET_ETH_PTYPE_EAPOL 0x888e
70#define NET_ETH_PTYPE_IEEE802154 0x00F6
72#if !defined(ETH_P_ALL)
73#define ETH_P_ALL NET_ETH_PTYPE_ALL
76#define ETH_P_IP NET_ETH_PTYPE_IP
78#if !defined(ETH_P_ARP)
79#define ETH_P_ARP NET_ETH_PTYPE_ARP
81#if !defined(ETH_P_IPV6)
82#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
84#if !defined(ETH_P_8021Q)
85#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
87#if !defined(ETH_P_TSN)
88#define ETH_P_TSN NET_ETH_PTYPE_TSN
90#if !defined(ETH_P_ECAT)
91#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
93#if !defined(ETH_P_IEEE802154)
94#define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
97#define NET_ETH_MINIMAL_FRAME_SIZE 60
98#define NET_ETH_MTU 1500
99#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + sizeof(struct net_eth_hdr))
100#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
105#if defined(CONFIG_NET_DSA)
106#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
107#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
109#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
110#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
113#define NET_ETH_VLAN_HDR_SIZE 4
180enum ethernet_config_type {
181 ETHERNET_CONFIG_TYPE_AUTO_NEG,
182 ETHERNET_CONFIG_TYPE_LINK,
183 ETHERNET_CONFIG_TYPE_DUPLEX,
184 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
185 ETHERNET_CONFIG_TYPE_QAV_PARAM,
186 ETHERNET_CONFIG_TYPE_QBV_PARAM,
187 ETHERNET_CONFIG_TYPE_QBU_PARAM,
188 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
189 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
190 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
191 ETHERNET_CONFIG_TYPE_FILTER,
192 ETHERNET_CONFIG_TYPE_PORTS_NUM,
195enum ethernet_qav_param_type {
196 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
197 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
198 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
199 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
200 ETHERNET_QAV_PARAM_TYPE_STATUS,
209 enum ethernet_qav_param_type
type;
226enum ethernet_qbv_param_type {
227 ETHERNET_QBV_PARAM_TYPE_STATUS,
228 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
229 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
230 ETHERNET_QBV_PARAM_TYPE_TIME,
233enum ethernet_qbv_state_type {
234 ETHERNET_QBV_STATE_TYPE_ADMIN,
235 ETHERNET_QBV_STATE_TYPE_OPER,
238enum ethernet_gate_state_operation {
239 ETHERNET_SET_GATE_STATE,
240 ETHERNET_SET_AND_HOLD_MAC_STATE,
241 ETHERNET_SET_AND_RELEASE_MAC_STATE,
250 enum ethernet_qbv_param_type
type;
292enum ethernet_qbu_param_type {
293 ETHERNET_QBU_PARAM_TYPE_STATUS,
294 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
295 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
296 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
299 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
300 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
303enum ethernet_qbu_preempt_status {
304 ETHERNET_QBU_STATUS_EXPRESS,
305 ETHERNET_QBU_STATUS_PREEMPTABLE
314 enum ethernet_qbu_param_type
type;
324 enum ethernet_qbu_preempt_status
343enum ethernet_filter_type {
344 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
345 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
352 enum ethernet_filter_type
type;
361enum ethernet_txtime_param_type {
362 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
369 enum ethernet_txtime_param_type
type;
377struct ethernet_config {
379 bool auto_negotiation;
389 struct net_eth_addr mac_address;
396 int priority_queues_num;
411#if defined(CONFIG_NET_STATISTICS_ETHERNET)
430 enum ethernet_config_type type,
431 const struct ethernet_config *config);
435 enum ethernet_config_type type,
436 struct ethernet_config *config);
438#if defined(CONFIG_NET_VLAN)
444 int (*vlan_setup)(
const struct device *dev,
struct net_if *iface,
448#if defined(CONFIG_PTP_CLOCK)
450 const struct device *(*get_ptp_clock)(
const struct device *dev);
460BUILD_ASSERT(offsetof(
struct ethernet_api, iface_api) == 0);
464 struct net_eth_addr dst;
465 struct net_eth_addr src;
469struct ethernet_vlan {
477#if defined(CONFIG_NET_VLAN_COUNT)
478#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
482#define NET_VLAN_MAX_COUNT 1
487#if defined(CONFIG_NET_LLDP)
488struct ethernet_lldp {
526#if defined(CONFIG_NET_VLAN)
527 struct ethernet_vlan vlan[NET_VLAN_MAX_COUNT];
537#if defined(CONFIG_NET_ETHERNET_BRIDGE)
552#if defined(CONFIG_NET_LLDP)
553 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
561#if defined(CONFIG_NET_L2_PTP)
569#if defined(CONFIG_NET_DSA)
579 struct dsa_context *dsa_ctx;
585#if defined(CONFIG_NET_VLAN)
609#define ETHERNET_L2_CTX_TYPE struct ethernet_context
614struct net_eth_vlan_hdr {
615 struct net_eth_addr dst;
616 struct net_eth_addr src;
625static inline bool net_eth_is_addr_broadcast(
struct net_eth_addr *addr)
627 if (addr->addr[0] == 0xff &&
628 addr->addr[1] == 0xff &&
629 addr->addr[2] == 0xff &&
630 addr->addr[3] == 0xff &&
631 addr->addr[4] == 0xff &&
632 addr->addr[5] == 0xff) {
639static inline bool net_eth_is_addr_unspecified(
struct net_eth_addr *addr)
641 if (addr->addr[0] == 0x00 &&
642 addr->addr[1] == 0x00 &&
643 addr->addr[2] == 0x00 &&
644 addr->addr[3] == 0x00 &&
645 addr->addr[4] == 0x00 &&
646 addr->addr[5] == 0x00) {
653static inline bool net_eth_is_addr_multicast(
struct net_eth_addr *addr)
655#if defined(CONFIG_NET_IPV6)
656 if (addr->addr[0] == 0x33 &&
657 addr->addr[1] == 0x33) {
662#if defined(CONFIG_NET_IPV4)
663 if (addr->addr[0] == 0x01 &&
664 addr->addr[1] == 0x00 &&
665 addr->addr[2] == 0x5e) {
673static inline bool net_eth_is_addr_group(
struct net_eth_addr *addr)
675 return addr->addr[0] & 0x01;
678static inline bool net_eth_is_addr_valid(
struct net_eth_addr *addr)
680 return !net_eth_is_addr_unspecified(addr) && !net_eth_is_addr_group(addr);
683static inline bool net_eth_is_addr_lldp_multicast(
struct net_eth_addr *addr)
685#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
686 if (addr->addr[0] == 0x01 &&
687 addr->addr[1] == 0x80 &&
688 addr->addr[2] == 0xc2 &&
689 addr->addr[3] == 0x00 &&
690 addr->addr[4] == 0x00 &&
691 addr->addr[5] == 0x0e) {
699const struct net_eth_addr *net_eth_broadcast_addr(
void);
710 struct net_eth_addr *mac_addr);
719 struct net_eth_addr *mac_addr);
749#if defined(CONFIG_NET_VLAN)
766#if defined(CONFIG_NET_VLAN)
783#if defined(CONFIG_NET_VLAN)
802#if defined(CONFIG_NET_VLAN)
820#if defined(CONFIG_NET_VLAN)
838#if defined(CONFIG_NET_VLAN)
847#if defined(CONFIG_NET_VLAN)
848#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
849 config, prio, api, mtu) \
850 Z_DEVICE_STATE_DEFINE(dev_id); \
851 Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
852 config, POST_KERNEL, prio, api, \
853 &Z_DEVICE_STATE_NAME(dev_id)); \
854 NET_L2_DATA_INIT(dev_id, 0, NET_L2_GET_CTX_TYPE(ETHERNET_L2)); \
855 NET_IF_INIT(dev_id, 0, ETHERNET_L2, mtu, NET_VLAN_MAX_COUNT)
859#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
860 config, prio, api, mtu) \
861 Z_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
862 config, prio, api, ETHERNET_L2, \
863 NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
883#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
885 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
886 pm, data, config, prio, api, mtu)
904#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
906 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
907 DEVICE_DT_NAME(node_id), init_fn, pm, \
908 data, config, prio, api, mtu)
919#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
920 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
957#if defined(CONFIG_PTP_CLOCK)
986#if defined(CONFIG_NET_L2_PTP)
1003#if defined(CONFIG_NET_L2_PTP)
1004void net_eth_set_ptp_port(
struct net_if *iface,
int port);
1015#include <syscalls/ethernet.h>
long atomic_t
Definition: atomic.h:22
ZTEST_BMEM int index[(3)]
Definition: main.c:32
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:68
int(* dsa_send_t)(const struct device *dev, struct net_pkt *pkt)
Pointer to master interface send function.
Definition: dsa.h:94
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition: atomic.h:114
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition: ethernet.h:752
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition: ethernet.h:989
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:960
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. This happens when cable is disconnected.
static uint16_t net_eth_get_vlan_tag(struct net_if *iface)
Return VLAN tag specified to network interface.
Definition: ethernet.h:786
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:841
const struct device * net_eth_get_ptp_clock_by_index(int index)
Return PTP clock that is tied to this ethernet network interface index.
ethernet_hw_caps
Definition: ethernet.h:118
ethernet_flags
Definition: ethernet.h:515
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:729
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:769
void net_eth_carrier_on(struct net_if *iface)
Inform ethernet L2 driver that ethernet carrier is detected. This happens when cable is connected.
static bool net_eth_is_vlan_enabled(struct ethernet_context *ctx, struct net_if *iface)
Check if VLAN is enabled for a specific network interface.
Definition: ethernet.h:824
void ethernet_init(struct net_if *iface)
Initialize Ethernet L2 stack for a given interface.
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:806
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.
@ ETHERNET_HW_VLAN
Definition: ethernet.h:126
@ ETHERNET_PRIORITY_QUEUES
Definition: ethernet.h:153
@ ETHERNET_DUPLEX_SET
Definition: ethernet.h:141
@ ETHERNET_HW_VLAN_TAG_STRIP
Definition: ethernet.h:162
@ ETHERNET_LINK_10BASE_T
Definition: ethernet.h:132
@ ETHERNET_HW_FILTERING
Definition: ethernet.h:156
@ ETHERNET_PTP
Definition: ethernet.h:144
@ ETHERNET_QBU
Definition: ethernet.h:172
@ ETHERNET_LINK_100BASE_T
Definition: ethernet.h:135
@ ETHERNET_DSA_MASTER_PORT
Definition: ethernet.h:166
@ ETHERNET_DSA_SLAVE_PORT
Definition: ethernet.h:165
@ ETHERNET_QAV
Definition: ethernet.h:147
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
Definition: ethernet.h:123
@ ETHERNET_LINK_1000BASE_T
Definition: ethernet.h:138
@ ETHERNET_LLDP
Definition: ethernet.h:159
@ ETHERNET_AUTO_NEGOTIATION_SET
Definition: ethernet.h:129
@ ETHERNET_TXTIME
Definition: ethernet.h:175
@ ETHERNET_QBV
Definition: ethernet.h:169
@ ETHERNET_PROMISC_MODE
Definition: ethernet.h:150
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
Definition: ethernet.h:120
@ ETH_CARRIER_UP
Definition: ethernet.h:516
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 const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition: net_if.h:698
net_l2_flags
Definition: net_l2.h:33
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define EINVAL
Definition: errno.h:61
#define ENODEV
Definition: errno.h:58
#define NET_VLAN_TAG_UNSPEC
Definition: ethernet_vlan.h:30
LLDP definitions and handler.
Public API for network interface.
IPv6 and IPv4 definitions.
Network packet buffer descriptor API.
Public functions for the Precision Time Protocol time specification.
struct _snode sys_snode_t
Definition: slist.h:33
__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
__INT8_TYPE__ int8_t
Definition: stdint.h:72
Runtime device structure (in ROM) per driver instance.
Definition: device.h:378
const void * api
Definition: device.h:384
Definition: ethernet_bridge.h:58
Definition: ethernet.h:404
struct net_if_api iface_api
Definition: ethernet.h:409
int(* start)(const struct device *dev)
Definition: ethernet.h:420
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Definition: ethernet.h:434
int(* stop)(const struct device *dev)
Definition: ethernet.h:423
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Definition: ethernet.h:426
int(* send)(const struct device *dev, struct net_pkt *pkt)
Definition: ethernet.h:454
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Definition: ethernet.h:429
Definition: ethernet.h:520
struct net_if * iface
Definition: ethernet.h:550
bool is_net_carrier_up
Definition: ethernet.h:594
enum net_l2_flags ethernet_l2_flags
Definition: ethernet.h:559
struct k_work carrier_work
Definition: ethernet.h:547
atomic_t flags
Definition: ethernet.h:524
bool is_init
Definition: ethernet.h:597
Definition: ethernet.h:350
struct net_eth_addr mac_address
Definition: ethernet.h:354
bool set
Definition: ethernet.h:356
enum ethernet_filter_type type
Definition: ethernet.h:352
Definition: ethernet.h:205
bool enabled
Definition: ethernet.h:212
unsigned int oper_idle_slope
Definition: ethernet.h:218
enum ethernet_qav_param_type type
Definition: ethernet.h:209
unsigned int traffic_class
Definition: ethernet.h:220
int queue_id
Definition: ethernet.h:207
unsigned int idle_slope
Definition: ethernet.h:216
unsigned int delta_bandwidth
Definition: ethernet.h:214
Definition: ethernet.h:310
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
Definition: ethernet.h:324
uint32_t release_advance
Definition: ethernet.h:320
enum ethernet_qbu_param_type type
Definition: ethernet.h:314
uint32_t hold_advance
Definition: ethernet.h:317
bool enabled
Definition: ethernet.h:328
bool link_partner_status
Definition: ethernet.h:331
int port_id
Definition: ethernet.h:312
uint8_t additional_fragment_size
Definition: ethernet.h:336
Definition: ethernet.h:246
int port_id
Definition: ethernet.h:248
bool enabled
Definition: ethernet.h:255
enum ethernet_qbv_param_type type
Definition: ethernet.h:250
uint16_t row
Definition: ethernet.h:268
enum ethernet_qbv_state_type state
Definition: ethernet.h:252
bool gate_status[NET_TC_TX_COUNT]
Definition: ethernet.h:259
struct net_ptp_extended_time base_time
Definition: ethernet.h:279
uint32_t extension_time
Definition: ethernet.h:285
enum ethernet_gate_state_operation operation
Definition: ethernet.h:262
struct ethernet_qbv_param::@209::@211 gate_control
uint32_t time_interval
Definition: ethernet.h:265
struct net_ptp_time cycle_time
Definition: ethernet.h:282
uint32_t gate_control_list_len
Definition: ethernet.h:272
Definition: ethernet.h:367
bool enable_txtime
Definition: ethernet.h:373
int queue_id
Definition: ethernet.h:371
enum ethernet_txtime_param_type type
Definition: ethernet.h:369
A structure used to submit work.
Definition: kernel.h:3707
Network Interface structure.
Definition: net_if.h:510
Network packet.
Definition: net_pkt.h:62
Precision Time Protocol Extended Timestamp format.
Definition: ptp_time.h:74
Precision Time Protocol Timestamp format.
Definition: ptp_time.h:39
All Ethernet specific statistics.
Definition: net_stats.h:441
static const char * tag(void)
Definition: main.c:27