doc: announce renaming of mbuf offload flags
[dpdk.git] / lib / mbuf / rte_mbuf.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_H_
7 #define _RTE_MBUF_H_
8
9 /**
10  * @file
11  * RTE Mbuf
12  *
13  * The mbuf library provides the ability to create and destroy buffers
14  * that may be used by the RTE application to store message
15  * buffers. The message buffers are stored in a mempool, using the
16  * RTE mempool library.
17  *
18  * The preferred way to create a mbuf pool is to use
19  * rte_pktmbuf_pool_create(). However, in some situations, an
20  * application may want to have more control (ex: populate the pool with
21  * specific memory), in this case it is possible to use functions from
22  * rte_mempool. See how rte_pktmbuf_pool_create() is implemented for
23  * details.
24  *
25  * This library provides an API to allocate/free packet mbufs, which are
26  * used to carry network packets.
27  *
28  * To understand the concepts of packet buffers or mbufs, you
29  * should read "TCP/IP Illustrated, Volume 2: The Implementation,
30  * Addison-Wesley, 1995, ISBN 0-201-63354-X from Richard Stevens"
31  * http://www.kohala.com/start/tcpipiv2.html
32  */
33
34 #include <stdint.h>
35 #include <rte_compat.h>
36 #include <rte_common.h>
37 #include <rte_config.h>
38 #include <rte_mempool.h>
39 #include <rte_memory.h>
40 #include <rte_prefetch.h>
41 #include <rte_branch_prediction.h>
42 #include <rte_byteorder.h>
43 #include <rte_mbuf_ptype.h>
44 #include <rte_mbuf_core.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /**
51  * Get the name of a RX offload flag
52  *
53  * @param mask
54  *   The mask describing the flag.
55  * @return
56  *   The name of this flag, or NULL if it's not a valid RX flag.
57  */
58 const char *rte_get_rx_ol_flag_name(uint64_t mask);
59
60 /**
61  * Dump the list of RX offload flags in a buffer
62  *
63  * @param mask
64  *   The mask describing the RX flags.
65  * @param buf
66  *   The output buffer.
67  * @param buflen
68  *   The length of the buffer.
69  * @return
70  *   0 on success, (-1) on error.
71  */
72 int rte_get_rx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
73
74 /**
75  * Get the name of a TX offload flag
76  *
77  * @param mask
78  *   The mask describing the flag. Usually only one bit must be set.
79  *   Several bits can be given if they belong to the same mask.
80  *   Ex: PKT_TX_L4_MASK.
81  * @return
82  *   The name of this flag, or NULL if it's not a valid TX flag.
83  */
84 const char *rte_get_tx_ol_flag_name(uint64_t mask);
85
86 /**
87  * Dump the list of TX offload flags in a buffer
88  *
89  * @param mask
90  *   The mask describing the TX flags.
91  * @param buf
92  *   The output buffer.
93  * @param buflen
94  *   The length of the buffer.
95  * @return
96  *   0 on success, (-1) on error.
97  */
98 int rte_get_tx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
99
100 /**
101  * Prefetch the first part of the mbuf
102  *
103  * The first 64 bytes of the mbuf corresponds to fields that are used early
104  * in the receive path. If the cache line of the architecture is higher than
105  * 64B, the second part will also be prefetched.
106  *
107  * @param m
108  *   The pointer to the mbuf.
109  */
110 static inline void
111 rte_mbuf_prefetch_part1(struct rte_mbuf *m)
112 {
113         rte_prefetch0(&m->cacheline0);
114 }
115
116 /**
117  * Prefetch the second part of the mbuf
118  *
119  * The next 64 bytes of the mbuf corresponds to fields that are used in the
120  * transmit path. If the cache line of the architecture is higher than 64B,
121  * this function does nothing as it is expected that the full mbuf is
122  * already in cache.
123  *
124  * @param m
125  *   The pointer to the mbuf.
126  */
127 static inline void
128 rte_mbuf_prefetch_part2(struct rte_mbuf *m)
129 {
130 #if RTE_CACHE_LINE_SIZE == 64
131         rte_prefetch0(&m->cacheline1);
132 #else
133         RTE_SET_USED(m);
134 #endif
135 }
136
137
138 static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp);
139
140 /**
141  * Return the IO address of the beginning of the mbuf data
142  *
143  * @param mb
144  *   The pointer to the mbuf.
145  * @return
146  *   The IO address of the beginning of the mbuf data
147  */
148 static inline rte_iova_t
149 rte_mbuf_data_iova(const struct rte_mbuf *mb)
150 {
151         return mb->buf_iova + mb->data_off;
152 }
153
154 /**
155  * Return the default IO address of the beginning of the mbuf data
156  *
157  * This function is used by drivers in their receive function, as it
158  * returns the location where data should be written by the NIC, taking
159  * the default headroom in account.
160  *
161  * @param mb
162  *   The pointer to the mbuf.
163  * @return
164  *   The IO address of the beginning of the mbuf data
165  */
166 static inline rte_iova_t
167 rte_mbuf_data_iova_default(const struct rte_mbuf *mb)
168 {
169         return mb->buf_iova + RTE_PKTMBUF_HEADROOM;
170 }
171
172 /**
173  * Return the mbuf owning the data buffer address of an indirect mbuf.
174  *
175  * @param mi
176  *   The pointer to the indirect mbuf.
177  * @return
178  *   The address of the direct mbuf corresponding to buffer_addr.
179  */
180 static inline struct rte_mbuf *
181 rte_mbuf_from_indirect(struct rte_mbuf *mi)
182 {
183         return (struct rte_mbuf *)RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size);
184 }
185
186 /**
187  * Return address of buffer embedded in the given mbuf.
188  *
189  * The return value shall be same as mb->buf_addr if the mbuf is already
190  * initialized and direct. However, this API is useful if mempool of the
191  * mbuf is already known because it doesn't need to access mbuf contents in
192  * order to get the mempool pointer.
193  *
194  * @warning
195  * @b EXPERIMENTAL: This API may change without prior notice.
196  * This will be used by rte_mbuf_to_baddr() which has redundant code once
197  * experimental tag is removed.
198  *
199  * @param mb
200  *   The pointer to the mbuf.
201  * @param mp
202  *   The pointer to the mempool of the mbuf.
203  * @return
204  *   The pointer of the mbuf buffer.
205  */
206 __rte_experimental
207 static inline char *
208 rte_mbuf_buf_addr(struct rte_mbuf *mb, struct rte_mempool *mp)
209 {
210         return (char *)mb + sizeof(*mb) + rte_pktmbuf_priv_size(mp);
211 }
212
213 /**
214  * Return the default address of the beginning of the mbuf data.
215  *
216  * @warning
217  * @b EXPERIMENTAL: This API may change without prior notice.
218  *
219  * @param mb
220  *   The pointer to the mbuf.
221  * @return
222  *   The pointer of the beginning of the mbuf data.
223  */
224 __rte_experimental
225 static inline char *
226 rte_mbuf_data_addr_default(__rte_unused struct rte_mbuf *mb)
227 {
228         /* gcc complains about calling this experimental function even
229          * when not using it. Hide it with ALLOW_EXPERIMENTAL_API.
230          */
231 #ifdef ALLOW_EXPERIMENTAL_API
232         return rte_mbuf_buf_addr(mb, mb->pool) + RTE_PKTMBUF_HEADROOM;
233 #else
234         return NULL;
235 #endif
236 }
237
238 /**
239  * Return address of buffer embedded in the given mbuf.
240  *
241  * @note: Accessing mempool pointer of a mbuf is expensive because the
242  * pointer is stored in the 2nd cache line of mbuf. If mempool is known, it
243  * is better not to reference the mempool pointer in mbuf but calling
244  * rte_mbuf_buf_addr() would be more efficient.
245  *
246  * @param md
247  *   The pointer to the mbuf.
248  * @return
249  *   The address of the data buffer owned by the mbuf.
250  */
251 static inline char *
252 rte_mbuf_to_baddr(struct rte_mbuf *md)
253 {
254 #ifdef ALLOW_EXPERIMENTAL_API
255         return rte_mbuf_buf_addr(md, md->pool);
256 #else
257         char *buffer_addr;
258         buffer_addr = (char *)md + sizeof(*md) + rte_pktmbuf_priv_size(md->pool);
259         return buffer_addr;
260 #endif
261 }
262
263 /**
264  * Return the starting address of the private data area embedded in
265  * the given mbuf.
266  *
267  * Note that no check is made to ensure that a private data area
268  * actually exists in the supplied mbuf.
269  *
270  * @param m
271  *   The pointer to the mbuf.
272  * @return
273  *   The starting address of the private data area of the given mbuf.
274  */
275 __rte_experimental
276 static inline void *
277 rte_mbuf_to_priv(struct rte_mbuf *m)
278 {
279         return RTE_PTR_ADD(m, sizeof(struct rte_mbuf));
280 }
281
282 /**
283  * Private data in case of pktmbuf pool.
284  *
285  * A structure that contains some pktmbuf_pool-specific data that are
286  * appended after the mempool structure (in private data).
287  */
288 struct rte_pktmbuf_pool_private {
289         uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf. */
290         uint16_t mbuf_priv_size;      /**< Size of private area in each mbuf. */
291         uint32_t flags; /**< reserved for future use. */
292 };
293
294 /**
295  * Return the flags from private data in an mempool structure.
296  *
297  * @param mp
298  *   A pointer to the mempool structure.
299  * @return
300  *   The flags from the private data structure.
301  */
302 static inline uint32_t
303 rte_pktmbuf_priv_flags(struct rte_mempool *mp)
304 {
305         struct rte_pktmbuf_pool_private *mbp_priv;
306
307         mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
308         return mbp_priv->flags;
309 }
310
311 /**
312  * When set, pktmbuf mempool will hold only mbufs with pinned external
313  * buffer. The external buffer will be attached to the mbuf at the
314  * memory pool creation and will never be detached by the mbuf free calls.
315  * mbuf should not contain any room for data after the mbuf structure.
316  */
317 #define RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF (1 << 0)
318
319 /**
320  * Returns non zero if given mbuf has a pinned external buffer, or zero
321  * otherwise. The pinned external buffer is allocated at pool creation
322  * time and should not be freed on mbuf freeing.
323  *
324  * External buffer is a user-provided anonymous buffer.
325  */
326 #define RTE_MBUF_HAS_PINNED_EXTBUF(mb) \
327         (rte_pktmbuf_priv_flags(mb->pool) & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF)
328
329 #ifdef RTE_LIBRTE_MBUF_DEBUG
330
331 /**  check mbuf type in debug mode */
332 #define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
333
334 #else /*  RTE_LIBRTE_MBUF_DEBUG */
335
336 /**  check mbuf type in debug mode */
337 #define __rte_mbuf_sanity_check(m, is_h) do { } while (0)
338
339 #endif /*  RTE_LIBRTE_MBUF_DEBUG */
340
341 #ifdef RTE_MBUF_REFCNT_ATOMIC
342
343 /**
344  * Reads the value of an mbuf's refcnt.
345  * @param m
346  *   Mbuf to read
347  * @return
348  *   Reference count number.
349  */
350 static inline uint16_t
351 rte_mbuf_refcnt_read(const struct rte_mbuf *m)
352 {
353         return __atomic_load_n(&m->refcnt, __ATOMIC_RELAXED);
354 }
355
356 /**
357  * Sets an mbuf's refcnt to a defined value.
358  * @param m
359  *   Mbuf to update
360  * @param new_value
361  *   Value set
362  */
363 static inline void
364 rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
365 {
366         __atomic_store_n(&m->refcnt, new_value, __ATOMIC_RELAXED);
367 }
368
369 /* internal */
370 static inline uint16_t
371 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
372 {
373         return __atomic_add_fetch(&m->refcnt, (uint16_t)value,
374                                  __ATOMIC_ACQ_REL);
375 }
376
377 /**
378  * Adds given value to an mbuf's refcnt and returns its new value.
379  * @param m
380  *   Mbuf to update
381  * @param value
382  *   Value to add/subtract
383  * @return
384  *   Updated value
385  */
386 static inline uint16_t
387 rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
388 {
389         /*
390          * The atomic_add is an expensive operation, so we don't want to
391          * call it in the case where we know we are the unique holder of
392          * this mbuf (i.e. ref_cnt == 1). Otherwise, an atomic
393          * operation has to be used because concurrent accesses on the
394          * reference counter can occur.
395          */
396         if (likely(rte_mbuf_refcnt_read(m) == 1)) {
397                 ++value;
398                 rte_mbuf_refcnt_set(m, (uint16_t)value);
399                 return (uint16_t)value;
400         }
401
402         return __rte_mbuf_refcnt_update(m, value);
403 }
404
405 #else /* ! RTE_MBUF_REFCNT_ATOMIC */
406
407 /* internal */
408 static inline uint16_t
409 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
410 {
411         m->refcnt = (uint16_t)(m->refcnt + value);
412         return m->refcnt;
413 }
414
415 /**
416  * Adds given value to an mbuf's refcnt and returns its new value.
417  */
418 static inline uint16_t
419 rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
420 {
421         return __rte_mbuf_refcnt_update(m, value);
422 }
423
424 /**
425  * Reads the value of an mbuf's refcnt.
426  */
427 static inline uint16_t
428 rte_mbuf_refcnt_read(const struct rte_mbuf *m)
429 {
430         return m->refcnt;
431 }
432
433 /**
434  * Sets an mbuf's refcnt to the defined value.
435  */
436 static inline void
437 rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
438 {
439         m->refcnt = new_value;
440 }
441
442 #endif /* RTE_MBUF_REFCNT_ATOMIC */
443
444 /**
445  * Reads the refcnt of an external buffer.
446  *
447  * @param shinfo
448  *   Shared data of the external buffer.
449  * @return
450  *   Reference count number.
451  */
452 static inline uint16_t
453 rte_mbuf_ext_refcnt_read(const struct rte_mbuf_ext_shared_info *shinfo)
454 {
455         return __atomic_load_n(&shinfo->refcnt, __ATOMIC_RELAXED);
456 }
457
458 /**
459  * Set refcnt of an external buffer.
460  *
461  * @param shinfo
462  *   Shared data of the external buffer.
463  * @param new_value
464  *   Value set
465  */
466 static inline void
467 rte_mbuf_ext_refcnt_set(struct rte_mbuf_ext_shared_info *shinfo,
468         uint16_t new_value)
469 {
470         __atomic_store_n(&shinfo->refcnt, new_value, __ATOMIC_RELAXED);
471 }
472
473 /**
474  * Add given value to refcnt of an external buffer and return its new
475  * value.
476  *
477  * @param shinfo
478  *   Shared data of the external buffer.
479  * @param value
480  *   Value to add/subtract
481  * @return
482  *   Updated value
483  */
484 static inline uint16_t
485 rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo,
486         int16_t value)
487 {
488         if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1)) {
489                 ++value;
490                 rte_mbuf_ext_refcnt_set(shinfo, (uint16_t)value);
491                 return (uint16_t)value;
492         }
493
494         return __atomic_add_fetch(&shinfo->refcnt, (uint16_t)value,
495                                  __ATOMIC_ACQ_REL);
496 }
497
498 /** Mbuf prefetch */
499 #define RTE_MBUF_PREFETCH_TO_FREE(m) do {       \
500         if ((m) != NULL)                        \
501                 rte_prefetch0(m);               \
502 } while (0)
503
504
505 /**
506  * Sanity checks on an mbuf.
507  *
508  * Check the consistency of the given mbuf. The function will cause a
509  * panic if corruption is detected.
510  *
511  * @param m
512  *   The mbuf to be checked.
513  * @param is_header
514  *   True if the mbuf is a packet header, false if it is a sub-segment
515  *   of a packet (in this case, some fields like nb_segs are not checked)
516  */
517 void
518 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
519
520 /**
521  * Sanity checks on a mbuf.
522  *
523  * Almost like rte_mbuf_sanity_check(), but this function gives the reason
524  * if corruption is detected rather than panic.
525  *
526  * @param m
527  *   The mbuf to be checked.
528  * @param is_header
529  *   True if the mbuf is a packet header, false if it is a sub-segment
530  *   of a packet (in this case, some fields like nb_segs are not checked)
531  * @param reason
532  *   A reference to a string pointer where to store the reason why a mbuf is
533  *   considered invalid.
534  * @return
535  *   - 0 if no issue has been found, reason is left untouched.
536  *   - -1 if a problem is detected, reason then points to a string describing
537  *     the reason why the mbuf is deemed invalid.
538  */
539 __rte_experimental
540 int rte_mbuf_check(const struct rte_mbuf *m, int is_header,
541                    const char **reason);
542
543 /**
544  * Sanity checks on a reinitialized mbuf in debug mode.
545  *
546  * Check the consistency of the given reinitialized mbuf.
547  * The function will cause a panic if corruption is detected.
548  *
549  * Check that the mbuf is properly reinitialized (refcnt=1, next=NULL,
550  * nb_segs=1), as done by rte_pktmbuf_prefree_seg().
551  *
552  * @param m
553  *   The mbuf to be checked.
554  */
555 static __rte_always_inline void
556 __rte_mbuf_raw_sanity_check(__rte_unused const struct rte_mbuf *m)
557 {
558         RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);
559         RTE_ASSERT(m->next == NULL);
560         RTE_ASSERT(m->nb_segs == 1);
561         __rte_mbuf_sanity_check(m, 0);
562 }
563
564 /** For backwards compatibility. */
565 #define MBUF_RAW_ALLOC_CHECK(m) __rte_mbuf_raw_sanity_check(m)
566
567 /**
568  * Allocate an uninitialized mbuf from mempool *mp*.
569  *
570  * This function can be used by PMDs (especially in RX functions) to
571  * allocate an uninitialized mbuf. The driver is responsible of
572  * initializing all the required fields. See rte_pktmbuf_reset().
573  * For standard needs, prefer rte_pktmbuf_alloc().
574  *
575  * The caller can expect that the following fields of the mbuf structure
576  * are initialized: buf_addr, buf_iova, buf_len, refcnt=1, nb_segs=1,
577  * next=NULL, pool, priv_size. The other fields must be initialized
578  * by the caller.
579  *
580  * @param mp
581  *   The mempool from which mbuf is allocated.
582  * @return
583  *   - The pointer to the new mbuf on success.
584  *   - NULL if allocation failed.
585  */
586 static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
587 {
588         struct rte_mbuf *m;
589
590         if (rte_mempool_get(mp, (void **)&m) < 0)
591                 return NULL;
592         __rte_mbuf_raw_sanity_check(m);
593         return m;
594 }
595
596 /**
597  * Put mbuf back into its original mempool.
598  *
599  * The caller must ensure that the mbuf is direct and properly
600  * reinitialized (refcnt=1, next=NULL, nb_segs=1), as done by
601  * rte_pktmbuf_prefree_seg().
602  *
603  * This function should be used with care, when optimization is
604  * required. For standard needs, prefer rte_pktmbuf_free() or
605  * rte_pktmbuf_free_seg().
606  *
607  * @param m
608  *   The mbuf to be freed.
609  */
610 static __rte_always_inline void
611 rte_mbuf_raw_free(struct rte_mbuf *m)
612 {
613         RTE_ASSERT(!RTE_MBUF_CLONED(m) &&
614                   (!RTE_MBUF_HAS_EXTBUF(m) || RTE_MBUF_HAS_PINNED_EXTBUF(m)));
615         __rte_mbuf_raw_sanity_check(m);
616         rte_mempool_put(m->pool, m);
617 }
618
619 /**
620  * The packet mbuf constructor.
621  *
622  * This function initializes some fields in the mbuf structure that are
623  * not modified by the user once created (origin pool, buffer start
624  * address, and so on). This function is given as a callback function to
625  * rte_mempool_obj_iter() or rte_mempool_create() at pool creation time.
626  *
627  * This function expects that the mempool private area was previously
628  * initialized with rte_pktmbuf_pool_init().
629  *
630  * @param mp
631  *   The mempool from which mbufs originate.
632  * @param opaque_arg
633  *   A pointer that can be used by the user to retrieve useful information
634  *   for mbuf initialization. This pointer is the opaque argument passed to
635  *   rte_mempool_obj_iter() or rte_mempool_create().
636  * @param m
637  *   The mbuf to initialize.
638  * @param i
639  *   The index of the mbuf in the pool table.
640  */
641 void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
642                       void *m, unsigned i);
643
644 /**
645  * A packet mbuf pool constructor.
646  *
647  * This function initializes the mempool private data in the case of a
648  * pktmbuf pool. This private data is needed by the driver. The
649  * function must be called on the mempool before it is used, or it
650  * can be given as a callback function to rte_mempool_create() at
651  * pool creation. It can be extended by the user, for example, to
652  * provide another packet size.
653  *
654  * The mempool private area size must be at least equal to
655  * sizeof(struct rte_pktmbuf_pool_private).
656  *
657  * @param mp
658  *   The mempool from which mbufs originate.
659  * @param opaque_arg
660  *   A pointer that can be used by the user to retrieve useful information
661  *   for mbuf initialization. This pointer is the opaque argument passed to
662  *   rte_mempool_create().
663  */
664 void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg);
665
666 /**
667  * Create a mbuf pool.
668  *
669  * This function creates and initializes a packet mbuf pool. It is
670  * a wrapper to rte_mempool functions.
671  *
672  * @param name
673  *   The name of the mbuf pool.
674  * @param n
675  *   The number of elements in the mbuf pool. The optimum size (in terms
676  *   of memory usage) for a mempool is when n is a power of two minus one:
677  *   n = (2^q - 1).
678  * @param cache_size
679  *   Size of the per-core object cache. See rte_mempool_create() for
680  *   details.
681  * @param priv_size
682  *   Size of application private are between the rte_mbuf structure
683  *   and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
684  * @param data_room_size
685  *   Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
686  * @param socket_id
687  *   The socket identifier where the memory should be allocated. The
688  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
689  *   reserved zone.
690  * @return
691  *   The pointer to the new allocated mempool, on success. NULL on error
692  *   with rte_errno set appropriately. Possible rte_errno values include:
693  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
694  *    - E_RTE_SECONDARY - function was called from a secondary process instance
695  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
696  *    - ENOSPC - the maximum number of memzones has already been allocated
697  *    - EEXIST - a memzone with the same name already exists
698  *    - ENOMEM - no appropriate memory area found in which to create memzone
699  */
700 struct rte_mempool *
701 rte_pktmbuf_pool_create(const char *name, unsigned n,
702         unsigned cache_size, uint16_t priv_size, uint16_t data_room_size,
703         int socket_id);
704
705 /**
706  * Create a mbuf pool with a given mempool ops name
707  *
708  * This function creates and initializes a packet mbuf pool. It is
709  * a wrapper to rte_mempool functions.
710  *
711  * @param name
712  *   The name of the mbuf pool.
713  * @param n
714  *   The number of elements in the mbuf pool. The optimum size (in terms
715  *   of memory usage) for a mempool is when n is a power of two minus one:
716  *   n = (2^q - 1).
717  * @param cache_size
718  *   Size of the per-core object cache. See rte_mempool_create() for
719  *   details.
720  * @param priv_size
721  *   Size of application private are between the rte_mbuf structure
722  *   and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
723  * @param data_room_size
724  *   Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
725  * @param socket_id
726  *   The socket identifier where the memory should be allocated. The
727  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
728  *   reserved zone.
729  * @param ops_name
730  *   The mempool ops name to be used for this mempool instead of
731  *   default mempool. The value can be *NULL* to use default mempool.
732  * @return
733  *   The pointer to the new allocated mempool, on success. NULL on error
734  *   with rte_errno set appropriately. Possible rte_errno values include:
735  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
736  *    - E_RTE_SECONDARY - function was called from a secondary process instance
737  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
738  *    - ENOSPC - the maximum number of memzones has already been allocated
739  *    - EEXIST - a memzone with the same name already exists
740  *    - ENOMEM - no appropriate memory area found in which to create memzone
741  */
742 struct rte_mempool *
743 rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
744         unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
745         int socket_id, const char *ops_name);
746
747 /** A structure that describes the pinned external buffer segment. */
748 struct rte_pktmbuf_extmem {
749         void *buf_ptr;          /**< The virtual address of data buffer. */
750         rte_iova_t buf_iova;    /**< The IO address of the data buffer. */
751         size_t buf_len;         /**< External buffer length in bytes. */
752         uint16_t elt_size;      /**< mbuf element size in bytes. */
753 };
754
755 /**
756  * Create a mbuf pool with external pinned data buffers.
757  *
758  * This function creates and initializes a packet mbuf pool that contains
759  * only mbufs with external buffer. It is a wrapper to rte_mempool functions.
760  *
761  * @param name
762  *   The name of the mbuf pool.
763  * @param n
764  *   The number of elements in the mbuf pool. The optimum size (in terms
765  *   of memory usage) for a mempool is when n is a power of two minus one:
766  *   n = (2^q - 1).
767  * @param cache_size
768  *   Size of the per-core object cache. See rte_mempool_create() for
769  *   details.
770  * @param priv_size
771  *   Size of application private are between the rte_mbuf structure
772  *   and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
773  * @param data_room_size
774  *   Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
775  * @param socket_id
776  *   The socket identifier where the memory should be allocated. The
777  *   value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
778  *   reserved zone.
779  * @param ext_mem
780  *   Pointer to the array of structures describing the external memory
781  *   for data buffers. It is caller responsibility to register this memory
782  *   with rte_extmem_register() (if needed), map this memory to appropriate
783  *   physical device, etc.
784  * @param ext_num
785  *   Number of elements in the ext_mem array.
786  * @return
787  *   The pointer to the new allocated mempool, on success. NULL on error
788  *   with rte_errno set appropriately. Possible rte_errno values include:
789  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
790  *    - E_RTE_SECONDARY - function was called from a secondary process instance
791  *    - EINVAL - cache size provided is too large, or priv_size is not aligned.
792  *    - ENOSPC - the maximum number of memzones has already been allocated
793  *    - EEXIST - a memzone with the same name already exists
794  *    - ENOMEM - no appropriate memory area found in which to create memzone
795  */
796 __rte_experimental
797 struct rte_mempool *
798 rte_pktmbuf_pool_create_extbuf(const char *name, unsigned int n,
799         unsigned int cache_size, uint16_t priv_size,
800         uint16_t data_room_size, int socket_id,
801         const struct rte_pktmbuf_extmem *ext_mem,
802         unsigned int ext_num);
803
804 /**
805  * Get the data room size of mbufs stored in a pktmbuf_pool
806  *
807  * The data room size is the amount of data that can be stored in a
808  * mbuf including the headroom (RTE_PKTMBUF_HEADROOM).
809  *
810  * @param mp
811  *   The packet mbuf pool.
812  * @return
813  *   The data room size of mbufs stored in this mempool.
814  */
815 static inline uint16_t
816 rte_pktmbuf_data_room_size(struct rte_mempool *mp)
817 {
818         struct rte_pktmbuf_pool_private *mbp_priv;
819
820         mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
821         return mbp_priv->mbuf_data_room_size;
822 }
823
824 /**
825  * Get the application private size of mbufs stored in a pktmbuf_pool
826  *
827  * The private size of mbuf is a zone located between the rte_mbuf
828  * structure and the data buffer where an application can store data
829  * associated to a packet.
830  *
831  * @param mp
832  *   The packet mbuf pool.
833  * @return
834  *   The private size of mbufs stored in this mempool.
835  */
836 static inline uint16_t
837 rte_pktmbuf_priv_size(struct rte_mempool *mp)
838 {
839         struct rte_pktmbuf_pool_private *mbp_priv;
840
841         mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
842         return mbp_priv->mbuf_priv_size;
843 }
844
845 /**
846  * Reset the data_off field of a packet mbuf to its default value.
847  *
848  * The given mbuf must have only one segment, which should be empty.
849  *
850  * @param m
851  *   The packet mbuf's data_off field has to be reset.
852  */
853 static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
854 {
855         m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM,
856                                         (uint16_t)m->buf_len);
857 }
858
859 /**
860  * Reset the fields of a packet mbuf to their default values.
861  *
862  * The given mbuf must have only one segment.
863  *
864  * @param m
865  *   The packet mbuf to be reset.
866  */
867 static inline void rte_pktmbuf_reset(struct rte_mbuf *m)
868 {
869         m->next = NULL;
870         m->pkt_len = 0;
871         m->tx_offload = 0;
872         m->vlan_tci = 0;
873         m->vlan_tci_outer = 0;
874         m->nb_segs = 1;
875         m->port = RTE_MBUF_PORT_INVALID;
876
877         m->ol_flags &= EXT_ATTACHED_MBUF;
878         m->packet_type = 0;
879         rte_pktmbuf_reset_headroom(m);
880
881         m->data_len = 0;
882         __rte_mbuf_sanity_check(m, 1);
883 }
884
885 /**
886  * Allocate a new mbuf from a mempool.
887  *
888  * This new mbuf contains one segment, which has a length of 0. The pointer
889  * to data is initialized to have some bytes of headroom in the buffer
890  * (if buffer size allows).
891  *
892  * @param mp
893  *   The mempool from which the mbuf is allocated.
894  * @return
895  *   - The pointer to the new mbuf on success.
896  *   - NULL if allocation failed.
897  */
898 static inline struct rte_mbuf *rte_pktmbuf_alloc(struct rte_mempool *mp)
899 {
900         struct rte_mbuf *m;
901         if ((m = rte_mbuf_raw_alloc(mp)) != NULL)
902                 rte_pktmbuf_reset(m);
903         return m;
904 }
905
906 /**
907  * Allocate a bulk of mbufs, initialize refcnt and reset the fields to default
908  * values.
909  *
910  *  @param pool
911  *    The mempool from which mbufs are allocated.
912  *  @param mbufs
913  *    Array of pointers to mbufs
914  *  @param count
915  *    Array size
916  *  @return
917  *   - 0: Success
918  *   - -ENOENT: Not enough entries in the mempool; no mbufs are retrieved.
919  */
920 static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
921          struct rte_mbuf **mbufs, unsigned count)
922 {
923         unsigned idx = 0;
924         int rc;
925
926         rc = rte_mempool_get_bulk(pool, (void **)mbufs, count);
927         if (unlikely(rc))
928                 return rc;
929
930         /* To understand duff's device on loop unwinding optimization, see
931          * https://en.wikipedia.org/wiki/Duff's_device.
932          * Here while() loop is used rather than do() while{} to avoid extra
933          * check if count is zero.
934          */
935         switch (count % 4) {
936         case 0:
937                 while (idx != count) {
938                         __rte_mbuf_raw_sanity_check(mbufs[idx]);
939                         rte_pktmbuf_reset(mbufs[idx]);
940                         idx++;
941                         /* fall-through */
942         case 3:
943                         __rte_mbuf_raw_sanity_check(mbufs[idx]);
944                         rte_pktmbuf_reset(mbufs[idx]);
945                         idx++;
946                         /* fall-through */
947         case 2:
948                         __rte_mbuf_raw_sanity_check(mbufs[idx]);
949                         rte_pktmbuf_reset(mbufs[idx]);
950                         idx++;
951                         /* fall-through */
952         case 1:
953                         __rte_mbuf_raw_sanity_check(mbufs[idx]);
954                         rte_pktmbuf_reset(mbufs[idx]);
955                         idx++;
956                         /* fall-through */
957                 }
958         }
959         return 0;
960 }
961
962 /**
963  * Initialize shared data at the end of an external buffer before attaching
964  * to a mbuf by ``rte_pktmbuf_attach_extbuf()``. This is not a mandatory
965  * initialization but a helper function to simply spare a few bytes at the
966  * end of the buffer for shared data. If shared data is allocated
967  * separately, this should not be called but application has to properly
968  * initialize the shared data according to its need.
969  *
970  * Free callback and its argument is saved and the refcnt is set to 1.
971  *
972  * @warning
973  * The value of buf_len will be reduced to RTE_PTR_DIFF(shinfo, buf_addr)
974  * after this initialization. This shall be used for
975  * ``rte_pktmbuf_attach_extbuf()``
976  *
977  * @param buf_addr
978  *   The pointer to the external buffer.
979  * @param [in,out] buf_len
980  *   The pointer to length of the external buffer. Input value must be
981  *   larger than the size of ``struct rte_mbuf_ext_shared_info`` and
982  *   padding for alignment. If not enough, this function will return NULL.
983  *   Adjusted buffer length will be returned through this pointer.
984  * @param free_cb
985  *   Free callback function to call when the external buffer needs to be
986  *   freed.
987  * @param fcb_opaque
988  *   Argument for the free callback function.
989  *
990  * @return
991  *   A pointer to the initialized shared data on success, return NULL
992  *   otherwise.
993  */
994 static inline struct rte_mbuf_ext_shared_info *
995 rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
996         rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)
997 {
998         struct rte_mbuf_ext_shared_info *shinfo;
999         void *buf_end = RTE_PTR_ADD(buf_addr, *buf_len);
1000         void *addr;
1001
1002         addr = RTE_PTR_ALIGN_FLOOR(RTE_PTR_SUB(buf_end, sizeof(*shinfo)),
1003                                    sizeof(uintptr_t));
1004         if (addr <= buf_addr)
1005                 return NULL;
1006
1007         shinfo = (struct rte_mbuf_ext_shared_info *)addr;
1008         shinfo->free_cb = free_cb;
1009         shinfo->fcb_opaque = fcb_opaque;
1010         rte_mbuf_ext_refcnt_set(shinfo, 1);
1011
1012         *buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
1013         return shinfo;
1014 }
1015
1016 /**
1017  * Attach an external buffer to a mbuf.
1018  *
1019  * User-managed anonymous buffer can be attached to an mbuf. When attaching
1020  * it, corresponding free callback function and its argument should be
1021  * provided via shinfo. This callback function will be called once all the
1022  * mbufs are detached from the buffer (refcnt becomes zero).
1023  *
1024  * The headroom length of the attaching mbuf will be set to zero and this
1025  * can be properly adjusted after attachment. For example, ``rte_pktmbuf_adj()``
1026  * or ``rte_pktmbuf_reset_headroom()`` might be used.
1027  *
1028  * Similarly, the packet length is initialized to 0. If the buffer contains
1029  * data, the user has to adjust ``data_len`` and the ``pkt_len`` field of
1030  * the mbuf accordingly.
1031  *
1032  * More mbufs can be attached to the same external buffer by
1033  * ``rte_pktmbuf_attach()`` once the external buffer has been attached by
1034  * this API.
1035  *
1036  * Detachment can be done by either ``rte_pktmbuf_detach_extbuf()`` or
1037  * ``rte_pktmbuf_detach()``.
1038  *
1039  * Memory for shared data must be provided and user must initialize all of
1040  * the content properly, especially free callback and refcnt. The pointer
1041  * of shared data will be stored in m->shinfo.
1042  * ``rte_pktmbuf_ext_shinfo_init_helper`` can help to simply spare a few
1043  * bytes at the end of buffer for the shared data, store free callback and
1044  * its argument and set the refcnt to 1. The following is an example:
1045  *
1046  *   struct rte_mbuf_ext_shared_info *shinfo =
1047  *          rte_pktmbuf_ext_shinfo_init_helper(buf_addr, &buf_len,
1048  *                                             free_cb, fcb_arg);
1049  *   rte_pktmbuf_attach_extbuf(m, buf_addr, buf_iova, buf_len, shinfo);
1050  *   rte_pktmbuf_reset_headroom(m);
1051  *   rte_pktmbuf_adj(m, data_len);
1052  *
1053  * Attaching an external buffer is quite similar to mbuf indirection in
1054  * replacing buffer addresses and length of a mbuf, but a few differences:
1055  * - When an indirect mbuf is attached, refcnt of the direct mbuf would be
1056  *   2 as long as the direct mbuf itself isn't freed after the attachment.
1057  *   In such cases, the buffer area of a direct mbuf must be read-only. But
1058  *   external buffer has its own refcnt and it starts from 1. Unless
1059  *   multiple mbufs are attached to a mbuf having an external buffer, the
1060  *   external buffer is writable.
1061  * - There's no need to allocate buffer from a mempool. Any buffer can be
1062  *   attached with appropriate free callback and its IO address.
1063  * - Smaller metadata is required to maintain shared data such as refcnt.
1064  *
1065  * @param m
1066  *   The pointer to the mbuf.
1067  * @param buf_addr
1068  *   The pointer to the external buffer.
1069  * @param buf_iova
1070  *   IO address of the external buffer.
1071  * @param buf_len
1072  *   The size of the external buffer.
1073  * @param shinfo
1074  *   User-provided memory for shared data of the external buffer.
1075  */
1076 static inline void
1077 rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
1078         rte_iova_t buf_iova, uint16_t buf_len,
1079         struct rte_mbuf_ext_shared_info *shinfo)
1080 {
1081         /* mbuf should not be read-only */
1082         RTE_ASSERT(RTE_MBUF_DIRECT(m) && rte_mbuf_refcnt_read(m) == 1);
1083         RTE_ASSERT(shinfo->free_cb != NULL);
1084
1085         m->buf_addr = buf_addr;
1086         m->buf_iova = buf_iova;
1087         m->buf_len = buf_len;
1088
1089         m->data_len = 0;
1090         m->data_off = 0;
1091
1092         m->ol_flags |= EXT_ATTACHED_MBUF;
1093         m->shinfo = shinfo;
1094 }
1095
1096 /**
1097  * Detach the external buffer attached to a mbuf, same as
1098  * ``rte_pktmbuf_detach()``
1099  *
1100  * @param m
1101  *   The mbuf having external buffer.
1102  */
1103 #define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)
1104
1105 /**
1106  * Copy dynamic fields from msrc to mdst.
1107  *
1108  * @param mdst
1109  *   The destination mbuf.
1110  * @param msrc
1111  *   The source mbuf.
1112  */
1113 static inline void
1114 rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1115 {
1116         memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst->dynfield1));
1117 }
1118
1119 /* internal */
1120 static inline void
1121 __rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1122 {
1123         mdst->port = msrc->port;
1124         mdst->vlan_tci = msrc->vlan_tci;
1125         mdst->vlan_tci_outer = msrc->vlan_tci_outer;
1126         mdst->tx_offload = msrc->tx_offload;
1127         mdst->hash = msrc->hash;
1128         mdst->packet_type = msrc->packet_type;
1129         rte_mbuf_dynfield_copy(mdst, msrc);
1130 }
1131
1132 /**
1133  * Attach packet mbuf to another packet mbuf.
1134  *
1135  * If the mbuf we are attaching to isn't a direct buffer and is attached to
1136  * an external buffer, the mbuf being attached will be attached to the
1137  * external buffer instead of mbuf indirection.
1138  *
1139  * Otherwise, the mbuf will be indirectly attached. After attachment we
1140  * refer the mbuf we attached as 'indirect', while mbuf we attached to as
1141  * 'direct'.  The direct mbuf's reference counter is incremented.
1142  *
1143  * Right now, not supported:
1144  *  - attachment for already indirect mbuf (e.g. - mi has to be direct).
1145  *  - mbuf we trying to attach (mi) is used by someone else
1146  *    e.g. it's reference counter is greater then 1.
1147  *
1148  * @param mi
1149  *   The indirect packet mbuf.
1150  * @param m
1151  *   The packet mbuf we're attaching to.
1152  */
1153 static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
1154 {
1155         RTE_ASSERT(RTE_MBUF_DIRECT(mi) &&
1156             rte_mbuf_refcnt_read(mi) == 1);
1157
1158         if (RTE_MBUF_HAS_EXTBUF(m)) {
1159                 rte_mbuf_ext_refcnt_update(m->shinfo, 1);
1160                 mi->ol_flags = m->ol_flags;
1161                 mi->shinfo = m->shinfo;
1162         } else {
1163                 /* if m is not direct, get the mbuf that embeds the data */
1164                 rte_mbuf_refcnt_update(rte_mbuf_from_indirect(m), 1);
1165                 mi->priv_size = m->priv_size;
1166                 mi->ol_flags = m->ol_flags | IND_ATTACHED_MBUF;
1167         }
1168
1169         __rte_pktmbuf_copy_hdr(mi, m);
1170
1171         mi->data_off = m->data_off;
1172         mi->data_len = m->data_len;
1173         mi->buf_iova = m->buf_iova;
1174         mi->buf_addr = m->buf_addr;
1175         mi->buf_len = m->buf_len;
1176
1177         mi->next = NULL;
1178         mi->pkt_len = mi->data_len;
1179         mi->nb_segs = 1;
1180
1181         __rte_mbuf_sanity_check(mi, 1);
1182         __rte_mbuf_sanity_check(m, 0);
1183 }
1184
1185 /**
1186  * @internal used by rte_pktmbuf_detach().
1187  *
1188  * Decrement the reference counter of the external buffer. When the
1189  * reference counter becomes 0, the buffer is freed by pre-registered
1190  * callback.
1191  */
1192 static inline void
1193 __rte_pktmbuf_free_extbuf(struct rte_mbuf *m)
1194 {
1195         RTE_ASSERT(RTE_MBUF_HAS_EXTBUF(m));
1196         RTE_ASSERT(m->shinfo != NULL);
1197
1198         if (rte_mbuf_ext_refcnt_update(m->shinfo, -1) == 0)
1199                 m->shinfo->free_cb(m->buf_addr, m->shinfo->fcb_opaque);
1200 }
1201
1202 /**
1203  * @internal used by rte_pktmbuf_detach().
1204  *
1205  * Decrement the direct mbuf's reference counter. When the reference
1206  * counter becomes 0, the direct mbuf is freed.
1207  */
1208 static inline void
1209 __rte_pktmbuf_free_direct(struct rte_mbuf *m)
1210 {
1211         struct rte_mbuf *md;
1212
1213         RTE_ASSERT(RTE_MBUF_CLONED(m));
1214
1215         md = rte_mbuf_from_indirect(m);
1216
1217         if (rte_mbuf_refcnt_update(md, -1) == 0) {
1218                 md->next = NULL;
1219                 md->nb_segs = 1;
1220                 rte_mbuf_refcnt_set(md, 1);
1221                 rte_mbuf_raw_free(md);
1222         }
1223 }
1224
1225 /**
1226  * Detach a packet mbuf from external buffer or direct buffer.
1227  *
1228  *  - decrement refcnt and free the external/direct buffer if refcnt
1229  *    becomes zero.
1230  *  - restore original mbuf address and length values.
1231  *  - reset pktmbuf data and data_len to their default values.
1232  *
1233  * All other fields of the given packet mbuf will be left intact.
1234  *
1235  * If the packet mbuf was allocated from the pool with pinned
1236  * external buffers the rte_pktmbuf_detach does nothing with the
1237  * mbuf of this kind, because the pinned buffers are not supposed
1238  * to be detached.
1239  *
1240  * @param m
1241  *   The indirect attached packet mbuf.
1242  */
1243 static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
1244 {
1245         struct rte_mempool *mp = m->pool;
1246         uint32_t mbuf_size, buf_len;
1247         uint16_t priv_size;
1248
1249         if (RTE_MBUF_HAS_EXTBUF(m)) {
1250                 /*
1251                  * The mbuf has the external attached buffer,
1252                  * we should check the type of the memory pool where
1253                  * the mbuf was allocated from to detect the pinned
1254                  * external buffer.
1255                  */
1256                 uint32_t flags = rte_pktmbuf_priv_flags(mp);
1257
1258                 if (flags & RTE_PKTMBUF_POOL_F_PINNED_EXT_BUF) {
1259                         /*
1260                          * The pinned external buffer should not be
1261                          * detached from its backing mbuf, just exit.
1262                          */
1263                         return;
1264                 }
1265                 __rte_pktmbuf_free_extbuf(m);
1266         } else {
1267                 __rte_pktmbuf_free_direct(m);
1268         }
1269         priv_size = rte_pktmbuf_priv_size(mp);
1270         mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size);
1271         buf_len = rte_pktmbuf_data_room_size(mp);
1272
1273         m->priv_size = priv_size;
1274         m->buf_addr = (char *)m + mbuf_size;
1275         m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
1276         m->buf_len = (uint16_t)buf_len;
1277         rte_pktmbuf_reset_headroom(m);
1278         m->data_len = 0;
1279         m->ol_flags = 0;
1280 }
1281
1282 /**
1283  * @internal Handle the packet mbufs with attached pinned external buffer
1284  * on the mbuf freeing:
1285  *
1286  *  - return zero if reference counter in shinfo is one. It means there is
1287  *  no more reference to this pinned buffer and mbuf can be returned to
1288  *  the pool
1289  *
1290  *  - otherwise (if reference counter is not one), decrement reference
1291  *  counter and return non-zero value to prevent freeing the backing mbuf.
1292  *
1293  * Returns non zero if mbuf should not be freed.
1294  */
1295 static inline int __rte_pktmbuf_pinned_extbuf_decref(struct rte_mbuf *m)
1296 {
1297         struct rte_mbuf_ext_shared_info *shinfo;
1298
1299         /* Clear flags, mbuf is being freed. */
1300         m->ol_flags = EXT_ATTACHED_MBUF;
1301         shinfo = m->shinfo;
1302
1303         /* Optimize for performance - do not dec/reinit */
1304         if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1))
1305                 return 0;
1306
1307         /*
1308          * Direct usage of add primitive to avoid
1309          * duplication of comparing with one.
1310          */
1311         if (likely(__atomic_add_fetch(&shinfo->refcnt, (uint16_t)-1,
1312                                      __ATOMIC_ACQ_REL)))
1313                 return 1;
1314
1315         /* Reinitialize counter before mbuf freeing. */
1316         rte_mbuf_ext_refcnt_set(shinfo, 1);
1317         return 0;
1318 }
1319
1320 /**
1321  * Decrease reference counter and unlink a mbuf segment
1322  *
1323  * This function does the same than a free, except that it does not
1324  * return the segment to its pool.
1325  * It decreases the reference counter, and if it reaches 0, it is
1326  * detached from its parent for an indirect mbuf.
1327  *
1328  * @param m
1329  *   The mbuf to be unlinked
1330  * @return
1331  *   - (m) if it is the last reference. It can be recycled or freed.
1332  *   - (NULL) if the mbuf still has remaining references on it.
1333  */
1334 static __rte_always_inline struct rte_mbuf *
1335 rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
1336 {
1337         __rte_mbuf_sanity_check(m, 0);
1338
1339         if (likely(rte_mbuf_refcnt_read(m) == 1)) {
1340
1341                 if (!RTE_MBUF_DIRECT(m)) {
1342                         rte_pktmbuf_detach(m);
1343                         if (RTE_MBUF_HAS_EXTBUF(m) &&
1344                             RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
1345                             __rte_pktmbuf_pinned_extbuf_decref(m))
1346                                 return NULL;
1347                 }
1348
1349                 if (m->next != NULL) {
1350                         m->next = NULL;
1351                         m->nb_segs = 1;
1352                 }
1353
1354                 return m;
1355
1356         } else if (__rte_mbuf_refcnt_update(m, -1) == 0) {
1357
1358                 if (!RTE_MBUF_DIRECT(m)) {
1359                         rte_pktmbuf_detach(m);
1360                         if (RTE_MBUF_HAS_EXTBUF(m) &&
1361                             RTE_MBUF_HAS_PINNED_EXTBUF(m) &&
1362                             __rte_pktmbuf_pinned_extbuf_decref(m))
1363                                 return NULL;
1364                 }
1365
1366                 if (m->next != NULL) {
1367                         m->next = NULL;
1368                         m->nb_segs = 1;
1369                 }
1370                 rte_mbuf_refcnt_set(m, 1);
1371
1372                 return m;
1373         }
1374         return NULL;
1375 }
1376
1377 /**
1378  * Free a segment of a packet mbuf into its original mempool.
1379  *
1380  * Free an mbuf, without parsing other segments in case of chained
1381  * buffers.
1382  *
1383  * @param m
1384  *   The packet mbuf segment to be freed.
1385  */
1386 static __rte_always_inline void
1387 rte_pktmbuf_free_seg(struct rte_mbuf *m)
1388 {
1389         m = rte_pktmbuf_prefree_seg(m);
1390         if (likely(m != NULL))
1391                 rte_mbuf_raw_free(m);
1392 }
1393
1394 /**
1395  * Free a packet mbuf back into its original mempool.
1396  *
1397  * Free an mbuf, and all its segments in case of chained buffers. Each
1398  * segment is added back into its original mempool.
1399  *
1400  * @param m
1401  *   The packet mbuf to be freed. If NULL, the function does nothing.
1402  */
1403 static inline void rte_pktmbuf_free(struct rte_mbuf *m)
1404 {
1405         struct rte_mbuf *m_next;
1406
1407         if (m != NULL)
1408                 __rte_mbuf_sanity_check(m, 1);
1409
1410         while (m != NULL) {
1411                 m_next = m->next;
1412                 rte_pktmbuf_free_seg(m);
1413                 m = m_next;
1414         }
1415 }
1416
1417 /**
1418  * Free a bulk of packet mbufs back into their original mempools.
1419  *
1420  * Free a bulk of mbufs, and all their segments in case of chained buffers.
1421  * Each segment is added back into its original mempool.
1422  *
1423  *  @param mbufs
1424  *    Array of pointers to packet mbufs.
1425  *    The array may contain NULL pointers.
1426  *  @param count
1427  *    Array size.
1428  */
1429 __rte_experimental
1430 void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count);
1431
1432 /**
1433  * Create a "clone" of the given packet mbuf.
1434  *
1435  * Walks through all segments of the given packet mbuf, and for each of them:
1436  *  - Creates a new packet mbuf from the given pool.
1437  *  - Attaches newly created mbuf to the segment.
1438  * Then updates pkt_len and nb_segs of the "clone" packet mbuf to match values
1439  * from the original packet mbuf.
1440  *
1441  * @param md
1442  *   The packet mbuf to be cloned.
1443  * @param mp
1444  *   The mempool from which the "clone" mbufs are allocated.
1445  * @return
1446  *   - The pointer to the new "clone" mbuf on success.
1447  *   - NULL if allocation fails.
1448  */
1449 struct rte_mbuf *
1450 rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp);
1451
1452 /**
1453  * Create a full copy of a given packet mbuf.
1454  *
1455  * Copies all the data from a given packet mbuf to a newly allocated
1456  * set of mbufs. The private data are is not copied.
1457  *
1458  * @param m
1459  *   The packet mbuf to be copiedd.
1460  * @param mp
1461  *   The mempool from which the "clone" mbufs are allocated.
1462  * @param offset
1463  *   The number of bytes to skip before copying.
1464  *   If the mbuf does not have that many bytes, it is an error
1465  *   and NULL is returned.
1466  * @param length
1467  *   The upper limit on bytes to copy.  Passing UINT32_MAX
1468  *   means all data (after offset).
1469  * @return
1470  *   - The pointer to the new "clone" mbuf on success.
1471  *   - NULL if allocation fails.
1472  */
1473 __rte_experimental
1474 struct rte_mbuf *
1475 rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp,
1476                  uint32_t offset, uint32_t length);
1477
1478 /**
1479  * Adds given value to the refcnt of all packet mbuf segments.
1480  *
1481  * Walks through all segments of given packet mbuf and for each of them
1482  * invokes rte_mbuf_refcnt_update().
1483  *
1484  * @param m
1485  *   The packet mbuf whose refcnt to be updated.
1486  * @param v
1487  *   The value to add to the mbuf's segments refcnt.
1488  */
1489 static inline void rte_pktmbuf_refcnt_update(struct rte_mbuf *m, int16_t v)
1490 {
1491         __rte_mbuf_sanity_check(m, 1);
1492
1493         do {
1494                 rte_mbuf_refcnt_update(m, v);
1495         } while ((m = m->next) != NULL);
1496 }
1497
1498 /**
1499  * Get the headroom in a packet mbuf.
1500  *
1501  * @param m
1502  *   The packet mbuf.
1503  * @return
1504  *   The length of the headroom.
1505  */
1506 static inline uint16_t rte_pktmbuf_headroom(const struct rte_mbuf *m)
1507 {
1508         __rte_mbuf_sanity_check(m, 0);
1509         return m->data_off;
1510 }
1511
1512 /**
1513  * Get the tailroom of a packet mbuf.
1514  *
1515  * @param m
1516  *   The packet mbuf.
1517  * @return
1518  *   The length of the tailroom.
1519  */
1520 static inline uint16_t rte_pktmbuf_tailroom(const struct rte_mbuf *m)
1521 {
1522         __rte_mbuf_sanity_check(m, 0);
1523         return (uint16_t)(m->buf_len - rte_pktmbuf_headroom(m) -
1524                           m->data_len);
1525 }
1526
1527 /**
1528  * Get the last segment of the packet.
1529  *
1530  * @param m
1531  *   The packet mbuf.
1532  * @return
1533  *   The last segment of the given mbuf.
1534  */
1535 static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m)
1536 {
1537         __rte_mbuf_sanity_check(m, 1);
1538         while (m->next != NULL)
1539                 m = m->next;
1540         return m;
1541 }
1542
1543 /**
1544  * A macro that returns the length of the packet.
1545  *
1546  * The value can be read or assigned.
1547  *
1548  * @param m
1549  *   The packet mbuf.
1550  */
1551 #define rte_pktmbuf_pkt_len(m) ((m)->pkt_len)
1552
1553 /**
1554  * A macro that returns the length of the segment.
1555  *
1556  * The value can be read or assigned.
1557  *
1558  * @param m
1559  *   The packet mbuf.
1560  */
1561 #define rte_pktmbuf_data_len(m) ((m)->data_len)
1562
1563 /**
1564  * Prepend len bytes to an mbuf data area.
1565  *
1566  * Returns a pointer to the new
1567  * data start address. If there is not enough headroom in the first
1568  * segment, the function will return NULL, without modifying the mbuf.
1569  *
1570  * @param m
1571  *   The pkt mbuf.
1572  * @param len
1573  *   The amount of data to prepend (in bytes).
1574  * @return
1575  *   A pointer to the start of the newly prepended data, or
1576  *   NULL if there is not enough headroom space in the first segment
1577  */
1578 static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m,
1579                                         uint16_t len)
1580 {
1581         __rte_mbuf_sanity_check(m, 1);
1582
1583         if (unlikely(len > rte_pktmbuf_headroom(m)))
1584                 return NULL;
1585
1586         /* NB: elaborating the subtraction like this instead of using
1587          *     -= allows us to ensure the result type is uint16_t
1588          *     avoiding compiler warnings on gcc 8.1 at least */
1589         m->data_off = (uint16_t)(m->data_off - len);
1590         m->data_len = (uint16_t)(m->data_len + len);
1591         m->pkt_len  = (m->pkt_len + len);
1592
1593         return (char *)m->buf_addr + m->data_off;
1594 }
1595
1596 /**
1597  * Append len bytes to an mbuf.
1598  *
1599  * Append len bytes to an mbuf and return a pointer to the start address
1600  * of the added data. If there is not enough tailroom in the last
1601  * segment, the function will return NULL, without modifying the mbuf.
1602  *
1603  * @param m
1604  *   The packet mbuf.
1605  * @param len
1606  *   The amount of data to append (in bytes).
1607  * @return
1608  *   A pointer to the start of the newly appended data, or
1609  *   NULL if there is not enough tailroom space in the last segment
1610  */
1611 static inline char *rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
1612 {
1613         void *tail;
1614         struct rte_mbuf *m_last;
1615
1616         __rte_mbuf_sanity_check(m, 1);
1617
1618         m_last = rte_pktmbuf_lastseg(m);
1619         if (unlikely(len > rte_pktmbuf_tailroom(m_last)))
1620                 return NULL;
1621
1622         tail = (char *)m_last->buf_addr + m_last->data_off + m_last->data_len;
1623         m_last->data_len = (uint16_t)(m_last->data_len + len);
1624         m->pkt_len  = (m->pkt_len + len);
1625         return (char*) tail;
1626 }
1627
1628 /**
1629  * Remove len bytes at the beginning of an mbuf.
1630  *
1631  * Returns a pointer to the start address of the new data area. If the
1632  * length is greater than the length of the first segment, then the
1633  * function will fail and return NULL, without modifying the mbuf.
1634  *
1635  * @param m
1636  *   The packet mbuf.
1637  * @param len
1638  *   The amount of data to remove (in bytes).
1639  * @return
1640  *   A pointer to the new start of the data.
1641  */
1642 static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
1643 {
1644         __rte_mbuf_sanity_check(m, 1);
1645
1646         if (unlikely(len > m->data_len))
1647                 return NULL;
1648
1649         /* NB: elaborating the addition like this instead of using
1650          *     += allows us to ensure the result type is uint16_t
1651          *     avoiding compiler warnings on gcc 8.1 at least */
1652         m->data_len = (uint16_t)(m->data_len - len);
1653         m->data_off = (uint16_t)(m->data_off + len);
1654         m->pkt_len  = (m->pkt_len - len);
1655         return (char *)m->buf_addr + m->data_off;
1656 }
1657
1658 /**
1659  * Remove len bytes of data at the end of the mbuf.
1660  *
1661  * If the length is greater than the length of the last segment, the
1662  * function will fail and return -1 without modifying the mbuf.
1663  *
1664  * @param m
1665  *   The packet mbuf.
1666  * @param len
1667  *   The amount of data to remove (in bytes).
1668  * @return
1669  *   - 0: On success.
1670  *   - -1: On error.
1671  */
1672 static inline int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
1673 {
1674         struct rte_mbuf *m_last;
1675
1676         __rte_mbuf_sanity_check(m, 1);
1677
1678         m_last = rte_pktmbuf_lastseg(m);
1679         if (unlikely(len > m_last->data_len))
1680                 return -1;
1681
1682         m_last->data_len = (uint16_t)(m_last->data_len - len);
1683         m->pkt_len  = (m->pkt_len - len);
1684         return 0;
1685 }
1686
1687 /**
1688  * Test if mbuf data is contiguous.
1689  *
1690  * @param m
1691  *   The packet mbuf.
1692  * @return
1693  *   - 1, if all data is contiguous (one segment).
1694  *   - 0, if there is several segments.
1695  */
1696 static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
1697 {
1698         __rte_mbuf_sanity_check(m, 1);
1699         return m->nb_segs == 1;
1700 }
1701
1702 /**
1703  * @internal used by rte_pktmbuf_read().
1704  */
1705 const void *__rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off,
1706         uint32_t len, void *buf);
1707
1708 /**
1709  * Read len data bytes in a mbuf at specified offset.
1710  *
1711  * If the data is contiguous, return the pointer in the mbuf data, else
1712  * copy the data in the buffer provided by the user and return its
1713  * pointer.
1714  *
1715  * @param m
1716  *   The pointer to the mbuf.
1717  * @param off
1718  *   The offset of the data in the mbuf.
1719  * @param len
1720  *   The amount of bytes to read.
1721  * @param buf
1722  *   The buffer where data is copied if it is not contiguous in mbuf
1723  *   data. Its length should be at least equal to the len parameter.
1724  * @return
1725  *   The pointer to the data, either in the mbuf if it is contiguous,
1726  *   or in the user buffer. If mbuf is too small, NULL is returned.
1727  */
1728 static inline const void *rte_pktmbuf_read(const struct rte_mbuf *m,
1729         uint32_t off, uint32_t len, void *buf)
1730 {
1731         if (likely(off + len <= rte_pktmbuf_data_len(m)))
1732                 return rte_pktmbuf_mtod_offset(m, char *, off);
1733         else
1734                 return __rte_pktmbuf_read(m, off, len, buf);
1735 }
1736
1737 /**
1738  * Chain an mbuf to another, thereby creating a segmented packet.
1739  *
1740  * Note: The implementation will do a linear walk over the segments to find
1741  * the tail entry. For cases when there are many segments, it's better to
1742  * chain the entries manually.
1743  *
1744  * @param head
1745  *   The head of the mbuf chain (the first packet)
1746  * @param tail
1747  *   The mbuf to put last in the chain
1748  *
1749  * @return
1750  *   - 0, on success.
1751  *   - -EOVERFLOW, if the chain segment limit exceeded
1752  */
1753 static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
1754 {
1755         struct rte_mbuf *cur_tail;
1756
1757         /* Check for number-of-segments-overflow */
1758         if (head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS)
1759                 return -EOVERFLOW;
1760
1761         /* Chain 'tail' onto the old tail */
1762         cur_tail = rte_pktmbuf_lastseg(head);
1763         cur_tail->next = tail;
1764
1765         /* accumulate number of segments and total length.
1766          * NB: elaborating the addition like this instead of using
1767          *     -= allows us to ensure the result type is uint16_t
1768          *     avoiding compiler warnings on gcc 8.1 at least */
1769         head->nb_segs = (uint16_t)(head->nb_segs + tail->nb_segs);
1770         head->pkt_len += tail->pkt_len;
1771
1772         /* pkt_len is only set in the head */
1773         tail->pkt_len = tail->data_len;
1774
1775         return 0;
1776 }
1777
1778 /*
1779  * @warning
1780  * @b EXPERIMENTAL: This API may change without prior notice.
1781  *
1782  * For given input values generate raw tx_offload value.
1783  * Note that it is caller responsibility to make sure that input parameters
1784  * don't exceed maximum bit-field values.
1785  * @param il2
1786  *   l2_len value.
1787  * @param il3
1788  *   l3_len value.
1789  * @param il4
1790  *   l4_len value.
1791  * @param tso
1792  *   tso_segsz value.
1793  * @param ol3
1794  *   outer_l3_len value.
1795  * @param ol2
1796  *   outer_l2_len value.
1797  * @param unused
1798  *   unused value.
1799  * @return
1800  *   raw tx_offload value.
1801  */
1802 static __rte_always_inline uint64_t
1803 rte_mbuf_tx_offload(uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso,
1804         uint64_t ol3, uint64_t ol2, uint64_t unused)
1805 {
1806         return il2 << RTE_MBUF_L2_LEN_OFS |
1807                 il3 << RTE_MBUF_L3_LEN_OFS |
1808                 il4 << RTE_MBUF_L4_LEN_OFS |
1809                 tso << RTE_MBUF_TSO_SEGSZ_OFS |
1810                 ol3 << RTE_MBUF_OUTL3_LEN_OFS |
1811                 ol2 << RTE_MBUF_OUTL2_LEN_OFS |
1812                 unused << RTE_MBUF_TXOFLD_UNUSED_OFS;
1813 }
1814
1815 /**
1816  * Validate general requirements for Tx offload in mbuf.
1817  *
1818  * This function checks correctness and completeness of Tx offload settings.
1819  *
1820  * @param m
1821  *   The packet mbuf to be validated.
1822  * @return
1823  *   0 if packet is valid
1824  */
1825 static inline int
1826 rte_validate_tx_offload(const struct rte_mbuf *m)
1827 {
1828         uint64_t ol_flags = m->ol_flags;
1829
1830         /* Does packet set any of available offloads? */
1831         if (!(ol_flags & PKT_TX_OFFLOAD_MASK))
1832                 return 0;
1833
1834         /* IP checksum can be counted only for IPv4 packet */
1835         if ((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6))
1836                 return -EINVAL;
1837
1838         /* IP type not set when required */
1839         if (ol_flags & (PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
1840                 if (!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6)))
1841                         return -EINVAL;
1842
1843         /* Check requirements for TSO packet */
1844         if (ol_flags & PKT_TX_TCP_SEG)
1845                 if ((m->tso_segsz == 0) ||
1846                                 ((ol_flags & PKT_TX_IPV4) &&
1847                                 !(ol_flags & PKT_TX_IP_CKSUM)))
1848                         return -EINVAL;
1849
1850         /* PKT_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */
1851         if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) &&
1852                         !(ol_flags & PKT_TX_OUTER_IPV4))
1853                 return -EINVAL;
1854
1855         return 0;
1856 }
1857
1858 /**
1859  * @internal used by rte_pktmbuf_linearize().
1860  */
1861 int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf);
1862
1863 /**
1864  * Linearize data in mbuf.
1865  *
1866  * This function moves the mbuf data in the first segment if there is enough
1867  * tailroom. The subsequent segments are unchained and freed.
1868  *
1869  * @param mbuf
1870  *   mbuf to linearize
1871  * @return
1872  *   - 0, on success
1873  *   - -1, on error
1874  */
1875 static inline int
1876 rte_pktmbuf_linearize(struct rte_mbuf *mbuf)
1877 {
1878         if (rte_pktmbuf_is_contiguous(mbuf))
1879                 return 0;
1880         return __rte_pktmbuf_linearize(mbuf);
1881 }
1882
1883 /**
1884  * Dump an mbuf structure to a file.
1885  *
1886  * Dump all fields for the given packet mbuf and all its associated
1887  * segments (in the case of a chained buffer).
1888  *
1889  * @param f
1890  *   A pointer to a file for output
1891  * @param m
1892  *   The packet mbuf.
1893  * @param dump_len
1894  *   If dump_len != 0, also dump the "dump_len" first data bytes of
1895  *   the packet.
1896  */
1897 void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len);
1898
1899 /**
1900  * Get the value of mbuf sched queue_id field.
1901  */
1902 static inline uint32_t
1903 rte_mbuf_sched_queue_get(const struct rte_mbuf *m)
1904 {
1905         return m->hash.sched.queue_id;
1906 }
1907
1908 /**
1909  * Get the value of mbuf sched traffic_class field.
1910  */
1911 static inline uint8_t
1912 rte_mbuf_sched_traffic_class_get(const struct rte_mbuf *m)
1913 {
1914         return m->hash.sched.traffic_class;
1915 }
1916
1917 /**
1918  * Get the value of mbuf sched color field.
1919  */
1920 static inline uint8_t
1921 rte_mbuf_sched_color_get(const struct rte_mbuf *m)
1922 {
1923         return m->hash.sched.color;
1924 }
1925
1926 /**
1927  * Get the values of mbuf sched queue_id, traffic_class and color.
1928  *
1929  * @param m
1930  *   Mbuf to read
1931  * @param queue_id
1932  *  Returns the queue id
1933  * @param traffic_class
1934  *  Returns the traffic class id
1935  * @param color
1936  *  Returns the colour id
1937  */
1938 static inline void
1939 rte_mbuf_sched_get(const struct rte_mbuf *m, uint32_t *queue_id,
1940                         uint8_t *traffic_class,
1941                         uint8_t *color)
1942 {
1943         struct rte_mbuf_sched sched = m->hash.sched;
1944
1945         *queue_id = sched.queue_id;
1946         *traffic_class = sched.traffic_class;
1947         *color = sched.color;
1948 }
1949
1950 /**
1951  * Set the mbuf sched queue_id to the defined value.
1952  */
1953 static inline void
1954 rte_mbuf_sched_queue_set(struct rte_mbuf *m, uint32_t queue_id)
1955 {
1956         m->hash.sched.queue_id = queue_id;
1957 }
1958
1959 /**
1960  * Set the mbuf sched traffic_class id to the defined value.
1961  */
1962 static inline void
1963 rte_mbuf_sched_traffic_class_set(struct rte_mbuf *m, uint8_t traffic_class)
1964 {
1965         m->hash.sched.traffic_class = traffic_class;
1966 }
1967
1968 /**
1969  * Set the mbuf sched color id to the defined value.
1970  */
1971 static inline void
1972 rte_mbuf_sched_color_set(struct rte_mbuf *m, uint8_t color)
1973 {
1974         m->hash.sched.color = color;
1975 }
1976
1977 /**
1978  * Set the mbuf sched queue_id, traffic_class and color.
1979  *
1980  * @param m
1981  *   Mbuf to set
1982  * @param queue_id
1983  *  Queue id value to be set
1984  * @param traffic_class
1985  *  Traffic class id value to be set
1986  * @param color
1987  *  Color id to be set
1988  */
1989 static inline void
1990 rte_mbuf_sched_set(struct rte_mbuf *m, uint32_t queue_id,
1991                         uint8_t traffic_class,
1992                         uint8_t color)
1993 {
1994         m->hash.sched = (struct rte_mbuf_sched){
1995                                 .queue_id = queue_id,
1996                                 .traffic_class = traffic_class,
1997                                 .color = color,
1998                                 .reserved = 0,
1999                         };
2000 }
2001
2002 #ifdef __cplusplus
2003 }
2004 #endif
2005
2006 #endif /* _RTE_MBUF_H_ */