qcacld-3.0: Add ini to configure max tdls peer count

Add ini "gTDLSMaxPeerCount" to configure max tdls peer count.

Change-Id: I45c287c6c9a2fa1dcebcea54fdd0fc0d8a14b064
CRs-Fixed: 2718971
diff --git a/components/tdls/dispatcher/inc/wlan_tdls_cfg.h b/components/tdls/dispatcher/inc/wlan_tdls_cfg.h
index da57d35..7d1044f 100644
--- a/components/tdls/dispatcher/inc/wlan_tdls_cfg.h
+++ b/components/tdls/dispatcher/inc/wlan_tdls_cfg.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -273,6 +273,30 @@
 	"Attempts for sending TDLS discovery requests")
 
 /*
+ * gTDLSMaxPeerCount - Max TDLS connected peer count
+ * @Min: 1
+ * @Max: 8
+ * @Default: 8
+ *
+ * This ini is used to configure the max connected TDLS peer count.
+ *
+ * Related: gEnableTDLSSupport.
+ *
+ * Supported Feature: TDLS
+ *
+ * Usage: External
+ *
+ * </ini>
+ */
+#define CFG_TDLS_MAX_PEER_COUNT CFG_INI_UINT( \
+	"gTDLSMaxPeerCount", \
+	1, \
+	8, \
+	8, \
+	CFG_VALUE_OR_DEFAULT, \
+	"Max TDLS peer count")
+
+/*
  * <ini>
  * gTDLSIdleTimeout - Duration within which number of TX / RX frames meet the
  * criteria for TDLS teardown.
@@ -690,6 +714,7 @@
 	CFG(CFG_TDLS_TX_STATS_PERIOD) \
 	CFG(CFG_TDLS_TX_PACKET_THRESHOLD) \
 	CFG(CFG_TDLS_MAX_DISCOVERY_ATTEMPT) \
+	CFG(CFG_TDLS_MAX_PEER_COUNT) \
 	CFG(CFG_TDLS_IDLE_TIMEOUT) \
 	CFG(CFG_TDLS_IDLE_PACKET_THRESHOLD) \
 	CFG(CFG_TDLS_RSSI_TRIGGER_THRESHOLD) \
diff --git a/components/tdls/dispatcher/inc/wlan_tdls_cfg_api.h b/components/tdls/dispatcher/inc/wlan_tdls_cfg_api.h
index f56d6d5..cd85ceb 100644
--- a/components/tdls/dispatcher/inc/wlan_tdls_cfg_api.h
+++ b/components/tdls/dispatcher/inc/wlan_tdls_cfg_api.h
@@ -27,6 +27,7 @@
 
 struct wlan_objmgr_psoc;
 
+#ifdef FEATURE_WLAN_TDLS
 /**
  * cfg_tdls_get_support_enable() - get tdls support enable
  * @psoc:        pointer to psoc object
@@ -243,4 +244,176 @@
 cfg_tdls_set_scan_enable(struct wlan_objmgr_psoc *psoc,
 			 bool val);
 
+/**
+ * cfg_tdls_get_max_peer_count() - get tdls max peer count
+ * @psoc:        pointer to psoc object
+ *
+ * This function gets tdls max peer count
+ */
+uint16_t cfg_tdls_get_max_peer_count(struct wlan_objmgr_psoc *psoc);
+#else
+static inline QDF_STATUS
+cfg_tdls_get_support_enable(struct wlan_objmgr_psoc *psoc,
+			    bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_support_enable(struct wlan_objmgr_psoc *psoc,
+			    bool val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_external_control(struct wlan_objmgr_psoc *psoc,
+			      bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_uapsd_mask(struct wlan_objmgr_psoc *psoc,
+			uint32_t *val)
+{
+	*val = 0;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_buffer_sta_enable(struct wlan_objmgr_psoc *psoc,
+			       bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_buffer_sta_enable(struct wlan_objmgr_psoc *psoc,
+			       bool val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_uapsd_inactivity_time(struct wlan_objmgr_psoc *psoc,
+				   uint32_t *val)
+{
+	*val = 0;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_rx_pkt_threshold(struct wlan_objmgr_psoc *psoc,
+			      uint32_t *val)
+{
+	*val = 0;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_off_channel_enable(struct wlan_objmgr_psoc *psoc,
+				bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_off_channel_enable(struct wlan_objmgr_psoc *psoc,
+				bool val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_off_channel_enable_orig(struct wlan_objmgr_psoc *psoc,
+				     bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline void
+cfg_tdls_restore_off_channel_enable(struct wlan_objmgr_psoc *psoc)
+{
+}
+
+static inline void
+cfg_tdls_store_off_channel_enable(struct wlan_objmgr_psoc *psoc)
+{
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_wmm_mode_enable(struct wlan_objmgr_psoc *psoc,
+			     bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_vdev_nss_2g(struct wlan_objmgr_psoc *psoc,
+			 uint8_t val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_vdev_nss_5g(struct wlan_objmgr_psoc *psoc,
+			 uint8_t val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_sleep_sta_enable(struct wlan_objmgr_psoc *psoc,
+			      bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_sleep_sta_enable(struct wlan_objmgr_psoc *psoc,
+			      bool val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_get_scan_enable(struct wlan_objmgr_psoc *psoc,
+			 bool *val)
+{
+	*val = false;
+
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline QDF_STATUS
+cfg_tdls_set_scan_enable(struct wlan_objmgr_psoc *psoc,
+			 bool val)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline uint16_t
+cfg_tdls_get_max_peer_count(struct wlan_objmgr_psoc *psoc)
+{
+	return 0;
+}
+#endif /* FEATURE_WLAN_TDLS */
 #endif /* _WLAN_TDLS_CFG_API_H_ */
diff --git a/components/tdls/dispatcher/src/wlan_tdls_cfg.c b/components/tdls/dispatcher/src/wlan_tdls_cfg.c
index fe5e50d..7d3a617 100644
--- a/components/tdls/dispatcher/src/wlan_tdls_cfg.c
+++ b/components/tdls/dispatcher/src/wlan_tdls_cfg.c
@@ -369,3 +369,17 @@
 
 	return QDF_STATUS_SUCCESS;
 }
+
+uint16_t
+cfg_tdls_get_max_peer_count(struct wlan_objmgr_psoc *psoc)
+{
+	struct tdls_soc_priv_obj *soc_obj;
+
+	soc_obj = wlan_psoc_get_tdls_soc_obj(psoc);
+	if (!soc_obj) {
+		tdls_err("tdls soc null");
+		return 0;
+	}
+
+	return soc_obj->max_num_tdls_sta;
+}
diff --git a/components/tdls/dispatcher/src/wlan_tdls_ucfg_api.c b/components/tdls/dispatcher/src/wlan_tdls_ucfg_api.c
index 9a1a552..4c31074 100644
--- a/components/tdls/dispatcher/src/wlan_tdls_ucfg_api.c
+++ b/components/tdls/dispatcher/src/wlan_tdls_ucfg_api.c
@@ -218,6 +218,8 @@
 			cfg_get(psoc, CFG_TDLS_IMPLICIT_TRIGGER);
 	tdls_soc_obj->tdls_configs.tdls_external_control =
 			cfg_get(psoc, CFG_TDLS_EXTERNAL_CONTROL);
+	tdls_soc_obj->max_num_tdls_sta =
+			cfg_get(psoc, CFG_TDLS_MAX_PEER_COUNT);
 
 	tdls_update_feature_flag(tdls_soc_obj);
 
@@ -337,8 +339,6 @@
 	    TDLS_IS_OFF_CHANNEL_ENABLED(tdls_feature_flags))
 		soc_obj->max_num_tdls_sta =
 			WLAN_TDLS_STA_P_UAPSD_OFFCHAN_MAX_NUM;
-		else
-			soc_obj->max_num_tdls_sta = WLAN_TDLS_STA_MAX_NUM;
 
 	for (sta_idx = 0; sta_idx < soc_obj->max_num_tdls_sta; sta_idx++) {
 		soc_obj->tdls_conn_info[sta_idx].valid_entry = false;
diff --git a/core/hdd/inc/wlan_hdd_assoc.h b/core/hdd/inc/wlan_hdd_assoc.h
index 9dce717..e3e2c72 100644
--- a/core/hdd/inc/wlan_hdd_assoc.h
+++ b/core/hdd/inc/wlan_hdd_assoc.h
@@ -33,14 +33,6 @@
 
 #define HDD_TIME_STRING_LEN 24
 
-/* Preprocessor Definitions and Constants */
-#ifdef FEATURE_WLAN_TDLS
-#define HDD_MAX_NUM_TDLS_STA          8
-#define HDD_MAX_NUM_TDLS_STA_P_UAPSD_OFFCHAN  1
-#else
-#define HDD_MAX_NUM_TDLS_STA          0
-
-#endif
 /* Timeout (in ms) for Link to Up before Registering Station */
 #define ASSOC_LINKUP_TIMEOUT 60
 
diff --git a/core/hdd/src/wlan_hdd_cfg80211.c b/core/hdd/src/wlan_hdd_cfg80211.c
index c03ba1c..6064cd7 100644
--- a/core/hdd/src/wlan_hdd_cfg80211.c
+++ b/core/hdd/src/wlan_hdd_cfg80211.c
@@ -904,11 +904,7 @@
 					WIFI_TDLS_EXTERNAL_CONTROL_SUPPORT : 0);
 		set = set | (tdls_off_channel ?
 					WIIF_TDLS_OFFCHANNEL_SUPPORT : 0);
-		if (tdls_sleep_sta_enable || tdls_buffer_sta ||
-		    tdls_off_channel)
-			max_num_tdls_sta = HDD_MAX_NUM_TDLS_STA_P_UAPSD_OFFCHAN;
-		else
-			max_num_tdls_sta = HDD_MAX_NUM_TDLS_STA;
+		max_num_tdls_sta = cfg_tdls_get_max_peer_count(hdd_ctx->psoc);
 
 		hdd_debug("TDLS Feature supported value %x", set);
 		if (nla_put_u32(skb, PARAM_MAX_TDLS_SESSION,
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 65d0fb6..305995a 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -263,8 +263,6 @@
 #define WOW_MIN_PATTERN_SIZE 6
 #define WOW_MAX_PATTERN_SIZE 64
 
-/* max peer can be tdls peers + self peer + bss peer */
-#define HDD_MAX_VDEV_PEER_COUNT  (HDD_MAX_NUM_TDLS_STA + 2)
 #define IS_IDLE_STOP (!cds_is_driver_unloading() && \
 		      !cds_is_driver_recovering() && !cds_is_driver_loading())
 
@@ -5030,6 +5028,7 @@
 	struct wlan_objmgr_vdev *vdev;
 	struct vdev_osif_priv *osif_priv;
 	struct wlan_vdev_create_params vdev_params = {0};
+	uint16_t max_peer_count;
 
 	hdd_nofl_debug("creating new vdev");
 
@@ -5103,7 +5102,12 @@
 		vdev = hdd_objmgr_get_vdev(adapter);
 		if (!vdev)
 			goto hdd_vdev_destroy_procedure;
-		wlan_vdev_set_max_peer_count(vdev, HDD_MAX_VDEV_PEER_COUNT);
+
+		/* Max peer can be tdls peers + self peer + bss peer */
+		max_peer_count = cfg_tdls_get_max_peer_count(hdd_ctx->psoc);
+		max_peer_count += 2;
+		wlan_vdev_set_max_peer_count(vdev, max_peer_count);
+
 		hdd_objmgr_put_vdev(vdev);
 	}
 
diff --git a/core/wma/src/wma_main.c b/core/wma/src/wma_main.c
index 8e4d267..13b4150 100644
--- a/core/wma/src/wma_main.c
+++ b/core/wma/src/wma_main.c
@@ -98,6 +98,7 @@
 #include "nan_ucfg_api.h"
 #include "wma_coex.h"
 #include "target_if_vdev_mgr_rx_ops.h"
+#include "wlan_tdls_cfg_api.h"
 #include "wlan_policy_mgr_i.h"
 #include "target_if_psoc_timer_tx_ops.h"
 
@@ -314,7 +315,7 @@
 	tgt_cfg->max_frag_entries = CFG_TGT_MAX_FRAG_TABLE_ENTRIES;
 	tgt_cfg->num_tdls_vdevs = CFG_TGT_NUM_TDLS_VDEVS;
 	tgt_cfg->num_tdls_conn_table_entries =
-		CFG_TGT_NUM_TDLS_CONN_TABLE_ENTRIES;
+			cfg_tdls_get_max_peer_count(wma_handle->psoc);
 	tgt_cfg->beacon_tx_offload_max_vdev =
 		CFG_TGT_DEFAULT_BEACON_TX_OFFLOAD_MAX_VDEV;
 	tgt_cfg->num_multicast_filter_entries =