Skip to contentSkip to conversation

hwmon: (dell-smm) Miscellaneous Improvments

PATCH Superseded [email protected] 2 participants 13 messages Oct 21, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hwmon: (dell-smm) Miscellaneous Improvments

From: Armin Wolf <[email protected]>

This patch series contains various improvments to the dell-smm-hwmon driver. The first patch is merely a cosmetic change. The next two patches improve the ioctl handling and have been tested with i8kutils (the only program using this interface). The fourth patch adds some config data for the Inspiron 3505, which has been verified with the fan data displayed by the Dell UEFI Diag ROM. The last patch accelerates the setting of fan speed and has been tested as well over the legacy interface and the hwmon sysfs interface.

Tested on a Dell Inspiron 3505, the Dell Latitude C600 is currently out-of-service.

Armin Wolf (5):
hwmon: (dell-smm) Sort includes in alphabetical order
hwmon: (dell-smm) Use strscpy_pad()
hwmon: (dell-smm) Return -ENOIOCTLCMD instead of -EINVAL
hwmon: (dell-smm) Add Dell Inspiron 3505 config data
hwmon: (dell-smm) Speed up setting of fan speed

 drivers/hwmon/dell-smm-hwmon.c | 48 +++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 15 deletions(-)

--
2.20.1

#1 lore raw

PATCH 1/5 hwmon: (dell-smm) Sort includes in alphabetical order

From: Armin Wolf <[email protected]>

Sort includes for better overview.

---
 drivers/hwmon/dell-smm-hwmon.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +8 -8
index af0d0d2b6e99..9773d6c0477a 100644
@@ -12,22 +12,22 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/capability.h>
 #include <linux/cpu.h>
+#include <linux/ctype.h>
 #include <linux/delay.h>
+#include <linux/dmi.h>
 #include <linux/err.h>
+#include <linux/hwmon.h>
+#include <linux/init.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
-#include <linux/types.h>
-#include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-#include <linux/dmi.h>
-#include <linux/capability.h>
-#include <linux/mutex.h>
-#include <linux/hwmon.h>
-#include <linux/uaccess.h>
-#include <linux/ctype.h>
 #include <linux/smp.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
 
 #include <linux/i8k.h>
 

--
2.20.1

maintainer Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] hwmon: (dell-smm) Sort includes in alphabetical order

Quoted 5 lines · On Thursday 21 October 2021 19:54:43 [email protected] wrote:

From: Armin Wolf <[email protected]>

Sort includes for better overview.

Quoted 42 lines
---
 drivers/hwmon/dell-smm-hwmon.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +8 -9
index af0d0d2b6e99..9773d6c0477a 100644
@@ -12,22 +12,22 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/capability.h>
 #include <linux/cpu.h>
+#include <linux/ctype.h>
 #include <linux/delay.h>
+#include <linux/dmi.h>
 #include <linux/err.h>
+#include <linux/hwmon.h>
+#include <linux/init.h>
 #include <linux/module.h>
+#include <linux/mutex.h>
 #include <linux/platform_device.h>
-#include <linux/types.h>
-#include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-#include <linux/dmi.h>
-#include <linux/capability.h>
-#include <linux/mutex.h>
-#include <linux/hwmon.h>
-#include <linux/uaccess.h>
-#include <linux/ctype.h>
 #include <linux/smp.h>
+#include <linux/types.h>
+#include <linux/uaccess.h>
 
 #include <linux/i8k.h>
 
--

2.20.1

#3 lore raw

PATCH 2/5 hwmon: (dell-smm) Use strscpy_pad()

In reply to [email protected]

From: Armin Wolf <[email protected]>

Using strscpy_pad() allows for fewer memory accesses since memset() will not unconditionally zero-out the whole buffer.

---
 drivers/hwmon/dell-smm-hwmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +2 -2
index 9773d6c0477a..b0c591bb761a 100644
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/string.h>
 #include <linux/smp.h>
 #include <linux/types.h>
 #include <linux/uaccess.h>
