target_if_spectral_sim.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. /*
  2. * Copyright (c) 2015,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. #ifdef QCA_SUPPORT_SPECTRAL_SIMULATION
  20. #include "target_if_spectral.h"
  21. #include "target_if_spectral_sim.h"
  22. #include "target_if_spectral_sim_int.h"
  23. #include "_ieee80211.h"
  24. #include "ieee80211_api.h"
  25. #include "ieee80211_defines.h"
  26. #include "qdf_types.h"
  27. #include "ieee80211_var.h"
  28. #include <wlan_mlme_dispatcher.h>
  29. #include <qdf_module.h>
  30. /* Helper functions */
  31. static int target_if_populate_report_static_gen2(
  32. struct spectralsim_report *report,
  33. enum phy_ch_width width, bool is_80_80);
  34. static int target_if_populate_report_static_gen3(
  35. struct spectralsim_report *report,
  36. enum phy_ch_width width, bool is_80_80);
  37. static void target_if_depopulate_report(
  38. struct spectralsim_report *report);
  39. static int target_if_populate_reportset_static(
  40. struct spectralsim_context *simctx,
  41. struct spectralsim_reportset *reportset,
  42. enum phy_ch_width width, bool is_80_80);
  43. static void target_if_depopulate_reportset(
  44. struct spectralsim_reportset *
  45. reportset);
  46. static int target_if_populate_simdata(struct spectralsim_context *simctx);
  47. static void target_if_depopulate_simdata(struct spectralsim_context *simctx);
  48. static OS_TIMER_FUNC(target_if_spectral_sim_phyerrdelivery_handler);
  49. /*
  50. * Static configuration.
  51. * For now, we will be having a single configuration per BW, and a single
  52. * report per configuration (since we need the data only for ensuring correct
  53. * format handling).
  54. *
  55. * Extend this for more functionality if required in the future.
  56. */
  57. /**
  58. * target_if_populate_report_static_gen2() - Statically populate simulation
  59. * data for one report for generation 2 chipsets
  60. * @report: Pointer to spectral report data instance
  61. * @width : Channel bandwidth enumeration
  62. * @is_80_80: Whether the channel is operating in 80-80 mode
  63. *
  64. * Statically populate simulation data for one report for generation 2 chipsets
  65. *
  66. * Return: 0 on success, negative error code on failure
  67. */
  68. static int
  69. target_if_populate_report_static_gen2(
  70. struct spectralsim_report *report,
  71. enum phy_ch_width width, bool is_80_80)
  72. {
  73. qdf_assert_always(report);
  74. switch (width) {
  75. case CH_WIDTH_20MHZ:
  76. report->data = NULL;
  77. report->data = (uint8_t *)
  78. qdf_mem_malloc(sizeof(reportdata_20_gen2));
  79. if (!report->data) {
  80. spectral_err("Spectral simulation: Could not allocate memory for report data");
  81. goto bad;
  82. }
  83. report->datasize = sizeof(reportdata_20_gen2);
  84. qdf_mem_copy(report->data,
  85. reportdata_20_gen2, report->datasize);
  86. qdf_mem_copy(&report->rfqual_info,
  87. &rfqual_info_20, sizeof(report->rfqual_info));
  88. qdf_mem_copy(&report->chan_info,
  89. &chan_info_20, sizeof(report->chan_info));
  90. break;
  91. case CH_WIDTH_40MHZ:
  92. report->data = NULL;
  93. report->data = (uint8_t *)
  94. qdf_mem_malloc(sizeof(reportdata_40_gen2));
  95. if (!report->data) {
  96. spectral_err("Spectral simulation: Could not allocate memory for report data");
  97. goto bad;
  98. }
  99. report->datasize = sizeof(reportdata_40_gen2);
  100. qdf_mem_copy(report->data,
  101. reportdata_40_gen2, report->datasize);
  102. qdf_mem_copy(&report->rfqual_info,
  103. &rfqual_info_40, sizeof(report->rfqual_info));
  104. qdf_mem_copy(&report->chan_info,
  105. &chan_info_40, sizeof(report->chan_info));
  106. break;
  107. case CH_WIDTH_80MHZ:
  108. report->data = NULL;
  109. report->data = (uint8_t *)
  110. qdf_mem_malloc(sizeof(reportdata_80_gen2));
  111. if (!report->data) {
  112. spectral_err("Spectral simulation: Could not allocate memory for report data");
  113. goto bad;
  114. }
  115. report->datasize = sizeof(reportdata_80_gen2);
  116. qdf_mem_copy(report->data,
  117. reportdata_80_gen2, report->datasize);
  118. qdf_mem_copy(&report->rfqual_info,
  119. &rfqual_info_80, sizeof(report->rfqual_info));
  120. qdf_mem_copy(&report->chan_info,
  121. &chan_info_80, sizeof(report->chan_info));
  122. break;
  123. case CH_WIDTH_160MHZ:
  124. if (is_80_80) {
  125. report->data = NULL;
  126. report->data = (uint8_t *)
  127. qdf_mem_malloc(sizeof(reportdata_80_80_gen2));
  128. if (!report->data) {
  129. spectral_err("Spectral simulation: Could not allocate memory for report data");
  130. goto bad;
  131. }
  132. report->datasize = sizeof(reportdata_80_80_gen2);
  133. qdf_mem_copy(report->data,
  134. reportdata_80_80_gen2, report->datasize);
  135. qdf_mem_copy(&report->rfqual_info,
  136. &rfqual_info_80_80,
  137. sizeof(report->rfqual_info));
  138. qdf_mem_copy(&report->chan_info,
  139. &chan_info_80_80,
  140. sizeof(report->chan_info));
  141. } else {
  142. report->data = NULL;
  143. report->data = (uint8_t *)
  144. qdf_mem_malloc(sizeof(reportdata_160_gen2));
  145. if (!report->data) {
  146. spectral_err("Spectral simulation: Could not allocate memory for report data");
  147. goto bad;
  148. }
  149. report->datasize = sizeof(reportdata_160_gen2);
  150. qdf_mem_copy(report->data,
  151. reportdata_160_gen2, report->datasize);
  152. qdf_mem_copy(&report->rfqual_info,
  153. &rfqual_info_160,
  154. sizeof(report->rfqual_info));
  155. qdf_mem_copy(&report->chan_info,
  156. &chan_info_160, sizeof(report->chan_info));
  157. }
  158. break;
  159. default:
  160. spectral_err("Unhandled width. Please correct. Asserting");
  161. qdf_assert_always(0);
  162. }
  163. return 0;
  164. bad:
  165. return -EPERM;
  166. }
  167. /**
  168. * target_if_populate_report_static_gen3() - Statically populate simulation
  169. * data for one report for generation 3 chipsets
  170. * @report: Pointer to spectral report data instance
  171. * @width : Channel bandwidth enumeration
  172. * @is_80_80: Whether the channel is operating in 80-80 mode
  173. *
  174. * Statically populate simulation data for one report for generation 3 chipsets
  175. *
  176. * Return: 0 on success, negative error code on failure
  177. */
  178. static int
  179. target_if_populate_report_static_gen3(
  180. struct spectralsim_report *report,
  181. enum phy_ch_width width, bool is_80_80)
  182. {
  183. qdf_assert_always(report);
  184. switch (width) {
  185. case CH_WIDTH_20MHZ:
  186. report->data = NULL;
  187. report->data = (uint8_t *)
  188. qdf_mem_malloc(sizeof(reportdata_20_gen3));
  189. if (!report->data) {
  190. spectral_err("Spectral simulation: Could not allocate memory for report data");
  191. goto bad;
  192. }
  193. report->datasize = sizeof(reportdata_20_gen3);
  194. qdf_mem_copy(report->data,
  195. reportdata_20_gen3, report->datasize);
  196. qdf_mem_copy(&report->rfqual_info,
  197. &rfqual_info_20, sizeof(report->rfqual_info));
  198. qdf_mem_copy(&report->chan_info,
  199. &chan_info_20, sizeof(report->chan_info));
  200. break;
  201. case CH_WIDTH_40MHZ:
  202. report->data = NULL;
  203. report->data = (uint8_t *)
  204. qdf_mem_malloc(sizeof(reportdata_40_gen3));
  205. if (!report->data) {
  206. spectral_err("Spectral simulation: Could not allocate memory for report data");
  207. goto bad;
  208. }
  209. report->datasize = sizeof(reportdata_40_gen3);
  210. qdf_mem_copy(report->data,
  211. reportdata_40_gen3, report->datasize);
  212. qdf_mem_copy(&report->rfqual_info,
  213. &rfqual_info_40, sizeof(report->rfqual_info));
  214. qdf_mem_copy(&report->chan_info,
  215. &chan_info_40, sizeof(report->chan_info));
  216. break;
  217. case CH_WIDTH_80MHZ:
  218. report->data = NULL;
  219. report->data = (uint8_t *)
  220. qdf_mem_malloc(sizeof(reportdata_80_gen3));
  221. if (!report->data) {
  222. spectral_err("Spectral simulation: Could not allocate memory for report data");
  223. goto bad;
  224. }
  225. report->datasize = sizeof(reportdata_80_gen3);
  226. qdf_mem_copy(report->data,
  227. reportdata_80_gen3, report->datasize);
  228. qdf_mem_copy(&report->rfqual_info,
  229. &rfqual_info_80, sizeof(report->rfqual_info));
  230. qdf_mem_copy(&report->chan_info,
  231. &chan_info_80, sizeof(report->chan_info));
  232. break;
  233. case CH_WIDTH_160MHZ:
  234. if (is_80_80) {
  235. report->data = NULL;
  236. report->data = (uint8_t *)
  237. qdf_mem_malloc(sizeof(reportdata_80_80_gen3));
  238. if (!report->data) {
  239. spectral_err("Spectral simulation: Could not allocate memory for report data");
  240. goto bad;
  241. }
  242. report->datasize = sizeof(reportdata_80_80_gen3);
  243. qdf_mem_copy(report->data,
  244. reportdata_80_80_gen3, report->datasize);
  245. qdf_mem_copy(&report->rfqual_info,
  246. &rfqual_info_80_80,
  247. sizeof(report->rfqual_info));
  248. qdf_mem_copy(&report->chan_info,
  249. &chan_info_80_80,
  250. sizeof(report->chan_info));
  251. } else {
  252. report->data = NULL;
  253. report->data = (uint8_t *)
  254. qdf_mem_malloc(sizeof(reportdata_160_gen3));
  255. if (!report->data) {
  256. spectral_err("Spectral simulation: Could not allocate memory for report data");
  257. goto bad;
  258. }
  259. report->datasize = sizeof(reportdata_160_gen3);
  260. qdf_mem_copy(report->data,
  261. reportdata_160_gen3, report->datasize);
  262. qdf_mem_copy(&report->rfqual_info,
  263. &rfqual_info_160,
  264. sizeof(report->rfqual_info));
  265. qdf_mem_copy(&report->chan_info,
  266. &chan_info_160, sizeof(report->chan_info));
  267. }
  268. break;
  269. default:
  270. spectral_err("Unhandled width. Please correct. Asserting");
  271. qdf_assert_always(0);
  272. }
  273. return 0;
  274. bad:
  275. return -EPERM;
  276. }
  277. /**
  278. * target_if_depopulate_report() - Free the given instances of
  279. * struct spectralsim_report
  280. * @report: instance of struct spectralsim_report
  281. *
  282. * Free the given instances of struct spectralsim_report
  283. *
  284. * Return: None
  285. */
  286. static void
  287. target_if_depopulate_report(
  288. struct spectralsim_report *report)
  289. {
  290. if (!report)
  291. return;
  292. if (report->data) {
  293. qdf_mem_free(report->data);
  294. report->data = NULL;
  295. report->datasize = 0;
  296. }
  297. }
  298. /**
  299. * target_if_populate_reportset_static() - Statically populate simulation data
  300. * for a given configuration
  301. * @simctx: Pointer to struct spectralsim_context
  302. * @reportset: Set of spectral report data instances
  303. * @width : Channel bandwidth enumeration
  304. * @is_80_80: Whether the channel is operating in 80+80 mode
  305. *
  306. * Statically populate simulation data for a given configuration
  307. *
  308. * Return: 0 on success, negative error code on failure
  309. */
  310. static int
  311. target_if_populate_reportset_static(
  312. struct spectralsim_context *simctx,
  313. struct spectralsim_reportset *reportset,
  314. enum phy_ch_width width, bool is_80_80)
  315. {
  316. int ret = 0;
  317. struct spectralsim_report *report = NULL;
  318. qdf_assert_always(reportset);
  319. reportset->headreport = NULL;
  320. reportset->curr_report = NULL;
  321. /* For now, we populate only one report */
  322. report = (struct spectralsim_report *)
  323. qdf_mem_malloc(sizeof(struct spectralsim_report));
  324. if (!report) {
  325. spectral_err("Spectral simulation: Could not allocate memory for report.");
  326. goto bad;
  327. }
  328. qdf_mem_zero(report, sizeof(*report));
  329. switch (width) {
  330. case CH_WIDTH_20MHZ:
  331. qdf_mem_copy(&reportset->config,
  332. &config_20_1, sizeof(reportset->config));
  333. ret = simctx->populate_report_static(report, CH_WIDTH_20MHZ, 0);
  334. if (ret != 0)
  335. goto bad;
  336. report->next = NULL;
  337. reportset->headreport = report;
  338. break;
  339. case CH_WIDTH_40MHZ:
  340. qdf_mem_copy(&reportset->config,
  341. &config_40_1, sizeof(reportset->config));
  342. ret = simctx->populate_report_static(report, CH_WIDTH_40MHZ, 0);
  343. if (ret != 0)
  344. goto bad;
  345. report->next = NULL;
  346. reportset->headreport = report;
  347. break;
  348. case CH_WIDTH_80MHZ:
  349. qdf_mem_copy(&reportset->config,
  350. &config_80_1, sizeof(reportset->config));
  351. ret = simctx->populate_report_static(report, CH_WIDTH_80MHZ, 0);
  352. if (ret != 0)
  353. goto bad;
  354. report->next = NULL;
  355. reportset->headreport = report;
  356. break;
  357. case CH_WIDTH_160MHZ:
  358. if (is_80_80) {
  359. qdf_mem_copy(&reportset->config,
  360. &config_80_80_1,
  361. sizeof(reportset->config));
  362. ret = simctx->populate_report_static(report,
  363. CH_WIDTH_160MHZ,
  364. 1);
  365. if (ret != 0)
  366. goto bad;
  367. report->next = NULL;
  368. reportset->headreport = report;
  369. } else {
  370. qdf_mem_copy(&reportset->config,
  371. &config_160_1, sizeof(reportset->config));
  372. ret = simctx->populate_report_static(report,
  373. CH_WIDTH_160MHZ,
  374. 0);
  375. if (ret != 0)
  376. goto bad;
  377. report->next = NULL;
  378. reportset->headreport = report;
  379. }
  380. break;
  381. default:
  382. spectral_err("Unhandled width. Please rectify.");
  383. qdf_assert_always(0);
  384. };
  385. reportset->curr_report = reportset->headreport;
  386. return 0;
  387. bad:
  388. target_if_depopulate_reportset(reportset);
  389. return -EPERM;
  390. }
  391. /**
  392. * target_if_depopulate_reportset() - Free all the instances of
  393. * struct spectralsim_reportset
  394. * @report: head pointer to struct spectralsim_reportset linked list
  395. *
  396. * Free all the instances of struct spectralsim_reportset
  397. *
  398. * Return: None
  399. */
  400. static void
  401. target_if_depopulate_reportset(
  402. struct spectralsim_reportset *reportset)
  403. {
  404. struct spectralsim_report *curr_report = NULL;
  405. struct spectralsim_report *next_report = NULL;
  406. if (!reportset)
  407. return;
  408. curr_report = reportset->headreport;
  409. while (curr_report) {
  410. next_report = curr_report->next;
  411. target_if_depopulate_report(curr_report);
  412. qdf_mem_free(curr_report);
  413. curr_report = next_report;
  414. }
  415. }
  416. /**
  417. * target_if_populate_simdata() - Populate simulation data
  418. * @simctx: Pointer to struct spectralsim_context
  419. *
  420. * Populate simulation data
  421. *
  422. * Return: 0 on success, negative error code on failure
  423. */
  424. static int
  425. target_if_populate_simdata(
  426. struct spectralsim_context *simctx)
  427. {
  428. /*
  429. * For now, we use static population. Switch to loading from a file if
  430. * needed in the future.
  431. */
  432. simctx->bw20_headreportset = NULL;
  433. SPECTRAL_SIM_REPORTSET_ALLOCPOPL_SINGLE(simctx,
  434. simctx->bw20_headreportset,
  435. CH_WIDTH_20MHZ, 0);
  436. simctx->bw40_headreportset = NULL;
  437. SPECTRAL_SIM_REPORTSET_ALLOCPOPL_SINGLE(simctx,
  438. simctx->bw40_headreportset,
  439. CH_WIDTH_40MHZ, 0);
  440. simctx->bw80_headreportset = NULL;
  441. SPECTRAL_SIM_REPORTSET_ALLOCPOPL_SINGLE(simctx,
  442. simctx->bw80_headreportset,
  443. CH_WIDTH_80MHZ, 0);
  444. simctx->bw160_headreportset = NULL;
  445. SPECTRAL_SIM_REPORTSET_ALLOCPOPL_SINGLE(simctx,
  446. simctx->bw160_headreportset,
  447. CH_WIDTH_160MHZ, 0);
  448. simctx->bw80_80_headreportset = NULL;
  449. SPECTRAL_SIM_REPORTSET_ALLOCPOPL_SINGLE(simctx,
  450. simctx->bw80_80_headreportset,
  451. CH_WIDTH_160MHZ, 1);
  452. simctx->curr_reportset = NULL;
  453. simctx->is_enabled = false;
  454. simctx->is_active = false;
  455. simctx->ssim_starting_tsf64 = 0;
  456. simctx->ssim_count = 0;
  457. simctx->ssim_period_ms = 0;
  458. return 0;
  459. }
  460. /**
  461. * target_if_depopulate_simdata() - De-populate simulation data
  462. * @simctx: Pointer to struct spectralsim_context
  463. *
  464. * De-populate simulation data
  465. *
  466. * Return: none
  467. */
  468. static void
  469. target_if_depopulate_simdata(
  470. struct spectralsim_context *simctx)
  471. {
  472. if (!simctx)
  473. return;
  474. SPECTRAL_SIM_REPORTSET_DEPOPLFREE_LIST(simctx->bw20_headreportset);
  475. SPECTRAL_SIM_REPORTSET_DEPOPLFREE_LIST(simctx->bw40_headreportset);
  476. SPECTRAL_SIM_REPORTSET_DEPOPLFREE_LIST(simctx->bw80_headreportset);
  477. SPECTRAL_SIM_REPORTSET_DEPOPLFREE_LIST(simctx->bw160_headreportset);
  478. SPECTRAL_SIM_REPORTSET_DEPOPLFREE_LIST(simctx->bw80_80_headreportset);
  479. }
  480. /**
  481. * target_if_spectral_sim_phyerrdelivery_handler() - Phyerr delivery handler
  482. *
  483. * Return: none
  484. */
  485. static
  486. OS_TIMER_FUNC(target_if_spectral_sim_phyerrdelivery_handler)
  487. {
  488. struct target_if_spectral *spectral = NULL;
  489. struct spectralsim_context *simctx = NULL;
  490. struct spectralsim_reportset *curr_reportset = NULL;
  491. struct spectralsim_report *curr_report = NULL;
  492. struct target_if_spectral_acs_stats acs_stats;
  493. uint64_t curr_tsf64 = 0;
  494. struct target_if_spectral_ops *p_sops;
  495. OS_GET_TIMER_ARG(spectral, struct target_if_spectral *);
  496. qdf_assert_always(spectral);
  497. p_sops = GET_TARGET_IF_SPECTRAL_OPS(spectral);
  498. qdf_assert_always(spectral);
  499. simctx = (struct spectralsim_context *)spectral->simctx;
  500. qdf_assert_always(simctx);
  501. if (!simctx->is_active)
  502. return;
  503. curr_reportset = simctx->curr_reportset;
  504. qdf_assert_always(curr_reportset);
  505. curr_report = curr_reportset->curr_report;
  506. qdf_assert_always(curr_report);
  507. qdf_assert_always(curr_reportset->headreport);
  508. /*
  509. * We use a simulation TSF since in offload architectures we can't
  510. * expect to
  511. * get an accurate current TSF from HW.
  512. * In case of TSF wrap over, we'll use it as-is for now since the
  513. * simulation
  514. * is intended only for format verification.
  515. */
  516. curr_tsf64 = simctx->ssim_starting_tsf64 +
  517. ((simctx->ssim_period_ms * simctx->ssim_count) * 1000);
  518. p_sops->spectral_process_phyerr(spectral,
  519. curr_report->data,
  520. curr_report->datasize,
  521. &curr_report->rfqual_info,
  522. &curr_report->chan_info,
  523. curr_tsf64, &acs_stats);
  524. simctx->ssim_count++;
  525. if (curr_report->next)
  526. curr_reportset->curr_report = curr_report->next;
  527. else
  528. curr_reportset->curr_report = curr_reportset->headreport;
  529. if (curr_reportset->config.ss_count != 0 &&
  530. simctx->ssim_count == curr_reportset->config.ss_count) {
  531. target_if_spectral_sops_sim_stop_scan(spectral);
  532. } else {
  533. qdf_timer_start(&simctx->ssim_pherrdelivery_timer,
  534. simctx->ssim_period_ms);
  535. }
  536. }
  537. /* Module services */
  538. int
  539. target_if_spectral_sim_attach(struct target_if_spectral *spectral)
  540. {
  541. struct spectralsim_context *simctx = NULL;
  542. qdf_assert_always(spectral);
  543. simctx = (struct spectralsim_context *)
  544. qdf_mem_malloc(sizeof(struct spectralsim_context));
  545. if (!simctx) {
  546. spectral_err("Spectral simulation: Could not allocate memory for context");
  547. return -EPERM;
  548. }
  549. qdf_mem_zero(simctx, sizeof(*simctx));
  550. spectral->simctx = simctx;
  551. if (spectral->spectral_gen == SPECTRAL_GEN2)
  552. simctx->populate_report_static =
  553. target_if_populate_report_static_gen2;
  554. else if (spectral->spectral_gen == SPECTRAL_GEN3)
  555. simctx->populate_report_static =
  556. target_if_populate_report_static_gen3;
  557. if (target_if_populate_simdata(simctx) != 0) {
  558. qdf_mem_free(simctx);
  559. spectral->simctx = NULL;
  560. spectral_err("Spectral simulation attach failed");
  561. return -EPERM;
  562. }
  563. qdf_timer_init(NULL,
  564. &simctx->ssim_pherrdelivery_timer,
  565. target_if_spectral_sim_phyerrdelivery_handler,
  566. (void *)(spectral), QDF_TIMER_TYPE_WAKE_APPS);
  567. spectral_info("Spectral simulation attached");
  568. return 0;
  569. }
  570. void
  571. target_if_spectral_sim_detach(struct target_if_spectral *spectral)
  572. {
  573. struct spectralsim_context *simctx = NULL;
  574. qdf_assert_always(spectral);
  575. simctx = (struct spectralsim_context *)spectral->simctx;
  576. qdf_assert_always(simctx);
  577. qdf_timer_free(&simctx->ssim_pherrdelivery_timer);
  578. target_if_depopulate_simdata(simctx);
  579. qdf_mem_free(simctx);
  580. spectral->simctx = NULL;
  581. spectral_info("Spectral simulation detached");
  582. }
  583. uint32_t
  584. target_if_spectral_sops_sim_is_active(void *arg)
  585. {
  586. struct target_if_spectral *spectral = NULL;
  587. struct spectralsim_context *simctx = NULL;
  588. spectral = (struct target_if_spectral *)arg;
  589. qdf_assert_always(spectral);
  590. simctx = (struct spectralsim_context *)spectral->simctx;
  591. qdf_assert_always(simctx);
  592. return simctx->is_active;
  593. }
  594. qdf_export_symbol(target_if_spectral_sops_sim_is_active);
  595. uint32_t
  596. target_if_spectral_sops_sim_is_enabled(void *arg)
  597. {
  598. struct target_if_spectral *spectral = NULL;
  599. struct spectralsim_context *simctx = NULL;
  600. spectral = (struct target_if_spectral *)arg;
  601. qdf_assert_always(spectral);
  602. simctx = (struct spectralsim_context *)spectral->simctx;
  603. qdf_assert_always(simctx);
  604. return simctx->is_enabled;
  605. }
  606. qdf_export_symbol(target_if_spectral_sops_sim_is_enabled);
  607. uint32_t
  608. target_if_spectral_sops_sim_start_scan(void *arg)
  609. {
  610. struct target_if_spectral *spectral = NULL;
  611. struct spectralsim_context *simctx = NULL;
  612. spectral = (struct target_if_spectral *)arg;
  613. qdf_assert_always(spectral);
  614. simctx = (struct spectralsim_context *)spectral->simctx;
  615. qdf_assert_always(simctx);
  616. if (!simctx->curr_reportset) {
  617. spectral_err("Spectral simulation: No current report set configured - unable to start simulated Spectral scan");
  618. return 0;
  619. }
  620. if (!simctx->curr_reportset->curr_report) {
  621. spectral_err("Spectral simulation: No report data instances populated - unable to start simulated Spectral scan");
  622. return 0;
  623. }
  624. if (!simctx->is_enabled)
  625. simctx->is_enabled = true;
  626. simctx->is_active = true;
  627. /* Hardcoding current time as zero since it is simulation */
  628. simctx->ssim_starting_tsf64 = 0;
  629. simctx->ssim_count = 0;
  630. /*
  631. * TODO: Support high resolution timer in microseconds if required, so
  632. * that
  633. * we can support default periods such as ~200 us. For now, we use 1
  634. * millisecond since the current use case for the simulation is to
  635. * validate
  636. * formats rather than have a time dependent classification.
  637. */
  638. simctx->ssim_period_ms = 1;
  639. qdf_timer_start(&simctx->ssim_pherrdelivery_timer,
  640. simctx->ssim_period_ms);
  641. return 1;
  642. }
  643. qdf_export_symbol(target_if_spectral_sops_sim_start_scan);
  644. uint32_t
  645. target_if_spectral_sops_sim_stop_scan(void *arg)
  646. {
  647. struct target_if_spectral *spectral = NULL;
  648. struct spectralsim_context *simctx = NULL;
  649. spectral = (struct target_if_spectral *)arg;
  650. qdf_assert_always(spectral);
  651. simctx = (struct spectralsim_context *)spectral->simctx;
  652. qdf_assert_always(simctx);
  653. qdf_timer_stop(&simctx->ssim_pherrdelivery_timer);
  654. simctx->is_active = false;
  655. simctx->is_enabled = false;
  656. simctx->ssim_starting_tsf64 = 0;
  657. simctx->ssim_count = 0;
  658. simctx->ssim_period_ms = 0;
  659. return 1;
  660. }
  661. qdf_export_symbol(target_if_spectral_sops_sim_stop_scan);
  662. #ifdef SPECTRAL_SIM_DUMP_PARAM_DATA
  663. static void
  664. target_if_log_sim_spectral_params(struct spectral_config *params)
  665. {
  666. int i = 0;
  667. spectral_debug("\n");
  668. spectral_debug("Spectral simulation: Param data dump:\nss_fft_period=%hu\nss_period=%hu\nss_count=%hu\nss_short_report=%hu\nradar_bin_thresh_sel=%hhu\nss_spectral_pri=%hu\nss_fft_size=%hu\nss_gc_ena=%hu\nss_restart_ena=%hu\nss_noise_floor_ref=%hu\nss_init_delay=%hu\nss_nb_tone_thr=%hu\nss_str_bin_thr=%hu\nss_wb_rpt_mode=%hu\nss_rssi_rpt_mode=%hu\nss_rssi_thr=%hu\nss_pwr_format=%hu\nss_rpt_mode=%hu\nss_bin_scale=%hu\nss_dbm_adj=%hu\nss_chn_mask=%hu\nss_nf_temp_data=%d",
  669. params->ss_fft_period,
  670. params->ss_period,
  671. params->ss_count,
  672. params->ss_short_report,
  673. params->radar_bin_thresh_sel,
  674. params->ss_spectral_pri,
  675. params->ss_fft_size,
  676. params->ss_gc_ena,
  677. params->ss_restart_ena,
  678. params->ss_noise_floor_ref,
  679. params->ss_init_delay,
  680. params->ss_nb_tone_thr,
  681. params->ss_str_bin_thr,
  682. params->ss_wb_rpt_mode,
  683. params->ss_rssi_rpt_mode,
  684. params->ss_rssi_thr,
  685. params->ss_pwr_format,
  686. params->ss_rpt_mode,
  687. params->ss_bin_scale,
  688. params->ss_dbm_adj,
  689. params->ss_chn_mask, params->ss_nf_temp_data);
  690. for (i = 0; i < AH_MAX_CHAINS * 2; i++)
  691. spectral_debug("ss_nf_cal[%d]=%hhd", i, params->ss_nf_cal[i]);
  692. for (i = 0; i < AH_MAX_CHAINS * 2; i++)
  693. spectral_debug("ss_nf_pwr[%d]=%hhd", i, params->ss_nf_pwr[i]);
  694. spectral_info("\n");
  695. }
  696. #else
  697. static void
  698. target_if_log_sim_spectral_params(struct spectral_config *params)
  699. {
  700. }
  701. #endif /* SPECTRAL_SIM_DUMP_PARAM_DATA */
  702. uint32_t
  703. target_if_spectral_sops_sim_configure_params(
  704. void *arg,
  705. struct spectral_config *params)
  706. {
  707. struct target_if_spectral *spectral = NULL;
  708. struct spectralsim_context *simctx = NULL;
  709. enum wlan_phymode phymode;
  710. uint8_t bw;
  711. struct spectralsim_reportset *des_headreportset = NULL;
  712. struct spectralsim_reportset *temp_reportset = NULL;
  713. bool is_invalid_width = false;
  714. struct wlan_objmgr_vdev *vdev = NULL;
  715. qdf_assert_always(params);
  716. target_if_log_sim_spectral_params(params);
  717. spectral = (struct target_if_spectral *)arg;
  718. qdf_assert_always(spectral);
  719. simctx = (struct spectralsim_context *)spectral->simctx;
  720. qdf_assert_always(simctx);
  721. vdev = target_if_spectral_get_vdev(spectral);
  722. if (!vdev) {
  723. spectral_warn("Spectral simulation: No VAPs found - not proceeding with param config.");
  724. return 0;
  725. }
  726. bw = target_if_vdev_get_ch_width(vdev);
  727. switch (bw) {
  728. case CH_WIDTH_20MHZ:
  729. des_headreportset = simctx->bw20_headreportset;
  730. break;
  731. case CH_WIDTH_40MHZ:
  732. des_headreportset = simctx->bw40_headreportset;
  733. break;
  734. case CH_WIDTH_80MHZ:
  735. des_headreportset = simctx->bw80_headreportset;
  736. break;
  737. case CH_WIDTH_160MHZ:
  738. phymode = wlan_vdev_get_phymode(vdev);
  739. if (phymode == WLAN_PHYMODE_11AC_VHT160) {
  740. des_headreportset = simctx->bw160_headreportset;
  741. } else if (phymode == WLAN_PHYMODE_11AC_VHT80_80) {
  742. des_headreportset = simctx->bw80_80_headreportset;
  743. } else {
  744. spectral_err("Spectral simulation: Unexpected PHY mode %u found for width 160 MHz...asserting.",
  745. phymode);
  746. qdf_assert_always(0);
  747. }
  748. break;
  749. case IEEE80211_CWM_WIDTHINVALID:
  750. spectral_err("Spectral simulation: Invalid width configured - not proceeding with param config.");
  751. is_invalid_width = true;
  752. default:
  753. spectral_err("Spectral simulation: Unknown width %u...asserting",
  754. bw);
  755. qdf_assert_always(0);
  756. break;
  757. }
  758. wlan_objmgr_vdev_release_ref(vdev, WLAN_SPECTRAL_ID);
  759. if (is_invalid_width)
  760. return 0;
  761. if (!des_headreportset) {
  762. spectral_warn("Spectral simulation: No simulation data present for configured bandwidth/PHY mode - unable to proceed with param config.");
  763. return 0;
  764. }
  765. simctx->curr_reportset = NULL;
  766. temp_reportset = des_headreportset;
  767. while (temp_reportset) {
  768. if (qdf_mem_cmp(&temp_reportset->config,
  769. params, sizeof(struct spectral_config)) == 0) {
  770. /* Found a matching config. We are done. */
  771. simctx->curr_reportset = temp_reportset;
  772. break;
  773. }
  774. temp_reportset = temp_reportset->next;
  775. }
  776. if (!simctx->curr_reportset) {
  777. spectral_warn("Spectral simulation: No simulation data present for desired Spectral configuration - unable to proceed with param config.");
  778. return 0;
  779. }
  780. if (!simctx->curr_reportset->curr_report) {
  781. spectral_warn("Spectral simulation: No report data instances populated for desired Spectral configuration - unable to proceed with param config");
  782. return 0;
  783. }
  784. return 1;
  785. }
  786. qdf_export_symbol(target_if_spectral_sops_sim_configure_params);
  787. uint32_t
  788. target_if_spectral_sops_sim_get_params(
  789. void *arg, struct spectral_config *params)
  790. {
  791. struct target_if_spectral *spectral = NULL;
  792. struct spectralsim_context *simctx = NULL;
  793. qdf_assert_always(params);
  794. spectral = (struct target_if_spectral *)arg;
  795. qdf_assert_always(spectral);
  796. simctx = (struct spectralsim_context *)spectral->simctx;
  797. qdf_assert_always(simctx);
  798. if (!simctx->curr_reportset) {
  799. spectral_warn("Spectral simulation: No configured reportset found.");
  800. return 0;
  801. }
  802. qdf_mem_copy(params, &simctx->curr_reportset->config, sizeof(*params));
  803. return 1;
  804. }
  805. qdf_export_symbol(target_if_spectral_sops_sim_get_params);
  806. #endif /* QCA_SUPPORT_SPECTRAL_SIMULATION */