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 CBBFF4378F; Tue, 26 Dec 2023 03:39:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E39E40DDA; Tue, 26 Dec 2023 03:38:41 +0100 (CET) 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 E804A40DDA for ; Tue, 26 Dec 2023 03:38:39 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TzLpBuBxeprLkKMSMJ175klUMplUdXUmoPnov2kvIeanWgr/o76ONorwIt/g8G1dwiAndPqM8J8ATA7SLUmNOkrHpDdXeKMGJ2elOrwHHrFal/i/aVW1ffc7Vfl8jQWzBEQJoKR1+jRnc8MBVTTt4fgRe8nRyNd3Xc4j/fR4FLaOoTrVBqii9hx4+rrl1fmCfVXQElG9c/1J7PttScR375U4bTXL7VUMwmOcJisgG/P2tTFM0cM7iwP2t6SyklL50uDxbyAOslIbM3EHG54jSSjOhyj11C7fdaSBlwmY2r4dIJAWwycOnfolR22dHJmBd3ngjLLzqR2QGzhbGOKlRA== 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=bvw8p3WM36EKeSmTHmv312caC+impQM+ErZ8SFrnPig=; b=FYqXwhkSuUNIpCOmeq+qiAnRaUM7YTi8G64m07B09DO9VFdAMVkXqtTtsoWZmF8b+l0sqYvwm6JfiuWQt2M67jvx3EFS4p//pdbd1feERwsHbqgbgYdKTaS6Gcbk8gX6QfrQBloBJ/BWCbVHTnCz1OCnNvaWDcVICktDb8QlgjuV2SW3qaiHJxZtp3UohElDPxtjTSB2V8eECw7nVotQ7banA+/lRKFMe/19wnXn4i7Fq1eVsB05B5tF5no6yPByQ4/GacaChzPBprecF8vBOo7ae+oHQrGa0ZjdbcJnMIklzrnyOneB8jpM5H5ZfkpUN+1XBT2UeWBhN8yLKiaU0w== 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=bvw8p3WM36EKeSmTHmv312caC+impQM+ErZ8SFrnPig=; b=F0kkFFXkqlePU7ZlrLlEfpYpSP1W6WBaPkPQOZhH/wtjdJA8kJK8Gh08s7sWdBtVAp0c9YIuDT8GS0ht6er15IAIvSKd8+ZnZHzjjiUx2o1TnTn8Z7oyfzBDBoWwq0abfYQm6ZNWLBfWc3axtXURKPA1icgRbRxnDuWyRPDmmVo= 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 MW4PR13MB5864.namprd13.prod.outlook.com (2603:10b6:303:1b7::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.26; Tue, 26 Dec 2023 02:38:38 +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.026; Tue, 26 Dec 2023 02:38:38 +0000 From: Chaoyong He To: dev@dpdk.org Cc: oss-drivers@corigine.com, Long Wu , Peng Zhang , Chaoyong He Subject: [PATCH v5 14/14] net/nfp: support offloading bond-flow Date: Tue, 26 Dec 2023 10:37:45 +0800 Message-Id: <20231226023745.3144143-15-chaoyong.he@corigine.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20231226023745.3144143-1-chaoyong.he@corigine.com> References: <20231018074821.1908906-1-chaoyong.he@corigine.com> <20231226023745.3144143-1-chaoyong.he@corigine.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR01CA0156.apcprd01.prod.exchangelabs.com (2603:1096:4:8f::36) To SJ0PR13MB5545.namprd13.prod.outlook.com (2603:10b6:a03:424::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR13MB5545:EE_|MW4PR13MB5864:EE_ X-MS-Office365-Filtering-Correlation-Id: 56ce81d9-919a-409a-f03a-08dc05bbc37f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vnxfi9G+JrIFQYIhieFNW25p3pJ4XyZN/H4AG4T3DupM4IqFP5DbodFN4qvqwVzr1srBlUUK7QgdkTRKvt4NXMgCYLjWvdJSSpMBdclV5oWuZXgSp1P1DSXZy4okmBkNktsjuXK2+nFQGuR+UrqZ+JpWvxqTR4hranF4C0WAnc3Wdr+5ydB/LhlzQSGztSCm7Ukxwm8/5u3vRiqpZRDyoIw9xBDKgYUoXcepEgBV38qKc7PSdH6qr/+5HtvzYAmKYWwoEhXvt44N5YpRUx0pFi/gTjspGWjah06oUqOKOFSZbgATVs8NHmvBS4bVtni3RIoRJiciMw8KmOMYPorC4jtsKL16AUX3utwUhM5xyKRXEKCO+oJDeyqqFva4bojN503l1BiScPXwcE/FZhog8E3+z5BWL6o3UMVWBfqdVWbOylxTYKxUOf8lnNvxrc47+YpiraLv4L7hRN6nzrvy8dxwXPjq0c4Aq6nbGOujZVkik+jpr1Ry0uRxZIfASxpDJlMzX6Vy/2H3svDRpBolR6UDqTeCxRh1IuWQt8xCrZy6WHTLXhNtpAjOsghZR92P2vGJLL04CP5JUOfIYm86X7kM3PHntVyWDLfXt3iXKqlJJw/ckz5oGVVuDNvDooyxw3Ksic2hKYwtgslBc/uqNm2cEBcTkPTze6ugJ8vHuEg= 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(83380400001)(41300700001)(2616005)(38100700002)(26005)(107886003)(1076003)(316002)(4326008)(54906003)(8676002)(30864003)(2906002)(5660300002)(44832011)(8936002)(478600001)(6512007)(6666004)(6506007)(52116002)(66476007)(66556008)(66946007)(6486002)(6916009)(38350700005)(86362001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?ZtoqJJd7CUnuKVSoM2Z8YcWst0e7Xt5WIt5XhDGegdKQ8H7Sp+XXgZVJ4igj?= =?us-ascii?Q?H0gnS1eAyGjmVsGyNvLByQALEFd/DJBJ5XhGSdqZnN/EC+iUjY2GSUww9xpM?= =?us-ascii?Q?PXyP5foCzyesDOy5Pe8gJN6UX3AWhNqpMEHJoLg2coY/qZX+xyOvO6/wZO9O?= =?us-ascii?Q?rqsD46GHZ/AEmPZMPtkV8D5ZIYvI/B8yiSzoG1smVFrSsfsIOe/pRNxlV0Hp?= =?us-ascii?Q?B6P55BRFWvEGeIHCoLluQN5VaPAyqr3CEo/+246lvJosy0xAjQi/nmUN/w6j?= =?us-ascii?Q?W2s7a5wTh6RsdE3fRNg33Vvz5zYPxQvip2X8lRKRAwdFmvMKBfFoZyqBi1er?= =?us-ascii?Q?6NOEQiOK979kwRYFgmb/ps2WR6c69Rj5OZkAgEwyDOJ+p0c4yWIX7NZevuyd?= =?us-ascii?Q?bew3bJ6/YEK91hkCi0y8CofB0B1X2aehWKOu4xkoV6VFD9wJGxp3pnCL72AH?= =?us-ascii?Q?gQQ3AVDnkCsW36oQOczIVlP8+o5yrTxkQkdjK93kOgHrmP3xk+6fhu+hCF0a?= =?us-ascii?Q?ZZiG0VpLoma739xyD/oGtARes6dRBvGUKX8XZkvaEBf9IJAp4AinR0ljwBKh?= =?us-ascii?Q?ioLWit9vtWBYbcv9s6JTFJ4DhOjCkeU2cZmA6bHevhF+HUmFyh22sp6kThI5?= =?us-ascii?Q?sBwN3KO9Kq3iOtUCvly3FjfYyUKqPLiJX4LkLg3RdBsibDKRJRKoDQDlLkV5?= =?us-ascii?Q?8cjDelYMdqA8TruCgnDgAZ391uw+9QD70+dXUD9A1WN+ZGIhLS7mlqOXxjvE?= =?us-ascii?Q?w5fNac0XgUlLa018Zl+j/Sc4Txv51G2AjNyzDVUYncbi8i459hKWGMOpVZRS?= =?us-ascii?Q?Bax8YI8bKEzNllnUhwYc6u3OItO9Fbi7RffkMFzvJFHh/ahazhg/vNfrqin+?= =?us-ascii?Q?g8/mw9sAiR1c0mS5TReJUcRZgQ0TvsiIpovlg4SNh16eaYAH9HtpHwczXOcM?= =?us-ascii?Q?1v9jdVjmxcmz0nf4f4Smj/uX/kHjLY0wktP3S42AVUORKW69T5giaTUB6eBb?= =?us-ascii?Q?G9LsD1GQH/kBzswj1rP/XWTrNO5rX1iuJ2DOxYp2bN3RjCrOjmErhPb0xcQg?= =?us-ascii?Q?49OGwUKeM7T8D9WTq7cp+4KJwV6Y+BU1+tHwwi8xdSGAO4IRE/vklO+ELqTS?= =?us-ascii?Q?WVycjhQ6+qlEfFvU1mMtDOhH4Yf6RnKrw6nibrdGSZ2ICVD2xzbaqIAe8uE3?= =?us-ascii?Q?VQNgPmgTjbYFLIj9cRyFFj6gSnXc5cwMGMTTkGIMC+rsrJm3jwziwRRvoJtg?= =?us-ascii?Q?oKEFaxINOPM2I/VajXii1V51b+WQGV2O3oUO/a3ke1BgdTj5KRQ9sVo0fSMb?= =?us-ascii?Q?TOrKViQmUExIM6wwx9snZzkhDr9Fpl3myYH2201sfFklypjDZWY+npFbSnKr?= =?us-ascii?Q?QMG4NC9to63BuVr7gaWLsKqG+QVS14TpgHNeXYllfPPyrjJvwDpn7tCDn5dc?= =?us-ascii?Q?V6NTugA69k7fPFjxb5Lz4URoEPrbUZWH9ne43OmwknbztBv68eejGIqbRQ5k?= =?us-ascii?Q?hiAAU/ER2KJ4Bfc86zaM86uFm3AzFZ8VmTJk6QjFhrWQRs+5IOtIzsGjY2DA?= =?us-ascii?Q?QAI2JVibO+MMKJ5A+lVb0cbtn6BWhx/d/9JV99zjOzskm9/PFErJ71naSh6X?= =?us-ascii?Q?0Q=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56ce81d9-919a-409a-f03a-08dc05bbc37f X-MS-Exchange-CrossTenant-AuthSource: SJ0PR13MB5545.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2023 02:38:38.0075 (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: OH68z3UCZdDea0KB5UM2Pnqpw/vVZTRok+RjgMK8CvEGVCDC43LotaHc8LQo3DHrHXuAxXMxSrEq8/Uwdjy5aIc5DNl+9Qr8VzLvNh7zzFk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR13MB5864 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 91d7d88b8c..6debe32549 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