Linux wireless drivers development
 help / color / mirror / Atom feed
From: Josef Schlehofer <pepe.schlehofer@gmail.com>
To: Jeff Johnson <jjohnson@kernel.org>
Cc: linux-wireless@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH ath-next 1/3] wifi: ath6kl: use little-endian BMI command fields
Date: Sun, 29 Nov 2026 16:47:08 +0100	[thread overview]
Message-ID: <20261129154710.86640-2-pepe.schlehofer@gmail.com> (raw)
In-Reply-To: <20261129154710.86640-1-pepe.schlehofer@gmail.com>

BMI command fields are little-endian, but ath6kl copies u32 values in
host byte order. This makes BMI commands fail on big-endian hosts, and
the first one, BMI_GET_TARGET_INFO, times out.

Use put_unaligned_le32() and cpu_to_le32() for the request fields and
get_unaligned_le32() for the 32-bit replies of BMI_EXECUTE and
BMI_READ_SOC_REGISTER. Memory payloads stay as they are. Also decode
the target info fields in the log messages with le32_to_cpu().

Fixes: bdcd81707973 ("Add ath6kl cleaned up driver")
Cc: stable@vger.kernel.org
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
Tested on a big-endian QCA9563 with an AR6006 hw1.1 USB device, using
local AR6006 support patches. Target info, register accesses, memory
writes and the LZ upload work, and the firmware boots. This chip does
not use BMI_EXECUTE or BMI_SET_APP_START.

 drivers/net/wireless/ath/ath6kl/bmi.c | 55 ++++++++++++++-------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/bmi.c b/drivers/net/wireless/ath/ath6kl/bmi.c
index 5a9e93fd1..771cd7270 100644
--- a/drivers/net/wireless/ath/ath6kl/bmi.c
+++ b/drivers/net/wireless/ath/ath6kl/bmi.c
@@ -15,6 +15,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <linux/unaligned.h>
+
 #include "core.h"
 #include "hif-ops.h"
 #include "target.h"
@@ -23,7 +25,7 @@
 int ath6kl_bmi_done(struct ath6kl *ar)
 {
 	int ret;
-	u32 cid = BMI_DONE;
+	__le32 cid = cpu_to_le32(BMI_DONE);
 
 	if (ar->bmi.done_sent) {
 		ath6kl_dbg(ATH6KL_DBG_BMI, "bmi done skipped\n");
@@ -46,13 +48,14 @@ int ath6kl_bmi_get_target_info(struct ath6kl *ar,
 {
 	int ret;
 	u32 cid = BMI_GET_TARGET_INFO;
+	__le32 cmd = cpu_to_le32(cid);
 
 	if (ar->bmi.done_sent) {
 		ath6kl_err("bmi done sent already, cmd %d disallowed\n", cid);
 		return -EACCES;
 	}
 
-	ret = ath6kl_hif_bmi_write(ar, (u8 *)&cid, sizeof(cid));
+	ret = ath6kl_hif_bmi_write(ar, (u8 *)&cmd, sizeof(cmd));
 	if (ret) {
 		ath6kl_err("Unable to send get target info: %d\n", ret);
 		return ret;
@@ -102,13 +105,13 @@ int ath6kl_bmi_get_target_info(struct ath6kl *ar,
 
 		if (ret) {
 			ath6kl_err("Unable to read target info (%d bytes): %d\n",
-				   targ_info->byte_count, ret);
+				   le32_to_cpu(targ_info->byte_count), ret);
 			return ret;
 		}
 	}
 
 	ath6kl_dbg(ATH6KL_DBG_BMI, "target info (ver: 0x%x type: 0x%x)\n",
-		   targ_info->version, targ_info->type);
+		   le32_to_cpu(targ_info->version), le32_to_cpu(targ_info->type));
 
 	return 0;
 }
@@ -143,11 +146,11 @@ int ath6kl_bmi_read(struct ath6kl *ar, u32 addr, u8 *buf, u32 len)
 		rx_len = (len_remain < ar->bmi.max_data_size) ?
 					len_remain : ar->bmi.max_data_size;
 		offset = 0;
-		memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+		put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(cid);
-		memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+		put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(addr);
-		memcpy(&(ar->bmi.cmd_buf[offset]), &rx_len, sizeof(rx_len));
+		put_unaligned_le32(rx_len, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(len);
 
 		ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
@@ -215,11 +218,11 @@ int ath6kl_bmi_write(struct ath6kl *ar, u32 addr, u8 *buf, u32 len)
 		}
 
 		offset = 0;
-		memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+		put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(cid);
-		memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+		put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(addr);
-		memcpy(&(ar->bmi.cmd_buf[offset]), &tx_len, sizeof(tx_len));
+		put_unaligned_le32(tx_len, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(tx_len);
 		memcpy(&(ar->bmi.cmd_buf[offset]), src, tx_len);
 		offset += tx_len;
@@ -259,11 +262,11 @@ int ath6kl_bmi_execute(struct ath6kl *ar, u32 addr, u32 *param)
 		   addr, *param);
 
 	offset = 0;
-	memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+	put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(cid);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+	put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(addr);
-	memcpy(&(ar->bmi.cmd_buf[offset]), param, sizeof(*param));
+	put_unaligned_le32(*param, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(*param);
 
 	ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
@@ -278,7 +281,7 @@ int ath6kl_bmi_execute(struct ath6kl *ar, u32 addr, u32 *param)
 		return ret;
 	}
 
-	memcpy(param, ar->bmi.cmd_buf, sizeof(*param));
+	*param = get_unaligned_le32(ar->bmi.cmd_buf);
 
 	return 0;
 }
@@ -305,9 +308,9 @@ int ath6kl_bmi_set_app_start(struct ath6kl *ar, u32 addr)
 	ath6kl_dbg(ATH6KL_DBG_BMI, "bmi set app start: addr: 0x%x\n", addr);
 
 	offset = 0;
-	memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+	put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(cid);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+	put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(addr);
 
 	ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
@@ -341,9 +344,9 @@ int ath6kl_bmi_reg_read(struct ath6kl *ar, u32 addr, u32 *param)
 	ath6kl_dbg(ATH6KL_DBG_BMI, "bmi read SOC reg: addr: 0x%x\n", addr);
 
 	offset = 0;
-	memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+	put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(cid);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+	put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(addr);
 
 	ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
@@ -357,7 +360,7 @@ int ath6kl_bmi_reg_read(struct ath6kl *ar, u32 addr, u32 *param)
 		ath6kl_err("Unable to read from the device: %d\n", ret);
 		return ret;
 	}
