src/dpdk/lib/librte_mbuf/rte_mbuf.h
static inline void
rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
	rte_iova_t buf_iova, uint16_t buf_len,
	struct rte_mbuf_ext_shared_info *shinfo)
{
	/* mbuf should not be read-only */
	RTE_ASSERT(RTE_MBUF_DIRECT(m) && rte_mbuf_refcnt_read(m) == 1);
	RTE_ASSERT(shinfo->free_cb != NULL);

	m->buf_addr = buf_addr;
	m->buf_iova = buf_iova;
	m->buf_len = buf_len;

	m->data_len = 0;
	m->data_off = 0;

	m->ol_flags |= EXT_ATTACHED_MBUF;
	m->shinfo = shinfo;
}
/**
 * Attach an external buffer to a mbuf.
 *
 * User-managed anonymous buffer can be attached to an mbuf. When attaching
 * it, corresponding free callback function and its argument should be
 * provided via shinfo. This callback function will be called once all the
 * mbufs are detached from the buffer (refcnt becomes zero).
 *
 * The headroom length of the attaching mbuf will be set to zero and this
 * can be properly adjusted after attachment. For example, ``rte_pktmbuf_adj()``
 * or ``rte_pktmbuf_reset_headroom()`` might be used.
 *
 * Similarly, the packet length is initialized to 0. If the buffer contains
 * data, the user has to adjust ``data_len`` and the ``pkt_len`` field of
 * the mbuf accordingly.
 *
 * More mbufs can be attached to the same external buffer by
 * ``rte_pktmbuf_attach()`` once the external buffer has been attached by
 * this API.
 *
 * Detachment can be done by either ``rte_pktmbuf_detach_extbuf()`` or
 * ``rte_pktmbuf_detach()``.
 *
 * Memory for shared data must be provided and user must initialize all of
 * the content properly, especially free callback and refcnt. The pointer
 * of shared data will be stored in m->shinfo.
 * ``rte_pktmbuf_ext_shinfo_init_helper`` can help to simply spare a few
 * bytes at the end of buffer for the shared data, store free callback and
 * its argument and set the refcnt to 1. The following is an example:
 *
 *   struct rte_mbuf_ext_shared_info *shinfo =
 *          rte_pktmbuf_ext_shinfo_init_helper(buf_addr, &buf_len,
 *                                             free_cb, fcb_arg);
 *   rte_pktmbuf_attach_extbuf(m, buf_addr, buf_iova, buf_len, shinfo);
 *   rte_pktmbuf_reset_headroom(m);
 *   rte_pktmbuf_adj(m, data_len);
 *
 * Attaching an external buffer is quite similar to mbuf indirection in
 * replacing buffer addresses and length of a mbuf, but a few differences:
 * - When an indirect mbuf is attached, refcnt of the direct mbuf would be
 *   2 as long as the direct mbuf itself isn't freed after the attachment.
 *   In such cases, the buffer area of a direct mbuf must be read-only. But
 *   external buffer has its own refcnt and it starts from 1. Unless
 *   multiple mbufs are attached to a mbuf having an external buffer, the
 *   external buffer is writable.
 * - There's no need to allocate buffer from a mempool. Any buffer can be
 *   attached with appropriate free callback and its IO address.
 * - Smaller metadata is required to maintain shared data such as refcnt.
 *
 * @param m
 *   The pointer to the mbuf.
 * @param buf_addr
 *   The pointer to the external buffer.
 * @param buf_iova
 *   IO address of the external buffer.
 * @param buf_len
 *   The size of the external buffer.
 * @param shinfo
 *   User-provided memory for shared data of the external buffer.
 */
Attach an external buffer to a mbuf.
User-managed anonymous buffer can be attached to an mbuf. When attaching
it, corresponding free callback function and its argument should be
provided via shinfo. This callback function will be called once all the
mbufs are detached from the buffer (refcnt becomes zero).

The headroom length of the attaching mbuf will be set to zero and this
can be properly adjusted after attachment.

Similarly, the packet length is initialized to 0.

More mbufs can be attached to the same external buffer by
``rte_pktmbuf_attach()`` once the external buffer has been attached by
this API.



