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 22D57A0553; Thu, 20 Oct 2022 18:00:43 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9FDAA42BBF; Thu, 20 Oct 2022 17:59:36 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2080.outbound.protection.outlook.com [40.107.237.80]) by mails.dpdk.org (Postfix) with ESMTP id 2A06E42B80 for ; Thu, 20 Oct 2022 17:59:35 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NuXPS1gIgorjOIxfYWEESJPeB9CQRbd6XSI553KCG00B77evQ3LS8XlA3nmSbYAJG0y690poByjbEjos33TkUDgoZzVz10RKspn7k/T1mGigI6HXtpfMtTx65VuYwJ4Mz8m1Uppi6cgoMlBRBwBDpUjMtGlrztC9KKIlVPLQvdAkI+U3M230VJgrbNECusZANfAF3wolHxFHs8OQm3dFi0hsaacJvTc/uCmtR1PTdEsZmS/20OADPofEWgy0slB3aOempBD5InxTBwKi6wd28xVUJAewU/nLZ1h0Tf3zwQw5nm5hVcL6OjA1jN7fifXWaOaUc6pbu65tIp8Pckwjuw== 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=AoBuaUIgo1SdzDswOaVhXgv3WuBrLgBgX9ATf2Y+HliE8RFppq6EqdvVvq+K8sqYdPN7dp0X6Rn9pn7mB4aX5rR9InEqnBdJ6qJMtJ3a+hFkF0VoYwFIQ6wT1RwW8Q+y7Uki9xCmbu9O6CXDvU0qdyrlKTl1T+jrkG6Se9Bxmns+QkhZRpjDVP/cX79MfKoNyV+Fx1UyT47cgYe9OYUKgh0YuR/uoVVOy4yWBTIHMozyFdbYKOqaIFJY7y1huAV9vmRo6zIYsDw80HO0dLpMI56HOJxwHypA7u7DfqT0EAInjJ+NpNQHvwyb7oSzeJRFtXC2GVQ6cHGRx55ocBNCvg== 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=Nen1Tr7wVdpIR0y0x2zPL0h+T5gYqlyf/cG1OZhLtYhfY+eZ9MrJI8YVR1jBBuchY7D0TGSz+pv73kdDa6TqZ/L7MeLnVIrPS9qnbURXY+ties0btpheIgQcNZVgsN0AphAmYmcXYJsFiyHZTXE5ksuJVWQ+a/r7v1snSEpeYes6qU0Q6P1mkU7Ru37XsSxeg4VfPmbZoR+weOULEn49y31d+yUQYT/AR+4xLUcnE9X8oNNrYPuztJpceyflNHdFX9YhFAXvagJ4B7vxTfR5smVtNcsa6/W+w1fRI/4A1WRnvy/sqsM5EX+66n8lODGJmEwy63R5TD0DHt4kfADsCw== Received: from BN9PR03CA0073.namprd03.prod.outlook.com (2603:10b6:408:fc::18) by DS7PR12MB5935.namprd12.prod.outlook.com (2603:10b6:8:7e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.32; Thu, 20 Oct 2022 15:59:33 +0000 Received: from BN8NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fc:cafe::88) by BN9PR03CA0073.outlook.office365.com (2603:10b6:408:fc::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.34 via Frontend Transport; Thu, 20 Oct 2022 15:59:33 +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 BN8NAM11FT028.mail.protection.outlook.com (10.13.176.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.16 via Frontend Transport; Thu, 20 Oct 2022 15:59:32 +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; Thu, 20 Oct 2022 08:59:20 -0700 Received: from nvidia.com (10.126.230.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; Thu, 20 Oct 2022 08:59:17 -0700 From: Alex Vesker To: , , , , Matan Azrad CC: , , Erez Shitrit Subject: [v6 13/18] net/mlx5/hws: Add HWS table object Date: Thu, 20 Oct 2022 18:57:43 +0300 Message-ID: <20221020155749.16643-14-valex@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20221020155749.16643-1-valex@nvidia.com> References: <20220922190345.394-1-valex@nvidia.com> <20221020155749.16643-1-valex@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.230.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: BN8NAM11FT028:EE_|DS7PR12MB5935:EE_ X-MS-Office365-Filtering-Correlation-Id: 5df2022a-8ca8-4acd-9124-08dab2b4145b 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: lVG9EYJq1S2Xeoo5io0E/t5ClZMP0mMf4Ff3GiCqX0zcsSQEPYvHfqa35dHcY9yGDeDRoxH9z3l1kTtUdNp3CZWCLpPiiQObYGL56C3P+tXavagzHeDHYU4RYEawBDP8r4KWUpCjKcLTgJ1SCANd7iwdSiZrs3AyjjRAKhmfkTmxx3qLPyumKP3bXf/BF/Mz68JGwDQVEEYiVomCN/FvRfpyB4DCltP5azqizREIL8gXNVdK+ak+PTHbazBz2RG/t2viQdDiywiJCD4wQtkhi6arftM+tlahaUeD7c2wvdjFo1/PN5b7TkIKfDhUierqUTPemEYUJBk4TaG/eK11MoN36bYNYXuicBwZQMZiwLcKubVCD8ukWXdlrMAFW28LkT3dGtSplxbTmuzYwthhctGfjSV1EZjAPP1yxT3NPQTqGgBD9iSk26ibaf//esyUwJonLHhBi6STSP8CSButkO9+tc3MVCMtjVjBrjb2cr66hQyTjdS4raEAJQlcPuDhFeBSK3v74fM8sRuaObil6MYRKUfk53O+HKNiSBV+oLSa/1lIF00o1iNY6U/SAVVgbtC/+agrDIDbkFbQU8g9E4Y5NcYH1fVnaZSt0eXlv+/uaIbUndoESuQYJHJssCXGQ4gQu6971DWFsNwARi/3bvrXOnr/DLLHENESkvc3RKRfk2KjAXBwP/IPucXyMXXyL7eH1e9+Y6zhcsoZV+Gx1BOiKPjOIqe6b4FGZ07AQwDQCMykAcljG6XfGczXmN89QUbybDS2UqrF/FJe3dEm6g== 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)(396003)(346002)(39860400002)(376002)(451199015)(46966006)(40470700004)(36840700001)(8676002)(70206006)(5660300002)(7696005)(4326008)(7636003)(107886003)(6666004)(70586007)(26005)(36756003)(6286002)(8936002)(356005)(41300700001)(6636002)(110136005)(54906003)(316002)(336012)(86362001)(40480700001)(47076005)(426003)(55016003)(83380400001)(2906002)(186003)(16526019)(1076003)(40460700003)(82740400003)(36860700001)(2616005)(82310400005)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Oct 2022 15:59:32.9405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5df2022a-8ca8-4acd-9124-08dab2b4145b 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: BN8NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5935 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