xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/utils/inc/wlan_utility.h (revision a86b23ee68a2491aede2e03991f3fb37046f4e41)
1 /*
2  * Copyright (c) 2017-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * DOC: Contains mandatory API from legacy
19  */
20 
21 #ifndef _WLAN_UTILITY_H_
22 #define _WLAN_UTILITY_H_
23 
24 #include <qdf_types.h>
25 #include <wlan_objmgr_psoc_obj.h>
26 #include <wlan_objmgr_pdev_obj.h>
27 #include <wlan_objmgr_vdev_obj.h>
28 
29 #define TGT_INVALID_SNR         (0)
30 #define TGT_MAX_SNR             (TGT_NOISE_FLOOR_DBM * (-1))
31 #define TGT_NOISE_FLOOR_DBM     (-96)
32 #define TGT_IS_VALID_SNR(x)     ((x) >= 0 && (x) < TGT_MAX_SNR)
33 #define TGT_IS_VALID_RSSI(x)    ((x) != 0xFF)
34 
35 /**
36  * struct wlan_vdev_ch_check_filter - vdev chan check filter object
37  * @flag:     matches or not
38  * @vdev:     vdev to be checked against all the active vdevs
39  */
40 struct wlan_vdev_ch_check_filter {
41 	uint8_t flag;
42 	struct wlan_objmgr_vdev *vdev;
43 };
44 
45 /**
46  * struct wlan_peer_count- vdev connected peer count
47  * @opmode: QDF mode
48  * @peer_count: peer count
49  **/
50 struct wlan_op_mode_peer_count {
51 	enum QDF_OPMODE opmode;
52 	uint16_t peer_count;
53 };
54 
55 /**
56  * wlan_chan_to_freq() - converts channel to frequency
57  * @chan: channel number
58  *
59  * @return frequency of the channel
60  */
61 uint32_t wlan_chan_to_freq(uint8_t chan);
62 
63 /**
64  * wlan_freq_to_chan() - converts frequency to channel
65  * @freq: frequency
66  *
67  * Return: channel of frequency
68  */
69 uint8_t wlan_freq_to_chan(uint32_t freq);
70 
71 /**
72  * wlan_is_ie_valid() - Determine if an IE sequence is valid
73  * @ie: Pointer to the IE buffer
74  * @ie_len: Length of the IE buffer @ie
75  *
76  * This function validates that the IE sequence is valid by verifying
77  * that the sum of the lengths of the embedded elements match the
78  * length of the sequence.
79  *
80  * Note well that a 0-length IE sequence is considered valid.
81  *
82  * Return: true if the IE sequence is valid, false if it is invalid
83  */
84 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len);
85 
86 /**
87  * wlan_get_ie_ptr_from_eid() - Find out ie from eid
88  * @eid: element id
89  * @ie: source ie address
90  * @ie_len: source ie length
91  *
92  * Return: vendor ie address - success
93  *         NULL - failure
94  */
95 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid,
96 					const uint8_t *ie,
97 					int ie_len);
98 
99 /**
100  * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie
101  * @oui: oui buffer
102  * @oui_size: oui size
103  * @ie: source ie address
104  * @ie_len: source ie length
105  *
106  * This function find out vendor ie by pass source ie and vendor oui.
107  *
108  * Return: vendor ie address - success
109  *         NULL - failure
110  */
111 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui,
112 					       uint8_t oui_size,
113 					       const uint8_t *ie,
114 					       uint16_t ie_len);
115 
116 /**
117  * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie
118  * @oui: oui buffer
119  * @oui_size: oui size
120  * @ie: source ie address
121  * @ie_len: source ie length
122  *
123  * This function find out ext ie from ext id (passed oui)
124  *
125  * Return: vendor ie address - success
126  *         NULL - failure
127  */
128 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui,
129 					       uint8_t oui_size,
130 					       const uint8_t *ie,
131 					       uint16_t ie_len);
132 
133 /**
134  * wlan_is_emulation_platform() - check if platform is emulation based
135  * @phy_version - psoc nif phy_version
136  *
137  * Return: boolean value based on platform type
138  */
139 bool wlan_is_emulation_platform(uint32_t phy_version);
140 
141 /**
142  * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id
143  * @psoc: psoc object
144  * @vdev_id: vdev identifier
145  * @dbg_id: object manager debug id
146  *
147  * This function is used to derive the pdev id from vdev id for a psoc
148  *
149  * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID
150  *          for failure
151  */
152 uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc,
153 				 uint8_t vdev_id,
154 				 wlan_objmgr_ref_dbgid dbg_id);
155 
156 /**
157  * wlan_util_is_vdev_active() - Check for vdev active
158  * @pdev: pdev pointer
159  * @dbg_id: debug id for ref counting
160  *
161  * Return: QDF_STATUS_SUCCESS in case of vdev active
162  *          QDF_STATUS_E_INVAL, if dev is not active
163  */
164 QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev,
165 				    wlan_objmgr_ref_dbgid dbg_id);
166 
167 /**
168  * wlan_vdev_is_up() - Check for vdev is in UP state
169  * @vdev: vdev pointer
170  *
171  * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE
172  */
173 QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev);
174 
175 /**
176  * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches
177  *                                        with other vdevs in pdev
178  * @pdev: pdev object
179  * @vdev: vdev object
180  * @ref_id: object manager ref id
181  *
182  * This function checks the vdev desired channel with other vdev channels
183  *
184  * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
185  */
186 QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev,
187 					      struct wlan_objmgr_vdev *vdev,
188 					      wlan_objmgr_ref_dbgid dbg_id);
189 
190 /**
191  * wlan_util_change_map_index() - function to set/reset given index bit
192  * @map: bitmpap
193  * @id: bit index
194  * @set: 1 for set, 0 of reset
195  *
196  * This function set/reset given index bit
197  *
198  * Return: void
199  */
200 void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set);
201 
202 /**
203  * wlan_util_map_index_is_set() - function to check whether given index bit is
204  *                                set
205  * @map: bitmpap
206  * @id: bit index
207  *
208  * This function checks the given index bit is set
209  *
210  * Return: true, if bit is set, otherwise false
211  */
212 bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id);
213 
214 /**
215  * wlan_util_map_is_any_index_set() - Check if any bit is set in given bitmap
216  * @map: bitmap
217  * @nbytes: number of bytes in bitmap
218  *
219  * Return: true, if any of the bit is set, otherwise false
220  */
221 bool wlan_util_map_is_any_index_set(unsigned long *map, unsigned long nbytes);
222 
223 /**
224  * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change
225  *                                         pending flag
226  * @pdev: pdev object
227  * @vdev_id_map: bitmap to derive channel change vdevs
228  * @ref_id: object manager ref id
229  *
230  * This function test/set channel change pending flag
231  *
232  * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs,
233  *         otherwise QDF_STATUS_E_FAILURE
234  */
235 QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev,
236 					       unsigned long *vdev_id_map,
237 					       wlan_objmgr_ref_dbgid dbg_id);
238 
239 /**
240  * wlan_chan_eq() - function to check whether both channels are same
241  * @chan1: channel1 object
242  * @chan2: channel2 object
243  *
244  * This function checks the chan1 and chan2 are same
245  *
246  * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE
247  */
248 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2);
249 
250 /**
251  * wlan_chan_copy() - function to copy channel
252  * @tgt:  target channel object
253  * @src:  src achannel object
254  *
255  * This function copies channel data from src to tgt
256  *
257  * Return: void
258  */
259 void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src);
260 
261 /**
262  * wlan_vdev_get_active_channel() - derives the vdev operating channel
263  * @vdev:  VDEV object
264  *
265  * This function checks vdev state and return the channel pointer accordingly
266  *
267  * Return: active channel, if vdev chan config is valid
268  *         NULL, if VDEV is in INIT or STOP state
269  */
270 struct wlan_channel *wlan_vdev_get_active_channel
271 				(struct wlan_objmgr_vdev *vdev);
272 
273 /**
274  * wlan_util_stats_get_rssi() - API to get rssi in dbm
275  * @db2dbm_enabled: If db2dbm capability is enabled
276  * @bcn_snr: beacon snr
277  * @dat_snr: data snr
278  * @rssi: rssi
279  *
280  * This function gets the rssi based on db2dbm support. If this feature is
281  * present in hw then it means firmware directly sends rssi and no converstion
282  * is required. If this capablity is not present then host needs to convert
283  * snr to rssi
284  *
285  * Return: None
286  */
287 void
288 wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr,
289 			 int8_t *rssi);
290 
291 /**
292  * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state
293  * @pdev: pdev pointer
294  * @dbg_id: module id
295  *
296  * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS
297  * substate
298  *
299  * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate
300  *         otherwise QDF_STATUS_E_FAILURE
301  */
302 QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev,
303 					      wlan_objmgr_ref_dbgid dbg_id);
304 
305 /**
306  * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan
307  * @pdev: pdev pointer
308  * @dbg_id: module id
309  *
310  * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in
311  * S_UP state
312  *
313  * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE
314  */
315 QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev,
316 					  wlan_objmgr_ref_dbgid dbg_id);
317 
318 /**
319  * wlan_util_get_peer_count_for_mode - This api gives vdev mode specific
320  * peer count`
321  * @pdev: PDEV object
322  * @mode: Operation mode.
323  *
324  * Return: int- peer count for operating mode
325  */
326 uint16_t wlan_util_get_peer_count_for_mode(struct wlan_objmgr_pdev *pdev,
327 					   enum QDF_OPMODE mode);
328 
329 /**
330  * wlan_minidump_host_data - Data structure type logged in Minidump
331  * @WLAN_MD_CP_EXT_PDEV - ol_ath_softc_net80211
332  * @WLAN_MD_CP_EXT_PSOC - ol_ath_soc_softc
333  * @WLAN_MD_CP_EXT_VDEV - ieee80211vap
334  * @WLAN_MD_CP_EXT_PEER - ieee80211_node
335  * @WLAN_MD_DP_SOC - dp_soc
336  * @WLAN_MD_DP_PDEV - dp_pdev
337  * @WLAN_MD_DP_VDEV - dp_vdev
338  * @WLAN_MD_DP_PEER - dp_peer
339  * @WLAN_MD_DP_SRNG_REO_DEST - dp_srng type for reo dest
340  * @WLAN_MD_DP_SRNG_REO_EXCEPTION - dp_srng type for reo exception
341  * @WLAN_MD_DP_SRNG_REO_CMD - dp_srng type for reo cmd
342  * @WLAN_MD_DP_SRNG_RX_REL - dp_srng type for reo release
343  * @WLAN_MD_DP_SRNG_REO_REINJECT - dp_srng type for reo reinject
344  * @WLAN_MD_DP_SRNG_REO_STATUS - dp_srng type for reo status
345  * @WLAN_MD_DP_SRNG_TCL_DATA - dp_srng type for tcl data
346  * @WLAN_MD_DP_SRNG_TCL_STATUS - dp_srng type for tcl status
347  * @WLAN_MD_DP_SRNG_TX_COMP - dp_srng type for tcl comp
348  * @WLAN_MD_DP_SRNG_WBM_DESC_REL - dp_srng_type for wbm desc rel
349  * @WLAN_MD_DP_SRNG_WBM_IDLE_LINK - dp_srng type for wbm idle link
350  * @WLAN_MD_DP_LINK_DESC_BANK - Wbm link_desc_bank
351  * @WLAN_MD_DP_SRNG_RXDMA_MON_STATUS - dp_srng type for rxdma mon status
352  * @WLAN_MD_DP_SRNG_RXDMA_MON_BUF - dp_srng type for rxdma mon buf
353  * @WLAN_MD_DP_SRNG_RXDMA_MON_DST - dp_srng type for rxdma mon dest
354  * @WLAN_MD_DP_SRNG_RXDMA_MON_DESC - dp_srng type for rxdma mon desc
355  * @WLAN_MD_DP_SRNG_RXDMA_ERR_DST - dp_srng type for rxdma err dst
356  * @WLAN_MD_DP_HAL_SOC - hal_soc
357  * @WLAN_MD_OBJMGR_PSOC - wlan_objmgr_psoc
358  * @WLAN_MD_OBJMGR_PSOC_TGT_INFO - wlan_objmgr_tgt_psoc_info
359  * @WLAN_MD_OBJMGR_PDEV - wlan_objmgr_pdev
360  * @WLAN_MD_OBJMGR_PDEV_MLME - pdev_mlme
361  * @WLAN_MD_OBJMGR_VDEV - wlan_objmgr_vdev
362  * @WLAN_MD_OBJMGR_VDEV_MLME -vdev mlme
363  * @WLAN_MD_OBJMGR_VDEV_SM - wlan_sm
364  * @WLAN_MD_MAX - Max value
365  */
366 enum wlan_minidump_host_data {
367 	WLAN_MD_CP_EXT_PDEV,
368 	WLAN_MD_CP_EXT_PSOC,
369 	WLAN_MD_CP_EXT_VDEV,
370 	WLAN_MD_CP_EXT_PEER,
371 	WLAN_MD_DP_SOC,
372 	WLAN_MD_DP_PDEV,
373 	WLAN_MD_DP_VDEV,
374 	WLAN_MD_DP_PEER,
375 	WLAN_MD_DP_SRNG_REO_DEST,
376 	WLAN_MD_DP_SRNG_REO_EXCEPTION,
377 	WLAN_MD_DP_SRNG_REO_CMD,
378 	WLAN_MD_DP_SRNG_RX_REL,
379 	WLAN_MD_DP_SRNG_REO_REINJECT,
380 	WLAN_MD_DP_SRNG_REO_STATUS,
381 	WLAN_MD_DP_SRNG_TCL_DATA,
382 	WLAN_MD_DP_SRNG_TCL_CMD,
383 	WLAN_MD_DP_SRNG_TCL_STATUS,
384 	WLAN_MD_DP_SRNG_TX_COMP,
385 	WLAN_MD_DP_SRNG_WBM_DESC_REL,
386 	WLAN_MD_DP_SRNG_WBM_IDLE_LINK,
387 	WLAN_MD_DP_LINK_DESC_BANK,
388 	WLAN_MD_DP_SRNG_RXDMA_MON_STATUS,
389 	WLAN_MD_DP_SRNG_RXDMA_MON_BUF,
390 	WLAN_MD_DP_SRNG_RXDMA_MON_DST,
391 	WLAN_MD_DP_SRNG_RXDMA_MON_DESC,
392 	WLAN_MD_DP_SRNG_RXDMA_ERR_DST,
393 	WLAN_MD_DP_HAL_SOC,
394 	WLAN_MD_OBJMGR_PSOC,
395 	WLAN_MD_OBJMGR_PSOC_TGT_INFO,
396 	WLAN_MD_OBJMGR_PDEV,
397 	WLAN_MD_OBJMGR_PDEV_MLME,
398 	WLAN_MD_OBJMGR_VDEV,
399 	WLAN_MD_OBJMGR_VDEV_MLME,
400 	WLAN_MD_OBJMGR_VDEV_SM,
401 	WLAN_MD_MAX
402 };
403 
404 void wlan_minidump_log(void *start_addr, size_t size,
405 		       void *psoc,
406 		       enum wlan_minidump_host_data type,
407 		       const char *name);
408 
409 void wlan_minidump_remove(void *addr);
410 
411 #endif /* _WLAN_UTILITY_H_ */
412