From: Saeed Mahameed <saeed@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Eric Dumazet <edumazet@google.com>
Cc: Saeed Mahameed <saeedm@nvidia.com>,
netdev@vger.kernel.org, Tariq Toukan <tariqt@nvidia.com>,
Gal Pressman <gal@nvidia.com>,
Leon Romanovsky <leonro@nvidia.com>,
Dragos Tatulea <dtatulea@nvidia.com>
Subject: [net-next 10/11] net/mlx5e: Implement queue mgmt ops and single channel swap
Date: Thu, 16 Jan 2025 13:55:28 -0800 [thread overview]
Message-ID: <20250116215530.158886-11-saeed@kernel.org> (raw)
In-Reply-To: <20250116215530.158886-1-saeed@kernel.org>
From: Saeed Mahameed <saeedm@nvidia.com>
The bulk of the work is done in mlx5e_queue_mem_alloc, where we allocate
and create the new channel resources, similar to
mlx5e_safe_switch_params, but here we do it for a single channel using
existing params, sort of a clone channel.
To swap the old channel with the new one, we deactivate and close the
old channel then replace it with the new one, since the swap procedure
doesn't fail in mlx5, we do it all in one place (mlx5e_queue_start).
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/en_main.c | 96 +++++++++++++++++++
1 file changed, 96 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 340ed7d3feac..1e03f2afe625 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -5489,6 +5489,101 @@ static const struct netdev_stat_ops mlx5e_stat_ops = {
.get_base_stats = mlx5e_get_base_stats,
};
+struct mlx5_qmgmt_data {
+ struct mlx5e_channel *c;
+ struct mlx5e_channel_param cparam;
+};
+
+static int mlx5e_queue_mem_alloc(struct net_device *dev, void *newq, int queue_index)
+{
+ struct mlx5_qmgmt_data *new = (struct mlx5_qmgmt_data *)newq;
+ struct mlx5e_priv *priv = netdev_priv(dev);
+ struct mlx5e_channels *chs = &priv->channels;
+ struct mlx5e_params params = chs->params;
+ struct mlx5_core_dev *mdev;
+ int err;
+
+ ASSERT_RTNL();
+ mutex_lock(&priv->state_lock);
+ if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
+ err = -ENODEV;
+ goto unlock;
+ }
+
+ if (queue_index >= chs->num) {
+ err = -ERANGE;
+ goto unlock;
+ }
+
+ if (MLX5E_GET_PFLAG(&chs->params, MLX5E_PFLAG_TX_PORT_TS) ||
+ chs->params.ptp_rx ||
+ chs->params.xdp_prog ||
+ priv->htb) {
+ netdev_err(priv->netdev,
+ "Cloning channels with Port/rx PTP, XDP or HTB is not supported\n");
+ err = -EOPNOTSUPP;
+ goto unlock;
+ }
+
+ mdev = mlx5_sd_ch_ix_get_dev(priv->mdev, queue_index);
+ err = mlx5e_build_channel_param(mdev, ¶ms, &new->cparam);
+ if (err) {
+ return err;
+ goto unlock;
+ }
+
+ err = mlx5e_open_channel(priv, queue_index, ¶ms, NULL, &new->c);
+unlock:
+ mutex_unlock(&priv->state_lock);
+ return err;
+}
+
+static void mlx5e_queue_mem_free(struct net_device *dev, void *mem)
+{
+ struct mlx5_qmgmt_data *data = (struct mlx5_qmgmt_data *)mem;
+
+ /* not supposed to happen since mlx5e_queue_start never fails
+ * but this is how this should be implemented just in case
+ */
+ if (data->c)
+ mlx5e_close_channel(data->c);
+}
+
+static int mlx5e_queue_stop(struct net_device *dev, void *oldq, int queue_index)
+{
+ /* mlx5e_queue_start does not fail, we stop the old queue there */
+ return 0;
+}
+
+static int mlx5e_queue_start(struct net_device *dev, void *newq, int queue_index)
+{
+ struct mlx5_qmgmt_data *new = (struct mlx5_qmgmt_data *)newq;
+ struct mlx5e_priv *priv = netdev_priv(dev);
+ struct mlx5e_channel *old;
+
+ mutex_lock(&priv->state_lock);
+
+ /* stop and close the old */
+ old = priv->channels.c[queue_index];
+ mlx5e_deactivate_priv_channels(priv);
+ /* close old before activating new, to avoid napi conflict */
+ mlx5e_close_channel(old);
+
+ /* start the new */
+ priv->channels.c[queue_index] = new->c;
+ mlx5e_activate_priv_channels(priv);
+ mutex_unlock(&priv->state_lock);
+ return 0;
+}
+
+static const struct netdev_queue_mgmt_ops mlx5e_queue_mgmt_ops = {
+ .ndo_queue_mem_size = sizeof(struct mlx5_qmgmt_data),
+ .ndo_queue_mem_alloc = mlx5e_queue_mem_alloc,
+ .ndo_queue_mem_free = mlx5e_queue_mem_free,
+ .ndo_queue_start = mlx5e_queue_start,
+ .ndo_queue_stop = mlx5e_queue_stop,
+};
+
static void mlx5e_build_nic_netdev(struct net_device *netdev)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
@@ -5499,6 +5594,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
SET_NETDEV_DEV(netdev, mdev->device);
netdev->netdev_ops = &mlx5e_netdev_ops;
+ netdev->queue_mgmt_ops = &mlx5e_queue_mgmt_ops;
netdev->xdp_metadata_ops = &mlx5e_xdp_metadata_ops;
netdev->xsk_tx_metadata_ops = &mlx5e_xsk_tx_metadata_ops;
--
2.48.0
next prev parent reply other threads:[~2025-01-16 21:56 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-16 21:55 [pull request][net-next 00/11] mlx5 updates 2025-01-16 Saeed Mahameed
2025-01-16 21:55 ` [net-next 01/11] net: Kconfig NET_DEVMEM selects GENERIC_ALLOCATOR Saeed Mahameed
2025-01-16 21:55 ` [net-next 02/11] net/mlx5e: SHAMPO: Reorganize mlx5_rq_shampo_alloc Saeed Mahameed
2025-01-16 21:55 ` [net-next 03/11] net/mlx5e: SHAMPO: Remove redundant params Saeed Mahameed
2025-01-16 21:55 ` [net-next 04/11] net/mlx5e: SHAMPO: Improve hw gro capability checking Saeed Mahameed
2025-01-16 21:55 ` [net-next 05/11] net/mlx5e: SHAMPO: Separate pool for headers Saeed Mahameed
2025-01-16 21:55 ` [net-next 06/11] net/mlx5e: SHAMPO: Headers page pool stats Saeed Mahameed
2025-01-16 21:55 ` [net-next 07/11] net/mlx5e: Convert over to netmem Saeed Mahameed
2025-02-05 20:14 ` Mina Almasry
2025-04-09 12:40 ` Dragos Tatulea
2025-01-16 21:55 ` [net-next 08/11] net/mlx5e: Handle iov backed netmems Saeed Mahameed
2025-01-16 21:55 ` [net-next 09/11] net/mlx5e: Add support for UNREADABLE netmem page pools Saeed Mahameed
2025-01-16 21:55 ` Saeed Mahameed [this message]
2025-01-16 23:21 ` [net-next 10/11] net/mlx5e: Implement queue mgmt ops and single channel swap Jakub Kicinski
2025-01-16 23:46 ` Saeed Mahameed
2025-01-16 23:54 ` Jakub Kicinski
2025-01-24 0:39 ` Stanislav Fomichev
2025-01-24 0:55 ` Jakub Kicinski
2025-01-24 3:11 ` Saeed Mahameed
2025-01-24 15:26 ` Jakub Kicinski
2025-01-24 19:34 ` Saeed Mahameed
2025-01-27 19:27 ` Jakub Kicinski
2025-01-16 21:55 ` [net-next 11/11] net/mlx5e: Support ethtool tcp-data-split settings 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=20250116215530.158886-11-saeed@kernel.org \
--to=saeed@kernel.org \
--cc=davem@davemloft.net \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=kuba@kernel.org \
--cc=leonro@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.