Lines Matching +full:min +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (C) 2024-2025 Intel Corporation */
13 * libeth_rx_hw_len_mtu - get the actual buffer size to be passed to HW
17 * Return: HW-writeable length per one buffer to pass it to the HW accounting:
23 u32 len; in libeth_rx_hw_len_mtu() local
25 len = READ_ONCE(pp->netdev->mtu) + LIBETH_RX_LL_LEN; in libeth_rx_hw_len_mtu()
26 len = ALIGN(len, LIBETH_RX_BUF_STRIDE); in libeth_rx_hw_len_mtu()
27 len = min3(len, ALIGN_DOWN(max_len ? : U32_MAX, LIBETH_RX_BUF_STRIDE), in libeth_rx_hw_len_mtu()
28 pp->max_len); in libeth_rx_hw_len_mtu()
30 return len; in libeth_rx_hw_len_mtu()
34 * libeth_rx_hw_len_truesize - get the short buffer size to be passed to HW
39 * Return: HW-writeable length per one buffer to pass it to the HW ignoring the
46 u32 min, len; in libeth_rx_hw_len_truesize() local
48 min = SKB_HEAD_ALIGN(pp->offset + LIBETH_RX_BUF_STRIDE); in libeth_rx_hw_len_truesize()
49 truesize = clamp(roundup_pow_of_two(truesize), roundup_pow_of_two(min), in libeth_rx_hw_len_truesize()
52 len = SKB_WITH_OVERHEAD(truesize - pp->offset); in libeth_rx_hw_len_truesize()
53 len = ALIGN_DOWN(len, LIBETH_RX_BUF_STRIDE) ? : LIBETH_RX_BUF_STRIDE; in libeth_rx_hw_len_truesize()
54 len = min3(len, ALIGN_DOWN(max_len ? : U32_MAX, LIBETH_RX_BUF_STRIDE), in libeth_rx_hw_len_truesize()
55 pp->max_len); in libeth_rx_hw_len_truesize()
57 return len; in libeth_rx_hw_len_truesize()
61 * libeth_rx_page_pool_params - calculate params with the stack overhead
75 pp->offset = fq->xdp ? LIBETH_XDP_HEADROOM : LIBETH_SKB_HEADROOM; in libeth_rx_page_pool_params()
76 /* HW-writeable / syncable length per one page */ in libeth_rx_page_pool_params()
77 pp->max_len = LIBETH_RX_PAGE_LEN(pp->offset); in libeth_rx_page_pool_params()
79 /* HW-writeable length per buffer */ in libeth_rx_page_pool_params()
80 switch (fq->type) { in libeth_rx_page_pool_params()
82 fq->buf_len = libeth_rx_hw_len_mtu(pp, fq->buf_len); in libeth_rx_page_pool_params()
85 fq->buf_len = libeth_rx_hw_len_truesize(pp, fq->buf_len, in libeth_rx_page_pool_params()
86 fq->truesize); in libeth_rx_page_pool_params()
89 fq->buf_len = ALIGN(LIBETH_MAX_HEAD, LIBETH_RX_BUF_STRIDE); in libeth_rx_page_pool_params()
96 fq->truesize = roundup_pow_of_two(SKB_HEAD_ALIGN(pp->offset + in libeth_rx_page_pool_params()
97 fq->buf_len)); in libeth_rx_page_pool_params()
103 * libeth_rx_page_pool_params_zc - calculate params without the stack overhead
121 pp->offset = 0; in libeth_rx_page_pool_params_zc()
122 pp->max_len = PAGE_SIZE << LIBETH_RX_PAGE_ORDER; in libeth_rx_page_pool_params_zc()
124 switch (fq->type) { in libeth_rx_page_pool_params_zc()
126 mtu = READ_ONCE(pp->netdev->mtu); in libeth_rx_page_pool_params_zc()
129 mtu = fq->truesize; in libeth_rx_page_pool_params_zc()
136 max = min(rounddown_pow_of_two(fq->buf_len ? : U32_MAX), in libeth_rx_page_pool_params_zc()
137 pp->max_len); in libeth_rx_page_pool_params_zc()
139 fq->buf_len = clamp(mtu, LIBETH_RX_BUF_STRIDE, max); in libeth_rx_page_pool_params_zc()
140 fq->truesize = fq->buf_len; in libeth_rx_page_pool_params_zc()
146 * libeth_rx_fq_create - create a PP with the default libeth settings
150 * Return: %0 on success, -%errno on failure.
157 .pool_size = fq->count, in libeth_rx_fq_create()
158 .nid = fq->nid, in libeth_rx_fq_create()
159 .dev = napi->dev->dev.parent, in libeth_rx_fq_create()
160 .netdev = napi->dev, in libeth_rx_fq_create()
167 pp.dma_dir = fq->xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; in libeth_rx_fq_create()
169 if (!fq->hsplit) in libeth_rx_fq_create()
174 return -EINVAL; in libeth_rx_fq_create()
180 fqes = kvcalloc_node(fq->count, sizeof(*fqes), GFP_KERNEL, fq->nid); in libeth_rx_fq_create()
182 ret = -ENOMEM; in libeth_rx_fq_create()
190 fq->fqes = fqes; in libeth_rx_fq_create()
191 fq->pp = pool; in libeth_rx_fq_create()
205 * libeth_rx_fq_destroy - destroy a &page_pool created by libeth
210 xdp_unreg_page_pool(fq->pp); in libeth_rx_fq_destroy()
211 kvfree(fq->fqes); in libeth_rx_fq_destroy()
212 page_pool_destroy(fq->pp); in libeth_rx_fq_destroy()
217 * libeth_rx_recycle_slow - recycle libeth netmem
255 * libeth_rx_pt_gen_hash_type - generate an XDP RSS hash type for a PT
263 pt->hash_type = 0; in libeth_rx_pt_gen_hash_type()
264 pt->hash_type |= libeth_rx_pt_xdp_oip[pt->outer_ip]; in libeth_rx_pt_gen_hash_type()
265 pt->hash_type |= libeth_rx_pt_xdp_iprot[pt->inner_prot]; in libeth_rx_pt_gen_hash_type()
266 pt->hash_type |= libeth_rx_pt_xdp_pl[pt->payload_layer]; in libeth_rx_pt_gen_hash_type()