Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Ethernet Support Functions

Ethernet support functions. More...

Modules

 Ethernet MII Support Functions
 Ethernet MII (media independent interface) functions.
 

Data Structures

struct  ethernet_qav_param
 
struct  ethernet_qbv_param
 
struct  ethernet_qbu_param
 
struct  ethernet_filter
 
struct  ethernet_txtime_param
 
struct  ethernet_api
 
struct  ethernet_context
 

Macros

#define ETH_NET_DEVICE_INIT(dev_name, drv_name, init_fn, pm_control_fn, data, cfg, prio, api, mtu)
 Create an Ethernet network interface and bind it to network device. More...
 
#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn, data, cfg, prio, api, mtu)
 Like ETH_NET_DEVICE_INIT but taking metadata from a devicetree. Create an Ethernet network interface and bind it to network device. More...
 
#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...)    ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
 Like ETH_NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible. More...
 

Enumerations

enum  ethernet_hw_caps {
  ETHERNET_HW_TX_CHKSUM_OFFLOAD = BIT(0) , ETHERNET_HW_RX_CHKSUM_OFFLOAD = BIT(1) , ETHERNET_HW_VLAN = BIT(2) , ETHERNET_AUTO_NEGOTIATION_SET = BIT(3) ,
  ETHERNET_LINK_10BASE_T = BIT(4) , ETHERNET_LINK_100BASE_T = BIT(5) , ETHERNET_LINK_1000BASE_T = BIT(6) , ETHERNET_DUPLEX_SET = BIT(7) ,
  ETHERNET_PTP = BIT(8) , ETHERNET_QAV = BIT(9) , ETHERNET_PROMISC_MODE = BIT(10) , ETHERNET_PRIORITY_QUEUES = BIT(11) ,
  ETHERNET_HW_FILTERING = BIT(12) , ETHERNET_LLDP = BIT(13) , ETHERNET_HW_VLAN_TAG_STRIP = BIT(14) , ETHERNET_DSA_SLAVE_PORT = BIT(15) ,
  ETHERNET_DSA_MASTER_PORT = BIT(16) , ETHERNET_QBV = BIT(17) , ETHERNET_QBU = BIT(18) , ETHERNET_TXTIME = BIT(19)
}
 
enum  ethernet_flags { ETH_CARRIER_UP }
 

Functions

void ethernet_init (struct net_if *iface)
 Initialize Ethernet L2 stack for a given interface. More...
 
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. More...
 
static enum ethernet_hw_caps net_eth_get_hw_capabilities (struct net_if *iface)
 Return ethernet device hardware capability information. More...
 
static int net_eth_vlan_enable (struct net_if *iface, uint16_t tag)
 Add VLAN tag to the interface. More...
 
static int net_eth_vlan_disable (struct net_if *iface, uint16_t tag)
 Remove VLAN tag from the interface. More...
 
static uint16_t net_eth_get_vlan_tag (struct net_if *iface)
 Return VLAN tag specified to network interface. More...
 
static struct net_ifnet_eth_get_vlan_iface (struct net_if *iface, uint16_t tag)
 Return network interface related to this VLAN tag. More...
 
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. More...
 
static bool net_eth_get_vlan_status (struct net_if *iface)
 Get VLAN status for a given network interface (enabled or not). More...
 
void net_eth_carrier_on (struct net_if *iface)
 Inform ethernet L2 driver that ethernet carrier is detected. This happens when cable is connected. More...
 
void net_eth_carrier_off (struct net_if *iface)
 Inform ethernet L2 driver that ethernet carrier was lost. This happens when cable is disconnected. More...
 
int net_eth_promisc_mode (struct net_if *iface, bool enable)
 Set promiscuous mode either ON or OFF. More...
 
static const struct devicenet_eth_get_ptp_clock (struct net_if *iface)
 Return PTP clock that is tied to this ethernet network interface. More...
 
const struct devicenet_eth_get_ptp_clock_by_index (int index)
 Return PTP clock that is tied to this ethernet network interface index. More...
 
static int net_eth_get_ptp_port (struct net_if *iface)
 Return gPTP port number attached to this interface. More...
 

Detailed Description

Ethernet support functions.

Macro Definition Documentation

◆ ETH_NET_DEVICE_DT_DEFINE

#define ETH_NET_DEVICE_DT_DEFINE (   node_id,
  init_fn,
  pm_control_fn,
  data,
  cfg,
  prio,
  api,
  mtu 
)

#include <include/net/ethernet.h>

