From patchwork Wed Sep 11 02:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143918 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 465634595A; Wed, 11 Sep 2024 04:08:22 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 285E642ECE; Wed, 11 Sep 2024 04:08:11 +0200 (CEST) Received: from lf-2-40.ptr.blmpb.com (lf-2-40.ptr.blmpb.com [101.36.218.40]) by mails.dpdk.org (Postfix) with ESMTP id B0938402AB for ; Wed, 11 Sep 2024 04:08:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020473; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=xgrU0Op8yskBlqC1KmziZeL3HcthrkcnU3aZmxg9zLo=; b=d1v7HCo/YlWPE/7Yr9Ll7j2ye2FWpIeAg26OZC1Flviop6qktV1/7i0JsKHkQItDlNezbL zrtqGM0raVdnX//GVniPxN7hLUnZ3PsNKf2VANMr3/ETIgtco3xNO0QMHA3TQ1dUrwAOFw aPtGu2unmYPMcNwwvUrBUYTAvkcDjg7go9h3buocv+fsMQ1ISHsCKHxe9+Y1SkG4ylEWyr hioKyA3RLnCJCucG/Wows31xIWxQjjuD2+U4hLyA3Id3dmis0ZDBaJe0v4xTazNgvcwDxT IikLs0RmxT59fJ/KkW94+1pGHwUC5p+IEGeDwc91hBm9Beye4GEw87MEXEc9MA== To: Subject: [PATCH v2 01/19] net/xsc: add doc and minimum build framework X-Original-From: WanRenyong Cc: , , "WanRenyong" Date: Wed, 11 Sep 2024 10:07:22 +0800 X-Mailer: git-send-email 2.25.1 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:51 +0800 X-Lms-Return-Path: From: "WanRenyong" Message-Id: <20240911020740.3950704-2-wanry@yunsilicon.com> Mime-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add minimum PMD code, doc and build infrastructure for xsc. Signed-off-by: WanRenyong --- v2: * fix compilation error --- .mailmap | 4 ++++ MAINTAINERS | 9 +++++++++ doc/guides/nics/features/xsc.ini | 9 +++++++++ doc/guides/nics/index.rst | 1 + doc/guides/nics/xsc.rst | 31 +++++++++++++++++++++++++++++++ drivers/net/meson.build | 1 + drivers/net/xsc/meson.build | 13 +++++++++++++ drivers/net/xsc/xsc_ethdev.c | 3 +++ 8 files changed, 71 insertions(+) create mode 100644 doc/guides/nics/features/xsc.ini create mode 100644 doc/guides/nics/xsc.rst create mode 100644 drivers/net/xsc/meson.build create mode 100644 drivers/net/xsc/xsc_ethdev.c diff --git a/.mailmap b/.mailmap index 09fa253e12..d09ed30e16 100644 --- a/.mailmap +++ b/.mailmap @@ -1034,6 +1034,7 @@ Nagadheeraj Rottela Naga Harish K S V Naga Suresh Somarowthu Nalla Pradeep +Na Na Na Na Nan Chen Nannan Lu @@ -1268,6 +1269,7 @@ Ronak Doshi Ron Beider Ronghua Zhang RongQiang Xie +Rong Qian RongQing Li Rongwei Liu Rory Sexton @@ -1586,6 +1588,7 @@ Waldemar Dworakowski Walter Heymans Wang Sheng-Hui Wangyu (Eric) +WanRenyong Waterman Cao Wathsala Vithanage Weichun Chen @@ -1638,6 +1641,7 @@ Xiaonan Zhang Xiao Wang Xiaoxiao Zeng Xiaoxin Peng +Xiaoxiong Zhang Xiaoyu Min Xiaoyun Li Xiaoyun Wang diff --git a/MAINTAINERS b/MAINTAINERS index c5a703b5c0..f87d802b24 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -994,6 +994,15 @@ F: drivers/net/txgbe/ F: doc/guides/nics/txgbe.rst F: doc/guides/nics/features/txgbe.ini +Yunsilicon xsc +M: WanRenyong +M: Na Na +M: Rong Qian +M: Xiaoxiong Zhang +F: drivers/net/xsc/ +F: doc/guides/nics/xsc.rst +F: doc/guides/nics/features/xsc.ini + VMware vmxnet3 M: Jochen Behrens F: drivers/net/vmxnet3/ diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini new file mode 100644 index 0000000000..b5c44ce535 --- /dev/null +++ b/doc/guides/nics/features/xsc.ini @@ -0,0 +1,9 @@ +; +; Supported features of the 'xsc' network poll mode driver. +; +; Refer to default.ini for the full list of available PMD features. +; +[Features] +Linux = Y +ARMv8 = Y +x86-64 = Y diff --git a/doc/guides/nics/index.rst b/doc/guides/nics/index.rst index c14bc7988a..9781097a21 100644 --- a/doc/guides/nics/index.rst +++ b/doc/guides/nics/index.rst @@ -69,3 +69,4 @@ Network Interface Controller Drivers vhost virtio vmxnet3 + xsc diff --git a/doc/guides/nics/xsc.rst b/doc/guides/nics/xsc.rst new file mode 100644 index 0000000000..b7643b3ce2 --- /dev/null +++ b/doc/guides/nics/xsc.rst @@ -0,0 +1,31 @@ +.. SPDX-License-Identifier: BSD-3-Clause + Copyright 2024 Yunsilicon Technology Co., Ltd + +XSC Poll Mode Driver +====================== + +The xsc PMD (**librte_net_xsc**) provides poll mode driver support for +10/25/50/100/200 Gbps Yunsilicon metaScale Series Network Adapters. + +Supported NICs +-------------- + +The following Yunsilicon device models are supported by the same xsc driver: + + - metaScale-200S + - metaScale-200 + - metaScale-100Q + - metaScale-50 + +Prerequisites +-------------- + +- Follow the DPDK :doc:`../linux_gsg/index` to setup the basic DPDK environment. + +- Learning about Yunsilicon metaScale Series NICs using + ``_. + +Limitations or Known issues +--------------------------- +32bit ARCHs have not been tested and may not be supported. +Windows and BSD are not supported yet. diff --git a/drivers/net/meson.build b/drivers/net/meson.build index fb6d34b782..67fbe81861 100644 --- a/drivers/net/meson.build +++ b/drivers/net/meson.build @@ -62,6 +62,7 @@ drivers = [ 'vhost', 'virtio', 'vmxnet3', + 'xsc', ] std_deps = ['ethdev', 'kvargs'] # 'ethdev' also pulls in mbuf, net, eal etc std_deps += ['bus_pci'] # very many PMDs depend on PCI, so make std diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build new file mode 100644 index 0000000000..11cdcf912b --- /dev/null +++ b/drivers/net/xsc/meson.build @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2024 Yunsilicon Technology Co., Ltd. + +if not is_linux + build = false + reason = 'only supported on Linux' +endif + +sources = files( + 'xsc_ethdev.c', +) + + diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c new file mode 100644 index 0000000000..0e48cb76fa --- /dev/null +++ b/drivers/net/xsc/xsc_ethdev.c @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ From patchwork Wed Sep 11 02:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143917 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 464ED4595A; Wed, 11 Sep 2024 04:08:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C12CF42EB6; Wed, 11 Sep 2024 04:08:09 +0200 (CEST) Received: from lf-2-39.ptr.blmpb.com (lf-2-39.ptr.blmpb.com [101.36.218.39]) by mails.dpdk.org (Postfix) with ESMTP id A83D2427A5 for ; Wed, 11 Sep 2024 04:08:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020475; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=y1Q4WsEmR1kkcFHRGJQaKHta/oUhBPB7as1OgVH+dI4=; b=Ajrth8SWTnLn7iO0Ryk8I1NqlnLyN4YNNhYx8b3C2LlLNxl7gNixXYdXcEu1j4dfW5Lo7A accxjXQVNvWzC6rE9ermSFmNgNi/kK7X/iVbl5sMCzezTgxiE4eea9uGZzWE9+Rq6Mhybk 5PpRNDzJOfo9RyRniFbdGaMe96feBVSlmJEKCaBfa4m4bdlnCgEMFgQvzFVJoycVfNlmP4 8KArA7JqG26wqTt4nWTr+NUGmEgTZxbFgchWg/1sMFSzpmylK4zQkXhPXyixHlsqaZRylg A6EnvGy/YR7xsEKWXYESA16Sz+j0xMnWuwZJWuNb4LuYAv0fHPTFaP/uF6Nnjw== Mime-Version: 1.0 X-Original-From: WanRenyong X-Mailer: git-send-email 2.25.1 To: Subject: [PATCH v2 02/19] net/xsc: add log macro Message-Id: <20240911020740.3950704-3-wanry@yunsilicon.com> Cc: , , "WanRenyong" Date: Wed, 11 Sep 2024 10:07:23 +0800 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:53 +0800 X-Lms-Return-Path: From: "WanRenyong" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add log macro to print runtime messages and trace functions. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_ethdev.c | 11 +++++++++ drivers/net/xsc/xsc_log.h | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 drivers/net/xsc/xsc_log.h diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 0e48cb76fa..58ceaa3940 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -1,3 +1,14 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright 2024 Yunsilicon Technology Co., Ltd. */ + +#include "xsc_log.h" + +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE); +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE); +#ifdef RTE_ETHDEV_DEBUG_RX +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_rx, rx, DEBUG); +#endif +#ifdef RTE_ETHDEV_DEBUG_TX +RTE_LOG_REGISTER_SUFFIX(xsc_logtype_tx, tx, DEBUG); +#endif diff --git a/drivers/net/xsc/xsc_log.h b/drivers/net/xsc/xsc_log.h new file mode 100644 index 0000000000..163145ff09 --- /dev/null +++ b/drivers/net/xsc/xsc_log.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_LOG_H_ +#define _XSC_LOG_H_ + +#include + +extern int xsc_logtype_init; +extern int xsc_logtype_driver; + +#define PMD_INIT_LOG(level, fmt, ...) \ + rte_log(RTE_LOG_ ## level, xsc_logtype_init, "%s(): " fmt "\n", \ + __func__, ##__VA_ARGS__) + +#define PMD_INIT_FUNC_TRACE() PMD_INIT_LOG(DEBUG, " >>") + +#ifdef RTE_ETHDEV_DEBUG_RX +extern int xsc_logtype_rx; +#define PMD_RX_LOG(level, fmt, ...) \ + rte_log(RTE_LOG_ ## level, xsc_logtype_rx, \ + "%s(): " fmt "\n", __func__, ##__VA_ARGS__) +#else +#define PMD_RX_LOG(level, fmt, ...) do { } while (0) +#endif + +#ifdef RTE_ETHDEV_DEBUG_TX +extern int xsc_logtype_tx; +#define PMD_TX_LOG(level, fmt, ...) \ + rte_log(RTE_LOG_ ## level, xsc_logtype_tx, \ + "%s(): " fmt "\n", __func__, ##__VA_ARGS__) +#else +#define PMD_TX_LOG(level, fmt, ...) do { } while (0) +#endif + +#define PMD_DRV_LOG_RAW(level, fmt, ...) \ + rte_log(RTE_LOG_ ## level, xsc_logtype_driver, "%s(): " fmt, \ + __func__, ##__VA_ARGS__) + +#define PMD_DRV_LOG(level, fmt, ...) \ + PMD_DRV_LOG_RAW(level, fmt "\n", ##__VA_ARGS__) + +#endif /* _XSC_LOG_H_ */ From patchwork Wed Sep 11 02:07:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143921 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12A9C4595A; Wed, 11 Sep 2024 04:08:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9C7742F17; Wed, 11 Sep 2024 04:08:14 +0200 (CEST) Received: from lf-1-20.ptr.blmpb.com (lf-1-20.ptr.blmpb.com [103.149.242.20]) by mails.dpdk.org (Postfix) with ESMTP id 9F71940E1D for ; Wed, 11 Sep 2024 04:08:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020476; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=LuNNyN0MW3rg2Mxwh2wpsDJ5w8rcYYPxI7ecnwPirIk=; b=DQ8k62etkOqgBRFbKmRPi+VVgRMD6/YJyu0n27GGRDz6VT1jwBrEutSYwFFb+T5Dv7+xmw vsRBe46PCs3mG0Dk4g4UPm8i4d/hrWOeuY69w3WwGkGwpKwgQoNspWZBAfzv8FOn0zTEWi IC+8NjS9NnP/OxCwxgkB/ifcQM27ofXjgGdOx76eYgsOKx+BlI9j3Ffcry1fEHDWpigdTO iXEOcA1xs/pTXSsZWNXd+5TqDj6rUtl4+9yhPeWsJgnYO5xRFmLazyEn2oqQTL2LtIeKfw 4IONPj78uZkCAGple1s/5VxOMT0PSMm9xpiZlZL5NRPH/wp4WQjw6nhkKq+KtQ== To: Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:55 +0800 X-Mailer: git-send-email 2.25.1 Cc: , , "WanRenyong" , "Na Na" Subject: [PATCH v2 03/19] net/xsc: add PCI device probe and remove X-Original-From: WanRenyong Mime-Version: 1.0 X-Lms-Return-Path: From: "WanRenyong" Date: Wed, 11 Sep 2024 10:07:24 +0800 Message-Id: <20240911020740.3950704-4-wanry@yunsilicon.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Support the following Yunsilicon NICs to be probed: - metaScale-200 - metaScale-200S - metaScale-50 - metaScale-100Q Signed-off-by: WanRenyong Signed-off-by: Na Na --- 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 + #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_ */ From patchwork Wed Sep 11 02:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143920 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CD2614595A; Wed, 11 Sep 2024 04:08:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80EF642F03; Wed, 11 Sep 2024 04:08:13 +0200 (CEST) Received: from lf-2-40.ptr.blmpb.com (lf-2-40.ptr.blmpb.com [101.36.218.40]) by mails.dpdk.org (Postfix) with ESMTP id 5FA97402AB for ; Wed, 11 Sep 2024 04:08:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020478; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=8HX5SlF5QV/d7r1w21ZgSzmwnrkEOwVNQyGCx0Ee0jc=; b=AatQqHzrLOmU3qRLZW8TQSPWh4+dzRiUoqnZ6/CgULw6tHCGbr6wqJf8emhAz346/xQ+5I jPGrhtxWcwXv4NwYjevsLyrpQ8qwHuJ7p/4tqhu+RTFgbEP7b8CFF64JpLoTNrFq7hi0Pg KHtLVdBz+AgSrEXz53mZCHd/UQ4dI1PkqhRo5KYIbpT4VKDdZFBOqhM+5FktbBcXedlP5R Naeu8jdemYtxHLldK3YD8Qi8Ux3BdbqjjARV/zpM7c3dPQdrK2sSO80m7peVl9ir0uHKL4 7ILIogBrdSBuluEGq6jmNul1/WAWcXsxjTx8vSAuvRYztcNjavDh+ZqTxe6Fjw== X-Lms-Return-Path: Message-Id: <20240911020740.3950704-5-wanry@yunsilicon.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 Cc: , , "WanRenyong" Date: Wed, 11 Sep 2024 10:07:25 +0800 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:56 +0800 X-Original-From: WanRenyong To: From: "WanRenyong" Subject: [PATCH v2 04/19] net/xsc: add xsc device init and uninit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org XSC device is a concept of low level device used to manage hardware resource and to interact with firmware. Signed-off-by: WanRenyong --- v2: * fix compilation error caused by missing dependency --- drivers/net/xsc/meson.build | 20 +++++ drivers/net/xsc/xsc_defs.h | 23 +++++ drivers/net/xsc/xsc_dev.c | 162 +++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_dev.h | 34 ++++++++ drivers/net/xsc/xsc_ethdev.c | 22 ++++- drivers/net/xsc/xsc_ethdev.h | 1 + drivers/net/xsc/xsc_utils.c | 96 +++++++++++++++++++++ drivers/net/xsc/xsc_utils.h | 14 +++ 8 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 drivers/net/xsc/xsc_dev.c create mode 100644 drivers/net/xsc/xsc_dev.h create mode 100644 drivers/net/xsc/xsc_utils.c create mode 100644 drivers/net/xsc/xsc_utils.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 11cdcf912b..8bf6ee7b47 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -8,6 +8,26 @@ endif sources = files( 'xsc_ethdev.c', + 'xsc_dev.c', + 'xsc_utils.c', ) +libnames = ['ibverbs'] +foreach libname:libnames + lib = dependency('lib' + libname, required: false, method : 'pkg-config') + if lib.found() + ext_deps += lib + else + build = false + reason = 'missing dependency, "' + libname + '"' + subdir_done() + endif +endforeach +lib = dependency('libxscale', required: false, method : 'pkg-config') +if lib.found() + ext_deps += lib + cflags += '-DHAVE_XSC_DV_PROVIDER=1' +else + cflags += '-DHAVE_XSC_DV_PROVIDER=0' +endif diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index b4ede6eca6..97cd61b2d1 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -8,5 +8,28 @@ #define XSC_PCI_VENDOR_ID 0x1f67 #define XSC_PCI_DEV_ID_MS 0x1111 +enum xsc_nic_mode { + XSC_NIC_MODE_LEGACY, + XSC_NIC_MODE_SWITCHDEV, + XSC_NIC_MODE_SOC, +}; + +enum xsc_pph_type { + XSC_PPH_NONE = 0, + XSC_RX_PPH = 0x1, + XSC_TX_PPH = 0x2, + XSC_VFREP_PPH = 0x4, + XSC_UPLINK_PPH = 0x8, +}; + +enum xsc_flow_mode { + XSC_FLOW_OFF_HW_ONLY, + XSC_FLOW_ON_HW_ONLY, + XSC_FLOW_ON_HW_FIRST, + XSC_FLOW_HOTSPOT, + XSC_FLOW_MODE_NULL = 7, + XSC_FLOW_MODE_MAX, +}; + #endif /* XSC_DEFS_H_ */ diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c new file mode 100644 index 0000000000..9673049628 --- /dev/null +++ b/drivers/net/xsc/xsc_dev.c @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "xsc_log.h" +#include "xsc_defs.h" +#include "xsc_dev.h" +#include "xsc_utils.h" + +#define XSC_DEV_DEF_FLOW_MODE XSC_FLOW_MODE_NULL +#define XSC_DEV_CTRL_FILE_FMT "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT + +static +void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs) +{ + struct rte_kvargs *kvlist; + struct xsc_devargs *xdevargs = &dev->devargs; + const char *tmp; + + kvlist = rte_kvargs_parse(devargs->args, NULL); + if (kvlist == NULL) + return; + + tmp = rte_kvargs_get(kvlist, XSC_PPH_MODE_ARG); + if (tmp != NULL) + xdevargs->pph_mode = atoi(tmp); + else + xdevargs->pph_mode = XSC_PPH_NONE; + tmp = rte_kvargs_get(kvlist, XSC_NIC_MODE_ARG); + if (tmp != NULL) + xdevargs->nic_mode = atoi(tmp); + else + xdevargs->nic_mode = XSC_NIC_MODE_LEGACY; + tmp = rte_kvargs_get(kvlist, XSC_FLOW_MODE_ARG); + if (tmp != NULL) + xdevargs->flow_mode = atoi(tmp); + else + xdevargs->flow_mode = XSC_DEV_DEF_FLOW_MODE; + + rte_kvargs_free(kvlist); +} + +static int +xsc_dev_open(struct xsc_dev *dev, struct rte_pci_device *pci_dev) +{ + struct ibv_device *ib_dev; + char ctrl_file[PATH_MAX]; + struct rte_pci_addr *pci_addr = &pci_dev->addr; + int ret; + + ib_dev = xsc_get_ibv_device(&pci_dev->addr); + if (ib_dev == NULL) { + PMD_DRV_LOG(ERR, "Could not get ibv device"); + return -ENODEV; + } + + dev->ibv_ctx = ibv_open_device(ib_dev); + if (dev->ibv_ctx == NULL) { + PMD_DRV_LOG(ERR, "Could not open ibv device: %s", ib_dev->name); + return -ENODEV; + } + + dev->ibv_pd = ibv_alloc_pd(dev->ibv_ctx); + if (dev->ibv_pd == NULL) { + PMD_DRV_LOG(ERR, "Failed to create pd:%s", ib_dev->name); + ret = -EINVAL; + goto alloc_pd_fail; + } + + strcpy(dev->ibv_name, ib_dev->name); + + snprintf(ctrl_file, PATH_MAX, XSC_DEV_CTRL_FILE_FMT, + pci_addr->domain, pci_addr->bus, pci_addr->devid, pci_addr->function); + + ret = open(ctrl_file, O_RDWR); + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to open file: (%s) ", ctrl_file); + goto open_ctrl_file_fail; + } + dev->ctrl_fd = ret; + + dev->bar_len = pci_dev->mem_resource[0].len; + dev->bar_addr = mmap(NULL, dev->bar_len, PROT_READ | PROT_WRITE, + MAP_SHARED, dev->ctrl_fd, 0); + if (dev->bar_addr == MAP_FAILED) { + PMD_DRV_LOG(ERR, "Failed to mmap file: (%s) ", ctrl_file); + ret = -EINVAL; + goto mmap_fail; + } + + return 0; + +mmap_fail: + close(dev->ctrl_fd); +open_ctrl_file_fail: + ibv_dealloc_pd(dev->ibv_pd); +alloc_pd_fail: + ibv_close_device(dev->ibv_ctx); + + return ret; +} + +static void +xsc_dev_close(struct xsc_dev *dev) +{ + munmap(dev->bar_addr, dev->bar_len); + close(dev->ctrl_fd); + ibv_close_device(dev->ibv_ctx); +} + +int +xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev) +{ + struct xsc_dev *d; + int ret; + + PMD_INIT_FUNC_TRACE(); + + d = rte_zmalloc(NULL, sizeof(*d), RTE_CACHE_LINE_SIZE); + if (d == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc memory for xsc_dev"); + return -ENOMEM; + } + + xsc_dev_args_parse(d, pci_dev->device.devargs); + + ret = xsc_dev_open(d, pci_dev); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to open xsc device"); + goto dev_open_fail; + } + + d->pci_dev = pci_dev; + *dev = d; + + return 0; + +dev_open_fail: + rte_free(d); + return ret; +} + +void +xsc_dev_uninit(struct xsc_dev *dev) +{ + PMD_INIT_FUNC_TRACE(); + + xsc_dev_close(dev); + rte_free(dev); +} diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h new file mode 100644 index 0000000000..ce9dd65400 --- /dev/null +++ b/drivers/net/xsc/xsc_dev.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_DEV_H_ +#define _XSC_DEV_H_ + +#include + +#define XSC_PPH_MODE_ARG "pph_mode" +#define XSC_NIC_MODE_ARG "nic_mode" +#define XSC_FLOW_MODE_ARG "flow_mode" + +struct xsc_devargs { + int nic_mode; + int flow_mode; + int pph_mode; +}; + +struct xsc_dev { + struct rte_pci_device *pci_dev; + struct xsc_devargs devargs; + struct ibv_context *ibv_ctx; + struct ibv_pd *ibv_pd; + char ibv_name[IBV_SYSFS_NAME_MAX]; + void *bar_addr; + uint64_t bar_len; + int ctrl_fd; +}; + +int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev); +void xsc_dev_uninit(struct xsc_dev *dev); + +#endif /* _XSC_DEV_H_ */ diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 8f4d539848..6a33cbb2cd 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -6,27 +6,38 @@ #include "xsc_log.h" #include "xsc_defs.h" +#include "xsc_dev.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); + int ret; PMD_INIT_FUNC_TRACE(); priv->eth_dev = eth_dev; priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); + ret = xsc_dev_init(priv->pci_dev, &priv->xdev); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to initialize xsc device"); + return ret; + } + return 0; } static int xsc_ethdev_uninit(struct rte_eth_dev *eth_dev) { - RTE_SET_USED(eth_dev); + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); + PMD_INIT_FUNC_TRACE(); + xsc_dev_uninit(priv->xdev); + return 0; } @@ -75,8 +86,17 @@ static struct rte_pci_driver xsc_ethdev_pci_driver = { .remove = xsc_ethdev_pci_remove, }; +RTE_INIT(xsc_pmd_init) +{ + ibv_fork_init(); +} + RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver); RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map); +RTE_PMD_REGISTER_PARAM_STRING(net_xsc, + XSC_PPH_MODE_ARG "=" + XSC_NIC_MODE_ARG "=" + XSC_FLOW_MODE_ARG "="); 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 index 75aa34dc63..22fc462e25 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -8,6 +8,7 @@ struct xsc_ethdev_priv { struct rte_eth_dev *eth_dev; struct rte_pci_device *pci_dev; + struct xsc_dev *xdev; }; #define TO_XSC_ETHDEV_PRIV(dev) \ diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c new file mode 100644 index 0000000000..cd4e3d9bad --- /dev/null +++ b/drivers/net/xsc/xsc_utils.c @@ -0,0 +1,96 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "xsc_log.h" +#include "xsc_utils.h" + +static int +xsc_get_ibdev_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr) +{ + FILE *file; + char line[32]; + char path[PATH_MAX]; + int ret = -ENOENT; + + sprintf(path, "%s/device/uevent", dev_path); + + file = fopen(path, "rb"); + if (file == NULL) { + PMD_DRV_LOG(ERR, "Failed to open file: (%s) ", path); + return ret; + } + while (fgets(line, sizeof(line), file) == line) { + size_t len = strlen(line); + + /* Truncate long lines. */ + if (len == (sizeof(line) - 1)) { + while (line[(len - 1)] != '\n') { + int n = fgetc(file); + + if (n == EOF) + goto out; + line[(len - 1)] = n; + } + /* No match for long lines. */ + continue; + } + /* Extract information. */ + if (sscanf(line, + "PCI_SLOT_NAME=%04x:%hhx:%hhx.%hhx", + &pci_addr->domain, + &pci_addr->bus, + &pci_addr->devid, + &pci_addr->function) == 4) { + ret = 0; + break; + } + } +out: + fclose(file); + return ret; +} + +struct ibv_device * +xsc_get_ibv_device(const struct rte_pci_addr *addr) +{ + int ibv_num, i; + struct ibv_device **ibv_list; + struct ibv_device *ibv_match = NULL; + struct rte_pci_addr ibv_pci_addr; + + ibv_list = ibv_get_device_list(&ibv_num); + if (ibv_list == NULL) + return NULL; + + for (i = 0; i < ibv_num; i++) { + if (xsc_get_ibdev_pci_addr(ibv_list[i]->ibdev_path, &ibv_pci_addr) != 0) + continue; + if (rte_pci_addr_cmp(addr, &ibv_pci_addr) != 0) + continue; + ibv_match = ibv_list[i]; + PMD_DRV_LOG(DEBUG, "Finding device \"name:%s, %s, path:%s, %s\"..", + ibv_list[i]->name, ibv_list[i]->dev_name, + ibv_list[i]->dev_path, ibv_list[i]->ibdev_path); + break; + } + ibv_free_device_list(ibv_list); + + if (ibv_match == NULL) { + PMD_DRV_LOG(WARNING, + "No Verbs device matches PCI device " PCI_PRI_FMT, + addr->domain, addr->bus, addr->devid, addr->function); + } + + return ibv_match; +} diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h new file mode 100644 index 0000000000..0bc318e96a --- /dev/null +++ b/drivers/net/xsc/xsc_utils.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_UTILS_H_ +#define _XSC_UTILS_H_ + +#include + +#include + +struct ibv_device *xsc_get_ibv_device(const struct rte_pci_addr *addr); + +#endif /* _XSC_UTILS_H_ */ From patchwork Wed Sep 11 02:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143919 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D69814595A; Wed, 11 Sep 2024 04:08:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 585DB42EEB; Wed, 11 Sep 2024 04:08:12 +0200 (CEST) Received: from lf-1-13.ptr.blmpb.com (lf-1-13.ptr.blmpb.com [103.149.242.13]) by mails.dpdk.org (Postfix) with ESMTP id BC41C40E1D for ; Wed, 11 Sep 2024 04:08:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020479; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=UQFXlln2H4zYVk7jPk0wYBZ7kImYllTxsBbb1Kdcub8=; b=ac3hvIsWCQVxAFZxd8U6I1MH/7Og/txJvYTSe1GZJjZRwbZX1ptQDq9yFD5L2NNLw6ny0B 2MEua7XyK0M1hlIeeXqU3JGbVvhroo2b0awLcF+LaYYApXU1otDCrmqu2d2H3gbYBqcBhz X7c2vrC6B8CBXItCzYid2Qg7wcIcf3cGOWKz74se+dGZATvw1J/y/7TBD+4UGA9mFA1Xyj Sjx2Pa8s9UWFsyoQ8hn34tby7wrJO8vEDe8w3ZMjwik1Dh2azMnzOkyhqy/8n30rUEnlsv ZlbhtoC5ISLDYGbtAu0S0IwAfKnUBDKlwDm+kHu2yKhEra90ynfzvbRWAagUeQ== X-Original-From: WanRenyong Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:58 +0800 To: From: "WanRenyong" Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 Date: Wed, 11 Sep 2024 10:07:26 +0800 Message-Id: <20240911020740.3950704-6-wanry@yunsilicon.com> Cc: , , "WanRenyong" X-Lms-Return-Path: Subject: [PATCH v2 05/19] net/xsc: add ioctl command interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org IOCTL command interface is one of methods used to interact with firmware by PMD. By using ioctl interface, PMD sends command to the kernel module, then the kernel module translates the command and sends it to firmware, at last, the kernel module send back PDM the result from firmware. Signed-off-by: WanRenyong --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_ctrl.c | 56 ++++++++++++++++++++++++ drivers/net/xsc/xsc_ctrl.h | 86 +++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 drivers/net/xsc/xsc_ctrl.c create mode 100644 drivers/net/xsc/xsc_ctrl.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 8bf6ee7b47..f38ebdfe0f 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -10,6 +10,7 @@ sources = files( 'xsc_ethdev.c', 'xsc_dev.c', 'xsc_utils.c', + 'xsc_ctrl.c', ) libnames = ['ibverbs'] diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c new file mode 100644 index 0000000000..3e37bd914e --- /dev/null +++ b/drivers/net/xsc/xsc_ctrl.c @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "xsc_log.h" +#include "xsc_dev.h" +#include "xsc_ctrl.h" + +int +xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode, + void *data_in, int in_len, void *data_out, int out_len) +{ + struct xsc_ioctl_hdr *hdr; + int data_len = RTE_MAX(in_len, out_len); + int alloc_len = sizeof(struct xsc_ioctl_hdr) + data_len; + int ret = 0; + + hdr = rte_zmalloc(NULL, alloc_len, RTE_CACHE_LINE_SIZE); + if (hdr == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate xsc ioctl cmd memory"); + return -ENOMEM; + } + + hdr->check_field = XSC_IOCTL_CHECK_FIELD; + hdr->attr.opcode = opcode; + hdr->attr.length = data_len; + hdr->attr.error = 0; + + if (data_in != NULL && in_len > 0) + rte_memcpy(hdr + 1, data_in, in_len); + + ret = ioctl(dev->ctrl_fd, cmd, hdr); + if (ret == 0) { + if (hdr->attr.error != 0) + ret = hdr->attr.error; + else if (data_out != NULL && out_len > 0) + rte_memcpy(data_out, hdr + 1, out_len); + } + + rte_free(hdr); + return ret; +} diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h new file mode 100644 index 0000000000..d343e1b1a7 --- /dev/null +++ b/drivers/net/xsc/xsc_ctrl.h @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_CTRL_H_ +#define _XSC_CTRL_H_ + +#include + +#define XSC_IOCTL_CHECK_FIELD 0x01234567 + +#define XSC_IOCTL_MAGIC 0x1b +#define XSC_IOCTL_CMDQ \ + _IOWR(XSC_IOCTL_MAGIC, 1, struct xsc_ioctl_hdr) +#define XSC_IOCTL_DRV_GET \ + _IOR(XSC_IOCTL_MAGIC, 2, struct xsc_ioctl_hdr) +#define XSC_IOCTL_CMDQ_RAW \ + _IOWR(XSC_IOCTL_MAGIC, 5, struct xsc_ioctl_hdr) + +enum xsc_ioctl_opcode { + XSC_IOCTL_GET_HW_INFO = 0x100, +}; + +enum xsc_ioctl_opmod { + XSC_IOCTL_OP_GET_LOCAL, +}; + +struct xsc_ioctl_attr { + uint16_t opcode; /* ioctl cmd */ + uint16_t length; /* data length */ + uint32_t error; /* ioctl error info */ + uint8_t data[0]; /* specific table info */ +}; + +struct xsc_ioctl_hdr { + uint32_t check_field; + uint32_t domain; + uint32_t bus; + uint32_t devfn; + struct xsc_ioctl_attr attr; +}; + +struct xsc_ioctl_data_tl { + uint16_t table; + uint16_t opmod; + uint16_t length; + uint16_t rsvd; +}; + +struct xsc_ioctl_get_hwinfo { + uint32_t domain; + uint32_t bus; + uint32_t devfn; + uint32_t pcie_no; + uint32_t func_id; + uint32_t pcie_host; + uint32_t mac_phy_port; + uint32_t funcid_to_logic_port_off; + uint16_t lag_id; + uint16_t raw_qp_id_base; + uint16_t raw_rss_qp_id_base; + uint16_t pf0_vf_funcid_base; + uint16_t pf0_vf_funcid_top; + uint16_t pf1_vf_funcid_base; + uint16_t pf1_vf_funcid_top; + uint16_t pcie0_pf_funcid_base; + uint16_t pcie0_pf_funcid_top; + uint16_t pcie1_pf_funcid_base; + uint16_t pcie1_pf_funcid_top; + uint16_t lag_port_start; + uint16_t raw_tpe_qp_num; + int send_seg_num; + int recv_seg_num; + uint8_t on_chip_tbl_vld; + uint8_t dma_rw_tbl_vld; + uint8_t pct_compress_vld; + uint32_t chip_version; + uint32_t hca_core_clock; + uint8_t mac_bit; + uint8_t esw_mode; +}; + +int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode, + void *data_in, int in_len, void *data_out, int out_len); + +#endif /* _XSC_CTRL_H_ */ From patchwork Wed Sep 11 02:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143922 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23CF54595A; Wed, 11 Sep 2024 04:08:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 01C7A42F4F; Wed, 11 Sep 2024 04:08:16 +0200 (CEST) Received: from lf-1-19.ptr.blmpb.com (lf-1-19.ptr.blmpb.com [103.149.242.19]) by mails.dpdk.org (Postfix) with ESMTP id EFB4F402DE for ; Wed, 11 Sep 2024 04:08:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020481; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=V2WUDsjII+ZNpkG22zwzcxG7uuU2wIpYEsYHNmDOYjg=; b=HAsHFS6yJEKVv+q3dJeZLFmAcA808Ql/jXMmkbLXfIhJS1GG6GVu6w8lgTO3VdVmndtyH9 KBqpniPqzL7PBzYNR5PdhpCHosHCPC4IHXfcJLocoHEZTE3+j9JF6HKcGeLCN9WeuoewTs 84YWR1m1serOG2oH23FgHubMHJQWfVP4TLyywkXn/G9LWpcasnQhnTE0L3lvAFTipzo7GR 4GkjWbEYNexjv+qvlPDC8PuiYWsW6ZXSZqQZkKDd6kYQur45mZUEbJRoxJU7NoB3e9kCb5 mFDLS13A8RFH18f4YdGtpD2s1w93AxsS1ZxkJ5BjZIjPJEKBlqMmxFe5i7ehgg== To: Date: Wed, 11 Sep 2024 10:07:27 +0800 Message-Id: <20240911020740.3950704-7-wanry@yunsilicon.com> Mime-Version: 1.0 X-Lms-Return-Path: From: "WanRenyong" Subject: [PATCH v2 06/19] net/xsc: initialize hardware information X-Original-From: WanRenyong Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:59 +0800 X-Mailer: git-send-email 2.25.1 Cc: , , "WanRenyong" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Getting hardware information is done by ioctl command, which contains the information of xsc device, as well as the common information of the NIC board. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_dev.c | 63 +++++++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_dev.h | 32 ++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 9673049628..1eb68ac95d 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -18,10 +18,64 @@ #include "xsc_defs.h" #include "xsc_dev.h" #include "xsc_utils.h" +#include "xsc_ctrl.h" #define XSC_DEV_DEF_FLOW_MODE XSC_FLOW_MODE_NULL #define XSC_DEV_CTRL_FILE_FMT "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT +static int xsc_hwinfo_init(struct xsc_dev *dev) +{ + struct { + struct xsc_ioctl_data_tl tl; + struct xsc_ioctl_get_hwinfo hwinfo; + } data; + struct xsc_ioctl_get_hwinfo *info = &data.hwinfo; + int data_len; + int ret; + + PMD_INIT_FUNC_TRACE(); + + data_len = sizeof(data); + data.tl.opmod = XSC_IOCTL_OP_GET_LOCAL; + ret = xsc_ioctl(dev, XSC_IOCTL_DRV_GET, XSC_IOCTL_GET_HW_INFO, &data, data_len, + &data, data_len); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to get hardware info"); + return ret; + } + + dev->hwinfo.valid = 1; + dev->hwinfo.pcie_no = info->pcie_no; + dev->hwinfo.func_id = info->func_id; + dev->hwinfo.pcie_host = info->pcie_host; + dev->hwinfo.mac_phy_port = info->mac_phy_port; + dev->hwinfo.funcid_to_logic_port_off = info->funcid_to_logic_port_off; + dev->hwinfo.lag_id = info->lag_id; + dev->hwinfo.raw_qp_id_base = info->raw_qp_id_base; + dev->hwinfo.raw_rss_qp_id_base = info->raw_rss_qp_id_base; + dev->hwinfo.pf0_vf_funcid_base = info->pf0_vf_funcid_base; + dev->hwinfo.pf0_vf_funcid_top = info->pf0_vf_funcid_top; + dev->hwinfo.pf1_vf_funcid_base = info->pf1_vf_funcid_base; + dev->hwinfo.pf1_vf_funcid_top = info->pf1_vf_funcid_top; + dev->hwinfo.pcie0_pf_funcid_base = info->pcie0_pf_funcid_base; + dev->hwinfo.pcie0_pf_funcid_top = info->pcie0_pf_funcid_top; + dev->hwinfo.pcie1_pf_funcid_base = info->pcie1_pf_funcid_base; + dev->hwinfo.pcie1_pf_funcid_top = info->pcie1_pf_funcid_top; + dev->hwinfo.lag_port_start = info->lag_port_start; + dev->hwinfo.raw_tpe_qp_num = info->raw_tpe_qp_num; + dev->hwinfo.send_seg_num = info->send_seg_num; + dev->hwinfo.recv_seg_num = info->recv_seg_num; + dev->hwinfo.on_chip_tbl_vld = info->on_chip_tbl_vld; + dev->hwinfo.dma_rw_tbl_vld = info->dma_rw_tbl_vld; + dev->hwinfo.pct_compress_vld = info->pct_compress_vld; + dev->hwinfo.chip_version = info->chip_version; + dev->hwinfo.hca_core_clock = info->hca_core_clock; + dev->hwinfo.mac_bit = info->mac_bit; + dev->hwinfo.esw_mode = info->esw_mode; + + return 0; +} + static void xsc_dev_args_parse(struct xsc_dev *dev, struct rte_devargs *devargs) { @@ -142,11 +196,20 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev) goto dev_open_fail; } + ret = xsc_hwinfo_init(d); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to initialize hardware info"); + goto hwinfo_init_fail; + return ret; + } + d->pci_dev = pci_dev; *dev = d; return 0; +hwinfo_init_fail: + xsc_dev_close(d); dev_open_fail: rte_free(d); return ret; diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index ce9dd65400..5f0e911b42 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -11,6 +11,37 @@ #define XSC_NIC_MODE_ARG "nic_mode" #define XSC_FLOW_MODE_ARG "flow_mode" +struct xsc_hwinfo { + uint8_t valid; /* 1: current phy info is valid, 0 : invalid */ + uint32_t pcie_no; /* pcie number , 0 or 1 */ + uint32_t func_id; /* pf glb func id */ + uint32_t pcie_host; /* host pcie number */ + uint32_t mac_phy_port; /* mac port */ + uint32_t funcid_to_logic_port_off; /* port func id offset */ + uint16_t lag_id; + uint16_t raw_qp_id_base; + uint16_t raw_rss_qp_id_base; + uint16_t pf0_vf_funcid_base; + uint16_t pf0_vf_funcid_top; + uint16_t pf1_vf_funcid_base; + uint16_t pf1_vf_funcid_top; + uint16_t pcie0_pf_funcid_base; + uint16_t pcie0_pf_funcid_top; + uint16_t pcie1_pf_funcid_base; + uint16_t pcie1_pf_funcid_top; + uint16_t lag_port_start; + uint16_t raw_tpe_qp_num; + int send_seg_num; + int recv_seg_num; + uint8_t on_chip_tbl_vld; + uint8_t dma_rw_tbl_vld; + uint8_t pct_compress_vld; + uint32_t chip_version; + uint32_t hca_core_clock; + uint8_t mac_bit; + uint8_t esw_mode; +}; + struct xsc_devargs { int nic_mode; int flow_mode; @@ -20,6 +51,7 @@ struct xsc_devargs { struct xsc_dev { struct rte_pci_device *pci_dev; struct xsc_devargs devargs; + struct xsc_hwinfo hwinfo; struct ibv_context *ibv_ctx; struct ibv_pd *ibv_pd; char ibv_name[IBV_SYSFS_NAME_MAX]; From patchwork Wed Sep 11 02:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143924 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DBEB84595A; Wed, 11 Sep 2024 04:09:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C70042FA1; Wed, 11 Sep 2024 04:08:18 +0200 (CEST) Received: from lf-2-39.ptr.blmpb.com (lf-2-39.ptr.blmpb.com [101.36.218.39]) by mails.dpdk.org (Postfix) with ESMTP id 0DEDC42EFE for ; Wed, 11 Sep 2024 04:08:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020482; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=oN8fgGlO/mZy3UtuQ+A6RhUjuIBfonN7Dtl7mT4LJhw=; b=LBPk7KCgM3VEM9sDdCFUMcq0oPNpvvQgWkal92juTd6MHuaVLe9gszsA+jyorCT9obzVbC bGVNEueL4L+3DeEesj9gSMzdHiXMBN4FoXpXHfCkYyr6xtBlaN704GcpwJxpNqJ9PXA0kz fnUt3Xm9ygvcmgIFUenRQoUxWfPVu1GoMYeV46RNvqAiyYVLJYZZMrnPxbUqqJxwYIamLc /060PWWDmVrvhwAulaHKQCDUaa8AK3Arwl3FdsX/MyxJ+pHXGNCMj7tWaGN2FaPnnLIr88 5+2dOlSyrKJJza0utkzZrCK9R0wO0qF9pVnuxd/20LJ6HjO3bcoDyAhrjkhxYA== Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:01 +0800 Subject: [PATCH v2 07/19] net/xsc: add representor ports probe Message-Id: <20240911020740.3950704-8-wanry@yunsilicon.com> Mime-Version: 1.0 X-Lms-Return-Path: Cc: , , "WanRenyong" , "Na Na" From: "WanRenyong" X-Mailer: git-send-email 2.25.1 X-Original-From: WanRenyong To: Date: Wed, 11 Sep 2024 10:07:28 +0800 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org XSC representor port is designed to store representor resources. In addition to common representor ports, xsc device is a special representor port. Signed-off-by: WanRenyong Signed-off-by: Na Na --- drivers/net/xsc/xsc_defs.h | 24 +++++++ drivers/net/xsc/xsc_dev.c | 103 +++++++++++++++++++++++++++++- drivers/net/xsc/xsc_dev.h | 27 ++++++++ drivers/net/xsc/xsc_utils.c | 122 ++++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_utils.h | 3 + 5 files changed, 278 insertions(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 97cd61b2d1..8cb67ed2e1 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -8,6 +8,10 @@ #define XSC_PCI_VENDOR_ID 0x1f67 #define XSC_PCI_DEV_ID_MS 0x1111 +#define XSC_VFREP_BASE_LOGICAL_PORT 1081 + + + enum xsc_nic_mode { XSC_NIC_MODE_LEGACY, XSC_NIC_MODE_SWITCHDEV, @@ -31,5 +35,25 @@ enum xsc_flow_mode { XSC_FLOW_MODE_MAX, }; +enum xsc_funcid_type { + XSC_FUNCID_TYPE_INVAL = 0x0, + XSC_EMU_FUNCID = 0x1, + XSC_PHYPORT_MAC_FUNCID = 0x2, + XSC_VF_IOCTL_FUNCID = 0x3, + XSC_PHYPORT_LAG_FUNCID = 0x4, + XSC_FUNCID_TYPE_UNKNOWN = 0x5, +}; + +enum xsc_phy_port_type { + XSC_PORT_TYPE_NONE = 0, + XSC_PORT_TYPE_UPLINK, /* mac0rep */ + XSC_PORT_TYPE_UPLINK_BOND, /* bondrep */ + XSC_PORT_TYPE_PFVF, /*hasreps: vfrep*/ + XSC_PORT_TYPE_PFHPF, /*hasreps: host pf rep*/ + XSC_PORT_TYPE_UNKNOWN, +}; + +#define XSC_PHY_PORT_NUM 1 + #endif /* XSC_DEFS_H_ */ diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c index 1eb68ac95d..3ba9a16116 100644 --- a/drivers/net/xsc/xsc_dev.c +++ b/drivers/net/xsc/xsc_dev.c @@ -23,6 +23,31 @@ #define XSC_DEV_DEF_FLOW_MODE XSC_FLOW_MODE_NULL #define XSC_DEV_CTRL_FILE_FMT "/dev/yunsilicon/port_ctrl_" PCI_PRI_FMT +static int +xsc_dev_alloc_vfos_info(struct xsc_dev *dev) +{ + struct xsc_hwinfo *hwinfo; + int vfrep_offset = 0; + int base_lp = 0; + + hwinfo = &dev->hwinfo; + if (hwinfo->pcie_no == 1) { + vfrep_offset = hwinfo->func_id - + hwinfo->pcie1_pf_funcid_base + + hwinfo->pcie0_pf_funcid_top - + hwinfo->pcie0_pf_funcid_base + 1; + } else { + vfrep_offset = hwinfo->func_id - hwinfo->pcie0_pf_funcid_base; + } + + base_lp = XSC_VFREP_BASE_LOGICAL_PORT; + if (dev->devargs.nic_mode == XSC_NIC_MODE_LEGACY) + base_lp = base_lp + vfrep_offset; + + dev->vfos_logical_in_port = base_lp; + return 0; +} + static int xsc_hwinfo_init(struct xsc_dev *dev) { struct { @@ -174,6 +199,73 @@ xsc_dev_close(struct xsc_dev *dev) ibv_close_device(dev->ibv_ctx); } +static void +xsc_repr_info_init(struct xsc_repr_info *info, enum xsc_phy_port_type port_type, + enum xsc_funcid_type funcid_type, int32_t repr_id) +{ + info->repr_id = repr_id; + info->port_type = port_type; + if (port_type == XSC_PORT_TYPE_UPLINK_BOND) { + info->pf_bond = 1; + info->funcid = XSC_PHYPORT_LAG_FUNCID << 14; + } else if (port_type == XSC_PORT_TYPE_UPLINK) { + info->pf_bond = -1; + info->funcid = XSC_PHYPORT_MAC_FUNCID << 14; + } else if (port_type == XSC_PORT_TYPE_PFVF) { + info->funcid = funcid_type << 14; + } +} + +int +xsc_repr_ports_probe(struct xsc_dev *dev, int nb_ports, int max_nb_ports) +{ + int funcid_type; + struct xsc_repr_port *repr_port; + int i; + int ret; + + PMD_INIT_FUNC_TRACE(); + + ret = xsc_get_ifindex_by_pci_addr(&dev->pci_dev->addr, &dev->ifindex); + if (ret) { + PMD_DRV_LOG(ERR, "Could not get xsc dev ifindex"); + return ret; + } + + dev->num_repr_ports = nb_ports + 1; + + dev->repr_ports = rte_zmalloc(NULL, + sizeof(struct xsc_repr_port) * dev->num_repr_ports, + RTE_CACHE_LINE_SIZE); + if (dev->repr_ports == NULL) { + PMD_DRV_LOG(ERR, "Failed to allocate memory for repr_ports"); + return -ENOMEM; + } + + funcid_type = (dev->devargs.nic_mode == XSC_NIC_MODE_SWITCHDEV) ? + XSC_VF_IOCTL_FUNCID : XSC_PHYPORT_MAC_FUNCID; + + repr_port = &dev->repr_ports[XSC_DEV_REPR_PORT]; + xsc_repr_info_init(&repr_port->info, + XSC_PORT_TYPE_UPLINK, XSC_FUNCID_TYPE_UNKNOWN, -1); + repr_port->info.ifindex = dev->ifindex; + repr_port->xdev = dev; + + if ((dev->devargs.pph_mode & XSC_TX_PPH) == 0) + repr_port->info.repr_id = 510; + else + repr_port->info.repr_id = max_nb_ports - 1; + + for (i = 1; i < dev->num_repr_ports; i++) { + repr_port = &dev->repr_ports[i]; + xsc_repr_info_init(&repr_port->info, + XSC_PORT_TYPE_PFVF, funcid_type, i - XSC_PHY_PORT_NUM); + repr_port->xdev = dev; + } + + return 0; +} + int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev) { @@ -199,8 +291,15 @@ xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev) ret = xsc_hwinfo_init(d); if (ret) { PMD_DRV_LOG(ERR, "Failed to initialize hardware info"); + ret = -EINVAL; + goto hwinfo_init_fail; + } + + ret = xsc_dev_alloc_vfos_info(d); + if (ret) { + PMD_DRV_LOG(ERR, "Alloc vfos info failed"); + ret = -EINVAL; goto hwinfo_init_fail; - return ret; } d->pci_dev = pci_dev; @@ -220,6 +319,8 @@ xsc_dev_uninit(struct xsc_dev *dev) { PMD_INIT_FUNC_TRACE(); + if (dev->repr_ports != NULL) + rte_free(dev->repr_ports); xsc_dev_close(dev); rte_free(dev); } diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index 5f0e911b42..93ab1e24fe 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -7,10 +7,14 @@ #include +#include "xsc_defs.h" + #define XSC_PPH_MODE_ARG "pph_mode" #define XSC_NIC_MODE_ARG "nic_mode" #define XSC_FLOW_MODE_ARG "flow_mode" +#define XSC_DEV_REPR_PORT 0 + struct xsc_hwinfo { uint8_t valid; /* 1: current phy info is valid, 0 : invalid */ uint32_t pcie_no; /* pcie number , 0 or 1 */ @@ -48,10 +52,32 @@ struct xsc_devargs { int pph_mode; }; +struct xsc_repr_info { + int32_t repr_id; + enum xsc_phy_port_type port_type; + int pf_bond; + + uint32_t ifindex; + const char *phys_dev_name; + uint32_t funcid; +}; + +struct xsc_repr_port { + struct xsc_dev *xdev; + struct xsc_repr_info info; + void *drv_data; +}; + struct xsc_dev { struct rte_pci_device *pci_dev; struct xsc_devargs devargs; struct xsc_hwinfo hwinfo; + int vfos_logical_in_port; + + struct xsc_repr_port *repr_ports; + int num_repr_ports; + int ifindex; + struct ibv_context *ibv_ctx; struct ibv_pd *ibv_pd; char ibv_name[IBV_SYSFS_NAME_MAX]; @@ -62,5 +88,6 @@ struct xsc_dev { int xsc_dev_init(struct rte_pci_device *pci_dev, struct xsc_dev **dev); void xsc_dev_uninit(struct xsc_dev *dev); +int xsc_repr_ports_probe(struct xsc_dev *dev, int nb_port, int max_nb_ports); #endif /* _XSC_DEV_H_ */ diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c index cd4e3d9bad..0d8f3f5be9 100644 --- a/drivers/net/xsc/xsc_utils.c +++ b/drivers/net/xsc/xsc_utils.c @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include "xsc_log.h" @@ -94,3 +97,122 @@ xsc_get_ibv_device(const struct rte_pci_addr *addr) return ibv_match; } + +int +xsc_get_ifname_by_pci_addr(struct rte_pci_addr *addr, char *ifname) +{ + DIR *dir; + struct dirent *dent; + unsigned int dev_type = 0; + unsigned int dev_port_prev = ~0u; + char match[IF_NAMESIZE] = ""; + char net_path[PATH_MAX]; + + snprintf(net_path, sizeof(net_path), "%s/" PCI_PRI_FMT "/net", + rte_pci_get_sysfs_path(), addr->domain, addr->bus, + addr->devid, addr->function); + + dir = opendir(net_path); + if (dir == NULL) { + PMD_DRV_LOG(ERR, "Could not open %s", net_path); + return -ENOENT; + } + + while ((dent = readdir(dir)) != NULL) { + char *name = dent->d_name; + FILE *file; + unsigned int dev_port; + int r; + char path[PATH_MAX]; + + if ((name[0] == '.') && + ((name[1] == '\0') || + ((name[1] == '.') && (name[2] == '\0')))) + continue; + + snprintf(path, sizeof(path), "%s/%s/%s", + net_path, name, (dev_type ? "dev_id" : "dev_port")); + + file = fopen(path, "rb"); + if (file == NULL) { + if (errno != ENOENT) + continue; + /* + * Switch to dev_id when dev_port does not exist as + * is the case with Linux kernel versions < 3.15. + */ +try_dev_id: + match[0] = '\0'; + if (dev_type) + break; + dev_type = 1; + dev_port_prev = ~0u; + rewinddir(dir); + continue; + } + r = fscanf(file, (dev_type ? "%x" : "%u"), &dev_port); + fclose(file); + if (r != 1) + continue; + /* + * Switch to dev_id when dev_port returns the same value for + * all ports. May happen when using a MOFED release older than + * 3.0 with a Linux kernel >= 3.15. + */ + if (dev_port == dev_port_prev) + goto try_dev_id; + dev_port_prev = dev_port; + if (dev_port == 0) + snprintf(match, IF_NAMESIZE, "%s", name); + } + closedir(dir); + if (match[0] == '\0') + return -ENOENT; + + snprintf(ifname, IF_NAMESIZE, "%s", match); + return 0; +} + +int +xsc_get_ifindex_by_ifname(const char *ifname, int *ifindex) +{ + struct ifreq ifr; + int sockfd; + + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd == -1) + return -EINVAL; + + strncpy(ifr.ifr_name, ifname, IFNAMSIZ - 1); + if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) { + close(sockfd); + return -EINVAL; + } + + *ifindex = ifr.ifr_ifindex; + + close(sockfd); + return 0; +} + +int +xsc_get_ifindex_by_pci_addr(struct rte_pci_addr *addr, int *ifindex) +{ + char ifname[IF_NAMESIZE]; + int ret; + + ret = xsc_get_ifname_by_pci_addr(addr, ifname); + if (ret) { + PMD_DRV_LOG(ERR, "Could not get ifname by pci address:" PCI_PRI_FMT, + addr->domain, addr->bus, addr->devid, addr->function); + return ret; + } + + ret = xsc_get_ifindex_by_ifname(ifname, ifindex); + if (ret) { + PMD_DRV_LOG(ERR, "Could not get ifindex by ifname:%s", ifname); + return ret; + } + + return 0; +} diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h index 0bc318e96a..0d4596489a 100644 --- a/drivers/net/xsc/xsc_utils.h +++ b/drivers/net/xsc/xsc_utils.h @@ -10,5 +10,8 @@ #include struct ibv_device *xsc_get_ibv_device(const struct rte_pci_addr *addr); +int xsc_get_ifname_by_pci_addr(struct rte_pci_addr *addr, char *ifname); +int xsc_get_ifindex_by_ifname(const char *ifname, int *ifindex); +int xsc_get_ifindex_by_pci_addr(struct rte_pci_addr *addr, int *ifindex); #endif /* _XSC_UTILS_H_ */ From patchwork Wed Sep 11 02:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143925 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 42BE24595A; Wed, 11 Sep 2024 04:09:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0923C42FD1; Wed, 11 Sep 2024 04:08:20 +0200 (CEST) Received: from lf-1-18.ptr.blmpb.com (lf-1-18.ptr.blmpb.com [103.149.242.18]) by mails.dpdk.org (Postfix) with ESMTP id 82BDD42F01 for ; Wed, 11 Sep 2024 04:08:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020484; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=YxnIOqmQ39aHe4qWOI7CozKNDH2BjSe7qgWlIthe/Zw=; b=DygEO5QVtBcBeXnnQR/foUUzU5OTwtd2MMYWBSvfUXgiSy7iWlEHHd6rgFWlg9lI+Z+32B TWC4cAr20xzvLCGAfOR1VBDs7jCLHQGLk6mOmICK4LeE5Zia4YQeUQpOCnXw2jmmkeW2FB KbTWObWP2cyDeTElgHLaTD+Qc1YyvOSsFhYSyf9ovojHe9tsqLltxDucIRi2CLjM/4XEew ZeI5xSNRVSCH8dEleZM3OaRQ0AwDexsjxW6x+FlJ9xfrMyXv1QJqrma7mY5I6/YjmfZj0p vg47WoYLQ98+c25cZ9zFdgYGavOcY8AL9OyHIuo0s/4T4F3feRS2BpO8TmKZzw== Cc: , , "WanRenyong" From: "WanRenyong" X-Lms-Return-Path: To: Subject: [PATCH v2 08/19] net/xsc: create eth devices for representor ports X-Original-From: WanRenyong Message-Id: <20240911020740.3950704-9-wanry@yunsilicon.com> Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:02 +0800 Date: Wed, 11 Sep 2024 10:07:29 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Each representor port is a rte ethernet device. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_ethdev.c | 87 ++++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_ethdev.h | 1 + 2 files changed, 88 insertions(+) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 6a33cbb2cd..d6efc3c9a0 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -9,6 +9,83 @@ #include "xsc_dev.h" #include "xsc_ethdev.h" +static int +xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params) +{ + struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); + + priv->repr_port = repr_port; + repr_port->drv_data = eth_dev; + + return 0; +} + +static int +xsc_ethdev_init_representors(struct rte_eth_dev *eth_dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); + struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 }; + struct rte_device *dev; + struct xsc_dev *xdev; + struct xsc_repr_port *repr_port; + char name[RTE_ETH_NAME_MAX_LEN]; + int i; + int ret; + + PMD_INIT_FUNC_TRACE(); + + dev = &priv->pci_dev->device; + if (dev->devargs != NULL) { + ret = rte_eth_devargs_parse(dev->devargs->args, ð_da, 1); + if (ret < 0) { + PMD_DRV_LOG(ERR, "Failed to parse device arguments: %s", + dev->devargs->args); + return -EINVAL; + } + } + + xdev = priv->xdev; + ret = xsc_repr_ports_probe(xdev, eth_da.nb_representor_ports, RTE_MAX_ETHPORTS); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to probe %d xsc device representors", + eth_da.nb_representor_ports); + return ret; + } + + repr_port = &xdev->repr_ports[XSC_DEV_REPR_PORT]; + ret = xsc_ethdev_init_one_representor(eth_dev, repr_port); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to init backing representor"); + return ret; + } + + for (i = 1; i < xdev->num_repr_ports; i++) { + repr_port = &xdev->repr_ports[i]; + snprintf(name, sizeof(name), "%s_rep_%d", + xdev->ibv_name, repr_port->info.repr_id); + ret = rte_eth_dev_create(&xdev->pci_dev->device, + name, + sizeof(struct xsc_ethdev_priv), + NULL, NULL, + xsc_ethdev_init_one_representor, + repr_port); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to create representor: %d", i); + goto destroy_reprs; + } + } + + return 0; + +destroy_reprs: + while ((i--) > 1) { + repr_port = &xdev->repr_ports[i]; + rte_eth_dev_destroy((struct rte_eth_dev *)repr_port->drv_data, NULL); + } + return ret; +} + static int xsc_ethdev_init(struct rte_eth_dev *eth_dev) { @@ -26,7 +103,17 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev) return ret; } + ret = xsc_ethdev_init_representors(eth_dev); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Failed to initialize representors"); + goto uninit_xsc_dev; + } + return 0; + +uninit_xsc_dev: + xsc_dev_uninit(priv->xdev); + return ret; } static int diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h index 22fc462e25..a05a63193c 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -9,6 +9,7 @@ struct xsc_ethdev_priv { struct rte_eth_dev *eth_dev; struct rte_pci_device *pci_dev; struct xsc_dev *xdev; + struct xsc_repr_port *repr_port; }; #define TO_XSC_ETHDEV_PRIV(dev) \ From patchwork Wed Sep 11 02:07:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143926 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 003F94595A; Wed, 11 Sep 2024 04:09:30 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4AE4542F01; Wed, 11 Sep 2024 04:08:21 +0200 (CEST) Received: from lf-2-38.ptr.blmpb.com (lf-2-38.ptr.blmpb.com [101.36.218.38]) by mails.dpdk.org (Postfix) with ESMTP id CEF6942F65 for ; Wed, 11 Sep 2024 04:08:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020486; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=X5K0tVq//9VuAu3aQAFl2dVZgqyrfAXh/ufrXEqjAhE=; b=FEsXGlBLUA2d24KEACj+M+ViZsYKxHYIFKoxdA5t44lpvDIphm8qwv/7pIGWlYJQOo5Wox BKygMBmrVUFTG9ycGM2ibi9OUqtarTgIEiSV5puSFwUc/mIAaH+XrcN2S6nD7L0Ce35802 9tVNlvYhEHCjbDXk/E2YjZO+rTxbInaQQNGwmw8nYPCS9e/OATe0m6RsSsCsmxddMKGv77 m2wvVOjtchIhpv0mQuNlA5lokyp7YC6AzNzGVGDK+Fkcv/NDXCqw4UHzpkRLOgD0gHqDIv jydg04li60qYI4ib1tNpbC6L5m2PQBd4KeZmSUtwQeGEdyoHq279MUbQoLCPvw== To: Subject: [PATCH v2 09/19] net/xsc: initial representor eth device Mime-Version: 1.0 From: "WanRenyong" Date: Wed, 11 Sep 2024 10:07:30 +0800 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:04 +0800 Cc: , , "WanRenyong" X-Mailer: git-send-email 2.25.1 Message-Id: <20240911020740.3950704-10-wanry@yunsilicon.com> X-Original-From: WanRenyong X-Lms-Return-Path: X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Initialize xsc eth device private data. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_defs.h | 2 +- drivers/net/xsc/xsc_dev.h | 3 + drivers/net/xsc/xsc_ethdev.c | 64 +++++++++++++++++++++ drivers/net/xsc/xsc_ethdev.h | 30 ++++++++++ drivers/net/xsc/xsc_utils.c | 105 +++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_utils.h | 8 ++- 6 files changed, 210 insertions(+), 2 deletions(-) diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 8cb67ed2e1..7dc57e5717 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -10,7 +10,7 @@ #define XSC_VFREP_BASE_LOGICAL_PORT 1081 - +#define XSC_MAX_MAC_ADDRESSES 3 enum xsc_nic_mode { XSC_NIC_MODE_LEGACY, diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index 93ab1e24fe..f77551f1c5 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -15,6 +15,9 @@ #define XSC_DEV_REPR_PORT 0 +#define FUNCID_TYPE_MASK 0x1c000 +#define FUNCID_MASK 0x3fff + struct xsc_hwinfo { uint8_t valid; /* 1: current phy info is valid, 0 : invalid */ uint32_t pcie_no; /* pcie number , 0 or 1 */ diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index d6efc3c9a0..aacce8b90d 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -8,15 +8,79 @@ #include "xsc_defs.h" #include "xsc_dev.h" #include "xsc_ethdev.h" +#include "xsc_utils.h" + +#include "xsc_ctrl.h" + +const struct eth_dev_ops xsc_dev_ops = { +}; static int xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params) { struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params; struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); + struct xsc_dev_config *config = &priv->config; + struct rte_ether_addr mac; priv->repr_port = repr_port; repr_port->drv_data = eth_dev; + priv->xdev = repr_port->xdev; + priv->mtu = RTE_ETHER_MTU; + priv->funcid_type = (repr_port->info.funcid & FUNCID_TYPE_MASK) >> 14; + priv->funcid = repr_port->info.funcid & FUNCID_MASK; + if (repr_port->info.port_type == XSC_PORT_TYPE_UPLINK || + repr_port->info.port_type == XSC_PORT_TYPE_UPLINK_BOND) + priv->eth_type = RTE_ETH_REPRESENTOR_PF; + else + priv->eth_type = RTE_ETH_REPRESENTOR_VF; + priv->representor_id = repr_port->info.repr_id; + priv->dev_data = eth_dev->data; + priv->ifindex = repr_port->info.ifindex; + + eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; + eth_dev->data->mac_addrs = priv->mac; + if (rte_is_zero_ether_addr(eth_dev->data->mac_addrs)) { + if (priv->ifindex > 0) { + int ret = xsc_get_mac(mac.addr_bytes, priv->ifindex); + if (ret != 0) { + PMD_DRV_LOG(ERR, "port %u cannot get MAC address", + eth_dev->data->port_id); + return -ENODEV; + } + } else { + rte_eth_random_addr(mac.addr_bytes); + } + } + + xsc_mac_addr_add(eth_dev, &mac, 0); + + if (priv->ifindex > 0) + xsc_get_mtu(&priv->mtu, priv->ifindex); + + config->hw_csum = 1; + + config->pph_flag = priv->xdev->devargs.pph_mode; + if ((config->pph_flag & XSC_TX_PPH) != 0) { + config->tso = 0; + } else { + config->tso = 1; + if (config->tso) + config->tso_max_payload_sz = 1500; + } + + priv->representor = !!priv->eth_type; + if (priv->representor) { + eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; + eth_dev->data->representor_id = priv->representor_id; + eth_dev->data->backer_port_id = eth_dev->data->port_id; + } + eth_dev->dev_ops = &xsc_dev_ops; + + eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; + eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; + + rte_eth_dev_probing_finish(eth_dev); return 0; } diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h index a05a63193c..7c7e71d618 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -5,11 +5,41 @@ #ifndef _XSC_ETHDEV_H_ #define _XSC_ETHDEV_H_ +struct xsc_dev_config { + uint8_t pph_flag; + unsigned int hw_csum:1; + unsigned int tso:1; + unsigned int tso_max_payload_sz; +}; + struct xsc_ethdev_priv { struct rte_eth_dev *eth_dev; struct rte_pci_device *pci_dev; struct xsc_dev *xdev; struct xsc_repr_port *repr_port; + struct xsc_dev_config config; + struct rte_eth_dev_data *dev_data; + struct rte_ether_addr mac[XSC_MAX_MAC_ADDRESSES]; + struct rte_eth_rss_conf rss_conf; + + int32_t representor_id; + + uint32_t ifindex; + uint16_t mtu; + uint8_t isolated; + uint8_t representor; + + uint32_t mode:7; + uint32_t member_bitmap:8; + uint32_t funcid_type:3; + uint32_t funcid:14; + + uint16_t eth_type; + uint16_t qp_set_id; + + uint16_t num_sq; + uint16_t num_rq; + }; #define TO_XSC_ETHDEV_PRIV(dev) \ diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c index 0d8f3f5be9..e40b0904b7 100644 --- a/drivers/net/xsc/xsc_utils.c +++ b/drivers/net/xsc/xsc_utils.c @@ -15,8 +15,13 @@ #include #include +#include +#include +#include + #include "xsc_log.h" #include "xsc_utils.h" +#include "xsc_defs.h" static int xsc_get_ibdev_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr) @@ -216,3 +221,103 @@ xsc_get_ifindex_by_pci_addr(struct rte_pci_addr *addr, int *ifindex) return 0; } + + +static int +xsc_ifreq_by_ifname(const char *ifname, int req, struct ifreq *ifr) +{ + int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + int ret = 0; + + if (sock == -1) { + rte_errno = errno; + return -rte_errno; + } + rte_strscpy(ifr->ifr_name, ifname, sizeof(ifr->ifr_name)); + ret = ioctl(sock, req, ifr); + if (ret == -1) { + rte_errno = errno; + goto error; + } + close(sock); + return 0; +error: + close(sock); + return -rte_errno; +} + +int +xsc_get_mac(uint8_t *mac, uint32_t ifindex) +{ + struct ifreq request; + struct ifreq *ifr = &request; + char ifname[sizeof(ifr->ifr_name)]; + int ret; + + if (if_indextoname(ifindex, ifname) == NULL) + return -rte_errno; + + ret = xsc_ifreq_by_ifname(ifname, SIOCGIFHWADDR, &request); + if (ret) + return ret; + + memcpy(mac, request.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN); + return 0; +} + +int +xsc_get_mtu(uint16_t *mtu, uint32_t ifindex) +{ + struct ifreq request; + struct ifreq *ifr = &request; + char ifname[sizeof(ifr->ifr_name)]; + int ret; + + if (if_indextoname(ifindex, ifname) == NULL) + return -rte_errno; + + ret = xsc_ifreq_by_ifname(ifname, SIOCGIFMTU, &request); + if (ret) + return ret; + *mtu = request.ifr_mtu; + return 0; +} + +int +xsc_set_mtu(uint16_t mtu, uint32_t ifindex) +{ + struct ifreq request = { .ifr_mtu = mtu, }; + struct ifreq *ifr = &request; + char ifname[sizeof(ifr->ifr_name)]; + + if (if_indextoname(ifindex, ifname) == NULL) + return -rte_errno; + + return xsc_ifreq_by_ifname(ifname, SIOCSIFMTU, &request); +} + +int +xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index) +{ + int i; + rte_errno = EINVAL; + + if (index > XSC_MAX_MAC_ADDRESSES) + return -rte_errno; + + if (rte_is_zero_ether_addr(mac)) + return -rte_errno; + + for (i = 0; i != XSC_MAX_MAC_ADDRESSES; ++i) { + if (i == (int)index) + continue; + if (memcmp(&dev->data->mac_addrs[i], mac, sizeof(*mac))) + continue; + /* Address already configured elsewhere, return with error. */ + rte_errno = EADDRINUSE; + return -rte_errno; + } + + dev->data->mac_addrs[index] = *mac; + return 0; +} diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h index 0d4596489a..8d08cf75b7 100644 --- a/drivers/net/xsc/xsc_utils.h +++ b/drivers/net/xsc/xsc_utils.h @@ -14,4 +14,10 @@ int xsc_get_ifname_by_pci_addr(struct rte_pci_addr *addr, char *ifname); int xsc_get_ifindex_by_ifname(const char *ifname, int *ifindex); int xsc_get_ifindex_by_pci_addr(struct rte_pci_addr *addr, int *ifindex); -#endif /* _XSC_UTILS_H_ */ +int xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index); +int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex); +int xsc_set_mtu(uint16_t mtu, uint32_t ifindex); +int xsc_get_mac(uint8_t *mac, uint32_t ifindex); + + +#endif From patchwork Wed Sep 11 02:07:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143923 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3E13D4595A; Wed, 11 Sep 2024 04:09:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4672842F7A; Wed, 11 Sep 2024 04:08:17 +0200 (CEST) Received: from lf-2-39.ptr.blmpb.com (lf-2-39.ptr.blmpb.com [101.36.218.39]) by mails.dpdk.org (Postfix) with ESMTP id 1019342EFE for ; Wed, 11 Sep 2024 04:08:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020487; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=JqmPYrGYruMIsPzH/BzzalbY9Pg7E4Ot5603oZDFoLs=; b=PRJ6MNFTF/QlOeZxkTBo/6IjlhgU3qW3l7F192gJi0qbwNr8t9lkh7ribaTOM8DIlm9LA6 Vu43/58qQ5ZurRXGEABLAo30RlT9Yf+r8tVsEzwFyQDHB6oPN2t1qAO9TzQM+pvAzT8pYx IoY1U4e+gbfoIDdY/dRh1NkvC/omGsjCNg9evdYed0kR9ECxPZwNS47qkgM+EGIgR2D2uD rjOOq6KqRdVG7y6aShankSZfT1HbIIcWaqIDQluEmkEX7qPUbldccvuX/XNX3SMj8tkPYJ 1IMlWZP1eW4XT5YbMIo8PF4OmwgCX3taAd7ODvzDOlOQGGxUovO46VN9XOICHg== Cc: , , "WanRenyong" Date: Wed, 11 Sep 2024 10:07:31 +0800 Mime-Version: 1.0 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:06 +0800 Subject: [PATCH v2 10/19] net/xsc: add ethdev configure and rxtx queue setup ops From: "WanRenyong" X-Lms-Return-Path: X-Original-From: WanRenyong To: Message-Id: <20240911020740.3950704-11-wanry@yunsilicon.com> X-Mailer: git-send-email 2.25.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc ethdev configure, Rx and Tx queue setup functions. Signed-off-by: WanRenyong --- v2: * fix compilation warning --- drivers/net/xsc/xsc_ethdev.c | 171 +++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_ethdev.h | 6 ++ drivers/net/xsc/xsc_rxtx.h | 115 +++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 drivers/net/xsc/xsc_rxtx.h diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index aacce8b90d..f21b105e83 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -11,8 +11,179 @@ #include "xsc_utils.h" #include "xsc_ctrl.h" +#include "xsc_rxtx.h" + +static int +xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key, + uint8_t rss_key_len) +{ + return 0; +} + +static int +xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev, + struct rte_eth_rss_conf *rss_conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + int ret = 0; + + if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN || + rss_conf->rss_key == NULL) { + PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d", + rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN); + return -EINVAL; + } + + ret = xsc_rss_modify_cmd(priv, rss_conf->rss_key, rss_conf->rss_key_len); + if (ret == 0) { + rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key, + priv->rss_conf.rss_key_len); + priv->rss_conf.rss_key_len = rss_conf->rss_key_len; + priv->rss_conf.rss_hf = rss_conf->rss_hf; + } + + return ret; +} + +static int +xsc_ethdev_configure(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; + int ret; + struct rte_eth_rss_conf *rss_conf; + + priv->num_sq = dev->data->nb_tx_queues; + priv->num_rq = dev->data->nb_rx_queues; + + if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) + dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH; + + if (priv->rss_conf.rss_key == NULL) { + priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN, + RTE_CACHE_LINE_SIZE); + if (priv->rss_conf.rss_key == NULL) { + PMD_DRV_LOG(ERR, "Failed to alloc rss_key"); + rte_errno = ENOMEM; + ret = -rte_errno; + goto error; + } + priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN; + } + + if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) { + rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf; + ret = xsc_ethdev_rss_hash_update(dev, rss_conf); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!"); + rte_errno = -ENOEXEC; + goto error; + } + } + + if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) { + PMD_DRV_LOG(ERR, "xsc pmd do not support vlan filter now!"); + rte_errno = EINVAL; + goto error; + } + + if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) { + PMD_DRV_LOG(ERR, "xsc pmd do not support vlan strip now!"); + rte_errno = EINVAL; + goto error; + } + + priv->txqs = (void *)dev->data->tx_queues; + priv->rxqs = (void *)dev->data->rx_queues; + return 0; + +error: + return -rte_errno; +} + +static int +xsc_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, + uint32_t socket, const struct rte_eth_rxconf *conf, + struct rte_mempool *mp) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_rxq_data *rxq_data = NULL; + uint16_t desc_n; + uint16_t rx_free_thresh; + uint64_t offloads = conf->offloads | + dev->data->dev_conf.rxmode.offloads; + + desc = (desc > XSC_MAX_DESC_NUMBER) ? XSC_MAX_DESC_NUMBER : desc; + desc_n = desc; + + if (!rte_is_power_of_2(desc)) + desc_n = 1 << rte_log2_u32(desc); + + rxq_data = rte_malloc_socket(NULL, sizeof(*rxq_data) + desc_n * sizeof(struct rte_mbuf *), + RTE_CACHE_LINE_SIZE, socket); + if (rxq_data == NULL) { + PMD_DRV_LOG(ERR, "Port %u create rxq idx %d failure", + dev->data->port_id, idx); + rte_errno = ENOMEM; + return -rte_errno; + } + rxq_data->idx = idx; + rxq_data->priv = priv; + (*priv->rxqs)[idx] = rxq_data; + + rx_free_thresh = (conf->rx_free_thresh) ? conf->rx_free_thresh : XSC_RX_FREE_THRESH; + rxq_data->rx_free_thresh = rx_free_thresh; + + rxq_data->elts = (struct rte_mbuf *(*)[desc_n])(rxq_data + 1); + rxq_data->mp = mp; + rxq_data->socket = socket; + + rxq_data->csum = !!(offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM); + rxq_data->hw_timestamp = !!(offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP); + rxq_data->crc_present = 0; + + rxq_data->wqe_n = rte_log2_u32(desc_n); + rxq_data->wqe_s = desc_n; + rxq_data->wqe_m = desc_n - 1; + + dev->data->rx_queues[idx] = rxq_data; + return 0; +} + +static int +xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, + uint32_t socket, const struct rte_eth_txconf *conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq; + uint16_t desc_n; + + desc = (desc > XSC_MAX_DESC_NUMBER) ? XSC_MAX_DESC_NUMBER : desc; + desc_n = desc; + + if (!rte_is_power_of_2(desc)) + desc_n = 1 << rte_log2_u32(desc); + + txq = rte_malloc_socket(NULL, sizeof(*txq) + desc_n * sizeof(struct rte_mbuf *), + RTE_CACHE_LINE_SIZE, socket); + txq->offloads = conf->offloads | dev->data->dev_conf.txmode.offloads; + txq->priv = priv; + txq->socket = socket; + + txq->elts_n = rte_log2_u32(desc_n); + txq->elts_s = desc_n; + txq->elts_m = desc_n - 1; + txq->port_id = dev->data->port_id; + txq->idx = idx; + + (*priv->txqs)[idx] = txq; + return 0; +} const struct eth_dev_ops xsc_dev_ops = { + .dev_configure = xsc_ethdev_configure, + .rx_queue_setup = xsc_ethdev_rx_queue_setup, + .tx_queue_setup = xsc_ethdev_tx_queue_setup, }; static int diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h index 7c7e71d618..10c3d8cc87 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -5,6 +5,10 @@ #ifndef _XSC_ETHDEV_H_ #define _XSC_ETHDEV_H_ +#define XSC_RSS_HASH_KEY_LEN 52 +#define XSC_MAX_DESC_NUMBER 1024 +#define XSC_RX_FREE_THRESH 32 + struct xsc_dev_config { uint8_t pph_flag; unsigned int hw_csum:1; @@ -40,6 +44,8 @@ struct xsc_ethdev_priv { uint16_t num_sq; uint16_t num_rq; + struct xsc_txq_data *(*txqs)[]; + struct xsc_rxq_data *(*rxqs)[]; }; #define TO_XSC_ETHDEV_PRIV(dev) \ diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h new file mode 100644 index 0000000000..9b072e06e0 --- /dev/null +++ b/drivers/net/xsc/xsc_rxtx.h @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_RXTX_H_ +#define _XSC_RXTX_H_ + +struct xsc_cqe { + union { + uint8_t msg_opcode; + struct { + uint8_t error_code:7; + uint8_t is_error:1; + }; + }; + __le32 qp_id:15; + uint8_t rsv:1; + uint8_t se:1; + uint8_t has_pph:1; + uint8_t type:1; + uint8_t with_immdt:1; + uint8_t csum_err:4; + __le32 imm_data; + __le32 msg_len; + __le32 vni; + __le64 ts:48; + __le16 wqe_id; + __le16 rsv2[3]; + __le16 rsv3:15; + uint8_t owner:1; +}; + +struct __rte_cache_aligned xsc_txq_data { + uint16_t idx; /*QP idx */ + uint16_t port_id; + void *cq; /* CQ pointer */ + void *qp; /* QP pointer */ + uint32_t cqn; /* CQ serial number */ + uint32_t qpn; /* QP serial number */ + uint16_t elts_head; /* Current pos in (*elts)[] */ + uint16_t elts_tail; /* Counter of first element awaiting completion */ + uint16_t elts_comp; /* Elts index since last completion request */ + uint16_t elts_s; /* Number of (*elts)[] */ + uint16_t elts_m; /* Mask of (*elts)[] number */ + uint16_t wqe_ci; /* Consumer index for TXQ */ + uint16_t wqe_pi; /* Producer index for TXQ */ + uint16_t wqe_s; /* Number of WQE */ + uint16_t wqe_m; /* Mask of WQE number */ + uint16_t wqe_comp; /* WQE index since last completion request */ + uint16_t cq_ci; /* Consumer index for CQ */ + uint16_t cq_pi; /* Production index for CQ */ + uint16_t cqe_s; /* Number of CQE */ + uint16_t cqe_m; /* Mask of CQE number */ + uint16_t elts_n:4; /* Log 2 of (*elts)[] number */ + uint16_t cqe_n:4; /* Log 2 of CQE number */ + uint16_t wqe_n:4; /* Log 2 of WQE number */ + uint16_t wqe_ds_n:4; /* Log 2 of each WQE DS number */ + uint64_t offloads; /* TXQ offloads */ + struct xsc_wqe *wqes; + volatile struct xsc_cqe *cqes; + volatile uint32_t *qp_db; + volatile uint32_t *cq_db; + struct xsc_ethdev_priv *priv; + uint32_t socket; + uint8_t tso_en:1; /* TSO enable 0-off 1-on */ + uint16_t *fcqs; /* Free completion queue. */ + struct rte_mbuf *elts[0]; /* Storage for queued packets, for free */ +}; + +struct xsc_cqe_u64 { + struct xsc_cqe cqe0; + struct xsc_cqe cqe1; +}; + +struct __rte_cache_aligned xsc_rxq_data { + uint16_t idx; /*QP idx */ + uint16_t port_id; + void *cq; /* CQ pointer */ + void *qp; /* QP pointer */ + uint32_t cqn; /* CQ serial number */ + uint32_t qpn; /* QP serial number */ + uint16_t wqe_s; /* Number of WQE */ + uint16_t wqe_m; /* Mask of WQE number */ + uint16_t cqe_s; /* Number of CQE */ + uint16_t cqe_m; /* Mask of CQE number */ + uint16_t wqe_n:4; /* Log 2 of WQE number */ + uint16_t sge_n:4; /* Log 2 of each WQE DS number */ + uint16_t cqe_n:4; /* Log 2 of CQE number */ + volatile uint32_t *rq_db; + volatile uint32_t *cq_db; + uint32_t rq_ci; + uint32_t rq_pi; + uint16_t cq_ci; + uint16_t rx_free_thresh; + uint16_t nb_rx_hold; + volatile void *wqes; + union { + volatile struct xsc_cqe(*cqes)[]; + volatile struct xsc_cqe_u64(*cqes_u64)[]; + }; + struct rte_mbuf *(*elts)[]; /* Record the mbuf of wqe addr */ + struct rte_mempool *mp; + const struct rte_memzone *rq_pas; /* Palist memory */ + uint32_t socket; + struct xsc_ethdev_priv *priv; + /* attr */ + uint32_t csum:1; /* Checksum offloading enable */ + uint32_t hw_timestamp:1; + uint32_t vlan_strip:1; + uint32_t crc_present:1; /* CRC flag */ + uint32_t rss_hash:1; /* RSS hash enabled */ +}; + +#endif /* _XSC_RXTX_H_ */ + From patchwork Wed Sep 11 02:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143928 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BF4534595A; Wed, 11 Sep 2024 04:09:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E639843249; Wed, 11 Sep 2024 04:08:25 +0200 (CEST) Received: from lf-1-18.ptr.blmpb.com (lf-1-18.ptr.blmpb.com [103.149.242.18]) by mails.dpdk.org (Postfix) with ESMTP id 2DAA542FB1 for ; Wed, 11 Sep 2024 04:08:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020489; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=EoEBLGDNGG8JW52BqI0LVktBTXMMYJUnDa+r8jIAVo8=; b=Brh+LRTjHtW1Xht2mdmFRbd2kDjHlHU+WGbUgT6Z2TVfXaGWMKNg3w0sf5fCNNR0evKmWS +QFOGS9CKUIbsD170CqiErN1UeBXEokX/wq1BGdeT+OtvHs2sKY6p5Pd0lGiLsqLNnS4Kq pkN9GLYbjxuMdQIFhdMlOpH46zWWpadjyVDGwXE79juwyumaihOAPFwxjPTXeZHF7Zp59R +hYzS8pZbaipORcvurJR9kY5nVoZn6qMJtdYX12pc71GObnxNJvj/jU5Bhkj+UTPX9Qn3a 3BPuLUgI2kGsFQ9BWWs317IRLARpLvjmW2c2G7eEJwFXutDfLQrqYm6ToNwzPg== Mime-Version: 1.0 X-Original-From: WanRenyong To: Message-Id: <20240911020740.3950704-12-wanry@yunsilicon.com> X-Mailer: git-send-email 2.25.1 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:07 +0800 Cc: , , "WanRenyong" Subject: [PATCH v2 11/19] net/xsc: add mailbox and structure X-Lms-Return-Path: From: "WanRenyong" Date: Wed, 11 Sep 2024 10:07:32 +0800 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Mailbox is a communication channel between driver and firmware. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_ctrl.c | 8 ++++++++ drivers/net/xsc/xsc_ctrl.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/net/xsc/xsc_ctrl.c b/drivers/net/xsc/xsc_ctrl.c index 3e37bd914e..4d5e4b4d07 100644 --- a/drivers/net/xsc/xsc_ctrl.c +++ b/drivers/net/xsc/xsc_ctrl.c @@ -54,3 +54,11 @@ xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode, rte_free(hdr); return ret; } + +int +xsc_mailbox_exec(struct xsc_dev *dev, void *data_in, + int in_len, void *data_out, int out_len) +{ + /* ignore opcode in hdr->attr when cmd = XSC_IOCTL_CMDQ_RAW */ + return xsc_ioctl(dev, XSC_IOCTL_CMDQ_RAW, 0, data_in, in_len, data_out, out_len); +} diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h index d343e1b1a7..a7259c5fcb 100644 --- a/drivers/net/xsc/xsc_ctrl.h +++ b/drivers/net/xsc/xsc_ctrl.h @@ -40,6 +40,35 @@ struct xsc_ioctl_hdr { struct xsc_ioctl_attr attr; }; +/* ioctl */ +struct xsc_inbox_hdr { + __be16 opcode; + uint8_t rsvd[4]; + __be16 opmod; +}; + +struct xsc_outbox_hdr { + uint8_t status; + uint8_t rsvd[3]; + __be32 syndrome; +}; + +/* ioctl mbox */ +struct xsc_ioctl_mbox_in { + struct xsc_inbox_hdr hdr; + __be16 len; + __be16 rsvd; + uint8_t data[]; +}; + +struct xsc_ioctl_mbox_out { + struct xsc_outbox_hdr hdr; + __be32 error; + __be16 len; + __be16 rsvd; + uint8_t data[]; +}; + struct xsc_ioctl_data_tl { uint16_t table; uint16_t opmod; @@ -82,5 +111,7 @@ struct xsc_ioctl_get_hwinfo { int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode, void *data_in, int in_len, void *data_out, int out_len); +int xsc_mailbox_exec(struct xsc_dev *dev, void *data_in, + int in_len, void *data_out, int out_len); #endif /* _XSC_CTRL_H_ */ From patchwork Wed Sep 11 02:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143930 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F45E4595A; Wed, 11 Sep 2024 04:10:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8472B43251; Wed, 11 Sep 2024 04:08:28 +0200 (CEST) Received: from lf-1-13.ptr.blmpb.com (lf-1-13.ptr.blmpb.com [103.149.242.13]) by mails.dpdk.org (Postfix) with ESMTP id 47CED42FB1 for ; Wed, 11 Sep 2024 04:08:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020491; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=guudZXzc/qIc/XYPYoatNvikuZKiqe2qVRQhm5U6idQ=; b=TmWCeu7zw8T4IMLNdI1DrKXSPqEol461ZAn7u9sxKhVB8IsFZSpQH5hLcN37SG+W5CK/AT I5UPoMhhV9UuiXPxCwFe2wogd1Nyw0qNH7fPHxDkcC1Vy0hryIpzKrp7NCKdhsb5H/0HgI 3Mll5fQXLZYn+WNplEwXAnjQXOgYOw9fBcTvrbjveUjp1vdmQ2PNwrucp2iNigJdCQqFHG y9QmDmGNstEChcflISyJqG5DCxfN+7nBBbcgFChPlUCMxMaNPjTulJeo7xj70qwAEC0yZf W/j+mEvM1mCMFChKwo0HwUIeU7SHRjHsykYM06KHlJTRR7f84JSnrPvUMXFzkg== Message-Id: <20240911020740.3950704-13-wanry@yunsilicon.com> Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:09 +0800 X-Original-From: WanRenyong From: "WanRenyong" Subject: [PATCH v2 12/19] net/xsc: add ethdev RSS hash ops Date: Wed, 11 Sep 2024 10:07:33 +0800 To: Cc: , , "WanRenyong" X-Lms-Return-Path: Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc ethdev RSS hash config get and update functions. Signed-off-by: WanRenyong --- doc/guides/nics/features/xsc.ini | 3 +++ drivers/net/xsc/xsc_ctrl.h | 27 ++++++++++++++++++++ drivers/net/xsc/xsc_ethdev.c | 43 +++++++++++++++++++++++++++++++- drivers/net/xsc/xsc_ethdev.h | 17 +++++++++++++ drivers/net/xsc/xsc_utils.h | 5 +++- 5 files changed, 93 insertions(+), 2 deletions(-) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index b5c44ce535..bdeb7a984b 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -4,6 +4,9 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +RSS hash = Y +RSS key update = Y +RSS reta update = Y Linux = Y ARMv8 = Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h index a7259c5fcb..c33e625097 100644 --- a/drivers/net/xsc/xsc_ctrl.h +++ b/drivers/net/xsc/xsc_ctrl.h @@ -69,6 +69,33 @@ struct xsc_ioctl_mbox_out { uint8_t data[]; }; +struct xsc_nic_attr { + __be16 caps; + __be16 caps_mask; + uint8_t mac_addr[6]; +}; + +struct xsc_rss_modify_attr { + uint8_t caps_mask; + uint8_t rss_en; + __be16 rqn_base; + __be16 rqn_num; + uint8_t hfunc; + __be32 hash_tmpl; + uint8_t hash_key[52]; +}; + +struct xsc_cmd_modify_nic_hca_mbox_in { + struct xsc_inbox_hdr hdr; + struct xsc_nic_attr nic; + struct xsc_rss_modify_attr rss; +}; + +struct xsc_cmd_modify_nic_hca_mbox_out { + struct xsc_outbox_hdr hdr; + uint8_t rsvd0[4]; +}; + struct xsc_ioctl_data_tl { uint16_t table; uint16_t opmod; diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index f21b105e83..25b2a4c44d 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -17,6 +17,45 @@ static int xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key, uint8_t rss_key_len) { + struct xsc_cmd_modify_nic_hca_mbox_in in = {}; + struct xsc_cmd_modify_nic_hca_mbox_out out = {}; + uint8_t rss_caps_mask = 0; + int ret, key_len = 0; + + in.hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_MODIFY_NIC_HCA); + + key_len = RTE_MIN(rss_key_len, XSC_RSS_HASH_KEY_LEN); + rte_memcpy(in.rss.hash_key, rss_key, key_len); + rss_caps_mask |= BIT(XSC_RSS_HASH_KEY_UPDATE); + + in.rss.caps_mask = rss_caps_mask; + in.rss.rss_en = 1; + in.nic.caps_mask = rte_cpu_to_be_16(BIT(XSC_TBM_CAP_RSS)); + in.nic.caps = in.nic.caps_mask; + + ret = xsc_mailbox_exec(priv->xdev, &in, sizeof(in), &out, sizeof(out)); + if (ret != 0 || out.hdr.status != 0) + return -1; + return 0; +} + +static int +xsc_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev, + struct rte_eth_rss_conf *rss_conf) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + if (!rss_conf) { + rte_errno = EINVAL; + return -rte_errno; + } + if (rss_conf->rss_key != NULL && + rss_conf->rss_key_len >= priv->rss_conf.rss_key_len) { + memcpy(rss_conf->rss_key, priv->rss_conf.rss_key, + priv->rss_conf.rss_key_len); + } + rss_conf->rss_key_len = priv->rss_conf.rss_key_len; + rss_conf->rss_hf = priv->rss_conf.rss_hf; return 0; } @@ -30,7 +69,7 @@ xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev, if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN || rss_conf->rss_key == NULL) { PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d", - rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN); + rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN); return -EINVAL; } @@ -184,6 +223,8 @@ const struct eth_dev_ops xsc_dev_ops = { .dev_configure = xsc_ethdev_configure, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, + .rss_hash_update = xsc_ethdev_rss_hash_update, + .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get, }; static int diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h index 10c3d8cc87..fb92d47dd0 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -9,6 +9,8 @@ #define XSC_MAX_DESC_NUMBER 1024 #define XSC_RX_FREE_THRESH 32 +#define XSC_CMD_OP_MODIFY_NIC_HCA 0x812 + struct xsc_dev_config { uint8_t pph_flag; unsigned int hw_csum:1; @@ -51,4 +53,19 @@ struct xsc_ethdev_priv { #define TO_XSC_ETHDEV_PRIV(dev) \ ((struct xsc_ethdev_priv *)(dev)->data->dev_private) +enum { + XSC_TBM_CAP_HASH_PPH = 0, + XSC_TBM_CAP_RSS, + XSC_TBM_CAP_PP_BYPASS, + XSC_TBM_CAP_PCT_DROP_CONFIG, +}; + +enum { + XSC_RSS_HASH_KEY_UPDATE = 0, + XSC_RSS_HASH_TEMP_UPDATE, + XSC_RSS_HASH_FUNC_UPDATE, + XSC_RSS_RXQ_UPDATE, + XSC_RSS_RXQ_DROP, +}; + #endif /* _XSC_ETHDEV_H_ */ diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h index 8d08cf75b7..672ba3871e 100644 --- a/drivers/net/xsc/xsc_utils.h +++ b/drivers/net/xsc/xsc_utils.h @@ -9,6 +9,10 @@ #include +#ifndef BIT +#define BIT(n) (1UL << (n)) +#endif + struct ibv_device *xsc_get_ibv_device(const struct rte_pci_addr *addr); int xsc_get_ifname_by_pci_addr(struct rte_pci_addr *addr, char *ifname); int xsc_get_ifindex_by_ifname(const char *ifname, int *ifindex); @@ -19,5 +23,4 @@ int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex); int xsc_set_mtu(uint16_t mtu, uint32_t ifindex); int xsc_get_mac(uint8_t *mac, uint32_t ifindex); - #endif From patchwork Wed Sep 11 02:07:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143927 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DBD444595A; Wed, 11 Sep 2024 04:09:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B525542FFF; Wed, 11 Sep 2024 04:08:23 +0200 (CEST) Received: from lf-1-15.ptr.blmpb.com (lf-1-15.ptr.blmpb.com [103.149.242.15]) by mails.dpdk.org (Postfix) with ESMTP id 7178242F91 for ; Wed, 11 Sep 2024 04:08:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020492; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=iXwaFSpcZe3sfNvdMjwny5cw+7TRgcDVK4BqDf/nuPA=; b=UQiL7mhYobhh417KasTtqAeZfolL81gSCjian85J3APkvMcOMv0ukzB/Lh2EwPpPRt7qB7 81N45mXH1CW/DKx6r/UaspdefnsEcsBBHJ1Ih7RjcQFgCHJ5MKvXPOEEogWcPLH6uwwcTS E7lpmmZa03p2MtW/12k0IJaKl3dBX4b4Z3sjVKBE79uQJB4eYfWW6DuwuyVghF1JVU9l0y vNTIyp4yQ1jjzV+XhxHa6mXj8/Cig0C2kSBS05kgWo+xsNOX9OYE18Zurja59ltbtL4hED ZOcpMjQWiP/wKRNNOByZTl1uWEPPuCx/MkpHgI0xM88N2gGXIwTcvaIGIF1Zxw== Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:11 +0800 From: "WanRenyong" Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 Cc: , , "WanRenyong" , "Rong Qian" X-Original-From: WanRenyong Subject: [PATCH v2 13/19] net/xsc: add ethdev start and stop ops Date: Wed, 11 Sep 2024 10:07:34 +0800 Message-Id: <20240911020740.3950704-14-wanry@yunsilicon.com> X-Lms-Return-Path: To: X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc ethdev start and stop function. Signed-off-by: WanRenyong Signed-off-by: Rong Qian --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_ctrl.h | 152 ++++++- drivers/net/xsc/xsc_defs.h | 2 + drivers/net/xsc/xsc_dev.h | 3 + drivers/net/xsc/xsc_ethdev.c | 740 ++++++++++++++++++++++++++++++++++- drivers/net/xsc/xsc_ethdev.h | 10 + drivers/net/xsc/xsc_rxtx.c | 22 ++ drivers/net/xsc/xsc_rxtx.h | 68 +++- 8 files changed, 994 insertions(+), 4 deletions(-) create mode 100644 drivers/net/xsc/xsc_rxtx.c diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index f38ebdfe0f..5f15c8def5 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -11,6 +11,7 @@ sources = files( 'xsc_dev.c', 'xsc_utils.c', 'xsc_ctrl.c', + 'xsc_rxtx.c', ) libnames = ['ibverbs'] diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h index c33e625097..e51847d68f 100644 --- a/drivers/net/xsc/xsc_ctrl.h +++ b/drivers/net/xsc/xsc_ctrl.h @@ -5,7 +5,17 @@ #ifndef _XSC_CTRL_H_ #define _XSC_CTRL_H_ +#include +#include +#include +#include +#include #include +#include + +#ifndef PAGE_SIZE +#define PAGE_SIZE 4096 +#endif #define XSC_IOCTL_CHECK_FIELD 0x01234567 @@ -25,6 +35,17 @@ enum xsc_ioctl_opmod { XSC_IOCTL_OP_GET_LOCAL, }; +#define XSC_DIV_ROUND_UP(n, d) ({ \ + typeof(d) _d = (d); \ + typeof(n) _n = (n); \ + ((_n) + (_d) - 1) / (_d); \ +}) + +enum { + XSC_IOCTL_SET_QP_STATUS = 0x200, + XSC_IOCTL_SET_MAX +}; + struct xsc_ioctl_attr { uint16_t opcode; /* ioctl cmd */ uint16_t length; /* data length */ @@ -40,7 +61,18 @@ struct xsc_ioctl_hdr { struct xsc_ioctl_attr attr; }; -/* ioctl */ +enum { + XSC_QUEUE_TYPE_RDMA_RC = 0, + XSC_QUEUE_TYPE_RDMA_MAD = 1, + XSC_QUEUE_TYPE_RAW = 2, + XSC_QUEUE_TYPE_VIRTIO_NET = 3, + XSC_QUEUE_TYPE_VIRTIO_BLK = 4, + XSC_QUEUE_TYPE_RAW_TPE = 5, + XSC_QUEUE_TYPE_RAW_TSO = 6, + XSC_QUEUE_TYPE_RAW_TX = 7, + XSC_QUEUE_TYPE_INVALID = 0xFF, +}; + struct xsc_inbox_hdr { __be16 opcode; uint8_t rsvd[4]; @@ -53,7 +85,6 @@ struct xsc_outbox_hdr { __be32 syndrome; }; -/* ioctl mbox */ struct xsc_ioctl_mbox_in { struct xsc_inbox_hdr hdr; __be16 len; @@ -96,6 +127,54 @@ struct xsc_cmd_modify_nic_hca_mbox_out { uint8_t rsvd0[4]; }; +struct xsc_create_qp_request { + __be16 input_qpn; + __be16 pa_num; + uint8_t qp_type; + uint8_t log_sq_sz; + uint8_t log_rq_sz; + uint8_t dma_direct; + __be32 pdn; + __be16 cqn_send; + __be16 cqn_recv; + __be16 glb_funcid; + uint8_t page_shift; + uint8_t rsvd; + __be64 pas[]; +}; + +struct xsc_create_multiqp_mbox_in { + struct xsc_inbox_hdr hdr; + __be16 qp_num; + uint8_t qp_type; + uint8_t rsvd; + __be32 req_len; + uint8_t data[]; +}; + +struct xsc_create_multiqp_mbox_out { + struct xsc_outbox_hdr hdr; + __be32 qpn_base; +}; + + +struct xsc_destroy_qp_mbox_in { + struct xsc_inbox_hdr hdr; + __be32 qpn; + uint8_t rsvd[4]; +}; + +struct xsc_destroy_qp_mbox_out { + struct xsc_outbox_hdr hdr; + uint8_t rsvd[8]; +}; + +struct xsc_ioctl_qp_range { + uint16_t opcode; + int num; + uint32_t qpn; +}; + struct xsc_ioctl_data_tl { uint16_t table; uint16_t opmod; @@ -136,6 +215,75 @@ struct xsc_ioctl_get_hwinfo { uint8_t esw_mode; }; +/* for xscdv providers */ +#if !HAVE_XSC_DV_PROVIDER +enum xscdv_obj_type { + XSCDV_OBJ_QP = 1 << 0, + XSCDV_OBJ_CQ = 1 << 1, + XSCDV_OBJ_SRQ = 1 << 2, + XSCDV_OBJ_RWQ = 1 << 3, + XSCDV_OBJ_DM = 1 << 4, + XSCDV_OBJ_AH = 1 << 5, + XSCDV_OBJ_PD = 1 << 6, +}; + +enum xsc_qp_create_flags { + XSC_QP_CREATE_RAWPACKE_TSO = 1 << 0, + XSC_QP_CREATE_RAWPACKET_TSO = 1 << 0, + XSC_QP_CREATE_RAWPACKET_TX = 1 << 1, +}; + +struct xscdv_cq_init_attr { + uint64_t comp_mask; /* Use enum xscdv_cq_init_attr_mask */ + uint8_t cqe_comp_res_format; /* Use enum xscdv_cqe_comp_res_format */ + uint32_t flags; + uint16_t cqe_size; /* when XSCDV_CQ_INIT_ATTR_MASK_CQE_SIZE set */ +}; + +struct xscdv_obj { + struct { + struct ibv_qp *in; + struct xscdv_qp *out; + } qp; + struct { + struct ibv_cq *in; + struct xscdv_cq *out; + } cq; +}; + +struct xscdv_qp { + __le32 *dbrec; + struct { + void *buf; + uint32_t wqe_cnt; + uint32_t stride; + __le32 *db; + } sq; + struct { + void *buf; + uint32_t wqe_cnt; + uint32_t stride; + __le32 *db; + } rq; + uint64_t comp_mask; + uint32_t tirn; + uint32_t tisn; + uint32_t rqn; + uint32_t sqn; +}; + +struct xscdv_cq { + void *buf; + __le32 *dbrec; + __le32 *db; + uint32_t cqe_cnt; + uint32_t cqe_size; + uint32_t cqn; + uint64_t comp_mask; +}; + +#endif + int xsc_ioctl(struct xsc_dev *dev, int cmd, int opcode, void *data_in, int in_len, void *data_out, int out_len); int xsc_mailbox_exec(struct xsc_dev *dev, void *data_in, diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h index 7dc57e5717..769cbad812 100644 --- a/drivers/net/xsc/xsc_defs.h +++ b/drivers/net/xsc/xsc_defs.h @@ -11,6 +11,8 @@ #define XSC_VFREP_BASE_LOGICAL_PORT 1081 #define XSC_MAX_MAC_ADDRESSES 3 +#define XSC_SEND_WQE_DS 3 +#define XSC_ESEG_EXTRA_DATA_SIZE 48u enum xsc_nic_mode { XSC_NIC_MODE_LEGACY, diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h index f77551f1c5..a24ae582f3 100644 --- a/drivers/net/xsc/xsc_dev.h +++ b/drivers/net/xsc/xsc_dev.h @@ -5,6 +5,9 @@ #ifndef _XSC_DEV_H_ #define _XSC_DEV_H_ +#if HAVE_XSC_DV_PROVIDER +#include +#endif #include #include "xsc_defs.h" diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 25b2a4c44d..35daa16528 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -2,6 +2,8 @@ * Copyright 2024 Yunsilicon Technology Co., Ltd. */ +#include + #include #include "xsc_log.h" @@ -9,10 +11,29 @@ #include "xsc_dev.h" #include "xsc_ethdev.h" #include "xsc_utils.h" - #include "xsc_ctrl.h" #include "xsc_rxtx.h" +static __rte_always_inline struct xsc_rxq_data * +xsc_rxq_get(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + if (priv->rxqs != NULL && (*priv->rxqs)[idx] != NULL) + return (*priv->rxqs)[idx]; + return NULL; +} + +static __rte_always_inline struct xsc_txq_data * +xsc_txq_get(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + if (priv->txqs != NULL && (*priv->txqs)[idx] != NULL) + return (*priv->txqs)[idx]; + return NULL; +} + static int xsc_rss_modify_cmd(struct xsc_ethdev_priv *priv, uint8_t *rss_key, uint8_t rss_key_len) @@ -84,6 +105,31 @@ xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev, return ret; } +static int +xsc_modify_qpn_status(uint32_t qpn, int num, int opcode, struct xsc_dev *xdev) +{ + struct { + struct xsc_ioctl_data_tl tl; + struct xsc_ioctl_qp_range info; + } data_info; + + int ret; + + data_info.tl.opmod = XSC_IOCTL_SET_QP_STATUS; + data_info.info.opcode = opcode; + data_info.info.qpn = qpn; + data_info.info.num = num; + + ret = xsc_ioctl(xdev, XSC_IOCTL_DRV_GET, XSC_IOCTL_SET_QP_STATUS, + &data_info, sizeof(data_info), NULL, 0); + if (ret != 0) { + rte_errno = ret; + PMD_DRV_LOG(ERR, "modify qp status fail, ret = %d\n", ret); + } + + return ret; +} + static int xsc_ethdev_configure(struct rte_eth_dev *dev) { @@ -140,6 +186,685 @@ xsc_ethdev_configure(struct rte_eth_dev *dev) return -rte_errno; } +static int +xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type) +{ +#if HAVE_XSC_DV_PROVIDER + return xscdv_init_obj(obj, obj_type); +#else + (void)obj; + (void)obj_type; + return 0; +#endif +} + +static void +xsc_txq_elts_alloc(struct xsc_txq_data *txq_data) +{ + const uint32_t elts_s = 1 << txq_data->elts_n; + uint32_t i; + + for (i = 0; i < elts_s; ++i) + txq_data->elts[i] = NULL; + txq_data->elts_head = 0; + txq_data->elts_tail = 0; + txq_data->elts_comp = 0; +} + +static void +xsc_txq_elts_free(struct xsc_txq_data *txq_data) +{ + const uint16_t elts_n = 1 << txq_data->elts_n; + const uint16_t elts_m = elts_n - 1; + uint16_t elts_head = txq_data->elts_head; + uint16_t elts_tail = txq_data->elts_tail; + struct rte_mbuf *(*elts)[elts_n] = &txq_data->elts; + + txq_data->elts_head = 0; + txq_data->elts_tail = 0; + txq_data->elts_comp = 0; + + while (elts_tail != elts_head) { + struct rte_mbuf *elt = (*elts)[elts_tail & elts_m]; + rte_pktmbuf_free_seg(elt); + ++elts_tail; + } + PMD_DRV_LOG(DEBUG, "Port %u txq %u free elts", txq_data->port_id, txq_data->idx); +} + +static struct ibv_qp * +xsc_txq_ibv_qp_create(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq_data = xsc_txq_get(dev, idx); + struct ibv_qp *qp_obj = NULL; + struct ibv_qp_init_attr_ex qp_attr = { 0 }; + const int desc = 1 << txq_data->elts_n; + uint64_t tx_offloads = dev->data->dev_conf.txmode.offloads; + + qp_attr.send_cq = txq_data->cq; + qp_attr.recv_cq = txq_data->cq; + qp_attr.cap.max_send_wr = desc; + qp_attr.cap.max_recv_wr = 0; + qp_attr.cap.max_send_sge = 1; + qp_attr.qp_type = IBV_QPT_RAW_PACKET; + qp_attr.pd = priv->xdev->ibv_pd; + qp_attr.sq_sig_all = 0; + + if (tx_offloads & (RTE_ETH_TX_OFFLOAD_TCP_TSO)) { + qp_attr.create_flags = XSC_QP_CREATE_RAWPACKET_TSO; + qp_attr.comp_mask = IBV_QP_INIT_ATTR_PD | IBV_QP_INIT_ATTR_CREATE_FLAGS; + txq_data->tso_en = 1; + PMD_DRV_LOG(DEBUG, "Port %u txq %u, create tso qp", + dev->data->port_id, idx); + } else { + qp_attr.create_flags = XSC_QP_CREATE_RAWPACKET_TX; + qp_attr.comp_mask = IBV_QP_INIT_ATTR_PD | IBV_QP_INIT_ATTR_CREATE_FLAGS; + PMD_DRV_LOG(DEBUG, "Port %u txq %u, create non-tso qp", + dev->data->port_id, idx); + } + + qp_obj = ibv_create_qp_ex(priv->xdev->ibv_ctx, &qp_attr); + if (qp_obj == NULL) { + PMD_DRV_LOG(ERR, "Port %u txq %u, create %s qp fail, errno=%d", + dev->data->port_id, idx, + qp_attr.create_flags & XSC_QP_CREATE_RAWPACKET_TSO ? + "tso" : "non-tso", errno); + + if (!(tx_offloads & (RTE_ETH_TX_OFFLOAD_TCP_TSO))) { + qp_attr.create_flags = XSC_QP_CREATE_RAWPACKET_TSO; + qp_attr.comp_mask = IBV_QP_INIT_ATTR_PD | + IBV_QP_INIT_ATTR_CREATE_FLAGS; + PMD_DRV_LOG(DEBUG, "Port %u txq %u, recreate tso qp", + dev->data->port_id, idx); + + qp_obj = ibv_create_qp_ex(priv->xdev->ibv_ctx, &qp_attr); + if (qp_obj == NULL) + PMD_DRV_LOG(ERR, "Port %u txq %u, recreate tso qp fail, errno=%d", + dev->data->port_id, idx, errno); + else + txq_data->tso_en = 1; + } + } + + return qp_obj; +} + +static int +xsc_txq_ibv_obj_new(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq_data = xsc_txq_get(dev, idx); + struct xsc_hwinfo *hwinfo = &priv->xdev->hwinfo; + struct xscdv_qp qp_info = { 0 }; + struct xscdv_cq cq_info = { 0 }; + struct xscdv_obj obj; + const int desc = 1 << txq_data->elts_n; + uint32_t cqe_n; + int ret = 0; + + cqe_n = desc; + txq_data->cq = ibv_create_cq(priv->xdev->ibv_ctx, cqe_n, NULL, NULL, 0); + if (txq_data->cq == NULL) { + PMD_DRV_LOG(ERR, "Port %u txq %u, create cq fail", + dev->data->port_id, idx); + rte_errno = errno; + goto error; + } + + txq_data->qp = xsc_txq_ibv_qp_create(dev, idx); + if (txq_data->qp == NULL) { + rte_errno = errno; + goto error; + } + + obj.cq.in = txq_data->cq; + obj.cq.out = &cq_info; + obj.qp.in = txq_data->qp; + obj.qp.out = &qp_info; + ret = xsc_init_obj(&obj, XSCDV_OBJ_CQ | XSCDV_OBJ_QP); + if (ret != 0) { + rte_errno = errno; + goto error; + } + + txq_data->cqe_n = rte_log2_u32(cq_info.cqe_cnt); + txq_data->cqe_s = 1 << txq_data->cqe_n; + txq_data->cqe_m = txq_data->cqe_s - 1; + txq_data->qpn = ((struct ibv_qp *)txq_data->qp)->qp_num; + txq_data->wqes = qp_info.sq.buf; + txq_data->wqe_n = rte_log2_u32(qp_info.sq.wqe_cnt); + txq_data->wqe_s = 1 << txq_data->wqe_n; + txq_data->wqe_m = txq_data->wqe_s - 1; + txq_data->wqe_ds_n = rte_log2_u32(hwinfo->send_seg_num); + + /* txq doobell */ + txq_data->qp_db = qp_info.sq.db; + /* cqe doobell */ + txq_data->cq_db = cq_info.db; + txq_data->cqn = cq_info.cqn; + + txq_data->cqes = (volatile struct xsc_cqe *)cq_info.buf; + txq_data->cq_ci = 0; + txq_data->cq_pi = 0; + txq_data->wqe_ci = 0; + txq_data->wqe_pi = 0; + txq_data->wqe_comp = 0; + xsc_modify_qpn_status(txq_data->qpn, 1, XSC_CMD_OP_RTR2RTS_QP, priv->xdev); + dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED; + + PMD_DRV_LOG(INFO, "Port %u create tx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%d", + dev->data->port_id, + txq_data->cqe_s, txq_data->cqe_n, + txq_data->cq_db, txq_data->cqn); + + PMD_DRV_LOG(INFO, "Port %u create tx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%d", + dev->data->port_id, + txq_data->wqe_s, txq_data->wqe_n, + txq_data->qp_db, txq_data->qpn); + + return 0; + +error: + return -rte_errno; +} + +static void +xsc_txq_ibv_obj_release(struct xsc_txq_data *txq_data) +{ + PMD_DRV_LOG(DEBUG, "destroy tx queue %u, portid %u\n", + txq_data->idx, txq_data->port_id); + if (txq_data->qp != NULL) + ibv_destroy_qp(txq_data->qp); + if (txq_data->cq != NULL) + ibv_destroy_cq(txq_data->cq); +} + +static void +xsc_ethdev_txq_release(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq_data = xsc_txq_get(dev, idx); + + if (txq_data == NULL) + return; + xsc_txq_ibv_obj_release(txq_data); + if (txq_data->fcqs != NULL) + rte_free(txq_data->fcqs); + txq_data->fcqs = NULL; + xsc_txq_elts_free(txq_data); + rte_free(txq_data); + (*priv->txqs)[idx] = NULL; + + dev->data->tx_queues[idx] = NULL; + dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED; +} + +static int +xsc_txq_start(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_txq_data *txq_data; + uint16_t i; + int ret; + size_t size; + + for (i = 0; i != priv->num_sq; ++i) { + txq_data = xsc_txq_get(dev, i); + xsc_txq_elts_alloc(txq_data); + ret = xsc_txq_ibv_obj_new(dev, i); + if (ret < 0) + goto error; + + size = txq_data->cqe_s * sizeof(*txq_data->fcqs); + txq_data->fcqs = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); + if (!txq_data->fcqs) { + PMD_DRV_LOG(ERR, "Port %u txq %u alloc fcqs memory failed", + dev->data->port_id, i); + rte_errno = ENOMEM; + goto error; + } + } + + return 0; + +error: + /* Queue resources are released by xsc_ethdev_start calling the stop interface */ + return -rte_errno; +} + +static int +xsc_rxq_elts_alloc(struct xsc_rxq_data *rxq_data) +{ + uint32_t elts_s = rxq_data->wqe_s; + struct rte_mbuf *mbuf; + uint32_t i; + + for (i = 0; (i != elts_s); ++i) { + mbuf = rte_pktmbuf_alloc(rxq_data->mp); + if (mbuf == NULL) { + PMD_DRV_LOG(ERR, "Port %u rxq %u empty mbuf pool", + rxq_data->port_id, rxq_data->idx); + rte_errno = ENOMEM; + goto error; + } + + mbuf->port = rxq_data->port_id; + mbuf->nb_segs = 1; + rte_pktmbuf_data_len(mbuf) = rte_pktmbuf_data_room_size(rxq_data->mp); + rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_room_size(rxq_data->mp); + (*rxq_data->elts)[i] = mbuf; + } + + return 0; +error: + elts_s = i; + for (i = 0; (i != elts_s); ++i) { + if ((*rxq_data->elts)[i] != NULL) + rte_pktmbuf_free_seg((*rxq_data->elts)[i]); + (*rxq_data->elts)[i] = NULL; + } + + PMD_DRV_LOG(ERR, "Port %u rxq %u start failed, free elts", + rxq_data->port_id, rxq_data->idx); + + return -rte_errno; +} + +static void +xsc_rxq_elts_free(struct xsc_rxq_data *rxq_data) +{ + uint16_t i; + + if (rxq_data->elts == NULL) + return; + for (i = 0; i != rxq_data->wqe_s; ++i) { + if ((*rxq_data->elts)[i] != NULL) + rte_pktmbuf_free_seg((*rxq_data->elts)[i]); + (*rxq_data->elts)[i] = NULL; + } + + PMD_DRV_LOG(DEBUG, "Port %u rxq %u free elts", rxq_data->port_id, rxq_data->idx); +} + +static void +xsc_rxq_rss_obj_release(struct xsc_ethdev_priv *priv, struct xsc_rxq_data *rxq_data) +{ + struct xsc_destroy_qp_mbox_in in = { .hdr = { 0 } }; + struct xsc_destroy_qp_mbox_out out = { .hdr = { 0 } }; + int ret, in_len, out_len; + uint32_t qpn = rxq_data->qpn; + + xsc_modify_qpn_status(qpn, 1, XSC_CMD_OP_QP_2RST, priv->xdev); + + in_len = sizeof(struct xsc_destroy_qp_mbox_in); + out_len = sizeof(struct xsc_destroy_qp_mbox_out); + in.hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_DESTROY_QP); + in.qpn = rte_cpu_to_be_32(rxq_data->qpn); + + ret = xsc_mailbox_exec(priv->xdev, &in, in_len, &out, out_len); + if (ret != 0 || out.hdr.status != 0) { + PMD_DRV_LOG(ERR, "release rss rq failed, port id=%d, " + "qid=%d, err=%d, out.status=%u\n", + rxq_data->port_id, rxq_data->idx, ret, out.hdr.status); + rte_errno = ENOEXEC; + return; + } + + if (rxq_data->rq_pas != NULL) + rte_memzone_free(rxq_data->rq_pas); + + if (rxq_data->cq != NULL) + ibv_destroy_cq(rxq_data->cq); + rxq_data->cq = NULL; +} + +static void +xsc_ethdev_rxq_release(struct rte_eth_dev *dev, uint16_t idx) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_rxq_data *rxq_data = xsc_rxq_get(dev, idx); + + if (rxq_data == NULL) + return; + xsc_rxq_rss_obj_release(priv, rxq_data); + xsc_rxq_elts_free(rxq_data); + rte_free(rxq_data); + (*priv->rxqs)[idx] = NULL; + + dev->data->rx_queues[idx] = NULL; + dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STOPPED; +} + +static void +xsc_rxq_initialize(struct xsc_ethdev_priv *priv, struct xsc_rxq_data *rxq_data) +{ + const uint32_t wqe_n = rxq_data->wqe_s; + uint32_t i; + uint32_t seg_len = 0; + struct xsc_hwinfo *hwinfo = &priv->xdev->hwinfo; + uint32_t rx_ds_num = hwinfo->recv_seg_num; + uint32_t log2ds = rte_log2_u32(rx_ds_num); + uintptr_t addr; + struct rte_mbuf *mbuf; + volatile struct xsc_wqe_data_seg *seg; + + for (i = 0; (i != wqe_n); ++i) { + mbuf = (*rxq_data->elts)[i]; + seg = &((volatile struct xsc_wqe_data_seg *)rxq_data->wqes)[i * rx_ds_num]; + addr = (uintptr_t)rte_pktmbuf_iova(mbuf); + seg_len = rte_pktmbuf_data_len(mbuf); + *seg = (struct xsc_wqe_data_seg){ + .va = rte_cpu_to_le_64(addr), + .seg_len = rte_cpu_to_le_32(seg_len), + .lkey = 0, + }; + } + + rxq_data->rq_ci = wqe_n; + rxq_data->sge_n = rte_log2_u32(rx_ds_num); + + rte_io_wmb(); + union xsc_recv_doorbell recv_db = { + .recv_data = 0 + }; + + recv_db.next_pid = wqe_n << log2ds; + recv_db.qp_num = rxq_data->qpn; + *rxq_data->rq_db = rte_cpu_to_le_32(recv_db.recv_data); +} + +static int +xsc_rxq_rss_qp_create(struct rte_eth_dev *dev) +{ + struct xsc_create_multiqp_mbox_in *in; + struct xsc_create_qp_request *req; + struct xsc_create_multiqp_mbox_out *out; + uint8_t log_ele; + uint64_t iova; + int wqe_n; + int in_len, out_len, cmd_len; + int entry_total_len, entry_len; + uint8_t log_rq_sz, log_sq_sz = 0; + int j, ret; + uint16_t i, pa_num; + int rqn_base; + size_t page_size = PAGE_SIZE; + struct xsc_rxq_data *rxq_data; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_hwinfo *hwinfo = &priv->xdev->hwinfo; + int port_id = dev->data->port_id; + char name[64] = { 0 }; + + /* paslen */ + rxq_data = xsc_rxq_get(dev, 0); + log_ele = rte_log2_u32(sizeof(struct xsc_wqe_data_seg)); + wqe_n = rxq_data->wqe_s; + log_rq_sz = rte_log2_u32(wqe_n * hwinfo->recv_seg_num); + + pa_num = XSC_DIV_ROUND_UP((1 << (log_rq_sz + log_sq_sz + log_ele)), page_size); + entry_len = sizeof(struct xsc_create_qp_request) + + sizeof(uint64_t) * pa_num; + entry_total_len = entry_len * priv->num_rq; + + in_len = sizeof(struct xsc_create_multiqp_mbox_in) + entry_total_len; + out_len = sizeof(struct xsc_create_multiqp_mbox_out) + entry_total_len; + cmd_len = RTE_MAX(in_len, out_len); + in = rte_zmalloc(NULL, cmd_len, RTE_CACHE_LINE_SIZE); + if (in == NULL) { + rte_errno = ENOMEM; + PMD_DRV_LOG(ERR, "Alloc rss qp create cmd memory failed\n"); + goto error; + } + + in->qp_num = rte_cpu_to_be_16((uint16_t)priv->num_rq); + in->qp_type = XSC_QUEUE_TYPE_RAW; + in->req_len = rte_cpu_to_be_32(cmd_len); + + for (i = 0; i < priv->num_rq; i++) { + rxq_data = (*priv->rxqs)[i]; + req = (struct xsc_create_qp_request *)(&in->data[0] + entry_len * i); + req->input_qpn = rte_cpu_to_be_16(0); /* useless for eth */ + req->pa_num = rte_cpu_to_be_16(pa_num); + req->qp_type = XSC_QUEUE_TYPE_RAW; + req->log_rq_sz = log_rq_sz; + req->cqn_recv = rte_cpu_to_be_16((uint16_t)rxq_data->cqn); + req->cqn_send = req->cqn_recv; + req->glb_funcid = rte_cpu_to_be_16((uint16_t)hwinfo->func_id); + /* alloc pas addr */ + sprintf(name, "wqe_mem_rx_%d_%d", port_id, i); + rxq_data->rq_pas = rte_memzone_reserve_aligned(name, + (page_size * pa_num), SOCKET_ID_ANY, 0, page_size); + if (rxq_data->rq_pas == NULL) { + rte_errno = ENOMEM; + PMD_DRV_LOG(ERR, "Alloc rxq pas memory failed\n"); + goto error; + } + + iova = rxq_data->rq_pas->iova; + for (j = 0; j < pa_num; j++) + req->pas[j] = rte_cpu_to_be_64(iova + j * page_size); + } + + in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_CREATE_MULTI_QP); + out = (struct xsc_create_multiqp_mbox_out *)in; + ret = xsc_mailbox_exec(priv->xdev, in, in_len, out, out_len); + if (ret != 0 || out->hdr.status != 0) { + PMD_DRV_LOG(ERR, "Create rss rq failed, port id=%d, " + "qp_num=%d, type=%d, err=%d, out.status=%u\n", + port_id, priv->num_rq, XSC_QUEUE_TYPE_RAW, ret, out->hdr.status); + rte_errno = ENOEXEC; + goto error; + } + rqn_base = rte_be_to_cpu_32(out->qpn_base) & 0xffffff; + + for (i = 0; i < priv->num_rq; i++) { + rxq_data = xsc_rxq_get(dev, i); + rxq_data->wqes = rxq_data->rq_pas->addr; + rxq_data->rq_db = (uint32_t *)((uint8_t *)priv->xdev->bar_addr + + XSC_RXQ_DB_PF_OFFSET); + rxq_data->qpn = rqn_base + i; + xsc_modify_qpn_status(rxq_data->qpn, 1, XSC_CMD_OP_RTR2RTS_QP, + priv->xdev); + xsc_rxq_initialize(priv, rxq_data); + rxq_data->cq_ci = 0; + priv->dev_data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED; + PMD_DRV_LOG(INFO, "Port %u create rx qp, wqe_s:%d, wqe_n:%d, qp_db=%p, qpn:%d", + dev->data->port_id, + rxq_data->wqe_s, rxq_data->wqe_n, + rxq_data->rq_db, rxq_data->qpn); + } + + if (in != NULL) + rte_free(in); + return 0; + +error: + if (in != NULL) + rte_free(in); + return -rte_errno; +} + +static int +xsc_rxq_rss_obj_new(struct rte_eth_dev *dev) +{ + int ret; + uint32_t i; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t port_id = priv->dev_data->port_id; + struct xsc_rxq_data *rxq_data; + struct xscdv_cq cq_info = { 0 }; + struct xscdv_obj obj; + uint32_t cqe_s; + + /* Create CQ */ + for (i = 0; i < priv->num_rq; ++i) { + rxq_data = xsc_rxq_get(dev, i); + cqe_s = rxq_data->wqe_s; + rxq_data->cq = ibv_create_cq(priv->xdev->ibv_ctx, cqe_s, NULL, NULL, 0); + if (rxq_data->cq == NULL) { + PMD_DRV_LOG(ERR, "Port %u rxq %u create cq fail", port_id, i); + rte_errno = errno; + goto error; + } + obj.cq.in = rxq_data->cq; + obj.cq.out = &cq_info; + ret = xsc_init_obj(&obj, XSCDV_OBJ_CQ); + if (ret) { + rte_errno = errno; + goto error; + } + + rxq_data->cqe_n = rte_log2_u32(cq_info.cqe_cnt); + rxq_data->cqe_s = 1 << rxq_data->cqe_n; + rxq_data->cqe_m = rxq_data->cqe_s - 1; + rxq_data->cqes = (volatile struct xsc_cqe (*)[])(uintptr_t)cq_info.buf; + rxq_data->cq_db = cq_info.db; + rxq_data->cqn = cq_info.cqn; + PMD_DRV_LOG(INFO, "Port %u create rx cq, cqe_s:%d, cqe_n:%d, cq_db=%p, cqn:%d", + dev->data->port_id, + rxq_data->cqe_s, rxq_data->cqe_n, + rxq_data->cq_db, rxq_data->cqn); + } + + ret = xsc_rxq_rss_qp_create(dev); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Port %u rss rxq create fail", port_id); + goto error; + } + return 0; + +error: + return -rte_errno; +} + +static void +xsc_txq_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + for (i = 0; i != priv->num_sq; ++i) + xsc_ethdev_txq_release(dev, i); + priv->txqs = NULL; +} + +static void +xsc_rxq_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + for (i = 0; i != priv->num_rq; ++i) + xsc_ethdev_rxq_release(dev, i); + priv->rxqs = NULL; +} + +static int +xsc_rxq_start(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_rxq_data *rxq_data; + uint16_t i; + int ret; + + for (i = 0; i != priv->num_rq; ++i) { + rxq_data = xsc_rxq_get(dev, i); + if (dev->data->rx_queue_state[i] != RTE_ETH_QUEUE_STATE_STARTED) { + ret = xsc_rxq_elts_alloc(rxq_data); + if (ret != 0) + goto error; + } + } + + ret = xsc_rxq_rss_obj_new(dev); + if (ret != 0) + goto error; + + return 0; +error: + /* Queue resources are released by xsc_ethdev_start calling the stop interface */ + return -rte_errno; +} + +static int +xsc_ethdev_start(struct rte_eth_dev *dev) +{ + int ret; + + ret = xsc_txq_start(dev); + if (ret) { + PMD_DRV_LOG(ERR, "Port %u txq start failed: %s", + dev->data->port_id, strerror(rte_errno)); + goto error; + } + + ret = xsc_rxq_start(dev); + if (ret) { + PMD_DRV_LOG(ERR, "Port %u Rx queue start failed: %s", + dev->data->port_id, strerror(rte_errno)); + goto error; + } + + dev->data->dev_started = 1; + + rte_wmb(); + dev->rx_pkt_burst = xsc_rx_burst; + dev->tx_pkt_burst = xsc_tx_burst; + + return 0; + +error: + dev->data->dev_started = 0; + xsc_txq_stop(dev); + xsc_rxq_stop(dev); + return -rte_errno; +} + +static int +xsc_ethdev_stop(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t i; + + PMD_DRV_LOG(DEBUG, "Port %u stopping", dev->data->port_id); + dev->data->dev_started = 0; + dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; + dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; + rte_wmb(); + + rte_delay_us_sleep(1000 * priv->num_rq); + for (i = 0; i < priv->num_rq; ++i) + dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; + for (i = 0; i < priv->num_sq; ++i) + dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED; + return 0; +} + +static int +xsc_ethdev_close(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + PMD_DRV_LOG(DEBUG, "Port %u closing", dev->data->port_id); + dev->rx_pkt_burst = rte_eth_pkt_burst_dummy; + dev->tx_pkt_burst = rte_eth_pkt_burst_dummy; + rte_wmb(); + + rte_delay_us_sleep(1000); + xsc_txq_stop(dev); + rte_delay_us_sleep(1000); + xsc_rxq_stop(dev); + + if (priv->rss_conf.rss_key != NULL) + rte_free(priv->rss_conf.rss_key); + + /* priv is released in rte_eth_dev_release_port */ + + dev->data->mac_addrs = NULL; + return 0; +} + static int xsc_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, uint32_t socket, const struct rte_eth_rxconf *conf, @@ -219,10 +944,23 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, return 0; } +static int +xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev, + __rte_unused int wait_to_complete) +{ + return 0; +} + const struct eth_dev_ops xsc_dev_ops = { .dev_configure = xsc_ethdev_configure, + .dev_start = xsc_ethdev_start, + .dev_stop = xsc_ethdev_stop, + .dev_close = xsc_ethdev_close, + .link_update = xsc_ethdev_link_update, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, + .rx_queue_release = xsc_ethdev_rxq_release, + .tx_queue_release = xsc_ethdev_txq_release, .rss_hash_update = xsc_ethdev_rss_hash_update, .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get, }; diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h index fb92d47dd0..00d3671c31 100644 --- a/drivers/net/xsc/xsc_ethdev.h +++ b/drivers/net/xsc/xsc_ethdev.h @@ -5,7 +5,17 @@ #ifndef _XSC_ETHDEV_H_ #define _XSC_ETHDEV_H_ +#include "xsc_dev.h" +#include "xsc_utils.h" +#include "xsc_defs.h" + #define XSC_RSS_HASH_KEY_LEN 52 +#define XSC_RXQ_DB_PF_OFFSET 0x4804000 + +#define XSC_CMD_OP_DESTROY_QP 0x501 +#define XSC_CMD_OP_RTR2RTS_QP 0x504 +#define XSC_CMD_OP_QP_2RST 0x50A +#define XSC_CMD_OP_CREATE_MULTI_QP 0x515 #define XSC_MAX_DESC_NUMBER 1024 #define XSC_RX_FREE_THRESH 32 diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c new file mode 100644 index 0000000000..66b1511c6a --- /dev/null +++ b/drivers/net/xsc/xsc_rxtx.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#include "xsc_log.h" +#include "xsc_defs.h" +#include "xsc_dev.h" +#include "xsc_ethdev.h" +#include "xsc_rxtx.h" + +uint16_t +xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) +{ + return 0; +} + +uint16_t +xsc_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) +{ + return 0; +} + diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h index 9b072e06e0..0b2fded42b 100644 --- a/drivers/net/xsc/xsc_rxtx.h +++ b/drivers/net/xsc/xsc_rxtx.h @@ -5,6 +5,61 @@ #ifndef _XSC_RXTX_H_ #define _XSC_RXTX_H_ +struct xsc_send_wqe_ctrl_seg { + __le32 msg_opcode:8; + __le32 with_immdt:1; + __le32 csum_en:2; + __le32 ds_data_num:5; + __le32 wqe_id:16; + __le32 msg_len; + union { + __le32 opcode_data; + struct { + uint8_t has_pph:1; + uint8_t so_type:1; + __le16 so_data_size:14; + uint8_t rsv1:8; + uint8_t so_hdr_len:8; + }; + struct { + __le16 desc_id; + __le16 is_last_wqe:1; + __le16 dst_qp_id:15; + }; + }; + uint8_t se:1; + uint8_t ce:1; + __le32 rsv2:30; +}; + +struct xsc_wqe_data_seg { + union { + uint32_t in_line : 1; + struct { + uint32_t rsv1 : 1; + __le32 seg_len : 31; + __le32 lkey; + __le64 va; + }; + struct { + uint32_t rsv2 : 1; + uint32_t len : 7; + uint8_t in_line_data[15]; + }; + }; +} __rte_packed; + +struct xsc_wqe { + union { + struct xsc_send_wqe_ctrl_seg cseg; + uint32_t ctrl[4]; + }; + union { + struct xsc_wqe_data_seg dseg[XSC_SEND_WQE_DS]; + uint8_t data[XSC_ESEG_EXTRA_DATA_SIZE]; + }; +} __rte_packed; + struct xsc_cqe { union { uint8_t msg_opcode; @@ -111,5 +166,16 @@ struct __rte_cache_aligned xsc_rxq_data { uint32_t rss_hash:1; /* RSS hash enabled */ }; -#endif /* _XSC_RXTX_H_ */ +union xsc_recv_doorbell { + struct { + uint32_t next_pid : 13; + uint32_t qp_num : 15; + uint32_t rsv : 4; + }; + uint32_t recv_data; +}; + +uint16_t xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n); +uint16_t xsc_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n); +#endif /* _XSC_RXTX_H_ */ From patchwork Wed Sep 11 02:07:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143929 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 374804595A; Wed, 11 Sep 2024 04:09:54 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2FA4842FF3; Wed, 11 Sep 2024 04:08:27 +0200 (CEST) Received: from lf-2-31.ptr.blmpb.com (lf-2-31.ptr.blmpb.com [101.36.218.31]) by mails.dpdk.org (Postfix) with ESMTP id A38CA42FCB for ; Wed, 11 Sep 2024 04:08:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020494; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=Ctm3SKyhtrzWprDOuwD9FV4VcQ979/Bmpb5vftNUSC0=; b=eWWSS+nDG9dV0Iu1Eem898FWcriC46ZMBOwe1Dh8lni4JDw0JduucbwQ6AYiyECZZ/O6+Y R25qBPyGtRCxNiZfihFp1RZuUvq9ceCi/1gVJiBKj+dlnxuzqsB5V2gbAmy7dMF3cHN8th khUJgs5va3c0v0u5tN8W0nmupObMvW2LzF1/+UU14Sy7axySadFgRSDrczNhETPivJ4nTP PKWv+TToV0mdm2EiP/M7XheDD1xi+LZsdgjaGnbrXxuzkD2mVdYrR6bwh9xtOjU/hz0caS X+shxq2sbFfQaIo8BWRzFCZOvZvAXkZpgwkqkI2jaUgCl+W3PBgIJkLxa3aLSw== Cc: , , "WanRenyong" , "Xiaoxiong Zhang" From: "WanRenyong" Message-Id: <20240911020740.3950704-15-wanry@yunsilicon.com> X-Original-From: WanRenyong To: Subject: [PATCH v2 14/19] net/xsc: add ethdev Rx burst Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:12 +0800 Date: Wed, 11 Sep 2024 10:07:35 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 X-Lms-Return-Path: X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc PMD receive function. Signed-off-by: WanRenyong Signed-off-by: Xiaoxiong Zhang --- drivers/net/xsc/xsc_rxtx.c | 189 ++++++++++++++++++++++++++++++++++++- drivers/net/xsc/xsc_rxtx.h | 9 ++ 2 files changed, 197 insertions(+), 1 deletion(-) diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c index 66b1511c6a..28360e62ff 100644 --- a/drivers/net/xsc/xsc_rxtx.c +++ b/drivers/net/xsc/xsc_rxtx.c @@ -7,11 +7,198 @@ #include "xsc_dev.h" #include "xsc_ethdev.h" #include "xsc_rxtx.h" +#include "xsc_utils.h" +#include "xsc_ctrl.h" + +#define XSC_CQE_OWNER_MASK 0x1 +#define XSC_CQE_OWNER_HW 0x2 +#define XSC_CQE_OWNER_SW 0x4 +#define XSC_CQE_OWNER_ERR 0x8 + +#define XSC_MAX_RX_BURST_MBUFS 64 + +static __rte_always_inline int +check_cqe_own(volatile struct xsc_cqe *cqe, const uint16_t cqe_n, + const uint16_t ci) + +{ + if (unlikely(((cqe->owner & XSC_CQE_OWNER_MASK) != + ((ci >> cqe_n) & XSC_CQE_OWNER_MASK)))) + return XSC_CQE_OWNER_HW; + + rte_io_rmb(); + if (cqe->msg_len <= 0 && cqe->is_error) + return XSC_CQE_OWNER_ERR; + + return XSC_CQE_OWNER_SW; +} + +static inline void +xsc_cq_to_mbuf(struct xsc_rxq_data *rxq, struct rte_mbuf *pkt, + volatile struct xsc_cqe *cqe) +{ + uint32_t rss_hash_res = 0; + pkt->port = rxq->port_id; + if (rxq->rss_hash) { + rss_hash_res = rte_be_to_cpu_32(cqe->vni); + if (rss_hash_res) { + pkt->hash.rss = rss_hash_res; + pkt->ol_flags |= RTE_MBUF_F_RX_RSS_HASH; + } + } +} + +static inline int +xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct xsc_cqe *cqe) +{ + int len; + + do { + len = 0; + int ret; + + ret = check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci); + if (unlikely(ret != XSC_CQE_OWNER_SW)) { + if (unlikely(ret == XSC_CQE_OWNER_ERR)) { + /* TODO */ + if (ret == XSC_CQE_OWNER_HW || + ret == -1) + return 0; + } else { + return 0; + } + } + + rxq->cq_ci += 1; + len = rte_le_to_cpu_32(cqe->msg_len); + return len; + } while (1); +} + +static __rte_always_inline void +xsc_pkt_info_sync(struct rte_mbuf *rep, struct rte_mbuf *seg) +{ + if (rep != NULL && seg != NULL) { + rep->data_len = seg->data_len; + rep->pkt_len = seg->pkt_len; + rep->data_off = seg->data_off; + rep->port = seg->port; + } +} uint16_t xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) { - return 0; + struct xsc_rxq_data *rxq = dpdk_rxq; + const uint32_t wqe_m = rxq->wqe_m; + const uint32_t cqe_m = rxq->cqe_m; + const uint32_t sge_n = rxq->sge_n; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *seg = NULL; + volatile struct xsc_cqe *cqe = &(*rxq->cqes)[rxq->cq_ci & cqe_m]; + uint32_t nb_pkts = 0; + uint32_t rq_ci = rxq->rq_ci; + int len = 0; + uint32_t cq_ci_two = 0; + int read_cqe_num = 0; + int read_cqe_num_len = 0; + volatile struct xsc_cqe_u64 *cqe_u64 = NULL; + struct rte_mbuf *rep; + + while (pkts_n) { + uint32_t idx = rq_ci & wqe_m; + volatile struct xsc_wqe_data_seg *wqe = + &((volatile struct xsc_wqe_data_seg *)rxq->wqes)[idx << sge_n]; + seg = (*rxq->elts)[idx]; + rte_prefetch0(cqe); + rte_prefetch0(wqe); + + rep = rte_mbuf_raw_alloc(seg->pool); + if (unlikely(rep == NULL)) + break; + + if (!pkt) { + if (read_cqe_num) { + cqe = cqe + 1; + len = read_cqe_num_len; + read_cqe_num = 0; + } else if ((rxq->cq_ci % 2 == 0) && (pkts_n > 1)) { + cq_ci_two = (rxq->cq_ci & rxq->cqe_m) / 2; + cqe_u64 = &(*rxq->cqes_u64)[cq_ci_two]; + cqe = (volatile struct xsc_cqe *)cqe_u64; + len = xsc_rx_poll_len(rxq, cqe); + if (len > 0) { + read_cqe_num_len = xsc_rx_poll_len(rxq, cqe + 1); + if (read_cqe_num_len > 0) + read_cqe_num = 1; + } + } else { + cqe = &(*rxq->cqes)[rxq->cq_ci & rxq->cqe_m]; + len = xsc_rx_poll_len(rxq, cqe); + } + + if (!len) { + rte_mbuf_raw_free(rep); + break; + } + + if (len > rte_pktmbuf_data_len(seg)) { + rte_mbuf_raw_free(rep); + pkt = NULL; + ++rq_ci; + continue; + } + + pkt = seg; + pkt->ol_flags &= RTE_MBUF_F_EXTERNAL; + xsc_cq_to_mbuf(rxq, pkt, cqe); + + if (rxq->crc_present) + len -= RTE_ETHER_CRC_LEN; + rte_pktmbuf_pkt_len(pkt) = len; + } + + xsc_pkt_info_sync(rep, seg); + (*rxq->elts)[idx] = rep; + + /* Fill wqe */ + wqe->va = rte_cpu_to_le_64(rte_pktmbuf_iova(rep)); + rte_pktmbuf_data_len(seg) = len; + + *(pkts++) = pkt; + pkt = NULL; + --pkts_n; + ++nb_pkts; + ++rq_ci; + } + + if (unlikely(nb_pkts == 0 && rq_ci == rxq->rq_ci)) + return 0; + + rxq->rq_ci = rq_ci; + rxq->nb_rx_hold += nb_pkts; + + if (rxq->nb_rx_hold >= rxq->rx_free_thresh) { + union xsc_cq_doorbell cq_db = { + .cq_data = 0 + }; + cq_db.next_cid = rxq->cq_ci; + cq_db.cq_num = rxq->cqn; + + union xsc_recv_doorbell rq_db = { + .recv_data = 0 + }; + rq_db.next_pid = (rxq->rq_ci << sge_n); + rq_db.qp_num = rxq->qpn; + + rte_io_wmb(); + *rxq->cq_db = rte_cpu_to_le_32(cq_db.cq_data); + rte_io_wmb(); + *rxq->rq_db = rte_cpu_to_le_32(rq_db.recv_data); + rxq->nb_rx_hold = 0; + } + + return nb_pkts; } uint16_t diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h index 0b2fded42b..454d5c0378 100644 --- a/drivers/net/xsc/xsc_rxtx.h +++ b/drivers/net/xsc/xsc_rxtx.h @@ -175,6 +175,15 @@ union xsc_recv_doorbell { uint32_t recv_data; }; +union xsc_send_doorbell { + struct { + uint32_t next_pid : 16; + uint32_t qp_num : 15; + uint32_t rsv : 1; + }; + uint32_t send_data; +}; + uint16_t xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n); uint16_t xsc_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n); From patchwork Wed Sep 11 02:07:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143932 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CF9A24595A; Wed, 11 Sep 2024 04:10:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 298B74325C; Wed, 11 Sep 2024 04:08:31 +0200 (CEST) Received: from lf-1-15.ptr.blmpb.com (lf-1-15.ptr.blmpb.com [103.149.242.15]) by mails.dpdk.org (Postfix) with ESMTP id C098843245 for ; Wed, 11 Sep 2024 04:08:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020495; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=zYJSQbWsVmMu1M8kdNOf8ltF7YODz4QcIYKXaJvglG4=; b=aeoACPGm/oPTKvxmAyCk+DjPFcelfn9ug7Xjjyeb2/IzRHYimzsXuOXjP7O8QNHZwxkxxT h9o8JZ+/5YScRm6Sbe26T2C6itXX/+DrQt5nDdIyrHYyTPZW+e3ViruDWHrUC5ng1qrF7s foCdtzU+67L2NVkPDynmoRCbcwibk3Do1o2YXIv1awbzPDpmVaoADGee5Ks9fXUHEj6kVY 74VSUahf4u0KcFkNRir//u19e7Qt6LcS/BE4h8SSSJHLARoCTpYH63Cz5x0d/7PxSAmOJY S5SuRSGxjStP9CpoSW7DYcS+/UlX2mC/PRnewuey4G//seFxjA2hndoNyNoDOw== From: "WanRenyong" Date: Wed, 11 Sep 2024 10:07:36 +0800 Message-Id: <20240911020740.3950704-16-wanry@yunsilicon.com> To: X-Original-From: WanRenyong X-Lms-Return-Path: Mime-Version: 1.0 Cc: , , "WanRenyong" , "Rong Qian" Subject: [PATCH v2 15/19] net/xsc: add ethdev Tx burst Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:14 +0800 X-Mailer: git-send-email 2.25.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc PMD transmit function. Signed-off-by: WanRenyong Signed-off-by: Rong Qian --- doc/guides/nics/features/xsc.ini | 4 + drivers/net/xsc/xsc_rxtx.c | 231 ++++++++++++++++++++++++++++++- drivers/net/xsc/xsc_rxtx.h | 9 ++ 3 files changed, 242 insertions(+), 2 deletions(-) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index bdeb7a984b..772c6418c4 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -7,6 +7,10 @@ RSS hash = Y RSS key update = Y RSS reta update = Y +L3 checksum offload = Y +L4 checksum offload = Y +Inner L3 checksum = Y +Inner L4 checksum = Y Linux = Y ARMv8 = Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c index 28360e62ff..7a31cd428c 100644 --- a/drivers/net/xsc/xsc_rxtx.c +++ b/drivers/net/xsc/xsc_rxtx.c @@ -14,6 +14,8 @@ #define XSC_CQE_OWNER_HW 0x2 #define XSC_CQE_OWNER_SW 0x4 #define XSC_CQE_OWNER_ERR 0x8 +#define XSC_OPCODE_RAW 0x7 +#define XSC_TX_COMP_CQE_HANDLE_MAX 2 #define XSC_MAX_RX_BURST_MBUFS 64 @@ -201,9 +203,234 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) return nb_pkts; } +static __rte_always_inline void +xsc_tx_elts_free(struct xsc_txq_data *__rte_restrict txq, uint16_t tail) +{ + uint16_t elts_n = tail - txq->elts_tail; + uint32_t free_n; + + do { + free_n = txq->elts_s - (txq->elts_tail & txq->elts_m); + free_n = RTE_MIN(free_n, elts_n); + rte_pktmbuf_free_bulk(&txq->elts[txq->elts_tail & txq->elts_m], free_n); + txq->elts_tail += free_n; + elts_n -= free_n; + } while (elts_n > 0); +} + +static void +xsc_tx_cqes_handle(struct xsc_txq_data *__rte_restrict txq) +{ + uint32_t count = XSC_TX_COMP_CQE_HANDLE_MAX; + volatile struct xsc_cqe *last_cqe = NULL; + volatile struct xsc_cqe *cqe; + bool doorbell = false; + int ret; + uint16_t tail; + + do { + cqe = &txq->cqes[txq->cq_ci & txq->cqe_m]; + ret = check_cqe_own(cqe, txq->cqe_n, txq->cq_ci); + if (unlikely(ret != XSC_CQE_OWNER_SW)) { + if (likely(ret != XSC_CQE_OWNER_ERR)) + /* No new CQEs in completion queue. */ + break; + doorbell = true; + ++txq->cq_ci; + txq->cq_pi = txq->cq_ci; + last_cqe = NULL; + continue; + } + + doorbell = true; + ++txq->cq_ci; + last_cqe = cqe; + } while (--count > 0); + + if (likely(doorbell)) { + union xsc_cq_doorbell cq_db = { + .cq_data = 0 + }; + cq_db.next_cid = txq->cq_ci; + cq_db.cq_num = txq->cqn; + + /* Ring doorbell */ + rte_compiler_barrier(); + *txq->cq_db = rte_cpu_to_le_32(cq_db.cq_data); + + /* Release completed elts */ + if (likely(last_cqe != NULL)) { + txq->wqe_pi = rte_le_to_cpu_16(last_cqe->wqe_id) >> txq->wqe_ds_n; + tail = txq->fcqs[(txq->cq_ci - 1) & txq->cqe_m]; + if (likely(tail != txq->elts_tail)) + xsc_tx_elts_free(txq, tail); + } + } +} + +static __rte_always_inline void +xsc_tx_wqe_ctrl_seg_init(struct xsc_txq_data *__rte_restrict txq, + struct rte_mbuf *__rte_restrict mbuf, + struct xsc_wqe *__rte_restrict wqe) +{ + struct xsc_send_wqe_ctrl_seg *cs = &wqe->cseg; + int i = 0; + int ds_max = (1 << txq->wqe_ds_n) - 1; + + cs->msg_opcode = XSC_OPCODE_RAW; + cs->wqe_id = rte_cpu_to_le_16(txq->wqe_ci << txq->wqe_ds_n); + cs->has_pph = 0; + /* clear dseg's seg len */ + if (cs->ds_data_num > 1 && cs->ds_data_num <= ds_max) { + for (i = 1; i < cs->ds_data_num; i++) + wqe->dseg[i].seg_len = 0; + } + + cs->ds_data_num = mbuf->nb_segs; + if (mbuf->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) + cs->csum_en = 0x2; + else + cs->csum_en = 0; + + if (txq->tso_en == 1 && (mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) { + cs->has_pph = 0; + cs->so_type = 1; + cs->so_hdr_len = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; + cs->so_data_size = rte_cpu_to_le_16(mbuf->tso_segsz); + } + + cs->msg_len = rte_cpu_to_le_32(rte_pktmbuf_pkt_len(mbuf)); + if (unlikely(cs->msg_len == 0)) + cs->msg_len = rte_cpu_to_le_32(rte_pktmbuf_data_len(mbuf)); + + /* do not generate cqe for every pkts */ + cs->ce = 0; +} + +static __rte_always_inline void +xsc_tx_wqe_data_seg_init(struct rte_mbuf *mbuf, struct xsc_wqe *wqe) +{ + uint16_t i, nb_segs = mbuf->nb_segs; + uint32_t data_len; + rte_iova_t iova; + struct xsc_wqe_data_seg *dseg; + + for (i = 0; i < nb_segs; ++i) { + dseg = &wqe->dseg[i]; + iova = rte_pktmbuf_iova(mbuf); + data_len = rte_pktmbuf_data_len(mbuf); + + dseg->in_line = 0; + dseg->seg_len = rte_cpu_to_le_32(data_len); + dseg->lkey = 0; + dseg->va = rte_cpu_to_le_64(iova); + mbuf = mbuf->next; + } +} + +static __rte_always_inline struct xsc_wqe * +xsc_tx_wqes_fill(struct xsc_txq_data *__rte_restrict txq, + struct rte_mbuf **__rte_restrict pkts, + uint32_t pkts_n) +{ + uint32_t i; + struct xsc_wqe *wqe = NULL; + struct rte_mbuf *mbuf; + + for (i = 0; i < pkts_n; i++) { + mbuf = pkts[i]; + rte_prefetch0(mbuf); + wqe = (struct xsc_wqe *)((struct xsc_send_wqe_ctrl_seg *)txq->wqes + + (txq->wqe_ci & txq->wqe_m) * (1 << txq->wqe_ds_n)); + + /* init wqe ctrl seg */ + xsc_tx_wqe_ctrl_seg_init(txq, mbuf, wqe); + /* init wqe data segs */ + xsc_tx_wqe_data_seg_init(mbuf, wqe); + ++txq->wqe_ci; + } + + return wqe; +} + +static __rte_always_inline void +xsc_tx_doorbell_ring(volatile uint32_t *db, uint32_t index, + uint32_t qpn, uint16_t ds_n) +{ + union xsc_send_doorbell tx_db; + + rte_io_wmb(); + tx_db.next_pid = index << ds_n; + tx_db.qp_num = qpn; + *db = rte_cpu_to_le_32(tx_db.send_data); + + rte_wmb(); +} + +static __rte_always_inline void +xsc_tx_elts_store(struct xsc_txq_data *__rte_restrict txq, + struct rte_mbuf **__rte_restrict pkts, + uint32_t pkts_n) +{ + uint32_t part; + struct rte_mbuf **elts = (struct rte_mbuf **)txq->elts; + + part = txq->elts_s - (txq->elts_head & txq->elts_m); + rte_memcpy((void *)(elts + (txq->elts_head & txq->elts_m)), + (void *)pkts, + RTE_MIN(part, pkts_n) * sizeof(struct rte_mbuf *)); + + if (unlikely(part < pkts_n)) + rte_memcpy((void *)elts, (void *)(pkts + part), + (pkts_n - part) * sizeof(struct rte_mbuf *)); +} + uint16_t xsc_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) { - return 0; -} + struct xsc_txq_data *txq = dpdk_txq; + uint32_t tx_n, remain_n = pkts_n; + uint16_t idx, elts_free, wqe_free; + uint16_t elts_head; + struct xsc_wqe *last_wqe; + if (unlikely(!pkts_n)) + return 0; +loop: + xsc_tx_cqes_handle(txq); + + elts_free = txq->elts_s - (uint16_t)(txq->elts_head - txq->elts_tail); + wqe_free = txq->wqe_s - (((txq->wqe_ci << txq->wqe_ds_n) - + (txq->wqe_pi << txq->wqe_ds_n)) >> txq->wqe_ds_n); + if (unlikely(elts_free == 0 || wqe_free == 0)) + goto exit; + + /* Fill in WQEs */ + tx_n = RTE_MIN(remain_n, wqe_free); + idx = pkts_n - remain_n; + last_wqe = xsc_tx_wqes_fill(txq, &pkts[idx], tx_n); + remain_n -= tx_n; + last_wqe->cseg.ce = 1; + + /* Update free-cqs, elts_comp */ + elts_head = txq->elts_head; + elts_head += tx_n; + if ((uint16_t)(elts_head - txq->elts_comp) > 0) { + txq->elts_comp = elts_head; + txq->fcqs[txq->cq_pi++ & txq->cqe_m] = elts_head; + } + + /* Ring tx doorbell */ + xsc_tx_doorbell_ring(txq->qp_db, txq->wqe_ci, + txq->qpn, txq->wqe_ds_n); + + xsc_tx_elts_store(txq, &pkts[idx], tx_n); + txq->elts_head += tx_n; + + if (remain_n > 0) + /* Try to process cqe, if wqe free is still 0, exit */ + goto loop; + +exit: + return pkts_n - remain_n; +} diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h index 454d5c0378..ce6e47ad4c 100644 --- a/drivers/net/xsc/xsc_rxtx.h +++ b/drivers/net/xsc/xsc_rxtx.h @@ -166,6 +166,15 @@ struct __rte_cache_aligned xsc_rxq_data { uint32_t rss_hash:1; /* RSS hash enabled */ }; +union xsc_cq_doorbell { + struct { + uint32_t next_cid : 16; + uint32_t cq_num : 15; + uint32_t cq_sta : 1; + }; + uint32_t cq_data; +}; + union xsc_recv_doorbell { struct { uint32_t next_pid : 13; From patchwork Wed Sep 11 02:07:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143935 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BACF34595A; Wed, 11 Sep 2024 04:10:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1246343283; Wed, 11 Sep 2024 04:08:37 +0200 (CEST) Received: from lf-2-32.ptr.blmpb.com (lf-2-32.ptr.blmpb.com [101.36.218.32]) by mails.dpdk.org (Postfix) with ESMTP id AD0324300B for ; Wed, 11 Sep 2024 04:08:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020497; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=Vnq1HfZ+GklhyT3fYzngFIAXIhcuV+ZK+CX2Sp7QU3Y=; b=AIxGnBe/NVyhWgGQyglUMpswr/snDjaMhb3pFBMmgi5uYFQMsebNo3dykIrFykHRceKy5a /lmyw2s8uZWeKFaSN4mVvotaGYu/bWZzlmRrepn3WMiPB/69BPOGtKY97mxmiTkxxkllCf eyeJRO+20wkQp/r8O6aGO5rF8qTEqML5i7IR7unZ0g9DM56D1sw0Hbx8VUSKpc/WMidS+c uVrmjgUp6t0f08hUsFtEeaoBEu91Zhr8xe+tQzpd6hPGCZ3dudBt5kk8rt5F0CQr2sS5oZ JahXKgLFHZVhWP8fLBI6M9N1T1u6qYOPFN6IDptHnPJzCxtPHlPgkIhbt8sjkA== To: Date: Wed, 11 Sep 2024 10:07:37 +0800 Mime-Version: 1.0 X-Lms-Return-Path: X-Mailer: git-send-email 2.25.1 From: "WanRenyong" Message-Id: <20240911020740.3950704-17-wanry@yunsilicon.com> Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:15 +0800 Cc: , , "WanRenyong" , "Xiaoxiong Zhang" Subject: [PATCH v2 16/19] net/xsc: configure xsc device hardware table X-Original-From: WanRenyong X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Configure hardware table to enable transmission and reception of the queues. Signed-off-by: WanRenyong Signed-off-by: Xiaoxiong Zhang --- drivers/net/xsc/meson.build | 1 + drivers/net/xsc/xsc_ctrl.h | 22 +++++ drivers/net/xsc/xsc_ethdev.c | 39 ++++++++ drivers/net/xsc/xsc_flow.c | 167 +++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_flow.h | 67 ++++++++++++++ 5 files changed, 296 insertions(+) create mode 100644 drivers/net/xsc/xsc_flow.c create mode 100644 drivers/net/xsc/xsc_flow.h diff --git a/drivers/net/xsc/meson.build b/drivers/net/xsc/meson.build index 5f15c8def5..e922e3b320 100644 --- a/drivers/net/xsc/meson.build +++ b/drivers/net/xsc/meson.build @@ -12,6 +12,7 @@ sources = files( 'xsc_utils.c', 'xsc_ctrl.c', 'xsc_rxtx.c', + 'xsc_flow.c', ) libnames = ['ibverbs'] diff --git a/drivers/net/xsc/xsc_ctrl.h b/drivers/net/xsc/xsc_ctrl.h index e51847d68f..51bda47ca8 100644 --- a/drivers/net/xsc/xsc_ctrl.h +++ b/drivers/net/xsc/xsc_ctrl.h @@ -41,6 +41,12 @@ enum xsc_ioctl_opmod { ((_n) + (_d) - 1) / (_d); \ }) +enum { + XSC_CMD_OP_MODIFY_RAW_QP = 0x81f, + XSC_CMD_OP_IOCTL_FLOW = 0x900, + XSC_CMD_OP_MAX +}; + enum { XSC_IOCTL_SET_QP_STATUS = 0x200, XSC_IOCTL_SET_MAX @@ -72,6 +78,22 @@ enum { XSC_QUEUE_TYPE_RAW_TX = 7, XSC_QUEUE_TYPE_INVALID = 0xFF, }; +enum xsc_flow_tbl_id { + XSC_FLOW_TBL_IPAT = 0, + XSC_FLOW_TBL_PCT_V4 = 4, + XSC_FLOW_TBL_EPAT = 19, + XSC_FLOW_TBL_MAX +}; + +enum xsc_ioctl_op { + XSC_IOCTL_OP_ADD, + XSC_IOCTL_OP_DEL, + XSC_IOCTL_OP_GET, + XSC_IOCTL_OP_CLR, + XSC_IOCTL_OP_MOD, + XSC_IOCTL_OP_MAX +}; + struct xsc_inbox_hdr { __be16 opcode; diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 35daa16528..0dc1a63cc5 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -11,6 +11,7 @@ #include "xsc_dev.h" #include "xsc_ethdev.h" #include "xsc_utils.h" +#include "xsc_flow.h" #include "xsc_ctrl.h" #include "xsc_rxtx.h" @@ -787,6 +788,43 @@ xsc_rxq_start(struct rte_eth_dev *dev) return -rte_errno; } +static int +xsc_dev_start_config_hw(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_hwinfo *hwinfo; + int peer_dstinfo = 0; + int peer_logicalport = 0; + int logical_port = 0; + int local_dstinfo = 0; + int pcie_logic_port = 0; + int qp_set_id = 0; + int rep_id; + struct xsc_rxq_data *rxq = xsc_rxq_get(dev, 0); + uint16_t rx_qpn = (uint16_t)rxq->qpn; + static int xsc_global_pct_priority_idx = 128; + + if (priv->funcid_type != XSC_PHYPORT_MAC_FUNCID) + return -1; + + hwinfo = &priv->xdev->hwinfo; + rep_id = priv->representor_id; + peer_dstinfo = hwinfo->mac_phy_port; + peer_logicalport = hwinfo->mac_phy_port; + + qp_set_id = rep_id % 511 + 1; + logical_port = priv->xdev->vfos_logical_in_port + qp_set_id - 1; + local_dstinfo = logical_port; + pcie_logic_port = hwinfo->pcie_no + 8; + + xsc_create_ipat(dev, logical_port, peer_dstinfo); + xsc_create_epat(dev, local_dstinfo, pcie_logic_port, + rx_qpn - hwinfo->raw_rss_qp_id_base, priv->num_rq); + xsc_create_pct(dev, logical_port, peer_dstinfo, xsc_global_pct_priority_idx++); + xsc_create_pct(dev, peer_logicalport, local_dstinfo, xsc_global_pct_priority_idx++); + return 0; +} + static int xsc_ethdev_start(struct rte_eth_dev *dev) { @@ -812,6 +850,7 @@ xsc_ethdev_start(struct rte_eth_dev *dev) dev->rx_pkt_burst = xsc_rx_burst; dev->tx_pkt_burst = xsc_tx_burst; + ret = xsc_dev_start_config_hw(dev); return 0; error: diff --git a/drivers/net/xsc/xsc_flow.c b/drivers/net/xsc/xsc_flow.c new file mode 100644 index 0000000000..f1101b29d0 --- /dev/null +++ b/drivers/net/xsc/xsc_flow.c @@ -0,0 +1,167 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#include +#include + +#include "xsc_log.h" +#include "xsc_defs.h" +#include "xsc_dev.h" +#include "xsc_ethdev.h" +#include "xsc_utils.h" +#include "xsc_flow.h" +#include "xsc_ctrl.h" + + +static int +xsc_flow_exec(struct xsc_dev *dev, void *cmd, int len, int table, int opmod) +{ + struct xsc_ioctl_data_tl *tl; + struct xsc_ioctl_mbox_in *in; + struct xsc_ioctl_mbox_out *out; + int in_len; + int out_len; + int data_len; + int cmd_len; + int ret; + + data_len = sizeof(struct xsc_ioctl_data_tl) + len; + in_len = sizeof(struct xsc_ioctl_mbox_in) + data_len; + out_len = sizeof(struct xsc_ioctl_mbox_out) + data_len; + cmd_len = RTE_MAX(in_len, out_len); + in = rte_zmalloc(NULL, cmd_len, RTE_CACHE_LINE_SIZE); + if (in == NULL) { + rte_errno = ENOMEM; + PMD_DRV_LOG(ERR, "alloc flow ioctl cmd memory failed\n"); + return -rte_errno; + } + + in->hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_IOCTL_FLOW); + in->len = rte_cpu_to_be_16(data_len); + + tl = (struct xsc_ioctl_data_tl *)in->data; + tl->length = len; + tl->table = table; + tl->opmod = opmod; + if (cmd && len) + rte_memcpy(tl + 1, cmd, len); + + out = (struct xsc_ioctl_mbox_out *)in; + ret = xsc_mailbox_exec(dev, in, in_len, out, out_len); + + rte_free(in); + return ret; +} + +int +xsc_create_pct(struct rte_eth_dev *dev, uint16_t logical_in_port, + uint16_t dst_info, uint32_t priority) +{ + struct xsc_flow_pct_v4_add { + struct xsc_pct_v4_key key; + struct xsc_pct_v4_key mask; + struct xsc_pct_action action; + uint32_t priority; + } add; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&add, 0, sizeof(add)); + + + add.key.logical_in_port = logical_in_port & 0x07FF; + add.mask.logical_in_port = 0x07FF; + add.action.dst_info = dst_info; + add.priority = priority; + return xsc_flow_exec(priv->xdev, &add, sizeof(add), + XSC_FLOW_TBL_PCT_V4, XSC_IOCTL_OP_ADD); +} + +int +xsc_destroy_pct(struct rte_eth_dev *dev, uint16_t logical_in_port, uint32_t priority) +{ + struct xsc_flow_pct_v4_add { + struct xsc_pct_v4_key key; + struct xsc_pct_v4_key mask; + uint32_t priority; + } del; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&del, 0, sizeof(del)); + + del.key.logical_in_port = logical_in_port & 0x07FF; + del.mask.logical_in_port = 0x07FF; + del.priority = priority; + return xsc_flow_exec(priv->xdev, &del, sizeof(del), + XSC_FLOW_TBL_PCT_V4, XSC_IOCTL_OP_DEL); +} + +int +xsc_create_ipat(struct rte_eth_dev *dev, uint16_t logic_in_port, uint16_t dst_info) +{ + struct xsc_flow_ipat_add { + struct xsc_ipat_key key; + struct xsc_ipat_action action; + } add; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&add, 0, sizeof(add)); + + add.key.logical_in_port = logic_in_port; + add.action.dst_info = dst_info; + add.action.vld = 1; + return xsc_flow_exec(priv->xdev, &add, sizeof(add), + XSC_FLOW_TBL_IPAT, XSC_IOCTL_OP_ADD); +} + +int +xsc_destroy_ipat(struct rte_eth_dev *dev, uint16_t logic_in_port) +{ + struct xsc_flow_ipat_del { + struct xsc_ipat_key key; + } del; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&del, 0, sizeof(del)); + + del.key.logical_in_port = logic_in_port; + return xsc_flow_exec(priv->xdev, &del, sizeof(del), + XSC_FLOW_TBL_IPAT, XSC_IOCTL_OP_DEL); +} + +int +xsc_create_epat(struct rte_eth_dev *dev, uint16_t dst_info, uint8_t dst_port, + uint16_t qpn_ofst, uint8_t qp_num) +{ + struct xsc_flow_epat_add { + struct xsc_epat_key key; + struct xsc_epat_action action; + } add; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&add, 0, sizeof(add)); + add.key.dst_info = dst_info; + add.action.dst_port = dst_port; + add.action.vld = 1; + add.action.rx_qp_id_ofst = qpn_ofst; + add.action.qp_num = qp_num - 1; + + return xsc_flow_exec(priv->xdev, &add, sizeof(add), + XSC_FLOW_TBL_EPAT, XSC_IOCTL_OP_ADD); +} + +int +xsc_destroy_epat(struct rte_eth_dev *dev, uint16_t dst_info) +{ + struct xsc_flow_ipat_del { + struct xsc_epat_key key; + } del; + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + memset(&del, 0, sizeof(del)); + + del.key.dst_info = dst_info; + return xsc_flow_exec(priv->xdev, &del, sizeof(del), + XSC_FLOW_TBL_EPAT, XSC_IOCTL_OP_DEL); +} + diff --git a/drivers/net/xsc/xsc_flow.h b/drivers/net/xsc/xsc_flow.h new file mode 100644 index 0000000000..ced568d40e --- /dev/null +++ b/drivers/net/xsc/xsc_flow.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_FLOW_H_ +#define _XSC_FLOW_H_ + +#include + +#include "xsc_dev.h" +#include "xsc_utils.h" + +/* xsc flow */ +struct xsc_ipat_key { + uint16_t logical_in_port:11; +} __rte_packed; + +struct xsc_ipat_action { + uint64_t rsv0:64; + uint16_t rsv1:9; + uint16_t dst_info:11; + uint64_t rsv2:34; + uint8_t vld:1; +} __rte_packed; + +struct xsc_epat_key { + uint16_t dst_info:11; +} __rte_packed; + +struct xsc_epat_action { + uint8_t rsv0[14]; + uint8_t rsv1:4; + uint8_t dst_port:4; + uint8_t rss_hash_func:2; + uint8_t rss_hash_template:5; + uint8_t rss_en:1; + uint8_t qp_num:8; + uint16_t rx_qp_id_ofst:12; + uint16_t rsv3:4; + uint8_t rsv4:7; + uint8_t vld:1; +} __rte_packed; + +struct xsc_pct_v4_key { + uint16_t rsv0[20]; + uint16_t rsv1:13; + uint16_t logical_in_port:11; + uint8_t rsv2:8; +} __rte_packed; + +struct xsc_pct_action { + uint32_t rsv0:29; + uint16_t dst_info:11; + uint8_t rsv1:3; +} __rte_packed; + +int xsc_create_pct(struct rte_eth_dev *dev, uint16_t logical_in_port, + uint16_t dst_info, uint32_t priority); +int xsc_destroy_pct(struct rte_eth_dev *dev, uint16_t logical_in_port, uint32_t priority); +int xsc_create_ipat(struct rte_eth_dev *dev, uint16_t logic_in_port, uint16_t dst_info); +int xsc_destroy_ipat(struct rte_eth_dev *dev, uint16_t logic_in_port); +int xsc_create_epat(struct rte_eth_dev *dev, uint16_t dst_info, uint8_t dst_port, + uint16_t qpn_ofst, uint8_t qp_num); +int xsc_destroy_epat(struct rte_eth_dev *dev, uint16_t dst_info); + +#endif + From patchwork Wed Sep 11 02:07:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143934 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D60D54595A; Wed, 11 Sep 2024 04:10:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBF9043278; Wed, 11 Sep 2024 04:08:35 +0200 (CEST) Received: from lf-2-32.ptr.blmpb.com (lf-2-32.ptr.blmpb.com [101.36.218.32]) by mails.dpdk.org (Postfix) with ESMTP id B6FAE43254 for ; Wed, 11 Sep 2024 04:08:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020499; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=PHhWLsIwBTxrTJWWWw1HFD2PjSi8/PP65GYgzQ8oFF4=; b=fTLRsSVbP//qyzj7rcKNLibnr3LRtFk/znwLWGqbHLrCXL6xrud9Cy6X1KwCkUNoO5bv/W YQ6bghHmdJ3ixoUnmcVSzg7uCPWDpfgEhHBOrnBCn1YtAQ0jWaWYMGR/D3zCfUZCyq1MiS 7/o3tfhbSRoAcCiqPiae4kxTe43EEdbs1yjlSVwtlXfv31lnqG3Rc11spD6DtC/KWTh/sR DR96q2cyzOgpQVjGR4+PMqfD4qDt93uqjc8MU0Sz9PszP+cKp2fE63K5iJSB44PuXy8eM9 TQ41iC+gBq+ydI/sv3TUYWPMYsnI14SMctA8YMgGvYOVgyzTYPKdLNe0VC95uw== To: Date: Wed, 11 Sep 2024 10:07:38 +0800 X-Lms-Return-Path: Cc: , , "WanRenyong" Message-Id: <20240911020740.3950704-18-wanry@yunsilicon.com> X-Mailer: git-send-email 2.25.1 Mime-Version: 1.0 X-Original-From: WanRenyong From: "WanRenyong" Subject: [PATCH v2 17/19] net/xsc: add dev link and MTU ops Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:17 +0800 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org XSC PMD does not support update link right now, in order to start device successfully link_update function always return 0. Signed-off-by: WanRenyong --- doc/guides/nics/features/xsc.ini | 1 + drivers/net/xsc/xsc_ethdev.c | 50 ++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_utils.c | 23 +++++++++++++++ drivers/net/xsc/xsc_utils.h | 1 + 4 files changed, 75 insertions(+) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index 772c6418c4..84c5ff4b6b 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -4,6 +4,7 @@ ; Refer to default.ini for the full list of available PMD features. ; [Features] +MTU update = Y RSS hash = Y RSS key update = Y RSS reta update = Y diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 0dc1a63cc5..bc5e827d70 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -187,6 +187,20 @@ xsc_ethdev_configure(struct rte_eth_dev *dev) return -rte_errno; } +static int +xsc_ethdev_set_link_down(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + return xsc_link_process(dev, priv->ifindex, IFF_UP); +} + +static int +xsc_ethdev_set_link_up(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + return xsc_link_process(dev, priv->ifindex, ~IFF_UP); +} + static int xsc_init_obj(struct xscdv_obj *obj, uint64_t obj_type) { @@ -983,6 +997,39 @@ xsc_ethdev_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, return 0; } +static int +xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint16_t get_mtu = 0; + int ret = 0; + + if (priv->eth_type != RTE_ETH_REPRESENTOR_PF) { + priv->mtu = mtu; + return 0; + } + + ret = xsc_get_mtu(&priv->mtu, priv->ifindex); + if (ret) + return ret; + + ret = xsc_set_mtu(mtu, priv->ifindex); + if (ret) + return ret; + + ret = xsc_get_mtu(&get_mtu, priv->ifindex); + if (ret) + return ret; + + if (get_mtu != mtu) { + PMD_DRV_LOG(ERR, "mtu set to %u failure", mtu); + return -EAGAIN; + } + + priv->mtu = mtu; + return 0; +} + static int xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev, __rte_unused int wait_to_complete) @@ -994,12 +1041,15 @@ const struct eth_dev_ops xsc_dev_ops = { .dev_configure = xsc_ethdev_configure, .dev_start = xsc_ethdev_start, .dev_stop = xsc_ethdev_stop, + .dev_set_link_down = xsc_ethdev_set_link_down, + .dev_set_link_up = xsc_ethdev_set_link_up, .dev_close = xsc_ethdev_close, .link_update = xsc_ethdev_link_update, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, .rx_queue_release = xsc_ethdev_rxq_release, .tx_queue_release = xsc_ethdev_txq_release, + .mtu_set = xsc_ethdev_set_mtu, .rss_hash_update = xsc_ethdev_rss_hash_update, .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get, }; diff --git a/drivers/net/xsc/xsc_utils.c b/drivers/net/xsc/xsc_utils.c index e40b0904b7..788cdfa54a 100644 --- a/drivers/net/xsc/xsc_utils.c +++ b/drivers/net/xsc/xsc_utils.c @@ -321,3 +321,26 @@ xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t i dev->data->mac_addrs[index] = *mac; return 0; } + +int +xsc_link_process(struct rte_eth_dev *dev __rte_unused, + uint32_t ifindex, unsigned int flags) +{ + struct ifreq request; + struct ifreq *ifr = &request; + char ifname[sizeof(ifr->ifr_name)]; + int ret; + unsigned int keep = ~IFF_UP; + + if (if_indextoname(ifindex, ifname) == NULL) + return -rte_errno; + + ret = xsc_ifreq_by_ifname(ifname, SIOCGIFFLAGS, &request); + if (ret) + return ret; + + request.ifr_flags &= keep; + request.ifr_flags |= flags & ~keep; + + return xsc_ifreq_by_ifname(ifname, SIOCSIFFLAGS, &request); +} diff --git a/drivers/net/xsc/xsc_utils.h b/drivers/net/xsc/xsc_utils.h index 672ba3871e..d9327020cd 100644 --- a/drivers/net/xsc/xsc_utils.h +++ b/drivers/net/xsc/xsc_utils.h @@ -22,5 +22,6 @@ int xsc_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32 int xsc_get_mtu(uint16_t *mtu, uint32_t ifindex); int xsc_set_mtu(uint16_t mtu, uint32_t ifindex); int xsc_get_mac(uint8_t *mac, uint32_t ifindex); +int xsc_link_process(struct rte_eth_dev *dev, uint32_t ifindex, unsigned int flags); #endif From patchwork Wed Sep 11 02:07:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143931 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 11FB34595A; Wed, 11 Sep 2024 04:10:06 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D16F843254; Wed, 11 Sep 2024 04:08:29 +0200 (CEST) Received: from lf-2-35.ptr.blmpb.com (lf-2-35.ptr.blmpb.com [101.36.218.35]) by mails.dpdk.org (Postfix) with ESMTP id 91D6343067 for ; Wed, 11 Sep 2024 04:08:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020500; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=EZq+Fjq8nrc8bfPDi7EycMnV3BXZeftPFKbs1EoCeS0=; b=Sa0TiKShSifrqBY9QKrn6NALLg3O7LAa9qRYRln1ZJbQtqCRfvaEsFtRr9X6yeIY3M5uHQ cEQsv4xyCUCIR3LyTa4yMV9+fCg2r0+UfxXqw0/36owhMZABZVOB9bjnxcvOUtyGw1U2RB bHkPCDpJCibQevnQ5bRgD2vmc5zuQL0pfuQeR4udVP+jXAAoTimkVUdA5RiBsQNGyHxVW7 odbdJs+CqAOHWj6XDTbZ8y/On9qpBlgf1UjvwDJU9+6DnhAEezCquABk21Klcq8JHeIotz MPX9jPJQ5jtXZ0TZ45NYSBTmLBfKtXroO8yD74GMSoOhjY7m2U+2rcOmGVveGA== Cc: , , "WanRenyong" Subject: [PATCH v2 18/19] net/xsc: add dev infos get Date: Wed, 11 Sep 2024 10:07:39 +0800 From: "WanRenyong" Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:19 +0800 To: Message-Id: <20240911020740.3950704-19-wanry@yunsilicon.com> X-Lms-Return-Path: X-Original-From: WanRenyong X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc ethdev information get function. Signed-off-by: WanRenyong --- drivers/net/xsc/xsc_ethdev.c | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index bc5e827d70..ba3c215112 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -918,6 +918,65 @@ xsc_ethdev_close(struct rte_eth_dev *dev) return 0; } +static uint64_t +xsc_get_rx_queue_offloads(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + struct xsc_dev_config *config = &priv->config; + uint64_t offloads = 0; + + if (config->hw_csum) + offloads |= (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | + RTE_ETH_RX_OFFLOAD_UDP_CKSUM | + RTE_ETH_RX_OFFLOAD_TCP_CKSUM); + + return offloads; +} + +static uint64_t +xsc_get_tx_port_offloads(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint64_t offloads = 0; + struct xsc_dev_config *config = &priv->config; + + if (config->hw_csum) + offloads |= (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | + RTE_ETH_TX_OFFLOAD_UDP_CKSUM | + RTE_ETH_TX_OFFLOAD_TCP_CKSUM); + if (config->tso) + offloads |= RTE_ETH_TX_OFFLOAD_TCP_TSO; + return offloads; +} + +static int +xsc_ethdev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + + info->min_rx_bufsize = 64; + info->max_rx_pktlen = 65536; + info->max_lro_pkt_size = 0; + info->max_rx_queues = 256; + info->max_tx_queues = 1024; + info->rx_desc_lim.nb_max = 4096; + info->rx_desc_lim.nb_min = 16; + info->tx_desc_lim.nb_max = 8192; + info->tx_desc_lim.nb_min = 128; + + info->rx_queue_offload_capa = xsc_get_rx_queue_offloads(dev); + info->rx_offload_capa = info->rx_queue_offload_capa; + info->tx_offload_capa = xsc_get_tx_port_offloads(dev); + + info->if_index = priv->ifindex; + info->hash_key_size = XSC_RSS_HASH_KEY_LEN; + info->tx_desc_lim.nb_seg_max = 8; + info->tx_desc_lim.nb_mtu_seg_max = 8; + info->switch_info.name = dev->data->name; + info->switch_info.port_id = priv->representor_id; + return 0; +} + static int xsc_ethdev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc, uint32_t socket, const struct rte_eth_rxconf *conf, @@ -1045,6 +1104,7 @@ const struct eth_dev_ops xsc_dev_ops = { .dev_set_link_up = xsc_ethdev_set_link_up, .dev_close = xsc_ethdev_close, .link_update = xsc_ethdev_link_update, + .dev_infos_get = xsc_ethdev_infos_get, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, .rx_queue_release = xsc_ethdev_rxq_release, From patchwork Wed Sep 11 02:07:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WanRenyong X-Patchwork-Id: 143933 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB3A84595A; Wed, 11 Sep 2024 04:10:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DCB954326C; Wed, 11 Sep 2024 04:08:33 +0200 (CEST) Received: from lf-2-34.ptr.blmpb.com (lf-2-34.ptr.blmpb.com [101.36.218.34]) by mails.dpdk.org (Postfix) with ESMTP id 5857B43245 for ; Wed, 11 Sep 2024 04:08:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020502; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=kPdgbXoi/kbHv6FM9/sCPSeWwNSVgwrd5lETRI1/+WE=; b=HQ3eIoQqFfjQMoVfK4NY6X5t60qVNh2cRHG/sVsVBHZo1tUmw/U2stmU3nruNALevuFob8 8zFpEGjL64YOnPcHg5F1EI0InoKqdFp0eR1Hss5t6qun5fUOPjsCBSQA60q72GfuQOJPEP GHaDRZhUiNetqi2X1UaRK+BQUPo5d5/be3RH1ziS+4mMm/+YlCA2S1D95o0Z98J9JXA2f4 8pDTdAtL3tBP8eyumfgnY+8JsUGV2dfuU6iGbKjRf8Z2iCDIgViTdtHA0cJi8AMyCsCINy TFNBCGVarXdzKtY7gq5/LMfeRv/+xlIU9qt4xxVtQyaF7Zb6/KZM2Ud+ujRG2w== To: Message-Id: <20240911020740.3950704-20-wanry@yunsilicon.com> X-Lms-Return-Path: X-Original-From: WanRenyong From: "WanRenyong" Mime-Version: 1.0 X-Mailer: git-send-email 2.25.1 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:08:20 +0800 Cc: , , "WanRenyong" Subject: [PATCH v2 19/19] net/xsc: add dev basic stats ops Date: Wed, 11 Sep 2024 10:07:40 +0800 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Implement xsc ethdev basic stats get and reset functions. Signed-off-by: WanRenyong --- doc/guides/nics/features/xsc.ini | 1 + drivers/net/xsc/xsc_ethdev.c | 76 ++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_rxtx.c | 11 ++++- drivers/net/xsc/xsc_rxtx.h | 15 +++++++ 4 files changed, 102 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini index 84c5ff4b6b..d73cf9d136 100644 --- a/doc/guides/nics/features/xsc.ini +++ b/doc/guides/nics/features/xsc.ini @@ -12,6 +12,7 @@ L3 checksum offload = Y L4 checksum offload = Y Inner L3 checksum = Y Inner L4 checksum = Y +Basic stats = Y Linux = Y ARMv8 = Y x86-64 = Y diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index ba3c215112..9fa7173a7a 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -1089,6 +1089,80 @@ xsc_ethdev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) return 0; } +static int +xsc_ethdev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint32_t rxqs_n = priv->num_rq; + uint32_t txqs_n = priv->num_sq; + uint32_t i, idx; + struct xsc_rxq_data *rxq; + struct xsc_txq_data *txq; + + memset(stats, 0, sizeof(struct rte_eth_stats)); + for (i = 0; i < rxqs_n; ++i) { + rxq = xsc_rxq_get(dev, i); + if (unlikely(rxq == NULL)) + continue; + + idx = rxq->idx; + if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_ipackets[idx] += rxq->stats.rx_pkts; + stats->q_ibytes[idx] += rxq->stats.rx_bytes; + stats->q_errors[idx] += (rxq->stats.rx_errors + + rxq->stats.rx_nombuf); + } + stats->ipackets += rxq->stats.rx_pkts; + stats->ibytes += rxq->stats.rx_bytes; + stats->ierrors += rxq->stats.rx_errors; + stats->rx_nombuf += rxq->stats.rx_nombuf; + } + + for (i = 0; i < txqs_n; ++i) { + txq = xsc_txq_get(dev, i); + if (unlikely(txq == NULL)) + continue; + + idx = txq->idx; + if (idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) { + stats->q_opackets[idx] += txq->stats.tx_pkts; + stats->q_obytes[idx] += txq->stats.tx_bytes; + stats->q_errors[idx] += txq->stats.tx_errors; + } + stats->opackets += txq->stats.tx_pkts; + stats->obytes += txq->stats.tx_bytes; + stats->oerrors += txq->stats.tx_errors; + } + + return 0; +} + +static int +xsc_ethdev_stats_reset(struct rte_eth_dev *dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev); + uint32_t rxqs_n = priv->num_rq; + uint32_t txqs_n = priv->num_sq; + uint32_t i; + struct xsc_rxq_data *rxq; + struct xsc_txq_data *txq; + + for (i = 0; i < rxqs_n; ++i) { + rxq = xsc_rxq_get(dev, i); + if (unlikely(rxq == NULL)) + continue; + memset(&rxq->stats, 0, sizeof(struct xsc_rxq_stats)); + } + for (i = 0; i < txqs_n; ++i) { + txq = xsc_txq_get(dev, i); + if (unlikely(txq == NULL)) + continue; + memset(&txq->stats, 0, sizeof(struct xsc_txq_stats)); + } + + return 0; +} + static int xsc_ethdev_link_update(__rte_unused struct rte_eth_dev *dev, __rte_unused int wait_to_complete) @@ -1104,6 +1178,8 @@ const struct eth_dev_ops xsc_dev_ops = { .dev_set_link_up = xsc_ethdev_set_link_up, .dev_close = xsc_ethdev_close, .link_update = xsc_ethdev_link_update, + .stats_get = xsc_ethdev_stats_get, + .stats_reset = xsc_ethdev_stats_reset, .dev_infos_get = xsc_ethdev_infos_get, .rx_queue_setup = xsc_ethdev_rx_queue_setup, .tx_queue_setup = xsc_ethdev_tx_queue_setup, diff --git a/drivers/net/xsc/xsc_rxtx.c b/drivers/net/xsc/xsc_rxtx.c index 7a31cd428c..8aed8f4b12 100644 --- a/drivers/net/xsc/xsc_rxtx.c +++ b/drivers/net/xsc/xsc_rxtx.c @@ -62,6 +62,7 @@ xsc_rx_poll_len(struct xsc_rxq_data *rxq, volatile struct xsc_cqe *cqe) ret = check_cqe_own(cqe, rxq->cqe_n, rxq->cq_ci); if (unlikely(ret != XSC_CQE_OWNER_SW)) { if (unlikely(ret == XSC_CQE_OWNER_ERR)) { + ++rxq->stats.rx_errors; /* TODO */ if (ret == XSC_CQE_OWNER_HW || ret == -1) @@ -116,8 +117,10 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) rte_prefetch0(wqe); rep = rte_mbuf_raw_alloc(seg->pool); - if (unlikely(rep == NULL)) + if (unlikely(rep == NULL)) { + ++rxq->stats.rx_nombuf; break; + } if (!pkt) { if (read_cqe_num) { @@ -166,6 +169,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) /* Fill wqe */ wqe->va = rte_cpu_to_le_64(rte_pktmbuf_iova(rep)); rte_pktmbuf_data_len(seg) = len; + rxq->stats.rx_bytes += rte_pktmbuf_pkt_len(pkt); *(pkts++) = pkt; pkt = NULL; @@ -200,6 +204,7 @@ xsc_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) rxq->nb_rx_hold = 0; } + rxq->stats.rx_pkts += nb_pkts; return nb_pkts; } @@ -239,6 +244,7 @@ xsc_tx_cqes_handle(struct xsc_txq_data *__rte_restrict txq) ++txq->cq_ci; txq->cq_pi = txq->cq_ci; last_cqe = NULL; + ++txq->stats.tx_errors; continue; } @@ -348,6 +354,7 @@ xsc_tx_wqes_fill(struct xsc_txq_data *__rte_restrict txq, /* init wqe data segs */ xsc_tx_wqe_data_seg_init(mbuf, wqe); ++txq->wqe_ci; + txq->stats.tx_bytes += rte_pktmbuf_pkt_len(mbuf); } return wqe; @@ -432,5 +439,7 @@ xsc_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) goto loop; exit: + + txq->stats.tx_pkts += (pkts_n - remain_n); return pkts_n - remain_n; } diff --git a/drivers/net/xsc/xsc_rxtx.h b/drivers/net/xsc/xsc_rxtx.h index ce6e47ad4c..3d1e3ba83a 100644 --- a/drivers/net/xsc/xsc_rxtx.h +++ b/drivers/net/xsc/xsc_rxtx.h @@ -85,6 +85,12 @@ struct xsc_cqe { uint8_t owner:1; }; +struct xsc_txq_stats { + uint64_t tx_pkts; /* Total number of tx packets */ + uint64_t tx_bytes; /* Total number of tx bytes */ + uint64_t tx_errors; /* Total number of tx error packets */ +}; + struct __rte_cache_aligned xsc_txq_data { uint16_t idx; /*QP idx */ uint16_t port_id; @@ -116,12 +122,20 @@ struct __rte_cache_aligned xsc_txq_data { volatile uint32_t *qp_db; volatile uint32_t *cq_db; struct xsc_ethdev_priv *priv; + struct xsc_txq_stats stats; uint32_t socket; uint8_t tso_en:1; /* TSO enable 0-off 1-on */ uint16_t *fcqs; /* Free completion queue. */ struct rte_mbuf *elts[0]; /* Storage for queued packets, for free */ }; +struct xsc_rxq_stats { + uint64_t rx_pkts; /* Total number of rx packets */ + uint64_t rx_bytes; /* Total number of rx bytes */ + uint64_t rx_errors; /* Total number of rx error packets */ + uint64_t rx_nombuf; /* Total number of rx mbuf alloc failed */ +}; + struct xsc_cqe_u64 { struct xsc_cqe cqe0; struct xsc_cqe cqe1; @@ -158,6 +172,7 @@ struct __rte_cache_aligned xsc_rxq_data { const struct rte_memzone *rq_pas; /* Palist memory */ uint32_t socket; struct xsc_ethdev_priv *priv; + struct xsc_rxq_stats stats; /* attr */ uint32_t csum:1; /* Checksum offloading enable */ uint32_t hw_timestamp:1;