Skip to contentSkip to conversation

net: stmmac: retain PTP-clock at hwtstamp_set

PATCH In review Holger Assmann 5 participants 9 messages Dec 16, 2020 – Jan 11, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net: stmmac: retain PTP-clock at hwtstamp_set

As it is, valid SIOCSHWTSTAMP ioctl calls - i.e. enable/disable time stamping or changing filter settings - lead to synchronization of the NIC's hardware clock with CLOCK_REALTIME. This might be necessary during system initialization, but at runtime, when the PTP clock has already been synchronized to a grand master, a reset of the timestamp settings might result in a clock jump.

This further differs from how drivers like IGB and FEC behave: Those initialize the PTP system time less frequently - on interface up and at probe time, respectively.

We consequently introduce the new function stmmac_init_hwtstamp(), which gets called during ndo_open(). It contains the code snippet moved from stmmac_hwtstamp_set() that manages the time synchronization. Besides, the sub second increment configuration is also moved here since the related values are hardware dependent and do not change during runtime.

Furthermore, the hardware clock must be kept running even when no time stamping mode is selected in order to retain the once synced time basis. That way, time stamping can be enabled again at any time only with the need for compensation of the clock's natural drifting.

As a side effect, this patch fixes a potential race between SIOCSHWTSTAMP and ptp_clock_info::enable regarding priv->systime_flags. Subsequently, since this variable becomes deprecated by this commit, it should be removed completely in a follow-up patch.

Fixes 92ba6888510c ("stmmac: add the support for PTP hw clock driver")
Fixes cc4c9001ce31 ("net: stmmac: Switch stmmac_hwtimestamp to generic

HW Interface Helpers")

---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 121 ++++++++++++------
 1 file changed, 80 insertions(+), 41 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +80 -41
index 5b1c12ff98c0..55f5e6cd1cad 100644
@@ -46,6 +46,13 @@
 #include "dwxgmac2.h"
 #include "hwif.h"
 
+
+/* As long the interface is active, we keep the timestamping HW enabled with
+ * fine resolution and binary rollover. This avoid non-monotonic behavior
+ * when changing timestamp settings at runtime
+ * */
+#define STMMAC_HWTS_ACTIVE (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR)
+
 #define	STMMAC_ALIGN(x)		ALIGN(ALIGN(x, SMP_CACHE_BYTES), 16)
 #define	TSO_MAX_BUFF_SIZE	(SZ_16K - 1)
 
@@ -509,8 +516,6 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 {
 	struct stmmac_priv *priv = netdev_priv(dev);
 	struct hwtstamp_config config;
-	struct timespec64 now;
-	u64 temp = 0;
 	u32 ptp_v2 = 0;
 	u32 tstamp_all = 0;
 	u32 ptp_over_ipv4_udp = 0;
@@ -519,7 +524,6 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 	u32 snap_type_sel = 0;
 	u32 ts_master_en = 0;
 	u32 ts_event_en = 0;
-	u32 sec_inc = 0;
 	u32 value = 0;
 	bool xmac;
 
@@ -686,39 +690,16 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 	priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
 
 	if (!priv->hwts_tx_en && !priv->hwts_rx_en)
-		stmmac_config_hw_tstamping(priv, priv->ptpaddr, 0);
+		stmmac_config_hw_tstamping(priv, priv->ptpaddr, STMMAC_HWTS_ACTIVE);
 	else {
-		value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR |
+		value = (STMMAC_HWTS_ACTIVE |
 			 tstamp_all | ptp_v2 | ptp_over_ethernet |
 			 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
 			 ts_master_en | snap_type_sel);
 		stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
-
-		/* program Sub Second Increment reg */
-		stmmac_config_sub_second_increment(priv,
-				priv->ptpaddr, priv->plat->clk_ptp_rate,
-				xmac, &sec_inc);
-		temp = div_u64(1000000000ULL, sec_inc);
-
-		/* Store sub second increment and flags for later use */
-		priv->sub_second_inc = sec_inc;
+		
+		/* Store flags for later use */
 		priv->systime_flags = value;
-
-		/* calculate default added value:
-		 * formula is :
-		 * addend = (2^32)/freq_div_ratio;
-		 * where, freq_div_ratio = 1e9ns/sec_inc
-		 */
-		temp = (u64)(temp << 32);
-		priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
-		stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
-
-		/* initialize system time */
-		ktime_get_real_ts64(&now);
-
-		/* lower 32 bits of tv_sec are safe until y2106 */
-		stmmac_init_systime(priv, priv->ptpaddr,
-				(u32)now.tv_sec, now.tv_nsec);
 	}
 
 	memcpy(&priv->tstamp_config, &config, sizeof(config));
@@ -791,6 +772,63 @@ static void stmmac_release_ptp(struct stmmac_priv *priv)
 	stmmac_ptp_unregister(priv);
 }
 
+/**
+ * stmmac_init_hwtstamp - init Timestamping Hardware
+ * @priv: driver private structure
+ * Description: Initialize hardware for Timestamping use
+ * This is valid as long as the interface is open and not suspended.
+ * Will be rerun after resume from suspension.
+ */
+static int stmmac_init_hwtstamp(struct stmmac_priv *priv)
+{
+	bool xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;
+	struct timespec64 now;
+	u32 sec_inc = 0;
+	u64 temp = 0;
+	u32 value;
+	int ret;
+
+	ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
+	if (ret < 0) {
+		netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret);
+		return ret;
+	}
+
+	if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))
+		return -EOPNOTSUPP;
+
+	value = STMMAC_HWTS_ACTIVE;
+	stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
+
+	/* program Sub Second Increment reg */
+	stmmac_config_sub_second_increment(priv,
+			priv->ptpaddr, priv->plat->clk_ptp_rate,
+			xmac, &sec_inc);
+	temp = div_u64(1000000000ULL, sec_inc);
+
+	/* Store sub second increment and flags for later use */
+	priv->sub_second_inc = sec_inc;
+	priv->systime_flags = value;
+
+	/* calculate default added value:
+	 * formula is :
+	 * addend = (2^32)/freq_div_ratio;
+	 * where, freq_div_ratio = 1e9ns/sec_inc
+	 */
+	temp = (u64)(temp << 32);
+	priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
+	stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
+
+	/* initialize system time */
+	ktime_get_real_ts64(&now);
+
+	/* lower 32 bits of tv_sec are safe until y2106 */
+	stmmac_init_systime(priv, priv->ptpaddr,
+			(u32)now.tv_sec, now.tv_nsec);
+
+	return 0;
+}
+
 /**
  *  stmmac_mac_flow_ctrl - Configure flow control in all queues
  *  @priv: driver private structure
@@ -2713,15 +2751,17 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
 	stmmac_mmc_setup(priv);
 
 	if (init_ptp) {
-		ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
-		if (ret < 0)
-			netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret);
-
-		ret = stmmac_init_ptp(priv);
-		if (ret == -EOPNOTSUPP)
-			netdev_warn(priv->dev, "PTP not supported by HW\n");
-		else if (ret)
-			netdev_warn(priv->dev, "PTP init failed\n");
+		ret = stmmac_init_hwtstamp(priv);
+		if (ret) {
+			netdev_warn(priv->dev, "HW Timestamping init failed: %pe\n",
+					ERR_PTR(ret));
+		} else {
+			ret = stmmac_init_ptp(priv);
+			if (ret == -EOPNOTSUPP)
+				netdev_warn(priv->dev, "PTP not supported by HW\n");
+			else if (ret)
+				netdev_warn(priv->dev, "PTP init failed\n");
+		}
 	}
 
 	priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS;
@@ -5290,8 +5330,7 @@ int stmmac_resume(struct device *dev)
 		/* enable the clk previously disabled */
 		clk_prepare_enable(priv->plat->stmmac_clk);
 		clk_prepare_enable(priv->plat->pclk);
