Commit 2752b823 authored by Parav Pandit's avatar Parav Pandit Committed by Saeed Mahameed
Browse files

net/mlx5: Introduce and use mlx5_eswitch_get_total_vports()



Instead MLX5_TOTAL_VPORTS, use mlx5_eswitch_get_total_vports().
mlx5_eswitch_get_total_vports() in subsequent patch accounts for SF
vports as well.
Expanding MLX5_TOTAL_VPORTS macro would require exposing SF internals to
more generic vport.h header file. Such exposure is not desired.
Hence a mlx5_eswitch_get_total_vports() is introduced.

Given that mlx5_eswitch_get_total_vports() API wants to work on const
mlx5_core_dev*, change its helper functions also to accept const *dev.

Signed-off-by: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent e4075c44
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ mlx5_ib_set_vport_rep(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
static int
mlx5_ib_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
{
	int num_ports = MLX5_TOTAL_VPORTS(dev);
	int num_ports = mlx5_eswitch_get_total_vports(dev);
	const struct mlx5_ib_profile *profile;
	struct mlx5_ib_dev *ibdev;
	int vport_index;
+3 −1
Original line number Diff line number Diff line
@@ -1868,14 +1868,16 @@ void mlx5_eswitch_disable(struct mlx5_eswitch *esw)

int mlx5_eswitch_init(struct mlx5_core_dev *dev)
{
	int total_vports = MLX5_TOTAL_VPORTS(dev);
	struct mlx5_eswitch *esw;
	struct mlx5_vport *vport;
	int total_vports;
	int err, i;

	if (!MLX5_VPORT_MANAGER(dev))
		return 0;

	total_vports = mlx5_eswitch_get_total_vports(dev);

	esw_info(dev,
		 "Total vports %d, per vport: max uc(%d) max mc(%d)\n",
		 total_vports,
+1 −1
Original line number Diff line number Diff line
@@ -1394,7 +1394,7 @@ void esw_offloads_cleanup_reps(struct mlx5_eswitch *esw)

int esw_offloads_init_reps(struct mlx5_eswitch *esw)
{
	int total_vports = MLX5_TOTAL_VPORTS(esw->dev);
	int total_vports = esw->total_vports;
	struct mlx5_core_dev *dev = esw->dev;
	struct mlx5_eswitch_rep *rep;
	u8 hw_id[ETH_ALEN], rep_type;
+15 −11
Original line number Diff line number Diff line
@@ -2090,7 +2090,7 @@ struct mlx5_flow_namespace *mlx5_get_flow_vport_acl_namespace(struct mlx5_core_d
{
	struct mlx5_flow_steering *steering = dev->priv.steering;

	if (!steering || vport >= MLX5_TOTAL_VPORTS(dev))
	if (!steering || vport >= mlx5_eswitch_get_total_vports(dev))
		return NULL;

	switch (type) {
@@ -2421,7 +2421,7 @@ static void cleanup_egress_acls_root_ns(struct mlx5_core_dev *dev)
	if (!steering->esw_egress_root_ns)
		return;

	for (i = 0; i < MLX5_TOTAL_VPORTS(dev); i++)
	for (i = 0; i < mlx5_eswitch_get_total_vports(dev); i++)
		cleanup_root_ns(steering->esw_egress_root_ns[i]);

	kfree(steering->esw_egress_root_ns);
@@ -2435,7 +2435,7 @@ static void cleanup_ingress_acls_root_ns(struct mlx5_core_dev *dev)
	if (!steering->esw_ingress_root_ns)
		return;

	for (i = 0; i < MLX5_TOTAL_VPORTS(dev); i++)
	for (i = 0; i < mlx5_eswitch_get_total_vports(dev); i++)
		cleanup_root_ns(steering->esw_ingress_root_ns[i]);

	kfree(steering->esw_ingress_root_ns);
@@ -2614,16 +2614,18 @@ static int init_ingress_acl_root_ns(struct mlx5_flow_steering *steering, int vpo
static int init_egress_acls_root_ns(struct mlx5_core_dev *dev)
{
	struct mlx5_flow_steering *steering = dev->priv.steering;
	int total_vports = mlx5_eswitch_get_total_vports(dev);
	int err;
	int i;

	steering->esw_egress_root_ns = kcalloc(MLX5_TOTAL_VPORTS(dev),
	steering->esw_egress_root_ns =
			kcalloc(total_vports,
				sizeof(*steering->esw_egress_root_ns),
				GFP_KERNEL);
	if (!steering->esw_egress_root_ns)
		return -ENOMEM;

	for (i = 0; i < MLX5_TOTAL_VPORTS(dev); i++) {
	for (i = 0; i < total_vports; i++) {
		err = init_egress_acl_root_ns(steering, i);
		if (err)
			goto cleanup_root_ns;
@@ -2641,16 +2643,18 @@ cleanup_root_ns:
static int init_ingress_acls_root_ns(struct mlx5_core_dev *dev)
{
	struct mlx5_flow_steering *steering = dev->priv.steering;
	int total_vports = mlx5_eswitch_get_total_vports(dev);
	int err;
	int i;

	steering->esw_ingress_root_ns = kcalloc(MLX5_TOTAL_VPORTS(dev),
	steering->esw_ingress_root_ns =
			kcalloc(total_vports,
				sizeof(*steering->esw_ingress_root_ns),
				GFP_KERNEL);
	if (!steering->esw_ingress_root_ns)
		return -ENOMEM;

	for (i = 0; i < MLX5_TOTAL_VPORTS(dev); i++) {
	for (i = 0; i < total_vports; i++) {
		err = init_ingress_acl_root_ns(steering, i);
		if (err)
			goto cleanup_root_ns;
+15 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <linux/etherdevice.h>
#include <linux/mlx5/driver.h>
#include <linux/mlx5/vport.h>
#include <linux/mlx5/eswitch.h>
#include "mlx5_core.h"

/* Mutex to hold while enabling or disabling RoCE */
@@ -1165,3 +1166,17 @@ u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev)
	return tmp;
}
EXPORT_SYMBOL_GPL(mlx5_query_nic_system_image_guid);

/**
 * mlx5_eswitch_get_total_vports - Get total vports of the eswitch
 *
 * @dev:	Pointer to core device
 *
 * mlx5_eswitch_get_total_vports returns total number of vports for
 * the eswitch.
 */
u16 mlx5_eswitch_get_total_vports(const struct mlx5_core_dev *dev)
{
	return MLX5_SPECIAL_VPORTS(dev) + mlx5_core_max_vfs(dev);
}
EXPORT_SYMBOL(mlx5_eswitch_get_total_vports);
Loading