DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2020 Mellanox Technologies, Ltd
 */

#ifndef RTE_PMD_MLX5_FLOW_OS_H_
#define RTE_PMD_MLX5_FLOW_OS_H_

#include "mlx5_flow.h"

#ifdef HAVE_IBV_FLOW_DV_SUPPORT
extern const struct mlx5_flow_driver_ops mlx5_flow_dv_drv_ops;
#endif

/**
 * Get OS enforced flow type. MLX5_FLOW_TYPE_MAX means "non enforced type".
 *
 * @return
 *   Flow type (MLX5_FLOW_TYPE_MAX)
 */
static inline enum mlx5_flow_drv_type
mlx5_flow_os_get_type(void)
{
	return MLX5_FLOW_TYPE_MAX;
}

/**
 * Check if item type is supported.
 *
 * @param item
 *   Item type to check.
 *
 * @return
 *   True is this item type is supported, false if not supported.
 */
static inline bool
mlx5_flow_os_item_supported(int item __rte_unused)
{
	return true;
}

/**
 * Check if action type is supported.
 *
 * @param action
 *   Action type to check.
 *
 * @return
 *   True is this action type is supported, false if not supported.
 */
static inline bool
mlx5_flow_os_action_supported(int action __rte_unused)
{
	return true;
}

/**
 * Create flow rule.
 *
 * @param[in] matcher
 *   Pointer to match mask structure.
 * @param[in] match_value
 *   Pointer to match value structure.
 * @param[in] num_actions
 *   Number of actions in flow rule.
 * @param[in] actions
 *   Pointer to array of flow rule actions.
 * @param[out] flow
 *   Pointer to a valid flow rule object on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow(void *matcher, void *match_value,
			 size_t num_actions, void *actions[], void **flow)
{
	*flow = mlx5_glue->dv_create_flow(matcher, match_value,
					  num_actions, actions);
	return (*flow) ? 0 : -1;
}

/**
 * Destroy flow rule.
 *
 * @param[in] drv_flow_ptr
 *   Pointer to flow rule object.
 *
 * @return
 *   0 on success, or the value of errno on failure.
 */
static inline int
mlx5_flow_os_destroy_flow(void *drv_flow_ptr)
{
	return mlx5_glue->dv_destroy_flow(drv_flow_ptr);
}

/**
 * Create flow table.
 *
 * @param[in] domain
 *   Pointer to relevant domain.
 * @param[in] table_id
 *   Table ID.
 * @param[out] table
 *   Pointer to a valid flow table object on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_tbl(void *domain, uint32_t table_id, void **table)
{
	*table = mlx5_glue->dr_create_flow_tbl(domain, table_id);
	return (*table) ? 0 : -1;
}

/**
 * Destroy flow table.
 *
 * @param[in] table
 *   Pointer to table object to destroy.
 *
 * @return
 *   0 on success, or the value of errno on failure.
 */
static inline int
mlx5_flow_os_destroy_flow_tbl(void *table)
{
	return mlx5_glue->dr_destroy_flow_tbl(table);
}

/**
 * Create flow matcher in a flow table.
 *
 * @param[in] ctx
 *   Pointer to relevant device context.
 * @param[in] attr
 *   Pointer to relevant attributes.
 * @param[in] table
 *   Pointer to table object.
 * @param[out] matcher
 *   Pointer to a valid flow matcher object on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_matcher(void *ctx, void *attr, void *table,
				 void **matcher)
{
	*matcher = mlx5_glue->dv_create_flow_matcher(ctx, attr, table);
	return (*matcher) ? 0 : -1;
}

/**
 * Destroy flow matcher.
 *
 * @param[in] matcher
 *   Pointer to matcher object to destroy.
 *
 * @return
 *   0 on success, or the value of errno on failure.
 */
static inline int
mlx5_flow_os_destroy_flow_matcher(void *matcher)
{
	return mlx5_glue->dv_destroy_flow_matcher(matcher);
}

