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 B0EB9A06CC; Wed, 19 Oct 2022 16:45:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0619A42C0A; Wed, 19 Oct 2022 16:44:11 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2049.outbound.protection.outlook.com [40.107.94.49]) by mails.dpdk.org (Postfix) with ESMTP id 2D51042BD1 for ; Wed, 19 Oct 2022 16:44:10 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HMj5VJWyc8xKIB3unRRMIhM8twsFZj9+8fGnY06rnTtx4YmqZlOd7QCueO7B6Ia+kMBdVq8ckXLOu21MjXxHmHTjKNt+2uM8ngPCWd+k7hkaq4tVaXar/AXiYO60Ztn70Xn4z1sGHuAhi7nF7AC7AA130ZpY/psStX4Oovh4f05ZtKcvmnehd9/sZbZitkRQAtMngKSWZOhq/yeJAwmc6x2tfI4NLwOeNDNfU7xhvXNoWTGkZsDLzj5tspRJ/oVSlviT8ppwsBkPXM5kErSab/RgPrltfeGo8Ty7T3TVH2BQGFbLgruL0rL5cuor5uiiGM0w+QT2QSTEl/WbNopuPg== 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=LB6Dd8jDR97FcOAdD1772udo4FwYMHPq20KW/o5z2Xs=; b=ihxbJfG8LHsGdVTenzPz59M4wWXi8q8UHFgmRkPS3eD+XjzSmip3QKkEinTaE6yq1uJ3dcDF99f7STV2qzQOCDUgEllO7dEVQEY6rXV5SRKlIqzIjfKOXee/zWoae5XILa7Pn4+rTz5JqPkdDHwdfGvnaLHTXRzes2gF7tAhQ1glpHBXHFICW5mrFRdsxN4jQ8UZ/mfQbuMMxkGH0GXf9J4o4BeT8UOoUWpeudLm1dIrghAnpuaw+S8sR4qr5+RQesn8MDSvt1472JdJdlzmr0jsIphdILu1HbNq+4ouInbfuNyuvu9Z1MjZv+9VHXwF6/GHjhO0W8PneviH9W4UKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 216.228.117.161) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject 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=LB6Dd8jDR97FcOAdD1772udo4FwYMHPq20KW/o5z2Xs=; b=Oq7bNhW1v9e4gRWgAMUQbWj55yFAqfdSxkJGS9M8rgzs8wiAkN3MgBjQSufwxZpFKU+AOgSBns/CdCo0CfmPMI0IE6kOI/ARSPPioLmUk8NxxnjEGNALPBVi+WqhXlab+fqY6pc6+UzIy3FNq77gYC5bUOEg8WsbhEuaKzMOZ5gm/hofJxTvLVA9PyVhPLMyXSn/LFJnCnDUmdXM8Wk0ogqLPsPolq6/XH9cpC+zVO565qAOvnCeI4SdazJpEyZsW44FYXWcHI12IpVA2ne8n1NlCycKFTP4zQSz+Za6Ufz+Yg3oQN/qMVJkuKjzG4uYhifct2zKvCBZ8gKyawu2MA== Received: from BN0PR04CA0011.namprd04.prod.outlook.com (2603:10b6:408:ee::16) by CY8PR12MB7492.namprd12.prod.outlook.com (2603:10b6:930:93::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Wed, 19 Oct 2022 14:44:07 +0000 Received: from BN8NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ee:cafe::fa) by BN0PR04CA0011.outlook.office365.com (2603:10b6:408:ee::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.34 via Frontend Transport; Wed, 19 Oct 2022 14:44:06 +0000 X-MS-Exchange-Authentication-Results: spf=none (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=nvidia.com; Received-SPF: None (protection.outlook.com: nvidia.com does not designate permitted sender hosts) Received: from mail.nvidia.com (216.228.117.161) by BN8NAM11FT017.mail.protection.outlook.com (10.13.177.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.16 via Frontend Transport; Wed, 19 Oct 2022 14:44:05 +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.26; Wed, 19 Oct 2022 07:43:53 -0700 Received: from nvidia.com (10.126.231.35) 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.29; Wed, 19 Oct 2022 07:43:50 -0700 From: Alex Vesker To: , , , , Matan Azrad CC: , , Erez Shitrit Subject: [v4 13/18] net/mlx5/hws: Add HWS table object Date: Wed, 19 Oct 2022 17:42:53 +0300 Message-ID: <20221019144258.16282-14-valex@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20221019144258.16282-1-valex@nvidia.com> References: <20220922190345.394-1-valex@nvidia.com> <20221019144258.16282-1-valex@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT017:EE_|CY8PR12MB7492:EE_ X-MS-Office365-Filtering-Correlation-Id: 718c608c-f5c4-4388-7278-08dab1e05f7b X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vbw8+PN82S3ancCCW+GN38yoUlW28/lX8EAW9pYNJ9rqriU7ziLQEpoXXVz3+IsPapQQFeiERdCN/pmnc2622H47o4vAwbfUmQLMUBBVQXs5Ee9I3fLY3JPZ4M0yHa1jjbSllhi0Hzm5tUvJkRkNZJJMrtuaTzXDSBJ09nbWFRiCxCROumVmBE4fpcGYBcBW2gb6nqBWRbQpyYRfRc9h7oKTQeY9gX+jVJdE8aWDxURC7E5Oq31EjPtV6R3ZQrh3VVHcR61qo989xL3v5DOIMzFnqlMRbwZ4iNngjBMMgRQ6rAq4iM7O0sBunJZl/TuEvPASNWOBS084NB7uZY8r9u5xdJc125ZUGNzhKQfho4qIMwAYDZsekrFK6RZRepPsbOQN/RnrjeBBumLSsr82bqHF1z+EVfvbBNl+kylTWgXoxLo5UBIXmPE9WbWD8lCHW0lVfMeq6csd0DjUdQHV68aIk7GGQFmc+GDajaivWUcdiAxa121OdlVUBuU/XRY1yaDm106xORoOKZuvmzKPZBsOKxM+8qaxV4TF9n4v9JJEmbEzqn1LwLb7hLMaeu4XwvY4VWLwpOEHuKOGfV0z8MRZvJyed4gJW3RdXEWSShbmVZDs++XC0ZOBKr1vut7bR22HeEBBhzem8GPI3qUhknAMnAaKmAKAb0H04PTaGHd8BAZkS77Paz+GQfFo+Df7wKnGqDSQPo8jHkfx5X3gaYDUvnx+efwy40HOU9XUo9b2qb7EvwfLJmNIvfhqNZLQoMf5da20/xQyAaKhVhybkA== 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:(13230022)(4636009)(136003)(346002)(39860400002)(376002)(396003)(451199015)(46966006)(40470700004)(36840700001)(70586007)(1076003)(2906002)(478600001)(8676002)(110136005)(107886003)(41300700001)(4326008)(70206006)(186003)(40460700003)(36860700001)(316002)(336012)(82310400005)(86362001)(36756003)(5660300002)(8936002)(6636002)(7696005)(16526019)(83380400001)(6286002)(47076005)(54906003)(26005)(2616005)(82740400003)(356005)(7636003)(40480700001)(426003)(55016003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2022 14:44:05.6719 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 718c608c-f5c4-4388-7278-08dab1e05f7b 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: BN8NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7492 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 HWS table resides under the context object, each context can have multiple tables with different steering types RX/TX/FDB. The table is not only a logical object but it is also represented in the HW, packets can be steered to the table and from there to other tables. Signed-off-by: Erez Shitrit Signed-off-by: Alex Vesker --- drivers/net/mlx5/hws/mlx5dr_table.c | 248 ++++++++++++++++++++++++++++ drivers/net/mlx5/hws/mlx5dr_table.h | 44 +++++ 2 files changed, 292 insertions(+) create mode 100644 drivers/net/mlx5/hws/mlx5dr_table.c create mode 100644 drivers/net/mlx5/hws/mlx5dr_table.h diff --git a/drivers/net/mlx5/hws/mlx5dr_table.c b/drivers/net/mlx5/hws/mlx5dr_table.c new file mode 100644 index 0000000000..d3f77e4780 --- /dev/null +++ b/drivers/net/mlx5/hws/mlx5dr_table.c @@ -0,0 +1,248 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 NVIDIA Corporation & Affiliates + */ + +#include "mlx5dr_internal.h" + +static void mlx5dr_table_init_next_ft_attr(struct mlx5dr_table *tbl, + struct mlx5dr_cmd_ft_create_attr *ft_attr) +{ + ft_attr->type = tbl->fw_ft_type; + if (tbl->type == MLX5DR_TABLE_TYPE_FDB) + ft_attr->level = tbl->ctx->caps->fdb_ft.max_level - 1; + else + ft_attr->level = tbl->ctx->caps->nic_ft.max_level - 1; + ft_attr->rtc_valid = true; +} + +/* Call this under ctx->ctrl_lock */ +static int +mlx5dr_table_up_default_fdb_miss_tbl(struct mlx5dr_table *tbl) +{ + struct mlx5dr_cmd_ft_create_attr ft_attr = {0}; + struct mlx5dr_cmd_forward_tbl *default_miss; + struct mlx5dr_context *ctx = tbl->ctx; + uint8_t tbl_type = tbl->type; + uint32_t vport; + + if (tbl->type != MLX5DR_TABLE_TYPE_FDB) + return 0; + + if (ctx->common_res[tbl_type].default_miss) { + ctx->common_res[tbl_type].default_miss->refcount++; + return 0; + } + + ft_attr.type = tbl->fw_ft_type; + ft_attr.level = tbl->ctx->caps->fdb_ft.max_level; /* The last level */ + ft_attr.rtc_valid = false; + + assert(ctx->caps->eswitch_manager); + vport = ctx->caps->eswitch_manager_vport_number; + + default_miss = mlx5dr_cmd_miss_ft_create(ctx->ibv_ctx, &ft_attr, vport); + if (!default_miss) { + DR_LOG(ERR, "Failed to default miss table type: 0x%x", tbl_type); + return rte_errno; + } + + ctx->common_res[tbl_type].default_miss = default_miss; + ctx->common_res[tbl_type].default_miss->refcount++; + return 0; +} + +/* Called under pthread_spin_lock(&ctx->ctrl_lock) */ +static void mlx5dr_table_down_default_fdb_miss_tbl(struct mlx5dr_table *tbl) +{ + struct mlx5dr_cmd_forward_tbl *default_miss; + struct mlx5dr_context *ctx = tbl->ctx; + uint8_t tbl_type = tbl->type; + + if (tbl->type != MLX5DR_TABLE_TYPE_FDB) + return; + + default_miss = ctx->common_res[tbl_type].default_miss; + if (--default_miss->refcount) + return; + + mlx5dr_cmd_miss_ft_destroy(default_miss); + + simple_free(default_miss); + ctx->common_res[tbl_type].default_miss = NULL; +} + +static int +mlx5dr_table_connect_to_default_miss_tbl(struct mlx5dr_table *tbl, + struct mlx5dr_devx_obj *ft) +{ + struct mlx5dr_cmd_ft_modify_attr ft_attr = {0}; + int ret; + + assert(tbl->type == MLX5DR_TABLE_TYPE_FDB); + + mlx5dr_cmd_set_attr_connect_miss_tbl(tbl->ctx, + tbl->fw_ft_type, + tbl->type, + &ft_attr); + + /* Connect to next */ + ret = mlx5dr_cmd_flow_table_modify(ft, &ft_attr); + if (ret) { + DR_LOG(ERR, "Failed to connect FT to default FDB FT"); + return errno; + } + + return 0; +} + +struct mlx5dr_devx_obj * +mlx5dr_table_create_default_ft(struct mlx5dr_table *tbl) +{ + struct mlx5dr_cmd_ft_create_attr ft_attr = {0}; + struct mlx5dr_devx_obj *ft_obj; + int ret; + + mlx5dr_table_init_next_ft_attr(tbl, &ft_attr); + + ft_obj = mlx5dr_cmd_flow_table_create(tbl->ctx->ibv_ctx, &ft_attr); + if (ft_obj && tbl->type == MLX5DR_TABLE_TYPE_FDB) { + /* Take/create ref over the default miss */ + ret = mlx5dr_table_up_default_fdb_miss_tbl(tbl); + if (ret) { + DR_LOG(ERR, "Failed to get default fdb miss"); + goto free_ft_obj; + } + ret = mlx5dr_table_connect_to_default_miss_tbl(tbl, ft_obj); + if (ret) { + DR_LOG(ERR, "Failed connecting to default miss tbl"); + goto down_miss_tbl; + } + } + + return ft_obj; + +down_miss_tbl: + mlx5dr_table_down_default_fdb_miss_tbl(tbl); +free_ft_obj: + mlx5dr_cmd_destroy_obj(ft_obj); + return NULL; +} + +void mlx5dr_table_destroy_default_ft(struct mlx5dr_table *tbl, + struct mlx5dr_devx_obj *ft_obj) +{ + mlx5dr_table_down_default_fdb_miss_tbl(tbl); + mlx5dr_cmd_destroy_obj(ft_obj); +} + +static int mlx5dr_table_init(struct mlx5dr_table *tbl) +{ + struct mlx5dr_context *ctx = tbl->ctx; + int ret; + + if (mlx5dr_table_is_root(tbl)) + return 0; + + if (!(tbl->ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) { + DR_LOG(ERR, "HWS not supported, cannot create mlx5dr_table"); + rte_errno = EOPNOTSUPP; + return rte_errno; + } + + switch (tbl->type) { + case MLX5DR_TABLE_TYPE_NIC_RX: + tbl->fw_ft_type = FS_FT_NIC_RX; + break; + case MLX5DR_TABLE_TYPE_NIC_TX: + tbl->fw_ft_type = FS_FT_NIC_TX; + break; + case MLX5DR_TABLE_TYPE_FDB: + tbl->fw_ft_type = FS_FT_FDB; + break; + default: + assert(0); + break; + } + + pthread_spin_lock(&ctx->ctrl_lock); + tbl->ft = mlx5dr_table_create_default_ft(tbl); + if (!tbl->ft) { + DR_LOG(ERR, "Failed to create flow table devx object"); + pthread_spin_unlock(&ctx->ctrl_lock); + return rte_errno; + } + + ret = mlx5dr_action_get_default_stc(ctx, tbl->type); + if (ret) + goto tbl_destroy; + pthread_spin_unlock(&ctx->ctrl_lock); + + return 0; + +tbl_destroy: + mlx5dr_table_destroy_default_ft(tbl, tbl->ft); + pthread_spin_unlock(&ctx->ctrl_lock); + return rte_errno; +} + +static void mlx5dr_table_uninit(struct mlx5dr_table *tbl) +{ + if (mlx5dr_table_is_root(tbl)) + return; + pthread_spin_lock(&tbl->ctx->ctrl_lock); + mlx5dr_action_put_default_stc(tbl->ctx, tbl->type); + mlx5dr_table_destroy_default_ft(tbl, tbl->ft); + pthread_spin_unlock(&tbl->ctx->ctrl_lock); +} + +struct mlx5dr_table *mlx5dr_table_create(struct mlx5dr_context *ctx, + struct mlx5dr_table_attr *attr) +{ + struct mlx5dr_table *tbl; + int ret; + + if (attr->type > MLX5DR_TABLE_TYPE_FDB) { + DR_LOG(ERR, "Invalid table type %d", attr->type); + return NULL; + } + + tbl = simple_malloc(sizeof(*tbl)); + if (!tbl) { + rte_errno = ENOMEM; + return NULL; + } + + tbl->ctx = ctx; + tbl->type = attr->type; + tbl->level = attr->level; + LIST_INIT(&tbl->head); + + ret = mlx5dr_table_init(tbl); + if (ret) { + DR_LOG(ERR, "Failed to initialise table"); + goto free_tbl; + } + + pthread_spin_lock(&ctx->ctrl_lock); + LIST_INSERT_HEAD(&ctx->head, tbl, next); + pthread_spin_unlock(&ctx->ctrl_lock); + + return tbl; + +free_tbl: + simple_free(tbl); + return NULL; +} + +int mlx5dr_table_destroy(struct mlx5dr_table *tbl) +{ + struct mlx5dr_context *ctx = tbl->ctx; + + pthread_spin_lock(&ctx->ctrl_lock); + LIST_REMOVE(tbl, next); + pthread_spin_unlock(&ctx->ctrl_lock); + mlx5dr_table_uninit(tbl); + simple_free(tbl); + + return 0; +} diff --git a/drivers/net/mlx5/hws/mlx5dr_table.h b/drivers/net/mlx5/hws/mlx5dr_table.h new file mode 100644 index 0000000000..786dddfaa4 --- /dev/null +++ b/drivers/net/mlx5/hws/mlx5dr_table.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 NVIDIA Corporation & Affiliates + */ + +#ifndef MLX5DR_TABLE_H_ +#define MLX5DR_TABLE_H_ + +#define MLX5DR_ROOT_LEVEL 0 + +struct mlx5dr_table { + struct mlx5dr_context *ctx; + struct mlx5dr_devx_obj *ft; + enum mlx5dr_table_type type; + uint32_t fw_ft_type; + uint32_t level; + LIST_HEAD(matcher_head, mlx5dr_matcher) head; + LIST_ENTRY(mlx5dr_table) next; +}; + +static inline +uint32_t mlx5dr_table_get_res_fw_ft_type(enum mlx5dr_table_type tbl_type, + bool is_mirror) +{ + if (tbl_type == MLX5DR_TABLE_TYPE_NIC_RX) + return FS_FT_NIC_RX; + else if (tbl_type == MLX5DR_TABLE_TYPE_NIC_TX) + return FS_FT_NIC_TX; + else if (tbl_type == MLX5DR_TABLE_TYPE_FDB) + return is_mirror ? FS_FT_FDB_TX : FS_FT_FDB_RX; + + assert(0); + return 0; +} + +static inline bool mlx5dr_table_is_root(struct mlx5dr_table *tbl) +{ + return (tbl->level == MLX5DR_ROOT_LEVEL); +} + +struct mlx5dr_devx_obj *mlx5dr_table_create_default_ft(struct mlx5dr_table *tbl); + +void mlx5dr_table_destroy_default_ft(struct mlx5dr_table *tbl, + struct mlx5dr_devx_obj *ft_obj); +#endif /* MLX5DR_TABLE_H_ */ -- 2.18.1