qdf_nbuf_frag.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Copyright (c) 2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2023 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() - Exit network frag debug functionality
  50. *
  51. * Exit network frag tracking debug functionality and log frag memory leaks
  52. *
  53. * Return: none
  54. */
  55. void qdf_frag_debug_exit(void);
  56. /**
  57. * qdf_frag_debug_add_node() - Add frag node in the debug hash table
  58. * @fragp: Pointer to frag
  59. * @func_name: Caller function name
  60. * @line_num: Caller function line no.
  61. *
  62. * Return: none
  63. */
  64. void qdf_frag_debug_add_node(qdf_frag_t fragp, const char *func_name,
  65. uint32_t line_num);
  66. /**
  67. * qdf_frag_debug_refcount_inc() - Increment refcount for frag node
  68. * @fragp: Pointer to frag
  69. * @func_name: Caller function name
  70. * @line_num: Caller function line no.
  71. *
  72. * Return: none
  73. */
  74. void qdf_frag_debug_refcount_inc(qdf_frag_t fragp, const char *func_name,
  75. uint32_t line_num);
  76. /**
  77. * qdf_frag_debug_refcount_dec() - Decrement refcount for frag node
  78. * @fragp: Pointer to frag
  79. * @func_name: Caller function name
  80. * @line_num: Caller function line no.
  81. *
  82. * Return: none
  83. */
  84. void qdf_frag_debug_refcount_dec(qdf_frag_t fragp, const char *func_name,
  85. uint32_t line_num);
  86. /**
  87. * qdf_frag_debug_delete_node() - Remove frag node from debug hash table
  88. * @fragp: Pointer to frag
  89. * @func_name: Caller function name
  90. * @line_num: Caller function line no.
  91. *
  92. * Return: none
  93. */
  94. void qdf_frag_debug_delete_node(qdf_frag_t fragp, const char *func_name,
  95. uint32_t line_num);
  96. /**
  97. * qdf_frag_debug_update_addr() - Update frag address in debug tracker
  98. * @p_fragp: Previous frag address
  99. * @n_fragp: New frag address
  100. * @func_name: Caller function name
  101. * @line_num: Caller function line no.
  102. *
  103. * Return: none
  104. */
  105. void qdf_frag_debug_update_addr(qdf_frag_t p_fragp, qdf_frag_t n_fragp,
  106. const char *func_name, uint32_t line_num);
  107. #define qdf_frag_alloc(p, s) \
  108. qdf_frag_alloc_debug(p, s, __func__, __LINE__)
  109. /**
  110. * qdf_frag_alloc_debug() - Allocate frag memory
  111. * @pf_cache: page frag cache
  112. * @fragsz: Size of frag memory to be allocated
  113. * @func_name: Caller function name
  114. * @line_num: Caller function line no.
  115. *
  116. * Return: Allocated frag address
  117. */
  118. qdf_frag_t qdf_frag_alloc_debug(qdf_frag_cache_t *pf_cache,
  119. unsigned int fragsz,
  120. const char *func_name,
  121. uint32_t line_num);
  122. #define qdf_frag_free(p) \
  123. qdf_frag_free_debug(p, __func__, __LINE__)
  124. /**
  125. * qdf_frag_free_debug() - Free allocated frag memory
  126. * @vaddr: Frag address to be freed
  127. * @func_name: Caller function name
  128. * @line_num: Caller function line no.
  129. *
  130. * Return: none
  131. */
  132. void qdf_frag_free_debug(qdf_frag_t vaddr, const char *func_name,
  133. uint32_t line_num);
  134. #else /* NBUF_FRAG_MEMORY_DEBUG */
  135. static inline void qdf_frag_debug_init(void)
  136. {
  137. }
  138. static inline void qdf_frag_debug_exit(void)
  139. {
  140. }
  141. static inline void qdf_frag_debug_add_node(qdf_frag_t fragp,
  142. const char *func_name,
  143. uint32_t line_num)
  144. {
  145. }
  146. static inline void qdf_frag_debug_refcount_inc(qdf_frag_t fragp,
  147. const char *func_name,
  148. uint32_t line_num)
  149. {
  150. }
  151. static inline void qdf_frag_debug_refcount_dec(qdf_frag_t fragp,
  152. const char *func_name,
  153. uint32_t line_num)
  154. {
  155. }
  156. static inline void qdf_frag_debug_delete_node(qdf_frag_t fragp,
  157. const char *func_name,
  158. uint32_t line_num)
  159. {
  160. }
  161. static inline void qdf_frag_debug_update_addr(qdf_frag_t p_fragp,
  162. qdf_frag_t n_fragp,
  163. const char *func_name,
  164. uint32_t line_num)
  165. {
  166. }
  167. /**
  168. * qdf_frag_alloc() - Allocate frag memory
  169. * @pf_cache: page frag cache
  170. * @fragsz: Size of frag memory to be allocated
  171. *
  172. * Return: Allocated frag address
  173. */
  174. static inline qdf_frag_t qdf_frag_alloc(qdf_frag_cache_t *pf_cache,
  175. unsigned int fragsz)
  176. {
  177. return __qdf_frag_alloc(pf_cache, fragsz);
  178. }
  179. /**
  180. * qdf_frag_free() - Free allocated frag memory
  181. * @vaddr: Frag address to be freed
  182. *
  183. * Return: none
  184. */
  185. static inline void qdf_frag_free(qdf_frag_t vaddr)
  186. {
  187. __qdf_frag_free(vaddr);
  188. }
  189. #endif /* NBUF_FRAG_MEMORY_DEBUG */
  190. /**
  191. * qdf_frag_count_get() - Get global frag gauge
  192. *
  193. * Return: Global frag gauge
  194. */
  195. static inline uint32_t qdf_frag_count_get(void)
  196. {
  197. return __qdf_frag_count_get();
  198. }
  199. /**
  200. * qdf_frag_count_inc() - Increment global frag count
  201. * @value: Increment value
  202. *
  203. * Return: none
  204. */
  205. static inline void qdf_frag_count_inc(uint32_t value)
  206. {
  207. return __qdf_frag_count_inc(value);
  208. }
  209. /**
  210. * qdf_frag_count_dec() - Decrement global frag count
  211. * @value: Decrement value
  212. *
  213. * Return: none
  214. */
  215. static inline void qdf_frag_count_dec(uint32_t value)
  216. {
  217. return __qdf_frag_count_dec(value);
  218. }
  219. /**
  220. * qdf_frag_mod_init() - Initialization routine for qdf_frag
  221. *
  222. * Return: none
  223. */
  224. static inline void qdf_frag_mod_init(void)
  225. {
  226. return __qdf_frag_mod_init();
  227. }
  228. /**
  229. * qdf_frag_mod_exit() - Unintialization routine for qdf_frag
  230. *
  231. * Return: none
  232. */
  233. static inline void qdf_frag_mod_exit(void)
  234. {
  235. return __qdf_frag_mod_exit();
  236. }
  237. /**
  238. * qdf_mem_map_page() - Map Page
  239. * @osdev: qdf_device_t
  240. * @buf: Virtual page address to be mapped
  241. * @dir: qdf_dma_dir_t
  242. * @nbytes: Size of memory to be mapped
  243. * @phy_addr: Corresponding mapped physical address
  244. *
  245. * Return: QDF_STATUS
  246. */
  247. static inline QDF_STATUS qdf_mem_map_page(qdf_device_t osdev, qdf_frag_t buf,
  248. qdf_dma_dir_t dir, size_t nbytes,
  249. qdf_dma_addr_t *phy_addr)
  250. {
  251. return __qdf_mem_map_page(osdev, buf, dir, nbytes, phy_addr);
  252. }
  253. /**
  254. * qdf_mem_unmap_page() - Unmap Page
  255. * @osdev: qdf_device_t
  256. * @paddr: Physical memory to be unmapped
  257. * @nbytes: Size of memory to be unmapped
  258. * @dir: qdf_dma_dir_t
  259. */
  260. static inline void qdf_mem_unmap_page(qdf_device_t osdev, qdf_dma_addr_t paddr,
  261. size_t nbytes, qdf_dma_dir_t dir)
  262. {
  263. __qdf_mem_unmap_page(osdev, paddr, nbytes, dir);
  264. }
  265. /*
  266. * qdf_frag_cache_drain() - Drain page frag cache
  267. *
  268. * @pf_cache: page frag cache
  269. *
  270. * Return: void
  271. */
  272. static inline void qdf_frag_cache_drain(qdf_frag_cache_t *pf_cache)
  273. {
  274. __qdf_frag_cache_drain(pf_cache);
  275. }
  276. #endif /* _QDF_NBUF_FRAG_H */