Commit ad38d47b authored by Amit Cohen's avatar Amit Cohen Committed by David S. Miller

mlxsw: core_hwmon: Split temperature querying from show functions

mlxsw_hwmon_module_temp_show(), mlxsw_hwmon_module_temp_critical_show()
and mlxsw_hwmon_module_temp_emergency_show() query the relevant
temperature from firmware and fill the value in provided buffers.

Split the temperature querying functionality to individual get()
functions and call them from the show() functions.

The get() functions will be used by subsequent patches in the set.
Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
Reviewed-by: default avatarPetr Machata <petrm@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7544abd9
...@@ -205,25 +205,39 @@ static ssize_t mlxsw_hwmon_pwm_store(struct device *dev, ...@@ -205,25 +205,39 @@ static ssize_t mlxsw_hwmon_pwm_store(struct device *dev,
return len; return len;
} }
static ssize_t mlxsw_hwmon_module_temp_show(struct device *dev, static int mlxsw_hwmon_module_temp_get(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) int *p_temp)
{ {
struct mlxsw_hwmon_attr *mlwsw_hwmon_attr = struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
char mtmp_pl[MLXSW_REG_MTMP_LEN]; char mtmp_pl[MLXSW_REG_MTMP_LEN];
u8 module; u8 module;
int temp;
int err; int err;
module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count;
mlxsw_reg_mtmp_pack(mtmp_pl, MLXSW_REG_MTMP_MODULE_INDEX_MIN + module, mlxsw_reg_mtmp_pack(mtmp_pl, MLXSW_REG_MTMP_MODULE_INDEX_MIN + module,
false, false); false, false);
err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl); err = mlxsw_reg_query(mlxsw_hwmon->core, MLXSW_REG(mtmp), mtmp_pl);
if (err) {
dev_err(dev, "Failed to query module temperature\n");
return err;
}
mlxsw_reg_mtmp_unpack(mtmp_pl, p_temp, NULL, NULL);
return 0;
}
static ssize_t mlxsw_hwmon_module_temp_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int err, temp;
err = mlxsw_hwmon_module_temp_get(dev, attr, &temp);
if (err) if (err)
return err; return err;
mlxsw_reg_mtmp_unpack(mtmp_pl, &temp, NULL, NULL);
return sprintf(buf, "%d\n", temp); return sprintf(buf, "%d\n", temp);
} }
...@@ -270,48 +284,72 @@ static ssize_t mlxsw_hwmon_module_temp_fault_show(struct device *dev, ...@@ -270,48 +284,72 @@ static ssize_t mlxsw_hwmon_module_temp_fault_show(struct device *dev,
return sprintf(buf, "%u\n", fault); return sprintf(buf, "%u\n", fault);
} }
static ssize_t static int mlxsw_hwmon_module_temp_critical_get(struct device *dev,
mlxsw_hwmon_module_temp_critical_show(struct device *dev, struct device_attribute *attr,
struct device_attribute *attr, char *buf) int *p_temp)
{ {
struct mlxsw_hwmon_attr *mlwsw_hwmon_attr = struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
int temp;
u8 module; u8 module;
int err; int err;
module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count;
err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module, err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module,
SFP_TEMP_HIGH_WARN, &temp); SFP_TEMP_HIGH_WARN, p_temp);
if (err) { if (err) {
dev_err(dev, "Failed to query module temperature thresholds\n"); dev_err(dev, "Failed to query module temperature thresholds\n");
return err; return err;
} }
return sprintf(buf, "%u\n", temp); return 0;
} }
static ssize_t static ssize_t
mlxsw_hwmon_module_temp_emergency_show(struct device *dev, mlxsw_hwmon_module_temp_critical_show(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr, char *buf)
char *buf) {
int err, temp;
err = mlxsw_hwmon_module_temp_critical_get(dev, attr, &temp);
if (err)
return err;
return sprintf(buf, "%u\n", temp);
}
static int mlxsw_hwmon_module_temp_emergency_get(struct device *dev,
struct device_attribute *attr,
int *p_temp)
{ {
struct mlxsw_hwmon_attr *mlwsw_hwmon_attr = struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
container_of(attr, struct mlxsw_hwmon_attr, dev_attr); container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon; struct mlxsw_hwmon *mlxsw_hwmon = mlwsw_hwmon_attr->hwmon;
u8 module; u8 module;
int temp;
int err; int err;
module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count; module = mlwsw_hwmon_attr->type_index - mlxsw_hwmon->sensor_count;
err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module, err = mlxsw_env_module_temp_thresholds_get(mlxsw_hwmon->core, module,
SFP_TEMP_HIGH_ALARM, &temp); SFP_TEMP_HIGH_ALARM, p_temp);
if (err) { if (err) {
dev_err(dev, "Failed to query module temperature thresholds\n"); dev_err(dev, "Failed to query module temperature thresholds\n");
return err; return err;
} }
return 0;
}
static ssize_t
mlxsw_hwmon_module_temp_emergency_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int err, temp;
err = mlxsw_hwmon_module_temp_emergency_get(dev, attr, &temp);
if (err)
return err;
return sprintf(buf, "%u\n", temp); return sprintf(buf, "%u\n", temp);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment