DPDK  19.11.1
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 
409 /*
410  * define a set of marker types that can be used to refer to set points in the
411  * mbuf.
412  */
413 __extension__
414 typedef void *MARKER[0];
415 __extension__
416 typedef uint8_t MARKER8[0];
419 __extension__
420 typedef uint64_t MARKER64[0];
421 
422 struct rte_mbuf_sched {
423  uint32_t queue_id;
424  uint8_t traffic_class;
428  uint8_t color;
430  uint16_t reserved;
431 };
437 enum {
438  RTE_MBUF_L2_LEN_BITS = 7,
439  RTE_MBUF_L3_LEN_BITS = 9,
440  RTE_MBUF_L4_LEN_BITS = 8,
441  RTE_MBUF_TSO_SEGSZ_BITS = 16,
442  RTE_MBUF_OUTL3_LEN_BITS = 9,
443  RTE_MBUF_OUTL2_LEN_BITS = 7,
444  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
445  RTE_MBUF_L2_LEN_BITS -
446  RTE_MBUF_L3_LEN_BITS -
447  RTE_MBUF_L4_LEN_BITS -
448  RTE_MBUF_TSO_SEGSZ_BITS -
449  RTE_MBUF_OUTL3_LEN_BITS -
450  RTE_MBUF_OUTL2_LEN_BITS,
451 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
452  RTE_MBUF_L2_LEN_OFS =
453  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
454  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
455  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
456  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
457  RTE_MBUF_OUTL3_LEN_OFS =
458  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
459  RTE_MBUF_OUTL2_LEN_OFS =
460  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
461  RTE_MBUF_TXOFLD_UNUSED_OFS =
462  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
463 #else
464  RTE_MBUF_L2_LEN_OFS = 0,
465  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
466  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
467  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
468  RTE_MBUF_OUTL3_LEN_OFS =
469  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
470  RTE_MBUF_OUTL2_LEN_OFS =
471  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
472  RTE_MBUF_TXOFLD_UNUSED_OFS =
473  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
474 #endif
475 };
476 
480 struct rte_mbuf {
481  MARKER cacheline0;
482 
483  void *buf_addr;
491  union {
492  rte_iova_t buf_iova;
494  } __rte_aligned(sizeof(rte_iova_t));
495 
496  /* next 8 bytes are initialised on RX descriptor rearm */
497  MARKER64 rearm_data;
498  uint16_t data_off;
499 
510  union {
513  uint16_t refcnt;
514  };
515  uint16_t nb_segs;
520  uint16_t port;
521 
522  uint64_t ol_flags;
524  /* remaining bytes are set on RX when pulling packet from descriptor */
525  MARKER rx_descriptor_fields1;
526 
527  /*
528  * The packet type, which is the combination of outer/inner L2, L3, L4
529  * and tunnel types. The packet_type is about data really present in the
530  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
531  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
532  * vlan is stripped from the data.
533  */
535  union {
536  uint32_t packet_type;
537  struct {
538  uint32_t l2_type:4;
539  uint32_t l3_type:4;
540  uint32_t l4_type:4;
541  uint32_t tun_type:4;
543  union {
549  __extension__
550  struct {
551  uint8_t inner_l2_type:4;
553  uint8_t inner_l3_type:4;
555  };
556  };
557  uint32_t inner_l4_type:4;
558  };
559  };
560 
561  uint32_t pkt_len;
562  uint16_t data_len;
564  uint16_t vlan_tci;
565 
567  union {
568  union {
569  uint32_t rss;
570  struct {
571  union {
572  struct {
573  uint16_t hash;
574  uint16_t id;
575  };
576  uint32_t lo;
578  };
579  uint32_t hi;
583  } fdir;
584  struct rte_mbuf_sched sched;
586  struct {
587  uint32_t reserved1;
588  uint16_t reserved2;
589  uint16_t txq;
594  } txadapter;
596  uint32_t usr;
597  } hash;
598  };
599 
601  uint16_t vlan_tci_outer;
602 
603  uint16_t buf_len;
610  uint64_t timestamp;
611 
612  /* second cache line - fields only used in slow path or on TX */
613  MARKER cacheline1 __rte_cache_min_aligned;
614 
616  union {
617  void *userdata;
618  uint64_t udata64;
619  };
620 
621  struct rte_mempool *pool;
622  struct rte_mbuf *next;
624  /* fields to support TX offloads */
626  union {
627  uint64_t tx_offload;
628  __extension__
629  struct {
630  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
634  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
636  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
638  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
641  /*
642  * Fields for Tx offloading of tunnels.
643  * These are undefined for packets which don't request
644  * any tunnel offloads (outer IP or UDP checksum,
645  * tunnel TSO).
646  *
647  * PMDs should not use these fields unconditionally
648  * when calculating offsets.
649  *
650  * Applications are expected to set appropriate tunnel
651  * offload flags when they fill in these fields.
652  */
653  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
655  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
658  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
659  };
660  };
661 
665  uint16_t priv_size;
666 
668  uint16_t timesync;
669 
671  uint32_t seqn;
672 
677 
678  uint64_t dynfield1[2];
680 
684 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
685 
691  void *fcb_opaque;
693 };
694 
696 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
697 
705 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
706 
712 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
713 
720 #define RTE_MBUF_DIRECT(mb) \
721  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
722 
723 #define MBUF_INVALID_PORT UINT16_MAX
724 
739 #define rte_pktmbuf_mtod_offset(m, t, o) \
740  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
741 
754 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
755 
765 #define rte_pktmbuf_iova_offset(m, o) \
766  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
767 
775 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
776 
777 #ifdef __cplusplus
778 }
779 #endif
780 
781 #endif /* _RTE_MBUF_CORE_H_ */
rte_mbuf::next
struct rte_mbuf * next
Definition: rte_mbuf_core.h:622
MARKER64
__extension__ typedef uint64_t MARKER64[0]
Definition: rte_mbuf_core.h:420
rte_mbuf::fdir
struct rte_mbuf::@212::@224::@225 fdir
rte_iova_t
uint64_t rte_iova_t
Definition: rte_common.h:335
rte_mbuf::l4_len
uint64_t l4_len
Definition: rte_mbuf_core.h:636
rte_mbuf::buf_addr
void * buf_addr
Definition: rte_mbuf_core.h:483
rte_mbuf::tso_segsz
uint64_t tso_segsz
Definition: rte_mbuf_core.h:638
rte_mbuf::timestamp
uint64_t timestamp
Definition: rte_mbuf_core.h:610
rte_mbuf::lo
uint32_t lo
Definition: rte_mbuf_core.h:576
rte_mbuf::vlan_tci_outer
uint16_t vlan_tci_outer
Definition: rte_mbuf_core.h:601
rte_mbuf_ext_shared_info::refcnt_atomic
rte_atomic16_t refcnt_atomic
Definition: rte_mbuf_core.h:692
rte_mbuf_ext_shared_info::free_cb
rte_mbuf_extbuf_free_callback_t free_cb
Definition: rte_mbuf_core.h:690
rte_mbuf::hi
uint32_t hi
Definition: rte_mbuf_core.h:579
rte_atomic16_t
Definition: rte_atomic.h:223
rte_mbuf::data_len
uint16_t data_len
Definition: rte_mbuf_core.h:562
rte_mbuf::seqn
uint32_t seqn
Definition: rte_mbuf_core.h:671
rte_mbuf::pool
struct rte_mempool * pool
Definition: rte_mbuf_core.h:621
rte_mbuf
Definition: rte_mbuf_core.h:480
__rte_cache_aligned
#define __rte_cache_aligned
Definition: rte_common.h:317
rte_mbuf::l2_type
uint32_t l2_type
Definition: rte_mbuf_core.h:538
rte_mbuf::userdata
void * userdata
Definition: rte_mbuf_core.h:617
rte_mbuf::buf_len
uint16_t buf_len
Definition: rte_mbuf_core.h:603
rte_mbuf::__rte_aligned
RTE_STD_C11 union rte_mbuf::@209 __rte_aligned
rte_atomic.h
rte_mbuf::shinfo
struct rte_mbuf_ext_shared_info * shinfo
Definition: rte_mbuf_core.h:676
rte_mbuf::packet_type
uint32_t packet_type
Definition: rte_mbuf_core.h:536
rte_mbuf_extbuf_free_callback_t
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
Definition: rte_mbuf_core.h:684
rte_mbuf::timesync
uint16_t timesync
Definition: rte_mbuf_core.h:668
rte_mbuf::refcnt
uint16_t refcnt
Definition: rte_mbuf_core.h:513
rte_mbuf::sched
struct rte_mbuf_sched sched
Definition: rte_mbuf_core.h:584
rte_mbuf::inner_esp_next_proto
uint8_t inner_esp_next_proto
Definition: rte_mbuf_core.h:544
rte_mbuf::nb_segs
uint16_t nb_segs
Definition: rte_mbuf_core.h:515
rte_mbuf::buf_physaddr
rte_iova_t buf_physaddr
Definition: rte_mbuf_core.h:493
rte_mbuf::dynfield1
uint64_t dynfield1[2]
Definition: rte_mbuf_core.h:678
rte_mbuf::l2_len
uint64_t l2_len
Definition: rte_mbuf_core.h:630
rte_mbuf::l3_type
uint32_t l3_type
Definition: rte_mbuf_core.h:539
rte_mbuf::port
uint16_t port
Definition: rte_mbuf_core.h:520
rte_mbuf::txadapter
struct rte_mbuf::@212::@224::@226 txadapter
rte_mbuf::outer_l3_len
uint64_t outer_l3_len
Definition: rte_mbuf_core.h:653
rte_mbuf_ext_shared_info::fcb_opaque
void * fcb_opaque
Definition: rte_mbuf_core.h:691
MARKER8
__extension__ typedef uint8_t MARKER8[0]
Definition: rte_mbuf_core.h:416
rte_mbuf::udata64
uint64_t udata64
Definition: rte_mbuf_core.h:618
rte_mbuf::inner_l2_type
uint8_t inner_l2_type
Definition: rte_mbuf_core.h:551
rte_mbuf::priv_size
uint16_t priv_size
Definition: rte_mbuf_core.h:665
rte_mempool
Definition: rte_mempool.h:216
rte_mbuf::ol_flags
uint64_t ol_flags
Definition: rte_mbuf_core.h:522
RTE_STD_C11
#define RTE_STD_C11
Definition: rte_common.h:40
rte_mbuf::pkt_len
uint32_t pkt_len
Definition: rte_mbuf_core.h:561
rte_mbuf::l3_len
uint64_t l3_len
Definition: rte_mbuf_core.h:634
rte_mbuf::txq
uint16_t txq
Definition: rte_mbuf_core.h:589
rte_mbuf::rss
uint32_t rss
Definition: rte_mbuf_core.h:569
rte_mbuf::refcnt_atomic
rte_atomic16_t refcnt_atomic
Definition: rte_mbuf_core.h:511
rte_mbuf::l4_type
uint32_t l4_type
Definition: rte_mbuf_core.h:540
rte_mbuf::tx_offload
uint64_t tx_offload
Definition: rte_mbuf_core.h:627
rte_mbuf::vlan_tci
uint16_t vlan_tci
Definition: rte_mbuf_core.h:564
rte_mbuf::inner_l4_type
uint32_t inner_l4_type
Definition: rte_mbuf_core.h:557
rte_mbuf::outer_l2_len
uint64_t outer_l2_len
Definition: rte_mbuf_core.h:655
rte_mbuf::tun_type
uint32_t tun_type
Definition: rte_mbuf_core.h:541
MARKER
__extension__ typedef void * MARKER[0]
Definition: rte_mbuf_core.h:414
rte_mbuf_ext_shared_info
Definition: rte_mbuf_core.h:689
rte_mbuf::inner_l3_type
uint8_t inner_l3_type
Definition: rte_mbuf_core.h:553