Skip to contentSkip to conversation

drm/amd/pm: correct the checks for fan attributes support

PATCH In review Evan Quan 2 participants 7 messages Jan 11, 2022

Subsystems (3)
lore
Share & tools
lore

Evan Quan

author
#0 lore raw

PATCH 1/1 drm/amd/pm: correct the checks for fan attributes support

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power implementation details to

amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
---
 .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
 drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
 drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
 .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115 +++++++++---------
 6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
 				void  *rps,
 				bool  *equal);
 /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
 	int (*set_fan_speed_pwm)(void *handle, u32 speed);
 	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
 	int (*force_clock_level)(void *handle, enum pp_clock_type type, uint32_t mask);
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +26 -5
index 68d2e80a673b..fe69785df403 100644
@@ -1030,15 +1030,20 @@ int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
 				    uint32_t *fan_mode)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
 	if (!pp_funcs->get_fan_control_mode)
 		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+
 	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle,
+					     fan_mode);
 	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
 }
 
 int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
@@ -1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
 	int ret = 0;
 
 	if (!pp_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
 		return -EINVAL;
 
 	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
 	int ret = 0;
 
 	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
 		return -EINVAL;
 
 	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
 	int ret = 0;
 
 	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
 		return -EINVAL;
 
 	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
 	int ret = 0;
 
 	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
 		return -EINVAL;
 
 	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
 				    uint32_t mode)
 {
 	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
 	if (!pp_funcs->set_fan_control_mode)
 		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
 	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
+					     mode);
 	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
 }
 
 int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -11
index d3eab245e0fe..940cbe751163 100644
@@ -3197,7 +3197,6 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
 	struct device *dev = kobj_to_dev(kobj);
 	struct amdgpu_device *adev = dev_get_drvdata(dev);
 	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
 	/* under multi-vf mode, the hwmon attributes are all not supported */
 	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
@@ -3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
 		return 0;
 
 	/* mask fan attributes if we have no bindings for this asic to expose */
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
 	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -EOPNOTSUPP) &&
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -EOPNOTSUPP) &&
 	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
 		effective_mode &= ~S_IRUGO;
 
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
 	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -EOPNOTSUPP) &&
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) == -EOPNOTSUPP) &&
 	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
 		effective_mode &= ~S_IWUSR;
 
@@ -3291,16 +3290,16 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
 		return 0;
 
 	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)) &&
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP)) &&
 	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
 	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
 		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL) &&
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP) &&
 	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
 	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
 		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +7 -3
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void *handle,
 	return 0;
 }
 
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
 		else
 			si_fan_ctrl_set_default_mode(adev);
 	}
+
+	return 0;
 }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32 *fan_mode)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 	struct si_power_info *si_pi = si_get_pi(adev);
@@ -6697,7 +6699,9 @@ static u32 si_dpm_get_fan_control_mode(void *handle)
 		return 0;
 
 	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
 }
 
 #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +27 -32

111 lines not on this page · raw message

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +60 -55

210 lines not on this page · raw message

Signature · 1 line
2.29.0
#1 lore raw
Quoted 38 lines · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power implementation details to

amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
---
  .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
  drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
  drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115 +++++++++---------
  6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
  				void  *rps,
  				bool  *equal);
  /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
  	int (*set_fan_speed_pwm)(void *handle, u32 speed);
  	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
  	int (*force_clock_level)(void *handle, enum pp_clock_type type, uint32_t mask);
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
index 68d2e80a673b..fe69785df403 100644
@@ -1030,15 +1030,20 @@ int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,
  				    uint32_t *fan_mode)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
  	if (!pp_funcs->get_fan_control_mode)
  		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

Thanks,
Lijo

Quoted 511 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +22 -5
  	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev->powerplay.pp_handle,
+					     fan_mode);
  	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
  }
 
  int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
@@ -1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,
  	int ret = 0;
 
  	if (!pp_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct amdgpu_device *adev,
  	int ret = 0;
 
  	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct amdgpu_device *adev,
  	int ret = 0;
 
  	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct amdgpu_device *adev,
  	int ret = 0;
 
  	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,
  				    uint32_t mode)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
  	if (!pp_funcs->set_fan_control_mode)
  		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
  	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
+					     mode);
  	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
  }
 
  int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,
drivers/gpu/drm/amd/pm/amdgpu_pm.c +10 -11
index d3eab245e0fe..940cbe751163 100644
@@ -3197,7 +3197,6 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  	struct device *dev = kobj_to_dev(kobj);
  	struct amdgpu_device *adev = dev_get_drvdata(dev);
  	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
  	/* under multi-vf mode, the hwmon attributes are all not supported */
  	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
@@ -3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  		return 0;
 
  	/* mask fan attributes if we have no bindings for this asic to expose */
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
  	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -EOPNOTSUPP) &&
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -EOPNOTSUPP) &&
  	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
  		effective_mode &= ~S_IRUGO;
 
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
  	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -EOPNOTSUPP) &&
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) == -EOPNOTSUPP) &&
  	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
  		effective_mode &= ~S_IWUSR;
 
@@ -3291,16 +3290,16 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
  		return 0;
 
  	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL) &&
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL) &&
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)) &&
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP)) &&
  	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL) &&
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL) &&
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP) &&
  	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
  	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
  		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +7 -3
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void *handle,
  	return 0;
  }
 
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
  		else
  			si_fan_ctrl_set_default_mode(adev);
  	}
+
+	return 0;
  }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32 *fan_mode)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct si_power_info *si_pi = si_get_pi(adev);
@@ -6697,7 +6699,9 @@ static u32 si_dpm_get_fan_control_mode(void *handle)
  		return 0;
 
  	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
  }
 
  #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +27 -32
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)
  	return pm_type;
  }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
  {
  	struct pp_hwmgr *hwmgr = handle;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n", __func__);
-		return;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
  	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
  }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t *fan_mode)
  {
  	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n", __func__);
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
+	*fan_mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
  	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
  }
 
  static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)
@@ -528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)
  	int ret = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n", __func__);
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr, speed);
  	mutex_unlock(&hwmgr->smu_lock);
@@ -546,12 +544,10 @@ static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)
  	int ret = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n", __func__);
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr, speed);
@@ -565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm)
  	int ret = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
  	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm);
@@ -582,12 +578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
  	int ret = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n", __func__);
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr, rpm);
  	mutex_unlock(&hwmgr->smu_lock);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +60 -55
index c374c3067496..474f1f04cc96 100644
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context *smu,
  			   bool lock_needed);
  static int smu_reset(struct smu_context *smu);
  static int smu_set_fan_speed_pwm(void *handle, u32 speed);
-static int smu_set_fan_control_mode(struct smu_context *smu, int value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
  static int smu_set_power_limit(void *handle, uint32_t limit);
  static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);
  static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
@@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)
  	if (smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_MANUAL ||
  	    smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_NONE) {
  		ret = smu_set_fan_control_mode(smu, smu->user_dpm_profile.fan_mode);
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
  			smu->user_dpm_profile.fan_speed_pwm = 0;
  			smu->user_dpm_profile.fan_speed_rpm = 0;
  			smu->user_dpm_profile.fan_mode = AMD_FAN_CTRL_AUTO;
@@ -416,13 +416,13 @@ static void smu_restore_dpm_user_profile(struct smu_context *smu)
 
  		if (smu->user_dpm_profile.fan_speed_pwm) {
  			ret = smu_set_fan_speed_pwm(smu, smu->user_dpm_profile.fan_speed_pwm);
-			if (ret)
+			if (ret != -EOPNOTSUPP)
  				dev_err(smu->adev->dev, "Failed to set manual fan speed in pwm\n");
  		}
 
  		if (smu->user_dpm_profile.fan_speed_rpm) {
  			ret = smu_set_fan_speed_rpm(smu, smu->user_dpm_profile.fan_speed_rpm);
-			if (ret)
+			if (ret != -EOPNOTSUPP)
  				dev_err(smu->adev->dev, "Failed to set manual fan speed in rpm\n");
  		}
  	}
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
-			smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_RPM;
-			smu->user_dpm_profile.fan_speed_rpm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
+		smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_RPM;
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they cannot co-exist */
-			smu->user_dpm_profile.flags &= ~SMU_CUSTOM_FAN_SPEED_PWM;
-			smu->user_dpm_profile.fan_speed_pwm = 0;
-		}
+		/* Override custom PWM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &= ~SMU_CUSTOM_FAN_SPEED_PWM;
+		smu->user_dpm_profile.fan_speed_pwm = 0;
  	}
 
  	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int smu_set_power_profile_mode(void *handle,
  }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
  {
  	struct smu_context *smu = handle;
-	u32 ret = 0;
 
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
 
  	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
  }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
  {
+	struct smu_context *smu = handle;
  	int ret = 0;
 
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
-		if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE))
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
+		smu->user_dpm_profile.fan_mode = value;
 
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &= ~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm = 0;
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &= ~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);
+		}
  	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value)
-{
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
-	smu_set_fan_control_mode(smu, value);
+	return ret;
  }
 
-
  static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
  {
  	struct smu_context *smu = handle;
@@ -2624,10 +2624,12 @@ static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
  	mutex_unlock(&smu->mutex);
 
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void *handle, u32 speed)
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
-			smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_PWM;
-			smu->user_dpm_profile.fan_speed_pwm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {
+		smu->user_dpm_profile.flags |= SMU_CUSTOM_FAN_SPEED_PWM;
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they cannot co-exist */
-			smu->user_dpm_profile.flags &= ~SMU_CUSTOM_FAN_SPEED_RPM;
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &= ~SMU_CUSTOM_FAN_SPEED_RPM;
+		smu->user_dpm_profile.fan_speed_rpm = 0;
  	}
 
  	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void *handle, uint32_t *speed)
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
  	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void *handle, void **addr, size_t *size)
 
  static const struct amd_pm_funcs swsmu_pm_funcs = {
  	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
  	.get_fan_control_mode    = smu_get_fan_control_mode,
  	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,
  	.get_fan_speed_pwm   = smu_get_fan_speed_pwm,
author
#2 lore raw

[AMD Official Use Only]

Quoted 71 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 4:14 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 4 lines · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power

implementation

Quoted 5 lines

details to
amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
Quoted 7 lines
---
  .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
  drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
  drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
  drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
  .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115 +++++++++----

-----

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 24 lines
  6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
  				void  *rps,
  				bool  *equal);
  /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
  	int (*set_fan_speed_pwm)(void *handle, u32 speed);
  	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
  	int (*force_clock_level)(void *handle, enum pp_clock_type type,

uint32_t mask); diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 68d2e80a673b..fe69785df403 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1030,15 +1030,20 @@ int

amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
  				    uint32_t *fan_mode)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
  	if (!pp_funcs->get_fan_control_mode)
  		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

Quoted 2 lines

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

[Quan, Evan] Yes, I agree. And if you go through the changes below, you will see the checks (for the layers down) there. This patch checks not only those amdgpu_dpm_xxxx APIs, but also those downstream interfaces(smu_xxxx and pp_dpm_xxxx).

BR
Evan

Quoted 610 lines

Thanks,
Lijo

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -2
  	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle,
+					     fan_mode);
  	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
  }
Quoted 1 line

int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,

@@

Quoted 1 line

-1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_pwm(struct

Quoted 10 lines
  	int ret = 0;

if (!pp_funcs->set_fan_speed_pwm)

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
  	int ret = 0;
 
  	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
  	int ret = 0;
 
  	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
  	int ret = 0;
 
  	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
  		return -EINVAL;
 
  	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int

amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct

Quoted 30 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -3
  				    uint32_t mode)
  {
  	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
  	if (!pp_funcs->set_fan_control_mode)
  		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
  	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev-
 powerplay.pp_handle,
+					     mode);
  	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
  }
 

int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, diff
--git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index d3eab245e0fe..940cbe751163 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3197,7 +3197,6 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  	struct device *dev = kobj_to_dev(kobj);
  	struct amdgpu_device *adev = dev_get_drvdata(dev);
  	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
  	/* under multi-vf mode, the hwmon attributes are all not supported

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj, · line 3202

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))

@@

Quoted 1 line

-3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

Quoted 3 lines

return 0;

/* mask fan attributes if we have no bindings for this asic to expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 1 line
  	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 1 line

attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
  		effective_mode &= ~S_IRUGO;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

Quoted 1 line
  	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) ==
+-EOPNOTSUPP) &&
  	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
  		effective_mode &= ~S_IWUSR;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3291,16 +3290,16 @@ static umode_t

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  		return 0;
 
  	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3297

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL))

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3293

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP)) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
  	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3303

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3301

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3302

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
  	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
  	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
  		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void

*handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void si_dpm_set_fan_control_mode(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
  	return 0;
  }
 
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void si_dpm_set_fan_control_mode(void

*handle, u32 mode)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type

Quoted 29 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
  		else
  			si_fan_ctrl_set_default_mode(adev);
  	}
+
+	return 0;
  }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32 *fan_mode)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  	struct si_power_info *si_pi = si_get_pi(adev); @@ -6697,7 +6699,9

@@ static u32 si_dpm_get_fan_control_mode(void *handle)
return 0;

  	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
  }
 
  #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type

pp_dpm_get_current_power_state(void *handle)

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
  	return pm_type;
  }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
  {
  	struct pp_hwmgr *hwmgr = handle;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 15 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -4
-		return;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
  	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
  }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t
+*fan_mode)
  {
  	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) · line 524

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -4
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
+	*fan_mode = hwmgr->hwmgr_func-
 get_fan_control_mode(hwmgr);
  	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
  }
 
  static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

@@

Quoted 1 line

-528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void *handle,

uint32_t speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

Quoted 11 lines
  	int ret = 0;

  	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr, speed);
  	mutex_unlock(&hwmgr->smu_lock);
@@ -546,12 +544,10 @@ static int pp_dpm_get_fan_speed_pwm(void

*handle, uint32_t *speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -3
  	int ret = 0;
 
  	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed) · line 553

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr, speed);

@@

Quoted 1 line

-565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void *handle,

uint32_t *rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) · line 570

Quoted 12 lines
  	int ret = 0;

  	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
  	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm);

@@ -582,12

Quoted 1 line

+578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle,

uint32_t rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)

Quoted 11 lines
  	int ret = 0;

  	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct

Quoted 20 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
  	mutex_lock(&hwmgr->smu_lock);
  	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr, rpm);
  	mutex_unlock(&hwmgr->smu_lock);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index c374c3067496..474f1f04cc96 100644
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context *smu,
  			   bool lock_needed);
  static int smu_reset(struct smu_context *smu);
  static int smu_set_fan_speed_pwm(void *handle, u32 speed); -static
 int smu_set_fan_control_mode(struct smu_context *smu, int value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
  static int smu_set_power_limit(void *handle, uint32_t limit);
  static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);
  static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
@@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct

smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct · line 407

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
  	if (smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_MANUAL ||

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
  	    smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_NONE) {
  		ret = smu_set_fan_control_mode(smu, smu-
 user_dpm_profile.fan_mode);
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
  			smu->user_dpm_profile.fan_speed_pwm = 0;
  			smu->user_dpm_profile.fan_speed_rpm = 0;

smu->user_dpm_profile.fan_mode =

AMD_FAN_CTRL_AUTO; @@ -416,13

Quoted 1 line

+416,13 @@ static void smu_restore_dpm_user_profile(struct

smu_context

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

*smu)

if (smu->user_dpm_profile.fan_speed_pwm) {
ret = smu_set_fan_speed_pwm(smu, smu-
user_dpm_profile.fan_speed_pwm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
  				dev_err(smu->adev->dev, "Failed to set

manual fan speed in pwm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines
  		}

if (smu->user_dpm_profile.fan_speed_rpm) {
ret = smu_set_fan_speed_rpm(smu, smu-
user_dpm_profile.fan_speed_rpm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
  				dev_err(smu->adev->dev, "Failed to set

manual fan speed in rpm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void

Quoted 3 lines
  		}
  	}
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void

*handle, uint32_t speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2226

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_rpm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2228

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2230

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_pwm = 0;
-		}
+		/* Override custom PWM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_pwm = 0;
  	}
 
  	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int smu_set_power_profile_mode(void

*handle,

Quoted 37 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -8
  }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
  {
  	struct smu_context *smu = handle;
-	u32 ret = 0;
 
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
 
  	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
  }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
  {
+	struct smu_context *smu = handle;
  	int ret = 0;
 
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -3
+		smu->user_dpm_profile.fan_mode = value;
 
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm = 0;
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_pwm(void

Quoted 20 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -7
+		}
  	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value) -{
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
-	smu_set_fan_control_mode(smu, value);
+	return ret;
  }
 
-
  static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
  {
  	struct smu_context *smu = handle;
@@ -2624,10 +2624,12 @@ static int smu_get_fan_speed_pwm(void

*handle, u32 *speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void

Quoted 15 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -2
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
  	mutex_unlock(&smu->mutex);
 
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void

*handle, u32 speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2650

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_pwm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_rpm = 0;
  	}
 
  	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void

*handle, uint32_t *speed)

Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -3
  	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
  		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
  	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
  	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void
 *handle, void **addr, size_t *size)
 
  static const struct amd_pm_funcs swsmu_pm_funcs = {
  	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
  	.get_fan_control_mode    = smu_get_fan_control_mode,
  	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,

.get_fan_speed_pwm = smu_get_fan_speed_pwm,

#3 lore raw
Quoted 75 lines · Evan

[AMD Official Use Only]

Quoted 71 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 4:14 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 4 lines · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power

implementation

Quoted 5 lines

details to
amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
Quoted 7 lines
---
   .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
   drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
   drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
   .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115 +++++++++----

-----

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 24 lines
   6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
   				void  *rps,
   				bool  *equal);
   /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
   	int (*set_fan_speed_pwm)(void *handle, u32 speed);
   	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
   	int (*force_clock_level)(void *handle, enum pp_clock_type type,

uint32_t mask); diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 68d2e80a673b..fe69785df403 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1030,15 +1030,20 @@ int

amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
   				    uint32_t *fan_mode)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
   	if (!pp_funcs->get_fan_control_mode)
   		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

Quoted 5 lines
Quoted 2 lines

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

[Quan, Evan] Yes, I agree. And if you go through the changes below, you will see the checks (for the layers down) there. This patch checks not only those amdgpu_dpm_xxxx APIs, but also those downstream interfaces(smu_xxxx and pp_dpm_xxxx).

Say you call amdgpu_dpm_get_fan_control_mode(adev, NULL) from amdgpu_pm

pp_funcs->get_fan_control_mode => this will point to smu_get_fan_control_mode for all swsmu ASICs. So "if (!pp_funcs->get_fan_control_mode)" will be false.

The next statement is NULL check and it will return -EINVAL.

What we want to know is ppt_func is implemented or not for the particualr swsmu ASIC. Isn't that the case or am I reading it differently?

Thanks,
Lijo

Quoted 612 lines

BR
Evan

Quoted 610 lines

Thanks,
Lijo

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -2
   	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle,
+					     fan_mode);
   	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
   }
Quoted 1 line

int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,

@@

Quoted 1 line

-1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_pwm(struct

Quoted 10 lines
   	int ret = 0;
   	if (!pp_funcs->set_fan_speed_pwm)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int

amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct

Quoted 30 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -3
   				    uint32_t mode)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
   	if (!pp_funcs->set_fan_control_mode)
   		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
   	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev-
 powerplay.pp_handle,
+					     mode);
   	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
   }
 

int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, diff
--git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index d3eab245e0fe..940cbe751163 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3197,7 +3197,6 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   	struct device *dev = kobj_to_dev(kobj);
   	struct amdgpu_device *adev = dev_get_drvdata(dev);
   	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
   	/* under multi-vf mode, the hwmon attributes are all not supported

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj, · line 3202

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))

@@

Quoted 1 line

-3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

Quoted 3 lines
   		return 0;

   	/* mask fan attributes if we have no bindings for this asic to expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 1 line
   	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 1 line
   	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
   		effective_mode &= ~S_IRUGO;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

Quoted 1 line
   	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) ==
+-EOPNOTSUPP) &&
   	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
   		effective_mode &= ~S_IWUSR;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3291,16 +3290,16 @@ static umode_t

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   		return 0;
 
   	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3297

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL))

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3293

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP)) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
   	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
   		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3303

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3301

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3302

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
   	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
   		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void

*handle,

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void si_dpm_set_fan_control_mode(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
   	return 0;
   }
 
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void si_dpm_set_fan_control_mode(void

*handle, u32 mode)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type

Quoted 29 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
   		else
   			si_fan_ctrl_set_default_mode(adev);
   	}
+
+	return 0;
   }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32 *fan_mode)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   	struct si_power_info *si_pi = si_get_pi(adev); @@ -6697,7 +6699,9

@@ static u32 si_dpm_get_fan_control_mode(void *handle)
return 0;

   	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
   }
 
   #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type

pp_dpm_get_current_power_state(void *handle)

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
   	return pm_type;
   }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode)
   {
   	struct pp_hwmgr *hwmgr = handle;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 15 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -4
-		return;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
   	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
   }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t
+*fan_mode)
   {
   	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) · line 524

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -4
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
+	*fan_mode = hwmgr->hwmgr_func-
 get_fan_control_mode(hwmgr);
   	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
   }
 
   static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

@@

Quoted 1 line

-528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void *handle,

uint32_t speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

Quoted 11 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr, speed);
   	mutex_unlock(&hwmgr->smu_lock);
@@ -546,12 +544,10 @@ static int pp_dpm_get_fan_speed_pwm(void

*handle, uint32_t *speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -3
   	int ret = 0;
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed) · line 553

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr, speed);

@@

Quoted 1 line

-565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void *handle,

uint32_t *rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) · line 570

Quoted 12 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
   	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm);

@@ -582,12

Quoted 1 line

+578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle,

uint32_t rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)

Quoted 11 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct

Quoted 20 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr, rpm);
   	mutex_unlock(&hwmgr->smu_lock);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
index c374c3067496..474f1f04cc96 100644
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context *smu,
   			   bool lock_needed);
   static int smu_reset(struct smu_context *smu);
   static int smu_set_fan_speed_pwm(void *handle, u32 speed); -static
 int smu_set_fan_control_mode(struct smu_context *smu, int value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
   static int smu_set_power_limit(void *handle, uint32_t limit);
   static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);
   static int smu_set_gfx_cgpg(struct smu_context *smu, bool enabled);
@@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct

smu_context *smu)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct · line 407

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
   	if (smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_MANUAL ||

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
   	    smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_NONE) {
   		ret = smu_set_fan_control_mode(smu, smu-
 user_dpm_profile.fan_mode);
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
   			smu->user_dpm_profile.fan_speed_pwm = 0;
   			smu->user_dpm_profile.fan_speed_rpm = 0;
   			smu->user_dpm_profile.fan_mode =

AMD_FAN_CTRL_AUTO; @@ -416,13

Quoted 1 line

+416,13 @@ static void smu_restore_dpm_user_profile(struct

smu_context

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

*smu)

if (smu->user_dpm_profile.fan_speed_pwm) {
ret = smu_set_fan_speed_pwm(smu, smu-
user_dpm_profile.fan_speed_pwm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
   				dev_err(smu->adev->dev, "Failed to set

manual fan speed in pwm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines
   		}

if (smu->user_dpm_profile.fan_speed_rpm) {
ret = smu_set_fan_speed_rpm(smu, smu-
user_dpm_profile.fan_speed_rpm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
   				dev_err(smu->adev->dev, "Failed to set

manual fan speed in rpm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void

Quoted 3 lines
   		}
   	}
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void

*handle, uint32_t speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2226

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_rpm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2228

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2230

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_pwm = 0;
-		}
+		/* Override custom PWM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_pwm = 0;
   	}
 
   	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int smu_set_power_profile_mode(void

*handle,

Quoted 37 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -8
   }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
   {
   	struct smu_context *smu = handle;
-	u32 ret = 0;
 
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
 
   	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
   }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
   {
+	struct smu_context *smu = handle;
   	int ret = 0;
 
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -3
+		smu->user_dpm_profile.fan_mode = value;
 
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm = 0;
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM | SMU_CUSTOM_FAN_SPEED_PWM);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_pwm(void

Quoted 20 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -7
+		}
   	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value) -{
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
-	smu_set_fan_control_mode(smu, value);
+	return ret;
   }
 
-
   static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
   {
   	struct smu_context *smu = handle;
@@ -2624,10 +2624,12 @@ static int smu_get_fan_speed_pwm(void

*handle, u32 *speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void

Quoted 15 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -2
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
   	mutex_unlock(&smu->mutex);
 
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void

*handle, u32 speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2650

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_pwm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_rpm = 0;
   	}
 
   	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void

*handle, uint32_t *speed)

Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
   	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void
 *handle, void **addr, size_t *size)
 
   static const struct amd_pm_funcs swsmu_pm_funcs = {
   	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
   	.get_fan_control_mode    = smu_get_fan_control_mode,
   	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,

.get_fan_speed_pwm = smu_get_fan_speed_pwm,

author
#4 lore raw

[AMD Official Use Only]

Quoted 100 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 6:15 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 33 lines · Evan

[AMD Official Use Only]

Quoted 29 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 4:14 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 4 lines · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power

implementation

Quoted 12 lines

details to
amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
---
   .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
   drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
   drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
   drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
   .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
   drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115

+++++++++----

Quoted 43 lines
Quoted 43 lines

-----

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 24 lines
   6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
   				void  *rps,
   				bool  *equal);
   /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
   	int (*set_fan_speed_pwm)(void *handle, u32 speed);
   	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
   	int (*force_clock_level)(void *handle, enum pp_clock_type type,

uint32_t mask); diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 68d2e80a673b..fe69785df403 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1030,15 +1030,20 @@ int

amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
   				    uint32_t *fan_mode)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
   	if (!pp_funcs->get_fan_control_mode)
   		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

Quoted 3 lines
Quoted 2 lines

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

[Quan, Evan] Yes, I agree. And if you go through the changes below, you

will see the checks (for the layers down) there.

Quoted 1 line

This patch checks not only those amdgpu_dpm_xxxx APIs, but also those

downstream interfaces(smu_xxxx and pp_dpm_xxxx).

Quoted 1 line

Say you call amdgpu_dpm_get_fan_control_mode(adev, NULL) from amdgpu_pm

Quoted 9 lines

pp_funcs->get_fan_control_mode => this will point to smu_get_fan_control_mode for all swsmu ASICs. So "if (!pp_funcs-

Quoted 1 line

get_fan_control_mode)" will be false.

The next statement is NULL check and it will return -EINVAL.

What we want to know is ppt_func is implemented or not for the particualr swsmu ASIC. Isn't that the case or am I reading it differently?

[Quan, Evan] OK, I get your point now. Hmm, that will be a little tricky.
I suppose the EINVAL check needs to be dispatched in every instance(pp_dpm_xxxxx, smu_xxxx, si_dpm_xxxx) then. Any better idea?

BR
Evan

Quoted 633 lines

Thanks,
Lijo

Quoted 89 lines

BR
Evan

Quoted 87 lines

Thanks,
Lijo

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -2
   	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle,
+					     fan_mode);
   	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
   }
Quoted 1 line

int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,

@@

Quoted 1 line

-1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_pwm(struct

Quoted 10 lines
   	int ret = 0;
   	if (!pp_funcs->set_fan_speed_pwm)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
   	int ret = 0;
 
   	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
   		return -EINVAL;
 
   	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int

amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

Quoted 23 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -3
   				    uint32_t mode)
   {
   	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
   	if (!pp_funcs->set_fan_control_mode)
   		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
   	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev-
 powerplay.pp_handle,
+					     mode);
   	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
   }
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 7 lines

int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, diff
--git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index d3eab245e0fe..940cbe751163 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3197,7 +3197,6 @@ static umode_t

hwmon_attributes_visible(struct

Quoted 95 lines
Quoted 95 lines

kobject *kobj,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   	struct device *dev = kobj_to_dev(kobj);
   	struct amdgpu_device *adev = dev_get_drvdata(dev);
   	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
   	/* under multi-vf mode, the hwmon attributes are all not

supported

*/

