Skip to contentSkip to conversation

ice: fix PTP stale Tx timestamps cleanup

PATCH Superseded Michal Michalik 3 participants 4 messages Apr 14, 2022 – Apr 19, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: fix PTP stale Tx timestamps cleanup

Read stale PTP Tx timestamps from PHY on cleanup.

After running out of Tx timestamps request handlers hardware (HW) stops reporting finished requests. Function ice_ptp_tx_tstamp_cleanup() used to only cleanup stale handlers in driver and was leaving the hardware registers not read. Not reading stale PTP Tx timestamps prevents next interrupts from arriving and makes timestamping not usable.

Fixes ea9b847cda64 ("ice: enable transmit timestamps for E810 devices")
---
 drivers/net/ethernet/intel/ice/ice_ptp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +7 -2
index a1cd332..826a508 100644
@@ -2287,6 +2287,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
 
 /**
  * ice_ptp_tx_tstamp_cleanup - Cleanup old timestamp requests that got dropped
+ * @hw: pointer to the hw struct
  * @tx: PTP Tx tracker to clean up
  *
  * Loop through the Tx timestamp requests and see if any of them have been
@@ -2295,7 +2296,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
  * timestamp will never be captured. This might happen if the packet gets
  * discarded before it reaches the PHY timestamping block.
  */
