DPDK 25.11.0-rc3
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
26extern "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(), rte_get_rx_ol_flag_list(),
41 * rte_get_tx_ol_flag_name(), and rte_get_tx_ol_flag_list().
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/*
184 * Add new Rx flags here.
185 * Don't forget to update RTE_MBUF_F_FIRST_FREE,
186 * rte_get_rx_ol_flag_name(), and rte_get_rx_ol_flag_list().
187 */
188
189#define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
190#define RTE_MBUF_F_LAST_FREE (1ULL << 40)
191
192/*
193 * Add new Tx flags here.
194 * Don't forget to update RTE_MBUF_F_LAST_FREE, RTE_MBUF_F_TX_OFFLOAD_MASK,
195 * rte_get_tx_ol_flag_name(), and rte_get_tx_ol_flag_list().
196 */
197
207#define RTE_MBUF_F_TX_OUTER_UDP_CKSUM (1ULL << 41)
208
214#define RTE_MBUF_F_TX_UDP_SEG (1ULL << 42)
215
222#define RTE_MBUF_F_TX_SEC_OFFLOAD (1ULL << 43)
223
228#define RTE_MBUF_F_TX_MACSEC (1ULL << 44)
229
239#define RTE_MBUF_F_TX_TUNNEL_VXLAN (0x1ULL << 45)
240#define RTE_MBUF_F_TX_TUNNEL_GRE (0x2ULL << 45)
241#define RTE_MBUF_F_TX_TUNNEL_IPIP (0x3ULL << 45)
242#define RTE_MBUF_F_TX_TUNNEL_GENEVE (0x4ULL << 45)
244#define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
245#define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
246#define RTE_MBUF_F_TX_TUNNEL_GTP (0x7ULL << 45)
247#define RTE_MBUF_F_TX_TUNNEL_ESP (0x8ULL << 45)
259#define RTE_MBUF_F_TX_TUNNEL_IP (0xDULL << 45)
272#define RTE_MBUF_F_TX_TUNNEL_UDP (0xEULL << 45)
273/* add new TX TUNNEL type here */
274#define RTE_MBUF_F_TX_TUNNEL_MASK (0xFULL << 45)
275
281#define RTE_MBUF_F_TX_QINQ (1ULL << 49)
282
292#define RTE_MBUF_F_TX_TCP_SEG (1ULL << 50)
293
295#define RTE_MBUF_F_TX_IEEE1588_TMST (1ULL << 51)
296
297/*
298 * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
299 * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
300 * L4 checksum offload, the user needs to:
301 * - fill l2_len and l3_len in mbuf
302 * - set the flags RTE_MBUF_F_TX_TCP_CKSUM, RTE_MBUF_F_TX_SCTP_CKSUM or
303 * RTE_MBUF_F_TX_UDP_CKSUM
304 * - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
305 */
306
308#define RTE_MBUF_F_TX_L4_NO_CKSUM (0ULL << 52)
309
311#define RTE_MBUF_F_TX_TCP_CKSUM (1ULL << 52)
312
314#define RTE_MBUF_F_TX_SCTP_CKSUM (2ULL << 52)
315
317#define RTE_MBUF_F_TX_UDP_CKSUM (3ULL << 52)
318
320#define RTE_MBUF_F_TX_L4_MASK (3ULL << 52)
321
328#define RTE_MBUF_F_TX_IP_CKSUM (1ULL << 54)
329
336#define RTE_MBUF_F_TX_IPV4 (1ULL << 55)
337
344#define RTE_MBUF_F_TX_IPV6 (1ULL << 56)
345
351#define RTE_MBUF_F_TX_VLAN (1ULL << 57)
352
359#define RTE_MBUF_F_TX_OUTER_IP_CKSUM (1ULL << 58)
360
366#define RTE_MBUF_F_TX_OUTER_IPV4 (1ULL << 59)
367
373#define RTE_MBUF_F_TX_OUTER_IPV6 (1ULL << 60)
374
379#define RTE_MBUF_F_TX_OFFLOAD_MASK ( \
380 RTE_MBUF_F_TX_OUTER_IPV6 | \
381 RTE_MBUF_F_TX_OUTER_IPV4 | \
382 RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
383 RTE_MBUF_F_TX_VLAN | \
384 RTE_MBUF_F_TX_IPV6 | \
385 RTE_MBUF_F_TX_IPV4 | \
386 RTE_MBUF_F_TX_IP_CKSUM | \
387 RTE_MBUF_F_TX_L4_MASK | \
388 RTE_MBUF_F_TX_IEEE1588_TMST | \
389 RTE_MBUF_F_TX_TCP_SEG | \
390 RTE_MBUF_F_TX_QINQ | \
391 RTE_MBUF_F_TX_TUNNEL_MASK | \
392 RTE_MBUF_F_TX_MACSEC | \
393 RTE_MBUF_F_TX_SEC_OFFLOAD | \
394 RTE_MBUF_F_TX_UDP_SEG | \
395 RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
396
400#define RTE_MBUF_F_EXTERNAL (1ULL << 61)
401
402#define RTE_MBUF_F_INDIRECT (1ULL << 62)
405#define RTE_MBUF_PRIV_ALIGN 8
406
413#define RTE_MBUF_DEFAULT_DATAROOM 2048
414#define RTE_MBUF_DEFAULT_BUF_SIZE \
415 (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
416
418 uint32_t queue_id;
423 uint8_t color;
425 uint16_t reserved;
426};
432enum {
433 RTE_MBUF_L2_LEN_BITS = 7,
434 RTE_MBUF_L3_LEN_BITS = 9,
435 RTE_MBUF_L4_LEN_BITS = 8,
436 RTE_MBUF_TSO_SEGSZ_BITS = 16,
437 RTE_MBUF_OUTL3_LEN_BITS = 9,
438 RTE_MBUF_OUTL2_LEN_BITS = 7,
439 RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
440 RTE_MBUF_L2_LEN_BITS -
441 RTE_MBUF_L3_LEN_BITS -
442 RTE_MBUF_L4_LEN_BITS -
443 RTE_MBUF_TSO_SEGSZ_BITS -
444 RTE_MBUF_OUTL3_LEN_BITS -
445 RTE_MBUF_OUTL2_LEN_BITS,
446#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
447 RTE_MBUF_L2_LEN_OFS =
448 sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
449 RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
450 RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
451 RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
452 RTE_MBUF_OUTL3_LEN_OFS =
453 RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
454 RTE_MBUF_OUTL2_LEN_OFS =
455 RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
456 RTE_MBUF_TXOFLD_UNUSED_OFS =
457 RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
458#else
459 RTE_MBUF_L2_LEN_OFS = 0,
460 RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
461 RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
462 RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
463 RTE_MBUF_OUTL3_LEN_OFS =
464 RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
465 RTE_MBUF_OUTL2_LEN_OFS =
466 RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
467 RTE_MBUF_TXOFLD_UNUSED_OFS =
468 RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
469#endif
470};
471
476 void *buf_addr;
477#if RTE_IOVA_IN_MBUF
486 alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
487#else
493 struct rte_mbuf *next;
494#endif
495
496 /*
497 * Next 8 bytes are initialised on Rx descriptor rearm,
498 * or on Rx when pulling packet from descriptor.
499 */
500 union {
501 uint64_t rearm_data[1];
502 __extension__
503 struct {
504 uint16_t data_off;
505
514 RTE_ATOMIC(uint16_t) refcnt;
515
520 uint16_t nb_segs;
521
525 uint16_t port;
526 };
527 };
528
529 uint64_t ol_flags;
531 /* Remaining 24 bytes are set on Rx when pulling packet from descriptor. */
532 union {
533 /* void * type of the array elements is retained for driver compatibility. */
534 void *rx_descriptor_fields1[24 / sizeof(void *)];
535 __extension__
536 struct {
537 /*
538 * The packet type, which is the combination of outer/inner L2, L3, L4
539 * and tunnel types. The packet_type is about data really present in the
540 * mbuf. Example: if vlan stripping is enabled, a received vlan packet
541 * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
542 * vlan is stripped from the data.
543 */
544 union {
545 uint32_t packet_type;
546 __extension__
547 struct {
548 uint8_t l2_type:4;
549 uint8_t l3_type:4;
550 uint8_t l4_type:4;
551 uint8_t tun_type:4;
552 union {
558 __extension__
559 struct {
560 uint8_t inner_l2_type:4;
562 uint8_t inner_l3_type:4;
564 };
565 };
566 uint8_t inner_l4_type:4;
567 };
568 };
569
570 uint32_t pkt_len;
571 uint16_t data_len;
573 uint16_t vlan_tci;
574
575 union {
576 union {
577 uint32_t rss;
578 struct {
579 union {
580 struct {
581 uint16_t hash;
582 uint16_t id;
583 };
584 uint32_t lo;
586 };
587 uint32_t hi;
591 } fdir;
592 struct rte_mbuf_sched sched;
594 struct {
595 uint32_t reserved1;
596 uint16_t reserved2;
597 uint16_t txq;
602 } txadapter;
603 uint32_t usr;
605 } hash;
606 };
607
610
611 uint16_t buf_len;
612 };
613 };
614
617 /*
618 * Second cache line - fields only used in slow path or on Tx.
619 * In special cases, some of these fields are also set on Rx,
620 * most notably the 'next' field is set on Rx scattered packets.
621 */
622#if RTE_IOVA_IN_MBUF
628 struct rte_mbuf *next;
629#else
635 uint64_t dynfield2;
636#endif
637
638 /* fields to support TX offloads */
639 union {
640 uint64_t tx_offload;
641 __extension__
642 struct {
643 uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
647 uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
649 uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
651 uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
654 /*
655 * Fields for Tx offloading of tunnels.
656 * These are undefined for packets which don't request
657 * any tunnel offloads (outer IP or UDP checksum,
658 * tunnel TSO).
659 *
660 * PMDs should not use these fields unconditionally
661 * when calculating offsets.
662 *
663 * Applications are expected to set appropriate tunnel
664 * offload flags when they fill in these fields.
665 */
666 uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
668 uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
671 /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
672 };
673 };
674
679
683 uint16_t priv_size;
684
686 uint16_t timesync;
687
688 uint32_t dynfield1[9];
689};
690
694typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
695
702 RTE_ATOMIC(uint16_t) refcnt;
703};
704
706#define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
707
715#define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
716
722#define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
723
756#ifdef __DOXYGEN__
757#define RTE_MBUF_DIRECT(mb) \
758 !(((const char *)(&(mb)->ol_flags))[MSB_OFFSET /* 7 or 0, depending on endianness */] & \
759 (char)((RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL) >> (7 * CHAR_BIT)) /* 0x60 */)
760#else /* !__DOXYGEN__ */
761#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
762/* On little endian architecture, the MSB of a 64-bit integer is at byte offset 7. */
763#define RTE_MBUF_DIRECT(mb) !(((const char *)(&(mb)->ol_flags))[7] & 0x60)
764#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
765/* On big endian architecture, the MSB of a 64-bit integer is at byte offset 0. */
766#define RTE_MBUF_DIRECT(mb) !(((const char *)(&(mb)->ol_flags))[0] & 0x60)
767#endif /* RTE_BYTE_ORDER */
768#endif /* !__DOXYGEN__ */
769/* Verify the optimization above. */
770static_assert((RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL) == UINT64_C(0x60) << (7 * CHAR_BIT),
771 "(RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL) is not 0x60 at MSB");
772
774#define RTE_MBUF_PORT_INVALID UINT16_MAX
776#define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
777
792#define rte_pktmbuf_mtod_offset(m, t, o) \
793 ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
794
807#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
808
818#define rte_pktmbuf_iova_offset(m, o) \
819 (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
820
828#define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
829
830#ifdef __cplusplus
831}
832#endif
833
834#endif /* _RTE_MBUF_CORE_H_ */
#define RTE_CACHE_LINE_MIN_SIZE
Definition: rte_common.h:736
uint64_t rte_iova_t
Definition: rte_common.h:770
#define __rte_cache_aligned
Definition: rte_common.h:739
#define RTE_MBUF_F_EXTERNAL
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
#define RTE_MBUF_F_INDIRECT
rte_mbuf_extbuf_free_callback_t free_cb
uint16_t reserved
uint32_t queue_id
uint8_t traffic_class
uint8_t inner_l2_type
uint64_t ol_flags
uint64_t l4_len
uint16_t nb_segs
uint16_t vlan_tci
uint16_t txq
uint16_t priv_size
uint32_t pkt_len
uint8_t tun_type
uint8_t l3_type
uint16_t timesync
uint32_t usr
uint16_t buf_len
uint64_t l3_len
struct rte_mbuf_ext_shared_info * shinfo
uint8_t inner_l4_type
uint32_t packet_type
uint16_t port
uint8_t inner_l3_type
void * buf_addr
uint64_t l2_len
uint32_t rss
struct rte_mempool * pool
uint32_t hi
uint64_t outer_l3_len
uint8_t l4_type
uint16_t vlan_tci_outer
struct rte_mbuf * next
uint64_t tx_offload
uint16_t data_len
uint64_t tso_segsz
uint8_t inner_esp_next_proto
uint8_t l2_type
uint64_t outer_l2_len
uint16_t refcnt
uint32_t lo