aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-sta.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-sta.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c691
1 files changed, 408 insertions, 283 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 4a6686fa6b36..db934476b5e9 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}
@@ -132,7 +143,7 @@ static void iwl_process_add_sta_resp(struct iwl_priv *priv,
132 sta_id); 143 sta_id);
133 break; 144 break;
134 case ADD_STA_MODIFY_NON_EXIST_STA: 145 case ADD_STA_MODIFY_NON_EXIST_STA:
135 IWL_ERR(priv, "Attempting to modify non-existing station %d \n", 146 IWL_ERR(priv, "Attempting to modify non-existing station %d\n",
136 sta_id); 147 sta_id);
137 break; 148 break;
138 default: 149 default:
@@ -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 __maybe_unused = 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,198 @@ 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;
428 int ret = 0;
346 429
347 BUG_ON(sta_id == IWL_INVALID_STATION); 430 /* Set up the rate scaling to start at selected rate, fall back
431 * all the way down to 1M in IEEE order, and then spin on 1M */
432 if (is_ap)
433 r = IWL_RATE_54M_INDEX;
434 else if (priv->band == IEEE80211_BAND_5GHZ)
435 r = IWL_RATE_6M_INDEX;
436 else
437 r = IWL_RATE_1M_INDEX;
348 438
349 IWL_DEBUG_ASSOC(priv, "Removed STA from Ucode: %pM\n", addr); 439 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
440 rate_flags = 0;
441 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
442 rate_flags |= RATE_MCS_CCK_MSK;
350 443
351 spin_lock_irqsave(&priv->sta_lock, flags); 444 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
445 RATE_MCS_ANT_POS;
352 446
353 /* Ucode must be active and driver must be non active */ 447 link_cmd.rs_table[i].rate_n_flags =
354 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE) 448 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
355 IWL_ERR(priv, "removed non active STA %d\n", sta_id); 449 r = iwl_get_prev_ieee_rate(r);
450 }
356 451
357 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; 452 link_cmd.general_params.single_stream_ant_msk =
453 first_antenna(priv->hw_params.valid_tx_ant);
358 454
359 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); 455 link_cmd.general_params.dual_stream_ant_msk =
360 spin_unlock_irqrestore(&priv->sta_lock, flags); 456 priv->hw_params.valid_tx_ant &
457 ~first_antenna(priv->hw_params.valid_tx_ant);
458 if (!link_cmd.general_params.dual_stream_ant_msk) {
459 link_cmd.general_params.dual_stream_ant_msk = ANT_AB;
460 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
461 link_cmd.general_params.dual_stream_ant_msk =
462 priv->hw_params.valid_tx_ant;
463 }
464
465 link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
466 link_cmd.agg_params.agg_time_limit =
467 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
468
469 /* Update the rate scaling for control frame Tx to AP */
470 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
471
472 ret = iwl_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD,
473 sizeof(link_cmd), &link_cmd);
474 if (ret)
475 IWL_ERR(priv, "REPLY_TX_LINK_QUALITY_CMD failed (%d)\n", ret);
361} 476}
362 477
363static void iwl_remove_sta_callback(struct iwl_priv *priv, 478/*
364 struct iwl_device_cmd *cmd, 479 * iwl_add_local_stations - Add stations not requested by mac80211
365 struct iwl_rx_packet *pkt) 480 *
481 * This will be either the broadcast station or the bssid station needed by
482 * ad-hoc.
483 *
484 * Function sleeps.
485 */
486int iwl_add_local_station(struct iwl_priv *priv, const u8 *addr, bool init_rs)
366{ 487{
367 struct iwl_rem_sta_cmd *rm_sta = 488 int ret;
368 (struct iwl_rem_sta_cmd *)cmd->cmd.payload; 489 u8 sta_id;
369 const u8 *addr = rm_sta->addr;
370 490
371 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { 491 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id);
372 IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", 492 if (ret) {
373 pkt->hdr.flags); 493 IWL_ERR(priv, "Unable to add station %pM\n", addr);
374 return; 494 return ret;
375 } 495 }
376 496
377 switch (pkt->u.rem_sta.status) { 497 if (init_rs)
378 case REM_STA_SUCCESS_MSK: 498 /* Set up default rate scaling table in device's station table */
379 iwl_sta_ucode_deactivate(priv, addr); 499 iwl_sta_init_lq(priv, addr, false);
380 break; 500 return 0;
381 default: 501}
382 IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); 502EXPORT_SYMBOL(iwl_add_local_station);
383 break; 503
384 } 504/**
505 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
506 *
507 * priv->sta_lock must be held
508 */
509static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id)
510{
511 /* Ucode must be active and driver must be non active */
512 if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
513 IWL_ERR(priv, "removed non active STA %u\n", sta_id);
514
515 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
516
517 memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
518 IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id);
385} 519}
386 520
387static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr, 521static int iwl_send_remove_station(struct iwl_priv *priv,
388 u8 flags) 522 struct iwl_station_entry *station)
389{ 523{
390 struct iwl_rx_packet *pkt; 524 struct iwl_rx_packet *pkt;
391 int ret; 525 int ret;
392 526
527 unsigned long flags_spin;
393 struct iwl_rem_sta_cmd rm_sta_cmd; 528 struct iwl_rem_sta_cmd rm_sta_cmd;
394 529
395 struct iwl_host_cmd cmd = { 530 struct iwl_host_cmd cmd = {
396 .id = REPLY_REMOVE_STA, 531 .id = REPLY_REMOVE_STA,
397 .len = sizeof(struct iwl_rem_sta_cmd), 532 .len = sizeof(struct iwl_rem_sta_cmd),
398 .flags = flags, 533 .flags = CMD_SYNC,
399 .data = &rm_sta_cmd, 534 .data = &rm_sta_cmd,
400 }; 535 };
401 536
402 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); 537 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
403 rm_sta_cmd.num_sta = 1; 538 rm_sta_cmd.num_sta = 1;
404 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN); 539 memcpy(&rm_sta_cmd.addr, &station->sta.sta.addr , ETH_ALEN);
540
541 cmd.flags |= CMD_WANT_SKB;
405 542
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); 543 ret = iwl_send_cmd(priv, &cmd);
411 544
412 if (ret || (flags & CMD_ASYNC)) 545 if (ret)
413 return ret; 546 return ret;
414 547
415 pkt = (struct iwl_rx_packet *)cmd.reply_page; 548 pkt = (struct iwl_rx_packet *)cmd.reply_page;
@@ -422,7 +555,9 @@ static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
422 if (!ret) { 555 if (!ret) {
423 switch (pkt->u.rem_sta.status) { 556 switch (pkt->u.rem_sta.status) {
424 case REM_STA_SUCCESS_MSK: 557 case REM_STA_SUCCESS_MSK:
425 iwl_sta_ucode_deactivate(priv, addr); 558 spin_lock_irqsave(&priv->sta_lock, flags_spin);
559 iwl_sta_ucode_deactivate(priv, station->sta.sta.sta_id);
560 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
426 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); 561 IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
427 break; 562 break;
428 default: 563 default:
@@ -439,23 +574,35 @@ static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
439/** 574/**
440 * iwl_remove_station - Remove driver's knowledge of station. 575 * iwl_remove_station - Remove driver's knowledge of station.
441 */ 576 */
442int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap) 577static int iwl_remove_station(struct iwl_priv *priv, struct ieee80211_sta *sta)
443{ 578{
444 int sta_id = IWL_INVALID_STATION; 579 int sta_id = IWL_INVALID_STATION;
445 int i, ret = -EINVAL; 580 int i, ret = -EINVAL;
446 unsigned long flags; 581 unsigned long flags;
582 bool is_ap = priv->iw_mode == NL80211_IFTYPE_STATION;
583 struct iwl_station_entry *station;
584
585 if (!iwl_is_ready(priv)) {
586 IWL_DEBUG_INFO(priv,
587 "Unable to remove station %pM, device not ready.\n",
588 sta->addr);
589 /*
590 * It is typical for stations to be removed when we are
591 * going down. Return success since device will be down
592 * soon anyway
593 */
594 return 0;
595 }
447 596
448 spin_lock_irqsave(&priv->sta_lock, flags); 597 spin_lock_irqsave(&priv->sta_lock, flags);
449 598
450 if (is_ap) 599 if (is_ap)
451 sta_id = IWL_AP_ID; 600 sta_id = IWL_AP_ID;
452 else if (is_broadcast_ether_addr(addr))
453 sta_id = priv->hw_params.bcast_sta_id;
454 else 601 else
455 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) 602 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
456 if (priv->stations[i].used && 603 if (priv->stations[i].used &&
457 !compare_ether_addr(priv->stations[i].sta.sta.addr, 604 !compare_ether_addr(priv->stations[i].sta.sta.addr,
458 addr)) { 605 sta->addr)) {
459 sta_id = i; 606 sta_id = i;
460 break; 607 break;
461 } 608 }
@@ -464,17 +611,17 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
464 goto out; 611 goto out;
465 612
466 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", 613 IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
467 sta_id, addr); 614 sta_id, sta->addr);
468 615
469 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { 616 if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
470 IWL_ERR(priv, "Removing %pM but non DRIVER active\n", 617 IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n",
471 addr); 618 sta->addr);
472 goto out; 619 goto out;
473 } 620 }
474 621
475 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { 622 if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
476 IWL_ERR(priv, "Removing %pM but non UCODE active\n", 623 IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n",
477 addr); 624 sta->addr);
478 goto out; 625 goto out;
479 } 626 }
480 627
@@ -485,9 +632,10 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
485 632
486 BUG_ON(priv->num_stations < 0); 633 BUG_ON(priv->num_stations < 0);
487 634
635 station = &priv->stations[sta_id];
488 spin_unlock_irqrestore(&priv->sta_lock, flags); 636 spin_unlock_irqrestore(&priv->sta_lock, flags);
489 637
490 ret = iwl_send_remove_station(priv, addr, CMD_ASYNC); 638 ret = iwl_send_remove_station(priv, station);
491 return ret; 639 return ret;
492out: 640out:
493 spin_unlock_irqrestore(&priv->sta_lock, flags); 641 spin_unlock_irqrestore(&priv->sta_lock, flags);
@@ -495,37 +643,122 @@ out:
495} 643}
496 644
497/** 645/**
498 * iwl_clear_stations_table - Clear the driver's station table 646 * iwl_clear_ucode_stations() - clear entire station table driver and/or ucode
499 * 647 * @priv:
500 * NOTE: This does not clear or otherwise alter the device's station table. 648 * @force: If set then the uCode station table needs to be cleared here. If
649 * not set then the uCode station table has already been cleared,
650 * for example after sending it a RXON command without ASSOC bit
651 * set, and we just need to change driver state here.
501 */ 652 */
502void iwl_clear_stations_table(struct iwl_priv *priv) 653void iwl_clear_ucode_stations(struct iwl_priv *priv, bool force)
503{ 654{
504 unsigned long flags;
505 int i; 655 int i;
656 unsigned long flags_spin;
657 bool cleared = false;
658
659 IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver%s\n",
660 force ? " and ucode" : "");
661
662 if (force) {
663 if (!iwl_is_ready(priv)) {
664 /*
665 * If device is not ready at this point the station
666 * table is likely already empty (uCode not ready
667 * to receive station requests) or will soon be
668 * due to interface going down.
669 */
670 IWL_DEBUG_INFO(priv, "Unable to remove stations from device - device not ready\n");
671 } else {
672 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL);
673 }
674 }
506 675
507 spin_lock_irqsave(&priv->sta_lock, flags); 676 spin_lock_irqsave(&priv->sta_lock, flags_spin);
677 if (force) {
678 IWL_DEBUG_INFO(priv, "Clearing all station information in driver\n");
679 priv->num_stations = 0;
680 memset(priv->stations, 0, sizeof(priv->stations));
681 } else {
682 for (i = 0; i < priv->hw_params.max_stations; i++) {
683 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
684 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
685 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
686 cleared = true;
687 }
688 }
689 }
690 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
691
692 if (!cleared)
693 IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n");
694}
695EXPORT_SYMBOL(iwl_clear_ucode_stations);
508 696
509 if (iwl_is_alive(priv) && 697/**
510 !test_bit(STATUS_EXIT_PENDING, &priv->status) && 698 * iwl_restore_stations() - Restore driver known stations to device
511 iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL)) 699 *
512 IWL_ERR(priv, "Couldn't clear the station table\n"); 700 * All stations considered active by driver, but not present in ucode, is
701 * restored.
702 *
703 * Function sleeps.
704 */
705void iwl_restore_stations(struct iwl_priv *priv)
706{
707 struct iwl_station_entry *station;
708 unsigned long flags_spin;
709 int i;
710 bool found = false;
711 int ret;
513 712
514 priv->num_stations = 0; 713 if (!iwl_is_ready(priv)) {
515 memset(priv->stations, 0, sizeof(priv->stations)); 714 IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n");
715 return;
716 }
516 717
517 /* clean ucode key table bit map */ 718 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
518 priv->ucode_key_table = 0; 719 spin_lock_irqsave(&priv->sta_lock, flags_spin);
720 for (i = 0; i < priv->hw_params.max_stations; i++) {
721 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
722 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
723 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
724 priv->stations[i].sta.sta.addr);
725 priv->stations[i].sta.mode = 0;
726 priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS;
727 found = true;
728 }
729 }
519 730
520 /* keep track of static keys */ 731 for (i = 0; i < priv->hw_params.max_stations; i++) {
521 for (i = 0; i < WEP_KEYS_MAX ; i++) { 732 if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) {
522 if (priv->wep_keys[i].key_size) 733 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
523 set_bit(i, &priv->ucode_key_table); 734 station = &priv->stations[i];
735 ret = iwl_send_add_sta(priv, &priv->stations[i].sta, CMD_SYNC);
736 if (ret) {
737 IWL_ERR(priv, "Adding station %pM failed.\n",
738 station->sta.sta.addr);
739 spin_lock_irqsave(&priv->sta_lock, flags_spin);
740 priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE;
741 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
742 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
743 }
744 /*
745 * Rate scaling has already been initialized, send
746 * current LQ command
747 */
748 if (station->lq)
749 iwl_send_lq_cmd(priv, station->lq, CMD_SYNC, true);
750 spin_lock_irqsave(&priv->sta_lock, flags_spin);
751 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
752 }
524 } 753 }
525 754
526 spin_unlock_irqrestore(&priv->sta_lock, flags); 755 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
756 if (!found)
757 IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n");
758 else
759 IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n");
527} 760}
528EXPORT_SYMBOL(iwl_clear_stations_table); 761EXPORT_SYMBOL(iwl_restore_stations);
529 762
530int iwl_get_free_ucode_key_index(struct iwl_priv *priv) 763int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
531{ 764{
@@ -539,7 +772,7 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
539} 772}
540EXPORT_SYMBOL(iwl_get_free_ucode_key_index); 773EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
541 774
542int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) 775static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
543{ 776{
544 int i, not_empty = 0; 777 int i, not_empty = 0;
545 u8 buff[sizeof(struct iwl_wep_cmd) + 778 u8 buff[sizeof(struct iwl_wep_cmd) +
@@ -549,9 +782,11 @@ int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
549 struct iwl_host_cmd cmd = { 782 struct iwl_host_cmd cmd = {
550 .id = REPLY_WEPKEY, 783 .id = REPLY_WEPKEY,
551 .data = wep_cmd, 784 .data = wep_cmd,
552 .flags = CMD_ASYNC, 785 .flags = CMD_SYNC,
553 }; 786 };
554 787
788 might_sleep();
789
555 memset(wep_cmd, 0, cmd_size + 790 memset(wep_cmd, 0, cmd_size +
556 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX)); 791 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
557 792
@@ -581,33 +816,34 @@ int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
581 else 816 else
582 return 0; 817 return 0;
583} 818}
584EXPORT_SYMBOL(iwl_send_static_wepkey_cmd); 819
820int iwl_restore_default_wep_keys(struct iwl_priv *priv)
821{
822 WARN_ON(!mutex_is_locked(&priv->mutex));
823
824 return iwl_send_static_wepkey_cmd(priv, 0);
825}
826EXPORT_SYMBOL(iwl_restore_default_wep_keys);
585 827
586int iwl_remove_default_wep_key(struct iwl_priv *priv, 828int iwl_remove_default_wep_key(struct iwl_priv *priv,
587 struct ieee80211_key_conf *keyconf) 829 struct ieee80211_key_conf *keyconf)
588{ 830{
589 int ret; 831 int ret;
590 unsigned long flags;
591 832
592 spin_lock_irqsave(&priv->sta_lock, flags); 833 WARN_ON(!mutex_is_locked(&priv->mutex));
834
593 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", 835 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
594 keyconf->keyidx); 836 keyconf->keyidx);
595 837
596 if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
597 IWL_ERR(priv, "index %d not used in uCode key table.\n",
598 keyconf->keyidx);
599
600 priv->default_wep_key--;
601 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); 838 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
602 if (iwl_is_rfkill(priv)) { 839 if (iwl_is_rfkill(priv)) {
603 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); 840 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
604 spin_unlock_irqrestore(&priv->sta_lock, flags); 841 /* but keys in device are clear anyway so return success */
605 return 0; 842 return 0;
606 } 843 }
607 ret = iwl_send_static_wepkey_cmd(priv, 1); 844 ret = iwl_send_static_wepkey_cmd(priv, 1);
608 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", 845 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
609 keyconf->keyidx, ret); 846 keyconf->keyidx, ret);
610 spin_unlock_irqrestore(&priv->sta_lock, flags);
611 847
612 return ret; 848 return ret;
613} 849}
@@ -617,7 +853,8 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
617 struct ieee80211_key_conf *keyconf) 853 struct ieee80211_key_conf *keyconf)
618{ 854{
619 int ret; 855 int ret;
620 unsigned long flags; 856
857 WARN_ON(!mutex_is_locked(&priv->mutex));
621 858
622 if (keyconf->keylen != WEP_KEY_LEN_128 && 859 if (keyconf->keylen != WEP_KEY_LEN_128 &&
623 keyconf->keylen != WEP_KEY_LEN_64) { 860 keyconf->keylen != WEP_KEY_LEN_64) {
@@ -629,13 +866,6 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
629 keyconf->hw_key_idx = HW_KEY_DEFAULT; 866 keyconf->hw_key_idx = HW_KEY_DEFAULT;
630 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; 867 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
631 868
632 spin_lock_irqsave(&priv->sta_lock, flags);
633 priv->default_wep_key++;
634
635 if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
636 IWL_ERR(priv, "index %d already used in uCode key table.\n",
637 keyconf->keyidx);
638
639 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; 869 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
640 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, 870 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
641 keyconf->keylen); 871 keyconf->keylen);
@@ -643,7 +873,6 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
643 ret = iwl_send_static_wepkey_cmd(priv, 0); 873 ret = iwl_send_static_wepkey_cmd(priv, 0);
644 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", 874 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
645 keyconf->keylen, keyconf->keyidx, ret); 875 keyconf->keylen, keyconf->keyidx, ret);
646 spin_unlock_irqrestore(&priv->sta_lock, flags);
647 876
648 return ret; 877 return ret;
649} 878}
@@ -885,7 +1114,7 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
885 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 1114 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
886 1115
887 if (iwl_is_rfkill(priv)) { 1116 if (iwl_is_rfkill(priv)) {
888 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled. \n"); 1117 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
889 spin_unlock_irqrestore(&priv->sta_lock, flags); 1118 spin_unlock_irqrestore(&priv->sta_lock, flags);
890 return 0; 1119 return 0;
891 } 1120 }
@@ -948,9 +1177,22 @@ static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
948} 1177}
949#endif 1178#endif
950 1179
1180/**
1181 * iwl_send_lq_cmd() - Send link quality command
1182 * @init: This command is sent as part of station initialization right
1183 * after station has been added.
1184 *
1185 * The link quality command is sent as the last step of station creation.
1186 * This is the special case in which init is set and we call a callback in
1187 * this case to clear the state indicating that station creation is in
1188 * progress.
1189 */
951int iwl_send_lq_cmd(struct iwl_priv *priv, 1190int iwl_send_lq_cmd(struct iwl_priv *priv,
952 struct iwl_link_quality_cmd *lq, u8 flags) 1191 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
953{ 1192{
1193 int ret = 0;
1194 unsigned long flags_spin;
1195
954 struct iwl_host_cmd cmd = { 1196 struct iwl_host_cmd cmd = {
955 .id = REPLY_TX_LINK_QUALITY_CMD, 1197 .id = REPLY_TX_LINK_QUALITY_CMD,
956 .len = sizeof(struct iwl_link_quality_cmd), 1198 .len = sizeof(struct iwl_link_quality_cmd),
@@ -958,175 +1200,34 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
958 .data = lq, 1200 .data = lq,
959 }; 1201 };
960 1202
961 if ((lq->sta_id == 0xFF) && 1203 if (WARN_ON(lq->sta_id == IWL_INVALID_STATION))
962 (priv->iw_mode == NL80211_IFTYPE_ADHOC))
963 return -EINVAL; 1204 return -EINVAL;
964 1205
965 if (lq->sta_id == 0xFF)
966 lq->sta_id = IWL_AP_ID;
967
968 iwl_dump_lq_cmd(priv, lq); 1206 iwl_dump_lq_cmd(priv, lq);
1207 BUG_ON(init && (cmd.flags & CMD_ASYNC));
969 1208
970 if (iwl_is_associated(priv) && priv->assoc_station_added) 1209 ret = iwl_send_cmd(priv, &cmd);
971 return iwl_send_cmd(priv, &cmd); 1210 if (ret || (cmd.flags & CMD_ASYNC))
1211 return ret;
972 1212
1213 if (init) {
1214 IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n",
1215 lq->sta_id);
1216 spin_lock_irqsave(&priv->sta_lock, flags_spin);
1217 priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1218 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
1219 }
973 return 0; 1220 return 0;
974} 1221}
975EXPORT_SYMBOL(iwl_send_lq_cmd); 1222EXPORT_SYMBOL(iwl_send_lq_cmd);
976 1223
977/** 1224/**
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. 1225 * iwl_add_bcast_station - add broadcast station into station table.
1122 */ 1226 */
1123void iwl_add_bcast_station(struct iwl_priv *priv) 1227void iwl_add_bcast_station(struct iwl_priv *priv)
1124{ 1228{
1125 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); 1229 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1126 iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL); 1230 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} 1231}
1131EXPORT_SYMBOL(iwl_add_bcast_station); 1232EXPORT_SYMBOL(iwl_add_bcast_station);
1132 1233
@@ -1136,7 +1237,14 @@ EXPORT_SYMBOL(iwl_add_bcast_station);
1136void iwl3945_add_bcast_station(struct iwl_priv *priv) 1237void iwl3945_add_bcast_station(struct iwl_priv *priv)
1137{ 1238{
1138 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n"); 1239 IWL_DEBUG_INFO(priv, "Adding broadcast station to station table\n");
1139 iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL); 1240 iwl_add_local_station(priv, iwl_bcast_addr, false);
1241 /*
1242 * It is assumed that when station is added more initialization
1243 * needs to be done, but for 3945 it is not the case and we can
1244 * just release station table access right here.
1245 */
1246 priv->stations[priv->hw_params.bcast_sta_id].used &= ~IWL_STA_UCODE_INPROGRESS;
1247
1140} 1248}
1141EXPORT_SYMBOL(iwl3945_add_bcast_station); 1249EXPORT_SYMBOL(iwl3945_add_bcast_station);
1142 1250
@@ -1159,6 +1267,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 1267 /* 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) */ 1268 * AP station entry (that's the only station we communicate with) */
1161 case NL80211_IFTYPE_STATION: 1269 case NL80211_IFTYPE_STATION:
1270 /*
1271 * If addition of station not complete yet, which means
1272 * that rate scaling has not been initialized, then return
1273 * the broadcast station.
1274 */
1275 if (!(priv->stations[IWL_AP_ID].used & IWL_STA_UCODE_ACTIVE))
1276 return priv->hw_params.bcast_sta_id;
1162 return IWL_AP_ID; 1277 return IWL_AP_ID;
1163 1278
1164 /* If we are an AP, then find the station, or use BCAST */ 1279 /* If we are an AP, then find the station, or use BCAST */
@@ -1175,13 +1290,6 @@ int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
1175 if (sta_id != IWL_INVALID_STATION) 1290 if (sta_id != IWL_INVALID_STATION)
1176 return sta_id; 1291 return sta_id;
1177 1292
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. " 1293 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
1186 "Defaulting to broadcast...\n", 1294 "Defaulting to broadcast...\n",
1187 hdr->addr1); 1295 hdr->addr1);
@@ -1291,3 +1399,20 @@ void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1291 1399
1292 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); 1400 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1293} 1401}
1402EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
1403
1404int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1405 struct ieee80211_vif *vif,
1406 struct ieee80211_sta *sta)
1407{
1408 int ret;
1409 struct iwl_priv *priv = hw->priv;
1410 IWL_DEBUG_INFO(priv, "received request to remove station %pM\n",
1411 sta->addr);
1412 ret = iwl_remove_station(priv, sta);
1413 if (ret)
1414 IWL_ERR(priv, "Error removing station %pM\n",
1415 sta->addr);
1416 return ret;
1417}
1418EXPORT_SYMBOL(iwl_mac_sta_remove);