xref: /wlan-dirver/qca-wifi-host-cmn/spectral/dispatcher/inc/wlan_spectral_public_structs.h (revision 45a38684b07295822dc8eba39e293408f203eec8)
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 spectral_debug - Spectral debug level
166  * @DEBUG_SPECTRAL:  Minimal SPECTRAL debug
167  * @DEBUG_SPECTRAL1: Normal SPECTRAL debug
168  * @DEBUG_SPECTRAL2: Maximal SPECTRAL debug
169  * @DEBUG_SPECTRAL3: Matched filterID display
170  * @DEBUG_SPECTRAL4: One time dump of FFT report
171  */
172 enum spectral_debug {
173 	DEBUG_SPECTRAL = 0x00000100,
174 	DEBUG_SPECTRAL1 = 0x00000200,
175 	DEBUG_SPECTRAL2 = 0x00000400,
176 	DEBUG_SPECTRAL3 = 0x00000800,
177 	DEBUG_SPECTRAL4 = 0x00001000,
178 };
179 
180 /**
181  * enum spectral_capability_type - Spectral capability type
182  * @SPECTRAL_CAP_PHYDIAG:              Phydiag capability
183  * @SPECTRAL_CAP_RADAR:                Radar detection capability
184  * @SPECTRAL_CAP_SPECTRAL_SCAN:        Spectral capability
185  * @SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN: Advanced spectral capability
186  */
187 enum spectral_capability_type {
188 	SPECTRAL_CAP_PHYDIAG,
189 	SPECTRAL_CAP_RADAR,
190 	SPECTRAL_CAP_SPECTRAL_SCAN,
191 	SPECTRAL_CAP_ADVNCD_SPECTRAL_SCAN,
192 };
193 
194 /**
195  * enum spectral_cp_error_code - Spectral control path response code
196  * @SPECTRAL_SCAN_RESP_ERR_INVALID: Invalid error identifier
197  * @SPECTRAL_SCAN_RESP_ERR_PARAM_UNSUPPORTED: parameter unsupported
198  * @SPECTRAL_SCAN_RESP_ERR_MODE_UNSUPPORTED: mode unsupported
199  * @SPECTRAL_SCAN_RESP_ERR_PARAM_INVALID_VALUE: invalid parameter value
200  * @SPECTRAL_SCAN_RESP_ERR_PARAM_NOT_INITIALIZED: parameter uninitialized
201  */
202 enum spectral_cp_error_code {
203 	SPECTRAL_SCAN_ERR_INVALID,
204 	SPECTRAL_SCAN_ERR_PARAM_UNSUPPORTED,
205 	SPECTRAL_SCAN_ERR_MODE_UNSUPPORTED,
206 	SPECTRAL_SCAN_ERR_PARAM_INVALID_VALUE,
207 	SPECTRAL_SCAN_ERR_PARAM_NOT_INITIALIZED,
208 };
209 
210 /**
211  * enum spectral_dma_debug -   Spectral DMA debug
212  * @SPECTRAL_DMA_RING_DEBUG:   Spectral DMA ring debug
213  * @SPECTRAL_DMA_BUFFER_DEBUG: Spectral DMA buffer debug
214  */
215 enum spectral_dma_debug {
216 	SPECTRAL_DMA_RING_DEBUG,
217 	SPECTRAL_DMA_BUFFER_DEBUG,
218 };
219 
220 struct wiphy;
221 
222 /**
223  * struct spectral_cfg80211_vendor_cmd_handlers - Spectral vendor command
224  * handlers
225  * @wlan_cfg80211_spectral_scan_start: start scan handler
226  * @wlan_cfg80211_spectral_scan_stop: stop scan handler
227  * @wlan_cfg80211_spectral_scan_get_config: get config handler
228  * @wlan_cfg80211_spectral_scan_get_diag_stats: get diag stats handler
229  * @wlan_cfg80211_spectral_scan_get_cap: get capability handler
230  * @wlan_cfg80211_spectral_scan_get_status: get status handler
231  */
232 struct spectral_cfg80211_vendor_cmd_handlers {
233 	int (*wlan_cfg80211_spectral_scan_start)(struct wiphy *wiphy,
234 						 struct wlan_objmgr_pdev *pdev,
235 						 struct wlan_objmgr_vdev *vdev,
236 						 const void *data,
237 						 int data_len);
238 	int (*wlan_cfg80211_spectral_scan_stop)(struct wiphy *wiphy,
239 						struct wlan_objmgr_pdev *pdev,
240 						struct wlan_objmgr_vdev *vdev,
241 						const void *data,
242 						int data_len);
243 	int (*wlan_cfg80211_spectral_scan_get_config)(
244 						struct wiphy *wiphy,
245 						struct wlan_objmgr_pdev *pdev,
246 						struct wlan_objmgr_vdev *vdev,
247 						const void *data,
248 						int data_len);
249 	int (*wlan_cfg80211_spectral_scan_get_diag_stats)(
250 						struct wiphy *wiphy,
251 						struct wlan_objmgr_pdev *pdev,
252 						struct wlan_objmgr_vdev *vdev,
253 						const void *data,
254 						int data_len);
255 	int (*wlan_cfg80211_spectral_scan_get_cap)(
256 						struct wiphy *wiphy,
257 						struct wlan_objmgr_pdev *pdev,
258 						struct wlan_objmgr_vdev *vdev,
259 						const void *data,
260 						int data_len);
261 	int (*wlan_cfg80211_spectral_scan_get_status)(
262 						struct wiphy *wiphy,
263 						struct wlan_objmgr_pdev *pdev,
264 						struct wlan_objmgr_vdev *vdev,
265 						const void *data,
266 						int data_len);
267 };
268 
269 /**
270  * struct spectral_cp_param - Spectral control path data structure which
271  * contains parameter and its value
272  * @id: Parameter ID
273  * @value: Single parameter value
274  * @freq: Spectral scan frequency
275  */
276 struct spectral_cp_param {
277 	uint32_t id;
278 	union {
279 		uint32_t value;
280 		struct spectral_config_frequency freq;
281 	};
282 };
283 
284 /**
285  * struct spectral_chan_stats - channel status info
286  * @cycle_count:         Cycle count
287  * @channel_load:        Channel load
288  * @per:                 Period
289  * @noisefloor:          Noise floor
290  * @comp_usablity:       Computed usability
291  * @maxregpower:         Maximum allowed regulatory power
292  * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
293  * @maxregpower_sec80:   Max regulatory power of secondary 80 Mhz
294  */
295 struct spectral_chan_stats {
296 	int cycle_count;
297 	int channel_load;
298 	int per;
299 	int noisefloor;
300 	uint16_t comp_usablity;
301 	int8_t maxregpower;
302 	uint16_t comp_usablity_sec80;
303 	int8_t maxregpower_sec80;
304 };
305 
306 /**
307  * struct spectral_diag_stats - spectral diag stats
308  * @spectral_mismatch:             Spectral TLV signature mismatches
309  * @spectral_sec80_sfft_insufflen: Insufficient length when parsing for
310  *                                 Secondary 80 Search FFT report
311  * @spectral_no_sec80_sfft:        Secondary 80 Search FFT report
312  *                                 TLV not found
313  * @spectral_vhtseg1id_mismatch:   VHT Operation Segment 1 ID
314  *                                 mismatches in Search FFT report
315  * @spectral_vhtseg2id_mismatch:   VHT Operation Segment 2 ID
316  *                                 mismatches in Search FFT report
317  * @spectral_invalid_detector_id:  Invalid detector id
318  */
319 struct spectral_diag_stats {
320 	uint64_t spectral_mismatch;
321 	uint64_t spectral_sec80_sfft_insufflen;
322 	uint64_t spectral_no_sec80_sfft;
323 	uint64_t spectral_vhtseg1id_mismatch;
324 	uint64_t spectral_vhtseg2id_mismatch;
325 	uint64_t spectral_invalid_detector_id;
326 };
327 
328 /**
329  * struct spectral_scan_state - State of spectral scan
330  * @is_active:  Is spectral scan active
331  * @is_enabled: Is spectral scan enabled
332  */
333 struct spectral_scan_state {
334 	uint8_t is_active;
335 	uint8_t is_enabled;
336 };
337 
338 /* Forward declarations */
339 struct wlan_objmgr_pdev;
340 
341 /**
342  * struct spectral_nl_cb - Spectral Netlink callbacks
343  * @get_sbuff:      Get the socket buffer to send the data to the application
344  * @send_nl_bcast:  Send data to the application using netlink broadcast
345  * @send_nl_unicast:  Send data to the application using netlink unicast
346  * @free_sbuff: Free the socket buffer for a particular message type
347  */
348 struct spectral_nl_cb {
349 	void *(*get_sbuff)(struct wlan_objmgr_pdev *pdev,
350 			   enum spectral_msg_type smsg_type,
351 			   enum spectral_msg_buf_type buf_type);
352 	int (*send_nl_bcast)(struct wlan_objmgr_pdev *pdev,
353 			     enum spectral_msg_type smsg_type);
354 	int (*send_nl_unicast)(struct wlan_objmgr_pdev *pdev,
355 			       enum spectral_msg_type smsg_type);
356 	void (*free_sbuff)(struct wlan_objmgr_pdev *pdev,
357 			   enum spectral_msg_type smsg_type);
358 };
359 
360 /**
361  * struct spectral_scan_config_request - Config request
362  * @sscan_config: Spectral parameters
363  * @sscan_err_code: Spectral scan error code
364  */
365 struct spectral_scan_config_request {
366 	struct spectral_config sscan_config;
367 	enum spectral_cp_error_code sscan_err_code;
368 };
369 
370 /**
371  * struct spectral_scan_action_request - Action request
372  * @sscan_err_code: Spectral scan error code
373  */
374 struct spectral_scan_action_request {
375 	enum spectral_cp_error_code sscan_err_code;
376 };
377 
378 /**
379  * struct spectral_scan_get_caps_request - Get caps request
380  * @sscan_caps: Spectral capabilities
381  * @sscan_err_code: Spectral scan error code
382  */
383 struct spectral_scan_get_caps_request {
384 	struct spectral_caps sscan_caps;
385 	enum spectral_cp_error_code sscan_err_code;
386 };
387 
388 /**
389  * struct spectral_scan_get_diag_request - Get diag request
390  * @sscan_diag: Spectral diag stats
391  * @sscan_err_code: Spectral scan error code
392  */
393 struct spectral_scan_get_diag_request {
394 	struct spectral_diag_stats sscan_diag;
395 	enum spectral_cp_error_code sscan_err_code;
396 };
397 
398 /**
399  * struct spectral_scan_get_chan_width_request - Get channel width request
400  * @chan_width: Channel width
401  * @sscan_err_code: Spectral scan error code
402  */
403 struct spectral_scan_get_chan_width_request {
404 	uint32_t chan_width;
405 	enum spectral_cp_error_code sscan_err_code;
406 };
407 
408 /**
409  * struct spectral_scan_get_status_request - Get status request
410  * @is_active: is Spectral scan active
411  * @is_enabled: is Spectral scan enabled
412  * @sscan_err_code: Spectral scan error code
413  */
414 struct spectral_scan_get_status_request {
415 	bool is_active;
416 	bool is_enabled;
417 	enum spectral_cp_error_code sscan_err_code;
418 };
419 
420 /**
421  * struct spectral_scan_debug_request - Get/set debug level request
422  * @spectral_dbg_level: Spectral debug level
423  * @sscan_err_code: Spectral scan error code
424  */
425 struct spectral_scan_debug_request {
426 	uint32_t spectral_dbg_level;
427 	enum spectral_cp_error_code sscan_err_code;
428 };
429 
430 /**
431  * struct spectral_scan_dma_debug_request - DMA debug request
432  * @dma_debug_enable: Enable/disable @dma_debug_type
433  * @dma_debug_type: Type of Spectral DMA debug i.e., ring or buffer debug
434  * @sscan_err_code: Spectral scan error code
435  */
436 struct spectral_scan_dma_debug_request {
437 	bool dma_debug_enable;
438 	enum spectral_dma_debug dma_debug_type;
439 	enum spectral_cp_error_code sscan_err_code;
440 };
441 
442 /**
443  * struct spectral_cp_request - Spectral control path request
444  *                              Creating request and extracting response has to
445  *                              be atomic.
446  * @ss_mode: Spectral scan mode
447  * @req_id: Request identifier
448  * @vdev_id: VDEV id
449  * @dma_debug_req: Spectral DMA debug request
450  */
451 struct spectral_cp_request {
452 	enum spectral_scan_mode ss_mode;
453 	uint8_t req_id;
454 	uint8_t vdev_id;
455 	union {
456 		struct spectral_scan_config_request config_req;
457 		struct spectral_scan_action_request action_req;
458 		struct spectral_scan_get_caps_request caps_req;
459 		struct spectral_scan_get_diag_request diag_req;
460 		struct spectral_scan_get_chan_width_request chan_width_req;
461 		struct spectral_scan_get_status_request status_req;
462 		struct spectral_scan_debug_request debug_req;
463 		struct spectral_scan_dma_debug_request dma_debug_req;
464 	};
465 };
466 
467 #ifndef __KERNEL__
468 
469 static inline int16_t
470 spectral_pwfactor_max(int16_t pwfactor1,
471 		      int16_t pwfactor2)
472 {
473 	return ((pwfactor1 > pwfactor2) ? pwfactor1 : pwfactor2);
474 }
475 
476 /**
477  * get_spectral_scale_rssi_corr() - Compute RSSI correction factor for scaling
478  * @agc_total_gain_db: AGC total gain in dB steps
479  * @gen3_defmaxgain: Default max gain value of the gen III chipset
480  * @gen2_maxgain: Max gain value used by the reference gen II chipset
481  * @lowlevel_offset: Low level offset for scaling
482  * @inband_pwr: In band power in dB steps
483  * @rssi_thr: RSSI threshold for scaling
484  *
485  * Helper function to compute RSSI correction factor for Gen III linear format
486  * Spectral scaling. It is the responsibility of the caller to ensure that
487  * correct values are passed.
488  *
489  * Return: RSSI correction factor
490  */
491 static inline int16_t
492 get_spectral_scale_rssi_corr(u_int8_t agc_total_gain_db,
493 			     u_int8_t gen3_defmaxgain, u_int8_t gen2_maxgain,
494 			     int16_t lowlevel_offset, int16_t inband_pwr,
495 			     int16_t rssi_thr)
496 {
497 	return ((agc_total_gain_db < gen3_defmaxgain) ?
498 		(gen2_maxgain - gen3_defmaxgain + lowlevel_offset) :
499 		spectral_pwfactor_max((inband_pwr - rssi_thr), 0));
500 }
501 
502 /**
503  * spectral_scale_linear_to_gen2() - Scale linear bin value to gen II equivalent
504  * @gen3_binmag: Captured FFT bin value from the Spectral Search FFT report
505  * generated by the Gen III chipset
506  * @gen2_maxgain: Max gain value used by the reference gen II chipset
507  * @gen3_defmaxgain: Default max gain value of the gen III chipset
508  * @lowlevel_offset: Low level offset for scaling
509  * @inband_pwr: In band power in dB steps
510  * @rssi_thr: RSSI threshold for scaling
511  * @agc_total_gain_db: AGC total gain in dB steps
512  * @highlevel_offset: High level offset for scaling
513  * @gen2_bin_scale: Bin scale value used on reference gen II chipset
514  * @gen3_bin_scale: Bin scale value used on gen III chipset
515  *
516  * Helper function to scale a given gen III linear format bin value into an
517  * approximately equivalent gen II value. The scaled value can possibly be
518  * higher than 8 bits.  If the caller is incapable of handling values larger
519  * than 8 bits, the caller can saturate the value at 255. This function does not
520  * carry out this saturation for the sake of flexibility so that callers
521  * interested in the larger values can avail of this. Also note it is the
522  * responsibility of the caller to ensure that correct values are passed.
523  *
524  * Return: Scaled bin value
525  */
526 static inline u_int32_t
527 spectral_scale_linear_to_gen2(u_int8_t gen3_binmag,
528 			      u_int8_t gen2_maxgain, u_int8_t gen3_defmaxgain,
529 			      int16_t lowlevel_offset, int16_t inband_pwr,
530 			      int16_t rssi_thr, u_int8_t agc_total_gain_db,
531 			      int16_t highlevel_offset, u_int8_t gen2_bin_scale,
532 			      u_int8_t gen3_bin_scale)
533 {
534 	return (gen3_binmag *
535 		sqrt(pow(10, (((double)spectral_pwfactor_max(gen2_maxgain -
536 			gen3_defmaxgain + lowlevel_offset -
537 			get_spectral_scale_rssi_corr(agc_total_gain_db,
538 						     gen3_defmaxgain,
539 						     gen2_maxgain,
540 						     lowlevel_offset,
541 						     inband_pwr,
542 						     rssi_thr),
543 			(agc_total_gain_db < gen3_defmaxgain) *
544 				highlevel_offset)) / 10))) *
545 		 pow(2, (gen3_bin_scale - gen2_bin_scale)));
546 }
547 
548 #endif /*  __KERNEL__  */
549 
550 #endif				/* _WLAN_SPECTRAL_PUBLIC_STRUCTS_H_ */
551