habanalabs: power management through sysfs is only for GOYA
authorOded Gabbay <oded.gabbay@gmail.com>
Thu, 4 Jul 2019 08:57:12 +0000 (11:57 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Thu, 5 Sep 2019 11:55:26 +0000 (14:55 +0300)
The ability of setting power management properties by the system
administrator (through sysfs properties) is only relevant for the GOYA
ASIC. Therefore, move the relevant sysfs properties to the GOYA sysfs
specific file, to make the properties appear in sysfs only for GOYA cards.

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Omer Shpigelman <oshpigelman@habana.ai>
Documentation/ABI/testing/sysfs-driver-habanalabs
drivers/misc/habanalabs/goya/goya_hwmgr.c
drivers/misc/habanalabs/sysfs.c

index 8d1c81cc9167694f26a39edc4af83df305c22e16..782df74042ed21f908ef84d8010f33c3367658ed 100644 (file)
@@ -57,6 +57,7 @@ KernelVersion:  5.1
 Contact:        oded.gabbay@gmail.com
 Description:    Allows the user to set the maximum clock frequency for MME, TPC
                 and IC when the power management profile is set to "automatic".
+                This property is valid only for the Goya ASIC family
 
 What:           /sys/class/habanalabs/hl<n>/ic_clk
 Date:           Jan 2019
@@ -127,8 +128,8 @@ Description:    Power management profile. Values are "auto", "manual". In "auto"
                 the max clock frequency to a low value when there are no user
                 processes that are opened on the device's file. In "manual"
                 mode, the user sets the maximum clock frequency by writing to
-                ic_clk, mme_clk and tpc_clk
-
+                ic_clk, mme_clk and tpc_clk. This property is valid only for
+                the Goya ASIC family
 
 What:           /sys/class/habanalabs/hl<n>/preboot_btl_ver
 Date:           Jan 2019
index 088692c852b6a3a0f33ed3756cad815f8fed3f10..a51d836542a1a819bf5ec0f6f27ab9bd8a7d3f5e 100644 (file)
@@ -230,18 +230,116 @@ static ssize_t ic_clk_curr_show(struct device *dev,
        return sprintf(buf, "%lu\n", value);
 }
 
+static ssize_t pm_mng_profile_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+
+       if (hl_device_disabled_or_in_reset(hdev))
+               return -ENODEV;
+
+       return sprintf(buf, "%s\n",
+                       (hdev->pm_mng_profile == PM_AUTO) ? "auto" :
+                       (hdev->pm_mng_profile == PM_MANUAL) ? "manual" :
+                       "unknown");
+}
+
+static ssize_t pm_mng_profile_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+
+       if (hl_device_disabled_or_in_reset(hdev)) {
+               count = -ENODEV;
+               goto out;
+       }
+
+       mutex_lock(&hdev->fd_open_cnt_lock);
+
+       if (atomic_read(&hdev->fd_open_cnt) > 0) {
+               dev_err(hdev->dev,
+                       "Can't change PM profile while user process is opened on the device\n");
+               count = -EPERM;
+               goto unlock_mutex;
+       }
+
+       if (strncmp("auto", buf, strlen("auto")) == 0) {
+               /* Make sure we are in LOW PLL when changing modes */
+               if (hdev->pm_mng_profile == PM_MANUAL) {
+                       atomic_set(&hdev->curr_pll_profile, PLL_HIGH);
+                       hl_device_set_frequency(hdev, PLL_LOW);
+                       hdev->pm_mng_profile = PM_AUTO;
+               }
+       } else if (strncmp("manual", buf, strlen("manual")) == 0) {
+               /* Make sure we are in LOW PLL when changing modes */
+               if (hdev->pm_mng_profile == PM_AUTO) {
+                       flush_delayed_work(&hdev->work_freq);
+                       hdev->pm_mng_profile = PM_MANUAL;
+               }
+       } else {
+               dev_err(hdev->dev, "value should be auto or manual\n");
+               count = -EINVAL;
+               goto unlock_mutex;
+       }
+
+unlock_mutex:
+       mutex_unlock(&hdev->fd_open_cnt_lock);
+out:
+       return count;
+}
+
+static ssize_t high_pll_show(struct device *dev, struct device_attribute *attr,
+                               char *buf)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+
+       if (hl_device_disabled_or_in_reset(hdev))
+               return -ENODEV;
+
+       return sprintf(buf, "%u\n", hdev->high_pll);
+}
+
+static ssize_t high_pll_store(struct device *dev, struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+       long value;
+       int rc;
+
+       if (hl_device_disabled_or_in_reset(hdev)) {
+               count = -ENODEV;
+               goto out;
+       }
+
+       rc = kstrtoul(buf, 0, &value);
+
+       if (rc) {
+               count = -EINVAL;
+               goto out;
+       }
+
+       hdev->high_pll = value;
+
+out:
+       return count;
+}
+
+static DEVICE_ATTR_RW(high_pll);
 static DEVICE_ATTR_RW(ic_clk);
 static DEVICE_ATTR_RO(ic_clk_curr);
 static DEVICE_ATTR_RW(mme_clk);
 static DEVICE_ATTR_RO(mme_clk_curr);
