qcacld-3.0: HDD changes for common scan module

HDD changes to support scan start and abort

Change-Id: I3260369879108f167453d5e0b8435c30ed729c5e
CRs-Fixed: 2013212
diff --git a/core/hdd/inc/wlan_hdd_main.h b/core/hdd/inc/wlan_hdd_main.h
index 3927605..d9a127d 100644
--- a/core/hdd/inc/wlan_hdd_main.h
+++ b/core/hdd/inc/wlan_hdd_main.h
@@ -1508,8 +1508,10 @@
 	struct delayed_work roc_req_work;
 	qdf_spinlock_t hdd_roc_req_q_lock;
 	qdf_list_t hdd_roc_req_q;
+#ifndef NAPIER_SCAN
 	qdf_spinlock_t hdd_scan_req_q_lock;
 	qdf_list_t hdd_scan_req_q;
+#endif
 	uint8_t miracast_value;
 
 #ifdef WLAN_NS_OFFLOAD
diff --git a/core/hdd/src/wlan_hdd_ioctl.c b/core/hdd/src/wlan_hdd_ioctl.c
index 3278e02..b8fe11f 100644
--- a/core/hdd/src/wlan_hdd_ioctl.c
+++ b/core/hdd/src/wlan_hdd_ioctl.c
@@ -6943,8 +6943,12 @@
 		hdd_err("value out of range");
 		return -EINVAL;
 	}
-
+#ifndef NAPIER_SCAN
+	/* This code will be removed*/
 	scan_pending = !qdf_list_empty(&hdd_ctx->hdd_scan_req_q);
+#else
+	scan_pending = ucfg_scan_get_pdev_status(hdd_ctx->hdd_pdev);
+#endif
 	status = sme_handle_set_fcc_channel(hdd_ctx->hHal, !fcc_constraint,
 					    scan_pending);
 	if (status != QDF_STATUS_SUCCESS) {
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 6e7463a..d749034 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -6900,9 +6900,9 @@
 	hdd_scan_context_destroy(hdd_ctx);
 	hdd_rx_wake_lock_destroy(hdd_ctx);
 	hdd_tdls_context_destroy(hdd_ctx);
-
 list_destroy:
 	qdf_list_destroy(&hdd_ctx->hddAdapters);
+
 	return ret;
 }
 
diff --git a/core/hdd/src/wlan_hdd_object_manager.c b/core/hdd/src/wlan_hdd_object_manager.c
index 0ea249b..a480c7a 100644
--- a/core/hdd/src/wlan_hdd_object_manager.c
+++ b/core/hdd/src/wlan_hdd_object_manager.c
@@ -38,6 +38,7 @@
 {
 	/* Initialize the OS private structure*/
 	os_priv->wiphy = hdd_ctx->wiphy;
+	wlan_cfg80211_scan_priv_init(hdd_ctx->hdd_pdev);
 }
 
 int hdd_create_and_store_psoc(hdd_context_t *hdd_ctx, uint8_t psoc_id)
@@ -82,15 +83,13 @@
 		hdd_err("pdev os obj create failed");
 		return -ENOMEM;
 	}
-
-	hdd_init_os_priv(hdd_ctx, priv);
-
 	pdev = wlan_objmgr_pdev_obj_create(psoc, priv);
 	if (!pdev) {
 		hdd_err("pdev obj create failed");
 		return -ENOMEM;
 	}
 	hdd_ctx->hdd_pdev = pdev;
+	hdd_init_os_priv(hdd_ctx, priv);
 
 	return 0;
 }
diff --git a/core/hdd/src/wlan_hdd_power.c b/core/hdd/src/wlan_hdd_power.c
index 610ce00..6a59be5 100644
--- a/core/hdd/src/wlan_hdd_power.c
+++ b/core/hdd/src/wlan_hdd_power.c
@@ -1308,8 +1308,11 @@
 
 	hdd_info("Invoking packetdump deregistration API");
 	wlan_deregister_txrx_packetdump();
