Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / steering / dr_types.h
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019, Mellanox Technologies */
3
4 #ifndef _DR_TYPES_
5 #define _DR_TYPES_
6
7 #include <linux/mlx5/driver.h>
8 #include <linux/refcount.h>
9 #include "fs_core.h"
10 #include "wq.h"
11 #include "lib/mlx5.h"
12 #include "mlx5_ifc_dr.h"
13 #include "mlx5dr.h"
14
15 #define DR_RULE_MAX_STES 17
16 #define DR_ACTION_MAX_STES 5
17 #define WIRE_PORT 0xFFFF
18 #define DR_STE_SVLAN 0x1
19 #define DR_STE_CVLAN 0x2
20 #define DR_SZ_MATCH_PARAM (MLX5_ST_SZ_DW_MATCH_PARAM * 4)
21
22 #define mlx5dr_err(dmn, arg...) mlx5_core_err((dmn)->mdev, ##arg)
23 #define mlx5dr_info(dmn, arg...) mlx5_core_info((dmn)->mdev, ##arg)
24 #define mlx5dr_dbg(dmn, arg...) mlx5_core_dbg((dmn)->mdev, ##arg)
25
26 enum mlx5dr_icm_chunk_size {
27         DR_CHUNK_SIZE_1,
28         DR_CHUNK_SIZE_MIN = DR_CHUNK_SIZE_1, /* keep updated when changing */
29         DR_CHUNK_SIZE_2,
30         DR_CHUNK_SIZE_4,
31         DR_CHUNK_SIZE_8,
32         DR_CHUNK_SIZE_16,
33         DR_CHUNK_SIZE_32,
34         DR_CHUNK_SIZE_64,
35         DR_CHUNK_SIZE_128,
36         DR_CHUNK_SIZE_256,
37         DR_CHUNK_SIZE_512,
38         DR_CHUNK_SIZE_1K,
39         DR_CHUNK_SIZE_2K,
40         DR_CHUNK_SIZE_4K,
41         DR_CHUNK_SIZE_8K,
42         DR_CHUNK_SIZE_16K,
43         DR_CHUNK_SIZE_32K,
44         DR_CHUNK_SIZE_64K,
45         DR_CHUNK_SIZE_128K,
46         DR_CHUNK_SIZE_256K,
47         DR_CHUNK_SIZE_512K,
48         DR_CHUNK_SIZE_1024K,
49         DR_CHUNK_SIZE_2048K,
50         DR_CHUNK_SIZE_MAX,
51 };
52
53 enum mlx5dr_icm_type {
54         DR_ICM_TYPE_STE,
55         DR_ICM_TYPE_MODIFY_ACTION,
56 };
57
58 static inline enum mlx5dr_icm_chunk_size
59 mlx5dr_icm_next_higher_chunk(enum mlx5dr_icm_chunk_size chunk)
60 {
61         chunk += 2;
62         if (chunk < DR_CHUNK_SIZE_MAX)
63                 return chunk;
64
65         return DR_CHUNK_SIZE_MAX;
66 }
67
68 enum {
69         DR_STE_SIZE = 64,
70         DR_STE_SIZE_CTRL = 32,
71         DR_STE_SIZE_TAG = 16,
72         DR_STE_SIZE_MASK = 16,
73 };
74
75 enum {
76         DR_STE_SIZE_REDUCED = DR_STE_SIZE - DR_STE_SIZE_MASK,
77 };
78
79 enum {
80         DR_MODIFY_ACTION_SIZE = 8,
81 };
82
83 enum mlx5dr_matcher_criteria {
84         DR_MATCHER_CRITERIA_EMPTY = 0,
85         DR_MATCHER_CRITERIA_OUTER = 1 << 0,
86         DR_MATCHER_CRITERIA_MISC = 1 << 1,
87         DR_MATCHER_CRITERIA_INNER = 1 << 2,
88         DR_MATCHER_CRITERIA_MISC2 = 1 << 3,
89         DR_MATCHER_CRITERIA_MISC3 = 1 << 4,
90         DR_MATCHER_CRITERIA_MAX = 1 << 5,
91 };
92
93 enum mlx5dr_action_type {
94         DR_ACTION_TYP_TNL_L2_TO_L2,
95         DR_ACTION_TYP_L2_TO_TNL_L2,
96         DR_ACTION_TYP_TNL_L3_TO_L2,
97         DR_ACTION_TYP_L2_TO_TNL_L3,
98         DR_ACTION_TYP_DROP,
99         DR_ACTION_TYP_QP,
100         DR_ACTION_TYP_FT,
101         DR_ACTION_TYP_CTR,
102         DR_ACTION_TYP_TAG,
103         DR_ACTION_TYP_MODIFY_HDR,
104         DR_ACTION_TYP_VPORT,
105         DR_ACTION_TYP_POP_VLAN,
106         DR_ACTION_TYP_PUSH_VLAN,
107         DR_ACTION_TYP_MAX,
108 };
109
110 enum mlx5dr_ipv {
111         DR_RULE_IPV4,
112         DR_RULE_IPV6,
113         DR_RULE_IPV_MAX,
114 };
115
116 struct mlx5dr_icm_pool;
117 struct mlx5dr_icm_chunk;
118 struct mlx5dr_icm_buddy_mem;
119 struct mlx5dr_ste_htbl;
120 struct mlx5dr_match_param;
121 struct mlx5dr_cmd_caps;
122 struct mlx5dr_matcher_rx_tx;
123
124 struct mlx5dr_ste {
125         u8 *hw_ste;
126         /* refcount: indicates the num of rules that using this ste */
127         u32 refcount;
128
129         /* attached to the miss_list head at each htbl entry */
130         struct list_head miss_list_node;
131
132         /* each rule member that uses this ste attached here */
133         struct list_head rule_list;
134
135         /* this ste is member of htbl */
136         struct mlx5dr_ste_htbl *htbl;
137
138         struct mlx5dr_ste_htbl *next_htbl;
139
140         /* this ste is part of a rule, located in ste's chain */
141         u8 ste_chain_location;
142 };
143
144 struct mlx5dr_ste_htbl_ctrl {
145         /* total number of valid entries belonging to this hash table. This
146          * includes the non collision and collision entries
147          */
148         unsigned int num_of_valid_entries;
149
150         /* total number of collisions entries attached to this table */
151         unsigned int num_of_collisions;
152         unsigned int increase_threshold;
153         u8 may_grow:1;
154 };
155
156 struct mlx5dr_ste_htbl {
157         u8 lu_type;
158         u16 byte_mask;
159         u32 refcount;
160         struct mlx5dr_icm_chunk *chunk;
161         struct mlx5dr_ste *ste_arr;
162         u8 *hw_ste_arr;
163
164         struct list_head *miss_list;
165
166         enum mlx5dr_icm_chunk_size chunk_size;
167         struct mlx5dr_ste *pointing_ste;
168
169         struct mlx5dr_ste_htbl_ctrl ctrl;
170 };
171
172 struct mlx5dr_ste_send_info {
173         struct mlx5dr_ste *ste;
174         struct list_head send_list;
175         u16 size;
176         u16 offset;
177         u8 data_cont[DR_STE_SIZE];
178         u8 *data;
179 };
180
181 void mlx5dr_send_fill_and_append_ste_send_info(struct mlx5dr_ste *ste, u16 size,
182                                                u16 offset, u8 *data,
183                                                struct mlx5dr_ste_send_info *ste_info,
184                                                struct list_head *send_list,
185                                                bool copy_data);
186
187 struct mlx5dr_ste_build {
188         u8 inner:1;
189         u8 rx:1;
190         u8 vhca_id_valid:1;
191         struct mlx5dr_domain *dmn;
192         struct mlx5dr_cmd_caps *caps;
193         u8 lu_type;
194         u16 byte_mask;
195         u8 bit_mask[DR_STE_SIZE_MASK];
196         int (*ste_build_tag_func)(struct mlx5dr_match_param *spec,
197                                   struct mlx5dr_ste_build *sb,
198                                   u8 *tag);
199 };
200
201 struct mlx5dr_ste_htbl *
202 mlx5dr_ste_htbl_alloc(struct mlx5dr_icm_pool *pool,
203                       enum mlx5dr_icm_chunk_size chunk_size,
204                       u8 lu_type, u16 byte_mask);
205
206 int mlx5dr_ste_htbl_free(struct mlx5dr_ste_htbl *htbl);
207
208 static inline void mlx5dr_htbl_put(struct mlx5dr_ste_htbl *htbl)
209 {
210         htbl->refcount--;
211         if (!htbl->refcount)
212                 mlx5dr_ste_htbl_free(htbl);
213 }
214
215 static inline void mlx5dr_htbl_get(struct mlx5dr_ste_htbl *htbl)
216 {
217         htbl->refcount++;
218 }
219
220 /* STE utils */
221 u32 mlx5dr_ste_calc_hash_index(u8 *hw_ste_p, struct mlx5dr_ste_htbl *htbl);
222 void mlx5dr_ste_init(u8 *hw_ste_p, u8 lu_type, u8 entry_type, u16 gvmi);
223 void mlx5dr_ste_always_hit_htbl(struct mlx5dr_ste *ste,
224                                 struct mlx5dr_ste_htbl *next_htbl);
225 void mlx5dr_ste_set_miss_addr(u8 *hw_ste, u64 miss_addr);
226 u64 mlx5dr_ste_get_miss_addr(u8 *hw_ste);
227 void mlx5dr_ste_set_hit_gvmi(u8 *hw_ste_p, u16 gvmi);
228 void mlx5dr_ste_set_hit_addr(u8 *hw_ste, u64 icm_addr, u32 ht_size);
229 void mlx5dr_ste_always_miss_addr(struct mlx5dr_ste *ste, u64 miss_addr);
230 void mlx5dr_ste_set_bit_mask(u8 *hw_ste_p, u8 *bit_mask);
231 bool mlx5dr_ste_is_last_in_rule(struct mlx5dr_matcher_rx_tx *nic_matcher,
232                                 u8 ste_location);
233 void mlx5dr_ste_rx_set_flow_tag(u8 *hw_ste_p, u32 flow_tag);
234 void mlx5dr_ste_set_counter_id(u8 *hw_ste_p, u32 ctr_id);
235 void mlx5dr_ste_set_tx_encap(void *hw_ste_p, u32 reformat_id,
236                              int size, bool encap_l3);
237 void mlx5dr_ste_set_rx_decap(u8 *hw_ste_p);
238 void mlx5dr_ste_set_rx_decap_l3(u8 *hw_ste_p, bool vlan);
239 void mlx5dr_ste_set_rx_pop_vlan(u8 *hw_ste_p);
240 void mlx5dr_ste_set_tx_push_vlan(u8 *hw_ste_p, u32 vlan_tpid_pcp_dei_vid,
241                                  bool go_back);
242 void mlx5dr_ste_set_entry_type(u8 *hw_ste_p, u8 entry_type);
243 u8 mlx5dr_ste_get_entry_type(u8 *hw_ste_p);
244 void mlx5dr_ste_set_rewrite_actions(u8 *hw_ste_p, u16 num_of_actions,
245                                     u32 re_write_index);
246 void mlx5dr_ste_set_go_back_bit(u8 *hw_ste_p);
247 u64 mlx5dr_ste_get_icm_addr(struct mlx5dr_ste *ste);
248 u64 mlx5dr_ste_get_mr_addr(struct mlx5dr_ste *ste);
249 struct list_head *mlx5dr_ste_get_miss_list(struct mlx5dr_ste *ste);
250
251 void mlx5dr_ste_free(struct mlx5dr_ste *ste,
252                      struct mlx5dr_matcher *matcher,
253                      struct mlx5dr_matcher_rx_tx *nic_matcher);
254 static inline void mlx5dr_ste_put(struct mlx5dr_ste *ste,
255                                   struct mlx5dr_matcher *matcher,
256                                   struct mlx5dr_matcher_rx_tx *nic_matcher)
257 {
258         ste->refcount--;
259         if (!ste->refcount)
260                 mlx5dr_ste_free(ste, matcher, nic_matcher);
261 }
262
263 /* initial as 0, increased only when ste appears in a new rule */
264 static inline void mlx5dr_ste_get(struct mlx5dr_ste *ste)
265 {
266         ste->refcount++;
267 }
268
269 static inline bool mlx5dr_ste_is_not_used(struct mlx5dr_ste *ste)
270 {
271         return !ste->refcount;
272 }
273
274 void mlx5dr_ste_set_hit_addr_by_next_htbl(u8 *hw_ste,
275                                           struct mlx5dr_ste_htbl *next_htbl);
276 bool mlx5dr_ste_equal_tag(void *src, void *dst);
277 int mlx5dr_ste_create_next_htbl(struct mlx5dr_matcher *matcher,
278                                 struct mlx5dr_matcher_rx_tx *nic_matcher,
279                                 struct mlx5dr_ste *ste,
280                                 u8 *cur_hw_ste,
281                                 enum mlx5dr_icm_chunk_size log_table_size);
282
283 /* STE build functions */
284 int mlx5dr_ste_build_pre_check(struct mlx5dr_domain *dmn,
285                                u8 match_criteria,
286                                struct mlx5dr_match_param *mask,
287                                struct mlx5dr_match_param *value);
288 int mlx5dr_ste_build_ste_arr(struct mlx5dr_matcher *matcher,
289                              struct mlx5dr_matcher_rx_tx *nic_matcher,
290                              struct mlx5dr_match_param *value,
291                              u8 *ste_arr);
292 void mlx5dr_ste_build_eth_l2_src_dst(struct mlx5dr_ste_build *builder,
293                                      struct mlx5dr_match_param *mask,
294                                      bool inner, bool rx);
295 void mlx5dr_ste_build_eth_l3_ipv4_5_tuple(struct mlx5dr_ste_build *sb,
296                                           struct mlx5dr_match_param *mask,
297                                           bool inner, bool rx);
298 void mlx5dr_ste_build_eth_l3_ipv4_misc(struct mlx5dr_ste_build *sb,
299                                        struct mlx5dr_match_param *mask,
300                                        bool inner, bool rx);
301 void mlx5dr_ste_build_eth_l3_ipv6_dst(struct mlx5dr_ste_build *sb,
302                                       struct mlx5dr_match_param *mask,
303                                       bool inner, bool rx);
304 void mlx5dr_ste_build_eth_l3_ipv6_src(struct mlx5dr_ste_build *sb,
305                                       struct mlx5dr_match_param *mask,
306                                       bool inner, bool rx);
307 void mlx5dr_ste_build_eth_l2_src(struct mlx5dr_ste_build *sb,
308                                  struct mlx5dr_match_param *mask,
309                                  bool inner, bool rx);
310 void mlx5dr_ste_build_eth_l2_dst(struct mlx5dr_ste_build *sb,
311                                  struct mlx5dr_match_param *mask,
312                                  bool inner, bool rx);
313 void mlx5dr_ste_build_eth_l2_tnl(struct mlx5dr_ste_build *sb,
314                                  struct mlx5dr_match_param *mask,
315                                  bool inner, bool rx);
316 void mlx5dr_ste_build_eth_ipv6_l3_l4(struct mlx5dr_ste_build *sb,
317                                      struct mlx5dr_match_param *mask,
318                                      bool inner, bool rx);
319 void mlx5dr_ste_build_eth_l4_misc(struct mlx5dr_ste_build *sb,
320                                   struct mlx5dr_match_param *mask,
321                                   bool inner, bool rx);
322 void mlx5dr_ste_build_tnl_gre(struct mlx5dr_ste_build *sb,
323                               struct mlx5dr_match_param *mask,
324                               bool inner, bool rx);
325 void mlx5dr_ste_build_mpls(struct mlx5dr_ste_build *sb,
326                            struct mlx5dr_match_param *mask,
327                            bool inner, bool rx);
328 void mlx5dr_ste_build_tnl_mpls(struct mlx5dr_ste_build *sb,
329                                struct mlx5dr_match_param *mask,
330                                bool inner, bool rx);
331 int mlx5dr_ste_build_icmp(struct mlx5dr_ste_build *sb,
332                           struct mlx5dr_match_param *mask,
333                           struct mlx5dr_cmd_caps *caps,
334                           bool inner, bool rx);
335 void mlx5dr_ste_build_tnl_vxlan_gpe(struct mlx5dr_ste_build *sb,
336                                     struct mlx5dr_match_param *mask,
337                                     bool inner, bool rx);
338 void mlx5dr_ste_build_tnl_geneve(struct mlx5dr_ste_build *sb,
339                                  struct mlx5dr_match_param *mask,
340                                  bool inner, bool rx);
341 void mlx5dr_ste_build_general_purpose(struct mlx5dr_ste_build *sb,
342                                       struct mlx5dr_match_param *mask,
343                                       bool inner, bool rx);
344 void mlx5dr_ste_build_register_0(struct mlx5dr_ste_build *sb,
345                                  struct mlx5dr_match_param *mask,
346                                  bool inner, bool rx);
347 void mlx5dr_ste_build_register_1(struct mlx5dr_ste_build *sb,
348                                  struct mlx5dr_match_param *mask,
349                                  bool inner, bool rx);
350 void mlx5dr_ste_build_src_gvmi_qpn(struct mlx5dr_ste_build *sb,
351                                    struct mlx5dr_match_param *mask,
352                                    struct mlx5dr_domain *dmn,
353                                    bool inner, bool rx);
354 void mlx5dr_ste_build_empty_always_hit(struct mlx5dr_ste_build *sb, bool rx);
355
356 /* Actions utils */
357 int mlx5dr_actions_build_ste_arr(struct mlx5dr_matcher *matcher,
358                                  struct mlx5dr_matcher_rx_tx *nic_matcher,
359                                  struct mlx5dr_action *actions[],
360                                  u32 num_actions,
361                                  u8 *ste_arr,
362                                  u32 *new_hw_ste_arr_sz);
363
364 struct mlx5dr_match_spec {
365         u32 smac_47_16;         /* Source MAC address of incoming packet */
366         /* Incoming packet Ethertype - this is the Ethertype
367          * following the last VLAN tag of the packet
368          */
369         u32 ethertype:16;
370         u32 smac_15_0:16;       /* Source MAC address of incoming packet */
371         u32 dmac_47_16;         /* Destination MAC address of incoming packet */
372         /* VLAN ID of first VLAN tag in the incoming packet.
373          * Valid only when cvlan_tag==1 or svlan_tag==1
374          */
375         u32 first_vid:12;
376         /* CFI bit of first VLAN tag in the incoming packet.
377          * Valid only when cvlan_tag==1 or svlan_tag==1
378          */
379         u32 first_cfi:1;
380         /* Priority of first VLAN tag in the incoming packet.
381          * Valid only when cvlan_tag==1 or svlan_tag==1
382          */
383         u32 first_prio:3;
384         u32 dmac_15_0:16;       /* Destination MAC address of incoming packet */
385         /* TCP flags. ;Bit 0: FIN;Bit 1: SYN;Bit 2: RST;Bit 3: PSH;Bit 4: ACK;
386          *             Bit 5: URG;Bit 6: ECE;Bit 7: CWR;Bit 8: NS
387          */
388         u32 tcp_flags:9;
389         u32 ip_version:4;       /* IP version */
390         u32 frag:1;             /* Packet is an IP fragment */
391         /* The first vlan in the packet is s-vlan (0x8a88).
392          * cvlan_tag and svlan_tag cannot be set together
393          */
394         u32 svlan_tag:1;
395         /* The first vlan in the packet is c-vlan (0x8100).
396          * cvlan_tag and svlan_tag cannot be set together
397          */
398         u32 cvlan_tag:1;
399         /* Explicit Congestion Notification derived from
400          * Traffic Class/TOS field of IPv6/v4
401          */
402         u32 ip_ecn:2;
403         /* Differentiated Services Code Point derived from
404          * Traffic Class/TOS field of IPv6/v4
405          */
406         u32 ip_dscp:6;
407         u32 ip_protocol:8;      /* IP protocol */
408         /* TCP destination port.
409          * tcp and udp sport/dport are mutually exclusive
410          */
411         u32 tcp_dport:16;
412         /* TCP source port.;tcp and udp sport/dport are mutually exclusive */
413         u32 tcp_sport:16;
414         u32 ttl_hoplimit:8;
415         u32 reserved:24;
416         /* UDP destination port.;tcp and udp sport/dport are mutually exclusive */
417         u32 udp_dport:16;
418         /* UDP source port.;tcp and udp sport/dport are mutually exclusive */
419         u32 udp_sport:16;
420         /* IPv6 source address of incoming packets
421          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
422          * This field should be qualified by an appropriate ethertype
423          */
424         u32 src_ip_127_96;
425         /* IPv6 source address of incoming packets
426          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
427          * This field should be qualified by an appropriate ethertype
428          */
429         u32 src_ip_95_64;
430         /* IPv6 source address of incoming packets
431          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
432          * This field should be qualified by an appropriate ethertype
433          */
434         u32 src_ip_63_32;
435         /* IPv6 source address of incoming packets
436          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
437          * This field should be qualified by an appropriate ethertype
438          */
439         u32 src_ip_31_0;
440         /* IPv6 destination address of incoming packets
441          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
442          * This field should be qualified by an appropriate ethertype
443          */
444         u32 dst_ip_127_96;
445         /* IPv6 destination address of incoming packets
446          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
447          * This field should be qualified by an appropriate ethertype
448          */
449         u32 dst_ip_95_64;
450         /* IPv6 destination address of incoming packets
451          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
452          * This field should be qualified by an appropriate ethertype
453          */
454         u32 dst_ip_63_32;
455         /* IPv6 destination address of incoming packets
456          * For IPv4 address use bits 31:0 (rest of the bits are reserved)
457          * This field should be qualified by an appropriate ethertype
458          */
459         u32 dst_ip_31_0;
460 };
461
462 struct mlx5dr_match_misc {
463         u32 source_sqn:24;              /* Source SQN */
464         u32 source_vhca_port:4;
465         /* used with GRE, sequence number exist when gre_s_present == 1 */
466         u32 gre_s_present:1;
467         /* used with GRE, key exist when gre_k_present == 1 */
468         u32 gre_k_present:1;
469         u32 reserved_auto1:1;
470         /* used with GRE, checksum exist when gre_c_present == 1 */
471         u32 gre_c_present:1;
472         /* Source port.;0xffff determines wire port */
473         u32 source_port:16;
474         u32 source_eswitch_owner_vhca_id:16;
475         /* VLAN ID of first VLAN tag the inner header of the incoming packet.
476          * Valid only when inner_second_cvlan_tag ==1 or inner_second_svlan_tag ==1
477          */
478         u32 inner_second_vid:12;
479         /* CFI bit of first VLAN tag in the inner header of the incoming packet.
480          * Valid only when inner_second_cvlan_tag ==1 or inner_second_svlan_tag ==1
481          */
482         u32 inner_second_cfi:1;
483         /* Priority of second VLAN tag in the inner header of the incoming packet.
484          * Valid only when inner_second_cvlan_tag ==1 or inner_second_svlan_tag ==1
485          */
486         u32 inner_second_prio:3;
487         /* VLAN ID of first VLAN tag the outer header of the incoming packet.
488          * Valid only when outer_second_cvlan_tag ==1 or outer_second_svlan_tag ==1
489          */
490         u32 outer_second_vid:12;
491         /* CFI bit of first VLAN tag in the outer header of the incoming packet.
492          * Valid only when outer_second_cvlan_tag ==1 or outer_second_svlan_tag ==1
493          */
494         u32 outer_second_cfi:1;
495         /* Priority of second VLAN tag in the outer header of the incoming packet.
496          * Valid only when outer_second_cvlan_tag ==1 or outer_second_svlan_tag ==1
497          */
498         u32 outer_second_prio:3;
499         u32 gre_protocol:16;            /* GRE Protocol (outer) */
500         u32 reserved_auto3:12;
501         /* The second vlan in the inner header of the packet is s-vlan (0x8a88).
502          * inner_second_cvlan_tag and inner_second_svlan_tag cannot be set together
503          */
504         u32 inner_second_svlan_tag:1;
505         /* The second vlan in the outer header of the packet is s-vlan (0x8a88).
506          * outer_second_cvlan_tag and outer_second_svlan_tag cannot be set together
507          */
508         u32 outer_second_svlan_tag:1;
509         /* The second vlan in the inner header of the packet is c-vlan (0x8100).
510          * inner_second_cvlan_tag and inner_second_svlan_tag cannot be set together
511          */
512         u32 inner_second_cvlan_tag:1;
513         /* The second vlan in the outer header of the packet is c-vlan (0x8100).
514          * outer_second_cvlan_tag and outer_second_svlan_tag cannot be set together
515          */
516         u32 outer_second_cvlan_tag:1;
517         u32 gre_key_l:8;                /* GRE Key [7:0] (outer) */
518         u32 gre_key_h:24;               /* GRE Key[31:8] (outer) */
519         u32 reserved_auto4:8;
520         u32 vxlan_vni:24;               /* VXLAN VNI (outer) */
521         u32 geneve_oam:1;               /* GENEVE OAM field (outer) */
522         u32 reserved_auto5:7;
523         u32 geneve_vni:24;              /* GENEVE VNI field (outer) */
524         u32 outer_ipv6_flow_label:20;   /* Flow label of incoming IPv6 packet (outer) */
525         u32 reserved_auto6:12;
526         u32 inner_ipv6_flow_label:20;   /* Flow label of incoming IPv6 packet (inner) */
527         u32 reserved_auto7:12;
528         u32 geneve_protocol_type:16;    /* GENEVE protocol type (outer) */
529         u32 geneve_opt_len:6;           /* GENEVE OptLen (outer) */
530         u32 reserved_auto8:10;
531         u32 bth_dst_qp:24;              /* Destination QP in BTH header */
532         u32 reserved_auto9:8;
533         u8 reserved_auto10[20];
534 };
535
536 struct mlx5dr_match_misc2 {
537         u32 outer_first_mpls_ttl:8;             /* First MPLS TTL (outer) */
538         u32 outer_first_mpls_s_bos:1;           /* First MPLS S_BOS (outer) */
539         u32 outer_first_mpls_exp:3;             /* First MPLS EXP (outer) */
540         u32 outer_first_mpls_label:20;          /* First MPLS LABEL (outer) */
541         u32 inner_first_mpls_ttl:8;             /* First MPLS TTL (inner) */
542         u32 inner_first_mpls_s_bos:1;           /* First MPLS S_BOS (inner) */
543         u32 inner_first_mpls_exp:3;             /* First MPLS EXP (inner) */
544         u32 inner_first_mpls_label:20;          /* First MPLS LABEL (inner) */
545         u32 outer_first_mpls_over_gre_ttl:8;    /* last MPLS TTL (outer) */
546         u32 outer_first_mpls_over_gre_s_bos:1;  /* last MPLS S_BOS (outer) */
547         u32 outer_first_mpls_over_gre_exp:3;    /* last MPLS EXP (outer) */
548         u32 outer_first_mpls_over_gre_label:20; /* last MPLS LABEL (outer) */
549         u32 outer_first_mpls_over_udp_ttl:8;    /* last MPLS TTL (outer) */
550         u32 outer_first_mpls_over_udp_s_bos:1;  /* last MPLS S_BOS (outer) */
551         u32 outer_first_mpls_over_udp_exp:3;    /* last MPLS EXP (outer) */
552         u32 outer_first_mpls_over_udp_label:20; /* last MPLS LABEL (outer) */
553         u32 metadata_reg_c_7;                   /* metadata_reg_c_7 */
554         u32 metadata_reg_c_6;                   /* metadata_reg_c_6 */
555         u32 metadata_reg_c_5;                   /* metadata_reg_c_5 */
556         u32 metadata_reg_c_4;                   /* metadata_reg_c_4 */
557         u32 metadata_reg_c_3;                   /* metadata_reg_c_3 */
558         u32 metadata_reg_c_2;                   /* metadata_reg_c_2 */
559         u32 metadata_reg_c_1;                   /* metadata_reg_c_1 */
560         u32 metadata_reg_c_0;                   /* metadata_reg_c_0 */
561         u32 metadata_reg_a;                     /* metadata_reg_a */
562         u8 reserved_auto2[12];
563 };
564
565 struct mlx5dr_match_misc3 {
566         u32 inner_tcp_seq_num;
567         u32 outer_tcp_seq_num;
568         u32 inner_tcp_ack_num;
569         u32 outer_tcp_ack_num;
570         u32 outer_vxlan_gpe_vni:24;
571         u32 reserved_auto1:8;
572         u32 reserved_auto2:16;
573         u32 outer_vxlan_gpe_flags:8;
574         u32 outer_vxlan_gpe_next_protocol:8;
575         u32 icmpv4_header_data;
576         u32 icmpv6_header_data;
577         u32 icmpv6_code:8;
578         u32 icmpv6_type:8;
579         u32 icmpv4_code:8;
580         u32 icmpv4_type:8;
581         u8 reserved_auto3[0x1c];
582 };
583
584 struct mlx5dr_match_param {
585         struct mlx5dr_match_spec outer;
586         struct mlx5dr_match_misc misc;
587         struct mlx5dr_match_spec inner;
588         struct mlx5dr_match_misc2 misc2;
589         struct mlx5dr_match_misc3 misc3;
590 };
591
592 #define DR_MASK_IS_ICMPV4_SET(_misc3) ((_misc3)->icmpv4_type || \
593                                        (_misc3)->icmpv4_code || \
594                                        (_misc3)->icmpv4_header_data)
595
596 struct mlx5dr_esw_caps {
597         u64 drop_icm_address_rx;
598         u64 drop_icm_address_tx;
599         u64 uplink_icm_address_rx;
600         u64 uplink_icm_address_tx;
601         bool sw_owner;
602 };
603
604 struct mlx5dr_cmd_vport_cap {
605         u16 vport_gvmi;
606         u16 vhca_gvmi;
607         u64 icm_address_rx;
608         u64 icm_address_tx;
609         u32 num;
610 };
611
612 struct mlx5dr_cmd_caps {
613         u16 gvmi;
614         u64 nic_rx_drop_address;
615         u64 nic_tx_drop_address;
616         u64 nic_tx_allow_address;
617         u64 esw_rx_drop_address;
618         u64 esw_tx_drop_address;
619         u32 log_icm_size;
620         u64 hdr_modify_icm_addr;
621         u32 flex_protocols;
622         u8 flex_parser_id_icmp_dw0;
623         u8 flex_parser_id_icmp_dw1;
624         u8 flex_parser_id_icmpv6_dw0;
625         u8 flex_parser_id_icmpv6_dw1;
626         u8 max_ft_level;
627         u16 roce_min_src_udp;
628         u8 num_esw_ports;
629         u8 sw_format_ver;
630         bool eswitch_manager;
631         bool rx_sw_owner;
632         bool tx_sw_owner;
633         bool fdb_sw_owner;
634         u32 num_vports;
635         struct mlx5dr_esw_caps esw_caps;
636         struct mlx5dr_cmd_vport_cap *vports_caps;
637         bool prio_tag_required;
638 };
639
640 struct mlx5dr_domain_rx_tx {
641         u64 drop_icm_addr;
642         u64 default_icm_addr;
643         enum mlx5dr_ste_entry_type ste_type;
644         struct mutex mutex; /* protect rx/tx domain */
645 };
646
647 struct mlx5dr_domain_info {
648         bool supp_sw_steering;
649         u32 max_inline_size;
650         u32 max_send_wr;
651         u32 max_log_sw_icm_sz;
652         u32 max_log_action_icm_sz;
653         struct mlx5dr_domain_rx_tx rx;
654         struct mlx5dr_domain_rx_tx tx;
655         struct mlx5dr_cmd_caps caps;
656 };
657
658 struct mlx5dr_domain_cache {
659         struct mlx5dr_fw_recalc_cs_ft **recalc_cs_ft;
660 };
661
662 struct mlx5dr_domain {
663         struct mlx5dr_domain *peer_dmn;
664         struct mlx5_core_dev *mdev;
665         u32 pdn;
666         struct mlx5_uars_page *uar;
667         enum mlx5dr_domain_type type;
668         refcount_t refcount;
669         struct mlx5dr_icm_pool *ste_icm_pool;
670         struct mlx5dr_icm_pool *action_icm_pool;
671         struct mlx5dr_send_ring *send_ring;
672         struct mlx5dr_domain_info info;
673         struct mlx5dr_domain_cache cache;
674 };
675
676 struct mlx5dr_table_rx_tx {
677         struct mlx5dr_ste_htbl *s_anchor;
678         struct mlx5dr_domain_rx_tx *nic_dmn;
679         u64 default_icm_addr;
680 };
681
682 struct mlx5dr_table {
683         struct mlx5dr_domain *dmn;
684         struct mlx5dr_table_rx_tx rx;
685         struct mlx5dr_table_rx_tx tx;
686         u32 level;
687         u32 table_type;
688         u32 table_id;
689         u32 flags;
690         struct list_head matcher_list;
691         struct mlx5dr_action *miss_action;
692         refcount_t refcount;
693 };
694
695 struct mlx5dr_matcher_rx_tx {
696         struct mlx5dr_ste_htbl *s_htbl;
697         struct mlx5dr_ste_htbl *e_anchor;
698         struct mlx5dr_ste_build *ste_builder;
699         struct mlx5dr_ste_build ste_builder_arr[DR_RULE_IPV_MAX]
700                                                [DR_RULE_IPV_MAX]
701                                                [DR_RULE_MAX_STES];
702         u8 num_of_builders;
703         u8 num_of_builders_arr[DR_RULE_IPV_MAX][DR_RULE_IPV_MAX];
704         u64 default_icm_addr;
705         struct mlx5dr_table_rx_tx *nic_tbl;
706 };
707
708 struct mlx5dr_matcher {
709         struct mlx5dr_table *tbl;
710         struct mlx5dr_matcher_rx_tx rx;
711         struct mlx5dr_matcher_rx_tx tx;
712         struct list_head matcher_list;
713         u32 prio;
714         struct mlx5dr_match_param mask;
715         u8 match_criteria;
716         refcount_t refcount;
717         struct mlx5dv_flow_matcher *dv_matcher;
718 };
719
720 struct mlx5dr_rule_member {
721         struct mlx5dr_ste *ste;
722         /* attached to mlx5dr_rule via this */
723         struct list_head list;
724         /* attached to mlx5dr_ste via this */
725         struct list_head use_ste_list;
726 };
727
728 struct mlx5dr_action {
729         enum mlx5dr_action_type action_type;
730         refcount_t refcount;
731         union {
732                 struct {
733                         struct mlx5dr_domain *dmn;
734                         struct mlx5dr_icm_chunk *chunk;
735                         u8 *data;
736                         u16 num_of_actions;
737                         u32 index;
738                         u8 allow_rx:1;
739                         u8 allow_tx:1;
740                         u8 modify_ttl:1;
741                 } rewrite;
742                 struct {
743                         struct mlx5dr_domain *dmn;
744                         u32 reformat_id;
745                         u32 reformat_size;
746                 } reformat;
747                 struct {
748                         u8 is_fw_tbl:1;
749                         union {
750                                 struct mlx5dr_table *tbl;
751                                 struct {
752                                         struct mlx5dr_domain *dmn;
753                                         u32 id;
754                                         u32 group_id;
755                                         enum fs_flow_table_type type;
756                                         u64 rx_icm_addr;
757                                         u64 tx_icm_addr;
758                                         struct mlx5dr_action **ref_actions;
759                                         u32 num_of_ref_actions;
760                                 } fw_tbl;
761                         };
762                 } dest_tbl;
763                 struct {
764                         u32 ctr_id;
765                         u32 offeset;
766                 } ctr;
767                 struct {
768                         struct mlx5dr_domain *dmn;
769                         struct mlx5dr_cmd_vport_cap *caps;
770                 } vport;
771                 struct {
772                         u32 vlan_hdr; /* tpid_pcp_dei_vid */
773                 } push_vlan;
774                 u32 flow_tag;
775         };
776 };
777
778 enum mlx5dr_connect_type {
779         CONNECT_HIT     = 1,
780         CONNECT_MISS    = 2,
781 };
782
783 struct mlx5dr_htbl_connect_info {
784         enum mlx5dr_connect_type type;
785         union {
786                 struct mlx5dr_ste_htbl *hit_next_htbl;
787                 u64 miss_icm_addr;
788         };
789 };
790
791 struct mlx5dr_rule_rx_tx {
792         struct list_head rule_members_list;
793         struct mlx5dr_matcher_rx_tx *nic_matcher;
794 };
795
796 struct mlx5dr_rule {
797         struct mlx5dr_matcher *matcher;
798         struct mlx5dr_rule_rx_tx rx;
799         struct mlx5dr_rule_rx_tx tx;
800         struct list_head rule_actions_list;
801         u32 flow_source;
802 };
803
804 void mlx5dr_rule_update_rule_member(struct mlx5dr_ste *new_ste,
805                                     struct mlx5dr_ste *ste);
806
807 struct mlx5dr_icm_chunk {
808         struct mlx5dr_icm_buddy_mem *buddy_mem;
809         struct list_head chunk_list;
810         u32 rkey;
811         u32 num_of_entries;
812         u32 byte_size;
813         u64 icm_addr;
814         u64 mr_addr;
815
816         /* indicates the index of this chunk in the whole memory,
817          * used for deleting the chunk from the buddy
818          */
819         unsigned int seg;
820
821         /* Memory optimisation */
822         struct mlx5dr_ste *ste_arr;
823         u8 *hw_ste_arr;
824         struct list_head *miss_list;
825 };
826
827 static inline void mlx5dr_domain_nic_lock(struct mlx5dr_domain_rx_tx *nic_dmn)
828 {
829         mutex_lock(&nic_dmn->mutex);
830 }
831
832 static inline void mlx5dr_domain_nic_unlock(struct mlx5dr_domain_rx_tx *nic_dmn)
833 {
834         mutex_unlock(&nic_dmn->mutex);
835 }
836
837 static inline void mlx5dr_domain_lock(struct mlx5dr_domain *dmn)
838 {
839         mlx5dr_domain_nic_lock(&dmn->info.rx);
840         mlx5dr_domain_nic_lock(&dmn->info.tx);
841 }
842
843 static inline void mlx5dr_domain_unlock(struct mlx5dr_domain *dmn)
844 {
845         mlx5dr_domain_nic_unlock(&dmn->info.tx);
846         mlx5dr_domain_nic_unlock(&dmn->info.rx);
847 }
848
849 int mlx5dr_matcher_select_builders(struct mlx5dr_matcher *matcher,
850                                    struct mlx5dr_matcher_rx_tx *nic_matcher,
851                                    enum mlx5dr_ipv outer_ipv,
852                                    enum mlx5dr_ipv inner_ipv);
853
854 static inline int
855 mlx5dr_icm_pool_dm_type_to_entry_size(enum mlx5dr_icm_type icm_type)
856 {
857         if (icm_type == DR_ICM_TYPE_STE)
858                 return DR_STE_SIZE;
859
860         return DR_MODIFY_ACTION_SIZE;
861 }
862
863 static inline u32
864 mlx5dr_icm_pool_chunk_size_to_entries(enum mlx5dr_icm_chunk_size chunk_size)
865 {
866         return 1 << chunk_size;
867 }
868
869 static inline int
870 mlx5dr_icm_pool_chunk_size_to_byte(enum mlx5dr_icm_chunk_size chunk_size,
871                                    enum mlx5dr_icm_type icm_type)
872 {
873         int num_of_entries;
874         int entry_size;
875
876         entry_size = mlx5dr_icm_pool_dm_type_to_entry_size(icm_type);
877         num_of_entries = mlx5dr_icm_pool_chunk_size_to_entries(chunk_size);
878
879         return entry_size * num_of_entries;
880 }
881
882 static inline struct mlx5dr_cmd_vport_cap *
883 mlx5dr_get_vport_cap(struct mlx5dr_cmd_caps *caps, u32 vport)
884 {
885         if (!caps->vports_caps ||
886             (vport >= caps->num_vports && vport != WIRE_PORT))
887                 return NULL;
888
889         if (vport == WIRE_PORT)
890                 vport = caps->num_vports;
891
892         return &caps->vports_caps[vport];
893 }
894
895 struct mlx5dr_cmd_query_flow_table_details {
896         u8 status;
897         u8 level;
898         u64 sw_owner_icm_root_1;
899         u64 sw_owner_icm_root_0;
900 };
901
902 struct mlx5dr_cmd_create_flow_table_attr {
903         u32 table_type;
904         u64 icm_addr_rx;
905         u64 icm_addr_tx;
906         u8 level;
907         bool sw_owner;
908         bool term_tbl;
909         bool decap_en;
910         bool reformat_en;
911 };
912
913 /* internal API functions */
914 int mlx5dr_cmd_query_device(struct mlx5_core_dev *mdev,
915                             struct mlx5dr_cmd_caps *caps);
916 int mlx5dr_cmd_query_esw_vport_context(struct mlx5_core_dev *mdev,
917                                        bool other_vport, u16 vport_number,
918                                        u64 *icm_address_rx,
919                                        u64 *icm_address_tx);
920 int mlx5dr_cmd_query_gvmi(struct mlx5_core_dev *mdev,
921                           bool other_vport, u16 vport_number, u16 *gvmi);
922 int mlx5dr_cmd_query_esw_caps(struct mlx5_core_dev *mdev,
923                               struct mlx5dr_esw_caps *caps);
924 int mlx5dr_cmd_sync_steering(struct mlx5_core_dev *mdev);
925 int mlx5dr_cmd_set_fte_modify_and_vport(struct mlx5_core_dev *mdev,
926                                         u32 table_type,
927                                         u32 table_id,
928                                         u32 group_id,
929                                         u32 modify_header_id,
930                                         u32 vport_id);
931 int mlx5dr_cmd_del_flow_table_entry(struct mlx5_core_dev *mdev,
932                                     u32 table_type,
933                                     u32 table_id);
934 int mlx5dr_cmd_alloc_modify_header(struct mlx5_core_dev *mdev,
935                                    u32 table_type,
936                                    u8 num_of_actions,
937                                    u64 *actions,
938                                    u32 *modify_header_id);
939 int mlx5dr_cmd_dealloc_modify_header(struct mlx5_core_dev *mdev,
940                                      u32 modify_header_id);
941 int mlx5dr_cmd_create_empty_flow_group(struct mlx5_core_dev *mdev,
942                                        u32 table_type,
943                                        u32 table_id,
944                                        u32 *group_id);
945 int mlx5dr_cmd_destroy_flow_group(struct mlx5_core_dev *mdev,
946                                   u32 table_type,
947                                   u32 table_id,
948                                   u32 group_id);
949 int mlx5dr_cmd_create_flow_table(struct mlx5_core_dev *mdev,
950                                  struct mlx5dr_cmd_create_flow_table_attr *attr,
951                                  u64 *fdb_rx_icm_addr,
952                                  u32 *table_id);
953 int mlx5dr_cmd_destroy_flow_table(struct mlx5_core_dev *mdev,
954                                   u32 table_id,
955                                   u32 table_type);
956 int mlx5dr_cmd_query_flow_table(struct mlx5_core_dev *dev,
957                                 enum fs_flow_table_type type,
958                                 u32 table_id,
959                                 struct mlx5dr_cmd_query_flow_table_details *output);
960 int mlx5dr_cmd_create_reformat_ctx(struct mlx5_core_dev *mdev,
961                                    enum mlx5_reformat_ctx_type rt,
962                                    size_t reformat_size,
963                                    void *reformat_data,
964                                    u32 *reformat_id);
965 void mlx5dr_cmd_destroy_reformat_ctx(struct mlx5_core_dev *mdev,
966                                      u32 reformat_id);
967
968 struct mlx5dr_cmd_gid_attr {
969         u8 gid[16];
970         u8 mac[6];
971         u32 roce_ver;
972 };
973
974 struct mlx5dr_cmd_qp_create_attr {
975         u32 page_id;
976         u32 pdn;
977         u32 cqn;
978         u32 pm_state;
979         u32 service_type;
980         u32 buff_umem_id;
981         u32 db_umem_id;
982         u32 sq_wqe_cnt;
983         u32 rq_wqe_cnt;
984         u32 rq_wqe_shift;
985 };
986
987 int mlx5dr_cmd_query_gid(struct mlx5_core_dev *mdev, u8 vhca_port_num,
988                          u16 index, struct mlx5dr_cmd_gid_attr *attr);
989
990 struct mlx5dr_icm_pool *mlx5dr_icm_pool_create(struct mlx5dr_domain *dmn,
991                                                enum mlx5dr_icm_type icm_type);
992 void mlx5dr_icm_pool_destroy(struct mlx5dr_icm_pool *pool);
993
994 struct mlx5dr_icm_chunk *
995 mlx5dr_icm_alloc_chunk(struct mlx5dr_icm_pool *pool,
996                        enum mlx5dr_icm_chunk_size chunk_size);
997 void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk);
998 int mlx5dr_ste_htbl_init_and_postsend(struct mlx5dr_domain *dmn,
999                                       struct mlx5dr_domain_rx_tx *nic_dmn,
1000                                       struct mlx5dr_ste_htbl *htbl,
1001                                       struct mlx5dr_htbl_connect_info *connect_info,
1002                                       bool update_hw_ste);
1003 void mlx5dr_ste_set_formatted_ste(u16 gvmi,
1004                                   struct mlx5dr_domain_rx_tx *nic_dmn,
1005                                   struct mlx5dr_ste_htbl *htbl,
1006                                   u8 *formatted_ste,
1007                                   struct mlx5dr_htbl_connect_info *connect_info);
1008 void mlx5dr_ste_copy_param(u8 match_criteria,
1009                            struct mlx5dr_match_param *set_param,
1010                            struct mlx5dr_match_parameters *mask);
1011
1012 struct mlx5dr_qp {
1013         struct mlx5_core_dev *mdev;
1014         struct mlx5_wq_qp wq;
1015         struct mlx5_uars_page *uar;
1016         struct mlx5_wq_ctrl wq_ctrl;
1017         u32 qpn;
1018         struct {
1019                 unsigned int pc;
1020                 unsigned int cc;
1021                 unsigned int size;
1022                 unsigned int *wqe_head;
1023                 unsigned int wqe_cnt;
1024         } sq;
1025         struct {
1026                 unsigned int pc;
1027                 unsigned int cc;
1028                 unsigned int size;
1029                 unsigned int wqe_cnt;
1030         } rq;
1031         int max_inline_data;
1032 };
1033
1034 struct mlx5dr_cq {
1035         struct mlx5_core_dev *mdev;
1036         struct mlx5_cqwq wq;
1037         struct mlx5_wq_ctrl wq_ctrl;
1038         struct mlx5_core_cq mcq;
1039         struct mlx5dr_qp *qp;
1040 };
1041
1042 struct mlx5dr_mr {
1043         struct mlx5_core_dev *mdev;
1044         struct mlx5_core_mkey mkey;
1045         dma_addr_t dma_addr;
1046         void *addr;
1047         size_t size;
1048 };
1049
1050 #define MAX_SEND_CQE            64
1051 #define MIN_READ_SYNC           64
1052
1053 struct mlx5dr_send_ring {
1054         struct mlx5dr_cq *cq;
1055         struct mlx5dr_qp *qp;
1056         struct mlx5dr_mr *mr;
1057         /* How much wqes are waiting for completion */
1058         u32 pending_wqe;
1059         /* Signal request per this trash hold value */
1060         u16 signal_th;
1061         /* Each post_send_size less than max_post_send_size */
1062         u32 max_post_send_size;
1063         /* manage the send queue */
1064         u32 tx_head;
1065         void *buf;
1066         u32 buf_size;
1067         struct ib_wc wc[MAX_SEND_CQE];
1068         u8 sync_buff[MIN_READ_SYNC];
1069         struct mlx5dr_mr *sync_mr;
1070         spinlock_t lock; /* Protect the data path of the send ring */
1071 };
1072
1073 int mlx5dr_send_ring_alloc(struct mlx5dr_domain *dmn);
1074 void mlx5dr_send_ring_free(struct mlx5dr_domain *dmn,
1075                            struct mlx5dr_send_ring *send_ring);
1076 int mlx5dr_send_ring_force_drain(struct mlx5dr_domain *dmn);
1077 int mlx5dr_send_postsend_ste(struct mlx5dr_domain *dmn,
1078                              struct mlx5dr_ste *ste,
1079                              u8 *data,
1080                              u16 size,
1081                              u16 offset);
1082 int mlx5dr_send_postsend_htbl(struct mlx5dr_domain *dmn,
1083                               struct mlx5dr_ste_htbl *htbl,
1084                               u8 *formatted_ste, u8 *mask);
1085 int mlx5dr_send_postsend_formatted_htbl(struct mlx5dr_domain *dmn,
1086                                         struct mlx5dr_ste_htbl *htbl,
1087                                         u8 *ste_init_data,
1088                                         bool update_hw_ste);
1089 int mlx5dr_send_postsend_action(struct mlx5dr_domain *dmn,
1090                                 struct mlx5dr_action *action);
1091
1092 struct mlx5dr_cmd_ft_info {
1093         u32 id;
1094         u16 vport;
1095         enum fs_flow_table_type type;
1096 };
1097
1098 struct mlx5dr_cmd_flow_destination_hw_info {
1099         enum mlx5_flow_destination_type type;
1100         union {
1101                 u32 tir_num;
1102                 u32 ft_num;
1103                 u32 ft_id;
1104                 u32 counter_id;
1105                 struct {
1106                         u16 num;
1107                         u16 vhca_id;
1108                         u32 reformat_id;
1109                         u8 flags;
1110                 } vport;
1111         };
1112 };
1113
1114 struct mlx5dr_cmd_fte_info {
1115         u32 dests_size;
1116         u32 index;
1117         struct mlx5_flow_context flow_context;
1118         u32 *val;
1119         struct mlx5_flow_act action;
1120         struct mlx5dr_cmd_flow_destination_hw_info *dest_arr;
1121 };
1122
1123 int mlx5dr_cmd_set_fte(struct mlx5_core_dev *dev,
1124                        int opmod, int modify_mask,
1125                        struct mlx5dr_cmd_ft_info *ft,
1126                        u32 group_id,
1127                        struct mlx5dr_cmd_fte_info *fte);
1128
1129 struct mlx5dr_fw_recalc_cs_ft {
1130         u64 rx_icm_addr;
1131         u32 table_id;
1132         u32 group_id;
1133         u32 modify_hdr_id;
1134 };
1135
1136 struct mlx5dr_fw_recalc_cs_ft *
1137 mlx5dr_fw_create_recalc_cs_ft(struct mlx5dr_domain *dmn, u32 vport_num);
1138 void mlx5dr_fw_destroy_recalc_cs_ft(struct mlx5dr_domain *dmn,
1139                                     struct mlx5dr_fw_recalc_cs_ft *recalc_cs_ft);
1140 int mlx5dr_domain_cache_get_recalc_cs_ft_addr(struct mlx5dr_domain *dmn,
1141                                               u32 vport_num,
1142                                               u64 *rx_icm_addr);
1143 int mlx5dr_fw_create_md_tbl(struct mlx5dr_domain *dmn,
1144                             struct mlx5dr_cmd_flow_destination_hw_info *dest,
1145                             int num_dest,
1146                             bool reformat_req,
1147                             u32 *tbl_id,
1148                             u32 *group_id);
1149 void mlx5dr_fw_destroy_md_tbl(struct mlx5dr_domain *dmn, u32 tbl_id,
1150                               u32 group_id);
1151 #endif  /* _DR_TYPES_H_ */