Skip to contentSkip to conversation

net: mvpp2: tai: warn once if we fail to update our timestamp

PATCH Superseded Russell King 3 participants 3 messages Dec 11, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: mvpp2: tai: warn once if we fail to update our timestamp

The hardware timestamps for packets contain a truncated seconds field, only containing two bits of seconds. In order to provide the full number of seconds, we need to keep track of the full hardware clock by reading it every two seconds.

However, if we fail to read the clock, we silently ignore the error. Print a warning indicating that the PP2 TAI clock timestamps have become unreliable.

--
v2: correct dev_warn_once() indentation

---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +4 -1
index 95862aff49f1..6b60beb1f3ed 100644
@@ -54,6 +54,7 @@
 #define TCSR_CAPTURE_0_VALID		BIT(0)
 
 struct mvpp2_tai {
+	struct device *dev;
 	struct ptp_clock_info caps;
 	struct ptp_clock *ptp_clock;
 	void __iomem *base;
@@ -303,7 +304,8 @@ static long mvpp22_tai_aux_work(struct ptp_clock_info *ptp)
 {
 	struct mvpp2_tai *tai = ptp_to_tai(ptp);
 
-	mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL);
+	if (mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL) < 0)
+		dev_warn_once(tai->dev, "PTP timestamps are unreliable");
 
 	return msecs_to_jiffies(2000);
 }
@@ -401,6 +403,7 @@ int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv)
 
 	spin_lock_init(&tai->lock);
 
+	tai->dev = dev;
 	tai->base = priv->iface_base;
 
 	/* The step size consists of three registers - a 16-bit nanosecond step
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 29 lines · Russell King

The hardware timestamps for packets contain a truncated seconds field, only containing two bits of seconds. In order to provide the full number of seconds, we need to keep track of the full hardware clock by reading it every two seconds.

However, if we fail to read the clock, we silently ignore the error. Print a warning indicating that the PP2 TAI clock timestamps have become unreliable.

--
v2: correct dev_warn_once() indentation

---
  drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +1 -0
index 95862aff49f1..6b60beb1f3ed 100644
@@ -54,6 +54,7 @@
  #define TCSR_CAPTURE_0_VALID		BIT(0)
 
  struct mvpp2_tai {
+	struct device *dev;
  	struct ptp_clock_info caps;
  	struct ptp_clock *ptp_clock;
  	void __iomem *base;

drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c static long mvpp22_tai_aux_work(struct ptp_clock_info *ptp) · line 308

Quoted 6 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +2 -1
@@ -303,7 +304,8 @@ static long mvpp22_tai_aux_work(struct ptp_clock_info *ptp)
  {
  	struct mvpp2_tai *tai = ptp_to_tai(ptp);
 
-	mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL);
+	if (mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL) < 0)
+		dev_warn_once(tai->dev, "PTP timestamps are unreliable");

Only small nitpick/question - shouldn't text end with '\n'? I see in the code that most of calls of dev_warn_once has '\n' at the end.

drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv) · line 409

Quoted 11 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +1 -0
  	return msecs_to_jiffies(2000);
  }
@@ -401,6 +403,7 @@ int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv)
 
  	spin_lock_init(&tai->lock);
 
+	tai->dev = dev;
  	tai->base = priv->iface_base;
 
  	/* The step size consists of three registers - a 16-bit nanosecond step

Nevertheless the code itself looks good to me, nice improvement.

#2 lore raw
Quoted 29 lines · Mateusz Polchlopek
Quoted 28 lines · Russell King

The hardware timestamps for packets contain a truncated seconds field, only containing two bits of seconds. In order to provide the full number of seconds, we need to keep track of the full hardware clock by reading it every two seconds.

However, if we fail to read the clock, we silently ignore the error. Print a warning indicating that the PP2 TAI clock timestamps have become unreliable.

--
v2: correct dev_warn_once() indentation

---
  drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +1 -0
index 95862aff49f1..6b60beb1f3ed 100644
@@ -54,6 +54,7 @@
  #define TCSR_CAPTURE_0_VALID		BIT(0)
  struct mvpp2_tai {
+	struct device *dev;
  	struct ptp_clock_info caps;
  	struct ptp_clock *ptp_clock;
  	void __iomem *base;
@@ -303,7 +304,8 @@ static long mvpp22_tai_aux_work(struct ptp_clock_info *ptp)
Quoted 8 lines

drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c static long mvpp22_tai_aux_work(struct ptp_clock_info *ptp) · line 308

Quoted 5 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c +2 -1
  {
  	struct mvpp2_tai *tai = ptp_to_tai(ptp);
-	mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL);
+	if (mvpp22_tai_gettimex64(ptp, &tai->stamp, NULL) < 0)
+		dev_warn_once(tai->dev, "PTP timestamps are unreliable");

Only small nitpick/question - shouldn't text end with '\n'? I see in the code that most of calls of dev_warn_once has '\n' at the end.

Yes, thanks for spotting.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!