Lines Matching +full:scaled +full:- +full:sync
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2021 - 2023 Intel Corporation
7 #include "iwl-debug.h"
14 /* The scaled_ppm parameter is ppm (parts per million) with a 16-bit fractional
16 * 2^-16 ppm, and 2^16=65536 is 1 ppm.
28 if (gp2 < mvm->ptp_data.last_gp2 && in iwl_mvm_ptp_update_new_read()
29 mvm->ptp_data.last_gp2 - gp2 < IWL_PTP_WRAP_THRESHOLD_USEC) { in iwl_mvm_ptp_update_new_read()
32 gp2, mvm->ptp_data.last_gp2); in iwl_mvm_ptp_update_new_read()
36 if (gp2 < mvm->ptp_data.last_gp2) { in iwl_mvm_ptp_update_new_read()
37 mvm->ptp_data.wrap_counter++; in iwl_mvm_ptp_update_new_read()
40 mvm->ptp_data.wrap_counter); in iwl_mvm_ptp_update_new_read()
43 mvm->ptp_data.last_gp2 = gp2; in iwl_mvm_ptp_update_new_read()
44 schedule_delayed_work(&mvm->ptp_data.dwork, IWL_PTP_WRAP_TIME); in iwl_mvm_ptp_update_new_read()
49 struct ptp_data *data = &mvm->ptp_data; in iwl_mvm_ptp_get_adj_time()
50 u64 last_gp2_ns = mvm->ptp_data.scale_update_gp2 * NSEC_PER_USEC; in iwl_mvm_ptp_get_adj_time()
58 (unsigned long long)base_time_ns, data->wrap_counter); in iwl_mvm_ptp_get_adj_time()
61 (data->wrap_counter * IWL_PTP_GP2_WRAP * NSEC_PER_USEC); in iwl_mvm_ptp_get_adj_time()
64 * last scale update. Since we don't know how to scale - ignore it. in iwl_mvm_ptp_get_adj_time()
67 IWL_DEBUG_INFO(mvm, "Time before scale update - ignore\n"); in iwl_mvm_ptp_get_adj_time()
71 diff = base_time_ns - last_gp2_ns; in iwl_mvm_ptp_get_adj_time()
74 diff = mul_u64_u64_div_u64(diff, data->scaled_freq, in iwl_mvm_ptp_get_adj_time()
76 IWL_DEBUG_INFO(mvm, "scaled diff ns=%llu\n", (unsigned long long)diff); in iwl_mvm_ptp_get_adj_time()
78 res = data->scale_update_adj_time_ns + data->delta + diff; in iwl_mvm_ptp_get_adj_time()
81 (unsigned long long)base_time_ns, (long long)data->delta, in iwl_mvm_ptp_get_adj_time()
112 return -EIO; in iwl_mvm_get_crosstimestamp_fw()
115 resp = (void *)pkt->data; in iwl_mvm_get_crosstimestamp_fw()
117 gp2_10ns = (u64)le32_to_cpu(resp->gp2_timestamp_hi) << 32 | in iwl_mvm_get_crosstimestamp_fw()
118 le32_to_cpu(resp->gp2_timestamp_lo); in iwl_mvm_get_crosstimestamp_fw()
121 *sys_time = (u64)le32_to_cpu(resp->platform_timestamp_hi) << 32 | in iwl_mvm_get_crosstimestamp_fw()
122 le32_to_cpu(resp->platform_timestamp_lo); in iwl_mvm_get_crosstimestamp_fw()
138 new_diff = tmp_sys_time - ((u64)tmp_gp2 * NSEC_PER_USEC); in iwl_mvm_phc_get_crosstimestamp_loop()
165 if (!mvm->ptp_data.ptp_clock) { in iwl_mvm_phc_get_crosstimestamp()
167 return -ENODEV; in iwl_mvm_phc_get_crosstimestamp()
170 mutex_lock(&mvm->mutex); in iwl_mvm_phc_get_crosstimestamp()
171 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SYNCED_TIME)) { in iwl_mvm_phc_get_crosstimestamp()
182 IWL_INFO(mvm, "Got Sync Time: GP2:%u, last_GP2: %u, GP2_ns: %lld, sys_time: %lld\n", in iwl_mvm_phc_get_crosstimestamp()
183 gp2, mvm->ptp_data.last_gp2, gp2_ns, (s64)sys_time); in iwl_mvm_phc_get_crosstimestamp()
186 xtstamp->device = (ktime_t)gp2_ns; in iwl_mvm_phc_get_crosstimestamp()
187 xtstamp->sys_realtime = sys_time; in iwl_mvm_phc_get_crosstimestamp()
190 mutex_unlock(&mvm->mutex); in iwl_mvm_phc_get_crosstimestamp()
200 mutex_lock(&mvm->mutex); in iwl_mvm_ptp_work()
203 mutex_unlock(&mvm->mutex); in iwl_mvm_ptp_work()
214 mutex_lock(&mvm->mutex); in iwl_mvm_ptp_gettime()
217 mutex_unlock(&mvm->mutex); in iwl_mvm_ptp_gettime()
230 mutex_lock(&mvm->mutex); in iwl_mvm_ptp_adjtime()
231 data->delta += delta; in iwl_mvm_ptp_adjtime()
233 (long long)data->delta); in iwl_mvm_ptp_adjtime()
234 mutex_unlock(&mvm->mutex); in iwl_mvm_ptp_adjtime()
242 struct ptp_data *data = &mvm->ptp_data; in iwl_mvm_ptp_adjfine()
245 mutex_lock(&mvm->mutex); in iwl_mvm_ptp_adjfine()
248 * data->scale_update_gp2 or data->scaled_freq since in iwl_mvm_ptp_adjfine()
252 data->scale_update_adj_time_ns = in iwl_mvm_ptp_adjfine()
254 data->scale_update_gp2 = gp2; in iwl_mvm_ptp_adjfine()
255 data->wrap_counter = 0; in iwl_mvm_ptp_adjfine()
256 data->delta = 0; in iwl_mvm_ptp_adjfine()
258 data->scaled_freq = SCALE_FACTOR + scaled_ppm; in iwl_mvm_ptp_adjfine()
260 scaled_ppm, (unsigned long long)data->scaled_freq); in iwl_mvm_ptp_adjfine()
262 mutex_unlock(&mvm->mutex); in iwl_mvm_ptp_adjfine()
266 /* iwl_mvm_ptp_init - initialize PTP for devices which support it.
274 if (WARN_ON(mvm->ptp_data.ptp_clock)) in iwl_mvm_ptp_init()
277 mvm->ptp_data.ptp_clock_info.owner = THIS_MODULE; in iwl_mvm_ptp_init()
278 mvm->ptp_data.ptp_clock_info.max_adj = 0x7fffffff; in iwl_mvm_ptp_init()
279 mvm->ptp_data.ptp_clock_info.getcrosststamp = in iwl_mvm_ptp_init()
281 mvm->ptp_data.ptp_clock_info.adjfine = iwl_mvm_ptp_adjfine; in iwl_mvm_ptp_init()
282 mvm->ptp_data.ptp_clock_info.adjtime = iwl_mvm_ptp_adjtime; in iwl_mvm_ptp_init()
283 mvm->ptp_data.ptp_clock_info.gettime64 = iwl_mvm_ptp_gettime; in iwl_mvm_ptp_init()
284 mvm->ptp_data.scaled_freq = SCALE_FACTOR; in iwl_mvm_ptp_init()
287 snprintf(mvm->ptp_data.ptp_clock_info.name, in iwl_mvm_ptp_init()
288 sizeof(mvm->ptp_data.ptp_clock_info.name), in iwl_mvm_ptp_init()
289 "%s", "iwlwifi-PTP"); in iwl_mvm_ptp_init()
291 INIT_DELAYED_WORK(&mvm->ptp_data.dwork, iwl_mvm_ptp_work); in iwl_mvm_ptp_init()
293 mvm->ptp_data.ptp_clock = in iwl_mvm_ptp_init()
294 ptp_clock_register(&mvm->ptp_data.ptp_clock_info, mvm->dev); in iwl_mvm_ptp_init()
296 if (IS_ERR(mvm->ptp_data.ptp_clock)) { in iwl_mvm_ptp_init()
298 PTR_ERR(mvm->ptp_data.ptp_clock)); in iwl_mvm_ptp_init()
299 mvm->ptp_data.ptp_clock = NULL; in iwl_mvm_ptp_init()
300 } else if (mvm->ptp_data.ptp_clock) { in iwl_mvm_ptp_init()
302 mvm->ptp_data.ptp_clock_info.name, in iwl_mvm_ptp_init()
303 ptp_clock_index(mvm->ptp_data.ptp_clock)); in iwl_mvm_ptp_init()
307 /* iwl_mvm_ptp_remove - disable PTP device.
314 if (mvm->ptp_data.ptp_clock) { in iwl_mvm_ptp_remove()
316 mvm->ptp_data.ptp_clock_info.name, in iwl_mvm_ptp_remove()
317 ptp_clock_index(mvm->ptp_data.ptp_clock)); in iwl_mvm_ptp_remove()
319 ptp_clock_unregister(mvm->ptp_data.ptp_clock); in iwl_mvm_ptp_remove()
320 mvm->ptp_data.ptp_clock = NULL; in iwl_mvm_ptp_remove()
321 memset(&mvm->ptp_data.ptp_clock_info, 0, in iwl_mvm_ptp_remove()
322 sizeof(mvm->ptp_data.ptp_clock_info)); in iwl_mvm_ptp_remove()
323 mvm->ptp_data.last_gp2 = 0; in iwl_mvm_ptp_remove()
324 cancel_delayed_work_sync(&mvm->ptp_data.dwork); in iwl_mvm_ptp_remove()