Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 1 | /* |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 2 | * Copyright (c) 2016-2018 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" |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 22 | #include "wlan_hdd_main.h" |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 23 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 24 | /** |
| 25 | * enum hdd_tsf_get_state - status of get tsf action |
| 26 | * @TSF_RETURN: get tsf |
| 27 | * @TSF_STA_NOT_CONNECTED_NO_TSF: sta not connected to ap |
| 28 | * @TSF_NOT_RETURNED_BY_FW: fw not returned tsf |
| 29 | * @TSF_CURRENT_IN_CAP_STATE: driver in capture state |
| 30 | * @TSF_CAPTURE_FAIL: capture fail |
| 31 | * @TSF_GET_FAIL: get fail |
| 32 | * @TSF_RESET_GPIO_FAIL: GPIO reset fail |
| 33 | * @TSF_SAP_NOT_STARTED_NO_TSF SAP not started |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 34 | * @TSF_NOT_READY: TSF module is not initialized or init failed |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 35 | * @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] | 36 | */ |
| 37 | enum hdd_tsf_get_state { |
| 38 | TSF_RETURN = 0, |
| 39 | TSF_STA_NOT_CONNECTED_NO_TSF, |
| 40 | TSF_NOT_RETURNED_BY_FW, |
| 41 | TSF_CURRENT_IN_CAP_STATE, |
| 42 | TSF_CAPTURE_FAIL, |
| 43 | TSF_GET_FAIL, |
| 44 | TSF_RESET_GPIO_FAIL, |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 45 | TSF_SAP_NOT_STARTED_NO_TSF, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 46 | TSF_NOT_READY, |
| 47 | TSF_DISABLED_BY_TSFPLUS |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * enum hdd_tsf_capture_state - status of capture |
| 52 | * @TSF_IDLE: idle |
| 53 | * @TSF_CAP_STATE: current is in capture state |
| 54 | */ |
| 55 | enum hdd_tsf_capture_state { |
| 56 | TSF_IDLE = 0, |
| 57 | TSF_CAP_STATE |
| 58 | }; |
| 59 | |
| 60 | #ifdef WLAN_FEATURE_TSF |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 61 | /** |
| 62 | * wlan_hdd_tsf_init() - set gpio and callbacks for |
| 63 | * capturing tsf and init tsf_plus |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 64 | * @hdd_ctx: pointer to the struct hdd_context |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 65 | * |
| 66 | * This function set the callback to sme module, the callback will be |
| 67 | * called when a tsf event is reported by firmware; set gpio number |
| 68 | * to FW, FW will toggle this gpio when received a CAP_TSF command; |
| 69 | * do tsf_plus init |
| 70 | * |
| 71 | * Return: nothing |
| 72 | */ |
Jeff Johnson | 82797b6 | 2017-08-11 15:31:27 -0700 | [diff] [blame] | 73 | void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * wlan_hdd_tsf_deinit() - reset callbacks for capturing tsf, deinit tsf_plus |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 77 | * @hdd_ctx: pointer to the struct hdd_context |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 78 | * |
| 79 | * This function reset the callback to sme module, and deinit tsf_plus |
| 80 | * |
| 81 | * Return: nothing |
| 82 | */ |
Jeff Johnson | 854cccd | 2017-08-28 11:39:24 -0700 | [diff] [blame] | 83 | void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * hdd_capture_tsf() - capture tsf |
| 87 | * @adapter: pointer to adapter |
| 88 | * @buf: pointer to uplayer buf |
| 89 | * @len : the length of buf |
| 90 | * |
| 91 | * This function returns tsf value to uplayer. |
| 92 | * |
| 93 | * Return: 0 for success or non-zero negative failure code |
| 94 | */ |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 95 | 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] | 96 | |
| 97 | /** |
| 98 | * hdd_indicate_tsf() - return tsf to uplayer |
| 99 | * |
| 100 | * @adapter: pointer to adapter |
| 101 | * @buf: pointer to uplayer buf |
| 102 | * @len : the length of buf |
| 103 | * |
| 104 | * This function returns tsf value to uplayer. |
| 105 | * |
| 106 | * Return: Describe the execute result of this routine |
| 107 | */ |
Jeff Johnson | 85b5c11 | 2017-08-11 15:15:23 -0700 | [diff] [blame] | 108 | 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] | 109 | |
| 110 | /** |
| 111 | * wlan_hdd_cfg80211_handle_tsf_cmd(): Setup TSF operations |
| 112 | * @wiphy: Pointer to wireless phy |
| 113 | * @wdev: Pointer to wireless device |
| 114 | * @data: Pointer to data |
| 115 | * @data_len: Data length |
| 116 | * |
| 117 | * Handle TSF SET / GET operation from userspace |
| 118 | * |
| 119 | * Return: 0 on success, negative errno on failure |
| 120 | */ |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 121 | int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 122 | struct wireless_dev *wdev, |
| 123 | const void *data, |
| 124 | int data_len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 125 | |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 126 | int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf); |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 127 | |
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) |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 164 | /** |
| 165 | * hdd_tsf_is_ptp_enabled() - check ini configuration |
| 166 | * @hdd: pointer to hdd context |
| 167 | * |
| 168 | * This function checks tsf configuration for ptp |
| 169 | * |
| 170 | * Return: true on enable, false on disable |
| 171 | */ |
| 172 | bool hdd_tsf_is_ptp_enabled(struct hdd_context *hdd); |
| 173 | /** |
| 174 | * hdd_tsf_is_tx_set() - check ini configuration |
| 175 | * @hdd: pointer to hdd context |
| 176 | * |
| 177 | * This function checks tsf configuration for ptp on tx |
| 178 | * |
| 179 | * Return: true on enable, false on disable |
| 180 | */ |
Yu Wang | 66a250b | 2017-07-19 11:46:40 +0800 | [diff] [blame] | 181 | |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 182 | bool hdd_tsf_is_tx_set(struct hdd_context *hdd); |
| 183 | /** |
| 184 | * hdd_tsf_is_rx_set() - check ini configuration |
| 185 | * @hdd: pointer to hdd context |
| 186 | * |
| 187 | * This function checks tsf configuration for ptp on rx |
| 188 | * |
| 189 | * Return: true on enable, false on disable |
| 190 | */ |
| 191 | bool hdd_tsf_is_rx_set(struct hdd_context *hdd); |
| 192 | /** |
| 193 | * hdd_tsf_is_raw_set() - check ini configuration |
| 194 | * @hdd: pointer to hdd context |
| 195 | * |
| 196 | * This function checks tsf configuration for ptp on raw |
| 197 | * |
| 198 | * Return: true on enable, false on disable |
| 199 | */ |
| 200 | bool hdd_tsf_is_raw_set(struct hdd_context *hdd); |
| 201 | /** |
| 202 | * hdd_tsf_is_dbg_fs_set() - check ini configuration |
| 203 | * @hdd: pointer to hdd context |
| 204 | * |
| 205 | * This function checks tsf configuration for ptp on dbg fs |
| 206 | * |
| 207 | * Return: true on enable, false on disable |
| 208 | */ |
| 209 | bool hdd_tsf_is_dbg_fs_set(struct hdd_context *hdd); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * hdd_start_tsf_sync() - start tsf sync |
| 213 | * @adapter: pointer to adapter |
| 214 | * |
| 215 | * This function initialize and start TSF synchronization |
| 216 | * |
| 217 | * Return: Describe the execute result of this routine |
| 218 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 219 | int hdd_start_tsf_sync(struct hdd_adapter *adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * hdd_stop_tsf_sync() - stop tsf sync |
| 223 | * @adapter: pointer to adapter |
| 224 | * |
| 225 | * This function stop and de-initialize TSF synchronization |
| 226 | * |
| 227 | * Return: Describe the execute result of this routine |
| 228 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 229 | int hdd_stop_tsf_sync(struct hdd_adapter *adapter); |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 230 | |
| 231 | /** |
| 232 | * hdd_tsf_notify_wlan_state_change() - |
| 233 | * notify tsf module of wlan connection state |
| 234 | * @old_state: old wlan state |
| 235 | * @new_state: new wlan state |
| 236 | * |
| 237 | * This function check the old and new connection state, determine whether |
| 238 | * to start or stop tsf sync |
| 239 | * |
| 240 | * Return: nothing |
| 241 | */ |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 242 | void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 243 | eConnectionState old_state, |
| 244 | eConnectionState new_state); |
| 245 | |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 246 | /** |
| 247 | * hdd_tx_timestamp() - time stamp TX netbuf |
| 248 | * |
| 249 | * @netbuf: pointer to a TX netbuf |
| 250 | * @target_time: TX time for the netbuf |
| 251 | * |
| 252 | * This function get corresponding host time from target time, |
| 253 | * and time stamp the TX netbuf with this time |
| 254 | * |
| 255 | * Return: Describe the execute result of this routine |
| 256 | */ |
| 257 | int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time); |
| 258 | |
| 259 | /** |
| 260 | * hdd_rx_timestamp() - time stamp RX netbuf |
| 261 | * |
| 262 | * @netbuf: pointer to a RX netbuf |
| 263 | * @target_time: RX time for the netbuf |
| 264 | * |
| 265 | * This function get corresponding host time from target time, |
| 266 | * and time stamp the RX netbuf with this time |
| 267 | * |
| 268 | * Return: Describe the execute result of this routine |
| 269 | */ |
| 270 | int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time); |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 271 | /** |
| 272 | * hdd_capture_req_timer_expired_handler() - capture req timer handler |
| 273 | * @arg: pointer to a adapter |
| 274 | * |
| 275 | * This function set a timeout handler for TSF capture timer. |
| 276 | * |
| 277 | * Return: none |
| 278 | */ |
| 279 | |
| 280 | void hdd_capture_req_timer_expired_handler(void *arg); |
| 281 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 282 | #else |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 283 | static inline int hdd_start_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 284 | { |
| 285 | return -ENOTSUPP; |
| 286 | } |
| 287 | |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 288 | static inline int hdd_stop_tsf_sync(struct hdd_adapter *adapter) |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 289 | { |
| 290 | return -ENOTSUPP; |
| 291 | } |
| 292 | |
| 293 | static inline |
Jeff Johnson | 8f38986 | 2017-08-29 14:19:23 -0700 | [diff] [blame] | 294 | void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 295 | eConnectionState old_state, |
| 296 | eConnectionState new_state) |
| 297 | |
| 298 | { |
| 299 | } |
Yu Wang | 04ccd76 | 2017-05-31 19:29:43 +0800 | [diff] [blame] | 300 | |
| 301 | static inline |
| 302 | int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 303 | { |
| 304 | return -ENOTSUPP; |
| 305 | } |
| 306 | |
| 307 | static inline |
| 308 | int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time) |
| 309 | { |
| 310 | return -ENOTSUPP; |
| 311 | } |
yuanl | 2746f07 | 2018-09-21 19:19:16 +0800 | [diff] [blame^] | 312 | |
| 313 | static inline |
| 314 | void hdd_capture_req_timer_expired_handler(void *arg) |
| 315 | { |
| 316 | } |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame] | 317 | #endif |
| 318 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 319 | #endif |