1 /* 2 * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * 6 * Permission to use, copy, modify, and/or distribute this software for 7 * any purpose with or without fee is hereby granted, provided that the 8 * above copyright notice and this permission notice appear in all 9 * copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 13 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 14 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 15 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 16 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 17 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 18 * PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21 #include <qdf_types.h> 22 #include "wlan_dfs_ioctl.h" 23 #include <spectral_ioctl.h> 24 25 #ifndef __KERNEL__ 26 #include <math.h> 27 #endif /* __KERNEL__ */ 28 29 #ifndef _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ 30 #define _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ 31 32 #ifndef AH_MAX_CHAINS 33 #define AH_MAX_CHAINS 3 34 #endif 35 36 #define MAX_NUM_CHANNELS 255 37 #define SPECTRAL_PHYERR_PARAM_NOVAL 65535 38 39 #ifdef SPECTRAL_USE_EMU_DEFAULTS 40 /* Use defaults from emulation */ 41 #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0x0) 42 #define SPECTRAL_SCAN_ENABLE_DEFAULT (0x0) 43 #define SPECTRAL_SCAN_COUNT_DEFAULT (0x0) 44 #define SPECTRAL_SCAN_PERIOD_DEFAULT (250) 45 #define SPECTRAL_SCAN_PRIORITY_DEFAULT (0x1) 46 #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (0x7) 47 #define SPECTRAL_SCAN_GC_ENA_DEFAULT (0x1) 48 #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0x0) 49 #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (0xa0) 50 #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (0x50) 51 #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (0xc) 52 #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (0x7) 53 #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0x0) 54 #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0x1) 55 #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf) 56 #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0x1) 57 #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (0x2) 58 #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (0x1) 59 #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (0x0) 60 #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (0x1) 61 #else 62 /* 63 * Static default values for spectral state and configuration. 64 * These definitions should be treated as temporary. Ideally, 65 * we should get the defaults from firmware - this will be discussed. 66 * 67 * Use defaults from Spectral Hardware Micro-Architecture 68 * document (v1.0) 69 */ 70 #define SPECTRAL_SCAN_ACTIVE_DEFAULT (0) 71 #define SPECTRAL_SCAN_ENABLE_DEFAULT (0) 72 #define SPECTRAL_SCAN_COUNT_DEFAULT (0) 73 #define SPECTRAL_SCAN_PERIOD_GEN_I_DEFAULT (35) 74 #define SPECTRAL_SCAN_PERIOD_GEN_II_DEFAULT (35) 75 #define SPECTRAL_SCAN_PERIOD_GEN_III_DEFAULT (224) 76 #define SPECTRAL_SCAN_PRIORITY_DEFAULT (1) 77 #define SPECTRAL_SCAN_FFT_SIZE_DEFAULT (7) 78 #define SPECTRAL_SCAN_GC_ENA_DEFAULT (1) 79 #define SPECTRAL_SCAN_RESTART_ENA_DEFAULT (0) 80 #define SPECTRAL_SCAN_NOISE_FLOOR_REF_DEFAULT (-96) 81 #define SPECTRAL_SCAN_INIT_DELAY_DEFAULT (80) 82 #define SPECTRAL_SCAN_NB_TONE_THR_DEFAULT (12) 83 #define SPECTRAL_SCAN_STR_BIN_THR_DEFAULT (8) 84 #define SPECTRAL_SCAN_WB_RPT_MODE_DEFAULT (0) 85 #define SPECTRAL_SCAN_RSSI_RPT_MODE_DEFAULT (0) 86 #define SPECTRAL_SCAN_RSSI_THR_DEFAULT (0xf0) 87 #define SPECTRAL_SCAN_PWR_FORMAT_DEFAULT (0) 88 #define SPECTRAL_SCAN_RPT_MODE_DEFAULT (2) 89 #define SPECTRAL_SCAN_BIN_SCALE_DEFAULT (1) 90 #define SPECTRAL_SCAN_DBM_ADJ_DEFAULT (1) 91 #define SPECTRAL_SCAN_CHN_MASK_DEFAULT (1) 92 #define SPECTRAL_SCAN_FREQUENCY_DEFAULT (0) 93 #define SPECTRAL_FFT_RECAPTURE_DEFAULT (0) 94 #endif /* SPECTRAL_USE_EMU_DEFAULTS */ 95 96 /* The below two definitions apply only to pre-11ac chipsets */ 97 #define SPECTRAL_SCAN_SHORT_REPORT_DEFAULT (1) 98 #define SPECTRAL_SCAN_FFT_PERIOD_DEFAULT (1) 99 100 /* 101 * Definitions to help in scaling of gen3 linear format Spectral bins to values 102 * similar to those from gen2 chipsets. 103 */ 104 105 /* 106 * Max gain for QCA9984. Since this chipset is a prime representative of gen2 107 * chipsets, it is chosen for this value. 108 */ 109 #define SPECTRAL_QCA9984_MAX_GAIN (78) 110 111 /* Temporary section for hard-coded values. These need to come from FW. */ 112 113 /* Max gain for IPQ8074 */ 114 #define SPECTRAL_IPQ8074_DEFAULT_MAX_GAIN_HARDCODE (62) 115 116 /* 117 * Section for values needing tuning per customer platform. These too may need 118 * to come from FW. To be considered as hard-coded for now. 119 */ 120 121 /* 122 * If customers have a different gain line up than QCA reference designs for 123 * IPQ8074 and/or QCA9984, they may have to tune the low level threshold and 124 * the RSSI threshold. 125 */ 126 #define SPECTRAL_SCALING_LOW_LEVEL_OFFSET (7) 127 #define SPECTRAL_SCALING_RSSI_THRESH (5) 128 129 /* 130 * If customers set the AGC backoff differently, they may have to tune the high 131 * level threshold. 132 */ 133 #define SPECTRAL_SCALING_HIGH_LEVEL_OFFSET (5) 134 135 /* End of section for values needing fine tuning. */ 136 /* End of temporary section for hard-coded values */ 137 138 /** 139 * enum spectral_msg_buf_type - Spectral message buffer type 140 * @SPECTRAL_MSG_BUF_NEW: Allocate new buffer 141 * @SPECTRAL_MSG_BUF_SAVED: Reuse last buffer, used for secondary segment report 142 * in case of 160 MHz. 143 */ 144 enum spectral_msg_buf_type { 145 SPECTRAL_MSG_BUF_NEW, 146 SPECTRAL_MSG_BUF_SAVED, 147 SPECTRAL_MSG_BUF_TYPE_MAX, 148 }; 149 150 /** 151 * enum spectral_msg_type - Spectral SAMP message type 152 * @SPECTRAL_MSG_NORMAL_MODE: Normal mode Spectral SAMP message 153 * @SPECTRAL_MSG_AGILE_MODE: Agile mode Spectral SAMP message 154 * @SPECTRAL_MSG_INTERFERENCE_NOTIFICATION: Interference notification to 155 * external auto channel selection 156 * entity 157 * @SPECTRAL_MSG_TYPE_MAX: Spectral SAMP message type max 158 */ 159 enum spectral_msg_type { 160 SPECTRAL_MSG_NORMAL_MODE, 161 SPECTRAL_MSG_AGILE_MODE, 162 SPECTRAL_MSG_INTERFERENCE_NOTIFICATION, 163 SPECTRAL_MSG_TYPE_MAX, 164 }; 165 166 /** 167 * enum spectral_debug - Spectral debug level 168 * @DEBUG_SPECTRAL: Minimal SPECTRAL debug 169 * @DEBUG_SPECTRAL1: Normal SPECTRAL debug 170 * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug 171 * @DEBUG_SPECTRAL3: Matched filterID display 172 * @DEBUG_SPECTRAL4: One time dump of FFT report 173 */ 174 enum spectral_debug { 175 DEBUG_SPECTRAL = 0x00000100, 176 DEBUG_SPECTRAL1 = 0x00000200, 177 DEBUG_SPECTRAL2 = 0x00000400, 178 DEBUG_SPECTRAL3 = 0x00000800, 179 DEBUG_SPECTRAL4 = 0x00001000, 180 }; 181 182 /** 183 * enum spectral_capability_type - Spectral capability type 184 * @SPECTRAL_CAP_PHYDIAG: Phydiag capability 185 * @SPECTRAL_CAP_RADAR: Radar detection capability 186 * @SPECTRAL_CAP_SPECTRAL_SCAN: Spectral capability 187 * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability 188 */ 189 enum spectral_capability_type { 190 SPECTRAL_CAP_PHYDIAG, 191 SPECTRAL_CAP_RADAR, 192 SPECTRAL_CAP_SPECTRAL_SCAN, 193 SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN, 194 }; 195 196 /** 197 * enum spectral_cp_error_code - Spectral control path response code 198 * @SPECTRAL_SCAN_RESP_ERR_INVALID: Invalid error identifier 199 * @SPECTRAL_SCAN_RESP_ERR_PARAM_UNSUPPORTED: parameter unsupported 200 * @SPECTRAL_SCAN_RESP_ERR_MODE_UNSUPPORTED: mode unsupported 201 * @SPECTRAL_SCAN_RESP_ERR_PARAM_INVALID_VALUE: invalid parameter value 202 * @SPECTRAL_SCAN_RESP_ERR_PARAM_NOT_INITIALIZED: parameter uninitialized 203 */ 204 enum spectral_cp_error_code { 205 SPECTRAL_SCAN_ERR_INVALID, 206 SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED, 207 SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED, 208 SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE, 209 SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED, 210 }; 211 212 /** 213 * enum spectral_dma_debug - Spectral DMA debug 214 * @SPECTRAL_DMA_RING_DEBUG: Spectral DMA ring debug 215 * @SPECTRAL_DMA_BUFFER_DEBUG: Spectral DMA buffer debug 216 */ 217 enum spectral_dma_debug { 218 SPECTRAL_DMA_RING_DEBUG, 219 SPECTRAL_DMA_BUFFER_DEBUG, 220 }; 221 222 struct wiphy; 223 struct wlan_objmgr_pdev; 224 struct wlan_objmgr_vdev; 225 /** 226 * struct spectral_cfg80211_vendor_cmd_handlers - Spectral vendor command 227 * handlers 228 * @wlan_cfg80211_spectral_scan_start: start scan handler 229 * @wlan_cfg80211_spectral_scan_stop: stop scan handler 230 * @wlan_cfg80211_spectral_scan_get_config: get config handler 231 * @wlan_cfg80211_spectral_scan_get_diag_stats: get diag stats handler 232 * @wlan_cfg80211_spectral_scan_get_cap: get capability handler 233 * @wlan_cfg80211_spectral_scan_get_status: get status handler 234 */ 235 struct spectral_cfg80211_vendor_cmd_handlers { 236 int (*wlan_cfg80211_spectral_scan_start)(struct wiphy *wiphy, 237 struct wlan_objmgr_pdev *pdev, 238 struct wlan_objmgr_vdev *vdev, 239 const void *data, 240 int data_len); 241 int (*wlan_cfg80211_spectral_scan_stop)(struct wiphy *wiphy, 242 struct wlan_objmgr_pdev *pdev, 243 struct wlan_objmgr_vdev *vdev, 244 const void *data, 245 int data_len); 246 int (*wlan_cfg80211_spectral_scan_get_config)( 247 struct wiphy *wiphy, 248 struct wlan_objmgr_pdev *pdev, 249 struct wlan_objmgr_vdev *vdev, 250 const void *data, 251 int data_len); 252 int (*wlan_cfg80211_spectral_scan_get_diag_stats)( 253 struct wiphy *wiphy, 254 struct wlan_objmgr_pdev *pdev, 255 struct wlan_objmgr_vdev *vdev, 256 const void *data, 257 int data_len); 258 int (*wlan_cfg80211_spectral_scan_get_cap)( 259 struct wiphy *wiphy, 260 struct wlan_objmgr_pdev *pdev, 261 struct wlan_objmgr_vdev *vdev, 262 const void *data, 263 int data_len); 264 int (*wlan_cfg80211_spectral_scan_get_status)( 265 struct wiphy *wiphy, 266 struct wlan_objmgr_pdev *pdev, 267 struct wlan_objmgr_vdev *vdev, 268 const void *data, 269 int data_len); 270 }; 271 272 /** 273 * struct spectral_cp_param - Spectral control path data structure which 274 * contains parameter and its value 275 * @id: Parameter ID 276 * @value: Single parameter value 277 * @freq: Spectral scan frequency 278 */ 279 struct spectral_cp_param { 280 uint32_t id; 281 union { 282 uint32_t value; 283 struct spectral_config_frequency freq; 284 }; 285 }; 286 287 /** 288 * struct spectral_chan_stats - channel status info 289 * @cycle_count: Cycle count 290 * @channel_load: Channel load 291 * @per: Period 292 * @noisefloor: Noise floor 293 * @comp_usablity: Computed usability 294 * @maxregpower: Maximum allowed regulatory power 295 * @comp_usablity_sec80: Computed usability of secondary 80 Mhz 296 * @maxregpower_sec80: Max regulatory power of secondary 80 Mhz 297 */ 298 struct spectral_chan_stats { 299 int cycle_count; 300 int channel_load; 301 int per; 302 int noisefloor; 303 uint16_t comp_usablity; 304 int8_t maxregpower; 305 uint16_t comp_usablity_sec80; 306 int8_t maxregpower_sec80; 307 }; 308 309 /** 310 * struct spectral_diag_stats - spectral diag stats 311 * @spectral_mismatch: Spectral TLV signature mismatches 312 * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for 313 * Secondary 80 Search FFT report 314 * @spectral_no_sec80_sfft: Secondary 80 Search FFT report 315 * TLV not found 316 * @spectral_vhtseg1id_mismatch: VHT Operation Segment 1 ID 317 * mismatches in Search FFT report 318 * @spectral_vhtseg2id_mismatch: VHT Operation Segment 2 ID 319 * mismatches in Search FFT report 320 * @spectral_invalid_detector_id: Invalid detector id 321 */ 322 struct spectral_diag_stats { 323 uint64_t spectral_mismatch; 324 uint64_t spectral_sec80_sfft_insufflen; 325 uint64_t spectral_no_sec80_sfft; 326 uint64_t spectral_vhtseg1id_mismatch; 327 uint64_t spectral_vhtseg2id_mismatch; 328 uint64_t spectral_invalid_detector_id; 329 }; 330 331 /** 332 * struct spectral_scan_state - State of spectral scan 333 * @is_active: Is spectral scan active 334 * @is_enabled: Is spectral scan enabled 335 */ 336 struct spectral_scan_state { 337 uint8_t is_active; 338 uint8_t is_enabled; 339 }; 340 341 /* Forward declarations */ 342 struct wlan_objmgr_pdev; 343 344 /** 345 * struct spectral_nl_cb - Spectral Netlink callbacks 346 * @get_sbuff: Get the socket buffer to send the data to the application 347 * @send_nl_bcast: Send data to the application using netlink broadcast 348 * @send_nl_unicast: Send data to the application using netlink unicast 349 * @free_sbuff: Free the socket buffer for a particular message type 350 */ 351 struct spectral_nl_cb { 352 void *(*get_sbuff)(struct wlan_objmgr_pdev *pdev, 353 enum spectral_msg_type smsg_type, 354 enum spectral_msg_buf_type buf_type); 355 int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev, 356 enum spectral_msg_type smsg_type); 357 int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev, 358 enum spectral_msg_type smsg_type); 359 void (*free_sbuff)(struct wlan_objmgr_pdev *pdev, 360 enum spectral_msg_type smsg_type); 361 int (*convert_to_nl_ch_width)(uint8_t phy_chwidth); 362 uint8_t (*convert_to_phy_ch_width)(uint8_t nl_chwidth); 363 }; 364 365 /** 366 * struct spectral_scan_config_request - Config request 367 * @sscan_config: Spectral parameters 368 * @sscan_err_code: Spectral scan error code 369 */ 370 struct spectral_scan_config_request { 371 struct spectral_config sscan_config; 372 enum spectral_cp_error_code sscan_err_code; 373 }; 374 375 /** 376 * struct spectral_scan_action_request - Action request 377 * @sscan_err_code: Spectral scan error code 378 */ 379 struct spectral_scan_action_request { 380 enum spectral_cp_error_code sscan_err_code; 381 }; 382 383 /** 384 * struct spectral_scan_get_caps_request - Get caps request 385 * @sscan_caps: Spectral capabilities 386 * @sscan_err_code: Spectral scan error code 387 */ 388 struct spectral_scan_get_caps_request { 389 struct spectral_caps sscan_caps; 390 enum spectral_cp_error_code sscan_err_code; 391 }; 392 393 /** 394 * struct spectral_scan_get_diag_request - Get diag request 395 * @sscan_diag: Spectral diag stats 396 * @sscan_err_code: Spectral scan error code 397 */ 398 struct spectral_scan_get_diag_request { 399 struct spectral_diag_stats sscan_diag; 400 enum spectral_cp_error_code sscan_err_code; 401 }; 402 403 /** 404 * struct spectral_scan_get_chan_width_request - Get channel width request 405 * @chan_width: Channel width 406 * @sscan_err_code: Spectral scan error code 407 */ 408 struct spectral_scan_get_chan_width_request { 409 uint32_t chan_width; 410 enum spectral_cp_error_code sscan_err_code; 411 }; 412 413 /** 414 * struct spectral_scan_get_status_request - Get status request 415 * @is_active: is Spectral scan active 416 * @is_enabled: is Spectral scan enabled 417 * @sscan_err_code: Spectral scan error code 418 */ 419 struct spectral_scan_get_status_request { 420 bool is_active; 421 bool is_enabled; 422 enum spectral_cp_error_code sscan_err_code; 423 }; 424 425 /** 426 * struct spectral_scan_debug_request - Get/set debug level request 427 * @spectral_dbg_level: Spectral debug level 428 * @sscan_err_code: Spectral scan error code 429 */ 430 struct spectral_scan_debug_request { 431 uint32_t spectral_dbg_level; 432 enum spectral_cp_error_code sscan_err_code; 433 }; 434 435 /** 436 * struct spectral_scan_dma_debug_request - DMA debug request 437 * @dma_debug_enable: Enable/disable @dma_debug_type 438 * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug 439 * @sscan_err_code: Spectral scan error code 440 */ 441 struct spectral_scan_dma_debug_request { 442 bool dma_debug_enable; 443 enum spectral_dma_debug dma_debug_type; 444 enum spectral_cp_error_code sscan_err_code; 445 }; 446 447 /** 448 * struct spectral_cp_request - Spectral control path request 449 * Creating request and extracting response has to 450 * be atomic. 451 * @ss_mode: Spectral scan mode 452 * @req_id: Request identifier 453 * @vdev_id: VDEV id 454 * @dma_debug_req: Spectral DMA debug request 455 */ 456 struct spectral_cp_request { 457 enum spectral_scan_mode ss_mode; 458 uint8_t req_id; 459 uint8_t vdev_id; 460 union { 461 struct spectral_scan_config_request config_req; 462 struct spectral_scan_action_request action_req; 463 struct spectral_scan_get_caps_request caps_req; 464 struct spectral_scan_get_diag_request diag_req; 465 struct spectral_scan_get_chan_width_request chan_width_req; 466 struct spectral_scan_get_status_request status_req; 467 struct spectral_scan_debug_request debug_req; 468 struct spectral_scan_dma_debug_request dma_debug_req; 469 }; 470 }; 471 472 /** 473 * struct spectral_data_stats - Spectral data stats 474 * @spectral_rx_events: Number of Spectral rx events 475 * @consume_spectral_calls: Number of consume_spectral_report() invocations 476 * @fill_samp_msg_calls: Number of fill_samp_msg() invocations 477 * @msgs_ready_for_user: Number of SAMP messages that are ready to be sent to 478 * user-space 479 * @msgs_queued_to_user: Number of SAMP messages queued to the user-space 480 */ 481 struct spectral_data_stats { 482 uint32_t spectral_rx_events; 483 uint32_t consume_spectral_calls; 484 uint32_t fill_samp_msg_calls; 485 uint32_t msgs_ready_for_user; 486 uint32_t msgs_queued_to_user; 487 }; 488 489 #ifndef __KERNEL__ 490 491 static inline int16_t 492 spectral_pwfactor_max(int16_t pwfactor1, 493 int16_t pwfactor2) 494 { 495 return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2); 496 } 497 498 /** 499 * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling 500 * @agc_total_gain_db: AGC total gain in dB steps 501 * @gen3_defmaxgain: Default max gain value of the gen III chipset 502 * @gen2_maxgain: Max gain value used by the reference gen II chipset 503 * @lowlevel_offset: Low level offset for scaling 504 * @inband_pwr: In band power in dB steps 505 * @rssi_thr: RSSI threshold for scaling 506 * 507 * Helper function to compute RSSI correction factor for Gen III linear format 508 * Spectral scaling. It is the responsibility of the caller to ensure that 509 * correct values are passed. 510 * 511 * Return: RSSI correction factor 512 */ 513 static inline int16_t 514 get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db, 515 u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain, 516 int16_t lowlevel_offset, int16_t inband_pwr, 517 int16_t rssi_thr) 518 { 519 return ((agc_total_gain_db < gen3_defmaxgain) ? 520 (gen2_maxgain - gen3_defmaxgain + lowlevel_offset) : 521 spectral_pwfactor_max((inband_pwr - rssi_thr), 0)); 522 } 523 524 /** 525 * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent 526 * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report 527 * generated by the Gen III chipset 528 * @gen2_maxgain: Max gain value used by the reference gen II chipset 529 * @gen3_defmaxgain: Default max gain value of the gen III chipset 530 * @lowlevel_offset: Low level offset for scaling 531 * @inband_pwr: In band power in dB steps 532 * @rssi_thr: RSSI threshold for scaling 533 * @agc_total_gain_db: AGC total gain in dB steps 534 * @highlevel_offset: High level offset for scaling 535 * @gen2_bin_scale: Bin scale value used on reference gen II chipset 536 * @gen3_bin_scale: Bin scale value used on gen III chipset 537 * 538 * Helper function to scale a given gen III linear format bin value into an 539 * approximately equivalent gen II value. The scaled value can possibly be 540 * higher than 8 bits. If the caller is incapable of handling values larger 541 * than 8 bits, the caller can saturate the value at 255. This function does not 542 * carry out this saturation for the sake of flexibility so that callers 543 * interested in the larger values can avail of this. Also note it is the 544 * responsibility of the caller to ensure that correct values are passed. 545 * 546 * Return: Scaled bin value 547 */ 548 static inline u_int32_t 549 spectral_scale_linear_to_gen2(u_int8_t gen3_binmag, 550 u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain, 551 int16_t lowlevel_offset, int16_t inband_pwr, 552 int16_t rssi_thr, u_int8_t agc_total_gain_db, 553 int16_t highlevel_offset, u_int8_t gen2_bin_scale, 554 u_int8_t gen3_bin_scale) 555 { 556 return (gen3_binmag * 557 sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain - 558 gen3_defmaxgain + lowlevel_offset - 559 get_spectral_scale_rssi_corr(agc_total_gain_db, 560 gen3_defmaxgain, 561 gen2_maxgain, 562 lowlevel_offset, 563 inband_pwr, 564 rssi_thr), 565 (agc_total_gain_db < gen3_defmaxgain) * 566 highlevel_offset)) / 10))) * 567 pow(2, (gen3_bin_scale - gen2_bin_scale))); 568 } 569 570 #endif /* __KERNEL__ */ 571 572 #endif /* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */ 573