dp_tx_desc.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  41. uint16_t num_elem);
  42. QDF_STATUS dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  43. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  44. uint16_t num_elem);
  45. QDF_STATUS dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  46. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  47. uint16_t num_elem);
  48. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  49. /**
  50. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  51. *
  52. * @param soc Handle to DP SoC structure
  53. * @param pool_id
  54. *
  55. * Return:
  56. */
  57. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  58. uint8_t desc_pool_id)
  59. {
  60. struct dp_tx_desc_s *tx_desc = NULL;
  61. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  62. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  63. /* Pool is exhausted */
  64. if (!tx_desc) {
  65. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  66. return NULL;
  67. }
  68. if (soc->tx_desc[desc_pool_id].freelist) {
  69. soc->tx_desc[desc_pool_id].freelist =
  70. soc->tx_desc[desc_pool_id].freelist->next;
  71. soc->tx_desc[desc_pool_id].num_allocated++;
  72. soc->tx_desc[desc_pool_id].num_free--;
  73. }
  74. DP_STATS_INC(soc, tx.desc_in_use, 1);
  75. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  76. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  77. return tx_desc;
  78. }
  79. /**
  80. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  81. * from given pool
  82. * @soc: Handle to DP SoC structure
  83. * @pool_id: pool id should pick up
  84. * @num_requested: number of required descriptor
  85. *
  86. * allocate multiple tx descriptor and make a link
  87. *
  88. * Return: h_desc first descriptor pointer
  89. */
  90. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  91. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  92. {
  93. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  94. uint8_t count;
  95. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  96. if ((num_requested == 0) ||
  97. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  98. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  99. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  100. "%s, No Free Desc: Available(%d) num_requested(%d)",
  101. __func__, soc->tx_desc[desc_pool_id].num_free,
  102. num_requested);
  103. return NULL;
  104. }
  105. h_desc = soc->tx_desc[desc_pool_id].freelist;
  106. /* h_desc should never be NULL since num_free > requested */
  107. qdf_assert_always(h_desc);
  108. c_desc = h_desc;
  109. for (count = 0; count < (num_requested - 1); count++) {
  110. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  111. c_desc = c_desc->next;
  112. }
  113. soc->tx_desc[desc_pool_id].num_free -= count;
  114. soc->tx_desc[desc_pool_id].num_allocated += count;
  115. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  116. c_desc->next = NULL;
  117. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  118. return h_desc;
  119. }
  120. /**
  121. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  122. *
  123. * @soc Handle to DP SoC structure
  124. * @pool_id
  125. * @tx_desc
  126. */
  127. static inline void
  128. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  129. uint8_t desc_pool_id)
  130. {
  131. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  132. tx_desc->flags = 0;
  133. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  134. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  135. DP_STATS_DEC(soc, tx.desc_in_use, 1);
  136. soc->tx_desc[desc_pool_id].num_allocated--;
  137. soc->tx_desc[desc_pool_id].num_free++;
  138. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  139. }
  140. /**
  141. * dp_tx_desc_find() - find dp tx descriptor from cokie
  142. * @soc - handle for the device sending the data
  143. * @tx_desc_id - the ID of the descriptor in question
  144. * @return the descriptor object that has the specified ID
  145. *
  146. * Use a tx descriptor ID to find the corresponding descriptor object.
  147. *
  148. */
  149. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  150. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  151. {
  152. return soc->tx_desc[pool_id].desc_pages.cacheable_pages[page_id] +
  153. soc->tx_desc[pool_id].elem_size * offset;
  154. }
  155. /**
  156. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  157. * @soc: handle for the device sending the data
  158. * @pool_id: target pool id
  159. *
  160. * Return: None
  161. */
  162. static inline
  163. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  164. uint8_t desc_pool_id)
  165. {
  166. struct dp_tx_ext_desc_elem_s *c_elem;
  167. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  168. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  169. soc->tx_ext_desc[desc_pool_id].freelist =
  170. soc->tx_ext_desc[desc_pool_id].freelist->next;
  171. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  172. return c_elem;
  173. }
  174. /**
  175. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  176. * @soc: handle for the device sending the data
  177. * @pool_id: target pool id
  178. * @elem: ext descriptor pointer should release
  179. *
  180. * Return: None
  181. */
  182. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  183. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  184. {
  185. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  186. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  187. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  188. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  189. return;
  190. }
  191. /**
  192. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  193. * attach it to free list
  194. * @soc: Handle to DP SoC structure
  195. * @desc_pool_id: pool id should pick up
  196. * @elem: tx descriptor should be freed
  197. * @num_free: number of descriptors should be freed
  198. *
  199. * Return: none
  200. */
  201. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  202. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  203. uint8_t num_free)
  204. {
  205. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  206. uint8_t freed = num_free;
  207. /* caller should always guarantee atleast list of num_free nodes */
  208. qdf_assert_always(head);
  209. head = elem;
  210. c_elem = head;
  211. tail = head;
  212. while (c_elem && freed) {
  213. tail = c_elem;
  214. c_elem = c_elem->next;
  215. freed--;
  216. }
  217. /* caller should always guarantee atleast list of num_free nodes */
  218. qdf_assert_always(tail);
  219. TX_DESC_LOCK_LOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  220. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  221. soc->tx_ext_desc[desc_pool_id].freelist = head;
  222. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  223. TX_DESC_LOCK_UNLOCK(&soc->tx_ext_desc[desc_pool_id].lock);
  224. return;
  225. }
  226. /**
  227. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  228. * @soc: device soc instance
  229. * @pool_id: pool id should pick up tso descriptor
  230. *
  231. * Allocates a TSO segment element from the free list held in
  232. * the soc
  233. *
  234. * Return: tso_seg, tso segment memory pointer
  235. */
  236. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  237. struct dp_soc *soc, uint8_t pool_id)
  238. {
  239. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  240. TX_DESC_LOCK_LOCK(&soc->tx_tso_desc[pool_id].lock);
  241. if (soc->tx_tso_desc[pool_id].freelist) {
  242. soc->tx_tso_desc[pool_id].num_free--;
  243. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  244. soc->tx_tso_desc[pool_id].freelist =
  245. soc->tx_tso_desc[pool_id].freelist->next;
  246. }
  247. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_desc[pool_id].lock);
  248. return tso_seg;
  249. }
  250. /**
  251. * dp_tx_tso_desc_free() - function to free a TSO segment
  252. * @soc: device soc instance
  253. * @pool_id: pool id should pick up tso descriptor
  254. * @tso_seg: tso segment memory pointer
  255. *
  256. * Returns a TSO segment element to the free list held in the
  257. * HTT pdev
  258. *
  259. * Return: none
  260. */
  261. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  262. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  263. {
  264. TX_DESC_LOCK_LOCK(&soc->tx_tso_desc[pool_id].lock);
  265. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  266. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  267. soc->tx_tso_desc[pool_id].num_free++;
  268. TX_DESC_LOCK_UNLOCK(&soc->tx_tso_desc[pool_id].lock);
  269. }
  270. #endif /* DP_TX_DESC_H */