linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Emmanuel Grumbach <egrumbach@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: Andrei Otcheretianski <andrei.otcheretianski@intel.com>,
	Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Subject: [PATCH 33/40] iwlwifi: mvm: Reflect GO channel switch in NoA
Date: Sun,  6 Jul 2014 12:36:09 +0300	[thread overview]
Message-ID: <1404639376-3792-33-git-send-email-egrumbach@gmail.com> (raw)
In-Reply-To: <53B917DC.5050902@gmail.com>

From: Andrei Otcheretianski <andrei.otcheretianski@intel.com>

According to the spec, GO/AP should perform the channel switch just
before "beacon 0". However, since the exact timing isn't defined,
it may result in a sudden GO disappearance from the channel.
Prevent potential packet loss when performing the CS by scheduling
NoA time event and executing the channel switch flow when a notification
from fw is received.

Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
Reviewed-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
---
 drivers/net/wireless/iwlwifi/mvm/fw-api.h     |  3 ++
 drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c   | 41 +++++++++++----
 drivers/net/wireless/iwlwifi/mvm/mac80211.c   |  5 +-
 drivers/net/wireless/iwlwifi/mvm/mvm.h        | 12 +++++
 drivers/net/wireless/iwlwifi/mvm/time-event.c | 73 +++++++++++++++++++++++++++
 drivers/net/wireless/iwlwifi/mvm/time-event.h | 29 +++++++++++
 6 files changed, 153 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/iwlwifi/mvm/fw-api.h b/drivers/net/wireless/iwlwifi/mvm/fw-api.h
index 6c479de..99329ed 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw-api.h
+++ b/drivers/net/wireless/iwlwifi/mvm/fw-api.h
@@ -538,6 +538,9 @@ enum iwl_time_event_type {
 	/* WiDi Sync Events */
 	TE_WIDI_TX_SYNC,
 
+	/* Channel Switch NoA */
+	TE_P2P_GO_CSA_NOA,
+
 	TE_MAX
 }; /* MAC_EVENT_TYPE_API_E_VER_1 */
 
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c b/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
index 19bd696..a176d00 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
@@ -67,6 +67,7 @@
 #include "iwl-prph.h"
 #include "fw-api.h"
 #include "mvm.h"
+#include "time-event.h"
 
 const u8 iwl_mvm_ac_to_tx_fifo[] = {
 	IWL_MVM_TX_FIFO_VO,
@@ -1200,6 +1201,35 @@ int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
 	return 0;
 }
 
+static void iwl_mvm_csa_count_down(struct iwl_mvm *mvm,
+				   struct ieee80211_vif *csa_vif, u32 gp2)
+{
+	struct iwl_mvm_vif *mvmvif =
+			iwl_mvm_vif_from_mac80211(csa_vif);
+
+	if (!ieee80211_csa_is_complete(csa_vif)) {
+		int c = ieee80211_csa_update_counter(csa_vif);
+
+		iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
+		if (csa_vif->p2p &&
+		    !iwl_mvm_te_scheduled(&mvmvif->time_event_data) && gp2) {
+			u32 rel_time = (c + 1) *
+				       csa_vif->bss_conf.beacon_int -
+				       IWL_MVM_CHANNEL_SWITCH_TIME;
+			u32 apply_time = gp2 + rel_time * 1024;
+
+			iwl_mvm_schedule_csa_noa(mvm, csa_vif,
+						 IWL_MVM_CHANNEL_SWITCH_TIME -
+						 IWL_MVM_CHANNEL_SWITCH_MARGIN,
+						 apply_time);
+		}
+	} else if (!iwl_mvm_te_scheduled(&mvmvif->time_event_data)) {
+		/* we don't have CSA NoA scheduled yet, switch now */
+		ieee80211_csa_finish(csa_vif);
+		RCU_INIT_POINTER(mvm->csa_vif, NULL);
+	}
+}
+
 int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
 			    struct iwl_rx_cmd_buffer *rxb,
 			    struct iwl_device_cmd *cmd)
@@ -1234,15 +1264,8 @@ int iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
 
 	csa_vif = rcu_dereference_protected(mvm->csa_vif,
 					    lockdep_is_held(&mvm->mutex));
-	if (unlikely(csa_vif && csa_vif->csa_active)) {
-		if (!ieee80211_csa_is_complete(csa_vif)) {
-			ieee80211_csa_update_counter(csa_vif);
-			iwl_mvm_mac_ctxt_beacon_changed(mvm, csa_vif);
-		} else {
-			ieee80211_csa_finish(csa_vif);
-			RCU_INIT_POINTER(mvm->csa_vif, NULL);
-		}
-	}
+	if (unlikely(csa_vif && csa_vif->csa_active))
+		iwl_mvm_csa_count_down(mvm, csa_vif, mvm->ap_last_beacon_gp2);
 
 	return 0;
 }
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index 984a1e7..4a0350f 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -1608,8 +1608,11 @@ static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
 	mutex_lock(&mvm->mutex);
 
 	/* Handle AP stop while in CSA */