-		if (priv->plat->clk_ptp_ref)
-			clk_prepare_enable(priv->plat->clk_ptp_ref);
+		stmmac_init_hwtstamp(priv);
 		/* reset the phy so that it's ready */
 		if (priv->mii)
 			stmmac_mdio_reset(priv->mii);

base-commit: 3db1a3fa98808aa90f95ec3e0fa2fc7abf28f5c9

Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 net: stmmac: drop no longer variable priv member

This follow-up patch removes the member "systime_flags" from "stmmac_priv" and the affected funtions in stmmac.

Usage of this variable becomes deprecated after the introduction of "stmmac_init_hwtstamp()", which now takes care of setting the respective register flags.

---
 drivers/net/ethernet/stmicro/stmmac/dwmac5.c        | 7 +++----
 drivers/net/ethernet/stmicro/stmmac/dwmac5.h        | 2 +-
 drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 7 +++----
 drivers/net/ethernet/stmicro/stmmac/hwif.h          | 2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac.h        | 1 -
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c   | 6 +-----
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c    | 3 +--
 7 files changed, 10 insertions(+), 18 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac5.c +3 -4
index 03e79a677c8b..53d14d660220 100644
@@ -494,7 +494,7 @@ int dwmac5_rxp_config(void __iomem *ioaddr, struct stmmac_tc_entry *entries,
 
 int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
 			   struct stmmac_pps_cfg *cfg, bool enable,
-			   u32 sub_second_inc, u32 systime_flags)
+			   u32 sub_second_inc)
 {
 	u32 tnsec = readl(ioaddr + MAC_PPSx_TARGET_TIME_NSEC(index));
 	u32 val = readl(ioaddr + MAC_PPS_CONTROL);
@@ -504,7 +504,7 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
 		return -EINVAL;
 	if (tnsec & TRGTBUSY0)
 		return -EBUSY;
-	if (!sub_second_inc || !systime_flags)
+	if (!sub_second_inc)
 		return -EINVAL;
 
 	val &= ~PPSx_MASK(index);
@@ -522,8 +522,7 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
 
 	writel(cfg->start.tv_sec, ioaddr + MAC_PPSx_TARGET_TIME_SEC(index));
 
-	if (!(systime_flags & PTP_TCR_TSCTRLSSR))
-		cfg->start.tv_nsec = (cfg->start.tv_nsec * 1000) / 465;
+	/* HW timestamping init always sets PTP_TCR_TSCTRLSSR, so no conversion necessary */
 	writel(cfg->start.tv_nsec, ioaddr + MAC_PPSx_TARGET_TIME_NSEC(index));
 
 	period = cfg->period.tv_sec * 1000000000;
drivers/net/ethernet/stmicro/stmmac/dwmac5.h +1 -1
index 56b0762c1276..f89996cc4403 100644
@@ -108,7 +108,7 @@ int dwmac5_rxp_config(void __iomem *ioaddr, struct stmmac_tc_entry *entries,
 		      unsigned int count);
 int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
 			   struct stmmac_pps_cfg *cfg, bool enable,
-			   u32 sub_second_inc, u32 systime_flags);
+			   u32 sub_second_inc);
 int dwmac5_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg,
 			 unsigned int ptp_rate);
 void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 num_rxq,
drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +3 -4
index ad4df9bddcf3..3bf3ce81dbd8 100644
@@ -1109,7 +1109,7 @@ static int dwxgmac2_get_mac_tx_timestamp(struct mac_device_info *hw, u64 *ts)
 
 static int dwxgmac2_flex_pps_config(void __iomem *ioaddr, int index,
 				    struct stmmac_pps_cfg *cfg, bool enable,
-				    u32 sub_second_inc, u32 systime_flags)
+				    u32 sub_second_inc)
 {
 	u32 tnsec = readl(ioaddr + XGMAC_PPSx_TARGET_TIME_NSEC(index));
 	u32 val = readl(ioaddr + XGMAC_PPS_CONTROL);
@@ -1119,7 +1119,7 @@ static int dwxgmac2_flex_pps_config(void __iomem *ioaddr, int index,
 		return -EINVAL;
 	if (tnsec & XGMAC_TRGTBUSY0)
 		return -EBUSY;
-	if (!sub_second_inc || !systime_flags)
+	if (!sub_second_inc)
 		return -EINVAL;
 
 	val &= ~XGMAC_PPSx_MASK(index);
@@ -1136,8 +1136,7 @@ static int dwxgmac2_flex_pps_config(void __iomem *ioaddr, int index,
 
 	writel(cfg->start.tv_sec, ioaddr + XGMAC_PPSx_TARGET_TIME_SEC(index));
 
-	if (!(systime_flags & PTP_TCR_TSCTRLSSR))
-		cfg->start.tv_nsec = (cfg->start.tv_nsec * 1000) / 465;
+	/* HW timestamping init always sets PTP_TCR_TSCTRLSSR, so no conversion necessary */
 	writel(cfg->start.tv_nsec, ioaddr + XGMAC_PPSx_TARGET_TIME_NSEC(index));
 
 	period = cfg->period.tv_sec * 1000000000;
drivers/net/ethernet/stmicro/stmmac/hwif.h +1 -1
index b40b2e0667bb..7d73d3206068 100644
@@ -360,7 +360,7 @@ struct stmmac_ops {
 	/* Flexible PPS */
 	int (*flex_pps_config)(void __iomem *ioaddr, int index,
 			       struct stmmac_pps_cfg *cfg, bool enable,
-			       u32 sub_second_inc, u32 systime_flags);
+			       u32 sub_second_inc);
 	/* Loopback for selftests */
 	void (*set_mac_loopback)(void __iomem *ioaddr, bool enable);
 	/* RSS */
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -1
index e553b9a1f785..4d0642ae55d6 100644
@@ -217,7 +217,6 @@ struct stmmac_priv {
 	struct ptp_clock_info ptp_clock_ops;
 	unsigned int default_addend;
 	u32 sub_second_inc;
-	u32 systime_flags;
 	u32 adv_ts;
 	int use_riwt;
 	int irq_wake;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -5
index 55f5e6cd1cad..a6e4c7c26b4d 100644
@@ -697,9 +697,6 @@ static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
 			 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
 			 ts_master_en | snap_type_sel);
 		stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
-		
-		/* Store flags for later use */
-		priv->systime_flags = value;
 	}
 
 	memcpy(&priv->tstamp_config, &config, sizeof(config));
@@ -806,9 +803,8 @@ static int stmmac_init_hwtstamp(struct stmmac_priv *priv)
 			xmac, &sec_inc);
 	temp = div_u64(1000000000ULL, sec_inc);
 
-	/* Store sub second increment and flags for later use */
+	/* Store sub second increment for later use */
 	priv->sub_second_inc = sec_inc;
-	priv->systime_flags = value;
 
 	/* calculate default added value:
 	 * formula is :
drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c +1 -2
index 0989e2bb6ee3..70a113ab4789 100644
@@ -154,8 +154,7 @@ static int stmmac_enable(struct ptp_clock_info *ptp,
 		spin_lock_irqsave(&priv->ptp_lock, flags);
 		ret = stmmac_flex_pps_config(priv, priv->ioaddr,
 					     rq->perout.index, cfg, on,
-					     priv->sub_second_inc,
-					     priv->systime_flags);
+					     priv->sub_second_inc);
 		spin_unlock_irqrestore(&priv->ptp_lock, flags);
 		break;
 	default:
Signature · 1 line
2.20.1
maintainer
#2 lore raw
In reply to Holger Assmann
Quoted 22 lines · On Wed, 16 Dec 2020 12:32:38 +0100 Holger Assmann wrote:

As it is, valid SIOCSHWTSTAMP ioctl calls - i.e. enable/disable time stamping or changing filter settings - lead to synchronization of the NIC's hardware clock with CLOCK_REALTIME. This might be necessary during system initialization, but at runtime, when the PTP clock has already been synchronized to a grand master, a reset of the timestamp settings might result in a clock jump.

This further differs from how drivers like IGB and FEC behave: Those initialize the PTP system time less frequently - on interface up and at probe time, respectively.

We consequently introduce the new function stmmac_init_hwtstamp(), which gets called during ndo_open(). It contains the code snippet moved from stmmac_hwtstamp_set() that manages the time synchronization. Besides, the sub second increment configuration is also moved here since the related values are hardware dependent and do not change during runtime.

Furthermore, the hardware clock must be kept running even when no time stamping mode is selected in order to retain the once synced time basis. That way, time stamping can be enabled again at any time only with the need for compensation of the clock's natural drifting.

Quoted 9 lines

As a side effect, this patch fixes a potential race between SIOCSHWTSTAMP and ptp_clock_info::enable regarding priv->systime_flags. Subsequently, since this variable becomes deprecated by this commit, it should be removed completely in a follow-up patch.

Fixes 92ba6888510c ("stmmac: add the support for PTP hw clock driver")
Fixes cc4c9001ce31 ("net: stmmac: Switch stmmac_hwtimestamp to generic

HW Interface Helpers")

Thanks for the patch, minor nits below.

If you post a v2 please don't wrap fixes tags and no space between those and the other tags.

Also please put the tree in the subject, like [PATCH net 1/2].

Please remember to CC Richard, the PTP maintainer.

Quoted 12 lines
---
 .../net/ethernet/stmicro/stmmac/stmmac_main.c | 121 ++++++++++++------
 1 file changed, 80 insertions(+), 41 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 5b1c12ff98c0..55f5e6cd1cad 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c line 49

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -0
@@ -46,6 +46,13 @@
 #include "dwxgmac2.h"
 #include "hwif.h"
 
+

Spurious new line

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c line 53

Quoted 4 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -0
+/* As long the interface is active, we keep the timestamping HW enabled with
+ * fine resolution and binary rollover. This avoid non-monotonic behavior
+ * when changing timestamp settings at runtime
+ * */

The */ should be on a line of its own.

Quoted 22 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +15 -0
+#define STMMAC_HWTS_ACTIVE (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSCTRLSSR)
+
 #define	STMMAC_ALIGN(x)		ALIGN(ALIGN(x, SMP_CACHE_BYTES), 16)
 #define	TSO_MAX_BUFF_SIZE	(SZ_16K - 1)
 
@@ -791,6 +772,63 @@ static void stmmac_release_ptp(struct stmmac_priv *priv)
 	stmmac_ptp_unregister(priv);
 }
 
