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 struct mlx5_flow_attr *attr) 43 { 44 struct mlx5e_tc_flow *flow = parse_state->flow; 45 46 return csum_offload_supported(flow->priv, attr->action, 47 act->csum_flags, parse_state->extack); 48 } 49 50 static int 51 tc_act_parse_csum(struct mlx5e_tc_act_parse_state *parse_state, 52 const struct flow_action_entry *act, 53 struct mlx5e_priv *priv, 54 struct mlx5_flow_attr *attr) 55 { 56 return 0; 57 } 58 59 struct mlx5e_tc_act mlx5e_tc_act_csum = { 60 .can_offload = tc_act_can_offload_csum, 61 .parse_action = tc_act_parse_csum, 62 }; 63