net/mxl5e: Add change profile method
authorSaeed Mahameed <saeedm@nvidia.com>
Mon, 23 Mar 2020 06:17:14 +0000 (23:17 -0700)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 2 Feb 2021 06:52:32 +0000 (22:52 -0800)
Port nic netdevice will be used as uplink representor in downstream
patches. Add change profile method to allow changing a mlx5e netdevice
profile dynamically.

Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

index bf5de1e791341675b9f5c85e88e3048c08464462..fa461cfd64106cd5b0e8c97181121430de0da6b4 100644 (file)
@@ -1154,9 +1154,10 @@ int mlx5e_ethtool_set_pauseparam(struct mlx5e_priv *priv,
                                 struct ethtool_pauseparam *pauseparam);
 
 /* mlx5e generic netdev management API */
-static inline unsigned int mlx5e_calc_max_nch(struct mlx5e_priv *priv)
+static inline unsigned int
+mlx5e_calc_max_nch(struct mlx5e_priv *priv, const struct mlx5e_profile *profile)
 {
-       return priv->netdev->num_rx_queues / max_t(u8, priv->profile->rq_groups, 1);
+       return priv->netdev->num_rx_queues / max_t(u8, profile->rq_groups, 1);
 }
 
 int mlx5e_netdev_init(struct net_device *netdev,
@@ -1168,6 +1169,8 @@ mlx5e_create_netdev(struct mlx5_core_dev *mdev, unsigned int txqs, unsigned int
 int mlx5e_attach_netdev(struct mlx5e_priv *priv);
 void mlx5e_detach_netdev(struct mlx5e_priv *priv);
 void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
+int mlx5e_netdev_change_profile(struct mlx5e_priv *priv,
+                               const struct mlx5e_profile *new_profile, void *new_ppriv);
 void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv);
 void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16 mtu);
 void mlx5e_build_rq_params(struct mlx5_core_dev *mdev,
index 260ced27014d90910f7d0c5955545d0c707d3f37..91f23871ded5515e11ddefd0be04c5ba9b8e1823 100644 (file)
@@ -4936,7 +4936,7 @@ void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16
        struct mlx5_core_dev *mdev = priv->mdev;
        u8 rx_cq_period_mode;
 
-       priv->max_nch = mlx5e_calc_max_nch(priv);
+       priv->max_nch = mlx5e_calc_max_nch(priv, priv->profile);
 
        params->sw_mtu = mtu;
        params->hard_mtu = MLX5E_ETH_HARD_MTU;
@@ -5461,6 +5461,8 @@ int mlx5e_netdev_init(struct net_device *netdev,
                      struct mlx5e_priv *priv,
                      struct mlx5_core_dev *mdev)
 {
+       memset(priv, 0, sizeof(*priv));
+
        /* priv init */
        priv->mdev        = mdev;
        priv->netdev      = netdev;
@@ -5615,6 +5617,70 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)
        cancel_work_sync(&priv->update_stats_work);
 }
 
+static int
+mlx5e_netdev_attach_profile(struct mlx5e_priv *priv,
+                           const struct mlx5e_profile *new_profile, void *new_ppriv)
+{
+       struct net_device *netdev = priv->netdev;
+       struct mlx5_core_dev *mdev = priv->mdev;
+       int err;
+
+       err = mlx5e_netdev_init(netdev, priv, mdev);
+       if (err) {
+               mlx5_core_err(mdev, "mlx5e_netdev_init failed, err=%d\n", err);
+               return err;
+       }
+       priv->profile = new_profile;
+       priv->ppriv = new_ppriv;
+       err = new_profile->init(priv->mdev, priv->netdev);
+       if (err)
+               return err;
+       err = mlx5e_attach_netdev(priv);
+       if (err)
+               new_profile->cleanup(priv);
+       return err;
+}
+
+int mlx5e_netdev_change_profile(struct mlx5e_priv *priv,
+                               const struct mlx5e_profile *new_profile, void *new_ppriv)
+{
+       unsigned int new_max_nch = mlx5e_calc_max_nch(priv, new_profile);
+       const struct mlx5e_profile *orig_profile = priv->profile;
+       void *orig_ppriv = priv->ppriv;
+       int err, rollback_err;
+
+       /* sanity */
+       if (new_max_nch != priv->max_nch) {
+               netdev_warn(priv->netdev,
+                           "%s: Replacing profile with different max channles\n",
+                           __func__);
+               return -EINVAL;
+       }
+
+       /* cleanup old profile */
+       mlx5e_detach_netdev(priv);
+       priv->profile->cleanup(priv);
+       mlx5e_netdev_cleanup(priv->netdev, priv);
+
+       err = mlx5e_netdev_attach_profile(priv, new_profile, new_ppriv);
+       if (err) { /* roll back to original profile */
+               netdev_warn(priv->netdev, "%s: new profile init failed, %d\n",
+                           __func__, err);
+               goto rollback;
+       }
+
+       return 0;
+
+rollback:
+       rollback_err = mlx5e_netdev_attach_profile(priv, orig_profile, orig_ppriv);
+       if (rollback_err) {
+               netdev_err(priv->netdev,
+                          "%s: failed to rollback to orig profile, %d\n",
+                          __func__, rollback_err);
+       }
+       return err;
+}
+
 void mlx5e_destroy_netdev(struct mlx5e_priv *priv)
 {
        struct net_device *netdev = priv->netdev;
index d94d2ff9d312fefe97bdbea4e45cb6278bb0d204..c8a0f4c88d4baa48adf6520086cd0a9e93bf9d9a 100644 (file)
@@ -684,7 +684,7 @@ static void mlx5e_build_rep_params(struct net_device *netdev)
                                         MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
                                         MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
 
-       priv->max_nch = mlx5e_calc_max_nch(priv);
+       priv->max_nch = mlx5e_calc_max_nch(priv, priv->profile);
        params = &priv->channels.params;
 
        params->num_channels = MLX5E_REP_PARAMS_DEF_NUM_CHANNELS;