DPDK  22.11.5
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 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /*
28  * Packet Offload Features Flags. It also carry packet type information.
29  * Critical resources. Both rx/tx shared these bits. Be cautious on any change
30  *
31  * - RX flags start at bit position zero, and get added to the left of previous
32  * flags.
33  * - The most-significant 3 bits are reserved for generic mbuf flags
34  * - TX flags therefore start at bit position 60 (i.e. 63-3), and new flags get
35  * added to the right of the previously defined flags i.e. they should count
36  * downwards, not upwards.
37  *
38  * Keep these flags synchronized with rte_get_rx_ol_flag_name() and
39  * rte_get_tx_ol_flag_name().
40  */
41 
49 #define RTE_MBUF_F_RX_VLAN (1ULL << 0)
50 
52 #define RTE_MBUF_F_RX_RSS_HASH (1ULL << 1)
53 
55 #define RTE_MBUF_F_RX_FDIR (1ULL << 2)
56 
61 #define RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
62 
69 #define RTE_MBUF_F_RX_VLAN_STRIPPED (1ULL << 6)
70 
79 #define RTE_MBUF_F_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
80 
81 #define RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN 0
82 #define RTE_MBUF_F_RX_IP_CKSUM_BAD (1ULL << 4)
83 #define RTE_MBUF_F_RX_IP_CKSUM_GOOD (1ULL << 7)
84 #define RTE_MBUF_F_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
85 
94 #define RTE_MBUF_F_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
95 
96 #define RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN 0
97 #define RTE_MBUF_F_RX_L4_CKSUM_BAD (1ULL << 3)
98 #define RTE_MBUF_F_RX_L4_CKSUM_GOOD (1ULL << 8)
99 #define RTE_MBUF_F_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
100 
102 #define RTE_MBUF_F_RX_IEEE1588_PTP (1ULL << 9)
103 
105 #define RTE_MBUF_F_RX_IEEE1588_TMST (1ULL << 10)
106 
108 #define RTE_MBUF_F_RX_FDIR_ID (1ULL << 13)
109 
111 #define RTE_MBUF_F_RX_FDIR_FLX (1ULL << 14)
112 
128 #define RTE_MBUF_F_RX_QINQ_STRIPPED (1ULL << 15)
129 
135 #define RTE_MBUF_F_RX_LRO (1ULL << 16)
136 
137 /* There is no flag defined at offset 17. It is free for any future use. */
138 
142 #define RTE_MBUF_F_RX_SEC_OFFLOAD (1ULL << 18)
143 
147 #define RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
148 
157 #define RTE_MBUF_F_RX_QINQ (1ULL << 20)
158 
174 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
175 
176 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN 0
177 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
178 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
179 #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
180 
181 /* add new RX flags here, don't forget to update RTE_MBUF_F_FIRST_FREE */
182 
183 #define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
184 #define RTE_MBUF_F_LAST_FREE (1ULL << 40)
185 
186 /* add new TX flags here, don't forget to update RTE_MBUF_F_LAST_FREE */
187 
197 #define RTE_MBUF_F_TX_OUTER_UDP_CKSUM (1ULL << 41)
198 
204 #define RTE_MBUF_F_TX_UDP_SEG (1ULL << 42)
205 
212 #define RTE_MBUF_F_TX_SEC_OFFLOAD (1ULL << 43)
213 
218 #define RTE_MBUF_F_TX_MACSEC (1ULL << 44)
219 
229 #define RTE_MBUF_F_TX_TUNNEL_VXLAN (0x1ULL << 45)
230 #define RTE_MBUF_F_TX_TUNNEL_GRE (0x2ULL << 45)
231 #define RTE_MBUF_F_TX_TUNNEL_IPIP (0x3ULL << 45)
232 #define RTE_MBUF_F_TX_TUNNEL_GENEVE (0x4ULL << 45)
233 
234 #define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
235 #define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
236 #define RTE_MBUF_F_TX_TUNNEL_GTP (0x7ULL << 45)
237 #define RTE_MBUF_F_TX_TUNNEL_ESP (0x8ULL << 45)
238 
249 #define RTE_MBUF_F_TX_TUNNEL_IP (0xDULL << 45)
250 
262 #define RTE_MBUF_F_TX_TUNNEL_UDP (0xEULL << 45)
263 /* add new TX TUNNEL type here */
264 #define RTE_MBUF_F_TX_TUNNEL_MASK (0xFULL << 45)
265 
271 #define RTE_MBUF_F_TX_QINQ (1ULL << 49)
272 
282 #define RTE_MBUF_F_TX_TCP_SEG (1ULL << 50)
283 
285 #define RTE_MBUF_F_TX_IEEE1588_TMST (1ULL << 51)
286 
287 /*
288  * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
289  * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
290  * L4 checksum offload, the user needs to:
291  * - fill l2_len and l3_len in mbuf
292  * - set the flags RTE_MBUF_F_TX_TCP_CKSUM, RTE_MBUF_F_TX_SCTP_CKSUM or
293  * RTE_MBUF_F_TX_UDP_CKSUM
294  * - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
295  */
296 
298 #define RTE_MBUF_F_TX_L4_NO_CKSUM (0ULL << 52)
299 
301 #define RTE_MBUF_F_TX_TCP_CKSUM (1ULL << 52)
302 
304 #define RTE_MBUF_F_TX_SCTP_CKSUM (2ULL << 52)
305 
307 #define RTE_MBUF_F_TX_UDP_CKSUM (3ULL << 52)
308 
310 #define RTE_MBUF_F_TX_L4_MASK (3ULL << 52)
311 
318 #define RTE_MBUF_F_TX_IP_CKSUM (1ULL << 54)
319 
326 #define RTE_MBUF_F_TX_IPV4 (1ULL << 55)
327 
334 #define RTE_MBUF_F_TX_IPV6 (1ULL << 56)
335 
341 #define RTE_MBUF_F_TX_VLAN (1ULL << 57)
342 
349 #define RTE_MBUF_F_TX_OUTER_IP_CKSUM (1ULL << 58)
350 
356 #define RTE_MBUF_F_TX_OUTER_IPV4 (1ULL << 59)
357 
363 #define RTE_MBUF_F_TX_OUTER_IPV6 (1ULL << 60)
364 
369 #define RTE_MBUF_F_TX_OFFLOAD_MASK ( \
370  RTE_MBUF_F_TX_OUTER_IPV6 | \
371  RTE_MBUF_F_TX_OUTER_IPV4 | \
372  RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
373  RTE_MBUF_F_TX_VLAN | \
374  RTE_MBUF_F_TX_IPV6 | \
375  RTE_MBUF_F_TX_IPV4 | \
376  RTE_MBUF_F_TX_IP_CKSUM | \
377  RTE_MBUF_F_TX_L4_MASK | \
378  RTE_MBUF_F_TX_IEEE1588_TMST | \
379  RTE_MBUF_F_TX_TCP_SEG | \
380  RTE_MBUF_F_TX_QINQ | \
381  RTE_MBUF_F_TX_TUNNEL_MASK | \
382  RTE_MBUF_F_TX_MACSEC | \
383  RTE_MBUF_F_TX_SEC_OFFLOAD | \
384  RTE_MBUF_F_TX_UDP_SEG | \
385  RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
386 
390 #define RTE_MBUF_F_EXTERNAL (1ULL << 61)
391 
392 #define RTE_MBUF_F_INDIRECT (1ULL << 62)
395 #define RTE_MBUF_PRIV_ALIGN 8
396 
403 #define RTE_MBUF_DEFAULT_DATAROOM 2048
404 #define RTE_MBUF_DEFAULT_BUF_SIZE \
405  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
406 
408  uint32_t queue_id;
409  uint8_t traffic_class;
413  uint8_t color;
415  uint16_t reserved;
416 };
422 enum {
423  RTE_MBUF_L2_LEN_BITS = 7,
424  RTE_MBUF_L3_LEN_BITS = 9,
425  RTE_MBUF_L4_LEN_BITS = 8,
426  RTE_MBUF_TSO_SEGSZ_BITS = 16,
427  RTE_MBUF_OUTL3_LEN_BITS = 9,
428  RTE_MBUF_OUTL2_LEN_BITS = 7,
429  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
430  RTE_MBUF_L2_LEN_BITS -
431  RTE_MBUF_L3_LEN_BITS -
432  RTE_MBUF_L4_LEN_BITS -
433  RTE_MBUF_TSO_SEGSZ_BITS -
434  RTE_MBUF_OUTL3_LEN_BITS -
435  RTE_MBUF_OUTL2_LEN_BITS,
436 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
437  RTE_MBUF_L2_LEN_OFS =
438  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
439  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
440  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
441  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
442  RTE_MBUF_OUTL3_LEN_OFS =
443  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
444  RTE_MBUF_OUTL2_LEN_OFS =
445  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
446  RTE_MBUF_TXOFLD_UNUSED_OFS =
447  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
448 #else
449  RTE_MBUF_L2_LEN_OFS = 0,
450  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
451  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
452  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
453  RTE_MBUF_OUTL3_LEN_OFS =
454  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
455  RTE_MBUF_OUTL2_LEN_OFS =
456  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
457  RTE_MBUF_TXOFLD_UNUSED_OFS =
458  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
459 #endif
460 };
461 
465 struct rte_mbuf {
466  RTE_MARKER cacheline0;
467 
468  void *buf_addr;
469 #if RTE_IOVA_AS_PA
470 
478  rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
479 #else
480 
485  struct rte_mbuf *next;
486 #endif
487 
488  /* next 8 bytes are initialised on RX descriptor rearm */
489  RTE_MARKER64 rearm_data;
490  uint16_t data_off;
491 
500  uint16_t refcnt;
501 
506  uint16_t nb_segs;
507 
511  uint16_t port;
512 
513  uint64_t ol_flags;
515  /* remaining bytes are set on RX when pulling packet from descriptor */
516  RTE_MARKER rx_descriptor_fields1;
517 
518  /*
519  * The packet type, which is the combination of outer/inner L2, L3, L4
520  * and tunnel types. The packet_type is about data really present in the
521  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
522  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
523  * vlan is stripped from the data.
524  */
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;
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 
559  union {
560  union {
561  uint32_t rss;
562  struct {
563  union {
564  struct {
565  uint16_t hash;
566  uint16_t id;
567  };
568  uint32_t lo;
570  };
571  uint32_t hi;
575  } fdir;
576  struct rte_mbuf_sched sched;
578  struct {
579  uint32_t reserved1;
580  uint16_t reserved2;
581  uint16_t txq;
586  } txadapter;
587  uint32_t usr;
589  } hash;
590  };
591 
593  uint16_t vlan_tci_outer;
594 
595  uint16_t buf_len;
597  struct rte_mempool *pool;
599  /* second cache line - fields only used in slow path or on TX */
601 
602 #if RTE_IOVA_AS_PA
603 
607  struct rte_mbuf *next;
608 #else
609 
613  uint64_t dynfield2;
614 #endif
615 
616  /* fields to support TX offloads */
618  union {
619  uint64_t tx_offload;
620  __extension__
621  struct {
622  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
626  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
628  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
630  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
633  /*
634  * Fields for Tx offloading of tunnels.
635  * These are undefined for packets which don't request
636  * any tunnel offloads (outer IP or UDP checksum,
637  * tunnel TSO).
638  *
639  * PMDs should not use these fields unconditionally
640  * when calculating offsets.
641  *
642  * Applications are expected to set appropriate tunnel
643  * offload flags when they fill in these fields.
644  */
645  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
647  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
650  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
651  };
652  };
653 
658 
662  uint16_t priv_size;
663 
665  uint16_t timesync;
666 
667  uint32_t dynfield1[9];
669 
673 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
674 
680  void *fcb_opaque;
681  uint16_t refcnt;
682 };
683 
685 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
686 
694 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
695 
701 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
702 
709 #define RTE_MBUF_DIRECT(mb) \
710  (!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
711 
713 #define RTE_MBUF_PORT_INVALID UINT16_MAX
714 
715 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
716 
731 #define rte_pktmbuf_mtod_offset(m, t, o) \
732  ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
733 
746 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
747 
757 #define rte_pktmbuf_iova_offset(m, o) \
758  (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
759 
767 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
768 
769 #ifdef __cplusplus
770 }
771 #endif
772 
773 #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
#define __rte_cache_min_aligned
Definition: rte_common.h:443
uint8_t l3_type
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:458
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:464
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:472
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:440
uint8_t l4_type
#define RTE_STD_C11
Definition: rte_common.h:39
struct rte_mempool * pool
uint32_t rss
__extension__ struct rte_eth_link __rte_aligned(8)
uint16_t reserved
uint8_t traffic_class
uint64_t tx_offload
uint16_t vlan_tci
uint8_t tun_type
uint32_t usr