dp_tx_desc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  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 "hal_hw_headers.h"
  20. #include "dp_types.h"
  21. #include "dp_tx_desc.h"
  22. #ifndef DESC_PARTITION
  23. #define DP_TX_DESC_SIZE(a) qdf_get_pwr2(a)
  24. #define DP_TX_DESC_PAGE_DIVIDER(soc, num_desc_per_page, pool_id) \
  25. do { \
  26. uint8_t sig_bit; \
  27. soc->tx_desc[pool_id].offset_filter = num_desc_per_page - 1; \
  28. /* Calculate page divider to find page number */ \
  29. sig_bit = 0; \
  30. while (num_desc_per_page) { \
  31. sig_bit++; \
  32. num_desc_per_page = num_desc_per_page >> 1; \
  33. } \
  34. soc->tx_desc[pool_id].page_divider = (sig_bit - 1); \
  35. } while (0)
  36. #else
  37. #define DP_TX_DESC_SIZE(a) a
  38. #define DP_TX_DESC_PAGE_DIVIDER(soc, num_desc_per_page, pool_id) {}
  39. #endif /* DESC_PARTITION */
  40. /**
  41. * dp_tx_desc_pool_counter_initialize() - Initialize counters
  42. * @tx_desc_pool Handle to DP tx_desc_pool structure
  43. * @num_elem Number of descriptor elements per pool
  44. *
  45. * Return: None
  46. */
  47. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  48. static void
  49. dp_tx_desc_pool_counter_initialize(struct dp_tx_desc_pool_s *tx_desc_pool,
  50. uint16_t num_elem)
  51. {
  52. }
  53. #else
  54. static void
  55. dp_tx_desc_pool_counter_initialize(struct dp_tx_desc_pool_s *tx_desc_pool,
  56. uint16_t num_elem)
  57. {
  58. tx_desc_pool->num_free = num_elem;
  59. tx_desc_pool->num_allocated = 0;
  60. }
  61. #endif
  62. /**
  63. * dp_tx_desc_pool_alloc() - Allocate Tx Descriptor pool(s)
  64. * @soc Handle to DP SoC structure
  65. * @pool_id pool to allocate
  66. * @num_elem Number of descriptor elements per pool
  67. *
  68. * This function allocates memory for SW tx descriptors
  69. * (used within host for tx data path).
  70. * The number of tx descriptors required will be large
  71. * since based on number of clients (1024 clients x 3 radios),
  72. * outstanding MSDUs stored in TQM queues and LMAC queues will be significantly
  73. * large.
  74. *
  75. * To avoid allocating a large contiguous memory, it uses multi_page_alloc qdf
  76. * function to allocate memory
  77. * in multiple pages. It then iterates through the memory allocated across pages
  78. * and links each descriptor
  79. * to next descriptor, taking care of page boundaries.
  80. *
  81. * Since WiFi 3.0 HW supports multiple Tx rings, multiple pools are allocated,
  82. * one for each ring;
  83. * This minimizes lock contention when hard_start_xmit is called
  84. * from multiple CPUs.
  85. * Alternately, multiple pools can be used for multiple VDEVs for VDEV level
  86. * flow control.
  87. *
  88. * Return: Status code. 0 for success.
  89. */
  90. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  91. uint32_t num_elem)
  92. {
  93. uint32_t desc_size;
  94. struct dp_tx_desc_pool_s *tx_desc_pool;
  95. desc_size = DP_TX_DESC_SIZE(sizeof(struct dp_tx_desc_s));
  96. tx_desc_pool = &((soc)->tx_desc[(pool_id)]);
  97. dp_desc_multi_pages_mem_alloc(soc, DP_TX_DESC_TYPE,
  98. &tx_desc_pool->desc_pages,
  99. desc_size, num_elem,
  100. 0, true);
  101. if (!tx_desc_pool->desc_pages.num_pages) {
  102. dp_err("Multi page alloc fail, tx desc");
  103. return QDF_STATUS_E_NOMEM;
  104. }
  105. return QDF_STATUS_SUCCESS;
  106. }
  107. /**
  108. * dp_tx_desc_pool_free() - Free the tx dexcriptor pools
  109. * @soc: Handle to DP SoC structure
  110. * @pool_id: pool to free
  111. *
  112. */
  113. void dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id)
  114. {
  115. struct dp_tx_desc_pool_s *tx_desc_pool;
  116. tx_desc_pool = &((soc)->tx_desc[pool_id]);
  117. if (tx_desc_pool->desc_pages.num_pages)
  118. dp_desc_multi_pages_mem_free(soc, DP_TX_DESC_TYPE,
  119. &tx_desc_pool->desc_pages, 0,
  120. true);
  121. }
  122. /**
  123. * dp_tx_desc_pool_init() - Initialize Tx Descriptor pool(s)
  124. * @soc: Handle to DP SoC structure
  125. * @pool_id: pool to allocate
  126. * @num_elem: Number of descriptor elements per pool
  127. *
  128. * Return: QDF_STATUS_SUCCESS
  129. * QDF_STATUS_E_FAULT
  130. */
  131. QDF_STATUS dp_tx_desc_pool_init(struct dp_soc *soc, uint8_t pool_id,
  132. uint32_t num_elem)
  133. {
  134. struct dp_tx_desc_pool_s *tx_desc_pool;
  135. uint32_t desc_size;
  136. desc_size = DP_TX_DESC_SIZE(sizeof(struct dp_tx_desc_s));
  137. tx_desc_pool = &soc->tx_desc[pool_id];
  138. if (qdf_mem_multi_page_link(soc->osdev,
  139. &tx_desc_pool->desc_pages,
  140. desc_size, num_elem, true)) {
  141. dp_err("invalid tx desc allocation -overflow num link");
  142. return QDF_STATUS_E_FAULT;
  143. }
  144. tx_desc_pool->freelist = (struct dp_tx_desc_s *)
  145. *tx_desc_pool->desc_pages.cacheable_pages;
  146. /* Set unique IDs for each Tx descriptor */
  147. if (QDF_STATUS_SUCCESS != soc->arch_ops.dp_tx_desc_pool_init(
  148. soc, num_elem, pool_id)) {
  149. dp_err("initialization per target failed");
  150. return QDF_STATUS_E_FAULT;
  151. }
  152. tx_desc_pool->elem_size = DP_TX_DESC_SIZE(sizeof(struct dp_tx_desc_s));
  153. dp_tx_desc_pool_counter_initialize(tx_desc_pool, num_elem);
  154. TX_DESC_LOCK_CREATE(&tx_desc_pool->lock);
  155. return QDF_STATUS_SUCCESS;
  156. }
  157. /**
  158. * dp_tx_desc_pool_deinit() - de-initialize Tx Descriptor pool(s)
  159. * @soc Handle to DP SoC structure
  160. * @pool_id: pool to de-initialize
  161. *
  162. */
  163. void dp_tx_desc_pool_deinit(struct dp_soc *soc, uint8_t pool_id)
  164. {
  165. struct dp_tx_desc_pool_s *tx_desc_pool;
  166. tx_desc_pool = &soc->tx_desc[pool_id];
  167. soc->arch_ops.dp_tx_desc_pool_deinit(soc, tx_desc_pool, pool_id);
  168. TX_DESC_POOL_MEMBER_CLEAN(tx_desc_pool);
  169. TX_DESC_LOCK_DESTROY(&tx_desc_pool->lock);
  170. }
  171. /**
  172. * dp_tx_ext_desc_pool_alloc() - allocate Tx extenstion Descriptor pool(s)
  173. * @soc: Handle to DP SoC structure
  174. * @num_pool: Number of pools to allocate
  175. * @num_elem: Number of descriptor elements per pool
  176. *
  177. * Return - QDF_STATUS_SUCCESS
  178. * QDF_STATUS_E_NOMEM
  179. */
  180. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  181. uint32_t num_elem)
  182. {
  183. QDF_STATUS status = QDF_STATUS_SUCCESS;
  184. qdf_dma_context_t memctx = 0;
  185. uint8_t pool_id, count;
  186. uint16_t elem_size = HAL_TX_EXT_DESC_WITH_META_DATA;
  187. struct dp_tx_ext_desc_pool_s *dp_tx_ext_desc_pool;
  188. uint16_t link_elem_size = sizeof(struct dp_tx_ext_desc_elem_s);
  189. /* Coherent tx extension descriptor alloc */
  190. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  191. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[pool_id]);
  192. memctx = qdf_get_dma_mem_context(dp_tx_ext_desc_pool, memctx);
  193. dp_desc_multi_pages_mem_alloc(
  194. soc, DP_TX_EXT_DESC_TYPE,
  195. &dp_tx_ext_desc_pool->desc_pages,
  196. elem_size,
  197. num_elem,
  198. memctx, false);
  199. if (!dp_tx_ext_desc_pool->desc_pages.num_pages) {
  200. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  201. "ext desc page alloc fail");
  202. status = QDF_STATUS_E_NOMEM;
  203. goto fail_exit;
  204. }
  205. }
  206. /*
  207. * Cacheable ext descriptor link alloc
  208. * This structure also large size already
  209. * single element is 24bytes, 2K elements are 48Kbytes
  210. * Have to alloc multi page cacheable memory
  211. */
  212. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  213. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[pool_id]);
  214. dp_desc_multi_pages_mem_alloc(
  215. soc,
  216. DP_TX_EXT_DESC_LINK_TYPE,
  217. &dp_tx_ext_desc_pool->desc_link_pages,
  218. link_elem_size,
  219. num_elem,
  220. 0, true);
  221. if (!dp_tx_ext_desc_pool->desc_link_pages.num_pages) {
  222. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  223. "ext link desc page alloc fail");
  224. status = QDF_STATUS_E_NOMEM;
  225. goto free_ext_desc_page;
  226. }
  227. }
  228. return status;
  229. free_ext_desc_page:
  230. for (count = 0; count < pool_id; count++) {
  231. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[count]);
  232. dp_desc_multi_pages_mem_free(
  233. soc, DP_TX_EXT_DESC_LINK_TYPE,
  234. &dp_tx_ext_desc_pool->desc_link_pages,
  235. 0, true);
  236. }
  237. pool_id = num_pool;
  238. fail_exit:
  239. for (count = 0; count < pool_id; count++) {
  240. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[count]);
  241. memctx = qdf_get_dma_mem_context(dp_tx_ext_desc_pool, memctx);
  242. dp_desc_multi_pages_mem_free(
  243. soc, DP_TX_EXT_DESC_TYPE,
  244. &dp_tx_ext_desc_pool->desc_pages,
  245. memctx, false);
  246. }
  247. return status;
  248. }
  249. /**
  250. * dp_tx_ext_desc_pool_init() - initialize Tx extenstion Descriptor pool(s)
  251. * @soc: Handle to DP SoC structure
  252. * @num_pool: Number of pools to initialize
  253. * @num_elem: Number of descriptor elements per pool
  254. *
  255. * Return - QDF_STATUS_SUCCESS
  256. * QDF_STATUS_E_NOMEM
  257. */
  258. QDF_STATUS dp_tx_ext_desc_pool_init(struct dp_soc *soc, uint8_t num_pool,
  259. uint32_t num_elem)
  260. {
  261. uint32_t i;
  262. struct dp_tx_ext_desc_elem_s *c_elem, *p_elem;
  263. struct qdf_mem_dma_page_t *page_info;
  264. struct qdf_mem_multi_page_t *pages;
  265. struct dp_tx_ext_desc_pool_s *dp_tx_ext_desc_pool;
  266. uint8_t pool_id;
  267. QDF_STATUS status;
  268. /* link tx descriptors into a freelist */
  269. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  270. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[pool_id]);
  271. soc->tx_ext_desc[pool_id].elem_size =
  272. HAL_TX_EXT_DESC_WITH_META_DATA;
  273. soc->tx_ext_desc[pool_id].link_elem_size =
  274. sizeof(struct dp_tx_ext_desc_elem_s);
  275. soc->tx_ext_desc[pool_id].elem_count = num_elem;
  276. dp_tx_ext_desc_pool->freelist = (struct dp_tx_ext_desc_elem_s *)
  277. *dp_tx_ext_desc_pool->desc_link_pages.cacheable_pages;
  278. if (qdf_mem_multi_page_link(soc->osdev,
  279. &dp_tx_ext_desc_pool->
  280. desc_link_pages,
  281. dp_tx_ext_desc_pool->link_elem_size,
  282. dp_tx_ext_desc_pool->elem_count,
  283. true)) {
  284. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  285. "ext link desc page linking fail");
  286. status = QDF_STATUS_E_FAULT;
  287. goto fail;
  288. }
  289. /* Assign coherent memory pointer into linked free list */
  290. pages = &dp_tx_ext_desc_pool->desc_pages;
  291. page_info = dp_tx_ext_desc_pool->desc_pages.dma_pages;
  292. c_elem = dp_tx_ext_desc_pool->freelist;
  293. p_elem = c_elem;
  294. for (i = 0; i < dp_tx_ext_desc_pool->elem_count; i++) {
  295. if (!(i % pages->num_element_per_page)) {
  296. /**
  297. * First element for new page,
  298. * should point next page
  299. */
  300. if (!pages->dma_pages->page_v_addr_start) {
  301. QDF_TRACE(QDF_MODULE_ID_DP,
  302. QDF_TRACE_LEVEL_ERROR,
  303. "link over flow");
  304. status = QDF_STATUS_E_FAULT;
  305. goto fail;
  306. }
  307. c_elem->vaddr =
  308. (void *)page_info->page_v_addr_start;
  309. c_elem->paddr = page_info->page_p_addr;
  310. page_info++;
  311. } else {
  312. c_elem->vaddr = (void *)(p_elem->vaddr +
  313. dp_tx_ext_desc_pool->elem_size);
  314. c_elem->paddr = (p_elem->paddr +
  315. dp_tx_ext_desc_pool->elem_size);
  316. }
  317. p_elem = c_elem;
  318. c_elem = c_elem->next;
  319. if (!c_elem)
  320. break;
  321. }
  322. dp_tx_ext_desc_pool->num_free = num_elem;
  323. qdf_spinlock_create(&dp_tx_ext_desc_pool->lock);
  324. }
  325. return QDF_STATUS_SUCCESS;
  326. fail:
  327. return status;
  328. }
  329. /**
  330. * dp_tx_ext_desc_pool_free() - free Tx extenstion Descriptor pool(s)
  331. * @soc: Handle to DP SoC structure
  332. * @num_pool: Number of pools to free
  333. *
  334. */
  335. void dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t num_pool)
  336. {
  337. uint8_t pool_id;
  338. struct dp_tx_ext_desc_pool_s *dp_tx_ext_desc_pool;
  339. qdf_dma_context_t memctx = 0;
  340. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  341. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[pool_id]);
  342. memctx = qdf_get_dma_mem_context(dp_tx_ext_desc_pool, memctx);
  343. dp_desc_multi_pages_mem_free(
  344. soc, DP_TX_EXT_DESC_LINK_TYPE,
  345. &dp_tx_ext_desc_pool->desc_link_pages,
  346. 0, true);
  347. dp_desc_multi_pages_mem_free(
  348. soc, DP_TX_EXT_DESC_TYPE,
  349. &dp_tx_ext_desc_pool->desc_pages,
  350. memctx, false);
  351. }
  352. }
  353. /**
  354. * dp_tx_ext_desc_pool_deinit() - deinit Tx extenstion Descriptor pool(s)
  355. * @soc: Handle to DP SoC structure
  356. * @num_pool: Number of pools to de-initialize
  357. *
  358. */
  359. void dp_tx_ext_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  360. {
  361. uint8_t pool_id;
  362. struct dp_tx_ext_desc_pool_s *dp_tx_ext_desc_pool;
  363. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  364. dp_tx_ext_desc_pool = &((soc)->tx_ext_desc[pool_id]);
  365. qdf_spinlock_destroy(&dp_tx_ext_desc_pool->lock);
  366. }
  367. }
  368. #if defined(FEATURE_TSO)
  369. /**
  370. * dp_tx_tso_desc_pool_alloc() - allocate TSO Descriptor pool(s)
  371. * @soc: Handle to DP SoC structure
  372. * @num_pool: Number of pools to allocate
  373. * @num_elem: Number of descriptor elements per pool
  374. *
  375. * Return - QDF_STATUS_SUCCESS
  376. * QDF_STATUS_E_NOMEM
  377. */
  378. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  379. uint32_t num_elem)
  380. {
  381. struct dp_tx_tso_seg_pool_s *tso_desc_pool;
  382. uint32_t desc_size, pool_id, i;
  383. desc_size = DP_TX_DESC_SIZE(sizeof(struct qdf_tso_seg_elem_t));
  384. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  385. tso_desc_pool = &soc->tx_tso_desc[pool_id];
  386. tso_desc_pool->num_free = 0;
  387. dp_desc_multi_pages_mem_alloc(
  388. soc,
  389. DP_TX_TSO_DESC_TYPE,
  390. &tso_desc_pool->desc_pages,
  391. desc_size,
  392. num_elem, 0, true);
  393. if (!tso_desc_pool->desc_pages.num_pages) {
  394. dp_err("Multi page alloc fail, tx desc");
  395. goto fail;
  396. }
  397. }
  398. return QDF_STATUS_SUCCESS;
  399. fail:
  400. for (i = 0; i < pool_id; i++) {
  401. tso_desc_pool = &soc->tx_tso_desc[i];
  402. dp_desc_multi_pages_mem_free(soc, DP_TX_TSO_DESC_TYPE,
  403. &tso_desc_pool->desc_pages,
  404. 0, true);
  405. }
  406. return QDF_STATUS_E_NOMEM;
  407. }
  408. /**
  409. * dp_tx_tso_desc_pool_free() - free TSO Descriptor pool(s)
  410. * @soc: Handle to DP SoC structure
  411. * @num_pool: Number of pools to free
  412. *
  413. */
  414. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t num_pool)
  415. {
  416. struct dp_tx_tso_seg_pool_s *tso_desc_pool;
  417. uint32_t pool_id;
  418. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  419. tso_desc_pool = &soc->tx_tso_desc[pool_id];
  420. dp_desc_multi_pages_mem_free(soc, DP_TX_TSO_DESC_TYPE,
  421. &tso_desc_pool->desc_pages,
  422. 0, true);
  423. }
  424. }
  425. /**
  426. * dp_tx_tso_desc_pool_init() - initialize TSO Descriptor pool(s)
  427. * @soc: Handle to DP SoC structure
  428. * @num_pool: Number of pools to initialize
  429. * @num_elem: Number of descriptor elements per pool
  430. *
  431. * Return - QDF_STATUS_SUCCESS
  432. * QDF_STATUS_E_NOMEM
  433. */
  434. QDF_STATUS dp_tx_tso_desc_pool_init(struct dp_soc *soc, uint8_t num_pool,
  435. uint32_t num_elem)
  436. {
  437. struct dp_tx_tso_seg_pool_s *tso_desc_pool;
  438. uint32_t desc_size, pool_id;
  439. desc_size = DP_TX_DESC_SIZE(sizeof(struct qdf_tso_seg_elem_t));
  440. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  441. tso_desc_pool = &soc->tx_tso_desc[pool_id];
  442. if (qdf_mem_multi_page_link(soc->osdev,
  443. &tso_desc_pool->desc_pages,
  444. desc_size,
  445. num_elem, true)) {
  446. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  447. "invalid tso desc allocation - overflow num link");
  448. return QDF_STATUS_E_FAULT;
  449. }
  450. tso_desc_pool->freelist = (struct qdf_tso_seg_elem_t *)
  451. *tso_desc_pool->desc_pages.cacheable_pages;
  452. tso_desc_pool->num_free = num_elem;
  453. TSO_DEBUG("Number of free descriptors: %u\n",
  454. tso_desc_pool->num_free);
  455. tso_desc_pool->pool_size = num_elem;
  456. qdf_spinlock_create(&tso_desc_pool->lock);
  457. }
  458. return QDF_STATUS_SUCCESS;
  459. }
  460. /**
  461. * dp_tx_tso_desc_pool_deinit() - deinitialize TSO Descriptor pool(s)
  462. * @soc: Handle to DP SoC structure
  463. * @num_pool: Number of pools to free
  464. *
  465. */
  466. void dp_tx_tso_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  467. {
  468. struct dp_tx_tso_seg_pool_s *tso_desc_pool;
  469. uint32_t pool_id;
  470. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  471. tso_desc_pool = &soc->tx_tso_desc[pool_id];
  472. qdf_spin_lock_bh(&tso_desc_pool->lock);
  473. tso_desc_pool->freelist = NULL;
  474. tso_desc_pool->num_free = 0;
  475. tso_desc_pool->pool_size = 0;
  476. qdf_spin_unlock_bh(&tso_desc_pool->lock);
  477. qdf_spinlock_destroy(&tso_desc_pool->lock);
  478. }
  479. }
  480. /**
  481. * dp_tx_tso_num_seg_pool_alloc() - Allocate descriptors that tracks the
  482. * fragments in each tso segment
  483. *
  484. * @soc: handle to dp soc structure
  485. * @num_pool: number of pools to allocate
  486. * @num_elem: total number of descriptors to be allocated
  487. *
  488. * Return - QDF_STATUS_SUCCESS
  489. * QDF_STATUS_E_NOMEM
  490. */
  491. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  492. uint32_t num_elem)
  493. {
  494. struct dp_tx_tso_num_seg_pool_s *tso_num_seg_pool;
  495. uint32_t desc_size, pool_id, i;
  496. desc_size = DP_TX_DESC_SIZE(sizeof(struct qdf_tso_num_seg_elem_t));
  497. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  498. tso_num_seg_pool = &soc->tx_tso_num_seg[pool_id];
  499. tso_num_seg_pool->num_free = 0;
  500. dp_desc_multi_pages_mem_alloc(soc, DP_TX_TSO_NUM_SEG_TYPE,
  501. &tso_num_seg_pool->desc_pages,
  502. desc_size,
  503. num_elem, 0, true);
  504. if (!tso_num_seg_pool->desc_pages.num_pages) {
  505. dp_err("Multi page alloc fail, tso_num_seg_pool");
  506. goto fail;
  507. }
  508. }
  509. return QDF_STATUS_SUCCESS;
  510. fail:
  511. for (i = 0; i < pool_id; i++) {
  512. tso_num_seg_pool = &soc->tx_tso_num_seg[i];
  513. dp_desc_multi_pages_mem_free(soc, DP_TX_TSO_NUM_SEG_TYPE,
  514. &tso_num_seg_pool->desc_pages,
  515. 0, true);
  516. }
  517. return QDF_STATUS_E_NOMEM;
  518. }
  519. /**
  520. * dp_tx_tso_num_seg_pool_free() - free descriptors that tracks the
  521. * fragments in each tso segment
  522. *
  523. * @soc: handle to dp soc structure
  524. * @num_pool: number of pools to free
  525. */
  526. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t num_pool)
  527. {
  528. struct dp_tx_tso_num_seg_pool_s *tso_num_seg_pool;
  529. uint32_t pool_id;
  530. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  531. tso_num_seg_pool = &soc->tx_tso_num_seg[pool_id];
  532. dp_desc_multi_pages_mem_free(soc, DP_TX_TSO_NUM_SEG_TYPE,
  533. &tso_num_seg_pool->desc_pages,
  534. 0, true);
  535. }
  536. }
  537. /**
  538. * dp_tx_tso_num_seg_pool_init() - Initialize descriptors that tracks the
  539. * fragments in each tso segment
  540. *
  541. * @soc: handle to dp soc structure
  542. * @num_pool: number of pools to initialize
  543. * @num_elem: total number of descriptors to be initialized
  544. *
  545. * Return - QDF_STATUS_SUCCESS
  546. * QDF_STATUS_E_FAULT
  547. */
  548. QDF_STATUS dp_tx_tso_num_seg_pool_init(struct dp_soc *soc, uint8_t num_pool,
  549. uint32_t num_elem)
  550. {
  551. struct dp_tx_tso_num_seg_pool_s *tso_num_seg_pool;
  552. uint32_t desc_size, pool_id;
  553. desc_size = DP_TX_DESC_SIZE(sizeof(struct qdf_tso_num_seg_elem_t));
  554. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  555. tso_num_seg_pool = &soc->tx_tso_num_seg[pool_id];
  556. if (qdf_mem_multi_page_link(soc->osdev,
  557. &tso_num_seg_pool->desc_pages,
  558. desc_size,
  559. num_elem, true)) {
  560. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  561. "invalid tso desc allocation - overflow num link");
  562. return QDF_STATUS_E_FAULT;
  563. }
  564. tso_num_seg_pool->freelist = (struct qdf_tso_num_seg_elem_t *)
  565. *tso_num_seg_pool->desc_pages.cacheable_pages;
  566. tso_num_seg_pool->num_free = num_elem;
  567. tso_num_seg_pool->num_seg_pool_size = num_elem;
  568. qdf_spinlock_create(&tso_num_seg_pool->lock);
  569. }
  570. return QDF_STATUS_SUCCESS;
  571. }
  572. /**
  573. * dp_tx_tso_num_seg_pool_deinit() - de-initialize descriptors that tracks the
  574. * fragments in each tso segment
  575. *
  576. * @soc: handle to dp soc structure
  577. * @num_pool: number of pools to de-initialize
  578. *
  579. * Return - QDF_STATUS_SUCCESS
  580. * QDF_STATUS_E_FAULT
  581. */
  582. void dp_tx_tso_num_seg_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  583. {
  584. struct dp_tx_tso_num_seg_pool_s *tso_num_seg_pool;
  585. uint32_t pool_id;
  586. for (pool_id = 0; pool_id < num_pool; pool_id++) {
  587. tso_num_seg_pool = &soc->tx_tso_num_seg[pool_id];
  588. qdf_spin_lock_bh(&tso_num_seg_pool->lock);
  589. tso_num_seg_pool->freelist = NULL;
  590. tso_num_seg_pool->num_free = 0;
  591. tso_num_seg_pool->num_seg_pool_size = 0;
  592. qdf_spin_unlock_bh(&tso_num_seg_pool->lock);
  593. qdf_spinlock_destroy(&tso_num_seg_pool->lock);
  594. }
  595. }
  596. #else
  597. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  598. uint32_t num_elem)
  599. {
  600. return QDF_STATUS_SUCCESS;
  601. }
  602. QDF_STATUS dp_tx_tso_desc_pool_init(struct dp_soc *soc, uint8_t num_pool,
  603. uint32_t num_elem)
  604. {
  605. return QDF_STATUS_SUCCESS;
  606. }
  607. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t num_pool)
  608. {
  609. }
  610. void dp_tx_tso_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  611. {
  612. }
  613. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  614. uint32_t num_elem)
  615. {
  616. return QDF_STATUS_SUCCESS;
  617. }
  618. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t num_pool)
  619. {
  620. }
  621. QDF_STATUS dp_tx_tso_num_seg_pool_init(struct dp_soc *soc, uint8_t num_pool,
  622. uint32_t num_elem)
  623. {
  624. return QDF_STATUS_SUCCESS;
  625. }
  626. void dp_tx_tso_num_seg_pool_deinit(struct dp_soc *soc, uint8_t num_pool)
  627. {
  628. }
  629. #endif