Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 1 | /* |
Manikandan Mohan | 0faf628 | 2019-01-14 18:00:04 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved. |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 3 | * |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all |
| 7 | * copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 10 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 11 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 12 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 15 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 16 | * PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 19 | /** |
| 20 | * wlan_hdd_tsf.c - WLAN Host Device Driver tsf related implementation |
| 21 | */ |
| 22 | |
Dustin Brown | a09acf4 | 2018-11-08 12:32:26 +0530 | [diff] [blame] | 23 | #include "osif_sync.h" |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 24 | #include "wlan_hdd_main.h" |
Jeff Johnson | dde3449 | 2016-10-05 16:28:04 -0700 | [diff] [blame] | 25 | #include "wlan_hdd_tsf.h" |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 26 | #include "wma_api.h" |
Sourav Mohapatra | 0f3b857 | 2018-09-12 10:03:51 +0530 | [diff] [blame] | 27 | #include "wlan_fwol_ucfg_api.h" |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 28 | #include <qca_vendor.h> |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 29 | #include <linux/errqueue.h> |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 30 | #if defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_IRQ) || \ |
| 31 | defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 32 | #include <linux/gpio.h> |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 33 | #endif |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 34 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 35 | #include "ol_txrx_api.h" |
Dustin Brown | a09acf4 | 2018-11-08 12:32:26 +0530 | [diff] [blame] | 36 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 37 | #ifdef WLAN_FEATURE_TSF_PLUS |
| 38 | #ifndef WLAN_FEATURE_TSF_PLUS_NOIRQ |
| 39 | #ifndef WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC |
| 40 | static int tsf_gpio_irq_num = -1; |
| 41 | #endif |
| 42 | #endif |
| 43 | #endif |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 44 | static struct completion tsf_sync_get_completion_evt; |
| 45 | #define WLAN_TSF_SYNC_GET_TIMEOUT 2000 |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 46 | #define WLAN_HDD_CAPTURE_TSF_REQ_TIMEOUT_MS 500 |
| 47 | #define WLAN_HDD_CAPTURE_TSF_INIT_INTERVAL_MS 100 |
Subrat Dash | f75d3d3 | 2019-08-23 22:27:37 +0530 | [diff] [blame] | 48 | #ifdef WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC |
| 49 | #define WLAN_HDD_SOFTAP_INTERVAL_TIMES 1 |
| 50 | #else |
| 51 | #define WLAN_HDD_SOFTAP_INTERVAL_TIMES 100 |
| 52 | #endif |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 53 | #define OUTPUT_HIGH 1 |
| 54 | #define OUTPUT_LOW 0 |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 55 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 56 | #ifdef WLAN_FEATURE_TSF_PLUS |
| 57 | #ifdef WLAN_FEATURE_TSF_PLUS_NOIRQ |
| 58 | static void hdd_update_timestamp(struct hdd_adapter *adapter); |
| 59 | #else |
| 60 | static void |
| 61 | hdd_update_timestamp(struct hdd_adapter *adapter, |
| 62 | uint64_t target_time, uint64_t host_time); |
| 63 | #endif |
| 64 | #endif |
| 65 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 66 | /** |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 67 | * enum hdd_tsf_op_result - result of tsf operation |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 68 | * |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 69 | * HDD_TSF_OP_SUCC: succeed |
| 70 | * HDD_TSF_OP_FAIL: fail |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 71 | */ |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 72 | enum hdd_tsf_op_result { |
| 73 | HDD_TSF_OP_SUCC, |
| 74 | HDD_TSF_OP_FAIL |
| 75 | }; |
| 76 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 77 | #ifdef WLAN_FEATURE_TSF_PLUS |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 78 | #ifdef WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC |
| 79 | #define WLAN_HDD_CAPTURE_TSF_RESYNC_INTERVAL 1 |
| 80 | #else |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 81 | #define WLAN_HDD_CAPTURE_TSF_RESYNC_INTERVAL 9 |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 82 | #endif |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 83 | static inline void hdd_set_th_sync_status(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 84 | bool initialized) |
| 85 | { |
| 86 | qdf_atomic_set(&adapter->tsf_sync_ready_flag, |
| 87 | (initialized ? 1 : 0)); |
| 88 | } |
| 89 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 90 | static inline bool hdd_get_th_sync_status(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 91 | { |
| 92 | return qdf_atomic_read(&adapter->tsf_sync_ready_flag) != 0; |
| 93 | } |
| 94 | |
| 95 | #else |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 96 | static inline bool hdd_get_th_sync_status(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 97 | { |
| 98 | return true; |
| 99 | } |
| 100 | #endif |
| 101 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 102 | static |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 103 | enum hdd_tsf_get_state hdd_tsf_check_conn_state(struct hdd_adapter *adapter) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 104 | { |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 105 | enum hdd_tsf_get_state ret = TSF_RETURN; |
Jeff Johnson | 40dae4e | 2017-08-29 14:00:25 -0700 | [diff] [blame] | 106 | struct hdd_station_ctx *hdd_sta_ctx; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 107 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 108 | if (adapter->device_mode == QDF_STA_MODE || |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 109 | adapter->device_mode == QDF_P2P_CLIENT_MODE) { |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 110 | hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); |
Jeff Johnson | e795151 | 2019-02-27 10:02:51 -0800 | [diff] [blame] | 111 | if (hdd_sta_ctx->conn_info.conn_state != |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 112 | eConnectionState_Associated) { |
| 113 | hdd_err("failed to cap tsf, not connect with ap"); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 114 | ret = TSF_STA_NOT_CONNECTED_NO_TSF; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 115 | } |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 116 | } else if ((adapter->device_mode == QDF_SAP_MODE || |
| 117 | adapter->device_mode == QDF_P2P_GO_MODE) && |
| 118 | !(test_bit(SOFTAP_BSS_STARTED, |
| 119 | &adapter->event_flags))) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 120 | hdd_err("Soft AP / P2p GO not beaconing"); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 121 | ret = TSF_SAP_NOT_STARTED_NO_TSF; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 122 | } |
| 123 | return ret; |
| 124 | } |
| 125 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 126 | static bool hdd_tsf_is_initialized(struct hdd_adapter *adapter) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 127 | { |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 128 | struct hdd_context *hddctx; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 129 | |
| 130 | if (!adapter) { |
| 131 | hdd_err("invalid adapter"); |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 136 | if (!hddctx) { |
| 137 | hdd_err("invalid hdd context"); |
| 138 | return false; |
| 139 | } |
| 140 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 141 | if (!qdf_atomic_read(&hddctx->tsf_ready_flag) || |
| 142 | !hdd_get_th_sync_status(adapter)) { |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 143 | hdd_err("TSF is not initialized"); |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | return true; |
| 148 | } |
| 149 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 150 | #if (defined(WLAN_FEATURE_TSF_PLUS_NOIRQ) && \ |
| 151 | defined(WLAN_FEATURE_TSF_PLUS)) || \ |
Paul Zhang | faa929c | 2019-11-12 10:10:44 +0800 | [diff] [blame^] | 152 | defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) || \ |
| 153 | defined(WLAN_FEATURE_TSF_TIMER_SYNC) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 154 | /** |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 155 | * hdd_tsf_reset_gpio() - Reset TSF GPIO used for host timer sync |
| 156 | * @adapter: pointer to adapter |
| 157 | * |
| 158 | * This function send WMI command to reset GPIO configured in FW after |
| 159 | * TSF get operation. |
| 160 | * |
| 161 | * Return: TSF_RETURN on Success, TSF_RESET_GPIO_FAIL on failure |
| 162 | */ |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 163 | static int hdd_tsf_reset_gpio(struct hdd_adapter *adapter) |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 164 | { |
| 165 | /* No GPIO Host timer sync for integrated WIFI Device */ |
| 166 | return TSF_RETURN; |
| 167 | } |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * hdd_tsf_set_gpio() - Set TSF GPIO used for host timer sync |
| 171 | * @hdd_ctx: pointer to hdd context |
| 172 | * |
| 173 | * This function is a dummy function for adrastea arch |
| 174 | * |
| 175 | * Return: QDF_STATUS_SUCCESS on Success |
| 176 | */ |
| 177 | |
| 178 | static QDF_STATUS hdd_tsf_set_gpio(struct hdd_context *hdd_ctx) |
| 179 | { |
| 180 | return QDF_STATUS_SUCCESS; |
| 181 | } |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 182 | #else |
| 183 | static int hdd_tsf_reset_gpio(struct hdd_adapter *adapter) |
| 184 | { |
| 185 | int ret; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 186 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 187 | ret = wma_cli_set_command((int)adapter->vdev_id, |
| 188 | (int)GEN_PARAM_RESET_TSF_GPIO, |
| 189 | adapter->vdev_id, |
| 190 | GEN_CMD); |
| 191 | |
| 192 | if (ret != 0) { |
| 193 | hdd_err("tsf reset GPIO fail "); |
| 194 | ret = TSF_RESET_GPIO_FAIL; |
| 195 | } else { |
| 196 | ret = TSF_RETURN; |
| 197 | } |
| 198 | return ret; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * hdd_tsf_set_gpio() - Set TSF GPIO used for host timer sync |
| 203 | * @hdd_ctx: pointer to hdd context |
| 204 | * |
| 205 | * This function check GPIO and set GPIO as IRQ to FW side on |
| 206 | * none Adrastea arch |
| 207 | * |
| 208 | * Return: QDF_STATUS_SUCCESS on Success, others on Failure. |
| 209 | */ |
| 210 | static QDF_STATUS hdd_tsf_set_gpio(struct hdd_context *hdd_ctx) |
| 211 | { |
| 212 | QDF_STATUS status; |
| 213 | uint32_t tsf_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 214 | |
| 215 | status = ucfg_fwol_get_tsf_gpio_pin(hdd_ctx->psoc, &tsf_gpio_pin); |
| 216 | if (QDF_IS_STATUS_ERROR(status)) |
| 217 | return QDF_STATUS_E_INVAL; |
| 218 | |
| 219 | if (tsf_gpio_pin == TSF_GPIO_PIN_INVALID) |
| 220 | return QDF_STATUS_E_INVAL; |
| 221 | |
| 222 | status = sme_set_tsf_gpio(hdd_ctx->mac_handle, |
| 223 | tsf_gpio_pin); |
| 224 | |
| 225 | return status; |
| 226 | } |
| 227 | #endif |
| 228 | |
| 229 | #ifdef WLAN_FEATURE_TSF_PLUS |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 230 | static bool hdd_tsf_is_ptp_enabled(struct hdd_context *hdd) |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 231 | { |
Manikandan Mohan | 0faf628 | 2019-01-14 18:00:04 -0800 | [diff] [blame] | 232 | uint32_t tsf_ptp_options; |
| 233 | |
| 234 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 235 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 236 | return !!tsf_ptp_options; |
| 237 | else |
| 238 | return false; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | bool hdd_tsf_is_tx_set(struct hdd_context *hdd) |
| 242 | { |
Manikandan Mohan | d350c19 | 2018-11-29 14:01:12 -0800 | [diff] [blame] | 243 | uint32_t tsf_ptp_options; |
| 244 | |
| 245 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 246 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 247 | return tsf_ptp_options & CFG_SET_TSF_PTP_OPT_TX; |
| 248 | else |
| 249 | return false; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | bool hdd_tsf_is_rx_set(struct hdd_context *hdd) |
| 253 | { |
Manikandan Mohan | d350c19 | 2018-11-29 14:01:12 -0800 | [diff] [blame] | 254 | uint32_t tsf_ptp_options; |
| 255 | |
| 256 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 257 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 258 | return tsf_ptp_options & CFG_SET_TSF_PTP_OPT_RX; |
| 259 | else |
| 260 | return false; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | bool hdd_tsf_is_raw_set(struct hdd_context *hdd) |
| 264 | { |
Manikandan Mohan | d350c19 | 2018-11-29 14:01:12 -0800 | [diff] [blame] | 265 | uint32_t tsf_ptp_options; |
| 266 | |
| 267 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 268 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 269 | return tsf_ptp_options & CFG_SET_TSF_PTP_OPT_RAW; |
| 270 | else |
| 271 | return false; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | bool hdd_tsf_is_dbg_fs_set(struct hdd_context *hdd) |
| 275 | { |
Manikandan Mohan | d350c19 | 2018-11-29 14:01:12 -0800 | [diff] [blame] | 276 | uint32_t tsf_ptp_options; |
| 277 | |
| 278 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 279 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 280 | return tsf_ptp_options & CFG_SET_TSF_DBG_FS; |
| 281 | else |
| 282 | return false; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 283 | } |
Jiani Liu | 6d3b6a1 | 2019-05-08 15:15:06 +0800 | [diff] [blame] | 284 | |
| 285 | bool hdd_tsf_is_tsf64_tx_set(struct hdd_context *hdd) |
| 286 | { |
| 287 | uint32_t tsf_ptp_options; |
| 288 | |
| 289 | if (hdd && QDF_IS_STATUS_SUCCESS( |
| 290 | ucfg_fwol_get_tsf_ptp_options(hdd->psoc, &tsf_ptp_options))) |
| 291 | return tsf_ptp_options & CFG_SET_TSF_PTP_OPT_TSF64_TX; |
| 292 | else |
| 293 | return false; |
| 294 | } |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 295 | #else |
| 296 | |
| 297 | static bool hdd_tsf_is_ptp_enabled(struct hdd_context *hdd) |
| 298 | { |
| 299 | return false; |
| 300 | } |
| 301 | #endif |
| 302 | |
| 303 | #ifdef WLAN_FEATURE_TSF_PLUS |
| 304 | static inline |
| 305 | uint64_t hdd_get_monotonic_host_time(struct hdd_context *hdd_ctx) |
| 306 | { |
| 307 | return hdd_tsf_is_raw_set(hdd_ctx) ? |
| 308 | ktime_get_ns() : ktime_get_real_ns(); |
| 309 | } |
| 310 | #endif |
| 311 | |
| 312 | #if defined(WLAN_FEATURE_TSF_PLUS) && \ |
| 313 | defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) |
Subrat Dash | 42155f6 | 2019-11-21 18:10:21 +0530 | [diff] [blame] | 314 | #define MAX_CONTINUOUS_RETRY_CNT 10 |
| 315 | static uint32_t |
| 316 | hdd_wlan_retry_tsf_cap(struct hdd_adapter *adapter) |
| 317 | { |
| 318 | struct hdd_context *hddctx; |
| 319 | int count = adapter->continuous_cap_retry_count; |
| 320 | |
| 321 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 322 | if (count == MAX_CONTINUOUS_RETRY_CNT) { |
| 323 | hdd_debug("Max retry countr reached"); |
| 324 | return 0; |
| 325 | } |
| 326 | qdf_atomic_set(&hddctx->cap_tsf_flag, 0); |
| 327 | count++; |
| 328 | adapter->continuous_cap_retry_count = count; |
| 329 | return (count * WLAN_HDD_CAPTURE_TSF_REQ_TIMEOUT_MS); |
| 330 | } |
| 331 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 332 | static void |
Subrat Dash | 9ba2ff8 | 2019-11-27 18:36:45 +0530 | [diff] [blame] | 333 | hdd_wlan_restart_tsf_cap(struct hdd_adapter *adapter) |
| 334 | { |
| 335 | struct hdd_context *hddctx; |
| 336 | int count = adapter->continuous_cap_retry_count; |
| 337 | |
| 338 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 339 | if (count == MAX_CONTINUOUS_RETRY_CNT) { |
| 340 | hdd_debug("Restart TSF CAP"); |
| 341 | qdf_atomic_set(&hddctx->cap_tsf_flag, 0); |
| 342 | adapter->continuous_cap_retry_count = 0; |
| 343 | qdf_mc_timer_start(&adapter->host_target_sync_timer, |
| 344 | WLAN_HDD_CAPTURE_TSF_INIT_INTERVAL_MS); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | static void |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 349 | hdd_update_host_time(struct hdd_adapter *adapter) |
| 350 | { |
| 351 | struct hdd_context *hdd_ctx; |
| 352 | u64 host_time; |
| 353 | char *name = NULL; |
| 354 | |
| 355 | hdd_ctx = adapter->hdd_ctx; |
| 356 | |
| 357 | if (!hdd_tsf_is_initialized(adapter)) { |
| 358 | hdd_err("tsf is not init, exit"); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
| 363 | hdd_update_timestamp(adapter, 0, host_time); |
| 364 | name = adapter->dev->name; |
| 365 | |
| 366 | hdd_debug("iface: %s - host_time: %llu", |
| 367 | (!name ? "none" : name), host_time); |
| 368 | } |
| 369 | |
| 370 | static |
| 371 | void hdd_tsf_ext_gpio_sync_work(void *data) |
| 372 | { |
| 373 | QDF_STATUS status; |
| 374 | struct hdd_adapter *adapter; |
| 375 | struct hdd_context *hdd_ctx; |
| 376 | uint32_t tsf_sync_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 377 | |
| 378 | adapter = data; |
| 379 | hdd_ctx = adapter->hdd_ctx; |
| 380 | status = ucfg_fwol_get_tsf_sync_host_gpio_pin(hdd_ctx->psoc, |
| 381 | &tsf_sync_gpio_pin); |
| 382 | if (QDF_IS_STATUS_ERROR(status)) { |
| 383 | hdd_err("tsf sync gpio host pin error"); |
| 384 | return; |
| 385 | } |
| 386 | gpio_set_value(tsf_sync_gpio_pin, OUTPUT_HIGH); |
| 387 | hdd_update_host_time(adapter); |
| 388 | usleep_range(50, 100); |
| 389 | gpio_set_value(tsf_sync_gpio_pin, OUTPUT_LOW); |
| 390 | |
| 391 | status = wma_cli_set_command((int)adapter->vdev_id, |
| 392 | (int)GEN_PARAM_CAPTURE_TSF, |
| 393 | adapter->vdev_id, GEN_CMD); |
| 394 | if (status != QDF_STATUS_SUCCESS) { |
| 395 | hdd_err("cap tsf fail"); |
| 396 | qdf_mc_timer_stop(&adapter->host_capture_req_timer); |
| 397 | qdf_mc_timer_destroy(&adapter->host_capture_req_timer); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | static void |
| 402 | hdd_tsf_gpio_sync_work_init(struct hdd_adapter *adapter) |
| 403 | { |
| 404 | qdf_create_work(0, &adapter->gpio_tsf_sync_work, |
| 405 | hdd_tsf_ext_gpio_sync_work, adapter); |
| 406 | } |
| 407 | |
| 408 | static void |
| 409 | hdd_tsf_gpio_sync_work_deinit(struct hdd_adapter *adapter) |
| 410 | { |
| 411 | qdf_destroy_work(0, &adapter->gpio_tsf_sync_work); |
| 412 | } |
| 413 | |
| 414 | static void |
| 415 | hdd_tsf_stop_ext_gpio_sync(struct hdd_adapter *adapter) |
| 416 | { |
| 417 | qdf_cancel_work(&adapter->gpio_tsf_sync_work); |
| 418 | } |
| 419 | |
| 420 | static void |
| 421 | hdd_tsf_start_ext_gpio_sync(struct hdd_adapter *adapter) |
| 422 | { |
| 423 | qdf_sched_work(0, &adapter->gpio_tsf_sync_work); |
| 424 | } |
| 425 | |
| 426 | static bool hdd_tsf_cap_sync_send(struct hdd_adapter *adapter) |
| 427 | { |
| 428 | hdd_tsf_start_ext_gpio_sync(adapter); |
| 429 | return true; |
| 430 | } |
| 431 | #elif defined(WLAN_FEATURE_TSF_PLUS) && \ |
| 432 | !defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) |
Subrat Dash | 42155f6 | 2019-11-21 18:10:21 +0530 | [diff] [blame] | 433 | static uint32_t |
| 434 | hdd_wlan_retry_tsf_cap(struct hdd_adapter *adapter) |
| 435 | { |
| 436 | return 0; |
| 437 | } |
| 438 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 439 | static void |
Subrat Dash | 9ba2ff8 | 2019-11-27 18:36:45 +0530 | [diff] [blame] | 440 | hdd_wlan_restart_tsf_cap(struct hdd_adapter *adapter) |
| 441 | { |
| 442 | } |
| 443 | |
| 444 | static void |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 445 | hdd_tsf_gpio_sync_work_init(struct hdd_adapter *adapter) |
| 446 | { |
| 447 | } |
| 448 | |
| 449 | static void |
| 450 | hdd_tsf_gpio_sync_work_deinit(struct hdd_adapter *adapter) |
| 451 | { |
| 452 | } |
| 453 | |
| 454 | static void |
| 455 | hdd_tsf_stop_ext_gpio_sync(struct hdd_adapter *adapter) |
| 456 | { |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | hdd_tsf_start_ext_gpio_sync(struct hdd_adapter *adapter) |
| 461 | { |
| 462 | } |
| 463 | |
| 464 | static bool |
| 465 | hdd_tsf_cap_sync_send(struct hdd_adapter *adapter) |
| 466 | { |
| 467 | hdd_tsf_start_ext_gpio_sync(adapter); |
| 468 | return false; |
| 469 | } |
| 470 | |
| 471 | #else |
| 472 | static bool hdd_tsf_cap_sync_send(struct hdd_adapter *adapter) |
| 473 | { |
| 474 | return false; |
| 475 | } |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 476 | #endif |
| 477 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 478 | static enum hdd_tsf_op_result hdd_capture_tsf_internal( |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 479 | struct hdd_adapter *adapter, uint32_t *buf, int len) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 480 | { |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 481 | int ret; |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 482 | struct hdd_context *hddctx; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 483 | qdf_mc_timer_t *cap_timer; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 484 | |
Jeff Johnson | d36fa33 | 2019-03-18 13:42:25 -0700 | [diff] [blame] | 485 | if (!adapter || !buf) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 486 | hdd_err("invalid pointer"); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 487 | return HDD_TSF_OP_FAIL; |
| 488 | } |
| 489 | |
| 490 | if (len != 1) |
| 491 | return HDD_TSF_OP_FAIL; |
| 492 | |
| 493 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 494 | if (!hddctx) { |
| 495 | hdd_err("invalid hdd context"); |
| 496 | return HDD_TSF_OP_FAIL; |
| 497 | } |
| 498 | |
| 499 | if (!hdd_tsf_is_initialized(adapter)) { |
| 500 | buf[0] = TSF_NOT_READY; |
| 501 | return HDD_TSF_OP_SUCC; |
| 502 | } |
| 503 | |
| 504 | buf[0] = hdd_tsf_check_conn_state(adapter); |
| 505 | if (buf[0] != TSF_RETURN) |
| 506 | return HDD_TSF_OP_SUCC; |
| 507 | |
| 508 | if (qdf_atomic_inc_return(&hddctx->cap_tsf_flag) > 1) { |
| 509 | hdd_err("current in capture state"); |
| 510 | buf[0] = TSF_CURRENT_IN_CAP_STATE; |
| 511 | return HDD_TSF_OP_SUCC; |
| 512 | } |
| 513 | |
| 514 | /* record adapter for cap_tsf_irq_handler */ |
| 515 | hddctx->cap_tsf_context = adapter; |
| 516 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 517 | hdd_info("+ioctl issue cap tsf cmd"); |
| 518 | cap_timer = &adapter->host_capture_req_timer; |
| 519 | qdf_mc_timer_init(cap_timer, QDF_TIMER_TYPE_SW, |
| 520 | hdd_capture_req_timer_expired_handler, |
| 521 | (void *)adapter); |
| 522 | qdf_mc_timer_start(cap_timer, WLAN_HDD_CAPTURE_TSF_REQ_TIMEOUT_MS); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 523 | |
| 524 | /* Reset TSF value for new capture */ |
| 525 | adapter->cur_target_time = 0; |
| 526 | |
| 527 | buf[0] = TSF_RETURN; |
| 528 | init_completion(&tsf_sync_get_completion_evt); |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 529 | |
| 530 | if (hdd_tsf_cap_sync_send(adapter)) |
| 531 | return HDD_TSF_OP_SUCC; |
| 532 | |
Jeff Johnson | 9597f3b | 2019-02-04 14:27:56 -0800 | [diff] [blame] | 533 | ret = wma_cli_set_command((int)adapter->vdev_id, |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 534 | (int)GEN_PARAM_CAPTURE_TSF, |
Jeff Johnson | 9597f3b | 2019-02-04 14:27:56 -0800 | [diff] [blame] | 535 | adapter->vdev_id, GEN_CMD); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 536 | if (QDF_STATUS_SUCCESS != ret) { |
| 537 | hdd_err("cap tsf fail"); |
| 538 | buf[0] = TSF_CAPTURE_FAIL; |
| 539 | hddctx->cap_tsf_context = NULL; |
| 540 | qdf_atomic_set(&hddctx->cap_tsf_flag, 0); |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 541 | qdf_mc_timer_stop(&adapter->host_capture_req_timer); |
| 542 | qdf_mc_timer_destroy(&adapter->host_capture_req_timer); |
| 543 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 544 | return HDD_TSF_OP_SUCC; |
| 545 | } |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 546 | hdd_info("-ioctl return cap tsf cmd"); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 547 | return HDD_TSF_OP_SUCC; |
| 548 | } |
| 549 | |
| 550 | static enum hdd_tsf_op_result hdd_indicate_tsf_internal( |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 551 | struct hdd_adapter *adapter, uint32_t *buf, int len) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 552 | { |
| 553 | int ret; |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 554 | struct hdd_context *hddctx; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 555 | |
| 556 | if (!adapter || !buf) { |
| 557 | hdd_err("invalid pointer"); |
| 558 | return HDD_TSF_OP_FAIL; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | if (len != 3) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 562 | return HDD_TSF_OP_FAIL; |
| 563 | |
| 564 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 565 | if (!hddctx) { |
| 566 | hdd_err("invalid hdd context"); |
| 567 | return HDD_TSF_OP_FAIL; |
| 568 | } |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 569 | |
| 570 | buf[1] = 0; |
| 571 | buf[2] = 0; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 572 | |
| 573 | if (!hdd_tsf_is_initialized(adapter)) { |
| 574 | buf[0] = TSF_NOT_READY; |
| 575 | return HDD_TSF_OP_SUCC; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 576 | } |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 577 | |
| 578 | buf[0] = hdd_tsf_check_conn_state(adapter); |
| 579 | if (buf[0] != TSF_RETURN) |
| 580 | return HDD_TSF_OP_SUCC; |
| 581 | |
| 582 | if (adapter->cur_target_time == 0) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 583 | hdd_info("TSF value not received"); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 584 | buf[0] = TSF_NOT_RETURNED_BY_FW; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 585 | return HDD_TSF_OP_SUCC; |
Jeff Johnson | a5fb218 | 2017-10-06 20:27:38 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | buf[0] = TSF_RETURN; |
| 589 | buf[1] = (uint32_t)(adapter->cur_target_time & 0xffffffff); |
| 590 | buf[2] = (uint32_t)((adapter->cur_target_time >> 32) & |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 591 | 0xffffffff); |
| 592 | |
Jeff Johnson | a5fb218 | 2017-10-06 20:27:38 -0700 | [diff] [blame] | 593 | if (!qdf_atomic_read(&hddctx->cap_tsf_flag)) { |
| 594 | hdd_info("old: status=%u, tsf_low=%u, tsf_high=%u", |
| 595 | buf[0], buf[1], buf[2]); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 596 | return HDD_TSF_OP_SUCC; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 597 | } |
Jeff Johnson | a5fb218 | 2017-10-06 20:27:38 -0700 | [diff] [blame] | 598 | |
| 599 | ret = hdd_tsf_reset_gpio(adapter); |
| 600 | if (0 != ret) { |
| 601 | hdd_err("reset tsf gpio fail"); |
| 602 | buf[0] = TSF_RESET_GPIO_FAIL; |
| 603 | return HDD_TSF_OP_SUCC; |
| 604 | } |
| 605 | hddctx->cap_tsf_context = NULL; |
| 606 | qdf_atomic_set(&hddctx->cap_tsf_flag, 0); |
| 607 | hdd_info("get tsf cmd,status=%u, tsf_low=%u, tsf_high=%u", |
| 608 | buf[0], buf[1], buf[2]); |
| 609 | |
| 610 | return HDD_TSF_OP_SUCC; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 611 | } |
| 612 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 613 | #ifdef WLAN_FEATURE_TSF_PLUS |
| 614 | /* unit for target time: us; host time: ns */ |
| 615 | #define HOST_TO_TARGET_TIME_RATIO NSEC_PER_USEC |
gaolez | c2b7208 | 2017-10-30 15:29:59 +0800 | [diff] [blame] | 616 | #define MAX_ALLOWED_DEVIATION_NS (100 * NSEC_PER_USEC) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 617 | #define MAX_CONTINUOUS_ERROR_CNT 3 |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 618 | |
| 619 | /* to distinguish 32-bit overflow case, this inverval should: |
| 620 | * equal or less than (1/2 * OVERFLOW_INDICATOR32 us) |
| 621 | */ |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 622 | #if defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_IRQ) || \ |
| 623 | defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 624 | #define WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC 2 |
| 625 | #else |
guangde | 87e1720 | 2019-09-20 18:18:28 +0800 | [diff] [blame] | 626 | #define WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC 4 |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 627 | #endif |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 628 | #define OVERFLOW_INDICATOR32 (((int64_t)0x1) << 32) |
gaolez | c2b7208 | 2017-10-30 15:29:59 +0800 | [diff] [blame] | 629 | #define CAP_TSF_TIMER_FIX_SEC 1 |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 630 | |
| 631 | /** |
| 632 | * TS_STATUS - timestamp status |
| 633 | * |
| 634 | * HDD_TS_STATUS_WAITING: one of the stamp-pair |
| 635 | * is not updated |
| 636 | * HDD_TS_STATUS_READY: valid tstamp-pair |
| 637 | * HDD_TS_STATUS_INVALID: invalid tstamp-pair |
| 638 | */ |
| 639 | enum hdd_ts_status { |
| 640 | HDD_TS_STATUS_WAITING, |
| 641 | HDD_TS_STATUS_READY, |
| 642 | HDD_TS_STATUS_INVALID |
| 643 | }; |
| 644 | |
| 645 | static |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 646 | enum hdd_tsf_op_result __hdd_start_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 647 | { |
| 648 | QDF_STATUS ret; |
| 649 | |
| 650 | if (!hdd_get_th_sync_status(adapter)) { |
| 651 | hdd_err("Host Target sync has not initialized"); |
| 652 | return HDD_TSF_OP_FAIL; |
| 653 | } |
| 654 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 655 | hdd_tsf_gpio_sync_work_init(adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 656 | ret = qdf_mc_timer_start(&adapter->host_target_sync_timer, |
| 657 | WLAN_HDD_CAPTURE_TSF_INIT_INTERVAL_MS); |
| 658 | if (ret != QDF_STATUS_SUCCESS && ret != QDF_STATUS_E_ALREADY) { |
| 659 | hdd_err("Failed to start timer, ret: %d", ret); |
| 660 | return HDD_TSF_OP_FAIL; |
| 661 | } |
| 662 | return HDD_TSF_OP_SUCC; |
| 663 | } |
| 664 | |
| 665 | static |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 666 | enum hdd_tsf_op_result __hdd_stop_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 667 | { |
| 668 | QDF_STATUS ret; |
| 669 | |
| 670 | if (!hdd_get_th_sync_status(adapter)) { |
| 671 | hdd_err("Host Target sync has not initialized"); |
| 672 | return HDD_TSF_OP_SUCC; |
| 673 | } |
| 674 | |
| 675 | ret = qdf_mc_timer_stop(&adapter->host_target_sync_timer); |
| 676 | if (ret != QDF_STATUS_SUCCESS) { |
| 677 | hdd_err("Failed to stop timer, ret: %d", ret); |
| 678 | return HDD_TSF_OP_FAIL; |
| 679 | } |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 680 | hdd_tsf_stop_ext_gpio_sync(adapter); |
| 681 | hdd_tsf_gpio_sync_work_deinit(adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 682 | return HDD_TSF_OP_SUCC; |
| 683 | } |
| 684 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 685 | static inline void hdd_reset_timestamps(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 686 | { |
| 687 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 688 | adapter->cur_host_time = 0; |
| 689 | adapter->cur_target_time = 0; |
| 690 | adapter->last_host_time = 0; |
| 691 | adapter->last_target_time = 0; |
| 692 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * hdd_check_timestamp_status() - return the tstamp status |
| 697 | * |
| 698 | * @last_target_time: the last saved target time |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 699 | * @last_sync_time: the last saved sync time |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 700 | * @cur_target_time : new target time |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 701 | * @cur_sync_time : new sync time |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 702 | * |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 703 | * This function check the new timstamp-pair(cur_host_time/cur_target_time)or |
| 704 | * (cur_qtime_time/cur_target_time) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 705 | * Return: |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 706 | * HDD_TS_STATUS_WAITING: cur_sync_time or cur_sync_time is 0 |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 707 | * HDD_TS_STATUS_READY: cur_target_time/cur_host_time is a valid pair, |
| 708 | * and can be saved |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 709 | * HDD_TS_STATUS_INVALID: cur_target_time/cur_sync_time is a invalid pair, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 710 | * should be discard |
| 711 | */ |
| 712 | static |
| 713 | enum hdd_ts_status hdd_check_timestamp_status( |
| 714 | uint64_t last_target_time, |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 715 | uint64_t last_sync_time, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 716 | uint64_t cur_target_time, |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 717 | uint64_t cur_sync_time) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 718 | { |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 719 | uint64_t delta_ns, delta_target_time, delta_sync_time; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 720 | |
| 721 | /* one or more are not updated, need to wait */ |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 722 | if (cur_target_time == 0 || cur_sync_time == 0) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 723 | return HDD_TS_STATUS_WAITING; |
| 724 | |
| 725 | /* init value, it's the first time to update the pair */ |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 726 | if (last_target_time == 0 && last_sync_time == 0) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 727 | return HDD_TS_STATUS_READY; |
| 728 | |
| 729 | /* the new values should be greater than the saved values */ |
| 730 | if ((cur_target_time <= last_target_time) || |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 731 | (cur_sync_time <= last_sync_time)) { |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 732 | hdd_err("Invalid timestamps!last_target_time: %llu;" |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 733 | "last_sync_time: %llu; cur_target_time: %llu;" |
| 734 | "cur_sync_time: %llu", |
| 735 | last_target_time, last_sync_time, |
| 736 | cur_target_time, cur_sync_time); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 737 | return HDD_TS_STATUS_INVALID; |
| 738 | } |
| 739 | |
| 740 | delta_target_time = (cur_target_time - last_target_time) * |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 741 | NSEC_PER_USEC; |
| 742 | delta_sync_time = cur_sync_time - last_sync_time; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 743 | |
| 744 | /* |
| 745 | * DO NOT use abs64() , a big uint64 value might be turned to |
| 746 | * a small int64 value |
| 747 | */ |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 748 | delta_ns = ((delta_target_time > delta_sync_time) ? |
| 749 | (delta_target_time - delta_sync_time) : |
| 750 | (delta_sync_time - delta_target_time)); |
| 751 | hdd_warn("timestamps deviation - delta: %llu ns", delta_ns); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 752 | /* the deviation should be smaller than a threshold */ |
| 753 | if (delta_ns > MAX_ALLOWED_DEVIATION_NS) { |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 754 | hdd_warn("Invalid timestamps - delta: %llu ns", delta_ns); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 755 | return HDD_TS_STATUS_INVALID; |
| 756 | } |
| 757 | return HDD_TS_STATUS_READY; |
| 758 | } |
| 759 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 760 | static inline bool hdd_tsf_is_in_cap(struct hdd_adapter *adapter) |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 761 | { |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 762 | struct hdd_context *hddctx; |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 763 | |
| 764 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 765 | if (!hddctx) |
| 766 | return false; |
| 767 | |
| 768 | return qdf_atomic_read(&hddctx->cap_tsf_flag) > 0; |
| 769 | } |
| 770 | |
| 771 | /* define 64bit plus/minus to deal with overflow */ |
| 772 | static inline int hdd_64bit_plus(uint64_t x, int64_t y, uint64_t *ret) |
| 773 | { |
| 774 | if ((y < 0 && (-y) > x) || |
| 775 | (y > 0 && (y > U64_MAX - x))) { |
| 776 | *ret = 0; |
| 777 | return -EINVAL; |
| 778 | } |
| 779 | |
| 780 | *ret = x + y; |
| 781 | return 0; |
| 782 | } |
| 783 | |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 784 | static inline int hdd_uint64_plus(uint64_t x, uint64_t y, uint64_t *ret) |
| 785 | { |
| 786 | if (!ret) |
| 787 | return -EINVAL; |
| 788 | |
| 789 | if (x > (U64_MAX - y)) { |
| 790 | *ret = 0; |
| 791 | return -EINVAL; |
| 792 | } |
| 793 | |
| 794 | *ret = x + y; |
| 795 | return 0; |
| 796 | } |
| 797 | |
| 798 | static inline int hdd_uint64_minus(uint64_t x, uint64_t y, uint64_t *ret) |
| 799 | { |
| 800 | if (!ret) |
| 801 | return -EINVAL; |
| 802 | |
| 803 | if (x < y) { |
| 804 | *ret = 0; |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | *ret = x - y; |
| 809 | return 0; |
| 810 | } |
| 811 | |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 812 | static inline int32_t hdd_get_hosttime_from_targettime( |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 813 | struct hdd_adapter *adapter, uint64_t target_time, |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 814 | uint64_t *host_time) |
| 815 | { |
| 816 | int32_t ret = -EINVAL; |
| 817 | int64_t delta32_target; |
| 818 | bool in_cap_state; |
gaolez | d11c7c5 | 2018-03-28 15:04:13 +0800 | [diff] [blame] | 819 | int64_t normal_interval_target; |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 820 | |
| 821 | in_cap_state = hdd_tsf_is_in_cap(adapter); |
| 822 | |
| 823 | /* |
| 824 | * To avoid check the lock when it's not capturing tsf |
| 825 | * (the tstamp-pair won't be changed) |
| 826 | */ |
| 827 | if (in_cap_state) |
| 828 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 829 | |
Subrat Dash | 9ba2ff8 | 2019-11-27 18:36:45 +0530 | [diff] [blame] | 830 | hdd_wlan_restart_tsf_cap(adapter); |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 831 | /* at present, target_time is only 32bit in fact */ |
| 832 | delta32_target = (int64_t)((target_time & U32_MAX) - |
| 833 | (adapter->last_target_time & U32_MAX)); |
| 834 | |
yuanl | 45a1526 | 2018-11-11 01:11:47 +0800 | [diff] [blame] | 835 | normal_interval_target = WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC * |
| 836 | qdf_do_div(NSEC_PER_SEC, HOST_TO_TARGET_TIME_RATIO); |
gaolez | d11c7c5 | 2018-03-28 15:04:13 +0800 | [diff] [blame] | 837 | |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 838 | if (delta32_target < |
gaolez | d11c7c5 | 2018-03-28 15:04:13 +0800 | [diff] [blame] | 839 | (normal_interval_target - OVERFLOW_INDICATOR32)) |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 840 | delta32_target += OVERFLOW_INDICATOR32; |
| 841 | else if (delta32_target > |
gaolez | d11c7c5 | 2018-03-28 15:04:13 +0800 | [diff] [blame] | 842 | (OVERFLOW_INDICATOR32 - normal_interval_target)) |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 843 | delta32_target -= OVERFLOW_INDICATOR32; |
| 844 | |
| 845 | ret = hdd_64bit_plus(adapter->last_host_time, |
| 846 | HOST_TO_TARGET_TIME_RATIO * delta32_target, |
| 847 | host_time); |
| 848 | |
| 849 | if (in_cap_state) |
| 850 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 851 | |
| 852 | return ret; |
| 853 | } |
| 854 | |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 855 | static inline int32_t hdd_get_targettime_from_hosttime( |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 856 | struct hdd_adapter *adapter, uint64_t host_time, |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 857 | uint64_t *target_time) |
| 858 | { |
| 859 | int32_t ret = -EINVAL; |
| 860 | bool in_cap_state; |
| 861 | |
| 862 | if (!adapter || host_time == 0) |
| 863 | return ret; |
| 864 | |
| 865 | in_cap_state = hdd_tsf_is_in_cap(adapter); |
| 866 | if (in_cap_state) |
| 867 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 868 | |
| 869 | if (host_time < adapter->last_host_time) |
| 870 | ret = hdd_uint64_minus(adapter->last_target_time, |
Yu Wang | c9ef24f | 2017-09-15 18:37:07 +0800 | [diff] [blame] | 871 | qdf_do_div(adapter->last_host_time - |
| 872 | host_time, |
| 873 | HOST_TO_TARGET_TIME_RATIO), |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 874 | target_time); |
| 875 | else |
| 876 | ret = hdd_uint64_plus(adapter->last_target_time, |
Yu Wang | c9ef24f | 2017-09-15 18:37:07 +0800 | [diff] [blame] | 877 | qdf_do_div(host_time - |
| 878 | adapter->last_host_time, |
| 879 | HOST_TO_TARGET_TIME_RATIO), |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 880 | target_time); |
| 881 | |
| 882 | if (in_cap_state) |
| 883 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 888 | /** |
| 889 | * hdd_get_soctime_from_tsf64time() - return get status |
| 890 | * |
| 891 | * @adapter: Adapter pointer |
| 892 | * @tsf64_time: current tsf64time, us |
| 893 | * @soc_time: current soc time(qtime), ns |
| 894 | * |
| 895 | * This function get current soc time from current tsf64 time |
| 896 | * Returun int32_t value to tell get success or fail. |
| 897 | * |
| 898 | * Return: |
| 899 | * 0: success |
| 900 | * other: fail |
| 901 | * |
| 902 | */ |
| 903 | static inline int32_t hdd_get_soctime_from_tsf64time( |
| 904 | struct hdd_adapter *adapter, uint64_t tsf64_time, |
| 905 | uint64_t *soc_time) |
| 906 | { |
| 907 | int32_t ret = -EINVAL; |
| 908 | uint64_t delta64_tsf64time; |
| 909 | uint64_t delta64_soctime; |
| 910 | bool in_cap_state; |
| 911 | |
| 912 | in_cap_state = hdd_tsf_is_in_cap(adapter); |
| 913 | |
| 914 | /* |
| 915 | * To avoid check the lock when it's not capturing tsf |
| 916 | * (the tstamp-pair won't be changed) |
| 917 | */ |
| 918 | if (in_cap_state) |
| 919 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 920 | |
| 921 | /* at present, target_time is 64bit (g_tsf64), us*/ |
guangde | 45e45e7 | 2019-07-12 10:21:31 +0800 | [diff] [blame] | 922 | if (tsf64_time > adapter->last_target_global_tsf_time) { |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 923 | delta64_tsf64time = tsf64_time - |
guangde | 45e45e7 | 2019-07-12 10:21:31 +0800 | [diff] [blame] | 924 | adapter->last_target_global_tsf_time; |
| 925 | delta64_soctime = delta64_tsf64time * NSEC_PER_USEC; |
| 926 | |
| 927 | /* soc_time (ns)*/ |
| 928 | ret = hdd_uint64_plus(adapter->last_tsf_sync_soc_time, |
| 929 | delta64_soctime, soc_time); |
| 930 | } else { |
| 931 | delta64_tsf64time = adapter->last_target_global_tsf_time - |
| 932 | tsf64_time; |
| 933 | delta64_soctime = delta64_tsf64time * NSEC_PER_USEC; |
| 934 | |
| 935 | /* soc_time (ns)*/ |
| 936 | ret = hdd_uint64_minus(adapter->last_tsf_sync_soc_time, |
| 937 | delta64_soctime, soc_time); |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 938 | } |
| 939 | |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 940 | if (in_cap_state) |
| 941 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 942 | |
| 943 | return ret; |
| 944 | } |
| 945 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 946 | static void hdd_capture_tsf_timer_expired_handler(void *arg) |
| 947 | { |
| 948 | uint32_t tsf_op_resp; |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 949 | struct hdd_adapter *adapter; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 950 | |
| 951 | if (!arg) |
| 952 | return; |
| 953 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 954 | adapter = (struct hdd_adapter *)arg; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 955 | hdd_capture_tsf_internal(adapter, &tsf_op_resp, 1); |
| 956 | } |
| 957 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 958 | #ifndef WLAN_FEATURE_TSF_PLUS_NOIRQ |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 959 | #ifndef WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 960 | static irqreturn_t hdd_tsf_captured_irq_handler(int irq, void *arg) |
| 961 | { |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 962 | struct hdd_adapter *adapter; |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 963 | struct hdd_context *hdd_ctx; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 964 | uint64_t host_time; |
| 965 | char *name = NULL; |
| 966 | |
| 967 | if (!arg) |
| 968 | return IRQ_NONE; |
| 969 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 970 | if (irq != tsf_gpio_irq_num) |
| 971 | return IRQ_NONE; |
| 972 | |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 973 | hdd_ctx = (struct hdd_context *)arg; |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 974 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 975 | |
| 976 | adapter = hdd_ctx->cap_tsf_context; |
| 977 | if (!adapter) |
| 978 | return IRQ_HANDLED; |
| 979 | |
| 980 | if (!hdd_tsf_is_initialized(adapter)) { |
| 981 | hdd_err("tsf is not init, ignore irq"); |
| 982 | return IRQ_HANDLED; |
| 983 | } |
| 984 | |
| 985 | hdd_update_timestamp(adapter, 0, host_time); |
| 986 | if (adapter->dev) |
| 987 | name = adapter->dev->name; |
| 988 | |
| 989 | hdd_info("irq: %d - iface: %s - host_time: %llu", |
| 990 | irq, (!name ? "none" : name), host_time); |
| 991 | |
| 992 | return IRQ_HANDLED; |
| 993 | } |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 994 | #endif |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 995 | #endif |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 996 | |
| 997 | void hdd_capture_req_timer_expired_handler(void *arg) |
| 998 | { |
| 999 | struct hdd_adapter *adapter; |
| 1000 | struct hdd_context *hdd_ctx; |
| 1001 | QDF_TIMER_STATE capture_req_timer_status; |
| 1002 | qdf_mc_timer_t *sync_timer; |
| 1003 | int interval; |
| 1004 | int ret; |
| 1005 | |
| 1006 | if (!arg) |
| 1007 | return; |
| 1008 | adapter = (struct hdd_adapter *)arg; |
| 1009 | |
| 1010 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1011 | if (!hdd_ctx) { |
| 1012 | hdd_warn("invalid hdd context"); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | if (!hdd_tsf_is_initialized(adapter)) { |
| 1017 | qdf_mc_timer_destroy(&adapter->host_capture_req_timer); |
| 1018 | hdd_warn("tsf not init"); |
| 1019 | return; |
| 1020 | } |
| 1021 | |
| 1022 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 1023 | adapter->cur_host_time = 0; |
| 1024 | adapter->cur_target_time = 0; |
| 1025 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 1026 | |
| 1027 | ret = hdd_tsf_reset_gpio(adapter); |
| 1028 | if (0 != ret) |
| 1029 | hdd_info("reset tsf gpio fail"); |
| 1030 | |
| 1031 | hdd_ctx->cap_tsf_context = NULL; |
| 1032 | qdf_atomic_set(&hdd_ctx->cap_tsf_flag, 0); |
| 1033 | qdf_mc_timer_destroy(&adapter->host_capture_req_timer); |
| 1034 | |
| 1035 | sync_timer = &adapter->host_target_sync_timer; |
| 1036 | capture_req_timer_status = |
| 1037 | qdf_mc_timer_get_current_state(sync_timer); |
| 1038 | |
| 1039 | if (capture_req_timer_status == QDF_TIMER_STATE_UNUSED) { |
| 1040 | hdd_warn("invalid timer status"); |
| 1041 | return; |
| 1042 | } |
| 1043 | |
| 1044 | interval = WLAN_HDD_CAPTURE_TSF_RESYNC_INTERVAL * MSEC_PER_SEC; |
| 1045 | qdf_mc_timer_start(sync_timer, interval); |
| 1046 | } |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1047 | |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1048 | #ifdef WLAN_FEATURE_TSF_PLUS_NOIRQ |
| 1049 | static void hdd_update_timestamp(struct hdd_adapter *adapter) |
| 1050 | { |
| 1051 | int interval = 0; |
| 1052 | enum hdd_ts_status sync_status; |
| 1053 | |
| 1054 | if (!adapter) |
| 1055 | return; |
| 1056 | |
| 1057 | /* on ADREASTEA ach, Qtime is used to sync host and tsf time as a |
| 1058 | * intermedia there is no IRQ to sync up TSF-HOST, so host time in ns |
| 1059 | * and target in us will be updated at the same time in WMI command |
| 1060 | * callback |
| 1061 | */ |
| 1062 | |
| 1063 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 1064 | sync_status = |
| 1065 | hdd_check_timestamp_status(adapter->last_target_time, |
| 1066 | adapter->last_tsf_sync_soc_time, |
| 1067 | adapter->cur_target_time, |
| 1068 | adapter->cur_tsf_sync_soc_time); |
| 1069 | hdd_info("sync_status %d", sync_status); |
| 1070 | switch (sync_status) { |
| 1071 | case HDD_TS_STATUS_INVALID: |
| 1072 | if (++adapter->continuous_error_count < |
| 1073 | MAX_CONTINUOUS_ERROR_CNT) { |
| 1074 | interval = |
| 1075 | WLAN_HDD_CAPTURE_TSF_INIT_INTERVAL_MS; |
| 1076 | adapter->cur_target_time = 0; |
| 1077 | adapter->cur_tsf_sync_soc_time = 0; |
| 1078 | break; |
| 1079 | } |
| 1080 | hdd_warn("Reach the max continuous error count"); |
| 1081 | /* |
| 1082 | * fall through: |
| 1083 | * If reach MAX_CONTINUOUS_ERROR_CNT, treat it as a |
| 1084 | * valid pair |
| 1085 | */ |
| 1086 | case HDD_TS_STATUS_READY: |
| 1087 | adapter->last_target_time = adapter->cur_target_time; |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1088 | adapter->last_target_global_tsf_time = |
| 1089 | adapter->cur_target_global_tsf_time; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1090 | adapter->last_tsf_sync_soc_time = |
| 1091 | adapter->cur_tsf_sync_soc_time; |
| 1092 | adapter->cur_target_time = 0; |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1093 | adapter->cur_target_global_tsf_time = 0; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1094 | adapter->cur_tsf_sync_soc_time = 0; |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1095 | hdd_info("ts-pair updated: target: %llu; g_target:%llu, Qtime: %llu", |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1096 | adapter->last_target_time, |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1097 | adapter->last_target_global_tsf_time, |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1098 | adapter->last_tsf_sync_soc_time); |
| 1099 | |
| 1100 | /* |
| 1101 | * TSF-HOST need to be updated in at most |
| 1102 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC, it couldn't be achieved |
| 1103 | * if the timer interval is also |
| 1104 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC, due to processing or |
| 1105 | * schedule delay. So deduct several seconds from |
| 1106 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC. |
| 1107 | * Without this change, hdd_get_hosttime_from_targettime() will |
| 1108 | * get wrong host time when it's longer than |
| 1109 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC from last |
| 1110 | * TSF-HOST update. |
| 1111 | */ |
| 1112 | interval = (WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC - |
| 1113 | CAP_TSF_TIMER_FIX_SEC) * MSEC_PER_SEC; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1114 | |
| 1115 | adapter->continuous_error_count = 0; |
Subrat Dash | 42155f6 | 2019-11-21 18:10:21 +0530 | [diff] [blame] | 1116 | adapter->continuous_cap_retry_count = 0; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1117 | hdd_debug("ts-pair updated: interval: %d", |
| 1118 | interval); |
| 1119 | break; |
| 1120 | case HDD_TS_STATUS_WAITING: |
| 1121 | interval = 0; |
| 1122 | hdd_warn("TS status is waiting due to one or more pair not updated"); |
| 1123 | break; |
| 1124 | } |
| 1125 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 1126 | |
| 1127 | if (interval > 0) |
| 1128 | qdf_mc_timer_start(&adapter->host_target_sync_timer, interval); |
| 1129 | } |
| 1130 | |
| 1131 | static ssize_t __hdd_wlan_tsf_show(struct device *dev, |
| 1132 | struct device_attribute *attr, char *buf) |
| 1133 | { |
| 1134 | struct hdd_station_ctx *hdd_sta_ctx; |
| 1135 | struct hdd_adapter *adapter; |
| 1136 | struct hdd_context *hdd_ctx; |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1137 | uint64_t tsf_sync_qtime, host_time, reg_qtime, qtime; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1138 | ssize_t size; |
| 1139 | |
| 1140 | struct net_device *net_dev = container_of(dev, struct net_device, dev); |
| 1141 | |
| 1142 | adapter = (struct hdd_adapter *)(netdev_priv(net_dev)); |
| 1143 | if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) |
| 1144 | return scnprintf(buf, PAGE_SIZE, "Invalid device\n"); |
| 1145 | |
| 1146 | if (!hdd_get_th_sync_status(adapter)) |
| 1147 | return scnprintf(buf, PAGE_SIZE, |
| 1148 | "TSF sync is not initialized\n"); |
| 1149 | |
| 1150 | hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); |
Jeff Johnson | e795151 | 2019-02-27 10:02:51 -0800 | [diff] [blame] | 1151 | if (eConnectionState_Associated != hdd_sta_ctx->conn_info.conn_state && |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1152 | (adapter->device_mode == QDF_STA_MODE || |
| 1153 | adapter->device_mode == QDF_P2P_CLIENT_MODE)) |
| 1154 | return scnprintf(buf, PAGE_SIZE, "NOT connected\n"); |
| 1155 | |
| 1156 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1157 | |
| 1158 | if (!hdd_ctx) |
| 1159 | return scnprintf(buf, PAGE_SIZE, "Invalid HDD context\n"); |
| 1160 | |
| 1161 | tsf_sync_qtime = adapter->last_tsf_sync_soc_time; |
| 1162 | do_div(tsf_sync_qtime, NSEC_PER_USEC); |
| 1163 | |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1164 | reg_qtime = qdf_get_log_timestamp(); |
| 1165 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
| 1166 | |
| 1167 | qtime = qdf_log_timestamp_to_usecs(reg_qtime); |
| 1168 | do_div(host_time, NSEC_PER_USEC); |
| 1169 | |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1170 | if (adapter->device_mode == QDF_STA_MODE || |
| 1171 | adapter->device_mode == QDF_P2P_CLIENT_MODE) { |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1172 | size = scnprintf(buf, PAGE_SIZE, "%s%llu %llu %pM %llu %llu\n", |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1173 | buf, adapter->last_target_time, |
| 1174 | tsf_sync_qtime, |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1175 | hdd_sta_ctx->conn_info.bssid.bytes, |
| 1176 | qtime, host_time); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1177 | } else { |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1178 | size = scnprintf(buf, PAGE_SIZE, "%s%llu %llu %pM %llu %llu\n", |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1179 | buf, adapter->last_target_time, |
| 1180 | tsf_sync_qtime, |
Jiani Liu | ef39b96 | 2019-05-30 13:24:59 +0800 | [diff] [blame] | 1181 | adapter->mac_addr.bytes, |
| 1182 | qtime, host_time); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | return size; |
| 1186 | } |
| 1187 | |
| 1188 | static inline void hdd_update_tsf(struct hdd_adapter *adapter, uint64_t tsf) |
| 1189 | { |
| 1190 | uint32_t tsf_op_resp[3]; |
| 1191 | struct hdd_context *hddctx; |
| 1192 | |
| 1193 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 1194 | hdd_indicate_tsf_internal(adapter, tsf_op_resp, 3); |
| 1195 | hdd_update_timestamp(adapter); |
| 1196 | } |
| 1197 | #else |
| 1198 | static void hdd_update_timestamp(struct hdd_adapter *adapter, |
| 1199 | uint64_t target_time, uint64_t host_time) |
| 1200 | { |
| 1201 | int interval = 0; |
| 1202 | enum hdd_ts_status sync_status; |
| 1203 | |
| 1204 | if (!adapter) |
| 1205 | return; |
| 1206 | |
| 1207 | /* host time is updated in IRQ context, it's always before target time, |
| 1208 | * and so no need to try update last_host_time at present; |
| 1209 | * since the interval of capturing TSF |
| 1210 | * (WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC) is long enough, host and target |
| 1211 | * time are updated in pairs, and one by one, we can return here to |
| 1212 | * avoid requiring spin lock, and to speed up the IRQ processing. |
| 1213 | */ |
| 1214 | if (host_time > 0) |
| 1215 | adapter->cur_host_time = host_time; |
| 1216 | |
| 1217 | qdf_spin_lock_bh(&adapter->host_target_sync_lock); |
| 1218 | if (target_time > 0) |
| 1219 | adapter->cur_target_time = target_time; |
| 1220 | |
| 1221 | sync_status = hdd_check_timestamp_status(adapter->last_target_time, |
| 1222 | adapter->last_host_time, |
| 1223 | adapter->cur_target_time, |
| 1224 | adapter->cur_host_time); |
| 1225 | hdd_info("sync_status %d", sync_status); |
| 1226 | switch (sync_status) { |
| 1227 | case HDD_TS_STATUS_INVALID: |
| 1228 | if (++adapter->continuous_error_count < |
| 1229 | MAX_CONTINUOUS_ERROR_CNT) { |
| 1230 | interval = |
| 1231 | WLAN_HDD_CAPTURE_TSF_INIT_INTERVAL_MS; |
| 1232 | adapter->cur_target_time = 0; |
| 1233 | adapter->cur_host_time = 0; |
| 1234 | break; |
| 1235 | } |
| 1236 | hdd_warn("Reach the max continuous error count"); |
| 1237 | /* |
| 1238 | * fall through: |
| 1239 | * If reach MAX_CONTINUOUS_ERROR_CNT, treat it as a |
| 1240 | * valid pair |
| 1241 | */ |
| 1242 | case HDD_TS_STATUS_READY: |
| 1243 | adapter->last_target_time = adapter->cur_target_time; |
| 1244 | adapter->last_host_time = adapter->cur_host_time; |
| 1245 | adapter->cur_target_time = 0; |
| 1246 | adapter->cur_host_time = 0; |
| 1247 | hdd_info("ts-pair updated: target: %llu; host: %llu", |
| 1248 | adapter->last_target_time, |
| 1249 | adapter->last_host_time); |
| 1250 | |
| 1251 | /* |
| 1252 | * TSF-HOST need to be updated in at most |
| 1253 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC, it couldn't be achieved |
| 1254 | * if the timer interval is also |
| 1255 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC, due to processing or |
| 1256 | * schedule delay. So deduct several seconds from |
| 1257 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC. |
| 1258 | * Without this change, hdd_get_hosttime_from_targettime() will |
| 1259 | * get wrong host time when it's longer than |
| 1260 | * WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC from last |
| 1261 | * TSF-HOST update. |
| 1262 | */ |
| 1263 | interval = (WLAN_HDD_CAPTURE_TSF_INTERVAL_SEC - |
| 1264 | CAP_TSF_TIMER_FIX_SEC) * MSEC_PER_SEC; |
| 1265 | if (adapter->device_mode == QDF_SAP_MODE || |
| 1266 | adapter->device_mode == QDF_P2P_GO_MODE) { |
Subrat Dash | f75d3d3 | 2019-08-23 22:27:37 +0530 | [diff] [blame] | 1267 | interval *= WLAN_HDD_SOFTAP_INTERVAL_TIMES; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | adapter->continuous_error_count = 0; |
Subrat Dash | 42155f6 | 2019-11-21 18:10:21 +0530 | [diff] [blame] | 1271 | adapter->continuous_cap_retry_count = 0; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1272 | hdd_debug("ts-pair updated: interval: %d", |
| 1273 | interval); |
| 1274 | break; |
| 1275 | case HDD_TS_STATUS_WAITING: |
| 1276 | interval = 0; |
| 1277 | hdd_warn("TS status is waiting due to one or more pair not updated"); |
Subrat Dash | 42155f6 | 2019-11-21 18:10:21 +0530 | [diff] [blame] | 1278 | |
| 1279 | if (!target_time && !host_time) |
| 1280 | interval = hdd_wlan_retry_tsf_cap(adapter); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1281 | break; |
| 1282 | } |
| 1283 | qdf_spin_unlock_bh(&adapter->host_target_sync_lock); |
| 1284 | |
| 1285 | if (interval > 0) |
| 1286 | qdf_mc_timer_start(&adapter->host_target_sync_timer, interval); |
| 1287 | } |
| 1288 | |
| 1289 | static ssize_t __hdd_wlan_tsf_show(struct device *dev, |
| 1290 | struct device_attribute *attr, char *buf) |
| 1291 | { |
| 1292 | struct hdd_station_ctx *hdd_sta_ctx; |
| 1293 | struct hdd_adapter *adapter; |
| 1294 | struct hdd_context *hdd_ctx; |
| 1295 | ssize_t size; |
| 1296 | uint64_t host_time, target_time; |
| 1297 | |
| 1298 | struct net_device *net_dev = container_of(dev, struct net_device, dev); |
| 1299 | |
| 1300 | adapter = (struct hdd_adapter *)(netdev_priv(net_dev)); |
| 1301 | if (adapter->magic != WLAN_HDD_ADAPTER_MAGIC) |
| 1302 | return scnprintf(buf, PAGE_SIZE, "Invalid device\n"); |
| 1303 | |
| 1304 | if (!hdd_get_th_sync_status(adapter)) |
| 1305 | return scnprintf(buf, PAGE_SIZE, |
| 1306 | "TSF sync is not initialized\n"); |
| 1307 | |
| 1308 | hdd_sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter); |
Jeff Johnson | e795151 | 2019-02-27 10:02:51 -0800 | [diff] [blame] | 1309 | if (eConnectionState_Associated != hdd_sta_ctx->conn_info.conn_state && |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1310 | (adapter->device_mode == QDF_STA_MODE || |
| 1311 | adapter->device_mode == QDF_P2P_CLIENT_MODE)) |
| 1312 | return scnprintf(buf, PAGE_SIZE, "NOT connected\n"); |
| 1313 | |
| 1314 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1315 | if (!hdd_ctx) |
| 1316 | return scnprintf(buf, PAGE_SIZE, "Invalid HDD context\n"); |
| 1317 | |
| 1318 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
| 1319 | |
| 1320 | if (hdd_get_targettime_from_hosttime(adapter, host_time, |
| 1321 | &target_time)) { |
| 1322 | size = scnprintf(buf, PAGE_SIZE, "Invalid timestamp\n"); |
| 1323 | } else { |
| 1324 | if (adapter->device_mode == QDF_STA_MODE || |
| 1325 | adapter->device_mode == QDF_P2P_CLIENT_MODE) { |
| 1326 | size = scnprintf(buf, PAGE_SIZE, "%s%llu %llu %pM\n", |
| 1327 | buf, target_time, host_time, |
Jeff Johnson | e04b699 | 2019-02-27 14:06:55 -0800 | [diff] [blame] | 1328 | hdd_sta_ctx->conn_info.bssid.bytes); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1329 | } else { |
| 1330 | size = scnprintf(buf, PAGE_SIZE, "%s%llu %llu %pM\n", |
| 1331 | buf, target_time, host_time, |
| 1332 | adapter->mac_addr.bytes); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | return size; |
| 1337 | } |
| 1338 | |
| 1339 | static inline void hdd_update_tsf(struct hdd_adapter *adapter, uint64_t tsf) |
| 1340 | { |
| 1341 | uint32_t tsf_op_resp[3]; |
| 1342 | |
| 1343 | hdd_indicate_tsf_internal(adapter, tsf_op_resp, 3); |
| 1344 | hdd_update_timestamp(adapter, tsf, 0); |
| 1345 | } |
| 1346 | #endif |
| 1347 | |
| 1348 | static ssize_t hdd_wlan_tsf_show(struct device *dev, |
| 1349 | struct device_attribute *attr, char *buf) |
| 1350 | { |
Dustin Brown | 96b98dd | 2019-03-06 12:39:37 -0800 | [diff] [blame] | 1351 | struct net_device *net_dev = container_of(dev, struct net_device, dev); |
| 1352 | struct osif_vdev_sync *vdev_sync; |
| 1353 | ssize_t err_size; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1354 | |
Dustin Brown | 96b98dd | 2019-03-06 12:39:37 -0800 | [diff] [blame] | 1355 | err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync); |
| 1356 | if (err_size) |
| 1357 | return err_size; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1358 | |
Dustin Brown | 96b98dd | 2019-03-06 12:39:37 -0800 | [diff] [blame] | 1359 | err_size = __hdd_wlan_tsf_show(dev, attr, buf); |
| 1360 | |
| 1361 | osif_vdev_sync_op_stop(vdev_sync); |
| 1362 | |
| 1363 | return err_size; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | static DEVICE_ATTR(tsf, 0400, hdd_wlan_tsf_show, NULL); |
| 1367 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1368 | static enum hdd_tsf_op_result hdd_tsf_sync_init(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1369 | { |
| 1370 | QDF_STATUS ret; |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1371 | struct hdd_context *hddctx; |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 1372 | struct net_device *net_dev; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1373 | |
| 1374 | if (!adapter) |
| 1375 | return HDD_TSF_OP_FAIL; |
| 1376 | |
| 1377 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 1378 | if (!hddctx) { |
| 1379 | hdd_err("invalid hdd context"); |
| 1380 | return HDD_TSF_OP_FAIL; |
| 1381 | } |
| 1382 | |
| 1383 | if (!qdf_atomic_read(&hddctx->tsf_ready_flag)) { |
| 1384 | hdd_err("TSF feature has NOT been initialized"); |
| 1385 | return HDD_TSF_OP_FAIL; |
| 1386 | } |
| 1387 | |
| 1388 | if (hdd_get_th_sync_status(adapter)) { |
| 1389 | hdd_err("Host Target sync has been initialized!!"); |
| 1390 | return HDD_TSF_OP_SUCC; |
| 1391 | } |
| 1392 | |
| 1393 | qdf_spinlock_create(&adapter->host_target_sync_lock); |
| 1394 | |
| 1395 | hdd_reset_timestamps(adapter); |
| 1396 | |
| 1397 | ret = qdf_mc_timer_init(&adapter->host_target_sync_timer, |
| 1398 | QDF_TIMER_TYPE_SW, |
| 1399 | hdd_capture_tsf_timer_expired_handler, |
| 1400 | (void *)adapter); |
| 1401 | if (ret != QDF_STATUS_SUCCESS) { |
| 1402 | hdd_err("Failed to init timer, ret: %d", ret); |
| 1403 | goto fail; |
| 1404 | } |
| 1405 | |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 1406 | net_dev = adapter->dev; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1407 | if (net_dev && hdd_tsf_is_dbg_fs_set(hddctx)) |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 1408 | device_create_file(&net_dev->dev, &dev_attr_tsf); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1409 | hdd_set_th_sync_status(adapter, true); |
| 1410 | |
| 1411 | return HDD_TSF_OP_SUCC; |
| 1412 | fail: |
| 1413 | hdd_set_th_sync_status(adapter, false); |
| 1414 | return HDD_TSF_OP_FAIL; |
| 1415 | } |
| 1416 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1417 | static enum hdd_tsf_op_result hdd_tsf_sync_deinit(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1418 | { |
| 1419 | QDF_STATUS ret; |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1420 | struct hdd_context *hddctx; |
Yu Wang | 0ea1017 | 2017-06-02 13:40:52 +0800 | [diff] [blame] | 1421 | struct net_device *net_dev; |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1422 | |
| 1423 | if (!adapter) |
| 1424 | return HDD_TSF_OP_FAIL; |
| 1425 | |
| 1426 | if (!hdd_get_th_sync_status(adapter)) { |
| 1427 | hdd_err("Host Target sync has not been initialized!!"); |
| 1428 | return HDD_TSF_OP_SUCC; |
| 1429 | } |
| 1430 | |
| 1431 | hdd_set_th_sync_status(adapter, false); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1432 | ret = qdf_mc_timer_destroy(&adapter->host_target_sync_timer); |
| 1433 | if (ret != QDF_STATUS_SUCCESS) |
| 1434 | hdd_err("Failed to destroy timer, ret: %d", ret); |
| 1435 | |
| 1436 | hddctx = WLAN_HDD_GET_CTX(adapter); |
| 1437 | |
| 1438 | /* reset the cap_tsf flag and gpio if needed */ |
| 1439 | if (hddctx && qdf_atomic_read(&hddctx->cap_tsf_flag) && |
| 1440 | hddctx->cap_tsf_context == adapter) { |
| 1441 | int reset_ret = hdd_tsf_reset_gpio(adapter); |
| 1442 | |
| 1443 | if (reset_ret) |
| 1444 | hdd_err("Failed to reset tsf gpio, ret:%d", |
| 1445 | reset_ret); |
| 1446 | hddctx->cap_tsf_context = NULL; |
| 1447 | qdf_atomic_set(&hddctx->cap_tsf_flag, 0); |
| 1448 | } |
| 1449 | |
| 1450 | hdd_reset_timestamps(adapter); |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 1451 | |
| 1452 | net_dev = adapter->dev; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1453 | if (net_dev && hdd_tsf_is_dbg_fs_set(hddctx)) { |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 1454 | struct device *dev = &net_dev->dev; |
| 1455 | |
| 1456 | device_remove_file(dev, &dev_attr_tsf); |
| 1457 | } |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1458 | return HDD_TSF_OP_SUCC; |
| 1459 | } |
| 1460 | |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1461 | #ifdef CONFIG_HL_SUPPORT |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1462 | static inline |
| 1463 | enum hdd_tsf_op_result hdd_netbuf_timestamp(qdf_nbuf_t netbuf, |
| 1464 | uint64_t target_time) |
| 1465 | { |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1466 | struct hdd_adapter *adapter; |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1467 | struct net_device *net_dev = netbuf->dev; |
| 1468 | |
| 1469 | if (!net_dev) |
| 1470 | return HDD_TSF_OP_FAIL; |
| 1471 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1472 | adapter = (struct hdd_adapter *)(netdev_priv(net_dev)); |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1473 | if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC && |
| 1474 | hdd_get_th_sync_status(adapter)) { |
| 1475 | uint64_t host_time; |
| 1476 | int32_t ret = hdd_get_hosttime_from_targettime(adapter, |
| 1477 | target_time, &host_time); |
| 1478 | if (!ret) { |
| 1479 | netbuf->tstamp = ns_to_ktime(host_time); |
| 1480 | return HDD_TSF_OP_SUCC; |
| 1481 | } |
| 1482 | } |
| 1483 | |
| 1484 | return HDD_TSF_OP_FAIL; |
| 1485 | } |
| 1486 | |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1487 | #else |
| 1488 | static inline |
| 1489 | enum hdd_tsf_op_result hdd_netbuf_timestamp(qdf_nbuf_t netbuf, |
| 1490 | uint64_t target_time) |
| 1491 | { |
| 1492 | struct hdd_adapter *adapter; |
| 1493 | struct net_device *net_dev = netbuf->dev; |
guangde | 44f9ab7 | 2019-10-17 18:48:44 +0800 | [diff] [blame] | 1494 | struct skb_shared_hwtstamps hwtstamps; |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1495 | |
| 1496 | if (!net_dev) |
| 1497 | return HDD_TSF_OP_FAIL; |
| 1498 | |
| 1499 | adapter = (struct hdd_adapter *)(netdev_priv(net_dev)); |
| 1500 | if (adapter && adapter->magic == WLAN_HDD_ADAPTER_MAGIC && |
| 1501 | hdd_get_th_sync_status(adapter)) { |
| 1502 | uint64_t tsf64_time = target_time; |
| 1503 | uint64_t soc_time = 0;/*ns*/ |
| 1504 | int32_t ret = hdd_get_soctime_from_tsf64time(adapter, |
| 1505 | tsf64_time, &soc_time); |
| 1506 | if (!ret) { |
guangde | 44f9ab7 | 2019-10-17 18:48:44 +0800 | [diff] [blame] | 1507 | hwtstamps.hwtstamp = soc_time; |
| 1508 | *skb_hwtstamps(netbuf) = hwtstamps; |
guangde | 7bd92e6 | 2019-10-21 16:46:38 +0800 | [diff] [blame] | 1509 | netbuf->tstamp = ktime_set(0, 0); |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 1510 | return HDD_TSF_OP_SUCC; |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | return HDD_TSF_OP_FAIL; |
| 1515 | } |
| 1516 | #endif |
| 1517 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1518 | int hdd_start_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1519 | { |
| 1520 | enum hdd_tsf_op_result ret; |
| 1521 | |
| 1522 | if (!adapter) |
| 1523 | return -EINVAL; |
| 1524 | |
| 1525 | ret = hdd_tsf_sync_init(adapter); |
| 1526 | if (ret != HDD_TSF_OP_SUCC) { |
| 1527 | hdd_err("Failed to init tsf sync, ret: %d", ret); |
| 1528 | return -EINVAL; |
| 1529 | } |
| 1530 | |
| 1531 | return (__hdd_start_tsf_sync(adapter) == |
| 1532 | HDD_TSF_OP_SUCC) ? 0 : -EINVAL; |
| 1533 | } |
| 1534 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1535 | int hdd_stop_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1536 | { |
| 1537 | enum hdd_tsf_op_result ret; |
| 1538 | |
| 1539 | if (!adapter) |
| 1540 | return -EINVAL; |
| 1541 | |
| 1542 | ret = __hdd_stop_tsf_sync(adapter); |
| 1543 | if (ret != HDD_TSF_OP_SUCC) |
| 1544 | return -EINVAL; |
| 1545 | |
| 1546 | ret = hdd_tsf_sync_deinit(adapter); |
| 1547 | if (ret != HDD_TSF_OP_SUCC) { |
| 1548 | hdd_err("Failed to deinit tsf sync, ret: %d", ret); |
| 1549 | return -EINVAL; |
| 1550 | } |
| 1551 | return 0; |
| 1552 | } |
| 1553 | |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1554 | int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 1555 | { |
| 1556 | struct sock *sk = netbuf->sk; |
| 1557 | |
| 1558 | if (!sk) |
| 1559 | return -EINVAL; |
| 1560 | |
guangde | 44f9ab7 | 2019-10-17 18:48:44 +0800 | [diff] [blame] | 1561 | if ((skb_shinfo(netbuf)->tx_flags & SKBTX_HW_TSTAMP) && |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1562 | !(skb_shinfo(netbuf)->tx_flags & SKBTX_IN_PROGRESS)) { |
| 1563 | struct sock_exterr_skb *serr; |
| 1564 | qdf_nbuf_t new_netbuf; |
| 1565 | int err; |
| 1566 | |
| 1567 | if (hdd_netbuf_timestamp(netbuf, target_time) != |
| 1568 | HDD_TSF_OP_SUCC) |
| 1569 | return -EINVAL; |
| 1570 | |
| 1571 | new_netbuf = qdf_nbuf_clone(netbuf); |
| 1572 | if (!new_netbuf) |
| 1573 | return -ENOMEM; |
| 1574 | |
| 1575 | serr = SKB_EXT_ERR(new_netbuf); |
| 1576 | memset(serr, 0, sizeof(*serr)); |
| 1577 | serr->ee.ee_errno = ENOMSG; |
| 1578 | serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING; |
| 1579 | |
| 1580 | err = sock_queue_err_skb(sk, new_netbuf); |
| 1581 | if (err) { |
| 1582 | qdf_nbuf_free(new_netbuf); |
| 1583 | return err; |
| 1584 | } |
| 1585 | |
| 1586 | return 0; |
| 1587 | } |
| 1588 | return -EINVAL; |
| 1589 | } |
| 1590 | |
| 1591 | int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 1592 | { |
| 1593 | if (hdd_netbuf_timestamp(netbuf, target_time) == |
| 1594 | HDD_TSF_OP_SUCC) |
| 1595 | return 0; |
| 1596 | |
| 1597 | /* reset tstamp when failed */ |
guangde | 7bd92e6 | 2019-10-21 16:46:38 +0800 | [diff] [blame] | 1598 | netbuf->tstamp = ktime_set(0, 0); |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 1599 | return -EINVAL; |
| 1600 | } |
| 1601 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1602 | static inline int __hdd_capture_tsf(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1603 | uint32_t *buf, int len) |
| 1604 | { |
| 1605 | if (!adapter || !buf) { |
| 1606 | hdd_err("invalid pointer"); |
| 1607 | return -EINVAL; |
| 1608 | } |
| 1609 | |
| 1610 | if (len != 1) |
| 1611 | return -EINVAL; |
| 1612 | |
| 1613 | buf[0] = TSF_DISABLED_BY_TSFPLUS; |
| 1614 | |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1618 | static inline int __hdd_indicate_tsf(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1619 | uint32_t *buf, int len) |
| 1620 | { |
| 1621 | if (!adapter || !buf) { |
| 1622 | hdd_err("invalid pointer"); |
| 1623 | return -EINVAL; |
| 1624 | } |
| 1625 | |
| 1626 | if (len != 3) |
| 1627 | return -EINVAL; |
| 1628 | |
| 1629 | buf[0] = TSF_DISABLED_BY_TSFPLUS; |
| 1630 | buf[1] = 0; |
| 1631 | buf[2] = 0; |
| 1632 | |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 1636 | #if defined(WLAN_FEATURE_TSF_PLUS_NOIRQ) |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1637 | static inline |
| 1638 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
| 1639 | { |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1640 | |
| 1641 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1642 | ol_register_timestamp_callback(hdd_tx_timestamp); |
| 1643 | return HDD_TSF_OP_SUCC; |
| 1644 | } |
| 1645 | |
| 1646 | static inline |
| 1647 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
| 1648 | { |
| 1649 | QDF_STATUS status; |
| 1650 | QDF_TIMER_STATE capture_req_timer_status; |
| 1651 | qdf_mc_timer_t *cap_timer; |
| 1652 | struct hdd_adapter *adapter, *adapternode_ptr, *next_ptr; |
| 1653 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1654 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1655 | ol_deregister_timestamp_callback(); |
| 1656 | |
| 1657 | status = hdd_get_front_adapter(hdd_ctx, &adapternode_ptr); |
| 1658 | |
Jeff Johnson | d36fa33 | 2019-03-18 13:42:25 -0700 | [diff] [blame] | 1659 | while (adapternode_ptr && QDF_STATUS_SUCCESS == status) { |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1660 | adapter = adapternode_ptr; |
| 1661 | status = |
| 1662 | hdd_get_next_adapter(hdd_ctx, adapternode_ptr, &next_ptr); |
| 1663 | adapternode_ptr = next_ptr; |
| 1664 | if (adapter->host_capture_req_timer.state == 0) |
| 1665 | continue; |
| 1666 | cap_timer = &adapter->host_capture_req_timer; |
| 1667 | capture_req_timer_status = |
| 1668 | qdf_mc_timer_get_current_state(cap_timer); |
| 1669 | |
| 1670 | if (capture_req_timer_status != QDF_TIMER_STATE_UNUSED) { |
| 1671 | qdf_mc_timer_stop(cap_timer); |
| 1672 | status = |
| 1673 | qdf_mc_timer_destroy(cap_timer); |
| 1674 | if (status != QDF_STATUS_SUCCESS) |
| 1675 | hdd_err("remove timer failed: %d", status); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | return HDD_TSF_OP_SUCC; |
| 1680 | } |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 1681 | |
| 1682 | #elif defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_SYNC) |
| 1683 | static |
| 1684 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
| 1685 | { |
| 1686 | int ret; |
| 1687 | QDF_STATUS status; |
| 1688 | uint32_t tsf_sync_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 1689 | |
| 1690 | status = ucfg_fwol_get_tsf_sync_host_gpio_pin(hdd_ctx->psoc, |
| 1691 | &tsf_sync_gpio_pin); |
| 1692 | if (QDF_IS_STATUS_ERROR(status)) { |
| 1693 | hdd_err("tsf gpio irq host pin error"); |
| 1694 | goto fail; |
| 1695 | } |
| 1696 | |
| 1697 | if (tsf_sync_gpio_pin == TSF_GPIO_PIN_INVALID) { |
| 1698 | hdd_err("gpio host pin is invalid"); |
| 1699 | goto fail; |
| 1700 | } |
| 1701 | |
| 1702 | ret = gpio_request(tsf_sync_gpio_pin, "wlan_tsf"); |
| 1703 | if (ret) { |
| 1704 | hdd_err("gpio host pin is invalid"); |
| 1705 | goto fail; |
| 1706 | } |
| 1707 | |
| 1708 | ret = gpio_direction_output(tsf_sync_gpio_pin, OUTPUT_LOW); |
| 1709 | if (ret) { |
| 1710 | hdd_err("gpio host pin is invalid"); |
| 1711 | goto fail_free_gpio; |
| 1712 | } |
| 1713 | |
| 1714 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1715 | ol_register_timestamp_callback(hdd_tx_timestamp); |
| 1716 | |
| 1717 | return HDD_TSF_OP_SUCC; |
| 1718 | |
| 1719 | fail_free_gpio: |
| 1720 | gpio_free(tsf_sync_gpio_pin); |
| 1721 | fail: |
| 1722 | return HDD_TSF_OP_FAIL; |
| 1723 | } |
| 1724 | |
| 1725 | static |
| 1726 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
| 1727 | { |
| 1728 | QDF_STATUS status; |
| 1729 | uint32_t tsf_sync_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 1730 | |
| 1731 | status = ucfg_fwol_get_tsf_sync_host_gpio_pin(hdd_ctx->psoc, |
| 1732 | &tsf_sync_gpio_pin); |
| 1733 | if (QDF_IS_STATUS_ERROR(status)) |
| 1734 | return QDF_STATUS_E_INVAL; |
| 1735 | |
| 1736 | if (tsf_sync_gpio_pin == TSF_GPIO_PIN_INVALID) |
| 1737 | return QDF_STATUS_E_INVAL; |
| 1738 | |
| 1739 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1740 | ol_deregister_timestamp_callback(); |
| 1741 | |
| 1742 | gpio_free(tsf_sync_gpio_pin); |
| 1743 | return HDD_TSF_OP_SUCC; |
| 1744 | } |
| 1745 | |
| 1746 | #elif defined(WLAN_FEATURE_TSF_PLUS_EXT_GPIO_IRQ) |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 1747 | static |
| 1748 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
| 1749 | { |
| 1750 | int ret; |
| 1751 | QDF_STATUS status; |
| 1752 | uint32_t tsf_irq_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 1753 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 1754 | status = ucfg_fwol_get_tsf_irq_host_gpio_pin(hdd_ctx->psoc, |
| 1755 | &tsf_irq_gpio_pin); |
| 1756 | if (QDF_IS_STATUS_ERROR(status)) { |
| 1757 | hdd_err("tsf gpio irq host pin error"); |
| 1758 | goto fail; |
| 1759 | } |
| 1760 | |
| 1761 | if (tsf_irq_gpio_pin == TSF_GPIO_PIN_INVALID) { |
| 1762 | hdd_err("gpio host pin is invalid"); |
| 1763 | goto fail; |
| 1764 | } |
| 1765 | |
| 1766 | ret = gpio_request(tsf_irq_gpio_pin, "wlan_tsf"); |
| 1767 | if (ret) { |
| 1768 | hdd_err("gpio host pin is invalid"); |
| 1769 | goto fail; |
| 1770 | } |
| 1771 | |
| 1772 | ret = gpio_direction_input(tsf_irq_gpio_pin); |
| 1773 | if (ret) { |
| 1774 | hdd_err("gpio host pin is invalid"); |
| 1775 | goto fail_free_gpio; |
| 1776 | } |
| 1777 | |
| 1778 | tsf_gpio_irq_num = gpio_to_irq(tsf_irq_gpio_pin); |
| 1779 | if (tsf_gpio_irq_num < 0) { |
| 1780 | hdd_err("fail to get irq: %d", tsf_gpio_irq_num); |
| 1781 | goto fail_free_gpio; |
| 1782 | } |
| 1783 | |
| 1784 | ret = request_irq(tsf_gpio_irq_num, hdd_tsf_captured_irq_handler, |
| 1785 | IRQF_SHARED | IRQF_TRIGGER_RISING, "wlan_tsf", |
| 1786 | hdd_ctx); |
| 1787 | |
| 1788 | if (ret) { |
| 1789 | hdd_err("Failed to register irq handler: %d", ret); |
| 1790 | goto fail_free_gpio; |
| 1791 | } |
| 1792 | |
| 1793 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1794 | ol_register_timestamp_callback(hdd_tx_timestamp); |
| 1795 | |
| 1796 | return HDD_TSF_OP_SUCC; |
| 1797 | |
| 1798 | fail_free_gpio: |
| 1799 | gpio_free(tsf_irq_gpio_pin); |
| 1800 | fail: |
| 1801 | tsf_gpio_irq_num = -1; |
| 1802 | return HDD_TSF_OP_FAIL; |
| 1803 | } |
| 1804 | |
| 1805 | static |
| 1806 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
| 1807 | { |
| 1808 | QDF_STATUS status; |
| 1809 | uint32_t tsf_irq_gpio_pin = TSF_GPIO_PIN_INVALID; |
| 1810 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 1811 | status = ucfg_fwol_get_tsf_irq_host_gpio_pin(hdd_ctx->psoc, |
| 1812 | &tsf_irq_gpio_pin); |
| 1813 | if (QDF_IS_STATUS_ERROR(status)) |
| 1814 | return QDF_STATUS_E_INVAL; |
| 1815 | |
| 1816 | if (tsf_irq_gpio_pin == TSF_GPIO_PIN_INVALID) |
| 1817 | return QDF_STATUS_E_INVAL; |
| 1818 | |
| 1819 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
| 1820 | ol_deregister_timestamp_callback(); |
| 1821 | |
| 1822 | if (tsf_gpio_irq_num >= 0) { |
| 1823 | free_irq(tsf_gpio_irq_num, hdd_ctx); |
| 1824 | tsf_gpio_irq_num = -1; |
| 1825 | gpio_free(tsf_irq_gpio_pin); |
| 1826 | } |
| 1827 | |
| 1828 | return HDD_TSF_OP_SUCC; |
| 1829 | } |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 1830 | |
Paul Zhang | faa929c | 2019-11-12 10:10:44 +0800 | [diff] [blame^] | 1831 | #elif defined(WLAN_FEATURE_TSF_TIMER_SYNC) |
| 1832 | static inline |
| 1833 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
| 1834 | { |
| 1835 | return HDD_TSF_OP_SUCC; |
| 1836 | } |
| 1837 | |
| 1838 | static inline |
| 1839 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
| 1840 | { |
| 1841 | return HDD_TSF_OP_SUCC; |
| 1842 | } |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 1843 | #else |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1844 | static inline |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1845 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1846 | { |
| 1847 | int ret; |
| 1848 | |
| 1849 | ret = cnss_common_register_tsf_captured_handler( |
| 1850 | hdd_ctx->parent_dev, |
| 1851 | hdd_tsf_captured_irq_handler, |
| 1852 | (void *)hdd_ctx); |
| 1853 | if (ret != 0) { |
| 1854 | hdd_err("Failed to register irq handler: %d", ret); |
| 1855 | return HDD_TSF_OP_FAIL; |
| 1856 | } |
Yu Wang | ceb357b | 2017-06-01 12:04:18 +0800 | [diff] [blame] | 1857 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1858 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 1859 | ol_register_timestamp_callback(hdd_tx_timestamp); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1860 | return HDD_TSF_OP_SUCC; |
| 1861 | } |
| 1862 | |
| 1863 | static inline |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1864 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1865 | { |
| 1866 | int ret; |
| 1867 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1868 | if (hdd_tsf_is_tx_set(hdd_ctx)) |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 1869 | ol_deregister_timestamp_callback(); |
| 1870 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1871 | ret = cnss_common_unregister_tsf_captured_handler( |
| 1872 | hdd_ctx->parent_dev, |
| 1873 | (void *)hdd_ctx); |
| 1874 | if (ret != 0) { |
| 1875 | hdd_err("Failed to unregister irq handler, ret:%d", |
| 1876 | ret); |
| 1877 | ret = HDD_TSF_OP_FAIL; |
| 1878 | } |
| 1879 | |
| 1880 | return HDD_TSF_OP_SUCC; |
| 1881 | } |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 1882 | #endif |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1883 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1884 | void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1885 | eConnectionState old_state, |
| 1886 | eConnectionState new_state) |
| 1887 | { |
| 1888 | if (!adapter) |
| 1889 | return; |
| 1890 | |
| 1891 | if (old_state != eConnectionState_Associated && |
| 1892 | new_state == eConnectionState_Associated) |
| 1893 | hdd_start_tsf_sync(adapter); |
| 1894 | else if (old_state == eConnectionState_Associated && |
| 1895 | new_state != eConnectionState_Associated) |
| 1896 | hdd_stop_tsf_sync(adapter); |
| 1897 | } |
| 1898 | #else |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1899 | static inline void hdd_update_tsf(struct hdd_adapter *adapter, uint64_t tsf) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1900 | { |
| 1901 | } |
| 1902 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1903 | static inline int __hdd_indicate_tsf(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1904 | uint32_t *buf, int len) |
| 1905 | { |
| 1906 | return (hdd_indicate_tsf_internal(adapter, buf, len) == |
| 1907 | HDD_TSF_OP_SUCC) ? 0 : -EINVAL; |
| 1908 | } |
| 1909 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1910 | static inline int __hdd_capture_tsf(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1911 | uint32_t *buf, int len) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 1912 | { |
| 1913 | return (hdd_capture_tsf_internal(adapter, buf, len) == |
| 1914 | HDD_TSF_OP_SUCC) ? 0 : -EINVAL; |
| 1915 | } |
| 1916 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1917 | static inline |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1918 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_init(struct hdd_context *hdd_ctx) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1919 | { |
| 1920 | return HDD_TSF_OP_SUCC; |
| 1921 | } |
| 1922 | |
| 1923 | static inline |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 1924 | enum hdd_tsf_op_result wlan_hdd_tsf_plus_deinit(struct hdd_context *hdd_ctx) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1925 | { |
| 1926 | return HDD_TSF_OP_SUCC; |
| 1927 | } |
| 1928 | #endif /* WLAN_FEATURE_TSF_PLUS */ |
| 1929 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1930 | int hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1931 | { |
| 1932 | return __hdd_capture_tsf(adapter, buf, len); |
| 1933 | } |
| 1934 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 1935 | int hdd_indicate_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 1936 | { |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 1937 | return __hdd_indicate_tsf(adapter, buf, len); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 1940 | #ifdef WLAN_FEATURE_TSF_PTP |
| 1941 | int wlan_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) |
| 1942 | |
| 1943 | { |
| 1944 | struct hdd_adapter *adapter = netdev_priv(dev); |
| 1945 | struct osif_vdev_sync *vdev_sync; |
| 1946 | struct hdd_context *hdd_ctx; |
| 1947 | int errno; |
| 1948 | |
| 1949 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 1950 | errno = wlan_hdd_validate_context(hdd_ctx); |
| 1951 | if (errno) |
| 1952 | return -EINVAL; |
| 1953 | |
| 1954 | errno = osif_vdev_sync_op_start(dev, &vdev_sync); |
| 1955 | if (errno) |
| 1956 | return -EAGAIN; |
| 1957 | |
| 1958 | info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | |
| 1959 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1960 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1961 | if (hdd_ctx->ptp_clock) |
| 1962 | info->phc_index = ptp_clock_index(hdd_ctx->ptp_clock); |
| 1963 | else |
| 1964 | info->phc_index = -1; |
| 1965 | |
| 1966 | osif_vdev_sync_op_stop(vdev_sync); |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | #if (KERNEL_VERSION(4, 1, 0) > LINUX_VERSION_CODE) |
| 1971 | /** |
| 1972 | * wlan_ptp_gettime() - return fw ts info to uplayer |
| 1973 | * @ptp: pointer to ptp_clock_info. |
| 1974 | * @ts: pointer to timespec. |
| 1975 | * |
| 1976 | * Return: Describe the execute result of this routine |
| 1977 | */ |
| 1978 | static int wlan_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts) |
| 1979 | { |
| 1980 | uint64_t host_time, target_time = 0; |
| 1981 | struct hdd_context *hdd_ctx; |
| 1982 | struct hdd_adapter *adapter; |
| 1983 | uint32_t tsf_reg_read_enabled; |
| 1984 | struct osif_psoc_sync *psoc_sync; |
| 1985 | int errno, status = 0; |
| 1986 | |
| 1987 | hdd_ctx = qdf_container_of(ptp, struct hdd_context, ptp_cinfo); |
| 1988 | errno = wlan_hdd_validate_context(hdd_ctx); |
| 1989 | if (errno) |
| 1990 | return -EINVAL; |
| 1991 | |
| 1992 | errno = osif_psoc_sync_op_start(hdd_ctx->parent_dev, &psoc_sync); |
| 1993 | if (errno) |
| 1994 | return -EAGAIN; |
| 1995 | |
| 1996 | adapter = hdd_get_adapter(hdd_ctx, QDF_P2P_GO_MODE); |
| 1997 | if (!adapter) { |
| 1998 | adapter = hdd_get_adapter(hdd_ctx, QDF_P2P_CLIENT_MODE); |
| 1999 | if (!adapter) { |
| 2000 | adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE); |
| 2001 | if (!adapter) |
| 2002 | adapter = hdd_get_adapter(hdd_ctx, |
| 2003 | QDF_STA_MODE); |
| 2004 | if (!adapter) { |
| 2005 | status = -EOPNOTSUPP; |
| 2006 | goto end; |
| 2007 | } |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
| 2012 | if (hdd_get_targettime_from_hosttime(adapter, host_time, |
| 2013 | &target_time)) { |
| 2014 | hdd_err("get invalid target timestamp"); |
| 2015 | status = -EINVAL; |
| 2016 | goto end; |
| 2017 | } |
| 2018 | *ts = ns_to_timespec(target_time * NSEC_PER_USEC); |
| 2019 | |
| 2020 | end: |
| 2021 | osif_psoc_sync_op_stop(psoc_sync); |
| 2022 | return status; |
| 2023 | } |
| 2024 | |
| 2025 | /** |
| 2026 | * wlan_hdd_phc_init() - phc init |
| 2027 | * @hdd_ctx: pointer to the hdd_contex. |
| 2028 | * |
| 2029 | * Return: NULL |
| 2030 | */ |
| 2031 | static void wlan_hdd_phc_init(struct hdd_context *hdd_ctx) |
| 2032 | { |
| 2033 | hdd_ctx->ptp_cinfo.gettime = wlan_ptp_gettime; |
| 2034 | |
| 2035 | hdd_ctx->ptp_clock = ptp_clock_register(&hdd_ctx->ptp_cinfo, |
| 2036 | hdd_ctx->parent_dev); |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * wlan_hdd_phc_deinit() - phc deinit |
| 2041 | * @hdd_ctx: pointer to the hdd_contex. |
| 2042 | * |
| 2043 | * Return: NULL |
| 2044 | */ |
| 2045 | static void wlan_hdd_phc_deinit(struct hdd_context *hdd_ctx) |
| 2046 | { |
| 2047 | hdd_ctx->ptp_cinfo.gettime = NULL; |
| 2048 | |
| 2049 | if (hdd_ctx->ptp_clock) { |
| 2050 | ptp_clock_unregister(hdd_ctx->ptp_clock); |
| 2051 | hdd_ctx->ptp_clock = NULL; |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | #else |
| 2056 | static int wlan_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts) |
| 2057 | { |
| 2058 | uint64_t host_time, target_time = 0; |
| 2059 | struct hdd_context *hdd_ctx; |
| 2060 | struct hdd_adapter *adapter; |
| 2061 | struct osif_psoc_sync *psoc_sync; |
| 2062 | int errno, status = 0; |
| 2063 | |
| 2064 | hdd_ctx = qdf_container_of(ptp, struct hdd_context, ptp_cinfo); |
| 2065 | errno = wlan_hdd_validate_context(hdd_ctx); |
| 2066 | if (errno) |
| 2067 | return -EINVAL; |
| 2068 | |
| 2069 | errno = osif_psoc_sync_op_start(hdd_ctx->parent_dev, &psoc_sync); |
| 2070 | if (errno) |
| 2071 | return -EAGAIN; |
| 2072 | |
| 2073 | adapter = hdd_get_adapter(hdd_ctx, QDF_P2P_GO_MODE); |
| 2074 | if (!adapter) { |
| 2075 | adapter = hdd_get_adapter(hdd_ctx, QDF_P2P_CLIENT_MODE); |
| 2076 | if (!adapter) { |
| 2077 | adapter = hdd_get_adapter(hdd_ctx, QDF_SAP_MODE); |
| 2078 | if (!adapter) |
| 2079 | adapter = hdd_get_adapter(hdd_ctx, |
| 2080 | QDF_STA_MODE); |
| 2081 | if (!adapter) { |
| 2082 | status = -EOPNOTSUPP; |
| 2083 | goto end; |
| 2084 | } |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | host_time = hdd_get_monotonic_host_time(hdd_ctx); |
| 2089 | if (hdd_get_targettime_from_hosttime(adapter, host_time, |
| 2090 | &target_time)) { |
| 2091 | hdd_err("get invalid target timestamp"); |
| 2092 | status = -EINVAL; |
| 2093 | goto end; |
| 2094 | } |
| 2095 | *ts = ns_to_timespec64(target_time * NSEC_PER_USEC); |
| 2096 | |
| 2097 | end: |
| 2098 | osif_psoc_sync_op_stop(psoc_sync); |
| 2099 | return status; |
| 2100 | } |
| 2101 | |
| 2102 | static void wlan_hdd_phc_init(struct hdd_context *hdd_ctx) |
| 2103 | { |
| 2104 | hdd_ctx->ptp_cinfo.gettime64 = wlan_ptp_gettime; |
| 2105 | hdd_ctx->ptp_clock = ptp_clock_register(&hdd_ctx->ptp_cinfo, |
| 2106 | hdd_ctx->parent_dev); |
| 2107 | } |
| 2108 | |
| 2109 | static void wlan_hdd_phc_deinit(struct hdd_context *hdd_ctx) |
| 2110 | { |
| 2111 | hdd_ctx->ptp_cinfo.gettime64 = NULL; |
| 2112 | |
| 2113 | if (hdd_ctx->ptp_clock) { |
| 2114 | ptp_clock_unregister(hdd_ctx->ptp_clock); |
| 2115 | hdd_ctx->ptp_clock = NULL; |
| 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | #endif |
| 2120 | #else |
| 2121 | |
| 2122 | static void wlan_hdd_phc_init(struct hdd_context *hdd_ctx) |
| 2123 | { |
| 2124 | } |
| 2125 | |
| 2126 | static void wlan_hdd_phc_deinit(struct hdd_context *hdd_ctx) |
| 2127 | { |
| 2128 | } |
| 2129 | #endif /* WLAN_FEATURE_TSF_PTP */ |
| 2130 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2131 | /** |
| 2132 | * hdd_get_tsf_cb() - handle tsf callback |
| 2133 | * @pcb_cxt: pointer to the hdd_contex |
| 2134 | * @ptsf: pointer to struct stsf |
| 2135 | * |
| 2136 | * This function handle the event that reported by firmware at first. |
| 2137 | * The event contains the vdev_id, current tsf value of this vdev, |
| 2138 | * tsf value is 64bits, discripted in two varaible tsf_low and tsf_high. |
| 2139 | * These two values each is uint32. |
| 2140 | * |
| 2141 | * Return: 0 for success or non-zero negative failure code |
| 2142 | */ |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 2143 | int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2144 | { |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 2145 | struct hdd_context *hddctx; |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 2146 | struct hdd_adapter *adapter; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2147 | int ret; |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 2148 | uint64_t tsf_sync_soc_time; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2149 | QDF_STATUS status; |
| 2150 | QDF_TIMER_STATE capture_req_timer_status; |
| 2151 | qdf_mc_timer_t *capture_timer; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2152 | |
Jeff Johnson | d36fa33 | 2019-03-18 13:42:25 -0700 | [diff] [blame] | 2153 | if (!pcb_cxt || !ptsf) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2154 | hdd_err("HDD context is not valid"); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2155 | return -EINVAL; |
| 2156 | } |
| 2157 | |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 2158 | hddctx = (struct hdd_context *)pcb_cxt; |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2159 | ret = wlan_hdd_validate_context(hddctx); |
| 2160 | if (0 != ret) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2161 | return -EINVAL; |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2162 | |
| 2163 | adapter = hdd_get_adapter_by_vdev(hddctx, ptsf->vdev_id); |
| 2164 | |
Jeff Johnson | d36fa33 | 2019-03-18 13:42:25 -0700 | [diff] [blame] | 2165 | if (!adapter) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2166 | hdd_err("failed to find adapter"); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2167 | return -EINVAL; |
| 2168 | } |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2169 | |
| 2170 | if (!hdd_tsf_is_initialized(adapter)) { |
| 2171 | hdd_err("tsf is not init, ignore tsf event"); |
| 2172 | return -EINVAL; |
| 2173 | } |
| 2174 | |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2175 | hdd_info("tsf cb handle event, device_mode is %d", |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2176 | adapter->device_mode); |
| 2177 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2178 | capture_timer = &adapter->host_capture_req_timer; |
| 2179 | capture_req_timer_status = |
| 2180 | qdf_mc_timer_get_current_state(capture_timer); |
| 2181 | if (capture_req_timer_status == QDF_TIMER_STATE_UNUSED) { |
| 2182 | hdd_warn("invalid timer status"); |
| 2183 | return -EINVAL; |
| 2184 | } |
| 2185 | |
| 2186 | qdf_mc_timer_stop(capture_timer); |
| 2187 | status = qdf_mc_timer_destroy(capture_timer); |
| 2188 | if (status != QDF_STATUS_SUCCESS) |
| 2189 | hdd_warn("destroy cap req timer fail, ret: %d", status); |
| 2190 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2191 | adapter->cur_target_time = ((uint64_t)ptsf->tsf_high << 32 | |
| 2192 | ptsf->tsf_low); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2193 | |
Jiani Liu | a8fd170 | 2019-05-01 10:07:10 +0800 | [diff] [blame] | 2194 | adapter->cur_target_global_tsf_time = |
| 2195 | ((uint64_t)ptsf->global_tsf_high << 32 | |
| 2196 | ptsf->global_tsf_low); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 2197 | tsf_sync_soc_time = ((uint64_t)ptsf->soc_timer_high << 32 | |
| 2198 | ptsf->soc_timer_low); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 2199 | adapter->cur_tsf_sync_soc_time = |
| 2200 | qdf_log_timestamp_to_usecs(tsf_sync_soc_time) * NSEC_PER_USEC; |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2201 | complete(&tsf_sync_get_completion_evt); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 2202 | hdd_update_tsf(adapter, adapter->cur_target_time); |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 2203 | hdd_info("Vdev=%u, tsf_low=%u, tsf_high=%u ptsf->soc_timer_low=%u ptsf->soc_timer_high=%u", |
| 2204 | ptsf->vdev_id, ptsf->tsf_low, ptsf->tsf_high, |
| 2205 | ptsf->soc_timer_low, ptsf->soc_timer_high); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2206 | return 0; |
| 2207 | } |
| 2208 | |
Jeff Johnson | 363764f | 2017-06-02 13:43:36 -0700 | [diff] [blame] | 2209 | static const struct nla_policy tsf_policy[QCA_WLAN_VENDOR_ATTR_TSF_MAX + 1] = { |
| 2210 | [QCA_WLAN_VENDOR_ATTR_TSF_CMD] = {.type = NLA_U32}, |
| 2211 | }; |
| 2212 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2213 | /** |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2214 | * __wlan_hdd_cfg80211_handle_tsf_cmd(): Setup TSF operations |
| 2215 | * @wiphy: Pointer to wireless phy |
| 2216 | * @wdev: Pointer to wireless device |
| 2217 | * @data: Pointer to data |
| 2218 | * @data_len: Data length |
| 2219 | * |
| 2220 | * Handle TSF SET / GET operation from userspace |
| 2221 | * |
| 2222 | * Return: 0 on success, negative errno on failure |
| 2223 | */ |
| 2224 | static int __wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 2225 | struct wireless_dev *wdev, |
| 2226 | const void *data, |
| 2227 | int data_len) |
| 2228 | { |
| 2229 | struct net_device *dev = wdev->netdev; |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 2230 | struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 2231 | struct hdd_context *hdd_ctx = wiphy_priv(wiphy); |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2232 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_TSF_MAX + 1]; |
| 2233 | int status, ret; |
| 2234 | struct sk_buff *reply_skb; |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 2235 | uint32_t tsf_op_resp[3] = {0}, tsf_cmd; |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2236 | |
Dustin Brown | fdf17c1 | 2018-03-14 12:55:34 -0700 | [diff] [blame] | 2237 | hdd_enter_dev(wdev->netdev); |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2238 | |
| 2239 | status = wlan_hdd_validate_context(hdd_ctx); |
| 2240 | if (0 != status) |
| 2241 | return -EINVAL; |
| 2242 | |
Dustin Brown | 4ea21db | 2018-01-05 14:13:17 -0800 | [diff] [blame] | 2243 | if (wlan_cfg80211_nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_TSF_MAX, |
| 2244 | data, data_len, tsf_policy)) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2245 | hdd_err("Invalid TSF cmd"); |
| 2246 | return -EINVAL; |
| 2247 | } |
| 2248 | |
| 2249 | if (!tb_vendor[QCA_WLAN_VENDOR_ATTR_TSF_CMD]) { |
| 2250 | hdd_err("Invalid TSF cmd"); |
| 2251 | return -EINVAL; |
| 2252 | } |
| 2253 | tsf_cmd = nla_get_u32(tb_vendor[QCA_WLAN_VENDOR_ATTR_TSF_CMD]); |
| 2254 | |
| 2255 | if (tsf_cmd == QCA_TSF_CAPTURE || tsf_cmd == QCA_TSF_SYNC_GET) { |
| 2256 | hdd_capture_tsf(adapter, tsf_op_resp, 1); |
| 2257 | switch (tsf_op_resp[0]) { |
| 2258 | case TSF_RETURN: |
| 2259 | status = 0; |
| 2260 | break; |
| 2261 | case TSF_CURRENT_IN_CAP_STATE: |
| 2262 | status = -EALREADY; |
| 2263 | break; |
| 2264 | case TSF_STA_NOT_CONNECTED_NO_TSF: |
| 2265 | case TSF_SAP_NOT_STARTED_NO_TSF: |
| 2266 | status = -EPERM; |
| 2267 | break; |
| 2268 | default: |
| 2269 | case TSF_CAPTURE_FAIL: |
| 2270 | status = -EINVAL; |
| 2271 | break; |
| 2272 | } |
| 2273 | } |
| 2274 | if (status < 0) |
| 2275 | goto end; |
| 2276 | |
| 2277 | if (tsf_cmd == QCA_TSF_SYNC_GET) { |
| 2278 | ret = wait_for_completion_timeout(&tsf_sync_get_completion_evt, |
| 2279 | msecs_to_jiffies(WLAN_TSF_SYNC_GET_TIMEOUT)); |
| 2280 | if (ret == 0) { |
| 2281 | status = -ETIMEDOUT; |
| 2282 | goto end; |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | if (tsf_cmd == QCA_TSF_GET || tsf_cmd == QCA_TSF_SYNC_GET) { |
| 2287 | hdd_indicate_tsf(adapter, tsf_op_resp, 3); |
| 2288 | switch (tsf_op_resp[0]) { |
| 2289 | case TSF_RETURN: |
| 2290 | status = 0; |
| 2291 | break; |
| 2292 | case TSF_NOT_RETURNED_BY_FW: |
| 2293 | status = -EINPROGRESS; |
| 2294 | break; |
| 2295 | case TSF_STA_NOT_CONNECTED_NO_TSF: |
| 2296 | case TSF_SAP_NOT_STARTED_NO_TSF: |
| 2297 | status = -EPERM; |
| 2298 | break; |
| 2299 | default: |
| 2300 | status = -EINVAL; |
| 2301 | break; |
| 2302 | } |
| 2303 | if (status != 0) |
| 2304 | goto end; |
| 2305 | |
| 2306 | reply_skb = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL, |
| 2307 | sizeof(uint64_t) * 2 + NLMSG_HDRLEN, |
| 2308 | QCA_NL80211_VENDOR_SUBCMD_TSF_INDEX, |
| 2309 | GFP_KERNEL); |
| 2310 | if (!reply_skb) { |
| 2311 | hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed"); |
| 2312 | status = -ENOMEM; |
| 2313 | goto end; |
| 2314 | } |
Dustin Brown | bb7e2f5 | 2016-10-17 12:16:35 -0700 | [diff] [blame] | 2315 | if (hdd_wlan_nla_put_u64(reply_skb, |
| 2316 | QCA_WLAN_VENDOR_ATTR_TSF_TIMER_VALUE, |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2317 | adapter->cur_target_time) || |
Dustin Brown | bb7e2f5 | 2016-10-17 12:16:35 -0700 | [diff] [blame] | 2318 | hdd_wlan_nla_put_u64(reply_skb, |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2319 | QCA_WLAN_VENDOR_ATTR_TSF_SOC_TIMER_VALUE, |
yuanl | 69575bb | 2019-01-24 19:16:28 +0800 | [diff] [blame] | 2320 | adapter->cur_tsf_sync_soc_time)) { |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2321 | hdd_err("nla put fail"); |
| 2322 | kfree_skb(reply_skb); |
| 2323 | status = -EINVAL; |
| 2324 | goto end; |
| 2325 | } |
| 2326 | status = cfg80211_vendor_cmd_reply(reply_skb); |
| 2327 | } |
| 2328 | |
| 2329 | end: |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2330 | hdd_info("TSF operation %d status: %d", tsf_cmd, status); |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2331 | return status; |
| 2332 | } |
| 2333 | |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2334 | int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 2335 | struct wireless_dev *wdev, |
| 2336 | const void *data, |
| 2337 | int data_len) |
| 2338 | { |
Dustin Brown | a09acf4 | 2018-11-08 12:32:26 +0530 | [diff] [blame] | 2339 | int errno; |
| 2340 | struct osif_vdev_sync *vdev_sync; |
| 2341 | |
| 2342 | errno = osif_vdev_sync_op_start(wdev->netdev, &vdev_sync); |
| 2343 | if (errno) |
| 2344 | return errno; |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2345 | |
Dustin Brown | a09acf4 | 2018-11-08 12:32:26 +0530 | [diff] [blame] | 2346 | errno = __wlan_hdd_cfg80211_handle_tsf_cmd(wiphy, wdev, data, data_len); |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2347 | |
Dustin Brown | a09acf4 | 2018-11-08 12:32:26 +0530 | [diff] [blame] | 2348 | osif_vdev_sync_op_stop(vdev_sync); |
| 2349 | |
| 2350 | return errno; |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | /** |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2354 | * wlan_hdd_tsf_init() - set callback to handle tsf value. |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 2355 | * @hdd_ctx: pointer to the struct hdd_context |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2356 | * |
| 2357 | * This function set the callback to sme module, the callback will be |
| 2358 | * called when a tsf event is reported by firmware |
| 2359 | * |
| 2360 | * Return: none |
| 2361 | */ |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 2362 | void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2363 | { |
Jeff Johnson | ad278e6 | 2018-06-14 11:11:24 -0700 | [diff] [blame] | 2364 | QDF_STATUS status; |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2365 | |
| 2366 | if (!hdd_ctx) |
| 2367 | return; |
| 2368 | |
| 2369 | if (qdf_atomic_inc_return(&hdd_ctx->tsf_ready_flag) > 1) |
| 2370 | return; |
| 2371 | |
| 2372 | qdf_atomic_init(&hdd_ctx->cap_tsf_flag); |
| 2373 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame] | 2374 | status = hdd_tsf_set_gpio(hdd_ctx); |
Sourav Mohapatra | 0f3b857 | 2018-09-12 10:03:51 +0530 | [diff] [blame] | 2375 | |
Jeff Johnson | ad278e6 | 2018-06-14 11:11:24 -0700 | [diff] [blame] | 2376 | if (QDF_STATUS_SUCCESS != status) { |
| 2377 | hdd_err("set tsf GPIO failed, status: %d", status); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2378 | goto fail; |
| 2379 | } |
| 2380 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 2381 | if (wlan_hdd_tsf_plus_init(hdd_ctx) != HDD_TSF_OP_SUCC) |
| 2382 | goto fail; |
| 2383 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 2384 | if (hdd_tsf_is_ptp_enabled(hdd_ctx)) |
| 2385 | wlan_hdd_phc_init(hdd_ctx); |
Subrat Dash | 5f36fbe | 2019-02-12 16:28:14 +0530 | [diff] [blame] | 2386 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2387 | return; |
| 2388 | |
| 2389 | fail: |
| 2390 | qdf_atomic_set(&hdd_ctx->tsf_ready_flag, 0); |
| 2391 | } |
| 2392 | |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 2393 | void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2394 | { |
| 2395 | if (!hdd_ctx) |
| 2396 | return; |
| 2397 | |
| 2398 | if (!qdf_atomic_read(&hdd_ctx->tsf_ready_flag)) |
| 2399 | return; |
| 2400 | |
Subrat Dash | b1e61b2 | 2019-07-22 14:09:34 +0530 | [diff] [blame] | 2401 | if (hdd_tsf_is_ptp_enabled(hdd_ctx)) |
| 2402 | wlan_hdd_phc_deinit(hdd_ctx); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 2403 | wlan_hdd_tsf_plus_deinit(hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 2404 | qdf_atomic_set(&hdd_ctx->tsf_ready_flag, 0); |
| 2405 | qdf_atomic_set(&hdd_ctx->cap_tsf_flag, 0); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 2406 | } |