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 CBB35433FD; Tue, 5 Dec 2023 03:56:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C2B2842DEA; Tue, 5 Dec 2023 03:55:33 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2116.outbound.protection.outlook.com [40.107.237.116]) by mails.dpdk.org (Postfix) with ESMTP id 9B19342DD1 for ; Tue, 5 Dec 2023 03:55:31 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h82sDW/IxXZjweLHcrkOTUd+GyIYuorxAtFLtNEA2aXtkATYjdmk+1FqGx76HDC1xgkkwfROdMCM8sKJdReRY9xls+zdpm+d5hNKR11FWNQ2dk16A4rSg3tQmQgzSOoo4hOBNL/74Jz6x8zWvC2wQrlDIMFGq9grrAhm4qeg4HWVrTp3BstH9Rvymc12BP0jlF6EJ3U4PgkDnEOfi0k/ktOUZVyy9xj/JK1jQKAJkvRyLWoVpBeGckkYKax63O1mRM169kJifdaYjLoTSYOK/7EjDh+fSsjkohbKqTNKVcdlE3+qemG3kqz/JkkBJSpAfuLQbtROZCrLY1kgnX/Qdw== 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=Qd3rnXW8jmdME6/9EPZSCoWWSZJ2fH7oRNK/1moBj9E=; b=gbyqcv+JR1aXkb/NN3mZ8WOKbb1cuiPERZXztDrtpg/PfL2ryWaXIzjwaZ4Ln8L63yi24EL1tm6GeXcM4M1C8iwcO+T2ijW5wID2t1xwc2Mlom3LSXYt/IlaDKy/D+eKnNsDTWWHZqe0Tt2sx3zy4H8o/GQezBd7/B4BRYFc7wXB1xoyfPqZCqq3dFf/GXGdATIvEIr0jFeTauHc+/KCS1NoVH2RpACqKu/+bdkm5lglu1YirRpavounZKY4iUTJPWCrPPamzLqJDQJ8TwTPswP/rHIhcbHNnS0mKsX+o840+KzzhJI0T7+MS7hNRc9CliEJyodbV6jxKQgxj+0UJQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qd3rnXW8jmdME6/9EPZSCoWWSZJ2fH7oRNK/1moBj9E=; b=pHFspgWTa7BUAJMa8ZVtJlzk1jL4wQAAf7icrKThH4NiTX8IY7BJVG1N/lR1BkAAWxID4qnHGr2bxAxnx6+DZlSpM+zV8xAESBk7AeAkQhoTK4L8SOdJyJwISa6+c2C40Xxp0s4Sl+NAeR+XH4cjIb/vy/gywS2s4Cvk8s8EuSg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) by BY5PR13MB4439.namprd13.prod.outlook.com (2603:10b6:a03:1dd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.34; Tue, 5 Dec 2023 02:55:27 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::45b3:d83c:cff2:4a1b]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::45b3:d83c:cff2:4a1b%6]) with mapi id 15.20.7046.033; Tue, 5 Dec 2023 02:55:26 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Chaoyong He , Long Wu , Peng Zhang Subject: [PATCH v2 05/11] net/nfp: support Ethernet flow item Date: Tue, 5 Dec 2023 10:54:51 +0800 Message-Id: <20231205025457.1067372-6-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231205025457.1067372-1-chaoyong.he@corigine.com> References: <20231103062606.2632012-1-chaoyong.he@corigine.com> <20231205025457.1067372-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR03CA0214.namprd03.prod.outlook.com (2603:10b6:a03:39f::9) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|BY5PR13MB4439:EE_ X-MS-Office365-Filtering-Correlation-Id: 977753b5-ab8f-41c1-0fe9-08dbf53da223 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MVk2RydNRYivsVyGtXClrV3cVp/ac3wX0yy+RHnyYcIAlJjJW/nAfD4RS6TcaoGE11TdBHazpP2BwQ9ncjharYBUf1pTwLYOubzs0wiAsQlq7zVIBZwaKlkzOTXS2K9VORKmA1IlT8/DYyaggLiROQVsuQgUkHI+yzlVlbLvqN/9epNr1AwKj06bFB/u+Hsx9BWQaf0OWLc03PU3hFQnubYmBPiFoI6bFuw7pCHRYXDsvZDO1l4E7Bf6I1Rv13qZTK/gkv1N4+eUwiN5277JLAouG3aigEBlWNIrDOxzdisI/6P2GSNVSQvdx0U6GrVQoJdnG94ll5Iyf0rgEJL7+2Y5qwJzFi0sZjOUXUdyiKOfpyA++B8sse0jtZT1hGqON9cJ28aTZyFmOWipLVp5ypJJslaQZTCjmZYOXe8J5YDY49KU147KA/8ROJ5DnFgOTcGK932k3w6m5JH9WWMK0d+C+T6y/uEFVvJ48Y66qTVfc4f5+1vLWIrmIdLE3CdvcoIPbQ19ANwbw7BYvIF7mMPM6E9iE1Qx9QCfDi1Rl2sfFDwh6t9xIJOOTMtIVk3VMvV2ymCQNDofMMAT9lbj0yBg4GsFYD4S1mkXmSsFKQrQLMf5gK8pO3OP6GQ0GsO7A8opmlp5FKDR+9KWDj7vWv5dI5hIsERpO980A0L9t8A= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR13MB5545.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(136003)(396003)(346002)(376002)(39830400003)(230922051799003)(1800799012)(451199024)(186009)(64100799003)(6486002)(83380400001)(478600001)(6512007)(52116002)(2616005)(6506007)(26005)(6666004)(1076003)(107886003)(316002)(66476007)(54906003)(6916009)(66556008)(66946007)(86362001)(41300700001)(36756003)(8676002)(4326008)(8936002)(38350700005)(2906002)(44832011)(5660300002)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?GCkBa1k86nVmHN8F6d/AG36BuyEELLIz52oUt3SA60A3LXx8LeSweaYDaydC?= =?us-ascii?Q?kCMxuaTKhXKHZMAo10BoMUo4VZoaxMUkSoZt1f8MMolPjICd+XbhsFYG4Mjl?= =?us-ascii?Q?wusnubRN1jPF0JzTu40zRNUeiUvbkITKPdhJXlm6XHzJIShg3+MA1dgTNpip?= =?us-ascii?Q?6LdrNVkiXkLrggXR2GjNSeZOw/LLy0fKnLbmoYKBIP4N6otxHj+AyCuvhevY?= =?us-ascii?Q?JNtmPqPrOkImaAM+WXHMHRU5X0oE1+O7vZ5iKYAzvGTgjwnOWLB+Z8ajUqPg?= =?us-ascii?Q?U1K5yUncb45rCkQXPcRbZP3HQ+fTY29s4PErVQRATk/onJp1+7XUmLWfLoT6?= =?us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eD7mta+MBWcbabLqT+eO?= =?us-ascii?Q?1iOe4bGIuRPAvcHXFCeEL78StVokguePo4rhO4EsR19oybehorIfJ/v/3Z2C?= =?us-ascii?Q?pjs3XGuZTDx3xMw5cw6vJUqAEpa4IoF6G6scpIlEs1LgzNYCHkEaNEAchhW6?= =?us-ascii?Q?RI0sQgh4dyYFiNmJWD/iGR0c0WNrbVSOuA6Ct0mS7ABIV1sMFMnbUYw2Du14?= =?us-ascii?Q?YxqGlslZRe9eSj2hJLtU+FGIlFwQmgYuV+5CpF5j8RqMxTnq/FgOxrejdsGs?= =?us-ascii?Q?00940GEg6dg40CWsW5NSPkqgY1u8Ak++MDAgDS906M3fTN2MvjpkDW74txWw?= =?us-ascii?Q?FOmYzCeASeVUs4wwu5t3rBaTgg/2+aucRP+2eUakDYekgdDN55NHuNKQWAnp?= =?us-ascii?Q?0g=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 977753b5-ab8f-41c1-0fe9-08dbf53da223 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2023 02:55:26.8018 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fECGX8yy/YguyRRb0J0Oa7A3GX2QIWCIDKcT7p3Apu5JBwnEe0SzLELcbRkxBHsG7Vb75ebSrdZQTFhugB1EsDR4txrLX9XweF5rpKH5nPM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR13MB4439 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 Add the corresponding data structure and logics, to support the offload of ethernet item. Signed-off-by: Chaoyong He Reviewed-by: Long Wu Reviewed-by: Peng Zhang --- drivers/net/nfp/nfp_net_cmsg.h | 13 +++ drivers/net/nfp/nfp_net_flow.c | 169 +++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/drivers/net/nfp/nfp_net_cmsg.h b/drivers/net/nfp/nfp_net_cmsg.h index b526feaff2..a95f4ef831 100644 --- a/drivers/net/nfp/nfp_net_cmsg.h +++ b/drivers/net/nfp/nfp_net_cmsg.h @@ -8,6 +8,19 @@ #include "nfp_net_common.h" +/** + * Match EtherType data + * Bit 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 + * -----\ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * Word +-------------------------------+-------------------------------+ + * 0 | | Ethtype | + * +-----------------+-------------+-------------------------------+ + */ +struct nfp_net_cmsg_match_eth { + uint16_t ether_type; + uint16_t spare; +}; + #define NFP_NET_CMSG_ACTION_DROP (0x1 << 0) /* Drop action */ #define NFP_NET_CMSG_ACTION_QUEUE (0x1 << 1) /* Queue action */ #define NFP_NET_CMSG_ACTION_MARK (0x1 << 2) /* Mark action */ diff --git a/drivers/net/nfp/nfp_net_flow.c b/drivers/net/nfp/nfp_net_flow.c index 658bdff1f9..5b6c8553d8 100644 --- a/drivers/net/nfp/nfp_net_flow.c +++ b/drivers/net/nfp/nfp_net_flow.c @@ -13,6 +13,28 @@ #include "nfp_logs.h" #include "nfp_net_cmsg.h" +/* Static initializer for a list of subsequent item types */ +#define NEXT_ITEM(...) \ + ((const enum rte_flow_item_type []){ \ + __VA_ARGS__, RTE_FLOW_ITEM_TYPE_END, \ + }) + +/* Process structure associated with a flow item */ +struct nfp_net_flow_item_proc { + /* Bit-mask for fields supported by this PMD. */ + const void *mask_support; + /* Bit-mask to use when @p item->mask is not provided. */ + const void *mask_default; + /* Size in bytes for @p mask_support and @p mask_default. */ + const uint32_t mask_sz; + /* Merge a pattern item into a flow rule handle. */ + int (*merge)(struct rte_flow *nfp_flow, + const struct rte_flow_item *item, + const struct nfp_net_flow_item_proc *proc); + /* List of possible subsequent items. */ + const enum rte_flow_item_type *const next_item; +}; + static int nfp_net_flow_table_add(struct nfp_net_priv *priv, struct rte_flow *nfp_flow) @@ -162,6 +184,10 @@ nfp_net_flow_calculate_items(const struct rte_flow_item items[], for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) { switch (item->type) { + case RTE_FLOW_ITEM_TYPE_ETH: + PMD_DRV_LOG(DEBUG, "RTE_FLOW_ITEM_TYPE_ETH detected"); + *match_len = sizeof(struct nfp_net_cmsg_match_eth); + return 0; default: PMD_DRV_LOG(ERR, "Can't calculate match length"); *match_len = 0; @@ -172,6 +198,143 @@ nfp_net_flow_calculate_items(const struct rte_flow_item items[], return -EINVAL; } +static int +nfp_net_flow_merge_eth(__rte_unused struct rte_flow *nfp_flow, + const struct rte_flow_item *item, + __rte_unused const struct nfp_net_flow_item_proc *proc) +{ + struct nfp_net_cmsg_match_eth *eth; + const struct rte_flow_item_eth *spec; + + spec = item->spec; + if (spec == NULL) { + PMD_DRV_LOG(ERR, "NFP flow merge eth: no item->spec!"); + return -EINVAL; + } + + nfp_flow->payload.cmsg_type = NFP_NET_CFG_MBOX_CMD_FS_ADD_ETHTYPE; + + eth = (struct nfp_net_cmsg_match_eth *)nfp_flow->payload.match_data; + eth->ether_type = rte_be_to_cpu_16(spec->type); + + return 0; +} + +/* Graph of supported items and associated process function */ +static const struct nfp_net_flow_item_proc nfp_net_flow_item_proc_list[] = { + [RTE_FLOW_ITEM_TYPE_END] = { + .next_item = NEXT_ITEM(RTE_FLOW_ITEM_TYPE_ETH), + }, + [RTE_FLOW_ITEM_TYPE_ETH] = { + .merge = nfp_net_flow_merge_eth, + }, +}; + +static int +nfp_net_flow_item_check(const struct rte_flow_item *item, + const struct nfp_net_flow_item_proc *proc) +{ + uint32_t i; + int ret = 0; + const uint8_t *mask; + + /* item->last and item->mask cannot exist without item->spec. */ + if (item->spec == NULL) { + if (item->mask || item->last) { + PMD_DRV_LOG(ERR, "'mask' or 'last' field provided" + " without a corresponding 'spec'."); + return -EINVAL; + } + + /* No spec, no mask, no problem. */ + return 0; + } + + mask = (item->mask != NULL) ? item->mask : proc->mask_default; + + /* + * Single-pass check to make sure that: + * - Mask is supported, no bits are set outside proc->mask_support. + * - Both item->spec and item->last are included in mask. + */ + for (i = 0; i != proc->mask_sz; ++i) { + if (mask[i] == 0) + continue; + + if ((mask[i] | ((const uint8_t *)proc->mask_support)[i]) != + ((const uint8_t *)proc->mask_support)[i]) { + PMD_DRV_LOG(ERR, "Unsupported field found in 'mask'."); + ret = -EINVAL; + break; + } + + if (item->last != NULL && + (((const uint8_t *)item->spec)[i] & mask[i]) != + (((const uint8_t *)item->last)[i] & mask[i])) { + PMD_DRV_LOG(ERR, "Range between 'spec' and 'last'" + " is larger than 'mask'."); + ret = -ERANGE; + break; + } + } + + return ret; +} + +static int +nfp_net_flow_compile_items(const struct rte_flow_item items[], + struct rte_flow *nfp_flow) +{ + uint32_t i; + int ret = 0; + const struct rte_flow_item *item; + const struct nfp_net_flow_item_proc *proc_list; + + proc_list = nfp_net_flow_item_proc_list; + + for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) { + const struct nfp_net_flow_item_proc *proc = NULL; + + for (i = 0; (proc_list->next_item != NULL) && + (proc_list->next_item[i] != RTE_FLOW_ITEM_TYPE_END); ++i) { + if (proc_list->next_item[i] == item->type) { + proc = &nfp_net_flow_item_proc_list[item->type]; + break; + } + } + + if (proc == NULL) { + PMD_DRV_LOG(ERR, "No next item provided for %d", item->type); + ret = -ENOTSUP; + break; + } + + /* Perform basic sanity checks */ + ret = nfp_net_flow_item_check(item, proc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "NFP flow item %d check failed", item->type); + ret = -EINVAL; + break; + } + + if (proc->merge == NULL) { + PMD_DRV_LOG(ERR, "NFP flow item %d no proc function", item->type); + ret = -ENOTSUP; + break; + } + + ret = proc->merge(nfp_flow, item, proc); + if (ret != 0) { + PMD_DRV_LOG(ERR, "NFP flow item %d exact merge failed", item->type); + break; + } + + proc_list = proc; + } + + return ret; +} + static void nfp_net_flow_process_priority(__rte_unused struct rte_flow *nfp_flow, uint32_t match_len) @@ -218,6 +381,12 @@ nfp_net_flow_setup(struct rte_eth_dev *dev, return NULL; } + ret = nfp_net_flow_compile_items(items, nfp_flow); + if (ret != 0) { + PMD_DRV_LOG(ERR, "NFP flow item process failed."); + goto free_flow; + } + /* Calculate and store the hash_key for later use */ hash_data = nfp_flow->payload.match_data; nfp_flow->hash_key = rte_jhash(hash_data, match_len + action_len, -- 2.39.1