1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2018 Mellanox Technologies. */ 3 4 #ifndef __MLX5_EN_TC_CT_H__ 5 #define __MLX5_EN_TC_CT_H__ 6 7 #include <net/pkt_cls.h> 8 #include <linux/mlx5/fs.h> 9 #include <net/tc_act/tc_ct.h> 10 11 #include "en.h" 12 13 struct mlx5_esw_flow_attr; 14 struct mlx5e_tc_mod_hdr_acts; 15 struct mlx5_rep_uplink_priv; 16 struct mlx5e_tc_flow; 17 struct mlx5e_priv; 18 19 struct mlx5_ct_flow; 20 21 struct nf_flowtable; 22 23 struct mlx5_ct_attr { 24 u16 zone; 25 u16 ct_action; 26 struct mlx5_ct_flow *ct_flow; 27 struct nf_flowtable *nf_ft; 28 }; 29 30 #define zone_to_reg_ct {\ 31 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\ 32 .moffset = 0,\ 33 .mlen = 2,\ 34 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 35 misc_parameters_2.metadata_reg_c_2) + 2,\ 36 } 37 38 #define ctstate_to_reg_ct {\ 39 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\ 40 .moffset = 2,\ 41 .mlen = 2,\ 42 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 43 misc_parameters_2.metadata_reg_c_2),\ 44 } 45 46 #define mark_to_reg_ct {\ 47 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_3,\ 48 .moffset = 0,\ 49 .mlen = 4,\ 50 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 51 misc_parameters_2.metadata_reg_c_3),\ 52 } 53 54 #define labels_to_reg_ct {\ 55 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_4,\ 56 .moffset = 0,\ 57 .mlen = 4,\ 58 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 59 misc_parameters_2.metadata_reg_c_4),\ 60 } 61 62 #define fteid_to_reg_ct {\ 63 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_5,\ 64 .moffset = 0,\ 65 .mlen = 4,\ 66 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 67 misc_parameters_2.metadata_reg_c_5),\ 68 } 69 70 #define tupleid_to_reg_ct {\ 71 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1,\ 72 .moffset = 0,\ 73 .mlen = 3,\ 74 .soffset = MLX5_BYTE_OFF(fte_match_param,\ 75 misc_parameters_2.metadata_reg_c_1),\ 76 } 77 78 #define TUPLE_ID_BITS (mlx5e_tc_attr_to_reg_mappings[TUPLEID_TO_REG].mlen * 8) 79 #define TUPLE_ID_MAX GENMASK(TUPLE_ID_BITS - 1, 0) 80 81 #if IS_ENABLED(CONFIG_MLX5_TC_CT) 82 83 int 84 mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv); 85 void 86 mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv); 87 88 int 89 mlx5_tc_ct_parse_match(struct mlx5e_priv *priv, 90 struct mlx5_flow_spec *spec, 91 struct flow_cls_offload *f, 92 struct netlink_ext_ack *extack); 93 int 94 mlx5_tc_ct_parse_action(struct mlx5e_priv *priv, 95 struct mlx5_esw_flow_attr *attr, 96 const struct flow_action_entry *act, 97 struct netlink_ext_ack *extack); 98 99 struct mlx5_flow_handle * 100 mlx5_tc_ct_flow_offload(struct mlx5e_priv *priv, 101 struct mlx5e_tc_flow *flow, 102 struct mlx5_flow_spec *spec, 103 struct mlx5_esw_flow_attr *attr, 104 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts); 105 void 106 mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv, 107 struct mlx5e_tc_flow *flow, 108 struct mlx5_esw_flow_attr *attr); 109 110 bool 111 mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv, 112 struct sk_buff *skb, u32 tupleid); 113 114 #else /* CONFIG_MLX5_TC_CT */ 115 116 static inline int 117 mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv) 118 { 119 return 0; 120 } 121 122 static inline void 123 mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv) 124 { 125 } 126 127 static inline int 128 mlx5_tc_ct_parse_match(struct mlx5e_priv *priv, 129 struct mlx5_flow_spec *spec, 130 struct flow_cls_offload *f, 131 struct netlink_ext_ack *extack) 132 { 133 struct flow_rule *rule = flow_cls_offload_flow_rule(f); 134 135 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CT)) 136 return 0; 137 138 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled."); 139 netdev_warn(priv->netdev, "mlx5 tc ct offload isn't enabled.\n"); 140 return -EOPNOTSUPP; 141 } 142 143 static inline int 144 mlx5_tc_ct_parse_action(struct mlx5e_priv *priv, 145 struct mlx5_esw_flow_attr *attr, 146 const struct flow_action_entry *act, 147 struct netlink_ext_ack *extack) 148 { 149 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled."); 150 netdev_warn(priv->netdev, "mlx5 tc ct offload isn't enabled.\n"); 151 return -EOPNOTSUPP; 152 } 153 154 static inline struct mlx5_flow_handle * 155 mlx5_tc_ct_flow_offload(struct mlx5e_priv *priv, 156 struct mlx5e_tc_flow *flow, 157 struct mlx5_flow_spec *spec, 158 struct mlx5_esw_flow_attr *attr, 159 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts) 160 { 161 return ERR_PTR(-EOPNOTSUPP); 162 } 163 164 static inline void 165 mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv, 166 struct mlx5e_tc_flow *flow, 167 struct mlx5_esw_flow_attr *attr) 168 { 169 } 170 171 static inline bool 172 mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv, 173 struct sk_buff *skb, u32 tupleid) 174 { 175 if (!tupleid) 176 return true; 177 178 return false; 179 } 180 181 #endif /* !IS_ENABLED(CONFIG_MLX5_TC_CT) */ 182 #endif /* __MLX5_EN_TC_CT_H__ */ 183