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 99C7AA0C46; Mon, 27 Sep 2021 16:59:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A18764113F; Mon, 27 Sep 2021 16:58:18 +0200 (CEST) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by mails.dpdk.org (Postfix) with ESMTP id BDCE040E3C for ; Mon, 27 Sep 2021 15:36:28 +0200 (CEST) Received: by mail-pj1-f42.google.com with SMTP id k23-20020a17090a591700b001976d2db364so13738717pji.2 for ; Mon, 27 Sep 2021 06:36:28 -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=5PSEI9St58r1uE1BIBJ9fosLgSVlHEgcoQBo6PDboPk=; b=h+py+udAMco2WnKC+QVKnuqaHKGSNAK7lOsI/2pvuEX2JUuKN38xu1dB4aq/nxTBR0 /ju+ddUGBomXGD1aQEH9Q63Qooijc90dl75Rg8V5iMwNVUYJ9JoWWffbviK6JF+FSh+5 MgWpauWRBnTHfMhAyf2OpwdAbPs79ZimiaxDM= 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=5PSEI9St58r1uE1BIBJ9fosLgSVlHEgcoQBo6PDboPk=; b=2ztOUIWrAt4HncwKv6BOpHPj8ChXvdNRMYdA/DVf8jGgngE0Z8VevdspvDJBmfXbCw K9yeaBaLD/ZGYeYaO7K+Mzwy4fonBUdJbH6kABi17PUrIdzVpm3UhE5t9HAQrPGSjPPB gH3DYPal91k/4puSgev113J5EbN+fypUGyu/CUCD+ugorfgA383ewm0vbAIdgKvTKHcj QsOLWcuaM1zXeBo0lWjm5Dwhjdhkrn92VG+wWrZYi2ylfv05Fr2JvJq2gXXGaQwQjeb8 YUSEPQ979Peq22MaI90uKURQiS9i7YUC8iQ9pI8bMVnBs7uQtuHHLnNwTcrHv+ctdlZ9 rVfA== X-Gm-Message-State: AOAM530molosruZthMFJJPx8CWNnIYZE1RwcGBbD7GPdJzqSvN2xyUML IgNYIavu3wtZtJChIe+BQasBXA== X-Google-Smtp-Source: ABdhPJyvFNnyOaru6H2PFHoGUYTqS/E7LtXSMRzgROYsr3frTNnCgMKwQIxtZDQAyy3uJDvIw10+FQ== X-Received: by 2002:a17:90b:1e09:: with SMTP id pg9mr20099985pjb.73.1632749786981; Mon, 27 Sep 2021 06:36:26 -0700 (PDT) Received: from srikanth-ThinkPad-T450.domain.name ([223.178.22.200]) by smtp.gmail.com with ESMTPSA id t6sm17342274pfh.63.2021.09.27.06.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:36:26 -0700 (PDT) From: Srikanth Kaka To: Matan Azrad , Viacheslav Ovsiienko Cc: dev@dpdk.org, Vag Singh , Anand Thulasiram , Srikanth Kaka Date: Mon, 27 Sep 2021 19:04:40 +0530 Message-Id: <20210927133450.10653-10-srikanth.k@oneconvergence.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210927133450.10653-1-srikanth.k@oneconvergence.com> References: <20210927133450.10653-1-srikanth.k@oneconvergence.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 27 Sep 2021 16:58:07 +0200 Subject: [dpdk-dev] [PATCH 09/19] common/mlx5: get interface 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" All network stack operations use interface name. Get it using IBV dev index and sysctl. Signed-off-by: Srikanth Kaka Signed-off-by: Vag Singh Signed-off-by: Anand Thulasiram --- drivers/common/mlx5/freebsd/mlx5_common_os.c | 86 +++++--------------- drivers/common/mlx5/freebsd/mlx5_common_os.h | 3 + 2 files changed, 25 insertions(+), 64 deletions(-) diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.c b/drivers/common/mlx5/freebsd/mlx5_common_os.c index af28ff756d..303df16c9f 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.c +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.c @@ -147,77 +147,35 @@ mlx5_translate_port_name(const char *port_name_in, } int -mlx5_get_ifname_sysfs(const char *ibdev_path, char *ifname) +mlx5_get_ibvindex(const char *ibdev_path) { - DIR *dir; - struct dirent *dent; - unsigned int dev_type = 0; - unsigned int dev_port_prev = ~0u; - char match[IF_NAMESIZE] = ""; + unsigned int ibv_idx; MLX5_ASSERT(ibdev_path); - { - MKSTR(path, "%s/device/net", ibdev_path); - - dir = opendir(path); - if (dir == NULL) { - rte_errno = errno; - return -rte_errno; - } - } - while ((dent = readdir(dir)) != NULL) { - char *name = dent->d_name; - FILE *file; - unsigned int dev_port; - int r; - - if ((name[0] == '.') && - ((name[1] == '\0') || - ((name[1] == '.') && (name[2] == '\0')))) - continue; + sscanf(ibdev_path, "/sys/class/infiniband/mlx5_%u", &ibv_idx); - MKSTR(path, "%s/device/net/%s/%s", - ibdev_path, name, - (dev_type ? "dev_id" : "dev_port")); + return ibv_idx; +} - file = fopen(path, "rb"); - if (file == NULL) { - if (errno != ENOENT) - continue; - /* - * Switch to dev_id when dev_port does not exist as - * is the case with Linux kernel versions < 3.15. - */ -try_dev_id: - match[0] = '\0'; - if (dev_type) - break; - dev_type = 1; - dev_port_prev = ~0u; - rewinddir(dir); - continue; - } - r = fscanf(file, (dev_type ? "%x" : "%u"), &dev_port); - fclose(file); - if (r != 1) - continue; - /* - * Switch to dev_id when dev_port returns the same value for - * all ports. May happen when using a MOFED release older than - * 3.0 with a Linux kernel >= 3.15. - */ - if (dev_port == dev_port_prev) - goto try_dev_id; - dev_port_prev = dev_port; - if (dev_port == 0) - strlcpy(match, name, IF_NAMESIZE); - } - closedir(dir); - if (match[0] == '\0') { - rte_errno = ENOENT; +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); + + 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, match, IF_NAMESIZE); + strncpy(ifname, name, IF_NAMESIZE); + return 0; } diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.h b/drivers/common/mlx5/freebsd/mlx5_common_os.h index 8fb681444f..bb5f74c599 100644 --- a/drivers/common/mlx5/freebsd/mlx5_common_os.h +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.h @@ -298,4 +298,7 @@ __rte_internal struct ibv_device * mlx5_os_get_ibv_dev(const struct rte_device *dev); +int +mlx5_get_ibvindex(const char *ibdev_path); + #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */ -- 2.30.2