DPDK  20.05.0
rte_mbuf_core.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright 2014 6WIND S.A.
4  */
5 
6 #ifndef _RTE_MBUF_CORE_H_
7 #define _RTE_MBUF_CORE_H_
8 
17 #include <stdint.h>
18 #include <rte_compat.h>
19 #include <generic/rte_atomic.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /*
26  * Packet Offload Features Flags. It also carry packet type information.
27  * Critical resources. Both rx/tx shared these bits. Be cautious on any change
28  *
29  * - RX flags start at bit position zero, and get added to the left of previous
30  * flags.
31  * - The most-significant 3 bits are reserved for generic mbuf flags
32  * - TX flags therefore start at bit position 60 (i.e. 63-3), and new flags get
33  * added to the right of the previously defined flags i.e. they should count
34  * downwards, not upwards.
35  *
36  * Keep these flags synchronized with rte_get_rx_ol_flag_name() and
37  * rte_get_tx_ol_flag_name().
38  */
39 
47 #define PKT_RX_VLAN (1ULL << 0)
48 
50 #define PKT_RX_RSS_HASH (1ULL << 1)
51 
53 #define PKT_RX_FDIR (1ULL << 2)
54 
62 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
63 
71 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
72 
74 #define PKT_RX_EIP_CKSUM_BAD (1ULL << 5)
75 
82 #define PKT_RX_VLAN_STRIPPED (1ULL << 6)
83 
92 #define PKT_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
93 
94 #define PKT_RX_IP_CKSUM_UNKNOWN 0
95 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
96 #define PKT_RX_IP_CKSUM_GOOD (1ULL << 7)
97 #define PKT_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
98 
107 #define PKT_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
108 
109 #define PKT_RX_L4_CKSUM_UNKNOWN 0
110 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
111 #define PKT_RX_L4_CKSUM_GOOD (1ULL << 8)
112 #define PKT_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
113 
115 #define PKT_RX_IEEE1588_PTP (1ULL << 9)
116 
118 #define PKT_RX_IEEE1588_TMST (1ULL << 10)
119 
121 #define PKT_RX_FDIR_ID (1ULL << 13)
122 
124 #define PKT_RX_FDIR_FLX (1ULL << 14)
125 
134 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
135 
141 #define PKT_RX_LRO (1ULL << 16)
142 
146 #define PKT_RX_TIMESTAMP (1ULL << 17)
147 
151 #define PKT_RX_SEC_OFFLOAD (1ULL << 18)
152 
156 #define PKT_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
157 
166 #define PKT_RX_QINQ (1ULL << 20)
167 
180 #define PKT_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
181 
182 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN 0
183 #define PKT_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
184 #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
185 #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
186 
187 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
188 
189 #define PKT_FIRST_FREE (1ULL << 23)
190 #define PKT_LAST_FREE (1ULL << 40)
191 
192 /* add new TX flags here, don't forget to update PKT_LAST_FREE */
193 
203 #define PKT_TX_OUTER_UDP_CKSUM (1ULL << 41)
204 
210 #define PKT_TX_UDP_SEG (1ULL << 42)
211 
215 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
216 
221 #define PKT_TX_MACSEC (1ULL << 44)
222 
231 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
232 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
233 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
234 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
235 
236 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
237 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
238 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
239 
250 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
251 
263 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
264 /* add new TX TUNNEL type here */
265 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
266 
272 #define PKT_TX_QINQ (1ULL << 49)
273 /* this old name is deprecated */
274 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
275 
285 #define PKT_TX_TCP_SEG (1ULL << 50)
286 
288 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
289 
298 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
301 #define PKT_TX_TCP_CKSUM (1ULL << 52)
302 
304 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
305 
307 #define PKT_TX_UDP_CKSUM (3ULL << 52)
308 
310 #define PKT_TX_L4_MASK (3ULL << 52)
311 
318 #define PKT_TX_IP_CKSUM (1ULL << 54)
319 
326 #define PKT_TX_IPV4 (1ULL << 55)
327 
334 #define PKT_TX_IPV6 (1ULL << 56)
335 
341 #define PKT_TX_VLAN (1ULL << 57)
342 /* this old name is deprecated */
343 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
344 
351 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
352 
358 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
359 
365 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
366 
371 #define PKT_TX_OFFLOAD_MASK ( \
372  PKT_TX_OUTER_IPV6 | \
373  PKT_TX_OUTER_IPV4 | \
374  PKT_TX_OUTER_IP_CKSUM | \
375  PKT_TX_VLAN_PKT | \
376  PKT_TX_IPV6 | \
377  PKT_TX_IPV4 | \
378  PKT_TX_IP_CKSUM | \
379  PKT_TX_L4_MASK | \
380  PKT_TX_IEEE1588_TMST | \
381  PKT_TX_TCP_SEG | \
382  PKT_TX_QINQ_PKT | \
383  PKT_TX_TUNNEL_MASK | \
384  PKT_TX_MACSEC | \
385  PKT_TX_SEC_OFFLOAD | \
386  PKT_TX_UDP_SEG | \
387  PKT_TX_OUTER_UDP_CKSUM)
388 
392 #define EXT_ATTACHED_MBUF (1ULL << 61)
393 
394 #define IND_ATTACHED_MBUF (1ULL << 62)
397 #define RTE_MBUF_PRIV_ALIGN 8
398 
405 #define RTE_MBUF_DEFAULT_DATAROOM 2048
406 #define RTE_MBUF_DEFAULT_BUF_SIZE \
407  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
408 
410  uint32_t queue_id;
411  uint8_t traffic_class;
415  uint8_t color;
417  uint16_t reserved;
418 };
424 enum {
425  RTE_MBUF_L2_LEN_BITS = 7,
426  RTE_MBUF_L3_LEN_BITS = 9,
427  RTE_MBUF_L4_LEN_BITS = 8,
428  RTE_MBUF_TSO_SEGSZ_BITS = 16,
429  RTE_MBUF_OUTL3_LEN_BITS = 9,
430  RTE_MBUF_OUTL2_LEN_BITS = 7,
431  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
432  RTE_MBUF_L2_LEN_BITS -
433  RTE_MBUF_L3_LEN_BITS -
434  RTE_MBUF_L4_LEN_BITS -
435  RTE_MBUF_TSO_SEGSZ_BITS -
436  RTE_MBUF_OUTL3_LEN_BITS -
437  RTE_MBUF_OUTL2_LEN_BITS,
438 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
439  RTE_MBUF_L2_LEN_OFS =
440  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
441  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
442  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
443  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
444  RTE_MBUF_OUTL3_LEN_OFS =
445  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
446  RTE_MBUF_OUTL2_LEN_OFS =
447  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
448  RTE_MBUF_TXOFLD_UNUSED_OFS =
449  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
450 #else
451  RTE_MBUF_L2_LEN_OFS = 0,
452  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
453  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
454  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
455  RTE_MBUF_OUTL3_LEN_OFS =
456  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
457  RTE_MBUF_OUTL2_LEN_OFS =
458  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
459  RTE_MBUF_TXOFLD_UNUSED_OFS =
460  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
461 #endif
462 };
463 
467 struct rte_mbuf {
468  RTE_MARKER cacheline0;
469 
470  void *buf_addr;
478  union {
479  rte_iova_t buf_iova;
481  } __rte_aligned(sizeof(rte_iova_t));
482 
483  /* next 8 bytes are initialised on RX descriptor rearm */
484  RTE_MARKER64 rearm_data;
485  uint16_t data_off;
486 
497  union {
500  uint16_t refcnt;
501  };
502  uint16_t nb_segs;
507  uint16_t port;
508 
509  uint64_t ol_flags;
511  /* remaining bytes are set on RX when pulling packet from descriptor */
512  RTE_MARKER rx_descriptor_fields1;
513 
514  /*
515  * The packet type, which is the combination of outer/inner L2, L3, L4
516  * and tunnel types. The packet_type is about data really present in the
517  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
518  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
519  * vlan is stripped from the data.
520  */
522  union {
523  uint32_t packet_type;
524  struct {
525  uint32_t l2_type:4;
526  uint32_t l3_type:4;
527  uint32_t l4_type:4;
528  uint32_t tun_type:4;
530  union {
536  __extension__
537  struct {
538  uint8_t inner_l2_type:4;
540  uint8_t inner_l3_type:4;
542  };
543  };
544  uint32_t inner_l4_type:4;
545  };
546  };
547 
548  uint32_t pkt_len;
549  uint16_t data_len;
551  uint16_t vlan_tci;
552 
554  union {
555  union {
556  uint32_t rss;
557  struct {
558  union {
559  struct {
560  uint16_t hash;
561  uint16_t id;
562  };
563  uint32_t lo;
565  };
566  uint32_t hi;
570  } fdir;
573  struct {
574  uint32_t reserved1;
575  uint16_t reserved2;
576  uint16_t txq;
581  } txadapter;
583  uint32_t usr;
584  } hash;
585  };
586 
588  uint16_t vlan_tci_outer;
589 
590  uint16_t buf_len;
597  uint64_t timestamp;
598 
599  /* second cache line - fields only used in slow path or on TX */
600  RTE_MARKER cacheline1 __rte_cache_min_aligned;
601 
603  union {
604  void *userdata;
605  uint64_t udata64;
606  };
607 
608  struct rte_mempool *pool;
609  struct rte_mbuf *next;
611  /* fields to support TX offloads */
613  union {
614  uint64_t tx_offload;
615  __extension__
616  struct {
617  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
621  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
623  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
625  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
628  /*
629  * Fields for Tx offloading of tunnels.
630  * These are undefined for packets which don't request
631  * any tunnel offloads (outer IP or UDP checksum,
632  * tunnel TSO).
633  *
634  * PMDs should not use these fields unconditionally
635  * when calculating offsets.
636  *
637  * Applications are expected to set appropriate tunnel
638  * offload flags when they fill in these fields.
639  */
640  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
642  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
645  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
646  };
647  };
648 
652  uint16_t priv_size;
653 
655  uint16_t timesync;
656 
658  uint32_t seqn;
659 
664 
665  uint64_t dynfield1[2];
667 
671 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
672 
678  void *fcb_opaque;
680 };
681 
683 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
684 
692 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
693 
699 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
700 
707 #define RTE_MBUF_DIRECT(mb) \
708  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
709 
710 #define MBUF_INVALID_PORT UINT16_MAX
711 
726 #define rte_pktmbuf_mtod_offset(m, t, o) \
727  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
728 
741 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
742 
752 #define rte_pktmbuf_iova_offset(m, o) \
753  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
754 
762 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
763 
764 #ifdef __cplusplus
765 }
766 #endif
767 
768 #endif /* _RTE_MBUF_CORE_H_ */
struct rte_mbuf_ext_shared_info * shinfo
struct rte_mbuf * next
uint16_t txq
uint64_t timestamp
uint16_t vlan_tci_outer
uint8_t inner_esp_next_proto
rte_iova_t buf_physaddr
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:385
void * buf_addr
uint32_t l2_type
uint16_t data_len
uint32_t lo
rte_mbuf_extbuf_free_callback_t free_cb
void * userdata
uint8_t inner_l2_type
uint64_t tso_segsz
uint64_t l4_len
uint16_t nb_segs
uint16_t port
uint64_t outer_l3_len
uint64_t l3_len
uint32_t l4_type
__extension__ typedef void * RTE_MARKER[0]
Definition: rte_common.h:391
uint16_t priv_size
uint16_t timesync
uint32_t hi
struct rte_mbuf_sched sched
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
uint64_t outer_l2_len
uint16_t refcnt
uint32_t tun_type
__extension__ typedef uint64_t RTE_MARKER64[0]
Definition: rte_common.h:399
uint64_t ol_flags
uint32_t pkt_len
uint64_t dynfield1[2]
uint16_t buf_len
uint32_t inner_l4_type
uint32_t packet_type
uint32_t seqn
uint8_t inner_l3_type
#define RTE_STD_C11
Definition: rte_common.h:40
struct rte_mempool * pool
#define __rte_cache_aligned
Definition: rte_common.h:367
uint32_t rss
RTE_STD_C11 union rte_mbuf::@218 __rte_aligned
uint16_t reserved
uint64_t udata64
uint8_t traffic_class
uint32_t l3_type
rte_atomic16_t refcnt_atomic
struct rte_mbuf::@221::@233::@235 txadapter
uint64_t tx_offload
uint16_t vlan_tci
rte_atomic16_t refcnt_atomic
struct rte_mbuf::@221::@233::@234 fdir