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