]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ath11k: Use reserved host DDR addresses from DT for PCI devices
authorAnilkumar Kolli <akolli@codeaurora.org>
Tue, 14 Dec 2021 15:39:43 +0000 (17:39 +0200)
committerKalle Valo <quic_kvalo@quicinc.com>
Thu, 16 Dec 2021 15:33:51 +0000 (17:33 +0200)
Host DDR memory (contiguous 45 MB in mode-0 or 15 MB in mode-2)
is reserved through DT entries for firmware usage. Send the base
address from DT entries.
If DT entry is available, PCI device will work with
fixed_mem_region else host allocates multiple segments.

IPQ8074 on HK10 board supports multiple PCI devices.
IPQ8074 + QCN9074 is tested with this patch.

Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.4.0.1-01838-QCAHKSWPL_SILICONZ-1

Signed-off-by: Anilkumar Kolli <akolli@codeaurora.org>
Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>
Link: https://lore.kernel.org/r/1638789319-2950-2-git-send-email-akolli@codeaurora.org
drivers/net/wireless/ath/ath11k/core.h
drivers/net/wireless/ath/ath11k/mhi.c
drivers/net/wireless/ath/ath11k/pci.c
drivers/net/wireless/ath/ath11k/qmi.c
drivers/net/wireless/ath/ath11k/qmi.h

