From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EF18AA034F; Fri, 8 Oct 2021 12:56:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F188141150; Fri, 8 Oct 2021 12:56:04 +0200 (CEST) Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by mails.dpdk.org (Postfix) with ESMTP id DF67941217 for ; Thu, 7 Oct 2021 20:44:32 +0200 (CEST) Received: by mail-pj1-f50.google.com with SMTP id np13so5569218pjb.4 for ; Thu, 07 Oct 2021 11:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5wuHPQFr6ztPw+nIR71q/bSoQDII8Z8VpDwQAzzZFHY=; b=jnqIFytbVgpD9X9Eiu0QW0NIUlVw/jFVeWVGMqIaqfafYRZ2GWwD3VKFLD5qUSg+hr U7YDyqHai7buIlNu5AwKMf2a/6864BQA8PlR26yMujPB1B8tpWmJW9CKHvRzcDh2BE/T bm5p9Dk5rfJl4HxluvuQURvcS632TftOydrew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5wuHPQFr6ztPw+nIR71q/bSoQDII8Z8VpDwQAzzZFHY=; b=3sV6LyAEp5ujwKZ/4ACsrqjlMjowx/ouSqSIHpcIE+89KqlH1u1RRSnKuDbXynvmjt 73iHQUmaU41eVLCxRc+r18NhjtMYqvs3D/EPS3s03Z/nwDjeIn1PN/7kt3Fvzki/4fbw XvCJcc0fpU+nhEOxSo14eDLHxdm8EWpmPdeyb4voJiRkYzONdEBtQOFHBNQK2dFg4ErP gpAy6g6v6q5miS4pRysLogOIHpp0W9MGAgA40wbEykINMfaDUeAlNIrFs3Hw0y53CSwX q6OIJjoC02pYb710c+N22aWyVNWPXFaDiKPViPnli0iP246FpDIcLpPhoBo712L8CIEU 0mQg== X-Gm-Message-State: AOAM531Zc008zMy1SFDtPVyMNO7gy91HwGcVczfYgwIPT6DVUXMI3caT E/Ygkz8AI6DQ50aftWLy6laVmA== X-Google-Smtp-Source: ABdhPJzLQQhm3iAEWu/1bvSctJRHGG6SSNmopQ2RJN0lzlYcZSu8G1XlOJSOWP5U1jawmz6UIlvNMw== X-Received: by 2002:a17:90a:6401:: with SMTP id g1mr7307148pjj.228.1633632272172; Thu, 07 Oct 2021 11:44:32 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([136.185.113.102]) by smtp.gmail.com with ESMTPSA id c11sm3311586pji.38.2021.10.07.11.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:44:31 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Fri, 8 Oct 2021 00:13:16 +0530 Message-Id: <20211007184350.73858-8-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007184350.73858-1-srikanth.k@oneconvergence.com> References: <20211007184350.73858-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 08 Oct 2021 12:55:54 +0200 Subject: [dpdk-dev] [PATCH v2 07/41] common/mlx5: retrieve the device index and name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The mlx5_core kernel driver creates a sysctl variable dev.mlx5_core.0.ifname: mce0 Using this the device index and interface name are obtained The interface name can be used by PMD to communicate with FreeBSD network stack Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/common/mlx5/freebsd/mlx5_common_os.c | 44 ++++++++++++++++++++ drivers/common/mlx5/freebsd/mlx5_common_os.h | 6 +++ 2 files changed, 50 insertions(+) diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.c b/drivers/common/mlx5/freebsd/mlx5_common_os.c index 9c3cd1e4e6..23370857eb 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.c +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.c @@ -4,14 +4,58 @@ #include #include +#include #include #include #include "mlx5_common.h" #include "mlx5_common_log.h" +#include "mlx5_common_os.h" #include "mlx5_glue.h" +/** + * Derive IB dev index from devpath + */ +int +mlx5_get_ibvindex(const char *ibdev_path) +{ + unsigned int ibv_idx; + + MLX5_ASSERT(ibdev_path); + if (sscanf(ibdev_path, "/sys/class/infiniband/mlx5_%u", + &ibv_idx) != 1) + ibv_idx = -1; + + return ibv_idx; +} + +int +mlx5_get_ifname_sysfs(const char *ibdev_path, char *ifname) +{ + char buffer[MLX5_SYSCTL_BY_NAME_SIZE]; + char name[IF_NAMESIZE]; + size_t len = IF_NAMESIZE; + unsigned int idx; + + idx = mlx5_get_ibvindex(ibdev_path); + if (idx < 0) { + rte_errno = EINVAL; + return -rte_errno; + } + + snprintf(buffer, sizeof(buffer), "dev.mlx5_core.%u.ifname", idx); + if (sysctlbyname(buffer, &name, &len, NULL, 0)) { + DRV_LOG(ERR, "port %u failed to get interface name: %s", + idx, strerror(errno)); + rte_errno = errno; + return -rte_errno; + } + strncpy(ifname, name, IF_NAMESIZE); + + return 0; +} + /** * Initialization routine for run-time dependency on rdma-core. */ diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.h b/drivers/common/mlx5/freebsd/mlx5_common_os.h index dab67ecbf0..60e7c4f21f 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.h +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.h @@ -18,6 +18,8 @@ #include "mlx5_autoconf.h" #include "mlx5_glue.h" +#define MLX5_SYSCTL_BY_NAME_SIZE 100 + /** * Get device name. Given an ibv_device pointer - return a * pointer to the corresponding device name. @@ -287,4 +289,8 @@ mlx5_os_free(void *addr) { free(addr); } + +int +mlx5_get_ibvindex(const char *ibdev_path); + #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */ -- 2.30.2