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 3EC6AA0C47; Tue, 12 Oct 2021 13:33:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C48641161; Tue, 12 Oct 2021 13:33:00 +0200 (CEST) Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam07on2062.outbound.protection.outlook.com [40.107.95.62]) by mails.dpdk.org (Postfix) with ESMTP id 352864115D for ; Tue, 12 Oct 2021 13:32:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X8GxTzYUvgh4zI3JvbnBjocf9eY3qBJhqTRoTGhgtchXY4HSwUSAiotXkMvUsp37gwD2WfV1iLIyvwVu7Ob8k2DJLkb3soDrx3pdsjRei1Wj9ritSkXjNSt8pJJErc5JYGY4nL/7L/Ia6SJIibImNDn7YHRCB/Cy95eQFuoXAfDwM7sUxEDi6WwyNWbMv+/2kMtLTc8dZzGKprB6wgrbMW2FpdxhN4Eg2OePtxMYNQPFZXbXujkLFqC71DAofk2443/SaCB4yeW1Fugv+RQTVwGdXpz2DWNaNef5bNywdc98RBJPn3peIFJ3OVBWmukLPcwJ9wWu3dRuSY2duW+uvw== 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=5M/NBeLmm7ln36O8i6I3rmQyC6ip2HifE3x0+WFKDFk=; b=j0aCTJLsvNtP1ZcNuD9ETYSUJZHYQZtaDJXf+siGXprqLPaV+IYPq0x1/0CTVWdIXilzU/tSgXPH3P7EzP7m2mKLyq64H1DVU1yju/smIR8L9U9Qi9OIRA43m77ZGGGFvC5Yt3jXCnGdbUAfOQ7/r/MPa5iSky6PPRy4RD9OLpF75Qb1i7UbrVA8GRYtxEbI66RAvr32YbzZdsGEYR4aaiRxUTFLOiTfZ8F0vUhxcX1lMWO3zDx4nbMvOs/MluMinZFmajoMAWtltnoN6EDn9QHIlwp1MKsacGAjjtFwYBMU0ohuT3FLAAZHI774sdcSpHhmgyczAgBc9yIFGSoDzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine 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=5M/NBeLmm7ln36O8i6I3rmQyC6ip2HifE3x0+WFKDFk=; b=YWApDglbkqftqJr8GT/alm3xWi5Xt/D3++nxwp1oTLknU9kh4rh0GcZuuyxn2mgU9BN7oQNsHBdL4r9rSd5lEkvm4NASnZcELFRfUpD86At/my9DsAMb4m8BM0dRxEfhN7crFlBrqLBuYG0cLOf5aREcMDF1Gwu5naR4k7oMtNxAe5AnECMJrzER7tux8XaS4qG1K8JYNJFfuH7nnZ81VhbrRrg7a3gIfgxLqdkDc8KX8QJ6+SlGkp3YiAzrEw21vgZiDEKgdBwbOTWoQPqoAvgwDDLRCrkovqrHs4d1jX6U4owor3bXwjmBvbujp/hqfVcKOitTkgi4/JYtVN4GVQ== Received: from BN6PR22CA0051.namprd22.prod.outlook.com (2603:10b6:404:ca::13) by SJ0PR12MB5408.namprd12.prod.outlook.com (2603:10b6:a03:305::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.22; Tue, 12 Oct 2021 11:32:57 +0000 Received: from BN8NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:404:ca:cafe::db) by BN6PR22CA0051.outlook.office365.com (2603:10b6:404:ca::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Tue, 12 Oct 2021 11:32:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT022.mail.protection.outlook.com (10.13.176.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4587.18 via Frontend Transport; Tue, 12 Oct 2021 11:32:56 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 12 Oct 2021 11:32:53 +0000 From: Viacheslav Ovsiienko To: CC: , , , , , Date: Tue, 12 Oct 2021 14:32:32 +0300 Message-ID: <20211012113235.24975-3-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20211012113235.24975-1-viacheslavo@nvidia.com> References: <20210922180418.20663-1-viacheslavo@nvidia.com> <20211012113235.24975-1-viacheslavo@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 248d4113-aa64-499c-ebb2-08d98d7409bf X-MS-TrafficTypeDiagnostic: SJ0PR12MB5408: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p143M6/ZKzhkWLWmpd5hjomDJ+bOOnCV+/ZeFv3TAd4dydf/2iIxgNpq6chDA33l7rwhMn/PXtRsT01Waya43w1lXjAfNBGXES0HhSlAUima1PT0IHgo6X78GLlqKoFMbGtTJzjRoFFs/IYnpbWZ9nxBAuERuCZXm55BBdTuOGGYQa42JgCiGqSMG9oVOnK/V9iQjiTIJSUM155snc1Vy/vrMCXHyslppHIGiuEgoSphEgMqJOAxdaXdVdTjT9xD8wqufH+Ix4MHNIkPPBycjbXOxF40939zmo5nPmabiBAKbB0sk1JxTQg+smIaQ+8TVc/YBCOLob7NlLnIciAJOYF67ppO+x4AMekIl32VmrAGQ4ayl5+5OraFfX7y+uBNr3F/u4xseyM7jMpACwYpV0tFbQtbOGQ9oJeIpNoZ4vnH3vJDJuIWkdfLOHm6H7GfkKlSbfnGPTeMe3/6lcJaM+dcwTAxBRQfbbFaHk0qF6ZoCWhkGcaKs1hecde2/bqhP02utKzQKeek6xSblKcH208eAKklBhRJS1ZOMyusvVEmAZttbOuxj+q9dI6L18Zy8d7nmDwn+Q31VoU/0mtDO3t8QQgY+UE54xjNyhzf27B5uZrEv782asS/hJbyQEFiLdiqbrxNs7BaHfAsTX3sCP1h2vfu3MLgj8WVuxo0c7Kg1kkmwZAatxKDZhyp2kggz3rE+Mla2466hDnPnts8MA== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(426003)(86362001)(1076003)(6666004)(7696005)(6286002)(2616005)(5660300002)(316002)(83380400001)(8936002)(70586007)(26005)(36860700001)(70206006)(54906003)(2906002)(55016002)(186003)(8676002)(336012)(82310400003)(508600001)(4326008)(16526019)(47076005)(36756003)(6916009)(7636003)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2021 11:32:56.7122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 248d4113-aa64-499c-ebb2-08d98d7409bf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB5408 Subject: [dpdk-dev] [PATCH v4 2/5] ethdev: support flow elements with variable length 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 Sender: "dev" From: Gregory Etelson RTE flow API provides RAW item type for packet patterns of variable length. The RAW item structure has fixed size members that describe the variable pattern length and methods to process it. There is the new RTE Flow items with variable lengths coming - flex item). In order to handle this item (and potentially other new ones with variable pattern length) in RTE flow copy and conversion routines the helper function is introduced. Signed-off-by: Gregory Etelson Reviewed-by: Viacheslav Ovsiienko --- lib/ethdev/rte_flow.c | 83 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 8cb7a069c8..100983ca59 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -30,13 +30,67 @@ uint64_t rte_flow_dynf_metadata_mask; struct rte_flow_desc_data { const char *name; size_t size; + size_t (*desc_fn)(void *dst, const void *src); }; +/** + * + * @param buf + * Destination memory. + * @param data + * Source memory + * @param size + * Requested copy size + * @param desc + * rte_flow_desc_item - for flow item conversion. + * rte_flow_desc_action - for flow action conversion. + * @param type + * Offset into the desc param or negative value for private flow elements. + */ +static inline size_t +rte_flow_conv_copy(void *buf, const void *data, const size_t size, + const struct rte_flow_desc_data *desc, int type) +{ + /** + * allow PMD private flow item + * see 5d1bff8fe2 + * "ethdev: allow negative values in flow rule types" + */ + size_t sz = type >= 0 ? desc[type].size : sizeof(void *); + if (buf == NULL || data == NULL) + return 0; + rte_memcpy(buf, data, (size > sz ? sz : size)); + if (desc[type].desc_fn) + sz += desc[type].desc_fn(size > 0 ? buf : NULL, data); + return sz; +} + +static size_t +rte_flow_item_flex_conv(void *buf, const void *data) +{ + struct rte_flow_item_flex *dst = buf; + const struct rte_flow_item_flex *src = data; + if (buf) { + dst->pattern = rte_memcpy + ((void *)((uintptr_t)(dst + 1)), src->pattern, + src->length); + } + return src->length; +} + /** Generate flow_item[] entry. */ #define MK_FLOW_ITEM(t, s) \ [RTE_FLOW_ITEM_TYPE_ ## t] = { \ .name = # t, \ - .size = s, \ + .size = s, \ + .desc_fn = NULL,\ + } + +#define MK_FLOW_ITEM_FN(t, s, fn) \ + [RTE_FLOW_ITEM_TYPE_ ## t] = {\ + .name = # t, \ + .size = s, \ + .desc_fn = fn, \ } /** Information about known flow pattern items. */ @@ -100,6 +154,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = { MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)), MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)), MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)), + MK_FLOW_ITEM_FN(FLEX, sizeof(struct rte_flow_item_flex), + rte_flow_item_flex_conv), }; /** Generate flow_action[] entry. */ @@ -107,8 +163,17 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = { [RTE_FLOW_ACTION_TYPE_ ## t] = { \ .name = # t, \ .size = s, \ + .desc_fn = NULL,\ + } + +#define MK_FLOW_ACTION_FN(t, fn) \ + [RTE_FLOW_ACTION_TYPE_ ## t] = { \ + .name = # t, \ + .size = 0, \ + .desc_fn = fn,\ } + /** Information about known flow actions. */ static const struct rte_flow_desc_data rte_flow_desc_action[] = { MK_FLOW_ACTION(END, 0), @@ -527,12 +592,8 @@ rte_flow_conv_item_spec(void *buf, const size_t size, } break; default: - /** - * allow PMD private flow item - */ - off = (int)item->type >= 0 ? - rte_flow_desc_item[item->type].size : sizeof(void *); - rte_memcpy(buf, data, (size > off ? off : size)); + off = rte_flow_conv_copy(buf, data, size, + rte_flow_desc_item, item->type); break; } return off; @@ -634,12 +695,8 @@ rte_flow_conv_action_conf(void *buf, const size_t size, } break; default: - /** - * allow PMD private flow action - */ - off = (int)action->type >= 0 ? - rte_flow_desc_action[action->type].size : sizeof(void *); - rte_memcpy(buf, action->conf, (size > off ? off : size)); + off = rte_flow_conv_copy(buf, action->conf, size, + rte_flow_desc_action, action->type); break; } return off; -- 2.18.1