qdf_nbuf_frag.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. * Copyright (c) 2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qdf_nbuf_frag.h
  21. * This file defines the nbuf frag abstraction.
  22. */
  23. #ifndef _QDF_NBUF_FRAG_H
  24. #define _QDF_NBUF_FRAG_H
  25. #include <qdf_util.h>
  26. #include <i_qdf_trace.h>
  27. #include <i_qdf_nbuf_frag.h>
  28. /*
  29. * typedef qdf_frag_cache_t - Platform independent
  30. * frag cache abstraction
  31. */
  32. typedef __qdf_frag_cache_t qdf_frag_cache_t;
  33. /*
  34. * typedef qdf_frag_t - Platform independent frag address abstraction
  35. */
  36. typedef __qdf_frag_t qdf_frag_t;
  37. /**
  38. * Maximum number of frags an SKB can hold
  39. */
  40. #define QDF_NBUF_MAX_FRAGS __QDF_NBUF_MAX_FRAGS
  41. #ifdef NBUF_FRAG_MEMORY_DEBUG
  42. /**
  43. * qdf_frag_debug_init() - Initialize frag debug tracker
  44. *
  45. * Return: none
  46. */
  47. void qdf_frag_debug_init(void);
  48. /**
  49. * qdf_frag_debug_exit() - Destroy frag debug tracker
  50. *
  51. * Return: none
  52. */
  53. void qdf_frag_debug_exit(void);
  54. /**
  55. * qdf_frag_debug_add_node() - Add frag node in the debug hash table
  56. * @fragp: Pointer to frag
  57. * @func_name: Caller function name
  58. * @line_num: Caller function line no.
  59. *
  60. * Return: none
  61. */
  62. void qdf_frag_debug_add_node(qdf_frag_t fragp, const char *func_name,
  63. uint32_t line_num);
  64. /**
  65. * qdf_frag_debug_refcount_inc() - Increment refcount for frag node
  66. * @fragp: Pointer to frag
  67. * @func_name: Caller function name
  68. * @line_num: Caller function line no.
  69. *
  70. * Return: none
  71. */
  72. void qdf_frag_debug_refcount_inc(qdf_frag_t fragp, const char *func_name,
  73. uint32_t line_num);
  74. /**
  75. * qdf_frag_debug_refcount_dec() - Decrement refcount for frag node
  76. * @fragp: Pointer to frag
  77. * @func_name: Caller function name
  78. * @line_num: Caller function line no.
  79. *
  80. * Return: none
  81. */
  82. void qdf_frag_debug_refcount_dec(qdf_frag_t fragp, const char *func_name,
  83. uint32_t line_num);
  84. /**
  85. * qdf_frag_debug_delete_node() - Remove frag node from debug hash table
  86. * @fragp: Pointer to frag
  87. * @func_name: Caller function name
  88. * @line_num: Caller function line no.
  89. *
  90. * Return: none
  91. */
  92. void qdf_frag_debug_delete_node(qdf_frag_t fragp, const char *func_name,
  93. uint32_t line_num);
  94. /**
  95. * qdf_frag_debug_update_addr() - Update frag address in debug tracker
  96. * @p_fragp: Previous frag address
  97. * @n_fragp: New frag address
  98. * @func_name: Caller function name
  99. * @line_num: Caller function line no.
  100. *
  101. * Return: none
  102. */
  103. void qdf_frag_debug_update_addr(qdf_frag_t p_fragp, qdf_frag_t n_fragp,
  104. const char *func_name, uint32_t line_num);
  105. #define qdf_frag_alloc(p, s) \
  106. qdf_frag_alloc_debug(p, s, __func__, __LINE__)
  107. /**
  108. * qdf_frag_alloc_debug() - Allocate frag memory
  109. * @pf_cache: page frag cache
  110. * @fragsz: Size of frag memory to be allocated
  111. * @func_name: Caller function name
  112. * @line_num: Caller function line no.
  113. *
  114. * Return: Allocated frag address
  115. */
  116. qdf_frag_t qdf_frag_alloc_debug(qdf_frag_cache_t *pf_cache,
  117. unsigned int fragsz,
  118. const char *func_name,
  119. uint32_t line_num);
  120. #define qdf_frag_free(p) \
  121. qdf_frag_free_debug(p, __func__, __LINE__)
  122. /**
  123. * qdf_frag_free_debug() - Free allocated frag memory
  124. * @vaddr: Frag address to be freed
  125. * @func_name: Caller function name
  126. * @line_num: Caller function line no.
  127. *
  128. * Return: none
  129. */
  130. void qdf_frag_free_debug(qdf_frag_t vaddr, const char *func_name,
  131. uint32_t line_num);
  132. #else /* NBUF_FRAG_MEMORY_DEBUG */
  133. static inline void qdf_frag_debug_init(void)
  134. {
  135. }
  136. static inline void qdf_frag_debug_exit(void)
  137. {
  138. }
  139. static inline void qdf_frag_debug_add_node(qdf_frag_t fragp,
  140. const char *func_name,
  141. uint32_t line_num)
  142. {
  143. }
  144. static inline void qdf_frag_debug_refcount_inc(qdf_frag_t fragp,
  145. const char *func_name,
  146. uint32_t line_num)
  147. {
  148. }
  149. static inline void qdf_frag_debug_refcount_dec(qdf_frag_t fragp,
  150. const char *func_name,
  151. uint32_t line_num)
  152. {
  153. }
  154. static inline void qdf_frag_debug_delete_node(qdf_frag_t fragp,
  155. const char *func_name,
  156. uint32_t line_num)
  157. {
  158. }
  159. static inline void qdf_frag_debug_update_addr(qdf_frag_t p_fragp,
  160. qdf_frag_t n_fragp,
  161. const char *func_name,
  162. uint32_t line_num)
  163. {
  164. }
  165. /**
  166. * qdf_frag_alloc() - Allocate frag memory
  167. * @pf_cache: page frag cache
  168. * @fragsz: Size of frag memory to be allocated
  169. *
  170. * Return: Allocated frag address
  171. */
  172. static inline qdf_frag_t qdf_frag_alloc(qdf_frag_cache_t *pf_cache,
  173. unsigned int fragsz)
  174. {
  175. return __qdf_frag_alloc(pf_cache, fragsz);
  176. }
  177. /**
  178. * qdf_frag_free() - Free allocated frag memory
  179. * @vaddr: Frag address to be freed
  180. *
  181. * Return: none
  182. */
  183. static inline void qdf_frag_free(qdf_frag_t vaddr)
  184. {
  185. __qdf_frag_free(vaddr);
  186. }
  187. #endif /* NBUF_FRAG_MEMORY_DEBUG */
  188. /**
  189. * qdf_frag_count_get() - Get global frag gauge
  190. *
  191. * Return: Global frag gauge
  192. */
  193. static inline uint32_t qdf_frag_count_get(void)
  194. {
  195. return __qdf_frag_count_get();
  196. }
  197. /**
  198. * qdf_frag_count_inc() - Increment global frag count
  199. * @value: Increment value
  200. *
  201. * Return: none
  202. */
  203. static inline void qdf_frag_count_inc(uint32_t value)
  204. {
  205. return __qdf_frag_count_inc(value);
  206. }
  207. /**
  208. * qdf_frag_count_dec() - Decrement global frag count
  209. * @value: Decrement value
  210. *
  211. * Return: none
  212. */
  213. static inline void qdf_frag_count_dec(uint32_t value)
  214. {
  215. return __qdf_frag_count_dec(value);
  216. }
  217. /**
  218. * qdf_frag_mod_init() - Initialization routine for qdf_frag
  219. *
  220. * Return: none
  221. */
  222. static inline void qdf_frag_mod_init(void)
  223. {
  224. return __qdf_frag_mod_init();
  225. }
  226. /**
  227. * qdf_frag_mod_exit() - Unintialization routine for qdf_frag
  228. *
  229. * Return: none
  230. */
  231. static inline void qdf_frag_mod_exit(void)
  232. {
  233. return __qdf_frag_mod_exit();
  234. }
  235. /**
  236. * qdf_mem_map_page() - Map Page
  237. * @osdev: qdf_device_t
  238. * @buf: Virtual page address to be mapped
  239. * @dir: qdf_dma_dir_t
  240. * @nbytes: Size of memory to be mapped
  241. * @paddr: Corresponding mapped physical address
  242. *
  243. * Return: QDF_STATUS
  244. */
  245. static inline QDF_STATUS qdf_mem_map_page(qdf_device_t osdev, qdf_frag_t buf,
  246. qdf_dma_dir_t dir, size_t nbytes,
  247. qdf_dma_addr_t *phy_addr)
  248. {
  249. return __qdf_mem_map_page(osdev, buf, dir, nbytes, phy_addr);
  250. }
  251. /**
  252. * qdf_mem_unmap_page() - Unmap Page
  253. * @osdev: qdf_device_t
  254. * @paddr: Physical memory to be unmapped
  255. * @nbytes: Size of memory to be unmapped
  256. * @dir: qdf_dma_dir_t
  257. */
  258. static inline void qdf_mem_unmap_page(qdf_device_t osdev, qdf_dma_addr_t paddr,
  259. size_t nbytes, qdf_dma_dir_t dir)
  260. {
  261. __qdf_mem_unmap_page(osdev, paddr, nbytes, dir);
  262. }
  263. /*
  264. * qdf_frag_cache_drain() - Drain page frag cache
  265. *
  266. * @pf_cache: page frag cache
  267. *
  268. * Return: void
  269. */
  270. static inline void qdf_frag_cache_drain(qdf_frag_cache_t *pf_cache)
  271. {
  272. __qdf_frag_cache_drain(pf_cache);
  273. }
  274. #endif /* _QDF_NBUF_FRAG_H */