xref: /wlan-dirver/qca-wifi-host-cmn/target_if/spectral/target_if_spectral.h (revision 97f44cd39e4ff816eaa1710279d28cf6b9e65ad9)
1 /*
2  * Copyright (c) 2011,2017-2020 The Linux Foundation. All rights reserved.
3  *
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _TARGET_IF_SPECTRAL_H_
21 #define _TARGET_IF_SPECTRAL_H_
22 
23 #include <wlan_objmgr_cmn.h>
24 #include <wlan_objmgr_psoc_obj.h>
25 #include <wlan_objmgr_pdev_obj.h>
26 #include <wlan_objmgr_vdev_obj.h>
27 #include <qdf_lock.h>
28 #include <wlan_spectral_public_structs.h>
29 #include <reg_services_public_struct.h>
30 #ifdef DIRECT_BUF_RX_ENABLE
31 #include <target_if_direct_buf_rx_api.h>
32 #endif
33 #ifdef WIN32
34 #pragma pack(push, target_if_spectral, 1)
35 #define __ATTRIB_PACK
36 #else
37 #ifndef __ATTRIB_PACK
38 #define __ATTRIB_PACK __attribute__ ((packed))
39 #endif
40 #endif
41 
42 #include <spectral_defs_i.h>
43 #include <wmi_unified_param.h>
44 
45 #define FREQ_OFFSET_10MHZ (10)
46 #define FREQ_OFFSET_40MHZ (40)
47 #define FREQ_OFFSET_80MHZ (80)
48 #ifndef SPECTRAL_USE_NL_BCAST
49 #define SPECTRAL_USE_NL_BCAST  (0)
50 #endif
51 
52 #define STATUS_PASS       1
53 #define STATUS_FAIL       0
54 #undef spectral_dbg_line
55 #define spectral_dbg_line() \
56 	spectral_debug("----------------------------------------------------")
57 
58 #undef spectral_ops_not_registered
59 #define spectral_ops_not_registered(str) \
60 	spectral_info("SPECTRAL : %s not registered\n", (str))
61 #undef not_yet_implemented
62 #define not_yet_implemented() \
63 	spectral_info("SPECTRAL : %s : %d Not yet implemented\n", \
64 		      __func__, __LINE__)
65 
66 #define SPECTRAL_HT20_NUM_BINS               56
67 #define SPECTRAL_HT20_FFT_LEN                56
68 #define SPECTRAL_HT20_DC_INDEX               (SPECTRAL_HT20_FFT_LEN / 2)
69 #define SPECTRAL_HT20_DATA_LEN               60
70 #define SPECTRAL_HT20_TOTAL_DATA_LEN         (SPECTRAL_HT20_DATA_LEN + 3)
71 #define SPECTRAL_HT40_TOTAL_NUM_BINS         128
72 #define SPECTRAL_HT40_DATA_LEN               135
73 #define SPECTRAL_HT40_TOTAL_DATA_LEN         (SPECTRAL_HT40_DATA_LEN + 3)
74 #define SPECTRAL_HT40_FFT_LEN                128
75 #define SPECTRAL_HT40_DC_INDEX               (SPECTRAL_HT40_FFT_LEN / 2)
76 
77 /*
78  * Used for the SWAR to obtain approximate combined rssi
79  * in secondary 80Mhz segment
80  */
81 #define OFFSET_CH_WIDTH_20	65
82 #define OFFSET_CH_WIDTH_40	62
83 #define OFFSET_CH_WIDTH_80	56
84 #define OFFSET_CH_WIDTH_160	50
85 
86 /* Min and max for relevant Spectral params */
87 #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN2          (1)
88 #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN2          (9)
89 #define SPECTRAL_PARAM_FFT_SIZE_MIN_GEN3          (5)
90 #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_DEFAULT  (9)
91 #define SPECTRAL_PARAM_FFT_SIZE_MAX_GEN3_QCN9000  (10)
92 #define SPECTRAL_PARAM_RPT_MODE_MIN               (0)
93 #define SPECTRAL_PARAM_RPT_MODE_MAX               (3)
94 #define MAX_FFTBIN_VALUE                          (255)
95 
96 /* DBR ring debug size for Spectral */
97 #define SPECTRAL_DBR_RING_DEBUG_SIZE 512
98 
99 #ifdef BIG_ENDIAN_HOST
100 #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len)  do { \
101 	int j; \
102 	uint32_t *src, *dest; \
103 	src = (uint32_t *)(srcp); \
104 	dest = (uint32_t *)(destp); \
105 	for (j = 0; j < roundup((len), sizeof(uint32_t)) / 4; j++) { \
106 	*(dest + j) = qdf_le32_to_cpu(*(src + j)); \
107 	} \
108 	} while (0)
109 #else
110 #define SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(destp, srcp, len) \
111 	OS_MEMCPY((destp), (srcp), (len));
112 #endif
113 
114 #define DUMMY_NF_VALUE          (-123)
115 /* 5 categories x (lower + upper) bands */
116 #define MAX_INTERF                   10
117 #define HOST_MAX_ANTENNA         3
118 /* Mask for time stamp from descriptor */
119 #define SPECTRAL_TSMASK              0xFFFFFFFF
120 #define SPECTRAL_SIGNATURE           0xdeadbeef
121 /* Signature to write onto spectral buffer and then later validate */
122 #define MEM_POISON_SIGNATURE (htobe32(0xdeadbeef))
123 
124 /* START of spectral GEN II HW specific details */
125 #define SPECTRAL_PHYERR_SIGNATURE_GEN2           0xbb
126 #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN2     0xF9
127 #define TLV_TAG_ADC_REPORT_GEN2                  0xFA
128 #define TLV_TAG_SEARCH_FFT_REPORT_GEN2           0xFB
129 
130 /**
131  * enum spectral_160mhz_report_delivery_state - 160 MHz state machine states
132  * @SPECTRAL_REPORT_WAIT_PRIMARY80:   Wait for primary80 report
133  * @SPECTRAL_REPORT_RX_PRIMARY80:     Receive primary 80 report
134  * @SPECTRAL_REPORT_WAIT_SECONDARY80: Wait for secondory 80 report
135  * @SPECTRAL_REPORT_RX_SECONDARY80:   Receive secondary 80 report
136  */
137 enum spectral_160mhz_report_delivery_state {
138 	SPECTRAL_REPORT_WAIT_PRIMARY80,
139 	SPECTRAL_REPORT_RX_PRIMARY80,
140 	SPECTRAL_REPORT_WAIT_SECONDARY80,
141 	SPECTRAL_REPORT_RX_SECONDARY80,
142 };
143 
144 /**
145  * enum spectral_detector_id - Spectral detector id
146  * @SPECTRAL_DETECTOR_ID_0: Spectral detector 0
147  * @SPECTRAL_DETECTOR_ID_1: Spectral detector 1
148  * @SPECTRAL_DETECTOR_ID_2: Spectral detector 2
149  * @SPECTRAL_DETECTOR_ID_MAX: Max Spectral detector ID
150  * @SPECTRAL_DETECTOR_ID_INVALID: Invalid Spectral detector ID
151  */
152 enum spectral_detector_id {
153 	SPECTRAL_DETECTOR_ID_0,
154 	SPECTRAL_DETECTOR_ID_1,
155 	SPECTRAL_DETECTOR_ID_2,
156 	SPECTRAL_DETECTOR_ID_MAX,
157 	SPECTRAL_DETECTOR_ID_INVALID = 0xff,
158 };
159 
160 /**
161  * struct spectral_search_fft_info_gen2 - spectral search fft report for gen2
162  * @relpwr_db:       Total bin power in db
163  * @num_str_bins_ib: Number of strong bins
164  * @base_pwr:        Base power
165  * @total_gain_info: Total gain
166  * @fft_chn_idx:     FFT chain on which report is originated
167  * @avgpwr_db:       Average power in db
168  * @peak_mag:        Peak power seen in the bins
169  * @peak_inx:        Index of bin holding peak power
170  */
171 struct spectral_search_fft_info_gen2 {
172 	uint32_t relpwr_db;
173 	uint32_t num_str_bins_ib;
174 	uint32_t base_pwr;
175 	uint32_t total_gain_info;
176 	uint32_t fft_chn_idx;
177 	uint32_t avgpwr_db;
178 	uint32_t peak_mag;
179 	int16_t  peak_inx;
180 };
181 
182 /*
183  * XXX Check if we should be handling the endinness difference in some
184  * other way opaque to the host
185  */
186 #ifdef BIG_ENDIAN_HOST
187 
188 /**
189  * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for big endian host
190  * @signature: signature
191  * @tag:       tag
192  * @length:    length
193  */
194 struct spectral_phyerr_tlv_gen2 {
195 	uint8_t  signature;
196 	uint8_t  tag;
197 	uint16_t length;
198 } __ATTRIB_PACK;
199 
200 #else
201 
202 /**
203  * struct spectral_phyerr_tlv_gen2 - phyerr tlv info for little endian host
204  * @length:    length
205  * @tag:       tag
206  * @signature: signature
207  */
208 struct spectral_phyerr_tlv_gen2 {
209 	uint16_t length;
210 	uint8_t  tag;
211 	uint8_t  signature;
212 } __ATTRIB_PACK;
213 
214 #endif /* BIG_ENDIAN_HOST */
215 
216 /**
217  * struct spectral_phyerr_hdr_gen2 - phyerr header for gen2 HW
218  * @hdr_a: Header[0:31]
219  * @hdr_b: Header[32:63]
220  */
221 struct spectral_phyerr_hdr_gen2 {
222 	uint32_t hdr_a;
223 	uint32_t hdr_b;
224 };
225 
226 /*
227  * Segment ID information for 80+80.
228  *
229  * If the HW micro-architecture specification extends this DWORD for other
230  * purposes, then redefine+rename accordingly. For now, the specification
231  * mentions only segment ID (though this doesn't require an entire DWORD)
232  * without mention of any generic terminology for the DWORD, or any reservation.
233  * We use nomenclature accordingly.
234  */
235 typedef uint32_t SPECTRAL_SEGID_INFO;
236 
237 /**
238  * struct spectral_phyerr_fft_gen2 - fft info in phyerr event
239  * @buf: fft report
240  */
241 struct spectral_phyerr_fft_gen2 {
242 	uint8_t buf[0];
243 };
244 /* END of spectral GEN II HW specific details */
245 
246 /* START of spectral GEN III HW specific details */
247 
248 #define get_bitfield(value, size, pos) \
249 	(((value) >> (pos)) & ((1 << (size)) - 1))
250 #define unsigned_to_signed(value, width) \
251 	(((value) >= (1 << ((width) - 1))) ? \
252 		(value - (1 << (width))) : (value))
253 
254 #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_POS_GEN3         (29)
255 #define SSCAN_SUMMARY_REPORT_HDR_A_DETECTOR_ID_SIZE_GEN3        (2)
256 #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_POS_GEN3      (0)
257 #define SSCAN_SUMMARY_REPORT_HDR_A_AGC_TOTAL_GAIN_SIZE_GEN3     (8)
258 #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_POS_GEN3       (18)
259 #define SSCAN_SUMMARY_REPORT_HDR_A_INBAND_PWR_DB_SIZE_GEN3      (10)
260 #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_POS_GEN3               (31)
261 #define SSCAN_SUMMARY_REPORT_HDR_A_PRI80_SIZE_GEN3              (1)
262 #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_POS_GEN3_V1       (30)
263 #define SSCAN_SUMMARY_REPORT_HDR_B_GAINCHANGE_SIZE_GEN3_V1      (1)
264 #define SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_POS_GEN3_V2       (16)
265 #define SSCAN_SUMMARY_REPORT_HDR_C_GAINCHANGE_SIZE_GEN3_V2      (1)
266 
267 #define SPECTRAL_PHYERR_SIGNATURE_GEN3                          (0xFA)
268 #define TLV_TAG_SPECTRAL_SUMMARY_REPORT_GEN3                    (0x02)
269 #define TLV_TAG_SEARCH_FFT_REPORT_GEN3                          (0x03)
270 #define SPECTRAL_PHYERR_TLVSIZE_GEN3                            (4)
271 
272 #define NUM_SPECTRAL_DETECTORS_GEN3_V1                     (3)
273 #define NUM_SPECTRAL_DETECTORS_GEN3_V2                     (2)
274 #define FFT_REPORT_HEADER_LENGTH_GEN3_V2                   (24)
275 #define FFT_REPORT_HEADER_LENGTH_GEN3_V1                   (16)
276 #define NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V1      (0)
277 #define NUM_PADDING_BYTES_SSCAN_SUMARY_REPORT_GEN3_V2      (16)
278 
279 #define PHYERR_HDR_SIG_POS    \
280 	(offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_sig))
281 #define PHYERR_HDR_TAG_POS    \
282 	(offsetof(struct spectral_phyerr_fft_report_gen3, fft_hdr_tag))
283 #define SPECTRAL_FFT_BINS_POS \
284 	(offsetof(struct spectral_phyerr_fft_report_gen3, buf))
285 
286 /**
287  * struct phyerr_info - spectral search fft report for gen3
288  * @data:       handle to phyerror buffer
289  * @datalen:    length of phyerror bufer
290  * @p_rfqual:   rf quality matrices
291  * @p_chaninfo: pointer to chaninfo
292  * @tsf64:      64 bit TSF
293  * @acs_stats:  acs stats
294  */
295 struct phyerr_info {
296 	uint8_t *data;
297 	uint32_t datalen;
298 	struct target_if_spectral_rfqual_info *p_rfqual;
299 	struct target_if_spectral_chan_info *p_chaninfo;
300 	uint64_t tsf64;
301 	struct target_if_spectral_acs_stats *acs_stats;
302 };
303 
304 /**
305  * struct spectral_search_fft_info_gen3 - spectral search fft report for gen3
306  * @timestamp:           Timestamp at which fft report was generated
307  * @fft_detector_id:     Which radio generated this report
308  * @fft_num:             The FFT count number. Set to 0 for short FFT.
309  * @fft_radar_check:     NA for spectral
310  * @fft_peak_sidx:       Index of bin with maximum power
311  * @fft_chn_idx:         Rx chain index
312  * @fft_base_pwr_db:     Base power in dB
313  * @fft_total_gain_db:   Total gain in dB
314  * @fft_num_str_bins_ib: Number of strong bins in the report
315  * @fft_peak_mag:        Peak magnitude
316  * @fft_avgpwr_db:       Average power in dB
317  * @fft_relpwr_db:       Relative power in dB
318  */
319 struct spectral_search_fft_info_gen3 {
320 	uint32_t timestamp;
321 	uint32_t fft_detector_id;
322 	uint32_t fft_num;
323 	uint32_t fft_radar_check;
324 	int32_t  fft_peak_sidx;
325 	uint32_t fft_chn_idx;
326 	uint32_t fft_base_pwr_db;
327 	uint32_t fft_total_gain_db;
328 	uint32_t fft_num_str_bins_ib;
329 	int32_t  fft_peak_mag;
330 	uint32_t fft_avgpwr_db;
331 	uint32_t fft_relpwr_db;
332 };
333 
334 /**
335  * struct spectral_phyerr_sfftreport_gen3 - fft info in phyerr event
336  * @fft_timestamp:  Timestamp at which fft report was generated
337  * @fft_hdr_sig:    signature
338  * @fft_hdr_tag:    tag
339  * @fft_hdr_length: length
340  * @hdr_a:          Header[0:31]
341  * @hdr_b:          Header[32:63]
342  * @hdr_c:          Header[64:95]
343  * @resv:           Header[96:127]
344  * @buf:            fft bins
345  */
346 struct spectral_phyerr_fft_report_gen3 {
347 	uint32_t fft_timestamp;
348 #ifdef BIG_ENDIAN_HOST
349 	uint8_t  fft_hdr_sig;
350 	uint8_t  fft_hdr_tag;
351 	uint16_t fft_hdr_length;
352 #else
353 	uint16_t fft_hdr_length;
354 	uint8_t  fft_hdr_tag;
355 	uint8_t  fft_hdr_sig;
356 #endif /* BIG_ENDIAN_HOST */
357 	uint32_t hdr_a;
358 	uint32_t hdr_b;
359 	uint32_t hdr_c;
360 	uint32_t resv;
361 	uint8_t buf[0];
362 } __ATTRIB_PACK;
363 
364 /**
365  * struct sscan_report_fields_gen3 - Fields of spectral report
366  * @sscan_agc_total_gain:  The AGC total gain in DB.
367  * @inband_pwr_db: The in-band power of the signal in 1/2 DB steps
368  * @sscan_gainchange: This bit is set to 1 if a gainchange occurred during
369  *                 the spectral scan FFT.  Software may choose to
370  *                 disregard the results.
371  * @sscan_pri80: This is set to 1 to indicate that the Spectral scan was
372  *                 performed on the pri80 segment. Software may choose to
373  *                 disregard the FFT sample if this is set to 1 but detector ID
374  *                 does not correspond to the ID for the pri80 segment.
375  */
376 struct sscan_report_fields_gen3 {
377 	uint8_t sscan_agc_total_gain;
378 	int16_t inband_pwr_db;
379 	uint8_t sscan_gainchange;
380 	uint8_t sscan_pri80;
381 };
382 
383 /**
384  * struct spectral_sscan_summary_report_gen3 - Spectral summary report
385  * event
386  * @sscan_timestamp:  Timestamp at which fft report was generated
387  * @sscan_hdr_sig:    signature
388  * @sscan_hdr_tag:    tag
389  * @sscan_hdr_length: length
390  * @hdr_a:          Header[0:31]
391  * @resv:           Header[32:63]
392  * @hdr_b:          Header[64:95]
393  * @hdr_c:          Header[96:127]
394  */
395 struct spectral_sscan_summary_report_gen3 {
396 	u_int32_t sscan_timestamp;
397 #ifdef BIG_ENDIAN_HOST
398 	u_int8_t  sscan_hdr_sig;
399 	u_int8_t  sscan_hdr_tag;
400 	u_int16_t sscan_hdr_length;
401 #else
402 	u_int16_t sscan_hdr_length;
403 	u_int8_t  sscan_hdr_tag;
404 	u_int8_t  sscan_hdr_sig;
405 #endif /* BIG_ENDIAN_HOST */
406 	u_int32_t hdr_a;
407 	u_int32_t res1;
408 	u_int32_t hdr_b;
409 	u_int32_t hdr_c;
410 } __ATTRIB_PACK;
411 
412 #ifdef DIRECT_BUF_RX_ENABLE
413 /**
414  * struct Spectral_report - spectral report
415  * @data: Report buffer
416  * @noisefloor: Noise floor values
417  * @reset_delay: Time taken for warm reset in us
418  * @cfreq1: center frequency 1
419  * @cfreq2: center frequency 2
420  * @ch_width: channel width
421  */
422 struct spectral_report {
423 	uint8_t *data;
424 	int32_t noisefloor[DBR_MAX_CHAINS];
425 	uint32_t reset_delay;
426 	uint32_t cfreq1;
427 	uint32_t cfreq2;
428 	uint32_t ch_width;
429 };
430 #endif
431 /* END of spectral GEN III HW specific details */
432 
433 typedef signed char pwr_dbm;
434 
435 /**
436  * enum spectral_gen - spectral hw generation
437  * @SPECTRAL_GEN1 : spectral hw gen 1
438  * @SPECTRAL_GEN2 : spectral hw gen 2
439  * @SPECTRAL_GEN3 : spectral hw gen 3
440  */
441 enum spectral_gen {
442 	SPECTRAL_GEN1,
443 	SPECTRAL_GEN2,
444 	SPECTRAL_GEN3,
445 };
446 
447 /**
448  * enum spectral_fftbin_size_war - spectral fft bin size war
449  * @SPECTRAL_FFTBIN_SIZE_NO_WAR : No WAR applicable for Spectral FFT bin size
450  * @SPECTRAL_FFTBIN_SIZE_2BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
451  *                                        least significant byte from 2 byte
452  *                                        FFT bin transferred by HW
453  * @SPECTRAL_FFTBIN_SIZE_4BYTE_TO_1BYTE : Spectral FFT bin size: Retain only
454  *                                        least significant byte from 4 byte
455  *                                        FFT bin transferred by HW
456  */
457 enum spectral_fftbin_size_war {
458 	SPECTRAL_FFTBIN_SIZE_NO_WAR = 0,
459 	SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE = 1,
460 	SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE = 2,
461 };
462 
463 /**
464  * enum spectral_report_format_version - This represents the report format
465  * version number within each Spectral generation.
466  * @SPECTRAL_REPORT_FORMAT_VERSION_1 : version 1
467  * @SPECTRAL_REPORT_FORMAT_VERSION_2 : version 2
468  */
469 enum spectral_report_format_version {
470 	SPECTRAL_REPORT_FORMAT_VERSION_1,
471 	SPECTRAL_REPORT_FORMAT_VERSION_2,
472 };
473 
474 /**
475  * struct spectral_fft_bin_len_adj_swar - Encapsulate information required for
476  * Spectral FFT bin length adjusting software WARS.
477  * @inband_fftbin_size_adj: Whether to carry out FFT bin size adjustment for
478  * in-band report format. This would be required on some chipsets under the
479  * following circumstances: In report mode 2 only the in-band bins are DMA'ed.
480  * Scatter/gather is used. However, the HW generates all bins, not just in-band,
481  * and reports the number of bins accordingly. The subsystem arranging for the
482  * DMA cannot change this value. On such chipsets the adjustment required at the
483  * host driver is to check if report format is 2, and if so halve the number of
484  * bins reported to get the number actually DMA'ed.
485  * @null_fftbin_adj: Whether to remove NULL FFT bins for report mode (1) in
486  * which only summary of metrics for each completed FFT + spectral scan summary
487  * report are to be provided. This would be required on some chipsets under the
488  * following circumstances: In report mode 1, HW reports a length corresponding
489  * to all bins, and provides bins with value 0. This is because the subsystem
490  * arranging for the FFT information does not arrange for DMA of FFT bin values
491  * (as expected), but cannot arrange for a smaller length to be reported by HW.
492  * In these circumstances, the driver would have to disregard the NULL bins and
493  * report a bin count of 0 to higher layers.
494  * @packmode_fftbin_size_adj: Pack mode in HW refers to packing of each Spectral
495  * FFT bin into 2 bytes. But due to a bug HW reports 2 times the expected length
496  * when packmode is enabled. This SWAR compensates this bug by dividing the
497  * length with 2.
498  * @fftbin_size_war: Type of FFT bin size SWAR
499  */
500 struct spectral_fft_bin_len_adj_swar {
501 	u_int8_t inband_fftbin_size_adj;
502 	u_int8_t null_fftbin_adj;
503 	uint8_t packmode_fftbin_size_adj;
504 	enum spectral_fftbin_size_war fftbin_size_war;
505 };
506 
507 /**
508  * struct spectral_report_params - Parameters related to format of Spectral
509  * report.
510  * @version: This represents the report format version number within each
511  * Spectral generation.
512  * @ssumaary_padding_bytes: Number of bytes of padding after Spectral summary
513  * report
514  * @fft_report_hdr_len: Number of bytes in the header of the FFT report. This
515  * has to be subtracted from the length field of FFT report to find the length
516  * of FFT bins.
517  * @fragmentation_160: This indicates whether Spectral reports in 160/80p80 is
518  * fragmented.
519  * @max_agile_ch_width: Maximum agile BW supported by the target
520  * @detid_mode_table: Detector ID to Spectral scan mode table
521  * @num_spectral_detectors: Total number of Spectral detectors
522  * @marker: Describes the boundaries of pri80, 5 MHz and sec80 bins
523  */
524 struct spectral_report_params {
525 	enum spectral_report_format_version version;
526 	uint8_t ssumaary_padding_bytes;
527 	uint8_t fft_report_hdr_len;
528 	bool fragmentation_160[SPECTRAL_SCAN_MODE_MAX];
529 	enum phy_ch_width max_agile_ch_width;
530 	enum spectral_scan_mode detid_mode_table[SPECTRAL_DETECTOR_ID_MAX];
531 	uint8_t num_spectral_detectors;
532 	struct spectral_fft_bin_markers_160_165mhz
533 				marker[SPECTRAL_SCAN_MODE_MAX];
534 };
535 
536 /**
537  * struct spectral_param_min_max - Spectral parameter minimum and maximum values
538  * @fft_size_min: Minimum value of fft_size
539  * @fft_size_max: Maximum value of fft_size for each BW
540  */
541 struct spectral_param_min_max {
542 	uint16_t fft_size_min;
543 	uint16_t fft_size_max[CH_WIDTH_MAX];
544 };
545 
546 /**
547  * struct spectral_timestamp_swar - Spectral time stamp WAR related parameters
548  * @timestamp_war_offset: Offset to be added to correct timestamp
549  * @target_reset_count: Number of times target exercised the reset routine
550  * @last_fft_timestamp: last fft report timestamp
551  */
552 struct spectral_timestamp_war {
553 	uint32_t timestamp_war_offset[SPECTRAL_SCAN_MODE_MAX];
554 	uint64_t target_reset_count;
555 	uint32_t last_fft_timestamp[SPECTRAL_SCAN_MODE_MAX];
556 };
557 
558 #if ATH_PERF_PWR_OFFLOAD
559 /**
560  * enum target_if_spectral_info - Enumerations for specifying which spectral
561  *                              information (among parameters and states)
562  *                              is desired.
563  * @TARGET_IF_SPECTRAL_INFO_ACTIVE:  Indicated whether spectral is active
564  * @TARGET_IF_SPECTRAL_INFO_ENABLED: Indicated whether spectral is enabled
565  * @TARGET_IF_SPECTRAL_INFO_PARAMS:  Config params
566  */
567 enum target_if_spectral_info {
568 	TARGET_IF_SPECTRAL_INFO_ACTIVE,
569 	TARGET_IF_SPECTRAL_INFO_ENABLED,
570 	TARGET_IF_SPECTRAL_INFO_PARAMS,
571 };
572 #endif /* ATH_PERF_PWR_OFFLOAD */
573 
574 /* forward declaration */
575 struct target_if_spectral;
576 
577 /**
578  * struct target_if_spectral_chan_info - Channel information
579  * @center_freq1: center frequency 1 in MHz
580  * @center_freq2: center frequency 2 in MHz -valid only for
581  *		 11ACVHT 80PLUS80 mode
582  * @chan_width:   channel width in MHz
583  */
584 struct target_if_spectral_chan_info {
585 	uint16_t    center_freq1;
586 	uint16_t    center_freq2;
587 	uint8_t     chan_width;
588 };
589 
590 /**
591  * struct target_if_spectral_acs_stats - EACS stats from spectral samples
592  * @nfc_ctl_rssi: Control chan rssi
593  * @nfc_ext_rssi: Extension chan rssi
594  * @ctrl_nf:      Control chan Noise Floor
595  * @ext_nf:       Extension chan Noise Floor
596  */
597 struct target_if_spectral_acs_stats {
598 	int8_t nfc_ctl_rssi;
599 	int8_t nfc_ext_rssi;
600 	int8_t ctrl_nf;
601 	int8_t ext_nf;
602 };
603 
604 /**
605  * struct target_if_spectral_perchain_rssi_info - per chain rssi info
606  * @rssi_pri20: Rssi of primary 20 Mhz
607  * @rssi_sec20: Rssi of secondary 20 Mhz
608  * @rssi_sec40: Rssi of secondary 40 Mhz
609  * @rssi_sec80: Rssi of secondary 80 Mhz
610  */
611 struct target_if_spectral_perchain_rssi_info {
612 	int8_t    rssi_pri20;
613 	int8_t    rssi_sec20;
614 	int8_t    rssi_sec40;
615 	int8_t    rssi_sec80;
616 };
617 
618 /**
619  * struct target_if_spectral_rfqual_info - RF measurement information
620  * @rssi_comb:    RSSI Information
621  * @pc_rssi_info: XXX : For now, we know we are getting information
622  *                for only 4 chains at max. For future extensions
623  *                use a define
624  * @noise_floor:  Noise floor information
625  */
626 struct target_if_spectral_rfqual_info {
627 	int8_t    rssi_comb;
628 	struct    target_if_spectral_perchain_rssi_info pc_rssi_info[4];
629 	int16_t   noise_floor[4];
630 };
631 
632 #define GET_TARGET_IF_SPECTRAL_OPS(spectral) \
633 	((struct target_if_spectral_ops *)(&((spectral)->spectral_ops)))
634 
635 /**
636  * struct target_if_spectral_ops - spectral low level ops table
637  * @get_tsf64:               Get 64 bit TSF value
638  * @get_capability:          Get capability info
639  * @set_rxfilter:            Set rx filter
640  * @get_rxfilter:            Get rx filter
641  * @is_spectral_active:      Check whether icm is active
642  * @is_spectral_enabled:     Check whether spectral is enabled
643  * @start_spectral_scan:     Start spectral scan
644  * @stop_spectral_scan:      Stop spectral scan
645  * @get_extension_channel:   Get extension channel
646  * @get_ctl_noisefloor:      Get control noise floor
647  * @get_ext_noisefloor:      Get extension noise floor
648  * @configure_spectral:      Set spectral configurations
649  * @get_spectral_config:     Get spectral configurations
650  * @get_ent_spectral_mask:   Get spectral mask
651  * @get_mac_address:         Get mac address
652  * @get_current_channel:     Get current channel
653  * @reset_hw:                Reset HW
654  * @get_chain_noise_floor:   Get Channel noise floor
655  * @spectral_process_phyerr: Process phyerr event
656  * @process_spectral_report: Process spectral report
657  */
658 struct target_if_spectral_ops {
659 	uint64_t (*get_tsf64)(void *arg);
660 	uint32_t (*get_capability)(
661 		void *arg, enum spectral_capability_type type);
662 	uint32_t (*set_rxfilter)(void *arg, int rxfilter);
663 	uint32_t (*get_rxfilter)(void *arg);
664 	uint32_t (*is_spectral_active)(void *arg,
665 				       enum spectral_scan_mode smode);
666 	uint32_t (*is_spectral_enabled)(void *arg,
667 					enum spectral_scan_mode smode);
668 	uint32_t (*start_spectral_scan)(void *arg,
669 					enum spectral_scan_mode smode,
670 					enum spectral_cp_error_code *err);
671 	uint32_t (*stop_spectral_scan)(void *arg,
672 				       enum spectral_scan_mode smode);
673 	uint32_t (*get_extension_channel)(void *arg,
674 					  enum spectral_scan_mode smode);
675 	int8_t    (*get_ctl_noisefloor)(void *arg);
676 	int8_t    (*get_ext_noisefloor)(void *arg);
677 	uint32_t (*configure_spectral)(
678 			void *arg,
679 			struct spectral_config *params,
680 			enum spectral_scan_mode smode);
681 	uint32_t (*get_spectral_config)(
682 			void *arg,
683 			struct spectral_config *params,
684 			enum spectral_scan_mode smode);
685 	uint32_t (*get_ent_spectral_mask)(void *arg);
686 	uint32_t (*get_mac_address)(void *arg, char *addr);
687 	uint32_t (*get_current_channel)(void *arg,
688 					enum spectral_scan_mode smode);
689 	uint32_t (*reset_hw)(void *arg);
690 	uint32_t (*get_chain_noise_floor)(void *arg, int16_t *nf_buf);
691 	int (*spectral_process_phyerr)(struct target_if_spectral *spectral,
692 				       uint8_t *data, uint32_t datalen,
693 			struct target_if_spectral_rfqual_info *p_rfqual,
694 			struct target_if_spectral_chan_info *p_chaninfo,
695 			uint64_t tsf64,
696 			struct target_if_spectral_acs_stats *acs_stats);
697 	int (*process_spectral_report)(struct wlan_objmgr_pdev *pdev,
698 				       void *payload);
699 };
700 
701 /**
702  * struct target_if_spectral_stats - spectral stats info
703  * @num_spectral_detects: Total num. of spectral detects
704  * @total_phy_errors:     Total number of phyerrors
705  * @owl_phy_errors:       Indicated phyerrors in old gen1 chipsets
706  * @pri_phy_errors:       Phyerrors in primary channel
707  * @ext_phy_errors:       Phyerrors in secondary channel
708  * @dc_phy_errors:        Phyerrors due to dc
709  * @early_ext_phy_errors: Early secondary channel phyerrors
710  * @bwinfo_errors:        Bandwidth info errors
711  * @datalen_discards:     Invalid data length errors, seen in gen1 chipsets
712  * @rssi_discards bw:     Indicates reports dropped due to RSSI threshold
713  * @last_reset_tstamp:    Last reset time stamp
714  */
715 struct target_if_spectral_stats {
716 	uint32_t    num_spectral_detects;
717 	uint32_t    total_phy_errors;
718 	uint32_t    owl_phy_errors;
719 	uint32_t    pri_phy_errors;
720 	uint32_t    ext_phy_errors;
721 	uint32_t    dc_phy_errors;
722 	uint32_t    early_ext_phy_errors;
723 	uint32_t    bwinfo_errors;
724 	uint32_t    datalen_discards;
725 	uint32_t    rssi_discards;
726 	uint64_t    last_reset_tstamp;
727 };
728 
729 /**
730  * struct target_if_spectral_event - spectral event structure
731  * @se_ts:        Original 15 bit recv timestamp
732  * @se_full_ts:   64-bit full timestamp from interrupt time
733  * @se_rssi:      Rssi of spectral event
734  * @se_bwinfo:    Rssi of spectral event
735  * @se_dur:       Duration of spectral pulse
736  * @se_chanindex: Channel of event
737  * @se_list:      List of spectral events
738  */
739 struct target_if_spectral_event {
740 	uint32_t                       se_ts;
741 	uint64_t                       se_full_ts;
742 	uint8_t                        se_rssi;
743 	uint8_t                        se_bwinfo;
744 	uint8_t                        se_dur;
745 	uint8_t                        se_chanindex;
746 
747 	STAILQ_ENTRY(spectral_event)    se_list;
748 };
749 
750 /**
751  * struct target_if_chain_noise_pwr_info - Noise power info for each channel
752  * @rptcount:        Count of reports in pwr array
753  * @un_cal_nf:       Uncalibrated noise floor
754  * @factory_cal_nf:  Noise floor as calibrated at the factory for module
755  * @median_pwr:      Median power (median of pwr array)
756  * @pwr:             Power reports
757  */
758 struct target_if_chain_noise_pwr_info {
759 	int        rptcount;
760 	pwr_dbm    un_cal_nf;
761 	pwr_dbm    factory_cal_nf;
762 	pwr_dbm    median_pwr;
763 	pwr_dbm    pwr[];
764 } __ATTRIB_PACK;
765 
766 /**
767  * struct target_if_spectral_chan_stats - Channel information
768  * @cycle_count:         Cycle count
769  * @channel_load:        Channel load
770  * @per:                 Period
771  * @noisefloor:          Noise floor
772  * @comp_usablity:       Computed usability
773  * @maxregpower:         Maximum allowed regulatary power
774  * @comp_usablity_sec80: Computed usability of secondary 80 Mhz
775  * @maxregpower_sec80:   Max regulatory power in secondary 80 Mhz
776  */
777 struct target_if_spectral_chan_stats {
778 	int          cycle_count;
779 	int          channel_load;
780 	int          per;
781 	int          noisefloor;
782 	uint16_t    comp_usablity;
783 	int8_t       maxregpower;
784 	uint16_t    comp_usablity_sec80;
785 	int8_t       maxregpower_sec80;
786 };
787 
788 #if ATH_PERF_PWR_OFFLOAD
789 
790 /**
791  * struct target_if_spectral_cache - Cache used to minimize WMI operations
792  *                             in offload architecture
793  * @osc_spectral_enabled: Whether Spectral is enabled
794  * @osc_spectral_active:  Whether spectral is active
795  *                        XXX: Ideally, we should NOT cache this
796  *                        since the hardware can self clear the bit,
797  *                        the firmware can possibly stop spectral due to
798  *                        intermittent off-channel activity, etc
799  *                        A WMI read command should be introduced to handle
800  *                        this This will be discussed.
801  * @osc_params:           Spectral parameters
802  * @osc_is_valid:         Whether the cache is valid
803  */
804 struct target_if_spectral_cache {
805 	uint8_t                  osc_spectral_enabled;
806 	uint8_t                  osc_spectral_active;
807 	struct spectral_config    osc_params;
808 	uint8_t                  osc_is_valid;
809 };
810 
811 /**
812  * struct target_if_spectral_param_state_info - Structure used to represent and
813  *                                        manage spectral information
814  *                                        (parameters and states)
815  * @osps_lock:  Lock to synchronize accesses to information
816  * @osps_cache: Cacheable' information
817  */
818 struct target_if_spectral_param_state_info {
819 	qdf_spinlock_t               osps_lock;
820 	struct target_if_spectral_cache    osps_cache;
821 	/* XXX - Non-cacheable information goes here, in the future */
822 };
823 #endif /* ATH_PERF_PWR_OFFLOAD */
824 
825 struct vdev_spectral_configure_params;
826 struct vdev_spectral_enable_params;
827 
828 /**
829  * struct spectral_wmi_ops - structure used holding the operations
830  * related to Spectral WMI
831  * @wmi_spectral_configure_cmd_send: Configure Spectral parameters
832  * @wmi_spectral_enable_cmd_send: Enable/Disable Spectral
833  * @wmi_spectral_crash_inject: Inject FW crash
834  * @wmi_extract_pdev_sscan_fw_cmd_fixed_param: Extract Fixed params from
835  * start scan response event
836  * @wmi_extract_pdev_sscan_fft_bin_index: Extract TLV which describes FFT
837  * bin indices from start scan response event
838  * @wmi_unified_register_event_handler: Register WMI event handler
839  * @wmi_unified_unregister_event_handler: Unregister WMI event handler
840  */
841 struct spectral_wmi_ops {
842 	QDF_STATUS (*wmi_spectral_configure_cmd_send)(
843 		    wmi_unified_t wmi_hdl,
844 		    struct vdev_spectral_configure_params *param);
845 	QDF_STATUS (*wmi_spectral_enable_cmd_send)(
846 		    wmi_unified_t wmi_hdl,
847 		    struct vdev_spectral_enable_params *param);
848 	QDF_STATUS (*wmi_spectral_crash_inject)(
849 		wmi_unified_t wmi_handle, struct crash_inject *param);
850 	QDF_STATUS (*wmi_extract_pdev_sscan_fw_cmd_fixed_param)(
851 				wmi_unified_t wmi_handle, uint8_t *evt_buf,
852 				struct spectral_startscan_resp_params *param);
853 	QDF_STATUS (*wmi_extract_pdev_sscan_fft_bin_index)(
854 			wmi_unified_t wmi_handle, uint8_t *evt_buf,
855 			struct spectral_fft_bin_markers_160_165mhz *param);
856 	QDF_STATUS (*wmi_unified_register_event_handler)(
857 				wmi_unified_t wmi_handle,
858 				wmi_conv_event_id event_id,
859 				wmi_unified_event_handler handler_func,
860 				uint8_t rx_ctx);
861 	QDF_STATUS (*wmi_unified_unregister_event_handler)(
862 				wmi_unified_t wmi_handle,
863 				wmi_conv_event_id event_id);
864 };
865 
866 /**
867  * struct spectral_tgt_ops - structure used holding the operations
868  * related to target operations
869  * @tgt_get_psoc_from_scn_hdl: Function to get psoc from scn
870  */
871 struct spectral_tgt_ops {
872 	struct wlan_objmgr_psoc *(*tgt_get_psoc_from_scn_hdl)(void *scn_handle);
873 };
874 
875 /**
876  * struct spectral_param_properties - structure holding Spectral
877  *                                    parameter properties
878  * @supported: Parameter is supported or not
879  * @common_all_modes: Parameter should be common for all modes or not
880  */
881 struct spectral_param_properties {
882 	bool supported;
883 	bool common_all_modes;
884 };
885 
886 /**
887  * struct target_if_finite_spectral_scan_params - Parameters related to finite
888  * Spectral scan
889  * @finite_spectral_scan: Indicates the Spectrl scan is finite/infinite
890  * @num_reports_expected: Number of Spectral reports expected from target for a
891  * finite Spectral scan
892  */
893 struct target_if_finite_spectral_scan_params {
894 	bool finite_spectral_scan;
895 	uint32_t num_reports_expected;
896 };
897 
898 /**
899  * struct target_if_spectral - main spectral structure
900  * @pdev: Pointer to pdev
901  * @spectral_ops: Target if internal Spectral low level operations table
902  * @capability: Spectral capabilities structure
903  * @properties: Spectral parameter properties per mode
904  * @spectral_lock: Lock used for internal Spectral operations
905  * @vdev_id: VDEV id for all spectral modes
906  * @spectral_curchan_radindex: Current channel spectral index
907  * @spectral_extchan_radindex: Extension channel spectral index
908  * @spectraldomain: Current Spectral domain
909  * @spectral_proc_phyerr:  Flags to process for PHY errors
910  * @spectral_defaultparams: Default PHY params per Spectral stat
911  * @spectral_stats:  Spectral related stats
912  * @events:   Events structure
913  * @sc_spectral_ext_chan_ok:  Can spectral be detected on the extension channel?
914  * @sc_spectral_combined_rssi_ok:  Can use combined spectral RSSI?
915  * @sc_spectral_20_40_mode:  Is AP in 20-40 mode?
916  * @sc_spectral_noise_pwr_cal:  Noise power cal required?
917  * @sc_spectral_non_edma:  Is the spectral capable device Non-EDMA?
918  * @upper_is_control: Upper segment is primary
919  * @upper_is_extension: Upper segment is secondary
920  * @lower_is_control: Lower segment is primary
921  * @lower_is_extension: Lower segment is secondary
922  * @sc_spectraltest_ieeechan:  IEEE channel number to return to after a spectral
923  * mute test
924  * @spectral_numbins: Number of bins
925  * @spectral_fft_len: FFT length
926  * @spectral_data_len: Total phyerror report length
927  * @lb_edge_extrabins: Number of extra bins on left band edge
928  * @rb_edge_extrabins: Number of extra bins on right band edge
929  * @spectral_max_index_offset: Max FFT index offset (20 MHz mode)
930  * @spectral_upper_max_index_offset: Upper max FFT index offset (20/40 MHz mode)
931  * @spectral_lower_max_index_offset: Lower max FFT index offset (20/40 MHz mode)
932  * @spectral_dc_index: At which index DC is present
933  * @send_single_packet: Deprecated
934  * @spectral_sent_msg: Indicates whether we send report to upper layers
935  * @params: Spectral parameters
936  * @last_capture_time: Indicates timestamp of previouse report
937  * @num_spectral_data: Number of Spectral samples received in current session
938  * @total_spectral_data: Total number of Spectral samples received
939  * @max_rssi: Maximum RSSI
940  * @detects_control_channel: NA
941  * @detects_extension_channel: NA
942  * @detects_below_dc: NA
943  * @detects_above_dc: NA
944  * @sc_scanning: Indicates active wifi scan
945  * @sc_spectral_scan: Indicates active specral scan
946  * @sc_spectral_full_scan: Deprecated
947  * @scan_start_tstamp: Deprecated
948  * @last_tstamp: Deprecated
949  * @first_tstamp: Deprecated
950  * @spectral_samp_count: Deprecated
951  * @sc_spectral_samp_count: Deprecated
952  * @noise_pwr_reports_reqd: Number of noise power reports required
953  * @noise_pwr_reports_recv: Number of noise power reports received
954  * @noise_pwr_reports_lock: Lock used for Noise power report processing
955  * @noise_pwr_chain_ctl: Noise power report - control channel
956  * @noise_pwr_chain_ext: Noise power report - extension channel
957  * @chaninfo: Channel statistics
958  * @tsf64: Latest TSF Value
959  * @param_info: Offload architecture Spectral parameter cache information
960  * @ch_width: Indicates Channel Width 20/40/80/160 MHz for each Spectral mode
961  * @diag_stats: Diagnostic statistics
962  * @is_160_format:  Indicates whether information provided by HW is in altered
963  * format for 802.11ac 160/80+80 MHz support (QCA9984 onwards)
964  * @is_lb_edge_extrabins_format:  Indicates whether information provided by
965  * HW has 4 extra bins, at left band edge, for report mode 2
966  * @is_rb_edge_extrabins_format:   Indicates whether information provided
967  * by HW has 4 extra bins, at right band edge, for report mode 2
968  * @is_sec80_rssi_war_required: Indicates whether the software workaround is
969  * required to obtain approximate combined RSSI for secondary 80Mhz segment
970  * @simctx: Spectral Simulation context
971  * @spectral_gen: Spectral hardware generation
972  * @hdr_sig_exp: Expected signature in PHYERR TLV header, for the given hardware
973  * generation
974  * @tag_sscan_summary_exp: Expected Spectral Scan Summary tag in PHYERR TLV
975  * header, for the given hardware generation
976  * @tag_sscan_fft_exp: Expected Spectral Scan FFT report tag in PHYERR TLV
977  * header, for the given hardware generation
978  * @tlvhdr_size: Expected PHYERR TLV header size, for the given hardware
979  * generation
980  * @nl_cb: Netlink callbacks
981  * @use_nl_bcast: Whether to use Netlink broadcast/unicast
982  * @send_phy_data: Send data to the application layer for a particular msg type
983  * @len_adj_swar: Spectral fft bin length adjustment SWAR related info
984  * @timestamp_war: Spectral time stamp WAR related info
985  * @dbr_ring_debug: Whether Spectral DBR ring debug is enabled
986  * @dbr_buff_debug: Whether Spectral DBR buffer debug is enabled
987  * @direct_dma_support: Whether Direct-DMA is supported on the current radio
988  * @prev_tstamp: Timestamp of the previously received sample, which has to be
989  * compared with the current tstamp to check descrepancy
990  * @rparams: Parameters related to Spectral report structure
991  * @param_min_max: Spectral parameter's minimum and maximum values
992  * @finite_scan: Parameters for finite Spectral scan
993  */
994 struct target_if_spectral {
995 	struct wlan_objmgr_pdev *pdev_obj;
996 	struct target_if_spectral_ops                 spectral_ops;
997 	struct spectral_caps                    capability;
998 	struct spectral_param_properties
999 			properties[SPECTRAL_SCAN_MODE_MAX][SPECTRAL_PARAM_MAX];
1000 	qdf_spinlock_t                          spectral_lock;
1001 	uint8_t                                 vdev_id[SPECTRAL_SCAN_MODE_MAX];
1002 	int16_t                                 spectral_curchan_radindex;
1003 	int16_t                                 spectral_extchan_radindex;
1004 	uint32_t                               spectraldomain;
1005 	uint32_t                               spectral_proc_phyerr;
1006 	struct spectral_config                  spectral_defaultparams;
1007 	struct target_if_spectral_stats         spectral_stats;
1008 	struct target_if_spectral_event *events;
1009 	unsigned int                            sc_spectral_ext_chan_ok:1,
1010 						sc_spectral_combined_rssi_ok:1,
1011 						sc_spectral_20_40_mode:1,
1012 						sc_spectral_noise_pwr_cal:1,
1013 						sc_spectral_non_edma:1;
1014 	int                                     upper_is_control;
1015 	int                                     upper_is_extension;
1016 	int                                     lower_is_control;
1017 	int                                     lower_is_extension;
1018 	uint8_t                                sc_spectraltest_ieeechan;
1019 	int                                     spectral_numbins;
1020 	int                                     spectral_fft_len;
1021 	int                                     spectral_data_len;
1022 
1023 	/*
1024 	 * For 11ac chipsets prior to AR900B version 2.0, a max of 512 bins are
1025 	 * delivered.  However, there can be additional bins reported for
1026 	 * AR900B version 2.0 and QCA9984 as described next:
1027 	 *
1028 	 * AR900B version 2.0: An additional tone is processed on the right
1029 	 * hand side in order to facilitate detection of radar pulses out to
1030 	 * the extreme band-edge of the channel frequency. Since the HW design
1031 	 * processes four tones at a time, this requires one additional Dword
1032 	 * to be added to the search FFT report.
1033 	 *
1034 	 * QCA9984: When spectral_scan_rpt_mode = 2, i.e 2-dword summary +
1035 	 * 1x-oversampled bins (in-band) per FFT, then 8 more bins
1036 	 * (4 more on left side and 4 more on right side)are added.
1037 	 */
1038 
1039 	int                                     lb_edge_extrabins;
1040 	int                                     rb_edge_extrabins;
1041 	int                                     spectral_max_index_offset;
1042 	int                                     spectral_upper_max_index_offset;
1043 	int                                     spectral_lower_max_index_offset;
1044 	int                                     spectral_dc_index;
1045 	int                                     send_single_packet;
1046 	int                                     spectral_sent_msg;
1047 	int                                     classify_scan;
1048 	qdf_timer_t                             classify_timer;
1049 	struct spectral_config params[SPECTRAL_SCAN_MODE_MAX];
1050 	bool params_valid[SPECTRAL_SCAN_MODE_MAX];
1051 	struct spectral_classifier_params       classifier_params;
1052 	int                                     last_capture_time;
1053 	int                                     num_spectral_data;
1054 	int                                     total_spectral_data;
1055 	int                                     max_rssi;
1056 	int                                     detects_control_channel;
1057 	int                                     detects_extension_channel;
1058 	int                                     detects_below_dc;
1059 	int                                     detects_above_dc;
1060 	int                                     sc_scanning;
1061 	int                                     sc_spectral_scan;
1062 	int                                     sc_spectral_full_scan;
1063 	uint64_t                               scan_start_tstamp;
1064 	uint32_t                               last_tstamp;
1065 	uint32_t                               first_tstamp;
1066 	uint32_t                               spectral_samp_count;
1067 	uint32_t                               sc_spectral_samp_count;
1068 	int                                     noise_pwr_reports_reqd;
1069 	int                                     noise_pwr_reports_recv;
1070 	qdf_spinlock_t                          noise_pwr_reports_lock;
1071 	struct target_if_chain_noise_pwr_info
1072 		*noise_pwr_chain_ctl[HOST_MAX_ANTENNA];
1073 	struct target_if_chain_noise_pwr_info
1074 		*noise_pwr_chain_ext[HOST_MAX_ANTENNA];
1075 	uint64_t                               tsf64;
1076 #if ATH_PERF_PWR_OFFLOAD
1077 	struct target_if_spectral_param_state_info
1078 					param_info[SPECTRAL_SCAN_MODE_MAX];
1079 #endif
1080 	enum phy_ch_width ch_width[SPECTRAL_SCAN_MODE_MAX];
1081 	struct spectral_diag_stats              diag_stats;
1082 	bool                                    is_160_format;
1083 	bool                                    is_lb_edge_extrabins_format;
1084 	bool                                    is_rb_edge_extrabins_format;
1085 	bool                                    is_sec80_rssi_war_required;
1086 #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
1087 	void                                    *simctx;
1088 #endif
1089 	enum spectral_gen                       spectral_gen;
1090 	uint8_t                                hdr_sig_exp;
1091 	uint8_t                                tag_sscan_summary_exp;
1092 	uint8_t                                tag_sscan_fft_exp;
1093 	uint8_t                                tlvhdr_size;
1094 	struct spectral_nl_cb nl_cb;
1095 	bool use_nl_bcast;
1096 	int (*send_phy_data)(struct wlan_objmgr_pdev *pdev,
1097 			     enum spectral_msg_type smsg_type);
1098 	struct spectral_fft_bin_len_adj_swar len_adj_swar;
1099 	struct spectral_timestamp_war timestamp_war;
1100 	enum spectral_160mhz_report_delivery_state
1101 			state_160mhz_delivery[SPECTRAL_SCAN_MODE_MAX];
1102 	bool dbr_ring_debug;
1103 	bool dbr_buff_debug;
1104 	bool direct_dma_support;
1105 	uint32_t prev_tstamp;
1106 	struct spectral_report_params rparams;
1107 	struct spectral_param_min_max param_min_max;
1108 	struct target_if_finite_spectral_scan_params
1109 					finite_scan[SPECTRAL_SCAN_MODE_MAX];
1110 };
1111 
1112 /**
1113  * struct target_if_psoc_spectral - Target if psoc Spectral object
1114  * @psoc_obj:  psoc object
1115  * @wmi_ops:  Spectral WMI operations
1116  */
1117 struct target_if_psoc_spectral {
1118 	struct wlan_objmgr_psoc *psoc_obj;
1119 	struct spectral_wmi_ops wmi_ops;
1120 };
1121 
1122 /**
1123  * struct target_if_samp_msg_params - Spectral Analysis Messaging Protocol
1124  * data format
1125  * @rssi:  RSSI (except for secondary 80 segment)
1126  * @rssi_sec80:  RSSI for secondary 80 segment
1127  * @lower_rssi:  RSSI of lower band
1128  * @upper_rssi:  RSSI of upper band
1129  * @chain_ctl_rssi: RSSI for control channel, for all antennas
1130  * @chain_ext_rssi: RSSI for extension channel, for all antennas
1131  * @bwinfo:  bandwidth info
1132  * @data_len:  length of FFT data (except for secondary 80 segment)
1133  * @data_len_sec80:  length of FFT data for secondary 80 segment
1134  * @tstamp:  timestamp
1135  * @last_tstamp:  last time stamp
1136  * @max_mag:  maximum magnitude (except for secondary 80 segment)
1137  * @max_mag_sec80:  maximum magnitude for secondary 80 segment
1138  * @max_index:  index of max magnitude (except for secondary 80 segment)
1139  * @max_index_sec80:  index of max magnitude for secondary 80 segment
1140  * @max_exp:  max exp
1141  * @peak: peak frequency (obsolete)
1142  * @pwr_count:  number of FFT bins (except for secondary 80 segment)
1143  * @pwr_count_5mhz:  number of FFT bins in extra 5 MHz in
1144  *                   165 MHz/restricted 80p80 mode
1145  * @pwr_count_sec80:  number of FFT bins in secondary 80 segment
1146  * @nb_lower: This is deprecated
1147  * @nb_upper: This is deprecated
1148  * @max_upper_index:  index of max mag in upper band
1149  * @max_lower_index:  index of max mag in lower band
1150  * @bin_pwr_data: Contains FFT magnitudes (except for secondary 80 segment)
1151  * @bin_pwr_data_5mhz: Contains FFT magnitudes for the extra 5 MHz
1152  *                     in 165 MHz/restricted 80p80 mode
1153  * @bin_pwr_data_sec80: Contains FFT magnitudes for the secondary 80 segment
1154  * @freq: Center frequency of primary 20MHz channel in MHz
1155  * @vhtop_ch_freq_seg1: VHT operation first segment center frequency in MHz
1156  * @vhtop_ch_freq_seg2: VHT operation second segment center frequency in MHz
1157  * @agile_freq1:        Center frequency in MHz of the entire span(for 80+80 MHz
1158  *                      agile Scan it is primary 80 MHz span) across which
1159  *                      Agile Spectral is carried out. Applicable only for Agile
1160  *                      Spectral samples.
1161  * @agile_freq2:        Center frequency in MHz of the secondary 80 MHz span
1162  *                      across which Agile Spectral is carried out. Applicable
1163  *                      only for Agile Spectral samples in 80+80 MHz mode.
1164  * @freq_loading: spectral control duty cycles
1165  * @noise_floor:  current noise floor (except for secondary 80 segment)
1166  * @noise_floor_sec80:  current noise floor for secondary 80 segment
1167  * @interf_list: List of interfernce sources
1168  * @classifier_params:  classifier parameters
1169  * @sc:  classifier parameters
1170  * @pri80ind: Indication from hardware that the sample was received on the
1171  * primary 80 MHz segment. If this is set when smode =
1172  * SPECTRAL_SCAN_MODE_AGILE, it indicates that Spectral was carried out on
1173  * pri80 instead of the Agile frequency due to a channel switch - Software may
1174  * choose to ignore the sample in this case.
1175  * @pri80ind_sec80: Indication from hardware that the sample was received on the
1176  * primary 80 MHz segment instead of the secondary 80 MHz segment due to a
1177  * channel switch - Software may choose to ignore the sample if this is set.
1178  * Applicable only if smode = SPECTRAL_SCAN_MODE_NORMAL and for 160/80+80 MHz
1179  * Spectral operation and if the chipset supports fragmented 160/80+80 MHz
1180  * operation.
1181  * @last_raw_timestamp: Previous FFT report's raw timestamp. In case of 160MHz
1182  * it will be primary 80 segment's timestamp as both primary & secondary
1183  * segment's timestamps are expected to be almost equal
1184  * @timestamp_war_offset: Offset calculated based on reset_delay and
1185  * last_raw_stamp. It will be added to raw_timestamp to get tstamp.
1186  * @raw_timestamp: FFT timestamp reported by HW on primary segment.
1187  * @raw_timestamp_sec80: FFT timestamp reported by HW on secondary 80 segment.
1188  * @reset_delay: Time gap between the last spectral report before reset and the
1189  * end of reset.
1190  * @target_reset_count: Indicates the the number of times the target went
1191  * through reset routine after spectral was enabled.
1192  */
1193 struct target_if_samp_msg_params {
1194 	int8_t      rssi;
1195 	int8_t      rssi_sec80;
1196 	int8_t      lower_rssi;
1197 	int8_t      upper_rssi;
1198 	int8_t      chain_ctl_rssi[HOST_MAX_ANTENNA];
1199 	int8_t      chain_ext_rssi[HOST_MAX_ANTENNA];
1200 	uint16_t    bwinfo;
1201 	uint16_t    datalen;
1202 	uint16_t    datalen_sec80;
1203 	uint32_t    tstamp;
1204 	uint32_t    last_tstamp;
1205 	uint16_t    max_mag;
1206 	uint16_t    max_mag_sec80;
1207 	uint16_t    max_index;
1208 	uint16_t    max_index_sec80;
1209 	uint8_t     max_exp;
1210 	int         peak;
1211 	int         pwr_count;
1212 	int         pwr_count_5mhz;
1213 	int         pwr_count_sec80;
1214 	int8_t      nb_lower;
1215 	int8_t      nb_upper;
1216 	uint16_t    max_lower_index;
1217 	uint16_t    max_upper_index;
1218 	uint8_t    *bin_pwr_data;
1219 	uint8_t    *bin_pwr_data_5mhz;
1220 	uint8_t    *bin_pwr_data_sec80;
1221 	uint16_t   freq;
1222 	uint16_t   vhtop_ch_freq_seg1;
1223 	uint16_t   vhtop_ch_freq_seg2;
1224 	uint16_t   agile_freq1;
1225 	uint16_t   agile_freq2;
1226 	uint16_t   freq_loading;
1227 	int16_t     noise_floor;
1228 	int16_t     noise_floor_sec80;
1229 	struct interf_src_rsp interf_list;
1230 	struct spectral_classifier_params classifier_params;
1231 	struct ath_softc *sc;
1232 	uint8_t agc_total_gain;
1233 	uint8_t agc_total_gain_sec80;
1234 	uint8_t gainchange;
1235 	uint8_t gainchange_sec80;
1236 	enum spectral_scan_mode smode;
1237 	uint8_t pri80ind;
1238 	uint8_t pri80ind_sec80;
1239 	uint32_t last_raw_timestamp;
1240 	uint32_t timestamp_war_offset;
1241 	uint32_t raw_timestamp;
1242 	uint32_t raw_timestamp_sec80;
1243 	uint32_t reset_delay;
1244 	uint32_t target_reset_count;
1245 };
1246 
1247 #ifdef WLAN_CONV_SPECTRAL_ENABLE
1248 /**
1249  * target_if_spectral_dump_fft() - Dump Spectral FFT
1250  * @pfft: Pointer to Spectral Phyerr FFT
1251  * @fftlen: FFT length
1252  *
1253  * Return: Success or failure
1254  */
1255 int target_if_spectral_dump_fft(uint8_t *pfft, int fftlen);
1256 
1257 /**
1258  * target_if_dbg_print_samp_param() - Print contents of SAMP struct
1259  * @p: Pointer to SAMP message
1260  *
1261  * Return: Void
1262  */
1263 void target_if_dbg_print_samp_param(struct target_if_samp_msg_params *p);
1264 
1265 /**
1266  * target_if_get_offset_swar_sec80() - Get offset for SWAR according to
1267  *                                     the channel width
1268  * @channel_width: Channel width
1269  *
1270  * Return: Offset for SWAR
1271  */
1272 uint32_t target_if_get_offset_swar_sec80(uint32_t channel_width);
1273 
1274 /**
1275  * target_if_sptrl_register_tx_ops() - Register Spectral target_if Tx Ops
1276  * @tx_ops: Tx Ops
1277  *
1278  * Return: void
1279  */
1280 void target_if_sptrl_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops);
1281 
1282 /**
1283  * target_if_spectral_create_samp_msg() - Create the spectral samp message
1284  * @spectral : Pointer to spectral internal structure
1285  * @params : spectral samp message parameters
1286  *
1287  * API to create the spectral samp message
1288  *
1289  * Return: void
1290  */
1291 void target_if_spectral_create_samp_msg(
1292 	struct target_if_spectral *spectral,
1293 	struct target_if_samp_msg_params *params);
1294 
1295 /**
1296  * target_if_spectral_process_phyerr_gen3() - Process phyerror event for gen3
1297  * @pdev:    Pointer to pdev object
1298  * @payload: Pointer to spectral report
1299  *
1300  * Process phyerror event for gen3
1301  *
1302  * Return: Success/Failure
1303  */
1304 int target_if_spectral_process_report_gen3(
1305 	struct wlan_objmgr_pdev *pdev,
1306 	void *buf);
1307 
1308 /**
1309  * target_if_process_phyerr_gen2() - Process PHY Error for gen2
1310  * @spectral: Pointer to Spectral object
1311  * @data: Pointer to phyerror event buffer
1312  * @datalen: Data length
1313  * @p_rfqual: RF quality info
1314  * @p_chaninfo: Channel info
1315  * @tsf64: 64 bit tsf timestamp
1316  * @acs_stats: ACS stats
1317  *
1318  * Process PHY Error for gen2
1319  *
1320  * Return: Success/Failure
1321  */
1322 int target_if_process_phyerr_gen2(
1323 	struct target_if_spectral *spectral,
1324 	uint8_t *data,
1325 	uint32_t datalen, struct target_if_spectral_rfqual_info *p_rfqual,
1326 	struct target_if_spectral_chan_info *p_chaninfo,
1327 	uint64_t tsf64,
1328 	struct target_if_spectral_acs_stats *acs_stats);
1329 
1330 /**
1331  * target_if_spectral_send_intf_found_msg() - Indicate to application layer that
1332  * interference has been found
1333  * @pdev: Pointer to pdev
1334  * @cw_int: 1 if CW interference is found, 0 if WLAN interference is found
1335  * @dcs_enabled: 1 if DCS is enabled, 0 if DCS is disabled
1336  *
1337  * Send message to application layer
1338  * indicating that interference has been found
1339  *
1340  * Return: None
1341  */
1342 void target_if_spectral_send_intf_found_msg(
1343 	struct wlan_objmgr_pdev *pdev,
1344 	uint16_t cw_int, uint32_t dcs_enabled);
1345 
1346 /**
1347  * target_if_stop_spectral_scan() - Stop spectral scan
1348  * @pdev: Pointer to pdev object
1349  * @smode: Spectral scan mode
1350  * @err: Pointer to error code
1351  *
1352  * API to stop the current on-going spectral scan
1353  *
1354  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
1355  */
1356 QDF_STATUS target_if_stop_spectral_scan(struct wlan_objmgr_pdev *pdev,
1357 					const enum spectral_scan_mode smode,
1358 					enum spectral_cp_error_code *err);
1359 
1360 /**
1361  * target_if_spectral_get_vdev() - Get pointer to vdev to be used for Spectral
1362  * operations
1363  * @spectral: Pointer to Spectral target_if internal private data
1364  * @smode: spectral scan mode
1365  *
1366  * Spectral operates on pdev. However, in order to retrieve some WLAN
1367  * properties, a vdev is required. To facilitate this, the function returns the
1368  * first vdev in our pdev. The caller should release the reference to the vdev
1369  * once it is done using it.
1370  * TODO: If the framework later provides an API to obtain the first active
1371  * vdev, then it would be preferable to use this API.
1372  *
1373  * Return: Pointer to vdev on success, NULL on failure
1374  */
1375 struct wlan_objmgr_vdev *target_if_spectral_get_vdev(
1376 	struct target_if_spectral *spectral,
1377 	enum spectral_scan_mode smode);
1378 
1379 /**
1380  * target_if_spectral_dump_hdr_gen2() - Dump Spectral header for gen2
1381  * @phdr: Pointer to Spectral Phyerr Header
1382  *
1383  * Dump Spectral header
1384  *
1385  * Return: Success/Failure
1386  */
1387 int target_if_spectral_dump_hdr_gen2(struct spectral_phyerr_hdr_gen2 *phdr);
1388 
1389 /**
1390  * target_if_get_combrssi_sec80_seg_gen2() - Get approximate combined RSSI
1391  *                                           for Secondary 80 segment
1392  * @spectral: Pointer to spectral object
1393  * @p_sfft_sec80: Pointer to search fft info of secondary 80 segment
1394  *
1395  * Get approximate combined RSSI for Secondary 80 segment
1396  *
1397  * Return: Combined RSSI for secondary 80Mhz segment
1398  */
1399 int8_t target_if_get_combrssi_sec80_seg_gen2(
1400 	struct target_if_spectral *spectral,
1401 	struct spectral_search_fft_info_gen2 *p_sfft_sec80);
1402 
1403 /**
1404  * target_if_spectral_dump_tlv_gen2() - Dump Spectral TLV for gen2
1405  * @ptlv: Pointer to Spectral Phyerr TLV
1406  * @is_160_format: Indicates 160 format
1407  *
1408  * Dump Spectral TLV for gen2
1409  *
1410  * Return: Success/Failure
1411  */
1412 int target_if_spectral_dump_tlv_gen2(
1413 	struct spectral_phyerr_tlv_gen2 *ptlv, bool is_160_format);
1414 
1415 /**
1416  * target_if_spectral_dump_phyerr_data_gen2() - Dump Spectral
1417  * related PHY Error for gen2
1418  * @data: Pointer to phyerror buffer
1419  * @datalen: Data length
1420  * @is_160_format: Indicates 160 format
1421  *
1422  * Dump Spectral related PHY Error for gen2
1423  *
1424  * Return: Success/Failure
1425  */
1426 int target_if_spectral_dump_phyerr_data_gen2(
1427 	uint8_t *data,
1428 	uint32_t datalen,
1429 	bool is_160_format);
1430 
1431 /**
1432  * target_if_dbg_print_samp_msg() - Print contents of SAMP Message
1433  * @p: Pointer to SAMP message
1434  *
1435  * Print contents of SAMP Message
1436  *
1437  * Return: Void
1438  */
1439 void target_if_dbg_print_samp_msg(struct spectral_samp_msg *pmsg);
1440 
1441 /**
1442  * get_target_if_spectral_handle_from_pdev() - Get handle to target_if internal
1443  * Spectral data
1444  * @pdev: Pointer to pdev
1445  *
1446  * Return: Handle to target_if internal Spectral data on success, NULL on
1447  * failure
1448  */
1449 static inline
1450 struct target_if_spectral *get_target_if_spectral_handle_from_pdev(
1451 	struct wlan_objmgr_pdev *pdev)
1452 {
1453 	struct target_if_spectral *spectral;
1454 	struct wlan_objmgr_psoc *psoc;
1455 	struct wlan_lmac_if_rx_ops *rx_ops;
1456 
1457 	if (!pdev) {
1458 		spectral_err("pdev is null");
1459 		return NULL;
1460 	}
1461 
1462 	psoc = wlan_pdev_get_psoc(pdev);
1463 	if (!psoc) {
1464 		spectral_err("psoc is null");
1465 		return NULL;
1466 	}
1467 
1468 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1469 	if (!rx_ops) {
1470 		spectral_err("rx_ops is null");
1471 		return NULL;
1472 	}
1473 
1474 	spectral = (struct target_if_spectral *)
1475 		rx_ops->sptrl_rx_ops.sptrlro_get_pdev_target_handle(pdev);
1476 
1477 	return spectral;
1478 }
1479 
1480 /**
1481  * get_target_if_spectral_handle_from_psoc() - Get handle to psoc target_if
1482  * internal Spectral data
1483  * @psoc: Pointer to psoc
1484  *
1485  * Return: Handle to target_if psoc internal Spectral data on success, NULL on
1486  * failure
1487  */
1488 static inline
1489 struct target_if_psoc_spectral *get_target_if_spectral_handle_from_psoc(
1490 	struct wlan_objmgr_psoc *psoc)
1491 {
1492 	struct wlan_lmac_if_rx_ops *rx_ops;
1493 	struct target_if_psoc_spectral *psoc_spectral;
1494 
1495 	if (!psoc) {
1496 		spectral_err("psoc is null");
1497 		return NULL;
1498 	}
1499 
1500 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1501 	if (!rx_ops) {
1502 		spectral_err("rx_ops is null");
1503 		return NULL;
1504 	}
1505 
1506 	psoc_spectral = (struct target_if_psoc_spectral *)
1507 		rx_ops->sptrl_rx_ops.sptrlro_get_psoc_target_handle(psoc);
1508 
1509 	return psoc_spectral;
1510 }
1511 
1512 /**
1513  * target_if_vdev_get_chan_freq() - Get the operating channel frequency of a
1514  * given vdev
1515  * @pdev: Pointer to vdev
1516  *
1517  * Get the operating channel frequency of a given vdev
1518  *
1519  * Return: Operating channel frequency of a vdev
1520  */
1521 static inline
1522 int16_t target_if_vdev_get_chan_freq(struct wlan_objmgr_vdev *vdev)
1523 {
1524 	struct wlan_objmgr_psoc *psoc = NULL;
1525 	struct wlan_lmac_if_rx_ops *rx_ops;
1526 
1527 	psoc = wlan_vdev_get_psoc(vdev);
1528 	if (!psoc) {
1529 		spectral_err("psoc is NULL");
1530 		return -EINVAL;
1531 	}
1532 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1533 	if (!rx_ops) {
1534 		spectral_err("rx_ops is null");
1535 		return -EINVAL;
1536 	}
1537 
1538 	return rx_ops->sptrl_rx_ops.sptrlro_vdev_get_chan_freq(
1539 		vdev);
1540 }
1541 
1542 /**
1543  * target_if_vdev_get_chan_freq_seg2() - Get center frequency of secondary 80 of
1544  * given vdev
1545  * @vdev: Pointer to vdev
1546  *
1547  * Get the center frequency of secondary 80 of given vdev
1548  *
1549  * Return: center frequency of secondary 80
1550  */
1551 static inline
1552 int16_t target_if_vdev_get_chan_freq_seg2(struct wlan_objmgr_vdev *vdev)
1553 {
1554 	struct wlan_objmgr_psoc *psoc = NULL;
1555 	struct wlan_lmac_if_rx_ops *rx_ops;
1556 
1557 	psoc = wlan_vdev_get_psoc(vdev);
1558 	if (!psoc) {
1559 		spectral_err("psoc is NULL");
1560 		return -EINVAL;
1561 	}
1562 
1563 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1564 	if (!rx_ops) {
1565 		spectral_err("rx_ops is null");
1566 		return -EINVAL;
1567 	}
1568 
1569 	return rx_ops->sptrl_rx_ops.sptrlro_vdev_get_chan_freq_seg2(vdev);
1570 }
1571 
1572 /**
1573  * target_if_vdev_get_ch_width() - Get the operating channel bandwidth of a
1574  * given vdev
1575  * @pdev: Pointer to vdev
1576  *
1577  * Get the operating channel bandwidth of a given vdev
1578  *
1579  * Return: channel bandwidth enumeration corresponding to the vdev
1580  */
1581 static inline
1582 enum phy_ch_width target_if_vdev_get_ch_width(struct wlan_objmgr_vdev *vdev)
1583 {
1584 	struct wlan_objmgr_psoc *psoc = NULL;
1585 	enum phy_ch_width ch_width;
1586 	struct wlan_lmac_if_rx_ops *rx_ops;
1587 
1588 	psoc = wlan_vdev_get_psoc(vdev);
1589 	if (!psoc) {
1590 		spectral_err("psoc is NULL");
1591 		return CH_WIDTH_INVALID;
1592 	}
1593 
1594 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1595 	if (!rx_ops) {
1596 		spectral_err("rx_ops is null");
1597 		return CH_WIDTH_INVALID;
1598 	}
1599 
1600 	ch_width = rx_ops->sptrl_rx_ops.sptrlro_vdev_get_ch_width(vdev);
1601 
1602 	if (ch_width == CH_WIDTH_160MHZ) {
1603 		int16_t cfreq2;
1604 
1605 		cfreq2 = target_if_vdev_get_chan_freq_seg2(vdev);
1606 		if (cfreq2 < 0) {
1607 			spectral_err("Invalid value for cfreq2 %d", cfreq2);
1608 			return CH_WIDTH_INVALID;
1609 		}
1610 
1611 		/* Use non zero cfreq2 to identify 80p80 */
1612 		if (cfreq2)
1613 			ch_width = CH_WIDTH_80P80MHZ;
1614 	}
1615 
1616 	return ch_width;
1617 }
1618 
1619 /**
1620  * target_if_vdev_get_sec20chan_freq_mhz() - Get the frequency of secondary
1621  * 20 MHz channel for a given vdev
1622  * @pdev: Pointer to vdev
1623  *
1624  * Get the frequency of secondary 20Mhz channel for a given vdev
1625  *
1626  * Return: Frequency of secondary 20Mhz channel for a given vdev
1627  */
1628 static inline
1629 int target_if_vdev_get_sec20chan_freq_mhz(
1630 	struct wlan_objmgr_vdev *vdev,
1631 	uint16_t *sec20chan_freq)
1632 {
1633 	struct wlan_objmgr_psoc *psoc = NULL;
1634 	struct wlan_lmac_if_rx_ops *rx_ops;
1635 
1636 	psoc = wlan_vdev_get_psoc(vdev);
1637 	if (!psoc) {
1638 		spectral_err("psoc is NULL");
1639 		return -EINVAL;
1640 	}
1641 
1642 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1643 	if (!rx_ops) {
1644 		spectral_err("rx_ops is null");
1645 		return -EINVAL;
1646 	}
1647 
1648 	return rx_ops->sptrl_rx_ops.
1649 		sptrlro_vdev_get_sec20chan_freq_mhz(vdev, sec20chan_freq);
1650 }
1651 
1652 /**
1653  * target_if_spectral_set_rxchainmask() - Set Spectral Rx chainmask
1654  * @pdev: Pointer to pdev
1655  * @spectral_rx_chainmask: Spectral Rx chainmask
1656  *
1657  * Return: None
1658  */
1659 static inline
1660 void target_if_spectral_set_rxchainmask(struct wlan_objmgr_pdev *pdev,
1661 					uint8_t spectral_rx_chainmask)
1662 {
1663 	struct wlan_objmgr_psoc *psoc = NULL;
1664 	struct target_if_spectral *spectral = NULL;
1665 	enum spectral_scan_mode smode = SPECTRAL_SCAN_MODE_NORMAL;
1666 	struct wlan_lmac_if_rx_ops *rx_ops;
1667 
1668 	psoc = wlan_pdev_get_psoc(pdev);
1669 	if (!psoc) {
1670 		spectral_err("psoc is NULL");
1671 		return;
1672 	}
1673 
1674 	rx_ops = wlan_psoc_get_lmac_if_rxops(psoc);
1675 	if (!rx_ops) {
1676 		spectral_err("rx_ops is null");
1677 		return;
1678 	}
1679 
1680 	if (smode >= SPECTRAL_SCAN_MODE_MAX) {
1681 		spectral_err("Invalid Spectral mode %u", smode);
1682 		return;
1683 	}
1684 
1685 	if (rx_ops->sptrl_rx_ops.
1686 	    sptrlro_spectral_is_feature_disabled(psoc)) {
1687 		spectral_info("Spectral is disabled");
1688 		return;
1689 	}
1690 
1691 	spectral = get_target_if_spectral_handle_from_pdev(pdev);
1692 	if (!spectral) {
1693 		spectral_err("Spectral target if object is null");
1694 		return;
1695 	}
1696 
1697 	/* set chainmask for all the modes */
1698 	for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
1699 		spectral->params[smode].ss_chn_mask = spectral_rx_chainmask;
1700 }
1701 
1702 /**
1703  * target_if_spectral_process_phyerr() - Process Spectral PHY error
1704  * @pdev: Pointer to pdev
1705  * @data: PHY error data received from FW
1706  * @datalen: Length of data
1707  * @p_rfqual: Pointer to RF Quality information
1708  * @p_chaninfo: Pointer to channel information
1709  * @tsf: TSF time instance at which the Spectral sample was received
1710  * @acs_stats: ACS stats
1711  *
1712  * Process Spectral PHY error by extracting necessary information from the data
1713  * sent by FW, and send the extracted information to application layer.
1714  *
1715  * Return: None
1716  */
1717 static inline
1718 void target_if_spectral_process_phyerr(
1719 	struct wlan_objmgr_pdev *pdev,
1720 	uint8_t *data, uint32_t datalen,
1721 	struct target_if_spectral_rfqual_info *p_rfqual,
1722 	struct target_if_spectral_chan_info *p_chaninfo,
1723 	uint64_t tsf64,
1724 	struct target_if_spectral_acs_stats *acs_stats)
1725 {
1726 	struct target_if_spectral *spectral = NULL;
1727 	struct target_if_spectral_ops *p_sops = NULL;
1728 
1729 	spectral = get_target_if_spectral_handle_from_pdev(pdev);
1730 	if (!spectral) {
1731 		spectral_err("Spectral target if object is null");
1732 		return;
1733 	}
1734 
1735 	p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
1736 	p_sops->spectral_process_phyerr(spectral, data, datalen,
1737 					p_rfqual, p_chaninfo,
1738 					tsf64, acs_stats);
1739 }
1740 
1741 static QDF_STATUS
1742 target_if_get_spectral_msg_type(enum spectral_scan_mode smode,
1743 				enum spectral_msg_type *msg_type) {
1744 
1745 	switch (smode) {
1746 	case SPECTRAL_SCAN_MODE_NORMAL:
1747 		*msg_type = SPECTRAL_MSG_NORMAL_MODE;
1748 		break;
1749 
1750 	case SPECTRAL_SCAN_MODE_AGILE:
1751 		*msg_type = SPECTRAL_MSG_AGILE_MODE;
1752 		break;
1753 
1754 	default:
1755 		spectral_err("Invalid spectral mode");
1756 		return QDF_STATUS_E_FAILURE;
1757 	}
1758 
1759 	return QDF_STATUS_SUCCESS;
1760 }
1761 
1762 static inline bool
1763 is_ch_width_160_or_80p80(enum phy_ch_width ch_width)
1764 {
1765 	return (ch_width == CH_WIDTH_160MHZ || ch_width == CH_WIDTH_80P80MHZ);
1766 }
1767 
1768 /**
1769  * init_160mhz_delivery_state_machine() - Initialize 160MHz Spectral
1770  *                                        state machine
1771  * @spectral: Pointer to Spectral
1772  *
1773  * Initialize 160MHz Spectral state machine
1774  *
1775  * Return: void
1776  */
1777 static inline void
1778 init_160mhz_delivery_state_machine(struct target_if_spectral *spectral)
1779 {
1780 	uint8_t smode;
1781 
1782 	smode = 0;
1783 	for (; smode < SPECTRAL_SCAN_MODE_MAX; smode++)
1784 		spectral->state_160mhz_delivery[smode] =
1785 				SPECTRAL_REPORT_WAIT_PRIMARY80;
1786 }
1787 
1788 /**
1789  * reset_160mhz_delivery_state_machine() - Reset 160MHz Spectral state machine
1790  * @spectral: Pointer to Spectral
1791  *
1792  * Reset 160MHz Spectral state machine
1793  *
1794  * Return: void
1795  */
1796 static inline void
1797 reset_160mhz_delivery_state_machine(struct target_if_spectral *spectral,
1798 				    enum spectral_scan_mode smode)
1799 {
1800 	enum spectral_msg_type smsg_type;
1801 	QDF_STATUS ret;
1802 
1803 	if (smode >= SPECTRAL_SCAN_MODE_MAX) {
1804 		spectral_err_rl("Invalid Spectral mode %d", smode);
1805 		return;
1806 	}
1807 
1808 	if (is_ch_width_160_or_80p80(spectral->ch_width[smode])) {
1809 		spectral->state_160mhz_delivery[smode] =
1810 			SPECTRAL_REPORT_WAIT_PRIMARY80;
1811 
1812 		ret = target_if_get_spectral_msg_type(smode, &smsg_type);
1813 		if (QDF_IS_STATUS_ERROR(ret)) {
1814 			spectral_err("Failed to get spectral message type");
1815 			return;
1816 		}
1817 
1818 		spectral->nl_cb.free_sbuff(spectral->pdev_obj,
1819 					   smsg_type);
1820 	}
1821 }
1822 
1823 /**
1824  * is_secondaryseg_expected() - Is waiting for secondary 80 report
1825  * @spectral: Pointer to Spectral
1826  * @smode: Spectral scan mode
1827  *
1828  * Return true if secondary 80 report expected and mode is 160 MHz
1829  *
1830  * Return: true or false
1831  */
1832 static inline
1833 bool is_secondaryseg_expected(struct target_if_spectral *spectral,
1834 			      enum spectral_scan_mode smode)
1835 {
1836 	return
1837 	(is_ch_width_160_or_80p80(spectral->ch_width[smode]) &&
1838 	 spectral->rparams.fragmentation_160[smode] &&
1839 	 (spectral->state_160mhz_delivery[smode] ==
1840 	  SPECTRAL_REPORT_WAIT_SECONDARY80));
1841 }
1842 
1843 /**
1844  * is_primaryseg_expected() - Is waiting for primary 80 report
1845  * @spectral: Pointer to Spectral
1846  * @smode: Spectral scan mode
1847  *
1848  * Return true if mode is 160 Mhz and primary 80 report expected or
1849  * mode is not 160 Mhz
1850  *
1851  * Return: true or false
1852  */
1853 static inline
1854 bool is_primaryseg_expected(struct target_if_spectral *spectral,
1855 			    enum spectral_scan_mode smode)
1856 {
1857 	return
1858 	(!is_ch_width_160_or_80p80(spectral->ch_width[smode]) ||
1859 	 !spectral->rparams.fragmentation_160[smode] ||
1860 	 (spectral->state_160mhz_delivery[smode] ==
1861 	  SPECTRAL_REPORT_WAIT_PRIMARY80));
1862 }
1863 
1864 /**
1865  * is_primaryseg_rx_inprog() - Is primary 80 report processing is in progress
1866  * @spectral: Pointer to Spectral
1867  * @smode: Spectral scan mode
1868  *
1869  * Is primary 80 report processing is in progress
1870  *
1871  * Return: true or false
1872  */
1873 static inline
1874 bool is_primaryseg_rx_inprog(struct target_if_spectral *spectral,
1875 			     enum spectral_scan_mode smode)
1876 {
1877 	return
1878 	(!is_ch_width_160_or_80p80(spectral->ch_width[smode]) ||
1879 	 spectral->spectral_gen == SPECTRAL_GEN2 ||
1880 	 (spectral->spectral_gen == SPECTRAL_GEN3 &&
1881 	  (!spectral->rparams.fragmentation_160[smode] ||
1882 	   spectral->state_160mhz_delivery[smode] ==
1883 	   SPECTRAL_REPORT_RX_PRIMARY80)));
1884 }
1885 
1886 /**
1887  * is_secondaryseg_rx_inprog() - Is secondary80 report processing is in progress
1888  * @spectral: Pointer to Spectral
1889  * @smode: Spectral scan mode
1890  *
1891  * Is secondary 80 report processing is in progress
1892  *
1893  * Return: true or false
1894  */
1895 static inline
1896 bool is_secondaryseg_rx_inprog(struct target_if_spectral *spectral,
1897 			       enum spectral_scan_mode smode)
1898 {
1899 	return
1900 	(is_ch_width_160_or_80p80(spectral->ch_width[smode]) &&
1901 	 (spectral->spectral_gen == SPECTRAL_GEN2 ||
1902 	  ((spectral->spectral_gen == SPECTRAL_GEN3) &&
1903 	   (!spectral->rparams.fragmentation_160[smode] ||
1904 	    spectral->state_160mhz_delivery[smode] ==
1905 	    SPECTRAL_REPORT_RX_SECONDARY80))));
1906 }
1907 
1908 /**
1909  * target_if_160mhz_delivery_state_change() - State transition for 160Mhz
1910  *                                            Spectral
1911  * @spectral: Pointer to spectral object
1912  * @smode: Spectral scan mode
1913  * @detector_id: Detector id
1914  *
1915  * Move the states of state machine for 160MHz spectral scan report receive
1916  *
1917  * Return: QDF_STATUS
1918  */
1919 QDF_STATUS
1920 target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
1921 				       enum spectral_scan_mode smode,
1922 				       uint8_t detector_id);
1923 
1924 /**
1925  * target_if_sops_is_spectral_enabled() - Get whether Spectral is enabled
1926  * @arg: Pointer to handle for Spectral target_if internal private data
1927  * @smode: Spectral scan mode
1928  *
1929  * Function to check whether Spectral is enabled
1930  *
1931  * Return: True if Spectral is enabled, false if Spectral is not enabled
1932  */
1933 uint32_t target_if_sops_is_spectral_enabled(void *arg,
1934 					    enum spectral_scan_mode smode);
1935 
1936 /**
1937  * target_if_sops_is_spectral_active() - Get whether Spectral is active
1938  * @arg: Pointer to handle for Spectral target_if internal private data
1939  * @smode: Spectral scan mode
1940  *
1941  * Function to check whether Spectral is active
1942  *
1943  * Return: True if Spectral is active, false if Spectral is not active
1944  */
1945 uint32_t target_if_sops_is_spectral_active(void *arg,
1946 					   enum spectral_scan_mode smode);
1947 
1948 /**
1949  * target_if_sops_start_spectral_scan() - Start Spectral scan
1950  * @arg: Pointer to handle for Spectral target_if internal private data
1951  * @smode: Spectral scan mode
1952  * @err: Pointer to error code
1953  *
1954  * Function to start spectral scan
1955  *
1956  * Return: 0 on success else failure
1957  */
1958 uint32_t target_if_sops_start_spectral_scan(void *arg,
1959 					    enum spectral_scan_mode smode,
1960 					    enum spectral_cp_error_code *err);
1961 
1962 /**
1963  * target_if_sops_stop_spectral_scan() - Stop Spectral scan
1964  * @arg: Pointer to handle for Spectral target_if internal private data
1965  * @smode: Spectral scan mode
1966  *
1967  * Function to stop spectral scan
1968  *
1969  * Return: 0 in case of success, -1 on failure
1970  */
1971 uint32_t target_if_sops_stop_spectral_scan(void *arg,
1972 					   enum spectral_scan_mode smode);
1973 
1974 /**
1975  * target_if_spectral_get_extension_channel() - Get the current Extension
1976  *                                              channel (in MHz)
1977  * @arg: Pointer to handle for Spectral target_if internal private data
1978  * @smode: Spectral scan mode
1979  *
1980  * Return: Current Extension channel (in MHz) on success, 0 on failure or if
1981  * extension channel is not present.
1982  */
1983 uint32_t
1984 target_if_spectral_get_extension_channel(void *arg,
1985 					 enum spectral_scan_mode smode);
1986 
1987 /**
1988  * target_if_spectral_get_current_channel() - Get the current channel (in MHz)
1989  * @arg: Pointer to handle for Spectral target_if internal private data
1990  * @smode: Spectral scan mode
1991  *
1992  * Return: Current channel (in MHz) on success, 0 on failure
1993  */
1994 uint32_t
1995 target_if_spectral_get_current_channel(void *arg,
1996 				       enum spectral_scan_mode smode);
1997 
1998 
1999 /**
2000  * target_if_spectral_reset_hw() - Reset the hardware
2001  * @arg: Pointer to handle for Spectral target_if internal private data
2002  *
2003  * This is only a placeholder since it is not currently required in the offload
2004  * case.
2005  *
2006  * Return: 0
2007  */
2008 uint32_t target_if_spectral_reset_hw(void *arg);
2009 
2010 /**
2011  * target_if_spectral_get_chain_noise_floor() - Get the Chain noise floor from
2012  * Noisefloor history buffer
2013  * @arg: Pointer to handle for Spectral target_if internal private data
2014  * @nf_buf: Pointer to buffer into which chain Noise Floor data should be copied
2015  *
2016  * This is only a placeholder since it is not currently required in the offload
2017  * case.
2018  *
2019  * Return: 0
2020  */
2021 uint32_t target_if_spectral_get_chain_noise_floor(void *arg, int16_t *nf_buf);
2022 
2023 /**
2024  * target_if_spectral_get_ext_noisefloor() - Get the extension channel
2025  * noisefloor
2026  * @arg: Pointer to handle for Spectral target_if internal private data
2027  *
2028  * This is only a placeholder since it is not currently required in the offload
2029  * case.
2030  *
2031  * Return: 0
2032  */
2033 int8_t target_if_spectral_get_ext_noisefloor(void *arg);
2034 
2035 /**
2036  * target_if_spectral_get_ctl_noisefloor() - Get the control channel noisefloor
2037  * @arg: Pointer to handle for Spectral target_if internal private data
2038  *
2039  * This is only a placeholder since it is not currently required in the offload
2040  * case.
2041  *
2042  * Return: 0
2043  */
2044 int8_t target_if_spectral_get_ctl_noisefloor(void *arg);
2045 
2046 /**
2047  * target_if_spectral_get_capability() - Get whether a given Spectral hardware
2048  * capability is available
2049  * @arg: Pointer to handle for Spectral target_if internal private data
2050  * @type: Spectral hardware capability type
2051  *
2052  * Return: True if the capability is available, false if the capability is not
2053  * available
2054  */
2055 uint32_t target_if_spectral_get_capability(
2056 	void *arg, enum spectral_capability_type type);
2057 
2058 /**
2059  * target_if_spectral_set_rxfilter() - Set the RX Filter before Spectral start
2060  * @arg: Pointer to handle for Spectral target_if internal private data
2061  * @rxfilter: Rx filter to be used
2062  *
2063  * Note: This is only a placeholder function. It is not currently required since
2064  * FW should be taking care of setting the required filters.
2065  *
2066  * Return: 0
2067  */
2068 uint32_t target_if_spectral_set_rxfilter(void *arg, int rxfilter);
2069 
2070 /**
2071  * target_if_spectral_sops_configure_params() - Configure user supplied Spectral
2072  * parameters
2073  * @arg: Pointer to handle for Spectral target_if internal private data
2074  * @params: Spectral parameters
2075  * @smode: Spectral scan mode
2076  *
2077  * Return: 0 in case of success, -1 on failure
2078  */
2079 uint32_t target_if_spectral_sops_configure_params(
2080 				void *arg, struct spectral_config *params,
2081 				enum spectral_scan_mode smode);
2082 
2083 /**
2084  * target_if_spectral_get_rxfilter() - Get the current RX Filter settings
2085  * @arg: Pointer to handle for Spectral target_if internal private data
2086  *
2087  * Note: This is only a placeholder function. It is not currently required since
2088  * FW should be taking care of setting the required filters.
2089  *
2090  * Return: 0
2091  */
2092 uint32_t target_if_spectral_get_rxfilter(void *arg);
2093 
2094 /**
2095  * target_if_pdev_spectral_deinit() - De-initialize target_if Spectral
2096  * functionality for the given pdev
2097  * @pdev: Pointer to pdev object
2098  *
2099  * Return: None
2100  */
2101 void target_if_pdev_spectral_deinit(struct wlan_objmgr_pdev *pdev);
2102 
2103 /**
2104  * target_if_set_spectral_config() - Set spectral config
2105  * @pdev:       Pointer to pdev object
2106  * @param: Spectral parameter id and value
2107  * @smode: Spectral scan mode
2108  * @err: Pointer to Spectral error code
2109  *
2110  * API to set spectral configurations
2111  *
2112  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2113  */
2114 QDF_STATUS target_if_set_spectral_config(struct wlan_objmgr_pdev *pdev,
2115 					 const struct spectral_cp_param *param,
2116 					 const enum spectral_scan_mode smode,
2117 					 enum spectral_cp_error_code *err);
2118 
2119 /**
2120  * target_if_pdev_spectral_init() - Initialize target_if Spectral
2121  * functionality for the given pdev
2122  * @pdev: Pointer to pdev object
2123  *
2124  * Return: On success, pointer to Spectral target_if internal private data, on
2125  * failure, NULL
2126  */
2127 void *target_if_pdev_spectral_init(struct wlan_objmgr_pdev *pdev);
2128 
2129 /**
2130  * target_if_spectral_sops_get_params() - Get user configured Spectral
2131  * parameters
2132  * @arg: Pointer to handle for Spectral target_if internal private data
2133  * @params: Pointer to buffer into which Spectral parameters should be copied
2134  * @smode: Spectral scan mode
2135  *
2136  * Return: 0 in case of success, -1 on failure
2137  */
2138 uint32_t target_if_spectral_sops_get_params(
2139 			void *arg, struct spectral_config *params,
2140 			enum spectral_scan_mode smode);
2141 
2142 /**
2143  * target_if_init_spectral_capability() - Initialize Spectral capability
2144  *
2145  * @spectral: Pointer to Spectral target_if internal private data
2146  * @target_type: target type
2147  *
2148  * This is a workaround.
2149  *
2150  * Return: QDF_STATUS
2151  */
2152 QDF_STATUS
2153 target_if_init_spectral_capability(struct target_if_spectral *spectral,
2154 				   uint32_t target_type);
2155 
2156 /**
2157  * target_if_start_spectral_scan() - Start spectral scan
2158  * @pdev: Pointer to pdev object
2159  * @vdev_id: VDEV id
2160  * @smode: Spectral scan mode
2161  * @err: Spectral error code
2162  *
2163  * API to start spectral scan
2164  *
2165  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2166  */
2167 QDF_STATUS target_if_start_spectral_scan(struct wlan_objmgr_pdev *pdev,
2168 					 uint8_t vdev_id,
2169 					 enum spectral_scan_mode smode,
2170 					 enum spectral_cp_error_code *err);
2171 
2172 /**
2173  * target_if_get_spectral_config() - Get spectral configuration
2174  * @pdev: Pointer to pdev object
2175  * @param: Pointer to spectral_config structure in which the configuration
2176  * should be returned
2177  * @smode: Spectral scan mode
2178  *
2179  * API to get the current spectral configuration
2180  *
2181  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2182  */
2183 QDF_STATUS target_if_get_spectral_config(struct wlan_objmgr_pdev *pdev,
2184 					 struct spectral_config *param,
2185 					 enum spectral_scan_mode smode);
2186 
2187 /**
2188  * target_if_spectral_scan_enable_params() - Enable use of desired Spectral
2189  *                                           parameters
2190  * @spectral: Pointer to Spectral target_if internal private data
2191  * @spectral_params: Pointer to Spectral parameters
2192  * @smode: Spectral scan mode
2193  * @err: Spectral error code
2194  *
2195  * Enable use of desired Spectral parameters by configuring them into HW, and
2196  * starting Spectral scan
2197  *
2198  * Return: 0 on success, 1 on failure
2199  */
2200 int target_if_spectral_scan_enable_params(
2201 		struct target_if_spectral *spectral,
2202 		struct spectral_config *spectral_params,
2203 		enum spectral_scan_mode smode,
2204 		enum spectral_cp_error_code *err);
2205 
2206 /**
2207  * target_if_is_spectral_active() - Get whether Spectral is active
2208  * @pdev: Pointer to pdev object
2209  * @smode: Spectral scan mode
2210  *
2211  * Return: True if Spectral is active, false if Spectral is not active
2212  */
2213 bool target_if_is_spectral_active(struct wlan_objmgr_pdev *pdev,
2214 				  enum spectral_scan_mode smode);
2215 
2216 /**
2217  * target_if_is_spectral_enabled() - Get whether Spectral is enabled
2218  * @pdev: Pointer to pdev object
2219  * @smode: Spectral scan mode
2220  *
2221  * Return: True if Spectral is enabled, false if Spectral is not enabled
2222  */
2223 bool target_if_is_spectral_enabled(struct wlan_objmgr_pdev *pdev,
2224 				   enum spectral_scan_mode smode);
2225 
2226 /**
2227  * target_if_set_debug_level() - Set debug level for Spectral
2228  * @pdev: Pointer to pdev object
2229  * @debug_level: Debug level
2230  *
2231  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2232  *
2233  */
2234 QDF_STATUS target_if_set_debug_level(struct wlan_objmgr_pdev *pdev,
2235 				     uint32_t debug_level);
2236 
2237 /**
2238  * target_if_get_debug_level() - Get debug level for Spectral
2239  * @pdev: Pointer to pdev object
2240  *
2241  * Return: Current debug level
2242  */
2243 uint32_t target_if_get_debug_level(struct wlan_objmgr_pdev *pdev);
2244 
2245 
2246 /**
2247  * target_if_get_spectral_capinfo() - Get Spectral capability information
2248  * @pdev: Pointer to pdev object
2249  * @scaps: Buffer into which data should be copied
2250  *
2251  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2252  */
2253 QDF_STATUS target_if_get_spectral_capinfo(struct wlan_objmgr_pdev *pdev,
2254 					  struct spectral_caps *scaps);
2255 
2256 
2257 /**
2258  * target_if_get_spectral_diagstats() - Get Spectral diagnostic statistics
2259  * @pdev:  Pointer to pdev object
2260  * @stats: Buffer into which data should be copied
2261  *
2262  * Return: QDF_STATUS_SUCCESS in case of success, else QDF_STATUS_E_FAILURE
2263  */
2264 QDF_STATUS target_if_get_spectral_diagstats(struct wlan_objmgr_pdev *pdev,
2265 					    struct spectral_diag_stats *stats);
2266 
2267 QDF_STATUS
2268 target_if_160mhz_delivery_state_change(struct target_if_spectral *spectral,
2269 				       enum spectral_scan_mode smode,
2270 				       uint8_t detector_id);
2271 #ifdef DIRECT_BUF_RX_ENABLE
2272 /**
2273  * target_if_consume_sfft_report_gen3() -  Process fft report for gen3
2274  * @spectral: Pointer to spectral object
2275  * @report: Pointer to spectral report
2276  *
2277  * Process fft report for gen3
2278  *
2279  * Return: Success/Failure
2280  */
2281 int
2282 target_if_consume_spectral_report_gen3(
2283 	 struct target_if_spectral *spectral,
2284 	 struct spectral_report *report);
2285 #endif
2286 
2287 /**
2288  * target_if_spectral_fw_hang() - Crash the FW from Spectral module
2289  * @spectral: Pointer to Spectral LMAC object
2290  *
2291  * Return: QDF_STATUS of operation
2292  */
2293 QDF_STATUS target_if_spectral_fw_hang(struct target_if_spectral *spectral);
2294 
2295 /**
2296  * target_if_spectral_finite_scan_update() - Update scan count for finite scan
2297  * and stop Spectral scan when required
2298  * @spectral: Pointer to Spectral target_if internal private data
2299  * @smode: Spectral scan mode
2300  *
2301  * This API decrements the number of Spectral reports expected from target for
2302  * a finite Spectral scan. When expected number of reports are received from
2303  * target Spectral scan is stopped.
2304  *
2305  * Return: QDF_STATUS on success
2306  */
2307 QDF_STATUS
2308 target_if_spectral_finite_scan_update(struct target_if_spectral *spectral,
2309 				      enum spectral_scan_mode smode);
2310 
2311 /**
2312  * target_if_spectral_is_finite_scan() - Check Spectral scan is finite/infinite
2313  * @spectral: Pointer to Spectral target_if internal private data
2314  * @smode: Spectral scan mode
2315  *
2316  * API to check whether Spectral scan is finite/infinite for the give mode.
2317  * A non zero scan count indicates that scan is finite. Scan count of 0
2318  * indicates an infinite Spectral scan.
2319  *
2320  * Return: QDF_STATUS on success
2321  */
2322 QDF_STATUS
2323 target_if_spectral_is_finite_scan(struct target_if_spectral *spectral,
2324 				  enum spectral_scan_mode smode,
2325 				  bool *finite_spectral_scan);
2326 
2327 #ifdef WIN32
2328 #pragma pack(pop, target_if_spectral)
2329 #endif
2330 #ifdef __ATTRIB_PACK
2331 #undef __ATTRIB_PACK
2332 #endif
2333 
2334 #endif /* WLAN_CONV_SPECTRAL_ENABLE */
2335 #endif /* _TARGET_IF_SPECTRAL_H_ */
2336