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 ¶ms->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.ch_width = spectral->ch_width; 158 159 spec_samp_msg->samp_data.spectral_combined_rssi = 160 (uint8_t)params->rssi; 161 spec_samp_msg->samp_data.spectral_upper_rssi = params->upper_rssi; 162 spec_samp_msg->samp_data.spectral_lower_rssi = params->lower_rssi; 163 164 OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ctl_rssi, 165 params->chain_ctl_rssi, sizeof(params->chain_ctl_rssi)); 166 OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ext_rssi, 167 params->chain_ext_rssi, sizeof(params->chain_ext_rssi)); 168 169 spec_samp_msg->samp_data.spectral_bwinfo = params->bwinfo; 170 spec_samp_msg->samp_data.spectral_tstamp = params->tstamp; 171 spec_samp_msg->samp_data.spectral_max_index = params->max_index; 172 173 /* Classifier in user space needs access to these */ 174 spec_samp_msg->samp_data.spectral_lower_max_index = 175 params->max_lower_index; 176 spec_samp_msg->samp_data.spectral_upper_max_index = 177 params->max_upper_index; 178 spec_samp_msg->samp_data.spectral_nb_lower = params->nb_lower; 179 spec_samp_msg->samp_data.spectral_nb_upper = params->nb_upper; 180 spec_samp_msg->samp_data.spectral_last_tstamp = params->last_tstamp; 181 spec_samp_msg->samp_data.spectral_max_mag = params->max_mag; 182 spec_samp_msg->samp_data.bin_pwr_count = params->pwr_count; 183 spec_samp_msg->samp_data.lb_edge_extrabins = 184 spectral->lb_edge_extrabins; 185 spec_samp_msg->samp_data.rb_edge_extrabins = 186 spectral->rb_edge_extrabins; 187 spec_samp_msg->samp_data.spectral_combined_rssi = params->rssi; 188 spec_samp_msg->samp_data.spectral_max_scale = params->max_exp; 189 190 /* 191 * This is a dirty hack to get the Windows build pass. 192 * Currently Windows and Linux builds source spectral_data.h 193 * form two different place. The windows version do not 194 * have noise_floor member in it. 195 * 196 * As a temp workaround this variable is set under the 197 * SPECTRAL_USE_NETLINK_SOCKETS as this is called only 198 * under the linux build and this saves the day 199 * 200 * The plan to sync of header files in under the way 201 * 202 */ 203 204 spec_samp_msg->samp_data.noise_floor = params->noise_floor; 205 206 /* Classifier in user space needs access to these */ 207 cp = &spec_samp_msg->samp_data.classifier_params; 208 pcp = ¶ms->classifier_params; 209 210 OS_MEMCPY(cp, pcp, sizeof(struct spectral_classifier_params)); 211 212 if (spectral->fftbin_size_war) { 213 binptr = (uint32_t *)bin_pwr_data; 214 for (idx = 0; idx < params->pwr_count; idx++) 215 data->bin_pwr[idx] = *(binptr++); 216 } else { 217 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr[0], 218 bin_pwr_data, params->pwr_count); 219 } 220 221 spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1; 222 spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2; 223 224 if (spectral->ch_width == CH_WIDTH_160MHZ) { 225 spec_samp_msg->samp_data.spectral_rssi_sec80 = 226 params->rssi_sec80; 227 spec_samp_msg->samp_data.noise_floor_sec80 = 228 params->noise_floor_sec80; 229 230 spec_samp_msg->samp_data.spectral_data_len_sec80 = 231 params->datalen_sec80; 232 spec_samp_msg->samp_data.spectral_max_index_sec80 = 233 params->max_index_sec80; 234 spec_samp_msg->samp_data.spectral_max_mag_sec80 = 235 params->max_mag_sec80; 236 spec_samp_msg->samp_data.bin_pwr_count_sec80 = 237 params->pwr_count_sec80; 238 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr_sec80[0], 239 (params->bin_pwr_data_sec80), 240 params->pwr_count_sec80); 241 242 /* 243 * Note: REVERSE_ORDER is not a known use case for 244 * secondary 80 data at this point. 245 */ 246 } 247 248 target_if_spectral_init_interf_list(data, params); 249 p_sops->get_mac_address(spectral, spec_samp_msg->macaddr); 250 251 if (spectral->sc_spectral_noise_pwr_cal) 252 target_if_spectral_process_noise_pwr_report( 253 spectral, spec_samp_msg); 254 255 if (spectral->send_phy_data(spectral->pdev_obj) == 0) 256 spectral->spectral_sent_msg++; 257 258 samp_msg_index++; 259 } 260