patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] net/mlx5: use bond index for netdev operations
@ 2020-09-15  3:05 Xueming Li
  2020-09-21  9:29 ` Slava Ovsiienko
  2020-09-23  7:38 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh
  0 siblings, 2 replies; 3+ messages in thread
From: Xueming Li @ 2020-09-15  3:05 UTC (permalink / raw)
  To: Matan Azrad, Viacheslav Ovsiienko; +Cc: dev, Asaf Penso, xuemingl, stable

In case of bonding, device ifindex was detected as the PF ifindex, so
any operation using ifindex applied to PF instead of the bond device.
These operations includes MTU get/set, up/down and mac address
manipulation, etc.

This patch detects bond interface ifindex and name for PF that join a
bond interface, uses it by default for netdev operations.

Cc: stable@dpdk.org
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 56 +++++++++++++++++++++++++
 drivers/net/mlx5/linux/mlx5_os.c        | 13 ++++++
 drivers/net/mlx5/mlx5.h                 |  4 ++
 drivers/net/mlx5/mlx5_ethdev.c          |  2 +-
 4 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 7256c1bcfe..593b0d08ac 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -151,6 +151,10 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])
 
 	MLX5_ASSERT(priv);
 	MLX5_ASSERT(priv->sh);
+	if (priv->bond_ifindex > 0) {
+		memcpy(ifname, priv->bond_name, IF_NAMESIZE);
+		return 0;
+	}
 	ifindex = mlx5_ifindex(dev);
 	if (!ifindex) {
 		if (!priv->representor)
@@ -1101,6 +1105,58 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
 	return 0;
 }
 
+/**
+ * Get bond information associated with network interface.
+ *
+ * @param pf_ifindex
+ *   Network interface index of bond slave interface
+ * @param[out] ifindex
+ *   Pointer to bond ifindex.
+ * @param[out] ifname
+ *   Pointer to bond ifname.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
+		     char *ifname)
+{
+	char name[IF_NAMESIZE];
+	FILE *file;
+	unsigned int index;
+	int ret;
+
+	if (!if_indextoname(pf_ifindex, name) || !strlen(name)) {
+		rte_errno = errno;
+		return -rte_errno;
+	}
+	MKSTR(bond_if, "/sys/class/net/%s/master/ifindex", name);
+	/* read bond ifindex */
+	file = fopen(bond_if, "rb");
+	if (file == NULL) {
+		rte_errno = errno;
+		return -rte_errno;
+	}
+	ret = fscanf(file, "%u", &index);
+	fclose(file);
+	if (ret <= 0) {
+		rte_errno = errno;
+		return -rte_errno;
+	}
+	if (ifindex)
+		*ifindex = index;
+
+	/* read bond device name from symbol link */
+	if (ifname) {
+		if (!if_indextoname(index, ifname)) {
+			rte_errno = errno;
+			return -rte_errno;
+		}
+	}
+	return 0;
+}
+
 /**
  * DPDK callback to retrieve plug-in module EEPROM information (type and size).
  *
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 5f1e9520f7..b4c80d7af0 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1168,6 +1168,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 	 */
 	MLX5_ASSERT(spawn->ifindex);
 	priv->if_index = spawn->ifindex;
+	if (priv->pf_bond >= 0 && priv->master) {
+		/* Get bond interface info */
+		err = mlx5_sysfs_bond_info(priv->if_index,
+				     &priv->bond_ifindex,
+				     priv->bond_name);
+		if (err)
+			DRV_LOG(ERR, "unable to get bond info: %s",
+				strerror(rte_errno));
+		else
+			DRV_LOG(INFO, "PF device %u, bond device %u(%s)",
+				priv->if_index, priv->bond_ifindex,
+				priv->bond_name);
+	}
 	eth_dev->data->dev_private = priv;
 	priv->dev_data = eth_dev->data;
 	eth_dev->data->mac_addrs = priv->mac;
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 1a7c712f2c..c62643ae62 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -771,6 +771,8 @@ struct mlx5_priv {
 	int32_t representor_id; /* Port representor identifier. */
 	int32_t pf_bond; /* >=0 means PF index in bonding configuration. */
 	unsigned int if_index; /* Associated kernel network device index. */
+	uint32_t bond_ifindex; /**< Bond interface index. */
+	char bond_name[IF_NAMESIZE]; /**< Bond interface name. */
 	/* RX/TX queues. */
 	unsigned int rxqs_n; /* RX queues array size. */
 	unsigned int txqs_n; /* TX queues array size. */
@@ -897,6 +899,8 @@ void mlx5_translate_port_name(const char *port_name_in,
 			      struct mlx5_switch_info *port_info_out);
 void mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
 				   rte_intr_callback_fn cb_fn, void *cb_arg);
+int mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
+			 char *ifname);
 int mlx5_get_module_info(struct rte_eth_dev *dev,
 			 struct rte_eth_dev_module_info *modinfo);
 int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index cefb45064e..48121929de 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -43,7 +43,7 @@ mlx5_ifindex(const struct rte_eth_dev *dev)
 
 	MLX5_ASSERT(priv);
 	MLX5_ASSERT(priv->if_index);
-	ifindex = priv->if_index;
+	ifindex = priv->bond_ifindex > 0 ? priv->bond_ifindex : priv->if_index;
 	if (!ifindex)
 		rte_errno = ENXIO;
 	return ifindex;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-stable] [PATCH] net/mlx5: use bond index for netdev operations
  2020-09-15  3:05 [dpdk-stable] [PATCH] net/mlx5: use bond index for netdev operations Xueming Li
@ 2020-09-21  9:29 ` Slava Ovsiienko
  2020-09-23  7:38 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Slava Ovsiienko @ 2020-09-21  9:29 UTC (permalink / raw)
  To: Xueming(Steven) Li, Matan Azrad
  Cc: dev, Asaf Penso, Xueming(Steven) Li, stable

