From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by dpdk.org (Postfix) with ESMTP id 1C631C422 for ; Tue, 30 Jun 2015 11:28:26 +0200 (CEST) Received: by wiar9 with SMTP id r9so29612345wia.1 for ; Tue, 30 Jun 2015 02:28:26 -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=t8KvxibO35yDAFn/emGsXwKNyI30C0UcCAIrK3XqhJ0=; b=RagVBx8f2O6/Bv8mq+1AS+q+M0YPchSAMP58OKFo1FiiAsjV+i5RMOxfNNWRMMJ8KH jzw0rKrZDy9O6uF02BMyUw7VWg7EDsYfLw/LjtA8FGjn98ghjHQMKmd9+5eYcNVayDv1 84nnLXyy4izrUoVJ9nOLpgolOWtE1Gfdn+vJLYk++JWBL47L2aH3kikqs+E94u2QFYPT TLCEHtF71boZU7Z7ArN0H7h7Rm75mcS0OS3OFQC9aXbryHayfRbX8RTv2kYmajt15tca rc6uejXvKXaEbs9BrNSo2eRSl4oiTJEJHOOChKd19unRxZCd3EEAugMN14w0QRrtt+Ql zcIw== X-Gm-Message-State: ALoCoQm4TGL1jONQenN+cuZ+Ql9H9LP8M+BdV7fzNgjV9HLDWxlQLcQDGmTJpTwfcd41bwlDC3x+ X-Received: by 10.180.75.132 with SMTP id c4mr20982611wiw.20.1435656505970; Tue, 30 Jun 2015 02:28:25 -0700 (PDT) Received: from 6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by mx.google.com with ESMTPSA id g15sm16084382wiv.22.2015.06.30.02.28.24 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 02:28:25 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Tue, 30 Jun 2015 11:27:48 +0200 Message-Id: <1435656489-27986-3-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435656489-27986-1-git-send-email-adrien.mazarguil@6wind.com> References: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> <1435656489-27986-1-git-send-email-adrien.mazarguil@6wind.com> Subject: [dpdk-dev] [PATCH v2 02/23] 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: Tue, 30 Jun 2015 09:28:26 -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 d1166b2..ad37e01 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