[11/15] net/virtio: add vDPA op to stop and close the device
diff mbox series

Message ID 20190829080000.20806-12-maxime.coquelin@redhat.com
State Deferred
Delegated to: Maxime Coquelin
Headers show
Series
  • Introduce Virtio vDPA driver
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Maxime Coquelin Aug. 29, 2019, 7:59 a.m. UTC
This patch implements the vDPA .dev_close() callback.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/net/virtio/virtio_vdpa.c | 52 ++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

Comments

Tiwei Bie Sept. 2, 2019, 7:07 a.m. UTC | #1
On Thu, Aug 29, 2019 at 09:59:56AM +0200, Maxime Coquelin wrote:
> This patch implements the vDPA .dev_close() callback.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/net/virtio/virtio_vdpa.c | 52 ++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
> index 13b4dd07d..691844906 100644
> --- a/drivers/net/virtio/virtio_vdpa.c
> +++ b/drivers/net/virtio/virtio_vdpa.c
> @@ -436,6 +436,33 @@ virtio_vdpa_start(struct virtio_vdpa_device *dev)
>  	return ret;
>  }
>  
> +static void
> +virtio_vdpa_stop(struct virtio_vdpa_device *dev)
> +{
> +	struct virtio_hw *hw = &dev->hw;
> +	uint32_t i, nr_vring;
> +	int vid = dev->vid;
> +	struct rte_vhost_vring vr;
> +	uint16_t last_used_idx, last_avail_idx;
> +
> +	nr_vring = rte_vhost_get_vring_num(vid);
> +
> +	vtpci_reset(hw);
> +
> +	for (i = 0; i < nr_vring; i++) {
> +		rte_vhost_get_vhost_vring(vid, i, &vr);
> +
> +		last_used_idx = vr.used->idx;
> +		last_avail_idx = vr.avail->idx;

This only works in split ring.

Regards,
Tiwei

> +
> +		rte_vhost_set_vring_base(vid, i, last_avail_idx,
> +				last_used_idx);
> +	}
> +
> +	rte_free(dev->vqs);
> +	dev->vqs = NULL;
> +}
> +
Maxime Coquelin Sept. 3, 2019, 7:30 a.m. UTC | #2
On 9/2/19 9:07 AM, Tiwei Bie wrote:
> On Thu, Aug 29, 2019 at 09:59:56AM +0200, Maxime Coquelin wrote:
>> This patch implements the vDPA .dev_close() callback.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>  drivers/net/virtio/virtio_vdpa.c | 52 ++++++++++++++++++++++++++++++++
>>  1 file changed, 52 insertions(+)
>>
>> diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
>> index 13b4dd07d..691844906 100644
>> --- a/drivers/net/virtio/virtio_vdpa.c
>> +++ b/drivers/net/virtio/virtio_vdpa.c
>> @@ -436,6 +436,33 @@ virtio_vdpa_start(struct virtio_vdpa_device *dev)
>>  	return ret;
>>  }
>>  
>> +static void
>> +virtio_vdpa_stop(struct virtio_vdpa_device *dev)
>> +{
>> +	struct virtio_hw *hw = &dev->hw;
>> +	uint32_t i, nr_vring;
>> +	int vid = dev->vid;
>> +	struct rte_vhost_vring vr;
>> +	uint16_t last_used_idx, last_avail_idx;
>> +
>> +	nr_vring = rte_vhost_get_vring_num(vid);
>> +
>> +	vtpci_reset(hw);
>> +
>> +	for (i = 0; i < nr_vring; i++) {
>> +		rte_vhost_get_vhost_vring(vid, i, &vr);
>> +
>> +		last_used_idx = vr.used->idx;
>> +		last_avail_idx = vr.avail->idx;
> 
> This only works in split ring.

Right, thanks for spotting it.
For the v2, I'll try to fix it and test it with Jason's Qemu series
adding packed ring support.

> Regards,
> Tiwei
> 
>> +
>> +		rte_vhost_set_vring_base(vid, i, last_avail_idx,
>> +				last_used_idx);
>> +	}
>> +
>> +	rte_free(dev->vqs);
>> +	dev->vqs = NULL;
>> +}
>> +

Patch
diff mbox series

diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
index 13b4dd07d..691844906 100644
--- a/drivers/net/virtio/virtio_vdpa.c
+++ b/drivers/net/virtio/virtio_vdpa.c
@@ -436,6 +436,33 @@  virtio_vdpa_start(struct virtio_vdpa_device *dev)
 	return ret;
 }
 
+static void
+virtio_vdpa_stop(struct virtio_vdpa_device *dev)
+{
+	struct virtio_hw *hw = &dev->hw;
+	uint32_t i, nr_vring;
+	int vid = dev->vid;
+	struct rte_vhost_vring vr;
+	uint16_t last_used_idx, last_avail_idx;
+
+	nr_vring = rte_vhost_get_vring_num(vid);
+
+	vtpci_reset(hw);
+
+	for (i = 0; i < nr_vring; i++) {
+		rte_vhost_get_vhost_vring(vid, i, &vr);
+
+		last_used_idx = vr.used->idx;
+		last_avail_idx = vr.avail->idx;
+
+		rte_vhost_set_vring_base(vid, i, last_avail_idx,
+				last_used_idx);
+	}
+
+	rte_free(dev->vqs);
+	dev->vqs = NULL;
+}
+
 static int
 virtio_vdpa_dev_config(int vid)
 {
@@ -470,11 +497,36 @@  virtio_vdpa_dev_config(int vid)
 	return ret;
 }
 
+static int
+virtio_vdpa_dev_close(int vid)
+{
+	int did;
+	struct internal_list *list;
+	struct virtio_vdpa_device *dev;
+
+	did = rte_vhost_get_vdpa_device_id(vid);
+	list = find_internal_resource_by_did(did);
+	if (list == NULL) {
+		DRV_LOG(ERR, "Invalid device id: %d", did);
+		return -1;
+	}
+
+	dev = list->dev;
+
+	rte_spinlock_lock(&dev->lock);
+	virtio_vdpa_stop(dev);
+	virtio_vdpa_dma_map(dev, 0);
+	rte_spinlock_unlock(&dev->lock);
+
+	return 0;
+}
+
 static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
 	.get_queue_num = virtio_vdpa_get_queue_num,
 	.get_features = virtio_vdpa_get_features,
 	.get_protocol_features = virtio_vdpa_get_protocol_features,
 	.dev_conf = virtio_vdpa_dev_config,
+	.dev_close = virtio_vdpa_dev_close,
 };
 
 static inline int