DPDK  20.11.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 <stdint.h>
20 #include <rte_compat.h>
21 #include <generic/rte_atomic.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 PKT_RX_VLAN (1ULL << 0)
50 
52 #define PKT_RX_RSS_HASH (1ULL << 1)
53 
55 #define PKT_RX_FDIR (1ULL << 2)
56 
64 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
65 
73 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
74 
76 #define PKT_RX_EIP_CKSUM_BAD (1ULL << 5)
77 
84 #define PKT_RX_VLAN_STRIPPED (1ULL << 6)
85 
94 #define PKT_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
95 
96 #define PKT_RX_IP_CKSUM_UNKNOWN 0
97 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
98 #define PKT_RX_IP_CKSUM_GOOD (1ULL << 7)
99 #define PKT_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
100 
109 #define PKT_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
110 
111 #define PKT_RX_L4_CKSUM_UNKNOWN 0
112 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
113 #define PKT_RX_L4_CKSUM_GOOD (1ULL << 8)
114 #define PKT_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
115 
117 #define PKT_RX_IEEE1588_PTP (1ULL << 9)
118 
120 #define PKT_RX_IEEE1588_TMST (1ULL << 10)
121 
123 #define PKT_RX_FDIR_ID (1ULL << 13)
124 
126 #define PKT_RX_FDIR_FLX (1ULL << 14)
127 
143 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
144 
150 #define PKT_RX_LRO (1ULL << 16)
151 
152 /* There is no flag defined at offset 17. It is free for any future use. */
153 
157 #define PKT_RX_SEC_OFFLOAD (1ULL << 18)
158 
162 #define PKT_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
163 
172 #define PKT_RX_QINQ (1ULL << 20)
173 
186 #define PKT_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
187 
188 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN 0
189 #define PKT_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
190 #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
191 #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
192 
193 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
194 
195 #define PKT_FIRST_FREE (1ULL << 23)
196 #define PKT_LAST_FREE (1ULL << 40)
197 
198 /* add new TX flags here, don't forget to update PKT_LAST_FREE */
199 
209 #define PKT_TX_OUTER_UDP_CKSUM (1ULL << 41)
210 
216 #define PKT_TX_UDP_SEG (1ULL << 42)
217 
221 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
222 
227 #define PKT_TX_MACSEC (1ULL << 44)
228 
237 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
238 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
239 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
240 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
242 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
243 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
244 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
256 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
269 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
270 /* add new TX TUNNEL type here */
271 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
272 
278 #define PKT_TX_QINQ (1ULL << 49)
280 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
281 
291 #define PKT_TX_TCP_SEG (1ULL << 50)
292 
294 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
295 
304 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
307 #define PKT_TX_TCP_CKSUM (1ULL << 52)
308 
310 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
311 
313 #define PKT_TX_UDP_CKSUM (3ULL << 52)
314 
316 #define PKT_TX_L4_MASK (3ULL << 52)
317 
324 #define PKT_TX_IP_CKSUM (1ULL << 54)
325 
332 #define PKT_TX_IPV4 (1ULL << 55)
333 
340 #define PKT_TX_IPV6 (1ULL << 56)
341 
347 #define PKT_TX_VLAN (1ULL << 57)
348 /* this old name is deprecated */
349 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
350 
357 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
358 
364 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
365 
371 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
372 
377 #define PKT_TX_OFFLOAD_MASK ( \
378  PKT_TX_OUTER_IPV6 | \
379  PKT_TX_OUTER_IPV4 | \
380  PKT_TX_OUTER_IP_CKSUM | \
381  PKT_TX_VLAN_PKT | \
382  PKT_TX_IPV6 | \
383  PKT_TX_IPV4 | \
384  PKT_TX_IP_CKSUM | \
385  PKT_TX_L4_MASK | \
386  PKT_TX_IEEE1588_TMST | \
387  PKT_TX_TCP_SEG | \
388  PKT_TX_QINQ_PKT | \
389  PKT_TX_TUNNEL_MASK | \
390  PKT_TX_MACSEC | \
391  PKT_TX_SEC_OFFLOAD | \
392  PKT_TX_UDP_SEG | \
393  PKT_TX_OUTER_UDP_CKSUM)
394 
398 #define EXT_ATTACHED_MBUF (1ULL << 61)
399 
400 #define IND_ATTACHED_MBUF (1ULL << 62)
403 #define RTE_MBUF_PRIV_ALIGN 8
404 
411 #define RTE_MBUF_DEFAULT_DATAROOM 2048
412 #define RTE_MBUF_DEFAULT_BUF_SIZE \
413  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
414 
416  uint32_t queue_id;
417  uint8_t traffic_class;
421  uint8_t color;
423  uint16_t reserved;
424 };
430 enum {
431  RTE_MBUF_L2_LEN_BITS = 7,
432  RTE_MBUF_L3_LEN_BITS = 9,
433  RTE_MBUF_L4_LEN_BITS = 8,
434  RTE_MBUF_TSO_SEGSZ_BITS = 16,
435  RTE_MBUF_OUTL3_LEN_BITS = 9,
436  RTE_MBUF_OUTL2_LEN_BITS = 7,
437  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
438  RTE_MBUF_L2_LEN_BITS -
439  RTE_MBUF_L3_LEN_BITS -
440  RTE_MBUF_L4_LEN_BITS -
441  RTE_MBUF_TSO_SEGSZ_BITS -
442  RTE_MBUF_OUTL3_LEN_BITS -
443  RTE_MBUF_OUTL2_LEN_BITS,
444 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
445  RTE_MBUF_L2_LEN_OFS =
446  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
447  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
448  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
449  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
450  RTE_MBUF_OUTL3_LEN_OFS =
451  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
452  RTE_MBUF_OUTL2_LEN_OFS =
453  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
454  RTE_MBUF_TXOFLD_UNUSED_OFS =
455  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
456 #else
457  RTE_MBUF_L2_LEN_OFS = 0,
458  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
459  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
460  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
461  RTE_MBUF_OUTL3_LEN_OFS =
462  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
463  RTE_MBUF_OUTL2_LEN_OFS =
464  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
465  RTE_MBUF_TXOFLD_UNUSED_OFS =
466  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
467 #endif
468 };
469 
473 struct rte_mbuf {
474  RTE_MARKER cacheline0;
475 
476  void *buf_addr;
484 
485  /* next 8 bytes are initialised on RX descriptor rearm */
486  RTE_MARKER64 rearm_data;
487  uint16_t data_off;
488 
497  uint16_t refcnt;
498  uint16_t nb_segs;
503  uint16_t port;
504 
505  uint64_t ol_flags;
507  /* remaining bytes are set on RX when pulling packet from descriptor */
508  RTE_MARKER rx_descriptor_fields1;
509 
510  /*
511  * The packet type, which is the combination of outer/inner L2, L3, L4
512  * and tunnel types. The packet_type is about data really present in the
513  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
514  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
515  * vlan is stripped from the data.
516  */
518  union {
519  uint32_t packet_type;
520  __extension__
521  struct {
522  uint8_t l2_type:4;
523  uint8_t l3_type:4;
524  uint8_t l4_type:4;
525  uint8_t tun_type:4;
527  union {
533  __extension__
534  struct {
535  uint8_t inner_l2_type:4;
537  uint8_t inner_l3_type:4;
539  };
540  };
541  uint8_t inner_l4_type:4;
542  };
543  };
544 
545  uint32_t pkt_len;
546  uint16_t data_len;
548  uint16_t vlan_tci;
549 
551  union {
552  union {
553  uint32_t rss;
554  struct {
555  union {
556  struct {
557  uint16_t hash;
558  uint16_t id;
559  };
560  uint32_t lo;
562  };
563  uint32_t hi;
567  } fdir;
568  struct rte_mbuf_sched sched;
570  struct {
571  uint32_t reserved1;
572  uint16_t reserved2;
573  uint16_t txq;
578  } txadapter;
580  uint32_t usr;
581  } hash;
582  };
583 
585  uint16_t vlan_tci_outer;
586 
587  uint16_t buf_len;
589  struct rte_mempool *pool;
591  /* second cache line - fields only used in slow path or on TX */
593 
594  struct rte_mbuf *next;
596  /* fields to support TX offloads */
598  union {
599  uint64_t tx_offload;
600  __extension__
601  struct {
602  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
606  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
608  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
610  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
613  /*
614  * Fields for Tx offloading of tunnels.
615  * These are undefined for packets which don't request
616  * any tunnel offloads (outer IP or UDP checksum,
617  * tunnel TSO).
618  *
619  * PMDs should not use these fields unconditionally
620  * when calculating offsets.
621  *
622  * Applications are expected to set appropriate tunnel
623  * offload flags when they fill in these fields.
624  */
625  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
627  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
630  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
631  };
632  };
633 
638 
642  uint16_t priv_size;
643 
645  uint16_t timesync;
646 
647  uint32_t dynfield1[9];
649 
653 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
654 
660  void *fcb_opaque;
661  uint16_t refcnt;
662 };
663 
665 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
666 
674 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
675 
681 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
682 
689 #define RTE_MBUF_DIRECT(mb) \
690  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
691 
693 #define RTE_MBUF_PORT_INVALID UINT16_MAX
695 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
696 
711 #define rte_pktmbuf_mtod_offset(m, t, o) \
712  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
713 
726 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
727 
737 #define rte_pktmbuf_iova_offset(m, o) \
738  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
739 
747 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
748 
749 #ifdef __cplusplus
750 }
751 #endif
752 
753 #endif /* _RTE_MBUF_CORE_H_ */
__extension__ typedef uint64_t RTE_MARKER64[0]
Definition: rte_common.h:432
#define __rte_cache_min_aligned
Definition: rte_common.h:403
#define __rte_cache_aligned
Definition: rte_common.h:400
uint64_t rte_iova_t
Definition: rte_common.h:418
#define RTE_STD_C11
Definition: rte_common.h:40
__extension__ typedef void * RTE_MARKER[0]
Definition: rte_common.h:424
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
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
struct rte_mbuf_sched sched
uint8_t l3_type
uint16_t timesync
uint16_t buf_len
struct rte_mbuf::@239::@249::@251 txadapter
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
struct rte_mbuf::@239::@249::@250 fdir
void * buf_addr
uint64_t l2_len
uint32_t rss
struct rte_mempool * pool
uint32_t hi
uint32_t dynfield1[9]
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
rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t))
uint32_t lo