Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2015 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stddef.h>
7 : : #include <unistd.h>
8 : : #include <string.h>
9 : : #include <stdint.h>
10 : : #include <stdlib.h>
11 : : #include <errno.h>
12 : : #include <fcntl.h>
13 : :
14 : : #include <eal_export.h>
15 : : #include <rte_malloc.h>
16 : : #include <ethdev_driver.h>
17 : : #include <rte_pci.h>
18 : : #include <bus_pci_driver.h>
19 : : #include <rte_common.h>
20 : : #include <rte_kvargs.h>
21 : : #include <rte_rwlock.h>
22 : : #include <rte_spinlock.h>
23 : : #include <rte_string_fns.h>
24 : : #include <rte_eal_paging.h>
25 : : #include <rte_alarm.h>
26 : : #include <rte_cycles.h>
27 : : #include <rte_interrupts.h>
28 : :
29 : : #include <mlx5_glue.h>
30 : : #include <mlx5_devx_cmds.h>
31 : : #include <mlx5_common.h>
32 : : #include <mlx5_common_os.h>
33 : : #include <mlx5_common_mp.h>
34 : : #include <mlx5_malloc.h>
35 : :
36 : : #include "mlx5_defs.h"
37 : : #include "mlx5.h"
38 : : #include "mlx5_utils.h"
39 : : #include "mlx5_rxtx.h"
40 : : #include "mlx5_rx.h"
41 : : #include "mlx5_tx.h"
42 : : #include "mlx5_autoconf.h"
43 : : #include "mlx5_flow.h"
44 : : #include "mlx5_flow_os.h"
45 : : #include "rte_pmd_mlx5.h"
46 : :
47 : : #define MLX5_ETH_DRIVER_NAME mlx5_eth
48 : :
49 : : /* Device parameter to enable RX completion queue compression. */
50 : : #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
51 : :
52 : : /* Device parameter to enable padding Rx packet to cacheline size. */
53 : : #define MLX5_RXQ_PKT_PAD_EN "rxq_pkt_pad_en"
54 : :
55 : : /* Device parameter to enable Multi-Packet Rx queue. */
56 : : #define MLX5_RX_MPRQ_EN "mprq_en"
57 : :
58 : : /* Device parameter to configure log 2 of the number of strides for MPRQ. */
59 : : #define MLX5_RX_MPRQ_LOG_STRIDE_NUM "mprq_log_stride_num"
60 : :
61 : : /* Device parameter to configure log 2 of the stride size for MPRQ. */
62 : : #define MLX5_RX_MPRQ_LOG_STRIDE_SIZE "mprq_log_stride_size"
63 : :
64 : : /* Device parameter to limit the size of memcpy'd packet for MPRQ. */
65 : : #define MLX5_RX_MPRQ_MAX_MEMCPY_LEN "mprq_max_memcpy_len"
66 : :
67 : : /* Device parameter to set the minimum number of Rx queues to enable MPRQ. */
68 : : #define MLX5_RXQS_MIN_MPRQ "rxqs_min_mprq"
69 : :
70 : : /* Device parameter to configure inline send. Deprecated, ignored.*/
71 : : #define MLX5_TXQ_INLINE "txq_inline"
72 : :
73 : : /* Device parameter to limit packet size to inline with ordinary SEND. */
74 : : #define MLX5_TXQ_INLINE_MAX "txq_inline_max"
75 : :
76 : : /* Device parameter to configure minimal data size to inline. */
77 : : #define MLX5_TXQ_INLINE_MIN "txq_inline_min"
78 : :
79 : : /* Device parameter to limit packet size to inline with Enhanced MPW. */
80 : : #define MLX5_TXQ_INLINE_MPW "txq_inline_mpw"
81 : :
82 : : /*
83 : : * Device parameter to configure the number of TX queues threshold for
84 : : * enabling inline send.
85 : : */
86 : : #define MLX5_TXQS_MIN_INLINE "txqs_min_inline"
87 : :
88 : : /*
89 : : * Device parameter to configure the number of TX queues threshold for
90 : : * enabling vectorized Tx, deprecated, ignored (no vectorized Tx routines).
91 : : */
92 : : #define MLX5_TXQS_MAX_VEC "txqs_max_vec"
93 : :
94 : : /* Device parameter to enable multi-packet send WQEs. */
95 : : #define MLX5_TXQ_MPW_EN "txq_mpw_en"
96 : :
97 : : /*
98 : : * Device parameter to include 2 dsegs in the title WQEBB.
99 : : * Deprecated, ignored.
100 : : */
101 : : #define MLX5_TXQ_MPW_HDR_DSEG_EN "txq_mpw_hdr_dseg_en"
102 : :
103 : : /*
104 : : * Device parameter to limit the size of inlining packet.
105 : : * Deprecated, ignored.
106 : : */
107 : : #define MLX5_TXQ_MAX_INLINE_LEN "txq_max_inline_len"
108 : :
109 : : /*
110 : : * Device parameter to enable Tx scheduling on timestamps
111 : : * and specify the packet pacing granularity in nanoseconds.
112 : : */
113 : : #define MLX5_TX_PP "tx_pp"
114 : :
115 : : /*
116 : : * Device parameter to specify skew in nanoseconds on Tx datapath,
117 : : * it represents the time between SQ start WQE processing and
118 : : * appearing actual packet data on the wire.
119 : : */
120 : : #define MLX5_TX_SKEW "tx_skew"
121 : :
122 : : /*
123 : : * Device parameter to enable hardware Tx vector.
124 : : * Deprecated, ignored (no vectorized Tx routines anymore).
125 : : */
126 : : #define MLX5_TX_VEC_EN "tx_vec_en"
127 : :
128 : : /* Device parameter to enable hardware Rx vector. */
129 : : #define MLX5_RX_VEC_EN "rx_vec_en"
130 : :
131 : : /* Allow L3 VXLAN flow creation. */
132 : : #define MLX5_L3_VXLAN_EN "l3_vxlan_en"
133 : :
134 : : /* Activate DV E-Switch flow steering. */
135 : : #define MLX5_DV_ESW_EN "dv_esw_en"
136 : :
137 : : /* Activate DV flow steering. */
138 : : #define MLX5_DV_FLOW_EN "dv_flow_en"
139 : :
140 : : /* Enable extensive flow metadata support. */
141 : : #define MLX5_DV_XMETA_EN "dv_xmeta_en"
142 : :
143 : : /* Device parameter to let the user manage the lacp traffic of bonding device */
144 : : #define MLX5_LACP_BY_USER "lacp_by_user"
145 : :
146 : : /* Activate Netlink support in VF mode. */
147 : : #define MLX5_VF_NL_EN "vf_nl_en"
148 : :
149 : : /* Select port representors to instantiate. */
150 : : #define MLX5_REPRESENTOR "representor"
151 : :
152 : : /* Device parameter to configure the maximum number of dump files per queue. */
153 : : #define MLX5_MAX_DUMP_FILES_NUM "max_dump_files_num"
154 : :
155 : : /* Configure timeout of LRO session (in microseconds). */
156 : : #define MLX5_LRO_TIMEOUT_USEC "lro_timeout_usec"
157 : :
158 : : /*
159 : : * Device parameter to configure the total data buffer size for a single
160 : : * hairpin queue (logarithm value).
161 : : */
162 : : #define MLX5_HP_BUF_SIZE "hp_buf_log_sz"
163 : :
164 : : /* Flow memory reclaim mode. */
165 : : #define MLX5_RECLAIM_MEM "reclaim_mem_mode"
166 : :
167 : : /* Decap will be used or not. */
168 : : #define MLX5_DECAP_EN "decap_en"
169 : :
170 : : /* Device parameter to configure allow or prevent duplicate rules pattern. */
171 : : #define MLX5_ALLOW_DUPLICATE_PATTERN "allow_duplicate_pattern"
172 : :
173 : : /* Device parameter to configure the delay drop when creating Rxqs. */
174 : : #define MLX5_DELAY_DROP "delay_drop"
175 : :
176 : : /* Device parameter to create the fdb default rule in PMD */
177 : : #define MLX5_FDB_DEFAULT_RULE_EN "fdb_def_rule_en"
178 : :
179 : : /* HW steering counter configuration. */
180 : : #define MLX5_HWS_CNT_SERVICE_CORE "service_core"
181 : :
182 : : /* HW steering counter's query interval. */
183 : : #define MLX5_HWS_CNT_CYCLE_TIME "svc_cycle_time"
184 : :
185 : : /*
186 : : * Alignment of the Tx queue starting address,
187 : : * If not set, using separate umem and MR for each TxQ.
188 : : * If set, using consecutive memory address and single MR for all Tx queues,
189 : : * each TxQ will start at the alignment specified.
190 : : */
191 : : #define MLX5_TXQ_MEM_ALGN "txq_mem_algn"
192 : :
193 : : /* Shared memory between primary and secondary processes. */
194 : : struct mlx5_shared_data *mlx5_shared_data;
195 : :
196 : : /** Driver-specific log messages type. */
197 : : int mlx5_logtype;
198 : :
199 : : static LIST_HEAD(mlx5_dev_ctx_list, mlx5_dev_ctx_shared) dev_ctx_list = LIST_HEAD_INITIALIZER();
200 : : static LIST_HEAD(mlx5_phdev_list, mlx5_physical_device) phdev_list = LIST_HEAD_INITIALIZER();
201 : : static pthread_mutex_t mlx5_dev_ctx_list_mutex;
202 : :
203 : : static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
204 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
205 : : [MLX5_IPOOL_DECAP_ENCAP] = {
206 : : .size = sizeof(struct mlx5_flow_dv_encap_decap_resource),
207 : : .trunk_size = 64,
208 : : .grow_trunk = 3,
209 : : .grow_shift = 2,
210 : : .need_lock = 1,
211 : : .release_mem_en = 1,
212 : : .malloc = mlx5_malloc,
213 : : .free = mlx5_free,
214 : : .type = "mlx5_encap_decap_ipool",
215 : : },
216 : : [MLX5_IPOOL_PUSH_VLAN] = {
217 : : .size = sizeof(struct mlx5_flow_dv_push_vlan_action_resource),
218 : : .trunk_size = 64,
219 : : .grow_trunk = 3,
220 : : .grow_shift = 2,
221 : : .need_lock = 1,
222 : : .release_mem_en = 1,
223 : : .malloc = mlx5_malloc,
224 : : .free = mlx5_free,
225 : : .type = "mlx5_push_vlan_ipool",
226 : : },
227 : : [MLX5_IPOOL_TAG] = {
228 : : .size = sizeof(struct mlx5_flow_dv_tag_resource),
229 : : .trunk_size = 64,
230 : : .grow_trunk = 3,
231 : : .grow_shift = 2,
232 : : .need_lock = 1,
233 : : .release_mem_en = 0,
234 : : .per_core_cache = (1 << 16),
235 : : .malloc = mlx5_malloc,
236 : : .free = mlx5_free,
237 : : .type = "mlx5_tag_ipool",
238 : : },
239 : : [MLX5_IPOOL_PORT_ID] = {
240 : : .size = sizeof(struct mlx5_flow_dv_port_id_action_resource),
241 : : .trunk_size = 64,
242 : : .grow_trunk = 3,
243 : : .grow_shift = 2,
244 : : .need_lock = 1,
245 : : .release_mem_en = 1,
246 : : .malloc = mlx5_malloc,
247 : : .free = mlx5_free,
248 : : .type = "mlx5_port_id_ipool",
249 : : },
250 : : [MLX5_IPOOL_JUMP] = {
251 : : /*
252 : : * MLX5_IPOOL_JUMP ipool entry size depends on selected flow engine.
253 : : * When HW steering is enabled mlx5_flow_group struct is used.
254 : : * Otherwise mlx5_flow_tbl_data_entry struct is used.
255 : : */
256 : : .size = 0,
257 : : .trunk_size = 64,
258 : : .grow_trunk = 3,
259 : : .grow_shift = 2,
260 : : .need_lock = 1,
261 : : .release_mem_en = 1,
262 : : .malloc = mlx5_malloc,
263 : : .free = mlx5_free,
264 : : .type = "mlx5_jump_ipool",
265 : : },
266 : : [MLX5_IPOOL_SAMPLE] = {
267 : : .size = sizeof(struct mlx5_flow_dv_sample_resource),
268 : : .trunk_size = 64,
269 : : .grow_trunk = 3,
270 : : .grow_shift = 2,
271 : : .need_lock = 1,
272 : : .release_mem_en = 1,
273 : : .malloc = mlx5_malloc,
274 : : .free = mlx5_free,
275 : : .type = "mlx5_sample_ipool",
276 : : },
277 : : [MLX5_IPOOL_DEST_ARRAY] = {
278 : : .size = sizeof(struct mlx5_flow_dv_dest_array_resource),
279 : : .trunk_size = 64,
280 : : .grow_trunk = 3,
281 : : .grow_shift = 2,
282 : : .need_lock = 1,
283 : : .release_mem_en = 1,
284 : : .malloc = mlx5_malloc,
285 : : .free = mlx5_free,
286 : : .type = "mlx5_dest_array_ipool",
287 : : },
288 : : [MLX5_IPOOL_TUNNEL_ID] = {
289 : : .size = sizeof(struct mlx5_flow_tunnel),
290 : : .trunk_size = MLX5_MAX_TUNNELS,
291 : : .need_lock = 1,
292 : : .release_mem_en = 1,
293 : : .type = "mlx5_tunnel_offload",
294 : : },
295 : : [MLX5_IPOOL_TNL_TBL_ID] = {
296 : : .size = 0,
297 : : .need_lock = 1,
298 : : .type = "mlx5_flow_tnl_tbl_ipool",
299 : : },
300 : : #endif
301 : : [MLX5_IPOOL_MTR] = {
302 : : /**
303 : : * The ipool index should grow continually from small to big,
304 : : * for meter idx, so not set grow_trunk to avoid meter index
305 : : * not jump continually.
306 : : */
307 : : .size = sizeof(struct mlx5_legacy_flow_meter),
308 : : .trunk_size = 64,
309 : : .need_lock = 1,
310 : : .release_mem_en = 1,
311 : : .malloc = mlx5_malloc,
312 : : .free = mlx5_free,
313 : : .type = "mlx5_meter_ipool",
314 : : },
315 : : [MLX5_IPOOL_MCP] = {
316 : : .size = sizeof(struct mlx5_flow_mreg_copy_resource),
317 : : .trunk_size = 64,
318 : : .grow_trunk = 3,
319 : : .grow_shift = 2,
320 : : .need_lock = 1,
321 : : .release_mem_en = 1,
322 : : .malloc = mlx5_malloc,
323 : : .free = mlx5_free,
324 : : .type = "mlx5_mcp_ipool",
325 : : },
326 : : [MLX5_IPOOL_HRXQ] = {
327 : : .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
328 : : .trunk_size = 64,
329 : : .grow_trunk = 3,
330 : : .grow_shift = 2,
331 : : .need_lock = 1,
332 : : .release_mem_en = 1,
333 : : .malloc = mlx5_malloc,
334 : : .free = mlx5_free,
335 : : .type = "mlx5_hrxq_ipool",
336 : : },
337 : : [MLX5_IPOOL_MLX5_FLOW] = {
338 : : /*
339 : : * MLX5_IPOOL_MLX5_FLOW size varies for DV and VERBS flows.
340 : : * It set in run time according to PCI function configuration.
341 : : */
342 : : .size = 0,
343 : : .trunk_size = 64,
344 : : .grow_trunk = 3,
345 : : .grow_shift = 2,
346 : : .need_lock = 1,
347 : : .release_mem_en = 0,
348 : : .per_core_cache = 1 << 19,
349 : : .malloc = mlx5_malloc,
350 : : .free = mlx5_free,
351 : : .type = "mlx5_flow_handle_ipool",
352 : : },
353 : : [MLX5_IPOOL_RTE_FLOW] = {
354 : : .size = sizeof(struct rte_flow),
355 : : .trunk_size = 4096,
356 : : .need_lock = 1,
357 : : .release_mem_en = 1,
358 : : .malloc = mlx5_malloc,
359 : : .free = mlx5_free,
360 : : .type = "rte_flow_ipool",
361 : : },
362 : : [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID] = {
363 : : .size = 0,
364 : : .need_lock = 1,
365 : : .type = "mlx5_flow_rss_id_ipool",
366 : : },
367 : : [MLX5_IPOOL_RSS_SHARED_ACTIONS] = {
368 : : .size = sizeof(struct mlx5_shared_action_rss),
369 : : .trunk_size = 64,
370 : : .grow_trunk = 3,
371 : : .grow_shift = 2,
372 : : .need_lock = 1,
373 : : .release_mem_en = 1,
374 : : .malloc = mlx5_malloc,
375 : : .free = mlx5_free,
376 : : .type = "mlx5_shared_action_rss",
377 : : },
378 : : [MLX5_IPOOL_MTR_POLICY] = {
379 : : /**
380 : : * The ipool index should grow continually from small to big,
381 : : * for policy idx, so not set grow_trunk to avoid policy index
382 : : * not jump continually.
383 : : */
384 : : .size = sizeof(struct mlx5_flow_meter_sub_policy),
385 : : .trunk_size = 64,
386 : : .need_lock = 1,
387 : : .release_mem_en = 1,
388 : : .malloc = mlx5_malloc,
389 : : .free = mlx5_free,
390 : : .type = "mlx5_meter_policy_ipool",
391 : : },
392 : : };
393 : :
394 : : #define MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE 1024
395 : :
396 : : #define MLX5_RXQ_ENH_CQE_COMP_MASK 0x80
397 : :
398 : : /**
399 : : * Decide whether representor ID is a HPF(host PF) port on BF2.
400 : : *
401 : : * @param dev
402 : : * Pointer to Ethernet device structure.
403 : : *
404 : : * @return
405 : : * Non-zero if HPF, otherwise 0.
406 : : */
407 : : bool
408 : 0 : mlx5_is_hpf(struct rte_eth_dev *dev)
409 : : {
410 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
411 : 0 : uint16_t repr = MLX5_REPRESENTOR_REPR(priv->representor_id);
412 : 0 : int type = MLX5_REPRESENTOR_TYPE(priv->representor_id);
413 : :
414 [ # # ]: 0 : return priv->representor != 0 && type == RTE_ETH_REPRESENTOR_VF &&
415 [ # # ]: 0 : MLX5_REPRESENTOR_REPR(-1) == repr;
416 : : }
417 : :
418 : : /**
419 : : * Decide whether representor ID is a SF port representor.
420 : : *
421 : : * @param dev
422 : : * Pointer to Ethernet device structure.
423 : : *
424 : : * @return
425 : : * Non-zero if HPF, otherwise 0.
426 : : */
427 : : bool
428 : 0 : mlx5_is_sf_repr(struct rte_eth_dev *dev)
429 : : {
430 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
431 : 0 : int type = MLX5_REPRESENTOR_TYPE(priv->representor_id);
432 : :
433 [ # # # # ]: 0 : return priv->representor != 0 && type == RTE_ETH_REPRESENTOR_SF;
434 : : }
435 : :
436 : : /**
437 : : * Initialize the ASO aging management structure.
438 : : *
439 : : * @param[in] sh
440 : : * Pointer to mlx5_dev_ctx_shared object to free
441 : : *
442 : : * @return
443 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
444 : : */
445 : : int
446 : 0 : mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh)
447 : : {
448 : : int err;
449 : :
450 [ # # ]: 0 : if (sh->aso_age_mng)
451 : : return 0;
452 : 0 : sh->aso_age_mng = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sh->aso_age_mng),
453 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
454 [ # # ]: 0 : if (!sh->aso_age_mng) {
455 : 0 : DRV_LOG(ERR, "aso_age_mng allocation was failed.");
456 : 0 : rte_errno = ENOMEM;
457 : 0 : return -ENOMEM;
458 : : }
459 : 0 : err = mlx5_aso_queue_init(sh, ASO_OPC_MOD_FLOW_HIT, 1);
460 [ # # ]: 0 : if (err) {
461 : 0 : mlx5_free(sh->aso_age_mng);
462 : 0 : sh->aso_age_mng = NULL;
463 : 0 : return -1;
464 : : }
465 : 0 : rte_rwlock_init(&sh->aso_age_mng->resize_rwl);
466 : : rte_spinlock_init(&sh->aso_age_mng->free_sl);
467 : 0 : LIST_INIT(&sh->aso_age_mng->free);
468 : 0 : return 0;
469 : : }
470 : :
471 : : /**
472 : : * Close and release all the resources of the ASO aging management structure.
473 : : *
474 : : * @param[in] sh
475 : : * Pointer to mlx5_dev_ctx_shared object to free.
476 : : */
477 : : static void
478 : 0 : mlx5_flow_aso_age_mng_close(struct mlx5_dev_ctx_shared *sh)
479 : : {
480 : : int i, j;
481 : :
482 : 0 : mlx5_aso_flow_hit_queue_poll_stop(sh);
483 : 0 : mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_FLOW_HIT);
484 [ # # ]: 0 : if (sh->aso_age_mng->pools) {
485 : : struct mlx5_aso_age_pool *pool;
486 : :
487 [ # # ]: 0 : for (i = 0; i < sh->aso_age_mng->next; ++i) {
488 : 0 : pool = sh->aso_age_mng->pools[i];
489 : 0 : claim_zero(mlx5_devx_cmd_destroy
490 : : (pool->flow_hit_aso_obj));
491 [ # # ]: 0 : for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j)
492 [ # # ]: 0 : if (pool->actions[j].dr_action)
493 : : claim_zero
494 : : (mlx5_flow_os_destroy_flow_action
495 : : (pool->actions[j].dr_action));
496 : 0 : mlx5_free(pool);
497 : : }
498 : 0 : mlx5_free(sh->aso_age_mng->pools);
499 : : }
500 : 0 : mlx5_free(sh->aso_age_mng);
501 : 0 : }
502 : :
503 : : /**
504 : : * Initialize the shared aging list information per port.
505 : : *
506 : : * @param[in] sh
507 : : * Pointer to mlx5_dev_ctx_shared object.
508 : : */
509 : : static void
510 : : mlx5_flow_aging_init(struct mlx5_dev_ctx_shared *sh)
511 : : {
512 : : uint32_t i;
513 : : struct mlx5_age_info *age_info;
514 : :
515 : : /*
516 : : * In HW steering, aging information structure is initialized later
517 : : * during configure function.
518 : : */
519 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
520 : : return;
521 [ # # ]: 0 : for (i = 0; i < sh->max_port; i++) {
522 : : age_info = &sh->port[i].age_info;
523 : : age_info->flags = 0;
524 : 0 : TAILQ_INIT(&age_info->aged_counters);
525 : 0 : LIST_INIT(&age_info->aged_aso);
526 : : rte_spinlock_init(&age_info->aged_sl);
527 : 0 : MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
528 : : }
529 : : }
530 : :
531 : : /**
532 : : * DV flow counter mode detect and config.
533 : : *
534 : : * @param dev
535 : : * Pointer to rte_eth_dev structure.
536 : : *
537 : : */
538 : : void
539 : 0 : mlx5_flow_counter_mode_config(struct rte_eth_dev *dev __rte_unused)
540 : : {
541 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
542 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
543 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
544 : 0 : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
545 : : bool fallback;
546 : :
547 : : #ifndef HAVE_IBV_DEVX_ASYNC
548 : : fallback = true;
549 : : #else
550 : : fallback = false;
551 [ # # # # ]: 0 : if (!sh->cdev->config.devx || !sh->config.dv_flow_en ||
552 [ # # ]: 0 : !hca_attr->flow_counters_dump ||
553 [ # # # # ]: 0 : !(hca_attr->flow_counter_bulk_alloc_bitmap & 0x4) ||
554 : 0 : (mlx5_flow_dv_discover_counter_offset_support(dev) == -ENOTSUP))
555 : : fallback = true;
556 : : #endif
557 : : if (fallback)
558 : 0 : DRV_LOG(INFO, "Use fall-back DV counter management. Flow "
559 : : "counter dump:%d, bulk_alloc_bitmap:0x%hhx.",
560 : : hca_attr->flow_counters_dump,
561 : : hca_attr->flow_counter_bulk_alloc_bitmap);
562 : : /* Initialize fallback mode only on the port initializes sh. */
563 [ # # ]: 0 : if (sh->refcnt == 1)
564 : 0 : sh->sws_cmng.counter_fallback = fallback;
565 [ # # ]: 0 : else if (fallback != sh->sws_cmng.counter_fallback)
566 : 0 : DRV_LOG(WARNING, "Port %d in sh has different fallback mode "
567 : : "with others:%d.", PORT_ID(priv), fallback);
568 : : #endif
569 : 0 : }
570 : :
571 : : /**
572 : : * Initialize the counters management structure.
573 : : *
574 : : * @param[in] sh
575 : : * Pointer to mlx5_dev_ctx_shared object to free
576 : : *
577 : : * @return
578 : : * 0 on success, otherwise negative errno value and rte_errno is set.
579 : : */
580 : : static int
581 : 0 : mlx5_flow_counters_mng_init(struct mlx5_dev_ctx_shared *sh)
582 : : {
583 : : int i, j;
584 : :
585 [ # # ]: 0 : if (sh->config.dv_flow_en < 2) {
586 : : void *pools;
587 : :
588 : 0 : pools = mlx5_malloc(MLX5_MEM_ZERO,
589 : : sizeof(struct mlx5_flow_counter_pool *) *
590 : : MLX5_COUNTER_POOLS_MAX_NUM,
591 : : 0, SOCKET_ID_ANY);
592 [ # # ]: 0 : if (!pools) {
593 : 0 : DRV_LOG(ERR,
594 : : "Counter management allocation was failed.");
595 : 0 : rte_errno = ENOMEM;
596 : 0 : return -rte_errno;
597 : : }
598 : 0 : memset(&sh->sws_cmng, 0, sizeof(sh->sws_cmng));
599 : 0 : TAILQ_INIT(&sh->sws_cmng.flow_counters);
600 : 0 : sh->sws_cmng.min_id = MLX5_CNT_BATCH_OFFSET;
601 : 0 : sh->sws_cmng.max_id = -1;
602 : 0 : sh->sws_cmng.last_pool_idx = POOL_IDX_INVALID;
603 : 0 : sh->sws_cmng.pools = pools;
604 : : rte_spinlock_init(&sh->sws_cmng.pool_update_sl);
605 [ # # ]: 0 : for (i = 0; i < MLX5_COUNTER_TYPE_MAX; i++) {
606 : 0 : TAILQ_INIT(&sh->sws_cmng.counters[i]);
607 : : rte_spinlock_init(&sh->sws_cmng.csl[i]);
608 : : }
609 : : } else {
610 : 0 : struct mlx5_hca_attr *attr = &sh->cdev->config.hca_attr;
611 : 0 : uint32_t fw_max_nb_cnts = attr->max_flow_counter;
612 : 0 : uint8_t log_dcs = log2above(fw_max_nb_cnts) - 1;
613 : : uint32_t max_nb_cnts = 0;
614 : :
615 [ # # ]: 0 : for (i = 0, j = 0; j < MLX5_HWS_CNT_DCS_NUM; ++i) {
616 : 0 : int log_dcs_i = log_dcs - i;
617 : :
618 [ # # ]: 0 : if (log_dcs_i < 0)
619 : : break;
620 [ # # ]: 0 : if ((max_nb_cnts | RTE_BIT32(log_dcs_i)) >
621 : : fw_max_nb_cnts)
622 : 0 : continue;
623 : : max_nb_cnts |= RTE_BIT32(log_dcs_i);
624 : 0 : j++;
625 : : }
626 : 0 : sh->hws_max_log_bulk_sz = log_dcs;
627 : 0 : sh->hws_max_nb_counters = max_nb_cnts;
628 : : }
629 : : return 0;
630 : : }
631 : :
632 : : /**
633 : : * Destroy all the resources allocated for a counter memory management.
634 : : *
635 : : * @param[in] mng
636 : : * Pointer to the memory management structure.
637 : : */
638 : : static void
639 : 0 : mlx5_flow_destroy_counter_stat_mem_mng(struct mlx5_counter_stats_mem_mng *mng)
640 : : {
641 : 0 : uint8_t *mem = (uint8_t *)(uintptr_t)mng->raws[0].data;
642 : :
643 [ # # ]: 0 : LIST_REMOVE(mng, next);
644 : 0 : mlx5_os_wrapped_mkey_destroy(&mng->wm);
645 : 0 : mlx5_free(mem);
646 : 0 : }
647 : :
648 : : /**
649 : : * Close and release all the resources of the counters management.
650 : : *
651 : : * @param[in] sh
652 : : * Pointer to mlx5_dev_ctx_shared object to free.
653 : : */
654 : : static void
655 : 0 : mlx5_flow_counters_mng_close(struct mlx5_dev_ctx_shared *sh)
656 : : {
657 : : struct mlx5_counter_stats_mem_mng *mng;
658 : : int i, j;
659 : : int retries = 1024;
660 : :
661 : 0 : rte_errno = 0;
662 [ # # ]: 0 : while (--retries) {
663 : 0 : rte_eal_alarm_cancel(mlx5_flow_query_alarm, sh);
664 [ # # ]: 0 : if (rte_errno != EINPROGRESS)
665 : : break;
666 : : rte_pause();
667 : : }
668 : :
669 [ # # ]: 0 : if (sh->sws_cmng.pools) {
670 : : struct mlx5_flow_counter_pool *pool;
671 : 0 : uint16_t n_valid = sh->sws_cmng.n_valid;
672 : 0 : bool fallback = sh->sws_cmng.counter_fallback;
673 : :
674 [ # # ]: 0 : for (i = 0; i < n_valid; ++i) {
675 : 0 : pool = sh->sws_cmng.pools[i];
676 [ # # # # ]: 0 : if (!fallback && pool->min_dcs)
677 : 0 : claim_zero(mlx5_devx_cmd_destroy
678 : : (pool->min_dcs));
679 [ # # ]: 0 : for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j) {
680 : 0 : struct mlx5_flow_counter *cnt =
681 [ # # ]: 0 : MLX5_POOL_GET_CNT(pool, j);
682 : :
683 [ # # ]: 0 : if (cnt->action)
684 : : claim_zero
685 : : (mlx5_flow_os_destroy_flow_action
686 : : (cnt->action));
687 [ # # # # ]: 0 : if (fallback && cnt->dcs_when_free)
688 : 0 : claim_zero(mlx5_devx_cmd_destroy
689 : : (cnt->dcs_when_free));
690 : : }
691 : 0 : mlx5_free(pool);
692 : : }
693 : 0 : mlx5_free(sh->sws_cmng.pools);
694 : : }
695 : 0 : mng = LIST_FIRST(&sh->sws_cmng.mem_mngs);
696 [ # # ]: 0 : while (mng) {
697 : 0 : mlx5_flow_destroy_counter_stat_mem_mng(mng);
698 : 0 : mng = LIST_FIRST(&sh->sws_cmng.mem_mngs);
699 : : }
700 : 0 : memset(&sh->sws_cmng, 0, sizeof(sh->sws_cmng));
701 : 0 : }
702 : :
703 : : /**
704 : : * Initialize the aso flow meters management structure.
705 : : *
706 : : * @param[in] sh
707 : : * Pointer to mlx5_dev_ctx_shared object to free
708 : : */
709 : : int
710 : 0 : mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh)
711 : : {
712 [ # # ]: 0 : if (!sh->mtrmng) {
713 : 0 : sh->mtrmng = mlx5_malloc(MLX5_MEM_ZERO,
714 : : sizeof(*sh->mtrmng),
715 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
716 [ # # ]: 0 : if (!sh->mtrmng) {
717 : 0 : DRV_LOG(ERR,
718 : : "meter management allocation was failed.");
719 : 0 : rte_errno = ENOMEM;
720 : 0 : return -ENOMEM;
721 : : }
722 [ # # ]: 0 : if (sh->meter_aso_en) {
723 : : rte_spinlock_init(&sh->mtrmng->pools_mng.mtrsl);
724 : : rte_rwlock_init(&sh->mtrmng->pools_mng.resize_mtrwl);
725 : 0 : LIST_INIT(&sh->mtrmng->pools_mng.meters);
726 : : }
727 : 0 : sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
728 : : }
729 : : return 0;
730 : : }
731 : :
732 : : /**
733 : : * Close and release all the resources of
734 : : * the ASO flow meter management structure.
735 : : *
736 : : * @param[in] sh
737 : : * Pointer to mlx5_dev_ctx_shared object to free.
738 : : */
739 : : static void
740 : 0 : mlx5_aso_flow_mtrs_mng_close(struct mlx5_dev_ctx_shared *sh)
741 : : {
742 : : struct mlx5_aso_mtr_pool *mtr_pool;
743 : 0 : struct mlx5_flow_mtr_mng *mtrmng = sh->mtrmng;
744 : : uint32_t idx;
745 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
746 : : struct mlx5_aso_mtr *aso_mtr;
747 : : int i;
748 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
749 : :
750 [ # # ]: 0 : if (sh->meter_aso_en) {
751 : 0 : mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_POLICER);
752 : 0 : idx = mtrmng->pools_mng.n_valid;
753 [ # # ]: 0 : while (idx--) {
754 : 0 : mtr_pool = mtrmng->pools_mng.pools[idx];
755 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
756 [ # # ]: 0 : for (i = 0; i < MLX5_ASO_MTRS_PER_POOL; i++) {
757 : : aso_mtr = &mtr_pool->mtrs[i];
758 [ # # ]: 0 : if (aso_mtr->fm.meter_action_g)
759 : 0 : claim_zero
760 : : (mlx5_glue->destroy_flow_action
761 : : (aso_mtr->fm.meter_action_g));
762 [ # # ]: 0 : if (aso_mtr->fm.meter_action_y)
763 : 0 : claim_zero
764 : : (mlx5_glue->destroy_flow_action
765 : : (aso_mtr->fm.meter_action_y));
766 : : }
767 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
768 : 0 : claim_zero(mlx5_devx_cmd_destroy
769 : : (mtr_pool->devx_obj));
770 : 0 : mtrmng->pools_mng.n_valid--;
771 : 0 : mlx5_free(mtr_pool);
772 : : }
773 : 0 : mlx5_free(sh->mtrmng->pools_mng.pools);
774 : : }
775 : 0 : mlx5_free(sh->mtrmng);
776 : 0 : sh->mtrmng = NULL;
777 : 0 : }
778 : :
779 : : /* Send FLOW_AGED event if needed. */
780 : : void
781 : 0 : mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh)
782 : : {
783 : : struct mlx5_age_info *age_info;
784 : : uint32_t i;
785 : :
786 [ # # ]: 0 : for (i = 0; i < sh->max_port; i++) {
787 : : age_info = &sh->port[i].age_info;
788 [ # # ]: 0 : if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
789 : 0 : continue;
790 : 0 : MLX5_AGE_UNSET(age_info, MLX5_AGE_EVENT_NEW);
791 [ # # ]: 0 : if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER)) {
792 : 0 : MLX5_AGE_UNSET(age_info, MLX5_AGE_TRIGGER);
793 : 0 : rte_eth_dev_callback_process
794 : 0 : (&rte_eth_devices[sh->port[i].devx_ih_port_id],
795 : : RTE_ETH_EVENT_FLOW_AGED, NULL);
796 : : }
797 : : }
798 : 0 : }
799 : :
800 : : /*
801 : : * Initialize the ASO connection tracking structure.
802 : : *
803 : : * @param[in] sh
804 : : * Pointer to mlx5_dev_ctx_shared object.
805 : : *
806 : : * @return
807 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
808 : : */
809 : : int
810 : 0 : mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)
811 : : {
812 : : int err;
813 : :
814 [ # # ]: 0 : if (sh->ct_mng)
815 : : return 0;
816 : 0 : sh->ct_mng = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sh->ct_mng) +
817 : : sizeof(struct mlx5_aso_sq) * MLX5_ASO_CT_SQ_NUM,
818 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
819 [ # # ]: 0 : if (!sh->ct_mng) {
820 : 0 : DRV_LOG(ERR, "ASO CT management allocation failed.");
821 : 0 : rte_errno = ENOMEM;
822 : 0 : return -rte_errno;
823 : : }
824 : 0 : err = mlx5_aso_queue_init(sh, ASO_OPC_MOD_CONNECTION_TRACKING, MLX5_ASO_CT_SQ_NUM);
825 [ # # ]: 0 : if (err) {
826 : 0 : mlx5_free(sh->ct_mng);
827 : 0 : sh->ct_mng = NULL;
828 : : /* rte_errno should be extracted from the failure. */
829 : 0 : rte_errno = EINVAL;
830 : 0 : return -rte_errno;
831 : : }
832 : 0 : rte_spinlock_init(&sh->ct_mng->ct_sl);
833 : : rte_rwlock_init(&sh->ct_mng->resize_rwl);
834 : 0 : LIST_INIT(&sh->ct_mng->free_cts);
835 : 0 : return 0;
836 : : }
837 : :
838 : : /*
839 : : * Close and release all the resources of the
840 : : * ASO connection tracking management structure.
841 : : *
842 : : * @param[in] sh
843 : : * Pointer to mlx5_dev_ctx_shared object to free.
844 : : */
845 : : static void
846 : 0 : mlx5_flow_aso_ct_mng_close(struct mlx5_dev_ctx_shared *sh)
847 : : {
848 : 0 : struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng;
849 : : struct mlx5_aso_ct_pool *ct_pool;
850 : : struct mlx5_aso_ct_action *ct;
851 : : uint32_t idx;
852 : : uint32_t val;
853 : : uint32_t cnt;
854 : : int i;
855 : :
856 : 0 : mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_CONNECTION_TRACKING);
857 : 0 : idx = mng->next;
858 [ # # ]: 0 : while (idx--) {
859 : : cnt = 0;
860 : 0 : ct_pool = mng->pools[idx];
861 [ # # ]: 0 : for (i = 0; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
862 : : ct = &ct_pool->actions[i];
863 : 0 : val = rte_atomic_fetch_sub_explicit(&ct->refcnt, 1,
864 : : rte_memory_order_relaxed);
865 : : MLX5_ASSERT(val == 1);
866 [ # # ]: 0 : if (val > 1)
867 : 0 : cnt++;
868 : : #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
869 [ # # ]: 0 : if (ct->dr_action_orig)
870 : 0 : claim_zero(mlx5_glue->destroy_flow_action
871 : : (ct->dr_action_orig));
872 [ # # ]: 0 : if (ct->dr_action_rply)
873 : 0 : claim_zero(mlx5_glue->destroy_flow_action
874 : : (ct->dr_action_rply));
875 : : #endif
876 : : }
877 : 0 : claim_zero(mlx5_devx_cmd_destroy(ct_pool->devx_obj));
878 [ # # ]: 0 : if (cnt) {
879 : 0 : DRV_LOG(DEBUG, "%u ASO CT objects are being used in the pool %u",
880 : : cnt, i);
881 : : }
882 : 0 : mlx5_free(ct_pool);
883 : : /* in case of failure. */
884 : 0 : mng->next--;
885 : : }
886 : 0 : mlx5_free(mng->pools);
887 : 0 : mlx5_free(mng);
888 : : /* Management structure must be cleared to 0s during allocation. */
889 : 0 : sh->ct_mng = NULL;
890 : 0 : }
891 : :
892 : : /**
893 : : * Initialize the flow resources' indexed mempool.
894 : : *
895 : : * @param[in] sh
896 : : * Pointer to mlx5_dev_ctx_shared object.
897 : : */
898 : : static void
899 : 0 : mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh)
900 : : {
901 : : uint8_t i;
902 : : struct mlx5_indexed_pool_config cfg;
903 : :
904 [ # # ]: 0 : for (i = 0; i < MLX5_IPOOL_MAX; ++i) {
905 : 0 : cfg = mlx5_ipool_cfg[i];
906 [ # # # ]: 0 : switch (i) {
907 : : default:
908 : : break;
909 : : /*
910 : : * Set MLX5_IPOOL_MLX5_FLOW ipool size
911 : : * according to PCI function flow configuration.
912 : : */
913 : 0 : case MLX5_IPOOL_MLX5_FLOW:
914 [ # # ]: 0 : cfg.size = sh->config.dv_flow_en ?
915 : : RTE_ALIGN_MUL_CEIL(sizeof(struct mlx5_flow_handle), 8) :
916 : : MLX5_FLOW_HANDLE_VERBS_SIZE;
917 : 0 : break;
918 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
919 : : /* Set MLX5_IPOOL_JUMP ipool entry size depending on selected flow engine. */
920 : 0 : case MLX5_IPOOL_JUMP:
921 [ # # ]: 0 : cfg.size = sh->config.dv_flow_en == 2 ?
922 : : sizeof(struct mlx5_flow_group) :
923 : : sizeof(struct mlx5_flow_tbl_data_entry);
924 : 0 : break;
925 : : #endif
926 : : }
927 [ # # ]: 0 : if (sh->config.reclaim_mode) {
928 : 0 : cfg.release_mem_en = 1;
929 : 0 : cfg.per_core_cache = 0;
930 : : } else {
931 : 0 : cfg.release_mem_en = 0;
932 : : }
933 : 0 : sh->ipool[i] = mlx5_ipool_create(&cfg);
934 : : }
935 : 0 : }
936 : :
937 : :
938 : : /**
939 : : * Release the flow resources' indexed mempool.
940 : : *
941 : : * @param[in] sh
942 : : * Pointer to mlx5_dev_ctx_shared object.
943 : : */
944 : : static void
945 : 0 : mlx5_flow_ipool_destroy(struct mlx5_dev_ctx_shared *sh)
946 : : {
947 : : uint8_t i;
948 : :
949 [ # # ]: 0 : for (i = 0; i < MLX5_IPOOL_MAX; ++i)
950 : 0 : mlx5_ipool_destroy(sh->ipool[i]);
951 [ # # ]: 0 : for (i = 0; i < MLX5_MAX_MODIFY_NUM; ++i)
952 [ # # ]: 0 : if (sh->mdh_ipools[i])
953 : 0 : mlx5_ipool_destroy(sh->mdh_ipools[i]);
954 : 0 : }
955 : :
956 : : /*
957 : : * Check if dynamic flex parser for eCPRI already exists.
958 : : *
959 : : * @param dev
960 : : * Pointer to Ethernet device structure.
961 : : *
962 : : * @return
963 : : * true on exists, false on not.
964 : : */
965 : : bool
966 : 0 : mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev)
967 : : {
968 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
969 : 0 : struct mlx5_ecpri_parser_profile *prf = &priv->sh->ecpri_parser;
970 : :
971 : 0 : return !!prf->obj;
972 : : }
973 : :
974 : : /*
975 : : * Allocation of a flex parser for eCPRI. Once created, this parser related
976 : : * resources will be held until the device is closed.
977 : : *
978 : : * @param dev
979 : : * Pointer to Ethernet device structure.
980 : : *
981 : : * @return
982 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
983 : : */
984 : : int
985 : 0 : mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev)
986 : : {
987 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
988 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
989 : : struct mlx5_ecpri_parser_profile *prf = &priv->sh->ecpri_parser;
990 : 0 : struct mlx5_devx_graph_node_attr node = {
991 : : .modify_field_select = 0,
992 : : };
993 : : uint32_t ids[8];
994 : : int ret;
995 : :
996 [ # # ]: 0 : if (!priv->sh->cdev->config.hca_attr.parse_graph_flex_node) {
997 : 0 : DRV_LOG(ERR, "Dynamic flex parser is not supported "
998 : : "for device %s.", priv->dev_data->name);
999 : 0 : return -ENOTSUP;
1000 : : }
1001 : : node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIXED;
1002 : 0 : node.header_length_field_offset_mode = !attr->header_length_field_mode_wa;
1003 : : /* 8 bytes now: 4B common header + 4B message body header. */
1004 : 0 : node.header_length_base_value = 0x8;
1005 : : /* After MAC layer: Ether / VLAN. */
1006 : 0 : node.in[0].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_MAC;
1007 : : /* Type of compared condition should be 0xAEFE in the L2 layer. */
1008 : 0 : node.in[0].compare_condition_value = RTE_ETHER_TYPE_ECPRI;
1009 : : /* Sample #0: type in common header. */
1010 : 0 : node.sample[0].flow_match_sample_en = 1;
1011 : : /* Fixed offset. */
1012 : : node.sample[0].flow_match_sample_offset_mode = 0x0;
1013 : : /* Only the 2nd byte will be used. */
1014 : : node.sample[0].flow_match_sample_field_base_offset = 0x0;
1015 : : /* Sample #1: message payload. */
1016 : 0 : node.sample[1].flow_match_sample_en = 1;
1017 : : /* Fixed offset. */
1018 : : node.sample[1].flow_match_sample_offset_mode = 0x0;
1019 : : /*
1020 : : * Only the first two bytes will be used right now, and its offset will
1021 : : * start after the common header that with the length of a DW(u32).
1022 : : */
1023 : 0 : node.sample[1].flow_match_sample_field_base_offset = sizeof(uint32_t);
1024 : 0 : prf->obj = mlx5_devx_cmd_create_flex_parser(priv->sh->cdev->ctx, &node);
1025 [ # # ]: 0 : if (!prf->obj) {
1026 : 0 : DRV_LOG(ERR, "Failed to create flex parser node object.");
1027 [ # # ]: 0 : return (rte_errno == 0) ? -ENODEV : -rte_errno;
1028 : : }
1029 : 0 : prf->num = 2;
1030 : 0 : ret = mlx5_devx_cmd_query_parse_samples(prf->obj, ids, prf->num, NULL);
1031 [ # # ]: 0 : if (ret) {
1032 : 0 : DRV_LOG(ERR, "Failed to query sample IDs.");
1033 : 0 : goto error;
1034 : : }
1035 : 0 : prf->offset[0] = 0x0;
1036 : 0 : prf->offset[1] = sizeof(uint32_t);
1037 : 0 : prf->ids[0] = ids[0];
1038 : 0 : prf->ids[1] = ids[1];
1039 : 0 : return 0;
1040 : : error:
1041 : 0 : mlx5_devx_cmd_destroy(prf->obj);
1042 [ # # ]: 0 : return (rte_errno == 0) ? -ENODEV : -rte_errno;
1043 : : }
1044 : :
1045 : : /* IPv6 SRH header is defined in RFC 8754 */
1046 : : #define MLX5_SRH_HEADER_LENGTH_FIELD_OFFSET 8
1047 : : #define MLX5_SRH_HEADER_LENGTH_FIELD_SIZE 8
1048 : : #define MLX5_SRH_HEADER_LENGTH_SHIFT 3
1049 : :
1050 : : /*
1051 : : * Allocation of a flex parser for srh. Once refcnt is zero, the resources held
1052 : : * by this parser will be freed.
1053 : : * @param dev
1054 : : * Pointer to Ethernet device structure.
1055 : : *
1056 : : * @return
1057 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1058 : : */
1059 : : int
1060 : 0 : mlx5_alloc_srh_flex_parser(struct rte_eth_dev *dev)
1061 : : {
1062 : : static rte_spinlock_t srh_init_sl = RTE_SPINLOCK_INITIALIZER;
1063 : 0 : struct mlx5_devx_graph_node_attr node = {
1064 : : .modify_field_select = 0,
1065 : : };
1066 : : uint32_t i;
1067 : : uint32_t ids[MLX5_GRAPH_NODE_SAMPLE_NUM];
1068 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1069 : 0 : struct mlx5_common_dev_config *config = &priv->sh->cdev->config;
1070 : 0 : struct mlx5_hca_flex_attr *attr = &priv->sh->cdev->config.hca_attr.flex;
1071 [ # # ]: 0 : void *fp = NULL, *ibv_ctx = priv->sh->cdev->ctx;
1072 : : int ret;
1073 : :
1074 : : memset(ids, 0xff, sizeof(ids));
1075 [ # # ]: 0 : if (!config->hca_attr.parse_graph_flex_node ||
1076 [ # # ]: 0 : !config->hca_attr.flex.query_match_sample_info) {
1077 : 0 : DRV_LOG(ERR, "Dynamic flex parser is not supported on HWS");
1078 : 0 : return -ENOTSUP;
1079 : : }
1080 : : rte_spinlock_lock(&srh_init_sl);
1081 [ # # ]: 0 : if (rte_atomic_load_explicit(&priv->sh->srh_flex_parser.refcnt,
1082 : : rte_memory_order_relaxed) > 0)
1083 : 0 : goto end;
1084 : 0 : priv->sh->srh_flex_parser.flex.devx_fp = mlx5_malloc(MLX5_MEM_ZERO,
1085 : : sizeof(struct mlx5_flex_parser_devx), 0, SOCKET_ID_ANY);
1086 [ # # ]: 0 : if (!priv->sh->srh_flex_parser.flex.devx_fp) {
1087 : 0 : rte_errno = ENOMEM;
1088 : 0 : goto error;
1089 : : }
1090 : 0 : node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIELD;
1091 : 0 : node.header_length_field_offset_mode = !attr->header_length_field_mode_wa;
1092 : : /* Srv6 first two DW are not counted in. */
1093 : 0 : node.header_length_base_value = 0x8;
1094 : : /* The unit is uint64_t. */
1095 : 0 : node.header_length_field_shift = MLX5_SRH_HEADER_LENGTH_SHIFT;
1096 : : node.header_length_field_offset_mode = !attr->header_length_field_mode_wa;
1097 : : /* Header length is the 2nd byte. */
1098 : 0 : node.header_length_field_offset = MLX5_SRH_HEADER_LENGTH_FIELD_OFFSET;
1099 [ # # ]: 0 : if (attr->header_length_mask_width < MLX5_SRH_HEADER_LENGTH_FIELD_SIZE)
1100 : 0 : node.header_length_field_offset +=
1101 : 0 : MLX5_SRH_HEADER_LENGTH_FIELD_SIZE - attr->header_length_mask_width;
1102 : 0 : node.header_length_field_mask = mlx5_flex_hdr_len_mask(MLX5_SRH_HEADER_LENGTH_SHIFT, attr);
1103 : : /* One byte next header protocol. */
1104 : 0 : node.next_header_field_size = 0x8;
1105 : 0 : node.in[0].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_IP;
1106 : 0 : node.in[0].compare_condition_value = IPPROTO_ROUTING;
1107 : : /* Final IPv6 address. */
1108 [ # # ]: 0 : for (i = 0; i <= MLX5_SRV6_SAMPLE_NUM - 1 && i < MLX5_GRAPH_NODE_SAMPLE_NUM; i++) {
1109 : 0 : node.sample[i].flow_match_sample_en = 1;
1110 : 0 : node.sample[i].flow_match_sample_offset_mode =
1111 : : MLX5_GRAPH_SAMPLE_OFFSET_FIXED;
1112 : : /* First come first serve no matter inner or outer. */
1113 : 0 : node.sample[i].flow_match_sample_tunnel_mode =
1114 : : MLX5_GRAPH_SAMPLE_TUNNEL_FIRST;
1115 : 0 : node.sample[i].flow_match_sample_field_base_offset =
1116 : 0 : (i + 1) * sizeof(uint32_t); /* in bytes */
1117 : : }
1118 : 0 : node.sample[0].flow_match_sample_field_base_offset = 0;
1119 : 0 : node.out[0].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_TCP;
1120 : 0 : node.out[0].compare_condition_value = IPPROTO_TCP;
1121 : 0 : node.out[1].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_UDP;
1122 : 0 : node.out[1].compare_condition_value = IPPROTO_UDP;
1123 : 0 : node.out[2].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_IPV6;
1124 : 0 : node.out[2].compare_condition_value = IPPROTO_IPV6;
1125 : 0 : fp = mlx5_devx_cmd_create_flex_parser(ibv_ctx, &node);
1126 [ # # ]: 0 : if (!fp) {
1127 : 0 : DRV_LOG(ERR, "Failed to create flex parser node object.");
1128 : 0 : goto error;
1129 : : }
1130 : 0 : priv->sh->srh_flex_parser.flex.devx_fp->devx_obj = fp;
1131 : 0 : priv->sh->srh_flex_parser.flex.mapnum = MLX5_SRV6_SAMPLE_NUM;
1132 : 0 : priv->sh->srh_flex_parser.flex.devx_fp->num_samples = MLX5_SRV6_SAMPLE_NUM;
1133 : :
1134 : 0 : ret = mlx5_devx_cmd_query_parse_samples(fp, ids, priv->sh->srh_flex_parser.flex.mapnum,
1135 : : &priv->sh->srh_flex_parser.flex.devx_fp->anchor_id);
1136 [ # # ]: 0 : if (ret) {
1137 : 0 : DRV_LOG(ERR, "Failed to query sample IDs.");
1138 : 0 : goto error;
1139 : : }
1140 [ # # ]: 0 : for (i = 0; i <= MLX5_SRV6_SAMPLE_NUM - 1 && i < MLX5_GRAPH_NODE_SAMPLE_NUM; i++) {
1141 : 0 : ret = mlx5_devx_cmd_match_sample_info_query(ibv_ctx, ids[i],
1142 : 0 : &priv->sh->srh_flex_parser.flex.devx_fp->sample_info[i]);
1143 [ # # ]: 0 : if (ret) {
1144 : 0 : DRV_LOG(ERR, "Failed to query sample id %u information.", ids[i]);
1145 : 0 : goto error;
1146 : : }
1147 : : }
1148 [ # # ]: 0 : for (i = 0; i <= MLX5_SRV6_SAMPLE_NUM - 1 && i < MLX5_GRAPH_NODE_SAMPLE_NUM; i++) {
1149 : 0 : priv->sh->srh_flex_parser.flex.devx_fp->sample_ids[i] = ids[i];
1150 : 0 : priv->sh->srh_flex_parser.flex.map[i].width = sizeof(uint32_t) * CHAR_BIT;
1151 : 0 : priv->sh->srh_flex_parser.flex.map[i].reg_id = i;
1152 : 0 : priv->sh->srh_flex_parser.flex.map[i].shift =
1153 : : (i + 1) * sizeof(uint32_t) * CHAR_BIT;
1154 : : }
1155 : 0 : priv->sh->srh_flex_parser.flex.map[0].shift = 0;
1156 : 0 : DRV_LOG(NOTICE,
1157 : : "SRH flex parser node object is created successfully. "
1158 : : "Header extension length field size: %d bits\n",
1159 : : attr->header_length_mask_width > MLX5_SRH_HEADER_LENGTH_FIELD_SIZE ?
1160 : : MLX5_SRH_HEADER_LENGTH_FIELD_SIZE : attr->header_length_mask_width);
1161 : 0 : end:
1162 : 0 : rte_atomic_fetch_add_explicit(&priv->sh->srh_flex_parser.refcnt, 1,
1163 : : rte_memory_order_relaxed);
1164 : : rte_spinlock_unlock(&srh_init_sl);
1165 : 0 : return 0;
1166 : 0 : error:
1167 [ # # ]: 0 : if (fp)
1168 : 0 : mlx5_devx_cmd_destroy(fp);
1169 [ # # ]: 0 : if (priv->sh->srh_flex_parser.flex.devx_fp)
1170 : 0 : mlx5_free(priv->sh->srh_flex_parser.flex.devx_fp);
1171 : : rte_spinlock_unlock(&srh_init_sl);
1172 [ # # ]: 0 : return (rte_errno == 0) ? -ENODEV : -rte_errno;
1173 : : }
1174 : :
1175 : : /*
1176 : : * Destroy the flex parser node, including the parser itself, input / output
1177 : : * arcs and DW samples. Resources could be reused then.
1178 : : *
1179 : : * @param dev
1180 : : * Pointer to Ethernet device structure
1181 : : */
1182 : : void
1183 : 0 : mlx5_free_srh_flex_parser(struct rte_eth_dev *dev)
1184 : : {
1185 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1186 : 0 : struct mlx5_internal_flex_parser_profile *fp = &priv->sh->srh_flex_parser;
1187 : :
1188 [ # # ]: 0 : if (rte_atomic_fetch_sub_explicit(&fp->refcnt, 1, rte_memory_order_relaxed) > 1)
1189 : : return;
1190 : 0 : mlx5_devx_cmd_destroy(fp->flex.devx_fp->devx_obj);
1191 : 0 : mlx5_free(fp->flex.devx_fp);
1192 : 0 : fp->flex.devx_fp = NULL;
1193 : : }
1194 : :
1195 : : uint32_t
1196 : 0 : mlx5_get_supported_sw_parsing_offloads(const struct mlx5_hca_attr *attr)
1197 : : {
1198 : : uint32_t sw_parsing_offloads = 0;
1199 : :
1200 [ # # ]: 0 : if (attr->swp) {
1201 : : sw_parsing_offloads |= MLX5_SW_PARSING_CAP;
1202 [ # # ]: 0 : if (attr->swp_csum)
1203 : : sw_parsing_offloads |= MLX5_SW_PARSING_CSUM_CAP;
1204 : :
1205 [ # # ]: 0 : if (attr->swp_lso)
1206 : 0 : sw_parsing_offloads |= MLX5_SW_PARSING_TSO_CAP;
1207 : : }
1208 : 0 : return sw_parsing_offloads;
1209 : : }
1210 : :
1211 : : uint32_t
1212 : 0 : mlx5_get_supported_tunneling_offloads(const struct mlx5_hca_attr *attr)
1213 : : {
1214 : : uint32_t tn_offloads = 0;
1215 : :
1216 [ # # ]: 0 : if (attr->tunnel_stateless_vxlan)
1217 : : tn_offloads |= MLX5_TUNNELED_OFFLOADS_VXLAN_CAP;
1218 [ # # ]: 0 : if (attr->tunnel_stateless_gre)
1219 : 0 : tn_offloads |= MLX5_TUNNELED_OFFLOADS_GRE_CAP;
1220 [ # # ]: 0 : if (attr->tunnel_stateless_geneve_rx)
1221 : 0 : tn_offloads |= MLX5_TUNNELED_OFFLOADS_GENEVE_CAP;
1222 : 0 : return tn_offloads;
1223 : : }
1224 : :
1225 : : /* Fill all fields of UAR structure. */
1226 : : static int
1227 : 0 : mlx5_rxtx_uars_prepare(struct mlx5_dev_ctx_shared *sh)
1228 : : {
1229 : : int ret;
1230 : :
1231 : 0 : ret = mlx5_devx_uar_prepare(sh->cdev, &sh->tx_uar);
1232 [ # # ]: 0 : if (ret) {
1233 : 0 : DRV_LOG(ERR, "Failed to prepare Tx DevX UAR.");
1234 : 0 : return -rte_errno;
1235 : : }
1236 : : MLX5_ASSERT(sh->tx_uar.obj);
1237 : : MLX5_ASSERT(mlx5_os_get_devx_uar_base_addr(sh->tx_uar.obj));
1238 : 0 : ret = mlx5_devx_uar_prepare(sh->cdev, &sh->rx_uar);
1239 [ # # ]: 0 : if (ret) {
1240 : 0 : DRV_LOG(ERR, "Failed to prepare Rx DevX UAR.");
1241 : 0 : mlx5_devx_uar_release(&sh->tx_uar);
1242 : 0 : return -rte_errno;
1243 : : }
1244 : : MLX5_ASSERT(sh->rx_uar.obj);
1245 : : MLX5_ASSERT(mlx5_os_get_devx_uar_base_addr(sh->rx_uar.obj));
1246 : : return 0;
1247 : : }
1248 : :
1249 : : static void
1250 : : mlx5_rxtx_uars_release(struct mlx5_dev_ctx_shared *sh)
1251 : : {
1252 : 0 : mlx5_devx_uar_release(&sh->rx_uar);
1253 : 0 : mlx5_devx_uar_release(&sh->tx_uar);
1254 : 0 : }
1255 : :
1256 : : /**
1257 : : * rte_mempool_walk() callback to unregister Rx mempools.
1258 : : * It used when implicit mempool registration is disabled.
1259 : : *
1260 : : * @param mp
1261 : : * The mempool being walked.
1262 : : * @param arg
1263 : : * Pointer to the device shared context.
1264 : : */
1265 : : static void
1266 : 0 : mlx5_dev_ctx_shared_rx_mempool_unregister_cb(struct rte_mempool *mp, void *arg)
1267 : : {
1268 : : struct mlx5_dev_ctx_shared *sh = arg;
1269 : :
1270 : 0 : mlx5_dev_mempool_unregister(sh->cdev, mp);
1271 : 0 : }
1272 : :
1273 : : /**
1274 : : * Callback used when implicit mempool registration is disabled
1275 : : * in order to track Rx mempool destruction.
1276 : : *
1277 : : * @param event
1278 : : * Mempool life cycle event.
1279 : : * @param mp
1280 : : * An Rx mempool registered explicitly when the port is started.
1281 : : * @param arg
1282 : : * Pointer to a device shared context.
1283 : : */
1284 : : static void
1285 : 0 : mlx5_dev_ctx_shared_rx_mempool_event_cb(enum rte_mempool_event event,
1286 : : struct rte_mempool *mp, void *arg)
1287 : : {
1288 : : struct mlx5_dev_ctx_shared *sh = arg;
1289 : :
1290 [ # # ]: 0 : if (event == RTE_MEMPOOL_EVENT_DESTROY)
1291 : 0 : mlx5_dev_mempool_unregister(sh->cdev, mp);
1292 : 0 : }
1293 : :
1294 : : int
1295 : 0 : mlx5_dev_ctx_shared_mempool_subscribe(struct rte_eth_dev *dev)
1296 : : {
1297 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1298 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
1299 : : int ret;
1300 : :
1301 : : /* Check if we only need to track Rx mempool destruction. */
1302 [ # # ]: 0 : if (!sh->cdev->config.mr_mempool_reg_en) {
1303 : 0 : ret = rte_mempool_event_callback_register
1304 : : (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh);
1305 [ # # # # ]: 0 : return ret == 0 || rte_errno == EEXIST ? 0 : ret;
1306 : : }
1307 : 0 : return mlx5_dev_mempool_subscribe(sh->cdev);
1308 : : }
1309 : :
1310 : : /**
1311 : : * Set up multiple TISs with different affinities according to
1312 : : * number of bonding ports
1313 : : *
1314 : : * @param priv
1315 : : * Pointer of shared context.
1316 : : *
1317 : : * @return
1318 : : * Zero on success, -1 otherwise.
1319 : : */
1320 : : static int
1321 : 0 : mlx5_setup_tis(struct mlx5_dev_ctx_shared *sh)
1322 : : {
1323 : 0 : struct mlx5_devx_lag_context lag_ctx = { 0 };
1324 : 0 : struct mlx5_devx_tis_attr tis_attr = { 0 };
1325 : : int i;
1326 : :
1327 : 0 : tis_attr.transport_domain = sh->td->id;
1328 [ # # ]: 0 : if (sh->bond.n_port) {
1329 [ # # ]: 0 : if (!mlx5_devx_cmd_query_lag(sh->cdev->ctx, &lag_ctx)) {
1330 : 0 : sh->lag.tx_remap_affinity[0] =
1331 : 0 : lag_ctx.tx_remap_affinity_1;
1332 : 0 : sh->lag.tx_remap_affinity[1] =
1333 : 0 : lag_ctx.tx_remap_affinity_2;
1334 : 0 : sh->lag.affinity_mode = lag_ctx.port_select_mode;
1335 : : } else {
1336 : 0 : DRV_LOG(ERR, "Failed to query lag affinity.");
1337 : 0 : return -1;
1338 : : }
1339 [ # # ]: 0 : if (sh->lag.affinity_mode == MLX5_LAG_MODE_TIS)
1340 : 0 : DRV_LOG(DEBUG, "LAG number of ports : %d, affinity_1 & 2 : pf%d & %d.\n",
1341 : : sh->bond.n_port, lag_ctx.tx_remap_affinity_1,
1342 : : lag_ctx.tx_remap_affinity_2);
1343 [ # # ]: 0 : else if (sh->lag.affinity_mode == MLX5_LAG_MODE_HASH)
1344 : 0 : DRV_LOG(INFO, "Device %s enabled HW hash based LAG.",
1345 : : sh->ibdev_name);
1346 : : }
1347 [ # # ]: 0 : for (i = 0; i <= sh->bond.n_port; i++) {
1348 : : /*
1349 : : * lag_tx_port_affinity: 0 auto-selection, 1 PF1, 2 PF2 vice versa.
1350 : : * Each TIS binds to one PF by setting lag_tx_port_affinity (> 0).
1351 : : * Once LAG enabled, we create multiple TISs and bind each one to
1352 : : * different PFs, then TIS[i+1] gets affinity i+1 and goes to PF i+1.
1353 : : * TIS[0] is reserved for HW Hash mode.
1354 : : */
1355 : 0 : tis_attr.lag_tx_port_affinity = i;
1356 : 0 : sh->tis[i] = mlx5_devx_cmd_create_tis(sh->cdev->ctx, &tis_attr);
1357 [ # # ]: 0 : if (!sh->tis[i]) {
1358 : 0 : DRV_LOG(ERR, "Failed to create TIS %d/%d for [bonding] device"
1359 : : " %s.", i, sh->bond.n_port,
1360 : : sh->ibdev_name);
1361 : 0 : return -1;
1362 : : }
1363 : : }
1364 : : return 0;
1365 : : }
1366 : :
1367 : : /**
1368 : : * Verify and store value for share device argument.
1369 : : *
1370 : : * @param[in] key
1371 : : * Key argument to verify.
1372 : : * @param[in] val
1373 : : * Value associated with key.
1374 : : * @param opaque
1375 : : * User data.
1376 : : *
1377 : : * @return
1378 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1379 : : */
1380 : : static int
1381 : 0 : mlx5_dev_args_check_handler(const char *key, const char *val, void *opaque)
1382 : : {
1383 : : struct mlx5_sh_config *config = opaque;
1384 : : signed long tmp;
1385 : :
1386 : 0 : errno = 0;
1387 : 0 : tmp = strtol(val, NULL, 0);
1388 [ # # ]: 0 : if (errno) {
1389 : 0 : rte_errno = errno;
1390 : 0 : DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
1391 : 0 : return -rte_errno;
1392 : : }
1393 [ # # # # : 0 : if (tmp < 0 && strcmp(MLX5_TX_PP, key) && strcmp(MLX5_TX_SKEW, key)) {
# # ]
1394 : : /* Negative values are acceptable for some keys only. */
1395 : 0 : rte_errno = EINVAL;
1396 : 0 : DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
1397 : 0 : return -rte_errno;
1398 : : }
1399 [ # # ]: 0 : if (strcmp(MLX5_TX_PP, key) == 0) {
1400 : : unsigned long mod = tmp >= 0 ? tmp : -tmp;
1401 : :
1402 [ # # ]: 0 : if (!mod) {
1403 : 0 : DRV_LOG(ERR, "Zero Tx packet pacing parameter.");
1404 : 0 : rte_errno = EINVAL;
1405 : 0 : return -rte_errno;
1406 : : }
1407 : 0 : config->tx_pp = tmp;
1408 [ # # ]: 0 : } else if (strcmp(MLX5_TX_SKEW, key) == 0) {
1409 : 0 : config->tx_skew = tmp;
1410 [ # # ]: 0 : } else if (strcmp(MLX5_L3_VXLAN_EN, key) == 0) {
1411 : 0 : config->l3_vxlan_en = !!tmp;
1412 [ # # ]: 0 : } else if (strcmp(MLX5_VF_NL_EN, key) == 0) {
1413 : 0 : config->vf_nl_en = !!tmp;
1414 [ # # ]: 0 : } else if (strcmp(MLX5_DV_ESW_EN, key) == 0) {
1415 : 0 : config->dv_esw_en = !!tmp;
1416 [ # # ]: 0 : } else if (strcmp(MLX5_DV_FLOW_EN, key) == 0) {
1417 [ # # ]: 0 : if (tmp > 2) {
1418 : 0 : DRV_LOG(ERR, "Invalid %s parameter.", key);
1419 : 0 : rte_errno = EINVAL;
1420 : 0 : return -rte_errno;
1421 : : }
1422 : 0 : config->dv_flow_en = tmp;
1423 [ # # ]: 0 : } else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
1424 : 0 : if (tmp != MLX5_XMETA_MODE_LEGACY &&
1425 : : tmp != MLX5_XMETA_MODE_META16 &&
1426 : : tmp != MLX5_XMETA_MODE_META32 &&
1427 [ # # ]: 0 : tmp != MLX5_XMETA_MODE_MISS_INFO &&
1428 : : tmp != MLX5_XMETA_MODE_META32_HWS) {
1429 : 0 : DRV_LOG(ERR, "Invalid extensive metadata parameter.");
1430 : 0 : rte_errno = EINVAL;
1431 : 0 : return -rte_errno;
1432 : : }
1433 [ # # ]: 0 : if (tmp != MLX5_XMETA_MODE_MISS_INFO)
1434 : 0 : config->dv_xmeta_en = tmp;
1435 : : else
1436 : 0 : config->dv_miss_info = 1;
1437 [ # # ]: 0 : } else if (strcmp(MLX5_LACP_BY_USER, key) == 0) {
1438 : 0 : config->lacp_by_user = !!tmp;
1439 [ # # ]: 0 : } else if (strcmp(MLX5_RECLAIM_MEM, key) == 0) {
1440 : 0 : if (tmp != MLX5_RCM_NONE &&
1441 [ # # ]: 0 : tmp != MLX5_RCM_LIGHT &&
1442 : : tmp != MLX5_RCM_AGGR) {
1443 : 0 : DRV_LOG(ERR, "Unrecognize %s: \"%s\"", key, val);
1444 : 0 : rte_errno = EINVAL;
1445 : 0 : return -rte_errno;
1446 : : }
1447 : 0 : config->reclaim_mode = tmp;
1448 [ # # ]: 0 : } else if (strcmp(MLX5_DECAP_EN, key) == 0) {
1449 : 0 : config->decap_en = !!tmp;
1450 [ # # ]: 0 : } else if (strcmp(MLX5_ALLOW_DUPLICATE_PATTERN, key) == 0) {
1451 : 0 : config->allow_duplicate_pattern = !!tmp;
1452 [ # # ]: 0 : } else if (strcmp(MLX5_FDB_DEFAULT_RULE_EN, key) == 0) {
1453 : 0 : config->fdb_def_rule = !!tmp;
1454 [ # # ]: 0 : } else if (strcmp(MLX5_HWS_CNT_SERVICE_CORE, key) == 0) {
1455 : 0 : config->cnt_svc.service_core = tmp;
1456 [ # # ]: 0 : } else if (strcmp(MLX5_HWS_CNT_CYCLE_TIME, key) == 0) {
1457 : 0 : config->cnt_svc.cycle_time = tmp;
1458 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MEM_ALGN, key) == 0) {
1459 : 0 : config->txq_mem_algn = (uint32_t)tmp;
1460 : : }
1461 : : return 0;
1462 : : }
1463 : :
1464 : : /**
1465 : : * Parse user device parameters and adjust them according to device
1466 : : * capabilities.
1467 : : *
1468 : : * @param sh
1469 : : * Pointer to shared device context.
1470 : : * @param mkvlist
1471 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
1472 : : * @param config
1473 : : * Pointer to shared device configuration structure.
1474 : : *
1475 : : * @return
1476 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1477 : : */
1478 : : static int
1479 : 0 : mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh,
1480 : : struct mlx5_kvargs_ctrl *mkvlist,
1481 : : struct mlx5_sh_config *config)
1482 : : {
1483 : 0 : const char **params = (const char *[]){
1484 : : MLX5_TX_PP,
1485 : : MLX5_TX_SKEW,
1486 : : MLX5_L3_VXLAN_EN,
1487 : : MLX5_VF_NL_EN,
1488 : : MLX5_DV_ESW_EN,
1489 : : MLX5_DV_FLOW_EN,
1490 : : MLX5_DV_XMETA_EN,
1491 : : MLX5_LACP_BY_USER,
1492 : : MLX5_RECLAIM_MEM,
1493 : : MLX5_DECAP_EN,
1494 : : MLX5_ALLOW_DUPLICATE_PATTERN,
1495 : : MLX5_FDB_DEFAULT_RULE_EN,
1496 : : MLX5_HWS_CNT_SERVICE_CORE,
1497 : : MLX5_HWS_CNT_CYCLE_TIME,
1498 : : MLX5_TXQ_MEM_ALGN,
1499 : : NULL,
1500 : : };
1501 : : int ret = 0;
1502 : 0 : size_t alignment = rte_mem_page_size();
1503 : 0 : uint32_t max_queue_umem_size = MLX5_WQE_SIZE * mlx5_dev_get_max_wq_size(sh);
1504 : :
1505 [ # # ]: 0 : if (alignment == (size_t)-1) {
1506 : : alignment = (1 << MLX5_LOG_PAGE_SIZE);
1507 : 0 : DRV_LOG(WARNING, "Failed to get page_size, using default %zu size.", alignment);
1508 : : }
1509 : :
1510 : : /* Default configuration. */
1511 : : memset(config, 0, sizeof(*config));
1512 : 0 : mlx5_os_default_flow_config(config, sh);
1513 : 0 : config->vf_nl_en = 1;
1514 : 0 : config->dv_esw_en = 1;
1515 : 0 : config->decap_en = 1;
1516 : 0 : config->fdb_def_rule = 1;
1517 : 0 : config->cnt_svc.cycle_time = MLX5_CNT_SVC_CYCLE_TIME_DEFAULT;
1518 : 0 : config->cnt_svc.service_core = rte_get_main_lcore();
1519 : 0 : config->txq_mem_algn = log2above(alignment);
1520 [ # # ]: 0 : if (mkvlist != NULL) {
1521 : : /* Process parameters. */
1522 : 0 : ret = mlx5_kvargs_process(mkvlist, params,
1523 : : mlx5_dev_args_check_handler, config);
1524 [ # # ]: 0 : if (ret) {
1525 : 0 : DRV_LOG(ERR, "Failed to process device arguments: %s",
1526 : : strerror(rte_errno));
1527 : 0 : return -rte_errno;
1528 : : }
1529 : : }
1530 : : /* Adjust parameters according to device capabilities. */
1531 : 0 : mlx5_fixup_flow_config(config, sh, mkvlist);
1532 [ # # # # ]: 0 : if (config->dv_esw_en && !sh->dev_cap.dv_esw_en) {
1533 : 0 : DRV_LOG(DEBUG, "E-Switch DV flow is not supported.");
1534 : 0 : config->dv_esw_en = 0;
1535 : : }
1536 [ # # ]: 0 : if (config->dv_esw_en && !config->dv_flow_en) {
1537 : 0 : DRV_LOG(DEBUG,
1538 : : "E-Switch DV flow is supported only when DV flow is enabled.");
1539 : 0 : config->dv_esw_en = 0;
1540 : : }
1541 [ # # ]: 0 : if (config->dv_miss_info && config->dv_esw_en)
1542 : 0 : config->dv_xmeta_en = MLX5_XMETA_MODE_META16;
1543 [ # # ]: 0 : if (!config->dv_esw_en &&
1544 [ # # ]: 0 : config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1545 : 0 : DRV_LOG(WARNING,
1546 : : "Metadata mode %u is not supported (no E-Switch).",
1547 : : config->dv_xmeta_en);
1548 : 0 : config->dv_xmeta_en = MLX5_XMETA_MODE_LEGACY;
1549 : : }
1550 [ # # # # ]: 0 : if (config->tx_pp && !sh->dev_cap.txpp_en) {
1551 : 0 : DRV_LOG(ERR, "Packet pacing is not supported.");
1552 : 0 : rte_errno = ENODEV;
1553 : 0 : return -rte_errno;
1554 : : }
1555 [ # # # # ]: 0 : if (!config->tx_pp && config->tx_skew &&
1556 [ # # ]: 0 : !sh->cdev->config.hca_attr.wait_on_time) {
1557 : 0 : DRV_LOG(WARNING,
1558 : : "\"tx_skew\" doesn't affect without \"tx_pp\".");
1559 : : }
1560 : : /* Check for LRO support. */
1561 [ # # # # ]: 0 : if (mlx5_devx_obj_ops_en(sh) && sh->cdev->config.hca_attr.lro_cap) {
1562 : : /* TBD check tunnel lro caps. */
1563 : 0 : config->lro_allowed = 1;
1564 : 0 : DRV_LOG(DEBUG, "LRO is allowed.");
1565 : 0 : DRV_LOG(DEBUG,
1566 : : "LRO minimal size of TCP segment required for coalescing is %d bytes.",
1567 : : sh->cdev->config.hca_attr.lro_min_mss_size);
1568 : : }
1569 : : /*
1570 : : * If HW has bug working with tunnel packet decapsulation and scatter
1571 : : * FCS, and decapsulation is needed, clear the hw_fcs_strip bit.
1572 : : * Then RTE_ETH_RX_OFFLOAD_KEEP_CRC bit will not be set anymore.
1573 : : */
1574 [ # # # # ]: 0 : if (sh->dev_cap.scatter_fcs_w_decap_disable && sh->config.decap_en)
1575 : 0 : config->hw_fcs_strip = 0;
1576 : : else
1577 : 0 : config->hw_fcs_strip = sh->dev_cap.hw_fcs_strip;
1578 [ # # # # ]: 0 : if (config->txq_mem_algn != 0 && config->txq_mem_algn < log2above(alignment)) {
1579 : 0 : DRV_LOG(WARNING,
1580 : : "\"txq_mem_algn\" too small %u, round up to %u.",
1581 : : config->txq_mem_algn, log2above(alignment));
1582 : 0 : config->txq_mem_algn = log2above(alignment);
1583 [ # # ]: 0 : } else if (config->txq_mem_algn > log2above(max_queue_umem_size)) {
1584 : 0 : DRV_LOG(WARNING,
1585 : : "\"txq_mem_algn\" with value %u bigger than %u.",
1586 : : config->txq_mem_algn, log2above(max_queue_umem_size));
1587 : : }
1588 [ # # ]: 0 : DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported",
1589 : : (config->hw_fcs_strip ? "" : "not "));
1590 : 0 : DRV_LOG(DEBUG, "\"tx_pp\" is %d.", config->tx_pp);
1591 : 0 : DRV_LOG(DEBUG, "\"tx_skew\" is %d.", config->tx_skew);
1592 : 0 : DRV_LOG(DEBUG, "\"reclaim_mode\" is %u.", config->reclaim_mode);
1593 : 0 : DRV_LOG(DEBUG, "\"dv_esw_en\" is %u.", config->dv_esw_en);
1594 : 0 : DRV_LOG(DEBUG, "\"dv_flow_en\" is %u.", config->dv_flow_en);
1595 : 0 : DRV_LOG(DEBUG, "\"dv_xmeta_en\" is %u.", config->dv_xmeta_en);
1596 : 0 : DRV_LOG(DEBUG, "\"dv_miss_info\" is %u.", config->dv_miss_info);
1597 : 0 : DRV_LOG(DEBUG, "\"l3_vxlan_en\" is %u.", config->l3_vxlan_en);
1598 : 0 : DRV_LOG(DEBUG, "\"vf_nl_en\" is %u.", config->vf_nl_en);
1599 : 0 : DRV_LOG(DEBUG, "\"lacp_by_user\" is %u.", config->lacp_by_user);
1600 : 0 : DRV_LOG(DEBUG, "\"decap_en\" is %u.", config->decap_en);
1601 : 0 : DRV_LOG(DEBUG, "\"allow_duplicate_pattern\" is %u.",
1602 : : config->allow_duplicate_pattern);
1603 : 0 : DRV_LOG(DEBUG, "\"fdb_def_rule_en\" is %u.", config->fdb_def_rule);
1604 : 0 : DRV_LOG(DEBUG, "\"txq_mem_algn\" is %u.", config->txq_mem_algn);
1605 : 0 : return 0;
1606 : : }
1607 : :
1608 : : /**
1609 : : * Configure realtime timestamp format.
1610 : : *
1611 : : * @param sh
1612 : : * Pointer to mlx5_dev_ctx_shared object.
1613 : : * @param hca_attr
1614 : : * Pointer to DevX HCA capabilities structure.
1615 : : */
1616 : : void
1617 : 0 : mlx5_rt_timestamp_config(struct mlx5_dev_ctx_shared *sh,
1618 : : struct mlx5_hca_attr *hca_attr)
1619 : : {
1620 : : uint32_t reg[MLX5_ST_SZ_DW(register_mtutc)];
1621 : : int ret = ENOTSUP;
1622 : :
1623 [ # # ]: 0 : if (hca_attr->access_register_user)
1624 : 0 : ret = mlx5_devx_cmd_register_read(sh->cdev->ctx,
1625 : : MLX5_REGISTER_ID_MTUTC, 0,
1626 : : reg, RTE_DIM(reg));
1627 [ # # ]: 0 : if (!ret) {
1628 : : uint32_t ts_mode;
1629 : :
1630 : : /* MTUTC register is read successfully. */
1631 [ # # ]: 0 : ts_mode = MLX5_GET(register_mtutc, reg, time_stamp_mode);
1632 [ # # ]: 0 : if (ts_mode == MLX5_MTUTC_TIMESTAMP_MODE_REAL_TIME)
1633 : 0 : sh->dev_cap.rt_timestamp = 1;
1634 : : } else {
1635 : : /* Kernel does not support register reading. */
1636 [ # # ]: 0 : if (hca_attr->dev_freq_khz == (NS_PER_S / MS_PER_S))
1637 : 0 : sh->dev_cap.rt_timestamp = 1;
1638 : : }
1639 : 0 : }
1640 : :
1641 : : static void
1642 : 0 : mlx5_init_hws_flow_tags_registers(struct mlx5_dev_ctx_shared *sh)
1643 : : {
1644 : : struct mlx5_dev_registers *reg = &sh->registers;
1645 : 0 : uint32_t meta_mode = sh->config.dv_xmeta_en;
1646 : 0 : uint16_t reg_c_caps = (uint16_t)sh->cdev->config.hca_attr.set_reg_c;
1647 : : uint16_t masks = reg_c_caps;
1648 : : uint16_t unset = 0;
1649 : : uint32_t i, j;
1650 : :
1651 : : /*
1652 : : * The CAPA is global for common device but only used in net.
1653 : : * It is shared per eswitch domain.
1654 : : */
1655 [ # # ]: 0 : if (reg->aso_reg != REG_NON)
1656 : 0 : unset |= 1 << mlx5_regc_index(reg->aso_reg);
1657 : 0 : unset |= 1 << mlx5_regc_index(REG_C_6);
1658 [ # # ]: 0 : if (sh->config.dv_esw_en)
1659 : 0 : unset |= 1 << mlx5_regc_index(REG_C_0);
1660 [ # # # # ]: 0 : if (meta_mode == MLX5_XMETA_MODE_META32_HWS ||
1661 [ # # ]: 0 : mlx5_vport_rx_metadata_passing_enabled(sh) ||
1662 : 0 : mlx5_vport_tx_metadata_passing_enabled(sh))
1663 : 0 : unset |= 1 << mlx5_regc_index(REG_C_1);
1664 : 0 : masks &= ~unset;
1665 [ # # ]: 0 : for (i = 0, j = 0; i < MLX5_FLOW_HW_TAGS_MAX; i++) {
1666 [ # # ]: 0 : if (!!((1 << i) & masks))
1667 : 0 : reg->hw_avl_tags[j++] = mlx5_regc_value(i);
1668 : : }
1669 : : /*
1670 : : * Set the registers for NAT64 usage internally. REG_C_6 is always used.
1671 : : * The other 2 registers will be fetched from right to left, at least 2
1672 : : * tag registers should be available.
1673 : : * If not enough registers are available or REG_C_6 is not supported by current FW,
1674 : : * NAT64 action will not be supported.
1675 : : */
1676 [ # # # # ]: 0 : if ((reg_c_caps & RTE_BIT32(mlx5_regc_index(REG_C_6))) &&
1677 : : j >= MLX5_FLOW_NAT64_REGS_MAX - 1) {
1678 : : MLX5_ASSERT(j >= (MLX5_FLOW_NAT64_REGS_MAX - 1));
1679 : 0 : reg->nat64_regs[0] = REG_C_6;
1680 : 0 : reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
1681 : 0 : reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
1682 : : } else {
1683 [ # # ]: 0 : if (j >= MLX5_FLOW_NAT64_REGS_MAX) {
1684 : 0 : reg->nat64_regs[0] = reg->hw_avl_tags[j - 3];
1685 : 0 : reg->nat64_regs[1] = reg->hw_avl_tags[j - 2];
1686 : 0 : reg->nat64_regs[2] = reg->hw_avl_tags[j - 1];
1687 : : }
1688 : : }
1689 : 0 : }
1690 : :
1691 : : static void
1692 : 0 : mlx5_init_aso_register(struct mlx5_dev_ctx_shared *sh)
1693 : : {
1694 : : #if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO_EXT)
1695 : 0 : const struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
1696 : : const struct mlx5_hca_qos_attr *qos = &hca_attr->qos;
1697 : 0 : uint8_t reg_c_mask = qos->flow_meter_reg_c_ids & 0xfc;
1698 : :
1699 [ # # # # ]: 0 : if (!(qos->sup && qos->flow_meter_old && sh->config.dv_flow_en))
1700 : : return;
1701 : : /*
1702 : : * Meter needs two REG_C's for color match and pre-sfx
1703 : : * flow match. Here get the REG_C for color match.
1704 : : * REG_C_0 and REG_C_1 is reserved for metadata feature.
1705 : : */
1706 [ # # ]: 0 : if (rte_popcount32(reg_c_mask) > 0) {
1707 : : /*
1708 : : * The meter color register is used by the
1709 : : * flow-hit feature as well.
1710 : : * The flow-hit feature must use REG_C_3
1711 : : * Prefer REG_C_3 if it is available.
1712 : : */
1713 [ # # ]: 0 : if (reg_c_mask & (1 << mlx5_regc_index(REG_C_3)))
1714 : 0 : sh->registers.aso_reg = REG_C_3;
1715 : : else
1716 : 0 : sh->registers.aso_reg =
1717 : 0 : mlx5_regc_value(ffs(reg_c_mask) - 1);
1718 : : }
1719 : : #else
1720 : : RTE_SET_USED(sh);
1721 : : #endif
1722 : : }
1723 : :
1724 : : static void
1725 : 0 : mlx5_init_shared_dev_registers(struct mlx5_dev_ctx_shared *sh)
1726 : : {
1727 [ # # ]: 0 : if (sh->cdev->config.devx)
1728 : 0 : mlx5_init_aso_register(sh);
1729 [ # # ]: 0 : if (sh->registers.aso_reg != REG_NON) {
1730 : 0 : DRV_LOG(DEBUG, "ASO register: REG_C%d",
1731 : : mlx5_regc_index(sh->registers.aso_reg));
1732 : : } else {
1733 : 0 : DRV_LOG(DEBUG, "ASO register: NONE");
1734 : : }
1735 [ # # ]: 0 : if (sh->config.dv_flow_en == 2)
1736 : 0 : mlx5_init_hws_flow_tags_registers(sh);
1737 : 0 : }
1738 : :
1739 : : static struct mlx5_physical_device *
1740 : 0 : mlx5_get_physical_device(struct mlx5_common_device *cdev)
1741 : : {
1742 : : struct mlx5_physical_device *phdev;
1743 : : struct mlx5_hca_attr *attr = &cdev->config.hca_attr;
1744 : :
1745 : : /* Search for physical device by system_image_guid. */
1746 [ # # ]: 0 : LIST_FOREACH(phdev, &phdev_list, next) {
1747 [ # # ]: 0 : if (phdev->guid == attr->system_image_guid) {
1748 : 0 : phdev->refcnt++;
1749 : 0 : return phdev;
1750 : : }
1751 : : }
1752 : 0 : phdev = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1753 : : sizeof(struct mlx5_physical_device),
1754 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1755 [ # # ]: 0 : if (!phdev) {
1756 : 0 : DRV_LOG(ERR, "Physical device allocation failure.");
1757 : 0 : rte_errno = ENOMEM;
1758 : 0 : return NULL;
1759 : : }
1760 : : /*
1761 : : * The same CTX create the physical device objects should destroy them.
1762 : : * Since we can't be sure it will be done by same CTX, we prepare for
1763 : : * the physical device a special CTX used by objects creation.
1764 : : */
1765 : 0 : phdev->ctx = mlx5_os_get_physical_device_ctx(cdev);
1766 [ # # ]: 0 : if (!phdev->ctx) {
1767 : 0 : mlx5_free(phdev);
1768 : 0 : return NULL;
1769 : : }
1770 : 0 : phdev->guid = attr->system_image_guid;
1771 : 0 : phdev->refcnt = 1;
1772 [ # # ]: 0 : LIST_INSERT_HEAD(&phdev_list, phdev, next);
1773 : 0 : DRV_LOG(DEBUG, "Physical device is created, guid=%" PRIu64 ".",
1774 : : phdev->guid);
1775 : 0 : return phdev;
1776 : : }
1777 : :
1778 : : struct mlx5_physical_device *
1779 : 0 : mlx5_get_locked_physical_device(struct mlx5_priv *priv)
1780 : : {
1781 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
1782 : 0 : return priv->sh->phdev;
1783 : : }
1784 : :
1785 : : void
1786 : 0 : mlx5_unlock_physical_device(void)
1787 : : {
1788 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1789 : 0 : }
1790 : :
1791 : : static void
1792 : 0 : mlx5_physical_device_destroy(struct mlx5_physical_device *phdev)
1793 : : {
1794 : : #ifdef RTE_PMD_MLX5_DEBUG
1795 : : /* Check the object presence in the list. */
1796 : : struct mlx5_physical_device *lphdev;
1797 : :
1798 : : LIST_FOREACH(lphdev, &phdev_list, next)
1799 : : if (lphdev == phdev)
1800 : : break;
1801 : : MLX5_ASSERT(lphdev);
1802 : : if (lphdev != phdev) {
1803 : : DRV_LOG(ERR, "Freeing non-existing physical device");
1804 : : return;
1805 : : }
1806 : : #endif
1807 : : MLX5_ASSERT(phdev);
1808 : : MLX5_ASSERT(phdev->refcnt);
1809 [ # # ]: 0 : if (--phdev->refcnt)
1810 : : return;
1811 : : /* Remove physical device from the global device list. */
1812 [ # # ]: 0 : LIST_REMOVE(phdev, next);
1813 : : MLX5_ASSERT(phdev->ctx);
1814 : 0 : claim_zero(mlx5_glue->close_device(phdev->ctx));
1815 : 0 : mlx5_free(phdev);
1816 : : }
1817 : :
1818 : : /**
1819 : : * Allocate shared device context. If there is multiport device the
1820 : : * master and representors will share this context, if there is single
1821 : : * port dedicated device, the context will be used by only given
1822 : : * port due to unification.
1823 : : *
1824 : : * Routine first searches the context for the specified device name,
1825 : : * if found the shared context assumed and reference counter is incremented.
1826 : : * If no context found the new one is created and initialized with specified
1827 : : * device context and parameters.
1828 : : *
1829 : : * @param[in] spawn
1830 : : * Pointer to the device attributes (name, port, etc).
1831 : : * @param mkvlist
1832 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
1833 : : *
1834 : : * @return
1835 : : * Pointer to mlx5_dev_ctx_shared object on success,
1836 : : * otherwise NULL and rte_errno is set.
1837 : : */
1838 : : struct mlx5_dev_ctx_shared *
1839 : 0 : mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
1840 : : struct mlx5_kvargs_ctrl *mkvlist)
1841 : : {
1842 : : struct mlx5_dev_ctx_shared *sh;
1843 : : int err = 0;
1844 : : uint32_t i;
1845 : :
1846 : : MLX5_ASSERT(spawn);
1847 : : /* Secondary process should not create the shared context. */
1848 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
1849 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
1850 : : /* Search for IB context by device name. */
1851 [ # # ]: 0 : LIST_FOREACH(sh, &dev_ctx_list, next) {
1852 [ # # ]: 0 : if (!strcmp(sh->ibdev_name, spawn->phys_dev_name)) {
1853 : 0 : sh->refcnt++;
1854 : 0 : goto exit;
1855 : : }
1856 : : }
1857 : : /* No device found, we have to create new shared context. */
1858 : : MLX5_ASSERT(spawn->max_port);
1859 : 0 : sh = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1860 : : sizeof(struct mlx5_dev_ctx_shared) +
1861 : 0 : spawn->max_port * sizeof(struct mlx5_dev_shared_port),
1862 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1863 [ # # ]: 0 : if (!sh) {
1864 : 0 : DRV_LOG(ERR, "Shared context allocation failure.");
1865 : 0 : rte_errno = ENOMEM;
1866 : 0 : goto exit;
1867 : : }
1868 : 0 : pthread_mutex_init(&sh->txpp.mutex, NULL);
1869 : 0 : sh->numa_node = spawn->cdev->dev->numa_node;
1870 : 0 : sh->cdev = spawn->cdev;
1871 : 0 : sh->esw_mode = !!(spawn->info.master || spawn->info.representor);
1872 [ # # ]: 0 : if (spawn->bond_info)
1873 : 0 : sh->bond = *spawn->bond_info;
1874 : 0 : err = mlx5_os_capabilities_prepare(sh);
1875 [ # # ]: 0 : if (err) {
1876 : 0 : DRV_LOG(ERR, "Fail to configure device capabilities.");
1877 : 0 : goto error;
1878 : : }
1879 : 0 : err = mlx5_shared_dev_ctx_args_config(sh, mkvlist, &sh->config);
1880 [ # # ]: 0 : if (err) {
1881 : 0 : DRV_LOG(ERR, "Failed to process device configure: %s",
1882 : : strerror(rte_errno));
1883 : 0 : goto error;
1884 : : }
1885 : : /* Used on Tx send scheduling (tx_pp=1 or wait-on-time). */
1886 : 0 : sh->txpp.skew = sh->config.tx_skew;
1887 : 0 : sh->refcnt = 1;
1888 : 0 : sh->max_port = spawn->max_port;
1889 [ # # # # ]: 0 : strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->cdev->ctx),
1890 : : sizeof(sh->ibdev_name) - 1);
1891 [ # # ]: 0 : strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->cdev->ctx),
1892 : : sizeof(sh->ibdev_path) - 1);
1893 : 0 : sh->phdev = mlx5_get_physical_device(sh->cdev);
1894 [ # # ]: 0 : if (!sh->phdev)
1895 : 0 : goto error;
1896 : : /*
1897 : : * Setting port_id to max unallowed value means there is no interrupt
1898 : : * subhandler installed for the given port index i.
1899 : : */
1900 [ # # ]: 0 : for (i = 0; i < sh->max_port; i++) {
1901 : 0 : sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
1902 : 0 : sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS;
1903 : 0 : sh->port[i].nl_ih_port_id = RTE_MAX_ETHPORTS;
1904 : : }
1905 [ # # ]: 0 : if (sh->cdev->config.devx) {
1906 : 0 : sh->td = mlx5_devx_cmd_create_td(sh->cdev->ctx);
1907 [ # # ]: 0 : if (!sh->td) {
1908 : 0 : DRV_LOG(ERR, "TD allocation failure");
1909 : 0 : rte_errno = ENOMEM;
1910 : 0 : goto error;
1911 : : }
1912 [ # # ]: 0 : if (mlx5_setup_tis(sh)) {
1913 : 0 : DRV_LOG(ERR, "TIS allocation failure");
1914 : 0 : rte_errno = ENOMEM;
1915 : 0 : goto error;
1916 : : }
1917 : 0 : err = mlx5_rxtx_uars_prepare(sh);
1918 [ # # ]: 0 : if (err)
1919 : 0 : goto error;
1920 : : #ifndef RTE_ARCH_64
1921 : : } else {
1922 : : /* Initialize UAR access locks for 32bit implementations. */
1923 : : rte_spinlock_init(&sh->uar_lock_cq);
1924 : : for (i = 0; i < MLX5_UAR_PAGE_NUM_MAX; i++)
1925 : : rte_spinlock_init(&sh->uar_lock[i]);
1926 : : #endif
1927 : : }
1928 : 0 : mlx5_os_dev_shared_handler_install(sh);
1929 [ # # ]: 0 : if (LIST_EMPTY(&dev_ctx_list)) {
1930 : 0 : err = mlx5_flow_os_init_workspace_once();
1931 [ # # ]: 0 : if (err)
1932 : 0 : goto error;
1933 : : }
1934 : 0 : err = mlx5_flow_counters_mng_init(sh);
1935 [ # # ]: 0 : if (err) {
1936 : 0 : DRV_LOG(ERR, "Fail to initialize counters manage.");
1937 : 0 : goto error;
1938 : : }
1939 : : mlx5_flow_aging_init(sh);
1940 : 0 : mlx5_flow_ipool_create(sh);
1941 : : /* Add context to the global device list. */
1942 [ # # ]: 0 : LIST_INSERT_HEAD(&dev_ctx_list, sh, next);
1943 : : rte_spinlock_init(&sh->geneve_tlv_opt_sl);
1944 : 0 : mlx5_init_shared_dev_registers(sh);
1945 : : /* Init counter pool list header and lock. */
1946 : 0 : LIST_INIT(&sh->hws_cpool_list);
1947 : : rte_spinlock_init(&sh->cpool_lock);
1948 : 0 : exit:
1949 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1950 : 0 : return sh;
1951 : 0 : error:
1952 : 0 : err = rte_errno;
1953 : 0 : pthread_mutex_destroy(&sh->txpp.mutex);
1954 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1955 : : MLX5_ASSERT(sh);
1956 : : mlx5_rxtx_uars_release(sh);
1957 : : i = 0;
1958 : : do {
1959 [ # # ]: 0 : if (sh->tis[i])
1960 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
1961 [ # # ]: 0 : } while (++i <= (uint32_t)sh->bond.n_port);
1962 [ # # ]: 0 : if (sh->td)
1963 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->td));
1964 [ # # ]: 0 : if (sh->phdev)
1965 : 0 : mlx5_physical_device_destroy(sh->phdev);
1966 : 0 : mlx5_free(sh);
1967 : 0 : rte_errno = err;
1968 : 0 : return NULL;
1969 : : }
1970 : :
1971 : : /**
1972 : : * Create LWM event_channel and interrupt handle for shared device
1973 : : * context. All rxqs sharing the device context share the event_channel.
1974 : : * A callback is registered in interrupt thread to receive the LWM event.
1975 : : *
1976 : : * @param[in] priv
1977 : : * Pointer to mlx5_priv instance.
1978 : : *
1979 : : * @return
1980 : : * 0 on success, negative with rte_errno set.
1981 : : */
1982 : : int
1983 : 0 : mlx5_lwm_setup(struct mlx5_priv *priv)
1984 : : {
1985 : : int fd_lwm;
1986 : :
1987 : 0 : pthread_mutex_init(&priv->sh->lwm_config_lock, NULL);
1988 : 0 : priv->sh->devx_channel_lwm = mlx5_os_devx_create_event_channel
1989 : 0 : (priv->sh->cdev->ctx,
1990 : : MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA);
1991 [ # # ]: 0 : if (!priv->sh->devx_channel_lwm)
1992 : 0 : goto err;
1993 : : fd_lwm = mlx5_os_get_devx_channel_fd(priv->sh->devx_channel_lwm);
1994 : 0 : priv->sh->intr_handle_lwm = mlx5_os_interrupt_handler_create
1995 : : (RTE_INTR_INSTANCE_F_SHARED, true,
1996 : : fd_lwm, mlx5_dev_interrupt_handler_lwm, priv);
1997 [ # # ]: 0 : if (!priv->sh->intr_handle_lwm)
1998 : 0 : goto err;
1999 : : return 0;
2000 : 0 : err:
2001 [ # # ]: 0 : if (priv->sh->devx_channel_lwm) {
2002 : : mlx5_os_devx_destroy_event_channel
2003 : : (priv->sh->devx_channel_lwm);
2004 : 0 : priv->sh->devx_channel_lwm = NULL;
2005 : : }
2006 : 0 : pthread_mutex_destroy(&priv->sh->lwm_config_lock);
2007 : 0 : return -rte_errno;
2008 : : }
2009 : :
2010 : : /**
2011 : : * Destroy LWM event_channel and interrupt handle for shared device
2012 : : * context before free this context. The interrupt handler is also
2013 : : * unregistered.
2014 : : *
2015 : : * @param[in] sh
2016 : : * Pointer to shared device context.
2017 : : */
2018 : : void
2019 : 0 : mlx5_lwm_unset(struct mlx5_dev_ctx_shared *sh)
2020 : : {
2021 [ # # ]: 0 : if (sh->intr_handle_lwm) {
2022 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle_lwm,
2023 : : mlx5_dev_interrupt_handler_lwm, (void *)-1);
2024 : 0 : sh->intr_handle_lwm = NULL;
2025 : : }
2026 [ # # ]: 0 : if (sh->devx_channel_lwm) {
2027 : : mlx5_os_devx_destroy_event_channel
2028 : : (sh->devx_channel_lwm);
2029 : 0 : sh->devx_channel_lwm = NULL;
2030 : : }
2031 : 0 : pthread_mutex_destroy(&sh->lwm_config_lock);
2032 : 0 : }
2033 : :
2034 : : /**
2035 : : * Free shared IB device context. Decrement counter and if zero free
2036 : : * all allocated resources and close handles.
2037 : : *
2038 : : * @param[in] sh
2039 : : * Pointer to mlx5_dev_ctx_shared object to free
2040 : : */
2041 : : void
2042 : 0 : mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
2043 : : {
2044 : : int ret;
2045 : : int i = 0;
2046 : :
2047 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
2048 : : #ifdef RTE_PMD_MLX5_DEBUG
2049 : : /* Check the object presence in the list. */
2050 : : struct mlx5_dev_ctx_shared *lctx;
2051 : :
2052 : : LIST_FOREACH(lctx, &dev_ctx_list, next)
2053 : : if (lctx == sh)
2054 : : break;
2055 : : MLX5_ASSERT(lctx);
2056 : : if (lctx != sh) {
2057 : : DRV_LOG(ERR, "Freeing non-existing shared IB context");
2058 : : goto exit;
2059 : : }
2060 : : #endif
2061 : : MLX5_ASSERT(sh);
2062 : : MLX5_ASSERT(sh->refcnt);
2063 : : /* Secondary process should not free the shared context. */
2064 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
2065 [ # # ]: 0 : if (--sh->refcnt)
2066 : 0 : goto exit;
2067 : : /* Stop watching for mempool events and unregister all mempools. */
2068 [ # # ]: 0 : if (!sh->cdev->config.mr_mempool_reg_en) {
2069 : 0 : ret = rte_mempool_event_callback_unregister
2070 : : (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh);
2071 [ # # ]: 0 : if (ret == 0)
2072 : 0 : rte_mempool_walk
2073 : : (mlx5_dev_ctx_shared_rx_mempool_unregister_cb, sh);
2074 : : }
2075 : : /* Remove context from the global device list. */
2076 [ # # ]: 0 : LIST_REMOVE(sh, next);
2077 : : /* Release resources on the last device removal. */
2078 [ # # ]: 0 : if (LIST_EMPTY(&dev_ctx_list)) {
2079 : 0 : mlx5_os_net_cleanup();
2080 : 0 : mlx5_flow_os_release_workspace();
2081 : : }
2082 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
2083 [ # # ]: 0 : if (sh->flex_parsers_dv) {
2084 : 0 : mlx5_list_destroy(sh->flex_parsers_dv);
2085 : 0 : sh->flex_parsers_dv = NULL;
2086 : : }
2087 : : /*
2088 : : * Ensure there is no async event handler installed.
2089 : : * Only primary process handles async device events.
2090 : : **/
2091 : 0 : mlx5_flow_counters_mng_close(sh);
2092 [ # # ]: 0 : if (sh->ct_mng)
2093 : 0 : mlx5_flow_aso_ct_mng_close(sh);
2094 [ # # ]: 0 : if (sh->aso_age_mng) {
2095 : 0 : mlx5_flow_aso_age_mng_close(sh);
2096 : 0 : sh->aso_age_mng = NULL;
2097 : : }
2098 [ # # ]: 0 : if (sh->mtrmng)
2099 : 0 : mlx5_aso_flow_mtrs_mng_close(sh);
2100 : 0 : mlx5_flow_ipool_destroy(sh);
2101 : 0 : mlx5_os_dev_shared_handler_uninstall(sh);
2102 : : mlx5_rxtx_uars_release(sh);
2103 : : do {
2104 [ # # ]: 0 : if (sh->tis[i])
2105 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
2106 [ # # ]: 0 : } while (++i <= sh->bond.n_port);
2107 [ # # ]: 0 : if (sh->td)
2108 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->td));
2109 : : MLX5_ASSERT(sh->geneve_tlv_option_resource == NULL);
2110 : 0 : pthread_mutex_destroy(&sh->txpp.mutex);
2111 : 0 : mlx5_lwm_unset(sh);
2112 : 0 : mlx5_physical_device_destroy(sh->phdev);
2113 : 0 : mlx5_free(sh);
2114 : 0 : return;
2115 : : exit:
2116 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
2117 : : }
2118 : :
2119 : : /**
2120 : : * Destroy table hash list.
2121 : : *
2122 : : * @param[in] priv
2123 : : * Pointer to the private device data structure.
2124 : : */
2125 : : void
2126 : 0 : mlx5_free_table_hash_list(struct mlx5_priv *priv)
2127 : : {
2128 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2129 : : struct mlx5_hlist **tbls = (priv->sh->config.dv_flow_en == 2) ?
2130 : : &sh->groups : &sh->flow_tbls;
2131 [ # # ]: 0 : if (*tbls == NULL)
2132 : : return;
2133 : 0 : mlx5_hlist_destroy(*tbls);
2134 : 0 : *tbls = NULL;
2135 : : }
2136 : :
2137 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2138 : : /**
2139 : : * Allocate HW steering group hash list.
2140 : : *
2141 : : * @param[in] priv
2142 : : * Pointer to the private device data structure.
2143 : : */
2144 : : static int
2145 : 0 : mlx5_alloc_hw_group_hash_list(struct mlx5_priv *priv)
2146 : : {
2147 : : int err = 0;
2148 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2149 : : char s[MLX5_NAME_SIZE];
2150 : :
2151 : : MLX5_ASSERT(sh);
2152 : 0 : snprintf(s, sizeof(s), "%s_flow_groups", priv->sh->ibdev_name);
2153 : 0 : sh->groups = mlx5_hlist_create
2154 : : (s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE,
2155 : : false, true, sh,
2156 : : mlx5_flow_hw_grp_create_cb,
2157 : : mlx5_flow_hw_grp_match_cb,
2158 : : mlx5_flow_hw_grp_remove_cb,
2159 : : mlx5_flow_hw_grp_clone_cb,
2160 : : mlx5_flow_hw_grp_clone_free_cb);
2161 [ # # ]: 0 : if (!sh->groups) {
2162 : 0 : DRV_LOG(ERR, "flow groups with hash creation failed.");
2163 : : err = ENOMEM;
2164 : : }
2165 : 0 : return err;
2166 : : }
2167 : : #endif
2168 : :
2169 : :
2170 : : /**
2171 : : * Initialize flow table hash list and create the root tables entry
2172 : : * for each domain.
2173 : : *
2174 : : * @param[in] priv
2175 : : * Pointer to the private device data structure.
2176 : : *
2177 : : * @return
2178 : : * Zero on success, positive error code otherwise.
2179 : : */
2180 : : int
2181 : 0 : mlx5_alloc_table_hash_list(struct mlx5_priv *priv __rte_unused)
2182 : : {
2183 : : int err = 0;
2184 : :
2185 : : /* Tables are only used in DV and DR modes. */
2186 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
2187 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2188 : : char s[MLX5_NAME_SIZE];
2189 : :
2190 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2191 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2192 : 0 : return mlx5_alloc_hw_group_hash_list(priv);
2193 : : #endif
2194 : : MLX5_ASSERT(sh);
2195 : 0 : snprintf(s, sizeof(s), "%s_flow_table", priv->sh->ibdev_name);
2196 : 0 : sh->flow_tbls = mlx5_hlist_create(s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE,
2197 : : false, true, sh,
2198 : : mlx5_flow_dv_tbl_create_cb,
2199 : : mlx5_flow_dv_tbl_match_cb,
2200 : : mlx5_flow_dv_tbl_remove_cb,
2201 : : mlx5_flow_dv_tbl_clone_cb,
2202 : : mlx5_flow_dv_tbl_clone_free_cb);
2203 [ # # ]: 0 : if (!sh->flow_tbls) {
2204 : 0 : DRV_LOG(ERR, "flow tables with hash creation failed.");
2205 : : err = ENOMEM;
2206 : 0 : return err;
2207 : : }
2208 : : #ifndef HAVE_MLX5DV_DR
2209 : : struct rte_flow_error error;
2210 : : struct rte_eth_dev *dev = &rte_eth_devices[priv->dev_data->port_id];
2211 : :
2212 : : /*
2213 : : * In case we have not DR support, the zero tables should be created
2214 : : * because DV expect to see them even if they cannot be created by
2215 : : * RDMA-CORE.
2216 : : */
2217 : : if (!mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 0, 0,
2218 : : NULL, 0, 1, 0, &error) ||
2219 : : !mlx5_flow_dv_tbl_resource_get(dev, 0, 1, 0, 0,
2220 : : NULL, 0, 1, 0, &error) ||
2221 : : !mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 1, 0,
2222 : : NULL, 0, 1, 0, &error)) {
2223 : : err = ENOMEM;
2224 : : goto error;
2225 : : }
2226 : : return err;
2227 : : error:
2228 : : mlx5_free_table_hash_list(priv);
2229 : : #endif /* HAVE_MLX5DV_DR */
2230 : : #endif
2231 : : return err;
2232 : : }
2233 : :
2234 : : /**
2235 : : * Retrieve integer value from environment variable.
2236 : : *
2237 : : * @param[in] name
2238 : : * Environment variable name.
2239 : : *
2240 : : * @return
2241 : : * Integer value, 0 if the variable is not set.
2242 : : */
2243 : : int
2244 : 0 : mlx5_getenv_int(const char *name)
2245 : : {
2246 : 0 : const char *val = getenv(name);
2247 : :
2248 [ # # ]: 0 : if (val == NULL)
2249 : : return 0;
2250 : 0 : return atoi(val);
2251 : : }
2252 : :
2253 : : /**
2254 : : * DPDK callback to add udp tunnel port
2255 : : *
2256 : : * @param[in] dev
2257 : : * A pointer to eth_dev
2258 : : * @param[in] udp_tunnel
2259 : : * A pointer to udp tunnel
2260 : : *
2261 : : * @return
2262 : : * 0 on valid udp ports and tunnels, -ENOTSUP otherwise.
2263 : : */
2264 : : int
2265 : 0 : mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev __rte_unused,
2266 : : struct rte_eth_udp_tunnel *udp_tunnel)
2267 : : {
2268 : : MLX5_ASSERT(udp_tunnel != NULL);
2269 [ # # ]: 0 : if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN &&
2270 [ # # ]: 0 : udp_tunnel->udp_port == 4789)
2271 : : return 0;
2272 [ # # ]: 0 : if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN_GPE &&
2273 [ # # ]: 0 : udp_tunnel->udp_port == 4790)
2274 : 0 : return 0;
2275 : : return -ENOTSUP;
2276 : : }
2277 : :
2278 : : /**
2279 : : * Initialize process private data structure.
2280 : : *
2281 : : * @param dev
2282 : : * Pointer to Ethernet device structure.
2283 : : *
2284 : : * @return
2285 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2286 : : */
2287 : : int
2288 : 0 : mlx5_proc_priv_init(struct rte_eth_dev *dev)
2289 : : {
2290 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2291 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2292 : : struct mlx5_proc_priv *ppriv;
2293 : : size_t ppriv_size;
2294 : :
2295 : 0 : mlx5_proc_priv_uninit(dev);
2296 : : /*
2297 : : * UAR register table follows the process private structure. BlueFlame
2298 : : * registers for Tx queues are stored in the table.
2299 : : */
2300 : 0 : ppriv_size = sizeof(struct mlx5_proc_priv) +
2301 : 0 : priv->txqs_n * sizeof(struct mlx5_uar_data);
2302 [ # # # # : 0 : ppriv = mlx5_malloc_numa_tolerant(MLX5_MEM_RTE | MLX5_MEM_ZERO, ppriv_size,
# # ]
2303 : : RTE_CACHE_LINE_SIZE, dev->device->numa_node);
2304 [ # # ]: 0 : if (!ppriv) {
2305 : 0 : rte_errno = ENOMEM;
2306 : 0 : return -rte_errno;
2307 : : }
2308 : 0 : ppriv->uar_table_sz = priv->txqs_n;
2309 : 0 : dev->process_private = ppriv;
2310 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2311 : 0 : priv->sh->pppriv = ppriv;
2312 : : /* Check and try to map HCA PCI BAR to allow reading real time. */
2313 [ # # # # ]: 0 : if (sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device))
2314 : 0 : mlx5_txpp_map_hca_bar(dev);
2315 : : return 0;
2316 : : }
2317 : :
2318 : : /**
2319 : : * Un-initialize process private data structure.
2320 : : *
2321 : : * @param dev
2322 : : * Pointer to Ethernet device structure.
2323 : : */
2324 : : void
2325 : 0 : mlx5_proc_priv_uninit(struct rte_eth_dev *dev)
2326 : : {
2327 : 0 : struct mlx5_proc_priv *ppriv = dev->process_private;
2328 : :
2329 [ # # ]: 0 : if (!ppriv)
2330 : : return;
2331 [ # # ]: 0 : if (ppriv->hca_bar)
2332 : 0 : mlx5_txpp_unmap_hca_bar(dev);
2333 : 0 : mlx5_free(dev->process_private);
2334 : 0 : dev->process_private = NULL;
2335 : : }
2336 : :
2337 : : static void
2338 : : mlx5_flow_pools_destroy(struct mlx5_priv *priv)
2339 : : {
2340 : : int i;
2341 : :
2342 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
2343 [ # # ]: 0 : if (!priv->flows[i])
2344 : 0 : continue;
2345 : 0 : mlx5_ipool_destroy(priv->flows[i]);
2346 : : }
2347 : : }
2348 : :
2349 : : /**
2350 : : * DPDK callback to close the device.
2351 : : *
2352 : : * Destroy all queues and objects, free memory.
2353 : : *
2354 : : * @param dev
2355 : : * Pointer to Ethernet device structure.
2356 : : */
2357 : : int
2358 : 0 : mlx5_dev_close(struct rte_eth_dev *dev)
2359 : : {
2360 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2361 : : struct mlx5_dev_ctx_shared *sh;
2362 : : unsigned int i;
2363 : : int ret;
2364 : :
2365 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
2366 [ # # ]: 0 : if (!priv)
2367 : 0 : DRV_LOG(WARNING, "primary process is already closed");
2368 : : /* Check if process_private released. */
2369 [ # # ]: 0 : if (!dev->process_private)
2370 : : return 0;
2371 : 0 : mlx5_tx_uar_uninit_secondary(dev);
2372 : 0 : mlx5_proc_priv_uninit(dev);
2373 : 0 : rte_eth_dev_release_port(dev);
2374 : 0 : return 0;
2375 : : }
2376 : 0 : sh = priv->sh;
2377 [ # # ]: 0 : if (!sh)
2378 : : return 0;
2379 [ # # ]: 0 : if (priv->shared_refcnt) {
2380 : 0 : DRV_LOG(ERR, "port %u is shared host in use (%u)",
2381 : : dev->data->port_id, priv->shared_refcnt);
2382 : 0 : rte_errno = EBUSY;
2383 : 0 : return -EBUSY;
2384 : : }
2385 : 0 : DRV_LOG(DEBUG, "port %u closing device \"%s\"",
2386 : : dev->data->port_id, sh->ibdev_name);
2387 : : /*
2388 : : * If default mreg copy action is removed at the stop stage,
2389 : : * the search will return none and nothing will be done anymore.
2390 : : */
2391 : 0 : mlx5_flow_stop_default(dev);
2392 : 0 : mlx5_traffic_disable(dev);
2393 : : /*
2394 : : * If all the flows are already flushed in the device stop stage,
2395 : : * then this will return directly without any action.
2396 : : */
2397 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
2398 : 0 : mlx5_action_handle_flush(dev);
2399 : 0 : mlx5_flow_meter_flush(dev, NULL);
2400 : : /* Prevent crashes when queues are still in use. */
2401 : 0 : dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
2402 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
2403 : : rte_wmb();
2404 : : /* Disable datapath on secondary process. */
2405 : 0 : mlx5_mp_os_req_stop_rxtx(dev);
2406 : : /* Free the eCPRI flex parser resource. */
2407 : 0 : mlx5_flex_parser_ecpri_release(dev);
2408 : 0 : mlx5_flex_item_port_cleanup(dev);
2409 [ # # ]: 0 : if (priv->representor) {
2410 : : /* Each representor has a dedicated interrupts handler */
2411 : 0 : rte_intr_instance_free(dev->intr_handle);
2412 : 0 : dev->intr_handle = NULL;
2413 : : }
2414 : 0 : mlx5_indirect_list_handles_release(dev);
2415 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2416 : 0 : mlx5_nta_sample_context_free(dev);
2417 : 0 : mlx5_flow_hw_destroy_vport_action(dev);
2418 : : /* dr context will be closed after mlx5_os_free_shared_dr. */
2419 : 0 : mlx5_flow_hw_resource_release(dev);
2420 : 0 : mlx5_flow_hw_clear_port_info(dev);
2421 [ # # ]: 0 : if (priv->tlv_options != NULL) {
2422 : : /* Free the GENEVE TLV parser resource. */
2423 : 0 : claim_zero(mlx5_geneve_tlv_options_destroy(priv->tlv_options, sh->phdev));
2424 : 0 : priv->tlv_options = NULL;
2425 : : }
2426 [ # # ]: 0 : if (priv->ptype_rss_groups) {
2427 : 0 : mlx5_ipool_destroy(priv->ptype_rss_groups);
2428 : 0 : priv->ptype_rss_groups = NULL;
2429 : : }
2430 : : #endif
2431 [ # # ]: 0 : if (priv->rxq_privs != NULL) {
2432 : : /* XXX race condition if mlx5_rx_burst() is still running. */
2433 : 0 : rte_delay_us_sleep(1000);
2434 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i)
2435 : 0 : mlx5_rxq_release(dev, i);
2436 : 0 : priv->rxqs_n = 0;
2437 : 0 : mlx5_free(priv->rxq_privs);
2438 : 0 : priv->rxq_privs = NULL;
2439 : : }
2440 [ # # # # ]: 0 : if (priv->txqs != NULL && dev->data->tx_queues != NULL) {
2441 : : /* XXX race condition if mlx5_tx_burst() is still running. */
2442 : 0 : rte_delay_us_sleep(1000);
2443 [ # # ]: 0 : for (i = 0; (i != priv->txqs_n); ++i)
2444 : 0 : mlx5_txq_release(dev, i);
2445 : 0 : priv->txqs_n = 0;
2446 : 0 : priv->txqs = NULL;
2447 : : }
2448 : 0 : mlx5_proc_priv_uninit(dev);
2449 [ # # ]: 0 : if (priv->drop_queue.hrxq)
2450 : 0 : mlx5_drop_action_destroy(dev);
2451 : 0 : mlx5_q_counters_destroy(dev);
2452 : 0 : mlx5_mprq_free_mp(dev);
2453 : 0 : mlx5_os_free_shared_dr(priv);
2454 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2455 [ # # ]: 0 : if (priv->dr_ctx) {
2456 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
2457 : 0 : priv->dr_ctx = NULL;
2458 : : }
2459 : : #endif
2460 [ # # ]: 0 : if (priv->rss_conf.rss_key != NULL)
2461 : 0 : mlx5_free(priv->rss_conf.rss_key);
2462 [ # # ]: 0 : if (priv->reta_idx != NULL)
2463 : 0 : mlx5_free(priv->reta_idx);
2464 [ # # ]: 0 : if (sh->dev_cap.vf)
2465 : 0 : mlx5_os_mac_addr_flush(dev);
2466 [ # # ]: 0 : if (priv->nl_socket_route >= 0)
2467 : 0 : close(priv->nl_socket_route);
2468 [ # # ]: 0 : if (priv->nl_socket_rdma >= 0)
2469 : 0 : close(priv->nl_socket_rdma);
2470 [ # # ]: 0 : if (priv->vmwa_context)
2471 : 0 : mlx5_vlan_vmwa_exit(priv->vmwa_context);
2472 : 0 : ret = mlx5_hrxq_verify(dev);
2473 [ # # ]: 0 : if (ret)
2474 : 0 : DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
2475 : : dev->data->port_id);
2476 : 0 : ret = mlx5_ind_table_obj_verify(dev);
2477 [ # # ]: 0 : if (ret)
2478 : 0 : DRV_LOG(WARNING, "port %u some indirection table still remain",
2479 : : dev->data->port_id);
2480 : 0 : ret = mlx5_rxq_obj_verify(dev);
2481 [ # # ]: 0 : if (ret)
2482 : 0 : DRV_LOG(WARNING, "port %u some Rx queue objects still remain",
2483 : : dev->data->port_id);
2484 : 0 : ret = mlx5_ext_rxq_verify(dev);
2485 [ # # ]: 0 : if (ret)
2486 : 0 : DRV_LOG(WARNING, "Port %u some external RxQ still remain.",
2487 : : dev->data->port_id);
2488 : 0 : ret = mlx5_rxq_verify(dev);
2489 [ # # ]: 0 : if (ret)
2490 : 0 : DRV_LOG(WARNING, "port %u some Rx queues still remain",
2491 : : dev->data->port_id);
2492 : 0 : ret = mlx5_txq_obj_verify(dev);
2493 [ # # ]: 0 : if (ret)
2494 : 0 : DRV_LOG(WARNING, "port %u some Verbs Tx queue still remain",
2495 : : dev->data->port_id);
2496 : 0 : ret = mlx5_ext_txq_verify(dev);
2497 [ # # ]: 0 : if (ret)
2498 : 0 : DRV_LOG(WARNING, "Port %u some external TxQ still remain.",
2499 : : dev->data->port_id);
2500 : 0 : ret = mlx5_txq_verify(dev);
2501 [ # # ]: 0 : if (ret)
2502 : 0 : DRV_LOG(WARNING, "port %u some Tx queues still remain",
2503 : : dev->data->port_id);
2504 : 0 : ret = mlx5_flow_verify(dev);
2505 [ # # ]: 0 : if (ret)
2506 : 0 : DRV_LOG(WARNING, "port %u some flows still remain",
2507 : : dev->data->port_id);
2508 [ # # ]: 0 : if (priv->hrxqs)
2509 : 0 : mlx5_list_destroy(priv->hrxqs);
2510 : 0 : mlx5_free(priv->ext_rxqs);
2511 : 0 : mlx5_free(priv->ext_txqs);
2512 : 0 : sh->port[priv->dev_port - 1].nl_ih_port_id = RTE_MAX_ETHPORTS;
2513 : : /*
2514 : : * The interrupt handler port id must be reset before priv is reset
2515 : : * since 'mlx5_dev_interrupt_nl_cb' uses priv.
2516 : : */
2517 : 0 : rte_io_wmb();
2518 : : /*
2519 : : * Free the shared context in last turn, because the cleanup
2520 : : * routines above may use some shared fields, like
2521 : : * mlx5_os_mac_addr_flush() uses ibdev_path for retrieving
2522 : : * ifindex if Netlink fails.
2523 : : */
2524 : 0 : mlx5_free_shared_dev_ctx(sh);
2525 [ # # ]: 0 : if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
2526 : : unsigned int c = 0;
2527 : : uint16_t port_id;
2528 : :
2529 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
2530 : 0 : struct mlx5_priv *opriv =
2531 : 0 : rte_eth_devices[port_id].data->dev_private;
2532 : :
2533 [ # # ]: 0 : if (!opriv ||
2534 [ # # ]: 0 : opriv->domain_id != priv->domain_id ||
2535 [ # # ]: 0 : &rte_eth_devices[port_id] == dev)
2536 : : continue;
2537 : : ++c;
2538 : : break;
2539 : : }
2540 [ # # ]: 0 : if (!c)
2541 : 0 : claim_zero(rte_eth_switch_domain_free(priv->domain_id));
2542 : : }
2543 : : mlx5_flow_pools_destroy(priv);
2544 : : memset(priv, 0, sizeof(*priv));
2545 : 0 : priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
2546 : : /*
2547 : : * Reset mac_addrs to NULL such that it is not freed as part of
2548 : : * rte_eth_dev_release_port(). mac_addrs is part of dev_private so
2549 : : * it is freed when dev_private is freed.
2550 : : */
2551 : 0 : dev->data->mac_addrs = NULL;
2552 : 0 : return 0;
2553 : : }
2554 : :
2555 : : const struct eth_dev_ops mlx5_dev_ops = {
2556 : : .dev_configure = mlx5_dev_configure,
2557 : : .dev_start = mlx5_dev_start,
2558 : : .dev_stop = mlx5_dev_stop,
2559 : : .dev_set_link_down = mlx5_set_link_down,
2560 : : .dev_set_link_up = mlx5_set_link_up,
2561 : : .dev_close = mlx5_dev_close,
2562 : : .promiscuous_enable = mlx5_promiscuous_enable,
2563 : : .promiscuous_disable = mlx5_promiscuous_disable,
2564 : : .allmulticast_enable = mlx5_allmulticast_enable,
2565 : : .allmulticast_disable = mlx5_allmulticast_disable,
2566 : : .link_update = mlx5_link_update,
2567 : : .stats_get = mlx5_stats_get,
2568 : : .stats_reset = mlx5_stats_reset,
2569 : : .xstats_get = mlx5_xstats_get,
2570 : : .xstats_reset = mlx5_xstats_reset,
2571 : : .xstats_get_names = mlx5_xstats_get_names,
2572 : :
2573 : : .xstats_enable = mlx5_xstats_enable,
2574 : : .xstats_disable = mlx5_xstats_disable,
2575 : : .xstats_query_state = mlx5_xstats_query_state,
2576 : :
2577 : : .fw_version_get = mlx5_fw_version_get,
2578 : : .dev_infos_get = mlx5_dev_infos_get,
2579 : : .representor_info_get = mlx5_representor_info_get,
2580 : : .read_clock = mlx5_txpp_read_clock,
2581 : : .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
2582 : : .vlan_filter_set = mlx5_vlan_filter_set,
2583 : : .rx_queue_setup = mlx5_rx_queue_setup,
2584 : : .rx_queue_avail_thresh_set = mlx5_rx_queue_lwm_set,
2585 : : .rx_queue_avail_thresh_query = mlx5_rx_queue_lwm_query,
2586 : : .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
2587 : : .tx_queue_setup = mlx5_tx_queue_setup,
2588 : : .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
2589 : : .rx_queue_release = mlx5_rx_queue_release,
2590 : : .tx_queue_release = mlx5_tx_queue_release,
2591 : : .rx_queue_start = mlx5_rx_queue_start,
2592 : : .rx_queue_stop = mlx5_rx_queue_stop,
2593 : : .tx_queue_start = mlx5_tx_queue_start,
2594 : : .tx_queue_stop = mlx5_tx_queue_stop,
2595 : : .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
2596 : : .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
2597 : : .mac_addr_remove = mlx5_mac_addr_remove,
2598 : : .mac_addr_add = mlx5_mac_addr_add,
2599 : : .mac_addr_set = mlx5_mac_addr_set,
2600 : : .set_mc_addr_list = mlx5_set_mc_addr_list,
2601 : : .mtu_set = mlx5_dev_set_mtu,
2602 : : .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
2603 : : .vlan_offload_set = mlx5_vlan_offload_set,
2604 : : .reta_update = mlx5_dev_rss_reta_update,
2605 : : .reta_query = mlx5_dev_rss_reta_query,
2606 : : .rss_hash_update = mlx5_rss_hash_update,
2607 : : .rss_hash_conf_get = mlx5_rss_hash_conf_get,
2608 : : .flow_ops_get = mlx5_flow_ops_get,
2609 : : .rxq_info_get = mlx5_rxq_info_get,
2610 : : .txq_info_get = mlx5_txq_info_get,
2611 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2612 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2613 : : .rx_queue_intr_enable = mlx5_rx_intr_enable,
2614 : : .rx_queue_intr_disable = mlx5_rx_intr_disable,
2615 : : .is_removed = mlx5_is_removed,
2616 : : .udp_tunnel_port_add = mlx5_udp_tunnel_port_add,
2617 : : .get_module_info = mlx5_get_module_info,
2618 : : .get_module_eeprom = mlx5_get_module_eeprom,
2619 : : .hairpin_cap_get = mlx5_hairpin_cap_get,
2620 : : .mtr_ops_get = mlx5_flow_meter_ops_get,
2621 : : .hairpin_bind = mlx5_hairpin_bind,
2622 : : .hairpin_unbind = mlx5_hairpin_unbind,
2623 : : .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
2624 : : .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
2625 : : .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
2626 : : .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
2627 : : .get_monitor_addr = mlx5_get_monitor_addr,
2628 : : .count_aggr_ports = mlx5_count_aggr_ports,
2629 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2630 : : .rx_metadata_negotiate = mlx5_flow_rx_metadata_negotiate,
2631 : : .get_restore_flags = mlx5_get_restore_flags,
2632 : : };
2633 : :
2634 : : /* Available operations from secondary process. */
2635 : : const struct eth_dev_ops mlx5_dev_sec_ops = {
2636 : : .stats_get = mlx5_stats_get,
2637 : : .stats_reset = mlx5_stats_reset,
2638 : : .xstats_get = mlx5_xstats_get,
2639 : : .xstats_reset = mlx5_xstats_reset,
2640 : : .xstats_get_names = mlx5_xstats_get_names,
2641 : : .fw_version_get = mlx5_fw_version_get,
2642 : : .dev_infos_get = mlx5_dev_infos_get,
2643 : : .representor_info_get = mlx5_representor_info_get,
2644 : : .read_clock = mlx5_txpp_read_clock,
2645 : : .rx_queue_start = mlx5_rx_queue_start,
2646 : : .rx_queue_stop = mlx5_rx_queue_stop,
2647 : : .tx_queue_start = mlx5_tx_queue_start,
2648 : : .tx_queue_stop = mlx5_tx_queue_stop,
2649 : : .rxq_info_get = mlx5_rxq_info_get,
2650 : : .txq_info_get = mlx5_txq_info_get,
2651 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2652 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2653 : : .get_module_info = mlx5_get_module_info,
2654 : : .get_module_eeprom = mlx5_get_module_eeprom,
2655 : : .count_aggr_ports = mlx5_count_aggr_ports,
2656 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2657 : : .rx_metadata_negotiate = mlx5_flow_rx_metadata_negotiate,
2658 : : };
2659 : :
2660 : : /* Available operations in flow isolated mode. */
2661 : : const struct eth_dev_ops mlx5_dev_ops_isolate = {
2662 : : .dev_configure = mlx5_dev_configure,
2663 : : .dev_start = mlx5_dev_start,
2664 : : .dev_stop = mlx5_dev_stop,
2665 : : .dev_set_link_down = mlx5_set_link_down,
2666 : : .dev_set_link_up = mlx5_set_link_up,
2667 : : .dev_close = mlx5_dev_close,
2668 : : .promiscuous_enable = mlx5_promiscuous_enable,
2669 : : .promiscuous_disable = mlx5_promiscuous_disable,
2670 : : .allmulticast_enable = mlx5_allmulticast_enable,
2671 : : .allmulticast_disable = mlx5_allmulticast_disable,
2672 : : .link_update = mlx5_link_update,
2673 : : .stats_get = mlx5_stats_get,
2674 : : .stats_reset = mlx5_stats_reset,
2675 : : .xstats_get = mlx5_xstats_get,
2676 : : .xstats_reset = mlx5_xstats_reset,
2677 : : .xstats_get_names = mlx5_xstats_get_names,
2678 : : .fw_version_get = mlx5_fw_version_get,
2679 : : .dev_infos_get = mlx5_dev_infos_get,
2680 : : .representor_info_get = mlx5_representor_info_get,
2681 : : .read_clock = mlx5_txpp_read_clock,
2682 : : .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
2683 : : .vlan_filter_set = mlx5_vlan_filter_set,
2684 : : .rx_queue_setup = mlx5_rx_queue_setup,
2685 : : .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
2686 : : .tx_queue_setup = mlx5_tx_queue_setup,
2687 : : .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
2688 : : .rx_queue_release = mlx5_rx_queue_release,
2689 : : .tx_queue_release = mlx5_tx_queue_release,
2690 : : .rx_queue_start = mlx5_rx_queue_start,
2691 : : .rx_queue_stop = mlx5_rx_queue_stop,
2692 : : .tx_queue_start = mlx5_tx_queue_start,
2693 : : .tx_queue_stop = mlx5_tx_queue_stop,
2694 : : .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
2695 : : .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
2696 : : .mac_addr_remove = mlx5_mac_addr_remove,
2697 : : .mac_addr_add = mlx5_mac_addr_add,
2698 : : .mac_addr_set = mlx5_mac_addr_set,
2699 : : .set_mc_addr_list = mlx5_set_mc_addr_list,
2700 : : .mtu_set = mlx5_dev_set_mtu,
2701 : : .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
2702 : : .vlan_offload_set = mlx5_vlan_offload_set,
2703 : : .flow_ops_get = mlx5_flow_ops_get,
2704 : : .rxq_info_get = mlx5_rxq_info_get,
2705 : : .txq_info_get = mlx5_txq_info_get,
2706 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2707 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2708 : : .rx_queue_intr_enable = mlx5_rx_intr_enable,
2709 : : .rx_queue_intr_disable = mlx5_rx_intr_disable,
2710 : : .is_removed = mlx5_is_removed,
2711 : : .get_module_info = mlx5_get_module_info,
2712 : : .get_module_eeprom = mlx5_get_module_eeprom,
2713 : : .hairpin_cap_get = mlx5_hairpin_cap_get,
2714 : : .mtr_ops_get = mlx5_flow_meter_ops_get,
2715 : : .hairpin_bind = mlx5_hairpin_bind,
2716 : : .hairpin_unbind = mlx5_hairpin_unbind,
2717 : : .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
2718 : : .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
2719 : : .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
2720 : : .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
2721 : : .get_monitor_addr = mlx5_get_monitor_addr,
2722 : : .count_aggr_ports = mlx5_count_aggr_ports,
2723 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2724 : : .get_restore_flags = mlx5_get_restore_flags,
2725 : : };
2726 : :
2727 : : /**
2728 : : * Verify and store value for device argument.
2729 : : *
2730 : : * @param[in] key
2731 : : * Key argument to verify.
2732 : : * @param[in] val
2733 : : * Value associated with key.
2734 : : * @param opaque
2735 : : * User data.
2736 : : *
2737 : : * @return
2738 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2739 : : */
2740 : : static int
2741 : 0 : mlx5_port_args_check_handler(const char *key, const char *val, void *opaque)
2742 : : {
2743 : : struct mlx5_port_config *config = opaque;
2744 : : signed long tmp;
2745 : :
2746 : : /* No-op, port representors are processed in mlx5_dev_spawn(). */
2747 [ # # ]: 0 : if (!strcmp(MLX5_REPRESENTOR, key))
2748 : : return 0;
2749 : 0 : errno = 0;
2750 : 0 : tmp = strtol(val, NULL, 0);
2751 [ # # ]: 0 : if (errno) {
2752 : 0 : rte_errno = errno;
2753 : 0 : DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
2754 : 0 : return -rte_errno;
2755 : : }
2756 [ # # ]: 0 : if (tmp < 0) {
2757 : : /* Negative values are acceptable for some keys only. */
2758 : 0 : rte_errno = EINVAL;
2759 : 0 : DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
2760 : 0 : return -rte_errno;
2761 : : }
2762 [ # # ]: 0 : if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
2763 [ # # ]: 0 : if ((tmp & ~MLX5_RXQ_ENH_CQE_COMP_MASK) >
2764 : : MLX5_CQE_RESP_FORMAT_L34H_STRIDX) {
2765 : 0 : DRV_LOG(ERR, "invalid CQE compression "
2766 : : "format parameter");
2767 : 0 : rte_errno = EINVAL;
2768 : 0 : return -rte_errno;
2769 : : }
2770 : 0 : config->cqe_comp = !!tmp;
2771 : 0 : config->cqe_comp_fmt = tmp & ~MLX5_RXQ_ENH_CQE_COMP_MASK;
2772 : 0 : config->enh_cqe_comp = !!(tmp & MLX5_RXQ_ENH_CQE_COMP_MASK);
2773 [ # # ]: 0 : } else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
2774 : 0 : config->hw_padding = !!tmp;
2775 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
2776 : 0 : config->mprq.enabled = !!tmp;
2777 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_NUM, key) == 0) {
2778 : 0 : config->mprq.log_stride_num = tmp;
2779 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_SIZE, key) == 0) {
2780 : 0 : config->mprq.log_stride_size = tmp;
2781 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_MAX_MEMCPY_LEN, key) == 0) {
2782 : 0 : config->mprq.max_memcpy_len = tmp;
2783 [ # # ]: 0 : } else if (strcmp(MLX5_RXQS_MIN_MPRQ, key) == 0) {
2784 : 0 : config->mprq.min_rxqs_num = tmp;
2785 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
2786 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter,"
2787 : : " converted to txq_inline_max", key);
2788 : 0 : config->txq_inline_max = tmp;
2789 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MAX, key) == 0) {
2790 : 0 : config->txq_inline_max = tmp;
2791 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MIN, key) == 0) {
2792 : 0 : config->txq_inline_min = tmp;
2793 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MPW, key) == 0) {
2794 : 0 : config->txq_inline_mpw = tmp;
2795 [ # # ]: 0 : } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
2796 : 0 : config->txqs_inline = tmp;
2797 [ # # ]: 0 : } else if (strcmp(MLX5_TXQS_MAX_VEC, key) == 0) {
2798 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2799 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
2800 : 0 : config->mps = !!tmp;
2801 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MPW_HDR_DSEG_EN, key) == 0) {
2802 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2803 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MAX_INLINE_LEN, key) == 0) {
2804 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter,"
2805 : : " converted to txq_inline_mpw", key);
2806 : 0 : config->txq_inline_mpw = tmp;
2807 [ # # ]: 0 : } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
2808 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2809 [ # # ]: 0 : } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
2810 : 0 : config->rx_vec_en = !!tmp;
2811 [ # # ]: 0 : } else if (strcmp(MLX5_MAX_DUMP_FILES_NUM, key) == 0) {
2812 : 0 : config->max_dump_files_num = tmp;
2813 [ # # ]: 0 : } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) {
2814 : 0 : config->lro_timeout = tmp;
2815 [ # # ]: 0 : } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) {
2816 : 0 : config->log_hp_size = tmp;
2817 [ # # ]: 0 : } else if (strcmp(MLX5_DELAY_DROP, key) == 0) {
2818 : 0 : config->std_delay_drop = !!(tmp & MLX5_DELAY_DROP_STANDARD);
2819 : 0 : config->hp_delay_drop = !!(tmp & MLX5_DELAY_DROP_HAIRPIN);
2820 : : }
2821 : : return 0;
2822 : : }
2823 : :
2824 : : /**
2825 : : * Parse user port parameters and adjust them according to device capabilities.
2826 : : *
2827 : : * @param priv
2828 : : * Pointer to shared device context.
2829 : : * @param mkvlist
2830 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
2831 : : * @param config
2832 : : * Pointer to port configuration structure.
2833 : : *
2834 : : * @return
2835 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2836 : : */
2837 : : int
2838 : 0 : mlx5_port_args_config(struct mlx5_priv *priv, struct mlx5_kvargs_ctrl *mkvlist,
2839 : : struct mlx5_port_config *config)
2840 : : {
2841 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2842 : : struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
2843 : 0 : bool devx = priv->sh->cdev->config.devx;
2844 [ # # ]: 0 : const char **params = (const char *[]){
2845 : : MLX5_RXQ_CQE_COMP_EN,
2846 : : MLX5_RXQ_PKT_PAD_EN,
2847 : : MLX5_RX_MPRQ_EN,
2848 : : MLX5_RX_MPRQ_LOG_STRIDE_NUM,
2849 : : MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
2850 : : MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
2851 : : MLX5_RXQS_MIN_MPRQ,
2852 : : MLX5_TXQ_INLINE,
2853 : : MLX5_TXQ_INLINE_MIN,
2854 : : MLX5_TXQ_INLINE_MAX,
2855 : : MLX5_TXQ_INLINE_MPW,
2856 : : MLX5_TXQS_MIN_INLINE,
2857 : : MLX5_TXQS_MAX_VEC,
2858 : : MLX5_TXQ_MPW_EN,
2859 : : MLX5_TXQ_MPW_HDR_DSEG_EN,
2860 : : MLX5_TXQ_MAX_INLINE_LEN,
2861 : : MLX5_TX_VEC_EN,
2862 : : MLX5_RX_VEC_EN,
2863 : : MLX5_REPRESENTOR,
2864 : : MLX5_MAX_DUMP_FILES_NUM,
2865 : : MLX5_LRO_TIMEOUT_USEC,
2866 : : MLX5_HP_BUF_SIZE,
2867 : : MLX5_DELAY_DROP,
2868 : : NULL,
2869 : : };
2870 : : int ret = 0;
2871 : :
2872 : : /* Default configuration. */
2873 : : memset(config, 0, sizeof(*config));
2874 : 0 : config->mps = MLX5_ARG_UNSET;
2875 : 0 : config->cqe_comp = 1;
2876 : 0 : config->rx_vec_en = 1;
2877 : 0 : config->txq_inline_max = MLX5_ARG_UNSET;
2878 : 0 : config->txq_inline_min = MLX5_ARG_UNSET;
2879 : 0 : config->txq_inline_mpw = MLX5_ARG_UNSET;
2880 : 0 : config->txqs_inline = MLX5_ARG_UNSET;
2881 : 0 : config->mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN;
2882 : 0 : config->mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS;
2883 : 0 : config->mprq.log_stride_num = MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM;
2884 : 0 : config->mprq.log_stride_size = MLX5_ARG_UNSET;
2885 : 0 : config->log_hp_size = MLX5_ARG_UNSET;
2886 : : config->std_delay_drop = 0;
2887 : : config->hp_delay_drop = 0;
2888 [ # # ]: 0 : if (mkvlist != NULL) {
2889 : : /* Process parameters. */
2890 : 0 : ret = mlx5_kvargs_process(mkvlist, params,
2891 : : mlx5_port_args_check_handler, config);
2892 [ # # ]: 0 : if (ret) {
2893 : 0 : DRV_LOG(ERR, "Failed to process port arguments: %s",
2894 : : strerror(rte_errno));
2895 : 0 : return -rte_errno;
2896 : : }
2897 : : }
2898 : : /* Adjust parameters according to device capabilities. */
2899 [ # # # # ]: 0 : if (config->hw_padding && !dev_cap->hw_padding) {
2900 : 0 : DRV_LOG(DEBUG, "Rx end alignment padding isn't supported.");
2901 : 0 : config->hw_padding = 0;
2902 [ # # ]: 0 : } else if (config->hw_padding) {
2903 : 0 : DRV_LOG(DEBUG, "Rx end alignment padding is enabled.");
2904 : : }
2905 : : /*
2906 : : * MPW is disabled by default, while the Enhanced MPW is enabled
2907 : : * by default.
2908 : : */
2909 [ # # ]: 0 : if (config->mps == MLX5_ARG_UNSET)
2910 : 0 : config->mps = (dev_cap->mps == MLX5_MPW_ENHANCED) ?
2911 [ # # ]: 0 : MLX5_MPW_ENHANCED : MLX5_MPW_DISABLED;
2912 : : else
2913 [ # # ]: 0 : config->mps = config->mps ? dev_cap->mps : MLX5_MPW_DISABLED;
2914 [ # # # # : 0 : DRV_LOG(INFO, "%sMPS is %s",
# # ]
2915 : : config->mps == MLX5_MPW_ENHANCED ? "enhanced " :
2916 : : config->mps == MLX5_MPW ? "legacy " : "",
2917 : : config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled");
2918 [ # # ]: 0 : if (priv->sh->config.lro_allowed) {
2919 : : /*
2920 : : * If LRO timeout is not configured by application,
2921 : : * use the minimal supported value.
2922 : : */
2923 [ # # ]: 0 : if (!config->lro_timeout)
2924 : 0 : config->lro_timeout =
2925 : 0 : hca_attr->lro_timer_supported_periods[0];
2926 : 0 : DRV_LOG(DEBUG, "LRO session timeout set to %d usec.",
2927 : : config->lro_timeout);
2928 : : }
2929 [ # # # # ]: 0 : if (config->cqe_comp && !dev_cap->cqe_comp) {
2930 : 0 : DRV_LOG(WARNING, "Rx CQE 128B compression is not supported.");
2931 : 0 : config->cqe_comp = 0;
2932 : : }
2933 [ # # # # ]: 0 : if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_FTAG_STRIDX &&
2934 [ # # ]: 0 : (!devx || !hca_attr->mini_cqe_resp_flow_tag)) {
2935 : 0 : DRV_LOG(WARNING,
2936 : : "Flow Tag CQE compression format isn't supported.");
2937 : 0 : config->cqe_comp = 0;
2938 : : }
2939 [ # # # # ]: 0 : if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_L34H_STRIDX &&
2940 [ # # ]: 0 : (!devx || !hca_attr->mini_cqe_resp_l3_l4_tag)) {
2941 : 0 : DRV_LOG(WARNING,
2942 : : "L3/L4 Header CQE compression format isn't supported.");
2943 : 0 : config->cqe_comp = 0;
2944 : : }
2945 [ # # # # ]: 0 : if (config->enh_cqe_comp && !hca_attr->enhanced_cqe_compression) {
2946 : 0 : DRV_LOG(WARNING,
2947 : : "Enhanced CQE compression isn't supported.");
2948 : 0 : config->enh_cqe_comp = 0;
2949 : : }
2950 [ # # # # ]: 0 : DRV_LOG(DEBUG, "%sRx CQE compression is %ssupported.",
2951 : : config->enh_cqe_comp ? "Enhanced " : "",
2952 : : config->cqe_comp ? "" : "not ");
2953 [ # # ]: 0 : if ((config->std_delay_drop || config->hp_delay_drop) &&
2954 [ # # ]: 0 : !dev_cap->rq_delay_drop_en) {
2955 : 0 : config->std_delay_drop = 0;
2956 : 0 : config->hp_delay_drop = 0;
2957 : 0 : DRV_LOG(WARNING, "dev_port-%u: Rxq delay drop isn't supported.",
2958 : : priv->dev_port);
2959 : : }
2960 [ # # # # ]: 0 : if (config->mprq.enabled && !priv->sh->dev_cap.mprq.enabled) {
2961 : 0 : DRV_LOG(WARNING, "Multi-Packet RQ isn't supported.");
2962 : 0 : config->mprq.enabled = 0;
2963 : : }
2964 [ # # ]: 0 : if (config->max_dump_files_num == 0)
2965 : 0 : config->max_dump_files_num = 128;
2966 : : /* Detect minimal data bytes to inline. */
2967 : 0 : mlx5_set_min_inline(priv);
2968 [ # # ]: 0 : DRV_LOG(DEBUG, "VLAN insertion in WQE is %ssupported.",
2969 : : config->hw_vlan_insert ? "" : "not ");
2970 : 0 : DRV_LOG(DEBUG, "\"rxq_pkt_pad_en\" is %u.", config->hw_padding);
2971 : 0 : DRV_LOG(DEBUG, "\"rxq_cqe_comp_en\" is %u.", config->cqe_comp);
2972 : 0 : DRV_LOG(DEBUG, "\"cqe_comp_fmt\" is %u.", config->cqe_comp_fmt);
2973 : 0 : DRV_LOG(DEBUG, "\"enh_cqe_comp\" is %u.", config->enh_cqe_comp);
2974 : 0 : DRV_LOG(DEBUG, "\"rx_vec_en\" is %u.", config->rx_vec_en);
2975 : 0 : DRV_LOG(DEBUG, "Standard \"delay_drop\" is %u.",
2976 : : config->std_delay_drop);
2977 : 0 : DRV_LOG(DEBUG, "Hairpin \"delay_drop\" is %u.", config->hp_delay_drop);
2978 : 0 : DRV_LOG(DEBUG, "\"max_dump_files_num\" is %u.",
2979 : : config->max_dump_files_num);
2980 : 0 : DRV_LOG(DEBUG, "\"log_hp_size\" is %u.", config->log_hp_size);
2981 : 0 : DRV_LOG(DEBUG, "\"mprq_en\" is %u.", config->mprq.enabled);
2982 : 0 : DRV_LOG(DEBUG, "\"mprq_log_stride_num\" is %u.",
2983 : : config->mprq.log_stride_num);
2984 : 0 : DRV_LOG(DEBUG, "\"mprq_log_stride_size\" is %u.",
2985 : : config->mprq.log_stride_size);
2986 : 0 : DRV_LOG(DEBUG, "\"mprq_max_memcpy_len\" is %u.",
2987 : : config->mprq.max_memcpy_len);
2988 : 0 : DRV_LOG(DEBUG, "\"rxqs_min_mprq\" is %u.", config->mprq.min_rxqs_num);
2989 : 0 : DRV_LOG(DEBUG, "\"lro_timeout_usec\" is %u.", config->lro_timeout);
2990 : 0 : DRV_LOG(DEBUG, "\"txq_mpw_en\" is %d.", config->mps);
2991 : 0 : DRV_LOG(DEBUG, "\"txqs_min_inline\" is %d.", config->txqs_inline);
2992 : 0 : DRV_LOG(DEBUG, "\"txq_inline_min\" is %d.", config->txq_inline_min);
2993 : 0 : DRV_LOG(DEBUG, "\"txq_inline_max\" is %d.", config->txq_inline_max);
2994 : 0 : DRV_LOG(DEBUG, "\"txq_inline_mpw\" is %d.", config->txq_inline_mpw);
2995 : 0 : return 0;
2996 : : }
2997 : :
2998 : : /**
2999 : : * Print the key for device argument.
3000 : : *
3001 : : * It is "dummy" handler whose whole purpose is to enable using
3002 : : * mlx5_kvargs_process() function which set devargs as used.
3003 : : *
3004 : : * @param key
3005 : : * Key argument.
3006 : : * @param val
3007 : : * Value associated with key, unused.
3008 : : * @param opaque
3009 : : * Unused, can be NULL.
3010 : : *
3011 : : * @return
3012 : : * 0 on success, function cannot fail.
3013 : : */
3014 : : static int
3015 : 0 : mlx5_dummy_handler(const char *key, const char *val, void *opaque)
3016 : : {
3017 : 0 : DRV_LOG(DEBUG, "\tKey: \"%s\" is set as used.", key);
3018 : : RTE_SET_USED(opaque);
3019 : : RTE_SET_USED(val);
3020 : 0 : return 0;
3021 : : }
3022 : :
3023 : : /**
3024 : : * Set requested devargs as used when device is already spawned.
3025 : : *
3026 : : * It is necessary since it is valid to ask probe again for existing device,
3027 : : * if its devargs don't assign as used, mlx5_kvargs_validate() will fail.
3028 : : *
3029 : : * @param name
3030 : : * Name of the existing device.
3031 : : * @param port_id
3032 : : * Port identifier of the device.
3033 : : * @param mkvlist
3034 : : * Pointer to mlx5 kvargs control to sign as used.
3035 : : */
3036 : : void
3037 : 0 : mlx5_port_args_set_used(const char *name, uint16_t port_id,
3038 : : struct mlx5_kvargs_ctrl *mkvlist)
3039 : : {
3040 : 0 : const char **params = (const char *[]){
3041 : : MLX5_RXQ_CQE_COMP_EN,
3042 : : MLX5_RXQ_PKT_PAD_EN,
3043 : : MLX5_RX_MPRQ_EN,
3044 : : MLX5_RX_MPRQ_LOG_STRIDE_NUM,
3045 : : MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
3046 : : MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
3047 : : MLX5_RXQS_MIN_MPRQ,
3048 : : MLX5_TXQ_INLINE,
3049 : : MLX5_TXQ_INLINE_MIN,
3050 : : MLX5_TXQ_INLINE_MAX,
3051 : : MLX5_TXQ_INLINE_MPW,
3052 : : MLX5_TXQS_MIN_INLINE,
3053 : : MLX5_TXQS_MAX_VEC,
3054 : : MLX5_TXQ_MPW_EN,
3055 : : MLX5_TXQ_MPW_HDR_DSEG_EN,
3056 : : MLX5_TXQ_MAX_INLINE_LEN,
3057 : : MLX5_TX_VEC_EN,
3058 : : MLX5_RX_VEC_EN,
3059 : : MLX5_REPRESENTOR,
3060 : : MLX5_MAX_DUMP_FILES_NUM,
3061 : : MLX5_LRO_TIMEOUT_USEC,
3062 : : MLX5_HP_BUF_SIZE,
3063 : : MLX5_DELAY_DROP,
3064 : : NULL,
3065 : : };
3066 : :
3067 : : /* Secondary process should not handle devargs. */
3068 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3069 : 0 : return;
3070 : : MLX5_ASSERT(mkvlist != NULL);
3071 : 0 : DRV_LOG(DEBUG, "Ethernet device \"%s\" for port %u "
3072 : : "already exists, set devargs as used:", name, port_id);
3073 : : /* This function cannot fail with this handler. */
3074 : 0 : mlx5_kvargs_process(mkvlist, params, mlx5_dummy_handler, NULL);
3075 : : }
3076 : :
3077 : : /**
3078 : : * Check sibling device configurations when probing again.
3079 : : *
3080 : : * Sibling devices sharing infiniband device context should have compatible
3081 : : * configurations. This regards representors and bonding device.
3082 : : *
3083 : : * @param cdev
3084 : : * Pointer to mlx5 device structure.
3085 : : * @param mkvlist
3086 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
3087 : : *
3088 : : * @return
3089 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3090 : : */
3091 : : int
3092 : 0 : mlx5_probe_again_args_validate(struct mlx5_common_device *cdev,
3093 : : struct mlx5_kvargs_ctrl *mkvlist)
3094 : : {
3095 : : struct mlx5_dev_ctx_shared *sh = NULL;
3096 : : struct mlx5_sh_config *config;
3097 : : int ret;
3098 : :
3099 : : /* Secondary process should not handle devargs. */
3100 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3101 : : return 0;
3102 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
3103 : : /* Search for IB context by common device pointer. */
3104 [ # # ]: 0 : LIST_FOREACH(sh, &dev_ctx_list, next)
3105 [ # # ]: 0 : if (sh->cdev == cdev)
3106 : : break;
3107 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
3108 : : /* There is sh for this device -> it isn't probe again. */
3109 [ # # ]: 0 : if (sh == NULL)
3110 : : return 0;
3111 : 0 : config = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
3112 : : sizeof(struct mlx5_sh_config),
3113 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
3114 [ # # ]: 0 : if (config == NULL) {
3115 : 0 : rte_errno = -ENOMEM;
3116 : 0 : return -rte_errno;
3117 : : }
3118 : : /*
3119 : : * Creates a temporary IB context configure structure according to new
3120 : : * devargs attached in probing again.
3121 : : */
3122 : 0 : ret = mlx5_shared_dev_ctx_args_config(sh, mkvlist, config);
3123 [ # # ]: 0 : if (ret) {
3124 : 0 : DRV_LOG(ERR, "Failed to process device configure: %s",
3125 : : strerror(rte_errno));
3126 : 0 : mlx5_free(config);
3127 : 0 : return ret;
3128 : : }
3129 : : /*
3130 : : * Checks the match between the temporary structure and the existing
3131 : : * IB context structure.
3132 : : */
3133 [ # # ]: 0 : if (sh->config.dv_flow_en ^ config->dv_flow_en) {
3134 : 0 : DRV_LOG(ERR, "\"dv_flow_en\" "
3135 : : "configuration mismatch for shared %s context.",
3136 : : sh->ibdev_name);
3137 : 0 : goto error;
3138 : : }
3139 [ # # ]: 0 : if ((sh->config.dv_xmeta_en ^ config->dv_xmeta_en) ||
3140 : : (sh->config.dv_miss_info ^ config->dv_miss_info)) {
3141 : 0 : DRV_LOG(ERR, "\"dv_xmeta_en\" "
3142 : : "configuration mismatch for shared %s context.",
3143 : : sh->ibdev_name);
3144 : 0 : goto error;
3145 : : }
3146 [ # # ]: 0 : if (sh->config.dv_esw_en ^ config->dv_esw_en) {
3147 : 0 : DRV_LOG(ERR, "\"dv_esw_en\" "
3148 : : "configuration mismatch for shared %s context.",
3149 : : sh->ibdev_name);
3150 : 0 : goto error;
3151 : : }
3152 [ # # ]: 0 : if (sh->config.reclaim_mode ^ config->reclaim_mode) {
3153 : 0 : DRV_LOG(ERR, "\"reclaim_mode\" "
3154 : : "configuration mismatch for shared %s context.",
3155 : : sh->ibdev_name);
3156 : 0 : goto error;
3157 : : }
3158 : 0 : if (sh->config.allow_duplicate_pattern ^
3159 [ # # ]: 0 : config->allow_duplicate_pattern) {
3160 : 0 : DRV_LOG(ERR, "\"allow_duplicate_pattern\" "
3161 : : "configuration mismatch for shared %s context.",
3162 : : sh->ibdev_name);
3163 : 0 : goto error;
3164 : : }
3165 [ # # ]: 0 : if (sh->config.fdb_def_rule ^ config->fdb_def_rule) {
3166 : 0 : DRV_LOG(ERR, "\"fdb_def_rule_en\" configuration mismatch for shared %s context.",
3167 : : sh->ibdev_name);
3168 : 0 : goto error;
3169 : : }
3170 [ # # ]: 0 : if (sh->config.l3_vxlan_en ^ config->l3_vxlan_en) {
3171 : 0 : DRV_LOG(ERR, "\"l3_vxlan_en\" "
3172 : : "configuration mismatch for shared %s context.",
3173 : : sh->ibdev_name);
3174 : 0 : goto error;
3175 : : }
3176 [ # # ]: 0 : if (sh->config.decap_en ^ config->decap_en) {
3177 : 0 : DRV_LOG(ERR, "\"decap_en\" "
3178 : : "configuration mismatch for shared %s context.",
3179 : : sh->ibdev_name);
3180 : 0 : goto error;
3181 : : }
3182 [ # # ]: 0 : if (sh->config.lacp_by_user ^ config->lacp_by_user) {
3183 : 0 : DRV_LOG(ERR, "\"lacp_by_user\" "
3184 : : "configuration mismatch for shared %s context.",
3185 : : sh->ibdev_name);
3186 : 0 : goto error;
3187 : : }
3188 [ # # ]: 0 : if (sh->config.tx_pp ^ config->tx_pp) {
3189 : 0 : DRV_LOG(ERR, "\"tx_pp\" "
3190 : : "configuration mismatch for shared %s context.",
3191 : : sh->ibdev_name);
3192 : 0 : goto error;
3193 : : }
3194 [ # # ]: 0 : if (sh->config.tx_skew ^ config->tx_skew) {
3195 : 0 : DRV_LOG(ERR, "\"tx_skew\" "
3196 : : "configuration mismatch for shared %s context.",
3197 : : sh->ibdev_name);
3198 : 0 : goto error;
3199 : : }
3200 [ # # ]: 0 : if (sh->config.txq_mem_algn != config->txq_mem_algn) {
3201 : 0 : DRV_LOG(ERR, "\"TxQ memory alignment\" "
3202 : : "configuration mismatch for shared %s context. %u - %u",
3203 : : sh->ibdev_name, sh->config.txq_mem_algn, config->txq_mem_algn);
3204 : 0 : goto error;
3205 : : }
3206 : 0 : mlx5_free(config);
3207 : 0 : return 0;
3208 : 0 : error:
3209 : 0 : mlx5_free(config);
3210 : 0 : rte_errno = EINVAL;
3211 : 0 : return -rte_errno;
3212 : : }
3213 : :
3214 : : /**
3215 : : * Configures the minimal amount of data to inline into WQE
3216 : : * while sending packets.
3217 : : *
3218 : : * - the txq_inline_min has the maximal priority, if this
3219 : : * key is specified in devargs
3220 : : * - if DevX is enabled the inline mode is queried from the
3221 : : * device (HCA attributes and NIC vport context if needed).
3222 : : * - otherwise L2 mode (18 bytes) is assumed for ConnectX-4/4 Lx
3223 : : * and none (0 bytes) for other NICs
3224 : : *
3225 : : * @param priv
3226 : : * Pointer to the private device data structure.
3227 : : */
3228 : : void
3229 : 0 : mlx5_set_min_inline(struct mlx5_priv *priv)
3230 : : {
3231 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
3232 : : struct mlx5_port_config *config = &priv->config;
3233 : :
3234 [ # # ]: 0 : if (config->txq_inline_min != MLX5_ARG_UNSET) {
3235 : : /* Application defines size of inlined data explicitly. */
3236 [ # # ]: 0 : if (priv->pci_dev != NULL) {
3237 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
3238 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
3239 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
3240 [ # # ]: 0 : if (config->txq_inline_min <
3241 : : (int)MLX5_INLINE_HSIZE_L2) {
3242 : 0 : DRV_LOG(DEBUG,
3243 : : "txq_inline_mix aligned to minimal ConnectX-4 required value %d",
3244 : : (int)MLX5_INLINE_HSIZE_L2);
3245 : 0 : config->txq_inline_min =
3246 : : MLX5_INLINE_HSIZE_L2;
3247 : : }
3248 : : break;
3249 : : }
3250 : : }
3251 : 0 : goto exit;
3252 : : }
3253 [ # # ]: 0 : if (hca_attr->eth_net_offloads) {
3254 : : /* We have DevX enabled, inline mode queried successfully. */
3255 [ # # # # ]: 0 : switch (hca_attr->wqe_inline_mode) {
3256 : 0 : case MLX5_CAP_INLINE_MODE_L2:
3257 : : /* outer L2 header must be inlined. */
3258 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
3259 : 0 : goto exit;
3260 : 0 : case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
3261 : : /* No inline data are required by NIC. */
3262 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3263 : 0 : config->hw_vlan_insert =
3264 : 0 : hca_attr->wqe_vlan_insert;
3265 : 0 : DRV_LOG(DEBUG, "Tx VLAN insertion is supported");
3266 : 0 : goto exit;
3267 : 0 : case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
3268 : : /* inline mode is defined by NIC vport context. */
3269 [ # # ]: 0 : if (!hca_attr->eth_virt)
3270 : : break;
3271 [ # # # # : 0 : switch (hca_attr->vport_inline_mode) {
# # # # ]
3272 : 0 : case MLX5_INLINE_MODE_NONE:
3273 : 0 : config->txq_inline_min =
3274 : : MLX5_INLINE_HSIZE_NONE;
3275 : 0 : goto exit;
3276 : 0 : case MLX5_INLINE_MODE_L2:
3277 : 0 : config->txq_inline_min =
3278 : : MLX5_INLINE_HSIZE_L2;
3279 : 0 : goto exit;
3280 : 0 : case MLX5_INLINE_MODE_IP:
3281 : 0 : config->txq_inline_min =
3282 : : MLX5_INLINE_HSIZE_L3;
3283 : 0 : goto exit;
3284 : 0 : case MLX5_INLINE_MODE_TCP_UDP:
3285 : 0 : config->txq_inline_min =
3286 : : MLX5_INLINE_HSIZE_L4;
3287 : 0 : goto exit;
3288 : 0 : case MLX5_INLINE_MODE_INNER_L2:
3289 : 0 : config->txq_inline_min =
3290 : : MLX5_INLINE_HSIZE_INNER_L2;
3291 : 0 : goto exit;
3292 : 0 : case MLX5_INLINE_MODE_INNER_IP:
3293 : 0 : config->txq_inline_min =
3294 : : MLX5_INLINE_HSIZE_INNER_L3;
3295 : 0 : goto exit;
3296 : 0 : case MLX5_INLINE_MODE_INNER_TCP_UDP:
3297 : 0 : config->txq_inline_min =
3298 : : MLX5_INLINE_HSIZE_INNER_L4;
3299 : 0 : goto exit;
3300 : : }
3301 : : }
3302 : : }
3303 [ # # ]: 0 : if (priv->pci_dev == NULL) {
3304 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3305 : 0 : goto exit;
3306 : : }
3307 : : /*
3308 : : * We get here if we are unable to deduce
3309 : : * inline data size with DevX. Try PCI ID
3310 : : * to determine old NICs.
3311 : : */
3312 [ # # # ]: 0 : switch (priv->pci_dev->id.device_id) {
3313 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
3314 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
3315 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4LX:
3316 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
3317 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
3318 : 0 : config->hw_vlan_insert = 0;
3319 : 0 : break;
3320 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX5:
3321 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
3322 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5EX:
3323 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
3324 : : /*
3325 : : * These NICs support VLAN insertion from WQE and
3326 : : * report the wqe_vlan_insert flag. But there is the bug
3327 : : * and PFC control may be broken, so disable feature.
3328 : : */
3329 : 0 : config->hw_vlan_insert = 0;
3330 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3331 : 0 : break;
3332 : 0 : default:
3333 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3334 : 0 : break;
3335 : : }
3336 : 0 : exit:
3337 : 0 : DRV_LOG(DEBUG, "min tx inline configured: %d", config->txq_inline_min);
3338 : 0 : }
3339 : :
3340 : : /**
3341 : : * Configures the metadata mask fields in the shared context.
3342 : : *
3343 : : * @param [in] dev
3344 : : * Pointer to Ethernet device.
3345 : : */
3346 : : void
3347 : 0 : mlx5_set_metadata_mask(struct rte_eth_dev *dev)
3348 : : {
3349 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3350 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3351 : : uint32_t meta, mark, reg_c0;
3352 : :
3353 : 0 : reg_c0 = ~priv->vport_meta_mask;
3354 [ # # # # : 0 : switch (sh->config.dv_xmeta_en) {
# ]
3355 : : case MLX5_XMETA_MODE_LEGACY:
3356 : : meta = UINT32_MAX;
3357 : : mark = MLX5_FLOW_MARK_MASK;
3358 : : break;
3359 : : case MLX5_XMETA_MODE_META16:
3360 : 0 : meta = reg_c0 >> rte_bsf32(reg_c0);
3361 : : mark = MLX5_FLOW_MARK_MASK;
3362 : 0 : break;
3363 : 0 : case MLX5_XMETA_MODE_META32:
3364 : : meta = UINT32_MAX;
3365 : 0 : mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
3366 : 0 : break;
3367 : 0 : case MLX5_XMETA_MODE_META32_HWS:
3368 : : meta = UINT32_MAX;
3369 : 0 : mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
3370 : 0 : break;
3371 : 0 : default:
3372 : : meta = 0;
3373 : : mark = 0;
3374 : : MLX5_ASSERT(false);
3375 : 0 : break;
3376 : : }
3377 [ # # # # ]: 0 : if (sh->dv_mark_mask && sh->dv_mark_mask != mark)
3378 : 0 : DRV_LOG(WARNING, "metadata MARK mask mismatch %08X:%08X",
3379 : : sh->dv_mark_mask, mark);
3380 : : else
3381 : 0 : sh->dv_mark_mask = mark;
3382 [ # # # # ]: 0 : if (sh->dv_meta_mask && sh->dv_meta_mask != meta)
3383 : 0 : DRV_LOG(WARNING, "metadata META mask mismatch %08X:%08X",
3384 : : sh->dv_meta_mask, meta);
3385 : : else
3386 : 0 : sh->dv_meta_mask = meta;
3387 [ # # # # ]: 0 : if (sh->dv_regc0_mask && sh->dv_regc0_mask != reg_c0)
3388 : 0 : DRV_LOG(WARNING, "metadata reg_c0 mask mismatch %08X:%08X",
3389 : : sh->dv_meta_mask, reg_c0);
3390 : : else
3391 : 0 : sh->dv_regc0_mask = reg_c0;
3392 : 0 : DRV_LOG(DEBUG, "metadata mode %u", sh->config.dv_xmeta_en);
3393 : 0 : DRV_LOG(DEBUG, "metadata MARK mask %08X", sh->dv_mark_mask);
3394 : 0 : DRV_LOG(DEBUG, "metadata META mask %08X", sh->dv_meta_mask);
3395 : 0 : DRV_LOG(DEBUG, "metadata reg_c0 mask %08X", sh->dv_regc0_mask);
3396 : 0 : }
3397 : :
3398 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_get_dyn_flag_names, 20.02)
3399 : : int
3400 : 0 : rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
3401 : : {
3402 : : static const char *const dynf_names[] = {
3403 : : RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
3404 : : RTE_MBUF_DYNFLAG_METADATA_NAME,
3405 : : RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME
3406 : : };
3407 : : unsigned int i;
3408 : :
3409 [ # # ]: 0 : if (n < RTE_DIM(dynf_names))
3410 : : return -ENOMEM;
3411 [ # # ]: 0 : for (i = 0; i < RTE_DIM(dynf_names); i++) {
3412 [ # # ]: 0 : if (names[i] == NULL)
3413 : : return -EINVAL;
3414 : 0 : strcpy(names[i], dynf_names[i]);
3415 : : }
3416 : : return RTE_DIM(dynf_names);
3417 : : }
3418 : :
3419 : : /**
3420 : : * Look for the ethernet device belonging to mlx5 driver.
3421 : : *
3422 : : * @param[in] port_id
3423 : : * port_id to start looking for device.
3424 : : * @param[in] odev
3425 : : * Pointer to the hint device. When device is being probed
3426 : : * the its siblings (master and preceding representors might
3427 : : * not have assigned driver yet (because the mlx5_os_pci_probe()
3428 : : * is not completed yet, for this case match on hint
3429 : : * device may be used to detect sibling device.
3430 : : *
3431 : : * @return
3432 : : * port_id of found device, RTE_MAX_ETHPORT if not found.
3433 : : */
3434 : : uint16_t
3435 : 0 : mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev)
3436 : : {
3437 [ # # ]: 0 : while (port_id < RTE_MAX_ETHPORTS) {
3438 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3439 : :
3440 [ # # ]: 0 : if (dev->state != RTE_ETH_DEV_UNUSED &&
3441 [ # # # # ]: 0 : dev->device &&
3442 : 0 : (dev->device == odev ||
3443 [ # # ]: 0 : (dev->device->driver &&
3444 [ # # ]: 0 : dev->device->driver->name &&
3445 [ # # ]: 0 : ((strcmp(dev->device->driver->name,
3446 : 0 : MLX5_PCI_DRIVER_NAME) == 0) ||
3447 [ # # ]: 0 : (strcmp(dev->device->driver->name,
3448 : : MLX5_AUXILIARY_DRIVER_NAME) == 0)))))
3449 : : break;
3450 : 0 : port_id++;
3451 : : }
3452 : : if (port_id >= RTE_MAX_ETHPORTS)
3453 : : return RTE_MAX_ETHPORTS;
3454 : : return port_id;
3455 : : }
3456 : :
3457 : : static int
3458 : 0 : mlx5_hairpin_queue_counter_supported(struct mlx5_priv *priv)
3459 : : {
3460 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
3461 : 0 : DRV_LOG(WARNING,
3462 : : "DevX counter is not supported in the secondary process");
3463 : 0 : return -ENOTSUP;
3464 : : }
3465 : :
3466 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_modify_counter_set_id == NULL) {
3467 : 0 : DRV_LOG(WARNING,
3468 : : "DevX counter is not supported in this device");
3469 : 0 : return -ENOTSUP;
3470 : : }
3471 : : return 0;
3472 : : }
3473 : :
3474 : : /**
3475 : : * Disables the port-level hairpin counter.
3476 : : *
3477 : : * This function iterates over each RXQ, detaches it from the global
3478 : : * counter if it's a hairpin counter, and then destroys the global counter object if
3479 : : * it exists.
3480 : : *
3481 : : * @param dev
3482 : : * Pointer to Ethernet device.
3483 : : * @param id
3484 : : * The counter ID to disable (not used in this implementation).
3485 : : *
3486 : : * @return
3487 : : * 0 on success, error code otherwise.
3488 : : */
3489 : : int
3490 : 0 : mlx5_disable_port_level_hairpin_counter(struct rte_eth_dev *dev, uint64_t id __rte_unused)
3491 : : {
3492 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3493 : 0 : unsigned int num_rxqs = priv->rxqs_n;
3494 : : unsigned int i;
3495 : :
3496 [ # # ]: 0 : if (priv->q_counter_hairpin == NULL)
3497 : : return 0;
3498 : :
3499 : : /* Detach each RXQ from the global hairpin counter */
3500 [ # # ]: 0 : for (i = 0; i < num_rxqs; ++i) {
3501 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
3502 : :
3503 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3504 : 0 : continue;
3505 : :
3506 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, 0) != 0)
3507 : 0 : DRV_LOG(ERR, "Port %u failed to modify rq object %s",
3508 : : priv->dev_data->port_id, strerror(rte_errno));
3509 : : }
3510 : :
3511 : 0 : mlx5_devx_cmd_destroy(priv->q_counter_hairpin);
3512 : 0 : priv->q_counter_hairpin = NULL;
3513 : :
3514 : : /* Reset oob stats. */
3515 : 0 : mlx5_reset_xstats_by_name(priv, "hairpin_out_of_buffer");
3516 : 0 : return 0;
3517 : : }
3518 : :
3519 : : /**
3520 : : * Enables the port-level hairpin counter.
3521 : : *
3522 : : * This function iterates over each RXQ, allocate a q counter and attach it to each
3523 : : * hairpin queue.
3524 : : *
3525 : : * @param dev
3526 : : * Pointer to Ethernet device.
3527 : : * @param id
3528 : : * The counter ID to disable (not used in this implementation).
3529 : : *
3530 : : * @return
3531 : : * 0 on success, error code otherwise.
3532 : : */
3533 : : int
3534 : 0 : mlx5_enable_port_level_hairpin_counter(struct rte_eth_dev *dev, uint64_t id __rte_unused)
3535 : : {
3536 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3537 : : struct mlx5_rxq_priv *rxq;
3538 : 0 : int syndrome = 0;
3539 : : unsigned int i;
3540 : :
3541 : 0 : int ret = mlx5_hairpin_queue_counter_supported(priv);
3542 [ # # ]: 0 : if (ret) {
3543 : 0 : DRV_LOG(DEBUG, "Hairpin out of buffer counter "
3544 : : "is not available on this NIC.");
3545 : 0 : return ret;
3546 : : }
3547 : :
3548 : : /* check if counter is enable per queue - if yes - fail to enable per port */
3549 [ # # ]: 0 : if (priv->num_of_hairpin_q_counter_enabled != 0) {
3550 : 0 : DRV_LOG(WARNING, "Hairpin out of buffer counter is enabled per queue.");
3551 : 0 : return -EINVAL;
3552 : : }
3553 : :
3554 : : /* Alloc global hairpin queue counter. */
3555 : 0 : priv->q_counter_hairpin = mlx5_devx_cmd_queue_counter_alloc(priv->sh->cdev->ctx, &syndrome);
3556 [ # # ]: 0 : if (!priv->q_counter_hairpin) {
3557 [ # # ]: 0 : if (syndrome == MLX5_Q_COUNTERS_LIMIT_REACHED) {
3558 : 0 : DRV_LOG(ERR, "Maximum number of queue counters reached. "
3559 : : "Unable to create counter object for Port %d using DevX.",
3560 : : priv->dev_data->port_id);
3561 : 0 : return -ENOSPC;
3562 : : }
3563 : 0 : DRV_LOG(ERR, "Port %d global hairpin queue counter object cannot be created "
3564 : : "by DevX.", priv->dev_data->port_id);
3565 : 0 : return -ENOMEM;
3566 : : }
3567 : :
3568 : : /* go over each queue and attach to global counter */
3569 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i) {
3570 : 0 : rxq = mlx5_rxq_get(dev, i);
3571 : :
3572 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3573 : 0 : continue;
3574 : :
3575 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, priv->q_counter_hairpin->id);
3576 [ # # ]: 0 : if (ret) {
3577 : 0 : DRV_LOG(ERR, "failed to modify rq object for port %u"
3578 : : "%s", priv->dev_data->port_id, strerror(rte_errno));
3579 : 0 : return ret;
3580 : : }
3581 : : }
3582 : :
3583 : : /* Reset oob stats. */
3584 : 0 : mlx5_reset_xstats_by_name(priv, "hairpin_out_of_buffer");
3585 : 0 : return 0;
3586 : : }
3587 : :
3588 : : /**
3589 : : * Creates a queue counter for hairpin Rx queue.
3590 : : *
3591 : : * @param dev
3592 : : * Pointer to Ethernet device structure.
3593 : : * @param id
3594 : : * Index of the RX queue to disable the hairpin queue counter for.
3595 : : * @return
3596 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3597 : : */
3598 : : int
3599 : 0 : mlx5_enable_per_queue_hairpin_counter(struct rte_eth_dev *dev, uint64_t id)
3600 : : {
3601 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3602 : : struct mlx5_rxq_priv *rxq;
3603 : : struct mlx5_rxq_data *rxq_data;
3604 : 0 : int syndrome = 0;
3605 : :
3606 : 0 : int ret = mlx5_hairpin_queue_counter_supported(priv);
3607 [ # # ]: 0 : if (ret) {
3608 : 0 : DRV_LOG(DEBUG, "Hairpin out of buffer counter "
3609 : : "is not available on this NIC.");
3610 : 0 : return ret;
3611 : : }
3612 : :
3613 : : /* check if we have port level counter enabled. if yes, don't set the queue level counter */
3614 [ # # ]: 0 : if (priv->q_counter_hairpin) {
3615 : 0 : DRV_LOG(WARNING, "Hairpin out of buffer counter is enabled per port.");
3616 : 0 : return -EINVAL;
3617 : : }
3618 : :
3619 : 0 : rxq = mlx5_rxq_get(dev, id);
3620 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3621 : : return -EINVAL;
3622 : :
3623 [ # # ]: 0 : if (rxq->q_counter != NULL)
3624 : : return 0;
3625 : :
3626 : : /* Alloc hairpin queue counter. */
3627 : 0 : rxq->q_counter = mlx5_devx_cmd_queue_counter_alloc(priv->sh->cdev->ctx, &syndrome);
3628 [ # # ]: 0 : if (rxq->q_counter == NULL) {
3629 [ # # ]: 0 : if (syndrome == MLX5_Q_COUNTERS_LIMIT_REACHED) {
3630 : 0 : DRV_LOG(ERR, "Maximum number of queue counters reached. "
3631 : : "Unable to create counter object for Port %d, Queue %d "
3632 : : "using DevX. The counter from this queue will not increment.",
3633 : : priv->dev_data->port_id, rxq->idx);
3634 : 0 : return -ENOSPC;
3635 : : }
3636 : 0 : DRV_LOG(ERR, "Port %d queue %d counter object cannot be created "
3637 : : "by DevX. Counter from this queue will not increment.",
3638 : : priv->dev_data->port_id, rxq->idx);
3639 : 0 : return -ENOMEM;
3640 : : }
3641 : :
3642 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, rxq->q_counter->id);
3643 [ # # ]: 0 : if (ret) {
3644 : 0 : DRV_LOG(ERR, "failed to modify rq object for port %u"
3645 : : "%s", priv->dev_data->port_id, strerror(rte_errno));
3646 : 0 : mlx5_devx_cmd_destroy(rxq->q_counter);
3647 : 0 : rxq->q_counter = NULL;
3648 : 0 : return ret;
3649 : : }
3650 : :
3651 : 0 : rxq_data = mlx5_rxq_data_get(dev, id);
3652 [ # # ]: 0 : if (rxq_data != NULL)
3653 : 0 : rxq_data->stats.oobs.ctrl.enabled = 1;
3654 : :
3655 : 0 : priv->num_of_hairpin_q_counter_enabled++;
3656 : 0 : return 0;
3657 : : }
3658 : :
3659 : : /**
3660 : : * Disables the hairpin queue counter for a specified RX queue.
3661 : : *
3662 : : * @param dev
3663 : : * Pointer to Ethernet device structure.
3664 : : * @param id
3665 : : * Index of the RX queue to disable the hairpin queue counter for.
3666 : : * @return
3667 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3668 : : */
3669 : : int
3670 : 0 : mlx5_disable_per_queue_hairpin_counter(struct rte_eth_dev *dev, uint64_t id)
3671 : : {
3672 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3673 : : struct mlx5_rxq_priv *rxq;
3674 : : struct mlx5_rxq_data *rxq_data;
3675 : : int ret = 0;
3676 : :
3677 : 0 : rxq = mlx5_rxq_get(dev, id);
3678 : 0 : rxq_data = mlx5_rxq_data_get(dev, id);
3679 : :
3680 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3681 : : return 0;
3682 : :
3683 [ # # ]: 0 : if (rxq->q_counter != NULL) {
3684 : : /* Modify rxq. */
3685 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, 0);
3686 [ # # ]: 0 : if (ret)
3687 : 0 : DRV_LOG(ERR, "Port %u failed to modify rq object "
3688 : : " %s", priv->dev_data->port_id, strerror(rte_errno));
3689 : :
3690 : 0 : mlx5_devx_cmd_destroy(rxq->q_counter);
3691 : 0 : rxq->q_counter = NULL;
3692 : : }
3693 : :
3694 : : /* Reset queue oob stats. */
3695 [ # # ]: 0 : if (rxq_data != NULL) {
3696 : 0 : rxq_data->stats.oobs.count = 0;
3697 : 0 : rxq_data->stats_reset.oobs.count = 0;
3698 : 0 : rxq_data->stats.oobs.ctrl.enabled = 0;
3699 : : }
3700 : :
3701 : 0 : priv->num_of_hairpin_q_counter_enabled--;
3702 : 0 : return 0;
3703 : : }
3704 : :
3705 : : /**
3706 : : * Read statistics per queue by a named counter.
3707 : : *
3708 : : * @param[in] q_counter
3709 : : * Pointer to the queue's counter object.
3710 : : * @param[in] ctr_name
3711 : : * Pointer to the name of the statistic counter to read
3712 : : * @param[out] stat
3713 : : * Pointer to read statistic value.
3714 : : * @return
3715 : : * 0 on success and stat is valid, 1 if failed to read the value
3716 : : * rte_errno is set.
3717 : : *
3718 : : */
3719 : : int
3720 : 0 : mlx5_read_queue_counter(struct mlx5_devx_obj *q_counter, const char *ctr_name,
3721 : : uint64_t *stat)
3722 : : {
3723 : : uint32_t val;
3724 : : int ret;
3725 : :
3726 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
3727 : 0 : DRV_LOG(WARNING,
3728 : : "DevX %s counter is not supported in the secondary process", ctr_name);
3729 : 0 : return -ENOTSUP;
3730 : : }
3731 : :
3732 [ # # ]: 0 : if (q_counter == NULL)
3733 : : return -EINVAL;
3734 : :
3735 : 0 : ret = mlx5_devx_cmd_queue_counter_query(q_counter, 0, &val);
3736 [ # # ]: 0 : if (ret == 0)
3737 : 0 : *stat = val;
3738 : :
3739 : : return ret;
3740 : : }
3741 : :
3742 : : /**
3743 : : * Fix up shared configuration passed by user based on device capabilities.
3744 : : *
3745 : : * @param[in] config
3746 : : * Pointer to shared configuration.
3747 : : * @param[in] sh
3748 : : * Pointer to shared device context.
3749 : : * @param[in] mkvlist
3750 : : * Key/value list of passed options
3751 : : */
3752 : : void
3753 : 0 : mlx5_fixup_flow_config(struct mlx5_sh_config *config,
3754 : : struct mlx5_dev_ctx_shared *sh,
3755 : : struct mlx5_kvargs_ctrl *mkvlist)
3756 : : {
3757 [ # # # # ]: 0 : if (config->dv_flow_en && !sh->dev_cap.dv_flow_en) {
3758 : 0 : DRV_LOG(WARNING, "DV flow is not supported.");
3759 : 0 : config->dv_flow_en = 0;
3760 : : }
3761 : :
3762 : : /* Apply platform-dependent logic. */
3763 : 0 : mlx5_os_fixup_flow_en(config, sh);
3764 : 0 : mlx5_os_fixup_duplicate_pattern(config, mkvlist, MLX5_ALLOW_DUPLICATE_PATTERN);
3765 : 0 : }
3766 : :
3767 : : /**
3768 : : * Callback to remove a device.
3769 : : *
3770 : : * This function removes all Ethernet devices belong to a given device.
3771 : : *
3772 : : * @param[in] cdev
3773 : : * Pointer to the generic device.
3774 : : *
3775 : : * @return
3776 : : * 0 on success, the function cannot fail.
3777 : : */
3778 : : int
3779 : 0 : mlx5_net_remove(struct mlx5_common_device *cdev)
3780 : : {
3781 : : uint16_t port_id;
3782 : : int ret = 0;
3783 : :
3784 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, cdev->dev) {
3785 : : /*
3786 : : * mlx5_dev_close() is not registered to secondary process,
3787 : : * call the close function explicitly for secondary process.
3788 : : */
3789 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
3790 : 0 : ret |= mlx5_dev_close(&rte_eth_devices[port_id]);
3791 : : else
3792 : 0 : ret |= rte_eth_dev_close(port_id);
3793 : : }
3794 [ # # ]: 0 : return ret == 0 ? 0 : -EIO;
3795 : : }
3796 : :
3797 : : static const struct rte_pci_id mlx5_pci_id_map[] = {
3798 : : {
3799 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3800 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4)
3801 : : },
3802 : : {
3803 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3804 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
3805 : : },
3806 : : {
3807 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3808 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
3809 : : },
3810 : : {
3811 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3812 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
3813 : : },
3814 : : {
3815 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3816 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5)
3817 : : },
3818 : : {
3819 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3820 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5VF)
3821 : : },
3822 : : {
3823 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3824 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EX)
3825 : : },
3826 : : {
3827 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3828 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)
3829 : : },
3830 : : {
3831 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3832 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD)
3833 : : },
3834 : : {
3835 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3836 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELDVF)
3837 : : },
3838 : : {
3839 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3840 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6)
3841 : : },
3842 : : {
3843 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3844 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
3845 : : },
3846 : : {
3847 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3848 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
3849 : : },
3850 : : {
3851 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3852 : : PCI_DEVICE_ID_MELLANOX_CONNECTXVF)
3853 : : },
3854 : : {
3855 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3856 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD2)
3857 : : },
3858 : : {
3859 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3860 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6LX)
3861 : : },
3862 : : {
3863 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3864 : : PCI_DEVICE_ID_MELLANOX_CONNECTX7)
3865 : : },
3866 : : {
3867 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3868 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD3)
3869 : : },
3870 : : {
3871 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3872 : : PCI_DEVICE_ID_MELLANOX_CONNECTX8)
3873 : : },
3874 : : {
3875 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3876 : : PCI_DEVICE_ID_MELLANOX_CONNECTX9)
3877 : : },
3878 : : {
3879 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3880 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD4)
3881 : : },
3882 : : {
3883 : : .vendor_id = 0
3884 : : }
3885 : : };
3886 : :
3887 : : static struct mlx5_class_driver mlx5_net_driver = {
3888 : : .drv_class = MLX5_CLASS_ETH,
3889 : : .name = RTE_STR(MLX5_ETH_DRIVER_NAME),
3890 : : .id_table = mlx5_pci_id_map,
3891 : : .probe = mlx5_os_net_probe,
3892 : : .remove = mlx5_net_remove,
3893 : : .probe_again = 1,
3894 : : .intr_lsc = 1,
3895 : : .intr_rmv = 1,
3896 : : };
3897 : :
3898 : : /* Initialize driver log type. */
3899 [ - + ]: 276 : RTE_LOG_REGISTER_DEFAULT(mlx5_logtype, NOTICE)
3900 : :
3901 : : /**
3902 : : * Driver initialization routine.
3903 : : */
3904 : 276 : RTE_INIT(rte_mlx5_pmd_init)
3905 : : {
3906 : 276 : pthread_mutex_init(&mlx5_dev_ctx_list_mutex, NULL);
3907 : 276 : mlx5_common_init();
3908 : : /* Build the static tables for Verbs conversion. */
3909 : 276 : mlx5_set_ptype_table();
3910 : 276 : mlx5_set_cksum_table();
3911 : 276 : mlx5_set_swp_types_table();
3912 [ + - ]: 276 : if (mlx5_glue)
3913 : 276 : mlx5_class_driver_register(&mlx5_net_driver);
3914 : 276 : }
3915 : :
3916 : : RTE_PMD_EXPORT_NAME(MLX5_ETH_DRIVER_NAME);
3917 : : RTE_PMD_REGISTER_PCI_TABLE(MLX5_ETH_DRIVER_NAME, mlx5_pci_id_map);
3918 : : RTE_PMD_REGISTER_KMOD_DEP(MLX5_ETH_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");
|