Ethernet

Overview

Ethernet is a networking technology commonly used in local area networks (LAN). For more information, see this Ethernet Wikipedia article.

Zephyr supports following Ethernet features:

Not all Ethernet device drivers support all of these features. You can see what is supported by net iface net-shell command. It will print currently supported Ethernet features.

API Reference

group ethernet

Ethernet support functions.

Defines

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.

Parameters
  • dev_name: Network device name.

  • drv_name: The name this instance of the driver exposes to the system.

  • init_fn: Address to the init function of the driver.

  • pm_control_fn: Pointer to device_pm_control function. Can be empty function (device_pm_control_nop) if not implemented.

  • data: Pointer to the device’s private data.

  • cfg: The address to the structure containing the configuration information for this instance of the driver.

  • prio: The initialization level at which configuration occurs.

  • api: Provides an initial pointer to the API function struct used by the driver. Can be NULL.

  • mtu: Maximum transfer unit in bytes for this network interface.

Enums

enum ethernet_hw_caps

Ethernet hardware capabilities

Values:

enumerator ETHERNET_HW_TX_CHKSUM_OFFLOAD

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

enumerator ETHERNET_HW_RX_CHKSUM_OFFLOAD

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

enumerator ETHERNET_HW_VLAN

VLAN supported

enumerator ETHERNET_AUTO_NEGOTIATION_SET

Enabling/disabling auto negotiation supported

10 Mbits link supported

100 Mbits link supported

1 Gbits link supported

enumerator ETHERNET_DUPLEX_SET

Changing duplex (half/full) supported

enumerator ETHERNET_PTP

IEEE 802.1AS (gPTP) clock supported

enumerator ETHERNET_QAV

IEEE 802.1Qav (credit-based shaping) supported

enumerator ETHERNET_PROMISC_MODE

Promiscuous mode supported

enumerator ETHERNET_PRIORITY_QUEUES

Priority queues available

enumerator ETHERNET_HW_FILTERING

MAC address filtering supported

enumerator ETHERNET_LLDP

Link Layer Discovery Protocol supported

enumerator ETHERNET_HW_VLAN_TAG_STRIP

VLAN Tag stripping

Functions

void ethernet_init(struct net_if *iface)

Initialize Ethernet L2 stack for a given interface.

Parameters
  • iface: A valid pointer to a network interface

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.

Parameters
  • ipv6_addr: IPv6 multicast address

  • mac_addr: Output buffer for Ethernet address

enum ethernet_hw_caps net_eth_get_hw_capabilities(struct net_if *iface)

Return ethernet device hardware capability information.

Return

Hardware capabilities

Parameters
  • iface: Network interface

int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)

Add VLAN tag to the interface.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

  • tag: VLAN tag to add

int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)

Remove VLAN tag from the interface.

Return

0 if ok, <0 if error

Parameters
  • iface: Interface to use.

  • tag: VLAN tag to remove

uint16_t net_eth_get_vlan_tag(struct net_if *iface)

Return VLAN tag specified to network interface.

Return

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

Parameters
  • iface: Network interface.

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

Return network interface related to this VLAN tag.

Return

Network interface related to this tag or NULL if no such interface exists.

Parameters
  • iface: Master network interface. This is used to get the pointer to ethernet L2 context

  • tag: VLAN tag

bool net_eth_is_vlan_enabled(struct ethernet_context *ctx, struct net_if *iface)

Check if VLAN is enabled for a specific network interface.

Return

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

Parameters
  • ctx: Ethernet context

  • iface: Network interface

bool net_eth_get_vlan_status(struct net_if *iface)

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

Return

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

Parameters
  • iface: Network interface

void net_eth_carrier_on(struct net_if *iface)

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

Parameters
  • iface: Network interface

void net_eth_carrier_off(struct net_if *iface)

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

Parameters
  • iface: Network interface

int net_eth_promisc_mode(struct net_if *iface, bool enable)

Set promiscuous mode either ON or OFF.

Return

0 if mode set or unset was successful, <0 otherwise.

Parameters
  • iface: Network interface

  • enable: on (true) or off (false)

const struct device *net_eth_get_ptp_clock(struct net_if *iface)

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

Return

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

Parameters
  • iface: Network interface

const struct device *net_eth_get_ptp_clock_by_index(int index)

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

