From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10055.outbound.protection.outlook.com [40.107.1.55]) by dpdk.org (Postfix) with ESMTP id 5BE001B568 for ; Wed, 10 Oct 2018 14:56:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GZV3QfY55l+pDTRZ3JUVk/EMjkTSDOu5ny/oRCAi4tU=; b=hekUKddh+chF8nIPiEijMDCEeePMPBaSM5vb+2Bx0MU3DgCGeyjyWOEzPIQEelCFXk7BsD9mK/F8lMg9iKqDhQXRo5Vln/SfpsmI5uQGilrnzITCGXiaPsKomLNQvtGGyt5BQBX/KqkHw7ZZRyJO6aMY5Gux/g52CBidaS5cnTQ= Received: from DB6PR0501MB2023.eurprd05.prod.outlook.com (10.168.9.17) by DB6PR0501MB2117.eurprd05.prod.outlook.com (10.168.9.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.23; Wed, 10 Oct 2018 12:56:15 +0000 Received: from DB6PR0501MB2023.eurprd05.prod.outlook.com ([fe80::b1fb:bad3:b5b1:f913]) by DB6PR0501MB2023.eurprd05.prod.outlook.com ([fe80::b1fb:bad3:b5b1:f913%3]) with mapi id 15.20.1228.020; Wed, 10 Oct 2018 12:56:15 +0000 From: Jack Min To: Shahaf Shuler , Yongseok Koh CC: "dev@dpdk.org" Thread-Topic: [PATCH v2] net/mlx5: rewrite IP address UDP/TCP port by E-Switch Thread-Index: AQHUYJigTNA5xxt4P0y43befUQK92Q== Date: Wed, 10 Oct 2018 12:56:15 +0000 Message-ID: <20181010125536.23035-1-jackmin@mellanox.com> References: <20180925115107.12242-1-jackmin@mellanox.com> In-Reply-To: <20180925115107.12242-1-jackmin@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK2PR02CA0187.apcprd02.prod.outlook.com (2603:1096:201:21::23) To DB6PR0501MB2023.eurprd05.prod.outlook.com (2603:10a6:4:6::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=jackmin@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [118.201.220.138] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB6PR0501MB2117; 6:y5CakMlsAmWUzaG3Ouq405JOHh97fHLxLZ3c9WZJUu0xvoF6jGvT6MNdZyn8t7EVUZxufdQPO4UEiskrNQY3Tl0eI1FWe4Deiik164ZQNSaScTSks50Jbzrml1mGyEz+dc+rz6TN+q+YDGEjRkQY3gDJdfcZDw0Hs55OwcjOdZGyBvoMxb7ozmJ8x58UNCDJNnEvckrg8T5b2f4mh+bMTVMSNW69Mj6Cui29ZtiOEqMxhqV1LzFug/80X5Kd9F+7ZsW8p4UaRuIGY2xVSUh7c8f8IETApaYI8J4UleV6RDhj7PAwIpbBGXUOeXpU9DtKBbYHRLsuQQl9jykD1QS5Z4znRTSP66QUSmi3dS3RVkpY8r16YtAcIS0nCSv0fbl0YfucKCqwj6ICDZXY7DI/SXc3jo/gj4141GQX2hMnosy3EsKLCn73UMBgZo9A1CC5X9vj0xMA67R7htxaxuCDuQ==; 5:lskqO3/n3IA8pJKSU9e3sN/AC1INnLmjXupg5mZCZ/njyznqHOiXDQGNC5GJZ68TX4JIsxsKJ8+SjKdjty6e4Di45NvTmODxctAYiZF3edwxj4a67zfbXyjU1dHtkg2PNcxDQia9/Nmox9ynS4jiB+5wy2BZ9YWYAQLyURvdVFw=; 7:i7I5QXVH+YVolT/0NFh7vv3qDv1KLB1qHd0RYGmcZ7K2KRT4PpGj1gp/9Uv6WHrLKcNFEsJJUHSHq+maXxy3SkjJjNF4LF9J/6HXFQgPPapXi9ZReNN10le/tQ9FmHg3SJxJYQfKkzxcWNL7P0vUN+JgM85FpYUlS0wUP5rAcSNx2bEHZnhFpfsmGGDa8teb2Z1lJNjsuU0nFPz7snbvg+hr7cgMwqpwkzYMOfbzKfI1W4cx/Cu11rhQGk2hmQkp x-ms-office365-filtering-correlation-id: 2b5a3c84-e039-42c2-df67-08d62eafc2ff x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:DB6PR0501MB2117; x-ms-traffictypediagnostic: DB6PR0501MB2117: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:DB6PR0501MB2117; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0501MB2117; x-forefront-prvs: 08213D42D3 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(346002)(39860400002)(376002)(366004)(136003)(199004)(189003)(486006)(2616005)(446003)(476003)(6506007)(386003)(68736007)(85306007)(99286004)(25786009)(11346002)(36756003)(2906002)(110136005)(4744004)(6636002)(4326008)(186003)(5660300001)(26005)(6486002)(86362001)(53936002)(6512007)(53946003)(6436002)(575784001)(316002)(97736004)(71200400001)(71190400001)(305945005)(102836004)(6116002)(3846002)(8676002)(14454004)(81166006)(478600001)(81156014)(8936002)(5250100002)(105586002)(76176011)(66066001)(52116002)(106356001)(7736002)(1076002)(256004)(2900100001)(14444005)(579004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0501MB2117; H:DB6PR0501MB2023.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 8lz0j9Ri4oOWcBpgbPWlwvxdXQff8d2WrBfreHr0dtnQHl/+Bj72cO1Ecrv7wqL86Hqxfn5x5F+29AKrHTEqDd/DaR0srWbLYZorpTinEzCqGxXJwph7RBQXY081ZcOdvlIGDqEXIvbYi/EBJ3dj5UZ52TfppORNhkErXPw9AE82MvnHfLxiPvITZ454VOzwBzkWTEaApJ/AYyY3HlIA150aNgMiBFKg3j7Niah2fFsY9mH/1w2LDDfDZg34kPuorAy1TW7DTIGj1692d33XtpDSgfph+hM7DzaVINIP8rSv8TnhD11+5d/jN+Mkablpu1L5RtWrWeJfyjDaZ8nResMvNKva5UU32DSn0GJVfME= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b5a3c84-e039-42c2-df67-08d62eafc2ff X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Oct 2018 12:56:15.4895 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0501MB2117 Subject: [dpdk-dev] [PATCH v2] net/mlx5: rewrite IP address UDP/TCP port by E-Switch X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2018 12:56:18 -0000 Offload the following rte_flow actions by inserting accordingly E-Switch rules via TC Flower driver - RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC - RTE_FLOW_ACTION_TYPE_SET_IPV4_DST - RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC - RTE_FLOW_ACTION_TYPE_SET_IPV6_DST - RTE_FLOW_ACTION_TYPE_SET_TP_SRC - RTE_FLOW_ACTION_TYPE_SET_TP_DST The example testpmd command is: flow create 0 transfer ingress pattern eth / ipv4 / udp dst is 7000 / end actions set_ipv4_src ipv4_addr 172.168.0.1 / set_ipv4_dst ipv4_addr 172.168.10.1 / set_tp_dst port 9000 / set_tp_src port 700 / port_id id 1 / end Signed-off-by: Xiaoyu Min --- v2: * rebased * validate pedit actions with drop action * validate successive pedit actions * a more generic way of validation * added testpmd commands in commit log * added comments of new added functions * fix some coding style issue drivers/net/mlx5/Makefile | 5 + drivers/net/mlx5/meson.build | 2 + drivers/net/mlx5/mlx5_flow.h | 6 + drivers/net/mlx5/mlx5_flow_tcf.c | 468 ++++++++++++++++++++++++++++++- 4 files changed, 475 insertions(+), 6 deletions(-) diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index ca1de9f21..49b95e78e 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -346,6 +346,11 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config= -h.sh linux/tc_act/tc_vlan.h \ enum TCA_VLAN_PUSH_VLAN_PRIORITY \ $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ + HAVE_TC_ACT_PEDIT \ + linux/tc_act/tc_pedit.h \ + enum TCA_PEDIT_KEY_EX_HDR_TYPE_UDP \ + $(AUTOCONF_OUTPUT) $Q sh -- '$<' '$@' \ HAVE_SUPPORTED_40000baseKR4_Full \ /usr/include/linux/ethtool.h \ diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build index fd93ac162..ef6a85101 100644 --- a/drivers/net/mlx5/meson.build +++ b/drivers/net/mlx5/meson.build @@ -182,6 +182,8 @@ if build 'TCA_FLOWER_KEY_VLAN_ETH_TYPE' ], [ 'HAVE_TC_ACT_VLAN', 'linux/tc_act/tc_vlan.h', 'TCA_VLAN_PUSH_VLAN_PRIORITY' ], + [ 'HAVE_TC_ACT_PEDIT', 'linux/tc_act/tc_pedit.h', + 'TCA_PEDIT_KEY_EX_HDR_TYPE_UDP' ], [ 'HAVE_RDMA_NL_NLDEV', 'rdma/rdma_netlink.h', 'RDMA_NL_NLDEV' ], [ 'HAVE_RDMA_NLDEV_CMD_GET', 'rdma/rdma_netlink.h', diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 12de841e8..cbb8c56c8 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -78,6 +78,12 @@ #define MLX5_FLOW_ACTION_OF_PUSH_VLAN (1u << 8) #define MLX5_FLOW_ACTION_OF_SET_VLAN_VID (1u << 9) #define MLX5_FLOW_ACTION_OF_SET_VLAN_PCP (1u << 10) +#define MLX5_FLOW_ACTION_SET_IPV4_SRC (1u << 11) +#define MLX5_FLOW_ACTION_SET_IPV4_DST (1u << 12) +#define MLX5_FLOW_ACTION_SET_IPV6_SRC (1u << 13) +#define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14) +#define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15) +#define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16) =20 #define MLX5_FLOW_FATE_ACTIONS \ (MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index 91f6ef678..65e8a4b3f 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -53,6 +53,62 @@ struct tc_vlan { =20 #endif /* HAVE_TC_ACT_VLAN */ =20 +#ifdef HAVE_TC_ACT_PEDIT + +#include + +#else /* HAVE_TC_ACT_VLAN */ +enum { + TCA_PEDIT_UNSPEC, + TCA_PEDIT_TM, + TCA_PEDIT_PARMS, + TCA_PEDIT_PAD, + TCA_PEDIT_PARMS_EX, + TCA_PEDIT_KEYS_EX, + TCA_PEDIT_KEY_EX, + __TCA_PEDIT_MAX +}; + +enum { + TCA_PEDIT_KEY_EX_HTYPE =3D 1, + TCA_PEDIT_KEY_EX_CMD =3D 2, + __TCA_PEDIT_KEY_EX_MAX +}; + +enum pedit_header_type { + TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK =3D 0, + TCA_PEDIT_KEY_EX_HDR_TYPE_ETH =3D 1, + TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 =3D 2, + TCA_PEDIT_KEY_EX_HDR_TYPE_IP6 =3D 3, + TCA_PEDIT_KEY_EX_HDR_TYPE_TCP =3D 4, + TCA_PEDIT_KEY_EX_HDR_TYPE_UDP =3D 5, + __PEDIT_HDR_TYPE_MAX, +}; + +enum pedit_cmd { + TCA_PEDIT_KEY_EX_CMD_SET =3D 0, + TCA_PEDIT_KEY_EX_CMD_ADD =3D 1, + __PEDIT_CMD_MAX, +}; + +struct tc_pedit_key { + __u32 mask; /* AND */ + __u32 val; /*XOR */ + __u32 off; /*offset */ + __u32 at; + __u32 offmask; + __u32 shift; +}; + +struct tc_pedit_sel { + tc_gen; + unsigned char nkeys; + unsigned char flags; + struct tc_pedit_key keys[0]; +}; + +#endif /* HAVE_TC_ACT_VLAN */ + /* Normally found in linux/netlink.h. */ #ifndef NETLINK_CAP_ACK #define NETLINK_CAP_ACK 10 @@ -153,6 +209,14 @@ struct tc_vlan { #define IPV6_ADDR_LEN 16 #endif =20 +#ifndef IPV4_ADDR_LEN +#define IPV4_ADDR_LEN 4 +#endif + +#ifndef TP_PORT_LEN +#define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */ +#endif + /** Empty masks for known item types. */ static const union { struct rte_flow_item_port_id port_id; @@ -230,6 +294,286 @@ struct flow_tcf_ptoi { (MLX5_FLOW_ACTION_OF_POP_VLAN | MLX5_FLOW_ACTION_OF_PUSH_VLAN | \ MLX5_FLOW_ACTION_OF_SET_VLAN_VID | MLX5_FLOW_ACTION_OF_SET_VLAN_PCP) =20 +#define MLX5_TCF_PEDIT_ACTIONS (MLX5_FLOW_ACTION_SET_IPV4_SRC | \ + MLX5_FLOW_ACTION_SET_IPV4_DST | \ + MLX5_FLOW_ACTION_SET_IPV6_SRC | \ + MLX5_FLOW_ACTION_SET_IPV6_DST | \ + MLX5_FLOW_ACTION_SET_TP_SRC | \ + MLX5_FLOW_ACTION_SET_TP_DST) + +#define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \ + MLX5_FLOW_ACTION_OF_PUSH_VLAN | \ + MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \ + MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \ + MLX5_TCF_PEDIT_ACTIONS) + +#define MAX_PEDIT_KEYS (128) +#define SZ_PEDIT_KEY_VAL (4) + +struct pedit_key_ex { + enum pedit_header_type htype; + enum pedit_cmd cmd; +}; + +struct pedit_parser { + struct tc_pedit_sel sel; + struct tc_pedit_key keys[MAX_PEDIT_KEYS]; + struct pedit_key_ex keys_ex[MAX_PEDIT_KEYS]; +}; + +/** + * Calculate how many pedit keys for a given + * size in byte + * + * @param[in] size + * size in byte + * @return + * number of pedit keys + */ +static int +flow_tcf_calc_pedit_keys(const uint64_t size) +{ + int keys =3D (size / SZ_PEDIT_KEY_VAL) + + ((size % SZ_PEDIT_KEY_VAL) ? 1 : 0); + return keys; +} + +/** + * Set pedit key of transport (TCP/UDP) port value + * + * @param[in] actions + * pointer to action specification + * @param[in,out] p_parser + * pointer to pedit_parser + * @param[in] item_flags + * flags of all items presented + */ +static void +flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions, + struct pedit_parser *p_parser, + uint64_t item_flags) +{ + int idx =3D p_parser->sel.nkeys; + + if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP) + p_parser->keys_ex[idx].htype =3D TCA_PEDIT_KEY_EX_HDR_TYPE_UDP; + if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP) + p_parser->keys_ex[idx].htype =3D TCA_PEDIT_KEY_EX_HDR_TYPE_TCP; + p_parser->keys_ex[idx].cmd =3D TCA_PEDIT_KEY_EX_CMD_SET; + assert(offsetof(struct tcp_hdr, src_port) =3D=3D + offsetof(struct udp_hdr, src_port)); + assert(offsetof(struct tcp_hdr, dst_port) =3D=3D + offsetof(struct udp_hdr, dst_port)); + p_parser->keys[idx].off =3D + actions->type =3D=3D RTE_FLOW_ACTION_TYPE_SET_TP_SRC ? + offsetof(struct tcp_hdr, src_port) : + offsetof(struct tcp_hdr, dst_port); + p_parser->keys[idx].mask =3D 0xFFFF0000; + p_parser->keys[idx].val =3D + (__u32)((const struct rte_flow_action_set_tp *) + actions->conf)->port; + p_parser->sel.nkeys =3D (++idx); +} + +/** + * Set pedit key of ipv6 address + * + * @param[in] actions + * pointer to action specification + * @param[in,out] p_parser + * pointer to pedit_parser + */ +static void +flow_tcf_pedit_key_set_ipv6_addr(const struct rte_flow_action *actions, + struct pedit_parser *p_parser) +{ + int idx =3D p_parser->sel.nkeys; + int keys =3D flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + int off_base =3D + actions->type =3D=3D RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ? + offsetof(struct ipv6_hdr, src_addr) : + offsetof(struct ipv6_hdr, dst_addr); + const struct rte_flow_action_set_ipv6 *conf =3D + (const struct rte_flow_action_set_ipv6 *)actions->conf; + + for (int i =3D 0; i < keys; i++, idx++) { + p_parser->keys_ex[idx].htype =3D TCA_PEDIT_KEY_EX_HDR_TYPE_IP6; + p_parser->keys_ex[idx].cmd =3D TCA_PEDIT_KEY_EX_CMD_SET; + p_parser->keys[idx].off =3D off_base + i * SZ_PEDIT_KEY_VAL; + p_parser->keys[idx].mask =3D ~UINT32_MAX; + memcpy(&p_parser->keys[idx].val, + conf->ipv6_addr + i * SZ_PEDIT_KEY_VAL, + SZ_PEDIT_KEY_VAL); + } + p_parser->sel.nkeys +=3D keys; +} + +/** + * Set pedit key of ipv4 address + * + * @param[in] actions + * pointer to action specification + * @param[in,out] p_parser + * pointer to pedit_parser + */ +static void +flow_tcf_pedit_key_set_ipv4_addr(const struct rte_flow_action *actions, + struct pedit_parser *p_parser) +{ + int idx =3D p_parser->sel.nkeys; + + p_parser->keys_ex[idx].htype =3D TCA_PEDIT_KEY_EX_HDR_TYPE_IP4; + p_parser->keys_ex[idx].cmd =3D TCA_PEDIT_KEY_EX_CMD_SET; + p_parser->keys[idx].off =3D + actions->type =3D=3D RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ? + offsetof(struct ipv4_hdr, src_addr) : + offsetof(struct ipv4_hdr, dst_addr); + p_parser->keys[idx].mask =3D ~UINT32_MAX; + p_parser->keys[idx].val =3D + ((const struct rte_flow_action_set_ipv4 *) + actions->conf)->ipv4_addr; + p_parser->sel.nkeys =3D (++idx); +} + +/** + * Create the pedit's na attribute in netlink message + * on pre-allocate message buffer + * + * @param[in,out] nl + * pointer to pre-allocated netlink message buffer + * @param[in,out] actions + * pointer to pointer of actions specification. + * @param[in,out] action_flags + * pointer to actions flags + * @param[in] item_flags + * flags of all item presented + * @return + * 0 on sucess + */ +static int +flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl, + const struct rte_flow_action **actions, + uint64_t item_flags) +{ + struct pedit_parser p_parser; + + memset(&p_parser, 0, sizeof(p_parser)); + mnl_attr_put_strz(nl, TCA_ACT_KIND, "pedit"); + struct nlattr *na_act_options =3D mnl_attr_nest_start(nl, + TCA_ACT_OPTIONS); + /* all modify header actions should be in one tc-pedit action */ + for (; (*actions)->type !=3D RTE_FLOW_ACTION_TYPE_END; (*actions)++) { + switch ((*actions)->type) { + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + flow_tcf_pedit_key_set_ipv4_addr(*actions, &p_parser); + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + flow_tcf_pedit_key_set_ipv6_addr(*actions, &p_parser); + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + flow_tcf_pedit_key_set_tp_port(*actions, + &p_parser, item_flags); + break; + default: + goto pedit_mnl_msg_done; + } + } +pedit_mnl_msg_done: + p_parser.sel.action =3D TC_ACT_PIPE; + mnl_attr_put(nl, TCA_PEDIT_PARMS_EX, + sizeof(p_parser.sel) + + p_parser.sel.nkeys * sizeof(struct tc_pedit_key), + &p_parser); + struct nlattr *na_pedit_keys =3D mnl_attr_nest_start(nl, + TCA_PEDIT_KEYS_EX | NLA_F_NESTED); + for (int i =3D 0; i < p_parser.sel.nkeys; i++) { + struct nlattr *na_pedit_key =3D mnl_attr_nest_start(nl, + TCA_PEDIT_KEY_EX | NLA_F_NESTED); + mnl_attr_put_u16(nl, TCA_PEDIT_KEY_EX_HTYPE, + p_parser.keys_ex[i].htype); + mnl_attr_put_u16(nl, TCA_PEDIT_KEY_EX_CMD, + p_parser.keys_ex[i].cmd); + mnl_attr_nest_end(nl, na_pedit_key); + } + mnl_attr_nest_end(nl, na_pedit_keys); + mnl_attr_nest_end(nl, na_act_options); + (*actions)--; + return 0; +} + +/** + * Calculate max memory size of one TC-pedit actions. + * One TC-pedit action can contain set of keys each defining + * a rewrite element (rte_flow action) + * + * @param[in,out] actions + * actions specification. + * @param[in,out] action_flags + * actions flags + * @param[in,out] size + * accumulated size + * @return + * Max memory size of one TC-pedit action + */ +static int +flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions, + uint64_t *action_flags) +{ + int pedit_size =3D 0; + int keys =3D 0; + uint64_t flags =3D 0; + + pedit_size +=3D SZ_NLATTR_NEST + /* na_act_index. */ + SZ_NLATTR_STRZ_OF("pedit") + + SZ_NLATTR_NEST; /* TCA_ACT_OPTIONS. */ + for (; (*actions)->type !=3D RTE_FLOW_ACTION_TYPE_END; (*actions)++) { + switch ((*actions)->type) { + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + keys +=3D flow_tcf_calc_pedit_keys(IPV4_ADDR_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_IPV4_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + keys +=3D flow_tcf_calc_pedit_keys(IPV4_ADDR_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_IPV4_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + keys +=3D flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_IPV6_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + keys +=3D flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_IPV6_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + /* TCP is as same as UDP */ + keys +=3D flow_tcf_calc_pedit_keys(TP_PORT_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_TP_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + /* TCP is as same as UDP */ + keys +=3D flow_tcf_calc_pedit_keys(TP_PORT_LEN); + flags |=3D MLX5_FLOW_ACTION_SET_TP_DST; + break; + default: + goto get_pedit_action_size_done; + } + } +get_pedit_action_size_done: + /* TCA_PEDIT_PARAMS_EX */ + pedit_size +=3D SZ_NLATTR_DATA_OF(sizeof(struct tc_pedit_sel) + + keys * sizeof(struct tc_pedit_key)); + pedit_size +=3D SZ_NLATTR_NEST; /* TCA_PEDIT_KEYS */ + pedit_size +=3D keys * + /* TCA_PEDIT_KEY_EX + HTYPE + CMD */ + (SZ_NLATTR_NEST + SZ_NLATTR_DATA_OF(2) + SZ_NLATTR_DATA_OF(2)); + (*action_flags) |=3D flags; + (*actions)--; + return pedit_size; +} + /** * Retrieve mask for pattern item. * @@ -433,11 +777,14 @@ flow_tcf_validate(struct rte_eth_dev *dev, of_set_vlan_vid; const struct rte_flow_action_of_set_vlan_pcp * of_set_vlan_pcp; + const struct rte_flow_action_set_ipv4 *set_ipv4; + const struct rte_flow_action_set_ipv6 *set_ipv6; } conf; uint32_t item_flags =3D 0; uint32_t action_flags =3D 0; uint8_t next_protocol =3D -1; unsigned int tcm_ifindex =3D 0; + uint8_t pedit_validated =3D 0; struct flow_tcf_ptoi ptoi[PTOI_TABLE_SZ_MAX(dev)]; struct rte_eth_dev *port_id_dev =3D NULL; bool in_port_id_set; @@ -648,16 +995,20 @@ flow_tcf_validate(struct rte_eth_dev *dev, } for (; actions->type !=3D RTE_FLOW_ACTION_TYPE_END; actions++) { unsigned int i; + uint32_t current_action_flag =3D 0; =20 switch (actions->type) { case RTE_FLOW_ACTION_TYPE_VOID: break; case RTE_FLOW_ACTION_TYPE_PORT_ID: + current_action_flag =3D MLX5_FLOW_ACTION_PORT_ID; if (action_flags & MLX5_TCF_FATE_ACTIONS) return rte_flow_error_set (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, actions, "can't have multiple fate actions"); + if (!actions->conf) + break; conf.port_id =3D actions->conf; if (conf.port_id->original) i =3D 0; @@ -672,7 +1023,6 @@ flow_tcf_validate(struct rte_eth_dev *dev, conf.port_id, "missing data to convert port ID to" " ifindex"); - action_flags |=3D MLX5_FLOW_ACTION_PORT_ID; port_id_dev =3D &rte_eth_devices[conf.port_id->id]; break; case RTE_FLOW_ACTION_TYPE_DROP: @@ -681,13 +1031,13 @@ flow_tcf_validate(struct rte_eth_dev *dev, (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, actions, "can't have multiple fate actions"); - action_flags |=3D MLX5_FLOW_ACTION_DROP; + current_action_flag =3D MLX5_FLOW_ACTION_DROP; break; case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN: - action_flags |=3D MLX5_FLOW_ACTION_OF_POP_VLAN; + current_action_flag =3D MLX5_FLOW_ACTION_OF_POP_VLAN; break; case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN: - action_flags |=3D MLX5_FLOW_ACTION_OF_PUSH_VLAN; + current_action_flag =3D MLX5_FLOW_ACTION_OF_PUSH_VLAN; break; case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID: if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)) @@ -696,7 +1046,7 @@ flow_tcf_validate(struct rte_eth_dev *dev, RTE_FLOW_ERROR_TYPE_ACTION, actions, "vlan modify is not supported," " set action must follow push action"); - action_flags |=3D MLX5_FLOW_ACTION_OF_SET_VLAN_VID; + current_action_flag =3D MLX5_FLOW_ACTION_OF_SET_VLAN_VID; break; case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP: if (!(action_flags & MLX5_FLOW_ACTION_OF_PUSH_VLAN)) @@ -705,7 +1055,25 @@ flow_tcf_validate(struct rte_eth_dev *dev, RTE_FLOW_ERROR_TYPE_ACTION, actions, "vlan modify is not supported," " set action must follow push action"); - action_flags |=3D MLX5_FLOW_ACTION_OF_SET_VLAN_PCP; + current_action_flag =3D MLX5_FLOW_ACTION_OF_SET_VLAN_PCP; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + current_action_flag =3D MLX5_FLOW_ACTION_SET_IPV4_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + current_action_flag =3D MLX5_FLOW_ACTION_SET_IPV4_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + current_action_flag =3D MLX5_FLOW_ACTION_SET_IPV6_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + current_action_flag =3D MLX5_FLOW_ACTION_SET_IPV6_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + current_action_flag =3D MLX5_FLOW_ACTION_SET_TP_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + current_action_flag =3D MLX5_FLOW_ACTION_SET_TP_DST; break; default: return rte_flow_error_set(error, ENOTSUP, @@ -713,6 +1081,66 @@ flow_tcf_validate(struct rte_eth_dev *dev, actions, "action not supported"); } + if (current_action_flag & MLX5_TCF_CONFIG_ACTIONS) { + if (!actions->conf) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + actions, + "action configuration not set"); + } + if ((current_action_flag & MLX5_TCF_PEDIT_ACTIONS) && + pedit_validated) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "not successive pedit " + "actions"); + if ((current_action_flag & ~MLX5_TCF_PEDIT_ACTIONS) && + (action_flags & MLX5_TCF_PEDIT_ACTIONS)) + pedit_validated =3D 1; + action_flags |=3D current_action_flag; + } + if ((action_flags & MLX5_TCF_PEDIT_ACTIONS) && + (action_flags & MLX5_FLOW_ACTION_DROP)) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "actions are not compatible"); + if ((action_flags & MLX5_TCF_PEDIT_ACTIONS) && + !(action_flags & MLX5_FLOW_ACTION_PORT_ID)) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "pedit action must be followed by " + "port_id action"); + if (action_flags & + (MLX5_FLOW_ACTION_SET_IPV4_SRC | MLX5_FLOW_ACTION_SET_IPV4_DST)) { + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4)) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no ipv4 item found in" + " pattern"); + } + if (action_flags & + (MLX5_FLOW_ACTION_SET_IPV6_SRC | MLX5_FLOW_ACTION_SET_IPV6_DST)) { + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no ipv6 item found in" + " pattern"); + } + if (action_flags & + (MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST)) { + if (!(item_flags & + (MLX5_FLOW_LAYER_OUTER_L4_UDP | + MLX5_FLOW_LAYER_OUTER_L4_TCP))) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no TCP/UDP item found in" + " pattern"); } /* * FW syndrome (0xA9C090): @@ -884,6 +1312,15 @@ flow_tcf_get_actions_and_size(const struct rte_flow_a= ction actions[], SZ_NLATTR_TYPE_OF(uint16_t) + /* VLAN ID. */ SZ_NLATTR_TYPE_OF(uint8_t); /* VLAN prio. */ break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + size +=3D flow_tcf_get_pedit_actions_size(&actions, + &flags); + break; default: DRV_LOG(WARNING, "unsupported action %p type %d," @@ -1042,6 +1479,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, struct nlattr *na_flower_act; struct nlattr *na_vlan_id =3D NULL; struct nlattr *na_vlan_priority =3D NULL; + uint64_t item_flags =3D 0; =20 claim_nonzero(flow_tcf_build_ptoi_table(dev, ptoi, PTOI_TABLE_SZ_MAX(dev))); @@ -1088,6 +1526,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, tcm->tcm_ifindex =3D ptoi[i].ifindex; break; case RTE_FLOW_ITEM_TYPE_ETH: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_L2; mask.eth =3D flow_tcf_item_mask (items, &rte_flow_item_eth_mask, &flow_tcf_mask_supported.eth, @@ -1121,6 +1560,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_VLAN: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_VLAN; mask.vlan =3D flow_tcf_item_mask (items, &rte_flow_item_vlan_mask, &flow_tcf_mask_supported.vlan, @@ -1153,6 +1593,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, RTE_BE16(0x0fff))); break; case RTE_FLOW_ITEM_TYPE_IPV4: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_L3_IPV4; mask.ipv4 =3D flow_tcf_item_mask (items, &rte_flow_item_ipv4_mask, &flow_tcf_mask_supported.ipv4, @@ -1192,6 +1633,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_IPV6: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_L3_IPV6; mask.ipv6 =3D flow_tcf_item_mask (items, &rte_flow_item_ipv6_mask, &flow_tcf_mask_supported.ipv6, @@ -1233,6 +1675,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_UDP: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_L4_UDP; mask.udp =3D flow_tcf_item_mask (items, &rte_flow_item_udp_mask, &flow_tcf_mask_supported.udp, @@ -1262,6 +1705,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct ml= x5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_TCP: + item_flags |=3D MLX5_FLOW_LAYER_OUTER_L4_TCP; mask.tcp =3D flow_tcf_item_mask (items, &rte_flow_item_tcp_mask, &flow_tcf_mask_supported.tcp, @@ -1412,6 +1856,18 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct m= lx5_flow *dev_flow, conf.of_set_vlan_pcp->vlan_pcp; } break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + na_act_index =3D + mnl_attr_nest_start(nlh, na_act_index_cur++); + flow_tcf_create_pedit_mnl_msg(nlh, + &actions, item_flags); + mnl_attr_nest_end(nlh, na_act_index); + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, --=20 2.17.1