From patchwork Fri Jun 25 11:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueming Li X-Patchwork-Id: 94862 X-Patchwork-Delegate: thomas@monjalon.net 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 04170A0547; Fri, 25 Jun 2021 13:48:00 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 883F040698; Fri, 25 Jun 2021 13:48:00 +0200 (CEST) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2049.outbound.protection.outlook.com [40.107.220.49]) by mails.dpdk.org (Postfix) with ESMTP id BE27E4068A for ; Fri, 25 Jun 2021 13:47:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CdWzAF3tPXLZivdjOFfPQu0TpacAFICFylf3T8i12x41F3qqC2IKDvN8OMx/QdJRkYzwbNQkNS0oJO4y0yZV19CwzlrYP8PFD7wnVKBjC9GceLoII4gixZ9o04cUXwtilawZA7a9kkJqRwmu+MnVk5YZ7U0UMLzq6ej3DlXThS7aTVwK0bdOSaM1Y2gxWgH93PJxLb3y2cZCpHGwqKHV77BsYvzgmXKAbUMd9LN4BNhYagYhW42mkFTW/YFB1JA+0YLMu4yhTWIqciIrnR4mCJRxX3r77ZB79/r5uNly5qdc40bJIRhAyAaHaT4tmiDb/ImXzIpJ35p0+qkpPvmQaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lgofwfR+I2p5mM2niAUugfp6Up6C7Sr+QYp6lvAb53k=; b=Qa/jx1wFsvPX8lccqKgc6oAmPBY9QBepk+AQ6YxLotlMm2JjH5B4148I+ssZ4sfs8ED5ZQWATTG57s/W9YO14F4kZoNd491yb8wr9vO09Es/JwaPfxVev70SmlfbG4d3YIrgka24his+SzfG/vZ7EzL5CU00qp/HjiyQTPPWnykRUYjhgRj+aQLPe/ha2EK5F8FXcOvYIj+VicN4MHa4EgmY3HEQYU8LjDjNh03FfoXZ6bte8H76ha6AWYJlolvjKbpW/7PVDxveiReZQrw3GqXr/+1QhFEAKKIwjrFd112FOLkjiamp0A1PrWqcyI7wWZ1obClCU3hCmWGikFGUJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=huawei.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lgofwfR+I2p5mM2niAUugfp6Up6C7Sr+QYp6lvAb53k=; b=eUjGoezv82RtWoVOKJ7YbuI85XPdVZfhFvKWNWIfyLf7gD9r5Hy5wzxB77i+1xu/tZZPidc8p+eAgn7lnWoj4e6lB2s6E9nZcy8tA5V1QftS1uFrYP8YMx3NnPT2JHa3hZXJGqkhSkJr9pd0m8Z/n+PkjlMymGfC7MBGMyG+utTh2S8YVIcv1W9V/yY1FQHGR6noz/Xn5FnA55UapZvLFaDl//LFlsijDAgGjrJp9eWNE5JCzdVD3o2XAu/HSKeZ+ntuSlSK47KKsCn1+Wz+iSX5nUCyKW8lxkJvH2fpoCiKHIUJPomM9wW+NeJtdnfauPG3f82+17Yfjbrjwicgzw== Received: from BN6PR16CA0048.namprd16.prod.outlook.com (2603:10b6:405:14::34) by DM5PR12MB1674.namprd12.prod.outlook.com (2603:10b6:4:11::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.20; Fri, 25 Jun 2021 11:47:56 +0000 Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:405:14:cafe::4a) by BN6PR16CA0048.outlook.office365.com (2603:10b6:405:14::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18 via Frontend Transport; Fri, 25 Jun 2021 11:47:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; huawei.com; dkim=none (message not signed) header.d=none;huawei.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4264.18 via Frontend Transport; Fri, 25 Jun 2021 11:47:56 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 25 Jun 2021 11:47:52 +0000 From: Xueming Li To: CC: , , Thomas Monjalon , Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko , "Andrew Rybchenko" , Chas Williams , "Min Hu (Connor)" , Beilei Xing , Jingjing Wu Date: Fri, 25 Jun 2021 14:47:24 +0300 Message-ID: <20210625114726.776425-1-xuemingl@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210623000349.631468-2-xuemingl@nvidia.com> References: <20210623000349.631468-2-xuemingl@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f22fb40-c466-4a72-8fbb-08d937cf12d2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1674: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:85; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NulqC8Kw75FsBulKqzrrTNhexcseqmS979P2OqsX848yG2G3kDf/b44BVkWAH7kH02ki5CC6F4ShP9Tsf0LGkuCDcFvEXEsz2wRaeSXNP3gyOgNdDfUBYl9206OZnJIJrDiVixPA61wYB4vVBzVNdgX9Tw0zt64Mbk6vIzemtkxPG3Q3YabAMxU0s0FvMv1LJdR/y3I0gFNk45edaO+mJZb07XslHSAEE/leuBzmL1nbjsd9AbbehfGY6ZjN0iNBc4YNjSiBHMzXqgv+4mWlg8nLdByNTounHMIOFxLTqT57IgOauBxYBrzKN9+wubHBVzvGuB3/WnIa3hd648P0YpAX7qG6C/fJmiW/oxYDupq/nmgYhnxg4MceIgC95S+Jbkg3R7MM9z24/duoq0BDGVCDARY0rAasjk3wT7S2DWvoXxZxjFVsD6K4fgy/k0iGX1fJF1K9ugDfunEy2voZ6m8WNY1RMhe5s//vQVSzWbafbnwmFGu4HGM8PSixrZQoRNK988w2zi5/KAWb1t6+YMM5MFZoraLHrrp5Jd+Gp7KEd9mbEFiQs1OJ9fnghtbhegLuZpNOMkDu9+cPYhFOKWYy0+5k3ivK3Jy0LZIyKDAl42rGxR4ykGBr6cdgywYXfL2qi1vXJ9I0sqh9dJmfP8kfz5RXvbJMmwVg6/mOvLo= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(136003)(346002)(396003)(36840700001)(46966006)(16526019)(336012)(186003)(70586007)(4326008)(82310400003)(1076003)(26005)(356005)(36756003)(86362001)(6666004)(8676002)(2616005)(316002)(70206006)(426003)(8936002)(109986005)(47076005)(7636003)(54906003)(478600001)(7696005)(5660300002)(83380400001)(55016002)(2906002)(36860700001)(82740400003)(6286002)(266003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2021 11:47:56.0624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f22fb40-c466-4a72-8fbb-08d937cf12d2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1674 Subject: [dpdk-dev] [PATCH v6 1/2] devargs: add common key definition 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 Sender: "dev" Adds common devargs key definition for "bus", "class" and "driver". Acked-by: Thomas Monjalon Signed-off-by: Xueming Li Acked-by: Andrew Rybchenko --- drivers/common/mlx5/mlx5_common.h | 2 -- drivers/common/mlx5/mlx5_common_pci.c | 2 +- drivers/common/sfc_efx/sfc_efx.c | 7 +++---- drivers/common/sfc_efx/sfc_efx.h | 2 -- drivers/net/bonding/rte_eth_bond_args.c | 2 +- drivers/net/i40e/i40e_ethdev_vf.c | 5 ++--- drivers/net/iavf/iavf_ethdev.c | 5 ++--- drivers/net/mlx5/mlx5.c | 4 ++-- drivers/net/sfc/sfc_kvargs.c | 2 +- drivers/vdpa/mlx5/mlx5_vdpa.c | 2 +- lib/eal/common/eal_common_devargs.c | 12 ++++++------ lib/eal/include/rte_devargs.h | 24 ++++++++++++++++++++++++ 12 files changed, 43 insertions(+), 26 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 1fbefe0fa6..306f2f1ab7 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -208,8 +208,6 @@ __rte_internal int mlx5_get_ifname_sysfs(const char *ibdev_path, char *ifname); -#define MLX5_CLASS_ARG_NAME "class" - enum mlx5_class { MLX5_CLASS_INVALID, MLX5_CLASS_NET = RTE_BIT64(0), diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c index 3f16cd21cf..34747c4e07 100644 --- a/drivers/common/mlx5/mlx5_common_pci.c +++ b/drivers/common/mlx5/mlx5_common_pci.c @@ -118,7 +118,7 @@ bus_cmdline_options_handler(__rte_unused const char *key, static int parse_class_options(const struct rte_devargs *devargs) { - const char *key = MLX5_CLASS_ARG_NAME; + const char *key = RTE_DEVARGS_KEY_CLASS; struct rte_kvargs *kvlist; int ret = 0; diff --git a/drivers/common/sfc_efx/sfc_efx.c b/drivers/common/sfc_efx/sfc_efx.c index 0b78933d9f..2dc5545760 100644 --- a/drivers/common/sfc_efx/sfc_efx.c +++ b/drivers/common/sfc_efx/sfc_efx.c @@ -42,7 +42,6 @@ enum sfc_efx_dev_class sfc_efx_dev_class_get(struct rte_devargs *devargs) { struct rte_kvargs *kvargs; - const char *key = SFC_EFX_KVARG_DEV_CLASS; enum sfc_efx_dev_class dev_class = SFC_EFX_DEV_CLASS_NET; if (devargs == NULL) @@ -52,9 +51,9 @@ sfc_efx_dev_class_get(struct rte_devargs *devargs) if (kvargs == NULL) return dev_class; - if (rte_kvargs_count(kvargs, key) != 0) { - rte_kvargs_process(kvargs, key, sfc_efx_kvarg_dev_class_handler, - &dev_class); + if (rte_kvargs_count(kvargs, RTE_DEVARGS_KEY_CLASS) != 0) { + rte_kvargs_process(kvargs, RTE_DEVARGS_KEY_CLASS, + sfc_efx_kvarg_dev_class_handler, &dev_class); } rte_kvargs_free(kvargs); diff --git a/drivers/common/sfc_efx/sfc_efx.h b/drivers/common/sfc_efx/sfc_efx.h index 6b6164cb1f..c16eca60f3 100644 --- a/drivers/common/sfc_efx/sfc_efx.h +++ b/drivers/common/sfc_efx/sfc_efx.h @@ -19,8 +19,6 @@ extern "C" { #endif -#define SFC_EFX_KVARG_DEV_CLASS "class" - enum sfc_efx_dev_class { SFC_EFX_DEV_CLASS_INVALID = 0, SFC_EFX_DEV_CLASS_NET, diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c index 764b1b8c8e..5406e1c934 100644 --- a/drivers/net/bonding/rte_eth_bond_args.c +++ b/drivers/net/bonding/rte_eth_bond_args.c @@ -18,7 +18,7 @@ const char *pmd_bond_init_valid_arguments[] = { PMD_BOND_SOCKET_ID_KVARG, PMD_BOND_MAC_ADDR_KVARG, PMD_BOND_AGG_MODE_KVARG, - "driver", + RTE_DEVARGS_KEY_DRIVER, NULL }; diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c index 385ebedcd3..0cfe13b7b2 100644 --- a/drivers/net/i40e/i40e_ethdev_vf.c +++ b/drivers/net/i40e/i40e_ethdev_vf.c @@ -1660,7 +1660,6 @@ static int i40evf_driver_selected(struct rte_devargs *devargs) { struct rte_kvargs *kvlist; - const char *key = "driver"; int ret = 0; if (devargs == NULL) @@ -1670,13 +1669,13 @@ i40evf_driver_selected(struct rte_devargs *devargs) if (kvlist == NULL) return 0; - if (!rte_kvargs_count(kvlist, key)) + if (!rte_kvargs_count(kvlist, RTE_DEVARGS_KEY_DRIVER)) goto exit; /* i40evf driver selected when there's a key-value pair: * driver=i40evf */ - if (rte_kvargs_process(kvlist, key, + if (rte_kvargs_process(kvlist, RTE_DEVARGS_KEY_DRIVER, i40evf_check_driver_handler, NULL) < 0) goto exit; diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index 5290588b17..472538181e 100644 --- a/drivers/net/iavf/iavf_ethdev.c +++ b/drivers/net/iavf/iavf_ethdev.c @@ -2448,7 +2448,6 @@ static int iavf_drv_i40evf_selected(struct rte_devargs *devargs, uint16_t device_id) { struct rte_kvargs *kvlist; - const char *key = "driver"; int ret = 0; if (device_id != IAVF_DEV_ID_VF && @@ -2464,13 +2463,13 @@ iavf_drv_i40evf_selected(struct rte_devargs *devargs, uint16_t device_id) if (kvlist == NULL) return 0; - if (!rte_kvargs_count(kvlist, key)) + if (!rte_kvargs_count(kvlist, RTE_DEVARGS_KEY_DRIVER)) goto exit; /* i40evf driver selected when there's a key-value pair: * driver=i40evf */ - if (rte_kvargs_process(kvlist, key, + if (rte_kvargs_process(kvlist, RTE_DEVARGS_KEY_DRIVER, iavf_drv_i40evf_check_handler, NULL) < 0) goto exit; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index cf1815cb74..d0faa45944 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1931,7 +1931,7 @@ mlx5_args_check(const char *key, const char *val, void *opaque) config->max_dump_files_num = tmp; } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) { config->lro.timeout = tmp; - } else if (strcmp(MLX5_CLASS_ARG_NAME, key) == 0) { + } else if (strcmp(RTE_DEVARGS_KEY_CLASS, key) == 0) { DRV_LOG(DEBUG, "class argument is %s.", val); } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) { config->log_hp_size = tmp; @@ -2002,7 +2002,7 @@ mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs) MLX5_REPRESENTOR, MLX5_MAX_DUMP_FILES_NUM, MLX5_LRO_TIMEOUT_USEC, - MLX5_CLASS_ARG_NAME, + RTE_DEVARGS_KEY_CLASS, MLX5_HP_BUF_SIZE, MLX5_RECLAIM_MEM, MLX5_SYS_MEM_EN, diff --git a/drivers/net/sfc/sfc_kvargs.c b/drivers/net/sfc/sfc_kvargs.c index 0efa92ed28..974c05e68e 100644 --- a/drivers/net/sfc/sfc_kvargs.c +++ b/drivers/net/sfc/sfc_kvargs.c @@ -28,7 +28,7 @@ sfc_kvargs_parse(struct sfc_adapter *sa) SFC_KVARG_TX_DATAPATH, SFC_KVARG_FW_VARIANT, SFC_KVARG_RXD_WAIT_TIMEOUT_NS, - SFC_EFX_KVARG_DEV_CLASS, + RTE_DEVARGS_KEY_CLASS, NULL, }; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index e5e03e6582..8b5bfd8c3d 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -588,7 +588,7 @@ mlx5_vdpa_args_check_handler(const char *key, const char *val, void *opaque) unsigned long tmp; int n_cores = sysconf(_SC_NPROCESSORS_ONLN); - if (strcmp(key, "class") == 0) + if (strcmp(key, RTE_DEVARGS_KEY_CLASS) == 0) return 0; errno = 0; tmp = strtoul(val, NULL, 0); diff --git a/lib/eal/common/eal_common_devargs.c b/lib/eal/common/eal_common_devargs.c index b31ac879a9..23aaf8b7e4 100644 --- a/lib/eal/common/eal_common_devargs.c +++ b/lib/eal/common/eal_common_devargs.c @@ -49,9 +49,9 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, const char *str; struct rte_kvargs *kvlist; } layers[] = { - { "bus=", NULL, NULL, }, - { "class=", NULL, NULL, }, - { "driver=", NULL, NULL, }, + { RTE_DEVARGS_KEY_BUS "=", NULL, NULL, }, + { RTE_DEVARGS_KEY_CLASS "=", NULL, NULL, }, + { RTE_DEVARGS_KEY_DRIVER "=", NULL, NULL, }, }; struct rte_kvargs_pair *kv = NULL; struct rte_class *cls = NULL; @@ -118,7 +118,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, if (layers[i].kvlist == NULL) continue; kv = &layers[i].kvlist->pairs[0]; - if (strcmp(kv->key, "bus") == 0) { + if (strcmp(kv->key, RTE_DEVARGS_KEY_BUS) == 0) { bus = rte_bus_find_by_name(kv->value); if (bus == NULL) { RTE_LOG(ERR, EAL, "Could not find bus \"%s\"\n", @@ -126,7 +126,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, ret = -EFAULT; goto get_out; } - } else if (strcmp(kv->key, "class") == 0) { + } else if (strcmp(kv->key, RTE_DEVARGS_KEY_CLASS) == 0) { cls = rte_class_find_by_name(kv->value); if (cls == NULL) { RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n", @@ -134,7 +134,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs, ret = -EFAULT; goto get_out; } - } else if (strcmp(kv->key, "driver") == 0) { + } else if (strcmp(kv->key, RTE_DEVARGS_KEY_DRIVER) == 0) { /* Ignore */ continue; } diff --git a/lib/eal/include/rte_devargs.h b/lib/eal/include/rte_devargs.h index 1e595b3c51..cd90944fe8 100644 --- a/lib/eal/include/rte_devargs.h +++ b/lib/eal/include/rte_devargs.h @@ -25,6 +25,30 @@ extern "C" { #include #include +/** + * Bus type key in global devargs syntax. + * + * Legacy devargs parser doesn't use this key as bus type + * is resolved as first optional value separated by ":". + */ +#define RTE_DEVARGS_KEY_BUS "bus" + +/** + * Class type key in global devargs syntax. + * + * Legacy devargs parser doesn't parse class type. PMD driver is + * encouraged to use this key to resolve class type. + */ +#define RTE_DEVARGS_KEY_CLASS "class" + +/** + * Driver type key in global devargs syntax. + * + * Legacy devargs parser doesn't parse driver type. PMD driver is + * encouraged to use this key to resolve driver type. + */ +#define RTE_DEVARGS_KEY_DRIVER "driver" + /** * Type of generic device */ From patchwork Fri Jun 25 11:47:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xueming Li X-Patchwork-Id: 94863 X-Patchwork-Delegate: thomas@monjalon.net 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 67F13A0547; Fri, 25 Jun 2021 13:48:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E0C83410DD; Fri, 25 Jun 2021 13:48:02 +0200 (CEST) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) by mails.dpdk.org (Postfix) with ESMTP id 173E24068A for ; Fri, 25 Jun 2021 13:48:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l0X/nnhaE/lvGAO++xTn2hHRj5hgRFXeLmZdDJ08HbZLq5gXaKUe36pN3TbkEtyU9g1UQH28LwNup5rXsT3eqNKA+RhnlH8tvCH3gsrzdYZEv8wq6hk3MJzOEQ2bEvPQ5uvyPOIdyqUTkhDjWrSD5zYyc+PTP9Fi7tjzJZKZts6Lwtsl1G2QMs4EqIP77SjHp61/aC4/sNqzCH1Ruc4xWeBfWhNOs+eQxr1LU/QykP6IY6eK/6urebgnExRYN3cBezDpcBh6KjeXtT4DKJGqQ068/CsVOkgd64ghSVkD0yiVyZCWcm9p0iQIuVpTI9/8UR8nALauhGfoholDPlJJ3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p2L7GVC6hiOFIcKwQeZ6sf9j92D/LCQwJBJYqwsWEUI=; b=nxXRQiLk+XGCYUgSObUIexCdkhYSoFytzUlO1CUSjhld1n4V1kExVbV194wXxHhF1lM+ai2NpLWT0fM53jpJ8sIm/LKwdDqD4Q8afP9fiWC9P1GQ2fwqlBayHsUX589d1ciR/Jsu96isSdAHuEn1MX3Aggu3Ii0vJaljUl+CS7ukfQICVZU1wBWwNrvcML4ktQBTbWdCBkB2JAbcOz50ZMj67pPrmuZJ6c98disG4wiuWKerB1RCcpWBYJ7jpecIXpyzxYUPiN0OvPBp/4iNFcA6d9zaZWMgTR8umO8H963s2y2YR1B7cFlzHyXljy4aQR+hOZgPn4F2UK8GtlffCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=ashroe.eu smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=p2L7GVC6hiOFIcKwQeZ6sf9j92D/LCQwJBJYqwsWEUI=; b=kP0cOvpnOWRttanrpNmRFXN4B/okdACJ8lsswZBsIEfICRO5Z3CJ2/6byssj5jctDt7mMBsd5JYb3GDM1KwBwRGWRc6EVAQk/jIE6MBVHIiF1vyCHNI0h9LjHi+uKlIz0XI+4H3lH4IzfxAdKvekWVs8/C1wIwkxk1xV/g6lqEvC0qQvUPF92mKgD+JBDuPd/G4U63K7lkNwzWAYD8rOkaY5F/0mD/jo+8ZtCHQqb/LHgKyM27iHZWD+cETcMtxkWkaTkOLR4Ns57TvJ2ql5+yScAmYQsDu3zq2HOEovZoAetQOuYzwKpfIpgpIljtitaIW/Ls5YjKAuAuT3VuKLYw== Received: from BN6PR16CA0043.namprd16.prod.outlook.com (2603:10b6:405:14::29) by DM5PR12MB1722.namprd12.prod.outlook.com (2603:10b6:3:107::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.21; Fri, 25 Jun 2021 11:47:58 +0000 Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:405:14:cafe::b) by BN6PR16CA0043.outlook.office365.com (2603:10b6:405:14::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18 via Frontend Transport; Fri, 25 Jun 2021 11:47:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; ashroe.eu; dkim=none (message not signed) header.d=none;ashroe.eu; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4264.18 via Frontend Transport; Fri, 25 Jun 2021 11:47:57 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 25 Jun 2021 11:47:55 +0000 From: Xueming Li To: CC: , , Wang Haiyue , Thomas Monjalon , Kinsella Ray , Neil Horman Date: Fri, 25 Jun 2021 14:47:25 +0300 Message-ID: <20210625114726.776425-2-xuemingl@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210623000349.631468-2-xuemingl@nvidia.com> References: <20210623000349.631468-2-xuemingl@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f1b6eacb-5ffa-4bbe-aa1d-08d937cf1386 X-MS-TrafficTypeDiagnostic: DM5PR12MB1722: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CQLYnUfJOgv1OgWJfWnwo8Zlqmmx2JR0v4uBaEpSev92mmuOFeGheD4ci8M9JmImYhMVBWW9xTTkPzdmBEKwEUsA+lpDWgfPGbzIoyFIhLInnr2L8ey7DZTLoVgm4edqSW0EhQ7LYDpR6nq4dSczpHAZVmgUxKalWCPvPJRZ+Ej+yxj/6UDtJmVzDEU4xSc6FDuc8gkMesLmrC1ZWof6T9DBDlIPChLgaWU7dqJmZJ2MExxQfUu/kcbsfAg2o8C/jJPjjZ3Zh+KTyGT1awYtgs9l9orFtpjsTn0XHqZqe+oIjYXv2UScjtwCnBXQdvPCRpn8/c5sRe24xXtns9mZQ1nwKp19gt0MVzpGtxy8c1o/M4agJV8lvPJTkg52MVqaEkdrzhBkBgRyi4e3i2y3pF7RKLrHJXEymwPI4QV9gQILudhNQYnRxaiwk82I0OnvWR1GlNvRKyW6Z8pEudkF9/8XrwQDbrdv2hvXnEcjuKtG0UlSjpKLL+Gh8lxGMQ16uvK0Jhw1HDjEEOXtDeAxPZURgbB433nB1he28QDyc4iOw4J+gcgZkSp5uUDxU3yiTQwi7YN+2e7senZ6iC75FwrdCZEUCYJwmufn9twfmnfPGYwjeQ4pF9wFABpw3qYEhL5EFleurubOO3ruWz4OBVQxnfkkGzyel153HzVRMWZXZ/pr4rqLq1Pu23nuGs9o48Kuco6ITWZJCtbZBODnGye5dI2T6f8LAEdhbQiUTZnXOcVC8k42sc/JRM/m9k1u52Y89tR1UkQAX8X+hfbZC6MEGcRVu9IDq5SIjo2XNIWExxEj5xxyZwhkfutuTMXYa3AIeuHAQhlq16q7ZAivyilwCD1hQRhGxOeDVaEQtoI= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(396003)(39860400002)(136003)(346002)(46966006)(36840700001)(6286002)(82740400003)(36756003)(47076005)(109986005)(30864003)(5660300002)(336012)(16526019)(2616005)(4326008)(7696005)(426003)(26005)(186003)(86362001)(8936002)(6666004)(1076003)(8676002)(966005)(83380400001)(55016002)(70206006)(70586007)(2906002)(36860700001)(54906003)(82310400003)(7636003)(478600001)(316002)(356005)(266003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2021 11:47:57.2167 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1b6eacb-5ffa-4bbe-aa1d-08d937cf1386 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1722 Subject: [dpdk-dev] [PATCH v6 2/2] bus/auxiliary: introduce auxiliary bus 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 Sender: "dev" Auxiliary bus [1] provides a way to split function into child-devices representing sub-domains of functionality. Each auxiliary device represents a part of its parent functionality. Auxiliary device is identified by unique device name, sysfs path: /sys/bus/auxiliary/devices/ Devargs legacy syntax ofauxiliary device: -a auxiliary:[,args...] Devargs generic syntax of auxiliary device: -a bus=auxiliary,name=,,/class=,,/driver=,, [1] kernel auxiliary bus document: https://www.kernel.org/doc/html/latest/driver-api/auxiliary_bus.html Signed-off-by: Xueming Li Cc: Wang Haiyue Cc: Thomas Monjalon Cc: Kinsella Ray Acked-by: Andrew Rybchenko Acked-by: Ray Kinsella --- MAINTAINERS | 5 + doc/guides/rel_notes/release_21_08.rst | 6 + drivers/bus/auxiliary/auxiliary_common.c | 411 ++++++++++++++++++++++ drivers/bus/auxiliary/auxiliary_params.c | 59 ++++ drivers/bus/auxiliary/linux/auxiliary.c | 141 ++++++++ drivers/bus/auxiliary/meson.build | 16 + drivers/bus/auxiliary/private.h | 74 ++++ drivers/bus/auxiliary/rte_bus_auxiliary.h | 201 +++++++++++ drivers/bus/auxiliary/version.map | 7 + drivers/bus/meson.build | 1 + 10 files changed, 921 insertions(+) create mode 100644 drivers/bus/auxiliary/auxiliary_common.c create mode 100644 drivers/bus/auxiliary/auxiliary_params.c create mode 100644 drivers/bus/auxiliary/linux/auxiliary.c create mode 100644 drivers/bus/auxiliary/meson.build create mode 100644 drivers/bus/auxiliary/private.h create mode 100644 drivers/bus/auxiliary/rte_bus_auxiliary.h create mode 100644 drivers/bus/auxiliary/version.map diff --git a/MAINTAINERS b/MAINTAINERS index 5877a16971..eaf691ca6a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -525,6 +525,11 @@ F: doc/guides/mempool/octeontx2.rst Bus Drivers ----------- +Auxiliary bus driver +M: Parav Pandit +M: Xueming Li +F: drivers/bus/auxiliary/ + Intel FPGA bus M: Rosen Xu F: drivers/bus/ifpga/ diff --git a/doc/guides/rel_notes/release_21_08.rst b/doc/guides/rel_notes/release_21_08.rst index a6ecfdf3ce..e7ef4c8a05 100644 --- a/doc/guides/rel_notes/release_21_08.rst +++ b/doc/guides/rel_notes/release_21_08.rst @@ -55,6 +55,12 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added auxiliary bus support.** + + Auxiliary bus provides a way to split function into child-devices + representing sub-domains of functionality. Each auxiliary device + represents a part of its parent functionality. + Removed Items ------------- diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c new file mode 100644 index 0000000000..8a75306da5 --- /dev/null +++ b/drivers/bus/auxiliary/auxiliary_common.c @@ -0,0 +1,411 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "private.h" +#include "rte_bus_auxiliary.h" + +static struct rte_devargs * +auxiliary_devargs_lookup(const char *name) +{ + struct rte_devargs *devargs; + + RTE_EAL_DEVARGS_FOREACH(RTE_BUS_AUXILIARY_NAME, devargs) { + if (strcmp(devargs->name, name) == 0) + return devargs; + } + return NULL; +} + +/* + * Test whether the auxiliary device exist + * + * Stub for OS not supporting auxiliary bus. + */ +__rte_weak bool +auxiliary_dev_exists(const char *name) +{ + RTE_SET_USED(name); + return false; +} + +/* + * Scan the devices in the auxiliary bus. + * + * Stub for OS not supporting auxiliary bus. + */ +__rte_weak int +auxiliary_scan(void) +{ + return 0; +} + +/* + * Update a device's devargs being scanned. + * + * @param aux_dev + * AUXILIARY device. + */ +void +auxiliary_on_scan(struct rte_auxiliary_device *aux_dev) +{ + aux_dev->device.devargs = auxiliary_devargs_lookup(aux_dev->name); +} + +/* + * Match the auxiliary driver and device using driver function. + */ +bool +auxiliary_match(const struct rte_auxiliary_driver *aux_drv, + const struct rte_auxiliary_device *aux_dev) +{ + if (aux_drv->match == NULL) + return false; + return aux_drv->match(aux_dev->name); +} + +/* + * Call the probe() function of the driver. + */ +static int +rte_auxiliary_probe_one_driver(struct rte_auxiliary_driver *drv, + struct rte_auxiliary_device *dev) +{ + enum rte_iova_mode iova_mode; + int ret; + + if ((drv == NULL) || (dev == NULL)) + return -EINVAL; + + /* Check if driver supports it. */ + if (!auxiliary_match(drv, dev)) + /* Match of device and driver failed */ + return 1; + + /* No initialization when marked as blocked, return without error. */ + if (dev->device.devargs != NULL && + dev->device.devargs->policy == RTE_DEV_BLOCKED) { + AUXILIARY_LOG(INFO, "Device is blocked, not initializing"); + return -1; + } + + if (dev->device.numa_node < 0) { + AUXILIARY_LOG(INFO, "Device is not NUMA-aware, defaulting socket to 0"); + dev->device.numa_node = 0; + } + + iova_mode = rte_eal_iova_mode(); + if ((drv->drv_flags & RTE_AUXILIARY_DRV_NEED_IOVA_AS_VA) > 0 && + iova_mode != RTE_IOVA_VA) { + AUXILIARY_LOG(ERR, "Driver %s expecting VA IOVA mode but current mode is PA, not initializing", + drv->driver.name); + return -EINVAL; + } + + dev->driver = drv; + + AUXILIARY_LOG(INFO, "Probe auxiliary driver: %s device: %s (socket %i)", + drv->driver.name, dev->name, dev->device.numa_node); + ret = drv->probe(drv, dev); + if (ret != 0) + dev->driver = NULL; + else + dev->device.driver = &drv->driver; + + return ret; +} + +/* + * Call the remove() function of the driver. + */ +static int +rte_auxiliary_driver_remove_dev(struct rte_auxiliary_device *dev) +{ + struct rte_auxiliary_driver *drv; + int ret = 0; + + if (dev == NULL) + return -EINVAL; + + drv = dev->driver; + + AUXILIARY_LOG(DEBUG, "Driver %s remove auxiliary device %s on NUMA socket %i", + drv->driver.name, dev->name, dev->device.numa_node); + + if (drv->remove != NULL) { + ret = drv->remove(dev); + if (ret < 0) + return ret; + } + + /* clear driver structure */ + dev->driver = NULL; + dev->device.driver = NULL; + + return 0; +} + +/* + * Call the probe() function of all registered driver for the given device. + * Return < 0 if initialization failed. + * Return 1 if no driver is found for this device. + */ +static int +auxiliary_probe_all_drivers(struct rte_auxiliary_device *dev) +{ + struct rte_auxiliary_driver *drv; + int rc; + + if (dev == NULL) + return -EINVAL; + + FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) { + if (!drv->match(dev->name)) + continue; + + rc = rte_auxiliary_probe_one_driver(drv, dev); + if (rc < 0) + /* negative value is an error */ + return rc; + if (rc > 0) + /* positive value means driver doesn't support it */ + continue; + return 0; + } + return 1; +} + +/* + * Scan the content of the auxiliary bus, and call the probe function for + * all registered drivers to try to probe discovered devices. + */ +static int +auxiliary_probe(void) +{ + struct rte_auxiliary_device *dev = NULL; + size_t probed = 0, failed = 0; + int ret = 0; + + FOREACH_DEVICE_ON_AUXILIARY_BUS(dev) { + probed++; + + ret = auxiliary_probe_all_drivers(dev); + if (ret < 0) { + if (ret != -EEXIST) { + AUXILIARY_LOG(ERR, "Requested device %s cannot be used", + dev->name); + rte_errno = errno; + failed++; + } + ret = 0; + } + } + + return (probed && probed == failed) ? -1 : 0; +} + +static int +auxiliary_parse(const char *name, void *addr) +{ + struct rte_auxiliary_driver *drv = NULL; + const char **out = addr; + + /* Allow empty device name "auxiliary:" to bypass entire bus scan. */ + if (strlen(name) == 0) + return 0; + + FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) { + if (drv->match(name)) + break; + } + if (drv != NULL && addr != NULL) + *out = name; + return drv != NULL ? 0 : -1; +} + +/* Register a driver */ +void +rte_auxiliary_register(struct rte_auxiliary_driver *driver) +{ + TAILQ_INSERT_TAIL(&auxiliary_bus.driver_list, driver, next); + driver->bus = &auxiliary_bus; +} + +/* Unregister a driver */ +void +rte_auxiliary_unregister(struct rte_auxiliary_driver *driver) +{ + TAILQ_REMOVE(&auxiliary_bus.driver_list, driver, next); + driver->bus = NULL; +} + +/* Add a device to auxiliary bus */ +void +auxiliary_add_device(struct rte_auxiliary_device *aux_dev) +{ + TAILQ_INSERT_TAIL(&auxiliary_bus.device_list, aux_dev, next); +} + +/* Insert a device into a predefined position in auxiliary bus */ +void +auxiliary_insert_device(struct rte_auxiliary_device *exist_aux_dev, + struct rte_auxiliary_device *new_aux_dev) +{ + TAILQ_INSERT_BEFORE(exist_aux_dev, new_aux_dev, next); +} + +/* Remove a device from auxiliary bus */ +static void +rte_auxiliary_remove_device(struct rte_auxiliary_device *auxiliary_dev) +{ + TAILQ_REMOVE(&auxiliary_bus.device_list, auxiliary_dev, next); +} + +static struct rte_device * +auxiliary_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, + const void *data) +{ + const struct rte_auxiliary_device *pstart; + struct rte_auxiliary_device *adev; + + if (start != NULL) { + pstart = RTE_DEV_TO_AUXILIARY_CONST(start); + adev = TAILQ_NEXT(pstart, next); + } else { + adev = TAILQ_FIRST(&auxiliary_bus.device_list); + } + while (adev != NULL) { + if (cmp(&adev->device, data) == 0) + return &adev->device; + adev = TAILQ_NEXT(adev, next); + } + return NULL; +} + +static int +auxiliary_plug(struct rte_device *dev) +{ + if (!auxiliary_dev_exists(dev->name)) + return -ENOENT; + return auxiliary_probe_all_drivers(RTE_DEV_TO_AUXILIARY(dev)); +} + +static int +auxiliary_unplug(struct rte_device *dev) +{ + struct rte_auxiliary_device *adev; + int ret; + + adev = RTE_DEV_TO_AUXILIARY(dev); + ret = rte_auxiliary_driver_remove_dev(adev); + if (ret == 0) { + rte_auxiliary_remove_device(adev); + rte_devargs_remove(dev->devargs); + free(adev); + } + return ret; +} + +static int +auxiliary_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) +{ + struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev); + + if (dev == NULL || aux_dev->driver == NULL) { + rte_errno = EINVAL; + return -1; + } + if (aux_dev->driver->dma_map == NULL) { + rte_errno = ENOTSUP; + return -1; + } + return aux_dev->driver->dma_map(aux_dev, addr, iova, len); +} + +static int +auxiliary_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, + size_t len) +{ + struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev); + + if (dev == NULL || aux_dev->driver == NULL) { + rte_errno = EINVAL; + return -1; + } + if (aux_dev->driver->dma_unmap == NULL) { + rte_errno = ENOTSUP; + return -1; + } + return aux_dev->driver->dma_unmap(aux_dev, addr, iova, len); +} + +bool +auxiliary_is_ignored_device(const char *name) +{ + struct rte_devargs *devargs = auxiliary_devargs_lookup(name); + + switch (auxiliary_bus.bus.conf.scan_mode) { + case RTE_BUS_SCAN_ALLOWLIST: + if (devargs && devargs->policy == RTE_DEV_ALLOWED) + return false; + break; + case RTE_BUS_SCAN_UNDEFINED: + case RTE_BUS_SCAN_BLOCKLIST: + if (devargs == NULL || devargs->policy != RTE_DEV_BLOCKED) + return false; + break; + } + return true; +} + +static enum rte_iova_mode +auxiliary_get_iommu_class(void) +{ + const struct rte_auxiliary_driver *drv; + + FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) { + if ((drv->drv_flags & RTE_AUXILIARY_DRV_NEED_IOVA_AS_VA) > 0) + return RTE_IOVA_VA; + } + + return RTE_IOVA_DC; +} + +struct rte_auxiliary_bus auxiliary_bus = { + .bus = { + .scan = auxiliary_scan, + .probe = auxiliary_probe, + .find_device = auxiliary_find_device, + .plug = auxiliary_plug, + .unplug = auxiliary_unplug, + .parse = auxiliary_parse, + .dma_map = auxiliary_dma_map, + .dma_unmap = auxiliary_dma_unmap, + .get_iommu_class = auxiliary_get_iommu_class, + .dev_iterate = auxiliary_dev_iterate, + }, + .device_list = TAILQ_HEAD_INITIALIZER(auxiliary_bus.device_list), + .driver_list = TAILQ_HEAD_INITIALIZER(auxiliary_bus.driver_list), +}; + +RTE_REGISTER_BUS(auxiliary, auxiliary_bus.bus); +RTE_LOG_REGISTER_DEFAULT(auxiliary_bus_logtype, NOTICE); diff --git a/drivers/bus/auxiliary/auxiliary_params.c b/drivers/bus/auxiliary/auxiliary_params.c new file mode 100644 index 0000000000..cd3fa56cb4 --- /dev/null +++ b/drivers/bus/auxiliary/auxiliary_params.c @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#include + +#include +#include +#include +#include + +#include "private.h" +#include "rte_bus_auxiliary.h" + +enum auxiliary_params { + RTE_AUXILIARY_PARAM_NAME, +}; + +static const char * const auxiliary_params_keys[] = { + [RTE_AUXILIARY_PARAM_NAME] = "name", +}; + +static int +auxiliary_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + int ret; + + ret = rte_kvargs_process(kvlist, + auxiliary_params_keys[RTE_AUXILIARY_PARAM_NAME], + rte_kvargs_strcmp, (void *)(uintptr_t)dev->name); + + return ret != 0 ? -1 : 0; +} + +void * +auxiliary_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it __rte_unused) +{ + rte_bus_find_device_t find_device; + struct rte_kvargs *kvargs = NULL; + struct rte_device *dev; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, auxiliary_params_keys); + if (kvargs == NULL) { + AUXILIARY_LOG(ERR, "cannot parse argument list %s", + str); + rte_errno = EINVAL; + return NULL; + } + } + find_device = auxiliary_bus.bus.find_device; + dev = find_device(start, auxiliary_dev_match, kvargs); + rte_kvargs_free(kvargs); + return dev; +} diff --git a/drivers/bus/auxiliary/linux/auxiliary.c b/drivers/bus/auxiliary/linux/auxiliary.c new file mode 100644 index 0000000000..8464487971 --- /dev/null +++ b/drivers/bus/auxiliary/linux/auxiliary.c @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "../rte_bus_auxiliary.h" +#include "../private.h" + +#define AUXILIARY_SYSFS_PATH "/sys/bus/auxiliary/devices" + +/* Scan one auxiliary sysfs entry, and fill the devices list from it. */ +static int +auxiliary_scan_one(const char *dirname, const char *name) +{ + struct rte_auxiliary_device *dev; + struct rte_auxiliary_device *dev2; + char filename[PATH_MAX]; + unsigned long tmp; + int ret; + + dev = malloc(sizeof(*dev)); + if (dev == NULL) + return -1; + + memset(dev, 0, sizeof(*dev)); + if (rte_strscpy(dev->name, name, sizeof(dev->name)) < 0) { + free(dev); + return -1; + } + dev->device.name = dev->name; + dev->device.bus = &auxiliary_bus.bus; + + /* Get NUMA node, default to 0 if not present */ + snprintf(filename, sizeof(filename), "%s/%s/numa_node", + dirname, name); + if (access(filename, F_OK) != -1) { + if (eal_parse_sysfs_value(filename, &tmp) == 0) + dev->device.numa_node = tmp; + else + dev->device.numa_node = -1; + } else { + dev->device.numa_node = 0; + } + + auxiliary_on_scan(dev); + + /* Device is valid, add in list (sorted) */ + TAILQ_FOREACH(dev2, &auxiliary_bus.device_list, next) { + ret = strcmp(dev->name, dev2->name); + if (ret > 0) + continue; + if (ret < 0) { + auxiliary_insert_device(dev2, dev); + } else { /* already registered */ + if (rte_dev_is_probed(&dev2->device) && + dev2->device.devargs != dev->device.devargs) { + /* To probe device with new devargs. */ + rte_devargs_remove(dev2->device.devargs); + auxiliary_on_scan(dev2); + } + free(dev); + } + return 0; + } + auxiliary_add_device(dev); + return 0; +} + +/* + * Test whether the auxiliary device exist + */ +bool +auxiliary_dev_exists(const char *name) +{ + DIR *dir; + char dirname[PATH_MAX]; + + snprintf(dirname, sizeof(dirname), "%s/%s", + AUXILIARY_SYSFS_PATH, name); + dir = opendir(dirname); + if (dir == NULL) + return false; + closedir(dir); + return true; +} + +/* + * Scan the devices in the auxiliary bus + */ +int +auxiliary_scan(void) +{ + struct dirent *e; + DIR *dir; + char dirname[PATH_MAX]; + struct rte_auxiliary_driver *drv; + + dir = opendir(AUXILIARY_SYSFS_PATH); + if (dir == NULL) { + AUXILIARY_LOG(INFO, "%s not found, is auxiliary module loaded?", + AUXILIARY_SYSFS_PATH); + return 0; + } + + while ((e = readdir(dir)) != NULL) { + if (e->d_name[0] == '.') + continue; + + if (auxiliary_is_ignored_device(e->d_name)) + continue; + + snprintf(dirname, sizeof(dirname), "%s/%s", + AUXILIARY_SYSFS_PATH, e->d_name); + + /* Ignore if no driver can handle. */ + FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) { + if (drv->match(e->d_name)) + break; + } + if (drv == NULL) + continue; + + if (auxiliary_scan_one(dirname, e->d_name) < 0) + goto error; + } + closedir(dir); + return 0; + +error: + closedir(dir); + return -1; +} diff --git a/drivers/bus/auxiliary/meson.build b/drivers/bus/auxiliary/meson.build new file mode 100644 index 0000000000..357550eff7 --- /dev/null +++ b/drivers/bus/auxiliary/meson.build @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2021 NVIDIA Corporation & Affiliates + +headers = files( + 'rte_bus_auxiliary.h', +) +sources = files( + 'auxiliary_common.c', + 'auxiliary_params.c', +) +if is_linux + sources += files( + 'linux/auxiliary.c', + ) +endif +deps += ['kvargs'] diff --git a/drivers/bus/auxiliary/private.h b/drivers/bus/auxiliary/private.h new file mode 100644 index 0000000000..cb3e849993 --- /dev/null +++ b/drivers/bus/auxiliary/private.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#ifndef AUXILIARY_PRIVATE_H +#define AUXILIARY_PRIVATE_H + +#include +#include + +#include "rte_bus_auxiliary.h" + +extern struct rte_auxiliary_bus auxiliary_bus; +extern int auxiliary_bus_logtype; + +#define AUXILIARY_LOG(level, ...) \ + rte_log(RTE_LOG_ ## level, auxiliary_bus_logtype, \ + RTE_FMT("auxiliary bus: " RTE_FMT_HEAD(__VA_ARGS__,) "\n", \ + RTE_FMT_TAIL(__VA_ARGS__,))) + +/* Auxiliary bus iterators */ +#define FOREACH_DEVICE_ON_AUXILIARY_BUS(p) \ + TAILQ_FOREACH(p, &(auxiliary_bus.device_list), next) + +#define FOREACH_DRIVER_ON_AUXILIARY_BUS(p) \ + TAILQ_FOREACH(p, &(auxiliary_bus.driver_list), next) + +bool auxiliary_dev_exists(const char *name); + +/* + * Scan the content of the auxiliary bus, and the devices in the devices + * list. + */ +int auxiliary_scan(void); + +/* + * Update a device being scanned. + */ +void auxiliary_on_scan(struct rte_auxiliary_device *aux_dev); + +/* + * Validate whether a device with given auxiliary device should be ignored + * or not. + */ +bool auxiliary_is_ignored_device(const char *name); + +/* + * Add an auxiliary device to the auxiliary bus (append to auxiliary device + * list). This function also updates the bus references of the auxiliary + * device and the generic device object embedded within. + */ +void auxiliary_add_device(struct rte_auxiliary_device *aux_dev); + +/* + * Insert an auxiliary device in the auxiliary bus at a particular location + * in the device list. It also updates the auxiliary bus reference of the + * new devices to be inserted. + */ +void auxiliary_insert_device(struct rte_auxiliary_device *exist_aux_dev, + struct rte_auxiliary_device *new_aux_dev); + +/* + * Match the auxiliary driver and device by driver function + */ +bool auxiliary_match(const struct rte_auxiliary_driver *aux_drv, + const struct rte_auxiliary_device *aux_dev); + +/* + * Iterate over devices, matching any device against the provided string + */ +void *auxiliary_dev_iterate(const void *start, const char *str, + const struct rte_dev_iterator *it); + +#endif /* AUXILIARY_PRIVATE_H */ diff --git a/drivers/bus/auxiliary/rte_bus_auxiliary.h b/drivers/bus/auxiliary/rte_bus_auxiliary.h new file mode 100644 index 0000000000..16b147e387 --- /dev/null +++ b/drivers/bus/auxiliary/rte_bus_auxiliary.h @@ -0,0 +1,201 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 NVIDIA Corporation & Affiliates + */ + +#ifndef RTE_BUS_AUXILIARY_H +#define RTE_BUS_AUXILIARY_H + +/** + * @file + * + * Auxiliary Bus Interface. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define RTE_BUS_AUXILIARY_NAME "auxiliary" + +/* Forward declarations */ +struct rte_auxiliary_driver; +struct rte_auxiliary_bus; +struct rte_auxiliary_device; + +/** + * Match function for the driver to decide if device can be handled. + * + * @param name + * Pointer to the auxiliary device name. + * @return + * Whether the driver can handle the auxiliary device. + */ +typedef bool(rte_auxiliary_match_t)(const char *name); + +/** + * Initialization function for the driver called during auxiliary probing. + * + * @param drv + * Pointer to the auxiliary driver. + * @param dev + * Pointer to the auxiliary device. + * @return + * - 0 On success. + * - Negative value and rte_errno is set otherwise. + */ +typedef int(rte_auxiliary_probe_t)(struct rte_auxiliary_driver *drv, + struct rte_auxiliary_device *dev); + +/** + * Uninitialization function for the driver called during hotplugging. + * + * @param dev + * Pointer to the auxiliary device. + * @return + * - 0 On success. + * - Negative value and rte_errno is set otherwise. + */ +typedef int (rte_auxiliary_remove_t)(struct rte_auxiliary_device *dev); + +/** + * Driver-specific DMA mapping. After a successful call the device + * will be able to read/write from/to this segment. + * + * @param dev + * Pointer to the auxiliary device. + * @param addr + * Starting virtual address of memory to be mapped. + * @param iova + * Starting IOVA address of memory to be mapped. + * @param len + * Length of memory segment being mapped. + * @return + * - 0 On success. + * - Negative value and rte_errno is set otherwise. + */ +typedef int (rte_auxiliary_dma_map_t)(struct rte_auxiliary_device *dev, + void *addr, uint64_t iova, size_t len); + +/** + * Driver-specific DMA un-mapping. After a successful call the device + * will not be able to read/write from/to this segment. + * + * @param dev + * Pointer to the auxiliary device. + * @param addr + * Starting virtual address of memory to be unmapped. + * @param iova + * Starting IOVA address of memory to be unmapped. + * @param len + * Length of memory segment being unmapped. + * @return + * - 0 On success. + * - Negative value and rte_errno is set otherwise. + */ +typedef int (rte_auxiliary_dma_unmap_t)(struct rte_auxiliary_device *dev, + void *addr, uint64_t iova, size_t len); + +/** + * A structure describing an auxiliary device. + */ +struct rte_auxiliary_device { + TAILQ_ENTRY(rte_auxiliary_device) next; /**< Next probed device. */ + struct rte_device device; /**< Inherit core device */ + char name[RTE_DEV_NAME_MAX_LEN + 1]; /**< ASCII device name */ + struct rte_intr_handle intr_handle; /**< Interrupt handle */ + struct rte_auxiliary_driver *driver; /**< Device driver */ +}; + +/** List of auxiliary devices */ +TAILQ_HEAD(rte_auxiliary_device_list, rte_auxiliary_device); +/** List of auxiliary drivers */ +TAILQ_HEAD(rte_auxiliary_driver_list, rte_auxiliary_driver); + +/** + * Structure describing the auxiliary bus + */ +struct rte_auxiliary_bus { + struct rte_bus bus; /**< Inherit the generic class */ + struct rte_auxiliary_device_list device_list; /**< List of devices */ + struct rte_auxiliary_driver_list driver_list; /**< List of drivers */ +}; + +/** + * A structure describing an auxiliary driver. + */ +struct rte_auxiliary_driver { + TAILQ_ENTRY(rte_auxiliary_driver) next; /**< Next in list. */ + struct rte_driver driver; /**< Inherit core driver. */ + struct rte_auxiliary_bus *bus; /**< Auxiliary bus reference. */ + rte_auxiliary_match_t *match; /**< Device match function. */ + rte_auxiliary_probe_t *probe; /**< Device probe function. */ + rte_auxiliary_remove_t *remove; /**< Device remove function. */ + rte_auxiliary_dma_map_t *dma_map; /**< Device DMA map function. */ + rte_auxiliary_dma_unmap_t *dma_unmap; /**< Device DMA unmap function. */ + uint32_t drv_flags; /**< Flags RTE_AUXILIARY_DRV_*. */ +}; + +/** + * @internal + * Helper macro for drivers that need to convert to struct rte_auxiliary_device. + */ +#define RTE_DEV_TO_AUXILIARY(ptr) \ + container_of(ptr, struct rte_auxiliary_device, device) + +#define RTE_DEV_TO_AUXILIARY_CONST(ptr) \ + container_of(ptr, const struct rte_auxiliary_device, device) + +#define RTE_ETH_DEV_TO_AUXILIARY(eth_dev) \ + RTE_DEV_TO_AUXILIARY((eth_dev)->device) + +/** Device driver needs IOVA as VA and cannot work with IOVA as PA */ +#define RTE_AUXILIARY_DRV_NEED_IOVA_AS_VA 0x002 + +/** + * Register an auxiliary driver. + * + * @param driver + * A pointer to a rte_auxiliary_driver structure describing the driver + * to be registered. + */ +__rte_experimental +void rte_auxiliary_register(struct rte_auxiliary_driver *driver); + +/** Helper for auxiliary device registration from driver instance */ +#define RTE_PMD_REGISTER_AUXILIARY(nm, auxiliary_drv) \ + RTE_INIT(auxiliaryinitfn_ ##nm) \ + { \ + (auxiliary_drv).driver.name = RTE_STR(nm); \ + rte_auxiliary_register(&(auxiliary_drv)); \ + } \ + RTE_PMD_EXPORT_NAME(nm, __COUNTER__) + +/** + * Unregister an auxiliary driver. + * + * @param driver + * A pointer to a rte_auxiliary_driver structure describing the driver + * to be unregistered. + */ +__rte_experimental +void rte_auxiliary_unregister(struct rte_auxiliary_driver *driver); + +#ifdef __cplusplus +} +#endif + +#endif /* RTE_BUS_AUXILIARY_H */ diff --git a/drivers/bus/auxiliary/version.map b/drivers/bus/auxiliary/version.map new file mode 100644 index 0000000000..a52260657c --- /dev/null +++ b/drivers/bus/auxiliary/version.map @@ -0,0 +1,7 @@ +EXPERIMENTAL { + global: + + # added in 21.08 + rte_auxiliary_register; + rte_auxiliary_unregister; +}; diff --git a/drivers/bus/meson.build b/drivers/bus/meson.build index 410058de3a..45eab5233d 100644 --- a/drivers/bus/meson.build +++ b/drivers/bus/meson.build @@ -2,6 +2,7 @@ # Copyright(c) 2017 Intel Corporation drivers = [ + 'auxiliary', 'dpaa', 'fslmc', 'ifpga',