net/mlx5e: IPoIB, Basic netdev ndos open/close
authorSaeed Mahameed <saeedm@mellanox.com>
Thu, 13 Apr 2017 03:36:59 +0000 (06:36 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 Apr 2017 15:08:30 +0000 (11:08 -0400)
Implement open/close of IPoIB netdevice ndos using mlx5e's
channels API to manage data path resources (RQs/SQs/CQs).

Set IPoIB netdev address on dev_init ndo.

Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
Reviewed-by: Erez Shitrit <erezsh@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/ipoib.c

index 5345d875b6957062f5033e79b79c1aafb34c61cb..23b92ec54e1267ecce3ef1c13ede479c8030063d 100644 (file)
@@ -883,6 +883,8 @@ typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv);
 void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
                                struct mlx5e_channels *new_chs,
                                mlx5e_fp_hw_modify hw_modify);
+void mlx5e_activate_priv_channels(struct mlx5e_priv *priv);
+void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);
 
 void mlx5e_build_default_indir_rqt(struct mlx5_core_dev *mdev,
                                   u32 *indirection_rqt, int len,
index 1fde4e2301a4119a20ac2ca3bd87a84d15ff5784..eb657987e9b5575291e4966872eb442786ae8de1 100644 (file)
@@ -2547,7 +2547,7 @@ static void mlx5e_build_channels_tx_maps(struct mlx5e_priv *priv)
        }
 }
 
-static void mlx5e_activate_priv_channels(struct mlx5e_priv *priv)
+void mlx5e_activate_priv_channels(struct mlx5e_priv *priv)
 {
        int num_txqs = priv->channels.num * priv->channels.params.num_tc;
        struct net_device *netdev = priv->netdev;
@@ -2567,7 +2567,7 @@ static void mlx5e_activate_priv_channels(struct mlx5e_priv *priv)
        mlx5e_redirect_rqts_to_channels(priv, &priv->channels);
 }
 
-static void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)
+void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)
 {
        mlx5e_redirect_rqts_to_drop(priv);
 
index d7d705c840ae0d0b960afb244f100df9afa07f7b..e188d067bc970f569135076cec29977b9dafa934 100644 (file)
 #include "en.h"
 #include "ipoib.h"
 
+static int mlx5i_open(struct net_device *netdev);
+static int mlx5i_close(struct net_device *netdev);
+static int  mlx5i_dev_init(struct net_device *dev);
+static void mlx5i_dev_cleanup(struct net_device *dev);
+
+static const struct net_device_ops mlx5i_netdev_ops = {
+       .ndo_open                = mlx5i_open,
+       .ndo_stop                = mlx5i_close,
+       .ndo_init                = mlx5i_dev_init,
+       .ndo_uninit              = mlx5i_dev_cleanup,
+};
+
 /* IPoIB mlx5 netdev profile */
 
 /* Called directly after IPoIB netdevice was created to initialize SW structs */
@@ -52,7 +64,17 @@ static void mlx5i_init(struct mlx5_core_dev *mdev,
        mlx5e_build_nic_params(mdev, &priv->channels.params, profile->max_nch(mdev));
 
        mutex_init(&priv->state_lock);
-       /* TODO : init netdev features here */
+
+       netdev->hw_features    |= NETIF_F_SG;
+       netdev->hw_features    |= NETIF_F_IP_CSUM;
+       netdev->hw_features    |= NETIF_F_IPV6_CSUM;
+       netdev->hw_features    |= NETIF_F_GRO;
+       netdev->hw_features    |= NETIF_F_TSO;
+       netdev->hw_features    |= NETIF_F_TSO6;
+       netdev->hw_features    |= NETIF_F_RXCSUM;
+       netdev->hw_features    |= NETIF_F_RXHASH;
+
+       netdev->netdev_ops = &mlx5i_netdev_ops;
 }
 
 /* Called directly before IPoIB netdevice is destroyed to cleanup SW structs */
@@ -181,6 +203,72 @@ static const struct mlx5e_profile mlx5i_nic_profile = {
        .max_tc            = MLX5I_MAX_NUM_TC,
 };
 
+/* mlx5i netdev NDos */
+
+static int mlx5i_dev_init(struct net_device *dev)
+{
+       struct mlx5e_priv    *priv   = mlx5i_epriv(dev);
+       struct mlx5i_priv    *ipriv  = priv->ppriv;
+
+       /* Set dev address using underlay QP */
+       dev->dev_addr[1] = (ipriv->qp.qpn >> 16) & 0xff;
+       dev->dev_addr[2] = (ipriv->qp.qpn >>  8) & 0xff;
+       dev->dev_addr[3] = (ipriv->qp.qpn) & 0xff;
+
+       return 0;
+}
+
+static void mlx5i_dev_cleanup(struct net_device *dev)
+{
+       /* TODO: detach underlay qp from flow-steering by reset it */
+}
+
+static int mlx5i_open(struct net_device *netdev)
+{
+       struct mlx5e_priv *priv = mlx5i_epriv(netdev);
+       int err;
+
+       mutex_lock(&priv->state_lock);
+
+       set_bit(MLX5E_STATE_OPENED, &priv->state);
+
+       err = mlx5e_open_channels(priv, &priv->channels);
+       if (err)
+               goto err_clear_state_opened_flag;
+
+       mlx5e_refresh_tirs(priv, false);
+       mlx5e_activate_priv_channels(priv);
+       mutex_unlock(&priv->state_lock);
+       return 0;
+
+err_clear_state_opened_flag:
+       clear_bit(MLX5E_STATE_OPENED, &priv->state);
+       mutex_unlock(&priv->state_lock);
+       return err;
+}
+
+static int mlx5i_close(struct net_device *netdev)
+{
+       struct mlx5e_priv *priv = mlx5i_epriv(netdev);
+
+       /* May already be CLOSED in case a previous configuration operation
+        * (e.g RX/TX queue size change) that involves close&open failed.
+        */
+       mutex_lock(&priv->state_lock);
+
+       if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
+               goto unlock;
+
+       clear_bit(MLX5E_STATE_OPENED, &priv->state);
+
+       netif_carrier_off(priv->netdev);
+       mlx5e_deactivate_priv_channels(priv);
+       mlx5e_close_channels(&priv->channels);
+unlock:
+       mutex_unlock(&priv->state_lock);
+       return 0;
+}
+
 /* IPoIB RDMA netdev callbacks */
 
 static int mlx5i_check_required_hca_cap(struct mlx5_core_dev *mdev)