-
+#ifndef NAPIER_SCAN
 	hdd_cleanup_scan_queue(pHddCtx);
+#else
+	wlan_cfg80211_abort_scan(pHddCtx->hdd_pdev);
+#endif
 	hdd_ipa_uc_ssr_deinit();
 	hdd_reset_all_adapters(pHddCtx);
 
diff --git a/core/hdd/src/wlan_hdd_scan.c b/core/hdd/src/wlan_hdd_scan.c
index a19e6a0..3cb76b6 100644
--- a/core/hdd/src/wlan_hdd_scan.c
+++ b/core/hdd/src/wlan_hdd_scan.c
@@ -52,6 +52,10 @@
 #endif
 #include <qca_vendor.h>
 
+#ifdef NAPIER_SCAN
+#include <wlan_cfg80211_scan.h>
+#endif
+
 #define MAX_RATES                       12
 #define HDD_WAKE_LOCK_SCAN_DURATION (5 * 1000) /* in msec */
 
@@ -70,7 +74,7 @@
 	eBCAST_HIDDEN = 2,
 } tSSIDBcastType;
 
-
+#ifndef NAPIER_SCAN
 /**
  * typedef hdd_scan_info_t - HDD scan info
  * @dev: Pointer to net device
@@ -84,7 +88,6 @@
 	char *start;
 	char *end;
 } hdd_scan_info_t, *hdd_scan_info_tp;
-
 /**
  * hdd_translate_abg_rate_to_mbps_rate() - translate abg rate to Mbps rate
  * @pFcRate: Rate pointer
@@ -191,7 +194,6 @@
 
 	return 0;
 }
-
 /**
  * hdd_indicate_scan_result() - indicate scan results
  * @scanInfo: Pointer to the scan info structure.
@@ -545,7 +547,6 @@
 	qdf_spin_unlock(&hdd_ctx->hdd_scan_req_q_lock);
 	return false;
 }
-
 /**
  * wlan_hdd_scan_request_enqueue() - enqueue Scan Request
  * @adapter: Pointer to the adapter
@@ -660,7 +661,6 @@
 	hdd_err("Failed to find scan id %d", scan_id);
 	return status;
 }
-
 /**
  * hdd_scan_request_callback() - scan complete callback from SME
  * @halHandle: Pointer to the Hal Handle
@@ -910,7 +910,6 @@
 
 	return ret;
 }
-
 /**
  * __iw_get_scan() - get scan
  * @dev: Pointer to the net device.
@@ -1013,6 +1012,7 @@
 
 	return ret;
 }
+#endif
 
 /**
  * hdd_abort_mac_scan() - aborts ongoing mac scan
@@ -1028,9 +1028,13 @@
 void hdd_abort_mac_scan(hdd_context_t *pHddCtx, uint8_t sessionId,
 			uint32_t scan_id, eCsrAbortReason reason)
 {
+#ifndef NAPIER_SCAN
 	sme_abort_mac_scan(pHddCtx->hHal, sessionId, scan_id, reason);
+#else
+	wlan_abort_scan(pHddCtx->hdd_pdev, INVAL_PDEV_ID, sessionId, scan_id);
+#endif
 }
-
+#ifndef NAPIER_SCAN
 /**
  * hdd_vendor_scan_callback() - Scan completed callback event
  * @hddctx: HDD context
@@ -1116,7 +1120,7 @@
 	qdf_mem_free(req);
 	return;
 }
-
+#endif
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0))
 /**
  * hdd_cfg80211_scan_done() - Scan completed callback to cfg80211
@@ -1175,7 +1179,7 @@
 	cfg80211_scan_done(req, aborted);
 }
 #endif
-
+#ifndef NAPIER_SCAN
 /**
  * hdd_cfg80211_scan_done_callback() - scan done callback function called after
  *				       scan is finished
@@ -1305,7 +1309,7 @@
 	EXIT();
 	return 0;
 }
-
+#endif
 #ifdef FEATURE_WLAN_AP_AP_ACS_OPTIMIZE
 /**
  * wlan_hdd_sap_skip_scan_check() - The function will check OBSS
@@ -1482,14 +1486,6 @@
  *
  * Return: 0 for success, non zero for failure
  */
