qdf_mem.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  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. * @cache_name: Cache name
  672. * @size: Size of the object to be created
  673. *
  674. * Return: Cache address on successful creation, else NULL
  675. */
  676. static inline qdf_kmem_cache_t
  677. qdf_kmem_cache_create(const char *cache_name,
  678. qdf_size_t size)
  679. {
  680. return __qdf_kmem_cache_create(cache_name, size);
  681. }
  682. /**
  683. * qdf_kmem_cache_destroy() - OS abstraction for cache destruction
  684. * @cache: Cache pointer
  685. *
  686. * Return: void
  687. */
  688. static inline void qdf_kmem_cache_destroy(qdf_kmem_cache_t cache)
  689. {
  690. __qdf_kmem_cache_destroy(cache);
  691. }
  692. /**
  693. * qdf_kmem_cache_alloc() - Function to allocation object from a cache
  694. * @cache: Cache address
  695. *
  696. * Return: Object from cache
  697. *
  698. */
  699. static inline void *qdf_kmem_cache_alloc(qdf_kmem_cache_t cache)
  700. {
  701. return __qdf_kmem_cache_alloc(cache);
  702. }
  703. /**
  704. * qdf_kmem_cache_free() - Function to free cache object
  705. * @cache: Cache address
  706. * @node: Object to be returned to cache
  707. *
  708. * Return: void
  709. */
  710. static inline void qdf_kmem_cache_free(qdf_kmem_cache_t cache, void *node)
  711. {
  712. __qdf_kmem_cache_free(cache, node);
  713. }
  714. /**
  715. * qdf_mem_dma_sync_single_for_device() - assign memory to device
  716. * @osdev: OS device handle
  717. * @bus_addr: dma address to give to the device
  718. * @size: Size of the memory block
  719. * @direction: direction data will be DMAed
  720. *
  721. * Assign memory to the remote device.
  722. * The cache lines are flushed to ram or invalidated as needed.
  723. *
  724. * Return: none
  725. */
  726. void qdf_mem_dma_sync_single_for_device(qdf_device_t osdev,
  727. qdf_dma_addr_t bus_addr,
  728. qdf_size_t size,
  729. __dma_data_direction direction);
  730. /**
  731. * qdf_mem_dma_sync_single_for_cpu() - assign memory to CPU
  732. * @osdev: OS device handle
  733. * @bus_addr: dma address to give to the cpu
  734. * @size: Size of the memory block
  735. * @direction: direction data will be DMAed
  736. *
  737. * Assign memory to the CPU.
  738. *
  739. * Return: none
  740. */
  741. void qdf_mem_dma_sync_single_for_cpu(qdf_device_t osdev,
  742. qdf_dma_addr_t bus_addr,
  743. qdf_size_t size,
  744. __dma_data_direction direction);
  745. /**
  746. * qdf_mem_multi_page_link() - Make links for multi page elements
  747. * @osdev: OS device handle pointer
  748. * @pages: Multi page information storage
  749. * @elem_size: Single element size
  750. * @elem_count: elements count should be linked
  751. * @cacheable: Coherent memory or cacheable memory
  752. *
  753. * This function will make links for multi page allocated structure
  754. *
  755. * Return: 0 success
  756. */
  757. int qdf_mem_multi_page_link(qdf_device_t osdev,
  758. struct qdf_mem_multi_page_t *pages,
  759. uint32_t elem_size, uint32_t elem_count,
  760. uint8_t cacheable);
  761. /**
  762. * qdf_mem_kmalloc_inc() - increment kmalloc allocated bytes count
  763. * @size: number of bytes to increment by
  764. *
  765. * Return: None
  766. */
  767. void qdf_mem_kmalloc_inc(qdf_size_t size);
  768. /**
  769. * qdf_mem_kmalloc_dec() - decrement kmalloc allocated bytes count
  770. * @size: number of bytes to decrement by
  771. *
  772. * Return: None
  773. */
  774. void qdf_mem_kmalloc_dec(qdf_size_t size);
  775. #ifdef CONFIG_WLAN_SYSFS_MEM_STATS
  776. /**
  777. * qdf_mem_skb_inc() - increment total skb allocation size
  778. * @size: size to be added
  779. *
  780. * Return: none
  781. */
  782. void qdf_mem_skb_inc(qdf_size_t size);
  783. /**
  784. * qdf_mem_skb_dec() - decrement total skb allocation size
  785. * @size: size to be decremented
  786. *
  787. * Return: none
  788. */
  789. void qdf_mem_skb_dec(qdf_size_t size);
  790. /**
  791. * qdf_mem_skb_total_inc() - increment total skb allocation size
  792. * in host driver in both debug and perf builds
  793. * @size: size to be added
  794. *
  795. * Return: none
  796. */
  797. void qdf_mem_skb_total_inc(qdf_size_t size);
  798. /**
  799. * qdf_mem_skb_total_dec() - decrement total skb allocation size
  800. * in the host driver in debug and perf flavors
  801. * @size: size to be decremented
  802. *
  803. * Return: none
  804. */
  805. void qdf_mem_skb_total_dec(qdf_size_t size);
  806. /**
  807. * qdf_mem_dp_tx_skb_inc() - Increment Tx skb allocation size
  808. * @size: size to be added
  809. *
  810. * Return: none
  811. */
  812. void qdf_mem_dp_tx_skb_inc(qdf_size_t size);
  813. /**
  814. * qdf_mem_dp_tx_skb_dec() - Decrement Tx skb allocation size
  815. * @size: size to be decreased
  816. *
  817. * Return: none
  818. */
  819. void qdf_mem_dp_tx_skb_dec(qdf_size_t size);
  820. /**
  821. * qdf_mem_dp_rx_skb_inc() - Increment Rx skb allocation size
  822. * @size: size to be added
  823. *
  824. * Return: none
  825. */
  826. void qdf_mem_dp_rx_skb_inc(qdf_size_t size);
  827. /**
  828. * qdf_mem_dp_rx_skb_dec() - Decrement Rx skb allocation size
  829. * @size: size to be decreased
  830. *
  831. * Return: none
  832. */
  833. void qdf_mem_dp_rx_skb_dec(qdf_size_t size);
  834. /**
  835. * qdf_mem_dp_tx_skb_cnt_inc() - Increment Tx buffer count
  836. *
  837. * Return: none
  838. */
  839. void qdf_mem_dp_tx_skb_cnt_inc(void);
  840. /**
  841. * qdf_mem_dp_tx_skb_cnt_dec() - Decrement Tx buffer count
  842. *
  843. * Return: none
  844. */
  845. void qdf_mem_dp_tx_skb_cnt_dec(void);
  846. /**
  847. * qdf_mem_dp_rx_skb_cnt_inc() - Increment Rx buffer count
  848. *
  849. * Return: none
  850. */
  851. void qdf_mem_dp_rx_skb_cnt_inc(void);
  852. /**
  853. * qdf_mem_dp_rx_skb_cnt_dec() - Decrement Rx buffer count
  854. *
  855. * Return: none
  856. */
  857. void qdf_mem_dp_rx_skb_cnt_dec(void);
  858. #else
  859. static inline void qdf_mem_skb_inc(qdf_size_t size)
  860. {
  861. }
  862. static inline void qdf_mem_skb_dec(qdf_size_t size)
  863. {
  864. }
  865. static inline void qdf_mem_skb_total_inc(qdf_size_t size)
  866. {
  867. }
  868. static inline void qdf_mem_skb_total_dec(qdf_size_t size)
  869. {
  870. }
  871. static inline void qdf_mem_dp_tx_skb_inc(qdf_size_t size)
  872. {
  873. }
  874. static inline void qdf_mem_dp_tx_skb_dec(qdf_size_t size)
  875. {
  876. }
  877. static inline void qdf_mem_dp_rx_skb_inc(qdf_size_t size)
  878. {
  879. }
  880. static inline void qdf_mem_dp_rx_skb_dec(qdf_size_t size)
  881. {
  882. }
  883. static inline void qdf_mem_dp_tx_skb_cnt_inc(void)
  884. {
  885. }
  886. static inline void qdf_mem_dp_tx_skb_cnt_dec(void)
  887. {
  888. }
  889. static inline void qdf_mem_dp_rx_skb_cnt_inc(void)
  890. {
  891. }
  892. static inline void qdf_mem_dp_rx_skb_cnt_dec(void)
  893. {
  894. }
  895. #endif /* CONFIG_WLAN_SYSFS_MEM_STATS */
  896. /**
  897. * qdf_mem_map_table_alloc() - Allocate shared memory info structure
  898. * @num: number of required storage
  899. *
  900. * Allocate mapping table for DMA memory allocation. This is needed for
  901. * IPA-WLAN buffer sharing when SMMU Stage1 Translation is enabled.
  902. *
  903. * Return: shared memory info storage table pointer
  904. */
  905. static inline qdf_mem_info_t *qdf_mem_map_table_alloc(uint32_t num)
  906. {
  907. qdf_mem_info_t *mem_info_arr;
  908. mem_info_arr = qdf_mem_malloc(num * sizeof(mem_info_arr[0]));
  909. return mem_info_arr;
  910. }
  911. #ifdef ENHANCED_OS_ABSTRACTION
  912. /**
  913. * qdf_update_mem_map_table() - Update DMA memory map info
  914. * @osdev: Parent device instance
  915. * @mem_info: Pointer to shared memory information
  916. * @dma_addr: dma address
  917. * @mem_size: memory size allocated
  918. *
  919. * Store DMA shared memory information
  920. *
  921. * Return: none
  922. */
  923. void qdf_update_mem_map_table(qdf_device_t osdev,
  924. qdf_mem_info_t *mem_info,
  925. qdf_dma_addr_t dma_addr,
  926. uint32_t mem_size);
  927. /**
  928. * qdf_mem_paddr_from_dmaaddr() - get actual physical address from dma address
  929. * @osdev: Parent device instance
  930. * @dma_addr: DMA/IOVA address
  931. *
  932. * Get actual physical address from dma_addr based on SMMU enablement status.
  933. * IF SMMU Stage 1 translation is enabled, DMA APIs return IO virtual address
  934. * (IOVA) otherwise returns physical address. So get SMMU physical address
  935. * mapping from IOVA.
  936. *
  937. * Return: dmaable physical address
  938. */
  939. qdf_dma_addr_t qdf_mem_paddr_from_dmaaddr(qdf_device_t osdev,
  940. qdf_dma_addr_t dma_addr);
  941. #else
  942. static inline
  943. void qdf_update_mem_map_table(qdf_device_t osdev,
  944. qdf_mem_info_t *mem_info,
  945. qdf_dma_addr_t dma_addr,
  946. uint32_t mem_size)
  947. {
  948. if (!mem_info) {
  949. qdf_nofl_err("%s: NULL mem_info", __func__);
  950. return;
  951. }
  952. __qdf_update_mem_map_table(osdev, mem_info, dma_addr, mem_size);
  953. }
  954. static inline
  955. qdf_dma_addr_t qdf_mem_paddr_from_dmaaddr(qdf_device_t osdev,
  956. qdf_dma_addr_t dma_addr)
  957. {
  958. return __qdf_mem_paddr_from_dmaaddr(osdev, dma_addr);
  959. }
  960. #endif
  961. /**
  962. * qdf_mem_smmu_s1_enabled() - Return SMMU stage 1 translation enable status
  963. * @osdev: parent device instance
  964. *
  965. * Return: true if smmu s1 enabled, false if smmu s1 is bypassed
  966. */
  967. static inline bool qdf_mem_smmu_s1_enabled(qdf_device_t osdev)
  968. {
  969. return __qdf_mem_smmu_s1_enabled(osdev);
  970. }
  971. /**
  972. * qdf_mem_dma_get_sgtable() - Returns DMA memory scatter gather table
  973. * @dev: device instance
  974. * @sgt: scatter gather table pointer
  975. * @cpu_addr: HLOS virtual address
  976. * @dma_addr: dma address
  977. * @size: allocated memory size
  978. *
  979. * Return: physical address
  980. */
  981. static inline int
  982. qdf_mem_dma_get_sgtable(struct device *dev, void *sgt, void *cpu_addr,
  983. qdf_dma_addr_t dma_addr, size_t size)
  984. {
  985. return __qdf_os_mem_dma_get_sgtable(dev, sgt, cpu_addr, dma_addr, size);
  986. }
  987. /**
  988. * qdf_mem_free_sgtable() - Free a previously allocated sg table
  989. * @sgt: the mapped sg table header
  990. *
  991. * Return: None
  992. */
  993. static inline void
  994. qdf_mem_free_sgtable(struct sg_table *sgt)
  995. {
  996. __qdf_os_mem_free_sgtable(sgt);
  997. }
  998. /**
  999. * qdf_dma_get_sgtable_dma_addr() - Assigns DMA address to scatterlist elements
  1000. * @sgt: scatter gather table pointer
  1001. *
  1002. * Return: None
  1003. */
  1004. static inline void
  1005. qdf_dma_get_sgtable_dma_addr(struct sg_table *sgt)
  1006. {
  1007. __qdf_dma_get_sgtable_dma_addr(sgt);
  1008. }
  1009. /**
  1010. * qdf_mem_get_dma_addr() - Return dma address based on SMMU translation status.
  1011. * @osdev: Parent device instance
  1012. * @mem_info: Pointer to allocated memory information
  1013. *
  1014. * Get dma address based on SMMU enablement status. If SMMU Stage 1
  1015. * translation is enabled, DMA APIs return IO virtual address otherwise
  1016. * returns physical address.
  1017. *
  1018. * Return: dma address
  1019. */
  1020. static inline qdf_dma_addr_t qdf_mem_get_dma_addr(qdf_device_t osdev,
  1021. qdf_mem_info_t *mem_info)
  1022. {
  1023. return __qdf_mem_get_dma_addr(osdev, mem_info);
  1024. }
  1025. /**
  1026. * qdf_mem_get_dma_addr_ptr() - Return DMA address pointer from mem info struct
  1027. * @osdev: Parent device instance
  1028. * @mem_info: Pointer to allocated memory information
  1029. *
  1030. * Based on smmu stage 1 translation enablement, return corresponding dma
  1031. * address storage pointer.
  1032. *
  1033. * Return: dma address storage pointer
  1034. */
  1035. static inline qdf_dma_addr_t *qdf_mem_get_dma_addr_ptr(qdf_device_t osdev,
  1036. qdf_mem_info_t *mem_info)
  1037. {
  1038. return __qdf_mem_get_dma_addr_ptr(osdev, mem_info);
  1039. }
  1040. /**
  1041. * qdf_mem_get_dma_size() - Return DMA memory size
  1042. * @osdev: parent device instance
  1043. * @mem_info: Pointer to allocated memory information
  1044. *
  1045. * Return: DMA memory size
  1046. */
  1047. static inline uint32_t
  1048. qdf_mem_get_dma_size(qdf_device_t osdev,
  1049. qdf_mem_info_t *mem_info)
  1050. {
  1051. return __qdf_mem_get_dma_size(osdev, mem_info);
  1052. }
  1053. /**
  1054. * qdf_mem_set_dma_size() - Set DMA memory size
  1055. * @osdev: parent device instance
  1056. * @mem_info: Pointer to allocated memory information
  1057. * @mem_size: memory size allocated
  1058. *
  1059. * Return: none
  1060. */
  1061. static inline void
  1062. qdf_mem_set_dma_size(qdf_device_t osdev,
  1063. qdf_mem_info_t *mem_info,
  1064. uint32_t mem_size)
  1065. {
  1066. __qdf_mem_set_dma_size(osdev, mem_info, mem_size);
  1067. }
  1068. /**
  1069. * qdf_mem_get_dma_pa() - Return DMA physical address
  1070. * @osdev: parent device instance
  1071. * @mem_info: Pointer to allocated memory information
  1072. *
  1073. * Return: DMA physical address
  1074. */
  1075. static inline qdf_dma_addr_t
  1076. qdf_mem_get_dma_pa(qdf_device_t osdev,
  1077. qdf_mem_info_t *mem_info)
  1078. {
  1079. return __qdf_mem_get_dma_pa(osdev, mem_info);
  1080. }
  1081. /**
  1082. * qdf_mem_set_dma_pa() - Set DMA physical address
  1083. * @osdev: parent device instance
  1084. * @mem_info: Pointer to allocated memory information
  1085. * @dma_pa: DMA phsical address
  1086. *
  1087. * Return: none
  1088. */
  1089. static inline void
  1090. qdf_mem_set_dma_pa(qdf_device_t osdev,
  1091. qdf_mem_info_t *mem_info,
  1092. qdf_dma_addr_t dma_pa)
  1093. {
  1094. __qdf_mem_set_dma_pa(osdev, mem_info, dma_pa);
  1095. }
  1096. /**
  1097. * qdf_mem_shared_mem_alloc() - Allocate DMA memory for shared resource
  1098. * @osdev: parent device instance
  1099. * @size: size to be allocated
  1100. *
  1101. * Allocate DMA memory which will be shared with external kernel module. This
  1102. * information is needed for SMMU mapping.
  1103. *
  1104. * Return: Pointer to allocated DMA memory on success, NULL on failure
  1105. */
  1106. qdf_shared_mem_t *qdf_mem_shared_mem_alloc(qdf_device_t osdev, uint32_t size);
  1107. #ifdef DP_UMAC_HW_RESET_SUPPORT
  1108. /**
  1109. * qdf_tx_desc_pool_free_bufs() - Go through elems and call the registered cb
  1110. * @ctxt: Context to be passed to the cb
  1111. * @pages: Multi page information storage
  1112. * @elem_size: Each element size
  1113. * @elem_count: Total number of elements in the pool.
  1114. * @cacheable: Coherent memory or cacheable memory
  1115. * @cb: Callback to free the elements
  1116. * @elem_list: elem list for delayed free
  1117. *
  1118. * Return: 0 on Succscc, or Error code
  1119. */
  1120. int qdf_tx_desc_pool_free_bufs(void *ctxt, struct qdf_mem_multi_page_t *pages,
  1121. uint32_t elem_size, uint32_t elem_count,
  1122. uint8_t cacheable, qdf_mem_release_cb cb,
  1123. void *elem_list);
  1124. #endif
  1125. /**
  1126. * qdf_mem_shared_mem_free() - Free shared memory
  1127. * @osdev: parent device instance
  1128. * @shared_mem: shared memory information storage
  1129. *
  1130. * Free DMA shared memory resource
  1131. *
  1132. * Return: None
  1133. */
  1134. static inline void qdf_mem_shared_mem_free(qdf_device_t osdev,
  1135. qdf_shared_mem_t *shared_mem)
  1136. {
  1137. if (!shared_mem) {
  1138. qdf_nofl_err("%s: NULL shared mem struct passed",
  1139. __func__);
  1140. return;
  1141. }
  1142. if (shared_mem->vaddr) {
  1143. qdf_mem_free_consistent(osdev, osdev->dev,
  1144. qdf_mem_get_dma_size(osdev,
  1145. &shared_mem->mem_info),
  1146. shared_mem->vaddr,
  1147. qdf_mem_get_dma_addr(osdev,
  1148. &shared_mem->mem_info),
  1149. qdf_get_dma_mem_context(shared_mem,
  1150. memctx));
  1151. }
  1152. qdf_mem_free_sgtable(&shared_mem->sgtable);
  1153. qdf_mem_free(shared_mem);
  1154. }
  1155. /**
  1156. * qdf_dma_mem_stats_read() - Return the DMA memory allocated in
  1157. * host driver
  1158. *
  1159. * Return: Total DMA memory allocated
  1160. */
  1161. int32_t qdf_dma_mem_stats_read(void);
  1162. /**
  1163. * qdf_heap_mem_stats_read() - Return the heap memory allocated
  1164. * in host driver
  1165. *
  1166. * Return: Total heap memory allocated
  1167. */
  1168. int32_t qdf_heap_mem_stats_read(void);
  1169. /**
  1170. * qdf_skb_mem_stats_read() - Return the SKB memory allocated in
  1171. * host driver
  1172. *
  1173. * Return: Total SKB memory allocated
  1174. */
  1175. int32_t qdf_skb_mem_stats_read(void);
  1176. /**
  1177. * qdf_skb_total_mem_stats_read() - Return the SKB memory allocated
  1178. * in the host driver tracked in both debug and perf builds
  1179. *
  1180. * Return: Total SKB memory allocated
  1181. */
  1182. int32_t qdf_skb_total_mem_stats_read(void);
  1183. /**
  1184. * qdf_skb_max_mem_stats_read() - Return the max SKB memory
  1185. * allocated in host driver. This is the high watermark for the
  1186. * total SKB allocated in the host driver
  1187. *
  1188. * Return: None
  1189. */
  1190. int32_t qdf_skb_max_mem_stats_read(void);
  1191. /**
  1192. * qdf_mem_tx_desc_cnt_read() - Return the outstanding Tx descs
  1193. * which are waiting on Tx completions
  1194. *
  1195. * Return: Outstanding Tx desc count
  1196. */
  1197. int32_t qdf_mem_tx_desc_cnt_read(void);
  1198. /**
  1199. * qdf_mem_tx_desc_max_read() - Return the max outstanding Tx
  1200. * descs which are waiting on Tx completions. This is the high
  1201. * watermark for the pending desc count
  1202. *
  1203. * Return: Max outstanding Tx desc count
  1204. */
  1205. int32_t qdf_mem_tx_desc_max_read(void);
  1206. /**
  1207. * qdf_mem_stats_init() - Initialize the qdf memstats fields on
  1208. * creating the sysfs node
  1209. *
  1210. * Return: None
  1211. */
  1212. void qdf_mem_stats_init(void);
  1213. /**
  1214. * qdf_dp_tx_skb_mem_stats_read() - Return the SKB memory
  1215. * allocated for Tx data path
  1216. *
  1217. * Return: Tx SKB memory allocated
  1218. */
  1219. int32_t qdf_dp_tx_skb_mem_stats_read(void);
  1220. /**
  1221. * qdf_dp_rx_skb_mem_stats_read() - Return the SKB memory
  1222. * allocated for Rx data path
  1223. *
  1224. * Return: Rx SKB memory allocated
  1225. */
  1226. int32_t qdf_dp_rx_skb_mem_stats_read(void);
  1227. /**
  1228. * qdf_dp_tx_skb_max_mem_stats_read() - Return the high
  1229. * watermark for the SKB memory allocated for Tx data path
  1230. *
  1231. * Return: Max Tx SKB memory allocated
  1232. */
  1233. int32_t qdf_dp_tx_skb_max_mem_stats_read(void);
  1234. /**
  1235. * qdf_dp_rx_skb_max_mem_stats_read() - Return the high
  1236. * watermark for the SKB memory allocated for Rx data path
  1237. *
  1238. * Return: Max Rx SKB memory allocated
  1239. */
  1240. int32_t qdf_dp_rx_skb_max_mem_stats_read(void);
  1241. /**
  1242. * qdf_mem_dp_tx_skb_cnt_read() - Return number of buffers
  1243. * allocated in the Tx data path by the host driver or
  1244. * buffers coming from the n/w stack
  1245. *
  1246. * Return: Number of DP Tx buffers allocated
  1247. */
  1248. int32_t qdf_mem_dp_tx_skb_cnt_read(void);
  1249. /**
  1250. * qdf_mem_dp_tx_skb_max_cnt_read() - Return max number of
  1251. * buffers allocated in the Tx data path
  1252. *
  1253. * Return: Max number of DP Tx buffers allocated
  1254. */
  1255. int32_t qdf_mem_dp_tx_skb_max_cnt_read(void);
  1256. /**
  1257. * qdf_mem_dp_rx_skb_cnt_read() - Return number of buffers
  1258. * allocated in the Rx data path
  1259. *
  1260. * Return: Number of DP Rx buffers allocated
  1261. */
  1262. int32_t qdf_mem_dp_rx_skb_cnt_read(void);
  1263. /**
  1264. * qdf_mem_dp_rx_skb_max_cnt_read() - Return max number of
  1265. * buffers allocated in the Rx data path
  1266. *
  1267. * Return: Max number of DP Rx buffers allocated
  1268. */
  1269. int32_t qdf_mem_dp_rx_skb_max_cnt_read(void);
  1270. /**
  1271. * qdf_mem_tx_desc_cnt_update() - Update the pending tx desc
  1272. * count and the high watermark for pending tx desc count
  1273. *
  1274. * @pending_tx_descs: outstanding Tx desc count
  1275. * @tx_descs_max: high watermark for outstanding Tx desc count
  1276. *
  1277. * Return: None
  1278. */
  1279. void qdf_mem_tx_desc_cnt_update(qdf_atomic_t pending_tx_descs,
  1280. int32_t tx_descs_max);
  1281. /**
  1282. * qdf_mem_vfree() - Free the virtual memory pointed to by ptr
  1283. * @ptr: Pointer to the starting address of the memory to
  1284. * be freed.
  1285. *
  1286. * Return: None
  1287. */
  1288. #define qdf_mem_vfree(ptr) __qdf_mem_vfree(ptr)
  1289. /**
  1290. * qdf_mem_valloc() - Allocate virtual memory for the given
  1291. * size
  1292. * @size: Number of bytes of memory to be allocated
  1293. *
  1294. * Return: Pointer to the starting address of the allocated virtual memory
  1295. */
  1296. #define qdf_mem_valloc(size) __qdf_mem_valloc(size, __func__, __LINE__)
  1297. #ifdef ENABLE_VALLOC_REPLACE_MALLOC
  1298. /**
  1299. * qdf_mem_common_alloc() - Common function to allocate memory for the
  1300. * given size, allocation method decided by ENABLE_VALLOC_REPLACE_MALLOC
  1301. * @size: Number of bytes of memory to be allocated
  1302. *
  1303. * Return: Pointer to the starting address of the allocated memory
  1304. */
  1305. #define qdf_mem_common_alloc(size) qdf_mem_valloc(size)
  1306. /**
  1307. * qdf_mem_common_free() - Common function to free the memory pointed
  1308. * to by ptr, memory free method decided by ENABLE_VALLOC_REPLACE_MALLOC
  1309. * @ptr: Pointer to the starting address of the memory to
  1310. * be freed.
  1311. *
  1312. * Return: None
  1313. */
  1314. #define qdf_mem_common_free(ptr) qdf_mem_vfree(ptr)
  1315. #else
  1316. #define qdf_mem_common_alloc(size) qdf_mem_malloc(size)
  1317. #define qdf_mem_common_free(ptr) qdf_mem_free(ptr)
  1318. #endif
  1319. /**
  1320. * qdf_ioremap() - map bus memory into cpu space
  1321. * @HOST_CE_ADDRESS: bus address of the memory
  1322. * @HOST_CE_SIZE: memory size to map
  1323. */
  1324. #define qdf_ioremap(HOST_CE_ADDRESS, HOST_CE_SIZE) \
  1325. __qdf_ioremap(HOST_CE_ADDRESS, HOST_CE_SIZE)
  1326. #if IS_ENABLED(CONFIG_ARM_SMMU) && defined(ENABLE_SMMU_S1_TRANSLATION)
  1327. /*
  1328. * typedef qdf_iommu_domain_t: Platform independent iommu domain
  1329. * abstraction
  1330. */
  1331. typedef __qdf_iommu_domain_t qdf_iommu_domain_t;
  1332. /**
  1333. * qdf_iommu_domain_get_attr() - API to get iommu domain attributes
  1334. * @domain: iommu domain
  1335. * @attr: iommu attribute
  1336. * @data: data pointer
  1337. *
  1338. * Return: 0 on success, else errno
  1339. */
  1340. int
  1341. qdf_iommu_domain_get_attr(qdf_iommu_domain_t *domain,
  1342. enum qdf_iommu_attr attr, void *data);
  1343. #endif
  1344. #endif /* __QDF_MEMORY_H */