1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 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 *****************************************************************************/
30 #include <net/mac80211.h>
35 #include "iwl-trans.h"
37 /* priv->shrd->sta_lock must be held */
38 static void iwl_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
41 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
42 IWL_ERR(priv
, "ACTIVATE a non DRIVER active station id %u "
44 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
46 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
48 "STA id %u addr %pM already present in uCode "
49 "(according to driver)\n",
50 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
52 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_ACTIVE
;
53 IWL_DEBUG_ASSOC(priv
, "Added STA id %u addr %pM to uCode\n",
54 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
58 static int iwl_process_add_sta_resp(struct iwl_priv
*priv
,
59 struct iwl_addsta_cmd
*addsta
,
60 struct iwl_rx_packet
*pkt
)
62 u8 sta_id
= addsta
->sta
.sta_id
;
66 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
67 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
72 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
75 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
77 switch (pkt
->u
.add_sta
.status
) {
78 case ADD_STA_SUCCESS_MSK
:
79 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
80 iwl_sta_ucode_activate(priv
, sta_id
);
83 case ADD_STA_NO_ROOM_IN_TABLE
:
84 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
87 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
88 IWL_ERR(priv
, "Adding station %d failed, no block ack "
89 "resource.\n", sta_id
);
91 case ADD_STA_MODIFY_NON_EXIST_STA
:
92 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
96 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
97 pkt
->u
.add_sta
.status
);
101 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
102 priv
->stations
[sta_id
].sta
.mode
==
103 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
104 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
107 * XXX: The MAC address in the command buffer is often changed from
108 * the original sent to the device. That is, the MAC address
109 * written to the command buffer often is not the same MAC address
110 * read from the command buffer when the command returns. This
111 * issue has not yet been resolved and this debugging is left to
112 * observe the problem.
114 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
115 priv
->stations
[sta_id
].sta
.mode
==
116 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
118 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
123 int iwl_add_sta_callback(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
,
124 struct iwl_device_cmd
*cmd
)
126 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
127 struct iwl_addsta_cmd
*addsta
=
128 (struct iwl_addsta_cmd
*) cmd
->payload
;
130 return iwl_process_add_sta_resp(priv
, addsta
, pkt
);
133 static u16
iwlagn_build_addsta_hcmd(const struct iwl_addsta_cmd
*cmd
, u8
*data
)
135 u16 size
= (u16
)sizeof(struct iwl_addsta_cmd
);
136 struct iwl_addsta_cmd
*addsta
= (struct iwl_addsta_cmd
*)data
;
137 memcpy(addsta
, cmd
, size
);
138 /* resrved in 5000 */
139 addsta
->rate_n_flags
= cpu_to_le16(0);
143 int iwl_send_add_sta(struct iwl_priv
*priv
,
144 struct iwl_addsta_cmd
*sta
, u8 flags
)
147 u8 data
[sizeof(*sta
)];
148 struct iwl_host_cmd cmd
= {
153 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
155 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
156 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
158 if (!(flags
& CMD_ASYNC
)) {
159 cmd
.flags
|= CMD_WANT_SKB
;
163 cmd
.len
[0] = iwlagn_build_addsta_hcmd(sta
, data
);
164 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
166 if (ret
|| (flags
& CMD_ASYNC
))
168 /*else the command was successfully sent in SYNC mode, need to free
171 iwl_free_pages(priv
->shrd
, cmd
.reply_page
);
173 if (cmd
.handler_status
)
174 IWL_ERR(priv
, "%s - error in the CMD response %d", __func__
,
177 return cmd
.handler_status
;
180 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
181 struct ieee80211_sta
*sta
,
182 struct iwl_rxon_context
*ctx
)
184 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
188 if (!sta
|| !sta_ht_inf
->ht_supported
)
191 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
192 IWL_DEBUG_ASSOC(priv
, "spatial multiplexing power save mode: %s\n",
193 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
195 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
196 "dynamic" : "disabled");
198 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
200 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
202 switch (mimo_ps_mode
) {
203 case WLAN_HT_CAP_SM_PS_STATIC
:
204 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
206 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
207 sta_flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
209 case WLAN_HT_CAP_SM_PS_DISABLED
:
212 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", mimo_ps_mode
);
216 sta_flags
|= cpu_to_le32(
217 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
219 sta_flags
|= cpu_to_le32(
220 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
222 if (iwl_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
223 sta_flags
|= STA_FLG_HT40_EN_MSK
;
225 sta_flags
&= ~STA_FLG_HT40_EN_MSK
;
227 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
233 * iwl_prep_station - Prepare station information for addition
235 * should be called with sta_lock held
237 u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
238 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
240 struct iwl_station_entry
*station
;
242 u8 sta_id
= IWL_INVALID_STATION
;
245 sta_id
= ctx
->ap_sta_id
;
246 else if (is_broadcast_ether_addr(addr
))
247 sta_id
= ctx
->bcast_sta_id
;
249 for (i
= IWL_STA_ID
; i
< IWLAGN_STATION_COUNT
; i
++) {
250 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
256 if (!priv
->stations
[i
].used
&&
257 sta_id
== IWL_INVALID_STATION
)
262 * These two conditions have the same outcome, but keep them
265 if (unlikely(sta_id
== IWL_INVALID_STATION
))
269 * uCode is not able to deal with multiple requests to add a
270 * station. Keep track if one is in progress so that we do not send
273 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
274 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
279 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
280 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
281 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
282 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
283 "adding again.\n", sta_id
, addr
);
287 station
= &priv
->stations
[sta_id
];
288 station
->used
= IWL_STA_DRIVER_ACTIVE
;
289 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
291 priv
->num_stations
++;
293 /* Set up the REPLY_ADD_STA command to send to device */
294 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
295 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
296 station
->sta
.mode
= 0;
297 station
->sta
.sta
.sta_id
= sta_id
;
298 station
->sta
.station_flags
= ctx
->station_flags
;
299 station
->ctxid
= ctx
->ctxid
;
302 struct iwl_station_priv
*sta_priv
;
304 sta_priv
= (void *)sta
->drv_priv
;
309 * OK to call unconditionally, since local stations (IBSS BSSID
310 * STA and broadcast STA) pass in a NULL sta, and mac80211
311 * doesn't allow HT IBSS.
313 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
319 #define STA_WAIT_TIMEOUT (HZ/2)
322 * iwl_add_station_common -
324 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
325 const u8
*addr
, bool is_ap
,
326 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
328 unsigned long flags_spin
;
331 struct iwl_addsta_cmd sta_cmd
;
334 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
335 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
336 if (sta_id
== IWL_INVALID_STATION
) {
337 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
339 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
344 * uCode is not able to deal with multiple requests to add a
345 * station. Keep track if one is in progress so that we do not send
348 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
349 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
351 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
355 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
356 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
357 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
358 "adding again.\n", sta_id
, addr
);
359 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
363 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
364 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
365 sizeof(struct iwl_addsta_cmd
));
366 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
368 /* Add station to device's station table */
369 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
371 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
372 IWL_ERR(priv
, "Adding station %pM failed.\n",
373 priv
->stations
[sta_id
].sta
.sta
.addr
);
374 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
375 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
376 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
383 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
385 * priv->shrd->sta_lock must be held
387 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
389 /* Ucode must be active and driver must be non active */
390 if ((priv
->stations
[sta_id
].used
&
391 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
392 IWL_STA_UCODE_ACTIVE
)
393 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
395 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
397 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
398 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
401 static int iwl_send_remove_station(struct iwl_priv
*priv
,
402 const u8
*addr
, int sta_id
,
405 struct iwl_rx_packet
*pkt
;
408 unsigned long flags_spin
;
409 struct iwl_rem_sta_cmd rm_sta_cmd
;
411 struct iwl_host_cmd cmd
= {
412 .id
= REPLY_REMOVE_STA
,
413 .len
= { sizeof(struct iwl_rem_sta_cmd
), },
415 .data
= { &rm_sta_cmd
, },
418 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
419 rm_sta_cmd
.num_sta
= 1;
420 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
422 cmd
.flags
|= CMD_WANT_SKB
;
424 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
429 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
430 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
431 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
437 switch (pkt
->u
.rem_sta
.status
) {
438 case REM_STA_SUCCESS_MSK
:
440 spin_lock_irqsave(&priv
->shrd
->sta_lock
,
442 iwl_sta_ucode_deactivate(priv
, sta_id
);
443 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
446 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
450 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
454 iwl_free_pages(priv
->shrd
, cmd
.reply_page
);
460 * iwl_remove_station - Remove driver's knowledge of station.
462 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
467 if (!iwl_is_ready(priv
->shrd
)) {
469 "Unable to remove station %pM, device not ready.\n",
472 * It is typical for stations to be removed when we are
473 * going down. Return success since device will be down
479 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
482 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
485 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
487 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
488 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
493 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
494 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
499 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
500 kfree(priv
->stations
[sta_id
].lq
);
501 priv
->stations
[sta_id
].lq
= NULL
;
504 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
506 priv
->num_stations
--;
508 if (WARN_ON(priv
->num_stations
< 0))
509 priv
->num_stations
= 0;
511 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
513 return iwl_send_remove_station(priv
, addr
, sta_id
, false);
515 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
520 * iwl_clear_ucode_stations - clear ucode station table bits
522 * This function clears all the bits in the driver indicating
523 * which stations are active in the ucode. Call when something
524 * other than explicit station management would cause this in
525 * the ucode, e.g. unassociated RXON.
527 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
528 struct iwl_rxon_context
*ctx
)
531 unsigned long flags_spin
;
532 bool cleared
= false;
534 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
536 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
537 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
538 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
541 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
543 "Clearing ucode active for station %d\n", i
);
544 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
548 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
552 "No active stations found to be cleared\n");
556 * iwl_restore_stations() - Restore driver known stations to device
558 * All stations considered active by driver, but not present in ucode, is
563 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
565 struct iwl_addsta_cmd sta_cmd
;
566 struct iwl_link_quality_cmd lq
;
567 unsigned long flags_spin
;
573 if (!iwl_is_ready(priv
->shrd
)) {
575 "Not ready yet, not restoring any stations.\n");
579 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
580 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
581 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
582 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
584 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
585 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
586 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
587 priv
->stations
[i
].sta
.sta
.addr
);
588 priv
->stations
[i
].sta
.mode
= 0;
589 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
594 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
595 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
596 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
597 sizeof(struct iwl_addsta_cmd
));
599 if (priv
->stations
[i
].lq
) {
600 if (priv
->shrd
->wowlan
)
601 iwl_sta_fill_lq(priv
, ctx
, i
, &lq
);
603 memcpy(&lq
, priv
->stations
[i
].lq
,
604 sizeof(struct iwl_link_quality_cmd
));
607 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
609 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
611 spin_lock_irqsave(&priv
->shrd
->sta_lock
,
613 IWL_ERR(priv
, "Adding station %pM failed.\n",
614 priv
->stations
[i
].sta
.sta
.addr
);
615 priv
->stations
[i
].used
&=
616 ~IWL_STA_DRIVER_ACTIVE
;
617 priv
->stations
[i
].used
&=
618 ~IWL_STA_UCODE_INPROGRESS
;
619 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
623 * Rate scaling has already been initialized, send
627 iwl_send_lq_cmd(priv
, ctx
, &lq
,
629 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
630 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
634 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
636 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
637 "no stations to be restored.\n");
639 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
643 void iwl_reprogram_ap_sta(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
646 int sta_id
= ctx
->ap_sta_id
;
648 struct iwl_addsta_cmd sta_cmd
;
649 struct iwl_link_quality_cmd lq
;
650 bool active
, have_lq
= false;
652 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
653 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
654 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
658 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
660 if (priv
->stations
[sta_id
].lq
) {
661 memcpy(&lq
, priv
->stations
[sta_id
].lq
, sizeof(lq
));
665 active
= priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
;
666 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
667 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
670 ret
= iwl_send_remove_station(
671 priv
, priv
->stations
[sta_id
].sta
.sta
.addr
,
674 IWL_ERR(priv
, "failed to remove STA %pM (%d)\n",
675 priv
->stations
[sta_id
].sta
.sta
.addr
, ret
);
677 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
678 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
679 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
681 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
683 IWL_ERR(priv
, "failed to re-add STA %pM (%d)\n",
684 priv
->stations
[sta_id
].sta
.sta
.addr
, ret
);
686 iwl_send_lq_cmd(priv
, ctx
, &lq
, CMD_SYNC
, true);
689 int iwl_get_free_ucode_key_offset(struct iwl_priv
*priv
)
693 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
694 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
697 return WEP_INVALID_OFFSET
;
700 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
705 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
706 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
707 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
710 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
711 priv
->num_stations
--;
712 if (WARN_ON(priv
->num_stations
< 0))
713 priv
->num_stations
= 0;
714 kfree(priv
->stations
[i
].lq
);
715 priv
->stations
[i
].lq
= NULL
;
717 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
720 #ifdef CONFIG_IWLWIFI_DEBUG
721 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
722 struct iwl_link_quality_cmd
*lq
)
725 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
726 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
727 lq
->general_params
.single_stream_ant_msk
,
728 lq
->general_params
.dual_stream_ant_msk
);
730 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
731 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
732 i
, lq
->rs_table
[i
].rate_n_flags
);
735 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
736 struct iwl_link_quality_cmd
*lq
)
742 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
744 * It sometimes happens when a HT rate has been in use and we
745 * loose connectivity with AP then mac80211 will first tell us that the
746 * current channel is not HT anymore before removing the station. In such a
747 * scenario the RXON flags will be updated to indicate we are not
748 * communicating HT anymore, but the LQ command may still contain HT rates.
749 * Test for this to prevent driver from sending LQ command between the time
750 * RXON flags are updated and when LQ command is updated.
752 static bool is_lq_table_valid(struct iwl_priv
*priv
,
753 struct iwl_rxon_context
*ctx
,
754 struct iwl_link_quality_cmd
*lq
)
761 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
762 ctx
->active
.channel
);
763 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
764 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
767 "index %d of LQ expects HT channel\n",
776 * iwl_send_lq_cmd() - Send link quality command
777 * @init: This command is sent as part of station initialization right
778 * after station has been added.
780 * The link quality command is sent as the last step of station creation.
781 * This is the special case in which init is set and we call a callback in
782 * this case to clear the state indicating that station creation is in
785 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
786 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
789 unsigned long flags_spin
;
791 struct iwl_host_cmd cmd
= {
792 .id
= REPLY_TX_LINK_QUALITY_CMD
,
793 .len
= { sizeof(struct iwl_link_quality_cmd
), },
798 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
802 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
803 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
804 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
807 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
809 iwl_dump_lq_cmd(priv
, lq
);
810 if (WARN_ON(init
&& (cmd
.flags
& CMD_ASYNC
)))
813 if (is_lq_table_valid(priv
, ctx
, lq
))
814 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
818 if (cmd
.flags
& CMD_ASYNC
)
822 IWL_DEBUG_INFO(priv
, "init LQ command complete, "
823 "clearing sta addition status for sta %d\n",
825 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
826 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
827 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
833 void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
834 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
840 lockdep_assert_held(&priv
->shrd
->mutex
);
842 memset(link_cmd
, 0, sizeof(*link_cmd
));
844 /* Set up the rate scaling to start at selected rate, fall back
845 * all the way down to 1M in IEEE order, and then spin on 1M */
846 if (priv
->band
== IEEE80211_BAND_5GHZ
)
847 r
= IWL_RATE_6M_INDEX
;
848 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
849 r
= IWL_RATE_6M_INDEX
;
851 r
= IWL_RATE_1M_INDEX
;
853 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
854 rate_flags
|= RATE_MCS_CCK_MSK
;
856 rate_flags
|= first_antenna(hw_params(priv
).valid_tx_ant
) <<
858 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
859 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
860 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
862 link_cmd
->general_params
.single_stream_ant_msk
=
863 first_antenna(hw_params(priv
).valid_tx_ant
);
865 link_cmd
->general_params
.dual_stream_ant_msk
=
866 hw_params(priv
).valid_tx_ant
&
867 ~first_antenna(hw_params(priv
).valid_tx_ant
);
868 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
869 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
870 } else if (num_of_ant(hw_params(priv
).valid_tx_ant
) == 2) {
871 link_cmd
->general_params
.dual_stream_ant_msk
=
872 hw_params(priv
).valid_tx_ant
;
875 link_cmd
->agg_params
.agg_dis_start_th
=
876 LINK_QUAL_AGG_DISABLE_START_DEF
;
877 link_cmd
->agg_params
.agg_time_limit
=
878 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
880 link_cmd
->sta_id
= sta_id
;
883 static struct iwl_link_quality_cmd
*
884 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
887 struct iwl_link_quality_cmd
*link_cmd
;
889 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
891 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
895 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
901 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
905 int iwlagn_add_bssid_station(struct iwl_priv
*priv
,
906 struct iwl_rxon_context
*ctx
,
907 const u8
*addr
, u8
*sta_id_r
)
911 struct iwl_link_quality_cmd
*link_cmd
;
915 *sta_id_r
= IWL_INVALID_STATION
;
917 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
919 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
926 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
927 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
928 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
930 /* Set up default rate scaling table in device's station table */
931 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
934 "Unable to initialize rate scaling for station %pM.\n",
939 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
941 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
943 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
944 priv
->stations
[sta_id
].lq
= link_cmd
;
945 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
953 * For each context, the device has a table of 4 static WEP keys
954 * (one for each key index) that is updated with the following
958 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
959 struct iwl_rxon_context
*ctx
,
962 int i
, not_empty
= 0;
963 u8 buff
[sizeof(struct iwl_wep_cmd
) +
964 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
965 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
966 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
967 struct iwl_host_cmd cmd
= {
968 .id
= ctx
->wep_key_cmd
,
969 .data
= { wep_cmd
, },
975 memset(wep_cmd
, 0, cmd_size
+
976 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
978 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
979 wep_cmd
->key
[i
].key_index
= i
;
980 if (ctx
->wep_keys
[i
].key_size
) {
981 wep_cmd
->key
[i
].key_offset
= i
;
984 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
987 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
988 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
989 ctx
->wep_keys
[i
].key_size
);
992 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
993 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
995 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
997 cmd
.len
[0] = cmd_size
;
999 if (not_empty
|| send_if_empty
)
1000 return iwl_trans_send_cmd(trans(priv
), &cmd
);
1005 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
1006 struct iwl_rxon_context
*ctx
)
1008 lockdep_assert_held(&priv
->shrd
->mutex
);
1010 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1013 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
1014 struct iwl_rxon_context
*ctx
,
1015 struct ieee80211_key_conf
*keyconf
)
1019 lockdep_assert_held(&priv
->shrd
->mutex
);
1021 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
1024 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
1025 if (iwl_is_rfkill(priv
->shrd
)) {
1027 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
1028 /* but keys in device are clear anyway so return success */
1031 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
1032 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
1033 keyconf
->keyidx
, ret
);
1038 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
1039 struct iwl_rxon_context
*ctx
,
1040 struct ieee80211_key_conf
*keyconf
)
1044 lockdep_assert_held(&priv
->shrd
->mutex
);
1046 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
1047 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
1049 "Bad WEP key length %d\n", keyconf
->keylen
);
1053 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
1055 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
1056 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
1059 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1060 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
1061 keyconf
->keylen
, keyconf
->keyidx
, ret
);
1067 * dynamic (per-station) keys
1069 * The dynamic keys are a little more complicated. The device has
1070 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
1071 * These are linked to stations by a table that contains an index
1072 * into the key table for each station/key index/{mcast,unicast},
1073 * i.e. it's basically an array of pointers like this:
1074 * key_offset_t key_mapping[NUM_STATIONS][4][2];
1075 * (it really works differently, but you can think of it as such)
1077 * The key uploading and linking happens in the same command, the
1078 * add station command with STA_MODIFY_KEY_MASK.
1081 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
1082 struct ieee80211_vif
*vif
,
1083 struct ieee80211_sta
*sta
)
1085 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1086 u8 sta_id
= IWL_INVALID_STATION
;
1089 sta_id
= iwl_sta_id(sta
);
1092 * The device expects GTKs for station interfaces to be
1093 * installed as GTKs for the AP station. If we have no
1094 * station ID, then use the ap_sta_id in that case.
1096 if (!sta
&& vif
&& vif_priv
->ctx
) {
1097 switch (vif
->type
) {
1098 case NL80211_IFTYPE_STATION
:
1099 sta_id
= vif_priv
->ctx
->ap_sta_id
;
1103 * In all other cases, the key will be
1104 * used either for TX only or is bound
1105 * to a station already.
1114 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
1115 struct ieee80211_key_conf
*keyconf
,
1116 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1119 unsigned long flags
;
1121 struct iwl_addsta_cmd sta_cmd
;
1124 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1125 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1126 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1128 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1129 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
1131 switch (keyconf
->cipher
) {
1132 case WLAN_CIPHER_SUITE_CCMP
:
1133 key_flags
|= STA_KEY_FLG_CCMP
;
1134 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1136 case WLAN_CIPHER_SUITE_TKIP
:
1137 key_flags
|= STA_KEY_FLG_TKIP
;
1138 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
1139 for (i
= 0; i
< 5; i
++)
1140 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1141 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1143 case WLAN_CIPHER_SUITE_WEP104
:
1144 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
1146 case WLAN_CIPHER_SUITE_WEP40
:
1147 key_flags
|= STA_KEY_FLG_WEP
;
1148 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
1155 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1156 key_flags
|= STA_KEY_MULTICAST_MSK
;
1158 /* key pointer (offset) */
1159 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1161 sta_cmd
.key
.key_flags
= key_flags
;
1162 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1163 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1165 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
1168 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1169 struct ieee80211_vif
*vif
,
1170 struct ieee80211_key_conf
*keyconf
,
1171 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1173 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
1175 if (sta_id
== IWL_INVALID_STATION
)
1178 if (iwl_scan_cancel(priv
)) {
1179 /* cancel scan failed, just live w/ bad key and rely
1180 briefly on SW decryption */
1184 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1185 iv32
, phase1key
, CMD_ASYNC
);
1188 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1189 struct iwl_rxon_context
*ctx
,
1190 struct ieee80211_key_conf
*keyconf
,
1191 struct ieee80211_sta
*sta
)
1193 unsigned long flags
;
1194 struct iwl_addsta_cmd sta_cmd
;
1195 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1197 /* if station isn't there, neither is the key */
1198 if (sta_id
== IWL_INVALID_STATION
)
1201 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1202 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1203 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
1204 sta_id
= IWL_INVALID_STATION
;
1205 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1207 if (sta_id
== IWL_INVALID_STATION
)
1210 lockdep_assert_held(&priv
->shrd
->mutex
);
1212 ctx
->key_mapping_keys
--;
1214 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1215 keyconf
->keyidx
, sta_id
);
1217 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
1218 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
1219 keyconf
->hw_key_idx
);
1221 sta_cmd
.key
.key_flags
= STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_INVALID
;
1222 sta_cmd
.key
.key_offset
= WEP_INVALID_OFFSET
;
1223 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1224 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1226 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1229 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
1230 struct iwl_rxon_context
*ctx
,
1231 struct ieee80211_key_conf
*keyconf
,
1232 struct ieee80211_sta
*sta
)
1234 struct ieee80211_key_seq seq
;
1237 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1240 if (sta_id
== IWL_INVALID_STATION
)
1243 lockdep_assert_held(&priv
->shrd
->mutex
);
1245 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
1246 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
1249 ctx
->key_mapping_keys
++;
1251 switch (keyconf
->cipher
) {
1252 case WLAN_CIPHER_SUITE_TKIP
:
1255 else /* station mode case only */
1256 addr
= ctx
->active
.bssid_addr
;
1258 /* pre-fill phase 1 key into device cache */
1259 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1260 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1261 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1262 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1264 case WLAN_CIPHER_SUITE_CCMP
:
1265 case WLAN_CIPHER_SUITE_WEP40
:
1266 case WLAN_CIPHER_SUITE_WEP104
:
1267 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1271 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
1276 ctx
->key_mapping_keys
--;
1277 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
1280 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1281 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1282 sta
? sta
->addr
: NULL
, ret
);
1288 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
1290 * This adds the broadcast station into the driver's station table
1291 * and marks it driver active, so that it will be restored to the
1292 * device at the next best time.
1294 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
1295 struct iwl_rxon_context
*ctx
)
1297 struct iwl_link_quality_cmd
*link_cmd
;
1298 unsigned long flags
;
1301 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1302 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1303 if (sta_id
== IWL_INVALID_STATION
) {
1304 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1305 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1310 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1311 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1312 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1314 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1317 "Unable to initialize rate scaling for bcast station.\n");
1321 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1322 priv
->stations
[sta_id
].lq
= link_cmd
;
1323 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1329 * iwl_update_bcast_station - update broadcast station's LQ command
1331 * Only used by iwlagn. Placed here to have all bcast station management
1334 int iwl_update_bcast_station(struct iwl_priv
*priv
,
1335 struct iwl_rxon_context
*ctx
)
1337 unsigned long flags
;
1338 struct iwl_link_quality_cmd
*link_cmd
;
1339 u8 sta_id
= ctx
->bcast_sta_id
;
1341 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1343 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1347 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1348 if (priv
->stations
[sta_id
].lq
)
1349 kfree(priv
->stations
[sta_id
].lq
);
1351 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1352 priv
->stations
[sta_id
].lq
= link_cmd
;
1353 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1358 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1360 struct iwl_rxon_context
*ctx
;
1363 for_each_context(priv
, ctx
) {
1364 ret
= iwl_update_bcast_station(priv
, ctx
);
1373 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1375 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1377 unsigned long flags
;
1378 struct iwl_addsta_cmd sta_cmd
;
1380 lockdep_assert_held(&priv
->shrd
->mutex
);
1382 /* Remove "disable" flag, to enable Tx for this TID */
1383 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
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_irqrestore(&priv
->shrd
->sta_lock
, flags
);
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
,
1396 unsigned long flags
;
1398 struct iwl_addsta_cmd sta_cmd
;
1400 lockdep_assert_held(&priv
->shrd
->mutex
);
1402 sta_id
= iwl_sta_id(sta
);
1403 if (sta_id
== IWL_INVALID_STATION
)
1406 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1407 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1408 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1409 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1410 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1411 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1412 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1413 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1415 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1418 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1421 unsigned long flags
;
1423 struct iwl_addsta_cmd sta_cmd
;
1425 lockdep_assert_held(&priv
->shrd
->mutex
);
1427 sta_id
= iwl_sta_id(sta
);
1428 if (sta_id
== IWL_INVALID_STATION
) {
1429 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1433 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1434 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1435 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1436 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1437 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1438 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1439 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1441 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1446 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1448 unsigned long flags
;
1450 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1451 priv
->stations
[sta_id
].sta
.station_flags
|= STA_FLG_PWR_SAVE_MSK
;
1452 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
1453 priv
->stations
[sta_id
].sta
.sta
.modify_mask
=
1454 STA_MODIFY_SLEEP_TX_COUNT_MSK
;
1455 priv
->stations
[sta_id
].sta
.sleep_tx_count
= cpu_to_le16(cnt
);
1456 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1457 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1458 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);