From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id F3D95C364 for ; Sat, 6 Jun 2015 01:15:42 +0200 (CEST) Received: by wgez8 with SMTP id z8so66704469wge.0 for ; Fri, 05 Jun 2015 16:15:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FOxDDgDBB8OQSIhJ94tmIYe/6Hkx00bCSG3QEjgujas=; b=HJ5kk2aOB5+AY/HKcvcXCF4O3wswG6gPgBZnjiwQMxKN1jtkiVfMiL5vunSz+NsczS NUbRTF/E1zO7VW03AAZWyxUgXoOJy3iK5GN7v7E94/fBIiBY+dyCi5/kHrQIgMjGZIen iK4doakxpcyvWZHsFE0IC5nRsSUx5hQl9clWBzsENn9EaFdRNdp4jOCRjL9DekxYzr4X WVg+59TlhaeVczwtbbLqC7hHl+wM4KfVkHkinC07uRjcM+3j5fCMrwyjRrwjFMKsKHjo dOR5ctUjNSKO+yysK1PpYArmmOXDJd97VoYwQ/dKqk2vZVpx81xMa4RusJj+gIw5RUc7 eeyg== X-Gm-Message-State: ALoCoQnhn5bgy4C4QQhSCtMfxK/Ox7naSMZVMMRu7anyxNKZugxA5gZbRjRxQKDR+Yg5Z1f0VdjF X-Received: by 10.194.209.130 with SMTP id mm2mr10154411wjc.64.1433546142854; Fri, 05 Jun 2015 16:15:42 -0700 (PDT) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by mx.google.com with ESMTPSA id bg4sm12581037wjc.10.2015.06.05.16.15.41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 05 Jun 2015 16:15:41 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Sat, 6 Jun 2015 01:15:05 +0200 Message-Id: <1433546120-2254-2-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> References: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> Cc: Nitzan Weller Subject: [dpdk-dev] [PATCH 01/16] mlx4: add MOFED 3.0 compatibility to interfaces names retrieval X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 23:15:43 -0000 Since Mellanox OFED 3.0 and Linux 3.15, interface port numbers are stored in dev_port instead of dev_id sysfs files. Signed-off-by: Or Ami Signed-off-by: Nitzan Weller Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 51 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index f915bc1..648b210 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -337,9 +337,11 @@ priv_unlock(struct priv *priv) static int priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]) { - int ret = -1; DIR *dir; struct dirent *dent; + unsigned int dev_type = 0; + unsigned int dev_port_prev = ~0u; + char match[IF_NAMESIZE] = ""; { MKSTR(path, "%s/device/net", priv->ctx->device->ibdev_path); @@ -351,7 +353,7 @@ priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]) while ((dent = readdir(dir)) != NULL) { char *name = dent->d_name; FILE *file; - unsigned int dev_id; + unsigned int dev_port; int r; if ((name[0] == '.') && @@ -359,22 +361,47 @@ priv_get_ifname(const struct priv *priv, char (*ifname)[IF_NAMESIZE]) ((name[1] == '.') && (name[2] == '\0')))) continue; - MKSTR(path, "%s/device/net/%s/dev_id", - priv->ctx->device->ibdev_path, name); + MKSTR(path, "%s/device/net/%s/%s", + priv->ctx->device->ibdev_path, name, + (dev_type ? "dev_id" : "dev_port")); file = fopen(path, "rb"); - if (file == NULL) + 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, "%x", &dev_id); - fclose(file); - if ((r == 1) && (dev_id == (priv->port - 1u))) { - snprintf(*ifname, sizeof(*ifname), "%s", name); - ret = 0; - break; } + 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 == (priv->port - 1u)) + snprintf(match, sizeof(match), "%s", name); } closedir(dir); - return ret; + if (match[0] == '\0') + return -1; + strncpy(*ifname, match, sizeof(*ifname)); + return 0; } /** -- 2.1.0