-	memcpy(param, ar->bmi.cmd_buf, sizeof(*param));
+	*param = get_unaligned_le32(ar->bmi.cmd_buf);
 
 	return 0;
 }
@@ -386,11 +389,11 @@ int ath6kl_bmi_reg_write(struct ath6kl *ar, u32 addr, u32 param)
 		    addr, param);
 
 	offset = 0;
-	memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+	put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(cid);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+	put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(addr);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &param, sizeof(param));
+	put_unaligned_le32(param, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(param);
 
 	ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
@@ -432,9 +435,9 @@ int ath6kl_bmi_lz_data(struct ath6kl *ar, u8 *buf, u32 len)
 			  len_remain : (ar->bmi.max_data_size - header);
 
 		offset = 0;
-		memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+		put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(cid);
-		memcpy(&(ar->bmi.cmd_buf[offset]), &tx_len, sizeof(tx_len));
+		put_unaligned_le32(tx_len, &ar->bmi.cmd_buf[offset]);
 		offset += sizeof(tx_len);
 		memcpy(&(ar->bmi.cmd_buf[offset]), &buf[len - len_remain],
 		       tx_len);
@@ -477,9 +480,9 @@ int ath6kl_bmi_lz_stream_start(struct ath6kl *ar, u32 addr)
 		    addr);
 
 	offset = 0;
-	memcpy(&(ar->bmi.cmd_buf[offset]), &cid, sizeof(cid));
+	put_unaligned_le32(cid, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(cid);
-	memcpy(&(ar->bmi.cmd_buf[offset]), &addr, sizeof(addr));
+	put_unaligned_le32(addr, &ar->bmi.cmd_buf[offset]);
 	offset += sizeof(addr);
 
 	ret = ath6kl_hif_bmi_write(ar, ar->bmi.cmd_buf, offset);
-- 
2.54.0 (Apple Git-157)


  reply	other threads:[~2026-11-29 15:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 15:47 [PATCH ath-next 0/3] wifi: ath6kl: fix issues found on big-endian MIPS Josef Schlehofer
2026-11-29 15:47 ` Josef Schlehofer [this message]
2026-11-29 15:47 ` [PATCH ath-next 2/3] wifi: ath6kl: use kvfree() for firmware Josef Schlehofer
2026-11-29 15:47 ` [PATCH ath-next 3/3] wifi: ath6kl: use test_bit() for firmware capabilities 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=20261129154710.86640-2-pepe.schlehofer@gmail.com \
    --to=pepe.schlehofer@gmail.com \
    --cc=jjohnson@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=stable@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