* [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions
@ 2018-09-25 15:03 Xiaoyu Min
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
` (4 more replies)
0 siblings, 5 replies; 20+ messages in thread
From: Xiaoyu Min @ 2018-09-25 15:03 UTC (permalink / raw)
To: ferruh.yigit; +Cc: dev
This series is for RFC[1]
Patch 1 adds generic MAC address rewrite actions to flow API
Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
[1]: https://patches.dpdk.org/patch/44005/
Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: eswitch-modify MAC address actions
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++
app/test-pmd/config.c | 4 ++
doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 +++
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 62 ++++++++++++++++++++-
lib/librte_ethdev/rte_flow.c | 2 +
lib/librte_ethdev/rte_flow.h | 29 ++++++++++
8 files changed, 186 insertions(+), 1 deletion(-)
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH 1/3] ethdev: add generic MAC address rewrite actions
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
@ 2018-09-25 15:03 ` Xiaoyu Min
2018-10-03 20:08 ` Yongseok Koh
2018-10-08 9:31 ` Andrew Rybchenko
2018-09-25 15:03 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address Xiaoyu Min
` (3 subsequent siblings)
4 siblings, 2 replies; 20+ messages in thread
From: Xiaoyu Min @ 2018-09-25 15:03 UTC (permalink / raw)
To: ferruh.yigit, Adrien Mazarguil, John McNamara, Marko Kovacevic,
Thomas Monjalon, Andrew Rybchenko
Cc: dev
rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC
The rte_flow_itme_eth must be present in rte_flow pattern
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
lib/librte_ethdev/rte_flow.c | 2 ++
lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 3aec0834b..5ecf154b6 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2196,6 +2196,36 @@ Assigns a new TTL value.
| ``ttl_value`` | new TTL value |
+---------------+--------------------+
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
Negative types
~~~~~~~~~~~~~~
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 631f80efd..1f4b67603 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -123,6 +123,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
sizeof(struct rte_flow_action_set_tp)),
MK_FLOW_ACTION(DEC_TTL, 0),
MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+ MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+ MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
};
static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index b41e37a31..19552902a 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1567,6 +1567,26 @@ enum rte_flow_action_type {
* See struct rte_flow_action_set_ttl
*/
RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+ /**
+ * Set source MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+ /**
+ * Set destination MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
};
/**
@@ -1986,6 +2006,15 @@ struct rte_flow_action_set_ttl {
uint8_t ttl_value;
};
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+ uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
/*
* Definition of a single action.
*
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
@ 2018-09-25 15:03 ` Xiaoyu Min
2018-10-03 20:09 ` Yongseok Koh
2018-09-25 15:03 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions Xiaoyu Min
` (2 subsequent siblings)
4 siblings, 1 reply; 20+ messages in thread
From: Xiaoyu Min @ 2018-09-25 15:03 UTC (permalink / raw)
To: ferruh.yigit, Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu,
Bernard Iremonger, John McNamara, Marko Kovacevic
Cc: dev
add commands to support following actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++++++
app/test-pmd/config.c | 4 ++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 ++++
3 files changed, 62 insertions(+)
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index fae825462..d06e75799 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -258,6 +258,10 @@ enum index {
ACTION_DEC_TTL,
ACTION_SET_TTL,
ACTION_SET_TTL_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_SET_MAC_DST,
+ ACTION_SET_MAC_DST_MAC_DST,
};
/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -839,6 +843,8 @@ static const enum index next_action[] = {
ACTION_SET_TP_DST,
ACTION_DEC_TTL,
ACTION_SET_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_DST,
ZERO,
};
@@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
ZERO,
};
+static const enum index action_set_mac_src[] = {
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_NEXT,
+ ZERO,
+};
+
static const enum index action_set_ipv4_dst[] = {
ACTION_SET_IPV4_DST_IPV4_DST,
ACTION_NEXT,
@@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
ZERO,
};
+static const enum index action_set_mac_dst[] = {
+ ACTION_SET_MAC_DST_MAC_DST,
+ ACTION_NEXT,
+ ZERO,
+};
+
static int parse_init(struct context *, const struct token *,
const char *, unsigned int,
void *, unsigned int);
@@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
(struct rte_flow_action_set_ttl, ttl_value)),
.call = parse_vc_conf,
},
+ [ACTION_SET_MAC_SRC] = {
+ .name = "set_mac_src",
+ .help = "set source mac address",
+ .priv = PRIV_ACTION(SET_MAC_SRC,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_src),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_SRC_MAC_SRC] = {
+ .name = "mac_addr",
+ .help = "new source mac address",
+ .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
+ [ACTION_SET_MAC_DST] = {
+ .name = "set_mac_dst",
+ .help = "set destination mac address",
+ .priv = PRIV_ACTION(SET_MAC_DST,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_dst),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_DST_MAC_DST] = {
+ .name = "mac_addr",
+ .help = "new destination mac address to set",
+ .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
};
/** Remove and return last entry from argument stack. */
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index d28b6ed14..c2cbf5ce8 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1177,6 +1177,10 @@ static const struct {
MK_FLOW_ACTION(DEC_TTL, 0),
MK_FLOW_ACTION(SET_TTL,
sizeof(struct rte_flow_action_set_ttl)),
+ MK_FLOW_ACTION(SET_MAC_SRC,
+ sizeof(struct rte_flow_action_set_mac)),
+ MK_FLOW_ACTION(SET_MAC_DST,
+ sizeof(struct rte_flow_action_set_mac)),
};
/** Compute storage space needed by action configuration and copy it. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index db68c4346..0a8cc73a3 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3726,6 +3726,14 @@ This section lists supported actions and their attributes, if any.
- ``set_ttl``: Set TTL value with specificed value
- ``ttl_value {unsigned}``: The new TTL value to be set
+- ``set_mac_src``: set source MAC address
+
+ - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+ - ``mac_addr {MAC-48}``: new destination MAC address
+
Destroying flow rules
~~~~~~~~~~~~~~~~~~~~~
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
2018-09-25 15:03 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address Xiaoyu Min
@ 2018-09-25 15:03 ` Xiaoyu Min
2018-10-03 20:10 ` Yongseok Koh
2018-10-05 12:54 ` [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
4 siblings, 1 reply; 20+ messages in thread
From: Xiaoyu Min @ 2018-09-25 15:03 UTC (permalink / raw)
To: ferruh.yigit, Shahaf Shuler, Yongseok Koh; +Cc: dev
Offload following modify MAC address actions to E-Switch
via TC-Flower driver
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
The corresponding rte_flow_item_eth must be present in
rte_flow pattern
Only support modify outer layer MAC address
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
drivers/net/mlx5/mlx5_flow.h | 2 ++
drivers/net/mlx5/mlx5_flow_tcf.c | 62 +++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 5237e31dd..76c4e8398 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -95,6 +95,8 @@
#define MLX5_ACTION_SET_TP_DST (1u << 16)
#define MLX5_ACTION_SET_TTL (1u << 17)
#define MLX5_ACTION_DEC_TTL (1u << 18)
+#define MLX5_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_ACTION_SET_MAC_DST (1u << 20)
/* 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 af88c4a0d..cb60c3e05 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -303,7 +303,9 @@ struct flow_tcf_ptoi {
(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \
(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST || \
(act) == RTE_FLOW_ACTION_TYPE_SET_TTL || \
- (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ? \
+ (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL || \
+ (act) == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC || \
+ (act) == RTE_FLOW_ACTION_TYPE_SET_MAC_DST) ? \
1 : 0; })
#define MAX_PEDIT_KEYS (128)
#define SZ_PEDIT_KEY_VAL (4)
@@ -327,6 +329,33 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
return keys;
}
+static void
+flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
+ struct pedit_parser *p_parser)
+{
+ int idx = p_parser->sel.nkeys;
+ uint32_t off =
+ actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ? 6 : 0;
+ const struct rte_flow_action_set_mac *conf =
+ (const struct rte_flow_action_set_mac *)actions->conf;
+
+ p_parser->keys[idx].off = off;
+ p_parser->keys[idx].mask = ~UINT32_MAX;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr, SZ_PEDIT_KEY_VAL);
+ idx++;
+ p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
+ p_parser->keys[idx].mask = 0xFFFF0000;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr + SZ_PEDIT_KEY_VAL,
+ ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
+ p_parser->sel.nkeys = (++idx);
+}
+
static void
flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
struct pedit_parser *p_parser,
@@ -447,6 +476,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
flow_tcf_pedit_key_set_dec_ttl(*actions,
&p_parser, item_flags);
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ flow_tcf_pedit_key_set_mac(*actions, &p_parser);
+ break;
default:
goto pedit_mnl_msg_done;
}
@@ -535,6 +568,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
keys += flow_tcf_calc_pedit_keys(TTL_LEN);
flags |= MLX5_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+ flags |= MLX5_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+ flags |= MLX5_ACTION_SET_MAC_DST;
+ break;
default:
goto get_pedit_action_size_done;
}
@@ -1041,6 +1082,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
action_flags |= MLX5_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ action_flags |= MLX5_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ action_flags |= MLX5_ACTION_SET_MAC_DST;
+ break;
default:
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1093,6 +1140,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
actions,
"no IP found in pattern");
}
+ if (action_flags &
+ (MLX5_ACTION_SET_MAC_SRC | MLX5_ACTION_SET_MAC_DST)) {
+ if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ actions,
+ "no ethernet found in"
+ " pattern");
+ }
return 0;
}
@@ -1244,6 +1300,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
size += flow_tcf_get_pedit_actions_size(&actions,
&flags);
break;
@@ -1788,6 +1846,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
na_act_index =
mnl_attr_nest_start(nlh, na_act_index_cur++);
flow_tcf_create_pedit_mnl_msg(nlh,
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 1/3] ethdev: add generic MAC address rewrite actions
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
@ 2018-10-03 20:08 ` Yongseok Koh
2018-10-08 9:31 ` Andrew Rybchenko
1 sibling, 0 replies; 20+ messages in thread
From: Yongseok Koh @ 2018-10-03 20:08 UTC (permalink / raw)
To: Jack Min
Cc: ferruh.yigit, Adrien Mazarguil, John McNamara, Marko Kovacevic,
Thomas Monjalon, Andrew Rybchenko, dev
On Tue, Sep 25, 2018 at 11:03:38PM +0800, Xiaoyu Min wrote:
> rte_flow actions:
> - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
> - RTE_FLOW_ACTION_TYPE_SET_MAC_DST
> added in order to offload to NIC
>
> The rte_flow_itme_eth must be present in rte_flow pattern
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
Acked-by: Yongseok Koh <yskoh@mellanox.com>
Thanks
> doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
> lib/librte_ethdev/rte_flow.c | 2 ++
> lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
> 3 files changed, 61 insertions(+)
>
> diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
> index 3aec0834b..5ecf154b6 100644
> --- a/doc/guides/prog_guide/rte_flow.rst
> +++ b/doc/guides/prog_guide/rte_flow.rst
> @@ -2196,6 +2196,36 @@ Assigns a new TTL value.
> | ``ttl_value`` | new TTL value |
> +---------------+--------------------+
>
> +Action: ``SET_MAC_SRC``
> +^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set source MAC address
> +
> +.. _table_rte_flow_action_set_mac_src:
> +
> +.. table:: SET_MAC_SRC
> +
> + +--------------+---------------+
> + | Field | Value |
> + +==============+===============+
> + | ``mac_addr`` | MAC address |
> + +--------------+---------------+
> +
> +Action: ``SET_MAC_DST``
> +^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set source MAC address
> +
> +.. _table_rte_flow_action_set_mac_dst:
> +
> +.. table:: SET_MAC_DST
> +
> + +--------------+---------------+
> + | Field | Value |
> + +==============+===============+
> + | ``mac_addr`` | MAC address |
> + +--------------+---------------+
> +
> Negative types
> ~~~~~~~~~~~~~~
>
> diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
> index 631f80efd..1f4b67603 100644
> --- a/lib/librte_ethdev/rte_flow.c
> +++ b/lib/librte_ethdev/rte_flow.c
> @@ -123,6 +123,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
> sizeof(struct rte_flow_action_set_tp)),
> MK_FLOW_ACTION(DEC_TTL, 0),
> MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
> + MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
> + MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
> };
>
> static int
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index b41e37a31..19552902a 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1567,6 +1567,26 @@ enum rte_flow_action_type {
> * See struct rte_flow_action_set_ttl
> */
> RTE_FLOW_ACTION_TYPE_SET_TTL,
> +
> + /**
> + * Set source MAC address from matched flow.
> + *
> + * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
> + * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
> + *
> + * See struct rte_flow_action_set_mac.
> + */
> + RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
> +
> + /**
> + * Set destination MAC address from matched flow.
> + *
> + * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
> + * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
> + *
> + * See struct rte_flow_action_set_mac.
> + */
> + RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
> };
>
> /**
> @@ -1986,6 +2006,15 @@ struct rte_flow_action_set_ttl {
> uint8_t ttl_value;
> };
>
> +/**
> + * RTE_FLOW_ACTION_TYPE_SET_MAC
> + *
> + * Set MAC address from the matched flow
> + */
> +struct rte_flow_action_set_mac {
> + uint8_t mac_addr[ETHER_ADDR_LEN];
> +};
> +
> /*
> * Definition of a single action.
> *
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address
2018-09-25 15:03 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address Xiaoyu Min
@ 2018-10-03 20:09 ` Yongseok Koh
0 siblings, 0 replies; 20+ messages in thread
From: Yongseok Koh @ 2018-10-03 20:09 UTC (permalink / raw)
To: Jack Min
Cc: ferruh.yigit, Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu,
Bernard Iremonger, John McNamara, Marko Kovacevic, dev
On Tue, Sep 25, 2018 at 11:03:39PM +0800, Xiaoyu Min wrote:
> add commands to support following actions:
>
> - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
> - RTE_FLOW_ACTION_TYPE_SET_MAC_DST
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
Acked-by: Yongseok Koh <yskoh@mellanox.com>
Thanks
> app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++++++
> app/test-pmd/config.c | 4 ++
> doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 ++++
> 3 files changed, 62 insertions(+)
>
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index fae825462..d06e75799 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -258,6 +258,10 @@ enum index {
> ACTION_DEC_TTL,
> ACTION_SET_TTL,
> ACTION_SET_TTL_TTL,
> + ACTION_SET_MAC_SRC,
> + ACTION_SET_MAC_SRC_MAC_SRC,
> + ACTION_SET_MAC_DST,
> + ACTION_SET_MAC_DST_MAC_DST,
> };
>
> /** Maximum size for pattern in struct rte_flow_item_raw. */
> @@ -839,6 +843,8 @@ static const enum index next_action[] = {
> ACTION_SET_TP_DST,
> ACTION_DEC_TTL,
> ACTION_SET_TTL,
> + ACTION_SET_MAC_SRC,
> + ACTION_SET_MAC_DST,
> ZERO,
> };
>
> @@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
> ZERO,
> };
>
> +static const enum index action_set_mac_src[] = {
> + ACTION_SET_MAC_SRC_MAC_SRC,
> + ACTION_NEXT,
> + ZERO,
> +};
> +
> static const enum index action_set_ipv4_dst[] = {
> ACTION_SET_IPV4_DST_IPV4_DST,
> ACTION_NEXT,
> @@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
> ZERO,
> };
>
> +static const enum index action_set_mac_dst[] = {
> + ACTION_SET_MAC_DST_MAC_DST,
> + ACTION_NEXT,
> + ZERO,
> +};
> +
> static int parse_init(struct context *, const struct token *,
> const char *, unsigned int,
> void *, unsigned int);
> @@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
> (struct rte_flow_action_set_ttl, ttl_value)),
> .call = parse_vc_conf,
> },
> + [ACTION_SET_MAC_SRC] = {
> + .name = "set_mac_src",
> + .help = "set source mac address",
> + .priv = PRIV_ACTION(SET_MAC_SRC,
> + sizeof(struct rte_flow_action_set_mac)),
> + .next = NEXT(action_set_mac_src),
> + .call = parse_vc,
> + },
> + [ACTION_SET_MAC_SRC_MAC_SRC] = {
> + .name = "mac_addr",
> + .help = "new source mac address",
> + .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
> + .args = ARGS(ARGS_ENTRY_HTON
> + (struct rte_flow_action_set_mac, mac_addr)),
> + .call = parse_vc_conf,
> + },
> + [ACTION_SET_MAC_DST] = {
> + .name = "set_mac_dst",
> + .help = "set destination mac address",
> + .priv = PRIV_ACTION(SET_MAC_DST,
> + sizeof(struct rte_flow_action_set_mac)),
> + .next = NEXT(action_set_mac_dst),
> + .call = parse_vc,
> + },
> + [ACTION_SET_MAC_DST_MAC_DST] = {
> + .name = "mac_addr",
> + .help = "new destination mac address to set",
> + .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
> + .args = ARGS(ARGS_ENTRY_HTON
> + (struct rte_flow_action_set_mac, mac_addr)),
> + .call = parse_vc_conf,
> + },
> };
>
> /** Remove and return last entry from argument stack. */
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index d28b6ed14..c2cbf5ce8 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -1177,6 +1177,10 @@ static const struct {
> MK_FLOW_ACTION(DEC_TTL, 0),
> MK_FLOW_ACTION(SET_TTL,
> sizeof(struct rte_flow_action_set_ttl)),
> + MK_FLOW_ACTION(SET_MAC_SRC,
> + sizeof(struct rte_flow_action_set_mac)),
> + MK_FLOW_ACTION(SET_MAC_DST,
> + sizeof(struct rte_flow_action_set_mac)),
> };
>
> /** Compute storage space needed by action configuration and copy it. */
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index db68c4346..0a8cc73a3 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -3726,6 +3726,14 @@ This section lists supported actions and their attributes, if any.
> - ``set_ttl``: Set TTL value with specificed value
> - ``ttl_value {unsigned}``: The new TTL value to be set
>
> +- ``set_mac_src``: set source MAC address
> +
> + - ``mac_addr {MAC-48}``: new source MAC address
> +
> +- ``set_mac_dst``: set destination MAC address
> +
> + - ``mac_addr {MAC-48}``: new destination MAC address
> +
> Destroying flow rules
> ~~~~~~~~~~~~~~~~~~~~~
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions
2018-09-25 15:03 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions Xiaoyu Min
@ 2018-10-03 20:10 ` Yongseok Koh
0 siblings, 0 replies; 20+ messages in thread
From: Yongseok Koh @ 2018-10-03 20:10 UTC (permalink / raw)
To: Jack Min; +Cc: ferruh.yigit, Shahaf Shuler, dev
On Tue, Sep 25, 2018 at 11:03:40PM +0800, Xiaoyu Min wrote:
> Offload following modify MAC address actions to E-Switch
> via TC-Flower driver
>
> - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
> - RTE_FLOW_ACTION_TYPE_SET_MAC_DST
>
> The corresponding rte_flow_item_eth must be present in
> rte_flow pattern
>
> Only support modify outer layer MAC address
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
Same comments as before.
Thanks,
Yongseok
> drivers/net/mlx5/mlx5_flow.h | 2 ++
> drivers/net/mlx5/mlx5_flow_tcf.c | 62 +++++++++++++++++++++++++++++++-
> 2 files changed, 63 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index 5237e31dd..76c4e8398 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -95,6 +95,8 @@
> #define MLX5_ACTION_SET_TP_DST (1u << 16)
> #define MLX5_ACTION_SET_TTL (1u << 17)
> #define MLX5_ACTION_DEC_TTL (1u << 18)
> +#define MLX5_ACTION_SET_MAC_SRC (1u << 19)
> +#define MLX5_ACTION_SET_MAC_DST (1u << 20)
>
> /* 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 af88c4a0d..cb60c3e05 100644
> --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> @@ -303,7 +303,9 @@ struct flow_tcf_ptoi {
> (act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \
> (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST || \
> (act) == RTE_FLOW_ACTION_TYPE_SET_TTL || \
> - (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ? \
> + (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL || \
> + (act) == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC || \
> + (act) == RTE_FLOW_ACTION_TYPE_SET_MAC_DST) ? \
> 1 : 0; })
> #define MAX_PEDIT_KEYS (128)
> #define SZ_PEDIT_KEY_VAL (4)
> @@ -327,6 +329,33 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
> return keys;
> }
>
> +static void
> +flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
> + struct pedit_parser *p_parser)
> +{
> + int idx = p_parser->sel.nkeys;
> + uint32_t off =
> + actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ? 6 : 0;
> + const struct rte_flow_action_set_mac *conf =
> + (const struct rte_flow_action_set_mac *)actions->conf;
> +
> + p_parser->keys[idx].off = off;
> + p_parser->keys[idx].mask = ~UINT32_MAX;
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> + memcpy(&p_parser->keys[idx].val,
> + conf->mac_addr, SZ_PEDIT_KEY_VAL);
> + idx++;
> + p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
> + p_parser->keys[idx].mask = 0xFFFF0000;
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> + memcpy(&p_parser->keys[idx].val,
> + conf->mac_addr + SZ_PEDIT_KEY_VAL,
> + ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
> + p_parser->sel.nkeys = (++idx);
> +}
> +
> static void
> flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> struct pedit_parser *p_parser,
> @@ -447,6 +476,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
> flow_tcf_pedit_key_set_dec_ttl(*actions,
> &p_parser, item_flags);
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + flow_tcf_pedit_key_set_mac(*actions, &p_parser);
> + break;
> default:
> goto pedit_mnl_msg_done;
> }
> @@ -535,6 +568,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
> keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> flags |= MLX5_ACTION_DEC_TTL;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
> + flags |= MLX5_ACTION_SET_MAC_SRC;
> + break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
> + flags |= MLX5_ACTION_SET_MAC_DST;
> + break;
> default:
> goto get_pedit_action_size_done;
> }
> @@ -1041,6 +1082,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> action_flags |= MLX5_ACTION_DEC_TTL;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + action_flags |= MLX5_ACTION_SET_MAC_SRC;
> + break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + action_flags |= MLX5_ACTION_SET_MAC_DST;
> + break;
> default:
> return rte_flow_error_set(error, ENOTSUP,
> RTE_FLOW_ERROR_TYPE_ACTION,
> @@ -1093,6 +1140,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> actions,
> "no IP found in pattern");
> }
> + if (action_flags &
> + (MLX5_ACTION_SET_MAC_SRC | MLX5_ACTION_SET_MAC_DST)) {
> + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
> + return rte_flow_error_set(error, ENOTSUP,
> + RTE_FLOW_ERROR_TYPE_ACTION,
> + actions,
> + "no ethernet found in"
> + " pattern");
> + }
> return 0;
> }
>
> @@ -1244,6 +1300,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TTL:
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> size += flow_tcf_get_pedit_actions_size(&actions,
> &flags);
> break;
> @@ -1788,6 +1846,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TTL:
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> na_act_index =
> mnl_attr_nest_start(nlh, na_act_index_cur++);
> flow_tcf_create_pedit_mnl_msg(nlh,
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
` (2 preceding siblings ...)
2018-09-25 15:03 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions Xiaoyu Min
@ 2018-10-05 12:54 ` Ferruh Yigit
2018-10-08 2:32 ` Xiaoyu Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
4 siblings, 1 reply; 20+ messages in thread
From: Ferruh Yigit @ 2018-10-05 12:54 UTC (permalink / raw)
To: Xiaoyu Min; +Cc: dev
On 9/25/2018 4:03 PM, Xiaoyu Min wrote:
> This series is for RFC[1]
>
> Patch 1 adds generic MAC address rewrite actions to flow API
> Patch 2 adds testpmd commands for that
> Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
>
> [1]: https://patches.dpdk.org/patch/44005/
>
> Xiaoyu Min (3):
> ethdev: add generic MAC address rewrite actions
> app/testpmd: add commands of modify MAC address
> net/mlx5: eswitch-modify MAC address actions
Same here, can you please rebase and send new version?
And it looks like there are change requests to mlx5 patch.
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions
2018-10-05 12:54 ` [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
@ 2018-10-08 2:32 ` Xiaoyu Min
0 siblings, 0 replies; 20+ messages in thread
From: Xiaoyu Min @ 2018-10-08 2:32 UTC (permalink / raw)
To: Ferruh Yigit; +Cc: dev
On 18-10-05 13:54:38, Ferruh Yigit wrote:
> On 9/25/2018 4:03 PM, Xiaoyu Min wrote:
> > This series is for RFC[1]
> >
> > Patch 1 adds generic MAC address rewrite actions to flow API
> > Patch 2 adds testpmd commands for that
> > Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
> >
> > [1]: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatches.dpdk.org%2Fpatch%2F44005%2F&data=02%7C01%7Cjackmin%40mellanox.com%7C47ee836f61fc48f0d5fa08d62ac1b9b4%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636743408874175728&sdata=8KZfEwLk4zC0%2BBIWhRtFVcSKQ%2Fmqe6StiU79eseNARs%3D&reserved=0
> >
> > Xiaoyu Min (3):
> > ethdev: add generic MAC address rewrite actions
> > app/testpmd: add commands of modify MAC address
> > net/mlx5: eswitch-modify MAC address actions
>
> Same here, can you please rebase and send new version?
> And it looks like there are change requests to mlx5 patch.
Sure, I will do that
-Jack
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH 1/3] ethdev: add generic MAC address rewrite actions
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
2018-10-03 20:08 ` Yongseok Koh
@ 2018-10-08 9:31 ` Andrew Rybchenko
1 sibling, 0 replies; 20+ messages in thread
From: Andrew Rybchenko @ 2018-10-08 9:31 UTC (permalink / raw)
To: Xiaoyu Min, ferruh.yigit, Adrien Mazarguil, John McNamara,
Marko Kovacevic, Thomas Monjalon
Cc: dev
On 9/25/18 6:03 PM, Xiaoyu Min wrote:
> rte_flow actions:
> - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
> - RTE_FLOW_ACTION_TYPE_SET_MAC_DST
> added in order to offload to NIC
>
> The rte_flow_itme_eth must be present in rte_flow pattern
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v2 0/3] ethdev: add generic MAC address rewrite actions
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
` (3 preceding siblings ...)
2018-10-05 12:54 ` [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
@ 2018-10-10 13:11 ` Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 1/3] " Jack Min
` (3 more replies)
4 siblings, 4 replies; 20+ messages in thread
From: Jack Min @ 2018-10-10 13:11 UTC (permalink / raw)
Cc: dev
This series is for RFC[1] and depends on patch[2]
Patch 1 adds generic MAC address rewrite actions to flow API
Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
[1]: https://patches.dpdk.org/patch/44005/
[2]: https://patches.dpdk.org/patch/46495/
v2:
* rebased
* changed commit message title
* added example testpmd command in commit log
* changes in validation
Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: rewrite MAC address by E-Switch
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++
doc/guides/prog_guide/rte_flow.rst | 30 +++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 +++
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 71 ++++++++++++++++++++-
lib/librte_ethdev/rte_flow.c | 2 +
lib/librte_ethdev/rte_flow.h | 29 +++++++++
7 files changed, 191 insertions(+), 1 deletion(-)
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v2 1/3] ethdev: add generic MAC address rewrite actions
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
@ 2018-10-10 13:11 ` Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify MAC address Jack Min
` (2 subsequent siblings)
3 siblings, 0 replies; 20+ messages in thread
From: Jack Min @ 2018-10-10 13:11 UTC (permalink / raw)
To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
Cc: dev
rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC
The rte_flow_itme_eth must be present in rte_flow pattern
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
lib/librte_ethdev/rte_flow.c | 2 ++
lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index e8df1e488..d0f2d8b54 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2196,6 +2196,36 @@ Assigns a new TTL value.
| ``ttl_value`` | new TTL value |
+---------------+--------------------+
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
Negative types
~~~~~~~~~~~~~~
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 458a05994..810069935 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -137,6 +137,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
sizeof(struct rte_flow_action_set_tp)),
MK_FLOW_ACTION(DEC_TTL, 0),
MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+ MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+ MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
};
static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index bb07eba9d..4193f4e05 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1568,6 +1568,26 @@ enum rte_flow_action_type {
* See struct rte_flow_action_set_ttl
*/
RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+ /**
+ * Set source MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+ /**
+ * Set destination MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
};
/**
@@ -1987,6 +2007,15 @@ struct rte_flow_action_set_ttl {
uint8_t ttl_value;
};
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+ uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
/*
* Definition of a single action.
*
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify MAC address
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 1/3] " Jack Min
@ 2018-10-10 13:11 ` Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
3 siblings, 0 replies; 20+ messages in thread
From: Jack Min @ 2018-10-10 13:11 UTC (permalink / raw)
To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
John McNamara, Marko Kovacevic
Cc: dev
add commands to support following actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 ++++
2 files changed, 58 insertions(+)
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index fae825462..d06e75799 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -258,6 +258,10 @@ enum index {
ACTION_DEC_TTL,
ACTION_SET_TTL,
ACTION_SET_TTL_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_SET_MAC_DST,
+ ACTION_SET_MAC_DST_MAC_DST,
};
/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -839,6 +843,8 @@ static const enum index next_action[] = {
ACTION_SET_TP_DST,
ACTION_DEC_TTL,
ACTION_SET_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_DST,
ZERO,
};
@@ -947,6 +953,12 @@ static const enum index action_set_ipv4_src[] = {
ZERO,
};
+static const enum index action_set_mac_src[] = {
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_NEXT,
+ ZERO,
+};
+
static const enum index action_set_ipv4_dst[] = {
ACTION_SET_IPV4_DST_IPV4_DST,
ACTION_NEXT,
@@ -989,6 +1001,12 @@ static const enum index action_jump[] = {
ZERO,
};
+static const enum index action_set_mac_dst[] = {
+ ACTION_SET_MAC_DST_MAC_DST,
+ ACTION_NEXT,
+ ZERO,
+};
+
static int parse_init(struct context *, const struct token *,
const char *, unsigned int,
void *, unsigned int);
@@ -2654,6 +2672,38 @@ static const struct token token_list[] = {
(struct rte_flow_action_set_ttl, ttl_value)),
.call = parse_vc_conf,
},
+ [ACTION_SET_MAC_SRC] = {
+ .name = "set_mac_src",
+ .help = "set source mac address",
+ .priv = PRIV_ACTION(SET_MAC_SRC,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_src),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_SRC_MAC_SRC] = {
+ .name = "mac_addr",
+ .help = "new source mac address",
+ .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
+ [ACTION_SET_MAC_DST] = {
+ .name = "set_mac_dst",
+ .help = "set destination mac address",
+ .priv = PRIV_ACTION(SET_MAC_DST,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_dst),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_DST_MAC_DST] = {
+ .name = "mac_addr",
+ .help = "new destination mac address to set",
+ .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
};
/** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 16cd4468e..ab478fa96 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3733,6 +3733,14 @@ This section lists supported actions and their attributes, if any.
- ``set_ttl``: Set TTL value with specificed value
- ``ttl_value {unsigned}``: The new TTL value to be set
+- ``set_mac_src``: set source MAC address
+
+ - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+ - ``mac_addr {MAC-48}``: new destination MAC address
+
Destroying flow rules
~~~~~~~~~~~~~~~~~~~~~
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 1/3] " Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify MAC address Jack Min
@ 2018-10-10 13:11 ` Jack Min
2018-10-11 5:51 ` Yongseok Koh
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
3 siblings, 1 reply; 20+ messages in thread
From: Jack Min @ 2018-10-10 13:11 UTC (permalink / raw)
To: Shahaf Shuler, Yongseok Koh; +Cc: dev
Offload following modify MAC address actions to E-Switch
via TC-Flower driver
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
The corresponding rte_flow_item_eth must be present in
rte_flow pattern
Only support modify outer layer MAC address
The example testpmd command is:
flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end
actions set_mac_dst mac_addr dd:00:aa:11:bb:33 /
set_mac_src mac_addr bb:00:cc:11:aa:22 /
port_id id 1 / end
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 71 +++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 0ad8c12ea..22e648b36 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -86,6 +86,8 @@
#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_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 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 af8a68529..c10fdd3fb 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -305,7 +305,9 @@ struct flow_tcf_ptoi {
MLX5_FLOW_ACTION_SET_TP_SRC | \
MLX5_FLOW_ACTION_SET_TP_DST | \
MLX5_FLOW_ACTION_SET_TTL | \
- MLX5_FLOW_ACTION_DEC_TTL)
+ MLX5_FLOW_ACTION_DEC_TTL | \
+ MLX5_FLOW_ACTION_SET_MAC_SRC | \
+ MLX5_FLOW_ACTION_SET_MAC_DST)
#define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \
MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
@@ -345,6 +347,42 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
return keys;
}
+/**
+ * Set pedit key of MAC address
+ *
+ * @param[in] actions
+ * pointer to action specification
+ * @param[in,out] p_parser
+ * pointer to pedit_parser
+ */
+static void
+flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
+ struct pedit_parser *p_parser)
+{
+ int idx = p_parser->sel.nkeys;
+ uint32_t off = actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
+ offsetof(struct ether_hdr, s_addr) :
+ offsetof(struct ether_hdr, d_addr);
+ const struct rte_flow_action_set_mac *conf =
+ (const struct rte_flow_action_set_mac *)actions->conf;
+
+ p_parser->keys[idx].off = off;
+ p_parser->keys[idx].mask = ~UINT32_MAX;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr, SZ_PEDIT_KEY_VAL);
+ idx++;
+ p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
+ p_parser->keys[idx].mask = 0xFFFF0000;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr + SZ_PEDIT_KEY_VAL,
+ ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
+ p_parser->sel.nkeys = (++idx);
+}
+
/**
* Set pedit key of decrease/set ttl
*
@@ -529,6 +567,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
flow_tcf_pedit_key_set_dec_ttl(*actions,
&p_parser, item_flags);
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ flow_tcf_pedit_key_set_mac(*actions, &p_parser);
+ break;
default:
goto pedit_mnl_msg_done;
}
@@ -617,6 +659,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
keys += flow_tcf_calc_pedit_keys(TTL_LEN);
flags |= MLX5_FLOW_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+ flags |= MLX5_FLOW_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
+ flags |= MLX5_FLOW_ACTION_SET_MAC_DST;
+ break;
default:
goto get_pedit_action_size_done;
}
@@ -1141,6 +1191,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ current_action_flag = MLX5_FLOW_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ current_action_flag = MLX5_FLOW_ACTION_SET_MAC_DST;
+ break;
default:
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1245,6 +1301,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
actions,
"no IP found in pattern");
}
+ if (action_flags &
+ (MLX5_FLOW_ACTION_SET_MAC_SRC | MLX5_FLOW_ACTION_SET_MAC_DST)) {
+ if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ actions,
+ "no ethernet found in"
+ " pattern");
+ }
return 0;
}
@@ -1396,6 +1461,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
size += flow_tcf_get_pedit_actions_size(&actions,
&flags);
break;
@@ -1942,6 +2009,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
na_act_index =
mnl_attr_nest_start(nlh, na_act_index_cur++);
flow_tcf_create_pedit_mnl_msg(nlh,
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
@ 2018-10-11 5:51 ` Yongseok Koh
0 siblings, 0 replies; 20+ messages in thread
From: Yongseok Koh @ 2018-10-11 5:51 UTC (permalink / raw)
To: Jack Min; +Cc: Shahaf Shuler, dev
On Wed, Oct 10, 2018 at 06:11:45AM -0700, Jack Min wrote:
> Offload following modify MAC address actions to E-Switch
> via TC-Flower driver
>
> - RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
> - RTE_FLOW_ACTION_TYPE_SET_MAC_DST
>
> The corresponding rte_flow_item_eth must be present in
> rte_flow pattern
>
> Only support modify outer layer MAC address
>
> The example testpmd command is:
>
> flow create 0 transfer ingress
> pattern eth / ipv4 / udp dst is 7000 / end
> actions set_mac_dst mac_addr dd:00:aa:11:bb:33 /
> set_mac_src mac_addr bb:00:cc:11:aa:22 /
> port_id id 1 / end
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
Acked-by: Yongseok Koh <yskoh@mellanox.com>
But you'll also need to rebase it on your other patchsets.
Thanks
> drivers/net/mlx5/mlx5_flow.h | 2 +
> drivers/net/mlx5/mlx5_flow_tcf.c | 71 +++++++++++++++++++++++++++++++-
> 2 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index 0ad8c12ea..22e648b36 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -86,6 +86,8 @@
> #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_ACTION_SET_MAC_SRC (1u << 19)
> +#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 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 af8a68529..c10fdd3fb 100644
> --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> @@ -305,7 +305,9 @@ struct flow_tcf_ptoi {
> MLX5_FLOW_ACTION_SET_TP_SRC | \
> MLX5_FLOW_ACTION_SET_TP_DST | \
> MLX5_FLOW_ACTION_SET_TTL | \
> - MLX5_FLOW_ACTION_DEC_TTL)
> + MLX5_FLOW_ACTION_DEC_TTL | \
> + MLX5_FLOW_ACTION_SET_MAC_SRC | \
> + MLX5_FLOW_ACTION_SET_MAC_DST)
>
> #define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \
> MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
> @@ -345,6 +347,42 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
> return keys;
> }
>
> +/**
> + * Set pedit key of MAC address
> + *
> + * @param[in] actions
> + * pointer to action specification
> + * @param[in,out] p_parser
> + * pointer to pedit_parser
> + */
> +static void
> +flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
> + struct pedit_parser *p_parser)
> +{
> + int idx = p_parser->sel.nkeys;
> + uint32_t off = actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
> + offsetof(struct ether_hdr, s_addr) :
> + offsetof(struct ether_hdr, d_addr);
> + const struct rte_flow_action_set_mac *conf =
> + (const struct rte_flow_action_set_mac *)actions->conf;
> +
> + p_parser->keys[idx].off = off;
> + p_parser->keys[idx].mask = ~UINT32_MAX;
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> + memcpy(&p_parser->keys[idx].val,
> + conf->mac_addr, SZ_PEDIT_KEY_VAL);
> + idx++;
> + p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
> + p_parser->keys[idx].mask = 0xFFFF0000;
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> + memcpy(&p_parser->keys[idx].val,
> + conf->mac_addr + SZ_PEDIT_KEY_VAL,
> + ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
> + p_parser->sel.nkeys = (++idx);
> +}
> +
> /**
> * Set pedit key of decrease/set ttl
> *
> @@ -529,6 +567,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
> flow_tcf_pedit_key_set_dec_ttl(*actions,
> &p_parser, item_flags);
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + flow_tcf_pedit_key_set_mac(*actions, &p_parser);
> + break;
> default:
> goto pedit_mnl_msg_done;
> }
> @@ -617,6 +659,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
> keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> flags |= MLX5_FLOW_ACTION_DEC_TTL;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
> + flags |= MLX5_FLOW_ACTION_SET_MAC_SRC;
> + break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + keys += flow_tcf_calc_pedit_keys(ETHER_ADDR_LEN);
> + flags |= MLX5_FLOW_ACTION_SET_MAC_DST;
> + break;
> default:
> goto get_pedit_action_size_done;
> }
> @@ -1141,6 +1191,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + current_action_flag = MLX5_FLOW_ACTION_SET_MAC_SRC;
> + break;
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> + current_action_flag = MLX5_FLOW_ACTION_SET_MAC_DST;
> + break;
> default:
> return rte_flow_error_set(error, ENOTSUP,
> RTE_FLOW_ERROR_TYPE_ACTION,
> @@ -1245,6 +1301,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> actions,
> "no IP found in pattern");
> }
> + if (action_flags &
> + (MLX5_FLOW_ACTION_SET_MAC_SRC | MLX5_FLOW_ACTION_SET_MAC_DST)) {
> + if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
> + return rte_flow_error_set(error, ENOTSUP,
> + RTE_FLOW_ERROR_TYPE_ACTION,
> + actions,
> + "no ethernet found in"
> + " pattern");
> + }
> return 0;
> }
>
> @@ -1396,6 +1461,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TTL:
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> size += flow_tcf_get_pedit_actions_size(&actions,
> &flags);
> break;
> @@ -1942,6 +2009,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TTL:
> case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
> + case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
> na_act_index =
> mnl_attr_nest_start(nlh, na_act_index_cur++);
> flow_tcf_create_pedit_mnl_msg(nlh,
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
` (2 preceding siblings ...)
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
@ 2018-10-11 13:31 ` Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
` (3 more replies)
3 siblings, 4 replies; 20+ messages in thread
From: Jack Min @ 2018-10-11 13:31 UTC (permalink / raw)
Cc: dev
This series is for RFC[1] and depends on patch[2]
Patch 1 adds generic MAC address rewrite actions to flow API
Patch 2 adds testpmd commands for that
Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
[1]: https://patches.dpdk.org/patch/44005/
[2]: http://patches.dpdk.org/patch/46625/
v2:
* rebased
* changed commit message title
* added example testpmd command in commit log
* changes in validation
v3:
* fix some coding style issues
* use macro of calc pedit keys
* rebased
Xiaoyu Min (3):
ethdev: add generic MAC address rewrite actions
app/testpmd: add commands of modify MAC address
net/mlx5: rewrite MAC address by E-Switch
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++
doc/guides/prog_guide/rte_flow.rst | 30 +++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 +++
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 70 ++++++++++++++++++++-
lib/librte_ethdev/rte_flow.c | 2 +
lib/librte_ethdev/rte_flow.h | 29 +++++++++
7 files changed, 190 insertions(+), 1 deletion(-)
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 1/3] ethdev: add generic MAC address rewrite actions
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
@ 2018-10-11 13:31 ` Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify MAC address Jack Min
` (2 subsequent siblings)
3 siblings, 0 replies; 20+ messages in thread
From: Jack Min @ 2018-10-11 13:31 UTC (permalink / raw)
To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
Cc: dev
rte_flow actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
added in order to offload to NIC
The rte_flow_itme_eth must be present in rte_flow pattern
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
doc/guides/prog_guide/rte_flow.rst | 30 ++++++++++++++++++++++++++++++
lib/librte_ethdev/rte_flow.c | 2 ++
lib/librte_ethdev/rte_flow.h | 29 +++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 9fc5b88f2..0f7d89555 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2227,6 +2227,36 @@ Assigns a new TTL value.
| ``ttl_value`` | new TTL value |
+---------------+--------------------+
+Action: ``SET_MAC_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_src:
+
+.. table:: SET_MAC_SRC
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
+Action: ``SET_MAC_DST``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Set source MAC address
+
+.. _table_rte_flow_action_set_mac_dst:
+
+.. table:: SET_MAC_DST
+
+ +--------------+---------------+
+ | Field | Value |
+ +==============+===============+
+ | ``mac_addr`` | MAC address |
+ +--------------+---------------+
+
Negative types
~~~~~~~~~~~~~~
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 5040c7667..1752ed5eb 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -138,6 +138,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
MK_FLOW_ACTION(MAC_SWAP, 0),
MK_FLOW_ACTION(DEC_TTL, 0),
MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
+ MK_FLOW_ACTION(SET_MAC_SRC, sizeof(struct rte_flow_action_set_mac)),
+ MK_FLOW_ACTION(SET_MAC_DST, sizeof(struct rte_flow_action_set_mac)),
};
static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index f102e6939..844ee3b25 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1599,6 +1599,26 @@ enum rte_flow_action_type {
* See struct rte_flow_action_set_ttl
*/
RTE_FLOW_ACTION_TYPE_SET_TTL,
+
+ /**
+ * Set source MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
+
+ /**
+ * Set destination MAC address from matched flow.
+ *
+ * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_ETH,
+ * the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION error.
+ *
+ * See struct rte_flow_action_set_mac.
+ */
+ RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
};
/**
@@ -2018,6 +2038,15 @@ struct rte_flow_action_set_ttl {
uint8_t ttl_value;
};
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_MAC
+ *
+ * Set MAC address from the matched flow
+ */
+struct rte_flow_action_set_mac {
+ uint8_t mac_addr[ETHER_ADDR_LEN];
+};
+
/*
* Definition of a single action.
*
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify MAC address
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
@ 2018-10-11 13:31 ` Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
2018-10-16 9:11 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
3 siblings, 0 replies; 20+ messages in thread
From: Jack Min @ 2018-10-11 13:31 UTC (permalink / raw)
To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
John McNamara, Marko Kovacevic
Cc: dev
add commands to support following actions:
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++++++
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 ++++
2 files changed, 58 insertions(+)
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 3efc2d86e..a527b6bb4 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -259,6 +259,10 @@ enum index {
ACTION_DEC_TTL,
ACTION_SET_TTL,
ACTION_SET_TTL_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_SET_MAC_DST,
+ ACTION_SET_MAC_DST_MAC_DST,
};
/** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -841,6 +845,8 @@ static const enum index next_action[] = {
ACTION_MAC_SWAP,
ACTION_DEC_TTL,
ACTION_SET_TTL,
+ ACTION_SET_MAC_SRC,
+ ACTION_SET_MAC_DST,
ZERO,
};
@@ -949,6 +955,12 @@ static const enum index action_set_ipv4_src[] = {
ZERO,
};
+static const enum index action_set_mac_src[] = {
+ ACTION_SET_MAC_SRC_MAC_SRC,
+ ACTION_NEXT,
+ ZERO,
+};
+
static const enum index action_set_ipv4_dst[] = {
ACTION_SET_IPV4_DST_IPV4_DST,
ACTION_NEXT,
@@ -991,6 +1003,12 @@ static const enum index action_jump[] = {
ZERO,
};
+static const enum index action_set_mac_dst[] = {
+ ACTION_SET_MAC_DST_MAC_DST,
+ ACTION_NEXT,
+ ZERO,
+};
+
static int parse_init(struct context *, const struct token *,
const char *, unsigned int,
void *, unsigned int);
@@ -2670,6 +2688,38 @@ static const struct token token_list[] = {
(struct rte_flow_action_set_ttl, ttl_value)),
.call = parse_vc_conf,
},
+ [ACTION_SET_MAC_SRC] = {
+ .name = "set_mac_src",
+ .help = "set source mac address",
+ .priv = PRIV_ACTION(SET_MAC_SRC,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_src),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_SRC_MAC_SRC] = {
+ .name = "mac_addr",
+ .help = "new source mac address",
+ .next = NEXT(action_set_mac_src, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
+ [ACTION_SET_MAC_DST] = {
+ .name = "set_mac_dst",
+ .help = "set destination mac address",
+ .priv = PRIV_ACTION(SET_MAC_DST,
+ sizeof(struct rte_flow_action_set_mac)),
+ .next = NEXT(action_set_mac_dst),
+ .call = parse_vc,
+ },
+ [ACTION_SET_MAC_DST_MAC_DST] = {
+ .name = "mac_addr",
+ .help = "new destination mac address to set",
+ .next = NEXT(action_set_mac_dst, NEXT_ENTRY(MAC_ADDR)),
+ .args = ARGS(ARGS_ENTRY_HTON
+ (struct rte_flow_action_set_mac, mac_addr)),
+ .call = parse_vc_conf,
+ },
};
/** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 77233987b..1ca3e8c20 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3744,6 +3744,14 @@ This section lists supported actions and their attributes, if any.
- ``set_ttl``: Set TTL value with specificed value
- ``ttl_value {unsigned}``: The new TTL value to be set
+- ``set_mac_src``: set source MAC address
+
+ - ``mac_addr {MAC-48}``: new source MAC address
+
+- ``set_mac_dst``: set destination MAC address
+
+ - ``mac_addr {MAC-48}``: new destination MAC address
+
Destroying flow rules
~~~~~~~~~~~~~~~~~~~~~
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite MAC address by E-Switch
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify MAC address Jack Min
@ 2018-10-11 13:31 ` Jack Min
2018-10-16 9:11 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
3 siblings, 0 replies; 20+ messages in thread
From: Jack Min @ 2018-10-11 13:31 UTC (permalink / raw)
To: Shahaf Shuler, Yongseok Koh; +Cc: dev
Offload following modify MAC address actions to E-Switch
via TC-Flower driver
- RTE_FLOW_ACTION_TYPE_SET_MAC_SRC
- RTE_FLOW_ACTION_TYPE_SET_MAC_DST
The corresponding rte_flow_item_eth must be present in
rte_flow pattern
Only support modify outer layer MAC address
The example testpmd command is:
flow create 0 transfer ingress
pattern eth / ipv4 / udp dst is 7000 / end
actions set_mac_dst mac_addr dd:00:aa:11:bb:33 /
set_mac_src mac_addr bb:00:cc:11:aa:22 /
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 | 70 +++++++++++++++++++++++++++++++-
2 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index cb07cf652..8ac24ebd5 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -86,6 +86,8 @@
#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_ACTION_SET_MAC_SRC (1u << 19)
+#define MLX5_FLOW_ACTION_SET_MAC_DST (1u << 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 a0a3680d5..885e50235 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -303,7 +303,8 @@ struct flow_tcf_ptoi {
(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_TTL | MLX5_FLOW_ACTION_DEC_TTL)
+ MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL | \
+ MLX5_FLOW_ACTION_SET_MAC_SRC | MLX5_FLOW_ACTION_SET_MAC_DST)
#define MLX5_TCF_CONFIG_ACTIONS \
(MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
@@ -328,6 +329,42 @@ struct pedit_parser {
};
+/**
+ * Set pedit key of MAC address
+ *
+ * @param[in] actions
+ * pointer to action specification
+ * @param[in,out] p_parser
+ * pointer to pedit_parser
+ */
+static void
+flow_tcf_pedit_key_set_mac(const struct rte_flow_action *actions,
+ struct pedit_parser *p_parser)
+{
+ int idx = p_parser->sel.nkeys;
+ uint32_t off = actions->type == RTE_FLOW_ACTION_TYPE_SET_MAC_SRC ?
+ offsetof(struct ether_hdr, s_addr) :
+ offsetof(struct ether_hdr, d_addr);
+ const struct rte_flow_action_set_mac *conf =
+ (const struct rte_flow_action_set_mac *)actions->conf;
+
+ p_parser->keys[idx].off = off;
+ p_parser->keys[idx].mask = ~UINT32_MAX;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr, SZ_PEDIT_KEY_VAL);
+ idx++;
+ p_parser->keys[idx].off = off + SZ_PEDIT_KEY_VAL;
+ p_parser->keys[idx].mask = 0xFFFF0000;
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH;
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ memcpy(&p_parser->keys[idx].val,
+ conf->mac_addr + SZ_PEDIT_KEY_VAL,
+ ETHER_ADDR_LEN - SZ_PEDIT_KEY_VAL);
+ p_parser->sel.nkeys = (++idx);
+}
+
/**
* Set pedit key of decrease/set ttl
*
@@ -508,6 +545,10 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
flow_tcf_pedit_key_set_dec_ttl(*actions,
&p_parser, item_flags);
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ flow_tcf_pedit_key_set_mac(*actions, &p_parser);
+ break;
default:
goto pedit_mnl_msg_done;
}
@@ -596,6 +637,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
flags |= MLX5_FLOW_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ keys += NUM_OF_PEDIT_KEYS(ETHER_ADDR_LEN);
+ flags |= MLX5_FLOW_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ keys += NUM_OF_PEDIT_KEYS(ETHER_ADDR_LEN);
+ flags |= MLX5_FLOW_ACTION_SET_MAC_DST;
+ break;
default:
goto get_pedit_action_size_done;
}
@@ -1122,6 +1171,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ current_action_flag = MLX5_FLOW_ACTION_SET_MAC_SRC;
+ break;
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
+ current_action_flag = MLX5_FLOW_ACTION_SET_MAC_DST;
+ break;
default:
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1227,6 +1282,15 @@ flow_tcf_validate(struct rte_eth_dev *dev,
actions,
"no IP found in pattern");
}
+ if (action_flags &
+ (MLX5_FLOW_ACTION_SET_MAC_SRC | MLX5_FLOW_ACTION_SET_MAC_DST)) {
+ if (!(item_flags & MLX5_FLOW_LAYER_OUTER_L2))
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ actions,
+ "no ethernet found in"
+ " pattern");
+ }
return 0;
}
@@ -1378,6 +1442,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
size += flow_tcf_get_pedit_actions_size(&actions,
&flags);
break;
@@ -1924,6 +1990,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
case RTE_FLOW_ACTION_TYPE_SET_TTL:
case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
+ case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
na_act_index =
mnl_attr_nest_start(nlh, na_act_index_cur++);
flow_tcf_create_pedit_mnl_msg(nlh,
--
2.17.1
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
` (2 preceding siblings ...)
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
@ 2018-10-16 9:11 ` Ferruh Yigit
3 siblings, 0 replies; 20+ messages in thread
From: Ferruh Yigit @ 2018-10-16 9:11 UTC (permalink / raw)
To: Jack Min; +Cc: dev
On 10/11/2018 2:31 PM, Jack Min wrote:
> This series is for RFC[1] and depends on patch[2]
>
> Patch 1 adds generic MAC address rewrite actions to flow API
> Patch 2 adds testpmd commands for that
> Patch 3 offloads these actions on Mellanox MLX5 by using E-Switch rule
>
> [1]: https://patches.dpdk.org/patch/44005/
> [2]: http://patches.dpdk.org/patch/46625/
>
> v2:
> * rebased
> * changed commit message title
> * added example testpmd command in commit log
> * changes in validation
> v3:
> * fix some coding style issues
> * use macro of calc pedit keys
> * rebased
>
> Xiaoyu Min (3):
> ethdev: add generic MAC address rewrite actions
> app/testpmd: add commands of modify MAC address
> net/mlx5: rewrite MAC address by E-Switch
Series applied to dpdk-next-net/master, thanks.
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2018-10-16 9:11 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25 15:03 [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Xiaoyu Min
2018-09-25 15:03 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
2018-10-03 20:08 ` Yongseok Koh
2018-10-08 9:31 ` Andrew Rybchenko
2018-09-25 15:03 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify MAC address Xiaoyu Min
2018-10-03 20:09 ` Yongseok Koh
2018-09-25 15:03 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify MAC address actions Xiaoyu Min
2018-10-03 20:10 ` Yongseok Koh
2018-10-05 12:54 ` [dpdk-dev] [PATCH 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
2018-10-08 2:32 ` Xiaoyu Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 " Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 1/3] " Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify MAC address Jack Min
2018-10-10 13:11 ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
2018-10-11 5:51 ` Yongseok Koh
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify MAC address Jack Min
2018-10-11 13:31 ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite MAC address by E-Switch Jack Min
2018-10-16 9:11 ` [dpdk-dev] [PATCH v3 0/3] ethdev: add generic MAC address rewrite actions Ferruh Yigit
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).