DPDK  24.07.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  void *buf_addr;
469 #if RTE_IOVA_IN_MBUF
470 
478  alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
479 #else
480 
485  struct rte_mbuf *next;
486 #endif
487 
488  /* next 8 bytes are initialised on RX descriptor rearm */
489  union {
490  uint64_t rearm_data[1];
491  __extension__
492  struct {
493  uint16_t data_off;
494 
503  RTE_ATOMIC(uint16_t) refcnt;
504 
509  uint16_t nb_segs;
510 
514  uint16_t port;
515  };
516  };
517 
518  uint64_t ol_flags;
520  /* remaining 24 bytes are set on RX when pulling packet from descriptor */
521  union {
522  /* void * type of the array elements is retained for driver compatibility. */
523  void *rx_descriptor_fields1[24 / sizeof(void *)];
524  __extension__
525  struct {
526  /*
527  * The packet type, which is the combination of outer/inner L2, L3, L4
528  * and tunnel types. The packet_type is about data really present in the
529  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
530  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
531  * vlan is stripped from the data.
532  */
533  union {
534  uint32_t packet_type;
535  __extension__
536  struct {
537  uint8_t l2_type:4;
538  uint8_t l3_type:4;
539  uint8_t l4_type:4;
540  uint8_t tun_type:4;
541  union {
547  __extension__
548  struct {
549  uint8_t inner_l2_type:4;
551  uint8_t inner_l3_type:4;
553  };
554  };
555  uint8_t inner_l4_type:4;
556  };
557  };
558 
559  uint32_t pkt_len;
560  uint16_t data_len;
562  uint16_t vlan_tci;
563 
564  union {
565  union {
566  uint32_t rss;
567  struct {
568  union {
569  struct {
570  uint16_t hash;
571  uint16_t id;
572  };
573  uint32_t lo;
575  };
576  uint32_t hi;
580  } fdir;
581  struct rte_mbuf_sched sched;
583  struct {
584  uint32_t reserved1;
585  uint16_t reserved2;
586  uint16_t txq;
591  } txadapter;
592  uint32_t usr;
594  } hash;
595  };
596 
598  uint16_t vlan_tci_outer;
599 
600  uint16_t buf_len;
601  };
602  };
603 
604  struct rte_mempool *pool;
606  /* second cache line - fields only used in slow path or on TX */
607 #if RTE_IOVA_IN_MBUF
608 
612  alignas(RTE_CACHE_LINE_MIN_SIZE)
613  struct rte_mbuf *next;
614 #else
615 
619  alignas(RTE_CACHE_LINE_MIN_SIZE)
620  uint64_t dynfield2;
621 #endif
622 
623  /* fields to support TX offloads */
624  union {
625  uint64_t tx_offload;
626  __extension__
627  struct {
628  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
632  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
634  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
636  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
639  /*
640  * Fields for Tx offloading of tunnels.
641  * These are undefined for packets which don't request
642  * any tunnel offloads (outer IP or UDP checksum,
643  * tunnel TSO).
644  *
645  * PMDs should not use these fields unconditionally
646  * when calculating offsets.
647  *
648  * Applications are expected to set appropriate tunnel
649  * offload flags when they fill in these fields.
650  */
651  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
653  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
656  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
657  };
658  };
659 
664 
668  uint16_t priv_size;
669 
671  uint16_t timesync;
672 
673  uint32_t dynfield1[9];
674 };
675 
679 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
680 
686  void *fcb_opaque;
687  RTE_ATOMIC(uint16_t) refcnt;
688 };
689 
691 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
692 
700 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
701 
707 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
708 
715 #define RTE_MBUF_DIRECT(mb) \
716  (!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
717 
719 #define RTE_MBUF_PORT_INVALID UINT16_MAX
720 
721 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
722 
737 #define rte_pktmbuf_mtod_offset(m, t, o) \
738  ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
739 
752 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
753 
763 #define rte_pktmbuf_iova_offset(m, o) \
764  (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
765 
773 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
774 
775 #ifdef __cplusplus
776 }
777 #endif
778 
779 #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:599
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:568
uint16_t nb_segs
uint16_t port
uint64_t outer_l3_len
uint64_t l3_len
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 outer_l2_len
uint16_t refcnt
#define RTE_CACHE_LINE_MIN_SIZE
Definition: rte_common.h:565
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