1 /* 2 * Copyright (c) 2020 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: i_qdf_nbuf_frag.h 21 * This file provides OS dependent nbuf frag API's. 22 */ 23 24 #ifndef _I_QDF_NBUF_FRAG_H 25 #define _I_QDF_NBUF_FRAG_H 26 27 #include <qdf_net_types.h> 28 #include <qdf_mem.h> 29 30 #define QDF_NBUF_FRAG_DEBUG_COUNT_ZERO 0 31 #define QDF_NBUF_FRAG_DEBUG_COUNT_ONE 1 32 33 /** 34 * typedef __qdf_frag_t - Abstraction for void * for frag address 35 */ 36 typedef void *__qdf_frag_t; 37 38 #ifdef QDF_NBUF_FRAG_GLOBAL_COUNT 39 40 /** 41 * __qdf_frag_count_get() - Get global frag count 42 * 43 * Return: Global frag gauge 44 */ 45 uint32_t __qdf_frag_count_get(void); 46 47 /** 48 * __qdf_frag_count_inc() - Increment frag global count 49 * @value: Increment value 50 * 51 * Return: none 52 */ 53 void __qdf_frag_count_inc(uint32_t value); 54 55 /** 56 * __qdf_frag_count_dec() - Decrement frag global count 57 * @value: Decrement value 58 * 59 * Return: none 60 */ 61 void __qdf_frag_count_dec(uint32_t value); 62 63 /* 64 * __qdf_frag_mod_init() - Initialization routine for qdf_frag 65 * 66 * Return: none 67 */ 68 void __qdf_frag_mod_init(void); 69 70 /** 71 * __qdf_frag_mod_exit() - Uninitialization routine for qdf_frag 72 * 73 * Return: none 74 */ 75 void __qdf_frag_mod_exit(void); 76 77 #else 78 static inline uint32_t __qdf_frag_count_get(void) 79 { 80 return 0; 81 } 82 83 static inline void __qdf_frag_count_inc(uint32_t value) 84 { 85 } 86 87 static inline void __qdf_frag_count_dec(uint32_t value) 88 { 89 } 90 91 static inline void __qdf_frag_mod_init(void) 92 { 93 } 94 95 static inline void __qdf_frag_mod_exit(void) 96 { 97 } 98 #endif /* QDF_NBUF_FRAG_GLOBAL_COUNT */ 99 100 /** 101 * Maximum number of frags an SKB can hold 102 */ 103 #define __QDF_NBUF_MAX_FRAGS MAX_SKB_FRAGS 104 105 /** 106 * __qdf_mem_unmap_page() - Unmap frag memory 107 * @osdev: qdf_device_t 108 * @paddr: Address to be unmapped 109 * @nbytes: Number of bytes to be unmapped 110 * @dir: qdf_dma_dir_t 111 */ 112 void __qdf_mem_unmap_page(qdf_device_t osdev, qdf_dma_addr_t paddr, 113 size_t nbytes, qdf_dma_dir_t dir); 114 115 /** 116 * __qdf_mem_map_page() - Map frag memory 117 * @osdev: qdf_device_t 118 * @buf: Vaddr to be mapped 119 * @dir: qdf_dma_dir_t 120 * @nbytes: Number of bytes to be mapped 121 * @paddr: Mapped physical address 122 * 123 * Return: QDF_STATUS 124 */ 125 QDF_STATUS __qdf_mem_map_page(qdf_device_t osdev, __qdf_frag_t buf, 126 qdf_dma_dir_t dir, size_t nbytes, 127 qdf_dma_addr_t *phy_addr); 128 129 /** 130 * __qdf_frag_free() - Free allocated frag memory 131 * @vaddr: Frag address to be freed 132 * 133 * Return: none 134 */ 135 static inline void __qdf_frag_free(__qdf_frag_t vaddr) 136 { 137 if (qdf_likely(vaddr)) { 138 skb_free_frag(vaddr); 139 __qdf_frag_count_dec(QDF_NBUF_FRAG_DEBUG_COUNT_ONE); 140 } 141 } 142 143 /** 144 * __qdf_frag_alloc() - Allocate frag Memory 145 * @fragsz: Size of frag memory to be allocated 146 * 147 * Return: Allocated frag addr. 148 */ 149 static inline __qdf_frag_t __qdf_frag_alloc(unsigned int fragsz) 150 { 151 __qdf_frag_t p_frag = netdev_alloc_frag(fragsz); 152 153 if (p_frag) 154 __qdf_frag_count_inc(QDF_NBUF_FRAG_DEBUG_COUNT_ONE); 155 return p_frag; 156 } 157 158 #endif /* _I_QDF_NBUF_FRAG_H */ 159