Summary: hwmon driver disk and solid state drives with temperature sensors
Subsystems (4)
Guenter Roeck
maintainerv3 cover Summary: hwmon driver disk and solid state drives with temperature sensors
In the past, several attempts have been made to add support for reporting SCSI/[S]ATA drive temperatures to the Linux kernel. This is desirable to have a means to report drive temperatures to userspace without root privileges and in a standard format, but also to be able to tie reported temperatures with the thermal subsystem.
The most recent attempt was [1] by Linus Walleij. It went through a total of seven iterations. At the end, it was rejected for a number of reasons; see the provided link for details. This implementation resides in the SCSI core. It originally resided in libata but was moved to SCSI per maintainer request, where it was ultimately rejected.
An earlier submission of a driver to report SCSI/SATA drive temperatures was made back in 2009 by Constantin Baranov [2]. This submission resides in the hardware monitoring subsystem. It does not rely on changes in the SCSI subsystem or in libata-scsi. Instead, it registers itself with the SCSI subsystem using scsi_register_interface(). It was rejected primarily because it executes ATA passthrough commands without verification that it is actually connected to an ATA drive.
Both submissions use SMART attributes to read drive temperature information.
[1] also tries to identify temperature limits from those attributes. Unfortunately, SMART attributes are not well defined, resulting in relative complex code trying to identify the exact format of the reported data.
With the available information and feedback, we can make a number of observations and conclusions.
a) Using available (S)ATA drive temperature information and convert it to a SCSI log page is an interesting idea. On the downside, it would add a substantial amount of complexity to libata-scsi. The code would either have to be optional, or it would have to be built into the kernel even if it is never used on a given system. Without access to SCSI drives supporting this feature, it would be all but impossible to test the code against such a drive. It would neither be possible to test correctness of the code in libata-scsi nor in the driver using that information. Overall it would be much easier and much less risky to implement such code on the receiving side (ie in a driver reporting the temperatures) instead of trying to convert the information from one format to another first. In summary, it is neither practical nor feasible. On top of that, there is no guarantee that code implementing this functionality would ever be accepted into the kernel for this very reason.
b) The code needed to read and analyze SCSI temperature log pages is quite complex (see smartmontools [5]). There is no existing support code in the Linux kernel; such code would have to be written. This makes the approach discussed in a) even more risky and less practical.
c) Overall, any attempt to report temperature information for anything but SATA drives in the kernel is not practical due to the complexity involved, and due to the inability to test the resulting code with non-SATA drives.
d) Using SMART data for anything but basic temperature reporting is not really feasible due to the lack of standardization. Any attempt to do this would add a substantial amount of code, ambiguity, and risk.
This submission implements a driver to report the temperature of SATA drives through the hardware monitoring subsystem. It is implemented as stand-alone driver in the hardware monitoring subsystem. The driver uses the mechanism from submission [1] to register with the SCSI subsystem. By using this mechanism, changes in the SCSI or ATA subsystems are not required. To reduce risk and complexity, it only instantiates after reliably validating that it is connected to a SATA drive. It does not attempt to report the temperature of non-SATA drives.
The driver uses the SCT Command Transport feature set as specified in ATA8-ACS [4] to read and report the temperature as well as temperature limits and lowest/highest temperature information (if available) for SATA drives. If a drive does not support SCT Command Transport, the driver attempts to access a limited set of well known SMART attributes to read the drive temperature. In that case, only the current drive temperature is reported.
The driver does not currently report temperatures for SCSI drives. This will be added with a subsequent patch.
---
v3: Rename satatemp -> drivetemp
Use cached VPD page 89 data (available with v5.5 and later kernels) Relax ATA drive detection; still check if inquiry data is present, but don't use it for access detection.
Modify VPD data analysis following guidance from Martin K. Petersen Separate SATA drive detection into separate function Marked as RFT. Martin K. Petersen reports:
"I get a crash in the driver core during probe if the drivetemp module
is loaded prior to loading ahci or a SCSI HBA driver. This crash is unrelated to my changes. Haven't had time to debug."
This will require further testing before the patch is applied.
v2: scsi_cmd variable is no longer static
Fixed drive name in Kconfig
Describe heuristics used to select SCT or SMART in commit message Added Reviewed-by: from Linus Walleij
---
References:
[1] https://patchwork.kernel.org/patch/10688021/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] http://www.t10.org/cgi-bin/ac.pl?t=f&f=sat5r02.pdf
Information technology - SCSI / ATA Translation - 5 (SAT-5), section 10.3.8 (Temperature log page).
[4] http://www.t13.org/documents/uploadeddocuments/docs2008/d1699r6a-ata8-acs.pdf
ANS T13/1699-D "Information technology - AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)"
[5] https://github.com/mirror/smartmontools.git
Guenter Roeck
maintainerPATCH v3 1/1 hwmon: Driver for disk and solid state drives with temperature sensors
Reading the temperature of ATA drives has been supported for years by userspace tools such as smarttools or hddtemp. The downside of such tools is that they need to run with super-user privilege, that the temperatures are not reported by standard tools such as 'sensors' or 'libsensors', and that drive temperatures are not available for use in the kernel's thermal subsystem.
This driver solves this problem by adding support for reading the temperature of ATA drives from the kernel using the hwmon API and by adding a temperature zone for each drive.
With this driver, the hard disk temperature can be read using the unprivileged 'sensors' application:
$ sensors satatemp-scsi-1-0 satatemp-scsi-1-0 Adapter: SCSI adapter temp1: +23.0°C
or directly from sysfs:
$ grep . /sys/class/hwmon/hwmon9/{name,temp1_input}
/sys/class/hwmon/hwmon9/name:satatemp
/sys/class/hwmon/hwmon9/temp1_input:23000If the drive supports SCT transport and reports temperature limits, those are reported as well.
satatemp-scsi-0-0
Adapter: SCSI adapter
temp1: +27.0°C (low = +0.0°C, high = +60.0°C)
(crit low = -41.0°C, crit = +85.0°C)
(lowest = +23.0°C, highest = +34.0°C)The driver attempts to use SCT Command Transport to read the drive temperature. If the SCT Command Transport feature set is not available, or if it does not report the drive temperature, drive temperatures may be readable through SMART attributes. Since SMART attributes are not well defined, this method is only used as fallback mechanism.
---
v3: Rename satatemp -> drivetemp
Use cached VPD page 89 data (available with v5.5 and later kernels) Relax ATA drive detection; still check if inquiry data is present, but don't use it for access detection.
Modify VPD data analysis following guidance from Martin K. Petersen Separate SATA drive detection into separate function Marked as RFT. Martin K. Petersen reports:
"I get a crash in the driver core during probe if the drivetemp module
is loaded prior to loading ahci or a SCSI HBA driver. This crash is unrelated to my changes. Haven't had time to debug."
This will require further testing before the patch is applied.
v2: scsi_cmd variable is no longer static
Fixed drive name in Kconfig
Describe heuristics used to select SCT or SMART in commit message Added Reviewed-by: from Linus Walleij
--- Documentation/hwmon/drivetemp.rst | 52 +++ Documentation/hwmon/index.rst | 1 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/drivetemp.c | 574 ++++++++++++++++++++++++++++++ 5 files changed, 638 insertions(+) create mode 100644 Documentation/hwmon/drivetemp.rst create mode 100644 drivers/hwmon/drivetemp.c
Documentation/hwmon/drivetemp.rst new file +52 -0
@@ -0,0 +1,52 @@ +.. SPDX-License-Identifier: GPL-2.0 + +Kernel driver drivetemp +======================= + + +References +---------- + +ANS T13/1699-D +Information technology - AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS) + +ANS Project T10/BSR INCITS 513 +Information technology - SCSI Primary Commands - 4 (SPC-4) + +ANS Project INCITS 557 +Information technology - SCSI / ATA Translation - 5 (SAT-5) + + +Description +----------- + +This driver supports reporting the temperature of disk and solid state +drives with temperature sensors. + +If supported, it uses the ATA SCT Command Transport feature to read +the current drive temperature and, if available, temperature limits +as well as historic minimum and maximum temperatures. If SCT Command +Transport is not supported, the driver uses SMART attributes to read +the drive temperature. + + +Sysfs entries +------------- + +Only the temp1_input attribute is always available. Other attributes are +available only if reported by the drive. All temperatures are reported in +milli-degrees Celsius. + +======================= ===================================================== +temp1_input Current drive temperature +temp1_lcrit Minimum temperature limit. Operating the device below + this temperature may cause physical damage to the + device. +temp1_min Minimum recommended continuous operating limit +temp1_max Maximum recommended continuous operating temperature +temp1_crit Maximum temperature limit. Operating the device above + this temperature may cause physical damage to the + device. +temp1_lowest Minimum temperature seen this power cycle +temp1_highest Maximum temperature seen this power cycle +======================= =====================================================
Documentation/hwmon/index.rst +1 -0
@@ -47,6 +47,7 @@ Hardware Monitoring Kernel Drivers da9055 dell-smm-hwmon dme1737 + drivetemp ds1621 ds620 emc1403
drivers/hwmon/Kconfig +10 -0
@@ -385,6 +385,16 @@ config SENSORS_ATXP1 This driver can also be built as a module. If so, the module will be called atxp1. +config SENSORS_DRIVETEMP + tristate "Hard disk drives with temperature sensors" + depends on SCSI && ATA + help + If you say yes you get support for the temperature sensor on + hard disk drives. + + This driver can also be built as a module. If so, the module + will be called satatemp. + config SENSORS_DS620 tristate "Dallas Semiconductor DS620" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_SENSORS_DA9052_ADC)+= da9052-hwmon.o obj-$(CONFIG_SENSORS_DA9055)+= da9055-hwmon.o obj-$(CONFIG_SENSORS_DELL_SMM) += dell-smm-hwmon.o obj-$(CONFIG_SENSORS_DME1737) += dme1737.o +obj-$(CONFIG_SENSORS_DRIVETEMP) += drivetemp.o obj-$(CONFIG_SENSORS_DS620) += ds620.o obj-$(CONFIG_SENSORS_DS1621) += ds1621.o obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o
drivers/hwmon/drivetemp.c new file +574 -0
574 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFT PATCH v3 1/1] hwmon: Driver for disk and solid state drives with temperature sensors
Quoted 6 lines · Guenter Roeck
Reading the temperature of ATA drives has been supported for years by userspace tools such as smarttools or hddtemp. The downside of such tools is that they need to run with super-user privilege, that the temperatures are not reported by standard tools such as 'sensors' or 'libsensors', and that drive temperatures are not available for use in the kernel's thermal subsystem.
(...)
Quoted 6 lines
Cc Chris Healy <[email protected]>Cc Linus Walleij <[email protected]>Cc Martin K. Petersen <[email protected]>Cc Bart Van Assche <[email protected]>Reviewed-by Linus Walleij <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
I took the v3 patch for a test run on the D-Link DIR-695 NAS/router and it works like a charm.
With a few additional patches (that I am
starting to upstream) the temperature zone in the drive can be used to control the GPIO-based fan in the NAS to keep the enclosure/chassis temperature down.
I define a thermal zone in device tree like this:
+ thermal-zones {
+ chassis-thermal {
+ /* Poll every 20 seconds */ + polling-delay = <20000>; + /* Poll every 2nd second when cooling */ + polling-delay-passive = <2000>; + /* Use the thermal sensor in the hard drive */ + thermal-sensors = <&sata_drive>;
+
+ /* Tripping points from the fan.script in the rootfs */
+ trips {
+ alert: chassis-alert {
+ /* At 43 degrees turn on the fan */
+ temperature = <43000>;
+ hysteresis = <3000>;
+ type = "active";
+ };
+ crit: chassis-crit {
+ /* Just shut down at 60 degrees */
+ temperature = <60000>;
+ hysteresis = <2000>;
+ type = "critical";+ };
+ };
+
+ cooling-maps {
+ map0 {
+ trip = <&alert>;
+ cooling-device = <&fan0 1 1>;
+ };
+ };
+ };
+ };
(...)
pata-controller@63000000 {
status = "okay";
+
+ /*
+ * This drive may have a temperature sensor with a
+ * thermal zone we can use for thermal control of the
+ * chassis temperature using the fan.
+ */
+ sata_drive: drive@0 {
+ reg = <0>;
+ #thermal-sensor-cells = <0>;
+ };
};The temperature started out at household temperature 26 degrees this morning, leaving the device running it gradually reached the trip point at 43 degrees and runs the fan. It then switches the fan off/on with some hysteresis keeping the temperature around 43 degreed.
The PID-controller in the thermal framework handles it all in-kernel as expected.
Yours,
Linus Walleij