net/mlx5: E-Switch, Prepare to return total vports from eswitch struct
authorParav Pandit <parav@nvidia.com>
Tue, 2 Mar 2021 12:10:49 +0000 (14:10 +0200)
committerSaeed Mahameed <saeedm@nvidia.com>
Sat, 24 Apr 2021 07:58:43 +0000 (00:58 -0700)
Total vports are already stored during eswitch initialization. Instead
of calculating everytime, read directly from eswitch.

Additionally, host PF's SF vport information is available using
QUERY_HCA_CAP command. It is not available through HCA_CAP of the
eswitch manager PF.
Hence, this patch prepares the return total eswitch vport count from the
existing eswitch struct.

This further helps to keep eswitch port counting macros and logic within
eswitch.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Roi Dayan <roid@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
include/linux/mlx5/vport.h

index c3a5822..f0974aa 100644 (file)
@@ -1573,8 +1573,8 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
        if (!MLX5_VPORT_MANAGER(dev))
                return 0;
 
-       total_vports = mlx5_eswitch_get_total_vports(dev);
-
+       total_vports = MLX5_SPECIAL_VPORTS(dev) + mlx5_core_max_vfs(dev) +
+                       mlx5_sf_max_functions(dev);
        esw_info(dev,
                 "Total vports %d, per vport: max uc(%d) max mc(%d)\n",
                 total_vports,
@@ -2215,6 +2215,9 @@ void mlx5_esw_unlock(struct mlx5_eswitch *esw)
  */
 u16 mlx5_eswitch_get_total_vports(const struct mlx5_core_dev *dev)
 {
-       return MLX5_SPECIAL_VPORTS(dev) + mlx5_core_max_vfs(dev) + mlx5_sf_max_functions(dev);
+       struct mlx5_eswitch *esw;
+
+       esw = dev->priv.eswitch;
+       return mlx5_esw_allowed(esw) ? esw->total_vports : 0;
 }
 EXPORT_SYMBOL_GPL(mlx5_eswitch_get_total_vports);
index b289d75..5ab480a 100644 (file)
@@ -545,6 +545,14 @@ static inline u16 mlx5_eswitch_first_host_vport_num(struct mlx5_core_dev *dev)
                MLX5_VPORT_PF : MLX5_VPORT_FIRST_VF;
 }
 
+#define MLX5_VPORT_PF_PLACEHOLDER              (1u)
+#define MLX5_VPORT_UPLINK_PLACEHOLDER          (1u)
+#define MLX5_VPORT_ECPF_PLACEHOLDER(mdev)      (mlx5_ecpf_vport_exists(mdev))
+
+#define MLX5_SPECIAL_VPORTS(mdev) (MLX5_VPORT_PF_PLACEHOLDER +         \
+                                  MLX5_VPORT_UPLINK_PLACEHOLDER +      \
+                                  MLX5_VPORT_ECPF_PLACEHOLDER(mdev))
+
 static inline int mlx5_esw_sf_start_idx(const struct mlx5_eswitch *esw)
 {
        /* PF and VF vports indices start from 0 to max_vfs */
index 4db87bc..aad53cb 100644 (file)
 #include <linux/mlx5/driver.h>
 #include <linux/mlx5/device.h>
 
-#define MLX5_VPORT_PF_PLACEHOLDER              (1u)
-#define MLX5_VPORT_UPLINK_PLACEHOLDER          (1u)
-#define MLX5_VPORT_ECPF_PLACEHOLDER(mdev)      (mlx5_ecpf_vport_exists(mdev))
-
-#define MLX5_SPECIAL_VPORTS(mdev) (MLX5_VPORT_PF_PLACEHOLDER +         \
-                                  MLX5_VPORT_UPLINK_PLACEHOLDER +      \
-                                  MLX5_VPORT_ECPF_PLACEHOLDER(mdev))
-
 #define MLX5_VPORT_MANAGER(mdev)                                       \
        (MLX5_CAP_GEN(mdev, vport_group_manager) &&                     \
         (MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&   \