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