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 647FFA0C52; Wed, 21 Jul 2021 16:39:54 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0CA474111A; Wed, 21 Jul 2021 16:39:35 +0200 (CEST) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2059.outbound.protection.outlook.com [40.107.95.59]) by mails.dpdk.org (Postfix) with ESMTP id 6575E410DA for ; Wed, 21 Jul 2021 16:39:33 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kSVmWNbiHcjOANiheD7ZC4RhgDr5p+GQQ2OT2SUjm1nYQAbtOY/U23wO+5zLOI3lCOpGZ7QKxhjfdHuk8G0404FWG+gybr1a6A9uAz5U36huD+Gy/eqYZLlhie4nCz1ikm5Rrhk9QSCoa4IimOWsk/T1Y8igvu9BEJP4CIXb54ANxq5H8xV0QXmtacfrG4IBKyGr6OZ92S61RbBpLxmB9pH6ieTbpQp/vaUZk0xAGIf+QuCG6IwSGYGr8iOypDnRXvKO/Sog3KhrZuUv8rL7C0I+WhGxSDdDVITOAPDeYK7xB8jBE6s5aczbs6GAcKkFpgWt+m/5WUS6mXfMDqvLxg== 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=89xJK82I5/X4RoVJwR6cwQNxjWBCwc+cFd+vzdRWyzg=; b=Uz6nRIK1CFZpotXjN4U9lF1Kd72yCHoCQ5p3vsrdfWKhLDspnNJy7PrzzbNtwO885bSZa9bsGRCHhkFptvtwiCeoxiTqaUo4FG9qR6Ii8igVN0ovCGjSAdZFqNqj7r4axi5k3vLrg3XzJCQuk4Q3VCM2fExR3hSu410vNJdY0cnf/n4lkOKMjHHeWz6xhVW7GxgnnjYWbC49m1A9VyzYIGqkn4mATfGYJuxi8lsCsfB0N9wSx1aADO8O3HGt6pIFMoEi4bii5mmSxkucla5wgkATdll3UDgPSlz/tbh/nfA/nEIjQ57qsF/M14QLyZVqSULyyaVjnph4SAz9G1wPSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine 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=89xJK82I5/X4RoVJwR6cwQNxjWBCwc+cFd+vzdRWyzg=; b=O6JaIXaY5apP8xmwhjV3STC0iIRunRWyYJTI2P52chzLTttWxOZJMOMpRsqqPglaBLnQeADngcRKp9oXrIhP+vwUwskDh/BhcqPHPIQp5qePTZ/zN7RJD33cGZefL4N7KddkVvAA6W8fBOALhDfeV9z7zZmF+AjxGErdgtL2CCudPHkuru5tUyUOnBqjf3uDLj/AnDiETngUCXnAXkWqz2n+Y6wIdX4yfvLJ0NoQu9QJMeMrp1af1+toRg1UQTKEKMUoMdEi1oQMSWiSa+tA4QL3hpQiTYnTjOBOElAWWSET+wZDMeziGy269Kdp4eBCp5DhnHcKpyH9YwdRTJCCzA== Received: from BN9PR03CA0228.namprd03.prod.outlook.com (2603:10b6:408:f8::23) by DM5PR12MB1388.namprd12.prod.outlook.com (2603:10b6:3:78::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.26; Wed, 21 Jul 2021 14:39:31 +0000 Received: from BN8NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f8:cafe::45) by BN9PR03CA0228.outlook.office365.com (2603:10b6:408:f8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Wed, 21 Jul 2021 14:39:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; 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 BN8NAM11FT060.mail.protection.outlook.com (10.13.177.211) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4352.24 via Frontend Transport; Wed, 21 Jul 2021 14:39:31 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Jul 2021 14:39:29 +0000 From: Xueming Li To: Viacheslav Ovsiienko CC: Thomas Monjalon , , , Matan Azrad Date: Wed, 21 Jul 2021 22:37:39 +0800 Message-ID: <20210721143743.24626-13-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210721143743.24626-1-xuemingl@nvidia.com> References: <20210616040935.311733-1-xuemingl@nvidia.com> <20210721143743.24626-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3ca8113-94e8-427f-6ef5-08d94c555a2f X-MS-TrafficTypeDiagnostic: DM5PR12MB1388: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1850; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D1eksvmjwNPEG1mk/6C5fdKNcmQdtBLnUhP8gw6cfYmpn+ugksWYVXIkyGWUcDcCyMA+i8aktHBSED2eJKDmqQIGS/RsDZenibe2XPuxKIwQQZEnskZBuokaIII4XDxlqtXeAQ1PJewhFD4LgmFIln9MgiJIAz/WhwTcjW03/brhr6XO25puzsuibGpMlPTSin5N+3s7bVxf9KRTo+YFkBmKDbniENwbxWg5RjY7PMKAW+lRzPpqQFTBsYvVrP8YK141YSaBHv2qBc7UzE0eBPSKCeO70nSqYLUOSO0BzXkhJ/D+1UUjzRPlbwPEvYDqN2FBCLURkqAhFXeo0jXrTZXizRlsOkDbTMf6RmkyOeKDFEMfErV9a/RqeUbPJevpGTIUY5gil0Dwi4kO3tQGoR9Ls792Kw6VHP5wjBjRhwiak40+28jdv8cIa0IEXXEyOIxLoxwPlwBb1qCWAWUvZiB4jkwujnEgmWDaciYfwacss5b8ICbJJICrxTleOkEC+IQOLuWn41uf7yB0NrroJ7GeCxDnmZ240mSty25Q3DWKW55PedmeprFKWY3jGbjEOd61BcR8En/FTsMxxn7qfdawjnpBeG75F3J2aJyei3vbUq/GMOHfbjdwy6t5lscCKHjKaFLyDZFbBukOfARdvt2Weg1/0s+WwzjQ0YFr6vVMbmVZSqY6sv29JrJekr6qqWM86R74dkFZ+xX3ZWGViQ== 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)(136003)(346002)(376002)(396003)(39860400002)(36840700001)(46966006)(26005)(70586007)(316002)(6286002)(70206006)(478600001)(7636003)(54906003)(356005)(36906005)(16526019)(55016002)(186003)(1076003)(107886003)(7696005)(6862004)(8676002)(83380400001)(86362001)(37006003)(6666004)(426003)(2906002)(82310400003)(36860700001)(82740400003)(4326008)(336012)(36756003)(47076005)(2616005)(8936002)(6636002)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2021 14:39:31.6386 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3ca8113-94e8-427f-6ef5-08d94c555a2f 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: BN8NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1388 Subject: [dpdk-dev] [PATCH v4 12/16] vdpa/mlx5: remove PCI specifics 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" From: Thomas Monjalon Removes PCI specific driver, replaces with common class driver. Signed-off-by: Thomas Monjalon Acked-by: Viacheslav Ovsiienko --- drivers/vdpa/mlx5/mlx5_vdpa.c | 119 ++++++++++------------------------ drivers/vdpa/mlx5/mlx5_vdpa.h | 1 - 2 files changed, 34 insertions(+), 86 deletions(-) diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 5ab7c525c2..9c9a552ba0 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -11,12 +11,11 @@ #include #include #include -#include #include +#include #include #include -#include #include #include #include @@ -552,34 +551,13 @@ mlx5_vdpa_sys_roce_disable(const char *addr) } static int -mlx5_vdpa_roce_disable(struct rte_pci_addr *addr, struct ibv_device **ibv) +mlx5_vdpa_roce_disable(struct rte_device *dev) { - char addr_name[64] = {0}; - - rte_pci_device_name(addr, addr_name, sizeof(addr_name)); /* Firstly try to disable ROCE by Netlink and fallback to sysfs. */ - if (mlx5_vdpa_nl_roce_disable(addr_name) == 0 || - mlx5_vdpa_sys_roce_disable(addr_name) == 0) { - /* - * Succeed to disable ROCE, wait for the IB device to appear - * again after reload. - */ - int r; - struct ibv_device *ibv_new; - - for (r = MLX5_VDPA_MAX_RETRIES; r; r--) { - ibv_new = mlx5_os_get_ibv_device(addr); - if (ibv_new) { - *ibv = ibv_new; - return 0; - } - usleep(MLX5_VDPA_USEC); - } - DRV_LOG(ERR, "Cannot much device %s after ROCE disable, " - "retries exceed %d", addr_name, MLX5_VDPA_MAX_RETRIES); - rte_errno = EAGAIN; - } - return -rte_errno; + if (mlx5_vdpa_nl_roce_disable(dev->name) != 0 && + mlx5_vdpa_sys_roce_disable(dev->name) != 0) + return -rte_errno; + return 0; } static int @@ -647,44 +625,33 @@ mlx5_vdpa_config_get(struct rte_devargs *devargs, struct mlx5_vdpa_priv *priv) DRV_LOG(DEBUG, "no traffic max is %u.", priv->no_traffic_max); } -/** - * DPDK callback to register a mlx5 PCI device. - * - * This function spawns vdpa device out of a given PCI device. - * - * @param[in] pci_drv - * PCI driver structure (mlx5_vpda_driver). - * @param[in] pci_dev - * PCI device information. - * - * @return - * 0 on success, 1 to skip this driver, a negative errno value otherwise - * and rte_errno is set. - */ static int -mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, - struct rte_pci_device *pci_dev __rte_unused) +mlx5_vdpa_dev_probe(struct rte_device *dev) { struct ibv_device *ibv; struct mlx5_vdpa_priv *priv = NULL; struct ibv_context *ctx = NULL; struct mlx5_hca_attr attr; + int retry; int ret; - ibv = mlx5_os_get_ibv_device(&pci_dev->addr); - if (!ibv) { - DRV_LOG(ERR, "No matching IB device for PCI slot " - PCI_PRI_FMT ".", pci_dev->addr.domain, - pci_dev->addr.bus, pci_dev->addr.devid, - pci_dev->addr.function); + if (mlx5_vdpa_roce_disable(dev) != 0) { + DRV_LOG(WARNING, "Failed to disable ROCE for \"%s\".", + dev->name); return -rte_errno; - } else { - DRV_LOG(INFO, "PCI information matches for device \"%s\".", - ibv->name); } - if (mlx5_vdpa_roce_disable(&pci_dev->addr, &ibv) != 0) { - DRV_LOG(WARNING, "Failed to disable ROCE for \"%s\".", - ibv->name); + /* Wait for the IB device to appear again after reload. */ + for (retry = MLX5_VDPA_MAX_RETRIES; retry > 0; --retry) { + ibv = mlx5_os_get_ibv_dev(dev); + if (ibv != NULL) + break; + usleep(MLX5_VDPA_USEC); + } + if (ibv == NULL) { + DRV_LOG(ERR, "Cannot get IB device after disabling RoCE for " + "\"%s\", retries exceed %d.", + dev->name, MLX5_VDPA_MAX_RETRIES); + rte_errno = EAGAIN; return -rte_errno; } ctx = mlx5_glue->dv_open_device(ibv); @@ -722,20 +689,18 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, if (attr.num_lag_ports == 0) priv->num_lag_ports = 1; priv->ctx = ctx; - priv->pci_dev = pci_dev; priv->var = mlx5_glue->dv_alloc_var(ctx, 0); if (!priv->var) { DRV_LOG(ERR, "Failed to allocate VAR %u.", errno); goto error; } - priv->vdev = rte_vdpa_register_device(&pci_dev->device, - &mlx5_vdpa_ops); + priv->vdev = rte_vdpa_register_device(dev, &mlx5_vdpa_ops); if (priv->vdev == NULL) { DRV_LOG(ERR, "Failed to register vDPA device."); rte_errno = rte_errno ? rte_errno : EINVAL; goto error; } - mlx5_vdpa_config_get(pci_dev->device.devargs, priv); + mlx5_vdpa_config_get(dev->devargs, priv); SLIST_INIT(&priv->mr_list); pthread_mutex_init(&priv->vq_config_lock, NULL); pthread_mutex_lock(&priv_list_lock); @@ -754,26 +719,15 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, return -rte_errno; } -/** - * DPDK callback to remove a PCI device. - * - * This function removes all vDPA devices belong to a given PCI device. - * - * @param[in] pci_dev - * Pointer to the PCI device. - * - * @return - * 0 on success, the function cannot fail. - */ static int -mlx5_vdpa_pci_remove(struct rte_pci_device *pci_dev) +mlx5_vdpa_dev_remove(struct rte_device *dev) { struct mlx5_vdpa_priv *priv = NULL; int found = 0; pthread_mutex_lock(&priv_list_lock); TAILQ_FOREACH(priv, &priv_list, next) { - if (!rte_pci_addr_cmp(&priv->pci_dev->addr, &pci_dev->addr)) { + if (priv->vdev->device == dev) { found = 1; break; } @@ -831,17 +785,12 @@ static const struct rte_pci_id mlx5_vdpa_pci_id_map[] = { } }; -static struct mlx5_pci_driver mlx5_vdpa_driver = { - .driver_class = MLX5_CLASS_VDPA, - .pci_driver = { - .driver = { - .name = RTE_STR(MLX5_VDPA_DRIVER_NAME), - }, - .id_table = mlx5_vdpa_pci_id_map, - .probe = mlx5_vdpa_pci_probe, - .remove = mlx5_vdpa_pci_remove, - .drv_flags = 0, - }, +static struct mlx5_class_driver mlx5_vdpa_driver = { + .drv_class = MLX5_CLASS_VDPA, + .name = RTE_STR(MLX5_VDPA_DRIVER_NAME), + .id_table = mlx5_vdpa_pci_id_map, + .probe = mlx5_vdpa_dev_probe, + .remove = mlx5_vdpa_dev_remove, }; RTE_LOG_REGISTER_DEFAULT(mlx5_vdpa_logtype, NOTICE) @@ -853,7 +802,7 @@ RTE_INIT(rte_mlx5_vdpa_init) { mlx5_common_init(); if (mlx5_glue) - mlx5_pci_driver_register(&mlx5_vdpa_driver); + mlx5_class_driver_register(&mlx5_vdpa_driver); } RTE_PMD_EXPORT_NAME(MLX5_VDPA_DRIVER_NAME, __COUNTER__); diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.h b/drivers/vdpa/mlx5/mlx5_vdpa.h index 722c72b65e..2a04e36607 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.h +++ b/drivers/vdpa/mlx5/mlx5_vdpa.h @@ -133,7 +133,6 @@ struct mlx5_vdpa_priv { struct rte_vdpa_device *vdev; /* vDPA device. */ int vid; /* vhost device id. */ struct ibv_context *ctx; /* Device context. */ - struct rte_pci_device *pci_dev; struct mlx5_hca_vdpa_attr caps; uint32_t pdn; /* Protection Domain number. */ struct ibv_pd *pd; -- 2.25.1