aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-03-29 16:50:10 -0400
committerDavid S. Miller <davem@davemloft.net>2010-03-29 16:50:10 -0400
commit7905e357ebe67a26d9dc8caa1a0b8346431b5f0d (patch)
tree134442df2f062caa6cebda1b352948b8209efcec /drivers/net/wireless/iwlwifi
parent083ba279d52bcad20f1dfa3cefd4255cbe82d521 (diff)
parent76232ebf898c4d5e657f2b663fbf7108bca80ded (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6
Diffstat (limited to 'drivers/net/wireless/iwlwifi')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c83
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c22
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c28
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c24
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c124
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c154
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c102
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h19
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h23
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c155
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c630
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c72
18 files changed, 987 insertions, 493 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 59b092eaa829..9e392896005d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -212,6 +212,9 @@ static struct iwl_lib_ops iwl1000_lib = {
212 .set_ct_kill = iwl1000_set_ct_threshold, 212 .set_ct_kill = iwl1000_set_ct_threshold,
213 }, 213 },
214 .add_bcast_station = iwl_add_bcast_station, 214 .add_bcast_station = iwl_add_bcast_station,
215 .recover_from_tx_stall = iwl_bg_monitor_recover,
216 .check_plcp_health = iwl_good_plcp_health,
217 .check_ack_health = iwl_good_ack_health,
215}; 218};
216 219
217static const struct iwl_ops iwl1000_ops = { 220static const struct iwl_ops iwl1000_ops = {
@@ -223,7 +226,7 @@ static const struct iwl_ops iwl1000_ops = {
223}; 226};
224 227
225struct iwl_cfg iwl1000_bgn_cfg = { 228struct iwl_cfg iwl1000_bgn_cfg = {
226 .name = "1000 Series BGN", 229 .name = "Intel(R) Centrino(R) Wireless-N 1000 BGN",
227 .fw_name_pre = IWL1000_FW_PRE, 230 .fw_name_pre = IWL1000_FW_PRE,
228 .ucode_api_max = IWL1000_UCODE_API_MAX, 231 .ucode_api_max = IWL1000_UCODE_API_MAX,
229 .ucode_api_min = IWL1000_UCODE_API_MIN, 232 .ucode_api_min = IWL1000_UCODE_API_MIN,
@@ -249,10 +252,11 @@ struct iwl_cfg iwl1000_bgn_cfg = {
249 .support_ct_kill_exit = true, 252 .support_ct_kill_exit = true,
250 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, 253 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
251 .chain_noise_scale = 1000, 254 .chain_noise_scale = 1000,
255 .monitor_recover_period = IWL_MONITORING_PERIOD,
252}; 256};
253 257
254struct iwl_cfg iwl1000_bg_cfg = { 258struct iwl_cfg iwl1000_bg_cfg = {
255 .name = "1000 Series BG", 259 .name = "Intel(R) Centrino(R) Wireless-N 1000 BG",
256 .fw_name_pre = IWL1000_FW_PRE, 260 .fw_name_pre = IWL1000_FW_PRE,
257 .ucode_api_max = IWL1000_UCODE_API_MAX, 261 .ucode_api_max = IWL1000_UCODE_API_MAX,
258 .ucode_api_min = IWL1000_UCODE_API_MIN, 262 .ucode_api_min = IWL1000_UCODE_API_MIN,
@@ -277,6 +281,7 @@ struct iwl_cfg iwl1000_bg_cfg = {
277 .support_ct_kill_exit = true, 281 .support_ct_kill_exit = true,
278 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, 282 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
279 .chain_noise_scale = 1000, 283 .chain_noise_scale = 1000,
284 .monitor_recover_period = IWL_MONITORING_PERIOD,
280}; 285};
281 286
282MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX)); 287MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX));
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index b588cb69536a..605aca4c78c8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -329,16 +329,25 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
329 329
330} 330}
331 331
332static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband, 332/*
333 struct ieee80211_sta *sta, void *priv_sta) 333 * Called after adding a new station to initialize rate scaling
334 */
335void iwl3945_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id)
334{ 336{
335 struct iwl3945_rs_sta *rs_sta = priv_sta; 337 struct ieee80211_hw *hw = priv->hw;
336 struct iwl_priv *priv = (struct iwl_priv *)priv_r; 338 struct ieee80211_conf *conf = &priv->hw->conf;
339 struct iwl3945_sta_priv *psta;
340 struct iwl3945_rs_sta *rs_sta;
341 struct ieee80211_supported_band *sband;
337 int i; 342 int i;
338 343
339 IWL_DEBUG_RATE(priv, "enter\n"); 344 IWL_DEBUG_INFO(priv, "enter \n");
345 if (sta_id == priv->hw_params.bcast_sta_id)
346 goto out;
340 347
341 spin_lock_init(&rs_sta->lock); 348 psta = (struct iwl3945_sta_priv *) sta->drv_priv;
349 rs_sta = &psta->rs_sta;
350 sband = hw->wiphy->bands[conf->channel->band];
342 351
343 rs_sta->priv = priv; 352 rs_sta->priv = priv;
344 353
@@ -351,9 +360,7 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
351 rs_sta->last_flush = jiffies; 360 rs_sta->last_flush = jiffies;
352 rs_sta->flush_time = IWL_RATE_FLUSH; 361 rs_sta->flush_time = IWL_RATE_FLUSH;
353 rs_sta->last_tx_packets = 0; 362 rs_sta->last_tx_packets = 0;
354 rs_sta->ibss_sta_added = 0;
355 363
356 init_timer(&rs_sta->rate_scale_flush);
357 rs_sta->rate_scale_flush.data = (unsigned long)rs_sta; 364 rs_sta->rate_scale_flush.data = (unsigned long)rs_sta;
358 rs_sta->rate_scale_flush.function = iwl3945_bg_rate_scale_flush; 365 rs_sta->rate_scale_flush.function = iwl3945_bg_rate_scale_flush;
359 366
@@ -380,8 +387,10 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
380 IWL_FIRST_OFDM_RATE; 387 IWL_FIRST_OFDM_RATE;
381 } 388 }
382 389
390out:
391 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
383 392
384 IWL_DEBUG_RATE(priv, "leave\n"); 393 IWL_DEBUG_INFO(priv, "leave\n");
385} 394}
386 395
387static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir) 396static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
@@ -405,6 +414,9 @@ static void *rs_alloc_sta(void *iwl_priv, struct ieee80211_sta *sta, gfp_t gfp)
405 414
406 rs_sta = &psta->rs_sta; 415 rs_sta = &psta->rs_sta;
407 416
417 spin_lock_init(&rs_sta->lock);
418 init_timer(&rs_sta->rate_scale_flush);
419
408 IWL_DEBUG_RATE(priv, "leave\n"); 420 IWL_DEBUG_RATE(priv, "leave\n");
409 421
410 return rs_sta; 422 return rs_sta;
@@ -413,13 +425,14 @@ static void *rs_alloc_sta(void *iwl_priv, struct ieee80211_sta *sta, gfp_t gfp)
413static void rs_free_sta(void *iwl_priv, struct ieee80211_sta *sta, 425static void rs_free_sta(void *iwl_priv, struct ieee80211_sta *sta,
414 void *priv_sta) 426 void *priv_sta)
415{ 427{
416 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv; 428 struct iwl3945_rs_sta *rs_sta = priv_sta;
417 struct iwl3945_rs_sta *rs_sta = &psta->rs_sta;
418 struct iwl_priv *priv __maybe_unused = rs_sta->priv;
419 429
420 IWL_DEBUG_RATE(priv, "enter\n"); 430 /*
431 * Be careful not to use any members of iwl3945_rs_sta (like trying
432 * to use iwl_priv to print out debugging) since it may not be fully
433 * initialized at this point.
434 */
421 del_timer_sync(&rs_sta->rate_scale_flush); 435 del_timer_sync(&rs_sta->rate_scale_flush);
422 IWL_DEBUG_RATE(priv, "leave\n");
423} 436}
424 437
425 438
@@ -458,6 +471,13 @@ static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband
458 return; 471 return;
459 } 472 }
460 473
474 /* Treat uninitialized rate scaling data same as non-existing. */
475 if (!rs_sta->priv) {
476 IWL_DEBUG_RATE(priv, "leave: STA priv data uninitialized!\n");
477 return;
478 }
479
480
461 rs_sta->tx_packets++; 481 rs_sta->tx_packets++;
462 482
463 scale_rate_index = first_index; 483 scale_rate_index = first_index;
@@ -625,7 +645,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
625 u32 fail_count; 645 u32 fail_count;
626 s8 scale_action = 0; 646 s8 scale_action = 0;
627 unsigned long flags; 647 unsigned long flags;
628 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
629 u16 rate_mask = sta ? sta->supp_rates[sband->band] : 0; 648 u16 rate_mask = sta ? sta->supp_rates[sband->band] : 0;
630 s8 max_rate_idx = -1; 649 s8 max_rate_idx = -1;
631 struct iwl_priv *priv = (struct iwl_priv *)priv_r; 650 struct iwl_priv *priv = (struct iwl_priv *)priv_r;
@@ -633,6 +652,12 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
633 652
634 IWL_DEBUG_RATE(priv, "enter\n"); 653 IWL_DEBUG_RATE(priv, "enter\n");
635 654
655 /* Treat uninitialized rate scaling data same as non-existing. */
656 if (rs_sta && !rs_sta->priv) {
657 IWL_DEBUG_RATE(priv, "Rate scaling information not initialized yet.\n");
658 priv_sta = NULL;
659 }
660
636 if (rate_control_send_low(sta, priv_sta, txrc)) 661 if (rate_control_send_low(sta, priv_sta, txrc))
637 return; 662 return;
638 663
@@ -650,20 +675,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta,
650 if (sband->band == IEEE80211_BAND_5GHZ) 675 if (sband->band == IEEE80211_BAND_5GHZ)
651 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; 676 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE;
652 677
653 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
654 !rs_sta->ibss_sta_added) {
655 u8 sta_id = iwl_find_station(priv, hdr->addr1);
656
657 if (sta_id == IWL_INVALID_STATION) {
658 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
659 hdr->addr1);
660 sta_id = iwl_add_station(priv, hdr->addr1, false,
661 CMD_ASYNC, NULL);
662 }
663 if (sta_id != IWL_INVALID_STATION)
664 rs_sta->ibss_sta_added = 1;
665 }
666
667 spin_lock_irqsave(&rs_sta->lock, flags); 678 spin_lock_irqsave(&rs_sta->lock, flags);
668 679
669 /* for recent assoc, choose best rate regarding 680 /* for recent assoc, choose best rate regarding
@@ -883,12 +894,22 @@ static void iwl3945_remove_debugfs(void *priv, void *priv_sta)
883} 894}
884#endif 895#endif
885 896
897/*
898 * Initialization of rate scaling information is done by driver after
899 * the station is added. Since mac80211 calls this function before a
900 * station is added we ignore it.
901 */
902static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband,
903 struct ieee80211_sta *sta, void *priv_sta)
904{
905}
906
886static struct rate_control_ops rs_ops = { 907static struct rate_control_ops rs_ops = {
887 .module = NULL, 908 .module = NULL,
888 .name = RS_NAME, 909 .name = RS_NAME,
889 .tx_status = rs_tx_status, 910 .tx_status = rs_tx_status,
890 .get_rate = rs_get_rate, 911 .get_rate = rs_get_rate,
891 .rate_init = rs_rate_init, 912 .rate_init = rs_rate_init_stub,
892 .alloc = rs_alloc, 913 .alloc = rs_alloc,
893 .free = rs_free, 914 .free = rs_free,
894 .alloc_sta = rs_alloc_sta, 915 .alloc_sta = rs_alloc_sta,
@@ -899,7 +920,6 @@ static struct rate_control_ops rs_ops = {
899#endif 920#endif
900 921
901}; 922};
902
903void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) 923void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
904{ 924{
905 struct iwl_priv *priv = hw->priv; 925 struct iwl_priv *priv = hw->priv;
@@ -916,6 +936,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
916 sta = ieee80211_find_sta(priv->vif, 936 sta = ieee80211_find_sta(priv->vif,
917 priv->stations[sta_id].sta.sta.addr); 937 priv->stations[sta_id].sta.sta.addr);
918 if (!sta) { 938 if (!sta) {
939 IWL_DEBUG_RATE(priv, "Unable to find station to initialize rate scaling.\n");
919 rcu_read_unlock(); 940 rcu_read_unlock();
920 return; 941 return;
921 } 942 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 12a42fc743d7..3b5889d8d662 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -1911,6 +1911,8 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1911 "configuration (%d).\n", rc); 1911 "configuration (%d).\n", rc);
1912 return rc; 1912 return rc;
1913 } 1913 }
1914 iwl_clear_ucode_stations(priv, false);
1915 iwl_restore_stations(priv);
1914 } 1916 }
1915 1917
1916 IWL_DEBUG_INFO(priv, "Sending RXON\n" 1918 IWL_DEBUG_INFO(priv, "Sending RXON\n"
@@ -1941,7 +1943,10 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1941 1943
1942 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); 1944 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
1943 1945
1944 iwl_clear_stations_table(priv); 1946 if (!new_assoc) {
1947 iwl_clear_ucode_stations(priv, false);
1948 iwl_restore_stations(priv);
1949 }
1945 1950
1946 /* If we issue a new RXON command which required a tune then we must 1951 /* If we issue a new RXON command which required a tune then we must
1947 * send a new TXPOWER command or we won't be able to Tx any frames */ 1952 * send a new TXPOWER command or we won't be able to Tx any frames */
@@ -1951,19 +1956,6 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1951 return rc; 1956 return rc;
1952 } 1957 }
1953 1958
1954 /* Add the broadcast address so we can send broadcast frames */
1955 priv->cfg->ops->lib->add_bcast_station(priv);
1956
1957 /* If we have set the ASSOC_MSK and we are in BSS mode then
1958 * add the IWL_AP_ID to the station rate table */
1959 if (iwl_is_associated(priv) &&
1960 (priv->iw_mode == NL80211_IFTYPE_STATION))
1961 if (iwl_add_station(priv, priv->active_rxon.bssid_addr,
1962 true, CMD_SYNC, NULL) == IWL_INVALID_STATION) {
1963 IWL_ERR(priv, "Error adding AP address for transmit\n");
1964 return -EIO;
1965 }
1966
1967 /* Init the hardware's rate fallback order based on the band */ 1959 /* Init the hardware's rate fallback order based on the band */
1968 rc = iwl3945_init_hw_rate_table(priv); 1960 rc = iwl3945_init_hw_rate_table(priv);
1969 if (rc) { 1961 if (rc) {
@@ -2828,6 +2820,7 @@ static struct iwl_cfg iwl3945_bg_cfg = {
2828 .led_compensation = 64, 2820 .led_compensation = 64,
2829 .broken_powersave = true, 2821 .broken_powersave = true,
2830 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 2822 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
2823 .monitor_recover_period = IWL_MONITORING_PERIOD,
2831}; 2824};
2832 2825
2833static struct iwl_cfg iwl3945_abg_cfg = { 2826static struct iwl_cfg iwl3945_abg_cfg = {
@@ -2846,6 +2839,7 @@ static struct iwl_cfg iwl3945_abg_cfg = {
2846 .led_compensation = 64, 2839 .led_compensation = 64,
2847 .broken_powersave = true, 2840 .broken_powersave = true,
2848 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 2841 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
2842 .monitor_recover_period = IWL_MONITORING_PERIOD,
2849}; 2843};
2850 2844
2851DEFINE_PCI_DEVICE_TABLE(iwl3945_hw_card_ids) = { 2845DEFINE_PCI_DEVICE_TABLE(iwl3945_hw_card_ids) = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index 452dfd5456c6..b89219573b91 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -95,7 +95,6 @@ struct iwl3945_rs_sta {
95 u8 tgg; 95 u8 tgg;
96 u8 flush_pending; 96 u8 flush_pending;
97 u8 start_rate; 97 u8 start_rate;
98 u8 ibss_sta_added;
99 struct timer_list rate_scale_flush; 98 struct timer_list rate_scale_flush;
100 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT_3945]; 99 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT_3945];
101#ifdef CONFIG_MAC80211_DEBUGFS 100#ifdef CONFIG_MAC80211_DEBUGFS
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index 644aacfbd7df..3949133d9ee2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -2187,6 +2187,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2187 .load_ucode = iwl4965_load_bsm, 2187 .load_ucode = iwl4965_load_bsm,
2188 .dump_nic_event_log = iwl_dump_nic_event_log, 2188 .dump_nic_event_log = iwl_dump_nic_event_log,
2189 .dump_nic_error_log = iwl_dump_nic_error_log, 2189 .dump_nic_error_log = iwl_dump_nic_error_log,
2190 .dump_fh = iwl_dump_fh,
2190 .set_channel_switch = iwl4965_hw_channel_switch, 2191 .set_channel_switch = iwl4965_hw_channel_switch,
2191 .apm_ops = { 2192 .apm_ops = {
2192 .init = iwl_apm_init, 2193 .init = iwl_apm_init,
@@ -2220,6 +2221,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2220 .set_ct_kill = iwl4965_set_ct_threshold, 2221 .set_ct_kill = iwl4965_set_ct_threshold,
2221 }, 2222 },
2222 .add_bcast_station = iwl_add_bcast_station, 2223 .add_bcast_station = iwl_add_bcast_station,
2224 .check_plcp_health = iwl_good_plcp_health,
2223}; 2225};
2224 2226
2225static const struct iwl_ops iwl4965_ops = { 2227static const struct iwl_ops iwl4965_ops = {
@@ -2231,7 +2233,7 @@ static const struct iwl_ops iwl4965_ops = {
2231}; 2233};
2232 2234
2233struct iwl_cfg iwl4965_agn_cfg = { 2235struct iwl_cfg iwl4965_agn_cfg = {
2234 .name = "4965AGN", 2236 .name = "Intel(R) Wireless WiFi Link 4965AGN",
2235 .fw_name_pre = IWL4965_FW_PRE, 2237 .fw_name_pre = IWL4965_FW_PRE,
2236 .ucode_api_max = IWL4965_UCODE_API_MAX, 2238 .ucode_api_max = IWL4965_UCODE_API_MAX,
2237 .ucode_api_min = IWL4965_UCODE_API_MIN, 2239 .ucode_api_min = IWL4965_UCODE_API_MIN,
@@ -2254,6 +2256,7 @@ struct iwl_cfg iwl4965_agn_cfg = {
2254 .led_compensation = 61, 2256 .led_compensation = 61,
2255 .chain_noise_num_beacons = IWL4965_CAL_NUM_BEACONS, 2257 .chain_noise_num_beacons = IWL4965_CAL_NUM_BEACONS,
2256 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 2258 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
2259 .monitor_recover_period = IWL_MONITORING_PERIOD,
2257}; 2260};
2258 2261
2259/* Module firmware */ 2262/* Module firmware */
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 37e1e77f513d..2267cad49cbf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -544,7 +544,6 @@ void iwl5000_init_alive_start(struct iwl_priv *priv)
544 goto restart; 544 goto restart;
545 } 545 }
546 546
547 iwl_clear_stations_table(priv);
548 ret = priv->cfg->ops->lib->alive_notify(priv); 547 ret = priv->cfg->ops->lib->alive_notify(priv);
549 if (ret) { 548 if (ret) {
550 IWL_WARN(priv, 549 IWL_WARN(priv,
@@ -1500,6 +1499,9 @@ struct iwl_lib_ops iwl5000_lib = {
1500 .set_ct_kill = iwl5000_set_ct_threshold, 1499 .set_ct_kill = iwl5000_set_ct_threshold,
1501 }, 1500 },
1502 .add_bcast_station = iwl_add_bcast_station, 1501 .add_bcast_station = iwl_add_bcast_station,
1502 .recover_from_tx_stall = iwl_bg_monitor_recover,
1503 .check_plcp_health = iwl_good_plcp_health,
1504 .check_ack_health = iwl_good_ack_health,
1503}; 1505};
1504 1506
1505static struct iwl_lib_ops iwl5150_lib = { 1507static struct iwl_lib_ops iwl5150_lib = {
@@ -1554,6 +1556,9 @@ static struct iwl_lib_ops iwl5150_lib = {
1554 .set_ct_kill = iwl5150_set_ct_threshold, 1556 .set_ct_kill = iwl5150_set_ct_threshold,
1555 }, 1557 },
1556 .add_bcast_station = iwl_add_bcast_station, 1558 .add_bcast_station = iwl_add_bcast_station,
1559 .recover_from_tx_stall = iwl_bg_monitor_recover,
1560 .check_plcp_health = iwl_good_plcp_health,
1561 .check_ack_health = iwl_good_ack_health,
1557}; 1562};
1558 1563
1559static const struct iwl_ops iwl5000_ops = { 1564static const struct iwl_ops iwl5000_ops = {
@@ -1580,7 +1585,7 @@ struct iwl_mod_params iwl50_mod_params = {
1580 1585
1581 1586
1582struct iwl_cfg iwl5300_agn_cfg = { 1587struct iwl_cfg iwl5300_agn_cfg = {
1583 .name = "5300AGN", 1588 .name = "Intel(R) Ultimate N WiFi Link 5300 AGN",
1584 .fw_name_pre = IWL5000_FW_PRE, 1589 .fw_name_pre = IWL5000_FW_PRE,
1585 .ucode_api_max = IWL5000_UCODE_API_MAX, 1590 .ucode_api_max = IWL5000_UCODE_API_MAX,
1586 .ucode_api_min = IWL5000_UCODE_API_MIN, 1591 .ucode_api_min = IWL5000_UCODE_API_MIN,
@@ -1603,10 +1608,11 @@ struct iwl_cfg iwl5300_agn_cfg = {
1603 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1608 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1604 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1609 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1605 .chain_noise_scale = 1000, 1610 .chain_noise_scale = 1000,
1611 .monitor_recover_period = IWL_MONITORING_PERIOD,
1606}; 1612};
1607 1613
1608struct iwl_cfg iwl5100_bgn_cfg = { 1614struct iwl_cfg iwl5100_bgn_cfg = {
1609 .name = "5100BGN", 1615 .name = "Intel(R) WiFi Link 5100 BGN",
1610 .fw_name_pre = IWL5000_FW_PRE, 1616 .fw_name_pre = IWL5000_FW_PRE,
1611 .ucode_api_max = IWL5000_UCODE_API_MAX, 1617 .ucode_api_max = IWL5000_UCODE_API_MAX,
1612 .ucode_api_min = IWL5000_UCODE_API_MIN, 1618 .ucode_api_min = IWL5000_UCODE_API_MIN,
@@ -1629,10 +1635,11 @@ struct iwl_cfg iwl5100_bgn_cfg = {
1629 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1635 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1630 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1636 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1631 .chain_noise_scale = 1000, 1637 .chain_noise_scale = 1000,
1638 .monitor_recover_period = IWL_MONITORING_PERIOD,
1632}; 1639};
1633 1640
1634struct iwl_cfg iwl5100_abg_cfg = { 1641struct iwl_cfg iwl5100_abg_cfg = {
1635 .name = "5100ABG", 1642 .name = "Intel(R) WiFi Link 5100 ABG",
1636 .fw_name_pre = IWL5000_FW_PRE, 1643 .fw_name_pre = IWL5000_FW_PRE,
1637 .ucode_api_max = IWL5000_UCODE_API_MAX, 1644 .ucode_api_max = IWL5000_UCODE_API_MAX,
1638 .ucode_api_min = IWL5000_UCODE_API_MIN, 1645 .ucode_api_min = IWL5000_UCODE_API_MIN,
@@ -1653,10 +1660,11 @@ struct iwl_cfg iwl5100_abg_cfg = {
1653 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1660 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1654 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1661 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1655 .chain_noise_scale = 1000, 1662 .chain_noise_scale = 1000,
1663 .monitor_recover_period = IWL_MONITORING_PERIOD,
1656}; 1664};
1657 1665
1658struct iwl_cfg iwl5100_agn_cfg = { 1666struct iwl_cfg iwl5100_agn_cfg = {
1659 .name = "5100AGN", 1667 .name = "Intel(R) WiFi Link 5100 AGN",
1660 .fw_name_pre = IWL5000_FW_PRE, 1668 .fw_name_pre = IWL5000_FW_PRE,
1661 .ucode_api_max = IWL5000_UCODE_API_MAX, 1669 .ucode_api_max = IWL5000_UCODE_API_MAX,
1662 .ucode_api_min = IWL5000_UCODE_API_MIN, 1670 .ucode_api_min = IWL5000_UCODE_API_MIN,
@@ -1679,10 +1687,11 @@ struct iwl_cfg iwl5100_agn_cfg = {
1679 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1687 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1680 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1688 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1681 .chain_noise_scale = 1000, 1689 .chain_noise_scale = 1000,
1690 .monitor_recover_period = IWL_MONITORING_PERIOD,
1682}; 1691};
1683 1692
1684struct iwl_cfg iwl5350_agn_cfg = { 1693struct iwl_cfg iwl5350_agn_cfg = {
1685 .name = "5350AGN", 1694 .name = "Intel(R) WiMAX/WiFi Link 5350 AGN",
1686 .fw_name_pre = IWL5000_FW_PRE, 1695 .fw_name_pre = IWL5000_FW_PRE,
1687 .ucode_api_max = IWL5000_UCODE_API_MAX, 1696 .ucode_api_max = IWL5000_UCODE_API_MAX,
1688 .ucode_api_min = IWL5000_UCODE_API_MIN, 1697 .ucode_api_min = IWL5000_UCODE_API_MIN,
@@ -1705,10 +1714,11 @@ struct iwl_cfg iwl5350_agn_cfg = {
1705 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1714 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1706 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1715 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1707 .chain_noise_scale = 1000, 1716 .chain_noise_scale = 1000,
1717 .monitor_recover_period = IWL_MONITORING_PERIOD,
1708}; 1718};
1709 1719
1710struct iwl_cfg iwl5150_agn_cfg = { 1720struct iwl_cfg iwl5150_agn_cfg = {
1711 .name = "5150AGN", 1721 .name = "Intel(R) WiMAX/WiFi Link 5150 AGN",
1712 .fw_name_pre = IWL5150_FW_PRE, 1722 .fw_name_pre = IWL5150_FW_PRE,
1713 .ucode_api_max = IWL5150_UCODE_API_MAX, 1723 .ucode_api_max = IWL5150_UCODE_API_MAX,
1714 .ucode_api_min = IWL5150_UCODE_API_MIN, 1724 .ucode_api_min = IWL5150_UCODE_API_MIN,
@@ -1731,10 +1741,11 @@ struct iwl_cfg iwl5150_agn_cfg = {
1731 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1741 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1732 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1742 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1733 .chain_noise_scale = 1000, 1743 .chain_noise_scale = 1000,
1744 .monitor_recover_period = IWL_MONITORING_PERIOD,
1734}; 1745};
1735 1746
1736struct iwl_cfg iwl5150_abg_cfg = { 1747struct iwl_cfg iwl5150_abg_cfg = {
1737 .name = "5150ABG", 1748 .name = "Intel(R) WiMAX/WiFi Link 5150 ABG",
1738 .fw_name_pre = IWL5150_FW_PRE, 1749 .fw_name_pre = IWL5150_FW_PRE,
1739 .ucode_api_max = IWL5150_UCODE_API_MAX, 1750 .ucode_api_max = IWL5150_UCODE_API_MAX,
1740 .ucode_api_min = IWL5150_UCODE_API_MIN, 1751 .ucode_api_min = IWL5150_UCODE_API_MIN,
@@ -1755,6 +1766,7 @@ struct iwl_cfg iwl5150_abg_cfg = {
1755 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, 1766 .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
1756 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 1767 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
1757 .chain_noise_scale = 1000, 1768 .chain_noise_scale = 1000,
1769 .monitor_recover_period = IWL_MONITORING_PERIOD,
1758}; 1770};
1759 1771
1760MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); 1772MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index 4b7bc008220f..d75799946a7e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -278,6 +278,9 @@ static struct iwl_lib_ops iwl6000_lib = {
278 .set_ct_kill = iwl6000_set_ct_threshold, 278 .set_ct_kill = iwl6000_set_ct_threshold,
279 }, 279 },
280 .add_bcast_station = iwl_add_bcast_station, 280 .add_bcast_station = iwl_add_bcast_station,
281 .recover_from_tx_stall = iwl_bg_monitor_recover,
282 .check_plcp_health = iwl_good_plcp_health,
283 .check_ack_health = iwl_good_ack_health,
281}; 284};
282 285
283static const struct iwl_ops iwl6000_ops = { 286static const struct iwl_ops iwl6000_ops = {
@@ -343,6 +346,9 @@ static struct iwl_lib_ops iwl6050_lib = {
343 .set_calib_version = iwl6050_set_calib_version, 346 .set_calib_version = iwl6050_set_calib_version,
344 }, 347 },
345 .add_bcast_station = iwl_add_bcast_station, 348 .add_bcast_station = iwl_add_bcast_station,
349 .recover_from_tx_stall = iwl_bg_monitor_recover,
350 .check_plcp_health = iwl_good_plcp_health,
351 .check_ack_health = iwl_good_ack_health,
346}; 352};
347 353
348static const struct iwl_ops iwl6050_ops = { 354static const struct iwl_ops iwl6050_ops = {
@@ -357,7 +363,7 @@ static const struct iwl_ops iwl6050_ops = {
357 * "i": Internal configuration, use internal Power Amplifier 363 * "i": Internal configuration, use internal Power Amplifier
358 */ 364 */
359struct iwl_cfg iwl6000i_2agn_cfg = { 365struct iwl_cfg iwl6000i_2agn_cfg = {
360 .name = "6000 Series 2x2 AGN", 366 .name = "Intel(R) Centrino(R) Advanced-N 6200 AGN",
361 .fw_name_pre = IWL6000_FW_PRE, 367 .fw_name_pre = IWL6000_FW_PRE,
362 .ucode_api_max = IWL6000_UCODE_API_MAX, 368 .ucode_api_max = IWL6000_UCODE_API_MAX,
363 .ucode_api_min = IWL6000_UCODE_API_MIN, 369 .ucode_api_min = IWL6000_UCODE_API_MIN,
@@ -386,10 +392,11 @@ struct iwl_cfg iwl6000i_2agn_cfg = {
386 .support_ct_kill_exit = true, 392 .support_ct_kill_exit = true,
387 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 393 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
388 .chain_noise_scale = 1000, 394 .chain_noise_scale = 1000,
395 .monitor_recover_period = IWL_MONITORING_PERIOD,
389}; 396};
390 397
391struct iwl_cfg iwl6000i_2abg_cfg = { 398struct iwl_cfg iwl6000i_2abg_cfg = {
392 .name = "6000 Series 2x2 ABG", 399 .name = "Intel(R) Centrino(R) Advanced-N 6200 ABG",
393 .fw_name_pre = IWL6000_FW_PRE, 400 .fw_name_pre = IWL6000_FW_PRE,
394 .ucode_api_max = IWL6000_UCODE_API_MAX, 401 .ucode_api_max = IWL6000_UCODE_API_MAX,
395 .ucode_api_min = IWL6000_UCODE_API_MIN, 402 .ucode_api_min = IWL6000_UCODE_API_MIN,
@@ -417,10 +424,11 @@ struct iwl_cfg iwl6000i_2abg_cfg = {
417 .support_ct_kill_exit = true, 424 .support_ct_kill_exit = true,
418 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 425 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
419 .chain_noise_scale = 1000, 426 .chain_noise_scale = 1000,
427 .monitor_recover_period = IWL_MONITORING_PERIOD,
420}; 428};
421 429
422struct iwl_cfg iwl6000i_2bg_cfg = { 430struct iwl_cfg iwl6000i_2bg_cfg = {
423 .name = "6000 Series 2x2 BG", 431 .name = "Intel(R) Centrino(R) Advanced-N 6200 BG",
424 .fw_name_pre = IWL6000_FW_PRE, 432 .fw_name_pre = IWL6000_FW_PRE,
425 .ucode_api_max = IWL6000_UCODE_API_MAX, 433 .ucode_api_max = IWL6000_UCODE_API_MAX,
426 .ucode_api_min = IWL6000_UCODE_API_MIN, 434 .ucode_api_min = IWL6000_UCODE_API_MIN,
@@ -448,10 +456,11 @@ struct iwl_cfg iwl6000i_2bg_cfg = {
448 .support_ct_kill_exit = true, 456 .support_ct_kill_exit = true,
449 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 457 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
450 .chain_noise_scale = 1000, 458 .chain_noise_scale = 1000,
459 .monitor_recover_period = IWL_MONITORING_PERIOD,
451}; 460};
452 461
453struct iwl_cfg iwl6050_2agn_cfg = { 462struct iwl_cfg iwl6050_2agn_cfg = {
454 .name = "6050 Series 2x2 AGN", 463 .name = "Intel(R) Centrino(R) Advanced-N + WiMAX 6250 AGN",
455 .fw_name_pre = IWL6050_FW_PRE, 464 .fw_name_pre = IWL6050_FW_PRE,
456 .ucode_api_max = IWL6050_UCODE_API_MAX, 465 .ucode_api_max = IWL6050_UCODE_API_MAX,
457 .ucode_api_min = IWL6050_UCODE_API_MIN, 466 .ucode_api_min = IWL6050_UCODE_API_MIN,
@@ -480,10 +489,11 @@ struct iwl_cfg iwl6050_2agn_cfg = {
480 .support_ct_kill_exit = true, 489 .support_ct_kill_exit = true,
481 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 490 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
482 .chain_noise_scale = 1500, 491 .chain_noise_scale = 1500,
492 .monitor_recover_period = IWL_MONITORING_PERIOD,
483}; 493};
484 494
485struct iwl_cfg iwl6050_2abg_cfg = { 495struct iwl_cfg iwl6050_2abg_cfg = {
486 .name = "6050 Series 2x2 ABG", 496 .name = "Intel(R) Centrino(R) Advanced-N + WiMAX 6250 ABG",
487 .fw_name_pre = IWL6050_FW_PRE, 497 .fw_name_pre = IWL6050_FW_PRE,
488 .ucode_api_max = IWL6050_UCODE_API_MAX, 498 .ucode_api_max = IWL6050_UCODE_API_MAX,
489 .ucode_api_min = IWL6050_UCODE_API_MIN, 499 .ucode_api_min = IWL6050_UCODE_API_MIN,
@@ -511,10 +521,11 @@ struct iwl_cfg iwl6050_2abg_cfg = {
511 .support_ct_kill_exit = true, 521 .support_ct_kill_exit = true,
512 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 522 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
513 .chain_noise_scale = 1500, 523 .chain_noise_scale = 1500,
524 .monitor_recover_period = IWL_MONITORING_PERIOD,
514}; 525};
515 526
516struct iwl_cfg iwl6000_3agn_cfg = { 527struct iwl_cfg iwl6000_3agn_cfg = {
517 .name = "6000 Series 3x3 AGN", 528 .name = "Intel(R) Centrino(R) Ultimate-N 6300 AGN",
518 .fw_name_pre = IWL6000_FW_PRE, 529 .fw_name_pre = IWL6000_FW_PRE,
519 .ucode_api_max = IWL6000_UCODE_API_MAX, 530 .ucode_api_max = IWL6000_UCODE_API_MAX,
520 .ucode_api_min = IWL6000_UCODE_API_MIN, 531 .ucode_api_min = IWL6000_UCODE_API_MIN,
@@ -543,6 +554,7 @@ struct iwl_cfg iwl6000_3agn_cfg = {
543 .support_ct_kill_exit = true, 554 .support_ct_kill_exit = true,
544 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 555 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF,
545 .chain_noise_scale = 1000, 556 .chain_noise_scale = 1000,
557 .monitor_recover_period = IWL_MONITORING_PERIOD,
546}; 558};
547 559
548MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX)); 560MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX));
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 84271cc62afa..5155b1a027eb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -769,6 +769,15 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
769 769
770 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); 770 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
771 771
772 /* Treat uninitialized rate scaling data same as non-existing. */
773 if (!lq_sta) {
774 IWL_DEBUG_RATE(priv, "Station rate scaling not created yet.\n");
775 return;
776 } else if (!lq_sta->drv) {
777 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
778 return;
779 }
780
772 if (!ieee80211_is_data(hdr->frame_control) || 781 if (!ieee80211_is_data(hdr->frame_control) ||
773 info->flags & IEEE80211_TX_CTL_NO_ACK) 782 info->flags & IEEE80211_TX_CTL_NO_ACK)
774 return; 783 return;
@@ -778,10 +787,6 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
778 !(info->flags & IEEE80211_TX_STAT_AMPDU)) 787 !(info->flags & IEEE80211_TX_STAT_AMPDU))
779 return; 788 return;
780 789
781 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
782 !lq_sta->ibss_sta_added)
783 return;
784
785 /* 790 /*
786 * Ignore this Tx frame response if its initial rate doesn't match 791 * Ignore this Tx frame response if its initial rate doesn't match
787 * that of latest Link Quality command. There may be stragglers 792 * that of latest Link Quality command. There may be stragglers
@@ -827,7 +832,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
827 lq_sta->missed_rate_counter++; 832 lq_sta->missed_rate_counter++;
828 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { 833 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
829 lq_sta->missed_rate_counter = 0; 834 lq_sta->missed_rate_counter = 0;
830 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 835 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false);
831 } 836 }
832 /* Regardless, ignore this status info for outdated rate */ 837 /* Regardless, ignore this status info for outdated rate */
833 return; 838 return;
@@ -1915,7 +1920,7 @@ static u32 rs_update_rate_tbl(struct iwl_priv *priv,
1915 /* Update uCode's rate table. */ 1920 /* Update uCode's rate table. */
1916 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); 1921 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
1917 rs_fill_link_cmd(priv, lq_sta, rate); 1922 rs_fill_link_cmd(priv, lq_sta, rate);
1918 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 1923 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false);
1919 1924
1920 return rate; 1925 return rate;
1921} 1926}
@@ -2291,7 +2296,7 @@ lq_update:
2291 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n", 2296 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n",
2292 tbl->current_rate, index); 2297 tbl->current_rate, index);
2293 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 2298 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2294 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2299 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false);
2295 } else 2300 } else
2296 done_search = 1; 2301 done_search = 1;
2297 } 2302 }
@@ -2340,7 +2345,20 @@ out:
2340 return; 2345 return;
2341} 2346}
2342 2347
2343 2348/**
2349 * rs_initialize_lq - Initialize a station's hardware rate table
2350 *
2351 * The uCode's station table contains a table of fallback rates
2352 * for automatic fallback during transmission.
2353 *
2354 * NOTE: This sets up a default set of values. These will be replaced later
2355 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
2356 * rc80211_simple.
2357 *
2358 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
2359 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
2360 * which requires station table entry to exist).
2361 */
2344static void rs_initialize_lq(struct iwl_priv *priv, 2362static void rs_initialize_lq(struct iwl_priv *priv,
2345 struct ieee80211_conf *conf, 2363 struct ieee80211_conf *conf,
2346 struct ieee80211_sta *sta, 2364 struct ieee80211_sta *sta,
@@ -2359,10 +2377,6 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2359 2377
2360 i = lq_sta->last_txrate_idx; 2378 i = lq_sta->last_txrate_idx;
2361 2379
2362 if ((lq_sta->lq.sta_id == 0xff) &&
2363 (priv->iw_mode == NL80211_IFTYPE_ADHOC))
2364 goto out;
2365
2366 valid_tx_ant = priv->hw_params.valid_tx_ant; 2380 valid_tx_ant = priv->hw_params.valid_tx_ant;
2367 2381
2368 if (!lq_sta->search_better_tbl) 2382 if (!lq_sta->search_better_tbl)
@@ -2390,7 +2404,8 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2390 tbl->current_rate = rate; 2404 tbl->current_rate = rate;
2391 rs_set_expected_tpt_table(lq_sta, tbl); 2405 rs_set_expected_tpt_table(lq_sta, tbl);
2392 rs_fill_link_cmd(NULL, lq_sta, rate); 2406 rs_fill_link_cmd(NULL, lq_sta, rate);
2393 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2407 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
2408 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_SYNC, true);
2394 out: 2409 out:
2395 return; 2410 return;
2396} 2411}
@@ -2402,9 +2417,6 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2402 struct sk_buff *skb = txrc->skb; 2417 struct sk_buff *skb = txrc->skb;
2403 struct ieee80211_supported_band *sband = txrc->sband; 2418 struct ieee80211_supported_band *sband = txrc->sband;
2404 struct iwl_priv *priv = (struct iwl_priv *)priv_r; 2419 struct iwl_priv *priv = (struct iwl_priv *)priv_r;
2405 struct ieee80211_conf *conf = &priv->hw->conf;
2406 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2407 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2408 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2420 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2409 struct iwl_lq_sta *lq_sta = priv_sta; 2421 struct iwl_lq_sta *lq_sta = priv_sta;
2410 int rate_idx; 2422 int rate_idx;
@@ -2422,30 +2434,18 @@ static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
2422 lq_sta->max_rate_idx = -1; 2434 lq_sta->max_rate_idx = -1;
2423 } 2435 }
2424 2436
2437 /* Treat uninitialized rate scaling data same as non-existing. */
2438 if (lq_sta && !lq_sta->drv) {
2439 IWL_DEBUG_RATE(priv, "Rate scaling not initialized yet.\n");
2440 priv_sta = NULL;
2441 }
2442
2425 /* Send management frames and NO_ACK data using lowest rate. */ 2443 /* Send management frames and NO_ACK data using lowest rate. */
2426 if (rate_control_send_low(sta, priv_sta, txrc)) 2444 if (rate_control_send_low(sta, priv_sta, txrc))
2427 return; 2445 return;
2428 2446
2429 rate_idx = lq_sta->last_txrate_idx; 2447 rate_idx = lq_sta->last_txrate_idx;
2430 2448
2431 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
2432 !lq_sta->ibss_sta_added) {
2433 u8 sta_id = iwl_find_station(priv, hdr->addr1);
2434
2435 if (sta_id == IWL_INVALID_STATION) {
2436 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n",
2437 hdr->addr1);
2438 sta_id = iwl_add_station(priv, hdr->addr1,
2439 false, CMD_ASYNC, ht_cap);
2440 }
2441 if ((sta_id != IWL_INVALID_STATION)) {
2442 lq_sta->lq.sta_id = sta_id;
2443 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2444 lq_sta->ibss_sta_added = 1;
2445 rs_initialize_lq(priv, conf, sta, lq_sta);
2446 }
2447 }
2448
2449 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) { 2449 if (lq_sta->last_rate_n_flags & RATE_MCS_HT_MSK) {
2450 rate_idx -= IWL_FIRST_OFDM_RATE; 2450 rate_idx -= IWL_FIRST_OFDM_RATE;
2451 /* 6M and 9M shared same MCS index */ 2451 /* 6M and 9M shared same MCS index */
@@ -2495,16 +2495,25 @@ static void *rs_alloc_sta(void *priv_rate, struct ieee80211_sta *sta,
2495 return lq_sta; 2495 return lq_sta;
2496} 2496}
2497 2497
2498static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband, 2498/*
2499 struct ieee80211_sta *sta, void *priv_sta) 2499 * Called after adding a new station to initialize rate scaling
2500 */
2501void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_id)
2500{ 2502{
2501 int i, j; 2503 int i, j;
2502 struct iwl_priv *priv = (struct iwl_priv *)priv_r; 2504 struct ieee80211_hw *hw = priv->hw;
2503 struct ieee80211_conf *conf = &priv->hw->conf; 2505 struct ieee80211_conf *conf = &priv->hw->conf;
2504 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap; 2506 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2505 struct iwl_lq_sta *lq_sta = priv_sta; 2507 struct iwl_station_priv *sta_priv;
2508 struct iwl_lq_sta *lq_sta;
2509 struct ieee80211_supported_band *sband;
2510
2511 sta_priv = (struct iwl_station_priv *) sta->drv_priv;
2512 lq_sta = &sta_priv->lq_sta;
2513 sband = hw->wiphy->bands[conf->channel->band];
2514
2506 2515
2507 lq_sta->lq.sta_id = 0xff; 2516 lq_sta->lq.sta_id = sta_id;
2508 2517
2509 for (j = 0; j < LQ_SIZE; j++) 2518 for (j = 0; j < LQ_SIZE; j++)
2510 for (i = 0; i < IWL_RATE_COUNT; i++) 2519 for (i = 0; i < IWL_RATE_COUNT; i++)
@@ -2516,33 +2525,13 @@ static void rs_rate_init(void *priv_r, struct ieee80211_supported_band *sband,
2516 for (i = 0; i < IWL_RATE_COUNT; i++) 2525 for (i = 0; i < IWL_RATE_COUNT; i++)
2517 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]); 2526 rs_rate_scale_clear_window(&lq_sta->lq_info[j].win[i]);
2518 2527
2519 IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init ***\n"); 2528 IWL_DEBUG_RATE(priv, "LQ: *** rate scale station global init for station %d ***\n",
2529 sta_id);
2520 /* TODO: what is a good starting rate for STA? About middle? Maybe not 2530 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2521 * the lowest or the highest rate.. Could consider using RSSI from 2531 * the lowest or the highest rate.. Could consider using RSSI from
2522 * previous packets? Need to have IEEE 802.1X auth succeed immediately 2532 * previous packets? Need to have IEEE 802.1X auth succeed immediately
2523 * after assoc.. */ 2533 * after assoc.. */
2524 2534
2525 lq_sta->ibss_sta_added = 0;
2526 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2527 u8 sta_id = iwl_find_station(priv,
2528 sta->addr);
2529
2530 /* for IBSS the call are from tasklet */
2531 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2532
2533 if (sta_id == IWL_INVALID_STATION) {
2534 IWL_DEBUG_RATE(priv, "LQ: ADD station %pM\n", sta->addr);
2535 sta_id = iwl_add_station(priv, sta->addr, false,
2536 CMD_ASYNC, ht_cap);
2537 }
2538 if ((sta_id != IWL_INVALID_STATION)) {
2539 lq_sta->lq.sta_id = sta_id;
2540 lq_sta->lq.rs_table[0].rate_n_flags = 0;
2541 }
2542 /* FIXME: this is w/a remove it later */
2543 priv->assoc_station_added = 1;
2544 }
2545
2546 lq_sta->is_dup = 0; 2535 lq_sta->is_dup = 0;
2547 lq_sta->max_rate_idx = -1; 2536 lq_sta->max_rate_idx = -1;
2548 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; 2537 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
@@ -2795,7 +2784,7 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2795 2784
2796 if (lq_sta->dbg_fixed_rate) { 2785 if (lq_sta->dbg_fixed_rate) {
2797 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate); 2786 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
2798 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC); 2787 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC, false);
2799 } 2788 }
2800 2789
2801 return count; 2790 return count;
@@ -2992,12 +2981,21 @@ static void rs_remove_debugfs(void *priv, void *priv_sta)
2992} 2981}
2993#endif 2982#endif
2994 2983
2984/*
2985 * Initialization of rate scaling information is done by driver after
2986 * the station is added. Since mac80211 calls this function before a
2987 * station is added we ignore it.
2988 */
2989static void rs_rate_init_stub(void *priv_r, struct ieee80211_supported_band *sband,
2990 struct ieee80211_sta *sta, void *priv_sta)
2991{
2992}
2995static struct rate_control_ops rs_ops = { 2993static struct rate_control_ops rs_ops = {
2996 .module = NULL, 2994 .module = NULL,
2997 .name = RS_NAME, 2995 .name = RS_NAME,
2998 .tx_status = rs_tx_status, 2996 .tx_status = rs_tx_status,
2999 .get_rate = rs_get_rate, 2997 .get_rate = rs_get_rate,
3000 .rate_init = rs_rate_init, 2998 .rate_init = rs_rate_init_stub,
3001 .alloc = rs_alloc, 2999 .alloc = rs_alloc,
3002 .free = rs_free, 3000 .free = rs_free,
3003 .alloc_sta = rs_alloc_sta, 3001 .alloc_sta = rs_alloc_sta,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
index e182f5a0f736..8292f6d48ec6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
@@ -403,7 +403,6 @@ struct iwl_lq_sta {
403 u8 is_green; 403 u8 is_green;
404 u8 is_dup; 404 u8 is_dup;
405 enum ieee80211_band band; 405 enum ieee80211_band band;
406 u8 ibss_sta_added;
407 406
408 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 407 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
409 u32 supp_rates; 408 u32 supp_rates;
@@ -478,6 +477,12 @@ static inline u8 iwl3945_get_prev_ieee_rate(u8 rate_index)
478 */ 477 */
479extern void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id); 478extern void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id);
480 479
480/* Initialize station's rate scaling information after adding station */
481extern void iwl_rs_rate_init(struct iwl_priv *priv,
482 struct ieee80211_sta *sta, u8 sta_id);
483extern void iwl3945_rs_rate_init(struct iwl_priv *priv,
484 struct ieee80211_sta *sta, u8 sta_id);
485
481/** 486/**
482 * iwl_rate_control_register - Register the rate control algorithm callbacks 487 * iwl_rate_control_register - Register the rate control algorithm callbacks
483 * 488 *
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index efee4e39d282..0a376f720d78 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -144,9 +144,6 @@ int iwl_commit_rxon(struct iwl_priv *priv)
144 return 0; 144 return 0;
145 } 145 }
146 146
147 /* station table will be cleared */
148 priv->assoc_station_added = 0;
149
150 /* If we are currently associated and the new config requires 147 /* If we are currently associated and the new config requires
151 * an RXON_ASSOC and the new config wants the associated mask enabled, 148 * an RXON_ASSOC and the new config wants the associated mask enabled,
152 * we must clear the associated from the active configuration 149 * we must clear the associated from the active configuration
@@ -166,6 +163,8 @@ int iwl_commit_rxon(struct iwl_priv *priv)
166 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret); 163 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
167 return ret; 164 return ret;
168 } 165 }
166 iwl_clear_ucode_stations(priv, false);
167 iwl_restore_stations(priv);
169 } 168 }
170 169
171 IWL_DEBUG_INFO(priv, "Sending RXON\n" 170 IWL_DEBUG_INFO(priv, "Sending RXON\n"
@@ -179,9 +178,8 @@ int iwl_commit_rxon(struct iwl_priv *priv)
179 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto); 178 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
180 179
181 /* Apply the new configuration 180 /* Apply the new configuration
182 * RXON unassoc clears the station table in uCode, send it before 181 * RXON unassoc clears the station table in uCode so restoration of
183 * we add the bcast station. If assoc bit is set, we will send RXON 182 * stations is needed after it (the RXON command) completes
184 * after having added the bcast and bssid station.
185 */ 183 */
186 if (!new_assoc) { 184 if (!new_assoc) {
187 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 185 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
@@ -190,35 +188,14 @@ int iwl_commit_rxon(struct iwl_priv *priv)
190 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); 188 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
191 return ret; 189 return ret;
192 } 190 }
191 IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON. \n");
193 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 192 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
193 iwl_clear_ucode_stations(priv, false);
194 iwl_restore_stations(priv);
194 } 195 }
195 196
196 iwl_clear_stations_table(priv);
197
198 priv->start_calib = 0; 197 priv->start_calib = 0;
199
200 /* Add the broadcast address so we can send broadcast frames */
201 priv->cfg->ops->lib->add_bcast_station(priv);
202
203
204 /* If we have set the ASSOC_MSK and we are in BSS mode then
205 * add the IWL_AP_ID to the station rate table */
206 if (new_assoc) { 198 if (new_assoc) {
207 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
208 ret = iwl_rxon_add_station(priv,
209 priv->active_rxon.bssid_addr, 1);
210 if (ret == IWL_INVALID_STATION) {
211 IWL_ERR(priv,
212 "Error adding AP address for TX.\n");
213 return -EIO;
214 }
215 priv->assoc_station_added = 1;
216 if (priv->default_wep_key &&
217 iwl_send_static_wepkey_cmd(priv, 0))
218 IWL_ERR(priv,
219 "Could not send WEP static key.\n");
220 }
221
222 /* 199 /*
223 * allow CTS-to-self if possible for new association. 200 * allow CTS-to-self if possible for new association.
224 * this is relevant only for 5000 series and up, 201 * this is relevant only for 5000 series and up,
@@ -2087,7 +2064,6 @@ static void iwl_alive_start(struct iwl_priv *priv)
2087 goto restart; 2064 goto restart;
2088 } 2065 }
2089 2066
2090 iwl_clear_stations_table(priv);
2091 ret = priv->cfg->ops->lib->alive_notify(priv); 2067 ret = priv->cfg->ops->lib->alive_notify(priv);
2092 if (ret) { 2068 if (ret) {
2093 IWL_WARN(priv, 2069 IWL_WARN(priv,
@@ -2098,6 +2074,13 @@ static void iwl_alive_start(struct iwl_priv *priv)
2098 /* After the ALIVE response, we can send host commands to the uCode */ 2074 /* After the ALIVE response, we can send host commands to the uCode */
2099 set_bit(STATUS_ALIVE, &priv->status); 2075 set_bit(STATUS_ALIVE, &priv->status);
2100 2076
2077 if (priv->cfg->ops->lib->recover_from_tx_stall) {
2078 /* Enable timer to monitor the driver queues */
2079 mod_timer(&priv->monitor_recover,
2080 jiffies +
2081 msecs_to_jiffies(priv->cfg->monitor_recover_period));
2082 }
2083
2101 if (iwl_is_rfkill(priv)) 2084 if (iwl_is_rfkill(priv))
2102 return; 2085 return;
2103 2086
@@ -2143,6 +2126,8 @@ static void iwl_alive_start(struct iwl_priv *priv)
2143 wake_up_interruptible(&priv->wait_command_queue); 2126 wake_up_interruptible(&priv->wait_command_queue);
2144 2127
2145 iwl_power_update_mode(priv, true); 2128 iwl_power_update_mode(priv, true);
2129 IWL_DEBUG_INFO(priv, "Updated power mode\n");
2130
2146 2131
2147 return; 2132 return;
2148 2133
@@ -2162,7 +2147,7 @@ static void __iwl_down(struct iwl_priv *priv)
2162 if (!exit_pending) 2147 if (!exit_pending)
2163 set_bit(STATUS_EXIT_PENDING, &priv->status); 2148 set_bit(STATUS_EXIT_PENDING, &priv->status);
2164 2149
2165 iwl_clear_stations_table(priv); 2150 iwl_clear_ucode_stations(priv, true);
2166 2151
2167 /* Unblock any waiting calls */ 2152 /* Unblock any waiting calls */
2168 wake_up_interruptible_all(&priv->wait_command_queue); 2153 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -2359,8 +2344,6 @@ static int __iwl_up(struct iwl_priv *priv)
2359 2344
2360 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2345 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2361 2346
2362 iwl_clear_stations_table(priv);
2363
2364 /* load bootstrap state machine, 2347 /* load bootstrap state machine,
2365 * load bootstrap program into processor's memory, 2348 * load bootstrap program into processor's memory,
2366 * prepare to load the "initialize" uCode */ 2349 * prepare to load the "initialize" uCode */
@@ -2501,10 +2484,6 @@ void iwl_post_associate(struct iwl_priv *priv)
2501 return; 2484 return;
2502 } 2485 }
2503 2486
2504 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
2505 priv->assoc_id, priv->active_rxon.bssid_addr);
2506
2507
2508 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2487 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2509 return; 2488 return;
2510 2489
@@ -2556,6 +2535,9 @@ void iwl_post_associate(struct iwl_priv *priv)
2556 2535
2557 iwlcore_commit_rxon(priv); 2536 iwlcore_commit_rxon(priv);
2558 2537
2538 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
2539 priv->assoc_id, priv->active_rxon.bssid_addr);
2540
2559 switch (priv->iw_mode) { 2541 switch (priv->iw_mode) {
2560 case NL80211_IFTYPE_STATION: 2542 case NL80211_IFTYPE_STATION:
2561 break; 2543 break;
@@ -2565,7 +2547,7 @@ void iwl_post_associate(struct iwl_priv *priv)
2565 /* assume default assoc id */ 2547 /* assume default assoc id */
2566 priv->assoc_id = 1; 2548 priv->assoc_id = 1;
2567 2549
2568 iwl_rxon_add_station(priv, priv->bssid, 0); 2550 iwl_add_local_station(priv, priv->bssid, true);
2569 iwl_send_beacon_cmd(priv); 2551 iwl_send_beacon_cmd(priv);
2570 2552
2571 break; 2553 break;
@@ -2576,9 +2558,6 @@ void iwl_post_associate(struct iwl_priv *priv)
2576 break; 2558 break;
2577 } 2559 }
2578 2560
2579 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2580 priv->assoc_station_added = 1;
2581
2582 spin_lock_irqsave(&priv->lock, flags); 2561 spin_lock_irqsave(&priv->lock, flags);
2583 iwl_activate_qos(priv, 0); 2562 iwl_activate_qos(priv, 0);
2584 spin_unlock_irqrestore(&priv->lock, flags); 2563 spin_unlock_irqrestore(&priv->lock, flags);
@@ -2937,10 +2916,21 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2937 return ret; 2916 return ret;
2938 case IEEE80211_AMPDU_TX_START: 2917 case IEEE80211_AMPDU_TX_START:
2939 IWL_DEBUG_HT(priv, "start Tx\n"); 2918 IWL_DEBUG_HT(priv, "start Tx\n");
2940 return iwl_tx_agg_start(priv, sta->addr, tid, ssn); 2919 ret = iwl_tx_agg_start(priv, sta->addr, tid, ssn);
2920 if (ret == 0) {
2921 priv->_agn.agg_tids_count++;
2922 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2923 priv->_agn.agg_tids_count);
2924 }
2925 return ret;
2941 case IEEE80211_AMPDU_TX_STOP: 2926 case IEEE80211_AMPDU_TX_STOP:
2942 IWL_DEBUG_HT(priv, "stop Tx\n"); 2927 IWL_DEBUG_HT(priv, "stop Tx\n");
2943 ret = iwl_tx_agg_stop(priv, sta->addr, tid); 2928 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2929 if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
2930 priv->_agn.agg_tids_count--;
2931 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2932 priv->_agn.agg_tids_count);
2933 }
2944 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2934 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2945 return 0; 2935 return 0;
2946 else 2936 else
@@ -2977,18 +2967,7 @@ static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
2977 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; 2967 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
2978 int sta_id; 2968 int sta_id;
2979 2969
2980 /*
2981 * TODO: We really should use this callback to
2982 * actually maintain the station table in
2983 * the device.
2984 */
2985
2986 switch (cmd) { 2970 switch (cmd) {
2987 case STA_NOTIFY_ADD:
2988 atomic_set(&sta_priv->pending_frames, 0);
2989 if (vif->type == NL80211_IFTYPE_AP)
2990 sta_priv->client = true;
2991 break;
2992 case STA_NOTIFY_SLEEP: 2971 case STA_NOTIFY_SLEEP:
2993 WARN_ON(!sta_priv->client); 2972 WARN_ON(!sta_priv->client);
2994 sta_priv->asleep = true; 2973 sta_priv->asleep = true;
@@ -3009,6 +2988,55 @@ static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
3009 } 2988 }
3010} 2989}
3011 2990
2991/**
2992 * iwl_restore_wepkeys - Restore WEP keys to device
2993 */
2994static void iwl_restore_wepkeys(struct iwl_priv *priv)
2995{
2996 mutex_lock(&priv->mutex);
2997 if (priv->iw_mode == NL80211_IFTYPE_STATION &&
2998 priv->default_wep_key &&
2999 iwl_send_static_wepkey_cmd(priv, 0))
3000 IWL_ERR(priv, "Could not send WEP static key\n");
3001 mutex_unlock(&priv->mutex);
3002}
3003
3004static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
3005 struct ieee80211_vif *vif,
3006 struct ieee80211_sta *sta)
3007{
3008 struct iwl_priv *priv = hw->priv;
3009 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
3010 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
3011 int ret;
3012 u8 sta_id;
3013
3014 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
3015 sta->addr);
3016
3017 atomic_set(&sta_priv->pending_frames, 0);
3018 if (vif->type == NL80211_IFTYPE_AP)
3019 sta_priv->client = true;
3020
3021 ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap,
3022 &sta_id);
3023 if (ret) {
3024 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3025 sta->addr, ret);
3026 /* Should we return success if return code is EEXIST ? */
3027 return ret;
3028 }
3029
3030 iwl_restore_wepkeys(priv);
3031
3032 /* Initialize rate scaling */
3033 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM \n",
3034 sta->addr);
3035 iwl_rs_rate_init(priv, sta, sta_id);
3036
3037 return ret;
3038}
3039
3012/***************************************************************************** 3040/*****************************************************************************
3013 * 3041 *
3014 * sysfs attributes 3042 * sysfs attributes
@@ -3214,6 +3242,13 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
3214 priv->ucode_trace.data = (unsigned long)priv; 3242 priv->ucode_trace.data = (unsigned long)priv;
3215 priv->ucode_trace.function = iwl_bg_ucode_trace; 3243 priv->ucode_trace.function = iwl_bg_ucode_trace;
3216 3244
3245 if (priv->cfg->ops->lib->recover_from_tx_stall) {
3246 init_timer(&priv->monitor_recover);
3247 priv->monitor_recover.data = (unsigned long)priv;
3248 priv->monitor_recover.function =
3249 priv->cfg->ops->lib->recover_from_tx_stall;
3250 }
3251
3217 if (!priv->cfg->use_isr_legacy) 3252 if (!priv->cfg->use_isr_legacy)
3218 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) 3253 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3219 iwl_irq_tasklet, (unsigned long)priv); 3254 iwl_irq_tasklet, (unsigned long)priv);
@@ -3233,6 +3268,8 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
3233 cancel_work_sync(&priv->beacon_update); 3268 cancel_work_sync(&priv->beacon_update);
3234 del_timer_sync(&priv->statistics_periodic); 3269 del_timer_sync(&priv->statistics_periodic);
3235 del_timer_sync(&priv->ucode_trace); 3270 del_timer_sync(&priv->ucode_trace);
3271 if (priv->cfg->ops->lib->recover_from_tx_stall)
3272 del_timer_sync(&priv->monitor_recover);
3236} 3273}
3237 3274
3238static void iwl_init_hw_rates(struct iwl_priv *priv, 3275static void iwl_init_hw_rates(struct iwl_priv *priv,
@@ -3270,9 +3307,6 @@ static int iwl_init_drv(struct iwl_priv *priv)
3270 mutex_init(&priv->mutex); 3307 mutex_init(&priv->mutex);
3271 mutex_init(&priv->sync_cmd_mutex); 3308 mutex_init(&priv->sync_cmd_mutex);
3272 3309
3273 /* Clear the driver's (not device's) station table */
3274 iwl_clear_stations_table(priv);
3275
3276 priv->ieee_channels = NULL; 3310 priv->ieee_channels = NULL;
3277 priv->ieee_rates = NULL; 3311 priv->ieee_rates = NULL;
3278 priv->band = IEEE80211_BAND_2GHZ; 3312 priv->band = IEEE80211_BAND_2GHZ;
@@ -3280,6 +3314,7 @@ static int iwl_init_drv(struct iwl_priv *priv)
3280 priv->iw_mode = NL80211_IFTYPE_STATION; 3314 priv->iw_mode = NL80211_IFTYPE_STATION;
3281 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC; 3315 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
3282 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; 3316 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
3317 priv->_agn.agg_tids_count = 0;
3283 3318
3284 /* initialize force reset */ 3319 /* initialize force reset */
3285 priv->force_reset[IWL_RF_RESET].reset_duration = 3320 priv->force_reset[IWL_RF_RESET].reset_duration =
@@ -3365,6 +3400,8 @@ static struct ieee80211_ops iwl_hw_ops = {
3365 .ampdu_action = iwl_mac_ampdu_action, 3400 .ampdu_action = iwl_mac_ampdu_action,
3366 .hw_scan = iwl_mac_hw_scan, 3401 .hw_scan = iwl_mac_hw_scan,
3367 .sta_notify = iwl_mac_sta_notify, 3402 .sta_notify = iwl_mac_sta_notify,
3403 .sta_add = iwlagn_mac_sta_add,
3404 .sta_remove = iwl_mac_sta_remove,
3368}; 3405};
3369 3406
3370static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 3407static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -3468,7 +3505,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3468 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); 3505 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3469 3506
3470 iwl_hw_detect(priv); 3507 iwl_hw_detect(priv);
3471 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n", 3508 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
3472 priv->cfg->name, priv->hw_rev); 3509 priv->cfg->name, priv->hw_rev);
3473 3510
3474 /* We disable the RETRY_TIMEOUT register (0x41) to keep 3511 /* We disable the RETRY_TIMEOUT register (0x41) to keep
@@ -3649,7 +3686,6 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3649 iwl_rx_queue_free(priv, &priv->rxq); 3686 iwl_rx_queue_free(priv, &priv->rxq);
3650 iwl_hw_txq_ctx_free(priv); 3687 iwl_hw_txq_ctx_free(priv);
3651 3688
3652 iwl_clear_stations_table(priv);
3653 iwl_eeprom_free(priv); 3689 iwl_eeprom_free(priv);
3654 3690
3655 3691
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index ec435e5491d9..5180fb24cd38 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -2283,8 +2283,6 @@ static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
2283 2283
2284 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 2284 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2285 2285
2286 iwl_clear_stations_table(priv);
2287
2288 return iwlcore_commit_rxon(priv); 2286 return iwlcore_commit_rxon(priv);
2289} 2287}
2290 2288
@@ -2317,6 +2315,10 @@ int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2317 err = iwl_set_mode(priv, vif); 2315 err = iwl_set_mode(priv, vif);
2318 if (err) 2316 if (err)
2319 goto out_err; 2317 goto out_err;
2318
2319 /* Add the broadcast address so we can send broadcast frames */
2320 priv->cfg->ops->lib->add_bcast_station(priv);
2321
2320 goto out; 2322 goto out;
2321 2323
2322 out_err: 2324 out_err:
@@ -2339,6 +2341,8 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2339 2341
2340 mutex_lock(&priv->mutex); 2342 mutex_lock(&priv->mutex);
2341 2343
2344 iwl_clear_ucode_stations(priv, true);
2345
2342 if (iwl_is_ready_rf(priv)) { 2346 if (iwl_is_ready_rf(priv)) {
2343 iwl_scan_cancel_timeout(priv, 100); 2347 iwl_scan_cancel_timeout(priv, 100);
2344 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2348 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
@@ -2526,7 +2530,6 @@ void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2526 spin_lock_irqsave(&priv->lock, flags); 2530 spin_lock_irqsave(&priv->lock, flags);
2527 priv->assoc_id = 0; 2531 priv->assoc_id = 0;
2528 priv->assoc_capability = 0; 2532 priv->assoc_capability = 0;
2529 priv->assoc_station_added = 0;
2530 2533
2531 /* new association get rid of ibss beacon skb */ 2534 /* new association get rid of ibss beacon skb */
2532 if (priv->ibss_beacon) 2535 if (priv->ibss_beacon)
@@ -3048,6 +3051,99 @@ int iwl_force_reset(struct iwl_priv *priv, int mode)
3048 } 3051 }
3049 return 0; 3052 return 0;
3050} 3053}
3054EXPORT_SYMBOL(iwl_force_reset);
3055
3056/**
3057 * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
3058 *
3059 * During normal condition (no queue is stuck), the timer is continually set to
3060 * execute every monitor_recover_period milliseconds after the last timer
3061 * expired. When the queue read_ptr is at the same place, the timer is
3062 * shorten to 100mSecs. This is
3063 * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
3064 * 2) to detect the stuck queues quicker before the station and AP can
3065 * disassociate each other.
3066 *
3067 * This function monitors all the tx queues and recover from it if any
3068 * of the queues are stuck.
3069 * 1. It first check the cmd queue for stuck conditions. If it is stuck,
3070 * it will recover by resetting the firmware and return.
3071 * 2. Then, it checks for station association. If it associates it will check
3072 * other queues. If any queue is stuck, it will recover by resetting
3073 * the firmware.
3074 * Note: It the number of times the queue read_ptr to be at the same place to
3075 * be MAX_REPEAT+1 in order to consider to be stuck.
3076 */
3077/*
3078 * The maximum number of times the read pointer of the tx queue at the
3079 * same place without considering to be stuck.
3080 */
3081#define MAX_REPEAT (2)
3082static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
3083{
3084 struct iwl_tx_queue *txq;
3085 struct iwl_queue *q;
3086
3087 txq = &priv->txq[cnt];
3088 q = &txq->q;
3089 /* queue is empty, skip */
3090 if (q->read_ptr != q->write_ptr) {
3091 if (q->read_ptr == q->last_read_ptr) {
3092 /* a queue has not been read from last time */
3093 if (q->repeat_same_read_ptr > MAX_REPEAT) {
3094 IWL_ERR(priv,
3095 "queue %d stuck %d time. Fw reload.\n",
3096 q->id, q->repeat_same_read_ptr);
3097 q->repeat_same_read_ptr = 0;
3098 iwl_force_reset(priv, IWL_FW_RESET);
3099 } else {
3100 q->repeat_same_read_ptr++;
3101 IWL_DEBUG_RADIO(priv,
3102 "queue %d, not read %d time\n",
3103 q->id,
3104 q->repeat_same_read_ptr);
3105 mod_timer(&priv->monitor_recover, jiffies +
3106 msecs_to_jiffies(IWL_ONE_HUNDRED_MSECS));
3107 }
3108 return 1;
3109 } else {
3110 q->last_read_ptr = q->read_ptr;
3111 q->repeat_same_read_ptr = 0;
3112 }
3113 }
3114 return 0;
3115}
3116
3117void iwl_bg_monitor_recover(unsigned long data)
3118{
3119 struct iwl_priv *priv = (struct iwl_priv *)data;
3120 int cnt;
3121
3122 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3123 return;
3124
3125 /* monitor and check for stuck cmd queue */
3126 if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM))
3127 return;
3128
3129 /* monitor and check for other stuck queues */
3130 if (iwl_is_associated(priv)) {
3131 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
3132 /* skip as we already checked the command queue */
3133 if (cnt == IWL_CMD_QUEUE_NUM)
3134 continue;
3135 if (iwl_check_stuck_queue(priv, cnt))
3136 return;
3137 }
3138 }
3139 /*
3140 * Reschedule the timer to occur in
3141 * priv->cfg->monitor_recover_period
3142 */
3143 mod_timer(&priv->monitor_recover,
3144 jiffies + msecs_to_jiffies(priv->cfg->monitor_recover_period));
3145}
3146EXPORT_SYMBOL(iwl_bg_monitor_recover);
3051 3147
3052#ifdef CONFIG_PM 3148#ifdef CONFIG_PM
3053 3149
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index aced12f1611e..b3e698b576e1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -191,6 +191,14 @@ struct iwl_lib_ops {
191 struct iwl_temp_ops temp_ops; 191 struct iwl_temp_ops temp_ops;
192 /* station management */ 192 /* station management */
193 void (*add_bcast_station)(struct iwl_priv *priv); 193 void (*add_bcast_station)(struct iwl_priv *priv);
194 /* recover from tx queue stall */
195 void (*recover_from_tx_stall)(unsigned long data);
196 /* check for plcp health */
197 bool (*check_plcp_health)(struct iwl_priv *priv,
198 struct iwl_rx_packet *pkt);
199 /* check for ack health */
200 bool (*check_ack_health)(struct iwl_priv *priv,
201 struct iwl_rx_packet *pkt);
194}; 202};
195 203
196struct iwl_led_ops { 204struct iwl_led_ops {
@@ -295,6 +303,8 @@ struct iwl_cfg {
295 const bool support_wimax_coexist; 303 const bool support_wimax_coexist;
296 u8 plcp_delta_threshold; 304 u8 plcp_delta_threshold;
297 s32 chain_noise_scale; 305 s32 chain_noise_scale;
306 /* timer period for monitor the driver queues */
307 u32 monitor_recover_period;
298}; 308};
299 309
300/*************************** 310/***************************
@@ -430,6 +440,10 @@ void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
430 struct iwl_rx_mem_buffer *rxb); 440 struct iwl_rx_mem_buffer *rxb);
431void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv, 441void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
432 struct iwl_rx_mem_buffer *rxb); 442 struct iwl_rx_mem_buffer *rxb);
443bool iwl_good_plcp_health(struct iwl_priv *priv,
444 struct iwl_rx_packet *pkt);
445bool iwl_good_ack_health(struct iwl_priv *priv,
446 struct iwl_rx_packet *pkt);
433void iwl_rx_statistics(struct iwl_priv *priv, 447void iwl_rx_statistics(struct iwl_priv *priv,
434 struct iwl_rx_mem_buffer *rxb); 448 struct iwl_rx_mem_buffer *rxb);
435void iwl_reply_statistics(struct iwl_priv *priv, 449void iwl_reply_statistics(struct iwl_priv *priv,
@@ -568,6 +582,9 @@ static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv)
568 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl); 582 pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl);
569 return pci_lnk_ctl; 583 return pci_lnk_ctl;
570} 584}
585
586void iwl_bg_monitor_recover(unsigned long data);
587
571#ifdef CONFIG_PM 588#ifdef CONFIG_PM
572int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state); 589int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state);
573int iwl_pci_resume(struct pci_dev *pdev); 590int iwl_pci_resume(struct pci_dev *pdev);
@@ -667,7 +684,7 @@ extern int iwl_send_statistics_request(struct iwl_priv *priv,
667 u8 flags, bool clear); 684 u8 flags, bool clear);
668extern int iwl_verify_ucode(struct iwl_priv *priv); 685extern int iwl_verify_ucode(struct iwl_priv *priv);
669extern int iwl_send_lq_cmd(struct iwl_priv *priv, 686extern int iwl_send_lq_cmd(struct iwl_priv *priv,
670 struct iwl_link_quality_cmd *lq, u8 flags); 687 struct iwl_link_quality_cmd *lq, u8 flags, bool init);
671extern void iwl_rx_reply_rx(struct iwl_priv *priv, 688extern void iwl_rx_reply_rx(struct iwl_priv *priv,
672 struct iwl_rx_mem_buffer *rxb); 689 struct iwl_rx_mem_buffer *rxb);
673extern void iwl_rx_reply_rx_phy(struct iwl_priv *priv, 690extern void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 2e4d47c7139b..e847e6197a3d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -183,6 +183,10 @@ struct iwl_queue {
183 int n_bd; /* number of BDs in this queue */ 183 int n_bd; /* number of BDs in this queue */
184 int write_ptr; /* 1-st empty entry (index) host_w*/ 184 int write_ptr; /* 1-st empty entry (index) host_w*/
185 int read_ptr; /* last used entry (index) host_r*/ 185 int read_ptr; /* last used entry (index) host_r*/
186 /* use for monitoring and recovering the stuck queue */
187 int last_read_ptr; /* storing the last read_ptr */
188 /* number of time read_ptr and last_read_ptr are the same */
189 u8 repeat_same_read_ptr;
186 dma_addr_t dma_addr; /* physical addr for BD's */ 190 dma_addr_t dma_addr; /* physical addr for BD's */
187 int n_window; /* safe queue window */ 191 int n_window; /* safe queue window */
188 u32 id; 192 u32 id;
@@ -544,11 +548,18 @@ struct iwl_qos_info {
544 struct iwl_qosparam_cmd def_qos_parm; 548 struct iwl_qosparam_cmd def_qos_parm;
545}; 549};
546 550
551/*
552 * Structure should be accessed with sta_lock held. When station addition
553 * is in progress (IWL_STA_UCODE_INPROGRESS) it is possible to access only
554 * the commands (iwl_addsta_cmd and iwl_link_quality_cmd) without sta_lock
555 * held.
556 */
547struct iwl_station_entry { 557struct iwl_station_entry {
548 struct iwl_addsta_cmd sta; 558 struct iwl_addsta_cmd sta;
549 struct iwl_tid_data tid[MAX_TID_COUNT]; 559 struct iwl_tid_data tid[MAX_TID_COUNT];
550 u8 used; 560 u8 used;
551 struct iwl_hw_key keyinfo; 561 struct iwl_hw_key keyinfo;
562 struct iwl_link_quality_cmd *lq;
552}; 563};
553 564
554/* 565/*
@@ -1037,6 +1048,11 @@ struct iwl_event_log {
1037#define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3) 1048#define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3)
1038#define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5) 1049#define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
1039 1050
1051/* timer constants use to monitor and recover stuck tx queues in mSecs */
1052#define IWL_MONITORING_PERIOD (1000)
1053#define IWL_ONE_HUNDRED_MSECS (100)
1054#define IWL_SIXTY_SECS (60000)
1055
1040enum iwl_reset { 1056enum iwl_reset {
1041 IWL_RF_RESET = 0, 1057 IWL_RF_RESET = 0,
1042 IWL_FW_RESET, 1058 IWL_FW_RESET,
@@ -1163,7 +1179,6 @@ struct iwl_priv {
1163 1179
1164 u16 active_rate; 1180 u16 active_rate;
1165 1181
1166 u8 assoc_station_added;
1167 u8 start_calib; 1182 u8 start_calib;
1168 struct iwl_sensitivity_data sensitivity_data; 1183 struct iwl_sensitivity_data sensitivity_data;
1169 struct iwl_chain_noise_data chain_noise_data; 1184 struct iwl_chain_noise_data chain_noise_data;
@@ -1285,6 +1300,11 @@ struct iwl_priv {
1285 int ict_index; 1300 int ict_index;
1286 u32 inta; 1301 u32 inta;
1287 bool use_ict; 1302 bool use_ict;
1303 /*
1304 * reporting the number of tids has AGG on. 0 means
1305 * no AGGREGATION
1306 */
1307 u8 agg_tids_count;
1288 } _agn; 1308 } _agn;
1289#endif 1309#endif
1290 }; 1310 };
@@ -1348,6 +1368,7 @@ struct iwl_priv {
1348 struct work_struct run_time_calib_work; 1368 struct work_struct run_time_calib_work;
1349 struct timer_list statistics_periodic; 1369 struct timer_list statistics_periodic;
1350 struct timer_list ucode_trace; 1370 struct timer_list ucode_trace;
1371 struct timer_list monitor_recover;
1351 bool hw_ready; 1372 bool hw_ready;
1352 1373
1353 struct iwl_event_log event_log; 1374 struct iwl_event_log event_log;
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 8116aa0d7678..2fa30dfb7c59 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -616,29 +616,77 @@ static void iwl_accumulative_statistics(struct iwl_priv *priv,
616 616
617#define REG_RECALIB_PERIOD (60) 617#define REG_RECALIB_PERIOD (60)
618 618
619#define PLCP_MSG "plcp_err exceeded %u, %u, %u, %u, %u, %d, %u mSecs\n" 619/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
620void iwl_rx_statistics(struct iwl_priv *priv, 620#define ACK_CNT_RATIO (50)
621 struct iwl_rx_mem_buffer *rxb) 621#define BA_TIMEOUT_CNT (5)
622#define BA_TIMEOUT_MAX (16)
623
624#if defined(CONFIG_IWLAGN) || defined(CONFIG_IWLAGN_MODULE)
625/**
626 * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
627 *
628 * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding
629 * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
630 * operation state.
631 */
632bool iwl_good_ack_health(struct iwl_priv *priv,
633 struct iwl_rx_packet *pkt)
622{ 634{
623 int change; 635 bool rc = true;
624 struct iwl_rx_packet *pkt = rxb_addr(rxb); 636 int actual_ack_cnt_delta, expected_ack_cnt_delta;
637 int ba_timeout_delta;
638
639 actual_ack_cnt_delta =
640 le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) -
641 le32_to_cpu(priv->statistics.tx.actual_ack_cnt);
642 expected_ack_cnt_delta =
643 le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) -
644 le32_to_cpu(priv->statistics.tx.expected_ack_cnt);
645 ba_timeout_delta =
646 le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) -
647 le32_to_cpu(priv->statistics.tx.agg.ba_timeout);
648 if ((priv->_agn.agg_tids_count > 0) &&
649 (expected_ack_cnt_delta > 0) &&
650 (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta)
651 < ACK_CNT_RATIO) &&
652 (ba_timeout_delta > BA_TIMEOUT_CNT)) {
653 IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d,"
654 " expected_ack_cnt = %d\n",
655 actual_ack_cnt_delta, expected_ack_cnt_delta);
656
657#ifdef CONFIG_IWLWIFI_DEBUG
658 IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta = %d\n",
659 priv->delta_statistics.tx.rx_detected_cnt);
660 IWL_DEBUG_RADIO(priv,
661 "ack_or_ba_timeout_collision delta = %d\n",
662 priv->delta_statistics.tx.
663 ack_or_ba_timeout_collision);
664#endif
665 IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n",
666 ba_timeout_delta);
667 if (!actual_ack_cnt_delta &&
668 (ba_timeout_delta >= BA_TIMEOUT_MAX))
669 rc = false;
670 }
671 return rc;
672}
673EXPORT_SYMBOL(iwl_good_ack_health);
674#endif
675
676/**
677 * iwl_good_plcp_health - checks for plcp error.
678 *
679 * When the plcp error is exceeding the thresholds, reset the radio
680 * to improve the throughput.
681 */
682bool iwl_good_plcp_health(struct iwl_priv *priv,
683 struct iwl_rx_packet *pkt)
684{
685 bool rc = true;
625 int combined_plcp_delta; 686 int combined_plcp_delta;
626 unsigned int plcp_msec; 687 unsigned int plcp_msec;
627 unsigned long plcp_received_jiffies; 688 unsigned long plcp_received_jiffies;
628 689
629 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
630 (int)sizeof(priv->statistics),
631 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
632
633 change = ((priv->statistics.general.temperature !=
634 pkt->u.stats.general.temperature) ||
635 ((priv->statistics.flag &
636 STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
637 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
638
639#ifdef CONFIG_IWLWIFI_DEBUG
640 iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
641#endif
642 /* 690 /*
643 * check for plcp_err and trigger radio reset if it exceeds 691 * check for plcp_err and trigger radio reset if it exceeds
644 * the plcp error threshold plcp_delta. 692 * the plcp error threshold plcp_delta.
@@ -659,11 +707,11 @@ void iwl_rx_statistics(struct iwl_priv *priv,
659 le32_to_cpu(priv->statistics.rx.ofdm_ht.plcp_err)); 707 le32_to_cpu(priv->statistics.rx.ofdm_ht.plcp_err));
660 708
661 if ((combined_plcp_delta > 0) && 709 if ((combined_plcp_delta > 0) &&
662 ((combined_plcp_delta * 100) / plcp_msec) > 710 ((combined_plcp_delta * 100) / plcp_msec) >
663 priv->cfg->plcp_delta_threshold) { 711 priv->cfg->plcp_delta_threshold) {
664 /* 712 /*
665 * if plcp_err exceed the threshold, the following 713 * if plcp_err exceed the threshold,
666 * data is printed in csv format: 714 * the following data is printed in csv format:
667 * Text: plcp_err exceeded %d, 715 * Text: plcp_err exceeded %d,
668 * Received ofdm.plcp_err, 716 * Received ofdm.plcp_err,
669 * Current ofdm.plcp_err, 717 * Current ofdm.plcp_err,
@@ -672,22 +720,73 @@ void iwl_rx_statistics(struct iwl_priv *priv,
672 * combined_plcp_delta, 720 * combined_plcp_delta,
673 * plcp_msec 721 * plcp_msec
674 */ 722 */
675 IWL_DEBUG_RADIO(priv, PLCP_MSG, 723 IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
724 "%u, %u, %u, %u, %d, %u mSecs\n",
676 priv->cfg->plcp_delta_threshold, 725 priv->cfg->plcp_delta_threshold,
677 le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err), 726 le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err),
678 le32_to_cpu(priv->statistics.rx.ofdm.plcp_err), 727 le32_to_cpu(priv->statistics.rx.ofdm.plcp_err),
679 le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err), 728 le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err),
680 le32_to_cpu( 729 le32_to_cpu(
681 priv->statistics.rx.ofdm_ht.plcp_err), 730 priv->statistics.rx.ofdm_ht.plcp_err),
682 combined_plcp_delta, plcp_msec); 731 combined_plcp_delta, plcp_msec);
732 rc = false;
733 }
734 }
735 return rc;
736}
737EXPORT_SYMBOL(iwl_good_plcp_health);
683 738
684 /* 739static void iwl_recover_from_statistics(struct iwl_priv *priv,
685 * Reset the RF radio due to the high plcp 740 struct iwl_rx_packet *pkt)
686 * error rate 741{
687 */ 742 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
688 iwl_force_reset(priv, IWL_RF_RESET); 743 return;
744 if (iwl_is_associated(priv)) {
745 if (priv->cfg->ops->lib->check_ack_health) {
746 if (!priv->cfg->ops->lib->check_ack_health(
747 priv, pkt)) {
748 /*
749 * low ack count detected
750 * restart Firmware
751 */
752 IWL_ERR(priv, "low ack count detected, "
753 "restart firmware\n");
754 iwl_force_reset(priv, IWL_FW_RESET);
755 }
756 } else if (priv->cfg->ops->lib->check_plcp_health) {
757 if (!priv->cfg->ops->lib->check_plcp_health(
758 priv, pkt)) {
759 /*
760 * high plcp error detected
761 * reset Radio
762 */
763 iwl_force_reset(priv, IWL_RF_RESET);
764 }
689 } 765 }
690 } 766 }
767}
768
769void iwl_rx_statistics(struct iwl_priv *priv,
770 struct iwl_rx_mem_buffer *rxb)
771{
772 int change;
773 struct iwl_rx_packet *pkt = rxb_addr(rxb);
774
775
776 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
777 (int)sizeof(priv->statistics),
778 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
779
780 change = ((priv->statistics.general.temperature !=
781 pkt->u.stats.general.temperature) ||
782 ((priv->statistics.flag &
783 STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
784 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
785
786#ifdef CONFIG_IWLWIFI_DEBUG
787 iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
788#endif
789 iwl_recover_from_statistics(priv, pkt);
691 790
692 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); 791 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
693 792
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index b1aad306efa9..d401b6f226f9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -29,14 +29,12 @@
29 29
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/sched.h>
32 33
33#include "iwl-dev.h" 34#include "iwl-dev.h"
34#include "iwl-core.h" 35#include "iwl-core.h"
35#include "iwl-sta.h" 36#include "iwl-sta.h"
36 37
37#define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
38#define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
39
40u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr) 38u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
41{ 39{
42 int i; 40 int i;
@@ -64,6 +62,19 @@ u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
64 addr, priv->num_stations); 62 addr, priv->num_stations);
65 63
66 out: 64 out:
65 /*
66 * It may be possible that more commands interacting with stations
67 * arrive before we completed processing the adding of
68 * station
69 */
70 if (ret != IWL_INVALID_STATION &&
71 (!(priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) ||
72 ((priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) &&
73 (priv->stations[ret].used & IWL_STA_UCODE_INPROGRESS)))) {
74 IWL_ERR(priv, "Requested station info for sta %d before ready. \n",
75 ret);
76 ret = IWL_INVALID_STATION;
77 }
67 spin_unlock_irqrestore(&priv->sta_lock, flags); 78 spin_unlock_irqrestore(&priv->sta_lock, flags);
68 return ret; 79 return ret;
69} 80}
@@ -158,13 +169,6 @@ static void iwl_process_add_sta_resp(struct iwl_priv *priv,
158 priv->stations[sta_id].sta.mode == 169 priv->stations[sta_id].sta.mode ==
159 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", 170 STA_CONTROL_MODIFY_MSK ? "Modified" : "Added",
160 addsta->sta.addr); 171 addsta->sta.addr);
161
162 /*
163 * Determine if we wanted to modify or add a station,
164 * if adding a station succeeded we have some more initialization
165 * to do when using station notification. TODO
166 */
167
168 spin_unlock_irqrestore(&priv->sta_lock, flags); 172 spin_unlock_irqrestore(&priv->sta_lock, flags);
169} 173}
170 174
@@ -190,6 +194,10 @@ int iwl_send_add_sta(struct iwl_priv *priv,
190 .flags = flags, 194 .flags = flags,
191 .data = data, 195 .data = data,
192 }; 196 };
197 u8 sta_id = sta->sta.sta_id;
198
199 IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n",
200 sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : "");
193 201
194 if (flags & CMD_ASYNC) 202 if (flags & CMD_ASYNC)
195 cmd.callback = iwl_add_sta_callback; 203 cmd.callback = iwl_add_sta_callback;
@@ -263,18 +271,19 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
263} 271}
264 272
265/** 273/**
266 * iwl_add_station - Add station to tables in driver and device 274 * iwl_prep_station - Prepare station information for addition
275 *
276 * should be called with sta_lock held
267 */ 277 */
268u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags, 278static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
269 struct ieee80211_sta_ht_cap *ht_info) 279 bool is_ap,
280 struct ieee80211_sta_ht_cap *ht_info)
270{ 281{
271 struct iwl_station_entry *station; 282 struct iwl_station_entry *station;
272 unsigned long flags_spin;
273 int i; 283 int i;
274 int sta_id = IWL_INVALID_STATION; 284 u8 sta_id = IWL_INVALID_STATION;
275 u16 rate; 285 u16 rate;
276 286
277 spin_lock_irqsave(&priv->sta_lock, flags_spin);
278 if (is_ap) 287 if (is_ap)
279 sta_id = IWL_AP_ID; 288 sta_id = IWL_AP_ID;
280 else if (is_broadcast_ether_addr(addr)) 289 else if (is_broadcast_ether_addr(addr))
@@ -292,20 +301,32 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags,
292 sta_id = i; 301 sta_id = i;
293 } 302 }
294 303
295 /* These two conditions have the same outcome, but keep them separate 304 /*
296 since they have different meanings */ 305 * These two conditions have the same outcome, but keep them
297 if (unlikely(sta_id == IWL_INVALID_STATION)) { 306 * separate
298 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 307 */
308 if (unlikely(sta_id == IWL_INVALID_STATION))
309 return sta_id;
310
311 /*
312 * uCode is not able to deal with multiple requests to add a
313 * station. Keep track if one is in progress so that we do not send
314 * another.
315 */
316 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
317 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
318 sta_id);
299 return sta_id; 319 return sta_id;
300 } 320 }
301 321
302 if (priv->stations[sta_id].used && 322 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
323 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) &&
303 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { 324 !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
304 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 325 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
326 sta_id, addr);
305 return sta_id; 327 return sta_id;
306 } 328 }
307 329
308
309 station = &priv->stations[sta_id]; 330 station = &priv->stations[sta_id];
310 station->used = IWL_STA_DRIVER_ACTIVE; 331 station->used = IWL_STA_DRIVER_ACTIVE;
311 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", 332 IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
@@ -330,86 +351,185 @@ u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags,
330 /* Turn on both antennas for the station... */ 351 /* Turn on both antennas for the station... */
331 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK); 352 station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
332 353
354 return sta_id;
355
356}
357
358#define STA_WAIT_TIMEOUT (HZ/2)
359
360/**
361 * iwl_add_station_common -
362 */
363int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
364 bool is_ap,
365 struct ieee80211_sta_ht_cap *ht_info,
366 u8 *sta_id_r)
367{
368 struct iwl_station_entry *station;
369 unsigned long flags_spin;
370 int ret = 0;
371 u8 sta_id;
372
373 *sta_id_r = 0;
374 spin_lock_irqsave(&priv->sta_lock, flags_spin);
375 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info);
376 if (sta_id == IWL_INVALID_STATION) {
377 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
378 addr);
379 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
380 return -EINVAL;
381 }
382
383 /*
384 * uCode is not able to deal with multiple requests to add a
385 * station. Keep track if one is in progress so that we do not send
386 * another.
387 */
388 if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) {
389 IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n",
390 sta_id);
391 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
392 return -EEXIST;
393 }
394
395 if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) &&
396 (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
397 IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n",
398 sta_id, addr);
399 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
400 return -EEXIST;
401 }
402
403 priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS;
404 station = &priv->stations[sta_id];
333 spin_unlock_irqrestore(&priv->sta_lock, flags_spin); 405 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
334 406
335 /* Add station to device's station table */ 407 /* Add station to device's station table */
336 iwl_send_add_sta(priv, &station->sta, flags); 408 ret = iwl_send_add_sta(priv, &station->sta, CMD_SYNC);
337 return sta_id; 409 if (ret) {
338 410 IWL_ERR(priv, "Adding station %pM failed.\n", station->sta.sta.addr);
411 spin_lock_irqsave(&priv->sta_lock, flags_spin);
412 priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
413 priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
414 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
415 }
416 *sta_id_r = sta_id;
417 return ret;
339} 418}
340EXPORT_SYMBOL(iwl_add_station); 419EXPORT_SYMBOL(iwl_add_station_common);
341 420
342static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const u8 *addr) 421static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
343{ 422{
344 unsigned long flags; 423 int i, r;
345 u8 sta_id = iwl_find_station(priv, addr); 424 struct iwl_link_quality_cmd link_cmd = {
425 .reserved1 = 0,
426 };
427 u32 rate_flags;
346 428
347 BUG_ON(sta_id == IWL_INVALID_STATION); 429 /* Set up the rate scaling to start at selected rate, fall back
430 * all the way down to 1M in IEEE order, and then spin on 1M */
431 if (is_ap)
432 r = IWL_RATE_54M_INDEX;
433 else if (priv->band == IEEE80211_BAND_5GHZ)
434 r = IWL_RATE_6M_INDEX;
435 else
436 r = IWL_RATE_1M_INDEX;
437
438 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
439 rate_flags = 0;
440 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
441 rate_flags |= RATE_MCS_CCK_MSK;
348 442
349 IWL_DEBUG_ASSOC(priv, "Removed STA from Ucode: %pM\n", addr); 443 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
444 RATE_MCS_ANT_POS;
350 445
351 spin_lock_irqsave(&priv->sta_lock, flags); 446 link_cmd.rs_table[i].rate_n_flags =
447 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
448 r = iwl_get_prev_ieee_rate(r);
449 }
352 450
353 /* Ucode must be active and driver must be non active */ 451 link_cmd.general_params.single_stream_ant_msk =
354 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE) 452 first_antenna(priv->hw_params.valid_tx_ant);
355 IWL_ERR(priv, "removed non active STA %d\n", sta_id); 453 link_cmd.general_params.dual_stream_ant_msk = 3;
454 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
455 link_cmd.agg_params.agg_time_limit =
456 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
356 457
357 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; 458 /* Update the rate scaling for control frame Tx to AP */
459 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
358 460
359 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); 461 iwl_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD,
360 spin_unlock_irqrestore(&priv->sta_lock, flags); 462 sizeof(link_cmd), &link_cmd);
361} 463}
362 464
363static void iwl_remove_sta_callback(struct iwl_priv *priv, 465/*
364 struct iwl_device_cmd *cmd, 466 * iwl_add_local_stations - Add stations not requested by mac80211
365 struct iwl_rx_packet *pkt) 467 *
468 * This will be either the broadcast station or the bssid station needed by
469 * ad-hoc.
470 *
471 * Function sleeps.
472 */
473int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs)
366{ 474{
367 struct iwl_rem_sta_cmd *rm_sta = 475 int ret;
368 (struct iwl_rem_sta_cmd *)cmd->cmd.payload; 476 u8 sta_id;
369 const u8 *addr = rm_sta->addr;
370 477
371 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { 478 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
372 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", 479 if (ret) {
373 pkt->hdr.flags); 480 IWL_ERR(priv, "Unable to add station %pM\n", addr);
374 return; 481 return ret;
375 } 482 }
376 483
377 switch (pkt->u.rem_sta.status) { 484 if (init_rs)
378 case REM_STA_SUCCESS_MSK: 485 /* Set up default rate scaling table in device's station table */
379 iwl_sta_ucode_deactivate(priv, addr); 486 iwl_sta_init_lq(priv, addr, false);
380 break; 487 return 0;
381 default: 488}
382 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); 489EXPORT_SYMBOL(iwl_add_local_station);
383 break; 490
384 } 491/**
492 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
493 *
494 * priv->sta_lock must be held
495 */
496static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
497{
498 /* Ucode must be active and driver must be non active */
499 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
500 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
501
502 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
503
504 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
505 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
385} 506}
386 507
387static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr, 508static int iwl_send_remove_station(struct iwl_priv *priv,
388 u8 flags) 509 struct iwl_station_entry *station)
389{ 510{
390 struct iwl_rx_packet *pkt; 511 struct iwl_rx_packet *pkt;
391 int ret; 512 int ret;
392 513
514 unsigned long flags_spin;
393 struct iwl_rem_sta_cmd rm_sta_cmd; 515 struct iwl_rem_sta_cmd rm_sta_cmd;
394 516
395 struct iwl_host_cmd cmd = { 517 struct iwl_host_cmd cmd = {
396 .id = REPLY_REMOVE_STA, 518 .id = REPLY_REMOVE_STA,
397 .len = sizeof(struct iwl_rem_sta_cmd), 519 .len = sizeof(struct iwl_rem_sta_cmd),
398 .flags = flags, 520 .flags = CMD_SYNC,
399 .data = &rm_sta_cmd, 521 .data = &rm_sta_cmd,
400 }; 522 };
401 523
402 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); 524 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
403 rm_sta_cmd.num_sta = 1; 525 rm_sta_cmd.num_sta = 1;
404 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN); 526 memcpy(&rm_sta_cmd.addr, &station->sta.sta.addr , ETH_ALEN);
527
528 cmd.flags |= CMD_WANT_SKB;
405 529
406 if (flags & CMD_ASYNC)
407 cmd.callback = iwl_remove_sta_callback;
408 else
409 cmd.flags |= CMD_WANT_SKB;
410 ret = iwl_send_cmd(priv, &cmd); 530 ret = iwl_send_cmd(priv, &cmd);
411 531
412 if (ret || (flags & CMD_ASYNC)) 532 if (ret)
413 return ret; 533 return ret;
414 534
415 pkt = (struct iwl_rx_packet *)cmd.reply_page; 535 pkt = (struct iwl_rx_packet *)cmd.reply_page;
@@ -422,7 +542,9 @@ static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
422 if (!ret) { 542 if (!ret) {
423 switch (pkt->u.rem_sta.status) { 543 switch (pkt->u.rem_sta.status) {
424 case REM_STA_SUCCESS_MSK: 544 case REM_STA_SUCCESS_MSK:
425 iwl_sta_ucode_deactivate(priv, addr); 545 spin_lock_irqsave(&priv->sta_lock, flags_spin);
546 iwl_sta_ucode_deactivate(priv, station->sta.sta.sta_id);
547 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
426 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); 548 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
427 break; 549 break;
428 default: 550 default:
@@ -439,23 +561,35 @@ static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
439/** 561/**
440 * iwl_remove_station - Remove driver's knowledge of station. 562 * iwl_remove_station - Remove driver's knowledge of station.
441 */ 563 */
442int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap) 564static int iwl_remove_station(struct iwl_priv *priv, struct ieee80211_sta *sta)
443{ 565{
444 int sta_id = IWL_INVALID_STATION; 566 int sta_id = IWL_INVALID_STATION;
445 int i, ret = -EINVAL; 567 int i, ret = -EINVAL;
446 unsigned long flags; 568 unsigned long flags;
569 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
570 struct iwl_station_entry *station;
571
572 if (!iwl_is_ready(priv)) {
573 IWL_DEBUG_INFO(priv,
574 "Unable to remove station %pM, device not ready. \n",
575 sta->addr);
576 /*
577 * It is typical for stations to be removed when we are
578 * going down. Return success since device will be down
579 * soon anyway
580 */
581 return 0;
582 }
447 583
448 spin_lock_irqsave(&priv->sta_lock, flags); 584 spin_lock_irqsave(&priv->sta_lock, flags);
449 585
450 if (is_ap) 586 if (is_ap)
451 sta_id = IWL_AP_ID; 587 sta_id = IWL_AP_ID;
452 else if (is_broadcast_ether_addr(addr))
453 sta_id = priv->hw_params.bcast_sta_id;
454 else 588 else
455 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) 589 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
456 if (priv->stations[i].used && 590 if (priv->stations[i].used &&
457 !compare_ether_addr(priv->stations[i].sta.sta.addr, 591 !compare_ether_addr(priv->stations[i].sta.sta.addr,
458 addr)) { 592 sta->addr)) {
459 sta_id = i; 593 sta_id = i;
460 break; 594 break;
461 } 595 }
@@ -464,17 +598,17 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
464 goto out; 598 goto out;
465 599
466 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", 600 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
467 sta_id, addr); 601 sta_id, sta->addr);
468 602
469 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { 603 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
470 IWL_ERR(priv, "Removing %pM but non DRIVER active\n", 604 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
471 addr); 605 sta->addr);
472 goto out; 606 goto out;
473 } 607 }
474 608
475 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { 609 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
476 IWL_ERR(priv, "Removing %pM but non UCODE active\n", 610 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
477 addr); 611 sta->addr);
478 goto out; 612 goto out;
479 } 613 }
480 614
@@ -485,9 +619,10 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
485 619
486 BUG_ON(priv->num_stations < 0); 620 BUG_ON(priv->num_stations < 0);
487 621
622 station = &priv->stations[sta_id];
488 spin_unlock_irqrestore(&priv->sta_lock, flags); 623 spin_unlock_irqrestore(&priv->sta_lock, flags);
489 624
490 ret = iwl_send_remove_station(priv, addr, CMD_ASYNC); 625 ret = iwl_send_remove_station(priv, station);
491 return ret; 626 return ret;
492out: 627out:
493 spin_unlock_irqrestore(&priv->sta_lock, flags); 628 spin_unlock_irqrestore(&priv->sta_lock, flags);
@@ -495,37 +630,122 @@ out:
495} 630}
496 631
497/** 632/**
498 * iwl_clear_stations_table - Clear the driver's station table 633 * iwl_clear_ucode_stations() - clear entire station table driver and/or ucode
499 * 634 * @priv:
500 * NOTE: This does not clear or otherwise alter the device's station table. 635 * @force: If set then the uCode station table needs to be cleared here. If
636 * not set then the uCode station table has already been cleared,
637 * for example after sending it a RXON command without ASSOC bit
638 * set, and we just need to change driver state here.
501 */ 639 */
502void iwl_clear_stations_table(struct iwl_priv *priv) 640void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force)
503{ 641{
504 unsigned long flags;
505 int i; 642 int i;
643 unsigned long flags_spin;
644 bool cleared = false;
645
646 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver%s\n",
647 force ? " and ucode" : "");
648
649 if (force) {
650 if (!iwl_is_ready(priv)) {
651 /*
652 * If device is not ready at this point the station
653 * table is likely already empty (uCode not ready
654 * to receive station requests) or will soon be
655 * due to interface going down.
656 */
657 IWL_DEBUG_INFO(priv, "Unable to remove stations from device - device not ready\n");
658 } else {
659 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL);
660 }
661 }
506 662
507 spin_lock_irqsave(&priv->sta_lock, flags); 663 spin_lock_irqsave(&priv->sta_lock, flags_spin);
664 if (force) {
665 IWL_DEBUG_INFO(priv, "Clearing all station information in driver\n");
666 priv->num_stations = 0;
667 memset(priv->stations, 0, sizeof(priv->stations));
668 } else {
669 for (i = 0; i < priv->hw_params.max_stations; i++) {
670 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
671 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d \n", i);
672 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
673 cleared = true;
674 }
675 }
676 }
677 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
508 678
509 if (iwl_is_alive(priv) && 679 if (!cleared)
510 !test_bit(STATUS_EXIT_PENDING, &priv->status) && 680 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
511 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL)) 681}
512 IWL_ERR(priv, "Couldn't clear the station table\n"); 682EXPORT_SYMBOL(iwl_clear_ucode_stations);
513 683
514 priv->num_stations = 0; 684/**
515 memset(priv->stations, 0, sizeof(priv->stations)); 685 * iwl_restore_stations() - Restore driver known stations to device
686 *
687 * All stations considered active by driver, but not present in ucode, is
688 * restored.
689 *
690 * Function sleeps.
691 */
692void iwl_restore_stations(struct iwl_priv *priv)
693{
694 struct iwl_station_entry *station;
695 unsigned long flags_spin;
696 int i;
697 bool found = false;
698 int ret;
516 699
517 /* clean ucode key table bit map */ 700 if (!iwl_is_ready(priv)) {
518 priv->ucode_key_table = 0; 701 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
702 return;
703 }
519 704
520 /* keep track of static keys */ 705 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
521 for (i = 0; i < WEP_KEYS_MAX ; i++) { 706 spin_lock_irqsave(&priv->sta_lock, flags_spin);
522 if (priv->wep_keys[i].key_size) 707 for (i = 0; i < priv->hw_params.max_stations; i++) {
523 set_bit(i, &priv->ucode_key_table); 708 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
709 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
710 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
711 priv->stations[i].sta.sta.addr);
712 priv->stations[i].sta.mode = 0;
713 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
714 found = true;
715 }
524 } 716 }
525 717
526 spin_unlock_irqrestore(&priv->sta_lock, flags); 718 for (i = 0; i < priv->hw_params.max_stations; i++) {
719 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
720 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
721 station = &priv->stations[i];
722 ret = iwl_send_add_sta(priv, &priv->stations[i].sta, CMD_SYNC);
723 if (ret) {
724 IWL_ERR(priv, "Adding station %pM failed.\n",
725 station->sta.sta.addr);
726 spin_lock_irqsave(&priv->sta_lock, flags_spin);
727 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
728 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
729 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
730 }
731 /*
732 * Rate scaling has already been initialized, send
733 * current LQ command
734 */
735 if (station->lq)
736 iwl_send_lq_cmd(priv, station->lq, CMD_SYNC, true);
737 spin_lock_irqsave(&priv->sta_lock, flags_spin);
738 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
739 }
740 }
741
742 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
743 if (!found)
744 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
745 else
746 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
527} 747}
528EXPORT_SYMBOL(iwl_clear_stations_table); 748EXPORT_SYMBOL(iwl_restore_stations);
529 749
530int iwl_get_free_ucode_key_index(struct iwl_priv *priv) 750int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
531{ 751{
@@ -948,9 +1168,22 @@ static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
948} 1168}
949#endif 1169#endif
950 1170
1171/**
1172 * iwl_send_lq_cmd() - Send link quality command
1173 * @init: This command is sent as part of station initialization right
1174 * after station has been added.
1175 *
1176 * The link quality command is sent as the last step of station creation.
1177 * This is the special case in which init is set and we call a callback in
1178 * this case to clear the state indicating that station creation is in
1179 * progress.
1180 */
951int iwl_send_lq_cmd(struct iwl_priv *priv, 1181int iwl_send_lq_cmd(struct iwl_priv *priv,
952 struct iwl_link_quality_cmd *lq, u8 flags) 1182 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
953{ 1183{
1184 int ret = 0;
1185 unsigned long flags_spin;
1186
954 struct iwl_host_cmd cmd = { 1187 struct iwl_host_cmd cmd = {
955 .id = REPLY_TX_LINK_QUALITY_CMD, 1188 .id = REPLY_TX_LINK_QUALITY_CMD,
956 .len = sizeof(struct iwl_link_quality_cmd), 1189 .len = sizeof(struct iwl_link_quality_cmd),
@@ -966,167 +1199,31 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
966 lq->sta_id = IWL_AP_ID; 1199 lq->sta_id = IWL_AP_ID;
967 1200
968 iwl_dump_lq_cmd(priv, lq); 1201 iwl_dump_lq_cmd(priv, lq);
1202 BUG_ON(init && (cmd.flags & CMD_ASYNC));
969 1203
970 if (iwl_is_associated(priv) && priv->assoc_station_added) 1204 iwl_dump_lq_cmd(priv, lq);
971 return iwl_send_cmd(priv, &cmd); 1205 ret = iwl_send_cmd(priv, &cmd);
1206 if (ret || (cmd.flags & CMD_ASYNC))
1207 return ret;
972 1208
1209 if (init) {
1210 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d \n",
1211 lq->sta_id);
1212 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1213 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1214 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1215 }
973 return 0; 1216 return 0;
974} 1217}
975EXPORT_SYMBOL(iwl_send_lq_cmd); 1218EXPORT_SYMBOL(iwl_send_lq_cmd);
976 1219
977/** 1220/**
978 * iwl_sta_init_lq - Initialize a station's hardware rate table
979 *
980 * The uCode's station table contains a table of fallback rates
981 * for automatic fallback during transmission.
982 *
983 * NOTE: This sets up a default set of values. These will be replaced later
984 * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
985 * rc80211_simple.
986 *
987 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
988 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
989 * which requires station table entry to exist).
990 */
991static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
992{
993 int i, r;
994 struct iwl_link_quality_cmd link_cmd = {
995 .reserved1 = 0,
996 };
997 u32 rate_flags;
998
999 /* Set up the rate scaling to start at selected rate, fall back
1000 * all the way down to 1M in IEEE order, and then spin on 1M */
1001 if (is_ap)
1002 r = IWL_RATE_54M_INDEX;
1003 else if (priv->band == IEEE80211_BAND_5GHZ)
1004 r = IWL_RATE_6M_INDEX;
1005 else
1006 r = IWL_RATE_1M_INDEX;
1007
1008 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1009 rate_flags = 0;
1010 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
1011 rate_flags |= RATE_MCS_CCK_MSK;
1012
1013 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
1014 RATE_MCS_ANT_POS;
1015
1016 link_cmd.rs_table[i].rate_n_flags =
1017 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
1018 r = iwl_get_prev_ieee_rate(r);
1019 }
1020
1021 link_cmd.general_params.single_stream_ant_msk =
1022 first_antenna(priv->hw_params.valid_tx_ant);
1023 link_cmd.general_params.dual_stream_ant_msk = 3;
1024 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
1025 link_cmd.agg_params.agg_time_limit =
1026 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
1027
1028 /* Update the rate scaling for control frame Tx to AP */
1029 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
1030
1031 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
1032 sizeof(link_cmd), &link_cmd, NULL);
1033}
1034
1035/**
1036 * iwl_rxon_add_station - add station into station table.
1037 *
1038 * there is only one AP station with id= IWL_AP_ID
1039 * NOTE: mutex must be held before calling this function
1040 */
1041int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
1042{
1043 struct ieee80211_sta *sta;
1044 struct ieee80211_sta_ht_cap ht_config;
1045 struct ieee80211_sta_ht_cap *cur_ht_config = NULL;
1046 u8 sta_id;
1047
1048 /*
1049 * Set HT capabilities. It is ok to set this struct even if not using
1050 * HT config: the priv->current_ht_config.is_ht flag will just be false
1051 */
1052 rcu_read_lock();
1053 sta = ieee80211_find_sta(priv->vif, addr);
1054 if (sta) {
1055 memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
1056 cur_ht_config = &ht_config;
1057 }
1058 rcu_read_unlock();
1059
1060 /* Add station to device's station table */
1061 sta_id = iwl_add_station(priv, addr, is_ap, CMD_SYNC, cur_ht_config);
1062
1063 /* Set up default rate scaling table in device's station table */
1064 iwl_sta_init_lq(priv, addr, is_ap);
1065
1066 return sta_id;
1067}
1068EXPORT_SYMBOL(iwl_rxon_add_station);
1069
1070/**
1071 * iwl_sta_init_bcast_lq - Initialize a bcast station's hardware rate table
1072 *
1073 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
1074 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
1075 * which requires station table entry to exist).
1076 */
1077static void iwl_sta_init_bcast_lq(struct iwl_priv *priv)
1078{
1079 int i, r;
1080 struct iwl_link_quality_cmd link_cmd = {
1081 .reserved1 = 0,
1082 };
1083 u32 rate_flags;
1084
1085 /* Set up the rate scaling to start at selected rate, fall back
1086 * all the way down to 1M in IEEE order, and then spin on 1M */
1087 if (priv->band == IEEE80211_BAND_5GHZ)
1088 r = IWL_RATE_6M_INDEX;
1089 else
1090 r = IWL_RATE_1M_INDEX;
1091
1092 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1093 rate_flags = 0;
1094 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
1095 rate_flags |= RATE_MCS_CCK_MSK;
1096
1097 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
1098 RATE_MCS_ANT_POS;
1099
1100 link_cmd.rs_table[i].rate_n_flags =
1101 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
1102 r = iwl_get_prev_ieee_rate(r);
1103 }
1104
1105 link_cmd.general_params.single_stream_ant_msk =
1106 first_antenna(priv->hw_params.valid_tx_ant);
1107 link_cmd.general_params.dual_stream_ant_msk = 3;
1108 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
1109 link_cmd.agg_params.agg_time_limit =
1110 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
1111
1112 /* Update the rate scaling for control frame Tx to AP */
1113 link_cmd.sta_id = priv->hw_params.bcast_sta_id;
1114
1115 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
1116 sizeof(link_cmd), &link_cmd, NULL);
1117}
1118
1119
1120/**
1121 * iwl_add_bcast_station - add broadcast station into station table. 1221 * iwl_add_bcast_station - add broadcast station into station table.
1122 */ 1222 */
1123void iwl_add_bcast_station(struct iwl_priv *priv) 1223void iwl_add_bcast_station(struct iwl_priv *priv)
1124{ 1224{
1125 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); 1225 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1126 iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL); 1226 iwl_add_local_station(priv, iwl_bcast_addr, true);
1127
1128 /* Set up default rate scaling table in device's station table */
1129 iwl_sta_init_bcast_lq(priv);
1130} 1227}
1131EXPORT_SYMBOL(iwl_add_bcast_station); 1228EXPORT_SYMBOL(iwl_add_bcast_station);
1132 1229
@@ -1136,7 +1233,14 @@ EXPORT_SYMBOL(iwl_add_bcast_station);
1136void iwl3945_add_bcast_station(struct iwl_priv *priv) 1233void iwl3945_add_bcast_station(struct iwl_priv *priv)
1137{ 1234{
1138 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); 1235 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1139 iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL); 1236 iwl_add_local_station(priv, iwl_bcast_addr, false);
1237 /*
1238 * It is assumed that when station is added more initialization
1239 * needs to be done, but for 3945 it is not the case and we can
1240 * just release station table access right here.
1241 */
1242 priv->stations[priv->hw_params.bcast_sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1243
1140} 1244}
1141EXPORT_SYMBOL(iwl3945_add_bcast_station); 1245EXPORT_SYMBOL(iwl3945_add_bcast_station);
1142 1246
@@ -1159,6 +1263,13 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1159 /* If we are a client station in a BSS network, use the special 1263 /* If we are a client station in a BSS network, use the special
1160 * AP station entry (that's the only station we communicate with) */ 1264 * AP station entry (that's the only station we communicate with) */
1161 case NL80211_IFTYPE_STATION: 1265 case NL80211_IFTYPE_STATION:
1266 /*
1267 * If addition of station not complete yet, which means
1268 * that rate scaling has not been initialized, then return
1269 * the broadcast station.
1270 */
1271 if (!(priv->stations[IWL_AP_ID].used & IWL_STA_UCODE_ACTIVE))
1272 return priv->hw_params.bcast_sta_id;
1162 return IWL_AP_ID; 1273 return IWL_AP_ID;
1163 1274
1164 /* If we are an AP, then find the station, or use BCAST */ 1275 /* If we are an AP, then find the station, or use BCAST */
@@ -1175,13 +1286,6 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1175 if (sta_id != IWL_INVALID_STATION) 1286 if (sta_id != IWL_INVALID_STATION)
1176 return sta_id; 1287 return sta_id;
1177 1288
1178 /* Create new station table entry */
1179 sta_id = iwl_add_station(priv, hdr->addr1, false,
1180 CMD_ASYNC, NULL);
1181
1182 if (sta_id != IWL_INVALID_STATION)
1183 return sta_id;
1184
1185 IWL_DEBUG_DROP(priv, "Station %pM not in station map. " 1289 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
1186 "Defaulting to broadcast...\n", 1290 "Defaulting to broadcast...\n",
1187 hdr->addr1); 1291 hdr->addr1);
@@ -1291,3 +1395,19 @@ void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1291 1395
1292 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); 1396 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1293} 1397}
1398
1399int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1400 struct ieee80211_vif *vif,
1401 struct ieee80211_sta *sta)
1402{
1403 int ret;
1404 struct iwl_priv *priv = hw->priv;
1405 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1406 sta->addr);
1407 ret = iwl_remove_station(priv, sta);
1408 if (ret)
1409 IWL_ERR(priv, "Error removing station %pM\n",
1410 sta->addr);
1411 return ret;
1412}
1413EXPORT_SYMBOL(iwl_mac_sta_remove);
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 2dc35fe28f56..87a34997a758 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -32,6 +32,12 @@
32#define HW_KEY_DYNAMIC 0 32#define HW_KEY_DYNAMIC 0
33#define HW_KEY_DEFAULT 1 33#define HW_KEY_DEFAULT 1
34 34
35#define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
36#define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
37#define IWL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of
38 being activated */
39
40
35/** 41/**
36 * iwl_find_station - Find station id for a given BSSID 42 * iwl_find_station - Find station id for a given BSSID
37 * @bssid: MAC address of station ID to find 43 * @bssid: MAC address of station ID to find
@@ -51,18 +57,22 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
51 struct ieee80211_key_conf *keyconf, 57 struct ieee80211_key_conf *keyconf,
52 const u8 *addr, u32 iv32, u16 *phase1key); 58 const u8 *addr, u32 iv32, u16 *phase1key);
53 59
54int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap);
55void iwl_add_bcast_station(struct iwl_priv *priv); 60void iwl_add_bcast_station(struct iwl_priv *priv);
56void iwl3945_add_bcast_station(struct iwl_priv *priv); 61void iwl3945_add_bcast_station(struct iwl_priv *priv);
57int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap); 62void iwl_restore_stations(struct iwl_priv *priv);
58void iwl_clear_stations_table(struct iwl_priv *priv); 63void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force);
59int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 64int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
60int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 65int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
61int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr); 66int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr);
62int iwl_send_add_sta(struct iwl_priv *priv, 67int iwl_send_add_sta(struct iwl_priv *priv,
63 struct iwl_addsta_cmd *sta, u8 flags); 68 struct iwl_addsta_cmd *sta, u8 flags);
64u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags, 69int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs);
65 struct ieee80211_sta_ht_cap *ht_info); 70int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
71 bool is_ap,
72 struct ieee80211_sta_ht_cap *ht_info,
73 u8 *sta_id_r);
74int iwl_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
75 struct ieee80211_sta *sta);
66void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid); 76void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid);
67int iwl_sta_rx_agg_start(struct iwl_priv *priv, 77int iwl_sta_rx_agg_start(struct iwl_priv *priv,
68 const u8 *addr, int tid, u16 ssn); 78 const u8 *addr, int tid, u16 ssn);
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index d6222aabe6ed..1e481f3fcabf 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -322,6 +322,8 @@ static int iwl_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
322 q->high_mark = 2; 322 q->high_mark = 2;
323 323
324 q->write_ptr = q->read_ptr = 0; 324 q->write_ptr = q->read_ptr = 0;
325 q->last_read_ptr = 0;
326 q->repeat_same_read_ptr = 0;
325 327
326 return 0; 328 return 0;
327} 329}
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 2579bbcaab36..4995134d7e4a 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -2480,8 +2480,6 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2480 goto restart; 2480 goto restart;
2481 } 2481 }
2482 2482
2483 iwl_clear_stations_table(priv);
2484
2485 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); 2483 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
2486 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill); 2484 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
2487 2485
@@ -2503,6 +2501,13 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2503 /* After the ALIVE response, we can send commands to 3945 uCode */ 2501 /* After the ALIVE response, we can send commands to 3945 uCode */
2504 set_bit(STATUS_ALIVE, &priv->status); 2502 set_bit(STATUS_ALIVE, &priv->status);
2505 2503
2504 if (priv->cfg->ops->lib->recover_from_tx_stall) {
2505 /* Enable timer to monitor the driver queues */
2506 mod_timer(&priv->monitor_recover,
2507 jiffies +
2508 msecs_to_jiffies(priv->cfg->monitor_recover_period));
2509 }
2510
2506 if (iwl_is_rfkill(priv)) 2511 if (iwl_is_rfkill(priv))
2507 return; 2512 return;
2508 2513
@@ -2558,7 +2563,8 @@ static void __iwl3945_down(struct iwl_priv *priv)
2558 if (!exit_pending) 2563 if (!exit_pending)
2559 set_bit(STATUS_EXIT_PENDING, &priv->status); 2564 set_bit(STATUS_EXIT_PENDING, &priv->status);
2560 2565
2561 iwl_clear_stations_table(priv); 2566 /* Station information will now be cleared in device */
2567 iwl_clear_ucode_stations(priv, true);
2562 2568
2563 /* Unblock any waiting calls */ 2569 /* Unblock any waiting calls */
2564 wake_up_interruptible_all(&priv->wait_command_queue); 2570 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -2692,8 +2698,6 @@ static int __iwl3945_up(struct iwl_priv *priv)
2692 2698
2693 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2699 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2694 2700
2695 iwl_clear_stations_table(priv);
2696
2697 /* load bootstrap state machine, 2701 /* load bootstrap state machine,
2698 * load bootstrap program into processor's memory, 2702 * load bootstrap program into processor's memory,
2699 * prepare to load the "initialize" uCode */ 2703 * prepare to load the "initialize" uCode */
@@ -3119,12 +3123,13 @@ void iwl3945_post_associate(struct iwl_priv *priv)
3119 case NL80211_IFTYPE_ADHOC: 3123 case NL80211_IFTYPE_ADHOC:
3120 3124
3121 priv->assoc_id = 1; 3125 priv->assoc_id = 1;
3122 iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL); 3126 iwl_add_local_station(priv, priv->bssid, false);
3123 iwl3945_sync_sta(priv, IWL_STA_ID, 3127 iwl3945_sync_sta(priv, IWL_STA_ID,
3124 (priv->band == IEEE80211_BAND_5GHZ) ? 3128 (priv->band == IEEE80211_BAND_5GHZ) ?
3125 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, 3129 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3126 CMD_ASYNC); 3130 CMD_ASYNC);
3127 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); 3131 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3132
3128 iwl3945_send_beacon_cmd(priv); 3133 iwl3945_send_beacon_cmd(priv);
3129 3134
3130 break; 3135 break;
@@ -3309,7 +3314,7 @@ void iwl3945_config_ap(struct iwl_priv *priv)
3309 /* restore RXON assoc */ 3314 /* restore RXON assoc */
3310 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3315 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3311 iwlcore_commit_rxon(priv); 3316 iwlcore_commit_rxon(priv);
3312 iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL); 3317 iwl_add_local_station(priv, iwl_bcast_addr, false);
3313 } 3318 }
3314 iwl3945_send_beacon_cmd(priv); 3319 iwl3945_send_beacon_cmd(priv);
3315 3320
@@ -3376,6 +3381,38 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3376 return ret; 3381 return ret;
3377} 3382}
3378 3383
3384static int iwl3945_mac_sta_add(struct ieee80211_hw *hw,
3385 struct ieee80211_vif *vif,
3386 struct ieee80211_sta *sta)
3387{
3388 struct iwl_priv *priv = hw->priv;
3389 int ret;
3390 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
3391 u8 sta_id;
3392
3393 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
3394 sta->addr);
3395
3396 ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap,
3397 &sta_id);
3398 if (ret) {
3399 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3400 sta->addr, ret);
3401 /* Should we return success if return code is EEXIST ? */
3402 return ret;
3403 }
3404
3405 /* Initialize rate scaling */
3406 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM \n",
3407 sta->addr);
3408 iwl3945_rs_rate_init(priv, sta, sta_id);
3409
3410 return 0;
3411
3412
3413
3414 return ret;
3415}
3379/***************************************************************************** 3416/*****************************************************************************
3380 * 3417 *
3381 * sysfs attributes 3418 * sysfs attributes
@@ -3766,6 +3803,13 @@ static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
3766 3803
3767 iwl3945_hw_setup_deferred_work(priv); 3804 iwl3945_hw_setup_deferred_work(priv);
3768 3805
3806 if (priv->cfg->ops->lib->recover_from_tx_stall) {
3807 init_timer(&priv->monitor_recover);
3808 priv->monitor_recover.data = (unsigned long)priv;
3809 priv->monitor_recover.function =
3810 priv->cfg->ops->lib->recover_from_tx_stall;
3811 }
3812
3769 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) 3813 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3770 iwl3945_irq_tasklet, (unsigned long)priv); 3814 iwl3945_irq_tasklet, (unsigned long)priv);
3771} 3815}
@@ -3778,6 +3822,8 @@ static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
3778 cancel_delayed_work(&priv->scan_check); 3822 cancel_delayed_work(&priv->scan_check);
3779 cancel_delayed_work(&priv->alive_start); 3823 cancel_delayed_work(&priv->alive_start);
3780 cancel_work_sync(&priv->beacon_update); 3824 cancel_work_sync(&priv->beacon_update);
3825 if (priv->cfg->ops->lib->recover_from_tx_stall)
3826 del_timer_sync(&priv->monitor_recover);
3781} 3827}
3782 3828
3783static struct attribute *iwl3945_sysfs_entries[] = { 3829static struct attribute *iwl3945_sysfs_entries[] = {
@@ -3815,7 +3861,9 @@ static struct ieee80211_ops iwl3945_hw_ops = {
3815 .conf_tx = iwl_mac_conf_tx, 3861 .conf_tx = iwl_mac_conf_tx,
3816 .reset_tsf = iwl_mac_reset_tsf, 3862 .reset_tsf = iwl_mac_reset_tsf,
3817 .bss_info_changed = iwl_bss_info_changed, 3863 .bss_info_changed = iwl_bss_info_changed,
3818 .hw_scan = iwl_mac_hw_scan 3864 .hw_scan = iwl_mac_hw_scan,
3865 .sta_add = iwl3945_mac_sta_add,
3866 .sta_remove = iwl_mac_sta_remove,
3819}; 3867};
3820 3868
3821static int iwl3945_init_drv(struct iwl_priv *priv) 3869static int iwl3945_init_drv(struct iwl_priv *priv)
@@ -3834,9 +3882,6 @@ static int iwl3945_init_drv(struct iwl_priv *priv)
3834 mutex_init(&priv->mutex); 3882 mutex_init(&priv->mutex);
3835 mutex_init(&priv->sync_cmd_mutex); 3883 mutex_init(&priv->sync_cmd_mutex);
3836 3884
3837 /* Clear the driver's (not device's) station table */
3838 iwl_clear_stations_table(priv);
3839
3840 priv->ieee_channels = NULL; 3885 priv->ieee_channels = NULL;
3841 priv->ieee_rates = NULL; 3886 priv->ieee_rates = NULL;
3842 priv->band = IEEE80211_BAND_2GHZ; 3887 priv->band = IEEE80211_BAND_2GHZ;
@@ -4196,7 +4241,6 @@ static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
4196 iwl3945_hw_txq_ctx_free(priv); 4241 iwl3945_hw_txq_ctx_free(priv);
4197 4242
4198 iwl3945_unset_hw_params(priv); 4243 iwl3945_unset_hw_params(priv);
4199 iwl_clear_stations_table(priv);
4200 4244
4201 /*netif_stop_queue(dev); */ 4245 /*netif_stop_queue(dev); */
4202 flush_workqueue(priv->workqueue); 4246 flush_workqueue(priv->workqueue);