/**
 * Create flow action: packet reformat.
 *
 * @param[in] ctx
 *   Pointer to relevant device context.
 * @param[in] domain
 *   Pointer to domain handler.
 * @param[in] resource
 *   Pointer to action data resource.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_packet_reformat(void *ctx, void *domain,
						void *resource, void **action)
{
	struct mlx5_flow_dv_encap_decap_resource *res =
			(struct mlx5_flow_dv_encap_decap_resource *)resource;

	*action = mlx5_glue->dv_create_flow_action_packet_reformat
					(ctx, res->reformat_type, res->ft_type,
					 domain, res->flags, res->size,
					 (res->size ? res->buf : NULL));
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: modify header.
 *
 * @param[in] ctx
 *   Pointer to relevant device context.
 * @param[in] domain
 *   Pointer to domain handler.
 * @param[in] resource
 *   Pointer to action data resource.
 * @param[in] actions_len
 *   Total length of actions data in resource.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_modify_header(void *ctx, void *domain,
					      void *resource,
					      uint32_t actions_len,
					      void **action)
{
	struct mlx5_flow_dv_modify_hdr_resource *res =
			(struct mlx5_flow_dv_modify_hdr_resource *)resource;

	*action = mlx5_glue->dv_create_flow_action_modify_header
					(ctx, res->ft_type, domain, res->flags,
					 actions_len, (uint64_t *)res->actions);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: destination flow table.
 *
 * @param[in] tbl_obj
 *   Pointer to destination table object.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_dest_flow_tbl(void *tbl_obj, void **action)
{
	*action = mlx5_glue->dr_create_flow_action_dest_flow_tbl(tbl_obj);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: destination port.
 *
 * @param[in] domain
 *   Pointer to domain handler.
 * @param[in] port_id
 *   Destination port ID.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_dest_port(void *domain, uint32_t port_id,
					  void **action)
{
	/*
	 * Depending on rdma_core version the glue routine calls
	 * either mlx5dv_dr_action_create_dest_ib_port(domain, dev_port)
	 * or mlx5dv_dr_action_create_dest_vport(domain, vport_id).
	 */
	*action = mlx5_glue->dr_create_flow_action_dest_port(domain, port_id);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: push vlan.
 *
 * @param[in] domain
 *   Pointer to domain handler.
 * @param[in] vlan_tag
 *   VLAN tag value.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_push_vlan(void *domain, rte_be32_t vlan_tag,
					  void **action)
{
	*action = mlx5_glue->dr_create_flow_action_push_vlan(domain, vlan_tag);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: count.
 *
 * @param[in] cnt_obj
 *   Pointer to DevX counter object.
 * @param[in] offset
 *   Offset of counter in array.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_count(void *cnt_obj, uint16_t offset,
				      void **action)
{
	*action = mlx5_glue->dv_create_flow_action_counter(cnt_obj, offset);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: tag.
 *
 * @param[in] tag
 *   Tag value.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_tag(uint32_t tag, void **action)
{
	*action = mlx5_glue->dv_create_flow_action_tag(tag);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: drop.
 *
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_drop(void **action)
{
	*action = mlx5_glue->dr_create_flow_action_drop();
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: default miss.
 *
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_default_miss(void **action)
{
	*action = mlx5_glue->dr_create_flow_action_default_miss();
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: dest_devx_tir
 *
 * @param[in] tir
 *   Pointer to DevX tir object
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_flow_os_create_flow_action_dest_devx_tir(struct mlx5_devx_obj *tir,
					      void **action)
{
#ifdef HAVE_IBV_FLOW_DV_SUPPORT
	*action = mlx5_glue->dv_create_flow_action_dest_devx_tir(tir->obj);
	return (*action) ? 0 : -1;
#else
	/* If no DV support - skip the operation and return success */
	RTE_SET_USED(tir);
	*action = 0;
	return 0;
#endif
}

/**
 * Create flow action: sampler
 *
 * @param[in] attr
 *   Pointer to sampler attribute
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_os_flow_dr_create_flow_action_sampler
			(struct mlx5dv_dr_flow_sampler_attr *attr,
			void **action)
{
	*action = mlx5_glue->dr_create_flow_action_sampler(attr);
	return (*action) ? 0 : -1;
}

/**
 * Create flow action: dest_array
 *
 * @param[in] domain
 *   Pointer to relevant domain.
 * @param[in] num_dest
 *   Number of destinations array.
 * @param[in] dests
 *   Array of destination attributes.
 * @param[out] action
 *   Pointer to a valid action on success, NULL otherwise.
 *
 * @return
 *   0 on success, or -1 on failure and errno is set.
 */
static inline int
mlx5_os_flow_dr_create_flow_action_dest_array
			(void *domain,
			 size_t num_dest,
			 struct mlx5dv_dr_action_dest_attr *dests[],
			 void **action)
{
	*action = mlx5_glue->dr_create_flow_action_dest_array(
						domain, num_dest, dests);
	return (*action) ? 0 : -1;
}

/**
 * Destroy flow action.
 *
 * @param[in] action
 *   Pointer to action object to destroy.
 *
 * @return
 *   0 on success, or the value of errno on failure.
 */
static inline int
mlx5_flow_os_destroy_flow_action(void *action)
{
	return mlx5_glue->destroy_flow_action(action);
}

/**
 * OS wrapper over Verbs API.
 * Adjust flow priority based on the highest layer and the request priority.
 *
 * @param[in] dev
 *    Pointer to the Ethernet device structure.
 * @param[in] priority
 *    The rule base priority.
 * @param[in] subpriority
 *    The priority based on the items.
 *
 * @return
 *    The new priority.
 */
static inline uint32_t
mlx5_os_flow_adjust_priority(struct rte_eth_dev *dev, int32_t priority,
			  uint32_t subpriority)
{
	return mlx5_flow_adjust_priority(dev, priority, subpriority);
}

static inline int
mlx5_os_flow_dr_sync_domain(void *domain, uint32_t flags)
{
	return mlx5_glue->dr_sync_domain(domain, flags);
}
#endif /* RTE_PMD_MLX5_FLOW_OS_H_ */