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