qdf_mem.h 41 KB

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