/** * libeth_rx_hw_len_mtu - get the actual buffer size to be passed to HW * @pp: &page_pool_params of the netdev to calculate the size for * @max_len: maximum buffer size for a single descriptor * * Return: HW-writeable length per one buffer to pass it to the HW accounting: * MTU the @dev has, HW required alignment, minimum and maximum allowed values, * and system's page size.
*/ static u32 libeth_rx_hw_len_mtu(conststruct page_pool_params *pp, u32 max_len)
{
u32 len;
len = READ_ONCE(pp->netdev->mtu) + LIBETH_RX_LL_LEN;
len = ALIGN(len, LIBETH_RX_BUF_STRIDE);
len = min3(len, ALIGN_DOWN(max_len ? : U32_MAX, LIBETH_RX_BUF_STRIDE),
pp->max_len);
return len;
}
/** * libeth_rx_hw_len_truesize - get the short buffer size to be passed to HW * @pp: &page_pool_params of the netdev to calculate the size for * @max_len: maximum buffer size for a single descriptor * @truesize: desired truesize for the buffers * * Return: HW-writeable length per one buffer to pass it to the HW ignoring the * MTU and closest to the passed truesize. Can be used for "short" buffer * queues to fragment pages more efficiently.
*/ static u32 libeth_rx_hw_len_truesize(conststruct page_pool_params *pp,
u32 max_len, u32 truesize)
{
u32 min, len;
len = SKB_WITH_OVERHEAD(truesize - pp->offset);
len = ALIGN_DOWN(len, LIBETH_RX_BUF_STRIDE) ? : LIBETH_RX_BUF_STRIDE;
len = min3(len, ALIGN_DOWN(max_len ? : U32_MAX, LIBETH_RX_BUF_STRIDE),
pp->max_len);
return len;
}
/** * libeth_rx_page_pool_params - calculate params with the stack overhead * @fq: buffer queue to calculate the size for * @pp: &page_pool_params of the netdev * * Set the PP params to will all needed stack overhead (headroom, tailroom) and * both the HW buffer length and the truesize for all types of buffers. For * "short" buffers, truesize never exceeds the "wanted" one; for the rest, * it can be up to the page size. * * Return: true on success, false on invalid input params.
*/ staticbool libeth_rx_page_pool_params(struct libeth_fq *fq, struct page_pool_params *pp)
{
pp->offset = fq->xdp ? LIBETH_XDP_HEADROOM : LIBETH_SKB_HEADROOM; /* HW-writeable / syncable length per one page */
pp->max_len = LIBETH_RX_PAGE_LEN(pp->offset);
/* HW-writeable length per buffer */ switch (fq->type) { case LIBETH_FQE_MTU:
fq->buf_len = libeth_rx_hw_len_mtu(pp, fq->buf_len); break; case LIBETH_FQE_SHORT:
fq->buf_len = libeth_rx_hw_len_truesize(pp, fq->buf_len,
fq->truesize); break; case LIBETH_FQE_HDR:
fq->buf_len = ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE); break; default: returnfalse;
}
/** * libeth_rx_page_pool_params_zc - calculate params without the stack overhead * @fq: buffer queue to calculate the size for * @pp: &page_pool_params of the netdev * * Set the PP params to exclude the stack overhead and both the buffer length * and the truesize, which are equal for the data buffers. Note that this * requires separate header buffers to be always active and account the * overhead. * With the MTU == ``PAGE_SIZE``, this allows the kernel to enable the zerocopy * mode. * * Return: true on success, false on invalid input params.
*/ staticbool libeth_rx_page_pool_params_zc(struct libeth_fq *fq, struct page_pool_params *pp)
{
u32 mtu, max;
switch (fq->type) { case LIBETH_FQE_MTU:
mtu = READ_ONCE(pp->netdev->mtu); break; case LIBETH_FQE_SHORT:
mtu = fq->truesize; break; default: returnfalse;
}
mtu = roundup_pow_of_two(mtu);
max = min(rounddown_pow_of_two(fq->buf_len ? : U32_MAX),
pp->max_len);
/** * libeth_rx_fq_destroy - destroy a &page_pool created by libeth * @fq: buffer queue to process
*/ void libeth_rx_fq_destroy(struct libeth_fq *fq)
{
xdp_unreg_page_pool(fq->pp);
kvfree(fq->fqes);
page_pool_destroy(fq->pp);
}
EXPORT_SYMBOL_GPL(libeth_rx_fq_destroy);
/** * libeth_rx_recycle_slow - recycle libeth netmem * @netmem: network memory to recycle * * To be used on exceptions or rare cases not requiring fast inline recycling.
*/ void __cold libeth_rx_recycle_slow(netmem_ref netmem)
{
page_pool_put_full_netmem(netmem_get_pp(netmem), netmem, false);
}
EXPORT_SYMBOL_GPL(libeth_rx_recycle_slow);
/* Converting abstract packet type numbers into a software structure with * the packet parameters to do O(1) lookup on Rx.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.