netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeedm@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Bodong Wang <bodong@mellanox.com>, Vu Pham <vuhuong@mellanox.com>,
	Parav Pandit <parav@mellanox.com>,
	Saeed Mahameed <saeedm@mellanox.com>
Subject: [net-next 13/15] net/mlx5: E-Switch, Use getter to access all vport array
Date: Tue, 30 Apr 2019 20:40:09 +0000	[thread overview]
Message-ID: <20190430203926.19284-14-saeedm@mellanox.com> (raw)
In-Reply-To: <20190430203926.19284-1-saeedm@mellanox.com>

From: Bodong Wang <bodong@mellanox.com>

Some functions issue vport commands and access vport array using
vport_index/vport_num interchangeably which is OK for VFs vports.
However, this creates potential bug if those vports are not VFs
(E.g, uplink, sf) where their vport_index don't equal to vport_num.

Prepare code to access mlx5_vport structure using a getter function.

Signed-off-by: Bodong Wang <bodong@mellanox.com>
Signed-off-by: Vu Pham <vuhuong@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/eswitch.c  | 18 +++++++++---------
 .../net/ethernet/mellanox/mlx5/core/eswitch.h  |  2 ++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
index 41afc7bf8bd8..0107ce8bf659 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
@@ -72,8 +72,8 @@ static void esw_cleanup_vepa_rules(struct mlx5_eswitch *esw);
 			    MC_ADDR_CHANGE | \
 			    PROMISC_CHANGE)
 
-static struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw,
-						 u16 vport_num)
+struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw,
+					  u16 vport_num)
 {
 	u16 idx = mlx5_eswitch_vport_num_to_index(esw, vport_num);
 
@@ -1916,7 +1916,7 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
 		return -EINVAL;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 
 	if (evport->info.spoofchk && !is_valid_ether_addr(mac))
 		mlx5_core_warn(esw->dev,
@@ -1960,7 +1960,7 @@ int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
 		return -EINVAL;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 
 	err = mlx5_modify_vport_admin_state(esw->dev,
 					    MLX5_VPORT_STATE_OP_MOD_ESW_VPORT,
@@ -1989,7 +1989,7 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
 	if (!LEGAL_VPORT(esw, vport))
 		return -EINVAL;
 
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 
 	memset(ivi, 0, sizeof(*ivi));
 	ivi->vf = vport - 1;
@@ -2020,7 +2020,7 @@ int __mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
 		return -EINVAL;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 
 	err = modify_esw_vport_cvlan(esw->dev, vport, vlan, qos, set_flags);
 	if (err)
@@ -2064,7 +2064,7 @@ int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch *esw,
 		return -EINVAL;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 	pschk = evport->info.spoofchk;
 	evport->info.spoofchk = spoofchk;
 	if (pschk && !is_valid_ether_addr(evport->info.mac))
@@ -2213,7 +2213,7 @@ int mlx5_eswitch_set_vport_trust(struct mlx5_eswitch *esw,
 		return -EINVAL;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 	evport->info.trusted = setting;
 	if (evport->enabled)
 		esw_vport_change_handle_locked(evport);
@@ -2299,7 +2299,7 @@ int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, int vport,
 		return -EOPNOTSUPP;
 
 	mutex_lock(&esw->state_lock);
-	evport = &esw->vports[vport];
+	evport = mlx5_eswitch_get_vport(esw, vport);
 
 	if (min_rate == evport->info.min_rate)
 		goto set_max_rate;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
index fc512a5d0c4c..2e6b37d4fc7f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
@@ -488,6 +488,8 @@ void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);
 #define mlx5_esw_for_each_vf_vport_num_reverse(esw, vport, nvfs)	\
 	for ((vport) = (nvfs); (vport) >= MLX5_VPORT_FIRST_VF; (vport)--)
 
+struct mlx5_vport *mlx5_eswitch_get_vport(struct mlx5_eswitch *esw,
+					  u16 vport_num);
 #else  /* CONFIG_MLX5_ESWITCH */
 /* eswitch API stubs */
 static inline int  mlx5_eswitch_init(struct mlx5_core_dev *dev) { return 0; }
-- 
2.20.1


  parent reply	other threads:[~2019-04-30 20:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 20:39 [pull request][net-next 00/15] Mellanox, mlx5 updates 2019-04-30 Saeed Mahameed
2019-04-30 20:39 ` [net-next 01/15] net/mlx5e: Take common TIR context settings into a function Saeed Mahameed
2019-04-30 20:39 ` [net-next 02/15] net/mlx5e: Turn on HW tunnel offload in all TIRs Saeed Mahameed
2019-04-30 20:39 ` [net-next 03/15] net/mlx5e: ACLs for priority tag mode Saeed Mahameed
2019-04-30 20:39 ` [net-next 04/15] net/mlx5e: Replace TC VLAN pop with VLAN 0 rewrite in prio " Saeed Mahameed
2019-04-30 20:39 ` [net-next 05/15] net/mlx5e: Return error when trying to insert existing flower filter Saeed Mahameed
2019-04-30 20:39 ` [net-next 06/15] ethtool: Add SFF-8436 and SFF-8636 max EEPROM length definitions Saeed Mahameed
2019-04-30 20:39 ` [net-next 07/15] net/mlx5e: ethtool, Add support for EEPROM high pages query Saeed Mahameed
2019-04-30 20:39 ` [net-next 08/15] net/mlx5e: Put the common XDP code into a function Saeed Mahameed
2019-04-30 20:40 ` [net-next 09/15] net/mlx5e: remove meaningless CFLAGS_tracepoint.o Saeed Mahameed
2019-04-30 20:40 ` [net-next 10/15] net/mlx5: Remove unused mlx5_query_nic_vport_vlans Saeed Mahameed
2019-04-30 20:40 ` [net-next 11/15] net/mlx5: Reuse mlx5_esw_for_each_vf_vport macro in two files Saeed Mahameed
2019-04-30 20:40 ` [net-next 12/15] net/mlx5: Use available mlx5_vport struct Saeed Mahameed
2019-04-30 20:40 ` Saeed Mahameed [this message]
2019-04-30 20:40 ` [net-next 14/15] net/mlx5: E-Switch, Fix the check of legal vport Saeed Mahameed
2019-04-30 20:40 ` [net-next 15/15] net/mlx5: E-Switch, Use atomic rep state to serialize state change Saeed Mahameed
2019-05-01 21:43 ` [pull request][net-next 00/15] Mellanox, mlx5 updates 2019-04-30 Saeed Mahameed
2019-05-01 23:52   ` 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=20190430203926.19284-14-saeedm@mellanox.com \
    --to=saeedm@mellanox.com \
    --cc=bodong@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=parav@mellanox.com \
    --cc=vuhuong@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;
as well as URLs for NNTP newsgroup(s).