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 13A28A0350; Tue, 22 Feb 2022 09:53:24 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 167F041186; Tue, 22 Feb 2022 09:52:40 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2041.outbound.protection.outlook.com [40.107.243.41]) by mails.dpdk.org (Postfix) with ESMTP id A173C41150 for ; Tue, 22 Feb 2022 09:52:38 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CreKWx5OY7FGHfNe5VEI5xrO+P47ssLCqO5iU7UbP4rpTt5DpP0DyP7ORxQDb74anVvalqDLiEA5t5UpN4/HcF8q/Idj+oWLUa0eroTbUqO5lTkuKgGnyCfPJHfaEsMetx/rCbpvcUABKC7CuZuDDeJjypt3dvS9uJLEntaq3Y4cM2Vjjhiq9o7e7hVm6ZkRHg0Wm/+8yVhsj5ijzCjrh5XJMNsWTkUizEShAozXJff/dhdOPEbt/fmzZ5U59yrZVsX3NosJOBi/wjAY63e9OJIXMGKhO/O2s61e8doU4cjBkQAXejIfhO8rX/OMwlfqVyvG2DpZIy9bxfnEFy4ong== 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=7cHHe0MgX3BCliW4usut/JJw89U034czWqj2/4z0Wlo=; b=CsqsFJBIpG/XqREuwYEFWr9az/xeND7E0UEvKpI3zGP4N/1aDlw8TrEut9Oww/ZDzK5wOSYozavAImx981Y01qbYEHCq3OEVDPjkNVTFKtcDXSvNR3xgWkCx2XeeIVhWFBEnHzU+NnPUFJpoWukCC3gjSwFmkP0XR3mbr40omJsZCu3JkK6AiZSS/FJ0xWEgxMCM60erW+xZelb/eIEdmFdV8Rz0/yG5PNC7V2Lvref3xyH1g+tzqt6eE5ExO9yjHUx8S7RjITufj/tZOSMCf3++Kdyw55xlRznWh9ofWHo92PzdUhvDIdxKM7BJbsTd5Nqq5ljtMOdcKTbA9F+O9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) 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 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=7cHHe0MgX3BCliW4usut/JJw89U034czWqj2/4z0Wlo=; b=WLNnECS7DLAdaxCMai9FK40frinKshozmamQytpQ1od4Y6mw3Ar+Yd3pavAwIGcXxCp+4BGSYYYK4aCCFiSxlal+DNCRDHWD1q8i3AQ9GKRJCWNHga0zi9I8MW6V2L/Pvu667/RKmh4hhmt9/c6RJ52Id8SPfB2hjLyAxrrI3JzZ0n/hGFaCQA1gxffqyAtssQWUM03o7VSJdHb0ax5L1wgwWZivRpy9IN7Ic5PdD5HqqEQUWukRo0bV6A8u8H1hflyLrvtxyEW0UnWfAubkmLxXw1zEmhE2E8GU2Hd1Lsi0Ty50dIkHaMSdxN9wN58NiuK70zRJe2Be1QE0QIm1Eg== Received: from MWHPR10CA0069.namprd10.prod.outlook.com (2603:10b6:300:2c::31) by CH0PR12MB5298.namprd12.prod.outlook.com (2603:10b6:610:d5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.15; Tue, 22 Feb 2022 08:52:37 +0000 Received: from CO1NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:300:2c:cafe::d5) by MWHPR10CA0069.outlook.office365.com (2603:10b6:300:2c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16 via Frontend Transport; Tue, 22 Feb 2022 08:52:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by CO1NAM11FT068.mail.protection.outlook.com (10.13.175.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4995.15 via Frontend Transport; Tue, 22 Feb 2022 08:52:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 22 Feb 2022 08:52:35 +0000 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.9; Tue, 22 Feb 2022 00:52:31 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v2 09/14] net/mlx5: add flow flush function Date: Tue, 22 Feb 2022 10:51:51 +0200 Message-ID: <20220222085156.27137-10-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220222085156.27137-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220222085156.27137-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 17962d27-c92c-4a0d-17a9-08d9f5e0acbc X-MS-TrafficTypeDiagnostic: CH0PR12MB5298:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9RvhVa5I2khbU0x5bV0UnuBrapmGWKDPwOUoLJeLsdwl4SZ4h3zNANWpNJ4BsGLYVsgJON/ZZbyM35mdrw1v3lXI4ivAtLeSAqxYK0ziI2t8/YqcZdTalLmvQKkB+Qmnj8wx9Ygwm8m7Klf+arH063FVx1JczP/bGCG6LKqV+HbYfstcV1jZs1kqcGxBPL6OblzHXQQqsrkhAN3094l18Ku+nL8gTPwksJiC0BciFhPbMLq+FnkBFrEUGTjfbrh90N0RK20T7P5tm1Tj+e+e0HbrsDyTo+Sazm3VTuNcPPlGkaVZfz2iH2scms99Q1zvbJQOAaF6rn1aylWlkR8bD7qwbldQtmKFt/fYDMqoauAbXIWGZgdO1LM074scp4OkM10yIVlMET5ZB/Pg0+KrdWBQHirLGADBgvRadLRMfu4RolucuI30arRqlsj2z1Q0AbZldCQeOjYUWeqHnU/x7PIUEczzfSOv843e1ogBo/O8P7fJA9CFRhPR1KpAXxsKA9985B4hqv7rtpT6rbA38UmpU2g0IBUAsV8F7PsFjyftslmFaEkTGmEfx/N99OXuzaUmOGmKpgUThbrxdGYfJuWWRh0K6Do80w39iff+Rj0GmH7D+rQP7P+jtOFsf3KWTxRsyggyBSYAM5W1y33vbgMthLMHHmxZ7gYGMP1h3CKoA7hqpaDWepqwEwj/ahGWfRYFn3/+xxlBE7COLaifKg== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(16526019)(6286002)(2616005)(1076003)(36756003)(426003)(2906002)(336012)(186003)(26005)(83380400001)(55016003)(8936002)(7696005)(6666004)(47076005)(508600001)(82310400004)(36860700001)(40460700003)(86362001)(6636002)(316002)(4326008)(70206006)(5660300002)(70586007)(110136005)(54906003)(356005)(81166007)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Feb 2022 08:52:36.8029 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 17962d27-c92c-4a0d-17a9-08d9f5e0acbc X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5298 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 In case port is being stopped, all created flows should be flushed. This commit adds the flow flush helper function. Signed-off-by: Suanming Mou Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5_flow.c | 8 ++ drivers/net/mlx5/mlx5_flow_hw.c | 129 ++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index c6224e4f06..ff1c9f0067 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -7013,6 +7013,14 @@ mlx5_flow_list_flush(struct rte_eth_dev *dev, enum mlx5_flow_type type, uint32_t num_flushed = 0, fidx = 1; struct rte_flow *flow; +#ifdef HAVE_IBV_FLOW_DV_SUPPORT + if (priv->sh->config.dv_flow_en == 2 && + type == MLX5_FLOW_TYPE_GEN) { + flow_hw_q_flow_flush(dev, NULL); + return; + } +#endif + MLX5_IPOOL_FOREACH(priv->flows[type], fidx, flow) { flow_list_destroy(dev, type, fidx); num_flushed++; diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index accc3a96d9..ed14eacce2 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -13,6 +13,12 @@ /* The maximum actions support in the flow. */ #define MLX5_HW_MAX_ACTS 16 +/* Default push burst threshold. */ +#define BURST_THR 32u + +/* Default queue to flush the flows. */ +#define MLX5_DEFAULT_FLUSH_QUEUE 0 + const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops; /* DR action flags with different table. */ @@ -391,6 +397,129 @@ flow_hw_push(struct rte_eth_dev *dev, return 0; } +/** + * Drain the enqueued flows' completion. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] queue + * The queue to pull the flow. + * @param[in] pending_rules + * The pending flow number. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, negative value otherwise and rte_errno is set. + */ +static int +__flow_hw_pull_comp(struct rte_eth_dev *dev, + uint32_t queue, + uint32_t pending_rules, + struct rte_flow_error *error) +{ + struct rte_flow_op_result comp[BURST_THR]; + int ret, i, empty_loop = 0; + + flow_hw_push(dev, queue, error); + while (pending_rules) { + ret = flow_hw_pull(dev, queue, comp, BURST_THR, error); + if (ret < 0) + return -1; + if (!ret) { + rte_delay_us_sleep(20000); + if (++empty_loop > 5) { + DRV_LOG(WARNING, "No available dequeue, quit."); + break; + } + continue; + } + for (i = 0; i < ret; i++) { + if (comp[i].status == RTE_FLOW_OP_ERROR) + DRV_LOG(WARNING, "Flow flush get error CQE."); + } + if ((uint32_t)ret > pending_rules) { + DRV_LOG(WARNING, "Flow flush get extra CQE."); + return rte_flow_error_set(error, ERANGE, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "get extra CQE"); + } + pending_rules -= ret; + empty_loop = 0; + } + return 0; +} + +/** + * Flush created flows. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, negative value otherwise and rte_errno is set. + */ +int +flow_hw_q_flow_flush(struct rte_eth_dev *dev, + struct rte_flow_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_hw_q *hw_q; + struct rte_flow_template_table *tbl; + struct rte_flow_hw *flow; + struct rte_flow_op_attr attr = { + .postpone = 0, + }; + uint32_t pending_rules = 0; + uint32_t queue; + uint32_t fidx; + + /* + * Ensure to push and dequeue all the enqueued flow + * creation/destruction jobs in case user forgot to + * dequeue. Or the enqueued created flows will be + * leaked. The forgotten dequeues would also cause + * flow flush get extra CQEs as expected and pending_rules + * be minus value. + */ + for (queue = 0; queue < priv->nb_queue; queue++) { + hw_q = &priv->hw_q[queue]; + if (__flow_hw_pull_comp(dev, queue, hw_q->size - hw_q->job_idx, + error)) + return -1; + } + /* Flush flow per-table from MLX5_DEFAULT_FLUSH_QUEUE. */ + hw_q = &priv->hw_q[MLX5_DEFAULT_FLUSH_QUEUE]; + LIST_FOREACH(tbl, &priv->flow_hw_tbl, next) { + MLX5_IPOOL_FOREACH(tbl->flow, fidx, flow) { + if (flow_hw_async_flow_destroy(dev, + MLX5_DEFAULT_FLUSH_QUEUE, + &attr, + (struct rte_flow *)flow, + NULL, + error)) + return -1; + pending_rules++; + /* Drain completion with queue size. */ + if (pending_rules >= hw_q->size) { + if (__flow_hw_pull_comp(dev, + MLX5_DEFAULT_FLUSH_QUEUE, + pending_rules, error)) + return -1; + pending_rules = 0; + } + } + } + /* Drain left completion. */ + if (pending_rules && + __flow_hw_pull_comp(dev, MLX5_DEFAULT_FLUSH_QUEUE, pending_rules, + error)) + return -1; + return 0; +} + /** * Create flow table. * -- 2.25.1