target_if_spectral_netlink.c 20 KB

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