habanalabs: sysfs functions should be in sysfs.c
authorOded Gabbay <ogabbay@kernel.org>
Sat, 8 Jan 2022 11:23:54 +0000 (13:23 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Mon, 28 Feb 2022 12:22:01 +0000 (14:22 +0200)
Move common sysfs store/show functions to sysfs.c file for
consistency.

This is part of a patch-set to remove hwmgr.c

Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/common/hwmgr.c
drivers/misc/habanalabs/common/sysfs.c
drivers/misc/habanalabs/gaudi/gaudi.c

index e96f26e7e8044b0f1ebaebb2a87f3884c715c671..571998899253e02270e8fea4c9feeb93108a9094 100644 (file)
@@ -3125,8 +3125,7 @@ int hl_get_power(struct hl_device *hdev,
 int hl_get_clk_rate(struct hl_device *hdev,
                        u32 *cur_clk, u32 *max_clk);
 void hl_set_pll_profile(struct hl_device *hdev, enum hl_pll_frequency freq);
-void hl_add_device_attr(struct hl_device *hdev,
-                       struct attribute_group *dev_attr_grp);
+void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_attr_grp);
 void hw_sob_get(struct hl_hw_sob *hw_sob);
 void hw_sob_put(struct hl_hw_sob *hw_sob);
 void hl_encaps_handle_do_release(struct kref *ref);
index 5451019f143fac59213cedc9dba2b453ba20eadb..f0e5417560c34b1b4b53c5df7bca4160c3819793 100644 (file)
@@ -43,75 +43,3 @@ int hl_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk)
 
        return 0;
 }
-
-static ssize_t clk_max_freq_mhz_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-       long value;
-
-       if (!hl_device_operational(hdev, NULL))
-               return -ENODEV;
-
-       value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false);
-
-       hdev->asic_prop.max_freq_value = value;
-
-       return sprintf(buf, "%lu\n", (value / 1000 / 1000));
-}
-
-static ssize_t clk_max_freq_mhz_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-       int rc;
-       u64 value;
-
-       if (!hl_device_operational(hdev, NULL)) {
-               count = -ENODEV;
-               goto fail;
-       }
-
-       rc = kstrtoull(buf, 0, &value);
-       if (rc) {
-               count = -EINVAL;
-               goto fail;
-       }
-
-       hdev->asic_prop.max_freq_value = value * 1000 * 1000;
-
-       hl_set_frequency(hdev, hdev->asic_prop.clk_pll_index,
-                       hdev->asic_prop.max_freq_value);
-
-fail:
-       return count;
-}
-
-static ssize_t clk_cur_freq_mhz_show(struct device *dev,
-               struct device_attribute *attr, char *buf)
-{
-       struct hl_device *hdev = dev_get_drvdata(dev);
-       long value;
-
-       if (!hl_device_operational(hdev, NULL))
-               return -ENODEV;
-
-       value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true);
-
-       return sprintf(buf, "%lu\n", (value / 1000 / 1000));
-}
-
-static DEVICE_ATTR_RW(clk_max_freq_mhz);
-static DEVICE_ATTR_RO(clk_cur_freq_mhz);
-
-static struct attribute *hl_dev_attrs[] = {
-       &dev_attr_clk_max_freq_mhz.attr,
-       &dev_attr_clk_cur_freq_mhz.attr,
-       NULL,
-};
-
-void hl_add_device_attr(struct hl_device *hdev,
-                       struct attribute_group *dev_attr_grp)
-{
-       dev_attr_grp->attrs = hl_dev_attrs;
-}
index 45c715325e2a7fcf4b046dedd3c97ddfeb2a3ce8..d66cf43788d8a420e0790a84ed9bdcdb46a1bddc 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 /*
- * Copyright 2016-2019 HabanaLabs, Ltd.
+ * Copyright 2016-2022 HabanaLabs, Ltd.
  * All Rights Reserved.
  */
 
@@ -109,6 +109,69 @@ void hl_set_max_power(struct hl_device *hdev)
                dev_err(hdev->dev, "Failed to set max power, error %d\n", rc);
 }
 
+static ssize_t clk_max_freq_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+       long value;
+
+       if (!hl_device_operational(hdev, NULL))
+               return -ENODEV;
+
+       value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false);
+
+       hdev->asic_prop.max_freq_value = value;
+
+       return sprintf(buf, "%lu\n", (value / 1000 / 1000));
+}
+
+static ssize_t clk_max_freq_mhz_store(struct device *dev, struct device_attribute *attr,
+                                       const char *buf, size_t count)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+       int rc;
+       u64 value;
+
+       if (!hl_device_operational(hdev, NULL)) {
+               count = -ENODEV;
+               goto fail;
+       }
+
+       rc = kstrtoull(buf, 0, &value);
+       if (rc) {
+               count = -EINVAL;
+               goto fail;
+       }
+
+       hdev->asic_prop.max_freq_value = value * 1000 * 1000;
+
+       hl_set_frequency(hdev, hdev->asic_prop.clk_pll_index, hdev->asic_prop.max_freq_value);
+
+fail:
+       return count;
+}
+
+static ssize_t clk_cur_freq_mhz_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+       long value;
+
+       if (!hl_device_operational(hdev, NULL))
+               return -ENODEV;
+
+       value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true);
+
+       return sprintf(buf, "%lu\n", (value / 1000 / 1000));
+}
+
+static DEVICE_ATTR_RW(clk_max_freq_mhz);
+static DEVICE_ATTR_RO(clk_cur_freq_mhz);
+
+static struct attribute *hl_dev_clk_attrs[] = {
+       &dev_attr_clk_max_freq_mhz.attr,
+       &dev_attr_clk_cur_freq_mhz.attr,
+       NULL,
+};
+
 static ssize_t uboot_ver_show(struct device *dev, struct device_attribute *attr,
                                char *buf)
 {
@@ -463,6 +526,11 @@ static const struct attribute_group *hl_dev_inference_attr_groups[] = {
        NULL,
 };
 
+void hl_sysfs_add_dev_clk_attr(struct hl_device *hdev, struct attribute_group *dev_attr_grp)
+{
+       dev_attr_grp->attrs = hl_dev_clk_attrs;
+}
+
 int hl_sysfs_init(struct hl_device *hdev)
 {
        int rc;
index 16637d629e67334e7db86cff87260922add62f1f..f096cfc03bf3e4f8938e404741de5324ac15334e 100644 (file)
@@ -9361,7 +9361,7 @@ static const struct hl_asic_funcs gaudi_funcs = {
        .debugfs_read64 = gaudi_debugfs_read64,
        .debugfs_write64 = gaudi_debugfs_write64,
        .debugfs_read_dma = gaudi_debugfs_read_dma,
-       .add_device_attr = hl_add_device_attr,
+       .add_device_attr = hl_sysfs_add_dev_clk_attr,
        .handle_eqe = gaudi_handle_eqe,
        .set_pll_profile = hl_set_pll_profile,
        .get_events_stat = gaudi_get_events_stat,