]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mlxsw: spectrum_router: Expose RIF MAC profiles to devlink resource
authorDanielle Ratson <danieller@nvidia.com>
Tue, 26 Oct 2021 09:42:21 +0000 (12:42 +0300)
committerDavid S. Miller <davem@davemloft.net>
Tue, 26 Oct 2021 12:35:57 +0000 (13:35 +0100)
Expose via devlink-resource the maximum number of RIF MAC profiles and
their current occupancy, so it can be used for debug and writing generic
tests, like in the next patch.

Example for Spectrum-2 output:

$ devlink resource show pci/0000:06:00.0
...
  name rif_mac_profiles size 4 occ 0 unit entry dpipe_tables none

Signed-off-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum.h
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index 66c346a86ec59ebf159e822deee0f67bcab9ccad..5925db386b1ba5bdfae89c23f0d03b88046c2e88 100644 (file)
@@ -3282,6 +3282,30 @@ static int mlxsw_sp_resources_span_register(struct mlxsw_core *mlxsw_core)
                                         &span_size_params);
 }
 
+static int
+mlxsw_sp_resources_rif_mac_profile_register(struct mlxsw_core *mlxsw_core)
+{
+       struct devlink *devlink = priv_to_devlink(mlxsw_core);
+       struct devlink_resource_size_params size_params;
+       u8 max_rif_mac_profiles;
+
+       if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_RIF_MAC_PROFILES))
+               return -EIO;
+
+       max_rif_mac_profiles = MLXSW_CORE_RES_GET(mlxsw_core,
+                                                 MAX_RIF_MAC_PROFILES);
+       devlink_resource_size_params_init(&size_params, max_rif_mac_profiles,
+                                         max_rif_mac_profiles, 1,
+                                         DEVLINK_RESOURCE_UNIT_ENTRY);
+
+       return devlink_resource_register(devlink,
+                                        "rif_mac_profiles",
+                                        max_rif_mac_profiles,
+                                        MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
+                                        DEVLINK_RESOURCE_ID_PARENT_TOP,
+                                        &size_params);
+}
+
 static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
 {
        int err;
@@ -3300,10 +3324,16 @@ static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
 
        err = mlxsw_sp_policer_resources_register(mlxsw_core);
        if (err)
-               goto err_resources_counter_register;
+               goto err_policer_resources_register;
+
+       err = mlxsw_sp_resources_rif_mac_profile_register(mlxsw_core);
+       if (err)
+               goto err_resources_rif_mac_profile_register;
 
        return 0;
 
+err_resources_rif_mac_profile_register:
+err_policer_resources_register:
 err_resources_counter_register:
 err_resources_span_register:
        devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL);
@@ -3328,10 +3358,16 @@ static int mlxsw_sp2_resources_register(struct mlxsw_core *mlxsw_core)
 
        err = mlxsw_sp_policer_resources_register(mlxsw_core);
        if (err)
-               goto err_resources_counter_register;
+               goto err_policer_resources_register;
+
+       err = mlxsw_sp_resources_rif_mac_profile_register(mlxsw_core);
+       if (err)
+               goto err_resources_rif_mac_profile_register;
 
        return 0;
 
+err_resources_rif_mac_profile_register:
+err_policer_resources_register:
 err_resources_counter_register:
 err_resources_span_register:
        devlink_resources_unregister(priv_to_devlink(mlxsw_core), NULL);
index 3ab57e98cad22700537cfc27859083cb5d364828..32fdd37657ddae06b8e6c85520231c0ac5838bbc 100644 (file)
@@ -67,6 +67,7 @@ enum mlxsw_sp_resource_id {
        MLXSW_SP_RESOURCE_COUNTERS_RIF,
        MLXSW_SP_RESOURCE_GLOBAL_POLICERS,
        MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
+       MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
 };
 
 struct mlxsw_sp_port;
index f7b18192e2c7b5c605e95ef7c7c01a20a9bf026f..217e3b351dfe6048f90e9f93930a23fde8b2e09f 100644 (file)
@@ -9762,6 +9762,7 @@ static const struct mlxsw_sp_rif_ops *mlxsw_sp2_rif_ops_arr[] = {
 static int mlxsw_sp_rifs_init(struct mlxsw_sp *mlxsw_sp)
 {
        u64 max_rifs = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
        struct mlxsw_core *core = mlxsw_sp->core;
 
        if (!MLXSW_CORE_RES_VALID(core, MAX_RIF_MAC_PROFILES))
@@ -9777,17 +9778,24 @@ static int mlxsw_sp_rifs_init(struct mlxsw_sp *mlxsw_sp)
 
        idr_init(&mlxsw_sp->router->rif_mac_profiles_idr);
        atomic_set(&mlxsw_sp->router->rif_mac_profiles_count, 0);
+       devlink_resource_occ_get_register(devlink,
+                                         MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
+                                         mlxsw_sp_rif_mac_profiles_occ_get,
+                                         mlxsw_sp);
 
        return 0;
 }
 
 static void mlxsw_sp_rifs_fini(struct mlxsw_sp *mlxsw_sp)
 {
+       struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
        int i;
 
        for (i = 0; i < MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); i++)
                WARN_ON_ONCE(mlxsw_sp->router->rifs[i]);
 
+       devlink_resource_occ_get_unregister(devlink,
+                                           MLXSW_SP_RESOURCE_RIF_MAC_PROFILES);
        WARN_ON(!idr_is_empty(&mlxsw_sp->router->rif_mac_profiles_idr));
        idr_destroy(&mlxsw_sp->router->rif_mac_profiles_idr);
        kfree(mlxsw_sp->router->rifs);