DPDK  20.11.3
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 
77 #define PKT_RX_EIP_CKSUM_BAD (1ULL << 5)
78 
85 #define PKT_RX_VLAN_STRIPPED (1ULL << 6)
86 
95 #define PKT_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
96 
97 #define PKT_RX_IP_CKSUM_UNKNOWN 0
98 #define PKT_RX_IP_CKSUM_BAD (1ULL << 4)
99 #define PKT_RX_IP_CKSUM_GOOD (1ULL << 7)
100 #define PKT_RX_IP_CKSUM_NONE ((1ULL << 4) | (1ULL << 7))
101 
110 #define PKT_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
111 
112 #define PKT_RX_L4_CKSUM_UNKNOWN 0
113 #define PKT_RX_L4_CKSUM_BAD (1ULL << 3)
114 #define PKT_RX_L4_CKSUM_GOOD (1ULL << 8)
115 #define PKT_RX_L4_CKSUM_NONE ((1ULL << 3) | (1ULL << 8))
116 
118 #define PKT_RX_IEEE1588_PTP (1ULL << 9)
119 
121 #define PKT_RX_IEEE1588_TMST (1ULL << 10)
122 
124 #define PKT_RX_FDIR_ID (1ULL << 13)
125 
127 #define PKT_RX_FDIR_FLX (1ULL << 14)
128 
144 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
145 
151 #define PKT_RX_LRO (1ULL << 16)
152 
153 /* There is no flag defined at offset 17. It is free for any future use. */
154 
158 #define PKT_RX_SEC_OFFLOAD (1ULL << 18)
159 
163 #define PKT_RX_SEC_OFFLOAD_FAILED (1ULL << 19)
164 
173 #define PKT_RX_QINQ (1ULL << 20)
174 
187 #define PKT_RX_OUTER_L4_CKSUM_MASK ((1ULL << 21) | (1ULL << 22))
188 
189 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN 0
190 #define PKT_RX_OUTER_L4_CKSUM_BAD (1ULL << 21)
191 #define PKT_RX_OUTER_L4_CKSUM_GOOD (1ULL << 22)
192 #define PKT_RX_OUTER_L4_CKSUM_INVALID ((1ULL << 21) | (1ULL << 22))
193 
194 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
195 
196 #define PKT_FIRST_FREE (1ULL << 23)
197 #define PKT_LAST_FREE (1ULL << 40)
198 
199 /* add new TX flags here, don't forget to update PKT_LAST_FREE */
200 
210 #define PKT_TX_OUTER_UDP_CKSUM (1ULL << 41)
211 
217 #define PKT_TX_UDP_SEG (1ULL << 42)
218 
222 #define PKT_TX_SEC_OFFLOAD (1ULL << 43)
223 
228 #define PKT_TX_MACSEC (1ULL << 44)
229 
238 #define PKT_TX_TUNNEL_VXLAN (0x1ULL << 45)
239 #define PKT_TX_TUNNEL_GRE (0x2ULL << 45)
240 #define PKT_TX_TUNNEL_IPIP (0x3ULL << 45)
241 #define PKT_TX_TUNNEL_GENEVE (0x4ULL << 45)
242 
243 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
244 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
245 #define PKT_TX_TUNNEL_GTP (0x7ULL << 45)
246 
257 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
258 
270 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
271 /* add new TX TUNNEL type here */
272 #define PKT_TX_TUNNEL_MASK (0xFULL << 45)
273 
279 #define PKT_TX_QINQ (1ULL << 49)
280 
281 #define PKT_TX_QINQ_PKT PKT_TX_QINQ
282 
292 #define PKT_TX_TCP_SEG (1ULL << 50)
293 
295 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
296 
305 #define PKT_TX_L4_NO_CKSUM (0ULL << 52)
308 #define PKT_TX_TCP_CKSUM (1ULL << 52)
309 
311 #define PKT_TX_SCTP_CKSUM (2ULL << 52)
312 
314 #define PKT_TX_UDP_CKSUM (3ULL << 52)
315 
317 #define PKT_TX_L4_MASK (3ULL << 52)
318 
325 #define PKT_TX_IP_CKSUM (1ULL << 54)
326 
333 #define PKT_TX_IPV4 (1ULL << 55)
334 
341 #define PKT_TX_IPV6 (1ULL << 56)
342 
348 #define PKT_TX_VLAN (1ULL << 57)
349 /* this old name is deprecated */
350 #define PKT_TX_VLAN_PKT PKT_TX_VLAN
351 
358 #define PKT_TX_OUTER_IP_CKSUM (1ULL << 58)
359 
365 #define PKT_TX_OUTER_IPV4 (1ULL << 59)
366 
372 #define PKT_TX_OUTER_IPV6 (1ULL << 60)
373 
378 #define PKT_TX_OFFLOAD_MASK ( \
379  PKT_TX_OUTER_IPV6 | \
380  PKT_TX_OUTER_IPV4 | \
381  PKT_TX_OUTER_IP_CKSUM | \
382  PKT_TX_VLAN_PKT | \
383  PKT_TX_IPV6 | \
384  PKT_TX_IPV4 | \
385  PKT_TX_IP_CKSUM | \
386  PKT_TX_L4_MASK | \
387  PKT_TX_IEEE1588_TMST | \
388  PKT_TX_TCP_SEG | \
389  PKT_TX_QINQ_PKT | \
390  PKT_TX_TUNNEL_MASK | \
391  PKT_TX_MACSEC | \
392  PKT_TX_SEC_OFFLOAD | \
393  PKT_TX_UDP_SEG | \
394  PKT_TX_OUTER_UDP_CKSUM)
395 
399 #define EXT_ATTACHED_MBUF (1ULL << 61)
400 
401 #define IND_ATTACHED_MBUF (1ULL << 62)
404 #define RTE_MBUF_PRIV_ALIGN 8
405 
412 #define RTE_MBUF_DEFAULT_DATAROOM 2048
413 #define RTE_MBUF_DEFAULT_BUF_SIZE \
414  (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
415 
417  uint32_t queue_id;
418  uint8_t traffic_class;
422  uint8_t color;
424  uint16_t reserved;
425 };
431 enum {
432  RTE_MBUF_L2_LEN_BITS = 7,
433  RTE_MBUF_L3_LEN_BITS = 9,
434  RTE_MBUF_L4_LEN_BITS = 8,
435  RTE_MBUF_TSO_SEGSZ_BITS = 16,
436  RTE_MBUF_OUTL3_LEN_BITS = 9,
437  RTE_MBUF_OUTL2_LEN_BITS = 7,
438  RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
439  RTE_MBUF_L2_LEN_BITS -
440  RTE_MBUF_L3_LEN_BITS -
441  RTE_MBUF_L4_LEN_BITS -
442  RTE_MBUF_TSO_SEGSZ_BITS -
443  RTE_MBUF_OUTL3_LEN_BITS -
444  RTE_MBUF_OUTL2_LEN_BITS,
445 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
446  RTE_MBUF_L2_LEN_OFS =
447  sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
448  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
449  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
450  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
451  RTE_MBUF_OUTL3_LEN_OFS =
452  RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
453  RTE_MBUF_OUTL2_LEN_OFS =
454  RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
455  RTE_MBUF_TXOFLD_UNUSED_OFS =
456  RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
457 #else
458  RTE_MBUF_L2_LEN_OFS = 0,
459  RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
460  RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
461  RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
462  RTE_MBUF_OUTL3_LEN_OFS =
463  RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
464  RTE_MBUF_OUTL2_LEN_OFS =
465  RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
466  RTE_MBUF_TXOFLD_UNUSED_OFS =
467  RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
468 #endif
469 };
470 
474 struct rte_mbuf {
475  RTE_MARKER cacheline0;
476 
477  void *buf_addr;
484  rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
485 
486  /* next 8 bytes are initialised on RX descriptor rearm */
487  RTE_MARKER64 rearm_data;
488  uint16_t data_off;
489 
498  uint16_t refcnt;
499  uint16_t nb_segs;
504  uint16_t port;
505 
506  uint64_t ol_flags;
508  /* remaining bytes are set on RX when pulling packet from descriptor */
509  RTE_MARKER rx_descriptor_fields1;
510 
511  /*
512  * The packet type, which is the combination of outer/inner L2, L3, L4
513  * and tunnel types. The packet_type is about data really present in the
514  * mbuf. Example: if vlan stripping is enabled, a received vlan packet
515  * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
516  * vlan is stripped from the data.
517  */
519  union {
520  uint32_t packet_type;
521  __extension__
522  struct {
523  uint8_t l2_type:4;
524  uint8_t l3_type:4;
525  uint8_t l4_type:4;
526  uint8_t tun_type:4;
528  union {
534  __extension__
535  struct {
536  uint8_t inner_l2_type:4;
538  uint8_t inner_l3_type:4;
540  };
541  };
542  uint8_t inner_l4_type:4;
543  };
544  };
545 
546  uint32_t pkt_len;
547  uint16_t data_len;
549  uint16_t vlan_tci;
550 
552  union {
553  union {
554  uint32_t rss;
555  struct {
556  union {
557  struct {
558  uint16_t hash;
559  uint16_t id;
560  };
561  uint32_t lo;
563  };
564  uint32_t hi;
568  } fdir;
569  struct rte_mbuf_sched sched;
571  struct {
572  uint32_t reserved1;
573  uint16_t reserved2;
574  uint16_t txq;
579  } txadapter;
581  uint32_t usr;
582  } hash;
583  };
584 
586  uint16_t vlan_tci_outer;
587 
588  uint16_t buf_len;
590  struct rte_mempool *pool;
592  /* second cache line - fields only used in slow path or on TX */
594 
595  struct rte_mbuf *next;
597  /* fields to support TX offloads */
599  union {
600  uint64_t tx_offload;
601  __extension__
602  struct {
603  uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
607  uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
609  uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
611  uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
614  /*
615  * Fields for Tx offloading of tunnels.
616  * These are undefined for packets which don't request
617  * any tunnel offloads (outer IP or UDP checksum,
618  * tunnel TSO).
619  *
620  * PMDs should not use these fields unconditionally
621  * when calculating offsets.
622  *
623  * Applications are expected to set appropriate tunnel
624  * offload flags when they fill in these fields.
625  */
626  uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
628  uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
631  /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
632  };
633  };
634 
639 
643  uint16_t priv_size;
644 
646  uint16_t timesync;
647 
648  uint32_t dynfield1[9];
650 
654 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
655 
661  void *fcb_opaque;
662  uint16_t refcnt;
663 };
664 
666 #define RTE_MBUF_MAX_NB_SEGS UINT16_MAX
667 
675 #define RTE_MBUF_CLONED(mb) ((mb)->ol_flags & IND_ATTACHED_MBUF)
676 
682 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
683 
690 #define RTE_MBUF_DIRECT(mb) \
691  (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
692 
694 #define RTE_MBUF_PORT_INVALID UINT16_MAX
695 
696 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
697 
712 #define rte_pktmbuf_mtod_offset(m, t, o) \
713  ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
714 
727 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
728 
738 #define rte_pktmbuf_iova_offset(m, o) \
739  (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
740 
748 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
749 
750 #ifdef __cplusplus
751 }
752 #endif
753 
754 #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:403
uint8_t l3_type
uint32_t queue_id
uint64_t l2_len
uint64_t rte_iova_t
Definition: rte_common.h:418
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:424
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:432
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:400
uint8_t l4_type
#define RTE_STD_C11
Definition: rte_common.h:40
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