+/**
+ * stmmac_init_hwtstamp - init Timestamping Hardware
+ * @priv: driver private structure
+ * Description: Initialize hardware for Timestamping use
+ * This is valid as long as the interface is open and not suspended.
+ * Will be rerun after resume from suspension.
+ */
+static int stmmac_init_hwtstamp(struct stmmac_priv *priv)
+{
+	bool xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;
+	struct timespec64 now;
+	u32 sec_inc = 0;
+	u64 temp = 0;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_release_ptp(struct stmmac_priv *priv) · line 797

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +10 -0
+	u32 value;
+	int ret;
+
+	ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
+	if (ret < 0) {
+		netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret);
+		return ret;
+	}
+
+	if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))

!a && !b reads better IMHO

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_release_ptp(struct stmmac_priv *priv) · line 806

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +9 -0
+		return -EOPNOTSUPP;
+
+	value = STMMAC_HWTS_ACTIVE;
+	stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
+
+	/* program Sub Second Increment reg */
+	stmmac_config_sub_second_increment(priv,
+			priv->ptpaddr, priv->plat->clk_ptp_rate,
+			xmac, &sec_inc);

Now that this code is not indented as much any more please align the continuation lines under the opening bracket.

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -0
+	temp = div_u64(1000000000ULL, sec_inc);
+
+	/* Store sub second increment and flags for later use */
+	priv->sub_second_inc = sec_inc;
+	priv->systime_flags = value;
+
+	/* calculate default added value:
+	 * formula is :
+	 * addend = (2^32)/freq_div_ratio;
+	 * where, freq_div_ratio = 1e9ns/sec_inc
+	 */

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static void stmmac_release_ptp(struct stmmac_priv *priv) · line 827

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +10 -0
+	temp = (u64)(temp << 32);
+	priv->default_addend = div_u64(temp, priv->plat->clk_ptp_rate);
+	stmmac_config_addend(priv, priv->ptpaddr, priv->default_addend);
+
+	/* initialize system time */
+	ktime_get_real_ts64(&now);
+
+	/* lower 32 bits of tv_sec are safe until y2106 */
+	stmmac_init_systime(priv, priv->ptpaddr,
+			(u32)now.tv_sec, now.tv_nsec);

