[PATCH ath-next v2 02/15] wifi: ath12k: refactor PCI window selection to per-device layout

From: Madhavan Ganesan

Date: Wed Nov 18 2026 - 01:19:45 EST


ath12k currently assumes a fixed PCI/AHB window layout with value bits
[24:19], CE shift 6, and UMAC shift 12. Those values match Wi-Fi 7, but
QCN9575 uses a different window field and shift layout. With fixed
values, ath12k programs an incorrect window and breaks register access.

Move window layout parameters into struct ath12k_pci_reg_base and
struct ath12k_ahb_reg_base, and use them in ath12k_pci_select_window(),
ath12k_pci_select_static_window(), ath12k_pcic_config_static_window(),
and ath12k_pcic_select_static_window(). Set the Wi-Fi 7 values in
ath12k_wifi7_reg_base and ath12k_wifi7_ahb_reg_base so each device
family provides its own window mapping for both the PCI and AHB bus
paths. Move the window register address into struct ath12k_ahb as
window_reg_addr, mirroring the existing per-device window_reg_addr in
struct ath12k_pci. Replace the open-coded u32_get_bits() calls that
assumed the fixed WINDOW_VALUE_MASK constant with field_get() and
field_prep() using the per-device masks. Remove the now-unused
WINDOW_VALUE_MASK and WINDOW_STATIC_MASK constants from the common
pci.h and move the Wi-Fi 7 window constants into wifi7/pci.h.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3

Signed-off-by: Madhavan Ganesan <madhavan.ganesan@xxxxxxxxxxxxxxxx>
---
drivers/net/wireless/ath/ath12k/ahb.h | 6 ++++++
drivers/net/wireless/ath/ath12k/pci.c | 15 +++++++++------
drivers/net/wireless/ath/ath12k/pci.h | 8 ++++----
drivers/net/wireless/ath/ath12k/pcic.c | 27 +++++++++++++++++----------
drivers/net/wireless/ath/ath12k/wifi7/ahb.c | 6 ++++++
drivers/net/wireless/ath/ath12k/wifi7/pci.c | 4 ++++
drivers/net/wireless/ath/ath12k/wifi7/pci.h | 8 ++++++++
7 files changed, 54 insertions(+), 20 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/ahb.h b/drivers/net/wireless/ath/ath12k/ahb.h
index 373dc3b92728..712fddb03f6a 100644
--- a/drivers/net/wireless/ath/ath12k/ahb.h
+++ b/drivers/net/wireless/ath/ath12k/ahb.h
@@ -14,6 +14,10 @@
struct ath12k_ahb_reg_base {
u32 umac_base;
u32 ce_reg_base;
+ u32 window_value_mask;
+ u32 window_static_mask;
+ u32 ce_window_mask;
+ u32 umac_window_mask;
};

#define ATH12K_AHB_RECOVERY_TIMEOUT (3 * HZ)
@@ -111,6 +115,8 @@ struct ath12k_ahb {
bool supports_multipd;
u32 static_window_reg;
const struct ath12k_ahb_reg_base *reg_base;
+
+ u32 window_reg_addr;
};

struct ath12k_ahb_driver {
diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c
index 4bb14a95aec9..6617440954b1 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -125,14 +125,15 @@ static const char *irq_name[ATH12K_IRQ_NUM_MAX] = {
static void ath12k_pci_select_window(struct ath12k_pci *ab_pci, u32 offset)
{
struct ath12k_base *ab = ab_pci->ab;
-
- u32 window = u32_get_bits(offset, WINDOW_VALUE_MASK);
u32 static_window;
+ u32 window;

lockdep_assert_held(&ab_pci->window_lock);

+ window = field_get(ab_pci->reg_base->window_value_mask, offset);
+
/* Preserve the static window configuration and reset only dynamic window */
- static_window = ab_pci->register_window & WINDOW_STATIC_MASK;
+ static_window = ab_pci->register_window & ab_pci->reg_base->window_static_mask;
window |= static_window;

if (window != ab_pci->register_window) {
@@ -145,13 +146,15 @@ static void ath12k_pci_select_window(struct ath12k_pci *ab_pci, u32 offset)

static void ath12k_pci_select_static_window(struct ath12k_pci *ab_pci)
{
+ const struct ath12k_pci_reg_base *reg_base = ab_pci->reg_base;
u32 umac_window;
u32 ce_window;
u32 window;

- umac_window = u32_get_bits(ab_pci->reg_base->umac_base, WINDOW_VALUE_MASK);
- ce_window = u32_get_bits(ab_pci->reg_base->ce_reg_base, WINDOW_VALUE_MASK);
- window = (umac_window << 12) | (ce_window << 6);
+ umac_window = field_get(reg_base->window_value_mask, reg_base->umac_base);
+ ce_window = field_get(reg_base->window_value_mask, reg_base->ce_reg_base);
+ window = field_prep(reg_base->umac_window_mask, umac_window) |
+ field_prep(reg_base->ce_window_mask, ce_window);

spin_lock_bh(&ab_pci->window_lock);
ab_pci->register_window = window;
diff --git a/drivers/net/wireless/ath/ath12k/pci.h b/drivers/net/wireless/ath/ath12k/pci.h
index 55cc875f9ce0..62b72558c0e2 100644
--- a/drivers/net/wireless/ath/ath12k/pci.h
+++ b/drivers/net/wireless/ath/ath12k/pci.h
@@ -77,12 +77,8 @@
#define QRTR_PCI_BUS_NUMBER_MASK GENMASK(3, 0)

#define WINDOW_ENABLE_BIT 0x40000000
-#define WINDOW_REG_ADDRESS 0x310c
-#define WINDOW_REG_ADDRESS_QCC2072 0x3278
-#define WINDOW_VALUE_MASK GENMASK(24, 19)
#define WINDOW_START 0x80000
#define WINDOW_RANGE_MASK GENMASK(18, 0)
-#define WINDOW_STATIC_MASK GENMASK(31, 6)

struct ath12k_msi_user {
const char *name;
@@ -118,6 +114,10 @@ struct ath12k_pci_device_family_ops {
struct ath12k_pci_reg_base {
u32 umac_base;
u32 ce_reg_base;
+ u32 window_value_mask;
+ u32 window_static_mask;
+ u32 ce_window_mask;
+ u32 umac_window_mask;
};

struct ath12k_pci {
diff --git a/drivers/net/wireless/ath/ath12k/pcic.c b/drivers/net/wireless/ath/ath12k/pcic.c
index b6d306fd3b99..c10e21d68830 100644
--- a/drivers/net/wireless/ath/ath12k/pcic.c
+++ b/drivers/net/wireless/ath/ath12k/pcic.c
@@ -15,13 +15,19 @@
void ath12k_pcic_config_static_window(struct ath12k_base *ab)
{
struct ath12k_ahb *ab_ahb = ath12k_ab_to_ahb(ab);
- u32 umac_window = u32_get_bits(ab_ahb->reg_base->umac_base, WINDOW_VALUE_MASK);
- u32 ce_window = u32_get_bits(ab_ahb->reg_base->ce_reg_base, WINDOW_VALUE_MASK);
+ const struct ath12k_ahb_reg_base *reg_base;
+ u32 umac_window;
+ u32 ce_window;
u32 window;

- window = (umac_window << 12) | (ce_window << 6);
- writel_relaxed(WINDOW_ENABLE_BIT | window, ab->mem + WINDOW_REG_ADDRESS);
- ab_ahb->static_window_reg = readl_relaxed(ab->mem + WINDOW_REG_ADDRESS);
+ reg_base = ab_ahb->reg_base;
+ umac_window = field_get(reg_base->window_value_mask, reg_base->umac_base);
+ ce_window = field_get(reg_base->window_value_mask, reg_base->ce_reg_base);
+ window = field_prep(reg_base->umac_window_mask, umac_window) |
+ field_prep(reg_base->ce_window_mask, ce_window);
+
+ writel_relaxed(WINDOW_ENABLE_BIT | window, ab->mem + ab_ahb->window_reg_addr);
+ ab_ahb->static_window_reg = readl_relaxed(ab->mem + ab_ahb->window_reg_addr);
}

static int ath12k_pcic_select_static_window(struct ath12k_base *ab, u32 addr)
@@ -32,20 +38,21 @@ static int ath12k_pcic_select_static_window(struct ath12k_base *ab, u32 addr)
const int max_retries = 10;
int i;

- window_bits = u32_get_bits(addr, WINDOW_VALUE_MASK);
+ window_bits = field_get(ab_ahb->reg_base->window_value_mask, addr);

- /* Update window bits [5:0], preserving other bits */
- new_window = u32_replace_bits(ab_ahb->static_window_reg, window_bits, 0x3f);
+ /* Update the dynamic window bits, preserving the static window configuration */
+ new_window = u32_replace_bits(ab_ahb->static_window_reg, window_bits,
+ ~ab_ahb->reg_base->window_static_mask);

if (new_window == ab_ahb->static_window_reg)
return 0;

reg_value = WINDOW_ENABLE_BIT | new_window;
- writel_relaxed(reg_value, ab->mem + WINDOW_REG_ADDRESS);
+ writel_relaxed(reg_value, ab->mem + ab_ahb->window_reg_addr);

/* Wait for the write to take effect */
for (i = 0; i < max_retries; i++) {
- if (readl_relaxed(ab->mem + WINDOW_REG_ADDRESS) == reg_value) {
+ if (readl_relaxed(ab->mem + ab_ahb->window_reg_addr) == reg_value) {
ab_ahb->static_window_reg = reg_value;
return 0;
}
diff --git a/drivers/net/wireless/ath/ath12k/wifi7/ahb.c b/drivers/net/wireless/ath/ath12k/wifi7/ahb.c
index ae5380eb6f8f..8552f403864e 100644
--- a/drivers/net/wireless/ath/ath12k/wifi7/ahb.c
+++ b/drivers/net/wireless/ath/ath12k/wifi7/ahb.c
@@ -15,6 +15,7 @@
#include "dp.h"
#include "core.h"
#include "hal.h"
+#include "pci.h"

static const struct ath12k_ahb_userpd_map ath12k_wifi7_ahb_userpd_map[] = {
{ .io_start = 0x0c000000, .upd_id = ATH12K_AHB_USERPD_ID_0 },
@@ -91,6 +92,7 @@ static int ath12k_wifi7_ahb_probe(struct platform_device *pdev)
if (!desc)
return -EOPNOTSUPP;

+ ab_ahb->window_reg_addr = WINDOW_REG_ADDRESS;
ab->target_mem_mode = ATH12K_QMI_MEMORY_MODE_DEFAULT;
ab->hw_rev = desc->hw_rev;
ab->hif.ops = desc->ops;
@@ -112,6 +114,10 @@ static int ath12k_wifi7_ahb_probe(struct platform_device *pdev)
static const struct ath12k_ahb_reg_base ath12k_wifi7_ahb_reg_base = {
.umac_base = HAL_SEQ_WCSS_UMAC_OFFSET,
.ce_reg_base = HAL_CE_WFSS_CE_REG_BASE,
+ .window_value_mask = WINDOW_VALUE_MASK,
+ .window_static_mask = WINDOW_STATIC_MASK,
+ .ce_window_mask = CE_WINDOW_MASK,
+ .umac_window_mask = UMAC_WINDOW_MASK,
};

static struct ath12k_ahb_driver ath12k_wifi7_ahb_driver = {
diff --git a/drivers/net/wireless/ath/ath12k/wifi7/pci.c b/drivers/net/wireless/ath/ath12k/wifi7/pci.c
index 783c5d020f07..6dc674e045be 100644
--- a/drivers/net/wireless/ath/ath12k/wifi7/pci.c
+++ b/drivers/net/wireless/ath/ath12k/wifi7/pci.c
@@ -167,6 +167,10 @@ static int ath12k_wifi7_pci_probe(struct pci_dev *pdev,
static const struct ath12k_pci_reg_base ath12k_wifi7_reg_base = {
.umac_base = HAL_SEQ_WCSS_UMAC_OFFSET,
.ce_reg_base = HAL_CE_WFSS_CE_REG_BASE,
+ .window_value_mask = WINDOW_VALUE_MASK,
+ .window_static_mask = WINDOW_STATIC_MASK,
+ .ce_window_mask = CE_WINDOW_MASK,
+ .umac_window_mask = UMAC_WINDOW_MASK,
};

static struct ath12k_pci_driver ath12k_wifi7_pci_driver = {
diff --git a/drivers/net/wireless/ath/ath12k/wifi7/pci.h b/drivers/net/wireless/ath/ath12k/wifi7/pci.h
index 662a8bab0ce7..1017975b4c9f 100644
--- a/drivers/net/wireless/ath/ath12k/wifi7/pci.h
+++ b/drivers/net/wireless/ath/ath12k/wifi7/pci.h
@@ -6,6 +6,14 @@
#ifndef ATH12K_PCI_WIFI7_H
#define ATH12K_PCI_WIFI7_H

+#define WINDOW_REG_ADDRESS 0x310c
+#define WINDOW_REG_ADDRESS_QCC2072 0x3278
+
+#define WINDOW_VALUE_MASK GENMASK(24, 19)
+#define WINDOW_STATIC_MASK GENMASK(31, 6)
+#define CE_WINDOW_MASK GENMASK(11, 6)
+#define UMAC_WINDOW_MASK GENMASK(17, 12)
+
int ath12k_wifi7_pci_init(void);
void ath12k_wifi7_pci_exit(void);


--
2.34.1