DPDK  24.03.0-rc1
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 <stdint.h>
20 
21 #include <rte_byteorder.h>
22 #include <rte_stdatomic.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*
29  * Packet Offload Features Flags. It also carry packet type information.
30  * Critical resources. Both rx/tx shared these bits. Be cautious on any change
31  *
32  * - RX flags start at bit position zero, and get added to the left of previous
33  * flags.
34  * - The most-significant 3 bits are reserved for generic mbuf flags
35  * - TX flags therefore start at bit position 60 (i.e. 63-3), and new flags get
36  * added to the right of the previously defined flags i.e. they should count
37  * downwards, not upwards.
38  *
39  * Keep these flags synchronized with rte_get_rx_ol_flag_name() and
40  * rte_get_tx_ol_flag_name().
41  */
42 
50 #define RTE_MBUF_F_RX_VLAN (1ULL << 0)
51 
53 #define RTE_MBUF_F_RX_RSS_HASH (1ULL << 1)
54 
56 #define RTE_MBUF_F_RX_FDIR (1ULL << 2)
57 
62 #define RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
63 
70 #define RTE_MBUF_F_RX_VLAN_STRIPPED (1ULL << 6)
71 
80 #define RTE_MBUF_F_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
81 
82 #define RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN 0
83 #define RTE_MBUF_F_RX_IP_CKSUM_BAD (1ULL << 4)
84 #define RTE_MBUF_F_RX_IP_CKSUM_GOOD (1ULL << 7)
85 #define RTE_MBUF_F_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
86 
95 #define RTE_MBUF_F_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
96 
97 #define RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN 0
98 #define RTE_MBUF_F_RX_L4_CKSUM_BAD (1ULL << 3)
99 #define RTE_MBUF_F_RX_L4_CKSUM_GOOD (1ULL << 8)
100 #define RTE_MBUF_F_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
101 
103 #define RTE_MBUF_F_RX_IEEE1588_PTP (1ULL << 9)
104 
106 #define RTE_MBUF_F_RX_IEEE1588_TMST (1ULL << 10)
107 
109 #define RTE_MBUF_F_RX_FDIR_ID (1ULL << 13)
110 
112 #define RTE_MBUF_F_RX_FDIR_FLX (1ULL << 14)
113 
129 #define RTE_MBUF_F_RX_QINQ_STRIPPED (1ULL << 15)
130 
136 #define RTE_MBUF_F_RX_LRO (1ULL << 16)
137 
138 /* There is no flag defined at offset 17. It is free for any future use. */
139 
143 #define RTE_MBUF_F_RX_SEC_OFFLOAD (1ULL << 18)
144 
148 #define RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
149 
158 #define RTE_MBUF_F_RX_QINQ (1ULL << 20)
159 
175 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
176 
177 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN 0
178 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
179 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
180 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
181 
182 /* add new RX flags here, don't forget to update RTE_MBUF_F_FIRST_FREE */
183 
184 #define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
185 #define RTE_MBUF_F_LAST_FREE (1ULL << 40)
186 
187 /* add new TX flags here, don't forget to update RTE_MBUF_F_LAST_FREE */
188 
198 #define RTE_MBUF_F_TX_OUTER_UDP_CKSUM (1ULL << 41)
199 
205 #define RTE_MBUF_F_TX_UDP_SEG (1ULL << 42)
206 
213 #define RTE_MBUF_F_TX_SEC_OFFLOAD (1ULL << 43)
214 
219 #define RTE_MBUF_F_TX_MACSEC (1ULL << 44)
220 
230 #define RTE_MBUF_F_TX_TUNNEL_VXLAN (0x1ULL << 45)
231 #define RTE_MBUF_F_TX_TUNNEL_GRE (0x2ULL << 45)
232 #define RTE_MBUF_F_TX_TUNNEL_IPIP (0x3ULL << 45)
233 #define RTE_MBUF_F_TX_TUNNEL_GENEVE (0x4ULL << 45)
234 
235 #define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
236 #define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
237 #define RTE_MBUF_F_TX_TUNNEL_GTP (0x7ULL << 45)
238 #define RTE_MBUF_F_TX_TUNNEL_ESP (0x8ULL << 45)
239 
250 #define RTE_MBUF_F_TX_TUNNEL_IP (0xDULL << 45)
251 
263 #define RTE_MBUF_F_TX_TUNNEL_UDP (0xEULL << 45)
264 /* add new TX TUNNEL type here */
265 #define RTE_MBUF_F_TX_TUNNEL_MASK (0xFULL << 45)
266 
272 #define RTE_MBUF_F_TX_QINQ (1ULL << 49)
273 
283 #define RTE_MBUF_F_TX_TCP_SEG (1ULL << 50)
284 
286 #define RTE_MBUF_F_TX_IEEE1588_TMST (1ULL << 51)
287 
288 /*
289  * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
290  * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
291  * L4 checksum offload, the user needs to:
292  * - fill l2_len and l3_len in mbuf
293  * - set the flags RTE_MBUF_F_TX_TCP_CKSUM, RTE_MBUF_F_TX_SCTP_CKSUM or
294  * RTE_MBUF_F_TX_UDP_CKSUM
295  * - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
296  */
297 
299 #define RTE_MBUF_F_TX_L4_NO_CKSUM (0ULL << 52)
300 
302 #define RTE_MBUF_F_TX_TCP_CKSUM (1ULL << 52)
303 
305 #define RTE_MBUF_F_TX_SCTP_CKSUM (2ULL << 52)
306 
308 #define RTE_MBUF_F_TX_UDP_CKSUM (3ULL << 52)
309 
311 #define RTE_MBUF_F_TX_L4_MASK (3ULL << 52)
312 
319 #define RTE_MBUF_F_TX_IP_CKSUM (1ULL << 54)
320 
327 #define RTE_MBUF_F_TX_IPV4 (1ULL << 55)
328 
335 #define RTE_MBUF_F_TX_IPV6 (1ULL << 56)
336 
342 #define RTE_MBUF_F_TX_VLAN (1ULL << 57)
343 
350 #define RTE_MBUF_F_TX_OUTER_IP_CKSUM (1ULL << 58)
351 
357 #define RTE_MBUF_F_TX_OUTER_IPV4 (1ULL << 59)
358 
364 #define RTE_MBUF_F_TX_OUTER_IPV6 (1ULL << 60)
365 
370 #define RTE_MBUF_F_TX_OFFLOAD_MASK ( \
371  RTE_MBUF_F_TX_OUTER_IPV6 | \
372  RTE_MBUF_F_TX_OUTER_IPV4 | \
373  RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
374  RTE_MBUF_F_TX_VLAN | \
375  RTE_MBUF_F_TX_IPV6 | \
376  RTE_MBUF_F_TX_IPV4 | \
377  RTE_MBUF_F_TX_IP_CKSUM | \
378  RTE_MBUF_F_TX_L4_MASK | \
379  RTE_MBUF_F_TX_IEEE1588_TMST | \
380  RTE_MBUF_F_TX_TCP_SEG | \
381  RTE_MBUF_F_TX_QINQ | \
382  RTE_MBUF_F_TX_TUNNEL_MASK | \
383  RTE_MBUF_F_TX_MACSEC | \
384  RTE_MBUF_F_TX_SEC_OFFLOAD | \
385  RTE_MBUF_F_TX_UDP_SEG | \
386  RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
387 
391 #define RTE_MBUF_F_EXTERNAL (1ULL << 61)
392 
393 #define RTE_MBUF_F_INDIRECT (1ULL << 62)
396 #define RTE_MBUF_PRIV_ALIGN 8
397 
404 #define RTE_MBUF_DEFAULT_DATAROOM 2048
405 #define RTE_MBUF_DEFAULT_BUF_SIZE \
406  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
407 
409  uint32_t queue_id;
410  uint8_t traffic_class;
414  uint8_t color;
416  uint16_t reserved;
417 };
423 enum {
424  RTE_MBUF_L2_LEN_BITS = 7,
425  RTE_MBUF_L3_LEN_BITS = 9,
426  RTE_MBUF_L4_LEN_BITS = 8,
427  RTE_MBUF_TSO_SEGSZ_BITS = 16,
428  RTE_MBUF_OUTL3_LEN_BITS = 9,
429  RTE_MBUF_OUTL2_LEN_BITS = 7,
430  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
431  RTE_MBUF_L2_LEN_BITS -
432  RTE_MBUF_L3_LEN_BITS -
433  RTE_MBUF_L4_LEN_BITS -
434  RTE_MBUF_TSO_SEGSZ_BITS -
435  RTE_MBUF_OUTL3_LEN_BITS -
436  RTE_MBUF_OUTL2_LEN_BITS,
437 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
438  RTE_MBUF_L2_LEN_OFS =
439  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
440  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
441  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
442  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
443  RTE_MBUF_OUTL3_LEN_OFS =
444  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
445  RTE_MBUF_OUTL2_LEN_OFS =
446  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
447  RTE_MBUF_TXOFLD_UNUSED_OFS =
448  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
449 #else
450  RTE_MBUF_L2_LEN_OFS = 0,
451  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
452  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
453  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
454  RTE_MBUF_OUTL3_LEN_OFS =
455  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
456  RTE_MBUF_OUTL2_LEN_OFS =
457  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
458  RTE_MBUF_TXOFLD_UNUSED_OFS =
459  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
460 #endif
461 };
462 
466 struct rte_mbuf {
467  RTE_MARKER cacheline0;
468 
469  void *buf_addr;
470 #if RTE_IOVA_IN_MBUF
471 
479  rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
480 #else
481 
486  struct rte_mbuf *next;
487 #endif
488 
489  /* next 8 bytes are initialised on RX descriptor rearm */
490  RTE_MARKER64 rearm_data;
491  uint16_t data_off;
492 
501  RTE_ATOMIC(uint16_t) refcnt;
502 
507  uint16_t nb_segs;
508 
512  uint16_t port;
513 
514  uint64_t ol_flags;
516  /* remaining bytes are set on RX when pulling packet from descriptor */
517  RTE_MARKER rx_descriptor_fields1;
518 
519  /*
520  * The packet type, which is the combination of outer/inner L2, L3, L4
521  * and tunnel types. The packet_type is about data really present in the
522  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
523  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
524  * vlan is stripped from the data.
525  */
526  union {
527  uint32_t packet_type;
528  __extension__
529  struct {
530  uint8_t l2_type:4;
531  uint8_t l3_type:4;
532  uint8_t l4_type:4;
533  uint8_t tun_type:4;
534  union {
540  __extension__
541  struct {
542  uint8_t inner_l2_type:4;
544  uint8_t inner_l3_type:4;
546  };
547  };
548  uint8_t inner_l4_type:4;
549  };
550  };
551 
552  uint32_t pkt_len;
553  uint16_t data_len;
555  uint16_t vlan_tci;
556 
557  union {
558  union {
559  uint32_t rss;
560  struct {
561  union {
562  struct {
563  uint16_t hash;
564  uint16_t id;
565  };
566  uint32_t lo;
568  };
569  uint32_t hi;
573  } fdir;
574  struct rte_mbuf_sched sched;
576  struct {
577  uint32_t reserved1;
578  uint16_t reserved2;
579  uint16_t txq;
584  } txadapter;
585  uint32_t usr;
587  } hash;
588  };
589 
591  uint16_t vlan_tci_outer;
592 
593  uint16_t buf_len;
595  struct rte_mempool *pool;
597  /* second cache line - fields only used in slow path or on TX */
599 
600 #if RTE_IOVA_IN_MBUF
601 
605  struct rte_mbuf *next;
606 #else
607 
611  uint64_t dynfield2;
612 #endif
613 
614  /* fields to support TX offloads */
615  union {
616  uint64_t tx_offload;
617  __extension__
618  struct {
619  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
623  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
625  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
627  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
630  /*
631  * Fields for Tx offloading of tunnels.
632  * These are undefined for packets which don't request
633  * any tunnel offloads (outer IP or UDP checksum,
634  * tunnel TSO).
635  *
636  * PMDs should not use these fields unconditionally
637  * when calculating offsets.
638  *
639  * Applications are expected to set appropriate tunnel
640  * offload flags when they fill in these fields.
641  */
642  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
644  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
647  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
648  };
649  };
650 
655 
659  uint16_t priv_size;
660 
662  uint16_t timesync;
663 
664  uint32_t dynfield1[9];
666 
670 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
671 
677  void *fcb_opaque;
678  RTE_ATOMIC(uint16_t) refcnt;
679 };
680 
682 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
683 
691 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
692 
698 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
699 
706 #define RTE_MBUF_DIRECT(mb) \
707  (!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
708 
710 #define RTE_MBUF_PORT_INVALID UINT16_MAX
711 
712 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
713 
728 #define rte_pktmbuf_mtod_offset(m, t, o) \
729  ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
730 
743 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
744 
754 #define rte_pktmbuf_iova_offset(m, o) \
755  (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
756 
764 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
765 
766 #ifdef __cplusplus
767 }
768 #endif
769 
770 #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
#define __rte_cache_min_aligned
Definition: rte_common.h:548
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:576
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
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:584
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
__extension__ typedef uint64_t RTE_MARKER64[0]
Definition: rte_common.h:592
uint64_t ol_flags
uint32_t pkt_len
uint16_t buf_len
uint32_t packet_type
uint8_t inner_l3_type
#define __rte_cache_aligned
Definition: rte_common.h:544
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
#define __rte_aligned(a)
Definition: rte_common.h:71