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