target_if_spectral_netlink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Copyright (c) 2011,2017-2021 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. extern int spectral_debug_level;
  29. #ifdef OPTIMIZED_SAMP_MESSAGE
  30. QDF_STATUS
  31. target_if_spectral_fill_samp_msg(struct target_if_spectral *spectral,
  32. struct target_if_samp_msg_params *params)
  33. {
  34. struct spectral_samp_msg *spec_samp_msg;
  35. struct per_session_det_map *det_map;
  36. enum spectral_msg_type msg_type;
  37. QDF_STATUS ret;
  38. uint16_t dest_det_idx;
  39. enum spectral_scan_mode spectral_mode;
  40. uint16_t pwr_format;
  41. if (!spectral) {
  42. spectral_err_rl("Spectral LMAC object is null");
  43. return QDF_STATUS_E_NULL_VALUE;
  44. }
  45. if (!params) {
  46. spectral_err_rl("SAMP msg params structure is null");
  47. return QDF_STATUS_E_NULL_VALUE;
  48. }
  49. if (params->hw_detector_id >= SPECTRAL_DETECTOR_ID_MAX) {
  50. spectral_err_rl("Invalid detector ID");
  51. return QDF_STATUS_E_FAILURE;
  52. }
  53. spectral_mode =
  54. spectral->rparams.detid_mode_table[params->hw_detector_id];
  55. if (spectral_mode >= SPECTRAL_SCAN_MODE_MAX) {
  56. spectral_err_rl("No valid Spectral mode for detector id %u",
  57. params->hw_detector_id);
  58. return QDF_STATUS_E_FAILURE;
  59. }
  60. ret = target_if_get_spectral_msg_type(spectral_mode,
  61. &msg_type);
  62. if (QDF_IS_STATUS_ERROR(ret)) {
  63. spectral_err_rl("Invalid spectral msg type");
  64. return QDF_STATUS_E_FAILURE;
  65. }
  66. pwr_format = spectral->params[spectral_mode].ss_pwr_format;
  67. qdf_spin_lock_bh(&spectral->session_det_map_lock);
  68. if (!spectral->det_map[params->hw_detector_id].det_map_valid) {
  69. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  70. spectral_info("Detector Map not valid for det id = %d",
  71. params->hw_detector_id);
  72. return QDF_STATUS_E_FAILURE;
  73. }
  74. det_map = &spectral->det_map[params->hw_detector_id];
  75. spec_samp_msg = spectral->nl_cb.get_sbuff(spectral->pdev_obj,
  76. msg_type,
  77. det_map->buf_type);
  78. if (!spec_samp_msg) {
  79. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  80. spectral_err_rl("Spectral SAMP message is NULL");
  81. return QDF_STATUS_E_FAILURE;
  82. }
  83. for (dest_det_idx = 0; dest_det_idx < det_map->num_dest_det_info;
  84. dest_det_idx++) {
  85. struct per_session_dest_det_info *map_det_info;
  86. struct spectral_fft_bin_len_adj_swar *swar;
  87. struct samp_freq_span_info *span_info;
  88. struct samp_detector_info *detector_info;
  89. uint8_t dest_detector_id;
  90. uint8_t span_id;
  91. struct samp_edge_extra_bin_info *lb_edge_bins;
  92. struct samp_edge_extra_bin_info *rb_edge_bins;
  93. uint8_t *bin_pwr_data;
  94. size_t pwr_count;
  95. uint16_t num_edge_bins;
  96. uint16_t start_bin_index;
  97. uint32_t bytes_copied;
  98. swar = &spectral->len_adj_swar;
  99. map_det_info = &det_map->dest_det_info[dest_det_idx];
  100. span_id = map_det_info->freq_span_id;
  101. span_info = &spec_samp_msg->freq_span_info[span_id];
  102. span_info->num_detectors++;
  103. dest_detector_id = map_det_info->det_id;
  104. detector_info = &span_info->detector_info[dest_detector_id];
  105. lb_edge_bins = &detector_info->left_edge_bins;
  106. rb_edge_bins = &detector_info->right_edge_bins;
  107. detector_info->start_frequency = map_det_info->start_freq;
  108. detector_info->end_frequency = map_det_info->end_freq;
  109. detector_info->start_bin_idx = map_det_info->dest_start_bin_idx;
  110. detector_info->end_bin_idx = map_det_info->dest_end_bin_idx;
  111. lb_edge_bins->start_bin_idx =
  112. map_det_info->lb_extrabins_start_idx;
  113. lb_edge_bins->num_bins = map_det_info->lb_extrabins_num;
  114. rb_edge_bins->start_bin_idx =
  115. map_det_info->rb_extrabins_start_idx;
  116. rb_edge_bins->num_bins = map_det_info->rb_extrabins_num;
  117. start_bin_index = detector_info->start_bin_idx;
  118. detector_info->rssi = params->rssi;
  119. detector_info->last_raw_timestamp = params->last_raw_timestamp;
  120. detector_info->reset_delay = params->reset_delay;
  121. detector_info->raw_timestamp = params->raw_timestamp;
  122. detector_info->timestamp = params->timestamp;
  123. detector_info->timestamp_war_offset = spectral->timestamp_war.
  124. timestamp_war_offset[spectral_mode];
  125. detector_info->max_magnitude = params->max_mag;
  126. detector_info->max_index = params->max_index;
  127. detector_info->noise_floor = params->noise_floor;
  128. detector_info->agc_total_gain = params->agc_total_gain;
  129. detector_info->gainchange = params->gainchange;
  130. detector_info->is_sec80 = map_det_info->is_sec80;
  131. /* In 165MHz, Pri80 indication to be set for Span ID 0 only */
  132. if (span_id == SPECTRAL_FREQ_SPAN_ID_0)
  133. detector_info->pri80ind = params->pri80ind;
  134. bin_pwr_data = &params->bin_pwr_data
  135. [map_det_info->src_start_bin_idx];
  136. pwr_count = detector_info->end_bin_idx -
  137. detector_info->start_bin_idx + 1;
  138. num_edge_bins = lb_edge_bins->num_bins +
  139. rb_edge_bins->num_bins;
  140. /* Copy left edge bins */
  141. if (lb_edge_bins->num_bins > 0) {
  142. ret = target_if_spectral_copy_fft_bins(
  143. spectral, bin_pwr_data,
  144. &spec_samp_msg->bin_pwr[
  145. lb_edge_bins->start_bin_idx],
  146. lb_edge_bins->num_bins,
  147. &bytes_copied, pwr_format);
  148. if (QDF_IS_STATUS_ERROR(ret)) {
  149. qdf_spin_unlock_bh(
  150. &spectral->session_det_map_lock);
  151. spectral_err_rl("Unable to copy left edge FFT bins");
  152. return QDF_STATUS_E_FAILURE;
  153. }
  154. /* Advance the fft bin pointer in the report */
  155. bin_pwr_data += bytes_copied;
  156. }
  157. /* Copy the in-band and out-band bins */
  158. ret = target_if_spectral_copy_fft_bins(
  159. spectral, bin_pwr_data,
  160. &spec_samp_msg->bin_pwr[start_bin_index],
  161. pwr_count,
  162. &bytes_copied, pwr_format);
  163. if (QDF_IS_STATUS_ERROR(ret)) {
  164. qdf_spin_unlock_bh(
  165. &spectral->session_det_map_lock);
  166. spectral_err_rl("Unable to copy in-band/out-band FFT bins");
  167. return QDF_STATUS_E_FAILURE;
  168. }
  169. /* Advance the fft bin pointer in the report */
  170. bin_pwr_data += bytes_copied;
  171. /* Copy right edge bins */
  172. if (rb_edge_bins->num_bins > 0) {
  173. ret = target_if_spectral_copy_fft_bins(
  174. spectral, bin_pwr_data,
  175. &spec_samp_msg->bin_pwr[
  176. rb_edge_bins->start_bin_idx],
  177. rb_edge_bins->num_bins,
  178. &bytes_copied, pwr_format);
  179. if (QDF_IS_STATUS_ERROR(ret)) {
  180. qdf_spin_unlock_bh(
  181. &spectral->session_det_map_lock);
  182. spectral_err_rl("Unable to copy right edge FFT bins");
  183. return QDF_STATUS_E_FAILURE;
  184. }
  185. /* Advance the fft bin pointer in the report */
  186. bin_pwr_data += bytes_copied;
  187. }
  188. spec_samp_msg->bin_pwr_count += (pwr_count + num_edge_bins);
  189. }
  190. if (det_map->send_to_upper_layers) {
  191. /* Fill per-report information */
  192. struct per_session_report_info *rpt_info;
  193. struct target_if_spectral_ops *p_sops;
  194. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  195. qdf_spin_lock_bh(&spectral->session_report_info_lock);
  196. rpt_info = &spectral->report_info[spectral_mode];
  197. if (!rpt_info->valid) {
  198. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  199. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  200. spectral_info("per-session report info is not valid");
  201. return QDF_STATUS_E_FAILURE;
  202. }
  203. spec_samp_msg->signature = SPECTRAL_SIGNATURE;
  204. p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
  205. spec_samp_msg->spectral_mode = spectral_mode;
  206. spec_samp_msg->target_reset_count =
  207. spectral->timestamp_war.target_reset_count;
  208. spec_samp_msg->operating_bw = spectral->nl_cb.
  209. convert_to_nl_ch_width(rpt_info->operating_bw);
  210. if (spec_samp_msg->operating_bw < 0) {
  211. spectral_err_rl("Invalid operating channel width %d",
  212. rpt_info->operating_bw);
  213. return QDF_STATUS_E_FAILURE;
  214. }
  215. spec_samp_msg->pri20_freq = rpt_info->pri20_freq;
  216. spec_samp_msg->cfreq1 = rpt_info->cfreq1;
  217. spec_samp_msg->cfreq2 = rpt_info->cfreq2;
  218. spec_samp_msg->sscan_cfreq1 = rpt_info->sscan_cfreq1;
  219. spec_samp_msg->sscan_cfreq2 = rpt_info->sscan_cfreq2;
  220. spec_samp_msg->sscan_bw = spectral->nl_cb.
  221. convert_to_nl_ch_width(rpt_info->sscan_bw);
  222. if (spec_samp_msg->sscan_bw < 0) {
  223. spectral_err_rl("Invalid sscan channel width %d",
  224. rpt_info->sscan_bw);
  225. return QDF_STATUS_E_FAILURE;
  226. }
  227. spec_samp_msg->fft_width = FFT_BIN_SIZE_1BYTE;
  228. spec_samp_msg->num_freq_spans = rpt_info->num_spans;
  229. qdf_spin_unlock_bh(&spectral->session_report_info_lock);
  230. spec_samp_msg->spectral_upper_rssi = params->upper_rssi;
  231. spec_samp_msg->spectral_lower_rssi = params->lower_rssi;
  232. qdf_mem_copy(spec_samp_msg->spectral_chain_ctl_rssi,
  233. params->chain_ctl_rssi,
  234. sizeof(params->chain_ctl_rssi));
  235. qdf_mem_copy(spec_samp_msg->spectral_chain_ext_rssi,
  236. params->chain_ext_rssi,
  237. sizeof(params->chain_ext_rssi));
  238. if (spectral_debug_level & DEBUG_SPECTRAL4)
  239. target_if_dbg_print_samp_msg(spec_samp_msg);
  240. if (spectral->send_phy_data(spectral->pdev_obj,
  241. msg_type) == 0)
  242. spectral->spectral_sent_msg++;
  243. if (spectral->spectral_gen == SPECTRAL_GEN3)
  244. reset_160mhz_delivery_state_machine(spectral,
  245. spectral_mode);
  246. }
  247. qdf_spin_unlock_bh(&spectral->session_det_map_lock);
  248. return QDF_STATUS_SUCCESS;
  249. }
  250. #endif /* OPTIMIZED_SAMP_MESSAGE */
  251. #ifndef OPTIMIZED_SAMP_MESSAGE
  252. void
  253. target_if_spectral_create_samp_msg(struct target_if_spectral *spectral,
  254. struct target_if_samp_msg_params *params)
  255. {
  256. /*
  257. * XXX : Non-Rentrant. Will be an issue with dual concurrent
  258. * operation on multi-processor system
  259. */
  260. struct spectral_samp_msg *spec_samp_msg = NULL;
  261. uint8_t *bin_pwr_data = NULL;
  262. struct spectral_classifier_params *cp = NULL;
  263. struct spectral_classifier_params *pcp = NULL;
  264. struct target_if_spectral_ops *p_sops = NULL;
  265. uint32_t *binptr_32 = NULL;
  266. uint16_t *binptr_16 = NULL;
  267. uint16_t pwr_16;
  268. int idx = 0;
  269. struct spectral_samp_data *samp_data;
  270. static int samp_msg_index;
  271. size_t pwr_count = 0;
  272. size_t pwr_count_sec80 = 0;
  273. size_t pwr_count_5mhz = 0;
  274. enum spectral_msg_type msg_type;
  275. QDF_STATUS ret;
  276. struct spectral_fft_bin_len_adj_swar *swar = &spectral->len_adj_swar;
  277. ret = target_if_get_spectral_msg_type(params->smode, &msg_type);
  278. if (QDF_IS_STATUS_ERROR(ret))
  279. return;
  280. if (is_primaryseg_rx_inprog(spectral, params->smode)) {
  281. spec_samp_msg = (struct spectral_samp_msg *)
  282. spectral->nl_cb.get_sbuff(spectral->pdev_obj,
  283. msg_type,
  284. SPECTRAL_MSG_BUF_NEW);
  285. if (!spec_samp_msg)
  286. return;
  287. samp_data = &spec_samp_msg->samp_data;
  288. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  289. bin_pwr_data = params->bin_pwr_data;
  290. spec_samp_msg->signature = SPECTRAL_SIGNATURE;
  291. spec_samp_msg->freq = params->freq;
  292. spec_samp_msg->agile_freq1 = params->agile_freq1;
  293. spec_samp_msg->agile_freq2 = params->agile_freq2;
  294. spec_samp_msg->freq_loading = params->freq_loading;
  295. spec_samp_msg->vhtop_ch_freq_seg1 = params->vhtop_ch_freq_seg1;
  296. spec_samp_msg->vhtop_ch_freq_seg2 = params->vhtop_ch_freq_seg2;
  297. samp_data->spectral_mode = params->smode;
  298. samp_data->spectral_data_len = params->datalen;
  299. samp_data->spectral_rssi = params->rssi;
  300. samp_data->ch_width =
  301. spectral->ch_width[SPECTRAL_SCAN_MODE_NORMAL];
  302. samp_data->agile_ch_width =
  303. spectral->ch_width[SPECTRAL_SCAN_MODE_AGILE];
  304. samp_data->spectral_agc_total_gain = params->agc_total_gain;
  305. samp_data->spectral_gainchange = params->gainchange;
  306. samp_data->spectral_pri80ind = params->pri80ind;
  307. samp_data->last_raw_timestamp = params->last_raw_timestamp;
  308. samp_data->timestamp_war_offset = params->timestamp_war_offset;
  309. samp_data->raw_timestamp = params->raw_timestamp;
  310. samp_data->reset_delay = params->reset_delay;
  311. samp_data->target_reset_count = params->target_reset_count;
  312. samp_data->spectral_combined_rssi =
  313. (uint8_t)params->rssi;
  314. samp_data->spectral_upper_rssi = params->upper_rssi;
  315. samp_data->spectral_lower_rssi = params->lower_rssi;
  316. qdf_mem_copy(samp_data->spectral_chain_ctl_rssi,
  317. params->chain_ctl_rssi,
  318. sizeof(params->chain_ctl_rssi));
  319. qdf_mem_copy(samp_data->spectral_chain_ext_rssi,
  320. params->chain_ext_rssi,
  321. sizeof(params->chain_ext_rssi));
  322. samp_data->spectral_bwinfo = params->bwinfo;
  323. samp_data->spectral_tstamp = params->tstamp;
  324. samp_data->spectral_max_index = params->max_index;
  325. /* Classifier in user space needs access to these */
  326. samp_data->spectral_lower_max_index =
  327. params->max_lower_index;
  328. samp_data->spectral_upper_max_index =
  329. params->max_upper_index;
  330. samp_data->spectral_nb_lower = params->nb_lower;
  331. samp_data->spectral_nb_upper = params->nb_upper;
  332. samp_data->spectral_last_tstamp = params->last_tstamp;
  333. samp_data->spectral_max_mag = params->max_mag;
  334. /*
  335. * Currently, we compute pwr_count considering the size of the
  336. * samp_data->bin_pwr array rather than the number of elements
  337. * in this array. The reasons are that
  338. * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count will be
  339. * used maps directly to OS_MEMCPY() on little endian platforms,
  340. * and that samp_data->bin_pwr is an array of u_int8_t elements
  341. * due to which the number of elements in the array == the size
  342. * of the array. In case FFT bin size is increased from 8 bits
  343. * in the future, this code would have to be changed along with
  344. * rest of framework on which it depends.
  345. */
  346. pwr_count = qdf_min((size_t)params->pwr_count,
  347. sizeof(samp_data->bin_pwr));
  348. samp_data->bin_pwr_count = pwr_count;
  349. samp_data->lb_edge_extrabins =
  350. spectral->lb_edge_extrabins;
  351. samp_data->rb_edge_extrabins =
  352. spectral->rb_edge_extrabins;
  353. samp_data->spectral_combined_rssi = params->rssi;
  354. samp_data->spectral_max_scale = params->max_exp;
  355. samp_data->noise_floor = params->noise_floor;
  356. /* Classifier in user space needs access to these */
  357. cp = &samp_data->classifier_params;
  358. pcp = &params->classifier_params;
  359. qdf_mem_copy(cp, pcp,
  360. sizeof(struct spectral_classifier_params));
  361. /*
  362. * To check whether FFT bin values exceed 8 bits, we add a
  363. * check before copying values to samp_data->bin_pwr.
  364. * If it crosses 8 bits, we cap the values to maximum value
  365. * supported by 8 bits ie. 255. This needs to be done as the
  366. * destination array in SAMP message is 8 bits. This is a
  367. * temporary solution till an array of 16 bits is used for
  368. * SAMP message.
  369. */
  370. if (swar->fftbin_size_war ==
  371. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  372. binptr_32 = (uint32_t *)bin_pwr_data;
  373. for (idx = 0; idx < pwr_count; idx++) {
  374. /* Read only the first 2 bytes of the DWORD */
  375. pwr_16 = *((uint16_t *)binptr_32++);
  376. if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
  377. pwr_16 = MAX_FFTBIN_VALUE;
  378. samp_data->bin_pwr[idx] = pwr_16;
  379. }
  380. } else if (swar->fftbin_size_war ==
  381. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  382. binptr_16 = (uint16_t *)bin_pwr_data;
  383. for (idx = 0; idx < pwr_count; idx++) {
  384. pwr_16 = *(binptr_16++);
  385. if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
  386. pwr_16 = MAX_FFTBIN_VALUE;
  387. samp_data->bin_pwr[idx] = pwr_16;
  388. }
  389. } else {
  390. SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
  391. &samp_data->bin_pwr[0], bin_pwr_data,
  392. pwr_count);
  393. }
  394. p_sops->get_mac_address(spectral, spec_samp_msg->macaddr);
  395. }
  396. if (is_secondaryseg_rx_inprog(spectral, params->smode)) {
  397. spec_samp_msg = (struct spectral_samp_msg *)
  398. spectral->nl_cb.get_sbuff(spectral->pdev_obj,
  399. msg_type,
  400. SPECTRAL_MSG_BUF_SAVED);
  401. if (!spec_samp_msg) {
  402. spectral_err("Spectral SAMP message is NULL");
  403. return;
  404. }
  405. samp_data = &spec_samp_msg->samp_data;
  406. samp_data->spectral_rssi_sec80 =
  407. params->rssi_sec80;
  408. samp_data->noise_floor_sec80 =
  409. params->noise_floor_sec80;
  410. spec_samp_msg->samp_data.spectral_agc_total_gain_sec80 =
  411. params->agc_total_gain_sec80;
  412. spec_samp_msg->samp_data.spectral_gainchange_sec80 =
  413. params->gainchange_sec80;
  414. spec_samp_msg->samp_data.spectral_pri80ind_sec80 =
  415. params->pri80ind_sec80;
  416. samp_data->spectral_data_len_sec80 =
  417. params->datalen_sec80;
  418. samp_data->spectral_max_index_sec80 =
  419. params->max_index_sec80;
  420. samp_data->spectral_max_mag_sec80 =
  421. params->max_mag_sec80;
  422. samp_data->raw_timestamp_sec80 = params->raw_timestamp_sec80;
  423. /*
  424. * Currently, we compute pwr_count_sec80 considering the size of
  425. * the samp_data->bin_pwr_sec80 array rather than the number of
  426. * elements in this array. The reasons are that
  427. * SPECTRAL_MESSAGE_COPY_CHAR_ARRAY() where pwr_count_sec80 will
  428. * be used maps directly to OS_MEMCPY() on little endian
  429. * platforms, and that samp_data->bin_pwr_sec80 is an array of
  430. * u_int8_t elements due to which the number of elements in the
  431. * array == the size of the array. In case FFT bin size is
  432. * increased from 8 bits in the future, this code would have to
  433. * be changed along with rest of framework on which it depends.
  434. */
  435. pwr_count_sec80 = qdf_min((size_t)params->pwr_count_sec80,
  436. sizeof(samp_data->bin_pwr_sec80));
  437. pwr_count_5mhz = qdf_min((size_t)params->pwr_count_5mhz,
  438. sizeof(samp_data->bin_pwr_5mhz));
  439. samp_data->bin_pwr_count_sec80 = pwr_count_sec80;
  440. samp_data->bin_pwr_count_5mhz = pwr_count_5mhz;
  441. bin_pwr_data = params->bin_pwr_data_sec80;
  442. /*
  443. * To check whether FFT bin values exceed 8 bits, we add a
  444. * check before copying values to samp_data->bin_pwr_sec80.
  445. * If it crosses 8 bits, we cap the values to maximum value
  446. * supported by 8 bits ie. 255. This needs to be done as the
  447. * destination array in SAMP message is 8 bits. This is a
  448. * temporary solution till an array of 16 bits is used for
  449. * SAMP message.
  450. */
  451. if (swar->fftbin_size_war ==
  452. SPECTRAL_FFTBIN_SIZE_WAR_4BYTE_TO_1BYTE) {
  453. binptr_32 = (uint32_t *)bin_pwr_data;
  454. for (idx = 0; idx < pwr_count_sec80; idx++) {
  455. /* Read only the first 2 bytes of the DWORD */
  456. pwr_16 = *((uint16_t *)binptr_32++);
  457. if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
  458. pwr_16 = MAX_FFTBIN_VALUE;
  459. samp_data->bin_pwr_sec80[idx] = pwr_16;
  460. }
  461. } else if (swar->fftbin_size_war ==
  462. SPECTRAL_FFTBIN_SIZE_WAR_2BYTE_TO_1BYTE) {
  463. binptr_16 = (uint16_t *)bin_pwr_data;
  464. for (idx = 0; idx < pwr_count_sec80; idx++) {
  465. pwr_16 = *(binptr_16++);
  466. if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
  467. pwr_16 = MAX_FFTBIN_VALUE;
  468. samp_data->bin_pwr_sec80[idx] = pwr_16;
  469. }
  470. binptr_16 = (uint16_t *)params->bin_pwr_data_5mhz;
  471. for (idx = 0; idx < pwr_count_5mhz; idx++) {
  472. pwr_16 = *(binptr_16++);
  473. if (qdf_unlikely(pwr_16 > MAX_FFTBIN_VALUE))
  474. pwr_16 = MAX_FFTBIN_VALUE;
  475. samp_data->bin_pwr_5mhz[idx] = pwr_16;
  476. }
  477. } else {
  478. SPECTRAL_MESSAGE_COPY_CHAR_ARRAY(
  479. &samp_data->bin_pwr_sec80[0],
  480. params->bin_pwr_data_sec80,
  481. pwr_count_sec80);
  482. }
  483. }
  484. if (!is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) ||
  485. is_secondaryseg_rx_inprog(spectral, params->smode)) {
  486. if (spectral->send_phy_data(spectral->pdev_obj,
  487. msg_type) == 0)
  488. spectral->spectral_sent_msg++;
  489. samp_msg_index++;
  490. }
  491. /* Take care of state transitions for 160MHz/ 80p80 */
  492. if (spectral->spectral_gen == SPECTRAL_GEN3 &&
  493. is_ch_width_160_or_80p80(spectral->ch_width[params->smode]) &&
  494. spectral->rparams.fragmentation_160[params->smode])
  495. target_if_160mhz_delivery_state_change(
  496. spectral, params->smode,
  497. SPECTRAL_DETECTOR_ID_INVALID);
  498. }
  499. #endif