From: Zhan Xusheng Same problem as the mvm driver, in three places. A GP2 timestamp is a u32 in microseconds and NSEC_PER_USEC is 1000L, so on 32-bit u64 scale_time_gp2_ns = mld->ptp_data.scale_update_gp2 * NSEC_PER_USEC; iwl_mld_ptp_get_adj_time(mld, gp2 * NSEC_PER_USEC); iwl_mld_ptp_get_adj_time(mld, phy_data->gp2_on_air_rise * NSEC_PER_USEC); are evaluated in 32 bits and truncate for any GP2 value above 4.295 s. The last one matters most. iwl_mld_ptp_get_adj_time() passes its argument back to iwl_mld_ptp_update_new_read() in microseconds, which treats a backwards step of at least IWL_PTP_WRAP_THRESHOLD_USEC as a GP2 wraparound and bumps wrap_counter. A gp2 of 10 s truncates to a 32-bit product of 1410065408 ns, i.e. 1410065 us, an 8589935 us step back, so the 5000 us threshold is passed and a wraparound is recorded. Each spurious wraparound adds IWL_PTP_GP2_WRAP microseconds, about 71.6 minutes, to every later timestamp, and the error accumulates. iwl_mld_ptp_gettime() and iwl_mld_phc_get_crosstimestamp() in ptp.c already cast to u64 before multiplying. Do the same in the three remaining places. Signed-off-by: Zhan Xusheng Fixes: d1e879ec600f ("wifi: iwlwifi: add iwlmld sub-driver") --- drivers/net/wireless/intel/iwlwifi/mld/ptp.c | 5 +++-- drivers/net/wireless/intel/iwlwifi/mld/rx.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/mld/ptp.c b/drivers/net/wireless/intel/iwlwifi/mld/ptp.c index 1ac85d6ce1d79..41ba49f525845 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/ptp.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/ptp.c @@ -59,7 +59,8 @@ static void iwl_mld_ptp_update_new_read(struct iwl_mld *mld, u32 gp2) u64 iwl_mld_ptp_get_adj_time(struct iwl_mld *mld, u64 base_time_ns) { struct ptp_data *data = &mld->ptp_data; - u64 scale_time_gp2_ns = mld->ptp_data.scale_update_gp2 * NSEC_PER_USEC; + u64 scale_time_gp2_ns = (u64)mld->ptp_data.scale_update_gp2 * + NSEC_PER_USEC; u64 res; u64 diff; s64 scaled_diff; @@ -159,7 +160,7 @@ static int iwl_mld_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm) spin_lock_bh(&data->lock); data->scale_update_adj_time_ns = - iwl_mld_ptp_get_adj_time(mld, gp2 * NSEC_PER_USEC); + iwl_mld_ptp_get_adj_time(mld, (u64)gp2 * NSEC_PER_USEC); data->scale_update_gp2 = gp2; /* scale_update_adj_time_ns now relects the configured delta, the diff --git a/drivers/net/wireless/intel/iwlwifi/mld/rx.c b/drivers/net/wireless/intel/iwlwifi/mld/rx.c index 269439d789f46..33c8cfa95962e 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/rx.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/rx.c @@ -1526,7 +1526,7 @@ static void iwl_mld_rx_fill_status(struct iwl_mld *mld, int link_id, if (mld->monitor.ptp_time) { u64 adj_time = iwl_mld_ptp_get_adj_time(mld, - phy_data->gp2_on_air_rise * + (u64)phy_data->gp2_on_air_rise * NSEC_PER_USEC); rx_status->mactime = div64_u64(adj_time, NSEC_PER_USEC); -- 2.43.0