Quoted 1 line
   	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))

@@

Quoted 1 line

-3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

Quoted 4 lines
   		return 0;

   	/* mask fan attributes if we have no bindings for this asic to

expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 2 lines
   	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 2 lines
   	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /*

can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
   		effective_mode &= ~S_IRUGO;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

Quoted 1 line
   	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -

EOPNOTSUPP) &&

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) ==
+-EOPNOTSUPP) &&
   	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /*

can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
   		effective_mode &= ~S_IWUSR;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3291,16 +3290,16 @@ static umode_t

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   		return 0;
 
   	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3297

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL))

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3293

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP)) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
   	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
   	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
   		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3303

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3301

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3302

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
   	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
   	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
   		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void

*handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
   	return 0;
   }
 
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void

Quoted 6 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void

si_dpm_set_fan_control_mode(void

Quoted 10 lines
Quoted 10 lines

*handle, u32 mode)

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void si_dpm_set_fan_control_mode(void *handle, u32 mode)

Quoted 9 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
   		else
   			si_fan_ctrl_set_default_mode(adev);
   	}
+
+	return 0;
   }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32

*fan_mode)

Quoted 21 lines
Quoted 21 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type

Quoted 20 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +4 -1
   {
   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
   	struct si_power_info *si_pi = si_get_pi(adev); @@ -6697,7
+6699,9 @@ static u32 si_dpm_get_fan_control_mode(void *handle)
   		return 0;
 
   	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
   }
 
   #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type

pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
   	return pm_type;
   }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t
 mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t

mode)

Quoted 50 lines
Quoted 50 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
   {
   	struct pp_hwmgr *hwmgr = handle;
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 15 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -4
-		return;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
   	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
   }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t
+*fan_mode)
   {
   	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -4
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
+	*fan_mode = hwmgr->hwmgr_func-
 get_fan_control_mode(hwmgr);
   	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
   }
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

@@

Quoted 1 line

-528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void

*handle,

Quoted 34 lines
Quoted 34 lines

uint32_t speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

Quoted 11 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr, speed);
   	mutex_unlock(&hwmgr->smu_lock);
@@ -546,12 +544,10 @@ static int pp_dpm_get_fan_speed_pwm(void

*handle, uint32_t *speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -3
   	int ret = 0;
 
   	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed) · line 553

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr, speed);

@@

Quoted 1 line

-565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void

*handle,

Quoted 28 lines
Quoted 28 lines

uint32_t *rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) · line 570

Quoted 12 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
   	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm);

@@ -582,12

Quoted 1 line

+578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle,

uint32_t rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)

Quoted 11 lines
   	int ret = 0;

   	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_handle_task(struct smu_context

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
   	mutex_lock(&hwmgr->smu_lock);
   	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr, rpm);
   	mutex_unlock(&hwmgr->smu_lock);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index c374c3067496..474f1f04cc96 100644
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context

*smu,

Quoted 78 lines
Quoted 78 lines
Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
   			   bool lock_needed);
   static int smu_reset(struct smu_context *smu);
   static int smu_set_fan_speed_pwm(void *handle, u32 speed);
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
   static int smu_set_power_limit(void *handle, uint32_t limit);
   static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);

static int smu_set_gfx_cgpg(struct smu_context *smu, bool
enabled); @@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct

smu_context *smu)

Quoted 1 line
   	if (smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_MANUAL ||

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_NONE) {
ret = smu_set_fan_control_mode(smu, smu-
user_dpm_profile.fan_mode);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
   			smu->user_dpm_profile.fan_speed_pwm = 0;
   			smu->user_dpm_profile.fan_speed_rpm = 0;
   			smu->user_dpm_profile.fan_mode =

AMD_FAN_CTRL_AUTO; @@ -416,13

Quoted 1 line

+416,13 @@ static void smu_restore_dpm_user_profile(struct

smu_context

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

*smu)

if (smu->user_dpm_profile.fan_speed_pwm) {
ret = smu_set_fan_speed_pwm(smu, smu-
user_dpm_profile.fan_speed_pwm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
   				dev_err(smu->adev->dev, "Failed to set

manual fan speed in pwm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines
   		}

if (smu->user_dpm_profile.fan_speed_rpm) {
ret = smu_set_fan_speed_rpm(smu, smu-
user_dpm_profile.fan_speed_rpm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
   				dev_err(smu->adev->dev, "Failed to set

manual fan speed in rpm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void

Quoted 3 lines
   		}
   	}
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void

*handle, uint32_t speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2226

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_rpm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2228

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2230

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_pwm = 0;
-		}
+		/* Override custom PWM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_pwm = 0;
   	}
 
   	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int

smu_set_power_profile_mode(void

Quoted 60 lines
Quoted 60 lines

*handle,

Quoted 37 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -8
   }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
   {
   	struct smu_context *smu = handle;
-	u32 ret = 0;
 
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
 
   	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
   }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
   {
+	struct smu_context *smu = handle;
   	int ret = 0;
 
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_mode = value;
 
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm = 0;
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 99 lines
Quoted 99 lines
Quoted 19 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -7
+		}
   	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value) -{
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
-	smu_set_fan_control_mode(smu, value);
+	return ret;
   }
 
-
   static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
   {
   	struct smu_context *smu = handle; @@ -2624,10 +2624,12 @@ static
Quoted 1 line

int smu_get_fan_speed_pwm(void

*handle, u32 *speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void

Quoted 15 lines
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -2
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
   	mutex_unlock(&smu->mutex);
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void

*handle, u32 speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2650

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_pwm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_rpm = 0;
   	}
 
   	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void

*handle, uint32_t *speed)

Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -3
   	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
   		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
   	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
   	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void
 *handle, void **addr, size_t *size)
 
   static const struct amd_pm_funcs swsmu_pm_funcs = {
   	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
   	.get_fan_control_mode    = smu_get_fan_control_mode,
   	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,

.get_fan_speed_pwm = smu_get_fan_speed_pwm,

#5 lore raw
Quoted 108 lines · Evan

[AMD Official Use Only]

Quoted 104 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 6:15 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 33 lines · Evan

[AMD Official Use Only]

Quoted 29 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 4:14 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 4 lines · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And we rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power

implementation

Quoted 12 lines

details to
amdgpu_pm.c")

Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
---
    .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
    drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
    drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
    drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
    .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
    drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115

+++++++++----

Quoted 43 lines
Quoted 43 lines

-----

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 24 lines
    6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
    				void  *rps,
    				bool  *equal);
    /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
    	int (*set_fan_speed_pwm)(void *handle, u32 speed);
    	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
    	int (*force_clock_level)(void *handle, enum pp_clock_type type,

uint32_t mask); diff --git a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 68d2e80a673b..fe69785df403 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1030,15 +1030,20 @@ int

amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 11 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
    				    uint32_t *fan_mode)
    {
    	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
    	if (!pp_funcs->get_fan_control_mode)
    		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

Quoted 3 lines
Quoted 2 lines

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

[Quan, Evan] Yes, I agree. And if you go through the changes below, you

will see the checks (for the layers down) there.

Quoted 1 line

This patch checks not only those amdgpu_dpm_xxxx APIs, but also those

downstream interfaces(smu_xxxx and pp_dpm_xxxx).

Quoted 1 line

Say you call amdgpu_dpm_get_fan_control_mode(adev, NULL) from amdgpu_pm

pp_funcs->get_fan_control_mode => this will point to smu_get_fan_control_mode for all swsmu ASICs. So "if (!pp_funcs-

Quoted 1 line

get_fan_control_mode)" will be false.

Quoted 8 lines
Quoted 5 lines

The next statement is NULL check and it will return -EINVAL.

What we want to know is ppt_func is implemented or not for the particualr swsmu ASIC. Isn't that the case or am I reading it differently?

[Quan, Evan] OK, I get your point now. Hmm, that will be a little tricky.
I suppose the EINVAL check needs to be dispatched in every instance(pp_dpm_xxxxx, smu_xxxx, si_dpm_xxxx) then. Any better idea?

Yeah, that is what I meant by "checks should be at one layer down".

Thanks,
Lijo

Quoted 635 lines

BR
Evan

Quoted 633 lines

Thanks,
Lijo

Quoted 89 lines

BR
Evan

Quoted 87 lines

Thanks,
Lijo

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -2
    	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle,
+					     fan_mode);
    	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
    }
Quoted 1 line

int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device *adev,

@@

Quoted 1 line

-1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_pwm(struct

Quoted 10 lines
    	int ret = 0;

    	if (!pp_funcs->set_fan_speed_pwm)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int amdgpu_dpm_get_fan_speed_pwm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int amdgpu_dpm_get_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_fan_speed_rpm(struct

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int amdgpu_dpm_set_fan_speed_rpm(struct

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int

amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

Quoted 23 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +7 -3
    				    uint32_t mode)
    {
    	const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
+	int ret = 0;
 
    	if (!pp_funcs->set_fan_control_mode)
    		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
    	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev->powerplay.pp_handle,
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev-
 powerplay.pp_handle,
+					     mode);
    	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
    }
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 7 lines

int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev, diff
--git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index d3eab245e0fe..940cbe751163 100644

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3197,7 +3197,6 @@ static umode_t

hwmon_attributes_visible(struct

Quoted 95 lines
Quoted 95 lines

kobject *kobj,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
    	struct device *dev = kobj_to_dev(kobj);
    	struct amdgpu_device *adev = dev_get_drvdata(dev);
    	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
    	/* under multi-vf mode, the hwmon attributes are all not

supported

*/

