Skip to contentSkip to conversation

igb: Fix extts capture value format for 82580/i354/i350

PATCH In review Yuezhen Luan 3 participants 6 messages May 31, 2023 – Jun 1, 2023

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

PATCH 1/1 igb: Fix extts capture value format for 82580/i354/i350

82580/i354/i350 features circle-counter-like timestamp registers that are different with newer i210. The EXTTS capture value in AUXTSMPx should be converted from raw circle counter value to timestamp value in resolution of 1 nanosec by the driver.

---
 drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +6 -2
index 58872a4c2..187daa8ef 100644
@@ -6947,6 +6947,7 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
 	struct e1000_hw *hw = &adapter->hw;
 	struct ptp_clock_event event;
 	struct timespec64 ts;
+	unsigned long flags;
 
 	if (pin < 0 || pin >= IGB_N_SDP)
 		return;
@@ -6954,9 +6955,12 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
 	if (hw->mac.type == e1000_82580 ||
 	    hw->mac.type == e1000_i354 ||
 	    hw->mac.type == e1000_i350) {
-		s64 ns = rd32(auxstmpl);
+		u64 ns = rd32(auxstmpl);
 
-		ns += ((s64)(rd32(auxstmph) & 0xFF)) << 32;
+		ns += ((u64)(rd32(auxstmph) & 0xFF)) << 32;
+		spin_lock_irqsave(&adapter->tc, ns);
+		ns = timecounter_cyc2time(&adapter->tc, ns);
+		spin_unlock_irqrestore(&adapter->tc, ns);
 		ts = ns_to_timespec64(ns);
 	} else {
 		ts.tv_nsec = rd32(auxstmpl);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 24 lines · Yuezhen Luan

82580/i354/i350 features circle-counter-like timestamp registers that are different with newer i210. The EXTTS capture value in AUXTSMPx should be converted from raw circle counter value to timestamp value in resolution of 1 nanosec by the driver.

---
 drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +1 -0
index 58872a4c2..187daa8ef 100644
@@ -6947,6 +6947,7 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
 	struct e1000_hw *hw = &adapter->hw;
 	struct ptp_clock_event event;
 	struct timespec64 ts;
+	unsigned long flags;
 
 	if (pin < 0 || pin >= IGB_N_SDP)
 		return;
@@ -6954,9 +6955,12 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
 	if (hw->mac.type == e1000_82580 ||

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter, int tsintr_tt) · line 6963

Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_main.c +5 -2
 	    hw->mac.type == e1000_i354 ||
 	    hw->mac.type == e1000_i350) {
-		s64 ns = rd32(auxstmpl);
+		u64 ns = rd32(auxstmpl);
 
-		ns += ((s64)(rd32(auxstmph) & 0xFF)) << 32;
+		ns += ((u64)(rd32(auxstmph) & 0xFF)) << 32;
+		spin_lock_irqsave(&adapter->tc, ns);
+		ns = timecounter_cyc2time(&adapter->tc, ns);
+		spin_unlock_irqrestore(&adapter->tc, ns);

Hi Yuezhen Luan,

unfortunately this doesn't compile because the arguments to spin_lock_irqsave/spin_unlock_irqrestore are wrong.

Quoted 3 lines
drivers/net/ethernet/intel/igb/igb_main.c +0 -0
 		ts = ns_to_timespec64(ns);
 	} else {
 		ts.tv_nsec = rd32(auxstmpl);
Signature · 1 line
pw-bot: cr
author
#2 lore raw

Dear Simon,

Ah sorry the patch was generated in a different kernel source code dir with the one I tested. it’s a typo, I’ll fix it soon. Apologize for that mistake

Simon Horman <[email protected]>:

Quoted 44 lines · Yuezhen Luan

Review

Quoted 11 lines

82580/i354/i350 features circle-counter-like timestamp registers that are different with newer i210. The EXTTS capture value in AUXTSMPx should be converted from raw circle counter value to timestamp value in resolution of 1 nanosec by the driver.

---
 drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ethernet/intel/igb/igb_main.c

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter,

Quoted 4 lines

index 58872a4c2..187daa8ef 100644

drivers/net/ethernet/intel/igb/igb_main.c +0 -0
@@ -6947,6 +6947,7 @@ static void igb_extts(struct igb_adapter *adapter,

int tsintr_tt)

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter

Quoted 8 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -0
      struct e1000_hw *hw = &adapter->hw;
      struct ptp_clock_event event;
      struct timespec64 ts;
+     unsigned long flags;
 
      if (pin < 0 || pin >= IGB_N_SDP)
              return;
@@ -6954,9 +6955,12 @@ static void igb_extts(struct igb_adapter

*adapter, int tsintr_tt)

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter, int tsintr_tt) · line 6963

Quoted 11 lines
drivers/net/ethernet/intel/igb/igb_main.c +5 -2
      if (hw->mac.type == e1000_82580 ||
          hw->mac.type == e1000_i354 ||
          hw->mac.type == e1000_i350) {
-             s64 ns = rd32(auxstmpl);
+             u64 ns = rd32(auxstmpl);
 
-             ns += ((s64)(rd32(auxstmph) & 0xFF)) << 32;
+             ns += ((u64)(rd32(auxstmph) & 0xFF)) << 32;
+             spin_lock_irqsave(&adapter->tc, ns);
+             ns = timecounter_cyc2time(&adapter->tc, ns);
+             spin_unlock_irqrestore(&adapter->tc, ns);

Hi Yuezhen Luan,

unfortunately this doesn't compile because the arguments to spin_lock_irqsave/spin_unlock_irqrestore are wrong.

Quoted 8 lines

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter, int tsintr_tt) · line 6966

