qcacld-3.0: Avoid 2.4Ghz channel in 40Mhz for SAP start

When the channel list provided from hostapd contains both
2.4Ghz and 5Ghz channels and channel width is 40Mhz, scan
happens on all the 2.4Ghz  and 5Ghz channels and ACS algo
runs on all the channels to find the best channel for
starting SAP in 40Mhz. If a 2.4Ghz is selected, an OBSS
scan happens on all the 2.4Ghz channels to check if there
is any legacy BSS present on any overlapping channel. If
any BSS is found, channel width fallbacks to 20Mhz and
SAP gets started in 20Mhz bw instead of 40Mhz. This is
generally the case with 2.4Ghz whereas there is no such
issue in 5Ghz channels.

Avoid 2.4Ghz channels for starting SAP in 40Mhz bw by
assigning max weight to all the 2.4Ghz channels if 5Ghz
channels are also present in the channel list provided
from hostapd.

Change-Id: I079d20b912282c9db5c9b51b1ed4b85a4aa9c5df
CRs-Fixed: 2186658
diff --git a/core/sap/src/sap_ch_select.c b/core/sap/src/sap_ch_select.c
index 281d2f0..6641415 100644
--- a/core/sap/src/sap_ch_select.c
+++ b/core/sap/src/sap_ch_select.c
@@ -2108,6 +2108,56 @@
 }
 
 /**
+ * sap_allocate_max_weight_ht40_24_g() - allocate max weight for 40Mhz
+ *                                       to all 2.4Ghz channels
+ * @spect_info_params: Pointer to the tSapChSelSpectInfo structure
+ *
+ * Return: none
+ */
+static void sap_allocate_max_weight_ht40_24_g(
+			tSapChSelSpectInfo *spect_info_params)
+{
+	tSapSpectChInfo *spect_info;
+	uint8_t j;
+
+	/*
+	 * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all
+	 * 2.4 Ghz channels
+	 */
+	spect_info = spect_info_params->pSpectCh;
+	for (j = 0; j < spect_info_params->numSpectChans; j++) {
+		if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_1) &&
+		     spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_14)))
+			spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2;
+	}
+}
+
+/**
+ * sap_allocate_max_weight_ht40_5_g() - allocate max weight for 40Mhz
+ *                                      to all 5Ghz channels
+ * @spect_info_params: Pointer to the tSapChSelSpectInfo structure
+ *
+ * Return: none
+ */
+static void sap_allocate_max_weight_ht40_5_g(
+			tSapChSelSpectInfo *spect_info_params)
+{
+	tSapSpectChInfo *spect_info;
+	uint8_t j;
+
+	/*
+	 * Assign max weight for 40Mhz (SAP_ACS_WEIGHT_MAX * 2) to all
+	 * 5 Ghz channels
+	 */
+	spect_info = spect_info_params->pSpectCh;
+	for (j = 0; j < spect_info_params->numSpectChans; j++) {
+		if ((spect_info[j].chNum >= WLAN_REG_CH_NUM(CHAN_ENUM_36) &&
+		     spect_info[j].chNum <= WLAN_REG_CH_NUM(CHAN_ENUM_165)))
+			spect_info[j].weight = SAP_ACS_WEIGHT_MAX * 2;
+	}
+}
+
+/**
  * sap_sort_chl_weight_ht40_24_g() - to sort channel with the least weight
  * @pSpectInfoParams: Pointer to the tSapChSelSpectInfo structure
  *
@@ -2232,6 +2282,16 @@
 				pSpectInfo[j].weight = SAP_ACS_WEIGHT_MAX * 2;
 		}
 	}
+
+	pSpectInfo = pSpectInfoParams->pSpectCh;
+	for (j = 0; j < (pSpectInfoParams->numSpectChans); j++) {
+		QDF_TRACE(QDF_MODULE_ID_SAP, QDF_TRACE_LEVEL_INFO_HIGH,
+			  "In %s, Channel=%d Weight= %d rssi=%d bssCount=%d",
+			  __func__, pSpectInfo->chNum, pSpectInfo->weight,
+			  pSpectInfo->rssiAgr, pSpectInfo->bssCount);
+		pSpectInfo++;
+	}
+
 	sap_sort_chl_weight(pSpectInfoParams);
 }
 
@@ -2369,12 +2429,16 @@
 
 	switch (sap_ctx->acs_cfg->ch_width) {
 	case CH_WIDTH_40MHZ:
-		if (eCSR_DOT11_MODE_11g == operatingBand)
+		/*
+		 * Assign max weight to all 5Ghz channels when operating band
+		 * is 11g and to all 2.4Ghz channels when operating band is 11a
+		 * or 11abg to avoid selection in ACS algorithm for starting SAP
+		 */
+		if (eCSR_DOT11_MODE_11g == operatingBand) {
 			sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
-		else if (eCSR_DOT11_MODE_11a == operatingBand)
-			sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
-		else {
-			sap_sort_chl_weight_ht40_24_g(pSpectInfoParams, domain);
+			sap_allocate_max_weight_ht40_5_g(pSpectInfoParams);
+		} else {
+			sap_allocate_max_weight_ht40_24_g(pSpectInfoParams);
 			sap_sort_chl_weight_ht40_5_g(pSpectInfoParams);
 		}
 		break;