Quoted 1 line
    	if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))

@@

Quoted 1 line

-3263,15 +3262,15 @@ static umode_t hwmon_attributes_visible(struct

kobject *kobj,

Quoted 4 lines
    		return 0;

    	/* mask fan attributes if we have no bindings for this asic to

expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 2 lines
    	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 2 lines
    	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /*

can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
    		effective_mode &= ~S_IRUGO;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

Quoted 1 line
    	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) == -

EOPNOTSUPP) &&

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +2 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) ==
+-EOPNOTSUPP) &&
    	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /*

can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
    		effective_mode &= ~S_IWUSR;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3291,16 +3290,16 @@ static umode_t

hwmon_attributes_visible(struct kobject *kobj,

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 4 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
    		return 0;
 
    	/* hide max/min values if we can't both query and manage the fan */
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3297

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL))

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3293

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP)) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
    	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
    	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
    		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3303

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -EINVAL)

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3301

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3302

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
    	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
    	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
    		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void

*handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
    	return 0;
    }
 
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void

Quoted 6 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
@@ -6685,9 +6685,11 @@ static void

si_dpm_set_fan_control_mode(void

Quoted 10 lines
Quoted 10 lines

*handle, u32 mode)

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void si_dpm_set_fan_control_mode(void *handle, u32 mode)

