From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0087.outbound.protection.outlook.com [104.47.1.87]) by dpdk.org (Postfix) with ESMTP id 8B3A51B100 for ; Tue, 25 Sep 2018 13:52:15 +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=Sojj+Akfuk0A1eRKUFAGdjHBe+8CVtw0Kk7Pl8TQFJM=; b=UTUsyY4kTqkNGGc3bpZipTKLhY4EJ+4Jsq3oVtQBhZ6V56deDKO898IJgRNaN3Ej/R6o6seKabcQQ5H3Ca5i9AzIGsax4os0NbwavTvNRywJxY1xr5v0drZnvWiUXqks5qgU0V1VkDJUdTDWSH+ph2a0HlSFEtqqncwuvyAWjTU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=jackmin@mellanox.com; Received: from dev-r630-08.mtbc.labs.mlnx (118.201.220.138) by VI1PR0501MB2029.eurprd05.prod.outlook.com (2603:10a6:800:36::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.22; Tue, 25 Sep 2018 11:52:11 +0000 From: Xiaoyu Min To: Shahaf Shuler , Yongseok Koh Cc: dev@dpdk.org Date: Tue, 25 Sep 2018 19:51:06 +0800 Message-Id: <20180925115107.12242-1-jackmin@mellanox.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [118.201.220.138] X-ClientProxiedBy: SG2PR01CA0111.apcprd01.prod.exchangelabs.com (2603:1096:4:40::15) To VI1PR0501MB2029.eurprd05.prod.outlook.com (2603:10a6:800:36::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22a15d1a-0748-4a7d-1f2f-08d622dd553c X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:VI1PR0501MB2029; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2029; 3:j8P+OMkSW3Gvc1jIYUsEN0SbAsgFKZkoPTZ45KLsOTldk/8M8rcomzi3MTRc7+WOjnQFZnICwgcVFMXlmb49ynKmMhTl7GyXwhZ4xoH9sE8Hwv3UNZOfOCGXeePIY+3xXS/ql2MyRFh1YapzHQAKHQa4h3TWqeo7o9KybcZ3rhWJj0ezrK47B86obEnsPWqPa4a8vuXj2nqxWjG6GbxXFr1Zy/g/MW7SHoNEu91oCwJCtPwukpwpOcMm9wYkJGRc; 25:EhkhAzlVASYGKjtSLBvyQPaeNSTksVIfsZF8ovj+q8to4b/NgVbMJSL5zalrTfbartpne9QxEURIWvAWsRjoqfAYYVf9dbPbXM8AooG9L770x7iPqRPM+UkORQOqedUcBntAa+cwkkW4KzQHsnHgaw+5ry4IQCcRGTI8G96CM4jXnc11bzilfZ5Bpzds1yZwJ7Gdrl4ciGdxW/j/ZQD7R1y9IIMcc9zQB4NCQrUKIpe84K8TtVhJN50puTwZijw2lCVxGpUvb+TjkiWugc9ZqZgabc82f9qJyf/I0iZMVjr76aiR1jlQohiLPetpJ7GmvB5Rm90aP9SJCjMJoTlN2Q==; 31:9z3q6I8PCapO8w6BSyH/hC9O3wCWpb+ruwHSayg+5CcjAWleCL1N9GYZv5dSUWmrZOfkUHLC95fS6M6i9YO1qvl4d5VO2JEi9qeA8+h7q5+SzhHFBchFRXIt7SiiY/7Cg5gE6N7CMPx5HTIkXhvnPDmYJdMjG/s0Sxdnnn9jiCBmXsUDFis9FIf95xkb+3yuqgnf00epQwBW9nErBlu6HDtkLKmIfkm4Ox43IxsHnG4= X-MS-TrafficTypeDiagnostic: VI1PR0501MB2029: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2029; 20:d/Mqbp5ck+VJ9CQlAUyKQvX8j46qz6HLrfT0195EHWcwRgUOa6vkEkbzg3bHhQlTFxl4GBoNpceCpEixhYXAoWijPjB0FZW8Z7xeKpd7lHK0K3bMsW6QLoKzV5kbnjX4aKn+4V0T6xVcbZ8dnvF2OJDyCoZtAZvSboUpvwFKe36/Lm4a8Sxl3TrnwZ3Qug7aZVW12UfKFvztCMd0+s1GYaxqc0TMZkc4psu9rSG4l+f/gPv6vtf1jK8l+YMIlozK1wwTNyVLtAFjtHGTadbS3AJ7I2ySMNQI89gNHGDZXu67i+d0JlX+D85xTJGlkgwFCmjG4BOrwUp8OhfDHtiPnBU9p6XBELjamSUSanE5wLEZEDSEcXbMYx8hvfFvDI2vjmgt7JsllaXhuE46MlmiOwPFzrTi/AmGN9PPhD9JhCZrnfSCmAXLRKbu2/ogEfCvv16eMeie6Y3FHvXqIFKoT8jyoWOxwB+t81D8blYLRv3W0FGeWn6bPV9AXDBqQAHL; 4:wx2pnQV1Dz1LHql4V0AoZbLbe0eGQ2WxhZjuM1nTm0HZe3DT6oK+Fyf4rJSuvz9TJMLRk/iWMJeXC45SSx3c2y2vngV6Z2NNsKvb1tkSvLIgv7HqquJhRFJVnHv6S5HgyMBMEfaDq/yauHqlid8TsWeWcWh/CNRlmKNUW6zKeBE5qJe03e+OFITGAwinHu6CU/320sCKn5tjor391+NDAfTTmt1uTaYUhkElW75015q2sTmH+wmEgBe14BaTW2zZ6RBCEo+QzdAdiUXR0emVtg== 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)(93006095)(93001095)(10201501046)(3231355)(944501410)(52105095)(3002001)(6055026)(149066)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(20161123558120)(201708071742011)(7699051); SRVR:VI1PR0501MB2029; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2029; X-Forefront-PRVS: 08062C429B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(376002)(39860400002)(346002)(136003)(396003)(199004)(189003)(486006)(66066001)(6506007)(6486002)(6306002)(97736004)(16586007)(53936002)(110136005)(386003)(6512007)(86362001)(34290500001)(36756003)(316002)(2906002)(51416003)(50466002)(85306007)(52116002)(105586002)(48376002)(14444005)(5660300001)(106356001)(1857600001)(25786009)(966005)(16526019)(4326008)(26005)(2616005)(6116002)(3846002)(1076002)(305945005)(6666003)(81166006)(476003)(8676002)(81156014)(50226002)(68736007)(47776003)(956004)(7736002)(8936002)(478600001)(6636002); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2029; H:dev-r630-08.mtbc.labs.mlnx; 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-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2029; 23:f+pc4Npl3vbvbA5fb8jRqq2aPnkDe3LMfWjjQ6/?= =?us-ascii?Q?K6vYu+dq3C8swyIzC4nvkjzQmI/hExL2pCCnMCR+C2H4M3pa7kh0PclP2jBS?= =?us-ascii?Q?IHFyCzNQV/fkg5s7R44wXUqeocOqsWlG11O0V9prOJCM7s6jbaqOyezSKMmr?= =?us-ascii?Q?RqY2z1GgfvCfH/w0YdIl/KJqgjkCfW8FPDrMwJ87anXY/ytT3vOkCFfoyWM+?= =?us-ascii?Q?apZQ+BzfKNtIfD/9CSQBqiXQAMFUlm5xO1CsV4qCKuAZ9/9JOP18uOsOaPaU?= =?us-ascii?Q?BreQylZbGMPznHlSX/sNtgw5cbaqFku14EbxNL2JY4h2sFvugyI6SWBiCh/J?= =?us-ascii?Q?9wgUNLmVZUSiJMeCONv+U0KV3xOjn2GNFMUJAPVrsTRaxrW21zr2vykam/jD?= =?us-ascii?Q?TV0oL5EXI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 7:nkTibkZlp8KZDSrvXeshBqJH07yUz9uMYl48vRdo02QZXqB/m9F21guqnxjFqV9gv5qeCQkRk//4KZ4QkmrSYqGRqRdgo0/gUHk88k7PQ14JThS1Dm7UnPWhnvIlpiB6m6VUELt646oYCYtfKhR1QeXkaTrQsTogfk3fNIklDcILkSJwArcuy0Bnew5SjYwdRBoJWbGnF4+R62uqAj7q3AYRQ6hRLAdEAvQ1ktMzyVYU5qRCrwkcbQgCjWlfy71S SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2018 11:52:11.5433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22a15d1a-0748-4a7d-1f2f-08d622dd553c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2029 Subject: [dpdk-dev] [PATCH] net/mlx5: eswitch-IP address UDP/TCP port rewrite 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: Tue, 25 Sep 2018 11:52:15 -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 Signed-off-by: Xiaoyu Min --- This patch bases on Rahul Lakkireddy's patchs[1][2] and Yongseok Koh's patchset [3] [1] https://patches.dpdk.org/patch/45191/ [2] https://patches.dpdk.org/patch/45192/ [3] https://patches.dpdk.org/project/dpdk/list/?series=1474 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 | 356 +++++++++++++++++++++++++++++++ 4 files changed, 369 insertions(+) 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 10d700a7f..be182a643 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -87,6 +87,12 @@ #define MLX5_ACTION_OF_PUSH_VLAN (1u << 8) #define MLX5_ACTION_OF_SET_VLAN_VID (1u << 9) #define MLX5_ACTION_OF_SET_VLAN_PCP (1u << 10) +#define MLX5_ACTION_SET_IPV4_SRC (1u << 11) +#define MLX5_ACTION_SET_IPV4_DST (1u << 12) +#define MLX5_ACTION_SET_IPV6_SRC (1u << 13) +#define MLX5_ACTION_SET_IPV6_DST (1u << 14) +#define MLX5_ACTION_SET_TP_SRC (1u << 15) +#define MLX5_ACTION_SET_TP_DST (1u << 16) /* possible L3 layers protocols filtering. */ #define MLX5_IP_PROTOCOL_TCP 6 diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c index 14376188e..85c92f369 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -53,6 +53,62 @@ struct tc_vlan { #endif /* HAVE_TC_ACT_VLAN */ +#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 = 1, + TCA_PEDIT_KEY_EX_CMD = 2, + __TCA_PEDIT_KEY_EX_MAX +}; + +enum pedit_header_type { + TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK = 0, + TCA_PEDIT_KEY_EX_HDR_TYPE_ETH = 1, + TCA_PEDIT_KEY_EX_HDR_TYPE_IP4 = 2, + TCA_PEDIT_KEY_EX_HDR_TYPE_IP6 = 3, + TCA_PEDIT_KEY_EX_HDR_TYPE_TCP = 4, + TCA_PEDIT_KEY_EX_HDR_TYPE_UDP = 5, + __PEDIT_HDR_TYPE_MAX, +}; + +enum pedit_cmd { + TCA_PEDIT_KEY_EX_CMD_SET = 0, + TCA_PEDIT_KEY_EX_CMD_ADD = 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 +#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; @@ -227,6 +291,220 @@ struct flow_tcf_ptoi { #define MLX5_TCF_FATE_ACTIONS (MLX5_ACTION_DROP | MLX5_ACTION_PORT_ID) +#define IS_MODIFY_ACTION(act_) ({typeof(act_) act = (act_); \ + ((act) == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC || \ + (act) == RTE_FLOW_ACTION_TYPE_SET_IPV4_DST || \ + (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC || \ + (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST || \ + (act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \ + (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ? \ + 1 : 0; }) +#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]; +}; + +static int +flow_tcf_calc_pedit_keys(const uint64_t size) +{ + int keys = (size / SZ_PEDIT_KEY_VAL) + + ((size % SZ_PEDIT_KEY_VAL) ? 1 : 0); + return keys; +} + +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 = p_parser->sel.nkeys; + + if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_UDP) + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP; + if (item_flags & MLX5_FLOW_LAYER_OUTER_L4_TCP) + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP; + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET; + p_parser->keys[idx].off = + actions->type == RTE_FLOW_ACTION_TYPE_SET_TP_DST ? 2 : 0; + p_parser->keys[idx].mask = 0xFFFF0000; + p_parser->keys[idx].val = ((const struct rte_flow_action_set_tp *) + actions->conf)->port; + p_parser->sel.nkeys = (++idx); +} + +static void +flow_tcf_pedit_key_set_ipv6_addr(const struct rte_flow_action *actions, + struct pedit_parser *p_parser) +{ + int idx = p_parser->sel.nkeys; + int keys = flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + int off_base = + actions->type == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC ? 8 : 24; + const struct rte_flow_action_set_ipv6 *conf = + (const struct rte_flow_action_set_ipv6 *)actions->conf; + + for (int i = 0; i < keys; i++, idx++) { + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6; + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET; + p_parser->keys[idx].off = off_base + i * SZ_PEDIT_KEY_VAL; + p_parser->keys[idx].mask = ~UINT32_MAX; + memcpy(&p_parser->keys[idx].val, + conf->ipv6_addr + i * SZ_PEDIT_KEY_VAL, + SZ_PEDIT_KEY_VAL); + } + p_parser->sel.nkeys += keys; +} + +static void +flow_tcf_pedit_key_set_ipv4_addr(const struct rte_flow_action *actions, + struct pedit_parser *p_parser) +{ + int idx = p_parser->sel.nkeys; + + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4; + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET; + p_parser->keys[idx].off = + (actions->type == RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC ? 12 : 16); + p_parser->keys[idx].mask = ~UINT32_MAX; + p_parser->keys[idx].val = + ((const struct rte_flow_action_set_ipv4 *) + actions->conf)->ipv4_addr; + p_parser->sel.nkeys = (++idx); +} + +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 = mnl_attr_nest_start(nl, + TCA_ACT_OPTIONS); + /* all modify header actions should be in one tc-pedit action */ + for (; (*actions)->type != 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 = 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 = mnl_attr_nest_start(nl, + TCA_PEDIT_KEYS_EX | NLA_F_NESTED); + for (int i = 0; i < p_parser.sel.nkeys; i++) { + struct nlattr *na_pedit_key = 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] actions + * actions specification. + * @param[inout] action_flags + * actions flags + * @param[inout] 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 = 0; + int keys = 0; + uint64_t flags = 0; + + pedit_size += SZ_NLATTR_NEST + /* na_act_index. */ + SZ_NLATTR_STRZ_OF("pedit") + + SZ_NLATTR_NEST; /* TCA_ACT_OPTIONS. */ + for (; (*actions)->type != RTE_FLOW_ACTION_TYPE_END; (*actions)++) { + switch ((*actions)->type) { + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + keys += flow_tcf_calc_pedit_keys(IPV4_ADDR_LEN); + flags |= MLX5_ACTION_SET_IPV4_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + keys += flow_tcf_calc_pedit_keys(IPV4_ADDR_LEN); + flags |= MLX5_ACTION_SET_IPV4_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + keys += flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + flags |= MLX5_ACTION_SET_IPV6_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + keys += flow_tcf_calc_pedit_keys(IPV6_ADDR_LEN); + flags |= MLX5_ACTION_SET_IPV6_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + /* TCP is as same as UDP */ + keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN); + flags |= MLX5_ACTION_SET_TP_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + /* TCP is as same as UDP */ + keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN); + flags |= MLX5_ACTION_SET_TP_DST; + break; + default: + goto get_pedit_action_size_done; + } + } +get_pedit_action_size_done: + /* TCA_PEDIT_PARAMS_EX */ + pedit_size += SZ_NLATTR_DATA_OF(sizeof(struct tc_pedit_sel) + + keys * sizeof(struct tc_pedit_key)); + pedit_size += SZ_NLATTR_NEST; /* TCA_PEDIT_KEYS */ + pedit_size += keys * + /* TCA_PEDIT_KEY_EX + HTYPE + CMD */ + (SZ_NLATTR_NEST + SZ_NLATTR_DATA_OF(2) + SZ_NLATTR_DATA_OF(2)); + (*action_flags) |= flags; + (*actions)--; + return pedit_size; +} + /** * Retrieve mask for pattern item. * @@ -430,6 +708,8 @@ 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 = 0; uint32_t action_flags = 0; @@ -690,12 +970,64 @@ flow_tcf_validate(struct rte_eth_dev *dev, case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP: action_flags |= MLX5_ACTION_OF_SET_VLAN_PCP; break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_SRC: + action_flags |= MLX5_ACTION_SET_IPV4_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV4_DST: + action_flags |= MLX5_ACTION_SET_IPV4_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC: + action_flags |= MLX5_ACTION_SET_IPV6_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST: + action_flags |= MLX5_ACTION_SET_IPV6_DST; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_SRC: + action_flags |= MLX5_ACTION_SET_TP_SRC; + break; + case RTE_FLOW_ACTION_TYPE_SET_TP_DST: + action_flags |= MLX5_ACTION_SET_TP_DST; + break; default: return rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions, "action not supported"); } + if (IS_MODIFY_ACTION(actions->type)) { + if (!actions->conf) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION_CONF, + actions, + "action configuration not set"); + } + } + if (action_flags & + (MLX5_ACTION_SET_IPV4_SRC | MLX5_ACTION_SET_IPV4_DST)) { + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4)) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no ipv4 item found in" + " pattern"); + } + if (action_flags & + (MLX5_ACTION_SET_IPV6_SRC | MLX5_ACTION_SET_IPV6_DST)) { + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6)) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no ipv6 item found in pattern"); + } + if (action_flags & (MLX5_ACTION_SET_TP_SRC | MLX5_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, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + actions, + "no TCP/UDP item found in" + " pattern"); } return 0; } @@ -840,6 +1172,15 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action 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 += flow_tcf_get_pedit_actions_size(&actions, + &flags); + break; default: DRV_LOG(WARNING, "unsupported action %p type %d," @@ -998,6 +1339,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow, struct nlattr *na_flower_act; struct nlattr *na_vlan_id = NULL; struct nlattr *na_vlan_priority = NULL; + uint64_t item_flags = 0; claim_nonzero(flow_tcf_build_ptoi_table(dev, ptoi, PTOI_TABLE_SZ_MAX(dev))); @@ -1189,6 +1531,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_UDP: + item_flags |= MLX5_FLOW_LAYER_OUTER_L4_UDP; mask.udp = flow_tcf_item_mask (items, &rte_flow_item_udp_mask, &flow_tcf_mask_supported.udp, @@ -1218,6 +1561,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow, } break; case RTE_FLOW_ITEM_TYPE_TCP: + item_flags |= MLX5_FLOW_LAYER_OUTER_L4_TCP; mask.tcp = flow_tcf_item_mask (items, &rte_flow_item_tcp_mask, &flow_tcf_mask_supported.tcp, @@ -1368,6 +1712,18 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_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 = + 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, -- 2.17.1