From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adrien Mazarguil Subject: Re: [PATCH 1/2] net/mlx5: add kernel version function Date: Fri, 16 Feb 2018 11:48:48 +0100 Message-ID: <20180216104848.GB4256@6wind.com> References: <21fb91002768a627d9c7f3d81e0c8a12fbf6811f.1518684427.git.nelio.laranjeiro@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org, Yongseok Koh To: Nelio Laranjeiro Return-path: Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id 66CB51B28D for ; Fri, 16 Feb 2018 11:49:02 +0100 (CET) Received: by mail-wr0-f195.google.com with SMTP id f8so2435710wrh.8 for ; Fri, 16 Feb 2018 02:49:02 -0800 (PST) Content-Disposition: inline In-Reply-To: <21fb91002768a627d9c7f3d81e0c8a12fbf6811f.1518684427.git.nelio.laranjeiro@6wind.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Feb 15, 2018 at 09:47:27AM +0100, Nelio Laranjeiro wrote: > Use a function to retrieve the version of the kernel. > > Signed-off-by: Nelio Laranjeiro A couple of nits, please see below. > --- > 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 Looks like this one should remain; this file still uses KERNEL_VERSION(). > #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. > + */ Missing caps! > +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_ */ > -- > 2.11.0 > -- Adrien Mazarguil 6WIND