net/mlx5: link status change for bonding cases

Message ID 20240226120341.175710-1-haifeil@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: link status change for bonding cases |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Haifei Luo Feb. 26, 2024, 12:03 p.m. UTC
  The current implementation of mlx5_dev_interrupt_nl_cb routine first
compares if event netlink if_index belongs to the same device.
This is not fully correct for the bonding device since the bonding
master and slave interface netlink events indicate the bonding link
status change as well. Add check for if_index is related to the
bonding's master/slave.

The following step is that it compares the device link status before
and after the netlink event handling. There are also the bonding specifics
and it should compare the link status of the bonding master to detect
the actual status change.

Signed-off-by: Haifei Luo <haifeil@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 55 ++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 5 deletions(-)
  

Comments

Slava Ovsiienko Feb. 28, 2024, 5:47 p.m. UTC | #1
> -----Original Message-----
> From: Haifei Luo <haifeil@nvidia.com>
> Sent: Monday, February 26, 2024 2:04 PM
> To: Ori Kam <orika@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> Matan Azrad <matan@nvidia.com>; Shahaf Shuler <shahafs@nvidia.com>;
> Dariusz Sosnowski <dsosnowski@nvidia.com>; Suanming Mou
> <suanmingm@nvidia.com>
> Cc: dev@dpdk.org; NBU-Contact-Thomas Monjalon (EXTERNAL)
> <thomas@monjalon.net>; Wisam Jaddo <wisamm@nvidia.com>; Raslan
> Darawsheh <rasland@nvidia.com>; Roni Bar Yanai <roniba@nvidia.com>
> Subject: [PATCH] net/mlx5: link status change for bonding cases
> 
> The current implementation of mlx5_dev_interrupt_nl_cb routine first
> compares if event netlink if_index belongs to the same device.
> This is not fully correct for the bonding device since the bonding master and
> slave interface netlink events indicate the bonding link status change as well.
> Add check for if_index is related to the bonding's master/slave.
> 
> The following step is that it compares the device link status before and after the
> netlink event handling. There are also the bonding specifics and it should
> compare the link status of the bonding master to detect the actual status
> change.
> 
> Signed-off-by: Haifei Luo <haifeil@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
  
Raslan Darawsheh March 12, 2024, 8 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Haifei Luo <haifeil@nvidia.com>
> Sent: Monday, February 26, 2024 2:04 PM
> To: Ori Kam <orika@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> Matan Azrad <matan@nvidia.com>; Shahaf Shuler <shahafs@nvidia.com>;
> Dariusz Sosnowski <dsosnowski@nvidia.com>; Suanming Mou
> <suanmingm@nvidia.com>
> Cc: dev@dpdk.org; NBU-Contact-Thomas Monjalon (EXTERNAL)
> <thomas@monjalon.net>; Wisam Jaddo <wisamm@nvidia.com>; Raslan
> Darawsheh <rasland@nvidia.com>; Roni Bar Yanai <roniba@nvidia.com>
> Subject: [PATCH] net/mlx5: link status change for bonding cases
> 
> The current implementation of mlx5_dev_interrupt_nl_cb routine first
> compares if event netlink if_index belongs to the same device.
> This is not fully correct for the bonding device since the bonding
> master and slave interface netlink events indicate the bonding link
> status change as well. Add check for if_index is related to the
> bonding's master/slave.
> 
> The following step is that it compares the device link status before
> and after the netlink event handling. There are also the bonding specifics
> and it should compare the link status of the bonding master to detect
> the actual status change.
> 
> Signed-off-by: Haifei Luo <haifeil@nvidia.com>

Patch applied to next-net-mlx,
Kindest regards
Raslan Darawsheh
  

Patch

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index dd5a0c5..a9b94f8 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -768,6 +768,47 @@  struct ethtool_link_settings {
 	}
 }
 
+static bool
+mlx5_dev_nl_ifindex_verify(uint32_t if_index, struct mlx5_priv *priv)
+{
+	struct mlx5_bond_info *bond = &priv->sh->bond;
+	int i;
+
+	if (bond->n_port == 0)
+		return (if_index == priv->if_index);
+
+	if (if_index == bond->ifindex)
+		return true;
+	for (i = 0; i < bond->n_port; i++) {
+		if (i >= MLX5_BOND_MAX_PORTS)
+			return false;
+		if (if_index == bond->ports[i].ifindex)
+			return true;
+	}
+
+	return false;
+}
+
+static void
+mlx5_link_update_bond(struct rte_eth_dev *dev)
+{
+	struct mlx5_priv *priv = dev->data->dev_private;
+	struct mlx5_bond_info *bond = &priv->sh->bond;
+	struct ifreq ifr = (struct ifreq) {
+		.ifr_flags = 0,
+	};
+	int ret;
+
+	ret = mlx5_ifreq_by_ifname(bond->ifname, SIOCGIFFLAGS, &ifr);
+	if (ret) {
+		DRV_LOG(WARNING, "ifname %s ioctl(SIOCGIFFLAGS) failed: %s",
+			bond->ifname, strerror(rte_errno));
+		return;
+	}
+	dev->data->dev_link.link_status =
+		((ifr.ifr_flags & IFF_UP) && (ifr.ifr_flags & IFF_RUNNING));
+}
+
 static void
 mlx5_dev_interrupt_nl_cb(struct nlmsghdr *hdr, void *cb_arg)
 {
@@ -790,16 +831,20 @@  struct ethtool_link_settings {
 		    !dev->data->dev_conf.intr_conf.lsc)
 			break;
 		priv = dev->data->dev_private;
-		if (priv->if_index == if_index) {
+		if (mlx5_dev_nl_ifindex_verify(if_index, priv)) {
 			/* Block logical LSC events. */
 			uint16_t prev_status = dev->data->dev_link.link_status;
 
-			if (mlx5_link_update(dev, 0) < 0)
+			if (mlx5_link_update(dev, 0) < 0) {
 				DRV_LOG(ERR, "Failed to update link status: %s",
 					rte_strerror(rte_errno));
-			else if (prev_status != dev->data->dev_link.link_status)
-				rte_eth_dev_callback_process
-					(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+			} else {
+				if (priv->sh->bond.n_port)
+					mlx5_link_update_bond(dev);
+				if (prev_status != dev->data->dev_link.link_status)
+					rte_eth_dev_callback_process
+						(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
+			}
 			break;
 		}
 	}