]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/mlx4_en: Resolve bad operstate value
authorLama Kayal <lkayal@nvidia.com>
Sun, 19 Sep 2021 11:55:45 +0000 (14:55 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 19 Sep 2021 12:21:04 +0000 (13:21 +0100)
Any link state change that's done prior to net device registration
isn't reflected on the state, thus the operational state is left
obsolete, with 'UNKNOWN' status.

To resolve the issue, query link state from FW upon open operations
to ensure operational state is updated.

Fixes: eebe24d1aff7 ("mlx4_en: Add driver for Mellanox ConnectX 10GbE NIC")
Signed-off-by: Lama Kayal <lkayal@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx4/en_netdev.c
drivers/net/ethernet/mellanox/mlx4/mlx4_en.h

index a2f61a87cef805b38590fb2ec07b15f77c464f5f..35154635ec3a1ecad3befe03a419ccdb1d6dead8 100644 (file)
@@ -1269,7 +1269,6 @@ static void mlx4_en_do_set_rx_mode(struct work_struct *work)
        if (!netif_carrier_ok(dev)) {
                if (!mlx4_en_QUERY_PORT(mdev, priv->port)) {
                        if (priv->port_state.link_state) {
-                               priv->last_link_state = MLX4_DEV_EVENT_PORT_UP;
                                netif_carrier_on(dev);
                                en_dbg(LINK, priv, "Link Up\n");
                        }
@@ -1557,26 +1556,36 @@ static void mlx4_en_service_task(struct work_struct *work)
        mutex_unlock(&mdev->state_lock);
 }
 
-static void mlx4_en_linkstate(struct work_struct *work)
+static void mlx4_en_linkstate(struct mlx4_en_priv *priv)
+{
+       struct mlx4_en_port_state *port_state = &priv->port_state;
+       struct mlx4_en_dev *mdev = priv->mdev;
+       struct net_device *dev = priv->dev;
+       bool up;
+
+       if (mlx4_en_QUERY_PORT(mdev, priv->port))
+               port_state->link_state = MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN;
+
+       up = port_state->link_state == MLX4_PORT_STATE_DEV_EVENT_PORT_UP;
+       if (up == netif_carrier_ok(dev))
+               netif_carrier_event(dev);
+       if (!up) {
+               en_info(priv, "Link Down\n");
+               netif_carrier_off(dev);
+       } else {
+               en_info(priv, "Link Up\n");
+               netif_carrier_on(dev);
+       }
+}
+
+static void mlx4_en_linkstate_work(struct work_struct *work)
 {
        struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
                                                 linkstate_task);
        struct mlx4_en_dev *mdev = priv->mdev;
-       int linkstate = priv->link_state;
 
        mutex_lock(&mdev->state_lock);
-       /* If observable port state changed set carrier state and
-        * report to system log */
-       if (priv->last_link_state != linkstate) {
-               if (linkstate == MLX4_DEV_EVENT_PORT_DOWN) {
-                       en_info(priv, "Link Down\n");
-                       netif_carrier_off(priv->dev);
-               } else {
-                       en_info(priv, "Link Up\n");
-                       netif_carrier_on(priv->dev);
-               }
-       }
-       priv->last_link_state = linkstate;
+       mlx4_en_linkstate(priv);
        mutex_unlock(&mdev->state_lock);
 }
 
@@ -2079,9 +2088,11 @@ static int mlx4_en_open(struct net_device *dev)
        mlx4_en_clear_stats(dev);
 
        err = mlx4_en_start_port(dev);
-       if (err)
+       if (err) {
                en_err(priv, "Failed starting port:%d\n", priv->port);
-
+               goto out;
+       }
+       mlx4_en_linkstate(priv);
 out:
        mutex_unlock(&mdev->state_lock);
        return err;
@@ -3168,7 +3179,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
        spin_lock_init(&priv->stats_lock);
        INIT_WORK(&priv->rx_mode_task, mlx4_en_do_set_rx_mode);
        INIT_WORK(&priv->restart_task, mlx4_en_restart);
-       INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate);
+       INIT_WORK(&priv->linkstate_task, mlx4_en_linkstate_work);
        INIT_DELAYED_WORK(&priv->stats_task, mlx4_en_do_get_stats);
        INIT_DELAYED_WORK(&priv->service_task, mlx4_en_service_task);
 #ifdef CONFIG_RFS_ACCEL
index f3d1a20201ef34f860ef865143de5abc3349f04e..6bf558c5ec1070b93f9a38a8dac5cf72fa19401c 100644 (file)
@@ -552,7 +552,6 @@ struct mlx4_en_priv {
 
        struct mlx4_hwq_resources res;
        int link_state;
-       int last_link_state;
        bool port_up;
        int port;
        int registered;