Skip to content

Commit 546f18e

Browse files
author
Saeed Mahameed
committed
net/mlx5e: Fail safe ethtool settings
Use the new fail-safe channels switch mechanism to set new ethtool settings: - ring parameters - coalesce parameters - tx copy break parameters Signed-off-by: Saeed Mahameed <[email protected]> Reviewed-by: Tariq Toukan <[email protected]>
1 parent 55c2503 commit 546f18e

File tree

1 file changed

+73
-47
lines changed

1 file changed

+73
-47
lines changed

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

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ static int mlx5e_set_ringparam(struct net_device *dev,
457457
{
458458
struct mlx5e_priv *priv = netdev_priv(dev);
459459
int rq_wq_type = priv->channels.params.rq_wq_type;
460+
struct mlx5e_channels new_channels = {};
460461
u32 rx_pending_wqes;
461-
bool was_opened;
462462
u32 min_rq_size;
463463
u32 max_rq_size;
464464
u8 log_rq_size;
@@ -527,16 +527,22 @@ static int mlx5e_set_ringparam(struct net_device *dev,
527527

528528
mutex_lock(&priv->state_lock);
529529

530-
was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
531-
if (was_opened)
532-
mlx5e_close_locked(dev);
530+
new_channels.params = priv->channels.params;
531+
new_channels.params.log_rq_size = log_rq_size;
532+
new_channels.params.log_sq_size = log_sq_size;
533533

534-
priv->channels.params.log_rq_size = log_rq_size;
535-
priv->channels.params.log_sq_size = log_sq_size;
534+
if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
535+
priv->channels.params = new_channels.params;
536+
goto unlock;
537+
}
536538

537-
if (was_opened)
538-
err = mlx5e_open_locked(dev);
539+
err = mlx5e_open_channels(priv, &new_channels);
540+
if (err)
541+
goto unlock;
542+
543+
mlx5e_switch_priv_channels(priv, &new_channels);
539544

545+
unlock:
540546
mutex_unlock(&priv->state_lock);
541547

542548
return err;
@@ -623,36 +629,13 @@ static int mlx5e_get_coalesce(struct net_device *netdev,
623629
return 0;
624630
}
625631

626-
static int mlx5e_set_coalesce(struct net_device *netdev,
627-
struct ethtool_coalesce *coal)
632+
static void
633+
mlx5e_set_priv_channels_coalesce(struct mlx5e_priv *priv, struct ethtool_coalesce *coal)
628634
{
629-
struct mlx5e_priv *priv = netdev_priv(netdev);
630635
struct mlx5_core_dev *mdev = priv->mdev;
631-
bool restart =
632-
!!coal->use_adaptive_rx_coalesce != priv->channels.params.rx_am_enabled;
633-
bool was_opened;
634-
int err = 0;
635636
int tc;
636637
int i;
637638

638-
if (!MLX5_CAP_GEN(mdev, cq_moderation))
639-
return -EOPNOTSUPP;
640-
641-
mutex_lock(&priv->state_lock);
642-
643-
was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
644-
if (was_opened && restart) {
645-
mlx5e_close_locked(netdev);
646-
priv->channels.params.rx_am_enabled = !!coal->use_adaptive_rx_coalesce;
647-
}
648-
649-
priv->channels.params.tx_cq_moderation.usec = coal->tx_coalesce_usecs;
650-
priv->channels.params.tx_cq_moderation.pkts = coal->tx_max_coalesced_frames;
651-
priv->channels.params.rx_cq_moderation.usec = coal->rx_coalesce_usecs;
652-
priv->channels.params.rx_cq_moderation.pkts = coal->rx_max_coalesced_frames;
653-
654-
if (!was_opened || restart)
655-
goto out;
656639
for (i = 0; i < priv->channels.num; ++i) {
657640
struct mlx5e_channel *c = priv->channels.c[i];
658641

@@ -667,11 +650,50 @@ static int mlx5e_set_coalesce(struct net_device *netdev,
667650
coal->rx_coalesce_usecs,
668651
coal->rx_max_coalesced_frames);
669652
}
653+
}
670654

671-
out:
672-
if (was_opened && restart)
673-
err = mlx5e_open_locked(netdev);
655+
static int mlx5e_set_coalesce(struct net_device *netdev,
656+
struct ethtool_coalesce *coal)
657+
{
658+
struct mlx5e_priv *priv = netdev_priv(netdev);
659+
struct mlx5_core_dev *mdev = priv->mdev;
660+
struct mlx5e_channels new_channels = {};
661+
int err = 0;
662+
bool reset;
674663

664+
if (!MLX5_CAP_GEN(mdev, cq_moderation))
665+
return -EOPNOTSUPP;
666+
667+
mutex_lock(&priv->state_lock);
668+
new_channels.params = priv->channels.params;
669+
670+
new_channels.params.tx_cq_moderation.usec = coal->tx_coalesce_usecs;
671+
new_channels.params.tx_cq_moderation.pkts = coal->tx_max_coalesced_frames;
672+
new_channels.params.rx_cq_moderation.usec = coal->rx_coalesce_usecs;
673+
new_channels.params.rx_cq_moderation.pkts = coal->rx_max_coalesced_frames;
674+
new_channels.params.rx_am_enabled = !!coal->use_adaptive_rx_coalesce;
675+
676+
if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
677+
priv->channels.params = new_channels.params;
678+
goto out;
679+
}
680+
/* we are opened */
681+
682+
reset = !!coal->use_adaptive_rx_coalesce != priv->channels.params.rx_am_enabled;
683+
if (!reset) {
684+
mlx5e_set_priv_channels_coalesce(priv, coal);
685+
priv->channels.params = new_channels.params;
686+
goto out;
687+
}
688+
689+
/* open fresh channels with new coal parameters */
690+
err = mlx5e_open_channels(priv, &new_channels);
691+
if (err)
692+
goto out;
693+
694+
mlx5e_switch_priv_channels(priv, &new_channels);
695+
696+
out:
675697
mutex_unlock(&priv->state_lock);
676698
return err;
677699
}
@@ -1119,9 +1141,11 @@ static int mlx5e_set_tunable(struct net_device *dev,
11191141
{
11201142
struct mlx5e_priv *priv = netdev_priv(dev);
11211143
struct mlx5_core_dev *mdev = priv->mdev;
1122-
bool was_opened;
1123-
u32 val;
1144+
struct mlx5e_channels new_channels = {};
11241145
int err = 0;
1146+
u32 val;
1147+
1148+
mutex_lock(&priv->state_lock);
11251149

11261150
switch (tuna->id) {
11271151
case ETHTOOL_TX_COPYBREAK:
@@ -1131,24 +1155,26 @@ static int mlx5e_set_tunable(struct net_device *dev,
11311155
break;
11321156
}
11331157

1134-
mutex_lock(&priv->state_lock);
1158+
new_channels.params = priv->channels.params;
1159+
new_channels.params.tx_max_inline = val;
11351160

1136-
was_opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
1137-
if (was_opened)
1138-
mlx5e_close_locked(dev);
1139-
1140-
priv->channels.params.tx_max_inline = val;
1161+
if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
1162+
priv->channels.params = new_channels.params;
1163+
break;
1164+
}
11411165

1142-
if (was_opened)
1143-
err = mlx5e_open_locked(dev);
1166+
err = mlx5e_open_channels(priv, &new_channels);
1167+
if (err)
1168+
break;
1169+
mlx5e_switch_priv_channels(priv, &new_channels);
11441170

1145-
mutex_unlock(&priv->state_lock);
11461171
break;
11471172
default:
11481173
err = -EINVAL;
11491174
break;
11501175
}
11511176

1177+
mutex_unlock(&priv->state_lock);
11521178
return err;
11531179
}
11541180

0 commit comments

Comments
 (0)