Quoted 3 lines
drivers/net/ethernet/intel/igb/igb_main.c +0 -0
              ts = ns_to_timespec64(ns);
      } else {
              ts.tv_nsec = rd32(auxstmpl);

--
pw-bot: cr

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#3 lore raw
In reply to Yuezhen Luan

Dear Yuezhen,

Thank you very much for your patch.

Am 31.05.23 um 11:08 schrieb Yuezhen Luan:

Quoted 4 lines

82580/i354/i350 features circle-counter-like timestamp registers that are different with newer i210. The EXTTS capture value in AUXTSMPx should be converted from raw circle counter value to timestamp value in resolution of 1 nanosec by the driver.

It’d be great, if you added a paragraph how to reproduce the issue.

Quoted 10 lines
---
  drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +0 -0
index 58872a4c2..187daa8ef 100644

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter, int tsintr_tt) · line 6950

Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +1 -0
@@ -6947,6 +6947,7 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
  	struct e1000_hw *hw = &adapter->hw;
  	struct ptp_clock_event event;
  	struct timespec64 ts;
+	unsigned long flags;

I do not see the variable *flags* being used.

Quoted 8 lines
drivers/net/ethernet/intel/igb/igb_main.c +0 -1
  	if (pin < 0 || pin >= IGB_N_SDP)
  		return;
@@ -6954,9 +6955,12 @@ static void igb_extts(struct igb_adapter *adapter, int tsintr_tt)
  	if (hw->mac.type == e1000_82580 ||
  	    hw->mac.type == e1000_i354 ||
  	    hw->mac.type == e1000_i350) {
-		s64 ns = rd32(auxstmpl);

drivers/net/ethernet/intel/igb/igb_main.c static void igb_extts(struct igb_adapter *adapter, int tsintr_tt) · line 6966

Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_main.c +5 -1
+		u64 ns = rd32(auxstmpl);
 
-		ns += ((s64)(rd32(auxstmph) & 0xFF)) << 32;
+		ns += ((u64)(rd32(auxstmph) & 0xFF)) << 32;
+		spin_lock_irqsave(&adapter->tc, ns);
+		ns = timecounter_cyc2time(&adapter->tc, ns);
+		spin_unlock_irqrestore(&adapter->tc, ns);
  		ts = ns_to_timespec64(ns);
  	} else {
  		ts.tv_nsec = rd32(auxstmpl);

Kind regards,

Paul
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

author
#4 lore raw

Dear Paul,

Quoted 1 line

It’d be great, if you added a paragraph how to reproduce the issue.

I have tested an i350 NIC with a 1PPS signal input to a SDP pin, running 'ts2phc'
program from linuxptp project, and found that the 1PPS timestamps reading out are
raw register value in resolution of 1ns and a maximum range of 2^40 ns, thus about 1099 s.
It was supposed to be in TAI timestamp format.

Sorry I'm new to kernel development, should I make a new patch to add a paragraph
in the commit information?

Quoted 1 line

I do not see the variable *flags* being used.

This patch has a typo, please ignore this one, I have submitted a new one that fixed this.

I have tested the patch on a Ubuntu server 22.04 machine with kernel version 5.19.17, then I generated
the patch in the 'net-queue' development repo. I just handwritten the changes in the dev repo, made a
silly mistake.

Apolotize for that, I'll be more careful next time.

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#5 lore raw

Dear Egg,

Thank you for your reply.

Am 01.06.23 um 07:55 schrieb egg car:

Quoted 11 lines
Quoted 2 lines

It’d be great, if you added a paragraph how to reproduce the issue.

I have tested an i350 NIC with a 1PPS signal input to a SDP pin, running 'ts2phc' program from linuxptp project, and found that the 1PPS timestamps reading out are raw register value in resolution of 1ns and a maximum range of 2^40 ns, thus about 1099 s. It was supposed to be in TAI timestamp format.

Sorry I'm new to kernel development, should I make a new patch to add a paragraph in the commit information?

There is no hard rule about it, but I would appreciate it. In the end,
it’s the maintainers’ decision. You can amend the commit, and then regenerate the patch with git format-patch -1 -v2. Below the --- line you can add a short change-log, what you changed between the patch iterations.

Quoted 4 lines
Quoted 1 line

I do not see the variable *flags* being used.

This patch has a typo, please ignore this one, I have submitted a new one that fixed this.

I have not seen this yet.

Quoted 5 lines

I have tested the patch on a Ubuntu server 22.04 machine with kernel version 5.19.17, then I generated the patch in the 'net-queue' development repo. I just handwritten the changes in the dev repo,
made a silly mistake.

Apolot8ze for that, I'll be more careful next time.

No problem. This has happened to all of us. Congratulations on your first(?) Linux kernel contribution. Glad to have you and I am looking forward to your next improvements.

Kind regards,

Paul
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan