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) \