[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240619161908.82348-5-hengqi@linux.alibaba.com>
Date: Thu, 20 Jun 2024 00:19:07 +0800
From: Heng Qi <hengqi@...ux.alibaba.com>
To: netdev@...r.kernel.org,
virtualization@...ts.linux.dev
Cc: Jason Wang <jasowang@...hat.com>,
"Michael S. Tsirkin" <mst@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Eugenio PĂ©rez <eperezma@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next v4 4/5] virtio_net: refactor command sending and response handling
Refactor the command handling logic by splitting
virtnet_send_command_reply into virtnet_add_command_reply
and virtnet_wait_command_response for better clarity and
subsequent use.
Signed-off-by: Heng Qi <hengqi@...ux.alibaba.com>
---
drivers/net/virtio_net.c | 53 ++++++++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 15 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4256b1eda043..807724772bcf 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2684,20 +2684,14 @@ static int virtnet_tx_resize(struct virtnet_info *vi,
return err;
}
-/*
- * Send command via the control virtqueue and check status. Commands
- * supported by the hypervisor, as indicated by feature bits, should
- * never fail unless improperly formatted.
- */
-static bool virtnet_send_command_reply(struct virtnet_info *vi,
- u8 class, u8 cmd,
- struct control_buf *ctrl,
- struct scatterlist *out,
- struct scatterlist *in)
+static bool virtnet_add_command_reply(struct virtnet_info *vi,
+ u8 class, u8 cmd,
+ struct control_buf *ctrl,
+ struct scatterlist *out,
+ struct scatterlist *in)
{
struct scatterlist *sgs[5], hdr, stat;
- u32 out_num = 0, tmp, in_num = 0;
- bool ok;
+ u32 out_num = 0, in_num = 0;
int ret;
/* Caller should know better */
@@ -2731,18 +2725,47 @@ static bool virtnet_send_command_reply(struct virtnet_info *vi,
return false;
}
- if (unlikely(!virtqueue_kick(vi->cvq)))
- goto unlock;
+ if (unlikely(!virtqueue_kick(vi->cvq))) {
+ mutex_unlock(&vi->cvq_lock);
+ return false;
+ }
+
+ return true;
+}
+
+static bool virtnet_wait_command_response(struct virtnet_info *vi,
+ struct control_buf *ctrl)
+{
+ unsigned int tmp;
+ bool ok;
wait_for_completion(&ctrl->completion);
virtqueue_get_buf(vi->cvq, &tmp);
-unlock:
ok = ctrl->status == VIRTIO_NET_OK;
mutex_unlock(&vi->cvq_lock);
return ok;
}
+/* Send command via the control virtqueue and check status. Commands
+ * supported by the hypervisor, as indicated by feature bits, should
+ * never fail unless improperly formatted.
+ */
+static bool virtnet_send_command_reply(struct virtnet_info *vi,
+ u8 class, u8 cmd,
+ struct control_buf *ctrl,
+ struct scatterlist *out,
+ struct scatterlist *in)
+{
+ bool ret;
+
+ ret = virtnet_add_command_reply(vi, class, cmd, ctrl, out, in);
+ if (!ret)
+ return ret;
+
+ return virtnet_wait_command_response(vi, ctrl);
+}
+
static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
struct scatterlist *out)
{
--
2.32.0.3.g01195cf9f
Powered by blists - more mailing lists