Re: [PATCH v2] hwmon: Driver for temperature sensors on SATA drives

From: Martin K. Petersen
Date: Tue Jan 07 2020 - 20:30:24 EST



Guenter,

> "scsi-8-140" is created by libsensors, so any change in that would
> have to be made there, not in the kernel driver.

Yes. Something like the patch below which will produce actual SCSI
device instance names:

drivetemp-scsi-7:0:29:0
drivetemp-scsi-8:0:30:0
drivetemp-scsi-8:0:15:0
drivetemp-scsi-7:0:24:0

Instead of the current:

drivetemp-scsi-7-1d0
drivetemp-scsi-8-1e0
drivetemp-scsi-8-f0
drivetemp-scsi-7-180

Other question: Does hwmon have any notion of sensor topology? As I
mentioned earlier, SCSI installations typically rely on SAF-TE or SES
instead of the physical drive sensors. SES also includes monitoring of
fans, power supplies, etc. And more importantly, it provides a
representation of the location of a given component. E.g.: Tray number
#4, disk drive bay #5.

So it would be helpful if libsensors had a way to represent sensors in a
way that mimics the physical device layout reported by SES.

--
Martin K. Petersen Oracle Linux Engineering


diff --git a/lib/data.c b/lib/data.c
index c5aea42967a6..06cfa86f353b 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -202,8 +202,9 @@ int sensors_snprintf_chip_name(char *str, size_t size,
return snprintf(str, size, "%s-mdio-%x", chip->prefix,
chip->addr);
case SENSORS_BUS_TYPE_SCSI:
- return snprintf(str, size, "%s-scsi-%hd-%x", chip->prefix,
- chip->bus.nr, chip->addr);
+ return snprintf(str, size, "%s-scsi-%u:%u:%u:%lu", chip->prefix,
+ chip->bus.nr, chip->addr, chip->sub_addr,
+ chip->sub_sub_addr);
}

return -SENSORS_ERR_CHIP_NAME;
diff --git a/lib/sensors.h b/lib/sensors.h
index 94f6f23051d2..f468cccabc72 100644
--- a/lib/sensors.h
+++ b/lib/sensors.h
@@ -65,6 +65,8 @@ typedef struct sensors_chip_name {
char *prefix;
sensors_bus_id bus;
int addr;
+ unsigned int sub_addr;
+ unsigned long sub_sub_addr;
char *path;
} sensors_chip_name;

diff --git a/lib/sysfs.c b/lib/sysfs.c
index e63688b72aba..f76b4a99aa7d 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -620,6 +620,7 @@ static int classify_device(const char *dev_name,
sensors_chip_features *entry)
{
int domain, bus, slot, fn, vendor, product, id;
+ unsigned long lun;
char bus_path[NAME_MAX];
char *bus_attr;
int ret = 1;
@@ -687,11 +688,13 @@ static int classify_device(const char *dev_name,
entry->chip.bus.nr = 0;
} else
if (subsys && !strcmp(subsys, "scsi") &&
- sscanf(dev_name, "%d:%d:%d:%x", &domain, &bus, &slot, &fn) == 4) {
+ sscanf(dev_name, "%u:%u:%u:%lu", &domain, &bus, &id, &lun) == 4) {
/* adapter(host), channel(bus), id(target), lun */
- entry->chip.addr = (bus << 8) + (slot << 4) + fn;
- entry->chip.bus.type = SENSORS_BUS_TYPE_SCSI;
entry->chip.bus.nr = domain;
+ entry->chip.addr = bus;
+ entry->chip.sub_addr = id;
+ entry->chip.sub_sub_addr = lun;
+ entry->chip.bus.type = SENSORS_BUS_TYPE_SCSI;
} else {
/* Unknown device */
ret = 0;