RE: [PATCH 2/2] habanalabs: set clock gating per engine

2020-07-05 Thread Omer Shpigelman
On Tue, Jul 5, 2020 at 00:30 AM, Oded Gabbay  wrote:
> For debugging purposes, we need to allow the root user better control of the
> clock gating feature of the DMA and compute engines. Therefore, change
> the clock gating debugfs interface to be bitmask instead of true/false.
> Each bit represents a different engine, according to gaudi_engine_id enum.
> 
> See debugfs documentation for more details.
> 
> Signed-off-by: Oded Gabbay 

Reviewed-by: Omer Shpigelman 


[PATCH 2/2] habanalabs: set clock gating per engine

2020-07-04 Thread Oded Gabbay
For debugging purposes, we need to allow the root user better control of
the clock gating feature of the DMA and compute engines. Therefore, change
the clock gating debugfs interface to be bitmask instead of true/false.
Each bit represents a different engine, according to gaudi_engine_id enum.

See debugfs documentation for more details.

Signed-off-by: Oded Gabbay 
---
 .../ABI/testing/debugfs-driver-habanalabs |  11 +-
 drivers/misc/habanalabs/debugfs.c |  17 +--
 drivers/misc/habanalabs/device.c  |   2 +-
 drivers/misc/habanalabs/gaudi/gaudi.c | 112 --
 drivers/misc/habanalabs/goya/goya.c   |   8 +-
 drivers/misc/habanalabs/habanalabs.h  |  13 +-
 drivers/misc/habanalabs/habanalabs_drv.c  |   2 +-
 7 files changed, 103 insertions(+), 62 deletions(-)

diff --git a/Documentation/ABI/testing/debugfs-driver-habanalabs 
b/Documentation/ABI/testing/debugfs-driver-habanalabs
index f6d9c2a8d528..2e9ae311e02d 100644
--- a/Documentation/ABI/testing/debugfs-driver-habanalabs
+++ b/Documentation/ABI/testing/debugfs-driver-habanalabs
@@ -16,7 +16,16 @@ Description:Allow the root user to disable/enable in 
runtime the clock
 gating mechanism in Gaudi. Due to how Gaudi is built, the
 clock gating needs to be disabled in order to access the
 registers of the TPC and MME engines. This is sometimes needed
-during debug by the user and hence the user needs this option
+during debug by the user and hence the user needs this option.
+The user can supply a bitmask value, each bit represents
+a different engine to disable/enable its clock gating feature.
+The bitmask is composed of 20 bits:
+0  -  7 : DMA channels
+8  - 11 : MME engines
+12 - 19 : TPC engines
+The bit's location of a specific engine can be determined
+using (1 << GAUDI_ENGINE_ID_*). GAUDI_ENGINE_ID_* values
+are defined in uapi habanalabs.h file in enum gaudi_engine_id
 
 What:   /sys/kernel/debug/habanalabs/hl/command_buffers
 Date:   Jan 2019
diff --git a/drivers/misc/habanalabs/debugfs.c 
b/drivers/misc/habanalabs/debugfs.c
index fc4372c18ce2..136b8f6fa0b3 100644
--- a/drivers/misc/habanalabs/debugfs.c
+++ b/drivers/misc/habanalabs/debugfs.c
@@ -981,7 +981,7 @@ static ssize_t hl_clk_gate_read(struct file *f, char __user 
*buf,
if (*ppos)
return 0;
 
-   sprintf(tmp_buf, "%d\n", hdev->clock_gating);
+   sprintf(tmp_buf, "0x%llx\n", hdev->clock_gating_mask);
rc = simple_read_from_buffer(buf, strlen(tmp_buf) + 1, ppos, tmp_buf,
strlen(tmp_buf) + 1);
 
@@ -993,7 +993,7 @@ static ssize_t hl_clk_gate_write(struct file *f, const char 
__user *buf,
 {
struct hl_dbg_device_entry *entry = file_inode(f)->i_private;
struct hl_device *hdev = entry->hdev;
-   u32 value;
+   u64 value;
ssize_t rc;
 
if (atomic_read(>in_reset)) {
@@ -1002,19 +1002,12 @@ static ssize_t hl_clk_gate_write(struct file *f, const 
char __user *buf,
return 0;
}
 
-   rc = kstrtouint_from_user(buf, count, 10, );
+   rc = kstrtoull_from_user(buf, count, 16, );
if (rc)
return rc;
 
-   if (value) {
-   hdev->clock_gating = 1;
-   if (hdev->asic_funcs->enable_clock_gating)
-   hdev->asic_funcs->enable_clock_gating(hdev);
-   } else {
-   if (hdev->asic_funcs->disable_clock_gating)
-   hdev->asic_funcs->disable_clock_gating(hdev);
-   hdev->clock_gating = 0;
-   }
+   hdev->clock_gating_mask = value;
+   hdev->asic_funcs->set_clock_gating(hdev);
 
return count;
 }
diff --git a/drivers/misc/habanalabs/device.c b/drivers/misc/habanalabs/device.c
index 2b38a119704c..59608d1bac88 100644
--- a/drivers/misc/habanalabs/device.c
+++ b/drivers/misc/habanalabs/device.c
@@ -608,7 +608,7 @@ int hl_device_set_debug_mode(struct hl_device *hdev, bool 
enable)
hdev->in_debug = 0;
 
if (!hdev->hard_reset_pending)
-   hdev->asic_funcs->enable_clock_gating(hdev);
+   hdev->asic_funcs->set_clock_gating(hdev);
 
goto out;
}
diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c 
b/drivers/misc/habanalabs/gaudi/gaudi.c
index e22206527164..9d6aebef8854 100644
--- a/drivers/misc/habanalabs/gaudi/gaudi.c
+++ b/drivers/misc/habanalabs/gaudi/gaudi.c
@@ -98,6 +98,11 @@
 
 #define GAUDI_ARB_WDT_TIMEOUT  0x100
 
+#define GAUDI_CLK_GATE_DEBUGFS_MASK(\
+   BIT(GAUDI_ENGINE_ID_MME_0) |\
+   BIT(GAUDI_ENGINE_ID_MME_2) |\
+   GENMASK_ULL(GAUDI_ENGINE_ID_TPC_7, GAUDI_ENGINE_ID_TPC_0))
+
 static const char