-	if (rcu_access_pointer(mvm->csa_vif) == vif)
+	if (rcu_access_pointer(mvm->csa_vif) == vif) {
+		iwl_mvm_remove_time_event(mvm, mvmvif,
+					  &mvmvif->time_event_data);
 		RCU_INIT_POINTER(mvm->csa_vif, NULL);
+	}
 
 	mvmvif->ap_ibss_active = false;
 	mvm->ap_last_beacon_gp2 = 0;
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index 5bb42af..db496c5 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -83,6 +83,18 @@
 #define IWL_RSSI_OFFSET 50
 #define IWL_MVM_MISSED_BEACONS_THRESHOLD 8
 
+/*
+ * The CSA NoA is scheduled IWL_MVM_CHANNEL_SWITCH_TIME TUs before "beacon 0"
+ * TBTT. This value should be big enough to ensure that we switch in time.
+ */
+#define IWL_MVM_CHANNEL_SWITCH_TIME 40
+
+/*
+ * This value (in TUs) is used to fine tune the CSA NoA end time which should
+ * be just before "beacon 0" TBTT.
+ */
+#define IWL_MVM_CHANNEL_SWITCH_MARGIN 4
+
 enum iwl_mvm_tx_fifo {
 	IWL_MVM_TX_FIFO_BK = 0,
 	IWL_MVM_TX_FIFO_BE,
diff --git a/drivers/net/wireless/iwlwifi/mvm/time-event.c b/drivers/net/wireless/iwlwifi/mvm/time-event.c
index 80100f6..ae52613 100644
--- a/drivers/net/wireless/iwlwifi/mvm/time-event.c
+++ b/drivers/net/wireless/iwlwifi/mvm/time-event.c
@@ -138,6 +138,41 @@ static void iwl_mvm_roc_finished(struct iwl_mvm *mvm)
 	schedule_work(&mvm->roc_done_wk);
 }
 
+static void iwl_mvm_csa_noa_start(struct iwl_mvm *mvm)
+{
+	struct ieee80211_vif *csa_vif;
+
+	rcu_read_lock();
+
+	csa_vif = rcu_dereference(mvm->csa_vif);
+	if (!csa_vif || !csa_vif->csa_active)
+		goto out_unlock;
+
+	IWL_DEBUG_TE(mvm, "CSA NOA started\n");
+
+	/*
+	 * CSA NoA is started but we still have beacons to
+	 * transmit on the current channel.
+	 * So we just do nothing here and the switch
+	 * will be performed on the last TBTT.
+	 */
+	if (!ieee80211_csa_is_complete(csa_vif)) {
+		IWL_WARN(mvm, "CSA NOA started too early\n");
+		goto out_unlock;
+	}
+
+	ieee80211_csa_finish(csa_vif);
+
+	rcu_read_unlock();
+
+	RCU_INIT_POINTER(mvm->csa_vif, NULL);
+
+	return;
+
+out_unlock:
+	rcu_read_unlock();
+}
+
 static bool iwl_mvm_te_check_disconnect(struct iwl_mvm *mvm,
 					struct ieee80211_vif *vif,
 					const char *errmsg)
@@ -213,6 +248,14 @@ static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
 			set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
 			iwl_mvm_ref(mvm, IWL_MVM_REF_ROC);
 			ieee80211_ready_on_channel(mvm->hw);
+		} else if (te_data->vif->type == NL80211_IFTYPE_AP) {
+			if (le32_to_cpu(notif->status))
+				iwl_mvm_csa_noa_start(mvm);
+			else
+				IWL_DEBUG_TE(mvm, "CSA NOA failed to start\n");
+
+			/* we don't need it anymore */
+			iwl_mvm_te_clear_data(mvm, te_data);
 		}
 	} else {
 		IWL_WARN(mvm, "Got TE with unknown action\n");
@@ -538,3 +581,33 @@ void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm)
 
 	iwl_mvm_roc_finished(mvm);
 }
+
+int iwl_mvm_schedule_csa_noa(struct iwl_mvm *mvm,
+			      struct ieee80211_vif *vif,
+			      u32 duration, u32 apply_time)
+{
+	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
+	struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
+	struct iwl_time_event_cmd time_cmd = {};
+
+	lockdep_assert_held(&mvm->mutex);
+
+	if (te_data->running) {
+		IWL_DEBUG_TE(mvm, "CS NOA is already scheduled\n");
+		return -EBUSY;
+	}
+
+	time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
+	time_cmd.id_and_color =
+		cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
+	time_cmd.id = cpu_to_le32(TE_P2P_GO_CSA_NOA);
+	time_cmd.apply_time = cpu_to_le32(apply_time);
+	time_cmd.max_frags = TE_V2_FRAG_NONE;
+	time_cmd.duration = cpu_to_le32(duration);
+	time_cmd.repeat = 1;
+	time_cmd.interval = cpu_to_le32(1);
+	time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
+				      TE_V2_ABSENCE);
+
+	return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
+}
diff --git a/drivers/net/wireless/iwlwifi/mvm/time-event.h b/drivers/net/wireless/iwlwifi/mvm/time-event.h
index 4a61c8c..2f48a90 100644
--- a/drivers/net/wireless/iwlwifi/mvm/time-event.h
+++ b/drivers/net/wireless/iwlwifi/mvm/time-event.h
@@ -214,4 +214,33 @@ void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
 
 void iwl_mvm_roc_done_wk(struct work_struct *wk);
 
+/**
+ * iwl_mvm_schedule_csa_noa - request NoA for channel switch
+ * @mvm: the mvm component
+ * @vif: the virtual interface for which the channel switch is issued
+ * @duration: the duration of the NoA in TU.
+ * @apply_time: NoA start time in GP2.
+ *
+ * This function is used to schedule NoA time event and is used to perform
+ * the channel switch flow.
+ */
+int iwl_mvm_schedule_csa_noa(struct iwl_mvm *mvm,
+			     struct ieee80211_vif *vif,
+			     u32 duration, u32 apply_time);
+
+/**
+ * iwl_mvm_te_scheduled - check if the fw received the TE cmd
+ * @te_data: the time event data that corresponds to that time event
+ *
+ * This function returns true iff this TE is added to the fw.
+ */
+static inline bool
+iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data *te_data)
+{
+	if (!te_data)
+		return false;
+
+	return !!te_data->uid;
+}
+
 #endif /* __time_event_h__ */
-- 
1.8.3.2


  parent reply	other threads:[~2014-07-06  9:37 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-06  9:33 pull request: iwlwifi-next 2014-07-06 Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 01/40] iwlwifi: fix naming mistake for the fw_monitor module parameter Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 02/40] iwlwifi: remove wrong comment about alignment in iwl-fw-error-dump.h Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 03/40] iwlwifi: mvm: don't collect logs in the interrupt thread Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 04/40] iwlwifi: mvm: kill iwl_mvm_fw_error_rxf_dump Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 05/40] iwlwifi: mvm: update layout of firmware error dump Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 06/40] iwlwifi: mvm: wait for d0i3 exit in add interface flow Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 07/40] iwlwifi: mvm: read the mac address in family 8000 Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 08/40] iwlwifi: rename iwl_fw_error_fw_mon to iwl_fw_error_dump_fw_mon Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 09/40] iwlwifi: mvm: remove unused flags from TX command Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 10/40] iwlwifi: mvm: BT Coex - prepare towards new API Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 11/40] iwlwifi: mvm: BT Coex - " Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 12/40] iwlwifi: mvm: BT Coex - convert the sw boost update to " Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 13/40] iwlwifi: mvm: BT Coex - convert the co-running " Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 14/40] iwlwifi: mvm: BT Coex - convert reduced Tx power " Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 15/40] iwlwifi: mvm: BT Coex - add High Band retention Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 16/40] iwlwifi: mvm: BT Coex - fix debugfs with old API Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 17/40] iwlwifi: mvm: warn about empty OTP Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 18/40] iwlwifi: mvm: rs: don't clear persistent fields Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 19/40] iwlwifi: mvm: rs: don't save debugfs files Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 20/40] iwlwifi: mvm: add unified LMAC scan API Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 21/40] iwlwifi: mvm: init lmac scan command Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 22/40] iwlwifi: mvm: fix endianity in " Emmanuel Grumbach
2014-07-06  9:35 ` [PATCH 23/40] iwlwifi: 8000: drop a print when the address is invalid Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 24/40] iwlwifi: mvm: let iwl_mvm_update_quotas disregard a disabled vif Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 25/40] iwlwifi: mvm: don't send zero quota to the firmware Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 26/40] iwlwifi: mvm: validate that we don't send zero quota Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 27/40] iwlwifi: mvm: don't pass update type to quota iterator Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 28/40] iwlwifi: mvm: remove update type argument from quota update Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 29/40] iwlwifi: mvm: add switch_vif_chanctx operation Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 30/40] iwlwifi: mvm: CSA unbind-bind flow support for client Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 31/40] iwlwifi: mvm: Use beacon_get_template instead of beacon_get Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 32/40] iwlwifi: mvm: Protect mvm->csa_vif with RCU Emmanuel Grumbach
2014-07-06  9:36 ` Emmanuel Grumbach [this message]
2014-07-06  9:36 ` [PATCH 34/40] iwlwifi: mvm: Use CS tx block bit for AP/GO Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 35/40] iwlwifi: mvm: disallow new TDLS stations when appropriate Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 36/40] iwlwifi: mvm: protect TDLS discovery session Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 37/40] iwlwifi: disable PSM on vifs with associated TDLS peers Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 38/40] iwlwifi: mvm: teardown TDLS peers when initiating DCM Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 39/40] iwlwifi: mvm: remove 8000 HW family setting of adc sampling on nic config Emmanuel Grumbach
2014-07-06  9:36 ` [PATCH 40/40] iwlwifi: mvm: minor fix in comment Emmanuel Grumbach
2014-07-07 18:44 ` pull request: iwlwifi-next 2014-07-06 Emmanuel Grumbach
2014-07-07 20:08   ` John W. Linville

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404639376-3792-33-git-send-email-egrumbach@gmail.com \
    --to=egrumbach@gmail.com \
    --cc=andrei.otcheretianski@intel.com \
    --cc=emmanuel.grumbach@intel.com \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).