1 /* 2 * Copyright (c) 2011,2017-2020 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 uint16_t pwr_16; 48 int idx = 0; 49 struct spectral_samp_data *samp_data; 50 static int samp_msg_index; 51 size_t pwr_count = 0; 52 size_t pwr_count_sec80 = 0; 53 size_t pwr_count_5mhz = 0; 54 enum spectral_msg_type msg_type; 55 QDF_STATUS ret; 56 struct spectral_fft_bin_len_adj_swar *swar = &spectral->len_adj_swar; 57 58 ret = target_if_get_spectral_msg_type(params->smode, &msg_type); 59 if (QDF_IS_STATUS_ERROR(ret)) 60 return; 61 62 if (is_primaryseg_rx_inprog(spectral, params->smode)) { 63 spec_samp_msg = (struct spectral_samp_msg *) 64 spectral->nl_cb.get_sbuff(spectral->pdev_obj, 65 msg_type, 66 SPECTRAL_MSG_BUF_NEW); 67 68 if (!spec_samp_msg) 69 return; 70 71 samp_data = &spec_samp_msg->samp_data; 72 p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral); 73 bin_pwr_data = params->bin_pwr_data; 74 75 spec_samp_msg->signature = SPECTRAL_SIGNATURE; 76 spec_samp_msg->freq = params->freq; 77 spec_samp_msg->agile_freq1 = params->agile_freq1; 78 spec_samp_msg->agile_freq2 = params->agile_freq2; 79 spec_samp_msg->freq_loading = params->freq_loading; 80 spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1; 81 spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2; 82 samp_data->spectral_mode = params->smode; 83 samp_data->spectral_data_len = params->datalen; 84 samp_data->spectral_rssi = params->rssi; 85 samp_data->ch_width = 86 spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL]; 87 samp_data->agile_ch_width = 88 spectral->ch_width[SPECTRAL_SCAN_MODE_AGILE]; 89 samp_data->spectral_agc_total_gain = params->agc_total_gain; 90 samp_data->spectral_gainchange = params->gainchange; 91 samp_data->spectral_pri80ind = params->pri80ind; 92 samp_data->last_raw_timestamp = params->last_raw_timestamp; 93 samp_data->timestamp_war_offset = params->timestamp_war_offset; 94 samp_data->raw_timestamp = params->raw_timestamp; 95 samp_data->reset_delay = params->reset_delay; 96 samp_data->target_reset_count = params->target_reset_count; 97 98 samp_data->spectral_combined_rssi = 99 (uint8_t)params->rssi; 100 samp_data->spectral_upper_rssi = params->upper_rssi; 101 samp_data->spectral_lower_rssi = params->lower_rssi; 102 103 qdf_mem_copy(samp_data->spectral_chain_ctl_rssi, 104 params->chain_ctl_rssi, 105 sizeof(params->chain_ctl_rssi)); 106 qdf_mem_copy(samp_data->spectral_chain_ext_rssi, 107 params->chain_ext_rssi, 108 sizeof(params->chain_ext_rssi)); 109 110 samp_data->spectral_bwinfo = params->bwinfo; 111 samp_data->spectral_tstamp = params->tstamp; 112 samp_data->spectral_max_index = params->max_index; 113 114 /* Classifier in user space needs access to these */ 115 samp_data->spectral_lower_max_index = 116 params->max_lower_index; 117 samp_data->spectral_upper_max_index = 118 params->max_upper_index; 119 samp_data->spectral_nb_lower = params->nb_lower; 120 samp_data->spectral_nb_upper = params->nb_upper; 121 samp_data->spectral_last_tstamp = params->last_tstamp; 122 samp_data->spectral_max_mag = params->max_mag; 123 124 /* 125 * Currently, we compute pwr_count considering the size of the 126 * samp_data->bin_pwr array rather than the number of elements 127 * in this array. The reasons are that 128 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count will be 129 * used maps directly to OS_MEMCPY() on little endian platforms, 130 * and that samp_data->bin_pwr is an array of u_int8_t elements 131 * due to which the number of elements in the array == the size 132 * of the array. In case FFT bin size is increased from 8 bits 133 * in the future, this code would have to be changed along with 134 * rest of framework on which it depends. 135 */ 136 pwr_count = qdf_min((size_t)params->pwr_count, 137 sizeof(samp_data->bin_pwr)); 138 139 samp_data->bin_pwr_count = pwr_count; 140 samp_data->lb_edge_extrabins = 141 spectral->lb_edge_extrabins; 142 samp_data->rb_edge_extrabins = 143 spectral->rb_edge_extrabins; 144 samp_data->spectral_combined_rssi = params->rssi; 145 samp_data->spectral_max_scale = params->max_exp; 146 147 samp_data->noise_floor = params->noise_floor; 148 149 /* Classifier in user space needs access to these */ 150 cp = &samp_data->classifier_params; 151 pcp = ¶ms->classifier_params; 152 153 qdf_mem_copy(cp, pcp, 154 sizeof(struct spectral_classifier_params)); 155 156 /* 157 * To check whether FFT bin values exceed 8 bits, we add a 158 * check before copying values to samp_data->bin_pwr. 159 * If it crosses 8 bits, we cap the values to maximum value 160 * supported by 8 bits ie. 255. This needs to be done as the 161 * destination array in SAMP message is 8 bits. This is a 162 * temporary solution till an array of 16 bits is used for 163 * SAMP message. 164 */ 165 if (swar->fftbin_size_war == 166 SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) { 167 binptr_32 = (uint32_t *)bin_pwr_data; 168 for (idx = 0; idx < pwr_count; idx++) { 169 /* Read only the first 2 bytes of the DWORD */ 170 pwr_16 = *((uint16_t *)binptr_32++); 171 if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE)) 172 pwr_16 = MAX_FFTBIN_VALUE; 173 samp_data->bin_pwr[idx] = pwr_16; 174 } 175 } else if (swar->fftbin_size_war == 176 SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) { 177 binptr_16 = (uint16_t *)bin_pwr_data; 178 for (idx = 0; idx < pwr_count; idx++) { 179 pwr_16 = *(binptr_16++); 180 if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE)) 181 pwr_16 = MAX_FFTBIN_VALUE; 182 samp_data->bin_pwr[idx] = pwr_16; 183 } 184 } else { 185 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY( 186 &samp_data->bin_pwr[0], bin_pwr_data, 187 pwr_count); 188 } 189 190 p_sops->get_mac_address(spectral, spec_samp_msg->macaddr); 191 } 192 193 if (is_secondaryseg_rx_inprog(spectral, params->smode)) { 194 spec_samp_msg = (struct spectral_samp_msg *) 195 spectral->nl_cb.get_sbuff(spectral->pdev_obj, 196 msg_type, 197 SPECTRAL_MSG_BUF_SAVED); 198 199 if (!spec_samp_msg) { 200 spectral_err("Spectral SAMP message is NULL"); 201 return; 202 } 203 204 samp_data = &spec_samp_msg->samp_data; 205 samp_data->spectral_rssi_sec80 = 206 params->rssi_sec80; 207 samp_data->noise_floor_sec80 = 208 params->noise_floor_sec80; 209 spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 = 210 params->agc_total_gain_sec80; 211 spec_samp_msg->samp_data.spectral_gainchange_sec80 = 212 params->gainchange_sec80; 213 spec_samp_msg->samp_data.spectral_pri80ind_sec80 = 214 params->pri80ind_sec80; 215 216 samp_data->spectral_data_len_sec80 = 217 params->datalen_sec80; 218 samp_data->spectral_max_index_sec80 = 219 params->max_index_sec80; 220 samp_data->spectral_max_mag_sec80 = 221 params->max_mag_sec80; 222 223 samp_data->raw_timestamp_sec80 = params->raw_timestamp_sec80; 224 225 /* 226 * Currently, we compute pwr_count_sec80 considering the size of 227 * the samp_data->bin_pwr_sec80 array rather than the number of 228 * elements in this array. The reasons are that 229 * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count_sec80 will 230 * be used maps directly to OS_MEMCPY() on little endian 231 * platforms, and that samp_data->bin_pwr_sec80 is an array of 232 * u_int8_t elements due to which the number of elements in the 233 * array == the size of the array. In case FFT bin size is 234 * increased from 8 bits in the future, this code would have to 235 * be changed along with rest of framework on which it depends. 236 */ 237 pwr_count_sec80 = qdf_min((size_t)params->pwr_count_sec80, 238 sizeof(samp_data->bin_pwr_sec80)); 239 pwr_count_5mhz = qdf_min((size_t)params->pwr_count_5mhz, 240 sizeof(samp_data->bin_pwr_5mhz)); 241 242 samp_data->bin_pwr_count_sec80 = pwr_count_sec80; 243 samp_data->bin_pwr_count_5mhz = pwr_count_5mhz; 244 245 bin_pwr_data = params->bin_pwr_data_sec80; 246 247 /* 248 * To check whether FFT bin values exceed 8 bits, we add a 249 * check before copying values to samp_data->bin_pwr_sec80. 250 * If it crosses 8 bits, we cap the values to maximum value 251 * supported by 8 bits ie. 255. This needs to be done as the 252 * destination array in SAMP message is 8 bits. This is a 253 * temporary solution till an array of 16 bits is used for 254 * SAMP message. 255 */ 256 if (swar->fftbin_size_war == 257 SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) { 258 binptr_32 = (uint32_t *)bin_pwr_data; 259 for (idx = 0; idx < pwr_count_sec80; idx++) { 260 /* Read only the first 2 bytes of the DWORD */ 261 pwr_16 = *((uint16_t *)binptr_32++); 262 if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE)) 263 pwr_16 = MAX_FFTBIN_VALUE; 264 samp_data->bin_pwr_sec80[idx] = pwr_16; 265 } 266 } else if (swar->fftbin_size_war == 267 SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) { 268 binptr_16 = (uint16_t *)bin_pwr_data; 269 for (idx = 0; idx < pwr_count_sec80; idx++) { 270 pwr_16 = *(binptr_16++); 271 if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE)) 272 pwr_16 = MAX_FFTBIN_VALUE; 273 samp_data->bin_pwr_sec80[idx] = pwr_16; 274 } 275 276 binptr_16 = (uint16_t *)params->bin_pwr_data_5mhz; 277 for (idx = 0; idx < pwr_count_5mhz; idx++) { 278 pwr_16 = *(binptr_16++); 279 if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE)) 280 pwr_16 = MAX_FFTBIN_VALUE; 281 samp_data->bin_pwr_5mhz[idx] = pwr_16; 282 } 283 } else { 284 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY( 285 &samp_data->bin_pwr_sec80[0], 286 params->bin_pwr_data_sec80, 287 pwr_count_sec80); 288 } 289 } 290 291 if (!is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) || 292 is_secondaryseg_rx_inprog(spectral, params->smode)) { 293 if (spectral->send_phy_data(spectral->pdev_obj, 294 msg_type) == 0) 295 spectral->spectral_sent_msg++; 296 samp_msg_index++; 297 } 298 299 /* Take care of state transitions for 160MHz/ 80p80 */ 300 if (spectral->spectral_gen == SPECTRAL_GEN3 && 301 is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) && 302 spectral->rparams.fragmentation_160[params->smode]) 303 target_if_160mhz_delivery_state_change( 304 spectral, params->smode, 305 SPECTRAL_DETECTOR_ID_INVALID); 306 } 307