Skip to contentSkip to conversation

hwmon: Driver for SCSI/ATA temperature sensors

PATCH In review Constantin Baranov 5 participants 7 messages Sep 12, 2009 – Sep 16, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: Driver for SCSI/ATA temperature sensors

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Adding support of the pure SCSI methods is provided.

---
 drivers/hwmon/Kconfig    |   10 ++
 drivers/hwmon/Makefile   |    1 +
 drivers/hwmon/scsitemp.c |  264 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/scsitemp.c
drivers/hwmon/Kconfig +10 -0
index 2d50166..fb9fd9d 100644
@@ -692,6 +692,16 @@ config SENSORS_PCF8591
 	  These devices are hard to detect and rarely found on mainstream
 	  hardware.  If unsure, say N.
 
+config SENSORS_SCSITEMP
+	tristate "SCSI/ATA drive temperature sensors"
+	depends on SCSI
+	help
+	  If you say yes you get support for SCSI/ATA accessible temperature
+	  sensors found on most modern hard drives.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called scsitemp.
+
 config SENSORS_SHT15
 	tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
 	depends on GENERIC_GPIO
drivers/hwmon/Makefile +1 -0
index b793dce..8c4c870 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_PC87360)	+= pc87360.o
 obj-$(CONFIG_SENSORS_PC87427)	+= pc87427.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
+obj-$(CONFIG_SENSORS_SCSITEMP)	+= scsitemp.o
 obj-$(CONFIG_SENSORS_SHT15)	+= sht15.o
 obj-$(CONFIG_SENSORS_SIS5595)	+= sis5595.o
 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
drivers/hwmon/scsitemp.c new file +264 -0

264 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#1 lore raw

Am Sonntag 13 September 2009 01:01:04 schrieb Constantin Baranov:

Quoted 4 lines

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Adding support of the pure SCSI methods is provided.

That sounds useful. Do you have any nagios rules or something similar around that make use of this?

Quoted 7 lines
drivers/hwmon/scsitemp.c new file +7 -0
+static int scsitemp_ata_temp_input(struct scsitemp *st, long *temp)
+{
+	static const u8 cdb[16] = {
+		ATA_16,			0x08,	0x0e,			0x00,
+		ATA_SMART_READ_VALUES,	0x00,	0x01,			0x00,
+		0x00,			0x00,	ATA_SMART_LBAM_PASS,	0x00,
+		ATA_SMART_LBAH_PASS,	0x00,	ATA_CMD_SMART,		0x00,

drivers/hwmon/scsitemp.c line 71

Quoted 10 lines
drivers/hwmon/scsitemp.c new file +10 -0
+	};
+
+	u8 values[512];
+	unsigned len = sizeof(values);
+	unsigned nattrs, i;
+	int err;
+
+	err = scsitemp_execute(st, cdb, values, &len);
+	if (err)
+		goto out;

How about directly doing "return err;" here? This would make the label superfluous and tthe code a bit more obvious.

Quoted 15 lines
drivers/hwmon/scsitemp.c new file +15 -0
+	err = -ENXIO;
+	nattrs = min_t(unsigned, 30, len / 12);
+	for (i = 0; i < nattrs; i++) {
+		u8 *attr = values + i * 12;
+
+		if (attr[2] == 194) {
+			*temp = attr[7] * 1000;
+			err = 0;
+			break;
+		}
+	}
+
+out:
+	return err;
+}
#2 lore raw
Quoted 8 lines · On Sun, 13 Sep 2009 10:04:11 +0200 Rolf Eike Beer <[email protected]> wrote:

Am Sonntag 13 September 2009 01:01:04 schrieb Constantin Baranov:

Quoted 4 lines

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Adding support of the pure SCSI methods is provided.

That sounds useful. Do you have any nagios rules or something similar around that make use of this?

