habanalabs: get clk is common function
authorOded Gabbay <ogabbay@kernel.org>
Sat, 8 Jan 2022 19:40:06 +0000 (21:40 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Mon, 28 Feb 2022 12:22:01 +0000 (14:22 +0200)
Retrieving the clock from the f/w is done exactly the same in ALL our
ASICs. Therefore, no real justification for doing it as an
ASIC-specific function.

The only thing is we need to check if we are running on simulator,
which doesn't require ASIC-specific callback.

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

index 571998899253e02270e8fea4c9feeb93108a9094..ecfdfec7abdc6155045431b490a4d58e28c8541a 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0
  *
- * Copyright 2016-2021 HabanaLabs, Ltd.
+ * Copyright 2016-2022 HabanaLabs, Ltd.
  * All Rights Reserved.
  *
  */
@@ -1190,7 +1190,6 @@ struct fw_load_mgr {
  * @halt_coresight: stop the ETF and ETR traces.
  * @ctx_init: context dependent initialization.
  * @ctx_fini: context dependent cleanup.
- * @get_clk_rate: Retrieve the ASIC current and maximum clock rate in MHz
  * @get_queue_id_for_cq: Get the H/W queue id related to the given CQ index.
  * @load_firmware_to_device: load the firmware to the device's memory
  * @load_boot_fit_to_device: load boot fit to device's memory
@@ -1321,7 +1320,6 @@ struct hl_asic_funcs {
        void (*halt_coresight)(struct hl_device *hdev, struct hl_ctx *ctx);
        int (*ctx_init)(struct hl_ctx *ctx);
        void (*ctx_fini)(struct hl_ctx *ctx);
-       int (*get_clk_rate)(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk);
        u32 (*get_queue_id_for_cq)(struct hl_device *hdev, u32 cq_idx);
        int (*load_firmware_to_device)(struct hl_device *hdev);
        int (*load_boot_fit_to_device)(struct hl_device *hdev);
@@ -3122,8 +3120,7 @@ int hl_set_power(struct hl_device *hdev,
                        int sensor_index, u32 attr, long value);
 int hl_get_power(struct hl_device *hdev,
                        int sensor_index, u32 attr, long *value);
-int hl_get_clk_rate(struct hl_device *hdev,
-                       u32 *cur_clk, u32 *max_clk);
+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_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);
index 3ba3a8ffda3e5a5717e5dcb733afe372a7c14a4f..ed516f911ee2acf74126ae6dd6c33ad1a2ccde29 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.
  */
 
@@ -251,13 +251,12 @@ static int get_clk_rate(struct hl_device *hdev, struct hl_info_args *args)
        if ((!max_size) || (!out))
                return -EINVAL;
 
-       rc = hdev->asic_funcs->get_clk_rate(hdev, &clk_rate.cur_clk_rate_mhz,
-                                               &clk_rate.max_clk_rate_mhz);
+       rc = hl_get_clk_rate(hdev, &clk_rate.cur_clk_rate_mhz, &clk_rate.max_clk_rate_mhz);
        if (rc)
                return rc;
 
-       return copy_to_user(out, &clk_rate,
-               min((size_t) max_size, sizeof(clk_rate))) ? -EFAULT : 0;
+       return copy_to_user(out, &clk_rate, min_t(size_t, max_size, sizeof(clk_rate)))
+                                                                               ? -EFAULT : 0;
 }
 
 static int get_reset_count(struct hl_device *hdev, struct hl_info_args *args)
index f0e5417560c34b1b4b53c5df7bca4160c3819793..e96126b460566d2e2fbf7fb8421fcc499196642f 100644 (file)
@@ -20,11 +20,16 @@ int hl_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk)
        if (!hl_device_operational(hdev, NULL))
                return -ENODEV;
 
+       if (!hdev->pdev) {
+               *cur_clk = 0;
+               *max_clk = 0;
+               return 0;
+       }
+
        value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, false);
 
        if (value < 0) {
-               dev_err(hdev->dev, "Failed to retrieve device max clock %ld\n",
-                       value);
+               dev_err(hdev->dev, "Failed to retrieve device max clock %ld\n", value);
                return value;
        }
 
@@ -33,9 +38,7 @@ int hl_get_clk_rate(struct hl_device *hdev, u32 *cur_clk, u32 *max_clk)
        value = hl_get_frequency(hdev, hdev->asic_prop.clk_pll_index, true);
 
        if (value < 0) {
-               dev_err(hdev->dev,
-                       "Failed to retrieve device current clock %ld\n",
-                       value);
+               dev_err(hdev->dev, "Failed to retrieve device current clock %ld\n", value);
                return value;
        }
 
index f096cfc03bf3e4f8938e404741de5324ac15334e..744d4305db40547ce4ed66104d61296368307603 100644 (file)
@@ -9385,7 +9385,6 @@ static const struct hl_asic_funcs gaudi_funcs = {
        .halt_coresight = gaudi_halt_coresight,
        .ctx_init = gaudi_ctx_init,
        .ctx_fini = gaudi_ctx_fini,
-       .get_clk_rate = hl_get_clk_rate,
        .get_queue_id_for_cq = gaudi_get_queue_id_for_cq,
        .load_firmware_to_device = gaudi_load_firmware_to_device,
        .load_boot_fit_to_device = gaudi_load_boot_fit_to_device,
index 954ef4d7bbf7da0af9b72728faa2ef266f47afd1..318b97c53ed787dd85e52b476a3b53fe296f90ee 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 /*
- * Copyright 2016-2021 HabanaLabs, Ltd.
+ * Copyright 2016-2022 HabanaLabs, Ltd.
  * All Rights Reserved.
  */
 
@@ -5739,7 +5739,6 @@ static const struct hl_asic_funcs goya_funcs = {
        .halt_coresight = goya_halt_coresight,
        .ctx_init = goya_ctx_init,
        .ctx_fini = goya_ctx_fini,
-       .get_clk_rate = hl_get_clk_rate,
        .get_queue_id_for_cq = goya_get_queue_id_for_cq,
        .load_firmware_to_device = goya_load_firmware_to_device,
        .load_boot_fit_to_device = goya_load_boot_fit_to_device,