Quoted 9 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +3 -1
    		else
    			si_fan_ctrl_set_default_mode(adev);
    	}
+
+	return 0;
    }
 
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32

*fan_mode)

Quoted 21 lines
Quoted 21 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type

Quoted 20 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +4 -1
    {
    	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
    	struct si_power_info *si_pi = si_get_pi(adev); @@ -6697,7
+6699,9 @@ static u32 si_dpm_get_fan_control_mode(void *handle)
    		return 0;
 
    	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
    }
 
    #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type

pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
    	return pm_type;
    }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t
 mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t

mode)

Quoted 50 lines
Quoted 50 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 12 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
    {
    	struct pp_hwmgr *hwmgr = handle;
 
    	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 15 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -4
-		return;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode);
    	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
    }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t
+*fan_mode)
    {
    	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
 
    	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -4
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr);
+	*fan_mode = hwmgr->hwmgr_func-
 get_fan_control_mode(hwmgr);
    	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
    }
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

@@

Quoted 1 line

-528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void

*handle,

Quoted 34 lines
Quoted 34 lines

uint32_t speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

Quoted 11 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr, speed);
    	mutex_unlock(&hwmgr->smu_lock);
@@ -546,12 +544,10 @@ static int pp_dpm_get_fan_speed_pwm(void

*handle, uint32_t *speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 8 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -3
    	int ret = 0;
 
    	if (!hwmgr || !hwmgr->pm_en)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 5 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed) · line 553

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr, speed);

@@

Quoted 1 line

-565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void

*handle,

Quoted 28 lines
Quoted 28 lines

uint32_t *rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) · line 570

Quoted 12 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
    	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm);

@@ -582,12

Quoted 1 line

+578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle,

uint32_t rpm)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)

Quoted 11 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_handle_task(struct smu_context

Quoted 11 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr, rpm);
    	mutex_unlock(&hwmgr->smu_lock);
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
index c374c3067496..474f1f04cc96 100644
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context

*smu,

Quoted 78 lines
Quoted 78 lines
Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
    			   bool lock_needed);
    static int smu_reset(struct smu_context *smu);
    static int smu_set_fan_speed_pwm(void *handle, u32 speed);
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
    static int smu_set_power_limit(void *handle, uint32_t limit);
    static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);

static int smu_set_gfx_cgpg(struct smu_context *smu, bool
enabled); @@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct

smu_context *smu)

