xref: /dpdk/lib/mbuf/rte_mbuf_core.h (revision 9e152e674c77dd14c4f324a832ece4498b1c6470)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation.
399a2dd95SBruce Richardson  * Copyright 2014 6WIND S.A.
499a2dd95SBruce Richardson  */
599a2dd95SBruce Richardson 
699a2dd95SBruce Richardson #ifndef _RTE_MBUF_CORE_H_
799a2dd95SBruce Richardson #define _RTE_MBUF_CORE_H_
899a2dd95SBruce Richardson 
999a2dd95SBruce Richardson /**
1099a2dd95SBruce Richardson  * @file
117be78d02SJosh Soref  * This file contains definition of RTE mbuf structure itself,
1299a2dd95SBruce Richardson  * packet offload flags and some related macros.
1399a2dd95SBruce Richardson  * For majority of DPDK entities, it is not recommended to include
1499a2dd95SBruce Richardson  * this file directly, use include <rte_mbuf.h> instead.
1599a2dd95SBruce Richardson  *
1699a2dd95SBruce Richardson  * New fields and flags should fit in the "dynamic space".
1799a2dd95SBruce Richardson  */
1899a2dd95SBruce Richardson 
19e9fd1ebfSTyler Retzlaff #include <stdalign.h>
2099a2dd95SBruce Richardson #include <stdint.h>
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson #include <rte_byteorder.h>
239bcb34d4STyler Retzlaff #include <rte_stdatomic.h>
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson #ifdef __cplusplus
2699a2dd95SBruce Richardson extern "C" {
2799a2dd95SBruce Richardson #endif
2899a2dd95SBruce Richardson 
2999a2dd95SBruce Richardson /*
3099a2dd95SBruce Richardson  * Packet Offload Features Flags. It also carry packet type information.
3199a2dd95SBruce Richardson  * Critical resources. Both rx/tx shared these bits. Be cautious on any change
3299a2dd95SBruce Richardson  *
3399a2dd95SBruce Richardson  * - RX flags start at bit position zero, and get added to the left of previous
3499a2dd95SBruce Richardson  *   flags.
3599a2dd95SBruce Richardson  * - The most-significant 3 bits are reserved for generic mbuf flags
3699a2dd95SBruce Richardson  * - TX flags therefore start at bit position 60 (i.e. 63-3), and new flags get
3799a2dd95SBruce Richardson  *   added to the right of the previously defined flags i.e. they should count
3899a2dd95SBruce Richardson  *   downwards, not upwards.
3999a2dd95SBruce Richardson  *
4099a2dd95SBruce Richardson  * Keep these flags synchronized with rte_get_rx_ol_flag_name() and
4199a2dd95SBruce Richardson  * rte_get_tx_ol_flag_name().
4299a2dd95SBruce Richardson  */
4399a2dd95SBruce Richardson 
4499a2dd95SBruce Richardson /**
4599a2dd95SBruce Richardson  * The RX packet is a 802.1q VLAN packet, and the tci has been
4623f3dac4SStephen Hemminger  * saved in mbuf->vlan_tci.
47daa02b5cSOlivier Matz  * If the flag RTE_MBUF_F_RX_VLAN_STRIPPED is also present, the VLAN
4899a2dd95SBruce Richardson  * header has been stripped from mbuf data, else it is still
4999a2dd95SBruce Richardson  * present.
5099a2dd95SBruce Richardson  */
51daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_VLAN          (1ULL << 0)
5299a2dd95SBruce Richardson 
5399a2dd95SBruce Richardson /** RX packet with RSS hash result. */
54daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_RSS_HASH      (1ULL << 1)
5599a2dd95SBruce Richardson 
5699a2dd95SBruce Richardson  /** RX packet with FDIR match indicate. */
57daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_FDIR          (1ULL << 2)
5899a2dd95SBruce Richardson 
5999a2dd95SBruce Richardson /**
6099a2dd95SBruce Richardson  * This flag is set when the outermost IP header checksum is detected as
6199a2dd95SBruce Richardson  * wrong by the hardware.
6299a2dd95SBruce Richardson  */
63daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
6499a2dd95SBruce Richardson 
6599a2dd95SBruce Richardson /**
6699a2dd95SBruce Richardson  * A vlan has been stripped by the hardware and its tci is saved in
6799a2dd95SBruce Richardson  * mbuf->vlan_tci. This can only happen if vlan stripping is enabled
6899a2dd95SBruce Richardson  * in the RX configuration of the PMD.
69daa02b5cSOlivier Matz  * When RTE_MBUF_F_RX_VLAN_STRIPPED is set, RTE_MBUF_F_RX_VLAN must also be set.
7099a2dd95SBruce Richardson  */
71daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_VLAN_STRIPPED (1ULL << 6)
7299a2dd95SBruce Richardson 
7399a2dd95SBruce Richardson /**
7499a2dd95SBruce Richardson  * Mask of bits used to determine the status of RX IP checksum.
75daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN: no information about the RX IP checksum
76daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_IP_CKSUM_BAD: the IP checksum in the packet is wrong
77daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_IP_CKSUM_GOOD: the IP checksum in the packet is valid
78daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_IP_CKSUM_NONE: the IP checksum is not correct in the packet
7999a2dd95SBruce Richardson  *   data, but the integrity of the IP header is verified.
8099a2dd95SBruce Richardson  */
81daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
8299a2dd95SBruce Richardson 
83daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IP_CKSUM_UNKNOWN 0
84daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IP_CKSUM_BAD     (1ULL << 4)
85daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IP_CKSUM_GOOD    (1ULL << 7)
86daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IP_CKSUM_NONE    ((1ULL << 4) | (1ULL << 7))
8799a2dd95SBruce Richardson 
8899a2dd95SBruce Richardson /**
8999a2dd95SBruce Richardson  * Mask of bits used to determine the status of RX L4 checksum.
90daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN: no information about the RX L4 checksum
91daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_L4_CKSUM_BAD: the L4 checksum in the packet is wrong
92daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_L4_CKSUM_GOOD: the L4 checksum in the packet is valid
93daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_L4_CKSUM_NONE: the L4 checksum is not correct in the packet
9499a2dd95SBruce Richardson  *   data, but the integrity of the L4 data is verified.
9599a2dd95SBruce Richardson  */
96daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
9799a2dd95SBruce Richardson 
98daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_L4_CKSUM_UNKNOWN 0
99daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_L4_CKSUM_BAD     (1ULL << 3)
100daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_L4_CKSUM_GOOD    (1ULL << 8)
101daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_L4_CKSUM_NONE    ((1ULL << 3) | (1ULL << 8))
10299a2dd95SBruce Richardson 
10399a2dd95SBruce Richardson /** RX IEEE1588 L2 Ethernet PT Packet. */
104daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IEEE1588_PTP  (1ULL << 9)
10599a2dd95SBruce Richardson 
10699a2dd95SBruce Richardson /** RX IEEE1588 L2/L4 timestamped packet.*/
107daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_IEEE1588_TMST (1ULL << 10)
10899a2dd95SBruce Richardson 
10999a2dd95SBruce Richardson /** FD id reported if FDIR match. */
110daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_FDIR_ID       (1ULL << 13)
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson /** Flexible bytes reported if FDIR match. */
113daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_FDIR_FLX      (1ULL << 14)
11499a2dd95SBruce Richardson 
11599a2dd95SBruce Richardson /**
11699a2dd95SBruce Richardson  * The outer VLAN has been stripped by the hardware and its TCI is
11799a2dd95SBruce Richardson  * saved in mbuf->vlan_tci_outer.
11899a2dd95SBruce Richardson  * This can only happen if VLAN stripping is enabled in the Rx
11999a2dd95SBruce Richardson  * configuration of the PMD.
120daa02b5cSOlivier Matz  * When RTE_MBUF_F_RX_QINQ_STRIPPED is set, the flags RTE_MBUF_F_RX_VLAN
121daa02b5cSOlivier Matz  * and RTE_MBUF_F_RX_QINQ must also be set.
12299a2dd95SBruce Richardson  *
123daa02b5cSOlivier Matz  * - If both RTE_MBUF_F_RX_QINQ_STRIPPED and RTE_MBUF_F_RX_VLAN_STRIPPED are
124daa02b5cSOlivier Matz  *   set, the 2 VLANs have been stripped by the hardware and their TCIs are
125daa02b5cSOlivier Matz  *   saved in mbuf->vlan_tci (inner) and mbuf->vlan_tci_outer (outer).
126daa02b5cSOlivier Matz  * - If RTE_MBUF_F_RX_QINQ_STRIPPED is set and RTE_MBUF_F_RX_VLAN_STRIPPED
127daa02b5cSOlivier Matz  *   is unset, only the outer VLAN is removed from packet data, but both tci
128daa02b5cSOlivier Matz  *   are saved in mbuf->vlan_tci (inner) and mbuf->vlan_tci_outer (outer).
12999a2dd95SBruce Richardson  */
130daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_QINQ_STRIPPED (1ULL << 15)
13199a2dd95SBruce Richardson 
13299a2dd95SBruce Richardson /**
13399a2dd95SBruce Richardson  * When packets are coalesced by a hardware or virtual driver, this flag
13499a2dd95SBruce Richardson  * can be set in the RX mbuf, meaning that the m->tso_segsz field is
13599a2dd95SBruce Richardson  * valid and is set to the segment size of original packets.
13699a2dd95SBruce Richardson  */
137daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_LRO           (1ULL << 16)
13899a2dd95SBruce Richardson 
13999a2dd95SBruce Richardson /* There is no flag defined at offset 17. It is free for any future use. */
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson /**
14299a2dd95SBruce Richardson  * Indicate that security offload processing was applied on the RX packet.
14399a2dd95SBruce Richardson  */
144daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_SEC_OFFLOAD	(1ULL << 18)
14599a2dd95SBruce Richardson 
14699a2dd95SBruce Richardson /**
14799a2dd95SBruce Richardson  * Indicate that security offload processing failed on the RX packet.
14899a2dd95SBruce Richardson  */
149daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED	(1ULL << 19)
15099a2dd95SBruce Richardson 
15199a2dd95SBruce Richardson /**
15299a2dd95SBruce Richardson  * The RX packet is a double VLAN, and the outer tci has been
153daa02b5cSOlivier Matz  * saved in mbuf->vlan_tci_outer. If this flag is set, RTE_MBUF_F_RX_VLAN
15499a2dd95SBruce Richardson  * must also be set and the inner tci is saved in mbuf->vlan_tci.
155daa02b5cSOlivier Matz  * If the flag RTE_MBUF_F_RX_QINQ_STRIPPED is also present, both VLANs
15699a2dd95SBruce Richardson  * headers have been stripped from mbuf data, else they are still
15799a2dd95SBruce Richardson  * present.
15899a2dd95SBruce Richardson  */
159daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_QINQ          (1ULL << 20)
16099a2dd95SBruce Richardson 
16199a2dd95SBruce Richardson /**
16299a2dd95SBruce Richardson  * Mask of bits used to determine the status of outer RX L4 checksum.
163daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN: no info about the outer RX L4
164daa02b5cSOlivier Matz  *   checksum
165daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD: the outer L4 checksum in the packet
166daa02b5cSOlivier Matz  *   is wrong
167daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD: the outer L4 checksum in the packet
168daa02b5cSOlivier Matz  *   is valid
169daa02b5cSOlivier Matz  * - RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID: invalid outer L4 checksum state.
17099a2dd95SBruce Richardson  *
171daa02b5cSOlivier Matz  * The detection of RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD shall be based on the
172daa02b5cSOlivier Matz  * given HW capability, At minimum, the PMD should support
173daa02b5cSOlivier Matz  * RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN and RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD
174daa02b5cSOlivier Matz  * states if the RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM offload is available.
17599a2dd95SBruce Richardson  */
176daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_MASK	((1ULL << 21) | (1ULL << 22))
17799a2dd95SBruce Richardson 
178daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_UNKNOWN	0
179daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
180daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
181daa02b5cSOlivier Matz #define RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
18299a2dd95SBruce Richardson 
183daa02b5cSOlivier Matz /* add new RX flags here, don't forget to update RTE_MBUF_F_FIRST_FREE */
18499a2dd95SBruce Richardson 
185daa02b5cSOlivier Matz #define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
186daa02b5cSOlivier Matz #define RTE_MBUF_F_LAST_FREE (1ULL << 40)
18799a2dd95SBruce Richardson 
188daa02b5cSOlivier Matz /* add new TX flags here, don't forget to update RTE_MBUF_F_LAST_FREE  */
18999a2dd95SBruce Richardson 
19099a2dd95SBruce Richardson /**
19199a2dd95SBruce Richardson  * Outer UDP checksum offload flag. This flag is used for enabling
19299a2dd95SBruce Richardson  * outer UDP checksum in PMD. To use outer UDP checksum, the user needs to
19399a2dd95SBruce Richardson  * 1) Enable the following in mbuf,
19499a2dd95SBruce Richardson  * a) Fill outer_l2_len and outer_l3_len in mbuf.
195daa02b5cSOlivier Matz  * b) Set the RTE_MBUF_F_TX_OUTER_UDP_CKSUM flag.
196daa02b5cSOlivier Matz  * c) Set the RTE_MBUF_F_TX_OUTER_IPV4 or RTE_MBUF_F_TX_OUTER_IPV6 flag.
197295968d1SFerruh Yigit  * 2) Configure RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM offload flag.
19899a2dd95SBruce Richardson  */
199daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_OUTER_UDP_CKSUM     (1ULL << 41)
20099a2dd95SBruce Richardson 
20199a2dd95SBruce Richardson /**
20299a2dd95SBruce Richardson  * UDP Fragmentation Offload flag. This flag is used for enabling UDP
20399a2dd95SBruce Richardson  * fragmentation in SW or in HW. When use UFO, mbuf->tso_segsz is used
20499a2dd95SBruce Richardson  * to store the MSS of UDP fragments.
20599a2dd95SBruce Richardson  */
206daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_UDP_SEG	(1ULL << 42)
20799a2dd95SBruce Richardson 
20899a2dd95SBruce Richardson /**
20999a2dd95SBruce Richardson  * Request security offload processing on the TX packet.
2106d1f8c13SNithin Dabilpuram  * To use Tx security offload, the user needs to fill l2_len in mbuf
211338eb151SNithin Dabilpuram  * indicating L2 header size and where L3 header starts. Similarly,
212338eb151SNithin Dabilpuram  * l3_len should also be filled along with ol_flags reflecting current L3 type.
21399a2dd95SBruce Richardson  */
214daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_SEC_OFFLOAD	(1ULL << 43)
21599a2dd95SBruce Richardson 
21699a2dd95SBruce Richardson /**
21799a2dd95SBruce Richardson  * Offload the MACsec. This flag must be set by the application to enable
21899a2dd95SBruce Richardson  * this offload feature for a packet to be transmitted.
21999a2dd95SBruce Richardson  */
220daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_MACSEC        (1ULL << 44)
22199a2dd95SBruce Richardson 
22299a2dd95SBruce Richardson /**
22399a2dd95SBruce Richardson  * Bits 45:48 used for the tunnel type.
22499a2dd95SBruce Richardson  * The tunnel type must be specified for TSO or checksum on the inner part
22599a2dd95SBruce Richardson  * of tunnel packets.
226daa02b5cSOlivier Matz  * These flags can be used with RTE_MBUF_F_TX_TCP_SEG for TSO, or
227daa02b5cSOlivier Matz  * RTE_MBUF_F_TX_xxx_CKSUM.
22899a2dd95SBruce Richardson  * The mbuf fields for inner and outer header lengths are required:
22999a2dd95SBruce Richardson  * outer_l2_len, outer_l3_len, l2_len, l3_len, l4_len and tso_segsz for TSO.
23099a2dd95SBruce Richardson  */
231daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_VXLAN   (0x1ULL << 45)
232daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_GRE     (0x2ULL << 45)
233daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_IPIP    (0x3ULL << 45)
234daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_GENEVE  (0x4ULL << 45)
23599a2dd95SBruce Richardson /** TX packet with MPLS-in-UDP RFC 7510 header. */
236daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
237daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
238daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_GTP       (0x7ULL << 45)
239daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_ESP       (0x8ULL << 45)
24099a2dd95SBruce Richardson /**
24199a2dd95SBruce Richardson  * Generic IP encapsulated tunnel type, used for TSO and checksum offload.
24299a2dd95SBruce Richardson  * It can be used for tunnels which are not standards or listed above.
243daa02b5cSOlivier Matz  * It is preferred to use specific tunnel flags like RTE_MBUF_F_TX_TUNNEL_GRE
244daa02b5cSOlivier Matz  * or RTE_MBUF_F_TX_TUNNEL_IPIP if possible.
245295968d1SFerruh Yigit  * The ethdev must be configured with RTE_ETH_TX_OFFLOAD_IP_TNL_TSO.
24699a2dd95SBruce Richardson  * Outer and inner checksums are done according to the existing flags like
247daa02b5cSOlivier Matz  * RTE_MBUF_F_TX_xxx_CKSUM.
24899a2dd95SBruce Richardson  * Specific tunnel headers that contain payload length, sequence id
24999a2dd95SBruce Richardson  * or checksum are not expected to be updated.
25099a2dd95SBruce Richardson  */
251daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_IP (0xDULL << 45)
25299a2dd95SBruce Richardson /**
25399a2dd95SBruce Richardson  * Generic UDP encapsulated tunnel type, used for TSO and checksum offload.
25499a2dd95SBruce Richardson  * UDP tunnel type implies outer IP layer.
25599a2dd95SBruce Richardson  * It can be used for tunnels which are not standards or listed above.
256daa02b5cSOlivier Matz  * It is preferred to use specific tunnel flags like RTE_MBUF_F_TX_TUNNEL_VXLAN
25799a2dd95SBruce Richardson  * if possible.
258295968d1SFerruh Yigit  * The ethdev must be configured with RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO.
25999a2dd95SBruce Richardson  * Outer and inner checksums are done according to the existing flags like
260daa02b5cSOlivier Matz  * RTE_MBUF_F_TX_xxx_CKSUM.
26199a2dd95SBruce Richardson  * Specific tunnel headers that contain payload length, sequence id
26299a2dd95SBruce Richardson  * or checksum are not expected to be updated.
26399a2dd95SBruce Richardson  */
264daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_UDP (0xEULL << 45)
26599a2dd95SBruce Richardson /* add new TX TUNNEL type here */
266daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TUNNEL_MASK    (0xFULL << 45)
267daa02b5cSOlivier Matz 
26899a2dd95SBruce Richardson /**
26999a2dd95SBruce Richardson  * Double VLAN insertion (QinQ) request to driver, driver may offload the
27099a2dd95SBruce Richardson  * insertion based on device capability.
27199a2dd95SBruce Richardson  * mbuf 'vlan_tci' & 'vlan_tci_outer' must be valid when this flag is set.
27299a2dd95SBruce Richardson  */
273daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_QINQ        (1ULL << 49)
27499a2dd95SBruce Richardson 
27599a2dd95SBruce Richardson /**
27699a2dd95SBruce Richardson  * TCP segmentation offload. To enable this offload feature for a
27799a2dd95SBruce Richardson  * packet to be transmitted on hardware supporting TSO:
278daa02b5cSOlivier Matz  *  - set the RTE_MBUF_F_TX_TCP_SEG flag in mbuf->ol_flags (this flag implies
279daa02b5cSOlivier Matz  *    RTE_MBUF_F_TX_TCP_CKSUM)
280daa02b5cSOlivier Matz  *  - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
281daa02b5cSOlivier Matz  *  - if it's IPv4, set the RTE_MBUF_F_TX_IP_CKSUM flag
28299a2dd95SBruce Richardson  *  - fill the mbuf offload information: l2_len, l3_len, l4_len, tso_segsz
28399a2dd95SBruce Richardson  */
284daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TCP_SEG       (1ULL << 50)
28599a2dd95SBruce Richardson 
28699a2dd95SBruce Richardson /** TX IEEE1588 packet to timestamp. */
287daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_IEEE1588_TMST (1ULL << 51)
28899a2dd95SBruce Richardson 
289daa02b5cSOlivier Matz /*
29099a2dd95SBruce Richardson  * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
29199a2dd95SBruce Richardson  * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
29299a2dd95SBruce Richardson  * L4 checksum offload, the user needs to:
29399a2dd95SBruce Richardson  *  - fill l2_len and l3_len in mbuf
294daa02b5cSOlivier Matz  *  - set the flags RTE_MBUF_F_TX_TCP_CKSUM, RTE_MBUF_F_TX_SCTP_CKSUM or
295daa02b5cSOlivier Matz  *    RTE_MBUF_F_TX_UDP_CKSUM
296daa02b5cSOlivier Matz  *  - set the flag RTE_MBUF_F_TX_IPV4 or RTE_MBUF_F_TX_IPV6
29799a2dd95SBruce Richardson  */
298daa02b5cSOlivier Matz 
299daa02b5cSOlivier Matz /** Disable L4 cksum of TX pkt. */
300daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_L4_NO_CKSUM   (0ULL << 52)
30199a2dd95SBruce Richardson 
30299a2dd95SBruce Richardson /** TCP cksum of TX pkt. computed by NIC. */
303daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_TCP_CKSUM     (1ULL << 52)
30499a2dd95SBruce Richardson 
30599a2dd95SBruce Richardson /** SCTP cksum of TX pkt. computed by NIC. */
306daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_SCTP_CKSUM    (2ULL << 52)
30799a2dd95SBruce Richardson 
30899a2dd95SBruce Richardson /** UDP cksum of TX pkt. computed by NIC. */
309daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_UDP_CKSUM     (3ULL << 52)
31099a2dd95SBruce Richardson 
31199a2dd95SBruce Richardson /** Mask for L4 cksum offload request. */
312daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_L4_MASK       (3ULL << 52)
313daa02b5cSOlivier Matz 
31499a2dd95SBruce Richardson /**
315daa02b5cSOlivier Matz  * Offload the IP checksum in the hardware. The flag RTE_MBUF_F_TX_IPV4 should
31699a2dd95SBruce Richardson  * also be set by the application, although a PMD will only check
317daa02b5cSOlivier Matz  * RTE_MBUF_F_TX_IP_CKSUM.
31899a2dd95SBruce Richardson  *  - fill the mbuf offload information: l2_len, l3_len
31999a2dd95SBruce Richardson  */
320daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_IP_CKSUM      (1ULL << 54)
32199a2dd95SBruce Richardson 
32299a2dd95SBruce Richardson /**
32399a2dd95SBruce Richardson  * Packet is IPv4. This flag must be set when using any offload feature
32499a2dd95SBruce Richardson  * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
32599a2dd95SBruce Richardson  * packet. If the packet is a tunneled packet, this flag is related to
32699a2dd95SBruce Richardson  * the inner headers.
32799a2dd95SBruce Richardson  */
328daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_IPV4          (1ULL << 55)
32999a2dd95SBruce Richardson 
33099a2dd95SBruce Richardson /**
33199a2dd95SBruce Richardson  * Packet is IPv6. This flag must be set when using an offload feature
33299a2dd95SBruce Richardson  * (TSO or L4 checksum) to tell the NIC that the packet is an IPv6
33399a2dd95SBruce Richardson  * packet. If the packet is a tunneled packet, this flag is related to
33499a2dd95SBruce Richardson  * the inner headers.
33599a2dd95SBruce Richardson  */
336daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_IPV6          (1ULL << 56)
33799a2dd95SBruce Richardson 
33899a2dd95SBruce Richardson /**
33999a2dd95SBruce Richardson  * VLAN tag insertion request to driver, driver may offload the insertion
34099a2dd95SBruce Richardson  * based on the device capability.
34199a2dd95SBruce Richardson  * mbuf 'vlan_tci' field must be valid when this flag is set.
34299a2dd95SBruce Richardson  */
343daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_VLAN          (1ULL << 57)
34499a2dd95SBruce Richardson 
34599a2dd95SBruce Richardson /**
34699a2dd95SBruce Richardson  * Offload the IP checksum of an external header in the hardware. The
347daa02b5cSOlivier Matz  * flag RTE_MBUF_F_TX_OUTER_IPV4 should also be set by the application, although
348daa02b5cSOlivier Matz  * a PMD will only check RTE_MBUF_F_TX_OUTER_IP_CKSUM.
34999a2dd95SBruce Richardson  *  - fill the mbuf offload information: outer_l2_len, outer_l3_len
35099a2dd95SBruce Richardson  */
351daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_OUTER_IP_CKSUM   (1ULL << 58)
35299a2dd95SBruce Richardson 
35399a2dd95SBruce Richardson /**
35499a2dd95SBruce Richardson  * Packet outer header is IPv4. This flag must be set when using any
35599a2dd95SBruce Richardson  * outer offload feature (L3 or L4 checksum) to tell the NIC that the
35699a2dd95SBruce Richardson  * outer header of the tunneled packet is an IPv4 packet.
35799a2dd95SBruce Richardson  */
358daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_OUTER_IPV4   (1ULL << 59)
35999a2dd95SBruce Richardson 
36099a2dd95SBruce Richardson /**
36199a2dd95SBruce Richardson  * Packet outer header is IPv6. This flag must be set when using any
36299a2dd95SBruce Richardson  * outer offload feature (L4 checksum) to tell the NIC that the outer
36399a2dd95SBruce Richardson  * header of the tunneled packet is an IPv6 packet.
36499a2dd95SBruce Richardson  */
365daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_OUTER_IPV6    (1ULL << 60)
36699a2dd95SBruce Richardson 
36799a2dd95SBruce Richardson /**
36899a2dd95SBruce Richardson  * Bitmask of all supported packet Tx offload features flags,
36999a2dd95SBruce Richardson  * which can be set for packet.
37099a2dd95SBruce Richardson  */
371daa02b5cSOlivier Matz #define RTE_MBUF_F_TX_OFFLOAD_MASK (    \
372daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_OUTER_IPV6 |	 \
373daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_OUTER_IPV4 |	 \
374daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_OUTER_IP_CKSUM |  \
375daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_VLAN |        \
376daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_IPV6 |		 \
377daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_IPV4 |		 \
378daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_IP_CKSUM |        \
379daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_L4_MASK |         \
380daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_IEEE1588_TMST |	 \
381daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_TCP_SEG |         \
382daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_QINQ |        \
383daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_TUNNEL_MASK |	 \
384daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_MACSEC |		 \
385daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_SEC_OFFLOAD |	 \
386daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_UDP_SEG |	 \
387daa02b5cSOlivier Matz 		RTE_MBUF_F_TX_OUTER_UDP_CKSUM)
38899a2dd95SBruce Richardson 
38999a2dd95SBruce Richardson /**
39099a2dd95SBruce Richardson  * Mbuf having an external buffer attached. shinfo in mbuf must be filled.
39199a2dd95SBruce Richardson  */
392daa02b5cSOlivier Matz #define RTE_MBUF_F_EXTERNAL    (1ULL << 61)
39399a2dd95SBruce Richardson 
394daa02b5cSOlivier Matz #define RTE_MBUF_F_INDIRECT    (1ULL << 62) /**< Indirect attached mbuf */
39599a2dd95SBruce Richardson 
39699a2dd95SBruce Richardson /** Alignment constraint of mbuf private area. */
39799a2dd95SBruce Richardson #define RTE_MBUF_PRIV_ALIGN 8
39899a2dd95SBruce Richardson 
39999a2dd95SBruce Richardson /**
40099a2dd95SBruce Richardson  * Some NICs need at least 2KB buffer to RX standard Ethernet frame without
40199a2dd95SBruce Richardson  * splitting it into multiple segments.
40299a2dd95SBruce Richardson  * So, for mbufs that planned to be involved into RX/TX, the recommended
40399a2dd95SBruce Richardson  * minimal buffer length is 2KB + RTE_PKTMBUF_HEADROOM.
40499a2dd95SBruce Richardson  */
40599a2dd95SBruce Richardson #define	RTE_MBUF_DEFAULT_DATAROOM	2048
40699a2dd95SBruce Richardson #define	RTE_MBUF_DEFAULT_BUF_SIZE	\
40799a2dd95SBruce Richardson 	(RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
40899a2dd95SBruce Richardson 
40999a2dd95SBruce Richardson struct rte_mbuf_sched {
41099a2dd95SBruce Richardson 	uint32_t queue_id;   /**< Queue ID. */
41199a2dd95SBruce Richardson 	uint8_t traffic_class;
41299a2dd95SBruce Richardson 	/**< Traffic class ID. Traffic class 0
41399a2dd95SBruce Richardson 	 * is the highest priority traffic class.
41499a2dd95SBruce Richardson 	 */
41599a2dd95SBruce Richardson 	uint8_t color;
41699a2dd95SBruce Richardson 	/**< Color. @see enum rte_color.*/
41799a2dd95SBruce Richardson 	uint16_t reserved;   /**< Reserved. */
41899a2dd95SBruce Richardson }; /**< Hierarchical scheduler */
41999a2dd95SBruce Richardson 
42099a2dd95SBruce Richardson /**
42199a2dd95SBruce Richardson  * enum for the tx_offload bit-fields lengths and offsets.
42299a2dd95SBruce Richardson  * defines the layout of rte_mbuf tx_offload field.
42399a2dd95SBruce Richardson  */
42499a2dd95SBruce Richardson enum {
42599a2dd95SBruce Richardson 	RTE_MBUF_L2_LEN_BITS = 7,
42699a2dd95SBruce Richardson 	RTE_MBUF_L3_LEN_BITS = 9,
42799a2dd95SBruce Richardson 	RTE_MBUF_L4_LEN_BITS = 8,
42899a2dd95SBruce Richardson 	RTE_MBUF_TSO_SEGSZ_BITS = 16,
42999a2dd95SBruce Richardson 	RTE_MBUF_OUTL3_LEN_BITS = 9,
43099a2dd95SBruce Richardson 	RTE_MBUF_OUTL2_LEN_BITS = 7,
43199a2dd95SBruce Richardson 	RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
43299a2dd95SBruce Richardson 		RTE_MBUF_L2_LEN_BITS -
43399a2dd95SBruce Richardson 		RTE_MBUF_L3_LEN_BITS -
43499a2dd95SBruce Richardson 		RTE_MBUF_L4_LEN_BITS -
43599a2dd95SBruce Richardson 		RTE_MBUF_TSO_SEGSZ_BITS -
43699a2dd95SBruce Richardson 		RTE_MBUF_OUTL3_LEN_BITS -
43799a2dd95SBruce Richardson 		RTE_MBUF_OUTL2_LEN_BITS,
43899a2dd95SBruce Richardson #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
43999a2dd95SBruce Richardson 	RTE_MBUF_L2_LEN_OFS =
44099a2dd95SBruce Richardson 		sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
44199a2dd95SBruce Richardson 	RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
44299a2dd95SBruce Richardson 	RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
44399a2dd95SBruce Richardson 	RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
44499a2dd95SBruce Richardson 	RTE_MBUF_OUTL3_LEN_OFS =
44599a2dd95SBruce Richardson 		RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
44699a2dd95SBruce Richardson 	RTE_MBUF_OUTL2_LEN_OFS =
44799a2dd95SBruce Richardson 		RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
44899a2dd95SBruce Richardson 	RTE_MBUF_TXOFLD_UNUSED_OFS =
44999a2dd95SBruce Richardson 		RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
45099a2dd95SBruce Richardson #else
45199a2dd95SBruce Richardson 	RTE_MBUF_L2_LEN_OFS = 0,
45299a2dd95SBruce Richardson 	RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
45399a2dd95SBruce Richardson 	RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
45499a2dd95SBruce Richardson 	RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
45599a2dd95SBruce Richardson 	RTE_MBUF_OUTL3_LEN_OFS =
45699a2dd95SBruce Richardson 		RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
45799a2dd95SBruce Richardson 	RTE_MBUF_OUTL2_LEN_OFS =
45899a2dd95SBruce Richardson 		RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
45999a2dd95SBruce Richardson 	RTE_MBUF_TXOFLD_UNUSED_OFS =
46099a2dd95SBruce Richardson 		RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
46199a2dd95SBruce Richardson #endif
46299a2dd95SBruce Richardson };
46399a2dd95SBruce Richardson 
46499a2dd95SBruce Richardson /**
46599a2dd95SBruce Richardson  * The generic rte_mbuf, containing a packet mbuf.
46699a2dd95SBruce Richardson  */
467c6552d9aSTyler Retzlaff struct __rte_cache_aligned rte_mbuf {
46899a2dd95SBruce Richardson 	void *buf_addr;           /**< Virtual address of segment buffer. */
469d5d9e8feSThomas Monjalon #if RTE_IOVA_IN_MBUF
47099a2dd95SBruce Richardson 	/**
47199a2dd95SBruce Richardson 	 * Physical address of segment buffer.
472a986c2b7SShijith Thotton 	 * This field is undefined if the build is configured to use only
473d5d9e8feSThomas Monjalon 	 * virtual address as IOVA (i.e. RTE_IOVA_IN_MBUF is 0).
47499a2dd95SBruce Richardson 	 * Force alignment to 8-bytes, so as to ensure we have the exact
475*9e152e67STyler Retzlaff 	 * layout for the first cache line for 32-bit and 64-bit. This makes
47699a2dd95SBruce Richardson 	 * working on vector drivers easier.
47799a2dd95SBruce Richardson 	 */
478e9fd1ebfSTyler Retzlaff 	alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
479a986c2b7SShijith Thotton #else
48003b57eb7SShijith Thotton 	/**
4815812b327SShijith Thotton 	 * Next segment of scattered packet.
4825812b327SShijith Thotton 	 * This field is valid when physical address field is undefined.
4835812b327SShijith Thotton 	 * Otherwise next pointer in the second cache line will be used.
48403b57eb7SShijith Thotton 	 */
4855812b327SShijith Thotton 	struct rte_mbuf *next;
486a986c2b7SShijith Thotton #endif
48799a2dd95SBruce Richardson 
48899a2dd95SBruce Richardson 	/* next 8 bytes are initialised on RX descriptor rearm */
489*9e152e67STyler Retzlaff 	union {
490*9e152e67STyler Retzlaff 		uint64_t rearm_data[1];
491*9e152e67STyler Retzlaff 		__extension__
492*9e152e67STyler Retzlaff 		struct {
49399a2dd95SBruce Richardson 			uint16_t data_off;
49499a2dd95SBruce Richardson 
49599a2dd95SBruce Richardson 			/**
49699a2dd95SBruce Richardson 			 * Reference counter. Its size should at least equal to the size
49799a2dd95SBruce Richardson 			 * of port field (16 bits), to support zero-copy broadcast.
49899a2dd95SBruce Richardson 			 * It should only be accessed using the following functions:
49999a2dd95SBruce Richardson 			 * rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and
50099a2dd95SBruce Richardson 			 * rte_mbuf_refcnt_set(). The functionality of these functions (atomic,
50199a2dd95SBruce Richardson 			 * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
50299a2dd95SBruce Richardson 			 */
5039bcb34d4STyler Retzlaff 			RTE_ATOMIC(uint16_t) refcnt;
504efc6f910SOlivier Matz 
505efc6f910SOlivier Matz 			/**
506efc6f910SOlivier Matz 			 * Number of segments. Only valid for the first segment of an mbuf
507efc6f910SOlivier Matz 			 * chain.
508efc6f910SOlivier Matz 			 */
509efc6f910SOlivier Matz 			uint16_t nb_segs;
51099a2dd95SBruce Richardson 
51199a2dd95SBruce Richardson 			/** Input port (16 bits to support more than 256 virtual ports).
51299a2dd95SBruce Richardson 			 * The event eth Tx adapter uses this field to specify the output port.
51399a2dd95SBruce Richardson 			 */
51499a2dd95SBruce Richardson 			uint16_t port;
515*9e152e67STyler Retzlaff 		};
516*9e152e67STyler Retzlaff 	};
51799a2dd95SBruce Richardson 
51899a2dd95SBruce Richardson 	uint64_t ol_flags;        /**< Offload features. */
51999a2dd95SBruce Richardson 
520*9e152e67STyler Retzlaff 	/* remaining 24 bytes are set on RX when pulling packet from descriptor */
521*9e152e67STyler Retzlaff 	union {
522*9e152e67STyler Retzlaff 		/* void * type of the array elements is retained for driver compatibility. */
523*9e152e67STyler Retzlaff 		void *rx_descriptor_fields1[24 / sizeof(void *)];
524*9e152e67STyler Retzlaff 		__extension__
525*9e152e67STyler Retzlaff 		struct {
52699a2dd95SBruce Richardson 			/*
52799a2dd95SBruce Richardson 			 * The packet type, which is the combination of outer/inner L2, L3, L4
52899a2dd95SBruce Richardson 			 * and tunnel types. The packet_type is about data really present in the
52999a2dd95SBruce Richardson 			 * mbuf. Example: if vlan stripping is enabled, a received vlan packet
53099a2dd95SBruce Richardson 			 * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
53199a2dd95SBruce Richardson 			 * vlan is stripped from the data.
53299a2dd95SBruce Richardson 			 */
53399a2dd95SBruce Richardson 			union {
53499a2dd95SBruce Richardson 				uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */
53599a2dd95SBruce Richardson 				__extension__
53699a2dd95SBruce Richardson 				struct {
53799a2dd95SBruce Richardson 					uint8_t l2_type:4;   /**< (Outer) L2 type. */
53899a2dd95SBruce Richardson 					uint8_t l3_type:4;   /**< (Outer) L3 type. */
53999a2dd95SBruce Richardson 					uint8_t l4_type:4;   /**< (Outer) L4 type. */
54099a2dd95SBruce Richardson 					uint8_t tun_type:4;  /**< Tunnel type. */
54199a2dd95SBruce Richardson 					union {
54299a2dd95SBruce Richardson 						uint8_t inner_esp_next_proto;
54399a2dd95SBruce Richardson 						/**< ESP next protocol type, valid if
54499a2dd95SBruce Richardson 						 * RTE_PTYPE_TUNNEL_ESP tunnel type is set
54599a2dd95SBruce Richardson 						 * on both Tx and Rx.
54699a2dd95SBruce Richardson 						 */
54799a2dd95SBruce Richardson 						__extension__
54899a2dd95SBruce Richardson 						struct {
54999a2dd95SBruce Richardson 							uint8_t inner_l2_type:4;
55099a2dd95SBruce Richardson 							/**< Inner L2 type. */
55199a2dd95SBruce Richardson 							uint8_t inner_l3_type:4;
55299a2dd95SBruce Richardson 							/**< Inner L3 type. */
55399a2dd95SBruce Richardson 						};
55499a2dd95SBruce Richardson 					};
55599a2dd95SBruce Richardson 					uint8_t inner_l4_type:4; /**< Inner L4 type. */
55699a2dd95SBruce Richardson 				};
55799a2dd95SBruce Richardson 			};
55899a2dd95SBruce Richardson 
55999a2dd95SBruce Richardson 			uint32_t pkt_len;         /**< Total pkt len: sum of all segments. */
56099a2dd95SBruce Richardson 			uint16_t data_len;        /**< Amount of data in segment buffer. */
561daa02b5cSOlivier Matz 			/** VLAN TCI (CPU order), valid if RTE_MBUF_F_RX_VLAN is set. */
56299a2dd95SBruce Richardson 			uint16_t vlan_tci;
56399a2dd95SBruce Richardson 
56499a2dd95SBruce Richardson 			union {
56599a2dd95SBruce Richardson 				union {
56699a2dd95SBruce Richardson 					uint32_t rss;     /**< RSS hash result if RSS enabled */
56799a2dd95SBruce Richardson 					struct {
56899a2dd95SBruce Richardson 						union {
56999a2dd95SBruce Richardson 							struct {
57099a2dd95SBruce Richardson 								uint16_t hash;
57199a2dd95SBruce Richardson 								uint16_t id;
57299a2dd95SBruce Richardson 							};
57399a2dd95SBruce Richardson 							uint32_t lo;
57499a2dd95SBruce Richardson 							/**< Second 4 flexible bytes */
57599a2dd95SBruce Richardson 						};
57699a2dd95SBruce Richardson 						uint32_t hi;
57799a2dd95SBruce Richardson 						/**< First 4 flexible bytes or FD ID, dependent
578daa02b5cSOlivier Matz 						 * on RTE_MBUF_F_RX_FDIR_* flag in ol_flags.
57999a2dd95SBruce Richardson 						 */
58099a2dd95SBruce Richardson 					} fdir;	/**< Filter identifier if FDIR enabled */
58199a2dd95SBruce Richardson 					struct rte_mbuf_sched sched;
58299a2dd95SBruce Richardson 					/**< Hierarchical scheduler : 8 bytes */
58399a2dd95SBruce Richardson 					struct {
58499a2dd95SBruce Richardson 						uint32_t reserved1;
58599a2dd95SBruce Richardson 						uint16_t reserved2;
58699a2dd95SBruce Richardson 						uint16_t txq;
58799a2dd95SBruce Richardson 						/**< The event eth Tx adapter uses this field
58899a2dd95SBruce Richardson 						 * to store Tx queue id.
58999a2dd95SBruce Richardson 						 * @see rte_event_eth_tx_adapter_txq_set()
59099a2dd95SBruce Richardson 						 */
59199a2dd95SBruce Richardson 					} txadapter; /**< Eventdev ethdev Tx adapter */
59299a2dd95SBruce Richardson 					uint32_t usr;
593b3a16023SDavid Marchand 					/**< User defined tags. See rte_distributor_process() */
59499a2dd95SBruce Richardson 				} hash;                   /**< hash information */
59599a2dd95SBruce Richardson 			};
59699a2dd95SBruce Richardson 
597daa02b5cSOlivier Matz 			/** Outer VLAN TCI (CPU order), valid if RTE_MBUF_F_RX_QINQ is set. */
59899a2dd95SBruce Richardson 			uint16_t vlan_tci_outer;
59999a2dd95SBruce Richardson 
60099a2dd95SBruce Richardson 			uint16_t buf_len;         /**< Length of segment buffer. */
601*9e152e67STyler Retzlaff 		};
602*9e152e67STyler Retzlaff 	};
60399a2dd95SBruce Richardson 
60499a2dd95SBruce Richardson 	struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
60599a2dd95SBruce Richardson 
60699a2dd95SBruce Richardson 	/* second cache line - fields only used in slow path or on TX */
607d5d9e8feSThomas Monjalon #if RTE_IOVA_IN_MBUF
608efc6f910SOlivier Matz 	/**
6095812b327SShijith Thotton 	 * Next segment of scattered packet. Must be NULL in the last
6105812b327SShijith Thotton 	 * segment or in case of non-segmented packet.
611efc6f910SOlivier Matz 	 */
612*9e152e67STyler Retzlaff 	alignas(RTE_CACHE_LINE_MIN_SIZE)
613efc6f910SOlivier Matz 	struct rte_mbuf *next;
6145812b327SShijith Thotton #else
6155812b327SShijith Thotton 	/**
6165812b327SShijith Thotton 	 * Reserved for dynamic fields
617d5d9e8feSThomas Monjalon 	 * when the next pointer is in first cache line (i.e. RTE_IOVA_IN_MBUF is 0).
6185812b327SShijith Thotton 	 */
619*9e152e67STyler Retzlaff 	alignas(RTE_CACHE_LINE_MIN_SIZE)
6205812b327SShijith Thotton 	uint64_t dynfield2;
6215812b327SShijith Thotton #endif
62299a2dd95SBruce Richardson 
62399a2dd95SBruce Richardson 	/* fields to support TX offloads */
62499a2dd95SBruce Richardson 	union {
62599a2dd95SBruce Richardson 		uint64_t tx_offload;       /**< combined for easy fetch */
62699a2dd95SBruce Richardson 		__extension__
62799a2dd95SBruce Richardson 		struct {
62899a2dd95SBruce Richardson 			uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
62999a2dd95SBruce Richardson 			/**< L2 (MAC) Header Length for non-tunneling pkt.
63099a2dd95SBruce Richardson 			 * Outer_L4_len + ... + Inner_L2_len for tunneling pkt.
63199a2dd95SBruce Richardson 			 */
63299a2dd95SBruce Richardson 			uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
63399a2dd95SBruce Richardson 			/**< L3 (IP) Header Length. */
63499a2dd95SBruce Richardson 			uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
63599a2dd95SBruce Richardson 			/**< L4 (TCP/UDP) Header Length. */
63699a2dd95SBruce Richardson 			uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
63799a2dd95SBruce Richardson 			/**< TCP TSO segment size */
63899a2dd95SBruce Richardson 
63999a2dd95SBruce Richardson 			/*
64099a2dd95SBruce Richardson 			 * Fields for Tx offloading of tunnels.
64199a2dd95SBruce Richardson 			 * These are undefined for packets which don't request
64299a2dd95SBruce Richardson 			 * any tunnel offloads (outer IP or UDP checksum,
64399a2dd95SBruce Richardson 			 * tunnel TSO).
64499a2dd95SBruce Richardson 			 *
64599a2dd95SBruce Richardson 			 * PMDs should not use these fields unconditionally
64699a2dd95SBruce Richardson 			 * when calculating offsets.
64799a2dd95SBruce Richardson 			 *
64899a2dd95SBruce Richardson 			 * Applications are expected to set appropriate tunnel
64999a2dd95SBruce Richardson 			 * offload flags when they fill in these fields.
65099a2dd95SBruce Richardson 			 */
65199a2dd95SBruce Richardson 			uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
65299a2dd95SBruce Richardson 			/**< Outer L3 (IP) Hdr Length. */
65399a2dd95SBruce Richardson 			uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
65499a2dd95SBruce Richardson 			/**< Outer L2 (MAC) Hdr Length. */
65599a2dd95SBruce Richardson 
65699a2dd95SBruce Richardson 			/* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
65799a2dd95SBruce Richardson 		};
65899a2dd95SBruce Richardson 	};
65999a2dd95SBruce Richardson 
66099a2dd95SBruce Richardson 	/** Shared data for external buffer attached to mbuf. See
66199a2dd95SBruce Richardson 	 * rte_pktmbuf_attach_extbuf().
66299a2dd95SBruce Richardson 	 */
66399a2dd95SBruce Richardson 	struct rte_mbuf_ext_shared_info *shinfo;
66499a2dd95SBruce Richardson 
66599a2dd95SBruce Richardson 	/** Size of the application private data. In case of an indirect
66699a2dd95SBruce Richardson 	 * mbuf, it stores the direct mbuf private data size.
66799a2dd95SBruce Richardson 	 */
66899a2dd95SBruce Richardson 	uint16_t priv_size;
66999a2dd95SBruce Richardson 
67099a2dd95SBruce Richardson 	/** Timesync flags for use with IEEE1588. */
67199a2dd95SBruce Richardson 	uint16_t timesync;
67299a2dd95SBruce Richardson 
67399a2dd95SBruce Richardson 	uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
674c6552d9aSTyler Retzlaff };
67599a2dd95SBruce Richardson 
67699a2dd95SBruce Richardson /**
67799a2dd95SBruce Richardson  * Function typedef of callback to free externally attached buffer.
67899a2dd95SBruce Richardson  */
67999a2dd95SBruce Richardson typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
68099a2dd95SBruce Richardson 
68199a2dd95SBruce Richardson /**
68299a2dd95SBruce Richardson  * Shared data at the end of an external buffer.
68399a2dd95SBruce Richardson  */
68499a2dd95SBruce Richardson struct rte_mbuf_ext_shared_info {
68599a2dd95SBruce Richardson 	rte_mbuf_extbuf_free_callback_t free_cb; /**< Free callback function */
68699a2dd95SBruce Richardson 	void *fcb_opaque;                        /**< Free callback argument */
6879bcb34d4STyler Retzlaff 	RTE_ATOMIC(uint16_t) refcnt;
68899a2dd95SBruce Richardson };
68999a2dd95SBruce Richardson 
69099a2dd95SBruce Richardson /** Maximum number of nb_segs allowed. */
69199a2dd95SBruce Richardson #define RTE_MBUF_MAX_NB_SEGS	UINT16_MAX
69299a2dd95SBruce Richardson 
69399a2dd95SBruce Richardson /**
69499a2dd95SBruce Richardson  * Returns TRUE if given mbuf is cloned by mbuf indirection, or FALSE
69599a2dd95SBruce Richardson  * otherwise.
69699a2dd95SBruce Richardson  *
69799a2dd95SBruce Richardson  * If a mbuf has its data in another mbuf and references it by mbuf
69899a2dd95SBruce Richardson  * indirection, this mbuf can be defined as a cloned mbuf.
69999a2dd95SBruce Richardson  */
700daa02b5cSOlivier Matz #define RTE_MBUF_CLONED(mb)     ((mb)->ol_flags & RTE_MBUF_F_INDIRECT)
70199a2dd95SBruce Richardson 
70299a2dd95SBruce Richardson /**
70399a2dd95SBruce Richardson  * Returns TRUE if given mbuf has an external buffer, or FALSE otherwise.
70499a2dd95SBruce Richardson  *
70599a2dd95SBruce Richardson  * External buffer is a user-provided anonymous buffer.
70699a2dd95SBruce Richardson  */
707daa02b5cSOlivier Matz #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & RTE_MBUF_F_EXTERNAL)
70899a2dd95SBruce Richardson 
70999a2dd95SBruce Richardson /**
71099a2dd95SBruce Richardson  * Returns TRUE if given mbuf is direct, or FALSE otherwise.
71199a2dd95SBruce Richardson  *
71299a2dd95SBruce Richardson  * If a mbuf embeds its own data after the rte_mbuf structure, this mbuf
71399a2dd95SBruce Richardson  * can be defined as a direct mbuf.
71499a2dd95SBruce Richardson  */
71599a2dd95SBruce Richardson #define RTE_MBUF_DIRECT(mb) \
716daa02b5cSOlivier Matz 	(!((mb)->ol_flags & (RTE_MBUF_F_INDIRECT | RTE_MBUF_F_EXTERNAL)))
71799a2dd95SBruce Richardson 
71899a2dd95SBruce Richardson /** Uninitialized or unspecified port. */
71999a2dd95SBruce Richardson #define RTE_MBUF_PORT_INVALID UINT16_MAX
72099a2dd95SBruce Richardson /** For backwards compatibility. */
72199a2dd95SBruce Richardson #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
72299a2dd95SBruce Richardson 
72399a2dd95SBruce Richardson /**
72499a2dd95SBruce Richardson  * A macro that points to an offset into the data in the mbuf.
72599a2dd95SBruce Richardson  *
72699a2dd95SBruce Richardson  * The returned pointer is cast to type t. Before using this
72799a2dd95SBruce Richardson  * function, the user must ensure that the first segment is large
72899a2dd95SBruce Richardson  * enough to accommodate its data.
72999a2dd95SBruce Richardson  *
73099a2dd95SBruce Richardson  * @param m
73199a2dd95SBruce Richardson  *   The packet mbuf.
73299a2dd95SBruce Richardson  * @param o
73399a2dd95SBruce Richardson  *   The offset into the mbuf data.
73499a2dd95SBruce Richardson  * @param t
73599a2dd95SBruce Richardson  *   The type to cast the result into.
73699a2dd95SBruce Richardson  */
73799a2dd95SBruce Richardson #define rte_pktmbuf_mtod_offset(m, t, o)	\
738da0333c8SEli Britstein 	((t)(void *)((char *)(m)->buf_addr + (m)->data_off + (o)))
73999a2dd95SBruce Richardson 
74099a2dd95SBruce Richardson /**
74199a2dd95SBruce Richardson  * A macro that points to the start of the data in the mbuf.
74299a2dd95SBruce Richardson  *
74399a2dd95SBruce Richardson  * The returned pointer is cast to type t. Before using this
74499a2dd95SBruce Richardson  * function, the user must ensure that the first segment is large
74599a2dd95SBruce Richardson  * enough to accommodate its data.
74699a2dd95SBruce Richardson  *
74799a2dd95SBruce Richardson  * @param m
74899a2dd95SBruce Richardson  *   The packet mbuf.
74999a2dd95SBruce Richardson  * @param t
75099a2dd95SBruce Richardson  *   The type to cast the result into.
75199a2dd95SBruce Richardson  */
75299a2dd95SBruce Richardson #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
75399a2dd95SBruce Richardson 
75499a2dd95SBruce Richardson /**
75599a2dd95SBruce Richardson  * A macro that returns the IO address that points to an offset of the
75699a2dd95SBruce Richardson  * start of the data in the mbuf
75799a2dd95SBruce Richardson  *
75899a2dd95SBruce Richardson  * @param m
75999a2dd95SBruce Richardson  *   The packet mbuf.
76099a2dd95SBruce Richardson  * @param o
76199a2dd95SBruce Richardson  *   The offset into the data to calculate address from.
76299a2dd95SBruce Richardson  */
76399a2dd95SBruce Richardson #define rte_pktmbuf_iova_offset(m, o) \
764e811e2d7SShijith Thotton 	(rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o))
76599a2dd95SBruce Richardson 
76699a2dd95SBruce Richardson /**
76799a2dd95SBruce Richardson  * A macro that returns the IO address that points to the start of the
76899a2dd95SBruce Richardson  * data in the mbuf
76999a2dd95SBruce Richardson  *
77099a2dd95SBruce Richardson  * @param m
77199a2dd95SBruce Richardson  *   The packet mbuf.
77299a2dd95SBruce Richardson  */
77399a2dd95SBruce Richardson #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
77499a2dd95SBruce Richardson 
77599a2dd95SBruce Richardson #ifdef __cplusplus
77699a2dd95SBruce Richardson }
77799a2dd95SBruce Richardson #endif
77899a2dd95SBruce Richardson 
77999a2dd95SBruce Richardson #endif /* _RTE_MBUF_CORE_H_ */
780