* [PATCH v3 03/19] net/xsc: add PCI device probe and remove
@ 2024-09-18 6:09 WanRenyong
2024-09-18 7:28 ` David Marchand
0 siblings, 1 reply; 3+ messages in thread
From: WanRenyong @ 2024-09-18 6:09 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, WanRenyong
Support the following Yunsilicon NICs to be probed:
- metaScale-200
- metaScale-200S
- metaScale-50
- metaScale-100Q
Signed-off-by: WanRenyong <wanry@yunsilicon.com>
Signed-off-by: Na Na <nana@yunsilicon.com>
---
drivers/net/xsc/xsc_defs.h | 12 ++++++
drivers/net/xsc/xsc_ethdev.c | 74 ++++++++++++++++++++++++++++++++++++
drivers/net/xsc/xsc_ethdev.h | 16 ++++++++
3 files changed, 102 insertions(+)
create mode 100644 drivers/net/xsc/xsc_defs.h
create mode 100644 drivers/net/xsc/xsc_ethdev.h
diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
new file mode 100644
index 0000000000..b4ede6eca6
--- /dev/null
+++ b/drivers/net/xsc/xsc_defs.h
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef XSC_DEFS_H_
+#define XSC_DEFS_H_
+
+#define XSC_PCI_VENDOR_ID 0x1f67
+#define XSC_PCI_DEV_ID_MS 0x1111
+
+#endif /* XSC_DEFS_H_ */
+
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 58ceaa3940..8f4d539848 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -2,7 +2,81 @@
* Copyright 2024 Yunsilicon Technology Co., Ltd.
*/
+#include <ethdev_pci.h>
+
#include "xsc_log.h"
+#include "xsc_defs.h"
+#include "xsc_ethdev.h"
+
+static int
+xsc_ethdev_init(struct rte_eth_dev *eth_dev)
+{
+ struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+ PMD_INIT_FUNC_TRACE();
+
+ priv->eth_dev = eth_dev;
+ priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+ return 0;
+}
+
+static int
+xsc_ethdev_uninit(struct rte_eth_dev *eth_dev)
+{
+ RTE_SET_USED(eth_dev);
+ PMD_INIT_FUNC_TRACE();
+
+ return 0;
+}
+
+static int
+xsc_ethdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+ struct rte_pci_device *pci_dev)
+{
+ int ret;
+
+ PMD_INIT_FUNC_TRACE();
+
+ ret = rte_eth_dev_pci_generic_probe(pci_dev,
+ sizeof(struct xsc_ethdev_priv),
+ xsc_ethdev_init);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Failed to probe ethdev: %s", pci_dev->name);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int
+xsc_ethdev_pci_remove(struct rte_pci_device *pci_dev)
+{
+ int ret;
+
+ PMD_INIT_FUNC_TRACE();
+
+ ret = rte_eth_dev_pci_generic_remove(pci_dev, xsc_ethdev_uninit);
+ if (ret) {
+ PMD_DRV_LOG(ERR, "Could not remove ethdev: %s", pci_dev->name);
+ return ret;
+ }
+
+ return 0;
+}
+
+static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
+ { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
+};
+
+static struct rte_pci_driver xsc_ethdev_pci_driver = {
+ .id_table = xsc_ethdev_pci_id_map,
+ .probe = xsc_ethdev_pci_probe,
+ .remove = xsc_ethdev_pci_remove,
+};
+
+RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver);
+RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map);
RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE);
RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE);
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
new file mode 100644
index 0000000000..75aa34dc63
--- /dev/null
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2024 Yunsilicon Technology Co., Ltd.
+ */
+
+#ifndef _XSC_ETHDEV_H_
+#define _XSC_ETHDEV_H_
+
+struct xsc_ethdev_priv {
+ struct rte_eth_dev *eth_dev;
+ struct rte_pci_device *pci_dev;
+};
+
+#define TO_XSC_ETHDEV_PRIV(dev) \
+ ((struct xsc_ethdev_priv *)(dev)->data->dev_private)
+
+#endif /* _XSC_ETHDEV_H_ */
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 03/19] net/xsc: add PCI device probe and remove
2024-09-18 6:09 [PATCH v3 03/19] net/xsc: add PCI device probe and remove WanRenyong
@ 2024-09-18 7:28 ` David Marchand
2024-09-18 7:50 ` WanRenyong
0 siblings, 1 reply; 3+ messages in thread
From: David Marchand @ 2024-09-18 7:28 UTC (permalink / raw)
To: WanRenyong; +Cc: dev, ferruh.yigit
On Wed, Sep 18, 2024 at 8:10 AM WanRenyong <wanry@yunsilicon.com> wrote:
> +static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
> + { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
You need to null terminate this array with something like:
{ .vendor_id = 0, /* sentinel */ },
Otherwise the bus pci code may read a next symbol or data present in
the .data section.
ASan caught this issue when running the unit tests:
==70261==ERROR: AddressSanitizer: global-buffer-overflow on address
0x7f8e46bf45f0 at pc 0x7f8e56be523b bp 0x7ffe2ef88ca0 sp
0x7ffe2ef88c98
READ of size 2 at 0x7f8e46bf45f0 thread T0
#0 0x7f8e56be523a in rte_pci_match
/home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:178:47
#1 0x7f8e56be523a in rte_pci_probe_one_driver
/home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:223:7
#2 0x7f8e56be523a in pci_probe_all_drivers
/home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:391:8
#3 0x7f8e56be3297 in pci_probe
/home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:418:9
#4 0x7f8e56fe9ea8 in rte_bus_probe
/home/runner/work/dpdk/dpdk/build/../lib/eal/common/eal_common_bus.c:78:9
#5 0x7f8e570580d1 in rte_eal_init
/home/runner/work/dpdk/dpdk/build/../lib/eal/linux/eal.c:1288:6
#6 0x5573a597d65d in main
/home/runner/work/dpdk/dpdk/build/../app/test/test.c:145:9
#7 0x7f8e55829d8f in __libc_start_call_main
csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#8 0x7f8e55829e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#9 0x5573a58bf114 in _start
(/home/runner/work/dpdk/dpdk/build/app/dpdk-test+0x1e9114) (BuildId:
8d4741d712c15395a67005124e1f908d96acf7ff)
172 int
173 rte_pci_match(const struct rte_pci_driver *pci_drv,
174 const struct rte_pci_device *pci_dev)
175 {
176 const struct rte_pci_id *id_table;
177
178 for (id_table = pci_drv->id_table; id_table->vendor_id !=
0;
179 id_table++) {
--
David Marchand
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 03/19] net/xsc: add PCI device probe and remove
2024-09-18 7:28 ` David Marchand
@ 2024-09-18 7:50 ` WanRenyong
0 siblings, 0 replies; 3+ messages in thread
From: WanRenyong @ 2024-09-18 7:50 UTC (permalink / raw)
To: David Marchand; +Cc: dev, ferruh.yigit
On 2024/9/18 15:28, David Marchand wrote:
> On Wed, Sep 18, 2024 at 8:10 AM WanRenyong <wanry@yunsilicon.com> wrote:
>> +static const struct rte_pci_id xsc_ethdev_pci_id_map[] = {
>> + { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) },
> You need to null terminate this array with something like:
> { .vendor_id = 0, /* sentinel */ },
>
> Otherwise the bus pci code may read a next symbol or data present in
> the .data section.
>
> ASan caught this issue when running the unit tests:
>
> ==70261==ERROR: AddressSanitizer: global-buffer-overflow on address
> 0x7f8e46bf45f0 at pc 0x7f8e56be523b bp 0x7ffe2ef88ca0 sp
> 0x7ffe2ef88c98
> READ of size 2 at 0x7f8e46bf45f0 thread T0
> #0 0x7f8e56be523a in rte_pci_match
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:178:47
> #1 0x7f8e56be523a in rte_pci_probe_one_driver
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:223:7
> #2 0x7f8e56be523a in pci_probe_all_drivers
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:391:8
> #3 0x7f8e56be3297 in pci_probe
> /home/runner/work/dpdk/dpdk/build/../drivers/bus/pci/pci_common.c:418:9
> #4 0x7f8e56fe9ea8 in rte_bus_probe
> /home/runner/work/dpdk/dpdk/build/../lib/eal/common/eal_common_bus.c:78:9
> #5 0x7f8e570580d1 in rte_eal_init
> /home/runner/work/dpdk/dpdk/build/../lib/eal/linux/eal.c:1288:6
> #6 0x5573a597d65d in main
> /home/runner/work/dpdk/dpdk/build/../app/test/test.c:145:9
> #7 0x7f8e55829d8f in __libc_start_call_main
> csu/../sysdeps/nptl/libc_start_call_main.h:58:16
> #8 0x7f8e55829e3f in __libc_start_main csu/../csu/libc-start.c:392:3
> #9 0x5573a58bf114 in _start
> (/home/runner/work/dpdk/dpdk/build/app/dpdk-test+0x1e9114) (BuildId:
> 8d4741d712c15395a67005124e1f908d96acf7ff)
>
>
> 172 int
> 173 rte_pci_match(const struct rte_pci_driver *pci_drv,
> 174 const struct rte_pci_device *pci_dev)
> 175 {
> 176 const struct rte_pci_id *id_table;
> 177
> 178 for (id_table = pci_drv->id_table; id_table->vendor_id !=
> 0;
> 179 id_table++) {
>
>
Thanks for review, will fix it in the next version.
--
Thanks,
WanRenyong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-18 7:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 6:09 [PATCH v3 03/19] net/xsc: add PCI device probe and remove WanRenyong
2024-09-18 7:28 ` David Marchand
2024-09-18 7:50 ` WanRenyong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).