> -----Original Message-----
> From: Jacob Keller <[email protected]>
> Sent: Thursday, November 19, 2026 1:31 AM
> To: Intel Wired LAN <[email protected]>; Nguyen, Anthony
> L <[email protected]>; Kitszel, Przemyslaw
> <[email protected]>; Korba, Przemyslaw
> <[email protected]>; Nitka, Grzegorz
> <[email protected]>; Temerkhanov, Sergey
> <[email protected]>; Machnikowski, Maciej
> <[email protected]>; Kubalewski, Arkadiusz
> <[email protected]>; Keller, Jacob E
> <[email protected]>
> Subject: [PATCH iwl-next v4 1/4] ice: fix computation of ETF timestamps
> for E830
> 
> When Earliest TxTime First offload is enabled, the ice_tx_map() function
> computes the appropriate timestamps for the timestamp ring used to set
> the
> transmit times for each packet.
> 
> It computes this by converting the skb->tstamp into a timespec and then
> taking the sub-second portion from tv_nsec and dividing it by the
> timestamp
> resolution. This value is then inserted into the timestamp descriptor
> using
> ice_build_tstamp_desc().
> 
> At first glance this may seem reasonable. After all, the Tx timestamp
> descriptor field has a mask defined by ICE_TXTIME_STAMP_M which is
> GENMASK(31,13). This is a 19-bit wide field. With a unit size of 128
> nanoseconds, the maximum representable time is only ~67 milliseconds,
> far
> below the size of the tv_nsec field (just shy of one second).
> 
> The E830 device time is represented as a single 64-bit nanosecond value
> as
> seen by ice_ptp_read_src_clk_reg() using a simple rd64 on the
> GLTSYN_TIME_L
> register.
> 
> According to the data sheet, the hardware uses the following flow to
> determine when to transmit the next packet in the paced queue:
> 
>   half_window = window_size / 2
>   if (ts <= timer) {
>     if (timer - ts < half_window) {
>       // timestamp expired
>       pass
>     } else {
>       // wait before sending
>       stall
>     }
>   } else {
>     // Handle possible rollover case
>     if (ts - timer < half_window) {
>       // wait before sending
>       stall
>     } else {
>       // timestamp expired
>       pass
>     }
>   }
> 
> Here, window_size is the maximum value that fix in the 19 bit sized
> timestamp field, ts is the next packet timestamp waiting in the queue,
> and
> timer is the 19 bits of the GLTSYN_TIME MAC timer. The configured
> timestamp
> "resolution" determines at which bit position to capture from the
> GLTSYN_TIME registers. This logic does not perform any computation to
> divide out seconds or to handle anything like a timespec. The timestamp
> and
> timer values are compared directly with logic to account for handling
> rollover.
> 
> Because of the faulty logic, all of the timestamps computed and placed
> in
> the ring will result in the transmit time not matching the desired time
> per
> the skb. Consider a timestamp exactly on a second boundary. The computed
> timestamp will be 0, while the actual value should be (1,000,000,000 /
> 128)
> mod 2^19 or 472,468 (0x73594).
> 
> Fix this by directly converting the ktime to nanoseconds rather than
> converting to a timespec64.
> 
> Fixes: ccde82e90946 ("ice: add E830 Earliest TxTime First Offload
> support")
> Signed-off-by: Jacob Keller <[email protected]>
> ---
>  drivers/net/ethernet/intel/ice/ice_txrx.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ice/ice_txrx.c
> b/drivers/net/ethernet/intel/ice/ice_txrx.c
> index 9331b0113937..f34b39b891a7 100644
> --- a/drivers/net/ethernet/intel/ice/ice_txrx.c
> +++ b/drivers/net/ethernet/intel/ice/ice_txrx.c
> @@ -1518,10 +1518,9 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct
> ice_tx_buf *first,
> 
>       if (ice_is_txtime_cfg(tx_ring)) {
>               struct ice_tstamp_ring *tstamp_ring;
> -             u32 tstamp_count, j;
>               struct ice_ts_desc *ts_desc;
> -             struct timespec64 ts;
> -             u32 tstamp;
> +             u32 tstamp_count, j;
> +             u64 tstamp;
> 
>               smp_rmb();      /* order flag read before pointer read */
>               tstamp_ring = READ_ONCE(tx_ring->tstamp_ring);
> @@ -1531,8 +1530,8 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct
> ice_tx_buf *first,
>               tstamp_count = tstamp_ring->count;
>               j = tstamp_ring->next_to_use;
> 
> -             ts = ktime_to_timespec64(first->skb->tstamp);
> -             tstamp = ts.tv_nsec >> ICE_TXTIME_CTX_RESOLUTION_128NS;
> +             tstamp = ktime_to_ns(first->skb->tstamp);
> +             tstamp >>= ICE_TXTIME_CTX_RESOLUTION_128NS;
> 
>               ts_desc = ICE_TS_DESC(tstamp_ring, j);
>               ts_desc->tx_desc_idx_tstamp = ice_build_tstamp_desc(i,
> tstamp);
> 
> --
> 2.56.0.215.g47fdf2208c5b

Reviewed-by: Aleksandr Loktionov <[email protected]>

Reply via email to