-#ifdef WLAN_UMAC_CONVERGENCE
-static int __wlan_hdd_cfg80211_scan(struct wiphy *wiphy,
-				    struct cfg80211_scan_request *request,
-				    uint8_t source)
-{
-	return wlan_cfg80211_scan(wiphy, request);
-}
-#else
 static int __wlan_hdd_cfg80211_scan(struct wiphy *wiphy,
 				    struct cfg80211_scan_request *request,
 				    uint8_t source)
@@ -1497,17 +1493,19 @@
 	struct net_device *dev = request->wdev->netdev;
 	hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
 	hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
-	hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
 	struct hdd_config *cfg_param = NULL;
-	tCsrScanRequest scan_req;
-	uint8_t *channelList = NULL, i;
 	int status;
 	hdd_scaninfo_t *pScanInfo = NULL;
-	uint8_t *pP2pIe = NULL;
 	hdd_adapter_t *con_sap_adapter;
 	uint16_t con_dfs_ch;
+	hdd_wext_state_t *pwextBuf = WLAN_HDD_GET_WEXT_STATE_PTR(pAdapter);
+#ifndef NAPIER_SCAN
+	tCsrScanRequest scan_req;
+	uint8_t *channelList = NULL, i;
+	uint8_t *pP2pIe = NULL;
 	uint8_t num_chan = 0;
 	bool is_p2p_scan = false;
+#endif
 	uint8_t curr_session_id;
 	enum scan_reject_states curr_reason;
 
@@ -1524,7 +1522,6 @@
 	}
 
 	status = wlan_hdd_validate_context(pHddCtx);
-
 	if (0 != status)
 		return status;
 
@@ -1573,25 +1570,7 @@
 			return 0;
 		}
 	}
-	if (!wma_is_hw_dbs_capable()) {
-		if (true == pScanInfo->mScanPending) {
-			if (MAX_PENDING_LOG >
-				pScanInfo->mScanPendingCounter++) {
-				hdd_err("mScanPending is true");
-			}
-			return -EBUSY;
-		}
 
-		/* Don't Allow Scan and return busy if Remain On
-		 * Channel and action frame is pending
-		 * Otherwise Cancel Remain On Channel and allow Scan
-		 * If no action frame pending
-		 */
-		if (0 != wlan_hdd_check_remain_on_channel(pAdapter)) {
-			hdd_err("Remain On Channel Pending");
-			return -EBUSY;
-		}
-	}
 #ifdef FEATURE_WLAN_TDLS
 	/* if tdls disagree scan right now, return immediately.
 	 * tdls will schedule the scan when scan is allowed.
@@ -1660,6 +1639,33 @@
 		return 0;
 	}
 
+	/* Store the Scan IE's in Adapter*/
+	if (request->ie_len) {
+		/* save this for future association (join requires this) */
+		memset(&pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE));
+		memcpy(pScanInfo->scanAddIE.addIEdata, request->ie,
+		       request->ie_len);
+		pScanInfo->scanAddIE.length = request->ie_len;
+
+		if (wlan_hdd_update_scan_ies(pAdapter, pScanInfo,
+				pScanInfo->scanAddIE.addIEdata,
+				(uint8_t *)&pScanInfo->scanAddIE.length))
+			hdd_err("Update scan IEs with default Scan IEs failed");
+
+		if ((QDF_STA_MODE == pAdapter->device_mode) ||
+		    (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) ||
+		    (QDF_P2P_DEVICE_MODE == pAdapter->device_mode)
+		    ) {
+			pwextBuf->roamProfile.pAddIEScan =
+				pScanInfo->scanAddIE.addIEdata;
+			pwextBuf->roamProfile.nAddIEScanLength =
+				pScanInfo->scanAddIE.length;
+		}
+	}
+#ifdef NAPIER_SCAN
+	return wlan_cfg80211_scan(pHddCtx->hdd_pdev, request, source);
+#else
+	/* Below code will be removed once common scan module is available.*/
 	qdf_mem_zero(&scan_req, sizeof(scan_req));
 
 	scan_req.timestamp = qdf_mc_timer_get_system_time();
