iwlwifi: mvm: convert scan_status to a bitmap

LMAC scans cannot handle more than one scan at a time, but UMAC scans
can.  To avoid confusion we should combine the states of these two
types of scans.  To do so, we need to support mutliple scans at the
same time for UMAC.

This commit changes the scan_status element from a single value to a
bitmask of running scan types for LMAC.  Later, we will modify UMAC
scans to use the same state bitmask.

Additionally, add stopping scan flags for scheduled and regular scans.
This makes it easier to differentiate and handle stop requests
triggered by the driver and spontaneous stops generated by the
firmware.

Signed-off-by: Luciano Coelho <luciano.coelho@intel.com>
Reviewed-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index f44bb17..aff7de7 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -1227,7 +1227,7 @@
 
 	iwl_trans_stop_device(mvm->trans);
 
-	mvm->scan_status = IWL_MVM_SCAN_NONE;
+	mvm->scan_status = 0;
 	mvm->ps_disabled = false;
 	mvm->calibrating = false;
 
@@ -2374,28 +2374,30 @@
 }
 
 static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
-					  enum iwl_scan_status scan_type)
+					  unsigned int scan_type)
 {
 	int ret;
 	bool wait_for_handlers = false;
 
 	mutex_lock(&mvm->mutex);
 
-	if (mvm->scan_status != scan_type) {
+	if (!(mvm->scan_status & scan_type)) {
 		ret = 0;
 		/* make sure there are no pending notifications */
 		wait_for_handlers = true;
 		goto out;
 	}
 
+	/* It's okay to switch on bitmask values here, because we can
+	 * only stop one scan type at a time.
+	 */
 	switch (scan_type) {
 	case IWL_MVM_SCAN_SCHED:
 		ret = iwl_mvm_scan_offload_stop(mvm, true);
 		break;
-	case IWL_MVM_SCAN_OS:
+	case IWL_MVM_SCAN_REGULAR:
 		ret = iwl_mvm_cancel_scan(mvm);
 		break;
-	case IWL_MVM_SCAN_NONE:
 	default:
 		WARN_ON_ONCE(1);
 		ret = -EINVAL;
@@ -2440,7 +2442,7 @@
 		goto out;
 	}
 
-	if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
+	if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) {
 		ret = -EBUSY;
 		goto out;
 	}
@@ -2476,7 +2478,7 @@
 	/* FIXME: for now, we ignore this race for UMAC scans, since
 	 * they don't set the scan_status.
 	 */
-	if ((mvm->scan_status == IWL_MVM_SCAN_OS) ||
+	if ((mvm->scan_status & IWL_MVM_SCAN_REGULAR) ||
 	    (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN))
 		iwl_mvm_cancel_scan(mvm);
 
@@ -2797,7 +2799,7 @@
 	int ret;
 
 	if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
-		ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
+		ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_REGULAR);
 		if (ret)
 			return ret;
 	}
@@ -2815,14 +2817,14 @@
 		goto out;
 	}
 
-	if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
+	if (mvm->scan_status & IWL_MVM_SCAN_SCHED) {
 		ret = -EBUSY;
 		goto out;
 	}
 
 	ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
 	if (ret)
-		mvm->scan_status = IWL_MVM_SCAN_NONE;
+		mvm->scan_status &= ~IWL_MVM_SCAN_SCHED;
 
 out:
 	mutex_unlock(&mvm->mutex);
@@ -2848,7 +2850,7 @@
 	/* FIXME: for now, we ignore this race for UMAC scans, since
 	 * they don't set the scan_status.
 	 */
-	if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
+	if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED) &&
 	    !(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
 		mutex_unlock(&mvm->mutex);
 		return 0;