]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mlxsw: Add a helper function for getting maximum LAG ID
authorAmit Cohen <amcohen@nvidia.com>
Fri, 26 Aug 2022 16:06:51 +0000 (18:06 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 31 Aug 2022 06:20:43 +0000 (23:20 -0700)
Currently the driver queries the maximum supported LAG ID from firmware.
This will not be accurate anymore once the driver will configure 'max_lag'
via CONFIG_PROFILE command.

For resource query, firmware returns the maximum LAG ID which is supported
by hardware. Software can configure firmware to do not allocate entries for
all the supported LAGs, and to limit LAG IDs. In this case, the resource
query will not return the actual maximum LAG ID.

Add a helper function for getting this value. In case that 'max_lag' field
was set during initialization, return the value which was used, otherwise,
query firmware for the maximum supported ID.

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlxsw/core.c
drivers/net/ethernet/mellanox/mlxsw/core.h
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index afbe046b35a0bf00b2d850d43c093c00bd18362f..1d14b1d8c500525b949278de6ace422b95e01539 100644 (file)
@@ -186,6 +186,23 @@ unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core)
 }
 EXPORT_SYMBOL(mlxsw_core_max_ports);
 
+int mlxsw_core_max_lag(struct mlxsw_core *mlxsw_core, u16 *p_max_lag)
+{
+       struct mlxsw_driver *driver = mlxsw_core->driver;
+
+       if (driver->profile->used_max_lag) {
+               *p_max_lag = driver->profile->max_lag;
+               return 0;
+       }
+
+       if (!MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG))
+               return -EIO;
+
+       *p_max_lag = MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG);
+       return 0;
+}
+EXPORT_SYMBOL(mlxsw_core_max_lag);
+
 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core)
 {
        return mlxsw_core->driver_priv;
@@ -2099,6 +2116,7 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
        struct mlxsw_core *mlxsw_core;
        struct mlxsw_driver *mlxsw_driver;
        size_t alloc_size;
+       u16 max_lag;
        int err;
 
        mlxsw_driver = mlxsw_core_driver_get(device_kind);
@@ -2140,10 +2158,9 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
        if (err)
                goto err_ports_init;
 
-       if (MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG) &&
-           MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG_MEMBERS)) {
-               alloc_size = sizeof(*mlxsw_core->lag.mapping) *
-                       MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG) *
+       err = mlxsw_core_max_lag(mlxsw_core, &max_lag);
+       if (!err && MLXSW_CORE_RES_VALID(mlxsw_core, MAX_LAG_MEMBERS)) {
+               alloc_size = sizeof(*mlxsw_core->lag.mapping) * max_lag *
                        MLXSW_CORE_RES_GET(mlxsw_core, MAX_LAG_MEMBERS);
                mlxsw_core->lag.mapping = kzalloc(alloc_size, GFP_KERNEL);
                if (!mlxsw_core->lag.mapping) {
index 383c423c3ef8dd91314d1eed6472778811f60dd8..ca0c3d2bee6b31e247997557a138477c662dab94 100644 (file)
@@ -35,6 +35,8 @@ struct mlxsw_fw_rev;
 
 unsigned int mlxsw_core_max_ports(const struct mlxsw_core *mlxsw_core);
 
+int mlxsw_core_max_lag(struct mlxsw_core *mlxsw_core, u16 *p_max_lag);
+
 void *mlxsw_core_driver_priv(struct mlxsw_core *mlxsw_core);
 
 struct mlxsw_linecards *mlxsw_core_linecards(struct mlxsw_core *mlxsw_core);
index 30c7b0e1572181b76e87e3597a28e7652ed9d4aa..c71a040502799bd5b290a2558e33622012def311 100644 (file)
@@ -2691,6 +2691,7 @@ static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp)
 static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
 {
        char slcr_pl[MLXSW_REG_SLCR_LEN];
+       u16 max_lag;
        u32 seed;
        int err;
 
@@ -2709,12 +2710,14 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
        if (err)
                return err;
 
-       if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_LAG) ||
-           !MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_LAG_MEMBERS))
+       err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag);
+       if (err)
+               return err;
+
+       if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_LAG_MEMBERS))
                return -EIO;
 
-       mlxsw_sp->lags = kcalloc(MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_LAG),
-                                sizeof(struct mlxsw_sp_upper),
+       mlxsw_sp->lags = kcalloc(max_lag, sizeof(struct mlxsw_sp_upper),
                                 GFP_KERNEL);
        if (!mlxsw_sp->lags)
                return -ENOMEM;
@@ -4263,10 +4266,13 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp,
 {
        struct mlxsw_sp_upper *lag;
        int free_lag_id = -1;
-       u64 max_lag;
-       int i;
+       u16 max_lag;
+       int err, i;
+
+       err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag);
+       if (err)
+               return err;
 
-       max_lag = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_LAG);
        for (i = 0; i < max_lag; i++) {
                lag = mlxsw_sp_lag_get(mlxsw_sp, i);
                if (lag->ref_count) {