From: Madhavan Ganesan <madhavan.ganesan@oss.qualcomm.com>
To: Jeff Johnson <jjohnson@kernel.org>
Cc: linux-wireless@vger.kernel.org, ath12k@lists.infradead.org,
linux-kernel@vger.kernel.org,
Madhavan Ganesan <madhavan.ganesan@oss.qualcomm.com>
Subject: [PATCH ath-next 2/2] wifi: ath12k: refactor m3 and aux_uc firmware memory handling
Date: Tue, 03 Nov 2026 22:56:01 +0530 [thread overview]
Message-ID: <20261103-m3_and_aux_ucode-v1-2-e14f13fdfa41@oss.qualcomm.com> (raw)
In-Reply-To: <20261103-m3_and_aux_ucode-v1-0-e14f13fdfa41@oss.qualcomm.com>
ath12k_qmi_m3_free()/ath12k_qmi_m3_load() and
ath12k_qmi_aux_uc_free()/ath12k_qmi_aux_uc_load() implement identical
logic for freeing a DMA-coherent firmware memory region and for
loading firmware into it (reuse existing buffer if large enough,
otherwise free and reallocate, falling back to a standalone firmware
file when no embedded data is present).
Factor the common logic into ath12k_qmi_free_mem_region() and
ath12k_qmi_fw_mem_load(), and have the m3 and aux_uc wrappers call
into them with the appropriate struct ath12k_fw_mem_region and
firmware file name. The shared free helper also clears paddr, which
the previous per-region implementations missed.
Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1
Signed-off-by: Madhavan Ganesan <madhavan.ganesan@oss.qualcomm.com>
---
drivers/net/wireless/ath/ath12k/qmi.c | 159 +++++++++++-----------------------
1 file changed, 52 insertions(+), 107 deletions(-)
diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index b1efed1702cb..ba9365d10180 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -3225,77 +3225,78 @@ int ath12k_qmi_load_bdf_qmi(struct ath12k_base *ab,
return ret;
}
-static void ath12k_qmi_m3_free(struct ath12k_base *ab)
+static void ath12k_qmi_free_mem_region(struct ath12k_base *ab,
+ struct ath12k_fw_mem_region *mem_region)
{
- struct ath12k_fw_mem_region *m3_mem = &ab->qmi.m3_mem;
-
- if (ab->hw_params->fw.m3_loader == ath12k_m3_fw_loader_remoteproc)
+ if (!mem_region->vaddr)
return;
- if (!m3_mem->vaddr)
+ dma_free_coherent(ab->dev, mem_region->total_size,
+ mem_region->vaddr, mem_region->paddr);
+ mem_region->vaddr = NULL;
+ mem_region->total_size = 0;
+ mem_region->size = 0;
+}
+
+static void ath12k_qmi_m3_free(struct ath12k_base *ab)
+{
+ if (ab->hw_params->fw.m3_loader == ath12k_m3_fw_loader_remoteproc)
return;
- dma_free_coherent(ab->dev, m3_mem->total_size,
- m3_mem->vaddr, m3_mem->paddr);
- m3_mem->vaddr = NULL;
- m3_mem->total_size = 0;
- m3_mem->size = 0;
+ ath12k_qmi_free_mem_region(ab, &ab->qmi.m3_mem);
}
-static int ath12k_qmi_m3_load(struct ath12k_base *ab)
+static int ath12k_qmi_fw_mem_load(struct ath12k_base *ab,
+ struct ath12k_fw_mem_region *mem_region,
+ const u8 *embedded_data, size_t embedded_len,
+ const char *filename)
{
- struct ath12k_fw_mem_region *m3_mem = &ab->qmi.m3_mem;
const struct firmware *fw = NULL;
- const void *m3_data;
+ const void *data;
char path[100];
- size_t m3_len;
+ size_t len;
int ret;
- if (ab->fw.m3_data && ab->fw.m3_len > 0) {
- /* firmware-N.bin had a m3 firmware file so use that */
- m3_data = ab->fw.m3_data;
- m3_len = ab->fw.m3_len;
+ if (embedded_data && embedded_len > 0) {
+ data = embedded_data;
+ len = embedded_len;
} else {
- /* No m3 file in firmware-N.bin so try to request old
- * separate m3.bin.
- */
- fw = ath12k_core_firmware_request(ab, ATH12K_M3_FILE);
+ fw = ath12k_core_firmware_request(ab, filename);
if (IS_ERR(fw)) {
ret = PTR_ERR(fw);
- ath12k_core_create_firmware_path(ab, ATH12K_M3_FILE,
+ ath12k_core_create_firmware_path(ab, filename,
path, sizeof(path));
ath12k_err(ab, "failed to load %s: %d\n", path, ret);
return ret;
}
- m3_data = fw->data;
- m3_len = fw->size;
+ data = fw->data;
+ len = fw->size;
}
- /* In recovery/resume cases, M3 buffer is not freed, try to reuse that */
- if (m3_mem->vaddr) {
- if (m3_mem->total_size >= m3_len)
- goto skip_m3_alloc;
+ /* In recovery/resume cases, buffer is not freed, try to reuse that */
+ if (mem_region->vaddr) {
+ if (mem_region->total_size >= len)
+ goto skip_alloc;
/* Old buffer is too small, free and reallocate */
- ath12k_qmi_m3_free(ab);
+ ath12k_qmi_free_mem_region(ab, mem_region);
}
- m3_mem->vaddr = dma_alloc_coherent(ab->dev,
- m3_len, &m3_mem->paddr,
- GFP_KERNEL);
- if (!m3_mem->vaddr) {
- ath12k_err(ab, "failed to allocate memory for M3 with size %zu\n",
- m3_len);
+ mem_region->vaddr = dma_alloc_coherent(ab->dev, len, &mem_region->paddr,
+ GFP_KERNEL);
+ if (!mem_region->vaddr) {
+ ath12k_err(ab, "failed to allocate memory for %s with size %zu\n",
+ filename, len);
ret = -ENOMEM;
goto out;
}
- m3_mem->total_size = m3_len;
+ mem_region->total_size = len;
-skip_m3_alloc:
- memcpy(m3_mem->vaddr, m3_data, m3_len);
- m3_mem->size = m3_len;
+skip_alloc:
+ memcpy(mem_region->vaddr, data, len);
+ mem_region->size = len;
ret = 0;
@@ -3305,6 +3306,13 @@ static int ath12k_qmi_m3_load(struct ath12k_base *ab)
return ret;
}
+static int ath12k_qmi_m3_load(struct ath12k_base *ab)
+{
+ return ath12k_qmi_fw_mem_load(ab, &ab->qmi.m3_mem,
+ ab->fw.m3_data, ab->fw.m3_len,
+ ATH12K_M3_FILE);
+}
+
/* clang stack usage explodes if this is inlined */
static noinline_for_stack
int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab)
@@ -3359,77 +3367,14 @@ int ath12k_qmi_wlanfw_m3_info_send(struct ath12k_base *ab)
static void ath12k_qmi_aux_uc_free(struct ath12k_base *ab)
{
- struct ath12k_fw_mem_region *aux_uc_mem = &ab->qmi.aux_uc_mem;
-
- if (!aux_uc_mem->vaddr)
- return;
-
- dma_free_coherent(ab->dev, aux_uc_mem->total_size,
- aux_uc_mem->vaddr, aux_uc_mem->paddr);
- aux_uc_mem->vaddr = NULL;
- aux_uc_mem->total_size = 0;
- aux_uc_mem->size = 0;
+ ath12k_qmi_free_mem_region(ab, &ab->qmi.aux_uc_mem);
}
static int ath12k_qmi_aux_uc_load(struct ath12k_base *ab)
{
- struct ath12k_fw_mem_region *aux_uc_mem = &ab->qmi.aux_uc_mem;
- const struct firmware *fw = NULL;
- const void *aux_uc_data;
- char path[100];
- size_t aux_uc_len;
- int ret;
-
- if (ab->fw.aux_uc_data && ab->fw.aux_uc_len > 0) {
- /* firmware-N.bin had a aux_uc firmware file so use that */
- aux_uc_data = ab->fw.aux_uc_data;
- aux_uc_len = ab->fw.aux_uc_len;
- } else {
- /*
- * No aux_uc file in firmware-N.bin so try to request old
- * separate aux_ucode.bin.
- */
- fw = ath12k_core_firmware_request(ab, ATH12K_AUX_UC_FILE);
- if (IS_ERR(fw)) {
- ret = PTR_ERR(fw);
- ath12k_core_create_firmware_path(ab, ATH12K_AUX_UC_FILE,
- path, sizeof(path));
- ath12k_err(ab, "failed to load %s: %d\n", path, ret);
- return ret;
- }
-
- aux_uc_data = fw->data;
- aux_uc_len = fw->size;
- }
-
- /* In recovery/resume cases, AUX_UC buffer is not freed, try to reuse that */
- if (aux_uc_mem->vaddr) {
- if (aux_uc_mem->total_size >= aux_uc_len)
- goto copy;
-
- /* Old buffer is too small, free and reallocate */
- ath12k_qmi_aux_uc_free(ab);
- }
-
- aux_uc_mem->vaddr = dma_alloc_coherent(ab->dev, aux_uc_len,
- &aux_uc_mem->paddr, GFP_KERNEL);
- if (!aux_uc_mem->vaddr) {
- ret = -ENOMEM;
- goto out;
- }
-
- aux_uc_mem->total_size = aux_uc_len;
-
-copy:
- memcpy(aux_uc_mem->vaddr, aux_uc_data, aux_uc_len);
- aux_uc_mem->size = aux_uc_len;
-
- ret = 0;
-
-out:
- release_firmware(fw);
-
- return ret;
+ return ath12k_qmi_fw_mem_load(ab, &ab->qmi.aux_uc_mem,
+ ab->fw.aux_uc_data, ab->fw.aux_uc_len,
+ ATH12K_AUX_UC_FILE);
}
static noinline_for_stack
--
2.34.1
prev parent reply other threads:[~2026-11-03 17:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 17:25 [PATCH ath-next 0/2] wifi: ath12k: refactor m3/aux_uc " Madhavan Ganesan
2026-11-03 17:26 ` [PATCH ath-next 1/2] wifi: ath12k: rename m3_mem_region to ath12k_fw_mem_region Madhavan Ganesan
2026-11-03 17:26 ` Madhavan Ganesan [this message]
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=20261103-m3_and_aux_ucode-v1-2-e14f13fdfa41@oss.qualcomm.com \
--to=madhavan.ganesan@oss.qualcomm.com \
--cc=ath12k@lists.infradead.org \
--cc=jjohnson@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@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®