netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	Jiri Pirko <jiri@nvidia.com>, Shay Drory <shayd@nvidia.com>
Subject: [net-next 07/15] net/mlx5: Don't register ops for non-PF/VF/SF port and avoid checks in ops
Date: Tue, 22 Aug 2023 22:10:04 -0700	[thread overview]
Message-ID: <20230823051012.162483-8-saeed@kernel.org> (raw)
In-Reply-To: <20230823051012.162483-1-saeed@kernel.org>

From: Jiri Pirko <jiri@nvidia.com>

Currently each PF/VF/SF devlink port op called into mlx5 code calls
is_port_function_supported() to check if the port is either
PF, VF or SF. So make sure that the ops are registered with devlink
port only for those and avoid the is_port_function_supported() checks
in ops.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Shay Drory <shayd@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
---
 .../mellanox/mlx5/core/esw/devlink_port.c      |  4 +++-
 .../net/ethernet/mellanox/mlx5/core/eswitch.c  |  6 ++++++
 .../net/ethernet/mellanox/mlx5/core/eswitch.h  |  1 +
 .../mellanox/mlx5/core/eswitch_offloads.c      | 18 ------------------
 4 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
index b77893507476..69084673e7e6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c
@@ -173,8 +173,10 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_
 
 	if (mlx5_esw_is_sf_vport(esw, vport_num))
 		ops = &mlx5_esw_dl_sf_port_ops;
-	else
+	else if (mlx5_eswitch_is_pf_vf_vport(esw, vport_num))
 		ops = &mlx5_esw_pf_vf_dl_port_ops;
+	else
+		ops = NULL;
 
 	devlink = priv_to_devlink(dev);
 	dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index f77237401ee9..5d8d4a4f3e4e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1970,6 +1970,12 @@ bool mlx5_eswitch_is_vf_vport(struct mlx5_eswitch *esw, u16 vport_num)
 	return mlx5_esw_check_port_type(esw, vport_num, MLX5_ESW_VPT_VF);
 }
 
+bool mlx5_eswitch_is_pf_vf_vport(struct mlx5_eswitch *esw, u16 vport_num)
+{
+	return vport_num == MLX5_VPORT_PF ||
+		mlx5_eswitch_is_vf_vport(esw, vport_num);
+}
+
 bool mlx5_esw_is_sf_vport(struct mlx5_eswitch *esw, u16 vport_num)
 {
 	return mlx5_esw_check_port_type(esw, vport_num, MLX5_ESW_VPT_SF);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index e1e808105e98..ad2ebd843ed2 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -680,6 +680,7 @@ struct mlx5_vport *__must_check
 mlx5_eswitch_get_vport(struct mlx5_eswitch *esw, u16 vport_num);
 
 bool mlx5_eswitch_is_vf_vport(struct mlx5_eswitch *esw, u16 vport_num);
+bool mlx5_eswitch_is_pf_vf_vport(struct mlx5_eswitch *esw, u16 vport_num);
 bool mlx5_esw_is_sf_vport(struct mlx5_eswitch *esw, u16 vport_num);
 
 int mlx5_esw_funcs_changed_handler(struct notifier_block *nb, unsigned long type, void *data);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 4b03f2bf605d..1aa404218817 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -4218,14 +4218,6 @@ u32 mlx5_eswitch_get_vport_metadata_for_set(struct mlx5_eswitch *esw,
 }
 EXPORT_SYMBOL(mlx5_eswitch_get_vport_metadata_for_set);
 
-static bool
-is_port_function_supported(struct mlx5_eswitch *esw, u16 vport_num)
-{
-	return vport_num == MLX5_VPORT_PF ||
-	       mlx5_eswitch_is_vf_vport(esw, vport_num) ||
-	       mlx5_esw_is_sf_vport(esw, vport_num);
-}
-
 int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
 				     u8 *hw_addr, int *hw_addr_len,
 				     struct netlink_ext_ack *extack)
