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 D1DABA034C; Tue, 18 Jan 2022 16:31:01 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5BBC44272F; Tue, 18 Jan 2022 16:31:01 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2064.outbound.protection.outlook.com [40.107.236.64]) by mails.dpdk.org (Postfix) with ESMTP id 5489642727 for ; Tue, 18 Jan 2022 16:31:00 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OK+pPm0S0YnmYSLT3xMo1Qd7P8box9H1M4JZCHxUWKzu6xzNMkWoB6+Ir9hPQDQJqfhYcQCQbRXCl0nKCO1hxLBn9pMv6ECSL5Z1B0An0SFuKsS2cvTyXOCoJI8nUUkWklL0eeP0YyUPaARQKoGkAWC9nxJeShCptCXRZyUiAR9ehP0sy/PeNS4jC4+ERDgerlDSlFrKyUyxiJv8V3S6Fyhc+djYDY3u+gp24xj6wMp7OGKA8PKITI3HgtHA4F7311Zw85GajJsXSbOPQBeNJCfHhTV970fnZzkXxp3jDTTPia7VyFeck4YzktVQ6dxgi39iaYQ0qJjk04zRS4c79w== 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=dXfP4jFtialrPh4QJKiWk7nY5l2y60iLSSpqcu8iCbI=; b=FovdVicVX6u1k1W+GZQppAqsMcc3s41aFSGZGydC3titF76mgB17x1j02X4rTnkTfZ1UNSPx2tGT+q/OmOY8ChmagJsBItMUtYJ8e8W01eGQxLzitN3KYpQEhvMjUTprjYFKHJzCDw2+Y+egRkuPVEVYBElWNOj8t10jcjQ8BlhnVUTWgtGzjC3V4gEbDXQN0rov6NarmvobIw2bJxrjNwQpkB5boVRGGHBbMCwcUxL0zMlnMjQYt/rm/EdpJA7Dtj2c7VPdYDzU09gPr0kZYS9qUYoSDOMomq40mfnfkkXRkAi/9e8LA73QuWZejEhMQ0mv6qKa7SB5xI2c7zs02w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=intel.com 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=dXfP4jFtialrPh4QJKiWk7nY5l2y60iLSSpqcu8iCbI=; b=ILftn5rYub3A/CP5E4mtvFh/LvmPn+5bvtX7koPaTrDgV3PUF6zVIN0wMONl4hBjP4zRtUtiOTWcZJsAdPK0gKF0SVUFDGLklTmonqPjEMu5YE9uw0RHx9AItfQuoFb6o7EFdkyUpVs3BxWgnMpcd7ZsYWTZcmNJx4VgZ6f6UWt2tGLEhqsAp1ZVXwyf2kXjDuqs+ZXavMyvlqrAE8CeQFB0nA1SmuIqarkvnA3jHnkcPEmmn5h1eiZvFoyASq4tRFhJkm2TAAiGBSw8gF5HtRYgseX2/k5DkCvcXb1ctj7N2jjhs6Gq2takcKlMuaIc05hD09qd0Vq2h1BLdzWtDA== Received: from BY5PR12MB3844.namprd12.prod.outlook.com (2603:10b6:a03:1ad::24) by DM6PR12MB3913.namprd12.prod.outlook.com (2603:10b6:5:1cc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Tue, 18 Jan 2022 15:30:56 +0000 Received: from BN9PR03CA0595.namprd03.prod.outlook.com (2603:10b6:408:10d::30) by BY5PR12MB3844.namprd12.prod.outlook.com (2603:10b6:a03:1ad::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7; Tue, 18 Jan 2022 15:30:55 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10d:cafe::4b) by BN9PR03CA0595.outlook.office365.com (2603:10b6:408:10d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.7 via Frontend Transport; Tue, 18 Jan 2022 15:30:55 +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 BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4888.9 via Frontend Transport; Tue, 18 Jan 2022 15:30:55 +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, 18 Jan 2022 15:30:54 +0000 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_CBC_SHA384) id 15.2.986.9; Tue, 18 Jan 2022 07:30:51 -0800 From: Alexander Kozyrev To: CC: , , , , , , , , Subject: [PATCH v2 02/10] ethdev: add flow item/action templates Date: Tue, 18 Jan 2022 17:30:19 +0200 Message-ID: <20220118153027.3947448-3-akozyrev@nvidia.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20220118153027.3947448-1-akozyrev@nvidia.com> References: <20211006044835.3936226-1-akozyrev@nvidia.com> <20220118153027.3947448-1-akozyrev@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 103aa3c2-8358-45b0-1efe-08d9da9784e4 X-MS-TrafficTypeDiagnostic: BY5PR12MB3844:EE_|DM6PR12MB3913:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n/L5KJS78a3EeoAeymsHTtqIzsSPnxD5PVF1c60nKhTTd2bYxpTZeDXKW5Mt+rQk5g9QS+XBEn9K9+DPAdMUf+TCjAZqBSx6qlR2XdyQaZSv7LrHShHCSCFZ1oX4ZZqjq7vfzT1I31/+IQsnLm1Tk1AHrO2+WT0sbeHp0UDC5uapo4mJdeVNDoX+xbaPToy0UAm1sz5im+Rp9UGx1WpFIZQL8jkUlMb/29xzR6i/7ojlJUsIvXp0G3/YthEkD1UaTDLqXkyq/S9Xf02yvPZ4/VV9v7yKPUcH35+AlQ0tcFNL9i3aurDlDAe6+0WFaj82rIA7ryS/Hd3je3BJS4tdOCkKi1BmB2v8OFh4d5F6EYJXa7JM290AnWq9X/adMDSaIGgfcCTKQrmopE49iNDMnzJ38+Tlx8tKYJxt1awVcynTWYQ3UYNGfdBslQkO/nl1ISi++QRCEgYSD9/5MjsnMsoSRkC7k0bONNm7cRQnY4C7ImNkvw1WViRytQRSLeDAWvfNBlBb+SnLnhWMB4x15z6m+QrtgmptZlzifRuinMed/csIO6YiwWPGar+aGkaVVBbr9G0CMW9fbE0w+zFJrnA9UzvTXIlb4I4D6+CEt9Uw0+sQcvhA68RnH2b47n5b4PMzMxtAi4XSK2FdJmE9y9FJDFX2XYn2WMvTAWaizgt6BbQf6Y4nrcaIaSw8cocxncmabv52oL5QRQSG/JNnPyMdaLprgv3kfRPoP0Tdf2ACdmDDoYcDB08GJTyJr+RVqYnspqVEOU1scEz3jaWIVBZMq15xkDdWOvf8vTEtTFg= 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:(4636009)(46966006)(36840700001)(40470700002)(508600001)(81166007)(40460700001)(2906002)(1076003)(6666004)(8676002)(36756003)(7696005)(2616005)(26005)(8936002)(6916009)(5660300002)(336012)(6286002)(47076005)(16526019)(30864003)(86362001)(426003)(70586007)(83380400001)(54906003)(186003)(316002)(4326008)(82310400004)(55016003)(356005)(70206006)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 15:30:55.1595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 103aa3c2-8358-45b0-1efe-08d9da9784e4 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-FromEntityHeader: HybridOnPrem X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3913 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 Treating every single flow rule as a completely independent and separate entity negatively impacts the flow rules insertion rate. Oftentimes in an application, many flow rules share a common structure (the same item mask and/or action list) so they can be grouped and classified together. This knowledge may be used as a source of optimization by a PMD/HW. The item template defines common matching fields (the item mask) without values. The action template holds a list of action types that will be used together in the same rule. The specific values for items and actions will be given only during the rule creation. A table combines item and action templates along with shared flow rule attributes (group ID, priority and traffic direction). This way a PMD/HW can prepare all the resources needed for efficient flow rules creation in the datapath. To avoid any hiccups due to memory reallocation, the maximum number of flow rules is defined at table creation time. The flow rule creation is done by selecting a table, an item template and an action template (which are bound to the table), and setting unique values for the items and actions. Signed-off-by: Alexander Kozyrev --- doc/guides/prog_guide/rte_flow.rst | 124 ++++++++++++ doc/guides/rel_notes/release_22_03.rst | 8 + lib/ethdev/rte_flow.c | 141 +++++++++++++ lib/ethdev/rte_flow.h | 269 +++++++++++++++++++++++++ lib/ethdev/rte_flow_driver.h | 37 ++++ lib/ethdev/version.map | 6 + 6 files changed, 585 insertions(+) diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 86f8c8bda2..aa9d4e9573 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -3626,6 +3626,130 @@ Return values: - 0 on success, a negative errno value otherwise and ``rte_errno`` is set. +Flow templates +~~~~~~~~~~~~~~ + +Oftentimes in an application, many flow rules share a common structure +(the same pattern and/or action list) so they can be grouped and classified +together. This knowledge may be used as a source of optimization by a PMD/HW. +The flow rule creation is done by selecting a table, an item template +and an action template (which are bound to the table), and setting unique +values for the items and actions. This API is not thread-safe. + +Item templates +^^^^^^^^^^^^^^ + +The item template defines a common pattern (the item mask) without values. +The mask value is used to select a field to match on, spec/last are ignored. +The item template may be used by multiple tables and must not be destroyed +until all these tables are destroyed first. + +.. code-block:: c + + struct rte_flow_item_template * + rte_flow_item_template_create(uint16_t port_id, + const struct rte_flow_item_template_attr *it_attr, + const struct rte_flow_item items[], + struct rte_flow_error *error); + +For example, to create an item template to match on the destination MAC: + +.. code-block:: c + + struct rte_flow_item root_items[2] = {{0}}; + struct rte_flow_item_eth eth_m = {0}; + items[0].type = RTE_FLOW_ITEM_TYPE_ETH; + eth_m.dst.addr_bytes = "\xff\xff\xff\xff\xff\xff"; + items[0].mask = ð_m; + items[1].type = RTE_FLOW_ITEM_TYPE_END; + + struct rte_flow_item_template *it = + rte_flow_item_template_create(port, &itr, &items, &error); + +The concrete value to match on will be provided at the rule creation. + +Action templates +^^^^^^^^^^^^^^^^ + +The action template holds a list of action types to be used in flow rules. +The mask parameter allows specifying a shared constant value for every rule. +The action template may be used by multiple tables and must not be destroyed +until all these tables are destroyed first. + +.. code-block:: c + + struct rte_flow_action_template * + rte_flow_action_template_create(uint16_t port_id, + const struct rte_flow_action_template_attr *at_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); + +For example, to create an action template with the same Mark ID +but different Queue Index for every rule: + +.. code-block:: c + + struct rte_flow_action actions[] = { + /* Mark ID is constant (4) for every rule, Queue Index is unique */ + [0] = {.type = RTE_FLOW_ACTION_TYPE_MARK, + .conf = &(struct rte_flow_action_mark){.id = 4}}, + [1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE}, + [2] = {.type = RTE_FLOW_ACTION_TYPE_END,}, + }; + struct rte_flow_action masks[] = { + /* Assign to MARK mask any non-zero value to make it constant */ + [0] = {.type = RTE_FLOW_ACTION_TYPE_MARK, + .conf = &(struct rte_flow_action_mark){.id = 1}}, + [1] = {.type = RTE_FLOW_ACTION_TYPE_QUEUE}, + [2] = {.type = RTE_FLOW_ACTION_TYPE_END,}, + }; + + struct rte_flow_action_template *at = + rte_flow_action_template_create(port, &atr, &actions, &masks, &error); + +The concrete value for Queue Index will be provided at the rule creation. + +Flow table +^^^^^^^^^^ + +A table combines a number of item and action templates along with shared flow +rule attributes (group ID, priority and traffic direction). This way a PMD/HW +can prepare all the resources needed for efficient flow rules creation in +the datapath. To avoid any hiccups due to memory reallocation, the maximum +number of flow rules is defined at table creation time. Any flow rule +creation beyond the maximum table size is rejected. Application may create +another table to accommodate more rules in this case. + +.. code-block:: c + + struct rte_flow_table * + rte_flow_table_create(uint16_t port_id, + const struct rte_flow_table_attr *table_attr, + struct rte_flow_item_template *item_templates[], + uint8_t nb_item_templates, + struct rte_flow_action_template *action_templates[], + uint8_t nb_action_templates, + struct rte_flow_error *error); + +A table can be created only after the Flow Rules management is configured +and item and action templates are created. + +.. code-block:: c + + rte_flow_configure(port, *port_attr, *error); + + struct rte_flow_item_template *it[0] = + rte_flow_item_template_create(port, &itr, &items, &error); + struct rte_flow_action_template *at[0] = + rte_flow_action_template_create(port, &atr, &actions, &masks, &error); + + struct rte_flow_table *table = + rte_flow_table_create(port, *table_attr, + *it, nb_item_templates, + *at, nb_action_templates, + *error); + .. _flow_isolated_mode: Flow isolated mode diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst index 71b3f0a651..af56f54bc4 100644 --- a/doc/guides/rel_notes/release_22_03.rst +++ b/doc/guides/rel_notes/release_22_03.rst @@ -58,6 +58,14 @@ New Features * ethdev: Added ``rte_flow_configure`` API to configure Flow Management library, allowing to pre-allocate some resources for better performance. +* ethdev: Added ``rte_flow_table_create`` API to group flow rules with + the same flow attributes and common matching patterns and actions + defined by ``rte_flow_item_template_create`` and + ``rte_flow_action_template_create`` respectively. + Corresponding functions to destroy these entities are: + ``rte_flow_table_destroy``, ``rte_flow_item_template_destroy`` + and ``rte_flow_action_template_destroy`` respectively. + Removed Items ------------- diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 5b78780ef9..20613f6bed 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -1411,3 +1411,144 @@ rte_flow_configure(uint16_t port_id, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, rte_strerror(ENOTSUP)); } + +struct rte_flow_item_template * +rte_flow_item_template_create(uint16_t port_id, + const struct rte_flow_item_template_attr *it_attr, + const struct rte_flow_item items[], + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + struct rte_flow_item_template *template; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->item_template_create)) { + template = ops->item_template_create(dev, it_attr, + items, error); + if (template == NULL) + flow_err(port_id, -rte_errno, error); + return template; + } + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); + return NULL; +} + +int +rte_flow_item_template_destroy(uint16_t port_id, + struct rte_flow_item_template *it, + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + + if (unlikely(!ops)) + return -rte_errno; + if (likely(!!ops->item_template_destroy)) { + return flow_err(port_id, + ops->item_template_destroy(dev, it, error), + error); + } + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); +} + +struct rte_flow_action_template * +rte_flow_action_template_create(uint16_t port_id, + const struct rte_flow_action_template_attr *at_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + struct rte_flow_action_template *template; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->action_template_create)) { + template = ops->action_template_create(dev, at_attr, + actions, masks, error); + if (template == NULL) + flow_err(port_id, -rte_errno, error); + return template; + } + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); + return NULL; +} + +int +rte_flow_action_template_destroy(uint16_t port_id, + struct rte_flow_action_template *at, + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + + if (unlikely(!ops)) + return -rte_errno; + if (likely(!!ops->action_template_destroy)) { + return flow_err(port_id, + ops->action_template_destroy(dev, at, error), + error); + } + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); +} + +struct rte_flow_table * +rte_flow_table_create(uint16_t port_id, + const struct rte_flow_table_attr *table_attr, + struct rte_flow_item_template *item_templates[], + uint8_t nb_item_templates, + struct rte_flow_action_template *action_templates[], + uint8_t nb_action_templates, + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + struct rte_flow_table *table; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->table_create)) { + table = ops->table_create(dev, table_attr, + item_templates, nb_item_templates, + action_templates, nb_action_templates, + error); + if (table == NULL) + flow_err(port_id, -rte_errno, error); + return table; + } + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); + return NULL; +} + +int +rte_flow_table_destroy(uint16_t port_id, + struct rte_flow_table *table, + struct rte_flow_error *error) +{ + struct rte_eth_dev *dev = &rte_eth_devices[port_id]; + const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error); + + if (unlikely(!ops)) + return -rte_errno; + if (likely(!!ops->table_destroy)) { + return flow_err(port_id, + ops->table_destroy(dev, table, error), + error); + } + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); +} diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h index e145e68525..2e54e9d0e3 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -4916,6 +4916,275 @@ rte_flow_configure(uint16_t port_id, const struct rte_flow_port_attr *port_attr, struct rte_flow_error *error); +/** + * Opaque type returned after successful creation of item template. + * This handle can be used to manage the created item template. + */ +struct rte_flow_item_template; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Flow item template attributes. + */ +__extension__ +struct rte_flow_item_template_attr { + /** + * Version of the struct layout, should be 0. + */ + uint32_t version; + /** + * Relaxed matching policy, PMD may match only on items + * with mask member set and skip matching on protocol + * layers specified without any masks. + * If not set, PMD will match on protocol layers + * specified without any masks as well. + * Packet data must be stacked in the same order as the + * protocol layers to match inside packets, + * starting from the lowest. + */ + uint32_t relaxed_matching:1; +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create item template. + * The item template defines common matching fields (item mask) without values. + * For example, matching on 5 tuple TCP flow, the template will be + * eth(null) + IPv4(source + dest) + TCP(s_port + d_port), + * while values for each rule will be set during the flow rule creation. + * The number and order of items in the template must be the same + * at the rule creation. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] it_attr + * Item template attributes. + * @param[in] items + * Pattern specification (list terminated by the END pattern item). + * The spec member of an item is not used unless the end member is used. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * Handle on success, NULL otherwise and rte_errno is set. + */ +__rte_experimental +struct rte_flow_item_template * +rte_flow_item_template_create(uint16_t port_id, + const struct rte_flow_item_template_attr *it_attr, + const struct rte_flow_item items[], + struct rte_flow_error *error); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy item template. + * This function may be called only when + * there are no more tables referencing this template. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] it + * Handle of the template to be destroyed. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +__rte_experimental +int +rte_flow_item_template_destroy(uint16_t port_id, + struct rte_flow_item_template *it, + struct rte_flow_error *error); + +/** + * Opaque type returned after successful creation of action template. + * This handle can be used to manage the created action template. + */ +struct rte_flow_action_template; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Flow action template attributes. + */ +struct rte_flow_action_template_attr { + /** + * Version of the struct layout, should be 0. + */ + uint32_t version; + /* No attributes so far. */ +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create action template. + * The action template holds a list of action types without values. + * For example, the template to change TCP ports is TCP(s_port + d_port), + * while values for each rule will be set during the flow rule creation. + * The number and order of actions in the template must be the same + * at the rule creation. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] at_attr + * Template attributes. + * @param[in] actions + * Associated actions (list terminated by the END action). + * The spec member is only used if @p masks spec is non-zero. + * @param[in] masks + * List of actions that marks which of the action's member is constant. + * A mask has the same format as the corresponding action. + * If the action field in @p masks is not 0, + * the corresponding value in an action from @p actions will be the part + * of the template and used in all flow rules. + * The order of actions in @p masks is the same as in @p actions. + * In case of indirect actions present in @p actions, + * the actual action type should be present in @p mask. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * Handle on success, NULL otherwise and rte_errno is set. + */ +__rte_experimental +struct rte_flow_action_template * +rte_flow_action_template_create(uint16_t port_id, + const struct rte_flow_action_template_attr *at_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy action template. + * This function may be called only when + * there are no more tables referencing this template. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] at + * Handle to the template to be destroyed. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +__rte_experimental +int +rte_flow_action_template_destroy(uint16_t port_id, + struct rte_flow_action_template *at, + struct rte_flow_error *error); + + +/** + * Opaque type returned after successful creation of table. + * This handle can be used to manage the created table. + */ +struct rte_flow_table; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Table attributes. + */ +struct rte_flow_table_attr { + /** + * Version of the struct layout, should be 0. + */ + uint32_t version; + /** + * Flow attributes that will be used in the table. + */ + struct rte_flow_attr flow_attr; + /** + * Maximum number of flow rules that this table holds. + */ + uint32_t nb_flows; +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create table. + * Table is a group of flow rules with the same flow attributes + * (group ID, priority and traffic direction) defined for it. + * The table holds multiple item and action templates to build a flow rule. + * Each rule is free to use any combination of item and action templates + * and specify particular values for items and actions it would like to change. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] table_attr + * Table attributes. + * @param[in] item_templates + * Array of item templates to be used in this table. + * @param[in] nb_item_templates + * The number of item templates in the item_templates array. + * @param[in] action_templates + * Array of action templates to be used in this table. + * @param[in] nb_action_templates + * The number of action templates in the action_templates array. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * Handle on success, NULL otherwise and rte_errno is set. + */ +__rte_experimental +struct rte_flow_table * +rte_flow_table_create(uint16_t port_id, + const struct rte_flow_table_attr *table_attr, + struct rte_flow_item_template *item_templates[], + uint8_t nb_item_templates, + struct rte_flow_action_template *action_templates[], + uint8_t nb_action_templates, + struct rte_flow_error *error); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy table. + * This function may be called only when + * there are no more flow rules referencing this table. + * + * @param port_id + * Port identifier of Ethernet device. + * @param[in] table + * Handle to the table to be destroyed. + * @param[out] error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +__rte_experimental +int +rte_flow_table_destroy(uint16_t port_id, + struct rte_flow_table *table, + struct rte_flow_error *error); + #ifdef __cplusplus } #endif diff --git a/lib/ethdev/rte_flow_driver.h b/lib/ethdev/rte_flow_driver.h index 5f722f1a39..cda021c302 100644 --- a/lib/ethdev/rte_flow_driver.h +++ b/lib/ethdev/rte_flow_driver.h @@ -157,6 +157,43 @@ struct rte_flow_ops { (struct rte_eth_dev *dev, const struct rte_flow_port_attr *port_attr, struct rte_flow_error *err); + /** See rte_flow_item_template_create() */ + struct rte_flow_item_template *(*item_template_create) + (struct rte_eth_dev *dev, + const struct rte_flow_item_template_attr *it_attr, + const struct rte_flow_item items[], + struct rte_flow_error *err); + /** See rte_flow_item_template_destroy() */ + int (*item_template_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_item_template *it, + struct rte_flow_error *err); + /** See rte_flow_action_template_create() */ + struct rte_flow_action_template *(*action_template_create) + (struct rte_eth_dev *dev, + const struct rte_flow_action_template_attr *at_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *err); + /** See rte_flow_action_template_destroy() */ + int (*action_template_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_action_template *at, + struct rte_flow_error *err); + /** See rte_flow_table_create() */ + struct rte_flow_table *(*table_create) + (struct rte_eth_dev *dev, + const struct rte_flow_table_attr *table_attr, + struct rte_flow_item_template *item_templates[], + uint8_t nb_item_templates, + struct rte_flow_action_template *action_templates[], + uint8_t nb_action_templates, + struct rte_flow_error *err); + /** See rte_flow_table_destroy() */ + int (*table_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_table *table, + struct rte_flow_error *err); }; /** diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 7645796739..cfd5e2a3e4 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -259,6 +259,12 @@ EXPERIMENTAL { # added in 22.03 rte_flow_configure; + rte_flow_item_template_create; + rte_flow_item_template_destroy; + rte_flow_action_template_create; + rte_flow_action_template_destroy; + rte_flow_table_create; + rte_flow_table_destroy; }; INTERNAL { -- 2.18.2