2016-05-30 12:54:04 +02:00
|
|
|
/** @file
|
|
|
|
@brief Ethernet
|
|
|
|
|
|
|
|
This is not to be included by the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-05-30 12:54:04 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_NET_ETHERNET_H_
|
|
|
|
#define ZEPHYR_INCLUDE_NET_ETHERNET_H_
|
2016-05-30 12:54:04 +02:00
|
|
|
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/kernel.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
2016-06-07 12:35:13 +02:00
|
|
|
#include <stdbool.h>
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/sys/atomic.h>
|
2016-05-30 12:54:04 +02:00
|
|
|
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/net/net_ip.h>
|
|
|
|
#include <zephyr/net/net_pkt.h>
|
|
|
|
#include <zephyr/net/lldp.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
|
|
|
#include <zephyr/net/net_if.h>
|
|
|
|
#include <zephyr/net/ethernet_vlan.h>
|
|
|
|
#include <zephyr/net/ptp_time.h>
|
2016-05-30 12:54:04 +02:00
|
|
|
|
2020-04-13 10:23:43 +02:00
|
|
|
#if defined(CONFIG_NET_DSA)
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/net/dsa.h>
|
2020-04-13 10:23:43 +02:00
|
|
|
#endif
|
|
|
|
|
2021-06-26 00:54:17 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET_BRIDGE)
|
2022-05-06 10:30:42 +02:00
|
|
|
#include <zephyr/net/ethernet_bridge.h>
|
2021-06-26 00:54:17 +02:00
|
|
|
#endif
|
|
|
|
|
2017-07-24 15:23:14 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-07-20 15:29:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Ethernet support functions
|
|
|
|
* @defgroup ethernet Ethernet Support Functions
|
2017-11-17 17:43:53 +01:00
|
|
|
* @ingroup networking
|
2017-07-20 15:29:45 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
#define NET_ETH_ADDR_LEN 6U /**< Ethernet MAC address length */
|
2019-02-14 15:12:24 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet address */
|
2018-04-06 10:50:34 +02:00
|
|
|
struct net_eth_addr {
|
2024-05-18 08:37:25 +02:00
|
|
|
uint8_t addr[NET_ETH_ADDR_LEN]; /**< Buffer storing the address */
|
2018-04-06 10:50:34 +02:00
|
|
|
};
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2018-12-06 14:19:51 +01:00
|
|
|
#define NET_ETH_HDR(pkt) ((struct net_eth_hdr *)net_pkt_data(pkt))
|
2016-06-03 11:40:19 +02:00
|
|
|
|
2024-03-23 16:38:13 +01:00
|
|
|
#define NET_ETH_PTYPE_CAN 0x000C /* CAN: Controller Area Network */
|
|
|
|
#define NET_ETH_PTYPE_CANFD 0x000D /* CANFD: CAN flexible data rate*/
|
|
|
|
#define NET_ETH_PTYPE_HDLC 0x0019 /* HDLC frames (like in PPP) */
|
2016-12-02 14:47:29 +01:00
|
|
|
#define NET_ETH_PTYPE_ARP 0x0806
|
|
|
|
#define NET_ETH_PTYPE_IP 0x0800
|
2020-06-10 16:57:07 +02:00
|
|
|
#define NET_ETH_PTYPE_TSN 0x22f0 /* TSN (IEEE 1722) packet */
|
2016-12-02 14:47:29 +01:00
|
|
|
#define NET_ETH_PTYPE_IPV6 0x86dd
|
2018-01-19 11:24:33 +01:00
|
|
|
#define NET_ETH_PTYPE_VLAN 0x8100
|
2018-01-24 13:33:35 +01:00
|
|
|
#define NET_ETH_PTYPE_PTP 0x88f7
|
2017-04-06 02:17:12 +02:00
|
|
|
#define NET_ETH_PTYPE_LLDP 0x88cc
|
2018-11-09 09:19:49 +01:00
|
|
|
#define NET_ETH_PTYPE_ALL 0x0003 /* from linux/if_ether.h */
|
2021-12-08 08:01:15 +01:00
|
|
|
#define NET_ETH_PTYPE_ECAT 0x88a4
|
2022-08-07 22:31:58 +02:00
|
|
|
#define NET_ETH_PTYPE_EAPOL 0x888e
|
2022-08-27 09:06:32 +02:00
|
|
|
#define NET_ETH_PTYPE_IEEE802154 0x00F6 /* from linux/if_ether.h: IEEE802.15.4 frame */
|
2018-11-09 09:19:49 +01:00
|
|
|
|
|
|
|
#if !defined(ETH_P_ALL)
|
|
|
|
#define ETH_P_ALL NET_ETH_PTYPE_ALL
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_IP)
|
|
|
|
#define ETH_P_IP NET_ETH_PTYPE_IP
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_ARP)
|
|
|
|
#define ETH_P_ARP NET_ETH_PTYPE_ARP
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_IPV6)
|
|
|
|
#define ETH_P_IPV6 NET_ETH_PTYPE_IPV6
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_8021Q)
|
|
|
|
#define ETH_P_8021Q NET_ETH_PTYPE_VLAN
|
|
|
|
#endif
|
2020-06-10 16:57:07 +02:00
|
|
|
#if !defined(ETH_P_TSN)
|
|
|
|
#define ETH_P_TSN NET_ETH_PTYPE_TSN
|
|
|
|
#endif
|
2021-12-08 08:01:15 +01:00
|
|
|
#if !defined(ETH_P_ECAT)
|
|
|
|
#define ETH_P_ECAT NET_ETH_PTYPE_ECAT
|
|
|
|
#endif
|
2024-05-22 06:11:34 +02:00
|
|
|
#if !defined(ETH_P_EAPOL)
|
|
|
|
#define ETH_P_EAPOL NET_ETH_PTYPE_EAPOL
|
|
|
|
#endif
|
2022-08-27 09:06:32 +02:00
|
|
|
#if !defined(ETH_P_IEEE802154)
|
|
|
|
#define ETH_P_IEEE802154 NET_ETH_PTYPE_IEEE802154
|
|
|
|
#endif
|
2024-03-23 16:38:13 +01:00
|
|
|
#if !defined(ETH_P_CAN)
|
|
|
|
#define ETH_P_CAN NET_ETH_PTYPE_CAN
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_CANFD)
|
|
|
|
#define ETH_P_CANFD NET_ETH_PTYPE_CANFD
|
|
|
|
#endif
|
|
|
|
#if !defined(ETH_P_HDLC)
|
|
|
|
#define ETH_P_HDLC NET_ETH_PTYPE_HDLC
|
|
|
|
#endif
|
2016-12-02 14:47:29 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @endcond */
|
|
|
|
|
|
|
|
#define NET_ETH_MINIMAL_FRAME_SIZE 60 /**< Minimum Ethernet frame size */
|
|
|
|
#define NET_ETH_MTU 1500 /**< Ethernet MTU size */
|
|
|
|
|
|
|
|
/** @cond INTERNAL_HIDDEN */
|
2023-06-15 17:44:35 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_vlan_hdr))
|
|
|
|
#else
|
2020-04-13 10:23:43 +02:00
|
|
|
#define _NET_ETH_MAX_HDR_SIZE (sizeof(struct net_eth_hdr))
|
2023-06-15 17:44:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _NET_ETH_MAX_FRAME_SIZE (NET_ETH_MTU + _NET_ETH_MAX_HDR_SIZE)
|
2020-04-13 10:23:43 +02:00
|
|
|
/*
|
|
|
|
* Extend the max frame size for DSA (KSZ8794) by one byte (to 1519) to
|
|
|
|
* store tail tag.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_NET_DSA)
|
|
|
|
#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE + DSA_TAG_SIZE)
|
|
|
|
#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE + DSA_TAG_SIZE)
|
|
|
|
#else
|
|
|
|
#define NET_ETH_MAX_FRAME_SIZE (_NET_ETH_MAX_FRAME_SIZE)
|
|
|
|
#define NET_ETH_MAX_HDR_SIZE (_NET_ETH_MAX_HDR_SIZE)
|
|
|
|
#endif
|
2016-05-30 12:54:04 +02:00
|
|
|
|
2019-04-12 13:19:16 +02:00
|
|
|
#define NET_ETH_VLAN_HDR_SIZE 4
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @endcond */
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @brief Ethernet hardware capabilities */
|
2018-04-06 10:57:13 +02:00
|
|
|
enum ethernet_hw_caps {
|
2019-12-16 16:49:33 +01:00
|
|
|
/** TX Checksum offloading supported for all of IPv4, UDP, TCP */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_HW_TX_CHKSUM_OFFLOAD = BIT(0),
|
2018-03-14 09:55:19 +01:00
|
|
|
|
2019-12-16 16:49:33 +01:00
|
|
|
/** RX Checksum offloading supported for all of IPv4, UDP, TCP */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_HW_RX_CHKSUM_OFFLOAD = BIT(1),
|
2018-01-19 11:24:33 +01:00
|
|
|
|
|
|
|
/** VLAN supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_HW_VLAN = BIT(2),
|
2018-03-27 12:29:33 +02:00
|
|
|
|
|
|
|
/** Enabling/disabling auto negotiation supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_AUTO_NEGOTIATION_SET = BIT(3),
|
2018-03-27 12:29:33 +02:00
|
|
|
|
|
|
|
/** 10 Mbits link supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_LINK_10BASE_T = BIT(4),
|
2018-03-27 12:29:33 +02:00
|
|
|
|
|
|
|
/** 100 Mbits link supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_LINK_100BASE_T = BIT(5),
|
2018-03-27 12:29:33 +02:00
|
|
|
|
|
|
|
/** 1 Gbits link supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_LINK_1000BASE_T = BIT(6),
|
2018-03-27 12:29:33 +02:00
|
|
|
|
|
|
|
/** Changing duplex (half/full) supported */
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_DUPLEX_SET = BIT(7),
|
2018-01-24 14:22:55 +01:00
|
|
|
|
|
|
|
/** IEEE 802.1AS (gPTP) clock supported */
|
|
|
|
ETHERNET_PTP = BIT(8),
|
2018-05-16 15:46:17 +02:00
|
|
|
|
|
|
|
/** IEEE 802.1Qav (credit-based shaping) supported */
|
|
|
|
ETHERNET_QAV = BIT(9),
|
2018-07-20 15:44:58 +02:00
|
|
|
|
|
|
|
/** Promiscuous mode supported */
|
|
|
|
ETHERNET_PROMISC_MODE = BIT(10),
|
2018-07-27 12:58:56 +02:00
|
|
|
|
|
|
|
/** Priority queues available */
|
|
|
|
ETHERNET_PRIORITY_QUEUES = BIT(11),
|
2018-05-31 10:28:16 +02:00
|
|
|
|
|
|
|
/** MAC address filtering supported */
|
|
|
|
ETHERNET_HW_FILTERING = BIT(12),
|
2017-04-06 02:17:12 +02:00
|
|
|
|
|
|
|
/** Link Layer Discovery Protocol supported */
|
|
|
|
ETHERNET_LLDP = BIT(13),
|
2019-04-12 13:11:15 +02:00
|
|
|
|
|
|
|
/** VLAN Tag stripping */
|
|
|
|
ETHERNET_HW_VLAN_TAG_STRIP = BIT(14),
|
2020-04-13 10:23:43 +02:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** DSA switch slave port */
|
|
|
|
ETHERNET_DSA_SLAVE_PORT = BIT(15),
|
|
|
|
|
|
|
|
/** DSA switch master port */
|
2020-04-13 10:23:43 +02:00
|
|
|
ETHERNET_DSA_MASTER_PORT = BIT(16),
|
2018-09-10 14:58:24 +02:00
|
|
|
|
|
|
|
/** IEEE 802.1Qbv (scheduled traffic) supported */
|
|
|
|
ETHERNET_QBV = BIT(17),
|
2018-09-11 14:42:49 +02:00
|
|
|
|
|
|
|
/** IEEE 802.1Qbu (frame preemption) supported */
|
|
|
|
ETHERNET_QBU = BIT(18),
|
2020-04-20 19:42:11 +02:00
|
|
|
|
|
|
|
/** TXTIME supported */
|
|
|
|
ETHERNET_TXTIME = BIT(19),
|
2024-01-22 05:38:03 +01:00
|
|
|
|
|
|
|
/** TX-Injection supported */
|
|
|
|
ETHERNET_TXINJECTION_MODE = BIT(20),
|
2018-03-14 09:55:19 +01:00
|
|
|
};
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2018-04-06 10:50:34 +02:00
|
|
|
enum ethernet_config_type {
|
|
|
|
ETHERNET_CONFIG_TYPE_AUTO_NEG,
|
|
|
|
ETHERNET_CONFIG_TYPE_LINK,
|
|
|
|
ETHERNET_CONFIG_TYPE_DUPLEX,
|
|
|
|
ETHERNET_CONFIG_TYPE_MAC_ADDRESS,
|
2018-08-01 11:11:47 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_QAV_PARAM,
|
2018-09-10 14:58:24 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_QBV_PARAM,
|
2018-09-11 14:42:49 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_QBU_PARAM,
|
2020-04-20 19:42:11 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_TXTIME_PARAM,
|
2018-07-20 15:44:58 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_PROMISC_MODE,
|
2018-07-27 12:58:56 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM,
|
2018-05-31 10:28:16 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_FILTER,
|
2018-09-10 14:58:24 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_PORTS_NUM,
|
2023-11-14 16:28:11 +01:00
|
|
|
ETHERNET_CONFIG_TYPE_T1S_PARAM,
|
2024-01-22 05:38:03 +01:00
|
|
|
ETHERNET_CONFIG_TYPE_TXINJECTION_MODE,
|
2024-06-10 09:52:57 +02:00
|
|
|
ETHERNET_CONFIG_TYPE_RX_CHECKSUM_SUPPORT,
|
|
|
|
ETHERNET_CONFIG_TYPE_TX_CHECKSUM_SUPPORT
|
2018-05-16 15:46:17 +02:00
|
|
|
};
|
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_qav_param_type {
|
|
|
|
ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH,
|
|
|
|
ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE,
|
2018-08-01 12:04:30 +02:00
|
|
|
ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE,
|
|
|
|
ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS,
|
2018-08-01 11:11:47 +02:00
|
|
|
ETHERNET_QAV_PARAM_TYPE_STATUS,
|
|
|
|
};
|
|
|
|
|
2023-11-14 16:28:11 +01:00
|
|
|
enum ethernet_t1s_param_type {
|
|
|
|
ETHERNET_T1S_PARAM_TYPE_PLCA_CONFIG,
|
|
|
|
};
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @endcond */
|
2024-05-18 08:37:25 +02:00
|
|
|
|
|
|
|
/** Ethernet T1S specific parameters */
|
2023-11-14 16:28:11 +01:00
|
|
|
struct ethernet_t1s_param {
|
|
|
|
/** Type of T1S parameter */
|
|
|
|
enum ethernet_t1s_param_type type;
|
|
|
|
union {
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* PLCA is the Physical Layer (PHY) Collision
|
2023-11-14 16:28:11 +01:00
|
|
|
* Avoidance technique employed with multidrop
|
|
|
|
* 10Base-T1S standard.
|
|
|
|
*
|
|
|
|
* The PLCA parameters are described in standard [1]
|
|
|
|
* as registers in memory map 4 (MMS = 4) (point 9.6).
|
|
|
|
*
|
|
|
|
* IDVER (PLCA ID Version)
|
|
|
|
* CTRL0 (PLCA Control 0)
|
|
|
|
* CTRL1 (PLCA Control 1)
|
|
|
|
* STATUS (PLCA Status)
|
|
|
|
* TOTMR (PLCA TO Control)
|
|
|
|
* BURST (PLCA Burst Control)
|
|
|
|
*
|
|
|
|
* Those registers are implemented by each OA TC6
|
|
|
|
* compliant vendor (like for e.g. LAN865x - e.g. [2]).
|
|
|
|
*
|
|
|
|
* Documents:
|
|
|
|
* [1] - "OPEN Alliance 10BASE-T1x MAC-PHY Serial
|
|
|
|
* Interface" (ver. 1.1)
|
|
|
|
* [2] - "DS60001734C" - LAN865x data sheet
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
/** T1S PLCA enabled */
|
|
|
|
bool enable;
|
|
|
|
/** T1S PLCA node id range: 0 to 254 */
|
|
|
|
uint8_t node_id;
|
|
|
|
/** T1S PLCA node count range: 1 to 255 */
|
|
|
|
uint8_t node_count;
|
|
|
|
/** T1S PLCA burst count range: 0x0 to 0xFF */
|
|
|
|
uint8_t burst_count;
|
|
|
|
/** T1S PLCA burst timer */
|
|
|
|
uint8_t burst_timer;
|
|
|
|
/** T1S PLCA TO value */
|
|
|
|
uint8_t to_timer;
|
|
|
|
} plca;
|
|
|
|
};
|
|
|
|
};
|
2019-02-14 15:12:24 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet Qav specific parameters */
|
2018-08-01 11:11:47 +02:00
|
|
|
struct ethernet_qav_param {
|
|
|
|
/** ID of the priority queue to use */
|
2018-05-16 15:46:17 +02:00
|
|
|
int queue_id;
|
2018-08-01 11:11:47 +02:00
|
|
|
/** Type of Qav parameter */
|
|
|
|
enum ethernet_qav_param_type type;
|
2018-05-16 15:46:17 +02:00
|
|
|
union {
|
2018-08-01 11:11:47 +02:00
|
|
|
/** True if Qav is enabled for queue */
|
2018-07-30 15:51:01 +02:00
|
|
|
bool enabled;
|
2018-08-01 11:11:47 +02:00
|
|
|
/** Delta Bandwidth (percentage of bandwidth) */
|
2018-05-16 15:46:17 +02:00
|
|
|
unsigned int delta_bandwidth;
|
2018-08-01 11:11:47 +02:00
|
|
|
/** Idle Slope (bits per second) */
|
2018-05-16 15:46:17 +02:00
|
|
|
unsigned int idle_slope;
|
2018-08-01 12:04:30 +02:00
|
|
|
/** Oper Idle Slope (bits per second) */
|
|
|
|
unsigned int oper_idle_slope;
|
|
|
|
/** Traffic class the queue is bound to */
|
|
|
|
unsigned int traffic_class;
|
2018-05-16 15:46:17 +02:00
|
|
|
};
|
2018-04-06 10:50:34 +02:00
|
|
|
};
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2018-09-10 14:58:24 +02:00
|
|
|
enum ethernet_qbv_param_type {
|
|
|
|
ETHERNET_QBV_PARAM_TYPE_STATUS,
|
|
|
|
ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST,
|
|
|
|
ETHERNET_QBV_PARAM_TYPE_GATE_CONTROL_LIST_LEN,
|
|
|
|
ETHERNET_QBV_PARAM_TYPE_TIME,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ethernet_qbv_state_type {
|
|
|
|
ETHERNET_QBV_STATE_TYPE_ADMIN,
|
|
|
|
ETHERNET_QBV_STATE_TYPE_OPER,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ethernet_gate_state_operation {
|
|
|
|
ETHERNET_SET_GATE_STATE,
|
2018-09-11 14:42:49 +02:00
|
|
|
ETHERNET_SET_AND_HOLD_MAC_STATE,
|
|
|
|
ETHERNET_SET_AND_RELEASE_MAC_STATE,
|
2018-09-10 14:58:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @endcond */
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet Qbv specific parameters */
|
2018-09-10 14:58:24 +02:00
|
|
|
struct ethernet_qbv_param {
|
|
|
|
/** Port id */
|
|
|
|
int port_id;
|
|
|
|
/** Type of Qbv parameter */
|
|
|
|
enum ethernet_qbv_param_type type;
|
|
|
|
/** What state (Admin/Oper) parameters are these */
|
|
|
|
enum ethernet_qbv_state_type state;
|
|
|
|
union {
|
|
|
|
/** True if Qbv is enabled or not */
|
|
|
|
bool enabled;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Gate control information */
|
2018-09-10 14:58:24 +02:00
|
|
|
struct {
|
|
|
|
/** True = open, False = closed */
|
|
|
|
bool gate_status[NET_TC_TX_COUNT];
|
|
|
|
|
|
|
|
/** GateState operation */
|
|
|
|
enum ethernet_gate_state_operation operation;
|
|
|
|
|
|
|
|
/** Time interval ticks (nanoseconds) */
|
|
|
|
uint32_t time_interval;
|
|
|
|
|
|
|
|
/** Gate control list row */
|
|
|
|
uint16_t row;
|
|
|
|
} gate_control;
|
|
|
|
|
|
|
|
/** Number of entries in gate control list */
|
|
|
|
uint32_t gate_control_list_len;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* The time values are set in one go when type is set to
|
2018-09-10 14:58:24 +02:00
|
|
|
* ETHERNET_QBV_PARAM_TYPE_TIME
|
|
|
|
*/
|
|
|
|
struct {
|
|
|
|
/** Base time */
|
|
|
|
struct net_ptp_extended_time base_time;
|
|
|
|
|
|
|
|
/** Cycle time */
|
|
|
|
struct net_ptp_time cycle_time;
|
|
|
|
|
|
|
|
/** Extension time (nanoseconds) */
|
|
|
|
uint32_t extension_time;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-11 14:42:49 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
|
|
|
enum ethernet_qbu_param_type {
|
|
|
|
ETHERNET_QBU_PARAM_TYPE_STATUS,
|
|
|
|
ETHERNET_QBU_PARAM_TYPE_RELEASE_ADVANCE,
|
|
|
|
ETHERNET_QBU_PARAM_TYPE_HOLD_ADVANCE,
|
|
|
|
ETHERNET_QBU_PARAM_TYPE_PREEMPTION_STATUS_TABLE,
|
|
|
|
|
|
|
|
/* Some preemption settings are from Qbr spec. */
|
|
|
|
ETHERNET_QBR_PARAM_TYPE_LINK_PARTNER_STATUS,
|
|
|
|
ETHERNET_QBR_PARAM_TYPE_ADDITIONAL_FRAGMENT_SIZE,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ethernet_qbu_preempt_status {
|
|
|
|
ETHERNET_QBU_STATUS_EXPRESS,
|
|
|
|
ETHERNET_QBU_STATUS_PREEMPTABLE
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/** @endcond */
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet Qbu specific parameters */
|
2018-09-11 14:42:49 +02:00
|
|
|
struct ethernet_qbu_param {
|
|
|
|
/** Port id */
|
|
|
|
int port_id;
|
|
|
|
/** Type of Qbu parameter */
|
|
|
|
enum ethernet_qbu_param_type type;
|
|
|
|
union {
|
|
|
|
/** Hold advance (nanoseconds) */
|
|
|
|
uint32_t hold_advance;
|
|
|
|
|
|
|
|
/** Release advance (nanoseconds) */
|
|
|
|
uint32_t release_advance;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** sequence of framePreemptionAdminStatus values */
|
2018-09-11 14:42:49 +02:00
|
|
|
enum ethernet_qbu_preempt_status
|
|
|
|
frame_preempt_statuses[NET_TC_TX_COUNT];
|
|
|
|
|
|
|
|
/** True if Qbu is enabled or not */
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
/** Link partner status (from Qbr) */
|
|
|
|
bool link_partner_status;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* Additional fragment size (from Qbr). The minimum non-final
|
2018-09-11 14:42:49 +02:00
|
|
|
* fragment size is (additional_fragment_size + 1) * 64 octets
|
|
|
|
*/
|
|
|
|
uint8_t additional_fragment_size : 2;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-10 14:58:24 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2018-05-31 10:28:16 +02:00
|
|
|
enum ethernet_filter_type {
|
|
|
|
ETHERNET_FILTER_TYPE_SRC_MAC_ADDRESS,
|
|
|
|
ETHERNET_FILTER_TYPE_DST_MAC_ADDRESS,
|
|
|
|
};
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @endcond */
|
|
|
|
|
2023-06-05 22:24:20 +02:00
|
|
|
/** Types of Ethernet L2 */
|
|
|
|
enum ethernet_if_types {
|
|
|
|
/** IEEE 802.3 Ethernet (default) */
|
|
|
|
L2_ETH_IF_TYPE_ETHERNET,
|
|
|
|
|
|
|
|
/** IEEE 802.11 Wi-Fi*/
|
|
|
|
L2_ETH_IF_TYPE_WIFI,
|
|
|
|
} __packed;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet filter description */
|
2018-05-31 10:28:16 +02:00
|
|
|
struct ethernet_filter {
|
|
|
|
/** Type of filter */
|
|
|
|
enum ethernet_filter_type type;
|
|
|
|
/** MAC address to filter */
|
|
|
|
struct net_eth_addr mac_address;
|
|
|
|
/** Set (true) or unset (false) the filter */
|
|
|
|
bool set;
|
|
|
|
};
|
|
|
|
|
2020-04-20 19:42:11 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
|
|
|
enum ethernet_txtime_param_type {
|
|
|
|
ETHERNET_TXTIME_PARAM_TYPE_ENABLE_QUEUES,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @endcond */
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet TXTIME specific parameters */
|
2020-04-20 19:42:11 +02:00
|
|
|
struct ethernet_txtime_param {
|
|
|
|
/** Type of TXTIME parameter */
|
|
|
|
enum ethernet_txtime_param_type type;
|
|
|
|
/** Queue number for configuring TXTIME */
|
|
|
|
int queue_id;
|
|
|
|
/** Enable or disable TXTIME per queue */
|
|
|
|
bool enable_txtime;
|
|
|
|
};
|
|
|
|
|
2024-06-10 09:52:57 +02:00
|
|
|
/** Protocols that are supported by checksum offloading */
|
|
|
|
enum ethernet_checksum_support {
|
|
|
|
/** Device does not support any L3/L4 checksum offloading */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_NONE = NET_IF_CHECKSUM_NONE_BIT,
|
|
|
|
/** Device supports checksum offloading for the IPv4 header */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_IPV4_HEADER = NET_IF_CHECKSUM_IPV4_HEADER_BIT,
|
|
|
|
/** Device supports checksum offloading for ICMPv4 payload (implies IPv4 header) */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_IPV4_ICMP = NET_IF_CHECKSUM_IPV4_ICMP_BIT,
|
|
|
|
/** Device supports checksum offloading for the IPv6 header */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_IPV6_HEADER = NET_IF_CHECKSUM_IPV6_HEADER_BIT,
|
|
|
|
/** Device supports checksum offloading for ICMPv6 payload (implies IPv6 header) */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_IPV6_ICMP = NET_IF_CHECKSUM_IPV6_ICMP_BIT,
|
|
|
|
/** Device supports TCP checksum offloading for all supported IP protocols */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_TCP = NET_IF_CHECKSUM_TCP_BIT,
|
|
|
|
/** Device supports UDP checksum offloading for all supported IP protocols */
|
|
|
|
ETHERNET_CHECKSUM_SUPPORT_UDP = NET_IF_CHECKSUM_UDP_BIT,
|
|
|
|
};
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
2024-05-18 08:37:25 +02:00
|
|
|
|
2018-04-06 10:50:34 +02:00
|
|
|
struct ethernet_config {
|
|
|
|
union {
|
|
|
|
bool auto_negotiation;
|
|
|
|
bool full_duplex;
|
2018-07-20 15:44:58 +02:00
|
|
|
bool promisc_mode;
|
2024-01-22 05:38:03 +01:00
|
|
|
bool txinjection_mode;
|
2018-04-06 10:50:34 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
bool link_10bt;
|
|
|
|
bool link_100bt;
|
|
|
|
bool link_1000bt;
|
|
|
|
} l;
|
|
|
|
|
|
|
|
struct net_eth_addr mac_address;
|
2018-05-16 15:46:17 +02:00
|
|
|
|
2023-11-14 16:28:11 +01:00
|
|
|
struct ethernet_t1s_param t1s_param;
|
2018-08-01 11:11:47 +02:00
|
|
|
struct ethernet_qav_param qav_param;
|
2018-09-10 14:58:24 +02:00
|
|
|
struct ethernet_qbv_param qbv_param;
|
2018-09-11 14:42:49 +02:00
|
|
|
struct ethernet_qbu_param qbu_param;
|
2020-04-20 19:42:11 +02:00
|
|
|
struct ethernet_txtime_param txtime_param;
|
2018-07-27 12:58:56 +02:00
|
|
|
|
|
|
|
int priority_queues_num;
|
2018-09-10 14:58:24 +02:00
|
|
|
int ports_num;
|
2018-05-31 10:28:16 +02:00
|
|
|
|
2024-06-10 09:52:57 +02:00
|
|
|
enum ethernet_checksum_support chksum_support;
|
|
|
|
|
2018-05-31 10:28:16 +02:00
|
|
|
struct ethernet_filter filter;
|
2018-04-06 10:50:34 +02:00
|
|
|
};
|
|
|
|
};
|
2024-05-18 08:37:25 +02:00
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @endcond */
|
2018-04-06 10:50:34 +02:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet L2 API operations. */
|
2018-03-14 09:55:19 +01:00
|
|
|
struct ethernet_api {
|
|
|
|
/**
|
|
|
|
* The net_if_api must be placed in first position in this
|
|
|
|
* struct so that we are compatible with network interface API.
|
|
|
|
*/
|
|
|
|
struct net_if_api iface_api;
|
|
|
|
|
2018-03-28 15:59:45 +02:00
|
|
|
/** Collect optional ethernet specific statistics. This pointer
|
|
|
|
* should be set by driver if statistics needs to be collected
|
|
|
|
* for that driver.
|
|
|
|
*/
|
2024-05-18 08:37:25 +02:00
|
|
|
#if defined(CONFIG_NET_STATISTICS_ETHERNET)
|
2020-04-30 20:33:38 +02:00
|
|
|
struct net_stats_eth *(*get_stats)(const struct device *dev);
|
2018-03-28 15:59:45 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-09 15:08:27 +02:00
|
|
|
/** Start the device */
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*start)(const struct device *dev);
|
2018-08-09 15:08:27 +02:00
|
|
|
|
|
|
|
/** Stop the device */
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*stop)(const struct device *dev);
|
2018-08-09 15:08:27 +02:00
|
|
|
|
2018-03-14 09:55:19 +01:00
|
|
|
/** Get the device capabilities */
|
2020-04-30 20:33:38 +02:00
|
|
|
enum ethernet_hw_caps (*get_capabilities)(const struct device *dev);
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2018-04-06 10:50:34 +02:00
|
|
|
/** Set specific hardware configuration */
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*set_config)(const struct device *dev,
|
2018-04-06 10:50:34 +02:00
|
|
|
enum ethernet_config_type type,
|
|
|
|
const struct ethernet_config *config);
|
|
|
|
|
2018-07-27 12:34:21 +02:00
|
|
|
/** Get hardware specific configuration */
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*get_config)(const struct device *dev,
|
2018-07-27 12:34:21 +02:00
|
|
|
enum ethernet_config_type type,
|
|
|
|
struct ethernet_config *config);
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
/** The IP stack will call this function when a VLAN tag is enabled
|
|
|
|
* or disabled. If enable is set to true, then the VLAN tag was added,
|
|
|
|
* if it is false then the tag was removed. The driver can utilize
|
|
|
|
* this information if needed.
|
|
|
|
*/
|
2024-05-18 08:37:25 +02:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*vlan_setup)(const struct device *dev, struct net_if *iface,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t tag, bool enable);
|
2018-04-05 17:01:06 +02:00
|
|
|
#endif /* CONFIG_NET_VLAN */
|
2018-01-24 14:22:55 +01:00
|
|
|
|
|
|
|
/** Return ptp_clock device that is tied to this ethernet device */
|
2024-05-18 08:37:25 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK)
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *(*get_ptp_clock)(const struct device *dev);
|
2018-01-24 14:22:55 +01:00
|
|
|
#endif /* CONFIG_PTP_CLOCK */
|
2018-06-25 10:22:54 +02:00
|
|
|
|
|
|
|
/** Send a network packet */
|
2020-04-30 20:33:38 +02:00
|
|
|
int (*send)(const struct device *dev, struct net_pkt *pkt);
|
2018-03-27 21:05:40 +02:00
|
|
|
};
|
2018-03-14 09:55:19 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2019-11-26 10:04:32 +01:00
|
|
|
/* Make sure that the network interface API is properly setup inside
|
|
|
|
* Ethernet API struct (it is the first one).
|
|
|
|
*/
|
|
|
|
BUILD_ASSERT(offsetof(struct ethernet_api, iface_api) == 0);
|
|
|
|
|
2016-05-30 12:54:04 +02:00
|
|
|
struct net_eth_hdr {
|
|
|
|
struct net_eth_addr dst;
|
|
|
|
struct net_eth_addr src;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t type;
|
2016-05-30 12:54:04 +02:00
|
|
|
} __packed;
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
struct ethernet_vlan {
|
|
|
|
/** Network interface that has VLAN enabled */
|
|
|
|
struct net_if *iface;
|
|
|
|
|
|
|
|
/** VLAN tag */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t tag;
|
2018-01-19 11:24:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_VLAN_COUNT)
|
|
|
|
#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
|
|
|
|
#else
|
|
|
|
/* Even thou there are no VLAN support, the minimum count must be set to 1.
|
|
|
|
*/
|
|
|
|
#define NET_VLAN_MAX_COUNT 1
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
/** @endcond */
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** Ethernet LLDP specific parameters */
|
2017-04-06 02:17:12 +02:00
|
|
|
struct ethernet_lldp {
|
|
|
|
/** Used for track timers */
|
|
|
|
sys_snode_t node;
|
|
|
|
|
2018-08-24 11:07:26 +02:00
|
|
|
/** LLDP Data Unit mandatory TLVs for the interface. */
|
2017-04-06 02:17:12 +02:00
|
|
|
const struct net_lldpdu *lldpdu;
|
|
|
|
|
2018-08-24 11:07:26 +02:00
|
|
|
/** LLDP Data Unit optional TLVs for the interface */
|
2020-05-27 18:26:57 +02:00
|
|
|
const uint8_t *optional_du;
|
2018-08-24 11:07:26 +02:00
|
|
|
|
|
|
|
/** Length of the optional Data Unit TLVs */
|
|
|
|
size_t optional_len;
|
|
|
|
|
2017-04-06 02:17:12 +02:00
|
|
|
/** Network interface that has LLDP supported. */
|
|
|
|
struct net_if *iface;
|
|
|
|
|
|
|
|
/** LLDP TX timer start time */
|
2020-05-27 18:26:57 +02:00
|
|
|
int64_t tx_timer_start;
|
2017-04-06 02:17:12 +02:00
|
|
|
|
|
|
|
/** LLDP TX timeout */
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t tx_timer_timeout;
|
2018-08-20 10:40:53 +02:00
|
|
|
|
|
|
|
/** LLDP RX callback function */
|
|
|
|
net_lldp_recv_cb_t cb;
|
2017-04-06 02:17:12 +02:00
|
|
|
};
|
2024-05-18 08:37:25 +02:00
|
|
|
|
|
|
|
/** @cond INTERNAL_HIDDEN */
|
2017-04-06 02:17:12 +02:00
|
|
|
|
2021-03-16 17:18:54 +01:00
|
|
|
enum ethernet_flags {
|
|
|
|
ETH_CARRIER_UP,
|
|
|
|
};
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
/** Ethernet L2 context that is needed for VLAN */
|
|
|
|
struct ethernet_context {
|
2021-03-16 17:18:54 +01:00
|
|
|
/** Flags representing ethernet state, which are accessed from multiple
|
|
|
|
* threads.
|
|
|
|
*/
|
|
|
|
atomic_t flags;
|
|
|
|
|
2021-06-26 00:54:17 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET_BRIDGE)
|
|
|
|
struct eth_bridge_iface_context bridge;
|
|
|
|
#endif
|
|
|
|
|
2021-03-16 17:18:54 +01:00
|
|
|
/** Carrier ON/OFF handler worker. This is used to create
|
|
|
|
* network interface UP/DOWN event when ethernet L2 driver
|
|
|
|
* notices carrier ON/OFF situation. We must not create another
|
|
|
|
* network management event from inside management handler thus
|
|
|
|
* we use worker thread to trigger the UP/DOWN event.
|
|
|
|
*/
|
|
|
|
struct k_work carrier_work;
|
|
|
|
|
|
|
|
/** Network interface. */
|
|
|
|
struct net_if *iface;
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2017-04-06 02:17:12 +02:00
|
|
|
#if defined(CONFIG_NET_LLDP)
|
|
|
|
struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
|
|
|
|
#endif
|
|
|
|
|
2018-08-06 15:59:33 +02:00
|
|
|
/**
|
|
|
|
* This tells what L2 features does ethernet support.
|
|
|
|
*/
|
|
|
|
enum net_l2_flags ethernet_l2_flags;
|
|
|
|
|
2021-09-09 05:28:27 +02:00
|
|
|
#if defined(CONFIG_NET_L2_PTP)
|
|
|
|
/** The PTP port number for this network device. We need to store the
|
2018-01-24 13:33:35 +01:00
|
|
|
* port number here so that we do not need to fetch it for every
|
2021-09-09 05:28:27 +02:00
|
|
|
* incoming PTP packet.
|
2018-01-24 13:33:35 +01:00
|
|
|
*/
|
|
|
|
int port;
|
|
|
|
#endif
|
|
|
|
|
2020-04-13 10:23:43 +02:00
|
|
|
#if defined(CONFIG_NET_DSA)
|
|
|
|
/** DSA RX callback function - for custom processing - like e.g.
|
|
|
|
* redirecting packets when MAC address is caught
|
|
|
|
*/
|
|
|
|
dsa_net_recv_cb_t dsa_recv_cb;
|
|
|
|
|
|
|
|
/** Switch physical port number */
|
|
|
|
uint8_t dsa_port_idx;
|
|
|
|
|
|
|
|
/** DSA context pointer */
|
|
|
|
struct dsa_context *dsa_ctx;
|
|
|
|
|
|
|
|
/** Send a network packet via DSA master port */
|
|
|
|
dsa_send_t dsa_send;
|
|
|
|
#endif
|
|
|
|
|
2021-03-16 17:18:54 +01:00
|
|
|
/** Is network carrier up */
|
|
|
|
bool is_net_carrier_up : 1;
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
/** Is this context already initialized */
|
2021-03-16 17:18:54 +01:00
|
|
|
bool is_init : 1;
|
2023-06-05 22:24:20 +02:00
|
|
|
|
|
|
|
/** Types of Ethernet network interfaces */
|
|
|
|
enum ethernet_if_types eth_if_type;
|
2018-01-19 11:24:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initialize Ethernet L2 stack for a given interface
|
|
|
|
*
|
|
|
|
* @param iface A valid pointer to a network interface
|
|
|
|
*/
|
|
|
|
void ethernet_init(struct net_if *iface);
|
|
|
|
|
2019-02-14 15:12:24 +01:00
|
|
|
#define ETHERNET_L2_CTX_TYPE struct ethernet_context
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
/* Separate header for VLAN as some of device interfaces might not
|
|
|
|
* support VLAN.
|
|
|
|
*/
|
|
|
|
struct net_eth_vlan_hdr {
|
|
|
|
struct net_eth_addr dst;
|
|
|
|
struct net_eth_addr src;
|
|
|
|
struct {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t tpid; /* tag protocol id */
|
|
|
|
uint16_t tci; /* tag control info */
|
2018-01-19 11:24:33 +01:00
|
|
|
} vlan;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t type;
|
2018-01-19 11:24:33 +01:00
|
|
|
} __packed;
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @endcond */
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a broadcast address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is a broadcast address, false if not
|
|
|
|
*/
|
2016-06-07 12:35:13 +02:00
|
|
|
static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
if (addr->addr[0] == 0xff &&
|
|
|
|
addr->addr[1] == 0xff &&
|
|
|
|
addr->addr[2] == 0xff &&
|
|
|
|
addr->addr[3] == 0xff &&
|
|
|
|
addr->addr[4] == 0xff &&
|
|
|
|
addr->addr[5] == 0xff) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-24 16:52:22 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a all zeroes address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to an Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is an all zeroes address, false if not
|
|
|
|
*/
|
|
|
|
static inline bool net_eth_is_addr_all_zeroes(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
if (addr->addr[0] == 0x00 &&
|
|
|
|
addr->addr[1] == 0x00 &&
|
|
|
|
addr->addr[2] == 0x00 &&
|
|
|
|
addr->addr[3] == 0x00 &&
|
|
|
|
addr->addr[4] == 0x00 &&
|
|
|
|
addr->addr[5] == 0x00) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is unspecified.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is unspecified, false if not
|
|
|
|
*/
|
2019-02-26 15:51:04 +01:00
|
|
|
static inline bool net_eth_is_addr_unspecified(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
if (addr->addr[0] == 0x00 &&
|
|
|
|
addr->addr[1] == 0x00 &&
|
|
|
|
addr->addr[2] == 0x00 &&
|
|
|
|
addr->addr[3] == 0x00 &&
|
|
|
|
addr->addr[4] == 0x00 &&
|
|
|
|
addr->addr[5] == 0x00) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a multicast address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is a multicast address, false if not
|
|
|
|
*/
|
2016-06-07 12:35:13 +02:00
|
|
|
static inline bool net_eth_is_addr_multicast(struct net_eth_addr *addr)
|
|
|
|
{
|
2017-09-28 21:28:27 +02:00
|
|
|
#if defined(CONFIG_NET_IPV6)
|
2016-06-07 12:35:13 +02:00
|
|
|
if (addr->addr[0] == 0x33 &&
|
|
|
|
addr->addr[1] == 0x33) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-28 21:28:27 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IPV4)
|
|
|
|
if (addr->addr[0] == 0x01 &&
|
|
|
|
addr->addr[1] == 0x00 &&
|
|
|
|
addr->addr[2] == 0x5e) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2016-06-07 12:35:13 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a group address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is a group address, false if not
|
|
|
|
*/
|
2023-01-11 12:19:18 +01:00
|
|
|
static inline bool net_eth_is_addr_group(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
return addr->addr[0] & 0x01;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is valid.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is valid, false if not
|
|
|
|
*/
|
2023-01-11 12:19:18 +01:00
|
|
|
static inline bool net_eth_is_addr_valid(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
return !net_eth_is_addr_unspecified(addr) && !net_eth_is_addr_group(addr);
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a LLDP multicast address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is a LLDP multicast address, false if not
|
|
|
|
*/
|
2018-01-24 13:33:35 +01:00
|
|
|
static inline bool net_eth_is_addr_lldp_multicast(struct net_eth_addr *addr)
|
|
|
|
{
|
2017-04-06 02:17:12 +02:00
|
|
|
#if defined(CONFIG_NET_GPTP) || defined(CONFIG_NET_LLDP)
|
2018-01-24 13:33:35 +01:00
|
|
|
if (addr->addr[0] == 0x01 &&
|
|
|
|
addr->addr[1] == 0x80 &&
|
|
|
|
addr->addr[2] == 0xc2 &&
|
|
|
|
addr->addr[3] == 0x00 &&
|
|
|
|
addr->addr[4] == 0x00 &&
|
|
|
|
addr->addr[5] == 0x0e) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-18 08:37:25 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(addr);
|
2018-01-24 13:33:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet MAC address is a PTP multicast address.
|
|
|
|
*
|
|
|
|
* @param addr A valid pointer to a Ethernet MAC address.
|
|
|
|
*
|
|
|
|
* @return true if address is a PTP multicast address, false if not
|
|
|
|
*/
|
2023-07-04 07:39:50 +02:00
|
|
|
static inline bool net_eth_is_addr_ptp_multicast(struct net_eth_addr *addr)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_NET_GPTP)
|
|
|
|
if (addr->addr[0] == 0x01 &&
|
|
|
|
addr->addr[1] == 0x1b &&
|
|
|
|
addr->addr[2] == 0x19 &&
|
|
|
|
addr->addr[3] == 0x00 &&
|
|
|
|
addr->addr[4] == 0x00 &&
|
|
|
|
addr->addr[5] == 0x00) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-18 08:37:25 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(addr);
|
2023-07-04 07:39:50 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/**
|
|
|
|
* @brief Return Ethernet broadcast address.
|
|
|
|
*
|
|
|
|
* @return Ethernet broadcast address.
|
|
|
|
*/
|
2016-06-08 13:13:27 +02:00
|
|
|
const struct net_eth_addr *net_eth_broadcast_addr(void);
|
|
|
|
|
2021-09-21 10:43:19 +02:00
|
|
|
/**
|
|
|
|
* @brief Convert IPv4 multicast address to Ethernet address.
|
|
|
|
*
|
|
|
|
* @param ipv4_addr IPv4 multicast address
|
|
|
|
* @param mac_addr Output buffer for Ethernet address
|
|
|
|
*/
|
|
|
|
void net_eth_ipv4_mcast_to_mac_addr(const struct in_addr *ipv4_addr,
|
|
|
|
struct net_eth_addr *mac_addr);
|
|
|
|
|
2017-12-04 16:24:08 +01:00
|
|
|
/**
|
|
|
|
* @brief Convert IPv6 multicast address to Ethernet address.
|
|
|
|
*
|
|
|
|
* @param ipv6_addr IPv6 multicast address
|
|
|
|
* @param mac_addr Output buffer for Ethernet address
|
|
|
|
*/
|
|
|
|
void net_eth_ipv6_mcast_to_mac_addr(const struct in6_addr *ipv6_addr,
|
|
|
|
struct net_eth_addr *mac_addr);
|
|
|
|
|
2018-03-14 09:55:19 +01:00
|
|
|
/**
|
|
|
|
* @brief Return ethernet device hardware capability information.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @return Hardware capabilities
|
|
|
|
*/
|
|
|
|
static inline
|
2018-04-06 10:57:13 +02:00
|
|
|
enum ethernet_hw_caps net_eth_get_hw_capabilities(struct net_if *iface)
|
2018-03-14 09:55:19 +01:00
|
|
|
{
|
|
|
|
const struct ethernet_api *eth =
|
2020-05-28 21:23:02 +02:00
|
|
|
(struct ethernet_api *)net_if_get_device(iface)->api;
|
2018-03-14 09:55:19 +01:00
|
|
|
|
|
|
|
if (!eth->get_capabilities) {
|
2019-05-23 10:33:34 +02:00
|
|
|
return (enum ethernet_hw_caps)0;
|
2018-03-14 09:55:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return eth->get_capabilities(net_if_get_device(iface));
|
|
|
|
}
|
|
|
|
|
2024-06-10 09:52:57 +02:00
|
|
|
/**
|
|
|
|
* @brief Return ethernet device hardware configuration information.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
* @param type configuration type
|
|
|
|
* @param config Ethernet configuration
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
|
|
|
static inline
|
|
|
|
int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
|
|
|
|
struct ethernet_config *config)
|
|
|
|
{
|
|
|
|
const struct ethernet_api *eth =
|
|
|
|
(struct ethernet_api *)net_if_get_device(iface)->api;
|
|
|
|
|
|
|
|
if (!eth->get_config) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eth->get_config(net_if_get_device(iface), type, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-19 11:24:33 +01:00
|
|
|
/**
|
|
|
|
* @brief Add VLAN tag to the interface.
|
|
|
|
*
|
|
|
|
* @param iface Interface to use.
|
|
|
|
* @param tag VLAN tag to add
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2020-05-27 18:26:57 +02:00
|
|
|
int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
|
2019-02-14 14:33:22 +01:00
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(iface);
|
|
|
|
ARG_UNUSED(tag);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-19 11:24:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Remove VLAN tag from the interface.
|
|
|
|
*
|
|
|
|
* @param iface Interface to use.
|
|
|
|
* @param tag VLAN tag to remove
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2020-05-27 18:26:57 +02:00
|
|
|
int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
|
2019-02-14 14:33:22 +01:00
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(iface);
|
|
|
|
ARG_UNUSED(tag);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-19 11:24:33 +01:00
|
|
|
|
|
|
|
/**
|
2024-03-17 14:32:29 +01:00
|
|
|
* @brief Return VLAN tag specified to network interface.
|
|
|
|
*
|
|
|
|
* Note that the interface parameter must be the VLAN interface,
|
|
|
|
* and not the Ethernet one.
|
2018-01-19 11:24:33 +01:00
|
|
|
*
|
2024-03-17 14:32:29 +01:00
|
|
|
* @param iface VLAN network interface.
|
2018-01-19 11:24:33 +01:00
|
|
|
*
|
|
|
|
* @return VLAN tag for this interface or NET_VLAN_TAG_UNSPEC if VLAN
|
|
|
|
* is not configured for that interface.
|
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2020-05-27 18:26:57 +02:00
|
|
|
uint16_t net_eth_get_vlan_tag(struct net_if *iface);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
2020-05-27 18:26:57 +02:00
|
|
|
static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
|
2019-02-14 14:33:22 +01:00
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return NET_VLAN_TAG_UNSPEC;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-19 11:24:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return network interface related to this VLAN tag
|
|
|
|
*
|
2024-03-17 14:32:29 +01:00
|
|
|
* @param iface Main network interface (not the VLAN one).
|
2018-01-19 11:24:33 +01:00
|
|
|
* @param tag VLAN tag
|
|
|
|
*
|
|
|
|
* @return Network interface related to this tag or NULL if no such interface
|
|
|
|
* exists.
|
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2020-05-27 18:26:57 +02:00
|
|
|
struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
|
|
|
static inline
|
2020-05-27 18:26:57 +02:00
|
|
|
struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
|
2019-02-14 14:33:22 +01:00
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(iface);
|
|
|
|
ARG_UNUSED(tag);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-19 11:24:33 +01:00
|
|
|
|
|
|
|
/**
|
2024-03-17 14:32:29 +01:00
|
|
|
* @brief Return main network interface that is attached to this VLAN tag.
|
|
|
|
*
|
|
|
|
* @param iface VLAN network interface. This is used to get the
|
|
|
|
* pointer to ethernet L2 context
|
|
|
|
*
|
|
|
|
* @return Network interface related to this tag or NULL if no such interface
|
|
|
|
* exists.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
struct net_if *net_eth_get_vlan_main(struct net_if *iface);
|
|
|
|
#else
|
|
|
|
static inline
|
|
|
|
struct net_if *net_eth_get_vlan_main(struct net_if *iface)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if there are any VLAN interfaces enabled to this specific
|
|
|
|
* Ethernet network interface.
|
|
|
|
*
|
|
|
|
* Note that the iface must be the actual Ethernet interface and not the
|
|
|
|
* virtual VLAN interface.
|
2018-01-19 11:24:33 +01:00
|
|
|
*
|
|
|
|
* @param ctx Ethernet context
|
2024-03-17 14:32:29 +01:00
|
|
|
* @param iface Ethernet network interface
|
2018-01-19 11:24:33 +01:00
|
|
|
*
|
2024-03-17 14:32:29 +01:00
|
|
|
* @return True if there are enabled VLANs for this network interface,
|
|
|
|
* false if not.
|
2018-01-19 11:24:33 +01:00
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2018-01-19 11:24:33 +01:00
|
|
|
bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
|
|
|
|
struct net_if *iface);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
|
|
|
static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
|
|
|
|
struct net_if *iface)
|
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(ctx);
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2018-07-03 09:58:12 +02:00
|
|
|
/**
|
|
|
|
* @brief Get VLAN status for a given network interface (enabled or not).
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @return True if VLAN is enabled for this network interface, false if not.
|
|
|
|
*/
|
2019-02-14 14:33:22 +01:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
2018-07-03 09:58:12 +02:00
|
|
|
bool net_eth_get_vlan_status(struct net_if *iface);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
|
|
|
static inline bool net_eth_get_vlan_status(struct net_if *iface)
|
|
|
|
{
|
2024-03-17 14:32:29 +01:00
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
2019-02-14 14:33:22 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2018-07-03 09:58:12 +02:00
|
|
|
|
2024-04-25 08:47:23 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the given interface is a VLAN interface.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @return True if this network interface is VLAN one, false if not.
|
|
|
|
*/
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
bool net_eth_is_vlan_interface(struct net_if *iface);
|
|
|
|
#else
|
|
|
|
static inline bool net_eth_is_vlan_interface(struct net_if *iface)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @cond INTERNAL_HIDDEN */
|
|
|
|
|
2024-03-11 11:18:18 +01:00
|
|
|
#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
|
2020-12-16 17:59:35 +01:00
|
|
|
|
2024-03-11 14:58:58 +01:00
|
|
|
#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
|
|
|
|
init_fn, pm, data, config, prio, \
|
|
|
|
api, mtu) \
|
|
|
|
Z_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
|
|
|
|
init_fn, pm, data, config, prio, \
|
|
|
|
api, ETHERNET_L2, \
|
|
|
|
NET_L2_GET_CTX_TYPE(ETHERNET_L2), mtu)
|
|
|
|
|
2024-03-11 11:18:18 +01:00
|
|
|
#else /* CONFIG_ETH_DRIVER_RAW_MODE */
|
|
|
|
|
|
|
|
#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \
|
|
|
|
init_fn, pm, data, config, prio, \
|
|
|
|
api, mtu) \
|
|
|
|
Z_DEVICE_STATE_DEFINE(dev_id); \
|
|
|
|
Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, \
|
|
|
|
config, POST_KERNEL, prio, api, \
|
|
|
|
&Z_DEVICE_STATE_NAME(dev_id));
|
2024-03-17 14:32:29 +01:00
|
|
|
|
2024-03-11 11:18:18 +01:00
|
|
|
#endif /* CONFIG_ETH_DRIVER_RAW_MODE */
|
|
|
|
|
2022-09-30 10:01:28 +02:00
|
|
|
#define Z_ETH_NET_DEVICE_INIT(node_id, dev_id, name, init_fn, pm, data, \
|
|
|
|
config, prio, api, mtu) \
|
2024-03-11 14:58:58 +01:00
|
|
|
Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, 0, \
|
|
|
|
init_fn, pm, data, config, prio, \
|
|
|
|
api, mtu)
|
2020-12-16 17:59:35 +01:00
|
|
|
|
2024-05-18 08:37:25 +02:00
|
|
|
/** @endcond */
|
|
|
|
|
2019-02-19 15:37:27 +01:00
|
|
|
/**
|
|
|
|
* @brief Create an Ethernet network interface and bind it to network device.
|
|
|
|
*
|
2022-09-29 13:42:04 +02:00
|
|
|
* @param dev_id Network device id.
|
2022-09-30 10:01:28 +02:00
|
|
|
* @param name The name this instance of the driver exposes to
|
2019-02-19 15:37:27 +01:00
|
|
|
* the system.
|
|
|
|
* @param init_fn Address to the init function of the driver.
|
2022-09-30 10:51:35 +02:00
|
|
|
* @param pm Reference to struct pm_device associated with the device.
|
|
|
|
* (optional).
|
2020-05-29 09:18:31 +02:00
|
|
|
* @param data Pointer to the device's private data.
|
2022-09-30 10:01:28 +02:00
|
|
|
* @param config The address to the structure containing the
|
2019-02-19 15:37:27 +01:00
|
|
|
* configuration information for this instance of the driver.
|
|
|
|
* @param prio The initialization level at which configuration occurs.
|
|
|
|
* @param api Provides an initial pointer to the API function struct
|
|
|
|
* used by the driver. Can be NULL.
|
|
|
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
|
|
|
*/
|
2022-09-30 10:01:28 +02:00
|
|
|
#define ETH_NET_DEVICE_INIT(dev_id, name, init_fn, pm, data, config, \
|
|
|
|
prio, api, mtu) \
|
|
|
|
Z_ETH_NET_DEVICE_INIT(DT_INVALID_NODE, dev_id, name, init_fn, \
|
|
|
|
pm, data, config, prio, api, mtu)
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2024-03-11 14:58:58 +01:00
|
|
|
/**
|
|
|
|
* @brief Create multiple Ethernet network interfaces and bind them to network
|
|
|
|
* devices.
|
|
|
|
* If your network device needs more than one instance of a network interface,
|
|
|
|
* use this macro below and provide a different instance suffix each time
|
|
|
|
* (0, 1, 2, ... or a, b, c ... whatever works for you)
|
|
|
|
*
|
|
|
|
* @param dev_id Network device id.
|
|
|
|
* @param name The name this instance of the driver exposes to
|
|
|
|
* the system.
|
|
|
|
* @param instance Instance identifier.
|
|
|
|
* @param init_fn Address to the init function of the driver.
|
|
|
|
* @param pm Reference to struct pm_device associated with the device.
|
|
|
|
* (optional).
|
|
|
|
* @param data Pointer to the device's private data.
|
|
|
|
* @param config The address to the structure containing the
|
|
|
|
* configuration information for this instance of the driver.
|
|
|
|
* @param prio The initialization level at which configuration occurs.
|
|
|
|
* @param api Provides an initial pointer to the API function struct
|
|
|
|
* used by the driver. Can be NULL.
|
|
|
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
|
|
|
*/
|
|
|
|
#define ETH_NET_DEVICE_INIT_INSTANCE(dev_id, name, instance, init_fn, \
|
|
|
|
pm, data, config, prio, api, mtu) \
|
|
|
|
Z_ETH_NET_DEVICE_INIT_INSTANCE(DT_INVALID_NODE, dev_id, name, \
|
|
|
|
instance, init_fn, pm, data, \
|
|
|
|
config, prio, api, mtu)
|
|
|
|
|
2020-12-16 17:59:35 +01:00
|
|
|
/**
|
|
|
|
* @brief Like ETH_NET_DEVICE_INIT but taking metadata from a devicetree.
|
|
|
|
* Create an Ethernet network interface and bind it to network device.
|
|
|
|
*
|
|
|
|
* @param node_id The devicetree node identifier.
|
|
|
|
* @param init_fn Address to the init function of the driver.
|
2022-09-30 10:51:35 +02:00
|
|
|
* @param pm Reference to struct pm_device associated with the device.
|
|
|
|
* (optional).
|
2020-12-16 17:59:35 +01:00
|
|
|
* @param data Pointer to the device's private data.
|
2022-09-30 10:01:28 +02:00
|
|
|
* @param config The address to the structure containing the
|
2020-12-16 17:59:35 +01:00
|
|
|
* configuration information for this instance of the driver.
|
|
|
|
* @param prio The initialization level at which configuration occurs.
|
|
|
|
* @param api Provides an initial pointer to the API function struct
|
|
|
|
* used by the driver. Can be NULL.
|
|
|
|
* @param mtu Maximum transfer unit in bytes for this network interface.
|
|
|
|
*/
|
2022-09-30 10:01:28 +02:00
|
|
|
#define ETH_NET_DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, \
|
|
|
|
prio, api, mtu) \
|
2022-09-29 15:36:05 +02:00
|
|
|
Z_ETH_NET_DEVICE_INIT(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
|
2022-09-30 10:01:28 +02:00
|
|
|
DEVICE_DT_NAME(node_id), init_fn, pm, \
|
|
|
|
data, config, prio, api, mtu)
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2020-12-16 17:59:35 +01:00
|
|
|
/**
|
|
|
|
* @brief Like ETH_NET_DEVICE_DT_DEFINE for an instance of a DT_DRV_COMPAT
|
|
|
|
* compatible
|
|
|
|
*
|
|
|
|
* @param inst instance number. This is replaced by
|
|
|
|
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to ETH_NET_DEVICE_DT_DEFINE.
|
|
|
|
*
|
|
|
|
* @param ... other parameters as expected by ETH_NET_DEVICE_DT_DEFINE.
|
|
|
|
*/
|
|
|
|
#define ETH_NET_DEVICE_DT_INST_DEFINE(inst, ...) \
|
|
|
|
ETH_NET_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
|
2018-01-19 11:24:33 +01:00
|
|
|
|
2018-06-04 12:37:17 +02:00
|
|
|
/**
|
|
|
|
* @brief Inform ethernet L2 driver that ethernet carrier is detected.
|
|
|
|
* This happens when cable is connected.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*/
|
|
|
|
void net_eth_carrier_on(struct net_if *iface);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Inform ethernet L2 driver that ethernet carrier was lost.
|
|
|
|
* This happens when cable is disconnected.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*/
|
|
|
|
void net_eth_carrier_off(struct net_if *iface);
|
|
|
|
|
2018-07-20 15:44:58 +02:00
|
|
|
/**
|
|
|
|
* @brief Set promiscuous mode either ON or OFF.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
2018-07-24 20:52:34 +02:00
|
|
|
* @param enable on (true) or off (false)
|
|
|
|
*
|
|
|
|
* @return 0 if mode set or unset was successful, <0 otherwise.
|
2018-07-20 15:44:58 +02:00
|
|
|
*/
|
|
|
|
int net_eth_promisc_mode(struct net_if *iface, bool enable);
|
|
|
|
|
2024-01-22 05:38:03 +01:00
|
|
|
/**
|
|
|
|
* @brief Set TX-Injection mode either ON or OFF.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @param enable on (true) or off (false)
|
|
|
|
*
|
|
|
|
* @return 0 if mode set or unset was successful, <0 otherwise.
|
|
|
|
*/
|
|
|
|
int net_eth_txinjection_mode(struct net_if *iface, bool enable);
|
|
|
|
|
2024-02-23 12:10:16 +01:00
|
|
|
/**
|
|
|
|
* @brief Set or unset HW filtering for MAC address @p mac.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
* @param mac Pointer to an ethernet MAC address
|
|
|
|
* @param type Filter type, either source or destination
|
|
|
|
* @param enable Set (true) or unset (false)
|
|
|
|
*
|
|
|
|
* @return 0 if filter set or unset was successful, <0 otherwise.
|
|
|
|
*/
|
|
|
|
int net_eth_mac_filter(struct net_if *iface, struct net_eth_addr *mac,
|
|
|
|
enum ethernet_filter_type type, bool enable);
|
2018-01-24 14:22:55 +01:00
|
|
|
/**
|
|
|
|
* @brief Return PTP clock that is tied to this ethernet network interface.
|
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @return Pointer to PTP clock if found, NULL if not found or if this
|
|
|
|
* ethernet interface does not support PTP.
|
|
|
|
*/
|
2019-05-27 14:50:08 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK)
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *net_eth_get_ptp_clock(struct net_if *iface);
|
2019-05-27 14:50:08 +02:00
|
|
|
#else
|
2020-04-30 20:33:38 +02:00
|
|
|
static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
|
2019-05-27 14:50:08 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-24 14:22:55 +01:00
|
|
|
|
2019-05-24 13:43:56 +02:00
|
|
|
/**
|
|
|
|
* @brief Return PTP clock that is tied to this ethernet network interface
|
|
|
|
* index.
|
|
|
|
*
|
|
|
|
* @param index Network interface index
|
|
|
|
*
|
|
|
|
* @return Pointer to PTP clock if found, NULL if not found or if this
|
|
|
|
* ethernet interface index does not support PTP.
|
|
|
|
*/
|
2020-04-30 20:33:38 +02:00
|
|
|
__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
|
2019-05-24 13:43:56 +02:00
|
|
|
|
2018-01-24 13:33:35 +01:00
|
|
|
/**
|
2021-09-09 05:28:27 +02:00
|
|
|
* @brief Return PTP port number attached to this interface.
|
2018-01-24 13:33:35 +01:00
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
*
|
|
|
|
* @return Port number, no such port if < 0
|
|
|
|
*/
|
2021-09-09 05:28:27 +02:00
|
|
|
#if defined(CONFIG_NET_L2_PTP)
|
2018-01-24 13:33:35 +01:00
|
|
|
int net_eth_get_ptp_port(struct net_if *iface);
|
2019-02-14 14:33:22 +01:00
|
|
|
#else
|
|
|
|
static inline int net_eth_get_ptp_port(struct net_if *iface)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2021-09-09 05:28:27 +02:00
|
|
|
#endif /* CONFIG_NET_L2_PTP */
|
2018-01-24 13:33:35 +01:00
|
|
|
|
|
|
|
/**
|
2021-09-09 05:28:27 +02:00
|
|
|
* @brief Set PTP port number attached to this interface.
|
2018-01-24 13:33:35 +01:00
|
|
|
*
|
|
|
|
* @param iface Network interface
|
|
|
|
* @param port Port number to set
|
|
|
|
*/
|
2021-09-09 05:28:27 +02:00
|
|
|
#if defined(CONFIG_NET_L2_PTP)
|
2018-01-24 13:33:35 +01:00
|
|
|
void net_eth_set_ptp_port(struct net_if *iface, int port);
|
2023-06-06 20:06:14 +02:00
|
|
|
#else
|
|
|
|
static inline void net_eth_set_ptp_port(struct net_if *iface, int port)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(iface);
|
|
|
|
ARG_UNUSED(port);
|
|
|
|
}
|
2021-09-09 05:28:27 +02:00
|
|
|
#endif /* CONFIG_NET_L2_PTP */
|
2018-01-24 13:33:35 +01:00
|
|
|
|
2023-06-05 22:24:20 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if the Ethernet L2 network interface can perform Wi-Fi.
|
|
|
|
*
|
|
|
|
* @param iface Pointer to network interface
|
|
|
|
*
|
|
|
|
* @return True if interface supports Wi-Fi, False otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool net_eth_type_is_wifi(struct net_if *iface)
|
|
|
|
{
|
|
|
|
const struct ethernet_context *ctx = (struct ethernet_context *)
|
|
|
|
net_if_l2_data(iface);
|
|
|
|
|
|
|
|
return ctx->eth_if_type == L2_ETH_IF_TYPE_WIFI;
|
|
|
|
}
|
|
|
|
|
2019-08-12 23:40:47 +02:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2019-05-27 06:44:01 +02:00
|
|
|
|
2017-07-24 15:23:14 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-01-24 10:35:04 +01:00
|
|
|
#include <zephyr/syscalls/ethernet.h>
|
2017-07-20 15:29:45 +02:00
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_H_ */
|