> -----Original Message-----
> From: Xueming Li <xuemingl@nvidia.com>
> Sent: Tuesday, September 15, 2020 6:06
> To: Matan Azrad <matan@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>
> Cc: dev@dpdk.org; Asaf Penso <asafp@nvidia.com>; Xueming(Steven) Li
> <xuemingl@nvidia.com>; stable@dpdk.org
> Subject: [PATCH] net/mlx5: use bond index for netdev operations
> 
> In case of bonding, device ifindex was detected as the PF ifindex, so any
> operation using ifindex applied to PF instead of the bond device.
> These operations includes MTU get/set, up/down and mac address
> manipulation, etc.
> 
> This patch detects bond interface ifindex and name for PF that join a bond
> interface, uses it by default for netdev operations.
> 
> Cc: stable@dpdk.org
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>

Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH] net/mlx5: use bond index for netdev operations
  2020-09-15  3:05 [dpdk-stable] [PATCH] net/mlx5: use bond index for netdev operations Xueming Li
  2020-09-21  9:29 ` Slava Ovsiienko
@ 2020-09-23  7:38 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Raslan Darawsheh @ 2020-09-23  7:38 UTC (permalink / raw)
  To: Xueming(Steven) Li, Matan Azrad, Slava Ovsiienko
  Cc: dev, Asaf Penso, Xueming(Steven) Li, stable

Hi,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Xueming Li
> Sent: Tuesday, September 15, 2020 6:06 AM
> To: Matan Azrad <matan@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>
> Cc: dev@dpdk.org; Asaf Penso <asafp@nvidia.com>; Xueming(Steven) Li
> <xuemingl@nvidia.com>; stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/mlx5: use bond index for netdev
> operations
> 
> In case of bonding, device ifindex was detected as the PF ifindex, so
> any operation using ifindex applied to PF instead of the bond device.
> These operations includes MTU get/set, up/down and mac address
> manipulation, etc.
> 
> This patch detects bond interface ifindex and name for PF that join a
> bond interface, uses it by default for netdev operations.
> 
> Cc: stable@dpdk.org
> Signed-off-by: Xueming Li <xuemingl@nvidia.com>
> ---
>  drivers/net/mlx5/linux/mlx5_ethdev_os.c | 56
> +++++++++++++++++++++++++
>  drivers/net/mlx5/linux/mlx5_os.c        | 13 ++++++
>  drivers/net/mlx5/mlx5.h                 |  4 ++
>  drivers/net/mlx5/mlx5_ethdev.c          |  2 +-
>  4 files changed, 74 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
> b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
> index 7256c1bcfe..593b0d08ac 100644
> --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
> +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
> @@ -151,6 +151,10 @@ mlx5_get_ifname(const struct rte_eth_dev *dev,
> char (*ifname)[IF_NAMESIZE])
> 
>  	MLX5_ASSERT(priv);
>  	MLX5_ASSERT(priv->sh);
> +	if (priv->bond_ifindex > 0) {
> +		memcpy(ifname, priv->bond_name, IF_NAMESIZE);
> +		return 0;
> +	}
>  	ifindex = mlx5_ifindex(dev);
>  	if (!ifindex) {
>  		if (!priv->representor)
> @@ -1101,6 +1105,58 @@ mlx5_sysfs_switch_info(unsigned int ifindex,
> struct mlx5_switch_info *info)
>  	return 0;
>  }
> 
> +/**
> + * Get bond information associated with network interface.
> + *
> + * @param pf_ifindex
> + *   Network interface index of bond slave interface
> + * @param[out] ifindex
> + *   Pointer to bond ifindex.
> + * @param[out] ifname
> + *   Pointer to bond ifname.
> + *
> + * @return
> + *   0 on success, a negative errno value otherwise and rte_errno is set.
> + */
> +int
> +mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
> +		     char *ifname)
> +{
> +	char name[IF_NAMESIZE];
> +	FILE *file;
> +	unsigned int index;
> +	int ret;
> +
> +	if (!if_indextoname(pf_ifindex, name) || !strlen(name)) {
> +		rte_errno = errno;
> +		return -rte_errno;
> +	}
> +	MKSTR(bond_if, "/sys/class/net/%s/master/ifindex", name);
> +	/* read bond ifindex */
> +	file = fopen(bond_if, "rb");
> +	if (file == NULL) {
> +		rte_errno = errno;
> +		return -rte_errno;
> +	}
> +	ret = fscanf(file, "%u", &index);
> +	fclose(file);
> +	if (ret <= 0) {
> +		rte_errno = errno;
> +		return -rte_errno;
> +	}
> +	if (ifindex)
> +		*ifindex = index;
> +
> +	/* read bond device name from symbol link */
> +	if (ifname) {
> +		if (!if_indextoname(index, ifname)) {
> +			rte_errno = errno;
> +			return -rte_errno;
> +		}
> +	}
> +	return 0;
> +}
> +
>  /**
>   * DPDK callback to retrieve plug-in module EEPROM information (type and
> size).
>   *
> diff --git a/drivers/net/mlx5/linux/mlx5_os.c
> b/drivers/net/mlx5/linux/mlx5_os.c
> index 5f1e9520f7..b4c80d7af0 100644
> --- a/drivers/net/mlx5/linux/mlx5_os.c
> +++ b/drivers/net/mlx5/linux/mlx5_os.c
> @@ -1168,6 +1168,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
>  	 */
>  	MLX5_ASSERT(spawn->ifindex);
>  	priv->if_index = spawn->ifindex;
> +	if (priv->pf_bond >= 0 && priv->master) {
> +		/* Get bond interface info */
> +		err = mlx5_sysfs_bond_info(priv->if_index,
> +				     &priv->bond_ifindex,
> +				     priv->bond_name);
> +		if (err)
> +			DRV_LOG(ERR, "unable to get bond info: %s",
> +				strerror(rte_errno));
> +		else
> +			DRV_LOG(INFO, "PF device %u, bond device
> %u(%s)",
> +				priv->if_index, priv->bond_ifindex,
> +				priv->bond_name);
> +	}
>  	eth_dev->data->dev_private = priv;
>  	priv->dev_data = eth_dev->data;
>  	eth_dev->data->mac_addrs = priv->mac;
> diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
> index 1a7c712f2c..c62643ae62 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -771,6 +771,8 @@ struct mlx5_priv {
>  	int32_t representor_id; /* Port representor identifier. */
>  	int32_t pf_bond; /* >=0 means PF index in bonding configuration. */
>  	unsigned int if_index; /* Associated kernel network device index. */
> +	uint32_t bond_ifindex; /**< Bond interface index. */
> +	char bond_name[IF_NAMESIZE]; /**< Bond interface name. */
>  	/* RX/TX queues. */
>  	unsigned int rxqs_n; /* RX queues array size. */
>  	unsigned int txqs_n; /* TX queues array size. */
> @@ -897,6 +899,8 @@ void mlx5_translate_port_name(const char
> *port_name_in,
>  			      struct mlx5_switch_info *port_info_out);
>  void mlx5_intr_callback_unregister(const struct rte_intr_handle *handle,
>  				   rte_intr_callback_fn cb_fn, void *cb_arg);
> +int mlx5_sysfs_bond_info(unsigned int pf_ifindex, unsigned int *ifindex,
> +			 char *ifname);
>  int mlx5_get_module_info(struct rte_eth_dev *dev,
>  			 struct rte_eth_dev_module_info *modinfo);
>  int mlx5_get_module_eeprom(struct rte_eth_dev *dev,
> diff --git a/drivers/net/mlx5/mlx5_ethdev.c
> b/drivers/net/mlx5/mlx5_ethdev.c
> index cefb45064e..48121929de 100644
> --- a/drivers/net/mlx5/mlx5_ethdev.c
> +++ b/drivers/net/mlx5/mlx5_ethdev.c
> @@ -43,7 +43,7 @@ mlx5_ifindex(const struct rte_eth_dev *dev)
> 
>  	MLX5_ASSERT(priv);
>  	MLX5_ASSERT(priv->if_index);
> -	ifindex = priv->if_index;
> +	ifindex = priv->bond_ifindex > 0 ? priv->bond_ifindex : priv-
> >if_index;
>  	if (!ifindex)
>  		rte_errno = ENXIO;
>  	return ifindex;
> --
> 2.25.1

Patch applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-23  7:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15  3:05 [dpdk-stable] [PATCH] net/mlx5: use bond index for netdev operations Xueming Li
2020-09-21  9:29 ` Slava Ovsiienko
2020-09-23  7:38 ` [dpdk-stable] [dpdk-dev] " Raslan Darawsheh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).