DPDK  21.05.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 <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 
232 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
233 
238 #define PKT_TX_MACSEC (1ULL << 44)
239 
248 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
249 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
250 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
251 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
252 
253 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
254 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
255 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
256 
267 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
268 
280 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
281 /* add new TX TUNNEL type here */
282 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
283 
289 #define PKT_TX_QINQ (1ULL << 49)
290 
291 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
292 
302 #define PKT_TX_TCP_SEG (1ULL << 50)
303 
305 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
306 
315 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
318 #define PKT_TX_TCP_CKSUM (1ULL << 52)
319 
321 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
322 
324 #define PKT_TX_UDP_CKSUM (3ULL << 52)
325 
327 #define PKT_TX_L4_MASK (3ULL << 52)
328 
335 #define PKT_TX_IP_CKSUM (1ULL << 54)
336 
343 #define PKT_TX_IPV4 (1ULL << 55)
344 
351 #define PKT_TX_IPV6 (1ULL << 56)
352 
358 #define PKT_TX_VLAN (1ULL << 57)
359 /* this old name is deprecated */
360 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
361 
368 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
369 
375 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
376 
382 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
383 
388 #define PKT_TX_OFFLOAD_MASK ( \
389  PKT_TX_OUTER_IPV6 | \
390  PKT_TX_OUTER_IPV4 | \
391  PKT_TX_OUTER_IP_CKSUM | \
392  PKT_TX_VLAN_PKT | \
393  PKT_TX_IPV6 | \
394  PKT_TX_IPV4 | \
395  PKT_TX_IP_CKSUM | \
396  PKT_TX_L4_MASK | \
397  PKT_TX_IEEE1588_TMST | \
398  PKT_TX_TCP_SEG | \
399  PKT_TX_QINQ_PKT | \
400  PKT_TX_TUNNEL_MASK | \
401  PKT_TX_MACSEC | \
402  PKT_TX_SEC_OFFLOAD | \
403  PKT_TX_UDP_SEG | \
404  PKT_TX_OUTER_UDP_CKSUM)
405 
409 #define EXT_ATTACHED_MBUF (1ULL << 61)
410 
411 #define IND_ATTACHED_MBUF (1ULL << 62)
414 #define RTE_MBUF_PRIV_ALIGN 8
415 
422 #define RTE_MBUF_DEFAULT_DATAROOM 2048
423 #define RTE_MBUF_DEFAULT_BUF_SIZE \
424  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
425 
427  uint32_t queue_id;
428  uint8_t traffic_class;
432  uint8_t color;
434  uint16_t reserved;
435 };
441 enum {
442  RTE_MBUF_L2_LEN_BITS = 7,
443  RTE_MBUF_L3_LEN_BITS = 9,
444  RTE_MBUF_L4_LEN_BITS = 8,
445  RTE_MBUF_TSO_SEGSZ_BITS = 16,
446  RTE_MBUF_OUTL3_LEN_BITS = 9,
447  RTE_MBUF_OUTL2_LEN_BITS = 7,
448  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
449  RTE_MBUF_L2_LEN_BITS -
450  RTE_MBUF_L3_LEN_BITS -
451  RTE_MBUF_L4_LEN_BITS -
452  RTE_MBUF_TSO_SEGSZ_BITS -
453  RTE_MBUF_OUTL3_LEN_BITS -
454  RTE_MBUF_OUTL2_LEN_BITS,
455 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
456  RTE_MBUF_L2_LEN_OFS =
457  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
458  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
459  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
460  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
461  RTE_MBUF_OUTL3_LEN_OFS =
462  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
463  RTE_MBUF_OUTL2_LEN_OFS =
464  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
465  RTE_MBUF_TXOFLD_UNUSED_OFS =
466  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
467 #else
468  RTE_MBUF_L2_LEN_OFS = 0,
469  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
470  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
471  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
472  RTE_MBUF_OUTL3_LEN_OFS =
473  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
474  RTE_MBUF_OUTL2_LEN_OFS =
475  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
476  RTE_MBUF_TXOFLD_UNUSED_OFS =
477  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
478 #endif
479 };
480 
484 struct rte_mbuf {
485  RTE_MARKER cacheline0;
486 
487  void *buf_addr;
494  rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
495 
496  /* next 8 bytes are initialised on RX descriptor rearm */
497  RTE_MARKER64 rearm_data;
498  uint16_t data_off;
499 
508  uint16_t refcnt;
509  uint16_t nb_segs;
514  uint16_t port;
515 
516  uint64_t ol_flags;
518  /* remaining bytes are set on RX when pulling packet from descriptor */
519  RTE_MARKER rx_descriptor_fields1;
520 
521  /*
522  * The packet type, which is the combination of outer/inner L2, L3, L4
523  * and tunnel types. The packet_type is about data really present in the
524  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
525  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
526  * vlan is stripped from the data.
527  */
529  union {
530  uint32_t packet_type;
531  __extension__
532  struct {
533  uint8_t l2_type:4;
534  uint8_t l3_type:4;
535  uint8_t l4_type:4;
536  uint8_t tun_type:4;
538  union {
544  __extension__
545  struct {
546  uint8_t inner_l2_type:4;
548  uint8_t inner_l3_type:4;
550  };
551  };
552  uint8_t inner_l4_type:4;
553  };
554  };
555 
556  uint32_t pkt_len;
557  uint16_t data_len;
559  uint16_t vlan_tci;
560 
562  union {
563  union {
564  uint32_t rss;
565  struct {
566  union {
567  struct {
568  uint16_t hash;
569  uint16_t id;
570  };
571  uint32_t lo;
573  };
574  uint32_t hi;
578  } fdir;
579  struct rte_mbuf_sched sched;
581  struct {
582  uint32_t reserved1;
583  uint16_t reserved2;
584  uint16_t txq;
589  } txadapter;
591  uint32_t usr;
592  } hash;
593  };
594 
596  uint16_t vlan_tci_outer;
597 
598  uint16_t buf_len;
600  struct rte_mempool *pool;
602  /* second cache line - fields only used in slow path or on TX */
604 
605  struct rte_mbuf *next;
607  /* fields to support TX offloads */
609  union {
610  uint64_t tx_offload;
611  __extension__
612  struct {
613  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
617  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
619  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
621  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
624  /*
625  * Fields for Tx offloading of tunnels.
626  * These are undefined for packets which don't request
627  * any tunnel offloads (outer IP or UDP checksum,
628  * tunnel TSO).
629  *
630  * PMDs should not use these fields unconditionally
631  * when calculating offsets.
632  *
633  * Applications are expected to set appropriate tunnel
634  * offload flags when they fill in these fields.
635  */
636  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
638  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
641  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
642  };
643  };
644 
649 
653  uint16_t priv_size;
654 
656  uint16_t timesync;
657 
658  uint32_t dynfield1[9];
660 
664 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
665 
671  void *fcb_opaque;
672  uint16_t refcnt;
673 };
674 
676 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
677 
685 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
686 
692 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
693 
700 #define RTE_MBUF_DIRECT(mb) \
701  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
702 
704 #define RTE_MBUF_PORT_INVALID UINT16_MAX
705 
706 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
707 
722 #define rte_pktmbuf_mtod_offset(m, t, o) \
723  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
724 
737 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
738 
748 #define rte_pktmbuf_iova_offset(m, o) \
749  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
750 
758 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
759 
760 #ifdef __cplusplus
761 }
762 #endif
763 
764 #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