qdf_mem.h 42 KB

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