| 743 | } |
| 744 | |
| 745 | static struct mlx5_common_device * |
| 746 | mlx5_common_dev_create(struct rte_device *eal_dev, uint32_t classes, |
| 747 | struct mlx5_kvargs_ctrl *mkvlist) |
| 748 | { |
| 749 | struct mlx5_common_device *cdev; |
| 750 | int ret; |
| 751 | |
| 752 | cdev = rte_zmalloc("mlx5_common_device", sizeof(*cdev), 0); |
| 753 | if (!cdev) { |
| 754 | DRV_LOG(ERR, "Device allocation failure."); |
| 755 | rte_errno = ENOMEM; |
| 756 | return NULL; |
| 757 | } |
| 758 | cdev->dev = eal_dev; |
| 759 | if (rte_eal_process_type() != RTE_PROC_PRIMARY) |
| 760 | goto exit; |
| 761 | /* Parse device parameters. */ |
| 762 | ret = mlx5_common_config_get(mkvlist, &cdev->config); |
| 763 | if (ret < 0) { |
| 764 | DRV_LOG(ERR, "Failed to process device arguments: %s", |
| 765 | strerror(rte_errno)); |
| 766 | rte_free(cdev); |
| 767 | return NULL; |
| 768 | } |
| 769 | mlx5_malloc_mem_select(cdev->config.sys_mem_en); |
| 770 | /* Initialize all HW global of device context. */ |
| 771 | ret = mlx5_dev_hw_global_prepare(cdev, classes); |
| 772 | if (ret) { |
| 773 | DRV_LOG(ERR, "Failed to initialize device context."); |
| 774 | rte_free(cdev); |
| 775 | return NULL; |
| 776 | } |
| 777 | /* Initialize global MR cache resources and update its functions. */ |
| 778 | ret = mlx5_mr_create_cache(&cdev->mr_scache, eal_dev->numa_node); |
| 779 | if (ret) { |
| 780 | DRV_LOG(ERR, "Failed to initialize global MR share cache."); |
| 781 | mlx5_dev_hw_global_release(cdev); |
| 782 | rte_free(cdev); |
| 783 | return NULL; |
| 784 | } |
| 785 | /* Register callback function for global shared MR cache management. */ |
| 786 | if (TAILQ_EMPTY(&devices_list)) |
| 787 | rte_mem_event_callback_register("MLX5_MEM_EVENT_CB", |
| 788 | mlx5_mr_mem_event_cb, NULL); |
| 789 | exit: |
| 790 | pthread_mutex_lock(&devices_list_lock); |
| 791 | TAILQ_INSERT_HEAD(&devices_list, cdev, next); |
| 792 | pthread_mutex_unlock(&devices_list_lock); |
| 793 | return cdev; |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * Validate common devargs when probing again. |
no test coverage detected