wifi: rtw89: phy: print out RFK log with formatted string
authorPing-Ke Shih <pkshih@realtek.com>
Wed, 13 Dec 2023 00:50:54 +0000 (08:50 +0800)
committerKalle Valo <kvalo@kernel.org>
Fri, 15 Dec 2023 13:38:26 +0000 (15:38 +0200)
With formatted string loaded from firmware file, we can use the formatted
string ID and get corresponding string, and then use regular rtw89_debug()
to show the message if debug mask of RFK is enabled.

If the string ID doesn't present, fallback to print plain hexadecimal.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20231213005054.10568-7-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/fw.h
drivers/net/wireless/realtek/rtw89/phy.c

index aa749732a9e2cb198057017257927e6119177eac..bfe226fe3d07ff74be9ff00643023bc6e6b7099f 100644 (file)
@@ -3733,6 +3733,11 @@ struct rtw89_c2h_rf_log_hdr {
        u8 content[];
 } __packed;
 
+struct rtw89_c2h_rf_run_log {
+       __le32 fmt_idx;
+       __le32 arg[4];
+} __packed;
+
 struct rtw89_c2h_rf_dpk_rpt_log {
        u8 ver;
        u8 idx[2];
index 496160f72755db2ffb366ebd1cbd230a16e7bb4c..bafc7b1cc104174612067d4e7f65da4449419028 100644 (file)
@@ -2566,6 +2566,38 @@ out:
                    "unexpected RFK func %d report log with length %d\n", func, len);
 }
 
+static bool rtw89_phy_c2h_rfk_run_log(struct rtw89_dev *rtwdev,
+                                     enum rtw89_phy_c2h_rfk_log_func func,
+                                     void *content, u16 len)
+{
+       struct rtw89_fw_elm_info *elm_info = &rtwdev->fw.elm_info;
+       const struct rtw89_c2h_rf_run_log *log = content;
+       const struct rtw89_fw_element_hdr *elm;
+       u32 fmt_idx;
+       u16 offset;
+
+       if (sizeof(*log) != len)
+               return false;
+
+       if (!elm_info->rfk_log_fmt)
+               return false;
+
+       elm = elm_info->rfk_log_fmt->elm[func];
+       fmt_idx = le32_to_cpu(log->fmt_idx);
+       if (!elm || fmt_idx >= elm->u.rfk_log_fmt.nr)
+               return false;
+
+       offset = le16_to_cpu(elm->u.rfk_log_fmt.offset[fmt_idx]);
+       if (offset == 0)
+               return false;
+
+       rtw89_debug(rtwdev, RTW89_DBG_RFK, &elm->u.common.contents[offset],
+                   le32_to_cpu(log->arg[0]), le32_to_cpu(log->arg[1]),
+                   le32_to_cpu(log->arg[2]), le32_to_cpu(log->arg[3]));
+
+       return true;
+}
+
 static void rtw89_phy_c2h_rfk_log(struct rtw89_dev *rtwdev, struct sk_buff *c2h,
                                  u32 len, enum rtw89_phy_c2h_rfk_log_func func,
                                  const char *rfk_name)
@@ -2575,6 +2607,7 @@ static void rtw89_phy_c2h_rfk_log(struct rtw89_dev *rtwdev, struct sk_buff *c2h,
        void *log_ptr = c2h_hdr;
        u16 content_len;
        u16 chunk_len;
+       bool handled;
 
        if (!rtw89_debug_is_enabled(rtwdev, RTW89_DBG_RFK))
                return;
@@ -2592,6 +2625,11 @@ static void rtw89_phy_c2h_rfk_log(struct rtw89_dev *rtwdev, struct sk_buff *c2h,
 
                switch (log_hdr->type) {
                case RTW89_RF_RUN_LOG:
+                       handled = rtw89_phy_c2h_rfk_run_log(rtwdev, func,
+                                                           log_hdr->content, content_len);
+                       if (handled)
+                               break;
+
                        rtw89_debug(rtwdev, RTW89_DBG_RFK, "%s run: %*ph\n",
                                    rfk_name, content_len, log_hdr->content);
                        break;