+static DEVICE_ATTR_RW(pm_mng_profile);
 static DEVICE_ATTR_RW(tpc_clk);
 static DEVICE_ATTR_RO(tpc_clk_curr);
 
 static struct attribute *goya_dev_attrs[] = {
+       &dev_attr_high_pll.attr,
        &dev_attr_ic_clk.attr,
        &dev_attr_ic_clk_curr.attr,
        &dev_attr_mme_clk.attr,
        &dev_attr_mme_clk_curr.attr,
+       &dev_attr_pm_mng_profile.attr,
        &dev_attr_tpc_clk.attr,
        &dev_attr_tpc_clk_curr.attr,
        NULL,
index 67e3424d4e656202243ac9b5469f076719a8e805..080da09cc3b039489f04fb7ab852444432b6bbe6 100644 (file)
@@ -102,100 +102,6 @@ void hl_set_max_power(struct hl_device *hdev, u64 value)
                dev_err(hdev->dev, "Failed to set max power, error %d\n", rc);
 }
 
-static ssize_t pm_mng_profile_show(struct device *dev,
-                               struct device_attribute *attr, char *buf)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-
-       if (hl_device_disabled_or_in_reset(hdev))
-               return -ENODEV;
-
-       return sprintf(buf, "%s\n",
-                       (hdev->pm_mng_profile == PM_AUTO) ? "auto" :
-                       (hdev->pm_mng_profile == PM_MANUAL) ? "manual" :
-                       "unknown");
-}
-
-static ssize_t pm_mng_profile_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-
-       if (hl_device_disabled_or_in_reset(hdev)) {
-               count = -ENODEV;
-               goto out;
-       }
-
-       mutex_lock(&hdev->fd_open_cnt_lock);
-
-       if (atomic_read(&hdev->fd_open_cnt) > 0) {
-               dev_err(hdev->dev,
-                       "Can't change PM profile while user process is opened on the device\n");
-               count = -EPERM;
-               goto unlock_mutex;
-       }
-
-       if (strncmp("auto", buf, strlen("auto")) == 0) {
-               /* Make sure we are in LOW PLL when changing modes */
-               if (hdev->pm_mng_profile == PM_MANUAL) {
-                       atomic_set(&hdev->curr_pll_profile, PLL_HIGH);
-                       hl_device_set_frequency(hdev, PLL_LOW);
-                       hdev->pm_mng_profile = PM_AUTO;
-               }
-       } else if (strncmp("manual", buf, strlen("manual")) == 0) {
-               /* Make sure we are in LOW PLL when changing modes */
-               if (hdev->pm_mng_profile == PM_AUTO) {
-                       flush_delayed_work(&hdev->work_freq);
-                       hdev->pm_mng_profile = PM_MANUAL;
-               }
-       } else {
-               dev_err(hdev->dev, "value should be auto or manual\n");
-               count = -EINVAL;
-               goto unlock_mutex;
-       }
-
-unlock_mutex:
-       mutex_unlock(&hdev->fd_open_cnt_lock);
-out:
-       return count;
-}
-
-static ssize_t high_pll_show(struct device *dev, struct device_attribute *attr,
-                               char *buf)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-
-       if (hl_device_disabled_or_in_reset(hdev))
-               return -ENODEV;
-
-       return sprintf(buf, "%u\n", hdev->high_pll);
-}
-
-static ssize_t high_pll_store(struct device *dev, struct device_attribute *attr,
-                               const char *buf, size_t count)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-       long value;
-       int rc;
-
-       if (hl_device_disabled_or_in_reset(hdev)) {
-               count = -ENODEV;
-               goto out;
-       }
-
-       rc = kstrtoul(buf, 0, &value);
-
-       if (rc) {
-               count = -EINVAL;
-               goto out;
-       }
-
-       hdev->high_pll = value;
-
-out:
-       return count;
-}
-
 static ssize_t uboot_ver_show(struct device *dev, struct device_attribute *attr,
                                char *buf)
 {
@@ -442,11 +348,9 @@ static DEVICE_ATTR_RO(device_type);
 static DEVICE_ATTR_RO(fuse_ver);
 static DEVICE_ATTR_WO(hard_reset);
 static DEVICE_ATTR_RO(hard_reset_cnt);
-static DEVICE_ATTR_RW(high_pll);
 static DEVICE_ATTR_RO(infineon_ver);
 static DEVICE_ATTR_RW(max_power);
 static DEVICE_ATTR_RO(pci_addr);
-static DEVICE_ATTR_RW(pm_mng_profile);
 static DEVICE_ATTR_RO(preboot_btl_ver);
 static DEVICE_ATTR_WO(soft_reset);
 static DEVICE_ATTR_RO(soft_reset_cnt);
@@ -468,11 +372,9 @@ static struct attribute *hl_dev_attrs[] = {
        &dev_attr_fuse_ver.attr,
        &dev_attr_hard_reset.attr,
        &dev_attr_hard_reset_cnt.attr,
-       &dev_attr_high_pll.attr,
        &dev_attr_infineon_ver.attr,
        &dev_attr_max_power.attr,
        &dev_attr_pci_addr.attr,
-       &dev_attr_pm_mng_profile.attr,
        &dev_attr_preboot_btl_ver.attr,
        &dev_attr_soft_reset.attr,
        &dev_attr_soft_reset_cnt.attr,