@@ -1782,27 +1788,6 @@
 			pAdapter->sessionId);
 	}
 	if (request->ie_len) {
-		/* save this for future association (join requires this) */
-		memset(&pScanInfo->scanAddIE, 0, sizeof(pScanInfo->scanAddIE));
-		memcpy(pScanInfo->scanAddIE.addIEdata, request->ie,
-		       request->ie_len);
-		pScanInfo->scanAddIE.length = request->ie_len;
-
-		if (wlan_hdd_update_scan_ies(pAdapter, pScanInfo,
-				pScanInfo->scanAddIE.addIEdata,
-				(uint8_t *)&pScanInfo->scanAddIE.length))
-			hdd_err("Update scan IEs with default Scan IEs failed");
-
-		if ((QDF_STA_MODE == pAdapter->device_mode) ||
-		    (QDF_P2P_CLIENT_MODE == pAdapter->device_mode) ||
-		    (QDF_P2P_DEVICE_MODE == pAdapter->device_mode)
-		    ) {
-			pwextBuf->roamProfile.pAddIEScan =
-				pScanInfo->scanAddIE.addIEdata;
-			pwextBuf->roamProfile.nAddIEScanLength =
-				pScanInfo->scanAddIE.length;
-		}
-
 		scan_req.uIEFieldLen = pScanInfo->scanAddIE.length;
 		scan_req.pIEField = pScanInfo->scanAddIE.addIEdata;
 
@@ -1906,7 +1891,6 @@
 			scan_req.scan_id, scan_req.timestamp);
 	pAdapter->scan_info.mScanPending = true;
 	pHddCtx->beacon_probe_rsp_cnt_per_scan = 0;
-
 free_mem:
 	if (scan_req.SSIDs.SSIDList)
 		qdf_mem_free(scan_req.SSIDs.SSIDList);
@@ -1916,9 +1900,10 @@
 
 	EXIT();
 	return status;
-}
 #endif
 
+}
+
 /**
  * wlan_hdd_cfg80211_scan() - API to process cfg80211 scan request
  * @wiphy: Pointer to wiphy
@@ -2310,6 +2295,8 @@
 
 	return ret;
 }
+/* Below code will be removed once common scan module is available.*/
+#ifndef NAPIER_SCAN
 /**
  * wlan_hdd_get_scanid() - API to get the scan id
  * from the scan cookie attribute.
@@ -2362,6 +2349,7 @@
 	return ret;
 
 }
+#endif
 /**
  * __wlan_hdd_vendor_abort_scan() - API to process vendor command for
  * abort scan
@@ -2379,9 +2367,11 @@
 		int data_len)
 {
 	hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
+#ifndef NAPIER_SCAN
 	struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_SCAN_MAX + 1];
 	uint32_t scan_id;
 	uint64_t cookie;
+#endif
 	int ret;
 
 	if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
@@ -2393,6 +2383,8 @@
 	if (0 != ret)
 		return ret;
 
+/* Below code will be removed once common scan module is available.*/
+#ifndef NAPIER_SCAN
 	ret = -EINVAL;
 	if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_SCAN_MAX, data,
 	    data_len, NULL)) {
@@ -2413,7 +2405,10 @@
 				   scan_id,
 				   eCSR_SCAN_ABORT_DEFAULT);
 	}
-
+#else
+	wlan_vendor_abort_scan(hdd_ctx->hdd_pdev, data,
+				data_len);
+#endif
 	return ret;
 }
 
@@ -3058,8 +3053,11 @@
 	if (!ret)
 		return;
 
+#ifndef NAPIER_SCAN
 	wlan_hdd_scan_abort(adapter);
-
+#else
+	wlan_cfg80211_abort_scan(hdd_ctx->hdd_pdev);
+#endif
 	EXIT();
 }
 
