1 /******************************************************************************
3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
29 #include <linux/etherdevice.h>
30 #include <net/mac80211.h>
35 #include "iwl-trans.h"
37 static int iwl_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
39 lockdep_assert_held(&priv
->sta_lock
);
41 if (sta_id
>= IWLAGN_STATION_COUNT
) {
42 IWL_ERR(priv
, "invalid sta_id %u", sta_id
);
45 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
46 IWL_ERR(priv
, "ACTIVATE a non DRIVER active station id %u "
48 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
50 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
52 "STA id %u addr %pM already present in uCode "
53 "(according to driver)\n",
54 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
56 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_ACTIVE
;
57 IWL_DEBUG_ASSOC(priv
, "Added STA id %u addr %pM to uCode\n",
58 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
63 static int iwl_process_add_sta_resp(struct iwl_priv
*priv
,
64 struct iwl_addsta_cmd
*addsta
,
65 struct iwl_rx_packet
*pkt
)
67 struct iwl_add_sta_resp
*add_sta_resp
= (void *)pkt
->data
;
68 u8 sta_id
= addsta
->sta
.sta_id
;
71 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
72 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
77 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
80 spin_lock(&priv
->sta_lock
);
82 switch (add_sta_resp
->status
) {
83 case ADD_STA_SUCCESS_MSK
:
84 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
85 ret
= iwl_sta_ucode_activate(priv
, sta_id
);
87 case ADD_STA_NO_ROOM_IN_TABLE
:
88 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
91 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
92 IWL_ERR(priv
, "Adding station %d failed, no block ack "
93 "resource.\n", sta_id
);
95 case ADD_STA_MODIFY_NON_EXIST_STA
:
96 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
100 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
101 add_sta_resp
->status
);
105 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
106 priv
->stations
[sta_id
].sta
.mode
==
107 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
108 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
111 * XXX: The MAC address in the command buffer is often changed from
112 * the original sent to the device. That is, the MAC address
113 * written to the command buffer often is not the same MAC address
114 * read from the command buffer when the command returns. This
115 * issue has not yet been resolved and this debugging is left to
116 * observe the problem.
118 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
119 priv
->stations
[sta_id
].sta
.mode
==
120 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
122 spin_unlock(&priv
->sta_lock
);
127 int iwl_add_sta_callback(struct iwl_priv
*priv
, struct iwl_rx_cmd_buffer
*rxb
,
128 struct iwl_device_cmd
*cmd
)
130 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
131 struct iwl_addsta_cmd
*addsta
=
132 (struct iwl_addsta_cmd
*) cmd
->payload
;
134 return iwl_process_add_sta_resp(priv
, addsta
, pkt
);
137 int iwl_send_add_sta(struct iwl_priv
*priv
,
138 struct iwl_addsta_cmd
*sta
, u8 flags
)
141 struct iwl_host_cmd cmd
= {
145 .len
= { sizeof(*sta
), },
147 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
149 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
150 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
152 if (!(flags
& CMD_ASYNC
)) {
153 cmd
.flags
|= CMD_WANT_SKB
;
157 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
159 if (ret
|| (flags
& CMD_ASYNC
))
161 /*else the command was successfully sent in SYNC mode, need to free
166 if (cmd
.handler_status
)
167 IWL_ERR(priv
, "%s - error in the CMD response %d", __func__
,
170 return cmd
.handler_status
;
173 static void iwl_sta_calc_ht_flags(struct iwl_priv
*priv
,
174 struct ieee80211_sta
*sta
,
175 struct iwl_rxon_context
*ctx
,
176 __le32
*flags
, __le32
*mask
)
178 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
181 *mask
= STA_FLG_RTS_MIMO_PROT_MSK
|
182 STA_FLG_MIMO_DIS_MSK
|
183 STA_FLG_HT40_EN_MSK
|
184 STA_FLG_MAX_AGG_SIZE_MSK
|
185 STA_FLG_AGG_MPDU_DENSITY_MSK
;
188 if (!sta
|| !sta_ht_inf
->ht_supported
)
191 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
193 IWL_DEBUG_INFO(priv
, "STA %pM SM PS mode: %s\n",
194 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
196 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
197 "dynamic" : "disabled");
199 switch (mimo_ps_mode
) {
200 case WLAN_HT_CAP_SM_PS_STATIC
:
201 *flags
|= STA_FLG_MIMO_DIS_MSK
;
203 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
204 *flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
206 case WLAN_HT_CAP_SM_PS_DISABLED
:
209 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", mimo_ps_mode
);
213 *flags
|= cpu_to_le32(
214 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
216 *flags
|= cpu_to_le32(
217 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
219 if (iwl_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
220 *flags
|= STA_FLG_HT40_EN_MSK
;
223 int iwl_sta_update_ht(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
224 struct ieee80211_sta
*sta
)
226 u8 sta_id
= iwl_sta_id(sta
);
228 struct iwl_addsta_cmd cmd
;
230 if (WARN_ON_ONCE(sta_id
== IWL_INVALID_STATION
))
233 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
235 spin_lock_bh(&priv
->sta_lock
);
236 priv
->stations
[sta_id
].sta
.station_flags
&= ~mask
;
237 priv
->stations
[sta_id
].sta
.station_flags
|= flags
;
238 spin_unlock_bh(&priv
->sta_lock
);
240 memset(&cmd
, 0, sizeof(cmd
));
241 cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
242 cmd
.station_flags_msk
= mask
;
243 cmd
.station_flags
= flags
;
244 cmd
.sta
.sta_id
= sta_id
;
246 return iwl_send_add_sta(priv
, &cmd
, CMD_SYNC
);
249 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
250 struct ieee80211_sta
*sta
,
251 struct iwl_rxon_context
*ctx
)
255 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
257 lockdep_assert_held(&priv
->sta_lock
);
258 priv
->stations
[index
].sta
.station_flags
&= ~mask
;
259 priv
->stations
[index
].sta
.station_flags
|= flags
;
263 * iwl_prep_station - Prepare station information for addition
265 * should be called with sta_lock held
267 u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
268 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
270 struct iwl_station_entry
*station
;
272 u8 sta_id
= IWL_INVALID_STATION
;
275 sta_id
= ctx
->ap_sta_id
;
276 else if (is_broadcast_ether_addr(addr
))
277 sta_id
= ctx
->bcast_sta_id
;
279 for (i
= IWL_STA_ID
; i
< IWLAGN_STATION_COUNT
; i
++) {
280 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
286 if (!priv
->stations
[i
].used
&&
287 sta_id
== IWL_INVALID_STATION
)
292 * These two conditions have the same outcome, but keep them
295 if (unlikely(sta_id
== IWL_INVALID_STATION
))
299 * uCode is not able to deal with multiple requests to add a
300 * station. Keep track if one is in progress so that we do not send
303 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
304 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
309 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
310 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
311 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
312 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
313 "adding again.\n", sta_id
, addr
);
317 station
= &priv
->stations
[sta_id
];
318 station
->used
= IWL_STA_DRIVER_ACTIVE
;
319 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
321 priv
->num_stations
++;
323 /* Set up the REPLY_ADD_STA command to send to device */
324 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
325 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
326 station
->sta
.mode
= 0;
327 station
->sta
.sta
.sta_id
= sta_id
;
328 station
->sta
.station_flags
= ctx
->station_flags
;
329 station
->ctxid
= ctx
->ctxid
;
332 struct iwl_station_priv
*sta_priv
;
334 sta_priv
= (void *)sta
->drv_priv
;
339 * OK to call unconditionally, since local stations (IBSS BSSID
340 * STA and broadcast STA) pass in a NULL sta, and mac80211
341 * doesn't allow HT IBSS.
343 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
349 #define STA_WAIT_TIMEOUT (HZ/2)
352 * iwl_add_station_common -
354 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
355 const u8
*addr
, bool is_ap
,
356 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
360 struct iwl_addsta_cmd sta_cmd
;
363 spin_lock_bh(&priv
->sta_lock
);
364 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
365 if (sta_id
== IWL_INVALID_STATION
) {
366 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
368 spin_unlock_bh(&priv
->sta_lock
);
373 * uCode is not able to deal with multiple requests to add a
374 * station. Keep track if one is in progress so that we do not send
377 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
378 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
380 spin_unlock_bh(&priv
->sta_lock
);
384 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
385 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
386 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
387 "adding again.\n", sta_id
, addr
);
388 spin_unlock_bh(&priv
->sta_lock
);
392 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
393 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
394 sizeof(struct iwl_addsta_cmd
));
395 spin_unlock_bh(&priv
->sta_lock
);
397 /* Add station to device's station table */
398 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
400 spin_lock_bh(&priv
->sta_lock
);
401 IWL_ERR(priv
, "Adding station %pM failed.\n",
402 priv
->stations
[sta_id
].sta
.sta
.addr
);
403 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
404 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
405 spin_unlock_bh(&priv
->sta_lock
);
412 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
414 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
416 lockdep_assert_held(&priv
->sta_lock
);
418 /* Ucode must be active and driver must be non active */
419 if ((priv
->stations
[sta_id
].used
&
420 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
421 IWL_STA_UCODE_ACTIVE
)
422 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
424 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
426 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
427 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
430 static int iwl_send_remove_station(struct iwl_priv
*priv
,
431 const u8
*addr
, int sta_id
,
434 struct iwl_rx_packet
*pkt
;
436 struct iwl_rem_sta_cmd rm_sta_cmd
;
438 struct iwl_host_cmd cmd
= {
439 .id
= REPLY_REMOVE_STA
,
440 .len
= { sizeof(struct iwl_rem_sta_cmd
), },
442 .data
= { &rm_sta_cmd
, },
445 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
446 rm_sta_cmd
.num_sta
= 1;
447 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
449 cmd
.flags
|= CMD_WANT_SKB
;
451 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
457 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
458 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
464 struct iwl_rem_sta_resp
*rem_sta_resp
= (void *)pkt
->data
;
465 switch (rem_sta_resp
->status
) {
466 case REM_STA_SUCCESS_MSK
:
468 spin_lock_bh(&priv
->sta_lock
);
469 iwl_sta_ucode_deactivate(priv
, sta_id
);
470 spin_unlock_bh(&priv
->sta_lock
);
472 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
476 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
486 * iwl_remove_station - Remove driver's knowledge of station.
488 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
493 if (!iwl_is_ready(priv
)) {
495 "Unable to remove station %pM, device not ready.\n",
498 * It is typical for stations to be removed when we are
499 * going down. Return success since device will be down
505 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
508 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
511 spin_lock_bh(&priv
->sta_lock
);
513 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
514 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
519 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
520 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
525 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
526 kfree(priv
->stations
[sta_id
].lq
);
527 priv
->stations
[sta_id
].lq
= NULL
;
530 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
531 memset(&priv
->tid_data
[sta_id
][tid
], 0,
532 sizeof(priv
->tid_data
[sta_id
][tid
]));
534 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
536 priv
->num_stations
--;
538 if (WARN_ON(priv
->num_stations
< 0))
539 priv
->num_stations
= 0;
541 spin_unlock_bh(&priv
->sta_lock
);
543 return iwl_send_remove_station(priv
, addr
, sta_id
, false);
545 spin_unlock_bh(&priv
->sta_lock
);
549 void iwl_deactivate_station(struct iwl_priv
*priv
, const u8 sta_id
,
554 if (!iwl_is_ready(priv
)) {
556 "Unable to remove station %pM, device not ready.\n",
561 IWL_DEBUG_ASSOC(priv
, "Deactivating STA: %pM (%d)\n", addr
, sta_id
);
563 if (WARN_ON_ONCE(sta_id
== IWL_INVALID_STATION
))
566 spin_lock_bh(&priv
->sta_lock
);
568 WARN_ON_ONCE(!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
));
570 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
571 memset(&priv
->tid_data
[sta_id
][tid
], 0,
572 sizeof(priv
->tid_data
[sta_id
][tid
]));
574 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
576 priv
->num_stations
--;
578 if (WARN_ON_ONCE(priv
->num_stations
< 0))
579 priv
->num_stations
= 0;
581 spin_unlock_bh(&priv
->sta_lock
);
585 * iwl_clear_ucode_stations - clear ucode station table bits
587 * This function clears all the bits in the driver indicating
588 * which stations are active in the ucode. Call when something
589 * other than explicit station management would cause this in
590 * the ucode, e.g. unassociated RXON.
592 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
593 struct iwl_rxon_context
*ctx
)
596 bool cleared
= false;
598 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
600 spin_lock_bh(&priv
->sta_lock
);
601 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
602 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
605 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
607 "Clearing ucode active for station %d\n", i
);
608 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
612 spin_unlock_bh(&priv
->sta_lock
);
616 "No active stations found to be cleared\n");
620 * iwl_restore_stations() - Restore driver known stations to device
622 * All stations considered active by driver, but not present in ucode, is
627 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
629 struct iwl_addsta_cmd sta_cmd
;
630 struct iwl_link_quality_cmd lq
;
636 if (!iwl_is_ready(priv
)) {
638 "Not ready yet, not restoring any stations.\n");
642 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
643 spin_lock_bh(&priv
->sta_lock
);
644 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
645 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
647 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
648 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
649 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
650 priv
->stations
[i
].sta
.sta
.addr
);
651 priv
->stations
[i
].sta
.mode
= 0;
652 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
657 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
658 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
659 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
660 sizeof(struct iwl_addsta_cmd
));
662 if (priv
->stations
[i
].lq
) {
664 iwl_sta_fill_lq(priv
, ctx
, i
, &lq
);
666 memcpy(&lq
, priv
->stations
[i
].lq
,
667 sizeof(struct iwl_link_quality_cmd
));
670 spin_unlock_bh(&priv
->sta_lock
);
671 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
673 spin_lock_bh(&priv
->sta_lock
);
674 IWL_ERR(priv
, "Adding station %pM failed.\n",
675 priv
->stations
[i
].sta
.sta
.addr
);
676 priv
->stations
[i
].used
&=
677 ~IWL_STA_DRIVER_ACTIVE
;
678 priv
->stations
[i
].used
&=
679 ~IWL_STA_UCODE_INPROGRESS
;
680 spin_unlock_bh(&priv
->sta_lock
);
683 * Rate scaling has already been initialized, send
687 iwl_send_lq_cmd(priv
, ctx
, &lq
,
689 spin_lock_bh(&priv
->sta_lock
);
690 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
694 spin_unlock_bh(&priv
->sta_lock
);
696 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
697 "no stations to be restored.\n");
699 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
703 int iwl_get_free_ucode_key_offset(struct iwl_priv
*priv
)
707 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
708 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
711 return WEP_INVALID_OFFSET
;
714 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
718 spin_lock_bh(&priv
->sta_lock
);
719 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
720 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
723 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
724 priv
->num_stations
--;
725 if (WARN_ON(priv
->num_stations
< 0))
726 priv
->num_stations
= 0;
727 kfree(priv
->stations
[i
].lq
);
728 priv
->stations
[i
].lq
= NULL
;
730 spin_unlock_bh(&priv
->sta_lock
);
733 #ifdef CONFIG_IWLWIFI_DEBUG
734 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
735 struct iwl_link_quality_cmd
*lq
)
738 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
739 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
740 lq
->general_params
.single_stream_ant_msk
,
741 lq
->general_params
.dual_stream_ant_msk
);
743 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
744 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
745 i
, lq
->rs_table
[i
].rate_n_flags
);
748 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
749 struct iwl_link_quality_cmd
*lq
)
755 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
757 * It sometimes happens when a HT rate has been in use and we
758 * loose connectivity with AP then mac80211 will first tell us that the
759 * current channel is not HT anymore before removing the station. In such a
760 * scenario the RXON flags will be updated to indicate we are not
761 * communicating HT anymore, but the LQ command may still contain HT rates.
762 * Test for this to prevent driver from sending LQ command between the time
763 * RXON flags are updated and when LQ command is updated.
765 static bool is_lq_table_valid(struct iwl_priv
*priv
,
766 struct iwl_rxon_context
*ctx
,
767 struct iwl_link_quality_cmd
*lq
)
774 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
775 ctx
->active
.channel
);
776 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
777 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
780 "index %d of LQ expects HT channel\n",
789 * iwl_send_lq_cmd() - Send link quality command
790 * @init: This command is sent as part of station initialization right
791 * after station has been added.
793 * The link quality command is sent as the last step of station creation.
794 * This is the special case in which init is set and we call a callback in
795 * this case to clear the state indicating that station creation is in
798 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
799 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
802 struct iwl_host_cmd cmd
= {
803 .id
= REPLY_TX_LINK_QUALITY_CMD
,
804 .len
= { sizeof(struct iwl_link_quality_cmd
), },
809 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
813 spin_lock_bh(&priv
->sta_lock
);
814 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
815 spin_unlock_bh(&priv
->sta_lock
);
818 spin_unlock_bh(&priv
->sta_lock
);
820 iwl_dump_lq_cmd(priv
, lq
);
821 if (WARN_ON(init
&& (cmd
.flags
& CMD_ASYNC
)))
824 if (is_lq_table_valid(priv
, ctx
, lq
))
825 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
829 if (cmd
.flags
& CMD_ASYNC
)
833 IWL_DEBUG_INFO(priv
, "init LQ command complete, "
834 "clearing sta addition status for sta %d\n",
836 spin_lock_bh(&priv
->sta_lock
);
837 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
838 spin_unlock_bh(&priv
->sta_lock
);
844 void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
845 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
851 lockdep_assert_held(&priv
->mutex
);
853 memset(link_cmd
, 0, sizeof(*link_cmd
));
855 /* Set up the rate scaling to start at selected rate, fall back
856 * all the way down to 1M in IEEE order, and then spin on 1M */
857 if (priv
->band
== IEEE80211_BAND_5GHZ
)
858 r
= IWL_RATE_6M_INDEX
;
859 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
860 r
= IWL_RATE_6M_INDEX
;
862 r
= IWL_RATE_1M_INDEX
;
864 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
865 rate_flags
|= RATE_MCS_CCK_MSK
;
867 rate_flags
|= first_antenna(hw_params(priv
).valid_tx_ant
) <<
869 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
870 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
871 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
873 link_cmd
->general_params
.single_stream_ant_msk
=
874 first_antenna(hw_params(priv
).valid_tx_ant
);
876 link_cmd
->general_params
.dual_stream_ant_msk
=
877 hw_params(priv
).valid_tx_ant
&
878 ~first_antenna(hw_params(priv
).valid_tx_ant
);
879 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
880 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
881 } else if (num_of_ant(hw_params(priv
).valid_tx_ant
) == 2) {
882 link_cmd
->general_params
.dual_stream_ant_msk
=
883 hw_params(priv
).valid_tx_ant
;
886 link_cmd
->agg_params
.agg_dis_start_th
=
887 LINK_QUAL_AGG_DISABLE_START_DEF
;
888 link_cmd
->agg_params
.agg_time_limit
=
889 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
891 link_cmd
->sta_id
= sta_id
;
894 static struct iwl_link_quality_cmd
*
895 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
898 struct iwl_link_quality_cmd
*link_cmd
;
900 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
902 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
906 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
912 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
916 int iwlagn_add_bssid_station(struct iwl_priv
*priv
,
917 struct iwl_rxon_context
*ctx
,
918 const u8
*addr
, u8
*sta_id_r
)
922 struct iwl_link_quality_cmd
*link_cmd
;
925 *sta_id_r
= IWL_INVALID_STATION
;
927 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
929 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
936 spin_lock_bh(&priv
->sta_lock
);
937 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
938 spin_unlock_bh(&priv
->sta_lock
);
940 /* Set up default rate scaling table in device's station table */
941 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
944 "Unable to initialize rate scaling for station %pM.\n",
949 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
951 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
953 spin_lock_bh(&priv
->sta_lock
);
954 priv
->stations
[sta_id
].lq
= link_cmd
;
955 spin_unlock_bh(&priv
->sta_lock
);
963 * For each context, the device has a table of 4 static WEP keys
964 * (one for each key index) that is updated with the following
968 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
969 struct iwl_rxon_context
*ctx
,
972 int i
, not_empty
= 0;
973 u8 buff
[sizeof(struct iwl_wep_cmd
) +
974 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
975 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
976 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
977 struct iwl_host_cmd cmd
= {
978 .id
= ctx
->wep_key_cmd
,
979 .data
= { wep_cmd
, },
985 memset(wep_cmd
, 0, cmd_size
+
986 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
988 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
989 wep_cmd
->key
[i
].key_index
= i
;
990 if (ctx
->wep_keys
[i
].key_size
) {
991 wep_cmd
->key
[i
].key_offset
= i
;
994 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
997 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
998 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
999 ctx
->wep_keys
[i
].key_size
);
1002 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
1003 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
1005 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
1007 cmd
.len
[0] = cmd_size
;
1009 if (not_empty
|| send_if_empty
)
1010 return iwl_dvm_send_cmd(priv
, &cmd
);
1015 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
1016 struct iwl_rxon_context
*ctx
)
1018 lockdep_assert_held(&priv
->mutex
);
1020 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1023 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
1024 struct iwl_rxon_context
*ctx
,
1025 struct ieee80211_key_conf
*keyconf
)
1029 lockdep_assert_held(&priv
->mutex
);
1031 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
1034 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
1035 if (iwl_is_rfkill(priv
)) {
1037 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
1038 /* but keys in device are clear anyway so return success */
1041 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
1042 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
1043 keyconf
->keyidx
, ret
);
1048 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
1049 struct iwl_rxon_context
*ctx
,
1050 struct ieee80211_key_conf
*keyconf
)
1054 lockdep_assert_held(&priv
->mutex
);
1056 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
1057 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
1059 "Bad WEP key length %d\n", keyconf
->keylen
);
1063 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
1065 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
1066 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
1069 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1070 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
1071 keyconf
->keylen
, keyconf
->keyidx
, ret
);
1077 * dynamic (per-station) keys
1079 * The dynamic keys are a little more complicated. The device has
1080 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
1081 * These are linked to stations by a table that contains an index
1082 * into the key table for each station/key index/{mcast,unicast},
1083 * i.e. it's basically an array of pointers like this:
1084 * key_offset_t key_mapping[NUM_STATIONS][4][2];
1085 * (it really works differently, but you can think of it as such)
1087 * The key uploading and linking happens in the same command, the
1088 * add station command with STA_MODIFY_KEY_MASK.
1091 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
1092 struct ieee80211_vif
*vif
,
1093 struct ieee80211_sta
*sta
)
1095 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1098 return iwl_sta_id(sta
);
1101 * The device expects GTKs for station interfaces to be
1102 * installed as GTKs for the AP station. If we have no
1103 * station ID, then use the ap_sta_id in that case.
1105 if (vif
->type
== NL80211_IFTYPE_STATION
&& vif_priv
->ctx
)
1106 return vif_priv
->ctx
->ap_sta_id
;
1108 return IWL_INVALID_STATION
;
1111 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
1112 struct ieee80211_key_conf
*keyconf
,
1113 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1117 struct iwl_addsta_cmd sta_cmd
;
1120 spin_lock_bh(&priv
->sta_lock
);
1121 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1122 spin_unlock_bh(&priv
->sta_lock
);
1124 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1125 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
1127 switch (keyconf
->cipher
) {
1128 case WLAN_CIPHER_SUITE_CCMP
:
1129 key_flags
|= STA_KEY_FLG_CCMP
;
1130 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1132 case WLAN_CIPHER_SUITE_TKIP
:
1133 key_flags
|= STA_KEY_FLG_TKIP
;
1134 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
1135 for (i
= 0; i
< 5; i
++)
1136 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1137 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1139 case WLAN_CIPHER_SUITE_WEP104
:
1140 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
1142 case WLAN_CIPHER_SUITE_WEP40
:
1143 key_flags
|= STA_KEY_FLG_WEP
;
1144 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
1151 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1152 key_flags
|= STA_KEY_MULTICAST_MSK
;
1154 /* key pointer (offset) */
1155 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1157 sta_cmd
.key
.key_flags
= key_flags
;
1158 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1159 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1161 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
1164 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1165 struct ieee80211_vif
*vif
,
1166 struct ieee80211_key_conf
*keyconf
,
1167 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1169 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
1171 if (sta_id
== IWL_INVALID_STATION
)
1174 if (iwl_scan_cancel(priv
)) {
1175 /* cancel scan failed, just live w/ bad key and rely
1176 briefly on SW decryption */
1180 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1181 iv32
, phase1key
, CMD_ASYNC
);
1184 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1185 struct iwl_rxon_context
*ctx
,
1186 struct ieee80211_key_conf
*keyconf
,
1187 struct ieee80211_sta
*sta
)
1189 struct iwl_addsta_cmd sta_cmd
;
1190 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1193 /* if station isn't there, neither is the key */
1194 if (sta_id
== IWL_INVALID_STATION
)
1197 spin_lock_bh(&priv
->sta_lock
);
1198 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1199 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
1200 sta_id
= IWL_INVALID_STATION
;
1201 spin_unlock_bh(&priv
->sta_lock
);
1203 if (sta_id
== IWL_INVALID_STATION
)
1206 lockdep_assert_held(&priv
->mutex
);
1208 ctx
->key_mapping_keys
--;
1210 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1211 keyconf
->keyidx
, sta_id
);
1213 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
1214 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
1215 keyconf
->hw_key_idx
);
1217 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1218 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
| STA_KEY_FLG_NO_ENC
|
1219 STA_KEY_FLG_INVALID
;
1221 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1222 key_flags
|= STA_KEY_MULTICAST_MSK
;
1224 sta_cmd
.key
.key_flags
= key_flags
;
1225 sta_cmd
.key
.key_offset
= WEP_INVALID_OFFSET
;
1226 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1227 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1229 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1232 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
1233 struct iwl_rxon_context
*ctx
,
1234 struct ieee80211_key_conf
*keyconf
,
1235 struct ieee80211_sta
*sta
)
1237 struct ieee80211_key_seq seq
;
1240 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1243 if (sta_id
== IWL_INVALID_STATION
)
1246 lockdep_assert_held(&priv
->mutex
);
1248 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
1249 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
1252 ctx
->key_mapping_keys
++;
1254 switch (keyconf
->cipher
) {
1255 case WLAN_CIPHER_SUITE_TKIP
:
1258 else /* station mode case only */
1259 addr
= ctx
->active
.bssid_addr
;
1261 /* pre-fill phase 1 key into device cache */
1262 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1263 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1264 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1265 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1267 case WLAN_CIPHER_SUITE_CCMP
:
1268 case WLAN_CIPHER_SUITE_WEP40
:
1269 case WLAN_CIPHER_SUITE_WEP104
:
1270 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1274 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
1279 ctx
->key_mapping_keys
--;
1280 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
1283 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1284 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1285 sta
? sta
->addr
: NULL
, ret
);
1291 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
1293 * This adds the broadcast station into the driver's station table
1294 * and marks it driver active, so that it will be restored to the
1295 * device at the next best time.
1297 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
1298 struct iwl_rxon_context
*ctx
)
1300 struct iwl_link_quality_cmd
*link_cmd
;
1303 spin_lock_bh(&priv
->sta_lock
);
1304 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1305 if (sta_id
== IWL_INVALID_STATION
) {
1306 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1307 spin_unlock_bh(&priv
->sta_lock
);
1312 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1313 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1314 spin_unlock_bh(&priv
->sta_lock
);
1316 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1319 "Unable to initialize rate scaling for bcast station.\n");
1323 spin_lock_bh(&priv
->sta_lock
);
1324 priv
->stations
[sta_id
].lq
= link_cmd
;
1325 spin_unlock_bh(&priv
->sta_lock
);
1331 * iwl_update_bcast_station - update broadcast station's LQ command
1333 * Only used by iwlagn. Placed here to have all bcast station management
1336 int iwl_update_bcast_station(struct iwl_priv
*priv
,
1337 struct iwl_rxon_context
*ctx
)
1339 struct iwl_link_quality_cmd
*link_cmd
;
1340 u8 sta_id
= ctx
->bcast_sta_id
;
1342 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1344 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1348 spin_lock_bh(&priv
->sta_lock
);
1349 if (priv
->stations
[sta_id
].lq
)
1350 kfree(priv
->stations
[sta_id
].lq
);
1352 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1353 priv
->stations
[sta_id
].lq
= link_cmd
;
1354 spin_unlock_bh(&priv
->sta_lock
);
1359 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1361 struct iwl_rxon_context
*ctx
;
1364 for_each_context(priv
, ctx
) {
1365 ret
= iwl_update_bcast_station(priv
, ctx
);
1374 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1376 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1378 struct iwl_addsta_cmd sta_cmd
;
1380 lockdep_assert_held(&priv
->mutex
);
1382 /* Remove "disable" flag, to enable Tx for this TID */
1383 spin_lock_bh(&priv
->sta_lock
);
1384 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1385 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
1386 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1387 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1388 spin_unlock_bh(&priv
->sta_lock
);
1390 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1393 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1397 struct iwl_addsta_cmd sta_cmd
;
1399 lockdep_assert_held(&priv
->mutex
);
1401 sta_id
= iwl_sta_id(sta
);
1402 if (sta_id
== IWL_INVALID_STATION
)
1405 spin_lock_bh(&priv
->sta_lock
);
1406 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1407 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1408 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1409 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1410 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1411 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1412 spin_unlock_bh(&priv
->sta_lock
);
1414 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1417 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1421 struct iwl_addsta_cmd sta_cmd
;
1423 lockdep_assert_held(&priv
->mutex
);
1425 sta_id
= iwl_sta_id(sta
);
1426 if (sta_id
== IWL_INVALID_STATION
) {
1427 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1431 spin_lock_bh(&priv
->sta_lock
);
1432 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1433 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1434 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1435 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1436 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1437 spin_unlock_bh(&priv
->sta_lock
);
1439 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1444 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1446 struct iwl_addsta_cmd cmd
= {
1447 .mode
= STA_CONTROL_MODIFY_MSK
,
1448 .station_flags
= STA_FLG_PWR_SAVE_MSK
,
1449 .station_flags_msk
= STA_FLG_PWR_SAVE_MSK
,
1450 .sta
.sta_id
= sta_id
,
1451 .sta
.modify_mask
= STA_MODIFY_SLEEP_TX_COUNT_MSK
,
1452 .sleep_tx_count
= cpu_to_le16(cnt
),
1455 iwl_send_add_sta(priv
, &cmd
, CMD_ASYNC
);