virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Heng Qi <hengqi@linux.alibaba.com>
To: netdev@vger.kernel.org, virtualization@lists.linux.dev
Cc: "Jason Wang" <jasowang@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>
Subject: [PATCH net-next v4 4/5] virtio_net: refactor command sending and response handling
Date: Thu, 20 Jun 2024 00:19:07 +0800	[thread overview]
Message-ID: <20240619161908.82348-5-hengqi@linux.alibaba.com> (raw)
In-Reply-To: <20240619161908.82348-1-hengqi@linux.alibaba.com>

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@linux.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


  parent reply	other threads:[~2024-06-19 16:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 16:19 [PATCH net-next v4 0/5] virtio_net: enable the irq for ctrlq Heng Qi
2024-06-19 16:19 ` [PATCH net-next v4 1/5] virtio_net: passing control_buf explicitly Heng Qi
2024-06-19 16:19 ` [PATCH net-next v4 2/5] virtio_net: enable irq for the control vq Heng Qi
2024-06-19 21:19   ` Michael S. Tsirkin
2024-06-20  7:29     ` Heng Qi
2024-06-20  8:21       ` Jason Wang
2024-06-20  8:26         ` Jason Wang
2024-06-20  9:53           ` Heng Qi
2024-06-20 10:10             ` Michael S. Tsirkin
2024-06-20 10:11               ` Michael S. Tsirkin
2024-06-20 10:31                 ` Heng Qi
2024-06-26  7:52                   ` Jiri Pirko
2024-06-26  8:08                     ` Michael S. Tsirkin
2024-06-26  8:43                       ` Jiri Pirko
2024-06-26  9:58                         ` Michael S. Tsirkin
2024-06-26 11:51                           ` Jiri Pirko
2024-07-08 11:40                             ` Jiri Pirko
2024-07-08 12:19                               ` Heng Qi
2024-06-21  7:41                 ` Xuan Zhuo
2024-06-21 11:46                   ` Michael S. Tsirkin
2024-06-25  1:27                 ` Jason Wang
2024-06-25  7:14                   ` Michael S. Tsirkin
2024-06-20  8:32       ` Michael S. Tsirkin
2024-06-20  8:37         ` Jason Wang
2024-06-20  9:38         ` Heng Qi
2024-06-20 10:07           ` Michael S. Tsirkin
2024-06-24 11:30   ` Michael S. Tsirkin
2024-06-19 16:19 ` [PATCH net-next v4 3/5] virtio_net: change the command token to completion Heng Qi
2024-06-19 16:19 ` Heng Qi [this message]
2024-06-19 16:19 ` [PATCH net-next v4 5/5] virtio_net: improve dim command request efficiency Heng Qi
2024-06-20  6:40   ` kernel test robot
2024-06-19 21:16 ` [PATCH net-next v4 0/5] virtio_net: enable the irq for ctrlq Michael S. Tsirkin
2024-06-20  7:16   ` Heng Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240619161908.82348-5-hengqi@linux.alibaba.com \
    --to=hengqi@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).