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