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 : exit:
1979 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1980 : 0 : return sh;
1981 : 0 : error:
1982 : 0 : err = rte_errno;
1983 : 0 : pthread_mutex_destroy(&sh->txpp.mutex);
1984 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1985 : : MLX5_ASSERT(sh);
1986 : : mlx5_rxtx_uars_release(sh);
1987 : : i = 0;
1988 : : do {
1989 [ # # ]: 0 : if (sh->tis[i])
1990 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
1991 [ # # ]: 0 : } while (++i <= (uint32_t)sh->bond.n_port);
1992 [ # # ]: 0 : if (sh->td)
1993 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->td));
1994 [ # # ]: 0 : if (sh->phdev)
1995 : 0 : mlx5_physical_device_destroy(sh->phdev);
1996 : 0 : mlx5_free(sh);
1997 : 0 : rte_errno = err;
1998 : 0 : return NULL;
1999 : : }
2000 : :
2001 : : /**
2002 : : * Create LWM event_channel and interrupt handle for shared device
2003 : : * context. All rxqs sharing the device context share the event_channel.
2004 : : * A callback is registered in interrupt thread to receive the LWM event.
2005 : : *
2006 : : * @param[in] priv
2007 : : * Pointer to mlx5_priv instance.
2008 : : *
2009 : : * @return
2010 : : * 0 on success, negative with rte_errno set.
2011 : : */
2012 : : int
2013 : 0 : mlx5_lwm_setup(struct mlx5_priv *priv)
2014 : : {
2015 : : int fd_lwm;
2016 : :
2017 : 0 : pthread_mutex_init(&priv->sh->lwm_config_lock, NULL);
2018 : 0 : priv->sh->devx_channel_lwm = mlx5_os_devx_create_event_channel
2019 : 0 : (priv->sh->cdev->ctx,
2020 : : MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA);
2021 [ # # ]: 0 : if (!priv->sh->devx_channel_lwm)
2022 : 0 : goto err;
2023 : : fd_lwm = mlx5_os_get_devx_channel_fd(priv->sh->devx_channel_lwm);
2024 : 0 : priv->sh->intr_handle_lwm = mlx5_os_interrupt_handler_create
2025 : : (RTE_INTR_INSTANCE_F_SHARED, true,
2026 : : fd_lwm, mlx5_dev_interrupt_handler_lwm, priv);
2027 [ # # ]: 0 : if (!priv->sh->intr_handle_lwm)
2028 : 0 : goto err;
2029 : : return 0;
2030 : 0 : err:
2031 [ # # ]: 0 : if (priv->sh->devx_channel_lwm) {
2032 : : mlx5_os_devx_destroy_event_channel
2033 : : (priv->sh->devx_channel_lwm);
2034 : 0 : priv->sh->devx_channel_lwm = NULL;
2035 : : }
2036 : 0 : pthread_mutex_destroy(&priv->sh->lwm_config_lock);
2037 : 0 : return -rte_errno;
2038 : : }
2039 : :
2040 : : /**
2041 : : * Destroy LWM event_channel and interrupt handle for shared device
2042 : : * context before free this context. The interrupt handler is also
2043 : : * unregistered.
2044 : : *
2045 : : * @param[in] sh
2046 : : * Pointer to shared device context.
2047 : : */
2048 : : void
2049 : 0 : mlx5_lwm_unset(struct mlx5_dev_ctx_shared *sh)
2050 : : {
2051 [ # # ]: 0 : if (sh->intr_handle_lwm) {
2052 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle_lwm,
2053 : : mlx5_dev_interrupt_handler_lwm, (void *)-1);
2054 : 0 : sh->intr_handle_lwm = NULL;
2055 : : }
2056 [ # # ]: 0 : if (sh->devx_channel_lwm) {
2057 : : mlx5_os_devx_destroy_event_channel
2058 : : (sh->devx_channel_lwm);
2059 : 0 : sh->devx_channel_lwm = NULL;
2060 : : }
2061 : 0 : pthread_mutex_destroy(&sh->lwm_config_lock);
2062 : 0 : }
2063 : :
2064 : : /**
2065 : : * Free shared IB device context. Decrement counter and if zero free
2066 : : * all allocated resources and close handles.
2067 : : *
2068 : : * @param[in] sh
2069 : : * Pointer to mlx5_dev_ctx_shared object to free
2070 : : */
2071 : : void
2072 : 0 : mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
2073 : : {
2074 : : int ret;
2075 : : int i = 0;
2076 : :
2077 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
2078 : : #ifdef RTE_PMD_MLX5_DEBUG
2079 : : /* Check the object presence in the list. */
2080 : : struct mlx5_dev_ctx_shared *lctx;
2081 : :
2082 : : LIST_FOREACH(lctx, &dev_ctx_list, next)
2083 : : if (lctx == sh)
2084 : : break;
2085 : : MLX5_ASSERT(lctx);
2086 : : if (lctx != sh) {
2087 : : DRV_LOG(ERR, "Freeing non-existing shared IB context");
2088 : : goto exit;
2089 : : }
2090 : : #endif
2091 : : MLX5_ASSERT(sh);
2092 : : MLX5_ASSERT(sh->refcnt);
2093 : : /* Secondary process should not free the shared context. */
2094 : : MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
2095 [ # # ]: 0 : if (--sh->refcnt)
2096 : 0 : goto exit;
2097 : : /* Stop watching for mempool events and unregister all mempools. */
2098 [ # # ]: 0 : if (!sh->cdev->config.mr_mempool_reg_en) {
2099 : 0 : ret = rte_mempool_event_callback_unregister
2100 : : (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh);
2101 [ # # ]: 0 : if (ret == 0)
2102 : 0 : rte_mempool_walk
2103 : : (mlx5_dev_ctx_shared_rx_mempool_unregister_cb, sh);
2104 : : }
2105 : : /* Remove context from the global device list. */
2106 [ # # ]: 0 : LIST_REMOVE(sh, next);
2107 : : /* Release resources on the last device removal. */
2108 [ # # ]: 0 : if (LIST_EMPTY(&dev_ctx_list)) {
2109 : 0 : mlx5_os_net_cleanup();
2110 : 0 : mlx5_flow_os_release_workspace();
2111 : : }
2112 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
2113 [ # # ]: 0 : if (sh->flex_parsers_dv) {
2114 : 0 : mlx5_list_destroy(sh->flex_parsers_dv);
2115 : 0 : sh->flex_parsers_dv = NULL;
2116 : : }
2117 : : /*
2118 : : * Ensure there is no async event handler installed.
2119 : : * Only primary process handles async device events.
2120 : : **/
2121 : 0 : mlx5_flow_counters_mng_close(sh);
2122 [ # # ]: 0 : if (sh->ct_mng)
2123 : 0 : mlx5_flow_aso_ct_mng_close(sh);
2124 [ # # ]: 0 : if (sh->aso_age_mng) {
2125 : 0 : mlx5_flow_aso_age_mng_close(sh);
2126 : 0 : sh->aso_age_mng = NULL;
2127 : : }
2128 [ # # ]: 0 : if (sh->mtrmng)
2129 : 0 : mlx5_aso_flow_mtrs_mng_close(sh);
2130 : 0 : mlx5_flow_ipool_destroy(sh);
2131 : 0 : mlx5_os_dev_shared_handler_uninstall(sh);
2132 : : mlx5_rxtx_uars_release(sh);
2133 : : do {
2134 [ # # ]: 0 : if (sh->tis[i])
2135 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
2136 [ # # ]: 0 : } while (++i <= sh->bond.n_port);
2137 [ # # ]: 0 : if (sh->td)
2138 : 0 : claim_zero(mlx5_devx_cmd_destroy(sh->td));
2139 : : MLX5_ASSERT(sh->geneve_tlv_option_resource == NULL);
2140 : 0 : pthread_mutex_destroy(&sh->txpp.mutex);
2141 : 0 : mlx5_lwm_unset(sh);
2142 : 0 : mlx5_physical_device_destroy(sh->phdev);
2143 : 0 : mlx5_free(sh);
2144 : 0 : return;
2145 : : exit:
2146 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
2147 : : }
2148 : :
2149 : : /**
2150 : : * Destroy table hash list.
2151 : : *
2152 : : * @param[in] priv
2153 : : * Pointer to the private device data structure.
2154 : : */
2155 : : void
2156 : 0 : mlx5_free_table_hash_list(struct mlx5_priv *priv)
2157 : : {
2158 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2159 : : struct mlx5_hlist **tbls = (priv->sh->config.dv_flow_en == 2) ?
2160 : : &sh->groups : &sh->flow_tbls;
2161 [ # # ]: 0 : if (*tbls == NULL)
2162 : : return;
2163 : 0 : mlx5_hlist_destroy(*tbls);
2164 : 0 : *tbls = NULL;
2165 : : }
2166 : :
2167 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2168 : : /**
2169 : : * Allocate HW steering group hash list.
2170 : : *
2171 : : * @param[in] priv
2172 : : * Pointer to the private device data structure.
2173 : : */
2174 : : static int
2175 : 0 : mlx5_alloc_hw_group_hash_list(struct mlx5_priv *priv)
2176 : : {
2177 : : int err = 0;
2178 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2179 : : char s[MLX5_NAME_SIZE];
2180 : :
2181 : : MLX5_ASSERT(sh);
2182 : 0 : snprintf(s, sizeof(s), "%s_flow_groups", priv->sh->ibdev_name);
2183 : 0 : sh->groups = mlx5_hlist_create
2184 : : (s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE,
2185 : : false, true, sh,
2186 : : mlx5_flow_hw_grp_create_cb,
2187 : : mlx5_flow_hw_grp_match_cb,
2188 : : mlx5_flow_hw_grp_remove_cb,
2189 : : mlx5_flow_hw_grp_clone_cb,
2190 : : mlx5_flow_hw_grp_clone_free_cb);
2191 [ # # ]: 0 : if (!sh->groups) {
2192 : 0 : DRV_LOG(ERR, "flow groups with hash creation failed.");
2193 : : err = ENOMEM;
2194 : : }
2195 : 0 : return err;
2196 : : }
2197 : : #endif
2198 : :
2199 : :
2200 : : /**
2201 : : * Initialize flow table hash list and create the root tables entry
2202 : : * for each domain.
2203 : : *
2204 : : * @param[in] priv
2205 : : * Pointer to the private device data structure.
2206 : : *
2207 : : * @return
2208 : : * Zero on success, positive error code otherwise.
2209 : : */
2210 : : int
2211 : 0 : mlx5_alloc_table_hash_list(struct mlx5_priv *priv __rte_unused)
2212 : : {
2213 : : int err = 0;
2214 : :
2215 : : /* Tables are only used in DV and DR modes. */
2216 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
2217 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2218 : : char s[MLX5_NAME_SIZE];
2219 : :
2220 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2221 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2)
2222 : 0 : return mlx5_alloc_hw_group_hash_list(priv);
2223 : : #endif
2224 : : MLX5_ASSERT(sh);
2225 : 0 : snprintf(s, sizeof(s), "%s_flow_table", priv->sh->ibdev_name);
2226 : 0 : sh->flow_tbls = mlx5_hlist_create(s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE,
2227 : : false, true, sh,
2228 : : mlx5_flow_dv_tbl_create_cb,
2229 : : mlx5_flow_dv_tbl_match_cb,
2230 : : mlx5_flow_dv_tbl_remove_cb,
2231 : : mlx5_flow_dv_tbl_clone_cb,
2232 : : mlx5_flow_dv_tbl_clone_free_cb);
2233 [ # # ]: 0 : if (!sh->flow_tbls) {
2234 : 0 : DRV_LOG(ERR, "flow tables with hash creation failed.");
2235 : : err = ENOMEM;
2236 : 0 : return err;
2237 : : }
2238 : : #ifndef HAVE_MLX5DV_DR
2239 : : struct rte_flow_error error;
2240 : : struct rte_eth_dev *dev = &rte_eth_devices[priv->dev_data->port_id];
2241 : :
2242 : : /*
2243 : : * In case we have not DR support, the zero tables should be created
2244 : : * because DV expect to see them even if they cannot be created by
2245 : : * RDMA-CORE.
2246 : : */
2247 : : if (!mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 0, 0,
2248 : : NULL, 0, 1, 0, &error) ||
2249 : : !mlx5_flow_dv_tbl_resource_get(dev, 0, 1, 0, 0,
2250 : : NULL, 0, 1, 0, &error) ||
2251 : : !mlx5_flow_dv_tbl_resource_get(dev, 0, 0, 1, 0,
2252 : : NULL, 0, 1, 0, &error)) {
2253 : : err = ENOMEM;
2254 : : goto error;
2255 : : }
2256 : : return err;
2257 : : error:
2258 : : mlx5_free_table_hash_list(priv);
2259 : : #endif /* HAVE_MLX5DV_DR */
2260 : : #endif
2261 : : return err;
2262 : : }
2263 : :
2264 : : /**
2265 : : * Retrieve integer value from environment variable.
2266 : : *
2267 : : * @param[in] name
2268 : : * Environment variable name.
2269 : : *
2270 : : * @return
2271 : : * Integer value, 0 if the variable is not set.
2272 : : */
2273 : : int
2274 : 0 : mlx5_getenv_int(const char *name)
2275 : : {
2276 : 0 : const char *val = getenv(name);
2277 : :
2278 [ # # ]: 0 : if (val == NULL)
2279 : : return 0;
2280 : 0 : return atoi(val);
2281 : : }
2282 : :
2283 : : /**
2284 : : * DPDK callback to add udp tunnel port
2285 : : *
2286 : : * @param[in] dev
2287 : : * A pointer to eth_dev
2288 : : * @param[in] udp_tunnel
2289 : : * A pointer to udp tunnel
2290 : : *
2291 : : * @return
2292 : : * 0 on valid udp ports and tunnels, -ENOTSUP otherwise.
2293 : : */
2294 : : int
2295 : 0 : mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev __rte_unused,
2296 : : struct rte_eth_udp_tunnel *udp_tunnel)
2297 : : {
2298 : : MLX5_ASSERT(udp_tunnel != NULL);
2299 [ # # ]: 0 : if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN &&
2300 [ # # ]: 0 : udp_tunnel->udp_port == 4789)
2301 : : return 0;
2302 [ # # ]: 0 : if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN_GPE &&
2303 [ # # ]: 0 : udp_tunnel->udp_port == 4790)
2304 : 0 : return 0;
2305 : : return -ENOTSUP;
2306 : : }
2307 : :
2308 : : /**
2309 : : * Initialize process private data structure.
2310 : : *
2311 : : * @param dev
2312 : : * Pointer to Ethernet device structure.
2313 : : *
2314 : : * @return
2315 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2316 : : */
2317 : : int
2318 : 0 : mlx5_proc_priv_init(struct rte_eth_dev *dev)
2319 : : {
2320 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2321 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
2322 : : struct mlx5_proc_priv *ppriv;
2323 : : size_t ppriv_size;
2324 : :
2325 : 0 : mlx5_proc_priv_uninit(dev);
2326 : : /*
2327 : : * UAR register table follows the process private structure. BlueFlame
2328 : : * registers for Tx queues are stored in the table.
2329 : : */
2330 : 0 : ppriv_size = sizeof(struct mlx5_proc_priv) +
2331 : 0 : priv->txqs_n * sizeof(struct mlx5_uar_data);
2332 [ # # # # : 0 : ppriv = mlx5_malloc_numa_tolerant(MLX5_MEM_RTE | MLX5_MEM_ZERO, ppriv_size,
# # ]
2333 : : RTE_CACHE_LINE_SIZE, dev->device->numa_node);
2334 [ # # ]: 0 : if (!ppriv) {
2335 : 0 : rte_errno = ENOMEM;
2336 : 0 : return -rte_errno;
2337 : : }
2338 : 0 : ppriv->uar_table_sz = priv->txqs_n;
2339 : 0 : dev->process_private = ppriv;
2340 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2341 : 0 : priv->sh->pppriv = ppriv;
2342 : : /* Check and try to map HCA PCI BAR to allow reading real time. */
2343 [ # # # # ]: 0 : if (sh->dev_cap.rt_timestamp && mlx5_dev_is_pci(dev->device))
2344 : 0 : mlx5_txpp_map_hca_bar(dev);
2345 : : return 0;
2346 : : }
2347 : :
2348 : : /**
2349 : : * Un-initialize process private data structure.
2350 : : *
2351 : : * @param dev
2352 : : * Pointer to Ethernet device structure.
2353 : : */
2354 : : void
2355 : 0 : mlx5_proc_priv_uninit(struct rte_eth_dev *dev)
2356 : : {
2357 : 0 : struct mlx5_proc_priv *ppriv = dev->process_private;
2358 : :
2359 [ # # ]: 0 : if (!ppriv)
2360 : : return;
2361 [ # # ]: 0 : if (ppriv->hca_bar)
2362 : 0 : mlx5_txpp_unmap_hca_bar(dev);
2363 : 0 : mlx5_free(dev->process_private);
2364 : 0 : dev->process_private = NULL;
2365 : : }
2366 : :
2367 : : static void
2368 : : mlx5_flow_pools_destroy(struct mlx5_priv *priv)
2369 : : {
2370 : : int i;
2371 : :
2372 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
2373 [ # # ]: 0 : if (!priv->flows[i])
2374 : 0 : continue;
2375 : 0 : mlx5_ipool_destroy(priv->flows[i]);
2376 : : }
2377 : : }
2378 : :
2379 : : /**
2380 : : * DPDK callback to close the device.
2381 : : *
2382 : : * Destroy all queues and objects, free memory.
2383 : : *
2384 : : * @param dev
2385 : : * Pointer to Ethernet device structure.
2386 : : */
2387 : : int
2388 : 0 : mlx5_dev_close(struct rte_eth_dev *dev)
2389 : : {
2390 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
2391 : : struct mlx5_dev_ctx_shared *sh;
2392 : : unsigned int i;
2393 : : int ret;
2394 : :
2395 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
2396 [ # # ]: 0 : if (!priv)
2397 : 0 : DRV_LOG(WARNING, "primary process is already closed");
2398 : : /* Check if process_private released. */
2399 [ # # ]: 0 : if (!dev->process_private)
2400 : : return 0;
2401 : 0 : mlx5_tx_uar_uninit_secondary(dev);
2402 : 0 : mlx5_proc_priv_uninit(dev);
2403 : 0 : rte_eth_dev_release_port(dev);
2404 : 0 : return 0;
2405 : : }
2406 : 0 : sh = priv->sh;
2407 [ # # ]: 0 : if (!sh)
2408 : : return 0;
2409 [ # # ]: 0 : if (priv->shared_refcnt) {
2410 : 0 : DRV_LOG(ERR, "port %u is shared host in use (%u)",
2411 : : dev->data->port_id, priv->shared_refcnt);
2412 : 0 : rte_errno = EBUSY;
2413 : 0 : return -EBUSY;
2414 : : }
2415 : 0 : DRV_LOG(DEBUG, "port %u closing device \"%s\"",
2416 : : dev->data->port_id, sh->ibdev_name);
2417 : : /*
2418 : : * If default mreg copy action is removed at the stop stage,
2419 : : * the search will return none and nothing will be done anymore.
2420 : : */
2421 : 0 : mlx5_flow_stop_default(dev);
2422 : 0 : mlx5_traffic_disable(dev);
2423 : : /*
2424 : : * If all the flows are already flushed in the device stop stage,
2425 : : * then this will return directly without any action.
2426 : : */
2427 : 0 : mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
2428 : 0 : mlx5_action_handle_flush(dev);
2429 : 0 : mlx5_flow_meter_flush(dev, NULL);
2430 : : /* Prevent crashes when queues are still in use. */
2431 : 0 : dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
2432 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
2433 : : rte_wmb();
2434 : : /* Disable datapath on secondary process. */
2435 : 0 : mlx5_mp_os_req_stop_rxtx(dev);
2436 : : /* Free the eCPRI flex parser resource. */
2437 : 0 : mlx5_flex_parser_ecpri_release(dev);
2438 : 0 : mlx5_flex_item_port_cleanup(dev);
2439 [ # # ]: 0 : if (priv->representor) {
2440 : : /* Each representor has a dedicated interrupts handler */
2441 : 0 : rte_intr_instance_free(dev->intr_handle);
2442 : 0 : dev->intr_handle = NULL;
2443 : : }
2444 : 0 : mlx5_indirect_list_handles_release(dev);
2445 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2446 : 0 : mlx5_nta_sample_context_free(dev);
2447 : 0 : mlx5_flow_hw_destroy_vport_action(dev);
2448 : : /* dr context will be closed after mlx5_os_free_shared_dr. */
2449 : 0 : mlx5_flow_hw_resource_release(dev);
2450 : 0 : mlx5_flow_hw_clear_port_info(dev);
2451 [ # # ]: 0 : if (priv->tlv_options != NULL) {
2452 : : /* Free the GENEVE TLV parser resource. */
2453 : 0 : claim_zero(mlx5_geneve_tlv_options_destroy(priv->tlv_options, sh->phdev));
2454 : 0 : priv->tlv_options = NULL;
2455 : : }
2456 [ # # ]: 0 : if (priv->ptype_rss_groups) {
2457 : 0 : mlx5_ipool_destroy(priv->ptype_rss_groups);
2458 : 0 : priv->ptype_rss_groups = NULL;
2459 : : }
2460 : : #endif
2461 [ # # ]: 0 : if (priv->rxq_privs != NULL) {
2462 : : /* XXX race condition if mlx5_rx_burst() is still running. */
2463 : 0 : rte_delay_us_sleep(1000);
2464 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i)
2465 : 0 : mlx5_rxq_release(dev, i);
2466 : 0 : priv->rxqs_n = 0;
2467 : 0 : mlx5_free(priv->rxq_privs);
2468 : 0 : priv->rxq_privs = NULL;
2469 : : }
2470 [ # # # # ]: 0 : if (priv->txqs != NULL && dev->data->tx_queues != NULL) {
2471 : : /* XXX race condition if mlx5_tx_burst() is still running. */
2472 : 0 : rte_delay_us_sleep(1000);
2473 [ # # ]: 0 : for (i = 0; (i != priv->txqs_n); ++i)
2474 : 0 : mlx5_txq_release(dev, i);
2475 : 0 : priv->txqs_n = 0;
2476 : 0 : priv->txqs = NULL;
2477 : : }
2478 : 0 : mlx5_proc_priv_uninit(dev);
2479 [ # # ]: 0 : if (priv->drop_queue.hrxq)
2480 : 0 : mlx5_drop_action_destroy(dev);
2481 : 0 : mlx5_q_counters_destroy(dev);
2482 : 0 : mlx5_mprq_free_mp(dev);
2483 : 0 : mlx5_os_free_shared_dr(priv);
2484 : : #ifdef HAVE_MLX5_HWS_SUPPORT
2485 [ # # ]: 0 : if (priv->dr_ctx) {
2486 : 0 : claim_zero(mlx5dr_context_close(priv->dr_ctx));
2487 : 0 : priv->dr_ctx = NULL;
2488 : : }
2489 : : #endif
2490 [ # # ]: 0 : if (priv->rss_conf.rss_key != NULL)
2491 : 0 : mlx5_free(priv->rss_conf.rss_key);
2492 [ # # ]: 0 : if (priv->reta_idx != NULL)
2493 : 0 : mlx5_free(priv->reta_idx);
2494 [ # # ]: 0 : if (sh->dev_cap.vf)
2495 : 0 : mlx5_os_mac_addr_flush(dev);
2496 [ # # ]: 0 : if (priv->nl_socket_route >= 0)
2497 : 0 : close(priv->nl_socket_route);
2498 [ # # ]: 0 : if (priv->nl_socket_rdma >= 0)
2499 : 0 : close(priv->nl_socket_rdma);
2500 [ # # ]: 0 : if (priv->vmwa_context)
2501 : 0 : mlx5_vlan_vmwa_exit(priv->vmwa_context);
2502 : 0 : ret = mlx5_hrxq_verify(dev);
2503 [ # # ]: 0 : if (ret)
2504 : 0 : DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
2505 : : dev->data->port_id);
2506 : 0 : ret = mlx5_ind_table_obj_verify(dev);
2507 [ # # ]: 0 : if (ret)
2508 : 0 : DRV_LOG(WARNING, "port %u some indirection table still remain",
2509 : : dev->data->port_id);
2510 : 0 : ret = mlx5_rxq_obj_verify(dev);
2511 [ # # ]: 0 : if (ret)
2512 : 0 : DRV_LOG(WARNING, "port %u some Rx queue objects still remain",
2513 : : dev->data->port_id);
2514 : 0 : ret = mlx5_ext_rxq_verify(dev);
2515 [ # # ]: 0 : if (ret)
2516 : 0 : DRV_LOG(WARNING, "Port %u some external RxQ still remain.",
2517 : : dev->data->port_id);
2518 : 0 : ret = mlx5_rxq_verify(dev);
2519 [ # # ]: 0 : if (ret)
2520 : 0 : DRV_LOG(WARNING, "port %u some Rx queues still remain",
2521 : : dev->data->port_id);
2522 : 0 : ret = mlx5_txq_obj_verify(dev);
2523 [ # # ]: 0 : if (ret)
2524 : 0 : DRV_LOG(WARNING, "port %u some Verbs Tx queue still remain",
2525 : : dev->data->port_id);
2526 : 0 : ret = mlx5_ext_txq_verify(dev);
2527 [ # # ]: 0 : if (ret)
2528 : 0 : DRV_LOG(WARNING, "Port %u some external TxQ still remain.",
2529 : : dev->data->port_id);
2530 : 0 : ret = mlx5_txq_verify(dev);
2531 [ # # ]: 0 : if (ret)
2532 : 0 : DRV_LOG(WARNING, "port %u some Tx queues still remain",
2533 : : dev->data->port_id);
2534 : 0 : ret = mlx5_flow_verify(dev);
2535 [ # # ]: 0 : if (ret)
2536 : 0 : DRV_LOG(WARNING, "port %u some flows still remain",
2537 : : dev->data->port_id);
2538 [ # # ]: 0 : if (priv->hrxqs)
2539 : 0 : mlx5_list_destroy(priv->hrxqs);
2540 : 0 : mlx5_free(priv->ext_rxqs);
2541 : 0 : mlx5_free(priv->ext_txqs);
2542 : 0 : sh->port[priv->dev_port - 1].nl_ih_port_id = RTE_MAX_ETHPORTS;
2543 : : /*
2544 : : * The interrupt handler port id must be reset before priv is reset
2545 : : * since 'mlx5_dev_interrupt_nl_cb' uses priv.
2546 : : */
2547 : 0 : rte_io_wmb();
2548 : : /*
2549 : : * Free the shared context in last turn, because the cleanup
2550 : : * routines above may use some shared fields, like
2551 : : * mlx5_os_mac_addr_flush() uses ibdev_path for retrieving
2552 : : * ifindex if Netlink fails.
2553 : : */
2554 : 0 : mlx5_free_shared_dev_ctx(sh);
2555 [ # # ]: 0 : if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
2556 : : unsigned int c = 0;
2557 : : uint16_t port_id;
2558 : :
2559 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
2560 : 0 : struct mlx5_priv *opriv =
2561 : 0 : rte_eth_devices[port_id].data->dev_private;
2562 : :
2563 [ # # ]: 0 : if (!opriv ||
2564 [ # # ]: 0 : opriv->domain_id != priv->domain_id ||
2565 [ # # ]: 0 : &rte_eth_devices[port_id] == dev)
2566 : : continue;
2567 : : ++c;
2568 : : break;
2569 : : }
2570 [ # # ]: 0 : if (!c)
2571 : 0 : claim_zero(rte_eth_switch_domain_free(priv->domain_id));
2572 : : }
2573 : : mlx5_flow_pools_destroy(priv);
2574 : : memset(priv, 0, sizeof(*priv));
2575 : 0 : priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
2576 : : /*
2577 : : * Reset mac_addrs to NULL such that it is not freed as part of
2578 : : * rte_eth_dev_release_port(). mac_addrs is part of dev_private so
2579 : : * it is freed when dev_private is freed.
2580 : : */
2581 : 0 : dev->data->mac_addrs = NULL;
2582 : 0 : return 0;
2583 : : }
2584 : :
2585 : : const struct eth_dev_ops mlx5_dev_ops = {
2586 : : .dev_configure = mlx5_dev_configure,
2587 : : .dev_start = mlx5_dev_start,
2588 : : .dev_stop = mlx5_dev_stop,
2589 : : .dev_set_link_down = mlx5_set_link_down,
2590 : : .dev_set_link_up = mlx5_set_link_up,
2591 : : .dev_close = mlx5_dev_close,
2592 : : .promiscuous_enable = mlx5_promiscuous_enable,
2593 : : .promiscuous_disable = mlx5_promiscuous_disable,
2594 : : .allmulticast_enable = mlx5_allmulticast_enable,
2595 : : .allmulticast_disable = mlx5_allmulticast_disable,
2596 : : .link_update = mlx5_link_update,
2597 : : .stats_get = mlx5_stats_get,
2598 : : .stats_reset = mlx5_stats_reset,
2599 : : .xstats_get = mlx5_xstats_get,
2600 : : .xstats_reset = mlx5_xstats_reset,
2601 : : .xstats_get_names = mlx5_xstats_get_names,
2602 : :
2603 : : .xstats_enable = mlx5_xstats_enable,
2604 : : .xstats_disable = mlx5_xstats_disable,
2605 : : .xstats_query_state = mlx5_xstats_query_state,
2606 : :
2607 : : .fw_version_get = mlx5_fw_version_get,
2608 : : .dev_infos_get = mlx5_dev_infos_get,
2609 : : .representor_info_get = mlx5_representor_info_get,
2610 : : .read_clock = mlx5_txpp_read_clock,
2611 : : .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
2612 : : .vlan_filter_set = mlx5_vlan_filter_set,
2613 : : .rx_queue_setup = mlx5_rx_queue_setup,
2614 : : .rx_queue_avail_thresh_set = mlx5_rx_queue_lwm_set,
2615 : : .rx_queue_avail_thresh_query = mlx5_rx_queue_lwm_query,
2616 : : .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
2617 : : .tx_queue_setup = mlx5_tx_queue_setup,
2618 : : .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
2619 : : .rx_queue_release = mlx5_rx_queue_release,
2620 : : .tx_queue_release = mlx5_tx_queue_release,
2621 : : .rx_queue_start = mlx5_rx_queue_start,
2622 : : .rx_queue_stop = mlx5_rx_queue_stop,
2623 : : .tx_queue_start = mlx5_tx_queue_start,
2624 : : .tx_queue_stop = mlx5_tx_queue_stop,
2625 : : .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
2626 : : .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
2627 : : .mac_addr_remove = mlx5_mac_addr_remove,
2628 : : .mac_addr_add = mlx5_mac_addr_add,
2629 : : .mac_addr_set = mlx5_mac_addr_set,
2630 : : .set_mc_addr_list = mlx5_set_mc_addr_list,
2631 : : .mtu_set = mlx5_dev_set_mtu,
2632 : : .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
2633 : : .vlan_offload_set = mlx5_vlan_offload_set,
2634 : : .reta_update = mlx5_dev_rss_reta_update,
2635 : : .reta_query = mlx5_dev_rss_reta_query,
2636 : : .rss_hash_update = mlx5_rss_hash_update,
2637 : : .rss_hash_conf_get = mlx5_rss_hash_conf_get,
2638 : : .flow_ops_get = mlx5_flow_ops_get,
2639 : : .rxq_info_get = mlx5_rxq_info_get,
2640 : : .txq_info_get = mlx5_txq_info_get,
2641 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2642 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2643 : : .rx_queue_intr_enable = mlx5_rx_intr_enable,
2644 : : .rx_queue_intr_disable = mlx5_rx_intr_disable,
2645 : : .is_removed = mlx5_is_removed,
2646 : : .udp_tunnel_port_add = mlx5_udp_tunnel_port_add,
2647 : : .get_module_info = mlx5_get_module_info,
2648 : : .get_module_eeprom = mlx5_get_module_eeprom,
2649 : : .hairpin_cap_get = mlx5_hairpin_cap_get,
2650 : : .mtr_ops_get = mlx5_flow_meter_ops_get,
2651 : : .hairpin_bind = mlx5_hairpin_bind,
2652 : : .hairpin_unbind = mlx5_hairpin_unbind,
2653 : : .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
2654 : : .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
2655 : : .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
2656 : : .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
2657 : : .get_monitor_addr = mlx5_get_monitor_addr,
2658 : : .count_aggr_ports = mlx5_count_aggr_ports,
2659 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2660 : : .rx_metadata_negotiate = mlx5_flow_rx_metadata_negotiate,
2661 : : .get_restore_flags = mlx5_get_restore_flags,
2662 : : .set_queue_rate_limit = mlx5_set_queue_rate_limit,
2663 : : .get_queue_rate_limit = mlx5_get_queue_rate_limit,
2664 : : };
2665 : :
2666 : : /* Available operations from secondary process. */
2667 : : const struct eth_dev_ops mlx5_dev_sec_ops = {
2668 : : .stats_get = mlx5_stats_get,
2669 : : .stats_reset = mlx5_stats_reset,
2670 : : .xstats_get = mlx5_xstats_get,
2671 : : .xstats_reset = mlx5_xstats_reset,
2672 : : .xstats_get_names = mlx5_xstats_get_names,
2673 : : .fw_version_get = mlx5_fw_version_get,
2674 : : .dev_infos_get = mlx5_dev_infos_get,
2675 : : .representor_info_get = mlx5_representor_info_get,
2676 : : .read_clock = mlx5_txpp_read_clock,
2677 : : .rx_queue_start = mlx5_rx_queue_start,
2678 : : .rx_queue_stop = mlx5_rx_queue_stop,
2679 : : .tx_queue_start = mlx5_tx_queue_start,
2680 : : .tx_queue_stop = mlx5_tx_queue_stop,
2681 : : .rxq_info_get = mlx5_rxq_info_get,
2682 : : .txq_info_get = mlx5_txq_info_get,
2683 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2684 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2685 : : .get_module_info = mlx5_get_module_info,
2686 : : .get_module_eeprom = mlx5_get_module_eeprom,
2687 : : .count_aggr_ports = mlx5_count_aggr_ports,
2688 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2689 : : .rx_metadata_negotiate = mlx5_flow_rx_metadata_negotiate,
2690 : : };
2691 : :
2692 : : /* Available operations in flow isolated mode. */
2693 : : const struct eth_dev_ops mlx5_dev_ops_isolate = {
2694 : : .dev_configure = mlx5_dev_configure,
2695 : : .dev_start = mlx5_dev_start,
2696 : : .dev_stop = mlx5_dev_stop,
2697 : : .dev_set_link_down = mlx5_set_link_down,
2698 : : .dev_set_link_up = mlx5_set_link_up,
2699 : : .dev_close = mlx5_dev_close,
2700 : : .promiscuous_enable = mlx5_promiscuous_enable,
2701 : : .promiscuous_disable = mlx5_promiscuous_disable,
2702 : : .allmulticast_enable = mlx5_allmulticast_enable,
2703 : : .allmulticast_disable = mlx5_allmulticast_disable,
2704 : : .link_update = mlx5_link_update,
2705 : : .stats_get = mlx5_stats_get,
2706 : : .stats_reset = mlx5_stats_reset,
2707 : : .xstats_get = mlx5_xstats_get,
2708 : : .xstats_reset = mlx5_xstats_reset,
2709 : : .xstats_get_names = mlx5_xstats_get_names,
2710 : : .fw_version_get = mlx5_fw_version_get,
2711 : : .dev_infos_get = mlx5_dev_infos_get,
2712 : : .representor_info_get = mlx5_representor_info_get,
2713 : : .read_clock = mlx5_txpp_read_clock,
2714 : : .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
2715 : : .vlan_filter_set = mlx5_vlan_filter_set,
2716 : : .rx_queue_setup = mlx5_rx_queue_setup,
2717 : : .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
2718 : : .tx_queue_setup = mlx5_tx_queue_setup,
2719 : : .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
2720 : : .rx_queue_release = mlx5_rx_queue_release,
2721 : : .tx_queue_release = mlx5_tx_queue_release,
2722 : : .rx_queue_start = mlx5_rx_queue_start,
2723 : : .rx_queue_stop = mlx5_rx_queue_stop,
2724 : : .tx_queue_start = mlx5_tx_queue_start,
2725 : : .tx_queue_stop = mlx5_tx_queue_stop,
2726 : : .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
2727 : : .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
2728 : : .mac_addr_remove = mlx5_mac_addr_remove,
2729 : : .mac_addr_add = mlx5_mac_addr_add,
2730 : : .mac_addr_set = mlx5_mac_addr_set,
2731 : : .set_mc_addr_list = mlx5_set_mc_addr_list,
2732 : : .mtu_set = mlx5_dev_set_mtu,
2733 : : .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
2734 : : .vlan_offload_set = mlx5_vlan_offload_set,
2735 : : .flow_ops_get = mlx5_flow_ops_get,
2736 : : .rxq_info_get = mlx5_rxq_info_get,
2737 : : .txq_info_get = mlx5_txq_info_get,
2738 : : .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2739 : : .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2740 : : .rx_queue_intr_enable = mlx5_rx_intr_enable,
2741 : : .rx_queue_intr_disable = mlx5_rx_intr_disable,
2742 : : .is_removed = mlx5_is_removed,
2743 : : .get_module_info = mlx5_get_module_info,
2744 : : .get_module_eeprom = mlx5_get_module_eeprom,
2745 : : .hairpin_cap_get = mlx5_hairpin_cap_get,
2746 : : .mtr_ops_get = mlx5_flow_meter_ops_get,
2747 : : .hairpin_bind = mlx5_hairpin_bind,
2748 : : .hairpin_unbind = mlx5_hairpin_unbind,
2749 : : .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
2750 : : .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
2751 : : .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
2752 : : .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
2753 : : .get_monitor_addr = mlx5_get_monitor_addr,
2754 : : .count_aggr_ports = mlx5_count_aggr_ports,
2755 : : .map_aggr_tx_affinity = mlx5_map_aggr_tx_affinity,
2756 : : .get_restore_flags = mlx5_get_restore_flags,
2757 : : .set_queue_rate_limit = mlx5_set_queue_rate_limit,
2758 : : .get_queue_rate_limit = mlx5_get_queue_rate_limit,
2759 : : };
2760 : :
2761 : : /**
2762 : : * Verify and store value for device argument.
2763 : : *
2764 : : * @param[in] key
2765 : : * Key argument to verify.
2766 : : * @param[in] val
2767 : : * Value associated with key.
2768 : : * @param opaque
2769 : : * User data.
2770 : : *
2771 : : * @return
2772 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2773 : : */
2774 : : static int
2775 : 0 : mlx5_port_args_check_handler(const char *key, const char *val, void *opaque)
2776 : : {
2777 : : struct mlx5_port_config *config = opaque;
2778 : : signed long tmp;
2779 : :
2780 : : /* No-op, port representors are processed in mlx5_dev_spawn(). */
2781 [ # # ]: 0 : if (!strcmp(MLX5_REPRESENTOR, key))
2782 : : return 0;
2783 : 0 : errno = 0;
2784 : 0 : tmp = strtol(val, NULL, 0);
2785 [ # # ]: 0 : if (errno) {
2786 : 0 : rte_errno = errno;
2787 : 0 : DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
2788 : 0 : return -rte_errno;
2789 : : }
2790 [ # # ]: 0 : if (tmp < 0) {
2791 : : /* Negative values are acceptable for some keys only. */
2792 : 0 : rte_errno = EINVAL;
2793 : 0 : DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
2794 : 0 : return -rte_errno;
2795 : : }
2796 [ # # ]: 0 : if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
2797 [ # # ]: 0 : if ((tmp & ~MLX5_RXQ_ENH_CQE_COMP_MASK) >
2798 : : MLX5_CQE_RESP_FORMAT_L34H_STRIDX) {
2799 : 0 : DRV_LOG(ERR, "invalid CQE compression "
2800 : : "format parameter");
2801 : 0 : rte_errno = EINVAL;
2802 : 0 : return -rte_errno;
2803 : : }
2804 : 0 : config->cqe_comp = !!tmp;
2805 : 0 : config->cqe_comp_fmt = tmp & ~MLX5_RXQ_ENH_CQE_COMP_MASK;
2806 : 0 : config->enh_cqe_comp = !!(tmp & MLX5_RXQ_ENH_CQE_COMP_MASK);
2807 [ # # ]: 0 : } else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
2808 : 0 : config->hw_padding = !!tmp;
2809 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
2810 : 0 : config->mprq.enabled = !!tmp;
2811 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_NUM, key) == 0) {
2812 : 0 : config->mprq.log_stride_num = tmp;
2813 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_SIZE, key) == 0) {
2814 : 0 : config->mprq.log_stride_size = tmp;
2815 [ # # ]: 0 : } else if (strcmp(MLX5_RX_MPRQ_MAX_MEMCPY_LEN, key) == 0) {
2816 : 0 : config->mprq.max_memcpy_len = tmp;
2817 [ # # ]: 0 : } else if (strcmp(MLX5_RXQS_MIN_MPRQ, key) == 0) {
2818 : 0 : config->mprq.min_rxqs_num = tmp;
2819 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
2820 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter,"
2821 : : " converted to txq_inline_max", key);
2822 : 0 : config->txq_inline_max = tmp;
2823 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MAX, key) == 0) {
2824 : 0 : config->txq_inline_max = tmp;
2825 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MIN, key) == 0) {
2826 : 0 : config->txq_inline_min = tmp;
2827 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_INLINE_MPW, key) == 0) {
2828 : 0 : config->txq_inline_mpw = tmp;
2829 [ # # ]: 0 : } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
2830 : 0 : config->txqs_inline = tmp;
2831 [ # # ]: 0 : } else if (strcmp(MLX5_TXQS_MAX_VEC, key) == 0) {
2832 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2833 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
2834 : 0 : config->mps = !!tmp;
2835 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MPW_HDR_DSEG_EN, key) == 0) {
2836 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2837 [ # # ]: 0 : } else if (strcmp(MLX5_TXQ_MAX_INLINE_LEN, key) == 0) {
2838 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter,"
2839 : : " converted to txq_inline_mpw", key);
2840 : 0 : config->txq_inline_mpw = tmp;
2841 [ # # ]: 0 : } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
2842 : 0 : DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2843 [ # # ]: 0 : } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
2844 : 0 : config->rx_vec_en = !!tmp;
2845 [ # # ]: 0 : } else if (strcmp(MLX5_MAX_DUMP_FILES_NUM, key) == 0) {
2846 : 0 : config->max_dump_files_num = tmp;
2847 [ # # ]: 0 : } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) {
2848 : 0 : config->lro_timeout = tmp;
2849 [ # # ]: 0 : } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) {
2850 : 0 : config->log_hp_size = tmp;
2851 [ # # ]: 0 : } else if (strcmp(MLX5_DELAY_DROP, key) == 0) {
2852 : 0 : config->std_delay_drop = !!(tmp & MLX5_DELAY_DROP_STANDARD);
2853 : 0 : config->hp_delay_drop = !!(tmp & MLX5_DELAY_DROP_HAIRPIN);
2854 : : }
2855 : : return 0;
2856 : : }
2857 : :
2858 : : /**
2859 : : * Parse user port parameters and adjust them according to device capabilities.
2860 : : *
2861 : : * @param priv
2862 : : * Pointer to shared device context.
2863 : : * @param mkvlist
2864 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
2865 : : * @param config
2866 : : * Pointer to port configuration structure.
2867 : : *
2868 : : * @return
2869 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2870 : : */
2871 : : int
2872 : 0 : mlx5_port_args_config(struct mlx5_priv *priv, struct mlx5_kvargs_ctrl *mkvlist,
2873 : : struct mlx5_port_config *config)
2874 : : {
2875 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2876 : : struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
2877 : 0 : bool devx = priv->sh->cdev->config.devx;
2878 [ # # ]: 0 : const char **params = (const char *[]){
2879 : : MLX5_RXQ_CQE_COMP_EN,
2880 : : MLX5_RXQ_PKT_PAD_EN,
2881 : : MLX5_RX_MPRQ_EN,
2882 : : MLX5_RX_MPRQ_LOG_STRIDE_NUM,
2883 : : MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
2884 : : MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
2885 : : MLX5_RXQS_MIN_MPRQ,
2886 : : MLX5_TXQ_INLINE,
2887 : : MLX5_TXQ_INLINE_MIN,
2888 : : MLX5_TXQ_INLINE_MAX,
2889 : : MLX5_TXQ_INLINE_MPW,
2890 : : MLX5_TXQS_MIN_INLINE,
2891 : : MLX5_TXQS_MAX_VEC,
2892 : : MLX5_TXQ_MPW_EN,
2893 : : MLX5_TXQ_MPW_HDR_DSEG_EN,
2894 : : MLX5_TXQ_MAX_INLINE_LEN,
2895 : : MLX5_TX_VEC_EN,
2896 : : MLX5_RX_VEC_EN,
2897 : : MLX5_REPRESENTOR,
2898 : : MLX5_MAX_DUMP_FILES_NUM,
2899 : : MLX5_LRO_TIMEOUT_USEC,
2900 : : MLX5_HP_BUF_SIZE,
2901 : : MLX5_DELAY_DROP,
2902 : : NULL,
2903 : : };
2904 : : int ret = 0;
2905 : :
2906 : : /* Default configuration. */
2907 : : memset(config, 0, sizeof(*config));
2908 : 0 : config->mps = MLX5_ARG_UNSET;
2909 : 0 : config->cqe_comp = 1;
2910 : 0 : config->rx_vec_en = 1;
2911 : 0 : config->txq_inline_max = MLX5_ARG_UNSET;
2912 : 0 : config->txq_inline_min = MLX5_ARG_UNSET;
2913 : 0 : config->txq_inline_mpw = MLX5_ARG_UNSET;
2914 : 0 : config->txqs_inline = MLX5_ARG_UNSET;
2915 : 0 : config->mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN;
2916 : 0 : config->mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS;
2917 : 0 : config->mprq.log_stride_num = MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM;
2918 : 0 : config->mprq.log_stride_size = MLX5_ARG_UNSET;
2919 : 0 : config->log_hp_size = MLX5_ARG_UNSET;
2920 : : config->std_delay_drop = 0;
2921 : : config->hp_delay_drop = 0;
2922 [ # # ]: 0 : if (mkvlist != NULL) {
2923 : : /* Process parameters. */
2924 : 0 : ret = mlx5_kvargs_process(mkvlist, params,
2925 : : mlx5_port_args_check_handler, config);
2926 [ # # ]: 0 : if (ret) {
2927 : 0 : DRV_LOG(ERR, "Failed to process port arguments: %s",
2928 : : strerror(rte_errno));
2929 : 0 : return -rte_errno;
2930 : : }
2931 : : }
2932 : : /* Adjust parameters according to device capabilities. */
2933 [ # # # # ]: 0 : if (config->hw_padding && !dev_cap->hw_padding) {
2934 : 0 : DRV_LOG(DEBUG, "Rx end alignment padding isn't supported.");
2935 : 0 : config->hw_padding = 0;
2936 [ # # ]: 0 : } else if (config->hw_padding) {
2937 : 0 : DRV_LOG(DEBUG, "Rx end alignment padding is enabled.");
2938 : : }
2939 : : /*
2940 : : * MPW is disabled by default, while the Enhanced MPW is enabled
2941 : : * by default.
2942 : : */
2943 [ # # ]: 0 : if (config->mps == MLX5_ARG_UNSET)
2944 : 0 : config->mps = (dev_cap->mps == MLX5_MPW_ENHANCED) ?
2945 [ # # ]: 0 : MLX5_MPW_ENHANCED : MLX5_MPW_DISABLED;
2946 : : else
2947 [ # # ]: 0 : config->mps = config->mps ? dev_cap->mps : MLX5_MPW_DISABLED;
2948 [ # # # # : 0 : DRV_LOG(INFO, "%sMPS is %s",
# # ]
2949 : : config->mps == MLX5_MPW_ENHANCED ? "enhanced " :
2950 : : config->mps == MLX5_MPW ? "legacy " : "",
2951 : : config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled");
2952 [ # # ]: 0 : if (priv->sh->config.lro_allowed) {
2953 : : /*
2954 : : * If LRO timeout is not configured by application,
2955 : : * use the minimal supported value.
2956 : : */
2957 [ # # ]: 0 : if (!config->lro_timeout)
2958 : 0 : config->lro_timeout =
2959 : 0 : hca_attr->lro_timer_supported_periods[0];
2960 : 0 : DRV_LOG(DEBUG, "LRO session timeout set to %d usec.",
2961 : : config->lro_timeout);
2962 : : }
2963 [ # # # # ]: 0 : if (config->cqe_comp && !dev_cap->cqe_comp) {
2964 : 0 : DRV_LOG(WARNING, "Rx CQE 128B compression is not supported.");
2965 : 0 : config->cqe_comp = 0;
2966 : : }
2967 [ # # # # ]: 0 : if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_FTAG_STRIDX &&
2968 [ # # ]: 0 : (!devx || !hca_attr->mini_cqe_resp_flow_tag)) {
2969 : 0 : DRV_LOG(WARNING,
2970 : : "Flow Tag CQE compression format isn't supported.");
2971 : 0 : config->cqe_comp = 0;
2972 : : }
2973 [ # # # # ]: 0 : if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_L34H_STRIDX &&
2974 [ # # ]: 0 : (!devx || !hca_attr->mini_cqe_resp_l3_l4_tag)) {
2975 : 0 : DRV_LOG(WARNING,
2976 : : "L3/L4 Header CQE compression format isn't supported.");
2977 : 0 : config->cqe_comp = 0;
2978 : : }
2979 [ # # # # ]: 0 : if (config->enh_cqe_comp && !hca_attr->enhanced_cqe_compression) {
2980 : 0 : DRV_LOG(WARNING,
2981 : : "Enhanced CQE compression isn't supported.");
2982 : 0 : config->enh_cqe_comp = 0;
2983 : : }
2984 [ # # # # ]: 0 : DRV_LOG(DEBUG, "%sRx CQE compression is %ssupported.",
2985 : : config->enh_cqe_comp ? "Enhanced " : "",
2986 : : config->cqe_comp ? "" : "not ");
2987 [ # # ]: 0 : if ((config->std_delay_drop || config->hp_delay_drop) &&
2988 [ # # ]: 0 : !dev_cap->rq_delay_drop_en) {
2989 : 0 : config->std_delay_drop = 0;
2990 : 0 : config->hp_delay_drop = 0;
2991 : 0 : DRV_LOG(WARNING, "dev_port-%u: Rxq delay drop isn't supported.",
2992 : : priv->dev_port);
2993 : : }
2994 [ # # # # ]: 0 : if (config->mprq.enabled && !priv->sh->dev_cap.mprq.enabled) {
2995 : 0 : DRV_LOG(WARNING, "Multi-Packet RQ isn't supported.");
2996 : 0 : config->mprq.enabled = 0;
2997 : : }
2998 [ # # ]: 0 : if (config->max_dump_files_num == 0)
2999 : 0 : config->max_dump_files_num = 128;
3000 : : /* Detect minimal data bytes to inline. */
3001 : 0 : mlx5_set_min_inline(priv);
3002 [ # # ]: 0 : DRV_LOG(DEBUG, "VLAN insertion in WQE is %ssupported.",
3003 : : config->hw_vlan_insert ? "" : "not ");
3004 : 0 : DRV_LOG(DEBUG, "\"rxq_pkt_pad_en\" is %u.", config->hw_padding);
3005 : 0 : DRV_LOG(DEBUG, "\"rxq_cqe_comp_en\" is %u.", config->cqe_comp);
3006 : 0 : DRV_LOG(DEBUG, "\"cqe_comp_fmt\" is %u.", config->cqe_comp_fmt);
3007 : 0 : DRV_LOG(DEBUG, "\"enh_cqe_comp\" is %u.", config->enh_cqe_comp);
3008 : 0 : DRV_LOG(DEBUG, "\"rx_vec_en\" is %u.", config->rx_vec_en);
3009 : 0 : DRV_LOG(DEBUG, "Standard \"delay_drop\" is %u.",
3010 : : config->std_delay_drop);
3011 : 0 : DRV_LOG(DEBUG, "Hairpin \"delay_drop\" is %u.", config->hp_delay_drop);
3012 : 0 : DRV_LOG(DEBUG, "\"max_dump_files_num\" is %u.",
3013 : : config->max_dump_files_num);
3014 : 0 : DRV_LOG(DEBUG, "\"log_hp_size\" is %u.", config->log_hp_size);
3015 : 0 : DRV_LOG(DEBUG, "\"mprq_en\" is %u.", config->mprq.enabled);
3016 : 0 : DRV_LOG(DEBUG, "\"mprq_log_stride_num\" is %u.",
3017 : : config->mprq.log_stride_num);
3018 : 0 : DRV_LOG(DEBUG, "\"mprq_log_stride_size\" is %u.",
3019 : : config->mprq.log_stride_size);
3020 : 0 : DRV_LOG(DEBUG, "\"mprq_max_memcpy_len\" is %u.",
3021 : : config->mprq.max_memcpy_len);
3022 : 0 : DRV_LOG(DEBUG, "\"rxqs_min_mprq\" is %u.", config->mprq.min_rxqs_num);
3023 : 0 : DRV_LOG(DEBUG, "\"lro_timeout_usec\" is %u.", config->lro_timeout);
3024 : 0 : DRV_LOG(DEBUG, "\"txq_mpw_en\" is %d.", config->mps);
3025 : 0 : DRV_LOG(DEBUG, "\"txqs_min_inline\" is %d.", config->txqs_inline);
3026 : 0 : DRV_LOG(DEBUG, "\"txq_inline_min\" is %d.", config->txq_inline_min);
3027 : 0 : DRV_LOG(DEBUG, "\"txq_inline_max\" is %d.", config->txq_inline_max);
3028 : 0 : DRV_LOG(DEBUG, "\"txq_inline_mpw\" is %d.", config->txq_inline_mpw);
3029 : 0 : return 0;
3030 : : }
3031 : :
3032 : : /**
3033 : : * Print the key for device argument.
3034 : : *
3035 : : * It is "dummy" handler whose whole purpose is to enable using
3036 : : * mlx5_kvargs_process() function which set devargs as used.
3037 : : *
3038 : : * @param key
3039 : : * Key argument.
3040 : : * @param val
3041 : : * Value associated with key, unused.
3042 : : * @param opaque
3043 : : * Unused, can be NULL.
3044 : : *
3045 : : * @return
3046 : : * 0 on success, function cannot fail.
3047 : : */
3048 : : static int
3049 : 0 : mlx5_dummy_handler(const char *key, const char *val, void *opaque)
3050 : : {
3051 : 0 : DRV_LOG(DEBUG, "\tKey: \"%s\" is set as used.", key);
3052 : : RTE_SET_USED(opaque);
3053 : : RTE_SET_USED(val);
3054 : 0 : return 0;
3055 : : }
3056 : :
3057 : : /**
3058 : : * Set requested devargs as used when device is already spawned.
3059 : : *
3060 : : * It is necessary since it is valid to ask probe again for existing device,
3061 : : * if its devargs don't assign as used, mlx5_kvargs_validate() will fail.
3062 : : *
3063 : : * @param name
3064 : : * Name of the existing device.
3065 : : * @param port_id
3066 : : * Port identifier of the device.
3067 : : * @param mkvlist
3068 : : * Pointer to mlx5 kvargs control to sign as used.
3069 : : */
3070 : : void
3071 : 0 : mlx5_port_args_set_used(const char *name, uint16_t port_id,
3072 : : struct mlx5_kvargs_ctrl *mkvlist)
3073 : : {
3074 : 0 : const char **params = (const char *[]){
3075 : : MLX5_RXQ_CQE_COMP_EN,
3076 : : MLX5_RXQ_PKT_PAD_EN,
3077 : : MLX5_RX_MPRQ_EN,
3078 : : MLX5_RX_MPRQ_LOG_STRIDE_NUM,
3079 : : MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
3080 : : MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
3081 : : MLX5_RXQS_MIN_MPRQ,
3082 : : MLX5_TXQ_INLINE,
3083 : : MLX5_TXQ_INLINE_MIN,
3084 : : MLX5_TXQ_INLINE_MAX,
3085 : : MLX5_TXQ_INLINE_MPW,
3086 : : MLX5_TXQS_MIN_INLINE,
3087 : : MLX5_TXQS_MAX_VEC,
3088 : : MLX5_TXQ_MPW_EN,
3089 : : MLX5_TXQ_MPW_HDR_DSEG_EN,
3090 : : MLX5_TXQ_MAX_INLINE_LEN,
3091 : : MLX5_TX_VEC_EN,
3092 : : MLX5_RX_VEC_EN,
3093 : : MLX5_REPRESENTOR,
3094 : : MLX5_MAX_DUMP_FILES_NUM,
3095 : : MLX5_LRO_TIMEOUT_USEC,
3096 : : MLX5_HP_BUF_SIZE,
3097 : : MLX5_DELAY_DROP,
3098 : : NULL,
3099 : : };
3100 : :
3101 : : /* Secondary process should not handle devargs. */
3102 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3103 : 0 : return;
3104 : : MLX5_ASSERT(mkvlist != NULL);
3105 : 0 : DRV_LOG(DEBUG, "Ethernet device \"%s\" for port %u "
3106 : : "already exists, set devargs as used:", name, port_id);
3107 : : /* This function cannot fail with this handler. */
3108 : 0 : mlx5_kvargs_process(mkvlist, params, mlx5_dummy_handler, NULL);
3109 : : }
3110 : :
3111 : : /**
3112 : : * Check sibling device configurations when probing again.
3113 : : *
3114 : : * Sibling devices sharing infiniband device context should have compatible
3115 : : * configurations. This regards representors and bonding device.
3116 : : *
3117 : : * @param cdev
3118 : : * Pointer to mlx5 device structure.
3119 : : * @param mkvlist
3120 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
3121 : : *
3122 : : * @return
3123 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3124 : : */
3125 : : int
3126 : 0 : mlx5_probe_again_args_validate(struct mlx5_common_device *cdev,
3127 : : struct mlx5_kvargs_ctrl *mkvlist)
3128 : : {
3129 : : struct mlx5_dev_ctx_shared *sh = NULL;
3130 : : struct mlx5_sh_config *config;
3131 : : int ret;
3132 : :
3133 : : /* Secondary process should not handle devargs. */
3134 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3135 : : return 0;
3136 : 0 : pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
3137 : : /* Search for IB context by common device pointer. */
3138 [ # # ]: 0 : LIST_FOREACH(sh, &dev_ctx_list, next)
3139 [ # # ]: 0 : if (sh->cdev == cdev)
3140 : : break;
3141 : 0 : pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
3142 : : /* There is sh for this device -> it isn't probe again. */
3143 [ # # ]: 0 : if (sh == NULL)
3144 : : return 0;
3145 : 0 : config = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
3146 : : sizeof(struct mlx5_sh_config),
3147 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
3148 [ # # ]: 0 : if (config == NULL) {
3149 : 0 : rte_errno = -ENOMEM;
3150 : 0 : return -rte_errno;
3151 : : }
3152 : : /*
3153 : : * Creates a temporary IB context configure structure according to new
3154 : : * devargs attached in probing again.
3155 : : */
3156 : 0 : ret = mlx5_shared_dev_ctx_args_config(sh, mkvlist, config);
3157 [ # # ]: 0 : if (ret) {
3158 : 0 : DRV_LOG(ERR, "Failed to process device configure: %s",
3159 : : strerror(rte_errno));
3160 : 0 : mlx5_free(config);
3161 : 0 : return ret;
3162 : : }
3163 : : /*
3164 : : * Checks the match between the temporary structure and the existing
3165 : : * IB context structure.
3166 : : */
3167 [ # # ]: 0 : if (sh->config.dv_flow_en ^ config->dv_flow_en) {
3168 : 0 : DRV_LOG(ERR, "\"dv_flow_en\" "
3169 : : "configuration mismatch for shared %s context.",
3170 : : sh->ibdev_name);
3171 : 0 : goto error;
3172 : : }
3173 [ # # ]: 0 : if ((sh->config.dv_xmeta_en ^ config->dv_xmeta_en) ||
3174 : : (sh->config.dv_miss_info ^ config->dv_miss_info)) {
3175 : 0 : DRV_LOG(ERR, "\"dv_xmeta_en\" "
3176 : : "configuration mismatch for shared %s context.",
3177 : : sh->ibdev_name);
3178 : 0 : goto error;
3179 : : }
3180 [ # # ]: 0 : if (sh->config.dv_esw_en ^ config->dv_esw_en) {
3181 : 0 : DRV_LOG(ERR, "\"dv_esw_en\" "
3182 : : "configuration mismatch for shared %s context.",
3183 : : sh->ibdev_name);
3184 : 0 : goto error;
3185 : : }
3186 [ # # ]: 0 : if (sh->config.reclaim_mode ^ config->reclaim_mode) {
3187 : 0 : DRV_LOG(ERR, "\"reclaim_mode\" "
3188 : : "configuration mismatch for shared %s context.",
3189 : : sh->ibdev_name);
3190 : 0 : goto error;
3191 : : }
3192 : 0 : if (sh->config.allow_duplicate_pattern ^
3193 [ # # ]: 0 : config->allow_duplicate_pattern) {
3194 : 0 : DRV_LOG(ERR, "\"allow_duplicate_pattern\" "
3195 : : "configuration mismatch for shared %s context.",
3196 : : sh->ibdev_name);
3197 : 0 : goto error;
3198 : : }
3199 [ # # ]: 0 : if (sh->config.fdb_def_rule ^ config->fdb_def_rule) {
3200 : 0 : DRV_LOG(ERR, "\"fdb_def_rule_en\" configuration mismatch for shared %s context.",
3201 : : sh->ibdev_name);
3202 : 0 : goto error;
3203 : : }
3204 [ # # ]: 0 : if (sh->config.l3_vxlan_en ^ config->l3_vxlan_en) {
3205 : 0 : DRV_LOG(ERR, "\"l3_vxlan_en\" "
3206 : : "configuration mismatch for shared %s context.",
3207 : : sh->ibdev_name);
3208 : 0 : goto error;
3209 : : }
3210 [ # # ]: 0 : if (sh->config.decap_en ^ config->decap_en) {
3211 : 0 : DRV_LOG(ERR, "\"decap_en\" "
3212 : : "configuration mismatch for shared %s context.",
3213 : : sh->ibdev_name);
3214 : 0 : goto error;
3215 : : }
3216 [ # # ]: 0 : if (sh->config.lacp_by_user ^ config->lacp_by_user) {
3217 : 0 : DRV_LOG(ERR, "\"lacp_by_user\" "
3218 : : "configuration mismatch for shared %s context.",
3219 : : sh->ibdev_name);
3220 : 0 : goto error;
3221 : : }
3222 [ # # ]: 0 : if (sh->config.tx_pp ^ config->tx_pp) {
3223 : 0 : DRV_LOG(ERR, "\"tx_pp\" "
3224 : : "configuration mismatch for shared %s context.",
3225 : : sh->ibdev_name);
3226 : 0 : goto error;
3227 : : }
3228 [ # # ]: 0 : if (sh->config.tx_skew ^ config->tx_skew) {
3229 : 0 : DRV_LOG(ERR, "\"tx_skew\" "
3230 : : "configuration mismatch for shared %s context.",
3231 : : sh->ibdev_name);
3232 : 0 : goto error;
3233 : : }
3234 [ # # ]: 0 : if (sh->config.tx_burst_bound != config->tx_burst_bound) {
3235 : 0 : DRV_LOG(ERR, "\"tx_burst_bound\" "
3236 : : "configuration mismatch for shared %s context.",
3237 : : sh->ibdev_name);
3238 : 0 : goto error;
3239 : : }
3240 [ # # ]: 0 : if (sh->config.tx_typical_pkt_sz != config->tx_typical_pkt_sz) {
3241 : 0 : DRV_LOG(ERR, "\"tx_typical_pkt_sz\" "
3242 : : "configuration mismatch for shared %s context.",
3243 : : sh->ibdev_name);
3244 : 0 : goto error;
3245 : : }
3246 [ # # ]: 0 : if (sh->config.txq_mem_algn != config->txq_mem_algn) {
3247 : 0 : DRV_LOG(ERR, "\"TxQ memory alignment\" "
3248 : : "configuration mismatch for shared %s context. %u - %u",
3249 : : sh->ibdev_name, sh->config.txq_mem_algn, config->txq_mem_algn);
3250 : 0 : goto error;
3251 : : }
3252 : 0 : mlx5_free(config);
3253 : 0 : return 0;
3254 : 0 : error:
3255 : 0 : mlx5_free(config);
3256 : 0 : rte_errno = EINVAL;
3257 : 0 : return -rte_errno;
3258 : : }
3259 : :
3260 : : /**
3261 : : * Configures the minimal amount of data to inline into WQE
3262 : : * while sending packets.
3263 : : *
3264 : : * - the txq_inline_min has the maximal priority, if this
3265 : : * key is specified in devargs
3266 : : * - if DevX is enabled the inline mode is queried from the
3267 : : * device (HCA attributes and NIC vport context if needed).
3268 : : * - otherwise L2 mode (18 bytes) is assumed for ConnectX-4/4 Lx
3269 : : * and none (0 bytes) for other NICs
3270 : : *
3271 : : * @param priv
3272 : : * Pointer to the private device data structure.
3273 : : */
3274 : : void
3275 : 0 : mlx5_set_min_inline(struct mlx5_priv *priv)
3276 : : {
3277 : 0 : struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
3278 : : struct mlx5_port_config *config = &priv->config;
3279 : :
3280 [ # # ]: 0 : if (config->txq_inline_min != MLX5_ARG_UNSET) {
3281 : : /* Application defines size of inlined data explicitly. */
3282 [ # # ]: 0 : if (priv->pci_dev != NULL) {
3283 [ # # ]: 0 : switch (priv->pci_dev->id.device_id) {
3284 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
3285 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
3286 [ # # ]: 0 : if (config->txq_inline_min <
3287 : : (int)MLX5_INLINE_HSIZE_L2) {
3288 : 0 : DRV_LOG(DEBUG,
3289 : : "txq_inline_mix aligned to minimal ConnectX-4 required value %d",
3290 : : (int)MLX5_INLINE_HSIZE_L2);
3291 : 0 : config->txq_inline_min =
3292 : : MLX5_INLINE_HSIZE_L2;
3293 : : }
3294 : : break;
3295 : : }
3296 : : }
3297 : 0 : goto exit;
3298 : : }
3299 [ # # ]: 0 : if (hca_attr->eth_net_offloads) {
3300 : : /* We have DevX enabled, inline mode queried successfully. */
3301 [ # # # # ]: 0 : switch (hca_attr->wqe_inline_mode) {
3302 : 0 : case MLX5_CAP_INLINE_MODE_L2:
3303 : : /* outer L2 header must be inlined. */
3304 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
3305 : 0 : goto exit;
3306 : 0 : case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
3307 : : /* No inline data are required by NIC. */
3308 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3309 : 0 : config->hw_vlan_insert =
3310 : 0 : hca_attr->wqe_vlan_insert;
3311 : 0 : DRV_LOG(DEBUG, "Tx VLAN insertion is supported");
3312 : 0 : goto exit;
3313 : 0 : case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
3314 : : /* inline mode is defined by NIC vport context. */
3315 [ # # ]: 0 : if (!hca_attr->eth_virt)
3316 : : break;
3317 [ # # # # : 0 : switch (hca_attr->vport_inline_mode) {
# # # # ]
3318 : 0 : case MLX5_INLINE_MODE_NONE:
3319 : 0 : config->txq_inline_min =
3320 : : MLX5_INLINE_HSIZE_NONE;
3321 : 0 : goto exit;
3322 : 0 : case MLX5_INLINE_MODE_L2:
3323 : 0 : config->txq_inline_min =
3324 : : MLX5_INLINE_HSIZE_L2;
3325 : 0 : goto exit;
3326 : 0 : case MLX5_INLINE_MODE_IP:
3327 : 0 : config->txq_inline_min =
3328 : : MLX5_INLINE_HSIZE_L3;
3329 : 0 : goto exit;
3330 : 0 : case MLX5_INLINE_MODE_TCP_UDP:
3331 : 0 : config->txq_inline_min =
3332 : : MLX5_INLINE_HSIZE_L4;
3333 : 0 : goto exit;
3334 : 0 : case MLX5_INLINE_MODE_INNER_L2:
3335 : 0 : config->txq_inline_min =
3336 : : MLX5_INLINE_HSIZE_INNER_L2;
3337 : 0 : goto exit;
3338 : 0 : case MLX5_INLINE_MODE_INNER_IP:
3339 : 0 : config->txq_inline_min =
3340 : : MLX5_INLINE_HSIZE_INNER_L3;
3341 : 0 : goto exit;
3342 : 0 : case MLX5_INLINE_MODE_INNER_TCP_UDP:
3343 : 0 : config->txq_inline_min =
3344 : : MLX5_INLINE_HSIZE_INNER_L4;
3345 : 0 : goto exit;
3346 : : }
3347 : : }
3348 : : }
3349 [ # # ]: 0 : if (priv->pci_dev == NULL) {
3350 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3351 : 0 : goto exit;
3352 : : }
3353 : : /*
3354 : : * We get here if we are unable to deduce
3355 : : * inline data size with DevX. Try PCI ID
3356 : : * to determine old NICs.
3357 : : */
3358 [ # # # ]: 0 : switch (priv->pci_dev->id.device_id) {
3359 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
3360 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
3361 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4LX:
3362 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
3363 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
3364 : 0 : config->hw_vlan_insert = 0;
3365 : 0 : break;
3366 : 0 : case PCI_DEVICE_ID_MELLANOX_CONNECTX5:
3367 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
3368 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5EX:
3369 : : case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
3370 : : /*
3371 : : * These NICs support VLAN insertion from WQE and
3372 : : * report the wqe_vlan_insert flag. But there is the bug
3373 : : * and PFC control may be broken, so disable feature.
3374 : : */
3375 : 0 : config->hw_vlan_insert = 0;
3376 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3377 : 0 : break;
3378 : 0 : default:
3379 : 0 : config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
3380 : 0 : break;
3381 : : }
3382 : 0 : exit:
3383 : 0 : DRV_LOG(DEBUG, "min tx inline configured: %d", config->txq_inline_min);
3384 : 0 : }
3385 : :
3386 : : /**
3387 : : * Configures the metadata mask fields in the shared context.
3388 : : *
3389 : : * @param [in] dev
3390 : : * Pointer to Ethernet device.
3391 : : */
3392 : : void
3393 : 0 : mlx5_set_metadata_mask(struct rte_eth_dev *dev)
3394 : : {
3395 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3396 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
3397 : : uint32_t meta, mark, reg_c0;
3398 : :
3399 : 0 : reg_c0 = ~priv->vport_meta_mask;
3400 [ # # # # : 0 : switch (sh->config.dv_xmeta_en) {
# ]
3401 : : case MLX5_XMETA_MODE_LEGACY:
3402 : : meta = UINT32_MAX;
3403 : : mark = MLX5_FLOW_MARK_MASK;
3404 : : break;
3405 : : case MLX5_XMETA_MODE_META16:
3406 : 0 : meta = reg_c0 >> rte_bsf32(reg_c0);
3407 : : mark = MLX5_FLOW_MARK_MASK;
3408 : 0 : break;
3409 : 0 : case MLX5_XMETA_MODE_META32:
3410 : : meta = UINT32_MAX;
3411 : 0 : mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
3412 : 0 : break;
3413 : 0 : case MLX5_XMETA_MODE_META32_HWS:
3414 : : meta = UINT32_MAX;
3415 : 0 : mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
3416 : 0 : break;
3417 : 0 : default:
3418 : : meta = 0;
3419 : : mark = 0;
3420 : : MLX5_ASSERT(false);
3421 : 0 : break;
3422 : : }
3423 [ # # # # ]: 0 : if (sh->dv_mark_mask && sh->dv_mark_mask != mark)
3424 : 0 : DRV_LOG(WARNING, "metadata MARK mask mismatch %08X:%08X",
3425 : : sh->dv_mark_mask, mark);
3426 : : else
3427 : 0 : sh->dv_mark_mask = mark;
3428 [ # # # # ]: 0 : if (sh->dv_meta_mask && sh->dv_meta_mask != meta)
3429 : 0 : DRV_LOG(WARNING, "metadata META mask mismatch %08X:%08X",
3430 : : sh->dv_meta_mask, meta);
3431 : : else
3432 : 0 : sh->dv_meta_mask = meta;
3433 [ # # # # ]: 0 : if (sh->dv_regc0_mask && sh->dv_regc0_mask != reg_c0)
3434 : 0 : DRV_LOG(WARNING, "metadata reg_c0 mask mismatch %08X:%08X",
3435 : : sh->dv_meta_mask, reg_c0);
3436 : : else
3437 : 0 : sh->dv_regc0_mask = reg_c0;
3438 : 0 : DRV_LOG(DEBUG, "metadata mode %u", sh->config.dv_xmeta_en);
3439 : 0 : DRV_LOG(DEBUG, "metadata MARK mask %08X", sh->dv_mark_mask);
3440 : 0 : DRV_LOG(DEBUG, "metadata META mask %08X", sh->dv_meta_mask);
3441 : 0 : DRV_LOG(DEBUG, "metadata reg_c0 mask %08X", sh->dv_regc0_mask);
3442 : 0 : }
3443 : :
3444 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_mlx5_get_dyn_flag_names, 20.02)
3445 : : int
3446 : 0 : rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
3447 : : {
3448 : : static const char *const dynf_names[] = {
3449 : : RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
3450 : : RTE_MBUF_DYNFLAG_METADATA_NAME,
3451 : : RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME
3452 : : };
3453 : : unsigned int i;
3454 : :
3455 [ # # ]: 0 : if (n < RTE_DIM(dynf_names))
3456 : : return -ENOMEM;
3457 [ # # ]: 0 : for (i = 0; i < RTE_DIM(dynf_names); i++) {
3458 [ # # ]: 0 : if (names[i] == NULL)
3459 : : return -EINVAL;
3460 : 0 : strcpy(names[i], dynf_names[i]);
3461 : : }
3462 : : return RTE_DIM(dynf_names);
3463 : : }
3464 : :
3465 : : /**
3466 : : * Look for the ethernet device belonging to mlx5 driver.
3467 : : *
3468 : : * @param[in] port_id
3469 : : * port_id to start looking for device.
3470 : : * @param[in] odev
3471 : : * Pointer to the hint device. When device is being probed
3472 : : * the its siblings (master and preceding representors might
3473 : : * not have assigned driver yet (because the mlx5_os_pci_probe()
3474 : : * is not completed yet, for this case match on hint
3475 : : * device may be used to detect sibling device.
3476 : : *
3477 : : * @return
3478 : : * port_id of found device, RTE_MAX_ETHPORT if not found.
3479 : : */
3480 : : uint16_t
3481 : 0 : mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev)
3482 : : {
3483 [ # # ]: 0 : while (port_id < RTE_MAX_ETHPORTS) {
3484 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3485 : :
3486 [ # # ]: 0 : if (dev->state != RTE_ETH_DEV_UNUSED &&
3487 [ # # # # ]: 0 : dev->device &&
3488 : 0 : (dev->device == odev ||
3489 [ # # ]: 0 : (dev->device->driver &&
3490 [ # # ]: 0 : dev->device->driver->name &&
3491 [ # # ]: 0 : ((strcmp(dev->device->driver->name,
3492 : 0 : MLX5_PCI_DRIVER_NAME) == 0) ||
3493 [ # # ]: 0 : (strcmp(dev->device->driver->name,
3494 : : MLX5_AUXILIARY_DRIVER_NAME) == 0)))))
3495 : : break;
3496 : 0 : port_id++;
3497 : : }
3498 : : if (port_id >= RTE_MAX_ETHPORTS)
3499 : : return RTE_MAX_ETHPORTS;
3500 : : return port_id;
3501 : : }
3502 : :
3503 : : static int
3504 : 0 : mlx5_hairpin_queue_counter_supported(struct mlx5_priv *priv)
3505 : : {
3506 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
3507 : 0 : DRV_LOG(WARNING,
3508 : : "DevX counter is not supported in the secondary process");
3509 : 0 : return -ENOTSUP;
3510 : : }
3511 : :
3512 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_modify_counter_set_id == NULL) {
3513 : 0 : DRV_LOG(WARNING,
3514 : : "DevX counter is not supported in this device");
3515 : 0 : return -ENOTSUP;
3516 : : }
3517 : : return 0;
3518 : : }
3519 : :
3520 : : /**
3521 : : * Disables the port-level hairpin counter.
3522 : : *
3523 : : * This function iterates over each RXQ, detaches it from the global
3524 : : * counter if it's a hairpin counter, and then destroys the global counter object if
3525 : : * it exists.
3526 : : *
3527 : : * @param dev
3528 : : * Pointer to Ethernet device.
3529 : : * @param id
3530 : : * The counter ID to disable (not used in this implementation).
3531 : : *
3532 : : * @return
3533 : : * 0 on success, error code otherwise.
3534 : : */
3535 : : int
3536 : 0 : mlx5_disable_port_level_hairpin_counter(struct rte_eth_dev *dev, uint64_t id __rte_unused)
3537 : : {
3538 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3539 : 0 : unsigned int num_rxqs = priv->rxqs_n;
3540 : : unsigned int i;
3541 : :
3542 [ # # ]: 0 : if (priv->q_counter_hairpin == NULL)
3543 : : return 0;
3544 : :
3545 : : /* Detach each RXQ from the global hairpin counter */
3546 [ # # ]: 0 : for (i = 0; i < num_rxqs; ++i) {
3547 : 0 : struct mlx5_rxq_priv *rxq = mlx5_rxq_get(dev, i);
3548 : :
3549 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3550 : 0 : continue;
3551 : :
3552 [ # # ]: 0 : if (priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, 0) != 0)
3553 : 0 : DRV_LOG(ERR, "Port %u failed to modify rq object %s",
3554 : : priv->dev_data->port_id, strerror(rte_errno));
3555 : : }
3556 : :
3557 : 0 : mlx5_devx_cmd_destroy(priv->q_counter_hairpin);
3558 : 0 : priv->q_counter_hairpin = NULL;
3559 : :
3560 : : /* Reset oob stats. */
3561 : 0 : mlx5_reset_xstats_by_name(priv, "hairpin_out_of_buffer");
3562 : 0 : return 0;
3563 : : }
3564 : :
3565 : : /**
3566 : : * Enables the port-level hairpin counter.
3567 : : *
3568 : : * This function iterates over each RXQ, allocate a q counter and attach it to each
3569 : : * hairpin queue.
3570 : : *
3571 : : * @param dev
3572 : : * Pointer to Ethernet device.
3573 : : * @param id
3574 : : * The counter ID to disable (not used in this implementation).
3575 : : *
3576 : : * @return
3577 : : * 0 on success, error code otherwise.
3578 : : */
3579 : : int
3580 : 0 : mlx5_enable_port_level_hairpin_counter(struct rte_eth_dev *dev, uint64_t id __rte_unused)
3581 : : {
3582 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3583 : : struct mlx5_rxq_priv *rxq;
3584 : 0 : int syndrome = 0;
3585 : : unsigned int i;
3586 : :
3587 : 0 : int ret = mlx5_hairpin_queue_counter_supported(priv);
3588 [ # # ]: 0 : if (ret) {
3589 : 0 : DRV_LOG(DEBUG, "Hairpin out of buffer counter "
3590 : : "is not available on this NIC.");
3591 : 0 : return ret;
3592 : : }
3593 : :
3594 : : /* check if counter is enable per queue - if yes - fail to enable per port */
3595 [ # # ]: 0 : if (priv->num_of_hairpin_q_counter_enabled != 0) {
3596 : 0 : DRV_LOG(WARNING, "Hairpin out of buffer counter is enabled per queue.");
3597 : 0 : return -EINVAL;
3598 : : }
3599 : :
3600 : : /* Alloc global hairpin queue counter. */
3601 : 0 : priv->q_counter_hairpin = mlx5_devx_cmd_queue_counter_alloc(priv->sh->cdev->ctx, &syndrome);
3602 [ # # ]: 0 : if (!priv->q_counter_hairpin) {
3603 [ # # ]: 0 : if (syndrome == MLX5_Q_COUNTERS_LIMIT_REACHED) {
3604 : 0 : DRV_LOG(ERR, "Maximum number of queue counters reached. "
3605 : : "Unable to create counter object for Port %d using DevX.",
3606 : : priv->dev_data->port_id);
3607 : 0 : return -ENOSPC;
3608 : : }
3609 : 0 : DRV_LOG(ERR, "Port %d global hairpin queue counter object cannot be created "
3610 : : "by DevX.", priv->dev_data->port_id);
3611 : 0 : return -ENOMEM;
3612 : : }
3613 : :
3614 : : /* go over each queue and attach to global counter */
3615 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i) {
3616 : 0 : rxq = mlx5_rxq_get(dev, i);
3617 : :
3618 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3619 : 0 : continue;
3620 : :
3621 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, priv->q_counter_hairpin->id);
3622 [ # # ]: 0 : if (ret) {
3623 : 0 : DRV_LOG(ERR, "failed to modify rq object for port %u"
3624 : : "%s", priv->dev_data->port_id, strerror(rte_errno));
3625 : 0 : return ret;
3626 : : }
3627 : : }
3628 : :
3629 : : /* Reset oob stats. */
3630 : 0 : mlx5_reset_xstats_by_name(priv, "hairpin_out_of_buffer");
3631 : 0 : return 0;
3632 : : }
3633 : :
3634 : : /**
3635 : : * Creates a queue counter for hairpin Rx queue.
3636 : : *
3637 : : * @param dev
3638 : : * Pointer to Ethernet device structure.
3639 : : * @param id
3640 : : * Index of the RX queue to disable the hairpin queue counter for.
3641 : : * @return
3642 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3643 : : */
3644 : : int
3645 : 0 : mlx5_enable_per_queue_hairpin_counter(struct rte_eth_dev *dev, uint64_t id)
3646 : : {
3647 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3648 : : struct mlx5_rxq_priv *rxq;
3649 : : struct mlx5_rxq_data *rxq_data;
3650 : 0 : int syndrome = 0;
3651 : :
3652 : 0 : int ret = mlx5_hairpin_queue_counter_supported(priv);
3653 [ # # ]: 0 : if (ret) {
3654 : 0 : DRV_LOG(DEBUG, "Hairpin out of buffer counter "
3655 : : "is not available on this NIC.");
3656 : 0 : return ret;
3657 : : }
3658 : :
3659 : : /* check if we have port level counter enabled. if yes, don't set the queue level counter */
3660 [ # # ]: 0 : if (priv->q_counter_hairpin) {
3661 : 0 : DRV_LOG(WARNING, "Hairpin out of buffer counter is enabled per port.");
3662 : 0 : return -EINVAL;
3663 : : }
3664 : :
3665 : 0 : rxq = mlx5_rxq_get(dev, id);
3666 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3667 : : return -EINVAL;
3668 : :
3669 [ # # ]: 0 : if (rxq->q_counter != NULL)
3670 : : return 0;
3671 : :
3672 : : /* Alloc hairpin queue counter. */
3673 : 0 : rxq->q_counter = mlx5_devx_cmd_queue_counter_alloc(priv->sh->cdev->ctx, &syndrome);
3674 [ # # ]: 0 : if (rxq->q_counter == NULL) {
3675 [ # # ]: 0 : if (syndrome == MLX5_Q_COUNTERS_LIMIT_REACHED) {
3676 : 0 : DRV_LOG(ERR, "Maximum number of queue counters reached. "
3677 : : "Unable to create counter object for Port %d, Queue %d "
3678 : : "using DevX. The counter from this queue will not increment.",
3679 : : priv->dev_data->port_id, rxq->idx);
3680 : 0 : return -ENOSPC;
3681 : : }
3682 : 0 : DRV_LOG(ERR, "Port %d queue %d counter object cannot be created "
3683 : : "by DevX. Counter from this queue will not increment.",
3684 : : priv->dev_data->port_id, rxq->idx);
3685 : 0 : return -ENOMEM;
3686 : : }
3687 : :
3688 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, rxq->q_counter->id);
3689 [ # # ]: 0 : if (ret) {
3690 : 0 : DRV_LOG(ERR, "failed to modify rq object for port %u"
3691 : : "%s", priv->dev_data->port_id, strerror(rte_errno));
3692 : 0 : mlx5_devx_cmd_destroy(rxq->q_counter);
3693 : 0 : rxq->q_counter = NULL;
3694 : 0 : return ret;
3695 : : }
3696 : :
3697 : 0 : rxq_data = mlx5_rxq_data_get(dev, id);
3698 [ # # ]: 0 : if (rxq_data != NULL)
3699 : 0 : rxq_data->stats.oobs.ctrl.enabled = 1;
3700 : :
3701 : 0 : priv->num_of_hairpin_q_counter_enabled++;
3702 : 0 : return 0;
3703 : : }
3704 : :
3705 : : /**
3706 : : * Disables the hairpin queue counter for a specified RX queue.
3707 : : *
3708 : : * @param dev
3709 : : * Pointer to Ethernet device structure.
3710 : : * @param id
3711 : : * Index of the RX queue to disable the hairpin queue counter for.
3712 : : * @return
3713 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3714 : : */
3715 : : int
3716 : 0 : mlx5_disable_per_queue_hairpin_counter(struct rte_eth_dev *dev, uint64_t id)
3717 : : {
3718 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3719 : : struct mlx5_rxq_priv *rxq;
3720 : : struct mlx5_rxq_data *rxq_data;
3721 : : int ret = 0;
3722 : :
3723 : 0 : rxq = mlx5_rxq_get(dev, id);
3724 : 0 : rxq_data = mlx5_rxq_data_get(dev, id);
3725 : :
3726 [ # # # # : 0 : if (rxq == NULL || rxq->ctrl->obj->rq == NULL || !rxq->ctrl->is_hairpin)
# # ]
3727 : : return 0;
3728 : :
3729 [ # # ]: 0 : if (rxq->q_counter != NULL) {
3730 : : /* Modify rxq. */
3731 : 0 : ret = priv->obj_ops.rxq_obj_modify_counter_set_id(rxq, 0);
3732 [ # # ]: 0 : if (ret)
3733 : 0 : DRV_LOG(ERR, "Port %u failed to modify rq object "
3734 : : " %s", priv->dev_data->port_id, strerror(rte_errno));
3735 : :
3736 : 0 : mlx5_devx_cmd_destroy(rxq->q_counter);
3737 : 0 : rxq->q_counter = NULL;
3738 : : }
3739 : :
3740 : : /* Reset queue oob stats. */
3741 [ # # ]: 0 : if (rxq_data != NULL) {
3742 : 0 : rxq_data->stats.oobs.count = 0;
3743 : 0 : rxq_data->stats_reset.oobs.count = 0;
3744 : 0 : rxq_data->stats.oobs.ctrl.enabled = 0;
3745 : : }
3746 : :
3747 : 0 : priv->num_of_hairpin_q_counter_enabled--;
3748 : 0 : return 0;
3749 : : }
3750 : :
3751 : : /**
3752 : : * Read statistics per queue by a named counter.
3753 : : *
3754 : : * @param[in] q_counter
3755 : : * Pointer to the queue's counter object.
3756 : : * @param[in] ctr_name
3757 : : * Pointer to the name of the statistic counter to read
3758 : : * @param[out] stat
3759 : : * Pointer to read statistic value.
3760 : : * @return
3761 : : * 0 on success and stat is valid, 1 if failed to read the value
3762 : : * rte_errno is set.
3763 : : *
3764 : : */
3765 : : int
3766 : 0 : mlx5_read_queue_counter(struct mlx5_devx_obj *q_counter, const char *ctr_name,
3767 : : uint64_t *stat)
3768 : : {
3769 : : uint32_t val;
3770 : : int ret;
3771 : :
3772 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
3773 : 0 : DRV_LOG(WARNING,
3774 : : "DevX %s counter is not supported in the secondary process", ctr_name);
3775 : 0 : return -ENOTSUP;
3776 : : }
3777 : :
3778 [ # # ]: 0 : if (q_counter == NULL)
3779 : : return -EINVAL;
3780 : :
3781 : 0 : ret = mlx5_devx_cmd_queue_counter_query(q_counter, 0, &val);
3782 [ # # ]: 0 : if (ret == 0)
3783 : 0 : *stat = val;
3784 : :
3785 : : return ret;
3786 : : }
3787 : :
3788 : : /**
3789 : : * Fix up shared configuration passed by user based on device capabilities.
3790 : : *
3791 : : * @param[in] config
3792 : : * Pointer to shared configuration.
3793 : : * @param[in] sh
3794 : : * Pointer to shared device context.
3795 : : * @param[in] mkvlist
3796 : : * Key/value list of passed options
3797 : : */
3798 : : void
3799 : 0 : mlx5_fixup_flow_config(struct mlx5_sh_config *config,
3800 : : struct mlx5_dev_ctx_shared *sh,
3801 : : struct mlx5_kvargs_ctrl *mkvlist)
3802 : : {
3803 [ # # # # ]: 0 : if (config->dv_flow_en && !sh->dev_cap.dv_flow_en) {
3804 : 0 : DRV_LOG(WARNING, "DV flow is not supported.");
3805 : 0 : config->dv_flow_en = 0;
3806 : : }
3807 : :
3808 : : /* Apply platform-dependent logic. */
3809 : 0 : mlx5_os_fixup_flow_en(config, sh);
3810 : 0 : mlx5_os_fixup_duplicate_pattern(config, mkvlist, MLX5_ALLOW_DUPLICATE_PATTERN);
3811 : 0 : }
3812 : :
3813 : : /**
3814 : : * Callback to remove a device.
3815 : : *
3816 : : * This function removes all Ethernet devices belong to a given device.
3817 : : *
3818 : : * @param[in] cdev
3819 : : * Pointer to the generic device.
3820 : : *
3821 : : * @return
3822 : : * 0 on success, the function cannot fail.
3823 : : */
3824 : : int
3825 : 0 : mlx5_net_remove(struct mlx5_common_device *cdev)
3826 : : {
3827 : : uint16_t port_id;
3828 : : int ret = 0;
3829 : :
3830 [ # # ]: 0 : RTE_ETH_FOREACH_DEV_OF(port_id, cdev->dev) {
3831 : : /*
3832 : : * mlx5_dev_close() is not registered to secondary process,
3833 : : * call the close function explicitly for secondary process.
3834 : : */
3835 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
3836 : 0 : ret |= mlx5_dev_close(&rte_eth_devices[port_id]);
3837 : : else
3838 : 0 : ret |= rte_eth_dev_close(port_id);
3839 : : }
3840 [ # # ]: 0 : return ret == 0 ? 0 : -EIO;
3841 : : }
3842 : :
3843 : : static const struct rte_pci_id mlx5_pci_id_map[] = {
3844 : : {
3845 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3846 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4)
3847 : : },
3848 : : {
3849 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3850 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
3851 : : },
3852 : : {
3853 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3854 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
3855 : : },
3856 : : {
3857 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3858 : : PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
3859 : : },
3860 : : {
3861 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3862 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5)
3863 : : },
3864 : : {
3865 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3866 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5VF)
3867 : : },
3868 : : {
3869 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3870 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EX)
3871 : : },
3872 : : {
3873 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3874 : : PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)
3875 : : },
3876 : : {
3877 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3878 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD)
3879 : : },
3880 : : {
3881 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3882 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELDVF)
3883 : : },
3884 : : {
3885 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3886 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6)
3887 : : },
3888 : : {
3889 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3890 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
3891 : : },
3892 : : {
3893 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3894 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
3895 : : },
3896 : : {
3897 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3898 : : PCI_DEVICE_ID_MELLANOX_CONNECTXVF)
3899 : : },
3900 : : {
3901 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3902 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD2)
3903 : : },
3904 : : {
3905 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3906 : : PCI_DEVICE_ID_MELLANOX_CONNECTX6LX)
3907 : : },
3908 : : {
3909 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3910 : : PCI_DEVICE_ID_MELLANOX_CONNECTX7)
3911 : : },
3912 : : {
3913 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3914 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD3)
3915 : : },
3916 : : {
3917 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3918 : : PCI_DEVICE_ID_MELLANOX_CONNECTX8)
3919 : : },
3920 : : {
3921 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3922 : : PCI_DEVICE_ID_MELLANOX_CONNECTX9)
3923 : : },
3924 : : {
3925 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3926 : : PCI_DEVICE_ID_MELLANOX_BLUEFIELD4)
3927 : : },
3928 : : {
3929 : : RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3930 : : PCI_DEVICE_ID_MELLANOX_CONNECTX10)
3931 : : },
3932 : : {
3933 : : .vendor_id = 0
3934 : : }
3935 : : };
3936 : :
3937 : : static struct mlx5_class_driver mlx5_net_driver = {
3938 : : .drv_class = MLX5_CLASS_ETH,
3939 : : .name = RTE_STR(MLX5_ETH_DRIVER_NAME),
3940 : : .id_table = mlx5_pci_id_map,
3941 : : .probe = mlx5_os_net_probe,
3942 : : .remove = mlx5_net_remove,
3943 : : .probe_again = 1,
3944 : : .intr_lsc = 1,
3945 : : .intr_rmv = 1,
3946 : : };
3947 : :
3948 : : /* Initialize driver log type. */
3949 [ - + ]: 286 : RTE_LOG_REGISTER_DEFAULT(mlx5_logtype, NOTICE)
3950 : :
3951 : : /**
3952 : : * Driver initialization routine.
3953 : : */
3954 : 286 : RTE_INIT(rte_mlx5_pmd_init)
3955 : : {
3956 : 286 : pthread_mutex_init(&mlx5_dev_ctx_list_mutex, NULL);
3957 : 286 : mlx5_common_init();
3958 : : /* Build the static tables for Verbs conversion. */
3959 : 286 : mlx5_set_ptype_table();
3960 : 286 : mlx5_set_cksum_table();
3961 : 286 : mlx5_set_swp_types_table();
3962 [ + - ]: 286 : if (mlx5_glue)
3963 : 286 : mlx5_class_driver_register(&mlx5_net_driver);
3964 : 286 : }
3965 : :
3966 : : RTE_PMD_EXPORT_NAME(MLX5_ETH_DRIVER_NAME);
3967 : : RTE_PMD_REGISTER_PCI_TABLE(MLX5_ETH_DRIVER_NAME, mlx5_pci_id_map);
3968 : : RTE_PMD_REGISTER_KMOD_DEP(MLX5_ETH_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");
|