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