* Allocate shared device context. If there is multiport device the * master and representors will share this context, if there is single * port dedicated device, the context will be used by only given * port due to unification. * * Routine first searches the context for the specified device name, * if found the shared context assumed and reference counter is incremented. * If no context fou
| 1714 | * otherwise NULL and rte_errno is set. |
| 1715 | */ |
| 1716 | struct mlx5_dev_ctx_shared * |
| 1717 | mlx5_alloc_shared_dev_ctx(const struct mlx5_dev_spawn_data *spawn, |
| 1718 | struct mlx5_kvargs_ctrl *mkvlist) |
| 1719 | { |
| 1720 | struct mlx5_dev_ctx_shared *sh; |
| 1721 | int err = 0; |
| 1722 | uint32_t i; |
| 1723 | |
| 1724 | MLX5_ASSERT(spawn); |
| 1725 | /* Secondary process should not create the shared context. */ |
| 1726 | MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); |
| 1727 | pthread_mutex_lock(&mlx5_dev_ctx_list_mutex); |
| 1728 | /* Search for IB context by device name. */ |
| 1729 | LIST_FOREACH(sh, &mlx5_dev_ctx_list, next) { |
| 1730 | if (!strcmp(sh->ibdev_name, spawn->phys_dev_name)) { |
| 1731 | sh->refcnt++; |
| 1732 | goto exit; |
| 1733 | } |
| 1734 | } |
| 1735 | /* No device found, we have to create new shared context. */ |
| 1736 | MLX5_ASSERT(spawn->max_port); |
| 1737 | sh = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE, |
| 1738 | sizeof(struct mlx5_dev_ctx_shared) + |
| 1739 | spawn->max_port * sizeof(struct mlx5_dev_shared_port), |
| 1740 | RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); |
| 1741 | if (!sh) { |
| 1742 | DRV_LOG(ERR, "Shared context allocation failure."); |
| 1743 | rte_errno = ENOMEM; |
| 1744 | goto exit; |
| 1745 | } |
| 1746 | pthread_mutex_init(&sh->txpp.mutex, NULL); |
| 1747 | sh->numa_node = spawn->cdev->dev->numa_node; |
| 1748 | sh->cdev = spawn->cdev; |
| 1749 | sh->esw_mode = !!(spawn->info.master || spawn->info.representor); |
| 1750 | if (spawn->bond_info) |
| 1751 | sh->bond = *spawn->bond_info; |
| 1752 | err = mlx5_os_capabilities_prepare(sh); |
| 1753 | if (err) { |
| 1754 | DRV_LOG(ERR, "Fail to configure device capabilities."); |
| 1755 | goto error; |
| 1756 | } |
| 1757 | err = mlx5_shared_dev_ctx_args_config(sh, mkvlist, &sh->config); |
| 1758 | if (err) { |
| 1759 | DRV_LOG(ERR, "Failed to process device configure: %s", |
| 1760 | strerror(rte_errno)); |
| 1761 | goto error; |
| 1762 | } |
| 1763 | sh->refcnt = 1; |
| 1764 | sh->max_port = spawn->max_port; |
| 1765 | strncpy(sh->ibdev_name, mlx5_os_get_ctx_device_name(sh->cdev->ctx), |
| 1766 | sizeof(sh->ibdev_name) - 1); |
| 1767 | strncpy(sh->ibdev_path, mlx5_os_get_ctx_device_path(sh->cdev->ctx), |
| 1768 | sizeof(sh->ibdev_path) - 1); |
| 1769 | /* |
| 1770 | * Setting port_id to max unallowed value means there is no interrupt |
| 1771 | * subhandler installed for the given port index i. |
| 1772 | */ |
| 1773 | for (i = 0; i < sh->max_port; i++) { |
no test coverage detected