Return

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

Parameters
  • index: Network interface index

int net_eth_get_ptp_port(struct net_if *iface)

Return gPTP port number attached to this interface.

Return

Port number, no such port if < 0

Parameters
  • iface: Network interface

struct ethernet_qav_param
#include <ethernet.h>
struct ethernet_filter
#include <ethernet.h>
struct ethernet_api
#include <ethernet.h>
struct ethernet_context
#include <ethernet.h>

Ethernet L2 context that is needed for VLAN

struct carrier_mgmt
group ethernet_mii

Ethernet MII (media independent interface) functions.

Defines

MII_BMCR

Basic Mode Control Register

MII_BMSR

Basic Mode Status Register

MII_PHYID1R

PHY ID 1 Register

MII_PHYID2R

PHY ID 2 Register

MII_ANAR

Auto-Negotiation Advertisement Register

MII_ANLPAR

Auto-Negotiation Link Partner Ability Reg

MII_ANER

Auto-Negotiation Expansion Register

MII_ANNPTR

Auto-Negotiation Next Page Transmit Register

MII_ANLPRNPR

Auto-Negotiation Link Partner Received Next Page Reg

MII_MMD_ACR

MMD Access Control Register

MII_MMD_AADR

MMD Access Address Data Register

MII_ESTAT

Extended Status Register

MII_BMCR_RESET

PHY reset

MII_BMCR_LOOPBACK

enable loopback mode

MII_BMCR_SPEED_LSB

10=1000Mbps 01=100Mbps; 00=10Mbps

MII_BMCR_AUTONEG_ENABLE

Auto-Negotiation enable

MII_BMCR_POWER_DOWN

power down mode

MII_BMCR_ISOLATE

isolate electrically PHY from MII

MII_BMCR_AUTONEG_RESTART

restart auto-negotiation

MII_BMCR_DUPLEX_MODE

full duplex mode

MII_BMCR_SPEED_MSB

10=1000Mbps 01=100Mbps; 00=10Mbps

MII_BMCR_SPEED_MASK

Link Speed Field

MII_BMCR_SPEED_10

select speed 10 Mb/s

MII_BMCR_SPEED_100

select speed 100 Mb/s

MII_BMCR_SPEED_1000

select speed 1000 Mb/s

MII_BMSR_100BASE_T4

100BASE-T4 capable

MII_BMSR_100BASE_X_FULL

100BASE-X full duplex capable

MII_BMSR_100BASE_X_HALF

100BASE-X half duplex capable

MII_BMSR_10_FULL

10 Mb/s full duplex capable

MII_BMSR_10_HALF

10 Mb/s half duplex capable

MII_BMSR_100BASE_T2_FULL

100BASE-T2 full duplex capable

MII_BMSR_100BASE_T2_HALF

100BASE-T2 half duplex capable

MII_BMSR_EXTEND_STATUS

extend status information in reg 15

MII_BMSR_MF_PREAMB_SUPPR

PHY accepts management frames with preamble suppressed

MII_BMSR_AUTONEG_COMPLETE

Auto-negotiation process completed

MII_BMSR_REMOTE_FAULT

remote fault detected

MII_BMSR_AUTONEG_ABILITY

PHY is able to perform Auto-Negotiation

link is up

MII_BMSR_JABBER_DETECT

jabber condition detected

MII_BMSR_EXTEND_CAPAB

extended register capabilities

MII_ADVERTISE_NEXT_PAGE

next page

MII_ADVERTISE_LPACK

link partner acknowledge response

MII_ADVERTISE_REMOTE_FAULT

remote fault

MII_ADVERTISE_ASYM_PAUSE

try for asymmetric pause

MII_ADVERTISE_PAUSE

try for pause

MII_ADVERTISE_100BASE_T4

try for 100BASE-T4 support

MII_ADVERTISE_100_FULL

try for 100BASE-X full duplex support

MII_ADVERTISE_100_HALF

try for 100BASE-X support

MII_ADVERTISE_10_FULL

try for 10 Mb/s full duplex support

MII_ADVERTISE_10_HALF

try for 10 Mb/s half duplex support

MII_ADVERTISE_SEL_MASK

Selector Field

MII_ADVERTISE_SEL_IEEE_802_3
MII_ADVERTISE_ALL