target_if_spectral_netlink.c 11 KB

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