net: ptp: extract PTP interfaces outside gPTP subsys under NET_L2_PTP

As per #38352, we would like to start building out PTP (IEEE 1588)
support for superset of gPTP functionality in Zephyr. This is the first
step to abstract away some key interfaces from NET_GPTP umbrella to
NET_L2_PTP.

Signed-off-by: Alex Sergeev <asergeev@carbonrobotics.com>
This commit is contained in:
Alex Sergeev 2021-09-08 20:28:27 -07:00 committed by Christopher Friedt
commit e7778b8584
10 changed files with 34 additions and 26 deletions

View file

@ -549,10 +549,10 @@ struct ethernet_context {
*/
enum net_l2_flags ethernet_l2_flags;
#if defined(CONFIG_NET_GPTP)
/** The gPTP port number for this network device. We need to store the
#if defined(CONFIG_NET_L2_PTP)
/** The PTP port number for this network device. We need to store the
* port number here so that we do not need to fetch it for every
* incoming gPTP packet.
* incoming PTP packet.
*/
int port;
#endif
@ -966,13 +966,13 @@ static inline const struct device *net_eth_get_ptp_clock(struct net_if *iface)
__syscall const struct device *net_eth_get_ptp_clock_by_index(int index);
/**
* @brief Return gPTP port number attached to this interface.
* @brief Return PTP port number attached to this interface.
*
* @param iface Network interface
*
* @return Port number, no such port if < 0
*/
#if defined(CONFIG_NET_GPTP)
#if defined(CONFIG_NET_L2_PTP)
int net_eth_get_ptp_port(struct net_if *iface);
#else
static inline int net_eth_get_ptp_port(struct net_if *iface)
@ -981,17 +981,17 @@ static inline int net_eth_get_ptp_port(struct net_if *iface)
return -ENODEV;
}
#endif /* CONFIG_NET_GPTP */
#endif /* CONFIG_NET_L2_PTP */
/**
* @brief Set gPTP port number attached to this interface.
* @brief Set PTP port number attached to this interface.
*
* @param iface Network interface
* @param port Port number to set
*/
#if defined(CONFIG_NET_GPTP)
#if defined(CONFIG_NET_L2_PTP)
void net_eth_set_ptp_port(struct net_if *iface, int port);
#endif /* CONFIG_NET_GPTP */
#endif /* CONFIG_NET_L2_PTP */
/**
* @}

View file

@ -148,10 +148,10 @@ struct net_pkt {
* the driver yet.
* Used only if defined(CONFIG_NET_TCP)
*/
uint8_t gptp_pkt: 1; /* For outgoing packet: is this packet
* a GPTP packet.
* Used only if defined (CONFIG_NET_GPTP)
*/
uint8_t ptp_pkt: 1; /* For outgoing packet: is this packet
* a L2 PTP packet.
* Used only if defined (CONFIG_NET_L2_PTP)
*/
};
uint8_t forwarding : 1; /* Are we forwarding this pkt
@ -336,14 +336,14 @@ static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
pkt->family = family;
}
static inline bool net_pkt_is_gptp(struct net_pkt *pkt)
static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
{
return !!(pkt->gptp_pkt);
return !!(pkt->ptp_pkt);
}
static inline void net_pkt_set_gptp(struct net_pkt *pkt, bool is_gptp)
static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
{
pkt->gptp_pkt = is_gptp;
pkt->ptp_pkt = is_ptp;
}
static inline bool net_pkt_is_captured(struct net_pkt *pkt)

View file

@ -67,6 +67,7 @@ NET_IPV4_AUTO,n,experimental
NET_L2_CANBUS,n,experimental
NET_L2_IEEE802154_SECURITY,n,experimental
NET_L2_PPP,n,experimental
NET_L2_PTP,n,experimental
NET_OFFLOAD,n,experimental
NET_PROMISCUOUS_MODE,n,experimental
NET_SOCKETS_CAN,n,experimental

Can't render this file because it has a wrong number of fields in line 42.

View file

@ -751,7 +751,7 @@ config NET_PKT_TIMESTAMP
config NET_PKT_TIMESTAMP_THREAD
bool "Create TX timestamp thread"
default y if NET_GPTP
default y if NET_L2_PTP
depends on NET_PKT_TIMESTAMP
help
Create a TX timestamp thread that will pass the timestamped network

View file

@ -101,4 +101,11 @@ config NET_L2_WIFI_SHELL
This can be used for controlling Wi-Fi through the console via
exposing a shell module named "wifi".
config NET_L2_PTP
bool "Enable PTP L2 support"
select NET_PKT_TIMESTAMP
select PTP_CLOCK
help
Add support for PTP L2 capabilities. Required by gPTP.
endmenu

View file

@ -243,7 +243,7 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
net_pkt_set_family(pkt, AF_INET6);
family = AF_INET6;
break;
#if defined(CONFIG_NET_GPTP)
#if defined(CONFIG_NET_L2_PTP)
case NET_ETH_PTYPE_PTP:
family = AF_UNSPEC;
break;
@ -665,7 +665,7 @@ static int ethernet_send(struct net_if *iface, struct net_pkt *pkt)
} else {
goto send;
}
} else if (IS_ENABLED(CONFIG_NET_GPTP) && net_pkt_is_gptp(pkt)) {
} else if (IS_ENABLED(CONFIG_NET_L2_PTP) && net_pkt_is_ptp(pkt)) {
ptype = htons(NET_ETH_PTYPE_PTP);
} else if (IS_ENABLED(CONFIG_NET_LLDP) && net_pkt_is_lldp(pkt)) {
ptype = htons(NET_ETH_PTYPE_LLDP);
@ -1143,7 +1143,7 @@ const struct device *z_impl_net_eth_get_ptp_clock_by_index(int index)
}
#endif /* CONFIG_PTP_CLOCK */
#if defined(CONFIG_NET_GPTP)
#if defined(CONFIG_NET_L2_PTP)
int net_eth_get_ptp_port(struct net_if *iface)
{
struct ethernet_context *ctx = net_if_l2_data(iface);
@ -1157,7 +1157,7 @@ void net_eth_set_ptp_port(struct net_if *iface, int port)
ctx->port = port;
}
#endif /* CONFIG_NET_GPTP */
#endif /* CONFIG_NET_L2_PTP */
int net_eth_promisc_mode(struct net_if *iface, bool enable)
{

View file

@ -3,8 +3,7 @@
menuconfig NET_GPTP
bool "Enable IEEE 802.1AS (gPTP) support [EXPERIMENTAL]"
select NET_PKT_TIMESTAMP
select PTP_CLOCK
select NET_L2_PTP
help
Enable gPTP driver that send and receives gPTP packets
and handles network packet timestamps.

View file

@ -169,7 +169,7 @@ static struct net_pkt *setup_gptp_frame(struct net_if *iface,
}
net_buf_add(pkt->buffer, sizeof(struct gptp_hdr) + extra_header);
net_pkt_set_gptp(pkt, true);
net_pkt_set_ptp(pkt, true);
net_pkt_lladdr_src(pkt)->addr = net_if_get_link_addr(iface)->addr;
net_pkt_lladdr_src(pkt)->len = net_if_get_link_addr(iface)->len;

View file

@ -105,6 +105,7 @@ CONFIG_NET_L2_BT_LOG_LEVEL_DBG=y
CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL_DBG=y
CONFIG_NET_L2_WIFI_MGMT=y
CONFIG_NET_L2_WIFI_SHELL=y
CONFIG_NET_L2_PTP=y
# Bluetooth IPSP
CONFIG_BT=y

View file

@ -27,5 +27,5 @@ CONFIG_COVERAGE=n
CONFIG_TEST_USERSPACE=y
CONFIG_HEAP_MEM_POOL_SIZE=128
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_NET_GPTP=y
CONFIG_NET_L2_PTP=y
CONFIG_NET_TC_TX_COUNT=1