From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00056.outbound.protection.outlook.com [40.107.0.56]) by dpdk.org (Postfix) with ESMTP id 3FEF81B337 for ; Sun, 11 Feb 2018 12:55:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=32rfhhzVQjmQ/uA2hKyStF6rwPAfiloVfQvEBIsqzA8=; b=mpNu6mGdO1c+1eSYqIlIkAageu9+NmPSMsim5dN2MJgK9AmDjrqZ98jmbXbP7YqyaC80UXel7MO6iu74W2wYIs+3pOsId09MJ2kK1QVMGSayhDotQo0AWG0Xqe8tCFFNFU7GllB1blbyu80g0yplal/WSTW1CVCpK2qFwZor3tY= Received: from VI1PR05MB3149.eurprd05.prod.outlook.com (10.170.237.142) by VI1PR05MB3487.eurprd05.prod.outlook.com (10.170.239.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Sun, 11 Feb 2018 11:55:44 +0000 Received: from VI1PR05MB3149.eurprd05.prod.outlook.com ([fe80::cd00:54ee:63a8:937c]) by VI1PR05MB3149.eurprd05.prod.outlook.com ([fe80::cd00:54ee:63a8:937c%13]) with mapi id 15.20.0464.016; Sun, 11 Feb 2018 11:55:44 +0000 From: Shahaf Shuler To: Adrien Mazarguil CC: =?iso-8859-1?Q?N=E9lio_Laranjeiro?= , "Yongseok Koh" , "dev@dpdk.org" Thread-Topic: [PATCH v1] net/mlx: control netdevices through ioctl only Thread-Index: AQHToPsX66Z96xFR80eYY8xncJwoJ6OfFz1g Date: Sun, 11 Feb 2018 11:55:44 +0000 Message-ID: References: <20180208163538.22407-1-adrien.mazarguil@6wind.com> In-Reply-To: <20180208163538.22407-1-adrien.mazarguil@6wind.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shahafs@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR05MB3487; 7:q1ky8m5pVTEJkfhEhhZjBxSaynDwi8D6Qozs5lD3srblUG+VyGZjE8+pQATxm/n9uFhpjUlDrSI9Vhspaa2udlC9TlXrJkpdSLrvZCVLOqFzDOqQOAwJhF7J2sCtUe3c6t1ey/bsHlF1RIKaINwkIrGGbW4j6DXZfbypNX6MuEPzQxgXrb5H9aQv4TXCodarF6SGI1BkL0qGSe/Ryq8mXoixA7LNzXHi0dqz4DD5yUqPku/E8FFj3MoVd+cLndZc x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 54170708-1484-46ea-b9ac-08d571466207 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020); SRVR:VI1PR05MB3487; x-ms-traffictypediagnostic: VI1PR05MB3487: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(278428928389397); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3002001)(3231101)(944501161)(10201501046)(93006095)(93001095)(6055026)(6041288)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR05MB3487; BCL:0; PCL:0; RULEID:; SRVR:VI1PR05MB3487; x-forefront-prvs: 058043A388 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39380400002)(376002)(366004)(396003)(346002)(39860400002)(199004)(189003)(186003)(105586002)(33656002)(106356001)(66066001)(14454004)(316002)(25786009)(54906003)(6246003)(68736007)(478600001)(4326008)(81166006)(8676002)(81156014)(5250100002)(8936002)(6506007)(59450400001)(102836004)(76176011)(26005)(7696005)(99286004)(3660700001)(6436002)(3280700002)(6116002)(2906002)(3846002)(53946003)(229853002)(2950100002)(53936002)(2900100001)(9686003)(55016002)(7736002)(74316002)(305945005)(6916009)(86362001)(5660300001)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB3487; H:VI1PR05MB3149.eurprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 5YssngbseiJT3G8rSTg0im8vI7udPoMXAIr72IEj27IsMGrfeK+ouKe64uIUpzSYbJUZ8g43anwy5W0W5WO8WQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54170708-1484-46ea-b9ac-08d571466207 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Feb 2018 11:55:44.7709 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB3487 Subject: Re: [dpdk-dev] [PATCH v1] net/mlx: control netdevices through ioctl only 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: Sun, 11 Feb 2018 11:55:47 -0000 Hi Adrien, Small doc issues. Thursday, February 8, 2018 6:37 PM, Adrien Mazarguil: > Subject: [PATCH v1] net/mlx: control netdevices through ioctl only >=20 > Several control operations implemented by these PMDs affect netdevices > through sysfs, itself subject to file system permission checks enforced b= y the > kernel, which limits their use for most purposes to applications running = with > root privileges. >=20 > Since performing the same operations through ioctl() requires fewer > capabilities (only CAP_NET_ADMIN) and given the remaining operations are > already implemented this way, this patch standardizes on ioctl() and gets= rid > of redundant code. >=20 > Signed-off-by: Adrien Mazarguil > --- > drivers/net/mlx4/mlx4_ethdev.c | 192 ++------------------------- > drivers/net/mlx5/mlx5.h | 2 - > drivers/net/mlx5/mlx5_ethdev.c | 255 ++++-------------------------------= - > drivers/net/mlx5/mlx5_stats.c | 28 +++- > 4 files changed, 63 insertions(+), 414 deletions(-) >=20 > diff --git a/drivers/net/mlx4/mlx4_ethdev.c > b/drivers/net/mlx4/mlx4_ethdev.c index 3bc692731..fbeef16c8 100644 > --- a/drivers/net/mlx4/mlx4_ethdev.c > +++ b/drivers/net/mlx4/mlx4_ethdev.c > @@ -132,167 +132,6 @@ mlx4_get_ifname(const struct priv *priv, char > (*ifname)[IF_NAMESIZE]) } >=20 > /** > - * Read from sysfs entry. > - * > - * @param[in] priv > - * Pointer to private structure. > - * @param[in] entry > - * Entry name relative to sysfs path. > - * @param[out] buf > - * Data output buffer. > - * @param size > - * Buffer size. > - * > - * @return > - * Number of bytes read on success, negative errno value otherwise and > - * rte_errno is set. > - */ > -static int > -mlx4_sysfs_read(const struct priv *priv, const char *entry, > - char *buf, size_t size) > -{ > - char ifname[IF_NAMESIZE]; > - FILE *file; > - int ret; > - > - ret =3D mlx4_get_ifname(priv, &ifname); > - if (ret) > - return ret; > - > - MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device- > >ibdev_path, > - ifname, entry); > - > - file =3D fopen(path, "rb"); > - if (file =3D=3D NULL) { > - rte_errno =3D errno; > - return -rte_errno; > - } > - ret =3D fread(buf, 1, size, file); > - if ((size_t)ret < size && ferror(file)) { > - rte_errno =3D EIO; > - ret =3D -rte_errno; > - } else { > - ret =3D size; > - } > - fclose(file); > - return ret; > -} > - > -/** > - * Write to sysfs entry. > - * > - * @param[in] priv > - * Pointer to private structure. > - * @param[in] entry > - * Entry name relative to sysfs path. > - * @param[in] buf > - * Data buffer. > - * @param size > - * Buffer size. > - * > - * @return > - * Number of bytes written on success, negative errno value otherwise = and > - * rte_errno is set. > - */ > -static int > -mlx4_sysfs_write(const struct priv *priv, const char *entry, > - char *buf, size_t size) > -{ > - char ifname[IF_NAMESIZE]; > - FILE *file; > - int ret; > - > - ret =3D mlx4_get_ifname(priv, &ifname); > - if (ret) > - return ret; > - > - MKSTR(path, "%s/device/net/%s/%s", priv->ctx->device- > >ibdev_path, > - ifname, entry); > - > - file =3D fopen(path, "wb"); > - if (file =3D=3D NULL) { > - rte_errno =3D errno; > - return -rte_errno; > - } > - ret =3D fwrite(buf, 1, size, file); > - if ((size_t)ret < size || ferror(file)) { > - rte_errno =3D EIO; > - ret =3D -rte_errno; > - } else { > - ret =3D size; > - } > - fclose(file); > - return ret; > -} > - > -/** > - * Get unsigned long sysfs property. > - * > - * @param priv > - * Pointer to private structure. > - * @param[in] name > - * Entry name relative to sysfs path. > - * @param[out] value > - * Value output buffer. > - * > - * @return > - * 0 on success, negative errno value otherwise and rte_errno is set. > - */ > -static int > -mlx4_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long > *value) -{ > - int ret; > - unsigned long value_ret; > - char value_str[32]; > - > - ret =3D mlx4_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1))= ; > - if (ret < 0) { > - DEBUG("cannot read %s value from sysfs: %s", > - name, strerror(rte_errno)); > - return ret; > - } > - value_str[ret] =3D '\0'; > - errno =3D 0; > - value_ret =3D strtoul(value_str, NULL, 0); > - if (errno) { > - rte_errno =3D errno; > - DEBUG("invalid %s value `%s': %s", name, value_str, > - strerror(rte_errno)); > - return -rte_errno; > - } > - *value =3D value_ret; > - return 0; > -} > - > -/** > - * Set unsigned long sysfs property. > - * > - * @param priv > - * Pointer to private structure. > - * @param[in] name > - * Entry name relative to sysfs path. > - * @param value > - * Value to set. > - * > - * @return > - * 0 on success, negative errno value otherwise and rte_errno is set. > - */ > -static int > -mlx4_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long > value) -{ > - int ret; > - MKSTR(value_str, "%lu", value); > - > - ret =3D mlx4_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1)= ); > - if (ret < 0) { > - DEBUG("cannot write %s `%s' (%lu) to sysfs: %s", > - name, value_str, value, strerror(rte_errno)); > - return ret; > - } > - return 0; > -} > - > -/** > * Perform ifreq ioctl() on associated Ethernet device. > * > * @param[in] priv > @@ -361,12 +200,12 @@ mlx4_get_mac(struct priv *priv, uint8_t > (*mac)[ETHER_ADDR_LEN]) int mlx4_mtu_get(struct priv *priv, uint16_t > *mtu) { > - unsigned long ulong_mtu =3D 0; > - int ret =3D mlx4_get_sysfs_ulong(priv, "mtu", &ulong_mtu); > + struct ifreq request; > + int ret =3D mlx4_ifreq(priv, SIOCGIFMTU, &request); >=20 > if (ret) > return ret; Function documentation is : "0 on success, negative errno value otherwise a= nd rte_errno is set." Per my understating ioctl returns -1 on error with errno set.=20 > - *mtu =3D ulong_mtu; > + *mtu =3D request.ifr_mtu; > return 0; > } >=20 > @@ -385,20 +224,13 @@ int > mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) { > struct priv *priv =3D dev->data->dev_private; > - uint16_t new_mtu; > - int ret =3D mlx4_set_sysfs_ulong(priv, "mtu", mtu); > + struct ifreq request =3D { .ifr_mtu =3D mtu, }; > + int ret =3D mlx4_ifreq(priv, SIOCSIFMTU, &request); >=20 > if (ret) > return ret; Also here. > - ret =3D mlx4_mtu_get(priv, &new_mtu); > - if (ret) > - return ret; > - if (new_mtu =3D=3D mtu) { > - priv->mtu =3D mtu; > - return 0; > - } > - rte_errno =3D EINVAL; > - return -rte_errno; > + priv->mtu =3D mtu; > + return 0; > } >=20 > /** > @@ -417,14 +249,14 @@ mlx4_mtu_set(struct rte_eth_dev *dev, uint16_t > mtu) static int mlx4_set_flags(struct priv *priv, unsigned int keep, un= signed > int flags) { > - unsigned long tmp =3D 0; > - int ret =3D mlx4_get_sysfs_ulong(priv, "flags", &tmp); > + struct ifreq request; > + int ret =3D mlx4_ifreq(priv, SIOCGIFFLAGS, &request); >=20 > if (ret) > return ret; And here. > - tmp &=3D keep; > - tmp |=3D (flags & (~keep)); > - return mlx4_set_sysfs_ulong(priv, "flags", tmp); > + request.ifr_flags &=3D keep; > + request.ifr_flags |=3D flags & ~keep; > + return mlx4_ifreq(priv, SIOCSIFFLAGS, &request); > } >=20 > /** > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > 965c19f21..da44faaf4 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -209,8 +209,6 @@ struct priv *mlx5_get_priv(struct rte_eth_dev *dev); > int mlx5_is_secondary(void); int priv_get_ifname(const struct priv *, ch= ar > (*)[IF_NAMESIZE]); int priv_ifreq(const struct priv *, int req, struct i= freq *); - > int priv_is_ib_cntr(const char *); -int priv_get_cntr_sysfs(struct priv *= , const > char *, uint64_t *); int priv_get_num_vfs(struct priv *, uint16_t *); i= nt > priv_get_mtu(struct priv *, uint16_t *); int priv_set_flags(struct priv = *, > unsigned int, unsigned int); diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 666507691..b73cb53df 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -7,6 +7,7 @@ >=20 > #include > #include > +#include > #include > #include > #include > @@ -173,181 +174,6 @@ priv_get_ifname(const struct priv *priv, char > (*ifname)[IF_NAMESIZE]) } >=20 > /** > - * Check if the counter is located on ib counters file. > - * > - * @param[in] cntr > - * Counter name. > - * > - * @return > - * 1 if counter is located on ib counters file , 0 otherwise. > - */ > -int > -priv_is_ib_cntr(const char *cntr) > -{ > - if (!strcmp(cntr, "out_of_buffer")) > - return 1; > - return 0; > -} > - > -/** > - * Read from sysfs entry. > - * > - * @param[in] priv > - * Pointer to private structure. > - * @param[in] entry > - * Entry name relative to sysfs path. > - * @param[out] buf > - * Data output buffer. > - * @param size > - * Buffer size. > - * > - * @return > - * 0 on success, -1 on failure and errno is set. > - */ > -static int > -priv_sysfs_read(const struct priv *priv, const char *entry, > - char *buf, size_t size) > -{ > - char ifname[IF_NAMESIZE]; > - FILE *file; > - int ret; > - int err; > - > - if (priv_get_ifname(priv, &ifname)) > - return -1; > - > - if (priv_is_ib_cntr(entry)) { > - MKSTR(path, "%s/ports/1/hw_counters/%s", > - priv->ibdev_path, entry); > - file =3D fopen(path, "rb"); > - } else { > - MKSTR(path, "%s/device/net/%s/%s", > - priv->ibdev_path, ifname, entry); > - file =3D fopen(path, "rb"); > - } > - if (file =3D=3D NULL) > - return -1; > - ret =3D fread(buf, 1, size, file); > - err =3D errno; > - if (((size_t)ret < size) && (ferror(file))) > - ret =3D -1; > - else > - ret =3D size; > - fclose(file); > - errno =3D err; > - return ret; > -} > - > -/** > - * Write to sysfs entry. > - * > - * @param[in] priv > - * Pointer to private structure. > - * @param[in] entry > - * Entry name relative to sysfs path. > - * @param[in] buf > - * Data buffer. > - * @param size > - * Buffer size. > - * > - * @return > - * 0 on success, -1 on failure and errno is set. > - */ > -static int > -priv_sysfs_write(const struct priv *priv, const char *entry, > - char *buf, size_t size) > -{ > - char ifname[IF_NAMESIZE]; > - FILE *file; > - int ret; > - int err; > - > - if (priv_get_ifname(priv, &ifname)) > - return -1; > - > - MKSTR(path, "%s/device/net/%s/%s", priv->ibdev_path, ifname, > entry); > - > - file =3D fopen(path, "wb"); > - if (file =3D=3D NULL) > - return -1; > - ret =3D fwrite(buf, 1, size, file); > - err =3D errno; > - if (((size_t)ret < size) || (ferror(file))) > - ret =3D -1; > - else > - ret =3D size; > - fclose(file); > - errno =3D err; > - return ret; > -} > - > -/** > - * Get unsigned long sysfs property. > - * > - * @param priv > - * Pointer to private structure. > - * @param[in] name > - * Entry name relative to sysfs path. > - * @param[out] value > - * Value output buffer. > - * > - * @return > - * 0 on success, -1 on failure and errno is set. > - */ > -static int > -priv_get_sysfs_ulong(struct priv *priv, const char *name, unsigned long > *value) -{ > - int ret; > - unsigned long value_ret; > - char value_str[32]; > - > - ret =3D priv_sysfs_read(priv, name, value_str, (sizeof(value_str) - 1))= ; > - if (ret =3D=3D -1) { > - DEBUG("cannot read %s value from sysfs: %s", > - name, strerror(errno)); > - return -1; > - } > - value_str[ret] =3D '\0'; > - errno =3D 0; > - value_ret =3D strtoul(value_str, NULL, 0); > - if (errno) { > - DEBUG("invalid %s value `%s': %s", name, value_str, > - strerror(errno)); > - return -1; > - } > - *value =3D value_ret; > - return 0; > -} > - > -/** > - * Set unsigned long sysfs property. > - * > - * @param priv > - * Pointer to private structure. > - * @param[in] name > - * Entry name relative to sysfs path. > - * @param value > - * Value to set. > - * > - * @return > - * 0 on success, -1 on failure and errno is set. > - */ > -static int > -priv_set_sysfs_ulong(struct priv *priv, const char *name, unsigned long > value) -{ > - int ret; > - MKSTR(value_str, "%lu", value); > - > - ret =3D priv_sysfs_write(priv, name, value_str, (sizeof(value_str) - 1)= ); > - if (ret =3D=3D -1) { > - DEBUG("cannot write %s `%s' (%lu) to sysfs: %s", > - name, value_str, value, strerror(errno)); > - return -1; > - } > - return 0; > -} > - > -/** > * Perform ifreq ioctl() on associated Ethernet device. > * > * @param[in] priv > @@ -390,20 +216,25 @@ priv_get_num_vfs(struct priv *priv, uint16_t > *num_vfs) { > /* The sysfs entry name depends on the operating system. */ > const char **name =3D (const char *[]){ > - "device/sriov_numvfs", > - "device/mlx5_num_vfs", > + "sriov_numvfs", > + "mlx5_num_vfs", > NULL, > }; > - int ret; >=20 > do { > - unsigned long ulong_num_vfs; > + int n; > + FILE *file; > + MKSTR(path, "%s/device/%s", priv->ibdev_path, *name); >=20 > - ret =3D priv_get_sysfs_ulong(priv, *name, &ulong_num_vfs); > - if (!ret) > - *num_vfs =3D ulong_num_vfs; > - } while (*(++name) && ret); > - return ret; > + file =3D fopen(path, "rb"); > + if (!file) > + continue; > + n =3D fscanf(file, "%" SCNu16, num_vfs); > + fclose(file); > + if (n =3D=3D 1) > + return 0; > + } while (*(++name)); > + return -1; > } >=20 > /** > @@ -420,35 +251,12 @@ priv_get_num_vfs(struct priv *priv, uint16_t > *num_vfs) int priv_get_mtu(struct priv *priv, uint16_t *mtu) { > - unsigned long ulong_mtu; > + struct ifreq request; > + int ret =3D priv_ifreq(priv, SIOCGIFMTU, &request); >=20 > - if (priv_get_sysfs_ulong(priv, "mtu", &ulong_mtu) =3D=3D -1) > - return -1; > - *mtu =3D ulong_mtu; > - return 0; > -} > - > -/** > - * Read device counter from sysfs. > - * > - * @param priv > - * Pointer to private structure. > - * @param name > - * Counter name. > - * @param[out] cntr > - * Counter output buffer. > - * > - * @return > - * 0 on success, -1 on failure and errno is set. > - */ > -int > -priv_get_cntr_sysfs(struct priv *priv, const char *name, uint64_t *cntr)= -{ > - unsigned long ulong_ctr; > - > - if (priv_get_sysfs_ulong(priv, name, &ulong_ctr) =3D=3D -1) > - return -1; > - *cntr =3D ulong_ctr; > + if (ret) > + return ret; > + *mtu =3D request.ifr_mtu; > return 0; > } >=20 > @@ -466,15 +274,9 @@ priv_get_cntr_sysfs(struct priv *priv, const char > *name, uint64_t *cntr) static int priv_set_mtu(struct priv *priv, uint1= 6_t > mtu) { > - uint16_t new_mtu; > + struct ifreq request =3D { .ifr_mtu =3D mtu, }; >=20 > - if (priv_set_sysfs_ulong(priv, "mtu", mtu) || > - priv_get_mtu(priv, &new_mtu)) > - return -1; > - if (new_mtu =3D=3D mtu) > - return 0; > - errno =3D EINVAL; > - return -1; > + return priv_ifreq(priv, SIOCSIFMTU, &request); > } >=20 > /** > @@ -493,13 +295,14 @@ priv_set_mtu(struct priv *priv, uint16_t mtu) int > priv_set_flags(struct priv *priv, unsigned int keep, unsigned int flags) = { > - unsigned long tmp; > + struct ifreq request; > + int ret =3D priv_ifreq(priv, SIOCGIFFLAGS, &request); >=20 > - if (priv_get_sysfs_ulong(priv, "flags", &tmp) =3D=3D -1) > - return -1; > - tmp &=3D keep; > - tmp |=3D (flags & (~keep)); > - return priv_set_sysfs_ulong(priv, "flags", tmp); > + if (ret) > + return ret; > + request.ifr_flags &=3D keep; > + request.ifr_flags |=3D flags & ~keep; > + return priv_ifreq(priv, SIOCSIFFLAGS, &request); > } >=20 > /** > diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.= c > index 378472a70..eb9c65dcc 100644 > --- a/drivers/net/mlx5/mlx5_stats.c > +++ b/drivers/net/mlx5/mlx5_stats.c > @@ -3,8 +3,11 @@ > * Copyright 2015 Mellanox. > */ >=20 > +#include > #include > #include > +#include > +#include >=20 > #include > #include > @@ -19,6 +22,7 @@ struct mlx5_counter_ctrl { > char dpdk_name[RTE_ETH_XSTATS_NAME_SIZE]; > /* Name of the counter on the device table. */ > char ctr_name[RTE_ETH_XSTATS_NAME_SIZE]; > + uint32_t ib:1; /**< Nonzero for IB counters. */ > }; >=20 > static const struct mlx5_counter_ctrl mlx5_counters_init[] =3D { @@ -93,= 6 > +97,7 @@ static const struct mlx5_counter_ctrl mlx5_counters_init[] =3D { > { > .dpdk_name =3D "rx_out_of_buffer", > .ctr_name =3D "out_of_buffer", > + .ib =3D 1, > }, > { > .dpdk_name =3D "tx_packets_phy", > @@ -143,13 +148,24 @@ priv_read_dev_counters(struct priv *priv, uint64_t > *stats) > return -1; > } > for (i =3D 0; i !=3D xstats_n; ++i) { > - if (priv_is_ib_cntr(mlx5_counters_init[i].ctr_name)) > - priv_get_cntr_sysfs(priv, > - mlx5_counters_init[i].ctr_name, > - &stats[i]); > - else > + if (mlx5_counters_init[i].ib) { > + FILE *file; > + MKSTR(path, "%s/ports/1/hw_counters/%s", > + priv->ibdev_path, > + mlx5_counters_init[i].ctr_name); > + > + file =3D fopen(path, "rb"); > + if (file) { > + int n =3D fscanf(file, "%" SCNu64, &stats[i]); > + > + fclose(file); > + if (n !=3D 1) > + stats[i] =3D 0; > + } > + } else { > stats[i] =3D (uint64_t) > et_stats->data[xstats_ctrl- > >dev_table_idx[i]]; > + } > } > return 0; > } > @@ -232,7 +248,7 @@ priv_xstats_init(struct priv *priv) > } > } > for (j =3D 0; j !=3D xstats_n; ++j) { > - if (priv_is_ib_cntr(mlx5_counters_init[j].ctr_name)) > + if (mlx5_counters_init[j].ib) > continue; > if (xstats_ctrl->dev_table_idx[j] >=3D dev_stats_n) { > WARN("counter \"%s\" is not recognized", > -- > 2.11.0