dp_tx_desc.h 20 KB

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