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
70#if !defined(ETH_P_ALL)
71#define ETH_P_ALL NET_ETH_PTYPE_ALL
74#define ETH_P_IP NET_ETH_PTYPE_IP
76#if !defined(ETH_P_ARP)
77#define ETH_P_ARP NET_ETH_PTYPE_ARP
79#if !defined(ETH_P_IPV6)
80#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
82#if !defined(ETH_P_8021Q)
83#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
85#if !defined(ETH_P_TSN)
86#define ETH_P_TSN NET_ETH_PTYPE_TSN
88#if !defined(ETH_P_ECAT)
89#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
92#define NET_ETH_MINIMAL_FRAME_SIZE 60
93#define NET_ETH_MTU 1500
94#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + sizeof(struct net_eth_hdr))
95#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
100#if defined(CONFIG_NET_DSA)
101#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
102#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
104#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
105#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
108#define NET_ETH_VLAN_HDR_SIZE 4
175enum ethernet_config_type {
176 ETHERNET_CONFIG_TYPE_AUTO_NEG,
177 ETHERNET_CONFIG_TYPE_LINK,
178 ETHERNET_CONFIG_TYPE_DUPLEX,
179 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
180 ETHERNET_CONFIG_TYPE_QAV_PARAM,
181 ETHERNET_CONFIG_TYPE_QBV_PARAM,
182 ETHERNET_CONFIG_TYPE_QBU_PARAM,
183 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
184 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
185 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
186 ETHERNET_CONFIG_TYPE_FILTER,
187 ETHERNET_CONFIG_TYPE_PORTS_NUM,
190enum ethernet_qav_param_type {
191 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
192 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
193 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
194 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
195 ETHERNET_QAV_PARAM_TYPE_STATUS,
204 enum ethernet_qav_param_type
type;
221enum ethernet_qbv_param_type {
222 ETHERNET_QBV_PARAM_TYPE_STATUS,
223 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
224 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
225 ETHERNET_QBV_PARAM_TYPE_TIME,
228enum ethernet_qbv_state_type {
229 ETHERNET_QBV_STATE_TYPE_ADMIN,
230 ETHERNET_QBV_STATE_TYPE_OPER,
233enum ethernet_gate_state_operation {
234 ETHERNET_SET_GATE_STATE,
235 ETHERNET_SET_AND_HOLD_MAC_STATE,
236 ETHERNET_SET_AND_RELEASE_MAC_STATE,
245 enum ethernet_qbv_param_type
type;
287enum ethernet_qbu_param_type {
288 ETHERNET_QBU_PARAM_TYPE_STATUS,
289 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
290 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
291 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
294 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
295 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
298enum ethernet_qbu_preempt_status {
299 ETHERNET_QBU_STATUS_EXPRESS,
300 ETHERNET_QBU_STATUS_PREEMPTABLE
309 enum ethernet_qbu_param_type
type;
319 enum ethernet_qbu_preempt_status
338enum ethernet_filter_type {
339 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
340 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
347 enum ethernet_filter_type
type;
356enum ethernet_txtime_param_type {
357 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
364 enum ethernet_txtime_param_type
type;
372struct ethernet_config {
374 bool auto_negotiation;
384 struct net_eth_addr mac_address;
391 int priority_queues_num;
406#if defined(CONFIG_NET_STATISTICS_ETHERNET)
425 enum ethernet_config_type type,
426 const struct ethernet_config *config);
430 enum ethernet_config_type type,
431 struct ethernet_config *config);
433#if defined(CONFIG_NET_VLAN)
439 int (*vlan_setup)(
const struct device *dev,
struct net_if *iface,
443#if defined(CONFIG_PTP_CLOCK)
445 const struct device *(*get_ptp_clock)(
const struct device *dev);
455BUILD_ASSERT(offsetof(
struct ethernet_api, iface_api) == 0);
459 struct net_eth_addr dst;
460 struct net_eth_addr src;
464struct ethernet_vlan {
472#if defined(CONFIG_NET_VLAN_COUNT)
473#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
477#define NET_VLAN_MAX_COUNT 1
482#if defined(CONFIG_NET_LLDP)
483struct ethernet_lldp {
521#if defined(CONFIG_NET_VLAN)
522 struct ethernet_vlan vlan[NET_VLAN_MAX_COUNT];
532#if defined(CONFIG_NET_ETHERNET_BRIDGE)
547#if defined(CONFIG_NET_LLDP)
548 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
556#if defined(CONFIG_NET_L2_PTP)
564#if defined(CONFIG_NET_DSA)
574 struct dsa_context *dsa_ctx;
580#if defined(CONFIG_NET_VLAN)
604#define ETHERNET_L2_CTX_TYPE struct ethernet_context
609struct net_eth_vlan_hdr {
610 struct net_eth_addr dst;
611 struct net_eth_addr src;
620static inline bool net_eth_is_addr_broadcast(
struct net_eth_addr *addr)
622 if (addr->addr[0] == 0xff &&
623 addr->addr[1] == 0xff &&
624 addr->addr[2] == 0xff &&
625 addr->addr[3] == 0xff &&
626 addr->addr[4] == 0xff &&
627 addr->addr[5] == 0xff) {
634static inline bool net_eth_is_addr_unspecified(
struct net_eth_addr *addr)
636 if (addr->addr[0] == 0x00 &&
637 addr->addr[1] == 0x00 &&
638 addr->addr[2] == 0x00 &&
639 addr->addr[3] == 0x00 &&
640 addr->addr[4] == 0x00 &&
641 addr->addr[5] == 0x00) {
648static inline bool net_eth_is_addr_multicast(
struct net_eth_addr *addr)
650#if defined(CONFIG_NET_IPV6)
651 if (addr->addr[0] == 0x33 &&
652 addr->addr[1] == 0x33) {
657#if defined(CONFIG_NET_IPV4)
658 if (addr->addr[0] == 0x01 &&
659 addr->addr[1] == 0x00 &&
660 addr->addr[2] == 0x5e) {
668static inline bool net_eth_is_addr_lldp_multicast(
struct net_eth_addr *addr)
670#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
671 if (addr->addr[0] == 0x01 &&
672 addr->addr[1] == 0x80 &&
673 addr->addr[2] == 0xc2 &&
674 addr->addr[3] == 0x00 &&
675 addr->addr[4] == 0x00 &&
676 addr->addr[5] == 0x0e) {
684const struct net_eth_addr *net_eth_broadcast_addr(
void);
695 struct net_eth_addr *mac_addr);
704 struct net_eth_addr *mac_addr);
734#if defined(CONFIG_NET_VLAN)
751#if defined(CONFIG_NET_VLAN)
768#if defined(CONFIG_NET_VLAN)
787#if defined(CONFIG_NET_VLAN)
805#if defined(CONFIG_NET_VLAN)
823#if defined(CONFIG_NET_VLAN)
832#if defined(CONFIG_NET_VLAN)
833#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
834 pm_action_cb, data, cfg, prio, api, mtu) \
835 Z_DEVICE_STATE_DEFINE(node_id, dev_name) \
836 Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
837 pm_action_cb, data, cfg, POST_KERNEL, \
838 prio, api, &Z_DEVICE_STATE_NAME(dev_name)); \
839 NET_L2_DATA_INIT(dev_name, 0, NET_L2_GET_CTX_TYPE(ETHERNET_L2));\
840 NET_IF_INIT(dev_name, 0, ETHERNET_L2, mtu, NET_VLAN_MAX_COUNT)
844#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
845 pm_action_cb, data, cfg, prio, api, mtu) \
846 Z_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
847 pm_action_cb, data, cfg, prio, api, \
848 ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),\
871#define ETH_NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_action_cb, \
872 data, cfg, prio, api, mtu) \
873 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_name, drv_name, \
874 init_fn, pm_action_cb, data, cfg, prio, \
895#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_action_cb, data, \
896 cfg, prio, api, mtu) \
897 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
898 DT_PROP_OR(node_id, label, ""), \
899 init_fn, pm_action_cb, data, cfg, prio, \
913#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
914 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
951#if defined(CONFIG_PTP_CLOCK)
980#if defined(CONFIG_NET_L2_PTP)
997#if defined(CONFIG_NET_L2_PTP)
998void net_eth_set_ptp_port(
struct net_if *iface,
int port);
1009#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:737
static int net_eth_get_ptp_port(struct net_if *iface)
Return PTP port number attached to this interface.
Definition: ethernet.h:983
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:954
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:771
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: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.
ethernet_hw_caps
Definition: ethernet.h:113
ethernet_flags
Definition: ethernet.h:510
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:714
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:754
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:809
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:791
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:121
@ ETHERNET_PRIORITY_QUEUES
Definition: ethernet.h:148
@ ETHERNET_DUPLEX_SET
Definition: ethernet.h:136
@ ETHERNET_HW_VLAN_TAG_STRIP
Definition: ethernet.h:157
@ ETHERNET_LINK_10BASE_T
Definition: ethernet.h:127
@ ETHERNET_HW_FILTERING
Definition: ethernet.h:151
@ ETHERNET_PTP
Definition: ethernet.h:139
@ ETHERNET_QBU
Definition: ethernet.h:167
@ ETHERNET_LINK_100BASE_T
Definition: ethernet.h:130
@ ETHERNET_DSA_MASTER_PORT
Definition: ethernet.h:161
@ ETHERNET_DSA_SLAVE_PORT
Definition: ethernet.h:160
@ ETHERNET_QAV
Definition: ethernet.h:142
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
Definition: ethernet.h:118
@ ETHERNET_LINK_1000BASE_T
Definition: ethernet.h:133
@ ETHERNET_LLDP
Definition: ethernet.h:154
@ ETHERNET_AUTO_NEGOTIATION_SET
Definition: ethernet.h:124
@ ETHERNET_TXTIME
Definition: ethernet.h:170
@ ETHERNET_QBV
Definition: ethernet.h:164
@ ETHERNET_PROMISC_MODE
Definition: ethernet.h:145
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
Definition: ethernet.h:115
@ ETH_CARRIER_UP
Definition: ethernet.h:511
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:606
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:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
__INT64_TYPE__ int64_t
Definition: stdint.h:45
__INT8_TYPE__ int8_t
Definition: stdint.h:42
Runtime device structure (in ROM) per driver instance.
Definition: device.h:450
const void * api
Definition: device.h:456
Definition: ethernet_bridge.h:57
Definition: ethernet.h:399
struct net_if_api iface_api
Definition: ethernet.h:404
int(* start)(const struct device *dev)
Definition: ethernet.h:415
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Definition: ethernet.h:429
int(* stop)(const struct device *dev)
Definition: ethernet.h:418
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Definition: ethernet.h:421
int(* send)(const struct device *dev, struct net_pkt *pkt)
Definition: ethernet.h:449
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Definition: ethernet.h:424
Definition: ethernet.h:515
struct net_if * iface
Definition: ethernet.h:545
bool is_net_carrier_up
Definition: ethernet.h:589
enum net_l2_flags ethernet_l2_flags
Definition: ethernet.h:554
struct k_work carrier_work
Definition: ethernet.h:542
atomic_t flags
Definition: ethernet.h:519
bool is_init
Definition: ethernet.h:592
Definition: ethernet.h:345
struct net_eth_addr mac_address
Definition: ethernet.h:349
bool set
Definition: ethernet.h:351
enum ethernet_filter_type type
Definition: ethernet.h:347
Definition: ethernet.h:200
bool enabled
Definition: ethernet.h:207
unsigned int oper_idle_slope
Definition: ethernet.h:213
enum ethernet_qav_param_type type
Definition: ethernet.h:204
unsigned int traffic_class
Definition: ethernet.h:215
int queue_id
Definition: ethernet.h:202
unsigned int idle_slope
Definition: ethernet.h:211
unsigned int delta_bandwidth
Definition: ethernet.h:209
Definition: ethernet.h:305
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
Definition: ethernet.h:319
uint32_t release_advance
Definition: ethernet.h:315
enum ethernet_qbu_param_type type
Definition: ethernet.h:309
uint32_t hold_advance
Definition: ethernet.h:312
bool enabled
Definition: ethernet.h:323
bool link_partner_status
Definition: ethernet.h:326
int port_id
Definition: ethernet.h:307
uint8_t additional_fragment_size
Definition: ethernet.h:331
Definition: ethernet.h:241
int port_id
Definition: ethernet.h:243
bool enabled
Definition: ethernet.h:250
enum ethernet_qbv_param_type type
Definition: ethernet.h:245
uint16_t row
Definition: ethernet.h:263
enum ethernet_qbv_state_type state
Definition: ethernet.h:247
bool gate_status[NET_TC_TX_COUNT]
Definition: ethernet.h:254
struct net_ptp_extended_time base_time
Definition: ethernet.h:274
uint32_t extension_time
Definition: ethernet.h:280
enum ethernet_gate_state_operation operation
Definition: ethernet.h:257
struct ethernet_qbv_param::@150::@152 gate_control
uint32_t time_interval
Definition: ethernet.h:260
struct net_ptp_time cycle_time
Definition: ethernet.h:277
uint32_t gate_control_list_len
Definition: ethernet.h:267
Definition: ethernet.h:362
bool enable_txtime
Definition: ethernet.h:368
int queue_id
Definition: ethernet.h:366
enum ethernet_txtime_param_type type
Definition: ethernet.h:364
A structure used to submit work.
Definition: kernel.h:3572
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
Precision Time Protocol Extended Timestamp format.
Definition: ptp_time.h:76
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