Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates
3 : : */
4 : :
5 : : #ifndef MLX5DR_ACTION_H_
6 : : #define MLX5DR_ACTION_H_
7 : :
8 : : /* Max number of STEs needed for a rule (including match) */
9 : : #define MLX5DR_ACTION_MAX_STE 20
10 : :
11 : : /* Max number of internal subactions of ipv6_ext */
12 : : #define MLX5DR_ACTION_IPV6_EXT_MAX_SA 4
13 : :
14 : : enum mlx5dr_action_stc_idx {
15 : : MLX5DR_ACTION_STC_IDX_CTRL = 0,
16 : : MLX5DR_ACTION_STC_IDX_HIT = 1,
17 : : MLX5DR_ACTION_STC_IDX_DW5 = 2,
18 : : MLX5DR_ACTION_STC_IDX_DW6 = 3,
19 : : MLX5DR_ACTION_STC_IDX_DW7 = 4,
20 : : MLX5DR_ACTION_STC_IDX_MAX = 5,
21 : : /* STC Jumvo STE combo: CTR, Hit */
22 : : MLX5DR_ACTION_STC_IDX_LAST_JUMBO_STE = 1,
23 : : /* STC combo1: CTR, SINGLE, DOUBLE, Hit */
24 : : MLX5DR_ACTION_STC_IDX_LAST_COMBO1 = 3,
25 : : /* STC combo2: CTR, 3 x SINGLE, Hit */
26 : : MLX5DR_ACTION_STC_IDX_LAST_COMBO2 = 4,
27 : : };
28 : :
29 : : enum mlx5dr_action_offset {
30 : : MLX5DR_ACTION_OFFSET_DW0 = 0,
31 : : MLX5DR_ACTION_OFFSET_DW5 = 5,
32 : : MLX5DR_ACTION_OFFSET_DW6 = 6,
33 : : MLX5DR_ACTION_OFFSET_DW7 = 7,
34 : : MLX5DR_ACTION_OFFSET_HIT = 3,
35 : : MLX5DR_ACTION_OFFSET_HIT_LSB = 4,
36 : : };
37 : :
38 : : enum {
39 : : MLX5DR_ACTION_DOUBLE_SIZE = 8,
40 : : MLX5DR_ACTION_INLINE_DATA_SIZE = 4,
41 : : MLX5DR_ACTION_HDR_LEN_L2_MACS = 12,
42 : : MLX5DR_ACTION_HDR_LEN_L2_VLAN = 4,
43 : : MLX5DR_ACTION_HDR_LEN_L2_ETHER = 2,
44 : : MLX5DR_ACTION_HDR_LEN_L2 = (MLX5DR_ACTION_HDR_LEN_L2_MACS +
45 : : MLX5DR_ACTION_HDR_LEN_L2_ETHER),
46 : : MLX5DR_ACTION_HDR_LEN_L2_W_VLAN = (MLX5DR_ACTION_HDR_LEN_L2 +
47 : : MLX5DR_ACTION_HDR_LEN_L2_VLAN),
48 : : MLX5DR_ACTION_REFORMAT_DATA_SIZE = 64,
49 : : DECAP_L3_NUM_ACTIONS_W_NO_VLAN = 6,
50 : : DECAP_L3_NUM_ACTIONS_W_VLAN = 7,
51 : : };
52 : :
53 : : enum mlx5dr_action_setter_flag {
54 : : ASF_SINGLE1 = 1 << 0,
55 : : ASF_SINGLE2 = 1 << 1,
56 : : ASF_SINGLE3 = 1 << 2,
57 : : ASF_DOUBLE = ASF_SINGLE2 | ASF_SINGLE3,
58 : : ASF_INSERT = 1 << 3,
59 : : ASF_REMOVE = 1 << 4,
60 : : ASF_MODIFY = 1 << 5,
61 : : ASF_CTR = 1 << 6,
62 : : ASF_HIT = 1 << 7,
63 : : };
64 : :
65 : : enum mlx5dr_action_stc_reparse {
66 : : MLX5DR_ACTION_STC_REPARSE_DEFAULT,
67 : : MLX5DR_ACTION_STC_REPARSE_ON,
68 : : MLX5DR_ACTION_STC_REPARSE_OFF,
69 : : };
70 : :
71 : : struct mlx5dr_action_default_stc {
72 : : struct mlx5dr_pool_chunk nop_ctr;
73 : : struct mlx5dr_pool_chunk nop_dw5;
74 : : struct mlx5dr_pool_chunk nop_dw6;
75 : : struct mlx5dr_pool_chunk nop_dw7;
76 : : struct mlx5dr_pool_chunk default_hit;
77 : : uint32_t refcount;
78 : : };
79 : :
80 : : struct mlx5dr_action_shared_stc {
81 : : struct mlx5dr_pool_chunk remove_header;
82 : : uint32_t refcount;
83 : : };
84 : :
85 : : struct mlx5dr_actions_apply_data {
86 : : struct mlx5dr_send_engine *queue;
87 : : struct mlx5dr_rule_action *rule_action;
88 : : uint32_t *wqe_data;
89 : : struct mlx5dr_wqe_gta_ctrl_seg *wqe_ctrl;
90 : : uint32_t jump_to_action_stc;
91 : : struct mlx5dr_context_common_res *common_res;
92 : : enum mlx5dr_table_type tbl_type;
93 : : uint32_t next_direct_idx;
94 : : uint8_t require_dep;
95 : : };
96 : :
97 : : struct mlx5dr_actions_wqe_setter;
98 : :
99 : : typedef void (*mlx5dr_action_setter_fp)
100 : : (struct mlx5dr_actions_apply_data *apply,
101 : : struct mlx5dr_actions_wqe_setter *setter);
102 : :
103 : : struct mlx5dr_actions_wqe_setter {
104 : : mlx5dr_action_setter_fp set_single;
105 : : mlx5dr_action_setter_fp set_double;
106 : : mlx5dr_action_setter_fp set_hit;
107 : : mlx5dr_action_setter_fp set_ctr;
108 : : uint8_t idx_single;
109 : : uint8_t idx_double;
110 : : uint8_t idx_ctr;
111 : : uint8_t idx_hit;
112 : : uint8_t flags;
113 : : uint8_t extra_data;
114 : : };
115 : :
116 : : struct mlx5dr_action_template {
117 : : struct mlx5dr_actions_wqe_setter setters[MLX5DR_ACTION_MAX_STE];
118 : : enum mlx5dr_action_type *action_type_arr;
119 : : uint8_t num_of_action_stes;
120 : : uint8_t num_actions;
121 : : uint8_t only_term;
122 : : };
123 : :
124 : : struct mlx5dr_action {
125 : : uint8_t type;
126 : : uint8_t flags;
127 : : struct mlx5dr_context *ctx;
128 : : union {
129 : : struct {
130 : : struct mlx5dr_pool_chunk stc[MLX5DR_TABLE_TYPE_MAX];
131 : : union {
132 : : struct {
133 : : struct mlx5dr_devx_obj *pat_obj;
134 : : struct mlx5dr_devx_obj *arg_obj;
135 : : __be64 single_action;
136 : : uint8_t num_of_patterns;
137 : : uint8_t single_action_type;
138 : : uint8_t num_of_actions;
139 : : uint8_t max_num_of_actions;
140 : : uint8_t require_reparse;
141 : : } modify_header;
142 : : struct {
143 : : struct mlx5dr_devx_obj *arg_obj;
144 : : uint32_t header_size;
145 : : uint16_t max_hdr_sz;
146 : : uint8_t num_of_hdrs;
147 : : uint8_t anchor;
148 : : uint8_t offset;
149 : : bool encap;
150 : : uint8_t require_reparse;
151 : : } reformat;
152 : : struct {
153 : : struct mlx5dr_action
154 : : *action[MLX5DR_ACTION_IPV6_EXT_MAX_SA];
155 : : } ipv6_route_ext;
156 : : struct {
157 : : struct mlx5dr_devx_obj *devx_obj;
158 : : uint8_t return_reg_id;
159 : : } aso;
160 : : struct {
161 : : uint16_t vport_num;
162 : : uint16_t esw_owner_vhca_id;
163 : : } vport;
164 : : struct {
165 : : struct mlx5dr_devx_obj *devx_obj;
166 : : } alias;
167 : : struct {
168 : : struct mlx5dv_steering_anchor *sa;
169 : : } root_tbl;
170 : : struct {
171 : : struct mlx5dr_devx_obj *devx_obj;
172 : : } devx_dest;
173 : : struct {
174 : : struct mlx5dr_cmd_forward_tbl *fw_island;
175 : : size_t num_dest;
176 : : struct mlx5dr_cmd_set_fte_dest *dest_list;
177 : : } dest_array;
178 : : struct {
179 : : uint8_t type;
180 : : uint8_t start_anchor;
181 : : uint8_t end_anchor;
182 : : uint8_t num_of_words;
183 : : bool decap;
184 : : } remove_header;
185 : : };
186 : : };
187 : :
188 : : struct ibv_flow_action *flow_action;
189 : : struct mlx5dv_devx_obj *devx_obj;
190 : : struct ibv_qp *qp;
191 : : };
192 : : };
193 : :
194 : : int mlx5dr_action_root_build_attr(struct mlx5dr_rule_action rule_actions[],
195 : : uint32_t num_actions,
196 : : struct mlx5dv_flow_action_attr *attr);
197 : :
198 : : int mlx5dr_action_get_default_stc(struct mlx5dr_context *ctx,
199 : : uint8_t tbl_type);
200 : :
201 : : void mlx5dr_action_put_default_stc(struct mlx5dr_context *ctx,
202 : : uint8_t tbl_type);
203 : :
204 : : void mlx5dr_action_prepare_decap_l3_data(uint8_t *src, uint8_t *dst,
205 : : uint16_t num_of_actions);
206 : :
207 : : int mlx5dr_action_template_process(struct mlx5dr_action_template *at);
208 : :
209 : : bool mlx5dr_action_check_combo(enum mlx5dr_action_type *user_actions,
210 : : enum mlx5dr_table_type table_type);
211 : :
212 : : int mlx5dr_action_alloc_single_stc(struct mlx5dr_context *ctx,
213 : : struct mlx5dr_cmd_stc_modify_attr *stc_attr,
214 : : uint32_t table_type,
215 : : struct mlx5dr_pool_chunk *stc);
216 : :
217 : : void mlx5dr_action_free_single_stc(struct mlx5dr_context *ctx,
218 : : uint32_t table_type,
219 : : struct mlx5dr_pool_chunk *stc);
220 : :
221 : : static inline void
222 : : mlx5dr_action_setter_default_single(struct mlx5dr_actions_apply_data *apply,
223 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
224 : : {
225 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
226 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] =
227 : 0 : htobe32(apply->common_res->default_stc->nop_dw5.offset);
228 : 0 : }
229 : :
230 : : static inline void
231 : : mlx5dr_action_setter_default_double(struct mlx5dr_actions_apply_data *apply,
232 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
233 : : {
234 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
235 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
236 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] =
237 : 0 : htobe32(apply->common_res->default_stc->nop_dw6.offset);
238 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] =
239 : 0 : htobe32(apply->common_res->default_stc->nop_dw7.offset);
240 : 0 : }
241 : :
242 : : static inline void
243 : : mlx5dr_action_setter_default_ctr(struct mlx5dr_actions_apply_data *apply,
244 : : __rte_unused struct mlx5dr_actions_wqe_setter *setter)
245 : : {
246 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW0] = 0;
247 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_CTRL] =
248 : 0 : htobe32(apply->common_res->default_stc->nop_ctr.offset);
249 : 0 : }
250 : :
251 : : static inline void
252 : 0 : mlx5dr_action_apply_setter(struct mlx5dr_actions_apply_data *apply,
253 : : struct mlx5dr_actions_wqe_setter *setter,
254 : : bool is_jumbo)
255 : : {
256 : : uint8_t num_of_actions;
257 : :
258 : : /* Set control counter */
259 [ # # ]: 0 : if (setter->flags & ASF_CTR)
260 : 0 : setter->set_ctr(apply, setter);
261 : : else
262 : : mlx5dr_action_setter_default_ctr(apply, setter);
263 : :
264 : : /* Set single and double on match */
265 [ # # ]: 0 : if (!is_jumbo) {
266 [ # # ]: 0 : if (setter->flags & ASF_SINGLE1)
267 : 0 : setter->set_single(apply, setter);
268 : : else
269 : : mlx5dr_action_setter_default_single(apply, setter);
270 : :
271 [ # # ]: 0 : if (setter->flags & ASF_DOUBLE)
272 : 0 : setter->set_double(apply, setter);
273 : : else
274 : : mlx5dr_action_setter_default_double(apply, setter);
275 : :
276 [ # # ]: 0 : num_of_actions = setter->flags & ASF_DOUBLE ?
277 : : MLX5DR_ACTION_STC_IDX_LAST_COMBO1 :
278 : : MLX5DR_ACTION_STC_IDX_LAST_COMBO2;
279 : : } else {
280 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW5] = 0;
281 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW6] = 0;
282 : 0 : apply->wqe_data[MLX5DR_ACTION_OFFSET_DW7] = 0;
283 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW5] = 0;
284 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW6] = 0;
285 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_DW7] = 0;
286 : : num_of_actions = MLX5DR_ACTION_STC_IDX_LAST_JUMBO_STE;
287 : : }
288 : :
289 : : /* Set next/final hit action */
290 : 0 : setter->set_hit(apply, setter);
291 : :
292 : : /* Set number of actions */
293 : 0 : apply->wqe_ctrl->stc_ix[MLX5DR_ACTION_STC_IDX_CTRL] |=
294 : 0 : htobe32(num_of_actions << 29);
295 : 0 : }
296 : :
297 : : #endif /* MLX5DR_ACTION_H_ */
|