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