Memory for shared data must be provided and user must initialize all of
the content properly, especially free callback and refcnt. The pointer
of shared data will be stored in m->shinfo.
``rte_pktmbuf_ext_shinfo_init_helper`` can help to simply spare a few
bytes at the end of buffer for the shared data, store free callback and
its argument and set the refcnt to 1. The following is an example.



Attaching an external buffer is quite similar to mbuf indirection in
replacing buffer addresses and length of a mbuf, but a few differences:
- When an indirect mbuf is attached, refcnt of the direct mbuf would be
2 as long as the direct mbuf itself isn't freed after the attachment.
In such cases, the buffer area of a direct mbuf must be read-only. But
external buffer has its own refcnt and it starts from 1. Unless
multiple mbufs are attached to a mbuf having an external buffer, the
external buffer is writable.
- There's no need to allocate buffer from a mempool. Any buffer can be
attached with appropriate free callback and its IO address.
- Smaller metadata is required to maintain shared data such as refcnt.

@param m
The pointer to the mbuf.
@param buf_addr
The pointer to the external buffer.
@param buf_iova
IO address of the external buffer.
@param buf_len
The size of the external buffer.
@param shinfo
User-provided memory for shared data of the external buffer.
Attach an external buffer to a mbuf . User - managed anonymous buffer can be attached to an mbuf . When attaching it corresponding free callback function and its argument should be provided via shinfo . This callback function will be called once all the mbufs are detached from the buffer ( refcnt becomes zero ) . The headroom length of the attaching mbuf will be set to zero and this can be properly adjusted after attachment . Similarly the packet length is initialized to 0 . More mbufs can be attached to the same external buffer by ` ` rte_pktmbuf_attach () ` ` once the external buffer has been attached by this API . Memory for shared data must be provided and user must initialize all of the content properly especially free callback and refcnt . The pointer of shared data will be stored in m - > shinfo . ` ` rte_pktmbuf_ext_shinfo_init_helper ` ` can help to simply spare a few bytes at the end of buffer for the shared data store free callback and its argument and set the refcnt to 1 . The following is an example . Attaching an external buffer is quite similar to mbuf indirection in replacing buffer addresses and length of a mbuf but a few differences : - When an indirect mbuf is attached refcnt of the direct mbuf would be 2 as long as the direct mbuf itself isn ' t freed after the attachment . In such cases the buffer area of a direct mbuf must be read - only . But external buffer has its own refcnt and it starts from 1 . Unless multiple mbufs are attached to a mbuf having an external buffer the external buffer is writable . - There ' s no need to allocate buffer from a mempool . Any buffer can be attached with appropriate free callback and its IO address . - Smaller metadata is required to maintain shared data such as refcnt . @param m The pointer to the mbuf . @param buf_addr The pointer to the external buffer . @param buf_iova IO address of the external buffer . @param buf_len The size of the external buffer . @param shinfo User - provided memory for shared data of the external buffer .
static inline void
rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr,
	rte_iova_t buf_iova, uint16_t buf_len,
	struct rte_mbuf_ext_shared_info *shinfo)
{
	RTE_ASSERT(RTE_MBUF_DIRECT(m) && rte_mbuf_refcnt_read(m) == 1);
	RTE_ASSERT(shinfo->free_cb != NULL);
	m->buf_addr = buf_addr;
	m->buf_iova = buf_iova;
	m->buf_len = buf_len;
	m->data_len = 0;
	m->data_off = 0;
	m->ol_flags |= EXT_ATTACHED_MBUF;
	m->shinfo = shinfo;
}
static inline void rte_pktmbuf_attach_extbuf ( struct rte_mbuf * m , void * buf_addr , rte_iova_t buf_iova , uint16_t buf_len , struct rte_mbuf_ext_shared_info * shinfo ) { RTE_ASSERT ( RTE_MBUF_DIRECT ( m ) && rte_mbuf_refcnt_read ( m ) == 1 ) ; RTE_ASSERT ( shinfo -> free_cb != NULL ) ; m -> buf_addr = buf_addr ; m -> buf_iova = buf_iova ; m -> buf_len = buf_len ; m -> data_len = 0 ; m -> data_off = 0 ; m -> ol_flags |= EXT_ATTACHED_MBUF ; m -> shinfo = shinfo ; }
Attach an external buffer to a mbuf.
Attach an external buffer to a mbuf .
/* mbuf should not be read-only */