mlxsw: core: Add QSFP module temperature label attribute to hwmon
authorVadim Pasternak <vadimp@mellanox.com>
Wed, 13 Feb 2019 11:28:55 +0000 (11:28 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 14 Feb 2019 06:33:02 +0000 (22:33 -0800)
Add label attribute to hwmon object for exposing QSFP module's
temperature sensor name. Modules are labeled as "front panel xxx". The
label is used by utilities such as "sensors":

front panel 001:   +0.0C  (crit =  +0.0C, emerg =  +0.0C)
..
front panel 020:  +31.0C  (crit = +70.0C, emerg = +80.0C)
..
front panel 056:  +41.0C  (crit = +70.0C, emerg = +80.0C)

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c

index 504f6bba8874e43e67f0fce7eae982f8e7cdb5e1..f1ada4cdbd6b81b036f2e5834526c954df55081e 100644 (file)
@@ -321,6 +321,18 @@ mlxsw_hwmon_module_temp_emergency_show(struct device *dev,
        return sprintf(buf, "%u\n", temp);
 }
 
+static ssize_t
+mlxsw_hwmon_module_temp_label_show(struct device *dev,
+                                  struct device_attribute *attr,
+                                  char *buf)
+{
+       struct mlxsw_hwmon_attr *mlwsw_hwmon_attr =
+                       container_of(attr, struct mlxsw_hwmon_attr, dev_attr);
+
+       return sprintf(buf, "front panel %03u\n",
+                      mlwsw_hwmon_attr->type_index);
+}
+
 enum mlxsw_hwmon_attr_type {
        MLXSW_HWMON_ATTR_TYPE_TEMP,
        MLXSW_HWMON_ATTR_TYPE_TEMP_MAX,
@@ -332,6 +344,7 @@ enum mlxsw_hwmon_attr_type {
        MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_FAULT,
        MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_CRIT,
        MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
+       MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
 };
 
 static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
@@ -408,6 +421,13 @@ static void mlxsw_hwmon_attr_add(struct mlxsw_hwmon *mlxsw_hwmon,
                snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
                         "temp%u_emergency", num + 1);
                break;
+       case MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL:
+               mlxsw_hwmon_attr->dev_attr.show =
+                       mlxsw_hwmon_module_temp_label_show;
+               mlxsw_hwmon_attr->dev_attr.attr.mode = 0444;
+               snprintf(mlxsw_hwmon_attr->name, sizeof(mlxsw_hwmon_attr->name),
+                        "temp%u_label", num + 1);
+               break;
        default:
                WARN_ON(1);
        }
@@ -528,6 +548,9 @@ static int mlxsw_hwmon_module_init(struct mlxsw_hwmon *mlxsw_hwmon)
                mlxsw_hwmon_attr_add(mlxsw_hwmon,
                                     MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_EMERG,
                                     index, index);
+               mlxsw_hwmon_attr_add(mlxsw_hwmon,
+                                    MLXSW_HWMON_ATTR_TYPE_TEMP_MODULE_LABEL,
+                                    index, index);
                index++;
        }