xref: /wlan-dirver/qca-wifi-host-cmn/target_if/spectral/target_if_spectral_netlink.c (revision 1f55ed1a9f5050d8da228aa8dd3fff7c0242aa71)
1 /*
2  * Copyright (c) 2011,2017-2018 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 #include <osdep.h>
21 #include <wlan_tgt_def_config.h>
22 #include <hif.h>
23 #include <hif_hw_version.h>
24 #include <wmi_unified_api.h>
25 #include <target_if_spectral.h>
26 #include <wlan_lmac_if_def.h>
27 #include <wlan_osif_priv.h>
28 #include <reg_services_public_struct.h>
29 
30 void
31 target_if_spectral_create_samp_msg(struct target_if_spectral *spectral,
32 				   struct target_if_samp_msg_params *params)
33 {
34 	/*
35 	 * XXX : Non-Rentrant. Will be an issue with dual concurrent
36 	 *       operation on multi-processor system
37 	 */
38 
39 	struct spectral_samp_msg *spec_samp_msg = NULL;
40 
41 	uint8_t *bin_pwr_data = NULL;
42 	struct spectral_classifier_params *cp = NULL;
43 	struct spectral_classifier_params *pcp = NULL;
44 	struct target_if_spectral_ops *p_sops = NULL;
45 	uint32_t *binptr_32 = NULL;
46 	uint16_t *binptr_16 = NULL;
47 	int idx = 0;
48 	struct spectral_samp_data *samp_data;
49 	static int samp_msg_index;
50 	size_t pwr_count = 0;
51 	size_t pwr_count_sec80 = 0;
52 
53 	if (is_primaryseg_rx_inprog(spectral)) {
54 		spec_samp_msg  = (struct spectral_samp_msg *)
55 			spectral->nl_cb.get_nbuff(spectral->pdev_obj);
56 
57 		if (!spec_samp_msg)
58 			return;
59 
60 		samp_data = &spec_samp_msg->samp_data;
61 		if (spectral->spectral_gen == SPECTRAL_GEN3)
62 			save_spectral_report_skb(spectral, spec_samp_msg);
63 		p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
64 		bin_pwr_data = params->bin_pwr_data;
65 
66 		spec_samp_msg->signature = SPECTRAL_SIGNATURE;
67 		spec_samp_msg->freq = params->freq;
68 		spec_samp_msg->freq_loading = params->freq_loading;
69 		samp_data->spectral_data_len = params->datalen;
70 		samp_data->spectral_rssi = params->rssi;
71 		samp_data->ch_width = spectral->ch_width;
72 		samp_data->spectral_agc_total_gain = params->agc_total_gain;
73 		samp_data->spectral_gainchange = params->gainchange;
74 
75 		samp_data->spectral_combined_rssi =
76 		    (uint8_t)params->rssi;
77 		samp_data->spectral_upper_rssi = params->upper_rssi;
78 		samp_data->spectral_lower_rssi = params->lower_rssi;
79 
80 		qdf_mem_copy(samp_data->spectral_chain_ctl_rssi,
81 			     params->chain_ctl_rssi,
82 			     sizeof(params->chain_ctl_rssi));
83 		qdf_mem_copy(samp_data->spectral_chain_ext_rssi,
84 			     params->chain_ext_rssi,
85 			     sizeof(params->chain_ext_rssi));
86 
87 		samp_data->spectral_bwinfo = params->bwinfo;
88 		samp_data->spectral_tstamp = params->tstamp;
89 		samp_data->spectral_max_index = params->max_index;
90 
91 		/* Classifier in user space needs access to these */
92 		samp_data->spectral_lower_max_index =
93 		    params->max_lower_index;
94 		samp_data->spectral_upper_max_index =
95 		    params->max_upper_index;
96 		samp_data->spectral_nb_lower = params->nb_lower;
97 		samp_data->spectral_nb_upper = params->nb_upper;
98 		samp_data->spectral_last_tstamp = params->last_tstamp;
99 		samp_data->spectral_max_mag = params->max_mag;
100 
101 		/*
102 		 * Currently, we compute pwr_count considering the size of the
103 		 * samp_data->bin_pwr array rather than the number of elements
104 		 * in this array. The reasons are that
105 		 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count will be
106 		 * used maps directly to OS_MEMCPY() on little endian platforms,
107 		 * and that samp_data->bin_pwr is an array of u_int8_t elements
108 		 * due to which the number of elements in the array == the size
109 		 * of the array. In case FFT bin size is increased from 8 bits
110 		 * in the future, this code would have to be changed along with
111 		 * rest of framework on which it depends.
112 		 */
113 		pwr_count = qdf_min((size_t)params->pwr_count,
114 				    sizeof(samp_data->bin_pwr));
115 
116 		samp_data->bin_pwr_count = pwr_count;
117 		samp_data->lb_edge_extrabins =
118 			spectral->lb_edge_extrabins;
119 		samp_data->rb_edge_extrabins =
120 			spectral->rb_edge_extrabins;
121 		samp_data->spectral_combined_rssi = params->rssi;
122 		samp_data->spectral_max_scale = params->max_exp;
123 
124 		samp_data->noise_floor = params->noise_floor;
125 
126 		/* Classifier in user space needs access to these */
127 		cp = &samp_data->classifier_params;
128 		pcp = &params->classifier_params;
129 
130 		qdf_mem_copy(cp, pcp,
131 			     sizeof(struct spectral_classifier_params));
132 
133 		if (spectral->fftbin_size_war ==
134 				SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
135 			binptr_32 = (uint32_t *)bin_pwr_data;
136 			for (idx = 0; idx < pwr_count; idx++)
137 				samp_data->bin_pwr[idx] = *(binptr_32++);
138 		} else if (spectral->fftbin_size_war ==
139 				SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
140 			binptr_16 = (uint16_t *)bin_pwr_data;
141 			for (idx = 0; idx < pwr_count; idx++)
142 				samp_data->bin_pwr[idx] = *(binptr_16++);
143 		} else {
144 			SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
145 					&samp_data->bin_pwr[0], bin_pwr_data,
146 					pwr_count);
147 		}
148 
149 		p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
150 	}
151 
152 	if (is_secondaryseg_rx_inprog(spectral)) {
153 		if (spectral->spectral_gen == SPECTRAL_GEN3)
154 			restore_spectral_report_skb(spectral,
155 						    (void **)&spec_samp_msg);
156 		if (!spec_samp_msg) {
157 			spectral_err("Spectral SAMP message is NULL");
158 			return;
159 		}
160 
161 		samp_data = &spec_samp_msg->samp_data;
162 		spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1;
163 		spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2;
164 		samp_data->spectral_rssi_sec80 =
165 		    params->rssi_sec80;
166 		samp_data->noise_floor_sec80 =
167 		    params->noise_floor_sec80;
168 		spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 =
169 			params->agc_total_gain_sec80;
170 		spec_samp_msg->samp_data.spectral_gainchange_sec80 =
171 			params->gainchange_sec80;
172 
173 		samp_data->spectral_data_len_sec80 =
174 		    params->datalen_sec80;
175 		samp_data->spectral_max_index_sec80 =
176 		    params->max_index_sec80;
177 		samp_data->spectral_max_mag_sec80 =
178 		    params->max_mag_sec80;
179 
180 		/*
181 		 * Currently, we compute pwr_count_sec80 considering the size of
182 		 * the samp_data->bin_pwr_sec80 array rather than the number of
183 		 * elements in this array. The reasons are that
184 		 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count_sec80 will
185 		 * be used maps directly to OS_MEMCPY() on little endian
186 		 * platforms, and that samp_data->bin_pwr_sec80 is an array of
187 		 * u_int8_t elements due to which the number of elements in the
188 		 * array == the size of the array. In case FFT bin size is
189 		 * increased from 8 bits in the future, this code would have to
190 		 * be changed along with rest of framework on which it depends.
191 		 */
192 		pwr_count_sec80 = qdf_min((size_t)params->pwr_count_sec80,
193 					  sizeof(samp_data->bin_pwr_sec80));
194 
195 		samp_data->bin_pwr_count_sec80 = pwr_count_sec80;
196 
197 		bin_pwr_data = params->bin_pwr_data_sec80;
198 		if (spectral->fftbin_size_war ==
199 				SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
200 			binptr_32 = (uint32_t *)bin_pwr_data;
201 			for (idx = 0; idx < pwr_count_sec80; idx++)
202 				samp_data->bin_pwr_sec80[idx] = *(binptr_32++);
203 		} else if (spectral->fftbin_size_war ==
204 				SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
205 			binptr_16 = (uint16_t *)bin_pwr_data;
206 			for (idx = 0; idx < pwr_count_sec80; idx++)
207 				samp_data->bin_pwr_sec80[idx] = *(binptr_16++);
208 		} else {
209 			SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
210 					&samp_data->bin_pwr_sec80[0],
211 					params->bin_pwr_data_sec80,
212 					pwr_count_sec80);
213 		}
214 	}
215 
216 	if ((spectral->ch_width != CH_WIDTH_160MHZ) ||
217 	    is_secondaryseg_rx_inprog(spectral)) {
218 		if (spectral->send_phy_data(spectral->pdev_obj) == 0)
219 			spectral->spectral_sent_msg++;
220 		samp_msg_index++;
221 		if (spectral->spectral_gen == SPECTRAL_GEN3)
222 			clear_spectral_report_skb(spectral);
223 	}
224 
225 	/* Take care of state transitions for 160MHz/ 80p80 */
226 	if (spectral->spectral_gen == SPECTRAL_GEN3)
227 		target_if_160mhz_delivery_state_change(
228 				spectral,
229 				SPECTRAL_REPORT_EVENT_DETECTORID_INVALID);
230 }
231