net/mlx5e: Gather common netdev init/cleanup functionality in one place
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_rep.c
index 9264c3332aa60faf6842b602d81cb4bc9fb10e28..6176e53c8b83d94456ed3d17ef8ef5d0e40a4d18 100644 (file)
@@ -1078,28 +1078,40 @@ static void mlx5e_build_rep_netdev(struct net_device *netdev)
        netdev->max_mtu = MLX5E_HW2SW_MTU(&priv->channels.params, max_mtu);
 }
 
        netdev->max_mtu = MLX5E_HW2SW_MTU(&priv->channels.params, max_mtu);
 }
 
-static void mlx5e_init_rep(struct mlx5_core_dev *mdev,
-                          struct net_device *netdev,
-                          const struct mlx5e_profile *profile,
-                          void *ppriv)
+static int mlx5e_init_rep(struct mlx5_core_dev *mdev,
+                         struct net_device *netdev,
+                         const struct mlx5e_profile *profile,
+                         void *ppriv)
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
+       int err;
 
        priv->mdev                         = mdev;
        priv->netdev                       = netdev;
        priv->profile                      = profile;
        priv->ppriv                        = ppriv;
 
 
        priv->mdev                         = mdev;
        priv->netdev                       = netdev;
        priv->profile                      = profile;
        priv->ppriv                        = ppriv;
 
-       mutex_init(&priv->state_lock);
+       err = mlx5e_netdev_init(netdev, priv);
+       if (err)
+               return err;
 
        INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
 
 
        INIT_DELAYED_WORK(&priv->update_stats_work, mlx5e_update_stats_work);
 
-       priv->channels.params.num_channels = 1;
+       mutex_init(&priv->state_lock);
+
+       priv->channels.params.num_channels = profile->max_nch(mdev);
 
        mlx5e_build_rep_params(mdev, &priv->channels.params, netdev->mtu);
        mlx5e_build_rep_netdev(netdev);
 
        mlx5e_timestamp_init(priv);
 
        mlx5e_build_rep_params(mdev, &priv->channels.params, netdev->mtu);
        mlx5e_build_rep_netdev(netdev);
 
        mlx5e_timestamp_init(priv);
+
+       return 0;
+}
+
+static void mlx5e_cleanup_rep(struct mlx5e_priv *priv)
+{
+       mlx5e_netdev_cleanup(priv->netdev, priv);
 }
 
 static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv)
 }
 
 static int mlx5e_create_rep_ttc_table(struct mlx5e_priv *priv)
@@ -1224,6 +1236,7 @@ static int mlx5e_init_rep_tx(struct mlx5e_priv *priv)
 
 static const struct mlx5e_profile mlx5e_rep_profile = {
        .init                   = mlx5e_init_rep,
 
 static const struct mlx5e_profile mlx5e_rep_profile = {
        .init                   = mlx5e_init_rep,
+       .cleanup                = mlx5e_cleanup_rep,
        .init_rx                = mlx5e_init_rep_rx,
        .cleanup_rx             = mlx5e_cleanup_rep_rx,
        .init_tx                = mlx5e_init_rep_tx,
        .init_rx                = mlx5e_init_rep_rx,
        .cleanup_rx             = mlx5e_cleanup_rep_rx,
        .init_tx                = mlx5e_init_rep_tx,