xref: /wlan-dirver/qca-wifi-host-cmn/target_if/spectral/target_if_spectral_netlink.c (revision 901120c066e139c7f8a2c8e4820561fdd83c67ef)
1 /*
2  * Copyright (c) 2011,2017-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  *
6  * Permission to use, copy, modify, and/or distribute this software for
7  * any purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  * PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <osdep.h>
22 #include <wlan_tgt_def_config.h>
23 #include <hif.h>
24 #include <hif_hw_version.h>
25 #include <wmi_unified_api.h>
26 #include <target_if_spectral.h>
27 #include <wlan_lmac_if_def.h>
28 #include <wlan_osif_priv.h>
29 #include <reg_services_public_struct.h>
30 
31 extern int spectral_debug_level;
32 
33 #ifdef OPTIMIZED_SAMP_MESSAGE
34 QDF_STATUS
35 target_if_spectral_fill_samp_msg(struct target_if_spectral *spectral,
36 				 struct target_if_samp_msg_params *params)
37 {
38 	struct spectral_samp_msg *spec_samp_msg;
39 	struct per_session_det_map *det_map;
40 	enum spectral_msg_type msg_type;
41 	QDF_STATUS ret;
42 	uint16_t dest_det_idx;
43 	enum spectral_scan_mode spectral_mode;
44 	uint16_t pwr_format;
45 	struct spectral_data_stats *spectral_dp_stats;
46 
47 	if (!spectral) {
48 		spectral_err_rl("Spectral LMAC object is null");
49 		return QDF_STATUS_E_NULL_VALUE;
50 	}
51 
52 	spectral_dp_stats = &spectral->data_stats;
53 	spectral_dp_stats->fill_samp_msg_calls++;
54 
55 	if (!params) {
56 		spectral_err_rl("SAMP msg params structure is null");
57 		return QDF_STATUS_E_NULL_VALUE;
58 	}
59 
60 	if (params->hw_detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
61 		spectral_err_rl("Invalid detector ID");
62 		return QDF_STATUS_E_FAILURE;
63 	}
64 
65 	spectral_mode =
66 		spectral->rparams.detid_mode_table[params->hw_detector_id];
67 	if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
68 		spectral_err_rl("No valid Spectral mode for detector id %u",
69 				params->hw_detector_id);
70 		return QDF_STATUS_E_FAILURE;
71 	}
72 
73 	ret = target_if_get_spectral_msg_type(spectral_mode,
74 					      &msg_type);
75 	if (QDF_IS_STATUS_ERROR(ret)) {
76 		spectral_err_rl("Invalid spectral msg type");
77 		return QDF_STATUS_E_FAILURE;
78 	}
79 
80 	pwr_format = spectral->params[spectral_mode].ss_pwr_format;
81 
82 	qdf_spin_lock_bh(&spectral->session_det_map_lock);
83 
84 	if (!spectral->det_map[params->hw_detector_id].
85 				det_map_valid[spectral_mode]) {
86 		qdf_spin_unlock_bh(&spectral->session_det_map_lock);
87 		spectral_info("Detector Map not valid for det id = %d and spectral mode = %d",
88 			      params->hw_detector_id, spectral_mode);
89 		return QDF_STATUS_E_FAILURE;
90 	}
91 
92 	det_map = &spectral->det_map[params->hw_detector_id];
93 
94 	spec_samp_msg = spectral->nl_cb.get_sbuff(spectral->pdev_obj,
95 						  msg_type,
96 						  det_map->buf_type);
97 	if (!spec_samp_msg) {
98 		qdf_spin_unlock_bh(&spectral->session_det_map_lock);
99 		spectral_err_rl("Spectral SAMP message is NULL");
100 		return QDF_STATUS_E_FAILURE;
101 	}
102 
103 	for (dest_det_idx = 0; dest_det_idx < det_map->num_dest_det_info;
104 	     dest_det_idx++) {
105 		struct per_session_dest_det_info *map_det_info;
106 		struct samp_freq_span_info *span_info;
107 		struct samp_detector_info *detector_info;
108 		uint8_t dest_detector_id;
109 		uint8_t span_id;
110 		struct samp_edge_extra_bin_info *lb_edge_bins;
111 		struct samp_edge_extra_bin_info *rb_edge_bins;
112 		uint8_t *bin_pwr_data;
113 		size_t pwr_count;
114 		uint16_t num_edge_bins;
115 		uint16_t start_bin_index;
116 		uint32_t bytes_copied;
117 
118 
119 		map_det_info = &det_map->dest_det_info[dest_det_idx];
120 		span_id = map_det_info->freq_span_id;
121 		span_info = &spec_samp_msg->freq_span_info[span_id];
122 		span_info->num_detectors++;
123 
124 		dest_detector_id = map_det_info->det_id;
125 		detector_info = &span_info->detector_info[dest_detector_id];
126 		lb_edge_bins = &detector_info->left_edge_bins;
127 		rb_edge_bins = &detector_info->right_edge_bins;
128 
129 		detector_info->start_frequency = map_det_info->start_freq;
130 		detector_info->end_frequency = map_det_info->end_freq;
131 		detector_info->start_bin_idx = map_det_info->dest_start_bin_idx;
132 		detector_info->end_bin_idx = map_det_info->dest_end_bin_idx;
133 		lb_edge_bins->start_bin_idx =
134 					map_det_info->lb_extrabins_start_idx;
135 		lb_edge_bins->num_bins = map_det_info->lb_extrabins_num;
136 		rb_edge_bins->start_bin_idx =
137 					map_det_info->rb_extrabins_start_idx;
138 		rb_edge_bins->num_bins = map_det_info->rb_extrabins_num;
139 		start_bin_index = detector_info->start_bin_idx;
140 
141 		detector_info->rssi = params->rssi;
142 
143 		detector_info->last_raw_timestamp = params->last_raw_timestamp;
144 		detector_info->reset_delay = params->reset_delay;
145 		detector_info->raw_timestamp = params->raw_timestamp;
146 		detector_info->timestamp = params->timestamp;
147 		detector_info->timestamp_war_offset = spectral->timestamp_war.
148 				timestamp_war_offset[spectral_mode];
149 
150 		detector_info->max_magnitude = params->max_mag;
151 		detector_info->max_index = params->max_index;
152 
153 		detector_info->noise_floor = params->noise_floor;
154 		detector_info->agc_total_gain = params->agc_total_gain;
155 		detector_info->gainchange = params->gainchange;
156 		detector_info->is_sec80 = map_det_info->is_sec80;
157 		/* In 165MHz, Pri80 indication to be set for Span ID 0 only */
158 		if (span_id == SPECTRAL_FREQ_SPAN_ID_0)
159 			detector_info->pri80ind = params->pri80ind;
160 
161 		bin_pwr_data = &params->bin_pwr_data
162 					[map_det_info->src_start_bin_idx];
163 		pwr_count = detector_info->end_bin_idx -
164 			    detector_info->start_bin_idx + 1;
165 		num_edge_bins = lb_edge_bins->num_bins +
166 				rb_edge_bins->num_bins;
167 
168 		/* Copy left edge bins */
169 		if (lb_edge_bins->num_bins > 0) {
170 			ret = target_if_spectral_copy_fft_bins(
171 					spectral, bin_pwr_data,
172 					&spec_samp_msg->bin_pwr[
173 					lb_edge_bins->start_bin_idx],
174 					lb_edge_bins->num_bins,
175 					&bytes_copied, pwr_format);
176 
177 			if (QDF_IS_STATUS_ERROR(ret)) {
178 				qdf_spin_unlock_bh(
179 					&spectral->session_det_map_lock);
180 				spectral_err_rl("Unable to copy left edge FFT bins");
181 				return QDF_STATUS_E_FAILURE;
182 			}
183 
184 			/* Advance the fft bin pointer in the report */
185 			bin_pwr_data += bytes_copied;
186 		}
187 
188 		/* Copy the in-band and out-band bins */
189 		ret = target_if_spectral_copy_fft_bins(
190 				spectral, bin_pwr_data,
191 				&spec_samp_msg->bin_pwr[start_bin_index],
192 				pwr_count,
193 				&bytes_copied, pwr_format);
194 
195 		if (QDF_IS_STATUS_ERROR(ret)) {
196 			qdf_spin_unlock_bh(
197 				&spectral->session_det_map_lock);
198 			spectral_err_rl("Unable to copy in-band/out-band FFT bins");
199 			return QDF_STATUS_E_FAILURE;
200 		}
201 		/* Advance the fft bin pointer in the report */
202 		bin_pwr_data += bytes_copied;
203 
204 		/* Copy right edge bins */
205 		if (rb_edge_bins->num_bins > 0) {
206 			ret = target_if_spectral_copy_fft_bins(
207 					spectral, bin_pwr_data,
208 					&spec_samp_msg->bin_pwr[
209 					rb_edge_bins->start_bin_idx],
210 					rb_edge_bins->num_bins,
211 					&bytes_copied, pwr_format);
212 
213 			if (QDF_IS_STATUS_ERROR(ret)) {
214 				qdf_spin_unlock_bh(
215 					&spectral->session_det_map_lock);
216 				spectral_err_rl("Unable to copy right edge FFT bins");
217 				return QDF_STATUS_E_FAILURE;
218 			}
219 
220 			/* Advance the fft bin pointer in the report */
221 			bin_pwr_data += bytes_copied;
222 		}
223 
224 		spec_samp_msg->bin_pwr_count += (pwr_count + num_edge_bins);
225 	}
226 
227 	if (det_map->send_to_upper_layers) {
228 		/* Fill per-report information */
229 		struct per_session_report_info *rpt_info;
230 		struct target_if_spectral_ops *p_sops;
231 
232 		p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
233 
234 		qdf_spin_lock_bh(&spectral->session_report_info_lock);
235 
236 		rpt_info = &spectral->report_info[spectral_mode];
237 
238 		if (!rpt_info->valid) {
239 			qdf_spin_unlock_bh(&spectral->session_report_info_lock);
240 			qdf_spin_unlock_bh(&spectral->session_det_map_lock);
241 			spectral_info("per-session report info is not valid");
242 			return QDF_STATUS_E_FAILURE;
243 		}
244 
245 		spec_samp_msg->signature = SPECTRAL_SIGNATURE;
246 		p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
247 		spec_samp_msg->spectral_mode = spectral_mode;
248 		spec_samp_msg->target_reset_count =
249 				spectral->timestamp_war.target_reset_count;
250 		spec_samp_msg->operating_bw = spectral->nl_cb.
251 				convert_to_nl_ch_width(rpt_info->operating_bw);
252 		if (spec_samp_msg->operating_bw < 0) {
253 			spectral_err_rl("Invalid operating channel width %d",
254 					rpt_info->operating_bw);
255 			return QDF_STATUS_E_FAILURE;
256 		}
257 		spec_samp_msg->pri20_freq = rpt_info->pri20_freq;
258 		spec_samp_msg->cfreq1 = rpt_info->cfreq1;
259 		spec_samp_msg->cfreq2 = rpt_info->cfreq2;
260 		spec_samp_msg->sscan_cfreq1 = rpt_info->sscan_cfreq1;
261 		spec_samp_msg->sscan_cfreq2 = rpt_info->sscan_cfreq2;
262 		spec_samp_msg->sscan_bw = spectral->nl_cb.
263 				convert_to_nl_ch_width(rpt_info->sscan_bw);
264 		if (spec_samp_msg->sscan_bw < 0) {
265 			spectral_err_rl("Invalid sscan channel width %d",
266 					rpt_info->sscan_bw);
267 			return QDF_STATUS_E_FAILURE;
268 		}
269 		spec_samp_msg->fft_width = FFT_BIN_SIZE_1BYTE;
270 		spec_samp_msg->num_freq_spans = rpt_info->num_spans;
271 
272 		qdf_spin_unlock_bh(&spectral->session_report_info_lock);
273 
274 		spec_samp_msg->spectral_upper_rssi = params->upper_rssi;
275 		spec_samp_msg->spectral_lower_rssi = params->lower_rssi;
276 		qdf_mem_copy(spec_samp_msg->spectral_chain_ctl_rssi,
277 			     params->chain_ctl_rssi,
278 			     sizeof(params->chain_ctl_rssi));
279 		qdf_mem_copy(spec_samp_msg->spectral_chain_ext_rssi,
280 			     params->chain_ext_rssi,
281 			     sizeof(params->chain_ext_rssi));
282 
283 		if (spectral_debug_level & DEBUG_SPECTRAL4)
284 			target_if_dbg_print_samp_msg(spec_samp_msg);
285 
286 		spectral_dp_stats->msgs_ready_for_user++;
287 		if (spectral->send_phy_data(spectral->pdev_obj,
288 					    msg_type) == 0) {
289 			spectral->spectral_sent_msg++;
290 			spectral_dp_stats->msgs_queued_to_user++;
291 		}
292 		if (spectral->spectral_gen == SPECTRAL_GEN3)
293 			reset_160mhz_delivery_state_machine(spectral,
294 							    spectral_mode);
295 	}
296 	qdf_spin_unlock_bh(&spectral->session_det_map_lock);
297 
298 	return QDF_STATUS_SUCCESS;
299 }
300 #endif /* OPTIMIZED_SAMP_MESSAGE */
301 
302 #ifndef OPTIMIZED_SAMP_MESSAGE
303 void
304 target_if_spectral_create_samp_msg(struct target_if_spectral *spectral,
305 				   struct target_if_samp_msg_params *params)
306 {
307 	/*
308 	 * XXX : Non-Rentrant. Will be an issue with dual concurrent
309 	 *       operation on multi-processor system
310 	 */
311 
312 	struct spectral_samp_msg *spec_samp_msg = NULL;
313 
314 	uint8_t *bin_pwr_data = NULL;
315 	struct spectral_classifier_params *cp = NULL;
316 	struct spectral_classifier_params *pcp = NULL;
317 	struct target_if_spectral_ops *p_sops = NULL;
318 	uint32_t *binptr_32 = NULL;
319 	uint16_t *binptr_16 = NULL;
320 	uint16_t pwr_16;
321 	int idx = 0;
322 	struct spectral_samp_data *samp_data;
323 	static int samp_msg_index;
324 	size_t pwr_count = 0;
325 	size_t pwr_count_sec80 = 0;
326 	size_t pwr_count_5mhz = 0;
327 	enum spectral_msg_type msg_type;
328 	QDF_STATUS ret;
329 	struct spectral_fft_bin_len_adj_swar *swar = &spectral->len_adj_swar;
330 
331 	ret = target_if_get_spectral_msg_type(params->smode, &msg_type);
332 	if (QDF_IS_STATUS_ERROR(ret))
333 		return;
334 
335 	if (is_primaryseg_rx_inprog(spectral, params->smode)) {
336 		spec_samp_msg  = (struct spectral_samp_msg *)
337 		      spectral->nl_cb.get_sbuff(spectral->pdev_obj,
338 						msg_type,
339 						SPECTRAL_MSG_BUF_NEW);
340 
341 		if (!spec_samp_msg)
342 			return;
343 
344 		samp_data = &spec_samp_msg->samp_data;
345 		p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
346 		bin_pwr_data = params->bin_pwr_data;
347 
348 		spec_samp_msg->signature = SPECTRAL_SIGNATURE;
349 		spec_samp_msg->freq = params->freq;
350 		spec_samp_msg->agile_freq1 = params->agile_freq1;
351 		spec_samp_msg->agile_freq2 = params->agile_freq2;
352 		spec_samp_msg->freq_loading = params->freq_loading;
353 		spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1;
354 		spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2;
355 		samp_data->spectral_mode = params->smode;
356 		samp_data->spectral_data_len = params->datalen;
357 		samp_data->spectral_rssi = params->rssi;
358 		samp_data->ch_width =
359 				spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
360 		samp_data->agile_ch_width =
361 				spectral->ch_width[SPECTRAL_SCAN_MODE_AGILE];
362 		samp_data->spectral_agc_total_gain = params->agc_total_gain;
363 		samp_data->spectral_gainchange = params->gainchange;
364 		samp_data->spectral_pri80ind = params->pri80ind;
365 		samp_data->last_raw_timestamp = params->last_raw_timestamp;
366 		samp_data->timestamp_war_offset = params->timestamp_war_offset;
367 		samp_data->raw_timestamp = params->raw_timestamp;
368 		samp_data->reset_delay = params->reset_delay;
369 		samp_data->target_reset_count = params->target_reset_count;
370 
371 		samp_data->spectral_combined_rssi =
372 		    (uint8_t)params->rssi;
373 		samp_data->spectral_upper_rssi = params->upper_rssi;
374 		samp_data->spectral_lower_rssi = params->lower_rssi;
375 
376 		qdf_mem_copy(samp_data->spectral_chain_ctl_rssi,
377 			     params->chain_ctl_rssi,
378 			     sizeof(params->chain_ctl_rssi));
379 		qdf_mem_copy(samp_data->spectral_chain_ext_rssi,
380 			     params->chain_ext_rssi,
381 			     sizeof(params->chain_ext_rssi));
382 
383 		samp_data->spectral_bwinfo = params->bwinfo;
384 		samp_data->spectral_tstamp = params->tstamp;
385 		samp_data->spectral_max_index = params->max_index;
386 
387 		/* Classifier in user space needs access to these */
388 		samp_data->spectral_lower_max_index =
389 		    params->max_lower_index;
390 		samp_data->spectral_upper_max_index =
391 		    params->max_upper_index;
392 		samp_data->spectral_nb_lower = params->nb_lower;
393 		samp_data->spectral_nb_upper = params->nb_upper;
394 		samp_data->spectral_last_tstamp = params->last_tstamp;
395 		samp_data->spectral_max_mag = params->max_mag;
396 
397 		/*
398 		 * Currently, we compute pwr_count considering the size of the
399 		 * samp_data->bin_pwr array rather than the number of elements
400 		 * in this array. The reasons are that
401 		 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count will be
402 		 * used maps directly to OS_MEMCPY() on little endian platforms,
403 		 * and that samp_data->bin_pwr is an array of u_int8_t elements
404 		 * due to which the number of elements in the array == the size
405 		 * of the array. In case FFT bin size is increased from 8 bits
406 		 * in the future, this code would have to be changed along with
407 		 * rest of framework on which it depends.
408 		 */
409 		pwr_count = qdf_min((size_t)params->pwr_count,
410 				    sizeof(samp_data->bin_pwr));
411 
412 		samp_data->bin_pwr_count = pwr_count;
413 		samp_data->lb_edge_extrabins =
414 			spectral->lb_edge_extrabins;
415 		samp_data->rb_edge_extrabins =
416 			spectral->rb_edge_extrabins;
417 		samp_data->spectral_combined_rssi = params->rssi;
418 		samp_data->spectral_max_scale = params->max_exp;
419 
420 		samp_data->noise_floor = params->noise_floor;
421 
422 		/* Classifier in user space needs access to these */
423 		cp = &samp_data->classifier_params;
424 		pcp = &params->classifier_params;
425 
426 		qdf_mem_copy(cp, pcp,
427 			     sizeof(struct spectral_classifier_params));
428 
429 		/*
430 		 * To check whether FFT bin values exceed 8 bits, we add a
431 		 * check before copying values to samp_data->bin_pwr.
432 		 * If it crosses 8 bits, we cap the values to maximum value
433 		 * supported by 8 bits ie. 255. This needs to be done as the
434 		 * destination array in SAMP message is 8 bits. This is a
435 		 * temporary solution till an array of 16 bits is used for
436 		 * SAMP message.
437 		 */
438 		if (swar->fftbin_size_war ==
439 				SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
440 			binptr_32 = (uint32_t *)bin_pwr_data;
441 			for (idx = 0; idx < pwr_count; idx++) {
442 				/* Read only the first 2 bytes of the DWORD */
443 				pwr_16 = *((uint16_t *)binptr_32++);
444 				if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
445 					pwr_16 = MAX_FFTBIN_VALUE;
446 				samp_data->bin_pwr[idx] = pwr_16;
447 			}
448 		} else if (swar->fftbin_size_war ==
449 				SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
450 			binptr_16 = (uint16_t *)bin_pwr_data;
451 			for (idx = 0; idx < pwr_count; idx++) {
452 				pwr_16 = *(binptr_16++);
453 				if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
454 					pwr_16 = MAX_FFTBIN_VALUE;
455 				samp_data->bin_pwr[idx] = pwr_16;
456 			}
457 		} else {
458 			SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
459 					&samp_data->bin_pwr[0], bin_pwr_data,
460 					pwr_count);
461 		}
462 
463 		p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
464 	}
465 
466 	if (is_secondaryseg_rx_inprog(spectral, params->smode)) {
467 		spec_samp_msg  = (struct spectral_samp_msg *)
468 		      spectral->nl_cb.get_sbuff(spectral->pdev_obj,
469 						msg_type,
470 						SPECTRAL_MSG_BUF_SAVED);
471 
472 		if (!spec_samp_msg) {
473 			spectral_err("Spectral SAMP message is NULL");
474 			return;
475 		}
476 
477 		samp_data = &spec_samp_msg->samp_data;
478 		samp_data->spectral_rssi_sec80 =
479 		    params->rssi_sec80;
480 		samp_data->noise_floor_sec80 =
481 		    params->noise_floor_sec80;
482 		spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 =
483 			params->agc_total_gain_sec80;
484 		spec_samp_msg->samp_data.spectral_gainchange_sec80 =
485 			params->gainchange_sec80;
486 		spec_samp_msg->samp_data.spectral_pri80ind_sec80 =
487 			params->pri80ind_sec80;
488 
489 		samp_data->spectral_data_len_sec80 =
490 		    params->datalen_sec80;
491 		samp_data->spectral_max_index_sec80 =
492 		    params->max_index_sec80;
493 		samp_data->spectral_max_mag_sec80 =
494 		    params->max_mag_sec80;
495 
496 		samp_data->raw_timestamp_sec80 = params->raw_timestamp_sec80;
497 
498 		/*
499 		 * Currently, we compute pwr_count_sec80 considering the size of
500 		 * the samp_data->bin_pwr_sec80 array rather than the number of
501 		 * elements in this array. The reasons are that
502 		 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count_sec80 will
503 		 * be used maps directly to OS_MEMCPY() on little endian
504 		 * platforms, and that samp_data->bin_pwr_sec80 is an array of
505 		 * u_int8_t elements due to which the number of elements in the
506 		 * array == the size of the array. In case FFT bin size is
507 		 * increased from 8 bits in the future, this code would have to
508 		 * be changed along with rest of framework on which it depends.
509 		 */
510 		pwr_count_sec80 = qdf_min((size_t)params->pwr_count_sec80,
511 					  sizeof(samp_data->bin_pwr_sec80));
512 		pwr_count_5mhz = qdf_min((size_t)params->pwr_count_5mhz,
513 					 sizeof(samp_data->bin_pwr_5mhz));
514 
515 		samp_data->bin_pwr_count_sec80 = pwr_count_sec80;
516 		samp_data->bin_pwr_count_5mhz = pwr_count_5mhz;
517 
518 		bin_pwr_data = params->bin_pwr_data_sec80;
519 
520 		/*
521 		 * To check whether FFT bin values exceed 8 bits, we add a
522 		 * check before copying values to samp_data->bin_pwr_sec80.
523 		 * If it crosses 8 bits, we cap the values to maximum value
524 		 * supported by 8 bits ie. 255. This needs to be done as the
525 		 * destination array in SAMP message is 8 bits. This is a
526 		 * temporary solution till an array of 16 bits is used for
527 		 * SAMP message.
528 		 */
529 		if (swar->fftbin_size_war ==
530 				SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
531 			binptr_32 = (uint32_t *)bin_pwr_data;
532 			for (idx = 0; idx < pwr_count_sec80; idx++) {
533 				/* Read only the first 2 bytes of the DWORD */
534 				pwr_16 = *((uint16_t *)binptr_32++);
535 				if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
536 					pwr_16 = MAX_FFTBIN_VALUE;
537 				samp_data->bin_pwr_sec80[idx] = pwr_16;
538 			}
539 		} else if (swar->fftbin_size_war ==
540 				SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
541 			binptr_16 = (uint16_t *)bin_pwr_data;
542 			for (idx = 0; idx < pwr_count_sec80; idx++) {
543 				pwr_16 = *(binptr_16++);
544 				if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
545 					pwr_16 = MAX_FFTBIN_VALUE;
546 				samp_data->bin_pwr_sec80[idx] = pwr_16;
547 			}
548 
549 			binptr_16 = (uint16_t *)params->bin_pwr_data_5mhz;
550 			for (idx = 0; idx < pwr_count_5mhz; idx++) {
551 				pwr_16 = *(binptr_16++);
552 				if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
553 					pwr_16 = MAX_FFTBIN_VALUE;
554 				samp_data->bin_pwr_5mhz[idx] = pwr_16;
555 			}
556 		} else {
557 			SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
558 					&samp_data->bin_pwr_sec80[0],
559 					params->bin_pwr_data_sec80,
560 					pwr_count_sec80);
561 		}
562 	}
563 
564 	if (!is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) ||
565 	    is_secondaryseg_rx_inprog(spectral, params->smode)) {
566 		if (spectral->send_phy_data(spectral->pdev_obj,
567 					    msg_type) == 0)
568 			spectral->spectral_sent_msg++;
569 		samp_msg_index++;
570 	}
571 
572 	/* Take care of state transitions for 160MHz/ 80p80 */
573 	if (spectral->spectral_gen == SPECTRAL_GEN3 &&
574 	    is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) &&
575 	    spectral->rparams.fragmentation_160[params->smode])
576 		target_if_160mhz_delivery_state_change(
577 				spectral, params->smode,
578 				SPECTRAL_DETECTOR_ID_INVALID);
579 }
580 #endif
581