Value:
Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_NAME(node_id), \
DT_PROP_OR(node_id, label, ""), \
init_fn, pm_control_fn, data, cfg, prio, \
api, mtu)
#define DT_PROP_OR(node_id, prop, default_value)
Like DT_PROP(), but with a fallback to default_value.
Definition: devicetree.h:640
static fdata_t data[2]
Definition: test_fifo_contexts.c:15

Like ETH_NET_DEVICE_INIT but taking metadata from a devicetree. Create an Ethernet network interface and bind it to network device.

Parameters
node_idThe devicetree node identifier.
init_fnAddress to the init function of the driver.
pm_control_fnPointer to pm_control function. Can be NULL if not implemented.
dataPointer to the device's private data.
cfgThe address to the structure containing the configuration information for this instance of the driver.
prioThe initialization level at which configuration occurs.
apiProvides an initial pointer to the API function struct used by the driver. Can be NULL.
mtuMaximum transfer unit in bytes for this network interface.

◆ ETH_NET_DEVICE_DT_INST_DEFINE

#define ETH_NET_DEVICE_DT_INST_DEFINE (   inst,
  ... 
)     ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)

#include <include/net/ethernet.h>

Like ETH_NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT compatible.

Parameters
instinstance number. This is replaced by DT_DRV_COMPAT(inst) in the call to ETH_NET_DEVICE_DT_DEFINE.
...other parameters as expected by ETH_NET_DEVICE_DT_DEFINE.

◆ ETH_NET_DEVICE_INIT

#define ETH_NET_DEVICE_INIT (   dev_name,
  drv_name,
  init_fn,
  pm_control_fn,
  data,
  cfg,
  prio,
  api,
  mtu 
)

#include <include/net/ethernet.h>

Value:
Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_name, drv_name, \
init_fn, pm_control_fn, data, cfg, prio, \
api, mtu)
#define DT_INVALID_NODE
Name for an invalid node identifier.
Definition: devicetree.h:76

Create an Ethernet network interface and bind it to network device.

Parameters
dev_nameNetwork device name.
drv_nameThe name this instance of the driver exposes to the system.
init_fnAddress to the init function of the driver.
pm_control_fnPointer to pm_control function. Can be NULL if not implemented.
dataPointer to the device's private data.
cfgThe address to the structure containing the configuration information for this instance of the driver.
prioThe initialization level at which configuration occurs.
apiProvides an initial pointer to the API function struct used by the driver. Can be NULL.
mtuMaximum transfer unit in bytes for this network interface.

Enumeration Type Documentation

◆ ethernet_flags

#include <include/net/ethernet.h>

Enumerator
ETH_CARRIER_UP 

◆ ethernet_hw_caps

#include <include/net/ethernet.h>

Ethernet hardware capabilities

Enumerator
ETHERNET_HW_TX_CHKSUM_OFFLOAD 

TX Checksum offloading supported for all of IPv4, UDP, TCP

ETHERNET_HW_RX_CHKSUM_OFFLOAD 

RX Checksum offloading supported for all of IPv4, UDP, TCP

ETHERNET_HW_VLAN 

VLAN supported

ETHERNET_AUTO_NEGOTIATION_SET 

Enabling/disabling auto negotiation supported

ETHERNET_LINK_10BASE_T 

10 Mbits link supported

ETHERNET_LINK_100BASE_T 

100 Mbits link supported

ETHERNET_LINK_1000BASE_T 

1 Gbits link supported

ETHERNET_DUPLEX_SET 

Changing duplex (half/full) supported

ETHERNET_PTP 

IEEE 802.1AS (gPTP) clock supported

ETHERNET_QAV 

IEEE 802.1Qav (credit-based shaping) supported

ETHERNET_PROMISC_MODE 

Promiscuous mode supported

ETHERNET_PRIORITY_QUEUES 

Priority queues available

ETHERNET_HW_FILTERING 

MAC address filtering supported

ETHERNET_LLDP 

Link Layer Discovery Protocol supported

ETHERNET_HW_VLAN_TAG_STRIP 

VLAN Tag stripping

ETHERNET_DSA_SLAVE_PORT 

DSA switch

ETHERNET_DSA_MASTER_PORT 
ETHERNET_QBV 

IEEE 802.1Qbv (scheduled traffic) supported

ETHERNET_QBU 

IEEE 802.1Qbu (frame preemption) supported

ETHERNET_TXTIME 

TXTIME supported

Function Documentation

◆ ethernet_init()

void ethernet_init ( struct net_if iface)

#include <include/net/ethernet.h>

Initialize Ethernet L2 stack for a given interface.

Parameters
ifaceA valid pointer to a network interface

◆ net_eth_carrier_off()

void net_eth_carrier_off ( struct net_if iface)

#include <include/net/ethernet.h>

