summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOhad Sharabi <osharabi@habana.ai>2021-04-08 10:22:17 +0300
committerOded Gabbay <ogabbay@kernel.org>2021-06-18 15:23:38 +0300
commit364690429a603ac4a7e8df3c3b98b51c914c7c3f (patch)
tree1e28e988170aefa58e448986bb96e143c3638878
parent6e16ab6c326cd149c086ccbab6da9ccff1a528ff (diff)
downloadlinux-stable-364690429a603ac4a7e8df3c3b98b51c914c7c3f.tar.gz
linux-stable-364690429a603ac4a7e8df3c3b98b51c914c7c3f.tar.bz2
linux-stable-364690429a603ac4a7e8df3c3b98b51c914c7c3f.zip
habanalabs: request f/w in separate function
This refactor is needed due to the dynamic FW load in which requesting the FW file (and getting its attributes) is not immediately followed by copying FW file content. Signed-off-by: Ohad Sharabi <osharabi@habana.ai> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
-rw-r--r--drivers/misc/habanalabs/common/firmware_if.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
index a45aea4730cf..af9fbebabbfe 100644
--- a/drivers/misc/habanalabs/common/firmware_if.c
+++ b/drivers/misc/habanalabs/common/firmware_if.c
@@ -12,6 +12,47 @@
#include <linux/slab.h>
#define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */
+
+static int hl_request_fw(struct hl_device *hdev,
+ const struct firmware **firmware_p,
+ const char *fw_name)
+{
+ size_t fw_size;
+ int rc;
+
+ rc = request_firmware(firmware_p, fw_name, hdev->dev);
+ if (rc) {
+ dev_err(hdev->dev, "Firmware file %s is not found! (error %d)\n",
+ fw_name, rc);
+ goto out;
+ }
+
+ fw_size = (*firmware_p)->size;
+ if ((fw_size % 4) != 0) {
+ dev_err(hdev->dev, "Illegal %s firmware size %zu\n",
+ fw_name, fw_size);
+ rc = -EINVAL;
+ goto release_fw;
+ }
+
+ dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
+
+ if (fw_size > FW_FILE_MAX_SIZE) {
+ dev_err(hdev->dev,
+ "FW file size %zu exceeds maximum of %u bytes\n",
+ fw_size, FW_FILE_MAX_SIZE);
+ rc = -EINVAL;
+ goto release_fw;
+ }
+
+ return 0;
+
+release_fw:
+ release_firmware(*firmware_p);
+out:
+ return rc;
+}
+
/**
* hl_fw_load_fw_to_device() - Load F/W code to device's memory.
*
@@ -33,29 +74,11 @@ int hl_fw_load_fw_to_device(struct hl_device *hdev, const char *fw_name,
size_t fw_size;
int rc;
- rc = request_firmware(&fw, fw_name, hdev->dev);
- if (rc) {
- dev_err(hdev->dev, "Firmware file %s is not found!\n", fw_name);
- goto out;
- }
+ rc = hl_request_fw(hdev, &fw, fw_name);
+ if (rc)
+ return rc;
fw_size = fw->size;
- if ((fw_size % 4) != 0) {
- dev_err(hdev->dev, "Illegal %s firmware size %zu\n",
- fw_name, fw_size);
- rc = -EINVAL;
- goto out;
- }
-
- dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
-
- if (fw_size > FW_FILE_MAX_SIZE) {
- dev_err(hdev->dev,
- "FW file size %zu exceeds maximum of %u bytes\n",
- fw_size, FW_FILE_MAX_SIZE);
- rc = -EINVAL;
- goto out;
- }
if (size - src_offset > fw_size) {
dev_err(hdev->dev,