linux_pkt.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Linux Packet (skb) interface
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, 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. #ifndef _linux_pkt_h_
  32. #define _linux_pkt_h_
  33. #include <typedefs.h>
  34. #ifdef __ARM_ARCH_7A__
  35. #define PKT_HEADROOM_DEFAULT NET_SKB_PAD /**< NET_SKB_PAD is defined in a linux kernel header */
  36. #else
  37. #define PKT_HEADROOM_DEFAULT 16
  38. #endif /* __ARM_ARCH_7A__ */
  39. #ifdef BCMDRIVER
  40. /*
  41. * BINOSL selects the slightly slower function-call-based binary compatible osl.
  42. * Macros expand to calls to functions defined in linux_osl.c .
  43. */
  44. /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for
  45. * performance reasons), we need the Linux headers.
  46. */
  47. #include <linuxver.h>
  48. /* packet primitives */
  49. #ifdef BCM_OBJECT_TRACE
  50. #define PKTGET(osh, len, send) linux_pktget((osh), (len), __LINE__, __FUNCTION__)
  51. #define PKTDUP(osh, skb) osl_pktdup((osh), (skb), __LINE__, __FUNCTION__)
  52. #else
  53. #define PKTGET(osh, len, send) linux_pktget((osh), (len))
  54. #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
  55. #endif /* BCM_OBJECT_TRACE */
  56. #define PKTLIST_DUMP(osh, buf) BCM_REFERENCE(osh)
  57. #define PKTDBG_TRACE(osh, pkt, bit) BCM_REFERENCE(osh)
  58. #if defined(BCM_OBJECT_TRACE)
  59. #define PKTFREE(osh, skb, send) linux_pktfree((osh), (skb), (send), __LINE__, __FUNCTION__)
  60. #else
  61. #define PKTFREE(osh, skb, send) linux_pktfree((osh), (skb), (send))
  62. #endif /* BCM_OBJECT_TRACE */
  63. #ifdef CONFIG_DHD_USE_STATIC_BUF
  64. #define PKTGET_STATIC(osh, len, send) osl_pktget_static((osh), (len))
  65. #define PKTFREE_STATIC(osh, skb, send) osl_pktfree_static((osh), (skb), (send))
  66. #else
  67. #define PKTGET_STATIC PKTGET
  68. #define PKTFREE_STATIC PKTFREE
  69. #endif /* CONFIG_DHD_USE_STATIC_BUF */
  70. #define PKTDATA(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->data);})
  71. #define PKTLEN(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->len);})
  72. #define PKTHEAD(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->head);})
  73. #define PKTSETHEAD(osh, skb, h) ({BCM_REFERENCE(osh); \
  74. (((struct sk_buff *)(skb))->head = (h));})
  75. #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
  76. #define PKTEXPHEADROOM(osh, skb, b) \
  77. ({ \
  78. BCM_REFERENCE(osh); \
  79. skb_realloc_headroom((struct sk_buff*)(skb), (b)); \
  80. })
  81. #define PKTTAILROOM(osh, skb) \
  82. ({ \
  83. BCM_REFERENCE(osh); \
  84. skb_tailroom((struct sk_buff*)(skb)); \
  85. })
  86. #define PKTPADTAILROOM(osh, skb, padlen) \
  87. ({ \
  88. BCM_REFERENCE(osh); \
  89. skb_pad((struct sk_buff*)(skb), (padlen)); \
  90. })
  91. #define PKTNEXT(osh, skb) ({BCM_REFERENCE(osh); (((struct sk_buff*)(skb))->next);})
  92. #define PKTSETNEXT(osh, skb, x) \
  93. ({ \
  94. BCM_REFERENCE(osh); \
  95. (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x)); \
  96. })
  97. #define PKTSETLEN(osh, skb, len) \
  98. ({ \
  99. BCM_REFERENCE(osh); \
  100. __skb_trim((struct sk_buff*)(skb), (len)); \
  101. })
  102. #define PKTPUSH(osh, skb, bytes) \
  103. ({ \
  104. BCM_REFERENCE(osh); \
  105. skb_push((struct sk_buff*)(skb), (bytes)); \
  106. })
  107. #define PKTPULL(osh, skb, bytes) \
  108. ({ \
  109. BCM_REFERENCE(osh); \
  110. skb_pull((struct sk_buff*)(skb), (bytes)); \
  111. })
  112. #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb))
  113. #define PKTSETPOOL(osh, skb, x, y) BCM_REFERENCE(osh)
  114. #define PKTPOOL(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;})
  115. #define PKTFREELIST(skb) PKTLINK(skb)
  116. #define PKTSETFREELIST(skb, x) PKTSETLINK((skb), (x))
  117. #define PKTPTR(skb) (skb)
  118. #define PKTID(skb) ({BCM_REFERENCE(skb); 0;})
  119. #define PKTSETID(skb, id) ({BCM_REFERENCE(skb); BCM_REFERENCE(id);})
  120. #define PKTSHRINK(osh, m) ({BCM_REFERENCE(osh); m;})
  121. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)) && defined(TSQ_MULTIPLIER)
  122. #define PKTORPHAN(skb) osl_pkt_orphan_partial(skb)
  123. extern void osl_pkt_orphan_partial(struct sk_buff *skb);
  124. #else
  125. #define PKTORPHAN(skb) ({BCM_REFERENCE(skb); 0;})
  126. #endif /* LINUX VERSION >= 3.6 */
  127. #define PKTSETFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  128. #define PKTCLRFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  129. #define PKTISFAST(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;})
  130. #define PKTSETCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  131. #define PKTCLRCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  132. #define PKTISCTF(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;})
  133. #define PKTSETSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  134. #define PKTCLRSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  135. #define PKTSKIPCT(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  136. #define CTF_MARK(m) ({BCM_REFERENCE(m); 0;})
  137. #define PKTFRAGLEN(osh, lb, ix) (0)
  138. #define PKTSETFRAGLEN(osh, lb, ix, len) BCM_REFERENCE(osh)
  139. #define PKTSETFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); })
  140. #define PKTCLRFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); })
  141. #define PKTISFWDERBUF(osh, skb) ({ BCM_REFERENCE(osh); BCM_REFERENCE(skb); FALSE;})
  142. #define PKTSETTOBR(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  143. #define PKTCLRTOBR(osh, skb) ({BCM_REFERENCE(osh); BCM_REFERENCE(skb);})
  144. #define PKTISTOBR(skb) ({BCM_REFERENCE(skb); FALSE;})
  145. #ifdef BCMFA
  146. #ifdef BCMFA_HW_HASH
  147. #define PKTSETFAHIDX(skb, idx) (((struct sk_buff*)(skb))->napt_idx = idx)
  148. #else
  149. #define PKTSETFAHIDX(skb, idx) ({BCM_REFERENCE(skb); BCM_REFERENCE(idx);})
  150. #endif /* BCMFA_SW_HASH */
  151. #define PKTGETFAHIDX(skb) (((struct sk_buff*)(skb))->napt_idx)
  152. #define PKTSETFADEV(skb, imp) (((struct sk_buff*)(skb))->dev = imp)
  153. #define PKTSETRXDEV(skb) (((struct sk_buff*)(skb))->rxdev = ((struct sk_buff*)(skb))->dev)
  154. #define AUX_TCP_FIN_RST (1 << 0)
  155. #define AUX_FREED (1 << 1)
  156. #define PKTSETFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags |= AUX_TCP_FIN_RST)
  157. #define PKTCLRFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags &= (~AUX_TCP_FIN_RST))
  158. #define PKTISFAAUX(skb) (((struct sk_buff*)(skb))->napt_flags & AUX_TCP_FIN_RST)
  159. #define PKTSETFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags |= AUX_FREED)
  160. #define PKTCLRFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags &= (~AUX_FREED))
  161. #define PKTISFAFREED(skb) (((struct sk_buff*)(skb))->napt_flags & AUX_FREED)
  162. #define PKTISFABRIDGED(skb) PKTISFAAUX(skb)
  163. #else
  164. #define PKTISFAAUX(skb) ({BCM_REFERENCE(skb); FALSE;})
  165. #define PKTISFABRIDGED(skb) ({BCM_REFERENCE(skb); FALSE;})
  166. #define PKTISFAFREED(skb) ({BCM_REFERENCE(skb); FALSE;})
  167. #define PKTCLRFAAUX(skb) BCM_REFERENCE(skb)
  168. #define PKTSETFAFREED(skb) BCM_REFERENCE(skb)
  169. #define PKTCLRFAFREED(skb) BCM_REFERENCE(skb)
  170. #endif /* BCMFA */
  171. #if defined(BCM_OBJECT_TRACE)
  172. extern void linux_pktfree(osl_t *osh, void *skb, bool send, int line, const char *caller);
  173. #else
  174. extern void linux_pktfree(osl_t *osh, void *skb, bool send);
  175. #endif /* BCM_OBJECT_TRACE */
  176. extern void *osl_pktget_static(osl_t *osh, uint len);
  177. extern void osl_pktfree_static(osl_t *osh, void *skb, bool send);
  178. extern void osl_pktclone(osl_t *osh, void **pkt);
  179. #ifdef BCM_OBJECT_TRACE
  180. extern void *linux_pktget(osl_t *osh, uint len, int line, const char *caller);
  181. extern void *osl_pktdup(osl_t *osh, void *skb, int line, const char *caller);
  182. #else
  183. extern void *linux_pktget(osl_t *osh, uint len);
  184. extern void *osl_pktdup(osl_t *osh, void *skb);
  185. #endif /* BCM_OBJECT_TRACE */
  186. extern void *osl_pkt_frmnative(osl_t *osh, void *skb);
  187. extern struct sk_buff *osl_pkt_tonative(osl_t *osh, void *pkt);
  188. #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_t *)osh), (struct sk_buff*)(skb))
  189. #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_t *)(osh), (pkt))
  190. #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
  191. #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
  192. #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
  193. #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
  194. #define PKTSUMNEEDED(skb) (((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW)
  195. #define PKTSETSUMGOOD(skb, x) (((struct sk_buff*)(skb))->ip_summed = \
  196. ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
  197. /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is overloaded */
  198. #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned)
  199. #ifdef CONFIG_NF_CONNTRACK_MARK
  200. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
  201. #define PKTMARK(p) (((struct sk_buff *)(p))->mark)
  202. #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->mark = (m)
  203. #else /* !2.6.0 */
  204. #define PKTMARK(p) (((struct sk_buff *)(p))->nfmark)
  205. #define PKTSETMARK(p, m) ((struct sk_buff *)(p))->nfmark = (m)
  206. #endif /* 2.6.0 */
  207. #else /* CONFIG_NF_CONNTRACK_MARK */
  208. #define PKTMARK(p) 0
  209. #define PKTSETMARK(p, m)
  210. #endif /* CONFIG_NF_CONNTRACK_MARK */
  211. #define PKTALLOCED(osh) osl_pktalloced(osh)
  212. extern uint osl_pktalloced(osl_t *osh);
  213. #endif /* BCMDRIVER */
  214. #endif /* _linux_pkt_h_ */