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 BBF5343795; Tue, 26 Dec 2023 08:30:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D1CC040DDA; Tue, 26 Dec 2023 08:29:14 +0100 (CET) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2138.outbound.protection.outlook.com [40.107.212.138]) by mails.dpdk.org (Postfix) with ESMTP id C91A440E2D for ; Tue, 26 Dec 2023 08:29:12 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TcifrqfDiCrZZhHhYtGHk0lFgZJfDGokc2m5hKwOcV6ZpfHKaNaNHsJfa2xbH1nVPMp60mW0IBgih1zJb3T8BW/sKqYOXFVRqVblOmA+SDU+ImpEj22HA419NAHzmSMRMXSO/YgeKuNKjMJCLBEM5RvF26QV3pPQ9X2LyGk6e3VtIkySmFO3m087qcDxP9hs8ivOh+mH+5tECSHESwH5VJbi82iikqAqyoGO4AXUQvyeD93s3sYTQ6BvsNYgXnbFaF7u3teo+iq8+nLHbcMD9YSzNV56WKnRJnP8WZfQyGjUPrL11b4+nmLe035Bzg6FEugMbDNa7NQ0/Bn+ofj9GQ== 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=Kz6AxSRyxYAWiz4Z80tcP47HAyDQt9mpNsuwFgYiPfs=; b=WfZ141eMqbmy4ohdFMtijC2b0Ho97XrhuY9b04DuBoy3SOSZFyPOBjbdv9XgJn1IbnTd4aKGR7TV0gTYstt+mXtUEpOROE9XYh5hkoXpbQO3gP+J2FHkL4cpGIuQK6npRbnkAB6i+N65WykDKTeZEWY9qdsEIfzd7GAFz4IzXb2rTfxdmUmuEoCgF14sCQr0HZRNjFSKLuknLB9+VZq27vpT828ZzsLnlorcJlc/V/XoWutllmeKq2EzmsrbRFM4Nu9fFy2qE0OGsbESNulZkAbnKNEjo/vIrP9CbQWGXHJx+JJ5y2lVyCdx49Jyjy7PRENTwYLxA4yHJhHb6FTY7A== 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=Kz6AxSRyxYAWiz4Z80tcP47HAyDQt9mpNsuwFgYiPfs=; b=MfZRY/MEL4+A1dWQ/3EWufyJoaWJ+sWKdpprvEfqB8yE7oW7ScsqpeFhTmocuO/aO1bYxj/ruMXtofJpe/b4il99w/baEvcZ8M7ATaQ51cvRAehZHiC2EMPaovvQAnoW6Ded90k295hlUShCYDI43byf0r+X3qUIbucbRiojbg4= 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 CH3PR13MB6506.namprd13.prod.outlook.com (2603:10b6:610:1a3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.27; Tue, 26 Dec 2023 07:29:11 +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.7113.027; Tue, 26 Dec 2023 07:29:11 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Long Wu , Peng Zhang , Chaoyong He Subject: [PATCH v6 14/14] net/nfp: support offloading bond-flow Date: Tue, 26 Dec 2023 15:28:24 +0800 Message-Id: <20231226072824.3163121-15-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231226072824.3163121-1-chaoyong.he@corigine.com> References: <20231226023745.3144143-1-chaoyong.he@corigine.com> <20231226072824.3163121-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR03CA0239.namprd03.prod.outlook.com (2603:10b6:a03:39f::34) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|CH3PR13MB6506:EE_ X-MS-Office365-Filtering-Correlation-Id: 82ff253d-e347-4ddd-7592-08dc05e45a67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kB4u27JNh1RLVZPQhe+r9rJ7oazfEuTmZpikb/WYhRU+xwdS0In4KFsOS34rFqxi5gB50JkTcXxaElxU3RvsLx68khPr2K+qO4f2cbJhT18PSR/YsMrOFLihmY46vMaAsQDxIuyNWB7coRMKziDY1QPAZ2Qwnhu5t0iVqmkvN06OCwnIiYBLFcHhznkzfYPBr2p8XuAGHvBPsjKtaRkIXQcgZsRru+b238pys1qvf5rqIt7aCcGBYfvonAgBDQRIywfO0wOAs2WPgbWZS+zQx0YwoQNl0vurQ+vXwvqhQ7Eiw3pHp+EY/dPkiNB08T8h8YU3cc9CyOM4hUvn/Xxz+5DIsRW/VEpsUkuMzbFBQwlIJh+SvHKjl7H3jMrZFCBriC/zC+GSQt3xDKdniIagE3kBqKxzuNTbrpE9O/A8ZoIzYa2b1NGdAQAb+RnkotCdANerUbgpvXYxd1mIJzfpHhe+HNbG+IKV5mk8vDBb8g5oUJv5cwYfSTDG6N1NhfNTEwFbhFWB2yh36vkErpCLH1Ri9h2649aieZ6Qt/3YwqUbh8ep5kMEupLzPeZGWBrRholM43yrVbMjkhqJJX1lg1HznaE+Gl2a8Ojd8J2kiBceTOAu8P2Itnh8Xz2QYFxbAaDY1l1lEn6np6sMPdJnBFXUa/YXiEa7vNilIqfbA28= 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)(376002)(346002)(136003)(396003)(366004)(39840400004)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(107886003)(26005)(1076003)(52116002)(6666004)(2616005)(6512007)(83380400001)(5660300002)(44832011)(4326008)(8676002)(41300700001)(2906002)(30864003)(8936002)(6486002)(478600001)(316002)(6916009)(54906003)(66476007)(66556008)(66946007)(6506007)(86362001)(36756003)(38100700002)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QkiZPRl4DzuCmacSXeSUZw8FYCSS2Kr3LsM3xEsKcr0sUz+ZTllbA0pxPOGx?= =?us-ascii?Q?orbeEkvNM+LpQZY7Y4EHa1U1P35zJ3I0QOp+djT5yKMPhPChndX/r1WcFYWV?= =?us-ascii?Q?JN1FJGZ1Wd20+Xz8fnxT3dROrByFOsGxHjuGT9Ls3dTbIu1EGml5rtxSaC0W?= =?us-ascii?Q?BhVLmGmE8er19ybmnTceHDrUZLjMphXnTedTOTASGUdrWLTASA4E0DmwZV83?= =?us-ascii?Q?/HbK7Hl1NnJChCWtoxwkZ4DqEijp+yZynGHoczj7ogu6HywquVX/A7eYnhbr?= =?us-ascii?Q?FIpgtDd+mAp7lSvVbq6hwyMQN2Fzlrxd55B400HPvgCyvWEJsVeYtaBBY6cu?= =?us-ascii?Q?KnXcDhqfyhkDxcZ514P+9QrqLi7LjYzgANc1ZV3QkwNPf/ciUJjuF5fNZeSv?= =?us-ascii?Q?6dxKK9F/VtZW9vLIB6AweD2xQW3zWVdfpJWe2Q6W911pCkovS+xP5bl+SLBn?= =?us-ascii?Q?+880WjKDGo0DBwcft0OzrWyaw1/h2ULDzdu+oa5l0rrdr3swXYGl9Zy/5akH?= =?us-ascii?Q?IXtfBuAPw7CFcCrosUJH9qDaXkK+3L3IyG5MGs4dZN7+AzpmuC61pyTWfqIv?= =?us-ascii?Q?E5kBl2t2eQ7eBdTgfiNY1kbCqi30MCdTs6pvA6VOKnuIMXu7xqaBb9Vmyfp6?= =?us-ascii?Q?cMlC+r5gAFDFmJUZx4KqQ5ouBQfn9y3y2HagfWKAOE1AZV2H9K3gUol/rQ4h?= =?us-ascii?Q?UV4EnBifJKGj6RrqrOrM5NZb107YYr72xJRDDdHDyzsD3M2nm/RbWOOaK6AB?= =?us-ascii?Q?F0DEO1iPFwK1zbiT0PgnECIMdDfrW/ajHBqm6zThn0PlyFLc305TfxeKKnzs?= =?us-ascii?Q?Y2tXHabg6WAYtQZingsup81w/KN7TqQJy3Aqq4m5yYl+nioq+Js7m8gZMM1a?= =?us-ascii?Q?NN8N3E/tbicxhUZ54I9YK14IX6V44eL31b6PPeJALplyVBshm4aOV+Wq7Yab?= =?us-ascii?Q?hYYTXobPWBA2m76/kzxc3Q3f3AS8qBvPFnXc5ouPsOJ/91R4x9TSiLzFDHZ4?= =?us-ascii?Q?pXZvOIvKIIBR+OodWYf70moXDxcmf2pSXRNw+HwdjMaqIumOrt51UllI8iTH?= =?us-ascii?Q?65/pTKcCnd4D96rk+87LjZQ9Zrt6fofssVvXfKFN1fRiP1apuvjZKBkjmRHn?= =?us-ascii?Q?cI4pliqI3jYP5dZuHhsSx+ys8QnunOYuRfpiYgG9qnU7W/VU7rP4yb+3XBGc?= =?us-ascii?Q?VNc+Lu8KPjAwYmczHKbmunDDS7Q7Ah+Stv0jQDvOvA1ctLJu8jQEUOsPaxQr?= =?us-ascii?Q?4qf9wnW8aoDnib8mphaRXYwKwuBuW83iFzKrPQR8PkimAIvzJF4BHM0ivF1D?= =?us-ascii?Q?d6hFBBIPuz9FXIW/WO+SoVS47oAAV/TxhPvJy1xv5XQxORHc4ibiDLUeViLa?= =?us-ascii?Q?SqPmLT2Q79MRPuuFcpD2KA4Umrb8qlPnyii+ixys45s/foXsyd6dikAkeULL?= =?us-ascii?Q?/Zuvt4AUXoNIu79BMbX1H65wKec6dwSFGGUCUD7nEO+hsW9GBcKHLoY1XJcr?= =?us-ascii?Q?i9q+CSV5Vs+Vdvu2BlrC1TByc/vEhvLmhupfDrL5EJUB23dGX3lxDx4CaDrT?= =?us-ascii?Q?xfisF4XQH/MyG/M1TqN9ARc5jgN9Qf8s8pz5hOxBnhxz64m+R2flmyhQ5CZ+?= =?us-ascii?Q?SQ=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82ff253d-e347-4ddd-7592-08dc05e45a67 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2023 07:29:10.9948 (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: j7RoUu0PskclCSqF3VjT+g6C9m1oEEh2Pf1y88dvUwnVKZSPe83bQ4/9lCaSNvpnRH90Brba/tj91V17dPmkxD4z+D3wwVmFBxzE7rrApRY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR13MB6506 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 From: Long Wu After bonding port notification and firmware created the bonding port, NFP rte_flow rule adds support for destination port to bonding port. Signed-off-by: Long Wu Reviewed-by: Peng Zhang Reviewed-by: Chaoyong He --- drivers/net/nfp/flower/nfp_flower_bond.c | 22 +++ drivers/net/nfp/flower/nfp_flower_bond.h | 6 + drivers/net/nfp/flower/nfp_flower_cmsg.h | 9 + drivers/net/nfp/flower/nfp_flower_flow.c | 232 +++++++++++++++++++++-- 4 files changed, 252 insertions(+), 17 deletions(-) diff --git a/drivers/net/nfp/flower/nfp_flower_bond.c b/drivers/net/nfp/flower/nfp_flower_bond.c index c809465ffc..6e4d60659a 100644 --- a/drivers/net/nfp/flower/nfp_flower_bond.c +++ b/drivers/net/nfp/flower/nfp_flower_bond.c @@ -667,3 +667,25 @@ nfp_flower_bond_fw_create_get(struct rte_eth_dev *bond_dev, return ret; } + +int +nfp_flower_bond_get_output_id(struct nfp_flower_bond *nfp_bond, + const struct rte_eth_dev *bond_dev, + uint32_t *group_id) +{ + struct nfp_bond_group *group; + + pthread_mutex_lock(&nfp_bond->mutex); + + group = nfp_flower_bond_find_group(nfp_bond, bond_dev); + if (group == NULL) { + pthread_mutex_unlock(&nfp_bond->mutex); + return -ENOENT; + } + + *group_id = group->group_id; + + pthread_mutex_unlock(&nfp_bond->mutex); + + return 0; +} diff --git a/drivers/net/nfp/flower/nfp_flower_bond.h b/drivers/net/nfp/flower/nfp_flower_bond.h index 41cd64d9eb..7e451c58f1 100644 --- a/drivers/net/nfp/flower/nfp_flower_bond.h +++ b/drivers/net/nfp/flower/nfp_flower_bond.h @@ -44,6 +44,9 @@ /** We store 100(101-1) mbufs but queue needs 101 */ #define NFP_FL_BOND_RETRANS_LIMIT 101 +/* Flow output action of bonding port */ +#define NFP_FL_BOND_OUT 0xC0DE0000 + enum nfp_flower_bond_batch { NFP_FLOWER_BOND_BATCH_FIRST, NFP_FLOWER_BOND_BATCH_MEMBER, @@ -155,5 +158,8 @@ int nfp_fl_bond_put_unprocessed(struct nfp_flower_bond *nfp_bond, struct rte_mbuf *mbuf); int nfp_flower_bond_fw_create_get(struct rte_eth_dev *bond_dev, struct rte_eth_dev *nfp_dev); +int nfp_flower_bond_get_output_id(struct nfp_flower_bond *nfp_bond, + const struct rte_eth_dev *bond_dev, + uint32_t *group_id); #endif /* __NFP_FLOWER_BOND_H__ */ diff --git a/drivers/net/nfp/flower/nfp_flower_cmsg.h b/drivers/net/nfp/flower/nfp_flower_cmsg.h index 60ab58a3b1..17ef943855 100644 --- a/drivers/net/nfp/flower/nfp_flower_cmsg.h +++ b/drivers/net/nfp/flower/nfp_flower_cmsg.h @@ -712,6 +712,15 @@ struct nfp_fl_act_head { uint8_t len_lw; }; +#define NFP_FL_PRE_BOND_VER_OFF 8 + +struct nfp_fl_pre_bond { + struct nfp_fl_act_head head; + rte_be16_t group_id; + uint8_t lag_version[3]; + uint8_t instance; +}; + struct nfp_fl_act_output { struct nfp_fl_act_head head; rte_be16_t flags; diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c index e26be30d18..6e21ad8c26 100644 --- a/drivers/net/nfp/flower/nfp_flower_flow.c +++ b/drivers/net/nfp/flower/nfp_flower_flow.c @@ -5,12 +5,14 @@ #include "nfp_flower_flow.h" +#include #include #include #include #include #include "flower/nfp_conntrack.h" +#include "flower/nfp_flower_bond.h" #include "flower/nfp_flower_representor.h" #include "nfpcore/nfp_rtsym.h" #include "nfp_logs.h" @@ -969,9 +971,23 @@ nfp_flow_key_layers_calculate_items(const struct rte_flow_item items[], return 0; } +static bool +nfp_flow_check_bond_action(struct nfp_flower_representor *representor, + uint32_t port_id) +{ + struct rte_eth_dev *bond_dev = &rte_eth_devices[port_id]; + + if (nfp_flower_support_bond_offload(representor->app_fw_flower) || + !nfp_flower_bond_all_member_are_phyrepr(bond_dev)) + return false; + + return true; +} + static int nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], - struct nfp_fl_key_ls *key_ls) + struct nfp_fl_key_ls *key_ls, + struct nfp_flower_representor *representor) { int ret = 0; bool meter_flag = false; @@ -981,6 +997,8 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], bool mac_set_flag = false; bool ttl_tos_flag = false; const struct rte_flow_action *action; + const struct rte_flow_action_port_id *port_id; + const struct rte_flow_action_ethdev *action_ethdev; for (action = actions; action->type != RTE_FLOW_ACTION_TYPE_END; ++action) { /* Make sure actions length no longer than NFP_FL_MAX_A_SIZ */ @@ -1006,10 +1024,36 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], case RTE_FLOW_ACTION_TYPE_PORT_ID: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_PORT_ID detected"); key_ls->act_size += sizeof(struct nfp_fl_act_output); + + port_id = action->conf; + if (port_id == NULL) + return -ERANGE; + + if (!rte_eth_bond_is_valid_port(port_id->id)) + break; + + if (!nfp_flow_check_bond_action(representor, port_id->id)) + return -ENOTSUP; + + /* We only add when all checks have passed */ + key_ls->act_size += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT detected"); key_ls->act_size += sizeof(struct nfp_fl_act_output); + + action_ethdev = action->conf; + if (action_ethdev == NULL) + return -ERANGE; + + if (!rte_eth_bond_is_valid_port(action_ethdev->port_id)) + break; + + if (!nfp_flow_check_bond_action(representor, action_ethdev->port_id)) + return -ENOTSUP; + + /* We only add when all checks have passed */ + key_ls->act_size += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC: PMD_DRV_LOG(DEBUG, "RTE_FLOW_ACTION_TYPE_SET_MAC_SRC detected"); @@ -1150,7 +1194,8 @@ nfp_flow_key_layers_calculate_actions(const struct rte_flow_action actions[], static int nfp_flow_key_layers_calculate(const struct rte_flow_item items[], const struct rte_flow_action actions[], - struct nfp_fl_key_ls *key_ls) + struct nfp_fl_key_ls *key_ls, + struct nfp_flower_representor *representor) { int ret = 0; @@ -1164,7 +1209,7 @@ nfp_flow_key_layers_calculate(const struct rte_flow_item items[], key_ls->tun_type = NFP_FL_TUN_NONE; ret |= nfp_flow_key_layers_calculate_items(items, key_ls); - ret |= nfp_flow_key_layers_calculate_actions(actions, key_ls); + ret |= nfp_flow_key_layers_calculate_actions(actions, key_ls, representor); return ret; } @@ -2160,12 +2205,45 @@ nfp_flow_compile_items(struct nfp_flower_representor *representor, return 0; } +static int +nfp_flower_bond_populate_pre_action(struct nfp_flower_representor *repr, + struct rte_eth_dev *bond_dev, + struct nfp_fl_pre_bond *pre_bond) +{ + rte_be32_t version; + struct nfp_bond_group *group; + struct nfp_flower_bond *nfp_bond; + + nfp_bond = repr->app_fw_flower->nfp_bond; + + pthread_mutex_lock(&nfp_bond->mutex); + + group = nfp_flower_bond_find_group(nfp_bond, bond_dev); + if (group == NULL) { + pthread_mutex_unlock(&nfp_bond->mutex); + PMD_DRV_LOG(ERR, "Invalid entry: group does not exist for bond action"); + return -ENOENT; + } + + pre_bond->group_id = rte_cpu_to_be_16(group->group_id); + version = rte_cpu_to_be_32(nfp_bond->batch_ver << NFP_FL_PRE_BOND_VER_OFF); + memcpy(pre_bond->lag_version, &version, 3); + pre_bond->instance = group->group_inst; + + pthread_mutex_unlock(&nfp_bond->mutex); + + return 0; +} + static int nfp_flow_action_output(char *act_data, const struct rte_flow_action *action, struct nfp_fl_rule_metadata *nfp_flow_meta, - uint32_t output_cnt) + uint32_t output_cnt, + struct nfp_flower_bond *nfp_bond, + bool *bonding_port) { + uint32_t gid; size_t act_size; struct rte_eth_dev *ethdev; struct nfp_fl_act_output *output; @@ -2177,18 +2255,31 @@ nfp_flow_action_output(char *act_data, return -ERANGE; ethdev = &rte_eth_devices[port_id->id]; - representor = ethdev->data->dev_private; + output = (struct nfp_fl_act_output *)act_data; + if (rte_eth_bond_is_valid_port(port_id->id)) { + /* Output port is bonding port */ + if (nfp_flower_bond_get_output_id(nfp_bond, ethdev, &gid) != 0) { + PMD_DRV_LOG(ERR, "Cannot find group id for bond action"); + return -EINVAL; + } + + output->port = rte_cpu_to_be_32(NFP_FL_BOND_OUT | gid); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(NFP_FL_SC_ACT_NULL); + *bonding_port = true; + } else { + representor = ethdev->data->dev_private; + + output->port = rte_cpu_to_be_32(representor->port_id); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + } + act_size = sizeof(struct nfp_fl_act_output); - output = (struct nfp_fl_act_output *)act_data; output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT; output->head.len_lw = act_size >> NFP_FL_LW_SIZ; - output->port = rte_cpu_to_be_32(representor->port_id); if (output_cnt == 0) output->flags = rte_cpu_to_be_16(NFP_FL_OUT_FLAGS_LAST); - nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); - return 0; } @@ -2196,8 +2287,11 @@ static int nfp_flow_action_output_stage(char *act_data, const struct rte_flow_action *action, struct nfp_fl_rule_metadata *nfp_flow_meta, - uint32_t output_cnt) + uint32_t output_cnt, + struct nfp_flower_bond *nfp_bond, + bool *bonding_port) { + uint32_t gid; size_t act_size; struct rte_eth_dev *ethdev; struct nfp_fl_act_output *output; @@ -2209,17 +2303,70 @@ nfp_flow_action_output_stage(char *act_data, return -ERANGE; ethdev = &rte_eth_devices[action_ethdev->port_id]; - representor = ethdev->data->dev_private; + output = (struct nfp_fl_act_output *)act_data; + if (rte_eth_bond_is_valid_port(action_ethdev->port_id)) { + /* Output port is bonding port */ + if (nfp_flower_bond_get_output_id(nfp_bond, ethdev, &gid) != 0) { + PMD_DRV_LOG(ERR, "Cannot find group id for bond action"); + return -EINVAL; + } + + output->port = rte_cpu_to_be_32(NFP_FL_BOND_OUT | gid); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(NFP_FL_SC_ACT_NULL); + *bonding_port = true; + } else { + representor = ethdev->data->dev_private; + + output->port = rte_cpu_to_be_32(representor->port_id); + nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + } + act_size = sizeof(struct nfp_fl_act_output); - output = (struct nfp_fl_act_output *)act_data; output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT; output->head.len_lw = act_size >> NFP_FL_LW_SIZ; - output->port = rte_cpu_to_be_32(representor->port_id); if (output_cnt == 0) output->flags = rte_cpu_to_be_16(NFP_FL_OUT_FLAGS_LAST); - nfp_flow_meta->shortcut = rte_cpu_to_be_32(representor->port_id); + return 0; +} + +static int +nfp_flow_pre_bond(struct nfp_flower_representor *representor, + char *act_data, + char *actions, + const struct rte_flow_action *action) +{ + int err; + int act_len; + uint32_t port_id; + struct rte_eth_dev *ethdev; + struct nfp_fl_pre_bond *pre_bond; + uint32_t pre_bond_size = sizeof(struct nfp_fl_pre_bond); + + act_len = act_data - actions; + + if (act_len + pre_bond_size > NFP_FL_MAX_A_SIZ) { + PMD_DRV_LOG(ERR, "Maximum allowed action list size exceeded at bond action"); + return -EOPNOTSUPP; + } + + if (act_len != 0) + memmove(actions + pre_bond_size, actions, act_len); + + if (action->type == RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT) + port_id = ((const struct rte_flow_action_ethdev *)action->conf)->port_id; + else + port_id = ((const struct rte_flow_action_port_id *)action->conf)->id; + + ethdev = &rte_eth_devices[port_id]; + pre_bond = (struct nfp_fl_pre_bond *)actions; + err = nfp_flower_bond_populate_pre_action(representor, ethdev, pre_bond); + if (err != 0) + return err; + + pre_bond->head.jump_id = NFP_FL_ACTION_OPCODE_PRE_LAG; + pre_bond->head.len_lw = pre_bond_size >> NFP_FL_LW_SIZ; return 0; } @@ -3502,6 +3649,13 @@ nfp_flow_count_output(const struct rte_flow_action actions[]) return count; } +static bool +nfp_flow_check_action_first(const struct rte_flow_action actions[], + uint32_t count) +{ + return ((nfp_flow_count_output(actions) - count) == 1); +} + static int nfp_flow_compile_action(struct nfp_flower_representor *representor, const struct rte_flow_action actions[], @@ -3517,7 +3671,9 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, bool tp_set_flag = false; bool mac_set_flag = false; bool ttl_tos_flag = false; + bool bonding_port = false; uint32_t total_actions = 0; + struct nfp_flower_bond *nfp_bond; const struct rte_flow_action *action; struct nfp_flower_meta_tci *meta_tci; struct nfp_fl_rule_metadata *nfp_flow_meta; @@ -3546,7 +3702,10 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT"); count--; - ret = nfp_flow_action_output_stage(position, action, nfp_flow_meta, count); + + nfp_bond = representor->app_fw_flower->nfp_bond; + ret = nfp_flow_action_output_stage(position, action, + nfp_flow_meta, count, nfp_bond, &bonding_port); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed when process" " RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT"); @@ -3554,11 +3713,32 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, } position += sizeof(struct nfp_fl_act_output); + + /* Output port is not a bonding port */ + if (!bonding_port) + break; + + if (!nfp_flow_check_action_first(actions, count)) { + PMD_DRV_LOG(ERR, "Bond action should be first"); + return -EOPNOTSUPP; + } + + ret = nfp_flow_pre_bond(representor, position, + action_data, action); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Bond action special move failed"); + return ret; + } + + position += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_PORT_ID: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_PORT_ID"); count--; - ret = nfp_flow_action_output(position, action, nfp_flow_meta, count); + + nfp_bond = representor->app_fw_flower->nfp_bond; + ret = nfp_flow_action_output(position, action, + nfp_flow_meta, count, nfp_bond, &bonding_port); if (ret != 0) { PMD_DRV_LOG(ERR, "Failed when process" " RTE_FLOW_ACTION_TYPE_PORT_ID"); @@ -3566,6 +3746,24 @@ nfp_flow_compile_action(struct nfp_flower_representor *representor, } position += sizeof(struct nfp_fl_act_output); + + /* Output port is not a bonding port */ + if (!bonding_port) + break; + + if (!nfp_flow_check_action_first(actions, count)) { + PMD_DRV_LOG(ERR, "Bond action should be first"); + return -EOPNOTSUPP; + } + + ret = nfp_flow_pre_bond(representor, position, + action_data, action); + if (ret != 0) { + PMD_DRV_LOG(ERR, "Bond action special move failed"); + return ret; + } + + position += sizeof(struct nfp_fl_pre_bond); break; case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC: PMD_DRV_LOG(DEBUG, "Process RTE_FLOW_ACTION_TYPE_SET_MAC_SRC"); @@ -3770,7 +3968,7 @@ nfp_flow_process(struct nfp_flower_representor *representor, struct nfp_fl_key_ls key_layer; struct nfp_fl_rule_metadata *nfp_flow_meta; - ret = nfp_flow_key_layers_calculate(items, actions, &key_layer); + ret = nfp_flow_key_layers_calculate(items, actions, &key_layer, representor); if (ret != 0) { PMD_DRV_LOG(ERR, "Key layers calculate failed."); return NULL; -- 2.39.1