f7ead7b067b7a6ecf95ea95237543ca28002df86
[dpdk.git] / lib / mbuf / rte_mbuf_core.h
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
9 /**
10  * @file
11  * This file contains definion of RTE mbuf structure itself,
12  * packet offload flags and some related macros.
13  * For majority of DPDK entities, it is not recommended to include
14  * this file directly, use include <rte_mbuf.h> instead.
15  *
16  * New fields and flags should fit in the "dynamic space".
17  */
18
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
43 /**
44  * The RX packet is a 802.1q VLAN packet, and the tci has been
45  * saved in in mbuf->vlan_tci.
46  * If the flag PKT_RX_VLAN_STRIPPED is also present, the VLAN
47  * header has been stripped from mbuf data, else it is still
48  * present.
49  */
50 #define PKT_RX_VLAN          (1ULL << 0)
51
52 /** RX packet with RSS hash result. */
53 #define PKT_RX_RSS_HASH      (1ULL << 1)
54
55  /** RX packet with FDIR match indicate. */
56 #define PKT_RX_FDIR          (1ULL << 2)
57
58 /**
59  * This flag is set when the outermost IP header checksum is detected as
60  * wrong by the hardware.
61  */
62 #define PKT_RX_OUTER_IP_CKSUM_BAD (1ULL << 5)
63
64 /**
65  * A vlan has been stripped by the hardware and its tci is saved in
66  * mbuf->vlan_tci. This can only happen if vlan stripping is enabled
67  * in the RX configuration of the PMD.
68  * When PKT_RX_VLAN_STRIPPED is set, PKT_RX_VLAN must also be set.
69  */
70 #define PKT_RX_VLAN_STRIPPED (1ULL << 6)
71
72 /**
73  * Mask of bits used to determine the status of RX IP checksum.
74  * - PKT_RX_IP_CKSUM_UNKNOWN: no information about the RX IP checksum
75  * - PKT_RX_IP_CKSUM_BAD: the IP checksum in the packet is wrong
76  * - PKT_RX_IP_CKSUM_GOOD: the IP checksum in the packet is valid
77  * - PKT_RX_IP_CKSUM_NONE: the IP checksum is not correct in the packet
78  *   data, but the integrity of the IP header is verified.
79  */
80 #define PKT_RX_IP_CKSUM_MASK ((1ULL << 4) | (1ULL << 7))
81
82 #define PKT_RX_IP_CKSUM_UNKNOWN 0
83 #define PKT_RX_IP_CKSUM_BAD     (1ULL << 4)
84 #define PKT_RX_IP_CKSUM_GOOD    (1ULL << 7)
85 #define PKT_RX_IP_CKSUM_NONE    ((1ULL << 4) | (1ULL << 7))
86
87 /**
88  * Mask of bits used to determine the status of RX L4 checksum.
89  * - PKT_RX_L4_CKSUM_UNKNOWN: no information about the RX L4 checksum
90  * - PKT_RX_L4_CKSUM_BAD: the L4 checksum in the packet is wrong
91  * - PKT_RX_L4_CKSUM_GOOD: the L4 checksum in the packet is valid
92  * - PKT_RX_L4_CKSUM_NONE: the L4 checksum is not correct in the packet
93  *   data, but the integrity of the L4 data is verified.
94  */
95 #define PKT_RX_L4_CKSUM_MASK ((1ULL << 3) | (1ULL << 8))
96
97 #define PKT_RX_L4_CKSUM_UNKNOWN 0
98 #define PKT_RX_L4_CKSUM_BAD     (1ULL << 3)
99 #define PKT_RX_L4_CKSUM_GOOD    (1ULL << 8)
100 #define PKT_RX_L4_CKSUM_NONE    ((1ULL << 3) | (1ULL << 8))
101
102 /** RX IEEE1588 L2 Ethernet PT Packet. */
103 #define PKT_RX_IEEE1588_PTP  (1ULL << 9)
104
105 /** RX IEEE1588 L2/L4 timestamped packet.*/
106 #define PKT_RX_IEEE1588_TMST (1ULL << 10)
107
108 /** FD id reported if FDIR match. */
109 #define PKT_RX_FDIR_ID       (1ULL << 13)
110
111 /** Flexible bytes reported if FDIR match. */
112 #define PKT_RX_FDIR_FLX      (1ULL << 14)
113
114 /**
115  * The outer VLAN has been stripped by the hardware and its TCI is
116  * saved in mbuf->vlan_tci_outer.
117  * This can only happen if VLAN stripping is enabled in the Rx
118  * configuration of the PMD.
119  * When PKT_RX_QINQ_STRIPPED is set, the flags PKT_RX_VLAN and PKT_RX_QINQ
120  * must also be set.
121  *
122  * - If both PKT_RX_QINQ_STRIPPED and PKT_RX_VLAN_STRIPPED are set, the 2 VLANs
123  *   have been stripped by the hardware and their TCIs are saved in
124  *   mbuf->vlan_tci (inner) and mbuf->vlan_tci_outer (outer).
125  * - If PKT_RX_QINQ_STRIPPED is set and PKT_RX_VLAN_STRIPPED is unset, only the
126  *   outer VLAN is removed from packet data, but both tci are saved in
127  *   mbuf->vlan_tci (inner) and mbuf->vlan_tci_outer (outer).
128  */
129 #define PKT_RX_QINQ_STRIPPED (1ULL << 15)
130
131 /**
132  * When packets are coalesced by a hardware or virtual driver, this flag
133  * can be set in the RX mbuf, meaning that the m->tso_segsz field is
134  * valid and is set to the segment size of original packets.
135  */
136 #define PKT_RX_LRO           (1ULL << 16)
137
138 /* There is no flag defined at offset 17. It is free for any future use. */
139
140 /**
141  * Indicate that security offload processing was applied on the RX packet.
142  */
143 #define PKT_RX_SEC_OFFLOAD      (1ULL << 18)
144
145 /**
146  * Indicate that security offload processing failed on the RX packet.
147  */
148 #define PKT_RX_SEC_OFFLOAD_FAILED       (1ULL << 19)
149
150 /**
151  * The RX packet is a double VLAN, and the outer tci has been
152  * saved in mbuf->vlan_tci_outer. If this flag is set, PKT_RX_VLAN
153  * must also be set and the inner tci is saved in mbuf->vlan_tci.
154  * If the flag PKT_RX_QINQ_STRIPPED is also present, both VLANs
155  * headers have been stripped from mbuf data, else they are still
156  * present.
157  */
158 #define PKT_RX_QINQ          (1ULL << 20)
159
160 /**
161  * Mask of bits used to determine the status of outer RX L4 checksum.
162  * - PKT_RX_OUTER_L4_CKSUM_UNKNOWN: no info about the outer RX L4 checksum
163  * - PKT_RX_OUTER_L4_CKSUM_BAD: the outer L4 checksum in the packet is wrong
164  * - PKT_RX_OUTER_L4_CKSUM_GOOD: the outer L4 checksum in the packet is valid
165  * - PKT_RX_OUTER_L4_CKSUM_INVALID: invalid outer L4 checksum state.
166  *
167  * The detection of PKT_RX_OUTER_L4_CKSUM_GOOD shall be based on the given
168  * HW capability, At minimum, the PMD should support
169  * PKT_RX_OUTER_L4_CKSUM_UNKNOWN and PKT_RX_OUTER_L4_CKSUM_BAD states
170  * if the RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM offload is available.
171  */
172 #define PKT_RX_OUTER_L4_CKSUM_MASK      ((1ULL << 21) | (1ULL << 22))
173
174 #define PKT_RX_OUTER_L4_CKSUM_UNKNOWN   0
175 #define PKT_RX_OUTER_L4_CKSUM_BAD       (1ULL << 21)
176 #define PKT_RX_OUTER_L4_CKSUM_GOOD      (1ULL << 22)
177 #define PKT_RX_OUTER_L4_CKSUM_INVALID   ((1ULL << 21) | (1ULL << 22))
178
179 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
180
181 #define PKT_FIRST_FREE (1ULL << 23)
182 #define PKT_LAST_FREE (1ULL << 40)
183
184 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
185
186 /**
187  * Outer UDP checksum offload flag. This flag is used for enabling
188  * outer UDP checksum in PMD. To use outer UDP checksum, the user needs to
189  * 1) Enable the following in mbuf,
190  * a) Fill outer_l2_len and outer_l3_len in mbuf.
191  * b) Set the PKT_TX_OUTER_UDP_CKSUM flag.
192  * c) Set the PKT_TX_OUTER_IPV4 or PKT_TX_OUTER_IPV6 flag.
193  * 2) Configure RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM offload flag.
194  */
195 #define PKT_TX_OUTER_UDP_CKSUM     (1ULL << 41)
196
197 /**
198  * UDP Fragmentation Offload flag. This flag is used for enabling UDP
199  * fragmentation in SW or in HW. When use UFO, mbuf->tso_segsz is used
200  * to store the MSS of UDP fragments.
201  */
202 #define PKT_TX_UDP_SEG  (1ULL << 42)
203
204 /**
205  * Request security offload processing on the TX packet.
206  * To use Tx security offload, the user needs to fill l2_len in mbuf
207  * indicating L2 header size and where L3 header starts.
208  */
209 #define PKT_TX_SEC_OFFLOAD      (1ULL << 43)
210
211 /**
212  * Offload the MACsec. This flag must be set by the application to enable
213  * this offload feature for a packet to be transmitted.
214  */
215 #define PKT_TX_MACSEC        (1ULL << 44)
216
217 /**
218  * Bits 45:48 used for the tunnel type.
219  * The tunnel type must be specified for TSO or checksum on the inner part
220  * of tunnel packets.
221  * These flags can be used with PKT_TX_TCP_SEG for TSO, or PKT_TX_xxx_CKSUM.
222  * The mbuf fields for inner and outer header lengths are required:
223  * outer_l2_len, outer_l3_len, l2_len, l3_len, l4_len and tso_segsz for TSO.
224  */
225 #define PKT_TX_TUNNEL_VXLAN   (0x1ULL << 45)
226 #define PKT_TX_TUNNEL_GRE     (0x2ULL << 45)
227 #define PKT_TX_TUNNEL_IPIP    (0x3ULL << 45)
228 #define PKT_TX_TUNNEL_GENEVE  (0x4ULL << 45)
229 /** TX packet with MPLS-in-UDP RFC 7510 header. */
230 #define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)
231 #define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)
232 #define PKT_TX_TUNNEL_GTP       (0x7ULL << 45)
233 #define PKT_TX_TUNNEL_ESP       (0x8ULL << 45)
234 /**
235  * Generic IP encapsulated tunnel type, used for TSO and checksum offload.
236  * It can be used for tunnels which are not standards or listed above.
237  * It is preferred to use specific tunnel flags like PKT_TX_TUNNEL_GRE
238  * or PKT_TX_TUNNEL_IPIP if possible.
239  * The ethdev must be configured with RTE_ETH_TX_OFFLOAD_IP_TNL_TSO.
240  * Outer and inner checksums are done according to the existing flags like
241  * PKT_TX_xxx_CKSUM.
242  * Specific tunnel headers that contain payload length, sequence id
243  * or checksum are not expected to be updated.
244  */
245 #define PKT_TX_TUNNEL_IP (0xDULL << 45)
246 /**
247  * Generic UDP encapsulated tunnel type, used for TSO and checksum offload.
248  * UDP tunnel type implies outer IP layer.
249  * It can be used for tunnels which are not standards or listed above.
250  * It is preferred to use specific tunnel flags like PKT_TX_TUNNEL_VXLAN
251  * if possible.
252  * The ethdev must be configured with RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO.
253  * Outer and inner checksums are done according to the existing flags like
254  * PKT_TX_xxx_CKSUM.
255  * Specific tunnel headers that contain payload length, sequence id
256  * or checksum are not expected to be updated.
257  */
258 #define PKT_TX_TUNNEL_UDP (0xEULL << 45)
259 /* add new TX TUNNEL type here */
260 #define PKT_TX_TUNNEL_MASK    (0xFULL << 45)
261
262 /**
263  * Double VLAN insertion (QinQ) request to driver, driver may offload the
264  * insertion based on device capability.
265  * mbuf 'vlan_tci' & 'vlan_tci_outer' must be valid when this flag is set.
266  */
267 #define PKT_TX_QINQ        (1ULL << 49)
268 /** This old name is deprecated. */
269 #define PKT_TX_QINQ_PKT RTE_DEPRECATED(PKT_TX_QINQ_PKT) PKT_TX_QINQ
270
271 /**
272  * TCP segmentation offload. To enable this offload feature for a
273  * packet to be transmitted on hardware supporting TSO:
274  *  - set the PKT_TX_TCP_SEG flag in mbuf->ol_flags (this flag implies
275  *    PKT_TX_TCP_CKSUM)
276  *  - set the flag PKT_TX_IPV4 or PKT_TX_IPV6
277  *  - if it's IPv4, set the PKT_TX_IP_CKSUM flag
278  *  - fill the mbuf offload information: l2_len, l3_len, l4_len, tso_segsz
279  */
280 #define PKT_TX_TCP_SEG       (1ULL << 50)
281
282 /** TX IEEE1588 packet to timestamp. */
283 #define PKT_TX_IEEE1588_TMST (1ULL << 51)
284
285 /**
286  * Bits 52+53 used for L4 packet type with checksum enabled: 00: Reserved,
287  * 01: TCP checksum, 10: SCTP checksum, 11: UDP checksum. To use hardware
288  * L4 checksum offload, the user needs to:
289  *  - fill l2_len and l3_len in mbuf
290  *  - set the flags PKT_TX_TCP_CKSUM, PKT_TX_SCTP_CKSUM or PKT_TX_UDP_CKSUM
291  *  - set the flag PKT_TX_IPV4 or PKT_TX_IPV6
292  */
293 #define PKT_TX_L4_NO_CKSUM   (0ULL << 52) /**< Disable L4 cksum of TX pkt. */
294
295 /** TCP cksum of TX pkt. computed by NIC. */
296 #define PKT_TX_TCP_CKSUM     (1ULL << 52)
297
298 /** SCTP cksum of TX pkt. computed by NIC. */
299 #define PKT_TX_SCTP_CKSUM    (2ULL << 52)
300
301 /** UDP cksum of TX pkt. computed by NIC. */
302 #define PKT_TX_UDP_CKSUM     (3ULL << 52)
303
304 /** Mask for L4 cksum offload request. */
305 #define PKT_TX_L4_MASK       (3ULL << 52)
306
307 /**
308  * Offload the IP checksum in the hardware. The flag PKT_TX_IPV4 should
309  * also be set by the application, although a PMD will only check
310  * PKT_TX_IP_CKSUM.
311  *  - fill the mbuf offload information: l2_len, l3_len
312  */
313 #define PKT_TX_IP_CKSUM      (1ULL << 54)
314
315 /**
316  * Packet is IPv4. This flag must be set when using any offload feature
317  * (TSO, L3 or L4 checksum) to tell the NIC that the packet is an IPv4
318  * packet. If the packet is a tunneled packet, this flag is related to
319  * the inner headers.
320  */
321 #define PKT_TX_IPV4          (1ULL << 55)
322
323 /**
324  * Packet is IPv6. This flag must be set when using an offload feature
325  * (TSO or L4 checksum) to tell the NIC that the packet is an IPv6
326  * packet. If the packet is a tunneled packet, this flag is related to
327  * the inner headers.
328  */
329 #define PKT_TX_IPV6          (1ULL << 56)
330
331 /**
332  * VLAN tag insertion request to driver, driver may offload the insertion
333  * based on the device capability.
334  * mbuf 'vlan_tci' field must be valid when this flag is set.
335  */
336 #define PKT_TX_VLAN          (1ULL << 57)
337 /* this old name is deprecated */
338 #define PKT_TX_VLAN_PKT RTE_DEPRECATED(PKT_TX_VLAN_PKT) PKT_TX_VLAN
339
340 /**
341  * Offload the IP checksum of an external header in the hardware. The
342  * flag PKT_TX_OUTER_IPV4 should also be set by the application, although
343  * a PMD will only check PKT_TX_OUTER_IP_CKSUM.
344  *  - fill the mbuf offload information: outer_l2_len, outer_l3_len
345  */
346 #define PKT_TX_OUTER_IP_CKSUM   (1ULL << 58)
347
348 /**
349  * Packet outer header is IPv4. This flag must be set when using any
350  * outer offload feature (L3 or L4 checksum) to tell the NIC that the
351  * outer header of the tunneled packet is an IPv4 packet.
352  */
353 #define PKT_TX_OUTER_IPV4   (1ULL << 59)
354
355 /**
356  * Packet outer header is IPv6. This flag must be set when using any
357  * outer offload feature (L4 checksum) to tell the NIC that the outer
358  * header of the tunneled packet is an IPv6 packet.
359  */
360 #define PKT_TX_OUTER_IPV6    (1ULL << 60)
361
362 /**
363  * Bitmask of all supported packet Tx offload features flags,
364  * which can be set for packet.
365  */
366 #define PKT_TX_OFFLOAD_MASK (    \
367                 PKT_TX_OUTER_IPV6 |      \
368                 PKT_TX_OUTER_IPV4 |      \
369                 PKT_TX_OUTER_IP_CKSUM |  \
370                 PKT_TX_VLAN |        \
371                 PKT_TX_IPV6 |            \
372                 PKT_TX_IPV4 |            \
373                 PKT_TX_IP_CKSUM |        \
374                 PKT_TX_L4_MASK |         \
375                 PKT_TX_IEEE1588_TMST |   \
376                 PKT_TX_TCP_SEG |         \
377                 PKT_TX_QINQ |        \
378                 PKT_TX_TUNNEL_MASK |     \
379                 PKT_TX_MACSEC |          \
380                 PKT_TX_SEC_OFFLOAD |     \
381                 PKT_TX_UDP_SEG |         \
382                 PKT_TX_OUTER_UDP_CKSUM)
383
384 /**
385  * Mbuf having an external buffer attached. shinfo in mbuf must be filled.
386  */
387 #define EXT_ATTACHED_MBUF    (1ULL << 61)
388
389 #define IND_ATTACHED_MBUF    (1ULL << 62) /**< Indirect attached mbuf */
390
391 /** Alignment constraint of mbuf private area. */
392 #define RTE_MBUF_PRIV_ALIGN 8
393
394 /**
395  * Some NICs need at least 2KB buffer to RX standard Ethernet frame without
396  * splitting it into multiple segments.
397  * So, for mbufs that planned to be involved into RX/TX, the recommended
398  * minimal buffer length is 2KB + RTE_PKTMBUF_HEADROOM.
399  */
400 #define RTE_MBUF_DEFAULT_DATAROOM       2048
401 #define RTE_MBUF_DEFAULT_BUF_SIZE       \
402         (RTE_MBUF_DEFAULT_DATAROOM + RTE_PKTMBUF_HEADROOM)
403
404 struct rte_mbuf_sched {
405         uint32_t queue_id;   /**< Queue ID. */
406         uint8_t traffic_class;
407         /**< Traffic class ID. Traffic class 0
408          * is the highest priority traffic class.
409          */
410         uint8_t color;
411         /**< Color. @see enum rte_color.*/
412         uint16_t reserved;   /**< Reserved. */
413 }; /**< Hierarchical scheduler */
414
415 /**
416  * enum for the tx_offload bit-fields lengths and offsets.
417  * defines the layout of rte_mbuf tx_offload field.
418  */
419 enum {
420         RTE_MBUF_L2_LEN_BITS = 7,
421         RTE_MBUF_L3_LEN_BITS = 9,
422         RTE_MBUF_L4_LEN_BITS = 8,
423         RTE_MBUF_TSO_SEGSZ_BITS = 16,
424         RTE_MBUF_OUTL3_LEN_BITS = 9,
425         RTE_MBUF_OUTL2_LEN_BITS = 7,
426         RTE_MBUF_TXOFLD_UNUSED_BITS = sizeof(uint64_t) * CHAR_BIT -
427                 RTE_MBUF_L2_LEN_BITS -
428                 RTE_MBUF_L3_LEN_BITS -
429                 RTE_MBUF_L4_LEN_BITS -
430                 RTE_MBUF_TSO_SEGSZ_BITS -
431                 RTE_MBUF_OUTL3_LEN_BITS -
432                 RTE_MBUF_OUTL2_LEN_BITS,
433 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
434         RTE_MBUF_L2_LEN_OFS =
435                 sizeof(uint64_t) * CHAR_BIT - RTE_MBUF_L2_LEN_BITS,
436         RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS - RTE_MBUF_L3_LEN_BITS,
437         RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS - RTE_MBUF_L4_LEN_BITS,
438         RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS - RTE_MBUF_TSO_SEGSZ_BITS,
439         RTE_MBUF_OUTL3_LEN_OFS =
440                 RTE_MBUF_TSO_SEGSZ_OFS - RTE_MBUF_OUTL3_LEN_BITS,
441         RTE_MBUF_OUTL2_LEN_OFS =
442                 RTE_MBUF_OUTL3_LEN_OFS - RTE_MBUF_OUTL2_LEN_BITS,
443         RTE_MBUF_TXOFLD_UNUSED_OFS =
444                 RTE_MBUF_OUTL2_LEN_OFS - RTE_MBUF_TXOFLD_UNUSED_BITS,
445 #else
446         RTE_MBUF_L2_LEN_OFS = 0,
447         RTE_MBUF_L3_LEN_OFS = RTE_MBUF_L2_LEN_OFS + RTE_MBUF_L2_LEN_BITS,
448         RTE_MBUF_L4_LEN_OFS = RTE_MBUF_L3_LEN_OFS + RTE_MBUF_L3_LEN_BITS,
449         RTE_MBUF_TSO_SEGSZ_OFS = RTE_MBUF_L4_LEN_OFS + RTE_MBUF_L4_LEN_BITS,
450         RTE_MBUF_OUTL3_LEN_OFS =
451                 RTE_MBUF_TSO_SEGSZ_OFS + RTE_MBUF_TSO_SEGSZ_BITS,
452         RTE_MBUF_OUTL2_LEN_OFS =
453                 RTE_MBUF_OUTL3_LEN_OFS + RTE_MBUF_OUTL3_LEN_BITS,
454         RTE_MBUF_TXOFLD_UNUSED_OFS =
455                 RTE_MBUF_OUTL2_LEN_OFS + RTE_MBUF_OUTL2_LEN_BITS,
456 #endif
457 };
458
459 /**
460  * The generic rte_mbuf, containing a packet mbuf.
461  */
462 struct rte_mbuf {
463         RTE_MARKER cacheline0;
464
465         void *buf_addr;           /**< Virtual address of segment buffer. */
466         /**
467          * Physical address of segment buffer.
468          * Force alignment to 8-bytes, so as to ensure we have the exact
469          * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
470          * working on vector drivers easier.
471          */
472         rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
473
474         /* next 8 bytes are initialised on RX descriptor rearm */
475         RTE_MARKER64 rearm_data;
476         uint16_t data_off;
477
478         /**
479          * Reference counter. Its size should at least equal to the size
480          * of port field (16 bits), to support zero-copy broadcast.
481          * It should only be accessed using the following functions:
482          * rte_mbuf_refcnt_update(), rte_mbuf_refcnt_read(), and
483          * rte_mbuf_refcnt_set(). The functionality of these functions (atomic,
484          * or non-atomic) is controlled by the RTE_MBUF_REFCNT_ATOMIC flag.
485          */
486         uint16_t refcnt;
487
488         /**
489          * Number of segments. Only valid for the first segment of an mbuf
490          * chain.
491          */
492         uint16_t nb_segs;
493
494         /** Input port (16 bits to support more than 256 virtual ports).
495          * The event eth Tx adapter uses this field to specify the output port.
496          */
497         uint16_t port;
498
499         uint64_t ol_flags;        /**< Offload features. */
500
501         /* remaining bytes are set on RX when pulling packet from descriptor */
502         RTE_MARKER rx_descriptor_fields1;
503
504         /*
505          * The packet type, which is the combination of outer/inner L2, L3, L4
506          * and tunnel types. The packet_type is about data really present in the
507          * mbuf. Example: if vlan stripping is enabled, a received vlan packet
508          * would have RTE_PTYPE_L2_ETHER and not RTE_PTYPE_L2_VLAN because the
509          * vlan is stripped from the data.
510          */
511         RTE_STD_C11
512         union {
513                 uint32_t packet_type; /**< L2/L3/L4 and tunnel information. */
514                 __extension__
515                 struct {
516                         uint8_t l2_type:4;   /**< (Outer) L2 type. */
517                         uint8_t l3_type:4;   /**< (Outer) L3 type. */
518                         uint8_t l4_type:4;   /**< (Outer) L4 type. */
519                         uint8_t tun_type:4;  /**< Tunnel type. */
520                         RTE_STD_C11
521                         union {
522                                 uint8_t inner_esp_next_proto;
523                                 /**< ESP next protocol type, valid if
524                                  * RTE_PTYPE_TUNNEL_ESP tunnel type is set
525                                  * on both Tx and Rx.
526                                  */
527                                 __extension__
528                                 struct {
529                                         uint8_t inner_l2_type:4;
530                                         /**< Inner L2 type. */
531                                         uint8_t inner_l3_type:4;
532                                         /**< Inner L3 type. */
533                                 };
534                         };
535                         uint8_t inner_l4_type:4; /**< Inner L4 type. */
536                 };
537         };
538
539         uint32_t pkt_len;         /**< Total pkt len: sum of all segments. */
540         uint16_t data_len;        /**< Amount of data in segment buffer. */
541         /** VLAN TCI (CPU order), valid if PKT_RX_VLAN is set. */
542         uint16_t vlan_tci;
543
544         RTE_STD_C11
545         union {
546                 union {
547                         uint32_t rss;     /**< RSS hash result if RSS enabled */
548                         struct {
549                                 union {
550                                         struct {
551                                                 uint16_t hash;
552                                                 uint16_t id;
553                                         };
554                                         uint32_t lo;
555                                         /**< Second 4 flexible bytes */
556                                 };
557                                 uint32_t hi;
558                                 /**< First 4 flexible bytes or FD ID, dependent
559                                  * on PKT_RX_FDIR_* flag in ol_flags.
560                                  */
561                         } fdir; /**< Filter identifier if FDIR enabled */
562                         struct rte_mbuf_sched sched;
563                         /**< Hierarchical scheduler : 8 bytes */
564                         struct {
565                                 uint32_t reserved1;
566                                 uint16_t reserved2;
567                                 uint16_t txq;
568                                 /**< The event eth Tx adapter uses this field
569                                  * to store Tx queue id.
570                                  * @see rte_event_eth_tx_adapter_txq_set()
571                                  */
572                         } txadapter; /**< Eventdev ethdev Tx adapter */
573                         /**< User defined tags. See rte_distributor_process() */
574                         uint32_t usr;
575                 } hash;                   /**< hash information */
576         };
577
578         /** Outer VLAN TCI (CPU order), valid if PKT_RX_QINQ is set. */
579         uint16_t vlan_tci_outer;
580
581         uint16_t buf_len;         /**< Length of segment buffer. */
582
583         struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
584
585         /* second cache line - fields only used in slow path or on TX */
586         RTE_MARKER cacheline1 __rte_cache_min_aligned;
587
588         /**
589          * Next segment of scattered packet. Must be NULL in the last segment or
590          * in case of non-segmented packet.
591          */
592         struct rte_mbuf *next;
593
594         /* fields to support TX offloads */
595         RTE_STD_C11
596         union {
597                 uint64_t tx_offload;       /**< combined for easy fetch */
598                 __extension__
599                 struct {
600                         uint64_t l2_len:RTE_MBUF_L2_LEN_BITS;
601                         /**< L2 (MAC) Header Length for non-tunneling pkt.
602                          * Outer_L4_len + ... + Inner_L2_len for tunneling pkt.
603                          */
604                         uint64_t l3_len:RTE_MBUF_L3_LEN_BITS;
605                         /**< L3 (IP) Header Length. */
606                         uint64_t l4_len:RTE_MBUF_L4_LEN_BITS;
607                         /**< L4 (TCP/UDP) Header Length. */
608                         uint64_t tso_segsz:RTE_MBUF_TSO_SEGSZ_BITS;
609                         /**< TCP TSO segment size */
610
611                         /*
612                          * Fields for Tx offloading of tunnels.
613                          * These are undefined for packets which don't request
614                          * any tunnel offloads (outer IP or UDP checksum,
615                          * tunnel TSO).
616                          *
617                          * PMDs should not use these fields unconditionally
618                          * when calculating offsets.
619                          *
620                          * Applications are expected to set appropriate tunnel
621                          * offload flags when they fill in these fields.
622                          */
623                         uint64_t outer_l3_len:RTE_MBUF_OUTL3_LEN_BITS;
624                         /**< Outer L3 (IP) Hdr Length. */
625                         uint64_t outer_l2_len:RTE_MBUF_OUTL2_LEN_BITS;
626                         /**< Outer L2 (MAC) Hdr Length. */
627
628                         /* uint64_t unused:RTE_MBUF_TXOFLD_UNUSED_BITS; */
629                 };
630         };
631
632         /** Shared data for external buffer attached to mbuf. See
633          * rte_pktmbuf_attach_extbuf().
634          */
635         struct rte_mbuf_ext_shared_info *shinfo;
636
637         /** Size of the application private data. In case of an indirect
638          * mbuf, it stores the direct mbuf private data size.
639          */
640         uint16_t priv_size;
641
642         /** Timesync flags for use with IEEE1588. */
643         uint16_t timesync;
644
645         uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
646 } __rte_cache_aligned;
647
648 /**
649  * Function typedef of callback to free externally attached buffer.
650  */
651 typedef void (*rte_mbuf_extbuf_free_callback_t)(void *addr, void *opaque);
652
653 /**
654  * Shared data at the end of an external buffer.
655  */
656 struct rte_mbuf_ext_shared_info {
657         rte_mbuf_extbuf_free_callback_t free_cb; /**< Free callback function */
658         void *fcb_opaque;                        /**< Free callback argument */
659         uint16_t refcnt;
660 };
661
662 /** Maximum number of nb_segs allowed. */
663 #define RTE_MBUF_MAX_NB_SEGS    UINT16_MAX
664
665 /**
666  * Returns TRUE if given mbuf is cloned by mbuf indirection, or FALSE
667  * otherwise.
668  *
669  * If a mbuf has its data in another mbuf and references it by mbuf
670  * indirection, this mbuf can be defined as a cloned mbuf.
671  */
672 #define RTE_MBUF_CLONED(mb)     ((mb)->ol_flags & IND_ATTACHED_MBUF)
673
674 /**
675  * Returns TRUE if given mbuf has an external buffer, or FALSE otherwise.
676  *
677  * External buffer is a user-provided anonymous buffer.
678  */
679 #define RTE_MBUF_HAS_EXTBUF(mb) ((mb)->ol_flags & EXT_ATTACHED_MBUF)
680
681 /**
682  * Returns TRUE if given mbuf is direct, or FALSE otherwise.
683  *
684  * If a mbuf embeds its own data after the rte_mbuf structure, this mbuf
685  * can be defined as a direct mbuf.
686  */
687 #define RTE_MBUF_DIRECT(mb) \
688         (!((mb)->ol_flags & (IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF)))
689
690 /** Uninitialized or unspecified port. */
691 #define RTE_MBUF_PORT_INVALID UINT16_MAX
692 /** For backwards compatibility. */
693 #define MBUF_INVALID_PORT RTE_MBUF_PORT_INVALID
694
695 /**
696  * A macro that points to an offset into the data in the mbuf.
697  *
698  * The returned pointer is cast to type t. Before using this
699  * function, the user must ensure that the first segment is large
700  * enough to accommodate its data.
701  *
702  * @param m
703  *   The packet mbuf.
704  * @param o
705  *   The offset into the mbuf data.
706  * @param t
707  *   The type to cast the result into.
708  */
709 #define rte_pktmbuf_mtod_offset(m, t, o)        \
710         ((t)((char *)(m)->buf_addr + (m)->data_off + (o)))
711
712 /**
713  * A macro that points to the start of the data in the mbuf.
714  *
715  * The returned pointer is cast to type t. Before using this
716  * function, the user must ensure that the first segment is large
717  * enough to accommodate its data.
718  *
719  * @param m
720  *   The packet mbuf.
721  * @param t
722  *   The type to cast the result into.
723  */
724 #define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0)
725
726 /**
727  * A macro that returns the IO address that points to an offset of the
728  * start of the data in the mbuf
729  *
730  * @param m
731  *   The packet mbuf.
732  * @param o
733  *   The offset into the data to calculate address from.
734  */
735 #define rte_pktmbuf_iova_offset(m, o) \
736         (rte_iova_t)((m)->buf_iova + (m)->data_off + (o))
737
738 /**
739  * A macro that returns the IO address that points to the start of the
740  * data in the mbuf
741  *
742  * @param m
743  *   The packet mbuf.
744  */
745 #define rte_pktmbuf_iova(m) rte_pktmbuf_iova_offset(m, 0)
746
747 #ifdef __cplusplus
748 }
749 #endif
750
751 #endif /* _RTE_MBUF_CORE_H_ */