DPDK  19.11.14
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 
17 #include <stdint.h>
18 
19 #include <rte_compat.h>
20 #include <rte_byteorder.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 
136 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
137 
143 #define PKT_RX_LRO (1ULL << 16)
144 
148 #define PKT_RX_TIMESTAMP (1ULL << 17)
149 
153 #define PKT_RX_SEC_OFFLOAD (1ULL << 18)
154 
158 #define PKT_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
159 
168 #define PKT_RX_QINQ (1ULL << 20)
169 
182 #define PKT_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
183 
184 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN 0
185 #define PKT_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
186 #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
187 #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
188 
189 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
190 
191 #define PKT_FIRST_FREE (1ULL << 23)
192 #define PKT_LAST_FREE (1ULL << 40)
193 
194 /* add new TX flags here, don't forget to update PKT_LAST_FREE */
195 
205 #define PKT_TX_OUTER_UDP_CKSUM (1ULL << 41)
206 
212 #define PKT_TX_UDP_SEG (1ULL << 42)
213 
217 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
218 
223 #define PKT_TX_MACSEC (1ULL << 44)
224 
233 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
234 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
235 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
236 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
237 
238 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
239 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
240 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
241 
252 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
253 
265 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
266 /* add new TX TUNNEL type here */
267 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
268 
274 #define PKT_TX_QINQ (1ULL << 49)
275 /* this old name is deprecated */
276 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
277 
287 #define PKT_TX_TCP_SEG (1ULL << 50)
288 
290 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
291 
300 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
303 #define PKT_TX_TCP_CKSUM (1ULL << 52)
304 
306 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
307 
309 #define PKT_TX_UDP_CKSUM (3ULL << 52)
310 
312 #define PKT_TX_L4_MASK (3ULL << 52)
313 
320 #define PKT_TX_IP_CKSUM (1ULL << 54)
321 
328 #define PKT_TX_IPV4 (1ULL << 55)
329 
336 #define PKT_TX_IPV6 (1ULL << 56)
337 
343 #define PKT_TX_VLAN (1ULL << 57)
344 /* this old name is deprecated */
345 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
346 
353 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
354 
360 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
361 
367 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
368 
373 #define PKT_TX_OFFLOAD_MASK ( \
374  PKT_TX_OUTER_IPV6 | \
375  PKT_TX_OUTER_IPV4 | \
376  PKT_TX_OUTER_IP_CKSUM | \
377  PKT_TX_VLAN_PKT | \
378  PKT_TX_IPV6 | \
379  PKT_TX_IPV4 | \
380  PKT_TX_IP_CKSUM | \
381  PKT_TX_L4_MASK | \
382  PKT_TX_IEEE1588_TMST | \
383  PKT_TX_TCP_SEG | \
384  PKT_TX_QINQ_PKT | \
385  PKT_TX_TUNNEL_MASK | \
386  PKT_TX_MACSEC | \
387  PKT_TX_SEC_OFFLOAD | \
388  PKT_TX_UDP_SEG | \
389  PKT_TX_OUTER_UDP_CKSUM)
390 
394 #define EXT_ATTACHED_MBUF (1ULL << 61)
395 
396 #define IND_ATTACHED_MBUF (1ULL << 62)
399 #define RTE_MBUF_PRIV_ALIGN 8
400 
407 #define RTE_MBUF_DEFAULT_DATAROOM 2048
408 #define RTE_MBUF_DEFAULT_BUF_SIZE \
409  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
410 
411 /*
412  * define a set of marker types that can be used to refer to set points in the
413  * mbuf.
414  */
415 __extension__
416 typedef void *MARKER[0];
417 __extension__
418 typedef uint8_t MARKER8[0];
421 __extension__
422 typedef uint64_t MARKER64[0];
423 
425  uint32_t queue_id;
426  uint8_t traffic_class;
430  uint8_t color;
432  uint16_t reserved;
433 };
439 enum {
440  RTE_MBUF_L2_LEN_BITS = 7,
441  RTE_MBUF_L3_LEN_BITS = 9,
442  RTE_MBUF_L4_LEN_BITS = 8,
443  RTE_MBUF_TSO_SEGSZ_BITS = 16,
444  RTE_MBUF_OUTL3_LEN_BITS = 9,
445  RTE_MBUF_OUTL2_LEN_BITS = 7,
446  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
447  RTE_MBUF_L2_LEN_BITS -
448  RTE_MBUF_L3_LEN_BITS -
449  RTE_MBUF_L4_LEN_BITS -
450  RTE_MBUF_TSO_SEGSZ_BITS -
451  RTE_MBUF_OUTL3_LEN_BITS -
452  RTE_MBUF_OUTL2_LEN_BITS,
453 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
454  RTE_MBUF_L2_LEN_OFS =
455  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
456  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
457  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
458  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
459  RTE_MBUF_OUTL3_LEN_OFS =
460  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
461  RTE_MBUF_OUTL2_LEN_OFS =
462  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
463  RTE_MBUF_TXOFLD_UNUSED_OFS =
464  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
465 #else
466  RTE_MBUF_L2_LEN_OFS = 0,
467  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
468  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
469  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
470  RTE_MBUF_OUTL3_LEN_OFS =
471  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
472  RTE_MBUF_OUTL2_LEN_OFS =
473  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
474  RTE_MBUF_TXOFLD_UNUSED_OFS =
475  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
476 #endif
477 };
478 
482 struct rte_mbuf {
483  MARKER cacheline0;
484 
485  void *buf_addr;
493  union {
494  rte_iova_t buf_iova;
496  } __rte_aligned(sizeof(rte_iova_t));
497 
498  /* next 8 bytes are initialised on RX descriptor rearm */
499  MARKER64 rearm_data;
500  uint16_t data_off;
501 
512  union {
515  uint16_t refcnt;
516  };
517  uint16_t nb_segs;
522  uint16_t port;
523 
524  uint64_t ol_flags;
526  /* remaining bytes are set on RX when pulling packet from descriptor */
527  MARKER rx_descriptor_fields1;
528 
529  /*
530  * The packet type, which is the combination of outer/inner L2, L3, L4
531  * and tunnel types. The packet_type is about data really present in the
532  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
533  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
534  * vlan is stripped from the data.
535  */
537  union {
538  uint32_t packet_type;
539  struct {
540  uint32_t l2_type:4;
541  uint32_t l3_type:4;
542  uint32_t l4_type:4;
543  uint32_t tun_type:4;
545  union {
551  __extension__
552  struct {
553  uint8_t inner_l2_type:4;
555  uint8_t inner_l3_type:4;
557  };
558  };
559  uint32_t inner_l4_type:4;
560  };
561  };
562 
563  uint32_t pkt_len;
564  uint16_t data_len;
566  uint16_t vlan_tci;
567 
569  union {
570  union {
571  uint32_t rss;
572  struct {
573  union {
574  struct {
575  uint16_t hash;
576  uint16_t id;
577  };
578  uint32_t lo;
580  };
581  uint32_t hi;
585  } fdir;
586  struct rte_mbuf_sched sched;
588  struct {
589  uint32_t reserved1;
590  uint16_t reserved2;
591  uint16_t txq;
596  } txadapter;
598  uint32_t usr;
599  } hash;
600  };
601 
603  uint16_t vlan_tci_outer;
604 
605  uint16_t buf_len;
612  uint64_t timestamp;
613 
614  /* second cache line - fields only used in slow path or on TX */
615  MARKER cacheline1 __rte_cache_min_aligned;
616 
618  union {
619  void *userdata;
620  uint64_t udata64;
621  };
622 
623  struct rte_mempool *pool;
624  struct rte_mbuf *next;
626  /* fields to support TX offloads */
628  union {
629  uint64_t tx_offload;
630  __extension__
631  struct {
632  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
636  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
638  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
640  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
643  /*
644  * Fields for Tx offloading of tunnels.
645  * These are undefined for packets which don't request
646  * any tunnel offloads (outer IP or UDP checksum,
647  * tunnel TSO).
648  *
649  * PMDs should not use these fields unconditionally
650  * when calculating offsets.
651  *
652  * Applications are expected to set appropriate tunnel
653  * offload flags when they fill in these fields.
654  */
655  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
657  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
660  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
661  };
662  };
663 
667  uint16_t priv_size;
668 
670  uint16_t timesync;
671 
673  uint32_t seqn;
674 
679 
680  uint64_t dynfield1[2];
682 
686 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
687 
693  void *fcb_opaque;
695 };
696 
698 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
699 
707 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
708 
714 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
715 
722 #define RTE_MBUF_DIRECT(mb) \
723  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
724 
725 #define MBUF_INVALID_PORT UINT16_MAX
726 
741 #define rte_pktmbuf_mtod_offset(m, t, o) \
742  ((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
743 
756 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
757 
767 #define rte_pktmbuf_iova_offset(m, o) \
768  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
769 
777 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
778 
779 #ifdef __cplusplus
780 }
781 #endif
782 
783 #endif /* _RTE_MBUF_CORE_H_ */
struct rte_mbuf_ext_shared_info * shinfo
struct rte_mbuf * next
uint16_t txq
uint64_t timestamp
uint16_t vlan_tci_outer
uint8_t inner_esp_next_proto
rte_iova_t buf_physaddr
#define __rte_cache_min_aligned
Definition: rte_common.h:325
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:340
void * buf_addr
uint32_t l2_type
uint16_t data_len
uint32_t lo
rte_mbuf_extbuf_free_callback_t free_cb
void * userdata
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
__extension__ typedef void * MARKER[0]
uint64_t l3_len
uint32_t l4_type
uint16_t priv_size
uint16_t timesync
uint32_t hi
void(* rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque)
uint64_t outer_l2_len
uint16_t refcnt
uint32_t tun_type
uint64_t ol_flags
uint32_t pkt_len
uint16_t buf_len
uint32_t inner_l4_type
uint32_t packet_type
uint32_t seqn
__extension__ typedef uint64_t MARKER64[0]
uint8_t inner_l3_type
#define RTE_STD_C11
Definition: rte_common.h:40
struct rte_mempool * pool
#define __rte_cache_aligned
Definition: rte_common.h:322
uint32_t rss
uint16_t reserved
uint64_t udata64
uint8_t traffic_class
uint32_t l3_type
rte_atomic16_t refcnt_atomic
uint64_t tx_offload
uint16_t vlan_tci
__extension__ typedef uint8_t MARKER8[0]
rte_atomic16_t refcnt_atomic
#define __rte_aligned(a)
Definition: rte_common.h:64