Skip to content

Commit c4d7eb5

Browse files
author
Saeed Mahameed
committed
net/mxl5e: Add change profile method
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>
1 parent 3ef14e4 commit c4d7eb5

3 files changed

Lines changed: 73 additions & 4 deletions

File tree

drivers/net/ethernet/mellanox/mlx5/core/en.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,10 @@ int mlx5e_ethtool_set_pauseparam(struct mlx5e_priv *priv,
11541154
struct ethtool_pauseparam *pauseparam);
11551155

11561156
/* mlx5e generic netdev management API */
1157-
static inline unsigned int mlx5e_calc_max_nch(struct mlx5e_priv *priv)
1157+
static inline unsigned int
1158+
mlx5e_calc_max_nch(struct mlx5e_priv *priv, const struct mlx5e_profile *profile)
11581159
{
1159-
return priv->netdev->num_rx_queues / max_t(u8, priv->profile->rq_groups, 1);
1160+
return priv->netdev->num_rx_queues / max_t(u8, profile->rq_groups, 1);
11601161
}
11611162

11621163
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
11681169
int mlx5e_attach_netdev(struct mlx5e_priv *priv);
11691170
void mlx5e_detach_netdev(struct mlx5e_priv *priv);
11701171
void mlx5e_destroy_netdev(struct mlx5e_priv *priv);
1172+
int mlx5e_netdev_change_profile(struct mlx5e_priv *priv,
1173+
const struct mlx5e_profile *new_profile, void *new_ppriv);
11711174
void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv);
11721175
void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16 mtu);
11731176
void mlx5e_build_rq_params(struct mlx5_core_dev *mdev,

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4936,7 +4936,7 @@ void mlx5e_build_nic_params(struct mlx5e_priv *priv, struct mlx5e_xsk *xsk, u16
49364936
struct mlx5_core_dev *mdev = priv->mdev;
49374937
u8 rx_cq_period_mode;
49384938

4939-
priv->max_nch = mlx5e_calc_max_nch(priv);
4939+
priv->max_nch = mlx5e_calc_max_nch(priv, priv->profile);
49404940

49414941
params->sw_mtu = mtu;
49424942
params->hard_mtu = MLX5E_ETH_HARD_MTU;
@@ -5461,6 +5461,8 @@ int mlx5e_netdev_init(struct net_device *netdev,
54615461
struct mlx5e_priv *priv,
54625462
struct mlx5_core_dev *mdev)
54635463
{
5464+
memset(priv, 0, sizeof(*priv));
5465+
54645466
/* priv init */
54655467
priv->mdev = mdev;
54665468
priv->netdev = netdev;
@@ -5615,6 +5617,70 @@ void mlx5e_detach_netdev(struct mlx5e_priv *priv)
56155617
cancel_work_sync(&priv->update_stats_work);
56165618
}
56175619

5620+
static int
5621+
mlx5e_netdev_attach_profile(struct mlx5e_priv *priv,
5622+
const struct mlx5e_profile *new_profile, void *new_ppriv)
5623+
{
5624+
struct net_device *netdev = priv->netdev;
5625+
struct mlx5_core_dev *mdev = priv->mdev;
5626+
int err;
5627+
5628+
err = mlx5e_netdev_init(netdev, priv, mdev);
5629+
if (err) {
5630+
mlx5_core_err(mdev, "mlx5e_netdev_init failed, err=%d\n", err);
5631+
return err;
5632+
}
5633+
priv->profile = new_profile;
5634+
priv->ppriv = new_ppriv;
5635+
err = new_profile->init(priv->mdev, priv->netdev);
5636+
if (err)
5637+
return err;
5638+
err = mlx5e_attach_netdev(priv);
5639+
if (err)
5640+
new_profile->cleanup(priv);
5641+
return err;
5642+
}
5643+
5644+
int mlx5e_netdev_change_profile(struct mlx5e_priv *priv,
5645+
const struct mlx5e_profile *new_profile, void *new_ppriv)
5646+
{
5647+
unsigned int new_max_nch = mlx5e_calc_max_nch(priv, new_profile);
5648+
const struct mlx5e_profile *orig_profile = priv->profile;
5649+
void *orig_ppriv = priv->ppriv;
5650+
int err, rollback_err;
5651+
5652+
/* sanity */
5653+
if (new_max_nch != priv->max_nch) {
5654+
netdev_warn(priv->netdev,
5655+
"%s: Replacing profile with different max channles\n",
5656+
__func__);
5657+
return -EINVAL;
5658+
}
5659+
5660+
/* cleanup old profile */
5661+
mlx5e_detach_netdev(priv);
5662+
priv->profile->cleanup(priv);
5663+
mlx5e_netdev_cleanup(priv->netdev, priv);
5664+
5665+
err = mlx5e_netdev_attach_profile(priv, new_profile, new_ppriv);
5666+
if (err) { /* roll back to original profile */
5667+
netdev_warn(priv->netdev, "%s: new profile init failed, %d\n",
5668+
__func__, err);
5669+
goto rollback;
5670+
}
5671+
5672+
return 0;
5673+
5674+
rollback:
5675+
rollback_err = mlx5e_netdev_attach_profile(priv, orig_profile, orig_ppriv);
5676+
if (rollback_err) {
5677+
netdev_err(priv->netdev,
5678+
"%s: failed to rollback to orig profile, %d\n",
5679+
__func__, rollback_err);
5680+
}
5681+
return err;
5682+
}
5683+
56185684
void mlx5e_destroy_netdev(struct mlx5e_priv *priv)
56195685
{
56205686
struct net_device *netdev = priv->netdev;

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static void mlx5e_build_rep_params(struct net_device *netdev)
684684
MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
685685
MLX5_CQ_PERIOD_MODE_START_FROM_EQE;
686686

687-
priv->max_nch = mlx5e_calc_max_nch(priv);
687+
priv->max_nch = mlx5e_calc_max_nch(priv, priv->profile);
688688
params = &priv->channels.params;
689689

690690
params->num_channels = MLX5E_REP_PARAMS_DEF_NUM_CHANNELS;

0 commit comments

Comments
 (0)