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>
31 #include <linux/etherdevice.h>
32 #include <linux/sched.h>
33 #include <linux/lockdep.h>
39 /* priv->sta_lock must be held */
40 static void iwl_legacy_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
43 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
45 "ACTIVATE a non DRIVER active station id %u addr %pM\n",
46 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
48 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
50 "STA id %u addr %pM already present"
51 " in uCode (according to driver)\n",
52 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
54 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_ACTIVE
;
55 IWL_DEBUG_ASSOC(priv
, "Added STA id %u addr %pM to uCode\n",
56 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
60 static int iwl_legacy_process_add_sta_resp(struct iwl_priv
*priv
,
61 struct iwl_legacy_addsta_cmd
*addsta
,
62 struct iwl_rx_packet
*pkt
,
65 u8 sta_id
= addsta
->sta
.sta_id
;
69 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
70 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
75 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
78 spin_lock_irqsave(&priv
->sta_lock
, flags
);
80 switch (pkt
->u
.add_sta
.status
) {
81 case ADD_STA_SUCCESS_MSK
:
82 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
83 iwl_legacy_sta_ucode_activate(priv
, sta_id
);
86 case ADD_STA_NO_ROOM_IN_TABLE
:
87 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
90 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
92 "Adding station %d failed, no block ack resource.\n",
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 pkt
->u
.add_sta
.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_irqrestore(&priv
->sta_lock
, flags
);
127 static void iwl_legacy_add_sta_callback(struct iwl_priv
*priv
,
128 struct iwl_device_cmd
*cmd
,
129 struct iwl_rx_packet
*pkt
)
131 struct iwl_legacy_addsta_cmd
*addsta
=
132 (struct iwl_legacy_addsta_cmd
*)cmd
->cmd
.payload
;
134 iwl_legacy_process_add_sta_resp(priv
, addsta
, pkt
, false);
138 int iwl_legacy_send_add_sta(struct iwl_priv
*priv
,
139 struct iwl_legacy_addsta_cmd
*sta
, u8 flags
)
141 struct iwl_rx_packet
*pkt
= NULL
;
143 u8 data
[sizeof(*sta
)];
144 struct iwl_host_cmd cmd
= {
149 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
151 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
152 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
154 if (flags
& CMD_ASYNC
)
155 cmd
.callback
= iwl_legacy_add_sta_callback
;
157 cmd
.flags
|= CMD_WANT_SKB
;
161 cmd
.len
= priv
->cfg
->ops
->utils
->build_addsta_hcmd(sta
, data
);
162 ret
= iwl_legacy_send_cmd(priv
, &cmd
);
164 if (ret
|| (flags
& CMD_ASYNC
))
168 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
169 ret
= iwl_legacy_process_add_sta_resp(priv
, sta
, pkt
, true);
171 iwl_legacy_free_pages(priv
, cmd
.reply_page
);
175 EXPORT_SYMBOL(iwl_legacy_send_add_sta
);
177 static void iwl_legacy_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
178 struct ieee80211_sta
*sta
,
179 struct iwl_rxon_context
*ctx
)
181 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
185 if (!sta
|| !sta_ht_inf
->ht_supported
)
188 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
189 IWL_DEBUG_ASSOC(priv
, "spatial multiplexing power save mode: %s\n",
190 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
192 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
193 "dynamic" : "disabled");
195 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
197 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
199 switch (mimo_ps_mode
) {
200 case WLAN_HT_CAP_SM_PS_STATIC
:
201 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
203 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
204 sta_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 sta_flags
|= cpu_to_le32(
214 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
216 sta_flags
|= cpu_to_le32(
217 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
219 if (iwl_legacy_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
220 sta_flags
|= STA_FLG_HT40_EN_MSK
;
222 sta_flags
&= ~STA_FLG_HT40_EN_MSK
;
224 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
230 * iwl_legacy_prep_station - Prepare station information for addition
232 * should be called with sta_lock held
234 u8
iwl_legacy_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
235 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
237 struct iwl_station_entry
*station
;
239 u8 sta_id
= IWL_INVALID_STATION
;
243 sta_id
= ctx
->ap_sta_id
;
244 else if (is_broadcast_ether_addr(addr
))
245 sta_id
= ctx
->bcast_sta_id
;
247 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
248 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
254 if (!priv
->stations
[i
].used
&&
255 sta_id
== IWL_INVALID_STATION
)
260 * These two conditions have the same outcome, but keep them
263 if (unlikely(sta_id
== IWL_INVALID_STATION
))
267 * uCode is not able to deal with multiple requests to add a
268 * station. Keep track if one is in progress so that we do not send
271 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
273 "STA %d already in process of being added.\n",
278 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
279 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
280 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
281 IWL_DEBUG_ASSOC(priv
,
282 "STA %d (%pM) already added, not adding again.\n",
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_legacy_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_common
*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_legacy_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
316 rate
= (priv
->band
== IEEE80211_BAND_5GHZ
) ?
317 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
;
318 /* Turn on both antennas for the station... */
319 station
->sta
.rate_n_flags
= cpu_to_le16(rate
| RATE_MCS_ANT_AB_MSK
);
324 EXPORT_SYMBOL_GPL(iwl_legacy_prep_station
);
326 #define STA_WAIT_TIMEOUT (HZ/2)
329 * iwl_legacy_add_station_common -
332 iwl_legacy_add_station_common(struct iwl_priv
*priv
,
333 struct iwl_rxon_context
*ctx
,
334 const u8
*addr
, bool is_ap
,
335 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
337 unsigned long flags_spin
;
340 struct iwl_legacy_addsta_cmd sta_cmd
;
343 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
344 sta_id
= iwl_legacy_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
345 if (sta_id
== IWL_INVALID_STATION
) {
346 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
348 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
353 * uCode is not able to deal with multiple requests to add a
354 * station. Keep track if one is in progress so that we do not send
357 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
359 "STA %d already in process of being added.\n",
361 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
365 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
366 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
367 IWL_DEBUG_ASSOC(priv
,
368 "STA %d (%pM) already added, not adding again.\n",
370 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
374 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
375 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
376 sizeof(struct iwl_legacy_addsta_cmd
));
377 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
379 /* Add station to device's station table */
380 ret
= iwl_legacy_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
382 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
383 IWL_ERR(priv
, "Adding station %pM failed.\n",
384 priv
->stations
[sta_id
].sta
.sta
.addr
);
385 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
386 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
387 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
392 EXPORT_SYMBOL(iwl_legacy_add_station_common
);
395 * iwl_legacy_sta_ucode_deactivate - deactivate ucode status for a station
397 * priv->sta_lock must be held
399 static void iwl_legacy_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
401 /* Ucode must be active and driver must be non active */
402 if ((priv
->stations
[sta_id
].used
&
403 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
404 IWL_STA_UCODE_ACTIVE
)
405 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
407 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
409 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
410 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
413 static int iwl_legacy_send_remove_station(struct iwl_priv
*priv
,
414 const u8
*addr
, int sta_id
,
417 struct iwl_rx_packet
*pkt
;
420 unsigned long flags_spin
;
421 struct iwl_rem_sta_cmd rm_sta_cmd
;
423 struct iwl_host_cmd cmd
= {
424 .id
= REPLY_REMOVE_STA
,
425 .len
= sizeof(struct iwl_rem_sta_cmd
),
430 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
431 rm_sta_cmd
.num_sta
= 1;
432 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
434 cmd
.flags
|= CMD_WANT_SKB
;
436 ret
= iwl_legacy_send_cmd(priv
, &cmd
);
441 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
442 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
443 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
449 switch (pkt
->u
.rem_sta
.status
) {
450 case REM_STA_SUCCESS_MSK
:
452 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
453 iwl_legacy_sta_ucode_deactivate(priv
, sta_id
);
454 spin_unlock_irqrestore(&priv
->sta_lock
,
457 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
461 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
465 iwl_legacy_free_pages(priv
, cmd
.reply_page
);
471 * iwl_legacy_remove_station - Remove driver's knowledge of station.
473 int iwl_legacy_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
478 if (!iwl_legacy_is_ready(priv
)) {
480 "Unable to remove station %pM, device not ready.\n",
483 * It is typical for stations to be removed when we are
484 * going down. Return success since device will be down
490 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
493 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
496 spin_lock_irqsave(&priv
->sta_lock
, flags
);
498 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
499 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
504 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
505 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
510 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
511 kfree(priv
->stations
[sta_id
].lq
);
512 priv
->stations
[sta_id
].lq
= NULL
;
515 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
517 priv
->num_stations
--;
519 BUG_ON(priv
->num_stations
< 0);
521 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
523 return iwl_legacy_send_remove_station(priv
, addr
, sta_id
, false);
525 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
528 EXPORT_SYMBOL_GPL(iwl_legacy_remove_station
);
531 * iwl_legacy_clear_ucode_stations - clear ucode station table bits
533 * This function clears all the bits in the driver indicating
534 * which stations are active in the ucode. Call when something
535 * other than explicit station management would cause this in
536 * the ucode, e.g. unassociated RXON.
538 void iwl_legacy_clear_ucode_stations(struct iwl_priv
*priv
,
539 struct iwl_rxon_context
*ctx
)
542 unsigned long flags_spin
;
543 bool cleared
= false;
545 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
547 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
548 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
549 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
552 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
554 "Clearing ucode active for station %d\n", i
);
555 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
559 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
563 "No active stations found to be cleared\n");
565 EXPORT_SYMBOL(iwl_legacy_clear_ucode_stations
);
568 * iwl_legacy_restore_stations() - Restore driver known stations to device
570 * All stations considered active by driver, but not present in ucode, is
576 iwl_legacy_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
578 struct iwl_legacy_addsta_cmd sta_cmd
;
579 struct iwl_link_quality_cmd lq
;
580 unsigned long flags_spin
;
586 if (!iwl_legacy_is_ready(priv
)) {
588 "Not ready yet, not restoring any stations.\n");
592 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
593 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
594 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
595 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
597 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
598 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
599 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
600 priv
->stations
[i
].sta
.sta
.addr
);
601 priv
->stations
[i
].sta
.mode
= 0;
602 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
607 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
608 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
609 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
610 sizeof(struct iwl_legacy_addsta_cmd
));
612 if (priv
->stations
[i
].lq
) {
613 memcpy(&lq
, priv
->stations
[i
].lq
,
614 sizeof(struct iwl_link_quality_cmd
));
617 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
618 ret
= iwl_legacy_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
620 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
621 IWL_ERR(priv
, "Adding station %pM failed.\n",
622 priv
->stations
[i
].sta
.sta
.addr
);
623 priv
->stations
[i
].used
&=
624 ~IWL_STA_DRIVER_ACTIVE
;
625 priv
->stations
[i
].used
&=
626 ~IWL_STA_UCODE_INPROGRESS
;
627 spin_unlock_irqrestore(&priv
->sta_lock
,
631 * Rate scaling has already been initialized, send
635 iwl_legacy_send_lq_cmd(priv
, ctx
, &lq
,
637 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
638 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
642 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
644 IWL_DEBUG_INFO(priv
, "Restoring all known stations"
645 " .... no stations to be restored.\n");
647 IWL_DEBUG_INFO(priv
, "Restoring all known stations"
648 " .... complete.\n");
650 EXPORT_SYMBOL(iwl_legacy_restore_stations
);
652 int iwl_legacy_get_free_ucode_key_index(struct iwl_priv
*priv
)
656 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
657 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
660 return WEP_INVALID_OFFSET
;
662 EXPORT_SYMBOL(iwl_legacy_get_free_ucode_key_index
);
664 void iwl_legacy_dealloc_bcast_stations(struct iwl_priv
*priv
)
669 spin_lock_irqsave(&priv
->sta_lock
, flags
);
670 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
671 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
674 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
675 priv
->num_stations
--;
676 BUG_ON(priv
->num_stations
< 0);
677 kfree(priv
->stations
[i
].lq
);
678 priv
->stations
[i
].lq
= NULL
;
680 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
682 EXPORT_SYMBOL_GPL(iwl_legacy_dealloc_bcast_stations
);
684 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
685 static void iwl_legacy_dump_lq_cmd(struct iwl_priv
*priv
,
686 struct iwl_link_quality_cmd
*lq
)
689 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
690 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
691 lq
->general_params
.single_stream_ant_msk
,
692 lq
->general_params
.dual_stream_ant_msk
);
694 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
695 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
696 i
, lq
->rs_table
[i
].rate_n_flags
);
699 static inline void iwl_legacy_dump_lq_cmd(struct iwl_priv
*priv
,
700 struct iwl_link_quality_cmd
*lq
)
706 * iwl_legacy_is_lq_table_valid() - Test one aspect of LQ cmd for validity
708 * It sometimes happens when a HT rate has been in use and we
709 * loose connectivity with AP then mac80211 will first tell us that the
710 * current channel is not HT anymore before removing the station. In such a
711 * scenario the RXON flags will be updated to indicate we are not
712 * communicating HT anymore, but the LQ command may still contain HT rates.
713 * Test for this to prevent driver from sending LQ command between the time
714 * RXON flags are updated and when LQ command is updated.
716 static bool iwl_legacy_is_lq_table_valid(struct iwl_priv
*priv
,
717 struct iwl_rxon_context
*ctx
,
718 struct iwl_link_quality_cmd
*lq
)
725 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
726 ctx
->active
.channel
);
727 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
728 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
731 "index %d of LQ expects HT channel\n",
740 * iwl_legacy_send_lq_cmd() - Send link quality command
741 * @init: This command is sent as part of station initialization right
742 * after station has been added.
744 * The link quality command is sent as the last step of station creation.
745 * This is the special case in which init is set and we call a callback in
746 * this case to clear the state indicating that station creation is in
749 int iwl_legacy_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
750 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
753 unsigned long flags_spin
;
755 struct iwl_host_cmd cmd
= {
756 .id
= REPLY_TX_LINK_QUALITY_CMD
,
757 .len
= sizeof(struct iwl_link_quality_cmd
),
762 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
766 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
767 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
768 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
771 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
773 iwl_legacy_dump_lq_cmd(priv
, lq
);
774 BUG_ON(init
&& (cmd
.flags
& CMD_ASYNC
));
776 if (iwl_legacy_is_lq_table_valid(priv
, ctx
, lq
))
777 ret
= iwl_legacy_send_cmd(priv
, &cmd
);
781 if (cmd
.flags
& CMD_ASYNC
)
785 IWL_DEBUG_INFO(priv
, "init LQ command complete,"
786 " clearing sta addition status for sta %d\n",
788 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
789 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
790 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
794 EXPORT_SYMBOL(iwl_legacy_send_lq_cmd
);
796 int iwl_legacy_mac_sta_remove(struct ieee80211_hw
*hw
,
797 struct ieee80211_vif
*vif
,
798 struct ieee80211_sta
*sta
)
800 struct iwl_priv
*priv
= hw
->priv
;
801 struct iwl_station_priv_common
*sta_common
= (void *)sta
->drv_priv
;
804 IWL_DEBUG_INFO(priv
, "received request to remove station %pM\n",
806 mutex_lock(&priv
->mutex
);
807 IWL_DEBUG_INFO(priv
, "proceeding to remove station %pM\n",
809 ret
= iwl_legacy_remove_station(priv
, sta_common
->sta_id
, sta
->addr
);
811 IWL_ERR(priv
, "Error removing station %pM\n",
813 mutex_unlock(&priv
->mutex
);
816 EXPORT_SYMBOL(iwl_legacy_mac_sta_remove
);