From patchwork Sun Mar 10 16:06:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dekel Peled X-Patchwork-Id: 51022 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 355E9378B; Sun, 10 Mar 2019 17:07:58 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id F2697239 for ; Sun, 10 Mar 2019 17:07:56 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from dekelp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Mar 2019 18:07:13 +0200 Received: from mtl-vdi-280.wap.labs.mlnx. (mtl-vdi-280.wap.labs.mlnx [10.128.130.87]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x2AG7Dc4025532; Sun, 10 Mar 2019 18:07:13 +0200 From: Dekel Peled To: yskoh@mellanox.com, shahafs@mellanox.com Cc: dev@dpdk.org, orika@mellanox.com, dekelp@mellanox.com Date: Sun, 10 Mar 2019 18:06:41 +0200 Message-Id: <1552234001-49438-1-git-send-email-dekelp@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1552231266-47914-1-git-send-email-dekelp@mellanox.com> References: <1552231266-47914-1-git-send-email-dekelp@mellanox.com> Subject: [dpdk-dev] [PATCH v4] net/mlx5: support new representor naming format 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Kernel update [1] introduce new format of representors names. This patch implements RFC [2], updating MLX5 PMD to support the new format, while maintaining support of the existing format. [1] https://github.com/torvalds/linux/commit/c12ecc2 [2] http://mails.dpdk.org/archives/dev/2019-March/125676.html Signed-off-by: Dekel Peled --- v4: Remove redundant clear of errno. v3: Add utility function with common logic, call it from sysfs and nl. v2: Use public link to kernel patch, add link to RFC. --- --- drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 39 ++++++++++++++++++++++++++++++++++++--- drivers/net/mlx5/mlx5_nl.c | 10 +++------- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 5384453..f997e71 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -300,6 +300,7 @@ unsigned int mlx5_dev_to_port_id(const struct rte_device *dev, unsigned int port_list_n); int mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info); +bool mlx5_translate_port_name(const char *port_name_in, int32_t *port_name_out); /* mlx5_mac.c */ diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 795c9c7..433a723 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -1353,6 +1353,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info) { char ifname[IF_NAMESIZE]; + char port_name[IF_NAMESIZE]; FILE *file; DIR *dir; struct mlx5_switch_info data = { .master = 0, }; @@ -1375,10 +1376,10 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) file = fopen(phys_port_name, "rb"); if (file != NULL) { - port_name_set = - fscanf(file, "%d%c", &data.port_name, &c) == 2 && - c == '\n'; + fscanf(file, "%s", port_name); fclose(file); + port_name_set = mlx5_translate_port_name(port_name, + &data.port_name); } file = fopen(phys_switch_id, "rb"); if (file == NULL) { @@ -1399,3 +1400,35 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) *info = data; return 0; } + +/** + * Extract port name, as a number, from sysfs or netlink information. + * + * @param[in] port_name_in + * String representing the port name. + * @param[out] port_name_out + * Port name as a number. + * + * @return + * true on success, false otherwise. + */ +bool +mlx5_translate_port_name(const char *port_name_in, int32_t *port_name_out) +{ + char pf_c1, pf_c2, vf_c1, vf_c2; + int32_t pf_num; + bool port_name_set = false; + + /* + * Check for port-name as a string of the form pf0vf0 + * (support kernel ver >= 5.0) + */ + port_name_set = (sscanf(port_name_in, "%c%c%d%c%c%d", &pf_c1, &pf_c2, + &pf_num, &vf_c1, &vf_c2, port_name_out) == 6); + if (!port_name_set) { + /* Check for port-name as a number (support kernel ver < 5.0 */ + port_name_set = + (sscanf(port_name_in, "%d", port_name_out) == 1); + } + return port_name_set; +} diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c index 0bf6845..5fb34e6 100644 --- a/drivers/net/mlx5/mlx5_nl.c +++ b/drivers/net/mlx5/mlx5_nl.c @@ -849,7 +849,6 @@ struct mlx5_nl_ifindex_data { while (off < nh->nlmsg_len) { struct rtattr *ra = (void *)((uintptr_t)nh + off); void *payload = RTA_DATA(ra); - char *end; unsigned int i; if (ra->rta_len > nh->nlmsg_len - off) @@ -859,12 +858,9 @@ struct mlx5_nl_ifindex_data { num_vf_set = true; break; case IFLA_PHYS_PORT_NAME: - errno = 0; - info.port_name = strtol(payload, &end, 0); - if (errno || - (size_t)(end - (char *)payload) != strlen(payload)) - goto error; - port_name_set = true; + port_name_set = + mlx5_translate_port_name((char *)payload, + &info.port_name); break; case IFLA_PHYS_SWITCH_ID: info.switch_id = 0;