ditto

Quoted 14 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -3
+
+	return 0;
+}
+
 /**
  *  stmmac_mac_flow_ctrl - Configure flow control in all queues
  *  @priv: driver private structure
@@ -2713,15 +2751,17 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
 	stmmac_mmc_setup(priv);
 
 	if (init_ptp) {
-		ret = clk_prepare_enable(priv->plat->clk_ptp_ref);
-		if (ret < 0)
-			netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret);

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) · line 2757

Quoted 10 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +4 -6
-
-		ret = stmmac_init_ptp(priv);
-		if (ret == -EOPNOTSUPP)
-			netdev_warn(priv->dev, "PTP not supported by HW\n");
-		else if (ret)
-			netdev_warn(priv->dev, "PTP init failed\n");
+		ret = stmmac_init_hwtstamp(priv);
+		if (ret) {
+			netdev_warn(priv->dev, "HW Timestamping init failed: %pe\n",
+					ERR_PTR(ret));

why convert to ERR_PTR and use %pe and not just %d?

also continuation misaligned

Quoted 11 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
+		} else {
+			ret = stmmac_init_ptp(priv);
+			if (ret == -EOPNOTSUPP)
+				netdev_warn(priv->dev, "PTP not supported by HW\n");
+			else if (ret)
+				netdev_warn(priv->dev, "PTP init failed\n");
+		}
 	}
 
 	priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_resume(struct device *dev) · line 5333

Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -2
@@ -5290,8 +5330,7 @@ int stmmac_resume(struct device *dev)
 		/* enable the clk previously disabled */
 		clk_prepare_enable(priv->plat->stmmac_clk);
 		clk_prepare_enable(priv->plat->pclk);
-		if (priv->plat->clk_ptp_ref)
-			clk_prepare_enable(priv->plat->clk_ptp_ref);
+		stmmac_init_hwtstamp(priv);

This was optional, now you always init?

Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 		/* reset the phy so that it's ready */
 		if (priv->mii)
 			stmmac_mdio_reset(priv->mii);

base-commit: 3db1a3fa98808aa90f95ec3e0fa2fc7abf28f5c9

#3 lore raw
Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 16 Dec 2020 12:32:38 +0100 Holger Assmann wrote:

As it is, valid SIOCSHWTSTAMP ioctl calls - i.e. enable/disable time stamping or changing filter settings - lead to synchronization of the NIC's hardware clock with CLOCK_REALTIME. This might be necessary during system initialization, but at runtime, when the PTP clock has already been synchronized to a grand master, a reset of the timestamp settings might result in a clock jump.

+1 for keeping the PHC time continuous.

Quoted 1 line

Please remember to CC Richard, the PTP maintainer.

+1 to that, too!

Thanks,
Richard

#4 lore raw
In reply to Jakub Kicinski

Hello,

Quoted 4 lines · Jakub Kicinski

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) · line 2757

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
+			netdev_warn(priv->dev, "HW Timestamping init failed: %pe\n",
+					ERR_PTR(ret));

why convert to ERR_PTR and use %pe and not just %d?