@@ -4239,8 +4231,6 @@ int mlx5_devlink_port_fn_hw_addr_get(struct devlink_port *port,
 		return PTR_ERR(esw);
 
 	vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
-	if (!is_port_function_supported(esw, vport_num))
-		return -EOPNOTSUPP;
 
 	vport = mlx5_eswitch_get_vport(esw, vport_num);
 	if (IS_ERR(vport)) {
@@ -4269,11 +4259,6 @@ int mlx5_devlink_port_fn_hw_addr_set(struct devlink_port *port,
 	}
 
 	vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
-	if (!is_port_function_supported(esw, vport_num)) {
-		NL_SET_ERR_MSG_MOD(extack, "Port doesn't support set hw_addr");
-		return -EINVAL;
-	}
-
 	return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
 }
 
@@ -4286,9 +4271,6 @@ mlx5_devlink_port_fn_get_vport(struct devlink_port *port, struct mlx5_eswitch *e
 		return ERR_PTR(-EOPNOTSUPP);
 
 	vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
-	if (!is_port_function_supported(esw, vport_num))
-		return ERR_PTR(-EOPNOTSUPP);
-
 	return mlx5_eswitch_get_vport(esw, vport_num);
 }
 
-- 
2.41.0


  parent reply	other threads:[~2023-08-23  5:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-23  5:09 [pull request][net-next 00/15] mlx5 updates 2023-08-22 Saeed Mahameed
2023-08-23  5:09 ` [net-next 01/15] net/mlx5: Rework devlink port alloc/free into init/cleanup Saeed Mahameed
2023-08-24 13:40   ` patchwork-bot+netdevbpf
2023-08-23  5:09 ` [net-next 02/15] net/mlx5: Push out SF devlink port init and cleanup code to separate helpers Saeed Mahameed
2023-08-23  5:10 ` [net-next 03/15] net/mlx5: Push devlink port PF/VF init/cleanup calls out of devlink_port_register/unregister() Saeed Mahameed
2023-08-23  5:10 ` [net-next 04/15] net/mlx5: Allow mlx5_esw_offloads_devlink_port_register() to register SFs Saeed Mahameed
2023-08-23  5:10 ` [net-next 05/15] net/mlx5: Introduce mlx5_eswitch_load/unload_sf_vport() and use it from SF code Saeed Mahameed
2023-08-23  5:10 ` [net-next 06/15] net/mlx5: Remove no longer used mlx5_esw_offloads_sf_vport_enable/disable() Saeed Mahameed
2023-08-23  5:10 ` Saeed Mahameed [this message]
2023-08-23  5:10 ` [net-next 08/15] net/mlx5: Embed struct devlink_port into driver structure Saeed Mahameed
2023-08-23  5:10 ` [net-next 09/15] net/mlx5: Reduce number of vport lookups passing vport pointer instead of index Saeed Mahameed
2023-08-23  5:10 ` [net-next 10/15] net/mlx5: Return -EOPNOTSUPP in mlx5_devlink_port_fn_migratable_set() directly Saeed Mahameed
2023-08-23  5:10 ` [net-next 11/15] net/mlx5: Relax mlx5_devlink_eswitch_get() return value checking Saeed Mahameed
2023-08-23  5:10 ` [net-next 12/15] net/mlx5: Check vhca_resource_manager capability in each op and add extack msg Saeed Mahameed
2023-08-23  5:10 ` [net-next 13/15] net/mlx5: Store vport in struct mlx5_devlink_port and use it in port ops Saeed Mahameed
2023-08-23  5:10 ` [net-next 14/15] net/mlx5e: Support IPsec upper protocol selector field offload for RX Saeed Mahameed
2023-08-23  5:10 ` [net-next 15/15] net/mlx5e: Support IPsec upper TCP protocol selector Saeed Mahameed
2023-08-24  2:09 ` [pull request][net-next 00/15] mlx5 updates 2023-08-22 Jakub Kicinski

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=20230823051012.162483-8-saeed@kernel.org \
    --to=saeed@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=shayd@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).