2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
34 static int ath10k_send_key(struct ath10k_vif
*arvif
,
35 struct ieee80211_key_conf
*key
,
39 struct wmi_vdev_install_key_arg arg
= {
40 .vdev_id
= arvif
->vdev_id
,
41 .key_idx
= key
->keyidx
,
42 .key_len
= key
->keylen
,
47 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
49 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
50 arg
.key_flags
= WMI_KEY_PAIRWISE
;
52 arg
.key_flags
= WMI_KEY_GROUP
;
54 switch (key
->cipher
) {
55 case WLAN_CIPHER_SUITE_CCMP
:
56 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
57 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
59 case WLAN_CIPHER_SUITE_TKIP
:
60 arg
.key_cipher
= WMI_CIPHER_TKIP
;
61 arg
.key_txmic_len
= 8;
62 arg
.key_rxmic_len
= 8;
64 case WLAN_CIPHER_SUITE_WEP40
:
65 case WLAN_CIPHER_SUITE_WEP104
:
66 arg
.key_cipher
= WMI_CIPHER_WEP
;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr
, arvif
->vif
->addr
, ETH_ALEN
))
70 arg
.key_flags
= WMI_KEY_PAIRWISE
;
73 ath10k_warn("cipher %d is not supported\n", key
->cipher
);
77 if (cmd
== DISABLE_KEY
) {
78 arg
.key_cipher
= WMI_CIPHER_NONE
;
82 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
85 static int ath10k_install_key(struct ath10k_vif
*arvif
,
86 struct ieee80211_key_conf
*key
,
90 struct ath10k
*ar
= arvif
->ar
;
93 lockdep_assert_held(&ar
->conf_mutex
);
95 INIT_COMPLETION(ar
->install_key_done
);
97 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
);
101 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
108 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
111 struct ath10k
*ar
= arvif
->ar
;
112 struct ath10k_peer
*peer
;
116 lockdep_assert_held(&ar
->conf_mutex
);
118 spin_lock_bh(&ar
->data_lock
);
119 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
120 spin_unlock_bh(&ar
->data_lock
);
125 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
126 if (arvif
->wep_keys
[i
] == NULL
)
129 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
134 peer
->keys
[i
] = arvif
->wep_keys
[i
];
140 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
143 struct ath10k
*ar
= arvif
->ar
;
144 struct ath10k_peer
*peer
;
149 lockdep_assert_held(&ar
->conf_mutex
);
151 spin_lock_bh(&ar
->data_lock
);
152 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
153 spin_unlock_bh(&ar
->data_lock
);
158 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
159 if (peer
->keys
[i
] == NULL
)
162 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
164 if (ret
&& first_errno
== 0)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
171 peer
->keys
[i
] = NULL
;
177 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
178 struct ieee80211_key_conf
*key
)
180 struct ath10k
*ar
= arvif
->ar
;
181 struct ath10k_peer
*peer
;
187 lockdep_assert_held(&ar
->conf_mutex
);
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar
->data_lock
);
194 list_for_each_entry(peer
, &ar
->peers
, list
) {
195 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
196 if (peer
->keys
[i
] == key
) {
197 memcpy(addr
, peer
->addr
, ETH_ALEN
);
198 peer
->keys
[i
] = NULL
;
203 if (i
< ARRAY_SIZE(peer
->keys
))
206 spin_unlock_bh(&ar
->data_lock
);
208 if (i
== ARRAY_SIZE(peer
->keys
))
211 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
);
212 if (ret
&& first_errno
== 0)
216 ath10k_warn("could not remove key for %pM\n", addr
);
223 /*********************/
224 /* General utilities */
225 /*********************/
227 static inline enum wmi_phy_mode
228 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
230 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
232 switch (chandef
->chan
->band
) {
233 case IEEE80211_BAND_2GHZ
:
234 switch (chandef
->width
) {
235 case NL80211_CHAN_WIDTH_20_NOHT
:
238 case NL80211_CHAN_WIDTH_20
:
239 phymode
= MODE_11NG_HT20
;
241 case NL80211_CHAN_WIDTH_40
:
242 phymode
= MODE_11NG_HT40
;
244 case NL80211_CHAN_WIDTH_5
:
245 case NL80211_CHAN_WIDTH_10
:
246 case NL80211_CHAN_WIDTH_80
:
247 case NL80211_CHAN_WIDTH_80P80
:
248 case NL80211_CHAN_WIDTH_160
:
249 phymode
= MODE_UNKNOWN
;
253 case IEEE80211_BAND_5GHZ
:
254 switch (chandef
->width
) {
255 case NL80211_CHAN_WIDTH_20_NOHT
:
258 case NL80211_CHAN_WIDTH_20
:
259 phymode
= MODE_11NA_HT20
;
261 case NL80211_CHAN_WIDTH_40
:
262 phymode
= MODE_11NA_HT40
;
264 case NL80211_CHAN_WIDTH_80
:
265 phymode
= MODE_11AC_VHT80
;
267 case NL80211_CHAN_WIDTH_5
:
268 case NL80211_CHAN_WIDTH_10
:
269 case NL80211_CHAN_WIDTH_80P80
:
270 case NL80211_CHAN_WIDTH_160
:
271 phymode
= MODE_UNKNOWN
;
279 WARN_ON(phymode
== MODE_UNKNOWN
);
283 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
296 switch (mpdudensity
) {
302 /* Our lower layer calculations limit our precision to
318 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
322 lockdep_assert_held(&ar
->conf_mutex
);
324 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
328 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
335 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
337 if (value
!= 0xFFFFFFFF)
338 value
= min_t(u32
, arvif
->ar
->hw
->wiphy
->rts_threshold
,
341 return ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
,
342 WMI_VDEV_PARAM_RTS_THRESHOLD
,
346 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
348 if (value
!= 0xFFFFFFFF)
349 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
350 ATH10K_FRAGMT_THRESHOLD_MIN
,
351 ATH10K_FRAGMT_THRESHOLD_MAX
);
353 return ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
,
354 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD
,
358 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
362 lockdep_assert_held(&ar
->conf_mutex
);
364 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
368 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
375 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
377 struct ath10k_peer
*peer
, *tmp
;
379 lockdep_assert_held(&ar
->conf_mutex
);
381 spin_lock_bh(&ar
->data_lock
);
382 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
383 if (peer
->vdev_id
!= vdev_id
)
386 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
387 peer
->addr
, vdev_id
);
389 list_del(&peer
->list
);
392 spin_unlock_bh(&ar
->data_lock
);
395 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
397 struct ath10k_peer
*peer
, *tmp
;
399 lockdep_assert_held(&ar
->conf_mutex
);
401 spin_lock_bh(&ar
->data_lock
);
402 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
403 list_del(&peer
->list
);
406 spin_unlock_bh(&ar
->data_lock
);
409 /************************/
410 /* Interface management */
411 /************************/
413 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
417 lockdep_assert_held(&ar
->conf_mutex
);
419 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
420 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
427 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
429 struct ath10k
*ar
= arvif
->ar
;
430 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
431 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
432 struct wmi_vdev_start_request_arg arg
= {};
435 lockdep_assert_held(&ar
->conf_mutex
);
437 INIT_COMPLETION(ar
->vdev_setup_done
);
439 arg
.vdev_id
= arvif
->vdev_id
;
440 arg
.dtim_period
= arvif
->dtim_period
;
441 arg
.bcn_intval
= arvif
->beacon_interval
;
443 arg
.channel
.freq
= channel
->center_freq
;
445 arg
.channel
.band_center_freq1
= conf
->chandef
.center_freq1
;
447 arg
.channel
.mode
= chan_to_phymode(&conf
->chandef
);
449 arg
.channel
.min_power
= channel
->max_power
* 3;
450 arg
.channel
.max_power
= channel
->max_power
* 4;
451 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
452 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
454 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
455 arg
.ssid
= arvif
->u
.ap
.ssid
;
456 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
457 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
458 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
459 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
460 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
463 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
465 ath10k_warn("WMI vdev start failed: ret %d\n", ret
);
469 ret
= ath10k_vdev_setup_sync(ar
);
471 ath10k_warn("vdev setup failed %d\n", ret
);
478 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
480 struct ath10k
*ar
= arvif
->ar
;
483 lockdep_assert_held(&ar
->conf_mutex
);
485 INIT_COMPLETION(ar
->vdev_setup_done
);
487 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
489 ath10k_warn("WMI vdev stop failed: ret %d\n", ret
);
493 ret
= ath10k_vdev_setup_sync(ar
);
495 ath10k_warn("vdev setup failed %d\n", ret
);
502 static int ath10k_monitor_start(struct ath10k
*ar
, int vdev_id
)
504 struct ieee80211_channel
*channel
= ar
->hw
->conf
.chandef
.chan
;
505 struct wmi_vdev_start_request_arg arg
= {};
506 enum nl80211_channel_type type
;
509 lockdep_assert_held(&ar
->conf_mutex
);
511 type
= cfg80211_get_chandef_type(&ar
->hw
->conf
.chandef
);
513 arg
.vdev_id
= vdev_id
;
514 arg
.channel
.freq
= channel
->center_freq
;
515 arg
.channel
.band_center_freq1
= ar
->hw
->conf
.chandef
.center_freq1
;
517 /* TODO setup this dynamically, what in case we
518 don't have any vifs? */
519 arg
.channel
.mode
= chan_to_phymode(&ar
->hw
->conf
.chandef
);
521 arg
.channel
.min_power
= channel
->max_power
* 3;
522 arg
.channel
.max_power
= channel
->max_power
* 4;
523 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
524 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
526 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
528 ath10k_warn("Monitor vdev start failed: ret %d\n", ret
);
532 ret
= ath10k_vdev_setup_sync(ar
);
534 ath10k_warn("Monitor vdev setup failed %d\n", ret
);
538 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
540 ath10k_warn("Monitor vdev up failed: %d\n", ret
);
544 ar
->monitor_vdev_id
= vdev_id
;
545 ar
->monitor_enabled
= true;
550 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
552 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
557 static int ath10k_monitor_stop(struct ath10k
*ar
)
561 lockdep_assert_held(&ar
->conf_mutex
);
563 /* For some reasons, ath10k_wmi_vdev_down() here couse
564 * often ath10k_wmi_vdev_stop() to fail. Next we could
565 * not run monitor vdev and driver reload
566 * required. Don't see such problems we skip
567 * ath10k_wmi_vdev_down() here.
570 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
572 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
574 ret
= ath10k_vdev_setup_sync(ar
);
576 ath10k_warn("Monitor_down sync failed: %d\n", ret
);
578 ar
->monitor_enabled
= false;
582 static int ath10k_monitor_create(struct ath10k
*ar
)
586 lockdep_assert_held(&ar
->conf_mutex
);
588 if (ar
->monitor_present
) {
589 ath10k_warn("Monitor mode already enabled\n");
593 bit
= ffs(ar
->free_vdev_map
);
595 ath10k_warn("No free VDEV slots\n");
599 ar
->monitor_vdev_id
= bit
- 1;
600 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
602 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
603 WMI_VDEV_TYPE_MONITOR
,
606 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret
);
610 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor interface created, vdev id: %d\n",
611 ar
->monitor_vdev_id
);
613 ar
->monitor_present
= true;
618 * Restore the ID to the global map.
620 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
624 static int ath10k_monitor_destroy(struct ath10k
*ar
)
628 lockdep_assert_held(&ar
->conf_mutex
);
630 if (!ar
->monitor_present
)
633 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
635 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret
);
639 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
640 ar
->monitor_present
= false;
642 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor interface destroyed, vdev id: %d\n",
643 ar
->monitor_vdev_id
);
647 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
648 struct ieee80211_bss_conf
*info
)
652 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
654 if (!info
->enable_beacon
) {
655 ath10k_vdev_stop(arvif
);
659 arvif
->tx_seq_no
= 0x1000;
661 ret
= ath10k_vdev_start(arvif
);
665 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, 0, info
->bssid
);
667 ath10k_warn("Failed to bring up VDEV: %d\n",
671 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d up\n", arvif
->vdev_id
);
674 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
675 struct ieee80211_bss_conf
*info
,
676 const u8 self_peer
[ETH_ALEN
])
680 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
682 if (!info
->ibss_joined
) {
683 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
685 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
686 self_peer
, arvif
->vdev_id
, ret
);
688 if (is_zero_ether_addr(arvif
->u
.ibss
.bssid
))
691 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
692 arvif
->u
.ibss
.bssid
);
694 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
695 arvif
->u
.ibss
.bssid
, arvif
->vdev_id
, ret
);
699 memset(arvif
->u
.ibss
.bssid
, 0, ETH_ALEN
);
704 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
706 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
707 self_peer
, arvif
->vdev_id
, ret
);
711 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
,
712 WMI_VDEV_PARAM_ATIM_WINDOW
,
713 ATH10K_DEFAULT_ATIM
);
715 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
716 arvif
->vdev_id
, ret
);
720 * Review this when mac80211 gains per-interface powersave support.
722 static void ath10k_ps_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
724 struct ath10k_generic_iter
*ar_iter
= data
;
725 struct ieee80211_conf
*conf
= &ar_iter
->ar
->hw
->conf
;
726 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
727 enum wmi_sta_powersave_param param
;
728 enum wmi_sta_ps_mode psmode
;
731 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
733 if (vif
->type
!= NL80211_IFTYPE_STATION
)
736 if (conf
->flags
& IEEE80211_CONF_PS
) {
737 psmode
= WMI_STA_PS_MODE_ENABLED
;
738 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
740 ret
= ath10k_wmi_set_sta_ps_param(ar_iter
->ar
,
743 conf
->dynamic_ps_timeout
);
745 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
752 psmode
= WMI_STA_PS_MODE_DISABLED
;
755 ar_iter
->ret
= ath10k_wmi_set_psmode(ar_iter
->ar
, arvif
->vdev_id
,
758 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
759 psmode
, arvif
->vdev_id
);
761 ath10k_dbg(ATH10K_DBG_MAC
, "Set PS Mode: %d for VDEV: %d\n",
762 psmode
, arvif
->vdev_id
);
765 /**********************/
766 /* Station management */
767 /**********************/
769 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
770 struct ath10k_vif
*arvif
,
771 struct ieee80211_sta
*sta
,
772 struct ieee80211_bss_conf
*bss_conf
,
773 struct wmi_peer_assoc_complete_arg
*arg
)
775 lockdep_assert_held(&ar
->conf_mutex
);
777 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
778 arg
->vdev_id
= arvif
->vdev_id
;
779 arg
->peer_aid
= sta
->aid
;
780 arg
->peer_flags
|= WMI_PEER_AUTH
;
782 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
784 * Seems FW have problems with Power Save in STA
785 * mode when we setup this parameter to high (eg. 5).
786 * Often we see that FW don't send NULL (with clean P flags)
787 * frame even there is info about buffered frames in beacons.
788 * Sometimes we have to wait more than 10 seconds before FW
789 * will wakeup. Often sending one ping from AP to our device
790 * just fail (more than 50%).
792 * Seems setting this FW parameter to 1 couse FW
793 * will check every beacon and will wakup immediately
794 * after detection buffered data.
796 arg
->peer_listen_intval
= 1;
798 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
800 arg
->peer_num_spatial_streams
= 1;
803 * The assoc capabilities are available only in managed mode.
805 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
806 arg
->peer_caps
= bss_conf
->assoc_capability
;
809 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
810 struct ath10k_vif
*arvif
,
811 struct wmi_peer_assoc_complete_arg
*arg
)
813 struct ieee80211_vif
*vif
= arvif
->vif
;
814 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
815 struct cfg80211_bss
*bss
;
816 const u8
*rsnie
= NULL
;
817 const u8
*wpaie
= NULL
;
819 lockdep_assert_held(&ar
->conf_mutex
);
821 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
822 info
->bssid
, NULL
, 0, 0, 0);
824 const struct cfg80211_bss_ies
*ies
;
827 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
829 ies
= rcu_dereference(bss
->ies
);
831 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
832 WLAN_OUI_TYPE_MICROSOFT_WPA
,
836 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
839 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
840 if (rsnie
|| wpaie
) {
841 ath10k_dbg(ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
842 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
846 ath10k_dbg(ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
847 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
851 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
852 struct ieee80211_sta
*sta
,
853 struct wmi_peer_assoc_complete_arg
*arg
)
855 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
856 const struct ieee80211_supported_band
*sband
;
857 const struct ieee80211_rate
*rates
;
861 lockdep_assert_held(&ar
->conf_mutex
);
863 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
864 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
865 rates
= sband
->bitrates
;
867 rateset
->num_rates
= 0;
869 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
873 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
874 rateset
->num_rates
++;
878 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
879 struct ieee80211_sta
*sta
,
880 struct wmi_peer_assoc_complete_arg
*arg
)
882 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
886 lockdep_assert_held(&ar
->conf_mutex
);
888 if (!ht_cap
->ht_supported
)
891 arg
->peer_flags
|= WMI_PEER_HT
;
892 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
893 ht_cap
->ampdu_factor
)) - 1;
895 arg
->peer_mpdu_density
=
896 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
898 arg
->peer_ht_caps
= ht_cap
->cap
;
899 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
901 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
902 arg
->peer_flags
|= WMI_PEER_LDPC
;
904 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
905 arg
->peer_flags
|= WMI_PEER_40MHZ
;
906 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
909 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
910 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
912 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
913 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
915 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
916 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
917 arg
->peer_flags
|= WMI_PEER_STBC
;
920 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
922 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
923 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
924 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
925 arg
->peer_rate_caps
|= stbc
;
926 arg
->peer_flags
|= WMI_PEER_STBC
;
929 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
930 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
932 if (smps
== WLAN_HT_CAP_SM_PS_STATIC
) {
933 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
934 arg
->peer_flags
|= WMI_PEER_STATIC_MIMOPS
;
935 } else if (smps
== WLAN_HT_CAP_SM_PS_DYNAMIC
) {
936 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
937 arg
->peer_flags
|= WMI_PEER_DYN_MIMOPS
;
940 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
941 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
942 else if (ht_cap
->mcs
.rx_mask
[1])
943 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
945 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
946 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
947 arg
->peer_ht_rates
.rates
[n
++] = i
;
949 arg
->peer_ht_rates
.num_rates
= n
;
950 arg
->peer_num_spatial_streams
= max((n
+7) / 8, 1);
952 ath10k_dbg(ATH10K_DBG_MAC
, "mcs cnt %d nss %d\n",
953 arg
->peer_ht_rates
.num_rates
,
954 arg
->peer_num_spatial_streams
);
957 static void ath10k_peer_assoc_h_qos_ap(struct ath10k
*ar
,
958 struct ath10k_vif
*arvif
,
959 struct ieee80211_sta
*sta
,
960 struct ieee80211_bss_conf
*bss_conf
,
961 struct wmi_peer_assoc_complete_arg
*arg
)
966 lockdep_assert_held(&ar
->conf_mutex
);
969 arg
->peer_flags
|= WMI_PEER_QOS
;
971 if (sta
->wme
&& sta
->uapsd_queues
) {
972 ath10k_dbg(ATH10K_DBG_MAC
, "uapsd_queues: 0x%X, max_sp: %d\n",
973 sta
->uapsd_queues
, sta
->max_sp
);
975 arg
->peer_flags
|= WMI_PEER_APSD
;
976 arg
->peer_flags
|= WMI_RC_UAPSD_FLAG
;
978 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
979 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
980 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
981 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
982 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
983 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
984 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
985 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
986 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
987 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
988 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
989 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
992 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
993 max_sp
= sta
->max_sp
;
995 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
997 WMI_AP_PS_PEER_PARAM_UAPSD
,
1000 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1002 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1005 /* TODO setup this based on STA listen interval and
1006 beacon interval. Currently we don't know
1007 sta->listen_interval - mac80211 patch required.
1008 Currently use 10 seconds */
1009 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1011 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1016 static void ath10k_peer_assoc_h_qos_sta(struct ath10k
*ar
,
1017 struct ath10k_vif
*arvif
,
1018 struct ieee80211_sta
*sta
,
1019 struct ieee80211_bss_conf
*bss_conf
,
1020 struct wmi_peer_assoc_complete_arg
*arg
)
1023 arg
->peer_flags
|= WMI_PEER_QOS
;
1026 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1027 struct ieee80211_sta
*sta
,
1028 struct wmi_peer_assoc_complete_arg
*arg
)
1030 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1032 if (!vht_cap
->vht_supported
)
1035 arg
->peer_flags
|= WMI_PEER_VHT
;
1037 arg
->peer_vht_caps
= vht_cap
->cap
;
1039 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1040 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1042 arg
->peer_vht_rates
.rx_max_rate
=
1043 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1044 arg
->peer_vht_rates
.rx_mcs_set
=
1045 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1046 arg
->peer_vht_rates
.tx_max_rate
=
1047 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1048 arg
->peer_vht_rates
.tx_mcs_set
=
1049 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1051 ath10k_dbg(ATH10K_DBG_MAC
, "mac vht peer\n");
1054 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1055 struct ath10k_vif
*arvif
,
1056 struct ieee80211_sta
*sta
,
1057 struct ieee80211_bss_conf
*bss_conf
,
1058 struct wmi_peer_assoc_complete_arg
*arg
)
1060 switch (arvif
->vdev_type
) {
1061 case WMI_VDEV_TYPE_AP
:
1062 ath10k_peer_assoc_h_qos_ap(ar
, arvif
, sta
, bss_conf
, arg
);
1064 case WMI_VDEV_TYPE_STA
:
1065 ath10k_peer_assoc_h_qos_sta(ar
, arvif
, sta
, bss_conf
, arg
);
1072 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1073 struct ath10k_vif
*arvif
,
1074 struct ieee80211_sta
*sta
,
1075 struct wmi_peer_assoc_complete_arg
*arg
)
1077 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1079 /* FIXME: add VHT */
1081 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1082 case IEEE80211_BAND_2GHZ
:
1083 if (sta
->ht_cap
.ht_supported
) {
1084 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1085 phymode
= MODE_11NG_HT40
;
1087 phymode
= MODE_11NG_HT20
;
1093 case IEEE80211_BAND_5GHZ
:
1094 if (sta
->ht_cap
.ht_supported
) {
1095 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1096 phymode
= MODE_11NA_HT40
;
1098 phymode
= MODE_11NA_HT20
;
1108 arg
->peer_phymode
= phymode
;
1109 WARN_ON(phymode
== MODE_UNKNOWN
);
1112 static int ath10k_peer_assoc(struct ath10k
*ar
,
1113 struct ath10k_vif
*arvif
,
1114 struct ieee80211_sta
*sta
,
1115 struct ieee80211_bss_conf
*bss_conf
)
1117 struct wmi_peer_assoc_complete_arg arg
;
1119 lockdep_assert_held(&ar
->conf_mutex
);
1121 memset(&arg
, 0, sizeof(struct wmi_peer_assoc_complete_arg
));
1123 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, &arg
);
1124 ath10k_peer_assoc_h_crypto(ar
, arvif
, &arg
);
1125 ath10k_peer_assoc_h_rates(ar
, sta
, &arg
);
1126 ath10k_peer_assoc_h_ht(ar
, sta
, &arg
);
1127 ath10k_peer_assoc_h_vht(ar
, sta
, &arg
);
1128 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, &arg
);
1129 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, &arg
);
1131 return ath10k_wmi_peer_assoc(ar
, &arg
);
1134 /* can be called only in mac80211 callbacks due to `key_count` usage */
1135 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1136 struct ieee80211_vif
*vif
,
1137 struct ieee80211_bss_conf
*bss_conf
)
1139 struct ath10k
*ar
= hw
->priv
;
1140 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1141 struct ieee80211_sta
*ap_sta
;
1144 lockdep_assert_held(&ar
->conf_mutex
);
1148 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1150 ath10k_warn("Failed to find station entry for %pM\n",
1156 ret
= ath10k_peer_assoc(ar
, arvif
, ap_sta
, bss_conf
);
1158 ath10k_warn("Peer assoc failed for %pM\n", bss_conf
->bssid
);
1165 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, bss_conf
->aid
,
1168 ath10k_warn("VDEV: %d up failed: ret %d\n",
1169 arvif
->vdev_id
, ret
);
1171 ath10k_dbg(ATH10K_DBG_MAC
,
1172 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1173 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1179 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1180 struct ieee80211_vif
*vif
)
1182 struct ath10k
*ar
= hw
->priv
;
1183 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1186 lockdep_assert_held(&ar
->conf_mutex
);
1189 * For some reason, calling VDEV-DOWN before VDEV-STOP
1190 * makes the FW to send frames via HTT after disassociation.
1191 * No idea why this happens, even though VDEV-DOWN is supposed
1192 * to be analogous to link down, so just stop the VDEV.
1194 ret
= ath10k_vdev_stop(arvif
);
1196 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d stopped\n",
1200 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1201 * report beacons from previously associated network through HTT.
1202 * This in turn would spam mac80211 WARN_ON if we bring down all
1203 * interfaces as it expects there is no rx when no interface is
1206 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1208 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1209 arvif
->vdev_id
, ret
);
1211 ath10k_wmi_flush_tx(ar
);
1213 arvif
->def_wep_key_index
= 0;
1216 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1217 struct ieee80211_sta
*sta
)
1221 lockdep_assert_held(&ar
->conf_mutex
);
1223 ret
= ath10k_peer_assoc(ar
, arvif
, sta
, NULL
);
1225 ath10k_warn("WMI peer assoc failed for %pM\n", sta
->addr
);
1229 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1231 ath10k_warn("could not install peer wep keys (%d)\n", ret
);
1238 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1239 struct ieee80211_sta
*sta
)
1243 lockdep_assert_held(&ar
->conf_mutex
);
1245 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1247 ath10k_warn("could not clear all peer wep keys (%d)\n", ret
);
1258 static int ath10k_update_channel_list(struct ath10k
*ar
)
1260 struct ieee80211_hw
*hw
= ar
->hw
;
1261 struct ieee80211_supported_band
**bands
;
1262 enum ieee80211_band band
;
1263 struct ieee80211_channel
*channel
;
1264 struct wmi_scan_chan_list_arg arg
= {0};
1265 struct wmi_channel_arg
*ch
;
1271 lockdep_assert_held(&ar
->conf_mutex
);
1273 bands
= hw
->wiphy
->bands
;
1274 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1278 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1279 if (bands
[band
]->channels
[i
].flags
&
1280 IEEE80211_CHAN_DISABLED
)
1287 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1288 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1293 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1297 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1298 channel
= &bands
[band
]->channels
[i
];
1300 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1303 ch
->allow_ht
= true;
1305 /* FIXME: when should we really allow VHT? */
1306 ch
->allow_vht
= true;
1309 !(channel
->flags
& IEEE80211_CHAN_NO_IBSS
);
1312 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1314 passive
= channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
;
1315 ch
->passive
= passive
;
1317 ch
->freq
= channel
->center_freq
;
1318 ch
->min_power
= channel
->max_power
* 3;
1319 ch
->max_power
= channel
->max_power
* 4;
1320 ch
->max_reg_power
= channel
->max_reg_power
* 4;
1321 ch
->max_antenna_gain
= channel
->max_antenna_gain
;
1322 ch
->reg_class_id
= 0; /* FIXME */
1324 /* FIXME: why use only legacy modes, why not any
1325 * HT/VHT modes? Would that even make any
1327 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1328 ch
->mode
= MODE_11G
;
1330 ch
->mode
= MODE_11A
;
1332 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1335 ath10k_dbg(ATH10K_DBG_WMI
,
1336 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1337 __func__
, ch
- arg
.channels
, arg
.n_channels
,
1338 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1339 ch
->max_antenna_gain
, ch
->mode
);
1345 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1346 kfree(arg
.channels
);
1351 static void ath10k_regd_update(struct ath10k
*ar
)
1353 struct reg_dmn_pair_mapping
*regpair
;
1356 lockdep_assert_held(&ar
->conf_mutex
);
1358 ret
= ath10k_update_channel_list(ar
);
1360 ath10k_warn("could not update channel list (%d)\n", ret
);
1362 regpair
= ar
->ath_common
.regulatory
.regpair
;
1364 /* Target allows setting up per-band regdomain but ath_common provides
1365 * a combined one only */
1366 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1367 regpair
->regDmnEnum
,
1368 regpair
->regDmnEnum
, /* 2ghz */
1369 regpair
->regDmnEnum
, /* 5ghz */
1370 regpair
->reg_2ghz_ctl
,
1371 regpair
->reg_5ghz_ctl
);
1373 ath10k_warn("could not set pdev regdomain (%d)\n", ret
);
1376 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1377 struct regulatory_request
*request
)
1379 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1380 struct ath10k
*ar
= hw
->priv
;
1382 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1384 mutex_lock(&ar
->conf_mutex
);
1385 if (ar
->state
== ATH10K_STATE_ON
)
1386 ath10k_regd_update(ar
);
1387 mutex_unlock(&ar
->conf_mutex
);
1395 * Frames sent to the FW have to be in "Native Wifi" format.
1396 * Strip the QoS field from the 802.11 header.
1398 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw
*hw
,
1399 struct ieee80211_tx_control
*control
,
1400 struct sk_buff
*skb
)
1402 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1405 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1408 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1409 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
1410 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
1411 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
1414 static void ath10k_tx_h_update_wep_key(struct sk_buff
*skb
)
1416 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1417 struct ieee80211_vif
*vif
= info
->control
.vif
;
1418 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1419 struct ath10k
*ar
= arvif
->ar
;
1420 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1421 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
1424 /* TODO AP mode should be implemented */
1425 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1428 if (!ieee80211_has_protected(hdr
->frame_control
))
1434 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1435 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1438 if (key
->keyidx
== arvif
->def_wep_key_index
)
1441 ath10k_dbg(ATH10K_DBG_MAC
, "new wep keyidx will be %d\n", key
->keyidx
);
1443 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1444 WMI_VDEV_PARAM_DEF_KEYID
,
1447 ath10k_warn("could not update wep keyidx (%d)\n", ret
);
1451 arvif
->def_wep_key_index
= key
->keyidx
;
1454 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
, struct sk_buff
*skb
)
1456 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1457 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1458 struct ieee80211_vif
*vif
= info
->control
.vif
;
1459 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1461 /* This is case only for P2P_GO */
1462 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1463 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1466 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1467 spin_lock_bh(&ar
->data_lock
);
1468 if (arvif
->u
.ap
.noa_data
)
1469 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1471 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1472 arvif
->u
.ap
.noa_data
,
1473 arvif
->u
.ap
.noa_len
);
1474 spin_unlock_bh(&ar
->data_lock
);
1478 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1480 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1483 if (ieee80211_is_mgmt(hdr
->frame_control
))
1484 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1485 else if (ieee80211_is_nullfunc(hdr
->frame_control
))
1486 /* FW does not report tx status properly for NullFunc frames
1487 * unless they are sent through mgmt tx path. mac80211 sends
1488 * those frames when it detects link/beacon loss and depends on
1489 * the tx status to be correct. */
1490 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1492 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1495 ath10k_warn("tx failed (%d). dropping packet.\n", ret
);
1496 ieee80211_free_txskb(ar
->hw
, skb
);
1500 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
1502 struct sk_buff
*skb
;
1505 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1509 ieee80211_free_txskb(ar
->hw
, skb
);
1513 void ath10k_offchan_tx_work(struct work_struct
*work
)
1515 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
1516 struct ath10k_peer
*peer
;
1517 struct ieee80211_hdr
*hdr
;
1518 struct sk_buff
*skb
;
1519 const u8
*peer_addr
;
1523 /* FW requirement: We must create a peer before FW will send out
1524 * an offchannel frame. Otherwise the frame will be stuck and
1525 * never transmitted. We delete the peer upon tx completion.
1526 * It is unlikely that a peer for offchannel tx will already be
1527 * present. However it may be in some rare cases so account for that.
1528 * Otherwise we might remove a legitimate peer and break stuff. */
1531 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1535 mutex_lock(&ar
->conf_mutex
);
1537 ath10k_dbg(ATH10K_DBG_MAC
, "processing offchannel skb %p\n",
1540 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1541 peer_addr
= ieee80211_get_DA(hdr
);
1542 vdev_id
= ATH10K_SKB_CB(skb
)->htt
.vdev_id
;
1544 spin_lock_bh(&ar
->data_lock
);
1545 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
1546 spin_unlock_bh(&ar
->data_lock
);
1549 ath10k_dbg(ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
1550 peer_addr
, vdev_id
);
1553 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
1555 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1556 peer_addr
, vdev_id
, ret
);
1559 spin_lock_bh(&ar
->data_lock
);
1560 INIT_COMPLETION(ar
->offchan_tx_completed
);
1561 ar
->offchan_tx_skb
= skb
;
1562 spin_unlock_bh(&ar
->data_lock
);
1564 ath10k_tx_htt(ar
, skb
);
1566 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
1569 ath10k_warn("timed out waiting for offchannel skb %p\n",
1573 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
1575 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1576 peer_addr
, vdev_id
, ret
);
1579 mutex_unlock(&ar
->conf_mutex
);
1588 * This gets called if we dont get a heart-beat during scan.
1589 * This may indicate the FW has hung and we need to abort the
1590 * scan manually to prevent cancel_hw_scan() from deadlocking
1592 void ath10k_reset_scan(unsigned long ptr
)
1594 struct ath10k
*ar
= (struct ath10k
*)ptr
;
1596 spin_lock_bh(&ar
->data_lock
);
1597 if (!ar
->scan
.in_progress
) {
1598 spin_unlock_bh(&ar
->data_lock
);
1602 ath10k_warn("scan timeout. resetting. fw issue?\n");
1604 if (ar
->scan
.is_roc
)
1605 ieee80211_remain_on_channel_expired(ar
->hw
);
1607 ieee80211_scan_completed(ar
->hw
, 1 /* aborted */);
1609 ar
->scan
.in_progress
= false;
1610 complete_all(&ar
->scan
.completed
);
1611 spin_unlock_bh(&ar
->data_lock
);
1614 static int ath10k_abort_scan(struct ath10k
*ar
)
1616 struct wmi_stop_scan_arg arg
= {
1617 .req_id
= 1, /* FIXME */
1618 .req_type
= WMI_SCAN_STOP_ONE
,
1619 .u
.scan_id
= ATH10K_SCAN_ID
,
1623 lockdep_assert_held(&ar
->conf_mutex
);
1625 del_timer_sync(&ar
->scan
.timeout
);
1627 spin_lock_bh(&ar
->data_lock
);
1628 if (!ar
->scan
.in_progress
) {
1629 spin_unlock_bh(&ar
->data_lock
);
1633 ar
->scan
.aborting
= true;
1634 spin_unlock_bh(&ar
->data_lock
);
1636 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
1638 ath10k_warn("could not submit wmi stop scan (%d)\n", ret
);
1639 spin_lock_bh(&ar
->data_lock
);
1640 ar
->scan
.in_progress
= false;
1641 ath10k_offchan_tx_purge(ar
);
1642 spin_unlock_bh(&ar
->data_lock
);
1646 ath10k_wmi_flush_tx(ar
);
1648 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
1650 ath10k_warn("timed out while waiting for scan to stop\n");
1652 /* scan completion may be done right after we timeout here, so let's
1653 * check the in_progress and tell mac80211 scan is completed. if we
1654 * don't do that and FW fails to send us scan completion indication
1655 * then userspace won't be able to scan anymore */
1658 spin_lock_bh(&ar
->data_lock
);
1659 if (ar
->scan
.in_progress
) {
1660 ath10k_warn("could not stop scan. its still in progress\n");
1661 ar
->scan
.in_progress
= false;
1662 ath10k_offchan_tx_purge(ar
);
1665 spin_unlock_bh(&ar
->data_lock
);
1670 static int ath10k_start_scan(struct ath10k
*ar
,
1671 const struct wmi_start_scan_arg
*arg
)
1675 lockdep_assert_held(&ar
->conf_mutex
);
1677 ret
= ath10k_wmi_start_scan(ar
, arg
);
1681 /* make sure we submit the command so the completion
1682 * timeout makes sense */
1683 ath10k_wmi_flush_tx(ar
);
1685 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
1687 ath10k_abort_scan(ar
);
1691 /* the scan can complete earlier, before we even
1692 * start the timer. in that case the timer handler
1693 * checks ar->scan.in_progress and bails out if its
1694 * false. Add a 200ms margin to account event/command
1696 mod_timer(&ar
->scan
.timeout
, jiffies
+
1697 msecs_to_jiffies(arg
->max_scan_time
+200));
1701 /**********************/
1702 /* mac80211 callbacks */
1703 /**********************/
1705 static void ath10k_tx(struct ieee80211_hw
*hw
,
1706 struct ieee80211_tx_control
*control
,
1707 struct sk_buff
*skb
)
1709 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1710 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1711 struct ath10k
*ar
= hw
->priv
;
1712 struct ath10k_vif
*arvif
= NULL
;
1716 if (info
->control
.vif
) {
1717 arvif
= ath10k_vif_to_arvif(info
->control
.vif
);
1718 vdev_id
= arvif
->vdev_id
;
1719 } else if (ar
->monitor_enabled
) {
1720 vdev_id
= ar
->monitor_vdev_id
;
1723 /* We should disable CCK RATE due to P2P */
1724 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
1725 ath10k_dbg(ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1727 /* we must calculate tid before we apply qos workaround
1728 * as we'd lose the qos control field */
1729 tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1730 if (ieee80211_is_data_qos(hdr
->frame_control
) &&
1731 is_unicast_ether_addr(ieee80211_get_DA(hdr
))) {
1732 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
1733 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
1736 /* it makes no sense to process injected frames like that */
1737 if (info
->control
.vif
&&
1738 info
->control
.vif
->type
!= NL80211_IFTYPE_MONITOR
) {
1739 ath10k_tx_h_qos_workaround(hw
, control
, skb
);
1740 ath10k_tx_h_update_wep_key(skb
);
1741 ath10k_tx_h_add_p2p_noa_ie(ar
, skb
);
1742 ath10k_tx_h_seq_no(skb
);
1745 memset(ATH10K_SKB_CB(skb
), 0, sizeof(*ATH10K_SKB_CB(skb
)));
1746 ATH10K_SKB_CB(skb
)->htt
.vdev_id
= vdev_id
;
1747 ATH10K_SKB_CB(skb
)->htt
.tid
= tid
;
1749 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
1750 spin_lock_bh(&ar
->data_lock
);
1751 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
1752 ATH10K_SKB_CB(skb
)->htt
.vdev_id
= ar
->scan
.vdev_id
;
1753 spin_unlock_bh(&ar
->data_lock
);
1755 ath10k_dbg(ATH10K_DBG_MAC
, "queued offchannel skb %p\n", skb
);
1757 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
1758 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
1762 ath10k_tx_htt(ar
, skb
);
1766 * Initialize various parameters with default vaules.
1768 void ath10k_halt(struct ath10k
*ar
)
1770 lockdep_assert_held(&ar
->conf_mutex
);
1772 del_timer_sync(&ar
->scan
.timeout
);
1773 ath10k_offchan_tx_purge(ar
);
1774 ath10k_peer_cleanup_all(ar
);
1775 ath10k_core_stop(ar
);
1776 ath10k_hif_power_down(ar
);
1778 spin_lock_bh(&ar
->data_lock
);
1779 if (ar
->scan
.in_progress
) {
1780 del_timer(&ar
->scan
.timeout
);
1781 ar
->scan
.in_progress
= false;
1782 ieee80211_scan_completed(ar
->hw
, true);
1784 spin_unlock_bh(&ar
->data_lock
);
1787 static int ath10k_start(struct ieee80211_hw
*hw
)
1789 struct ath10k
*ar
= hw
->priv
;
1792 mutex_lock(&ar
->conf_mutex
);
1794 if (ar
->state
!= ATH10K_STATE_OFF
&&
1795 ar
->state
!= ATH10K_STATE_RESTARTING
) {
1800 ret
= ath10k_hif_power_up(ar
);
1802 ath10k_err("could not init hif (%d)\n", ret
);
1803 ar
->state
= ATH10K_STATE_OFF
;
1807 ret
= ath10k_core_start(ar
);
1809 ath10k_err("could not init core (%d)\n", ret
);
1810 ath10k_hif_power_down(ar
);
1811 ar
->state
= ATH10K_STATE_OFF
;
1815 if (ar
->state
== ATH10K_STATE_OFF
)
1816 ar
->state
= ATH10K_STATE_ON
;
1817 else if (ar
->state
== ATH10K_STATE_RESTARTING
)
1818 ar
->state
= ATH10K_STATE_RESTARTED
;
1820 ret
= ath10k_wmi_pdev_set_param(ar
, WMI_PDEV_PARAM_PMF_QOS
, 1);
1822 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1825 ret
= ath10k_wmi_pdev_set_param(ar
, WMI_PDEV_PARAM_DYNAMIC_BW
, 0);
1827 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1830 ath10k_regd_update(ar
);
1833 mutex_unlock(&ar
->conf_mutex
);
1837 static void ath10k_stop(struct ieee80211_hw
*hw
)
1839 struct ath10k
*ar
= hw
->priv
;
1841 mutex_lock(&ar
->conf_mutex
);
1842 if (ar
->state
== ATH10K_STATE_ON
||
1843 ar
->state
== ATH10K_STATE_RESTARTED
||
1844 ar
->state
== ATH10K_STATE_WEDGED
)
1847 ar
->state
= ATH10K_STATE_OFF
;
1848 mutex_unlock(&ar
->conf_mutex
);
1850 cancel_work_sync(&ar
->offchan_tx_work
);
1851 cancel_work_sync(&ar
->restart_work
);
1854 static void ath10k_config_ps(struct ath10k
*ar
)
1856 struct ath10k_generic_iter ar_iter
;
1858 lockdep_assert_held(&ar
->conf_mutex
);
1860 /* During HW reconfiguration mac80211 reports all interfaces that were
1861 * running until reconfiguration was started. Since FW doesn't have any
1862 * vdevs at this point we must not iterate over this interface list.
1863 * This setting will be updated upon add_interface(). */
1864 if (ar
->state
== ATH10K_STATE_RESTARTED
)
1867 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
1870 ieee80211_iterate_active_interfaces_atomic(
1871 ar
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1872 ath10k_ps_iter
, &ar_iter
);
1875 ath10k_warn("failed to set ps config (%d)\n", ar_iter
.ret
);
1878 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
1880 struct ath10k
*ar
= hw
->priv
;
1881 struct ieee80211_conf
*conf
= &hw
->conf
;
1884 mutex_lock(&ar
->conf_mutex
);
1886 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1887 ath10k_dbg(ATH10K_DBG_MAC
, "Config channel %d mhz\n",
1888 conf
->chandef
.chan
->center_freq
);
1889 spin_lock_bh(&ar
->data_lock
);
1890 ar
->rx_channel
= conf
->chandef
.chan
;
1891 spin_unlock_bh(&ar
->data_lock
);
1894 if (changed
& IEEE80211_CONF_CHANGE_PS
)
1895 ath10k_config_ps(ar
);
1897 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1898 if (conf
->flags
& IEEE80211_CONF_MONITOR
)
1899 ret
= ath10k_monitor_create(ar
);
1901 ret
= ath10k_monitor_destroy(ar
);
1904 ath10k_wmi_flush_tx(ar
);
1905 mutex_unlock(&ar
->conf_mutex
);
1911 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1912 * because we will send mgmt frames without CCK. This requirement
1913 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1916 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
1917 struct ieee80211_vif
*vif
)
1919 struct ath10k
*ar
= hw
->priv
;
1920 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1921 enum wmi_sta_powersave_param param
;
1926 mutex_lock(&ar
->conf_mutex
);
1928 memset(arvif
, 0, sizeof(*arvif
));
1933 if ((vif
->type
== NL80211_IFTYPE_MONITOR
) && ar
->monitor_present
) {
1934 ath10k_warn("Only one monitor interface allowed\n");
1939 bit
= ffs(ar
->free_vdev_map
);
1945 arvif
->vdev_id
= bit
- 1;
1946 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
1947 ar
->free_vdev_map
&= ~(1 << arvif
->vdev_id
);
1950 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
1952 switch (vif
->type
) {
1953 case NL80211_IFTYPE_UNSPECIFIED
:
1954 case NL80211_IFTYPE_STATION
:
1955 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
1957 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
1959 case NL80211_IFTYPE_ADHOC
:
1960 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
1962 case NL80211_IFTYPE_AP
:
1963 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
1966 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
1968 case NL80211_IFTYPE_MONITOR
:
1969 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
1976 ath10k_dbg(ATH10K_DBG_MAC
, "Add interface: id %d type %d subtype %d\n",
1977 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
1979 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
1980 arvif
->vdev_subtype
, vif
->addr
);
1982 ath10k_warn("WMI vdev create failed: ret %d\n", ret
);
1986 ret
= ath10k_wmi_vdev_set_param(ar
, 0, WMI_VDEV_PARAM_DEF_KEYID
,
1987 arvif
->def_wep_key_index
);
1989 ath10k_warn("Failed to set default keyid: %d\n", ret
);
1991 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1992 WMI_VDEV_PARAM_TX_ENCAP_TYPE
,
1993 ATH10K_HW_TXRX_NATIVE_WIFI
);
1995 ath10k_warn("Failed to set TX encap: %d\n", ret
);
1997 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1998 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
2000 ath10k_warn("Failed to create peer for AP: %d\n", ret
);
2005 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
2006 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
2007 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2008 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2011 ath10k_warn("Failed to set RX wake policy: %d\n", ret
);
2013 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
2014 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
2015 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2018 ath10k_warn("Failed to set TX wake thresh: %d\n", ret
);
2020 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
2021 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
2022 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2025 ath10k_warn("Failed to set PSPOLL count: %d\n", ret
);
2028 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
2030 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2031 arvif
->vdev_id
, ret
);
2033 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
2035 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2036 arvif
->vdev_id
, ret
);
2038 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2039 ar
->monitor_present
= true;
2042 mutex_unlock(&ar
->conf_mutex
);
2046 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
2047 struct ieee80211_vif
*vif
)
2049 struct ath10k
*ar
= hw
->priv
;
2050 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2053 mutex_lock(&ar
->conf_mutex
);
2055 ath10k_dbg(ATH10K_DBG_MAC
, "Remove interface: id %d\n", arvif
->vdev_id
);
2057 ar
->free_vdev_map
|= 1 << (arvif
->vdev_id
);
2059 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2060 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
2062 ath10k_warn("Failed to remove peer for AP: %d\n", ret
);
2064 kfree(arvif
->u
.ap
.noa_data
);
2067 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2069 ath10k_warn("WMI vdev delete failed: %d\n", ret
);
2071 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2072 ar
->monitor_present
= false;
2074 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
2076 mutex_unlock(&ar
->conf_mutex
);
2080 * FIXME: Has to be verified.
2082 #define SUPPORTED_FILTERS \
2083 (FIF_PROMISC_IN_BSS | \
2088 FIF_BCN_PRBRESP_PROMISC | \
2092 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
2093 unsigned int changed_flags
,
2094 unsigned int *total_flags
,
2097 struct ath10k
*ar
= hw
->priv
;
2100 mutex_lock(&ar
->conf_mutex
);
2102 changed_flags
&= SUPPORTED_FILTERS
;
2103 *total_flags
&= SUPPORTED_FILTERS
;
2104 ar
->filter_flags
= *total_flags
;
2106 if ((ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2107 !ar
->monitor_enabled
) {
2108 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
2110 ath10k_warn("Unable to start monitor mode\n");
2112 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor mode started\n");
2113 } else if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2114 ar
->monitor_enabled
) {
2115 ret
= ath10k_monitor_stop(ar
);
2117 ath10k_warn("Unable to stop monitor mode\n");
2119 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor mode stopped\n");
2122 mutex_unlock(&ar
->conf_mutex
);
2125 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
2126 struct ieee80211_vif
*vif
,
2127 struct ieee80211_bss_conf
*info
,
2130 struct ath10k
*ar
= hw
->priv
;
2131 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2134 mutex_lock(&ar
->conf_mutex
);
2136 if (changed
& BSS_CHANGED_IBSS
)
2137 ath10k_control_ibss(arvif
, info
, vif
->addr
);
2139 if (changed
& BSS_CHANGED_BEACON_INT
) {
2140 arvif
->beacon_interval
= info
->beacon_int
;
2141 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2142 WMI_VDEV_PARAM_BEACON_INTERVAL
,
2143 arvif
->beacon_interval
);
2145 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2148 ath10k_dbg(ATH10K_DBG_MAC
,
2149 "Beacon interval: %d set for VDEV: %d\n",
2150 arvif
->beacon_interval
, arvif
->vdev_id
);
2153 if (changed
& BSS_CHANGED_BEACON
) {
2154 ret
= ath10k_wmi_pdev_set_param(ar
,
2155 WMI_PDEV_PARAM_BEACON_TX_MODE
,
2156 WMI_BEACON_STAGGERED_MODE
);
2158 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2161 ath10k_dbg(ATH10K_DBG_MAC
,
2162 "Set staggered beacon mode for VDEV: %d\n",
2166 if (changed
& BSS_CHANGED_BEACON_INFO
) {
2167 arvif
->dtim_period
= info
->dtim_period
;
2169 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2170 WMI_VDEV_PARAM_DTIM_PERIOD
,
2171 arvif
->dtim_period
);
2173 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2176 ath10k_dbg(ATH10K_DBG_MAC
,
2177 "Set dtim period: %d for VDEV: %d\n",
2178 arvif
->dtim_period
, arvif
->vdev_id
);
2181 if (changed
& BSS_CHANGED_SSID
&&
2182 vif
->type
== NL80211_IFTYPE_AP
) {
2183 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
2185 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
2186 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
2189 if (changed
& BSS_CHANGED_BSSID
) {
2190 if (!is_zero_ether_addr(info
->bssid
)) {
2191 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
2194 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2195 info
->bssid
, arvif
->vdev_id
);
2197 ath10k_dbg(ATH10K_DBG_MAC
,
2198 "Added peer: %pM for VDEV: %d\n",
2199 info
->bssid
, arvif
->vdev_id
);
2202 if (vif
->type
== NL80211_IFTYPE_STATION
) {
2204 * this is never erased as we it for crypto key
2205 * clearing; this is FW requirement
2207 memcpy(arvif
->u
.sta
.bssid
, info
->bssid
,
2210 ret
= ath10k_vdev_start(arvif
);
2212 ath10k_dbg(ATH10K_DBG_MAC
,
2213 "VDEV: %d started with BSSID: %pM\n",
2214 arvif
->vdev_id
, info
->bssid
);
2218 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2219 * so driver need to store it. It is needed when leaving
2220 * IBSS in order to remove BSSID peer.
2222 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
2223 memcpy(arvif
->u
.ibss
.bssid
, info
->bssid
,
2228 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
2229 ath10k_control_beaconing(arvif
, info
);
2231 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
2233 if (info
->use_cts_prot
)
2238 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2239 WMI_VDEV_PARAM_ENABLE_RTSCTS
,
2242 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2245 ath10k_dbg(ATH10K_DBG_MAC
,
2246 "Set CTS prot: %d for VDEV: %d\n",
2247 cts_prot
, arvif
->vdev_id
);
2250 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2252 if (info
->use_short_slot
)
2253 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
2256 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
2258 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2259 WMI_VDEV_PARAM_SLOT_TIME
,
2262 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2265 ath10k_dbg(ATH10K_DBG_MAC
,
2266 "Set slottime: %d for VDEV: %d\n",
2267 slottime
, arvif
->vdev_id
);
2270 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
2272 if (info
->use_short_preamble
)
2273 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
2275 preamble
= WMI_VDEV_PREAMBLE_LONG
;
2277 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2278 WMI_VDEV_PARAM_PREAMBLE
,
2281 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2284 ath10k_dbg(ATH10K_DBG_MAC
,
2285 "Set preamble: %d for VDEV: %d\n",
2286 preamble
, arvif
->vdev_id
);
2289 if (changed
& BSS_CHANGED_ASSOC
) {
2291 ath10k_bss_assoc(hw
, vif
, info
);
2294 mutex_unlock(&ar
->conf_mutex
);
2297 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
2298 struct ieee80211_vif
*vif
,
2299 struct cfg80211_scan_request
*req
)
2301 struct ath10k
*ar
= hw
->priv
;
2302 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2303 struct wmi_start_scan_arg arg
;
2307 mutex_lock(&ar
->conf_mutex
);
2309 spin_lock_bh(&ar
->data_lock
);
2310 if (ar
->scan
.in_progress
) {
2311 spin_unlock_bh(&ar
->data_lock
);
2316 INIT_COMPLETION(ar
->scan
.started
);
2317 INIT_COMPLETION(ar
->scan
.completed
);
2318 ar
->scan
.in_progress
= true;
2319 ar
->scan
.aborting
= false;
2320 ar
->scan
.is_roc
= false;
2321 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2322 spin_unlock_bh(&ar
->data_lock
);
2324 memset(&arg
, 0, sizeof(arg
));
2325 ath10k_wmi_start_scan_init(ar
, &arg
);
2326 arg
.vdev_id
= arvif
->vdev_id
;
2327 arg
.scan_id
= ATH10K_SCAN_ID
;
2330 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
2333 arg
.ie_len
= req
->ie_len
;
2334 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
2338 arg
.n_ssids
= req
->n_ssids
;
2339 for (i
= 0; i
< arg
.n_ssids
; i
++) {
2340 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
2341 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
2344 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2347 if (req
->n_channels
) {
2348 arg
.n_channels
= req
->n_channels
;
2349 for (i
= 0; i
< arg
.n_channels
; i
++)
2350 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
2353 ret
= ath10k_start_scan(ar
, &arg
);
2355 ath10k_warn("could not start hw scan (%d)\n", ret
);
2356 spin_lock_bh(&ar
->data_lock
);
2357 ar
->scan
.in_progress
= false;
2358 spin_unlock_bh(&ar
->data_lock
);
2362 mutex_unlock(&ar
->conf_mutex
);
2366 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
2367 struct ieee80211_vif
*vif
)
2369 struct ath10k
*ar
= hw
->priv
;
2372 mutex_lock(&ar
->conf_mutex
);
2373 ret
= ath10k_abort_scan(ar
);
2375 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2377 ieee80211_scan_completed(hw
, 1 /* aborted */);
2379 mutex_unlock(&ar
->conf_mutex
);
2382 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2383 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
2384 struct ieee80211_key_conf
*key
)
2386 struct ath10k
*ar
= hw
->priv
;
2387 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2388 struct ath10k_peer
*peer
;
2389 const u8
*peer_addr
;
2390 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2391 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
2394 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
2397 mutex_lock(&ar
->conf_mutex
);
2400 peer_addr
= sta
->addr
;
2401 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
2402 peer_addr
= vif
->bss_conf
.bssid
;
2404 peer_addr
= vif
->addr
;
2406 key
->hw_key_idx
= key
->keyidx
;
2408 /* the peer should not disappear in mid-way (unless FW goes awry) since
2409 * we already hold conf_mutex. we just make sure its there now. */
2410 spin_lock_bh(&ar
->data_lock
);
2411 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2412 spin_unlock_bh(&ar
->data_lock
);
2415 if (cmd
== SET_KEY
) {
2416 ath10k_warn("cannot install key for non-existent peer %pM\n",
2421 /* if the peer doesn't exist there is no key to disable
2429 arvif
->wep_keys
[key
->keyidx
] = key
;
2431 arvif
->wep_keys
[key
->keyidx
] = NULL
;
2433 if (cmd
== DISABLE_KEY
)
2434 ath10k_clear_vdev_key(arvif
, key
);
2437 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
2439 ath10k_warn("ath10k_install_key failed (%d)\n", ret
);
2443 spin_lock_bh(&ar
->data_lock
);
2444 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2445 if (peer
&& cmd
== SET_KEY
)
2446 peer
->keys
[key
->keyidx
] = key
;
2447 else if (peer
&& cmd
== DISABLE_KEY
)
2448 peer
->keys
[key
->keyidx
] = NULL
;
2449 else if (peer
== NULL
)
2450 /* impossible unless FW goes crazy */
2451 ath10k_warn("peer %pM disappeared!\n", peer_addr
);
2452 spin_unlock_bh(&ar
->data_lock
);
2455 mutex_unlock(&ar
->conf_mutex
);
2459 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
2460 struct ieee80211_vif
*vif
,
2461 struct ieee80211_sta
*sta
,
2462 enum ieee80211_sta_state old_state
,
2463 enum ieee80211_sta_state new_state
)
2465 struct ath10k
*ar
= hw
->priv
;
2466 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2469 mutex_lock(&ar
->conf_mutex
);
2471 if (old_state
== IEEE80211_STA_NOTEXIST
&&
2472 new_state
== IEEE80211_STA_NONE
&&
2473 vif
->type
!= NL80211_IFTYPE_STATION
) {
2475 * New station addition.
2477 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
2479 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2480 sta
->addr
, arvif
->vdev_id
);
2482 ath10k_dbg(ATH10K_DBG_MAC
,
2483 "Added peer: %pM for VDEV: %d\n",
2484 sta
->addr
, arvif
->vdev_id
);
2485 } else if ((old_state
== IEEE80211_STA_NONE
&&
2486 new_state
== IEEE80211_STA_NOTEXIST
)) {
2488 * Existing station deletion.
2490 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
2492 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2493 sta
->addr
, arvif
->vdev_id
);
2495 ath10k_dbg(ATH10K_DBG_MAC
,
2496 "Removed peer: %pM for VDEV: %d\n",
2497 sta
->addr
, arvif
->vdev_id
);
2499 if (vif
->type
== NL80211_IFTYPE_STATION
)
2500 ath10k_bss_disassoc(hw
, vif
);
2501 } else if (old_state
== IEEE80211_STA_AUTH
&&
2502 new_state
== IEEE80211_STA_ASSOC
&&
2503 (vif
->type
== NL80211_IFTYPE_AP
||
2504 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2508 ret
= ath10k_station_assoc(ar
, arvif
, sta
);
2510 ath10k_warn("Failed to associate station: %pM\n",
2513 ath10k_dbg(ATH10K_DBG_MAC
,
2514 "Station %pM moved to assoc state\n",
2516 } else if (old_state
== IEEE80211_STA_ASSOC
&&
2517 new_state
== IEEE80211_STA_AUTH
&&
2518 (vif
->type
== NL80211_IFTYPE_AP
||
2519 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2523 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
2525 ath10k_warn("Failed to disassociate station: %pM\n",
2528 ath10k_dbg(ATH10K_DBG_MAC
,
2529 "Station %pM moved to disassociated state\n",
2533 mutex_unlock(&ar
->conf_mutex
);
2537 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
2538 u16 ac
, bool enable
)
2540 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2544 lockdep_assert_held(&ar
->conf_mutex
);
2546 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
2550 case IEEE80211_AC_VO
:
2551 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
2552 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
2554 case IEEE80211_AC_VI
:
2555 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
2556 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
2558 case IEEE80211_AC_BE
:
2559 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
2560 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
2562 case IEEE80211_AC_BK
:
2563 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
2564 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
2569 arvif
->u
.sta
.uapsd
|= value
;
2571 arvif
->u
.sta
.uapsd
&= ~value
;
2573 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2574 WMI_STA_PS_PARAM_UAPSD
,
2575 arvif
->u
.sta
.uapsd
);
2577 ath10k_warn("could not set uapsd params %d\n", ret
);
2581 if (arvif
->u
.sta
.uapsd
)
2582 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
2584 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2586 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2587 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
2590 ath10k_warn("could not set rx wake param %d\n", ret
);
2596 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
2597 struct ieee80211_vif
*vif
, u16 ac
,
2598 const struct ieee80211_tx_queue_params
*params
)
2600 struct ath10k
*ar
= hw
->priv
;
2601 struct wmi_wmm_params_arg
*p
= NULL
;
2604 mutex_lock(&ar
->conf_mutex
);
2607 case IEEE80211_AC_VO
:
2608 p
= &ar
->wmm_params
.ac_vo
;
2610 case IEEE80211_AC_VI
:
2611 p
= &ar
->wmm_params
.ac_vi
;
2613 case IEEE80211_AC_BE
:
2614 p
= &ar
->wmm_params
.ac_be
;
2616 case IEEE80211_AC_BK
:
2617 p
= &ar
->wmm_params
.ac_bk
;
2626 p
->cwmin
= params
->cw_min
;
2627 p
->cwmax
= params
->cw_max
;
2628 p
->aifs
= params
->aifs
;
2631 * The channel time duration programmed in the HW is in absolute
2632 * microseconds, while mac80211 gives the txop in units of
2635 p
->txop
= params
->txop
* 32;
2637 /* FIXME: FW accepts wmm params per hw, not per vif */
2638 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
2640 ath10k_warn("could not set wmm params %d\n", ret
);
2644 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
2646 ath10k_warn("could not set sta uapsd %d\n", ret
);
2649 mutex_unlock(&ar
->conf_mutex
);
2653 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2655 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
2656 struct ieee80211_vif
*vif
,
2657 struct ieee80211_channel
*chan
,
2659 enum ieee80211_roc_type type
)
2661 struct ath10k
*ar
= hw
->priv
;
2662 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2663 struct wmi_start_scan_arg arg
;
2666 mutex_lock(&ar
->conf_mutex
);
2668 spin_lock_bh(&ar
->data_lock
);
2669 if (ar
->scan
.in_progress
) {
2670 spin_unlock_bh(&ar
->data_lock
);
2675 INIT_COMPLETION(ar
->scan
.started
);
2676 INIT_COMPLETION(ar
->scan
.completed
);
2677 INIT_COMPLETION(ar
->scan
.on_channel
);
2678 ar
->scan
.in_progress
= true;
2679 ar
->scan
.aborting
= false;
2680 ar
->scan
.is_roc
= true;
2681 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2682 ar
->scan
.roc_freq
= chan
->center_freq
;
2683 spin_unlock_bh(&ar
->data_lock
);
2685 memset(&arg
, 0, sizeof(arg
));
2686 ath10k_wmi_start_scan_init(ar
, &arg
);
2687 arg
.vdev_id
= arvif
->vdev_id
;
2688 arg
.scan_id
= ATH10K_SCAN_ID
;
2690 arg
.channels
[0] = chan
->center_freq
;
2691 arg
.dwell_time_active
= duration
;
2692 arg
.dwell_time_passive
= duration
;
2693 arg
.max_scan_time
= 2 * duration
;
2694 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2695 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
2697 ret
= ath10k_start_scan(ar
, &arg
);
2699 ath10k_warn("could not start roc scan (%d)\n", ret
);
2700 spin_lock_bh(&ar
->data_lock
);
2701 ar
->scan
.in_progress
= false;
2702 spin_unlock_bh(&ar
->data_lock
);
2706 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
2708 ath10k_warn("could not switch to channel for roc scan\n");
2709 ath10k_abort_scan(ar
);
2716 mutex_unlock(&ar
->conf_mutex
);
2720 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
2722 struct ath10k
*ar
= hw
->priv
;
2724 mutex_lock(&ar
->conf_mutex
);
2725 ath10k_abort_scan(ar
);
2726 mutex_unlock(&ar
->conf_mutex
);
2732 * Both RTS and Fragmentation threshold are interface-specific
2733 * in ath10k, but device-specific in mac80211.
2735 static void ath10k_set_rts_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
2737 struct ath10k_generic_iter
*ar_iter
= data
;
2738 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2739 u32 rts
= ar_iter
->ar
->hw
->wiphy
->rts_threshold
;
2741 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
2743 /* During HW reconfiguration mac80211 reports all interfaces that were
2744 * running until reconfiguration was started. Since FW doesn't have any
2745 * vdevs at this point we must not iterate over this interface list.
2746 * This setting will be updated upon add_interface(). */
2747 if (ar_iter
->ar
->state
== ATH10K_STATE_RESTARTED
)
2750 ar_iter
->ret
= ath10k_mac_set_rts(arvif
, rts
);
2752 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2755 ath10k_dbg(ATH10K_DBG_MAC
,
2756 "Set RTS threshold: %d for VDEV: %d\n",
2757 rts
, arvif
->vdev_id
);
2760 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
2762 struct ath10k_generic_iter ar_iter
;
2763 struct ath10k
*ar
= hw
->priv
;
2765 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
2768 mutex_lock(&ar
->conf_mutex
);
2769 ieee80211_iterate_active_interfaces_atomic(
2770 hw
, IEEE80211_IFACE_ITER_NORMAL
,
2771 ath10k_set_rts_iter
, &ar_iter
);
2772 mutex_unlock(&ar
->conf_mutex
);
2777 static void ath10k_set_frag_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
2779 struct ath10k_generic_iter
*ar_iter
= data
;
2780 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2781 u32 frag
= ar_iter
->ar
->hw
->wiphy
->frag_threshold
;
2783 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
2785 /* During HW reconfiguration mac80211 reports all interfaces that were
2786 * running until reconfiguration was started. Since FW doesn't have any
2787 * vdevs at this point we must not iterate over this interface list.
2788 * This setting will be updated upon add_interface(). */
2789 if (ar_iter
->ar
->state
== ATH10K_STATE_RESTARTED
)
2792 ar_iter
->ret
= ath10k_mac_set_frag(arvif
, frag
);
2794 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2797 ath10k_dbg(ATH10K_DBG_MAC
,
2798 "Set frag threshold: %d for VDEV: %d\n",
2799 frag
, arvif
->vdev_id
);
2802 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
2804 struct ath10k_generic_iter ar_iter
;
2805 struct ath10k
*ar
= hw
->priv
;
2807 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
2810 mutex_lock(&ar
->conf_mutex
);
2811 ieee80211_iterate_active_interfaces_atomic(
2812 hw
, IEEE80211_IFACE_ITER_NORMAL
,
2813 ath10k_set_frag_iter
, &ar_iter
);
2814 mutex_unlock(&ar
->conf_mutex
);
2819 static void ath10k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
2821 struct ath10k
*ar
= hw
->priv
;
2825 /* mac80211 doesn't care if we really xmit queued frames or not
2826 * we'll collect those frames either way if we stop/delete vdevs */
2830 mutex_lock(&ar
->conf_mutex
);
2832 if (ar
->state
== ATH10K_STATE_WEDGED
)
2835 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
2838 spin_lock_bh(&ar
->htt
.tx_lock
);
2839 empty
= bitmap_empty(ar
->htt
.used_msdu_ids
,
2840 ar
->htt
.max_num_pending_tx
);
2841 spin_unlock_bh(&ar
->htt
.tx_lock
);
2843 skip
= (ar
->state
== ATH10K_STATE_WEDGED
);
2846 }), ATH10K_FLUSH_TIMEOUT_HZ
);
2848 if (ret
<= 0 || skip
)
2849 ath10k_warn("tx not flushed\n");
2852 mutex_unlock(&ar
->conf_mutex
);
2855 /* TODO: Implement this function properly
2856 * For now it is needed to reply to Probe Requests in IBSS mode.
2857 * Propably we need this information from FW.
2859 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
2865 static int ath10k_suspend(struct ieee80211_hw
*hw
,
2866 struct cfg80211_wowlan
*wowlan
)
2868 struct ath10k
*ar
= hw
->priv
;
2871 ar
->is_target_paused
= false;
2873 ret
= ath10k_wmi_pdev_suspend_target(ar
);
2875 ath10k_warn("could not suspend target (%d)\n", ret
);
2879 ret
= wait_event_interruptible_timeout(ar
->event_queue
,
2880 ar
->is_target_paused
== true,
2883 ath10k_warn("suspend interrupted (%d)\n", ret
);
2885 } else if (ret
== 0) {
2886 ath10k_warn("suspend timed out - target pause event never came\n");
2890 ret
= ath10k_hif_suspend(ar
);
2892 ath10k_warn("could not suspend hif (%d)\n", ret
);
2898 ret
= ath10k_wmi_pdev_resume_target(ar
);
2900 ath10k_warn("could not resume target (%d)\n", ret
);
2904 static int ath10k_resume(struct ieee80211_hw
*hw
)
2906 struct ath10k
*ar
= hw
->priv
;
2909 ret
= ath10k_hif_resume(ar
);
2911 ath10k_warn("could not resume hif (%d)\n", ret
);
2915 ret
= ath10k_wmi_pdev_resume_target(ar
);
2917 ath10k_warn("could not resume target (%d)\n", ret
);
2925 static void ath10k_restart_complete(struct ieee80211_hw
*hw
)
2927 struct ath10k
*ar
= hw
->priv
;
2929 mutex_lock(&ar
->conf_mutex
);
2931 /* If device failed to restart it will be in a different state, e.g.
2932 * ATH10K_STATE_WEDGED */
2933 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
2934 ath10k_info("device successfully recovered\n");
2935 ar
->state
= ATH10K_STATE_ON
;
2938 mutex_unlock(&ar
->conf_mutex
);
2941 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
2942 struct survey_info
*survey
)
2944 struct ath10k
*ar
= hw
->priv
;
2945 struct ieee80211_supported_band
*sband
;
2946 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
2949 mutex_lock(&ar
->conf_mutex
);
2951 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
2952 if (sband
&& idx
>= sband
->n_channels
) {
2953 idx
-= sband
->n_channels
;
2958 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
2960 if (!sband
|| idx
>= sband
->n_channels
) {
2965 spin_lock_bh(&ar
->data_lock
);
2966 memcpy(survey
, ar_survey
, sizeof(*survey
));
2967 spin_unlock_bh(&ar
->data_lock
);
2969 survey
->channel
= &sband
->channels
[idx
];
2972 mutex_unlock(&ar
->conf_mutex
);
2976 static const struct ieee80211_ops ath10k_ops
= {
2978 .start
= ath10k_start
,
2979 .stop
= ath10k_stop
,
2980 .config
= ath10k_config
,
2981 .add_interface
= ath10k_add_interface
,
2982 .remove_interface
= ath10k_remove_interface
,
2983 .configure_filter
= ath10k_configure_filter
,
2984 .bss_info_changed
= ath10k_bss_info_changed
,
2985 .hw_scan
= ath10k_hw_scan
,
2986 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
2987 .set_key
= ath10k_set_key
,
2988 .sta_state
= ath10k_sta_state
,
2989 .conf_tx
= ath10k_conf_tx
,
2990 .remain_on_channel
= ath10k_remain_on_channel
,
2991 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
2992 .set_rts_threshold
= ath10k_set_rts_threshold
,
2993 .set_frag_threshold
= ath10k_set_frag_threshold
,
2994 .flush
= ath10k_flush
,
2995 .tx_last_beacon
= ath10k_tx_last_beacon
,
2996 .restart_complete
= ath10k_restart_complete
,
2997 .get_survey
= ath10k_get_survey
,
2999 .suspend
= ath10k_suspend
,
3000 .resume
= ath10k_resume
,
3004 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3005 .bitrate = (_rate), \
3006 .flags = (_flags), \
3007 .hw_value = (_rateid), \
3010 #define CHAN2G(_channel, _freq, _flags) { \
3011 .band = IEEE80211_BAND_2GHZ, \
3012 .hw_value = (_channel), \
3013 .center_freq = (_freq), \
3014 .flags = (_flags), \
3015 .max_antenna_gain = 0, \
3019 #define CHAN5G(_channel, _freq, _flags) { \
3020 .band = IEEE80211_BAND_5GHZ, \
3021 .hw_value = (_channel), \
3022 .center_freq = (_freq), \
3023 .flags = (_flags), \
3024 .max_antenna_gain = 0, \
3028 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
3038 CHAN2G(10, 2457, 0),
3039 CHAN2G(11, 2462, 0),
3040 CHAN2G(12, 2467, 0),
3041 CHAN2G(13, 2472, 0),
3042 CHAN2G(14, 2484, 0),
3045 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
3046 CHAN5G(36, 5180, 0),
3047 CHAN5G(40, 5200, 0),
3048 CHAN5G(44, 5220, 0),
3049 CHAN5G(48, 5240, 0),
3050 CHAN5G(52, 5260, 0),
3051 CHAN5G(56, 5280, 0),
3052 CHAN5G(60, 5300, 0),
3053 CHAN5G(64, 5320, 0),
3054 CHAN5G(100, 5500, 0),
3055 CHAN5G(104, 5520, 0),
3056 CHAN5G(108, 5540, 0),
3057 CHAN5G(112, 5560, 0),
3058 CHAN5G(116, 5580, 0),
3059 CHAN5G(120, 5600, 0),
3060 CHAN5G(124, 5620, 0),
3061 CHAN5G(128, 5640, 0),
3062 CHAN5G(132, 5660, 0),
3063 CHAN5G(136, 5680, 0),
3064 CHAN5G(140, 5700, 0),
3065 CHAN5G(149, 5745, 0),
3066 CHAN5G(153, 5765, 0),
3067 CHAN5G(157, 5785, 0),
3068 CHAN5G(161, 5805, 0),
3069 CHAN5G(165, 5825, 0),
3072 static struct ieee80211_rate ath10k_rates
[] = {
3074 RATETAB_ENT(10, 0x82, 0),
3075 RATETAB_ENT(20, 0x84, 0),
3076 RATETAB_ENT(55, 0x8b, 0),
3077 RATETAB_ENT(110, 0x96, 0),
3079 RATETAB_ENT(60, 0x0c, 0),
3080 RATETAB_ENT(90, 0x12, 0),
3081 RATETAB_ENT(120, 0x18, 0),
3082 RATETAB_ENT(180, 0x24, 0),
3083 RATETAB_ENT(240, 0x30, 0),
3084 RATETAB_ENT(360, 0x48, 0),
3085 RATETAB_ENT(480, 0x60, 0),
3086 RATETAB_ENT(540, 0x6c, 0),
3089 #define ath10k_a_rates (ath10k_rates + 4)
3090 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3091 #define ath10k_g_rates (ath10k_rates + 0)
3092 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3094 struct ath10k
*ath10k_mac_create(void)
3096 struct ieee80211_hw
*hw
;
3099 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
), &ath10k_ops
);
3109 void ath10k_mac_destroy(struct ath10k
*ar
)
3111 ieee80211_free_hw(ar
->hw
);
3114 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
3117 .types
= BIT(NL80211_IFTYPE_STATION
)
3118 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
3122 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
3126 .types
= BIT(NL80211_IFTYPE_AP
)
3130 static const struct ieee80211_iface_combination ath10k_if_comb
= {
3131 .limits
= ath10k_if_limits
,
3132 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
3133 .max_interfaces
= 8,
3134 .num_different_channels
= 1,
3135 .beacon_int_infra_match
= true,
3138 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
3140 struct ieee80211_sta_vht_cap vht_cap
= {0};
3144 vht_cap
.vht_supported
= 1;
3145 vht_cap
.cap
= ar
->vht_cap_info
;
3148 for (i
= 0; i
< 8; i
++) {
3149 if (i
< ar
->num_rf_chains
)
3150 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
3152 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
3155 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
3156 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
3161 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
3164 struct ieee80211_sta_ht_cap ht_cap
= {0};
3166 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
3169 ht_cap
.ht_supported
= 1;
3170 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
3171 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
3172 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
3173 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
3174 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
3176 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
3177 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
3179 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
3180 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
3182 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
3185 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
3186 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
3191 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
3192 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
3194 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
3197 stbc
= ar
->ht_cap_info
;
3198 stbc
&= WMI_HT_CAP_RX_STBC
;
3199 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
3200 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
3201 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
3206 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
3207 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
3209 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
3210 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
3212 /* max AMSDU is implicitly taken from vht_cap_info */
3213 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
3214 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
3216 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3217 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
3219 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
3225 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
3226 struct ieee80211_vif
*vif
)
3228 struct ath10k_vif_iter
*arvif_iter
= data
;
3229 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3231 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
3232 arvif_iter
->arvif
= arvif
;
3235 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
3237 struct ath10k_vif_iter arvif_iter
;
3240 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
3241 arvif_iter
.vdev_id
= vdev_id
;
3243 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
3244 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3246 ath10k_get_arvif_iter
,
3248 if (!arvif_iter
.arvif
) {
3249 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id
);
3253 return arvif_iter
.arvif
;
3256 int ath10k_mac_register(struct ath10k
*ar
)
3258 struct ieee80211_supported_band
*band
;
3259 struct ieee80211_sta_vht_cap vht_cap
;
3260 struct ieee80211_sta_ht_cap ht_cap
;
3264 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
3266 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
3268 ht_cap
= ath10k_get_ht_cap(ar
);
3269 vht_cap
= ath10k_create_vht_cap(ar
);
3271 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
3272 channels
= kmemdup(ath10k_2ghz_channels
,
3273 sizeof(ath10k_2ghz_channels
),
3280 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
3281 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
3282 band
->channels
= channels
;
3283 band
->n_bitrates
= ath10k_g_rates_size
;
3284 band
->bitrates
= ath10k_g_rates
;
3285 band
->ht_cap
= ht_cap
;
3287 /* vht is not supported in 2.4 GHz */
3289 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
3292 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
3293 channels
= kmemdup(ath10k_5ghz_channels
,
3294 sizeof(ath10k_5ghz_channels
),
3301 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
3302 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
3303 band
->channels
= channels
;
3304 band
->n_bitrates
= ath10k_a_rates_size
;
3305 band
->bitrates
= ath10k_a_rates
;
3306 band
->ht_cap
= ht_cap
;
3307 band
->vht_cap
= vht_cap
;
3308 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
3311 ar
->hw
->wiphy
->interface_modes
=
3312 BIT(NL80211_IFTYPE_STATION
) |
3313 BIT(NL80211_IFTYPE_ADHOC
) |
3314 BIT(NL80211_IFTYPE_AP
) |
3315 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
3316 BIT(NL80211_IFTYPE_P2P_GO
);
3318 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
3319 IEEE80211_HW_SUPPORTS_PS
|
3320 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
3321 IEEE80211_HW_SUPPORTS_UAPSD
|
3322 IEEE80211_HW_MFP_CAPABLE
|
3323 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
3324 IEEE80211_HW_HAS_RATE_CONTROL
|
3325 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
3326 IEEE80211_HW_WANT_MONITOR_VIF
|
3327 IEEE80211_HW_AP_LINK_PS
;
3329 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
3330 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
3332 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
3333 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
3334 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
3337 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
3338 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
3340 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
3342 ar
->hw
->channel_change_time
= 5000;
3343 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
3345 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
3346 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
3348 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
3350 * on LL hardware queues are managed entirely by the FW
3351 * so we only advertise to mac we can do the queues thing
3355 ar
->hw
->wiphy
->iface_combinations
= &ath10k_if_comb
;
3356 ar
->hw
->wiphy
->n_iface_combinations
= 1;
3358 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
3360 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
3361 ath10k_reg_notifier
);
3363 ath10k_err("Regulatory initialization failed\n");
3367 ret
= ieee80211_register_hw(ar
->hw
);
3369 ath10k_err("ieee80211 registration failed: %d\n", ret
);
3373 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
3374 ret
= regulatory_hint(ar
->hw
->wiphy
,
3375 ar
->ath_common
.regulatory
.alpha2
);
3377 goto err_unregister
;
3383 ieee80211_unregister_hw(ar
->hw
);
3385 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
3386 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
3391 void ath10k_mac_unregister(struct ath10k
*ar
)
3393 ieee80211_unregister_hw(ar
->hw
);
3395 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
3396 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
3398 SET_IEEE80211_DEV(ar
->hw
, NULL
);