@@ -472,8 +473,7 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		if (restricted && !capable(CAP_SYS_ADMIN))
 			return -EPERM;
 
-		memset(buff, 0, sizeof(buff));
-		strscpy(buff, data->bios_machineid, sizeof(buff));
+		strscpy_pad(buff, data->bios_machineid, sizeof(buff));
 		break;
 
 	case I8K_FN_STATUS:

--
2.20.1

maintainer Acked-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] hwmon: (dell-smm) Use strscpy_pad()

Quoted 7 lines · On Thursday 21 October 2021 19:54:44 [email protected] wrote:

From: Armin Wolf <[email protected]>

Using strscpy_pad() allows for fewer memory accesses since memset() will not unconditionally zero-out the whole buffer.

Quoted 29 lines
---
 drivers/hwmon/dell-smm-hwmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +2 -3
index 9773d6c0477a..b0c591bb761a 100644
@@ -25,6 +25,7 @@
 #include <linux/platform_device.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/string.h>
 #include <linux/smp.h>
 #include <linux/types.h>
 #include <linux/uaccess.h>
@@ -472,8 +473,7 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		if (restricted && !capable(CAP_SYS_ADMIN))
 			return -EPERM;
 
-		memset(buff, 0, sizeof(buff));
-		strscpy(buff, data->bios_machineid, sizeof(buff));
+		strscpy_pad(buff, data->bios_machineid, sizeof(buff));
 		break;
 
 	case I8K_FN_STATUS:
--

2.20.1

#5 lore raw

PATCH 3/5 hwmon: (dell-smm) Return -ENOIOCTLCMD instead of -EINVAL

In reply to [email protected]

From: Armin Wolf <[email protected]>

Returning -ENOIOCTLCMD gives the callers a better
hint of what went wrong and is the recommended
behavior.

---
 drivers/hwmon/dell-smm-hwmon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/dell-smm-hwmon.c +2 -1
index b0c591bb761a..5f0338b4a717 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/err.h>
+#include <linux/errno.h>
 #include <linux/hwmon.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -516,7 +517,7 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		break;
 
 	default:
-		return -EINVAL;
+		return -ENOIOCTLCMD;
 	}
 
 	if (val < 0)

--
2.20.1

maintainer Acked-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] hwmon: (dell-smm) Return -ENOIOCTLCMD instead of -EINVAL

Quoted 7 lines · On Thursday 21 October 2021 19:54:45 [email protected] wrote:

From: Armin Wolf <[email protected]>

Returning -ENOIOCTLCMD gives the callers a better
hint of what went wrong and is the recommended
behavior.

Quoted 28 lines
---
 drivers/hwmon/dell-smm-hwmon.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/dell-smm-hwmon.c +2 -2
index b0c591bb761a..5f0338b4a717 100644
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/dmi.h>
 #include <linux/err.h>
+#include <linux/errno.h>
 #include <linux/hwmon.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -516,7 +517,7 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		break;
 
 	default:
-		return -EINVAL;
+		return -ENOIOCTLCMD;
 	}
 
 	if (val < 0)
--

2.20.1

#7 lore raw

PATCH 4/5 hwmon: (dell-smm) Add Dell Inspiron 3505 config data

In reply to [email protected]

From: Armin Wolf <[email protected]>

After checking the fan speeds reported with the Dell Diag UEFI ROM, its safe to permanently set fan_max to I8K_FAN_HIGH and fan_mult to 1 for the Dell Inspiron 3505.

Tested on a Dell Inspiron 3505.

---
 drivers/hwmon/dell-smm-hwmon.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/hwmon/dell-smm-hwmon.c +13 -0
