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