From: Josef Schlehofer <pepe.schlehofer@gmail.com>
To: Jeff Johnson <jjohnson@kernel.org>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH ath-next 6/9] wifi: ath6kl: take the AR6006 MAC address from DT
Date: Mon, 30 Nov 2026 10:50:39 +0100 [thread overview]
Message-ID: <20261130095042.41330-7-pepe.schlehofer@gmail.com> (raw)
In-Reply-To: <20261130095042.41330-1-pepe.schlehofer@gmail.com>
The AR6006 board data carries a default MAC address. On the Xiaomi
AIoT AC2350 it is the Atheros default 00:03:7f:20:01:42, so the real
address has to come from the board. Qualcomm's ath6kl-3.5 driver takes
it from a module parameter and writes it into the board data.
Read the address once at probe with of_get_mac_address() from the node
of the USB device, so mac-address, local-mac-address and nvmem cells
work. This happens before any firmware is loaded, so a deferred probe
frees everything on the existing error path. A missing node or
property is not an error, and neither is a kernel without nvmem
support. Other errors are logged and the board data default stays.
Write the address into the board data before the upload, also on
resume and recovery. The MAC sits at offset 8. The checksum at offset
4 is the inverted XOR of all little-endian 16-bit words of the
uploaded board data. Also set the option that keeps the firmware from
taking the MAC from OTP, as the vendor driver does.
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
On the router the address came from local-mac-address in one run and
from an nvmem cell in another, both added at runtime to the node of
the USB port, and the firmware used it. With nvmem-cells pointing at a
node that is no nvmem provider, the probe was deferred and left no
netdev. After the node got local-mac-address again, reloading the
driver probed the chip without a reset in between and booted the
firmware. Resume and recovery did not run.
drivers/net/wireless/ath/ath6kl/core.c | 5 ++
drivers/net/wireless/ath/ath6kl/core.h | 4 ++
drivers/net/wireless/ath/ath6kl/init.c | 77 ++++++++++++++++++++++++++
drivers/net/wireless/ath/ath6kl/usb.c | 3 +-
4 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/ath6kl/core.c b/drivers/net/wireless/ath/ath6kl/core.c
index 9762de89e..792a8b1f8 100644
--- a/drivers/net/wireless/ath/ath6kl/core.c
+++ b/drivers/net/wireless/ath/ath6kl/core.c
@@ -110,6 +110,11 @@ int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
if (ret)
goto err_power_off;
+ /* before any firmware is loaded, so a deferred probe leaks nothing */
+ ret = ath6kl_init_read_dt_mac(ar);
+ if (ret)
+ goto err_power_off;
+
ar->htc_target = ath6kl_htc_create(ar);
if (!ar->htc_target) {
diff --git a/drivers/net/wireless/ath/ath6kl/core.h b/drivers/net/wireless/ath/ath6kl/core.h
index da85c8dfb..d9b12dacc 100644
--- a/drivers/net/wireless/ath/ath6kl/core.h
+++ b/drivers/net/wireless/ath/ath6kl/core.h
@@ -716,6 +716,9 @@ struct ath6kl {
struct ieee80211_channel channels_2ghz[ATH6KL_NUM_2GHZ_CHANNELS];
struct ieee80211_channel channels_5ghz[ATH6KL_NUM_5GHZ_CHANNELS];
+ /* AR6006: MAC address from the device tree, zero if there is none */
+ u8 dt_mac[ETH_ALEN];
+
enum ath6kl_state state;
unsigned int testmode;
@@ -992,6 +995,7 @@ void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready);
int ath6kl_init_hw_start(struct ath6kl *ar);
int ath6kl_init_hw_stop(struct ath6kl *ar);
int ath6kl_init_fetch_firmwares(struct ath6kl *ar);
+int ath6kl_init_read_dt_mac(struct ath6kl *ar);
int ath6kl_init_hw_params(struct ath6kl *ar);
void ath6kl_check_wow_status(struct ath6kl *ar);
diff --git a/drivers/net/wireless/ath/ath6kl/init.c b/drivers/net/wireless/ath/ath6kl/init.c
index 745c49fcd..405df673b 100644
--- a/drivers/net/wireless/ath/ath6kl/init.c
+++ b/drivers/net/wireless/ath/ath6kl/init.c
@@ -22,8 +22,10 @@
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/of.h>
+#include <linux/of_net.h>
#include <linux/mmc/sdio_func.h>
#include <linux/vmalloc.h>
+#include <linux/unaligned.h>
#include "core.h"
#include "cfg80211.h"
@@ -1223,6 +1225,77 @@ int ath6kl_init_fetch_firmwares(struct ath6kl *ar)
return 0;
}
+/*
+ * The AR6006 board data carries a default MAC address, the Atheros default
+ * on some boards. A board can give the real one in the device tree
+ * (mac-address, local-mac-address or an nvmem cell). Read it once at probe.
+ */
+int ath6kl_init_read_dt_mac(struct ath6kl *ar)
+{
+ int ret;
+
+ if (ar->target_type != TARGET_TYPE_AR6006)
+ return 0;
+
+ ret = of_get_mac_address(ar->dev->of_node, ar->dt_mac);
+ if (!ret)
+ return 0;
+
+ eth_zero_addr(ar->dt_mac);
+
+ if (ret == -EPROBE_DEFER)
+ return ret;
+
+ if (ret != -ENODEV && ret != -ENOENT && ret != -EOPNOTSUPP)
+ ath6kl_warn("failed to read the MAC address from DT: %d\n", ret);
+
+ return 0;
+}
+
+#define AR6006_BOARD_DATA_CSUM_OFFSET 4
+#define AR6006_BOARD_DATA_MAC_OFFSET 8
+#define AR6006_HI_OPTION_DISABLE_MAC_OTP BIT(6)
+
+/*
+ * Put the MAC address from the device tree into the AR6006 board data. The
+ * MAC sits at offset 8. The checksum at offset 4 is the inverted XOR of all
+ * little-endian 16-bit words of the uploaded board data, taken with the
+ * checksum field zeroed.
+ */
+static int ath6kl_ar6006_set_board_mac(struct ath6kl *ar, u32 board_data_size)
+{
+ u16 sum = 0;
+ u32 param;
+ u32 i;
+ int ret;
+
+ if (ar->target_type != TARGET_TYPE_AR6006 ||
+ !is_valid_ether_addr(ar->dt_mac))
+ return 0;
+
+ put_unaligned_le16(0, &ar->fw_board[AR6006_BOARD_DATA_CSUM_OFFSET]);
+ memcpy(&ar->fw_board[AR6006_BOARD_DATA_MAC_OFFSET], ar->dt_mac,
+ ETH_ALEN);
+
+ for (i = 0; i + 1 < board_data_size; i += 2)
+ sum ^= get_unaligned_le16(&ar->fw_board[i]);
+
+ put_unaligned_le16(~sum, &ar->fw_board[AR6006_BOARD_DATA_CSUM_OFFSET]);
+
+ /* keep the firmware from taking the MAC from OTP instead */
+ ret = ath6kl_bmi_read_hi32(ar, hi_option_flag2, ¶m);
+ if (ret)
+ return ret;
+
+ param |= AR6006_HI_OPTION_DISABLE_MAC_OTP;
+ ret = ath6kl_bmi_write_hi32(ar, hi_option_flag2, param);
+ if (ret)
+ return ret;
+
+ ath6kl_dbg(ATH6KL_DBG_BOOT, "board data MAC set to %pM\n", ar->dt_mac);
+ return 0;
+}
+
static int ath6kl_upload_board_file(struct ath6kl *ar)
{
u32 board_address, board_ext_address, param;
@@ -1310,6 +1383,10 @@ static int ath6kl_upload_board_file(struct ath6kl *ar)
return ret;
}
+ ret = ath6kl_ar6006_set_board_mac(ar, board_data_size);
+ if (ret)
+ return ret;
+
ath6kl_dbg(ATH6KL_DBG_BOOT, "writing board file to 0x%x (%d B)\n",
board_address, board_data_size);
diff --git a/drivers/net/wireless/ath/ath6kl/usb.c b/drivers/net/wireless/ath/ath6kl/usb.c
index 945984c3d..2f08dba57 100644
--- a/drivers/net/wireless/ath/ath6kl/usb.c
+++ b/drivers/net/wireless/ath/ath6kl/usb.c
@@ -1161,7 +1161,8 @@ static int ath6kl_usb_probe(struct usb_interface *interface,
ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
if (ret) {
- ath6kl_err("Failed to init ath6kl core: %d\n", ret);
+ dev_err_probe(&interface->dev, ret,
+ "Failed to init ath6kl core\n");
goto err_core_free;
}
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-30 9:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:50 [PATCH ath-next 0/9] wifi: ath6kl: add AR6006 hw1.1 (QCA6006) support Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 1/9] wifi: ath6kl: add AR6006 hw1.1 support Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 2/9] wifi: ath6kl: handle the AR6006 WMI layout Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 3/9] wifi: ath6kl: ignore AR6006 regulatory domain events Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 4/9] wifi: ath6kl: use per-device band and channel copies Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 5/9] dt-bindings: net: wireless: add QCA6006 binding Josef Schlehofer
2026-11-30 9:50 ` Josef Schlehofer [this message]
2026-11-30 9:50 ` [PATCH ath-next 7/9] wifi: ath6kl: handle unsupported connection frequencies Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 8/9] wifi: ath6kl: honour ieee80211-freq-limit from DT Josef Schlehofer
2026-11-30 9:50 ` [PATCH ath-next 9/9] wifi: ath6kl: add QCA6006 USB ID Josef Schlehofer
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=20261130095042.41330-7-pepe.schlehofer@gmail.com \
--to=pepe.schlehofer@gmail.com \
--cc=jjohnson@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