index 5f0338b4a717..2579dd646b20 100644
@@ -990,6 +990,7 @@ struct i8k_config_data {
 };
 
 enum i8k_configs {
+	DELL_INSPIRON_3505,
 	DELL_LATITUDE_D520,
 	DELL_PRECISION_490,
 	DELL_STUDIO,
@@ -997,6 +998,10 @@ enum i8k_configs {
 };
 
 static const struct i8k_config_data i8k_config_data[] __initconst = {
+	[DELL_INSPIRON_3505] = {
+		.fan_mult = 1,
+		.fan_max = I8K_FAN_HIGH,
+	},
 	[DELL_LATITUDE_D520] = {
 		.fan_mult = 1,
 		.fan_max = I8K_FAN_TURBO,
@@ -1030,6 +1035,14 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
 		},
 	},
+	{
+		.ident = "Dell Inspiron 3505",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
+		},
+		.driver_data = (void *)&i8k_config_data[DELL_INSPIRON_3505],
+	},
 	{
 		.ident = "Dell Inspiron 2",
 		.matches = {

--
2.20.1

maintainer
#8 lore raw

Re: [PATCH 4/5] hwmon: (dell-smm) Add Dell Inspiron 3505 config data

Quoted 8 lines · On Thursday 21 October 2021 19:54:46 [email protected] wrote:

From: Armin Wolf <[email protected]>

After checking the fan speeds reported with the Dell Diag UEFI ROM, its safe to permanently set fan_max to I8K_FAN_HIGH and fan_mult to 1 for the Dell Inspiron 3505.

Tested on a Dell Inspiron 3505.

Hello! Are there any issues without this change on Dell Inspiron 3505? Because i8k_config_data[] array is there for machines which need some hooks and do not work correctly (e.g. allowing to use I8K_FAN_TURBO).

Quoted 46 lines
---
 drivers/hwmon/dell-smm-hwmon.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/hwmon/dell-smm-hwmon.c +13 -1
index 5f0338b4a717..2579dd646b20 100644
@@ -990,6 +990,7 @@ struct i8k_config_data {
 };
 
 enum i8k_configs {
+	DELL_INSPIRON_3505,
 	DELL_LATITUDE_D520,
 	DELL_PRECISION_490,
 	DELL_STUDIO,
@@ -997,6 +998,10 @@ enum i8k_configs {
 };
 
 static const struct i8k_config_data i8k_config_data[] __initconst = {
+	[DELL_INSPIRON_3505] = {
+		.fan_mult = 1,
+		.fan_max = I8K_FAN_HIGH,
+	},
 	[DELL_LATITUDE_D520] = {
 		.fan_mult = 1,
 		.fan_max = I8K_FAN_TURBO,
@@ -1030,6 +1035,14 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = {
 			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
 		},
 	},
+	{
+		.ident = "Dell Inspiron 3505",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
+		},
+		.driver_data = (void *)&i8k_config_data[DELL_INSPIRON_3505],
+	},
 	{
 		.ident = "Dell Inspiron 2",
 		.matches = {
--

2.20.1

author
#9 lore raw

Re: [PATCH 4/5] hwmon: (dell-smm) Add Dell Inspiron 3505 config data

Am 21.10.21 um 20:05 schrieb Pali Rohár:

Quoted 8 lines · On Thursday 21 October 2021 19:54:46 [email protected] wrote:
Quoted 7 lines

From: Armin Wolf <[email protected]>

After checking the fan speeds reported with the Dell Diag UEFI ROM, its safe to permanently set fan_max to I8K_FAN_HIGH and fan_mult to 1 for the Dell Inspiron 3505.

Quoted 4 lines
Quoted 1 line

Tested on a Dell Inspiron 3505.

Hello! Are there any issues without this change on Dell Inspiron 3505? Because i8k_config_data[] array is there for machines which need some hooks and do not work correctly (e.g. allowing to use I8K_FAN_TURBO).

The Inspiron 3505 works fine without this change. If i8k_config_data[] is only there for applying
device specific quirks, then this change can be removed.

Quoted 46 lines
Quoted 46 lines
---
  drivers/hwmon/dell-smm-hwmon.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/hwmon/dell-smm-hwmon.c +13 -1
index 5f0338b4a717..2579dd646b20 100644
@@ -990,6 +990,7 @@ struct i8k_config_data {
  };
 
  enum i8k_configs {
+	DELL_INSPIRON_3505,
  	DELL_LATITUDE_D520,
  	DELL_PRECISION_490,
  	DELL_STUDIO,
@@ -997,6 +998,10 @@ enum i8k_configs {
  };
 
  static const struct i8k_config_data i8k_config_data[] __initconst = {
+	[DELL_INSPIRON_3505] = {
+		.fan_mult = 1,
+		.fan_max = I8K_FAN_HIGH,
+	},
  	[DELL_LATITUDE_D520] = {
  		.fan_mult = 1,
  		.fan_max = I8K_FAN_TURBO,
@@ -1030,6 +1035,14 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = {
  			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  		},
  	},
+	{
+		.ident = "Dell Inspiron 3505",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
+		},
+		.driver_data = (void *)&i8k_config_data[DELL_INSPIRON_3505],
+	},
  	{
  		.ident = "Dell Inspiron 2",
  		.matches = {
--

2.20.1

maintainer
#10 lore raw

Re: [PATCH 4/5] hwmon: (dell-smm) Add Dell Inspiron 3505 config data

Quoted 9 lines · On Thursday 21 October 2021 20:36:16 Armin Wolf wrote:

Am 21.10.21 um 20:05 schrieb Pali Rohár:

Quoted 8 lines · On Thursday 21 October 2021 19:54:46 [email protected] wrote:
Quoted 7 lines

From: Armin Wolf <[email protected]>

After checking the fan speeds reported with the Dell Diag UEFI ROM, its safe to permanently set fan_max to I8K_FAN_HIGH and fan_mult to 1 for the Dell Inspiron 3505.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Tested on a Dell Inspiron 3505.

Hello! Are there any issues without this change on Dell Inspiron 3505? Because i8k_config_data[] array is there for machines which need some hooks and do not work correctly (e.g. allowing to use I8K_FAN_TURBO).

The Inspiron 3505 works fine without this change. If i8k_config_data[] is only there for applying
device specific quirks, then this change can be removed.

In past when autodetection of fan_mult started working, I removed machines which was tested that do not need hook entry anymore.

We really do not need special entry for every possible Dell machine on the world in this table.

Hm... Maybe some comment for this array could be add to express why it is there or why entries here are needed...

Quoted 47 lines
Quoted 46 lines
Quoted 46 lines
---
  drivers/hwmon/dell-smm-hwmon.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/hwmon/dell-smm-hwmon.c +13 -1
index 5f0338b4a717..2579dd646b20 100644
@@ -990,6 +990,7 @@ struct i8k_config_data {
  };
 
  enum i8k_configs {
+	DELL_INSPIRON_3505,
  	DELL_LATITUDE_D520,
  	DELL_PRECISION_490,
  	DELL_STUDIO,
@@ -997,6 +998,10 @@ enum i8k_configs {
  };
 
  static const struct i8k_config_data i8k_config_data[] __initconst = {
+	[DELL_INSPIRON_3505] = {
+		.fan_mult = 1,
+		.fan_max = I8K_FAN_HIGH,
+	},
  	[DELL_LATITUDE_D520] = {
  		.fan_mult = 1,
  		.fan_max = I8K_FAN_TURBO,
@@ -1030,6 +1035,14 @@ static const struct dmi_system_id i8k_dmi_table[] __initconst = {
  			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  		},
  	},
+	{
+		.ident = "Dell Inspiron 3505",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
+		},
+		.driver_data = (void *)&i8k_config_data[DELL_INSPIRON_3505],
+	},
  	{
  		.ident = "Dell Inspiron 2",
  		.matches = {
--

2.20.1

#11 lore raw

PATCH 5/5 hwmon: (dell-smm) Speed up setting of fan speed

In reply to [email protected]

From: Armin Wolf <[email protected]>

When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(), causing an unnecessary smm call which can be very slow while also making error handling difficult.
Fix that by removing the function call from i8k_set_fan() and call it separately when needed.

Tested on a Dell Inspiron 3505.

---
 drivers/hwmon/dell-smm-hwmon.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +8 -4
index 2579dd646b20..62f087f67925 100644
@@ -327,7 +327,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl
 }
 
 /*
- * Set the fan speed (off, low, high). Returns the new fan status.
+ * Set the fan speed (off, low, high, ...).
  */
 static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
 {
@@ -339,7 +339,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
 	speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
 	regs.ebx = (fan & 0xff) | (speed << 8);
 
-	return i8k_smm(&regs) ? : i8k_get_fan_status(data, fan);
+	return i8k_smm(&regs);
 }
 
 static int __init i8k_get_temp_type(int sensor)
@@ -453,7 +453,7 @@ static int
 i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg)
 {
 	int val = 0;
-	int speed;
+	int speed, err;
 	unsigned char buff[16];
 	int __user *argp = (int __user *)arg;
 
@@ -513,7 +513,11 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		if (copy_from_user(&speed, argp + 1, sizeof(int)))
 			return -EFAULT;
 
-		val = i8k_set_fan(data, val, speed);
+		err = i8k_set_fan(data, val, speed);
+		if (err < 0)
+			return err;
+
+		val = i8k_get_fan_status(data, val);
 		break;
 
 	default:

--
2.20.1

maintainer Reviewed-by on v1 5/5
#12 lore raw

Re: [PATCH 5/5] hwmon: (dell-smm) Speed up setting of fan speed

Quoted 7 lines · On Thursday 21 October 2021 19:54:47 [email protected] wrote:

From: Armin Wolf <[email protected]>

When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(), causing an unnecessary smm call which can be very slow while also making error handling difficult.
Fix that by removing the function call from i8k_set_fan() and call it separately when needed.

The important information which is missing in commit message is the fact that there are only two users of i8k_set_fan() function. First is dell_smm_write() and second is i8k_ioctl_unlocked().

First user only checks if error occurred during i8k_set_fan() call and ignores new fan status. Second user needs to know new fan status as it returns it to userspace.

So this change just speed up first user - dell_smm_write() function.

It would be nice to put this kind of information into commit message as from code change itself it is not obvious.

Otherwise code change is fine,

Quoted 54 lines

Tested on a Dell Inspiron 3505.

---
 drivers/hwmon/dell-smm-hwmon.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +8 -5
index 2579dd646b20..62f087f67925 100644
@@ -327,7 +327,7 @@ static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enabl
 }
 
 /*
- * Set the fan speed (off, low, high). Returns the new fan status.
+ * Set the fan speed (off, low, high, ...).
  */
 static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
 {
@@ -339,7 +339,7 @@ static int i8k_set_fan(const struct dell_smm_data *data, int fan, int speed)
 	speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
 	regs.ebx = (fan & 0xff) | (speed << 8);
 
-	return i8k_smm(&regs) ? : i8k_get_fan_status(data, fan);
+	return i8k_smm(&regs);
 }
 
 static int __init i8k_get_temp_type(int sensor)
@@ -453,7 +453,7 @@ static int
 i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd, unsigned long arg)
 {
 	int val = 0;
-	int speed;
+	int speed, err;
 	unsigned char buff[16];
 	int __user *argp = (int __user *)arg;
 
@@ -513,7 +513,11 @@ i8k_ioctl_unlocked(struct file *fp, struct dell_smm_data *data, unsigned int cmd
 		if (copy_from_user(&speed, argp + 1, sizeof(int)))
 			return -EFAULT;
 
-		val = i8k_set_fan(data, val, speed);
+		err = i8k_set_fan(data, val, speed);
+		if (err < 0)
+			return err;
+
+		val = i8k_get_fan_status(data, val);
 		break;
 
 	default:
--

2.20.1