From: Jack Min <jackmin@mellanox.com>
To: Shahaf Shuler <shahafs@mellanox.com>, Yongseok Koh <yskoh@mellanox.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH v4 3/3] net/mlx5: rewrite TTL by E-Switch
Date: Thu, 11 Oct 2018 13:27:24 +0000 [thread overview]
Message-ID: <20181011132641.1000-4-jackmin@mellanox.com> (raw)
In-Reply-To: <20181011132641.1000-1-jackmin@mellanox.com>
Offload following modify TTL actions to E-Switch via
TC-Flower driver
- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL
The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error
The example testpmd commands are:
flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end
actions dec_ttl /
port_id id 1 / end
flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7001 / end
actions set_ttl ttl_value 10 /
port_id id 1 / end
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 82 +++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index c592828b5..cb07cf652 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -84,6 +84,8 @@
#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)
+#define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
+#define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
#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 44c899830..a0a3680d5 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -218,6 +218,10 @@ struct tc_pedit_sel {
#define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
#endif
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
/** Empty masks for known item types. */
static const union {
struct rte_flow_item_port_id port_id;
@@ -298,12 +302,13 @@ struct flow_tcf_ptoi {
#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)
+ MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST | \
+ MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)
#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)
+ (MLX5_TCF_PEDIT_ACTIONS & ~MLX5_FLOW_ACTION_DEC_TTL))
#define MAX_PEDIT_KEYS 128
#define SZ_PEDIT_KEY_VAL 4
@@ -323,6 +328,46 @@ struct pedit_parser {
};
+/**
+ * Set pedit key of decrease/set ttl
+ *
+ * @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_dec_ttl(const struct rte_flow_action *actions,
+ struct pedit_parser *p_parser,
+ uint64_t item_flags)
+{
+ int idx = p_parser->sel.nkeys;
+
+ p_parser->keys[idx].mask = 0xFFFFFF00;
+ if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+ p_parser->keys[idx].off =
+ offsetof(struct ipv4_hdr, time_to_live);
+ }
+ if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+ p_parser->keys[idx].off =
+ offsetof(struct ipv6_hdr, hop_limits);
+ }
+ if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+ p_parser->keys[idx].val = 0x000000FF;
+ } else {
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ p_parser->keys[idx].val =
+ (__u32)((const struct rte_flow_action_set_ttl *)
+ actions->conf)->ttl_value;
+ }
+ p_parser->sel.nkeys = (++idx);
+}
+
/**
* Set pedit key of transport (TCP/UDP) port value
*
@@ -458,6 +503,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
flow_tcf_pedit_key_set_tp_port(*actions,
&p_parser, item_flags);
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ flow_tcf_pedit_key_set_dec_ttl(*actions,
+ &p_parser, item_flags);
+ break;
default:
goto pedit_mnl_msg_done;
}
@@ -538,6 +588,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
keys += NUM_OF_PEDIT_KEYS(TP_PORT_LEN);
flags |= MLX5_FLOW_ACTION_SET_TP_DST;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+ flags |= MLX5_FLOW_ACTION_SET_TTL;
+ break;
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+ flags |= MLX5_FLOW_ACTION_DEC_TTL;
+ break;
default:
goto get_pedit_action_size_done;
}
@@ -1058,6 +1116,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+ break;
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
+ break;
default:
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1153,6 +1217,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
return rte_flow_error_set(error, EINVAL,
RTE_FLOW_ERROR_TYPE_ACTION, actions,
"no fate action is found");
+ if (action_flags &
+ (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
+ if (!(item_flags &
+ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+ MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+ return rte_flow_error_set(error, EINVAL,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ actions,
+ "no IP found in pattern");
+ }
return 0;
}
@@ -1302,6 +1376,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
size += flow_tcf_get_pedit_actions_size(&actions,
&flags);
break;
@@ -1846,6 +1922,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
na_act_index =
mnl_attr_nest_start(nlh, na_act_index_cur++);
flow_tcf_create_pedit_mnl_msg(nlh,
--
2.17.1
next prev parent reply other threads:[~2018-10-11 13:27 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
2018-10-03 20:07 ` Yongseok Koh
2018-10-08 6:57 ` Xiaoyu Min
2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
2018-10-03 19:50 ` Yongseok Koh
2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
2018-10-03 19:51 ` Yongseok Koh
2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
2018-10-05 12:48 ` Ferruh Yigit
2018-10-05 18:17 ` Yongseok Koh
2018-10-03 20:35 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Thomas Monjalon
2018-10-05 12:52 ` Ferruh Yigit
2018-10-08 2:30 ` Xiaoyu Min
2018-10-10 13:05 ` [dpdk-dev] [PATCH v3 " Jack Min
2018-10-10 13:05 ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
2018-10-10 13:05 ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-10 13:06 ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
2018-10-11 5:47 ` Yongseok Koh
2018-10-11 13:27 ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-11 13:27 ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
2018-10-12 14:12 ` Ferruh Yigit
2018-10-13 2:16 ` Jack Min
2018-10-11 13:27 ` [dpdk-dev] [PATCH v4 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-11 13:27 ` Jack Min [this message]
2018-10-13 3:24 ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-13 3:24 ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
2018-10-14 7:35 ` Andrew Rybchenko
2018-10-16 2:03 ` Jack Min
2018-10-13 3:24 ` [dpdk-dev] [PATCH v5 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-13 3:24 ` [dpdk-dev] [PATCH v5 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
2018-10-16 8:14 ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-16 8:14 ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
2018-10-16 8:25 ` Andrew Rybchenko
2018-10-16 8:48 ` Ferruh Yigit
2018-10-16 8:14 ` [dpdk-dev] [PATCH v6 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-16 8:14 ` [dpdk-dev] [PATCH v6 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181011132641.1000-4-jackmin@mellanox.com \
--to=jackmin@mellanox.com \
--cc=dev@dpdk.org \
--cc=shahafs@mellanox.com \
--cc=yskoh@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).