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>
33 static int ath10k_send_key(struct ath10k_vif
*arvif
,
34 struct ieee80211_key_conf
*key
,
38 struct wmi_vdev_install_key_arg arg
= {
39 .vdev_id
= arvif
->vdev_id
,
40 .key_idx
= key
->keyidx
,
41 .key_len
= key
->keylen
,
46 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
47 arg
.key_flags
= WMI_KEY_PAIRWISE
;
49 arg
.key_flags
= WMI_KEY_GROUP
;
51 switch (key
->cipher
) {
52 case WLAN_CIPHER_SUITE_CCMP
:
53 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
54 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
56 case WLAN_CIPHER_SUITE_TKIP
:
57 arg
.key_cipher
= WMI_CIPHER_TKIP
;
58 arg
.key_txmic_len
= 8;
59 arg
.key_rxmic_len
= 8;
61 case WLAN_CIPHER_SUITE_WEP40
:
62 case WLAN_CIPHER_SUITE_WEP104
:
63 arg
.key_cipher
= WMI_CIPHER_WEP
;
64 /* AP/IBSS mode requires self-key to be groupwise
65 * Otherwise pairwise key must be set */
66 if (memcmp(macaddr
, arvif
->vif
->addr
, ETH_ALEN
))
67 arg
.key_flags
= WMI_KEY_PAIRWISE
;
70 ath10k_warn("cipher %d is not supported\n", key
->cipher
);
74 if (cmd
== DISABLE_KEY
) {
75 arg
.key_cipher
= WMI_CIPHER_NONE
;
79 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
82 static int ath10k_install_key(struct ath10k_vif
*arvif
,
83 struct ieee80211_key_conf
*key
,
87 struct ath10k
*ar
= arvif
->ar
;
90 INIT_COMPLETION(ar
->install_key_done
);
92 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
);
96 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
103 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
106 struct ath10k
*ar
= arvif
->ar
;
107 struct ath10k_peer
*peer
;
111 lockdep_assert_held(&ar
->conf_mutex
);
113 spin_lock_bh(&ar
->data_lock
);
114 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
115 spin_unlock_bh(&ar
->data_lock
);
120 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
121 if (arvif
->wep_keys
[i
] == NULL
)
124 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
129 peer
->keys
[i
] = arvif
->wep_keys
[i
];
135 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
138 struct ath10k
*ar
= arvif
->ar
;
139 struct ath10k_peer
*peer
;
144 lockdep_assert_held(&ar
->conf_mutex
);
146 spin_lock_bh(&ar
->data_lock
);
147 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
148 spin_unlock_bh(&ar
->data_lock
);
153 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
154 if (peer
->keys
[i
] == NULL
)
157 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
159 if (ret
&& first_errno
== 0)
163 ath10k_warn("could not remove peer wep key %d (%d)\n",
166 peer
->keys
[i
] = NULL
;
172 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
173 struct ieee80211_key_conf
*key
)
175 struct ath10k
*ar
= arvif
->ar
;
176 struct ath10k_peer
*peer
;
182 lockdep_assert_held(&ar
->conf_mutex
);
185 /* since ath10k_install_key we can't hold data_lock all the
186 * time, so we try to remove the keys incrementally */
187 spin_lock_bh(&ar
->data_lock
);
189 list_for_each_entry(peer
, &ar
->peers
, list
) {
190 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
191 if (peer
->keys
[i
] == key
) {
192 memcpy(addr
, peer
->addr
, ETH_ALEN
);
193 peer
->keys
[i
] = NULL
;
198 if (i
< ARRAY_SIZE(peer
->keys
))
201 spin_unlock_bh(&ar
->data_lock
);
203 if (i
== ARRAY_SIZE(peer
->keys
))
206 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
);
207 if (ret
&& first_errno
== 0)
211 ath10k_warn("could not remove key for %pM\n", addr
);
218 /*********************/
219 /* General utilities */
220 /*********************/
222 static inline enum wmi_phy_mode
223 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
225 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
227 switch (chandef
->chan
->band
) {
228 case IEEE80211_BAND_2GHZ
:
229 switch (chandef
->width
) {
230 case NL80211_CHAN_WIDTH_20_NOHT
:
233 case NL80211_CHAN_WIDTH_20
:
234 phymode
= MODE_11NG_HT20
;
236 case NL80211_CHAN_WIDTH_40
:
237 phymode
= MODE_11NG_HT40
;
239 case NL80211_CHAN_WIDTH_5
:
240 case NL80211_CHAN_WIDTH_10
:
241 case NL80211_CHAN_WIDTH_80
:
242 case NL80211_CHAN_WIDTH_80P80
:
243 case NL80211_CHAN_WIDTH_160
:
244 phymode
= MODE_UNKNOWN
;
248 case IEEE80211_BAND_5GHZ
:
249 switch (chandef
->width
) {
250 case NL80211_CHAN_WIDTH_20_NOHT
:
253 case NL80211_CHAN_WIDTH_20
:
254 phymode
= MODE_11NA_HT20
;
256 case NL80211_CHAN_WIDTH_40
:
257 phymode
= MODE_11NA_HT40
;
259 case NL80211_CHAN_WIDTH_80
:
260 phymode
= MODE_11AC_VHT80
;
262 case NL80211_CHAN_WIDTH_5
:
263 case NL80211_CHAN_WIDTH_10
:
264 case NL80211_CHAN_WIDTH_80P80
:
265 case NL80211_CHAN_WIDTH_160
:
266 phymode
= MODE_UNKNOWN
;
274 WARN_ON(phymode
== MODE_UNKNOWN
);
278 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
281 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
282 * 0 for no restriction
291 switch (mpdudensity
) {
297 /* Our lower layer calculations limit our precision to
313 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
317 lockdep_assert_held(&ar
->conf_mutex
);
319 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
323 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
330 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
334 lockdep_assert_held(&ar
->conf_mutex
);
336 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
340 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
347 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
349 struct ath10k_peer
*peer
, *tmp
;
351 lockdep_assert_held(&ar
->conf_mutex
);
353 spin_lock_bh(&ar
->data_lock
);
354 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
355 if (peer
->vdev_id
!= vdev_id
)
358 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
359 peer
->addr
, vdev_id
);
361 list_del(&peer
->list
);
364 spin_unlock_bh(&ar
->data_lock
);
367 /************************/
368 /* Interface management */
369 /************************/
371 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
375 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
376 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
383 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
385 struct ath10k
*ar
= arvif
->ar
;
386 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
387 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
388 struct wmi_vdev_start_request_arg arg
= {};
391 lockdep_assert_held(&ar
->conf_mutex
);
393 INIT_COMPLETION(ar
->vdev_setup_done
);
395 arg
.vdev_id
= arvif
->vdev_id
;
396 arg
.dtim_period
= arvif
->dtim_period
;
397 arg
.bcn_intval
= arvif
->beacon_interval
;
399 arg
.channel
.freq
= channel
->center_freq
;
401 arg
.channel
.band_center_freq1
= conf
->chandef
.center_freq1
;
403 arg
.channel
.mode
= chan_to_phymode(&conf
->chandef
);
405 arg
.channel
.min_power
= channel
->max_power
* 3;
406 arg
.channel
.max_power
= channel
->max_power
* 4;
407 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
408 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
410 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
411 arg
.ssid
= arvif
->u
.ap
.ssid
;
412 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
413 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
414 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
415 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
416 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
419 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
421 ath10k_warn("WMI vdev start failed: ret %d\n", ret
);
425 ret
= ath10k_vdev_setup_sync(ar
);
427 ath10k_warn("vdev setup failed %d\n", ret
);
434 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
436 struct ath10k
*ar
= arvif
->ar
;
439 lockdep_assert_held(&ar
->conf_mutex
);
441 INIT_COMPLETION(ar
->vdev_setup_done
);
443 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
445 ath10k_warn("WMI vdev stop failed: ret %d\n", ret
);
449 ret
= ath10k_vdev_setup_sync(ar
);
451 ath10k_warn("vdev setup failed %d\n", ret
);
458 static int ath10k_monitor_start(struct ath10k
*ar
, int vdev_id
)
460 struct ieee80211_channel
*channel
= ar
->hw
->conf
.chandef
.chan
;
461 struct wmi_vdev_start_request_arg arg
= {};
462 enum nl80211_channel_type type
;
465 lockdep_assert_held(&ar
->conf_mutex
);
467 type
= cfg80211_get_chandef_type(&ar
->hw
->conf
.chandef
);
469 arg
.vdev_id
= vdev_id
;
470 arg
.channel
.freq
= channel
->center_freq
;
471 arg
.channel
.band_center_freq1
= ar
->hw
->conf
.chandef
.center_freq1
;
473 /* TODO setup this dynamically, what in case we
474 don't have any vifs? */
475 arg
.channel
.mode
= chan_to_phymode(&ar
->hw
->conf
.chandef
);
477 arg
.channel
.min_power
= channel
->max_power
* 3;
478 arg
.channel
.max_power
= channel
->max_power
* 4;
479 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 4;
480 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
;
482 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
484 ath10k_warn("Monitor vdev start failed: ret %d\n", ret
);
488 ret
= ath10k_vdev_setup_sync(ar
);
490 ath10k_warn("Monitor vdev setup failed %d\n", ret
);
494 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
496 ath10k_warn("Monitor vdev up failed: %d\n", ret
);
500 ar
->monitor_vdev_id
= vdev_id
;
501 ar
->monitor_enabled
= true;
506 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
508 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
513 static int ath10k_monitor_stop(struct ath10k
*ar
)
517 lockdep_assert_held(&ar
->conf_mutex
);
519 /* For some reasons, ath10k_wmi_vdev_down() here couse
520 * often ath10k_wmi_vdev_stop() to fail. Next we could
521 * not run monitor vdev and driver reload
522 * required. Don't see such problems we skip
523 * ath10k_wmi_vdev_down() here.
526 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
528 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
530 ret
= ath10k_vdev_setup_sync(ar
);
532 ath10k_warn("Monitor_down sync failed: %d\n", ret
);
534 ar
->monitor_enabled
= false;
538 static int ath10k_monitor_create(struct ath10k
*ar
)
542 lockdep_assert_held(&ar
->conf_mutex
);
544 if (ar
->monitor_present
) {
545 ath10k_warn("Monitor mode already enabled\n");
549 bit
= ffs(ar
->free_vdev_map
);
551 ath10k_warn("No free VDEV slots\n");
555 ar
->monitor_vdev_id
= bit
- 1;
556 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
558 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
559 WMI_VDEV_TYPE_MONITOR
,
562 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret
);
566 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor interface created, vdev id: %d\n",
567 ar
->monitor_vdev_id
);
569 ar
->monitor_present
= true;
574 * Restore the ID to the global map.
576 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
580 static int ath10k_monitor_destroy(struct ath10k
*ar
)
584 lockdep_assert_held(&ar
->conf_mutex
);
586 if (!ar
->monitor_present
)
589 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
591 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret
);
595 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
596 ar
->monitor_present
= false;
598 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor interface destroyed, vdev id: %d\n",
599 ar
->monitor_vdev_id
);
603 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
604 struct ieee80211_bss_conf
*info
)
608 if (!info
->enable_beacon
) {
609 ath10k_vdev_stop(arvif
);
613 arvif
->tx_seq_no
= 0x1000;
615 ret
= ath10k_vdev_start(arvif
);
619 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, 0, info
->bssid
);
621 ath10k_warn("Failed to bring up VDEV: %d\n",
625 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d up\n", arvif
->vdev_id
);
628 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
629 struct ieee80211_bss_conf
*info
,
630 const u8 self_peer
[ETH_ALEN
])
634 if (!info
->ibss_joined
) {
635 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
637 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
638 self_peer
, arvif
->vdev_id
, ret
);
640 if (is_zero_ether_addr(arvif
->u
.ibss
.bssid
))
643 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
644 arvif
->u
.ibss
.bssid
);
646 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
647 arvif
->u
.ibss
.bssid
, arvif
->vdev_id
, ret
);
651 memset(arvif
->u
.ibss
.bssid
, 0, ETH_ALEN
);
656 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
658 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
659 self_peer
, arvif
->vdev_id
, ret
);
663 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
,
664 WMI_VDEV_PARAM_ATIM_WINDOW
,
665 ATH10K_DEFAULT_ATIM
);
667 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
668 arvif
->vdev_id
, ret
);
672 * Review this when mac80211 gains per-interface powersave support.
674 static void ath10k_ps_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
676 struct ath10k_generic_iter
*ar_iter
= data
;
677 struct ieee80211_conf
*conf
= &ar_iter
->ar
->hw
->conf
;
678 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
679 enum wmi_sta_powersave_param param
;
680 enum wmi_sta_ps_mode psmode
;
683 if (vif
->type
!= NL80211_IFTYPE_STATION
)
686 if (conf
->flags
& IEEE80211_CONF_PS
) {
687 psmode
= WMI_STA_PS_MODE_ENABLED
;
688 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
690 ret
= ath10k_wmi_set_sta_ps_param(ar_iter
->ar
,
693 conf
->dynamic_ps_timeout
);
695 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
702 psmode
= WMI_STA_PS_MODE_DISABLED
;
705 ar_iter
->ret
= ath10k_wmi_set_psmode(ar_iter
->ar
, arvif
->vdev_id
,
708 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
709 psmode
, arvif
->vdev_id
);
711 ath10k_dbg(ATH10K_DBG_MAC
, "Set PS Mode: %d for VDEV: %d\n",
712 psmode
, arvif
->vdev_id
);
715 /**********************/
716 /* Station management */
717 /**********************/
719 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
720 struct ath10k_vif
*arvif
,
721 struct ieee80211_sta
*sta
,
722 struct ieee80211_bss_conf
*bss_conf
,
723 struct wmi_peer_assoc_complete_arg
*arg
)
725 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
726 arg
->vdev_id
= arvif
->vdev_id
;
727 arg
->peer_aid
= sta
->aid
;
728 arg
->peer_flags
|= WMI_PEER_AUTH
;
730 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
732 * Seems FW have problems with Power Save in STA
733 * mode when we setup this parameter to high (eg. 5).
734 * Often we see that FW don't send NULL (with clean P flags)
735 * frame even there is info about buffered frames in beacons.
736 * Sometimes we have to wait more than 10 seconds before FW
737 * will wakeup. Often sending one ping from AP to our device
738 * just fail (more than 50%).
740 * Seems setting this FW parameter to 1 couse FW
741 * will check every beacon and will wakup immediately
742 * after detection buffered data.
744 arg
->peer_listen_intval
= 1;
746 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
748 arg
->peer_num_spatial_streams
= 1;
751 * The assoc capabilities are available only in managed mode.
753 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
754 arg
->peer_caps
= bss_conf
->assoc_capability
;
757 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
758 struct ath10k_vif
*arvif
,
759 struct wmi_peer_assoc_complete_arg
*arg
)
761 struct ieee80211_vif
*vif
= arvif
->vif
;
762 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
763 struct cfg80211_bss
*bss
;
764 const u8
*rsnie
= NULL
;
765 const u8
*wpaie
= NULL
;
767 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
768 info
->bssid
, NULL
, 0, 0, 0);
770 const struct cfg80211_bss_ies
*ies
;
773 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
775 ies
= rcu_dereference(bss
->ies
);
777 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
778 WLAN_OUI_TYPE_MICROSOFT_WPA
,
782 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
785 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
786 if (rsnie
|| wpaie
) {
787 ath10k_dbg(ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
788 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
792 ath10k_dbg(ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
793 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
797 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
798 struct ieee80211_sta
*sta
,
799 struct wmi_peer_assoc_complete_arg
*arg
)
801 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
802 const struct ieee80211_supported_band
*sband
;
803 const struct ieee80211_rate
*rates
;
807 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
808 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
809 rates
= sband
->bitrates
;
811 rateset
->num_rates
= 0;
813 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
817 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
818 rateset
->num_rates
++;
822 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
823 struct ieee80211_sta
*sta
,
824 struct wmi_peer_assoc_complete_arg
*arg
)
826 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
830 if (!ht_cap
->ht_supported
)
833 arg
->peer_flags
|= WMI_PEER_HT
;
834 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
835 ht_cap
->ampdu_factor
)) - 1;
837 arg
->peer_mpdu_density
=
838 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
840 arg
->peer_ht_caps
= ht_cap
->cap
;
841 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
843 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
844 arg
->peer_flags
|= WMI_PEER_LDPC
;
846 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
847 arg
->peer_flags
|= WMI_PEER_40MHZ
;
848 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
851 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
852 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
854 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
855 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
857 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
858 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
859 arg
->peer_flags
|= WMI_PEER_STBC
;
862 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
864 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
865 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
866 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
867 arg
->peer_rate_caps
|= stbc
;
868 arg
->peer_flags
|= WMI_PEER_STBC
;
871 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
872 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
874 if (smps
== WLAN_HT_CAP_SM_PS_STATIC
) {
875 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
876 arg
->peer_flags
|= WMI_PEER_STATIC_MIMOPS
;
877 } else if (smps
== WLAN_HT_CAP_SM_PS_DYNAMIC
) {
878 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
879 arg
->peer_flags
|= WMI_PEER_DYN_MIMOPS
;
882 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
883 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
884 else if (ht_cap
->mcs
.rx_mask
[1])
885 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
887 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
888 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
889 arg
->peer_ht_rates
.rates
[n
++] = i
;
891 arg
->peer_ht_rates
.num_rates
= n
;
892 arg
->peer_num_spatial_streams
= max((n
+7) / 8, 1);
894 ath10k_dbg(ATH10K_DBG_MAC
, "mcs cnt %d nss %d\n",
895 arg
->peer_ht_rates
.num_rates
,
896 arg
->peer_num_spatial_streams
);
899 static void ath10k_peer_assoc_h_qos_ap(struct ath10k
*ar
,
900 struct ath10k_vif
*arvif
,
901 struct ieee80211_sta
*sta
,
902 struct ieee80211_bss_conf
*bss_conf
,
903 struct wmi_peer_assoc_complete_arg
*arg
)
909 arg
->peer_flags
|= WMI_PEER_QOS
;
911 if (sta
->wme
&& sta
->uapsd_queues
) {
912 ath10k_dbg(ATH10K_DBG_MAC
, "uapsd_queues: 0x%X, max_sp: %d\n",
913 sta
->uapsd_queues
, sta
->max_sp
);
915 arg
->peer_flags
|= WMI_PEER_APSD
;
916 arg
->peer_flags
|= WMI_RC_UAPSD_FLAG
;
918 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
919 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
920 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
921 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
922 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
923 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
924 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
925 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
926 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
927 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
928 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
929 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
932 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
933 max_sp
= sta
->max_sp
;
935 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
937 WMI_AP_PS_PEER_PARAM_UAPSD
,
940 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
942 WMI_AP_PS_PEER_PARAM_MAX_SP
,
945 /* TODO setup this based on STA listen interval and
946 beacon interval. Currently we don't know
947 sta->listen_interval - mac80211 patch required.
948 Currently use 10 seconds */
949 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
951 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
956 static void ath10k_peer_assoc_h_qos_sta(struct ath10k
*ar
,
957 struct ath10k_vif
*arvif
,
958 struct ieee80211_sta
*sta
,
959 struct ieee80211_bss_conf
*bss_conf
,
960 struct wmi_peer_assoc_complete_arg
*arg
)
963 arg
->peer_flags
|= WMI_PEER_QOS
;
966 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
967 struct ieee80211_sta
*sta
,
968 struct wmi_peer_assoc_complete_arg
*arg
)
970 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
972 if (!vht_cap
->vht_supported
)
975 arg
->peer_flags
|= WMI_PEER_VHT
;
977 arg
->peer_vht_caps
= vht_cap
->cap
;
979 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
980 arg
->peer_flags
|= WMI_PEER_80MHZ
;
982 arg
->peer_vht_rates
.rx_max_rate
=
983 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
984 arg
->peer_vht_rates
.rx_mcs_set
=
985 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
986 arg
->peer_vht_rates
.tx_max_rate
=
987 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
988 arg
->peer_vht_rates
.tx_mcs_set
=
989 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
991 ath10k_dbg(ATH10K_DBG_MAC
, "mac vht peer\n");
994 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
995 struct ath10k_vif
*arvif
,
996 struct ieee80211_sta
*sta
,
997 struct ieee80211_bss_conf
*bss_conf
,
998 struct wmi_peer_assoc_complete_arg
*arg
)
1000 switch (arvif
->vdev_type
) {
1001 case WMI_VDEV_TYPE_AP
:
1002 ath10k_peer_assoc_h_qos_ap(ar
, arvif
, sta
, bss_conf
, arg
);
1004 case WMI_VDEV_TYPE_STA
:
1005 ath10k_peer_assoc_h_qos_sta(ar
, arvif
, sta
, bss_conf
, arg
);
1012 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1013 struct ath10k_vif
*arvif
,
1014 struct ieee80211_sta
*sta
,
1015 struct wmi_peer_assoc_complete_arg
*arg
)
1017 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1019 /* FIXME: add VHT */
1021 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1022 case IEEE80211_BAND_2GHZ
:
1023 if (sta
->ht_cap
.ht_supported
) {
1024 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1025 phymode
= MODE_11NG_HT40
;
1027 phymode
= MODE_11NG_HT20
;
1033 case IEEE80211_BAND_5GHZ
:
1034 if (sta
->ht_cap
.ht_supported
) {
1035 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1036 phymode
= MODE_11NA_HT40
;
1038 phymode
= MODE_11NA_HT20
;
1048 arg
->peer_phymode
= phymode
;
1049 WARN_ON(phymode
== MODE_UNKNOWN
);
1052 static int ath10k_peer_assoc(struct ath10k
*ar
,
1053 struct ath10k_vif
*arvif
,
1054 struct ieee80211_sta
*sta
,
1055 struct ieee80211_bss_conf
*bss_conf
)
1057 struct wmi_peer_assoc_complete_arg arg
;
1059 memset(&arg
, 0, sizeof(struct wmi_peer_assoc_complete_arg
));
1061 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, &arg
);
1062 ath10k_peer_assoc_h_crypto(ar
, arvif
, &arg
);
1063 ath10k_peer_assoc_h_rates(ar
, sta
, &arg
);
1064 ath10k_peer_assoc_h_ht(ar
, sta
, &arg
);
1065 ath10k_peer_assoc_h_vht(ar
, sta
, &arg
);
1066 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, &arg
);
1067 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, &arg
);
1069 return ath10k_wmi_peer_assoc(ar
, &arg
);
1072 /* can be called only in mac80211 callbacks due to `key_count` usage */
1073 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1074 struct ieee80211_vif
*vif
,
1075 struct ieee80211_bss_conf
*bss_conf
)
1077 struct ath10k
*ar
= hw
->priv
;
1078 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1079 struct ieee80211_sta
*ap_sta
;
1084 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1086 ath10k_warn("Failed to find station entry for %pM\n",
1092 ret
= ath10k_peer_assoc(ar
, arvif
, ap_sta
, bss_conf
);
1094 ath10k_warn("Peer assoc failed for %pM\n", bss_conf
->bssid
);
1101 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, bss_conf
->aid
,
1104 ath10k_warn("VDEV: %d up failed: ret %d\n",
1105 arvif
->vdev_id
, ret
);
1107 ath10k_dbg(ATH10K_DBG_MAC
,
1108 "VDEV: %d associated, BSSID: %pM, AID: %d\n",
1109 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1115 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1116 struct ieee80211_vif
*vif
)
1118 struct ath10k
*ar
= hw
->priv
;
1119 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1123 * For some reason, calling VDEV-DOWN before VDEV-STOP
1124 * makes the FW to send frames via HTT after disassociation.
1125 * No idea why this happens, even though VDEV-DOWN is supposed
1126 * to be analogous to link down, so just stop the VDEV.
1128 ret
= ath10k_vdev_stop(arvif
);
1130 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d stopped\n",
1134 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1135 * report beacons from previously associated network through HTT.
1136 * This in turn would spam mac80211 WARN_ON if we bring down all
1137 * interfaces as it expects there is no rx when no interface is
1140 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1142 ath10k_dbg(ATH10K_DBG_MAC
, "VDEV: %d ath10k_wmi_vdev_down failed (%d)\n",
1143 arvif
->vdev_id
, ret
);
1145 ath10k_wmi_flush_tx(ar
);
1147 arvif
->def_wep_key_index
= 0;
1150 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1151 struct ieee80211_sta
*sta
)
1155 ret
= ath10k_peer_assoc(ar
, arvif
, sta
, NULL
);
1157 ath10k_warn("WMI peer assoc failed for %pM\n", sta
->addr
);
1161 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1163 ath10k_warn("could not install peer wep keys (%d)\n", ret
);
1170 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1171 struct ieee80211_sta
*sta
)
1175 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1177 ath10k_warn("could not clear all peer wep keys (%d)\n", ret
);
1188 static int ath10k_update_channel_list(struct ath10k
*ar
)
1190 struct ieee80211_hw
*hw
= ar
->hw
;
1191 struct ieee80211_supported_band
**bands
;
1192 enum ieee80211_band band
;
1193 struct ieee80211_channel
*channel
;
1194 struct wmi_scan_chan_list_arg arg
= {0};
1195 struct wmi_channel_arg
*ch
;
1201 bands
= hw
->wiphy
->bands
;
1202 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1206 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1207 if (bands
[band
]->channels
[i
].flags
&
1208 IEEE80211_CHAN_DISABLED
)
1215 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1216 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1221 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1225 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1226 channel
= &bands
[band
]->channels
[i
];
1228 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1231 ch
->allow_ht
= true;
1233 /* FIXME: when should we really allow VHT? */
1234 ch
->allow_vht
= true;
1237 !(channel
->flags
& IEEE80211_CHAN_NO_IBSS
);
1240 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1242 passive
= channel
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
;
1243 ch
->passive
= passive
;
1245 ch
->freq
= channel
->center_freq
;
1246 ch
->min_power
= channel
->max_power
* 3;
1247 ch
->max_power
= channel
->max_power
* 4;
1248 ch
->max_reg_power
= channel
->max_reg_power
* 4;
1249 ch
->max_antenna_gain
= channel
->max_antenna_gain
;
1250 ch
->reg_class_id
= 0; /* FIXME */
1252 /* FIXME: why use only legacy modes, why not any
1253 * HT/VHT modes? Would that even make any
1255 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1256 ch
->mode
= MODE_11G
;
1258 ch
->mode
= MODE_11A
;
1260 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1263 ath10k_dbg(ATH10K_DBG_WMI
,
1264 "%s: [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1265 __func__
, ch
- arg
.channels
, arg
.n_channels
,
1266 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1267 ch
->max_antenna_gain
, ch
->mode
);
1273 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1274 kfree(arg
.channels
);
1279 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1280 struct regulatory_request
*request
)
1282 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1283 struct reg_dmn_pair_mapping
*regpair
;
1284 struct ath10k
*ar
= hw
->priv
;
1287 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1289 ret
= ath10k_update_channel_list(ar
);
1291 ath10k_warn("could not update channel list (%d)\n", ret
);
1293 regpair
= ar
->ath_common
.regulatory
.regpair
;
1294 /* Target allows setting up per-band regdomain but ath_common provides
1295 * a combined one only */
1296 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1297 regpair
->regDmnEnum
,
1298 regpair
->regDmnEnum
, /* 2ghz */
1299 regpair
->regDmnEnum
, /* 5ghz */
1300 regpair
->reg_2ghz_ctl
,
1301 regpair
->reg_5ghz_ctl
);
1303 ath10k_warn("could not set pdev regdomain (%d)\n", ret
);
1311 * Frames sent to the FW have to be in "Native Wifi" format.
1312 * Strip the QoS field from the 802.11 header.
1314 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw
*hw
,
1315 struct ieee80211_tx_control
*control
,
1316 struct sk_buff
*skb
)
1318 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1321 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1324 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1325 memmove(qos_ctl
, qos_ctl
+ IEEE80211_QOS_CTL_LEN
,
1326 skb
->len
- ieee80211_hdrlen(hdr
->frame_control
));
1327 skb_trim(skb
, skb
->len
- IEEE80211_QOS_CTL_LEN
);
1330 static void ath10k_tx_h_update_wep_key(struct sk_buff
*skb
)
1332 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1333 struct ieee80211_vif
*vif
= info
->control
.vif
;
1334 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1335 struct ath10k
*ar
= arvif
->ar
;
1336 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1337 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
1340 /* TODO AP mode should be implemented */
1341 if (vif
->type
!= NL80211_IFTYPE_STATION
)
1344 if (!ieee80211_has_protected(hdr
->frame_control
))
1350 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1351 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1354 if (key
->keyidx
== arvif
->def_wep_key_index
)
1357 ath10k_dbg(ATH10K_DBG_MAC
, "new wep keyidx will be %d\n", key
->keyidx
);
1359 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1360 WMI_VDEV_PARAM_DEF_KEYID
,
1363 ath10k_warn("could not update wep keyidx (%d)\n", ret
);
1367 arvif
->def_wep_key_index
= key
->keyidx
;
1370 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
, struct sk_buff
*skb
)
1372 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1373 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1374 struct ieee80211_vif
*vif
= info
->control
.vif
;
1375 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1377 /* This is case only for P2P_GO */
1378 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1379 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1382 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1383 spin_lock_bh(&ar
->data_lock
);
1384 if (arvif
->u
.ap
.noa_data
)
1385 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1387 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1388 arvif
->u
.ap
.noa_data
,
1389 arvif
->u
.ap
.noa_len
);
1390 spin_unlock_bh(&ar
->data_lock
);
1394 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1396 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1399 if (ieee80211_is_mgmt(hdr
->frame_control
))
1400 ret
= ath10k_htt_mgmt_tx(ar
->htt
, skb
);
1401 else if (ieee80211_is_nullfunc(hdr
->frame_control
))
1402 /* FW does not report tx status properly for NullFunc frames
1403 * unless they are sent through mgmt tx path. mac80211 sends
1404 * those frames when it detects link/beacon loss and depends on
1405 * the tx status to be correct. */
1406 ret
= ath10k_htt_mgmt_tx(ar
->htt
, skb
);
1408 ret
= ath10k_htt_tx(ar
->htt
, skb
);
1411 ath10k_warn("tx failed (%d). dropping packet.\n", ret
);
1412 ieee80211_free_txskb(ar
->hw
, skb
);
1416 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
1418 struct sk_buff
*skb
;
1421 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1425 ieee80211_free_txskb(ar
->hw
, skb
);
1429 void ath10k_offchan_tx_work(struct work_struct
*work
)
1431 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
1432 struct ath10k_peer
*peer
;
1433 struct ieee80211_hdr
*hdr
;
1434 struct sk_buff
*skb
;
1435 const u8
*peer_addr
;
1439 /* FW requirement: We must create a peer before FW will send out
1440 * an offchannel frame. Otherwise the frame will be stuck and
1441 * never transmitted. We delete the peer upon tx completion.
1442 * It is unlikely that a peer for offchannel tx will already be
1443 * present. However it may be in some rare cases so account for that.
1444 * Otherwise we might remove a legitimate peer and break stuff. */
1447 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1451 mutex_lock(&ar
->conf_mutex
);
1453 ath10k_dbg(ATH10K_DBG_MAC
, "processing offchannel skb %p\n",
1456 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1457 peer_addr
= ieee80211_get_DA(hdr
);
1458 vdev_id
= ATH10K_SKB_CB(skb
)->htt
.vdev_id
;
1460 spin_lock_bh(&ar
->data_lock
);
1461 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
1462 spin_unlock_bh(&ar
->data_lock
);
1465 ath10k_dbg(ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
1466 peer_addr
, vdev_id
);
1469 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
1471 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1472 peer_addr
, vdev_id
, ret
);
1475 spin_lock_bh(&ar
->data_lock
);
1476 INIT_COMPLETION(ar
->offchan_tx_completed
);
1477 ar
->offchan_tx_skb
= skb
;
1478 spin_unlock_bh(&ar
->data_lock
);
1480 ath10k_tx_htt(ar
, skb
);
1482 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
1485 ath10k_warn("timed out waiting for offchannel skb %p\n",
1489 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
1491 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1492 peer_addr
, vdev_id
, ret
);
1495 mutex_unlock(&ar
->conf_mutex
);
1504 * This gets called if we dont get a heart-beat during scan.
1505 * This may indicate the FW has hung and we need to abort the
1506 * scan manually to prevent cancel_hw_scan() from deadlocking
1508 void ath10k_reset_scan(unsigned long ptr
)
1510 struct ath10k
*ar
= (struct ath10k
*)ptr
;
1512 spin_lock_bh(&ar
->data_lock
);
1513 if (!ar
->scan
.in_progress
) {
1514 spin_unlock_bh(&ar
->data_lock
);
1518 ath10k_warn("scan timeout. resetting. fw issue?\n");
1520 if (ar
->scan
.is_roc
)
1521 ieee80211_remain_on_channel_expired(ar
->hw
);
1523 ieee80211_scan_completed(ar
->hw
, 1 /* aborted */);
1525 ar
->scan
.in_progress
= false;
1526 complete_all(&ar
->scan
.completed
);
1527 spin_unlock_bh(&ar
->data_lock
);
1530 static int ath10k_abort_scan(struct ath10k
*ar
)
1532 struct wmi_stop_scan_arg arg
= {
1533 .req_id
= 1, /* FIXME */
1534 .req_type
= WMI_SCAN_STOP_ONE
,
1535 .u
.scan_id
= ATH10K_SCAN_ID
,
1539 lockdep_assert_held(&ar
->conf_mutex
);
1541 del_timer_sync(&ar
->scan
.timeout
);
1543 spin_lock_bh(&ar
->data_lock
);
1544 if (!ar
->scan
.in_progress
) {
1545 spin_unlock_bh(&ar
->data_lock
);
1549 ar
->scan
.aborting
= true;
1550 spin_unlock_bh(&ar
->data_lock
);
1552 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
1554 ath10k_warn("could not submit wmi stop scan (%d)\n", ret
);
1558 ath10k_wmi_flush_tx(ar
);
1560 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
1562 ath10k_warn("timed out while waiting for scan to stop\n");
1564 /* scan completion may be done right after we timeout here, so let's
1565 * check the in_progress and tell mac80211 scan is completed. if we
1566 * don't do that and FW fails to send us scan completion indication
1567 * then userspace won't be able to scan anymore */
1570 spin_lock_bh(&ar
->data_lock
);
1571 if (ar
->scan
.in_progress
) {
1572 ath10k_warn("could not stop scan. its still in progress\n");
1573 ar
->scan
.in_progress
= false;
1574 ath10k_offchan_tx_purge(ar
);
1577 spin_unlock_bh(&ar
->data_lock
);
1582 static int ath10k_start_scan(struct ath10k
*ar
,
1583 const struct wmi_start_scan_arg
*arg
)
1587 lockdep_assert_held(&ar
->conf_mutex
);
1589 ret
= ath10k_wmi_start_scan(ar
, arg
);
1593 /* make sure we submit the command so the completion
1594 * timeout makes sense */
1595 ath10k_wmi_flush_tx(ar
);
1597 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
1599 ath10k_abort_scan(ar
);
1603 /* the scan can complete earlier, before we even
1604 * start the timer. in that case the timer handler
1605 * checks ar->scan.in_progress and bails out if its
1606 * false. Add a 200ms margin to account event/command
1608 mod_timer(&ar
->scan
.timeout
, jiffies
+
1609 msecs_to_jiffies(arg
->max_scan_time
+200));
1613 /**********************/
1614 /* mac80211 callbacks */
1615 /**********************/
1617 static void ath10k_tx(struct ieee80211_hw
*hw
,
1618 struct ieee80211_tx_control
*control
,
1619 struct sk_buff
*skb
)
1621 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1622 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1623 struct ath10k
*ar
= hw
->priv
;
1624 struct ath10k_vif
*arvif
= NULL
;
1628 if (info
->control
.vif
) {
1629 arvif
= ath10k_vif_to_arvif(info
->control
.vif
);
1630 vdev_id
= arvif
->vdev_id
;
1631 } else if (ar
->monitor_enabled
) {
1632 vdev_id
= ar
->monitor_vdev_id
;
1635 /* We should disable CCK RATE due to P2P */
1636 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
1637 ath10k_dbg(ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
1639 /* we must calculate tid before we apply qos workaround
1640 * as we'd lose the qos control field */
1641 tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1642 if (ieee80211_is_data_qos(hdr
->frame_control
) &&
1643 is_unicast_ether_addr(ieee80211_get_DA(hdr
))) {
1644 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
1645 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
1648 ath10k_tx_h_qos_workaround(hw
, control
, skb
);
1649 ath10k_tx_h_update_wep_key(skb
);
1650 ath10k_tx_h_add_p2p_noa_ie(ar
, skb
);
1651 ath10k_tx_h_seq_no(skb
);
1653 memset(ATH10K_SKB_CB(skb
), 0, sizeof(*ATH10K_SKB_CB(skb
)));
1654 ATH10K_SKB_CB(skb
)->htt
.vdev_id
= vdev_id
;
1655 ATH10K_SKB_CB(skb
)->htt
.tid
= tid
;
1657 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
1658 spin_lock_bh(&ar
->data_lock
);
1659 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
1660 ATH10K_SKB_CB(skb
)->htt
.vdev_id
= ar
->scan
.vdev_id
;
1661 spin_unlock_bh(&ar
->data_lock
);
1663 ath10k_dbg(ATH10K_DBG_MAC
, "queued offchannel skb %p\n", skb
);
1665 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
1666 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
1670 ath10k_tx_htt(ar
, skb
);
1674 * Initialize various parameters with default vaules.
1676 static int ath10k_start(struct ieee80211_hw
*hw
)
1678 struct ath10k
*ar
= hw
->priv
;
1681 ret
= ath10k_wmi_pdev_set_param(ar
, WMI_PDEV_PARAM_PMF_QOS
, 1);
1683 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
1686 ret
= ath10k_wmi_pdev_set_param(ar
, WMI_PDEV_PARAM_DYNAMIC_BW
, 0);
1688 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
1694 static void ath10k_stop(struct ieee80211_hw
*hw
)
1696 struct ath10k
*ar
= hw
->priv
;
1698 /* avoid leaks in case FW never confirms scan for offchannel */
1699 cancel_work_sync(&ar
->offchan_tx_work
);
1700 ath10k_offchan_tx_purge(ar
);
1703 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
1705 struct ath10k_generic_iter ar_iter
;
1706 struct ath10k
*ar
= hw
->priv
;
1707 struct ieee80211_conf
*conf
= &hw
->conf
;
1711 mutex_lock(&ar
->conf_mutex
);
1713 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1714 ath10k_dbg(ATH10K_DBG_MAC
, "Config channel %d mhz\n",
1715 conf
->chandef
.chan
->center_freq
);
1716 spin_lock_bh(&ar
->data_lock
);
1717 ar
->rx_channel
= conf
->chandef
.chan
;
1718 spin_unlock_bh(&ar
->data_lock
);
1721 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1722 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
1724 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
1726 ieee80211_iterate_active_interfaces_atomic(hw
,
1734 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1735 if (conf
->flags
& IEEE80211_CONF_MONITOR
)
1736 ret
= ath10k_monitor_create(ar
);
1738 ret
= ath10k_monitor_destroy(ar
);
1741 mutex_unlock(&ar
->conf_mutex
);
1747 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
1748 * because we will send mgmt frames without CCK. This requirement
1749 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
1752 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
1753 struct ieee80211_vif
*vif
)
1755 struct ath10k
*ar
= hw
->priv
;
1756 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1757 enum wmi_sta_powersave_param param
;
1762 mutex_lock(&ar
->conf_mutex
);
1767 if ((vif
->type
== NL80211_IFTYPE_MONITOR
) && ar
->monitor_present
) {
1768 ath10k_warn("Only one monitor interface allowed\n");
1773 bit
= ffs(ar
->free_vdev_map
);
1779 arvif
->vdev_id
= bit
- 1;
1780 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
1781 ar
->free_vdev_map
&= ~(1 << arvif
->vdev_id
);
1784 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
1786 switch (vif
->type
) {
1787 case NL80211_IFTYPE_UNSPECIFIED
:
1788 case NL80211_IFTYPE_STATION
:
1789 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
1791 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
1793 case NL80211_IFTYPE_ADHOC
:
1794 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
1796 case NL80211_IFTYPE_AP
:
1797 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
1800 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
1802 case NL80211_IFTYPE_MONITOR
:
1803 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
1810 ath10k_dbg(ATH10K_DBG_MAC
, "Add interface: id %d type %d subtype %d\n",
1811 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
1813 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
1814 arvif
->vdev_subtype
, vif
->addr
);
1816 ath10k_warn("WMI vdev create failed: ret %d\n", ret
);
1820 ret
= ath10k_wmi_vdev_set_param(ar
, 0, WMI_VDEV_PARAM_DEF_KEYID
,
1821 arvif
->def_wep_key_index
);
1823 ath10k_warn("Failed to set default keyid: %d\n", ret
);
1825 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1826 WMI_VDEV_PARAM_TX_ENCAP_TYPE
,
1827 ATH10K_HW_TXRX_NATIVE_WIFI
);
1829 ath10k_warn("Failed to set TX encap: %d\n", ret
);
1831 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1832 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
1834 ath10k_warn("Failed to create peer for AP: %d\n", ret
);
1839 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
1840 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
1841 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
1842 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1845 ath10k_warn("Failed to set RX wake policy: %d\n", ret
);
1847 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
1848 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
1849 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1852 ath10k_warn("Failed to set TX wake thresh: %d\n", ret
);
1854 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
1855 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
1856 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
1859 ath10k_warn("Failed to set PSPOLL count: %d\n", ret
);
1862 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
1863 ar
->monitor_present
= true;
1866 mutex_unlock(&ar
->conf_mutex
);
1870 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
1871 struct ieee80211_vif
*vif
)
1873 struct ath10k
*ar
= hw
->priv
;
1874 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1877 mutex_lock(&ar
->conf_mutex
);
1879 ath10k_dbg(ATH10K_DBG_MAC
, "Remove interface: id %d\n", arvif
->vdev_id
);
1881 ar
->free_vdev_map
|= 1 << (arvif
->vdev_id
);
1883 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
1884 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
1886 ath10k_warn("Failed to remove peer for AP: %d\n", ret
);
1888 kfree(arvif
->u
.ap
.noa_data
);
1891 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
1893 ath10k_warn("WMI vdev delete failed: %d\n", ret
);
1895 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
1896 ar
->monitor_present
= false;
1898 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
1900 mutex_unlock(&ar
->conf_mutex
);
1904 * FIXME: Has to be verified.
1906 #define SUPPORTED_FILTERS \
1907 (FIF_PROMISC_IN_BSS | \
1912 FIF_BCN_PRBRESP_PROMISC | \
1916 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
1917 unsigned int changed_flags
,
1918 unsigned int *total_flags
,
1921 struct ath10k
*ar
= hw
->priv
;
1924 mutex_lock(&ar
->conf_mutex
);
1926 changed_flags
&= SUPPORTED_FILTERS
;
1927 *total_flags
&= SUPPORTED_FILTERS
;
1928 ar
->filter_flags
= *total_flags
;
1930 if ((ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
1931 !ar
->monitor_enabled
) {
1932 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
1934 ath10k_warn("Unable to start monitor mode\n");
1936 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor mode started\n");
1937 } else if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
1938 ar
->monitor_enabled
) {
1939 ret
= ath10k_monitor_stop(ar
);
1941 ath10k_warn("Unable to stop monitor mode\n");
1943 ath10k_dbg(ATH10K_DBG_MAC
, "Monitor mode stopped\n");
1946 mutex_unlock(&ar
->conf_mutex
);
1949 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
1950 struct ieee80211_vif
*vif
,
1951 struct ieee80211_bss_conf
*info
,
1954 struct ath10k
*ar
= hw
->priv
;
1955 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1958 mutex_lock(&ar
->conf_mutex
);
1960 if (changed
& BSS_CHANGED_IBSS
)
1961 ath10k_control_ibss(arvif
, info
, vif
->addr
);
1963 if (changed
& BSS_CHANGED_BEACON_INT
) {
1964 arvif
->beacon_interval
= info
->beacon_int
;
1965 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1966 WMI_VDEV_PARAM_BEACON_INTERVAL
,
1967 arvif
->beacon_interval
);
1969 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
1972 ath10k_dbg(ATH10K_DBG_MAC
,
1973 "Beacon interval: %d set for VDEV: %d\n",
1974 arvif
->beacon_interval
, arvif
->vdev_id
);
1977 if (changed
& BSS_CHANGED_BEACON
) {
1978 ret
= ath10k_wmi_pdev_set_param(ar
,
1979 WMI_PDEV_PARAM_BEACON_TX_MODE
,
1980 WMI_BEACON_STAGGERED_MODE
);
1982 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
1985 ath10k_dbg(ATH10K_DBG_MAC
,
1986 "Set staggered beacon mode for VDEV: %d\n",
1990 if (changed
& BSS_CHANGED_BEACON_INFO
) {
1991 arvif
->dtim_period
= info
->dtim_period
;
1993 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
1994 WMI_VDEV_PARAM_DTIM_PERIOD
,
1995 arvif
->dtim_period
);
1997 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2000 ath10k_dbg(ATH10K_DBG_MAC
,
2001 "Set dtim period: %d for VDEV: %d\n",
2002 arvif
->dtim_period
, arvif
->vdev_id
);
2005 if (changed
& BSS_CHANGED_SSID
&&
2006 vif
->type
== NL80211_IFTYPE_AP
) {
2007 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
2009 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
2010 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
2013 if (changed
& BSS_CHANGED_BSSID
) {
2014 if (!is_zero_ether_addr(info
->bssid
)) {
2015 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
2018 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2019 info
->bssid
, arvif
->vdev_id
);
2021 ath10k_dbg(ATH10K_DBG_MAC
,
2022 "Added peer: %pM for VDEV: %d\n",
2023 info
->bssid
, arvif
->vdev_id
);
2026 if (vif
->type
== NL80211_IFTYPE_STATION
) {
2028 * this is never erased as we it for crypto key
2029 * clearing; this is FW requirement
2031 memcpy(arvif
->u
.sta
.bssid
, info
->bssid
,
2034 ret
= ath10k_vdev_start(arvif
);
2036 ath10k_dbg(ATH10K_DBG_MAC
,
2037 "VDEV: %d started with BSSID: %pM\n",
2038 arvif
->vdev_id
, info
->bssid
);
2042 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2043 * so driver need to store it. It is needed when leaving
2044 * IBSS in order to remove BSSID peer.
2046 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
2047 memcpy(arvif
->u
.ibss
.bssid
, info
->bssid
,
2052 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
2053 ath10k_control_beaconing(arvif
, info
);
2055 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
2057 if (info
->use_cts_prot
)
2062 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2063 WMI_VDEV_PARAM_ENABLE_RTSCTS
,
2066 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2069 ath10k_dbg(ATH10K_DBG_MAC
,
2070 "Set CTS prot: %d for VDEV: %d\n",
2071 cts_prot
, arvif
->vdev_id
);
2074 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2076 if (info
->use_short_slot
)
2077 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
2080 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
2082 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2083 WMI_VDEV_PARAM_SLOT_TIME
,
2086 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2089 ath10k_dbg(ATH10K_DBG_MAC
,
2090 "Set slottime: %d for VDEV: %d\n",
2091 slottime
, arvif
->vdev_id
);
2094 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
2096 if (info
->use_short_preamble
)
2097 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
2099 preamble
= WMI_VDEV_PREAMBLE_LONG
;
2101 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
2102 WMI_VDEV_PARAM_PREAMBLE
,
2105 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2108 ath10k_dbg(ATH10K_DBG_MAC
,
2109 "Set preamble: %d for VDEV: %d\n",
2110 preamble
, arvif
->vdev_id
);
2113 if (changed
& BSS_CHANGED_ASSOC
) {
2115 ath10k_bss_assoc(hw
, vif
, info
);
2118 mutex_unlock(&ar
->conf_mutex
);
2121 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
2122 struct ieee80211_vif
*vif
,
2123 struct cfg80211_scan_request
*req
)
2125 struct ath10k
*ar
= hw
->priv
;
2126 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2127 struct wmi_start_scan_arg arg
;
2131 mutex_lock(&ar
->conf_mutex
);
2133 spin_lock_bh(&ar
->data_lock
);
2134 if (ar
->scan
.in_progress
) {
2135 spin_unlock_bh(&ar
->data_lock
);
2140 INIT_COMPLETION(ar
->scan
.started
);
2141 INIT_COMPLETION(ar
->scan
.completed
);
2142 ar
->scan
.in_progress
= true;
2143 ar
->scan
.aborting
= false;
2144 ar
->scan
.is_roc
= false;
2145 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2146 spin_unlock_bh(&ar
->data_lock
);
2148 memset(&arg
, 0, sizeof(arg
));
2149 ath10k_wmi_start_scan_init(ar
, &arg
);
2150 arg
.vdev_id
= arvif
->vdev_id
;
2151 arg
.scan_id
= ATH10K_SCAN_ID
;
2154 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
2157 arg
.ie_len
= req
->ie_len
;
2158 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
2162 arg
.n_ssids
= req
->n_ssids
;
2163 for (i
= 0; i
< arg
.n_ssids
; i
++) {
2164 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
2165 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
2169 if (req
->n_channels
) {
2170 arg
.n_channels
= req
->n_channels
;
2171 for (i
= 0; i
< arg
.n_channels
; i
++)
2172 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
2175 ret
= ath10k_start_scan(ar
, &arg
);
2177 ath10k_warn("could not start hw scan (%d)\n", ret
);
2178 spin_lock_bh(&ar
->data_lock
);
2179 ar
->scan
.in_progress
= false;
2180 spin_unlock_bh(&ar
->data_lock
);
2184 mutex_unlock(&ar
->conf_mutex
);
2188 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
2189 struct ieee80211_vif
*vif
)
2191 struct ath10k
*ar
= hw
->priv
;
2194 mutex_lock(&ar
->conf_mutex
);
2195 ret
= ath10k_abort_scan(ar
);
2197 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2199 ieee80211_scan_completed(hw
, 1 /* aborted */);
2201 mutex_unlock(&ar
->conf_mutex
);
2204 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2205 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
2206 struct ieee80211_key_conf
*key
)
2208 struct ath10k
*ar
= hw
->priv
;
2209 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2210 struct ath10k_peer
*peer
;
2211 const u8
*peer_addr
;
2212 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2213 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
2216 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
2219 mutex_lock(&ar
->conf_mutex
);
2222 peer_addr
= sta
->addr
;
2223 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
2224 peer_addr
= vif
->bss_conf
.bssid
;
2226 peer_addr
= vif
->addr
;
2228 key
->hw_key_idx
= key
->keyidx
;
2230 /* the peer should not disappear in mid-way (unless FW goes awry) since
2231 * we already hold conf_mutex. we just make sure its there now. */
2232 spin_lock_bh(&ar
->data_lock
);
2233 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2234 spin_unlock_bh(&ar
->data_lock
);
2237 if (cmd
== SET_KEY
) {
2238 ath10k_warn("cannot install key for non-existent peer %pM\n",
2243 /* if the peer doesn't exist there is no key to disable
2251 arvif
->wep_keys
[key
->keyidx
] = key
;
2253 arvif
->wep_keys
[key
->keyidx
] = NULL
;
2255 if (cmd
== DISABLE_KEY
)
2256 ath10k_clear_vdev_key(arvif
, key
);
2259 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
2261 ath10k_warn("ath10k_install_key failed (%d)\n", ret
);
2265 spin_lock_bh(&ar
->data_lock
);
2266 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2267 if (peer
&& cmd
== SET_KEY
)
2268 peer
->keys
[key
->keyidx
] = key
;
2269 else if (peer
&& cmd
== DISABLE_KEY
)
2270 peer
->keys
[key
->keyidx
] = NULL
;
2271 else if (peer
== NULL
)
2272 /* impossible unless FW goes crazy */
2273 ath10k_warn("peer %pM disappeared!\n", peer_addr
);
2274 spin_unlock_bh(&ar
->data_lock
);
2277 mutex_unlock(&ar
->conf_mutex
);
2281 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
2282 struct ieee80211_vif
*vif
,
2283 struct ieee80211_sta
*sta
,
2284 enum ieee80211_sta_state old_state
,
2285 enum ieee80211_sta_state new_state
)
2287 struct ath10k
*ar
= hw
->priv
;
2288 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2291 mutex_lock(&ar
->conf_mutex
);
2293 if (old_state
== IEEE80211_STA_NOTEXIST
&&
2294 new_state
== IEEE80211_STA_NONE
&&
2295 vif
->type
!= NL80211_IFTYPE_STATION
) {
2297 * New station addition.
2299 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
2301 ath10k_warn("Failed to add peer: %pM for VDEV: %d\n",
2302 sta
->addr
, arvif
->vdev_id
);
2304 ath10k_dbg(ATH10K_DBG_MAC
,
2305 "Added peer: %pM for VDEV: %d\n",
2306 sta
->addr
, arvif
->vdev_id
);
2307 } else if ((old_state
== IEEE80211_STA_NONE
&&
2308 new_state
== IEEE80211_STA_NOTEXIST
)) {
2310 * Existing station deletion.
2312 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
2314 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2315 sta
->addr
, arvif
->vdev_id
);
2317 ath10k_dbg(ATH10K_DBG_MAC
,
2318 "Removed peer: %pM for VDEV: %d\n",
2319 sta
->addr
, arvif
->vdev_id
);
2321 if (vif
->type
== NL80211_IFTYPE_STATION
)
2322 ath10k_bss_disassoc(hw
, vif
);
2323 } else if (old_state
== IEEE80211_STA_AUTH
&&
2324 new_state
== IEEE80211_STA_ASSOC
&&
2325 (vif
->type
== NL80211_IFTYPE_AP
||
2326 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2330 ret
= ath10k_station_assoc(ar
, arvif
, sta
);
2332 ath10k_warn("Failed to associate station: %pM\n",
2335 ath10k_dbg(ATH10K_DBG_MAC
,
2336 "Station %pM moved to assoc state\n",
2338 } else if (old_state
== IEEE80211_STA_ASSOC
&&
2339 new_state
== IEEE80211_STA_AUTH
&&
2340 (vif
->type
== NL80211_IFTYPE_AP
||
2341 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2345 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
2347 ath10k_warn("Failed to disassociate station: %pM\n",
2350 ath10k_dbg(ATH10K_DBG_MAC
,
2351 "Station %pM moved to disassociated state\n",
2355 mutex_unlock(&ar
->conf_mutex
);
2359 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
2360 u16 ac
, bool enable
)
2362 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2366 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
2370 case IEEE80211_AC_VO
:
2371 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
2372 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
2374 case IEEE80211_AC_VI
:
2375 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
2376 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
2378 case IEEE80211_AC_BE
:
2379 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
2380 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
2382 case IEEE80211_AC_BK
:
2383 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
2384 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
2389 arvif
->u
.sta
.uapsd
|= value
;
2391 arvif
->u
.sta
.uapsd
&= ~value
;
2393 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2394 WMI_STA_PS_PARAM_UAPSD
,
2395 arvif
->u
.sta
.uapsd
);
2397 ath10k_warn("could not set uapsd params %d\n", ret
);
2401 if (arvif
->u
.sta
.uapsd
)
2402 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
2404 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2406 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2407 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
2410 ath10k_warn("could not set rx wake param %d\n", ret
);
2416 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
2417 struct ieee80211_vif
*vif
, u16 ac
,
2418 const struct ieee80211_tx_queue_params
*params
)
2420 struct ath10k
*ar
= hw
->priv
;
2421 struct wmi_wmm_params_arg
*p
= NULL
;
2424 mutex_lock(&ar
->conf_mutex
);
2427 case IEEE80211_AC_VO
:
2428 p
= &ar
->wmm_params
.ac_vo
;
2430 case IEEE80211_AC_VI
:
2431 p
= &ar
->wmm_params
.ac_vi
;
2433 case IEEE80211_AC_BE
:
2434 p
= &ar
->wmm_params
.ac_be
;
2436 case IEEE80211_AC_BK
:
2437 p
= &ar
->wmm_params
.ac_bk
;
2446 p
->cwmin
= params
->cw_min
;
2447 p
->cwmax
= params
->cw_max
;
2448 p
->aifs
= params
->aifs
;
2451 * The channel time duration programmed in the HW is in absolute
2452 * microseconds, while mac80211 gives the txop in units of
2455 p
->txop
= params
->txop
* 32;
2457 /* FIXME: FW accepts wmm params per hw, not per vif */
2458 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
2460 ath10k_warn("could not set wmm params %d\n", ret
);
2464 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
2466 ath10k_warn("could not set sta uapsd %d\n", ret
);
2469 mutex_unlock(&ar
->conf_mutex
);
2473 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
2475 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
2476 struct ieee80211_vif
*vif
,
2477 struct ieee80211_channel
*chan
,
2479 enum ieee80211_roc_type type
)
2481 struct ath10k
*ar
= hw
->priv
;
2482 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2483 struct wmi_start_scan_arg arg
;
2486 mutex_lock(&ar
->conf_mutex
);
2488 spin_lock_bh(&ar
->data_lock
);
2489 if (ar
->scan
.in_progress
) {
2490 spin_unlock_bh(&ar
->data_lock
);
2495 INIT_COMPLETION(ar
->scan
.started
);
2496 INIT_COMPLETION(ar
->scan
.completed
);
2497 INIT_COMPLETION(ar
->scan
.on_channel
);
2498 ar
->scan
.in_progress
= true;
2499 ar
->scan
.aborting
= false;
2500 ar
->scan
.is_roc
= true;
2501 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2502 ar
->scan
.roc_freq
= chan
->center_freq
;
2503 spin_unlock_bh(&ar
->data_lock
);
2505 memset(&arg
, 0, sizeof(arg
));
2506 ath10k_wmi_start_scan_init(ar
, &arg
);
2507 arg
.vdev_id
= arvif
->vdev_id
;
2508 arg
.scan_id
= ATH10K_SCAN_ID
;
2510 arg
.channels
[0] = chan
->center_freq
;
2511 arg
.dwell_time_active
= duration
;
2512 arg
.dwell_time_passive
= duration
;
2513 arg
.max_scan_time
= 2 * duration
;
2514 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2515 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
2517 ret
= ath10k_start_scan(ar
, &arg
);
2519 ath10k_warn("could not start roc scan (%d)\n", ret
);
2520 spin_lock_bh(&ar
->data_lock
);
2521 ar
->scan
.in_progress
= false;
2522 spin_unlock_bh(&ar
->data_lock
);
2526 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
2528 ath10k_warn("could not switch to channel for roc scan\n");
2529 ath10k_abort_scan(ar
);
2536 mutex_unlock(&ar
->conf_mutex
);
2540 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
2542 struct ath10k
*ar
= hw
->priv
;
2544 mutex_lock(&ar
->conf_mutex
);
2545 ath10k_abort_scan(ar
);
2546 mutex_unlock(&ar
->conf_mutex
);
2552 * Both RTS and Fragmentation threshold are interface-specific
2553 * in ath10k, but device-specific in mac80211.
2555 static void ath10k_set_rts_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
2557 struct ath10k_generic_iter
*ar_iter
= data
;
2558 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2559 u32 rts
= ar_iter
->ar
->hw
->wiphy
->rts_threshold
;
2561 rts
= min_t(u32
, rts
, ATH10K_RTS_MAX
);
2563 ar_iter
->ret
= ath10k_wmi_vdev_set_param(ar_iter
->ar
, arvif
->vdev_id
,
2564 WMI_VDEV_PARAM_RTS_THRESHOLD
,
2567 ath10k_warn("Failed to set RTS threshold for VDEV: %d\n",
2570 ath10k_dbg(ATH10K_DBG_MAC
,
2571 "Set RTS threshold: %d for VDEV: %d\n",
2572 rts
, arvif
->vdev_id
);
2575 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
2577 struct ath10k_generic_iter ar_iter
;
2578 struct ath10k
*ar
= hw
->priv
;
2580 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
2583 mutex_lock(&ar
->conf_mutex
);
2584 ieee80211_iterate_active_interfaces(hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
2585 ath10k_set_rts_iter
, &ar_iter
);
2586 mutex_unlock(&ar
->conf_mutex
);
2591 static void ath10k_set_frag_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
2593 struct ath10k_generic_iter
*ar_iter
= data
;
2594 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2595 u32 frag
= ar_iter
->ar
->hw
->wiphy
->frag_threshold
;
2598 frag
= clamp_t(u32
, frag
,
2599 ATH10K_FRAGMT_THRESHOLD_MIN
,
2600 ATH10K_FRAGMT_THRESHOLD_MAX
);
2602 ret
= ath10k_wmi_vdev_set_param(ar_iter
->ar
, arvif
->vdev_id
,
2603 WMI_VDEV_PARAM_FRAGMENTATION_THRESHOLD
,
2608 ath10k_warn("Failed to set frag threshold for VDEV: %d\n",
2611 ath10k_dbg(ATH10K_DBG_MAC
,
2612 "Set frag threshold: %d for VDEV: %d\n",
2613 frag
, arvif
->vdev_id
);
2616 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
2618 struct ath10k_generic_iter ar_iter
;
2619 struct ath10k
*ar
= hw
->priv
;
2621 memset(&ar_iter
, 0, sizeof(struct ath10k_generic_iter
));
2624 mutex_lock(&ar
->conf_mutex
);
2625 ieee80211_iterate_active_interfaces(hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
2626 ath10k_set_frag_iter
, &ar_iter
);
2627 mutex_unlock(&ar
->conf_mutex
);
2632 static void ath10k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
2634 struct ath10k
*ar
= hw
->priv
;
2637 /* mac80211 doesn't care if we really xmit queued frames or not
2638 * we'll collect those frames either way if we stop/delete vdevs */
2642 ret
= wait_event_timeout(ar
->htt
->empty_tx_wq
, ({
2644 spin_lock_bh(&ar
->htt
->tx_lock
);
2645 empty
= bitmap_empty(ar
->htt
->used_msdu_ids
,
2646 ar
->htt
->max_num_pending_tx
);
2647 spin_unlock_bh(&ar
->htt
->tx_lock
);
2649 }), ATH10K_FLUSH_TIMEOUT_HZ
);
2651 ath10k_warn("tx not flushed\n");
2654 /* TODO: Implement this function properly
2655 * For now it is needed to reply to Probe Requests in IBSS mode.
2656 * Propably we need this information from FW.
2658 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
2663 static const struct ieee80211_ops ath10k_ops
= {
2665 .start
= ath10k_start
,
2666 .stop
= ath10k_stop
,
2667 .config
= ath10k_config
,
2668 .add_interface
= ath10k_add_interface
,
2669 .remove_interface
= ath10k_remove_interface
,
2670 .configure_filter
= ath10k_configure_filter
,
2671 .bss_info_changed
= ath10k_bss_info_changed
,
2672 .hw_scan
= ath10k_hw_scan
,
2673 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
2674 .set_key
= ath10k_set_key
,
2675 .sta_state
= ath10k_sta_state
,
2676 .conf_tx
= ath10k_conf_tx
,
2677 .remain_on_channel
= ath10k_remain_on_channel
,
2678 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
2679 .set_rts_threshold
= ath10k_set_rts_threshold
,
2680 .set_frag_threshold
= ath10k_set_frag_threshold
,
2681 .flush
= ath10k_flush
,
2682 .tx_last_beacon
= ath10k_tx_last_beacon
,
2685 #define RATETAB_ENT(_rate, _rateid, _flags) { \
2686 .bitrate = (_rate), \
2687 .flags = (_flags), \
2688 .hw_value = (_rateid), \
2691 #define CHAN2G(_channel, _freq, _flags) { \
2692 .band = IEEE80211_BAND_2GHZ, \
2693 .hw_value = (_channel), \
2694 .center_freq = (_freq), \
2695 .flags = (_flags), \
2696 .max_antenna_gain = 0, \
2700 #define CHAN5G(_channel, _freq, _flags) { \
2701 .band = IEEE80211_BAND_5GHZ, \
2702 .hw_value = (_channel), \
2703 .center_freq = (_freq), \
2704 .flags = (_flags), \
2705 .max_antenna_gain = 0, \
2709 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
2719 CHAN2G(10, 2457, 0),
2720 CHAN2G(11, 2462, 0),
2721 CHAN2G(12, 2467, 0),
2722 CHAN2G(13, 2472, 0),
2723 CHAN2G(14, 2484, 0),
2726 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
2727 CHAN5G(36, 5180, 0),
2728 CHAN5G(40, 5200, 0),
2729 CHAN5G(44, 5220, 0),
2730 CHAN5G(48, 5240, 0),
2731 CHAN5G(52, 5260, 0),
2732 CHAN5G(56, 5280, 0),
2733 CHAN5G(60, 5300, 0),
2734 CHAN5G(64, 5320, 0),
2735 CHAN5G(100, 5500, 0),
2736 CHAN5G(104, 5520, 0),
2737 CHAN5G(108, 5540, 0),
2738 CHAN5G(112, 5560, 0),
2739 CHAN5G(116, 5580, 0),
2740 CHAN5G(120, 5600, 0),
2741 CHAN5G(124, 5620, 0),
2742 CHAN5G(128, 5640, 0),
2743 CHAN5G(132, 5660, 0),
2744 CHAN5G(136, 5680, 0),
2745 CHAN5G(140, 5700, 0),
2746 CHAN5G(149, 5745, 0),
2747 CHAN5G(153, 5765, 0),
2748 CHAN5G(157, 5785, 0),
2749 CHAN5G(161, 5805, 0),
2750 CHAN5G(165, 5825, 0),
2753 static struct ieee80211_rate ath10k_rates
[] = {
2755 RATETAB_ENT(10, 0x82, 0),
2756 RATETAB_ENT(20, 0x84, 0),
2757 RATETAB_ENT(55, 0x8b, 0),
2758 RATETAB_ENT(110, 0x96, 0),
2760 RATETAB_ENT(60, 0x0c, 0),
2761 RATETAB_ENT(90, 0x12, 0),
2762 RATETAB_ENT(120, 0x18, 0),
2763 RATETAB_ENT(180, 0x24, 0),
2764 RATETAB_ENT(240, 0x30, 0),
2765 RATETAB_ENT(360, 0x48, 0),
2766 RATETAB_ENT(480, 0x60, 0),
2767 RATETAB_ENT(540, 0x6c, 0),
2770 #define ath10k_a_rates (ath10k_rates + 4)
2771 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
2772 #define ath10k_g_rates (ath10k_rates + 0)
2773 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
2775 struct ath10k
*ath10k_mac_create(void)
2777 struct ieee80211_hw
*hw
;
2780 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
), &ath10k_ops
);
2790 void ath10k_mac_destroy(struct ath10k
*ar
)
2792 ieee80211_free_hw(ar
->hw
);
2795 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
2798 .types
= BIT(NL80211_IFTYPE_STATION
)
2799 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
2800 | BIT(NL80211_IFTYPE_P2P_GO
)
2801 | BIT(NL80211_IFTYPE_AP
)
2805 static const struct ieee80211_iface_combination ath10k_if_comb
= {
2806 .limits
= ath10k_if_limits
,
2807 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
2808 .max_interfaces
= 8,
2809 .num_different_channels
= 1,
2810 .beacon_int_infra_match
= true,
2813 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
2815 struct ieee80211_sta_vht_cap vht_cap
= {0};
2818 vht_cap
.vht_supported
= 1;
2819 vht_cap
.cap
= ar
->vht_cap_info
;
2821 /* FIXME: check dynamically how many streams board supports */
2822 mcs_map
= IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
2823 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 2 |
2824 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 4 |
2825 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 6 |
2826 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 8 |
2827 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 10 |
2828 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 12 |
2829 IEEE80211_VHT_MCS_NOT_SUPPORTED
<< 14;
2831 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
2832 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
2837 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
2840 struct ieee80211_sta_ht_cap ht_cap
= {0};
2842 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
2845 ht_cap
.ht_supported
= 1;
2846 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
2847 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
2848 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
2849 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
2850 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
2852 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
2853 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
2855 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
2856 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
2858 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
2861 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
2862 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
2867 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
2868 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
2870 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
2873 stbc
= ar
->ht_cap_info
;
2874 stbc
&= WMI_HT_CAP_RX_STBC
;
2875 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
2876 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
2877 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
2882 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
2883 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
2885 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
2886 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
2888 /* max AMSDU is implicitly taken from vht_cap_info */
2889 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
2890 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
2892 for (i
= 0; i
< WMI_MAX_SPATIAL_STREAM
; i
++)
2893 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
2895 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
2901 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
2902 struct ieee80211_vif
*vif
)
2904 struct ath10k_vif_iter
*arvif_iter
= data
;
2905 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2907 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
2908 arvif_iter
->arvif
= arvif
;
2911 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
2913 struct ath10k_vif_iter arvif_iter
;
2916 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
2917 arvif_iter
.vdev_id
= vdev_id
;
2919 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
2920 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
2922 ath10k_get_arvif_iter
,
2924 if (!arvif_iter
.arvif
) {
2925 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id
);
2929 return arvif_iter
.arvif
;
2932 int ath10k_mac_register(struct ath10k
*ar
)
2934 struct ieee80211_supported_band
*band
;
2935 struct ieee80211_sta_vht_cap vht_cap
;
2936 struct ieee80211_sta_ht_cap ht_cap
;
2940 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
2942 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
2944 ht_cap
= ath10k_get_ht_cap(ar
);
2945 vht_cap
= ath10k_create_vht_cap(ar
);
2947 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
2948 channels
= kmemdup(ath10k_2ghz_channels
,
2949 sizeof(ath10k_2ghz_channels
),
2954 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
2955 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
2956 band
->channels
= channels
;
2957 band
->n_bitrates
= ath10k_g_rates_size
;
2958 band
->bitrates
= ath10k_g_rates
;
2959 band
->ht_cap
= ht_cap
;
2961 /* vht is not supported in 2.4 GHz */
2963 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
2966 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
2967 channels
= kmemdup(ath10k_5ghz_channels
,
2968 sizeof(ath10k_5ghz_channels
),
2971 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
2972 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
2973 kfree(band
->channels
);
2978 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
2979 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
2980 band
->channels
= channels
;
2981 band
->n_bitrates
= ath10k_a_rates_size
;
2982 band
->bitrates
= ath10k_a_rates
;
2983 band
->ht_cap
= ht_cap
;
2984 band
->vht_cap
= vht_cap
;
2985 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
2988 ar
->hw
->wiphy
->interface_modes
=
2989 BIT(NL80211_IFTYPE_STATION
) |
2990 BIT(NL80211_IFTYPE_ADHOC
) |
2991 BIT(NL80211_IFTYPE_AP
) |
2992 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
2993 BIT(NL80211_IFTYPE_P2P_GO
);
2995 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
2996 IEEE80211_HW_SUPPORTS_PS
|
2997 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
2998 IEEE80211_HW_SUPPORTS_UAPSD
|
2999 IEEE80211_HW_MFP_CAPABLE
|
3000 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
3001 IEEE80211_HW_HAS_RATE_CONTROL
|
3002 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
3003 IEEE80211_HW_WANT_MONITOR_VIF
|
3004 IEEE80211_HW_AP_LINK_PS
;
3006 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
3007 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
3009 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
3010 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
3011 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
3014 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
3015 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
3017 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
3019 ar
->hw
->channel_change_time
= 5000;
3020 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
3022 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
3023 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
3025 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
3027 * on LL hardware queues are managed entirely by the FW
3028 * so we only advertise to mac we can do the queues thing
3032 ar
->hw
->wiphy
->iface_combinations
= &ath10k_if_comb
;
3033 ar
->hw
->wiphy
->n_iface_combinations
= 1;
3035 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
3036 ath10k_reg_notifier
);
3038 ath10k_err("Regulatory initialization failed\n");
3042 ret
= ieee80211_register_hw(ar
->hw
);
3044 ath10k_err("ieee80211 registration failed: %d\n", ret
);
3048 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
3049 ret
= regulatory_hint(ar
->hw
->wiphy
,
3050 ar
->ath_common
.regulatory
.alpha2
);
3057 ieee80211_unregister_hw(ar
->hw
);
3061 void ath10k_mac_unregister(struct ath10k
*ar
)
3063 ieee80211_unregister_hw(ar
->hw
);
3065 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
3066 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
3068 SET_IEEE80211_DEV(ar
->hw
, NULL
);