1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
13 #include <rte_malloc.h>
14 #include <ethdev_driver.h>
16 #include <rte_bus_pci.h>
17 #include <rte_common.h>
18 #include <rte_kvargs.h>
19 #include <rte_rwlock.h>
20 #include <rte_spinlock.h>
21 #include <rte_string_fns.h>
22 #include <rte_eal_paging.h>
23 #include <rte_alarm.h>
24 #include <rte_cycles.h>
26 #include <mlx5_glue.h>
27 #include <mlx5_devx_cmds.h>
28 #include <mlx5_common.h>
29 #include <mlx5_common_os.h>
30 #include <mlx5_common_mp.h>
31 #include <mlx5_malloc.h>
33 #include "mlx5_defs.h"
35 #include "mlx5_utils.h"
36 #include "mlx5_rxtx.h"
39 #include "mlx5_autoconf.h"
40 #include "mlx5_flow.h"
41 #include "mlx5_flow_os.h"
42 #include "rte_pmd_mlx5.h"
44 #define MLX5_ETH_DRIVER_NAME mlx5_eth
46 /* Device parameter to enable RX completion queue compression. */
47 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
49 /* Device parameter to enable padding Rx packet to cacheline size. */
50 #define MLX5_RXQ_PKT_PAD_EN "rxq_pkt_pad_en"
52 /* Device parameter to enable Multi-Packet Rx queue. */
53 #define MLX5_RX_MPRQ_EN "mprq_en"
55 /* Device parameter to configure log 2 of the number of strides for MPRQ. */
56 #define MLX5_RX_MPRQ_LOG_STRIDE_NUM "mprq_log_stride_num"
58 /* Device parameter to configure log 2 of the stride size for MPRQ. */
59 #define MLX5_RX_MPRQ_LOG_STRIDE_SIZE "mprq_log_stride_size"
61 /* Device parameter to limit the size of memcpy'd packet for MPRQ. */
62 #define MLX5_RX_MPRQ_MAX_MEMCPY_LEN "mprq_max_memcpy_len"
64 /* Device parameter to set the minimum number of Rx queues to enable MPRQ. */
65 #define MLX5_RXQS_MIN_MPRQ "rxqs_min_mprq"
67 /* Device parameter to configure inline send. Deprecated, ignored.*/
68 #define MLX5_TXQ_INLINE "txq_inline"
70 /* Device parameter to limit packet size to inline with ordinary SEND. */
71 #define MLX5_TXQ_INLINE_MAX "txq_inline_max"
73 /* Device parameter to configure minimal data size to inline. */
74 #define MLX5_TXQ_INLINE_MIN "txq_inline_min"
76 /* Device parameter to limit packet size to inline with Enhanced MPW. */
77 #define MLX5_TXQ_INLINE_MPW "txq_inline_mpw"
80 * Device parameter to configure the number of TX queues threshold for
81 * enabling inline send.
83 #define MLX5_TXQS_MIN_INLINE "txqs_min_inline"
86 * Device parameter to configure the number of TX queues threshold for
87 * enabling vectorized Tx, deprecated, ignored (no vectorized Tx routines).
89 #define MLX5_TXQS_MAX_VEC "txqs_max_vec"
91 /* Device parameter to enable multi-packet send WQEs. */
92 #define MLX5_TXQ_MPW_EN "txq_mpw_en"
95 * Device parameter to include 2 dsegs in the title WQEBB.
96 * Deprecated, ignored.
98 #define MLX5_TXQ_MPW_HDR_DSEG_EN "txq_mpw_hdr_dseg_en"
101 * Device parameter to limit the size of inlining packet.
102 * Deprecated, ignored.
104 #define MLX5_TXQ_MAX_INLINE_LEN "txq_max_inline_len"
107 * Device parameter to enable Tx scheduling on timestamps
108 * and specify the packet pacing granularity in nanoseconds.
110 #define MLX5_TX_PP "tx_pp"
113 * Device parameter to specify skew in nanoseconds on Tx datapath,
114 * it represents the time between SQ start WQE processing and
115 * appearing actual packet data on the wire.
117 #define MLX5_TX_SKEW "tx_skew"
120 * Device parameter to enable hardware Tx vector.
121 * Deprecated, ignored (no vectorized Tx routines anymore).
123 #define MLX5_TX_VEC_EN "tx_vec_en"
125 /* Device parameter to enable hardware Rx vector. */
126 #define MLX5_RX_VEC_EN "rx_vec_en"
128 /* Allow L3 VXLAN flow creation. */
129 #define MLX5_L3_VXLAN_EN "l3_vxlan_en"
131 /* Activate DV E-Switch flow steering. */
132 #define MLX5_DV_ESW_EN "dv_esw_en"
134 /* Activate DV flow steering. */
135 #define MLX5_DV_FLOW_EN "dv_flow_en"
137 /* Enable extensive flow metadata support. */
138 #define MLX5_DV_XMETA_EN "dv_xmeta_en"
140 /* Device parameter to let the user manage the lacp traffic of bonded device */
141 #define MLX5_LACP_BY_USER "lacp_by_user"
143 /* Activate Netlink support in VF mode. */
144 #define MLX5_VF_NL_EN "vf_nl_en"
146 /* Select port representors to instantiate. */
147 #define MLX5_REPRESENTOR "representor"
149 /* Device parameter to configure the maximum number of dump files per queue. */
150 #define MLX5_MAX_DUMP_FILES_NUM "max_dump_files_num"
152 /* Configure timeout of LRO session (in microseconds). */
153 #define MLX5_LRO_TIMEOUT_USEC "lro_timeout_usec"
156 * Device parameter to configure the total data buffer size for a single
157 * hairpin queue (logarithm value).
159 #define MLX5_HP_BUF_SIZE "hp_buf_log_sz"
161 /* Flow memory reclaim mode. */
162 #define MLX5_RECLAIM_MEM "reclaim_mem_mode"
164 /* Decap will be used or not. */
165 #define MLX5_DECAP_EN "decap_en"
167 /* Device parameter to configure allow or prevent duplicate rules pattern. */
168 #define MLX5_ALLOW_DUPLICATE_PATTERN "allow_duplicate_pattern"
170 /* Device parameter to configure the delay drop when creating Rxqs. */
171 #define MLX5_DELAY_DROP "delay_drop"
173 /* Shared memory between primary and secondary processes. */
174 struct mlx5_shared_data *mlx5_shared_data;
176 /** Driver-specific log messages type. */
179 static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
180 LIST_HEAD_INITIALIZER();
181 static pthread_mutex_t mlx5_dev_ctx_list_mutex;
182 static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
183 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
184 [MLX5_IPOOL_DECAP_ENCAP] = {
185 .size = sizeof(struct mlx5_flow_dv_encap_decap_resource),
191 .malloc = mlx5_malloc,
193 .type = "mlx5_encap_decap_ipool",
195 [MLX5_IPOOL_PUSH_VLAN] = {
196 .size = sizeof(struct mlx5_flow_dv_push_vlan_action_resource),
202 .malloc = mlx5_malloc,
204 .type = "mlx5_push_vlan_ipool",
207 .size = sizeof(struct mlx5_flow_dv_tag_resource),
213 .per_core_cache = (1 << 16),
214 .malloc = mlx5_malloc,
216 .type = "mlx5_tag_ipool",
218 [MLX5_IPOOL_PORT_ID] = {
219 .size = sizeof(struct mlx5_flow_dv_port_id_action_resource),
225 .malloc = mlx5_malloc,
227 .type = "mlx5_port_id_ipool",
229 [MLX5_IPOOL_JUMP] = {
230 .size = sizeof(struct mlx5_flow_tbl_data_entry),
236 .malloc = mlx5_malloc,
238 .type = "mlx5_jump_ipool",
240 [MLX5_IPOOL_SAMPLE] = {
241 .size = sizeof(struct mlx5_flow_dv_sample_resource),
247 .malloc = mlx5_malloc,
249 .type = "mlx5_sample_ipool",
251 [MLX5_IPOOL_DEST_ARRAY] = {
252 .size = sizeof(struct mlx5_flow_dv_dest_array_resource),
258 .malloc = mlx5_malloc,
260 .type = "mlx5_dest_array_ipool",
262 [MLX5_IPOOL_TUNNEL_ID] = {
263 .size = sizeof(struct mlx5_flow_tunnel),
264 .trunk_size = MLX5_MAX_TUNNELS,
267 .type = "mlx5_tunnel_offload",
269 [MLX5_IPOOL_TNL_TBL_ID] = {
272 .type = "mlx5_flow_tnl_tbl_ipool",
277 * The ipool index should grow continually from small to big,
278 * for meter idx, so not set grow_trunk to avoid meter index
279 * not jump continually.
281 .size = sizeof(struct mlx5_legacy_flow_meter),
285 .malloc = mlx5_malloc,
287 .type = "mlx5_meter_ipool",
290 .size = sizeof(struct mlx5_flow_mreg_copy_resource),
296 .malloc = mlx5_malloc,
298 .type = "mlx5_mcp_ipool",
300 [MLX5_IPOOL_HRXQ] = {
301 .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
307 .malloc = mlx5_malloc,
309 .type = "mlx5_hrxq_ipool",
311 [MLX5_IPOOL_MLX5_FLOW] = {
313 * MLX5_IPOOL_MLX5_FLOW size varies for DV and VERBS flows.
314 * It set in run time according to PCI function configuration.
322 .per_core_cache = 1 << 19,
323 .malloc = mlx5_malloc,
325 .type = "mlx5_flow_handle_ipool",
327 [MLX5_IPOOL_RTE_FLOW] = {
328 .size = sizeof(struct rte_flow),
332 .malloc = mlx5_malloc,
334 .type = "rte_flow_ipool",
336 [MLX5_IPOOL_RSS_EXPANTION_FLOW_ID] = {
339 .type = "mlx5_flow_rss_id_ipool",
341 [MLX5_IPOOL_RSS_SHARED_ACTIONS] = {
342 .size = sizeof(struct mlx5_shared_action_rss),
348 .malloc = mlx5_malloc,
350 .type = "mlx5_shared_action_rss",
352 [MLX5_IPOOL_MTR_POLICY] = {
354 * The ipool index should grow continually from small to big,
355 * for policy idx, so not set grow_trunk to avoid policy index
356 * not jump continually.
358 .size = sizeof(struct mlx5_flow_meter_sub_policy),
362 .malloc = mlx5_malloc,
364 .type = "mlx5_meter_policy_ipool",
368 #define MLX5_FLOW_MIN_ID_POOL_SIZE 512
369 #define MLX5_ID_GENERATION_ARRAY_FACTOR 16
371 #define MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE 1024
374 * Decide whether representor ID is a HPF(host PF) port on BF2.
377 * Pointer to Ethernet device structure.
380 * Non-zero if HPF, otherwise 0.
383 mlx5_is_hpf(struct rte_eth_dev *dev)
385 struct mlx5_priv *priv = dev->data->dev_private;
386 uint16_t repr = MLX5_REPRESENTOR_REPR(priv->representor_id);
387 int type = MLX5_REPRESENTOR_TYPE(priv->representor_id);
389 return priv->representor != 0 && type == RTE_ETH_REPRESENTOR_VF &&
390 MLX5_REPRESENTOR_REPR(-1) == repr;
394 * Decide whether representor ID is a SF port representor.
397 * Pointer to Ethernet device structure.
400 * Non-zero if HPF, otherwise 0.
403 mlx5_is_sf_repr(struct rte_eth_dev *dev)
405 struct mlx5_priv *priv = dev->data->dev_private;
406 int type = MLX5_REPRESENTOR_TYPE(priv->representor_id);
408 return priv->representor != 0 && type == RTE_ETH_REPRESENTOR_SF;
412 * Initialize the ASO aging management structure.
415 * Pointer to mlx5_dev_ctx_shared object to free
418 * 0 on success, a negative errno value otherwise and rte_errno is set.
421 mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh)
427 sh->aso_age_mng = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sh->aso_age_mng),
428 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
429 if (!sh->aso_age_mng) {
430 DRV_LOG(ERR, "aso_age_mng allocation was failed.");
434 err = mlx5_aso_queue_init(sh, ASO_OPC_MOD_FLOW_HIT);
436 mlx5_free(sh->aso_age_mng);
439 rte_rwlock_init(&sh->aso_age_mng->resize_rwl);
440 rte_spinlock_init(&sh->aso_age_mng->free_sl);
441 LIST_INIT(&sh->aso_age_mng->free);
446 * Close and release all the resources of the ASO aging management structure.
449 * Pointer to mlx5_dev_ctx_shared object to free.
452 mlx5_flow_aso_age_mng_close(struct mlx5_dev_ctx_shared *sh)
456 mlx5_aso_flow_hit_queue_poll_stop(sh);
457 mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_FLOW_HIT);
458 if (sh->aso_age_mng->pools) {
459 struct mlx5_aso_age_pool *pool;
461 for (i = 0; i < sh->aso_age_mng->next; ++i) {
462 pool = sh->aso_age_mng->pools[i];
463 claim_zero(mlx5_devx_cmd_destroy
464 (pool->flow_hit_aso_obj));
465 for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j)
466 if (pool->actions[j].dr_action)
468 (mlx5_flow_os_destroy_flow_action
469 (pool->actions[j].dr_action));
472 mlx5_free(sh->aso_age_mng->pools);
474 mlx5_free(sh->aso_age_mng);
478 * Initialize the shared aging list information per port.
481 * Pointer to mlx5_dev_ctx_shared object.
484 mlx5_flow_aging_init(struct mlx5_dev_ctx_shared *sh)
487 struct mlx5_age_info *age_info;
489 for (i = 0; i < sh->max_port; i++) {
490 age_info = &sh->port[i].age_info;
492 TAILQ_INIT(&age_info->aged_counters);
493 LIST_INIT(&age_info->aged_aso);
494 rte_spinlock_init(&age_info->aged_sl);
495 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
500 * DV flow counter mode detect and config.
503 * Pointer to rte_eth_dev structure.
507 mlx5_flow_counter_mode_config(struct rte_eth_dev *dev __rte_unused)
509 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
510 struct mlx5_priv *priv = dev->data->dev_private;
511 struct mlx5_dev_ctx_shared *sh = priv->sh;
512 struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
515 #ifndef HAVE_IBV_DEVX_ASYNC
519 if (!sh->cdev->config.devx || !sh->config.dv_flow_en ||
520 !hca_attr->flow_counters_dump ||
521 !(hca_attr->flow_counter_bulk_alloc_bitmap & 0x4) ||
522 (mlx5_flow_dv_discover_counter_offset_support(dev) == -ENOTSUP))
526 DRV_LOG(INFO, "Use fall-back DV counter management. Flow "
527 "counter dump:%d, bulk_alloc_bitmap:0x%hhx.",
528 hca_attr->flow_counters_dump,
529 hca_attr->flow_counter_bulk_alloc_bitmap);
530 /* Initialize fallback mode only on the port initializes sh. */
532 sh->cmng.counter_fallback = fallback;
533 else if (fallback != sh->cmng.counter_fallback)
534 DRV_LOG(WARNING, "Port %d in sh has different fallback mode "
535 "with others:%d.", PORT_ID(priv), fallback);
540 * Initialize the counters management structure.
543 * Pointer to mlx5_dev_ctx_shared object to free
546 mlx5_flow_counters_mng_init(struct mlx5_dev_ctx_shared *sh)
550 memset(&sh->cmng, 0, sizeof(sh->cmng));
551 TAILQ_INIT(&sh->cmng.flow_counters);
552 sh->cmng.min_id = MLX5_CNT_BATCH_OFFSET;
553 sh->cmng.max_id = -1;
554 sh->cmng.last_pool_idx = POOL_IDX_INVALID;
555 rte_spinlock_init(&sh->cmng.pool_update_sl);
556 for (i = 0; i < MLX5_COUNTER_TYPE_MAX; i++) {
557 TAILQ_INIT(&sh->cmng.counters[i]);
558 rte_spinlock_init(&sh->cmng.csl[i]);
563 * Destroy all the resources allocated for a counter memory management.
566 * Pointer to the memory management structure.
569 mlx5_flow_destroy_counter_stat_mem_mng(struct mlx5_counter_stats_mem_mng *mng)
571 uint8_t *mem = (uint8_t *)(uintptr_t)mng->raws[0].data;
573 LIST_REMOVE(mng, next);
574 mlx5_os_wrapped_mkey_destroy(&mng->wm);
579 * Close and release all the resources of the counters management.
582 * Pointer to mlx5_dev_ctx_shared object to free.
585 mlx5_flow_counters_mng_close(struct mlx5_dev_ctx_shared *sh)
587 struct mlx5_counter_stats_mem_mng *mng;
593 rte_eal_alarm_cancel(mlx5_flow_query_alarm, sh);
594 if (rte_errno != EINPROGRESS)
599 if (sh->cmng.pools) {
600 struct mlx5_flow_counter_pool *pool;
601 uint16_t n_valid = sh->cmng.n_valid;
602 bool fallback = sh->cmng.counter_fallback;
604 for (i = 0; i < n_valid; ++i) {
605 pool = sh->cmng.pools[i];
606 if (!fallback && pool->min_dcs)
607 claim_zero(mlx5_devx_cmd_destroy
609 for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j) {
610 struct mlx5_flow_counter *cnt =
611 MLX5_POOL_GET_CNT(pool, j);
615 (mlx5_flow_os_destroy_flow_action
617 if (fallback && MLX5_POOL_GET_CNT
618 (pool, j)->dcs_when_free)
619 claim_zero(mlx5_devx_cmd_destroy
620 (cnt->dcs_when_free));
624 mlx5_free(sh->cmng.pools);
626 mng = LIST_FIRST(&sh->cmng.mem_mngs);
628 mlx5_flow_destroy_counter_stat_mem_mng(mng);
629 mng = LIST_FIRST(&sh->cmng.mem_mngs);
631 memset(&sh->cmng, 0, sizeof(sh->cmng));
635 * Initialize the aso flow meters management structure.
638 * Pointer to mlx5_dev_ctx_shared object to free
641 mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh)
644 sh->mtrmng = mlx5_malloc(MLX5_MEM_ZERO,
646 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
649 "meter management allocation was failed.");
653 if (sh->meter_aso_en) {
654 rte_spinlock_init(&sh->mtrmng->pools_mng.mtrsl);
655 rte_rwlock_init(&sh->mtrmng->pools_mng.resize_mtrwl);
656 LIST_INIT(&sh->mtrmng->pools_mng.meters);
658 sh->mtrmng->def_policy_id = MLX5_INVALID_POLICY_ID;
664 * Close and release all the resources of
665 * the ASO flow meter management structure.
668 * Pointer to mlx5_dev_ctx_shared object to free.
671 mlx5_aso_flow_mtrs_mng_close(struct mlx5_dev_ctx_shared *sh)
673 struct mlx5_aso_mtr_pool *mtr_pool;
674 struct mlx5_flow_mtr_mng *mtrmng = sh->mtrmng;
676 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
677 struct mlx5_aso_mtr *aso_mtr;
679 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
681 if (sh->meter_aso_en) {
682 mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_POLICER);
683 idx = mtrmng->pools_mng.n_valid;
685 mtr_pool = mtrmng->pools_mng.pools[idx];
686 #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
687 for (i = 0; i < MLX5_ASO_MTRS_PER_POOL; i++) {
688 aso_mtr = &mtr_pool->mtrs[i];
689 if (aso_mtr->fm.meter_action)
691 (mlx5_glue->destroy_flow_action
692 (aso_mtr->fm.meter_action));
694 #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
695 claim_zero(mlx5_devx_cmd_destroy
696 (mtr_pool->devx_obj));
697 mtrmng->pools_mng.n_valid--;
700 mlx5_free(sh->mtrmng->pools_mng.pools);
702 mlx5_free(sh->mtrmng);
706 /* Send FLOW_AGED event if needed. */
708 mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh)
710 struct mlx5_age_info *age_info;
713 for (i = 0; i < sh->max_port; i++) {
714 age_info = &sh->port[i].age_info;
715 if (!MLX5_AGE_GET(age_info, MLX5_AGE_EVENT_NEW))
717 MLX5_AGE_UNSET(age_info, MLX5_AGE_EVENT_NEW);
718 if (MLX5_AGE_GET(age_info, MLX5_AGE_TRIGGER)) {
719 MLX5_AGE_UNSET(age_info, MLX5_AGE_TRIGGER);
720 rte_eth_dev_callback_process
721 (&rte_eth_devices[sh->port[i].devx_ih_port_id],
722 RTE_ETH_EVENT_FLOW_AGED, NULL);
728 * Initialize the ASO connection tracking structure.
731 * Pointer to mlx5_dev_ctx_shared object.
734 * 0 on success, a negative errno value otherwise and rte_errno is set.
737 mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh)
743 sh->ct_mng = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sh->ct_mng),
744 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
746 DRV_LOG(ERR, "ASO CT management allocation failed.");
750 err = mlx5_aso_queue_init(sh, ASO_OPC_MOD_CONNECTION_TRACKING);
752 mlx5_free(sh->ct_mng);
753 /* rte_errno should be extracted from the failure. */
757 rte_spinlock_init(&sh->ct_mng->ct_sl);
758 rte_rwlock_init(&sh->ct_mng->resize_rwl);
759 LIST_INIT(&sh->ct_mng->free_cts);
764 * Close and release all the resources of the
765 * ASO connection tracking management structure.
768 * Pointer to mlx5_dev_ctx_shared object to free.
771 mlx5_flow_aso_ct_mng_close(struct mlx5_dev_ctx_shared *sh)
773 struct mlx5_aso_ct_pools_mng *mng = sh->ct_mng;
774 struct mlx5_aso_ct_pool *ct_pool;
775 struct mlx5_aso_ct_action *ct;
781 mlx5_aso_queue_uninit(sh, ASO_OPC_MOD_CONNECTION_TRACKING);
785 ct_pool = mng->pools[idx];
786 for (i = 0; i < MLX5_ASO_CT_ACTIONS_PER_POOL; i++) {
787 ct = &ct_pool->actions[i];
788 val = __atomic_fetch_sub(&ct->refcnt, 1,
790 MLX5_ASSERT(val == 1);
793 #ifdef HAVE_MLX5_DR_ACTION_ASO_CT
794 if (ct->dr_action_orig)
795 claim_zero(mlx5_glue->destroy_flow_action
796 (ct->dr_action_orig));
797 if (ct->dr_action_rply)
798 claim_zero(mlx5_glue->destroy_flow_action
799 (ct->dr_action_rply));
802 claim_zero(mlx5_devx_cmd_destroy(ct_pool->devx_obj));
804 DRV_LOG(DEBUG, "%u ASO CT objects are being used in the pool %u",
808 /* in case of failure. */
811 mlx5_free(mng->pools);
813 /* Management structure must be cleared to 0s during allocation. */
818 * Initialize the flow resources' indexed mempool.
821 * Pointer to mlx5_dev_ctx_shared object.
824 mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh)
827 struct mlx5_indexed_pool_config cfg;
829 for (i = 0; i < MLX5_IPOOL_MAX; ++i) {
830 cfg = mlx5_ipool_cfg[i];
835 * Set MLX5_IPOOL_MLX5_FLOW ipool size
836 * according to PCI function flow configuration.
838 case MLX5_IPOOL_MLX5_FLOW:
839 cfg.size = sh->config.dv_flow_en ?
840 sizeof(struct mlx5_flow_handle) :
841 MLX5_FLOW_HANDLE_VERBS_SIZE;
844 if (sh->config.reclaim_mode) {
845 cfg.release_mem_en = 1;
846 cfg.per_core_cache = 0;
848 cfg.release_mem_en = 0;
850 sh->ipool[i] = mlx5_ipool_create(&cfg);
856 * Release the flow resources' indexed mempool.
859 * Pointer to mlx5_dev_ctx_shared object.
862 mlx5_flow_ipool_destroy(struct mlx5_dev_ctx_shared *sh)
866 for (i = 0; i < MLX5_IPOOL_MAX; ++i)
867 mlx5_ipool_destroy(sh->ipool[i]);
868 for (i = 0; i < MLX5_MAX_MODIFY_NUM; ++i)
869 if (sh->mdh_ipools[i])
870 mlx5_ipool_destroy(sh->mdh_ipools[i]);
874 * Check if dynamic flex parser for eCPRI already exists.
877 * Pointer to Ethernet device structure.
880 * true on exists, false on not.
883 mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev)
885 struct mlx5_priv *priv = dev->data->dev_private;
886 struct mlx5_ecpri_parser_profile *prf = &priv->sh->ecpri_parser;
892 * Allocation of a flex parser for eCPRI. Once created, this parser related
893 * resources will be held until the device is closed.
896 * Pointer to Ethernet device structure.
899 * 0 on success, a negative errno value otherwise and rte_errno is set.
902 mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev)
904 struct mlx5_priv *priv = dev->data->dev_private;
905 struct mlx5_ecpri_parser_profile *prf = &priv->sh->ecpri_parser;
906 struct mlx5_devx_graph_node_attr node = {
907 .modify_field_select = 0,
912 if (!priv->sh->cdev->config.hca_attr.parse_graph_flex_node) {
913 DRV_LOG(ERR, "Dynamic flex parser is not supported "
914 "for device %s.", priv->dev_data->name);
917 node.header_length_mode = MLX5_GRAPH_NODE_LEN_FIXED;
918 /* 8 bytes now: 4B common header + 4B message body header. */
919 node.header_length_base_value = 0x8;
920 /* After MAC layer: Ether / VLAN. */
921 node.in[0].arc_parse_graph_node = MLX5_GRAPH_ARC_NODE_MAC;
922 /* Type of compared condition should be 0xAEFE in the L2 layer. */
923 node.in[0].compare_condition_value = RTE_ETHER_TYPE_ECPRI;
924 /* Sample #0: type in common header. */
925 node.sample[0].flow_match_sample_en = 1;
927 node.sample[0].flow_match_sample_offset_mode = 0x0;
928 /* Only the 2nd byte will be used. */
929 node.sample[0].flow_match_sample_field_base_offset = 0x0;
930 /* Sample #1: message payload. */
931 node.sample[1].flow_match_sample_en = 1;
933 node.sample[1].flow_match_sample_offset_mode = 0x0;
935 * Only the first two bytes will be used right now, and its offset will
936 * start after the common header that with the length of a DW(u32).
938 node.sample[1].flow_match_sample_field_base_offset = sizeof(uint32_t);
939 prf->obj = mlx5_devx_cmd_create_flex_parser(priv->sh->cdev->ctx, &node);
941 DRV_LOG(ERR, "Failed to create flex parser node object.");
942 return (rte_errno == 0) ? -ENODEV : -rte_errno;
945 ret = mlx5_devx_cmd_query_parse_samples(prf->obj, ids, prf->num);
947 DRV_LOG(ERR, "Failed to query sample IDs.");
948 return (rte_errno == 0) ? -ENODEV : -rte_errno;
950 prf->offset[0] = 0x0;
951 prf->offset[1] = sizeof(uint32_t);
952 prf->ids[0] = ids[0];
953 prf->ids[1] = ids[1];
958 * Destroy the flex parser node, including the parser itself, input / output
959 * arcs and DW samples. Resources could be reused then.
962 * Pointer to Ethernet device structure.
965 mlx5_flex_parser_ecpri_release(struct rte_eth_dev *dev)
967 struct mlx5_priv *priv = dev->data->dev_private;
968 struct mlx5_ecpri_parser_profile *prf = &priv->sh->ecpri_parser;
971 mlx5_devx_cmd_destroy(prf->obj);
976 mlx5_get_supported_sw_parsing_offloads(const struct mlx5_hca_attr *attr)
978 uint32_t sw_parsing_offloads = 0;
981 sw_parsing_offloads |= MLX5_SW_PARSING_CAP;
983 sw_parsing_offloads |= MLX5_SW_PARSING_CSUM_CAP;
986 sw_parsing_offloads |= MLX5_SW_PARSING_TSO_CAP;
988 return sw_parsing_offloads;
992 mlx5_get_supported_tunneling_offloads(const struct mlx5_hca_attr *attr)
994 uint32_t tn_offloads = 0;
996 if (attr->tunnel_stateless_vxlan)
997 tn_offloads |= MLX5_TUNNELED_OFFLOADS_VXLAN_CAP;
998 if (attr->tunnel_stateless_gre)
999 tn_offloads |= MLX5_TUNNELED_OFFLOADS_GRE_CAP;
1000 if (attr->tunnel_stateless_geneve_rx)
1001 tn_offloads |= MLX5_TUNNELED_OFFLOADS_GENEVE_CAP;
1005 /* Fill all fields of UAR structure. */
1007 mlx5_rxtx_uars_prepare(struct mlx5_dev_ctx_shared *sh)
1011 ret = mlx5_devx_uar_prepare(sh->cdev, &sh->tx_uar);
1013 DRV_LOG(ERR, "Failed to prepare Tx DevX UAR.");
1016 MLX5_ASSERT(sh->tx_uar.obj);
1017 MLX5_ASSERT(mlx5_os_get_devx_uar_base_addr(sh->tx_uar.obj));
1018 ret = mlx5_devx_uar_prepare(sh->cdev, &sh->rx_uar);
1020 DRV_LOG(ERR, "Failed to prepare Rx DevX UAR.");
1021 mlx5_devx_uar_release(&sh->tx_uar);
1024 MLX5_ASSERT(sh->rx_uar.obj);
1025 MLX5_ASSERT(mlx5_os_get_devx_uar_base_addr(sh->rx_uar.obj));
1030 mlx5_rxtx_uars_release(struct mlx5_dev_ctx_shared *sh)
1032 mlx5_devx_uar_release(&sh->rx_uar);
1033 mlx5_devx_uar_release(&sh->tx_uar);
1037 * rte_mempool_walk() callback to unregister Rx mempools.
1038 * It used when implicit mempool registration is disabled.
1041 * The mempool being walked.
1043 * Pointer to the device shared context.
1046 mlx5_dev_ctx_shared_rx_mempool_unregister_cb(struct rte_mempool *mp, void *arg)
1048 struct mlx5_dev_ctx_shared *sh = arg;
1050 mlx5_dev_mempool_unregister(sh->cdev, mp);
1054 * Callback used when implicit mempool registration is disabled
1055 * in order to track Rx mempool destruction.
1058 * Mempool life cycle event.
1060 * An Rx mempool registered explicitly when the port is started.
1062 * Pointer to a device shared context.
1065 mlx5_dev_ctx_shared_rx_mempool_event_cb(enum rte_mempool_event event,
1066 struct rte_mempool *mp, void *arg)
1068 struct mlx5_dev_ctx_shared *sh = arg;
1070 if (event == RTE_MEMPOOL_EVENT_DESTROY)
1071 mlx5_dev_mempool_unregister(sh->cdev, mp);
1075 mlx5_dev_ctx_shared_mempool_subscribe(struct rte_eth_dev *dev)
1077 struct mlx5_priv *priv = dev->data->dev_private;
1078 struct mlx5_dev_ctx_shared *sh = priv->sh;
1081 /* Check if we only need to track Rx mempool destruction. */
1082 if (!sh->cdev->config.mr_mempool_reg_en) {
1083 ret = rte_mempool_event_callback_register
1084 (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh);
1085 return ret == 0 || rte_errno == EEXIST ? 0 : ret;
1087 return mlx5_dev_mempool_subscribe(sh->cdev);
1091 * Set up multiple TISs with different affinities according to
1092 * number of bonding ports
1095 * Pointer of shared context.
1098 * Zero on success, -1 otherwise.
1101 mlx5_setup_tis(struct mlx5_dev_ctx_shared *sh)
1104 struct mlx5_devx_lag_context lag_ctx = { 0 };
1105 struct mlx5_devx_tis_attr tis_attr = { 0 };
1107 tis_attr.transport_domain = sh->td->id;
1108 if (sh->bond.n_port) {
1109 if (!mlx5_devx_cmd_query_lag(sh->cdev->ctx, &lag_ctx)) {
1110 sh->lag.tx_remap_affinity[0] =
1111 lag_ctx.tx_remap_affinity_1;
1112 sh->lag.tx_remap_affinity[1] =
1113 lag_ctx.tx_remap_affinity_2;
1114 sh->lag.affinity_mode = lag_ctx.port_select_mode;
1116 DRV_LOG(ERR, "Failed to query lag affinity.");
1119 if (sh->lag.affinity_mode == MLX5_LAG_MODE_TIS) {
1120 for (i = 0; i < sh->bond.n_port; i++) {
1121 tis_attr.lag_tx_port_affinity =
1122 MLX5_IFC_LAG_MAP_TIS_AFFINITY(i,
1124 sh->tis[i] = mlx5_devx_cmd_create_tis(sh->cdev->ctx,
1127 DRV_LOG(ERR, "Failed to TIS %d/%d for bonding device"
1128 " %s.", i, sh->bond.n_port,
1133 DRV_LOG(DEBUG, "LAG number of ports : %d, affinity_1 & 2 : pf%d & %d.\n",
1134 sh->bond.n_port, lag_ctx.tx_remap_affinity_1,
1135 lag_ctx.tx_remap_affinity_2);
1138 if (sh->lag.affinity_mode == MLX5_LAG_MODE_HASH)
1139 DRV_LOG(INFO, "Device %s enabled HW hash based LAG.",
1142 tis_attr.lag_tx_port_affinity = 0;
1143 sh->tis[0] = mlx5_devx_cmd_create_tis(sh->cdev->ctx, &tis_attr);
1145 DRV_LOG(ERR, "Failed to TIS 0 for bonding device"
1146 " %s.", sh->ibdev_name);
1153 * Verify and store value for share device argument.
1156 * Key argument to verify.
1158 * Value associated with key.
1163 * 0 on success, a negative errno value otherwise and rte_errno is set.
1166 mlx5_dev_args_check_handler(const char *key, const char *val, void *opaque)
1168 struct mlx5_sh_config *config = opaque;
1172 tmp = strtol(val, NULL, 0);
1175 DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
1178 if (tmp < 0 && strcmp(MLX5_TX_PP, key) && strcmp(MLX5_TX_SKEW, key)) {
1179 /* Negative values are acceptable for some keys only. */
1181 DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
1184 if (strcmp(MLX5_TX_PP, key) == 0) {
1185 unsigned long mod = tmp >= 0 ? tmp : -tmp;
1188 DRV_LOG(ERR, "Zero Tx packet pacing parameter.");
1192 config->tx_pp = tmp;
1193 } else if (strcmp(MLX5_TX_SKEW, key) == 0) {
1194 config->tx_skew = tmp;
1195 } else if (strcmp(MLX5_L3_VXLAN_EN, key) == 0) {
1196 config->l3_vxlan_en = !!tmp;
1197 } else if (strcmp(MLX5_VF_NL_EN, key) == 0) {
1198 config->vf_nl_en = !!tmp;
1199 } else if (strcmp(MLX5_DV_ESW_EN, key) == 0) {
1200 config->dv_esw_en = !!tmp;
1201 } else if (strcmp(MLX5_DV_FLOW_EN, key) == 0) {
1202 config->dv_flow_en = !!tmp;
1203 } else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
1204 if (tmp != MLX5_XMETA_MODE_LEGACY &&
1205 tmp != MLX5_XMETA_MODE_META16 &&
1206 tmp != MLX5_XMETA_MODE_META32 &&
1207 tmp != MLX5_XMETA_MODE_MISS_INFO) {
1208 DRV_LOG(ERR, "Invalid extensive metadata parameter.");
1212 if (tmp != MLX5_XMETA_MODE_MISS_INFO)
1213 config->dv_xmeta_en = tmp;
1215 config->dv_miss_info = 1;
1216 } else if (strcmp(MLX5_LACP_BY_USER, key) == 0) {
1217 config->lacp_by_user = !!tmp;
1218 } else if (strcmp(MLX5_RECLAIM_MEM, key) == 0) {
1219 if (tmp != MLX5_RCM_NONE &&
1220 tmp != MLX5_RCM_LIGHT &&
1221 tmp != MLX5_RCM_AGGR) {
1222 DRV_LOG(ERR, "Unrecognize %s: \"%s\"", key, val);
1226 config->reclaim_mode = tmp;
1227 } else if (strcmp(MLX5_DECAP_EN, key) == 0) {
1228 config->decap_en = !!tmp;
1229 } else if (strcmp(MLX5_ALLOW_DUPLICATE_PATTERN, key) == 0) {
1230 config->allow_duplicate_pattern = !!tmp;
1236 * Parse user device parameters and adjust them according to device
1240 * Pointer to shared device context.
1242 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
1244 * Pointer to shared device configuration structure.
1247 * 0 on success, a negative errno value otherwise and rte_errno is set.
1250 mlx5_shared_dev_ctx_args_config(struct mlx5_dev_ctx_shared *sh,
1251 struct mlx5_kvargs_ctrl *mkvlist,
1252 struct mlx5_sh_config *config)
1254 const char **params = (const char *[]){
1265 MLX5_ALLOW_DUPLICATE_PATTERN,
1270 /* Default configuration. */
1271 memset(config, 0, sizeof(*config));
1272 config->vf_nl_en = 1;
1273 config->dv_esw_en = 1;
1274 config->dv_flow_en = 1;
1275 config->decap_en = 1;
1276 config->allow_duplicate_pattern = 1;
1277 if (mkvlist != NULL) {
1278 /* Process parameters. */
1279 ret = mlx5_kvargs_process(mkvlist, params,
1280 mlx5_dev_args_check_handler, config);
1282 DRV_LOG(ERR, "Failed to process device arguments: %s",
1283 strerror(rte_errno));
1287 /* Adjust parameters according to device capabilities. */
1288 if (config->dv_flow_en && !sh->dev_cap.dv_flow_en) {
1289 DRV_LOG(WARNING, "DV flow is not supported.");
1290 config->dv_flow_en = 0;
1292 if (config->dv_esw_en && !sh->dev_cap.dv_esw_en) {
1293 DRV_LOG(DEBUG, "E-Switch DV flow is not supported.");
1294 config->dv_esw_en = 0;
1296 if (config->dv_miss_info && config->dv_esw_en)
1297 config->dv_xmeta_en = MLX5_XMETA_MODE_META16;
1298 if (!config->dv_esw_en &&
1299 config->dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
1301 "Metadata mode %u is not supported (no E-Switch).",
1302 config->dv_xmeta_en);
1303 config->dv_xmeta_en = MLX5_XMETA_MODE_LEGACY;
1305 if (config->tx_pp && !sh->dev_cap.txpp_en) {
1306 DRV_LOG(ERR, "Packet pacing is not supported.");
1310 if (!config->tx_pp && config->tx_skew) {
1312 "\"tx_skew\" doesn't affect without \"tx_pp\".");
1315 * If HW has bug working with tunnel packet decapsulation and scatter
1316 * FCS, and decapsulation is needed, clear the hw_fcs_strip bit.
1317 * Then RTE_ETH_RX_OFFLOAD_KEEP_CRC bit will not be set anymore.
1319 if (sh->dev_cap.scatter_fcs_w_decap_disable && sh->config.decap_en)
1320 config->hw_fcs_strip = 0;
1322 config->hw_fcs_strip = sh->dev_cap.hw_fcs_strip;
1323 DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported",
1324 (config->hw_fcs_strip ? "" : "not "));
1325 DRV_LOG(DEBUG, "\"tx_pp\" is %d.", config->tx_pp);
1326 DRV_LOG(DEBUG, "\"tx_skew\" is %d.", config->tx_skew);
1327 DRV_LOG(DEBUG, "\"reclaim_mode\" is %u.", config->reclaim_mode);
1328 DRV_LOG(DEBUG, "\"dv_esw_en\" is %u.", config->dv_esw_en);
1329 DRV_LOG(DEBUG, "\"dv_flow_en\" is %u.", config->dv_flow_en);
1330 DRV_LOG(DEBUG, "\"dv_xmeta_en\" is %u.", config->dv_xmeta_en);
1331 DRV_LOG(DEBUG, "\"dv_miss_info\" is %u.", config->dv_miss_info);
1332 DRV_LOG(DEBUG, "\"l3_vxlan_en\" is %u.", config->l3_vxlan_en);
1333 DRV_LOG(DEBUG, "\"vf_nl_en\" is %u.", config->vf_nl_en);
1334 DRV_LOG(DEBUG, "\"lacp_by_user\" is %u.", config->lacp_by_user);
1335 DRV_LOG(DEBUG, "\"decap_en\" is %u.", config->decap_en);
1336 DRV_LOG(DEBUG, "\"allow_duplicate_pattern\" is %u.",
1337 config->allow_duplicate_pattern);
1342 * Configure realtime timestamp format.
1345 * Pointer to mlx5_dev_ctx_shared object.
1347 * Pointer to DevX HCA capabilities structure.
1350 mlx5_rt_timestamp_config(struct mlx5_dev_ctx_shared *sh,
1351 struct mlx5_hca_attr *hca_attr)
1353 uint32_t dw_cnt = MLX5_ST_SZ_DW(register_mtutc);
1354 uint32_t reg[dw_cnt];
1357 if (hca_attr->access_register_user)
1358 ret = mlx5_devx_cmd_register_read(sh->cdev->ctx,
1359 MLX5_REGISTER_ID_MTUTC, 0,
1364 /* MTUTC register is read successfully. */
1365 ts_mode = MLX5_GET(register_mtutc, reg, time_stamp_mode);
1366 if (ts_mode == MLX5_MTUTC_TIMESTAMP_MODE_REAL_TIME)
1367 sh->dev_cap.rt_timestamp = 1;
1369 /* Kernel does not support register reading. */
1370 if (hca_attr->dev_freq_khz == (NS_PER_S / MS_PER_S))
1371 sh->dev_cap.rt_timestamp = 1;
1376 * Allocate shared device context. If there is multiport device the
1377 * master and representors will share this context, if there is single
1378 * port dedicated device, the context will be used by only given
1379 * port due to unification.
1381 * Routine first searches the context for the specified device name,
1382 * if found the shared context assumed and reference counter is incremented.
1383 * If no context found the new one is created and initialized with specified
1384 * device context and parameters.
1387 * Pointer to the device attributes (name, port, etc).
1389 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
1392 * Pointer to mlx5_dev_ctx_shared object on success,
1393 * otherwise NULL and rte_errno is set.
1395 struct mlx5_dev_ctx_shared *
1396 mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
1397 struct mlx5_kvargs_ctrl *mkvlist)
1399 struct mlx5_dev_ctx_shared *sh;
1404 /* Secondary process should not create the shared context. */
1405 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
1406 pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
1407 /* Search for IB context by device name. */
1408 LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) {
1409 if (!strcmp(sh->ibdev_name, spawn->phys_dev_name)) {
1414 /* No device found, we have to create new shared context. */
1415 MLX5_ASSERT(spawn->max_port);
1416 sh = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1417 sizeof(struct mlx5_dev_ctx_shared) +
1418 spawn->max_port * sizeof(struct mlx5_dev_shared_port),
1419 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1421 DRV_LOG(ERR, "Shared context allocation failure.");
1425 pthread_mutex_init(&sh->txpp.mutex, NULL);
1426 sh->numa_node = spawn->cdev->dev->numa_node;
1427 sh->cdev = spawn->cdev;
1428 sh->esw_mode = !!(spawn->info.master || spawn->info.representor);
1429 if (spawn->bond_info)
1430 sh->bond = *spawn->bond_info;
1431 err = mlx5_os_capabilities_prepare(sh);
1433 DRV_LOG(ERR, "Fail to configure device capabilities.");
1436 err = mlx5_shared_dev_ctx_args_config(sh, mkvlist, &sh->config);
1438 DRV_LOG(ERR, "Failed to process device configure: %s",
1439 strerror(rte_errno));
1443 sh->max_port = spawn->max_port;
1444 strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->cdev->ctx),
1445 sizeof(sh->ibdev_name) - 1);
1446 strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->cdev->ctx),
1447 sizeof(sh->ibdev_path) - 1);
1449 * Setting port_id to max unallowed value means there is no interrupt
1450 * subhandler installed for the given port index i.
1452 for (i = 0; i < sh->max_port; i++) {
1453 sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
1454 sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS;
1456 if (sh->cdev->config.devx) {
1457 sh->td = mlx5_devx_cmd_create_td(sh->cdev->ctx);
1459 DRV_LOG(ERR, "TD allocation failure");
1463 if (mlx5_setup_tis(sh)) {
1464 DRV_LOG(ERR, "TIS allocation failure");
1468 err = mlx5_rxtx_uars_prepare(sh);
1473 /* Initialize UAR access locks for 32bit implementations. */
1474 rte_spinlock_init(&sh->uar_lock_cq);
1475 for (i = 0; i < MLX5_UAR_PAGE_NUM_MAX; i++)
1476 rte_spinlock_init(&sh->uar_lock[i]);
1479 mlx5_os_dev_shared_handler_install(sh);
1480 if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
1481 err = mlx5_flow_os_init_workspace_once();
1485 mlx5_flow_aging_init(sh);
1486 mlx5_flow_counters_mng_init(sh);
1487 mlx5_flow_ipool_create(sh);
1488 /* Add context to the global device list. */
1489 LIST_INSERT_HEAD(&mlx5_dev_ctx_list, sh, next);
1490 rte_spinlock_init(&sh->geneve_tlv_opt_sl);
1492 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1496 pthread_mutex_destroy(&sh->txpp.mutex);
1497 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1499 mlx5_rxtx_uars_release(sh);
1503 claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
1504 } while (++i < (uint32_t)sh->bond.n_port);
1506 claim_zero(mlx5_devx_cmd_destroy(sh->td));
1513 * Free shared IB device context. Decrement counter and if zero free
1514 * all allocated resources and close handles.
1517 * Pointer to mlx5_dev_ctx_shared object to free
1520 mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
1525 pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
1526 #ifdef RTE_LIBRTE_MLX5_DEBUG
1527 /* Check the object presence in the list. */
1528 struct mlx5_dev_ctx_shared *lctx;
1530 LIST_FOREACH(lctx, &mlx5_dev_ctx_list, next)
1535 DRV_LOG(ERR, "Freeing non-existing shared IB context");
1540 MLX5_ASSERT(sh->refcnt);
1541 /* Secondary process should not free the shared context. */
1542 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
1545 /* Stop watching for mempool events and unregister all mempools. */
1546 if (!sh->cdev->config.mr_mempool_reg_en) {
1547 ret = rte_mempool_event_callback_unregister
1548 (mlx5_dev_ctx_shared_rx_mempool_event_cb, sh);
1551 (mlx5_dev_ctx_shared_rx_mempool_unregister_cb, sh);
1553 /* Remove context from the global device list. */
1554 LIST_REMOVE(sh, next);
1555 /* Release resources on the last device removal. */
1556 if (LIST_EMPTY(&mlx5_dev_ctx_list)) {
1557 mlx5_os_net_cleanup();
1558 mlx5_flow_os_release_workspace();
1560 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1561 if (sh->flex_parsers_dv) {
1562 mlx5_list_destroy(sh->flex_parsers_dv);
1563 sh->flex_parsers_dv = NULL;
1566 * Ensure there is no async event handler installed.
1567 * Only primary process handles async device events.
1569 mlx5_flow_counters_mng_close(sh);
1571 mlx5_flow_aso_ct_mng_close(sh);
1572 if (sh->aso_age_mng) {
1573 mlx5_flow_aso_age_mng_close(sh);
1574 sh->aso_age_mng = NULL;
1577 mlx5_aso_flow_mtrs_mng_close(sh);
1578 mlx5_flow_ipool_destroy(sh);
1579 mlx5_os_dev_shared_handler_uninstall(sh);
1580 mlx5_rxtx_uars_release(sh);
1583 claim_zero(mlx5_devx_cmd_destroy(sh->tis[i]));
1584 } while (++i < sh->bond.n_port);
1586 claim_zero(mlx5_devx_cmd_destroy(sh->td));
1587 MLX5_ASSERT(sh->geneve_tlv_option_resource == NULL);
1588 pthread_mutex_destroy(&sh->txpp.mutex);
1592 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
1596 * Destroy table hash list.
1599 * Pointer to the private device data structure.
1602 mlx5_free_table_hash_list(struct mlx5_priv *priv)
1604 struct mlx5_dev_ctx_shared *sh = priv->sh;
1608 mlx5_hlist_destroy(sh->flow_tbls);
1609 sh->flow_tbls = NULL;
1613 * Initialize flow table hash list and create the root tables entry
1617 * Pointer to the private device data structure.
1620 * Zero on success, positive error code otherwise.
1623 mlx5_alloc_table_hash_list(struct mlx5_priv *priv __rte_unused)
1626 /* Tables are only used in DV and DR modes. */
1627 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
1628 struct mlx5_dev_ctx_shared *sh = priv->sh;
1629 char s[MLX5_NAME_SIZE];
1632 snprintf(s, sizeof(s), "%s_flow_table", priv->sh->ibdev_name);
1633 sh->flow_tbls = mlx5_hlist_create(s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE,
1635 flow_dv_tbl_create_cb,
1636 flow_dv_tbl_match_cb,
1637 flow_dv_tbl_remove_cb,
1638 flow_dv_tbl_clone_cb,
1639 flow_dv_tbl_clone_free_cb);
1640 if (!sh->flow_tbls) {
1641 DRV_LOG(ERR, "flow tables with hash creation failed.");
1645 #ifndef HAVE_MLX5DV_DR
1646 struct rte_flow_error error;
1647 struct rte_eth_dev *dev = &rte_eth_devices[priv->dev_data->port_id];
1650 * In case we have not DR support, the zero tables should be created
1651 * because DV expect to see them even if they cannot be created by
1654 if (!flow_dv_tbl_resource_get(dev, 0, 0, 0, 0,
1655 NULL, 0, 1, 0, &error) ||
1656 !flow_dv_tbl_resource_get(dev, 0, 1, 0, 0,
1657 NULL, 0, 1, 0, &error) ||
1658 !flow_dv_tbl_resource_get(dev, 0, 0, 1, 0,
1659 NULL, 0, 1, 0, &error)) {
1665 mlx5_free_table_hash_list(priv);
1666 #endif /* HAVE_MLX5DV_DR */
1672 * Retrieve integer value from environment variable.
1675 * Environment variable name.
1678 * Integer value, 0 if the variable is not set.
1681 mlx5_getenv_int(const char *name)
1683 const char *val = getenv(name);
1691 * DPDK callback to add udp tunnel port
1694 * A pointer to eth_dev
1695 * @param[in] udp_tunnel
1696 * A pointer to udp tunnel
1699 * 0 on valid udp ports and tunnels, -ENOTSUP otherwise.
1702 mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev __rte_unused,
1703 struct rte_eth_udp_tunnel *udp_tunnel)
1705 MLX5_ASSERT(udp_tunnel != NULL);
1706 if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN &&
1707 udp_tunnel->udp_port == 4789)
1709 if (udp_tunnel->prot_type == RTE_ETH_TUNNEL_TYPE_VXLAN_GPE &&
1710 udp_tunnel->udp_port == 4790)
1716 * Initialize process private data structure.
1719 * Pointer to Ethernet device structure.
1722 * 0 on success, a negative errno value otherwise and rte_errno is set.
1725 mlx5_proc_priv_init(struct rte_eth_dev *dev)
1727 struct mlx5_priv *priv = dev->data->dev_private;
1728 struct mlx5_proc_priv *ppriv;
1731 mlx5_proc_priv_uninit(dev);
1733 * UAR register table follows the process private structure. BlueFlame
1734 * registers for Tx queues are stored in the table.
1736 ppriv_size = sizeof(struct mlx5_proc_priv) +
1737 priv->txqs_n * sizeof(struct mlx5_uar_data);
1738 ppriv = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, ppriv_size,
1739 RTE_CACHE_LINE_SIZE, dev->device->numa_node);
1744 ppriv->uar_table_sz = priv->txqs_n;
1745 dev->process_private = ppriv;
1746 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1747 priv->sh->pppriv = ppriv;
1752 * Un-initialize process private data structure.
1755 * Pointer to Ethernet device structure.
1758 mlx5_proc_priv_uninit(struct rte_eth_dev *dev)
1760 if (!dev->process_private)
1762 mlx5_free(dev->process_private);
1763 dev->process_private = NULL;
1767 * DPDK callback to close the device.
1769 * Destroy all queues and objects, free memory.
1772 * Pointer to Ethernet device structure.
1775 mlx5_dev_close(struct rte_eth_dev *dev)
1777 struct mlx5_priv *priv = dev->data->dev_private;
1781 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1782 /* Check if process_private released. */
1783 if (!dev->process_private)
1785 mlx5_tx_uar_uninit_secondary(dev);
1786 mlx5_proc_priv_uninit(dev);
1787 rte_eth_dev_release_port(dev);
1792 DRV_LOG(DEBUG, "port %u closing device \"%s\"",
1794 ((priv->sh->cdev->ctx != NULL) ?
1795 mlx5_os_get_ctx_device_name(priv->sh->cdev->ctx) : ""));
1797 * If default mreg copy action is removed at the stop stage,
1798 * the search will return none and nothing will be done anymore.
1800 mlx5_flow_stop_default(dev);
1801 mlx5_traffic_disable(dev);
1803 * If all the flows are already flushed in the device stop stage,
1804 * then this will return directly without any action.
1806 mlx5_flow_list_flush(dev, MLX5_FLOW_TYPE_GEN, true);
1807 mlx5_action_handle_flush(dev);
1808 mlx5_flow_meter_flush(dev, NULL);
1809 /* Prevent crashes when queues are still in use. */
1810 dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1811 dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
1813 /* Disable datapath on secondary process. */
1814 mlx5_mp_os_req_stop_rxtx(dev);
1815 /* Free the eCPRI flex parser resource. */
1816 mlx5_flex_parser_ecpri_release(dev);
1817 mlx5_flex_item_port_cleanup(dev);
1818 if (priv->rxq_privs != NULL) {
1819 /* XXX race condition if mlx5_rx_burst() is still running. */
1820 rte_delay_us_sleep(1000);
1821 for (i = 0; (i != priv->rxqs_n); ++i)
1822 mlx5_rxq_release(dev, i);
1824 mlx5_free(priv->rxq_privs);
1825 priv->rxq_privs = NULL;
1827 if (priv->txqs != NULL) {
1828 /* XXX race condition if mlx5_tx_burst() is still running. */
1829 rte_delay_us_sleep(1000);
1830 for (i = 0; (i != priv->txqs_n); ++i)
1831 mlx5_txq_release(dev, i);
1835 mlx5_proc_priv_uninit(dev);
1836 if (priv->q_counters) {
1837 mlx5_devx_cmd_destroy(priv->q_counters);
1838 priv->q_counters = NULL;
1840 if (priv->drop_queue.hrxq)
1841 mlx5_drop_action_destroy(dev);
1842 if (priv->mreg_cp_tbl)
1843 mlx5_hlist_destroy(priv->mreg_cp_tbl);
1844 mlx5_mprq_free_mp(dev);
1845 mlx5_os_free_shared_dr(priv);
1846 if (priv->rss_conf.rss_key != NULL)
1847 mlx5_free(priv->rss_conf.rss_key);
1848 if (priv->reta_idx != NULL)
1849 mlx5_free(priv->reta_idx);
1850 if (priv->sh->dev_cap.vf)
1851 mlx5_os_mac_addr_flush(dev);
1852 if (priv->nl_socket_route >= 0)
1853 close(priv->nl_socket_route);
1854 if (priv->nl_socket_rdma >= 0)
1855 close(priv->nl_socket_rdma);
1856 if (priv->vmwa_context)
1857 mlx5_vlan_vmwa_exit(priv->vmwa_context);
1858 ret = mlx5_hrxq_verify(dev);
1860 DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
1861 dev->data->port_id);
1862 ret = mlx5_ind_table_obj_verify(dev);
1864 DRV_LOG(WARNING, "port %u some indirection table still remain",
1865 dev->data->port_id);
1866 ret = mlx5_rxq_obj_verify(dev);
1868 DRV_LOG(WARNING, "port %u some Rx queue objects still remain",
1869 dev->data->port_id);
1870 ret = mlx5_rxq_verify(dev);
1872 DRV_LOG(WARNING, "port %u some Rx queues still remain",
1873 dev->data->port_id);
1874 ret = mlx5_txq_obj_verify(dev);
1876 DRV_LOG(WARNING, "port %u some Verbs Tx queue still remain",
1877 dev->data->port_id);
1878 ret = mlx5_txq_verify(dev);
1880 DRV_LOG(WARNING, "port %u some Tx queues still remain",
1881 dev->data->port_id);
1882 ret = mlx5_flow_verify(dev);
1884 DRV_LOG(WARNING, "port %u some flows still remain",
1885 dev->data->port_id);
1887 mlx5_list_destroy(priv->hrxqs);
1889 * Free the shared context in last turn, because the cleanup
1890 * routines above may use some shared fields, like
1891 * mlx5_os_mac_addr_flush() uses ibdev_path for retrieving
1892 * ifindex if Netlink fails.
1894 mlx5_free_shared_dev_ctx(priv->sh);
1895 if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
1899 MLX5_ETH_FOREACH_DEV(port_id, dev->device) {
1900 struct mlx5_priv *opriv =
1901 rte_eth_devices[port_id].data->dev_private;
1904 opriv->domain_id != priv->domain_id ||
1905 &rte_eth_devices[port_id] == dev)
1911 claim_zero(rte_eth_switch_domain_free(priv->domain_id));
1913 memset(priv, 0, sizeof(*priv));
1914 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
1916 * Reset mac_addrs to NULL such that it is not freed as part of
1917 * rte_eth_dev_release_port(). mac_addrs is part of dev_private so
1918 * it is freed when dev_private is freed.
1920 dev->data->mac_addrs = NULL;
1924 const struct eth_dev_ops mlx5_dev_ops = {
1925 .dev_configure = mlx5_dev_configure,
1926 .dev_start = mlx5_dev_start,
1927 .dev_stop = mlx5_dev_stop,
1928 .dev_set_link_down = mlx5_set_link_down,
1929 .dev_set_link_up = mlx5_set_link_up,
1930 .dev_close = mlx5_dev_close,
1931 .promiscuous_enable = mlx5_promiscuous_enable,
1932 .promiscuous_disable = mlx5_promiscuous_disable,
1933 .allmulticast_enable = mlx5_allmulticast_enable,
1934 .allmulticast_disable = mlx5_allmulticast_disable,
1935 .link_update = mlx5_link_update,
1936 .stats_get = mlx5_stats_get,
1937 .stats_reset = mlx5_stats_reset,
1938 .xstats_get = mlx5_xstats_get,
1939 .xstats_reset = mlx5_xstats_reset,
1940 .xstats_get_names = mlx5_xstats_get_names,
1941 .fw_version_get = mlx5_fw_version_get,
1942 .dev_infos_get = mlx5_dev_infos_get,
1943 .representor_info_get = mlx5_representor_info_get,
1944 .read_clock = mlx5_txpp_read_clock,
1945 .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
1946 .vlan_filter_set = mlx5_vlan_filter_set,
1947 .rx_queue_setup = mlx5_rx_queue_setup,
1948 .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
1949 .tx_queue_setup = mlx5_tx_queue_setup,
1950 .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
1951 .rx_queue_release = mlx5_rx_queue_release,
1952 .tx_queue_release = mlx5_tx_queue_release,
1953 .rx_queue_start = mlx5_rx_queue_start,
1954 .rx_queue_stop = mlx5_rx_queue_stop,
1955 .tx_queue_start = mlx5_tx_queue_start,
1956 .tx_queue_stop = mlx5_tx_queue_stop,
1957 .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
1958 .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
1959 .mac_addr_remove = mlx5_mac_addr_remove,
1960 .mac_addr_add = mlx5_mac_addr_add,
1961 .mac_addr_set = mlx5_mac_addr_set,
1962 .set_mc_addr_list = mlx5_set_mc_addr_list,
1963 .mtu_set = mlx5_dev_set_mtu,
1964 .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
1965 .vlan_offload_set = mlx5_vlan_offload_set,
1966 .reta_update = mlx5_dev_rss_reta_update,
1967 .reta_query = mlx5_dev_rss_reta_query,
1968 .rss_hash_update = mlx5_rss_hash_update,
1969 .rss_hash_conf_get = mlx5_rss_hash_conf_get,
1970 .flow_ops_get = mlx5_flow_ops_get,
1971 .rxq_info_get = mlx5_rxq_info_get,
1972 .txq_info_get = mlx5_txq_info_get,
1973 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
1974 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
1975 .rx_queue_intr_enable = mlx5_rx_intr_enable,
1976 .rx_queue_intr_disable = mlx5_rx_intr_disable,
1977 .is_removed = mlx5_is_removed,
1978 .udp_tunnel_port_add = mlx5_udp_tunnel_port_add,
1979 .get_module_info = mlx5_get_module_info,
1980 .get_module_eeprom = mlx5_get_module_eeprom,
1981 .hairpin_cap_get = mlx5_hairpin_cap_get,
1982 .mtr_ops_get = mlx5_flow_meter_ops_get,
1983 .hairpin_bind = mlx5_hairpin_bind,
1984 .hairpin_unbind = mlx5_hairpin_unbind,
1985 .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
1986 .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
1987 .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
1988 .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
1989 .get_monitor_addr = mlx5_get_monitor_addr,
1992 /* Available operations from secondary process. */
1993 const struct eth_dev_ops mlx5_dev_sec_ops = {
1994 .stats_get = mlx5_stats_get,
1995 .stats_reset = mlx5_stats_reset,
1996 .xstats_get = mlx5_xstats_get,
1997 .xstats_reset = mlx5_xstats_reset,
1998 .xstats_get_names = mlx5_xstats_get_names,
1999 .fw_version_get = mlx5_fw_version_get,
2000 .dev_infos_get = mlx5_dev_infos_get,
2001 .representor_info_get = mlx5_representor_info_get,
2002 .read_clock = mlx5_txpp_read_clock,
2003 .rx_queue_start = mlx5_rx_queue_start,
2004 .rx_queue_stop = mlx5_rx_queue_stop,
2005 .tx_queue_start = mlx5_tx_queue_start,
2006 .tx_queue_stop = mlx5_tx_queue_stop,
2007 .rxq_info_get = mlx5_rxq_info_get,
2008 .txq_info_get = mlx5_txq_info_get,
2009 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2010 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2011 .get_module_info = mlx5_get_module_info,
2012 .get_module_eeprom = mlx5_get_module_eeprom,
2015 /* Available operations in flow isolated mode. */
2016 const struct eth_dev_ops mlx5_dev_ops_isolate = {
2017 .dev_configure = mlx5_dev_configure,
2018 .dev_start = mlx5_dev_start,
2019 .dev_stop = mlx5_dev_stop,
2020 .dev_set_link_down = mlx5_set_link_down,
2021 .dev_set_link_up = mlx5_set_link_up,
2022 .dev_close = mlx5_dev_close,
2023 .promiscuous_enable = mlx5_promiscuous_enable,
2024 .promiscuous_disable = mlx5_promiscuous_disable,
2025 .allmulticast_enable = mlx5_allmulticast_enable,
2026 .allmulticast_disable = mlx5_allmulticast_disable,
2027 .link_update = mlx5_link_update,
2028 .stats_get = mlx5_stats_get,
2029 .stats_reset = mlx5_stats_reset,
2030 .xstats_get = mlx5_xstats_get,
2031 .xstats_reset = mlx5_xstats_reset,
2032 .xstats_get_names = mlx5_xstats_get_names,
2033 .fw_version_get = mlx5_fw_version_get,
2034 .dev_infos_get = mlx5_dev_infos_get,
2035 .representor_info_get = mlx5_representor_info_get,
2036 .read_clock = mlx5_txpp_read_clock,
2037 .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
2038 .vlan_filter_set = mlx5_vlan_filter_set,
2039 .rx_queue_setup = mlx5_rx_queue_setup,
2040 .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
2041 .tx_queue_setup = mlx5_tx_queue_setup,
2042 .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
2043 .rx_queue_release = mlx5_rx_queue_release,
2044 .tx_queue_release = mlx5_tx_queue_release,
2045 .rx_queue_start = mlx5_rx_queue_start,
2046 .rx_queue_stop = mlx5_rx_queue_stop,
2047 .tx_queue_start = mlx5_tx_queue_start,
2048 .tx_queue_stop = mlx5_tx_queue_stop,
2049 .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
2050 .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
2051 .mac_addr_remove = mlx5_mac_addr_remove,
2052 .mac_addr_add = mlx5_mac_addr_add,
2053 .mac_addr_set = mlx5_mac_addr_set,
2054 .set_mc_addr_list = mlx5_set_mc_addr_list,
2055 .mtu_set = mlx5_dev_set_mtu,
2056 .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
2057 .vlan_offload_set = mlx5_vlan_offload_set,
2058 .flow_ops_get = mlx5_flow_ops_get,
2059 .rxq_info_get = mlx5_rxq_info_get,
2060 .txq_info_get = mlx5_txq_info_get,
2061 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
2062 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
2063 .rx_queue_intr_enable = mlx5_rx_intr_enable,
2064 .rx_queue_intr_disable = mlx5_rx_intr_disable,
2065 .is_removed = mlx5_is_removed,
2066 .get_module_info = mlx5_get_module_info,
2067 .get_module_eeprom = mlx5_get_module_eeprom,
2068 .hairpin_cap_get = mlx5_hairpin_cap_get,
2069 .mtr_ops_get = mlx5_flow_meter_ops_get,
2070 .hairpin_bind = mlx5_hairpin_bind,
2071 .hairpin_unbind = mlx5_hairpin_unbind,
2072 .hairpin_get_peer_ports = mlx5_hairpin_get_peer_ports,
2073 .hairpin_queue_peer_update = mlx5_hairpin_queue_peer_update,
2074 .hairpin_queue_peer_bind = mlx5_hairpin_queue_peer_bind,
2075 .hairpin_queue_peer_unbind = mlx5_hairpin_queue_peer_unbind,
2076 .get_monitor_addr = mlx5_get_monitor_addr,
2080 * Verify and store value for device argument.
2083 * Key argument to verify.
2085 * Value associated with key.
2090 * 0 on success, a negative errno value otherwise and rte_errno is set.
2093 mlx5_port_args_check_handler(const char *key, const char *val, void *opaque)
2095 struct mlx5_port_config *config = opaque;
2098 /* No-op, port representors are processed in mlx5_dev_spawn(). */
2099 if (!strcmp(MLX5_REPRESENTOR, key))
2102 tmp = strtol(val, NULL, 0);
2105 DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
2109 /* Negative values are acceptable for some keys only. */
2111 DRV_LOG(WARNING, "%s: invalid negative value \"%s\"", key, val);
2114 if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
2115 if (tmp > MLX5_CQE_RESP_FORMAT_L34H_STRIDX) {
2116 DRV_LOG(ERR, "invalid CQE compression "
2117 "format parameter");
2121 config->cqe_comp = !!tmp;
2122 config->cqe_comp_fmt = tmp;
2123 } else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
2124 config->hw_padding = !!tmp;
2125 } else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
2126 config->mprq.enabled = !!tmp;
2127 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_NUM, key) == 0) {
2128 config->mprq.log_stride_num = tmp;
2129 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_SIZE, key) == 0) {
2130 config->mprq.log_stride_size = tmp;
2131 } else if (strcmp(MLX5_RX_MPRQ_MAX_MEMCPY_LEN, key) == 0) {
2132 config->mprq.max_memcpy_len = tmp;
2133 } else if (strcmp(MLX5_RXQS_MIN_MPRQ, key) == 0) {
2134 config->mprq.min_rxqs_num = tmp;
2135 } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
2136 DRV_LOG(WARNING, "%s: deprecated parameter,"
2137 " converted to txq_inline_max", key);
2138 config->txq_inline_max = tmp;
2139 } else if (strcmp(MLX5_TXQ_INLINE_MAX, key) == 0) {
2140 config->txq_inline_max = tmp;
2141 } else if (strcmp(MLX5_TXQ_INLINE_MIN, key) == 0) {
2142 config->txq_inline_min = tmp;
2143 } else if (strcmp(MLX5_TXQ_INLINE_MPW, key) == 0) {
2144 config->txq_inline_mpw = tmp;
2145 } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
2146 config->txqs_inline = tmp;
2147 } else if (strcmp(MLX5_TXQS_MAX_VEC, key) == 0) {
2148 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2149 } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
2150 config->mps = !!tmp;
2151 } else if (strcmp(MLX5_TXQ_MPW_HDR_DSEG_EN, key) == 0) {
2152 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2153 } else if (strcmp(MLX5_TXQ_MAX_INLINE_LEN, key) == 0) {
2154 DRV_LOG(WARNING, "%s: deprecated parameter,"
2155 " converted to txq_inline_mpw", key);
2156 config->txq_inline_mpw = tmp;
2157 } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
2158 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
2159 } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
2160 config->rx_vec_en = !!tmp;
2161 } else if (strcmp(MLX5_MAX_DUMP_FILES_NUM, key) == 0) {
2162 config->max_dump_files_num = tmp;
2163 } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) {
2164 config->lro_timeout = tmp;
2165 } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) {
2166 config->log_hp_size = tmp;
2167 } else if (strcmp(MLX5_DELAY_DROP, key) == 0) {
2168 config->std_delay_drop = !!(tmp & MLX5_DELAY_DROP_STANDARD);
2169 config->hp_delay_drop = !!(tmp & MLX5_DELAY_DROP_HAIRPIN);
2175 * Parse user port parameters and adjust them according to device capabilities.
2178 * Pointer to shared device context.
2180 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
2182 * Pointer to port configuration structure.
2185 * 0 on success, a negative errno value otherwise and rte_errno is set.
2188 mlx5_port_args_config(struct mlx5_priv *priv, struct mlx5_kvargs_ctrl *mkvlist,
2189 struct mlx5_port_config *config)
2191 struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2192 struct mlx5_dev_cap *dev_cap = &priv->sh->dev_cap;
2193 bool devx = priv->sh->cdev->config.devx;
2194 const char **params = (const char *[]){
2195 MLX5_RXQ_CQE_COMP_EN,
2196 MLX5_RXQ_PKT_PAD_EN,
2198 MLX5_RX_MPRQ_LOG_STRIDE_NUM,
2199 MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
2200 MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
2203 MLX5_TXQ_INLINE_MIN,
2204 MLX5_TXQ_INLINE_MAX,
2205 MLX5_TXQ_INLINE_MPW,
2206 MLX5_TXQS_MIN_INLINE,
2209 MLX5_TXQ_MPW_HDR_DSEG_EN,
2210 MLX5_TXQ_MAX_INLINE_LEN,
2214 MLX5_MAX_DUMP_FILES_NUM,
2215 MLX5_LRO_TIMEOUT_USEC,
2222 /* Default configuration. */
2223 memset(config, 0, sizeof(*config));
2224 config->mps = MLX5_ARG_UNSET;
2225 config->cqe_comp = 1;
2226 config->rx_vec_en = 1;
2227 config->txq_inline_max = MLX5_ARG_UNSET;
2228 config->txq_inline_min = MLX5_ARG_UNSET;
2229 config->txq_inline_mpw = MLX5_ARG_UNSET;
2230 config->txqs_inline = MLX5_ARG_UNSET;
2231 config->mprq.max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN;
2232 config->mprq.min_rxqs_num = MLX5_MPRQ_MIN_RXQS;
2233 config->mprq.log_stride_num = MLX5_MPRQ_DEFAULT_LOG_STRIDE_NUM;
2234 config->log_hp_size = MLX5_ARG_UNSET;
2235 config->std_delay_drop = 0;
2236 config->hp_delay_drop = 0;
2237 if (mkvlist != NULL) {
2238 /* Process parameters. */
2239 ret = mlx5_kvargs_process(mkvlist, params,
2240 mlx5_port_args_check_handler, config);
2242 DRV_LOG(ERR, "Failed to process port arguments: %s",
2243 strerror(rte_errno));
2247 /* Adjust parameters according to device capabilities. */
2248 if (config->hw_padding && !dev_cap->hw_padding) {
2249 DRV_LOG(DEBUG, "Rx end alignment padding isn't supported.");
2250 config->hw_padding = 0;
2251 } else if (config->hw_padding) {
2252 DRV_LOG(DEBUG, "Rx end alignment padding is enabled.");
2255 * MPW is disabled by default, while the Enhanced MPW is enabled
2258 if (config->mps == MLX5_ARG_UNSET)
2259 config->mps = (dev_cap->mps == MLX5_MPW_ENHANCED) ?
2260 MLX5_MPW_ENHANCED : MLX5_MPW_DISABLED;
2262 config->mps = config->mps ? dev_cap->mps : MLX5_MPW_DISABLED;
2263 DRV_LOG(INFO, "%sMPS is %s",
2264 config->mps == MLX5_MPW_ENHANCED ? "enhanced " :
2265 config->mps == MLX5_MPW ? "legacy " : "",
2266 config->mps != MLX5_MPW_DISABLED ? "enabled" : "disabled");
2267 /* LRO is supported only when DV flow enabled. */
2268 if (dev_cap->lro_supported && !priv->sh->config.dv_flow_en)
2269 dev_cap->lro_supported = 0;
2270 if (dev_cap->lro_supported) {
2272 * If LRO timeout is not configured by application,
2273 * use the minimal supported value.
2275 if (!config->lro_timeout)
2276 config->lro_timeout =
2277 hca_attr->lro_timer_supported_periods[0];
2278 DRV_LOG(DEBUG, "LRO session timeout set to %d usec.",
2279 config->lro_timeout);
2281 if (config->cqe_comp && !dev_cap->cqe_comp) {
2282 DRV_LOG(WARNING, "Rx CQE 128B compression is not supported.");
2283 config->cqe_comp = 0;
2285 if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_FTAG_STRIDX &&
2286 (!devx || !hca_attr->mini_cqe_resp_flow_tag)) {
2288 "Flow Tag CQE compression format isn't supported.");
2289 config->cqe_comp = 0;
2291 if (config->cqe_comp_fmt == MLX5_CQE_RESP_FORMAT_L34H_STRIDX &&
2292 (!devx || !hca_attr->mini_cqe_resp_l3_l4_tag)) {
2294 "L3/L4 Header CQE compression format isn't supported.");
2295 config->cqe_comp = 0;
2297 DRV_LOG(DEBUG, "Rx CQE compression is %ssupported.",
2298 config->cqe_comp ? "" : "not ");
2299 if ((config->std_delay_drop || config->hp_delay_drop) &&
2300 !dev_cap->rq_delay_drop_en) {
2301 config->std_delay_drop = 0;
2302 config->hp_delay_drop = 0;
2303 DRV_LOG(WARNING, "dev_port-%u: Rxq delay drop isn't supported.",
2306 if (config->mprq.enabled && !priv->sh->dev_cap.mprq.enabled) {
2307 DRV_LOG(WARNING, "Multi-Packet RQ isn't supported.");
2308 config->mprq.enabled = 0;
2310 if (config->max_dump_files_num == 0)
2311 config->max_dump_files_num = 128;
2312 /* Detect minimal data bytes to inline. */
2313 mlx5_set_min_inline(priv);
2314 DRV_LOG(DEBUG, "VLAN insertion in WQE is %ssupported.",
2315 config->hw_vlan_insert ? "" : "not ");
2316 DRV_LOG(DEBUG, "\"rxq_pkt_pad_en\" is %u.", config->hw_padding);
2317 DRV_LOG(DEBUG, "\"rxq_cqe_comp_en\" is %u.", config->cqe_comp);
2318 DRV_LOG(DEBUG, "\"cqe_comp_fmt\" is %u.", config->cqe_comp_fmt);
2319 DRV_LOG(DEBUG, "\"rx_vec_en\" is %u.", config->rx_vec_en);
2320 DRV_LOG(DEBUG, "Standard \"delay_drop\" is %u.",
2321 config->std_delay_drop);
2322 DRV_LOG(DEBUG, "Hairpin \"delay_drop\" is %u.", config->hp_delay_drop);
2323 DRV_LOG(DEBUG, "\"max_dump_files_num\" is %u.",
2324 config->max_dump_files_num);
2325 DRV_LOG(DEBUG, "\"log_hp_size\" is %u.", config->log_hp_size);
2326 DRV_LOG(DEBUG, "\"mprq_en\" is %u.", config->mprq.enabled);
2327 DRV_LOG(DEBUG, "\"mprq_log_stride_num\" is %u.",
2328 config->mprq.log_stride_num);
2329 DRV_LOG(DEBUG, "\"mprq_log_stride_size\" is %u.",
2330 config->mprq.log_stride_size);
2331 DRV_LOG(DEBUG, "\"mprq_max_memcpy_len\" is %u.",
2332 config->mprq.max_memcpy_len);
2333 DRV_LOG(DEBUG, "\"rxqs_min_mprq\" is %u.", config->mprq.min_rxqs_num);
2334 DRV_LOG(DEBUG, "\"lro_timeout_usec\" is %u.", config->lro_timeout);
2335 DRV_LOG(DEBUG, "\"txq_mpw_en\" is %d.", config->mps);
2336 DRV_LOG(DEBUG, "\"txqs_min_inline\" is %d.", config->txqs_inline);
2337 DRV_LOG(DEBUG, "\"txq_inline_min\" is %d.", config->txq_inline_min);
2338 DRV_LOG(DEBUG, "\"txq_inline_max\" is %d.", config->txq_inline_max);
2339 DRV_LOG(DEBUG, "\"txq_inline_mpw\" is %d.", config->txq_inline_mpw);
2344 * Print the key for device argument.
2346 * It is "dummy" handler whose whole purpose is to enable using
2347 * mlx5_kvargs_process() function which set devargs as used.
2352 * Value associated with key, unused.
2354 * Unused, can be NULL.
2357 * 0 on success, function cannot fail.
2360 mlx5_dummy_handler(const char *key, const char *val, void *opaque)
2362 DRV_LOG(DEBUG, "\tKey: \"%s\" is set as used.", key);
2363 RTE_SET_USED(opaque);
2369 * Set requested devargs as used when device is already spawned.
2371 * It is necessary since it is valid to ask probe again for existing device,
2372 * if its devargs don't assign as used, mlx5_kvargs_validate() will fail.
2375 * Name of the existing device.
2377 * Port identifier of the device.
2379 * Pointer to mlx5 kvargs control to sign as used.
2382 mlx5_port_args_set_used(const char *name, uint16_t port_id,
2383 struct mlx5_kvargs_ctrl *mkvlist)
2385 const char **params = (const char *[]){
2386 MLX5_RXQ_CQE_COMP_EN,
2387 MLX5_RXQ_PKT_PAD_EN,
2389 MLX5_RX_MPRQ_LOG_STRIDE_NUM,
2390 MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
2391 MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
2394 MLX5_TXQ_INLINE_MIN,
2395 MLX5_TXQ_INLINE_MAX,
2396 MLX5_TXQ_INLINE_MPW,
2397 MLX5_TXQS_MIN_INLINE,
2400 MLX5_TXQ_MPW_HDR_DSEG_EN,
2401 MLX5_TXQ_MAX_INLINE_LEN,
2405 MLX5_MAX_DUMP_FILES_NUM,
2406 MLX5_LRO_TIMEOUT_USEC,
2412 /* Secondary process should not handle devargs. */
2413 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2415 MLX5_ASSERT(mkvlist != NULL);
2416 DRV_LOG(DEBUG, "Ethernet device \"%s\" for port %u "
2417 "already exists, set devargs as used:", name, port_id);
2418 /* This function cannot fail with this handler. */
2419 mlx5_kvargs_process(mkvlist, params, mlx5_dummy_handler, NULL);
2423 * Check sibling device configurations when probing again.
2425 * Sibling devices sharing infiniband device context should have compatible
2426 * configurations. This regards representors and bonding device.
2429 * Pointer to mlx5 device structure.
2431 * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
2434 * 0 on success, a negative errno value otherwise and rte_errno is set.
2437 mlx5_probe_again_args_validate(struct mlx5_common_device *cdev,
2438 struct mlx5_kvargs_ctrl *mkvlist)
2440 struct mlx5_dev_ctx_shared *sh = NULL;
2441 struct mlx5_sh_config *config;
2444 /* Secondary process should not handle devargs. */
2445 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2447 pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
2448 /* Search for IB context by common device pointer. */
2449 LIST_FOREACH(sh, &mlx5_dev_ctx_list, next)
2450 if (sh->cdev == cdev)
2452 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
2453 /* There is sh for this device -> it isn't probe again. */
2456 config = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
2457 sizeof(struct mlx5_sh_config),
2458 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
2459 if (config == NULL) {
2460 rte_errno = -ENOMEM;
2464 * Creates a temporary IB context configure structure according to new
2465 * devargs attached in probing again.
2467 ret = mlx5_shared_dev_ctx_args_config(sh, mkvlist, config);
2469 DRV_LOG(ERR, "Failed to process device configure: %s",
2470 strerror(rte_errno));
2475 * Checks the match between the temporary structure and the existing
2476 * IB context structure.
2478 if (sh->config.dv_flow_en ^ config->dv_flow_en) {
2479 DRV_LOG(ERR, "\"dv_flow_en\" "
2480 "configuration mismatch for shared %s context.",
2484 if ((sh->config.dv_xmeta_en ^ config->dv_xmeta_en) ||
2485 (sh->config.dv_miss_info ^ config->dv_miss_info)) {
2486 DRV_LOG(ERR, "\"dv_xmeta_en\" "
2487 "configuration mismatch for shared %s context.",
2491 if (sh->config.dv_esw_en ^ config->dv_esw_en) {
2492 DRV_LOG(ERR, "\"dv_esw_en\" "
2493 "configuration mismatch for shared %s context.",
2497 if (sh->config.reclaim_mode ^ config->reclaim_mode) {
2498 DRV_LOG(ERR, "\"reclaim_mode\" "
2499 "configuration mismatch for shared %s context.",
2503 if (sh->config.allow_duplicate_pattern ^
2504 config->allow_duplicate_pattern) {
2505 DRV_LOG(ERR, "\"allow_duplicate_pattern\" "
2506 "configuration mismatch for shared %s context.",
2510 if (sh->config.l3_vxlan_en ^ config->l3_vxlan_en) {
2511 DRV_LOG(ERR, "\"l3_vxlan_en\" "
2512 "configuration mismatch for shared %s context.",
2516 if (sh->config.decap_en ^ config->decap_en) {
2517 DRV_LOG(ERR, "\"decap_en\" "
2518 "configuration mismatch for shared %s context.",
2522 if (sh->config.lacp_by_user ^ config->lacp_by_user) {
2523 DRV_LOG(ERR, "\"lacp_by_user\" "
2524 "configuration mismatch for shared %s context.",
2528 if (sh->config.tx_pp ^ config->tx_pp) {
2529 DRV_LOG(ERR, "\"tx_pp\" "
2530 "configuration mismatch for shared %s context.",
2534 if (sh->config.tx_skew ^ config->tx_skew) {
2535 DRV_LOG(ERR, "\"tx_skew\" "
2536 "configuration mismatch for shared %s context.",
2549 * Configures the minimal amount of data to inline into WQE
2550 * while sending packets.
2552 * - the txq_inline_min has the maximal priority, if this
2553 * key is specified in devargs
2554 * - if DevX is enabled the inline mode is queried from the
2555 * device (HCA attributes and NIC vport context if needed).
2556 * - otherwise L2 mode (18 bytes) is assumed for ConnectX-4/4 Lx
2557 * and none (0 bytes) for other NICs
2560 * Pointer to the private device data structure.
2563 mlx5_set_min_inline(struct mlx5_priv *priv)
2565 struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr;
2566 struct mlx5_port_config *config = &priv->config;
2568 if (config->txq_inline_min != MLX5_ARG_UNSET) {
2569 /* Application defines size of inlined data explicitly. */
2570 if (priv->pci_dev != NULL) {
2571 switch (priv->pci_dev->id.device_id) {
2572 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
2573 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
2574 if (config->txq_inline_min <
2575 (int)MLX5_INLINE_HSIZE_L2) {
2577 "txq_inline_mix aligned to minimal ConnectX-4 required value %d",
2578 (int)MLX5_INLINE_HSIZE_L2);
2579 config->txq_inline_min =
2580 MLX5_INLINE_HSIZE_L2;
2587 if (hca_attr->eth_net_offloads) {
2588 /* We have DevX enabled, inline mode queried successfully. */
2589 switch (hca_attr->wqe_inline_mode) {
2590 case MLX5_CAP_INLINE_MODE_L2:
2591 /* outer L2 header must be inlined. */
2592 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
2594 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
2595 /* No inline data are required by NIC. */
2596 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2597 config->hw_vlan_insert =
2598 hca_attr->wqe_vlan_insert;
2599 DRV_LOG(DEBUG, "Tx VLAN insertion is supported");
2601 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
2602 /* inline mode is defined by NIC vport context. */
2603 if (!hca_attr->eth_virt)
2605 switch (hca_attr->vport_inline_mode) {
2606 case MLX5_INLINE_MODE_NONE:
2607 config->txq_inline_min =
2608 MLX5_INLINE_HSIZE_NONE;
2610 case MLX5_INLINE_MODE_L2:
2611 config->txq_inline_min =
2612 MLX5_INLINE_HSIZE_L2;
2614 case MLX5_INLINE_MODE_IP:
2615 config->txq_inline_min =
2616 MLX5_INLINE_HSIZE_L3;
2618 case MLX5_INLINE_MODE_TCP_UDP:
2619 config->txq_inline_min =
2620 MLX5_INLINE_HSIZE_L4;
2622 case MLX5_INLINE_MODE_INNER_L2:
2623 config->txq_inline_min =
2624 MLX5_INLINE_HSIZE_INNER_L2;
2626 case MLX5_INLINE_MODE_INNER_IP:
2627 config->txq_inline_min =
2628 MLX5_INLINE_HSIZE_INNER_L3;
2630 case MLX5_INLINE_MODE_INNER_TCP_UDP:
2631 config->txq_inline_min =
2632 MLX5_INLINE_HSIZE_INNER_L4;
2637 if (priv->pci_dev == NULL) {
2638 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2642 * We get here if we are unable to deduce
2643 * inline data size with DevX. Try PCI ID
2644 * to determine old NICs.
2646 switch (priv->pci_dev->id.device_id) {
2647 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
2648 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
2649 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LX:
2650 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
2651 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
2652 config->hw_vlan_insert = 0;
2654 case PCI_DEVICE_ID_MELLANOX_CONNECTX5:
2655 case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
2656 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EX:
2657 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
2659 * These NICs support VLAN insertion from WQE and
2660 * report the wqe_vlan_insert flag. But there is the bug
2661 * and PFC control may be broken, so disable feature.
2663 config->hw_vlan_insert = 0;
2664 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2667 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2671 DRV_LOG(DEBUG, "min tx inline configured: %d", config->txq_inline_min);
2675 * Configures the metadata mask fields in the shared context.
2678 * Pointer to Ethernet device.
2681 mlx5_set_metadata_mask(struct rte_eth_dev *dev)
2683 struct mlx5_priv *priv = dev->data->dev_private;
2684 struct mlx5_dev_ctx_shared *sh = priv->sh;
2685 uint32_t meta, mark, reg_c0;
2687 reg_c0 = ~priv->vport_meta_mask;
2688 switch (sh->config.dv_xmeta_en) {
2689 case MLX5_XMETA_MODE_LEGACY:
2691 mark = MLX5_FLOW_MARK_MASK;
2693 case MLX5_XMETA_MODE_META16:
2694 meta = reg_c0 >> rte_bsf32(reg_c0);
2695 mark = MLX5_FLOW_MARK_MASK;
2697 case MLX5_XMETA_MODE_META32:
2699 mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
2707 if (sh->dv_mark_mask && sh->dv_mark_mask != mark)
2708 DRV_LOG(WARNING, "metadata MARK mask mismatch %08X:%08X",
2709 sh->dv_mark_mask, mark);
2711 sh->dv_mark_mask = mark;
2712 if (sh->dv_meta_mask && sh->dv_meta_mask != meta)
2713 DRV_LOG(WARNING, "metadata META mask mismatch %08X:%08X",
2714 sh->dv_meta_mask, meta);
2716 sh->dv_meta_mask = meta;
2717 if (sh->dv_regc0_mask && sh->dv_regc0_mask != reg_c0)
2718 DRV_LOG(WARNING, "metadata reg_c0 mask mismatch %08X:%08X",
2719 sh->dv_meta_mask, reg_c0);
2721 sh->dv_regc0_mask = reg_c0;
2722 DRV_LOG(DEBUG, "metadata mode %u", sh->config.dv_xmeta_en);
2723 DRV_LOG(DEBUG, "metadata MARK mask %08X", sh->dv_mark_mask);
2724 DRV_LOG(DEBUG, "metadata META mask %08X", sh->dv_meta_mask);
2725 DRV_LOG(DEBUG, "metadata reg_c0 mask %08X", sh->dv_regc0_mask);
2729 rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
2731 static const char *const dynf_names[] = {
2732 RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
2733 RTE_MBUF_DYNFLAG_METADATA_NAME,
2734 RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME
2738 if (n < RTE_DIM(dynf_names))
2740 for (i = 0; i < RTE_DIM(dynf_names); i++) {
2741 if (names[i] == NULL)
2743 strcpy(names[i], dynf_names[i]);
2745 return RTE_DIM(dynf_names);
2749 * Look for the ethernet device belonging to mlx5 driver.
2751 * @param[in] port_id
2752 * port_id to start looking for device.
2754 * Pointer to the hint device. When device is being probed
2755 * the its siblings (master and preceding representors might
2756 * not have assigned driver yet (because the mlx5_os_pci_probe()
2757 * is not completed yet, for this case match on hint
2758 * device may be used to detect sibling device.
2761 * port_id of found device, RTE_MAX_ETHPORT if not found.
2764 mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev)
2766 while (port_id < RTE_MAX_ETHPORTS) {
2767 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
2769 if (dev->state != RTE_ETH_DEV_UNUSED &&
2771 (dev->device == odev ||
2772 (dev->device->driver &&
2773 dev->device->driver->name &&
2774 ((strcmp(dev->device->driver->name,
2775 MLX5_PCI_DRIVER_NAME) == 0) ||
2776 (strcmp(dev->device->driver->name,
2777 MLX5_AUXILIARY_DRIVER_NAME) == 0)))))
2781 if (port_id >= RTE_MAX_ETHPORTS)
2782 return RTE_MAX_ETHPORTS;
2787 * Callback to remove a device.
2789 * This function removes all Ethernet devices belong to a given device.
2792 * Pointer to the generic device.
2795 * 0 on success, the function cannot fail.
2798 mlx5_net_remove(struct mlx5_common_device *cdev)
2803 RTE_ETH_FOREACH_DEV_OF(port_id, cdev->dev) {
2805 * mlx5_dev_close() is not registered to secondary process,
2806 * call the close function explicitly for secondary process.
2808 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
2809 ret |= mlx5_dev_close(&rte_eth_devices[port_id]);
2811 ret |= rte_eth_dev_close(port_id);
2813 return ret == 0 ? 0 : -EIO;
2816 static const struct rte_pci_id mlx5_pci_id_map[] = {
2818 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2819 PCI_DEVICE_ID_MELLANOX_CONNECTX4)
2822 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2823 PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
2826 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2827 PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
2830 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2831 PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
2834 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2835 PCI_DEVICE_ID_MELLANOX_CONNECTX5)
2838 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2839 PCI_DEVICE_ID_MELLANOX_CONNECTX5VF)
2842 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2843 PCI_DEVICE_ID_MELLANOX_CONNECTX5EX)
2846 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2847 PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)
2850 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2851 PCI_DEVICE_ID_MELLANOX_CONNECTX5BF)
2854 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2855 PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF)
2858 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2859 PCI_DEVICE_ID_MELLANOX_CONNECTX6)
2862 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2863 PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
2866 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2867 PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
2870 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2871 PCI_DEVICE_ID_MELLANOX_CONNECTXVF)
2874 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2875 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
2878 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2879 PCI_DEVICE_ID_MELLANOX_CONNECTX6LX)
2882 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2883 PCI_DEVICE_ID_MELLANOX_CONNECTX7)
2886 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
2887 PCI_DEVICE_ID_MELLANOX_CONNECTX7BF)
2894 static struct mlx5_class_driver mlx5_net_driver = {
2895 .drv_class = MLX5_CLASS_ETH,
2896 .name = RTE_STR(MLX5_ETH_DRIVER_NAME),
2897 .id_table = mlx5_pci_id_map,
2898 .probe = mlx5_os_net_probe,
2899 .remove = mlx5_net_remove,
2905 /* Initialize driver log type. */
2906 RTE_LOG_REGISTER_DEFAULT(mlx5_logtype, NOTICE)
2909 * Driver initialization routine.
2911 RTE_INIT(rte_mlx5_pmd_init)
2913 pthread_mutex_init(&mlx5_dev_ctx_list_mutex, NULL);
2915 /* Build the static tables for Verbs conversion. */
2916 mlx5_set_ptype_table();
2917 mlx5_set_cksum_table();
2918 mlx5_set_swp_types_table();
2920 mlx5_class_driver_register(&mlx5_net_driver);
2923 RTE_PMD_EXPORT_NAME(MLX5_ETH_DRIVER_NAME, __COUNTER__);
2924 RTE_PMD_REGISTER_PCI_TABLE(MLX5_ETH_DRIVER_NAME, mlx5_pci_id_map);
2925 RTE_PMD_REGISTER_KMOD_DEP(MLX5_ETH_DRIVER_NAME, "* ib_uverbs & mlx5_core & mlx5_ib");