From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: Tariq Toukan <tariqt@nvidia.com>,
netdev@vger.kernel.org, Maxim Mikityanskiy <maximmi@mellanox.com>,
Saeed Mahameed <saeedm@nvidia.com>
Subject: [net-next 06/14] net/mlx5e: Allow mlx5e_safe_switch_channels to work with channels closed
Date: Fri, 16 Apr 2021 11:54:22 -0700 [thread overview]
Message-ID: <20210416185430.62584-7-saeed@kernel.org> (raw)
In-Reply-To: <20210416185430.62584-1-saeed@kernel.org>
From: Maxim Mikityanskiy <maximmi@mellanox.com>
mlx5e_safe_switch_channels is used to modify channel parameters and/or
hardware configuration in a safe way, so that if anything goes wrong,
everything reverts to the old configuration and remains in a consistent
state.
However, this function only works when the channels are open. When the
caller needs to modify some parameters, first it has to check that the
channels are open, otherwise it has to assign parameters directly, and
such boilerplate repeats in many different places.
This commit prepares for the refactoring of such places by allowing
mlx5e_safe_switch_channels to work when the channels are closed. In this
case it will assign the new parameters and run the preactivate hook.
Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/en_main.c | 40 +++++++++++++------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index df4959e46f27..cb88d7239db6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -2852,12 +2852,16 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
struct net_device *netdev = priv->netdev;
struct mlx5e_channels old_chs;
int carrier_ok;
+ bool opened;
int err = 0;
- carrier_ok = netif_carrier_ok(netdev);
- netif_carrier_off(netdev);
+ opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
+ if (opened) {
+ carrier_ok = netif_carrier_ok(netdev);
+ netif_carrier_off(netdev);
- mlx5e_deactivate_priv_channels(priv);
+ mlx5e_deactivate_priv_channels(priv);
+ }
old_chs = priv->channels;
priv->channels = *new_chs;
@@ -2873,15 +2877,19 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
}
}
- mlx5e_close_channels(&old_chs);
- priv->profile->update_rx(priv);
+ if (opened) {
+ mlx5e_close_channels(&old_chs);
+ priv->profile->update_rx(priv);
+ }
out:
- mlx5e_activate_priv_channels(priv);
+ if (opened) {
+ mlx5e_activate_priv_channels(priv);
- /* return carrier back if needed */
- if (carrier_ok)
- netif_carrier_on(netdev);
+ /* return carrier back if needed */
+ if (carrier_ok)
+ netif_carrier_on(netdev);
+ }
return err;
}
@@ -2891,11 +2899,16 @@ int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
mlx5e_fp_preactivate preactivate,
void *context)
{
+ bool opened;
int err;
- err = mlx5e_open_channels(priv, new_chs);
- if (err)
- return err;
+ opened = test_bit(MLX5E_STATE_OPENED, &priv->state);
+
+ if (opened) {
+ err = mlx5e_open_channels(priv, new_chs);
+ if (err)
+ return err;
+ }
err = mlx5e_switch_priv_channels(priv, new_chs, preactivate, context);
if (err)
@@ -2904,7 +2917,8 @@ int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
return 0;
err_close:
- mlx5e_close_channels(new_chs);
+ if (opened)
+ mlx5e_close_channels(new_chs);
return err;
}
--
2.30.2
next prev parent reply other threads:[~2021-04-16 18:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 18:54 [pull request][net-next 00/14] mlx5 updates 2021-04-16 Saeed Mahameed
2021-04-16 18:54 ` [net-next 01/14] net/mlx5e: Remove non-essential TLS SQ state bit Saeed Mahameed
2021-04-17 0:00 ` patchwork-bot+netdevbpf
2021-04-16 18:54 ` [net-next 02/14] net/mlx5e: Cleanup unused function parameter Saeed Mahameed
2021-04-16 18:54 ` [net-next 03/14] net/mlx5e: TX, Inline TLS skb check Saeed Mahameed
2021-04-16 18:54 ` [net-next 04/14] net/mlx5e: TX, Inline function mlx5e_tls_handle_tx_wqe() Saeed Mahameed
2021-04-16 18:54 ` [net-next 05/14] net/mlx5e: kTLS, Add resiliency to RX resync failures Saeed Mahameed
2021-04-16 18:54 ` Saeed Mahameed [this message]
2021-04-16 18:54 ` [net-next 07/14] net/mlx5e: Use mlx5e_safe_switch_channels when channels are closed Saeed Mahameed
2021-04-16 18:54 ` [net-next 08/14] net/mlx5e: Refactor on-the-fly configuration changes Saeed Mahameed
2021-04-16 18:54 ` [net-next 09/14] net/mlx5e: Cleanup safe switch channels API by passing params Saeed Mahameed
2021-04-16 18:54 ` [net-next 10/14] net/mlx5: Allocate FC bulk structs with kvzalloc() instead of kzalloc() Saeed Mahameed
2021-04-16 18:54 ` [net-next 11/14] net/mlx5: Add register layout to support extended link state Saeed Mahameed
2021-04-16 18:54 ` [net-next 12/14] net/mlx5e: Add ethtool " Saeed Mahameed
2021-04-16 18:54 ` [net-next 13/14] net/mlx5: Add helper to initialize 1PPS Saeed Mahameed
2021-04-16 18:54 ` [net-next 14/14] net/mlx5: Enhance diagnostics info for TX/RX reporters Saeed Mahameed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210416185430.62584-7-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=maximmi@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).