wifi: ath12k: add read variant from SMBIOS for download board data
authorWen Gong <quic_wgong@quicinc.com>
Sat, 30 Sep 2023 04:54:51 +0000 (07:54 +0300)
committerKalle Valo <quic_kvalo@quicinc.com>
Mon, 2 Oct 2023 16:13:50 +0000 (19:13 +0300)
This is to read variant from SMBIOS such as read from DT, the variant
string will be used to one part of string which used to search board
data from board-2.bin.

Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0-03427-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.15378.4

Signed-off-by: Wen Gong <quic_wgong@quicinc.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/20230905105637.10230-1-quic_wgong@quicinc.com
drivers/net/wireless/ath/ath12k/core.c
drivers/net/wireless/ath/ath12k/core.h
drivers/net/wireless/ath/ath12k/qmi.c

index 9a9a471ff130cdcd25429243e62735e5be2efdeb..c68750cb3c4db7a272eff969ceadad9e58323bec 100644 (file)
@@ -398,6 +398,75 @@ static void ath12k_core_stop(struct ath12k_base *ab)
        /* De-Init of components as needed */
 }
 
+static void ath12k_core_check_bdfext(const struct dmi_header *hdr, void *data)
+{
+       struct ath12k_base *ab = data;
+       const char *magic = ATH12K_SMBIOS_BDF_EXT_MAGIC;
+       struct ath12k_smbios_bdf *smbios = (struct ath12k_smbios_bdf *)hdr;
+       ssize_t copied;
+       size_t len;
+       int i;
+
+       if (ab->qmi.target.bdf_ext[0] != '\0')
+               return;
+
+       if (hdr->type != ATH12K_SMBIOS_BDF_EXT_TYPE)
+               return;
+
+       if (hdr->length != ATH12K_SMBIOS_BDF_EXT_LENGTH) {
+               ath12k_dbg(ab, ATH12K_DBG_BOOT,
+                          "wrong smbios bdf ext type length (%d).\n",
+                          hdr->length);
+               return;
+       }
+
+       if (!smbios->bdf_enabled) {
+               ath12k_dbg(ab, ATH12K_DBG_BOOT, "bdf variant name not found.\n");
+               return;
+       }
+
+       /* Only one string exists (per spec) */
+       if (memcmp(smbios->bdf_ext, magic, strlen(magic)) != 0) {
+               ath12k_dbg(ab, ATH12K_DBG_BOOT,
+                          "bdf variant magic does not match.\n");
+               return;
+       }
+
+       len = min_t(size_t,
+                   strlen(smbios->bdf_ext), sizeof(ab->qmi.target.bdf_ext));
+       for (i = 0; i < len; i++) {
+               if (!isascii(smbios->bdf_ext[i]) || !isprint(smbios->bdf_ext[i])) {
+                       ath12k_dbg(ab, ATH12K_DBG_BOOT,
+                                  "bdf variant name contains non ascii chars.\n");
+                       return;
+               }
+       }
+
+       /* Copy extension name without magic prefix */
+       copied = strscpy(ab->qmi.target.bdf_ext, smbios->bdf_ext + strlen(magic),
+                        sizeof(ab->qmi.target.bdf_ext));
+       if (copied < 0) {
+               ath12k_dbg(ab, ATH12K_DBG_BOOT,
+                          "bdf variant string is longer than the buffer can accommodate\n");
+               return;
+       }
+
+       ath12k_dbg(ab, ATH12K_DBG_BOOT,
+                  "found and validated bdf variant smbios_type 0x%x bdf %s\n",
+                  ATH12K_SMBIOS_BDF_EXT_TYPE, ab->qmi.target.bdf_ext);
+}
+
+int ath12k_core_check_smbios(struct ath12k_base *ab)
+{
+       ab->qmi.target.bdf_ext[0] = '\0';
+       dmi_walk(ath12k_core_check_bdfext, ab);
+
+       if (ab->qmi.target.bdf_ext[0] == '\0')
+               return -ENODATA;
+
+       return 0;
+}
+
 static int ath12k_core_soc_create(struct ath12k_base *ab)
 {
        int ret;
index 3f5f0471f640428aa4c11c4e4dc98e07c704d01a..254eb42a85c58d9c956a9f9657f5bb081e02874c 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/bitfield.h>
+#include <linux/dmi.h>
+#include <linux/ctype.h>
 #include "qmi.h"
 #include "htc.h"
 #include "wmi.h"
 /* Pending management packets threshold for dropping probe responses */
 #define ATH12K_PRB_RSP_DROP_THRESHOLD ((ATH12K_TX_MGMT_TARGET_MAX_SUPPORT_WMI * 3) / 4)
 
+/* SMBIOS type containing Board Data File Name Extension */
+#define ATH12K_SMBIOS_BDF_EXT_TYPE 0xF8
+
+/* SMBIOS type structure length (excluding strings-set) */
+#define ATH12K_SMBIOS_BDF_EXT_LENGTH 0x9
+
+/* The magic used by QCA spec */
+#define ATH12K_SMBIOS_BDF_EXT_MAGIC "BDF_"
+
 #define ATH12K_INVALID_HW_MAC_ID       0xFF
 #define        ATH12K_RX_RATE_TABLE_NUM        320
 #define        ATH12K_RX_RATE_TABLE_11AX_NUM   576
@@ -129,6 +140,13 @@ struct ath12k_ext_irq_grp {
        struct net_device napi_ndev;
 };
 
+struct ath12k_smbios_bdf {
+       struct dmi_header hdr;
+       u32 padding;
+       u8 bdf_enabled;
+       u8 bdf_ext[];
+} __packed;
+
 #define HEHANDLE_CAP_PHYINFO_SIZE       3
 #define HECAP_PHYINFO_SIZE              9
 #define HECAP_MACINFO_SIZE              5
@@ -792,7 +810,8 @@ int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,
 int ath12k_core_fetch_bdf(struct ath12k_base *ath12k,
                          struct ath12k_board_data *bd);
 void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd);
-
+int ath12k_core_check_dt(struct ath12k_base *ath12k);
+int ath12k_core_check_smbios(struct ath12k_base *ab);
 void ath12k_core_halt(struct ath12k *ar);
 int ath12k_core_resume(struct ath12k_base *ab);
 int ath12k_core_suspend(struct ath12k_base *ab);
index b2db0436bdde63ae75eccc37ad84d01f8372da63..fd1bf53c25023f2051d8b69e228b143d0819927e 100644 (file)
@@ -2213,6 +2213,7 @@ static int ath12k_qmi_request_target_cap(struct ath12k_base *ab)
        struct qmi_txn txn = {};
        unsigned int board_id = ATH12K_BOARD_ID_DEFAULT;
        int ret = 0;
+       int r;
        int i;
 
        memset(&req, 0, sizeof(req));
@@ -2297,6 +2298,10 @@ static int ath12k_qmi_request_target_cap(struct ath12k_base *ab)
                    ab->qmi.target.fw_build_timestamp,
                    ab->qmi.target.fw_build_id);
 
+       r = ath12k_core_check_smbios(ab);
+       if (r)
+               ath12k_dbg(ab, ATH12K_DBG_QMI, "SMBIOS bdf variant name not set.\n");
+
 out:
        return ret;
 }