wlan_dsc_test.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "__wlan_dsc.h"
  19. #include "qdf_event.h"
  20. #include "qdf_threads.h"
  21. #include "qdf_trace.h"
  22. #include "qdf_types.h"
  23. #include "wlan_dsc.h"
  24. #include "wlan_dsc_test.h"
  25. #include "cds_api.h"
  26. #define dsc_driver_trans_start(driver) dsc_driver_trans_start(driver, __func__)
  27. #define dsc_psoc_trans_start(psoc) dsc_psoc_trans_start(psoc, __func__)
  28. #define dsc_vdev_trans_start(vdev) dsc_vdev_trans_start(vdev, __func__)
  29. #define dsc_driver_trans_start_wait(driver) \
  30. dsc_driver_trans_start_wait(driver, "")
  31. #define dsc_psoc_trans_start_wait(psoc) \
  32. dsc_psoc_trans_start_wait(psoc, __func__)
  33. #define dsc_vdev_trans_start_wait(vdev) \
  34. dsc_vdev_trans_start_wait(vdev, __func__)
  35. static struct dsc_psoc *nth_psoc(struct dsc_driver *driver, int n)
  36. {
  37. struct dsc_psoc *psoc;
  38. QDF_BUG(n > 0);
  39. if (n <= 0)
  40. return NULL;
  41. dsc_for_each_driver_psoc(driver, psoc) {
  42. n--;
  43. if (n)
  44. continue;
  45. return psoc;
  46. }
  47. QDF_DEBUG_PANIC("Failed to find nth psoc: %d", n);
  48. return NULL;
  49. }
  50. static struct dsc_vdev *nth_vdev(struct dsc_psoc *psoc, int n)
  51. {
  52. struct dsc_vdev *vdev;
  53. QDF_BUG(n > 0);
  54. if (n <= 0)
  55. return NULL;
  56. dsc_for_each_psoc_vdev(psoc, vdev) {
  57. n--;
  58. if (n)
  59. continue;
  60. return vdev;
  61. }
  62. QDF_DEBUG_PANIC("Failed to find nth vdev: %d", n);
  63. return NULL;
  64. }
  65. static void __dsc_tree_destroy(struct dsc_driver *driver)
  66. {
  67. struct dsc_psoc *psoc;
  68. struct dsc_psoc *next_psoc;
  69. QDF_BUG(driver);
  70. qdf_list_for_each_del(&driver->psocs, psoc, next_psoc, node) {
  71. struct dsc_vdev *vdev;
  72. struct dsc_vdev *next_vdev;
  73. qdf_list_for_each_del(&psoc->vdevs, vdev, next_vdev, node)
  74. dsc_vdev_destroy(&vdev);
  75. dsc_psoc_destroy(&psoc);
  76. }
  77. dsc_driver_destroy(&driver);
  78. }
  79. static QDF_STATUS __dsc_tree_create(struct dsc_driver **out_driver,
  80. uint8_t psocs_per_driver,
  81. uint8_t vdevs_per_psoc)
  82. {
  83. QDF_STATUS status;
  84. struct dsc_driver *driver;
  85. int i, j;
  86. status = dsc_driver_create(&driver);
  87. if (QDF_IS_STATUS_ERROR(status)) {
  88. dsc_err("Failed to create driver; status:%u", status);
  89. return status;
  90. }
  91. for (i = 0; i < psocs_per_driver; i++) {
  92. struct dsc_psoc *psoc;
  93. status = dsc_psoc_create(driver, &psoc);
  94. if (QDF_IS_STATUS_ERROR(status)) {
  95. dsc_err("Failed to create psoc; status:%u", status);
  96. goto free_tree;
  97. }
  98. for (j = 0; j < vdevs_per_psoc; j++) {
  99. struct dsc_vdev *vdev;
  100. status = dsc_vdev_create(psoc, &vdev);
  101. if (QDF_IS_STATUS_ERROR(status)) {
  102. dsc_err("Failed to create vdev; status:%u",
  103. status);
  104. goto free_tree;
  105. }
  106. }
  107. }
  108. *out_driver = driver;
  109. return QDF_STATUS_SUCCESS;
  110. free_tree:
  111. __dsc_tree_destroy(driver);
  112. return status;
  113. }
  114. static uint32_t dsc_test_create_destroy(void)
  115. {
  116. uint32_t errors = 0;
  117. QDF_STATUS status;
  118. struct dsc_driver *driver;
  119. dsc_enter();
  120. status = __dsc_tree_create(&driver, 2, 2);
  121. if (QDF_IS_STATUS_ERROR(status)) {
  122. errors++;
  123. goto exit;
  124. }
  125. __dsc_tree_destroy(driver);
  126. exit:
  127. dsc_exit();
  128. return errors;
  129. }
  130. #define action_expect(obj, action, status, errors) \
  131. do { \
  132. void *__obj = obj; \
  133. QDF_STATUS __expected = status; \
  134. QDF_STATUS __result; \
  135. \
  136. __result = dsc_##obj##_##action##_start(__obj); \
  137. if (__result != __expected) { \
  138. dsc_err("FAIL: " #obj " " #action \
  139. "; expected " #status " (%u), found %u", \
  140. __expected, __result); \
  141. (errors)++; \
  142. } \
  143. if (QDF_IS_STATUS_SUCCESS(__result) && QDF_IS_STATUS_ERROR(__expected))\
  144. dsc_##obj##_##action##_stop(__obj); \
  145. } while (false)
  146. static uint32_t dsc_test_driver_trans_blocks(void)
  147. {
  148. uint32_t errors = 0;
  149. QDF_STATUS status;
  150. struct dsc_driver *driver;
  151. struct dsc_psoc *psoc;
  152. struct dsc_vdev *vdev;
  153. dsc_enter();
  154. /* setup */
  155. status = __dsc_tree_create(&driver, 2, 2);
  156. if (QDF_IS_STATUS_ERROR(status)) {
  157. errors++;
  158. goto exit;
  159. }
  160. /* test */
  161. /* a driver in transition should cause ... */
  162. action_expect(driver, trans, QDF_STATUS_SUCCESS, errors);
  163. /* ... the same driver trans/ops to fail */
  164. action_expect(driver, trans, QDF_STATUS_E_AGAIN, errors);
  165. action_expect(driver, op, QDF_STATUS_E_AGAIN, errors);
  166. /* ... children psoc trans/ops to fail */
  167. dsc_for_each_driver_psoc(driver, psoc) {
  168. action_expect(psoc, trans, QDF_STATUS_E_INVAL, errors);
  169. action_expect(psoc, op, QDF_STATUS_E_INVAL, errors);
  170. /* ... grandchildren vdev trans/ops to fail */
  171. dsc_for_each_psoc_vdev(psoc, vdev) {
  172. action_expect(vdev, trans, QDF_STATUS_E_INVAL, errors);
  173. action_expect(vdev, op, QDF_STATUS_E_INVAL, errors);
  174. }
  175. }
  176. /* teardown */
  177. dsc_driver_trans_stop(driver);
  178. __dsc_tree_destroy(driver);
  179. exit:
  180. dsc_exit();
  181. return errors;
  182. }
  183. static uint32_t dsc_test_psoc_trans_blocks(void)
  184. {
  185. uint32_t errors = 0;
  186. QDF_STATUS status;
  187. struct dsc_driver *driver;
  188. struct dsc_psoc *psoc;
  189. struct dsc_vdev *vdev;
  190. dsc_enter();
  191. /* setup */
  192. status = __dsc_tree_create(&driver, 2, 2);
  193. if (QDF_IS_STATUS_ERROR(status)) {
  194. errors++;
  195. goto exit;
  196. }
  197. /* test */
  198. /* a psoc in transition should cause ... */
  199. psoc = nth_psoc(driver, 1);
  200. action_expect(psoc, trans, QDF_STATUS_SUCCESS, errors);
  201. /* ... driver trans/ops to fail */
  202. action_expect(driver, trans, QDF_STATUS_E_AGAIN, errors);
  203. action_expect(driver, op, QDF_STATUS_E_AGAIN, errors);
  204. /* ... the same psoc trans/ops to fail */
  205. action_expect(psoc, trans, QDF_STATUS_E_AGAIN, errors);
  206. action_expect(psoc, op, QDF_STATUS_E_AGAIN, errors);
  207. /* ... children vdev trans/ops to fail */
  208. dsc_for_each_psoc_vdev(psoc, vdev) {
  209. action_expect(vdev, trans, QDF_STATUS_E_AGAIN, errors);
  210. action_expect(vdev, op, QDF_STATUS_E_AGAIN, errors);
  211. }
  212. /* ... while driver unload in progress vdev op and trans should be
  213. * rejected with EINVAL
  214. */
  215. cds_set_unload_in_progress(true);
  216. dsc_for_each_psoc_vdev(psoc, vdev) {
  217. action_expect(vdev, trans, QDF_STATUS_E_INVAL, errors);
  218. action_expect(vdev, op, QDF_STATUS_E_INVAL, errors);
  219. }
  220. cds_set_unload_in_progress(false);
  221. /* ... while SSR recovery in progress vdev op and trans should be
  222. * rejected with EINVAL
  223. */
  224. cds_set_recovery_in_progress(true);
  225. dsc_for_each_psoc_vdev(psoc, vdev) {
  226. action_expect(vdev, trans, QDF_STATUS_E_INVAL, errors);
  227. action_expect(vdev, op, QDF_STATUS_E_INVAL, errors);
  228. }
  229. cds_set_recovery_in_progress(false);
  230. /* a sibling psoc in transition should succeed and cause ... */
  231. psoc = nth_psoc(driver, 2);
  232. action_expect(psoc, trans, QDF_STATUS_SUCCESS, errors);
  233. /* ... driver trans/ops to fail */
  234. action_expect(driver, trans, QDF_STATUS_E_AGAIN, errors);
  235. action_expect(driver, op, QDF_STATUS_E_AGAIN, errors);
  236. /* ... the same psoc trans/ops to fail */
  237. action_expect(psoc, trans, QDF_STATUS_E_AGAIN, errors);
  238. action_expect(psoc, op, QDF_STATUS_E_AGAIN, errors);
  239. /* ... children vdev trans/ops to fail */
  240. dsc_for_each_psoc_vdev(psoc, vdev) {
  241. action_expect(vdev, trans, QDF_STATUS_E_AGAIN, errors);
  242. action_expect(vdev, op, QDF_STATUS_E_AGAIN, errors);
  243. }
  244. /* teardown */
  245. dsc_for_each_driver_psoc(driver, psoc)
  246. dsc_psoc_trans_stop(psoc);
  247. __dsc_tree_destroy(driver);
  248. exit:
  249. dsc_exit();
  250. return errors;
  251. }
  252. static uint32_t dsc_test_vdev_trans_blocks(void)
  253. {
  254. uint32_t errors = 0;
  255. QDF_STATUS status;
  256. struct dsc_driver *driver;
  257. struct dsc_psoc *psoc;
  258. struct dsc_vdev *vdev;
  259. dsc_enter();
  260. /* setup */
  261. status = __dsc_tree_create(&driver, 2, 2);
  262. if (QDF_IS_STATUS_ERROR(status)) {
  263. errors++;
  264. goto exit;
  265. }
  266. /* test */
  267. /* a vdev in transition should cause ... */
  268. dsc_for_each_driver_psoc(driver, psoc) {
  269. dsc_for_each_psoc_vdev(psoc, vdev)
  270. action_expect(vdev, trans, QDF_STATUS_SUCCESS, errors);
  271. }
  272. /* ... driver trans/ops to fail */
  273. action_expect(driver, trans, QDF_STATUS_E_AGAIN, errors);
  274. action_expect(driver, op, QDF_STATUS_E_AGAIN, errors);
  275. /* ... psoc trans/ops to fail */
  276. dsc_for_each_driver_psoc(driver, psoc) {
  277. action_expect(psoc, trans, QDF_STATUS_E_AGAIN, errors);
  278. action_expect(psoc, op, QDF_STATUS_E_AGAIN, errors);
  279. /* ... the same vdev trans/ops to fail */
  280. dsc_for_each_psoc_vdev(psoc, vdev) {
  281. action_expect(vdev, trans, QDF_STATUS_E_AGAIN, errors);
  282. action_expect(vdev, op, QDF_STATUS_E_AGAIN, errors);
  283. }
  284. }
  285. /* teardown */
  286. dsc_for_each_driver_psoc(driver, psoc) {
  287. dsc_for_each_psoc_vdev(psoc, vdev)
  288. dsc_vdev_trans_stop(vdev);
  289. }
  290. __dsc_tree_destroy(driver);
  291. exit:
  292. dsc_exit();
  293. return errors;
  294. }
  295. #define THREAD_TIMEOUT 1000 /* ms */
  296. #define dsc_event_wait(event) qdf_wait_single_event(event, THREAD_TIMEOUT)
  297. #define step_assert(field, expected) \
  298. do { \
  299. uint32_t _step = ++(field); \
  300. uint32_t _expected = (expected); \
  301. \
  302. if (_step != _expected) \
  303. QDF_DEBUG_PANIC("Step count is %u; Expected %u", \
  304. _step, _expected); \
  305. } while (false)
  306. #define trans_waiting(ctx) (!qdf_list_empty(&(ctx)->trans.queue))
  307. struct thread_ctx {
  308. struct dsc_driver *driver;
  309. qdf_event_t start_vdev_trans;
  310. qdf_event_t start_vdev_wait;
  311. uint32_t step;
  312. };
  313. static QDF_STATUS dsc_thread_ops(void *context)
  314. {
  315. struct thread_ctx *ctx = context;
  316. struct dsc_driver *driver = ctx->driver;
  317. struct dsc_psoc *psoc = nth_psoc(driver, 1);
  318. struct dsc_vdev *vdev = nth_vdev(psoc, 1);
  319. dsc_enter();
  320. /* thread 1 is doing some operations ... */
  321. step_assert(ctx->step, 1);
  322. dsc_assert_success(dsc_driver_op_start(driver));
  323. dsc_assert_success(dsc_psoc_op_start(psoc));
  324. dsc_assert_success(dsc_vdev_op_start(vdev));
  325. step_assert(ctx->step, 2);
  326. /* ... at which point, thread 2 starts to transition the vdevs */
  327. qdf_event_set(&ctx->start_vdev_trans);
  328. /* meanwhile, thread 3,4,5 queue up to transition vdev/psoc/driver */
  329. while (!trans_waiting(driver))
  330. schedule();
  331. /* at this point, each thread is:
  332. * 1) doing operations
  333. * 2) transitioning vdevs 1/2, waiting for ops to finish
  334. * 3) waiting to transition vdev 1
  335. * 4) waiting to transition psoc
  336. * 5) waitint to transition driver
  337. */
  338. step_assert(ctx->step, 8);
  339. dsc_driver_op_stop(driver);
  340. schedule();
  341. dsc_psoc_op_stop(psoc);
  342. schedule();
  343. dsc_vdev_op_stop(vdev);
  344. /* all operations complete; thread2 is now unblocked */
  345. dsc_exit();
  346. return QDF_STATUS_SUCCESS;
  347. }
  348. static QDF_STATUS dsc_thread_vdev_trans(void *context)
  349. {
  350. struct thread_ctx *ctx = context;
  351. struct dsc_driver *driver = ctx->driver;
  352. struct dsc_psoc *psoc = nth_psoc(driver, 1);
  353. struct dsc_vdev *vdev;
  354. dsc_enter();
  355. /* wait for thread 1 to start operations */
  356. dsc_assert_success(dsc_event_wait(&ctx->start_vdev_trans));
  357. /* start transitions on all vdevs */
  358. step_assert(ctx->step, 3);
  359. dsc_for_each_psoc_vdev(psoc, vdev)
  360. dsc_assert_success(dsc_vdev_trans_start(vdev));
  361. step_assert(ctx->step, 4);
  362. /* meanwhile, thread 3,4,5 queue up to transition vdev/psoc/driver */
  363. qdf_event_set(&ctx->start_vdev_wait);
  364. /* wait for thread 1 to complete pending vdev ops */
  365. dsc_for_each_psoc_vdev(psoc, vdev)
  366. dsc_vdev_wait_for_ops(vdev);
  367. /* actual vdev transition work would happen here */
  368. /* stop transition on vdev 1 */
  369. step_assert(ctx->step, 9);
  370. dsc_vdev_trans_stop(nth_vdev(psoc, 1));
  371. /* psoc trans should not start until both vdev trans are complete */
  372. schedule();
  373. step_assert(ctx->step, 10);
  374. dsc_vdev_trans_stop(nth_vdev(psoc, 2));
  375. dsc_exit();
  376. return QDF_STATUS_SUCCESS;
  377. }
  378. static QDF_STATUS dsc_thread_vdev_wait(void *context)
  379. {
  380. struct thread_ctx *ctx = context;
  381. struct dsc_vdev *vdev = nth_vdev(nth_psoc(ctx->driver, 1), 1);
  382. dsc_enter();
  383. dsc_assert_success(dsc_event_wait(&ctx->start_vdev_wait));
  384. step_assert(ctx->step, 5);
  385. /* vdev trans queues first ... */
  386. dsc_assert_success(dsc_vdev_trans_start_wait(vdev));
  387. /* ... but de-queues third */
  388. step_assert(ctx->step, 15);
  389. dsc_vdev_wait_for_ops(vdev);
  390. step_assert(ctx->step, 16);
  391. dsc_vdev_trans_stop(vdev);
  392. dsc_exit();
  393. return QDF_STATUS_SUCCESS;
  394. }
  395. static QDF_STATUS dsc_thread_psoc_wait(void *context)
  396. {
  397. struct thread_ctx *ctx = context;
  398. struct dsc_psoc *psoc = nth_psoc(ctx->driver, 1);
  399. struct dsc_vdev *vdev = nth_vdev(psoc, 1);
  400. dsc_enter();
  401. while (!trans_waiting(vdev))
  402. schedule();
  403. step_assert(ctx->step, 6);
  404. /* psoc trans queues second ... */
  405. dsc_assert_success(dsc_psoc_trans_start_wait(psoc));
  406. /* ... and de-queues second */
  407. step_assert(ctx->step, 13);
  408. dsc_psoc_wait_for_ops(psoc);
  409. step_assert(ctx->step, 14);
  410. dsc_psoc_trans_stop(psoc);
  411. dsc_exit();
  412. return QDF_STATUS_SUCCESS;
  413. }
  414. static QDF_STATUS dsc_thread_driver_wait(void *context)
  415. {
  416. struct thread_ctx *ctx = context;
  417. struct dsc_driver *driver = ctx->driver;
  418. struct dsc_psoc *psoc = nth_psoc(driver, 1);
  419. dsc_enter();
  420. while (!trans_waiting(psoc))
  421. schedule();
  422. step_assert(ctx->step, 7);
  423. /* driver trans queues third ... */
  424. dsc_assert_success(dsc_driver_trans_start_wait(driver));
  425. /* ... but de-queues first */
  426. step_assert(ctx->step, 11);
  427. dsc_driver_wait_for_ops(driver);
  428. step_assert(ctx->step, 12);
  429. dsc_driver_trans_stop(driver);
  430. dsc_exit();
  431. return QDF_STATUS_SUCCESS;
  432. }
  433. static uint32_t dsc_test_trans_wait(void)
  434. {
  435. uint32_t errors = 0;
  436. QDF_STATUS status;
  437. qdf_thread_t *ops_thread;
  438. qdf_thread_t *vdev_trans_thread;
  439. qdf_thread_t *vdev_wait_thread;
  440. qdf_thread_t *psoc_wait_thread;
  441. qdf_thread_t *driver_wait_thread;
  442. struct thread_ctx ctx = { 0 };
  443. dsc_enter();
  444. status = __dsc_tree_create(&ctx.driver, 1, 2);
  445. if (QDF_IS_STATUS_ERROR(status)) {
  446. errors++;
  447. goto exit;
  448. }
  449. dsc_assert_success(qdf_event_create(&ctx.start_vdev_trans));
  450. dsc_assert_success(qdf_event_create(&ctx.start_vdev_wait));
  451. dsc_debug("starting threads");
  452. ops_thread = qdf_thread_run(dsc_thread_ops, &ctx);
  453. vdev_trans_thread = qdf_thread_run(dsc_thread_vdev_trans, &ctx);
  454. vdev_wait_thread = qdf_thread_run(dsc_thread_vdev_wait, &ctx);
  455. psoc_wait_thread = qdf_thread_run(dsc_thread_psoc_wait, &ctx);
  456. driver_wait_thread = qdf_thread_run(dsc_thread_driver_wait, &ctx);
  457. qdf_thread_join(ops_thread);
  458. qdf_thread_join(vdev_trans_thread);
  459. qdf_thread_join(vdev_wait_thread);
  460. qdf_thread_join(psoc_wait_thread);
  461. qdf_thread_join(driver_wait_thread);
  462. dsc_debug("threads joined");
  463. qdf_event_destroy(&ctx.start_vdev_wait);
  464. qdf_event_destroy(&ctx.start_vdev_trans);
  465. __dsc_tree_destroy(ctx.driver);
  466. exit:
  467. dsc_exit();
  468. return errors;
  469. }
  470. uint32_t dsc_unit_test(void)
  471. {
  472. uint32_t errors = 0;
  473. errors += dsc_test_create_destroy();
  474. errors += dsc_test_driver_trans_blocks();
  475. errors += dsc_test_psoc_trans_blocks();
  476. errors += dsc_test_vdev_trans_blocks();
  477. errors += dsc_test_trans_wait();
  478. return errors;
  479. }