Skip to content

Commit

Permalink
mlxsw: core_env: Convert 'module_info_lock' to a mutex
Browse files Browse the repository at this point in the history
After the previous patch, the lock is always taken in process context so
it can be converted to a mutex. It is needed for future changes where we
will need to be able to sleep when holding the lock.

Convert the lock to a mutex.

Signed-off-by: Ido Schimmel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
idosch authored and davem330 committed Sep 15, 2021
1 parent 163f3d2 commit bd6e43f
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions drivers/net/ethernet/mellanox/mlxsw/core_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <linux/err.h>
#include <linux/ethtool.h>
#include <linux/sfp.h>
#include <linux/mutex.h>

#include "core.h"
#include "core_env.h"
Expand All @@ -19,7 +20,7 @@ struct mlxsw_env_module_info {
struct mlxsw_env {
struct mlxsw_core *core;
u8 module_count;
spinlock_t module_info_lock; /* Protects 'module_info'. */
struct mutex module_info_lock; /* Protects 'module_info'. */
struct mlxsw_env_module_info module_info[];
};

Expand Down Expand Up @@ -507,7 +508,7 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work)
sensor_warning =
mlxsw_reg_mtwe_sensor_warning_get(event->mtwe_pl,
i + MLXSW_REG_MTMP_MODULE_INDEX_MIN);
spin_lock(&mlxsw_env->module_info_lock);
mutex_lock(&mlxsw_env->module_info_lock);
is_overheat =
mlxsw_env->module_info[i].is_overheat;

Expand All @@ -517,21 +518,21 @@ static void mlxsw_env_mtwe_event_work(struct work_struct *work)
* warning OR current state in "no warning" and MTWE
* does not report warning.
*/
spin_unlock(&mlxsw_env->module_info_lock);
mutex_unlock(&mlxsw_env->module_info_lock);
continue;
} else if (is_overheat && !sensor_warning) {
/* MTWE reports "no warning", turn is_overheat off.
*/
mlxsw_env->module_info[i].is_overheat = false;
spin_unlock(&mlxsw_env->module_info_lock);
mutex_unlock(&mlxsw_env->module_info_lock);
} else {
/* Current state is "no warning" and MTWE reports
* "warning", increase the counter and turn is_overheat
* on.
*/
mlxsw_env->module_info[i].is_overheat = true;
mlxsw_env->module_info[i].module_overheat_counter++;
spin_unlock(&mlxsw_env->module_info_lock);
mutex_unlock(&mlxsw_env->module_info_lock);
}
}

Expand Down Expand Up @@ -597,9 +598,9 @@ static void mlxsw_env_pmpe_event_work(struct work_struct *work)
work);
mlxsw_env = event->mlxsw_env;

spin_lock_bh(&mlxsw_env->module_info_lock);
mutex_lock(&mlxsw_env->module_info_lock);
mlxsw_env->module_info[event->module].is_overheat = false;
spin_unlock_bh(&mlxsw_env->module_info_lock);
mutex_unlock(&mlxsw_env->module_info_lock);

err = mlxsw_env_module_has_temp_sensor(mlxsw_env->core, event->module,
&has_temp_sensor);
Expand Down Expand Up @@ -699,9 +700,9 @@ mlxsw_env_module_overheat_counter_get(struct mlxsw_core *mlxsw_core, u8 module,
if (WARN_ON_ONCE(module >= mlxsw_env->module_count))
return -EINVAL;

spin_lock_bh(&mlxsw_env->module_info_lock);
mutex_lock(&mlxsw_env->module_info_lock);
*p_counter = mlxsw_env->module_info[module].module_overheat_counter;
spin_unlock_bh(&mlxsw_env->module_info_lock);
mutex_unlock(&mlxsw_env->module_info_lock);

return 0;
}
Expand All @@ -725,7 +726,7 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env)
if (!env)
return -ENOMEM;

spin_lock_init(&env->module_info_lock);
mutex_init(&env->module_info_lock);
env->core = mlxsw_core;
env->module_count = module_count;
*p_env = env;
Expand Down Expand Up @@ -755,6 +756,7 @@ int mlxsw_env_init(struct mlxsw_core *mlxsw_core, struct mlxsw_env **p_env)
err_module_plug_event_register:
mlxsw_env_temp_warn_event_unregister(env);
err_temp_warn_event_register:
mutex_destroy(&env->module_info_lock);
kfree(env);
return err;
}
Expand All @@ -765,5 +767,6 @@ void mlxsw_env_fini(struct mlxsw_env *env)
/* Make sure there is no more event work scheduled. */
mlxsw_core_flush_owq();
mlxsw_env_temp_warn_event_unregister(env);
mutex_destroy(&env->module_info_lock);
kfree(env);
}

0 comments on commit bd6e43f

Please sign in to comment.