Skip to contentSkip to conversation

habanalabs: change CB's ID to be 64 bits

PATCH In review Oded Gabbay 2 participants 16 messages Aug 15, 2020 – Aug 16, 2020 1 message not in the archive Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/9 habanalabs: change CB's ID to be 64 bits

Although the possible values for CB's ID are only 32 bits, there are a few places in the code where this field is shifted and passed into a function which expects 64 bits.

---
 drivers/misc/habanalabs/common/command_buffer.c | 2 +-
 drivers/misc/habanalabs/common/debugfs.c        | 2 +-
 drivers/misc/habanalabs/common/habanalabs.h     | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/common/command_buffer.c +1 -1
index 7c38c4f7f9c0..33aee64f37aa 100644
@@ -173,7 +173,7 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,
 		goto release_cb;
 	}
 
-	cb->id = rc;
+	cb->id = (u64) rc;
 
 	kref_init(&cb->refcount);
 	spin_lock_init(&cb->lock);
drivers/misc/habanalabs/common/debugfs.c +1 -1
index c50c6fc9e905..25775b12139b 100644
@@ -110,7 +110,7 @@ static int command_buffers_show(struct seq_file *s, void *data)
 			seq_puts(s, "---------------------------------------------------------------\n");
 		}
 		seq_printf(s,
-			"   %03d        %d    0x%08x      %d          %d          %d\n",
+			"   %03llu        %d    0x%08x      %d          %d          %d\n",
 			cb->id, cb->ctx_id, cb->size,
 			kref_read(&cb->refcount),
 			cb->mmap, cb->cs_cnt);
