[07/15] net/virtio: add vDPA ops to get number of queue
diff mbox series

Message ID 20190829080000.20806-8-maxime.coquelin@redhat.com
State New
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 .get_queue_num() callback.

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

Comments

Tiwei Bie Sept. 2, 2019, 6:32 a.m. UTC | #1
On Thu, Aug 29, 2019 at 09:59:52AM +0200, Maxime Coquelin wrote:
> This patch implements the vDPA .get_queue_num() callback.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/net/virtio/virtio_vdpa.c | 43 ++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)

Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>

Patch
diff mbox series

diff --git a/drivers/net/virtio/virtio_vdpa.c b/drivers/net/virtio/virtio_vdpa.c
index bbb417b94..07ff1e090 100644
--- a/drivers/net/virtio/virtio_vdpa.c
+++ b/drivers/net/virtio/virtio_vdpa.c
@@ -60,6 +60,29 @@  static struct internal_list_head internal_list =
 
 static pthread_mutex_t internal_list_lock = PTHREAD_MUTEX_INITIALIZER;
 
+static struct internal_list *
+find_internal_resource_by_did(int did)
+{
+	int found = 0;
+	struct internal_list *list;
+
+	pthread_mutex_lock(&internal_list_lock);
+
+	TAILQ_FOREACH(list, &internal_list, next) {
+		if (did == list->dev->did) {
+			found = 1;
+			break;
+		}
+	}
+
+	pthread_mutex_unlock(&internal_list_lock);
+
+	if (!found)
+		return NULL;
+
+	return list;
+}
+
 static struct internal_list *
 find_internal_resource_by_dev(struct rte_pci_device *pdev)
 {
@@ -131,7 +154,27 @@  virtio_vdpa_vfio_setup(struct virtio_vdpa_device *dev)
 	return -1;
 }
 
+static int
+virtio_vdpa_get_queue_num(int did, uint32_t *queue_num)
+{
+	struct internal_list *list;
+	struct virtio_vdpa_device *dev;
+
+	list = find_internal_resource_by_did(did);
+	if (list == NULL) {
+		DRV_LOG(ERR, "Invalid device id: %d", did);
+		return -1;
+	}
+
+	dev = list->dev;
+
+	*queue_num = dev->max_queue_pairs;
+
+	return 0;
+}
+
 static struct rte_vdpa_dev_ops virtio_vdpa_ops = {
+	.get_queue_num = virtio_vdpa_get_queue_num,
 };
 
 static inline int