qdf_nbuf_frag.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * Copyright (c) 2020 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. /**
  19. * DOC: qdf_nbuf_frag.h
  20. * This file defines the nbuf frag abstraction.
  21. */
  22. #ifndef _QDF_NBUF_FRAG_H
  23. #define _QDF_NBUF_FRAG_H
  24. #include <qdf_util.h>
  25. #include <i_qdf_trace.h>
  26. #include <i_qdf_nbuf_frag.h>
  27. /*
  28. * typedef qdf_frag_t - Platform independent frag address abstraction
  29. */
  30. typedef __qdf_frag_t qdf_frag_t;
  31. /**
  32. * Maximum number of frags an SKB can hold
  33. */
  34. #define QDF_NBUF_MAX_FRAGS __QDF_NBUF_MAX_FRAGS
  35. #ifdef NBUF_FRAG_MEMORY_DEBUG
  36. /**
  37. * qdf_frag_debug_init() - Initialize frag debug tracker
  38. *
  39. * Return: none
  40. */
  41. void qdf_frag_debug_init(void);
  42. /**
  43. * qdf_frag_debug_exit() - Destroy frag debug tracker
  44. *
  45. * Return: none
  46. */
  47. void qdf_frag_debug_exit(void);
  48. /**
  49. * qdf_frag_debug_add_node() - Add frag node in the debug hash table
  50. * @fragp: Pointer to frag
  51. * @func_name: Caller function name
  52. * @line_num: Caller function line no.
  53. *
  54. * Return: none
  55. */
  56. void qdf_frag_debug_add_node(qdf_frag_t fragp, const char *func_name,
  57. uint32_t line_num);
  58. /**
  59. * qdf_frag_debug_refcount_inc() - Increment refcount for frag node
  60. * @fragp: Pointer to frag
  61. * @func_name: Caller function name
  62. * @line_num: Caller function line no.
  63. *
  64. * Return: none
  65. */
  66. void qdf_frag_debug_refcount_inc(qdf_frag_t fragp, const char *func_name,
  67. uint32_t line_num);
  68. /**
  69. * qdf_frag_debug_refcount_dec() - Decrement refcount for frag node
  70. * @fragp: Pointer to frag
  71. * @func_name: Caller function name
  72. * @line_num: Caller function line no.
  73. *
  74. * Return: none
  75. */
  76. void qdf_frag_debug_refcount_dec(qdf_frag_t fragp, const char *func_name,
  77. uint32_t line_num);
  78. /**
  79. * qdf_frag_debug_delete_node() - Remove frag node from debug hash table
  80. * @fragp: Pointer to frag
  81. * @func_name: Caller function name
  82. * @line_num: Caller function line no.
  83. *
  84. * Return: none
  85. */
  86. void qdf_frag_debug_delete_node(qdf_frag_t fragp, const char *func_name,
  87. uint32_t line_num);
  88. /**
  89. * qdf_frag_debug_update_addr() - Update frag address in debug tracker
  90. * @p_fragp: Previous frag address
  91. * @n_fragp: New frag address
  92. * @func_name: Caller function name
  93. * @line_num: Caller function line no.
  94. *
  95. * Return: none
  96. */
  97. void qdf_frag_debug_update_addr(qdf_frag_t p_fragp, qdf_frag_t n_fragp,
  98. const char *func_name, uint32_t line_num);
  99. #define qdf_frag_alloc(s) \
  100. qdf_frag_alloc_debug(s, __func__, __LINE__)
  101. /**
  102. * qdf_frag_alloc_debug() - Allocate frag memory
  103. * @fragsz: Size of frag memory to be allocated
  104. * @func_name: Caller function name
  105. * @line_num: Caller function line no.
  106. *
  107. * Return: Allocated frag address
  108. */
  109. qdf_frag_t qdf_frag_alloc_debug(unsigned int fragsz, const char *func_name,
  110. uint32_t line_num);
  111. #define qdf_frag_free(p) \
  112. qdf_frag_free_debug(p, __func__, __LINE__)
  113. /**
  114. * qdf_frag_free_debug() - Free allocated frag memory
  115. * @vaddr: Frag address to be freed
  116. * @func_name: Caller function name
  117. * @line_num: Caller function line no.
  118. *
  119. * Return: none
  120. */
  121. void qdf_frag_free_debug(qdf_frag_t vaddr, const char *func_name,
  122. uint32_t line_num);
  123. #else /* NBUF_FRAG_MEMORY_DEBUG */
  124. static inline void qdf_frag_debug_init(void)
  125. {
  126. }
  127. static inline void qdf_frag_debug_exit(void)
  128. {
  129. }
  130. static inline void qdf_frag_debug_add_node(qdf_frag_t fragp,
  131. const char *func_name,
  132. uint32_t line_num)
  133. {
  134. }
  135. static inline void qdf_frag_debug_refcount_inc(qdf_frag_t fragp,
  136. const char *func_name,
  137. uint32_t line_num)
  138. {
  139. }
  140. static inline void qdf_frag_debug_refcount_dec(qdf_frag_t fragp,
  141. const char *func_name,
  142. uint32_t line_num)
  143. {
  144. }
  145. static inline void qdf_frag_debug_delete_node(qdf_frag_t fragp,
  146. const char *func_name,
  147. uint32_t line_num)
  148. {
  149. }
  150. static inline void qdf_frag_debug_update_addr(qdf_frag_t p_fragp,
  151. qdf_frag_t n_fragp,
  152. const char *func_name,
  153. uint32_t line_num)
  154. {
  155. }
  156. /**
  157. * qdf_frag_alloc() - Allocate frag memory
  158. * @fragsz: Size of frag memory to be allocated
  159. *
  160. * Return: Allocated frag address
  161. */
  162. static inline qdf_frag_t qdf_frag_alloc(unsigned int fragsz)
  163. {
  164. return __qdf_frag_alloc(fragsz);
  165. }
  166. /**
  167. * qdf_frag_free() - Free allocated frag memory
  168. * @vaddr: Frag address to be freed
  169. *
  170. * Return: none
  171. */
  172. static inline void qdf_frag_free(qdf_frag_t vaddr)
  173. {
  174. __qdf_frag_free(vaddr);
  175. }
  176. #endif /* NBUF_FRAG_MEMORY_DEBUG */
  177. /**
  178. * qdf_frag_count_get() - Get global frag gauge
  179. *
  180. * Return: Global frag gauge
  181. */
  182. static inline uint32_t qdf_frag_count_get(void)
  183. {
  184. return __qdf_frag_count_get();
  185. }
  186. /**
  187. * qdf_frag_count_inc() - Increment global frag count
  188. * @value: Increment value
  189. *
  190. * Return: none
  191. */
  192. static inline void qdf_frag_count_inc(uint32_t value)
  193. {
  194. return __qdf_frag_count_inc(value);
  195. }
  196. /**
  197. * qdf_frag_count_dec() - Decrement global frag count
  198. * @value: Decrement value
  199. *
  200. * Return: none
  201. */
  202. static inline void qdf_frag_count_dec(uint32_t value)
  203. {
  204. return __qdf_frag_count_dec(value);
  205. }
  206. /**
  207. * qdf_frag_mod_init() - Initialization routine for qdf_frag
  208. *
  209. * Return: none
  210. */
  211. static inline void qdf_frag_mod_init(void)
  212. {
  213. return __qdf_frag_mod_init();
  214. }
  215. /**
  216. * qdf_frag_mod_exit() - Unintialization routine for qdf_frag
  217. *
  218. * Return: none
  219. */
  220. static inline void qdf_frag_mod_exit(void)
  221. {
  222. return __qdf_frag_mod_exit();
  223. }
  224. /**
  225. * qdf_mem_map_page() - Map Page
  226. * @osdev: qdf_device_t
  227. * @buf: Virtual page address to be mapped
  228. * @dir: qdf_dma_dir_t
  229. * @nbytes: Size of memory to be mapped
  230. * @paddr: Corresponding mapped physical address
  231. *
  232. * Return: QDF_STATUS
  233. */
  234. static inline QDF_STATUS qdf_mem_map_page(qdf_device_t osdev, qdf_frag_t buf,
  235. qdf_dma_dir_t dir, size_t nbytes,
  236. qdf_dma_addr_t *phy_addr)
  237. {
  238. return __qdf_mem_map_page(osdev, buf, dir, nbytes, phy_addr);
  239. }
  240. /**
  241. * qdf_mem_unmap_page() - Unmap Page
  242. * @osdev: qdf_device_t
  243. * @paddr: Physical memory to be unmapped
  244. * @nbytes: Size of memory to be unmapped
  245. * @dir: qdf_dma_dir_t
  246. */
  247. static inline void qdf_mem_unmap_page(qdf_device_t osdev, qdf_dma_addr_t paddr,
  248. size_t nbytes, qdf_dma_dir_t dir)
  249. {
  250. __qdf_mem_unmap_page(osdev, paddr, nbytes, dir);
  251. }
  252. #endif /* _QDF_NBUF_FRAG_H */