dp_tx_desc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * Copyright (c) 2016-2017 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. /**
  24. * 21 bits cookie
  25. * 3 bits ring id 0 ~ 7, mask 0x1C0000, offset 18
  26. * 8 bits page id 0 ~ 255, mask 0x03C800, offset 10
  27. * 10 bits offset id 0 ~ 1023 mask 0x0003FF, offset 0
  28. */
  29. /* ???Ring ID needed??? */
  30. #define DP_TX_DESC_ID_POOL_MASK 0x1C0000
  31. #define DP_TX_DESC_ID_POOL_OS 18
  32. #define DP_TX_DESC_ID_PAGE_MASK 0x03FC00
  33. #define DP_TX_DESC_ID_PAGE_OS 10
  34. #define DP_TX_DESC_ID_OFFSET_MASK 0x0003FF
  35. #define DP_TX_DESC_ID_OFFSET_OS 0
  36. #define TX_DESC_LOCK_CREATE(lock) qdf_spinlock_create(lock)
  37. #define TX_DESC_LOCK_DESTROY(lock) qdf_spinlock_destroy(lock)
  38. #define TX_DESC_LOCK_LOCK(lock) qdf_spin_lock(lock)
  39. #define TX_DESC_LOCK_UNLOCK(lock) qdf_spin_unlock(lock)
  40. #define MAX_POOL_BUFF_COUNT 10000
  41. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  42. uint16_t num_elem);
  43. QDF_STATUS dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  44. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  45. uint16_t num_elem);
  46. QDF_STATUS dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  47. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  48. uint16_t num_elem);
  49. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  50. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  51. uint16_t num_elem);
  52. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t pool_id);
  53. /**
  54. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  55. *
  56. * @param soc Handle to DP SoC structure
  57. * @param pool_id
  58. *
  59. * Return:
  60. */
  61. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  62. uint8_t desc_pool_id)
  63. {
  64. struct dp_tx_desc_s *tx_desc = NULL;
  65. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  66. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  67. /* Pool is exhausted */
  68. if (!tx_desc) {
  69. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  70. return NULL;
  71. }
  72. if (soc->tx_desc[desc_pool_id].freelist) {
  73. soc->tx_desc[desc_pool_id].freelist =
  74. soc->tx_desc[desc_pool_id].freelist->next;
  75. soc->tx_desc[desc_pool_id].num_allocated++;
  76. soc->tx_desc[desc_pool_id].num_free--;
  77. }
  78. DP_STATS_INC(soc, tx.desc_in_use, 1);
  79. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  80. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  81. return tx_desc;
  82. }
  83. /**
  84. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  85. * from given pool
  86. * @soc: Handle to DP SoC structure
  87. * @pool_id: pool id should pick up
  88. * @num_requested: number of required descriptor
  89. *
  90. * allocate multiple tx descriptor and make a link
  91. *
  92. * Return: h_desc first descriptor pointer
  93. */
  94. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  95. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  96. {
  97. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  98. uint8_t count;
  99. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  100. if ((num_requested == 0) ||
  101. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  102. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  103. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  104. "%s, No Free Desc: Available(%d) num_requested(%d)",
  105. __func__, soc->tx_desc[desc_pool_id].num_free,
  106. num_requested);
  107. return NULL;
  108. }
  109. h_desc = soc->tx_desc[desc_pool_id].freelist;
  110. /* h_desc should never be NULL since num_free > requested */
  111. qdf_assert_always(h_desc);
  112. c_desc = h_desc;
  113. for (count = 0; count < (num_requested - 1); count++) {
  114. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  115. c_desc = c_desc->next;
  116. }
  117. soc->tx_desc[desc_pool_id].num_free -= count;
  118. soc->tx_desc[desc_pool_id].num_allocated += count;
  119. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  120. c_desc->next = NULL;
  121. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  122. return h_desc;
  123. }
  124. /**
  125. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  126. *
  127. * @soc Handle to DP SoC structure
  128. * @pool_id
  129. * @tx_desc
  130. */
  131. static inline void
  132. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  133. uint8_t desc_pool_id)
  134. {
  135. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  136. tx_desc->flags = 0;
  137. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  138. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  139. DP_STATS_DEC(soc, tx.desc_in_use, 1);
  140. soc->tx_desc[desc_pool_id].num_allocated--;
  141. soc->tx_desc[desc_pool_id].num_free++;
  142. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  143. }
  144. /**
  145. * dp_tx_desc_find() - find dp tx descriptor from cokie
  146. * @soc - handle for the device sending the data
  147. * @tx_desc_id - the ID of the descriptor in question
  148. * @return the descriptor object that has the specified ID
  149. *
  150. * Use a tx descriptor ID to find the corresponding descriptor object.
  151. *
  152. */
  153. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  154. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  155. {
  156. return soc->tx_desc[pool_id].desc_pages.cacheable_pages[page_id] +
  157. soc->tx_desc[pool_id].elem_size * offset;
  158. }
  159. /**
  160. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  161. * @soc: handle for the device sending the data
  162. * @pool_id: target pool id
  163. *
  164. * Return: None
  165. */
  166. static inline
  167. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  168. uint8_t desc_pool_id)
  169. {
  170. struct dp_tx_ext_desc_elem_s *c_elem;
  171. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  172. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  173. soc->tx_ext_desc[desc_pool_id].freelist =
  174. soc->tx_ext_desc[desc_pool_id].freelist->next;
  175. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  176. return c_elem;
  177. }
  178. /**
  179. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  180. * @soc: handle for the device sending the data
  181. * @pool_id: target pool id
  182. * @elem: ext descriptor pointer should release
  183. *
  184. * Return: None
  185. */
  186. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  187. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  188. {
  189. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  190. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  191. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  192. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  193. return;
  194. }
  195. /**
  196. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  197. * attach it to free list
  198. * @soc: Handle to DP SoC structure
  199. * @desc_pool_id: pool id should pick up
  200. * @elem: tx descriptor should be freed
  201. * @num_free: number of descriptors should be freed
  202. *
  203. * Return: none
  204. */
  205. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  206. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  207. uint8_t num_free)
  208. {
  209. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  210. uint8_t freed = num_free;
  211. /* caller should always guarantee atleast list of num_free nodes */
  212. qdf_assert_always(head);
  213. head = elem;
  214. c_elem = head;
  215. tail = head;
  216. while (c_elem && freed) {
  217. tail = c_elem;
  218. c_elem = c_elem->next;
  219. freed--;
  220. }
  221. /* caller should always guarantee atleast list of num_free nodes */
  222. qdf_assert_always(tail);
  223. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  224. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  225. soc->tx_ext_desc[desc_pool_id].freelist = head;
  226. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  227. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  228. return;
  229. }
  230. #if defined(FEATURE_TSO)
  231. /**
  232. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  233. * @soc: device soc instance
  234. * @pool_id: pool id should pick up tso descriptor
  235. *
  236. * Allocates a TSO segment element from the free list held in
  237. * the soc
  238. *
  239. * Return: tso_seg, tso segment memory pointer
  240. */
  241. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  242. struct dp_soc *soc, uint8_t pool_id)
  243. {
  244. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  245. TX_DESC_LOCK_LOCK(&soc->tx_tso_desc[pool_id].lock);
  246. if (soc->tx_tso_desc[pool_id].freelist) {
  247. soc->tx_tso_desc[pool_id].num_free--;
  248. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  249. soc->tx_tso_desc[pool_id].freelist =
  250. soc->tx_tso_desc[pool_id].freelist->next;
  251. }
  252. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_desc[pool_id].lock);
  253. return tso_seg;
  254. }
  255. /**
  256. * dp_tx_tso_desc_free() - function to free a TSO segment
  257. * @soc: device soc instance
  258. * @pool_id: pool id should pick up tso descriptor
  259. * @tso_seg: tso segment memory pointer
  260. *
  261. * Returns a TSO segment element to the free list held in the
  262. * HTT pdev
  263. *
  264. * Return: none
  265. */
  266. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  267. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  268. {
  269. TX_DESC_LOCK_LOCK(&soc->tx_tso_desc[pool_id].lock);
  270. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  271. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  272. soc->tx_tso_desc[pool_id].num_free++;
  273. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_desc[pool_id].lock);
  274. }
  275. static inline
  276. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  277. uint8_t pool_id)
  278. {
  279. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  280. TX_DESC_LOCK_LOCK(&soc->tx_tso_num_seg[pool_id].lock);
  281. if (soc->tx_tso_num_seg[pool_id].freelist) {
  282. soc->tx_tso_num_seg[pool_id].num_free--;
  283. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  284. soc->tx_tso_num_seg[pool_id].freelist =
  285. soc->tx_tso_num_seg[pool_id].freelist->next;
  286. }
  287. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_num_seg[pool_id].lock);
  288. return tso_num_seg;
  289. }
  290. static inline
  291. void dp_tso_num_seg_free(struct dp_soc *soc,
  292. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  293. {
  294. TX_DESC_LOCK_LOCK(&soc->tx_tso_num_seg[pool_id].lock);
  295. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  296. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  297. soc->tx_tso_num_seg[pool_id].num_free++;
  298. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_num_seg[pool_id].lock);
  299. }
  300. #endif
  301. /*
  302. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  303. * @pdev DP_PDEV handle for datapath
  304. *
  305. * Return:dp_tx_me_buf_t(buf)
  306. */
  307. static inline struct dp_tx_me_buf_t*
  308. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  309. {
  310. struct dp_tx_me_buf_t *buf = NULL;
  311. qdf_spin_lock_bh(&pdev->tx_mutex);
  312. if (pdev->me_buf.freelist) {
  313. buf = pdev->me_buf.freelist;
  314. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  315. pdev->me_buf.buf_in_use++;
  316. } else {
  317. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  318. "Error allocating memory in pool");
  319. qdf_spin_unlock_bh(&pdev->tx_mutex);
  320. return NULL;
  321. }
  322. qdf_spin_unlock_bh(&pdev->tx_mutex);
  323. return buf;
  324. }
  325. /*
  326. * dp_tx_me_free_buf() - Free me descriptor and add it to pool
  327. * @pdev: DP_PDEV handle for datapath
  328. * @buf : Allocated ME BUF
  329. *
  330. * Return:void
  331. */
  332. static inline void
  333. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  334. {
  335. qdf_spin_lock_bh(&pdev->tx_mutex);
  336. buf->next = pdev->me_buf.freelist;
  337. pdev->me_buf.freelist = buf;
  338. pdev->me_buf.buf_in_use--;
  339. qdf_spin_unlock_bh(&pdev->tx_mutex);
  340. }
  341. #endif /* DP_TX_DESC_H */