xref: /wlan-driver/qca-wifi-host-cmn/spectral/dispatcher/inc/spectral_ioctl.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2011, 2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2024 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_samp_edge_extra_bin_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  * @blanking_status: Indicates whether scan blanking was enabled during this
537  * spectral report capture. This field is applicable only when scan blanking
538  * feature is enabled. When scan blanking feature is disabled, this field
539  * will be set to zero.
540  * @padding_detector_info: padding bytes
541  */
542 struct samp_detector_info {
543 	uint32_t start_frequency;
544 	uint32_t end_frequency;
545 	uint32_t timestamp;
546 	uint32_t last_tstamp;
547 	uint32_t last_raw_timestamp;
548 	uint32_t timestamp_war_offset;
549 	uint32_t raw_timestamp;
550 	uint32_t reset_delay;
551 	struct samp_edge_extra_bin_info left_edge_bins;
552 	struct samp_edge_extra_bin_info right_edge_bins;
553 	uint16_t start_bin_idx;
554 	uint16_t end_bin_idx;
555 	uint16_t max_index;
556 	uint16_t max_magnitude;
557 	int16_t noise_floor;
558 	int8_t rssi;
559 	uint8_t agc_total_gain;
560 	uint8_t gainchange;
561 	uint8_t pri80ind;
562 	uint8_t is_sec80;
563 	uint8_t blanking_status;
564 	/* Padding bits to make struct size multiple of 4 bytes */
565 	uint8_t padding_detector_info[];
566 } __packed;
567 
568 /* Compile time assert to check struct size is divisible by 4 Bytes */
569 SPECTRAL_COMPILE_TIME_ASSERT(struct_samp_detector_info_size_4byte_assertion,
570 			     (sizeof(struct samp_detector_info) % 4) == 0);
571 
572 /**
573  * struct samp_freq_span_info - SAMP per-frequency span information
574  * A frequency span here refers to a contiguous span of frequencies in which
575  * Spectral scan and interference detection is carried out.
576  * @detector_info: Per-detector Spectral information
577  * @num_detectors: Number of detectors per span
578  * @padding_span_info: padding bytes
579  */
580 struct samp_freq_span_info {
581 	struct samp_detector_info detector_info[MAX_NUM_DETECTORS];
582 	uint8_t num_detectors;
583 	/* Padding bits to make struct size multiple of 4 bytes */
584 	uint8_t padding_span_info[3];
585 } __packed;
586 
587 /* Compile time assert to check struct size is divisible by 4 Bytes */
588 SPECTRAL_COMPILE_TIME_ASSERT(struct_samp_freq_span_info_size_4byte_assertion,
589 			     (sizeof(struct samp_freq_span_info) % 4) == 0);
590 
591 /**
592  * struct spectral_samp_msg - Spectral SAMP message
593  * @signature: Validates the SAMP message
594  * @target_reset_count: Indicates the number of times target went through
595  * reset routine after spectral was enabled.
596  * @pri20_freq: Primary 20MHz operating frequency in MHz
597  * @cfreq1: Segment 1 centre frequency in MHz
598  * @cfreq2: For 80p80, indicates segment 2 centre frequency in MHz. For 160MHz,
599  * indicates the center frequency of 160MHz span.
600  * @sscan_cfreq1: Normal/Agile scan Center frequency for Segment 1
601  * based on Spectral Scan mode.
602  * @sscan_cfreq2: Normal/Agile scan Center frequency for Segment 2 in case of
603  * 80p80, and for 160MHz center frequency of the 160MHz span based on Spectral
604  * Scan mode.
605  * @bin_pwr_count: Indicates the number of FFT bins
606  * @freq_span_info: Spectral per-contiguous frequency span information
607  * @spectral_upper_rssi: Indicates RSSI of upper band
608  * @spectral_lower_rssi: Indicates RSSI of lower band
609  * @spectral_chain_ctl_rssi: RSSI for control channel, for all antennas
610  * @spectral_chain_ext_rssi: RSSI for extension channel, for all antennas
611  * @macaddr: Indicates the device interface
612  * @spectral_mode: Spectral scan mode
613  * @operating_bw: Device's operating bandwidth. Values = enum phy_ch_width
614  * @sscan_bw: Normal/Agile Scan BW based on Spectral scan mode.
615  * Values = enum phy_ch_width
616  * @fft_width: Indicates the number of bits representing an FFT bin
617  * @dcs_enabled: Whether DCS is enabled
618  * @int_type: Interference type indicated by DCS. Values = enum dcs_int_type
619  * @num_freq_spans: Number of contiguous frequency spans in operating bandwidth
620  * @bin_pwr: Contains FFT magnitudes
621  */
622 struct spectral_samp_msg {
623 	uint32_t signature;
624 	uint32_t target_reset_count;
625 	uint32_t pri20_freq;
626 	uint32_t cfreq1;
627 	uint32_t cfreq2;
628 	uint32_t sscan_cfreq1;
629 	uint32_t sscan_cfreq2;
630 	uint32_t bin_pwr_count;
631 	struct samp_freq_span_info freq_span_info[MAX_NUM_FREQ_SPANS];
632 	int8_t spectral_lower_rssi;
633 	int8_t spectral_upper_rssi;
634 	int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
635 	int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
636 	uint8_t macaddr[SPECTRAL_MAC_ADDR_SIZE];
637 	uint8_t spectral_mode;
638 	uint8_t operating_bw;
639 	uint8_t sscan_bw;
640 	uint8_t fft_width;
641 	uint8_t dcs_enabled;
642 	uint8_t int_type;
643 	uint8_t num_freq_spans;
644 	uint8_t bin_pwr[];  /*This should be the last item in the structure*/
645 } __packed;
646 
647 #else
648 /**
649  * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format
650  * @spectral_data_len:        Indicates the bin size
651  * @spectral_data_len_sec80:  Indicates the bin size for secondary 80 segment
652  * @spectral_rssi:            Indicates RSSI
653  * @spectral_rssi_sec80:      Indicates RSSI for secondary 80 segment
654  * @spectral_combined_rssi:   Indicates combined RSSI from all antennas
655  * @spectral_upper_rssi:      Indicates RSSI of upper band
656  * @spectral_lower_rssi:      Indicates RSSI of lower band
657  * @spectral_chain_ctl_rssi:  RSSI for control channel, for all antennas
658  * @spectral_chain_ext_rssi:  RSSI for extension channel, for all antennas
659  * @spectral_max_scale:       Indicates scale factor
660  * @spectral_bwinfo:          Indicates bandwidth info
661  * @spectral_tstamp:          Indicates timestamp
662  * @spectral_max_index:       Indicates the index of max magnitude
663  * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary
664  *                            80 segment
665  * @spectral_max_mag:         Indicates the maximum magnitude
666  * @spectral_max_mag_sec80:   Indicates the maximum magnitude for secondary 80
667  *                            segment
668  * @spectral_max_exp:         Indicates the max exp
669  * @spectral_last_tstamp:     Indicates the last time stamp
670  * @spectral_upper_max_index: Indicates the index of max mag in upper band
671  * @spectral_lower_max_index: Indicates the index of max mag in lower band
672  * @spectral_nb_upper:        Not Used
673  * @spectral_nb_lower:        Not Used
674  * @classifier_params:        Indicates classifier parameters
675  * @bin_pwr_count:            Indicates the number of FFT bins
676  * @lb_edge_extrabins:        Number of extra bins on left band edge
677  * @rb_edge_extrabins:        Number of extra bins on right band edge
678  * @bin_pwr_count_sec80:      Indicates the number of FFT bins in secondary 80
679  *                            segment
680  * @bin_pwr:                  Contains FFT magnitudes
681  * @bin_pwr_sec80:            Contains FFT magnitudes for the secondary 80
682  *                            segment
683  * @interf_list:              List of interference sources
684  * @noise_floor:              Indicates the current noise floor
685  * @noise_floor_sec80:        Indicates the current noise floor for secondary 80
686  *                            segment
687  * @ch_width:                 Channel width 20/40/80/160 MHz
688  * @spectral_agc_total_gain:
689  * @spectral_agc_total_gain_sec80:
690  * @spectral_gainchange:
691  * @spectral_gainchange_sec80:
692  * @spectral_mode:            Spectral scan mode
693  * @spectral_pri80ind:        Indication from hardware that the sample was
694  *                            received on the primary 80 MHz segment. If this
695  *                            is set when smode = SPECTRAL_SCAN_MODE_AGILE, it
696  *                            indicates that Spectral was carried out on pri80
697  *                            instead of the Agile frequency due to a
698  *                            channel switch - Software may choose
699  *                            to ignore the sample in this case.
700  * @spectral_pri80ind_sec80:  Indication from hardware that the sample was
701  *                            received on the primary 80 MHz segment instead of
702  *                            the secondary 80 MHz segment due to a channel
703  *                            switch - Software may choose to ignore the sample
704  *                            if this is set. Applicable only if smode =
705  *                            SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
706  *                            Spectral operation.
707  * @last_raw_timestamp:       Previous FFT report's raw timestamp. In case of
708  *                            160Mhz it will be primary 80 segment's timestamp
709  *                            as both primary & secondary segment's timestamp
710  *                            are expected to be almost equal.
711  * @timestamp_war_offset:     Offset calculated based on reset_delay and
712  *                            last_raw_timestamp. It will be added to
713  *                            raw_timestamp to get spectral_tstamp.
714  * @raw_timestamp:            Actual FFT timestamp reported by HW on primary
715  *                            segment.
716  * @raw_timestamp_sec80:      Actual FFT timestamp reported by HW on sec80 MHz
717  *                            segment.
718  * @reset_delay:              Time gap between the last spectral report before
719  *                            reset and the end of reset. It is provided by FW
720  *                            via direct DMA framework.
721  * @target_reset_count:       Indicates the number of times target went through
722  *                            reset routine after spectral was enabled.
723  * @agile_ch_width:
724  * @bin_pwr_count_5mhz:       Indicates the number of FFT bins in the extra
725  *                            5 MHz for 165 MHz/ Restricted 80p80 mode
726  * @bin_pwr_5mhz:             Contains FFT magnitudes corresponding to the extra
727  *                            5 MHz in 165 MHz/ Restricted 80p80 mode
728  */
729 struct spectral_samp_data {
730 	int16_t spectral_data_len;
731 	int16_t spectral_data_len_sec80;
732 	int16_t spectral_rssi;
733 	int16_t spectral_rssi_sec80;
734 	int8_t spectral_combined_rssi;
735 	int8_t spectral_upper_rssi;
736 	int8_t spectral_lower_rssi;
737 	int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
738 	int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
739 	uint8_t spectral_max_scale;
740 	int16_t spectral_bwinfo;
741 	int32_t spectral_tstamp;
742 	int16_t spectral_max_index;
743 	int16_t spectral_max_index_sec80;
744 	int16_t spectral_max_mag;
745 	int16_t spectral_max_mag_sec80;
746 	uint8_t spectral_max_exp;
747 	int32_t spectral_last_tstamp;
748 	int16_t spectral_upper_max_index;
749 	int16_t spectral_lower_max_index;
750 	uint8_t spectral_nb_upper;
751 	uint8_t spectral_nb_lower;
752 	struct spectral_classifier_params classifier_params;
753 	uint16_t bin_pwr_count;
754 	/*
755 	 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
756 	 * delivered.  However, there can be additional bins reported for
757 	 * AR900B version 2.0 and QCA9984 as described next:
758 	 *
759 	 * AR900B version 2.0: An additional tone is processed on the right
760 	 * hand side in order to facilitate detection of radar pulses out to
761 	 * the extreme band-edge of the channel frequency.
762 	 * Since the HW design processes four tones at a time,
763 	 * this requires one additional Dword to be added to the
764 	 * search FFT report.
765 	 *
766 	 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
767 	 * 1x-oversampled bins (in-band) per FFT,
768 	 * then 8 more bins (4 more on left side and 4 more on right side)
769 	 * are added.
770 	 */
771 	uint8_t lb_edge_extrabins;
772 	uint8_t rb_edge_extrabins;
773 	uint16_t bin_pwr_count_sec80;
774 	uint8_t bin_pwr[MAX_NUM_BINS_PRI80];
775 	uint8_t bin_pwr_sec80[MAX_NUM_BINS_SEC80];
776 	struct interf_src_rsp interf_list;
777 	int16_t noise_floor;
778 	int16_t noise_floor_sec80;
779 	uint32_t ch_width;
780 	uint8_t spectral_agc_total_gain;
781 	uint8_t spectral_agc_total_gain_sec80;
782 	uint8_t spectral_gainchange;
783 	uint8_t spectral_gainchange_sec80;
784 	enum spectral_scan_mode spectral_mode;
785 	uint8_t spectral_pri80ind;
786 	uint8_t spectral_pri80ind_sec80;
787 	uint32_t last_raw_timestamp;
788 	uint32_t timestamp_war_offset;
789 	uint32_t raw_timestamp;
790 	uint32_t raw_timestamp_sec80;
791 	uint32_t reset_delay;
792 	uint32_t target_reset_count;
793 	uint32_t agile_ch_width;
794 	uint16_t bin_pwr_count_5mhz;
795 	uint8_t bin_pwr_5mhz[MAX_NUM_BINS_5MHZ];
796 } __packed;
797 
798 /**
799  * struct spectral_samp_msg - Spectral SAMP message
800  * @signature:          Validates the SAMP message
801  * @freq:               Operating frequency in MHz
802  * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz
803  * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz
804  * @agile_freq1:        Center frequency in MHz of the entire span(for 80+80 MHz
805  *                      agile Scan it is primary 80 MHz span) across which
806  *                      Agile Spectral is carried out. Applicable only for Agile
807  *                      Spectral samples.
808  * @agile_freq2:        Center frequency in MHz of the secondary 80 MHz span
809  *                      across which Agile Spectral is carried out. Applicable
810  *                      only for Agile Spectral samples in 80+80 MHz mode.
811  * @freq_loading:       How busy was the channel
812  * @dcs_enabled:        Whether DCS is enabled
813  * @int_type:           Interference type indicated by DCS
814  * @macaddr:            Indicates the device interface
815  * @samp_data:          SAMP Data
816  */
817 struct spectral_samp_msg {
818 	uint32_t signature;
819 	uint16_t freq;
820 	uint16_t vhtop_ch_freq_seg1;
821 	uint16_t vhtop_ch_freq_seg2;
822 	uint16_t agile_freq1;
823 	uint16_t agile_freq2;
824 	uint16_t freq_loading;
825 	uint16_t dcs_enabled;
826 	enum dcs_int_type int_type;
827 	uint8_t macaddr[6];
828 	struct spectral_samp_data samp_data;
829 } __packed;
830 
831 #endif /* OPTIMIZED_SAMP_MESSAGE */
832 #endif
833