@@ -3081,7 +3079,7 @@
 	cds_ssr_unprotect(__func__);
 }
 #endif
-
+#ifndef NAPIER_SCAN
 /**
  * hdd_cleanup_scan_queue() - remove entries in scan queue
  *
@@ -3133,6 +3131,7 @@
 
 	return;
 }
+#endif
 
 /**
  * hdd_scan_context_destroy() - Destroy scan context
@@ -3144,7 +3143,9 @@
  */
 void hdd_scan_context_destroy(hdd_context_t *hdd_ctx)
 {
+#ifndef NAPIER_SCAN
 	qdf_list_destroy(&hdd_ctx->hdd_scan_req_q);
+#endif
 	qdf_spinlock_destroy(&hdd_ctx->sched_scan_lock);
 }
 
@@ -3159,9 +3160,9 @@
 int hdd_scan_context_init(hdd_context_t *hdd_ctx)
 {
 	qdf_spinlock_create(&hdd_ctx->sched_scan_lock);
-
+#ifndef NAPIER_SCAN
 	qdf_spinlock_create(&hdd_ctx->hdd_scan_req_q_lock);
 	qdf_list_create(&hdd_ctx->hdd_scan_req_q, CFG_MAX_SCAN_COUNT_MAX);
-
+#endif
 	return 0;
 }
diff --git a/core/hdd/src/wlan_hdd_scan.h b/core/hdd/src/wlan_hdd_scan.h
index 08e1091..046e739 100644
--- a/core/hdd/src/wlan_hdd_scan.h
+++ b/core/hdd/src/wlan_hdd_scan.h
@@ -30,6 +30,7 @@
 #define WLAN_HDD_SCAN_H
 
 #include "wlan_hdd_main.h"
+#include <wlan_cfg80211_scan.h>
 
 #define MAX_PENDING_LOG 5
 
diff --git a/core/hdd/src/wlan_hdd_wext.c b/core/hdd/src/wlan_hdd_wext.c
index 566536a..0215f62 100644
--- a/core/hdd/src/wlan_hdd_wext.c
+++ b/core/hdd/src/wlan_hdd_wext.c
@@ -12182,8 +12182,13 @@
 	(iw_handler) iw_get_ap_address, /* SIOCGIWAP */
 	(iw_handler) iw_set_mlme,       /* SIOCSIWMLME */
 	(iw_handler) NULL,      /* SIOCGIWAPLIST */
+#ifndef NAPIER_SCAN
 	(iw_handler) iw_set_scan,       /* SIOCSIWSCAN */
 	(iw_handler) iw_get_scan,       /* SIOCGIWSCAN */
+#else
+	(iw_handler) NULL,       /* SIOCSIWSCAN */
+	(iw_handler) NULL,       /* SIOCGIWSCAN */
+#endif
 	(iw_handler) iw_set_essid,      /* SIOCSIWESSID */
 	(iw_handler) iw_get_essid,      /* SIOCGIWESSID */
 	(iw_handler) iw_set_nick,       /* SIOCSIWNICKN */
diff --git a/core/wma/src/wma_main.c b/core/wma/src/wma_main.c
index 4acae1e..fd7e39a 100644
--- a/core/wma/src/wma_main.c
+++ b/core/wma/src/wma_main.c
@@ -3000,7 +3000,7 @@
 		qdf_status = QDF_STATUS_E_INVAL;
 		goto end;
 	}
-
+#ifndef NAPIER_SCAN
 	status = wmi_unified_register_event_handler(wma_handle->wmi_handle,
 						    WMI_SCAN_EVENTID,
 						    wma_scan_event_callback,
@@ -3010,7 +3010,7 @@
 		qdf_status = QDF_STATUS_E_FAILURE;
 		goto end;
 	}
-
+#endif
 	status = wmi_unified_register_event_handler(wma_handle->wmi_handle,
 						    WMI_ROAM_EVENTID,
 						    wma_roam_event_callback,