xref: /wlan-dirver/qca-wifi-host-cmn/target_if/spectral/target_if_spectral_netlink.c (revision 1b9674e21e24478fba4530f5ae7396b9555e9c6a)
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 static void
31 target_if_spectral_process_noise_pwr_report(
32 	struct target_if_spectral *spectral,
33 	const struct spectral_samp_msg *spec_samp_msg)
34 {
35 	int i, done;
36 
37 	qdf_spin_lock(&spectral->noise_pwr_reports_lock);
38 
39 	if (!spectral->noise_pwr_reports_reqd) {
40 		qdf_spin_unlock(&spectral->noise_pwr_reports_lock);
41 		return;
42 	}
43 
44 	if (spectral->noise_pwr_reports_recv <
45 	    spectral->noise_pwr_reports_reqd) {
46 		spectral->noise_pwr_reports_recv++;
47 
48 		for (i = 0; i < HOST_MAX_ANTENNA; i++) {
49 			uint32_t index;
50 
51 			if (spectral->noise_pwr_chain_ctl[i]) {
52 				index =
53 				    spectral->noise_pwr_chain_ctl[i]->
54 				    rptcount++;
55 				spectral->noise_pwr_chain_ctl[i]->pwr[index] =
56 				    spec_samp_msg->samp_data.
57 				    spectral_chain_ctl_rssi[i];
58 			}
59 			if (spectral->noise_pwr_chain_ext[i]) {
60 				index =
61 				    spectral->noise_pwr_chain_ext[i]->
62 				    rptcount++;
63 				spectral->noise_pwr_chain_ext[i]->pwr[index] =
64 				    spec_samp_msg->samp_data.
65 				    spectral_chain_ext_rssi[i];
66 			}
67 		}
68 	}
69 
70 	done = (spectral->noise_pwr_reports_recv >=
71 		spectral->noise_pwr_reports_reqd);
72 
73 	qdf_spin_unlock(&spectral->noise_pwr_reports_lock);
74 
75 	if (done) {
76 		qdf_spin_lock(&spectral->spectral_lock);
77 		target_if_stop_spectral_scan(spectral->pdev_obj);
78 		spectral->sc_spectral_scan = 0;
79 		qdf_spin_unlock(&spectral->spectral_lock);
80 	}
81 }
82 
83 /*
84  * Function     : spectral_create_samp_msg
85  * Description  : create SAMP message and send it host
86  * Input        :
87  * Output       :
88  *
89  */
90 
91 #ifdef SPECTRAL_CLASSIFIER_IN_KERNEL
92 static void
93 target_if_spectral_init_interf_list(
94 	struct spectral_samp_data *data,
95 	struct target_if_samp_msg_params *params)
96 {
97 	if (params->interf_list.count)
98 		OS_MEMCPY(&data->interf_list,
99 			  &params->interf_list, sizeof(struct interf_src_rsp));
100 	else
101 		data->interf_list.count = 0;
102 }
103 #else
104 static void
105 target_if_spectral_init_interf_list(
106 	struct spectral_samp_data *data,
107 	struct target_if_samp_msg_params *params)
108 {
109 	data->interf_list.count = 0;
110 }
111 #endif
112 
113 void
114 target_if_spectral_create_samp_msg(struct target_if_spectral *spectral,
115 				   struct target_if_samp_msg_params *params)
116 {
117 	/*
118 	 * XXX : Non-Rentrant. Will be an issue with dual concurrent
119 	 *       operation on multi-processor system
120 	 */
121 
122 	int temp_samp_msg_len = 0;
123 
124 	struct spectral_samp_msg *spec_samp_msg;
125 
126 	struct spectral_samp_data *data = NULL;
127 	uint8_t *bin_pwr_data = NULL;
128 	struct spectral_classifier_params *cp = NULL;
129 	struct spectral_classifier_params *pcp = NULL;
130 	struct target_if_spectral_ops *p_sops = NULL;
131 	uint32_t *binptr = NULL;
132 	int idx = 0;
133 
134 	static int samp_msg_index;
135 
136 	spec_samp_msg  = (struct spectral_samp_msg *)spectral->nl_cb.get_nbuff(
137 				spectral->pdev_obj);
138 	if (!spec_samp_msg)
139 		return;
140 
141 	p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
142 	temp_samp_msg_len = sizeof(struct spectral_samp_msg) -
143 	    (MAX_NUM_BINS * sizeof(uint8_t));
144 	temp_samp_msg_len += (params->pwr_count * sizeof(uint8_t));
145 	if (spectral->ch_width == CH_WIDTH_160MHZ)
146 		temp_samp_msg_len +=
147 		    (params->pwr_count_sec80 * sizeof(uint8_t));
148 	bin_pwr_data = params->bin_pwr_data;
149 
150 	data = &spec_samp_msg->samp_data;
151 
152 	spec_samp_msg->signature = SPECTRAL_SIGNATURE;
153 	spec_samp_msg->freq = params->freq;
154 	spec_samp_msg->freq_loading = params->freq_loading;
155 	spec_samp_msg->samp_data.spectral_data_len = params->datalen;
156 	spec_samp_msg->samp_data.spectral_rssi = params->rssi;
157 	spec_samp_msg->samp_data.spectral_agc_total_gain =
158 			params->agc_total_gain;
159 	spec_samp_msg->samp_data.spectral_gainchange = params->gainchange;
160 	spec_samp_msg->samp_data.ch_width = spectral->ch_width;
161 
162 	spec_samp_msg->samp_data.spectral_combined_rssi =
163 	    (uint8_t)params->rssi;
164 	spec_samp_msg->samp_data.spectral_upper_rssi = params->upper_rssi;
165 	spec_samp_msg->samp_data.spectral_lower_rssi = params->lower_rssi;
166 
167 	OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ctl_rssi,
168 		  params->chain_ctl_rssi, sizeof(params->chain_ctl_rssi));
169 	OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ext_rssi,
170 		  params->chain_ext_rssi, sizeof(params->chain_ext_rssi));
171 
172 	spec_samp_msg->samp_data.spectral_bwinfo = params->bwinfo;
173 	spec_samp_msg->samp_data.spectral_tstamp = params->tstamp;
174 	spec_samp_msg->samp_data.spectral_max_index = params->max_index;
175 
176 	/* Classifier in user space needs access to these */
177 	spec_samp_msg->samp_data.spectral_lower_max_index =
178 	    params->max_lower_index;
179 	spec_samp_msg->samp_data.spectral_upper_max_index =
180 	    params->max_upper_index;
181 	spec_samp_msg->samp_data.spectral_nb_lower = params->nb_lower;
182 	spec_samp_msg->samp_data.spectral_nb_upper = params->nb_upper;
183 	spec_samp_msg->samp_data.spectral_last_tstamp = params->last_tstamp;
184 	spec_samp_msg->samp_data.spectral_max_mag = params->max_mag;
185 	spec_samp_msg->samp_data.bin_pwr_count = params->pwr_count;
186 	spec_samp_msg->samp_data.lb_edge_extrabins =
187 		spectral->lb_edge_extrabins;
188 	spec_samp_msg->samp_data.rb_edge_extrabins =
189 		spectral->rb_edge_extrabins;
190 	spec_samp_msg->samp_data.spectral_combined_rssi = params->rssi;
191 	spec_samp_msg->samp_data.spectral_max_scale = params->max_exp;
192 
193 	/*
194 	 * This is a dirty hack to get the Windows build pass.
195 	 * Currently Windows and Linux builds source spectral_data.h
196 	 * form two different place. The windows version do not
197 	 * have noise_floor member in it.
198 	 *
199 	 * As a temp workaround this variable is set under the
200 	 * SPECTRAL_USE_NETLINK_SOCKETS as this is called only
201 	 * under the linux build and this saves the day
202 	 *
203 	 * The plan to sync of header files in under the way
204 	 *
205 	 */
206 
207 	spec_samp_msg->samp_data.noise_floor = params->noise_floor;
208 
209 	/* Classifier in user space needs access to these */
210 	cp = &spec_samp_msg->samp_data.classifier_params;
211 	pcp = &params->classifier_params;
212 
213 	OS_MEMCPY(cp, pcp, sizeof(struct spectral_classifier_params));
214 
215 	if (spectral->fftbin_size_war) {
216 		binptr = (uint32_t *)bin_pwr_data;
217 		for (idx = 0; idx < params->pwr_count; idx++)
218 			data->bin_pwr[idx] = *(binptr++);
219 	} else {
220 		SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr[0],
221 					 bin_pwr_data, params->pwr_count);
222 	}
223 
224 	spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1;
225 	spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2;
226 
227 	if (spectral->ch_width == CH_WIDTH_160MHZ) {
228 		spec_samp_msg->samp_data.spectral_rssi_sec80 =
229 		    params->rssi_sec80;
230 		spec_samp_msg->samp_data.noise_floor_sec80 =
231 		    params->noise_floor_sec80;
232 		spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 =
233 			params->agc_total_gain_sec80;
234 		spec_samp_msg->samp_data.spectral_gainchange_sec80 =
235 			params->gainchange_sec80;
236 
237 		spec_samp_msg->samp_data.spectral_data_len_sec80 =
238 		    params->datalen_sec80;
239 		spec_samp_msg->samp_data.spectral_max_index_sec80 =
240 		    params->max_index_sec80;
241 		spec_samp_msg->samp_data.spectral_max_mag_sec80 =
242 		    params->max_mag_sec80;
243 		spec_samp_msg->samp_data.bin_pwr_count_sec80 =
244 		    params->pwr_count_sec80;
245 		SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr_sec80[0],
246 						 (params->bin_pwr_data_sec80),
247 						 params->pwr_count_sec80);
248 
249 		/*
250 		 * Note: REVERSE_ORDER is not a known use case for
251 		 * secondary 80 data at this point.
252 		 */
253 	}
254 
255 	target_if_spectral_init_interf_list(data, params);
256 	p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
257 
258 	if (spectral->sc_spectral_noise_pwr_cal)
259 		target_if_spectral_process_noise_pwr_report(
260 			spectral, spec_samp_msg);
261 
262 	if (spectral->send_phy_data(spectral->pdev_obj) == 0)
263 		spectral->spectral_sent_msg++;
264 
265 	samp_msg_index++;
266 }
267