habanalabs: advanced FW loading
authorOfir Bitton <obitton@habana.ai>
Tue, 20 Oct 2020 07:45:37 +0000 (10:45 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Mon, 30 Nov 2020 08:47:31 +0000 (10:47 +0200)
Today driver is able to load a whole FW binary into a specific
location on ASIC. We add support for loading sections from the
same FW binary into different loactions.

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/firmware_if.c
drivers/misc/habanalabs/common/habanalabs.h
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/goya/goya.c

index 1340afa..647606f 100644 (file)
  * @hdev: pointer to hl_device structure.
  * @fw_name: the firmware image name
  * @dst: IO memory mapped address space to copy firmware to
+ * @src_offset: offset in src FW to copy from
+ * @size: amount of bytes to copy (0 to copy the whole binary)
  *
  * Copy fw code from firmware file to device memory.
  *
  * Return: 0 on success, non-zero for failure.
  */
 int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
-                               void __iomem *dst)
+                               void __iomem *dst, u32 src_offset, u32 size)
 {
        const struct firmware *fw;
-       const u64 *fw_data;
+       const void *fw_data;
        size_t fw_size;
        int rc;
 
@@ -57,9 +59,20 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
                goto out;
        }
 
-       fw_data = (const u64 *) fw->data;
+       if (size - src_offset > fw_size) {
+               dev_err(hdev->dev,
+                       "size to copy(%u) and offset(%u) are invalid\n",
+                       size, src_offset);
+               rc = -EINVAL;
+               goto out;
+       }
+
+       if (size)
+               fw_size = size;
+
+       fw_data = (const void *) fw->data;
 
-       memcpy_toio(dst, fw_data, fw_size);
+       memcpy_toio(dst, fw_data + src_offset, fw_size);
 
 out:
        release_firmware(fw);
index d6eb5c6..7f1522b 100644 (file)
@@ -2028,7 +2028,7 @@ int hl_mmu_if_set_funcs(struct hl_device *hdev);
 void hl_mmu_v1_set_funcs(struct hl_device *hdev);
 
 int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
-                               void __iomem *dst);
+                               void __iomem *dst, u32 src_offset, u32 size);
 int hl_fw_send_pci_access_msg(struct hl_device *hdev, u32 opcode);
 int hl_fw_send_cpu_message(struct hl_device *hdev, u32 hw_queue_id, u32 *msg,
                                u16 len, u32 timeout, long *result);
index a60c434..ab8c946 100644 (file)
@@ -3529,7 +3529,7 @@ static int gaudi_load_firmware_to_device(struct hl_device *hdev)
 
        dst = hdev->pcie_bar[HBM_BAR_ID] + LINUX_FW_OFFSET;
 
-       return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst);
+       return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst, 0, 0);
 }
 
 static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)
@@ -3538,7 +3538,7 @@ static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)
 
        dst = hdev->pcie_bar[SRAM_BAR_ID] + BOOT_FIT_SRAM_OFFSET;
 
-       return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst);
+       return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst, 0, 0);
 }
 
 static void gaudi_read_device_fw_version(struct hl_device *hdev,
index 374881f..ec5dd15 100644 (file)
@@ -2315,7 +2315,7 @@ static int goya_load_firmware_to_device(struct hl_device *hdev)
 
        dst = hdev->pcie_bar[DDR_BAR_ID] + LINUX_FW_OFFSET;
 
-       return hl_fw_load_fw_to_device(hdev, GOYA_LINUX_FW_FILE, dst);
+       return hl_fw_load_fw_to_device(hdev, GOYA_LINUX_FW_FILE, dst, 0, 0);
 }
 
 /*
@@ -2332,7 +2332,7 @@ static int goya_load_boot_fit_to_device(struct hl_device *hdev)
 
        dst = hdev->pcie_bar[SRAM_CFG_BAR_ID] + BOOT_FIT_SRAM_OFFSET;
 
-       return hl_fw_load_fw_to_device(hdev, GOYA_BOOT_FIT_FILE, dst);
+       return hl_fw_load_fw_to_device(hdev, GOYA_BOOT_FIT_FILE, dst, 0, 0);
 }
 
 /*