1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019, Mellanox Technologies */
3
4 #ifndef _MLX5DR_H_
5 #define _MLX5DR_H_
6
7 struct mlx5dr_domain;
8 struct mlx5dr_table;
9 struct mlx5dr_matcher;
10 struct mlx5dr_rule;
11 struct mlx5dr_action;
12
13 enum mlx5dr_domain_type {
14 MLX5DR_DOMAIN_TYPE_NIC_RX,
15 MLX5DR_DOMAIN_TYPE_NIC_TX,
16 MLX5DR_DOMAIN_TYPE_FDB,
17 };
18
19 enum mlx5dr_domain_sync_flags {
20 MLX5DR_DOMAIN_SYNC_FLAGS_SW = 1 << 0,
21 MLX5DR_DOMAIN_SYNC_FLAGS_HW = 1 << 1,
22 };
23
24 enum mlx5dr_action_reformat_type {
25 DR_ACTION_REFORMAT_TYP_TNL_L2_TO_L2,
26 DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L2,
27 DR_ACTION_REFORMAT_TYP_TNL_L3_TO_L2,
28 DR_ACTION_REFORMAT_TYP_L2_TO_TNL_L3,
29 };
30
31 struct mlx5dr_match_parameters {
32 size_t match_sz;
33 u64 *match_buf; /* Device spec format */
34 };
35
36 #ifdef CONFIG_MLX5_SW_STEERING
37
38 struct mlx5dr_domain *
39 mlx5dr_domain_create(struct mlx5_core_dev *mdev, enum mlx5dr_domain_type type);
40
41 int mlx5dr_domain_destroy(struct mlx5dr_domain *domain);
42
43 int mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags);
44
45 void mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn,
46 struct mlx5dr_domain *peer_dmn);
47
48 struct mlx5dr_table *
49 mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level);
50
51 int mlx5dr_table_destroy(struct mlx5dr_table *table);
52
53 u32 mlx5dr_table_get_id(struct mlx5dr_table *table);
54
55 struct mlx5dr_matcher *
56 mlx5dr_matcher_create(struct mlx5dr_table *table,
57 u16 priority,
58 u8 match_criteria_enable,
59 struct mlx5dr_match_parameters *mask);
60
61 int mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher);
62
63 struct mlx5dr_rule *
64 mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
65 struct mlx5dr_match_parameters *value,
66 size_t num_actions,
67 struct mlx5dr_action *actions[]);
68
69 int mlx5dr_rule_destroy(struct mlx5dr_rule *rule);
70
71 int mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
72 struct mlx5dr_action *action);
73
74 struct mlx5dr_action *
75 mlx5dr_action_create_dest_table(struct mlx5dr_table *table);
76
77 struct mlx5dr_action *
78 mlx5dr_create_action_dest_flow_fw_table(struct mlx5_flow_table *ft,
79 struct mlx5_core_dev *mdev);
80
81 struct mlx5dr_action *
82 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain,
83 u32 vport, u8 vhca_id_valid,
84 u16 vhca_id);
85
86 struct mlx5dr_action *mlx5dr_action_create_drop(void);
87
88 struct mlx5dr_action *mlx5dr_action_create_tag(u32 tag_value);
89
90 struct mlx5dr_action *
91 mlx5dr_action_create_flow_counter(u32 counter_id);
92
93 struct mlx5dr_action *
94 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn,
95 enum mlx5dr_action_reformat_type reformat_type,
96 size_t data_sz,
97 void *data);
98
99 struct mlx5dr_action *
100 mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain,
101 u32 flags,
102 size_t actions_sz,
103 __be64 actions[]);
104
105 struct mlx5dr_action *mlx5dr_action_create_pop_vlan(void);
106
107 struct mlx5dr_action *
108 mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain, __be32 vlan_hdr);
109
110 int mlx5dr_action_destroy(struct mlx5dr_action *action);
111
112 static inline bool
mlx5dr_is_supported(struct mlx5_core_dev * dev)113 mlx5dr_is_supported(struct mlx5_core_dev *dev)
114 {
115 return MLX5_CAP_ESW_FLOWTABLE_FDB(dev, sw_owner);
116 }
117
118 #else /* CONFIG_MLX5_SW_STEERING */
119
120 static inline struct mlx5dr_domain *
mlx5dr_domain_create(struct mlx5_core_dev * mdev,enum mlx5dr_domain_type type)121 mlx5dr_domain_create(struct mlx5_core_dev *mdev, enum mlx5dr_domain_type type) { return NULL; }
122
123 static inline int
mlx5dr_domain_destroy(struct mlx5dr_domain * domain)124 mlx5dr_domain_destroy(struct mlx5dr_domain *domain) { return 0; }
125
126 static inline int
mlx5dr_domain_sync(struct mlx5dr_domain * domain,u32 flags)127 mlx5dr_domain_sync(struct mlx5dr_domain *domain, u32 flags) { return 0; }
128
129 static inline void
mlx5dr_domain_set_peer(struct mlx5dr_domain * dmn,struct mlx5dr_domain * peer_dmn)130 mlx5dr_domain_set_peer(struct mlx5dr_domain *dmn,
131 struct mlx5dr_domain *peer_dmn) { }
132
133 static inline struct mlx5dr_table *
mlx5dr_table_create(struct mlx5dr_domain * domain,u32 level)134 mlx5dr_table_create(struct mlx5dr_domain *domain, u32 level) { return NULL; }
135
136 static inline int
mlx5dr_table_destroy(struct mlx5dr_table * table)137 mlx5dr_table_destroy(struct mlx5dr_table *table) { return 0; }
138
139 static inline u32
mlx5dr_table_get_id(struct mlx5dr_table * table)140 mlx5dr_table_get_id(struct mlx5dr_table *table) { return 0; }
141
142 static inline struct mlx5dr_matcher *
mlx5dr_matcher_create(struct mlx5dr_table * table,u16 priority,u8 match_criteria_enable,struct mlx5dr_match_parameters * mask)143 mlx5dr_matcher_create(struct mlx5dr_table *table,
144 u16 priority,
145 u8 match_criteria_enable,
146 struct mlx5dr_match_parameters *mask) { return NULL; }
147
148 static inline int
mlx5dr_matcher_destroy(struct mlx5dr_matcher * matcher)149 mlx5dr_matcher_destroy(struct mlx5dr_matcher *matcher) { return 0; }
150
151 static inline struct mlx5dr_rule *
mlx5dr_rule_create(struct mlx5dr_matcher * matcher,struct mlx5dr_match_parameters * value,size_t num_actions,struct mlx5dr_action * actions[])152 mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
153 struct mlx5dr_match_parameters *value,
154 size_t num_actions,
155 struct mlx5dr_action *actions[]) { return NULL; }
156
157 static inline int
mlx5dr_rule_destroy(struct mlx5dr_rule * rule)158 mlx5dr_rule_destroy(struct mlx5dr_rule *rule) { return 0; }
159
160 static inline int
mlx5dr_table_set_miss_action(struct mlx5dr_table * tbl,struct mlx5dr_action * action)161 mlx5dr_table_set_miss_action(struct mlx5dr_table *tbl,
162 struct mlx5dr_action *action) { return 0; }
163
164 static inline struct mlx5dr_action *
mlx5dr_action_create_dest_table(struct mlx5dr_table * table)165 mlx5dr_action_create_dest_table(struct mlx5dr_table *table) { return NULL; }
166
167 static inline struct mlx5dr_action *
mlx5dr_create_action_dest_flow_fw_table(struct mlx5_flow_table * ft,struct mlx5_core_dev * mdev)168 mlx5dr_create_action_dest_flow_fw_table(struct mlx5_flow_table *ft,
169 struct mlx5_core_dev *mdev) { return NULL; }
170
171 static inline struct mlx5dr_action *
mlx5dr_action_create_dest_vport(struct mlx5dr_domain * domain,u32 vport,u8 vhca_id_valid,u16 vhca_id)172 mlx5dr_action_create_dest_vport(struct mlx5dr_domain *domain,
173 u32 vport, u8 vhca_id_valid,
174 u16 vhca_id) { return NULL; }
175
176 static inline struct mlx5dr_action *
mlx5dr_action_create_drop(void)177 mlx5dr_action_create_drop(void) { return NULL; }
178
179 static inline struct mlx5dr_action *
mlx5dr_action_create_tag(u32 tag_value)180 mlx5dr_action_create_tag(u32 tag_value) { return NULL; }
181
182 static inline struct mlx5dr_action *
mlx5dr_action_create_flow_counter(u32 counter_id)183 mlx5dr_action_create_flow_counter(u32 counter_id) { return NULL; }
184
185 static inline struct mlx5dr_action *
mlx5dr_action_create_packet_reformat(struct mlx5dr_domain * dmn,enum mlx5dr_action_reformat_type reformat_type,size_t data_sz,void * data)186 mlx5dr_action_create_packet_reformat(struct mlx5dr_domain *dmn,
187 enum mlx5dr_action_reformat_type reformat_type,
188 size_t data_sz,
189 void *data) { return NULL; }
190
191 static inline struct mlx5dr_action *
mlx5dr_action_create_modify_header(struct mlx5dr_domain * domain,u32 flags,size_t actions_sz,__be64 actions[])192 mlx5dr_action_create_modify_header(struct mlx5dr_domain *domain,
193 u32 flags,
194 size_t actions_sz,
195 __be64 actions[]) { return NULL; }
196
197 static inline struct mlx5dr_action *
mlx5dr_action_create_pop_vlan(void)198 mlx5dr_action_create_pop_vlan(void) { return NULL; }
199
200 static inline struct mlx5dr_action *
mlx5dr_action_create_push_vlan(struct mlx5dr_domain * domain,__be32 vlan_hdr)201 mlx5dr_action_create_push_vlan(struct mlx5dr_domain *domain,
202 __be32 vlan_hdr) { return NULL; }
203
204 static inline int
mlx5dr_action_destroy(struct mlx5dr_action * action)205 mlx5dr_action_destroy(struct mlx5dr_action *action) { return 0; }
206
207 static inline bool
mlx5dr_is_supported(struct mlx5_core_dev * dev)208 mlx5dr_is_supported(struct mlx5_core_dev *dev) { return false; }
209
210 #endif /* CONFIG_MLX5_SW_STEERING */
211
212 #endif /* _MLX5DR_H_ */
213