1 /* 2 * Linux Packet (skb) interface 3 * 4 * Copyright (C) 1999-2019, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions 16 * of the license of that module. An independent module is a module which is 17 * not derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * Notwithstanding the above, under no circumstances may you combine this 21 * software in any way with any other Broadcom software provided under a license 22 * other than the GPL, without Broadcom's express prior written consent. 23 * 24 * 25 * <<Broadcom-WL-IPTag/Open:>> 26 * 27 * $Id: linux_pkt.h 701430 2017-05-25 00:03:02Z $ 28 */ 29 30 #ifndef _linux_pkt_h_ 31 #define _linux_pkt_h_ 32 33 #include <typedefs.h> 34 35 #ifdef __ARM_ARCH_7A__ 36 #define PKT_HEADROOM_DEFAULT \ 37 NET_SKB_PAD /**< NET_SKB_PAD is defined in a linux kernel header */ 38 #else 39 #define PKT_HEADROOM_DEFAULT 16 40 #endif /* __ARM_ARCH_7A__ */ 41 42 #ifdef BCMDRIVER 43 /* 44 * BINOSL selects the slightly slower function-call-based binary compatible osl. 45 * Macros expand to calls to functions defined in linux_osl.c . 46 */ 47 /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for 48 * performance reasons), we need the Linux headers. 49 */ 50 #include <linuxver.h> 51 52 /* packet primitives */ 53 #ifdef BCM_OBJECT_TRACE 54 #define PKTGET(osh, len, send) \ 55 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) \ 65 linux_pktfree((osh), (skb), (send), __LINE__, __FUNCTION__) 66 #else 67 #define PKTFREE(osh, skb, send) linux_pktfree((osh), (skb), (send)) 68 #endif /* BCM_OBJECT_TRACE */ 69 #ifdef CONFIG_DHD_USE_STATIC_BUF 70 #define PKTGET_STATIC(osh, len, send) osl_pktget_static((osh), (len)) 71 #define PKTFREE_STATIC(osh, skb, send) osl_pktfree_static((osh), (skb), (send)) 72 #else 73 #define PKTGET_STATIC PKTGET 74 #define PKTFREE_STATIC PKTFREE 75 #endif /* CONFIG_DHD_USE_STATIC_BUF */ 76 #define PKTDATA(osh, skb) \ 77 ( { \ 78 BCM_REFERENCE(osh); \ 79 (((struct sk_buff *)(skb))->data); \ 80 }) 81 #define PKTLEN(osh, skb) \ 82 ( { \ 83 BCM_REFERENCE(osh); \ 84 (((struct sk_buff *)(skb))->len); \ 85 }) 86 #define PKTHEAD(osh, skb) \ 87 ( { \ 88 BCM_REFERENCE(osh); \ 89 (((struct sk_buff *)(skb))->head); \ 90 }) 91 #define PKTSETHEAD(osh, skb, h) \ 92 ( { \ 93 BCM_REFERENCE(osh); \ 94 (((struct sk_buff *)(skb))->head = (h)); \ 95 }) 96 #define PKTHEADROOM(osh, skb) \ 97 (PKTDATA(osh, skb) - (((struct sk_buff *)(skb))->head)) 98 #define PKTEXPHEADROOM(osh, skb, b) \ 99 ( { \ 100 BCM_REFERENCE(osh); \ 101 skb_realloc_headroom((struct sk_buff *)(skb), (b)); \ 102 }) 103 #define PKTTAILROOM(osh, skb) \ 104 ( { \ 105 BCM_REFERENCE(osh); \ 106 skb_tailroom((struct sk_buff *)(skb)); \ 107 }) 108 #define PKTPADTAILROOM(osh, skb, padlen) \ 109 ( { \ 110 BCM_REFERENCE(osh); \ 111 skb_pad((struct sk_buff *)(skb), (padlen)); \ 112 }) 113 #define PKTNEXT(osh, skb) \ 114 ( { \ 115 BCM_REFERENCE(osh); \ 116 (((struct sk_buff *)(skb))->next); \ 117 }) 118 #define PKTSETNEXT(osh, skb, x) \ 119 ( { \ 120 BCM_REFERENCE(osh); \ 121 (((struct sk_buff *)(skb))->next = (struct sk_buff *)(x)); \ 122 }) 123 #define PKTSETLEN(osh, skb, len) \ 124 ( { \ 125 BCM_REFERENCE(osh); \ 126 __skb_trim((struct sk_buff *)(skb), (len)); \ 127 }) 128 #define PKTPUSH(osh, skb, bytes) \ 129 ( { \ 130 BCM_REFERENCE(osh); \ 131 skb_push((struct sk_buff *)(skb), (bytes)); \ 132 }) 133 #define PKTPULL(osh, skb, bytes) \ 134 ( { \ 135 BCM_REFERENCE(osh); \ 136 skb_pull((struct sk_buff *)(skb), (bytes)); \ 137 }) 138 #define PKTTAG(skb) ((void *)(((struct sk_buff *)(skb))->cb)) 139 #define PKTSETPOOL(osh, skb, x, y) BCM_REFERENCE(osh) 140 #define PKTPOOL(osh, skb) \ 141 ( { \ 142 BCM_REFERENCE(osh); \ 143 BCM_REFERENCE(skb); \ 144 FALSE; \ 145 }) 146 #define PKTFREELIST(skb) PKTLINK(skb) 147 #define PKTSETFREELIST(skb, x) PKTSETLINK((skb), (x)) 148 #define PKTPTR(skb) (skb) 149 #define PKTID(skb) \ 150 ( { \ 151 BCM_REFERENCE(skb); \ 152 0; \ 153 }) 154 #define PKTSETID(skb, id) \ 155 ( { \ 156 BCM_REFERENCE(skb); \ 157 BCM_REFERENCE(id); \ 158 }) 159 #define PKTSHRINK(osh, m) \ 160 ( { \ 161 BCM_REFERENCE(osh); \ 162 m; \ 163 }) 164 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) && defined(TSQ_MULTIPLIER) 165 #define PKTORPHAN(skb, tsq) osl_pkt_orphan_partial(skb, tsq) 166 extern void osl_pkt_orphan_partial(struct sk_buff *skb, int tsq); 167 #else 168 #define PKTORPHAN(skb, tsq) \ 169 ( { \ 170 BCM_REFERENCE(skb); \ 171 0; \ 172 }) 173 #endif /* LINUX VERSION >= 3.6 */ 174 175 #define PKTSETFAST(osh, skb) \ 176 ( { \ 177 BCM_REFERENCE(osh); \ 178 BCM_REFERENCE(skb); \ 179 }) 180 #define PKTCLRFAST(osh, skb) \ 181 ( { \ 182 BCM_REFERENCE(osh); \ 183 BCM_REFERENCE(skb); \ 184 }) 185 #define PKTISFAST(osh, skb) \ 186 ( { \ 187 BCM_REFERENCE(osh); \ 188 BCM_REFERENCE(skb); \ 189 FALSE; \ 190 }) 191 192 #define PKTSETCTF(osh, skb) \ 193 ( { \ 194 BCM_REFERENCE(osh); \ 195 BCM_REFERENCE(skb); \ 196 }) 197 #define PKTCLRCTF(osh, skb) \ 198 ( { \ 199 BCM_REFERENCE(osh); \ 200 BCM_REFERENCE(skb); \ 201 }) 202 #define PKTISCTF(osh, skb) \ 203 ( { \ 204 BCM_REFERENCE(osh); \ 205 BCM_REFERENCE(skb); \ 206 FALSE; \ 207 }) 208 209 #define PKTSETSKIPCT(osh, skb) \ 210 ( { \ 211 BCM_REFERENCE(osh); \ 212 BCM_REFERENCE(skb); \ 213 }) 214 #define PKTCLRSKIPCT(osh, skb) \ 215 ( { \ 216 BCM_REFERENCE(osh); \ 217 BCM_REFERENCE(skb); \ 218 }) 219 #define PKTSKIPCT(osh, skb) \ 220 ( { \ 221 BCM_REFERENCE(osh); \ 222 BCM_REFERENCE(skb); \ 223 }) 224 #define CTF_MARK(m) \ 225 ( { \ 226 BCM_REFERENCE(m); \ 227 0; \ 228 }) 229 230 #define PKTFRAGLEN(osh, lb, ix) (0) 231 #define PKTSETFRAGLEN(osh, lb, ix, len) BCM_REFERENCE(osh) 232 233 #define PKTSETFWDERBUF(osh, skb) \ 234 ( { \ 235 BCM_REFERENCE(osh); \ 236 BCM_REFERENCE(skb); \ 237 }) 238 #define PKTCLRFWDERBUF(osh, skb) \ 239 ( { \ 240 BCM_REFERENCE(osh); \ 241 BCM_REFERENCE(skb); \ 242 }) 243 #define PKTISFWDERBUF(osh, skb) \ 244 ( { \ 245 BCM_REFERENCE(osh); \ 246 BCM_REFERENCE(skb); \ 247 FALSE; \ 248 }) 249 250 #define PKTSETTOBR(osh, skb) \ 251 ( { \ 252 BCM_REFERENCE(osh); \ 253 BCM_REFERENCE(skb); \ 254 }) 255 #define PKTCLRTOBR(osh, skb) \ 256 ( { \ 257 BCM_REFERENCE(osh); \ 258 BCM_REFERENCE(skb); \ 259 }) 260 #define PKTISTOBR(skb) \ 261 ( { \ 262 BCM_REFERENCE(skb); \ 263 FALSE; \ 264 }) 265 266 #ifdef BCMFA 267 #ifdef BCMFA_HW_HASH 268 #define PKTSETFAHIDX(skb, idx) (((struct sk_buff *)(skb))->napt_idx = idx) 269 #else 270 #define PKTSETFAHIDX(skb, idx) \ 271 ( { \ 272 BCM_REFERENCE(skb); \ 273 BCM_REFERENCE(idx); \ 274 }) 275 #endif /* BCMFA_SW_HASH */ 276 #define PKTGETFAHIDX(skb) (((struct sk_buff *)(skb))->napt_idx) 277 #define PKTSETFADEV(skb, imp) (((struct sk_buff *)(skb))->dev = imp) 278 #define PKTSETRXDEV(skb) \ 279 (((struct sk_buff *)(skb))->rxdev = ((struct sk_buff *)(skb))->dev) 280 281 #define AUX_TCP_FIN_RST (1 << 0) 282 #define AUX_FREED (1 << 1) 283 #define PKTSETFAAUX(skb) \ 284 (((struct sk_buff *)(skb))->napt_flags |= AUX_TCP_FIN_RST) 285 #define PKTCLRFAAUX(skb) \ 286 (((struct sk_buff *)(skb))->napt_flags &= (~AUX_TCP_FIN_RST)) 287 #define PKTISFAAUX(skb) \ 288 (((struct sk_buff *)(skb))->napt_flags & AUX_TCP_FIN_RST) 289 #define PKTSETFAFREED(skb) (((struct sk_buff *)(skb))->napt_flags |= AUX_FREED) 290 #define PKTCLRFAFREED(skb) \ 291 (((struct sk_buff *)(skb))->napt_flags &= (~AUX_FREED)) 292 #define PKTISFAFREED(skb) (((struct sk_buff *)(skb))->napt_flags & AUX_FREED) 293 #define PKTISFABRIDGED(skb) PKTISFAAUX(skb) 294 #else 295 #define PKTISFAAUX(skb) \ 296 ( { \ 297 BCM_REFERENCE(skb); \ 298 FALSE; \ 299 }) 300 #define PKTISFABRIDGED(skb) \ 301 ( { \ 302 BCM_REFERENCE(skb); \ 303 FALSE; \ 304 }) 305 #define PKTISFAFREED(skb) \ 306 ( { \ 307 BCM_REFERENCE(skb); \ 308 FALSE; \ 309 }) 310 311 #define PKTCLRFAAUX(skb) BCM_REFERENCE(skb) 312 #define PKTSETFAFREED(skb) BCM_REFERENCE(skb) 313 #define PKTCLRFAFREED(skb) BCM_REFERENCE(skb) 314 #endif /* BCMFA */ 315 316 #if defined(BCM_OBJECT_TRACE) 317 extern void linux_pktfree(osl_t *osh, void *skb, bool send, int line, 318 const char *caller); 319 #else 320 extern void linux_pktfree(osl_t *osh, void *skb, bool send); 321 #endif /* BCM_OBJECT_TRACE */ 322 extern void *osl_pktget_static(osl_t *osh, uint len); 323 extern void osl_pktfree_static(osl_t *osh, void *skb, bool send); 324 extern void osl_pktclone(osl_t *osh, void **pkt); 325 326 #ifdef BCM_OBJECT_TRACE 327 extern void *linux_pktget(osl_t *osh, uint len, int line, const char *caller); 328 extern void *osl_pktdup(osl_t *osh, void *skb, int line, const char *caller); 329 #else 330 extern void *linux_pktget(osl_t *osh, uint len); 331 extern void *osl_pktdup(osl_t *osh, void *skb); 332 #endif /* BCM_OBJECT_TRACE */ 333 extern void *osl_pkt_frmnative(osl_t *osh, void *skb); 334 extern struct sk_buff *osl_pkt_tonative(osl_t *osh, void *pkt); 335 #define PKTFRMNATIVE(osh, skb) \ 336 osl_pkt_frmnative(((osl_t *)osh), (struct sk_buff *)(skb)) 337 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_t *)(osh), (pkt)) 338 339 #define PKTLINK(skb) (((struct sk_buff *)(skb))->prev) 340 #define PKTSETLINK(skb, x) \ 341 (((struct sk_buff *)(skb))->prev = (struct sk_buff *)(x)) 342 #define PKTPRIO(skb) (((struct sk_buff *)(skb))->priority) 343 #define PKTSETPRIO(skb, x) (((struct sk_buff *)(skb))->priority = (x)) 344 #define PKTSUMNEEDED(skb) (((struct sk_buff *)(skb))->ip_summed == CHECKSUM_HW) 345 #define PKTSETSUMGOOD(skb, x) \ 346 (((struct sk_buff *)(skb))->ip_summed = \ 347 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE)) 348 /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is 349 * overloaded */ 350 #define PKTSHARED(skb) (((struct sk_buff *)(skb))->cloned) 351 352 #ifdef CONFIG_NF_CONNTRACK_MARK 353 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)) 354 #define PKTMARK(p) (((struct sk_buff *)(p))->mark) 355 #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->mark = (m) 356 #else /* !2.6.0 */ 357 #define PKTMARK(p) (((struct sk_buff *)(p))->nfmark) 358 #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->nfmark = (m) 359 #endif /* 2.6.0 */ 360 #else /* CONFIG_NF_CONNTRACK_MARK */ 361 #define PKTMARK(p) 0 362 #define PKTSETMARK(p, m) 363 #endif /* CONFIG_NF_CONNTRACK_MARK */ 364 365 #define PKTALLOCED(osh) osl_pktalloced(osh) 366 extern uint osl_pktalloced(osl_t *osh); 367 368 #endif /* BCMDRIVER */ 369 370 #endif /* _linux_pkt_h_ */ 371