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 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | #if !defined WLAN_HDD_TSF_H |
| 29 | #define WLAN_HDD_TSF_H |
| 30 | |
| 31 | /** |
| 32 | * enum hdd_tsf_get_state - status of get tsf action |
| 33 | * @TSF_RETURN: get tsf |
| 34 | * @TSF_STA_NOT_CONNECTED_NO_TSF: sta not connected to ap |
| 35 | * @TSF_NOT_RETURNED_BY_FW: fw not returned tsf |
| 36 | * @TSF_CURRENT_IN_CAP_STATE: driver in capture state |
| 37 | * @TSF_CAPTURE_FAIL: capture fail |
| 38 | * @TSF_GET_FAIL: get fail |
| 39 | * @TSF_RESET_GPIO_FAIL: GPIO reset fail |
| 40 | * @TSF_SAP_NOT_STARTED_NO_TSF SAP not started |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 41 | * @TSF_NOT_READY: TSF module is not initialized or init failed |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame^] | 42 | * @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] | 43 | */ |
| 44 | enum hdd_tsf_get_state { |
| 45 | TSF_RETURN = 0, |
| 46 | TSF_STA_NOT_CONNECTED_NO_TSF, |
| 47 | TSF_NOT_RETURNED_BY_FW, |
| 48 | TSF_CURRENT_IN_CAP_STATE, |
| 49 | TSF_CAPTURE_FAIL, |
| 50 | TSF_GET_FAIL, |
| 51 | TSF_RESET_GPIO_FAIL, |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 52 | TSF_SAP_NOT_STARTED_NO_TSF, |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame^] | 53 | TSF_NOT_READY, |
| 54 | TSF_DISABLED_BY_TSFPLUS |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * enum hdd_tsf_capture_state - status of capture |
| 59 | * @TSF_IDLE: idle |
| 60 | * @TSF_CAP_STATE: current is in capture state |
| 61 | */ |
| 62 | enum hdd_tsf_capture_state { |
| 63 | TSF_IDLE = 0, |
| 64 | TSF_CAP_STATE |
| 65 | }; |
| 66 | |
| 67 | #ifdef WLAN_FEATURE_TSF |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 68 | /** |
| 69 | * wlan_hdd_tsf_init() - set gpio and callbacks for |
| 70 | * capturing tsf and init tsf_plus |
| 71 | * @hdd_ctx: pointer to the hdd_context_t |
| 72 | * |
| 73 | * This function set the callback to sme module, the callback will be |
| 74 | * called when a tsf event is reported by firmware; set gpio number |
| 75 | * to FW, FW will toggle this gpio when received a CAP_TSF command; |
| 76 | * do tsf_plus init |
| 77 | * |
| 78 | * Return: nothing |
| 79 | */ |
Jeff Johnson | dde3449 | 2016-10-05 16:28:04 -0700 | [diff] [blame] | 80 | void wlan_hdd_tsf_init(struct hdd_context_s *hdd_ctx); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * wlan_hdd_tsf_deinit() - reset callbacks for capturing tsf, deinit tsf_plus |
| 84 | * @hdd_ctx: pointer to the hdd_context_t |
| 85 | * |
| 86 | * This function reset the callback to sme module, and deinit tsf_plus |
| 87 | * |
| 88 | * Return: nothing |
| 89 | */ |
| 90 | void wlan_hdd_tsf_deinit(hdd_context_t *hdd_ctx); |
| 91 | |
| 92 | /** |
| 93 | * hdd_capture_tsf() - capture tsf |
| 94 | * @adapter: pointer to adapter |
| 95 | * @buf: pointer to uplayer buf |
| 96 | * @len : the length of buf |
| 97 | * |
| 98 | * This function returns tsf value to uplayer. |
| 99 | * |
| 100 | * Return: 0 for success or non-zero negative failure code |
| 101 | */ |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 102 | int hdd_capture_tsf(struct hdd_adapter_s *adapter, uint32_t *buf, int len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * hdd_indicate_tsf() - return tsf to uplayer |
| 106 | * |
| 107 | * @adapter: pointer to adapter |
| 108 | * @buf: pointer to uplayer buf |
| 109 | * @len : the length of buf |
| 110 | * |
| 111 | * This function returns tsf value to uplayer. |
| 112 | * |
| 113 | * Return: Describe the execute result of this routine |
| 114 | */ |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 115 | int hdd_indicate_tsf(struct hdd_adapter_s *adapter, uint32_t *buf, int len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * wlan_hdd_cfg80211_handle_tsf_cmd(): Setup TSF operations |
| 119 | * @wiphy: Pointer to wireless phy |
| 120 | * @wdev: Pointer to wireless device |
| 121 | * @data: Pointer to data |
| 122 | * @data_len: Data length |
| 123 | * |
| 124 | * Handle TSF SET / GET operation from userspace |
| 125 | * |
| 126 | * Return: 0 on success, negative errno on failure |
| 127 | */ |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 128 | int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 129 | struct wireless_dev *wdev, |
| 130 | const void *data, |
| 131 | int data_len); |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 132 | |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 133 | int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf); |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 134 | #else |
| 135 | static inline void wlan_hdd_tsf_init(struct hdd_context_s *hdd_ctx) |
| 136 | { |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Yu Wang | f5d5b5f | 2017-05-25 22:38:32 +0800 | [diff] [blame] | 139 | static inline void wlan_hdd_tsf_deinit(hdd_context_t *hdd_ctx) |
| 140 | { |
| 141 | } |
| 142 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 143 | static inline int hdd_indicate_tsf(struct hdd_adapter_s *adapter, uint32_t *buf, |
| 144 | int len) |
| 145 | { |
| 146 | return -ENOTSUPP; |
| 147 | } |
| 148 | |
| 149 | static inline int |
| 150 | hdd_capture_tsf(struct hdd_adapter_s *adapter, uint32_t *buf, int len) |
| 151 | { |
| 152 | return -ENOTSUPP; |
| 153 | } |
Manikandan Mohan | 5356c2b | 2016-04-03 15:51:35 -0700 | [diff] [blame] | 154 | |
| 155 | static inline int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy, |
| 156 | struct wireless_dev *wdev, |
| 157 | const void *data, |
| 158 | int data_len) |
| 159 | { |
| 160 | return -ENOTSUPP; |
| 161 | } |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 162 | static inline int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf) |
| 163 | { |
| 164 | return -ENOTSUPP; |
| 165 | } |
| 166 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 167 | #endif |
| 168 | |
Yu Wang | 000dc2f | 2017-05-26 17:38:48 +0800 | [diff] [blame^] | 169 | #if defined(WLAN_FEATURE_TSF_PLUS) && defined(WLAN_FEATURE_TSF) |
| 170 | |
| 171 | /** |
| 172 | * hdd_start_tsf_sync() - start tsf sync |
| 173 | * @adapter: pointer to adapter |
| 174 | * |
| 175 | * This function initialize and start TSF synchronization |
| 176 | * |
| 177 | * Return: Describe the execute result of this routine |
| 178 | */ |
| 179 | int hdd_start_tsf_sync(hdd_adapter_t *adapter); |
| 180 | |
| 181 | /** |
| 182 | * hdd_stop_tsf_sync() - stop tsf sync |
| 183 | * @adapter: pointer to adapter |
| 184 | * |
| 185 | * This function stop and de-initialize TSF synchronization |
| 186 | * |
| 187 | * Return: Describe the execute result of this routine |
| 188 | */ |
| 189 | int hdd_stop_tsf_sync(hdd_adapter_t *adapter); |
| 190 | |
| 191 | /** |
| 192 | * hdd_tsf_notify_wlan_state_change() - |
| 193 | * notify tsf module of wlan connection state |
| 194 | * @old_state: old wlan state |
| 195 | * @new_state: new wlan state |
| 196 | * |
| 197 | * This function check the old and new connection state, determine whether |
| 198 | * to start or stop tsf sync |
| 199 | * |
| 200 | * Return: nothing |
| 201 | */ |
| 202 | void hdd_tsf_notify_wlan_state_change(hdd_adapter_t *adapter, |
| 203 | eConnectionState old_state, |
| 204 | eConnectionState new_state); |
| 205 | |
| 206 | #else |
| 207 | static inline int hdd_start_tsf_sync(hdd_adapter_t *adapter) |
| 208 | { |
| 209 | return -ENOTSUPP; |
| 210 | } |
| 211 | |
| 212 | static inline int hdd_stop_tsf_sync(hdd_adapter_t *adapter) |
| 213 | { |
| 214 | return -ENOTSUPP; |
| 215 | } |
| 216 | |
| 217 | static inline |
| 218 | void hdd_tsf_notify_wlan_state_change(hdd_adapter_t *adapter, |
| 219 | eConnectionState old_state, |
| 220 | eConnectionState new_state) |
| 221 | |
| 222 | { |
| 223 | } |
| 224 | #endif |
| 225 | |
Manikandan Mohan | dcc21ba | 2016-03-15 14:31:56 -0700 | [diff] [blame] | 226 | #endif |