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
69#if !defined(ETH_P_ALL)
70#define ETH_P_ALL NET_ETH_PTYPE_ALL
73#define ETH_P_IP NET_ETH_PTYPE_IP
75#if !defined(ETH_P_ARP)
76#define ETH_P_ARP NET_ETH_PTYPE_ARP
78#if !defined(ETH_P_IPV6)
79#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
81#if !defined(ETH_P_8021Q)
82#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
84#if !defined(ETH_P_TSN)
85#define ETH_P_TSN NET_ETH_PTYPE_TSN
88#define NET_ETH_MINIMAL_FRAME_SIZE 60
89#define NET_ETH_MTU 1500
90#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + sizeof(struct net_eth_hdr))
91#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
96#if defined(CONFIG_NET_DSA)
97#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
98#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
100#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
101#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
104#define NET_ETH_VLAN_HDR_SIZE 4
171enum ethernet_config_type {
172 ETHERNET_CONFIG_TYPE_AUTO_NEG,
173 ETHERNET_CONFIG_TYPE_LINK,
174 ETHERNET_CONFIG_TYPE_DUPLEX,
175 ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
176 ETHERNET_CONFIG_TYPE_QAV_PARAM,
177 ETHERNET_CONFIG_TYPE_QBV_PARAM,
178 ETHERNET_CONFIG_TYPE_QBU_PARAM,
179 ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
180 ETHERNET_CONFIG_TYPE_PROMISC_MODE,
181 ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
182 ETHERNET_CONFIG_TYPE_FILTER,
183 ETHERNET_CONFIG_TYPE_PORTS_NUM,
186enum ethernet_qav_param_type {
187 ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
188 ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
189 ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
190 ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
191 ETHERNET_QAV_PARAM_TYPE_STATUS,
200 enum ethernet_qav_param_type
type;
217enum ethernet_qbv_param_type {
218 ETHERNET_QBV_PARAM_TYPE_STATUS,
219 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
220 ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
221 ETHERNET_QBV_PARAM_TYPE_TIME,
224enum ethernet_qbv_state_type {
225 ETHERNET_QBV_STATE_TYPE_ADMIN,
226 ETHERNET_QBV_STATE_TYPE_OPER,
229enum ethernet_gate_state_operation {
230 ETHERNET_SET_GATE_STATE,
231 ETHERNET_SET_AND_HOLD_MAC_STATE,
232 ETHERNET_SET_AND_RELEASE_MAC_STATE,
241 enum ethernet_qbv_param_type
type;
283enum ethernet_qbu_param_type {
284 ETHERNET_QBU_PARAM_TYPE_STATUS,
285 ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
286 ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
287 ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
290 ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
291 ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
294enum ethernet_qbu_preempt_status {
295 ETHERNET_QBU_STATUS_EXPRESS,
296 ETHERNET_QBU_STATUS_PREEMPTABLE
305 enum ethernet_qbu_param_type
type;
315 enum ethernet_qbu_preempt_status
334enum ethernet_filter_type {
335 ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
336 ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
343 enum ethernet_filter_type
type;
352enum ethernet_txtime_param_type {
353 ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
360 enum ethernet_txtime_param_type
type;
368struct ethernet_config {
370 bool auto_negotiation;
380 struct net_eth_addr mac_address;
387 int priority_queues_num;
402#if defined(CONFIG_NET_STATISTICS_ETHERNET)
421 enum ethernet_config_type type,
422 const struct ethernet_config *config);
426 enum ethernet_config_type type,
427 struct ethernet_config *config);
429#if defined(CONFIG_NET_VLAN)
435 int (*vlan_setup)(
const struct device *dev,
struct net_if *iface,
439#if defined(CONFIG_PTP_CLOCK)
441 const struct device *(*get_ptp_clock)(
const struct device *dev);
451BUILD_ASSERT(offsetof(
struct ethernet_api, iface_api) == 0);
455 struct net_eth_addr dst;
456 struct net_eth_addr src;
460struct ethernet_vlan {
468#if defined(CONFIG_NET_VLAN_COUNT)
469#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
473#define NET_VLAN_MAX_COUNT 1
478#if defined(CONFIG_NET_LLDP)
479struct ethernet_lldp {
517#if defined(CONFIG_NET_VLAN)
518 struct ethernet_vlan vlan[NET_VLAN_MAX_COUNT];
528#if defined(CONFIG_NET_ETHERNET_BRIDGE)
543#if defined(CONFIG_NET_LLDP)
544 struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
552#if defined(CONFIG_NET_GPTP)
560#if defined(CONFIG_NET_DSA)
570 struct dsa_context *dsa_ctx;
576#if defined(CONFIG_NET_VLAN)
600#define ETHERNET_L2_CTX_TYPE struct ethernet_context
605struct net_eth_vlan_hdr {
606 struct net_eth_addr dst;
607 struct net_eth_addr src;
616static inline bool net_eth_is_addr_broadcast(
struct net_eth_addr *addr)
618 if (addr->addr[0] == 0xff &&
619 addr->addr[1] == 0xff &&
620 addr->addr[2] == 0xff &&
621 addr->addr[3] == 0xff &&
622 addr->addr[4] == 0xff &&
623 addr->addr[5] == 0xff) {
630static inline bool net_eth_is_addr_unspecified(
struct net_eth_addr *addr)
632 if (addr->addr[0] == 0x00 &&
633 addr->addr[1] == 0x00 &&
634 addr->addr[2] == 0x00 &&
635 addr->addr[3] == 0x00 &&
636 addr->addr[4] == 0x00 &&
637 addr->addr[5] == 0x00) {
644static inline bool net_eth_is_addr_multicast(
struct net_eth_addr *addr)
646#if defined(CONFIG_NET_IPV6)
647 if (addr->addr[0] == 0x33 &&
648 addr->addr[1] == 0x33) {
653#if defined(CONFIG_NET_IPV4)
654 if (addr->addr[0] == 0x01 &&
655 addr->addr[1] == 0x00 &&
656 addr->addr[2] == 0x5e) {
664static inline bool net_eth_is_addr_lldp_multicast(
struct net_eth_addr *addr)
666#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
667 if (addr->addr[0] == 0x01 &&
668 addr->addr[1] == 0x80 &&
669 addr->addr[2] == 0xc2 &&
670 addr->addr[3] == 0x00 &&
671 addr->addr[4] == 0x00 &&
672 addr->addr[5] == 0x0e) {
680const struct net_eth_addr *net_eth_broadcast_addr(
void);
691 struct net_eth_addr *mac_addr);
721#if defined(CONFIG_NET_VLAN)
738#if defined(CONFIG_NET_VLAN)
755#if defined(CONFIG_NET_VLAN)
774#if defined(CONFIG_NET_VLAN)
792#if defined(CONFIG_NET_VLAN)
810#if defined(CONFIG_NET_VLAN)
819#if defined(CONFIG_NET_VLAN)
820#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
821 pm_control_fn, data, cfg, prio, api, mtu) \
822 Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, \
823 pm_control_fn, data, cfg, POST_KERNEL, \
825 NET_L2_DATA_INIT(dev_name, 0, NET_L2_GET_CTX_TYPE(ETHERNET_L2));\
826 NET_IF_INIT(dev_name, 0, ETHERNET_L2, mtu, NET_VLAN_MAX_COUNT)
830#define Z_ETH_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
831 pm_control_fn, data, cfg, prio, api, mtu) \
832 Z_NET_DEVICE_INIT(node_id, dev_name, drv_name, init_fn, \
833 pm_control_fn, data, cfg, prio, api, \
834 ETHERNET_L2, NET_L2_GET_CTX_TYPE(ETHERNET_L2),\
857#define ETH_NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_control_fn, \
858 data, cfg, prio, api, mtu) \
859 Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_name, drv_name, \
860 init_fn, pm_control_fn, data, cfg, prio, \
881#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, \
882 cfg, prio, api, mtu) \
883 Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
884 DT_PROP_OR(node_id, label, ""), \
885 init_fn, pm_control_fn, data, cfg, prio, \
899#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
900 ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
937#if defined(CONFIG_PTP_CLOCK)
966#if defined(CONFIG_NET_GPTP)
983#if defined(CONFIG_NET_GPTP)
984void net_eth_set_ptp_port(
struct net_if *iface,
int port);
995#include <syscalls/ethernet.h>
int atomic_t
Definition: atomic.h:21
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:113
static int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
Add VLAN tag to the interface.
Definition: ethernet.h:724
static int net_eth_get_ptp_port(struct net_if *iface)
Return gPTP port number attached to this interface.
Definition: ethernet.h:969
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:940
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:758
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:813
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:109
ethernet_flags
Definition: ethernet.h:506
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:701
static int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
Remove VLAN tag from the interface.
Definition: ethernet.h:741
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:796
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:778
@ ETHERNET_HW_VLAN
Definition: ethernet.h:117
@ ETHERNET_PRIORITY_QUEUES
Definition: ethernet.h:144
@ ETHERNET_DUPLEX_SET
Definition: ethernet.h:132
@ ETHERNET_HW_VLAN_TAG_STRIP
Definition: ethernet.h:153
@ ETHERNET_LINK_10BASE_T
Definition: ethernet.h:123
@ ETHERNET_HW_FILTERING
Definition: ethernet.h:147
@ ETHERNET_PTP
Definition: ethernet.h:135
@ ETHERNET_QBU
Definition: ethernet.h:163
@ ETHERNET_LINK_100BASE_T
Definition: ethernet.h:126
@ ETHERNET_DSA_MASTER_PORT
Definition: ethernet.h:157
@ ETHERNET_DSA_SLAVE_PORT
Definition: ethernet.h:156
@ ETHERNET_QAV
Definition: ethernet.h:138
@ ETHERNET_HW_RX_CHKSUM_OFFLOAD
Definition: ethernet.h:114
@ ETHERNET_LINK_1000BASE_T
Definition: ethernet.h:129
@ ETHERNET_LLDP
Definition: ethernet.h:150
@ ETHERNET_AUTO_NEGOTIATION_SET
Definition: ethernet.h:120
@ ETHERNET_TXTIME
Definition: ethernet.h:166
@ ETHERNET_QBV
Definition: ethernet.h:160
@ ETHERNET_PROMISC_MODE
Definition: ethernet.h:141
@ ETHERNET_HW_TX_CHKSUM_OFFLOAD
Definition: ethernet.h:111
@ ETH_CARRIER_UP
Definition: ethernet.h:507
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:367
const void * api
Definition: device.h:373
Definition: ethernet_bridge.h:57
Definition: ethernet.h:395
struct net_if_api iface_api
Definition: ethernet.h:400
int(* start)(const struct device *dev)
Definition: ethernet.h:411
int(* get_config)(const struct device *dev, enum ethernet_config_type type, struct ethernet_config *config)
Definition: ethernet.h:425
int(* stop)(const struct device *dev)
Definition: ethernet.h:414
enum ethernet_hw_caps(* get_capabilities)(const struct device *dev)
Definition: ethernet.h:417
int(* send)(const struct device *dev, struct net_pkt *pkt)
Definition: ethernet.h:445
int(* set_config)(const struct device *dev, enum ethernet_config_type type, const struct ethernet_config *config)
Definition: ethernet.h:420
Definition: ethernet.h:511
struct net_if * iface
Definition: ethernet.h:541
bool is_net_carrier_up
Definition: ethernet.h:585
enum net_l2_flags ethernet_l2_flags
Definition: ethernet.h:550
struct k_work carrier_work
Definition: ethernet.h:538
atomic_t flags
Definition: ethernet.h:515
bool is_init
Definition: ethernet.h:588
Definition: ethernet.h:341
struct net_eth_addr mac_address
Definition: ethernet.h:345
bool set
Definition: ethernet.h:347
enum ethernet_filter_type type
Definition: ethernet.h:343
Definition: ethernet.h:196
bool enabled
Definition: ethernet.h:203
unsigned int oper_idle_slope
Definition: ethernet.h:209
enum ethernet_qav_param_type type
Definition: ethernet.h:200
unsigned int traffic_class
Definition: ethernet.h:211
int queue_id
Definition: ethernet.h:198
unsigned int idle_slope
Definition: ethernet.h:207
unsigned int delta_bandwidth
Definition: ethernet.h:205
Definition: ethernet.h:301
enum ethernet_qbu_preempt_status frame_preempt_statuses[NET_TC_TX_COUNT]
Definition: ethernet.h:315
uint32_t release_advance
Definition: ethernet.h:311
enum ethernet_qbu_param_type type
Definition: ethernet.h:305
uint32_t hold_advance
Definition: ethernet.h:308
bool enabled
Definition: ethernet.h:319
bool link_partner_status
Definition: ethernet.h:322
int port_id
Definition: ethernet.h:303
uint8_t additional_fragment_size
Definition: ethernet.h:327
Definition: ethernet.h:237
int port_id
Definition: ethernet.h:239
bool enabled
Definition: ethernet.h:246
enum ethernet_qbv_param_type type
Definition: ethernet.h:241
uint16_t row
Definition: ethernet.h:259
enum ethernet_qbv_state_type state
Definition: ethernet.h:243
bool gate_status[NET_TC_TX_COUNT]
Definition: ethernet.h:250
struct net_ptp_extended_time base_time
Definition: ethernet.h:270
uint32_t extension_time
Definition: ethernet.h:276
enum ethernet_gate_state_operation operation
Definition: ethernet.h:253
uint32_t time_interval
Definition: ethernet.h:256
struct ethernet_qbv_param::@140::@142 gate_control
struct net_ptp_time cycle_time
Definition: ethernet.h:273
uint32_t gate_control_list_len
Definition: ethernet.h:263
Definition: ethernet.h:358
bool enable_txtime
Definition: ethernet.h:364
int queue_id
Definition: ethernet.h:362
enum ethernet_txtime_param_type type
Definition: ethernet.h:360
A structure used to submit work.
Definition: kernel.h:3623
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