Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / en / tc / act / mirred_nic.c
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
8 tc_act_can_offload_mirred_nic(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 *flow = parse_state->flow;
15         struct net_device *out_dev = act->dev;
16         struct mlx5e_priv *priv = flow->priv;
17
18         if (act->id != FLOW_ACTION_REDIRECT)
19                 return false;
20
21         if (priv->netdev->netdev_ops != out_dev->netdev_ops ||
22             !mlx5e_same_hw_devs(priv, netdev_priv(out_dev))) {
23                 NL_SET_ERR_MSG_MOD(extack,
24                                    "devices are not on same switch HW, can't offload forwarding");
25                 netdev_warn(priv->netdev,
26                             "devices %s %s not on same switch HW, can't offload forwarding\n",
27                             netdev_name(priv->netdev),
28                             out_dev->name);
29                 return false;
30         }
31
32         return true;
33 }
34
35 static int
36 tc_act_parse_mirred_nic(struct mlx5e_tc_act_parse_state *parse_state,
37                         const struct flow_action_entry *act,
38                         struct mlx5e_priv *priv,
39                         struct mlx5_flow_attr *attr)
40 {
41         attr->parse_attr->mirred_ifindex[0] = act->dev->ifindex;
42         flow_flag_set(parse_state->flow, HAIRPIN);
43         attr->action |= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
44
45         return 0;
46 }
47
48 struct mlx5e_tc_act mlx5e_tc_act_mirred_nic = {
49         .can_offload = tc_act_can_offload_mirred_nic,
50         .parse_action = tc_act_parse_mirred_nic,
51 };