iwlagn: reprogram AP STA after assoc

Instead of unconditionally sending unassoc RXON,
before any assoc RXON, re-send only the AP STA
entry which is required after the BSSID has been
programmed into the device to set up internal
filters in the microcode properly.

This fixes some issues that we correlated with
sending a lot of RXON commands to the device.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
index fbaa8d2..9db3924 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
@@ -97,6 +97,7 @@
 	/* cast away the const for active_rxon in this function */
 	struct iwl_rxon_cmd *active = (void *)&ctx->active;
 	bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
+	bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
 	int ret;
 
 	lockdep_assert_held(&priv->mutex);
@@ -176,25 +177,27 @@
 	 * AP station must be done after the BSSID is set to correctly
 	 * set up filters in the device.
 	 */
-	if (ctx->ctxid == IWL_RXON_CTX_BSS)
-		ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
-	else
-		ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
-	if (ret)
-		return ret;
+	if ((old_assoc && new_assoc) || !new_assoc) {
+		if (ctx->ctxid == IWL_RXON_CTX_BSS)
+			ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
+		else
+			ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
+		if (ret)
+			return ret;
 
-	memcpy(active, &ctx->staging, sizeof(*active));
+		memcpy(active, &ctx->staging, sizeof(*active));
 
-	/*
-	 * Un-assoc RXON clears the station table and WEP
-	 * keys, so we have to restore those afterwards.
-	 */
-	iwl_clear_ucode_stations(priv, ctx);
-	iwl_restore_stations(priv, ctx);
-	ret = iwl_restore_default_wep_keys(priv, ctx);
-	if (ret) {
-		IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
-		return ret;
+		/*
+		 * Un-assoc RXON clears the station table and WEP
+		 * keys, so we have to restore those afterwards.
+		 */
+		iwl_clear_ucode_stations(priv, ctx);
+		iwl_restore_stations(priv, ctx);
+		ret = iwl_restore_default_wep_keys(priv, ctx);
+		if (ret) {
+			IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
+			return ret;
+		}
 	}
 
 	/* RXON timing must be before associated RXON */
@@ -235,6 +238,8 @@
 		}
 		memcpy(active, &ctx->staging, sizeof(*active));
 
+		iwl_reprogram_ap_sta(priv, ctx);
+
 		/* IBSS beacon needs to be sent after setting assoc */
 		if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
 			if (iwlagn_update_beacon(priv, ctx->vif))