net/mlx5: E-Switch, Use getter to access all vport array
authorBodong Wang <bodong@mellanox.com>
Mon, 15 Apr 2019 22:36:43 +0000 (17:36 -0500)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 1 May 2019 21:39:17 +0000 (14:39 -0700)
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>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

index 41afc7b..0107ce8 100644 (file)
@@ -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;
index fc512a5..2e6b37d 100644 (file)
@@ -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; }