netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350
@ 2023-06-01  7:00 Yuezhen Luan
  2023-06-01 17:05 ` Keller, Jacob E
  0 siblings, 1 reply; 4+ messages in thread
From: Yuezhen Luan @ 2023-06-01  7:00 UTC (permalink / raw)
  To: jesse.brandeburg, anthony.l.nguyen, davem, edumazet, kuba, pabeni
  Cc: intel-wired-lan, netdev, linux-kernel, jacob.e.keller,
	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.

This issue can be reproduced on i350 nics, connecting an 1PPS
signal to a SDP pin, and run 'ts2phc' command to read external
1PPS timestamp value. On i210 this works fine, but on i350 the
extts is not correctly converted.

The i350/i354/82580's SYSTIM and other timestamp registers are
40bit counters, presenting time range of 2^40 ns, that means these
registers overflows every about 1099s. This causes all these regs
can't be used directly in contrast to the newer i210/i211s.

The igb driver needs to convert these raw register values to
valid time stamp format by using kernel timecounter apis for i350s
families. Here the igb_extts() just forgot to do the convert.

Signed-off-by: Yuezhen Luan <eggcar.luan@gmail.com>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 58872a4c2..bb3db387d 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -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->tmreg_lock, flags);
+		ns = timecounter_cyc2time(&adapter->tc, ns);
+		spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
 		ts = ns_to_timespec64(ns);
 	} else {
 		ts.tv_nsec = rd32(auxstmpl);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350
  2023-06-01  7:00 [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350 Yuezhen Luan
@ 2023-06-01 17:05 ` Keller, Jacob E
  2023-06-01 20:45   ` Tony Nguyen
  0 siblings, 1 reply; 4+ messages in thread
From: Keller, Jacob E @ 2023-06-01 17:05 UTC (permalink / raw)
  To: Yuezhen Luan, Brandeburg, Jesse, Nguyen, Anthony L,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
  Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org



> -----Original Message-----
> From: Yuezhen Luan <eggcar.luan@gmail.com>
> Sent: Thursday, June 1, 2023 12:01 AM
> To: Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
> <anthony.l.nguyen@intel.com>; davem@davemloft.net;
> edumazet@google.com; kuba@kernel.org; pabeni@redhat.com
> Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org; Keller, Jacob E <jacob.e.keller@intel.com>; Yuezhen
> Luan <eggcar.luan@gmail.com>
> Subject: [PATCH v2] 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.
> 
> This issue can be reproduced on i350 nics, connecting an 1PPS
> signal to a SDP pin, and run 'ts2phc' command to read external
> 1PPS timestamp value. On i210 this works fine, but on i350 the
> extts is not correctly converted.
> 
> The i350/i354/82580's SYSTIM and other timestamp registers are
> 40bit counters, presenting time range of 2^40 ns, that means these
> registers overflows every about 1099s. This causes all these regs
> can't be used directly in contrast to the newer i210/i211s.
> 
> The igb driver needs to convert these raw register values to
> valid time stamp format by using kernel timecounter apis for i350s
> families. Here the igb_extts() just forgot to do the convert.
> 
> Signed-off-by: Yuezhen Luan <eggcar.luan@gmail.com>

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>	

Thanks for fixing this!

@Nguyen, Anthony L
I think this is a worthy net fix.

> ---
>  drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/igb/igb_main.c
> b/drivers/net/ethernet/intel/igb/igb_main.c
> index 58872a4c2..bb3db387d 100644
> --- a/drivers/net/ethernet/intel/igb/igb_main.c
> +++ b/drivers/net/ethernet/intel/igb/igb_main.c
> @@ -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->tmreg_lock, flags);
> +		ns = timecounter_cyc2time(&adapter->tc, ns);
> +		spin_unlock_irqrestore(&adapter->tmreg_lock, flags);
>  		ts = ns_to_timespec64(ns);
>  	} else {
>  		ts.tv_nsec = rd32(auxstmpl);
> --
> 2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350
  2023-06-01 17:05 ` Keller, Jacob E
@ 2023-06-01 20:45   ` Tony Nguyen
  2023-06-02  6:28     ` egg car
  0 siblings, 1 reply; 4+ messages in thread
From: Tony Nguyen @ 2023-06-01 20:45 UTC (permalink / raw)
  To: Keller, Jacob E, Yuezhen Luan, Brandeburg, Jesse,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
  Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

On 6/1/2023 10:05 AM, Keller, Jacob E wrote:
> 
> 
>> -----Original Message-----
>> From: Yuezhen Luan <eggcar.luan@gmail.com>
>> Sent: Thursday, June 1, 2023 12:01 AM
>> To: Brandeburg, Jesse <jesse.brandeburg@intel.com>; Nguyen, Anthony L
>> <anthony.l.nguyen@intel.com>; davem@davemloft.net;
>> edumazet@google.com; kuba@kernel.org; pabeni@redhat.com
>> Cc: intel-wired-lan@lists.osuosl.org; netdev@vger.kernel.org; linux-
>> kernel@vger.kernel.org; Keller, Jacob E <jacob.e.keller@intel.com>; Yuezhen
>> Luan <eggcar.luan@gmail.com>
>> Subject: [PATCH v2] 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.
>>
>> This issue can be reproduced on i350 nics, connecting an 1PPS
>> signal to a SDP pin, and run 'ts2phc' command to read external
>> 1PPS timestamp value. On i210 this works fine, but on i350 the
>> extts is not correctly converted.
>>
>> The i350/i354/82580's SYSTIM and other timestamp registers are
>> 40bit counters, presenting time range of 2^40 ns, that means these
>> registers overflows every about 1099s. This causes all these regs
>> can't be used directly in contrast to the newer i210/i211s.
>>
>> The igb driver needs to convert these raw register values to
>> valid time stamp format by using kernel timecounter apis for i350s
>> families. Here the igb_extts() just forgot to do the convert.
>>
>> Signed-off-by: Yuezhen Luan <eggcar.luan@gmail.com>
> 
> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>	

Thanks for reviewing Jake.

> Thanks for fixing this!
> 
> @Nguyen, Anthony L
> I think this is a worthy net fix.

Hi Yuezhen,

Could you include a Fixes: so that we can route this through net.

You should also add a target tree for your patch (net or net-next).
Here's some useful intro information for netdev [1].

Thanks,
Tony

[1] 
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#netdev-faq 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350
  2023-06-01 20:45   ` Tony Nguyen
@ 2023-06-02  6:28     ` egg car
  0 siblings, 0 replies; 4+ messages in thread
From: egg car @ 2023-06-02  6:28 UTC (permalink / raw)
  To: Tony Nguyen
  Cc: Keller, Jacob E, Brandeburg, Jesse, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

Dear Tony and Jacob,

Thanks for the review, I'll optimize the patch soon.

Regards,
Yuezhen Luan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-02  6:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-01  7:00 [PATCH v2] igb: Fix extts capture value format for 82580/i354/i350 Yuezhen Luan
2023-06-01 17:05 ` Keller, Jacob E
2023-06-01 20:45   ` Tony Nguyen
2023-06-02  6:28     ` egg car

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).