2020-05-20 19:20:51 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* Interface for implementing AF_XDP zero-copy support in drivers.
|
|
|
|
* Copyright(c) 2020 Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_XDP_SOCK_DRV_H
|
|
|
|
#define _LINUX_XDP_SOCK_DRV_H
|
|
|
|
|
|
|
|
#include <net/xdp_sock.h>
|
2020-05-20 19:20:53 +00:00
|
|
|
#include <net/xsk_buff_pool.h>
|
2020-05-20 19:20:51 +00:00
|
|
|
|
2022-09-29 07:21:41 +00:00
|
|
|
#define XDP_UMEM_MIN_CHUNK_SHIFT 11
|
|
|
|
#define XDP_UMEM_MIN_CHUNK_SIZE (1 << XDP_UMEM_MIN_CHUNK_SHIFT)
|
|
|
|
|
2023-12-05 21:08:36 +00:00
|
|
|
struct xsk_cb_desc {
|
|
|
|
void *src;
|
|
|
|
u8 off;
|
|
|
|
u8 bytes;
|
|
|
|
};
|
|
|
|
|
2023-12-19 11:02:05 +00:00
|
|
|
#ifdef CONFIG_XDP_SOCKETS
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries);
|
|
|
|
bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc);
|
2022-01-25 16:04:43 +00:00
|
|
|
u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max);
|
2020-08-28 08:26:16 +00:00
|
|
|
void xsk_tx_release(struct xsk_buff_pool *pool);
|
|
|
|
struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev,
|
|
|
|
u16 queue_id);
|
|
|
|
void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool);
|
|
|
|
void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool);
|
|
|
|
void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool);
|
|
|
|
void xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool);
|
|
|
|
bool xsk_uses_need_wakeup(struct xsk_buff_pool *pool);
|
2020-05-20 19:20:51 +00:00
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return XDP_PACKET_HEADROOM + pool->headroom;
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return pool->chunk_size;
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return xsk_pool_get_chunk_size(pool) - xsk_pool_get_headroom(pool);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
struct xdp_rxq_info *rxq)
|
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
xp_set_rxq_info(pool, rxq);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 21:08:36 +00:00
|
|
|
static inline void xsk_pool_fill_cb(struct xsk_buff_pool *pool,
|
|
|
|
struct xsk_cb_desc *desc)
|
|
|
|
{
|
|
|
|
xp_fill_cb(pool, desc);
|
|
|
|
}
|
|
|
|
|
2022-07-07 13:08:42 +00:00
|
|
|
static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NET_RX_BUSY_POLL
|
|
|
|
return pool->heads[0].xdp.rxq->napi_id;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
unsigned long attrs)
|
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
xp_dma_unmap(pool, attrs);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline int xsk_pool_dma_map(struct xsk_buff_pool *pool,
|
|
|
|
struct device *dev, unsigned long attrs)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
struct xdp_umem *umem = pool->umem;
|
|
|
|
|
|
|
|
return xp_dma_map(pool, dev, attrs, umem->pgs, umem->npgs);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
|
|
|
|
|
|
|
|
return xp_get_dma(xskb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
|
|
|
|
|
|
|
|
return xp_get_frame_dma(xskb);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return xp_alloc(pool);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 13:24:04 +00:00
|
|
|
static inline bool xsk_is_eop_desc(struct xdp_desc *desc)
|
|
|
|
{
|
|
|
|
return !xp_mb_desc(desc);
|
|
|
|
}
|
|
|
|
|
xsk: Batched buffer allocation for the pool
Add a new driver interface xsk_buff_alloc_batch() offering batched
buffer allocations to improve performance. The new interface takes
three arguments: the buffer pool to allocated from, a pointer to an
array of struct xdp_buff pointers which will contain pointers to the
allocated xdp_buffs, and an unsigned integer specifying the max number
of buffers to allocate. The return value is the actual number of
buffers that the allocator managed to allocate and it will be in the
range 0 <= N <= max, where max is the third parameter to the function.
u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
u32 max);
A second driver interface is also introduced that need to be used in
conjunction with xsk_buff_alloc_batch(). It is a helper that sets the
size of struct xdp_buff and is used by the NIC Rx irq routine when
receiving a packet. This helper sets the three struct members data,
data_meta, and data_end. The two first ones is in the xsk_buff_alloc()
case set in the allocation routine and data_end is set when a packet
is received in the receive irq function. This unfortunately leads to
worse performance since the xdp_buff is touched twice with a long time
period in between leading to an extra cache miss. Instead, we fill out
the xdp_buff with all 3 fields at one single point in time in the
driver, when the size of the packet is known. Hence this helper. Note
that the driver has to use this helper (or set all three fields
itself) when using xsk_buff_alloc_batch(). xsk_buff_alloc() works as
before and does not require this.
void xsk_buff_set_size(struct xdp_buff *xdp, u32 size);
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922075613.12186-3-magnus.karlsson@gmail.com
2021-09-22 07:56:02 +00:00
|
|
|
/* Returns as many entries as possible up to max. 0 <= N <= max. */
|
|
|
|
static inline u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp, u32 max)
|
|
|
|
{
|
|
|
|
return xp_alloc_batch(pool, xdp, max);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline bool xsk_buff_can_alloc(struct xsk_buff_pool *pool, u32 count)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return xp_can_alloc(pool, count);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_buff_free(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
|
2023-07-19 13:24:08 +00:00
|
|
|
struct list_head *xskb_list = &xskb->pool->xskb_list;
|
|
|
|
struct xdp_buff_xsk *pos, *tmp;
|
2020-05-20 19:20:53 +00:00
|
|
|
|
2023-07-19 13:24:08 +00:00
|
|
|
if (likely(!xdp_buff_has_frags(xdp)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(pos, tmp, xskb_list, xskb_list_node) {
|
|
|
|
list_del(&pos->xskb_list_node);
|
|
|
|
xp_free(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
xdp_get_shared_info_from_buff(xdp)->nr_frags = 0;
|
|
|
|
out:
|
2020-05-20 19:20:53 +00:00
|
|
|
xp_free(xskb);
|
|
|
|
}
|
|
|
|
|
2023-07-19 13:24:08 +00:00
|
|
|
static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *frag = container_of(xdp, struct xdp_buff_xsk, xdp);
|
|
|
|
|
|
|
|
list_add_tail(&frag->xskb_list_node, &frag->pool->xskb_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_buff *xsk_buff_get_frag(struct xdp_buff *first)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(first, struct xdp_buff_xsk, xdp);
|
|
|
|
struct xdp_buff *ret = NULL;
|
|
|
|
struct xdp_buff_xsk *frag;
|
|
|
|
|
|
|
|
frag = list_first_entry_or_null(&xskb->pool->xskb_list,
|
|
|
|
struct xdp_buff_xsk, xskb_list_node);
|
|
|
|
if (frag) {
|
|
|
|
list_del(&frag->xskb_list_node);
|
|
|
|
ret = &frag->xdp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-24 19:15:54 +00:00
|
|
|
static inline void xsk_buff_del_tail(struct xdp_buff *tail)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(tail, struct xdp_buff_xsk, xdp);
|
|
|
|
|
|
|
|
list_del(&xskb->xskb_list_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_buff *xsk_buff_get_tail(struct xdp_buff *first)
|
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(first, struct xdp_buff_xsk, xdp);
|
|
|
|
struct xdp_buff_xsk *frag;
|
|
|
|
|
|
|
|
frag = list_last_entry(&xskb->pool->xskb_list, struct xdp_buff_xsk,
|
|
|
|
xskb_list_node);
|
|
|
|
return &frag->xdp;
|
|
|
|
}
|
|
|
|
|
xsk: Batched buffer allocation for the pool
Add a new driver interface xsk_buff_alloc_batch() offering batched
buffer allocations to improve performance. The new interface takes
three arguments: the buffer pool to allocated from, a pointer to an
array of struct xdp_buff pointers which will contain pointers to the
allocated xdp_buffs, and an unsigned integer specifying the max number
of buffers to allocate. The return value is the actual number of
buffers that the allocator managed to allocate and it will be in the
range 0 <= N <= max, where max is the third parameter to the function.
u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
u32 max);
A second driver interface is also introduced that need to be used in
conjunction with xsk_buff_alloc_batch(). It is a helper that sets the
size of struct xdp_buff and is used by the NIC Rx irq routine when
receiving a packet. This helper sets the three struct members data,
data_meta, and data_end. The two first ones is in the xsk_buff_alloc()
case set in the allocation routine and data_end is set when a packet
is received in the receive irq function. This unfortunately leads to
worse performance since the xdp_buff is touched twice with a long time
period in between leading to an extra cache miss. Instead, we fill out
the xdp_buff with all 3 fields at one single point in time in the
driver, when the size of the packet is known. Hence this helper. Note
that the driver has to use this helper (or set all three fields
itself) when using xsk_buff_alloc_batch(). xsk_buff_alloc() works as
before and does not require this.
void xsk_buff_set_size(struct xdp_buff *xdp, u32 size);
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922075613.12186-3-magnus.karlsson@gmail.com
2021-09-22 07:56:02 +00:00
|
|
|
static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
|
|
|
|
{
|
|
|
|
xdp->data = xdp->data_hard_start + XDP_PACKET_HEADROOM;
|
|
|
|
xdp->data_meta = xdp->data;
|
|
|
|
xdp->data_end = xdp->data + size;
|
xsk: make xsk_buff_pool responsible for clearing xdp_buff::flags
XDP multi-buffer support introduced XDP_FLAGS_HAS_FRAGS flag that is
used by drivers to notify data path whether xdp_buff contains fragments
or not. Data path looks up mentioned flag on first buffer that occupies
the linear part of xdp_buff, so drivers only modify it there. This is
sufficient for SKB and XDP_DRV modes as usually xdp_buff is allocated on
stack or it resides within struct representing driver's queue and
fragments are carried via skb_frag_t structs. IOW, we are dealing with
only one xdp_buff.
ZC mode though relies on list of xdp_buff structs that is carried via
xsk_buff_pool::xskb_list, so ZC data path has to make sure that
fragments do *not* have XDP_FLAGS_HAS_FRAGS set. Otherwise,
xsk_buff_free() could misbehave if it would be executed against xdp_buff
that carries a frag with XDP_FLAGS_HAS_FRAGS flag set. Such scenario can
take place when within supplied XDP program bpf_xdp_adjust_tail() is
used with negative offset that would in turn release the tail fragment
from multi-buffer frame.
Calling xsk_buff_free() on tail fragment with XDP_FLAGS_HAS_FRAGS would
result in releasing all the nodes from xskb_list that were produced by
driver before XDP program execution, which is not what is intended -
only tail fragment should be deleted from xskb_list and then it should
be put onto xsk_buff_pool::free_list. Such multi-buffer frame will never
make it up to user space, so from AF_XDP application POV there would be
no traffic running, however due to free_list getting constantly new
nodes, driver will be able to feed HW Rx queue with recycled buffers.
Bottom line is that instead of traffic being redirected to user space,
it would be continuously dropped.
To fix this, let us clear the mentioned flag on xsk_buff_pool side
during xdp_buff initialization, which is what should have been done
right from the start of XSK multi-buffer support.
Fixes: 1bbc04de607b ("ice: xsk: add RX multi-buffer support")
Fixes: 1c9ba9c14658 ("i40e: xsk: add RX multi-buffer support")
Fixes: 24ea50127ecf ("xsk: support mbuf on ZC RX")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://lore.kernel.org/r/20240124191602.566724-3-maciej.fijalkowski@intel.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2024-01-24 19:15:53 +00:00
|
|
|
xdp->flags = 0;
|
xsk: Batched buffer allocation for the pool
Add a new driver interface xsk_buff_alloc_batch() offering batched
buffer allocations to improve performance. The new interface takes
three arguments: the buffer pool to allocated from, a pointer to an
array of struct xdp_buff pointers which will contain pointers to the
allocated xdp_buffs, and an unsigned integer specifying the max number
of buffers to allocate. The return value is the actual number of
buffers that the allocator managed to allocate and it will be in the
range 0 <= N <= max, where max is the third parameter to the function.
u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
u32 max);
A second driver interface is also introduced that need to be used in
conjunction with xsk_buff_alloc_batch(). It is a helper that sets the
size of struct xdp_buff and is used by the NIC Rx irq routine when
receiving a packet. This helper sets the three struct members data,
data_meta, and data_end. The two first ones is in the xsk_buff_alloc()
case set in the allocation routine and data_end is set when a packet
is received in the receive irq function. This unfortunately leads to
worse performance since the xdp_buff is touched twice with a long time
period in between leading to an extra cache miss. Instead, we fill out
the xdp_buff with all 3 fields at one single point in time in the
driver, when the size of the packet is known. Hence this helper. Note
that the driver has to use this helper (or set all three fields
itself) when using xsk_buff_alloc_batch(). xsk_buff_alloc() works as
before and does not require this.
void xsk_buff_set_size(struct xdp_buff *xdp, u32 size);
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922075613.12186-3-magnus.karlsson@gmail.com
2021-09-22 07:56:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool,
|
|
|
|
u64 addr)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return xp_raw_get_dma(pool, addr);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
return xp_raw_get_data(pool, addr);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 19:03:13 +00:00
|
|
|
#define XDP_TXMD_FLAGS_VALID ( \
|
|
|
|
XDP_TXMD_FLAGS_TIMESTAMP | \
|
|
|
|
XDP_TXMD_FLAGS_CHECKSUM | \
|
|
|
|
0)
|
|
|
|
|
|
|
|
static inline bool xsk_buff_valid_tx_metadata(struct xsk_tx_metadata *meta)
|
|
|
|
{
|
|
|
|
return !(meta->flags & ~XDP_TXMD_FLAGS_VALID);
|
|
|
|
}
|
|
|
|
|
2023-11-27 19:03:08 +00:00
|
|
|
static inline struct xsk_tx_metadata *xsk_buff_get_metadata(struct xsk_buff_pool *pool, u64 addr)
|
|
|
|
{
|
2023-11-27 19:03:13 +00:00
|
|
|
struct xsk_tx_metadata *meta;
|
|
|
|
|
2023-11-27 19:03:08 +00:00
|
|
|
if (!pool->tx_metadata_len)
|
|
|
|
return NULL;
|
|
|
|
|
2023-11-27 19:03:13 +00:00
|
|
|
meta = xp_raw_get_data(pool, addr) - pool->tx_metadata_len;
|
|
|
|
if (unlikely(!xsk_buff_valid_tx_metadata(meta)))
|
|
|
|
return NULL; /* no way to signal the error to the user */
|
|
|
|
|
|
|
|
return meta;
|
2023-11-27 19:03:08 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 11:20:26 +00:00
|
|
|
static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
|
|
|
|
|
|
|
|
xp_dma_sync_for_cpu(xskb);
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
dma_addr_t dma,
|
|
|
|
size_t size)
|
|
|
|
{
|
2020-08-28 08:26:16 +00:00
|
|
|
xp_dma_sync_for_device(pool, dma, size);
|
2020-05-20 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 19:20:51 +00:00
|
|
|
#else
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline bool xsk_tx_peek_desc(struct xsk_buff_pool *pool,
|
|
|
|
struct xdp_desc *desc)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-01-25 16:04:43 +00:00
|
|
|
static inline u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, u32 max)
|
2020-11-16 11:12:46 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_tx_release(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:15 +00:00
|
|
|
static inline struct xsk_buff_pool *
|
2020-08-28 08:26:16 +00:00
|
|
|
xsk_get_pool_from_qid(struct net_device *dev, u16 queue_id)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_set_tx_need_wakeup(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_clear_rx_need_wakeup(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_clear_tx_need_wakeup(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline bool xsk_uses_need_wakeup(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:51 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_headroom(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_chunk_size(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline u32 xsk_pool_get_rx_frame_size(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_pool_set_rxq_info(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
struct xdp_rxq_info *rxq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-12-05 21:08:36 +00:00
|
|
|
static inline void xsk_pool_fill_cb(struct xsk_buff_pool *pool,
|
|
|
|
struct xsk_cb_desc *desc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-07 13:08:42 +00:00
|
|
|
static inline unsigned int xsk_pool_get_napi_id(struct xsk_buff_pool *pool)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_pool_dma_unmap(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
unsigned long attrs)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline int xsk_pool_dma_map(struct xsk_buff_pool *pool,
|
|
|
|
struct device *dev, unsigned long attrs)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xsk_buff_xdp_get_dma(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xsk_buff_xdp_get_frame_dma(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline struct xdp_buff *xsk_buff_alloc(struct xsk_buff_pool *pool)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-07-19 13:24:04 +00:00
|
|
|
static inline bool xsk_is_eop_desc(struct xdp_desc *desc)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
xsk: Batched buffer allocation for the pool
Add a new driver interface xsk_buff_alloc_batch() offering batched
buffer allocations to improve performance. The new interface takes
three arguments: the buffer pool to allocated from, a pointer to an
array of struct xdp_buff pointers which will contain pointers to the
allocated xdp_buffs, and an unsigned integer specifying the max number
of buffers to allocate. The return value is the actual number of
buffers that the allocator managed to allocate and it will be in the
range 0 <= N <= max, where max is the third parameter to the function.
u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
u32 max);
A second driver interface is also introduced that need to be used in
conjunction with xsk_buff_alloc_batch(). It is a helper that sets the
size of struct xdp_buff and is used by the NIC Rx irq routine when
receiving a packet. This helper sets the three struct members data,
data_meta, and data_end. The two first ones is in the xsk_buff_alloc()
case set in the allocation routine and data_end is set when a packet
is received in the receive irq function. This unfortunately leads to
worse performance since the xdp_buff is touched twice with a long time
period in between leading to an extra cache miss. Instead, we fill out
the xdp_buff with all 3 fields at one single point in time in the
driver, when the size of the packet is known. Hence this helper. Note
that the driver has to use this helper (or set all three fields
itself) when using xsk_buff_alloc_batch(). xsk_buff_alloc() works as
before and does not require this.
void xsk_buff_set_size(struct xdp_buff *xdp, u32 size);
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922075613.12186-3-magnus.karlsson@gmail.com
2021-09-22 07:56:02 +00:00
|
|
|
static inline u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp, u32 max)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline bool xsk_buff_can_alloc(struct xsk_buff_pool *pool, u32 count)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_buff_free(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-07-19 13:24:08 +00:00
|
|
|
static inline void xsk_buff_add_frag(struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_buff *xsk_buff_get_frag(struct xdp_buff *first)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-01-24 19:15:54 +00:00
|
|
|
static inline void xsk_buff_del_tail(struct xdp_buff *tail)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_buff *xsk_buff_get_tail(struct xdp_buff *first)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
xsk: Batched buffer allocation for the pool
Add a new driver interface xsk_buff_alloc_batch() offering batched
buffer allocations to improve performance. The new interface takes
three arguments: the buffer pool to allocated from, a pointer to an
array of struct xdp_buff pointers which will contain pointers to the
allocated xdp_buffs, and an unsigned integer specifying the max number
of buffers to allocate. The return value is the actual number of
buffers that the allocator managed to allocate and it will be in the
range 0 <= N <= max, where max is the third parameter to the function.
u32 xsk_buff_alloc_batch(struct xsk_buff_pool *pool, struct xdp_buff **xdp,
u32 max);
A second driver interface is also introduced that need to be used in
conjunction with xsk_buff_alloc_batch(). It is a helper that sets the
size of struct xdp_buff and is used by the NIC Rx irq routine when
receiving a packet. This helper sets the three struct members data,
data_meta, and data_end. The two first ones is in the xsk_buff_alloc()
case set in the allocation routine and data_end is set when a packet
is received in the receive irq function. This unfortunately leads to
worse performance since the xdp_buff is touched twice with a long time
period in between leading to an extra cache miss. Instead, we fill out
the xdp_buff with all 3 fields at one single point in time in the
driver, when the size of the packet is known. Hence this helper. Note
that the driver has to use this helper (or set all three fields
itself) when using xsk_buff_alloc_batch(). xsk_buff_alloc() works as
before and does not require this.
void xsk_buff_set_size(struct xdp_buff *xdp, u32 size);
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922075613.12186-3-magnus.karlsson@gmail.com
2021-09-22 07:56:02 +00:00
|
|
|
static inline void xsk_buff_set_size(struct xdp_buff *xdp, u32 size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline dma_addr_t xsk_buff_raw_get_dma(struct xsk_buff_pool *pool,
|
|
|
|
u64 addr)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void *xsk_buff_raw_get_data(struct xsk_buff_pool *pool, u64 addr)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-11-27 19:03:13 +00:00
|
|
|
static inline bool xsk_buff_valid_tx_metadata(struct xsk_tx_metadata *meta)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-27 19:03:08 +00:00
|
|
|
static inline struct xsk_tx_metadata *xsk_buff_get_metadata(struct xsk_buff_pool *pool, u64 addr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2024-05-07 11:20:26 +00:00
|
|
|
static inline void xsk_buff_dma_sync_for_cpu(struct xdp_buff *xdp)
|
2020-05-20 19:20:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-28 08:26:16 +00:00
|
|
|
static inline void xsk_buff_raw_dma_sync_for_device(struct xsk_buff_pool *pool,
|
2020-05-20 19:20:53 +00:00
|
|
|
dma_addr_t dma,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-05-20 19:20:51 +00:00
|
|
|
#endif /* CONFIG_XDP_SOCKETS */
|
|
|
|
|
|
|
|
#endif /* _LINUX_XDP_SOCK_DRV_H */
|