drm/amd/pm: add fan temperature/pwm curve OD setting support for SMU13
authorEvan Quan <evan.quan@amd.com>
Fri, 11 Aug 2023 08:13:59 +0000 (16:13 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 31 Aug 2023 20:40:14 +0000 (16:40 -0400)
Add SMU13 fan temperature/pwm curve OD setting support.

Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Documentation/gpu/amdgpu/thermal.rst
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

index 5e27e4eb395967f6625b9d82f743a33e7727a9d1..08ee33b2acb66a385d12675cb5fdb8f6f59e6d73 100644 (file)
@@ -64,6 +64,12 @@ gpu_metrics
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
    :doc: gpu_metrics
 
+fan_curve
+---------
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_curve
+
 GFXOFF
 ======
 
index 84c5224d994c434a90c02eaa43ed27c526ebe59f..7bdd2bdab970f1c38048a7466f683af18d5d835c 100644 (file)
@@ -113,6 +113,7 @@ enum pp_clock_type {
        OD_RANGE,
        OD_VDDGFX_OFFSET,
        OD_CCLK,
+       OD_FAN_CURVE,
 };
 
 enum amd_pp_sensors {
@@ -186,7 +187,8 @@ enum PP_OD_DPM_TABLE_COMMAND {
        PP_OD_EDIT_VDDC_CURVE,
        PP_OD_RESTORE_DEFAULT_TABLE,
        PP_OD_COMMIT_DPM_TABLE,
-       PP_OD_EDIT_VDDGFX_OFFSET
+       PP_OD_EDIT_VDDGFX_OFFSET,
+       PP_OD_EDIT_FAN_CURVE,
 };
 
 struct pp_states_info {
index edb52697c4898f780bd2183ee86b890e5683903f..1008d43e9c3fb4d39d6b496cf29a1344ae7fe0d5 100644 (file)
@@ -3383,7 +3383,215 @@ static const struct attribute_group *hwmon_groups[] = {
        NULL
 };
 
-static struct od_feature_set amdgpu_od_set;
+static int amdgpu_retrieve_od_settings(struct amdgpu_device *adev,
+                                      enum pp_clock_type od_type,
+                                      char *buf)
+{
+       int size = 0;
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0) {
+               pm_runtime_put_autosuspend(adev->dev);
+               return ret;
+       }
+
+       size = amdgpu_dpm_print_clock_levels(adev, od_type, buf);
+       if (size == 0)
+               size = sysfs_emit(buf, "\n");
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return size;
+}
+
+static int parse_input_od_command_lines(const char *buf,
+                                       size_t count,
+                                       u32 *type,
+                                       long *params,
+                                       uint32_t *num_of_params)
+{
+       const char delimiter[3] = {' ', '\n', '\0'};
+       uint32_t parameter_size = 0;
+       char buf_cpy[128] = {0};
+       char *tmp_str, *sub_str;
+       int ret;
+
+       if (count > sizeof(buf_cpy) - 1)
+               return -EINVAL;
+
+       memcpy(buf_cpy, buf, count);
+       tmp_str = buf_cpy;
+
+       /* skip heading spaces */
+       while (isspace(*tmp_str))
+               tmp_str++;
+
+       switch (*tmp_str) {
+       case 'c':
+               *type = PP_OD_COMMIT_DPM_TABLE;
+               return 0;
+       default:
+               break;
+       }
+
+       while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
+               if (strlen(sub_str) == 0)
+                       continue;
+
+               ret = kstrtol(sub_str, 0, &params[parameter_size]);
+               if (ret)
+                       return -EINVAL;
+               parameter_size++;
+
+               while (isspace(*tmp_str))
+                       tmp_str++;
+       }
+
+       *num_of_params = parameter_size;
+
+       return 0;
+}
+
+static int
+amdgpu_distribute_custom_od_settings(struct amdgpu_device *adev,
+                                    enum PP_OD_DPM_TABLE_COMMAND cmd_type,
+                                    const char *in_buf,
+                                    size_t count)
+{
+       uint32_t parameter_size = 0;
+       long parameter[64];
+       int ret;
+
+       if (amdgpu_in_reset(adev))
+               return -EPERM;
+       if (adev->in_suspend && !adev->in_runpm)
+               return -EPERM;
+
+       ret = parse_input_od_command_lines(in_buf,
+                                          count,
+                                          &cmd_type,
+                                          parameter,
+                                          &parameter_size);
+       if (ret)
+               return ret;
+
+       ret = pm_runtime_get_sync(adev->dev);
+       if (ret < 0)
+               goto err_out0;
+
+       ret = amdgpu_dpm_odn_edit_dpm_table(adev,
+                                           cmd_type,
+                                           parameter,
+                                           parameter_size);
+       if (ret)
+               goto err_out1;
+
+       if (cmd_type == PP_OD_COMMIT_DPM_TABLE) {
+               ret = amdgpu_dpm_dispatch_task(adev,
+                                              AMD_PP_TASK_READJUST_POWER_STATE,
+                                              NULL);
+               if (ret)
+                       goto err_out1;
+       }
+
+       pm_runtime_mark_last_busy(adev->dev);
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return count;
+
+err_out1:
+       pm_runtime_mark_last_busy(adev->dev);
+err_out0:
+       pm_runtime_put_autosuspend(adev->dev);
+
+       return ret;
+}
+
+/**
+ * DOC: fan_curve
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting the fan
+ * control curve line.
+ *
+ * Reading back the file shows you the current settings(temperature in Celsius
+ * degree and fan speed in pwm) applied to every anchor point of the curve line
+ * and their permitted ranges if changable.
+ *
+ * Writing a desired string(with the format like "anchor_point_index temperature
+ * fan_speed_in_pwm") to the file, change the settings for the specific anchor
+ * point accordingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file to commit
+ * your changes.
+ *
+ * There are two fan control modes supported: auto and manual. With auto mode,
+ * PMFW handles the fan speed control(how fan speed reacts to ASIC temperature).
+ * While with manual mode, users can set their own fan curve line as what
+ * described here. Normally the ASIC is booted up with auto mode. Any
+ * settings via this interface will switch the fan control to manual mode
+ * implicitly.
+ */
+static ssize_t fan_curve_show(struct kobject *kobj,
+                             struct kobj_attribute *attr,
+                             char *buf)
+{
+       struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+       struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+       return (ssize_t)amdgpu_retrieve_od_settings(adev, OD_FAN_CURVE, buf);
+}
+
+static ssize_t fan_curve_store(struct kobject *kobj,
+                              struct kobj_attribute *attr,
+                              const char *buf,
+                              size_t count)
+{
+       struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+       struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+       return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+                                                            PP_OD_EDIT_FAN_CURVE,
+                                                            buf,
+                                                            count);
+}
+
+static umode_t fan_curve_visible(struct amdgpu_device *adev)
+{
+       umode_t umode = 0000;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE)
+               umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+       if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_CURVE_SET)
+               umode |= S_IWUSR;
+
+       return umode;
+}
+
+static struct od_feature_set amdgpu_od_set = {
+       .containers = {
+               [0] = {
+                       .name = "fan_ctrl",
+                       .sub_feature = {
+                               [0] = {
+                                       .name = "fan_curve",
+                                       .ops = {
+                                               .is_visible = fan_curve_visible,
+                                               .show = fan_curve_show,
+                                               .store = fan_curve_store,
+                                       },
+                               },
+                       },
+               },
+       },
+};
 
 static void od_kobj_release(struct kobject *kobj)
 {
index 4cab6a2efb634249aeb6679782a4c0107de607b6..90544a8f450c35c59aaec7f11860a0717e934301 100644 (file)
@@ -314,6 +314,9 @@ struct config_table_setting
        uint16_t fclk_average_tau;
 };
 
