target_if_spectral_netlink.c 8.4 KB

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