linux/drivers/net/ethernet/intel/ice/ice_hwmon.c

127 lines
2.7 KiB
C
Raw Normal View History

ice: read internal temperature sensor Since 4.30 firmware exposes internal thermal sensor reading via admin queue commands. Expose those readouts via hwmon API when supported. Datasheet: Get Sensor Reading Command (Opcode: 0x0632) +--------------------+--------+--------------------+-------------------------+ | Name | Bytes | Value | Remarks | +--------------------+--------+--------------------+-------------------------+ | Flags | 1-0 | | | | Opcode | 2-3 | 0x0632 | Command opcode | | Datalen | 4-5 | 0 | No external buffer. | | Return value | 6-7 | | Return value. | | Cookie High | 8-11 | Cookie | | | Cookie Low | 12-15 | Cookie | | | Sensor | 16 | | 0x00: Internal temp | | | | | 0x01-0xFF: Reserved. | | Format | 17 | Requested response | Only 0x00 is supported. | | | | format | 0x01-0xFF: Reserved. | | Reserved | 18-23 | | | | Data Address high | 24-27 | Response buffer | | | | | address | | | Data Address low | 28-31 | Response buffer | | | | | address | | +--------------------+--------+--------------------+-------------------------+ Get Sensor Reading Response (Opcode: 0x0632) +--------------------+--------+--------------------+-------------------------+ | Name | Bytes | Value | Remarks | +--------------------+--------+--------------------+-------------------------+ | Flags | 1-0 | | | | Opcode | 2-3 | 0x0632 | Command opcode | | Datalen | 4-5 | 0 | No external buffer | | Return value | 6-7 | | Return value. | | | | | EINVAL: Invalid | | | | | parameters | | | | | ENOENT: Unsupported | | | | | sensor | | | | | EIO: Sensor access | | | | | error | | Cookie High | 8-11 | Cookie | | | Cookie Low | 12-15 | Cookie | | | Sensor Reading | 16-23 | | Format of the reading | | | | | is dependent on request | | Data Address high | 24-27 | Response buffer | | | | | address | | | Data Address low | 28-31 | Response buffer | | | | | address | | +--------------------+--------+--------------------+-------------------------+ Sensor Reading for Sensor 0x00 (Internal Chip Temperature): +--------------------+--------+--------------------+-------------------------+ | Name | Bytes | Value | Remarks | +--------------------+--------+--------------------+-------------------------+ | Thermal Sensor | 0 | | Reading in degrees | | reading | | | Celsius. Signed int8 | | Warning High | 1 | | Warning High threshold | | threshold | | | in degrees Celsius. | | | | | Unsigned int8. | | | | | 0xFF when unsupported | | Critical High | 2 | | Critical High threshold | | threshold | | | in degrees Celsius. | | | | | Unsigned int8. | | | | | 0xFF when unsupported | | Fatal High | 3 | | Fatal High threshold | | threshold | | | in degrees Celsius. | | | | | Unsigned int8. | | | | | 0xFF when unsupported | | Reserved | 4-7 | | | +--------------------+--------+--------------------+-------------------------+ Driver provides current reading from HW as well as device specific thresholds for thermal alarm (Warning, Critical, Fatal) events. $ sensors Output ========================================================= ice-pci-b100 Adapter: PCI adapter temp1: +62.0°C (high = +95.0°C, crit = +105.0°C) (emerg = +115.0°C) Tested on Intel Corporation Ethernet Controller E810-C for SFP Co-developed-by: Marcin Domagala <marcinx.domagala@intel.com> Signed-off-by: Marcin Domagala <marcinx.domagala@intel.com> Co-developed-by: Eric Joyner <eric.joyner@intel.com> Signed-off-by: Eric Joyner <eric.joyner@intel.com> Reviewed-by: Marcin Szycik <marcin.szycik@linux.intel.com> Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com> Signed-off-by: Konrad Knitter <konrad.knitter@intel.com> Tested-by: Pucha Himasekhar Reddy <himasekharx.reddy.pucha@intel.com> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2023-12-01 10:08:39 -08:00
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2023, Intel Corporation. */
#include "ice.h"
#include "ice_hwmon.h"
#include "ice_adminq_cmd.h"
#include <linux/hwmon.h>
#define TEMP_FROM_REG(reg) ((reg) * 1000)
static const struct hwmon_channel_info *ice_hwmon_info[] = {
HWMON_CHANNEL_INFO(temp,
HWMON_T_INPUT | HWMON_T_MAX |
HWMON_T_CRIT | HWMON_T_EMERGENCY),
NULL
};
static int ice_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
struct ice_aqc_get_sensor_reading_resp resp;
struct ice_pf *pf = dev_get_drvdata(dev);
int ret;
if (type != hwmon_temp)
return -EOPNOTSUPP;
ret = ice_aq_get_sensor_reading(&pf->hw, &resp);
if (ret) {
dev_warn_ratelimited(dev,
"%s HW read failure (%d)\n",
__func__,
ret);
return ret;
}
switch (attr) {
case hwmon_temp_input:
*val = TEMP_FROM_REG(resp.data.s0f0.temp);
break;
case hwmon_temp_max:
*val = TEMP_FROM_REG(resp.data.s0f0.temp_warning_threshold);
break;
case hwmon_temp_crit:
*val = TEMP_FROM_REG(resp.data.s0f0.temp_critical_threshold);
break;
case hwmon_temp_emergency:
*val = TEMP_FROM_REG(resp.data.s0f0.temp_fatal_threshold);
break;
default:
dev_dbg(dev, "%s unsupported attribute (%d)\n",
__func__, attr);
return -EOPNOTSUPP;
}
return 0;
}
static umode_t ice_hwmon_is_visible(const void *data,
enum hwmon_sensor_types type, u32 attr,
int channel)
{
if (type != hwmon_temp)
return 0;
switch (attr) {
case hwmon_temp_input:
case hwmon_temp_crit:
case hwmon_temp_max:
case hwmon_temp_emergency:
return 0444;
}
return 0;
}
static const struct hwmon_ops ice_hwmon_ops = {
.is_visible = ice_hwmon_is_visible,
.read = ice_hwmon_read
};
static const struct hwmon_chip_info ice_chip_info = {
.ops = &ice_hwmon_ops,
.info = ice_hwmon_info
};
static bool ice_is_internal_reading_supported(struct ice_pf *pf)
{
/* Only the first PF will report temperature for a chip.
* Note that internal temp reading is not supported
* for older FW (< v4.30).
*/
if (pf->hw.pf_id)
return false;
unsigned long sensors = pf->hw.dev_caps.supported_sensors;
return _test_bit(ICE_SENSOR_SUPPORT_E810_INT_TEMP_BIT, &sensors);
};
void ice_hwmon_init(struct ice_pf *pf)
{
struct device *dev = ice_pf_to_dev(pf);
struct device *hdev;
if (!ice_is_internal_reading_supported(pf))
return;
hdev = hwmon_device_register_with_info(dev, "ice", pf, &ice_chip_info,
NULL);
if (IS_ERR(hdev)) {
dev_warn(dev,
"hwmon_device_register_with_info returns error (%ld)",
PTR_ERR(hdev));
return;
}
pf->hwmon_dev = hdev;
}
void ice_hwmon_exit(struct ice_pf *pf)
{
if (!pf->hwmon_dev)
return;
hwmon_device_unregister(pf->hwmon_dev);
}