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 int temp_samp_msg_len = 0; 40 41 struct spectral_samp_msg *spec_samp_msg = NULL; 42 43 uint8_t *bin_pwr_data = NULL; 44 struct spectral_classifier_params *cp = NULL; 45 struct spectral_classifier_params *pcp = NULL; 46 struct target_if_spectral_ops *p_sops = NULL; 47 uint32_t *binptr = NULL; 48 int idx = 0; 49 struct spectral_samp_data *samp_data; 50 static int samp_msg_index; 51 52 if (is_primaryseg_rx_inprog(spectral)) { 53 spec_samp_msg = (struct spectral_samp_msg *) 54 spectral->nl_cb.get_nbuff(spectral->pdev_obj); 55 56 if (!spec_samp_msg) 57 return; 58 59 samp_data = &spec_samp_msg->samp_data; 60 if (spectral->spectral_gen == SPECTRAL_GEN3) 61 save_spectral_report_skb(spectral, spec_samp_msg); 62 p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral); 63 temp_samp_msg_len = sizeof(struct spectral_samp_msg) - 64 (MAX_NUM_BINS * sizeof(uint8_t)); 65 temp_samp_msg_len += (params->pwr_count * sizeof(uint8_t)); 66 if (spectral->ch_width == CH_WIDTH_160MHZ) 67 temp_samp_msg_len += 68 (params->pwr_count_sec80 * sizeof(uint8_t)); 69 bin_pwr_data = params->bin_pwr_data; 70 71 spec_samp_msg->signature = SPECTRAL_SIGNATURE; 72 spec_samp_msg->freq = params->freq; 73 spec_samp_msg->freq_loading = params->freq_loading; 74 samp_data->spectral_data_len = params->datalen; 75 samp_data->spectral_rssi = params->rssi; 76 samp_data->ch_width = spectral->ch_width; 77 samp_data->spectral_agc_total_gain = params->agc_total_gain; 78 samp_data->spectral_gainchange = params->gainchange; 79 80 samp_data->spectral_combined_rssi = 81 (uint8_t)params->rssi; 82 samp_data->spectral_upper_rssi = params->upper_rssi; 83 samp_data->spectral_lower_rssi = params->lower_rssi; 84 85 qdf_mem_copy(samp_data->spectral_chain_ctl_rssi, 86 params->chain_ctl_rssi, 87 sizeof(params->chain_ctl_rssi)); 88 qdf_mem_copy(samp_data->spectral_chain_ext_rssi, 89 params->chain_ext_rssi, 90 sizeof(params->chain_ext_rssi)); 91 92 samp_data->spectral_bwinfo = params->bwinfo; 93 samp_data->spectral_tstamp = params->tstamp; 94 samp_data->spectral_max_index = params->max_index; 95 96 /* Classifier in user space needs access to these */ 97 samp_data->spectral_lower_max_index = 98 params->max_lower_index; 99 samp_data->spectral_upper_max_index = 100 params->max_upper_index; 101 samp_data->spectral_nb_lower = params->nb_lower; 102 samp_data->spectral_nb_upper = params->nb_upper; 103 samp_data->spectral_last_tstamp = params->last_tstamp; 104 samp_data->spectral_max_mag = params->max_mag; 105 samp_data->bin_pwr_count = params->pwr_count; 106 samp_data->lb_edge_extrabins = 107 spectral->lb_edge_extrabins; 108 samp_data->rb_edge_extrabins = 109 spectral->rb_edge_extrabins; 110 samp_data->spectral_combined_rssi = params->rssi; 111 samp_data->spectral_max_scale = params->max_exp; 112 113 samp_data->noise_floor = params->noise_floor; 114 115 /* Classifier in user space needs access to these */ 116 cp = &samp_data->classifier_params; 117 pcp = ¶ms->classifier_params; 118 119 qdf_mem_copy(cp, pcp, 120 sizeof(struct spectral_classifier_params)); 121 122 if (spectral->fftbin_size_war) { 123 binptr = (uint32_t *)bin_pwr_data; 124 for (idx = 0; idx < params->pwr_count; idx++) 125 samp_data->bin_pwr[idx] = *(binptr++); 126 } else { 127 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY( 128 &samp_data->bin_pwr[0], bin_pwr_data, 129 params->pwr_count); 130 } 131 132 p_sops->get_mac_address(spectral, spec_samp_msg->macaddr); 133 } 134 135 if (is_secondaryseg_rx_inprog(spectral)) { 136 if (spectral->spectral_gen == SPECTRAL_GEN3) 137 restore_spectral_report_skb(spectral, 138 (void **)&spec_samp_msg); 139 if (!spec_samp_msg) { 140 spectral_err("Spectral SAMP message is NULL"); 141 return; 142 } 143 144 samp_data = &spec_samp_msg->samp_data; 145 spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1; 146 spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2; 147 samp_data->spectral_rssi_sec80 = 148 params->rssi_sec80; 149 samp_data->noise_floor_sec80 = 150 params->noise_floor_sec80; 151 spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 = 152 params->agc_total_gain_sec80; 153 spec_samp_msg->samp_data.spectral_gainchange_sec80 = 154 params->gainchange_sec80; 155 156 samp_data->spectral_data_len_sec80 = 157 params->datalen_sec80; 158 samp_data->spectral_max_index_sec80 = 159 params->max_index_sec80; 160 samp_data->spectral_max_mag_sec80 = 161 params->max_mag_sec80; 162 samp_data->bin_pwr_count_sec80 = 163 params->pwr_count_sec80; 164 165 bin_pwr_data = params->bin_pwr_data_sec80; 166 if (spectral->fftbin_size_war) { 167 binptr = (uint32_t *)bin_pwr_data; 168 for (idx = 0; idx < params->pwr_count_sec80; idx++) 169 samp_data->bin_pwr_sec80[idx] = *(binptr++); 170 } else { 171 SPECTRAL_MESSAGE_COPY_CHAR_ARRAY( 172 &samp_data->bin_pwr_sec80[0], 173 params->bin_pwr_data_sec80, 174 params->pwr_count_sec80); 175 } 176 } 177 178 if ((spectral->ch_width != CH_WIDTH_160MHZ) || 179 is_secondaryseg_rx_inprog(spectral)) { 180 if (spectral->send_phy_data(spectral->pdev_obj) == 0) 181 spectral->spectral_sent_msg++; 182 samp_msg_index++; 183 if (spectral->spectral_gen == SPECTRAL_GEN3) 184 clear_spectral_report_skb(spectral); 185 } 186 187 /* Take care of state transitions for 160MHz/ 80p80 */ 188 if (spectral->spectral_gen == SPECTRAL_GEN3) 189 target_if_160mhz_delivery_state_change( 190 spectral, 191 SPECTRAL_REPORT_EVENT_DETECTORID_INVALID); 192 } 193