1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright 2014 6WIND S.A.
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.
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
25 * This library provides an API to allocate/free packet mbufs, which are
26 * used to carry network packets.
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
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_atomic.h>
41 #include <rte_prefetch.h>
42 #include <rte_branch_prediction.h>
43 #include <rte_byteorder.h>
44 #include <rte_mbuf_ptype.h>
45 #include <rte_mbuf_core.h>
52 * Get the name of a RX offload flag
55 * The mask describing the flag.
57 * The name of this flag, or NULL if it's not a valid RX flag.
59 const char *rte_get_rx_ol_flag_name(uint64_t mask);
62 * Dump the list of RX offload flags in a buffer
65 * The mask describing the RX flags.
69 * The length of the buffer.
71 * 0 on success, (-1) on error.
73 int rte_get_rx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
76 * Get the name of a TX offload flag
79 * The mask describing the flag. Usually only one bit must be set.
80 * Several bits can be given if they belong to the same mask.
83 * The name of this flag, or NULL if it's not a valid TX flag.
85 const char *rte_get_tx_ol_flag_name(uint64_t mask);
88 * Dump the list of TX offload flags in a buffer
91 * The mask describing the TX flags.
95 * The length of the buffer.
97 * 0 on success, (-1) on error.
99 int rte_get_tx_ol_flag_list(uint64_t mask, char *buf, size_t buflen);
102 * Prefetch the first part of the mbuf
104 * The first 64 bytes of the mbuf corresponds to fields that are used early
105 * in the receive path. If the cache line of the architecture is higher than
106 * 64B, the second part will also be prefetched.
109 * The pointer to the mbuf.
112 rte_mbuf_prefetch_part1(struct rte_mbuf *m)
114 rte_prefetch0(&m->cacheline0);
118 * Prefetch the second part of the mbuf
120 * The next 64 bytes of the mbuf corresponds to fields that are used in the
121 * transmit path. If the cache line of the architecture is higher than 64B,
122 * this function does nothing as it is expected that the full mbuf is
126 * The pointer to the mbuf.
129 rte_mbuf_prefetch_part2(struct rte_mbuf *m)
131 #if RTE_CACHE_LINE_SIZE == 64
132 rte_prefetch0(&m->cacheline1);
139 static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp);
142 * Return the IO address of the beginning of the mbuf data
145 * The pointer to the mbuf.
147 * The IO address of the beginning of the mbuf data
149 static inline rte_iova_t
150 rte_mbuf_data_iova(const struct rte_mbuf *mb)
152 return mb->buf_iova + mb->data_off;
156 static inline phys_addr_t
157 rte_mbuf_data_dma_addr(const struct rte_mbuf *mb)
159 return rte_mbuf_data_iova(mb);
163 * Return the default IO address of the beginning of the mbuf data
165 * This function is used by drivers in their receive function, as it
166 * returns the location where data should be written by the NIC, taking
167 * the default headroom in account.
170 * The pointer to the mbuf.
172 * The IO address of the beginning of the mbuf data
174 static inline rte_iova_t
175 rte_mbuf_data_iova_default(const struct rte_mbuf *mb)
177 return mb->buf_iova + RTE_PKTMBUF_HEADROOM;
181 static inline phys_addr_t
182 rte_mbuf_data_dma_addr_default(const struct rte_mbuf *mb)
184 return rte_mbuf_data_iova_default(mb);
188 * Return the mbuf owning the data buffer address of an indirect mbuf.
191 * The pointer to the indirect mbuf.
193 * The address of the direct mbuf corresponding to buffer_addr.
195 static inline struct rte_mbuf *
196 rte_mbuf_from_indirect(struct rte_mbuf *mi)
198 return (struct rte_mbuf *)RTE_PTR_SUB(mi->buf_addr, sizeof(*mi) + mi->priv_size);
202 * Return address of buffer embedded in the given mbuf.
204 * The return value shall be same as mb->buf_addr if the mbuf is already
205 * initialized and direct. However, this API is useful if mempool of the
206 * mbuf is already known because it doesn't need to access mbuf contents in
207 * order to get the mempool pointer.
210 * @b EXPERIMENTAL: This API may change without prior notice.
211 * This will be used by rte_mbuf_to_baddr() which has redundant code once
212 * experimental tag is removed.
215 * The pointer to the mbuf.
217 * The pointer to the mempool of the mbuf.
219 * The pointer of the mbuf buffer.
223 rte_mbuf_buf_addr(struct rte_mbuf *mb, struct rte_mempool *mp)
225 return (char *)mb + sizeof(*mb) + rte_pktmbuf_priv_size(mp);
229 * Return the default address of the beginning of the mbuf data.
232 * @b EXPERIMENTAL: This API may change without prior notice.
235 * The pointer to the mbuf.
237 * The pointer of the beginning of the mbuf data.
241 rte_mbuf_data_addr_default(__rte_unused struct rte_mbuf *mb)
243 /* gcc complains about calling this experimental function even
244 * when not using it. Hide it with ALLOW_EXPERIMENTAL_API.
246 #ifdef ALLOW_EXPERIMENTAL_API
247 return rte_mbuf_buf_addr(mb, mb->pool) + RTE_PKTMBUF_HEADROOM;
254 * Return address of buffer embedded in the given mbuf.
256 * @note: Accessing mempool pointer of a mbuf is expensive because the
257 * pointer is stored in the 2nd cache line of mbuf. If mempool is known, it
258 * is better not to reference the mempool pointer in mbuf but calling
259 * rte_mbuf_buf_addr() would be more efficient.
262 * The pointer to the mbuf.
264 * The address of the data buffer owned by the mbuf.
267 rte_mbuf_to_baddr(struct rte_mbuf *md)
269 #ifdef ALLOW_EXPERIMENTAL_API
270 return rte_mbuf_buf_addr(md, md->pool);
273 buffer_addr = (char *)md + sizeof(*md) + rte_pktmbuf_priv_size(md->pool);
279 * Return the starting address of the private data area embedded in
282 * Note that no check is made to ensure that a private data area
283 * actually exists in the supplied mbuf.
286 * The pointer to the mbuf.
288 * The starting address of the private data area of the given mbuf.
292 rte_mbuf_to_priv(struct rte_mbuf *m)
294 return RTE_PTR_ADD(m, sizeof(struct rte_mbuf));
298 * Private data in case of pktmbuf pool.
300 * A structure that contains some pktmbuf_pool-specific data that are
301 * appended after the mempool structure (in private data).
303 struct rte_pktmbuf_pool_private {
304 uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf. */
305 uint16_t mbuf_priv_size; /**< Size of private area in each mbuf. */
308 #ifdef RTE_LIBRTE_MBUF_DEBUG
310 /** check mbuf type in debug mode */
311 #define __rte_mbuf_sanity_check(m, is_h) rte_mbuf_sanity_check(m, is_h)
313 #else /* RTE_LIBRTE_MBUF_DEBUG */
315 /** check mbuf type in debug mode */
316 #define __rte_mbuf_sanity_check(m, is_h) do { } while (0)
318 #endif /* RTE_LIBRTE_MBUF_DEBUG */
320 #ifdef RTE_MBUF_REFCNT_ATOMIC
323 * Reads the value of an mbuf's refcnt.
327 * Reference count number.
329 static inline uint16_t
330 rte_mbuf_refcnt_read(const struct rte_mbuf *m)
332 return (uint16_t)(rte_atomic16_read(&m->refcnt_atomic));
336 * Sets an mbuf's refcnt to a defined value.
343 rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
345 rte_atomic16_set(&m->refcnt_atomic, (int16_t)new_value);
349 static inline uint16_t
350 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
352 return (uint16_t)(rte_atomic16_add_return(&m->refcnt_atomic, value));
356 * Adds given value to an mbuf's refcnt and returns its new value.
360 * Value to add/subtract
364 static inline uint16_t
365 rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
368 * The atomic_add is an expensive operation, so we don't want to
369 * call it in the case where we know we are the unique holder of
370 * this mbuf (i.e. ref_cnt == 1). Otherwise, an atomic
371 * operation has to be used because concurrent accesses on the
372 * reference counter can occur.
374 if (likely(rte_mbuf_refcnt_read(m) == 1)) {
376 rte_mbuf_refcnt_set(m, (uint16_t)value);
377 return (uint16_t)value;
380 return __rte_mbuf_refcnt_update(m, value);
383 #else /* ! RTE_MBUF_REFCNT_ATOMIC */
386 static inline uint16_t
387 __rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
389 m->refcnt = (uint16_t)(m->refcnt + value);
394 * Adds given value to an mbuf's refcnt and returns its new value.
396 static inline uint16_t
397 rte_mbuf_refcnt_update(struct rte_mbuf *m, int16_t value)
399 return __rte_mbuf_refcnt_update(m, value);
403 * Reads the value of an mbuf's refcnt.
405 static inline uint16_t
406 rte_mbuf_refcnt_read(const struct rte_mbuf *m)
412 * Sets an mbuf's refcnt to the defined value.
415 rte_mbuf_refcnt_set(struct rte_mbuf *m, uint16_t new_value)
417 m->refcnt = new_value;
420 #endif /* RTE_MBUF_REFCNT_ATOMIC */
423 * Reads the refcnt of an external buffer.
426 * Shared data of the external buffer.
428 * Reference count number.
430 static inline uint16_t
431 rte_mbuf_ext_refcnt_read(const struct rte_mbuf_ext_shared_info *shinfo)
433 return (uint16_t)(rte_atomic16_read(&shinfo->refcnt_atomic));
437 * Set refcnt of an external buffer.
440 * Shared data of the external buffer.
445 rte_mbuf_ext_refcnt_set(struct rte_mbuf_ext_shared_info *shinfo,
448 rte_atomic16_set(&shinfo->refcnt_atomic, (int16_t)new_value);
452 * Add given value to refcnt of an external buffer and return its new
456 * Shared data of the external buffer.
458 * Value to add/subtract
462 static inline uint16_t
463 rte_mbuf_ext_refcnt_update(struct rte_mbuf_ext_shared_info *shinfo,
466 if (likely(rte_mbuf_ext_refcnt_read(shinfo) == 1)) {
468 rte_mbuf_ext_refcnt_set(shinfo, (uint16_t)value);
469 return (uint16_t)value;
472 return (uint16_t)rte_atomic16_add_return(&shinfo->refcnt_atomic, value);
476 #define RTE_MBUF_PREFETCH_TO_FREE(m) do { \
483 * Sanity checks on an mbuf.
485 * Check the consistency of the given mbuf. The function will cause a
486 * panic if corruption is detected.
489 * The mbuf to be checked.
491 * True if the mbuf is a packet header, false if it is a sub-segment
492 * of a packet (in this case, some fields like nb_segs are not checked)
495 rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header);
498 * Sanity checks on a mbuf.
500 * Almost like rte_mbuf_sanity_check(), but this function gives the reason
501 * if corruption is detected rather than panic.
504 * The mbuf to be checked.
506 * True if the mbuf is a packet header, false if it is a sub-segment
507 * of a packet (in this case, some fields like nb_segs are not checked)
509 * A reference to a string pointer where to store the reason why a mbuf is
510 * considered invalid.
512 * - 0 if no issue has been found, reason is left untouched.
513 * - -1 if a problem is detected, reason then points to a string describing
514 * the reason why the mbuf is deemed invalid.
517 int rte_mbuf_check(const struct rte_mbuf *m, int is_header,
518 const char **reason);
520 #define MBUF_RAW_ALLOC_CHECK(m) do { \
521 RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1); \
522 RTE_ASSERT((m)->next == NULL); \
523 RTE_ASSERT((m)->nb_segs == 1); \
524 __rte_mbuf_sanity_check(m, 0); \
528 * Allocate an uninitialized mbuf from mempool *mp*.
530 * This function can be used by PMDs (especially in RX functions) to
531 * allocate an uninitialized mbuf. The driver is responsible of
532 * initializing all the required fields. See rte_pktmbuf_reset().
533 * For standard needs, prefer rte_pktmbuf_alloc().
535 * The caller can expect that the following fields of the mbuf structure
536 * are initialized: buf_addr, buf_iova, buf_len, refcnt=1, nb_segs=1,
537 * next=NULL, pool, priv_size. The other fields must be initialized
541 * The mempool from which mbuf is allocated.
543 * - The pointer to the new mbuf on success.
544 * - NULL if allocation failed.
546 static inline struct rte_mbuf *rte_mbuf_raw_alloc(struct rte_mempool *mp)
550 if (rte_mempool_get(mp, (void **)&m) < 0)
552 MBUF_RAW_ALLOC_CHECK(m);
557 * Put mbuf back into its original mempool.
559 * The caller must ensure that the mbuf is direct and properly
560 * reinitialized (refcnt=1, next=NULL, nb_segs=1), as done by
561 * rte_pktmbuf_prefree_seg().
563 * This function should be used with care, when optimization is
564 * required. For standard needs, prefer rte_pktmbuf_free() or
565 * rte_pktmbuf_free_seg().
568 * The mbuf to be freed.
570 static __rte_always_inline void
571 rte_mbuf_raw_free(struct rte_mbuf *m)
573 RTE_ASSERT(RTE_MBUF_DIRECT(m));
574 RTE_ASSERT(rte_mbuf_refcnt_read(m) == 1);
575 RTE_ASSERT(m->next == NULL);
576 RTE_ASSERT(m->nb_segs == 1);
577 __rte_mbuf_sanity_check(m, 0);
578 rte_mempool_put(m->pool, m);
582 * The packet mbuf constructor.
584 * This function initializes some fields in the mbuf structure that are
585 * not modified by the user once created (origin pool, buffer start
586 * address, and so on). This function is given as a callback function to
587 * rte_mempool_obj_iter() or rte_mempool_create() at pool creation time.
590 * The mempool from which mbufs originate.
592 * A pointer that can be used by the user to retrieve useful information
593 * for mbuf initialization. This pointer is the opaque argument passed to
594 * rte_mempool_obj_iter() or rte_mempool_create().
596 * The mbuf to initialize.
598 * The index of the mbuf in the pool table.
600 void rte_pktmbuf_init(struct rte_mempool *mp, void *opaque_arg,
601 void *m, unsigned i);
605 * A packet mbuf pool constructor.
607 * This function initializes the mempool private data in the case of a
608 * pktmbuf pool. This private data is needed by the driver. The
609 * function must be called on the mempool before it is used, or it
610 * can be given as a callback function to rte_mempool_create() at
611 * pool creation. It can be extended by the user, for example, to
612 * provide another packet size.
615 * The mempool from which mbufs originate.
617 * A pointer that can be used by the user to retrieve useful information
618 * for mbuf initialization. This pointer is the opaque argument passed to
619 * rte_mempool_create().
621 void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg);
624 * Create a mbuf pool.
626 * This function creates and initializes a packet mbuf pool. It is
627 * a wrapper to rte_mempool functions.
630 * The name of the mbuf pool.
632 * The number of elements in the mbuf pool. The optimum size (in terms
633 * of memory usage) for a mempool is when n is a power of two minus one:
636 * Size of the per-core object cache. See rte_mempool_create() for
639 * Size of application private are between the rte_mbuf structure
640 * and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
641 * @param data_room_size
642 * Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
644 * The socket identifier where the memory should be allocated. The
645 * value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
648 * The pointer to the new allocated mempool, on success. NULL on error
649 * with rte_errno set appropriately. Possible rte_errno values include:
650 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
651 * - E_RTE_SECONDARY - function was called from a secondary process instance
652 * - EINVAL - cache size provided is too large, or priv_size is not aligned.
653 * - ENOSPC - the maximum number of memzones has already been allocated
654 * - EEXIST - a memzone with the same name already exists
655 * - ENOMEM - no appropriate memory area found in which to create memzone
658 rte_pktmbuf_pool_create(const char *name, unsigned n,
659 unsigned cache_size, uint16_t priv_size, uint16_t data_room_size,
663 * Create a mbuf pool with a given mempool ops name
665 * This function creates and initializes a packet mbuf pool. It is
666 * a wrapper to rte_mempool functions.
669 * The name of the mbuf pool.
671 * The number of elements in the mbuf pool. The optimum size (in terms
672 * of memory usage) for a mempool is when n is a power of two minus one:
675 * Size of the per-core object cache. See rte_mempool_create() for
678 * Size of application private are between the rte_mbuf structure
679 * and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN.
680 * @param data_room_size
681 * Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM.
683 * The socket identifier where the memory should be allocated. The
684 * value can be *SOCKET_ID_ANY* if there is no NUMA constraint for the
687 * The mempool ops name to be used for this mempool instead of
688 * default mempool. The value can be *NULL* to use default mempool.
690 * The pointer to the new allocated mempool, on success. NULL on error
691 * with rte_errno set appropriately. Possible rte_errno values include:
692 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
693 * - E_RTE_SECONDARY - function was called from a secondary process instance
694 * - EINVAL - cache size provided is too large, or priv_size is not aligned.
695 * - ENOSPC - the maximum number of memzones has already been allocated
696 * - EEXIST - a memzone with the same name already exists
697 * - ENOMEM - no appropriate memory area found in which to create memzone
700 rte_pktmbuf_pool_create_by_ops(const char *name, unsigned int n,
701 unsigned int cache_size, uint16_t priv_size, uint16_t data_room_size,
702 int socket_id, const char *ops_name);
705 * Get the data room size of mbufs stored in a pktmbuf_pool
707 * The data room size is the amount of data that can be stored in a
708 * mbuf including the headroom (RTE_PKTMBUF_HEADROOM).
711 * The packet mbuf pool.
713 * The data room size of mbufs stored in this mempool.
715 static inline uint16_t
716 rte_pktmbuf_data_room_size(struct rte_mempool *mp)
718 struct rte_pktmbuf_pool_private *mbp_priv;
720 mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
721 return mbp_priv->mbuf_data_room_size;
725 * Get the application private size of mbufs stored in a pktmbuf_pool
727 * The private size of mbuf is a zone located between the rte_mbuf
728 * structure and the data buffer where an application can store data
729 * associated to a packet.
732 * The packet mbuf pool.
734 * The private size of mbufs stored in this mempool.
736 static inline uint16_t
737 rte_pktmbuf_priv_size(struct rte_mempool *mp)
739 struct rte_pktmbuf_pool_private *mbp_priv;
741 mbp_priv = (struct rte_pktmbuf_pool_private *)rte_mempool_get_priv(mp);
742 return mbp_priv->mbuf_priv_size;
746 * Reset the data_off field of a packet mbuf to its default value.
748 * The given mbuf must have only one segment, which should be empty.
751 * The packet mbuf's data_off field has to be reset.
753 static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
755 m->data_off = (uint16_t)RTE_MIN((uint16_t)RTE_PKTMBUF_HEADROOM,
756 (uint16_t)m->buf_len);
760 * Reset the fields of a packet mbuf to their default values.
762 * The given mbuf must have only one segment.
765 * The packet mbuf to be reset.
767 #define MBUF_INVALID_PORT UINT16_MAX
769 static inline void rte_pktmbuf_reset(struct rte_mbuf *m)
775 m->vlan_tci_outer = 0;
777 m->port = MBUF_INVALID_PORT;
781 rte_pktmbuf_reset_headroom(m);
784 __rte_mbuf_sanity_check(m, 1);
788 * Allocate a new mbuf from a mempool.
790 * This new mbuf contains one segment, which has a length of 0. The pointer
791 * to data is initialized to have some bytes of headroom in the buffer
792 * (if buffer size allows).
795 * The mempool from which the mbuf is allocated.
797 * - The pointer to the new mbuf on success.
798 * - NULL if allocation failed.
800 static inline struct rte_mbuf *rte_pktmbuf_alloc(struct rte_mempool *mp)
803 if ((m = rte_mbuf_raw_alloc(mp)) != NULL)
804 rte_pktmbuf_reset(m);
809 * Allocate a bulk of mbufs, initialize refcnt and reset the fields to default
813 * The mempool from which mbufs are allocated.
815 * Array of pointers to mbufs
820 * - -ENOENT: Not enough entries in the mempool; no mbufs are retrieved.
822 static inline int rte_pktmbuf_alloc_bulk(struct rte_mempool *pool,
823 struct rte_mbuf **mbufs, unsigned count)
828 rc = rte_mempool_get_bulk(pool, (void **)mbufs, count);
832 /* To understand duff's device on loop unwinding optimization, see
833 * https://en.wikipedia.org/wiki/Duff's_device.
834 * Here while() loop is used rather than do() while{} to avoid extra
835 * check if count is zero.
839 while (idx != count) {
840 MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
841 rte_pktmbuf_reset(mbufs[idx]);
845 MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
846 rte_pktmbuf_reset(mbufs[idx]);
850 MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
851 rte_pktmbuf_reset(mbufs[idx]);
855 MBUF_RAW_ALLOC_CHECK(mbufs[idx]);
856 rte_pktmbuf_reset(mbufs[idx]);
865 * Initialize shared data at the end of an external buffer before attaching
866 * to a mbuf by ``rte_pktmbuf_attach_extbuf()``. This is not a mandatory
867 * initialization but a helper function to simply spare a few bytes at the
868 * end of the buffer for shared data. If shared data is allocated
869 * separately, this should not be called but application has to properly
870 * initialize the shared data according to its need.
872 * Free callback and its argument is saved and the refcnt is set to 1.
875 * The value of buf_len will be reduced to RTE_PTR_DIFF(shinfo, buf_addr)
876 * after this initialization. This shall be used for
877 * ``rte_pktmbuf_attach_extbuf()``
880 * The pointer to the external buffer.
881 * @param [in,out] buf_len
882 * The pointer to length of the external buffer. Input value must be
883 * larger than the size of ``struct rte_mbuf_ext_shared_info`` and
884 * padding for alignment. If not enough, this function will return NULL.
885 * Adjusted buffer length will be returned through this pointer.
887 * Free callback function to call when the external buffer needs to be
890 * Argument for the free callback function.
893 * A pointer to the initialized shared data on success, return NULL
896 static inline struct rte_mbuf_ext_shared_info *
897 rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
898 rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)
900 struct rte_mbuf_ext_shared_info *shinfo;
901 void *buf_end = RTE_PTR_ADD(buf_addr, *buf_len);
904 addr = RTE_PTR_ALIGN_FLOOR(RTE_PTR_SUB(buf_end, sizeof(*shinfo)),
906 if (addr <= buf_addr)
909 shinfo = (struct rte_mbuf_ext_shared_info *)addr;
910 shinfo->free_cb = free_cb;
911 shinfo->fcb_opaque = fcb_opaque;
912 rte_mbuf_ext_refcnt_set(shinfo, 1);
914 *buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
919 * Attach an external buffer to a mbuf.
921 * User-managed anonymous buffer can be attached to an mbuf. When attaching
922 * it, corresponding free callback function and its argument should be
923 * provided via shinfo. This callback function will be called once all the
924 * mbufs are detached from the buffer (refcnt becomes zero).
926 * The headroom for the attaching mbuf will be set to zero and this can be
927 * properly adjusted after attachment. For example, ``rte_pktmbuf_adj()``
928 * or ``rte_pktmbuf_reset_headroom()`` might be used.
930 * More mbufs can be attached to the same external buffer by
931 * ``rte_pktmbuf_attach()`` once the external buffer has been attached by
934 * Detachment can be done by either ``rte_pktmbuf_detach_extbuf()`` or
935 * ``rte_pktmbuf_detach()``.
937 * Memory for shared data must be provided and user must initialize all of
938 * the content properly, especially free callback and refcnt. The pointer
939 * of shared data will be stored in m->shinfo.
940 * ``rte_pktmbuf_ext_shinfo_init_helper`` can help to simply spare a few
941 * bytes at the end of buffer for the shared data, store free callback and
942 * its argument and set the refcnt to 1. The following is an example:
944 * struct rte_mbuf_ext_shared_info *shinfo =
945 * rte_pktmbuf_ext_shinfo_init_helper(buf_addr, &buf_len,
947 * rte_pktmbuf_attach_extbuf(m, buf_addr, buf_iova, buf_len, shinfo);
948 * rte_pktmbuf_reset_headroom(m);
949 * rte_pktmbuf_adj(m, data_len);
951 * Attaching an external buffer is quite similar to mbuf indirection in
952 * replacing buffer addresses and length of a mbuf, but a few differences:
953 * - When an indirect mbuf is attached, refcnt of the direct mbuf would be
954 * 2 as long as the direct mbuf itself isn't freed after the attachment.
955 * In such cases, the buffer area of a direct mbuf must be read-only. But
956 * external buffer has its own refcnt and it starts from 1. Unless
957 * multiple mbufs are attached to a mbuf having an external buffer, the
958 * external buffer is writable.
959 * - There's no need to allocate buffer from a mempool. Any buffer can be
960 * attached with appropriate free callback and its IO address.
961 * - Smaller metadata is required to maintain shared data such as refcnt.
964 * The pointer to the mbuf.
966 * The pointer to the external buffer.
968 * IO address of the external buffer.
970 * The size of the external buffer.
972 * User-provided memory for shared data of the external buffer.
975 rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
976 rte_iova_t buf_iova, uint16_t buf_len,
977 struct rte_mbuf_ext_shared_info *shinfo)
979 /* mbuf should not be read-only */
980 RTE_ASSERT(RTE_MBUF_DIRECT(m) && rte_mbuf_refcnt_read(m) == 1);
981 RTE_ASSERT(shinfo->free_cb != NULL);
983 m->buf_addr = buf_addr;
984 m->buf_iova = buf_iova;
985 m->buf_len = buf_len;
990 m->ol_flags |= EXT_ATTACHED_MBUF;
995 * Detach the external buffer attached to a mbuf, same as
996 * ``rte_pktmbuf_detach()``
999 * The mbuf having external buffer.
1001 #define rte_pktmbuf_detach_extbuf(m) rte_pktmbuf_detach(m)
1004 * Copy dynamic fields from msrc to mdst.
1007 * The destination mbuf.
1012 rte_mbuf_dynfield_copy(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1014 memcpy(&mdst->dynfield1, msrc->dynfield1, sizeof(mdst->dynfield1));
1019 __rte_pktmbuf_copy_hdr(struct rte_mbuf *mdst, const struct rte_mbuf *msrc)
1021 mdst->port = msrc->port;
1022 mdst->vlan_tci = msrc->vlan_tci;
1023 mdst->vlan_tci_outer = msrc->vlan_tci_outer;
1024 mdst->tx_offload = msrc->tx_offload;
1025 mdst->hash = msrc->hash;
1026 mdst->packet_type = msrc->packet_type;
1027 mdst->timestamp = msrc->timestamp;
1028 rte_mbuf_dynfield_copy(mdst, msrc);
1032 * Attach packet mbuf to another packet mbuf.
1034 * If the mbuf we are attaching to isn't a direct buffer and is attached to
1035 * an external buffer, the mbuf being attached will be attached to the
1036 * external buffer instead of mbuf indirection.
1038 * Otherwise, the mbuf will be indirectly attached. After attachment we
1039 * refer the mbuf we attached as 'indirect', while mbuf we attached to as
1040 * 'direct'. The direct mbuf's reference counter is incremented.
1042 * Right now, not supported:
1043 * - attachment for already indirect mbuf (e.g. - mi has to be direct).
1044 * - mbuf we trying to attach (mi) is used by someone else
1045 * e.g. it's reference counter is greater then 1.
1048 * The indirect packet mbuf.
1050 * The packet mbuf we're attaching to.
1052 static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m)
1054 RTE_ASSERT(RTE_MBUF_DIRECT(mi) &&
1055 rte_mbuf_refcnt_read(mi) == 1);
1057 if (RTE_MBUF_HAS_EXTBUF(m)) {
1058 rte_mbuf_ext_refcnt_update(m->shinfo, 1);
1059 mi->ol_flags = m->ol_flags;
1060 mi->shinfo = m->shinfo;
1062 /* if m is not direct, get the mbuf that embeds the data */
1063 rte_mbuf_refcnt_update(rte_mbuf_from_indirect(m), 1);
1064 mi->priv_size = m->priv_size;
1065 mi->ol_flags = m->ol_flags | IND_ATTACHED_MBUF;
1068 __rte_pktmbuf_copy_hdr(mi, m);
1070 mi->data_off = m->data_off;
1071 mi->data_len = m->data_len;
1072 mi->buf_iova = m->buf_iova;
1073 mi->buf_addr = m->buf_addr;
1074 mi->buf_len = m->buf_len;
1077 mi->pkt_len = mi->data_len;
1080 __rte_mbuf_sanity_check(mi, 1);
1081 __rte_mbuf_sanity_check(m, 0);
1085 * @internal used by rte_pktmbuf_detach().
1087 * Decrement the reference counter of the external buffer. When the
1088 * reference counter becomes 0, the buffer is freed by pre-registered
1092 __rte_pktmbuf_free_extbuf(struct rte_mbuf *m)
1094 RTE_ASSERT(RTE_MBUF_HAS_EXTBUF(m));
1095 RTE_ASSERT(m->shinfo != NULL);
1097 if (rte_mbuf_ext_refcnt_update(m->shinfo, -1) == 0)
1098 m->shinfo->free_cb(m->buf_addr, m->shinfo->fcb_opaque);
1102 * @internal used by rte_pktmbuf_detach().
1104 * Decrement the direct mbuf's reference counter. When the reference
1105 * counter becomes 0, the direct mbuf is freed.
1108 __rte_pktmbuf_free_direct(struct rte_mbuf *m)
1110 struct rte_mbuf *md;
1112 RTE_ASSERT(RTE_MBUF_CLONED(m));
1114 md = rte_mbuf_from_indirect(m);
1116 if (rte_mbuf_refcnt_update(md, -1) == 0) {
1119 rte_mbuf_refcnt_set(md, 1);
1120 rte_mbuf_raw_free(md);
1125 * Detach a packet mbuf from external buffer or direct buffer.
1127 * - decrement refcnt and free the external/direct buffer if refcnt
1129 * - restore original mbuf address and length values.
1130 * - reset pktmbuf data and data_len to their default values.
1132 * All other fields of the given packet mbuf will be left intact.
1135 * The indirect attached packet mbuf.
1137 static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
1139 struct rte_mempool *mp = m->pool;
1140 uint32_t mbuf_size, buf_len;
1143 if (RTE_MBUF_HAS_EXTBUF(m))
1144 __rte_pktmbuf_free_extbuf(m);
1146 __rte_pktmbuf_free_direct(m);
1148 priv_size = rte_pktmbuf_priv_size(mp);
1149 mbuf_size = (uint32_t)(sizeof(struct rte_mbuf) + priv_size);
1150 buf_len = rte_pktmbuf_data_room_size(mp);
1152 m->priv_size = priv_size;
1153 m->buf_addr = (char *)m + mbuf_size;
1154 m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size;
1155 m->buf_len = (uint16_t)buf_len;
1156 rte_pktmbuf_reset_headroom(m);
1162 * Decrease reference counter and unlink a mbuf segment
1164 * This function does the same than a free, except that it does not
1165 * return the segment to its pool.
1166 * It decreases the reference counter, and if it reaches 0, it is
1167 * detached from its parent for an indirect mbuf.
1170 * The mbuf to be unlinked
1172 * - (m) if it is the last reference. It can be recycled or freed.
1173 * - (NULL) if the mbuf still has remaining references on it.
1175 static __rte_always_inline struct rte_mbuf *
1176 rte_pktmbuf_prefree_seg(struct rte_mbuf *m)
1178 __rte_mbuf_sanity_check(m, 0);
1180 if (likely(rte_mbuf_refcnt_read(m) == 1)) {
1182 if (!RTE_MBUF_DIRECT(m))
1183 rte_pktmbuf_detach(m);
1185 if (m->next != NULL) {
1192 } else if (__rte_mbuf_refcnt_update(m, -1) == 0) {
1194 if (!RTE_MBUF_DIRECT(m))
1195 rte_pktmbuf_detach(m);
1197 if (m->next != NULL) {
1201 rte_mbuf_refcnt_set(m, 1);
1209 * Free a segment of a packet mbuf into its original mempool.
1211 * Free an mbuf, without parsing other segments in case of chained
1215 * The packet mbuf segment to be freed.
1217 static __rte_always_inline void
1218 rte_pktmbuf_free_seg(struct rte_mbuf *m)
1220 m = rte_pktmbuf_prefree_seg(m);
1221 if (likely(m != NULL))
1222 rte_mbuf_raw_free(m);
1226 * Free a packet mbuf back into its original mempool.
1228 * Free an mbuf, and all its segments in case of chained buffers. Each
1229 * segment is added back into its original mempool.
1232 * The packet mbuf to be freed. If NULL, the function does nothing.
1234 static inline void rte_pktmbuf_free(struct rte_mbuf *m)
1236 struct rte_mbuf *m_next;
1239 __rte_mbuf_sanity_check(m, 1);
1243 rte_pktmbuf_free_seg(m);
1249 * Free a bulk of packet mbufs back into their original mempools.
1251 * Free a bulk of mbufs, and all their segments in case of chained buffers.
1252 * Each segment is added back into its original mempool.
1255 * Array of pointers to packet mbufs.
1256 * The array may contain NULL pointers.
1261 void rte_pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int count);
1264 * Create a "clone" of the given packet mbuf.
1266 * Walks through all segments of the given packet mbuf, and for each of them:
1267 * - Creates a new packet mbuf from the given pool.
1268 * - Attaches newly created mbuf to the segment.
1269 * Then updates pkt_len and nb_segs of the "clone" packet mbuf to match values
1270 * from the original packet mbuf.
1273 * The packet mbuf to be cloned.
1275 * The mempool from which the "clone" mbufs are allocated.
1277 * - The pointer to the new "clone" mbuf on success.
1278 * - NULL if allocation fails.
1281 rte_pktmbuf_clone(struct rte_mbuf *md, struct rte_mempool *mp);
1284 * Create a full copy of a given packet mbuf.
1286 * Copies all the data from a given packet mbuf to a newly allocated
1287 * set of mbufs. The private data are is not copied.
1290 * The packet mbuf to be copiedd.
1292 * The mempool from which the "clone" mbufs are allocated.
1294 * The number of bytes to skip before copying.
1295 * If the mbuf does not have that many bytes, it is an error
1296 * and NULL is returned.
1298 * The upper limit on bytes to copy. Passing UINT32_MAX
1299 * means all data (after offset).
1301 * - The pointer to the new "clone" mbuf on success.
1302 * - NULL if allocation fails.
1306 rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp,
1307 uint32_t offset, uint32_t length);
1310 * Adds given value to the refcnt of all packet mbuf segments.
1312 * Walks through all segments of given packet mbuf and for each of them
1313 * invokes rte_mbuf_refcnt_update().
1316 * The packet mbuf whose refcnt to be updated.
1318 * The value to add to the mbuf's segments refcnt.
1320 static inline void rte_pktmbuf_refcnt_update(struct rte_mbuf *m, int16_t v)
1322 __rte_mbuf_sanity_check(m, 1);
1325 rte_mbuf_refcnt_update(m, v);
1326 } while ((m = m->next) != NULL);
1330 * Get the headroom in a packet mbuf.
1335 * The length of the headroom.
1337 static inline uint16_t rte_pktmbuf_headroom(const struct rte_mbuf *m)
1339 __rte_mbuf_sanity_check(m, 0);
1344 * Get the tailroom of a packet mbuf.
1349 * The length of the tailroom.
1351 static inline uint16_t rte_pktmbuf_tailroom(const struct rte_mbuf *m)
1353 __rte_mbuf_sanity_check(m, 0);
1354 return (uint16_t)(m->buf_len - rte_pktmbuf_headroom(m) -
1359 * Get the last segment of the packet.
1364 * The last segment of the given mbuf.
1366 static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m)
1368 __rte_mbuf_sanity_check(m, 1);
1369 while (m->next != NULL)
1375 #define rte_pktmbuf_mtophys_offset(m, o) \
1376 rte_pktmbuf_iova_offset(m, o)
1379 #define rte_pktmbuf_mtophys(m) rte_pktmbuf_iova(m)
1382 * A macro that returns the length of the packet.
1384 * The value can be read or assigned.
1389 #define rte_pktmbuf_pkt_len(m) ((m)->pkt_len)
1392 * A macro that returns the length of the segment.
1394 * The value can be read or assigned.
1399 #define rte_pktmbuf_data_len(m) ((m)->data_len)
1402 * Prepend len bytes to an mbuf data area.
1404 * Returns a pointer to the new
1405 * data start address. If there is not enough headroom in the first
1406 * segment, the function will return NULL, without modifying the mbuf.
1411 * The amount of data to prepend (in bytes).
1413 * A pointer to the start of the newly prepended data, or
1414 * NULL if there is not enough headroom space in the first segment
1416 static inline char *rte_pktmbuf_prepend(struct rte_mbuf *m,
1419 __rte_mbuf_sanity_check(m, 1);
1421 if (unlikely(len > rte_pktmbuf_headroom(m)))
1424 /* NB: elaborating the subtraction like this instead of using
1425 * -= allows us to ensure the result type is uint16_t
1426 * avoiding compiler warnings on gcc 8.1 at least */
1427 m->data_off = (uint16_t)(m->data_off - len);
1428 m->data_len = (uint16_t)(m->data_len + len);
1429 m->pkt_len = (m->pkt_len + len);
1431 return (char *)m->buf_addr + m->data_off;
1435 * Append len bytes to an mbuf.
1437 * Append len bytes to an mbuf and return a pointer to the start address
1438 * of the added data. If there is not enough tailroom in the last
1439 * segment, the function will return NULL, without modifying the mbuf.
1444 * The amount of data to append (in bytes).
1446 * A pointer to the start of the newly appended data, or
1447 * NULL if there is not enough tailroom space in the last segment
1449 static inline char *rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
1452 struct rte_mbuf *m_last;
1454 __rte_mbuf_sanity_check(m, 1);
1456 m_last = rte_pktmbuf_lastseg(m);
1457 if (unlikely(len > rte_pktmbuf_tailroom(m_last)))
1460 tail = (char *)m_last->buf_addr + m_last->data_off + m_last->data_len;
1461 m_last->data_len = (uint16_t)(m_last->data_len + len);
1462 m->pkt_len = (m->pkt_len + len);
1463 return (char*) tail;
1467 * Remove len bytes at the beginning of an mbuf.
1469 * Returns a pointer to the start address of the new data area. If the
1470 * length is greater than the length of the first segment, then the
1471 * function will fail and return NULL, without modifying the mbuf.
1476 * The amount of data to remove (in bytes).
1478 * A pointer to the new start of the data.
1480 static inline char *rte_pktmbuf_adj(struct rte_mbuf *m, uint16_t len)
1482 __rte_mbuf_sanity_check(m, 1);
1484 if (unlikely(len > m->data_len))
1487 /* NB: elaborating the addition like this instead of using
1488 * += allows us to ensure the result type is uint16_t
1489 * avoiding compiler warnings on gcc 8.1 at least */
1490 m->data_len = (uint16_t)(m->data_len - len);
1491 m->data_off = (uint16_t)(m->data_off + len);
1492 m->pkt_len = (m->pkt_len - len);
1493 return (char *)m->buf_addr + m->data_off;
1497 * Remove len bytes of data at the end of the mbuf.
1499 * If the length is greater than the length of the last segment, the
1500 * function will fail and return -1 without modifying the mbuf.
1505 * The amount of data to remove (in bytes).
1510 static inline int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
1512 struct rte_mbuf *m_last;
1514 __rte_mbuf_sanity_check(m, 1);
1516 m_last = rte_pktmbuf_lastseg(m);
1517 if (unlikely(len > m_last->data_len))
1520 m_last->data_len = (uint16_t)(m_last->data_len - len);
1521 m->pkt_len = (m->pkt_len - len);
1526 * Test if mbuf data is contiguous.
1531 * - 1, if all data is contiguous (one segment).
1532 * - 0, if there is several segments.
1534 static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
1536 __rte_mbuf_sanity_check(m, 1);
1537 return !!(m->nb_segs == 1);
1541 * @internal used by rte_pktmbuf_read().
1543 const void *__rte_pktmbuf_read(const struct rte_mbuf *m, uint32_t off,
1544 uint32_t len, void *buf);
1547 * Read len data bytes in a mbuf at specified offset.
1549 * If the data is contiguous, return the pointer in the mbuf data, else
1550 * copy the data in the buffer provided by the user and return its
1554 * The pointer to the mbuf.
1556 * The offset of the data in the mbuf.
1558 * The amount of bytes to read.
1560 * The buffer where data is copied if it is not contiguous in mbuf
1561 * data. Its length should be at least equal to the len parameter.
1563 * The pointer to the data, either in the mbuf if it is contiguous,
1564 * or in the user buffer. If mbuf is too small, NULL is returned.
1566 static inline const void *rte_pktmbuf_read(const struct rte_mbuf *m,
1567 uint32_t off, uint32_t len, void *buf)
1569 if (likely(off + len <= rte_pktmbuf_data_len(m)))
1570 return rte_pktmbuf_mtod_offset(m, char *, off);
1572 return __rte_pktmbuf_read(m, off, len, buf);
1576 * Chain an mbuf to another, thereby creating a segmented packet.
1578 * Note: The implementation will do a linear walk over the segments to find
1579 * the tail entry. For cases when there are many segments, it's better to
1580 * chain the entries manually.
1583 * The head of the mbuf chain (the first packet)
1585 * The mbuf to put last in the chain
1589 * - -EOVERFLOW, if the chain segment limit exceeded
1591 static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
1593 struct rte_mbuf *cur_tail;
1595 /* Check for number-of-segments-overflow */
1596 if (head->nb_segs + tail->nb_segs > RTE_MBUF_MAX_NB_SEGS)
1599 /* Chain 'tail' onto the old tail */
1600 cur_tail = rte_pktmbuf_lastseg(head);
1601 cur_tail->next = tail;
1603 /* accumulate number of segments and total length.
1604 * NB: elaborating the addition like this instead of using
1605 * -= allows us to ensure the result type is uint16_t
1606 * avoiding compiler warnings on gcc 8.1 at least */
1607 head->nb_segs = (uint16_t)(head->nb_segs + tail->nb_segs);
1608 head->pkt_len += tail->pkt_len;
1610 /* pkt_len is only set in the head */
1611 tail->pkt_len = tail->data_len;
1618 * @b EXPERIMENTAL: This API may change without prior notice.
1620 * For given input values generate raw tx_offload value.
1621 * Note that it is caller responsibility to make sure that input parameters
1622 * don't exceed maximum bit-field values.
1632 * outer_l3_len value.
1634 * outer_l2_len value.
1638 * raw tx_offload value.
1640 static __rte_always_inline uint64_t
1641 rte_mbuf_tx_offload(uint64_t il2, uint64_t il3, uint64_t il4, uint64_t tso,
1642 uint64_t ol3, uint64_t ol2, uint64_t unused)
1644 return il2 << RTE_MBUF_L2_LEN_OFS |
1645 il3 << RTE_MBUF_L3_LEN_OFS |
1646 il4 << RTE_MBUF_L4_LEN_OFS |
1647 tso << RTE_MBUF_TSO_SEGSZ_OFS |
1648 ol3 << RTE_MBUF_OUTL3_LEN_OFS |
1649 ol2 << RTE_MBUF_OUTL2_LEN_OFS |
1650 unused << RTE_MBUF_TXOFLD_UNUSED_OFS;
1654 * Validate general requirements for Tx offload in mbuf.
1656 * This function checks correctness and completeness of Tx offload settings.
1659 * The packet mbuf to be validated.
1661 * 0 if packet is valid
1664 rte_validate_tx_offload(const struct rte_mbuf *m)
1666 uint64_t ol_flags = m->ol_flags;
1668 /* Does packet set any of available offloads? */
1669 if (!(ol_flags & PKT_TX_OFFLOAD_MASK))
1672 /* IP checksum can be counted only for IPv4 packet */
1673 if ((ol_flags & PKT_TX_IP_CKSUM) && (ol_flags & PKT_TX_IPV6))
1676 /* IP type not set when required */
1677 if (ol_flags & (PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
1678 if (!(ol_flags & (PKT_TX_IPV4 | PKT_TX_IPV6)))
1681 /* Check requirements for TSO packet */
1682 if (ol_flags & PKT_TX_TCP_SEG)
1683 if ((m->tso_segsz == 0) ||
1684 ((ol_flags & PKT_TX_IPV4) &&
1685 !(ol_flags & PKT_TX_IP_CKSUM)))
1688 /* PKT_TX_OUTER_IP_CKSUM set for non outer IPv4 packet. */
1689 if ((ol_flags & PKT_TX_OUTER_IP_CKSUM) &&
1690 !(ol_flags & PKT_TX_OUTER_IPV4))
1697 * @internal used by rte_pktmbuf_linearize().
1699 int __rte_pktmbuf_linearize(struct rte_mbuf *mbuf);
1702 * Linearize data in mbuf.
1704 * This function moves the mbuf data in the first segment if there is enough
1705 * tailroom. The subsequent segments are unchained and freed.
1714 rte_pktmbuf_linearize(struct rte_mbuf *mbuf)
1716 if (rte_pktmbuf_is_contiguous(mbuf))
1718 return __rte_pktmbuf_linearize(mbuf);
1722 * Dump an mbuf structure to a file.
1724 * Dump all fields for the given packet mbuf and all its associated
1725 * segments (in the case of a chained buffer).
1728 * A pointer to a file for output
1732 * If dump_len != 0, also dump the "dump_len" first data bytes of
1735 void rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len);
1738 * Get the value of mbuf sched queue_id field.
1740 static inline uint32_t
1741 rte_mbuf_sched_queue_get(const struct rte_mbuf *m)
1743 return m->hash.sched.queue_id;
1747 * Get the value of mbuf sched traffic_class field.
1749 static inline uint8_t
1750 rte_mbuf_sched_traffic_class_get(const struct rte_mbuf *m)
1752 return m->hash.sched.traffic_class;
1756 * Get the value of mbuf sched color field.
1758 static inline uint8_t
1759 rte_mbuf_sched_color_get(const struct rte_mbuf *m)
1761 return m->hash.sched.color;
1765 * Get the values of mbuf sched queue_id, traffic_class and color.
1770 * Returns the queue id
1771 * @param traffic_class
1772 * Returns the traffic class id
1774 * Returns the colour id
1777 rte_mbuf_sched_get(const struct rte_mbuf *m, uint32_t *queue_id,
1778 uint8_t *traffic_class,
1781 struct rte_mbuf_sched sched = m->hash.sched;
1783 *queue_id = sched.queue_id;
1784 *traffic_class = sched.traffic_class;
1785 *color = sched.color;
1789 * Set the mbuf sched queue_id to the defined value.
1792 rte_mbuf_sched_queue_set(struct rte_mbuf *m, uint32_t queue_id)
1794 m->hash.sched.queue_id = queue_id;
1798 * Set the mbuf sched traffic_class id to the defined value.
1801 rte_mbuf_sched_traffic_class_set(struct rte_mbuf *m, uint8_t traffic_class)
1803 m->hash.sched.traffic_class = traffic_class;
1807 * Set the mbuf sched color id to the defined value.
1810 rte_mbuf_sched_color_set(struct rte_mbuf *m, uint8_t color)
1812 m->hash.sched.color = color;
1816 * Set the mbuf sched queue_id, traffic_class and color.
1821 * Queue id value to be set
1822 * @param traffic_class
1823 * Traffic class id value to be set
1825 * Color id to be set
1828 rte_mbuf_sched_set(struct rte_mbuf *m, uint32_t queue_id,
1829 uint8_t traffic_class,
1832 m->hash.sched = (struct rte_mbuf_sched){
1833 .queue_id = queue_id,
1834 .traffic_class = traffic_class,
1844 #endif /* _RTE_MBUF_H_ */