1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2015 6WIND S.A.
3 * Copyright 2015 Mellanox Technologies, Ltd
14 #include <linux/rtnetlink.h>
17 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
19 #pragma GCC diagnostic ignored "-Wpedantic"
21 #include <infiniband/verbs.h>
23 #pragma GCC diagnostic error "-Wpedantic"
26 #include <rte_malloc.h>
27 #include <rte_ethdev_driver.h>
28 #include <rte_ethdev_pci.h>
30 #include <rte_bus_pci.h>
31 #include <rte_common.h>
32 #include <rte_kvargs.h>
33 #include <rte_rwlock.h>
34 #include <rte_spinlock.h>
35 #include <rte_string_fns.h>
36 #include <rte_alarm.h>
38 #include <mlx5_glue.h>
39 #include <mlx5_devx_cmds.h>
40 #include <mlx5_common.h>
41 #include <mlx5_common_mp.h>
43 #include "mlx5_defs.h"
45 #include "mlx5_utils.h"
46 #include "mlx5_rxtx.h"
47 #include "mlx5_autoconf.h"
49 #include "mlx5_flow.h"
50 #include "rte_pmd_mlx5.h"
52 /* Device parameter to enable RX completion queue compression. */
53 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
55 /* Device parameter to enable RX completion entry padding to 128B. */
56 #define MLX5_RXQ_CQE_PAD_EN "rxq_cqe_pad_en"
58 /* Device parameter to enable padding Rx packet to cacheline size. */
59 #define MLX5_RXQ_PKT_PAD_EN "rxq_pkt_pad_en"
61 /* Device parameter to enable Multi-Packet Rx queue. */
62 #define MLX5_RX_MPRQ_EN "mprq_en"
64 /* Device parameter to configure log 2 of the number of strides for MPRQ. */
65 #define MLX5_RX_MPRQ_LOG_STRIDE_NUM "mprq_log_stride_num"
67 /* Device parameter to configure log 2 of the stride size for MPRQ. */
68 #define MLX5_RX_MPRQ_LOG_STRIDE_SIZE "mprq_log_stride_size"
70 /* Device parameter to limit the size of memcpy'd packet for MPRQ. */
71 #define MLX5_RX_MPRQ_MAX_MEMCPY_LEN "mprq_max_memcpy_len"
73 /* Device parameter to set the minimum number of Rx queues to enable MPRQ. */
74 #define MLX5_RXQS_MIN_MPRQ "rxqs_min_mprq"
76 /* Device parameter to configure inline send. Deprecated, ignored.*/
77 #define MLX5_TXQ_INLINE "txq_inline"
79 /* Device parameter to limit packet size to inline with ordinary SEND. */
80 #define MLX5_TXQ_INLINE_MAX "txq_inline_max"
82 /* Device parameter to configure minimal data size to inline. */
83 #define MLX5_TXQ_INLINE_MIN "txq_inline_min"
85 /* Device parameter to limit packet size to inline with Enhanced MPW. */
86 #define MLX5_TXQ_INLINE_MPW "txq_inline_mpw"
89 * Device parameter to configure the number of TX queues threshold for
90 * enabling inline send.
92 #define MLX5_TXQS_MIN_INLINE "txqs_min_inline"
95 * Device parameter to configure the number of TX queues threshold for
96 * enabling vectorized Tx, deprecated, ignored (no vectorized Tx routines).
98 #define MLX5_TXQS_MAX_VEC "txqs_max_vec"
100 /* Device parameter to enable multi-packet send WQEs. */
101 #define MLX5_TXQ_MPW_EN "txq_mpw_en"
104 * Device parameter to force doorbell register mapping
105 * to non-cahed region eliminating the extra write memory barrier.
107 #define MLX5_TX_DB_NC "tx_db_nc"
110 * Device parameter to include 2 dsegs in the title WQEBB.
111 * Deprecated, ignored.
113 #define MLX5_TXQ_MPW_HDR_DSEG_EN "txq_mpw_hdr_dseg_en"
116 * Device parameter to limit the size of inlining packet.
117 * Deprecated, ignored.
119 #define MLX5_TXQ_MAX_INLINE_LEN "txq_max_inline_len"
122 * Device parameter to enable hardware Tx vector.
123 * Deprecated, ignored (no vectorized Tx routines anymore).
125 #define MLX5_TX_VEC_EN "tx_vec_en"
127 /* Device parameter to enable hardware Rx vector. */
128 #define MLX5_RX_VEC_EN "rx_vec_en"
130 /* Allow L3 VXLAN flow creation. */
131 #define MLX5_L3_VXLAN_EN "l3_vxlan_en"
133 /* Activate DV E-Switch flow steering. */
134 #define MLX5_DV_ESW_EN "dv_esw_en"
136 /* Activate DV flow steering. */
137 #define MLX5_DV_FLOW_EN "dv_flow_en"
139 /* Enable extensive flow metadata support. */
140 #define MLX5_DV_XMETA_EN "dv_xmeta_en"
142 /* Activate Netlink support in VF mode. */
143 #define MLX5_VF_NL_EN "vf_nl_en"
145 /* Enable extending memsegs when creating a MR. */
146 #define MLX5_MR_EXT_MEMSEG_EN "mr_ext_memseg_en"
148 /* Select port representors to instantiate. */
149 #define MLX5_REPRESENTOR "representor"
151 /* Device parameter to configure the maximum number of dump files per queue. */
152 #define MLX5_MAX_DUMP_FILES_NUM "max_dump_files_num"
154 /* Configure timeout of LRO session (in microseconds). */
155 #define MLX5_LRO_TIMEOUT_USEC "lro_timeout_usec"
158 * Device parameter to configure the total data buffer size for a single
159 * hairpin queue (logarithm value).
161 #define MLX5_HP_BUF_SIZE "hp_buf_log_sz"
163 #ifndef HAVE_IBV_MLX5_MOD_MPW
164 #define MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED (1 << 2)
165 #define MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW (1 << 3)
168 #ifndef HAVE_IBV_MLX5_MOD_CQE_128B_COMP
169 #define MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP (1 << 4)
172 static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data";
174 /* Shared memory between primary and secondary processes. */
175 struct mlx5_shared_data *mlx5_shared_data;
177 /* Spinlock for mlx5_shared_data allocation. */
178 static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
180 /* Process local data for secondary processes. */
181 static struct mlx5_local_data mlx5_local_data;
183 /** Driver-specific log messages type. */
186 /** Data associated with devices to spawn. */
187 struct mlx5_dev_spawn_data {
188 uint32_t ifindex; /**< Network interface index. */
189 uint32_t max_port; /**< IB device maximal port index. */
190 uint32_t ibv_port; /**< IB device physical port index. */
191 int pf_bond; /**< bonding device PF index. < 0 - no bonding */
192 struct mlx5_switch_info info; /**< Switch information. */
193 struct ibv_device *ibv_dev; /**< Associated IB device. */
194 struct rte_eth_dev *eth_dev; /**< Associated Ethernet device. */
195 struct rte_pci_device *pci_dev; /**< Backend PCI device. */
198 static LIST_HEAD(, mlx5_ibv_shared) mlx5_ibv_list = LIST_HEAD_INITIALIZER();
199 static pthread_mutex_t mlx5_ibv_list_mutex = PTHREAD_MUTEX_INITIALIZER;
201 static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
202 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
204 .size = sizeof(struct mlx5_flow_dv_encap_decap_resource),
210 .malloc = rte_malloc_socket,
212 .type = "mlx5_encap_decap_ipool",
215 .size = sizeof(struct mlx5_flow_dv_push_vlan_action_resource),
221 .malloc = rte_malloc_socket,
223 .type = "mlx5_push_vlan_ipool",
226 .size = sizeof(struct mlx5_flow_dv_tag_resource),
232 .malloc = rte_malloc_socket,
234 .type = "mlx5_tag_ipool",
237 .size = sizeof(struct mlx5_flow_dv_port_id_action_resource),
243 .malloc = rte_malloc_socket,
245 .type = "mlx5_port_id_ipool",
248 .size = sizeof(struct mlx5_flow_tbl_data_entry),
254 .malloc = rte_malloc_socket,
256 .type = "mlx5_jump_ipool",
260 .size = sizeof(struct mlx5_flow_meter),
266 .malloc = rte_malloc_socket,
268 .type = "mlx5_meter_ipool",
271 .size = sizeof(struct mlx5_flow_mreg_copy_resource),
277 .malloc = rte_malloc_socket,
279 .type = "mlx5_mcp_ipool",
282 .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
288 .malloc = rte_malloc_socket,
290 .type = "mlx5_hrxq_ipool",
293 .size = sizeof(struct mlx5_flow_handle),
299 .malloc = rte_malloc_socket,
301 .type = "mlx5_flow_handle_ipool",
306 #define MLX5_FLOW_MIN_ID_POOL_SIZE 512
307 #define MLX5_ID_GENERATION_ARRAY_FACTOR 16
309 #define MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE 4096
310 #define MLX5_TAGS_HLIST_ARRAY_SIZE 8192
313 * Allocate ID pool structure.
316 * The maximum id can be allocated from the pool.
319 * Pointer to pool object, NULL value otherwise.
321 struct mlx5_flow_id_pool *
322 mlx5_flow_id_pool_alloc(uint32_t max_id)
324 struct mlx5_flow_id_pool *pool;
327 pool = rte_zmalloc("id pool allocation", sizeof(*pool),
328 RTE_CACHE_LINE_SIZE);
330 DRV_LOG(ERR, "can't allocate id pool");
334 mem = rte_zmalloc("", MLX5_FLOW_MIN_ID_POOL_SIZE * sizeof(uint32_t),
335 RTE_CACHE_LINE_SIZE);
337 DRV_LOG(ERR, "can't allocate mem for id pool");
341 pool->free_arr = mem;
342 pool->curr = pool->free_arr;
343 pool->last = pool->free_arr + MLX5_FLOW_MIN_ID_POOL_SIZE;
344 pool->base_index = 0;
345 pool->max_id = max_id;
353 * Release ID pool structure.
356 * Pointer to flow id pool object to free.
359 mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool)
361 rte_free(pool->free_arr);
369 * Pointer to flow id pool.
374 * 0 on success, error value otherwise.
377 mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id)
379 if (pool->curr == pool->free_arr) {
380 if (pool->base_index == pool->max_id) {
382 DRV_LOG(ERR, "no free id");
385 *id = ++pool->base_index;
388 *id = *(--pool->curr);
396 * Pointer to flow id pool.
401 * 0 on success, error value otherwise.
404 mlx5_flow_id_release(struct mlx5_flow_id_pool *pool, uint32_t id)
410 if (pool->curr == pool->last) {
411 size = pool->curr - pool->free_arr;
412 size2 = size * MLX5_ID_GENERATION_ARRAY_FACTOR;
413 MLX5_ASSERT(size2 > size);
414 mem = rte_malloc("", size2 * sizeof(uint32_t), 0);
416 DRV_LOG(ERR, "can't allocate mem for id pool");
420 memcpy(mem, pool->free_arr, size * sizeof(uint32_t));
421 rte_free(pool->free_arr);
422 pool->free_arr = mem;
423 pool->curr = pool->free_arr + size;
424 pool->last = pool->free_arr + size2;
432 * Initialize the counters management structure.
435 * Pointer to mlx5_ibv_shared object to free
438 mlx5_flow_counters_mng_init(struct mlx5_ibv_shared *sh)
442 TAILQ_INIT(&sh->cmng.flow_counters);
443 for (i = 0; i < RTE_DIM(sh->cmng.ccont); ++i)
444 TAILQ_INIT(&sh->cmng.ccont[i].pool_list);
448 * Destroy all the resources allocated for a counter memory management.
451 * Pointer to the memory management structure.
454 mlx5_flow_destroy_counter_stat_mem_mng(struct mlx5_counter_stats_mem_mng *mng)
456 uint8_t *mem = (uint8_t *)(uintptr_t)mng->raws[0].data;
458 LIST_REMOVE(mng, next);
459 claim_zero(mlx5_devx_cmd_destroy(mng->dm));
460 claim_zero(mlx5_glue->devx_umem_dereg(mng->umem));
465 * Close and release all the resources of the counters management.
468 * Pointer to mlx5_ibv_shared object to free.
471 mlx5_flow_counters_mng_close(struct mlx5_ibv_shared *sh)
473 struct mlx5_counter_stats_mem_mng *mng;
480 rte_eal_alarm_cancel(mlx5_flow_query_alarm, sh);
481 if (rte_errno != EINPROGRESS)
485 for (i = 0; i < RTE_DIM(sh->cmng.ccont); ++i) {
486 struct mlx5_flow_counter_pool *pool;
487 uint32_t batch = !!(i % 2);
489 if (!sh->cmng.ccont[i].pools)
491 pool = TAILQ_FIRST(&sh->cmng.ccont[i].pool_list);
496 (mlx5_devx_cmd_destroy(pool->min_dcs));
498 for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j) {
499 if (pool->counters_raw[j].action)
501 (mlx5_glue->destroy_flow_action
502 (pool->counters_raw[j].action));
503 if (!batch && MLX5_GET_POOL_CNT_EXT
505 claim_zero(mlx5_devx_cmd_destroy
506 (MLX5_GET_POOL_CNT_EXT
509 TAILQ_REMOVE(&sh->cmng.ccont[i].pool_list, pool,
512 pool = TAILQ_FIRST(&sh->cmng.ccont[i].pool_list);
514 rte_free(sh->cmng.ccont[i].pools);
516 mng = LIST_FIRST(&sh->cmng.mem_mngs);
518 mlx5_flow_destroy_counter_stat_mem_mng(mng);
519 mng = LIST_FIRST(&sh->cmng.mem_mngs);
521 memset(&sh->cmng, 0, sizeof(sh->cmng));
525 * Initialize the flow resources' indexed mempool.
528 * Pointer to mlx5_ibv_shared object.
530 * Pointer to user dev config.
533 mlx5_flow_ipool_create(struct mlx5_ibv_shared *sh,
534 const struct mlx5_dev_config *config __rte_unused)
538 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
540 * While DV is supported, user chooses the verbs mode,
541 * the mlx5 flow handle size is different with the
542 * MLX5_FLOW_HANDLE_VERBS_SIZE.
544 if (!config->dv_flow_en)
545 mlx5_ipool_cfg[MLX5_IPOOL_MLX5_FLOW].size =
546 MLX5_FLOW_HANDLE_VERBS_SIZE;
548 for (i = 0; i < MLX5_IPOOL_MAX; ++i)
549 sh->ipool[i] = mlx5_ipool_create(&mlx5_ipool_cfg[i]);
553 * Release the flow resources' indexed mempool.
556 * Pointer to mlx5_ibv_shared object.
559 mlx5_flow_ipool_destroy(struct mlx5_ibv_shared *sh)
563 for (i = 0; i < MLX5_IPOOL_MAX; ++i)
564 mlx5_ipool_destroy(sh->ipool[i]);
568 * Extract pdn of PD object using DV API.
571 * Pointer to the verbs PD object.
573 * Pointer to the PD object number variable.
576 * 0 on success, error value otherwise.
578 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
580 mlx5_get_pdn(struct ibv_pd *pd __rte_unused, uint32_t *pdn __rte_unused)
582 struct mlx5dv_obj obj;
583 struct mlx5dv_pd pd_info;
587 obj.pd.out = &pd_info;
588 ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD);
590 DRV_LOG(DEBUG, "Fail to get PD object info");
596 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
599 mlx5_config_doorbell_mapping_env(const struct mlx5_dev_config *config)
604 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
605 /* Get environment variable to store. */
606 env = getenv(MLX5_SHUT_UP_BF);
607 value = env ? !!strcmp(env, "0") : MLX5_ARG_UNSET;
608 if (config->dbnc == MLX5_ARG_UNSET)
609 setenv(MLX5_SHUT_UP_BF, MLX5_SHUT_UP_BF_DEFAULT, 1);
611 setenv(MLX5_SHUT_UP_BF,
612 config->dbnc == MLX5_TXDB_NCACHED ? "1" : "0", 1);
617 mlx5_restore_doorbell_mapping_env(int value)
619 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
620 /* Restore the original environment variable state. */
621 if (value == MLX5_ARG_UNSET)
622 unsetenv(MLX5_SHUT_UP_BF);
624 setenv(MLX5_SHUT_UP_BF, value ? "1" : "0", 1);
628 * Allocate shared IB device context. If there is multiport device the
629 * master and representors will share this context, if there is single
630 * port dedicated IB device, the context will be used by only given
631 * port due to unification.
633 * Routine first searches the context for the specified IB device name,
634 * if found the shared context assumed and reference counter is incremented.
635 * If no context found the new one is created and initialized with specified
636 * IB device context and parameters.
639 * Pointer to the IB device attributes (name, port, etc).
641 * Pointer to device configuration structure.
644 * Pointer to mlx5_ibv_shared object on success,
645 * otherwise NULL and rte_errno is set.
647 static struct mlx5_ibv_shared *
648 mlx5_alloc_shared_ibctx(const struct mlx5_dev_spawn_data *spawn,
649 const struct mlx5_dev_config *config)
651 struct mlx5_ibv_shared *sh;
655 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
656 struct mlx5_devx_tis_attr tis_attr = { 0 };
660 /* Secondary process should not create the shared context. */
661 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
662 pthread_mutex_lock(&mlx5_ibv_list_mutex);
663 /* Search for IB context by device name. */
664 LIST_FOREACH(sh, &mlx5_ibv_list, next) {
665 if (!strcmp(sh->ibdev_name, spawn->ibv_dev->name)) {
670 /* No device found, we have to create new shared context. */
671 MLX5_ASSERT(spawn->max_port);
672 sh = rte_zmalloc("ethdev shared ib context",
673 sizeof(struct mlx5_ibv_shared) +
675 sizeof(struct mlx5_ibv_shared_port),
676 RTE_CACHE_LINE_SIZE);
678 DRV_LOG(ERR, "shared context allocation failure");
683 * Configure environment variable "MLX5_BF_SHUT_UP"
684 * before the device creation. The rdma_core library
685 * checks the variable at device creation and
686 * stores the result internally.
688 dbmap_env = mlx5_config_doorbell_mapping_env(config);
689 /* Try to open IB device with DV first, then usual Verbs. */
691 sh->ctx = mlx5_glue->dv_open_device(spawn->ibv_dev);
694 DRV_LOG(DEBUG, "DevX is supported");
695 /* The device is created, no need for environment. */
696 mlx5_restore_doorbell_mapping_env(dbmap_env);
698 /* The environment variable is still configured. */
699 sh->ctx = mlx5_glue->open_device(spawn->ibv_dev);
700 err = errno ? errno : ENODEV;
702 * The environment variable is not needed anymore,
703 * all device creation attempts are completed.
705 mlx5_restore_doorbell_mapping_env(dbmap_env);
708 DRV_LOG(DEBUG, "DevX is NOT supported");
710 err = mlx5_glue->query_device_ex(sh->ctx, NULL, &sh->device_attr);
712 DRV_LOG(DEBUG, "ibv_query_device_ex() failed");
716 sh->max_port = spawn->max_port;
717 strncpy(sh->ibdev_name, sh->ctx->device->name,
718 sizeof(sh->ibdev_name));
719 strncpy(sh->ibdev_path, sh->ctx->device->ibdev_path,
720 sizeof(sh->ibdev_path));
721 pthread_mutex_init(&sh->intr_mutex, NULL);
723 * Setting port_id to max unallowed value means
724 * there is no interrupt subhandler installed for
725 * the given port index i.
727 for (i = 0; i < sh->max_port; i++) {
728 sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
729 sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS;
731 sh->pd = mlx5_glue->alloc_pd(sh->ctx);
732 if (sh->pd == NULL) {
733 DRV_LOG(ERR, "PD allocation failure");
737 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
739 err = mlx5_get_pdn(sh->pd, &sh->pdn);
741 DRV_LOG(ERR, "Fail to extract pdn from PD");
744 sh->td = mlx5_devx_cmd_create_td(sh->ctx);
746 DRV_LOG(ERR, "TD allocation failure");
750 tis_attr.transport_domain = sh->td->id;
751 sh->tis = mlx5_devx_cmd_create_tis(sh->ctx, &tis_attr);
753 DRV_LOG(ERR, "TIS allocation failure");
758 sh->flow_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX);
759 if (!sh->flow_id_pool) {
760 DRV_LOG(ERR, "can't create flow id pool");
764 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
766 * Once the device is added to the list of memory event
767 * callback, its global MR cache table cannot be expanded
768 * on the fly because of deadlock. If it overflows, lookup
769 * should be done by searching MR list linearly, which is slow.
771 * At this point the device is not added to the memory
772 * event list yet, context is just being created.
774 err = mlx5_mr_btree_init(&sh->share_cache.cache,
775 MLX5_MR_BTREE_CACHE_N * 2,
776 spawn->pci_dev->device.numa_node);
781 mlx5_flow_counters_mng_init(sh);
782 mlx5_flow_ipool_create(sh, config);
783 /* Add device to memory callback list. */
784 rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);
785 LIST_INSERT_HEAD(&mlx5_shared_data->mem_event_cb_list,
787 rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock);
788 /* Add context to the global device list. */
789 LIST_INSERT_HEAD(&mlx5_ibv_list, sh, next);
791 pthread_mutex_unlock(&mlx5_ibv_list_mutex);
794 pthread_mutex_unlock(&mlx5_ibv_list_mutex);
797 claim_zero(mlx5_devx_cmd_destroy(sh->tis));
799 claim_zero(mlx5_devx_cmd_destroy(sh->td));
801 claim_zero(mlx5_glue->dealloc_pd(sh->pd));
803 claim_zero(mlx5_glue->close_device(sh->ctx));
804 if (sh->flow_id_pool)
805 mlx5_flow_id_pool_release(sh->flow_id_pool);
807 MLX5_ASSERT(err > 0);
813 * Free shared IB device context. Decrement counter and if zero free
814 * all allocated resources and close handles.
817 * Pointer to mlx5_ibv_shared object to free
820 mlx5_free_shared_ibctx(struct mlx5_ibv_shared *sh)
822 pthread_mutex_lock(&mlx5_ibv_list_mutex);
823 #ifdef RTE_LIBRTE_MLX5_DEBUG
824 /* Check the object presence in the list. */
825 struct mlx5_ibv_shared *lctx;
827 LIST_FOREACH(lctx, &mlx5_ibv_list, next)
832 DRV_LOG(ERR, "Freeing non-existing shared IB context");
837 MLX5_ASSERT(sh->refcnt);
838 /* Secondary process should not free the shared context. */
839 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
842 /* Remove from memory callback device list. */
843 rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);
844 LIST_REMOVE(sh, mem_event_cb);
845 rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock);
846 /* Release created Memory Regions. */
847 mlx5_mr_release_cache(&sh->share_cache);
848 /* Remove context from the global device list. */
849 LIST_REMOVE(sh, next);
851 * Ensure there is no async event handler installed.
852 * Only primary process handles async device events.
854 mlx5_flow_counters_mng_close(sh);
855 mlx5_flow_ipool_destroy(sh);
856 MLX5_ASSERT(!sh->intr_cnt);
858 mlx5_intr_callback_unregister
859 (&sh->intr_handle, mlx5_dev_interrupt_handler, sh);
860 #ifdef HAVE_MLX5_DEVX_ASYNC_SUPPORT
861 if (sh->devx_intr_cnt) {
862 if (sh->intr_handle_devx.fd)
863 rte_intr_callback_unregister(&sh->intr_handle_devx,
864 mlx5_dev_interrupt_handler_devx, sh);
866 mlx5dv_devx_destroy_cmd_comp(sh->devx_comp);
869 pthread_mutex_destroy(&sh->intr_mutex);
871 claim_zero(mlx5_glue->dealloc_pd(sh->pd));
873 claim_zero(mlx5_devx_cmd_destroy(sh->tis));
875 claim_zero(mlx5_devx_cmd_destroy(sh->td));
877 claim_zero(mlx5_glue->close_device(sh->ctx));
878 if (sh->flow_id_pool)
879 mlx5_flow_id_pool_release(sh->flow_id_pool);
882 pthread_mutex_unlock(&mlx5_ibv_list_mutex);
886 * Destroy table hash list and all the root entries per domain.
889 * Pointer to the private device data structure.
892 mlx5_free_table_hash_list(struct mlx5_priv *priv)
894 struct mlx5_ibv_shared *sh = priv->sh;
895 struct mlx5_flow_tbl_data_entry *tbl_data;
896 union mlx5_flow_tbl_key table_key = {
904 struct mlx5_hlist_entry *pos;
908 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
910 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
912 MLX5_ASSERT(tbl_data);
913 mlx5_hlist_remove(sh->flow_tbls, pos);
916 table_key.direction = 1;
917 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
919 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
921 MLX5_ASSERT(tbl_data);
922 mlx5_hlist_remove(sh->flow_tbls, pos);
925 table_key.direction = 0;
926 table_key.domain = 1;
927 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
929 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
931 MLX5_ASSERT(tbl_data);
932 mlx5_hlist_remove(sh->flow_tbls, pos);
935 mlx5_hlist_destroy(sh->flow_tbls, NULL, NULL);
939 * Initialize flow table hash list and create the root tables entry
943 * Pointer to the private device data structure.
946 * Zero on success, positive error code otherwise.
949 mlx5_alloc_table_hash_list(struct mlx5_priv *priv)
951 struct mlx5_ibv_shared *sh = priv->sh;
952 char s[MLX5_HLIST_NAMESIZE];
956 snprintf(s, sizeof(s), "%s_flow_table", priv->sh->ibdev_name);
957 sh->flow_tbls = mlx5_hlist_create(s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE);
958 if (!sh->flow_tbls) {
959 DRV_LOG(ERR, "flow tables with hash creation failed.\n");
963 #ifndef HAVE_MLX5DV_DR
965 * In case we have not DR support, the zero tables should be created
966 * because DV expect to see them even if they cannot be created by
969 union mlx5_flow_tbl_key table_key = {
977 struct mlx5_flow_tbl_data_entry *tbl_data = rte_zmalloc(NULL,
978 sizeof(*tbl_data), 0);
984 tbl_data->entry.key = table_key.v64;
985 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
988 rte_atomic32_init(&tbl_data->tbl.refcnt);
989 rte_atomic32_inc(&tbl_data->tbl.refcnt);
990 table_key.direction = 1;
991 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
996 tbl_data->entry.key = table_key.v64;
997 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
1000 rte_atomic32_init(&tbl_data->tbl.refcnt);
1001 rte_atomic32_inc(&tbl_data->tbl.refcnt);
1002 table_key.direction = 0;
1003 table_key.domain = 1;
1004 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
1009 tbl_data->entry.key = table_key.v64;
1010 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
1013 rte_atomic32_init(&tbl_data->tbl.refcnt);
1014 rte_atomic32_inc(&tbl_data->tbl.refcnt);
1017 mlx5_free_table_hash_list(priv);
1018 #endif /* HAVE_MLX5DV_DR */
1023 * Initialize DR related data within private structure.
1024 * Routine checks the reference counter and does actual
1025 * resources creation/initialization only if counter is zero.
1028 * Pointer to the private device data structure.
1031 * Zero on success, positive error code otherwise.
1034 mlx5_alloc_shared_dr(struct mlx5_priv *priv)
1036 struct mlx5_ibv_shared *sh = priv->sh;
1037 char s[MLX5_HLIST_NAMESIZE];
1041 err = mlx5_alloc_table_hash_list(priv);
1043 DRV_LOG(DEBUG, "sh->flow_tbls[%p] already created, reuse\n",
1044 (void *)sh->flow_tbls);
1047 /* Create tags hash list table. */
1048 snprintf(s, sizeof(s), "%s_tags", sh->ibdev_name);
1049 sh->tag_table = mlx5_hlist_create(s, MLX5_TAGS_HLIST_ARRAY_SIZE);
1050 if (!sh->tag_table) {
1051 DRV_LOG(ERR, "tags with hash creation failed.\n");
1055 #ifdef HAVE_MLX5DV_DR
1058 if (sh->dv_refcnt) {
1059 /* Shared DV/DR structures is already initialized. */
1061 priv->dr_shared = 1;
1064 /* Reference counter is zero, we should initialize structures. */
1065 domain = mlx5_glue->dr_create_domain(sh->ctx,
1066 MLX5DV_DR_DOMAIN_TYPE_NIC_RX);
1068 DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed");
1072 sh->rx_domain = domain;
1073 domain = mlx5_glue->dr_create_domain(sh->ctx,
1074 MLX5DV_DR_DOMAIN_TYPE_NIC_TX);
1076 DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed");
1080 pthread_mutex_init(&sh->dv_mutex, NULL);
1081 sh->tx_domain = domain;
1082 #ifdef HAVE_MLX5DV_DR_ESWITCH
1083 if (priv->config.dv_esw_en) {
1084 domain = mlx5_glue->dr_create_domain
1085 (sh->ctx, MLX5DV_DR_DOMAIN_TYPE_FDB);
1087 DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed");
1091 sh->fdb_domain = domain;
1092 sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
1095 sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
1096 #endif /* HAVE_MLX5DV_DR */
1098 priv->dr_shared = 1;
1101 /* Rollback the created objects. */
1102 if (sh->rx_domain) {
1103 mlx5_glue->dr_destroy_domain(sh->rx_domain);
1104 sh->rx_domain = NULL;
1106 if (sh->tx_domain) {
1107 mlx5_glue->dr_destroy_domain(sh->tx_domain);
1108 sh->tx_domain = NULL;
1110 if (sh->fdb_domain) {
1111 mlx5_glue->dr_destroy_domain(sh->fdb_domain);
1112 sh->fdb_domain = NULL;
1114 if (sh->esw_drop_action) {
1115 mlx5_glue->destroy_flow_action(sh->esw_drop_action);
1116 sh->esw_drop_action = NULL;
1118 if (sh->pop_vlan_action) {
1119 mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
1120 sh->pop_vlan_action = NULL;
1122 if (sh->tag_table) {
1123 /* tags should be destroyed with flow before. */
1124 mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
1125 sh->tag_table = NULL;
1127 mlx5_free_table_hash_list(priv);
1132 * Destroy DR related data within private structure.
1135 * Pointer to the private device data structure.
1138 mlx5_free_shared_dr(struct mlx5_priv *priv)
1140 struct mlx5_ibv_shared *sh;
1142 if (!priv->dr_shared)
1144 priv->dr_shared = 0;
1147 #ifdef HAVE_MLX5DV_DR
1148 MLX5_ASSERT(sh->dv_refcnt);
1149 if (sh->dv_refcnt && --sh->dv_refcnt)
1151 if (sh->rx_domain) {
1152 mlx5_glue->dr_destroy_domain(sh->rx_domain);
1153 sh->rx_domain = NULL;
1155 if (sh->tx_domain) {
1156 mlx5_glue->dr_destroy_domain(sh->tx_domain);
1157 sh->tx_domain = NULL;
1159 #ifdef HAVE_MLX5DV_DR_ESWITCH
1160 if (sh->fdb_domain) {
1161 mlx5_glue->dr_destroy_domain(sh->fdb_domain);
1162 sh->fdb_domain = NULL;
1164 if (sh->esw_drop_action) {
1165 mlx5_glue->destroy_flow_action(sh->esw_drop_action);
1166 sh->esw_drop_action = NULL;
1169 if (sh->pop_vlan_action) {
1170 mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
1171 sh->pop_vlan_action = NULL;
1173 pthread_mutex_destroy(&sh->dv_mutex);
1174 #endif /* HAVE_MLX5DV_DR */
1175 if (sh->tag_table) {
1176 /* tags should be destroyed with flow before. */
1177 mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
1178 sh->tag_table = NULL;
1180 mlx5_free_table_hash_list(priv);
1184 * Initialize shared data between primary and secondary process.
1186 * A memzone is reserved by primary process and secondary processes attach to
1190 * 0 on success, a negative errno value otherwise and rte_errno is set.
1193 mlx5_init_shared_data(void)
1195 const struct rte_memzone *mz;
1198 rte_spinlock_lock(&mlx5_shared_data_lock);
1199 if (mlx5_shared_data == NULL) {
1200 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1201 /* Allocate shared memory. */
1202 mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA,
1203 sizeof(*mlx5_shared_data),
1207 "Cannot allocate mlx5 shared data");
1211 mlx5_shared_data = mz->addr;
1212 memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data));
1213 rte_spinlock_init(&mlx5_shared_data->lock);
1215 /* Lookup allocated shared memory. */
1216 mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA);
1219 "Cannot attach mlx5 shared data");
1223 mlx5_shared_data = mz->addr;
1224 memset(&mlx5_local_data, 0, sizeof(mlx5_local_data));
1228 rte_spinlock_unlock(&mlx5_shared_data_lock);
1233 * Retrieve integer value from environment variable.
1236 * Environment variable name.
1239 * Integer value, 0 if the variable is not set.
1242 mlx5_getenv_int(const char *name)
1244 const char *val = getenv(name);
1252 * Verbs callback to allocate a memory. This function should allocate the space
1253 * according to the size provided residing inside a huge page.
1254 * Please note that all allocation must respect the alignment from libmlx5
1255 * (i.e. currently sysconf(_SC_PAGESIZE)).
1258 * The size in bytes of the memory to allocate.
1260 * A pointer to the callback data.
1263 * Allocated buffer, NULL otherwise and rte_errno is set.
1266 mlx5_alloc_verbs_buf(size_t size, void *data)
1268 struct mlx5_priv *priv = data;
1270 size_t alignment = sysconf(_SC_PAGESIZE);
1271 unsigned int socket = SOCKET_ID_ANY;
1273 if (priv->verbs_alloc_ctx.type == MLX5_VERBS_ALLOC_TYPE_TX_QUEUE) {
1274 const struct mlx5_txq_ctrl *ctrl = priv->verbs_alloc_ctx.obj;
1276 socket = ctrl->socket;
1277 } else if (priv->verbs_alloc_ctx.type ==
1278 MLX5_VERBS_ALLOC_TYPE_RX_QUEUE) {
1279 const struct mlx5_rxq_ctrl *ctrl = priv->verbs_alloc_ctx.obj;
1281 socket = ctrl->socket;
1283 MLX5_ASSERT(data != NULL);
1284 ret = rte_malloc_socket(__func__, size, alignment, socket);
1291 * Verbs callback to free a memory.
1294 * A pointer to the memory to free.
1296 * A pointer to the callback data.
1299 mlx5_free_verbs_buf(void *ptr, void *data __rte_unused)
1301 MLX5_ASSERT(data != NULL);
1306 * DPDK callback to add udp tunnel port
1309 * A pointer to eth_dev
1310 * @param[in] udp_tunnel
1311 * A pointer to udp tunnel
1314 * 0 on valid udp ports and tunnels, -ENOTSUP otherwise.
1317 mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev __rte_unused,
1318 struct rte_eth_udp_tunnel *udp_tunnel)
1320 MLX5_ASSERT(udp_tunnel != NULL);
1321 if (udp_tunnel->prot_type == RTE_TUNNEL_TYPE_VXLAN &&
1322 udp_tunnel->udp_port == 4789)
1324 if (udp_tunnel->prot_type == RTE_TUNNEL_TYPE_VXLAN_GPE &&
1325 udp_tunnel->udp_port == 4790)
1331 * Initialize process private data structure.
1334 * Pointer to Ethernet device structure.
1337 * 0 on success, a negative errno value otherwise and rte_errno is set.
1340 mlx5_proc_priv_init(struct rte_eth_dev *dev)
1342 struct mlx5_priv *priv = dev->data->dev_private;
1343 struct mlx5_proc_priv *ppriv;
1347 * UAR register table follows the process private structure. BlueFlame
1348 * registers for Tx queues are stored in the table.
1351 sizeof(struct mlx5_proc_priv) + priv->txqs_n * sizeof(void *);
1352 ppriv = rte_malloc_socket("mlx5_proc_priv", ppriv_size,
1353 RTE_CACHE_LINE_SIZE, dev->device->numa_node);
1358 ppriv->uar_table_sz = ppriv_size;
1359 dev->process_private = ppriv;
1364 * Un-initialize process private data structure.
1367 * Pointer to Ethernet device structure.
1370 mlx5_proc_priv_uninit(struct rte_eth_dev *dev)
1372 if (!dev->process_private)
1374 rte_free(dev->process_private);
1375 dev->process_private = NULL;
1379 * DPDK callback to close the device.
1381 * Destroy all queues and objects, free memory.
1384 * Pointer to Ethernet device structure.
1387 mlx5_dev_close(struct rte_eth_dev *dev)
1389 struct mlx5_priv *priv = dev->data->dev_private;
1393 DRV_LOG(DEBUG, "port %u closing device \"%s\"",
1395 ((priv->sh->ctx != NULL) ? priv->sh->ctx->device->name : ""));
1396 /* In case mlx5_dev_stop() has not been called. */
1397 mlx5_dev_interrupt_handler_uninstall(dev);
1398 mlx5_dev_interrupt_handler_devx_uninstall(dev);
1400 * If default mreg copy action is removed at the stop stage,
1401 * the search will return none and nothing will be done anymore.
1403 mlx5_flow_stop_default(dev);
1404 mlx5_traffic_disable(dev);
1406 * If all the flows are already flushed in the device stop stage,
1407 * then this will return directly without any action.
1409 mlx5_flow_list_flush(dev, &priv->flows, true);
1410 mlx5_flow_meter_flush(dev, NULL);
1411 /* Free the intermediate buffers for flow creation. */
1412 mlx5_flow_free_intermediate(dev);
1413 /* Prevent crashes when queues are still in use. */
1414 dev->rx_pkt_burst = removed_rx_burst;
1415 dev->tx_pkt_burst = removed_tx_burst;
1417 /* Disable datapath on secondary process. */
1418 mlx5_mp_req_stop_rxtx(dev);
1419 if (priv->rxqs != NULL) {
1420 /* XXX race condition if mlx5_rx_burst() is still running. */
1422 for (i = 0; (i != priv->rxqs_n); ++i)
1423 mlx5_rxq_release(dev, i);
1427 if (priv->txqs != NULL) {
1428 /* XXX race condition if mlx5_tx_burst() is still running. */
1430 for (i = 0; (i != priv->txqs_n); ++i)
1431 mlx5_txq_release(dev, i);
1435 mlx5_proc_priv_uninit(dev);
1436 if (priv->mreg_cp_tbl)
1437 mlx5_hlist_destroy(priv->mreg_cp_tbl, NULL, NULL);
1438 mlx5_mprq_free_mp(dev);
1439 mlx5_free_shared_dr(priv);
1440 if (priv->rss_conf.rss_key != NULL)
1441 rte_free(priv->rss_conf.rss_key);
1442 if (priv->reta_idx != NULL)
1443 rte_free(priv->reta_idx);
1444 if (priv->config.vf)
1445 mlx5_nl_mac_addr_flush(priv->nl_socket_route, mlx5_ifindex(dev),
1446 dev->data->mac_addrs,
1447 MLX5_MAX_MAC_ADDRESSES, priv->mac_own);
1448 if (priv->nl_socket_route >= 0)
1449 close(priv->nl_socket_route);
1450 if (priv->nl_socket_rdma >= 0)
1451 close(priv->nl_socket_rdma);
1452 if (priv->vmwa_context)
1453 mlx5_vlan_vmwa_exit(priv->vmwa_context);
1454 ret = mlx5_hrxq_verify(dev);
1456 DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
1457 dev->data->port_id);
1458 ret = mlx5_ind_table_obj_verify(dev);
1460 DRV_LOG(WARNING, "port %u some indirection table still remain",
1461 dev->data->port_id);
1462 ret = mlx5_rxq_obj_verify(dev);
1464 DRV_LOG(WARNING, "port %u some Rx queue objects still remain",
1465 dev->data->port_id);
1466 ret = mlx5_rxq_verify(dev);
1468 DRV_LOG(WARNING, "port %u some Rx queues still remain",
1469 dev->data->port_id);
1470 ret = mlx5_txq_obj_verify(dev);
1472 DRV_LOG(WARNING, "port %u some Verbs Tx queue still remain",
1473 dev->data->port_id);
1474 ret = mlx5_txq_verify(dev);
1476 DRV_LOG(WARNING, "port %u some Tx queues still remain",
1477 dev->data->port_id);
1478 ret = mlx5_flow_verify(dev);
1480 DRV_LOG(WARNING, "port %u some flows still remain",
1481 dev->data->port_id);
1484 * Free the shared context in last turn, because the cleanup
1485 * routines above may use some shared fields, like
1486 * mlx5_nl_mac_addr_flush() uses ibdev_path for retrieveing
1487 * ifindex if Netlink fails.
1489 mlx5_free_shared_ibctx(priv->sh);
1492 if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
1496 MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
1497 struct mlx5_priv *opriv =
1498 rte_eth_devices[port_id].data->dev_private;
1501 opriv->domain_id != priv->domain_id ||
1502 &rte_eth_devices[port_id] == dev)
1508 claim_zero(rte_eth_switch_domain_free(priv->domain_id));
1510 memset(priv, 0, sizeof(*priv));
1511 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
1513 * Reset mac_addrs to NULL such that it is not freed as part of
1514 * rte_eth_dev_release_port(). mac_addrs is part of dev_private so
1515 * it is freed when dev_private is freed.
1517 dev->data->mac_addrs = NULL;
1520 const struct eth_dev_ops mlx5_dev_ops = {
1521 .dev_configure = mlx5_dev_configure,
1522 .dev_start = mlx5_dev_start,
1523 .dev_stop = mlx5_dev_stop,
1524 .dev_set_link_down = mlx5_set_link_down,
1525 .dev_set_link_up = mlx5_set_link_up,
1526 .dev_close = mlx5_dev_close,
1527 .promiscuous_enable = mlx5_promiscuous_enable,
1528 .promiscuous_disable = mlx5_promiscuous_disable,
1529 .allmulticast_enable = mlx5_allmulticast_enable,
1530 .allmulticast_disable = mlx5_allmulticast_disable,
1531 .link_update = mlx5_link_update,
1532 .stats_get = mlx5_stats_get,
1533 .stats_reset = mlx5_stats_reset,
1534 .xstats_get = mlx5_xstats_get,
1535 .xstats_reset = mlx5_xstats_reset,
1536 .xstats_get_names = mlx5_xstats_get_names,
1537 .fw_version_get = mlx5_fw_version_get,
1538 .dev_infos_get = mlx5_dev_infos_get,
1539 .read_clock = mlx5_read_clock,
1540 .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
1541 .vlan_filter_set = mlx5_vlan_filter_set,
1542 .rx_queue_setup = mlx5_rx_queue_setup,
1543 .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
1544 .tx_queue_setup = mlx5_tx_queue_setup,
1545 .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
1546 .rx_queue_release = mlx5_rx_queue_release,
1547 .tx_queue_release = mlx5_tx_queue_release,
1548 .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
1549 .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
1550 .mac_addr_remove = mlx5_mac_addr_remove,
1551 .mac_addr_add = mlx5_mac_addr_add,
1552 .mac_addr_set = mlx5_mac_addr_set,
1553 .set_mc_addr_list = mlx5_set_mc_addr_list,
1554 .mtu_set = mlx5_dev_set_mtu,
1555 .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
1556 .vlan_offload_set = mlx5_vlan_offload_set,
1557 .reta_update = mlx5_dev_rss_reta_update,
1558 .reta_query = mlx5_dev_rss_reta_query,
1559 .rss_hash_update = mlx5_rss_hash_update,
1560 .rss_hash_conf_get = mlx5_rss_hash_conf_get,
1561 .filter_ctrl = mlx5_dev_filter_ctrl,
1562 .rx_descriptor_status = mlx5_rx_descriptor_status,
1563 .tx_descriptor_status = mlx5_tx_descriptor_status,
1564 .rxq_info_get = mlx5_rxq_info_get,
1565 .txq_info_get = mlx5_txq_info_get,
1566 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
1567 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
1568 .rx_queue_count = mlx5_rx_queue_count,
1569 .rx_queue_intr_enable = mlx5_rx_intr_enable,
1570 .rx_queue_intr_disable = mlx5_rx_intr_disable,
1571 .is_removed = mlx5_is_removed,
1572 .udp_tunnel_port_add = mlx5_udp_tunnel_port_add,
1573 .get_module_info = mlx5_get_module_info,
1574 .get_module_eeprom = mlx5_get_module_eeprom,
1575 .hairpin_cap_get = mlx5_hairpin_cap_get,
1576 .mtr_ops_get = mlx5_flow_meter_ops_get,
1579 /* Available operations from secondary process. */
1580 static const struct eth_dev_ops mlx5_dev_sec_ops = {
1581 .stats_get = mlx5_stats_get,
1582 .stats_reset = mlx5_stats_reset,
1583 .xstats_get = mlx5_xstats_get,
1584 .xstats_reset = mlx5_xstats_reset,
1585 .xstats_get_names = mlx5_xstats_get_names,
1586 .fw_version_get = mlx5_fw_version_get,
1587 .dev_infos_get = mlx5_dev_infos_get,
1588 .rx_descriptor_status = mlx5_rx_descriptor_status,
1589 .tx_descriptor_status = mlx5_tx_descriptor_status,
1590 .rxq_info_get = mlx5_rxq_info_get,
1591 .txq_info_get = mlx5_txq_info_get,
1592 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
1593 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
1594 .get_module_info = mlx5_get_module_info,
1595 .get_module_eeprom = mlx5_get_module_eeprom,
1598 /* Available operations in flow isolated mode. */
1599 const struct eth_dev_ops mlx5_dev_ops_isolate = {
1600 .dev_configure = mlx5_dev_configure,
1601 .dev_start = mlx5_dev_start,
1602 .dev_stop = mlx5_dev_stop,
1603 .dev_set_link_down = mlx5_set_link_down,
1604 .dev_set_link_up = mlx5_set_link_up,
1605 .dev_close = mlx5_dev_close,
1606 .promiscuous_enable = mlx5_promiscuous_enable,
1607 .promiscuous_disable = mlx5_promiscuous_disable,
1608 .allmulticast_enable = mlx5_allmulticast_enable,
1609 .allmulticast_disable = mlx5_allmulticast_disable,
1610 .link_update = mlx5_link_update,
1611 .stats_get = mlx5_stats_get,
1612 .stats_reset = mlx5_stats_reset,
1613 .xstats_get = mlx5_xstats_get,
1614 .xstats_reset = mlx5_xstats_reset,
1615 .xstats_get_names = mlx5_xstats_get_names,
1616 .fw_version_get = mlx5_fw_version_get,
1617 .dev_infos_get = mlx5_dev_infos_get,
1618 .dev_supported_ptypes_get = mlx5_dev_supported_ptypes_get,
1619 .vlan_filter_set = mlx5_vlan_filter_set,
1620 .rx_queue_setup = mlx5_rx_queue_setup,
1621 .rx_hairpin_queue_setup = mlx5_rx_hairpin_queue_setup,
1622 .tx_queue_setup = mlx5_tx_queue_setup,
1623 .tx_hairpin_queue_setup = mlx5_tx_hairpin_queue_setup,
1624 .rx_queue_release = mlx5_rx_queue_release,
1625 .tx_queue_release = mlx5_tx_queue_release,
1626 .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
1627 .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
1628 .mac_addr_remove = mlx5_mac_addr_remove,
1629 .mac_addr_add = mlx5_mac_addr_add,
1630 .mac_addr_set = mlx5_mac_addr_set,
1631 .set_mc_addr_list = mlx5_set_mc_addr_list,
1632 .mtu_set = mlx5_dev_set_mtu,
1633 .vlan_strip_queue_set = mlx5_vlan_strip_queue_set,
1634 .vlan_offload_set = mlx5_vlan_offload_set,
1635 .filter_ctrl = mlx5_dev_filter_ctrl,
1636 .rx_descriptor_status = mlx5_rx_descriptor_status,
1637 .tx_descriptor_status = mlx5_tx_descriptor_status,
1638 .rxq_info_get = mlx5_rxq_info_get,
1639 .txq_info_get = mlx5_txq_info_get,
1640 .rx_burst_mode_get = mlx5_rx_burst_mode_get,
1641 .tx_burst_mode_get = mlx5_tx_burst_mode_get,
1642 .rx_queue_intr_enable = mlx5_rx_intr_enable,
1643 .rx_queue_intr_disable = mlx5_rx_intr_disable,
1644 .is_removed = mlx5_is_removed,
1645 .get_module_info = mlx5_get_module_info,
1646 .get_module_eeprom = mlx5_get_module_eeprom,
1647 .hairpin_cap_get = mlx5_hairpin_cap_get,
1648 .mtr_ops_get = mlx5_flow_meter_ops_get,
1652 * Verify and store value for device argument.
1655 * Key argument to verify.
1657 * Value associated with key.
1662 * 0 on success, a negative errno value otherwise and rte_errno is set.
1665 mlx5_args_check(const char *key, const char *val, void *opaque)
1667 struct mlx5_dev_config *config = opaque;
1670 /* No-op, port representors are processed in mlx5_dev_spawn(). */
1671 if (!strcmp(MLX5_REPRESENTOR, key))
1674 tmp = strtoul(val, NULL, 0);
1677 DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
1680 if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
1681 config->cqe_comp = !!tmp;
1682 } else if (strcmp(MLX5_RXQ_CQE_PAD_EN, key) == 0) {
1683 config->cqe_pad = !!tmp;
1684 } else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
1685 config->hw_padding = !!tmp;
1686 } else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
1687 config->mprq.enabled = !!tmp;
1688 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_NUM, key) == 0) {
1689 config->mprq.stride_num_n = tmp;
1690 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_SIZE, key) == 0) {
1691 config->mprq.stride_size_n = tmp;
1692 } else if (strcmp(MLX5_RX_MPRQ_MAX_MEMCPY_LEN, key) == 0) {
1693 config->mprq.max_memcpy_len = tmp;
1694 } else if (strcmp(MLX5_RXQS_MIN_MPRQ, key) == 0) {
1695 config->mprq.min_rxqs_num = tmp;
1696 } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
1697 DRV_LOG(WARNING, "%s: deprecated parameter,"
1698 " converted to txq_inline_max", key);
1699 config->txq_inline_max = tmp;
1700 } else if (strcmp(MLX5_TXQ_INLINE_MAX, key) == 0) {
1701 config->txq_inline_max = tmp;
1702 } else if (strcmp(MLX5_TXQ_INLINE_MIN, key) == 0) {
1703 config->txq_inline_min = tmp;
1704 } else if (strcmp(MLX5_TXQ_INLINE_MPW, key) == 0) {
1705 config->txq_inline_mpw = tmp;
1706 } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
1707 config->txqs_inline = tmp;
1708 } else if (strcmp(MLX5_TXQS_MAX_VEC, key) == 0) {
1709 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1710 } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
1711 config->mps = !!tmp;
1712 } else if (strcmp(MLX5_TX_DB_NC, key) == 0) {
1713 if (tmp != MLX5_TXDB_CACHED &&
1714 tmp != MLX5_TXDB_NCACHED &&
1715 tmp != MLX5_TXDB_HEURISTIC) {
1716 DRV_LOG(ERR, "invalid Tx doorbell "
1717 "mapping parameter");
1722 } else if (strcmp(MLX5_TXQ_MPW_HDR_DSEG_EN, key) == 0) {
1723 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1724 } else if (strcmp(MLX5_TXQ_MAX_INLINE_LEN, key) == 0) {
1725 DRV_LOG(WARNING, "%s: deprecated parameter,"
1726 " converted to txq_inline_mpw", key);
1727 config->txq_inline_mpw = tmp;
1728 } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
1729 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1730 } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
1731 config->rx_vec_en = !!tmp;
1732 } else if (strcmp(MLX5_L3_VXLAN_EN, key) == 0) {
1733 config->l3_vxlan_en = !!tmp;
1734 } else if (strcmp(MLX5_VF_NL_EN, key) == 0) {
1735 config->vf_nl_en = !!tmp;
1736 } else if (strcmp(MLX5_DV_ESW_EN, key) == 0) {
1737 config->dv_esw_en = !!tmp;
1738 } else if (strcmp(MLX5_DV_FLOW_EN, key) == 0) {
1739 config->dv_flow_en = !!tmp;
1740 } else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
1741 if (tmp != MLX5_XMETA_MODE_LEGACY &&
1742 tmp != MLX5_XMETA_MODE_META16 &&
1743 tmp != MLX5_XMETA_MODE_META32) {
1744 DRV_LOG(ERR, "invalid extensive "
1745 "metadata parameter");
1749 config->dv_xmeta_en = tmp;
1750 } else if (strcmp(MLX5_MR_EXT_MEMSEG_EN, key) == 0) {
1751 config->mr_ext_memseg_en = !!tmp;
1752 } else if (strcmp(MLX5_MAX_DUMP_FILES_NUM, key) == 0) {
1753 config->max_dump_files_num = tmp;
1754 } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) {
1755 config->lro.timeout = tmp;
1756 } else if (strcmp(MLX5_CLASS_ARG_NAME, key) == 0) {
1757 DRV_LOG(DEBUG, "class argument is %s.", val);
1758 } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) {
1759 config->log_hp_size = tmp;
1761 DRV_LOG(WARNING, "%s: unknown parameter", key);
1769 * Parse device parameters.
1772 * Pointer to device configuration structure.
1774 * Device arguments structure.
1777 * 0 on success, a negative errno value otherwise and rte_errno is set.
1780 mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs)
1782 const char **params = (const char *[]){
1783 MLX5_RXQ_CQE_COMP_EN,
1784 MLX5_RXQ_CQE_PAD_EN,
1785 MLX5_RXQ_PKT_PAD_EN,
1787 MLX5_RX_MPRQ_LOG_STRIDE_NUM,
1788 MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
1789 MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
1792 MLX5_TXQ_INLINE_MIN,
1793 MLX5_TXQ_INLINE_MAX,
1794 MLX5_TXQ_INLINE_MPW,
1795 MLX5_TXQS_MIN_INLINE,
1798 MLX5_TXQ_MPW_HDR_DSEG_EN,
1799 MLX5_TXQ_MAX_INLINE_LEN,
1808 MLX5_MR_EXT_MEMSEG_EN,
1810 MLX5_MAX_DUMP_FILES_NUM,
1811 MLX5_LRO_TIMEOUT_USEC,
1812 MLX5_CLASS_ARG_NAME,
1816 struct rte_kvargs *kvlist;
1820 if (devargs == NULL)
1822 /* Following UGLY cast is done to pass checkpatch. */
1823 kvlist = rte_kvargs_parse(devargs->args, params);
1824 if (kvlist == NULL) {
1828 /* Process parameters. */
1829 for (i = 0; (params[i] != NULL); ++i) {
1830 if (rte_kvargs_count(kvlist, params[i])) {
1831 ret = rte_kvargs_process(kvlist, params[i],
1832 mlx5_args_check, config);
1835 rte_kvargs_free(kvlist);
1840 rte_kvargs_free(kvlist);
1844 static struct rte_pci_driver mlx5_driver;
1847 * PMD global initialization.
1849 * Independent from individual device, this function initializes global
1850 * per-PMD data structures distinguishing primary and secondary processes.
1851 * Hence, each initialization is called once per a process.
1854 * 0 on success, a negative errno value otherwise and rte_errno is set.
1857 mlx5_init_once(void)
1859 struct mlx5_shared_data *sd;
1860 struct mlx5_local_data *ld = &mlx5_local_data;
1863 if (mlx5_init_shared_data())
1865 sd = mlx5_shared_data;
1867 rte_spinlock_lock(&sd->lock);
1868 switch (rte_eal_process_type()) {
1869 case RTE_PROC_PRIMARY:
1872 LIST_INIT(&sd->mem_event_cb_list);
1873 rte_rwlock_init(&sd->mem_event_rwlock);
1874 rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
1875 mlx5_mr_mem_event_cb, NULL);
1876 ret = mlx5_mp_init_primary(MLX5_MP_NAME,
1877 mlx5_mp_primary_handle);
1880 sd->init_done = true;
1882 case RTE_PROC_SECONDARY:
1885 ret = mlx5_mp_init_secondary(MLX5_MP_NAME,
1886 mlx5_mp_secondary_handle);
1889 ++sd->secondary_cnt;
1890 ld->init_done = true;
1896 rte_spinlock_unlock(&sd->lock);
1901 * Configures the minimal amount of data to inline into WQE
1902 * while sending packets.
1904 * - the txq_inline_min has the maximal priority, if this
1905 * key is specified in devargs
1906 * - if DevX is enabled the inline mode is queried from the
1907 * device (HCA attributes and NIC vport context if needed).
1908 * - otherwise L2 mode (18 bytes) is assumed for ConnectX-4/4 Lx
1909 * and none (0 bytes) for other NICs
1912 * Verbs device parameters (name, port, switch_info) to spawn.
1914 * Device configuration parameters.
1917 mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
1918 struct mlx5_dev_config *config)
1920 if (config->txq_inline_min != MLX5_ARG_UNSET) {
1921 /* Application defines size of inlined data explicitly. */
1922 switch (spawn->pci_dev->id.device_id) {
1923 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
1924 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
1925 if (config->txq_inline_min <
1926 (int)MLX5_INLINE_HSIZE_L2) {
1928 "txq_inline_mix aligned to minimal"
1929 " ConnectX-4 required value %d",
1930 (int)MLX5_INLINE_HSIZE_L2);
1931 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1937 if (config->hca_attr.eth_net_offloads) {
1938 /* We have DevX enabled, inline mode queried successfully. */
1939 switch (config->hca_attr.wqe_inline_mode) {
1940 case MLX5_CAP_INLINE_MODE_L2:
1941 /* outer L2 header must be inlined. */
1942 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1944 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
1945 /* No inline data are required by NIC. */
1946 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
1947 config->hw_vlan_insert =
1948 config->hca_attr.wqe_vlan_insert;
1949 DRV_LOG(DEBUG, "Tx VLAN insertion is supported");
1951 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
1952 /* inline mode is defined by NIC vport context. */
1953 if (!config->hca_attr.eth_virt)
1955 switch (config->hca_attr.vport_inline_mode) {
1956 case MLX5_INLINE_MODE_NONE:
1957 config->txq_inline_min =
1958 MLX5_INLINE_HSIZE_NONE;
1960 case MLX5_INLINE_MODE_L2:
1961 config->txq_inline_min =
1962 MLX5_INLINE_HSIZE_L2;
1964 case MLX5_INLINE_MODE_IP:
1965 config->txq_inline_min =
1966 MLX5_INLINE_HSIZE_L3;
1968 case MLX5_INLINE_MODE_TCP_UDP:
1969 config->txq_inline_min =
1970 MLX5_INLINE_HSIZE_L4;
1972 case MLX5_INLINE_MODE_INNER_L2:
1973 config->txq_inline_min =
1974 MLX5_INLINE_HSIZE_INNER_L2;
1976 case MLX5_INLINE_MODE_INNER_IP:
1977 config->txq_inline_min =
1978 MLX5_INLINE_HSIZE_INNER_L3;
1980 case MLX5_INLINE_MODE_INNER_TCP_UDP:
1981 config->txq_inline_min =
1982 MLX5_INLINE_HSIZE_INNER_L4;
1988 * We get here if we are unable to deduce
1989 * inline data size with DevX. Try PCI ID
1990 * to determine old NICs.
1992 switch (spawn->pci_dev->id.device_id) {
1993 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
1994 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
1995 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LX:
1996 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
1997 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1998 config->hw_vlan_insert = 0;
2000 case PCI_DEVICE_ID_MELLANOX_CONNECTX5:
2001 case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
2002 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EX:
2003 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
2005 * These NICs support VLAN insertion from WQE and
2006 * report the wqe_vlan_insert flag. But there is the bug
2007 * and PFC control may be broken, so disable feature.
2009 config->hw_vlan_insert = 0;
2010 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2013 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
2017 DRV_LOG(DEBUG, "min tx inline configured: %d", config->txq_inline_min);
2021 * Configures the metadata mask fields in the shared context.
2024 * Pointer to Ethernet device.
2027 mlx5_set_metadata_mask(struct rte_eth_dev *dev)
2029 struct mlx5_priv *priv = dev->data->dev_private;
2030 struct mlx5_ibv_shared *sh = priv->sh;
2031 uint32_t meta, mark, reg_c0;
2033 reg_c0 = ~priv->vport_meta_mask;
2034 switch (priv->config.dv_xmeta_en) {
2035 case MLX5_XMETA_MODE_LEGACY:
2037 mark = MLX5_FLOW_MARK_MASK;
2039 case MLX5_XMETA_MODE_META16:
2040 meta = reg_c0 >> rte_bsf32(reg_c0);
2041 mark = MLX5_FLOW_MARK_MASK;
2043 case MLX5_XMETA_MODE_META32:
2045 mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
2053 if (sh->dv_mark_mask && sh->dv_mark_mask != mark)
2054 DRV_LOG(WARNING, "metadata MARK mask mismatche %08X:%08X",
2055 sh->dv_mark_mask, mark);
2057 sh->dv_mark_mask = mark;
2058 if (sh->dv_meta_mask && sh->dv_meta_mask != meta)
2059 DRV_LOG(WARNING, "metadata META mask mismatche %08X:%08X",
2060 sh->dv_meta_mask, meta);
2062 sh->dv_meta_mask = meta;
2063 if (sh->dv_regc0_mask && sh->dv_regc0_mask != reg_c0)
2064 DRV_LOG(WARNING, "metadata reg_c0 mask mismatche %08X:%08X",
2065 sh->dv_meta_mask, reg_c0);
2067 sh->dv_regc0_mask = reg_c0;
2068 DRV_LOG(DEBUG, "metadata mode %u", priv->config.dv_xmeta_en);
2069 DRV_LOG(DEBUG, "metadata MARK mask %08X", sh->dv_mark_mask);
2070 DRV_LOG(DEBUG, "metadata META mask %08X", sh->dv_meta_mask);
2071 DRV_LOG(DEBUG, "metadata reg_c0 mask %08X", sh->dv_regc0_mask);
2075 * Allocate page of door-bells and register it using DevX API.
2078 * Pointer to Ethernet device.
2081 * Pointer to new page on success, NULL otherwise.
2083 static struct mlx5_devx_dbr_page *
2084 mlx5_alloc_dbr_page(struct rte_eth_dev *dev)
2086 struct mlx5_priv *priv = dev->data->dev_private;
2087 struct mlx5_devx_dbr_page *page;
2089 /* Allocate space for door-bell page and management data. */
2090 page = rte_calloc_socket(__func__, 1, sizeof(struct mlx5_devx_dbr_page),
2091 RTE_CACHE_LINE_SIZE, dev->device->numa_node);
2093 DRV_LOG(ERR, "port %u cannot allocate dbr page",
2094 dev->data->port_id);
2097 /* Register allocated memory. */
2098 page->umem = mlx5_glue->devx_umem_reg(priv->sh->ctx, page->dbrs,
2099 MLX5_DBR_PAGE_SIZE, 0);
2101 DRV_LOG(ERR, "port %u cannot umem reg dbr page",
2102 dev->data->port_id);
2110 * Find the next available door-bell, allocate new page if needed.
2113 * Pointer to Ethernet device.
2114 * @param [out] dbr_page
2115 * Door-bell page containing the page data.
2118 * Door-bell address offset on success, a negative error value otherwise.
2121 mlx5_get_dbr(struct rte_eth_dev *dev, struct mlx5_devx_dbr_page **dbr_page)
2123 struct mlx5_priv *priv = dev->data->dev_private;
2124 struct mlx5_devx_dbr_page *page = NULL;
2127 LIST_FOREACH(page, &priv->dbrpgs, next)
2128 if (page->dbr_count < MLX5_DBR_PER_PAGE)
2130 if (!page) { /* No page with free door-bell exists. */
2131 page = mlx5_alloc_dbr_page(dev);
2132 if (!page) /* Failed to allocate new page. */
2134 LIST_INSERT_HEAD(&priv->dbrpgs, page, next);
2136 /* Loop to find bitmap part with clear bit. */
2138 i < MLX5_DBR_BITMAP_SIZE && page->dbr_bitmap[i] == UINT64_MAX;
2141 /* Find the first clear bit. */
2142 j = rte_bsf64(~page->dbr_bitmap[i]);
2143 MLX5_ASSERT(i < (MLX5_DBR_PER_PAGE / 64));
2144 page->dbr_bitmap[i] |= (1 << j);
2147 return (((i * 64) + j) * sizeof(uint64_t));
2151 * Release a door-bell record.
2154 * Pointer to Ethernet device.
2155 * @param [in] umem_id
2156 * UMEM ID of page containing the door-bell record to release.
2157 * @param [in] offset
2158 * Offset of door-bell record in page.
2161 * 0 on success, a negative error value otherwise.
2164 mlx5_release_dbr(struct rte_eth_dev *dev, uint32_t umem_id, uint64_t offset)
2166 struct mlx5_priv *priv = dev->data->dev_private;
2167 struct mlx5_devx_dbr_page *page = NULL;
2170 LIST_FOREACH(page, &priv->dbrpgs, next)
2171 /* Find the page this address belongs to. */
2172 if (page->umem->umem_id == umem_id)
2177 if (!page->dbr_count) {
2178 /* Page not used, free it and remove from list. */
2179 LIST_REMOVE(page, next);
2181 ret = -mlx5_glue->devx_umem_dereg(page->umem);
2184 /* Mark in bitmap that this door-bell is not in use. */
2185 offset /= MLX5_DBR_SIZE;
2186 int i = offset / 64;
2187 int j = offset % 64;
2189 page->dbr_bitmap[i] &= ~(1 << j);
2195 rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
2197 static const char *const dynf_names[] = {
2198 RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
2199 RTE_MBUF_DYNFLAG_METADATA_NAME
2203 if (n < RTE_DIM(dynf_names))
2205 for (i = 0; i < RTE_DIM(dynf_names); i++) {
2206 if (names[i] == NULL)
2208 strcpy(names[i], dynf_names[i]);
2210 return RTE_DIM(dynf_names);
2214 * Check sibling device configurations.
2216 * Sibling devices sharing the Infiniband device context
2217 * should have compatible configurations. This regards
2218 * representors and bonding slaves.
2221 * Private device descriptor.
2223 * Configuration of the device is going to be created.
2226 * 0 on success, EINVAL otherwise
2229 mlx5_dev_check_sibling_config(struct mlx5_priv *priv,
2230 struct mlx5_dev_config *config)
2232 struct mlx5_ibv_shared *sh = priv->sh;
2233 struct mlx5_dev_config *sh_conf = NULL;
2237 /* Nothing to compare for the single/first device. */
2238 if (sh->refcnt == 1)
2240 /* Find the device with shared context. */
2241 MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
2242 struct mlx5_priv *opriv =
2243 rte_eth_devices[port_id].data->dev_private;
2245 if (opriv && opriv != priv && opriv->sh == sh) {
2246 sh_conf = &opriv->config;
2252 if (sh_conf->dv_flow_en ^ config->dv_flow_en) {
2253 DRV_LOG(ERR, "\"dv_flow_en\" configuration mismatch"
2254 " for shared %s context", sh->ibdev_name);
2258 if (sh_conf->dv_xmeta_en ^ config->dv_xmeta_en) {
2259 DRV_LOG(ERR, "\"dv_xmeta_en\" configuration mismatch"
2260 " for shared %s context", sh->ibdev_name);
2267 * Spawn an Ethernet device from Verbs information.
2270 * Backing DPDK device.
2272 * Verbs device parameters (name, port, switch_info) to spawn.
2274 * Device configuration parameters.
2277 * A valid Ethernet device object on success, NULL otherwise and rte_errno
2278 * is set. The following errors are defined:
2280 * EBUSY: device is not supposed to be spawned.
2281 * EEXIST: device is already spawned
2283 static struct rte_eth_dev *
2284 mlx5_dev_spawn(struct rte_device *dpdk_dev,
2285 struct mlx5_dev_spawn_data *spawn,
2286 struct mlx5_dev_config config)
2288 const struct mlx5_switch_info *switch_info = &spawn->info;
2289 struct mlx5_ibv_shared *sh = NULL;
2290 struct ibv_port_attr port_attr;
2291 struct mlx5dv_context dv_attr = { .comp_mask = 0 };
2292 struct rte_eth_dev *eth_dev = NULL;
2293 struct mlx5_priv *priv = NULL;
2295 unsigned int hw_padding = 0;
2297 unsigned int cqe_comp;
2298 unsigned int cqe_pad = 0;
2299 unsigned int tunnel_en = 0;
2300 unsigned int mpls_en = 0;
2301 unsigned int swp = 0;
2302 unsigned int mprq = 0;
2303 unsigned int mprq_min_stride_size_n = 0;
2304 unsigned int mprq_max_stride_size_n = 0;
2305 unsigned int mprq_min_stride_num_n = 0;
2306 unsigned int mprq_max_stride_num_n = 0;
2307 struct rte_ether_addr mac;
2308 char name[RTE_ETH_NAME_MAX_LEN];
2309 int own_domain_id = 0;
2312 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
2313 struct mlx5dv_devx_port devx_port = { .comp_mask = 0 };
2316 /* Determine if this port representor is supposed to be spawned. */
2317 if (switch_info->representor && dpdk_dev->devargs) {
2318 struct rte_eth_devargs eth_da;
2320 err = rte_eth_devargs_parse(dpdk_dev->devargs->args, ð_da);
2323 DRV_LOG(ERR, "failed to process device arguments: %s",
2324 strerror(rte_errno));
2327 for (i = 0; i < eth_da.nb_representor_ports; ++i)
2328 if (eth_da.representor_ports[i] ==
2329 (uint16_t)switch_info->port_name)
2331 if (i == eth_da.nb_representor_ports) {
2336 /* Build device name. */
2337 if (spawn->pf_bond < 0) {
2338 /* Single device. */
2339 if (!switch_info->representor)
2340 strlcpy(name, dpdk_dev->name, sizeof(name));
2342 snprintf(name, sizeof(name), "%s_representor_%u",
2343 dpdk_dev->name, switch_info->port_name);
2345 /* Bonding device. */
2346 if (!switch_info->representor)
2347 snprintf(name, sizeof(name), "%s_%s",
2348 dpdk_dev->name, spawn->ibv_dev->name);
2350 snprintf(name, sizeof(name), "%s_%s_representor_%u",
2351 dpdk_dev->name, spawn->ibv_dev->name,
2352 switch_info->port_name);
2354 /* check if the device is already spawned */
2355 if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) {
2359 DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name);
2360 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
2361 struct mlx5_mp_id mp_id;
2363 eth_dev = rte_eth_dev_attach_secondary(name);
2364 if (eth_dev == NULL) {
2365 DRV_LOG(ERR, "can not attach rte ethdev");
2369 eth_dev->device = dpdk_dev;
2370 eth_dev->dev_ops = &mlx5_dev_sec_ops;
2371 err = mlx5_proc_priv_init(eth_dev);
2374 mp_id.port_id = eth_dev->data->port_id;
2375 strlcpy(mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
2376 /* Receive command fd from primary process */
2377 err = mlx5_mp_req_verbs_cmd_fd(&mp_id);
2380 /* Remap UAR for Tx queues. */
2381 err = mlx5_tx_uar_init_secondary(eth_dev, err);
2385 * Ethdev pointer is still required as input since
2386 * the primary device is not accessible from the
2387 * secondary process.
2389 eth_dev->rx_pkt_burst = mlx5_select_rx_function(eth_dev);
2390 eth_dev->tx_pkt_burst = mlx5_select_tx_function(eth_dev);
2394 * Some parameters ("tx_db_nc" in particularly) are needed in
2395 * advance to create dv/verbs device context. We proceed the
2396 * devargs here to get ones, and later proceed devargs again
2397 * to override some hardware settings.
2399 err = mlx5_args(&config, dpdk_dev->devargs);
2402 DRV_LOG(ERR, "failed to process device arguments: %s",
2403 strerror(rte_errno));
2406 sh = mlx5_alloc_shared_ibctx(spawn, &config);
2409 config.devx = sh->devx;
2410 #ifdef HAVE_MLX5DV_DR_ACTION_DEST_DEVX_TIR
2411 config.dest_tir = 1;
2413 #ifdef HAVE_IBV_MLX5_MOD_SWP
2414 dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_SWP;
2417 * Multi-packet send is supported by ConnectX-4 Lx PF as well
2418 * as all ConnectX-5 devices.
2420 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2421 dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS;
2423 #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
2424 dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_STRIDING_RQ;
2426 mlx5_glue->dv_query_device(sh->ctx, &dv_attr);
2427 if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED) {
2428 if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW) {
2429 DRV_LOG(DEBUG, "enhanced MPW is supported");
2430 mps = MLX5_MPW_ENHANCED;
2432 DRV_LOG(DEBUG, "MPW is supported");
2436 DRV_LOG(DEBUG, "MPW isn't supported");
2437 mps = MLX5_MPW_DISABLED;
2439 #ifdef HAVE_IBV_MLX5_MOD_SWP
2440 if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_SWP)
2441 swp = dv_attr.sw_parsing_caps.sw_parsing_offloads;
2442 DRV_LOG(DEBUG, "SWP support: %u", swp);
2445 #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
2446 if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_STRIDING_RQ) {
2447 struct mlx5dv_striding_rq_caps mprq_caps =
2448 dv_attr.striding_rq_caps;
2450 DRV_LOG(DEBUG, "\tmin_single_stride_log_num_of_bytes: %d",
2451 mprq_caps.min_single_stride_log_num_of_bytes);
2452 DRV_LOG(DEBUG, "\tmax_single_stride_log_num_of_bytes: %d",
2453 mprq_caps.max_single_stride_log_num_of_bytes);
2454 DRV_LOG(DEBUG, "\tmin_single_wqe_log_num_of_strides: %d",
2455 mprq_caps.min_single_wqe_log_num_of_strides);
2456 DRV_LOG(DEBUG, "\tmax_single_wqe_log_num_of_strides: %d",
2457 mprq_caps.max_single_wqe_log_num_of_strides);
2458 DRV_LOG(DEBUG, "\tsupported_qpts: %d",
2459 mprq_caps.supported_qpts);
2460 DRV_LOG(DEBUG, "device supports Multi-Packet RQ");
2462 mprq_min_stride_size_n =
2463 mprq_caps.min_single_stride_log_num_of_bytes;
2464 mprq_max_stride_size_n =
2465 mprq_caps.max_single_stride_log_num_of_bytes;
2466 mprq_min_stride_num_n =
2467 mprq_caps.min_single_wqe_log_num_of_strides;
2468 mprq_max_stride_num_n =
2469 mprq_caps.max_single_wqe_log_num_of_strides;
2472 if (RTE_CACHE_LINE_SIZE == 128 &&
2473 !(dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP))
2477 config.cqe_comp = cqe_comp;
2478 #ifdef HAVE_IBV_MLX5_MOD_CQE_128B_PAD
2479 /* Whether device supports 128B Rx CQE padding. */
2480 cqe_pad = RTE_CACHE_LINE_SIZE == 128 &&
2481 (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_PAD);
2483 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
2484 if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS) {
2485 tunnel_en = ((dv_attr.tunnel_offloads_caps &
2486 MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_VXLAN) &&
2487 (dv_attr.tunnel_offloads_caps &
2488 MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GRE) &&
2489 (dv_attr.tunnel_offloads_caps &
2490 MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_GENEVE));
2492 DRV_LOG(DEBUG, "tunnel offloading is %ssupported",
2493 tunnel_en ? "" : "not ");
2496 "tunnel offloading disabled due to old OFED/rdma-core version");
2498 config.tunnel_en = tunnel_en;
2499 #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
2500 mpls_en = ((dv_attr.tunnel_offloads_caps &
2501 MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_GRE) &&
2502 (dv_attr.tunnel_offloads_caps &
2503 MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_UDP));
2504 DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is %ssupported",
2505 mpls_en ? "" : "not ");
2507 DRV_LOG(WARNING, "MPLS over GRE/UDP tunnel offloading disabled due to"
2508 " old OFED/rdma-core version or firmware configuration");
2510 config.mpls_en = mpls_en;
2511 /* Check port status. */
2512 err = mlx5_glue->query_port(sh->ctx, spawn->ibv_port, &port_attr);
2514 DRV_LOG(ERR, "port query failed: %s", strerror(err));
2517 if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
2518 DRV_LOG(ERR, "port is not configured in Ethernet mode");
2522 if (port_attr.state != IBV_PORT_ACTIVE)
2523 DRV_LOG(DEBUG, "port is not active: \"%s\" (%d)",
2524 mlx5_glue->port_state_str(port_attr.state),
2526 /* Allocate private eth device data. */
2527 priv = rte_zmalloc("ethdev private structure",
2529 RTE_CACHE_LINE_SIZE);
2531 DRV_LOG(ERR, "priv allocation failure");
2536 priv->ibv_port = spawn->ibv_port;
2537 priv->pci_dev = spawn->pci_dev;
2538 priv->mtu = RTE_ETHER_MTU;
2539 priv->mp_id.port_id = port_id;
2540 strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
2542 /* Initialize UAR access locks for 32bit implementations. */
2543 rte_spinlock_init(&priv->uar_lock_cq);
2544 for (i = 0; i < MLX5_UAR_PAGE_NUM_MAX; i++)
2545 rte_spinlock_init(&priv->uar_lock[i]);
2547 /* Some internal functions rely on Netlink sockets, open them now. */
2548 priv->nl_socket_rdma = mlx5_nl_init(NETLINK_RDMA);
2549 priv->nl_socket_route = mlx5_nl_init(NETLINK_ROUTE);
2550 priv->representor = !!switch_info->representor;
2551 priv->master = !!switch_info->master;
2552 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
2553 priv->vport_meta_tag = 0;
2554 priv->vport_meta_mask = 0;
2555 priv->pf_bond = spawn->pf_bond;
2556 #ifdef HAVE_MLX5DV_DR_DEVX_PORT
2558 * The DevX port query API is implemented. E-Switch may use
2559 * either vport or reg_c[0] metadata register to match on
2560 * vport index. The engaged part of metadata register is
2563 if (switch_info->representor || switch_info->master) {
2564 devx_port.comp_mask = MLX5DV_DEVX_PORT_VPORT |
2565 MLX5DV_DEVX_PORT_MATCH_REG_C_0;
2566 err = mlx5_glue->devx_port_query(sh->ctx, spawn->ibv_port,
2570 "can't query devx port %d on device %s",
2571 spawn->ibv_port, spawn->ibv_dev->name);
2572 devx_port.comp_mask = 0;
2575 if (devx_port.comp_mask & MLX5DV_DEVX_PORT_MATCH_REG_C_0) {
2576 priv->vport_meta_tag = devx_port.reg_c_0.value;
2577 priv->vport_meta_mask = devx_port.reg_c_0.mask;
2578 if (!priv->vport_meta_mask) {
2579 DRV_LOG(ERR, "vport zero mask for port %d"
2580 " on bonding device %s",
2581 spawn->ibv_port, spawn->ibv_dev->name);
2585 if (priv->vport_meta_tag & ~priv->vport_meta_mask) {
2586 DRV_LOG(ERR, "invalid vport tag for port %d"
2587 " on bonding device %s",
2588 spawn->ibv_port, spawn->ibv_dev->name);
2593 if (devx_port.comp_mask & MLX5DV_DEVX_PORT_VPORT) {
2594 priv->vport_id = devx_port.vport_num;
2595 } else if (spawn->pf_bond >= 0) {
2596 DRV_LOG(ERR, "can't deduce vport index for port %d"
2597 " on bonding device %s",
2598 spawn->ibv_port, spawn->ibv_dev->name);
2602 /* Suppose vport index in compatible way. */
2603 priv->vport_id = switch_info->representor ?
2604 switch_info->port_name + 1 : -1;
2608 * Kernel/rdma_core support single E-Switch per PF configurations
2609 * only and vport_id field contains the vport index for
2610 * associated VF, which is deduced from representor port name.
2611 * For example, let's have the IB device port 10, it has
2612 * attached network device eth0, which has port name attribute
2613 * pf0vf2, we can deduce the VF number as 2, and set vport index
2614 * as 3 (2+1). This assigning schema should be changed if the
2615 * multiple E-Switch instances per PF configurations or/and PCI
2616 * subfunctions are added.
2618 priv->vport_id = switch_info->representor ?
2619 switch_info->port_name + 1 : -1;
2621 /* representor_id field keeps the unmodified VF index. */
2622 priv->representor_id = switch_info->representor ?
2623 switch_info->port_name : -1;
2625 * Look for sibling devices in order to reuse their switch domain
2626 * if any, otherwise allocate one.
2628 MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
2629 const struct mlx5_priv *opriv =
2630 rte_eth_devices[port_id].data->dev_private;
2633 opriv->sh != priv->sh ||
2635 RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
2637 priv->domain_id = opriv->domain_id;
2640 if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
2641 err = rte_eth_switch_domain_alloc(&priv->domain_id);
2644 DRV_LOG(ERR, "unable to allocate switch domain: %s",
2645 strerror(rte_errno));
2650 /* Override some values set by hardware configuration. */
2651 mlx5_args(&config, dpdk_dev->devargs);
2652 err = mlx5_dev_check_sibling_config(priv, &config);
2655 config.hw_csum = !!(sh->device_attr.device_cap_flags_ex &
2656 IBV_DEVICE_RAW_IP_CSUM);
2657 DRV_LOG(DEBUG, "checksum offloading is %ssupported",
2658 (config.hw_csum ? "" : "not "));
2659 #if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \
2660 !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
2661 DRV_LOG(DEBUG, "counters are not supported");
2663 #if !defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_MLX5DV_DR)
2664 if (config.dv_flow_en) {
2665 DRV_LOG(WARNING, "DV flow is not supported");
2666 config.dv_flow_en = 0;
2669 config.ind_table_max_size =
2670 sh->device_attr.rss_caps.max_rwq_indirection_table_size;
2672 * Remove this check once DPDK supports larger/variable
2673 * indirection tables.
2675 if (config.ind_table_max_size > (unsigned int)ETH_RSS_RETA_SIZE_512)
2676 config.ind_table_max_size = ETH_RSS_RETA_SIZE_512;
2677 DRV_LOG(DEBUG, "maximum Rx indirection table size is %u",
2678 config.ind_table_max_size);
2679 config.hw_vlan_strip = !!(sh->device_attr.raw_packet_caps &
2680 IBV_RAW_PACKET_CAP_CVLAN_STRIPPING);
2681 DRV_LOG(DEBUG, "VLAN stripping is %ssupported",
2682 (config.hw_vlan_strip ? "" : "not "));
2683 config.hw_fcs_strip = !!(sh->device_attr.raw_packet_caps &
2684 IBV_RAW_PACKET_CAP_SCATTER_FCS);
2685 DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported",
2686 (config.hw_fcs_strip ? "" : "not "));
2687 #if defined(HAVE_IBV_WQ_FLAG_RX_END_PADDING)
2688 hw_padding = !!sh->device_attr.rx_pad_end_addr_align;
2689 #elif defined(HAVE_IBV_WQ_FLAGS_PCI_WRITE_END_PADDING)
2690 hw_padding = !!(sh->device_attr.device_cap_flags_ex &
2691 IBV_DEVICE_PCI_WRITE_END_PADDING);
2693 if (config.hw_padding && !hw_padding) {
2694 DRV_LOG(DEBUG, "Rx end alignment padding isn't supported");
2695 config.hw_padding = 0;
2696 } else if (config.hw_padding) {
2697 DRV_LOG(DEBUG, "Rx end alignment padding is enabled");
2699 config.tso = (sh->device_attr.tso_caps.max_tso > 0 &&
2700 (sh->device_attr.tso_caps.supported_qpts &
2701 (1 << IBV_QPT_RAW_PACKET)));
2703 config.tso_max_payload_sz = sh->device_attr.tso_caps.max_tso;
2705 * MPW is disabled by default, while the Enhanced MPW is enabled
2708 if (config.mps == MLX5_ARG_UNSET)
2709 config.mps = (mps == MLX5_MPW_ENHANCED) ? MLX5_MPW_ENHANCED :
2712 config.mps = config.mps ? mps : MLX5_MPW_DISABLED;
2713 DRV_LOG(INFO, "%sMPS is %s",
2714 config.mps == MLX5_MPW_ENHANCED ? "enhanced " :
2715 config.mps == MLX5_MPW ? "legacy " : "",
2716 config.mps != MLX5_MPW_DISABLED ? "enabled" : "disabled");
2717 if (config.cqe_comp && !cqe_comp) {
2718 DRV_LOG(WARNING, "Rx CQE compression isn't supported");
2719 config.cqe_comp = 0;
2721 if (config.cqe_pad && !cqe_pad) {
2722 DRV_LOG(WARNING, "Rx CQE padding isn't supported");
2724 } else if (config.cqe_pad) {
2725 DRV_LOG(INFO, "Rx CQE padding is enabled");
2728 priv->counter_fallback = 0;
2729 err = mlx5_devx_cmd_query_hca_attr(sh->ctx, &config.hca_attr);
2734 if (!config.hca_attr.flow_counters_dump)
2735 priv->counter_fallback = 1;
2736 #ifndef HAVE_IBV_DEVX_ASYNC
2737 priv->counter_fallback = 1;
2739 if (priv->counter_fallback)
2740 DRV_LOG(INFO, "Use fall-back DV counter management");
2741 /* Check for LRO support. */
2742 if (config.dest_tir && config.hca_attr.lro_cap &&
2743 config.dv_flow_en) {
2744 /* TBD check tunnel lro caps. */
2745 config.lro.supported = config.hca_attr.lro_cap;
2746 DRV_LOG(DEBUG, "Device supports LRO");
2748 * If LRO timeout is not configured by application,
2749 * use the minimal supported value.
2751 if (!config.lro.timeout)
2752 config.lro.timeout =
2753 config.hca_attr.lro_timer_supported_periods[0];
2754 DRV_LOG(DEBUG, "LRO session timeout set to %d usec",
2755 config.lro.timeout);
2757 #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_METER)
2758 if (config.hca_attr.qos.sup && config.hca_attr.qos.srtcm_sup &&
2759 config.dv_flow_en) {
2760 uint8_t reg_c_mask =
2761 config.hca_attr.qos.flow_meter_reg_c_ids;
2763 * Meter needs two REG_C's for color match and pre-sfx
2764 * flow match. Here get the REG_C for color match.
2765 * REG_C_0 and REG_C_1 is reserved for metadata feature.
2768 if (__builtin_popcount(reg_c_mask) < 1) {
2770 DRV_LOG(WARNING, "No available register for"
2773 priv->mtr_color_reg = ffs(reg_c_mask) - 1 +
2776 priv->mtr_reg_share =
2777 config.hca_attr.qos.flow_meter_reg_share;
2778 DRV_LOG(DEBUG, "The REG_C meter uses is %d",
2779 priv->mtr_color_reg);
2784 if (config.mprq.enabled && mprq) {
2785 if (config.mprq.stride_num_n &&
2786 (config.mprq.stride_num_n > mprq_max_stride_num_n ||
2787 config.mprq.stride_num_n < mprq_min_stride_num_n)) {
2788 config.mprq.stride_num_n =
2789 RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_NUM_N,
2790 mprq_min_stride_num_n),
2791 mprq_max_stride_num_n);
2793 "the number of strides"
2794 " for Multi-Packet RQ is out of range,"
2795 " setting default value (%u)",
2796 1 << config.mprq.stride_num_n);
2798 if (config.mprq.stride_size_n &&
2799 (config.mprq.stride_size_n > mprq_max_stride_size_n ||
2800 config.mprq.stride_size_n < mprq_min_stride_size_n)) {
2801 config.mprq.stride_size_n =
2802 RTE_MIN(RTE_MAX(MLX5_MPRQ_STRIDE_SIZE_N,
2803 mprq_min_stride_size_n),
2804 mprq_max_stride_size_n);
2806 "the size of a stride"
2807 " for Multi-Packet RQ is out of range,"
2808 " setting default value (%u)",
2809 1 << config.mprq.stride_size_n);
2811 config.mprq.min_stride_size_n = mprq_min_stride_size_n;
2812 config.mprq.max_stride_size_n = mprq_max_stride_size_n;
2813 } else if (config.mprq.enabled && !mprq) {
2814 DRV_LOG(WARNING, "Multi-Packet RQ isn't supported");
2815 config.mprq.enabled = 0;
2817 if (config.max_dump_files_num == 0)
2818 config.max_dump_files_num = 128;
2819 eth_dev = rte_eth_dev_allocate(name);
2820 if (eth_dev == NULL) {
2821 DRV_LOG(ERR, "can not allocate rte ethdev");
2825 /* Flag to call rte_eth_dev_release_port() in rte_eth_dev_close(). */
2826 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
2827 if (priv->representor) {
2828 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
2829 eth_dev->data->representor_id = priv->representor_id;
2832 * Store associated network device interface index. This index
2833 * is permanent throughout the lifetime of device. So, we may store
2834 * the ifindex here and use the cached value further.
2836 MLX5_ASSERT(spawn->ifindex);
2837 priv->if_index = spawn->ifindex;
2838 eth_dev->data->dev_private = priv;
2839 priv->dev_data = eth_dev->data;
2840 eth_dev->data->mac_addrs = priv->mac;
2841 eth_dev->device = dpdk_dev;
2842 /* Configure the first MAC address by default. */
2843 if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
2845 "port %u cannot get MAC address, is mlx5_en"
2846 " loaded? (errno: %s)",
2847 eth_dev->data->port_id, strerror(rte_errno));
2852 "port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
2853 eth_dev->data->port_id,
2854 mac.addr_bytes[0], mac.addr_bytes[1],
2855 mac.addr_bytes[2], mac.addr_bytes[3],
2856 mac.addr_bytes[4], mac.addr_bytes[5]);
2857 #ifdef RTE_LIBRTE_MLX5_DEBUG
2859 char ifname[IF_NAMESIZE];
2861 if (mlx5_get_ifname(eth_dev, &ifname) == 0)
2862 DRV_LOG(DEBUG, "port %u ifname is \"%s\"",
2863 eth_dev->data->port_id, ifname);
2865 DRV_LOG(DEBUG, "port %u ifname is unknown",
2866 eth_dev->data->port_id);
2869 /* Get actual MTU if possible. */
2870 err = mlx5_get_mtu(eth_dev, &priv->mtu);
2875 DRV_LOG(DEBUG, "port %u MTU is %u", eth_dev->data->port_id,
2877 /* Initialize burst functions to prevent crashes before link-up. */
2878 eth_dev->rx_pkt_burst = removed_rx_burst;
2879 eth_dev->tx_pkt_burst = removed_tx_burst;
2880 eth_dev->dev_ops = &mlx5_dev_ops;
2881 /* Register MAC address. */
2882 claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0));
2883 if (config.vf && config.vf_nl_en)
2884 mlx5_nl_mac_addr_sync(priv->nl_socket_route,
2885 mlx5_ifindex(eth_dev),
2886 eth_dev->data->mac_addrs,
2887 MLX5_MAX_MAC_ADDRESSES);
2888 TAILQ_INIT(&priv->flows);
2889 TAILQ_INIT(&priv->ctrl_flows);
2890 TAILQ_INIT(&priv->flow_meters);
2891 TAILQ_INIT(&priv->flow_meter_profiles);
2892 /* Hint libmlx5 to use PMD allocator for data plane resources */
2893 struct mlx5dv_ctx_allocators alctr = {
2894 .alloc = &mlx5_alloc_verbs_buf,
2895 .free = &mlx5_free_verbs_buf,
2898 mlx5_glue->dv_set_context_attr(sh->ctx,
2899 MLX5DV_CTX_ATTR_BUF_ALLOCATORS,
2900 (void *)((uintptr_t)&alctr));
2901 /* Bring Ethernet device up. */
2902 DRV_LOG(DEBUG, "port %u forcing Ethernet interface up",
2903 eth_dev->data->port_id);
2904 mlx5_set_link_up(eth_dev);
2906 * Even though the interrupt handler is not installed yet,
2907 * interrupts will still trigger on the async_fd from
2908 * Verbs context returned by ibv_open_device().
2910 mlx5_link_update(eth_dev, 0);
2911 #ifdef HAVE_MLX5DV_DR_ESWITCH
2912 if (!(config.hca_attr.eswitch_manager && config.dv_flow_en &&
2913 (switch_info->representor || switch_info->master)))
2914 config.dv_esw_en = 0;
2916 config.dv_esw_en = 0;
2918 /* Detect minimal data bytes to inline. */
2919 mlx5_set_min_inline(spawn, &config);
2920 /* Store device configuration on private structure. */
2921 priv->config = config;
2922 /* Create context for virtual machine VLAN workaround. */
2923 priv->vmwa_context = mlx5_vlan_vmwa_init(eth_dev, spawn->ifindex);
2924 if (config.dv_flow_en) {
2925 err = mlx5_alloc_shared_dr(priv);
2929 * RSS id is shared with meter flow id. Meter flow id can only
2930 * use the 24 MSB of the register.
2932 priv->qrss_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX >>
2933 MLX5_MTR_COLOR_BITS);
2934 if (!priv->qrss_id_pool) {
2935 DRV_LOG(ERR, "can't create flow id pool");
2940 /* Supported Verbs flow priority number detection. */
2941 err = mlx5_flow_discover_priorities(eth_dev);
2946 priv->config.flow_prio = err;
2947 if (!priv->config.dv_esw_en &&
2948 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2949 DRV_LOG(WARNING, "metadata mode %u is not supported "
2950 "(no E-Switch)", priv->config.dv_xmeta_en);
2951 priv->config.dv_xmeta_en = MLX5_XMETA_MODE_LEGACY;
2953 mlx5_set_metadata_mask(eth_dev);
2954 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
2955 !priv->sh->dv_regc0_mask) {
2956 DRV_LOG(ERR, "metadata mode %u is not supported "
2957 "(no metadata reg_c[0] is available)",
2958 priv->config.dv_xmeta_en);
2963 * Allocate the buffer for flow creating, just once.
2964 * The allocation must be done before any flow creating.
2966 mlx5_flow_alloc_intermediate(eth_dev);
2967 /* Query availibility of metadata reg_c's. */
2968 err = mlx5_flow_discover_mreg_c(eth_dev);
2973 if (!mlx5_flow_ext_mreg_supported(eth_dev)) {
2975 "port %u extensive metadata register is not supported",
2976 eth_dev->data->port_id);
2977 if (priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
2978 DRV_LOG(ERR, "metadata mode %u is not supported "
2979 "(no metadata registers available)",
2980 priv->config.dv_xmeta_en);
2985 if (priv->config.dv_flow_en &&
2986 priv->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
2987 mlx5_flow_ext_mreg_supported(eth_dev) &&
2988 priv->sh->dv_regc0_mask) {
2989 priv->mreg_cp_tbl = mlx5_hlist_create(MLX5_FLOW_MREG_HNAME,
2990 MLX5_FLOW_MREG_HTABLE_SZ);
2991 if (!priv->mreg_cp_tbl) {
2999 if (priv->mreg_cp_tbl)
3000 mlx5_hlist_destroy(priv->mreg_cp_tbl, NULL, NULL);
3002 mlx5_free_shared_dr(priv);
3003 if (priv->nl_socket_route >= 0)
3004 close(priv->nl_socket_route);
3005 if (priv->nl_socket_rdma >= 0)
3006 close(priv->nl_socket_rdma);
3007 if (priv->vmwa_context)
3008 mlx5_vlan_vmwa_exit(priv->vmwa_context);
3009 if (priv->qrss_id_pool)
3010 mlx5_flow_id_pool_release(priv->qrss_id_pool);
3012 claim_zero(rte_eth_switch_domain_free(priv->domain_id));
3014 if (eth_dev != NULL)
3015 eth_dev->data->dev_private = NULL;
3017 if (eth_dev != NULL) {
3018 /* mac_addrs must not be freed alone because part of dev_private */
3019 eth_dev->data->mac_addrs = NULL;
3020 rte_eth_dev_release_port(eth_dev);
3023 mlx5_free_shared_ibctx(sh);
3024 MLX5_ASSERT(err > 0);
3030 * Comparison callback to sort device data.
3032 * This is meant to be used with qsort().
3035 * Pointer to pointer to first data object.
3037 * Pointer to pointer to second data object.
3040 * 0 if both objects are equal, less than 0 if the first argument is less
3041 * than the second, greater than 0 otherwise.
3044 mlx5_dev_spawn_data_cmp(const void *a, const void *b)
3046 const struct mlx5_switch_info *si_a =
3047 &((const struct mlx5_dev_spawn_data *)a)->info;
3048 const struct mlx5_switch_info *si_b =
3049 &((const struct mlx5_dev_spawn_data *)b)->info;
3052 /* Master device first. */
3053 ret = si_b->master - si_a->master;
3056 /* Then representor devices. */
3057 ret = si_b->representor - si_a->representor;
3060 /* Unidentified devices come last in no specific order. */
3061 if (!si_a->representor)
3063 /* Order representors by name. */
3064 return si_a->port_name - si_b->port_name;
3068 * Match PCI information for possible slaves of bonding device.
3070 * @param[in] ibv_dev
3071 * Pointer to Infiniband device structure.
3072 * @param[in] pci_dev
3073 * Pointer to PCI device structure to match PCI address.
3074 * @param[in] nl_rdma
3075 * Netlink RDMA group socket handle.
3078 * negative value if no bonding device found, otherwise
3079 * positive index of slave PF in bonding.
3082 mlx5_device_bond_pci_match(const struct ibv_device *ibv_dev,
3083 const struct rte_pci_device *pci_dev,
3086 char ifname[IF_NAMESIZE + 1];
3087 unsigned int ifindex;
3093 * Try to get master device name. If something goes
3094 * wrong suppose the lack of kernel support and no
3099 if (!strstr(ibv_dev->name, "bond"))
3101 np = mlx5_nl_portnum(nl_rdma, ibv_dev->name);
3105 * The Master device might not be on the predefined
3106 * port (not on port index 1, it is not garanted),
3107 * we have to scan all Infiniband device port and
3110 for (i = 1; i <= np; ++i) {
3111 /* Check whether Infiniband port is populated. */
3112 ifindex = mlx5_nl_ifindex(nl_rdma, ibv_dev->name, i);
3115 if (!if_indextoname(ifindex, ifname))
3117 /* Try to read bonding slave names from sysfs. */
3119 "/sys/class/net/%s/master/bonding/slaves", ifname);
3120 file = fopen(slaves, "r");
3126 /* Use safe format to check maximal buffer length. */
3127 MLX5_ASSERT(atol(RTE_STR(IF_NAMESIZE)) == IF_NAMESIZE);
3128 while (fscanf(file, "%" RTE_STR(IF_NAMESIZE) "s", ifname) == 1) {
3129 char tmp_str[IF_NAMESIZE + 32];
3130 struct rte_pci_addr pci_addr;
3131 struct mlx5_switch_info info;
3133 /* Process slave interface names in the loop. */
3134 snprintf(tmp_str, sizeof(tmp_str),
3135 "/sys/class/net/%s", ifname);
3136 if (mlx5_dev_to_pci_addr(tmp_str, &pci_addr)) {
3137 DRV_LOG(WARNING, "can not get PCI address"
3138 " for netdev \"%s\"", ifname);
3141 if (pci_dev->addr.domain != pci_addr.domain ||
3142 pci_dev->addr.bus != pci_addr.bus ||
3143 pci_dev->addr.devid != pci_addr.devid ||
3144 pci_dev->addr.function != pci_addr.function)
3146 /* Slave interface PCI address match found. */
3148 snprintf(tmp_str, sizeof(tmp_str),
3149 "/sys/class/net/%s/phys_port_name", ifname);
3150 file = fopen(tmp_str, "rb");
3153 info.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET;
3154 if (fscanf(file, "%32s", tmp_str) == 1)
3155 mlx5_translate_port_name(tmp_str, &info);
3156 if (info.name_type == MLX5_PHYS_PORT_NAME_TYPE_LEGACY ||
3157 info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
3158 pf = info.port_name;
3167 * DPDK callback to register a PCI device.
3169 * This function spawns Ethernet devices out of a given PCI device.
3171 * @param[in] pci_drv
3172 * PCI driver structure (mlx5_driver).
3173 * @param[in] pci_dev
3174 * PCI device information.
3177 * 0 on success, a negative errno value otherwise and rte_errno is set.
3180 mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3181 struct rte_pci_device *pci_dev)
3183 struct ibv_device **ibv_list;
3185 * Number of found IB Devices matching with requested PCI BDF.
3186 * nd != 1 means there are multiple IB devices over the same
3187 * PCI device and we have representors and master.
3189 unsigned int nd = 0;
3191 * Number of found IB device Ports. nd = 1 and np = 1..n means
3192 * we have the single multiport IB device, and there may be
3193 * representors attached to some of found ports.
3195 unsigned int np = 0;
3197 * Number of DPDK ethernet devices to Spawn - either over
3198 * multiple IB devices or multiple ports of single IB device.
3199 * Actually this is the number of iterations to spawn.
3201 unsigned int ns = 0;
3204 * < 0 - no bonding device (single one)
3205 * >= 0 - bonding device (value is slave PF index)
3208 struct mlx5_dev_spawn_data *list = NULL;
3209 struct mlx5_dev_config dev_config;
3212 if (mlx5_class_get(pci_dev->device.devargs) != MLX5_CLASS_NET) {
3213 DRV_LOG(DEBUG, "Skip probing - should be probed by other mlx5"
3217 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3218 mlx5_pmd_socket_init();
3219 ret = mlx5_init_once();
3221 DRV_LOG(ERR, "unable to init PMD global data: %s",
3222 strerror(rte_errno));
3225 MLX5_ASSERT(pci_drv == &mlx5_driver);
3227 ibv_list = mlx5_glue->get_device_list(&ret);
3229 rte_errno = errno ? errno : ENOSYS;
3230 DRV_LOG(ERR, "cannot list devices, is ib_uverbs loaded?");
3234 * First scan the list of all Infiniband devices to find
3235 * matching ones, gathering into the list.
3237 struct ibv_device *ibv_match[ret + 1];
3238 int nl_route = mlx5_nl_init(NETLINK_ROUTE);
3239 int nl_rdma = mlx5_nl_init(NETLINK_RDMA);
3243 struct rte_pci_addr pci_addr;
3245 DRV_LOG(DEBUG, "checking device \"%s\"", ibv_list[ret]->name);
3246 bd = mlx5_device_bond_pci_match
3247 (ibv_list[ret], pci_dev, nl_rdma);
3250 * Bonding device detected. Only one match is allowed,
3251 * the bonding is supported over multi-port IB device,
3252 * there should be no matches on representor PCI
3253 * functions or non VF LAG bonding devices with
3254 * specified address.
3258 "multiple PCI match on bonding device"
3259 "\"%s\" found", ibv_list[ret]->name);
3264 DRV_LOG(INFO, "PCI information matches for"
3265 " slave %d bonding device \"%s\"",
3266 bd, ibv_list[ret]->name);
3267 ibv_match[nd++] = ibv_list[ret];
3270 if (mlx5_dev_to_pci_addr
3271 (ibv_list[ret]->ibdev_path, &pci_addr))
3273 if (pci_dev->addr.domain != pci_addr.domain ||
3274 pci_dev->addr.bus != pci_addr.bus ||
3275 pci_dev->addr.devid != pci_addr.devid ||
3276 pci_dev->addr.function != pci_addr.function)
3278 DRV_LOG(INFO, "PCI information matches for device \"%s\"",
3279 ibv_list[ret]->name);
3280 ibv_match[nd++] = ibv_list[ret];
3282 ibv_match[nd] = NULL;
3284 /* No device matches, just complain and bail out. */
3286 "no Verbs device matches PCI device " PCI_PRI_FMT ","
3287 " are kernel drivers loaded?",
3288 pci_dev->addr.domain, pci_dev->addr.bus,
3289 pci_dev->addr.devid, pci_dev->addr.function);
3296 * Found single matching device may have multiple ports.
3297 * Each port may be representor, we have to check the port
3298 * number and check the representors existence.
3301 np = mlx5_nl_portnum(nl_rdma, ibv_match[0]->name);
3303 DRV_LOG(WARNING, "can not get IB device \"%s\""
3304 " ports number", ibv_match[0]->name);
3305 if (bd >= 0 && !np) {
3306 DRV_LOG(ERR, "can not get ports"
3307 " for bonding device");
3313 #ifndef HAVE_MLX5DV_DR_DEVX_PORT
3316 * This may happen if there is VF LAG kernel support and
3317 * application is compiled with older rdma_core library.
3320 "No kernel/verbs support for VF LAG bonding found.");
3321 rte_errno = ENOTSUP;
3327 * Now we can determine the maximal
3328 * amount of devices to be spawned.
3330 list = rte_zmalloc("device spawn data",
3331 sizeof(struct mlx5_dev_spawn_data) *
3333 RTE_CACHE_LINE_SIZE);
3335 DRV_LOG(ERR, "spawn data array allocation failure");
3340 if (bd >= 0 || np > 1) {
3342 * Single IB device with multiple ports found,
3343 * it may be E-Switch master device and representors.
3344 * We have to perform identification trough the ports.
3346 MLX5_ASSERT(nl_rdma >= 0);
3347 MLX5_ASSERT(ns == 0);
3348 MLX5_ASSERT(nd == 1);
3350 for (i = 1; i <= np; ++i) {
3351 list[ns].max_port = np;
3352 list[ns].ibv_port = i;
3353 list[ns].ibv_dev = ibv_match[0];
3354 list[ns].eth_dev = NULL;
3355 list[ns].pci_dev = pci_dev;
3356 list[ns].pf_bond = bd;
3357 list[ns].ifindex = mlx5_nl_ifindex
3358 (nl_rdma, list[ns].ibv_dev->name, i);
3359 if (!list[ns].ifindex) {
3361 * No network interface index found for the
3362 * specified port, it means there is no
3363 * representor on this port. It's OK,
3364 * there can be disabled ports, for example
3365 * if sriov_numvfs < sriov_totalvfs.
3371 ret = mlx5_nl_switch_info
3375 if (ret || (!list[ns].info.representor &&
3376 !list[ns].info.master)) {
3378 * We failed to recognize representors with
3379 * Netlink, let's try to perform the task
3382 ret = mlx5_sysfs_switch_info
3386 if (!ret && bd >= 0) {
3387 switch (list[ns].info.name_type) {
3388 case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
3389 if (list[ns].info.port_name == bd)
3392 case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
3393 if (list[ns].info.pf_num == bd)
3401 if (!ret && (list[ns].info.representor ^
3402 list[ns].info.master))
3407 "unable to recognize master/representors"
3408 " on the IB device with multiple ports");
3415 * The existence of several matching entries (nd > 1) means
3416 * port representors have been instantiated. No existing Verbs
3417 * call nor sysfs entries can tell them apart, this can only
3418 * be done through Netlink calls assuming kernel drivers are
3419 * recent enough to support them.
3421 * In the event of identification failure through Netlink,
3422 * try again through sysfs, then:
3424 * 1. A single IB device matches (nd == 1) with single
3425 * port (np=0/1) and is not a representor, assume
3426 * no switch support.
3428 * 2. Otherwise no safe assumptions can be made;
3429 * complain louder and bail out.
3432 for (i = 0; i != nd; ++i) {
3433 memset(&list[ns].info, 0, sizeof(list[ns].info));
3434 list[ns].max_port = 1;
3435 list[ns].ibv_port = 1;
3436 list[ns].ibv_dev = ibv_match[i];
3437 list[ns].eth_dev = NULL;
3438 list[ns].pci_dev = pci_dev;
3439 list[ns].pf_bond = -1;
3440 list[ns].ifindex = 0;
3442 list[ns].ifindex = mlx5_nl_ifindex
3443 (nl_rdma, list[ns].ibv_dev->name, 1);
3444 if (!list[ns].ifindex) {
3445 char ifname[IF_NAMESIZE];
3448 * Netlink failed, it may happen with old
3449 * ib_core kernel driver (before 4.16).
3450 * We can assume there is old driver because
3451 * here we are processing single ports IB
3452 * devices. Let's try sysfs to retrieve
3453 * the ifindex. The method works for
3454 * master device only.
3458 * Multiple devices found, assume
3459 * representors, can not distinguish
3460 * master/representor and retrieve
3461 * ifindex via sysfs.
3465 ret = mlx5_get_master_ifname
3466 (ibv_match[i]->ibdev_path, &ifname);
3469 if_nametoindex(ifname);
3470 if (!list[ns].ifindex) {
3472 * No network interface index found
3473 * for the specified device, it means
3474 * there it is neither representor
3482 ret = mlx5_nl_switch_info
3486 if (ret || (!list[ns].info.representor &&
3487 !list[ns].info.master)) {
3489 * We failed to recognize representors with
3490 * Netlink, let's try to perform the task
3493 ret = mlx5_sysfs_switch_info
3497 if (!ret && (list[ns].info.representor ^
3498 list[ns].info.master)) {
3500 } else if ((nd == 1) &&
3501 !list[ns].info.representor &&
3502 !list[ns].info.master) {
3504 * Single IB device with
3505 * one physical port and
3506 * attached network device.
3507 * May be SRIOV is not enabled
3508 * or there is no representors.
3510 DRV_LOG(INFO, "no E-Switch support detected");
3517 "unable to recognize master/representors"
3518 " on the multiple IB devices");
3526 * Sort list to probe devices in natural order for users convenience
3527 * (i.e. master first, then representors from lowest to highest ID).
3529 qsort(list, ns, sizeof(*list), mlx5_dev_spawn_data_cmp);
3530 /* Default configuration. */
3531 dev_config = (struct mlx5_dev_config){
3533 .mps = MLX5_ARG_UNSET,
3534 .dbnc = MLX5_ARG_UNSET,
3536 .txq_inline_max = MLX5_ARG_UNSET,
3537 .txq_inline_min = MLX5_ARG_UNSET,
3538 .txq_inline_mpw = MLX5_ARG_UNSET,
3539 .txqs_inline = MLX5_ARG_UNSET,
3541 .mr_ext_memseg_en = 1,
3543 .enabled = 0, /* Disabled by default. */
3546 .max_memcpy_len = MLX5_MPRQ_MEMCPY_DEFAULT_LEN,
3547 .min_rxqs_num = MLX5_MPRQ_MIN_RXQS,
3551 .log_hp_size = MLX5_ARG_UNSET,
3553 /* Device specific configuration. */
3554 switch (pci_dev->id.device_id) {
3555 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
3556 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
3557 case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
3558 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
3559 case PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF:
3560 case PCI_DEVICE_ID_MELLANOX_CONNECTX6VF:
3561 case PCI_DEVICE_ID_MELLANOX_CONNECTX6DXVF:
3567 for (i = 0; i != ns; ++i) {
3570 list[i].eth_dev = mlx5_dev_spawn(&pci_dev->device,
3573 if (!list[i].eth_dev) {
3574 if (rte_errno != EBUSY && rte_errno != EEXIST)
3576 /* Device is disabled or already spawned. Ignore it. */
3579 restore = list[i].eth_dev->data->dev_flags;
3580 rte_eth_copy_pci_info(list[i].eth_dev, pci_dev);
3581 /* Restore non-PCI flags cleared by the above call. */
3582 list[i].eth_dev->data->dev_flags |= restore;
3583 mlx5_dev_interrupt_handler_devx_install(list[i].eth_dev);
3584 rte_eth_dev_probing_finish(list[i].eth_dev);
3588 "probe of PCI device " PCI_PRI_FMT " aborted after"
3589 " encountering an error: %s",
3590 pci_dev->addr.domain, pci_dev->addr.bus,
3591 pci_dev->addr.devid, pci_dev->addr.function,
3592 strerror(rte_errno));
3596 if (!list[i].eth_dev)
3598 mlx5_dev_close(list[i].eth_dev);
3599 /* mac_addrs must not be freed because in dev_private */
3600 list[i].eth_dev->data->mac_addrs = NULL;
3601 claim_zero(rte_eth_dev_release_port(list[i].eth_dev));
3603 /* Restore original error. */
3610 * Do the routine cleanup:
3611 * - close opened Netlink sockets
3612 * - free allocated spawn data array
3613 * - free the Infiniband device list
3621 MLX5_ASSERT(ibv_list);
3622 mlx5_glue->free_device_list(ibv_list);
3627 * Look for the ethernet device belonging to mlx5 driver.
3629 * @param[in] port_id
3630 * port_id to start looking for device.
3631 * @param[in] pci_dev
3632 * Pointer to the hint PCI device. When device is being probed
3633 * the its siblings (master and preceding representors might
3634 * not have assigned driver yet (because the mlx5_pci_probe()
3635 * is not completed yet, for this case match on hint PCI
3636 * device may be used to detect sibling device.
3639 * port_id of found device, RTE_MAX_ETHPORT if not found.
3642 mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev)
3644 while (port_id < RTE_MAX_ETHPORTS) {
3645 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
3647 if (dev->state != RTE_ETH_DEV_UNUSED &&
3649 (dev->device == &pci_dev->device ||
3650 (dev->device->driver &&
3651 dev->device->driver->name &&
3652 !strcmp(dev->device->driver->name, MLX5_DRIVER_NAME))))
3656 if (port_id >= RTE_MAX_ETHPORTS)
3657 return RTE_MAX_ETHPORTS;
3662 * DPDK callback to remove a PCI device.
3664 * This function removes all Ethernet devices belong to a given PCI device.
3666 * @param[in] pci_dev
3667 * Pointer to the PCI device.
3670 * 0 on success, the function cannot fail.
3673 mlx5_pci_remove(struct rte_pci_device *pci_dev)
3677 RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
3678 rte_eth_dev_close(port_id);
3682 static const struct rte_pci_id mlx5_pci_id_map[] = {
3684 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3685 PCI_DEVICE_ID_MELLANOX_CONNECTX4)
3688 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3689 PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
3692 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3693 PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
3696 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3697 PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
3700 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3701 PCI_DEVICE_ID_MELLANOX_CONNECTX5)
3704 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3705 PCI_DEVICE_ID_MELLANOX_CONNECTX5VF)
3708 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3709 PCI_DEVICE_ID_MELLANOX_CONNECTX5EX)
3712 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3713 PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)
3716 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3717 PCI_DEVICE_ID_MELLANOX_CONNECTX5BF)
3720 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3721 PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF)
3724 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3725 PCI_DEVICE_ID_MELLANOX_CONNECTX6)
3728 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3729 PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
3732 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3733 PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
3736 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3737 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXVF)
3740 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
3741 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
3748 static struct rte_pci_driver mlx5_driver = {
3750 .name = MLX5_DRIVER_NAME
3752 .id_table = mlx5_pci_id_map,
3753 .probe = mlx5_pci_probe,
3754 .remove = mlx5_pci_remove,
3755 .dma_map = mlx5_dma_map,
3756 .dma_unmap = mlx5_dma_unmap,
3757 .drv_flags = RTE_PCI_DRV_INTR_LSC | RTE_PCI_DRV_INTR_RMV |
3758 RTE_PCI_DRV_PROBE_AGAIN,
3762 * Driver initialization routine.
3764 RTE_INIT(rte_mlx5_pmd_init)
3766 /* Initialize driver log type. */
3767 mlx5_logtype = rte_log_register("pmd.net.mlx5");
3768 if (mlx5_logtype >= 0)
3769 rte_log_set_level(mlx5_logtype, RTE_LOG_NOTICE);
3771 /* Build the static tables for Verbs conversion. */
3772 mlx5_set_ptype_table();
3773 mlx5_set_cksum_table();
3774 mlx5_set_swp_types_table();
3776 rte_pci_register(&mlx5_driver);
3779 RTE_PMD_EXPORT_NAME(net_mlx5, __COUNTER__);
3780 RTE_PMD_REGISTER_PCI_TABLE(net_mlx5, mlx5_pci_id_map);
3781 RTE_PMD_REGISTER_KMOD_DEP(net_mlx5, "* ib_uverbs & mlx5_core & mlx5_ib");