index b4203fa0452ebb477b7bcd4c17f7d7b25696d836..bab3878a41a75de3fb0feac48885659a31f1f207 100644 (file)
@@ -202,6 +202,7 @@ enum ath11k_dev_flags {
        ATH11K_FLAG_HTC_SUSPEND_COMPLETE,
        ATH11K_FLAG_CE_IRQ_ENABLED,
        ATH11K_FLAG_EXT_IRQ_ENABLED,
+       ATH11K_FLAG_FIXED_MEM_RGN,
 };
 
 enum ath11k_monitor_flags {
index 9a8e61ca9964b03668b1cd56ad6104cd9c2eb6d5..38af8ec69d4c0aa595cefac6bb1407d65eeb0790 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <linux/msi.h>
 #include <linux/pci.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/ioport.h>
 
 #include "core.h"
 #include "debug.h"
@@ -318,6 +321,26 @@ static void ath11k_mhi_op_write_reg(struct mhi_controller *mhi_cntrl,
        writel(val, addr);
 }
 
+static int ath11k_mhi_read_addr_from_dt(struct mhi_controller *mhi_ctrl)
+{
+       struct device_node *np;
+       struct resource res;
+       int ret;
+
+       np = of_find_node_by_type(NULL, "memory");
+       if (!np)
+               return -ENOENT;
+
+       ret = of_address_to_resource(np, 0, &res);
+       if (ret)
+               return ret;
+
+       mhi_ctrl->iova_start = res.start + 0x1000000;
+       mhi_ctrl->iova_stop = res.end;
+
+       return 0;
+}
+
 int ath11k_mhi_register(struct ath11k_pci *ab_pci)
 {
        struct ath11k_base *ab = ab_pci->ab;
@@ -349,8 +372,15 @@ int ath11k_mhi_register(struct ath11k_pci *ab_pci)
        if (!test_bit(ATH11K_PCI_FLAG_MULTI_MSI_VECTORS, &ab_pci->flags))
                mhi_ctrl->irq_flags = IRQF_SHARED | IRQF_NOBALANCING;
 
-       mhi_ctrl->iova_start = 0;
-       mhi_ctrl->iova_stop = 0xffffffff;
+       if (test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) {
+               ret = ath11k_mhi_read_addr_from_dt(mhi_ctrl);
+               if (ret < 0)
+                       return ret;
+       } else {
+               mhi_ctrl->iova_start = 0;
+               mhi_ctrl->iova_stop = 0xFFFFFFFF;
+       }
+
        mhi_ctrl->sbl_size = SZ_512K;
        mhi_ctrl->seg_len = SZ_512K;
        mhi_ctrl->fbc_download = true;
index 0a2b2ba4ae0713bdcded66b07e9f612bed5a4618..8c09d61138a1987f07ef3a4fb02236c919895fde 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/module.h>
 #include <linux/msi.h>
 #include <linux/pci.h>
+#include <linux/of.h>
 
 #include "pci.h"
 #include "core.h"
@@ -1347,7 +1348,7 @@ static int ath11k_pci_probe(struct pci_dev *pdev,
 {
        struct ath11k_base *ab;
        struct ath11k_pci *ab_pci;
-       u32 soc_hw_version_major, soc_hw_version_minor;
+       u32 soc_hw_version_major, soc_hw_version_minor, addr;
        int ret;
 
        ab = ath11k_core_alloc(&pdev->dev, sizeof(*ab_pci), ATH11K_BUS_PCI,
@@ -1367,6 +1368,14 @@ static int ath11k_pci_probe(struct pci_dev *pdev,
        pci_set_drvdata(pdev, ab);
        spin_lock_init(&ab_pci->window_lock);
 
+       /* Set fixed_mem_region to true for platforms support reserved memory
+        * from DT. If memory is reserved from DT for FW, ath11k driver need not
+        * allocate memory.
+        */
+       ret = of_property_read_u32(ab->dev->of_node, "memory-region", &addr);
+       if (!ret)
+               set_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags);
+
        ret = ath11k_pci_claim(ab_pci, pdev);
        if (ret) {
                ath11k_err(ab, "failed to claim device: %d\n", ret);
index b71781398fc425b5378c11dfe5d223abcf71caeb..3b9ba0e03a666f99639a06b80a7018ee01c31dd8 100644 (file)
@@ -9,6 +9,8 @@
 #include "core.h"
 #include "debug.h"
 #include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/ioport.h>
 #include <linux/firmware.h>
 
 #define SLEEP_CLOCK_SELECT_INTERNAL_BIT        0x02
@@ -1751,7 +1753,9 @@ static int ath11k_qmi_respond_fw_mem_request(struct ath11k_base *ab)
         * failure to FW and FW will then request mulitple blocks of small
         * chunk size memory.
         */
-       if (!ab->bus_params.fixed_mem_region && ab->qmi.target_mem_delayed) {
+       if (!(ab->bus_params.fixed_mem_region ||
+             test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
+             ab->qmi.target_mem_delayed) {
                delayed = true;
                ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi delays mem_request %d\n",
                           ab->qmi.mem_seg_count);
@@ -1818,10 +1822,12 @@ static void ath11k_qmi_free_target_mem_chunk(struct ath11k_base *ab)
 {
        int i;
 
-       if (ab->bus_params.fixed_mem_region)
-               return;
-
        for (i = 0; i < ab->qmi.mem_seg_count; i++) {
+               if ((ab->bus_params.fixed_mem_region ||
+                    test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
+                    ab->qmi.target_mem[i].iaddr)
+                       iounmap(ab->qmi.target_mem[i].iaddr);
+
                if (!ab->qmi.target_mem[i].vaddr)
                        continue;
 
@@ -1869,10 +1875,44 @@ static int ath11k_qmi_alloc_target_mem_chunk(struct ath11k_base *ab)
 
 static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)
 {
-       int i, idx;
+       struct device *dev = ab->dev;
+       struct device_node *hremote_node = NULL;
+       struct resource res;
+       u32 host_ddr_sz;
+       int i, idx, ret;
 
        for (i = 0, idx = 0; i < ab->qmi.mem_seg_count; i++) {
                switch (ab->qmi.target_mem[i].type) {
+               case HOST_DDR_REGION_TYPE:
+                       hremote_node = of_parse_phandle(dev->of_node, "memory-region", 0);
+                       if (!hremote_node) {
+                               ath11k_dbg(ab, ATH11K_DBG_QMI,
+                                          "qmi fail to get hremote_node\n");
+                               return ret;
+                       }
+
+                       ret = of_address_to_resource(hremote_node, 0, &res);
+                       if (ret) {
+                               ath11k_dbg(ab, ATH11K_DBG_QMI,
+                                          "qmi fail to get reg from hremote\n");
+                               return ret;
+                       }
+
+                       if (res.end - res.start + 1 < ab->qmi.target_mem[i].size) {
+                               ath11k_dbg(ab, ATH11K_DBG_QMI,
+                                          "qmi fail to assign memory of sz\n");
+                               return -EINVAL;
+                       }
+
+                       ab->qmi.target_mem[idx].paddr = res.start;
+                       ab->qmi.target_mem[idx].iaddr =
+                               ioremap(ab->qmi.target_mem[idx].paddr,
+                                       ab->qmi.target_mem[i].size);
+                       ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
+                       host_ddr_sz = ab->qmi.target_mem[i].size;
+                       ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
+                       idx++;
+                       break;
                case BDF_MEM_REGION_TYPE:
                        ab->qmi.target_mem[idx].paddr = ab->hw_params.bdf_addr;
                        ab->qmi.target_mem[idx].vaddr = NULL;
@@ -1887,10 +1927,16 @@ static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)
                        }
 
                        if (ath11k_cold_boot_cal && ab->hw_params.cold_boot_calib) {
-                               ab->qmi.target_mem[idx].paddr =
-                                                    ATH11K_QMI_CALDB_ADDRESS;
-                               ab->qmi.target_mem[idx].vaddr =
-                                                    (void *)ATH11K_QMI_CALDB_ADDRESS;
+                               if (hremote_node) {
+                                       ab->qmi.target_mem[idx].paddr =
+                                                       res.start + host_ddr_sz;
+                                       ab->qmi.target_mem[idx].iaddr =
+                                               ioremap(ab->qmi.target_mem[idx].paddr,
+                                                       ab->qmi.target_mem[i].size);
+                               } else {
+                                       ab->qmi.target_mem[idx].paddr =
+                                               ATH11K_QMI_CALDB_ADDRESS;
+                               }
                        } else {
                                ab->qmi.target_mem[idx].paddr = 0;
                                ab->qmi.target_mem[idx].vaddr = NULL;
@@ -2621,7 +2667,8 @@ static void ath11k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl,
                           msg->mem_seg[i].type, msg->mem_seg[i].size);
        }
 
-       if (ab->bus_params.fixed_mem_region) {
+       if (ab->bus_params.fixed_mem_region ||
+           test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) {
                ret = ath11k_qmi_assign_target_mem_chunk(ab);
                if (ret) {
                        ath11k_warn(ab, "failed to assign qmi target memory: %d\n",
index 49db39bf638cc5f91e15d695f967d7b24805ced4..a6fb7d47ee8272b93e35f9f218a62c11c7119c7c 100644 (file)
@@ -94,6 +94,7 @@ struct target_mem_chunk {
        u32 type;
        dma_addr_t paddr;
        u32 *vaddr;
+       void __iomem *iaddr;
 };
 
 struct target_info {