+#define OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE              BIT(0)
+#define OD_OPS_SUPPORT_FAN_CURVE_SET                   BIT(1)
+
 struct amdgpu_pm {
        struct mutex            mutex;
        u32                     current_sclk;
@@ -368,6 +371,7 @@ struct amdgpu_pm {
        enum amdgpu_runpm_mode rpm_mode;
 
        struct list_head        od_kobj_list;
+       uint32_t                od_feature_mask;
 };
 
 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
index f005a90c35af43f195c66b73fccf9e3750b93e18..2d73a63813de88226a7afc5e4cc038248885843f 100644 (file)
@@ -2481,6 +2481,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
                clk_type = SMU_OD_VDDGFX_OFFSET; break;
        case OD_CCLK:
                clk_type = SMU_OD_CCLK; break;
+       case OD_FAN_CURVE:
+               clk_type = SMU_OD_FAN_CURVE; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
index e57265cf637c990692b64c96274447d0f87179c9..83e1d43efd2b626192c781dfdb6243909a5cbe05 100644 (file)
@@ -280,6 +280,7 @@ enum smu_clk_type {
        SMU_OD_VDDC_CURVE,
        SMU_OD_RANGE,
        SMU_OD_VDDGFX_OFFSET,
+       SMU_OD_FAN_CURVE,
        SMU_CLK_COUNT,
 };
 
index 5fdb2b3c042ab178a4065dca03191338bd253b7c..09297dbcbdf19c2e0e79fa88093e5fdaa07b487d 100644 (file)
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_CURVE_TEMP                   5
+#define PP_OD_FEATURE_FAN_CURVE_PWM                    6
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1122,6 +1124,14 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_CURVE_TEMP:
+               od_min_setting = overdrive_lowerlimits->FanLinearTempPoints;
+               od_max_setting = overdrive_upperlimits->FanLinearTempPoints;
+               break;
+       case PP_OD_FEATURE_FAN_CURVE_PWM:
+               od_min_setting = overdrive_lowerlimits->FanLinearPwmPoints;
+               od_max_setting = overdrive_upperlimits->FanLinearPwmPoints;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1341,6 +1351,35 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
                                      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_CURVE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n");
+               for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++)
+                       size += sysfs_emit_at(buf, size, "%d: %dC %d%%\n",
+                                               i,
+                                               (int)od_table->OverDriveTable.FanLinearTempPoints[i],
+                                               (int)od_table->OverDriveTable.FanLinearPwmPoints[i]);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_TEMP,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n",
+                                     min_value, max_value);
+
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n",
+                                     min_value, max_value);
+
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1551,6 +1590,44 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_FAN_CURVE:
+               if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               if (input[0] >= NUM_OD_FAN_MAX_POINTS - 1 ||
+                   input[0] < 0)
+                       return -EINVAL;
+
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_TEMP,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[1] < minimum ||
+                   input[1] > maximum) {
+                       dev_info(adev->dev, "Fan curve temp setting(%ld) must be within [%d, %d]!\n",
+                                input[1], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[2] < minimum ||
+                   input[2] > maximum) {
+                       dev_info(adev->dev, "Fan curve pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[2], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanLinearTempPoints[input[0]] = input[1];
+               od_table->OverDriveTable.FanLinearPwmPoints[input[0]] = input[2];
+               od_table->OverDriveTable.FanMode = FAN_MODE_MANUAL_LINEAR;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -1801,6 +1878,16 @@ static ssize_t smu_v13_0_0_get_gpu_metrics(struct smu_context *smu,
        return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
+{
+       struct amdgpu_device *adev = smu->adev;
+
+       if (smu_v13_0_0_is_od_feature_supported(smu,
+                                               PP_OD_FEATURE_FAN_CURVE_BIT))
+               adev->pm.od_feature_mask |= OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_CURVE_SET;
+}
+
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
 {
        OverDriveTableExternal_t *od_table =
@@ -1850,8 +1937,16 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
                                user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+               for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) {
+                       user_od_table->OverDriveTable.FanLinearTempPoints[i] =
+                               user_od_table_bak.OverDriveTable.FanLinearTempPoints[i];
+                       user_od_table->OverDriveTable.FanLinearPwmPoints[i] =
+                               user_od_table_bak.OverDriveTable.FanLinearPwmPoints[i];
+               }
        }
 
+       smu_v13_0_0_set_supported_od_feature_mask(smu);
+
        return 0;
 }
 
@@ -1862,9 +1957,10 @@ static int smu_v13_0_0_restore_user_od_settings(struct smu_context *smu)
        OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+                                                       BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_0_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)
index 12949928e2850a0e98e53f5e2644ea5270214776..3e852bf6177e87d469d569660b22b35996154ae0 100644 (file)
@@ -77,6 +77,8 @@
 #define PP_OD_FEATURE_UCLK_FMIN                                2
 #define PP_OD_FEATURE_UCLK_FMAX                                3
 #define PP_OD_FEATURE_GFX_VF_CURVE                     4
+#define PP_OD_FEATURE_FAN_CURVE_TEMP                   5
+#define PP_OD_FEATURE_FAN_CURVE_PWM                    6
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1102,6 +1104,14 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->VoltageOffsetPerZoneBoundary;
                od_max_setting = overdrive_upperlimits->VoltageOffsetPerZoneBoundary;
                break;
+       case PP_OD_FEATURE_FAN_CURVE_TEMP:
+               od_min_setting = overdrive_lowerlimits->FanLinearTempPoints;
+               od_max_setting = overdrive_upperlimits->FanLinearTempPoints;
+               break;
+       case PP_OD_FEATURE_FAN_CURVE_PWM:
+               od_min_setting = overdrive_lowerlimits->FanLinearPwmPoints;
+               od_max_setting = overdrive_upperlimits->FanLinearPwmPoints;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1321,6 +1331,35 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
                                      od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[0]);
                break;
 
