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_flow_attr;
14 struct mlx5e_tc_mod_hdr_acts;
15 struct mlx5_rep_uplink_priv;
19 struct mlx5_fs_chains;
20 struct mlx5_tc_ct_priv;
28 struct mlx5_ct_flow *ct_flow;
29 struct nf_flowtable *nf_ft;
33 #define zone_to_reg_ct {\
34 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\
37 .soffset = MLX5_BYTE_OFF(fte_match_param,\
38 misc_parameters_2.metadata_reg_c_2) + 2,\
41 #define ctstate_to_reg_ct {\
42 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_2,\
45 .soffset = MLX5_BYTE_OFF(fte_match_param,\
46 misc_parameters_2.metadata_reg_c_2),\
49 #define mark_to_reg_ct {\
50 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_3,\
53 .soffset = MLX5_BYTE_OFF(fte_match_param,\
54 misc_parameters_2.metadata_reg_c_3),\
57 #define labels_to_reg_ct {\
58 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_4,\
61 .soffset = MLX5_BYTE_OFF(fte_match_param,\
62 misc_parameters_2.metadata_reg_c_4),\
65 #define fteid_to_reg_ct {\
66 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_5,\
69 .soffset = MLX5_BYTE_OFF(fte_match_param,\
70 misc_parameters_2.metadata_reg_c_5),\
73 #define zone_restore_to_reg_ct {\
74 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_C_1,\
77 .soffset = MLX5_BYTE_OFF(fte_match_param,\
78 misc_parameters_2.metadata_reg_c_1) + 3,\
81 #define nic_zone_restore_to_reg_ct {\
82 .mfield = MLX5_ACTION_IN_FIELD_METADATA_REG_B,\
87 #define REG_MAPPING_MLEN(reg) (mlx5e_tc_attr_to_reg_mappings[reg].mlen)
88 #define REG_MAPPING_MOFFSET(reg) (mlx5e_tc_attr_to_reg_mappings[reg].moffset)
89 #define REG_MAPPING_SHIFT(reg) (REG_MAPPING_MOFFSET(reg) * 8)
90 #define ZONE_RESTORE_BITS (REG_MAPPING_MLEN(ZONE_RESTORE_TO_REG) * 8)
91 #define ZONE_RESTORE_MAX GENMASK(ZONE_RESTORE_BITS - 1, 0)
93 #if IS_ENABLED(CONFIG_MLX5_TC_CT)
95 struct mlx5_tc_ct_priv *
96 mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
97 struct mod_hdr_tbl *mod_hdr,
98 enum mlx5_flow_namespace_type ns_type);
100 mlx5_tc_ct_clean(struct mlx5_tc_ct_priv *ct_priv);
103 mlx5_tc_ct_match_del(struct mlx5_tc_ct_priv *priv, struct mlx5_ct_attr *ct_attr);
106 mlx5_tc_ct_match_add(struct mlx5_tc_ct_priv *priv,
107 struct mlx5_flow_spec *spec,
108 struct flow_cls_offload *f,
109 struct mlx5_ct_attr *ct_attr,
110 struct netlink_ext_ack *extack);
111 int mlx5_tc_ct_add_no_trk_match(struct mlx5_flow_spec *spec);
113 mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
114 struct mlx5_flow_attr *attr,
115 const struct flow_action_entry *act,
116 struct netlink_ext_ack *extack);
118 struct mlx5_flow_handle *
119 mlx5_tc_ct_flow_offload(struct mlx5_tc_ct_priv *priv,
120 struct mlx5e_tc_flow *flow,
121 struct mlx5_flow_spec *spec,
122 struct mlx5_flow_attr *attr,
123 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
125 mlx5_tc_ct_delete_flow(struct mlx5_tc_ct_priv *priv,
126 struct mlx5e_tc_flow *flow,
127 struct mlx5_flow_attr *attr);
130 mlx5e_tc_ct_restore_flow(struct mlx5_tc_ct_priv *ct_priv,
131 struct sk_buff *skb, u8 zone_restore_id);
133 #else /* CONFIG_MLX5_TC_CT */
135 static inline struct mlx5_tc_ct_priv *
136 mlx5_tc_ct_init(struct mlx5e_priv *priv, struct mlx5_fs_chains *chains,
137 struct mod_hdr_tbl *mod_hdr,
138 enum mlx5_flow_namespace_type ns_type)
144 mlx5_tc_ct_clean(struct mlx5_tc_ct_priv *ct_priv)
149 mlx5_tc_ct_match_del(struct mlx5_tc_ct_priv *priv, struct mlx5_ct_attr *ct_attr) {}
152 mlx5_tc_ct_match_add(struct mlx5_tc_ct_priv *priv,
153 struct mlx5_flow_spec *spec,
154 struct flow_cls_offload *f,
155 struct mlx5_ct_attr *ct_attr,
156 struct netlink_ext_ack *extack)
158 struct flow_rule *rule = flow_cls_offload_flow_rule(f);
160 if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CT))
163 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled.");
168 mlx5_tc_ct_add_no_trk_match(struct mlx5_flow_spec *spec)
174 mlx5_tc_ct_parse_action(struct mlx5_tc_ct_priv *priv,
175 struct mlx5_flow_attr *attr,
176 const struct flow_action_entry *act,
177 struct netlink_ext_ack *extack)
179 NL_SET_ERR_MSG_MOD(extack, "mlx5 tc ct offload isn't enabled.");
183 static inline struct mlx5_flow_handle *
184 mlx5_tc_ct_flow_offload(struct mlx5_tc_ct_priv *priv,
185 struct mlx5e_tc_flow *flow,
186 struct mlx5_flow_spec *spec,
187 struct mlx5_flow_attr *attr,
188 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
190 return ERR_PTR(-EOPNOTSUPP);
194 mlx5_tc_ct_delete_flow(struct mlx5_tc_ct_priv *priv,
195 struct mlx5e_tc_flow *flow,
196 struct mlx5_flow_attr *attr)
201 mlx5e_tc_ct_restore_flow(struct mlx5_tc_ct_priv *ct_priv,
202 struct sk_buff *skb, u8 zone_restore_id)
204 if (!zone_restore_id)
210 #endif /* !IS_ENABLED(CONFIG_MLX5_TC_CT) */
211 #endif /* __MLX5_EN_TC_CT_H__ */