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 struct ath10k
*ar
= arvif
->ar
;
340 if (value
!= 0xFFFFFFFF)
341 value
= min_t(u32
, arvif
->ar
->hw
->wiphy
->rts_threshold
,
344 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
345 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
348 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
350 struct ath10k
*ar
= arvif
->ar
;
353 if (value
!= 0xFFFFFFFF)
354 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
355 ATH10K_FRAGMT_THRESHOLD_MIN
,
356 ATH10K_FRAGMT_THRESHOLD_MAX
);
358 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
359 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
362 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
366 lockdep_assert_held(&ar
->conf_mutex
);
368 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
372 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
379 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
381 struct ath10k_peer
*peer
, *tmp
;
383 lockdep_assert_held(&ar
->conf_mutex
);
385 spin_lock_bh(&ar
->data_lock
);
386 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
387 if (peer
->vdev_id
!= vdev_id
)
390 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
391 peer
->addr
, vdev_id
);
393 list_del(&peer
->list
);
396 spin_unlock_bh(&ar
->data_lock
);
399 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
401 struct ath10k_peer
*peer
, *tmp
;
403 lockdep_assert_held(&ar
->conf_mutex
);
405 spin_lock_bh(&ar
->data_lock
);
406 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
407 list_del(&peer
->list
);
410 spin_unlock_bh(&ar
->data_lock
);
413 /************************/
414 /* Interface management */
415 /************************/
417 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
421 lockdep_assert_held(&ar
->conf_mutex
);
423 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
424 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
431 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
433 struct ath10k
*ar
= arvif
->ar
;
434 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
435 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
436 struct wmi_vdev_start_request_arg arg
= {};
439 lockdep_assert_held(&ar
->conf_mutex
);
441 INIT_COMPLETION(ar
->vdev_setup_done
);
443 arg
.vdev_id
= arvif
->vdev_id
;
444 arg
.dtim_period
= arvif
->dtim_period
;
445 arg
.bcn_intval
= arvif
->beacon_interval
;
447 arg
.channel
.freq
= channel
->center_freq
;
449 arg
.channel
.band_center_freq1
= conf
->chandef
.center_freq1
;
451 arg
.channel
.mode
= chan_to_phymode(&conf
->chandef
);
453 arg
.channel
.min_power
= channel
->max_power
* 3;
454 arg
.channel
.max_power
= channel
->max_power
* 4;
455 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
456 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
458 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
459 arg
.ssid
= arvif
->u
.ap
.ssid
;
460 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
461 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
462 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
463 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
464 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
467 ath10k_dbg(ATH10K_DBG_MAC
,
468 "mac vdev %d start center_freq %d phymode %s\n",
469 arg
.vdev_id
, arg
.channel
.freq
,
470 ath10k_wmi_phymode_str(arg
.channel
.mode
));
472 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
474 ath10k_warn("WMI vdev start failed: ret %d\n", ret
);
478 ret
= ath10k_vdev_setup_sync(ar
);
480 ath10k_warn("vdev setup failed %d\n", ret
);
487 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
489 struct ath10k
*ar
= arvif
->ar
;
492 lockdep_assert_held(&ar
->conf_mutex
);
494 INIT_COMPLETION(ar
->vdev_setup_done
);
496 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
498 ath10k_warn("WMI vdev stop failed: ret %d\n", ret
);
502 ret
= ath10k_vdev_setup_sync(ar
);
504 ath10k_warn("vdev setup failed %d\n", ret
);
511 static int ath10k_monitor_start(struct ath10k
*ar
, int vdev_id
)
513 struct ieee80211_channel
*channel
= ar
->hw
->conf
.chandef
.chan
;
514 struct wmi_vdev_start_request_arg arg
= {};
517 lockdep_assert_held(&ar
->conf_mutex
);
519 arg
.vdev_id
= vdev_id
;
520 arg
.channel
.freq
= channel
->center_freq
;
521 arg
.channel
.band_center_freq1
= ar
->hw
->conf
.chandef
.center_freq1
;
523 /* TODO setup this dynamically, what in case we
524 don't have any vifs? */
525 arg
.channel
.mode
= chan_to_phymode(&ar
->hw
->conf
.chandef
);
527 arg
.channel
.min_power
= channel
->max_power
* 3;
528 arg
.channel
.max_power
= channel
->max_power
* 4;
529 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
530 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
532 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
534 ath10k_warn("Monitor vdev start failed: ret %d\n", ret
);
538 ret
= ath10k_vdev_setup_sync(ar
);
540 ath10k_warn("Monitor vdev setup failed %d\n", ret
);
544 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
546 ath10k_warn("Monitor vdev up failed: %d\n", ret
);
550 ar
->monitor_vdev_id
= vdev_id
;
551 ar
->monitor_enabled
= true;
556 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
558 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
563 static int ath10k_monitor_stop(struct ath10k
*ar
)
567 lockdep_assert_held(&ar
->conf_mutex
);
569 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
571 ath10k_warn("Monitor vdev down failed: %d\n", ret
);
573 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
575 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
577 ret
= ath10k_vdev_setup_sync(ar
);
579 ath10k_warn("Monitor_down sync failed: %d\n", ret
);
581 ar
->monitor_enabled
= false;
585 static int ath10k_monitor_create(struct ath10k
*ar
)
589 lockdep_assert_held(&ar
->conf_mutex
);
591 if (ar
->monitor_present
) {
592 ath10k_warn("Monitor mode already enabled\n");
596 bit
= ffs(ar
->free_vdev_map
);
598 ath10k_warn("No free VDEV slots\n");
602 ar
->monitor_vdev_id
= bit
- 1;
603 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
605 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
606 WMI_VDEV_TYPE_MONITOR
,
609 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret
);
613 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
614 ar
->monitor_vdev_id
);
616 ar
->monitor_present
= true;
621 * Restore the ID to the global map.
623 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
627 static int ath10k_monitor_destroy(struct ath10k
*ar
)
631 lockdep_assert_held(&ar
->conf_mutex
);
633 if (!ar
->monitor_present
)
636 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
638 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret
);
642 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
643 ar
->monitor_present
= false;
645 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
646 ar
->monitor_vdev_id
);
650 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
651 struct ieee80211_bss_conf
*info
)
655 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
657 if (!info
->enable_beacon
) {
658 ath10k_vdev_stop(arvif
);
662 arvif
->tx_seq_no
= 0x1000;
664 ret
= ath10k_vdev_start(arvif
);
668 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, 0, info
->bssid
);
670 ath10k_warn("Failed to bring up VDEV: %d\n",
674 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
677 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
678 struct ieee80211_bss_conf
*info
,
679 const u8 self_peer
[ETH_ALEN
])
684 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
686 if (!info
->ibss_joined
) {
687 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
689 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
690 self_peer
, arvif
->vdev_id
, ret
);
692 if (is_zero_ether_addr(arvif
->u
.ibss
.bssid
))
695 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
696 arvif
->u
.ibss
.bssid
);
698 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
699 arvif
->u
.ibss
.bssid
, arvif
->vdev_id
, ret
);
703 memset(arvif
->u
.ibss
.bssid
, 0, ETH_ALEN
);
708 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
710 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
711 self_peer
, arvif
->vdev_id
, ret
);
715 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
716 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
717 ATH10K_DEFAULT_ATIM
);
719 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
720 arvif
->vdev_id
, ret
);
724 * Review this when mac80211 gains per-interface powersave support.
726 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
728 struct ath10k
*ar
= arvif
->ar
;
729 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
730 enum wmi_sta_powersave_param param
;
731 enum wmi_sta_ps_mode psmode
;
734 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
736 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
739 if (conf
->flags
& IEEE80211_CONF_PS
) {
740 psmode
= WMI_STA_PS_MODE_ENABLED
;
741 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
743 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
744 conf
->dynamic_ps_timeout
);
746 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
751 psmode
= WMI_STA_PS_MODE_DISABLED
;
754 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
755 arvif
->vdev_id
, psmode
? "enable" : "disable");
757 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
759 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
760 psmode
, arvif
->vdev_id
);
767 /**********************/
768 /* Station management */
769 /**********************/
771 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
772 struct ath10k_vif
*arvif
,
773 struct ieee80211_sta
*sta
,
774 struct ieee80211_bss_conf
*bss_conf
,
775 struct wmi_peer_assoc_complete_arg
*arg
)
777 lockdep_assert_held(&ar
->conf_mutex
);
779 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
780 arg
->vdev_id
= arvif
->vdev_id
;
781 arg
->peer_aid
= sta
->aid
;
782 arg
->peer_flags
|= WMI_PEER_AUTH
;
784 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
786 * Seems FW have problems with Power Save in STA
787 * mode when we setup this parameter to high (eg. 5).
788 * Often we see that FW don't send NULL (with clean P flags)
789 * frame even there is info about buffered frames in beacons.
790 * Sometimes we have to wait more than 10 seconds before FW
791 * will wakeup. Often sending one ping from AP to our device
792 * just fail (more than 50%).
794 * Seems setting this FW parameter to 1 couse FW
795 * will check every beacon and will wakup immediately
796 * after detection buffered data.
798 arg
->peer_listen_intval
= 1;
800 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
802 arg
->peer_num_spatial_streams
= 1;
805 * The assoc capabilities are available only in managed mode.
807 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
808 arg
->peer_caps
= bss_conf
->assoc_capability
;
811 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
812 struct ath10k_vif
*arvif
,
813 struct wmi_peer_assoc_complete_arg
*arg
)
815 struct ieee80211_vif
*vif
= arvif
->vif
;
816 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
817 struct cfg80211_bss
*bss
;
818 const u8
*rsnie
= NULL
;
819 const u8
*wpaie
= NULL
;
821 lockdep_assert_held(&ar
->conf_mutex
);
823 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
824 info
->bssid
, NULL
, 0, 0, 0);
826 const struct cfg80211_bss_ies
*ies
;
829 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
831 ies
= rcu_dereference(bss
->ies
);
833 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
834 WLAN_OUI_TYPE_MICROSOFT_WPA
,
838 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
841 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
842 if (rsnie
|| wpaie
) {
843 ath10k_dbg(ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
844 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
848 ath10k_dbg(ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
849 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
853 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
854 struct ieee80211_sta
*sta
,
855 struct wmi_peer_assoc_complete_arg
*arg
)
857 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
858 const struct ieee80211_supported_band
*sband
;
859 const struct ieee80211_rate
*rates
;
863 lockdep_assert_held(&ar
->conf_mutex
);
865 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
866 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
867 rates
= sband
->bitrates
;
869 rateset
->num_rates
= 0;
871 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
875 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
876 rateset
->num_rates
++;
880 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
881 struct ieee80211_sta
*sta
,
882 struct wmi_peer_assoc_complete_arg
*arg
)
884 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
888 lockdep_assert_held(&ar
->conf_mutex
);
890 if (!ht_cap
->ht_supported
)
893 arg
->peer_flags
|= WMI_PEER_HT
;
894 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
895 ht_cap
->ampdu_factor
)) - 1;
897 arg
->peer_mpdu_density
=
898 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
900 arg
->peer_ht_caps
= ht_cap
->cap
;
901 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
903 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
904 arg
->peer_flags
|= WMI_PEER_LDPC
;
906 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
907 arg
->peer_flags
|= WMI_PEER_40MHZ
;
908 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
911 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
912 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
914 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
915 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
917 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
918 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
919 arg
->peer_flags
|= WMI_PEER_STBC
;
922 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
924 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
925 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
926 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
927 arg
->peer_rate_caps
|= stbc
;
928 arg
->peer_flags
|= WMI_PEER_STBC
;
931 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
932 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
934 if (smps
== WLAN_HT_CAP_SM_PS_STATIC
) {
935 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
936 arg
->peer_flags
|= WMI_PEER_STATIC_MIMOPS
;
937 } else if (smps
== WLAN_HT_CAP_SM_PS_DYNAMIC
) {
938 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
939 arg
->peer_flags
|= WMI_PEER_DYN_MIMOPS
;
942 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
943 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
944 else if (ht_cap
->mcs
.rx_mask
[1])
945 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
947 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
948 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
949 arg
->peer_ht_rates
.rates
[n
++] = i
;
951 arg
->peer_ht_rates
.num_rates
= n
;
952 arg
->peer_num_spatial_streams
= max((n
+7) / 8, 1);
954 ath10k_dbg(ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
956 arg
->peer_ht_rates
.num_rates
,
957 arg
->peer_num_spatial_streams
);
960 static void ath10k_peer_assoc_h_qos_ap(struct ath10k
*ar
,
961 struct ath10k_vif
*arvif
,
962 struct ieee80211_sta
*sta
,
963 struct ieee80211_bss_conf
*bss_conf
,
964 struct wmi_peer_assoc_complete_arg
*arg
)
969 lockdep_assert_held(&ar
->conf_mutex
);
972 arg
->peer_flags
|= WMI_PEER_QOS
;
974 if (sta
->wme
&& sta
->uapsd_queues
) {
975 ath10k_dbg(ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
976 sta
->uapsd_queues
, sta
->max_sp
);
978 arg
->peer_flags
|= WMI_PEER_APSD
;
979 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
981 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
982 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
983 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
984 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
985 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
986 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
987 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
988 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
989 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
990 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
991 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
992 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
995 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
996 max_sp
= sta
->max_sp
;
998 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1000 WMI_AP_PS_PEER_PARAM_UAPSD
,
1003 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1005 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1008 /* TODO setup this based on STA listen interval and
1009 beacon interval. Currently we don't know
1010 sta->listen_interval - mac80211 patch required.
1011 Currently use 10 seconds */
1012 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1014 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1019 static void ath10k_peer_assoc_h_qos_sta(struct ath10k
*ar
,
1020 struct ath10k_vif
*arvif
,
1021 struct ieee80211_sta
*sta
,
1022 struct ieee80211_bss_conf
*bss_conf
,
1023 struct wmi_peer_assoc_complete_arg
*arg
)
1026 arg
->peer_flags
|= WMI_PEER_QOS
;
1029 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1030 struct ieee80211_sta
*sta
,
1031 struct wmi_peer_assoc_complete_arg
*arg
)
1033 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1036 if (!vht_cap
->vht_supported
)
1039 arg
->peer_flags
|= WMI_PEER_VHT
;
1040 arg
->peer_vht_caps
= vht_cap
->cap
;
1043 ampdu_factor
= (vht_cap
->cap
&
1044 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1045 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1047 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1048 * zero in VHT IE. Using it would result in degraded throughput.
1049 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1050 * it if VHT max_mpdu is smaller. */
1051 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1052 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1053 ampdu_factor
)) - 1);
1055 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1056 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1058 arg
->peer_vht_rates
.rx_max_rate
=
1059 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1060 arg
->peer_vht_rates
.rx_mcs_set
=
1061 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1062 arg
->peer_vht_rates
.tx_max_rate
=
1063 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1064 arg
->peer_vht_rates
.tx_mcs_set
=
1065 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1067 ath10k_dbg(ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1068 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1071 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1072 struct ath10k_vif
*arvif
,
1073 struct ieee80211_sta
*sta
,
1074 struct ieee80211_bss_conf
*bss_conf
,
1075 struct wmi_peer_assoc_complete_arg
*arg
)
1077 switch (arvif
->vdev_type
) {
1078 case WMI_VDEV_TYPE_AP
:
1079 ath10k_peer_assoc_h_qos_ap(ar
, arvif
, sta
, bss_conf
, arg
);
1081 case WMI_VDEV_TYPE_STA
:
1082 ath10k_peer_assoc_h_qos_sta(ar
, arvif
, sta
, bss_conf
, arg
);
1089 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1090 struct ath10k_vif
*arvif
,
1091 struct ieee80211_sta
*sta
,
1092 struct wmi_peer_assoc_complete_arg
*arg
)
1094 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1096 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1097 case IEEE80211_BAND_2GHZ
:
1098 if (sta
->ht_cap
.ht_supported
) {
1099 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1100 phymode
= MODE_11NG_HT40
;
1102 phymode
= MODE_11NG_HT20
;
1108 case IEEE80211_BAND_5GHZ
:
1112 if (sta
->vht_cap
.vht_supported
) {
1113 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1114 phymode
= MODE_11AC_VHT80
;
1115 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1116 phymode
= MODE_11AC_VHT40
;
1117 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1118 phymode
= MODE_11AC_VHT20
;
1119 } else if (sta
->ht_cap
.ht_supported
) {
1120 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1121 phymode
= MODE_11NA_HT40
;
1123 phymode
= MODE_11NA_HT20
;
1133 ath10k_dbg(ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1134 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1136 arg
->peer_phymode
= phymode
;
1137 WARN_ON(phymode
== MODE_UNKNOWN
);
1140 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1141 struct ath10k_vif
*arvif
,
1142 struct ieee80211_sta
*sta
,
1143 struct ieee80211_bss_conf
*bss_conf
,
1144 struct wmi_peer_assoc_complete_arg
*arg
)
1146 lockdep_assert_held(&ar
->conf_mutex
);
1148 memset(arg
, 0, sizeof(*arg
));
1150 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, arg
);
1151 ath10k_peer_assoc_h_crypto(ar
, arvif
, arg
);
1152 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1153 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1154 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1155 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, arg
);
1156 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, arg
);
1161 /* can be called only in mac80211 callbacks due to `key_count` usage */
1162 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1163 struct ieee80211_vif
*vif
,
1164 struct ieee80211_bss_conf
*bss_conf
)
1166 struct ath10k
*ar
= hw
->priv
;
1167 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1168 struct wmi_peer_assoc_complete_arg peer_arg
;
1169 struct ieee80211_sta
*ap_sta
;
1172 lockdep_assert_held(&ar
->conf_mutex
);
1176 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1178 ath10k_warn("Failed to find station entry for %pM\n",
1184 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, ap_sta
,
1185 bss_conf
, &peer_arg
);
1187 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1188 bss_conf
->bssid
, ret
);
1195 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1197 ath10k_warn("Peer assoc failed for %pM\n: %d",
1198 bss_conf
->bssid
, ret
);
1202 ath10k_dbg(ATH10K_DBG_MAC
,
1203 "mac vdev %d up (associated) bssid %pM aid %d\n",
1204 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1206 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, bss_conf
->aid
,
1209 ath10k_warn("VDEV: %d up failed: ret %d\n",
1210 arvif
->vdev_id
, ret
);
1216 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1217 struct ieee80211_vif
*vif
)
1219 struct ath10k
*ar
= hw
->priv
;
1220 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1223 lockdep_assert_held(&ar
->conf_mutex
);
1226 * For some reason, calling VDEV-DOWN before VDEV-STOP
1227 * makes the FW to send frames via HTT after disassociation.
1228 * No idea why this happens, even though VDEV-DOWN is supposed
1229 * to be analogous to link down, so just stop the VDEV.
1231 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d stop (disassociated\n",
1234 /* FIXME: check return value */
1235 ret
= ath10k_vdev_stop(arvif
);
1238 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1239 * report beacons from previously associated network through HTT.
1240 * This in turn would spam mac80211 WARN_ON if we bring down all
1241 * interfaces as it expects there is no rx when no interface is
1244 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d down\n", arvif
->vdev_id
);
1246 /* FIXME: why don't we print error if wmi call fails? */
1247 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1249 arvif
->def_wep_key_idx
= 0;
1252 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1253 struct ieee80211_sta
*sta
)
1255 struct wmi_peer_assoc_complete_arg peer_arg
;
1258 lockdep_assert_held(&ar
->conf_mutex
);
1260 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, sta
, NULL
, &peer_arg
);
1262 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1267 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1269 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1274 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1276 ath10k_warn("could not install peer wep keys (%d)\n", ret
);
1283 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1284 struct ieee80211_sta
*sta
)
1288 lockdep_assert_held(&ar
->conf_mutex
);
1290 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1292 ath10k_warn("could not clear all peer wep keys (%d)\n", ret
);
1303 static int ath10k_update_channel_list(struct ath10k
*ar
)
1305 struct ieee80211_hw
*hw
= ar
->hw
;
1306 struct ieee80211_supported_band
**bands
;
1307 enum ieee80211_band band
;
1308 struct ieee80211_channel
*channel
;
1309 struct wmi_scan_chan_list_arg arg
= {0};
1310 struct wmi_channel_arg
*ch
;
1316 lockdep_assert_held(&ar
->conf_mutex
);
1318 bands
= hw
->wiphy
->bands
;
1319 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1323 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1324 if (bands
[band
]->channels
[i
].flags
&
1325 IEEE80211_CHAN_DISABLED
)
1332 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1333 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1338 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1342 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1343 channel
= &bands
[band
]->channels
[i
];
1345 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1348 ch
->allow_ht
= true;
1350 /* FIXME: when should we really allow VHT? */
1351 ch
->allow_vht
= true;
1354 !(channel
->flags
& IEEE80211_CHAN_NO_IBSS
);
1357 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1359 passive
= channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
;
1360 ch
->passive
= passive
;
1362 ch
->freq
= channel
->center_freq
;
1363 ch
->min_power
= channel
->max_power
* 3;
1364 ch
->max_power
= channel
->max_power
* 4;
1365 ch
->max_reg_power
= channel
->max_reg_power
* 4;
1366 ch
->max_antenna_gain
= channel
->max_antenna_gain
;
1367 ch
->reg_class_id
= 0; /* FIXME */
1369 /* FIXME: why use only legacy modes, why not any
1370 * HT/VHT modes? Would that even make any
1372 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1373 ch
->mode
= MODE_11G
;
1375 ch
->mode
= MODE_11A
;
1377 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1380 ath10k_dbg(ATH10K_DBG_WMI
,
1381 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1382 ch
- arg
.channels
, arg
.n_channels
,
1383 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1384 ch
->max_antenna_gain
, ch
->mode
);
1390 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1391 kfree(arg
.channels
);
1396 static void ath10k_regd_update(struct ath10k
*ar
)
1398 struct reg_dmn_pair_mapping
*regpair
;
1401 lockdep_assert_held(&ar
->conf_mutex
);
1403 ret
= ath10k_update_channel_list(ar
);
1405 ath10k_warn("could not update channel list (%d)\n", ret
);
1407 regpair
= ar
->ath_common
.regulatory
.regpair
;
1409 /* Target allows setting up per-band regdomain but ath_common provides
1410 * a combined one only */
1411 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1412 regpair
->regDmnEnum
,
1413 regpair
->regDmnEnum
, /* 2ghz */
1414 regpair
->regDmnEnum
, /* 5ghz */
1415 regpair
->reg_2ghz_ctl
,
1416 regpair
->reg_5ghz_ctl
);
1418 ath10k_warn("could not set pdev regdomain (%d)\n", ret
);
1421 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1422 struct regulatory_request
*request
)
1424 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1425 struct ath10k
*ar
= hw
->priv
;
1427 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1429 mutex_lock(&ar
->conf_mutex
);
1430 if (ar
->state
== ATH10K_STATE_ON
)
1431 ath10k_regd_update(ar
);
1432 mutex_unlock(&ar
->conf_mutex
);
1439 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
1441 if (ieee80211_is_mgmt(hdr
->frame_control
))
1442 return HTT_DATA_TX_EXT_TID_MGMT
;
1444 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1445 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1447 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
1448 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1450 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
1453 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
,
1454 struct ieee80211_tx_info
*info
)
1456 if (info
->control
.vif
)
1457 return ath10k_vif_to_arvif(info
->control
.vif
)->vdev_id
;
1459 if (ar
->monitor_enabled
)
1460 return ar
->monitor_vdev_id
;
1462 ath10k_warn("could not resolve vdev id\n");
1467 * Frames sent to the FW have to be in "Native Wifi" format.
1468 * Strip the QoS field from the 802.11 header.
1470 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw
*hw
,
1471 struct ieee80211_tx_control
*control
,
1472 struct sk_buff
*skb
)
1474 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1477 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1480 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1481 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
1482 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
1483 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
1486 static void ath10k_tx_wep_key_work(struct work_struct
*work
)
1488 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1490 int ret
, keyidx
= arvif
->def_wep_key_newidx
;
1492 if (arvif
->def_wep_key_idx
== keyidx
)
1495 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
1496 arvif
->vdev_id
, keyidx
);
1498 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
1500 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
1503 ath10k_warn("could not update wep keyidx (%d)\n", ret
);
1507 arvif
->def_wep_key_idx
= keyidx
;
1510 static void ath10k_tx_h_update_wep_key(struct sk_buff
*skb
)
1512 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1513 struct ieee80211_vif
*vif
= info
->control
.vif
;
1514 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1515 struct ath10k
*ar
= arvif
->ar
;
1516 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1517 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
1519 if (!ieee80211_has_protected(hdr
->frame_control
))
1525 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1526 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1529 if (key
->keyidx
== arvif
->def_wep_key_idx
)
1532 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1533 * queueing frames until key index is updated is not an option because
1534 * sk_buff may need more processing to be done, e.g. offchannel */
1535 arvif
->def_wep_key_newidx
= key
->keyidx
;
1536 ieee80211_queue_work(ar
->hw
, &arvif
->wep_key_work
);
1539 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
, struct sk_buff
*skb
)
1541 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1542 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1543 struct ieee80211_vif
*vif
= info
->control
.vif
;
1544 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1546 /* This is case only for P2P_GO */
1547 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1548 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1551 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1552 spin_lock_bh(&ar
->data_lock
);
1553 if (arvif
->u
.ap
.noa_data
)
1554 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1556 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1557 arvif
->u
.ap
.noa_data
,
1558 arvif
->u
.ap
.noa_len
);
1559 spin_unlock_bh(&ar
->data_lock
);
1563 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1565 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1568 if (ar
->htt
.target_version_major
>= 3) {
1569 /* Since HTT 3.0 there is no separate mgmt tx command */
1570 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1574 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
1575 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1577 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
1578 ATH10K_MAX_NUM_MGMT_PENDING
) {
1579 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1584 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
1585 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
1587 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1589 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1591 ieee80211_is_nullfunc(hdr
->frame_control
)) {
1592 /* FW does not report tx status properly for NullFunc frames
1593 * unless they are sent through mgmt tx path. mac80211 sends
1594 * those frames when it detects link/beacon loss and depends
1595 * on the tx status to be correct. */
1596 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1598 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1603 ath10k_warn("tx failed (%d). dropping packet.\n", ret
);
1604 ieee80211_free_txskb(ar
->hw
, skb
);
1608 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
1610 struct sk_buff
*skb
;
1613 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1617 ieee80211_free_txskb(ar
->hw
, skb
);
1621 void ath10k_offchan_tx_work(struct work_struct
*work
)
1623 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
1624 struct ath10k_peer
*peer
;
1625 struct ieee80211_hdr
*hdr
;
1626 struct sk_buff
*skb
;
1627 const u8
*peer_addr
;
1631 /* FW requirement: We must create a peer before FW will send out
1632 * an offchannel frame. Otherwise the frame will be stuck and
1633 * never transmitted. We delete the peer upon tx completion.
1634 * It is unlikely that a peer for offchannel tx will already be
1635 * present. However it may be in some rare cases so account for that.
1636 * Otherwise we might remove a legitimate peer and break stuff. */
1639 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1643 mutex_lock(&ar
->conf_mutex
);
1645 ath10k_dbg(ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
1648 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1649 peer_addr
= ieee80211_get_DA(hdr
);
1650 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
1652 spin_lock_bh(&ar
->data_lock
);
1653 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
1654 spin_unlock_bh(&ar
->data_lock
);
1657 /* FIXME: should this use ath10k_warn()? */
1658 ath10k_dbg(ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
1659 peer_addr
, vdev_id
);
1662 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
1664 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1665 peer_addr
, vdev_id
, ret
);
1668 spin_lock_bh(&ar
->data_lock
);
1669 INIT_COMPLETION(ar
->offchan_tx_completed
);
1670 ar
->offchan_tx_skb
= skb
;
1671 spin_unlock_bh(&ar
->data_lock
);
1673 ath10k_tx_htt(ar
, skb
);
1675 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
1678 ath10k_warn("timed out waiting for offchannel skb %p\n",
1682 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
1684 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1685 peer_addr
, vdev_id
, ret
);
1688 mutex_unlock(&ar
->conf_mutex
);
1692 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
1694 struct sk_buff
*skb
;
1697 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
1701 ieee80211_free_txskb(ar
->hw
, skb
);
1705 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
1707 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
1708 struct sk_buff
*skb
;
1712 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
1716 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
1718 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret
);
1727 * This gets called if we dont get a heart-beat during scan.
1728 * This may indicate the FW has hung and we need to abort the
1729 * scan manually to prevent cancel_hw_scan() from deadlocking
1731 void ath10k_reset_scan(unsigned long ptr
)
1733 struct ath10k
*ar
= (struct ath10k
*)ptr
;
1735 spin_lock_bh(&ar
->data_lock
);
1736 if (!ar
->scan
.in_progress
) {
1737 spin_unlock_bh(&ar
->data_lock
);
1741 ath10k_warn("scan timeout. resetting. fw issue?\n");
1743 if (ar
->scan
.is_roc
)
1744 ieee80211_remain_on_channel_expired(ar
->hw
);
1746 ieee80211_scan_completed(ar
->hw
, 1 /* aborted */);
1748 ar
->scan
.in_progress
= false;
1749 complete_all(&ar
->scan
.completed
);
1750 spin_unlock_bh(&ar
->data_lock
);
1753 static int ath10k_abort_scan(struct ath10k
*ar
)
1755 struct wmi_stop_scan_arg arg
= {
1756 .req_id
= 1, /* FIXME */
1757 .req_type
= WMI_SCAN_STOP_ONE
,
1758 .u
.scan_id
= ATH10K_SCAN_ID
,
1762 lockdep_assert_held(&ar
->conf_mutex
);
1764 del_timer_sync(&ar
->scan
.timeout
);
1766 spin_lock_bh(&ar
->data_lock
);
1767 if (!ar
->scan
.in_progress
) {
1768 spin_unlock_bh(&ar
->data_lock
);
1772 ar
->scan
.aborting
= true;
1773 spin_unlock_bh(&ar
->data_lock
);
1775 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
1777 ath10k_warn("could not submit wmi stop scan (%d)\n", ret
);
1778 spin_lock_bh(&ar
->data_lock
);
1779 ar
->scan
.in_progress
= false;
1780 ath10k_offchan_tx_purge(ar
);
1781 spin_unlock_bh(&ar
->data_lock
);
1785 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
1787 ath10k_warn("timed out while waiting for scan to stop\n");
1789 /* scan completion may be done right after we timeout here, so let's
1790 * check the in_progress and tell mac80211 scan is completed. if we
1791 * don't do that and FW fails to send us scan completion indication
1792 * then userspace won't be able to scan anymore */
1795 spin_lock_bh(&ar
->data_lock
);
1796 if (ar
->scan
.in_progress
) {
1797 ath10k_warn("could not stop scan. its still in progress\n");
1798 ar
->scan
.in_progress
= false;
1799 ath10k_offchan_tx_purge(ar
);
1802 spin_unlock_bh(&ar
->data_lock
);
1807 static int ath10k_start_scan(struct ath10k
*ar
,
1808 const struct wmi_start_scan_arg
*arg
)
1812 lockdep_assert_held(&ar
->conf_mutex
);
1814 ret
= ath10k_wmi_start_scan(ar
, arg
);
1818 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
1820 ath10k_abort_scan(ar
);
1824 /* the scan can complete earlier, before we even
1825 * start the timer. in that case the timer handler
1826 * checks ar->scan.in_progress and bails out if its
1827 * false. Add a 200ms margin to account event/command
1829 mod_timer(&ar
->scan
.timeout
, jiffies
+
1830 msecs_to_jiffies(arg
->max_scan_time
+200));
1834 /**********************/
1835 /* mac80211 callbacks */
1836 /**********************/
1838 static void ath10k_tx(struct ieee80211_hw
*hw
,
1839 struct ieee80211_tx_control
*control
,
1840 struct sk_buff
*skb
)
1842 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1843 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1844 struct ath10k
*ar
= hw
->priv
;
1847 /* We should disable CCK RATE due to P2P */
1848 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
1849 ath10k_dbg(ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1851 /* we must calculate tid before we apply qos workaround
1852 * as we'd lose the qos control field */
1853 tid
= ath10k_tx_h_get_tid(hdr
);
1854 vdev_id
= ath10k_tx_h_get_vdev_id(ar
, info
);
1856 /* it makes no sense to process injected frames like that */
1857 if (info
->control
.vif
&&
1858 info
->control
.vif
->type
!= NL80211_IFTYPE_MONITOR
) {
1859 ath10k_tx_h_qos_workaround(hw
, control
, skb
);
1860 ath10k_tx_h_update_wep_key(skb
);
1861 ath10k_tx_h_add_p2p_noa_ie(ar
, skb
);
1862 ath10k_tx_h_seq_no(skb
);
1865 ATH10K_SKB_CB(skb
)->vdev_id
= vdev_id
;
1866 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
1867 ATH10K_SKB_CB(skb
)->htt
.tid
= tid
;
1869 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
1870 spin_lock_bh(&ar
->data_lock
);
1871 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
1872 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
1873 spin_unlock_bh(&ar
->data_lock
);
1875 ath10k_dbg(ATH10K_DBG_MAC
, "queued offchannel skb %p\n", skb
);
1877 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
1878 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
1882 ath10k_tx_htt(ar
, skb
);
1886 * Initialize various parameters with default vaules.
1888 void ath10k_halt(struct ath10k
*ar
)
1890 lockdep_assert_held(&ar
->conf_mutex
);
1892 del_timer_sync(&ar
->scan
.timeout
);
1893 ath10k_offchan_tx_purge(ar
);
1894 ath10k_mgmt_over_wmi_tx_purge(ar
);
1895 ath10k_peer_cleanup_all(ar
);
1896 ath10k_core_stop(ar
);
1897 ath10k_hif_power_down(ar
);
1899 spin_lock_bh(&ar
->data_lock
);
1900 if (ar
->scan
.in_progress
) {
1901 del_timer(&ar
->scan
.timeout
);
1902 ar
->scan
.in_progress
= false;
1903 ieee80211_scan_completed(ar
->hw
, true);
1905 spin_unlock_bh(&ar
->data_lock
);
1908 static int ath10k_start(struct ieee80211_hw
*hw
)
1910 struct ath10k
*ar
= hw
->priv
;
1913 mutex_lock(&ar
->conf_mutex
);
1915 if (ar
->state
!= ATH10K_STATE_OFF
&&
1916 ar
->state
!= ATH10K_STATE_RESTARTING
) {
1921 ret
= ath10k_hif_power_up(ar
);
1923 ath10k_err("could not init hif (%d)\n", ret
);
1924 ar
->state
= ATH10K_STATE_OFF
;
1928 ret
= ath10k_core_start(ar
);
1930 ath10k_err("could not init core (%d)\n", ret
);
1931 ath10k_hif_power_down(ar
);
1932 ar
->state
= ATH10K_STATE_OFF
;
1936 if (ar
->state
== ATH10K_STATE_OFF
)
1937 ar
->state
= ATH10K_STATE_ON
;
1938 else if (ar
->state
== ATH10K_STATE_RESTARTING
)
1939 ar
->state
= ATH10K_STATE_RESTARTED
;
1941 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
1943 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1946 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 0);
1948 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1951 ath10k_regd_update(ar
);
1954 mutex_unlock(&ar
->conf_mutex
);
1958 static void ath10k_stop(struct ieee80211_hw
*hw
)
1960 struct ath10k
*ar
= hw
->priv
;
1962 mutex_lock(&ar
->conf_mutex
);
1963 if (ar
->state
== ATH10K_STATE_ON
||
1964 ar
->state
== ATH10K_STATE_RESTARTED
||
1965 ar
->state
== ATH10K_STATE_WEDGED
)
1968 ar
->state
= ATH10K_STATE_OFF
;
1969 mutex_unlock(&ar
->conf_mutex
);
1971 ath10k_mgmt_over_wmi_tx_purge(ar
);
1973 cancel_work_sync(&ar
->offchan_tx_work
);
1974 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
1975 cancel_work_sync(&ar
->restart_work
);
1978 static int ath10k_config_ps(struct ath10k
*ar
)
1980 struct ath10k_vif
*arvif
;
1983 lockdep_assert_held(&ar
->conf_mutex
);
1985 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
1986 ret
= ath10k_mac_vif_setup_ps(arvif
);
1988 ath10k_warn("could not setup powersave (%d)\n", ret
);
1996 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
1998 struct ath10k
*ar
= hw
->priv
;
1999 struct ieee80211_conf
*conf
= &hw
->conf
;
2002 mutex_lock(&ar
->conf_mutex
);
2004 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2005 ath10k_dbg(ATH10K_DBG_MAC
, "mac config channel %d mhz\n",
2006 conf
->chandef
.chan
->center_freq
);
2007 spin_lock_bh(&ar
->data_lock
);
2008 ar
->rx_channel
= conf
->chandef
.chan
;
2009 spin_unlock_bh(&ar
->data_lock
);
2012 if (changed
& IEEE80211_CONF_CHANGE_PS
)
2013 ath10k_config_ps(ar
);
2015 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
2016 if (conf
->flags
& IEEE80211_CONF_MONITOR
)
2017 ret
= ath10k_monitor_create(ar
);
2019 ret
= ath10k_monitor_destroy(ar
);
2022 mutex_unlock(&ar
->conf_mutex
);
2028 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2029 * because we will send mgmt frames without CCK. This requirement
2030 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2033 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
2034 struct ieee80211_vif
*vif
)
2036 struct ath10k
*ar
= hw
->priv
;
2037 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2038 enum wmi_sta_powersave_param param
;
2044 mutex_lock(&ar
->conf_mutex
);
2046 memset(arvif
, 0, sizeof(*arvif
));
2051 INIT_WORK(&arvif
->wep_key_work
, ath10k_tx_wep_key_work
);
2053 if ((vif
->type
== NL80211_IFTYPE_MONITOR
) && ar
->monitor_present
) {
2054 ath10k_warn("Only one monitor interface allowed\n");
2059 bit
= ffs(ar
->free_vdev_map
);
2065 arvif
->vdev_id
= bit
- 1;
2066 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
2069 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
2071 switch (vif
->type
) {
2072 case NL80211_IFTYPE_UNSPECIFIED
:
2073 case NL80211_IFTYPE_STATION
:
2074 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
2076 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
2078 case NL80211_IFTYPE_ADHOC
:
2079 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
2081 case NL80211_IFTYPE_AP
:
2082 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
2085 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
2087 case NL80211_IFTYPE_MONITOR
:
2088 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
2095 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d\n",
2096 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
2098 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
2099 arvif
->vdev_subtype
, vif
->addr
);
2101 ath10k_warn("WMI vdev create failed: ret %d\n", ret
);
2105 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2106 list_add(&arvif
->list
, &ar
->arvifs
);
2108 vdev_param
= ar
->wmi
.vdev_param
->def_keyid
;
2109 ret
= ath10k_wmi_vdev_set_param(ar
, 0, vdev_param
,
2110 arvif
->def_wep_key_idx
);
2112 ath10k_warn("Failed to set default keyid: %d\n", ret
);
2113 goto err_vdev_delete
;
2116 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
2117 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2118 ATH10K_HW_TXRX_NATIVE_WIFI
);
2119 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2120 if (ret
&& ret
!= -EOPNOTSUPP
) {
2121 ath10k_warn("Failed to set TX encap: %d\n", ret
);
2122 goto err_vdev_delete
;
2125 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2126 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
2128 ath10k_warn("Failed to create peer for AP: %d\n", ret
);
2129 goto err_vdev_delete
;
2133 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
2134 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
2135 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2136 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2139 ath10k_warn("Failed to set RX wake policy: %d\n", ret
);
2140 goto err_peer_delete
;
2143 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
2144 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
2145 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2148 ath10k_warn("Failed to set TX wake thresh: %d\n", ret
);
2149 goto err_peer_delete
;
2152 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
2153 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
2154 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2157 ath10k_warn("Failed to set PSPOLL count: %d\n", ret
);
2158 goto err_peer_delete
;
2162 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
2164 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2165 arvif
->vdev_id
, ret
);
2166 goto err_peer_delete
;
2169 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
2171 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2172 arvif
->vdev_id
, ret
);
2173 goto err_peer_delete
;
2176 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2177 ar
->monitor_present
= true;
2179 mutex_unlock(&ar
->conf_mutex
);
2183 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
2184 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
2187 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2188 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2189 list_del(&arvif
->list
);
2192 mutex_unlock(&ar
->conf_mutex
);
2197 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
2198 struct ieee80211_vif
*vif
)
2200 struct ath10k
*ar
= hw
->priv
;
2201 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2204 mutex_lock(&ar
->conf_mutex
);
2206 cancel_work_sync(&arvif
->wep_key_work
);
2208 spin_lock_bh(&ar
->data_lock
);
2209 if (arvif
->beacon
) {
2210 dev_kfree_skb_any(arvif
->beacon
);
2211 arvif
->beacon
= NULL
;
2213 spin_unlock_bh(&ar
->data_lock
);
2215 ar
->free_vdev_map
|= 1 << (arvif
->vdev_id
);
2216 list_del(&arvif
->list
);
2218 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2219 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
2221 ath10k_warn("Failed to remove peer for AP: %d\n", ret
);
2223 kfree(arvif
->u
.ap
.noa_data
);
2226 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev delete %d (remove interface)\n",
2229 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2231 ath10k_warn("WMI vdev delete failed: %d\n", ret
);
2233 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2234 ar
->monitor_present
= false;
2236 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
2238 mutex_unlock(&ar
->conf_mutex
);
2242 * FIXME: Has to be verified.
2244 #define SUPPORTED_FILTERS \
2245 (FIF_PROMISC_IN_BSS | \
2250 FIF_BCN_PRBRESP_PROMISC | \
2254 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
2255 unsigned int changed_flags
,
2256 unsigned int *total_flags
,
2259 struct ath10k
*ar
= hw
->priv
;
2262 mutex_lock(&ar
->conf_mutex
);
2264 changed_flags
&= SUPPORTED_FILTERS
;
2265 *total_flags
&= SUPPORTED_FILTERS
;
2266 ar
->filter_flags
= *total_flags
;
2268 /* Monitor must not be started if it wasn't created first.
2269 * Promiscuous mode may be started on a non-monitor interface - in
2270 * such case the monitor vdev is not created so starting the
2271 * monitor makes no sense. Since ath10k uses no special RX filters
2272 * (only BSS filter in STA mode) there's no need for any special
2274 if ((ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2275 !ar
->monitor_enabled
&& ar
->monitor_present
) {
2276 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d start\n",
2277 ar
->monitor_vdev_id
);
2279 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
2281 ath10k_warn("Unable to start monitor mode\n");
2282 } else if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2283 ar
->monitor_enabled
&& ar
->monitor_present
) {
2284 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d stop\n",
2285 ar
->monitor_vdev_id
);
2287 ret
= ath10k_monitor_stop(ar
);
2289 ath10k_warn("Unable to stop monitor mode\n");
2292 mutex_unlock(&ar
->conf_mutex
);
2295 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
2296 struct ieee80211_vif
*vif
,
2297 struct ieee80211_bss_conf
*info
,
2300 struct ath10k
*ar
= hw
->priv
;
2301 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2303 u32 vdev_param
, pdev_param
;
2305 mutex_lock(&ar
->conf_mutex
);
2307 if (changed
& BSS_CHANGED_IBSS
)
2308 ath10k_control_ibss(arvif
, info
, vif
->addr
);
2310 if (changed
& BSS_CHANGED_BEACON_INT
) {
2311 arvif
->beacon_interval
= info
->beacon_int
;
2312 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
2313 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2314 arvif
->beacon_interval
);
2315 ath10k_dbg(ATH10K_DBG_MAC
,
2316 "mac vdev %d beacon_interval %d\n",
2317 arvif
->vdev_id
, arvif
->beacon_interval
);
2320 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2324 if (changed
& BSS_CHANGED_BEACON
) {
2325 ath10k_dbg(ATH10K_DBG_MAC
,
2326 "vdev %d set beacon tx mode to staggered\n",
2329 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
2330 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
2331 WMI_BEACON_STAGGERED_MODE
);
2333 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2337 if (changed
& BSS_CHANGED_BEACON_INFO
) {
2338 arvif
->dtim_period
= info
->dtim_period
;
2340 ath10k_dbg(ATH10K_DBG_MAC
,
2341 "mac vdev %d dtim_period %d\n",
2342 arvif
->vdev_id
, arvif
->dtim_period
);
2344 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
2345 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2346 arvif
->dtim_period
);
2348 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2352 if (changed
& BSS_CHANGED_SSID
&&
2353 vif
->type
== NL80211_IFTYPE_AP
) {
2354 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
2356 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
2357 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
2360 if (changed
& BSS_CHANGED_BSSID
) {
2361 if (!is_zero_ether_addr(info
->bssid
)) {
2362 ath10k_dbg(ATH10K_DBG_MAC
,
2363 "mac vdev %d create peer %pM\n",
2364 arvif
->vdev_id
, info
->bssid
);
2366 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
2369 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2370 info
->bssid
, arvif
->vdev_id
);
2372 if (vif
->type
== NL80211_IFTYPE_STATION
) {
2374 * this is never erased as we it for crypto key
2375 * clearing; this is FW requirement
2377 memcpy(arvif
->u
.sta
.bssid
, info
->bssid
,
2380 ath10k_dbg(ATH10K_DBG_MAC
,
2381 "mac vdev %d start %pM\n",
2382 arvif
->vdev_id
, info
->bssid
);
2384 /* FIXME: check return value */
2385 ret
= ath10k_vdev_start(arvif
);
2389 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2390 * so driver need to store it. It is needed when leaving
2391 * IBSS in order to remove BSSID peer.
2393 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
2394 memcpy(arvif
->u
.ibss
.bssid
, info
->bssid
,
2399 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
2400 ath10k_control_beaconing(arvif
, info
);
2402 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
2404 if (info
->use_cts_prot
)
2409 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
2410 arvif
->vdev_id
, cts_prot
);
2412 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
2413 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2416 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2420 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2422 if (info
->use_short_slot
)
2423 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
2426 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
2428 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
2429 arvif
->vdev_id
, slottime
);
2431 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
2432 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2435 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2439 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
2441 if (info
->use_short_preamble
)
2442 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
2444 preamble
= WMI_VDEV_PREAMBLE_LONG
;
2446 ath10k_dbg(ATH10K_DBG_MAC
,
2447 "mac vdev %d preamble %dn",
2448 arvif
->vdev_id
, preamble
);
2450 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
2451 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2454 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2458 if (changed
& BSS_CHANGED_ASSOC
) {
2460 ath10k_bss_assoc(hw
, vif
, info
);
2463 mutex_unlock(&ar
->conf_mutex
);
2466 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
2467 struct ieee80211_vif
*vif
,
2468 struct cfg80211_scan_request
*req
)
2470 struct ath10k
*ar
= hw
->priv
;
2471 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2472 struct wmi_start_scan_arg arg
;
2476 mutex_lock(&ar
->conf_mutex
);
2478 spin_lock_bh(&ar
->data_lock
);
2479 if (ar
->scan
.in_progress
) {
2480 spin_unlock_bh(&ar
->data_lock
);
2485 INIT_COMPLETION(ar
->scan
.started
);
2486 INIT_COMPLETION(ar
->scan
.completed
);
2487 ar
->scan
.in_progress
= true;
2488 ar
->scan
.aborting
= false;
2489 ar
->scan
.is_roc
= false;
2490 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2491 spin_unlock_bh(&ar
->data_lock
);
2493 memset(&arg
, 0, sizeof(arg
));
2494 ath10k_wmi_start_scan_init(ar
, &arg
);
2495 arg
.vdev_id
= arvif
->vdev_id
;
2496 arg
.scan_id
= ATH10K_SCAN_ID
;
2499 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
2502 arg
.ie_len
= req
->ie_len
;
2503 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
2507 arg
.n_ssids
= req
->n_ssids
;
2508 for (i
= 0; i
< arg
.n_ssids
; i
++) {
2509 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
2510 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
2513 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2516 if (req
->n_channels
) {
2517 arg
.n_channels
= req
->n_channels
;
2518 for (i
= 0; i
< arg
.n_channels
; i
++)
2519 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
2522 ret
= ath10k_start_scan(ar
, &arg
);
2524 ath10k_warn("could not start hw scan (%d)\n", ret
);
2525 spin_lock_bh(&ar
->data_lock
);
2526 ar
->scan
.in_progress
= false;
2527 spin_unlock_bh(&ar
->data_lock
);
2531 mutex_unlock(&ar
->conf_mutex
);
2535 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
2536 struct ieee80211_vif
*vif
)
2538 struct ath10k
*ar
= hw
->priv
;
2541 mutex_lock(&ar
->conf_mutex
);
2542 ret
= ath10k_abort_scan(ar
);
2544 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2546 ieee80211_scan_completed(hw
, 1 /* aborted */);
2548 mutex_unlock(&ar
->conf_mutex
);
2551 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2552 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
2553 struct ieee80211_key_conf
*key
)
2555 struct ath10k
*ar
= hw
->priv
;
2556 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2557 struct ath10k_peer
*peer
;
2558 const u8
*peer_addr
;
2559 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2560 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
2563 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
2566 mutex_lock(&ar
->conf_mutex
);
2569 peer_addr
= sta
->addr
;
2570 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
2571 peer_addr
= vif
->bss_conf
.bssid
;
2573 peer_addr
= vif
->addr
;
2575 key
->hw_key_idx
= key
->keyidx
;
2577 /* the peer should not disappear in mid-way (unless FW goes awry) since
2578 * we already hold conf_mutex. we just make sure its there now. */
2579 spin_lock_bh(&ar
->data_lock
);
2580 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2581 spin_unlock_bh(&ar
->data_lock
);
2584 if (cmd
== SET_KEY
) {
2585 ath10k_warn("cannot install key for non-existent peer %pM\n",
2590 /* if the peer doesn't exist there is no key to disable
2598 arvif
->wep_keys
[key
->keyidx
] = key
;
2600 arvif
->wep_keys
[key
->keyidx
] = NULL
;
2602 if (cmd
== DISABLE_KEY
)
2603 ath10k_clear_vdev_key(arvif
, key
);
2606 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
2608 ath10k_warn("ath10k_install_key failed (%d)\n", ret
);
2612 spin_lock_bh(&ar
->data_lock
);
2613 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2614 if (peer
&& cmd
== SET_KEY
)
2615 peer
->keys
[key
->keyidx
] = key
;
2616 else if (peer
&& cmd
== DISABLE_KEY
)
2617 peer
->keys
[key
->keyidx
] = NULL
;
2618 else if (peer
== NULL
)
2619 /* impossible unless FW goes crazy */
2620 ath10k_warn("peer %pM disappeared!\n", peer_addr
);
2621 spin_unlock_bh(&ar
->data_lock
);
2624 mutex_unlock(&ar
->conf_mutex
);
2628 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
2629 struct ieee80211_vif
*vif
,
2630 struct ieee80211_sta
*sta
,
2631 enum ieee80211_sta_state old_state
,
2632 enum ieee80211_sta_state new_state
)
2634 struct ath10k
*ar
= hw
->priv
;
2635 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2638 mutex_lock(&ar
->conf_mutex
);
2640 if (old_state
== IEEE80211_STA_NOTEXIST
&&
2641 new_state
== IEEE80211_STA_NONE
&&
2642 vif
->type
!= NL80211_IFTYPE_STATION
) {
2644 * New station addition.
2646 ath10k_dbg(ATH10K_DBG_MAC
,
2647 "mac vdev %d peer create %pM (new sta)\n",
2648 arvif
->vdev_id
, sta
->addr
);
2650 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
2652 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2653 sta
->addr
, arvif
->vdev_id
);
2654 } else if ((old_state
== IEEE80211_STA_NONE
&&
2655 new_state
== IEEE80211_STA_NOTEXIST
)) {
2657 * Existing station deletion.
2659 ath10k_dbg(ATH10K_DBG_MAC
,
2660 "mac vdev %d peer delete %pM (sta gone)\n",
2661 arvif
->vdev_id
, sta
->addr
);
2662 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
2664 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2665 sta
->addr
, arvif
->vdev_id
);
2667 if (vif
->type
== NL80211_IFTYPE_STATION
)
2668 ath10k_bss_disassoc(hw
, vif
);
2669 } else if (old_state
== IEEE80211_STA_AUTH
&&
2670 new_state
== IEEE80211_STA_ASSOC
&&
2671 (vif
->type
== NL80211_IFTYPE_AP
||
2672 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2676 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM associated\n",
2679 ret
= ath10k_station_assoc(ar
, arvif
, sta
);
2681 ath10k_warn("Failed to associate station: %pM\n",
2683 } else if (old_state
== IEEE80211_STA_ASSOC
&&
2684 new_state
== IEEE80211_STA_AUTH
&&
2685 (vif
->type
== NL80211_IFTYPE_AP
||
2686 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2690 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
2693 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
2695 ath10k_warn("Failed to disassociate station: %pM\n",
2699 mutex_unlock(&ar
->conf_mutex
);
2703 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
2704 u16 ac
, bool enable
)
2706 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2710 lockdep_assert_held(&ar
->conf_mutex
);
2712 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
2716 case IEEE80211_AC_VO
:
2717 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
2718 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
2720 case IEEE80211_AC_VI
:
2721 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
2722 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
2724 case IEEE80211_AC_BE
:
2725 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
2726 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
2728 case IEEE80211_AC_BK
:
2729 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
2730 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
2735 arvif
->u
.sta
.uapsd
|= value
;
2737 arvif
->u
.sta
.uapsd
&= ~value
;
2739 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2740 WMI_STA_PS_PARAM_UAPSD
,
2741 arvif
->u
.sta
.uapsd
);
2743 ath10k_warn("could not set uapsd params %d\n", ret
);
2747 if (arvif
->u
.sta
.uapsd
)
2748 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
2750 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2752 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2753 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
2756 ath10k_warn("could not set rx wake param %d\n", ret
);
2762 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
2763 struct ieee80211_vif
*vif
, u16 ac
,
2764 const struct ieee80211_tx_queue_params
*params
)
2766 struct ath10k
*ar
= hw
->priv
;
2767 struct wmi_wmm_params_arg
*p
= NULL
;
2770 mutex_lock(&ar
->conf_mutex
);
2773 case IEEE80211_AC_VO
:
2774 p
= &ar
->wmm_params
.ac_vo
;
2776 case IEEE80211_AC_VI
:
2777 p
= &ar
->wmm_params
.ac_vi
;
2779 case IEEE80211_AC_BE
:
2780 p
= &ar
->wmm_params
.ac_be
;
2782 case IEEE80211_AC_BK
:
2783 p
= &ar
->wmm_params
.ac_bk
;
2792 p
->cwmin
= params
->cw_min
;
2793 p
->cwmax
= params
->cw_max
;
2794 p
->aifs
= params
->aifs
;
2797 * The channel time duration programmed in the HW is in absolute
2798 * microseconds, while mac80211 gives the txop in units of
2801 p
->txop
= params
->txop
* 32;
2803 /* FIXME: FW accepts wmm params per hw, not per vif */
2804 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
2806 ath10k_warn("could not set wmm params %d\n", ret
);
2810 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
2812 ath10k_warn("could not set sta uapsd %d\n", ret
);
2815 mutex_unlock(&ar
->conf_mutex
);
2819 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2821 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
2822 struct ieee80211_vif
*vif
,
2823 struct ieee80211_channel
*chan
,
2825 enum ieee80211_roc_type type
)
2827 struct ath10k
*ar
= hw
->priv
;
2828 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2829 struct wmi_start_scan_arg arg
;
2832 mutex_lock(&ar
->conf_mutex
);
2834 spin_lock_bh(&ar
->data_lock
);
2835 if (ar
->scan
.in_progress
) {
2836 spin_unlock_bh(&ar
->data_lock
);
2841 INIT_COMPLETION(ar
->scan
.started
);
2842 INIT_COMPLETION(ar
->scan
.completed
);
2843 INIT_COMPLETION(ar
->scan
.on_channel
);
2844 ar
->scan
.in_progress
= true;
2845 ar
->scan
.aborting
= false;
2846 ar
->scan
.is_roc
= true;
2847 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2848 ar
->scan
.roc_freq
= chan
->center_freq
;
2849 spin_unlock_bh(&ar
->data_lock
);
2851 memset(&arg
, 0, sizeof(arg
));
2852 ath10k_wmi_start_scan_init(ar
, &arg
);
2853 arg
.vdev_id
= arvif
->vdev_id
;
2854 arg
.scan_id
= ATH10K_SCAN_ID
;
2856 arg
.channels
[0] = chan
->center_freq
;
2857 arg
.dwell_time_active
= duration
;
2858 arg
.dwell_time_passive
= duration
;
2859 arg
.max_scan_time
= 2 * duration
;
2860 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2861 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
2863 ret
= ath10k_start_scan(ar
, &arg
);
2865 ath10k_warn("could not start roc scan (%d)\n", ret
);
2866 spin_lock_bh(&ar
->data_lock
);
2867 ar
->scan
.in_progress
= false;
2868 spin_unlock_bh(&ar
->data_lock
);
2872 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
2874 ath10k_warn("could not switch to channel for roc scan\n");
2875 ath10k_abort_scan(ar
);
2882 mutex_unlock(&ar
->conf_mutex
);
2886 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
2888 struct ath10k
*ar
= hw
->priv
;
2890 mutex_lock(&ar
->conf_mutex
);
2891 ath10k_abort_scan(ar
);
2892 mutex_unlock(&ar
->conf_mutex
);
2898 * Both RTS and Fragmentation threshold are interface-specific
2899 * in ath10k, but device-specific in mac80211.
2902 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
2904 struct ath10k
*ar
= hw
->priv
;
2905 struct ath10k_vif
*arvif
;
2908 mutex_lock(&ar
->conf_mutex
);
2909 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2910 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
2911 arvif
->vdev_id
, value
);
2913 ret
= ath10k_mac_set_rts(arvif
, value
);
2915 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
2916 arvif
->vdev_id
, ret
);
2920 mutex_unlock(&ar
->conf_mutex
);
2925 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
2927 struct ath10k
*ar
= hw
->priv
;
2928 struct ath10k_vif
*arvif
;
2931 mutex_lock(&ar
->conf_mutex
);
2932 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2933 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d fragmentation threshold %d\n",
2934 arvif
->vdev_id
, value
);
2936 ret
= ath10k_mac_set_rts(arvif
, value
);
2938 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
2939 arvif
->vdev_id
, ret
);
2943 mutex_unlock(&ar
->conf_mutex
);
2948 static void ath10k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
2950 struct ath10k
*ar
= hw
->priv
;
2954 /* mac80211 doesn't care if we really xmit queued frames or not
2955 * we'll collect those frames either way if we stop/delete vdevs */
2959 mutex_lock(&ar
->conf_mutex
);
2961 if (ar
->state
== ATH10K_STATE_WEDGED
)
2964 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
2967 spin_lock_bh(&ar
->htt
.tx_lock
);
2968 empty
= (ar
->htt
.num_pending_tx
== 0);
2969 spin_unlock_bh(&ar
->htt
.tx_lock
);
2971 skip
= (ar
->state
== ATH10K_STATE_WEDGED
);
2974 }), ATH10K_FLUSH_TIMEOUT_HZ
);
2976 if (ret
<= 0 || skip
)
2977 ath10k_warn("tx not flushed\n");
2980 mutex_unlock(&ar
->conf_mutex
);
2983 /* TODO: Implement this function properly
2984 * For now it is needed to reply to Probe Requests in IBSS mode.
2985 * Propably we need this information from FW.
2987 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
2993 static int ath10k_suspend(struct ieee80211_hw
*hw
,
2994 struct cfg80211_wowlan
*wowlan
)
2996 struct ath10k
*ar
= hw
->priv
;
2999 ar
->is_target_paused
= false;
3001 ret
= ath10k_wmi_pdev_suspend_target(ar
);
3003 ath10k_warn("could not suspend target (%d)\n", ret
);
3007 ret
= wait_event_interruptible_timeout(ar
->event_queue
,
3008 ar
->is_target_paused
== true,
3011 ath10k_warn("suspend interrupted (%d)\n", ret
);
3013 } else if (ret
== 0) {
3014 ath10k_warn("suspend timed out - target pause event never came\n");
3018 ret
= ath10k_hif_suspend(ar
);
3020 ath10k_warn("could not suspend hif (%d)\n", ret
);
3026 ret
= ath10k_wmi_pdev_resume_target(ar
);
3028 ath10k_warn("could not resume target (%d)\n", ret
);
3032 static int ath10k_resume(struct ieee80211_hw
*hw
)
3034 struct ath10k
*ar
= hw
->priv
;
3037 ret
= ath10k_hif_resume(ar
);
3039 ath10k_warn("could not resume hif (%d)\n", ret
);
3043 ret
= ath10k_wmi_pdev_resume_target(ar
);
3045 ath10k_warn("could not resume target (%d)\n", ret
);
3053 static void ath10k_restart_complete(struct ieee80211_hw
*hw
)
3055 struct ath10k
*ar
= hw
->priv
;
3057 mutex_lock(&ar
->conf_mutex
);
3059 /* If device failed to restart it will be in a different state, e.g.
3060 * ATH10K_STATE_WEDGED */
3061 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
3062 ath10k_info("device successfully recovered\n");
3063 ar
->state
= ATH10K_STATE_ON
;
3066 mutex_unlock(&ar
->conf_mutex
);
3069 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
3070 struct survey_info
*survey
)
3072 struct ath10k
*ar
= hw
->priv
;
3073 struct ieee80211_supported_band
*sband
;
3074 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
3077 mutex_lock(&ar
->conf_mutex
);
3079 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
3080 if (sband
&& idx
>= sband
->n_channels
) {
3081 idx
-= sband
->n_channels
;
3086 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
3088 if (!sband
|| idx
>= sband
->n_channels
) {
3093 spin_lock_bh(&ar
->data_lock
);
3094 memcpy(survey
, ar_survey
, sizeof(*survey
));
3095 spin_unlock_bh(&ar
->data_lock
);
3097 survey
->channel
= &sband
->channels
[idx
];
3100 mutex_unlock(&ar
->conf_mutex
);
3104 static const struct ieee80211_ops ath10k_ops
= {
3106 .start
= ath10k_start
,
3107 .stop
= ath10k_stop
,
3108 .config
= ath10k_config
,
3109 .add_interface
= ath10k_add_interface
,
3110 .remove_interface
= ath10k_remove_interface
,
3111 .configure_filter
= ath10k_configure_filter
,
3112 .bss_info_changed
= ath10k_bss_info_changed
,
3113 .hw_scan
= ath10k_hw_scan
,
3114 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
3115 .set_key
= ath10k_set_key
,
3116 .sta_state
= ath10k_sta_state
,
3117 .conf_tx
= ath10k_conf_tx
,
3118 .remain_on_channel
= ath10k_remain_on_channel
,
3119 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
3120 .set_rts_threshold
= ath10k_set_rts_threshold
,
3121 .set_frag_threshold
= ath10k_set_frag_threshold
,
3122 .flush
= ath10k_flush
,
3123 .tx_last_beacon
= ath10k_tx_last_beacon
,
3124 .restart_complete
= ath10k_restart_complete
,
3125 .get_survey
= ath10k_get_survey
,
3127 .suspend
= ath10k_suspend
,
3128 .resume
= ath10k_resume
,
3132 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3133 .bitrate = (_rate), \
3134 .flags = (_flags), \
3135 .hw_value = (_rateid), \
3138 #define CHAN2G(_channel, _freq, _flags) { \
3139 .band = IEEE80211_BAND_2GHZ, \
3140 .hw_value = (_channel), \
3141 .center_freq = (_freq), \
3142 .flags = (_flags), \
3143 .max_antenna_gain = 0, \
3147 #define CHAN5G(_channel, _freq, _flags) { \
3148 .band = IEEE80211_BAND_5GHZ, \
3149 .hw_value = (_channel), \
3150 .center_freq = (_freq), \
3151 .flags = (_flags), \
3152 .max_antenna_gain = 0, \
3156 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
3166 CHAN2G(10, 2457, 0),
3167 CHAN2G(11, 2462, 0),
3168 CHAN2G(12, 2467, 0),
3169 CHAN2G(13, 2472, 0),
3170 CHAN2G(14, 2484, 0),
3173 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
3174 CHAN5G(36, 5180, 0),
3175 CHAN5G(40, 5200, 0),
3176 CHAN5G(44, 5220, 0),
3177 CHAN5G(48, 5240, 0),
3178 CHAN5G(52, 5260, 0),
3179 CHAN5G(56, 5280, 0),
3180 CHAN5G(60, 5300, 0),
3181 CHAN5G(64, 5320, 0),
3182 CHAN5G(100, 5500, 0),
3183 CHAN5G(104, 5520, 0),
3184 CHAN5G(108, 5540, 0),
3185 CHAN5G(112, 5560, 0),
3186 CHAN5G(116, 5580, 0),
3187 CHAN5G(120, 5600, 0),
3188 CHAN5G(124, 5620, 0),
3189 CHAN5G(128, 5640, 0),
3190 CHAN5G(132, 5660, 0),
3191 CHAN5G(136, 5680, 0),
3192 CHAN5G(140, 5700, 0),
3193 CHAN5G(149, 5745, 0),
3194 CHAN5G(153, 5765, 0),
3195 CHAN5G(157, 5785, 0),
3196 CHAN5G(161, 5805, 0),
3197 CHAN5G(165, 5825, 0),
3200 static struct ieee80211_rate ath10k_rates
[] = {
3202 RATETAB_ENT(10, 0x82, 0),
3203 RATETAB_ENT(20, 0x84, 0),
3204 RATETAB_ENT(55, 0x8b, 0),
3205 RATETAB_ENT(110, 0x96, 0),
3207 RATETAB_ENT(60, 0x0c, 0),
3208 RATETAB_ENT(90, 0x12, 0),
3209 RATETAB_ENT(120, 0x18, 0),
3210 RATETAB_ENT(180, 0x24, 0),
3211 RATETAB_ENT(240, 0x30, 0),
3212 RATETAB_ENT(360, 0x48, 0),
3213 RATETAB_ENT(480, 0x60, 0),
3214 RATETAB_ENT(540, 0x6c, 0),
3217 #define ath10k_a_rates (ath10k_rates + 4)
3218 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3219 #define ath10k_g_rates (ath10k_rates + 0)
3220 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3222 struct ath10k
*ath10k_mac_create(void)
3224 struct ieee80211_hw
*hw
;
3227 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
), &ath10k_ops
);
3237 void ath10k_mac_destroy(struct ath10k
*ar
)
3239 ieee80211_free_hw(ar
->hw
);
3242 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
3245 .types
= BIT(NL80211_IFTYPE_STATION
)
3246 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
3250 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
3254 .types
= BIT(NL80211_IFTYPE_AP
)
3258 static const struct ieee80211_iface_combination ath10k_if_comb
= {
3259 .limits
= ath10k_if_limits
,
3260 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
3261 .max_interfaces
= 8,
3262 .num_different_channels
= 1,
3263 .beacon_int_infra_match
= true,
3266 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
3268 struct ieee80211_sta_vht_cap vht_cap
= {0};
3272 vht_cap
.vht_supported
= 1;
3273 vht_cap
.cap
= ar
->vht_cap_info
;
3276 for (i
= 0; i
< 8; i
++) {
3277 if (i
< ar
->num_rf_chains
)
3278 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
3280 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
3283 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
3284 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
3289 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
3292 struct ieee80211_sta_ht_cap ht_cap
= {0};
3294 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
3297 ht_cap
.ht_supported
= 1;
3298 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
3299 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
3300 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
3301 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
3302 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
3304 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
3305 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
3307 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
3308 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
3310 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
3313 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
3314 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
3319 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
3320 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
3322 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
3325 stbc
= ar
->ht_cap_info
;
3326 stbc
&= WMI_HT_CAP_RX_STBC
;
3327 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
3328 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
3329 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
3334 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
3335 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
3337 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
3338 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
3340 /* max AMSDU is implicitly taken from vht_cap_info */
3341 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
3342 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
3344 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3345 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
3347 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
3353 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
3354 struct ieee80211_vif
*vif
)
3356 struct ath10k_vif_iter
*arvif_iter
= data
;
3357 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3359 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
3360 arvif_iter
->arvif
= arvif
;
3363 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
3365 struct ath10k_vif_iter arvif_iter
;
3368 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
3369 arvif_iter
.vdev_id
= vdev_id
;
3371 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
3372 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3374 ath10k_get_arvif_iter
,
3376 if (!arvif_iter
.arvif
) {
3377 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id
);
3381 return arvif_iter
.arvif
;
3384 int ath10k_mac_register(struct ath10k
*ar
)
3386 struct ieee80211_supported_band
*band
;
3387 struct ieee80211_sta_vht_cap vht_cap
;
3388 struct ieee80211_sta_ht_cap ht_cap
;
3392 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
3394 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
3396 ht_cap
= ath10k_get_ht_cap(ar
);
3397 vht_cap
= ath10k_create_vht_cap(ar
);
3399 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
3400 channels
= kmemdup(ath10k_2ghz_channels
,
3401 sizeof(ath10k_2ghz_channels
),
3408 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
3409 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
3410 band
->channels
= channels
;
3411 band
->n_bitrates
= ath10k_g_rates_size
;
3412 band
->bitrates
= ath10k_g_rates
;
3413 band
->ht_cap
= ht_cap
;
3415 /* vht is not supported in 2.4 GHz */
3417 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
3420 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
3421 channels
= kmemdup(ath10k_5ghz_channels
,
3422 sizeof(ath10k_5ghz_channels
),
3429 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
3430 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
3431 band
->channels
= channels
;
3432 band
->n_bitrates
= ath10k_a_rates_size
;
3433 band
->bitrates
= ath10k_a_rates
;
3434 band
->ht_cap
= ht_cap
;
3435 band
->vht_cap
= vht_cap
;
3436 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
3439 ar
->hw
->wiphy
->interface_modes
=
3440 BIT(NL80211_IFTYPE_STATION
) |
3441 BIT(NL80211_IFTYPE_ADHOC
) |
3442 BIT(NL80211_IFTYPE_AP
) |
3443 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
3444 BIT(NL80211_IFTYPE_P2P_GO
);
3446 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
3447 IEEE80211_HW_SUPPORTS_PS
|
3448 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
3449 IEEE80211_HW_SUPPORTS_UAPSD
|
3450 IEEE80211_HW_MFP_CAPABLE
|
3451 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
3452 IEEE80211_HW_HAS_RATE_CONTROL
|
3453 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
3454 IEEE80211_HW_WANT_MONITOR_VIF
|
3455 IEEE80211_HW_AP_LINK_PS
;
3457 /* MSDU can have HTT TX fragment pushed in front. The additional 4
3458 * bytes is used for padding/alignment if necessary. */
3459 ar
->hw
->extra_tx_headroom
+= sizeof(struct htt_data_tx_desc_frag
)*2 + 4;
3461 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
3462 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
3464 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
3465 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
3466 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
3469 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
3470 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
3472 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
3474 ar
->hw
->channel_change_time
= 5000;
3475 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
3477 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
3478 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
3480 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
3482 * on LL hardware queues are managed entirely by the FW
3483 * so we only advertise to mac we can do the queues thing
3487 ar
->hw
->wiphy
->iface_combinations
= &ath10k_if_comb
;
3488 ar
->hw
->wiphy
->n_iface_combinations
= 1;
3490 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
3492 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
3493 ath10k_reg_notifier
);
3495 ath10k_err("Regulatory initialization failed\n");
3499 ret
= ieee80211_register_hw(ar
->hw
);
3501 ath10k_err("ieee80211 registration failed: %d\n", ret
);
3505 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
3506 ret
= regulatory_hint(ar
->hw
->wiphy
,
3507 ar
->ath_common
.regulatory
.alpha2
);
3509 goto err_unregister
;
3515 ieee80211_unregister_hw(ar
->hw
);
3517 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
3518 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
3523 void ath10k_mac_unregister(struct ath10k
*ar
)
3525 ieee80211_unregister_hw(ar
->hw
);
3527 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
3528 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
3530 SET_IEEE80211_DEV(ar
->hw
, NULL
);