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 91C37A0353; Thu, 24 Feb 2022 04:11:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DC74041181; Thu, 24 Feb 2022 04:11:10 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2072.outbound.protection.outlook.com [40.107.236.72]) by mails.dpdk.org (Postfix) with ESMTP id 23FAD41172 for ; Thu, 24 Feb 2022 04:11:06 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D9Wb5vttltlAFu/2Gelepks1muglnL7htZE4iKLkCJN1lDq+S5kPO9NvzhbsaSh7IzUaM4jdN8N6K9y/LHoPhXiGQp+y/Vjsm7c/JcfiRH83+W+7ZzGAW7EEuC/oh3NoLJcnTwQXq1BFVE79SMEMwM6JzVFm2QpGs0CFMaJ29UyXPegRPVd3tdOcBQXomgT98foyNAduMO6ecY3SQNOKp4g/Dq8uEMrM50SMjftd6uLMeUWCJXEMnPYba8zbDJnpXbJJSiveQ8kLbqLz9xeWwqy+e5eI/dvlJoyw0E7yu/VtuSAol0R7uXKuBYfE1eT7/mA4aODXKHYUsLpJSPY8IA== 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=o8yufxz90UtgR4I/Y83XYZUvIk67mS8swu1YRnPLDyM=; b=G1v1F1E8qS6071UR+QUMjvlIiX1gIdJErJmHwZLNDUgwSg1Q7Wjo/fquRrrmRQjhS1momkB8eSUihfz6R3OS/R2DDx1itoe5S6+bsO12sm9vVVlYR5kAQIgPzgKL5wh2NaYt0L9tulSliBZYB6ocuK1mEvbSMw3bbYrFTMGg9YUKP2wYKeokQ4aiqfXNLUEJhnrr9g4g7RShY3yAOGtTeuznSj46nquTcaYi6XEhMd4gYeRUXlIO/JVDWEbIoCbaKfNrtkzEhK/zgLWOzfNuVKZwTbTY50oiL8V4REw70xkO5YMGxLpnI8Ybbzs/OtVABYOdLJ/Em9CJGVdBeKebqA== 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=o8yufxz90UtgR4I/Y83XYZUvIk67mS8swu1YRnPLDyM=; b=SYdVuGD5sezxmU+Lv31zU1S4K9JKQmSb/eK1ueahPRipUICoBtxQf5QRpeyKehnImAhkCh50/dpGrz6ymAPIwqATHaHbQZ1k8Lf3hEj794E6Xhu0BPoBhBQKqtL7x+/RBohNV8V6+BfXkzCQ7QgAjv5OYUJXoVKbMV3+JBO9HF45NczNMrNmuxbxz9FF4asKGYtCcx+gx2nY/Jpes5nc6r+BEVmRns9t5ID7JMdhiNZsUpXX0yUhcG9pr43sWdajovA9rR3rO6v369lbqkqw5HEdPkBIcPeHgh58b+2ZH2T81pz2NrDuC/yEhx6eYAWSTeXMpsU0ig6GDiphHTbX2A== Received: from DM5PR15CA0059.namprd15.prod.outlook.com (2603:10b6:3:ae::21) by DM6PR12MB4265.namprd12.prod.outlook.com (2603:10b6:5:211::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 03:11:04 +0000 Received: from DM6NAM11FT020.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ae:cafe::42) by DM5PR15CA0059.outlook.office365.com (2603:10b6:3:ae::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 03:11:04 +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 DM6NAM11FT020.mail.protection.outlook.com (10.13.172.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 03:11:03 +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; Thu, 24 Feb 2022 03:11:02 +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; Wed, 23 Feb 2022 19:11:00 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v3 09/14] net/mlx5: add flow flush function Date: Thu, 24 Feb 2022 05:10:24 +0200 Message-ID: <20220224031029.14049-10-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220224031029.14049-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220224031029.14049-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fb85d59c-5dcd-4a1b-30d4-08d9f7434ab1 X-MS-TrafficTypeDiagnostic: DM6PR12MB4265: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: 7PV9jlfAEjIz0g32bCD6NVhk6fpvAUruFpPkfgzIwx9V/36rfD0XHAABN7Pu/0n3qJJjbF3FBQ2fAmJ2x53q7x1LRqQEBnDvn7iSASm4CAXuSPhw32nOen2nT/DcxU3/854ClRQNOAoZW04XVZIqZqcZcYU6qjMy5TM+4bQ+DL/A2/ZhneDrI+MOBL1nBisC2gSCICgLaAHb67HPHzf5mTvf64bsft/gukoAb0dVouxS+99I5pzVeUrXcRB9gIIKD4SiUp8sz5PhAt633phDAhym0ffpbBf19Ay79Ea264FoiNw/x1CiNt759NDYdVinzcUmph0o24EEOyXF+kUw+QT9QimrTcjtwYhIRjmPQmt+MjydXoUZgj3ROcNB8R9PzNncNSYWFy6ZpE1uVJuQZ4oILT5B7TOfTGniY2pKF+90AxNoXZ8SaKArErkCPOLefxFwf/9FLhHXBH+CIMC+auOo4+cXNSBBQqi36cZLu3iR9fHaZlYpACcx8+p7vAvG3q13v9nBsJYv3YMA8hxyY9Dsq8Dxyu9DKwH92Ibv8jUdIc28Q7EBOzdvsTOUBKseIC8Hb5FTc51wcIiaNmDiMNO5h+L3MZM1qAeBHhLlbZxIjdVg/qSU1/4KdhVJcoP9WXap7nYgzuaZsd3RFR6+//Vpm7FgHF7AGQ63liFhGP9cbEa/JR6ooic1L/Omc1olTVsKz+Ehx8pXu1aRUsEmWw== 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)(46966006)(36840700001)(40470700004)(356005)(6286002)(70206006)(316002)(81166007)(6636002)(54906003)(6666004)(82310400004)(4326008)(2906002)(47076005)(70586007)(110136005)(26005)(186003)(16526019)(8676002)(1076003)(2616005)(5660300002)(336012)(426003)(8936002)(86362001)(7696005)(508600001)(40460700003)(36756003)(36860700001)(55016003)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 03:11:03.6381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb85d59c-5dcd-4a1b-30d4-08d9f7434ab1 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: DM6NAM11FT020.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4265 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 ad131c1b22..1672939200 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -7015,6 +7015,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