qcacld-3.0: Do not send UAPSD enable command to FW

Currently, UAPSD enable command is sent to FW if
INI UapsdMask is set for any access category.
But, when twt is enabled then UAPSD auto trig
 commands should not be sent to FW. If both twt
and UAPSD is enabled in FW then it can lead
to data stalls.

Send UAPSD enable command to FW if twt is not supported.

Change-Id: I5de9fed6dc7366aeecab9bdc1f6574bc78bae6fb
CRs-Fixed: 2373679
diff --git a/core/mac/inc/sir_api.h b/core/mac/inc/sir_api.h
index f5a4f97..a3989b8 100644
--- a/core/mac/inc/sir_api.h
+++ b/core/mac/inc/sir_api.h
@@ -1017,6 +1017,7 @@
 	uint32_t assocReqLength;
 	uint32_t assocRspLength;
 	uint32_t parsedRicRspLen;
+	uint8_t uapsd_mask;
 #ifdef FEATURE_WLAN_ESE
 	uint32_t tspecIeLen;
 #endif
diff --git a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
index c680d45..1c6f44e 100644
--- a/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
+++ b/core/mac/src/pe/lim/lim_send_sme_rsp_messages.c
@@ -508,7 +508,7 @@
 #endif
 		lim_handle_join_rsp_status(mac_ctx, session_entry, result_code,
 			sme_join_rsp);
-
+		sme_join_rsp->uapsd_mask = session_entry->gUapsdPerAcBitmask;
 		/* Send supported NSS 1x1 to SME */
 		sme_join_rsp->supported_nss_1x1 =
 			session_entry->supported_nss_1x1;
diff --git a/core/sme/src/csr/csr_api_roam.c b/core/sme/src/csr/csr_api_roam.c
index f5df77e..fd1a120 100644
--- a/core/sme/src/csr/csr_api_roam.c
+++ b/core/sme/src/csr/csr_api_roam.c
@@ -7054,6 +7054,8 @@
 		acm_mask = sme_qos_get_acm_mask(mac_ctx, bss_desc, NULL);
 #endif
 		conn_profile->acm_mask = acm_mask;
+		conn_profile->modifyProfileFields.uapsd_mask =
+						join_rsp->uapsd_mask;
 		/*
 		 * start UAPSD if uapsd_mask is not 0 because HDD will
 		 * configure for trigger frame It may be better to let QoS do
@@ -14301,51 +14303,24 @@
  * csr_enable_twt() - Check if its allowed to enable twt for this session
  * @ie: pointer to beacon/probe resp ie's
  *
- * TWT is allowed only if device is in 11ax mode or if QCN ie present.
+ * TWT is allowed only if device is in 11ax mode and peer supports
+ * TWT responder or if QCN ie present.
  *
  * Return: true or flase
  */
-static bool csr_enable_twt(tDot11fBeaconIEs *ie)
+static bool csr_enable_twt(struct mac_context *mac_ctx, tDot11fBeaconIEs *ie)
 {
-	if (IS_FEATURE_SUPPORTED_BY_FW(DOT11AX))
-		return true;
 
-	if (!ie) {
-		sme_debug("Beacon ie buffer is null");
-		return false;
-	}
-
-	return ie->QCN_IE.present;
-}
-
-/**
- * csr_enable_uapsd() - Used to disable uapsd if both twt and uapsd is enabled
- * @mac_ctx: pointer to global mac structure
- * @ie: pointer to beacon/probe resp ie's
- *
- * Return: true or flase
- */
-static bool csr_enable_uapsd(struct mac_context *mac_ctx, tDot11fBeaconIEs *ie)
-{
-	/* In non-HE case, TWT is enabled only for Q2Q.
-	 * So keed uAPSD enabled for non-Q2Q in this non-HE case.
-	 */
-	if (!csr_enable_twt(ie))
-		return true;
-
-	if (!ie) {
-		sme_debug("Beacon ie buffer is null");
+	if ((IS_FEATURE_SUPPORTED_BY_FW(DOT11AX) ||
+	    mac_ctx->mlme_cfg->twt_cfg.is_twt_requestor_enabled) && ie &&
+	    (ie->QCN_IE.present || ie->he_cap.twt_responder)) {
+		sme_debug("TWT is supported, hence disable UAPSD; twt req supp: %d,twt respon supp: %d, QCN_IE: %d",
+			  mac_ctx->mlme_cfg->twt_cfg.is_twt_requestor_enabled,
+			  ie->he_cap.twt_responder,
+			  ie->QCN_IE.present);
 		return true;
 	}
-
-	if ((mac_ctx->mlme_cfg->twt_cfg.is_twt_requestor_enabled ||
-	     IS_FEATURE_SUPPORTED_BY_FW(DOT11AX)) &&
-	    ie->he_cap.twt_responder) {
-		sme_debug("twt supported, disable uapsd");
-		return false;
-	}
-
-	return true;
+	return false;
 }
 
 /**
@@ -14633,8 +14608,8 @@
 					 (eCsrPhyMode) pProfile->phyMode,
 					 pBssDescription, pIes, &OpRateSet,
 					 &ExRateSet);
-		ps_param->uapsd_per_ac_bit_mask =
-			pProfile->uapsd_mask;
+		if (!csr_enable_twt(mac, pIes))
+			ps_param->uapsd_per_ac_bit_mask = pProfile->uapsd_mask;
 		if (QDF_IS_STATUS_SUCCESS(status)) {
 			/* OperationalRateSet */
 			if (OpRateSet.numRates) {
@@ -15148,8 +15123,8 @@
 				csr_join_req->supportedChannels.channelList,
 				&csr_join_req->supportedChannels.numChnl,
 				false);
-
-		if (csr_enable_uapsd(mac, pIes))
+		/* Enable UAPSD only if TWT is not supported */
+		if (!csr_enable_twt(mac, pIes))
 			csr_join_req->uapsdPerAcBitmask = pProfile->uapsd_mask;
 		/* Move the entire BssDescription into the join request. */
 		qdf_mem_copy(&csr_join_req->bssDescription, pBssDescription,
@@ -15204,7 +15179,8 @@
 			csr_join_req->enable_bcast_probe_rsp =
 				mac->mlme_cfg->oce.enable_bcast_probe_rsp;
 
-		csr_join_req->enable_session_twt_support = csr_enable_twt(pIes);
+		csr_join_req->enable_session_twt_support = csr_enable_twt(mac,
+									  pIes);
 		status = umac_send_mb_message_to_mac(csr_join_req);
 		if (!QDF_IS_STATUS_SUCCESS(status)) {
 			/*