blob: 91b679ad924856076357b497e53437461c86d320 [file] [log] [blame]
Manikandan Mohandcc21ba2016-03-15 14:31:56 -07001/*
Srinivas Girigowdaad005ab2017-03-25 00:47:37 -07002 * Copyright (c) 2016-2017 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"
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070022
Jeff Johnson854cccd2017-08-28 11:39:24 -070023struct hdd_context;
24
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070025/**
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 Wangf5d5b5f2017-05-25 22:38:32 +080035 * @TSF_NOT_READY: TSF module is not initialized or init failed
Yu Wang000dc2f2017-05-26 17:38:48 +080036 * @TSF_DISABLED_BY_TSFPLUS: cap_tsf/get_tsf are disabled due to TSF_PLUS
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070037 */
38enum 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 Wangf5d5b5f2017-05-25 22:38:32 +080046 TSF_SAP_NOT_STARTED_NO_TSF,
Yu Wang000dc2f2017-05-26 17:38:48 +080047 TSF_NOT_READY,
48 TSF_DISABLED_BY_TSFPLUS
Manikandan Mohandcc21ba2016-03-15 14:31:56 -070049};
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 */
56enum hdd_tsf_capture_state {
57 TSF_IDLE = 0,
58 TSF_CAP_STATE
59};
60
61#ifdef WLAN_FEATURE_TSF
Yu Wangf5d5b5f2017-05-25 22:38:32 +080062/**
63 * wlan_hdd_tsf_init() - set gpio and callbacks for
64 * capturing tsf and init tsf_plus
Jeff Johnson854cccd2017-08-28 11:39:24 -070065 * @hdd_ctx: pointer to the struct hdd_context
Yu Wangf5d5b5f2017-05-25 22:38:32 +080066 *
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 Johnson82797b62017-08-11 15:31:27 -070074void wlan_hdd_tsf_init(struct hdd_context *hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080075
76/**
77 * wlan_hdd_tsf_deinit() - reset callbacks for capturing tsf, deinit tsf_plus
Jeff Johnson854cccd2017-08-28 11:39:24 -070078 * @hdd_ctx: pointer to the struct hdd_context
Yu Wangf5d5b5f2017-05-25 22:38:32 +080079 *
80 * This function reset the callback to sme module, and deinit tsf_plus
81 *
82 * Return: nothing
83 */
Jeff Johnson854cccd2017-08-28 11:39:24 -070084void wlan_hdd_tsf_deinit(struct hdd_context *hdd_ctx);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080085
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 Johnson85b5c112017-08-11 15:15:23 -070096int hdd_capture_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +080097
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 Johnson85b5c112017-08-11 15:15:23 -0700109int hdd_indicate_tsf(struct hdd_adapter *adapter, uint32_t *buf, int len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +0800110
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 Mohan5356c2b2016-04-03 15:51:35 -0700122int wlan_hdd_cfg80211_handle_tsf_cmd(struct wiphy *wiphy,
123 struct wireless_dev *wdev,
124 const void *data,
125 int data_len);
Yu Wangf5d5b5f2017-05-25 22:38:32 +0800126
Arun Khandavalli4b55da72016-07-19 19:55:01 +0530127int hdd_get_tsf_cb(void *pcb_cxt, struct stsf *ptsf);
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)
Yu Wang66a250b2017-07-19 11:46:40 +0800164#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 Wang000dc2f2017-05-26 17:38:48 +0800197
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 Johnson8f389862017-08-29 14:19:23 -0700206int hdd_start_tsf_sync(struct hdd_adapter *adapter);
Yu Wang000dc2f2017-05-26 17:38:48 +0800207
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 Johnson8f389862017-08-29 14:19:23 -0700216int hdd_stop_tsf_sync(struct hdd_adapter *adapter);
Yu Wang000dc2f2017-05-26 17:38:48 +0800217
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 Johnson8f389862017-08-29 14:19:23 -0700229void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter,
Yu Wang000dc2f2017-05-26 17:38:48 +0800230 eConnectionState old_state,
231 eConnectionState new_state);
232
Yu Wang04ccd762017-05-31 19:29:43 +0800233/**
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 */
244int 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 */
257int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time);
Yu Wang000dc2f2017-05-26 17:38:48 +0800258#else
Jeff Johnson8f389862017-08-29 14:19:23 -0700259static inline int hdd_start_tsf_sync(struct hdd_adapter *adapter)
Yu Wang000dc2f2017-05-26 17:38:48 +0800260{
261 return -ENOTSUPP;
262}
263
Jeff Johnson8f389862017-08-29 14:19:23 -0700264static inline int hdd_stop_tsf_sync(struct hdd_adapter *adapter)
Yu Wang000dc2f2017-05-26 17:38:48 +0800265{
266 return -ENOTSUPP;
267}
268
269static inline
Jeff Johnson8f389862017-08-29 14:19:23 -0700270void hdd_tsf_notify_wlan_state_change(struct hdd_adapter *adapter,
Yu Wang000dc2f2017-05-26 17:38:48 +0800271 eConnectionState old_state,
272 eConnectionState new_state)
273
274{
275}
Yu Wang04ccd762017-05-31 19:29:43 +0800276
277static inline
278int hdd_tx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time)
279{
280 return -ENOTSUPP;
281}
282
283static inline
284int hdd_rx_timestamp(qdf_nbuf_t netbuf, uint64_t target_time)
285{
286 return -ENOTSUPP;
287}
Yu Wang000dc2f2017-05-26 17:38:48 +0800288#endif
289
Manikandan Mohandcc21ba2016-03-15 14:31:56 -0700290#endif