1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
4 #include "act.h"
5 #include "en/tc_priv.h"
6
7 static bool
tc_act_can_offload_redirect_ingress(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,int act_index,struct mlx5_flow_attr * attr)8 tc_act_can_offload_redirect_ingress(struct mlx5e_tc_act_parse_state *parse_state,
9 const struct flow_action_entry *act,
10 int act_index,
11 struct mlx5_flow_attr *attr)
12 {
13 struct netlink_ext_ack *extack = parse_state->extack;
14 struct mlx5e_tc_flow_parse_attr *parse_attr;
15 struct net_device *out_dev = act->dev;
16 struct mlx5_esw_flow_attr *esw_attr;
17
18 parse_attr = attr->parse_attr;
19 esw_attr = attr->esw_attr;
20
21 if (!out_dev)
22 return false;
23
24 if (!netif_is_ovs_master(out_dev)) {
25 NL_SET_ERR_MSG_MOD(extack,
26 "redirect to ingress is supported only for OVS internal ports");
27 return false;
28 }
29
30 if (netif_is_ovs_master(parse_attr->filter_dev)) {
31 NL_SET_ERR_MSG_MOD(extack,
32 "redirect to ingress is not supported from internal port");
33 return false;
34 }
35
36 if (!parse_state->ptype_host) {
37 NL_SET_ERR_MSG_MOD(extack,
38 "redirect to int port ingress requires ptype=host action");
39 return false;
40 }
41
42 if (esw_attr->out_count) {
43 NL_SET_ERR_MSG_MOD(extack,
44 "redirect to int port ingress is supported only as single destination");
45 return false;
46 }
47
48 return true;
49 }
50
51 static int
tc_act_parse_redirect_ingress(struct mlx5e_tc_act_parse_state * parse_state,const struct flow_action_entry * act,struct mlx5e_priv * priv,struct mlx5_flow_attr * attr)52 tc_act_parse_redirect_ingress(struct mlx5e_tc_act_parse_state *parse_state,
53 const struct flow_action_entry *act,
54 struct mlx5e_priv *priv,
55 struct mlx5_flow_attr *attr)
56 {
57 struct mlx5_esw_flow_attr *esw_attr = attr->esw_attr;
58 struct net_device *out_dev = act->dev;
59 int err;
60
61 attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
62
63 err = mlx5e_set_fwd_to_int_port_actions(priv, attr, out_dev->ifindex,
64 MLX5E_TC_INT_PORT_INGRESS,
65 &attr->action, esw_attr->out_count);
66 if (err)
67 return err;
68
69 parse_state->if_count = 0;
70 esw_attr->out_count++;
71
72 return 0;
73 }
74
75 struct mlx5e_tc_act mlx5e_tc_act_redirect_ingress = {
76 .can_offload = tc_act_can_offload_redirect_ingress,
77 .parse_action = tc_act_parse_redirect_ingress,
78 };
79
80