Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 1 | /* |
Srinivas Girigowda | ad005ab | 2017-03-25 00:47:37 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2017 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 | #if !defined WLAN_HDD_TSF_H |
| 20 | #define WLAN_HDD_TSF_H |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 21 | #include "wlan_hdd_cfg.h" |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 22 | |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 23 | struct hdd_context; |
| 24 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 25 | /** |
| 26 | * enum hdd_tsf_get_state - status of get tsf action |
| 27 | * @TSF_RETURN: get tsf |
| 28 | * @TSF_STA_NOT_CONNECTED_NO_TSF: sta not connected to ap |
| 29 | * @TSF_NOT_RETURNED_BY_FW: fw not returned tsf |
| 30 | * @TSF_CURRENT_IN_CAP_STATE: driver in capture state |
| 31 | * @TSF_CAPTURE_FAIL: capture fail |
| 32 | * @TSF_GET_FAIL: get fail |
| 33 | * @TSF_RESET_GPIO_FAIL: GPIO reset fail |
| 34 | * @TSF_SAP_NOT_STARTED_NO_TSF SAP not started |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 35 | * @TSF_NOT_READY: TSF module is not initialized or init failed |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 36 | * @TSF_DISABLED_BY_TSFPLUS: cap_tsf/get_tsf are disabled due to TSF_PLUS |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 37 | */ |
| 38 | enum hdd_tsf_get_state { |
| 39 | TSF_RETURN = 0, |
| 40 | TSF_STA_NOT_CONNECTED_NO_TSF, |
| 41 | TSF_NOT_RETURNED_BY_FW, |
| 42 | TSF_CURRENT_IN_CAP_STATE, |
| 43 | TSF_CAPTURE_FAIL, |
| 44 | TSF_GET_FAIL, |
| 45 | TSF_RESET_GPIO_FAIL, |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 46 | TSF_SAP_NOT_STARTED_NO_TSF, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 47 | TSF_NOT_READY, |
| 48 | TSF_DISABLED_BY_TSFPLUS |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * enum hdd_tsf_capture_state - status of capture |
| 53 | * @TSF_IDLE: idle |
| 54 | * @TSF_CAP_STATE: current is in capture state |
| 55 | */ |
| 56 | enum hdd_tsf_capture_state { |
| 57 | TSF_IDLE = 0, |
| 58 | TSF_CAP_STATE |
| 59 | }; |
| 60 | |
| 61 | #ifdef WLAN_FEATURE_TSF |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 62 | /** |
| 63 | * wlan_hdd_tsf_init() - set gpio and callbacks for |
| 64 | * capturing tsf and init tsf_plus |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 65 | * @hdd_ctx: pointer to the struct hdd_context |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 66 | * |
| 67 | * This function set the callback to sme module, the callback will be |
| 68 | * called when a tsf event is reported by firmware; set gpio number |
| 69 | * to FW, FW will toggle this gpio when received a CAP_TSF command; |
| 70 | * do tsf_plus init |
| 71 | * |
| 72 | * Return: nothing |
| 73 | */ |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 74 | void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * wlan_hdd_tsf_deinit() - reset callbacks for capturing tsf, deinit tsf_plus |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 78 | * @hdd_ctx: pointer to the struct hdd_context |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 79 | * |
| 80 | * This function reset the callback to sme module, and deinit tsf_plus |
| 81 | * |
| 82 | * Return: nothing |
| 83 | */ |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 84 | void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * hdd_capture_tsf() - capture tsf |
| 88 | * @adapter: pointer to adapter |
| 89 | * @buf: pointer to uplayer buf |
| 90 | * @len : the length of buf |
| 91 | * |
| 92 | * This function returns tsf value to uplayer. |
| 93 | * |
| 94 | * Return: 0 for success or non-zero negative failure code |
| 95 | */ |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 96 | int hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * hdd_indicate_tsf() - return tsf to uplayer |
| 100 | * |
| 101 | * @adapter: pointer to adapter |
| 102 | * @buf: pointer to uplayer buf |
| 103 | * @len : the length of buf |
| 104 | * |
| 105 | * This function returns tsf value to uplayer. |
| 106 | * |
| 107 | * Return: Describe the execute result of this routine |
| 108 | */ |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 109 | 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] | 110 | |
| 111 | /** |
| 112 | * wlan_hdd_cfg80211_handle_tsf_cmd(): Setup TSF operations |
| 113 | * @wiphy: Pointer to wireless phy |
| 114 | * @wdev: Pointer to wireless device |
| 115 | * @data: Pointer to data |
| 116 | * @data_len: Data length |
| 117 | * |
| 118 | * Handle TSF SET / GET operation from userspace |
| 119 | * |
| 120 | * Return: 0 on success, negative errno on failure |
| 121 | */ |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 122 | int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 123 | struct wireless_dev *wdev, |
| 124 | const void *data, |
| 125 | int data_len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 126 | |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 127 | int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 128 | #else |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 129 | static inline void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 130 | { |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 133 | static inline void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx) |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 134 | { |
| 135 | } |
| 136 | |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 137 | static inline int hdd_indicate_tsf(struct hdd_adapter *adapter, uint32_t *buf, |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 138 | int len) |
| 139 | { |
| 140 | return -ENOTSUPP; |
| 141 | } |
| 142 | |
| 143 | static inline int |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 144 | hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len) |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 145 | { |
| 146 | return -ENOTSUPP; |
| 147 | } |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 148 | |
| 149 | static inline int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 150 | struct wireless_dev *wdev, |
| 151 | const void *data, |
| 152 | int data_len) |
| 153 | { |
| 154 | return -ENOTSUPP; |
| 155 | } |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 156 | static inline int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf) |
| 157 | { |
| 158 | return -ENOTSUPP; |
| 159 | } |
| 160 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 161 | #endif |
| 162 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 163 | #if defined(WLAN_FEATURE_TSF_PLUS) && defined(WLAN_FEATURE_TSF) |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 164 | #define HDD_TSF_IS_PTP_ENABLED(hdd) \ |
| 165 | ({ \ |
| 166 | struct hdd_context *hdd_ctx = (hdd); \ |
| 167 | hdd_ctx && hdd_ctx->config && hdd_ctx->config->tsf_ptp_options; \ |
| 168 | }) |
| 169 | |
| 170 | #define HDD_TSF_IS_TX_SET(hdd) \ |
| 171 | ({ \ |
| 172 | struct hdd_context *hdd_ctx = (hdd); \ |
| 173 | hdd_ctx && hdd_ctx->config && \ |
| 174 | (hdd_ctx->config->tsf_ptp_options & CFG_SET_TSF_PTP_OPT_TX); \ |
| 175 | }) |
| 176 | |
| 177 | #define HDD_TSF_IS_RX_SET(hdd) \ |
| 178 | ({ \ |
| 179 | struct hdd_context *hdd_ctx = (hdd); \ |
| 180 | hdd_ctx && hdd_ctx->config && \ |
| 181 | (hdd_ctx->config->tsf_ptp_options & CFG_SET_TSF_PTP_OPT_RX); \ |
| 182 | }) |
| 183 | |
| 184 | #define HDD_TSF_IS_RAW_SET(hdd) \ |
| 185 | ({ \ |
| 186 | struct hdd_context *hdd_ctx = (hdd); \ |
| 187 | hdd_ctx && hdd_ctx->config && \ |
| 188 | (hdd_ctx->config->tsf_ptp_options & CFG_SET_TSF_PTP_OPT_RAW); \ |
| 189 | }) |
| 190 | |
| 191 | #define HDD_TSF_IS_DBG_FS_SET(hdd) \ |
| 192 | ({ \ |
| 193 | struct hdd_context *hdd_ctx = (hdd); \ |
| 194 | hdd_ctx && hdd_ctx->config && \ |
| 195 | (hdd_ctx->config->tsf_ptp_options & CFG_SET_TSF_DBG_FS); \ |
| 196 | }) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * hdd_start_tsf_sync() - start tsf sync |
| 200 | * @adapter: pointer to adapter |
| 201 | * |
| 202 | * This function initialize and start TSF synchronization |
| 203 | * |
| 204 | * Return: Describe the execute result of this routine |
| 205 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 206 | int hdd_start_tsf_sync(struct hdd_adapter *adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * hdd_stop_tsf_sync() - stop tsf sync |
| 210 | * @adapter: pointer to adapter |
| 211 | * |
| 212 | * This function stop and de-initialize TSF synchronization |
| 213 | * |
| 214 | * Return: Describe the execute result of this routine |
| 215 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 216 | int hdd_stop_tsf_sync(struct hdd_adapter *adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 217 | |
| 218 | /** |
| 219 | * hdd_tsf_notify_wlan_state_change() - |
| 220 | * notify tsf module of wlan connection state |
| 221 | * @old_state: old wlan state |
| 222 | * @new_state: new wlan state |
| 223 | * |
| 224 | * This function check the old and new connection state, determine whether |
| 225 | * to start or stop tsf sync |
| 226 | * |
| 227 | * Return: nothing |
| 228 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 229 | void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 230 | eConnectionState old_state, |
| 231 | eConnectionState new_state); |
| 232 | |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 233 | /** |
| 234 | * hdd_tx_timestamp() - time stamp TX netbuf |
| 235 | * |
| 236 | * @netbuf: pointer to a TX netbuf |
| 237 | * @target_time: TX time for the netbuf |
| 238 | * |
| 239 | * This function get corresponding host time from target time, |
| 240 | * and time stamp the TX netbuf with this time |
| 241 | * |
| 242 | * Return: Describe the execute result of this routine |
| 243 | */ |
| 244 | int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time); |
| 245 | |
| 246 | /** |
| 247 | * hdd_rx_timestamp() - time stamp RX netbuf |
| 248 | * |
| 249 | * @netbuf: pointer to a RX netbuf |
| 250 | * @target_time: RX time for the netbuf |
| 251 | * |
| 252 | * This function get corresponding host time from target time, |
| 253 | * and time stamp the RX netbuf with this time |
| 254 | * |
| 255 | * Return: Describe the execute result of this routine |
| 256 | */ |
| 257 | int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 258 | #else |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 259 | static inline int hdd_start_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 260 | { |
| 261 | return -ENOTSUPP; |
| 262 | } |
| 263 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 264 | static inline int hdd_stop_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 265 | { |
| 266 | return -ENOTSUPP; |
| 267 | } |
| 268 | |
| 269 | static inline |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 270 | void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 271 | eConnectionState old_state, |
| 272 | eConnectionState new_state) |
| 273 | |
| 274 | { |
| 275 | } |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 276 | |
| 277 | static inline |
| 278 | int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 279 | { |
| 280 | return -ENOTSUPP; |
| 281 | } |
| 282 | |
| 283 | static inline |
| 284 | int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 285 | { |
| 286 | return -ENOTSUPP; |
| 287 | } |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 288 | #endif |
| 289 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 290 | #endif |