To get a symbolic error name if support is compiled in (note the `e' after %p).

Quoted 12 lines

also continuation misaligned

Quoted 9 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -0
+		} else {
+			ret = stmmac_init_ptp(priv);
+			if (ret == -EOPNOTSUPP)
+				netdev_warn(priv->dev, "PTP not supported by HW\n");
+			else if (ret)
+				netdev_warn(priv->dev, "PTP init failed\n");
+		}
 	}
Quoted 10 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_resume(struct device *dev) · line 5333

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -2
 	priv->eee_tw_timer = STMMAC_DEFAULT_TWT_LS;
@@ -5290,8 +5330,7 @@ int stmmac_resume(struct device *dev)
 		/* enable the clk previously disabled */
 		clk_prepare_enable(priv->plat->stmmac_clk);
 		clk_prepare_enable(priv->plat->pclk);
-		if (priv->plat->clk_ptp_ref)
-			clk_prepare_enable(priv->plat->clk_ptp_ref);
+		stmmac_init_hwtstamp(priv);

This was optional, now you always init?

Indeed, omitting the if condition here will lead to a needless warning on every reset.

Cheers,
Ahmad

Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 		/* reset the phy so that it's ready */
 		if (priv->mii)
 			stmmac_mdio_reset(priv->mii);

base-commit: 3db1a3fa98808aa90f95ec3e0fa2fc7abf28f5c9

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#5 lore raw
Quoted 7 lines · On Thu, 17 Dec 2020 09:25:48 +0100 Ahmad Fatoum wrote:
Quoted 4 lines · Jakub Kicinski

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) · line 2757

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
+			netdev_warn(priv->dev, "HW Timestamping init failed: %pe\n",
+					ERR_PTR(ret));  

why convert to ERR_PTR and use %pe and not just %d?

To get a symbolic error name if support is compiled in (note the `e' after %p).

Cool, GTK. Kind of weird we there is no equivalent int decorator, tho. Do you happen to know why?

#6 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 17 Dec 2020 09:25:48 +0100 Ahmad Fatoum wrote:
Quoted 4 lines · Jakub Kicinski

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) · line 2757

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +2 -0
+			netdev_warn(priv->dev, "HW Timestamping init failed: %pe\n",
+					ERR_PTR(ret));  

why convert to ERR_PTR and use %pe and not just %d?

