1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4 #include <linux/if_vlan.h>
7 #include "en/tc_priv.h"
8 #include "en/mod_hdr.h"
10 static int pedit_header_offsets[] = {
11 [FLOW_ACT_MANGLE_HDR_TYPE_ETH] = offsetof(struct pedit_headers, eth),
12 [FLOW_ACT_MANGLE_HDR_TYPE_IP4] = offsetof(struct pedit_headers, ip4),
13 [FLOW_ACT_MANGLE_HDR_TYPE_IP6] = offsetof(struct pedit_headers, ip6),
14 [FLOW_ACT_MANGLE_HDR_TYPE_TCP] = offsetof(struct pedit_headers, tcp),
15 [FLOW_ACT_MANGLE_HDR_TYPE_UDP] = offsetof(struct pedit_headers, udp),
18 #define pedit_header(_ph, _htype) ((void *)(_ph) + pedit_header_offsets[_htype])
21 set_pedit_val(u8 hdr_type, u32 mask, u32 val, u32 offset,
22 struct pedit_headers_action *hdrs,
23 struct netlink_ext_ack *extack)
25 u32 *curr_pmask, *curr_pval;
27 curr_pmask = (u32 *)(pedit_header(&hdrs->masks, hdr_type) + offset);
28 curr_pval = (u32 *)(pedit_header(&hdrs->vals, hdr_type) + offset);
30 if (*curr_pmask & mask) { /* disallow acting twice on the same location */
31 NL_SET_ERR_MSG_MOD(extack,
32 "curr_pmask and new mask same. Acting twice on same location");
37 *curr_pval |= (val & mask);
46 mlx5e_tc_act_pedit_parse_action(struct mlx5e_priv *priv,
47 const struct flow_action_entry *act, int namespace,
48 struct pedit_headers_action *hdrs,
49 struct netlink_ext_ack *extack)
51 u8 cmd = (act->id == FLOW_ACTION_MANGLE) ? 0 : 1;
52 u8 htype = act->mangle.htype;
53 int err = -EOPNOTSUPP;
54 u32 mask, val, offset;
56 if (htype == FLOW_ACT_MANGLE_UNSPEC) {
57 NL_SET_ERR_MSG_MOD(extack, "legacy pedit isn't offloaded");
61 if (!mlx5e_mod_hdr_max_actions(priv->mdev, namespace)) {
62 NL_SET_ERR_MSG_MOD(extack, "The pedit offload action is not supported");
66 mask = act->mangle.mask;
67 val = act->mangle.val;
68 offset = act->mangle.offset;
70 err = set_pedit_val(htype, ~mask, val, offset, &hdrs[cmd], extack);
82 tc_act_parse_pedit(struct mlx5e_tc_act_parse_state *parse_state,
83 const struct flow_action_entry *act,
84 struct mlx5e_priv *priv,
85 struct mlx5_flow_attr *attr)
87 struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr;
88 struct mlx5e_tc_flow *flow = parse_state->flow;
89 enum mlx5_flow_namespace_type ns_type;
92 ns_type = mlx5e_get_flow_namespace(flow);
94 err = mlx5e_tc_act_pedit_parse_action(flow->priv, act, ns_type, attr->parse_attr->hdrs,
99 attr->action |= MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
101 if (ns_type == MLX5_FLOW_NAMESPACE_FDB) {
102 esw_attr->split_count = esw_attr->out_count;
103 parse_state->if_count = 0;
109 struct mlx5e_tc_act mlx5e_tc_act_pedit = {
110 .parse_action = tc_act_parse_pedit,