qcacld-3.0: Add INI support for number of vdevs

new INI gNumVdevs is added to allow number of VDEV support
for both Host and FW. Also Updated logic to calculate num_peers
and num_tids.

Change-Id: Ife5ff24e9594c8986913c06899ac5e41c83fc75c
CRs-Fixed: 2245506
diff --git a/Kbuild b/Kbuild
index 9e46b31..153acb1 100644
--- a/Kbuild
+++ b/Kbuild
@@ -1954,6 +1954,10 @@
 ccflags-y += -DPMO_WOW_FILTERS_MAX=$(CONFIG_CFG_PMO_WOW_FILTERS_MAX)
 endif
 
+ifdef CONFIG_CFG_NUM_OF_ADDITIONAL_FW_PEERS
+ccflags-y += -DNUM_OF_ADDITIONAL_FW_PEERS=$(CONFIG_CFG_NUM_OF_ADDITIONAL_FW_PEERS)
+endif
+
 KBUILD_CPPFLAGS += $(cppflags-y)
 
 # Currently, for versions of gcc which support it, the kernel Makefile
diff --git a/configs/genoa.snoc.debug_defconfig b/configs/genoa.snoc.debug_defconfig
index b130271..7a94a2d 100644
--- a/configs/genoa.snoc.debug_defconfig
+++ b/configs/genoa.snoc.debug_defconfig
@@ -178,4 +178,6 @@
 # WoW filter configs
 CONFIG_CFG_PMO_WOW_FILTERS_MAX := 16
 
+# Additional peers sent to firmware
+CONFIG_CFG_NUM_OF_ADDITIONAL_FW_PEERS := 0
 ###################################
diff --git a/configs/genoa.snoc.perf_defconfig b/configs/genoa.snoc.perf_defconfig
index b6fd9ab..f3a7a81 100644
--- a/configs/genoa.snoc.perf_defconfig
+++ b/configs/genoa.snoc.perf_defconfig
@@ -185,4 +185,6 @@
 # WoW filer configs
 CONFIG_CFG_PMO_WOW_FILTERS_MAX := 16
 
+# Additional peers sent to firmware
+CONFIG_CFG_NUM_OF_ADDITIONAL_FW_PEERS := 0
 ###################################
diff --git a/core/cds/inc/cds_config.h b/core/cds/inc/cds_config.h
index 79b8783..3452e0a 100644
--- a/core/cds/inc/cds_config.h
+++ b/core/cds/inc/cds_config.h
@@ -110,6 +110,7 @@
  * @rps_enabled: RPS enabled in SAP mode
  * @delay_before_vdev_stop: wait time for tx complete before vdev stop
  * Structure for holding cds ini parameters.
+ * @num_vdevs: Configured max number of VDEVs can be supported in the stack.
  */
 
 struct cds_config_info {
@@ -169,6 +170,7 @@
 	uint8_t bandcapability;
 	bool rps_enabled;
 	uint8_t delay_before_vdev_stop;
+	uint32_t num_vdevs;
 };
 
 #ifdef WLAN_FEATURE_FILS_SK
diff --git a/core/hdd/inc/wlan_hdd_cfg.h b/core/hdd/inc/wlan_hdd_cfg.h
index 26f897f..d7736e0 100644
--- a/core/hdd/inc/wlan_hdd_cfg.h
+++ b/core/hdd/inc/wlan_hdd_cfg.h
@@ -14187,6 +14187,23 @@
 #define CFG_ENABLE_SECONDARY_RATE_DEFAULT       (0x17)
 
 /*
+ * <ini>
+ * gNumVdevs - max number of VDEVs supported
+ *
+ * @Min: 0x1
+ * @Max: 0x4
+ * @Default: CFG_TGT_NUM_VDEV
+ *
+ * Usage: External
+ *
+ * </ini>
+ */
+#define CFG_NUM_VDEV_ENABLE_NAME      "gNumVdevs"
+#define CFG_NUM_VDEV_ENABLE_MIN       (0x1)
+#define CFG_NUM_VDEV_ENABLE_MAX       (0x4)
+#define CFG_NUM_VDEV_ENABLE_DEFAULT   (CFG_TGT_NUM_VDEV)
+
+/*
  * Type declarations
  */
 
@@ -15049,11 +15066,13 @@
 #ifdef WLAN_FEATURE_SAE
 	bool is_sae_enabled;
 #endif
+	bool enable_dtim_selection_diversity;
+	bool gcmp_enabled;
+	bool is_11k_offload_supported;
 	uint32_t btm_solicited_timeout;
 	uint32_t btm_max_attempt_cnt;
 	uint32_t btm_sticky_time;
