From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6AE8D459C3; Wed, 18 Sep 2024 08:10:56 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E429742E93; Wed, 18 Sep 2024 08:10:02 +0200 (CEST) Received: from lf-2-51.ptr.blmpb.com (lf-2-51.ptr.blmpb.com [101.36.218.51]) by mails.dpdk.org (Postfix) with ESMTP id 8A58342E79 for ; Wed, 18 Sep 2024 08:09:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726639793; 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=gZymznGxK7zVWl1qkuW5hXFQ9DcKvG6OMTD9+NDi+i2e/BBceypXz6ZJ7PWthBOo9r1u6u Xb1xOU3jGgAfTyjgLFIhDR3in04f3wMjxRPk3+JPVp7Gor3mWTQMDvNo4khq68buL0O406 AQD3ym8+zdvj5loEdv0nFLAQmPkKc2hVvsj5PKwNNa89dgj877KTPwxpOYLSfpurizOMcl 7dZ7DP5+MLsmW8EHD1S1sfjbmDrvOQiWvuCkJdTKrL6Tu3nw7Hi1ZxsDaZAvITBuvOJ0sU Kcd2cFNFX8/rEsewfrlX9pilQPGkmiQrY3I3EIhFl+PTamtBYfa2zr11Z4ru+g== To: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Cc: , "WanRenyong" From: "WanRenyong" Subject: [PATCH v3 08/19] net/xsc: create eth devices for representor ports X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 7bit Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 18 Sep 2024 14:09:51 +0800 Date: Wed, 18 Sep 2024 14:09:25 +0800 Message-Id: <20240918060936.1231758-9-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 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) \ -- 2.25.1