[v4,3/6] net/ngbe: support probe and remove

Message ID 20210406093048.2923172-4-jiawenwu@trustnetic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series net: ngbe PMD |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jiawen Wu April 6, 2021, 9:30 a.m. UTC
  Add basic PCIe ethdev probe and remove.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 doc/guides/nics/features/ngbe.ini |  1 +
 drivers/net/ngbe/ngbe_ethdev.c    | 77 +++++++++++++++++++++++++++++--
 drivers/net/ngbe/ngbe_ethdev.h    | 10 ++++
 3 files changed, 85 insertions(+), 3 deletions(-)
  

Comments

Ferruh Yigit April 9, 2021, 2:40 p.m. UTC | #1
On 4/6/2021 10:30 AM, Jiawen Wu wrote:
> Add basic PCIe ethdev probe and remove.
> 
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>

<...>

> --- a/drivers/net/ngbe/ngbe_ethdev.c
> +++ b/drivers/net/ngbe/ngbe_ethdev.c
> @@ -1,10 +1,12 @@
> - /* SPDX-License-Identifier: BSD-3-Clause
> -  * Copyright(c) 2018-2020
> -  */
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018-2020
> + */

Can you please fix this where it is introduced at first place?

<...>

> +static int
> +eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
> +		struct rte_pci_device *pci_dev)
> +{
> +	struct rte_eth_dev *pf_ethdev;
> +	struct rte_eth_devargs eth_da;
> +	int retval;
> +
> +	if (pci_dev->device.devargs) {
> +		retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
> +				&eth_da);
> +		if (retval)
> +			return retval;
> +	} else {
> +		memset(&eth_da, 0, sizeof(eth_da));
> +	}
> +
> +	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
> +			sizeof(struct ngbe_adapter),
> +			eth_dev_pci_specific_init, pci_dev,
> +			eth_ngbe_dev_init, NULL);
> +
> +	if (retval || eth_da.nb_representor_ports < 1)
> +		return retval;

no need to check the 'nb_representor_ports' here, the driver does not support 
the port anyway, it can return immediately.

Similarly 'rte_eth_devargs_parse()' call above can be removed, for same reason.

When port representor support added to driver, following check also may be added 
since new representator types are added recently.

         if (eth_da.type != RTE_ETH_REPRESENTOR_VF)
               return -ENOTSUP;

> +
> +	pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
> +	if (pf_ethdev == NULL)
> +		return -ENODEV;
> +

Also above part can be removed completely, pf_ethdev is get to use in the 
existance of the port representor, no need to get it now.

> +	return 0;
> +}
> +
> +static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
> +{
> +	struct rte_eth_dev *ethdev;
> +
> +	ethdev = rte_eth_dev_allocated(pci_dev->device.name);
> +	if (!ethdev)
> +		return -ENODEV;

This is not an error case, you can return success (0) here.

Same applies to txgbe too.
  

Patch

diff --git a/doc/guides/nics/features/ngbe.ini b/doc/guides/nics/features/ngbe.ini
index a7a524def..977286ac0 100644
--- a/doc/guides/nics/features/ngbe.ini
+++ b/doc/guides/nics/features/ngbe.ini
@@ -4,6 +4,7 @@ 
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Multiprocess aware   = Y
 Linux                = Y
 ARMv8                = Y
 x86-32               = Y
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index da951b6ef..d938fd68a 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -1,10 +1,12 @@ 
- /* SPDX-License-Identifier: BSD-3-Clause
-  * Copyright(c) 2018-2020
-  */
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2020
+ */
 
+#include <rte_common.h>
 #include <ethdev_pci.h>
 
 #include <base/ngbe_devids.h>
+#include "ngbe_ethdev.h"
 
 /*
  * The set of PCI devices this driver supports
@@ -25,10 +27,79 @@  static const struct rte_pci_id pci_id_ngbe_map[] = {
 	{ .vendor_id = 0, /* sentinel */ },
 };
 
+static int
+eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
+{
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	rte_eth_copy_pci_info(eth_dev, pci_dev);
+
+	return 0;
+}
+
+static int
+eth_ngbe_dev_uninit(struct rte_eth_dev *eth_dev)
+{
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	RTE_SET_USED(eth_dev);
+
+	return 0;
+}
+
+static int
+eth_ngbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+		struct rte_pci_device *pci_dev)
+{
+	struct rte_eth_dev *pf_ethdev;
+	struct rte_eth_devargs eth_da;
+	int retval;
+
+	if (pci_dev->device.devargs) {
+		retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
+				&eth_da);
+		if (retval)
+			return retval;
+	} else {
+		memset(&eth_da, 0, sizeof(eth_da));
+	}
+
+	retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
+			sizeof(struct ngbe_adapter),
+			eth_dev_pci_specific_init, pci_dev,
+			eth_ngbe_dev_init, NULL);
+
+	if (retval || eth_da.nb_representor_ports < 1)
+		return retval;
+
+	pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
+	if (pf_ethdev == NULL)
+		return -ENODEV;
+
+	return 0;
+}
+
+static int eth_ngbe_pci_remove(struct rte_pci_device *pci_dev)
+{
+	struct rte_eth_dev *ethdev;
+
+	ethdev = rte_eth_dev_allocated(pci_dev->device.name);
+	if (!ethdev)
+		return -ENODEV;
+
+	return rte_eth_dev_destroy(ethdev, eth_ngbe_dev_uninit);
+}
+
 static struct rte_pci_driver rte_ngbe_pmd = {
 	.id_table = pci_id_ngbe_map,
 	.drv_flags = RTE_PCI_DRV_NEED_MAPPING |
 		     RTE_PCI_DRV_INTR_LSC,
+	.probe = eth_ngbe_pci_probe,
+	.remove = eth_ngbe_pci_remove,
 };
 
 RTE_PMD_REGISTER_PCI(net_ngbe, rte_ngbe_pmd);
diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h
index 20f37e9d4..8dab39faf 100644
--- a/drivers/net/ngbe/ngbe_ethdev.h
+++ b/drivers/net/ngbe/ngbe_ethdev.h
@@ -2,3 +2,13 @@ 
  * Copyright(c) 2018-2020
  */
 
+#ifndef _NGBE_ETHDEV_H_
+#define _NGBE_ETHDEV_H_
+
+/*
+ * Structure to store private data for each driver instance (for each port).
+ */
+struct ngbe_adapter {
+};
+
+#endif /* _NGBE_ETHDEV_H_ */