1 /* 2 * Linux Packet (skb) interface 3 * 4 * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation 5 * 6 * Copyright (C) 1999-2017, Broadcom Corporation 7 * 8 * Unless you and Broadcom execute a separate written software license 9 * agreement governing use of this software, this software is licensed to you 10 * under the terms of the GNU General Public License version 2 (the "GPL"), 11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 12 * following added to such license: 13 * 14 * As a special exception, the copyright holders of this software give you 15 * permission to link this software with independent modules, and to copy and 16 * distribute the resulting executable under terms of your choice, provided that 17 * you also meet, for each linked independent module, the terms and conditions of 18 * the license of that module. An independent module is a module which is not 19 * derived from this software. The special exception does not apply to any 20 * modifications of the software. 21 * 22 * Notwithstanding the above, under no circumstances may you combine this 23 * software in any way with any other Broadcom software provided under a license 24 * other than the GPL, without Broadcom's express prior written consent. 25 * 26 * 27 * <<Broadcom-WL-IPTag/Open:>> 28 * 29 * $Id: linux_pkt.h 701430 2017-05-25 00:03:02Z $ 30 */ 31 32 #ifndef _linux_pkt_h_ 33 #define _linux_pkt_h_ 34 35 #include <typedefs.h> 36 37 #ifdef __ARM_ARCH_7A__ 38 #define PKT_HEADROOM_DEFAULT NET_SKB_PAD /**< NET_SKB_PAD is defined in a linux kernel header */ 39 #else 40 #define PKT_HEADROOM_DEFAULT 16 41 #endif /* __ARM_ARCH_7A__ */ 42 43 #ifdef BCMDRIVER 44 /* 45 * BINOSL selects the slightly slower function-call-based binary compatible osl. 46 * Macros expand to calls to functions defined in linux_osl.c . 47 */ 48 /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for 49 * performance reasons), we need the Linux headers. 50 */ 51 #include <linuxver.h> 52 53 /* packet primitives */ 54 #ifdef BCM_OBJECT_TRACE 55 #define PKTGET(osh, len, send) linux_pktget((osh), (len), __LINE__, __FUNCTION__) 56 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb), __LINE__, __FUNCTION__) 57 #else 58 #define PKTGET(osh, len, send) linux_pktget((osh), (len)) 59 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb)) 60 #endif /* BCM_OBJECT_TRACE */ 61 #define PKTLIST_DUMP(osh, buf) BCM_REFERENCE(osh) 62 #define PKTDBG_TRACE(osh, pkt, bit) BCM_REFERENCE(osh) 63 #if defined(BCM_OBJECT_TRACE) 64 #define PKTFREE(osh, skb, send) linux_pktfree((osh), (skb), (send), __LINE__, __FUNCTION__) 65 #else 66 #define PKTFREE(osh, skb, send) linux_pktfree((osh), (skb), (send)) 67 #endif /* BCM_OBJECT_TRACE */ 68 #ifdef CONFIG_DHD_USE_STATIC_BUF 69 #define PKTGET_STATIC(osh, len, send) osl_pktget_static((osh), (len)) 70 #define PKTFREE_STATIC(osh, skb, send) osl_pktfree_static((osh), (skb), (send)) 71 #else 72 #define PKTGET_STATIC PKTGET 73 #define PKTFREE_STATIC PKTFREE 74 #endif /* CONFIG_DHD_USE_STATIC_BUF */ 75 #define PKTDATA(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->data);}) 76 #define PKTLEN(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->len);}) 77 #define PKTHEAD(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->head);}) 78 #define PKTSETHEAD(osh, skb, h) ({BCM_REFERENCE(osh); \ 79 (((struct sk_buff *)(skb))->head = (h));}) 80 #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head)) 81 #define PKTEXPHEADROOM(osh, skb, b) \ 82 ({ \ 83 BCM_REFERENCE(osh); \ 84 skb_realloc_headroom((struct sk_buff*)(skb), (b)); \ 85 }) 86 #define PKTTAILROOM(osh, skb) \ 87 ({ \ 88 BCM_REFERENCE(osh); \ 89 skb_tailroom((struct sk_buff*)(skb)); \ 90 }) 91 #define PKTPADTAILROOM(osh, skb, padlen) \ 92 ({ \ 93 BCM_REFERENCE(osh); \ 94 skb_pad((struct sk_buff*)(skb), (padlen)); \ 95 }) 96 #define PKTNEXT(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->next);}) 97 #define PKTSETNEXT(osh, skb, x) \ 98 ({ \ 99 BCM_REFERENCE(osh); \ 100 (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x)); \ 101 }) 102 #define PKTSETLEN(osh, skb, len) \ 103 ({ \ 104 BCM_REFERENCE(osh); \ 105 __skb_trim((struct sk_buff*)(skb), (len)); \ 106 }) 107 #define PKTPUSH(osh, skb, bytes) \ 108 ({ \ 109 BCM_REFERENCE(osh); \ 110 skb_push((struct sk_buff*)(skb), (bytes)); \ 111 }) 112 #define PKTPULL(osh, skb, bytes) \ 113 ({ \ 114 BCM_REFERENCE(osh); \ 115 skb_pull((struct sk_buff*)(skb), (bytes)); \ 116 }) 117 #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb)) 118 #define PKTSETPOOL(osh, skb, x, y) BCM_REFERENCE(osh) 119 #define PKTPOOL(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;}) 120 #define PKTFREELIST(skb) PKTLINK(skb) 121 #define PKTSETFREELIST(skb, x) PKTSETLINK((skb), (x)) 122 #define PKTPTR(skb) (skb) 123 #define PKTID(skb) ({BCM_REFERENCE(skb); 0;}) 124 #define PKTSETID(skb, id) ({BCM_REFERENCE(skb); BCM_REFERENCE(id);}) 125 #define PKTSHRINK(osh, m) ({BCM_REFERENCE(osh); m;}) 126 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)) 127 #define PKTORPHAN(skb) skb_orphan(skb) 128 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) && defined(TSQ_MULTIPLIER) 129 #define PKTORPHAN(skb) osl_pkt_orphan_partial(skb) 130 extern void osl_pkt_orphan_partial(struct sk_buff *skb); 131 #else 132 #define PKTORPHAN(skb) ({BCM_REFERENCE(skb); 0;}) 133 #endif /* LINUX VERSION >= 3.6 and 4,12 */ 134 135 #define PKTSETFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 136 #define PKTCLRFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 137 #define PKTISFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;}) 138 139 #define PKTSETCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 140 #define PKTCLRCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 141 #define PKTISCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;}) 142 143 #define PKTSETSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 144 #define PKTCLRSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 145 #define PKTSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 146 #define CTF_MARK(m) ({BCM_REFERENCE(m); 0;}) 147 148 #define PKTFRAGLEN(osh, lb, ix) (0) 149 #define PKTSETFRAGLEN(osh, lb, ix, len) BCM_REFERENCE(osh) 150 151 #define PKTSETFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); }) 152 #define PKTCLRFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); }) 153 #define PKTISFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;}) 154 155 #define PKTSETTOBR(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 156 #define PKTCLRTOBR(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);}) 157 #define PKTISTOBR(skb) ({BCM_REFERENCE(skb); FALSE;}) 158 159 #ifdef BCMFA 160 #ifdef BCMFA_HW_HASH 161 #define PKTSETFAHIDX(skb, idx) (((struct sk_buff*)(skb))->napt_idx = idx) 162 #else 163 #define PKTSETFAHIDX(skb, idx) ({BCM_REFERENCE(skb); BCM_REFERENCE(idx);}) 164 #endif /* BCMFA_SW_HASH */ 165 #define PKTGETFAHIDX(skb) (((struct sk_buff*)(skb))->napt_idx) 166 #define PKTSETFADEV(skb, imp) (((struct sk_buff*)(skb))->dev = imp) 167 #define PKTSETRXDEV(skb) (((struct sk_buff*)(skb))->rxdev = ((struct sk_buff*)(skb))->dev) 168 169 #define AUX_TCP_FIN_RST (1 << 0) 170 #define AUX_FREED (1 << 1) 171 #define PKTSETFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags |= AUX_TCP_FIN_RST) 172 #define PKTCLRFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags &= (~AUX_TCP_FIN_RST)) 173 #define PKTISFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags & AUX_TCP_FIN_RST) 174 #define PKTSETFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags |= AUX_FREED) 175 #define PKTCLRFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags &= (~AUX_FREED)) 176 #define PKTISFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags & AUX_FREED) 177 #define PKTISFABRIDGED(skb) PKTISFAAUX(skb) 178 #else 179 #define PKTISFAAUX(skb) ({BCM_REFERENCE(skb); FALSE;}) 180 #define PKTISFABRIDGED(skb) ({BCM_REFERENCE(skb); FALSE;}) 181 #define PKTISFAFREED(skb) ({BCM_REFERENCE(skb); FALSE;}) 182 183 #define PKTCLRFAAUX(skb) BCM_REFERENCE(skb) 184 #define PKTSETFAFREED(skb) BCM_REFERENCE(skb) 185 #define PKTCLRFAFREED(skb) BCM_REFERENCE(skb) 186 #endif /* BCMFA */ 187 188 #if defined(BCM_OBJECT_TRACE) 189 extern void linux_pktfree(osl_t *osh, void *skb, bool send, int line, const char *caller); 190 #else 191 extern void linux_pktfree(osl_t *osh, void *skb, bool send); 192 #endif /* BCM_OBJECT_TRACE */ 193 extern void *osl_pktget_static(osl_t *osh, uint len); 194 extern void osl_pktfree_static(osl_t *osh, void *skb, bool send); 195 extern void osl_pktclone(osl_t *osh, void **pkt); 196 197 #ifdef BCM_OBJECT_TRACE 198 extern void *linux_pktget(osl_t *osh, uint len, int line, const char *caller); 199 extern void *osl_pktdup(osl_t *osh, void *skb, int line, const char *caller); 200 #else 201 extern void *linux_pktget(osl_t *osh, uint len); 202 extern void *osl_pktdup(osl_t *osh, void *skb); 203 #endif /* BCM_OBJECT_TRACE */ 204 extern void *osl_pkt_frmnative(osl_t *osh, void *skb); 205 extern struct sk_buff *osl_pkt_tonative(osl_t *osh, void *pkt); 206 #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_t *)osh), (struct sk_buff*)(skb)) 207 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_t *)(osh), (pkt)) 208 209 #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev) 210 #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x)) 211 #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority) 212 #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x)) 213 #define PKTSUMNEEDED(skb) (((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW) 214 #define PKTSETSUMGOOD(skb, x) (((struct sk_buff*)(skb))->ip_summed = \ 215 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE)) 216 /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is overloaded */ 217 #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned) 218 219 #ifdef CONFIG_NF_CONNTRACK_MARK 220 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) 221 #define PKTMARK(p) (((struct sk_buff *)(p))->mark) 222 #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->mark = (m) 223 #else /* !2.6.0 */ 224 #define PKTMARK(p) (((struct sk_buff *)(p))->nfmark) 225 #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->nfmark = (m) 226 #endif /* 2.6.0 */ 227 #else /* CONFIG_NF_CONNTRACK_MARK */ 228 #define PKTMARK(p) 0 229 #define PKTSETMARK(p, m) 230 #endif /* CONFIG_NF_CONNTRACK_MARK */ 231 232 #define PKTALLOCED(osh) osl_pktalloced(osh) 233 extern uint osl_pktalloced(osl_t *osh); 234 235 #endif /* BCMDRIVER */ 236 237 #endif /* _linux_pkt_h_ */ 238