From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id E3C8A1DB9 for ; Fri, 13 Jul 2018 15:54:12 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id s9-v6so1583699wmh.3 for ; Fri, 13 Jul 2018 06:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=qyloyPB4RVzEerG+Djz6d0BhV0N6bl1qjTaCDcrfLqo=; b=ysT6kkKl8Qy9C9K8ORszR9gPcdckwe5guYy4tpHN5XS5ZnUMs5fMtdRyMTrplhjVSC REaX3L6s37ftqU17FWsVaFxtFuhrzvEC+f8UlLdzeRBqllpvh+tPezsjR+AKzW5H9uJo ElpBzIa87wtjnvGCRXP+/Fena0D3Y1esDyYDZ82EWkkaGUaznik6WBwJMjfwWlcwCnq+ aJMmgCUy70lAUOlBnz8RmKLuDNj3blnGZQy7tBVLy+PHa8QONNpd1XaZMU2gq5X+2qUy Rv3fRX/kMOthQepEn7AL6Tkqwt8kJTtLDb5lJuMGYeDczWbMR07P96pDcxJuYEjytqrJ vlvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=qyloyPB4RVzEerG+Djz6d0BhV0N6bl1qjTaCDcrfLqo=; b=i0/ccAkOEl76vn+2giIHsPkd66vDm4lcmrJI3Otkbxdbh43C5m36zibM2hw+OoGgcA 6ppVUP1i1deu2AqUtW+Sh3bCwAXsvkqeqHcTuuPxCYaQU0sQoD10JH9sG3OJQG4ugBPQ tfUarTKMj9948o7sihophp9kcPG3/YYNlTTS4S6MGhlzd6DtqhoABRgrGGOd6uCpJW51 1BoyY1FZgSco9vYII8HuIs1Zx7sExo3YWW8xQNC5mbWDyoe2jBygoqTGcZLZakzb9Pcq bwOCB5t0SxrnQJIIJeAIOey4pGBuyIHmXUjyERQ4xGIbwbUqKU2hclFLnJl10jRj/pbb FdSA== X-Gm-Message-State: AOUpUlGRiVM8iZwtmqZtRfCt65z+qLOoacwu3r0Oki03u9ewFqZCfFGk VVAdzkbTsTn6w4/zuMRcu3hBpel84w== X-Google-Smtp-Source: AAOMgpcUlOys9i7R6kdGhc6Xo9M7amLLsXPVFg7QGRF6yL83dqJ8StVpHTPEDMIESdTTG2qdgso+0Q== X-Received: by 2002:a1c:ca0f:: with SMTP id a15-v6mr3940193wmg.102.1531490052318; Fri, 13 Jul 2018 06:54:12 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id b18-v6sm3427326wrj.72.2018.07.13.06.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 06:54:11 -0700 (PDT) From: Nelio Laranjeiro To: dev@dpdk.org, Shahaf Shuler , Yongseok Koh Date: Fri, 13 Jul 2018 15:53:37 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 Subject: [dpdk-dev] [PATCH] net/mlx5: fix representors detection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jul 2018 13:54:13 -0000 On systems where the required Netlink commands are not supported but Mellanox OFED is installed, representors information must be retrieved through sysfs. Fixes: 4c10141488fe ("net/mlx5: add port representor awareness") Signed-off-by: Nelio Laranjeiro Acked-by: Adrien Mazarguil --- drivers/net/mlx5/mlx5.c | 7 +++-- drivers/net/mlx5/mlx5.h | 2 ++ drivers/net/mlx5/mlx5_ethdev.c | 53 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index df7f39844..8174947f3 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1306,7 +1306,8 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, * Netlink calls assuming kernel drivers are recent enough to * support them. * - * In the event of identification failure through Netlink, either: + * In the event of identification failure through Netlink, try again + * through sysfs, then either: * * 1. No device matches (n == 0), complain and bail out. * 2. A single IB device matches (n == 1) and is not a representor, @@ -1325,7 +1326,9 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, if (nl_route < 0 || !list[i].ifindex || mlx5_nl_switch_info(nl_route, list[i].ifindex, - &list[i].info)) { + &list[i].info) || + ((!list[i].info.representor && !list[i].info.master) && + mlx5_sysfs_switch_info(list[i].ifindex, &list[i].info))) { list[i].ifindex = 0; memset(&list[i].info, 0, sizeof(list[i].info)); continue; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index cc01310e0..fff88b1d6 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -254,6 +254,8 @@ eth_rx_burst_t mlx5_select_rx_function(struct rte_eth_dev *dev); unsigned int mlx5_dev_to_port_id(const struct rte_device *dev, uint16_t *port_list, unsigned int port_list_n); +int mlx5_sysfs_switch_info(unsigned int ifindex, + struct mlx5_switch_info *info); /* mlx5_mac.c */ diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 05f66f7b6..101be4791 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -1296,3 +1296,56 @@ mlx5_dev_to_port_id(const struct rte_device *dev, uint16_t *port_list, } return n; } + +/** + * Get switch information associated with network interface. + * + * @param ifindex + * Network interface index. + * @param[out] info + * Switch information object, populated in case of success. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) +{ + char ifname[IF_NAMESIZE]; + FILE *file; + struct mlx5_switch_info data = { .master = 0, }; + bool port_name_set = false; + bool port_switch_id_set = false; + char c; + + if (!if_indextoname(ifindex, ifname)) { + rte_errno = errno; + return -rte_errno; + } + + MKSTR(phys_port_name, "/sys/class/net/%s/phys_port_name", + ifname); + MKSTR(phys_switch_id, "/sys/class/net/%s/phys_switch_id", + ifname); + + file = fopen(phys_port_name, "rb"); + if (file == NULL) + goto error; + port_name_set = fscanf(file, "%d%c", &data.port_name, &c) == 2 && + c == '\n'; + fclose(file); + file = fopen(phys_switch_id, "rb"); + if (file == NULL) + goto error; + port_switch_id_set = + fscanf(file, "%" SCNx64 "%c", &data.switch_id, &c) == 2 && + c == '\n'; + fclose(file); + data.master = port_switch_id_set && !port_name_set; + data.representor = port_switch_id_set && port_name_set; + *info = data; + return 0; +error: + rte_errno = errno; + return -rte_errno; +} -- 2.18.0