[PATCH AUTOSEL 5.18 30/56] habanalabs/gaudi: invoke device reset from one code block

From: Sasha Levin
Date: Sun Aug 14 2022 - 11:38:50 EST


From: Tal Cohen <talcohen@xxxxxxxxx>

[ Upstream commit be572e67dafbf8004d46a2c9d97338c107efb60e ]

In order to prepare the driver code for device reset event
notification, change the event handler function flow to call
device reset from one code block.

In addition, the commit fixes an issue that reset was performed
w/o checking the 'hard_reset_on_fw_event' state and w/o setting
the HL_DRV_RESET_DELAY flag.

Signed-off-by: Tal Cohen <talcohen@xxxxxxxxx>
Reviewed-by: Oded Gabbay <ogabbay@xxxxxxxxxx>
Signed-off-by: Oded Gabbay <ogabbay@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/misc/habanalabs/gaudi/gaudi.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c
index 1c271edb9297..90b769114fea 100644
--- a/drivers/misc/habanalabs/gaudi/gaudi.c
+++ b/drivers/misc/habanalabs/gaudi/gaudi.c
@@ -7942,10 +7942,10 @@ static void gaudi_handle_eqe(struct hl_device *hdev,
struct gaudi_device *gaudi = hdev->asic_specific;
u64 data = le64_to_cpu(eq_entry->data[0]);
u32 ctl = le32_to_cpu(eq_entry->hdr.ctl);
- u32 fw_fatal_err_flag = 0;
+ u32 fw_fatal_err_flag = 0, flags = 0;
u16 event_type = ((ctl & EQ_CTL_EVENT_TYPE_MASK)
>> EQ_CTL_EVENT_TYPE_SHIFT);
- bool reset_required;
+ bool reset_required, reset_direct = false;
u8 cause;
int rc;

@@ -8033,7 +8033,8 @@ static void gaudi_handle_eqe(struct hl_device *hdev,
dev_err(hdev->dev, "reset required due to %s\n",
gaudi_irq_map_table[event_type].name);

- hl_device_reset(hdev, 0);
+ reset_direct = true;
+ goto reset_device;
} else {
hl_fw_unmask_irq(hdev, event_type);
}
@@ -8055,7 +8056,8 @@ static void gaudi_handle_eqe(struct hl_device *hdev,
dev_err(hdev->dev, "reset required due to %s\n",
gaudi_irq_map_table[event_type].name);

- hl_device_reset(hdev, 0);
+ reset_direct = true;
+ goto reset_device;
} else {
hl_fw_unmask_irq(hdev, event_type);
}
@@ -8194,12 +8196,17 @@ static void gaudi_handle_eqe(struct hl_device *hdev,
return;

reset_device:
- if (hdev->asic_prop.fw_security_enabled)
- hl_device_reset(hdev, HL_DRV_RESET_HARD
- | HL_DRV_RESET_BYPASS_REQ_TO_FW
- | fw_fatal_err_flag);
+ reset_required = true;
+
+ if (hdev->asic_prop.fw_security_enabled && !reset_direct)
+ flags = HL_DRV_RESET_HARD | HL_DRV_RESET_BYPASS_REQ_TO_FW | fw_fatal_err_flag;
else if (hdev->hard_reset_on_fw_events)
- hl_device_reset(hdev, HL_DRV_RESET_HARD | HL_DRV_RESET_DELAY | fw_fatal_err_flag);
+ flags = HL_DRV_RESET_HARD | HL_DRV_RESET_DELAY | fw_fatal_err_flag;
+ else
+ reset_required = false;
+
+ if (reset_required)
+ hl_device_reset(hdev, flags);
else
hl_fw_unmask_irq(hdev, event_type);
}
--
2.35.1