From patchwork Thu Feb 15 08:47:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?N=C3=A9lio_Laranjeiro?= X-Patchwork-Id: 35185 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 CB6931B33B; Thu, 15 Feb 2018 09:46:49 +0100 (CET) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id D021C1B321 for ; Thu, 15 Feb 2018 09:46:48 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id w77so2493747wrc.6 for ; Thu, 15 Feb 2018 00:46:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=LFDoHMFQp4YstbmcA4PJ4App4gEGh5DXm74Z0A/iPy4=; b=eL7dPWqn42YcfQ/RCBMLKyoSQneH0IvUwXUAULJreu4ubk5B+R4fL5MkoPcRbCf8LB o5ZoXlc4WH0n0NNpymk74i/jVC/4zmRV28E32/HyFxYVKB/TVejdK/hXFKnT0XZxwKOb XhTLpBaP+NCfdukbQHUZ4frrZIWPCIbEddojMMk/wa6s4UYm9PYCr0KfFNSw5E4C6gNk H5Gg+sShDbJQK9NI1RiA9rq2Mha0Op/NMX7UqCanIhsMlqEBHTphMzYVegMMZ0FCJIqQ H7bn/U4hYtL2D9badQuXG0jpU4u6LYOeKNC0UcBVvh4Zk9bYmuNc6NPlIac7Z0a76blv dVgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=LFDoHMFQp4YstbmcA4PJ4App4gEGh5DXm74Z0A/iPy4=; b=Ctx8YgYYbw+it6u019B5MkRg00MKa5Y1SeBDvr0kW8gcQ4cGsRhH+9txvTivELoVGb HJVWQTEP2kTzN2X072429gmmKaEURYobcYxWQ/2oGV//DlIeWAVAk2vpmCk+f4eLVz1j 6gFX9yCoW+YR45xmVDCul6jujPWOm45Wk7Wpt3cNcJnRcg5XslartH4Uzq8StruXh/2E HRRWKhrVTET1lxhgTfJXgIdElNEu+WG8HJmUL90XGdklatJ07MomfO/iEjA1uNthRGDv MXSSCex1LOavpD7vEeJ+309HbIFJV0WxF4BawwMvXu2NcR41QNODGfy5umRvHrbF+viN Sj0g== X-Gm-Message-State: APf1xPA/QuOXlugL1W/gpfNEIF0dd71beXu82Oy7B97wiNSgmzfyPsDj 5GmtAyBok4lPsG2Cu5aI2YtE6bzXuw== X-Google-Smtp-Source: AH8x227kAejDAjhQ7uRmGONtQG9kuLZ6Bk+XwdghLpFKqX81+E9I8kBn9P+hqDkOKDwjBC38ducL1Q== X-Received: by 10.223.160.157 with SMTP id m29mr1679428wrm.119.1518684408365; Thu, 15 Feb 2018 00:46:48 -0800 (PST) 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 42sm3965186wrx.92.2018.02.15.00.46.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 00:46:47 -0800 (PST) From: Nelio Laranjeiro To: dev@dpdk.org Cc: Adrien Mazarguil , Yongseok Koh Date: Thu, 15 Feb 2018 09:47:27 +0100 Message-Id: <21fb91002768a627d9c7f3d81e0c8a12fbf6811f.1518684427.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH 1/2] net/mlx5: add kernel version function 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" Use a function to retrieve the version of the kernel. Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_ethdev.c | 13 +++++-------- drivers/net/mlx5/mlx5_utils.h | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index b73cb53df..0ce9f438a 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -18,11 +18,9 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -715,15 +713,14 @@ int priv_link_update(struct priv *priv, int wait_to_complete) { struct rte_eth_dev *dev = priv->dev; - struct utsname utsname; - int ver[3]; int ret; struct rte_eth_link dev_link = dev->data->dev_link; + unsigned int current_version = mlx5_kernel_version(); + int use_new_api = current_version > 0 ? + current_version >= KERNEL_VERSION(4, 9, 0) : + 0; - if (uname(&utsname) == -1 || - sscanf(utsname.release, "%d.%d.%d", - &ver[0], &ver[1], &ver[2]) != 3 || - KERNEL_VERSION(ver[0], ver[1], ver[2]) < KERNEL_VERSION(4, 9, 0)) + if (use_new_api) ret = mlx5_link_update_unlocked_gset(dev, wait_to_complete); else ret = mlx5_link_update_unlocked_gs(dev, wait_to_complete); diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h index e1bfb9cd9..bd179ed21 100644 --- a/drivers/net/mlx5/mlx5_utils.h +++ b/drivers/net/mlx5/mlx5_utils.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "mlx5_defs.h" @@ -159,4 +161,28 @@ log2above(unsigned int v) return l + r; } +/** + * retrieve the current kernel version. + * + * @return + * the current kernel version or negative errno on error. + */ +static inline unsigned int +mlx5_kernel_version(void) +{ + struct utsname utsname; + int ver[3]; + int ret; + + ret = uname(&utsname); + if (ret == -1) + goto error; + ret = sscanf(utsname.release, "%d.%d.%d", &ver[0], &ver[1], &ver[2]); + if (ret != 3) + goto error; + return KERNEL_VERSION(ver[0], ver[1], ver[2]); +error: + return -errno; +} + #endif /* RTE_PMD_MLX5_UTILS_H_ */