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 6FE0CA0560; Tue, 18 Oct 2022 13:28:14 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 667BC42684; Tue, 18 Oct 2022 13:27:45 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2100.outbound.protection.outlook.com [40.107.236.100]) by mails.dpdk.org (Postfix) with ESMTP id 32CED4281A for ; Tue, 18 Oct 2022 13:27:44 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lYP8afsFILgzNJmPtp5yWuRhmIO1sPHr319++FL5IgY6CYx5IYgvAjY8L3dy9CmFw0BvfFqFGWb1GdAfjwlxDl6YhXxfhaw9NIAbjdljOQfNOhU0gGUqngPmFiAnukYvIGFuWMMSOL/bv7UmAQv10Dtd+cBMGAY/nN4TN+eaNCVVRXmGZCJIRwJuSPlNeutNwWrQnxKjAWs6/B2dpUoKntSHlT3GWUgfhOUDjHzfUQps2I7e+6OVxr2sreYv5TRFmTHKS2PKL8QGXNzRZRN8EdOeufWfcRxkfqHNNtQwm/PoDLnsAdAQfTQj8T1aw2IcjW6jLc4eiyLGbm10t6FkoA== 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=/zbmrLQ9/tz9AhPO5to2Ao08Ey+cVY5a4aHdAmG5HdM=; b=k76J0JXOsP72JsMCztTA2FBAWIaxzsjXuTn8NH8chooknuqACMoRwOM7/8Ee+wxfq7lzaC1iq8Asxysl0yL2rfIbmE7bMOy1afWps8dw8bgLjTgDWlAPsEsK6iRA2SW7HrCrmhsgDn0nsqTQTAJmhp4wIb/t+ZsHdxNvaOq7j3DPdXNmClTdOk1tuRqQ5une1oDh/jHlgIgUybIzizNNthPVHv3KrNOe5+8pqo1iXQBz97BX/3LkicWVJpqhQMWDghH2ZoSnEY00XHmEN4uA6VvxLyixbkfMps2aYb3MgHY8FPifNguwwpW6337+PGBn9tGo5ASYqfWgxw3LKQ2t0A== 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=/zbmrLQ9/tz9AhPO5to2Ao08Ey+cVY5a4aHdAmG5HdM=; b=mdgDqyHM2sg2Zprn5mSZFPETUpp06LfyHKofMSdr3//XdhjSAekDVnZZGIYsfora+8u/6UX3jSwh8SHfomJYN6Y8bZ3zOtfcIpgdwqsBKjSU4yWlIyT/w/qUgc1LLeQkXBWUYaQCwz9JPnuMJwLsCbDmze5MdL3FM9l3QXfkgMo= 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 CO3PR13MB5686.namprd13.prod.outlook.com (2603:10b6:303:179::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.16; Tue, 18 Oct 2022 11:27:42 +0000 Received: from SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7c26:1a0b:2825:6f4b]) by SJ0PR13MB5545.namprd13.prod.outlook.com ([fe80::7c26:1a0b:2825:6f4b%4]) with mapi id 15.20.5723.014; Tue, 18 Oct 2022 11:27:42 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, niklas.soderlund@corigine.com, Chaoyong He Subject: [PATCH v4 05/25] net/nfp: support basic flow items Date: Tue, 18 Oct 2022 19:26:54 +0800 Message-Id: <1666092434-10357-6-git-send-email-chaoyong.he@corigine.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666092434-10357-1-git-send-email-chaoyong.he@corigine.com> References: <1666092434-10357-1-git-send-email-chaoyong.he@corigine.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SG2PR02CA0052.apcprd02.prod.outlook.com (2603:1096:4:54::16) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|CO3PR13MB5686:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c737293-0433-4be0-1e9f-08dab0fbc5b6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kv5Y/ZjLWR7RA9Uo1fxNZtWZhQ8mBwMhdSkB4NlR9KorpCSV1QMOHdj+nnjtzeBV2NdKvafxDrff9VYfzCQ9urqhqkBGqywrpza/yF7VgR5JrYMqrTWzB/3zOVRwFhh1fAUSgoJmPiTCtsWo/Em7sqW9DW9diQF/svxR9FtuqdNNkL/xN5rclWUOM3krheUOsyGKNvGgbHs3l9w/l00sevG23ir6/0CI92VxuVnxBbKDN9fzBlWi3R/HdIuUun1MhlLJJ4VwdYpJq9aOqBXmSP1gphDfYwfrh3cQ/xKAo/DkULEKp8TPmUaveL1wE04oq35F26SM720YgHsKMltNoL3eQEO4rCwhKzT6fKkYUKhuii6KBxew/0fqKu6SEaTI8JwB4Q2MIxWsP6XlW4dRecC1eoKHKGL6jn6UpCY+llCtfVRdczclLktoyG4jByfHE/Msyg7Hh39S4viutvTx3uK5TlOGrnrtTB7xfC4UXN8H+Itb0vnIVpn1Zgj2xC3ygvfRu6dUwVGFMfxw/0L4KT86wnPYMn9cXTC/pPU5HIBB1vtXzBhhp0MM9UrfCyMQFxB3LVgXDdDqYNGQhco4IlJ9HjsdaOClwn3aNR8OOMyQnMrP58r2rWwF/ij/e8gXGEsUheA9cAR60a/OH9axp1dcnvZF2yQZhOAGWfq6Wv8SlxMg2kTgY02zgiUdxVv4fK640PNMC4gXnEWJXBuQtNtz6YXJQ8xAUVP40LdaXyWOBPfGzloekKQYZhRWn8AsVT1utjSenM+kRv/Xi1uKffH6TGPIQd7r+/y4GGIYBFNwuN9RrjAsP4W4J5Di7S9L 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:(13230022)(4636009)(346002)(366004)(39840400004)(396003)(136003)(376002)(451199015)(38350700002)(38100700002)(2906002)(66574015)(41300700001)(316002)(66946007)(30864003)(66556008)(66476007)(83380400001)(4326008)(8676002)(6916009)(86362001)(44832011)(2616005)(8936002)(186003)(36756003)(5660300002)(6506007)(107886003)(6666004)(6486002)(478600001)(26005)(6512007)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SGliTXRiaUVZTUVBc0k1eTNWNGpDckp3NTduNlByT3FFUHhrUDNkOEhaTUtv?= =?utf-8?B?a0dhdjhXeisycXFrWFZXYnh4V1lpd3FuUFp4VElOUHNVdlBaYTdjTlVuSDF1?= =?utf-8?B?TFMveW5YbWtPb1NUMGsyYmlCb1dZNWx6ekFvTWJ4Q01aVnF6cXhBRkdkUVh6?= =?utf-8?B?d0VuVWJ6Mnh1SEJzSFFXUi9TdlV4Q2t2bFRuVnNVMU9qRlZWR3doR0EyZ3o4?= =?utf-8?B?U1RJUEtpdm80SjgxS2E3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POWsrNGRNRTJlYUkvMHNNQkZ4U1pzWGIvQnRITUhvOWlySjk3Q2RJK0o2?= =?utf-8?B?YVV3UDZrYWFKZUxEQWRiaXUwOXllZ09KS0Nqa3F4eWVMcWJ2eTk5amZxdHdj?= =?utf-8?B?Tmc9PQ==?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c737293-0433-4be0-1e9f-08dab0fbc5b6 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2022 11:27:42.7610 (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: 85h/VVz6zNLYi4u+B7pxUoS1vuxjYjTzWG6V5evZjEGJzlKijHFN6KTDU5B5PnyEAH6KoNxodkp8BuRfrP6ZPiJXNbmhG6lOixLS3sBVU0k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO3PR13MB5686 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 offload support of very basic items: ethernet and port id. Signed-off-by: Chaoyong He Reviewed-by: Niklas Söderlund --- doc/guides/nics/features/nfp.ini | 4 + doc/guides/rel_notes/release_22_11.rst | 2 + drivers/net/nfp/flower/nfp_flower_cmsg.h | 20 +++ drivers/net/nfp/nfp_flow.c | 252 ++++++++++++++++++++++++++++++- 4 files changed, 277 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/features/nfp.ini b/doc/guides/nics/features/nfp.ini index f7a0362..4460cf0 100644 --- a/doc/guides/nics/features/nfp.ini +++ b/doc/guides/nics/features/nfp.ini @@ -25,3 +25,7 @@ Linux = Y Multiprocess aware = Y x86-64 = Y Usage doc = Y + +[rte_flow items] +eth = Y +port_id = Y diff --git a/doc/guides/rel_notes/release_22_11.rst b/doc/guides/rel_notes/release_22_11.rst index a3700bb..6d421a2 100644 --- a/doc/guides/rel_notes/release_22_11.rst +++ b/doc/guides/rel_notes/release_22_11.rst @@ -163,6 +163,8 @@ New Features * Added the control message interactive channels between PMD and firmware. * Added the support of representor port. + Add the support of rte_flow pattern items. + * **Updated NXP dpaa2 driver.** * Added support for flow action REPRESENTED_PORT. diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h index 6045bb0..75a3b91 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.h +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h @@ -233,6 +233,26 @@ struct nfp_flower_in_port { rte_be32_t in_port; }; +/* + * L2 details (4W/16B) + * 3 2 1 + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | mac_addr_dst, 31 - 0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | mac_addr_dst, 47 - 32 | mac_addr_src, 15 - 0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | mac_addr_src, 47 - 16 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | mpls outermost label | TC |B| reserved |q| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +struct nfp_flower_mac_mpls { + uint8_t mac_dst[6]; + uint8_t mac_src[6]; + rte_be32_t mpls_lse; +}; + int nfp_flower_cmsg_mac_repr(struct nfp_app_fw_flower *app_fw_flower); int nfp_flower_cmsg_repr_reify(struct nfp_app_fw_flower *app_fw_flower, struct nfp_flower_representor *repr); diff --git a/drivers/net/nfp/nfp_flow.c b/drivers/net/nfp/nfp_flow.c index 64ebffe..56cbfb7 100644 --- a/drivers/net/nfp/nfp_flow.c +++ b/drivers/net/nfp/nfp_flow.c @@ -19,6 +19,30 @@ #include "nfpcore/nfp_mip.h" #include "nfpcore/nfp_rtsym.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_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 unsigned int mask_sz; + /* Merge a pattern item into a flow rule handle. */ + int (*merge)(struct rte_flow *nfp_flow, + char **mbuf_off, + const struct rte_flow_item *item, + const struct nfp_flow_item_proc *proc, + bool is_mask); + /* List of possible subsequent items. */ + const enum rte_flow_item_type *const next_item; +}; + struct nfp_mask_id_entry { uint32_t hash_key; uint32_t ref_cnt; @@ -476,12 +500,36 @@ struct nfp_mask_id_entry { static int nfp_flow_key_layers_calculate_items(const struct rte_flow_item items[], - __rte_unused struct nfp_fl_key_ls *key_ls) + struct nfp_fl_key_ls *key_ls) { + struct rte_eth_dev *ethdev; const struct rte_flow_item *item; + struct nfp_flower_representor *representor; + const struct rte_flow_item_port_id *port_id; 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"); + /* + * eth is set with no specific params. + * NFP does not need this. + */ + if (item->spec == NULL) + continue; + key_ls->key_layer |= NFP_FLOWER_LAYER_MAC; + key_ls->key_size += sizeof(struct nfp_flower_mac_mpls); + break; + case RTE_FLOW_ITEM_TYPE_PORT_ID: + PMD_DRV_LOG(DEBUG, "RTE_FLOW_ITEM_TYPE_PORT_ID detected"); + port_id = item->spec; + if (port_id->id >= RTE_MAX_ETHPORTS) + return -ERANGE; + ethdev = &rte_eth_devices[port_id->id]; + representor = (struct nfp_flower_representor *) + ethdev->data->dev_private; + key_ls->port = rte_cpu_to_be_32(representor->port_id); + break; default: PMD_DRV_LOG(ERR, "Item type %d not supported.", item->type); return -ENOTSUP; @@ -541,6 +589,202 @@ struct nfp_mask_id_entry { return ret; } +static int +nfp_flow_merge_eth(__rte_unused struct rte_flow *nfp_flow, + char **mbuf_off, + const struct rte_flow_item *item, + const struct nfp_flow_item_proc *proc, + bool is_mask) +{ + struct nfp_flower_mac_mpls *eth; + const struct rte_flow_item_eth *spec; + const struct rte_flow_item_eth *mask; + + spec = item->spec; + if (spec == NULL) { + PMD_DRV_LOG(DEBUG, "nfp flow merge eth: no item->spec!"); + goto eth_end; + } + + mask = item->mask ? item->mask : proc->mask_default; + eth = (void *)*mbuf_off; + + if (is_mask) { + memcpy(eth->mac_src, mask->src.addr_bytes, RTE_ETHER_ADDR_LEN); + memcpy(eth->mac_dst, mask->dst.addr_bytes, RTE_ETHER_ADDR_LEN); + } else { + memcpy(eth->mac_src, spec->src.addr_bytes, RTE_ETHER_ADDR_LEN); + memcpy(eth->mac_dst, spec->dst.addr_bytes, RTE_ETHER_ADDR_LEN); + } + + eth->mpls_lse = 0; + +eth_end: + *mbuf_off += sizeof(struct nfp_flower_mac_mpls); + + return 0; +} + +/* Graph of supported items and associated process function */ +static const struct nfp_flow_item_proc nfp_flow_item_proc_list[] = { + [RTE_FLOW_ITEM_TYPE_END] = { + .next_item = NEXT_ITEM(RTE_FLOW_ITEM_TYPE_ETH), + }, + [RTE_FLOW_ITEM_TYPE_ETH] = { + .mask_support = &(const struct rte_flow_item_eth){ + .hdr = { + .dst_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff", + .src_addr.addr_bytes = "\xff\xff\xff\xff\xff\xff", + .ether_type = RTE_BE16(0xffff), + }, + .has_vlan = 1, + }, + .mask_default = &rte_flow_item_eth_mask, + .mask_sz = sizeof(struct rte_flow_item_eth), + .merge = nfp_flow_merge_eth, + }, +}; + +static int +nfp_flow_item_check(const struct rte_flow_item *item, + const struct nfp_flow_item_proc *proc) +{ + int ret = 0; + unsigned int i; + 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 ? + (const uint8_t *)item->mask : + (const uint8_t *)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 && (((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_flow_compile_item_proc(const struct rte_flow_item items[], + struct rte_flow *nfp_flow, + char **mbuf_off_exact, + char **mbuf_off_mask) +{ + int i; + int ret = 0; + const struct rte_flow_item *item; + const struct nfp_flow_item_proc *proc_list; + + proc_list = nfp_flow_item_proc_list; + for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) { + const struct nfp_flow_item_proc *proc = NULL; + + for (i = 0; proc_list->next_item && proc_list->next_item[i]; ++i) { + if (proc_list->next_item[i] == item->type) { + proc = &nfp_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_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, mbuf_off_exact, item, + proc, false); + if (ret != 0) { + PMD_DRV_LOG(ERR, "nfp flow item %d exact merge failed", item->type); + break; + } + + ret = proc->merge(nfp_flow, mbuf_off_mask, item, + proc, true); + if (ret != 0) { + PMD_DRV_LOG(ERR, "nfp flow item %d mask merge failed", item->type); + break; + } + + proc_list = proc; + } + + return ret; +} + +static int +nfp_flow_compile_items(__rte_unused struct nfp_flower_representor *representor, + const struct rte_flow_item items[], + struct rte_flow *nfp_flow) +{ + int ret; + char *mbuf_off_mask; + char *mbuf_off_exact; + + mbuf_off_exact = nfp_flow->payload.unmasked_data + + sizeof(struct nfp_flower_meta_tci) + + sizeof(struct nfp_flower_in_port); + mbuf_off_mask = nfp_flow->payload.mask_data + + sizeof(struct nfp_flower_meta_tci) + + sizeof(struct nfp_flower_in_port); + + /* Go over items */ + ret = nfp_flow_compile_item_proc(items, nfp_flow, + &mbuf_off_exact, &mbuf_off_mask); + if (ret != 0) { + PMD_DRV_LOG(ERR, "nfp flow item compile failed."); + return -EINVAL; + } + + return 0; +} + static struct rte_flow * nfp_flow_process(struct nfp_flower_representor *representor, const struct rte_flow_item items[], @@ -583,6 +827,12 @@ struct nfp_mask_id_entry { nfp_flow_compile_metadata(priv, nfp_flow, &key_layer, stats_ctx); + ret = nfp_flow_compile_items(representor, items, nfp_flow); + if (ret != 0) { + PMD_DRV_LOG(ERR, "nfp flow item process failed."); + goto free_flow; + } + nfp_flow_meta = nfp_flow->payload.meta; mask_data = nfp_flow->payload.mask_data; mask_len = key_layer.key_size; -- 1.8.3.1