xref: /wlan-dirver/qca-wifi-host-cmn/spectral/dispatcher/inc/spectral_ioctl.h (revision 70a19e16789e308182f63b15c75decec7bf0b342)
1 /*
2  * Copyright (c) 2011, 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
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 #ifndef _SPECTRAL_IOCTL_H_
21 #define _SPECTRAL_IOCTL_H_
22 #include <wlan_dfs_ioctl.h>
23 
24 #ifndef AH_MAX_CHAINS
25 #define AH_MAX_CHAINS 3
26 #endif
27 
28 /* Compile time Assert */
29 #define SPECTRAL_COMPILE_TIME_ASSERT(assertion_name, predicate) \
30 	typedef char assertion_name[(predicate) ? 1 : -1]
31 
32 /*
33  * ioctl defines
34  */
35 
36 #define SPECTRAL_SET_CONFIG              (DFS_LAST_IOCTL + 1)
37 #define SPECTRAL_GET_CONFIG              (DFS_LAST_IOCTL + 2)
38 #define SPECTRAL_SHOW_INTERFERENCE       (DFS_LAST_IOCTL + 3)
39 #define SPECTRAL_ENABLE_SCAN             (DFS_LAST_IOCTL + 4)
40 #define SPECTRAL_DISABLE_SCAN            (DFS_LAST_IOCTL + 5)
41 #define SPECTRAL_ACTIVATE_SCAN           (DFS_LAST_IOCTL + 6)
42 #define SPECTRAL_STOP_SCAN               (DFS_LAST_IOCTL + 7)
43 #define SPECTRAL_SET_DEBUG_LEVEL         (DFS_LAST_IOCTL + 8)
44 #define SPECTRAL_IS_ACTIVE               (DFS_LAST_IOCTL + 9)
45 #define SPECTRAL_IS_ENABLED              (DFS_LAST_IOCTL + 10)
46 #define SPECTRAL_CLASSIFY_SCAN           (DFS_LAST_IOCTL + 11)
47 #define SPECTRAL_GET_CLASSIFIER_CONFIG   (DFS_LAST_IOCTL + 12)
48 #define SPECTRAL_EACS                    (DFS_LAST_IOCTL + 13)
49 #define SPECTRAL_ACTIVATE_FULL_SCAN      (DFS_LAST_IOCTL + 14)
50 #define SPECTRAL_STOP_FULL_SCAN          (DFS_LAST_IOCTL + 15)
51 #define SPECTRAL_GET_CAPABILITY_INFO     (DFS_LAST_IOCTL + 16)
52 #define SPECTRAL_GET_DIAG_STATS          (DFS_LAST_IOCTL + 17)
53 #define SPECTRAL_GET_CHAN_WIDTH          (DFS_LAST_IOCTL + 18)
54 #define SPECTRAL_GET_CHANINFO            (DFS_LAST_IOCTL + 19)
55 #define SPECTRAL_CLEAR_CHANINFO          (DFS_LAST_IOCTL + 20)
56 #define SPECTRAL_SET_ICM_ACTIVE          (DFS_LAST_IOCTL + 21)
57 #define SPECTRAL_GET_NOMINAL_NOISEFLOOR  (DFS_LAST_IOCTL + 22)
58 #define SPECTRAL_GET_DEBUG_LEVEL         (DFS_LAST_IOCTL + 23)
59 #define SPECTRAL_SET_DMA_DEBUG           (DFS_LAST_IOCTL + 24)
60 
61 /*
62  * Increase spectral sub version if struct spectral_samp_msg updated.
63  */
64 #define SPECTRAL_VERSION     (3)
65 #define SPECTRAL_SUB_VERSION (1)
66 
67 /*
68  * ioctl parameter types
69  */
70 enum spectral_params {
71 	SPECTRAL_PARAM_FFT_PERIOD,
72 	SPECTRAL_PARAM_SCAN_PERIOD,
73 	SPECTRAL_PARAM_FFT_RECAPTURE,
74 	SPECTRAL_PARAM_SCAN_COUNT,
75 	SPECTRAL_PARAM_SHORT_REPORT,
76 	SPECTRAL_PARAM_SPECT_PRI,
77 	SPECTRAL_PARAM_FFT_SIZE,
78 	SPECTRAL_PARAM_GC_ENA,
79 	SPECTRAL_PARAM_RESTART_ENA,
80 	SPECTRAL_PARAM_NOISE_FLOOR_REF,
81 	SPECTRAL_PARAM_INIT_DELAY,
82 	SPECTRAL_PARAM_NB_TONE_THR,
83 	SPECTRAL_PARAM_STR_BIN_THR,
84 	SPECTRAL_PARAM_WB_RPT_MODE,
85 	SPECTRAL_PARAM_RSSI_RPT_MODE,
86 	SPECTRAL_PARAM_RSSI_THR,
87 	SPECTRAL_PARAM_PWR_FORMAT,
88 	SPECTRAL_PARAM_RPT_MODE,
89 	SPECTRAL_PARAM_BIN_SCALE,
90 	SPECTRAL_PARAM_DBM_ADJ,
91 	SPECTRAL_PARAM_CHN_MASK,
92 	SPECTRAL_PARAM_ACTIVE,
93 	SPECTRAL_PARAM_STOP,
94 	SPECTRAL_PARAM_ENABLE,
95 	SPECTRAL_PARAM_FREQUENCY,
96 	SPECTRAL_PARAM_CHAN_FREQUENCY,
97 	SPECTRAL_PARAM_CHAN_WIDTH,
98 	SPECTRAL_PARAM_MAX,
99 };
100 
101 /**
102  * enum spectral_report_mode: Spectral report mode
103  * @SPECTRAL_REPORT_MODE_0: No FFT report (only spectral scan summary report)
104  * @SPECTRAL_REPORT_MODE_1: FFT report header + spectral scan summary report
105  * @SPECTRAL_REPORT_MODE_2: FFt report header + in-band bins per
106  *                          FFT (half of the number of FFT bins), where the
107  *                          FFT input is sampled at two times the channel
108  *                          bandwidth + spectral scan summary report
109  * @SPECTRAL_REPORT_MODE_3: FFT report header + all bins per FFT, where the FFT
110  *                          input is sampled at two times the channel bandwidth
111  *                          + spectral scan summary report
112  * @SPECTRAL_REPORT_MODE_MAX: Max number of report modes
113  */
114 enum spectral_report_mode {
115 	SPECTRAL_REPORT_MODE_0,
116 	SPECTRAL_REPORT_MODE_1,
117 	SPECTRAL_REPORT_MODE_2,
118 	SPECTRAL_REPORT_MODE_3,
119 	SPECTRAL_REPORT_MODE_MAX,
120 };
121 
122 /**
123  * enum spectral_pwr_format: Spectral FFT bin pwr format
124  * @SPECTRAL_PWR_FORMAT_LINEAR: Linear mode
125  * @SPECTRAL_PWR_FORMAT_DBM: dBm mode
126  */
127 enum spectral_pwr_format {
128 	SPECTRAL_PWR_FORMAT_LINEAR = 0,
129 	SPECTRAL_PWR_FORMAT_DBM = 1,
130 };
131 
132 /**
133  * enum spectral_scan_priority: Spectral scan priority
134  * @SPECTRAL_SCAN_PRIORITY_LOW: Low priority Spectral scan
135  * @SPECTRAL_SCAN_PRIORITY_HIGH: High priority Spectral scan
136  */
137 enum spectral_scan_priority {
138 	SPECTRAL_SCAN_PRIORITY_LOW = 0,
139 	SPECTRAL_SCAN_PRIORITY_HIGH = 1,
140 };
141 
142 /**
143  * enum spectral_fft_size : FFT size values
144  * @SPECTRAL_FFT_SIZE_INVALID: Invalid FFT size
145  * @SPECTRAL_FFT_SIZE_1: FFT size 1
146  * @SPECTRAL_FFT_SIZE_2: FFT size 2
147  * @SPECTRAL_FFT_SIZE_3: FFT size 3
148  * @SPECTRAL_FFT_SIZE_4: FFT size 4
149  * @SPECTRAL_FFT_SIZE_5: FFT size 5
150  * @SPECTRAL_FFT_SIZE_6: FFT size 6
151  * @SPECTRAL_FFT_SIZE_7: FFT size 7
152  * @SPECTRAL_FFT_SIZE_8: FFT size 8
153  * @SPECTRAL_FFT_SIZE_9: FFT size 9
154  * @SPECTRAL_FFT_SIZE_10: FFT size 10
155  * @SPECTRAL_FFT_SIZE_MAX: Max number of FFT size
156  */
157 enum spectral_fft_size {
158 	SPECTRAL_FFT_SIZE_INVALID,
159 	SPECTRAL_FFT_SIZE_1,
160 	SPECTRAL_FFT_SIZE_2,
161 	SPECTRAL_FFT_SIZE_3,
162 	SPECTRAL_FFT_SIZE_4,
163 	SPECTRAL_FFT_SIZE_5,
164 	SPECTRAL_FFT_SIZE_6,
165 	SPECTRAL_FFT_SIZE_7,
166 	SPECTRAL_FFT_SIZE_8,
167 	SPECTRAL_FFT_SIZE_9,
168 	SPECTRAL_FFT_SIZE_10,
169 	SPECTRAL_FFT_SIZE_MAX,
170 };
171 
172 /**
173  * enum spectral_scan_mode - Spectral scan mode
174  * @SPECTRAL_SCAN_MODE_NORMAL: Normal mode
175  * @SPECTRAL_SCAN_MODE_AGILE: Agile mode
176  * @SPECTRAL_SCAN_MODE_MAX: Max number of Spectral modes
177  * @SPECTRAL_SCAN_MODE_INVALID: Invalid Spectral mode
178  */
179 enum spectral_scan_mode {
180 	SPECTRAL_SCAN_MODE_NORMAL,
181 	SPECTRAL_SCAN_MODE_AGILE,
182 	SPECTRAL_SCAN_MODE_MAX,
183 	SPECTRAL_SCAN_MODE_INVALID = 0xff,
184 };
185 
186 /**
187  * enum spectral_chan_width - Spectral-specific channel width enum
188  * @SPECTRAL_CH_WIDTH_20MHZ: 20 mhz width
189  * @SPECTRAL_CH_WIDTH_40MHZ: 40 mhz width
190  * @SPECTRAL_CH_WIDTH_80MHZ: 80 mhz width
191  * @SPECTRAL_CH_WIDTH_160MHZ: 160 mhz width
192  * @SPECTRAL_CH_WIDTH_80P80MHZ: 80+80 mhz width
193  * @SPECTRAL_CH_WIDTH_5MHZ: 5 mhz width
194  * @SPECTRAL_CH_WIDTH_10MHZ: 10 mhz width
195  * @SPECTRAL_CH_WIDTH_320MHZ: 320 mhz width
196  * @SPECTRAL_CH_WIDTH_MAX: Max possible width
197  * @SPECTRAL_CH_WIDTH_INVALID: invalid width
198  */
199 enum spectral_chan_width {
200 	SPECTRAL_CH_WIDTH_20MHZ,
201 	SPECTRAL_CH_WIDTH_40MHZ,
202 	SPECTRAL_CH_WIDTH_80MHZ,
203 	SPECTRAL_CH_WIDTH_160MHZ,
204 	SPECTRAL_CH_WIDTH_80P80MHZ,
205 	SPECTRAL_CH_WIDTH_320MHZ,
206 	SPECTRAL_CH_WIDTH_5MHZ,
207 	SPECTRAL_CH_WIDTH_10MHZ,
208 	SPECTRAL_CH_WIDTH_MAX,
209 	SPECTRAL_CH_WIDTH_INVALID,
210 };
211 
212 struct spectral_ioctl_params {
213 	int16_t   spectral_fft_period;
214 	int16_t   pectral_period;
215 	int16_t   spectral_count;
216 	uint16_t spectral_short_report;
217 	uint16_t spectral_pri;
218 };
219 
220 /**
221  * enum spectral_cap_hw_gen - Definitions for the Spectral hardware generation.
222  * This corresponds to definitions in qca_wlan_vendor_spectral_scan_cap_hw_gen.
223  * @SPECTRAL_CAP_HW_GEN_1: Generation 1
224  * @SPECTRAL_CAP_HW_GEN_2: Generation 2
225  * @SPECTRAL_CAP_HW_GEN_3: Generation 3
226  */
227 enum spectral_cap_hw_gen {
228 	SPECTRAL_CAP_HW_GEN_1 = 0,
229 	SPECTRAL_CAP_HW_GEN_2 = 1,
230 	SPECTRAL_CAP_HW_GEN_3 = 2,
231 };
232 
233 /**
234  * struct spectral_config_frequency - Spectral scan frequency
235  * @cfreq1: Center frequency (in MHz) of the span of interest(primary 80 MHz
236  *          span for 80 + 80 agile scan request) or center frequency (in MHz)
237  *          of any WLAN channel in the span of interest.
238  * @cfreq2: Applicable only for Agile Spectral scan request in 80+80 MHz mode.
239  *          For 80+80 mode it represents  the center frequency (in MHz) of the
240  *          secondary 80 MHz span of interest or center frequency (in MHz) of
241  *          any WLAN channel in the secondary 80 MHz span of interest.
242  */
243 struct spectral_config_frequency {
244 	uint32_t cfreq1;
245 	uint32_t cfreq2;
246 };
247 
248 /**
249  * struct spectral_config - spectral config parameters
250  * @ss_fft_period:        Skip interval for FFT reports
251  * @ss_period:            Spectral scan period
252  * @ss_recapture:         Set this to allow FFT recapture if scan period > 52us
253  * @ss_count:             # of reports to return from ss_active
254  * @ss_short_report:      Set to report only 1 set of FFT results
255  * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT
256  * @ss_spectral_pri:      Priority, and are we doing a noise power cal ?
257  * @ss_fft_size:          Defines the number of FFT data points to compute,
258  *                        defined as a log index num_fft_pts =
259  *                        2^ss_fft_size
260  * @ss_gc_ena:            Set, to enable targeted gain change before
261  *                        starting the spectral scan FFT
262  * @ss_restart_ena:       Set, to enable abort of receive frames when in high
263  *                        priority and a spectral scan is queued
264  * @ss_noise_floor_ref:   Noise floor reference number (signed) for the
265  *                        calculation of bin power (dBm) Though stored as an
266  *                        unsigned this should be treated as a signed 8-bit int.
267  * @ss_init_delay:        Disallow spectral scan triggers after tx/rx packets
268  *                        by setting this delay value to roughly SIFS time
269  *                        period or greater Delay timer count in units of 0.25us
270  * @ss_nb_tone_thr:       Number of strong bins (inclusive) per sub-channel,
271  *                        below which a signal is declared a narrowband tone
272  * @ss_str_bin_thr:       Bin/max_bin ratio threshold over which a bin is
273  *                        declared strong (for spectral scan bandwidth analysis)
274  * @ss_wb_rpt_mode:       Set this bit to report spectral scans as EXT_BLOCKER
275  *                        (phy_error=36), if none of the sub-channels are
276  *                        deemed narrowband
277  * @ss_rssi_rpt_mode:     Set this bit to report spectral scans as EXT_BLOCKER
278  *                        (phy_error=36), if the ADC RSSI is below the
279  *                        threshold ss_rssi_thr
280  * @ss_rssi_thr:          ADC RSSI must be greater than or equal to this
281  *                        threshold (signed Db) to ensure spectral scan
282  *                        reporting with normal phy error codes (please see
283  *                        ss_rssi_rpt_mode above).Though stored as an unsigned
284  *                        value, this should be treated as a signed 8-bit int
285  * @ss_pwr_format:        Format of frequency bin magnitude for spectral scan
286  *                        triggered FFTs 0: linear magnitude
287  *                        1: log magnitude (20*log10(lin_mag), 1/2 dB step size)
288  * @ss_rpt_mode:          Format of per-FFT reports to software for spectral
289  *                        scan triggered FFTs
290  *                        0: No FFT report (only pulse end summary)
291  *                        1: 2-dword summary of metrics for each completed FFT
292  *                        2: 2-dword summary + 1x-oversampled bins(in-band) per
293  *                           FFT
294  *                        3: 2-dword summary + 2x-oversampled bins (all) per FFT
295  * @ss_bin_scale:         Number of LSBs to shift out to scale the FFT bins
296  *                        for spectral scan triggered FFTs
297  * @ss_dbm_adj:           Set (with ss_pwr_format=1), to report bin
298  *                        magnitudes
299  *                        converted to dBm power using the noisefloor
300  *                        calibration results
301  * @ss_chn_mask:          Per chain enable mask to select input ADC for search
302  *                        FFT
303  * @ss_nf_cal:            nf calibrated values for ctl+ext
304  * @ss_nf_pwr:            nf pwr values for ctl+ext
305  * @ss_nf_temp_data:      temperature data taken during nf scan
306  * @ss_frequency:         This specifies the frequency span over which Spectral
307  *                        scan would be carried out. Its value depends on the
308  *                        Spectral scan mode.
309  *                        Normal mode:-
310  *                          Not applicable. Spectral scan would happen in the
311  *                          operating span.
312  *                        Agile mode:-
313  *                          cfreq1 represents the center frequency (in MHz) of
314  *                          the span of interest(primary 80 MHz span for 80 + 80
315  *                          agile scan request) or center frequency (in MHz) of
316  *                          any WLAN channel in the span of interest. cfreq2 is
317  *                          applicable only for Agile Spectral scan request in
318  *                          80+80 MHz mode. For 80+80 mode it represents  the
319  *                          center frequency (in MHz) of the secondary 80 MHz
320  *                          span of interest or center frequency (in MHz) of
321  *                          any WLAN channel in the secondary 80 MHz span of
322  *                          interest.
323  * @ss_bandwidth: Spectral scan bandwidth
324  */
325 struct spectral_config {
326 	uint16_t ss_fft_period;
327 	uint16_t ss_period;
328 	uint16_t ss_recapture;
329 	uint16_t ss_count;
330 	uint16_t ss_short_report;
331 	uint8_t radar_bin_thresh_sel;
332 	uint16_t ss_spectral_pri;
333 	uint16_t ss_fft_size;
334 	uint16_t ss_gc_ena;
335 	uint16_t ss_restart_ena;
336 	uint16_t ss_noise_floor_ref;
337 	uint16_t ss_init_delay;
338 	uint16_t ss_nb_tone_thr;
339 	uint16_t ss_str_bin_thr;
340 	uint16_t ss_wb_rpt_mode;
341 	uint16_t ss_rssi_rpt_mode;
342 	uint16_t ss_rssi_thr;
343 	uint16_t ss_pwr_format;
344 	uint16_t ss_rpt_mode;
345 	uint16_t ss_bin_scale;
346 	uint16_t ss_dbm_adj;
347 	uint16_t ss_chn_mask;
348 	int8_t ss_nf_cal[AH_MAX_CHAINS * 2];
349 	int8_t ss_nf_pwr[AH_MAX_CHAINS * 2];
350 	int32_t ss_nf_temp_data;
351 	struct spectral_config_frequency ss_frequency;
352 	uint16_t ss_bandwidth;
353 };
354 
355 /**
356  * struct spectral_caps - Spectral capabilities structure
357  * @phydiag_cap:         Phydiag capability
358  * @radar_cap:           Radar detection capability
359  * @spectral_cap:        Spectral capability
360  * @advncd_spectral_cap: Advanced spectral capability
361  * @hw_gen: Spectral hw generation as defined in spectral_cap_hw_gen
362  * @is_scaling_params_populated: indicates whether scaling params is populated
363  * @formula_id: formula_id
364  * @low_level_offset: low_level_offset
365  * @high_level_offset: high_level_offset
366  * @rssi_thr: rssi_thr
367  * @default_agc_max_gain: default_agc_max_gain
368  * @agile_spectral_cap: agile Spectral capability for 20/40/80
369  * @agile_spectral_cap_160: agile Spectral capability for 160 MHz
370  * @agile_spectral_cap_80p80: agile Spectral capability for 80p80
371  * @agile_spectral_cap_320: agile Spectral capability for 320 MHz
372  * @num_detectors_20mhz: number of Spectral detectors in 20 MHz
373  * @num_detectors_40mhz: number of Spectral detectors in 40 MHz
374  * @num_detectors_80mhz: number of Spectral detectors in 80 MHz
375  * @num_detectors_160mhz: number of Spectral detectors in 160 MHz
376  * @num_detectors_80p80mhz: number of Spectral detectors in 80p80 MHz
377  * @num_detectors_320mhz: number of Spectral detectors in 320 MHz
378  */
379 struct spectral_caps {
380 	uint8_t phydiag_cap;
381 	uint8_t radar_cap;
382 	uint8_t spectral_cap;
383 	uint8_t advncd_spectral_cap;
384 	uint32_t hw_gen;
385 	bool is_scaling_params_populated;
386 	uint16_t formula_id;
387 	int16_t low_level_offset;
388 	int16_t high_level_offset;
389 	int16_t rssi_thr;
390 	uint8_t default_agc_max_gain;
391 	bool agile_spectral_cap;
392 	bool agile_spectral_cap_160;
393 	bool agile_spectral_cap_80p80;
394 	bool agile_spectral_cap_320;
395 	uint32_t num_detectors_20mhz;
396 	uint32_t num_detectors_40mhz;
397 	uint32_t num_detectors_80mhz;
398 	uint32_t num_detectors_160mhz;
399 	uint32_t num_detectors_80p80mhz;
400 	uint32_t num_detectors_320mhz;
401 };
402 
403 #define SPECTRAL_IOCTL_PARAM_NOVAL (65535)
404 
405 #define MAX_SPECTRAL_CHAINS           (3)
406 #define MAX_NUM_BINS                  (2048)
407 #define MAX_NUM_BINS_PRI80            (1024)
408 #define MAX_NUM_BINS_SEC80            (520)
409 #define MAX_NUM_BINS_5MHZ             (32)
410 /* 5 categories x (lower + upper) bands */
411 #define MAX_INTERF                   10
412 #define SPECTRAL_MAC_ADDR_SIZE        (6)
413 #define MAX_NUM_FREQ_SPANS            (3)
414 #define MAX_NUM_DETECTORS             (2)
415 #define MAX_SPECTRAL_PAYLOAD          (3028)
416 
417 #define SPECTRAL_RECAPTURE_SCAN_PERIOD_THRESHOLD   (52)
418 
419 /**
420  * enum dcs_int_type - Interference type indicated by DCS
421  * @SPECTRAL_DCS_INT_NONE:  No interference
422  * @SPECTRAL_DCS_INT_CW:  CW interference
423  * @SPECTRAL_DCS_INT_WIFI:  WLAN interference
424  */
425 enum dcs_int_type {
426 	SPECTRAL_DCS_INT_NONE,
427 	SPECTRAL_DCS_INT_CW,
428 	SPECTRAL_DCS_INT_WIFI
429 };
430 
431 /**
432  * struct interf_rsp - Interference record
433  * @interf_type:         eINTERF_TYPE giving type of interference
434  * @interf_min_freq:     Minimum frequency in MHz at which interference has been
435  * found
436  * @interf_max_freq:     Maximum frequency in MHz at which interference has been
437  * found
438  * @advncd_spectral_cap: Advanced spectral capability
439  */
440 struct interf_rsp {
441 	uint8_t interf_type;
442 	uint16_t interf_min_freq;
443 	uint16_t interf_max_freq;
444 } __packed;
445 
446 /**
447  * struct interf_src_rsp - List of interference sources
448  * @count: Number of interference records
449  * @interf: Array of interference records
450  */
451 struct interf_src_rsp {
452 	uint16_t count;
453 	struct interf_rsp interf[MAX_INTERF];
454 } __packed;
455 
456 /**
457  * struct spectral_classifier_params - spectral classifier parameters
458  * @spectral_20_40_mode:  Is AP in 20/40 mode?
459  * @spectral_dc_index:    DC index
460  * @spectral_dc_in_mhz:   DC in MHz
461  * @upper_chan_in_mhz:    Upper channel in MHz
462  * @lower_chan_in_mhz:    Lower channel in MHz
463  */
464 struct spectral_classifier_params {
465 	int spectral_20_40_mode;
466 	int spectral_dc_index;
467 	int spectral_dc_in_mhz;
468 	int upper_chan_in_mhz;
469 	int lower_chan_in_mhz;
470 } __packed;
471 
472 #ifdef OPTIMIZED_SAMP_MESSAGE
473 /**
474  * struct samp_edge_extra_bin_info - Spectral edge extra bins Information
475  * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
476  * delivered.  However, there can be additional bins reported for
477  * AR900B version 2.0 and QCA9984 as described next:
478  * AR900B version 2.0: An additional tone is processed on the right
479  * hand side in order to facilitate detection of radar pulses out to
480  * the extreme band-edge of the channel frequency.
481  * Since the HW design processes four tones at a time,
482  * this requires one additional Dword to be added to the
483  * search FFT report.
484  * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
485  * 1x-oversampled bins (in-band) per FFT,
486  * then 8 more bins (4 more on left side and 4 more on right side)
487  * are added.
488  *
489  * @num_bins: Number of edge extra bins
490  * @start_bin_idx: Indicates the start index of extra bins
491  */
492 struct samp_edge_extra_bin_info {
493 	uint16_t num_bins;
494 	uint16_t start_bin_idx;
495 } __packed;
496 
497 /* Compile time assert to check struct size is divisible by 4 Bytes */
498 SPECTRAL_COMPILE_TIME_ASSERT(struct_size_4byte_assertion,
499 			     (sizeof(struct samp_edge_extra_bin_info) % 4)
500 			     == 0);
501 
502 /**
503  * struct samp_detector_info - SAMP per-detector information
504  * A detector here refers to the HW carrying out the Spectral scan, to
505  * detect the presence of interferences.
506  * @start_frequency: Indicates start frequency per-detector (in MHz)
507  * @end_frequency: Indicates last frequency per-detector (in MHz)
508  * @timestamp: Indicates Spectral HW timestamp (usec)
509  * @last_tstamp: Indicates the last time stamp
510  * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of
511  * 160Mhz it will be primary 80 segment's timestamp as both primary & secondary
512  * segment's timestamp are expected to be almost equal.
513  * @timestamp_war_offset: Offset calculated based on reset_delay and
514  * last_raw_timestamp. It will be added to raw_timestamp to get timestamp.
515  * @raw_timestamp: Actual FFT timestamp reported by HW
516  * @reset_delay: Time gap between the last spectral report before reset and the
517  * end of reset. It is provided by FW via direct DMA framework.
518  * @left_edge_bins: Number of extra bins on left band edge
519  * @right_edge_bins: Number of extra bins on right band edge
520  * @start_bin_idx: Indicates the first bin index per-detector
521  * @end_bin_idx: Indicates the last bin index per-detector
522  * @max_index: Indicates the index of max magnitude
523  * @max_magnitude: Indicates the maximum magnitude
524  * @noise_floor: Indicates the current noise floor
525  * @rssi: Indicates RSSI
526  * @agc_total_gain:
527  * @gainchange:
528  * @pri80ind: Indication from hardware that the sample was received on the
529  * primary 80 MHz segment. If this is set for smode = SPECTRAL_SCAN_MODE_AGILE,
530  * it indicates that Spectral scan was carried out on pri80 instead of the
531  * Agile frequency due to a channel switch - Software may choose to ignore
532  * the sample in this case.
533  * @is_sec80: Indicates whether the frequency span corresponds to pri80 or
534  * sec80 (only applicable for 160/80p80 operating_bw for
535  * smode SPECTRAL_SCAN_MODE_NORMAL)
536  * @padding_detector_info: padding bytes
537  */
538 struct samp_detector_info {
539 	uint32_t start_frequency;
540 	uint32_t end_frequency;
541 	uint32_t timestamp;
542 	uint32_t last_tstamp;
543 	uint32_t last_raw_timestamp;
544 	uint32_t timestamp_war_offset;
545 	uint32_t raw_timestamp;
546 	uint32_t reset_delay;
547 	struct samp_edge_extra_bin_info left_edge_bins;
548 	struct samp_edge_extra_bin_info right_edge_bins;
549 	uint16_t start_bin_idx;
550 	uint16_t end_bin_idx;
551 	uint16_t max_index;
552 	uint16_t max_magnitude;
553 	int16_t noise_floor;
554 	int8_t rssi;
555 	uint8_t agc_total_gain;
556 	uint8_t gainchange;
557 	uint8_t pri80ind;
558 	uint8_t is_sec80;
559 	/* Padding bits to make struct size multiple of 4 bytes */
560 	uint8_t padding_detector_info[1];
561 } __packed;
562 
563 /* Compile time assert to check struct size is divisible by 4 Bytes */
564 SPECTRAL_COMPILE_TIME_ASSERT(struct_size_4byte_assertion,
565 			     (sizeof(struct samp_detector_info) % 4) == 0);
566 
567 /**
568  * struct samp_freq_span_info - SAMP per-frequency span information
569  * A frequency span here refers to a contiguous span of frequencies in which
570  * Spectral scan and interference detection is carried out.
571  * @detector_info: Per-detector Spectral information
572  * @num_detectors: Number of detectors per span
573  * @padding_span_info: padding bytes
574  */
575 struct samp_freq_span_info {
576 	struct samp_detector_info detector_info[MAX_NUM_DETECTORS];
577 	uint8_t num_detectors;
578 	/* Padding bits to make struct size multiple of 4 bytes */
579 	uint8_t padding_span_info[3];
580 } __packed;
581 
582 /* Compile time assert to check struct size is divisible by 4 Bytes */
583 SPECTRAL_COMPILE_TIME_ASSERT(struct_size_4byte_assertion,
584 			     (sizeof(struct samp_freq_span_info) % 4) == 0);
585 
586 /**
587  * struct spectral_samp_msg - Spectral SAMP message
588  * @signature: Validates the SAMP message
589  * @target_reset_count: Indicates the number of times target went through
590  * reset routine after spectral was enabled.
591  * @pri20_freq: Primary 20MHz operating frequency in MHz
592  * @cfreq1: Segment 1 centre frequency in MHz
593  * @cfreq2: For 80p80, indicates segment 2 centre frequency in MHz. For 160MHz,
594  * indicates the center frequency of 160MHz span.
595  * @sscan_cfreq1: Normal/Agile scan Center frequency for Segment 1
596  * based on Spectral Scan mode.
597  * @sscan_cfreq2: Normal/Agile scan Center frequency for Segment 2 in case of
598  * 80p80, and for 160MHz center frequency of the 160MHz span based on Spectral
599  * Scan mode.
600  * @bin_pwr_count: Indicates the number of FFT bins
601  * @freq_span_info: Spectral per-contiguous frequency span information
602  * @spectral_upper_rssi: Indicates RSSI of upper band
603  * @spectral_lower_rssi: Indicates RSSI of lower band
604  * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas
605  * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas
606  * @macaddr: Indicates the device interface
607  * @spectral_mode: Spectral scan mode
608  * @operating_bw: Device's operating bandwidth. Values = enum phy_ch_width
609  * @sscan_bw: Normal/Agile Scan BW based on Spectral scan mode.
610  * Values = enum phy_ch_width
611  * @fft_width: Indicates the number of bits representing an FFT bin
612  * @dcs_enabled: Whether DCS is enabled
613  * @int_type: Interference type indicated by DCS. Values = enum dcs_int_type
614  * @num_freq_spans: Number of contiguous frequency spans in operating bandwidth
615  * @bin_pwr: Contains FFT magnitudes
616  */
617 struct spectral_samp_msg {
618 	uint32_t signature;
619 	uint32_t target_reset_count;
620 	uint32_t pri20_freq;
621 	uint32_t cfreq1;
622 	uint32_t cfreq2;
623 	uint32_t sscan_cfreq1;
624 	uint32_t sscan_cfreq2;
625 	uint32_t bin_pwr_count;
626 	struct samp_freq_span_info freq_span_info[MAX_NUM_FREQ_SPANS];
627 	int8_t spectral_lower_rssi;
628 	int8_t spectral_upper_rssi;
629 	int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
630 	int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
631 	uint8_t macaddr[SPECTRAL_MAC_ADDR_SIZE];
632 	uint8_t spectral_mode;
633 	uint8_t operating_bw;
634 	uint8_t sscan_bw;
635 	uint8_t fft_width;
636 	uint8_t dcs_enabled;
637 	uint8_t int_type;
638 	uint8_t num_freq_spans;
639 	uint8_t bin_pwr[0];  /*This should be the last item in the structure*/
640 } __packed;
641 
642 #else
643 /**
644  * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format
645  * @spectral_data_len:        Indicates the bin size
646  * @spectral_data_len_sec80:  Indicates the bin size for secondary 80 segment
647  * @spectral_rssi:            Indicates RSSI
648  * @spectral_rssi_sec80:      Indicates RSSI for secondary 80 segment
649  * @spectral_combined_rssi:   Indicates combined RSSI from all antennas
650  * @spectral_upper_rssi:      Indicates RSSI of upper band
651  * @spectral_lower_rssi:      Indicates RSSI of lower band
652  * @spectral_chain_ctl_rssi:  RSSI for control channel, for all antennas
653  * @spectral_chain_ext_rssi:  RSSI for extension channel, for all antennas
654  * @spectral_max_scale:       Indicates scale factor
655  * @spectral_bwinfo:          Indicates bandwidth info
656  * @spectral_tstamp:          Indicates timestamp
657  * @spectral_max_index:       Indicates the index of max magnitude
658  * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary
659  *                            80 segment
660  * @spectral_max_mag:         Indicates the maximum magnitude
661  * @spectral_max_mag_sec80:   Indicates the maximum magnitude for secondary 80
662  *                            segment
663  * @spectral_max_exp:         Indicates the max exp
664  * @spectral_last_tstamp:     Indicates the last time stamp
665  * @spectral_upper_max_index: Indicates the index of max mag in upper band
666  * @spectral_lower_max_index: Indicates the index of max mag in lower band
667  * @spectral_nb_upper:        Not Used
668  * @spectral_nb_lower:        Not Used
669  * @classifier_params:        Indicates classifier parameters
670  * @bin_pwr_count:            Indicates the number of FFT bins
671  * @lb_edge_extrabins:        Number of extra bins on left band edge
672  * @rb_edge_extrabins:        Number of extra bins on right band edge
673  * @bin_pwr_count_sec80:      Indicates the number of FFT bins in secondary 80
674  *                            segment
675  * @bin_pwr:                  Contains FFT magnitudes
676  * @bin_pwr_sec80:            Contains FFT magnitudes for the secondary 80
677  *                            segment
678  * @interf_list:              List of interference sources
679  * @noise_floor:              Indicates the current noise floor
680  * @noise_floor_sec80:        Indicates the current noise floor for secondary 80
681  *                            segment
682  * @ch_width:                 Channel width 20/40/80/160 MHz
683  * @spectral_agc_total_gain:
684  * @spectral_agc_total_gain_sec80:
685  * @spectral_gainchange:
686  * @spectral_gainchange_sec80:
687  * @spectral_mode:            Spectral scan mode
688  * @spectral_pri80ind:        Indication from hardware that the sample was
689  *                            received on the primary 80 MHz segment. If this
690  *                            is set when smode = SPECTRAL_SCAN_MODE_AGILE, it
691  *                            indicates that Spectral was carried out on pri80
692  *                            instead of the Agile frequency due to a
693  *                            channel switch - Software may choose
694  *                            to ignore the sample in this case.
695  * @spectral_pri80ind_sec80:  Indication from hardware that the sample was
696  *                            received on the primary 80 MHz segment instead of
697  *                            the secondary 80 MHz segment due to a channel
698  *                            switch - Software may choose to ignore the sample
699  *                            if this is set. Applicable only if smode =
700  *                            SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
701  *                            Spectral operation.
702  * @last_raw_timestamp:       Previous FFT report's raw timestamp. In case of
703  *                            160Mhz it will be primary 80 segment's timestamp
704  *                            as both primary & secondary segment's timestamp
705  *                            are expected to be almost equal.
706  * @timestamp_war_offset:     Offset calculated based on reset_delay and
707  *                            last_raw_timestamp. It will be added to
708  *                            raw_timestamp to get spectral_tstamp.
709  * @raw_timestamp:            Actual FFT timestamp reported by HW on primary
710  *                            segment.
711  * @raw_timestamp_sec80:      Actual FFT timestamp reported by HW on sec80 MHz
712  *                            segment.
713  * @reset_delay:              Time gap between the last spectral report before
714  *                            reset and the end of reset. It is provided by FW
715  *                            via direct DMA framework.
716  * @target_reset_count:       Indicates the number of times target went through
717  *                            reset routine after spectral was enabled.
718  * @agile_ch_width:
719  * @bin_pwr_count_5mhz:       Indicates the number of FFT bins in the extra
720  *                            5 MHz for 165 MHz/ Restricted 80p80 mode
721  * @bin_pwr_5mhz:             Contains FFT magnitudes corresponding to the extra
722  *                            5 MHz in 165 MHz/ Restricted 80p80 mode
723  */
724 struct spectral_samp_data {
725 	int16_t spectral_data_len;
726 	int16_t spectral_data_len_sec80;
727 	int16_t spectral_rssi;
728 	int16_t spectral_rssi_sec80;
729 	int8_t spectral_combined_rssi;
730 	int8_t spectral_upper_rssi;
731 	int8_t spectral_lower_rssi;
732 	int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
733 	int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
734 	uint8_t spectral_max_scale;
735 	int16_t spectral_bwinfo;
736 	int32_t spectral_tstamp;
737 	int16_t spectral_max_index;
738 	int16_t spectral_max_index_sec80;
739 	int16_t spectral_max_mag;
740 	int16_t spectral_max_mag_sec80;
741 	uint8_t spectral_max_exp;
742 	int32_t spectral_last_tstamp;
743 	int16_t spectral_upper_max_index;
744 	int16_t spectral_lower_max_index;
745 	uint8_t spectral_nb_upper;
746 	uint8_t spectral_nb_lower;
747 	struct spectral_classifier_params classifier_params;
748 	uint16_t bin_pwr_count;
749 	/*
750 	 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
751 	 * delivered.  However, there can be additional bins reported for
752 	 * AR900B version 2.0 and QCA9984 as described next:
753 	 *
754 	 * AR900B version 2.0: An additional tone is processed on the right
755 	 * hand side in order to facilitate detection of radar pulses out to
756 	 * the extreme band-edge of the channel frequency.
757 	 * Since the HW design processes four tones at a time,
758 	 * this requires one additional Dword to be added to the
759 	 * search FFT report.
760 	 *
761 	 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
762 	 * 1x-oversampled bins (in-band) per FFT,
763 	 * then 8 more bins (4 more on left side and 4 more on right side)
764 	 * are added.
765 	 */
766 	uint8_t lb_edge_extrabins;
767 	uint8_t rb_edge_extrabins;
768 	uint16_t bin_pwr_count_sec80;
769 	uint8_t bin_pwr[MAX_NUM_BINS_PRI80];
770 	uint8_t bin_pwr_sec80[MAX_NUM_BINS_SEC80];
771 	struct interf_src_rsp interf_list;
772 	int16_t noise_floor;
773 	int16_t noise_floor_sec80;
774 	uint32_t ch_width;
775 	uint8_t spectral_agc_total_gain;
776 	uint8_t spectral_agc_total_gain_sec80;
777 	uint8_t spectral_gainchange;
778 	uint8_t spectral_gainchange_sec80;
779 	enum spectral_scan_mode spectral_mode;
780 	uint8_t spectral_pri80ind;
781 	uint8_t spectral_pri80ind_sec80;
782 	uint32_t last_raw_timestamp;
783 	uint32_t timestamp_war_offset;
784 	uint32_t raw_timestamp;
785 	uint32_t raw_timestamp_sec80;
786 	uint32_t reset_delay;
787 	uint32_t target_reset_count;
788 	uint32_t agile_ch_width;
789 	uint16_t bin_pwr_count_5mhz;
790 	uint8_t bin_pwr_5mhz[MAX_NUM_BINS_5MHZ];
791 } __packed;
792 
793 /**
794  * struct spectral_samp_msg - Spectral SAMP message
795  * @signature:          Validates the SAMP message
796  * @freq:               Operating frequency in MHz
797  * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz
798  * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz
799  * @agile_freq1:        Center frequency in MHz of the entire span(for 80+80 MHz
800  *                      agile Scan it is primary 80 MHz span) across which
801  *                      Agile Spectral is carried out. Applicable only for Agile
802  *                      Spectral samples.
803  * @agile_freq2:        Center frequency in MHz of the secondary 80 MHz span
804  *                      across which Agile Spectral is carried out. Applicable
805  *                      only for Agile Spectral samples in 80+80 MHz mode.
806  * @freq_loading:       How busy was the channel
807  * @dcs_enabled:        Whether DCS is enabled
808  * @int_type:           Interference type indicated by DCS
809  * @macaddr:            Indicates the device interface
810  * @samp_data:          SAMP Data
811  */
812 struct spectral_samp_msg {
813 	uint32_t signature;
814 	uint16_t freq;
815 	uint16_t vhtop_ch_freq_seg1;
816 	uint16_t vhtop_ch_freq_seg2;
817 	uint16_t agile_freq1;
818 	uint16_t agile_freq2;
819 	uint16_t freq_loading;
820 	uint16_t dcs_enabled;
821 	enum dcs_int_type int_type;
822 	uint8_t macaddr[6];
823 	struct spectral_samp_data samp_data;
824 } __packed;
825 
826 #endif /* OPTIMIZED_SAMP_MESSAGE */
827 #endif
828