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_pdev_chan_change_pending_vdevs_down() - function to test/set down 241 * change pending flag 242 * @pdev: pdev object 243 * @vdev_id_map: bitmap to derive channel change vdevs 244 * @ref_id: object manager ref id 245 * 246 * This function test/set channel change pending flag 247 * 248 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 249 * otherwise QDF_STATUS_E_FAILURE 250 */ 251 QDF_STATUS wlan_pdev_chan_change_pending_vdevs_down( 252 struct wlan_objmgr_pdev *pdev, 253 unsigned long *vdev_id_map, 254 wlan_objmgr_ref_dbgid dbg_id); 255 256 /** 257 * wlan_pdev_chan_change_pending_ap_vdevs_down() - function to test/set channel 258 * change pending flag for AP VDEVs 259 * @pdev: pdev object 260 * @vdev_id_map: bitmap to derive channel change AP vdevs 261 * @ref_id: object manager ref id 262 * 263 * This function test/set channel change pending flag for AP vdevs 264 * 265 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 266 * otherwise QDF_STATUS_E_FAILURE 267 */ 268 QDF_STATUS wlan_pdev_chan_change_pending_ap_vdevs_down( 269 struct wlan_objmgr_pdev *pdev, 270 unsigned long *vdev_id_map, 271 wlan_objmgr_ref_dbgid dbg_id); 272 273 /** 274 * wlan_chan_eq() - function to check whether both channels are same 275 * @chan1: channel1 object 276 * @chan2: channel2 object 277 * 278 * This function checks the chan1 and chan2 are same 279 * 280 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 281 */ 282 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2); 283 284 /** 285 * wlan_chan_copy() - function to copy channel 286 * @tgt: target channel object 287 * @src: src achannel object 288 * 289 * This function copies channel data from src to tgt 290 * 291 * Return: void 292 */ 293 void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src); 294 295 /** 296 * wlan_vdev_get_active_channel() - derives the vdev operating channel 297 * @vdev: VDEV object 298 * 299 * This function checks vdev state and return the channel pointer accordingly 300 * 301 * Return: active channel, if vdev chan config is valid 302 * NULL, if VDEV is in INIT or STOP state 303 */ 304 struct wlan_channel *wlan_vdev_get_active_channel 305 (struct wlan_objmgr_vdev *vdev); 306 307 /** 308 * wlan_util_stats_get_rssi() - API to get rssi in dbm 309 * @db2dbm_enabled: If db2dbm capability is enabled 310 * @bcn_snr: beacon snr 311 * @dat_snr: data snr 312 * @rssi: rssi 313 * 314 * This function gets the rssi based on db2dbm support. If this feature is 315 * present in hw then it means firmware directly sends rssi and no converstion 316 * is required. If this capablity is not present then host needs to convert 317 * snr to rssi 318 * 319 * Return: None 320 */ 321 void 322 wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr, 323 int8_t *rssi); 324 325 /** 326 * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state 327 * @pdev: pdev pointer 328 * @dbg_id: module id 329 * 330 * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS 331 * substate 332 * 333 * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate 334 * otherwise QDF_STATUS_E_FAILURE 335 */ 336 QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev, 337 wlan_objmgr_ref_dbgid dbg_id); 338 339 /** 340 * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan 341 * @pdev: pdev pointer 342 * @dbg_id: module id 343 * 344 * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in 345 * S_UP state 346 * 347 * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE 348 */ 349 QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev, 350 wlan_objmgr_ref_dbgid dbg_id); 351 352 /** 353 * wlan_util_get_peer_count_for_mode - This api gives vdev mode specific 354 * peer count` 355 * @pdev: PDEV object 356 * @mode: Operation mode. 357 * 358 * Return: int- peer count for operating mode 359 */ 360 uint16_t wlan_util_get_peer_count_for_mode(struct wlan_objmgr_pdev *pdev, 361 enum QDF_OPMODE mode); 362 363 /** 364 * wlan_minidump_host_data - Data structure type logged in Minidump 365 * @WLAN_MD_CP_EXT_PDEV - ol_ath_softc_net80211 366 * @WLAN_MD_CP_EXT_PSOC - ol_ath_soc_softc 367 * @WLAN_MD_CP_EXT_VDEV - ieee80211vap 368 * @WLAN_MD_CP_EXT_PEER - ieee80211_node 369 * @WLAN_MD_DP_SOC - dp_soc 370 * @WLAN_MD_DP_PDEV - dp_pdev 371 * @WLAN_MD_DP_VDEV - dp_vdev 372 * @WLAN_MD_DP_PEER - dp_peer 373 * @WLAN_MD_DP_SRNG_REO_DEST - dp_srng type for reo dest 374 * @WLAN_MD_DP_SRNG_REO_EXCEPTION - dp_srng type for reo exception 375 * @WLAN_MD_DP_SRNG_REO_CMD - dp_srng type for reo cmd 376 * @WLAN_MD_DP_SRNG_RX_REL - dp_srng type for reo release 377 * @WLAN_MD_DP_SRNG_REO_REINJECT - dp_srng type for reo reinject 378 * @WLAN_MD_DP_SRNG_REO_STATUS - dp_srng type for reo status 379 * @WLAN_MD_DP_SRNG_TCL_DATA - dp_srng type for tcl data 380 * @WLAN_MD_DP_SRNG_TCL_STATUS - dp_srng type for tcl status 381 * @WLAN_MD_DP_SRNG_TX_COMP - dp_srng type for tcl comp 382 * @WLAN_MD_DP_SRNG_WBM_DESC_REL - dp_srng_type for wbm desc rel 383 * @WLAN_MD_DP_SRNG_WBM_IDLE_LINK - dp_srng type for wbm idle link 384 * @WLAN_MD_DP_LINK_DESC_BANK - Wbm link_desc_bank 385 * @WLAN_MD_DP_SRNG_RXDMA_MON_STATUS - dp_srng type for rxdma mon status 386 * @WLAN_MD_DP_SRNG_RXDMA_MON_BUF - dp_srng type for rxdma mon buf 387 * @WLAN_MD_DP_SRNG_RXDMA_MON_DST - dp_srng type for rxdma mon dest 388 * @WLAN_MD_DP_SRNG_RXDMA_MON_DESC - dp_srng type for rxdma mon desc 389 * @WLAN_MD_DP_SRNG_RXDMA_ERR_DST - dp_srng type for rxdma err dst 390 * @WLAN_MD_DP_HAL_SOC - hal_soc 391 * @WLAN_MD_OBJMGR_PSOC - wlan_objmgr_psoc 392 * @WLAN_MD_OBJMGR_PSOC_TGT_INFO - wlan_objmgr_tgt_psoc_info 393 * @WLAN_MD_OBJMGR_PDEV - wlan_objmgr_pdev 394 * @WLAN_MD_OBJMGR_PDEV_MLME - pdev_mlme 395 * @WLAN_MD_OBJMGR_VDEV - wlan_objmgr_vdev 396 * @WLAN_MD_OBJMGR_VDEV_MLME -vdev mlme 397 * @WLAN_MD_OBJMGR_VDEV_SM - wlan_sm 398 * @WLAN_MD_MAX - Max value 399 */ 400 enum wlan_minidump_host_data { 401 WLAN_MD_CP_EXT_PDEV, 402 WLAN_MD_CP_EXT_PSOC, 403 WLAN_MD_CP_EXT_VDEV, 404 WLAN_MD_CP_EXT_PEER, 405 WLAN_MD_DP_SOC, 406 WLAN_MD_DP_PDEV, 407 WLAN_MD_DP_VDEV, 408 WLAN_MD_DP_PEER, 409 WLAN_MD_DP_SRNG_REO_DEST, 410 WLAN_MD_DP_SRNG_REO_EXCEPTION, 411 WLAN_MD_DP_SRNG_REO_CMD, 412 WLAN_MD_DP_SRNG_RX_REL, 413 WLAN_MD_DP_SRNG_REO_REINJECT, 414 WLAN_MD_DP_SRNG_REO_STATUS, 415 WLAN_MD_DP_SRNG_TCL_DATA, 416 WLAN_MD_DP_SRNG_TCL_CMD, 417 WLAN_MD_DP_SRNG_TCL_STATUS, 418 WLAN_MD_DP_SRNG_TX_COMP, 419 WLAN_MD_DP_SRNG_WBM_DESC_REL, 420 WLAN_MD_DP_SRNG_WBM_IDLE_LINK, 421 WLAN_MD_DP_LINK_DESC_BANK, 422 WLAN_MD_DP_SRNG_RXDMA_MON_STATUS, 423 WLAN_MD_DP_SRNG_RXDMA_MON_BUF, 424 WLAN_MD_DP_SRNG_RXDMA_MON_DST, 425 WLAN_MD_DP_SRNG_RXDMA_MON_DESC, 426 WLAN_MD_DP_SRNG_RXDMA_ERR_DST, 427 WLAN_MD_DP_HAL_SOC, 428 WLAN_MD_OBJMGR_PSOC, 429 WLAN_MD_OBJMGR_PSOC_TGT_INFO, 430 WLAN_MD_OBJMGR_PDEV, 431 WLAN_MD_OBJMGR_PDEV_MLME, 432 WLAN_MD_OBJMGR_VDEV, 433 WLAN_MD_OBJMGR_VDEV_MLME, 434 WLAN_MD_OBJMGR_VDEV_SM, 435 WLAN_MD_MAX 436 }; 437 438 void wlan_minidump_log(void *start_addr, size_t size, 439 void *psoc, 440 enum wlan_minidump_host_data type, 441 const char *name); 442 443 void wlan_minidump_remove(void *addr); 444 445 #endif /* _WLAN_UTILITY_H_ */ 446