target_if_spectral_netlink.c 20 KB

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