ACPI: processor: idle: Allow probing on platforms with one ACPI C-state
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / en / tc_ct.h
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         if (!flow_rule_match_key(f->rule, FLOW_DISSECTOR_KEY_CT))
134                 return 0;
135
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");
138         return -EOPNOTSUPP;
139 }
140
141 static inline int
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)
146 {
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");
149         return -EOPNOTSUPP;
150 }
151
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)
158 {
159         return ERR_PTR(-EOPNOTSUPP);
160 }
161
162 static inline void
163 mlx5_tc_ct_delete_flow(struct mlx5e_priv *priv,
164                        struct mlx5e_tc_flow *flow,
165                        struct mlx5_esw_flow_attr *attr)
166 {
167 }
168
169 static inline bool
170 mlx5e_tc_ct_restore_flow(struct mlx5_rep_uplink_priv *uplink_priv,
171                          struct sk_buff *skb, u32 tupleid)
172 {
173         if  (!tupleid)
174                 return  true;
175
176         return false;
177 }
178
179 #endif /* !IS_ENABLED(CONFIG_MLX5_TC_CT) */
180 #endif /* __MLX5_EN_TC_CT_H__ */