diff --git a/core/hdd/inc/wlan_hdd_main.h b/core/hdd/inc/wlan_hdd_main.h index b593318493..e378194e88 100644 --- a/core/hdd/inc/wlan_hdd_main.h +++ b/core/hdd/inc/wlan_hdd_main.h @@ -1292,6 +1292,7 @@ enum qdisc_filter_status { * @is_virtual_iface: Indicates that netdev is called from virtual interface * @mon_adapter: hdd_adapter of monitor mode. * @set_mac_addr_req_ctx: Set MAC address command request context + * @delta_qtime: delta between host qtime and monotonic time */ struct hdd_adapter { /* Magic cookie for adapter sanity verification. Note that this @@ -1607,6 +1608,7 @@ struct hdd_adapter { #ifdef WLAN_FEATURE_DYNAMIC_MAC_ADDR_UPDATE void *set_mac_addr_req_ctx; #endif + int64_t delta_qtime; }; #define WLAN_HDD_GET_STATION_CTX_PTR(adapter) (&(adapter)->session.station) diff --git a/core/hdd/src/wlan_hdd_tsf.c b/core/hdd/src/wlan_hdd_tsf.c index a5c4bc4ea9..ee35ec8eb6 100644 --- a/core/hdd/src/wlan_hdd_tsf.c +++ b/core/hdd/src/wlan_hdd_tsf.c @@ -1468,6 +1468,7 @@ static enum hdd_tsf_op_result hdd_tsf_sync_init(struct hdd_adapter *adapter) QDF_STATUS ret; struct hdd_context *hddctx; struct net_device *net_dev; + uint64_t host_time, qtime; if (!adapter) return HDD_TSF_OP_FAIL; @@ -1511,6 +1512,14 @@ static enum hdd_tsf_op_result hdd_tsf_sync_init(struct hdd_adapter *adapter) device_create_file(&net_dev->dev, &dev_attr_tsf); hdd_set_th_sync_status(adapter, true); + qtime = qdf_get_log_timestamp(); + host_time = hdd_get_monotonic_host_time(hddctx); + + qtime = qdf_log_timestamp_to_usecs(qtime); + do_div(host_time, NSEC_PER_USEC); + + adapter->delta_qtime = (qtime - host_time) * NSEC_PER_USEC; + return HDD_TSF_OP_SUCC; fail: hdd_set_th_sync_status(adapter, false); @@ -1774,10 +1783,18 @@ enum hdd_tsf_op_result hdd_netbuf_timestamp(qdf_nbuf_t netbuf, int32_t ret = hdd_get_soctime_from_tsf64time(adapter, tsf64_time, &soc_time); if (!ret) { - hwtstamps.hwtstamp = soc_time; - *skb_hwtstamps(netbuf) = hwtstamps; - netbuf->tstamp = ktime_set(0, 0); - return HDD_TSF_OP_SUCC; + /* Adjust delta_qtime to soc_time(Qtime), so that + * System Monotonic time and Qtime are in sync. + */ + if (soc_time > (adapter->delta_qtime)) { + hwtstamps.hwtstamp = + soc_time - (adapter->delta_qtime); + *skb_hwtstamps(netbuf) = hwtstamps; + netbuf->tstamp = ktime_set(0, 0); + return HDD_TSF_OP_SUCC; + } else { + return HDD_TSF_OP_FAIL; + } } }