support xsk XDP_SETUP_XSK_POOL. Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> --- drivers/net/virtio/main.c | 2 ++ drivers/net/virtio/virtio_net.h | 2 ++ drivers/net/virtio/xsk.c | 9 +++++++++ drivers/net/virtio/xsk.h | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 drivers/net/virtio/xsk.h diff --git a/drivers/net/virtio/main.c b/drivers/net/virtio/main.c index 0ee23468b795..ed79e750bc6c 100644 --- a/drivers/net/virtio/main.c +++ b/drivers/net/virtio/main.c @@ -3094,6 +3094,8 @@ static int virtnet_xdp(struct net_device *dev, struct netdev_bpf *xdp) switch (xdp->command) { case XDP_SETUP_PROG: return virtnet_xdp_set(dev, xdp->prog, xdp->extack); + case XDP_SETUP_XSK_POOL: + return virtnet_xsk_pool_setup(dev, xdp); default: return -EINVAL; } diff --git a/drivers/net/virtio/virtio_net.h b/drivers/net/virtio/virtio_net.h index 4a7633714802..a12d85624fe9 100644 --- a/drivers/net/virtio/virtio_net.h +++ b/drivers/net/virtio/virtio_net.h @@ -248,6 +248,8 @@ static inline void virtqueue_napi_schedule(struct napi_struct *napi, } } +#include "xsk.h" + static inline bool is_xdp_frame(void *ptr) { return (unsigned long)ptr & VIRTIO_XDP_FLAG; diff --git a/drivers/net/virtio/xsk.c b/drivers/net/virtio/xsk.c index 18c0c6e4d501..b96af38a2608 100644 --- a/drivers/net/virtio/xsk.c +++ b/drivers/net/virtio/xsk.c @@ -142,3 +142,12 @@ static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid) return err1 | err2; } + +int virtnet_xsk_pool_setup(struct net_device *dev, struct netdev_bpf *xdp) +{ + if (xdp->xsk.pool) + return virtnet_xsk_pool_enable(dev, xdp->xsk.pool, + xdp->xsk.queue_id); + else + return virtnet_xsk_pool_disable(dev, xdp->xsk.queue_id); +} diff --git a/drivers/net/virtio/xsk.h b/drivers/net/virtio/xsk.h new file mode 100644 index 000000000000..1918285c310c --- /dev/null +++ b/drivers/net/virtio/xsk.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __XSK_H__ +#define __XSK_H__ + +int virtnet_xsk_pool_setup(struct net_device *dev, struct netdev_bpf *xdp); +#endif -- 2.32.0.3.g01195cf9f