]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: ath12k: Clean up the WMI Unit Test command interface
authorJeff Johnson <jeff.johnson@oss.qualcomm.com>
Tue, 10 Mar 2026 15:16:12 +0000 (08:16 -0700)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Mon, 16 Mar 2026 15:34:23 +0000 (08:34 -0700)
Currently, ath12k_wmi_send_unit_test_cmd() provides the interface to
send a Unit Test command to firmware.  The payload for the command is
passed in two separate parameters, struct wmi_unit_test_cmd ut_cmd and
u32 *test_args.  This interface is strange in that it passes the
ut_cmd structure by value instead of by reference. But even worse,
this presents an interface that is not endian clean since the ut_cmd
structure is defined in little endian format while the test_args array
is defined to be in cpu endian format. Furthermore, the implementation
of this function passes the test_args directly to the firmware, without
performing cpu_to_le32() conversion, and hence this functionality will
not work correctly on big endian platforms.

In order to fix these issues, introduce a new wmi_unit_test_arg
structure which defines all of the parameters needed by the Unit Test
command in a single structure using cpu endian. Update
ath12k_wmi_send_unit_test_cmd() to take a pointer to this structure
and perform all cpu_to_le32() conversions needed while forming the
firmware command. Update the only existing Unit Test function,
ath12k_wmi_simulate_radar(), to properly fill and pass this new
structure to ath12k_wmi_send_unit_test_cmd().

Compile tested only.

Reviewed-by: Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com>
Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
Link: https://patch.msgid.link/20260310-ath12k-unit-test-cleanup-v1-1-03e3df56f903@oss.qualcomm.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath12k/wmi.c
drivers/net/wireless/ath/ath12k/wmi.h

index 8e13c3ec1cc70433d7f3c06d13f8c43f7d763cf6..8379aa8fe09188e27d6b7cf051ac4cfd875ec478 100644 (file)
@@ -10027,50 +10027,46 @@ static int ath12k_connect_pdev_htc_service(struct ath12k_base *ab,
 
 static int
 ath12k_wmi_send_unit_test_cmd(struct ath12k *ar,
-                             struct wmi_unit_test_cmd ut_cmd,
-                             u32 *test_args)
+                             const struct wmi_unit_test_arg *ut)
 {
        struct ath12k_wmi_pdev *wmi = ar->wmi;
        struct wmi_unit_test_cmd *cmd;
+       int buf_len, arg_len;
        struct sk_buff *skb;
        struct wmi_tlv *tlv;
+       __le32 *ut_cmd_args;
        void *ptr;
-       u32 *ut_cmd_args;
-       int buf_len, arg_len;
        int ret;
        int i;
 
-       arg_len = sizeof(u32) * le32_to_cpu(ut_cmd.num_args);
-       buf_len = sizeof(ut_cmd) + arg_len + TLV_HDR_SIZE;
+       arg_len = sizeof(*ut_cmd_args) * ut->num_args;
+       buf_len = sizeof(*cmd) + arg_len + TLV_HDR_SIZE;
 
        skb = ath12k_wmi_alloc_skb(wmi->wmi_ab, buf_len);
        if (!skb)
                return -ENOMEM;
 
-       cmd = (struct wmi_unit_test_cmd *)skb->data;
+       ptr = skb->data;
+       cmd = ptr;
        cmd->tlv_header = ath12k_wmi_tlv_cmd_hdr(WMI_TAG_UNIT_TEST_CMD,
-                                                sizeof(ut_cmd));
-
-       cmd->vdev_id = ut_cmd.vdev_id;
-       cmd->module_id = ut_cmd.module_id;
-       cmd->num_args = ut_cmd.num_args;
-       cmd->diag_token = ut_cmd.diag_token;
-
-       ptr = skb->data + sizeof(ut_cmd);
+                                                sizeof(*cmd));
+       cmd->vdev_id = cpu_to_le32(ut->vdev_id);
+       cmd->module_id = cpu_to_le32(ut->module_id);
+       cmd->num_args = cpu_to_le32(ut->num_args);
+       cmd->diag_token = cpu_to_le32(ut->diag_token);
 
+       ptr += sizeof(*cmd);
        tlv = ptr;
        tlv->header = ath12k_wmi_tlv_hdr(WMI_TAG_ARRAY_UINT32, arg_len);
 
        ptr += TLV_HDR_SIZE;
