From patchwork Sun Dec 3 11:25:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Baum X-Patchwork-Id: 134754 X-Patchwork-Delegate: rasland@nvidia.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 AAD2A4365F; Sun, 3 Dec 2023 12:27:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 954AD406FF; Sun, 3 Dec 2023 12:26:31 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) by mails.dpdk.org (Postfix) with ESMTP id B0A74406FF for ; Sun, 3 Dec 2023 12:26:30 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UQ/iWGhHhDeSfXyGY/4AbG9TJqI8NL8F6nagq0qtL6UVKzatj6oyfq2BAP9Kh9smcvzqJbQn+bmCAZNnlrDeGzG65CAxnz8zMUxSr67dSNgyHAq2u1jdWMJaccAS125cuD1/2OEkZvm14aqzNa/J1btzB2EES67cQ12tZrXL4g/qNtJPeAIo/q7jALLL+vZ25XRHg4mQwSR05pKwwrDvfYJ88QhPJPTDFog6dz3QAG6RIl7EmgJqEL5XijMgzoomlemxqcE4fv1GMy9/i8LBko2NYMCdIKUPLGCGapefU7OjF1wd+1TGgiatHDdUVks3LSYef5aKM0ovcNOjeLI5SA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=i7U4O6jAaafQvmSGv9+5GQyMSdIh9qK1cyO/6ndG8jQ=; b=YBwE4G/sQnXRGIY/KQgBYyuMJCt2vkCLlGJc0+U4ETtPrTM1Zth2g3/IIe5d8Srd7qCDBZgTE1ZZiSSe30qkBuXv9tQnlulS85EmD83aUHh26rd34tY9JhUH/tMReGr8nBMPg0KgyiJdEAb4lIE2r1/9z4RoA5Z+0E9yr1rE1wnRLrJJg/vzjE4+2puTTFcD1VpV7Fahxz+nq4DI20SSWHUx8rbUKIjrrwSfjluJkUxoI7IT5QWu/n1Vs7aOOBhxFiGXzP28waJ3VwLE3VHNhqrp+Fcg1zW5yweM0NwCQnHbO+9LQPE0duBYPqiC3hwXmSqsE2e8PrAU9DzWq/j5pA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=i7U4O6jAaafQvmSGv9+5GQyMSdIh9qK1cyO/6ndG8jQ=; b=iWleCqKizAnLmlmqRYzY894iYxs4JsX/b2CoJmOVKckEXXCZkbufSrIt/McPuJWhA2DXc11GDwp4rA9U4aDd8URQB6rAhCuq3CK95dmBCpZbrTYwi0ah5qACRlBKhuFxLtiklRTQsoET/+J4CFcfdgGgtZR5Jo9zANUdxazDZWlrmYMloXzwfyJaSelaCbOf69zI5lHaoshred1eKl3I7IsoeyFHmBXAEed7OPplL12snm+OGEpu/pat5m5mEd2FKZbNXyXVCO6JZ79Q4/Pm30Ub8w4EnIkBOIc74cqfLw2tAE9WiZnfFswpDVInkIcMgjQwvvViBLSFA5Ns/fOZ8A== Received: from DM6PR02CA0112.namprd02.prod.outlook.com (2603:10b6:5:1b4::14) by MW3PR12MB4505.namprd12.prod.outlook.com (2603:10b6:303:5a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.33; Sun, 3 Dec 2023 11:26:27 +0000 Received: from DS1PEPF0001709A.namprd05.prod.outlook.com (2603:10b6:5:1b4:cafe::7a) by DM6PR02CA0112.outlook.office365.com (2603:10b6:5:1b4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.32 via Frontend Transport; Sun, 3 Dec 2023 11:26:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS1PEPF0001709A.mail.protection.outlook.com (10.167.18.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.20 via Frontend Transport; Sun, 3 Dec 2023 11:26:27 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 3 Dec 2023 03:26:18 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 3 Dec 2023 03:26:18 -0800 Received: from nvidia.com (10.127.8.13) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41 via Frontend Transport; Sun, 3 Dec 2023 03:26:16 -0800 From: Michael Baum To: CC: Matan Azrad , Raslan Darawsheh , Viacheslav Ovsiienko , Ori Kam , Suanming Mou Subject: [PATCH v1 12/23] net/mlx5: add physical device handle Date: Sun, 3 Dec 2023 13:25:32 +0200 Message-ID: <20231203112543.844014-13-michaelba@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231203112543.844014-1-michaelba@nvidia.com> References: <20231203112543.844014-1-michaelba@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709A:EE_|MW3PR12MB4505:EE_ X-MS-Office365-Filtering-Correlation-Id: 761e45e2-a11c-403b-5595-08dbf3f2b093 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MC8kHHkSos50Ug/aqRtwsfToD/1Z6IPs2PFvvsNsmtCkdFvij58Al9BrbZ5lZWfQNAhZ+Tl5RTGLRszyI9T/WY6JCv9WiAgl/oRftRXh9xeK8dTuAVUuAgXIEZpCIs+r0PjcOXJ1M746SyqJGM6vJt03Nfnrxn6BP3s3BXnvPP9HAwL9RFx/+UZ6LFsXe/7v3HsV3X2FYkq/QVYQCpvk/qioKbKIVbGDtRBfY/qXxieRQk+uPdolyg7NXfTdNYs4UsSXI8LqsJbfngSGmKgtkOUP3PttNRy5rjRrQZsWl7ihDoKLNcWXQ1fcVSy0VPZj8OJ2Ye+2USYtwQwtMKjoO90Zxmiw5o3ufMIuViVPQMF5O68YKV0GYEvNwU0nkFX+wA2tEkuDeBmvIh1SQtE13FYkQxSvqZwdqUBgF7SSjsow18Xq5NH7DkpxHBXMFcoywARW9udKTC5fhCCdnXdqdTU9WxM1tB1ZyIIIgy2CkVFoEDKGbeyutPGx+ha67EncI+R6pDhkxbnqIGs9z2yis4SPVSYqK4djui4Fb70P/hw1PFbHGnTJ1vQnFVag3gF47R6718J7N2m2X1wWmfmfgW0LNjyHbNM3xX9eSqC0cBcxVXyxvTjvDuZ4QRou1wBjwrhh2NYe5q+a/yruTLLh6h3e+6tt601Q52Z9tSvK5uhOx8Y8uBPOWXvKqBxvJPP4X9iwjtElXj2kul2hSCshEmCzMQRBY3rKOjM60/S++9DYEMQWp93e1lyq1W/MmXRD X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(396003)(39860400002)(346002)(376002)(230922051799003)(186009)(64100799003)(451199024)(82310400011)(1800799012)(36840700001)(46966006)(40470700004)(5660300002)(40460700003)(86362001)(4326008)(8676002)(8936002)(2906002)(41300700001)(36756003)(2616005)(107886003)(40480700001)(1076003)(356005)(82740400003)(426003)(83380400001)(7636003)(26005)(6286002)(336012)(478600001)(7696005)(6666004)(47076005)(36860700001)(55016003)(316002)(54906003)(6916009)(70206006)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2023 11:26:27.1731 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 761e45e2-a11c-403b-5595-08dbf3f2b093 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4505 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 structure describing physical device, and manage physical device global list. Signed-off-by: Michael Baum --- drivers/net/mlx5/mlx5.c | 77 ++++++++++++++++++++++++++++++++++++----- drivers/net/mlx5/mlx5.h | 13 +++++++ 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 3a182de248..f9fc652136 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -190,9 +190,10 @@ struct mlx5_shared_data *mlx5_shared_data; /** Driver-specific log messages type. */ int mlx5_logtype; -static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list = - LIST_HEAD_INITIALIZER(); +static LIST_HEAD(mlx5_dev_ctx_list, mlx5_dev_ctx_shared) dev_ctx_list = LIST_HEAD_INITIALIZER(); +static LIST_HEAD(mlx5_phdev_list, mlx5_physical_device) phdev_list = LIST_HEAD_INITIALIZER(); static pthread_mutex_t mlx5_dev_ctx_list_mutex; + static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = { #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) [MLX5_IPOOL_DECAP_ENCAP] = { @@ -1692,6 +1693,60 @@ mlx5_init_shared_dev_registers(struct mlx5_dev_ctx_shared *sh) mlx5_init_hws_flow_tags_registers(sh); } +static struct mlx5_physical_device * +mlx5_get_physical_device(struct mlx5_common_device *cdev) +{ + struct mlx5_physical_device *phdev; + struct mlx5_hca_attr *attr = &cdev->config.hca_attr; + + /* Search for physical device by system_image_guid. */ + LIST_FOREACH(phdev, &phdev_list, next) { + if (phdev->guid == attr->system_image_guid) { + phdev->refcnt++; + return phdev; + } + } + phdev = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, + sizeof(struct mlx5_physical_device), + RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); + if (!phdev) { + DRV_LOG(ERR, "Physical device allocation failure."); + rte_errno = ENOMEM; + return NULL; + } + phdev->guid = attr->system_image_guid; + phdev->refcnt = 1; + LIST_INSERT_HEAD(&phdev_list, phdev, next); + DRV_LOG(DEBUG, "Physical device is created, guid=%" PRIu64 ".", + phdev->guid); + return phdev; +} + +static void +mlx5_physical_device_destroy(struct mlx5_physical_device *phdev) +{ +#ifdef RTE_LIBRTE_MLX5_DEBUG + /* Check the object presence in the list. */ + struct mlx5_physical_device *lphdev; + + LIST_FOREACH(lphdev, &phdev_list, next) + if (lphdev == phdev) + break; + MLX5_ASSERT(lphdev); + if (lphdev != phdev) { + DRV_LOG(ERR, "Freeing non-existing physical device"); + return; + } +#endif + MLX5_ASSERT(phdev); + MLX5_ASSERT(phdev->refcnt); + if (--phdev->refcnt) + return; + /* Remove physical device from the global device list. */ + LIST_REMOVE(phdev, next); + mlx5_free(phdev); +} + /** * Allocate shared device context. If there is multiport device the * master and representors will share this context, if there is single @@ -1725,7 +1780,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); pthread_mutex_lock(&mlx5_dev_ctx_list_mutex); /* Search for IB context by device name. */ - LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) { + LIST_FOREACH(sh, &dev_ctx_list, next) { if (!strcmp(sh->ibdev_name, spawn->phys_dev_name)) { sh->refcnt++; goto exit; @@ -1765,6 +1820,9 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, sizeof(sh->ibdev_name) - 1); strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->cdev->ctx), sizeof(sh->ibdev_path) - 1); + sh->phdev = mlx5_get_physical_device(sh->cdev); + if (!sh->phdev) + goto error; /* * Setting port_id to max unallowed value means there is no interrupt * subhandler installed for the given port index i. @@ -1798,7 +1856,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, #endif } mlx5_os_dev_shared_handler_install(sh); - if (LIST_EMPTY(&mlx5_dev_ctx_list)) { + if (LIST_EMPTY(&dev_ctx_list)) { err = mlx5_flow_os_init_workspace_once(); if (err) goto error; @@ -1811,7 +1869,7 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, mlx5_flow_aging_init(sh); mlx5_flow_ipool_create(sh); /* Add context to the global device list. */ - LIST_INSERT_HEAD(&mlx5_dev_ctx_list, sh, next); + LIST_INSERT_HEAD(&dev_ctx_list, sh, next); rte_spinlock_init(&sh->geneve_tlv_opt_sl); mlx5_init_shared_dev_registers(sh); /* Init counter pool list header and lock. */ @@ -1833,6 +1891,8 @@ mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, } while (++i <= (uint32_t)sh->bond.n_port); if (sh->td) claim_zero(mlx5_devx_cmd_destroy(sh->td)); + if (sh->phdev) + mlx5_physical_device_destroy(sh->phdev); mlx5_free(sh); rte_errno = err; return NULL; @@ -1919,7 +1979,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) /* Check the object presence in the list. */ struct mlx5_dev_ctx_shared *lctx; - LIST_FOREACH(lctx, &mlx5_dev_ctx_list, next) + LIST_FOREACH(lctx, &dev_ctx_list, next) if (lctx == sh) break; MLX5_ASSERT(lctx); @@ -1945,7 +2005,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) /* Remove context from the global device list. */ LIST_REMOVE(sh, next); /* Release resources on the last device removal. */ - if (LIST_EMPTY(&mlx5_dev_ctx_list)) { + if (LIST_EMPTY(&dev_ctx_list)) { mlx5_os_net_cleanup(); mlx5_flow_os_release_workspace(); } @@ -1985,6 +2045,7 @@ mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh) MLX5_ASSERT(sh->geneve_tlv_option_resource == NULL); pthread_mutex_destroy(&sh->txpp.mutex); mlx5_lwm_unset(sh); + mlx5_physical_device_destroy(sh->phdev); mlx5_free(sh); return; exit: @@ -2929,7 +2990,7 @@ mlx5_probe_again_args_validate(struct mlx5_common_device *cdev, return 0; pthread_mutex_lock(&mlx5_dev_ctx_list_mutex); /* Search for IB context by common device pointer. */ - LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) + LIST_FOREACH(sh, &dev_ctx_list, next) if (sh->cdev == cdev) break; pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex); diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 263ebead7f..6a82c38cf4 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1419,6 +1419,18 @@ struct mlx5_dev_registers { #define HAVE_MLX5_DR_CREATE_ACTION_ASO_EXT #endif +/** + * Physical device structure. + * This device is created once per NIC to manage recourses shared by all ports + * under same physical device. + */ +struct mlx5_physical_device { + LIST_ENTRY(mlx5_physical_device) next; + struct mlx5_dev_ctx_shared *sh; /* Created on sherd context. */ + uint64_t guid; /* System image guid, the uniq ID of physical device. */ + uint32_t refcnt; +}; + /* * Shared Infiniband device context for Master/Representors * which belong to same IB device with multiple IB ports. @@ -1449,6 +1461,7 @@ struct mlx5_dev_ctx_shared { uint32_t max_port; /* Maximal IB device port index. */ struct mlx5_bond_info bond; /* Bonding information. */ struct mlx5_common_device *cdev; /* Backend mlx5 device. */ + struct mlx5_physical_device *phdev; /* Backend physical device. */ uint32_t tdn; /* Transport Domain number. */ char ibdev_name[MLX5_FS_NAME_MAX]; /* SYSFS dev name. */ char ibdev_path[MLX5_FS_PATH_MAX]; /* SYSFS dev path for secondary */