qcacld-3.0: Check consistency in throughput before setting delack

Integration from cld-2.0 to cld-3.0.

Currently the throughput is measured every 100 ms. Delack is set to 20
if throughput for this interval is greater then threshold (~57 Mbps).
In the case of congestion control, tcp may take longer duration for
rampup. In this change, throughput is checked for consistency for
about three seconds and then tcp delack is set to 20.

CRs-Fixed: 1028085
Change-Id: I1a4e9be3407ac426a314e1192d0e1d315e1899e0
diff --git a/core/hdd/src/wlan_hdd_cfg.c b/core/hdd/src/wlan_hdd_cfg.c
index dbea7f3..f16c313 100644
--- a/core/hdd/src/wlan_hdd_cfg.c
+++ b/core/hdd/src/wlan_hdd_cfg.c
@@ -3015,13 +3015,19 @@
 		     CFG_TCP_DELACK_THRESHOLD_LOW_MIN,
 		     CFG_TCP_DELACK_THRESHOLD_LOW_MAX),
 
-	REG_VARIABLE(CFG_TCP_TX_HIGH_TPUT_THRESHOLD_NAME, WLAN_PARAM_Integer,
-		struct hdd_config, tcp_tx_high_tput_thres,
-		VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT,
-		CFG_TCP_TX_HIGH_TPUT_THRESHOLD_DEFAULT,
-		CFG_TCP_TX_HIGH_TPUT_THRESHOLD_MIN,
-		CFG_TCP_TX_HIGH_TPUT_THRESHOLD_MAX),
+	REG_VARIABLE(CFG_TCP_DELACK_TIMER_COUNT, WLAN_PARAM_Integer,
+		     struct hdd_config, tcp_delack_timer_count,
+		     VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT,
+		     CFG_TCP_DELACK_TIMER_COUNT_DEFAULT,
+		     CFG_TCP_DELACK_TIMER_COUNT_MIN,
+		     CFG_TCP_DELACK_TIMER_COUNT_MAX),
 
+	REG_VARIABLE(CFG_TCP_TX_HIGH_TPUT_THRESHOLD_NAME, WLAN_PARAM_Integer,
+		     struct hdd_config, tcp_tx_high_tput_thres,
+		     VAR_FLAGS_OPTIONAL | VAR_FLAGS_RANGE_CHECK_ASSUME_DEFAULT,
+		     CFG_TCP_TX_HIGH_TPUT_THRESHOLD_DEFAULT,
+		     CFG_TCP_TX_HIGH_TPUT_THRESHOLD_MIN,
+		     CFG_TCP_TX_HIGH_TPUT_THRESHOLD_MAX),
 #endif
 
 	REG_VARIABLE(CFG_ENABLE_FW_LOG_TYPE, WLAN_PARAM_Integer,
@@ -5331,9 +5337,13 @@
 		  "Name = [gTcpDelAckThresholdLow] Value = [%u] ",
 		  pHddCtx->config->tcpDelackThresholdLow);
 	QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_HIGH,
-		"Name = [%s] Value = [%u] ",
-		CFG_TCP_TX_HIGH_TPUT_THRESHOLD_NAME,
-		pHddCtx->config->tcp_tx_high_tput_thres);
+		  "Name = [%s] Value = [%u] ",
+		  CFG_TCP_DELACK_TIMER_COUNT,
+		  pHddCtx->config->tcp_delack_timer_count);
+	QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_INFO_HIGH,
+		  "Name = [%s] Value = [%u] ",
+		  CFG_TCP_TX_HIGH_TPUT_THRESHOLD_NAME,
+		  pHddCtx->config->tcp_tx_high_tput_thres);
 
 #endif
 
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 55d8eb8..9993857 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -4596,6 +4596,7 @@
 	if (QDF_TIMER_STATE_RUNNING ==
 	    qdf_mc_timer_get_current_state(&hdd_ctx->bus_bw_timer)) {
 		qdf_mc_timer_stop(&hdd_ctx->bus_bw_timer);
+		hdd_reset_tcp_delack(hdd_ctx);
 	}
 
 	if (!QDF_IS_STATUS_SUCCESS
@@ -5058,6 +5059,7 @@
 	enum pld_bus_width_type next_vote_level = PLD_BUS_WIDTH_NONE;
 	enum wlan_tp_level next_rx_level = WLAN_SVC_TP_NONE;
 	enum wlan_tp_level next_tx_level = WLAN_SVC_TP_NONE;
+	uint32_t delack_timer_cnt = hdd_ctx->config->tcp_delack_timer_count;
 
 	if (total > hdd_ctx->config->busBandwidthHighThreshold)
 		next_vote_level = PLD_BUS_WIDTH_HIGH;
@@ -5099,10 +5101,14 @@
 	temp_rx = (rx_packets + hdd_ctx->prev_rx) / 2;
 
 	hdd_ctx->prev_rx = rx_packets;
-	if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh)
+	if (temp_rx > hdd_ctx->config->tcpDelackThresholdHigh &&
+	    (hdd_ctx->cur_rx_level != WLAN_SVC_TP_HIGH &&
+	    ++hdd_ctx->rx_high_ind_cnt == delack_timer_cnt)) {
 		next_rx_level = WLAN_SVC_TP_HIGH;
-	else
+	} else {
 		next_rx_level = WLAN_SVC_TP_LOW;
+		hdd_ctx->rx_high_ind_cnt = 0;
+	}
 
 	hdd_ctx->hdd_txrx_hist[hdd_ctx->hdd_txrx_hist_idx].next_rx_level =
 								next_rx_level;
@@ -8400,8 +8406,10 @@
 		}
 	}
 
-	if (can_stop == true)
+	if (can_stop == true) {
 		qdf_mc_timer_stop(&hdd_ctx->bus_bw_timer);
+		hdd_reset_tcp_delack(hdd_ctx);
+	}
 }
 #endif
 
diff --git a/core/hdd/src/wlan_hdd_tx_rx.c b/core/hdd/src/wlan_hdd_tx_rx.c
index 479ed89..317f993 100644
--- a/core/hdd/src/wlan_hdd_tx_rx.c
+++ b/core/hdd/src/wlan_hdd_tx_rx.c
@@ -60,6 +60,7 @@
 #include "ol_txrx.h"
 
 #include "wlan_hdd_nan_datapath.h"
+#include "pld_common.h"
 
 const uint8_t hdd_wmm_ac_to_highest_up[] = {
 	SME_QOS_WMM_UP_RESV,
@@ -1396,4 +1397,21 @@
 	hdd_ctxt->enableRxThread = true;
 }
 
+#ifdef MSM_PLATFORM
+/**
+ * hdd_reset_tcp_delack() - Reset tcp delack value to default
+ * @hdd_ctx: Handle to hdd context
+ *
+ * Function used to reset TCP delack value to its default value
+ *
+ * Return: None
+ */
+void hdd_reset_tcp_delack(hdd_context_t *hdd_ctx)
+{
+	enum pld_bus_width_type next_level = PLD_BUS_WIDTH_LOW;
 
+	hdd_ctx->rx_high_ind_cnt = 0;
+	wlan_hdd_send_svc_nlink_msg(hdd_ctx->radio_index, WLAN_SVC_WLAN_TP_IND,
+				    &next_level, sizeof(next_level));
+}
+#endif /* MSM_PLATFORM */