net/mlx5: Introduce and use mlx5_eswitch_get_total_vports()
authorParav Pandit <parav@mellanox.com>
Wed, 15 May 2019 05:04:27 +0000 (00:04 -0500)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 3 Jul 2019 19:50:42 +0000 (12:50 -0700)
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: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/infiniband/hw/mlx5/ib_rep.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
drivers/net/ethernet/mellanox/mlx5/core/vport.c
include/linux/mlx5/driver.h
include/linux/mlx5/eswitch.h
include/linux/mlx5/vport.h

index 3065c5d0ee9610488927dce4d29f472419586bed..f2cb789d2331296bea11996ea081be5fa9a71f4e 100644 (file)
@@ -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;
index 89f52370e770b72103dabad88f6adfc181ebde1d..9137a8390216d744f1756f34b4c6a5788153ab10 100644 (file)
@@ -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,
index 50e5841c169810bc2bf2e421ece496fb7ef67518..5c8fb2597bfab36463d4b0d1fb234a64ca8d7a00 100644 (file)
@@ -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;
index 9f5544ac6b8a581b3c1fd101ee45c458bd70e307..8162252585ad26eff7114e793448b29d5be06696 100644 (file)
@@ -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),
-                                              sizeof(*steering->esw_egress_root_ns),
-                                              GFP_KERNEL);
+       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),
-                                               sizeof(*steering->esw_ingress_root_ns),
-                                               GFP_KERNEL);
+       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;
index 670fa493c5f5bdb89ab492b901293edcbbb00403..c912d82ca64bf9b48e9546cdd972973ca82f4f8a 100644 (file)
@@ -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);
index 24b02ab206c332af9c9da92b204a8ccef1d382c9..031043341ed589fc91075cd1562a84cbb95ac28f 100644 (file)
@@ -1085,7 +1085,7 @@ enum {
        MLX5_PCI_DEV_IS_VF              = 1 << 0,
 };
 
-static inline bool mlx5_core_is_pf(struct mlx5_core_dev *dev)
+static inline bool mlx5_core_is_pf(const struct mlx5_core_dev *dev)
 {
        return dev->coredev_type == MLX5_COREDEV_PF;
 }
@@ -1095,17 +1095,18 @@ static inline bool mlx5_core_is_ecpf(struct mlx5_core_dev *dev)
        return dev->caps.embedded_cpu;
 }
 
-static inline bool mlx5_core_is_ecpf_esw_manager(struct mlx5_core_dev *dev)
+static inline bool
+mlx5_core_is_ecpf_esw_manager(const struct mlx5_core_dev *dev)
 {
        return dev->caps.embedded_cpu && MLX5_CAP_GEN(dev, eswitch_manager);
 }
 
-static inline bool mlx5_ecpf_vport_exists(struct mlx5_core_dev *dev)
+static inline bool mlx5_ecpf_vport_exists(const struct mlx5_core_dev *dev)
 {
        return mlx5_core_is_pf(dev) && MLX5_CAP_ESW(dev, ecpf_vport_exists);
 }
 
-static inline u16 mlx5_core_max_vfs(struct mlx5_core_dev *dev)
+static inline u16 mlx5_core_max_vfs(const struct mlx5_core_dev *dev)
 {
        return dev->priv.sriov.max_vfs;
 }
index d4731199edb4e70a267c9a006215c868c9c2891f..61db37aa9642f3d69d15cfae89ad7c2678c2ebee 100644 (file)
@@ -66,6 +66,8 @@ struct mlx5_flow_handle *
 mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch *esw,
                                    int vport, u32 sqn);
 
+u16 mlx5_eswitch_get_total_vports(const struct mlx5_core_dev *dev);
+
 #ifdef CONFIG_MLX5_ESWITCH
 enum devlink_eswitch_encap_mode
 mlx5_eswitch_get_encap_mode(const struct mlx5_core_dev *dev);
@@ -93,4 +95,5 @@ mlx5_eswitch_get_vport_metadata_for_match(const struct mlx5_eswitch *esw,
        return 0;
 };
 #endif /* CONFIG_MLX5_ESWITCH */
+
 #endif
index 6cbf29229749287c632d7f2e64a1347f011de5b3..16060fb9b5e5619582903df517a95f5bb2a3b77c 100644 (file)
@@ -44,9 +44,6 @@
                                   MLX5_VPORT_UPLINK_PLACEHOLDER +      \
                                   MLX5_VPORT_ECPF_PLACEHOLDER(mdev))
 
-#define MLX5_TOTAL_VPORTS(mdev)        (MLX5_SPECIAL_VPORTS(mdev) +            \
-                                mlx5_core_max_vfs(mdev))
-
 #define MLX5_VPORT_MANAGER(mdev)                                       \
        (MLX5_CAP_GEN(mdev, vport_group_manager) &&                     \
         (MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&   \