target_if_spectral_netlink.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. static int samp_msg_index;
  116. spec_samp_msg = (struct spectral_samp_msg *)spectral->nl_cb.get_nbuff(
  117. spectral->pdev_obj);
  118. if (!spec_samp_msg)
  119. return;
  120. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  121. temp_samp_msg_len = sizeof(struct spectral_samp_msg) -
  122. (MAX_NUM_BINS * sizeof(uint8_t));
  123. temp_samp_msg_len += (params->pwr_count * sizeof(uint8_t));
  124. if (spectral->ch_width == CH_WIDTH_160MHZ)
  125. temp_samp_msg_len +=
  126. (params->pwr_count_sec80 * sizeof(uint8_t));
  127. bin_pwr_data = params->bin_pwr_data;
  128. data = &spec_samp_msg->samp_data;
  129. spec_samp_msg->signature = SPECTRAL_SIGNATURE;
  130. spec_samp_msg->freq = params->freq;
  131. spec_samp_msg->freq_loading = params->freq_loading;
  132. spec_samp_msg->samp_data.spectral_data_len = params->datalen;
  133. spec_samp_msg->samp_data.spectral_rssi = params->rssi;
  134. spec_samp_msg->samp_data.ch_width = spectral->ch_width;
  135. spec_samp_msg->samp_data.spectral_combined_rssi =
  136. (uint8_t)params->rssi;
  137. spec_samp_msg->samp_data.spectral_upper_rssi = params->upper_rssi;
  138. spec_samp_msg->samp_data.spectral_lower_rssi = params->lower_rssi;
  139. OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ctl_rssi,
  140. params->chain_ctl_rssi, sizeof(params->chain_ctl_rssi));
  141. OS_MEMCPY(spec_samp_msg->samp_data.spectral_chain_ext_rssi,
  142. params->chain_ext_rssi, sizeof(params->chain_ext_rssi));
  143. spec_samp_msg->samp_data.spectral_bwinfo = params->bwinfo;
  144. spec_samp_msg->samp_data.spectral_tstamp = params->tstamp;
  145. spec_samp_msg->samp_data.spectral_max_index = params->max_index;
  146. /* Classifier in user space needs access to these */
  147. spec_samp_msg->samp_data.spectral_lower_max_index =
  148. params->max_lower_index;
  149. spec_samp_msg->samp_data.spectral_upper_max_index =
  150. params->max_upper_index;
  151. spec_samp_msg->samp_data.spectral_nb_lower = params->nb_lower;
  152. spec_samp_msg->samp_data.spectral_nb_upper = params->nb_upper;
  153. spec_samp_msg->samp_data.spectral_last_tstamp = params->last_tstamp;
  154. spec_samp_msg->samp_data.spectral_max_mag = params->max_mag;
  155. spec_samp_msg->samp_data.bin_pwr_count = params->pwr_count;
  156. spec_samp_msg->samp_data.lb_edge_extrabins =
  157. spectral->lb_edge_extrabins;
  158. spec_samp_msg->samp_data.rb_edge_extrabins =
  159. spectral->rb_edge_extrabins;
  160. spec_samp_msg->samp_data.spectral_combined_rssi = params->rssi;
  161. spec_samp_msg->samp_data.spectral_max_scale = params->max_exp;
  162. /*
  163. * This is a dirty hack to get the Windows build pass.
  164. * Currently Windows and Linux builds source spectral_data.h
  165. * form two different place. The windows version do not
  166. * have noise_floor member in it.
  167. *
  168. * As a temp workaround this variable is set under the
  169. * SPECTRAL_USE_NETLINK_SOCKETS as this is called only
  170. * under the linux build and this saves the day
  171. *
  172. * The plan to sync of header files in under the way
  173. *
  174. */
  175. spec_samp_msg->samp_data.noise_floor = params->noise_floor;
  176. /* Classifier in user space needs access to these */
  177. cp = &spec_samp_msg->samp_data.classifier_params;
  178. pcp = &params->classifier_params;
  179. OS_MEMCPY(cp, pcp, sizeof(struct spectral_classifier_params));
  180. SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr[0],
  181. bin_pwr_data, params->pwr_count);
  182. spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1;
  183. spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2;
  184. if (spectral->ch_width == CH_WIDTH_160MHZ) {
  185. spec_samp_msg->samp_data.spectral_rssi_sec80 =
  186. params->rssi_sec80;
  187. spec_samp_msg->samp_data.noise_floor_sec80 =
  188. params->noise_floor_sec80;
  189. spec_samp_msg->samp_data.spectral_data_len_sec80 =
  190. params->datalen_sec80;
  191. spec_samp_msg->samp_data.spectral_max_index_sec80 =
  192. params->max_index_sec80;
  193. spec_samp_msg->samp_data.spectral_max_mag_sec80 =
  194. params->max_mag_sec80;
  195. spec_samp_msg->samp_data.bin_pwr_count_sec80 =
  196. params->pwr_count_sec80;
  197. SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(&data->bin_pwr_sec80[0],
  198. (params->bin_pwr_data_sec80),
  199. params->pwr_count_sec80);
  200. /*
  201. * Note: REVERSE_ORDER is not a known use case for
  202. * secondary 80 data at this point.
  203. */
  204. }
  205. target_if_spectral_init_interf_list(data, params);
  206. p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
  207. if (spectral->sc_spectral_noise_pwr_cal)
  208. target_if_spectral_process_noise_pwr_report(
  209. spectral, spec_samp_msg);
  210. spectral_debug("Recieved sample message");
  211. if (spectral->send_phy_data(spectral->pdev_obj) == 0)
  212. spectral->spectral_sent_msg++;
  213. samp_msg_index++;
  214. }