-	bool gcmp_enabled;
-	bool is_11k_offload_supported;
+	uint32_t num_vdevs;
 	uint32_t offload_11k_enable_bitmask;
 	uint32_t neighbor_report_offload_params_bitmask;
 	uint32_t neighbor_report_offload_time_offset;
@@ -15062,9 +15081,8 @@
 	uint32_t neighbor_report_offload_per_threshold_offset;
 	uint32_t neighbor_report_offload_cache_timeout;
 	uint32_t neighbor_report_offload_max_req_cap;
-	uint16_t wmi_wq_watchdog_timeout;
-	bool enable_dtim_selection_diversity;
 	uint32_t channel_select_logic_conc;
+	uint16_t wmi_wq_watchdog_timeout;
 	bool enable_bt_chain_separation;
 	uint8_t enable_tx_sch_delay;
 	uint32_t enable_secondary_rate;
diff --git a/core/hdd/src/wlan_hdd_cfg.c b/core/hdd/src/wlan_hdd_cfg.c
index 7d62e27..8d57cf0 100644
--- a/core/hdd/src/wlan_hdd_cfg.c
+++ b/core/hdd/src/wlan_hdd_cfg.c
@@ -5405,6 +5405,13 @@
 		     CFG_ROAM_FORCE_RSSI_TRIGGER_MIN,
 		     CFG_ROAM_FORCE_RSSI_TRIGGER_MAX),
 
+	REG_VARIABLE(CFG_NUM_VDEV_ENABLE_NAME,
+		     WLAN_PARAM_HexInteger,
+		     struct hdd_config, num_vdevs,
+		     VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT,
+		     CFG_NUM_VDEV_ENABLE_DEFAULT,
+		     CFG_NUM_VDEV_ENABLE_MIN,
+		     CFG_NUM_VDEV_ENABLE_MAX),
 };
 
 
@@ -7276,6 +7283,8 @@
 		  hdd_ctx->config->btm_max_attempt_cnt);
 	hdd_debug("Name = [btm_sticky_time] value = [0x%x]",
 		  hdd_ctx->config->btm_sticky_time);
+	hdd_debug("Name = [num_vdevs] value = [0x%x]",
+		  hdd_ctx->config->num_vdevs);
 	hdd_debug("Name = [%s] value = [%d]",
 		  CFG_ENABLE_GCMP_NAME,
 		  hdd_ctx->config->gcmp_enabled);
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 2784007..b5f7eac 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -9262,6 +9262,7 @@
 	cds_cfg->bandcapability = hdd_ctx->config->nBandCapability;
 	cds_cfg->delay_before_vdev_stop =
 		hdd_ctx->config->delay_before_vdev_stop;
+	cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
 
 	hdd_ra_populate_cds_config(cds_cfg, hdd_ctx);
 	hdd_txrx_populate_cds_config(cds_cfg, hdd_ctx);
diff --git a/core/wma/src/wma_main.c b/core/wma/src/wma_main.c
index cc2229a..2115a6b 100644
--- a/core/wma/src/wma_main.c
+++ b/core/wma/src/wma_main.c
@@ -177,28 +177,8 @@
  */
 static uint8_t wma_get_number_of_peers_supported(tp_wma_handle wma)
 {
-	struct hif_target_info *tgt_info;
 	struct wma_ini_config *cfg = wma_get_ini_handle(wma);
 	uint8_t max_no_of_peers = cfg ? cfg->max_no_of_peers : MIN_NO_OF_PEERS;
-	struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
-
-	if (!scn) {
-		WMA_LOGE("%s: Invalid wma handle", __func__);
-		return 0;
-	}
-
-	tgt_info = hif_get_target_info_handle(scn);
-
-	switch (tgt_info->target_version) {
-	case AR6320_REV1_1_VERSION:
-		if (max_no_of_peers > MAX_SUPPORTED_PEERS_REV1_1)
-			max_no_of_peers = MAX_SUPPORTED_PEERS_REV1_1;
-		break;
-	default:
-		if (max_no_of_peers > MAX_SUPPORTED_PEERS_REV1_3)
-			max_no_of_peers = MAX_SUPPORTED_PEERS_REV1_3;
-		break;
-	}
 
 	return max_no_of_peers;
 }
@@ -210,14 +190,16 @@
  * Return: Max number of tids supported
  */
 #if defined(CONFIG_HL_SUPPORT)
