habanalabs: enable device before hw_init()
authorOded Gabbay <oded.gabbay@gmail.com>
Wed, 15 Jul 2020 18:59:32 +0000 (21:59 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Fri, 24 Jul 2020 17:31:37 +0000 (20:31 +0300)
Device is now enabled before the hw_init() because part of the
initialization requires communication with the device firmware to get
information that is required for the initialization itself

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Reviewed-by: Tomer Tayar <ttayar@habana.ai>
drivers/misc/habanalabs/common/device.c
drivers/misc/habanalabs/common/sysfs.c

index 84800efec10d032bf224c88513c17eeaee950f71..9919ff121067188ab08d2c74ba5cadf491624e3a 100644 (file)
@@ -1033,6 +1033,12 @@ again:
                }
        }
 
+       /* Device is now enabled as part of the initialization requires
+        * communication with the device firmware to get information that
+        * is required for the initialization itself
+        */
+       hdev->disabled = false;
+
        rc = hdev->asic_funcs->hw_init(hdev);
        if (rc) {
                dev_err(hdev->dev,
@@ -1040,8 +1046,6 @@ again:
                goto out_err;
        }
 
-       hdev->disabled = false;
-
        /* Check that the communication with the device is working */
        rc = hdev->asic_funcs->test_queues(hdev);
        if (rc) {
@@ -1261,6 +1265,12 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
         */
        add_cdev_sysfs_on_err = true;
 
+       /* Device is now enabled as part of the initialization requires
+        * communication with the device firmware to get information that
+        * is required for the initialization itself
+        */
+       hdev->disabled = false;
+
        rc = hdev->asic_funcs->hw_init(hdev);
        if (rc) {
                dev_err(hdev->dev, "failed to initialize the H/W\n");
@@ -1268,8 +1278,6 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)
                goto out_disabled;
        }
 
-       hdev->disabled = false;
-
        /* Check that the communication with the device is working */
        rc = hdev->asic_funcs->test_queues(hdev);
        if (rc) {
index 5d78d5e1c7826163601cacdd12bac6a1a87e4e3e..c4e7c682d58482ca85e64416d5d478d9d294f8ca 100644 (file)
@@ -334,6 +334,9 @@ static ssize_t eeprom_read_handler(struct file *filp, struct kobject *kobj,
        char *data;
        int rc;
 
+       if (hl_device_disabled_or_in_reset(hdev))
+               return -ENODEV;
+
        if (!max_size)
                return -EINVAL;