[v5,03/32] net/sssnic: support probe and remove

Message ID 20230904045658.238185-4-wanry@3snic.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series Introduce sssnic PMD for 3SNIC's 9x0 serials Ethernet adapters |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Renyong Wan Sept. 4, 2023, 4:56 a.m. UTC
  From: Renyong Wan <wanry@3snic.com>

Register device ID for 3SNIC ethernet adapter to support
PCI ethdev probe and remove.

Signed-off-by: Steven Song <steven.song@3snic.com>
Signed-off-by: Renyong Wan <wanry@3snic.com>
---
 drivers/net/sssnic/base/sssnic_hw.h | 11 +++++++++
 drivers/net/sssnic/sssnic_ethdev.c  | 37 +++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 4 deletions(-)
 create mode 100644 drivers/net/sssnic/base/sssnic_hw.h
  

Comments

Stephen Hemminger Sept. 18, 2023, 4:08 p.m. UTC | #1
On Mon, 4 Sep 2023 12:56:29 +0800
<wanry@3snic.com> wrote:

> +static int
> +sssnic_ethdev_init(struct rte_eth_dev *ethdev)
> +{
> +	RTE_SET_USED(ethdev);
> +	PMD_INIT_FUNC_TRACE();
> +
> +	return -EINVAL;
> +}


Since device does not support secondary process, should
check and return error here.
  
Renyong Wan Sept. 19, 2023, 2 a.m. UTC | #2
Hello Stephen,

This patch is just a minimum probe frame, it does nothing and always 
return error. The error check will apear in the subsequent patch([PATCH 
v5 04/32]), in that patch, hardware base is initialized, so secondary 
process check is added logically.

Thanks.

On 2023/9/19 0:08, Stephen Hemminger wrote:
> On Mon, 4 Sep 2023 12:56:29 +0800
> <wanry@3snic.com> wrote:
>
>> +static int
>> +sssnic_ethdev_init(struct rte_eth_dev *ethdev)
>> +{
>> +	RTE_SET_USED(ethdev);
>> +	PMD_INIT_FUNC_TRACE();
>> +
>> +	return -EINVAL;
>> +}
>
> Since device does not support secondary process, should
> check and return error here.
  

Patch

diff --git a/drivers/net/sssnic/base/sssnic_hw.h b/drivers/net/sssnic/base/sssnic_hw.h
new file mode 100644
index 0000000000..db916b1977
--- /dev/null
+++ b/drivers/net/sssnic/base/sssnic_hw.h
@@ -0,0 +1,11 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2018-2022 Shenzhen 3SNIC Information Technology Co., Ltd.
+ */
+
+#ifndef _SSSNIC_HW_H_
+#define _SSSNIC_HW_H_
+
+#define SSSNIC_PCI_VENDOR_ID 0x1F3F
+#define SSSNIC_DEVICE_ID_STD 0x9020
+
+#endif /* _SSSNIC_HW_H_ */
diff --git a/drivers/net/sssnic/sssnic_ethdev.c b/drivers/net/sssnic/sssnic_ethdev.c
index 0f1017af9d..4f8b5c2684 100644
--- a/drivers/net/sssnic/sssnic_ethdev.c
+++ b/drivers/net/sssnic/sssnic_ethdev.c
@@ -6,25 +6,54 @@ 
 #include <ethdev_pci.h>
 
 #include "sssnic_log.h"
+#include "base/sssnic_hw.h"
+
+static int
+sssnic_ethdev_init(struct rte_eth_dev *ethdev)
+{
+	RTE_SET_USED(ethdev);
+	PMD_INIT_FUNC_TRACE();
+
+	return -EINVAL;
+}
+
+static int
+sssnic_ethdev_uninit(struct rte_eth_dev *ethdev)
+{
+	RTE_SET_USED(ethdev);
+	PMD_INIT_FUNC_TRACE();
+
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	return -EINVAL;
+}
 
 static int
 sssnic_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
 {
 	RTE_SET_USED(pci_drv);
-	RTE_SET_USED(pci_dev);
 	PMD_INIT_FUNC_TRACE();
-	return -EINVAL;
+
+	return rte_eth_dev_pci_generic_probe(pci_dev, 0, sssnic_ethdev_init);
 }
 
 static int
 sssnic_pci_remove(struct rte_pci_device *pci_dev)
 {
-	RTE_SET_USED(pci_dev);
 	PMD_INIT_FUNC_TRACE();
-	return -EINVAL;
+
+	return rte_eth_dev_pci_generic_remove(pci_dev, sssnic_ethdev_uninit);
 }
 
+static const struct rte_pci_id sssnic_pci_id_map[] = {
+	{ RTE_PCI_DEVICE(SSSNIC_PCI_VENDOR_ID, SSSNIC_DEVICE_ID_STD) },
+	{ .vendor_id = 0 },
+};
+
 static struct rte_pci_driver sssnic_pmd = {
+	.id_table = sssnic_pci_id_map,
+	.drv_flags = RTE_PCI_DRV_NEED_MAPPING,
 	.probe = sssnic_pci_probe,
 	.remove = sssnic_pci_remove,
 };