Commit 2a43565c authored by Toshiaki Makita's avatar Toshiaki Makita Committed by David S. Miller

virtio_net: Factor out the logic to determine xdp sq

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: default avatarToshiaki Makita <makita.toshiaki@lab.ntt.co.jp>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2c4a2f7d
...@@ -457,16 +457,22 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi, ...@@ -457,16 +457,22 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi,
return 0; 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, static int __virtnet_xdp_tx_xmit(struct virtnet_info *vi,
struct xdp_frame *xdpf) struct xdp_frame *xdpf)
{ {
struct xdp_frame *xdpf_sent; struct xdp_frame *xdpf_sent;
struct send_queue *sq; struct send_queue *sq;
unsigned int len; unsigned int len;
unsigned int qp;
qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id(); sq = virtnet_xdp_sq(vi);
sq = &vi->sq[qp];
/* Free up any pending old buffers before queueing new ones. */ /* Free up any pending old buffers before queueing new ones. */
while ((xdpf_sent = virtqueue_get_buf(sq->vq, &len)) != NULL) while ((xdpf_sent = virtqueue_get_buf(sq->vq, &len)) != NULL)
...@@ -484,7 +490,6 @@ static int virtnet_xdp_xmit(struct net_device *dev, ...@@ -484,7 +490,6 @@ static int virtnet_xdp_xmit(struct net_device *dev,
struct bpf_prog *xdp_prog; struct bpf_prog *xdp_prog;
struct send_queue *sq; struct send_queue *sq;
unsigned int len; unsigned int len;
unsigned int qp;
int drops = 0; int drops = 0;
int err; int err;
int i; int i;
...@@ -492,8 +497,7 @@ static int virtnet_xdp_xmit(struct net_device *dev, ...@@ -492,8 +497,7 @@ static int virtnet_xdp_xmit(struct net_device *dev,
if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
return -EINVAL; return -EINVAL;
qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id(); sq = virtnet_xdp_sq(vi);
sq = &vi->sq[qp];
/* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this /* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this
* indicate XDP resources have been successfully allocated. * indicate XDP resources have been successfully allocated.
...@@ -1349,7 +1353,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget) ...@@ -1349,7 +1353,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
container_of(napi, struct receive_queue, napi); container_of(napi, struct receive_queue, napi);
struct virtnet_info *vi = rq->vq->vdev->priv; struct virtnet_info *vi = rq->vq->vdev->priv;
struct send_queue *sq; struct send_queue *sq;
unsigned int received, qp; unsigned int received;
unsigned int xdp_xmit = 0; unsigned int xdp_xmit = 0;
virtnet_poll_cleantx(rq); virtnet_poll_cleantx(rq);
...@@ -1364,9 +1368,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget) ...@@ -1364,9 +1368,7 @@ static int virtnet_poll(struct napi_struct *napi, int budget)
xdp_do_flush_map(); xdp_do_flush_map();
if (xdp_xmit & VIRTIO_XDP_TX) { if (xdp_xmit & VIRTIO_XDP_TX) {
qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + sq = virtnet_xdp_sq(vi);
smp_processor_id();
sq = &vi->sq[qp];
virtqueue_kick(sq->vq); virtqueue_kick(sq->vq);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment