wifi: ath12k: Add logic to write QRTR node id to scratch
authorP Praneesh <quic_ppranees@quicinc.com>
Mon, 29 Jan 2024 06:57:16 +0000 (12:27 +0530)
committerKalle Valo <quic_kvalo@quicinc.com>
Fri, 2 Feb 2024 12:32:50 +0000 (14:32 +0200)
Currently only one MHI device is registered successfully on platform
having two or more identical MHI devices. This is beacuse QMI service
runs with identical QRTR node ID. And, qrtr-lookup cannot register
more than one QMI service with identical node ID.

Hence, generate a unique QRTR instance ID from PCIe domain number and
bus number. QMI allows node id to be written on scratch register.
Add logic to write QRTR node id to the register. It is available for
firmware to uniquely identify an instance.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.1.1-00188-QCAHKSWPL_SILICONZ-1
Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.0.1-00029-QCAHKSWPL_SILICONZ-1
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3

Signed-off-by: P Praneesh <quic_ppranees@quicinc.com>
Signed-off-by: Raj Kumar Bhagat <quic_rajkbhag@quicinc.com>
Acked-by: Jeff Johnson <quic_jjohnson@quicinc.com>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://msgid.link/20240129065724.2310207-6-quic_rajkbhag@quicinc.com
drivers/net/wireless/ath/ath12k/fw.h
drivers/net/wireless/ath/ath12k/pci.c
drivers/net/wireless/ath/ath12k/pci.h
drivers/net/wireless/ath/ath12k/qmi.h

index d91d95fc57405f1410a63d8b51576223fe207b7e..28dc1423df70aea61931fc98161d5cb0ce629721 100644 (file)
@@ -17,6 +17,11 @@ enum ath12k_fw_ie_type {
 };
 
 enum ath12k_fw_features {
+       /* The firmware supports setting the QRTR id via register
+        * PCIE_LOCAL_REG_QRTR_NODE_ID
+        */
+       ATH12K_FW_FEATURE_MULTI_QRTR_ID = 0,
+
        /* keep last */
        ATH12K_FW_FEATURE_COUNT,
 };
index 76438b3afd55b51fad60a1bcddfc8b25d1d89122..7a0ed7c9f5a26d42a1a0d23d6b1ec9f2c0de6775 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: BSD-3-Clause-Clear
 /*
  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
- * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/module.h>
 #define QCN9274_DEVICE_ID              0x1109
 #define WCN7850_DEVICE_ID              0x1107
 
+#define PCIE_LOCAL_REG_QRTR_NODE_ID    0x1E03164
+#define DOMAIN_NUMBER_MASK             GENMASK(7, 4)
+#define BUS_NUMBER_MASK                        GENMASK(3, 0)
+
 static const struct pci_device_id ath12k_pci_id_table[] = {
        { PCI_VDEVICE(QCOM, QCN9274_DEVICE_ID) },
        { PCI_VDEVICE(QCOM, WCN7850_DEVICE_ID) },
@@ -682,12 +686,22 @@ static void ath12k_pci_init_qmi_ce_config(struct ath12k_base *ab)
 {
        struct ath12k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg;
 
+       struct ath12k_pci *ab_pci = ath12k_pci_priv(ab);
+       struct pci_bus *bus = ab_pci->pdev->bus;
+
        cfg->tgt_ce = ab->hw_params->target_ce_config;
        cfg->tgt_ce_len = ab->hw_params->target_ce_count;
 
        cfg->svc_to_ce_map = ab->hw_params->svc_to_ce_map;
        cfg->svc_to_ce_map_len = ab->hw_params->svc_to_ce_map_len;
        ab->qmi.service_ins_id = ab->hw_params->qmi_service_ins_id;
+
+       if (test_bit(ATH12K_FW_FEATURE_MULTI_QRTR_ID, ab->fw.fw_features)) {
+               ab_pci->qmi_instance =
+                       u32_encode_bits(pci_domain_nr(bus), DOMAIN_NUMBER_MASK) |
+                       u32_encode_bits(bus->number, BUS_NUMBER_MASK);
+               ab->qmi.service_ins_id += ab_pci->qmi_instance;
+       }
 }
 
 static void ath12k_pci_ce_irqs_enable(struct ath12k_base *ab)
@@ -901,6 +915,26 @@ static void ath12k_pci_aspm_disable(struct ath12k_pci *ab_pci)
        set_bit(ATH12K_PCI_ASPM_RESTORE, &ab_pci->flags);
 }
 
+static void ath12k_pci_update_qrtr_node_id(struct ath12k_base *ab)
+{
+       struct ath12k_pci *ab_pci = ath12k_pci_priv(ab);
+       u32 reg;
+
+       /* On platforms with two or more identical mhi devices, qmi service run
+        * with identical qrtr-node-id. Because of this identical ID qrtr-lookup
+        * cannot register more than one qmi service with identical node ID.
+        *
+        * This generates a unique instance ID from PCIe domain number and bus number,
+        * writes to the given register, it is available for firmware when the QMI service
+        * is spawned.
+        */
+       reg = PCIE_LOCAL_REG_QRTR_NODE_ID & WINDOW_RANGE_MASK;
+       ath12k_pci_write32(ab, reg, ab_pci->qmi_instance);
+
+       ath12k_dbg(ab, ATH12K_DBG_PCI, "pci reg 0x%x instance 0x%x read val 0x%x\n",
+                  reg, ab_pci->qmi_instance, ath12k_pci_read32(ab, reg));
+}
+
 static void ath12k_pci_aspm_restore(struct ath12k_pci *ab_pci)
 {
        if (test_and_clear_bit(ATH12K_PCI_ASPM_RESTORE, &ab_pci->flags))
@@ -1219,6 +1253,9 @@ int ath12k_pci_power_up(struct ath12k_base *ab)
 
        ath12k_pci_msi_enable(ab_pci);
 
+       if (test_bit(ATH12K_FW_FEATURE_MULTI_QRTR_ID, ab->fw.fw_features))
+               ath12k_pci_update_qrtr_node_id(ab);
+
        ret = ath12k_mhi_start(ab_pci);
        if (ret) {
                ath12k_err(ab, "failed to start mhi: %d\n", ret);
index b2edf32ada20a90f6296a80dd72c2ec5eea5da9f..023616928f03e3c95786f9e5ccd1c9667ff1804a 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
 /*
  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
- * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 #ifndef ATH12K_PCI_H
 #define ATH12K_PCI_H
@@ -111,6 +111,7 @@ struct ath12k_pci {
        u16 link_ctl;
        unsigned long irq_flags;
        const struct ath12k_pci_ops *pci_ops;
+       u32 qmi_instance;
 };
 
 static inline struct ath12k_pci *ath12k_pci_priv(struct ath12k_base *ab)
index 828ab2bf037df477e18b26d1493a2e2a73e57ef0..6ee33c9851c6b39c9e6495a6f19cf10ab1490cac 100644 (file)
@@ -15,7 +15,6 @@
 #define ATH12K_QMI_MAX_BDF_FILE_NAME_SIZE      64
 #define ATH12K_QMI_CALDB_ADDRESS               0x4BA00000
 #define ATH12K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 128
-#define ATH12K_QMI_WLFW_NODE_ID_BASE           0x07
 #define ATH12K_QMI_WLFW_SERVICE_ID_V01         0x45
 #define ATH12K_QMI_WLFW_SERVICE_VERS_V01       0x01
 #define ATH12K_QMI_WLFW_SERVICE_INS_ID_V01     0x02