dp_tx_desc.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * Copyright (c) 2016-2018 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. #ifndef DP_TX_DESC_H
  19. #define DP_TX_DESC_H
  20. #include "dp_types.h"
  21. #include "dp_tx.h"
  22. #include "dp_internal.h"
  23. #ifdef TX_PER_PDEV_DESC_POOL
  24. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  25. #define DP_TX_GET_DESC_POOL_ID(vdev) (vdev->vdev_id)
  26. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  27. #define DP_TX_GET_DESC_POOL_ID(vdev) (vdev->pdev->pdev_id)
  28. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  29. #define DP_TX_GET_RING_ID(vdev) (vdev->pdev->pdev_id)
  30. #else
  31. #ifdef TX_PER_VDEV_DESC_POOL
  32. #define DP_TX_GET_DESC_POOL_ID(vdev) (vdev->vdev_id)
  33. #define DP_TX_GET_RING_ID(vdev) (vdev->pdev->pdev_id)
  34. #endif /* TX_PER_VDEV_DESC_POOL */
  35. #endif /* TX_PER_PDEV_DESC_POOL */
  36. /**
  37. * 21 bits cookie
  38. * 2 bits pool id 0 ~ 3,
  39. * 10 bits page id 0 ~ 1023
  40. * 5 bits offset id 0 ~ 31 (Desc size = 128, Num descs per page = 4096/128 = 32)
  41. */
  42. /* ???Ring ID needed??? */
  43. #define DP_TX_DESC_ID_POOL_MASK 0x018000
  44. #define DP_TX_DESC_ID_POOL_OS 15
  45. #define DP_TX_DESC_ID_PAGE_MASK 0x007FE0
  46. #define DP_TX_DESC_ID_PAGE_OS 5
  47. #define DP_TX_DESC_ID_OFFSET_MASK 0x00001F
  48. #define DP_TX_DESC_ID_OFFSET_OS 0
  49. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  50. #define TX_DESC_LOCK_CREATE(lock)
  51. #define TX_DESC_LOCK_DESTROY(lock)
  52. #define TX_DESC_LOCK_LOCK(lock)
  53. #define TX_DESC_LOCK_UNLOCK(lock)
  54. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  55. do { \
  56. (_tx_desc_pool)->elem_size = 0; \
  57. (_tx_desc_pool)->freelist = NULL; \
  58. (_tx_desc_pool)->pool_size = 0; \
  59. (_tx_desc_pool)->avail_desc = 0; \
  60. (_tx_desc_pool)->start_th = 0; \
  61. (_tx_desc_pool)->stop_th = 0; \
  62. (_tx_desc_pool)->status = FLOW_POOL_INACTIVE; \
  63. } while (0)
  64. #else /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  65. #define TX_DESC_LOCK_CREATE(lock) qdf_spinlock_create(lock)
  66. #define TX_DESC_LOCK_DESTROY(lock) qdf_spinlock_destroy(lock)
  67. #define TX_DESC_LOCK_LOCK(lock) qdf_spin_lock_bh(lock)
  68. #define TX_DESC_LOCK_UNLOCK(lock) qdf_spin_unlock_bh(lock)
  69. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  70. do { \
  71. (_tx_desc_pool)->elem_size = 0; \
  72. (_tx_desc_pool)->num_allocated = 0; \
  73. (_tx_desc_pool)->freelist = NULL; \
  74. (_tx_desc_pool)->elem_count = 0; \
  75. (_tx_desc_pool)->num_free = 0; \
  76. } while (0)
  77. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  78. #define MAX_POOL_BUFF_COUNT 10000
  79. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  80. uint16_t num_elem);
  81. QDF_STATUS dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  82. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  83. uint16_t num_elem);
  84. QDF_STATUS dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  85. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  86. uint16_t num_elem);
  87. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  88. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  89. uint16_t num_elem);
  90. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t pool_id);
  91. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  92. void dp_tx_flow_control_init(struct dp_soc *);
  93. void dp_tx_flow_control_deinit(struct dp_soc *);
  94. QDF_STATUS dp_txrx_register_pause_cb(struct cdp_soc_t *soc,
  95. tx_pause_callback pause_cb);
  96. QDF_STATUS dp_tx_flow_pool_map(struct cdp_soc_t *soc, struct cdp_pdev *pdev,
  97. uint8_t vdev_id);
  98. void dp_tx_flow_pool_unmap(struct cdp_soc_t *soc, struct cdp_pdev *pdev,
  99. uint8_t vdev_id);
  100. void dp_tx_clear_flow_pool_stats(struct dp_soc *soc);
  101. struct dp_tx_desc_pool_s *dp_tx_create_flow_pool(struct dp_soc *soc,
  102. uint8_t flow_pool_id, uint16_t flow_pool_size);
  103. QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev, uint8_t flow_id,
  104. uint8_t flow_type, uint8_t flow_pool_id, uint16_t flow_pool_size);
  105. void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev, uint8_t flow_id,
  106. uint8_t flow_type, uint8_t flow_pool_id);
  107. /**
  108. * dp_tx_get_desc_flow_pool() - get descriptor from flow pool
  109. * @pool: flow pool
  110. *
  111. * Caller needs to take lock and do sanity checks.
  112. *
  113. * Return: tx descriptor
  114. */
  115. static inline
  116. struct dp_tx_desc_s *dp_tx_get_desc_flow_pool(struct dp_tx_desc_pool_s *pool)
  117. {
  118. struct dp_tx_desc_s *tx_desc = pool->freelist;
  119. pool->freelist = pool->freelist->next;
  120. pool->avail_desc--;
  121. return tx_desc;
  122. }
  123. /**
  124. * ol_tx_put_desc_flow_pool() - put descriptor to flow pool freelist
  125. * @pool: flow pool
  126. * @tx_desc: tx descriptor
  127. *
  128. * Caller needs to take lock and do sanity checks.
  129. *
  130. * Return: none
  131. */
  132. static inline
  133. void dp_tx_put_desc_flow_pool(struct dp_tx_desc_pool_s *pool,
  134. struct dp_tx_desc_s *tx_desc)
  135. {
  136. tx_desc->next = pool->freelist;
  137. pool->freelist = tx_desc;
  138. pool->avail_desc++;
  139. }
  140. /**
  141. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  142. *
  143. * @soc Handle to DP SoC structure
  144. * @pool_id
  145. *
  146. * Return:
  147. */
  148. static inline struct dp_tx_desc_s *
  149. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  150. {
  151. struct dp_tx_desc_s *tx_desc = NULL;
  152. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  153. if (pool) {
  154. qdf_spin_lock_bh(&pool->flow_pool_lock);
  155. if (pool->status <= FLOW_POOL_ACTIVE_PAUSED &&
  156. pool->avail_desc) {
  157. tx_desc = dp_tx_get_desc_flow_pool(pool);
  158. tx_desc->pool_id = desc_pool_id;
  159. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  160. if (qdf_unlikely(pool->avail_desc < pool->stop_th)) {
  161. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  162. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  163. /* pause network queues */
  164. soc->pause_cb(desc_pool_id,
  165. WLAN_STOP_ALL_NETIF_QUEUE,
  166. WLAN_DATA_FLOW_CONTROL);
  167. } else {
  168. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  169. }
  170. } else {
  171. pool->pkt_drop_no_desc++;
  172. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  173. }
  174. } else {
  175. soc->pool_stats.pkt_drop_no_pool++;
  176. }
  177. return tx_desc;
  178. }
  179. /**
  180. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  181. *
  182. * @soc Handle to DP SoC structure
  183. * @pool_id
  184. * @tx_desc
  185. *
  186. * Return: None
  187. */
  188. static inline void
  189. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  190. uint8_t desc_pool_id)
  191. {
  192. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  193. qdf_spin_lock_bh(&pool->flow_pool_lock);
  194. tx_desc->flags = 0;
  195. dp_tx_put_desc_flow_pool(pool, tx_desc);
  196. switch (pool->status) {
  197. case FLOW_POOL_ACTIVE_PAUSED:
  198. if (pool->avail_desc > pool->start_th) {
  199. soc->pause_cb(pool->flow_pool_id,
  200. WLAN_WAKE_ALL_NETIF_QUEUE,
  201. WLAN_DATA_FLOW_CONTROL);
  202. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  203. }
  204. break;
  205. case FLOW_POOL_INVALID:
  206. if (pool->avail_desc == pool->pool_size) {
  207. dp_tx_desc_pool_free(soc, desc_pool_id);
  208. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  209. qdf_print("%s %d pool is freed!!\n",
  210. __func__, __LINE__);
  211. return;
  212. }
  213. break;
  214. case FLOW_POOL_ACTIVE_UNPAUSED:
  215. break;
  216. default:
  217. qdf_print("%s %d pool is INACTIVE State!!\n",
  218. __func__, __LINE__);
  219. break;
  220. };
  221. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  222. }
  223. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  224. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  225. {
  226. }
  227. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  228. {
  229. }
  230. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  231. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  232. uint16_t flow_pool_size)
  233. {
  234. return QDF_STATUS_SUCCESS;
  235. }
  236. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  237. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  238. {
  239. }
  240. /**
  241. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  242. *
  243. * @param soc Handle to DP SoC structure
  244. * @param pool_id
  245. *
  246. * Return:
  247. */
  248. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  249. uint8_t desc_pool_id)
  250. {
  251. struct dp_tx_desc_s *tx_desc = NULL;
  252. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  253. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  254. /* Pool is exhausted */
  255. if (!tx_desc) {
  256. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  257. return NULL;
  258. }
  259. soc->tx_desc[desc_pool_id].freelist =
  260. soc->tx_desc[desc_pool_id].freelist->next;
  261. soc->tx_desc[desc_pool_id].num_allocated++;
  262. soc->tx_desc[desc_pool_id].num_free--;
  263. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  264. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  265. return tx_desc;
  266. }
  267. /**
  268. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  269. * from given pool
  270. * @soc: Handle to DP SoC structure
  271. * @pool_id: pool id should pick up
  272. * @num_requested: number of required descriptor
  273. *
  274. * allocate multiple tx descriptor and make a link
  275. *
  276. * Return: h_desc first descriptor pointer
  277. */
  278. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  279. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  280. {
  281. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  282. uint8_t count;
  283. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  284. if ((num_requested == 0) ||
  285. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  286. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  287. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  288. "%s, No Free Desc: Available(%d) num_requested(%d)",
  289. __func__, soc->tx_desc[desc_pool_id].num_free,
  290. num_requested);
  291. return NULL;
  292. }
  293. h_desc = soc->tx_desc[desc_pool_id].freelist;
  294. /* h_desc should never be NULL since num_free > requested */
  295. qdf_assert_always(h_desc);
  296. c_desc = h_desc;
  297. for (count = 0; count < (num_requested - 1); count++) {
  298. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  299. c_desc = c_desc->next;
  300. }
  301. soc->tx_desc[desc_pool_id].num_free -= count;
  302. soc->tx_desc[desc_pool_id].num_allocated += count;
  303. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  304. c_desc->next = NULL;
  305. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  306. return h_desc;
  307. }
  308. /**
  309. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  310. *
  311. * @soc Handle to DP SoC structure
  312. * @pool_id
  313. * @tx_desc
  314. */
  315. static inline void
  316. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  317. uint8_t desc_pool_id)
  318. {
  319. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  320. tx_desc->flags = 0;
  321. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  322. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  323. soc->tx_desc[desc_pool_id].num_allocated--;
  324. soc->tx_desc[desc_pool_id].num_free++;
  325. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  326. }
  327. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  328. /**
  329. * dp_tx_desc_find() - find dp tx descriptor from cokie
  330. * @soc - handle for the device sending the data
  331. * @tx_desc_id - the ID of the descriptor in question
  332. * @return the descriptor object that has the specified ID
  333. *
  334. * Use a tx descriptor ID to find the corresponding descriptor object.
  335. *
  336. */
  337. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  338. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  339. {
  340. struct dp_tx_desc_pool_s *tx_desc_pool = &((soc)->tx_desc[(pool_id)]);
  341. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  342. tx_desc_pool->elem_size * offset;
  343. }
  344. /**
  345. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  346. * @soc: handle for the device sending the data
  347. * @pool_id: target pool id
  348. *
  349. * Return: None
  350. */
  351. static inline
  352. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  353. uint8_t desc_pool_id)
  354. {
  355. struct dp_tx_ext_desc_elem_s *c_elem;
  356. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  357. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  358. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  359. return NULL;
  360. }
  361. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  362. soc->tx_ext_desc[desc_pool_id].freelist =
  363. soc->tx_ext_desc[desc_pool_id].freelist->next;
  364. soc->tx_ext_desc[desc_pool_id].num_free--;
  365. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  366. return c_elem;
  367. }
  368. /**
  369. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  370. * @soc: handle for the device sending the data
  371. * @pool_id: target pool id
  372. * @elem: ext descriptor pointer should release
  373. *
  374. * Return: None
  375. */
  376. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  377. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  378. {
  379. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  380. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  381. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  382. soc->tx_ext_desc[desc_pool_id].num_free++;
  383. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  384. return;
  385. }
  386. /**
  387. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  388. * attach it to free list
  389. * @soc: Handle to DP SoC structure
  390. * @desc_pool_id: pool id should pick up
  391. * @elem: tx descriptor should be freed
  392. * @num_free: number of descriptors should be freed
  393. *
  394. * Return: none
  395. */
  396. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  397. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  398. uint8_t num_free)
  399. {
  400. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  401. uint8_t freed = num_free;
  402. /* caller should always guarantee atleast list of num_free nodes */
  403. qdf_assert_always(head);
  404. head = elem;
  405. c_elem = head;
  406. tail = head;
  407. while (c_elem && freed) {
  408. tail = c_elem;
  409. c_elem = c_elem->next;
  410. freed--;
  411. }
  412. /* caller should always guarantee atleast list of num_free nodes */
  413. qdf_assert_always(tail);
  414. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  415. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  416. soc->tx_ext_desc[desc_pool_id].freelist = head;
  417. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  418. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  419. return;
  420. }
  421. #if defined(FEATURE_TSO)
  422. /**
  423. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  424. * @soc: device soc instance
  425. * @pool_id: pool id should pick up tso descriptor
  426. *
  427. * Allocates a TSO segment element from the free list held in
  428. * the soc
  429. *
  430. * Return: tso_seg, tso segment memory pointer
  431. */
  432. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  433. struct dp_soc *soc, uint8_t pool_id)
  434. {
  435. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  436. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  437. if (soc->tx_tso_desc[pool_id].freelist) {
  438. soc->tx_tso_desc[pool_id].num_free--;
  439. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  440. soc->tx_tso_desc[pool_id].freelist =
  441. soc->tx_tso_desc[pool_id].freelist->next;
  442. }
  443. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  444. return tso_seg;
  445. }
  446. /**
  447. * dp_tx_tso_desc_free() - function to free a TSO segment
  448. * @soc: device soc instance
  449. * @pool_id: pool id should pick up tso descriptor
  450. * @tso_seg: tso segment memory pointer
  451. *
  452. * Returns a TSO segment element to the free list held in the
  453. * HTT pdev
  454. *
  455. * Return: none
  456. */
  457. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  458. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  459. {
  460. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  461. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  462. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  463. soc->tx_tso_desc[pool_id].num_free++;
  464. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  465. }
  466. static inline
  467. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  468. uint8_t pool_id)
  469. {
  470. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  471. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  472. if (soc->tx_tso_num_seg[pool_id].freelist) {
  473. soc->tx_tso_num_seg[pool_id].num_free--;
  474. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  475. soc->tx_tso_num_seg[pool_id].freelist =
  476. soc->tx_tso_num_seg[pool_id].freelist->next;
  477. }
  478. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  479. return tso_num_seg;
  480. }
  481. static inline
  482. void dp_tso_num_seg_free(struct dp_soc *soc,
  483. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  484. {
  485. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  486. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  487. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  488. soc->tx_tso_num_seg[pool_id].num_free++;
  489. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  490. }
  491. #endif
  492. /*
  493. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  494. * @pdev DP_PDEV handle for datapath
  495. *
  496. * Return:dp_tx_me_buf_t(buf)
  497. */
  498. static inline struct dp_tx_me_buf_t*
  499. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  500. {
  501. struct dp_tx_me_buf_t *buf = NULL;
  502. qdf_spin_lock_bh(&pdev->tx_mutex);
  503. if (pdev->me_buf.freelist) {
  504. buf = pdev->me_buf.freelist;
  505. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  506. pdev->me_buf.buf_in_use++;
  507. } else {
  508. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  509. "Error allocating memory in pool");
  510. qdf_spin_unlock_bh(&pdev->tx_mutex);
  511. return NULL;
  512. }
  513. qdf_spin_unlock_bh(&pdev->tx_mutex);
  514. return buf;
  515. }
  516. /*
  517. * dp_tx_me_free_buf() - Free me descriptor and add it to pool
  518. * @pdev: DP_PDEV handle for datapath
  519. * @buf : Allocated ME BUF
  520. *
  521. * Return:void
  522. */
  523. static inline void
  524. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  525. {
  526. qdf_spin_lock_bh(&pdev->tx_mutex);
  527. buf->next = pdev->me_buf.freelist;
  528. pdev->me_buf.freelist = buf;
  529. pdev->me_buf.buf_in_use--;
  530. qdf_spin_unlock_bh(&pdev->tx_mutex);
  531. }
  532. #endif /* DP_TX_DESC_H */