drivers/misc/habanalabs/common/habanalabs.h +2 -2
index 52a07c8d7d7c..2decf7be3e08 100644
@@ -401,11 +401,11 @@ struct hl_cb_mgr {
  * @lock: spinlock to protect mmap/cs flows.
  * @debugfs_list: node in debugfs list of command buffers.
  * @pool_list: node in pool list of command buffers.
+ * @id: the CB's ID.
  * @kernel_address: Holds the CB's kernel virtual address.
  * @bus_address: Holds the CB's DMA address.
  * @mmap_size: Holds the CB's size that was mmaped.
  * @size: holds the CB's size.
- * @id: the CB's ID.
  * @cs_cnt: holds number of CS that this CB participates in.
  * @ctx_id: holds the ID of the owner's context.
  * @mmap: true if the CB is currently mmaped to user.
@@ -418,11 +418,11 @@ struct hl_cb {
 	spinlock_t		lock;
 	struct list_head	debugfs_list;
 	struct list_head	pool_list;
+	u64			id;
 	u64			kernel_address;
 	dma_addr_t		bus_address;
 	u32			mmap_size;
 	u32			size;
-	u32			id;
 	u32			cs_cnt;
 	u32			ctx_id;
 	u8			mmap;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/9 habanalabs: cast int to u32 before printing it with %u

%u is used for unsigned so we need to cast the int variable to u32 to avoid compiler warning.

---
 drivers/misc/habanalabs/common/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/habanalabs/common/device.c +1 -1
index 35214a186913..38895493a0ed 100644
@@ -286,7 +286,7 @@ static int device_early_init(struct hl_device *hdev)
 	}
 
 	for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
-		snprintf(workq_name, 32, "hl-free-jobs-%u", i);
+		snprintf(workq_name, 32, "hl-free-jobs-%u", (u32) i);
 		hdev->cq_wq[i] = create_singlethread_workqueue(workq_name);
 		if (hdev->cq_wq[i] == NULL) {
 			dev_err(hdev->dev, "Failed to allocate CQ workqueue\n");
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/9 habanalabs: eliminate redundant else condition

In reply to Oded Gabbay

If both parts of if-else are goto statements, we can remove the else and put the else goto statement after the if statement.

---
 drivers/misc/habanalabs/common/command_submission.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/misc/habanalabs/common/command_submission.c +2 -2
index 2b40aa85bec9..58327cdb6a2c 100644
@@ -686,8 +686,8 @@ static int cs_ioctl_default(struct hl_fpriv *hpriv, void __user *chunks,
 			rc = -ENOMEM;
 			if (is_kernel_allocated_cb)
 				goto release_cb;
-			else
-				goto free_cs_object;
+
+			goto free_cs_object;
 		}
 
 		job->id = i + 1;
Signature · 1 line
2.17.1
#5 lore raw

PATCH 4/9 habanalabs: use standard BIT() and GENMASK()

In reply to Oded Gabbay

Use the standard macros to define bitmasks.

---
 drivers/misc/habanalabs/gaudi/gaudiP.h | 44 +++++++++++++-------------
 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/misc/habanalabs/gaudi/gaudiP.h +22 -22
index 5dc99f6f0296..2eb5b9330275 100644
@@ -141,28 +141,28 @@
 #define VA_HOST_SPACE_SIZE	(VA_HOST_SPACE_END - \
 					VA_HOST_SPACE_START) /* 767TB */
 
-#define HW_CAP_PLL		0x00000001
-#define HW_CAP_HBM		0x00000002
-#define HW_CAP_MMU		0x00000004
-#define HW_CAP_MME		0x00000008
-#define HW_CAP_CPU		0x00000010
-#define HW_CAP_PCI_DMA		0x00000020
-#define HW_CAP_MSI		0x00000040
-#define HW_CAP_CPU_Q		0x00000080
-#define HW_CAP_HBM_DMA		0x00000100
-#define HW_CAP_CLK_GATE		0x00000200
-#define HW_CAP_SRAM_SCRAMBLER	0x00000400
-#define HW_CAP_HBM_SCRAMBLER	0x00000800
-
-#define HW_CAP_TPC0		0x01000000
-#define HW_CAP_TPC1		0x02000000
-#define HW_CAP_TPC2		0x04000000
-#define HW_CAP_TPC3		0x08000000
-#define HW_CAP_TPC4		0x10000000
-#define HW_CAP_TPC5		0x20000000
-#define HW_CAP_TPC6		0x40000000
-#define HW_CAP_TPC7		0x80000000
-#define HW_CAP_TPC_MASK		0xFF000000
+#define HW_CAP_PLL		BIT(0)
+#define HW_CAP_HBM		BIT(1)
+#define HW_CAP_MMU		BIT(2)
+#define HW_CAP_MME		BIT(3)
+#define HW_CAP_CPU		BIT(4)
+#define HW_CAP_PCI_DMA		BIT(5)
+#define HW_CAP_MSI		BIT(6)
+#define HW_CAP_CPU_Q		BIT(7)
+#define HW_CAP_HBM_DMA		BIT(8)
+#define HW_CAP_CLK_GATE		BIT(9)
+#define HW_CAP_SRAM_SCRAMBLER	BIT(10)
+#define HW_CAP_HBM_SCRAMBLER	BIT(11)
+
+#define HW_CAP_TPC0		BIT(24)
+#define HW_CAP_TPC1		BIT(25)
+#define HW_CAP_TPC2		BIT(26)
+#define HW_CAP_TPC3		BIT(27)
+#define HW_CAP_TPC4		BIT(28)
+#define HW_CAP_TPC5		BIT(29)
+#define HW_CAP_TPC6		BIT(30)
+#define HW_CAP_TPC7		BIT(31)
+#define HW_CAP_TPC_MASK		GENMASK(31, 24)
 #define HW_CAP_TPC_SHIFT	24
 
 #define GAUDI_CPU_PCI_MSB_ADDR(addr)	(((addr) & GENMASK_ULL(49, 39)) >> 39)
Signature · 1 line
2.17.1
#7 lore raw

PATCH 5/9 habanalabs: use FIELD_PREP() instead of <<

In reply to Oded Gabbay

Use the standard FIELD_PREP() macro instead of << operator to perform bitmask operations. This ensures type check safety and eliminate compiler warnings.

---
 drivers/misc/habanalabs/common/hw_queue.c     |   9 +-
 drivers/misc/habanalabs/gaudi/gaudi.c         |  50 ++--
 .../habanalabs/include/gaudi/gaudi_masks.h    | 274 ++++++++----------
 3 files changed, 154 insertions(+), 179 deletions(-)
drivers/misc/habanalabs/common/hw_queue.c +5 -4
index 65b9aa69a83e..e2f9ba04b32d 100644
@@ -8,6 +8,7 @@
 #include "habanalabs.h"
 
 #include <linux/slab.h>
+#include <linux/bitfield.h>
 
 /*
  * hl_queue_add_ptr - add to pi or ci and checks if it wraps around
@@ -288,10 +289,10 @@ static void ext_queue_schedule_job(struct hl_cs_job *job)
 	ptr = cb->bus_address;
 
 	cq_pkt.data = cpu_to_le32(
-				((q->pi << CQ_ENTRY_SHADOW_INDEX_SHIFT)
-					& CQ_ENTRY_SHADOW_INDEX_MASK) |
-				(1 << CQ_ENTRY_SHADOW_INDEX_VALID_SHIFT) |
-				(1 << CQ_ENTRY_READY_SHIFT));
+			((q->pi << CQ_ENTRY_SHADOW_INDEX_SHIFT)
+				& CQ_ENTRY_SHADOW_INDEX_MASK) |
+			FIELD_PREP(CQ_ENTRY_SHADOW_INDEX_VALID_MASK, 1) |
+			FIELD_PREP(CQ_ENTRY_READY_MASK, 1));
 
 	/*
 	 * No need to protect pi_offset because scheduling to the
drivers/misc/habanalabs/gaudi/gaudi.c +27 -23

105 lines not on this page · raw message

drivers/misc/habanalabs/include/gaudi/gaudi_masks.h +122 -152

316 lines not on this page · raw message

Signature · 1 line
2.17.1
Reviewed-by on v1 5/9
#8 lore raw

RE: [PATCH 5/9] habanalabs: use FIELD_PREP() instead of <<

Quoted 6 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:

Use the standard FIELD_PREP() macro instead of << operator to perform bitmask operations. This ensures type check safety and eliminate compiler warnings.

#9 lore raw

PATCH 6/9 habanalabs: remove redundant assignment to variable

In reply to Oded Gabbay

new_dma_pkt->ctl is assigned a value and then is reassigned a new value without the first value ever being used.

---
 drivers/misc/habanalabs/gaudi/gaudi.c | 2 --
 1 file changed, 2 deletions(-)
drivers/misc/habanalabs/gaudi/gaudi.c +0 -2
index ed289a6ed622..ffd0849e8f2d 100644
@@ -3944,8 +3944,6 @@ static int gaudi_patch_dma_packet(struct hl_device *hdev,
 			}
 		}
 
-		new_dma_pkt->ctl = user_dma_pkt->ctl;
-
 		ctl = le32_to_cpu(user_dma_pkt->ctl);
 		if (likely(dma_desc_cnt))
 			ctl &= ~GAUDI_PKT_CTL_EB_MASK;
Signature · 1 line
2.17.1
#11 lore raw

PATCH 7/9 habanalabs: check TPC vector pipe is empty

In reply to Oded Gabbay

The driver waits for the TPC vector pipe to be empty before checking if the TPC kernel has finished executing, but the code doesn't validate that the pipe was indeed empty, it just wait for it without checking the return value.

---
 drivers/misc/habanalabs/gaudi/gaudi.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/misc/habanalabs/gaudi/gaudi.c +9 -0
index ffd0849e8f2d..3360c3c207a9 100644
@@ -6262,6 +6262,15 @@ static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel,
 		1000,
 		kernel_timeout);
 
+	if (rc) {
+		dev_err(hdev->dev,
+			"Timeout while waiting for TPC%d vector pipe\n",
+			tpc_id);
+		hdev->asic_funcs->set_clock_gating(hdev);
+		mutex_unlock(&gaudi->clk_gate_mutex);
+		return -EIO;
+	}
+
 	rc = hl_poll_timeout(
 		hdev,
 		mmTPC0_CFG_WQ_INFLIGHT_CNTR + offset,
Signature · 1 line
2.17.1
Reviewed-by on v1 7/9
#12 lore raw

RE: [PATCH 7/9] habanalabs: check TPC vector pipe is empty

Quoted 7 lines · On Sat, Aug 15, 2020 at 21:00 Oded Gabbay <[email protected]> wrote:

The driver waits for the TPC vector pipe to be empty before checking if the TPC kernel has finished executing, but the code doesn't validate that the pipe was indeed empty, it just wait for it without checking the return value.

#13 lore raw

PATCH 9/9 habanalabs: extend busy engines mask to 64 bits

In reply to Oded Gabbay

From: farah kassabri <[email protected]>

change busy engines bitmask to 64 bits in order to represent more engines, needed for future ASIC support.

---
 drivers/misc/habanalabs/common/habanalabs.h       | 2 +-
 drivers/misc/habanalabs/common/habanalabs_ioctl.c | 2 +-
 drivers/misc/habanalabs/gaudi/gaudi.c             | 2 +-
 drivers/misc/habanalabs/goya/goya.c               | 2 +-
 include/uapi/misc/habanalabs.h                    | 6 ++++++
 5 files changed, 10 insertions(+), 4 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +1 -1
index 2decf7be3e08..dbf214421ae1 100644
@@ -754,7 +754,7 @@ struct hl_asic_funcs {
 	void (*set_clock_gating)(struct hl_device *hdev);
 	void (*disable_clock_gating)(struct hl_device *hdev);
 	int (*debug_coresight)(struct hl_device *hdev, void *data);
-	bool (*is_device_idle)(struct hl_device *hdev, u32 *mask,
+	bool (*is_device_idle)(struct hl_device *hdev, u64 *mask,
 				struct seq_file *s);
 	int (*soft_reset_late_init)(struct hl_device *hdev);
 	void (*hw_queues_lock)(struct hl_device *hdev);
drivers/misc/habanalabs/common/habanalabs_ioctl.c +1 -1
index fe6c5534d378..a94800014243 100644
@@ -132,7 +132,7 @@ static int hw_idle(struct hl_device *hdev, struct hl_info_args *args)
 		return -EINVAL;
 
 	hw_idle.is_idle = hdev->asic_funcs->is_device_idle(hdev,
-					&hw_idle.busy_engines_mask, NULL);
+					&hw_idle.busy_engines_mask_ext, NULL);
 
 	return copy_to_user(out, &hw_idle,
 		min((size_t) max_size, sizeof(hw_idle))) ? -EFAULT : 0;
drivers/misc/habanalabs/gaudi/gaudi.c +1 -1
index 3360c3c207a9..e56f95e6c741 100644
@@ -6041,7 +6041,7 @@ static int gaudi_armcp_info_get(struct hl_device *hdev)
 	return 0;
 }
 
-static bool gaudi_is_device_idle(struct hl_device *hdev, u32 *mask,
+static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
 					struct seq_file *s)
 {
 	struct gaudi_device *gaudi = hdev->asic_specific;
drivers/misc/habanalabs/goya/goya.c +1 -1
index 77a5963a4d10..021cd26fb018 100644
@@ -5117,7 +5117,7 @@ static void goya_disable_clock_gating(struct hl_device *hdev)
 	/* clock gating not supported in Goya */
 }
 
-static bool goya_is_device_idle(struct hl_device *hdev, u32 *mask,
+static bool goya_is_device_idle(struct hl_device *hdev, u64 *mask,
 				struct seq_file *s)
 {
 	const char *fmt = "%-5d%-9s%#-14x%#-16x%#x\n";
include/uapi/misc/habanalabs.h +6 -0
index ca6dc1fc250e..693081728ef3 100644
@@ -319,6 +319,12 @@ struct hl_info_hw_idle {
 	 * Bits definition is according to `enum <chip>_enging_id'.
 	 */
 	__u32 busy_engines_mask;
+
+	/*
+	 * Extended Bitmask of busy engines.
+	 * Bits definition is according to `enum <chip>_enging_id'.
+	 */
+	__u64 busy_engines_mask_ext;
 };
 
 struct hl_info_device_status {
Signature · 1 line
2.17.1

A message that is not in the archive (sent off-list or not yet received): [email protected]