1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 
4 #include <linux/tc_act/tc_csum.h>
5 #include "act.h"
6 #include "en/tc_priv.h"
7 
8 static bool
9 csum_offload_supported(struct mlx5e_priv *priv,
10 		       u32 action,
11 		       u32 update_flags,
12 		       struct netlink_ext_ack *extack)
13 {
14 	u32 prot_flags = TCA_CSUM_UPDATE_FLAG_IPV4HDR | TCA_CSUM_UPDATE_FLAG_TCP |
15 			 TCA_CSUM_UPDATE_FLAG_UDP;
16 
17 	/*  The HW recalcs checksums only if re-writing headers */
18 	if (!(action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)) {
19 		NL_SET_ERR_MSG_MOD(extack,
20 				   "TC csum action is only offloaded with pedit");
21 		netdev_warn(priv->netdev,
22 			    "TC csum action is only offloaded with pedit\n");
23 		return false;
24 	}
25 
26 	if (update_flags & ~prot_flags) {
27 		NL_SET_ERR_MSG_MOD(extack,
28 				   "can't offload TC csum action for some header/s");
29 		netdev_warn(priv->netdev,
30 			    "can't offload TC csum action for some header/s - flags %#x\n",
31 			    update_flags);
32 		return false;
33 	}
34 
35 	return true;
36 }
37 
38 static bool
39 tc_act_can_offload_csum(struct mlx5e_tc_act_parse_state *parse_state,
40 			const struct flow_action_entry *act,
41 			int act_index)
42 {
43 	struct mlx5e_tc_flow *flow = parse_state->flow;
44 
45 	return csum_offload_supported(flow->priv, flow->attr->action,
46 				      act->csum_flags, parse_state->extack);
47 }
48 
49 static int
50 tc_act_parse_csum(struct mlx5e_tc_act_parse_state *parse_state,
51 		  const struct flow_action_entry *act,
52 		  struct mlx5e_priv *priv,
53 		  struct mlx5_flow_attr *attr)
54 {
55 	return 0;
56 }
57 
58 struct mlx5e_tc_act mlx5e_tc_act_csum = {
59 	.can_offload = tc_act_can_offload_csum,
60 	.parse_action = tc_act_parse_csum,
61 };
62