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:
- 10, 100 and 1000 Mbit/sec links
- Auto negotiation
- Half/full duplex
- Promiscuous mode
- TX and RX checksum offloading
- MAC address filtering
- Virtual LANs
- Priority queues
- IEEE 802.1AS (gPTP)
- IEEE 802.1Qav (credit based shaping)
- LLDP (Link Layer Discovery Protocol)
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, data, cfg_info, 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.data
: Pointer to the device’s configuration data.cfg_info
: 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:
-
ETHERNET_HW_TX_CHKSUM_OFFLOAD
= BIT(0)¶ TX Checksum offloading supported
-
ETHERNET_HW_RX_CHKSUM_OFFLOAD
= BIT(1)¶ RX Checksum offloading supported
-
ETHERNET_HW_VLAN
= BIT(2)¶ VLAN supported
-
ETHERNET_AUTO_NEGOTIATION_SET
= BIT(3)¶ Enabling/disabling auto negotiation supported
-
ETHERNET_LINK_10BASE_T
= BIT(4)¶ 10 Mbits link supported
-
ETHERNET_LINK_100BASE_T
= BIT(5)¶ 100 Mbits link supported
-
ETHERNET_LINK_1000BASE_T
= BIT(6)¶ 1 Gbits link supported
-
ETHERNET_DUPLEX_SET
= BIT(7)¶ Changing duplex (half/full) supported
-
ETHERNET_PTP
= BIT(8)¶ IEEE 802.1AS (gPTP) clock supported
-
ETHERNET_QAV
= BIT(9)¶ IEEE 802.1Qav (credit-based shaping) supported
-
ETHERNET_PROMISC_MODE
= BIT(10)¶ Promiscuous mode supported
-
ETHERNET_PRIORITY_QUEUES
= BIT(11)¶ Priority queues available
-
ETHERNET_HW_FILTERING
= BIT(12)¶ MAC address filtering supported
-
ETHERNET_LLDP
= BIT(13)¶ Link Layer Discovery Protocol supported
-
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 addressmac_addr
: Output buffer for Ethernet address
-
static 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
-
static int
net_eth_vlan_enable
(struct net_if *iface, u16_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
-
static int
net_eth_vlan_disable
(struct net_if *iface, u16_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
-
static u16_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.
-
static struct net_if *
net_eth_get_vlan_iface
(struct net_if *iface, u16_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 contexttag
: VLAN tag
-
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.
- Return
- True if VLAN is enabled for this network interface, false if not.
- Parameters
ctx
: Ethernet contextiface
: Network interface
-
static 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 interfaceenable
: on (true) or off (false)
-
struct
ethernet_context
¶ - #include <ethernet.h>
Ethernet L2 context that is needed for VLAN
-
-
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
-
MII_BMSR_LINK_STATUS
¶ 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
¶
-