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_os.h>
42 #include <mlx5_common_mp.h>
44 #include "mlx5_defs.h"
46 #include "mlx5_utils.h"
47 #include "mlx5_rxtx.h"
48 #include "mlx5_autoconf.h"
50 #include "mlx5_flow.h"
51 #include "rte_pmd_mlx5.h"
53 /* Device parameter to enable RX completion queue compression. */
54 #define MLX5_RXQ_CQE_COMP_EN "rxq_cqe_comp_en"
56 /* Device parameter to enable RX completion entry padding to 128B. */
57 #define MLX5_RXQ_CQE_PAD_EN "rxq_cqe_pad_en"
59 /* Device parameter to enable padding Rx packet to cacheline size. */
60 #define MLX5_RXQ_PKT_PAD_EN "rxq_pkt_pad_en"
62 /* Device parameter to enable Multi-Packet Rx queue. */
63 #define MLX5_RX_MPRQ_EN "mprq_en"
65 /* Device parameter to configure log 2 of the number of strides for MPRQ. */
66 #define MLX5_RX_MPRQ_LOG_STRIDE_NUM "mprq_log_stride_num"
68 /* Device parameter to configure log 2 of the stride size for MPRQ. */
69 #define MLX5_RX_MPRQ_LOG_STRIDE_SIZE "mprq_log_stride_size"
71 /* Device parameter to limit the size of memcpy'd packet for MPRQ. */
72 #define MLX5_RX_MPRQ_MAX_MEMCPY_LEN "mprq_max_memcpy_len"
74 /* Device parameter to set the minimum number of Rx queues to enable MPRQ. */
75 #define MLX5_RXQS_MIN_MPRQ "rxqs_min_mprq"
77 /* Device parameter to configure inline send. Deprecated, ignored.*/
78 #define MLX5_TXQ_INLINE "txq_inline"
80 /* Device parameter to limit packet size to inline with ordinary SEND. */
81 #define MLX5_TXQ_INLINE_MAX "txq_inline_max"
83 /* Device parameter to configure minimal data size to inline. */
84 #define MLX5_TXQ_INLINE_MIN "txq_inline_min"
86 /* Device parameter to limit packet size to inline with Enhanced MPW. */
87 #define MLX5_TXQ_INLINE_MPW "txq_inline_mpw"
90 * Device parameter to configure the number of TX queues threshold for
91 * enabling inline send.
93 #define MLX5_TXQS_MIN_INLINE "txqs_min_inline"
96 * Device parameter to configure the number of TX queues threshold for
97 * enabling vectorized Tx, deprecated, ignored (no vectorized Tx routines).
99 #define MLX5_TXQS_MAX_VEC "txqs_max_vec"
101 /* Device parameter to enable multi-packet send WQEs. */
102 #define MLX5_TXQ_MPW_EN "txq_mpw_en"
105 * Device parameter to force doorbell register mapping
106 * to non-cahed region eliminating the extra write memory barrier.
108 #define MLX5_TX_DB_NC "tx_db_nc"
111 * Device parameter to include 2 dsegs in the title WQEBB.
112 * Deprecated, ignored.
114 #define MLX5_TXQ_MPW_HDR_DSEG_EN "txq_mpw_hdr_dseg_en"
117 * Device parameter to limit the size of inlining packet.
118 * Deprecated, ignored.
120 #define MLX5_TXQ_MAX_INLINE_LEN "txq_max_inline_len"
123 * Device parameter to enable hardware Tx vector.
124 * Deprecated, ignored (no vectorized Tx routines anymore).
126 #define MLX5_TX_VEC_EN "tx_vec_en"
128 /* Device parameter to enable hardware Rx vector. */
129 #define MLX5_RX_VEC_EN "rx_vec_en"
131 /* Allow L3 VXLAN flow creation. */
132 #define MLX5_L3_VXLAN_EN "l3_vxlan_en"
134 /* Activate DV E-Switch flow steering. */
135 #define MLX5_DV_ESW_EN "dv_esw_en"
137 /* Activate DV flow steering. */
138 #define MLX5_DV_FLOW_EN "dv_flow_en"
140 /* Enable extensive flow metadata support. */
141 #define MLX5_DV_XMETA_EN "dv_xmeta_en"
143 /* Activate Netlink support in VF mode. */
144 #define MLX5_VF_NL_EN "vf_nl_en"
146 /* Enable extending memsegs when creating a MR. */
147 #define MLX5_MR_EXT_MEMSEG_EN "mr_ext_memseg_en"
149 /* Select port representors to instantiate. */
150 #define MLX5_REPRESENTOR "representor"
152 /* Device parameter to configure the maximum number of dump files per queue. */
153 #define MLX5_MAX_DUMP_FILES_NUM "max_dump_files_num"
155 /* Configure timeout of LRO session (in microseconds). */
156 #define MLX5_LRO_TIMEOUT_USEC "lro_timeout_usec"
159 * Device parameter to configure the total data buffer size for a single
160 * hairpin queue (logarithm value).
162 #define MLX5_HP_BUF_SIZE "hp_buf_log_sz"
164 /* Flow memory reclaim mode. */
165 #define MLX5_RECLAIM_MEM "reclaim_mem_mode"
167 static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data";
169 /* Shared memory between primary and secondary processes. */
170 struct mlx5_shared_data *mlx5_shared_data;
172 /* Spinlock for mlx5_shared_data allocation. */
173 static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
175 /* Process local data for secondary processes. */
176 static struct mlx5_local_data mlx5_local_data;
177 /** Driver-specific log messages type. */
180 static LIST_HEAD(, mlx5_dev_ctx_shared) mlx5_dev_ctx_list =
181 LIST_HEAD_INITIALIZER();
182 static pthread_mutex_t mlx5_dev_ctx_list_mutex = PTHREAD_MUTEX_INITIALIZER;
184 static const struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
185 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
187 .size = sizeof(struct mlx5_flow_dv_encap_decap_resource),
193 .malloc = rte_malloc_socket,
195 .type = "mlx5_encap_decap_ipool",
198 .size = sizeof(struct mlx5_flow_dv_push_vlan_action_resource),
204 .malloc = rte_malloc_socket,
206 .type = "mlx5_push_vlan_ipool",
209 .size = sizeof(struct mlx5_flow_dv_tag_resource),
215 .malloc = rte_malloc_socket,
217 .type = "mlx5_tag_ipool",
220 .size = sizeof(struct mlx5_flow_dv_port_id_action_resource),
226 .malloc = rte_malloc_socket,
228 .type = "mlx5_port_id_ipool",
231 .size = sizeof(struct mlx5_flow_tbl_data_entry),
237 .malloc = rte_malloc_socket,
239 .type = "mlx5_jump_ipool",
243 .size = sizeof(struct mlx5_flow_meter),
249 .malloc = rte_malloc_socket,
251 .type = "mlx5_meter_ipool",
254 .size = sizeof(struct mlx5_flow_mreg_copy_resource),
260 .malloc = rte_malloc_socket,
262 .type = "mlx5_mcp_ipool",
265 .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
271 .malloc = rte_malloc_socket,
273 .type = "mlx5_hrxq_ipool",
277 * MLX5_IPOOL_MLX5_FLOW size varies for DV and VERBS flows.
278 * It set in run time according to PCI function configuration.
286 .malloc = rte_malloc_socket,
288 .type = "mlx5_flow_handle_ipool",
291 .size = sizeof(struct rte_flow),
295 .malloc = rte_malloc_socket,
297 .type = "rte_flow_ipool",
302 #define MLX5_FLOW_MIN_ID_POOL_SIZE 512
303 #define MLX5_ID_GENERATION_ARRAY_FACTOR 16
305 #define MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE 4096
308 * Allocate ID pool structure.
311 * The maximum id can be allocated from the pool.
314 * Pointer to pool object, NULL value otherwise.
316 struct mlx5_flow_id_pool *
317 mlx5_flow_id_pool_alloc(uint32_t max_id)
319 struct mlx5_flow_id_pool *pool;
322 pool = rte_zmalloc("id pool allocation", sizeof(*pool),
323 RTE_CACHE_LINE_SIZE);
325 DRV_LOG(ERR, "can't allocate id pool");
329 mem = rte_zmalloc("", MLX5_FLOW_MIN_ID_POOL_SIZE * sizeof(uint32_t),
330 RTE_CACHE_LINE_SIZE);
332 DRV_LOG(ERR, "can't allocate mem for id pool");
336 pool->free_arr = mem;
337 pool->curr = pool->free_arr;
338 pool->last = pool->free_arr + MLX5_FLOW_MIN_ID_POOL_SIZE;
339 pool->base_index = 0;
340 pool->max_id = max_id;
348 * Release ID pool structure.
351 * Pointer to flow id pool object to free.
354 mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool)
356 rte_free(pool->free_arr);
364 * Pointer to flow id pool.
369 * 0 on success, error value otherwise.
372 mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id)
374 if (pool->curr == pool->free_arr) {
375 if (pool->base_index == pool->max_id) {
377 DRV_LOG(ERR, "no free id");
380 *id = ++pool->base_index;
383 *id = *(--pool->curr);
391 * Pointer to flow id pool.
396 * 0 on success, error value otherwise.
399 mlx5_flow_id_release(struct mlx5_flow_id_pool *pool, uint32_t id)
405 if (pool->curr == pool->last) {
406 size = pool->curr - pool->free_arr;
407 size2 = size * MLX5_ID_GENERATION_ARRAY_FACTOR;
408 MLX5_ASSERT(size2 > size);
409 mem = rte_malloc("", size2 * sizeof(uint32_t), 0);
411 DRV_LOG(ERR, "can't allocate mem for id pool");
415 memcpy(mem, pool->free_arr, size * sizeof(uint32_t));
416 rte_free(pool->free_arr);
417 pool->free_arr = mem;
418 pool->curr = pool->free_arr + size;
419 pool->last = pool->free_arr + size2;
427 * Initialize the shared aging list information per port.
430 * Pointer to mlx5_dev_ctx_shared object.
433 mlx5_flow_aging_init(struct mlx5_dev_ctx_shared *sh)
436 struct mlx5_age_info *age_info;
438 for (i = 0; i < sh->max_port; i++) {
439 age_info = &sh->port[i].age_info;
441 TAILQ_INIT(&age_info->aged_counters);
442 rte_spinlock_init(&age_info->aged_sl);
443 MLX5_AGE_SET(age_info, MLX5_AGE_TRIGGER);
448 * Initialize the counters management structure.
451 * Pointer to mlx5_dev_ctx_shared object to free
454 mlx5_flow_counters_mng_init(struct mlx5_dev_ctx_shared *sh)
458 memset(&sh->cmng, 0, sizeof(sh->cmng));
459 TAILQ_INIT(&sh->cmng.flow_counters);
460 for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i) {
461 sh->cmng.ccont[i].min_id = MLX5_CNT_BATCH_OFFSET;
462 sh->cmng.ccont[i].max_id = -1;
463 sh->cmng.ccont[i].last_pool_idx = POOL_IDX_INVALID;
464 TAILQ_INIT(&sh->cmng.ccont[i].pool_list);
465 rte_spinlock_init(&sh->cmng.ccont[i].resize_sl);
466 TAILQ_INIT(&sh->cmng.ccont[i].counters);
467 rte_spinlock_init(&sh->cmng.ccont[i].csl);
472 * Destroy all the resources allocated for a counter memory management.
475 * Pointer to the memory management structure.
478 mlx5_flow_destroy_counter_stat_mem_mng(struct mlx5_counter_stats_mem_mng *mng)
480 uint8_t *mem = (uint8_t *)(uintptr_t)mng->raws[0].data;
482 LIST_REMOVE(mng, next);
483 claim_zero(mlx5_devx_cmd_destroy(mng->dm));
484 claim_zero(mlx5_glue->devx_umem_dereg(mng->umem));
489 * Close and release all the resources of the counters management.
492 * Pointer to mlx5_dev_ctx_shared object to free.
495 mlx5_flow_counters_mng_close(struct mlx5_dev_ctx_shared *sh)
497 struct mlx5_counter_stats_mem_mng *mng;
504 rte_eal_alarm_cancel(mlx5_flow_query_alarm, sh);
505 if (rte_errno != EINPROGRESS)
509 for (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i) {
510 struct mlx5_flow_counter_pool *pool;
511 uint32_t batch = !!(i > 1);
513 if (!sh->cmng.ccont[i].pools)
515 pool = TAILQ_FIRST(&sh->cmng.ccont[i].pool_list);
517 if (batch && pool->min_dcs)
518 claim_zero(mlx5_devx_cmd_destroy
520 for (j = 0; j < MLX5_COUNTERS_PER_POOL; ++j) {
521 if (MLX5_POOL_GET_CNT(pool, j)->action)
523 (mlx5_glue->destroy_flow_action
526 if (!batch && MLX5_GET_POOL_CNT_EXT
528 claim_zero(mlx5_devx_cmd_destroy
529 (MLX5_GET_POOL_CNT_EXT
532 TAILQ_REMOVE(&sh->cmng.ccont[i].pool_list, pool, next);
534 pool = TAILQ_FIRST(&sh->cmng.ccont[i].pool_list);
536 rte_free(sh->cmng.ccont[i].pools);
538 mng = LIST_FIRST(&sh->cmng.mem_mngs);
540 mlx5_flow_destroy_counter_stat_mem_mng(mng);
541 mng = LIST_FIRST(&sh->cmng.mem_mngs);
543 memset(&sh->cmng, 0, sizeof(sh->cmng));
547 * Initialize the flow resources' indexed mempool.
550 * Pointer to mlx5_dev_ctx_shared object.
552 * Pointer to user dev config.
555 mlx5_flow_ipool_create(struct mlx5_dev_ctx_shared *sh,
556 const struct mlx5_dev_config *config)
559 struct mlx5_indexed_pool_config cfg;
561 for (i = 0; i < MLX5_IPOOL_MAX; ++i) {
562 cfg = mlx5_ipool_cfg[i];
567 * Set MLX5_IPOOL_MLX5_FLOW ipool size
568 * according to PCI function flow configuration.
570 case MLX5_IPOOL_MLX5_FLOW:
571 cfg.size = config->dv_flow_en ?
572 sizeof(struct mlx5_flow_handle) :
573 MLX5_FLOW_HANDLE_VERBS_SIZE;
576 if (config->reclaim_mode)
577 cfg.release_mem_en = 1;
578 sh->ipool[i] = mlx5_ipool_create(&cfg);
583 * Release the flow resources' indexed mempool.
586 * Pointer to mlx5_dev_ctx_shared object.
589 mlx5_flow_ipool_destroy(struct mlx5_dev_ctx_shared *sh)
593 for (i = 0; i < MLX5_IPOOL_MAX; ++i)
594 mlx5_ipool_destroy(sh->ipool[i]);
598 * Allocate shared device context. If there is multiport device the
599 * master and representors will share this context, if there is single
600 * port dedicated device, the context will be used by only given
601 * port due to unification.
603 * Routine first searches the context for the specified device name,
604 * if found the shared context assumed and reference counter is incremented.
605 * If no context found the new one is created and initialized with specified
606 * device context and parameters.
609 * Pointer to the device attributes (name, port, etc).
611 * Pointer to device configuration structure.
614 * Pointer to mlx5_dev_ctx_shared object on success,
615 * otherwise NULL and rte_errno is set.
617 struct mlx5_dev_ctx_shared *
618 mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn,
619 const struct mlx5_dev_config *config)
621 struct mlx5_dev_ctx_shared *sh;
624 struct mlx5_devx_tis_attr tis_attr = { 0 };
627 /* Secondary process should not create the shared context. */
628 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
629 pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
630 /* Search for IB context by device name. */
631 LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) {
632 if (!strcmp(sh->ibdev_name,
633 mlx5_os_get_dev_device_name(spawn->phys_dev))) {
638 /* No device found, we have to create new shared context. */
639 MLX5_ASSERT(spawn->max_port);
640 sh = rte_zmalloc("ethdev shared ib context",
641 sizeof(struct mlx5_dev_ctx_shared) +
643 sizeof(struct mlx5_dev_shared_port),
644 RTE_CACHE_LINE_SIZE);
646 DRV_LOG(ERR, "shared context allocation failure");
650 err = mlx5_os_open_device(spawn, config, sh);
653 err = mlx5_os_get_dev_attr(sh->ctx, &sh->device_attr);
655 DRV_LOG(DEBUG, "mlx5_os_get_dev_attr() failed");
659 sh->max_port = spawn->max_port;
660 strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->ctx),
661 sizeof(sh->ibdev_name) - 1);
662 strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->ctx),
663 sizeof(sh->ibdev_path) - 1);
665 * Setting port_id to max unallowed value means
666 * there is no interrupt subhandler installed for
667 * the given port index i.
669 for (i = 0; i < sh->max_port; i++) {
670 sh->port[i].ih_port_id = RTE_MAX_ETHPORTS;
671 sh->port[i].devx_ih_port_id = RTE_MAX_ETHPORTS;
673 sh->pd = mlx5_glue->alloc_pd(sh->ctx);
674 if (sh->pd == NULL) {
675 DRV_LOG(ERR, "PD allocation failure");
680 err = mlx5_os_get_pdn(sh->pd, &sh->pdn);
682 DRV_LOG(ERR, "Fail to extract pdn from PD");
685 sh->td = mlx5_devx_cmd_create_td(sh->ctx);
687 DRV_LOG(ERR, "TD allocation failure");
691 tis_attr.transport_domain = sh->td->id;
692 sh->tis = mlx5_devx_cmd_create_tis(sh->ctx, &tis_attr);
694 DRV_LOG(ERR, "TIS allocation failure");
699 sh->flow_id_pool = mlx5_flow_id_pool_alloc
700 ((1 << HAIRPIN_FLOW_ID_BITS) - 1);
701 if (!sh->flow_id_pool) {
702 DRV_LOG(ERR, "can't create flow id pool");
707 * Once the device is added to the list of memory event
708 * callback, its global MR cache table cannot be expanded
709 * on the fly because of deadlock. If it overflows, lookup
710 * should be done by searching MR list linearly, which is slow.
712 * At this point the device is not added to the memory
713 * event list yet, context is just being created.
715 err = mlx5_mr_btree_init(&sh->share_cache.cache,
716 MLX5_MR_BTREE_CACHE_N * 2,
717 spawn->pci_dev->device.numa_node);
722 mlx5_os_set_reg_mr_cb(&sh->share_cache.reg_mr_cb,
723 &sh->share_cache.dereg_mr_cb);
724 mlx5_os_dev_shared_handler_install(sh);
725 sh->cnt_id_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_DWORD);
726 if (!sh->cnt_id_tbl) {
730 mlx5_flow_aging_init(sh);
731 mlx5_flow_counters_mng_init(sh);
732 mlx5_flow_ipool_create(sh, config);
733 /* Add device to memory callback list. */
734 rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);
735 LIST_INSERT_HEAD(&mlx5_shared_data->mem_event_cb_list,
737 rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock);
738 /* Add context to the global device list. */
739 LIST_INSERT_HEAD(&mlx5_dev_ctx_list, sh, next);
741 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
744 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
746 if (sh->cnt_id_tbl) {
747 mlx5_l3t_destroy(sh->cnt_id_tbl);
748 sh->cnt_id_tbl = NULL;
751 claim_zero(mlx5_devx_cmd_destroy(sh->tis));
753 claim_zero(mlx5_devx_cmd_destroy(sh->td));
755 claim_zero(mlx5_glue->dealloc_pd(sh->pd));
757 claim_zero(mlx5_glue->close_device(sh->ctx));
758 if (sh->flow_id_pool)
759 mlx5_flow_id_pool_release(sh->flow_id_pool);
761 MLX5_ASSERT(err > 0);
767 * Free shared IB device context. Decrement counter and if zero free
768 * all allocated resources and close handles.
771 * Pointer to mlx5_dev_ctx_shared object to free
774 mlx5_free_shared_dev_ctx(struct mlx5_dev_ctx_shared *sh)
776 pthread_mutex_lock(&mlx5_dev_ctx_list_mutex);
777 #ifdef RTE_LIBRTE_MLX5_DEBUG
778 /* Check the object presence in the list. */
779 struct mlx5_dev_ctx_shared *lctx;
781 LIST_FOREACH(lctx, &mlx5_dev_ctx_list, next)
786 DRV_LOG(ERR, "Freeing non-existing shared IB context");
791 MLX5_ASSERT(sh->refcnt);
792 /* Secondary process should not free the shared context. */
793 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
796 /* Remove from memory callback device list. */
797 rte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);
798 LIST_REMOVE(sh, mem_event_cb);
799 rte_rwlock_write_unlock(&mlx5_shared_data->mem_event_rwlock);
800 /* Release created Memory Regions. */
801 mlx5_mr_release_cache(&sh->share_cache);
802 /* Remove context from the global device list. */
803 LIST_REMOVE(sh, next);
805 * Ensure there is no async event handler installed.
806 * Only primary process handles async device events.
808 mlx5_flow_counters_mng_close(sh);
809 mlx5_flow_ipool_destroy(sh);
810 mlx5_os_dev_shared_handler_uninstall(sh);
811 if (sh->cnt_id_tbl) {
812 mlx5_l3t_destroy(sh->cnt_id_tbl);
813 sh->cnt_id_tbl = NULL;
816 claim_zero(mlx5_glue->dealloc_pd(sh->pd));
818 claim_zero(mlx5_devx_cmd_destroy(sh->tis));
820 claim_zero(mlx5_devx_cmd_destroy(sh->td));
822 claim_zero(mlx5_glue->close_device(sh->ctx));
823 if (sh->flow_id_pool)
824 mlx5_flow_id_pool_release(sh->flow_id_pool);
827 pthread_mutex_unlock(&mlx5_dev_ctx_list_mutex);
831 * Destroy table hash list and all the root entries per domain.
834 * Pointer to the private device data structure.
837 mlx5_free_table_hash_list(struct mlx5_priv *priv)
839 struct mlx5_dev_ctx_shared *sh = priv->sh;
840 struct mlx5_flow_tbl_data_entry *tbl_data;
841 union mlx5_flow_tbl_key table_key = {
849 struct mlx5_hlist_entry *pos;
853 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
855 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
857 MLX5_ASSERT(tbl_data);
858 mlx5_hlist_remove(sh->flow_tbls, pos);
861 table_key.direction = 1;
862 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
864 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
866 MLX5_ASSERT(tbl_data);
867 mlx5_hlist_remove(sh->flow_tbls, pos);
870 table_key.direction = 0;
871 table_key.domain = 1;
872 pos = mlx5_hlist_lookup(sh->flow_tbls, table_key.v64);
874 tbl_data = container_of(pos, struct mlx5_flow_tbl_data_entry,
876 MLX5_ASSERT(tbl_data);
877 mlx5_hlist_remove(sh->flow_tbls, pos);
880 mlx5_hlist_destroy(sh->flow_tbls, NULL, NULL);
884 * Initialize flow table hash list and create the root tables entry
888 * Pointer to the private device data structure.
891 * Zero on success, positive error code otherwise.
894 mlx5_alloc_table_hash_list(struct mlx5_priv *priv)
896 struct mlx5_dev_ctx_shared *sh = priv->sh;
897 char s[MLX5_HLIST_NAMESIZE];
901 snprintf(s, sizeof(s), "%s_flow_table", priv->sh->ibdev_name);
902 sh->flow_tbls = mlx5_hlist_create(s, MLX5_FLOW_TABLE_HLIST_ARRAY_SIZE);
903 if (!sh->flow_tbls) {
904 DRV_LOG(ERR, "flow tables with hash creation failed.");
908 #ifndef HAVE_MLX5DV_DR
910 * In case we have not DR support, the zero tables should be created
911 * because DV expect to see them even if they cannot be created by
914 union mlx5_flow_tbl_key table_key = {
922 struct mlx5_flow_tbl_data_entry *tbl_data = rte_zmalloc(NULL,
923 sizeof(*tbl_data), 0);
929 tbl_data->entry.key = table_key.v64;
930 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
933 rte_atomic32_init(&tbl_data->tbl.refcnt);
934 rte_atomic32_inc(&tbl_data->tbl.refcnt);
935 table_key.direction = 1;
936 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
941 tbl_data->entry.key = table_key.v64;
942 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
945 rte_atomic32_init(&tbl_data->tbl.refcnt);
946 rte_atomic32_inc(&tbl_data->tbl.refcnt);
947 table_key.direction = 0;
948 table_key.domain = 1;
949 tbl_data = rte_zmalloc(NULL, sizeof(*tbl_data), 0);
954 tbl_data->entry.key = table_key.v64;
955 err = mlx5_hlist_insert(sh->flow_tbls, &tbl_data->entry);
958 rte_atomic32_init(&tbl_data->tbl.refcnt);
959 rte_atomic32_inc(&tbl_data->tbl.refcnt);
962 mlx5_free_table_hash_list(priv);
963 #endif /* HAVE_MLX5DV_DR */
968 * Initialize shared data between primary and secondary process.
970 * A memzone is reserved by primary process and secondary processes attach to
974 * 0 on success, a negative errno value otherwise and rte_errno is set.
977 mlx5_init_shared_data(void)
979 const struct rte_memzone *mz;
982 rte_spinlock_lock(&mlx5_shared_data_lock);
983 if (mlx5_shared_data == NULL) {
984 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
985 /* Allocate shared memory. */
986 mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA,
987 sizeof(*mlx5_shared_data),
991 "Cannot allocate mlx5 shared data");
995 mlx5_shared_data = mz->addr;
996 memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data));
997 rte_spinlock_init(&mlx5_shared_data->lock);
999 /* Lookup allocated shared memory. */
1000 mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA);
1003 "Cannot attach mlx5 shared data");
1007 mlx5_shared_data = mz->addr;
1008 memset(&mlx5_local_data, 0, sizeof(mlx5_local_data));
1012 rte_spinlock_unlock(&mlx5_shared_data_lock);
1017 * Retrieve integer value from environment variable.
1020 * Environment variable name.
1023 * Integer value, 0 if the variable is not set.
1026 mlx5_getenv_int(const char *name)
1028 const char *val = getenv(name);
1036 * DPDK callback to add udp tunnel port
1039 * A pointer to eth_dev
1040 * @param[in] udp_tunnel
1041 * A pointer to udp tunnel
1044 * 0 on valid udp ports and tunnels, -ENOTSUP otherwise.
1047 mlx5_udp_tunnel_port_add(struct rte_eth_dev *dev __rte_unused,
1048 struct rte_eth_udp_tunnel *udp_tunnel)
1050 MLX5_ASSERT(udp_tunnel != NULL);
1051 if (udp_tunnel->prot_type == RTE_TUNNEL_TYPE_VXLAN &&
1052 udp_tunnel->udp_port == 4789)
1054 if (udp_tunnel->prot_type == RTE_TUNNEL_TYPE_VXLAN_GPE &&
1055 udp_tunnel->udp_port == 4790)
1061 * Initialize process private data structure.
1064 * Pointer to Ethernet device structure.
1067 * 0 on success, a negative errno value otherwise and rte_errno is set.
1070 mlx5_proc_priv_init(struct rte_eth_dev *dev)
1072 struct mlx5_priv *priv = dev->data->dev_private;
1073 struct mlx5_proc_priv *ppriv;
1077 * UAR register table follows the process private structure. BlueFlame
1078 * registers for Tx queues are stored in the table.
1081 sizeof(struct mlx5_proc_priv) + priv->txqs_n * sizeof(void *);
1082 ppriv = rte_malloc_socket("mlx5_proc_priv", ppriv_size,
1083 RTE_CACHE_LINE_SIZE, dev->device->numa_node);
1088 ppriv->uar_table_sz = ppriv_size;
1089 dev->process_private = ppriv;
1094 * Un-initialize process private data structure.
1097 * Pointer to Ethernet device structure.
1100 mlx5_proc_priv_uninit(struct rte_eth_dev *dev)
1102 if (!dev->process_private)
1104 rte_free(dev->process_private);
1105 dev->process_private = NULL;
1109 * DPDK callback to close the device.
1111 * Destroy all queues and objects, free memory.
1114 * Pointer to Ethernet device structure.
1117 mlx5_dev_close(struct rte_eth_dev *dev)
1119 struct mlx5_priv *priv = dev->data->dev_private;
1123 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1124 /* Check if process_private released. */
1125 if (!dev->process_private)
1127 mlx5_tx_uar_uninit_secondary(dev);
1128 mlx5_proc_priv_uninit(dev);
1129 rte_eth_dev_release_port(dev);
1134 DRV_LOG(DEBUG, "port %u closing device \"%s\"",
1136 ((priv->sh->ctx != NULL) ?
1137 mlx5_os_get_ctx_device_name(priv->sh->ctx) : ""));
1139 * If default mreg copy action is removed at the stop stage,
1140 * the search will return none and nothing will be done anymore.
1142 mlx5_flow_stop_default(dev);
1143 mlx5_traffic_disable(dev);
1145 * If all the flows are already flushed in the device stop stage,
1146 * then this will return directly without any action.
1148 mlx5_flow_list_flush(dev, &priv->flows, true);
1149 mlx5_flow_meter_flush(dev, NULL);
1150 /* Free the intermediate buffers for flow creation. */
1151 mlx5_flow_free_intermediate(dev);
1152 /* Prevent crashes when queues are still in use. */
1153 dev->rx_pkt_burst = removed_rx_burst;
1154 dev->tx_pkt_burst = removed_tx_burst;
1156 /* Disable datapath on secondary process. */
1157 mlx5_mp_req_stop_rxtx(dev);
1158 if (priv->rxqs != NULL) {
1159 /* XXX race condition if mlx5_rx_burst() is still running. */
1161 for (i = 0; (i != priv->rxqs_n); ++i)
1162 mlx5_rxq_release(dev, i);
1166 if (priv->txqs != NULL) {
1167 /* XXX race condition if mlx5_tx_burst() is still running. */
1169 for (i = 0; (i != priv->txqs_n); ++i)
1170 mlx5_txq_release(dev, i);
1174 mlx5_proc_priv_uninit(dev);
1175 if (priv->mreg_cp_tbl)
1176 mlx5_hlist_destroy(priv->mreg_cp_tbl, NULL, NULL);
1177 mlx5_mprq_free_mp(dev);
1178 mlx5_os_free_shared_dr(priv);
1179 if (priv->rss_conf.rss_key != NULL)
1180 rte_free(priv->rss_conf.rss_key);
1181 if (priv->reta_idx != NULL)
1182 rte_free(priv->reta_idx);
1183 if (priv->config.vf)
1184 mlx5_nl_mac_addr_flush(priv->nl_socket_route, mlx5_ifindex(dev),
1185 dev->data->mac_addrs,
1186 MLX5_MAX_MAC_ADDRESSES, priv->mac_own);
1187 if (priv->nl_socket_route >= 0)
1188 close(priv->nl_socket_route);
1189 if (priv->nl_socket_rdma >= 0)
1190 close(priv->nl_socket_rdma);
1191 if (priv->vmwa_context)
1192 mlx5_vlan_vmwa_exit(priv->vmwa_context);
1193 ret = mlx5_hrxq_verify(dev);
1195 DRV_LOG(WARNING, "port %u some hash Rx queue still remain",
1196 dev->data->port_id);
1197 ret = mlx5_ind_table_obj_verify(dev);
1199 DRV_LOG(WARNING, "port %u some indirection table still remain",
1200 dev->data->port_id);
1201 ret = mlx5_rxq_obj_verify(dev);
1203 DRV_LOG(WARNING, "port %u some Rx queue objects still remain",
1204 dev->data->port_id);
1205 ret = mlx5_rxq_verify(dev);
1207 DRV_LOG(WARNING, "port %u some Rx queues still remain",
1208 dev->data->port_id);
1209 ret = mlx5_txq_obj_verify(dev);
1211 DRV_LOG(WARNING, "port %u some Verbs Tx queue still remain",
1212 dev->data->port_id);
1213 ret = mlx5_txq_verify(dev);
1215 DRV_LOG(WARNING, "port %u some Tx queues still remain",
1216 dev->data->port_id);
1217 ret = mlx5_flow_verify(dev);
1219 DRV_LOG(WARNING, "port %u some flows still remain",
1220 dev->data->port_id);
1222 * Free the shared context in last turn, because the cleanup
1223 * routines above may use some shared fields, like
1224 * mlx5_nl_mac_addr_flush() uses ibdev_path for retrieveing
1225 * ifindex if Netlink fails.
1227 mlx5_free_shared_dev_ctx(priv->sh);
1228 if (priv->domain_id != RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
1232 MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
1233 struct mlx5_priv *opriv =
1234 rte_eth_devices[port_id].data->dev_private;
1237 opriv->domain_id != priv->domain_id ||
1238 &rte_eth_devices[port_id] == dev)
1244 claim_zero(rte_eth_switch_domain_free(priv->domain_id));
1246 memset(priv, 0, sizeof(*priv));
1247 priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
1249 * Reset mac_addrs to NULL such that it is not freed as part of
1250 * rte_eth_dev_release_port(). mac_addrs is part of dev_private so
1251 * it is freed when dev_private is freed.
1253 dev->data->mac_addrs = NULL;
1257 * Verify and store value for device argument.
1260 * Key argument to verify.
1262 * Value associated with key.
1267 * 0 on success, a negative errno value otherwise and rte_errno is set.
1270 mlx5_args_check(const char *key, const char *val, void *opaque)
1272 struct mlx5_dev_config *config = opaque;
1275 /* No-op, port representors are processed in mlx5_dev_spawn(). */
1276 if (!strcmp(MLX5_REPRESENTOR, key))
1279 tmp = strtoul(val, NULL, 0);
1282 DRV_LOG(WARNING, "%s: \"%s\" is not a valid integer", key, val);
1285 if (strcmp(MLX5_RXQ_CQE_COMP_EN, key) == 0) {
1286 config->cqe_comp = !!tmp;
1287 } else if (strcmp(MLX5_RXQ_CQE_PAD_EN, key) == 0) {
1288 config->cqe_pad = !!tmp;
1289 } else if (strcmp(MLX5_RXQ_PKT_PAD_EN, key) == 0) {
1290 config->hw_padding = !!tmp;
1291 } else if (strcmp(MLX5_RX_MPRQ_EN, key) == 0) {
1292 config->mprq.enabled = !!tmp;
1293 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_NUM, key) == 0) {
1294 config->mprq.stride_num_n = tmp;
1295 } else if (strcmp(MLX5_RX_MPRQ_LOG_STRIDE_SIZE, key) == 0) {
1296 config->mprq.stride_size_n = tmp;
1297 } else if (strcmp(MLX5_RX_MPRQ_MAX_MEMCPY_LEN, key) == 0) {
1298 config->mprq.max_memcpy_len = tmp;
1299 } else if (strcmp(MLX5_RXQS_MIN_MPRQ, key) == 0) {
1300 config->mprq.min_rxqs_num = tmp;
1301 } else if (strcmp(MLX5_TXQ_INLINE, key) == 0) {
1302 DRV_LOG(WARNING, "%s: deprecated parameter,"
1303 " converted to txq_inline_max", key);
1304 config->txq_inline_max = tmp;
1305 } else if (strcmp(MLX5_TXQ_INLINE_MAX, key) == 0) {
1306 config->txq_inline_max = tmp;
1307 } else if (strcmp(MLX5_TXQ_INLINE_MIN, key) == 0) {
1308 config->txq_inline_min = tmp;
1309 } else if (strcmp(MLX5_TXQ_INLINE_MPW, key) == 0) {
1310 config->txq_inline_mpw = tmp;
1311 } else if (strcmp(MLX5_TXQS_MIN_INLINE, key) == 0) {
1312 config->txqs_inline = tmp;
1313 } else if (strcmp(MLX5_TXQS_MAX_VEC, key) == 0) {
1314 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1315 } else if (strcmp(MLX5_TXQ_MPW_EN, key) == 0) {
1316 config->mps = !!tmp;
1317 } else if (strcmp(MLX5_TX_DB_NC, key) == 0) {
1318 if (tmp != MLX5_TXDB_CACHED &&
1319 tmp != MLX5_TXDB_NCACHED &&
1320 tmp != MLX5_TXDB_HEURISTIC) {
1321 DRV_LOG(ERR, "invalid Tx doorbell "
1322 "mapping parameter");
1327 } else if (strcmp(MLX5_TXQ_MPW_HDR_DSEG_EN, key) == 0) {
1328 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1329 } else if (strcmp(MLX5_TXQ_MAX_INLINE_LEN, key) == 0) {
1330 DRV_LOG(WARNING, "%s: deprecated parameter,"
1331 " converted to txq_inline_mpw", key);
1332 config->txq_inline_mpw = tmp;
1333 } else if (strcmp(MLX5_TX_VEC_EN, key) == 0) {
1334 DRV_LOG(WARNING, "%s: deprecated parameter, ignored", key);
1335 } else if (strcmp(MLX5_RX_VEC_EN, key) == 0) {
1336 config->rx_vec_en = !!tmp;
1337 } else if (strcmp(MLX5_L3_VXLAN_EN, key) == 0) {
1338 config->l3_vxlan_en = !!tmp;
1339 } else if (strcmp(MLX5_VF_NL_EN, key) == 0) {
1340 config->vf_nl_en = !!tmp;
1341 } else if (strcmp(MLX5_DV_ESW_EN, key) == 0) {
1342 config->dv_esw_en = !!tmp;
1343 } else if (strcmp(MLX5_DV_FLOW_EN, key) == 0) {
1344 config->dv_flow_en = !!tmp;
1345 } else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
1346 if (tmp != MLX5_XMETA_MODE_LEGACY &&
1347 tmp != MLX5_XMETA_MODE_META16 &&
1348 tmp != MLX5_XMETA_MODE_META32) {
1349 DRV_LOG(ERR, "invalid extensive "
1350 "metadata parameter");
1354 config->dv_xmeta_en = tmp;
1355 } else if (strcmp(MLX5_MR_EXT_MEMSEG_EN, key) == 0) {
1356 config->mr_ext_memseg_en = !!tmp;
1357 } else if (strcmp(MLX5_MAX_DUMP_FILES_NUM, key) == 0) {
1358 config->max_dump_files_num = tmp;
1359 } else if (strcmp(MLX5_LRO_TIMEOUT_USEC, key) == 0) {
1360 config->lro.timeout = tmp;
1361 } else if (strcmp(MLX5_CLASS_ARG_NAME, key) == 0) {
1362 DRV_LOG(DEBUG, "class argument is %s.", val);
1363 } else if (strcmp(MLX5_HP_BUF_SIZE, key) == 0) {
1364 config->log_hp_size = tmp;
1365 } else if (strcmp(MLX5_RECLAIM_MEM, key) == 0) {
1366 if (tmp != MLX5_RCM_NONE &&
1367 tmp != MLX5_RCM_LIGHT &&
1368 tmp != MLX5_RCM_AGGR) {
1369 DRV_LOG(ERR, "Unrecognize %s: \"%s\"", key, val);
1373 config->reclaim_mode = tmp;
1375 DRV_LOG(WARNING, "%s: unknown parameter", key);
1383 * Parse device parameters.
1386 * Pointer to device configuration structure.
1388 * Device arguments structure.
1391 * 0 on success, a negative errno value otherwise and rte_errno is set.
1394 mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs)
1396 const char **params = (const char *[]){
1397 MLX5_RXQ_CQE_COMP_EN,
1398 MLX5_RXQ_CQE_PAD_EN,
1399 MLX5_RXQ_PKT_PAD_EN,
1401 MLX5_RX_MPRQ_LOG_STRIDE_NUM,
1402 MLX5_RX_MPRQ_LOG_STRIDE_SIZE,
1403 MLX5_RX_MPRQ_MAX_MEMCPY_LEN,
1406 MLX5_TXQ_INLINE_MIN,
1407 MLX5_TXQ_INLINE_MAX,
1408 MLX5_TXQ_INLINE_MPW,
1409 MLX5_TXQS_MIN_INLINE,
1412 MLX5_TXQ_MPW_HDR_DSEG_EN,
1413 MLX5_TXQ_MAX_INLINE_LEN,
1422 MLX5_MR_EXT_MEMSEG_EN,
1424 MLX5_MAX_DUMP_FILES_NUM,
1425 MLX5_LRO_TIMEOUT_USEC,
1426 MLX5_CLASS_ARG_NAME,
1431 struct rte_kvargs *kvlist;
1435 if (devargs == NULL)
1437 /* Following UGLY cast is done to pass checkpatch. */
1438 kvlist = rte_kvargs_parse(devargs->args, params);
1439 if (kvlist == NULL) {
1443 /* Process parameters. */
1444 for (i = 0; (params[i] != NULL); ++i) {
1445 if (rte_kvargs_count(kvlist, params[i])) {
1446 ret = rte_kvargs_process(kvlist, params[i],
1447 mlx5_args_check, config);
1450 rte_kvargs_free(kvlist);
1455 rte_kvargs_free(kvlist);
1460 * PMD global initialization.
1462 * Independent from individual device, this function initializes global
1463 * per-PMD data structures distinguishing primary and secondary processes.
1464 * Hence, each initialization is called once per a process.
1467 * 0 on success, a negative errno value otherwise and rte_errno is set.
1470 mlx5_init_once(void)
1472 struct mlx5_shared_data *sd;
1473 struct mlx5_local_data *ld = &mlx5_local_data;
1476 if (mlx5_init_shared_data())
1478 sd = mlx5_shared_data;
1480 rte_spinlock_lock(&sd->lock);
1481 switch (rte_eal_process_type()) {
1482 case RTE_PROC_PRIMARY:
1485 LIST_INIT(&sd->mem_event_cb_list);
1486 rte_rwlock_init(&sd->mem_event_rwlock);
1487 rte_mem_event_callback_register("MLX5_MEM_EVENT_CB",
1488 mlx5_mr_mem_event_cb, NULL);
1489 ret = mlx5_mp_init_primary(MLX5_MP_NAME,
1490 mlx5_mp_primary_handle);
1493 sd->init_done = true;
1495 case RTE_PROC_SECONDARY:
1498 ret = mlx5_mp_init_secondary(MLX5_MP_NAME,
1499 mlx5_mp_secondary_handle);
1502 ++sd->secondary_cnt;
1503 ld->init_done = true;
1509 rte_spinlock_unlock(&sd->lock);
1514 * Configures the minimal amount of data to inline into WQE
1515 * while sending packets.
1517 * - the txq_inline_min has the maximal priority, if this
1518 * key is specified in devargs
1519 * - if DevX is enabled the inline mode is queried from the
1520 * device (HCA attributes and NIC vport context if needed).
1521 * - otherwise L2 mode (18 bytes) is assumed for ConnectX-4/4 Lx
1522 * and none (0 bytes) for other NICs
1525 * Verbs device parameters (name, port, switch_info) to spawn.
1527 * Device configuration parameters.
1530 mlx5_set_min_inline(struct mlx5_dev_spawn_data *spawn,
1531 struct mlx5_dev_config *config)
1533 if (config->txq_inline_min != MLX5_ARG_UNSET) {
1534 /* Application defines size of inlined data explicitly. */
1535 switch (spawn->pci_dev->id.device_id) {
1536 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
1537 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
1538 if (config->txq_inline_min <
1539 (int)MLX5_INLINE_HSIZE_L2) {
1541 "txq_inline_mix aligned to minimal"
1542 " ConnectX-4 required value %d",
1543 (int)MLX5_INLINE_HSIZE_L2);
1544 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1550 if (config->hca_attr.eth_net_offloads) {
1551 /* We have DevX enabled, inline mode queried successfully. */
1552 switch (config->hca_attr.wqe_inline_mode) {
1553 case MLX5_CAP_INLINE_MODE_L2:
1554 /* outer L2 header must be inlined. */
1555 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1557 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
1558 /* No inline data are required by NIC. */
1559 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
1560 config->hw_vlan_insert =
1561 config->hca_attr.wqe_vlan_insert;
1562 DRV_LOG(DEBUG, "Tx VLAN insertion is supported");
1564 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
1565 /* inline mode is defined by NIC vport context. */
1566 if (!config->hca_attr.eth_virt)
1568 switch (config->hca_attr.vport_inline_mode) {
1569 case MLX5_INLINE_MODE_NONE:
1570 config->txq_inline_min =
1571 MLX5_INLINE_HSIZE_NONE;
1573 case MLX5_INLINE_MODE_L2:
1574 config->txq_inline_min =
1575 MLX5_INLINE_HSIZE_L2;
1577 case MLX5_INLINE_MODE_IP:
1578 config->txq_inline_min =
1579 MLX5_INLINE_HSIZE_L3;
1581 case MLX5_INLINE_MODE_TCP_UDP:
1582 config->txq_inline_min =
1583 MLX5_INLINE_HSIZE_L4;
1585 case MLX5_INLINE_MODE_INNER_L2:
1586 config->txq_inline_min =
1587 MLX5_INLINE_HSIZE_INNER_L2;
1589 case MLX5_INLINE_MODE_INNER_IP:
1590 config->txq_inline_min =
1591 MLX5_INLINE_HSIZE_INNER_L3;
1593 case MLX5_INLINE_MODE_INNER_TCP_UDP:
1594 config->txq_inline_min =
1595 MLX5_INLINE_HSIZE_INNER_L4;
1601 * We get here if we are unable to deduce
1602 * inline data size with DevX. Try PCI ID
1603 * to determine old NICs.
1605 switch (spawn->pci_dev->id.device_id) {
1606 case PCI_DEVICE_ID_MELLANOX_CONNECTX4:
1607 case PCI_DEVICE_ID_MELLANOX_CONNECTX4VF:
1608 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LX:
1609 case PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF:
1610 config->txq_inline_min = MLX5_INLINE_HSIZE_L2;
1611 config->hw_vlan_insert = 0;
1613 case PCI_DEVICE_ID_MELLANOX_CONNECTX5:
1614 case PCI_DEVICE_ID_MELLANOX_CONNECTX5VF:
1615 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EX:
1616 case PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF:
1618 * These NICs support VLAN insertion from WQE and
1619 * report the wqe_vlan_insert flag. But there is the bug
1620 * and PFC control may be broken, so disable feature.
1622 config->hw_vlan_insert = 0;
1623 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
1626 config->txq_inline_min = MLX5_INLINE_HSIZE_NONE;
1630 DRV_LOG(DEBUG, "min tx inline configured: %d", config->txq_inline_min);
1634 * Configures the metadata mask fields in the shared context.
1637 * Pointer to Ethernet device.
1640 mlx5_set_metadata_mask(struct rte_eth_dev *dev)
1642 struct mlx5_priv *priv = dev->data->dev_private;
1643 struct mlx5_dev_ctx_shared *sh = priv->sh;
1644 uint32_t meta, mark, reg_c0;
1646 reg_c0 = ~priv->vport_meta_mask;
1647 switch (priv->config.dv_xmeta_en) {
1648 case MLX5_XMETA_MODE_LEGACY:
1650 mark = MLX5_FLOW_MARK_MASK;
1652 case MLX5_XMETA_MODE_META16:
1653 meta = reg_c0 >> rte_bsf32(reg_c0);
1654 mark = MLX5_FLOW_MARK_MASK;
1656 case MLX5_XMETA_MODE_META32:
1658 mark = (reg_c0 >> rte_bsf32(reg_c0)) & MLX5_FLOW_MARK_MASK;
1666 if (sh->dv_mark_mask && sh->dv_mark_mask != mark)
1667 DRV_LOG(WARNING, "metadata MARK mask mismatche %08X:%08X",
1668 sh->dv_mark_mask, mark);
1670 sh->dv_mark_mask = mark;
1671 if (sh->dv_meta_mask && sh->dv_meta_mask != meta)
1672 DRV_LOG(WARNING, "metadata META mask mismatche %08X:%08X",
1673 sh->dv_meta_mask, meta);
1675 sh->dv_meta_mask = meta;
1676 if (sh->dv_regc0_mask && sh->dv_regc0_mask != reg_c0)
1677 DRV_LOG(WARNING, "metadata reg_c0 mask mismatche %08X:%08X",
1678 sh->dv_meta_mask, reg_c0);
1680 sh->dv_regc0_mask = reg_c0;
1681 DRV_LOG(DEBUG, "metadata mode %u", priv->config.dv_xmeta_en);
1682 DRV_LOG(DEBUG, "metadata MARK mask %08X", sh->dv_mark_mask);
1683 DRV_LOG(DEBUG, "metadata META mask %08X", sh->dv_meta_mask);
1684 DRV_LOG(DEBUG, "metadata reg_c0 mask %08X", sh->dv_regc0_mask);
1688 rte_pmd_mlx5_get_dyn_flag_names(char *names[], unsigned int n)
1690 static const char *const dynf_names[] = {
1691 RTE_PMD_MLX5_FINE_GRANULARITY_INLINE,
1692 RTE_MBUF_DYNFLAG_METADATA_NAME
1696 if (n < RTE_DIM(dynf_names))
1698 for (i = 0; i < RTE_DIM(dynf_names); i++) {
1699 if (names[i] == NULL)
1701 strcpy(names[i], dynf_names[i]);
1703 return RTE_DIM(dynf_names);
1707 * Comparison callback to sort device data.
1709 * This is meant to be used with qsort().
1712 * Pointer to pointer to first data object.
1714 * Pointer to pointer to second data object.
1717 * 0 if both objects are equal, less than 0 if the first argument is less
1718 * than the second, greater than 0 otherwise.
1721 mlx5_dev_check_sibling_config(struct mlx5_priv *priv,
1722 struct mlx5_dev_config *config)
1724 struct mlx5_dev_ctx_shared *sh = priv->sh;
1725 struct mlx5_dev_config *sh_conf = NULL;
1729 /* Nothing to compare for the single/first device. */
1730 if (sh->refcnt == 1)
1732 /* Find the device with shared context. */
1733 MLX5_ETH_FOREACH_DEV(port_id, priv->pci_dev) {
1734 struct mlx5_priv *opriv =
1735 rte_eth_devices[port_id].data->dev_private;
1737 if (opriv && opriv != priv && opriv->sh == sh) {
1738 sh_conf = &opriv->config;
1744 if (sh_conf->dv_flow_en ^ config->dv_flow_en) {
1745 DRV_LOG(ERR, "\"dv_flow_en\" configuration mismatch"
1746 " for shared %s context", sh->ibdev_name);
1750 if (sh_conf->dv_xmeta_en ^ config->dv_xmeta_en) {
1751 DRV_LOG(ERR, "\"dv_xmeta_en\" configuration mismatch"
1752 " for shared %s context", sh->ibdev_name);
1760 * Look for the ethernet device belonging to mlx5 driver.
1762 * @param[in] port_id
1763 * port_id to start looking for device.
1764 * @param[in] pci_dev
1765 * Pointer to the hint PCI device. When device is being probed
1766 * the its siblings (master and preceding representors might
1767 * not have assigned driver yet (because the mlx5_os_pci_probe()
1768 * is not completed yet, for this case match on hint PCI
1769 * device may be used to detect sibling device.
1772 * port_id of found device, RTE_MAX_ETHPORT if not found.
1775 mlx5_eth_find_next(uint16_t port_id, struct rte_pci_device *pci_dev)
1777 while (port_id < RTE_MAX_ETHPORTS) {
1778 struct rte_eth_dev *dev = &rte_eth_devices[port_id];
1780 if (dev->state != RTE_ETH_DEV_UNUSED &&
1782 (dev->device == &pci_dev->device ||
1783 (dev->device->driver &&
1784 dev->device->driver->name &&
1785 !strcmp(dev->device->driver->name, MLX5_DRIVER_NAME))))
1789 if (port_id >= RTE_MAX_ETHPORTS)
1790 return RTE_MAX_ETHPORTS;
1795 * DPDK callback to remove a PCI device.
1797 * This function removes all Ethernet devices belong to a given PCI device.
1799 * @param[in] pci_dev
1800 * Pointer to the PCI device.
1803 * 0 on success, the function cannot fail.
1806 mlx5_pci_remove(struct rte_pci_device *pci_dev)
1810 RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device) {
1812 * mlx5_dev_close() is not registered to secondary process,
1813 * call the close function explicitly for secondary process.
1815 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
1816 mlx5_dev_close(&rte_eth_devices[port_id]);
1818 rte_eth_dev_close(port_id);
1823 static const struct rte_pci_id mlx5_pci_id_map[] = {
1825 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1826 PCI_DEVICE_ID_MELLANOX_CONNECTX4)
1829 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1830 PCI_DEVICE_ID_MELLANOX_CONNECTX4VF)
1833 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1834 PCI_DEVICE_ID_MELLANOX_CONNECTX4LX)
1837 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1838 PCI_DEVICE_ID_MELLANOX_CONNECTX4LXVF)
1841 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1842 PCI_DEVICE_ID_MELLANOX_CONNECTX5)
1845 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1846 PCI_DEVICE_ID_MELLANOX_CONNECTX5VF)
1849 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1850 PCI_DEVICE_ID_MELLANOX_CONNECTX5EX)
1853 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1854 PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)
1857 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1858 PCI_DEVICE_ID_MELLANOX_CONNECTX5BF)
1861 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1862 PCI_DEVICE_ID_MELLANOX_CONNECTX5BFVF)
1865 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1866 PCI_DEVICE_ID_MELLANOX_CONNECTX6)
1869 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1870 PCI_DEVICE_ID_MELLANOX_CONNECTX6VF)
1873 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1874 PCI_DEVICE_ID_MELLANOX_CONNECTX6DX)
1877 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1878 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXVF)
1881 RTE_PCI_DEVICE(PCI_VENDOR_ID_MELLANOX,
1882 PCI_DEVICE_ID_MELLANOX_CONNECTX6DXBF)
1889 struct rte_pci_driver mlx5_driver = {
1891 .name = MLX5_DRIVER_NAME
1893 .id_table = mlx5_pci_id_map,
1894 .probe = mlx5_os_pci_probe,
1895 .remove = mlx5_pci_remove,
1896 .dma_map = mlx5_dma_map,
1897 .dma_unmap = mlx5_dma_unmap,
1898 .drv_flags = PCI_DRV_FLAGS,
1902 * Driver initialization routine.
1904 RTE_INIT(rte_mlx5_pmd_init)
1906 /* Initialize driver log type. */
1907 mlx5_logtype = rte_log_register("pmd.net.mlx5");
1908 if (mlx5_logtype >= 0)
1909 rte_log_set_level(mlx5_logtype, RTE_LOG_NOTICE);
1911 /* Build the static tables for Verbs conversion. */
1912 mlx5_set_ptype_table();
1913 mlx5_set_cksum_table();
1914 mlx5_set_swp_types_table();
1916 rte_pci_register(&mlx5_driver);
1919 RTE_PMD_EXPORT_NAME(net_mlx5, __COUNTER__);
1920 RTE_PMD_REGISTER_PCI_TABLE(net_mlx5, mlx5_pci_id_map);
1921 RTE_PMD_REGISTER_KMOD_DEP(net_mlx5, "* ib_uverbs & mlx5_core & mlx5_ib");