To get a symbolic error name if support is compiled in (note the `e' after %p).

Cool, GTK. Kind of weird we there is no equivalent int decorator, tho. Do you happen to know why?

New format-specifiers should be using %p<extension>, which is already established, said the reviewers:

https://lore.kernel.org/lkml/[email protected]/

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#7 lore raw
In reply to Jakub Kicinski
Quoted 2 lines · On Thu, 17.12.20 um 02:13 Jakub Kicinski wrote:

Thanks for the patch, minor nits below.

Thanks for the Feedback! I will work it in for my v2.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	if (!(priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp))

!a && !b reads better IMHO

We've chosen this variant because it is already used this way in stmmac_main (e.g. in stmmac_hwtstamp_set(), stmmac_hwtstamp_get(), or stmmac_validate()).

Quoted 9 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c int stmmac_resume(struct device *dev) · line 5333

Quoted 7 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -2
@@ -5290,8 +5330,7 @@ int stmmac_resume(struct device *dev)
  		/* enable the clk previously disabled */
  		clk_prepare_enable(priv->plat->stmmac_clk);
  		clk_prepare_enable(priv->plat->pclk);
-		if (priv->plat->clk_ptp_ref)
-			clk_prepare_enable(priv->plat->clk_ptp_ref);
+		stmmac_init_hwtstamp(priv);

This was optional, now you always init?

This was not intended. Will be fixed in v2 to be optional again.

Regards,
Holger

#8 lore raw
In reply to Holger Assmann
Thank you for the patch! Perhaps something to improve:

Hi Holger,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on 3db1a3fa98808aa90f95ec3e0fa2fc7abf28f5c9]

url:    https://github.com/0day-ci/linux/commits/Holger-Assmann/net-stmmac-retain-PTP-clock-at-hwtstamp_set/20201216-194127
base:    3db1a3fa98808aa90f95ec3e0fa2fc7abf28f5c9
config: arm-randconfig-r021-20201221 (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/303da978c0e8ad80e7577245b7c399f601a29b7a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Holger-Assmann/net-stmmac-retain-PTP-clock-at-hwtstamp_set/20201216-194127 git checkout 303da978c0e8ad80e7577245b7c399f601a29b7a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c: In function 'stmmac_hwtstamp_set':

>> drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:528:7: warning: variable 'xmac' set but not used [-Wunused-but-set-variable]
     528 |  bool xmac;
         |       ^~~~

vim +/xmac +528 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

891434b18ec0a21 Rayagond Kokatanur 2013-03-26  503  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  504  /**
d6228b7cdd6e790 Artem Panfilov     2019-01-20  505   *  stmmac_hwtstamp_set - control hardware timestamping.
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  506   *  @dev: device pointer.
8d45e42babb1c7b LABBE Corentin     2017-02-08  507   *  @ifr: An IOCTL specific structure, that can contain a pointer to
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  508   *  a proprietary structure used to pass information to the driver.
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  509   *  Description:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  510   *  This function configures the MAC to enable/disable both outgoing(TX)
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  511   *  and incoming(RX) packets time stamping based on user input.
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  512   *  Return Value:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  513   *  0 on success and an appropriate -ve integer on failure.
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  514   */
d6228b7cdd6e790 Artem Panfilov     2019-01-20  515  static int stmmac_hwtstamp_set(struct net_device *dev, struct ifreq *ifr)
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  516  {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  517  	struct stmmac_priv *priv = netdev_priv(dev);
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  518  	struct hwtstamp_config config;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  519  	u32 ptp_v2 = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  520  	u32 tstamp_all = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  521  	u32 ptp_over_ipv4_udp = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  522  	u32 ptp_over_ipv6_udp = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  523  	u32 ptp_over_ethernet = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  524  	u32 snap_type_sel = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  525  	u32 ts_master_en = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  526  	u32 ts_event_en = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  527  	u32 value = 0;
7d9e6c5afab6bfb Jose Abreu         2018-08-08 @528  	bool xmac;
7d9e6c5afab6bfb Jose Abreu         2018-08-08  529  
7d9e6c5afab6bfb Jose Abreu         2018-08-08  530  	xmac = priv->plat->has_gmac4 || priv->plat->has_xgmac;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  531  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  532  	if (!(priv->dma_cap.time_stamp || priv->adv_ts)) {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  533  		netdev_alert(priv->dev, "No support for HW time stamping\n");
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  534  		priv->hwts_tx_en = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  535  		priv->hwts_rx_en = 0;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  536  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  537  		return -EOPNOTSUPP;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  538  	}
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  539  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  540  	if (copy_from_user(&config, ifr->ifr_data,
d6228b7cdd6e790 Artem Panfilov     2019-01-20  541  			   sizeof(config)))
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  542  		return -EFAULT;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  543  
38ddc59d65b6d97 LABBE Corentin     2016-11-16  544  	netdev_dbg(priv->dev, "%s config flags:0x%x, tx_type:0x%x, rx_filter:0x%x\n",
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  545  		   __func__, config.flags, config.tx_type, config.rx_filter);
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  546  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  547  	/* reserved for future extensions */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  548  	if (config.flags)
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  549  		return -EINVAL;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  550  
5f3da3281932a79 Ben Hutchings      2013-11-14  551  	if (config.tx_type != HWTSTAMP_TX_OFF &&
5f3da3281932a79 Ben Hutchings      2013-11-14  552  	    config.tx_type != HWTSTAMP_TX_ON)
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  553  		return -ERANGE;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  554  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  555  	if (priv->adv_ts) {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  556  		switch (config.rx_filter) {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  557  		case HWTSTAMP_FILTER_NONE:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  558  			/* time stamp no incoming packet at all */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  559  			config.rx_filter = HWTSTAMP_FILTER_NONE;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  560  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  561  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  562  		case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  563  			/* PTP v1, UDP, any kind of event packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  564  			config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  565  			/* 'xmac' hardware can support Sync, Pdelay_Req and
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  566  			 * Pdelay_resp by setting bit14 and bits17/16 to 01
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  567  			 * This leaves Delay_Req timestamps out.
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  568  			 * Enable all events *and* general purpose message
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  569  			 * timestamping
7d8e249f393a1ac Ilias Apalodimas   2019-02-05  570  			 */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  571  			snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  572  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  573  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  574  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  575  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  576  		case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  577  			/* PTP v1, UDP, Sync packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  578  			config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_SYNC;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  579  			/* take time stamp for SYNC messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  580  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  581  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  582  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  583  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  584  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  585  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  586  		case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  587  			/* PTP v1, UDP, Delay_req packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  588  			config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  589  			/* take time stamp for Delay_Req messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  590  			ts_master_en = PTP_TCR_TSMSTRENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  591  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  592  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  593  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  594  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  595  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  596  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  597  		case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  598  			/* PTP v2, UDP, any kind of event packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  599  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  600  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  601  			/* take time stamp for all event messages */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  602  			snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  603  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  604  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  605  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  606  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  607  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  608  		case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  609  			/* PTP v2, UDP, Sync packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  610  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_SYNC;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  611  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  612  			/* take time stamp for SYNC messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  613  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  614  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  615  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  616  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  617  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  618  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  619  		case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  620  			/* PTP v2, UDP, Delay_req packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  621  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  622  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  623  			/* take time stamp for Delay_Req messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  624  			ts_master_en = PTP_TCR_TSMSTRENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  625  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  626  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  627  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  628  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  629  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  630  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  631  		case HWTSTAMP_FILTER_PTP_V2_EVENT:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  632  			/* PTP v2/802.AS1 any layer, any kind of event packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  633  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  634  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  635  			snap_type_sel = PTP_TCR_SNAPTYPSEL_1;
f2fb6b6275eba9d Fugang Duan        2020-05-25  636  			if (priv->synopsys_id != DWMAC_CORE_5_10)
14f347334bf2320 Jose Abreu         2019-09-30  637  				ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  638  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  639  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  640  			ptp_over_ethernet = PTP_TCR_TSIPENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  641  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  642  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  643  		case HWTSTAMP_FILTER_PTP_V2_SYNC:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  644  			/* PTP v2/802.AS1, any layer, Sync packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  645  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_SYNC;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  646  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  647  			/* take time stamp for SYNC messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  648  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  649  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  650  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  651  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  652  			ptp_over_ethernet = PTP_TCR_TSIPENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  653  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  654  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  655  		case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  656  			/* PTP v2/802.AS1, any layer, Delay_req packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  657  			config.rx_filter = HWTSTAMP_FILTER_PTP_V2_DELAY_REQ;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  658  			ptp_v2 = PTP_TCR_TSVER2ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  659  			/* take time stamp for Delay_Req messages only */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  660  			ts_master_en = PTP_TCR_TSMSTRENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  661  			ts_event_en = PTP_TCR_TSEVNTENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  662  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  663  			ptp_over_ipv4_udp = PTP_TCR_TSIPV4ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  664  			ptp_over_ipv6_udp = PTP_TCR_TSIPV6ENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  665  			ptp_over_ethernet = PTP_TCR_TSIPENA;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  666  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  667  
e3412575488ac24 Miroslav Lichvar   2017-05-19  668  		case HWTSTAMP_FILTER_NTP_ALL:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  669  		case HWTSTAMP_FILTER_ALL:
ceb694997e1b5d4 Giuseppe CAVALLARO 2013-04-08  670  			/* time stamp any incoming packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  671  			config.rx_filter = HWTSTAMP_FILTER_ALL;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  672  			tstamp_all = PTP_TCR_TSENALL;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  673  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  674  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  675  		default:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  676  			return -ERANGE;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  677  		}
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  678  	} else {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  679  		switch (config.rx_filter) {
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  680  		case HWTSTAMP_FILTER_NONE:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  681  			config.rx_filter = HWTSTAMP_FILTER_NONE;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  682  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  683  		default:
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  684  			/* PTP v1, UDP, any kind of event packet */
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  685  			config.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  686  			break;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  687  		}
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  688  	}
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  689  	priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1);
5f3da3281932a79 Ben Hutchings      2013-11-14  690  	priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  691  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  692  	if (!priv->hwts_tx_en && !priv->hwts_rx_en)
303da978c0e8ad8 Holger Assmann     2020-12-16  693  		stmmac_config_hw_tstamping(priv, priv->ptpaddr, STMMAC_HWTS_ACTIVE);
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  694  	else {
303da978c0e8ad8 Holger Assmann     2020-12-16  695  		value = (STMMAC_HWTS_ACTIVE |
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  696  			 tstamp_all | ptp_v2 | ptp_over_ethernet |
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  697  			 ptp_over_ipv6_udp | ptp_over_ipv4_udp | ts_event_en |
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  698  			 ts_master_en | snap_type_sel);
cc4c9001ce31e0c Jose Abreu         2018-04-16  699  		stmmac_config_hw_tstamping(priv, priv->ptpaddr, value);
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  700  		
303da978c0e8ad8 Holger Assmann     2020-12-16  701  		/* Store flags for later use */
9a8a02c9d46dcd4 Jose Abreu         2018-05-31  702  		priv->systime_flags = value;
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  703  	}
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  704  
d6228b7cdd6e790 Artem Panfilov     2019-01-20  705  	memcpy(&priv->tstamp_config, &config, sizeof(config));
d6228b7cdd6e790 Artem Panfilov     2019-01-20  706  
891434b18ec0a21 Rayagond Kokatanur 2013-03-26  707  	return copy_to_user(ifr->ifr_data, &config,
d6228b7cdd6e790 Artem Panfilov     2019-01-20  708  			    sizeof(config)) ? -EFAULT : 0;
d6228b7cdd6e790 Artem Panfilov     2019-01-20  709  }
d6228b7cdd6e790 Artem Panfilov     2019-01-20  710  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org