[v4,1/4] net/virtio: refactor devargs parsing
diff mbox series

Message ID 20200225072813.9385-2-i.dyukov@samsung.com
State Superseded
Delegated to: Maxime Coquelin
Headers show
Series
  • [v4,1/4] net/virtio: refactor devargs parsing
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

Ivan Dyukov Feb. 25, 2020, 7:28 a.m. UTC
refactor vdpa specific devargs parsing to more generic way

Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
---
 drivers/net/virtio/virtio_ethdev.c | 35 +++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 10 deletions(-)

Comments

Ye Xiaolong Feb. 26, 2020, 7:16 a.m. UTC | #1
On 02/25, Ivan Dyukov wrote:
>refactor vdpa specific devargs parsing to more generic way
>
>Signed-off-by: Ivan Dyukov <i.dyukov@samsung.com>
>---
> drivers/net/virtio/virtio_ethdev.c | 35 +++++++++++++++++++++---------
> 1 file changed, 25 insertions(+), 10 deletions(-)
>
>diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
>index 044eb10a7..22323d9a5 100644
>--- a/drivers/net/virtio/virtio_ethdev.c
>+++ b/drivers/net/virtio/virtio_ethdev.c
>@@ -1955,16 +1955,18 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
> }
> 
> static int vdpa_check_handler(__rte_unused const char *key,
>-		const char *value, __rte_unused void *opaque)
>+		const char *value, void *ret_val)
> {
>-	if (strcmp(value, "1"))
>-		return -1;
>+	if (strcmp(value, "1") == 0)
>+		*(int *)ret_val = 1;
>+	else
>+		*(int *)ret_val = 0;
> 
> 	return 0;
> }
> 
> static int
>-vdpa_mode_selected(struct rte_devargs *devargs)
>+virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa)
> {
> 	struct rte_kvargs *kvlist;
> 	const char *key = "vdpa";
>@@ -1980,12 +1982,16 @@ vdpa_mode_selected(struct rte_devargs *devargs)
> 	if (!rte_kvargs_count(kvlist, key))
> 		goto exit;
> 
>-	/* vdpa mode selected when there's a key-value pair: vdpa=1 */
>-	if (rte_kvargs_process(kvlist, key,
>-				vdpa_check_handler, NULL) < 0) {
>-		goto exit;
>+	if (vdpa) {
>+		/* vdpa mode selected when there's a key-value pair:
>+		 * vdpa=1
>+		 */
>+		ret = rte_kvargs_process(kvlist, key,
>+				vdpa_check_handler, vdpa);
>+		if (ret  < 0)

Double space between 'ret' and '<'.

>+			goto exit;
> 	}
>-	ret = 1;
>+
> 
> exit:
> 	rte_kvargs_free(kvlist);
>@@ -1995,8 +2001,17 @@ vdpa_mode_selected(struct rte_devargs *devargs)
> static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
> 	struct rte_pci_device *pci_dev)
> {
>+	int vdpa = 0;
>+	int ret = 0;
>+
>+	ret = virtio_dev_devargs_parse(pci_dev->device.devargs, &vdpa);
>+	if (ret < 0) {
>+		PMD_DRV_LOG(ERR,
>+			"devargs parsing is failed");

I think PMD_INIG_LOG should be used, and there is no need to split into 2 lines
as it won't exceed 80 chars.

Thanks,
Xiaolong

>+		return ret;
>+	}
> 	/* virtio pmd skips probe if device needs to work in vdpa mode */
>-	if (vdpa_mode_selected(pci_dev->device.devargs))
>+	if (vdpa == 1)
> 		return 1;
> 
> 	return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct virtio_hw),
>-- 
>2.17.1
>

Patch
diff mbox series

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 044eb10a7..22323d9a5 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1955,16 +1955,18 @@  eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 }
 
 static int vdpa_check_handler(__rte_unused const char *key,
-		const char *value, __rte_unused void *opaque)
+		const char *value, void *ret_val)
 {
-	if (strcmp(value, "1"))
-		return -1;
+	if (strcmp(value, "1") == 0)
+		*(int *)ret_val = 1;
+	else
+		*(int *)ret_val = 0;
 
 	return 0;
 }
 
 static int
-vdpa_mode_selected(struct rte_devargs *devargs)
+virtio_dev_devargs_parse(struct rte_devargs *devargs, int *vdpa)
 {
 	struct rte_kvargs *kvlist;
 	const char *key = "vdpa";
@@ -1980,12 +1982,16 @@  vdpa_mode_selected(struct rte_devargs *devargs)
 	if (!rte_kvargs_count(kvlist, key))
 		goto exit;
 
-	/* vdpa mode selected when there's a key-value pair: vdpa=1 */
-	if (rte_kvargs_process(kvlist, key,
-				vdpa_check_handler, NULL) < 0) {
-		goto exit;
+	if (vdpa) {
+		/* vdpa mode selected when there's a key-value pair:
+		 * vdpa=1
+		 */
+		ret = rte_kvargs_process(kvlist, key,
+				vdpa_check_handler, vdpa);
+		if (ret  < 0)
+			goto exit;
 	}
-	ret = 1;
+
 
 exit:
 	rte_kvargs_free(kvlist);
@@ -1995,8 +2001,17 @@  vdpa_mode_selected(struct rte_devargs *devargs)
 static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct rte_pci_device *pci_dev)
 {
+	int vdpa = 0;
+	int ret = 0;
+
+	ret = virtio_dev_devargs_parse(pci_dev->device.devargs, &vdpa);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR,
+			"devargs parsing is failed");
+		return ret;
+	}
 	/* virtio pmd skips probe if device needs to work in vdpa mode */
-	if (vdpa_mode_selected(pci_dev->device.devargs))
+	if (vdpa == 1)
 		return 1;
 
 	return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct virtio_hw),