dp_tx_desc.h 11 KB

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