Skip to content

Commit 37e738b

Browse files
kolacinskikarolanguy11
authored andcommitted
ice: Don't put stale timestamps in the skb
The driver has to check if it does not accidentally put the timestamp in the SKB before previous timestamp gets overwritten. Timestamp values in the PHY are read only and do not get cleared except at hardware reset or when a new timestamp value is captured. The cached_tstamp field is used to detect the case where a new timestamp has not yet been captured, ensuring that we avoid sending stale timestamp data to the stack. Fixes: ea9b847 ("ice: enable transmit timestamps for E810 devices") Signed-off-by: Karol Kolacinski <[email protected]> Tested-by: Gurucharan G <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 0013881 commit 37e738b

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

drivers/net/ethernet/intel/ice/ice_ptp.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,19 +1540,16 @@ static void ice_ptp_tx_tstamp_work(struct kthread_work *work)
15401540
if (err)
15411541
continue;
15421542

1543-
/* Check if the timestamp is valid */
1544-
if (!(raw_tstamp & ICE_PTP_TS_VALID))
1543+
/* Check if the timestamp is invalid or stale */
1544+
if (!(raw_tstamp & ICE_PTP_TS_VALID) ||
1545+
raw_tstamp == tx->tstamps[idx].cached_tstamp)
15451546
continue;
15461547

1547-
/* clear the timestamp register, so that it won't show valid
1548-
* again when re-used.
1549-
*/
1550-
ice_clear_phy_tstamp(hw, tx->quad, phy_idx);
1551-
15521548
/* The timestamp is valid, so we'll go ahead and clear this
15531549
* index and then send the timestamp up to the stack.
15541550
*/
15551551
spin_lock(&tx->lock);
1552+
tx->tstamps[idx].cached_tstamp = raw_tstamp;
15561553
clear_bit(idx, tx->in_use);
15571554
skb = tx->tstamps[idx].skb;
15581555
tx->tstamps[idx].skb = NULL;

drivers/net/ethernet/intel/ice/ice_ptp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ struct ice_perout_channel {
5555
* struct ice_tx_tstamp - Tracking for a single Tx timestamp
5656
* @skb: pointer to the SKB for this timestamp request
5757
* @start: jiffies when the timestamp was first requested
58+
* @cached_tstamp: last read timestamp
5859
*
5960
* This structure tracks a single timestamp request. The SKB pointer is
6061
* provided when initiating a request. The start time is used to ensure that
6162
* we discard old requests that were not fulfilled within a 2 second time
6263
* window.
64+
* Timestamp values in the PHY are read only and do not get cleared except at
65+
* hardware reset or when a new timestamp value is captured. The cached_tstamp
66+
* field is used to detect the case where a new timestamp has not yet been
67+
* captured, ensuring that we avoid sending stale timestamp data to the stack.
6368
*/
6469
struct ice_tx_tstamp {
6570
struct sk_buff *skb;
6671
unsigned long start;
72+
u64 cached_tstamp;
6773
};
6874

6975
/**

0 commit comments

Comments
 (0)