1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2018 Mellanox Technologies. */
4 #ifndef __MLX5_EN_TC_CT_H__
5 #define __MLX5_EN_TC_CT_H__
7 #include <net/pkt_cls.h>
8 #include <linux/mlx5/fs.h>
9 #include <net/tc_act/tc_ct.h>
13 struct mlx5_esw_flow_attr;
14 struct mlx5e_tc_mod_hdr_acts;
15 struct mlx5_rep_uplink_priv;
26 struct mlx5_ct_flow *ct_flow;
27 struct nf_flowtable *nf_ft;
30 #define zone_to_reg_ct {\
31 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\
34 .soffset = MLX5_BYTE_OFF(fte_match_param,\
35 misc_parameters_2.metadata_reg_c_2) + 2,\
38 #define ctstate_to_reg_ct {\
39 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\
42 .soffset = MLX5_BYTE_OFF(fte_match_param,\
43 misc_parameters_2.metadata_reg_c_2),\
46 #define mark_to_reg_ct {\
47 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_3,\
50 .soffset = MLX5_BYTE_OFF(fte_match_param,\
51 misc_parameters_2.metadata_reg_c_3),\
54 #define labels_to_reg_ct {\
55 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_4,\
58 .soffset = MLX5_BYTE_OFF(fte_match_param,\
59 misc_parameters_2.metadata_reg_c_4),\
62 #define fteid_to_reg_ct {\
63 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_5,\
66 .soffset = MLX5_BYTE_OFF(fte_match_param,\
67 misc_parameters_2.metadata_reg_c_5),\
70 #define tupleid_to_reg_ct {\
71 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1,\
74 .soffset = MLX5_BYTE_OFF(fte_match_param,\
75 misc_parameters_2.metadata_reg_c_1),\
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)
81 #if IS_ENABLED(CONFIG_MLX5_TC_CT)
84 mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv);
86 mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv);
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);
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);
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);
106 mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv,
107 struct mlx5e_tc_flow *flow,
108 struct mlx5_esw_flow_attr *attr);
111 mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
112 struct sk_buff *skb, u32 tupleid);
114 #else /* CONFIG_MLX5_TC_CT */
117 mlx5_tc_ct_init(struct mlx5_rep_uplink_priv *uplink_priv)
123 mlx5_tc_ct_clean(struct mlx5_rep_uplink_priv *uplink_priv)
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)
133 if (!flow_rule_match_key(f->rule, FLOW_DISSECTOR_KEY_CT))
136 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled.");
137 netdev_warn(priv->netdev, "mlx5 tc ct offload isn't enabled.\n");
142 mlx5_tc_ct_parse_action(struct mlx5e_priv *priv,
143 struct mlx5_esw_flow_attr *attr,
144 const struct flow_action_entry *act,
145 struct netlink_ext_ack *extack)
147 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled.");
148 netdev_warn(priv->netdev, "mlx5 tc ct offload isn't enabled.\n");
152 static inline struct mlx5_flow_handle *
153 mlx5_tc_ct_flow_offload(struct mlx5e_priv *priv,
154 struct mlx5e_tc_flow *flow,
155 struct mlx5_flow_spec *spec,
156 struct mlx5_esw_flow_attr *attr,
157 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
159 return ERR_PTR(-EOPNOTSUPP);
163 mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv,
164 struct mlx5e_tc_flow *flow,
165 struct mlx5_esw_flow_attr *attr)
170 mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
171 struct sk_buff *skb, u32 tupleid)
179 #endif /* !IS_ENABLED(CONFIG_MLX5_TC_CT) */
180 #endif /* __MLX5_EN_TC_CT_H__ */