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 247E2A0350; Sat, 12 Feb 2022 05:20:09 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF3EE41170; Sat, 12 Feb 2022 05:20:03 +0100 (CET) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2055.outbound.protection.outlook.com [40.107.223.55]) by mails.dpdk.org (Postfix) with ESMTP id 358E0410F0 for ; Sat, 12 Feb 2022 05:20:02 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EmsYkplNx7o8XDQxwtXJOJU9IxlsSAA7TnUEaj3rFmCkFQuZkSa/f1h0ohU6L58v+tIQSm+b/5fDfU+x8Aww1VPjv9H6H7g6GNhuy23ukZ9nCRgpOifacAShD43TE5fHrxj/vbG65ej6vYAY33n6d7QjGMhbD4ISGxN/TwSsrG+jA3aiEpg9yu8IcyKxe3n7RuJNYQlTRbr0uONxy+e1JbBjhtLIo8eKkzsrOVaxnxMa+kVptzSdyKWhzzR4aBlYQD1vRUZLP61CTir8My2uTzlzt36tDaf9ihDlcZU1L+rHGfv1kVitqyb3Gwyd0UBoFw5gdy1zTpTvueSY3EdEXw== 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=phGh4RT1LMjxX/1/GQ0LOV5vYGukk1GMWMLrfPHgHb4=; b=OVWZC7eFRDyFl4xAKQ9TC0AmeAOpd2Qi8ryEsPIDMpmn5Oqc0oHkwCMBU+TSThi1fX92014dGh2sOyDdZ+yVyRlPMZxCbo+WF21UnkscMgWLKFYI4oaHHaRJ0LDKdww6hO7gaRc3oCOyyFmTlZZTlcFkDENAU6XRIFy0aoAnThAmska+G2biidqNj6Q3ieJuPw7Le7wl97oHFPXAfMr0QI3yzsw3i5/IOeioWsUTAqBtYaR1XSVKdl5oGI+fJvw8Z/x7nEEpHDYV40/3sEDElyNshVtQv/AP7xZifHbbES/2e5ZOn/YwWqCrvVEgh3j3qAb3+Z/3GVP9z3/w7kBAGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) 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=phGh4RT1LMjxX/1/GQ0LOV5vYGukk1GMWMLrfPHgHb4=; b=li0ZpEKxOajojGdVxCqyrDFZmT6qOtFc8SbrYk0JgbiojQxG1iToEAQRQxJ3gMdBLgUrVtlPFHucCWNEiQ1ZWh5nmv5l0SOBQeHWrdAf7mI1JnhkgQoBlo5bTRyQXVrIAQDcjC1G3PrZb/0o8FRHgohFmYhiAuidYg2BHxhRCjsAzywIwgBJWFDd/qrJKHeewzRp2rDMZ4u8eybsiATeTb9BDjoPq3vP+tRp5rslUE4zfvOIGkPbQQDaGMxW0fsq7GrM71iHQUOVai3ePE0iTroA/kvM/ghUw+UlIGDlMYncYB8zttrmTa7zrNcK+oksXpveN30ayn08UEbxtPJCfg== Received: from DM4PR12MB5771.namprd12.prod.outlook.com (2603:10b6:8:62::16) by DM6PR12MB3356.namprd12.prod.outlook.com (2603:10b6:5:38::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11; Sat, 12 Feb 2022 04:19:59 +0000 Received: from DS7PR03CA0147.namprd03.prod.outlook.com (2603:10b6:5:3b4::32) by DM4PR12MB5771.namprd12.prod.outlook.com (2603:10b6:8:62::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.14; Sat, 12 Feb 2022 04:19:58 +0000 Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b4:cafe::a0) by DS7PR03CA0147.outlook.office365.com (2603:10b6:5:3b4::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Sat, 12 Feb 2022 04:19:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT014.mail.protection.outlook.com (10.13.173.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4975.11 via Frontend Transport; Sat, 12 Feb 2022 04:19:58 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 12 Feb 2022 04:19:57 +0000 Received: from pegasus01.mtr.labs.mlnx (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.9; Fri, 11 Feb 2022 20:19:54 -0800 From: Alexander Kozyrev To: CC: , , , , , , , , , Subject: [PATCH v6 02/10] ethdev: add flow item/action templates Date: Sat, 12 Feb 2022 06:19:22 +0200 Message-ID: <20220212041930.1516767-3-akozyrev@nvidia.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20220212041930.1516767-1-akozyrev@nvidia.com> References: <20220211022653.1372318-1-akozyrev@nvidia.com> <20220212041930.1516767-1-akozyrev@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-Office365-Filtering-Correlation-Id: 813b526c-9c3c-493e-d753-08d9eddeee55 X-MS-TrafficTypeDiagnostic: DM4PR12MB5771:EE_|DM6PR12MB3356: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: MpnfLYptc8M39M5zxh2pNB0e9ZZueeL3EV7V0/vAHqwA3L6H9z3tZjo/KfU0n3ns5j5iA4elaeJxcCcvznYvXkB1a02eS9KHpkgOVZZkn7rAd2nfOoWKlgKZQQQ3mylTisnOKXFnDz44rNiSYNIA1Ty0LpIOo2CgScYWWbk8vLZhFTKs0VJymeUgqMQZu+oWZSfkXsAycs5dmn9Ov9XnofX/gHqkluyyaN1MD4gykUi8rG0z4OK7a4a7HZWpdHmVksqhPmHg5j1mJpP8QC68qV3/OGrzGhl780KdBDFG8OWd+HqSHAz3Yo6XTEPmO3kx2m57OpakNqjZp8nexdVIdK1t+4RHx2hk4EDUPJdaf1nRN4zbrFhrCFx2QILaY3KDq62ohyyRHtfYM9XMhY+P+Mhj7LvA5UkqtmCudcB+MINV7p1o36YDcZau1CaV/qdGJ9CalDWJO7jUWslk9NluqucOX8RCzzwOVQa76qP2ZN+Hm5B8xZ/e4M5kiMnxJhL7rZftTwxnOV+6lVge2/gh6UTuF6IWlb1IVnsTYwpUzFg/xRHL1dtEccm0zFvlxxUK6Q39lGneMhPlXEs//6FFFPhdZLO2iUs0xwmkG01qVMmnz0q9y2hr1vvEDRZzCpPPBgEZ4M3Ds0V2SvBS8/StuoTz/SqxTtjjPwtJUHyAy4yIkboJIP2ilyyLIDL9Tc32FTa20+xgy7hStU5KnngYyQ== X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(186003)(2616005)(16526019)(26005)(2906002)(5660300002)(86362001)(6666004)(1076003)(82310400004)(36860700001)(40460700003)(83380400001)(336012)(6916009)(356005)(81166007)(36756003)(7416002)(70586007)(30864003)(70206006)(316002)(47076005)(426003)(8936002)(4326008)(54906003)(508600001)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2022 04:19:58.5199 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 813b526c-9c3c-493e-d753-08d9eddeee55 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.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3356 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 pattern template defines common matching fields (the item mask) without values. The actions 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 pattern and actions 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 the table creation time. The flow rule creation is done by selecting a table, a pattern template and an actions template (which are bound to the table), and setting unique values for the items and actions. Signed-off-by: Alexander Kozyrev Acked-by: Ori Kam --- doc/guides/prog_guide/rte_flow.rst | 135 +++++++++++++ doc/guides/rel_notes/release_22_03.rst | 8 + lib/ethdev/rte_flow.c | 147 ++++++++++++++ lib/ethdev/rte_flow.h | 260 +++++++++++++++++++++++++ lib/ethdev/rte_flow_driver.h | 37 ++++ lib/ethdev/version.map | 6 + 6 files changed, 593 insertions(+) diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 72fb1132ac..8aa33300a3 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -3626,6 +3626,141 @@ of pre-configurable resources for a given port on a system. struct rte_flow_port_info *port_info, struct rte_flow_error *error); +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, a pattern template +and an actions template (which are bound to the table), and setting unique +values for the items and actions. This API is not thread-safe. + +Pattern templates +^^^^^^^^^^^^^^^^^ + +The pattern 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 pattern 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_pattern_template * + rte_flow_pattern_template_create(uint16_t port_id, + const struct rte_flow_pattern_template_attr *template_attr, + const struct rte_flow_item pattern[], + struct rte_flow_error *error); + +For example, to create a pattern template to match on the destination MAC: + +.. code-block:: c + + const struct rte_flow_pattern_template_attr attr = {0}; + struct rte_flow_item_eth eth_m = { + .dst.addr_bytes = "\xff\xff\xff\xff\xff\xff"; + }; + struct rte_flow_item pattern[] = { + [0] = {.type = RTE_FLOW_ITEM_TYPE_ETH, + .mask = ð_m}, + [1] = {.type = RTE_FLOW_ITEM_TYPE_END,}, + }; + struct rte_flow_error error; + + struct rte_flow_pattern_template *pattern_template = + rte_flow_pattern_template_create(port, &pt_attr, &pattern, &error); + +The concrete value to match on will be provided at the rule creation. + +Actions templates +^^^^^^^^^^^^^^^^^ + +The actions 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 actions 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_actions_template * + rte_flow_actions_template_create(uint16_t port_id, + const struct rte_flow_actions_template_attr *template_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *error); + +For example, to create an actions template with the same Mark ID +but different Queue Index for every rule: + +.. code-block:: c + + rte_flow_actions_template_attr attr = {0}; + 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_error error; + + struct rte_flow_actions_template *actions_template = + rte_flow_actions_template_create(port, &attr, &actions, &masks, &err); + +The concrete value for Queue Index will be provided at the rule creation. + +Template table +^^^^^^^^^^^^^^ + +A template table combines a number of pattern and actions 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_template_table * + rte_flow_template_table_create(uint16_t port_id, + const struct rte_flow_template_table_attr *table_attr, + struct rte_flow_pattern_template *pattern_templates[], + uint8_t nb_pattern_templates, + struct rte_flow_actions_template *actions_templates[], + uint8_t nb_actions_templates, + struct rte_flow_error *error); + +A table can be created only after the Flow Rules management is configured +and pattern and actions templates are created. + +.. code-block:: c + + rte_flow_template_table_attr table_attr = { + .flow_attr.ingress = 1, + .nb_flows = 10000; + }; + uint8_t nb_pattern_templates = 1; + struct rte_flow_pattern_template *pattern_templates[nb_pattern_templates]; + pattern_templates[0] = pattern_template; + uint8_t nb_actions_templates = 1; + struct rte_flow_actions_template *actions_templates[nb_actions_templates]; + actions_templates[0] = actions_template; + struct rte_flow_error error; + + struct rte_flow_template_table *table = + rte_flow_template_table_create(port, &table_attr, + &pattern_templates, nb_pattern_templates, + &actions_templates, nb_actions_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 2a47a37f0a..6656b35295 100644 --- a/doc/guides/rel_notes/release_22_03.rst +++ b/doc/guides/rel_notes/release_22_03.rst @@ -75,6 +75,14 @@ New Features engine, allowing to pre-allocate some resources for better performance. Added ``rte_flow_info_get`` API to retrieve pre-configurable resources. + * ethdev: Added ``rte_flow_template_table_create`` API to group flow rules + with the same flow attributes and common matching patterns and actions + defined by ``rte_flow_pattern_template_create`` and + ``rte_flow_actions_template_create`` respectively. + Corresponding functions to destroy these entities are: + ``rte_flow_template_table_destroy``, ``rte_flow_pattern_template_destroy`` + and ``rte_flow_actions_template_destroy``. + * **Updated AF_XDP PMD** * Added support for libxdp >=v1.2.2. diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 66614ae29b..b53f8c9b89 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -1431,3 +1431,150 @@ rte_flow_configure(uint16_t port_id, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, rte_strerror(ENOTSUP)); } + +struct rte_flow_pattern_template * +rte_flow_pattern_template_create(uint16_t port_id, + const struct rte_flow_pattern_template_attr *template_attr, + const struct rte_flow_item pattern[], + 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_pattern_template *template; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->pattern_template_create)) { + template = ops->pattern_template_create(dev, template_attr, + pattern, 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_pattern_template_destroy(uint16_t port_id, + struct rte_flow_pattern_template *pattern_template, + 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->pattern_template_destroy)) { + return flow_err(port_id, + ops->pattern_template_destroy(dev, + pattern_template, + error), + error); + } + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); +} + +struct rte_flow_actions_template * +rte_flow_actions_template_create(uint16_t port_id, + const struct rte_flow_actions_template_attr *template_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_actions_template *template; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->actions_template_create)) { + template = ops->actions_template_create(dev, template_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_actions_template_destroy(uint16_t port_id, + struct rte_flow_actions_template *actions_template, + 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->actions_template_destroy)) { + return flow_err(port_id, + ops->actions_template_destroy(dev, + actions_template, + error), + error); + } + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, rte_strerror(ENOTSUP)); +} + +struct rte_flow_template_table * +rte_flow_template_table_create(uint16_t port_id, + const struct rte_flow_template_table_attr *table_attr, + struct rte_flow_pattern_template *pattern_templates[], + uint8_t nb_pattern_templates, + struct rte_flow_actions_template *actions_templates[], + uint8_t nb_actions_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_template_table *table; + + if (unlikely(!ops)) + return NULL; + if (likely(!!ops->template_table_create)) { + table = ops->template_table_create(dev, table_attr, + pattern_templates, nb_pattern_templates, + actions_templates, nb_actions_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_template_table_destroy(uint16_t port_id, + struct rte_flow_template_table *template_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->template_table_destroy)) { + return flow_err(port_id, + ops->template_table_destroy(dev, + template_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 c25d46b866..b4c5e3cd9d 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -4961,6 +4961,266 @@ 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 pattern template. + * This handle can be used to manage the created pattern template. + */ +struct rte_flow_pattern_template; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Flow pattern template attributes. + */ +__extension__ +struct rte_flow_pattern_template_attr { + /** + * 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 flow pattern template. + * + * The pattern template defines common matching fields 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] template_attr + * Pattern template attributes. + * @param[in] pattern + * 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_pattern_template * +rte_flow_pattern_template_create(uint16_t port_id, + const struct rte_flow_pattern_template_attr *template_attr, + const struct rte_flow_item pattern[], + struct rte_flow_error *error); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy flow pattern 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] pattern_template + * 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_pattern_template_destroy(uint16_t port_id, + struct rte_flow_pattern_template *pattern_template, + struct rte_flow_error *error); + +/** + * Opaque type returned after successful creation of actions template. + * This handle can be used to manage the created actions template. + */ +struct rte_flow_actions_template; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Flow actions template attributes. + */ +struct rte_flow_actions_template_attr; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Create flow actions template. + * + * The actions 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] template_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_actions_template * +rte_flow_actions_template_create(uint16_t port_id, + const struct rte_flow_actions_template_attr *template_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 flow actions 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] actions_template + * 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_actions_template_destroy(uint16_t port_id, + struct rte_flow_actions_template *actions_template, + struct rte_flow_error *error); + +/** + * Opaque type returned after successful creation of a template table. + * This handle can be used to manage the created template table. + */ +struct rte_flow_template_table; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Table attributes. + */ +struct rte_flow_template_table_attr { + /** + * Flow attributes to be used in each rule generated from this 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 flow template table. + * + * A template table consists of multiple pattern templates and actions + * templates associated with a single set of rule attributes (group ID, + * priority and traffic direction). + * + * Each rule is free to use any combination of pattern and actions 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 + * Template table attributes. + * @param[in] pattern_templates + * Array of pattern templates to be used in this table. + * @param[in] nb_pattern_templates + * The number of pattern templates in the pattern_templates array. + * @param[in] actions_templates + * Array of actions templates to be used in this table. + * @param[in] nb_actions_templates + * The number of actions templates in the actions_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_template_table * +rte_flow_template_table_create(uint16_t port_id, + const struct rte_flow_template_table_attr *table_attr, + struct rte_flow_pattern_template *pattern_templates[], + uint8_t nb_pattern_templates, + struct rte_flow_actions_template *actions_templates[], + uint8_t nb_actions_templates, + struct rte_flow_error *error); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destroy flow template 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] template_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_template_table_destroy(uint16_t port_id, + struct rte_flow_template_table *template_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 7c29930d0f..2d96db1dc7 100644 --- a/lib/ethdev/rte_flow_driver.h +++ b/lib/ethdev/rte_flow_driver.h @@ -162,6 +162,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_pattern_template_create() */ + struct rte_flow_pattern_template *(*pattern_template_create) + (struct rte_eth_dev *dev, + const struct rte_flow_pattern_template_attr *template_attr, + const struct rte_flow_item pattern[], + struct rte_flow_error *err); + /** See rte_flow_pattern_template_destroy() */ + int (*pattern_template_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_pattern_template *pattern_template, + struct rte_flow_error *err); + /** See rte_flow_actions_template_create() */ + struct rte_flow_actions_template *(*actions_template_create) + (struct rte_eth_dev *dev, + const struct rte_flow_actions_template_attr *template_attr, + const struct rte_flow_action actions[], + const struct rte_flow_action masks[], + struct rte_flow_error *err); + /** See rte_flow_actions_template_destroy() */ + int (*actions_template_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_actions_template *actions_template, + struct rte_flow_error *err); + /** See rte_flow_template_table_create() */ + struct rte_flow_template_table *(*template_table_create) + (struct rte_eth_dev *dev, + const struct rte_flow_template_table_attr *table_attr, + struct rte_flow_pattern_template *pattern_templates[], + uint8_t nb_pattern_templates, + struct rte_flow_actions_template *actions_templates[], + uint8_t nb_actions_templates, + struct rte_flow_error *err); + /** See rte_flow_template_table_destroy() */ + int (*template_table_destroy) + (struct rte_eth_dev *dev, + struct rte_flow_template_table *template_table, + struct rte_flow_error *err); }; /** diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index f1235aa913..5fd2108895 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -262,6 +262,12 @@ EXPERIMENTAL { rte_eth_dev_priority_flow_ctrl_queue_info_get; rte_flow_info_get; rte_flow_configure; + rte_flow_pattern_template_create; + rte_flow_pattern_template_destroy; + rte_flow_actions_template_create; + rte_flow_actions_template_destroy; + rte_flow_template_table_create; + rte_flow_template_table_destroy; }; INTERNAL { -- 2.18.2