Quoted 1 line
    	if (smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_MANUAL ||

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

smu->user_dpm_profile.fan_mode == AMD_FAN_CTRL_NONE) {
ret = smu_set_fan_control_mode(smu, smu-
user_dpm_profile.fan_mode);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
    			smu->user_dpm_profile.fan_speed_pwm = 0;
    			smu->user_dpm_profile.fan_speed_rpm = 0;
    			smu->user_dpm_profile.fan_mode =

AMD_FAN_CTRL_AUTO; @@ -416,13

Quoted 1 line

+416,13 @@ static void smu_restore_dpm_user_profile(struct

smu_context

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

*smu)

if (smu->user_dpm_profile.fan_speed_pwm) {
ret = smu_set_fan_speed_pwm(smu, smu-
user_dpm_profile.fan_speed_pwm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
    				dev_err(smu->adev->dev, "Failed to set

manual fan speed in pwm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines
    		}

    		if (smu->user_dpm_profile.fan_speed_rpm) {
    			ret = smu_set_fan_speed_rpm(smu, smu-

user_dpm_profile.fan_speed_rpm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
    				dev_err(smu->adev->dev, "Failed to set

manual fan speed in rpm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void

Quoted 3 lines
    		}
    	}
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void

*handle, uint32_t speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2226

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_rpm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2228

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2230

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_pwm = 0;
-		}
+		/* Override custom PWM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_pwm = 0;
    	}
 
    	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int

smu_set_power_profile_mode(void

Quoted 60 lines
Quoted 60 lines

*handle,

Quoted 37 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +9 -8
    }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
    {
    	struct smu_context *smu = handle;
-	u32 ret = 0;
 
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs->get_fan_control_mode(smu);
 
    	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
    }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
    {
+	struct smu_context *smu = handle;
    	int ret = 0;
 
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_mode = value;
 
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -0
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm = 0;
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 99 lines
Quoted 99 lines
Quoted 19 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -7
+		}
    	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value) -{
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
-	smu_set_fan_control_mode(smu, value);
+	return ret;
    }
 
-
    static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
    {
    	struct smu_context *smu = handle; @@ -2624,10 +2624,12 @@ static
Quoted 1 line

int smu_get_fan_speed_pwm(void

*handle, u32 *speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void

Quoted 15 lines
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -2
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
    	mutex_unlock(&smu->mutex);
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void

*handle, u32 speed)

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -3
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2650

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-			smu->user_dpm_profile.fan_speed_pwm = speed;
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they cannot co-

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -2
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-exist */
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_rpm = 0;
    	}
 
    	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void

*handle, uint32_t *speed)

Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -3
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
    	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void
 *handle, void **addr, size_t *size)
 
    static const struct amd_pm_funcs swsmu_pm_funcs = {
    	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
    	.get_fan_control_mode    = smu_get_fan_control_mode,
    	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,

.get_fan_speed_pwm = smu_get_fan_speed_pwm,

author
#6 lore raw

[AMD Official Use Only]

Quoted 132 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 6:53 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 24 lines · Evan

[AMD Official Use Only]

Quoted 20 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 6:15 PM
To: Quan, Evan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Chen, Guchun <[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 8 lines · Evan

[AMD Official Use Only]

Quoted 4 lines

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Tuesday, January 11, 2022 4:14 PM
To: Quan, Evan <[email protected]>; amd-

[email protected]

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Cc Deucher, Alexander <[email protected]>; Chen,

Guchun

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

<[email protected]>
Subject: Re: [PATCH] drm/amd/pm: correct the checks for fan attributes support

Quoted 1 line · Evan Quan

On functionality unsupported, -EOPNOTSUPP will be returned. And

we

Quoted 84 lines
Quoted 84 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

rely on that to determine the fan attributes support.

Fixes 801771de0331 ("drm/amd/pm: do not expose power

implementation

Quoted 3 lines

details to
amdgpu_pm.c")

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Change-Id I95e7e0beebd678a446221a72234cd356e14f0fcd
---
    .../gpu/drm/amd/include/kgd_pp_interface.h    |   4 +-
    drivers/gpu/drm/amd/pm/amdgpu_dpm.c           |  31 ++++-
    drivers/gpu/drm/amd/pm/amdgpu_pm.c            |  21 ++--
    drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c    |  10 +-
    .../gpu/drm/amd/pm/powerplay/amd_powerplay.c  |  59 ++++-----
    drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c     | 115

+++++++++----

Quoted 45 lines
Quoted 45 lines

-----

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 25 lines
    6 files changed, 132 insertions(+), 108 deletions(-)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +2 -2
index a8eec91c0995..387120099493 100644
@@ -315,8 +315,8 @@ struct amd_pm_funcs {
    				void  *rps,
    				bool  *equal);
    /* export for sysfs */
-	void (*set_fan_control_mode)(void *handle, u32 mode);
-	u32 (*get_fan_control_mode)(void *handle);
+	int (*set_fan_control_mode)(void *handle, u32 mode);
+	int (*get_fan_control_mode)(void *handle, u32 *fan_mode);
    	int (*set_fan_speed_pwm)(void *handle, u32 speed);
    	int (*get_fan_speed_pwm)(void *handle, u32 *speed);
    	int (*force_clock_level)(void *handle, enum pp_clock_type

type, uint32_t mask); diff --git
a/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
b/drivers/gpu/drm/amd/pm/amdgpu_dpm.c
index 68d2e80a673b..fe69785df403 100644

drivers/gpu/drm/amd/pm/amdgpu_dpm.c +0 -0
@@ -1030,15 +1030,20 @@ int

amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_get_fan_control_mode(struct amdgpu_device *adev, · line 1040

Quoted 12 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -0
    				    uint32_t *fan_mode)
    {
    	const struct amd_pm_funcs *pp_funcs =
 adev->powerplay.pp_funcs;
+	int ret = 0;
 
    	if (!pp_funcs->get_fan_control_mode)
    		return -EOPNOTSUPP;
 
+	if (!fan_mode)
+		return -EINVAL;
+

pp_funcs most likely will be there for smu/powerplay subsystem. I think the checks should be at one layer down - smu_get_fan_control_mode() and pp_dpm_get_fan_control_mode()

Quoted 4 lines
Quoted 2 lines

First one will check if ppt func is implemented and second one will check if hwmgr func is implemented for the specific ASIC.

[Quan, Evan] Yes, I agree. And if you go through the changes below, you

will see the checks (for the layers down) there.

Quoted 2 lines

This patch checks not only those amdgpu_dpm_xxxx APIs, but also those

downstream interfaces(smu_xxxx and pp_dpm_xxxx).

Quoted 1 line

Say you call amdgpu_dpm_get_fan_control_mode(adev, NULL) from amdgpu_pm

pp_funcs->get_fan_control_mode => this will point to smu_get_fan_control_mode for all swsmu ASICs. So "if (!pp_funcs-

Quoted 1 line

get_fan_control_mode)" will be false.

The next statement is NULL check and it will return -EINVAL.

What we want to know is ppt_func is implemented or not for the particualr swsmu ASIC. Isn't that the case or am I reading it differently?

Quoted 6 lines
Quoted 2 lines

[Quan, Evan] OK, I get your point now. Hmm, that will be a little tricky. I suppose the EINVAL check needs to be dispatched in every

instance(pp_dpm_xxxxx, smu_xxxx, si_dpm_xxxx) then. Any better idea?

Quoted 1 line

Yeah, that is what I meant by "checks should be at one layer down".

[Quan, Evan] OK, please check the updated V2.

BR
Evan

Quoted 696 lines

Thanks,
Lijo

Quoted 19 lines

BR
Evan

Quoted 17 lines

Thanks,
Lijo

Quoted 14 lines

BR
Evan

Quoted 12 lines

Thanks,
Lijo

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +2 -1
    	mutex_lock(&adev->pm.mutex);
-	*fan_mode = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle);
+	ret = pp_funcs->get_fan_control_mode(adev-
 powerplay.pp_handle,
+					     fan_mode);
    	mutex_unlock(&adev->pm.mutex);
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -1
-	return 0;
+	return ret;

}

int amdgpu_dpm_set_fan_speed_pwm(struct amdgpu_device

*adev,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

@@

Quoted 1 line

-1048,6 +1053,9 @@ int amdgpu_dpm_set_fan_speed_pwm(struct

amdgpu_device *adev,

Quoted 2 lines
    	int ret = 0;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 8 lines
    	if (!pp_funcs->set_fan_speed_pwm)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1065,6 +1073,9 @@ int

amdgpu_dpm_get_fan_speed_pwm(struct

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1082,6 +1093,9 @@ int

amdgpu_dpm_get_fan_speed_rpm(struct

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (!speed)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1099,6 +1113,9 @@ int

amdgpu_dpm_set_fan_speed_rpm(struct

Quoted 59 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines

amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int

Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -0
    	int ret = 0;
 
    	if (!pp_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
+	if (speed == U32_MAX)
    		return -EINVAL;
 
    	mutex_lock(&adev->pm.mutex);
@@ -1113,16 +1130,20 @@ int

amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

Quoted 6 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +1 -0
    				    uint32_t mode)
    {
    	const struct amd_pm_funcs *pp_funcs =
 adev->powerplay.pp_funcs;
+	int ret = 0;
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/amdgpu_dpm.c int amdgpu_dpm_set_fan_control_mode(struct amdgpu_device *adev,

Quoted 8 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -1
    	if (!pp_funcs->set_fan_control_mode)
    		return -EOPNOTSUPP;
 
+	if (mode == U32_MAX)
+		return -EINVAL;
+
    	mutex_lock(&adev->pm.mutex);
-	pp_funcs->set_fan_control_mode(adev-

powerplay.pp_handle,

Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +3 -2
-				       mode);
+	ret = pp_funcs->set_fan_control_mode(adev-
 powerplay.pp_handle,
+					     mode);
    	mutex_unlock(&adev->pm.mutex);
 
-	return 0;
+	return ret;
    }
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 7 lines

int amdgpu_dpm_get_power_limit(struct amdgpu_device *adev,

drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
index d3eab245e0fe..940cbe751163 100644
@@ -3197,7 +3197,6 @@ static umode_t

hwmon_attributes_visible(struct

Quoted 14 lines
Quoted 14 lines

kobject *kobj,

Quoted 7 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
    	struct device *dev = kobj_to_dev(kobj);
    	struct amdgpu_device *adev = dev_get_drvdata(dev);
    	umode_t effective_mode = attr->mode;
-	uint32_t speed = 0;
 
    	/* under multi-vf mode, the hwmon attributes are all not

supported

*/

Quoted 2 lines
    	if (amdgpu_sriov_vf(adev) &&

!amdgpu_sriov_is_pp_one_vf(adev))

@@

Quoted 2 lines

-3263,15 +3262,15 @@ static umode_t
hwmon_attributes_visible(struct

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

kobject *kobj,

Quoted 4 lines
    		return 0;

    	/* mask fan attributes if we have no bindings for this asic

to expose

*/

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_get_fan_speed_pwm(adev, &speed) ==

-EINVAL)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 2 lines
    	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /*

can't query

fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	    ((amdgpu_dpm_get_fan_control_mode(adev, &speed) ==

-

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	    ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -

EOPNOTSUPP) &&

Quoted 1 line
    	     attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr))

/*

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

can't

query state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 3 lines
    		effective_mode &= ~S_IRUGO;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX)

== -

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

EOPNOTSUPP) &&

Quoted 2 lines
    	      attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /*

can't

manage fan */

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      ((amdgpu_dpm_set_fan_control_mode(adev, speed) ==

-

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX)

==

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+-EOPNOTSUPP) &&

    	      attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr))

/*

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

can't

manage state */

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t

Quoted 3 lines
    		effective_mode &= ~S_IWUSR;
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
@@ -3291,16 +3290,16 @@ static umode_t

hwmon_attributes_visible(struct kobject *kobj,

Quoted 3 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
    		return 0;
 
    	/* hide max/min values if we can't both query and manage

the fan */

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	if (((amdgpu_dpm_set_fan_speed_pwm(adev, speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_pwm(adev, &speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3297

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	      (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -

EINVAL))

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3293

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX)

== -

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3294

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3295

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) ==

-

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3296

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	      (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP)) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t hwmon_attributes_visible(struct kobject *kobj,

Quoted 5 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
    	    (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
    	     attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
    		return 0;
 
-	if ((amdgpu_dpm_set_fan_speed_rpm(adev, speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3303

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -1
-	     (amdgpu_dpm_get_fan_speed_rpm(adev, &speed) == -

EINVAL)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

&&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3301

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) ==

-

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/amdgpu_pm.c static umode_t · line 3302

Quoted 1 line
drivers/gpu/drm/amd/pm/amdgpu_pm.c +1 -0
+	     (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -

EOPNOTSUPP) &&

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void

Quoted 9 lines
drivers/gpu/drm/amd/pm/amdgpu_pm.c +0 -0
    	     (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
    	     attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
    		return 0;
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
index 92b987fb31d4..7677d3a21f8c 100644
@@ -6669,7 +6669,7 @@ static int si_dpm_set_fan_speed_pwm(void

*handle,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static int si_dpm_set_fan_speed_pwm(void *handle,

Quoted 7 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
    	return 0;
    }
 
-static void si_dpm_set_fan_control_mode(void *handle, u32 mode)
+static int si_dpm_set_fan_control_mode(void *handle, u32 mode)
    {
    	struct amdgpu_device *adev = (struct amdgpu_device

*)handle;

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
@@ -6685,9 +6685,11 @@ static void

si_dpm_set_fan_control_mode(void

Quoted 8 lines
Quoted 8 lines

*handle, u32 mode)

Quoted 7 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +2 -0
    		else
    			si_fan_ctrl_set_default_mode(adev);
    	}
+
+	return 0;
    }
 
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c static void · line 6692

Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +1 -1
-static u32 si_dpm_get_fan_control_mode(void *handle)
+static int si_dpm_get_fan_control_mode(void *handle, u32

*fan_mode)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +0 -0
    {
    	struct amdgpu_device *adev = (struct amdgpu_device

*)handle;

Quoted 36 lines
Quoted 36 lines
Quoted 19 lines
Quoted 19 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type

Quoted 18 lines
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c +4 -1
    	struct si_power_info *si_pi = si_get_pi(adev); @@ -6697,7
+6699,9 @@ static u32 si_dpm_get_fan_control_mode(void *handle)
    		return 0;
 
    	tmp = RREG32(CG_FDO_CTRL2) & FDO_PWM_MODE_MASK;
-	return (tmp >> FDO_PWM_MODE_SHIFT);
+	*fan_mode = (tmp >> FDO_PWM_MODE_SHIFT);
+
+	return 0;
    }
 
    #if 0
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -0
index 89341729744d..57bc9405d6a9 100644
@@ -488,38 +488,37 @@ static enum amd_pm_state_type

pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 6 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
    	return pm_type;
    }
 
-static void pp_dpm_set_fan_control_mode(void *handle, uint32_t
 mode)
+static int pp_dpm_set_fan_control_mode(void *handle, uint32_t

mode)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -1
    {
    	struct pp_hwmgr *hwmgr = handle;
 
    	if (!hwmgr || !hwmgr->pm_en)
-		return;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type · line 500

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-	if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	hwmgr->hwmgr_func->set_fan_control_mode(hwmgr,

mode);

Quoted 49 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +8 -3
    	mutex_unlock(&hwmgr->smu_lock);
+
+	return 0;
    }
 
-static uint32_t pp_dpm_get_fan_control_mode(void *handle)
+static int pp_dpm_get_fan_control_mode(void *handle, uint32_t
+*fan_mode)
    {
    	struct pp_hwmgr *hwmgr = handle;
-	uint32_t mode = 0;
 
    	if (!hwmgr || !hwmgr->pm_en)
-		return 0;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL)
+		return -EOPNOTSUPP;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type · line 517

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-	if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -3
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
-	mode = hwmgr->hwmgr_func-

get_fan_control_mode(hwmgr);

Quoted 22 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -1
+	*fan_mode = hwmgr->hwmgr_func-
 get_fan_control_mode(hwmgr);
    	mutex_unlock(&hwmgr->smu_lock);
-	return mode;
+	return 0;
    }
 
    static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t

speed)

@@

Quoted 1 line

-528,12 +527,11 @@ static int pp_dpm_set_fan_speed_pwm(void

*handle,

Quoted 10 lines
Quoted 10 lines

uint32_t speed)

Quoted 9 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -1
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-	if (hwmgr->hwmgr_func->set_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->set_fan_speed_pwm(hwmgr,

speed);

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
    	mutex_unlock(&hwmgr->smu_lock); @@ -546,12 +544,10

@@ static

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 1 line

int pp_dpm_get_fan_speed_pwm(void

*handle, uint32_t *speed)

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 8 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -3
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
-	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_get_fan_speed_pwm(void *handle, uint32_t *speed)

Quoted 7 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +2 -2
-		return 0;
-	}
+	if (hwmgr->hwmgr_func->get_fan_speed_pwm == NULL)
+		return -EOPNOTSUPP;
 
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->get_fan_speed_pwm(hwmgr,

speed);

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

@@

Quoted 1 line

-565,10 +561,10 @@ static int pp_dpm_get_fan_speed_rpm(void

*handle,

Quoted 7 lines
Quoted 7 lines

uint32_t *rpm)

Quoted 6 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
-		return -EINVAL;
+		return -EOPNOTSUPP;
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static int pp_dpm_set_fan_speed_pwm(void *handle, uint32_t speed)

Quoted 6 lines
    	if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +1 -1
-		return -EINVAL;
+		return -EOPNOTSUPP;
 
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr,

rpm);

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

@@ -582,12

Quoted 1 line

+578,11 @@ static int pp_dpm_set_fan_speed_rpm(void *handle,

uint32_t rpm)

Quoted 9 lines
    	int ret = 0;

    	if (!hwmgr || !hwmgr->pm_en)
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +4 -1
-		return -EINVAL;
+		return -EOPNOTSUPP;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL)
+		return -EOPNOTSUPP;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c

Quoted 2 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-	if (hwmgr->hwmgr_func->set_fan_speed_rpm == NULL) {
-		pr_info_ratelimited("%s was not implemented.\n",

__func__);

drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle)

Quoted 4 lines
drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +0 -2
-		return 0;
-	}
    	mutex_lock(&hwmgr->smu_lock);
    	ret = hwmgr->hwmgr_func->set_fan_speed_rpm(hwmgr,

rpm);

Quoted 20 lines
Quoted 20 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_handle_task(struct smu_context

Quoted 7 lines
    	mutex_unlock(&hwmgr->smu_lock); diff --git

a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
index c374c3067496..474f1f04cc96 100644

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -59,7 +59,7 @@ static int smu_handle_task(struct smu_context

*smu,

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
    			   bool lock_needed);
    static int smu_reset(struct smu_context *smu);
    static int smu_set_fan_speed_pwm(void *handle, u32 speed);
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value);
+static int smu_set_fan_control_mode(void *handle, u32 value);
    static int smu_set_power_limit(void *handle, uint32_t limit);
    static int smu_set_fan_speed_rpm(void *handle, uint32_t speed);

static int smu_set_gfx_cgpg(struct smu_context *smu, bool
enabled); @@ -407,7 +407,7 @@ static void smu_restore_dpm_user_profile(struct

smu_context *smu)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
    	if (smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_MANUAL ||

Quoted 1 line
    	    smu->user_dpm_profile.fan_mode ==

AMD_FAN_CTRL_NONE) {

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 5 lines

ret = smu_set_fan_control_mode(smu, smu-
user_dpm_profile.fan_mode);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-		if (ret) {
+		if (ret != -EOPNOTSUPP) {
    			smu->user_dpm_profile.fan_speed_pwm =

0;

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
    			smu->user_dpm_profile.fan_speed_rpm = 0;
    			smu->user_dpm_profile.fan_mode =

AMD_FAN_CTRL_AUTO; @@ -416,13

Quoted 1 line

+416,13 @@ static void smu_restore_dpm_user_profile(struct

smu_context

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines

*smu)

if (smu->user_dpm_profile.fan_speed_pwm) {
ret = smu_set_fan_speed_pwm(smu, smu-
user_dpm_profile.fan_speed_pwm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
    				dev_err(smu->adev->dev, "Failed to

set

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

manual fan speed in pwm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static void smu_restore_dpm_user_profile(struct smu_context *smu)

Quoted 8 lines
    		}

    		if (smu->user_dpm_profile.fan_speed_rpm) {
    			ret = smu_set_fan_speed_rpm(smu, smu-

user_dpm_profile.fan_speed_rpm);

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-			if (ret)
+			if (ret != -EOPNOTSUPP)
    				dev_err(smu->adev->dev, "Failed to

set

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

manual fan speed in rpm\n");

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void

Quoted 3 lines
    		}
    	}
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
@@ -2218,18 +2218,19 @@ static int smu_set_fan_speed_rpm(void

*handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -2
+	if (!smu->ppt_funcs->set_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_rpm) {
-		ret = smu->ppt_funcs->set_fan_speed_rpm(smu,

speed);

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2225

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2226

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2227

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.fan_speed_rpm =

speed;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2227

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+	ret = smu->ppt_funcs->set_fan_speed_rpm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2228

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void *handle, uint32_t speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_rpm = speed;
 
-			/* Override custom PWM setting as they

cannot co-

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2230

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2231

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.fan_speed_pwm =

0;

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2231

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
-		}
+		/* Override custom PWM setting as they cannot co-

exist */

Quoted 52 lines
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_rpm(void · line 2232

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_pwm = 0;
    	}
 
    	mutex_unlock(&smu->mutex);
@@ -2562,60 +2563,59 @@ static int

smu_set_power_profile_mode(void

Quoted 17 lines
Quoted 17 lines

*handle,

Quoted 16 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +5 -3
    }
 
 
-static u32 smu_get_fan_control_mode(void *handle)
+static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)
    {
    	struct smu_context *smu = handle;
-	u32 ret = 0;
 
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return AMD_FAN_CTRL_NONE;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->get_fan_control_mode)
+		return -EOPNOTSUPP;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -2
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_control_mode)
-		ret = smu->ppt_funcs->get_fan_control_mode(smu);
+	*fan_mode = smu->ppt_funcs-

get_fan_control_mode(smu);

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +7 -3
    	mutex_unlock(&smu->mutex);
 
-	return ret;
+	return 0;
    }
 
-static int smu_set_fan_control_mode(struct smu_context *smu, int
 value)
+static int smu_set_fan_control_mode(void *handle, u32 value)
    {
+	struct smu_context *smu = handle;
    	int ret = 0;
 
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
-		return  -EOPNOTSUPP;
+		return -EOPNOTSUPP;
+
+	if (!smu->ppt_funcs->set_fan_control_mode)
+		return -EOPNOTSUPP;
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -2
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_control_mode) {
-		ret = smu->ppt_funcs->set_fan_control_mode(smu,

value);

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int · line 2594

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE))

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +4 -3
-			smu->user_dpm_profile.fan_mode = value;
-	}
+	ret = smu->ppt_funcs->set_fan_control_mode(smu, value);
+	if (ret)
+		goto out;
 
-	mutex_unlock(&smu->mutex);
+	if (!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -3
+		smu->user_dpm_profile.fan_mode = value;
 
-	/* reset user dpm fan speed */
-	if (!ret && value != AMD_FAN_CTRL_MANUAL &&
-			!(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -3
-		smu->user_dpm_profile.fan_speed_pwm = 0;
-		smu->user_dpm_profile.fan_speed_rpm = 0;
-		smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -0
+		/* reset user dpm fan speed */
+		if (value != AMD_FAN_CTRL_MANUAL) {
+			smu->user_dpm_profile.fan_speed_pwm =

0;

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int · line 2609

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+			smu->user_dpm_profile.fan_speed_rpm = 0;
+			smu->user_dpm_profile.flags &=

~(SMU_CUSTOM_FAN_SPEED_RPM |

SMU_CUSTOM_FAN_SPEED_PWM);

Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle, · line 2611

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -4
+		}
    	}
 
-	return ret;
-}
-
-static void smu_pp_set_fan_control_mode(void *handle, u32 value)

-{

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
-	struct smu_context *smu = handle;
+out:
+	mutex_unlock(&smu->mutex);
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -2
-	smu_set_fan_control_mode(smu, value);
+	return ret;
    }
 
-
    static int smu_get_fan_speed_pwm(void *handle, u32 *speed)
    {
    	struct smu_context *smu = handle; @@ -2624,10 +2624,12

@@

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

static int smu_get_fan_speed_pwm(void

*handle, u32 *speed)

Quoted 3 lines
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_pwm(void *handle, u32 *speed)

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -2
+	if (!smu->ppt_funcs->get_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_pwm)
-		ret = smu->ppt_funcs->get_fan_speed_pwm(smu,

speed);

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+	ret = smu->ppt_funcs->get_fan_speed_pwm(smu, speed);
 
    	mutex_unlock(&smu->mutex);
@@ -2642,18 +2644,19 @@ static int smu_set_fan_speed_pwm(void

*handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -2
+	if (!smu->ppt_funcs->set_fan_speed_pwm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->set_fan_speed_pwm) {
-		ret = smu->ppt_funcs->set_fan_speed_pwm(smu,

speed);

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2649

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-		if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2650

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2651

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.fan_speed_pwm =

speed;

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2653

Quoted 2 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -0
+	ret = smu->ppt_funcs->set_fan_speed_pwm(smu, speed);
+	if (!ret && !(smu->user_dpm_profile.flags &

SMU_DPM_USER_PROFILE_RESTORE)) {

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags |=

SMU_CUSTOM_FAN_SPEED_PWM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void *handle, u32 speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -1
+		smu->user_dpm_profile.fan_speed_pwm = speed;
 
-			/* Override custom RPM setting as they

cannot co-

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

exist */

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2654

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -1
-			smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_power_profile_mode(void *handle,

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -2
-			smu->user_dpm_profile.fan_speed_rpm = 0;
-		}
+		/* Override custom RPM setting as they cannot co-

exist */

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_set_fan_speed_pwm(void · line 2658

Quoted 1 line
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.flags &=

~SMU_CUSTOM_FAN_SPEED_RPM;

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void

Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +1 -0
+		smu->user_dpm_profile.fan_speed_rpm = 0;
    	}
 
    	mutex_unlock(&smu->mutex);
@@ -2669,10 +2672,12 @@ static int smu_get_fan_speed_rpm(void

*handle, uint32_t *speed)

Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +0 -0
    	if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)
    		return -EOPNOTSUPP;
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c static int smu_get_fan_speed_rpm(void *handle, uint32_t *speed)

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +3 -2
+	if (!smu->ppt_funcs->get_fan_speed_rpm)
+		return -EOPNOTSUPP;
+
    	mutex_lock(&smu->mutex);
 
-	if (smu->ppt_funcs->get_fan_speed_rpm)
-		ret = smu->ppt_funcs->get_fan_speed_rpm(smu,

speed);

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +2 -1
+	ret = smu->ppt_funcs->get_fan_speed_rpm(smu, speed);
 
    	mutex_unlock(&smu->mutex);
 
@@ -3101,7 +3106,7 @@ static int smu_get_prv_buffer_details(void
 *handle, void **addr, size_t *size)
 
    static const struct amd_pm_funcs swsmu_pm_funcs = {
    	/* export for sysfs */
-	.set_fan_control_mode    = smu_pp_set_fan_control_mode,
+	.set_fan_control_mode    = smu_set_fan_control_mode,
    	.get_fan_control_mode    = smu_get_fan_control_mode,
    	.set_fan_speed_pwm   = smu_set_fan_speed_pwm,

.get_fan_speed_pwm = smu_get_fan_speed_pwm,