From 1b402e444ff99efe84d09a084b96c39826783a8e Mon Sep 17 00:00:00 2001
From: Ramya Gnanasekar <rgnanase@codeaurora.org>
Date: Thu, 10 Sep 2020 13:33:55 +0530
Subject: [PATCH] ath11k: Enable 512MB profile in ath11k

Below changes are made to enable 512MB mem mode in ath11k
        * Makefile changes to implement compilation flag when
                512MB mem profile is configured.
        * Enabling 512MB mem profile by default from Makefile
                for IPQ5018. This can be removed later once
                512MB profile config is supported.
        * Update target_mem_mode, number of stations, peer and vap
                during compile time

Signed-off-by: Ramya Gnanasekar <rgnanase@codeaurora.org>
---
 drivers/net/wireless/ath/ath11k/Kconfig |  7 +++++++
 drivers/net/wireless/ath/ath11k/hw.h    | 14 +++++++++++---
 drivers/net/wireless/ath/ath11k/qmi.c   |  2 +-
 drivers/net/wireless/ath/ath11k/qmi.h   |  6 +++++-
 4 files changed, 24 insertions(+), 5 deletions(-)

--- a/drivers/net/wireless/ath/ath11k/Kconfig
+++ b/drivers/net/wireless/ath/ath11k/Kconfig
@@ -77,3 +77,10 @@ config ATH11K_PKTLOG
 	and reception, rate information and ani state. The packet
 	log uses ring buffer to dump the data. The buffer size,
 	frame filters can be alterted by debugfs entries.
+
+config ATH11K_MEM_PROFILE_512M
+	bool "ath11k enable 512MB memory profile"
+	depends on ATH11K
+	default n
+	---help---
+	Enables 512MB memory profile for ath11k
--- a/drivers/net/wireless/ath/ath11k/hw.h
+++ b/drivers/net/wireless/ath/ath11k/hw.h
@@ -9,11 +9,30 @@
 #include "wmi.h"
 
 /* Target configuration defines */
+#ifdef CPTCFG_ATH11K_MEM_PROFILE_512M
 
+#define TARGET_NUM_VDEVS	8
+#define TARGET_NUM_PEERS_PDEV	(128 + TARGET_NUM_VDEVS)
+/* Max num of stations (per radio) */
+#define TARGET_NUM_STATIONS	128
+#define ATH11K_QMI_TARGET_MEM_MODE	ATH11K_QMI_TARGET_MEM_MODE_512M
+#define ATH11K_DP_TX_COMP_RING_SIZE	8192
+#define ATH11K_DP_RXDMA_MON_STATUS_RING_SIZE	512
+#define ATH11K_DP_RXDMA_MONITOR_BUF_RING_SIZE	128
+#define ATH11K_DP_RXDMA_MONITOR_DST_RING_SIZE	128
+#else
 /* Num VDEVS per radio */
 #define TARGET_NUM_VDEVS	(16 + 1)
 
 #define TARGET_NUM_PEERS_PDEV	(512 + TARGET_NUM_VDEVS)
+/* Max num of stations (per radio) */
+#define TARGET_NUM_STATIONS	512
+#define ATH11K_QMI_TARGET_MEM_MODE	ATH11K_QMI_TARGET_MEM_MODE_DEFAULT
+#define ATH11K_DP_TX_COMP_RING_SIZE	32768
+#define ATH11K_DP_RXDMA_MON_STATUS_RING_SIZE	1024
+#define ATH11K_DP_RXDMA_MONITOR_BUF_RING_SIZE	4096
+#define ATH11K_DP_RXDMA_MONITOR_DST_RING_SIZE	2048
+#endif
 
 /* Num of peers for Single Radio mode */
 #define TARGET_NUM_PEERS_SINGLE		(TARGET_NUM_PEERS_PDEV)
@@ -24,9 +43,6 @@
 /* Num of peers for DBS_SBS */
 #define TARGET_NUM_PEERS_DBS_SBS	(3 * TARGET_NUM_PEERS_PDEV)
 
-/* Max num of stations (per radio) */
-#define TARGET_NUM_STATIONS	512
-
 #define TARGET_NUM_PEERS(x)	TARGET_NUM_PEERS_##x
 #define TARGET_NUM_PEER_KEYS	2
 #define TARGET_NUM_TIDS(x)	(2 * TARGET_NUM_PEERS(x) + \
--- a/drivers/net/wireless/ath/ath11k/qmi.c
+++ b/drivers/net/wireless/ath/ath11k/qmi.c
@@ -3956,7 +3956,7 @@ int ath11k_qmi_init_service(struct ath11
 	memset(&ab->qmi.target_mem, 0, sizeof(struct target_mem_chunk));
 	ab->qmi.ab = ab;
 
-	ab->qmi.target_mem_mode = ATH11K_QMI_TARGET_MEM_MODE_DEFAULT;
+	ab->qmi.target_mem_mode = ATH11K_QMI_TARGET_MEM_MODE;
 	ret = qmi_handle_init(&ab->qmi.handle, ATH11K_QMI_RESP_LEN_MAX,
 			      &ath11k_qmi_ops, ath11k_qmi_msg_handlers);
 	if (ret < 0) {
--- a/drivers/net/wireless/ath/ath11k/qmi.h
+++ b/drivers/net/wireless/ath/ath11k/qmi.h
@@ -32,8 +32,15 @@
 #define ATH11K_QMI_FW_MEM_REQ_SEGMENT_CNT	3
 #define ATH11K_QMI_MAX_QDSS_CONFIG_FILE_NAME_SIZE 64
 #define ATH11K_QMI_DEFAULT_QDSS_CONFIG_FILE_NAME "qdss_trace_config.bin"
+
+#ifdef CPTCFG_ATH11K_MEM_PROFILE_512M
+#define ATH11K_QMI_IPQ8074_M3_DUMP_ADDRESS	0x4E800000
+#define ATH11K_QMI_IPQ6018_M3_DUMP_ADDRESS	0x4E300000
+#else
 #define ATH11K_QMI_IPQ8074_M3_DUMP_ADDRESS	0x51000000
 #define ATH11K_QMI_IPQ6018_M3_DUMP_ADDRESS	0x50100000
+#endif
+
 #define ATH11K_QMI_IPQ5018_M3_DUMP_ADDRESS 0x4C800000
 #define ATH11K_QMI_M3_DUMP_SIZE			0x100000
 
@@ -49,11 +56,15 @@
 
 #define QMI_WLANFW_MAX_DATA_SIZE_V01		6144
 #define ATH11K_FIRMWARE_MODE_OFF		4
-#define ATH11K_QMI_TARGET_MEM_MODE_DEFAULT	0
 #define ATH11K_COLD_BOOT_FW_RESET_DELAY		(60 * HZ)
 
 struct ath11k_base;
 
+enum ath11k_target_mem_mode {
+	ATH11K_QMI_TARGET_MEM_MODE_DEFAULT = 0,
+	ATH11K_QMI_TARGET_MEM_MODE_512M,
+};
+
 enum ath11k_qmi_file_type {
 	ATH11K_QMI_FILE_TYPE_BDF_GOLDEN,
 	ATH11K_QMI_FILE_TYPE_CALDATA = 2,
--- a/local-symbols
+++ b/local-symbols
@@ -134,6 +134,7 @@ ATH11K=
 ATH11K_AHB=
 ATH11K_PCI=
 ATH11K_NSS_SUPPORT=
+ATH11K_MEM_PROFILE_512M=
 ATH11K_DEBUG=
 ATH11K_DEBUGFS=
 ATH11K_TRACING=
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -869,6 +869,7 @@ struct ath11k_base {
 	bool fw_recovery_support;
 	bool ce_remap;
 	u32 ce_remap_base_addr;
+	atomic_t num_max_allowed;
 
 	/* must be last */
 	u8 drv_priv[0] __aligned(sizeof(void *));
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -186,8 +186,9 @@ struct ath11k_pdev_dp {
 
 #define DP_WBM_RELEASE_RING_SIZE	64
 #define DP_TCL_DATA_RING_SIZE		512
-#define DP_TX_COMP_RING_SIZE		32768
+#define DP_TX_COMP_RING_SIZE		ATH11K_DP_TX_COMP_RING_SIZE
 #define DP_TX_IDR_SIZE			DP_TX_COMP_RING_SIZE
+#define DP_TX_COMP_MAX_ALLOWED		((DP_TX_COMP_RING_SIZE << 1)/3)
 #define DP_TCL_CMD_RING_SIZE		32
 #define DP_TCL_STATUS_RING_SIZE		32
 #define DP_REO_DST_RING_MAX		4
@@ -200,9 +201,9 @@ struct ath11k_pdev_dp {
 #define DP_RXDMA_BUF_RING_SIZE		4096
 #define DP_RXDMA_REFILL_RING_SIZE	2048
 #define DP_RXDMA_ERR_DST_RING_SIZE	1024
-#define DP_RXDMA_MON_STATUS_RING_SIZE	1024
-#define DP_RXDMA_MONITOR_BUF_RING_SIZE	4096
-#define DP_RXDMA_MONITOR_DST_RING_SIZE	2048
+#define DP_RXDMA_MON_STATUS_RING_SIZE	ATH11K_DP_RXDMA_MON_STATUS_RING_SIZE
+#define DP_RXDMA_MONITOR_BUF_RING_SIZE	ATH11K_DP_RXDMA_MONITOR_BUF_RING_SIZE
+#define DP_RXDMA_MONITOR_DST_RING_SIZE	ATH11K_DP_RXDMA_MONITOR_BUF_RING_SIZE
 #define DP_RXDMA_MONITOR_DESC_RING_SIZE	4096
 
 #define DP_RX_BUFFER_SIZE	2048
--- a/drivers/net/wireless/ath/ath11k/dp_tx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_tx.c
@@ -322,6 +322,7 @@ tcl_ring_sel:
 			skb->data, skb->len);
 
 	atomic_inc(&ar->dp.num_tx_pending);
+	atomic_inc(&ab->num_max_allowed);
 
 	return 0;
 
@@ -370,6 +371,7 @@ static void ath11k_dp_tx_free_txbuf(stru
 	ar = ab->pdevs[mac_id].ar;
 	if (atomic_dec_and_test(&ar->dp.num_tx_pending))
 		wake_up(&ar->dp.tx_empty_waitq);
+	atomic_dec(&ab->num_max_allowed);
 }
 
 static void
@@ -403,6 +405,7 @@ ath11k_dp_tx_htt_tx_complete_buf(struct
 
 	if (atomic_dec_and_test(&ar->dp.num_tx_pending))
 		wake_up(&ar->dp.tx_empty_waitq);
+	atomic_dec(&ab->num_max_allowed);
 
 	dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE);
 
@@ -702,6 +705,7 @@ void ath11k_dp_tx_completion_handler(str
 			wake_up(&ar->dp.tx_empty_waitq);
 
 		ath11k_dp_tx_complete_msdu(ar, msdu, &ts);
+		atomic_dec(&ab->num_max_allowed);
 	}
 }
 
