mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oded Gabbay <ogabbay@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: farah kassabri <fkassabri@habana.ai>
Subject: [PATCH 07/20] habanalabs: fix firmware descriptor copy operation
Date: Thu, 17 Nov 2022 18:19:38 +0200	[thread overview]
Message-ID: <20221117161951.845454-7-ogabbay@kernel.org> (raw)
In-Reply-To: <20221117161951.845454-1-ogabbay@kernel.org>

From: farah kassabri <fkassabri@habana.ai>

This is needed to allow adding more data to the lkd_fw_comms_desc
structure.

Signed-off-by: farah kassabri <fkassabri@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
---
 drivers/misc/habanalabs/common/firmware_if.c | 26 ++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c
index f18e53bbba6b..01c4ffba6e97 100644
--- a/drivers/misc/habanalabs/common/firmware_if.c
+++ b/drivers/misc/habanalabs/common/firmware_if.c
@@ -12,6 +12,7 @@
 #include <linux/crc32.h>
 #include <linux/slab.h>
 #include <linux/ctype.h>
+#include <linux/vmalloc.h>
 
 #define FW_FILE_MAX_SIZE		0x1400000 /* maximum size of 20MB */
 
@@ -1988,10 +1989,11 @@ static int hl_fw_dynamic_read_and_validate_descriptor(struct hl_device *hdev,
 						struct fw_load_mgr *fw_loader)
 {
 	struct lkd_fw_comms_desc *fw_desc;
+	void __iomem *src, *temp_fw_desc;
 	struct pci_mem_region *region;
 	struct fw_response *response;
+	u16 fw_data_size;
 	enum pci_region region_id;
-	void __iomem *src;
 	int rc;
 
 	fw_desc = &fw_loader->dynamic_loader.comm_desc;
@@ -2018,9 +2020,29 @@ static int hl_fw_dynamic_read_and_validate_descriptor(struct hl_device *hdev,
 	fw_loader->dynamic_loader.fw_desc_valid = false;
 	src = hdev->pcie_bar[region->bar_id] + region->offset_in_bar +
 							response->ram_offset;
+
+	/*
+	 * We do the copy of the fw descriptor in 2 phases:
+	 * 1. copy the header + data info according to our lkd_fw_comms_desc definition.
+	 *    then we're able to read the actual data size provided by fw.
+	 *    this is needed for cases where data in descriptor was changed(add/remove)
+	 *    in embedded specs header file before updating lkd copy of the header file
+	 * 2. copy descriptor to temporary buffer with aligned size and send it to validation
+	 */
 	memcpy_fromio(fw_desc, src, sizeof(struct lkd_fw_comms_desc));
+	fw_data_size = le16_to_cpu(fw_desc->header.size);
+
+	temp_fw_desc = vzalloc(sizeof(struct comms_desc_header) + fw_data_size);
+	if (!temp_fw_desc)
+		return -ENOMEM;
+
+	memcpy_fromio(temp_fw_desc, src, sizeof(struct comms_desc_header) + fw_data_size);
 
-	return hl_fw_dynamic_validate_descriptor(hdev, fw_loader, fw_desc);
+	rc = hl_fw_dynamic_validate_descriptor(hdev, fw_loader,
+					(struct lkd_fw_comms_desc *) temp_fw_desc);
+	vfree(temp_fw_desc);
+
+	return rc;
 }
 
 /**
-- 
2.25.1


  parent reply	other threads:[~2022-11-17 16:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 16:19 [PATCH 01/20] habanalabs/gaudi2: add PCI revision 2 support Oded Gabbay
2022-11-17 16:19 ` [PATCH 02/20] habanalabs/gaudi: add razwi notify event Oded Gabbay
2022-11-17 16:19 ` [PATCH 03/20] habanalabs: use single threaded WQ for event handling Oded Gabbay
2022-11-17 16:19 ` [PATCH 04/20] habanalabs/gaudi: add page fault notify event Oded Gabbay
2022-11-17 16:19 ` [PATCH 05/20] habanalabs/gaudi2: implement fp32 not supported event Oded Gabbay
2022-11-17 16:19 ` [PATCH 06/20] habanalabs/gaudi2: add razwi notify event Oded Gabbay
2022-11-17 16:19 ` Oded Gabbay [this message]
2022-11-17 16:19 ` [PATCH 08/20] habanalabs: skip events info ioctl if not supported Oded Gabbay
2022-11-17 16:19 ` [PATCH 09/20] habanalabs/gaudi2: classify power/thermal events as info Oded Gabbay
2022-11-17 16:19 ` [PATCH 10/20] habanalabs/gaudi2: add page fault notify event Oded Gabbay
2022-11-17 16:19 ` [PATCH 11/20] habanalabs: fix print for out-of-sync and pkt-failure events Oded Gabbay
2022-11-17 16:19 ` [PATCH 12/20] habanalabs/gaudi: fix print for firmware-alive event Oded Gabbay
2022-11-17 16:19 ` [PATCH 13/20] habanalabs/gaudi2: remove redundant firmware version check Oded Gabbay
2022-11-17 16:19 ` [PATCH 14/20] habanalabs/gaudi2: don't enable entries in the MSIX_GW table Oded Gabbay
2022-11-17 16:19 ` [PATCH 15/20] habanalabs/gaudi2: return to reset upon SM SEI BRESP error Oded Gabbay
2022-11-17 16:19 ` [PATCH 16/20] habanalabs: reset device if still in use when released Oded Gabbay
2022-11-17 16:19 ` [PATCH 17/20] habanalabs: check schedule_hard_reset correctly Oded Gabbay
2022-11-17 16:19 ` [PATCH 18/20] habanalabs: extend process wait timeout in device fine Oded Gabbay
2022-11-17 16:19 ` [PATCH 19/20] habanalabs/gaudi2: change memory scrub mechanism Oded Gabbay
2022-11-17 16:19 ` [PATCH 20/20] habanalabs: increase the size of busy engines mask Oded Gabbay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221117161951.845454-7-ogabbay@kernel.org \
    --to=ogabbay@kernel.org \
    --cc=fkassabri@habana.ai \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®