From 11b06fab761892f15a955aca864193bc9b31498c Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Fri, 24 May 2019 14:43:56 +0300 Subject: [PATCH] net: ethernet: Add net_eth_get_ptp_clock_by_index() function This can be used to get the PTP clock if only network interface index is known. Signed-off-by: Jukka Rissanen --- include/net/ethernet.h | 20 ++++++++++++++++++++ subsys/net/l2/ethernet/ethernet.c | 14 ++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/net/ethernet.h b/include/net/ethernet.h index 1cba61d9493..abd64e4f0ee 100644 --- a/include/net/ethernet.h +++ b/include/net/ethernet.h @@ -682,6 +682,26 @@ static inline struct device *net_eth_get_ptp_clock(struct net_if *iface) } #endif +/** + * @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. + */ +#if defined(CONFIG_PTP_CLOCK) +struct device *net_eth_get_ptp_clock_by_index(int index); +#else +static inline struct device *net_eth_get_ptp_clock_by_index(int index) +{ + ARG_UNUSED(index); + + return NULL; +} +#endif + /** * @brief Return gPTP port number attached to this interface. * diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index d8f28588e5e..c4e47cd26f3 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -987,6 +987,20 @@ struct device *net_eth_get_ptp_clock(struct net_if *iface) } #endif /* CONFIG_PTP_CLOCK */ +#if defined(CONFIG_PTP_CLOCK) +struct device *net_eth_get_ptp_clock_by_index(int index) +{ + struct net_if *iface; + + iface = net_if_get_by_index(index); + if (!iface) { + return NULL; + } + + return net_eth_get_ptp_clock(iface); +} +#endif + #if defined(CONFIG_NET_GPTP) int net_eth_get_ptp_port(struct net_if *iface) {