Skip to contentSkip to conversation

accel/habanalabs: remove sim code

PATCH In review Oded Gabbay 3 participants 7 messages May 22, 2023 – May 27, 2023

Subsystems (4)
lore
Share & tools
lore

Oded Gabbay

author maintainer
#0 lore raw

PATCH 1/4 accel/habanalabs: remove sim code

There were a few places where simulator only code got into the upstream. Remove those places that can confuse other developers.

Fixes 2a0a839b6a28 ("habanalabs: extend fatal messages to contain PCI info")
Cc Moti Haimovski <[email protected]>
Cc Dan Carpenter <[email protected]>
---
 drivers/accel/habanalabs/common/device.c     | 10 +++------
 drivers/accel/habanalabs/common/habanalabs.h | 23 ++++----------------
 2 files changed, 7 insertions(+), 26 deletions(-)
drivers/accel/habanalabs/common/device.c +3 -7
index cab5a63db8c1..ca15c8d0d042 100644
@@ -2328,13 +2328,9 @@ int hl_device_init(struct hl_device *hdev)
 	hdev->disabled = true;
 	if (expose_interfaces_on_err)
 		cdev_sysfs_debugfs_add(hdev);
-	if (hdev->pdev)
-		dev_err(&hdev->pdev->dev,
-			"Failed to initialize hl%d. Device %s is NOT usable !\n",
-			hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
-	else
-		pr_err("Failed to initialize hl%d. Device %s is NOT usable !\n",
-			hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
+	dev_err(&hdev->pdev->dev,
+		"Failed to initialize hl%d. Device %s is NOT usable !\n",
+		hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
 
 	return rc;
 }
drivers/accel/habanalabs/common/habanalabs.h +4 -19
index e2341a75a4b7..c5aa33eaa826 100644
@@ -2558,12 +2558,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
 	ktime_t __timeout; \
 	u32 __elbi_read; \
 	int __rc = 0; \
-	if (hdev->pdev) \
-		__timeout = ktime_add_us(ktime_get(), timeout_us); \
-	else \
-		__timeout = ktime_add_us(ktime_get(),\
-				min((u64)(timeout_us * 10), \
-					(u64) HL_SIM_MAX_TIMEOUT_US)); \
+	__timeout = ktime_add_us(ktime_get(), timeout_us); \
 	might_sleep_if(sleep_us); \
 	for (;;) { \
 		if (elbi) { \
@@ -2615,13 +2610,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
 	u8 __arr_idx;	\
 	int __rc = 0; \
 	\
-	if (hdev->pdev) \
-		__timeout = ktime_add_us(ktime_get(), timeout_us); \
-	else \
-		__timeout = ktime_add_us(ktime_get(),\
-				min(((u64)timeout_us * 10), \
-					(u64) HL_SIM_MAX_TIMEOUT_US)); \
-	\
+	__timeout = ktime_add_us(ktime_get(), timeout_us); \
 	might_sleep_if(sleep_us); \
 	if (arr_size >= 64) \
 		__rc = -EINVAL; \
@@ -2679,12 +2668,8 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);
 				mem_written_by_device) \
 ({ \
 	ktime_t __timeout; \
-	if (hdev->pdev) \
-		__timeout = ktime_add_us(ktime_get(), timeout_us); \
-	else \
-		__timeout = ktime_add_us(ktime_get(),\
-				min((u64)(timeout_us * 100), \
-					(u64) HL_SIM_MAX_TIMEOUT_US)); \
+	\
+	__timeout = ktime_add_us(ktime_get(), timeout_us); \
 	might_sleep_if(sleep_us); \
 	for (;;) { \
 		/* Verify we read updates done by other cores or by device */ \
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 2/4 accel/habanalabs: add description to several info ioctls

From: Dani Liberman <[email protected]>

Several info ioctls may return success although no data retrieved.

---
 include/uapi/drm/habanalabs_accel.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/uapi/drm/habanalabs_accel.h +10 -0
index d45454b9a62e..03464ed86c68 100644
@@ -787,18 +787,28 @@ enum hl_server_type {
  *                            The address which accessing it caused the razwi.
  *                            Razwi initiator.
  *                            Razwi cause, was it a page fault or MMU access error.
+ *                            May return 0 even though no new data is available, in that case
+ *                            timestamp will be 0.
  * HL_INFO_DEV_MEM_ALLOC_PAGE_SIZES - Retrieve valid page sizes for device memory allocation
  * HL_INFO_SECURED_ATTESTATION - Retrieve attestation report of the boot.
  * HL_INFO_REGISTER_EVENTFD   - Register eventfd for event notifications.
  * HL_INFO_UNREGISTER_EVENTFD - Unregister eventfd
  * HL_INFO_GET_EVENTS         - Retrieve the last occurred events
  * HL_INFO_UNDEFINED_OPCODE_EVENT - Retrieve last undefined opcode error information.
+ *                                  May return 0 even though no new data is available, in that case
+ *                                  timestamp will be 0.
  * HL_INFO_ENGINE_STATUS - Retrieve the status of all the h/w engines in the asic.
  * HL_INFO_PAGE_FAULT_EVENT - Retrieve parameters of captured page fault.
+ *                            May return 0 even though no new data is available, in that case
+ *                            timestamp will be 0.
  * HL_INFO_USER_MAPPINGS - Retrieve user mappings, captured after page fault event.
  * HL_INFO_FW_GENERIC_REQ - Send generic request to FW.
  * HL_INFO_HW_ERR_EVENT   - Retrieve information on the reported HW error.
+ *                          May return 0 even though no new data is available, in that case
+ *                          timestamp will be 0.
  * HL_INFO_FW_ERR_EVENT   - Retrieve information on the reported FW error.
+ *                          May return 0 even though no new data is available, in that case
+ *                          timestamp will be 0.
  */
 #define HL_INFO_HW_IP_INFO			0
 #define HL_INFO_HW_EVENTS			1
Signature · 1 line
2.40.1
author maintainer
#3 lore raw

PATCH 4/4 accel/habanalabs: move ioctl error print to debug level

In reply to Oded Gabbay

We don't want to allow users to spam the kernel log and sending ioctls with bad opcodes is a sure way to do it.

---
 drivers/accel/habanalabs/common/habanalabs_ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/accel/habanalabs/common/habanalabs_ioctl.c +3 -3
index 9a8be9395fb2..6a45a92344e9 100644
@@ -1195,7 +1195,7 @@ static long _hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg,
 
 out_err:
 	if (retcode)
-		dev_dbg(dev, "error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n",
+		dev_dbg_ratelimited(dev, "error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n",
 			  task_pid_nr(current), cmd, nr);
 
 	if (kdata != stack_kdata)
@@ -1219,7 +1219,7 @@ long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 	if ((nr >= HL_COMMAND_START) && (nr < HL_COMMAND_END)) {
 		ioctl = &hl_ioctls[nr];
 	} else {
-		dev_err(hdev->dev, "invalid ioctl: pid=%d, nr=0x%02x\n",
+		dev_dbg_ratelimited(hdev->dev, "invalid ioctl: pid=%d, nr=0x%02x\n",
 			task_pid_nr(current), nr);
 		return -ENOTTY;
 	}
@@ -1242,7 +1242,7 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)
 	if (nr == _IOC_NR(HL_IOCTL_INFO)) {
 		ioctl = &hl_ioctls_control[nr];
 	} else {
-		dev_err(hdev->dev_ctrl, "invalid ioctl: pid=%d, nr=0x%02x\n",
+		dev_dbg_ratelimited(hdev->dev_ctrl, "invalid ioctl: pid=%d, nr=0x%02x\n",
 			task_pid_nr(current), nr);
 		return -ENOTTY;
 	}
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

PATCH 3/4 accel/habanalabs: fix bug of not fetching addr_dec info

In reply to Oded Gabbay

From: Ofir Bitton <[email protected]>

addr_dec info should always be fetched, regardless of cause value.

---
 drivers/accel/habanalabs/gaudi2/gaudi2.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/accel/habanalabs/gaudi2/gaudi2.c +6 -2
index 1cb2b72e1cd2..0d41adf4792c 100644
@@ -8769,6 +8769,9 @@ static int gaudi2_print_pcie_addr_dec_info(struct hl_device *hdev, u16 event_typ
 	u32 error_count = 0;
 	int i;
 
+	gaudi2_print_event(hdev, event_type, true,
+		"intr_cause_data: %#llx", intr_cause_data);
+
 	for (i = 0 ; i < GAUDI2_NUM_OF_PCIE_ADDR_DEC_ERR_CAUSE ; i++) {
 		if (!(intr_cause_data & BIT_ULL(i)))
 			continue;
@@ -8781,10 +8784,11 @@ static int gaudi2_print_pcie_addr_dec_info(struct hl_device *hdev, u16 event_typ
 		 * Always check for LBW and HBW additional info as the indication itself is
 		 * sometimes missing
 		 */
-		hl_check_for_glbl_errors(hdev);
-		gaudi2_print_pcie_mstr_rr_mstr_if_razwi_info(hdev, event_mask);
 	}
 
+	hl_check_for_glbl_errors(hdev);
+	gaudi2_print_pcie_mstr_rr_mstr_if_razwi_info(hdev, event_mask);
+
 	return error_count;
 }
 
Signature · 1 line
2.40.1
#5 lore raw
In reply to Oded Gabbay

Thanks!

Quoted 6 lines · Oded Gabbay
drivers/accel/habanalabs/common/device.c +0 -0
index cab5a63db8c1..ca15c8d0d042 100644
@@ -2328,13 +2328,9 @@ int hl_device_init(struct hl_device *hdev)
 	hdev->disabled = true;

drivers/accel/habanalabs/common/device.c int hl_device_init(struct hl_device *hdev) · line 2331

Quoted 10 lines
drivers/accel/habanalabs/common/device.c +1 -7
 	if (expose_interfaces_on_err)
 		cdev_sysfs_debugfs_add(hdev);
-	if (hdev->pdev)
-		dev_err(&hdev->pdev->dev,
-			"Failed to initialize hl%d. Device %s is NOT usable !\n",
-			hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
-	else
-		pr_err("Failed to initialize hl%d. Device %s is NOT usable !\n",
-			hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
+	dev_err(&hdev->pdev->dev,
                 ^^^^^^^^^^^^^^^

drivers/accel/habanalabs/common/device.c int hl_device_init(struct hl_device *hdev) · line 2333

Quoted 2 lines
drivers/accel/habanalabs/common/device.c +2 -0
+		"Failed to initialize hl%d. Device %s is NOT usable !\n",
+		hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
                                         ^^^^^^^^^^^^^^^^^^^

I hate to be picky, but would it be too much to get rid of the parens around (hdev)?

regards,
dan carpenter

author maintainer
#6 lore raw
Quoted 22 lines · Dan Carpenter

Thanks!

Quoted 6 lines · Oded Gabbay
drivers/accel/habanalabs/common/device.c +0 -0
index cab5a63db8c1..ca15c8d0d042 100644
@@ -2328,13 +2328,9 @@ int hl_device_init(struct hl_device *hdev)
      hdev->disabled = true;

drivers/accel/habanalabs/common/device.c int hl_device_init(struct hl_device *hdev) · line 2331

Quoted 10 lines
drivers/accel/habanalabs/common/device.c +1 -7
      if (expose_interfaces_on_err)
              cdev_sysfs_debugfs_add(hdev);
-     if (hdev->pdev)
-             dev_err(&hdev->pdev->dev,
-                     "Failed to initialize hl%d. Device %s is NOT usable !\n",
-                     hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
-     else
-             pr_err("Failed to initialize hl%d. Device %s is NOT usable !\n",
-                     hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
+     dev_err(&hdev->pdev->dev,
                 ^^^^^^^^^^^^^^^
Quoted 6 lines

drivers/accel/habanalabs/common/device.c int hl_device_init(struct hl_device *hdev) · line 2333

Quoted 2 lines
drivers/accel/habanalabs/common/device.c +2 -0
+             "Failed to initialize hl%d. Device %s is NOT usable !\n",
+             hdev->cdev_idx, dev_name(&(hdev)->pdev->dev));
                                         ^^^^^^^^^^^^^^^^^^^

I hate to be picky, but would it be too much to get rid of the parens around (hdev)?

Sure, np. I'll fix it before pushing it to the branch. Oded

Quoted 3 lines

regards,
dan carpenter

Reviewed-by on v1 4/4
#4 lore raw

Re: [PATCH 4/4] accel/habanalabs: move ioctl error print to debug level

In reply to Oded Gabbay
Quoted 31 lines · Oded Gabbay

We don't want to allow users to spam the kernel log and sending ioctls with bad opcodes is a sure way to do it.

---
  drivers/accel/habanalabs/common/habanalabs_ioctl.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/accel/habanalabs/common/habanalabs_ioctl.c +2 -2
index 9a8be9395fb2..6a45a92344e9 100644
@@ -1195,7 +1195,7 @@ static long _hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg,
 
  out_err:
  	if (retcode)
-		dev_dbg(dev, "error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n",
+		dev_dbg_ratelimited(dev, "error in ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n",
  			  task_pid_nr(current), cmd, nr);
 
  	if (kdata != stack_kdata)
@@ -1219,7 +1219,7 @@ long hl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  	if ((nr >= HL_COMMAND_START) && (nr < HL_COMMAND_END)) {
  		ioctl = &hl_ioctls[nr];
  	} else {
-		dev_err(hdev->dev, "invalid ioctl: pid=%d, nr=0x%02x\n",
+		dev_dbg_ratelimited(hdev->dev, "invalid ioctl: pid=%d, nr=0x%02x\n",
  			task_pid_nr(current), nr);
  		return -ENOTTY;
  	}

drivers/accel/habanalabs/common/habanalabs_ioctl.c long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg) · line 1248

Quoted 8 lines
drivers/accel/habanalabs/common/habanalabs_ioctl.c +1 -1
@@ -1242,7 +1242,7 @@ long hl_ioctl_control(struct file *filep, unsigned int cmd, unsigned long arg)
  	if (nr == _IOC_NR(HL_IOCTL_INFO)) {
  		ioctl = &hl_ioctls_control[nr];
  	} else {
-		dev_err(hdev->dev_ctrl, "invalid ioctl: pid=%d, nr=0x%02x\n",
+		dev_dbg_ratelimited(hdev->dev_ctrl, "invalid ioctl: pid=%d, nr=0x%02x\n",
  			task_pid_nr(current), nr);
  		return -ENOTTY;
  	}