DPDK  21.11.0-rc0
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_compat.h>
22 #include <rte_byteorder.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 PKT_RX_VLAN (1ULL << 0)
51 
53 #define PKT_RX_RSS_HASH (1ULL << 1)
54 
56 #define PKT_RX_FDIR (1ULL << 2)
57 
65 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
66 
74 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
75 
80 #define PKT_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
81 
86 #define PKT_RX_EIP_CKSUM_BAD \
87  RTE_DEPRECATED(PKT_RX_EIP_CKSUM_BAD) PKT_RX_OUTER_IP_CKSUM_BAD
88 
95 #define PKT_RX_VLAN_STRIPPED (1ULL << 6)
96 
105 #define PKT_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
106 
107 #define PKT_RX_IP_CKSUM_UNKNOWN 0
108 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
109 #define PKT_RX_IP_CKSUM_GOOD (1ULL << 7)
110 #define PKT_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
111 
120 #define PKT_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
121 
122 #define PKT_RX_L4_CKSUM_UNKNOWN 0
123 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
124 #define PKT_RX_L4_CKSUM_GOOD (1ULL << 8)
125 #define PKT_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
126 
128 #define PKT_RX_IEEE1588_PTP (1ULL << 9)
129 
131 #define PKT_RX_IEEE1588_TMST (1ULL << 10)
132 
134 #define PKT_RX_FDIR_ID (1ULL << 13)
135 
137 #define PKT_RX_FDIR_FLX (1ULL << 14)
138 
154 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
155 
161 #define PKT_RX_LRO (1ULL << 16)
162 
163 /* There is no flag defined at offset 17. It is free for any future use. */
164 
168 #define PKT_RX_SEC_OFFLOAD (1ULL << 18)
169 
173 #define PKT_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
174 
183 #define PKT_RX_QINQ (1ULL << 20)
184 
197 #define PKT_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
198 
199 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN 0
200 #define PKT_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
201 #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
202 #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
203 
204 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
205 
206 #define PKT_FIRST_FREE (1ULL << 23)
207 #define PKT_LAST_FREE (1ULL << 40)
208 
209 /* add new TX flags here, don't forget to update PKT_LAST_FREE */
210 
220 #define PKT_TX_OUTER_UDP_CKSUM (1ULL << 41)
221 
227 #define PKT_TX_UDP_SEG (1ULL << 42)
228 
234 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
235 
240 #define PKT_TX_MACSEC (1ULL << 44)
241 
250 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
251 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
252 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
253 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
254 
255 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
256 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
257 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
258 
269 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
270 
282 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
283 /* add new TX TUNNEL type here */
284 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
285 
291 #define PKT_TX_QINQ (1ULL << 49)
292 
293 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
294 
304 #define PKT_TX_TCP_SEG (1ULL << 50)
305 
307 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
308 
317 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
320 #define PKT_TX_TCP_CKSUM (1ULL << 52)
321 
323 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
324 
326 #define PKT_TX_UDP_CKSUM (3ULL << 52)
327 
329 #define PKT_TX_L4_MASK (3ULL << 52)
330 
337 #define PKT_TX_IP_CKSUM (1ULL << 54)
338 
345 #define PKT_TX_IPV4 (1ULL << 55)
346 
353 #define PKT_TX_IPV6 (1ULL << 56)
354 
360 #define PKT_TX_VLAN (1ULL << 57)
361 /* this old name is deprecated */
362 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
363 
370 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
371 
377 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
378 
384 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
385 
390 #define PKT_TX_OFFLOAD_MASK ( \
391  PKT_TX_OUTER_IPV6 | \
392  PKT_TX_OUTER_IPV4 | \
393  PKT_TX_OUTER_IP_CKSUM | \
394  PKT_TX_VLAN_PKT | \
395  PKT_TX_IPV6 | \
396  PKT_TX_IPV4 | \
397  PKT_TX_IP_CKSUM | \
398  PKT_TX_L4_MASK | \
399  PKT_TX_IEEE1588_TMST | \
400  PKT_TX_TCP_SEG | \
401  PKT_TX_QINQ_PKT | \
402  PKT_TX_TUNNEL_MASK | \
403  PKT_TX_MACSEC | \
404  PKT_TX_SEC_OFFLOAD | \
405  PKT_TX_UDP_SEG | \
406  PKT_TX_OUTER_UDP_CKSUM)
407 
411 #define EXT_ATTACHED_MBUF (1ULL << 61)
412 
413 #define IND_ATTACHED_MBUF (1ULL << 62)
416 #define RTE_MBUF_PRIV_ALIGN 8
417 
424 #define RTE_MBUF_DEFAULT_DATAROOM 2048
425 #define RTE_MBUF_DEFAULT_BUF_SIZE \
426  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
427 
429  uint32_t queue_id;
430  uint8_t traffic_class;
434  uint8_t color;
436  uint16_t reserved;
437 };
443 enum {
444  RTE_MBUF_L2_LEN_BITS = 7,
445  RTE_MBUF_L3_LEN_BITS = 9,
446  RTE_MBUF_L4_LEN_BITS = 8,
447  RTE_MBUF_TSO_SEGSZ_BITS = 16,
448  RTE_MBUF_OUTL3_LEN_BITS = 9,
449  RTE_MBUF_OUTL2_LEN_BITS = 7,
450  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
451  RTE_MBUF_L2_LEN_BITS -
452  RTE_MBUF_L3_LEN_BITS -
453  RTE_MBUF_L4_LEN_BITS -
454  RTE_MBUF_TSO_SEGSZ_BITS -
455  RTE_MBUF_OUTL3_LEN_BITS -
456  RTE_MBUF_OUTL2_LEN_BITS,
457 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
458  RTE_MBUF_L2_LEN_OFS =
459  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
460  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
461  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
462  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
463  RTE_MBUF_OUTL3_LEN_OFS =
464  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
465  RTE_MBUF_OUTL2_LEN_OFS =
466  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
467  RTE_MBUF_TXOFLD_UNUSED_OFS =
468  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
469 #else
470  RTE_MBUF_L2_LEN_OFS = 0,
471  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
472  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
473  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
474  RTE_MBUF_OUTL3_LEN_OFS =
475  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
476  RTE_MBUF_OUTL2_LEN_OFS =
477  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
478  RTE_MBUF_TXOFLD_UNUSED_OFS =
479  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
480 #endif
481 };
482 
486 struct rte_mbuf {
487  RTE_MARKER cacheline0;
488 
489  void *buf_addr;
496  rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
497 
498  /* next 8 bytes are initialised on RX descriptor rearm */
499  RTE_MARKER64 rearm_data;
500  uint16_t data_off;
501 
510  uint16_t refcnt;
511  uint16_t nb_segs;
516  uint16_t port;
517 
518  uint64_t ol_flags;
520  /* remaining bytes are set on RX when pulling packet from descriptor */
521  RTE_MARKER rx_descriptor_fields1;
522 
523  /*
524  * The packet type, which is the combination of outer/inner L2, L3, L4
525  * and tunnel types. The packet_type is about data really present in the
526  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
527  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
528  * vlan is stripped from the data.
529  */
531  union {
532  uint32_t packet_type;
533  __extension__
534  struct {
535  uint8_t l2_type:4;
536  uint8_t l3_type:4;
537  uint8_t l4_type:4;
538  uint8_t tun_type:4;
540  union {
546  __extension__
547  struct {
548  uint8_t inner_l2_type:4;
550  uint8_t inner_l3_type:4;
552  };
553  };
554  uint8_t inner_l4_type:4;
555  };
556  };
557 
558  uint32_t pkt_len;
559  uint16_t data_len;
561  uint16_t vlan_tci;
562 
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;
593  uint32_t usr;
594  } hash;
595  };
596 
598  uint16_t vlan_tci_outer;
599 
600  uint16_t buf_len;
602  struct rte_mempool *pool;
604  /* second cache line - fields only used in slow path or on TX */
606 
607  struct rte_mbuf *next;
609  /* fields to support TX offloads */
611  union {
612  uint64_t tx_offload;
613  __extension__
614  struct {
615  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
619  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
621  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
623  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
626  /*
627  * Fields for Tx offloading of tunnels.
628  * These are undefined for packets which don't request
629  * any tunnel offloads (outer IP or UDP checksum,
630  * tunnel TSO).
631  *
632  * PMDs should not use these fields unconditionally
633  * when calculating offsets.
634  *
635  * Applications are expected to set appropriate tunnel
636  * offload flags when they fill in these fields.
637  */
638  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
640  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
643  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
644  };
645  };
646 
651 
655  uint16_t priv_size;
656 
658  uint16_t timesync;
659 
660  uint32_t dynfield1[9];
662 
666 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
667 
673  void *fcb_opaque;
674  uint16_t refcnt;
675 };
676 
678 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
679 
687 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
688 
694 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
695 
702 #define RTE_MBUF_DIRECT(mb) \
703  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
704 
706 #define RTE_MBUF_PORT_INVALID UINT16_MAX
707 
708 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
709 
724 #define rte_pktmbuf_mtod_offset(m, t, o) \
725  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
726 
739 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
740 
750 #define rte_pktmbuf_iova_offset(m, o) \
751  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
752 
760 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
761 
762 #ifdef __cplusplus
763 }
764 #endif
765 
766 #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:405
uint8_t l3_type
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:420
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:426
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
__extension__ typedef uint64_t RTE_MARKER64[0]
Definition: rte_common.h:434
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:402
uint8_t l4_type
#define RTE_STD_C11
Definition: rte_common.h:42
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