DPDK  24.03.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 
19 #include <stdalign.h>
20 #include <stdint.h>
21 
22 #include <rte_byteorder.h>
23 #include <rte_stdatomic.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /*
30  * Packet Offload Features Flags. It also carry packet type information.
31  * Critical resources. Both rx/tx shared these bits. Be cautious on any change
32  *
33  * - RX flags start at bit position zero, and get added to the left of previous
34  * flags.
35  * - The most-significant 3 bits are reserved for generic mbuf flags
36  * - TX flags therefore start at bit position 60 (i.e. 63-3), and new flags get
37  * added to the right of the previously defined flags i.e. they should count
38  * downwards, not upwards.
39  *
40  * Keep these flags synchronized with rte_get_rx_ol_flag_name() and
41  * rte_get_tx_ol_flag_name().
42  */
43 
51 #define RTE_MBUF_F_RX_VLAN (1ULL << 0)
52 
54 #define RTE_MBUF_F_RX_RSS_HASH (1ULL << 1)
55 
57 #define RTE_MBUF_F_RX_FDIR (1ULL << 2)
58 
63 #define RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
64 
71 #define RTE_MBUF_F_RX_VLAN_STRIPPED (1ULL << 6)
72 
81 #define RTE_MBUF_F_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
82 
83 #define RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN 0
84 #define RTE_MBUF_F_RX_IP_CKSUM_BAD (1ULL << 4)
85 #define RTE_MBUF_F_RX_IP_CKSUM_GOOD (1ULL << 7)
86 #define RTE_MBUF_F_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
87 
96 #define RTE_MBUF_F_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
97 
98 #define RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN 0
99 #define RTE_MBUF_F_RX_L4_CKSUM_BAD (1ULL << 3)
100 #define RTE_MBUF_F_RX_L4_CKSUM_GOOD (1ULL << 8)
101 #define RTE_MBUF_F_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
102 
104 #define RTE_MBUF_F_RX_IEEE1588_PTP (1ULL << 9)
105 
107 #define RTE_MBUF_F_RX_IEEE1588_TMST (1ULL << 10)
108 
110 #define RTE_MBUF_F_RX_FDIR_ID (1ULL << 13)
111 
113 #define RTE_MBUF_F_RX_FDIR_FLX (1ULL << 14)
114 
130 #define RTE_MBUF_F_RX_QINQ_STRIPPED (1ULL << 15)
131 
137 #define RTE_MBUF_F_RX_LRO (1ULL << 16)
138 
139 /* There is no flag defined at offset 17. It is free for any future use. */
140 
144 #define RTE_MBUF_F_RX_SEC_OFFLOAD (1ULL << 18)
145 
149 #define RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
150 
159 #define RTE_MBUF_F_RX_QINQ (1ULL << 20)
160 
176 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
177 
178 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN 0
179 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
180 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
181 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
182 
183 /* add new RX flags here, don't forget to update RTE_MBUF_F_FIRST_FREE */
184 
185 #define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
186 #define RTE_MBUF_F_LAST_FREE (1ULL << 40)
187 
188 /* add new TX flags here, don't forget to update RTE_MBUF_F_LAST_FREE */
189 
199 #define RTE_MBUF_F_TX_OUTER_UDP_CKSUM (1ULL << 41)
200 
206 #define RTE_MBUF_F_TX_UDP_SEG (1ULL << 42)
207 
214 #define RTE_MBUF_F_TX_SEC_OFFLOAD (1ULL << 43)
215 
220 #define RTE_MBUF_F_TX_MACSEC (1ULL << 44)
221 
231 #define RTE_MBUF_F_TX_TUNNEL_VXLAN (0x1ULL << 45)
232 #define RTE_MBUF_F_TX_TUNNEL_GRE (0x2ULL << 45)
233 #define RTE_MBUF_F_TX_TUNNEL_IPIP (0x3ULL << 45)
234 #define RTE_MBUF_F_TX_TUNNEL_GENEVE (0x4ULL << 45)
235 
236 #define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
237 #define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
238 #define RTE_MBUF_F_TX_TUNNEL_GTP (0x7ULL << 45)
239 #define RTE_MBUF_F_TX_TUNNEL_ESP (0x8ULL << 45)
240 
251 #define RTE_MBUF_F_TX_TUNNEL_IP (0xDULL << 45)
252 
264 #define RTE_MBUF_F_TX_TUNNEL_UDP (0xEULL << 45)
265 /* add new TX TUNNEL type here */
266 #define RTE_MBUF_F_TX_TUNNEL_MASK (0xFULL << 45)
267 
273 #define RTE_MBUF_F_TX_QINQ (1ULL << 49)
274 
284 #define RTE_MBUF_F_TX_TCP_SEG (1ULL << 50)
285 
287 #define RTE_MBUF_F_TX_IEEE1588_TMST (1ULL << 51)
288 
289 /*
290  * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
291  * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
292  * L4 checksum offload, the user needs to:
293  * - fill l2_len and l3_len in mbuf
294  * - set the flags RTE_MBUF_F_TX_TCP_CKSUM, RTE_MBUF_F_TX_SCTP_CKSUM or
295  * RTE_MBUF_F_TX_UDP_CKSUM
296  * - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
297  */
298 
300 #define RTE_MBUF_F_TX_L4_NO_CKSUM (0ULL << 52)
301 
303 #define RTE_MBUF_F_TX_TCP_CKSUM (1ULL << 52)
304 
306 #define RTE_MBUF_F_TX_SCTP_CKSUM (2ULL << 52)
307 
309 #define RTE_MBUF_F_TX_UDP_CKSUM (3ULL << 52)
310 
312 #define RTE_MBUF_F_TX_L4_MASK (3ULL << 52)
313 
320 #define RTE_MBUF_F_TX_IP_CKSUM (1ULL << 54)
321 
328 #define RTE_MBUF_F_TX_IPV4 (1ULL << 55)
329 
336 #define RTE_MBUF_F_TX_IPV6 (1ULL << 56)
337 
343 #define RTE_MBUF_F_TX_VLAN (1ULL << 57)
344 
351 #define RTE_MBUF_F_TX_OUTER_IP_CKSUM (1ULL << 58)
352 
358 #define RTE_MBUF_F_TX_OUTER_IPV4 (1ULL << 59)
359 
365 #define RTE_MBUF_F_TX_OUTER_IPV6 (1ULL << 60)
366 
371 #define RTE_MBUF_F_TX_OFFLOAD_MASK ( \
372  RTE_MBUF_F_TX_OUTER_IPV6 | \
373  RTE_MBUF_F_TX_OUTER_IPV4 | \
374  RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
375  RTE_MBUF_F_TX_VLAN | \
376  RTE_MBUF_F_TX_IPV6 | \
377  RTE_MBUF_F_TX_IPV4 | \
378  RTE_MBUF_F_TX_IP_CKSUM | \
379  RTE_MBUF_F_TX_L4_MASK | \
380  RTE_MBUF_F_TX_IEEE1588_TMST | \
381  RTE_MBUF_F_TX_TCP_SEG | \
382  RTE_MBUF_F_TX_QINQ | \
383  RTE_MBUF_F_TX_TUNNEL_MASK | \
384  RTE_MBUF_F_TX_MACSEC | \
385  RTE_MBUF_F_TX_SEC_OFFLOAD | \
386  RTE_MBUF_F_TX_UDP_SEG | \
387  RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
388 
392 #define RTE_MBUF_F_EXTERNAL (1ULL << 61)
393 
394 #define RTE_MBUF_F_INDIRECT (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 
468  RTE_MARKER cacheline0;
469 
470  void *buf_addr;
471 #if RTE_IOVA_IN_MBUF
472 
480  alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
481 #else
482 
487  struct rte_mbuf *next;
488 #endif
489 
490  /* next 8 bytes are initialised on RX descriptor rearm */
491  RTE_MARKER64 rearm_data;
492  uint16_t data_off;
493 
502  RTE_ATOMIC(uint16_t) refcnt;
503 
508  uint16_t nb_segs;
509 
513  uint16_t port;
514 
515  uint64_t ol_flags;
517  /* remaining bytes are set on RX when pulling packet from descriptor */
518  RTE_MARKER rx_descriptor_fields1;
519 
520  /*
521  * The packet type, which is the combination of outer/inner L2, L3, L4
522  * and tunnel types. The packet_type is about data really present in the
523  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
524  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
525  * vlan is stripped from the data.
526  */
527  union {
528  uint32_t packet_type;
529  __extension__
530  struct {
531  uint8_t l2_type:4;
532  uint8_t l3_type:4;
533  uint8_t l4_type:4;
534  uint8_t tun_type:4;
535  union {
541  __extension__
542  struct {
543  uint8_t inner_l2_type:4;
545  uint8_t inner_l3_type:4;
547  };
548  };
549  uint8_t inner_l4_type:4;
550  };
551  };
552 
553  uint32_t pkt_len;
554  uint16_t data_len;
556  uint16_t vlan_tci;
557 
558  union {
559  union {
560  uint32_t rss;
561  struct {
562  union {
563  struct {
564  uint16_t hash;
565  uint16_t id;
566  };
567  uint32_t lo;
569  };
570  uint32_t hi;
574  } fdir;
575  struct rte_mbuf_sched sched;
577  struct {
578  uint32_t reserved1;
579  uint16_t reserved2;
580  uint16_t txq;
585  } txadapter;
586  uint32_t usr;
588  } hash;
589  };
590 
592  uint16_t vlan_tci_outer;
593 
594  uint16_t buf_len;
596  struct rte_mempool *pool;
598  /* second cache line - fields only used in slow path or on TX */
599  alignas(RTE_CACHE_LINE_MIN_SIZE) RTE_MARKER cacheline1;
600 
601 #if RTE_IOVA_IN_MBUF
602 
606  struct rte_mbuf *next;
607 #else
608 
612  uint64_t dynfield2;
613 #endif
614 
615  /* fields to support TX offloads */
616  union {
617  uint64_t tx_offload;
618  __extension__
619  struct {
620  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
624  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
626  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
628  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
631  /*
632  * Fields for Tx offloading of tunnels.
633  * These are undefined for packets which don't request
634  * any tunnel offloads (outer IP or UDP checksum,
635  * tunnel TSO).
636  *
637  * PMDs should not use these fields unconditionally
638  * when calculating offsets.
639  *
640  * Applications are expected to set appropriate tunnel
641  * offload flags when they fill in these fields.
642  */
643  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
645  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
648  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
649  };
650  };
651 
656 
660  uint16_t priv_size;
661 
663  uint16_t timesync;
664 
665  uint32_t dynfield1[9];
666 };
667 
671 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
672 
678  void *fcb_opaque;
679  RTE_ATOMIC(uint16_t) refcnt;
680 };
681 
683 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
684 
692 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
693 
699 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
700 
707 #define RTE_MBUF_DIRECT(mb) \
708  (!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
709 
711 #define RTE_MBUF_PORT_INVALID UINT16_MAX
712 
713 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
714 
729 #define rte_pktmbuf_mtod_offset(m, t, o) \
730  ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
731 
744 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
745 
755 #define rte_pktmbuf_iova_offset(m, o) \
756  (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
757 
765 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
766 
767 #ifdef __cplusplus
768 }
769 #endif
770 
771 #endif /* _RTE_MBUF_CORE_H_ */
struct rte_mbuf_ext_shared_info * shinfo
struct rte_mbuf * next
uint16_t txq
uint16_t vlan_tci_outer
uint8_t inner_esp_next_proto
uint8_t l2_type
uint8_t l3_type
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:584
void * buf_addr
uint16_t data_len
uint32_t lo
rte_mbuf_extbuf_free_callback_t free_cb
uint8_t inner_l2_type
uint64_t tso_segsz
uint64_t l4_len
#define __rte_cache_aligned
Definition: rte_common.h:553
uint16_t nb_segs
uint16_t port
uint64_t outer_l3_len
uint64_t l3_len
__extension__ typedef void * RTE_MARKER[0]
Definition: rte_common.h:592
uint16_t priv_size
uint16_t timesync
uint32_t hi
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
uint8_t inner_l4_type
uint64_t dynfield2
uint64_t outer_l2_len
uint16_t refcnt
#define RTE_CACHE_LINE_MIN_SIZE
Definition: rte_common.h:550
__extension__ typedef uint64_t RTE_MARKER64[0]
Definition: rte_common.h:600
uint64_t ol_flags
uint32_t pkt_len
uint16_t buf_len
uint32_t packet_type
uint8_t inner_l3_type
uint8_t l4_type
struct rte_mempool * pool
uint32_t rss
uint16_t reserved
uint8_t traffic_class
uint64_t tx_offload
uint16_t vlan_tci
uint8_t tun_type
uint32_t usr