From: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Date: Mon, 23 Jul 2018 23:36:07 +0900
Subject: virtio_net: Factor out the logic to determine xdp sq
Patch-mainline: v4.19-rc1
Git-commit: 2a43565c06465323e33b117bcf2ce604c0594659
References: bsc#1109837
Make sure to use the same logic in all places to determine xdp sq. This
is useful for xdp counters which the following commit will introduce as
well.
Signed-off-by: Toshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
---
drivers/net/virtio_net.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -457,16 +457,22 @@ static int __virtnet_xdp_xmit_one(struct
return 0;
}
+static struct send_queue *virtnet_xdp_sq(struct virtnet_info *vi)
+{
+ unsigned int qp;
+
+ qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
+ return &vi->sq[qp];
+}
+
static int __virtnet_xdp_tx_xmit(struct virtnet_info *vi,
struct xdp_frame *xdpf)
{
struct xdp_frame *xdpf_sent;
struct send_queue *sq;
unsigned int len;
- unsigned int qp;
- qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
- sq = &vi->sq[qp];
+ sq = virtnet_xdp_sq(vi);
/* Free up any pending old buffers before queueing new ones. */
while ((xdpf_sent = virtqueue_get_buf(sq->vq, &len)) != NULL)
@@ -484,7 +490,6 @@ static int virtnet_xdp_xmit(struct net_d
struct bpf_prog *xdp_prog;
struct send_queue *sq;
unsigned int len;
- unsigned int qp;
int drops = 0;
int err;
int i;
@@ -492,8 +497,7 @@ static int virtnet_xdp_xmit(struct net_d
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
return -EINVAL;
- qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
- sq = &vi->sq[qp];
+ sq = virtnet_xdp_sq(vi);
/* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this
* indicate XDP resources have been successfully allocated.
@@ -1350,7 +1354,7 @@ static int virtnet_poll(struct napi_stru
container_of(napi, struct receive_queue, napi);
struct virtnet_info *vi = rq->vq->vdev->priv;
struct send_queue *sq;
- unsigned int received, qp;
+ unsigned int received;
unsigned int xdp_xmit = 0;
virtnet_poll_cleantx(rq);
@@ -1365,9 +1369,7 @@ static int virtnet_poll(struct napi_stru
xdp_do_flush_map();
if (xdp_xmit & VIRTIO_XDP_TX) {
- qp = vi->curr_queue_pairs - vi->xdp_queue_pairs +
- smp_processor_id();
- sq = &vi->sq[qp];
+ sq = virtnet_xdp_sq(vi);
virtqueue_kick(sq->vq);
}