I don't use nagios, thus I have nothing to say about its integration with scsitemp. However, scsitemp sensors appears under /sys/class/hwmon directory and are similar to other sensors. GKrellM is able to discover and read values from scsitemp.

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	err = scsitemp_execute(st, cdb, values, &len);
+	if (err)
+		goto out;

How about directly doing "return err;" here? This would make the label superfluous and tthe code a bit more obvious.

Agreed. Also I have removed orphan scsitemp.id field.

---
From: Constantin Baranov <[email protected]>
Date: Sun, 13 Sep 2009 03:34:38 +0500
Subject: [PATCH] hwmon: Driver for SCSI/ATA temperature sensors

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Future addition of the pure SCSI methods is provided.

---
 drivers/hwmon/Kconfig    |   10 ++
 drivers/hwmon/Makefile   |    1 +
 drivers/hwmon/scsitemp.c |  262 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 273 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/scsitemp.c
drivers/hwmon/Kconfig +10 -0
index 2d50166..fb9fd9d 100644
@@ -692,6 +692,16 @@ config SENSORS_PCF8591
 	  These devices are hard to detect and rarely found on mainstream
 	  hardware.  If unsure, say N.
 
+config SENSORS_SCSITEMP
+	tristate "SCSI/ATA drive temperature sensors"
+	depends on SCSI
+	help
+	  If you say yes you get support for SCSI/ATA accessible temperature
+	  sensors found on most modern hard drives.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called scsitemp.
+
 config SENSORS_SHT15
 	tristate "Sensiron humidity and temperature sensors. SHT15 and compat."
 	depends on GENERIC_GPIO
drivers/hwmon/Makefile +1 -0
index b793dce..8c4c870 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_SENSORS_MAX6650)	+= max6650.o
 obj-$(CONFIG_SENSORS_PC87360)	+= pc87360.o
 obj-$(CONFIG_SENSORS_PC87427)	+= pc87427.o
 obj-$(CONFIG_SENSORS_PCF8591)	+= pcf8591.o
+obj-$(CONFIG_SENSORS_SCSITEMP)	+= scsitemp.o
 obj-$(CONFIG_SENSORS_SHT15)	+= sht15.o
 obj-$(CONFIG_SENSORS_SIS5595)	+= sis5595.o
 obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
drivers/hwmon/scsitemp.c new file +262 -0

262 lines not on this page · raw message

Signature · 1 line
1.6.4.2
#3 lore raw
In reply to Constantin Baranov
Quoted 4 lines · Constantin Baranov

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Adding support of the pure SCSI methods is provided.

The code, as you wrote it looks fine.

The basic problem are the effects. Right at the moment it tries to send an ATA_16 encapsulated SMART command to every SCSI device in the system. We simply can't allow this. A huge number of SCSI presenting USB devices are known to lock up when they see either ATA_X encapsulation or SMART commands. It's not really even safe to send ATA_X to SCSI devices. The modern ones should all error out fine, but the older ones are likely to be less tolerant.

Finally, this:

drivers/hwmon/scsitemp.c line 81

