mlx5: count all link events
authorJakub Kicinski <kuba@kernel.org>
Wed, 19 May 2021 17:18:25 +0000 (10:18 -0700)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 3 Jun 2021 20:10:17 +0000 (13:10 -0700)
mlx5 devices were observed generating MLX5_PORT_CHANGE_SUBTYPE_ACTIVE
events without an intervening MLX5_PORT_CHANGE_SUBTYPE_DOWN. This
breaks link flap detection based on Linux carrier state transition
count as netif_carrier_on() does nothing if carrier is already on.
Make sure we count such events.

netif_carrier_event() increments the counters and fires the linkwatch
events. The latter is not necessary for the use case but seems like
the right thing to do.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
include/linux/netdevice.h
net/sched/sch_generic.c

index ad0f69480b9ca1d3c8609b01da74c4be4acc28b2..e36d0c6a08db9f9dd1dcede5510567195d08633f 100644 (file)
@@ -91,12 +91,16 @@ void mlx5e_update_carrier(struct mlx5e_priv *priv)
 {
        struct mlx5_core_dev *mdev = priv->mdev;
        u8 port_state;
+       bool up;
 
        port_state = mlx5_query_vport_state(mdev,
                                            MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT,
                                            0);
 
-       if (port_state == VPORT_STATE_UP) {
+       up = port_state == VPORT_STATE_UP;
+       if (up == netif_carrier_ok(priv->netdev))
+               netif_carrier_event(priv->netdev);
+       if (up) {
                netdev_info(priv->netdev, "Link up\n");
                netif_carrier_on(priv->netdev);
        } else {
index 5cbc950b34dfd3c6fad61982fd64179ff324d0f2..be1dcceda5e4892df6a19e1926f4ba59604e8a2e 100644 (file)
@@ -4187,8 +4187,8 @@ unsigned long dev_trans_start(struct net_device *dev);
 void __netdev_watchdog_up(struct net_device *dev);
 
 void netif_carrier_on(struct net_device *dev);
-
 void netif_carrier_off(struct net_device *dev);
+void netif_carrier_event(struct net_device *dev);
 
 /**
  *     netif_dormant_on - mark device as dormant.
index fc8b56bcabf39f01053894781ddf040df42e0c1e..e9c0afc8beccbe241fdcb83874266dd1bd915a12 100644 (file)
@@ -540,6 +540,24 @@ void netif_carrier_off(struct net_device *dev)
 }
 EXPORT_SYMBOL(netif_carrier_off);
 
+/**
+ *     netif_carrier_event - report carrier state event
+ *     @dev: network device
+ *
+ * Device has detected a carrier event but the carrier state wasn't changed.
+ * Use in drivers when querying carrier state asynchronously, to avoid missing
+ * events (link flaps) if link recovers before it's queried.
+ */
+void netif_carrier_event(struct net_device *dev)
+{
+       if (dev->reg_state == NETREG_UNINITIALIZED)
+               return;
+       atomic_inc(&dev->carrier_up_count);
+       atomic_inc(&dev->carrier_down_count);
+       linkwatch_fire_event(dev);
+}
+EXPORT_SYMBOL_GPL(netif_carrier_event);
+
 /* "NOOP" scheduler: the best scheduler, recommended for all interfaces
    under all circumstances. It is difficult to invent anything faster or
    cheaper.