-static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
+static void ice_ptp_tx_tstamp_cleanup(struct ice_hw *hw, struct ice_ptp_tx *tx)
 {
 	u8 idx;
 
@@ -2304,11 +2305,15 @@ static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
 
 	for_each_set_bit(idx, tx->in_use, tx->len) {
 		struct sk_buff *skb;
+		u64 raw_tstamp;
 
 		/* Check if this SKB has been waiting for too long */
 		if (time_is_after_jiffies(tx->tstamps[idx].start + 2 * HZ))
 			continue;
 
+		ice_read_phy_tstamp(hw, tx->quad, idx + tx->quad_offset,
+				    &raw_tstamp);
+
 		spin_lock(&tx->lock);
 		skb = tx->tstamps[idx].skb;
 		tx->tstamps[idx].skb = NULL;
@@ -2330,7 +2335,7 @@ static void ice_ptp_periodic_work(struct kthread_work *work)
 
 	ice_ptp_update_cached_phctime(pf);
 
-	ice_ptp_tx_tstamp_cleanup(&pf->ptp.port.tx);
+	ice_ptp_tx_tstamp_cleanup(&pf->hw, &pf->ptp.port.tx);
 
 	/* Run twice a second */
 	kthread_queue_delayed_work(ptp->kworker, &ptp->work,
Signature · 3 lines
2.9.5

base-commit: ad66aede031ecde3028926ebab54adffd19cf59c
#1 lore raw

PATCH 1/1 ice: fix PTP stale Tx timestamps cleanup

Dear Michal,

Thank you for your patch.

Am 14.04.22 um 12:23 schrieb Michal Michalik:

Quoted 5 lines

Read stale PTP Tx timestamps from PHY on cleanup.

After running out of Tx timestamps request handlers hardware (HW) stops reporting finished requests. Function ice_ptp_tx_tstamp_cleanup() used to only cleanup stale handlers in driver and was leaving the hardware

Nit: clean up

Quoted 2 lines

registers not read. Not reading stale PTP Tx timestamps prevents next interrupts from arriving and makes timestamping not usable.

Nit: unusable

Do you have a method, how to force the network device to run out of timestamps request handlers?

Quoted 31 lines
Fixes ea9b847cda64 ("ice: enable transmit timestamps for E810 devices")
---
  drivers/net/ethernet/intel/ice/ice_ptp.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +2 -1
index a1cd332..826a508 100644
@@ -2287,6 +2287,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
 
  /**
   * ice_ptp_tx_tstamp_cleanup - Cleanup old timestamp requests that got dropped
+ * @hw: pointer to the hw struct
   * @tx: PTP Tx tracker to clean up
   *
   * Loop through the Tx timestamp requests and see if any of them have been
@@ -2295,7 +2296,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
   * timestamp will never be captured. This might happen if the packet gets
   * discarded before it reaches the PHY timestamping block.
   */
-static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
+static void ice_ptp_tx_tstamp_cleanup(struct ice_hw *hw, struct ice_ptp_tx *tx)
  {
  	u8 idx;
 
@@ -2304,11 +2305,15 @@ static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
 
  	for_each_set_bit(idx, tx->in_use, tx->len) {

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx) · line 2316

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +4 -0
  		struct sk_buff *skb;
+		u64 raw_tstamp;
 
  		/* Check if this SKB has been waiting for too long */
  		if (time_is_after_jiffies(tx->tstamps[idx].start + 2 * HZ))
  			continue;
 
+		ice_read_phy_tstamp(hw, tx->quad, idx + tx->quad_offset,
+				    &raw_tstamp);
+

Are compilers or code analyzer going to complain, that nothing will be done with raw_tstamp? Is there some attribute, that it?s unused? Maybe also add a comment, this is just to read the value, and it?s not going to be used.

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_periodic_work(struct kthread_work *work) · line 2341

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
  		spin_lock(&tx->lock);
  		skb = tx->tstamps[idx].skb;
  		tx->tstamps[idx].skb = NULL;
@@ -2330,7 +2335,7 @@ static void ice_ptp_periodic_work(struct kthread_work *work)
 
  	ice_ptp_update_cached_phctime(pf);
 
-	ice_ptp_tx_tstamp_cleanup(&pf->ptp.port.tx);
+	ice_ptp_tx_tstamp_cleanup(&pf->hw, &pf->ptp.port.tx);
 
  	/* Run twice a second */
  	kthread_queue_delayed_work(ptp->kworker, &ptp->work,

Kind regards,

Paul

#2 lore raw

PATCH 1/1 ice: fix PTP stale Tx timestamps cleanup

Hi Paul,

Much thanks for your kind review of my first community patch.

Please excuse me for a delay in answering - Monday 18th was a Public Holiday here in Poland.

Quoted 12 lines

-----Original Message-----
From: Paul Menzel <[email protected]>
Sent: Friday, April 15, 2022 6:37 PM
To: Michalik, Michal <[email protected]>
Cc: intel-wired-lan at lists.osuosl.org
Subject: Re: [Intel-wired-lan] [PATCH net v1] ice: fix PTP stale Tx timestamps cleanup

Dear Michal,

Thank you for your patch.

Quoted 8 lines

Am 14.04.22 um 12:23 schrieb Michal Michalik:

Quoted 5 lines

Read stale PTP Tx timestamps from PHY on cleanup.

After running out of Tx timestamps request handlers hardware (HW) stops reporting finished requests. Function ice_ptp_tx_tstamp_cleanup() used to only cleanup stale handlers in driver and was leaving the hardware

Nit: clean up

Good catch - I should have used verb instead of noun. Will fix it in v2.

Quoted 5 lines
Quoted 3 lines

registers not read. Not reading stale PTP Tx timestamps prevents next interrupts from arriving and makes timestamping not usable.

Nit: unusable

Thanks - lesson learned. Will fix it in v2.

Quoted 3 lines

Do you have a method, how to force the network device to run out of timestamps request handlers?

Unlucky - I don't have anything convenient. Both reproducing this bug and proving fix for it is working correctly was done by performing stability tests for multiple hours (using linuxptp project).

Quoted 39 lines
Quoted 39 lines
Fixes ea9b847cda64 ("ice: enable transmit timestamps for E810 devices")
---
  drivers/net/ethernet/intel/ice/ice_ptp.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +3 -1
index a1cd332..826a508 100644
@@ -2287,6 +2287,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
 
  /**
   * ice_ptp_tx_tstamp_cleanup - Cleanup old timestamp requests that got dropped
+ * @hw: pointer to the hw struct
   * @tx: PTP Tx tracker to clean up
   *
   * Loop through the Tx timestamp requests and see if any of them have been
@@ -2295,7 +2296,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
   * timestamp will never be captured. This might happen if the packet gets
   * discarded before it reaches the PHY timestamping block.
   */
-static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
+static void ice_ptp_tx_tstamp_cleanup(struct ice_hw *hw, struct ice_ptp_tx *tx)
  {
  	u8 idx;
 
@@ -2304,11 +2305,15 @@ static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
 
  	for_each_set_bit(idx, tx->in_use, tx->len) {
  		struct sk_buff *skb;
+		u64 raw_tstamp;
 
  		/* Check if this SKB has been waiting for too long */
  		if (time_is_after_jiffies(tx->tstamps[idx].start + 2 * HZ))
  			continue;
 
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx) · line 2316

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +3 -0
+		ice_read_phy_tstamp(hw, tx->quad, idx + tx->quad_offset,
+				    &raw_tstamp);
+

Are compilers or code analyzer going to complain, that nothing will be done with raw_tstamp? Is there some attribute, that it?s unused? Maybe also add a comment, this is just to read the value, and it?s not going to be used.

I haven't noticed any complaints from compiler. This function is used in different places, where all parameters are used. Do you think we should consider changing ice_read_phy_tstamp() so it would be able to accept tstamp equal to NULL and remove this unused raw_tstamp from here? If we leave it as is I will add a comment, according to your suggestion.

Quoted 16 lines

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_periodic_work(struct kthread_work *work) · line 2341

Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
  		spin_lock(&tx->lock);
  		skb = tx->tstamps[idx].skb;
  		tx->tstamps[idx].skb = NULL;
@@ -2330,7 +2335,7 @@ static void ice_ptp_periodic_work(struct kthread_work *work)
 
  	ice_ptp_update_cached_phctime(pf);
 
-	ice_ptp_tx_tstamp_cleanup(&pf->ptp.port.tx);
+	ice_ptp_tx_tstamp_cleanup(&pf->hw, &pf->ptp.port.tx);
 
  	/* Run twice a second */
  	kthread_queue_delayed_work(ptp->kworker, &ptp->work,
Quoted 4 lines

Kind regards,

Paul

Best regards,
Micha? Michalik

#3 lore raw

PATCH 1/1 ice: fix PTP stale Tx timestamps cleanup

Dear Michal,

Am 19.04.22 um 15:27 schrieb Michalik, Michal:

[?]

Quoted 1 line

Much thanks for your kind review of my first community patch.

Hah, I didn?t know. Congratulations, and I hope, it?s the first of many more to come. ;-)

Quoted 2 lines

Please excuse me for a delay in answering - Monday 18th was a Public Holiday here in Poland.

No problem. Luckily email is async, and it?s no problem if replies only come after days/weeks. By the way, Easter Monday is also a public holiday in Germany.

Quoted 3 lines
Quoted 3 lines

-----Original Message-----
From: Paul Menzel <[email protected]>
Sent: Friday, April 15, 2022 6:37 PM

[?]

Quoted 12 lines
Quoted 8 lines

Am 14.04.22 um 12:23 schrieb Michal Michalik:

Quoted 5 lines

Read stale PTP Tx timestamps from PHY on cleanup.

After running out of Tx timestamps request handlers hardware (HW) stops reporting finished requests. Function ice_ptp_tx_tstamp_cleanup() used to only cleanup stale handlers in driver and was leaving the hardware

Nit: clean up

Good catch - I should have used verb instead of noun. Will fix it in v2.

Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

registers not read. Not reading stale PTP Tx timestamps prevents next interrupts from arriving and makes timestamping not usable.

Nit: unusable

Thanks - lesson learned. Will fix it in v2.

Both variants work, unusable is just a little shorter.

Quoted 6 lines
Quoted 2 lines

Do you have a method, how to force the network device to run out of timestamps request handlers?

Unlucky - I don't have anything convenient. Both reproducing this bug and proving fix for it is working correctly was done by performing stability tests for multiple hours (using linuxptp project).

Understood. Maybe just add that as a comment in the commit message.

Quoted 48 lines
Quoted 38 lines
Quoted 38 lines
Fixes ea9b847cda64 ("ice: enable transmit timestamps for E810 devices")
---
   drivers/net/ethernet/intel/ice/ice_ptp.c | 9 +++++++--
   1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +3 -1
index a1cd332..826a508 100644
@@ -2287,6 +2287,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
 
   /**
    * ice_ptp_tx_tstamp_cleanup - Cleanup old timestamp requests that got dropped
+ * @hw: pointer to the hw struct
    * @tx: PTP Tx tracker to clean up
    *
    * Loop through the Tx timestamp requests and see if any of them have been
@@ -2295,7 +2296,7 @@ ice_ptp_init_tx_e810(struct ice_pf *pf, struct ice_ptp_tx *tx)
    * timestamp will never be captured. This might happen if the packet gets
    * discarded before it reaches the PHY timestamping block.
    */
-static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
+static void ice_ptp_tx_tstamp_cleanup(struct ice_hw *hw, struct ice_ptp_tx *tx)
   {
   	u8 idx;
 
@@ -2304,11 +2305,15 @@ static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx)
 
   	for_each_set_bit(idx, tx->in_use, tx->len) {
   		struct sk_buff *skb;
+		u64 raw_tstamp;
 
   		/* Check if this SKB has been waiting for too long */
   		if (time_is_after_jiffies(tx->tstamps[idx].start + 2 * HZ))
   			continue;
 
Quoted 9 lines

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_tx_tstamp_cleanup(struct ice_ptp_tx *tx) · line 2316

Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +3 -0
+		ice_read_phy_tstamp(hw, tx->quad, idx + tx->quad_offset,
+				    &raw_tstamp);
+

Are compilers or code analyzer going to complain, that nothing will be done with raw_tstamp? Is there some attribute, that it?s unused? Maybe also add a comment, this is just to read the value, and it?s not going to be used.

Quoted 6 lines

I haven't noticed any complaints from compiler. This function is used in different places, where all parameters are used. Do you think we should consider changing ice_read_phy_tstamp() so it would be able to accept tstamp equal to NULL and remove this unused raw_tstamp from here? If we leave it as is I will add a comment, according to your suggestion.

I guess the comment is fine, and let?s see if compilers or analyzers are going to complain.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +0 -0
   		spin_lock(&tx->lock);
   		skb = tx->tstamps[idx].skb;
   		tx->tstamps[idx].skb = NULL;
@@ -2330,7 +2335,7 @@ static void ice_ptp_periodic_work(struct kthread_work *work)
 
   	ice_ptp_update_cached_phctime(pf);
 
Quoted 7 lines
Quoted 7 lines

drivers/net/ethernet/intel/ice/ice_ptp.c static void ice_ptp_periodic_work(struct kthread_work *work) · line 2341

Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_ptp.c +1 -1
-	ice_ptp_tx_tstamp_cleanup(&pf->ptp.port.tx);
+	ice_ptp_tx_tstamp_cleanup(&pf->hw, &pf->ptp.port.tx);
 
   	/* Run twice a second */
   	kthread_queue_delayed_work(ptp->kworker, &ptp->work,

Kind regards,

Paul