-
        ut_cmd_args = ptr;
-       for (i = 0; i < le32_to_cpu(ut_cmd.num_args); i++)
-               ut_cmd_args[i] = test_args[i];
+       for (i = 0; i < ut->num_args; i++)
+               ut_cmd_args[i] = cpu_to_le32(ut->args[i]);
 
        ath12k_dbg(ar->ab, ATH12K_DBG_WMI,
                   "WMI unit test : module %d vdev %d n_args %d token %d\n",
-                  cmd->module_id, cmd->vdev_id, cmd->num_args,
-                  cmd->diag_token);
+                  ut->module_id, ut->vdev_id, ut->num_args, ut->diag_token);
 
        ret = ath12k_wmi_cmd_send(wmi, skb, WMI_UNIT_TEST_CMDID);
 
@@ -10086,8 +10082,7 @@ ath12k_wmi_send_unit_test_cmd(struct ath12k *ar,
 int ath12k_wmi_simulate_radar(struct ath12k *ar)
 {
        struct ath12k_link_vif *arvif;
-       u32 dfs_args[DFS_MAX_TEST_ARGS];
-       struct wmi_unit_test_cmd wmi_ut;
+       struct wmi_unit_test_arg wmi_ut = {};
        bool arvif_found = false;
 
        list_for_each_entry(arvif, &ar->arvifs, list) {
@@ -10100,22 +10095,23 @@ int ath12k_wmi_simulate_radar(struct ath12k *ar)
        if (!arvif_found)
                return -EINVAL;
 
-       dfs_args[DFS_TEST_CMDID] = 0;
-       dfs_args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
-       /* Currently we could pass segment_id(b0 - b1), chirp(b2)
+       wmi_ut.args[DFS_TEST_CMDID] = 0;
+       wmi_ut.args[DFS_TEST_PDEV_ID] = ar->pdev->pdev_id;
+       /*
+        * Currently we could pass segment_id(b0 - b1), chirp(b2)
         * freq offset (b3 - b10) to unit test. For simulation
         * purpose this can be set to 0 which is valid.
         */
-       dfs_args[DFS_TEST_RADAR_PARAM] = 0;
+       wmi_ut.args[DFS_TEST_RADAR_PARAM] = 0;
 
-       wmi_ut.vdev_id = cpu_to_le32(arvif->vdev_id);
-       wmi_ut.module_id = cpu_to_le32(DFS_UNIT_TEST_MODULE);
-       wmi_ut.num_args = cpu_to_le32(DFS_MAX_TEST_ARGS);
-       wmi_ut.diag_token = cpu_to_le32(DFS_UNIT_TEST_TOKEN);
+       wmi_ut.vdev_id = arvif->vdev_id;
+       wmi_ut.module_id = DFS_UNIT_TEST_MODULE;
+       wmi_ut.num_args = DFS_MAX_TEST_ARGS;
+       wmi_ut.diag_token = DFS_UNIT_TEST_TOKEN;
 
        ath12k_dbg(ar->ab, ATH12K_DBG_REG, "Triggering Radar Simulation\n");
 
-       return ath12k_wmi_send_unit_test_cmd(ar, wmi_ut, dfs_args);
+       return ath12k_wmi_send_unit_test_cmd(ar, &wmi_ut);
 }
 
 int ath12k_wmi_send_tpc_stats_request(struct ath12k *ar,
index 0bf0a7941cd3c2b34edf3949300ace5b2cc0f813..8d766dd5b30451270f5db46502b08e51ec921c1f 100644 (file)
@@ -4210,6 +4210,17 @@ struct wmi_dfs_unit_test_arg {
        u32 radar_param;
 };
 
+/* update if another test command requires more */
+#define WMI_UNIT_TEST_ARGS_MAX DFS_MAX_TEST_ARGS
+
+struct wmi_unit_test_arg {
+       u32 vdev_id;
+       u32 module_id;
+       u32 diag_token;
+       u32 num_args;
+       u32 args[WMI_UNIT_TEST_ARGS_MAX];
+};
+
 struct wmi_unit_test_cmd {
        __le32 tlv_header;
        __le32 vdev_id;