1 /* 2 * Copyright (c) 2017-2021 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_get_320_center_freq() - find center frequencies for 320Mhz channel 65 * @freq: Primary frequency 66 * @center_freq1: possible 1st center frequency 67 * @center_freq2: possible 2nd center frequency 68 * 69 * return: void 70 **/ 71 void 72 wlan_get_320_center_freq(qdf_freq_t freq, 73 qdf_freq_t *center_freq1, 74 qdf_freq_t *center_freq2); 75 76 /** 77 * wlan_freq_to_chan() - converts frequency to channel 78 * @freq: frequency 79 * 80 * Return: channel of frequency 81 */ 82 uint8_t wlan_freq_to_chan(uint32_t freq); 83 84 /** 85 * wlan_is_ie_valid() - Determine if an IE sequence is valid 86 * @ie: Pointer to the IE buffer 87 * @ie_len: Length of the IE buffer @ie 88 * 89 * This function validates that the IE sequence is valid by verifying 90 * that the sum of the lengths of the embedded elements match the 91 * length of the sequence. 92 * 93 * Note well that a 0-length IE sequence is considered valid. 94 * 95 * Return: true if the IE sequence is valid, false if it is invalid 96 */ 97 bool wlan_is_ie_valid(const uint8_t *ie, size_t ie_len); 98 99 /** 100 * wlan_get_ie_ptr_from_eid() - Find out ie from eid 101 * @eid: element id 102 * @ie: source ie address 103 * @ie_len: source ie length 104 * 105 * Return: vendor ie address - success 106 * NULL - failure 107 */ 108 const uint8_t *wlan_get_ie_ptr_from_eid(uint8_t eid, 109 const uint8_t *ie, 110 int ie_len); 111 112 /** 113 * wlan_get_vendor_ie_ptr_from_oui() - Find out vendor ie 114 * @oui: oui buffer 115 * @oui_size: oui size 116 * @ie: source ie address 117 * @ie_len: source ie length 118 * 119 * This function find out vendor ie by pass source ie and vendor oui. 120 * 121 * Return: vendor ie address - success 122 * NULL - failure 123 */ 124 const uint8_t *wlan_get_vendor_ie_ptr_from_oui(const uint8_t *oui, 125 uint8_t oui_size, 126 const uint8_t *ie, 127 uint16_t ie_len); 128 129 /** 130 * wlan_get_ext_ie_ptr_from_ext_id() - Find out ext ie 131 * @oui: oui buffer 132 * @oui_size: oui size 133 * @ie: source ie address 134 * @ie_len: source ie length 135 * 136 * This function find out ext ie from ext id (passed oui) 137 * 138 * Return: vendor ie address - success 139 * NULL - failure 140 */ 141 const uint8_t *wlan_get_ext_ie_ptr_from_ext_id(const uint8_t *oui, 142 uint8_t oui_size, 143 const uint8_t *ie, 144 uint16_t ie_len); 145 146 /** 147 * wlan_is_emulation_platform() - check if platform is emulation based 148 * @phy_version - psoc nif phy_version 149 * 150 * Return: boolean value based on platform type 151 */ 152 bool wlan_is_emulation_platform(uint32_t phy_version); 153 154 /** 155 * wlan_get_pdev_id_from_vdev_id() - Helper func to derive pdev id from vdev_id 156 * @psoc: psoc object 157 * @vdev_id: vdev identifier 158 * @dbg_id: object manager debug id 159 * 160 * This function is used to derive the pdev id from vdev id for a psoc 161 * 162 * Return : pdev_id - +ve integer for success and WLAN_INVALID_PDEV_ID 163 * for failure 164 */ 165 uint32_t wlan_get_pdev_id_from_vdev_id(struct wlan_objmgr_psoc *psoc, 166 uint8_t vdev_id, 167 wlan_objmgr_ref_dbgid dbg_id); 168 169 /** 170 * wlan_util_is_vdev_active() - Check for vdev active 171 * @pdev: pdev pointer 172 * @dbg_id: debug id for ref counting 173 * 174 * Return: QDF_STATUS_SUCCESS in case of vdev active 175 * QDF_STATUS_E_INVAL, if dev is not active 176 */ 177 QDF_STATUS wlan_util_is_vdev_active(struct wlan_objmgr_pdev *pdev, 178 wlan_objmgr_ref_dbgid dbg_id); 179 180 /** 181 * wlan_vdev_is_up() - Check for vdev is in UP state 182 * @vdev: vdev pointer 183 * 184 * Return: QDF_STATUS_SUCCESS, if vdev is in up, otherwise QDF_STATUS_E_FAILURE 185 */ 186 QDF_STATUS wlan_vdev_is_up(struct wlan_objmgr_vdev *vdev); 187 188 /** 189 * wlan_util_pdev_vdevs_deschan_match() - function to check des channel matches 190 * with other vdevs in pdev 191 * @pdev: pdev object 192 * @vdev: vdev object 193 * @ref_id: object manager ref id 194 * 195 * This function checks the vdev desired channel with other vdev channels 196 * 197 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 198 */ 199 QDF_STATUS wlan_util_pdev_vdevs_deschan_match(struct wlan_objmgr_pdev *pdev, 200 struct wlan_objmgr_vdev *vdev, 201 wlan_objmgr_ref_dbgid dbg_id); 202 203 /** 204 * wlan_util_change_map_index() - function to set/reset given index bit 205 * @map: bitmpap 206 * @id: bit index 207 * @set: 1 for set, 0 of reset 208 * 209 * This function set/reset given index bit 210 * 211 * Return: void 212 */ 213 void wlan_util_change_map_index(unsigned long *map, uint8_t id, uint8_t set); 214 215 /** 216 * wlan_util_map_index_is_set() - function to check whether given index bit is 217 * set 218 * @map: bitmpap 219 * @id: bit index 220 * 221 * This function checks the given index bit is set 222 * 223 * Return: true, if bit is set, otherwise false 224 */ 225 bool wlan_util_map_index_is_set(unsigned long *map, uint8_t id); 226 227 /** 228 * wlan_util_map_is_any_index_set() - Check if any bit is set in given bitmap 229 * @map: bitmap 230 * @nbytes: number of bytes in bitmap 231 * 232 * Return: true, if any of the bit is set, otherwise false 233 */ 234 bool wlan_util_map_is_any_index_set(unsigned long *map, unsigned long nbytes); 235 236 /** 237 * wlan_pdev_chan_change_pending_vdevs() - function to test/set channel change 238 * pending flag 239 * @pdev: pdev object 240 * @vdev_id_map: bitmap to derive channel change vdevs 241 * @ref_id: object manager ref id 242 * 243 * This function test/set channel change pending flag 244 * 245 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 246 * otherwise QDF_STATUS_E_FAILURE 247 */ 248 QDF_STATUS wlan_pdev_chan_change_pending_vdevs(struct wlan_objmgr_pdev *pdev, 249 unsigned long *vdev_id_map, 250 wlan_objmgr_ref_dbgid dbg_id); 251 252 /** 253 * wlan_pdev_chan_change_pending_vdevs_down() - function to test/set down 254 * change pending flag 255 * @pdev: pdev object 256 * @vdev_id_map: bitmap to derive channel change vdevs 257 * @ref_id: object manager ref id 258 * 259 * This function test/set channel change pending flag 260 * 261 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 262 * otherwise QDF_STATUS_E_FAILURE 263 */ 264 QDF_STATUS wlan_pdev_chan_change_pending_vdevs_down( 265 struct wlan_objmgr_pdev *pdev, 266 unsigned long *vdev_id_map, 267 wlan_objmgr_ref_dbgid dbg_id); 268 269 /** 270 * wlan_pdev_chan_change_pending_ap_vdevs_down() - function to test/set channel 271 * change pending flag for AP VDEVs 272 * @pdev: pdev object 273 * @vdev_id_map: bitmap to derive channel change AP vdevs 274 * @ref_id: object manager ref id 275 * 276 * This function test/set channel change pending flag for AP vdevs 277 * 278 * Return: QDF_STATUS_SUCCESS, if it iterates through all vdevs, 279 * otherwise QDF_STATUS_E_FAILURE 280 */ 281 QDF_STATUS wlan_pdev_chan_change_pending_ap_vdevs_down( 282 struct wlan_objmgr_pdev *pdev, 283 unsigned long *vdev_id_map, 284 wlan_objmgr_ref_dbgid dbg_id); 285 286 /** 287 * wlan_chan_eq() - function to check whether both channels are same 288 * @chan1: channel1 object 289 * @chan2: channel2 object 290 * 291 * This function checks the chan1 and chan2 are same 292 * 293 * Return: QDF_STATUS_SUCCESS, if it matches, otherwise QDF_STATUS_E_FAILURE 294 */ 295 QDF_STATUS wlan_chan_eq(struct wlan_channel *chan1, struct wlan_channel *chan2); 296 297 /** 298 * wlan_chan_copy() - function to copy channel 299 * @tgt: target channel object 300 * @src: src achannel object 301 * 302 * This function copies channel data from src to tgt 303 * 304 * Return: void 305 */ 306 void wlan_chan_copy(struct wlan_channel *tgt, struct wlan_channel *src); 307 308 /** 309 * wlan_vdev_get_active_channel() - derives the vdev operating channel 310 * @vdev: VDEV object 311 * 312 * This function checks vdev state and return the channel pointer accordingly 313 * 314 * Return: active channel, if vdev chan config is valid 315 * NULL, if VDEV is in INIT or STOP state 316 */ 317 struct wlan_channel *wlan_vdev_get_active_channel 318 (struct wlan_objmgr_vdev *vdev); 319 320 /** 321 * wlan_get_connected_vdev_by_bssid() - check/get any vdev connected on bssid 322 * @pdev: pdev object 323 * @bssid: bssid to be checked 324 * @vdev_id: vdev id 325 * 326 * This function will loop through all the vdev in psoc and find/return the 327 * vdev which is connected to bssid provided. 328 * 329 * Return: bool 330 */ 331 bool wlan_get_connected_vdev_by_bssid(struct wlan_objmgr_pdev *pdev, 332 uint8_t *bssid, uint8_t *vdev_id); 333 334 /** 335 * wlan_util_stats_get_rssi() - API to get rssi in dbm 336 * @db2dbm_enabled: If db2dbm capability is enabled 337 * @bcn_snr: beacon snr 338 * @dat_snr: data snr 339 * @rssi: rssi 340 * 341 * This function gets the rssi based on db2dbm support. If this feature is 342 * present in hw then it means firmware directly sends rssi and no converstion 343 * is required. If this capablity is not present then host needs to convert 344 * snr to rssi 345 * 346 * Return: None 347 */ 348 void 349 wlan_util_stats_get_rssi(bool db2dbm_enabled, int32_t bcn_snr, int32_t dat_snr, 350 int8_t *rssi); 351 352 /** 353 * wlan_util_is_pdev_restart_progress() - Check if any vdev is in restart state 354 * @pdev: pdev pointer 355 * @dbg_id: module id 356 * 357 * Iterates through all vdevs, checks if any VDEV is in RESTART_PROGRESS 358 * substate 359 * 360 * Return: QDF_STATUS_SUCCESS,if any vdev is in RESTART_PROGRESS substate 361 * otherwise QDF_STATUS_E_FAILURE 362 */ 363 QDF_STATUS wlan_util_is_pdev_restart_progress(struct wlan_objmgr_pdev *pdev, 364 wlan_objmgr_ref_dbgid dbg_id); 365 366 /** 367 * wlan_util_is_pdev_scan_allowed() - Check for vdev is allowed to scan 368 * @pdev: pdev pointer 369 * @dbg_id: module id 370 * 371 * Iterates through all vdevs, checks if any VDEV is not either in S_INIT or in 372 * S_UP state 373 * 374 * Return: QDF_STATUS_SUCCESS,if scan is allowed, otherwise QDF_STATUS_E_FAILURE 375 */ 376 QDF_STATUS wlan_util_is_pdev_scan_allowed(struct wlan_objmgr_pdev *pdev, 377 wlan_objmgr_ref_dbgid dbg_id); 378 379 /** 380 * wlan_util_get_peer_count_for_mode - This api gives vdev mode specific 381 * peer count` 382 * @pdev: PDEV object 383 * @mode: Operation mode. 384 * 385 * Return: int- peer count for operating mode 386 */ 387 uint16_t wlan_util_get_peer_count_for_mode(struct wlan_objmgr_pdev *pdev, 388 enum QDF_OPMODE mode); 389 390 /** 391 * wlan_minidump_host_data - Data structure type logged in Minidump 392 * @WLAN_MD_CP_EXT_PDEV - ol_ath_softc_net80211 393 * @WLAN_MD_CP_EXT_PSOC - ol_ath_soc_softc 394 * @WLAN_MD_CP_EXT_VDEV - ieee80211vap 395 * @WLAN_MD_CP_EXT_PEER - ieee80211_node 396 * @WLAN_MD_DP_SOC - dp_soc 397 * @WLAN_MD_DP_PDEV - dp_pdev 398 * @WLAN_MD_DP_VDEV - dp_vdev 399 * @WLAN_MD_DP_PEER - dp_peer 400 * @WLAN_MD_DP_SRNG_REO_DEST - dp_srng type for reo dest 401 * @WLAN_MD_DP_SRNG_REO_EXCEPTION - dp_srng type for reo exception 402 * @WLAN_MD_DP_SRNG_REO_CMD - dp_srng type for reo cmd 403 * @WLAN_MD_DP_SRNG_RX_REL - dp_srng type for reo release 404 * @WLAN_MD_DP_SRNG_REO_REINJECT - dp_srng type for reo reinject 405 * @WLAN_MD_DP_SRNG_REO_STATUS - dp_srng type for reo status 406 * @WLAN_MD_DP_SRNG_TCL_DATA - dp_srng type for tcl data 407 * @WLAN_MD_DP_SRNG_TCL_STATUS - dp_srng type for tcl status 408 * @WLAN_MD_DP_SRNG_TX_COMP - dp_srng type for tcl comp 409 * @WLAN_MD_DP_SRNG_WBM_DESC_REL - dp_srng_type for wbm desc rel 410 * @WLAN_MD_DP_SRNG_WBM_IDLE_LINK - dp_srng type for wbm idle link 411 * @WLAN_MD_DP_LINK_DESC_BANK - Wbm link_desc_bank 412 * @WLAN_MD_DP_SRNG_RXDMA_MON_STATUS - dp_srng type for rxdma mon status 413 * @WLAN_MD_DP_SRNG_RXDMA_MON_BUF - dp_srng type for rxdma mon buf 414 * @WLAN_MD_DP_SRNG_RXDMA_MON_DST - dp_srng type for rxdma mon dest 415 * @WLAN_MD_DP_SRNG_RXDMA_MON_DESC - dp_srng type for rxdma mon desc 416 * @WLAN_MD_DP_SRNG_RXDMA_ERR_DST - dp_srng type for rxdma err dst 417 * @WLAN_MD_DP_HAL_SOC - hal_soc 418 * @WLAN_MD_OBJMGR_PSOC - wlan_objmgr_psoc 419 * @WLAN_MD_OBJMGR_PSOC_TGT_INFO - wlan_objmgr_tgt_psoc_info 420 * @WLAN_MD_OBJMGR_PDEV - wlan_objmgr_pdev 421 * @WLAN_MD_OBJMGR_PDEV_MLME - pdev_mlme 422 * @WLAN_MD_OBJMGR_VDEV - wlan_objmgr_vdev 423 * @WLAN_MD_OBJMGR_VDEV_MLME -vdev mlme 424 * @WLAN_MD_OBJMGR_VDEV_SM - wlan_sm 425 * @WLAN_MD_DP_SRNG_REO2PPE- dp_srng type PPE rx ring 426 * @WLAN_MD_DP_SRNG_PPE2TCL - dp_srng type for PPE tx ring 427 * @WLAN_MD_DP_SRNG_PPE_RELEASE - dp_srng type for PPE tx com ring 428 * @WLAN_MD_MAX - Max value 429 */ 430 enum wlan_minidump_host_data { 431 WLAN_MD_CP_EXT_PDEV, 432 WLAN_MD_CP_EXT_PSOC, 433 WLAN_MD_CP_EXT_VDEV, 434 WLAN_MD_CP_EXT_PEER, 435 WLAN_MD_DP_SOC, 436 WLAN_MD_DP_PDEV, 437 WLAN_MD_DP_VDEV, 438 WLAN_MD_DP_PEER, 439 WLAN_MD_DP_SRNG_REO_DEST, 440 WLAN_MD_DP_SRNG_REO_EXCEPTION, 441 WLAN_MD_DP_SRNG_REO_CMD, 442 WLAN_MD_DP_SRNG_RX_REL, 443 WLAN_MD_DP_SRNG_REO_REINJECT, 444 WLAN_MD_DP_SRNG_REO_STATUS, 445 WLAN_MD_DP_SRNG_TCL_DATA, 446 WLAN_MD_DP_SRNG_TCL_CMD, 447 WLAN_MD_DP_SRNG_TCL_STATUS, 448 WLAN_MD_DP_SRNG_TX_COMP, 449 WLAN_MD_DP_SRNG_WBM_DESC_REL, 450 WLAN_MD_DP_SRNG_WBM_IDLE_LINK, 451 WLAN_MD_DP_LINK_DESC_BANK, 452 WLAN_MD_DP_SRNG_RXDMA_MON_STATUS, 453 WLAN_MD_DP_SRNG_RXDMA_MON_BUF, 454 WLAN_MD_DP_SRNG_RXDMA_MON_DST, 455 WLAN_MD_DP_SRNG_RXDMA_MON_DESC, 456 WLAN_MD_DP_SRNG_RXDMA_ERR_DST, 457 WLAN_MD_DP_HAL_SOC, 458 WLAN_MD_OBJMGR_PSOC, 459 WLAN_MD_OBJMGR_PSOC_TGT_INFO, 460 WLAN_MD_OBJMGR_PDEV, 461 WLAN_MD_OBJMGR_PDEV_MLME, 462 WLAN_MD_OBJMGR_VDEV, 463 WLAN_MD_OBJMGR_VDEV_MLME, 464 WLAN_MD_OBJMGR_VDEV_SM, 465 WLAN_MD_DP_SRNG_REO2PPE, 466 WLAN_MD_DP_SRNG_PPE2TCL, 467 WLAN_MD_DP_SRNG_PPE_RELEASE, 468 WLAN_MD_MAX 469 }; 470 471 /** 472 * wlan_minidump_log() - Log memory address to be included in minidump 473 * @start_addr: Start address of the memory to be dumped 474 * @size: Size in bytes 475 * @psoc_obj: Psoc Object 476 * @type: Type of data structure 477 * @name: String to identify this entry 478 */ 479 void wlan_minidump_log(void *start_addr, const size_t size, 480 void *psoc_obj, 481 enum wlan_minidump_host_data type, 482 const char *name); 483 484 /** 485 * wlan_minidump_remove() - Remove memory address from minidump 486 * @start_addr: Start address of the memory previously added 487 * @size: Size in bytes 488 * @psoc_obj: Psoc Object 489 * @type: Type of data structure 490 * @name: String to identify this entry 491 */ 492 void wlan_minidump_remove(void *start_addr, const size_t size, 493 void *psoc_obj, 494 enum wlan_minidump_host_data type, 495 const char *name); 496 497 #endif /* _WLAN_UTILITY_H_ */ 498