Quoted 4 lines
drivers/hwmon/scsitemp.c new file +4 -0
+               if (attr[2] == 194) {
+                       *temp = attr[7] * 1000;
+                       err = 0;
+                       break;

Smart attribute 194 is highly vendor specific ... for instance my new SATA drive doesn't implement it (it does implement 190 instead).

So really, given the complexity of just obtaining the data and the problem of matching which data to obtain to which device you have, why not just use smartctl from userspace for monitoring? you could even just plug into smartd, it seems to have most of the necessary heuristics built in already.

James

#4 lore raw

Hi!

Quoted 7 lines

Finally, this:

drivers/hwmon/scsitemp.c line 81

Quoted 4 lines
drivers/hwmon/scsitemp.c new file +4 -0
+               if (attr[2] == 194) {
+                       *temp = attr[7] * 1000;
+                       err = 0;
+                       break;
Quoted 8 lines

Smart attribute 194 is highly vendor specific ... for instance my new SATA drive doesn't implement it (it does implement 190 instead).

So really, given the complexity of just obtaining the data and the problem of matching which data to obtain to which device you have, why not just use smartctl from userspace for monitoring? you could even just plug into smartd, it seems to have most of the necessary heuristics built in already.

Well, having unified kernel<->user interface for temperature sensors makes sense.

I'm not sure if benefits outweight costs here (I tend to think they do), but...

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#5 lore raw
In reply to James Bottomley
Quoted 23 lines · James Bottomley
Quoted 4 lines · Constantin Baranov

The scsitemp module attaches a device to each SCSI device and registers it in hwmon. Currently the only method of reading temperature is ATA SMART. Adding support of the pure SCSI methods is provided.

The code, as you wrote it looks fine.

The basic problem are the effects.  Right at the moment it tries to send an ATA_16 encapsulated SMART command to every SCSI device in the system. We simply can't allow this.  A huge number of SCSI presenting USB devices are known to lock up when they see either ATA_X encapsulation or SMART commands.  It's not really even safe to send ATA_X to SCSI devices.  The modern ones should all error out fine, but the older ones are likely to be less tolerant.

Finally, this:

Quoted 4 lines

+               if (attr[2] == 194) {
+                       *temp = attr[7] * 1000;
+                       err = 0;
+                       break;

Quoted 8 lines

Smart attribute 194 is highly vendor specific ... for instance my new SATA drive doesn't implement it (it does implement 190 instead).

So really, given the complexity of just obtaining the data and the problem of matching which data to obtain to which device you have, why not just use smartctl from userspace for monitoring?  you could even just plug into smartd, it seems to have most of the necessary heuristics built in already.

There's even a util called hddtemp which handles all this and has a database of smart attributes to use for most drives.

Thanks,

Signature · 8 lines
Julian Calaby

Email: [email protected]
.Plan: http://sites.google.com/site/juliancalaby/
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 2 lines · On Mon, 14 Sep 2009 17:00:20 +0200 Pavel Machek <[email protected]> wrote:

Well, having unified kernel<->user interface for temperature sensors makes sense.

This is my exact motivation.

Quoted 9 lines · On Tue, 15 Sep 2009 15:57:39 +1000 Julian Calaby <[email protected]>…
Quoted 5 lines · James Bottomley

So really, given the complexity of just obtaining the data and the problem of matching which data to obtain to which device you have, why not just use smartctl from userspace for monitoring?  you could even just plug into smartd, it seems to have most of the necessary heuristics built in already.

There's even a util called hddtemp which handles all this and has a database of smart attributes to use for most drives.

Of course, I know about both smartctl and hddtemp tools.

Quoted 7 lines · On Sun, 13 Sep 2009 09:00:53 -0500 James Bottomley <[email protected]>…

The basic problem are the effects. Right at the moment it tries to send an ATA_16 encapsulated SMART command to every SCSI device in the system. We simply can't allow this. A huge number of SCSI presenting USB devices are known to lock up when they see either ATA_X encapsulation or SMART commands. It's not really even safe to send ATA_X to SCSI devices. The modern ones should all error out fine, but the older ones are likely to be less tolerant.

I looked for reliable method of classifying devices. Unfortunately, without success. Maybe it's better to disable automatic scanning and provide a user (udev) with ability to enable monitoring on explicitly pointed device.

Quoted 2 lines

Smart attribute 194 is highly vendor specific ... for instance my new SATA drive doesn't implement it (it does implement 190 instead).

Unfortunately, every SMART attribute is either reserved or vendor specific as per T13. AFAIK, 194 is the most popular. That's why I have chosen it in the first version. However, attribute number (and interpretation method as well) may become configurable. Moreover, we can use hddtemp database to initially configure scsitemp. And use unified hwmon interface later :) --
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html