tpe.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * KUnit tests for TPE element handling
  4. *
  5. * Copyright (C) 2024 Intel Corporation
  6. */
  7. #include <kunit/test.h>
  8. #include "../ieee80211_i.h"
  9. MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
  10. static struct ieee80211_channel chan6g_1 = {
  11. .band = NL80211_BAND_6GHZ,
  12. .center_freq = 5955,
  13. };
  14. static struct ieee80211_channel chan6g_33 = {
  15. .band = NL80211_BAND_6GHZ,
  16. .center_freq = 6115,
  17. };
  18. static struct ieee80211_channel chan6g_61 = {
  19. .band = NL80211_BAND_6GHZ,
  20. .center_freq = 6255,
  21. };
  22. static const struct subchan_test_case {
  23. const char *desc;
  24. struct cfg80211_chan_def c;
  25. u8 n;
  26. int expect;
  27. } subchan_offset_cases[] = {
  28. {
  29. .desc = "identical 20 MHz",
  30. .c.width = NL80211_CHAN_WIDTH_20,
  31. .c.chan = &chan6g_1,
  32. .c.center_freq1 = 5955,
  33. .n = 1,
  34. .expect = 0,
  35. },
  36. {
  37. .desc = "identical 40 MHz",
  38. .c.width = NL80211_CHAN_WIDTH_40,
  39. .c.chan = &chan6g_1,
  40. .c.center_freq1 = 5965,
  41. .n = 2,
  42. .expect = 0,
  43. },
  44. {
  45. .desc = "identical 80+80 MHz",
  46. /* not really is valid? doesn't matter for the test */
  47. .c.width = NL80211_CHAN_WIDTH_80P80,
  48. .c.chan = &chan6g_1,
  49. .c.center_freq1 = 5985,
  50. .c.center_freq2 = 6225,
  51. .n = 16,
  52. .expect = 0,
  53. },
  54. {
  55. .desc = "identical 320 MHz",
  56. .c.width = NL80211_CHAN_WIDTH_320,
  57. .c.chan = &chan6g_1,
  58. .c.center_freq1 = 6105,
  59. .n = 16,
  60. .expect = 0,
  61. },
  62. {
  63. .desc = "lower 160 MHz of 320 MHz",
  64. .c.width = NL80211_CHAN_WIDTH_320,
  65. .c.chan = &chan6g_1,
  66. .c.center_freq1 = 6105,
  67. .n = 8,
  68. .expect = 0,
  69. },
  70. {
  71. .desc = "upper 160 MHz of 320 MHz",
  72. .c.width = NL80211_CHAN_WIDTH_320,
  73. .c.chan = &chan6g_61,
  74. .c.center_freq1 = 6105,
  75. .n = 8,
  76. .expect = 8,
  77. },
  78. {
  79. .desc = "upper 160 MHz of 320 MHz, go to 40",
  80. .c.width = NL80211_CHAN_WIDTH_320,
  81. .c.chan = &chan6g_61,
  82. .c.center_freq1 = 6105,
  83. .n = 2,
  84. .expect = 8 + 4 + 2,
  85. },
  86. {
  87. .desc = "secondary 80 above primary in 80+80 MHz",
  88. /* not really is valid? doesn't matter for the test */
  89. .c.width = NL80211_CHAN_WIDTH_80P80,
  90. .c.chan = &chan6g_1,
  91. .c.center_freq1 = 5985,
  92. .c.center_freq2 = 6225,
  93. .n = 4,
  94. .expect = 0,
  95. },
  96. {
  97. .desc = "secondary 80 below primary in 80+80 MHz",
  98. /* not really is valid? doesn't matter for the test */
  99. .c.width = NL80211_CHAN_WIDTH_80P80,
  100. .c.chan = &chan6g_61,
  101. .c.center_freq1 = 6225,
  102. .c.center_freq2 = 5985,
  103. .n = 4,
  104. .expect = 4,
  105. },
  106. {
  107. .desc = "secondary 80 below primary in 80+80 MHz, go to 20",
  108. /* not really is valid? doesn't matter for the test */
  109. .c.width = NL80211_CHAN_WIDTH_80P80,
  110. .c.chan = &chan6g_61,
  111. .c.center_freq1 = 6225,
  112. .c.center_freq2 = 5985,
  113. .n = 1,
  114. .expect = 7,
  115. },
  116. };
  117. KUNIT_ARRAY_PARAM_DESC(subchan_offset, subchan_offset_cases, desc);
  118. static void subchan_offset(struct kunit *test)
  119. {
  120. const struct subchan_test_case *params = test->param_value;
  121. int offset;
  122. KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(&params->c), true);
  123. offset = ieee80211_calc_chandef_subchan_offset(&params->c, params->n);
  124. KUNIT_EXPECT_EQ(test, params->expect, offset);
  125. }
  126. static const struct psd_reorder_test_case {
  127. const char *desc;
  128. struct cfg80211_chan_def ap, used;
  129. struct ieee80211_parsed_tpe_psd psd, out;
  130. } psd_reorder_cases[] = {
  131. {
  132. .desc = "no changes, 320 MHz",
  133. .ap.width = NL80211_CHAN_WIDTH_320,
  134. .ap.chan = &chan6g_1,
  135. .ap.center_freq1 = 6105,
  136. .used.width = NL80211_CHAN_WIDTH_320,
  137. .used.chan = &chan6g_1,
  138. .used.center_freq1 = 6105,
  139. .psd.valid = true,
  140. .psd.count = 16,
  141. .psd.n = 8,
  142. .psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
  143. .out.valid = true,
  144. .out.count = 16,
  145. .out.n = 8,
  146. .out.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
  147. },
  148. {
  149. .desc = "no changes, 320 MHz, 160 MHz used, n=0",
  150. .ap.width = NL80211_CHAN_WIDTH_320,
  151. .ap.chan = &chan6g_1,
  152. .ap.center_freq1 = 6105,
  153. .used.width = NL80211_CHAN_WIDTH_160,
  154. .used.chan = &chan6g_1,
  155. .used.center_freq1 = 6025,
  156. .psd.valid = true,
  157. .psd.count = 16,
  158. .psd.n = 0,
  159. .psd.power = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
  160. .out.valid = true,
  161. .out.count = 8,
  162. .out.n = 0,
  163. .out.power = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
  164. },
  165. {
  166. .desc = "320 MHz, HE is 80, used 160, all lower",
  167. .ap.width = NL80211_CHAN_WIDTH_320,
  168. .ap.chan = &chan6g_1,
  169. .ap.center_freq1 = 6105,
  170. .used.width = NL80211_CHAN_WIDTH_160,
  171. .used.chan = &chan6g_1,
  172. .used.center_freq1 = 6025,
  173. .psd.valid = true,
  174. .psd.count = 16,
  175. .psd.n = 4,
  176. .psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
  177. .out.valid = true,
  178. .out.count = 8,
  179. .out.n = 4,
  180. .out.power = { 0, 1, 2, 3, 4, 5, 6, 7, 127, 127, 127, 127, 127, 127, 127, 127},
  181. },
  182. {
  183. .desc = "320 MHz, HE is 80, used 160, all upper",
  184. /*
  185. * EHT: | | | | | | | | | | | | | | | | |
  186. * HE: | | | | |
  187. * used: | | | | | | | | |
  188. */
  189. .ap.width = NL80211_CHAN_WIDTH_320,
  190. .ap.chan = &chan6g_61,
  191. .ap.center_freq1 = 6105,
  192. .used.width = NL80211_CHAN_WIDTH_160,
  193. .used.chan = &chan6g_61,
  194. .used.center_freq1 = 6185,
  195. .psd.valid = true,
  196. .psd.count = 16,
  197. .psd.n = 4,
  198. .psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
  199. .out.valid = true,
  200. .out.count = 8,
  201. .out.n = 4,
  202. .out.power = { 12, 13, 14, 15, 0, 1, 2, 3, 127, 127, 127, 127, 127, 127, 127, 127},
  203. },
  204. {
  205. .desc = "320 MHz, HE is 80, used 160, split",
  206. /*
  207. * EHT: | | | | | | | | | | | | | | | | |
  208. * HE: | | | | |
  209. * used: | | | | | | | | |
  210. */
  211. .ap.width = NL80211_CHAN_WIDTH_320,
  212. .ap.chan = &chan6g_33,
  213. .ap.center_freq1 = 6105,
  214. .used.width = NL80211_CHAN_WIDTH_160,
  215. .used.chan = &chan6g_33,
  216. .used.center_freq1 = 6185,
  217. .psd.valid = true,
  218. .psd.count = 16,
  219. .psd.n = 4,
  220. .psd.power = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
  221. .out.valid = true,
  222. .out.count = 8,
  223. .out.n = 4,
  224. .out.power = { 0, 1, 2, 3, 12, 13, 14, 15, 127, 127, 127, 127, 127, 127, 127, 127},
  225. },
  226. };
  227. KUNIT_ARRAY_PARAM_DESC(psd_reorder, psd_reorder_cases, desc);
  228. static void psd_reorder(struct kunit *test)
  229. {
  230. const struct psd_reorder_test_case *params = test->param_value;
  231. struct ieee80211_parsed_tpe_psd tmp = params->psd;
  232. KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(&params->ap), true);
  233. KUNIT_ASSERT_EQ(test, cfg80211_chandef_valid(&params->used), true);
  234. ieee80211_rearrange_tpe_psd(&tmp, &params->ap, &params->used);
  235. KUNIT_EXPECT_MEMEQ(test, &tmp, &params->out, sizeof(tmp));
  236. }
  237. static struct kunit_case tpe_test_cases[] = {
  238. KUNIT_CASE_PARAM(subchan_offset, subchan_offset_gen_params),
  239. KUNIT_CASE_PARAM(psd_reorder, psd_reorder_gen_params),
  240. {}
  241. };
  242. static struct kunit_suite tpe = {
  243. .name = "mac80211-tpe",
  244. .test_cases = tpe_test_cases,
  245. };
  246. kunit_test_suite(tpe);