-static uint32_t wma_get_number_of_tids_supported(uint8_t no_of_peers_supported)
+static uint32_t wma_get_number_of_tids_supported(uint8_t no_of_peers_supported,
+						 uint8_t num_vdevs)
 {
 	return 4 * no_of_peers_supported;
 }
 #else
-static uint32_t wma_get_number_of_tids_supported(uint8_t no_of_peers_supported)
+static uint32_t wma_get_number_of_tids_supported(uint8_t no_of_peers_supported,
+						 uint8_t num_vdevs)
 {
-	return 2 * (no_of_peers_supported + CFG_TGT_NUM_VDEV + 2);
+	return 2 * (no_of_peers_supported + num_vdevs + 2);
 }
 #endif
 
@@ -236,6 +218,10 @@
 }
 
 #endif
+
+#ifndef NUM_OF_ADDITIONAL_FW_PEERS
+#define NUM_OF_ADDITIONAL_FW_PEERS	2
+#endif
 /**
  * wma_set_default_tgt_config() - set default tgt config
  * @wma_handle: wma handle
@@ -244,17 +230,27 @@
  * Return: none
  */
 static void wma_set_default_tgt_config(tp_wma_handle wma_handle,
-				       target_resource_config *tgt_cfg)
+				       target_resource_config *tgt_cfg,
+				       struct cds_config_info *cds_cfg)
 {
 	uint8_t no_of_peers_supported;
 
+	no_of_peers_supported = wma_get_number_of_peers_supported(wma_handle);
+
 	qdf_mem_zero(tgt_cfg, sizeof(target_resource_config));
-	tgt_cfg->num_vdevs = CFG_TGT_NUM_VDEV;
-	tgt_cfg->num_peers = CFG_TGT_NUM_PEERS + CFG_TGT_NUM_VDEV + 2;
-	tgt_cfg->num_offload_peers = CFG_TGT_NUM_OFFLOAD_PEERS;
-	tgt_cfg->num_offload_reorder_buffs = CFG_TGT_NUM_OFFLOAD_REORDER_BUFFS;
+	tgt_cfg->num_vdevs = cds_cfg->num_vdevs;
+	tgt_cfg->num_peers = no_of_peers_supported +
+				cds_cfg->num_vdevs +
+				NUM_OF_ADDITIONAL_FW_PEERS;
+	/* The current firmware implementation requires the number of
+	 * offload peers should be (number of vdevs + 1).
+	 */
+	tgt_cfg->num_offload_peers = cds_cfg->ap_maxoffload_peers + 1;
+	tgt_cfg->num_offload_reorder_buffs =
+				cds_cfg->ap_maxoffload_reorderbuffs + 1;
 	tgt_cfg->num_peer_keys = CFG_TGT_NUM_PEER_KEYS;
-	tgt_cfg->num_tids = CFG_TGT_NUM_TIDS;
+	tgt_cfg->num_tids = wma_get_number_of_tids_supported(
+				no_of_peers_supported, cds_cfg->num_vdevs);
 	tgt_cfg->ast_skid_limit = CFG_TGT_AST_SKID_LIMIT;
 	tgt_cfg->tx_chain_mask = CFG_TGT_DEFAULT_TX_CHAIN_MASK;
 	tgt_cfg->rx_chain_mask = CFG_TGT_DEFAULT_RX_CHAIN_MASK;
@@ -263,7 +259,7 @@
 	tgt_cfg->rx_timeout_pri[2] = CFG_TGT_RX_TIMEOUT_LO_PRI;
 	tgt_cfg->rx_timeout_pri[3] = CFG_TGT_RX_TIMEOUT_HI_PRI;
 	tgt_cfg->rx_decap_mode = CFG_TGT_RX_DECAP_MODE;
-	tgt_cfg->scan_max_pending_req = CFG_TGT_DEFAULT_SCAN_MAX_REQS;
+	tgt_cfg->scan_max_pending_req = wma_handle->max_scan;
 	tgt_cfg->bmiss_offload_max_vdev =
 			CFG_TGT_DEFAULT_BMISS_OFFLOAD_MAX_VDEV;
 	tgt_cfg->roam_offload_max_vdev = CFG_TGT_DEFAULT_ROAM_OFFLOAD_MAX_VDEV;
@@ -290,7 +286,7 @@
 	tgt_cfg->num_multicast_filter_entries =
 		CFG_TGT_MAX_MULTICAST_FILTER_ENTRIES;
 	tgt_cfg->num_wow_filters = 0;
-	tgt_cfg->num_keep_alive_pattern = 0;
+	tgt_cfg->num_keep_alive_pattern = WMA_MAXNUM_PERIODIC_TX_PTRNS;
 	tgt_cfg->keep_alive_pattern_size = 0;
 	tgt_cfg->max_tdls_concurrent_sleep_sta =
 		CFG_TGT_NUM_TDLS_CONC_SLEEP_STAS;
@@ -301,11 +297,6 @@
 	tgt_cfg->num_ocb_channels = CFG_TGT_NUM_OCB_CHANNELS;
 	tgt_cfg->num_ocb_schedules = CFG_TGT_NUM_OCB_SCHEDULES;
 
-	no_of_peers_supported = wma_get_number_of_peers_supported(wma_handle);
-	tgt_cfg->num_peers = no_of_peers_supported + CFG_TGT_NUM_VDEV + 2;
-	tgt_cfg->num_tids = wma_get_number_of_tids_supported(
-						no_of_peers_supported);
-	tgt_cfg->scan_max_pending_req = wma_handle->max_scan;
 
 	tgt_cfg->mgmt_comp_evt_bundle_support = true;
 	tgt_cfg->tx_msdu_new_partition_id_support = true;
@@ -1931,17 +1922,25 @@
  *
  * Return: void
  */
-static void wma_init_max_no_of_peers(tp_wma_handle wma_handle,
+static uint8_t wma_init_max_no_of_peers(tp_wma_handle wma_handle,
 				     uint16_t max_peers)
 {
 	struct wma_ini_config *cfg = wma_get_ini_handle(wma_handle);
+	struct hif_opaque_softc *scn = cds_get_context(QDF_MODULE_ID_HIF);
+	uint32_t tgt_version = hif_get_target_info_handle(scn)->target_version;
+	uint8_t max_no_of_peers;
+	uint8_t max_supported_peers = (tgt_version == AR6320_REV1_1_VERSION) ?
+			MAX_SUPPORTED_PEERS_REV1_1 : MAX_SUPPORTED_PEERS_REV1_3;
 
 	if (cfg == NULL) {
 		WMA_LOGE("%s: NULL WMA ini handle", __func__);
-		return;
+		return 0;
 	}
 
-	cfg->max_no_of_peers = max_peers;
+	max_no_of_peers = (max_peers > max_supported_peers) ?
+				max_supported_peers : max_peers;
+	cfg->max_no_of_peers = max_no_of_peers;
+	return max_no_of_peers;
 }
 
 /**
@@ -3186,11 +3185,8 @@
 	init_deinit_register_tgt_psoc_ev_handlers(psoc);
 
 	/* Initialize max_no_of_peers for wma_get_number_of_peers_supported() */
-	wma_init_max_no_of_peers(wma_handle, cds_cfg->max_station);
-	/* Cap maxStation based on the target version */
-	cds_cfg->max_station = wma_get_number_of_peers_supported(wma_handle);
-	/* Reinitialize max_no_of_peers based on the capped maxStation value */
-	wma_init_max_no_of_peers(wma_handle, cds_cfg->max_station);
+	cds_cfg->max_station = wma_init_max_no_of_peers(wma_handle,
+							cds_cfg->max_station);
 
 	/* initialize default target config */
 	wlan_res_cfg = target_psoc_get_wlan_res_cfg(tgt_psoc_info);
@@ -3200,26 +3196,13 @@
 		goto err_wma_handle;
 	}
 
-	wma_set_default_tgt_config(wma_handle, wlan_res_cfg);
+	wma_set_default_tgt_config(wma_handle, wlan_res_cfg, cds_cfg);
 
 	wma_handle->tx_chain_mask_cck = cds_cfg->tx_chain_mask_cck;
 	wma_handle->self_gen_frm_pwr = cds_cfg->self_gen_frm_pwr;
-	wma_init_max_no_of_peers(wma_handle, cds_cfg->max_station);
-	cds_cfg->max_station = wma_get_number_of_peers_supported(wma_handle);
 
 	cds_cfg->max_bssid = WMA_MAX_SUPPORTED_BSS;
 
-	wlan_res_cfg->num_keep_alive_pattern = WMA_MAXNUM_PERIODIC_TX_PTRNS;
-
-	/* The current firmware implementation requires the number of
-	 * offload peers should be (number of vdevs + 1).
-	 */
-	wlan_res_cfg->num_offload_peers =
-		cds_cfg->ap_maxoffload_peers + 1;
-
-	wlan_res_cfg->num_offload_reorder_buffs =
-		cds_cfg->ap_maxoffload_reorderbuffs + 1;
-
 	wma_handle->max_station = cds_cfg->max_station;
 	wma_handle->max_bssid = cds_cfg->max_bssid;
 	wma_handle->driver_type = cds_cfg->driver_type;