qdf_mem.h 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /*
  2. * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-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_mem
  21. * QCA driver framework (QDF) memory management APIs
  22. */
  23. #if !defined(__QDF_MEMORY_H)
  24. #define __QDF_MEMORY_H
  25. /* Include Files */
  26. #include <qdf_types.h>
  27. #include <i_qdf_mem.h>
  28. #include <i_qdf_trace.h>
  29. #include <qdf_atomic.h>
  30. #define QDF_CACHE_LINE_SZ __qdf_cache_line_sz
  31. /**
  32. * qdf_align() - align to the given size.
  33. * @a: input that needs to be aligned.
  34. * @align_size: boundary on which 'a' has to be alinged.
  35. *
  36. * Return: aligned value.
  37. */
  38. #define qdf_align(a, align_size) __qdf_align(a, align_size)
  39. #define qdf_page_size __page_size
  40. /**
  41. * struct qdf_mem_dma_page_t - Allocated dmaable page
  42. * @page_v_addr_start: Page start virtual address
  43. * @page_v_addr_end: Page end virtual address
  44. * @page_p_addr: Page start physical address
  45. */
  46. struct qdf_mem_dma_page_t {
  47. char *page_v_addr_start;
  48. char *page_v_addr_end;
  49. qdf_dma_addr_t page_p_addr;
  50. };
  51. /**
  52. * struct qdf_mem_multi_page_t - multiple page allocation information storage
  53. * @num_element_per_page: Number of element in single page
  54. * @num_pages: Number of allocation needed pages
  55. * @dma_pages: page information storage in case of coherent memory
  56. * @cacheable_pages: page information storage in case of cacheable memory
  57. * @is_mem_prealloc: flag for multiple pages pre-alloc or not
  58. */
  59. struct qdf_mem_multi_page_t {
  60. uint16_t num_element_per_page;
  61. uint16_t num_pages;
  62. struct qdf_mem_dma_page_t *dma_pages;
  63. void **cacheable_pages;
  64. qdf_size_t page_size;
  65. #ifdef DP_MEM_PRE_ALLOC
  66. uint8_t is_mem_prealloc;
  67. #endif
  68. };
  69. /* Preprocessor definitions and constants */
  70. typedef __qdf_mempool_t qdf_mempool_t;
  71. /**
  72. * qdf_mem_init() - Initialize QDF memory module
  73. *
  74. * Return: None
  75. *
  76. */
  77. void qdf_mem_init(void);
  78. /**
  79. * qdf_mem_exit() - Exit QDF memory module
  80. *
  81. * Return: None
  82. *
  83. */
  84. void qdf_mem_exit(void);
  85. #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
  86. #define qdf_untracked_mem_malloc(size) \
  87. __qdf_untracked_mem_malloc(size, __func__, __LINE__)
  88. #define qdf_untracked_mem_free(ptr) \
  89. __qdf_untracked_mem_free(ptr)
  90. #endif
  91. #define QDF_MEM_FUNC_NAME_SIZE 48
  92. #ifdef MEMORY_DEBUG
  93. /**
  94. * qdf_mem_debug_config_get() - Get the user configuration of mem_debug_disabled
  95. *
  96. * Return: value of mem_debug_disabled qdf module argument
  97. */
  98. bool qdf_mem_debug_config_get(void);
  99. #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
  100. /**
  101. * qdf_mem_debug_disabled_set() - Set mem_debug_disabled
  102. * @str_value: value of the module param
  103. *
  104. * This function will set qdf module param mem_debug_disabled
  105. *
  106. * Return: QDF_STATUS_SUCCESS on Success
  107. */
  108. QDF_STATUS qdf_mem_debug_disabled_config_set(const char *str_value);
  109. #endif
  110. /**
  111. * qdf_mem_malloc_atomic_debug() - debug version of QDF memory allocation API
  112. * @size: Number of bytes of memory to allocate.
  113. * @func: Function name of the call site
  114. * @line: Line number of the call site
  115. * @caller: Address of the caller function
  116. *
  117. * This function will dynamicallly allocate the specified number of bytes of
  118. * memory and add it to the qdf tracking list to check for memory leaks and
  119. * corruptions
  120. *
  121. * Return: A valid memory location on success, or NULL on failure
  122. */
  123. void *qdf_mem_malloc_atomic_debug(size_t size, const char *func,
  124. uint32_t line, void *caller);
  125. /**
  126. * qdf_mem_malloc_atomic_debug_fl() - allocation QDF memory atomically
  127. * @size: Number of bytes of memory to allocate.
  128. *
  129. * This function will dynamicallly allocate the specified number of bytes of
  130. * memory.
  131. *
  132. * Return:
  133. * Upon successful allocate, returns a non-NULL pointer to the allocated
  134. * memory. If this function is unable to allocate the amount of memory
  135. * specified (for any reason) it returns NULL.
  136. */
  137. void *qdf_mem_malloc_atomic_debug_fl(qdf_size_t size, const char *func,
  138. uint32_t line);
  139. /**
  140. * qdf_mem_malloc_debug() - debug version of QDF memory allocation API
  141. * @size: Number of bytes of memory to allocate.
  142. * @func: Function name of the call site
  143. * @line: Line number of the call site
  144. * @caller: Address of the caller function
  145. * @flag: GFP flag
  146. *
  147. * This function will dynamicallly allocate the specified number of bytes of
  148. * memory and add it to the qdf tracking list to check for memory leaks and
  149. * corruptions
  150. *
  151. * Return: A valid memory location on success, or NULL on failure
  152. */
  153. void *qdf_mem_malloc_debug(size_t size, const char *func, uint32_t line,
  154. void *caller, uint32_t flag);
  155. #define qdf_mem_malloc(size) \
  156. qdf_mem_malloc_debug(size, __func__, __LINE__, QDF_RET_IP, 0)
  157. #define qdf_mem_malloc_fl(size, func, line) \
  158. qdf_mem_malloc_debug(size, func, line, QDF_RET_IP, 0)
  159. #define qdf_mem_malloc_atomic(size) \
  160. qdf_mem_malloc_atomic_debug(size, __func__, __LINE__, QDF_RET_IP)
  161. /**
  162. * qdf_mem_free_debug() - debug version of qdf_mem_free
  163. * @ptr: Pointer to the starting address of the memory to be freed.
  164. *
  165. * This function will free the memory pointed to by 'ptr'. It also checks for
  166. * memory corruption, underrun, overrun, double free, domain mismatch, etc.
  167. *
  168. * Return: none
  169. */
  170. void qdf_mem_free_debug(void *ptr, const char *file, uint32_t line);
  171. #define qdf_mem_free(ptr) \
  172. qdf_mem_free_debug(ptr, __func__, __LINE__)
  173. void qdf_mem_multi_pages_alloc_debug(qdf_device_t osdev,
  174. struct qdf_mem_multi_page_t *pages,
  175. size_t element_size, uint32_t element_num,
  176. qdf_dma_context_t memctxt, bool cacheable,
  177. const char *func, uint32_t line,
  178. void *caller);
  179. #define qdf_mem_multi_pages_alloc(osdev, pages, element_size, element_num,\
  180. memctxt, cacheable) \
  181. qdf_mem_multi_pages_alloc_debug(osdev, pages, element_size, \
  182. element_num, memctxt, cacheable, \
  183. __func__, __LINE__, QDF_RET_IP)
  184. void qdf_mem_multi_pages_free_debug(qdf_device_t osdev,
  185. struct qdf_mem_multi_page_t *pages,
  186. qdf_dma_context_t memctxt, bool cacheable,
  187. const char *func, uint32_t line);
  188. #define qdf_mem_multi_pages_free(osdev, pages, memctxt, cacheable) \
  189. qdf_mem_multi_pages_free_debug(osdev, pages, memctxt, cacheable, \
  190. __func__, __LINE__)
  191. /**
  192. * qdf_mem_check_for_leaks() - Assert that the current memory domain is empty
  193. *
  194. * Call this to ensure there are no active memory allocations being tracked
  195. * against the current debug domain. For example, one should call this function
  196. * immediately before a call to qdf_debug_domain_set() as a memory leak
  197. * detection mechanism.
  198. *
  199. * e.g.
  200. * qdf_debug_domain_set(QDF_DEBUG_DOMAIN_ACTIVE);
  201. *
  202. * ...
  203. *
  204. * // memory is allocated and freed
  205. *
  206. * ...
  207. *
  208. * // before transitioning back to inactive state,
  209. * // make sure all active memory has been freed
  210. * qdf_mem_check_for_leaks();
  211. * qdf_debug_domain_set(QDF_DEBUG_DOMAIN_INIT);
  212. *
  213. * ...
  214. *
  215. * // also, before program exit, make sure init time memory is freed
  216. * qdf_mem_check_for_leaks();
  217. * exit();
  218. *
  219. * Return: None
  220. */
  221. void qdf_mem_check_for_leaks(void);
  222. /**
  223. * qdf_mem_alloc_consistent_debug() - allocates consistent qdf memory
  224. * @osdev: OS device handle
  225. * @dev: Pointer to device handle
  226. * @size: Size to be allocated
  227. * @paddr: Physical address
  228. * @func: Function name of the call site
  229. * @line: line numbe rof the call site
  230. * @caller: Address of the caller function
  231. *
  232. * Return: pointer of allocated memory or null if memory alloc fails
  233. */
  234. void *qdf_mem_alloc_consistent_debug(qdf_device_t osdev, void *dev,
  235. qdf_size_t size, qdf_dma_addr_t *paddr,
  236. const char *func, uint32_t line,
  237. void *caller);
  238. #define qdf_mem_alloc_consistent(osdev, dev, size, paddr) \
  239. qdf_mem_alloc_consistent_debug(osdev, dev, size, paddr, \
  240. __func__, __LINE__, QDF_RET_IP)
  241. /**
  242. * qdf_mem_free_consistent_debug() - free consistent qdf memory
  243. * @osdev: OS device handle
  244. * @size: Size to be allocated
  245. * @vaddr: virtual address
  246. * @paddr: Physical address
  247. * @memctx: Pointer to DMA context
  248. * @func: Function name of the call site
  249. * @line: line numbe rof the call site
  250. *
  251. * Return: none
  252. */
  253. void qdf_mem_free_consistent_debug(qdf_device_t osdev, void *dev,
  254. qdf_size_t size, void *vaddr,
  255. qdf_dma_addr_t paddr,
  256. qdf_dma_context_t memctx,
  257. const char *func, uint32_t line);
  258. #define qdf_mem_free_consistent(osdev, dev, size, vaddr, paddr, memctx) \
  259. qdf_mem_free_consistent_debug(osdev, dev, size, vaddr, paddr, memctx, \
  260. __func__, __LINE__)
  261. #else
  262. static inline bool qdf_mem_debug_config_get(void)
  263. {
  264. return false;
  265. }
  266. static inline
  267. QDF_STATUS qdf_mem_debug_disabled_config_set(const char *str_value)
  268. {
  269. return QDF_STATUS_SUCCESS;
  270. }
  271. /**
  272. * qdf_mem_malloc() - allocation QDF memory
  273. * @size: Number of bytes of memory to allocate.
  274. *
  275. * This function will dynamicallly allocate the specified number of bytes of
  276. * memory.
  277. *
  278. * Return:
  279. * Upon successful allocate, returns a non-NULL pointer to the allocated
  280. * memory. If this function is unable to allocate the amount of memory
  281. * specified (for any reason) it returns NULL.
  282. */
  283. #define qdf_mem_malloc(size) \
  284. __qdf_mem_malloc(size, __func__, __LINE__)
  285. #define qdf_mem_malloc_fl(size, func, line) \
  286. __qdf_mem_malloc(size, func, line)
  287. /**
  288. * qdf_mem_malloc_atomic() - allocation QDF memory atomically
  289. * @size: Number of bytes of memory to allocate.
  290. *
  291. * This function will dynamicallly allocate the specified number of bytes of
  292. * memory.
  293. *
  294. * Return:
  295. * Upon successful allocate, returns a non-NULL pointer to the allocated
  296. * memory. If this function is unable to allocate the amount of memory
  297. * specified (for any reason) it returns NULL.
  298. */
  299. #define qdf_mem_malloc_atomic(size) \
  300. qdf_mem_malloc_atomic_fl(size, __func__, __LINE__)
  301. void *qdf_mem_malloc_atomic_fl(qdf_size_t size,
  302. const char *func,
  303. uint32_t line);
  304. #define qdf_mem_free(ptr) \
  305. __qdf_mem_free(ptr)
  306. static inline void qdf_mem_check_for_leaks(void) { }
  307. #define qdf_mem_alloc_consistent(osdev, dev, size, paddr) \
  308. __qdf_mem_alloc_consistent(osdev, dev, size, paddr, __func__, __LINE__)
  309. #define qdf_mem_free_consistent(osdev, dev, size, vaddr, paddr, memctx) \
  310. __qdf_mem_free_consistent(osdev, dev, size, vaddr, paddr, memctx)
  311. void qdf_mem_multi_pages_alloc(qdf_device_t osdev,
  312. struct qdf_mem_multi_page_t *pages,
  313. size_t element_size, uint32_t element_num,
  314. qdf_dma_context_t memctxt, bool cacheable);
  315. void qdf_mem_multi_pages_free(qdf_device_t osdev,
  316. struct qdf_mem_multi_page_t *pages,
  317. qdf_dma_context_t memctxt, bool cacheable);
  318. #endif /* MEMORY_DEBUG */
  319. /**
  320. * qdf_mem_malloc_flags: Get mem allocation flags
  321. *
  322. * Return the flag to be use for memory allocation
  323. * based on the context
  324. *
  325. * Returns: Based on the context, returns the GFP flag
  326. * for memory alloaction
  327. */
  328. int qdf_mem_malloc_flags(void);
  329. /**
  330. * qdf_prealloc_disabled_config_get() - Get the user configuration of
  331. * prealloc_disabled
  332. *
  333. * Return: value of prealloc_disabled qdf module argument
  334. */
  335. bool qdf_prealloc_disabled_config_get(void);
  336. #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
  337. /**
  338. * qdf_prealloc_disabled_config_set() - Set prealloc_disabled
  339. * @str_value: value of the module param
  340. *
  341. * This function will set qdf module param prealloc_disabled
  342. *
  343. * Return: QDF_STATUS_SUCCESS on Success
  344. */
  345. QDF_STATUS qdf_prealloc_disabled_config_set(const char *str_value);
  346. #endif
  347. /**
  348. * qdf_mem_multi_pages_zero() - zero out each page memory
  349. * @pages: Multi page information storage
  350. * @cacheable: Coherent memory or cacheable memory
  351. *
  352. * This function will zero out each page memory
  353. *
  354. * Return: None
  355. */
  356. void qdf_mem_multi_pages_zero(struct qdf_mem_multi_page_t *pages,
  357. bool cacheable);
  358. /**
  359. * qdf_aligned_malloc() - allocates aligned QDF memory.
  360. * @size: Size to be allocated
  361. * @vaddr_unaligned: Unaligned virtual address.
  362. * @paddr_unaligned: Unaligned physical address.
  363. * @paddr_aligned: Aligned physical address.
  364. * @align: Base address alignment.
  365. * @func: Function name of the call site.
  366. * @line: Line number of the call site.
  367. *
  368. * This function will dynamically allocate the specified number of bytes of
  369. * memory. Checks if the allocated base address is aligned with base_align.
  370. * If not, it frees the allocated memory, adds base_align to alloc size and
  371. * re-allocates the memory.
  372. *
  373. * Return:
  374. * Upon successful allocate, returns an aligned base address of the allocated
  375. * memory. If this function is unable to allocate the amount of memory
  376. * specified (for any reason) it returns NULL.
  377. */
  378. #define qdf_aligned_malloc(size, vaddr_unaligned, paddr_unaligned, \
  379. paddr_aligned, align) \
  380. qdf_aligned_malloc_fl(size, vaddr_unaligned, paddr_unaligned, \
  381. paddr_aligned, align, __func__, __LINE__)
  382. void *qdf_aligned_malloc_fl(uint32_t *size, void **vaddr_unaligned,
  383. qdf_dma_addr_t *paddr_unaligned,
  384. qdf_dma_addr_t *paddr_aligned,
  385. uint32_t align,
  386. const char *func, uint32_t line);
  387. /**
  388. * qdf_aligned_mem_alloc_consistent() - allocates consistent qdf memory
  389. * @osdev: OS device handle
  390. * @size: Size to be allocated
  391. * @vaddr_unaligned: Unaligned virtual address.
  392. * @paddr_unaligned: Unaligned physical address.
  393. * @paddr_aligned: Aligned physical address.
  394. * @align: Base address alignment.
  395. * @func: Function name of the call site.
  396. * @line: Line number of the call site.
  397. *
  398. * Return: pointer of allocated memory or null if memory alloc fails.
  399. */
  400. #define qdf_aligned_mem_alloc_consistent(osdev, size, vaddr_unaligned, \
  401. paddr_unaligned, paddr_aligned, \
  402. align) \
  403. qdf_aligned_mem_alloc_consistent_fl(osdev, size, vaddr_unaligned, \
  404. paddr_unaligned, paddr_aligned, \
  405. align, __func__, __LINE__)
  406. void *qdf_aligned_mem_alloc_consistent_fl(qdf_device_t osdev, uint32_t *size,
  407. void **vaddr_unaligned,
  408. qdf_dma_addr_t *paddr_unaligned,
  409. qdf_dma_addr_t *paddr_aligned,
  410. uint32_t align, const char *func,
  411. uint32_t line);
  412. #define qdf_mem_virt_to_phys(vaddr) virt_to_phys(vaddr)
  413. void qdf_mem_set_io(void *ptr, uint32_t num_bytes, uint32_t value);
  414. void qdf_mem_copy_toio(void *dst_addr, const void *src_addr,
  415. uint32_t num_bytes);
  416. /**
  417. * qdf_mem_set() - set (fill) memory with a specified byte value.
  418. * @ptr: Pointer to memory that will be set
  419. * @num_bytes: Number of bytes to be set
  420. * @value: Byte set in memory
  421. *
  422. * WARNING: parameter @num_bytes and @value are swapped comparing with
  423. * standard C function "memset", please ensure correct usage of this function!
  424. *
  425. * Return: None
  426. */
  427. void qdf_mem_set(void *ptr, uint32_t num_bytes, uint32_t value);
  428. /**
  429. * qdf_mem_zero() - zero out memory
  430. * @ptr: pointer to memory that will be set to zero
  431. * @num_bytes: number of bytes zero
  432. *
  433. * This function sets the memory location to all zeros, essentially clearing
  434. * the memory.
  435. *
  436. * Return: None
  437. */
  438. static inline void qdf_mem_zero(void *ptr, uint32_t num_bytes)
  439. {
  440. qdf_mem_set(ptr, num_bytes, 0);
  441. }
  442. /**
  443. * qdf_mem_copy() - copy memory
  444. * @dst_addr: Pointer to destination memory location (to copy to)
  445. * @src_addr: Pointer to source memory location (to copy from)
  446. * @num_bytes: Number of bytes to copy.
  447. *
  448. * Copy host memory from one location to another, similar to memcpy in
  449. * standard C. Note this function does not specifically handle overlapping
  450. * source and destination memory locations. Calling this function with
  451. * overlapping source and destination memory locations will result in
  452. * unpredictable results. Use qdf_mem_move() if the memory locations
  453. * for the source and destination are overlapping (or could be overlapping!)
  454. *
  455. * Return: none
  456. */
  457. void qdf_mem_copy(void *dst_addr, const void *src_addr, uint32_t num_bytes);
  458. /**
  459. * qdf_mem_move() - move memory
  460. * @dst_addr: pointer to destination memory location (to move to)
  461. * @src_addr: pointer to source memory location (to move from)
  462. * @num_bytes: number of bytes to move.
  463. *
  464. * Move host memory from one location to another, similar to memmove in
  465. * standard C. Note this function *does* handle overlapping
  466. * source and destination memory locations.
  467. * Return: None
  468. */
  469. void qdf_mem_move(void *dst_addr, const void *src_addr, uint32_t num_bytes);
  470. /**
  471. * qdf_mem_cmp() - memory compare
  472. * @left: pointer to one location in memory to compare
  473. * @right: pointer to second location in memory to compare
  474. * @size: the number of bytes to compare
  475. *
  476. * Function to compare two pieces of memory, similar to memcmp function
  477. * in standard C.
  478. *
  479. * Return:
  480. * 0 -- equal
  481. * < 0 -- *memory1 is less than *memory2
  482. * > 0 -- *memory1 is bigger than *memory2
  483. */
  484. int qdf_mem_cmp(const void *left, const void *right, size_t size);
  485. void qdf_ether_addr_copy(void *dst_addr, const void *src_addr);
  486. /**
  487. * qdf_mem_map_nbytes_single - Map memory for DMA
  488. * @osdev: pomter OS device context
  489. * @buf: pointer to memory to be dma mapped
  490. * @dir: DMA map direction
  491. * @nbytes: number of bytes to be mapped.
  492. * @phy_addr: ponter to recive physical address.
  493. *
  494. * Return: success/failure
  495. */
  496. static inline uint32_t qdf_mem_map_nbytes_single(qdf_device_t osdev, void *buf,
  497. qdf_dma_dir_t dir, int nbytes,
  498. qdf_dma_addr_t *phy_addr)
  499. {
  500. #if defined(HIF_PCI) || defined(HIF_IPCI)
  501. return __qdf_mem_map_nbytes_single(osdev, buf, dir, nbytes, phy_addr);
  502. #else
  503. return 0;
  504. #endif
  505. }
  506. static inline void qdf_mem_dma_cache_sync(qdf_device_t osdev,
  507. qdf_dma_addr_t buf,
  508. qdf_dma_dir_t dir,
  509. int nbytes)
  510. {
  511. __qdf_mem_dma_cache_sync(osdev, buf, dir, nbytes);
  512. }
  513. /**
  514. * qdf_mem_unmap_nbytes_single() - un_map memory for DMA
  515. * @osdev: pomter OS device context
  516. * @phy_addr: physical address of memory to be dma unmapped
  517. * @dir: DMA unmap direction
  518. * @nbytes: number of bytes to be unmapped.
  519. *
  520. * Return: none
  521. */
  522. static inline void qdf_mem_unmap_nbytes_single(qdf_device_t osdev,
  523. qdf_dma_addr_t phy_addr,
  524. qdf_dma_dir_t dir,
  525. int nbytes)
  526. {
  527. #if defined(HIF_PCI) || defined(HIF_IPCI)
  528. __qdf_mem_unmap_nbytes_single(osdev, phy_addr, dir, nbytes);
  529. #endif
  530. }
  531. /**
  532. * qdf_mempool_init - Create and initialize memory pool
  533. * @osdev: platform device object
  534. * @pool_addr: address of the pool created
  535. * @elem_cnt: no. of elements in pool
  536. * @elem_size: size of each pool element in bytes
  537. * @flags: flags
  538. * Return: Handle to memory pool or NULL if allocation failed
  539. */
  540. static inline int qdf_mempool_init(qdf_device_t osdev,
  541. qdf_mempool_t *pool_addr, int elem_cnt,
  542. size_t elem_size, uint32_t flags)
  543. {
  544. return __qdf_mempool_init(osdev, pool_addr, elem_cnt, elem_size,
  545. flags);
  546. }
  547. /**
  548. * qdf_mempool_destroy - Destroy memory pool
  549. * @osdev: platform device object
  550. * @Handle: to memory pool
  551. * Return: none
  552. */
  553. static inline void qdf_mempool_destroy(qdf_device_t osdev, qdf_mempool_t pool)
  554. {
  555. __qdf_mempool_destroy(osdev, pool);
  556. }
  557. /**
  558. * qdf_mempool_alloc - Allocate an element memory pool
  559. * @osdev: platform device object
  560. * @Handle: to memory pool
  561. * Return: Pointer to the allocated element or NULL if the pool is empty
  562. */
  563. static inline void *qdf_mempool_alloc(qdf_device_t osdev, qdf_mempool_t pool)
  564. {
  565. return (void *)__qdf_mempool_alloc(osdev, pool);
  566. }
  567. /**
  568. * qdf_mempool_free - Free a memory pool element
  569. * @osdev: Platform device object
  570. * @pool: Handle to memory pool
  571. * @buf: Element to be freed
  572. * Return: none
  573. */
  574. static inline void qdf_mempool_free(qdf_device_t osdev, qdf_mempool_t pool,
  575. void *buf)
  576. {
  577. __qdf_mempool_free(osdev, pool, buf);
  578. }
  579. /**
  580. * qdf_kmem_cache_create() - OS abstraction for cache creation
  581. *
  582. * @cache_name: Cache name
  583. * @size: Size of the object to be created
  584. *
  585. * Return: Cache address on successful creation, else NULL
  586. */
  587. static inline qdf_kmem_cache_t
  588. qdf_kmem_cache_create(const char *cache_name,
  589. qdf_size_t size)
  590. {
  591. return __qdf_kmem_cache_create(cache_name, size);
  592. }
  593. /**
  594. * qdf_kmem_cache_destroy() - OS abstraction for cache destructin
  595. *
  596. * @cache: Cache pointer
  597. *
  598. * Return: void
  599. */
  600. static inline void qdf_kmem_cache_destroy(qdf_kmem_cache_t cache)
  601. {
  602. __qdf_kmem_cache_destroy(cache);
  603. }
  604. /**
  605. * qdf_kmem_cache_alloc() - Function to allocation object from a cache
  606. *
  607. * @cache: Cache address
  608. *
  609. * Return: Object from cache
  610. *
  611. */
  612. static inline void *qdf_kmem_cache_alloc(qdf_kmem_cache_t cache)
  613. {
  614. return __qdf_kmem_cache_alloc(cache);
  615. }
  616. /**
  617. * qdf_kmem_cache_free() - Function to free cache object
  618. *
  619. * @cache: Cache address
  620. * @object: Object to be returned to cache
  621. *
  622. * Return: void
  623. */
  624. static inline void qdf_kmem_cache_free(qdf_kmem_cache_t cache, void *node)
  625. {
  626. __qdf_kmem_cache_free(cache, node);
  627. }
  628. void qdf_mem_dma_sync_single_for_device(qdf_device_t osdev,
  629. qdf_dma_addr_t bus_addr,
  630. qdf_size_t size,
  631. __dma_data_direction direction);
  632. void qdf_mem_dma_sync_single_for_cpu(qdf_device_t osdev,
  633. qdf_dma_addr_t bus_addr,
  634. qdf_size_t size,
  635. __dma_data_direction direction);
  636. int qdf_mem_multi_page_link(qdf_device_t osdev,
  637. struct qdf_mem_multi_page_t *pages,
  638. uint32_t elem_size, uint32_t elem_count, uint8_t cacheable);
  639. /**
  640. * qdf_mem_kmalloc_inc() - increment kmalloc allocated bytes count
  641. * @size: number of bytes to increment by
  642. *
  643. * Return: None
  644. */
  645. void qdf_mem_kmalloc_inc(qdf_size_t size);
  646. /**
  647. * qdf_mem_kmalloc_dec() - decrement kmalloc allocated bytes count
  648. * @size: number of bytes to decrement by
  649. *
  650. * Return: None
  651. */
  652. void qdf_mem_kmalloc_dec(qdf_size_t size);
  653. #ifdef CONFIG_WLAN_SYSFS_MEM_STATS
  654. /**
  655. * qdf_mem_skb_inc() - increment total skb allocation size
  656. * @size: size to be added
  657. *
  658. * Return: none
  659. */
  660. void qdf_mem_skb_inc(qdf_size_t size);
  661. /**
  662. * qdf_mem_skb_dec() - decrement total skb allocation size
  663. * @size: size to be decremented
  664. *
  665. * Return: none
  666. */
  667. void qdf_mem_skb_dec(qdf_size_t size);
  668. /**
  669. * qdf_mem_skb_total_inc() - increment total skb allocation size
  670. * in host driver in both debug and perf builds
  671. * @size: size to be added
  672. *
  673. * Return: none
  674. */
  675. void qdf_mem_skb_total_inc(qdf_size_t size);
  676. /**
  677. * qdf_mem_skb_total_dec() - decrement total skb allocation size
  678. * in the host driver in debug and perf flavors
  679. * @size: size to be decremented
  680. *
  681. * Return: none
  682. */
  683. void qdf_mem_skb_total_dec(qdf_size_t size);
  684. /**
  685. * qdf_mem_dp_tx_skb_inc() - Increment Tx skb allocation size
  686. * @size: size to be added
  687. *
  688. * Return: none
  689. */
  690. void qdf_mem_dp_tx_skb_inc(qdf_size_t size);
  691. /**
  692. * qdf_mem_dp_tx_skb_dec() - Decrement Tx skb allocation size
  693. * @size: size to be decreased
  694. *
  695. * Return: none
  696. */
  697. void qdf_mem_dp_tx_skb_dec(qdf_size_t size);
  698. /**
  699. * qdf_mem_dp_rx_skb_inc() - Increment Rx skb allocation size
  700. * @size: size to be added
  701. *
  702. * Return: none
  703. */
  704. void qdf_mem_dp_rx_skb_inc(qdf_size_t size);
  705. /**
  706. * qdf_mem_dp_rx_skb_dec() - Decrement Rx skb allocation size
  707. * @size: size to be decreased
  708. *
  709. * Return: none
  710. */
  711. void qdf_mem_dp_rx_skb_dec(qdf_size_t size);
  712. /**
  713. * qdf_mem_dp_tx_skb_cnt_inc() - Increment Tx buffer count
  714. *
  715. * Return: none
  716. */
  717. void qdf_mem_dp_tx_skb_cnt_inc(void);
  718. /**
  719. * qdf_mem_dp_tx_skb_cnt_dec() - Decrement Tx buffer count
  720. *
  721. * Return: none
  722. */
  723. void qdf_mem_dp_tx_skb_cnt_dec(void);
  724. /**
  725. * qdf_mem_dp_rx_skb_cnt_inc() - Increment Rx buffer count
  726. *
  727. * Return: none
  728. */
  729. void qdf_mem_dp_rx_skb_cnt_inc(void);
  730. /**
  731. * qdf_mem_dp_rx_skb_cnt_dec() - Decrement Rx buffer count
  732. *
  733. * Return: none
  734. */
  735. void qdf_mem_dp_rx_skb_cnt_dec(void);
  736. #else
  737. static inline void qdf_mem_skb_inc(qdf_size_t size)
  738. {
  739. }
  740. static inline void qdf_mem_skb_dec(qdf_size_t size)
  741. {
  742. }
  743. static inline void qdf_mem_skb_total_inc(qdf_size_t size)
  744. {
  745. }
  746. static inline void qdf_mem_skb_total_dec(qdf_size_t size)
  747. {
  748. }
  749. static inline void qdf_mem_dp_tx_skb_inc(qdf_size_t size)
  750. {
  751. }
  752. static inline void qdf_mem_dp_tx_skb_dec(qdf_size_t size)
  753. {
  754. }
  755. static inline void qdf_mem_dp_rx_skb_inc(qdf_size_t size)
  756. {
  757. }
  758. static inline void qdf_mem_dp_rx_skb_dec(qdf_size_t size)
  759. {
  760. }
  761. static inline void qdf_mem_dp_tx_skb_cnt_inc(void)
  762. {
  763. }
  764. static inline void qdf_mem_dp_tx_skb_cnt_dec(void)
  765. {
  766. }
  767. static inline void qdf_mem_dp_rx_skb_cnt_inc(void)
  768. {
  769. }
  770. static inline void qdf_mem_dp_rx_skb_cnt_dec(void)
  771. {
  772. }
  773. #endif /* CONFIG_WLAN_SYSFS_MEM_STATS */
  774. /**
  775. * qdf_mem_map_table_alloc() - Allocate shared memory info structure
  776. * @num: number of required storage
  777. *
  778. * Allocate mapping table for DMA memory allocation. This is needed for
  779. * IPA-WLAN buffer sharing when SMMU Stage1 Translation is enabled.
  780. *
  781. * Return: shared memory info storage table pointer
  782. */
  783. static inline qdf_mem_info_t *qdf_mem_map_table_alloc(uint32_t num)
  784. {
  785. qdf_mem_info_t *mem_info_arr;
  786. mem_info_arr = qdf_mem_malloc(num * sizeof(mem_info_arr[0]));
  787. return mem_info_arr;
  788. }
  789. #ifdef ENHANCED_OS_ABSTRACTION
  790. /**
  791. * qdf_update_mem_map_table() - Update DMA memory map info
  792. * @osdev: Parent device instance
  793. * @mem_info: Pointer to shared memory information
  794. * @dma_addr: dma address
  795. * @mem_size: memory size allocated
  796. *
  797. * Store DMA shared memory information
  798. *
  799. * Return: none
  800. */
  801. void qdf_update_mem_map_table(qdf_device_t osdev,
  802. qdf_mem_info_t *mem_info,
  803. qdf_dma_addr_t dma_addr,
  804. uint32_t mem_size);
  805. /**
  806. * qdf_mem_paddr_from_dmaaddr() - get actual physical address from dma address
  807. * @osdev: Parent device instance
  808. * @dma_addr: DMA/IOVA address
  809. *
  810. * Get actual physical address from dma_addr based on SMMU enablement status.
  811. * IF SMMU Stage 1 tranlation is enabled, DMA APIs return IO virtual address
  812. * (IOVA) otherwise returns physical address. So get SMMU physical address
  813. * mapping from IOVA.
  814. *
  815. * Return: dmaable physical address
  816. */
  817. qdf_dma_addr_t qdf_mem_paddr_from_dmaaddr(qdf_device_t osdev,
  818. qdf_dma_addr_t dma_addr);
  819. #else
  820. static inline
  821. void qdf_update_mem_map_table(qdf_device_t osdev,
  822. qdf_mem_info_t *mem_info,
  823. qdf_dma_addr_t dma_addr,
  824. uint32_t mem_size)
  825. {
  826. if (!mem_info) {
  827. qdf_nofl_err("%s: NULL mem_info", __func__);
  828. return;
  829. }
  830. __qdf_update_mem_map_table(osdev, mem_info, dma_addr, mem_size);
  831. }
  832. static inline
  833. qdf_dma_addr_t qdf_mem_paddr_from_dmaaddr(qdf_device_t osdev,
  834. qdf_dma_addr_t dma_addr)
  835. {
  836. return __qdf_mem_paddr_from_dmaaddr(osdev, dma_addr);
  837. }
  838. #endif
  839. /**
  840. * qdf_mem_smmu_s1_enabled() - Return SMMU stage 1 translation enable status
  841. * @osdev parent device instance
  842. *
  843. * Return: true if smmu s1 enabled, false if smmu s1 is bypassed
  844. */
  845. static inline bool qdf_mem_smmu_s1_enabled(qdf_device_t osdev)
  846. {
  847. return __qdf_mem_smmu_s1_enabled(osdev);
  848. }
  849. /**
  850. * qdf_mem_dma_get_sgtable() - Returns DMA memory scatter gather table
  851. * @dev: device instace
  852. * @sgt: scatter gather table pointer
  853. * @cpu_addr: HLOS virtual address
  854. * @dma_addr: dma address
  855. * @size: allocated memory size
  856. *
  857. * Return: physical address
  858. */
  859. static inline int
  860. qdf_mem_dma_get_sgtable(struct device *dev, void *sgt, void *cpu_addr,
  861. qdf_dma_addr_t dma_addr, size_t size)
  862. {
  863. return __qdf_os_mem_dma_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
  864. }
  865. /**
  866. * qdf_mem_free_sgtable() - Free a previously allocated sg table
  867. * @sgt: the mapped sg table header
  868. *
  869. * Return: None
  870. */
  871. static inline void
  872. qdf_mem_free_sgtable(struct sg_table *sgt)
  873. {
  874. __qdf_os_mem_free_sgtable(sgt);
  875. }
  876. /**
  877. * qdf_dma_get_sgtable_dma_addr() - Assigns DMA address to scatterlist elements
  878. * @sgt: scatter gather table pointer
  879. *
  880. * Return: None
  881. */
  882. static inline void
  883. qdf_dma_get_sgtable_dma_addr(struct sg_table *sgt)
  884. {
  885. __qdf_dma_get_sgtable_dma_addr(sgt);
  886. }
  887. /**
  888. * qdf_mem_get_dma_addr() - Return dma address based on SMMU translation status.
  889. * @osdev: Parent device instance
  890. * @mem_info: Pointer to allocated memory information
  891. *
  892. * Get dma address based on SMMU enablement status. If SMMU Stage 1
  893. * tranlation is enabled, DMA APIs return IO virtual address otherwise
  894. * returns physical address.
  895. *
  896. * Return: dma address
  897. */
  898. static inline qdf_dma_addr_t qdf_mem_get_dma_addr(qdf_device_t osdev,
  899. qdf_mem_info_t *mem_info)
  900. {
  901. return __qdf_mem_get_dma_addr(osdev, mem_info);
  902. }
  903. /**
  904. * qdf_mem_get_dma_addr_ptr() - Return DMA address pointer from mem info struct
  905. * @osdev: Parent device instance
  906. * @mem_info: Pointer to allocated memory information
  907. *
  908. * Based on smmu stage 1 translation enablement, return corresponding dma
  909. * address storage pointer.
  910. *
  911. * Return: dma address storage pointer
  912. */
  913. static inline qdf_dma_addr_t *qdf_mem_get_dma_addr_ptr(qdf_device_t osdev,
  914. qdf_mem_info_t *mem_info)
  915. {
  916. return __qdf_mem_get_dma_addr_ptr(osdev, mem_info);
  917. }
  918. /**
  919. * qdf_mem_get_dma_size() - Return DMA memory size
  920. * @osdev: parent device instance
  921. * @mem_info: Pointer to allocated memory information
  922. *
  923. * Return: DMA memory size
  924. */
  925. static inline uint32_t
  926. qdf_mem_get_dma_size(qdf_device_t osdev,
  927. qdf_mem_info_t *mem_info)
  928. {
  929. return __qdf_mem_get_dma_size(osdev, mem_info);
  930. }
  931. /**
  932. * qdf_mem_set_dma_size() - Set DMA memory size
  933. * @osdev: parent device instance
  934. * @mem_info: Pointer to allocated memory information
  935. * @mem_size: memory size allocated
  936. *
  937. * Return: none
  938. */
  939. static inline void
  940. qdf_mem_set_dma_size(qdf_device_t osdev,
  941. qdf_mem_info_t *mem_info,
  942. uint32_t mem_size)
  943. {
  944. __qdf_mem_set_dma_size(osdev, mem_info, mem_size);
  945. }
  946. /**
  947. * qdf_mem_get_dma_size() - Return DMA physical address
  948. * @osdev: parent device instance
  949. * @mem_info: Pointer to allocated memory information
  950. *
  951. * Return: DMA physical address
  952. */
  953. static inline qdf_dma_addr_t
  954. qdf_mem_get_dma_pa(qdf_device_t osdev,
  955. qdf_mem_info_t *mem_info)
  956. {
  957. return __qdf_mem_get_dma_pa(osdev, mem_info);
  958. }
  959. /**
  960. * qdf_mem_set_dma_size() - Set DMA physical address
  961. * @osdev: parent device instance
  962. * @mem_info: Pointer to allocated memory information
  963. * @dma_pa: DMA phsical address
  964. *
  965. * Return: none
  966. */
  967. static inline void
  968. qdf_mem_set_dma_pa(qdf_device_t osdev,
  969. qdf_mem_info_t *mem_info,
  970. qdf_dma_addr_t dma_pa)
  971. {
  972. __qdf_mem_set_dma_pa(osdev, mem_info, dma_pa);
  973. }
  974. /**
  975. * qdf_mem_shared_mem_alloc() - Allocate DMA memory for shared resource
  976. * @osdev: parent device instance
  977. * @mem_info: Pointer to allocated memory information
  978. * @size: size to be allocated
  979. *
  980. * Allocate DMA memory which will be shared with external kernel module. This
  981. * information is needed for SMMU mapping.
  982. *
  983. * Return: 0 success
  984. */
  985. qdf_shared_mem_t *qdf_mem_shared_mem_alloc(qdf_device_t osdev, uint32_t size);
  986. #ifdef DP_UMAC_HW_RESET_SUPPORT
  987. /**
  988. * qdf_tx_desc_pool_free_bufs() - Go through elems and call the registered cb
  989. * @ctxt: Context to be passed to the cb
  990. * @pages: Multi page information storage
  991. * @elem_size: Each element size
  992. * @elem_count: Total number of elements should be allocated
  993. * @cacheable: Coherent memory or cacheable memory
  994. * @cb: Callback to free the elements
  995. * @elem_list: elem list for delayed free
  996. *
  997. * Return: 0 on Succscc, or Error code
  998. */
  999. int qdf_tx_desc_pool_free_bufs(void *ctxt, struct qdf_mem_multi_page_t *pages,
  1000. uint32_t elem_size, uint32_t elem_count,
  1001. uint8_t cacheable, qdf_mem_release_cb cb,
  1002. void *elem_list);
  1003. #endif
  1004. /**
  1005. * qdf_mem_shared_mem_free() - Free shared memory
  1006. * @osdev: parent device instance
  1007. * @shared_mem: shared memory information storage
  1008. *
  1009. * Free DMA shared memory resource
  1010. *
  1011. * Return: None
  1012. */
  1013. static inline void qdf_mem_shared_mem_free(qdf_device_t osdev,
  1014. qdf_shared_mem_t *shared_mem)
  1015. {
  1016. if (!shared_mem) {
  1017. qdf_nofl_err("%s: NULL shared mem struct passed",
  1018. __func__);
  1019. return;
  1020. }
  1021. if (shared_mem->vaddr) {
  1022. qdf_mem_free_consistent(osdev, osdev->dev,
  1023. qdf_mem_get_dma_size(osdev,
  1024. &shared_mem->mem_info),
  1025. shared_mem->vaddr,
  1026. qdf_mem_get_dma_addr(osdev,
  1027. &shared_mem->mem_info),
  1028. qdf_get_dma_mem_context(shared_mem,
  1029. memctx));
  1030. }
  1031. qdf_mem_free_sgtable(&shared_mem->sgtable);
  1032. qdf_mem_free(shared_mem);
  1033. }
  1034. /**
  1035. * qdf_dma_mem_stats_read() - Return the DMA memory allocated in
  1036. * host driver
  1037. *
  1038. * Return: Total DMA memory allocated
  1039. */
  1040. int32_t qdf_dma_mem_stats_read(void);
  1041. /**
  1042. * qdf_heap_mem_stats_read() - Return the heap memory allocated
  1043. * in host driver
  1044. *
  1045. * Return: Total heap memory allocated
  1046. */
  1047. int32_t qdf_heap_mem_stats_read(void);
  1048. /**
  1049. * qdf_skb_mem_stats_read() - Return the SKB memory allocated in
  1050. * host driver
  1051. *
  1052. * Return: Total SKB memory allocated
  1053. */
  1054. int32_t qdf_skb_mem_stats_read(void);
  1055. /**
  1056. * qdf_skb_total_mem_stats_read() - Return the SKB memory allocated
  1057. * in the host driver tracked in both debug and perf builds
  1058. *
  1059. * Return: Total SKB memory allocated
  1060. */
  1061. int32_t qdf_skb_total_mem_stats_read(void);
  1062. /**
  1063. * qdf_skb_max_mem_stats_read() - Return the max SKB memory
  1064. * allocated in host driver. This is the high watermark for the
  1065. * total SKB allocated in the host driver
  1066. *
  1067. * Return: None
  1068. */
  1069. int32_t qdf_skb_max_mem_stats_read(void);
  1070. /**
  1071. * qdf_mem_tx_desc_cnt_read() - Return the outstanding Tx descs
  1072. * which are waiting on Tx completions
  1073. *
  1074. * Return: Outstanding Tx desc count
  1075. */
  1076. int32_t qdf_mem_tx_desc_cnt_read(void);
  1077. /**
  1078. * qdf_mem_tx_desc_max_read() - Return the max outstanding Tx
  1079. * descs which are waiting on Tx completions. This is the high
  1080. * watermark for the pending desc count
  1081. *
  1082. * Return: Max outstanding Tx desc count
  1083. */
  1084. int32_t qdf_mem_tx_desc_max_read(void);
  1085. /**
  1086. * qdf_mem_stats_init() - Initialize the qdf memstats fields on
  1087. * creating the sysfs node
  1088. *
  1089. * Return: None
  1090. */
  1091. void qdf_mem_stats_init(void);
  1092. /**
  1093. * qdf_dp_tx_skb_mem_stats_read() - Return the SKB memory
  1094. * allocated for Tx data path
  1095. *
  1096. * Return: Tx SKB memory allocated
  1097. */
  1098. int32_t qdf_dp_tx_skb_mem_stats_read(void);
  1099. /**
  1100. * qdf_dp_rx_skb_mem_stats_read() - Return the SKB memory
  1101. * allocated for Rx data path
  1102. *
  1103. * Return: Rx SKB memory allocated
  1104. */
  1105. int32_t qdf_dp_rx_skb_mem_stats_read(void);
  1106. /**
  1107. * qdf_dp_tx_skb_max_mem_stats_read() - Return the high
  1108. * watermark for the SKB memory allocated for Tx data path
  1109. *
  1110. * Return: Max Tx SKB memory allocated
  1111. */
  1112. int32_t qdf_dp_tx_skb_max_mem_stats_read(void);
  1113. /**
  1114. * qdf_dp_rx_skb_max_mem_stats_read() - Return the high
  1115. * watermark for the SKB memory allocated for Rx data path
  1116. *
  1117. * Return: Max Rx SKB memory allocated
  1118. */
  1119. int32_t qdf_dp_rx_skb_max_mem_stats_read(void);
  1120. /**
  1121. * qdf_mem_dp_tx_skb_cnt_read() - Return number of buffers
  1122. * allocated in the Tx data path by the host driver or
  1123. * buffers coming from the n/w stack
  1124. *
  1125. * Return: Number of DP Tx buffers allocated
  1126. */
  1127. int32_t qdf_mem_dp_tx_skb_cnt_read(void);
  1128. /**
  1129. * qdf_mem_dp_tx_skb_max_cnt_read() - Return max number of
  1130. * buffers allocated in the Tx data path
  1131. *
  1132. * Return: Max number of DP Tx buffers allocated
  1133. */
  1134. int32_t qdf_mem_dp_tx_skb_max_cnt_read(void);
  1135. /**
  1136. * qdf_mem_dp_rx_skb_cnt_read() - Return number of buffers
  1137. * allocated in the Rx data path
  1138. *
  1139. * Return: Number of DP Rx buffers allocated
  1140. */
  1141. int32_t qdf_mem_dp_rx_skb_cnt_read(void);
  1142. /**
  1143. * qdf_mem_dp_rx_skb_max_cnt_read() - Return max number of
  1144. * buffers allocated in the Rx data path
  1145. *
  1146. * Return: Max number of DP Rx buffers allocated
  1147. */
  1148. int32_t qdf_mem_dp_rx_skb_max_cnt_read(void);
  1149. /**
  1150. * qdf_mem_tx_desc_cnt_update() - Update the pending tx desc
  1151. * count and the high watermark for pending tx desc count
  1152. *
  1153. * @pending_tx_descs: outstanding Tx desc count
  1154. * @tx_descs_max: high watermark for outstanding Tx desc count
  1155. *
  1156. * Return: None
  1157. */
  1158. void qdf_mem_tx_desc_cnt_update(qdf_atomic_t pending_tx_descs,
  1159. int32_t tx_descs_max);
  1160. /**
  1161. * qdf_mem_vfree() - Free the virtual memory pointed to by ptr
  1162. * @ptr: Pointer to the starting address of the memory to
  1163. * be freed.
  1164. *
  1165. * Return: None
  1166. */
  1167. #define qdf_mem_vfree(ptr) __qdf_mem_vfree(ptr)
  1168. /**
  1169. * qdf_mem_valloc() - Allocate virtual memory for the given
  1170. * size
  1171. * @size: Number of bytes of memory to be allocated
  1172. *
  1173. * Return: Pointer to the starting address of the allocated virtual memory
  1174. */
  1175. #define qdf_mem_valloc(size) __qdf_mem_valloc(size, __func__, __LINE__)
  1176. #if IS_ENABLED(CONFIG_ARM_SMMU) && defined(ENABLE_SMMU_S1_TRANSLATION)
  1177. /*
  1178. * typedef qdf_iommu_domain_t: Platform indepedent iommu domain
  1179. * abstraction
  1180. */
  1181. typedef __qdf_iommu_domain_t qdf_iommu_domain_t;
  1182. /**
  1183. * qdf_iommu_domain_get_attr() - API to get iommu domain attributes
  1184. * @domain: iommu domain
  1185. * @attr: iommu attribute
  1186. * @data: data pointer
  1187. *
  1188. * Return: 0 on success, else errno
  1189. */
  1190. int
  1191. qdf_iommu_domain_get_attr(qdf_iommu_domain_t *domain,
  1192. enum qdf_iommu_attr attr, void *data);
  1193. #endif
  1194. #endif /* __QDF_MEMORY_H */