Netdev List
 help / color / mirror / Atom feed
From: Parav Pandit <parav@mellanox.com>
To: netdev@vger.kernel.org
Cc: saeedm@mellanox.com, davem@davemloft.net, kuba@kernel.org,
	jiri@mellanox.com, Parav Pandit <parav@mellanox.com>,
	Roi Dayan <roid@mellanox.com>
Subject: [PATCH net-next 8/9] net/mlx5: Split mac address setting function for using state_lock
Date: Fri, 19 Jun 2020 03:32:54 +0000	[thread overview]
Message-ID: <20200619033255.163-9-parav@mellanox.com> (raw)
In-Reply-To: <20200619033255.163-1-parav@mellanox.com>

Refactor mac address setting function to let caller hold the necessary
state_lock mutex, so that subsequent patch and use this helper routine.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/eswitch.c | 38 ++++++++++++-------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 999e51656e16..2c08411e34ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -1801,46 +1801,56 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
 }
 
 /* Vport Administration */
-int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
-			       u16 vport, const u8 *mac)
+static int
+mlx5_esw_set_vport_mac_locked(struct mlx5_eswitch *esw,
+			      struct mlx5_vport *evport, const u8 *mac)
 {
-	struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
+	u16 vport_num = evport->vport;
 	u64 node_guid;
 	int err = 0;
 
-	if (IS_ERR(evport))
-		return PTR_ERR(evport);
 	if (is_multicast_ether_addr(mac))
 		return -EINVAL;
 
-	mutex_lock(&esw->state_lock);
-
 	if (evport->info.spoofchk && !is_valid_ether_addr(mac))
 		mlx5_core_warn(esw->dev,
 			       "Set invalid MAC while spoofchk is on, vport(%d)\n",
-			       vport);
+			       vport_num);
 
-	err = mlx5_modify_nic_vport_mac_address(esw->dev, vport, mac);
+	err = mlx5_modify_nic_vport_mac_address(esw->dev, vport_num, mac);
 	if (err) {
 		mlx5_core_warn(esw->dev,
 			       "Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n",
-			       vport, err);
-		goto unlock;
+			       vport_num, err);
+		return err;
 	}
 
 	node_guid_gen_from_mac(&node_guid, mac);
-	err = mlx5_modify_nic_vport_node_guid(esw->dev, vport, node_guid);
+	err = mlx5_modify_nic_vport_node_guid(esw->dev, vport_num, node_guid);
 	if (err)
 		mlx5_core_warn(esw->dev,
 			       "Failed to set vport %d node guid, err = %d. RDMA_CM will not function properly for this VF.\n",
-			       vport, err);
+			       vport_num, err);
 
 	ether_addr_copy(evport->info.mac, mac);
 	evport->info.node_guid = node_guid;
 	if (evport->enabled && esw->mode == MLX5_ESWITCH_LEGACY)
 		err = esw_acl_ingress_lgcy_setup(esw, evport);
 
-unlock:
+	return err;
+}
+
+int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
+			       u16 vport, const u8 *mac)
+{
+	struct mlx5_vport *evport = mlx5_eswitch_get_vport(esw, vport);
+	int err = 0;
+
+	if (IS_ERR(evport))
+		return PTR_ERR(evport);
+
+	mutex_lock(&esw->state_lock);
+	err = mlx5_esw_set_vport_mac_locked(esw, evport, mac);
 	mutex_unlock(&esw->state_lock);
 	return err;
 }
-- 
2.19.2


  parent reply	other threads:[~2020-06-19  3:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19  3:32 [PATCH net-next 0/9] devlink: Support get,set mac address of a port function Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 1/9] net/devlink: Prepare devlink port functions to fill extack Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 2/9] net/devlink: Support querying hardware address of port function Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 3/9] net/devlink: Support setting " Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 4/9] net/mlx5: Constify mac address pointer Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 5/9] net/mlx5: E-switch, Introduce and use eswitch support check helper Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 6/9] net/mlx5: Move helper to eswitch layer Parav Pandit
2020-06-19  3:32 ` [PATCH net-next 7/9] net/mlx5: E-switch, Support querying port function mac address Parav Pandit
2020-06-19  3:32 ` Parav Pandit [this message]
2020-06-19  3:32 ` [PATCH net-next 9/9] net/mlx5: E-switch, Supporting setting devlink " Parav Pandit
2020-06-22 22:29 ` [PATCH net-next 0/9] devlink: Support get,set mac address of a port function David Miller

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=20200619033255.163-9-parav@mellanox.com \
    --to=parav@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=jiri@mellanox.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=roid@mellanox.com \
    --cc=saeedm@mellanox.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