blob: 81235ecb09bc673499fd8288993fe4ce3de7e4bf [file] [log] [blame]
Manikandan Mohandcc21ba2016-03-15 14:31:56 -07001/*
yuanl2746f072018-09-21 19:19:16 +08002 * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
Manikandan Mohandcc21ba2016-03-15 14:31:56 -07003 *
Manikandan Mohandcc21ba2016-03-15 14:31:56 -07004 * 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 Mohandcc21ba2016-03-15 14:31:56 -070019#if !defined WLAN_HDD_TSF_H
20#define WLAN_HDD_TSF_H
Yu Wang66a250b2017-07-19 11:46:40 +080021#include "wlan_hdd_cfg.h"
yuanl2746f072018-09-21 19:19:16 +080022#include "wlan_hdd_main.h"
Jeff Johnson854cccd2017-08-28 11:39:24 -070023
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070024/**
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 Wangf5d5b5f2017-05-25 22:38:32 +080034 * @TSF_NOT_READY: TSF module is not initialized or init failed
Yu Wang000dc2f2017-05-26 17:38:48 +080035 * @TSF_DISABLED_BY_TSFPLUS: cap_tsf/get_tsf are disabled due to TSF_PLUS
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070036 */
37enum 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 Wangf5d5b5f2017-05-25 22:38:32 +080045 TSF_SAP_NOT_STARTED_NO_TSF,
Yu Wang000dc2f2017-05-26 17:38:48 +080046 TSF_NOT_READY,
47 TSF_DISABLED_BY_TSFPLUS
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070048};
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 */
55enum hdd_tsf_capture_state {
56 TSF_IDLE = 0,
57 TSF_CAP_STATE
58};
59
60#ifdef WLAN_FEATURE_TSF
Yu Wangf5d5b5f2017-05-25 22:38:32 +080061/**
62 * wlan_hdd_tsf_init() - set gpio and callbacks for
63 * capturing tsf and init tsf_plus
Jeff Johnson854cccd2017-08-28 11:39:24 -070064 * @hdd_ctx: pointer to the struct hdd_context
Yu Wangf5d5b5f2017-05-25 22:38:32 +080065 *
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 Johnson82797b62017-08-11 15:31:27 -070073void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080074
75/**
76 * wlan_hdd_tsf_deinit() - reset callbacks for capturing tsf, deinit tsf_plus
Jeff Johnson854cccd2017-08-28 11:39:24 -070077 * @hdd_ctx: pointer to the struct hdd_context
Yu Wangf5d5b5f2017-05-25 22:38:32 +080078 *
79 * This function reset the callback to sme module, and deinit tsf_plus
80 *
81 * Return: nothing
82 */
Jeff Johnson854cccd2017-08-28 11:39:24 -070083void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080084
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 Johnson85b5c112017-08-11 15:15:23 -070095int hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080096
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 Johnson85b5c112017-08-11 15:15:23 -0700108int hdd_indicate_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +0800109
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 Mohan5356c2b2016-04-03 15:51:35 -0700121int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy,
122 struct wireless_dev *wdev,
123 const void *data,
124 int data_len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +0800125
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530126int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf);
yuanl2746f072018-09-21 19:19:16 +0800127
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700128#else
Jeff Johnson82797b62017-08-11 15:31:27 -0700129static inline void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx)
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700130{
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700131}
132
Jeff Johnson854cccd2017-08-28 11:39:24 -0700133static inline void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx)
Yu Wangf5d5b5f2017-05-25 22:38:32 +0800134{
135}
136
Jeff Johnson85b5c112017-08-11 15:15:23 -0700137static inline int hdd_indicate_tsf(struct hdd_adapter *adapter, uint32_t *buf,
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700138 int len)
139{
140 return -ENOTSUPP;
141}
142
143static inline int
Jeff Johnson85b5c112017-08-11 15:15:23 -0700144hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len)
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700145{
146 return -ENOTSUPP;
147}
Manikandan Mohan5356c2b2016-04-03 15:51:35 -0700148
149static 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 Khandavalli4b55da72016-07-19 19:55:01 +0530156static inline int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf)
157{
158 return -ENOTSUPP;
159}
160
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700161#endif
162
Yu Wang000dc2f2017-05-26 17:38:48 +0800163#if defined(WLAN_FEATURE_TSF_PLUS) && defined(WLAN_FEATURE_TSF)
yuanl2746f072018-09-21 19:19:16 +0800164/**
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 */
172bool 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 Wang66a250b2017-07-19 11:46:40 +0800181
yuanl2746f072018-09-21 19:19:16 +0800182bool 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 */
191bool 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 */
200bool 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 */
209bool hdd_tsf_is_dbg_fs_set(struct hdd_context *hdd);
Yu Wang000dc2f2017-05-26 17:38:48 +0800210
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 Johnson8f389862017-08-29 14:19:23 -0700219int hdd_start_tsf_sync(struct hdd_adapter *adapter);
Yu Wang000dc2f2017-05-26 17:38:48 +0800220
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 Johnson8f389862017-08-29 14:19:23 -0700229int hdd_stop_tsf_sync(struct hdd_adapter *adapter);
Yu Wang000dc2f2017-05-26 17:38:48 +0800230
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 Johnson8f389862017-08-29 14:19:23 -0700242void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter,
Yu Wang000dc2f2017-05-26 17:38:48 +0800243 eConnectionState old_state,
244 eConnectionState new_state);
245
Yu Wang04ccd762017-05-31 19:29:43 +0800246/**
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 */
257int 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 */
270int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time);
yuanl2746f072018-09-21 19:19:16 +0800271/**
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
280void hdd_capture_req_timer_expired_handler(void *arg);
281
Yu Wang000dc2f2017-05-26 17:38:48 +0800282#else
Jeff Johnson8f389862017-08-29 14:19:23 -0700283static inline int hdd_start_tsf_sync(struct hdd_adapter *adapter)
Yu Wang000dc2f2017-05-26 17:38:48 +0800284{
285 return -ENOTSUPP;
286}
287
Jeff Johnson8f389862017-08-29 14:19:23 -0700288static inline int hdd_stop_tsf_sync(struct hdd_adapter *adapter)
Yu Wang000dc2f2017-05-26 17:38:48 +0800289{
290 return -ENOTSUPP;
291}
292
293static inline
Jeff Johnson8f389862017-08-29 14:19:23 -0700294void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter,
Yu Wang000dc2f2017-05-26 17:38:48 +0800295 eConnectionState old_state,
296 eConnectionState new_state)
297
298{
299}
Yu Wang04ccd762017-05-31 19:29:43 +0800300
301static inline
302int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time)
303{
304 return -ENOTSUPP;
305}
306
307static inline
308int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time)
309{
310 return -ENOTSUPP;
311}
yuanl2746f072018-09-21 19:19:16 +0800312
313static inline
314void hdd_capture_req_timer_expired_handler(void *arg)
315{
316}
Yu Wang000dc2f2017-05-26 17:38:48 +0800317#endif
318
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700319#endif