xref: /wlan-dirver/qca-wifi-host-cmn/spectral/dispatcher/inc/spectral_ioctl.h (revision dd4dc88b837a295134aa9869114a2efee0f4894b)
1 /*
2  * Copyright (c) 2011, 2017-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _SPECTRAL_IOCTL_H_
20 #define _SPECTRAL_IOCTL_H_
21 #include <wlan_dfs_ioctl.h>
22 
23 #ifndef AH_MAX_CHAINS
24 #define AH_MAX_CHAINS 3
25 #endif
26 
27 /*
28  * ioctl defines
29  */
30 
31 #define SPECTRAL_SET_CONFIG              (DFS_LAST_IOCTL + 1)
32 #define SPECTRAL_GET_CONFIG              (DFS_LAST_IOCTL + 2)
33 #define SPECTRAL_SHOW_INTERFERENCE       (DFS_LAST_IOCTL + 3)
34 #define SPECTRAL_ENABLE_SCAN             (DFS_LAST_IOCTL + 4)
35 #define SPECTRAL_DISABLE_SCAN            (DFS_LAST_IOCTL + 5)
36 #define SPECTRAL_ACTIVATE_SCAN           (DFS_LAST_IOCTL + 6)
37 #define SPECTRAL_STOP_SCAN               (DFS_LAST_IOCTL + 7)
38 #define SPECTRAL_SET_DEBUG_LEVEL         (DFS_LAST_IOCTL + 8)
39 #define SPECTRAL_IS_ACTIVE               (DFS_LAST_IOCTL + 9)
40 #define SPECTRAL_IS_ENABLED              (DFS_LAST_IOCTL + 10)
41 #define SPECTRAL_CLASSIFY_SCAN           (DFS_LAST_IOCTL + 11)
42 #define SPECTRAL_GET_CLASSIFIER_CONFIG   (DFS_LAST_IOCTL + 12)
43 #define SPECTRAL_EACS                    (DFS_LAST_IOCTL + 13)
44 #define SPECTRAL_ACTIVATE_FULL_SCAN      (DFS_LAST_IOCTL + 14)
45 #define SPECTRAL_STOP_FULL_SCAN          (DFS_LAST_IOCTL + 15)
46 #define SPECTRAL_GET_CAPABILITY_INFO     (DFS_LAST_IOCTL + 16)
47 #define SPECTRAL_GET_DIAG_STATS          (DFS_LAST_IOCTL + 17)
48 #define SPECTRAL_GET_CHAN_WIDTH          (DFS_LAST_IOCTL + 18)
49 #define SPECTRAL_GET_CHANINFO            (DFS_LAST_IOCTL + 19)
50 #define SPECTRAL_CLEAR_CHANINFO          (DFS_LAST_IOCTL + 20)
51 #define SPECTRAL_SET_ICM_ACTIVE          (DFS_LAST_IOCTL + 21)
52 #define SPECTRAL_GET_NOMINAL_NOISEFLOOR  (DFS_LAST_IOCTL + 22)
53 #define SPECTRAL_GET_DEBUG_LEVEL         (DFS_LAST_IOCTL + 23)
54 
55 /*
56  * ioctl parameter types
57  */
58 
59 #define SPECTRAL_PARAM_FFT_PERIOD        (1)
60 #define SPECTRAL_PARAM_SCAN_PERIOD       (2)
61 #define SPECTRAL_PARAM_SCAN_COUNT        (3)
62 #define SPECTRAL_PARAM_SHORT_REPORT      (4)
63 #define SPECTRAL_PARAM_SPECT_PRI         (5)
64 #define SPECTRAL_PARAM_FFT_SIZE          (6)
65 #define SPECTRAL_PARAM_GC_ENA            (7)
66 #define SPECTRAL_PARAM_RESTART_ENA       (8)
67 #define SPECTRAL_PARAM_NOISE_FLOOR_REF   (9)
68 #define SPECTRAL_PARAM_INIT_DELAY        (10)
69 #define SPECTRAL_PARAM_NB_TONE_THR       (11)
70 #define SPECTRAL_PARAM_STR_BIN_THR       (12)
71 #define SPECTRAL_PARAM_WB_RPT_MODE       (13)
72 #define SPECTRAL_PARAM_RSSI_RPT_MODE     (14)
73 #define SPECTRAL_PARAM_RSSI_THR          (15)
74 #define SPECTRAL_PARAM_PWR_FORMAT        (16)
75 #define SPECTRAL_PARAM_RPT_MODE          (17)
76 #define SPECTRAL_PARAM_BIN_SCALE         (18)
77 #define SPECTRAL_PARAM_DBM_ADJ           (19)
78 #define SPECTRAL_PARAM_CHN_MASK          (20)
79 #define SPECTRAL_PARAM_ACTIVE            (21)
80 #define SPECTRAL_PARAM_STOP              (22)
81 #define SPECTRAL_PARAM_ENABLE            (23)
82 
83 struct spectral_ioctl_params {
84 	int16_t   spectral_fft_period;
85 	int16_t   pectral_period;
86 	int16_t   spectral_count;
87 	uint16_t spectral_short_report;
88 	uint16_t spectral_pri;
89 };
90 
91 /**
92  * spectral_cap_hw_gen: Definitions for the Spectral hardware generation.
93  * This corresponds to definitions in qca_wlan_vendor_spectral_scan_cap_hw_gen.
94  * @SPECTRAL_CAP_HW_GEN_1: Generation 1
95  * @SPECTRAL_CAP_HW_GEN_2: Generation 2
96  * @SPECTRAL_CAP_HW_GEN_3: Generation 3
97  */
98 enum spectral_cap_hw_gen {
99 	SPECTRAL_CAP_HW_GEN_1 = 0,
100 	SPECTRAL_CAP_HW_GEN_2 = 1,
101 	SPECTRAL_CAP_HW_GEN_3 = 2,
102 };
103 
104 /**
105  * struct spectral_config - spectral config parameters
106  * @ss_fft_period:        Skip interval for FFT reports
107  * @ss_period:            Spectral scan period
108  * @ss_count:             # of reports to return from ss_active
109  * @ss_short_report:      Set to report only 1 set of FFT results
110  * @radar_bin_thresh_sel: Select threshold to classify strong bin for FFT
111  * @ss_spectral_pri:      Priority, and are we doing a noise power cal ?
112  * @ss_fft_size:          Defines the number of FFT data points to compute,
113  *                        defined as a log index num_fft_pts =
114  *                        2^ss_fft_size
115  * @ss_gc_ena:            Set, to enable targeted gain change before
116  *                        starting the spectral scan FFT
117  * @ss_restart_ena:       Set, to enable abort of receive frames when in high
118  *                        priority and a spectral scan is queued
119  * @ss_noise_floor_ref:   Noise floor reference number (signed) for the
120  *                        calculation of bin power (dBm) Though stored as an
121  *                        unsigned this should be treated as a signed 8-bit int.
122  * @ss_init_delay:        Disallow spectral scan triggers after tx/rx packets
123  *                        by setting this delay value to roughly SIFS time
124  *                        period or greater Delay timer count in units of 0.25us
125  * @ss_nb_tone_thr:       Number of strong bins (inclusive) per sub-channel,
126  *                        below which a signal is declared a narrowband tone
127  * @ss_str_bin_thr:       Bin/max_bin ratio threshold over which a bin is
128  *                        declared strong (for spectral scan bandwidth analysis)
129  * @ss_wb_rpt_mode:       Set this bit to report spectral scans as EXT_BLOCKER
130  *                        (phy_error=36), if none of the sub-channels are
131  *                        deemed narrowband
132  * @ss_rssi_rpt_mode:     Set this bit to report spectral scans as EXT_BLOCKER
133  *                        (phy_error=36), if the ADC RSSI is below the
134  *                        threshold ss_rssi_thr
135  * @ss_rssi_thr:          ADC RSSI must be greater than or equal to this
136  *                        threshold (signed Db) to ensure spectral scan
137  *                        reporting with normal phy error codes (please see
138  *                        ss_rssi_rpt_mode above).Though stored as an unsigned
139  *                        value, this should be treated as a signed 8-bit int
140  * @ss_pwr_format:        Format of frequency bin magnitude for spectral scan
141  *                        triggered FFTs 0: linear magnitude
142  *                        1: log magnitude (20*log10(lin_mag), 1/2 dB step size)
143  * @ss_rpt_mode:          Format of per-FFT reports to software for spectral
144  *                        scan triggered FFTs
145  *                        0: No FFT report (only pulse end summary)
146  *                        1: 2-dword summary of metrics for each completed FFT
147  *                        2: 2-dword summary + 1x-oversampled bins(in-band) per
148  *                           FFT
149  *                        3: 2-dword summary + 2x-oversampled bins (all) per FFT
150  * @ss_bin_scale:         Number of LSBs to shift out to scale the FFT bins
151  *                        for spectral scan triggered FFTs
152  * @ss_dbm_adj:           Set (with ss_pwr_format=1), to report bin
153  *                        magnitudes
154  *                        converted to dBm power using the noisefloor
155  *                        calibration results
156  * @ss_chn_mask:          Per chain enable mask to select input ADC for search
157  *                        FFT
158  * @ss_nf_cal:            nf calibrated values for ctl+ext
159  * @ss_nf_pwr:            nf pwr values for ctl+ext
160  * @ss_nf_temp_data:      temperature data taken during nf scan
161  */
162 struct spectral_config {
163 	uint16_t ss_fft_period;
164 	uint16_t ss_period;
165 	uint16_t ss_count;
166 	uint16_t ss_short_report;
167 	uint8_t radar_bin_thresh_sel;
168 	uint16_t ss_spectral_pri;
169 	uint16_t ss_fft_size;
170 	uint16_t ss_gc_ena;
171 	uint16_t ss_restart_ena;
172 	uint16_t ss_noise_floor_ref;
173 	uint16_t ss_init_delay;
174 	uint16_t ss_nb_tone_thr;
175 	uint16_t ss_str_bin_thr;
176 	uint16_t ss_wb_rpt_mode;
177 	uint16_t ss_rssi_rpt_mode;
178 	uint16_t ss_rssi_thr;
179 	uint16_t ss_pwr_format;
180 	uint16_t ss_rpt_mode;
181 	uint16_t ss_bin_scale;
182 	uint16_t ss_dbm_adj;
183 	uint16_t ss_chn_mask;
184 	int8_t ss_nf_cal[AH_MAX_CHAINS * 2];
185 	int8_t ss_nf_pwr[AH_MAX_CHAINS * 2];
186 	int32_t ss_nf_temp_data;
187 };
188 
189 /**
190  * struct spectral_caps - Spectral capabilities structure
191  * @phydiag_cap:         Phydiag capability
192  * @radar_cap:           Radar detection capability
193  * @spectral_cap:        Spectral capability
194  * @advncd_spectral_cap: Advanced spectral capability
195  * @hw_gen: Spectral hw generation as defined in spectral_cap_hw_gen
196  * @is_scaling_params_populated: indicates whether scaling params is populated
197  * @formula_id: formula_id
198  * @low_level_offset: low_level_offset
199  * @high_level_offset: high_level_offset
200  * @rssi_thr: rssi_thr
201  * @default_agc_max_gain: default_agc_max_gain
202  */
203 struct spectral_caps {
204 	uint8_t phydiag_cap;
205 	uint8_t radar_cap;
206 	uint8_t spectral_cap;
207 	uint8_t advncd_spectral_cap;
208 	uint32_t hw_gen;
209 	bool is_scaling_params_populated;
210 	uint16_t formula_id;
211 	int16_t low_level_offset;
212 	int16_t high_level_offset;
213 	int16_t rssi_thr;
214 	uint8_t default_agc_max_gain;
215 };
216 
217 #define SPECTRAL_IOCTL_PARAM_NOVAL (65535)
218 
219 #define MAX_SPECTRAL_CHAINS          3
220 #define MAX_NUM_BINS                 520
221 /* 5 categories x (lower + upper) bands */
222 #define MAX_INTERF                   10
223 
224 /**
225  * enum dcs_int_type - Interference type indicated by DCS
226  * @SPECTRAL_DCS_INT_NONE:  No interference
227  * @SPECTRAL_DCS_INT_CW:  CW interference
228  * @SPECTRAL_DCS_INT_WIFI:  WLAN interference
229  */
230 enum dcs_int_type {
231 	SPECTRAL_DCS_INT_NONE,
232 	SPECTRAL_DCS_INT_CW,
233 	SPECTRAL_DCS_INT_WIFI
234 };
235 
236 /**
237  * struct interf_rsp - Interference record
238  * @interf_type:         eINTERF_TYPE giving type of interference
239  * @interf_min_freq:     Minimum frequency in MHz at which interference has been
240  * found
241  * @interf_max_freq:     Maximum frequency in MHz at which interference has been
242  * found
243  * @advncd_spectral_cap: Advanced spectral capability
244  */
245 struct interf_rsp {
246 	uint8_t interf_type;
247 	uint16_t interf_min_freq;
248 	uint16_t interf_max_freq;
249 } __packed;
250 
251 /**
252  * struct interf_src_rsp - List of interference sources
253  * @count: Number of interference records
254  * @interf: Array of interference records
255  */
256 struct interf_src_rsp {
257 	uint16_t count;
258 	struct interf_rsp interf[MAX_INTERF];
259 } __packed;
260 
261 /**
262  * struct spectral_classifier_params - spectral classifier parameters
263  * @spectral_20_40_mode:  Is AP in 20/40 mode?
264  * @spectral_dc_index:    DC index
265  * @spectral_dc_in_mhz:   DC in MHz
266  * @upper_chan_in_mhz:    Upper channel in MHz
267  * @lower_chan_in_mhz:    Lower channel in MHz
268  */
269 struct spectral_classifier_params {
270 	int spectral_20_40_mode;
271 	int spectral_dc_index;
272 	int spectral_dc_in_mhz;
273 	int upper_chan_in_mhz;
274 	int lower_chan_in_mhz;
275 } __packed;
276 
277 /**
278  * struct spectral_samp_data - Spectral Analysis Messaging Protocol Data format
279  * @spectral_data_len:        Indicates the bin size
280  * @spectral_data_len_sec80:  Indicates the bin size for secondary 80 segment
281  * @spectral_rssi:            Indicates RSSI
282  * @spectral_rssi_sec80:      Indicates RSSI for secondary 80 segment
283  * @spectral_combined_rssi:   Indicates combined RSSI from all antennas
284  * @spectral_upper_rssi:      Indicates RSSI of upper band
285  * @spectral_lower_rssi:      Indicates RSSI of lower band
286  * @spectral_chain_ctl_rssi:  RSSI for control channel, for all antennas
287  * @spectral_chain_ext_rssi:  RSSI for extension channel, for all antennas
288  * @spectral_max_scale:       Indicates scale factor
289  * @spectral_bwinfo:          Indicates bandwidth info
290  * @spectral_tstamp:          Indicates timestamp
291  * @spectral_max_index:       Indicates the index of max magnitude
292  * @spectral_max_index_sec80: Indicates the index of max magnitude for secondary
293  *                            80 segment
294  * @spectral_max_mag:         Indicates the maximum magnitude
295  * @spectral_max_mag_sec80:   Indicates the maximum magnitude for secondary 80
296  *                            segment
297  * @spectral_max_exp:         Indicates the max exp
298  * @spectral_last_tstamp:     Indicates the last time stamp
299  * @spectral_upper_max_index: Indicates the index of max mag in upper band
300  * @spectral_lower_max_index: Indicates the index of max mag in lower band
301  * @spectral_nb_upper:        Not Used
302  * @spectral_nb_lower:        Not Used
303  * @classifier_params:        Indicates classifier parameters
304  * @bin_pwr_count:            Indicates the number of FFT bins
305  * @lb_edge_extrabins:        Number of extra bins on left band edge
306  * @rb_edge_extrabins:        Number of extra bins on right band edge
307  * @bin_pwr_count_sec80:      Indicates the number of FFT bins in secondary 80
308  *                            segment
309  * @bin_pwr:                  Contains FFT magnitudes
310  * @bin_pwr_sec80:            Contains FFT magnitudes for the secondary 80
311  *                            segment
312  * @interf_list:              List of interfernce sources
313  * @noise_floor:              Indicates the current noise floor
314  * @noise_floor_sec80:        Indicates the current noise floor for secondary 80
315  *                            segment
316  * @ch_width:                 Channel width 20/40/80/160 MHz
317  */
318 struct spectral_samp_data {
319 	int16_t spectral_data_len;
320 	int16_t spectral_data_len_sec80;
321 	int16_t spectral_rssi;
322 	int16_t spectral_rssi_sec80;
323 	int8_t spectral_combined_rssi;
324 	int8_t spectral_upper_rssi;
325 	int8_t spectral_lower_rssi;
326 	int8_t spectral_chain_ctl_rssi[MAX_SPECTRAL_CHAINS];
327 	int8_t spectral_chain_ext_rssi[MAX_SPECTRAL_CHAINS];
328 	uint8_t spectral_max_scale;
329 	int16_t spectral_bwinfo;
330 	int32_t spectral_tstamp;
331 	int16_t spectral_max_index;
332 	int16_t spectral_max_index_sec80;
333 	int16_t spectral_max_mag;
334 	int16_t spectral_max_mag_sec80;
335 	uint8_t spectral_max_exp;
336 	int32_t spectral_last_tstamp;
337 	int16_t spectral_upper_max_index;
338 	int16_t spectral_lower_max_index;
339 	uint8_t spectral_nb_upper;
340 	uint8_t spectral_nb_lower;
341 	struct spectral_classifier_params classifier_params;
342 	uint16_t bin_pwr_count;
343 	/*
344 	 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
345 	 * delivered.  However, there can be additional bins reported for
346 	 * AR900B version 2.0 and QCA9984 as described next:
347 	 *
348 	 * AR900B version 2.0: An additional tone is processed on the right
349 	 * hand side in order to facilitate detection of radar pulses out to
350 	 * the extreme band-edge of the channel frequency.
351 	 * Since the HW design processes four tones at a time,
352 	 * this requires one additional Dword to be added to the
353 	 * search FFT report.
354 	 *
355 	 * QCA9984: When spectral_scan_rpt_mode=2, i.e 2-dword summary +
356 	 * 1x-oversampled bins (in-band) per FFT,
357 	 * then 8 more bins (4 more on left side and 4 more on right side)
358 	 * are added.
359 	 */
360 	uint8_t lb_edge_extrabins;
361 	uint8_t rb_edge_extrabins;
362 	uint16_t bin_pwr_count_sec80;
363 	uint8_t bin_pwr[MAX_NUM_BINS];
364 	uint8_t bin_pwr_sec80[MAX_NUM_BINS];
365 	struct interf_src_rsp interf_list;
366 	int16_t noise_floor;
367 	int16_t noise_floor_sec80;
368 	uint32_t ch_width;
369 	uint8_t spectral_agc_total_gain;
370 	uint8_t spectral_agc_total_gain_sec80;
371 	uint8_t spectral_gainchange;
372 	uint8_t spectral_gainchange_sec80;
373 } __packed;
374 
375 /**
376  * struct spectral_samp_msg - Spectral SAMP message
377  * @signature:          Validates the SAMP message
378  * @freq:               Operating frequency in MHz
379  * @vhtop_ch_freq_seg1: VHT Segment 1 centre frequency in MHz
380  * @vhtop_ch_freq_seg2: VHT Segment 2 centre frequency in MHz
381  * @freq_loading:       How busy was the channel
382  * @dcs_enabled:        Whether DCS is enabled
383  * @int_type:           Interference type indicated by DCS
384  * @macaddr:            Indicates the device interface
385  * @samp_data:          SAMP Data
386  */
387 struct spectral_samp_msg {
388 	uint32_t signature;
389 	uint16_t freq;
390 	uint16_t vhtop_ch_freq_seg1;
391 	uint16_t vhtop_ch_freq_seg2;
392 	uint16_t freq_loading;
393 	uint16_t dcs_enabled;
394 	enum dcs_int_type int_type;
395 	uint8_t macaddr[6];
396 	struct spectral_samp_data samp_data;
397 } __packed;
398 
399 #endif
400