habanalabs: allow control device open during reset
authorOfir Bitton <obitton@habana.ai>
Tue, 23 Aug 2022 12:14:14 +0000 (15:14 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Wed, 23 Nov 2022 14:13:39 +0000 (16:13 +0200)
Monitoring apps would like to query device state at any time so we
should allow it also during reset because it doesn't involve
accessing the h/w.

Signed-off-by: Ofir Bitton <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/common/device.c
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/common/habanalabs_drv.c

index 233d8b4..1aaaa20 100644 (file)
@@ -355,6 +355,28 @@ bool hl_device_operational(struct hl_device *hdev,
        }
 }
 
+bool hl_ctrl_device_operational(struct hl_device *hdev,
+               enum hl_device_status *status)
+{
+       enum hl_device_status current_status;
+
+       current_status = hl_device_status(hdev);
+       if (status)
+               *status = current_status;
+
+       switch (current_status) {
+       case HL_DEVICE_STATUS_MALFUNCTION:
+               return false;
+       case HL_DEVICE_STATUS_IN_RESET:
+       case HL_DEVICE_STATUS_IN_RESET_AFTER_DEVICE_RELEASE:
+       case HL_DEVICE_STATUS_NEEDS_RESET:
+       case HL_DEVICE_STATUS_OPERATIONAL:
+       case HL_DEVICE_STATUS_IN_DEVICE_CREATION:
+       default:
+               return true;
+       }
+}
+
 static void hpriv_release(struct kref *ref)
 {
        u64 idle_mask[HL_BUSY_ENGINES_MASK_EXT_SIZE] = {0};
index 58c95b1..2ffb837 100644 (file)
@@ -3496,6 +3496,8 @@ int hl_device_open(struct inode *inode, struct file *filp);
 int hl_device_open_ctrl(struct inode *inode, struct file *filp);
 bool hl_device_operational(struct hl_device *hdev,
                enum hl_device_status *status);
+bool hl_ctrl_device_operational(struct hl_device *hdev,
+               enum hl_device_status *status);
 enum hl_device_status hl_device_status(struct hl_device *hdev);
 int hl_device_set_debug_mode(struct hl_device *hdev, struct hl_ctx *ctx, bool enable);
 int hl_hw_queues_create(struct hl_device *hdev);
index 112632a..3ee44ea 100644 (file)
@@ -270,9 +270,9 @@ int hl_device_open_ctrl(struct inode *inode, struct file *filp)
 
        mutex_lock(&hdev->fpriv_ctrl_list_lock);
 
-       if (!hl_device_operational(hdev, NULL)) {
+       if (!hl_ctrl_device_operational(hdev, NULL)) {
                dev_dbg_ratelimited(hdev->dev_ctrl,
-                       "Can't open %s because it is disabled or in reset\n",
+                       "Can't open %s because it is disabled\n",
                        dev_name(hdev->dev_ctrl));
                rc = -EPERM;
                goto out_err;