target_if_spectral_netlink.c 8.3 KB

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