+       case SMU_OD_FAN_CURVE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "OD_FAN_CURVE:\n");
+               for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++)
+                       size += sysfs_emit_at(buf, size, "%d: %dC %d%%\n",
+                                               i,
+                                               (int)od_table->OverDriveTable.FanLinearTempPoints[i],
+                                               (int)od_table->OverDriveTable.FanLinearPwmPoints[i]);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_TEMP,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "FAN_CURVE(hotspot temp): %uC %uC\n",
+                                     min_value, max_value);
+
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "FAN_CURVE(fan speed): %u%% %u%%\n",
+                                     min_value, max_value);
+
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1531,6 +1570,44 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_FAN_CURVE:
+               if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               if (input[0] >= NUM_OD_FAN_MAX_POINTS - 1 ||
+                   input[0] < 0)
+                       return -EINVAL;
+
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_TEMP,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[1] < minimum ||
+                   input[1] > maximum) {
+                       dev_info(adev->dev, "Fan curve temp setting(%ld) must be within [%d, %d]!\n",
+                                input[1], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_CURVE_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[2] < minimum ||
+                   input[2] > maximum) {
+                       dev_info(adev->dev, "Fan curve pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[2], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanLinearTempPoints[input[0]] = input[1];
+               od_table->OverDriveTable.FanLinearPwmPoints[input[0]] = input[2];
+               od_table->OverDriveTable.FanMode = FAN_MODE_MANUAL_LINEAR;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -1776,6 +1853,16 @@ static ssize_t smu_v13_0_7_get_gpu_metrics(struct smu_context *smu,
        return sizeof(struct gpu_metrics_v1_3);
 }
 
+static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
+{
+       struct amdgpu_device *adev = smu->adev;
+
+       if (smu_v13_0_7_is_od_feature_supported(smu,
+                                               PP_OD_FEATURE_FAN_CURVE_BIT))
+               adev->pm.od_feature_mask |= OD_OPS_SUPPORT_FAN_CURVE_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_CURVE_SET;
+}
+
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
 {
        OverDriveTableExternal_t *od_table =
@@ -1825,8 +1912,16 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                for (i = 0; i < PP_NUM_OD_VF_CURVE_POINTS; i++)
                        user_od_table->OverDriveTable.VoltageOffsetPerZoneBoundary[i] =
                                user_od_table_bak.OverDriveTable.VoltageOffsetPerZoneBoundary[i];
+               for (i = 0; i < NUM_OD_FAN_MAX_POINTS - 1; i++) {
+                       user_od_table->OverDriveTable.FanLinearTempPoints[i] =
+                               user_od_table_bak.OverDriveTable.FanLinearTempPoints[i];
+                       user_od_table->OverDriveTable.FanLinearPwmPoints[i] =
+                               user_od_table_bak.OverDriveTable.FanLinearPwmPoints[i];
+               }
        }
 
+       smu_v13_0_7_set_supported_od_feature_mask(smu);
+
        return 0;
 }
 
@@ -1837,9 +1932,10 @@ static int smu_v13_0_7_restore_user_od_settings(struct smu_context *smu)
        OverDriveTableExternal_t *user_od_table = table_context->user_overdrive_table;
        int res;
 
-       user_od_table->OverDriveTable.FeatureCtrlMask = 1U << PP_OD_FEATURE_GFXCLK_BIT |
-                                                       1U << PP_OD_FEATURE_UCLK_BIT |
-                                                       1U << PP_OD_FEATURE_GFX_VF_CURVE_BIT;
+       user_od_table->OverDriveTable.FeatureCtrlMask = BIT(PP_OD_FEATURE_GFXCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_UCLK_BIT) |
+                                                       BIT(PP_OD_FEATURE_GFX_VF_CURVE_BIT) |
+                                                       BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
        res = smu_v13_0_7_upload_overdrive_table(smu, user_od_table);
        user_od_table->OverDriveTable.FeatureCtrlMask = 0;
        if (res == 0)