Inform ethernet L2 driver that ethernet carrier was lost. This happens when cable is disconnected.

Parameters
ifaceNetwork interface

◆ net_eth_carrier_on()

void net_eth_carrier_on ( struct net_if iface)

#include <include/net/ethernet.h>

Inform ethernet L2 driver that ethernet carrier is detected. This happens when cable is connected.

Parameters
ifaceNetwork interface

◆ net_eth_get_hw_capabilities()

static enum ethernet_hw_caps net_eth_get_hw_capabilities ( struct net_if iface)
inlinestatic

#include <include/net/ethernet.h>

Return ethernet device hardware capability information.

Parameters
ifaceNetwork interface
Returns
Hardware capabilities

◆ net_eth_get_ptp_clock()

static const struct device * net_eth_get_ptp_clock ( struct net_if iface)
inlinestatic

#include <include/net/ethernet.h>

Return PTP clock that is tied to this ethernet network interface.

Parameters
ifaceNetwork interface
Returns
Pointer to PTP clock if found, NULL if not found or if this ethernet interface does not support PTP.

◆ net_eth_get_ptp_clock_by_index()

const struct device * net_eth_get_ptp_clock_by_index ( int  index)

#include <include/net/ethernet.h>

Return PTP clock that is tied to this ethernet network interface index.

Parameters
indexNetwork interface index
Returns
Pointer to PTP clock if found, NULL if not found or if this ethernet interface index does not support PTP.

◆ net_eth_get_ptp_port()

static int net_eth_get_ptp_port ( struct net_if iface)
inlinestatic

#include <include/net/ethernet.h>

Return gPTP port number attached to this interface.

Parameters
ifaceNetwork interface
Returns
Port number, no such port if < 0

◆ net_eth_get_vlan_iface()

static struct net_if * net_eth_get_vlan_iface ( struct net_if iface,
uint16_t  tag 
)
inlinestatic

#include <include/net/ethernet.h>

Return network interface related to this VLAN tag.

Parameters
ifaceMaster network interface. This is used to get the pointer to ethernet L2 context
tagVLAN tag
Returns
Network interface related to this tag or NULL if no such interface exists.

◆ net_eth_get_vlan_status()

static bool net_eth_get_vlan_status ( struct net_if iface)
inlinestatic

#include <include/net/ethernet.h>

Get VLAN status for a given network interface (enabled or not).

Parameters
ifaceNetwork interface
Returns
True if VLAN is enabled for this network interface, false if not.

◆ net_eth_get_vlan_tag()

static uint16_t net_eth_get_vlan_tag ( struct net_if iface)
inlinestatic

#include <include/net/ethernet.h>

Return VLAN tag specified to network interface.

Parameters
ifaceNetwork interface.
Returns
VLAN tag for this interface or NET_VLAN_TAG_UNSPEC if VLAN is not configured for that interface.

◆ net_eth_ipv6_mcast_to_mac_addr()

void net_eth_ipv6_mcast_to_mac_addr ( const struct in6_addr ipv6_addr,
struct net_eth_addr *  mac_addr 
)

#include <include/net/ethernet.h>

Convert IPv6 multicast address to Ethernet address.

Parameters
ipv6_addrIPv6 multicast address
mac_addrOutput buffer for Ethernet address

◆ net_eth_is_vlan_enabled()

static bool net_eth_is_vlan_enabled ( struct ethernet_context ctx,
struct net_if iface 
)
inlinestatic

#include <include/net/ethernet.h>

Check if VLAN is enabled for a specific network interface.

Parameters
ctxEthernet context
ifaceNetwork interface
Returns
True if VLAN is enabled for this network interface, false if not.

◆ net_eth_promisc_mode()

int net_eth_promisc_mode ( struct net_if iface,
bool  enable 
)

#include <include/net/ethernet.h>

Set promiscuous mode either ON or OFF.

Parameters
ifaceNetwork interface
enableon (true) or off (false)
Returns
0 if mode set or unset was successful, <0 otherwise.

◆ net_eth_vlan_disable()

static int net_eth_vlan_disable ( struct net_if iface,
uint16_t  tag 
)
inlinestatic

#include <include/net/ethernet.h>

Remove VLAN tag from the interface.

Parameters
ifaceInterface to use.
tagVLAN tag to remove
Returns
0 if ok, <0 if error

◆ net_eth_vlan_enable()

static int net_eth_vlan_enable ( struct net_if iface,
uint16_t  tag 
)
inlinestatic

#include <include/net/ethernet.h>

Add VLAN tag to the interface.

Parameters
ifaceInterface to use.
tagVLAN tag to add
Returns
0 if ok, <0 if error