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 C561845BA0; Tue, 22 Oct 2024 14:07:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B451A40697; Tue, 22 Oct 2024 14:07:36 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2055.outbound.protection.outlook.com [40.107.237.55]) by mails.dpdk.org (Postfix) with ESMTP id 6F6B44065E for ; Tue, 22 Oct 2024 14:07:28 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b5uNrff9o2HJyaEJ4rTgs+fUePB9+rvBxjWq1eYxx3fYC237CkBm84w3gtAec0ti/l6jkbM79Wc8iDxP3f1YzV/kQc3w50GI2PP92hjyAvhlPYgINvQlZHwGgu4ot9rkITqh7AFS6K+vsBEa7KpcIUHWK1x/MwJ7ZfzBCuxfu6nHEJQWEpGC2FLJY61KANTXlkhp0Fn5Gv2CiaN3F2/o3Xl22Utu1UzFa1kuKn/z3CMXevjxAi9+e1XAa27ioiDJdFCTWjlp+kM9MnYApuVyLQ2Kfo2C55wwEjj9HNjIhdldRKF0QTE+n1X++PFI9ZVBi72xaiDJPtC/ljYwyviMHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nae47mw7doxhcYq81K6Y8vNJZnuXz8U1wSSMn9kwboQ=; b=yu8dAGmfiQwyHtBCqybP2o9wGScEhctrjaedI2UpbjW3n+UtYKkioYZoV23WOJigkiBzXxUaDiTgiLREA0bkjgSxf8TqZfPq/I3zJCNeBqdGfiHaFAE3258GJE05BuwbBgjLmdpwdKxU2471zrP0gfC/yT4t1aoe6BoozZPi4XvKaRv5AaHSFdFW6kGs9XlB8BQDOWZ+bBdRi/CwKdtd9K0bPLuMNz+HqLBfqdV5iCunvi+TV7vRSnO3i+5d/RK2fabHLHYYA3phQXb+xpVZaKEPjw0T/HRCchmHJ4H7aiEHJ7dNif65SevdJGogmEo+IXeXV5O+gKWoYZqHEGpLgQ== 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=nae47mw7doxhcYq81K6Y8vNJZnuXz8U1wSSMn9kwboQ=; b=oWvL41YoHiQPID0pib49uSYnF6ez/TXbkciUuEPBlrqHq3EF54GC1QMfcafIJUf5dosXNBW3fjenKUJaE+j37t38ir8ewaK1cNDt2YxCi2wG+tlcA8B90f7KbWyfFxFaYT+0X9mMyBvpZq4aJZzXdyHhRXPnmiZG0bShO37XdsPLwyXNs3HNrEDZk0uDPwX95/k8tKMdgzpnrM6Dc5FkrUpMCGBb20ZLMdhLk0QsI4o/esMKy9T3R8GCiaOJ87bnpOMj9KUsEDCBEAS2vkiyfHaJbEzbVq7rlj99mP1Na4bZLoYq043TRqvecURyEXCeNmbM4nTzaEnzMZ362neT1A== Received: from SJ0PR13CA0127.namprd13.prod.outlook.com (2603:10b6:a03:2c6::12) by DM4PR12MB6328.namprd12.prod.outlook.com (2603:10b6:8:a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.29; Tue, 22 Oct 2024 12:07:23 +0000 Received: from SJ1PEPF000023D9.namprd21.prod.outlook.com (2603:10b6:a03:2c6:cafe::3e) by SJ0PR13CA0127.outlook.office365.com (2603:10b6:a03:2c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.16 via Frontend Transport; Tue, 22 Oct 2024 12:07:23 +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 SJ1PEPF000023D9.mail.protection.outlook.com (10.167.244.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.2 via Frontend Transport; Tue, 22 Oct 2024 12:07:23 +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.1544.4; Tue, 22 Oct 2024 05:07:09 -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.1544.4; Tue, 22 Oct 2024 05:07:08 -0700 From: Dariusz Sosnowski To: Viacheslav Ovsiienko , Bing Zhao , Ori Kam , Suanming Mou , Matan Azrad CC: Subject: [PATCH v2 09/10] net/mlx5: add dynamic unicast flow rule management Date: Tue, 22 Oct 2024 14:06:17 +0200 Message-ID: <20241022120618.512091-10-dsosnowski@nvidia.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241022120618.512091-1-dsosnowski@nvidia.com> References: <20241017075738.190064-1-dsosnowski@nvidia.com> <20241022120618.512091-1-dsosnowski@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: SJ1PEPF000023D9:EE_|DM4PR12MB6328:EE_ X-MS-Office365-Filtering-Correlation-Id: 660edacc-d456-494c-d2b1-08dcf2921681 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?HqzzNgbAeUXMhaFAR6oI5VBMuvU1IkBv5GhymWKqhaY4bFXceTGrejqRB2fO?= =?us-ascii?Q?Su1506GPHdBlrd7JWr+m8L6nM/nzNtyNUjKWsYhq6tTqbuoILFkfgmSYh8S3?= =?us-ascii?Q?H964LNpEM5/qDzSkucaENaJfu3nbHiwzX9z/ADxkW6JLr4ArK01fh4oeqMpe?= =?us-ascii?Q?lm1J3LfC+3wlGMYudarRPq+cFta516xCx51so4X+8MQI6K/J2/c8X16c8jeL?= =?us-ascii?Q?lE977bhSWTNS3UBfZUw0q++x6mLFWslhu5bKN/PT4ITO/rv+htx8yGafOk2G?= =?us-ascii?Q?1yvO8/qe+FoEuDY9jdHRkvCAOmhq1G/zyDRry7bln3cGEFk7jDmNiQasrf8X?= =?us-ascii?Q?XeoaUj+cVdzlb4wajUcE+nA7JpHnkUuUVMwGmu4lLftpy1Qk0VPSOMtKDPFh?= =?us-ascii?Q?P6CbI25x/W2mzRCTGSubLRQ42Jo1gzrG2NOM+7kzqpJDwG/nl7OzK6PCWwhy?= =?us-ascii?Q?6vqxuxkx7wTqitRWYbvnRM539xSNLV2d7oiCqk5dKhFo0hF4Sr7MJK15aEfi?= =?us-ascii?Q?+C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yIymFvvdqaijMgu0yU0g=3D=3D?= 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:(13230040)(376014)(36860700013)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2024 12:07:23.5896 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 660edacc-d456-494c-d2b1-08dcf2921681 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: SJ1PEPF000023D9.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6328 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 This patch extens the mlx5_traffic interface with a couple of functions: - mlx5_traffic_mac_add() - Create an unicast DMAC flow rule, without recreating all control flow rules. - mlx5_traffic_mac_remove() - Remove an unicast DMAC flow rule, without recreating all control flow rules. - mlx5_traffic_mac_vlan_add() - Create an unicast DMAC with VLAN flow rule, without recreating all control flow rules. - mlx5_traffic_mac_vlan_remove() - Remove an unicast DMAC with VLAN flow rule, without recreating all control flow rules. These functions will be used in the follow up commit, which will modify the behavior of adding/removing MAC address and enabling/disabling VLAN filter in mlx5 PMD. Signed-off-by: Dariusz Sosnowski Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.h | 4 + drivers/net/mlx5/mlx5_trigger.c | 236 ++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index a51727526f..0e026f7bbb 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -2372,6 +2372,10 @@ int mlx5_hairpin_bind(struct rte_eth_dev *dev, uint16_t rx_port); int mlx5_hairpin_unbind(struct rte_eth_dev *dev, uint16_t rx_port); int mlx5_hairpin_get_peer_ports(struct rte_eth_dev *dev, uint16_t *peer_ports, size_t len, uint32_t direction); +int mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr); +int mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr); +int mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid); +int mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid); /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_trigger.c b/drivers/net/mlx5/mlx5_trigger.c index 4fa9319c4d..cac532b1a1 100644 --- a/drivers/net/mlx5/mlx5_trigger.c +++ b/drivers/net/mlx5/mlx5_trigger.c @@ -1804,3 +1804,239 @@ mlx5_traffic_restart(struct rte_eth_dev *dev) } return 0; } + +static bool +mac_flows_update_needed(struct rte_eth_dev *dev) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (!dev->data->dev_started) + return false; + if (dev->data->promiscuous) + return false; + if (priv->isolated) + return false; + + return true; +} + +static int +traffic_dmac_create(struct rte_eth_dev *dev, const struct rte_ether_addr *addr) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (priv->sh->config.dv_flow_en == 2) + return mlx5_flow_hw_ctrl_flow_dmac(dev, addr); + else + return mlx5_legacy_dmac_flow_create(dev, addr); +} + +static int +traffic_dmac_destroy(struct rte_eth_dev *dev, const struct rte_ether_addr *addr) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (priv->sh->config.dv_flow_en == 2) + return mlx5_flow_hw_ctrl_flow_dmac_destroy(dev, addr); + else + return mlx5_legacy_dmac_flow_destroy(dev, addr); +} + +static int +traffic_dmac_vlan_create(struct rte_eth_dev *dev, + const struct rte_ether_addr *addr, + const uint16_t vid) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (priv->sh->config.dv_flow_en == 2) + return mlx5_flow_hw_ctrl_flow_dmac_vlan(dev, addr, vid); + else + return mlx5_legacy_dmac_vlan_flow_create(dev, addr, vid); +} + +static int +traffic_dmac_vlan_destroy(struct rte_eth_dev *dev, + const struct rte_ether_addr *addr, + const uint16_t vid) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (priv->sh->config.dv_flow_en == 2) + return mlx5_flow_hw_ctrl_flow_dmac_vlan_destroy(dev, addr, vid); + else + return mlx5_legacy_dmac_vlan_flow_destroy(dev, addr, vid); +} + +/** + * Adjust Rx control flow rules to allow traffic on provided MAC address. + */ +int +mlx5_traffic_mac_add(struct rte_eth_dev *dev, const struct rte_ether_addr *addr) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (!mac_flows_update_needed(dev)) + return 0; + + if (priv->vlan_filter_n > 0) { + unsigned int i; + + for (i = 0; i < priv->vlan_filter_n; ++i) { + uint16_t vlan = priv->vlan_filter[i]; + int ret; + + if (mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan)) + continue; + + ret = traffic_dmac_vlan_create(dev, addr, vlan); + if (ret != 0) + return ret; + } + + return 0; + } + + if (mlx5_ctrl_flow_uc_dmac_exists(dev, addr)) + return 0; + + return traffic_dmac_create(dev, addr); +} + +/** + * Adjust Rx control flow rules to disallow traffic with removed MAC address. + */ +int +mlx5_traffic_mac_remove(struct rte_eth_dev *dev, const struct rte_ether_addr *addr) +{ + struct mlx5_priv *priv = dev->data->dev_private; + + if (!mac_flows_update_needed(dev)) + return 0; + + if (priv->vlan_filter_n > 0) { + unsigned int i; + + for (i = 0; i < priv->vlan_filter_n; ++i) { + uint16_t vlan = priv->vlan_filter[i]; + int ret; + + if (!mlx5_ctrl_flow_uc_dmac_vlan_exists(dev, addr, vlan)) + continue; + + ret = traffic_dmac_vlan_destroy(dev, addr, vlan); + if (ret != 0) + return ret; + } + + return 0; + } + + if (!mlx5_ctrl_flow_uc_dmac_exists(dev, addr)) + return 0; + + return traffic_dmac_destroy(dev, addr); +} + +/** + * Adjust Rx control flow rules to allow traffic on provided VLAN. + * + * Assumptions: + * - Called when VLAN is added. + * - At least one VLAN is enabled before function call. + * + * This functions assumes that VLAN is new and was not included in + * Rx control flow rules set up before calling it. + */ +int +mlx5_traffic_vlan_add(struct rte_eth_dev *dev, const uint16_t vid) +{ + struct mlx5_priv *priv = dev->data->dev_private; + unsigned int i; + int ret; + + if (!mac_flows_update_needed(dev)) + return 0; + + /* Add all unicast DMAC flow rules with new VLAN attached. */ + for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) { + struct rte_ether_addr *mac = &dev->data->mac_addrs[i]; + + if (rte_is_zero_ether_addr(mac)) + continue; + + ret = traffic_dmac_vlan_create(dev, mac, vid); + if (ret != 0) + return ret; + } + + if (priv->vlan_filter_n == 1) { + /* + * Adding first VLAN. Need to remove unicast DMAC rules before adding new rules. + * Removing after creating VLAN rules so that traffic "gap" is not introduced. + */ + + for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) { + struct rte_ether_addr *mac = &dev->data->mac_addrs[i]; + + if (rte_is_zero_ether_addr(mac)) + continue; + + ret = traffic_dmac_destroy(dev, mac); + if (ret != 0) + return ret; + } + } + + return 0; +} + +/** + * Adjust Rx control flow rules to disallow traffic with removed VLAN. + * + * Assumptions: + * + * - VLAN was really removed. + */ +int +mlx5_traffic_vlan_remove(struct rte_eth_dev *dev, const uint16_t vid) +{ + struct mlx5_priv *priv = dev->data->dev_private; + unsigned int i; + int ret; + + if (!mac_flows_update_needed(dev)) + return 0; + + if (priv->vlan_filter_n == 0) { + /* + * If there are no VLANs as a result, unicast DMAC flow rules must be recreated. + * Recreating first to ensure no traffic "gap". + */ + + for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) { + struct rte_ether_addr *mac = &dev->data->mac_addrs[i]; + + if (rte_is_zero_ether_addr(mac)) + continue; + + ret = traffic_dmac_create(dev, mac); + if (ret != 0) + return ret; + } + } + + /* Remove all unicast DMAC flow rules with this VLAN. */ + for (i = 0; i != MLX5_MAX_MAC_ADDRESSES; ++i) { + struct rte_ether_addr *mac = &dev->data->mac_addrs[i]; + + if (rte_is_zero_ether_addr(mac)) + continue; + + ret = traffic_dmac_vlan_destroy(dev, mac, vid); + if (ret != 0) + return ret; + } + + return 0; +} -- 2.39.5