diff mbox series

[v1] net/virtio: wait device ready during reset

Message ID 20210915092113.79205-1-xuemingl@nvidia.com (mailing list archive)
State Superseded, archived
Headers show
Series [v1] net/virtio: wait device ready during reset | expand

Checks

Context Check Description
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/intel-Testing fail Testing issues
ci/Intel-compilation success Compilation OK
ci/iol-x86_64-unit-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/checkpatch success coding style OK

Commit Message

Xueming(Steven) Li Sept. 15, 2021, 9:21 a.m. UTC
According to virtio spec, the device MUST reset when 0 is written to
device_status, and present 0 in device_status once reset is done.

This patch waits status value to be 0 during reset operation, if
timeout in 3 seconds, log and continue.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Cc: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 drivers/net/virtio/virtio.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Andrew Rybchenko Sept. 15, 2021, 9:27 a.m. UTC | #1
On 9/15/21 12:21 PM, Xueming Li wrote:
> According to virtio spec, the device MUST reset when 0 is written to
> device_status, and present 0 in device_status once reset is done.
> 
> This patch waits status value to be 0 during reset operation, if
> timeout in 3 seconds, log and continue.

I have no strong opinion on timeout.

> 
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> Cc: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  drivers/net/virtio/virtio.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio.c b/drivers/net/virtio/virtio.c
> index 7e1e77797f..f865b27b65 100644
> --- a/drivers/net/virtio/virtio.c
> +++ b/drivers/net/virtio/virtio.c
> @@ -3,7 +3,10 @@
>   * Copyright(c) 2020 Red Hat, Inc.
>   */
>  
> +#include <unistd.h>
> +
>  #include "virtio.h"
> +#include "virtio_logs.h"
>  
>  uint64_t
>  virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
> @@ -38,9 +41,17 @@ virtio_write_dev_config(struct virtio_hw *hw, size_t offset,
>  void
>  virtio_reset(struct virtio_hw *hw)
>  {
> +	uint32_t retry = 0;
> +
>  	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
> -	/* flush status write */
> -	VIRTIO_OPS(hw)->get_status(hw);
> +	/* Flush status write and wait device ready max 3 seconds. */
> +	while (VIRTIO_OPS(hw)->get_status(hw) != VIRTIO_CONFIG_STATUS_RESET) {
> +		if (retry++ > 3000) {
> +			PMD_INIT_LOG(WARNING, "device reset timeout");

I think it would be very useful to log ethdev port ID here.

> +			break;
> +		}
> +		usleep(1000L);
> +	}
>  }
>  
>  void
>
Xueming(Steven) Li Sept. 15, 2021, 10:14 a.m. UTC | #2
On Wed, 2021-09-15 at 12:27 +0300, Andrew Rybchenko wrote:
> On 9/15/21 12:21 PM, Xueming Li wrote:
> > According to virtio spec, the device MUST reset when 0 is written to
> > device_status, and present 0 in device_status once reset is done.
> > 
> > This patch waits status value to be 0 during reset operation, if
> > timeout in 3 seconds, log and continue.
> 
> I have no strong opinion on timeout.
> 
> > 
> > Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> > Cc: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> > ---
> >  drivers/net/virtio/virtio.c | 15 +++++++++++++--
> >  1 file changed, 13 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/virtio/virtio.c b/drivers/net/virtio/virtio.c
> > index 7e1e77797f..f865b27b65 100644
> > --- a/drivers/net/virtio/virtio.c
> > +++ b/drivers/net/virtio/virtio.c
> > @@ -3,7 +3,10 @@
> >   * Copyright(c) 2020 Red Hat, Inc.
> >   */
> >  
> > +#include <unistd.h>
> > +
> >  #include "virtio.h"
> > +#include "virtio_logs.h"
> >  
> >  uint64_t
> >  virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
> > @@ -38,9 +41,17 @@ virtio_write_dev_config(struct virtio_hw *hw, size_t offset,
> >  void
> >  virtio_reset(struct virtio_hw *hw)
> >  {
> > +	uint32_t retry = 0;
> > +
> >  	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
> > -	/* flush status write */
> > -	VIRTIO_OPS(hw)->get_status(hw);
> > +	/* Flush status write and wait device ready max 3 seconds. */
> > +	while (VIRTIO_OPS(hw)->get_status(hw) != VIRTIO_CONFIG_STATUS_RESET) {
> > +		if (retry++ > 3000) {
> > +			PMD_INIT_LOG(WARNING, "device reset timeout");
> 
> I think it would be very useful to log ethdev port ID here.

Good suggesiton, v2 sent.

> 
> > +			break;
> > +		}
> > +		usleep(1000L);
> > +	}
> >  }
> >  
> >  void
> > 
>
diff mbox series

Patch

diff --git a/drivers/net/virtio/virtio.c b/drivers/net/virtio/virtio.c
index 7e1e77797f..f865b27b65 100644
--- a/drivers/net/virtio/virtio.c
+++ b/drivers/net/virtio/virtio.c
@@ -3,7 +3,10 @@ 
  * Copyright(c) 2020 Red Hat, Inc.
  */
 
+#include <unistd.h>
+
 #include "virtio.h"
+#include "virtio_logs.h"
 
 uint64_t
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
@@ -38,9 +41,17 @@  virtio_write_dev_config(struct virtio_hw *hw, size_t offset,
 void
 virtio_reset(struct virtio_hw *hw)
 {
+	uint32_t retry = 0;
+
 	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
-	/* flush status write */
-	VIRTIO_OPS(hw)->get_status(hw);
+	/* Flush status write and wait device ready max 3 seconds. */
+	while (VIRTIO_OPS(hw)->get_status(hw) != VIRTIO_CONFIG_STATUS_RESET) {
+		if (retry++ > 3000) {
+			PMD_INIT_LOG(WARNING, "device reset timeout");
+			break;
+		}
+		usleep(1000L);
+	}
 }
 
 void