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 reinit_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
);
326 ath10k_warn("Failed to create wmi peer: %i\n", ret
);
330 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
332 ath10k_warn("Failed to wait for created wmi peer: %i\n", ret
);
335 spin_lock_bh(&ar
->data_lock
);
337 spin_unlock_bh(&ar
->data_lock
);
342 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
344 struct ath10k
*ar
= arvif
->ar
;
347 if (value
!= 0xFFFFFFFF)
348 value
= min_t(u32
, arvif
->ar
->hw
->wiphy
->rts_threshold
,
351 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
352 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
355 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
357 struct ath10k
*ar
= arvif
->ar
;
360 if (value
!= 0xFFFFFFFF)
361 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
362 ATH10K_FRAGMT_THRESHOLD_MIN
,
363 ATH10K_FRAGMT_THRESHOLD_MAX
);
365 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
366 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
369 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
373 lockdep_assert_held(&ar
->conf_mutex
);
375 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
379 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
383 spin_lock_bh(&ar
->data_lock
);
385 spin_unlock_bh(&ar
->data_lock
);
390 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
392 struct ath10k_peer
*peer
, *tmp
;
394 lockdep_assert_held(&ar
->conf_mutex
);
396 spin_lock_bh(&ar
->data_lock
);
397 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
398 if (peer
->vdev_id
!= vdev_id
)
401 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
402 peer
->addr
, vdev_id
);
404 list_del(&peer
->list
);
408 spin_unlock_bh(&ar
->data_lock
);
411 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
413 struct ath10k_peer
*peer
, *tmp
;
415 lockdep_assert_held(&ar
->conf_mutex
);
417 spin_lock_bh(&ar
->data_lock
);
418 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
419 list_del(&peer
->list
);
423 spin_unlock_bh(&ar
->data_lock
);
426 /************************/
427 /* Interface management */
428 /************************/
430 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
434 lockdep_assert_held(&ar
->conf_mutex
);
436 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
437 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
444 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
446 struct ath10k
*ar
= arvif
->ar
;
447 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
448 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
449 struct wmi_vdev_start_request_arg arg
= {};
452 lockdep_assert_held(&ar
->conf_mutex
);
454 reinit_completion(&ar
->vdev_setup_done
);
456 arg
.vdev_id
= arvif
->vdev_id
;
457 arg
.dtim_period
= arvif
->dtim_period
;
458 arg
.bcn_intval
= arvif
->beacon_interval
;
460 arg
.channel
.freq
= channel
->center_freq
;
462 arg
.channel
.band_center_freq1
= conf
->chandef
.center_freq1
;
464 arg
.channel
.mode
= chan_to_phymode(&conf
->chandef
);
466 arg
.channel
.min_power
= 0;
467 arg
.channel
.max_power
= channel
->max_power
* 2;
468 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
469 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
471 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
472 arg
.ssid
= arvif
->u
.ap
.ssid
;
473 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
474 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
476 /* For now allow DFS for AP mode */
477 arg
.channel
.chan_radar
=
478 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
479 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
480 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
481 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
484 ath10k_dbg(ATH10K_DBG_MAC
,
485 "mac vdev %d start center_freq %d phymode %s\n",
486 arg
.vdev_id
, arg
.channel
.freq
,
487 ath10k_wmi_phymode_str(arg
.channel
.mode
));
489 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
491 ath10k_warn("WMI vdev start failed: ret %d\n", ret
);
495 ret
= ath10k_vdev_setup_sync(ar
);
497 ath10k_warn("vdev setup failed %d\n", ret
);
504 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
506 struct ath10k
*ar
= arvif
->ar
;
509 lockdep_assert_held(&ar
->conf_mutex
);
511 reinit_completion(&ar
->vdev_setup_done
);
513 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
515 ath10k_warn("WMI vdev stop failed: ret %d\n", ret
);
519 ret
= ath10k_vdev_setup_sync(ar
);
521 ath10k_warn("vdev setup failed %d\n", ret
);
528 static int ath10k_monitor_start(struct ath10k
*ar
, int vdev_id
)
530 struct ieee80211_channel
*channel
= ar
->hw
->conf
.chandef
.chan
;
531 struct wmi_vdev_start_request_arg arg
= {};
534 lockdep_assert_held(&ar
->conf_mutex
);
536 if (!ar
->monitor_present
) {
537 ath10k_warn("mac montor stop -- monitor is not present\n");
541 arg
.vdev_id
= vdev_id
;
542 arg
.channel
.freq
= channel
->center_freq
;
543 arg
.channel
.band_center_freq1
= ar
->hw
->conf
.chandef
.center_freq1
;
545 /* TODO setup this dynamically, what in case we
546 don't have any vifs? */
547 arg
.channel
.mode
= chan_to_phymode(&ar
->hw
->conf
.chandef
);
548 arg
.channel
.chan_radar
=
549 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
551 arg
.channel
.min_power
= 0;
552 arg
.channel
.max_power
= channel
->max_power
* 2;
553 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
554 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
556 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
558 ath10k_warn("Monitor vdev start failed: ret %d\n", ret
);
562 ret
= ath10k_vdev_setup_sync(ar
);
564 ath10k_warn("Monitor vdev setup failed %d\n", ret
);
568 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
570 ath10k_warn("Monitor vdev up failed: %d\n", ret
);
574 ar
->monitor_vdev_id
= vdev_id
;
575 ar
->monitor_enabled
= true;
580 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
582 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
587 static int ath10k_monitor_stop(struct ath10k
*ar
)
591 lockdep_assert_held(&ar
->conf_mutex
);
593 if (!ar
->monitor_present
) {
594 ath10k_warn("mac montor stop -- monitor is not present\n");
598 if (!ar
->monitor_enabled
) {
599 ath10k_warn("mac montor stop -- monitor is not enabled\n");
603 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
605 ath10k_warn("Monitor vdev down failed: %d\n", ret
);
607 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
609 ath10k_warn("Monitor vdev stop failed: %d\n", ret
);
611 ret
= ath10k_vdev_setup_sync(ar
);
613 ath10k_warn("Monitor_down sync failed: %d\n", ret
);
615 ar
->monitor_enabled
= false;
619 static int ath10k_monitor_create(struct ath10k
*ar
)
623 lockdep_assert_held(&ar
->conf_mutex
);
625 if (ar
->monitor_present
) {
626 ath10k_warn("Monitor mode already enabled\n");
630 bit
= ffs(ar
->free_vdev_map
);
632 ath10k_warn("No free VDEV slots\n");
636 ar
->monitor_vdev_id
= bit
- 1;
637 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
639 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
640 WMI_VDEV_TYPE_MONITOR
,
643 ath10k_warn("WMI vdev monitor create failed: ret %d\n", ret
);
647 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
648 ar
->monitor_vdev_id
);
650 ar
->monitor_present
= true;
655 * Restore the ID to the global map.
657 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
661 static int ath10k_monitor_destroy(struct ath10k
*ar
)
665 lockdep_assert_held(&ar
->conf_mutex
);
667 if (!ar
->monitor_present
)
670 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
672 ath10k_warn("WMI vdev monitor delete failed: %d\n", ret
);
676 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
677 ar
->monitor_present
= false;
679 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
680 ar
->monitor_vdev_id
);
684 static int ath10k_start_cac(struct ath10k
*ar
)
688 lockdep_assert_held(&ar
->conf_mutex
);
690 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
692 ret
= ath10k_monitor_create(ar
);
694 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
698 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
700 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
701 ath10k_monitor_destroy(ar
);
705 ath10k_dbg(ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
706 ar
->monitor_vdev_id
);
711 static int ath10k_stop_cac(struct ath10k
*ar
)
713 lockdep_assert_held(&ar
->conf_mutex
);
715 /* CAC is not running - do nothing */
716 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
719 ath10k_monitor_stop(ar
);
720 ath10k_monitor_destroy(ar
);
721 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
723 ath10k_dbg(ATH10K_DBG_MAC
, "mac cac finished\n");
728 static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state
)
731 case NL80211_DFS_USABLE
:
733 case NL80211_DFS_UNAVAILABLE
:
734 return "UNAVAILABLE";
735 case NL80211_DFS_AVAILABLE
:
743 static void ath10k_config_radar_detection(struct ath10k
*ar
)
745 struct ieee80211_channel
*chan
= ar
->hw
->conf
.chandef
.chan
;
746 bool radar
= ar
->hw
->conf
.radar_enabled
;
747 bool chan_radar
= !!(chan
->flags
& IEEE80211_CHAN_RADAR
);
748 enum nl80211_dfs_state dfs_state
= chan
->dfs_state
;
751 lockdep_assert_held(&ar
->conf_mutex
);
753 ath10k_dbg(ATH10K_DBG_MAC
,
754 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
755 chan
->center_freq
, radar
, chan_radar
,
756 ath10k_dfs_state(dfs_state
));
759 * It's safe to call it even if CAC is not started.
760 * This call here guarantees changing channel, etc. will stop CAC.
770 if (dfs_state
!= NL80211_DFS_USABLE
)
773 ret
= ath10k_start_cac(ar
);
776 * Not possible to start CAC on current channel so starting
777 * radiation is not allowed, make this channel DFS_UNAVAILABLE
778 * by indicating that radar was detected.
780 ath10k_warn("failed to start CAC (%d)\n", ret
);
781 ieee80211_radar_detected(ar
->hw
);
785 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
786 struct ieee80211_bss_conf
*info
)
790 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
792 if (!info
->enable_beacon
) {
793 ath10k_vdev_stop(arvif
);
797 arvif
->tx_seq_no
= 0x1000;
799 ret
= ath10k_vdev_start(arvif
);
803 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, 0, info
->bssid
);
805 ath10k_warn("Failed to bring up VDEV: %d\n",
809 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
812 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
813 struct ieee80211_bss_conf
*info
,
814 const u8 self_peer
[ETH_ALEN
])
819 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
821 if (!info
->ibss_joined
) {
822 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
824 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
825 self_peer
, arvif
->vdev_id
, ret
);
827 if (is_zero_ether_addr(arvif
->u
.ibss
.bssid
))
830 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
831 arvif
->u
.ibss
.bssid
);
833 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
834 arvif
->u
.ibss
.bssid
, arvif
->vdev_id
, ret
);
838 memset(arvif
->u
.ibss
.bssid
, 0, ETH_ALEN
);
843 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
845 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
846 self_peer
, arvif
->vdev_id
, ret
);
850 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
851 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
852 ATH10K_DEFAULT_ATIM
);
854 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
855 arvif
->vdev_id
, ret
);
859 * Review this when mac80211 gains per-interface powersave support.
861 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
863 struct ath10k
*ar
= arvif
->ar
;
864 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
865 enum wmi_sta_powersave_param param
;
866 enum wmi_sta_ps_mode psmode
;
869 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
871 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
874 if (conf
->flags
& IEEE80211_CONF_PS
) {
875 psmode
= WMI_STA_PS_MODE_ENABLED
;
876 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
878 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
879 conf
->dynamic_ps_timeout
);
881 ath10k_warn("Failed to set inactivity time for VDEV: %d\n",
886 psmode
= WMI_STA_PS_MODE_DISABLED
;
889 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
890 arvif
->vdev_id
, psmode
? "enable" : "disable");
892 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
894 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
895 psmode
, arvif
->vdev_id
);
902 /**********************/
903 /* Station management */
904 /**********************/
906 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
907 struct ath10k_vif
*arvif
,
908 struct ieee80211_sta
*sta
,
909 struct ieee80211_bss_conf
*bss_conf
,
910 struct wmi_peer_assoc_complete_arg
*arg
)
912 lockdep_assert_held(&ar
->conf_mutex
);
914 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
915 arg
->vdev_id
= arvif
->vdev_id
;
916 arg
->peer_aid
= sta
->aid
;
917 arg
->peer_flags
|= WMI_PEER_AUTH
;
919 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
921 * Seems FW have problems with Power Save in STA
922 * mode when we setup this parameter to high (eg. 5).
923 * Often we see that FW don't send NULL (with clean P flags)
924 * frame even there is info about buffered frames in beacons.
925 * Sometimes we have to wait more than 10 seconds before FW
926 * will wakeup. Often sending one ping from AP to our device
927 * just fail (more than 50%).
929 * Seems setting this FW parameter to 1 couse FW
930 * will check every beacon and will wakup immediately
931 * after detection buffered data.
933 arg
->peer_listen_intval
= 1;
935 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
937 arg
->peer_num_spatial_streams
= 1;
940 * The assoc capabilities are available only in managed mode.
942 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
943 arg
->peer_caps
= bss_conf
->assoc_capability
;
946 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
947 struct ath10k_vif
*arvif
,
948 struct wmi_peer_assoc_complete_arg
*arg
)
950 struct ieee80211_vif
*vif
= arvif
->vif
;
951 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
952 struct cfg80211_bss
*bss
;
953 const u8
*rsnie
= NULL
;
954 const u8
*wpaie
= NULL
;
956 lockdep_assert_held(&ar
->conf_mutex
);
958 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
959 info
->bssid
, NULL
, 0, 0, 0);
961 const struct cfg80211_bss_ies
*ies
;
964 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
966 ies
= rcu_dereference(bss
->ies
);
968 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
969 WLAN_OUI_TYPE_MICROSOFT_WPA
,
973 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
976 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
977 if (rsnie
|| wpaie
) {
978 ath10k_dbg(ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
979 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
983 ath10k_dbg(ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
984 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
988 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
989 struct ieee80211_sta
*sta
,
990 struct wmi_peer_assoc_complete_arg
*arg
)
992 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
993 const struct ieee80211_supported_band
*sband
;
994 const struct ieee80211_rate
*rates
;
998 lockdep_assert_held(&ar
->conf_mutex
);
1000 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1001 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1002 rates
= sband
->bitrates
;
1004 rateset
->num_rates
= 0;
1006 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1007 if (!(ratemask
& 1))
1010 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
1011 rateset
->num_rates
++;
1015 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1016 struct ieee80211_sta
*sta
,
1017 struct wmi_peer_assoc_complete_arg
*arg
)
1019 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1023 lockdep_assert_held(&ar
->conf_mutex
);
1025 if (!ht_cap
->ht_supported
)
1028 arg
->peer_flags
|= WMI_PEER_HT
;
1029 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1030 ht_cap
->ampdu_factor
)) - 1;
1032 arg
->peer_mpdu_density
=
1033 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1035 arg
->peer_ht_caps
= ht_cap
->cap
;
1036 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1038 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1039 arg
->peer_flags
|= WMI_PEER_LDPC
;
1041 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1042 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1043 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1046 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1047 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1049 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1050 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1052 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1053 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1054 arg
->peer_flags
|= WMI_PEER_STBC
;
1057 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1059 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1060 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1061 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1062 arg
->peer_rate_caps
|= stbc
;
1063 arg
->peer_flags
|= WMI_PEER_STBC
;
1066 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
1067 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
1069 if (smps
== WLAN_HT_CAP_SM_PS_STATIC
) {
1070 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
1071 arg
->peer_flags
|= WMI_PEER_STATIC_MIMOPS
;
1072 } else if (smps
== WLAN_HT_CAP_SM_PS_DYNAMIC
) {
1073 arg
->peer_flags
|= WMI_PEER_SPATIAL_MUX
;
1074 arg
->peer_flags
|= WMI_PEER_DYN_MIMOPS
;
1077 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1078 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1079 else if (ht_cap
->mcs
.rx_mask
[1])
1080 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1082 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1083 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1084 arg
->peer_ht_rates
.rates
[n
++] = i
;
1086 arg
->peer_ht_rates
.num_rates
= n
;
1087 arg
->peer_num_spatial_streams
= max((n
+7) / 8, 1);
1089 ath10k_dbg(ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1091 arg
->peer_ht_rates
.num_rates
,
1092 arg
->peer_num_spatial_streams
);
1095 static void ath10k_peer_assoc_h_qos_ap(struct ath10k
*ar
,
1096 struct ath10k_vif
*arvif
,
1097 struct ieee80211_sta
*sta
,
1098 struct ieee80211_bss_conf
*bss_conf
,
1099 struct wmi_peer_assoc_complete_arg
*arg
)
1104 lockdep_assert_held(&ar
->conf_mutex
);
1107 arg
->peer_flags
|= WMI_PEER_QOS
;
1109 if (sta
->wme
&& sta
->uapsd_queues
) {
1110 ath10k_dbg(ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1111 sta
->uapsd_queues
, sta
->max_sp
);
1113 arg
->peer_flags
|= WMI_PEER_APSD
;
1114 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1116 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1117 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1118 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1119 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1120 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1121 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1122 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1123 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1124 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1125 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1126 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1127 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1130 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1131 max_sp
= sta
->max_sp
;
1133 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1135 WMI_AP_PS_PEER_PARAM_UAPSD
,
1138 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1140 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1143 /* TODO setup this based on STA listen interval and
1144 beacon interval. Currently we don't know
1145 sta->listen_interval - mac80211 patch required.
1146 Currently use 10 seconds */
1147 ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1149 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
,
1154 static void ath10k_peer_assoc_h_qos_sta(struct ath10k
*ar
,
1155 struct ath10k_vif
*arvif
,
1156 struct ieee80211_sta
*sta
,
1157 struct ieee80211_bss_conf
*bss_conf
,
1158 struct wmi_peer_assoc_complete_arg
*arg
)
1161 arg
->peer_flags
|= WMI_PEER_QOS
;
1164 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1165 struct ieee80211_sta
*sta
,
1166 struct wmi_peer_assoc_complete_arg
*arg
)
1168 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1171 if (!vht_cap
->vht_supported
)
1174 arg
->peer_flags
|= WMI_PEER_VHT
;
1175 arg
->peer_vht_caps
= vht_cap
->cap
;
1178 ampdu_factor
= (vht_cap
->cap
&
1179 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1180 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1182 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1183 * zero in VHT IE. Using it would result in degraded throughput.
1184 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1185 * it if VHT max_mpdu is smaller. */
1186 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1187 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1188 ampdu_factor
)) - 1);
1190 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1191 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1193 arg
->peer_vht_rates
.rx_max_rate
=
1194 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1195 arg
->peer_vht_rates
.rx_mcs_set
=
1196 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1197 arg
->peer_vht_rates
.tx_max_rate
=
1198 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1199 arg
->peer_vht_rates
.tx_mcs_set
=
1200 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1202 ath10k_dbg(ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1203 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1206 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1207 struct ath10k_vif
*arvif
,
1208 struct ieee80211_sta
*sta
,
1209 struct ieee80211_bss_conf
*bss_conf
,
1210 struct wmi_peer_assoc_complete_arg
*arg
)
1212 switch (arvif
->vdev_type
) {
1213 case WMI_VDEV_TYPE_AP
:
1214 ath10k_peer_assoc_h_qos_ap(ar
, arvif
, sta
, bss_conf
, arg
);
1216 case WMI_VDEV_TYPE_STA
:
1217 ath10k_peer_assoc_h_qos_sta(ar
, arvif
, sta
, bss_conf
, arg
);
1224 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1225 struct ath10k_vif
*arvif
,
1226 struct ieee80211_sta
*sta
,
1227 struct wmi_peer_assoc_complete_arg
*arg
)
1229 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1231 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1232 case IEEE80211_BAND_2GHZ
:
1233 if (sta
->ht_cap
.ht_supported
) {
1234 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1235 phymode
= MODE_11NG_HT40
;
1237 phymode
= MODE_11NG_HT20
;
1243 case IEEE80211_BAND_5GHZ
:
1247 if (sta
->vht_cap
.vht_supported
) {
1248 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1249 phymode
= MODE_11AC_VHT80
;
1250 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1251 phymode
= MODE_11AC_VHT40
;
1252 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1253 phymode
= MODE_11AC_VHT20
;
1254 } else if (sta
->ht_cap
.ht_supported
) {
1255 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1256 phymode
= MODE_11NA_HT40
;
1258 phymode
= MODE_11NA_HT20
;
1268 ath10k_dbg(ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1269 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1271 arg
->peer_phymode
= phymode
;
1272 WARN_ON(phymode
== MODE_UNKNOWN
);
1275 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1276 struct ath10k_vif
*arvif
,
1277 struct ieee80211_sta
*sta
,
1278 struct ieee80211_bss_conf
*bss_conf
,
1279 struct wmi_peer_assoc_complete_arg
*arg
)
1281 lockdep_assert_held(&ar
->conf_mutex
);
1283 memset(arg
, 0, sizeof(*arg
));
1285 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, arg
);
1286 ath10k_peer_assoc_h_crypto(ar
, arvif
, arg
);
1287 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1288 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1289 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1290 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, arg
);
1291 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, arg
);
1296 /* can be called only in mac80211 callbacks due to `key_count` usage */
1297 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1298 struct ieee80211_vif
*vif
,
1299 struct ieee80211_bss_conf
*bss_conf
)
1301 struct ath10k
*ar
= hw
->priv
;
1302 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1303 struct wmi_peer_assoc_complete_arg peer_arg
;
1304 struct ieee80211_sta
*ap_sta
;
1307 lockdep_assert_held(&ar
->conf_mutex
);
1311 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1313 ath10k_warn("Failed to find station entry for %pM\n",
1319 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, ap_sta
,
1320 bss_conf
, &peer_arg
);
1322 ath10k_warn("Peer assoc prepare failed for %pM\n: %d",
1323 bss_conf
->bssid
, ret
);
1330 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1332 ath10k_warn("Peer assoc failed for %pM\n: %d",
1333 bss_conf
->bssid
, ret
);
1337 ath10k_dbg(ATH10K_DBG_MAC
,
1338 "mac vdev %d up (associated) bssid %pM aid %d\n",
1339 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1341 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, bss_conf
->aid
,
1344 ath10k_warn("VDEV: %d up failed: ret %d\n",
1345 arvif
->vdev_id
, ret
);
1351 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1352 struct ieee80211_vif
*vif
)
1354 struct ath10k
*ar
= hw
->priv
;
1355 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1358 lockdep_assert_held(&ar
->conf_mutex
);
1361 * For some reason, calling VDEV-DOWN before VDEV-STOP
1362 * makes the FW to send frames via HTT after disassociation.
1363 * No idea why this happens, even though VDEV-DOWN is supposed
1364 * to be analogous to link down, so just stop the VDEV.
1366 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d stop (disassociated\n",
1369 /* FIXME: check return value */
1370 ret
= ath10k_vdev_stop(arvif
);
1373 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1374 * report beacons from previously associated network through HTT.
1375 * This in turn would spam mac80211 WARN_ON if we bring down all
1376 * interfaces as it expects there is no rx when no interface is
1379 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d down\n", arvif
->vdev_id
);
1381 /* FIXME: why don't we print error if wmi call fails? */
1382 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1384 arvif
->def_wep_key_idx
= 0;
1387 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1388 struct ieee80211_sta
*sta
)
1390 struct wmi_peer_assoc_complete_arg peer_arg
;
1393 lockdep_assert_held(&ar
->conf_mutex
);
1395 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, sta
, NULL
, &peer_arg
);
1397 ath10k_warn("WMI peer assoc prepare failed for %pM\n",
1402 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1404 ath10k_warn("Peer assoc failed for STA %pM\n: %d",
1409 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1411 ath10k_warn("could not install peer wep keys (%d)\n", ret
);
1418 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1419 struct ieee80211_sta
*sta
)
1423 lockdep_assert_held(&ar
->conf_mutex
);
1425 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1427 ath10k_warn("could not clear all peer wep keys (%d)\n", ret
);
1438 static int ath10k_update_channel_list(struct ath10k
*ar
)
1440 struct ieee80211_hw
*hw
= ar
->hw
;
1441 struct ieee80211_supported_band
**bands
;
1442 enum ieee80211_band band
;
1443 struct ieee80211_channel
*channel
;
1444 struct wmi_scan_chan_list_arg arg
= {0};
1445 struct wmi_channel_arg
*ch
;
1451 lockdep_assert_held(&ar
->conf_mutex
);
1453 bands
= hw
->wiphy
->bands
;
1454 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1458 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1459 if (bands
[band
]->channels
[i
].flags
&
1460 IEEE80211_CHAN_DISABLED
)
1467 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1468 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1473 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1477 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1478 channel
= &bands
[band
]->channels
[i
];
1480 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1483 ch
->allow_ht
= true;
1485 /* FIXME: when should we really allow VHT? */
1486 ch
->allow_vht
= true;
1489 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
1492 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1495 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1497 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
1498 ch
->passive
= passive
;
1500 ch
->freq
= channel
->center_freq
;
1502 ch
->max_power
= channel
->max_power
* 2;
1503 ch
->max_reg_power
= channel
->max_reg_power
* 2;
1504 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
1505 ch
->reg_class_id
= 0; /* FIXME */
1507 /* FIXME: why use only legacy modes, why not any
1508 * HT/VHT modes? Would that even make any
1510 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1511 ch
->mode
= MODE_11G
;
1513 ch
->mode
= MODE_11A
;
1515 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1518 ath10k_dbg(ATH10K_DBG_WMI
,
1519 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1520 ch
- arg
.channels
, arg
.n_channels
,
1521 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1522 ch
->max_antenna_gain
, ch
->mode
);
1528 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1529 kfree(arg
.channels
);
1534 static void ath10k_regd_update(struct ath10k
*ar
)
1536 struct reg_dmn_pair_mapping
*regpair
;
1539 lockdep_assert_held(&ar
->conf_mutex
);
1541 ret
= ath10k_update_channel_list(ar
);
1543 ath10k_warn("could not update channel list (%d)\n", ret
);
1545 regpair
= ar
->ath_common
.regulatory
.regpair
;
1547 /* Target allows setting up per-band regdomain but ath_common provides
1548 * a combined one only */
1549 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1550 regpair
->regDmnEnum
,
1551 regpair
->regDmnEnum
, /* 2ghz */
1552 regpair
->regDmnEnum
, /* 5ghz */
1553 regpair
->reg_2ghz_ctl
,
1554 regpair
->reg_5ghz_ctl
);
1556 ath10k_warn("could not set pdev regdomain (%d)\n", ret
);
1559 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1560 struct regulatory_request
*request
)
1562 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1563 struct ath10k
*ar
= hw
->priv
;
1566 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1568 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
1569 ath10k_dbg(ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
1570 request
->dfs_region
);
1571 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
1572 request
->dfs_region
);
1574 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1575 request
->dfs_region
);
1578 mutex_lock(&ar
->conf_mutex
);
1579 if (ar
->state
== ATH10K_STATE_ON
)
1580 ath10k_regd_update(ar
);
1581 mutex_unlock(&ar
->conf_mutex
);
1588 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
1590 if (ieee80211_is_mgmt(hdr
->frame_control
))
1591 return HTT_DATA_TX_EXT_TID_MGMT
;
1593 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1594 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1596 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
1597 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1599 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
1602 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
,
1603 struct ieee80211_tx_info
*info
)
1605 if (info
->control
.vif
)
1606 return ath10k_vif_to_arvif(info
->control
.vif
)->vdev_id
;
1608 if (ar
->monitor_enabled
)
1609 return ar
->monitor_vdev_id
;
1611 ath10k_warn("could not resolve vdev id\n");
1616 * Frames sent to the FW have to be in "Native Wifi" format.
1617 * Strip the QoS field from the 802.11 header.
1619 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw
*hw
,
1620 struct ieee80211_tx_control
*control
,
1621 struct sk_buff
*skb
)
1623 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1626 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1629 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1630 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
1631 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
1632 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
1635 static void ath10k_tx_wep_key_work(struct work_struct
*work
)
1637 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1639 int ret
, keyidx
= arvif
->def_wep_key_newidx
;
1641 if (arvif
->def_wep_key_idx
== keyidx
)
1644 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
1645 arvif
->vdev_id
, keyidx
);
1647 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
1649 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
1652 ath10k_warn("could not update wep keyidx (%d)\n", ret
);
1656 arvif
->def_wep_key_idx
= keyidx
;
1659 static void ath10k_tx_h_update_wep_key(struct sk_buff
*skb
)
1661 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1662 struct ieee80211_vif
*vif
= info
->control
.vif
;
1663 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1664 struct ath10k
*ar
= arvif
->ar
;
1665 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1666 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
1668 if (!ieee80211_has_protected(hdr
->frame_control
))
1674 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1675 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1678 if (key
->keyidx
== arvif
->def_wep_key_idx
)
1681 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1682 * queueing frames until key index is updated is not an option because
1683 * sk_buff may need more processing to be done, e.g. offchannel */
1684 arvif
->def_wep_key_newidx
= key
->keyidx
;
1685 ieee80211_queue_work(ar
->hw
, &arvif
->wep_key_work
);
1688 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
, struct sk_buff
*skb
)
1690 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1691 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1692 struct ieee80211_vif
*vif
= info
->control
.vif
;
1693 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1695 /* This is case only for P2P_GO */
1696 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1697 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1700 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1701 spin_lock_bh(&ar
->data_lock
);
1702 if (arvif
->u
.ap
.noa_data
)
1703 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1705 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1706 arvif
->u
.ap
.noa_data
,
1707 arvif
->u
.ap
.noa_len
);
1708 spin_unlock_bh(&ar
->data_lock
);
1712 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1714 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1717 if (ar
->htt
.target_version_major
>= 3) {
1718 /* Since HTT 3.0 there is no separate mgmt tx command */
1719 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1723 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
1724 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1726 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
1727 ATH10K_MAX_NUM_MGMT_PENDING
) {
1728 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1733 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
1734 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
1736 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1738 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1740 ieee80211_is_nullfunc(hdr
->frame_control
)) {
1741 /* FW does not report tx status properly for NullFunc frames
1742 * unless they are sent through mgmt tx path. mac80211 sends
1743 * those frames when it detects link/beacon loss and depends
1744 * on the tx status to be correct. */
1745 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1747 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1752 ath10k_warn("tx failed (%d). dropping packet.\n", ret
);
1753 ieee80211_free_txskb(ar
->hw
, skb
);
1757 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
1759 struct sk_buff
*skb
;
1762 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1766 ieee80211_free_txskb(ar
->hw
, skb
);
1770 void ath10k_offchan_tx_work(struct work_struct
*work
)
1772 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
1773 struct ath10k_peer
*peer
;
1774 struct ieee80211_hdr
*hdr
;
1775 struct sk_buff
*skb
;
1776 const u8
*peer_addr
;
1780 /* FW requirement: We must create a peer before FW will send out
1781 * an offchannel frame. Otherwise the frame will be stuck and
1782 * never transmitted. We delete the peer upon tx completion.
1783 * It is unlikely that a peer for offchannel tx will already be
1784 * present. However it may be in some rare cases so account for that.
1785 * Otherwise we might remove a legitimate peer and break stuff. */
1788 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1792 mutex_lock(&ar
->conf_mutex
);
1794 ath10k_dbg(ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
1797 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1798 peer_addr
= ieee80211_get_DA(hdr
);
1799 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
1801 spin_lock_bh(&ar
->data_lock
);
1802 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
1803 spin_unlock_bh(&ar
->data_lock
);
1806 /* FIXME: should this use ath10k_warn()? */
1807 ath10k_dbg(ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
1808 peer_addr
, vdev_id
);
1811 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
1813 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1814 peer_addr
, vdev_id
, ret
);
1817 spin_lock_bh(&ar
->data_lock
);
1818 reinit_completion(&ar
->offchan_tx_completed
);
1819 ar
->offchan_tx_skb
= skb
;
1820 spin_unlock_bh(&ar
->data_lock
);
1822 ath10k_tx_htt(ar
, skb
);
1824 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
1827 ath10k_warn("timed out waiting for offchannel skb %p\n",
1831 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
1833 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1834 peer_addr
, vdev_id
, ret
);
1837 mutex_unlock(&ar
->conf_mutex
);
1841 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
1843 struct sk_buff
*skb
;
1846 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
1850 ieee80211_free_txskb(ar
->hw
, skb
);
1854 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
1856 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
1857 struct sk_buff
*skb
;
1861 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
1865 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
1867 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret
);
1868 ieee80211_free_txskb(ar
->hw
, skb
);
1878 * This gets called if we dont get a heart-beat during scan.
1879 * This may indicate the FW has hung and we need to abort the
1880 * scan manually to prevent cancel_hw_scan() from deadlocking
1882 void ath10k_reset_scan(unsigned long ptr
)
1884 struct ath10k
*ar
= (struct ath10k
*)ptr
;
1886 spin_lock_bh(&ar
->data_lock
);
1887 if (!ar
->scan
.in_progress
) {
1888 spin_unlock_bh(&ar
->data_lock
);
1892 ath10k_warn("scan timeout. resetting. fw issue?\n");
1894 if (ar
->scan
.is_roc
)
1895 ieee80211_remain_on_channel_expired(ar
->hw
);
1897 ieee80211_scan_completed(ar
->hw
, 1 /* aborted */);
1899 ar
->scan
.in_progress
= false;
1900 complete_all(&ar
->scan
.completed
);
1901 spin_unlock_bh(&ar
->data_lock
);
1904 static int ath10k_abort_scan(struct ath10k
*ar
)
1906 struct wmi_stop_scan_arg arg
= {
1907 .req_id
= 1, /* FIXME */
1908 .req_type
= WMI_SCAN_STOP_ONE
,
1909 .u
.scan_id
= ATH10K_SCAN_ID
,
1913 lockdep_assert_held(&ar
->conf_mutex
);
1915 del_timer_sync(&ar
->scan
.timeout
);
1917 spin_lock_bh(&ar
->data_lock
);
1918 if (!ar
->scan
.in_progress
) {
1919 spin_unlock_bh(&ar
->data_lock
);
1923 ar
->scan
.aborting
= true;
1924 spin_unlock_bh(&ar
->data_lock
);
1926 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
1928 ath10k_warn("could not submit wmi stop scan (%d)\n", ret
);
1929 spin_lock_bh(&ar
->data_lock
);
1930 ar
->scan
.in_progress
= false;
1931 ath10k_offchan_tx_purge(ar
);
1932 spin_unlock_bh(&ar
->data_lock
);
1936 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
1938 ath10k_warn("timed out while waiting for scan to stop\n");
1940 /* scan completion may be done right after we timeout here, so let's
1941 * check the in_progress and tell mac80211 scan is completed. if we
1942 * don't do that and FW fails to send us scan completion indication
1943 * then userspace won't be able to scan anymore */
1946 spin_lock_bh(&ar
->data_lock
);
1947 if (ar
->scan
.in_progress
) {
1948 ath10k_warn("could not stop scan. its still in progress\n");
1949 ar
->scan
.in_progress
= false;
1950 ath10k_offchan_tx_purge(ar
);
1953 spin_unlock_bh(&ar
->data_lock
);
1958 static int ath10k_start_scan(struct ath10k
*ar
,
1959 const struct wmi_start_scan_arg
*arg
)
1963 lockdep_assert_held(&ar
->conf_mutex
);
1965 ret
= ath10k_wmi_start_scan(ar
, arg
);
1969 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
1971 ath10k_abort_scan(ar
);
1975 /* the scan can complete earlier, before we even
1976 * start the timer. in that case the timer handler
1977 * checks ar->scan.in_progress and bails out if its
1978 * false. Add a 200ms margin to account event/command
1980 mod_timer(&ar
->scan
.timeout
, jiffies
+
1981 msecs_to_jiffies(arg
->max_scan_time
+200));
1985 /**********************/
1986 /* mac80211 callbacks */
1987 /**********************/
1989 static void ath10k_tx(struct ieee80211_hw
*hw
,
1990 struct ieee80211_tx_control
*control
,
1991 struct sk_buff
*skb
)
1993 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1994 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1995 struct ath10k
*ar
= hw
->priv
;
1998 /* We should disable CCK RATE due to P2P */
1999 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
2000 ath10k_dbg(ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2002 /* we must calculate tid before we apply qos workaround
2003 * as we'd lose the qos control field */
2004 tid
= ath10k_tx_h_get_tid(hdr
);
2005 vdev_id
= ath10k_tx_h_get_vdev_id(ar
, info
);
2007 /* it makes no sense to process injected frames like that */
2008 if (info
->control
.vif
&&
2009 info
->control
.vif
->type
!= NL80211_IFTYPE_MONITOR
) {
2010 ath10k_tx_h_qos_workaround(hw
, control
, skb
);
2011 ath10k_tx_h_update_wep_key(skb
);
2012 ath10k_tx_h_add_p2p_noa_ie(ar
, skb
);
2013 ath10k_tx_h_seq_no(skb
);
2016 ATH10K_SKB_CB(skb
)->vdev_id
= vdev_id
;
2017 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
2018 ATH10K_SKB_CB(skb
)->htt
.tid
= tid
;
2020 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
2021 spin_lock_bh(&ar
->data_lock
);
2022 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
2023 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
2024 spin_unlock_bh(&ar
->data_lock
);
2026 ath10k_dbg(ATH10K_DBG_MAC
, "queued offchannel skb %p\n", skb
);
2028 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
2029 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
2033 ath10k_tx_htt(ar
, skb
);
2037 * Initialize various parameters with default vaules.
2039 void ath10k_halt(struct ath10k
*ar
)
2041 lockdep_assert_held(&ar
->conf_mutex
);
2043 ath10k_stop_cac(ar
);
2044 del_timer_sync(&ar
->scan
.timeout
);
2045 ath10k_offchan_tx_purge(ar
);
2046 ath10k_mgmt_over_wmi_tx_purge(ar
);
2047 ath10k_peer_cleanup_all(ar
);
2048 ath10k_core_stop(ar
);
2049 ath10k_hif_power_down(ar
);
2051 spin_lock_bh(&ar
->data_lock
);
2052 if (ar
->scan
.in_progress
) {
2053 del_timer(&ar
->scan
.timeout
);
2054 ar
->scan
.in_progress
= false;
2055 ieee80211_scan_completed(ar
->hw
, true);
2057 spin_unlock_bh(&ar
->data_lock
);
2060 static int ath10k_start(struct ieee80211_hw
*hw
)
2062 struct ath10k
*ar
= hw
->priv
;
2065 mutex_lock(&ar
->conf_mutex
);
2067 if (ar
->state
!= ATH10K_STATE_OFF
&&
2068 ar
->state
!= ATH10K_STATE_RESTARTING
) {
2073 ret
= ath10k_hif_power_up(ar
);
2075 ath10k_err("could not init hif (%d)\n", ret
);
2076 ar
->state
= ATH10K_STATE_OFF
;
2080 ret
= ath10k_core_start(ar
);
2082 ath10k_err("could not init core (%d)\n", ret
);
2083 ath10k_hif_power_down(ar
);
2084 ar
->state
= ATH10K_STATE_OFF
;
2088 if (ar
->state
== ATH10K_STATE_OFF
)
2089 ar
->state
= ATH10K_STATE_ON
;
2090 else if (ar
->state
== ATH10K_STATE_RESTARTING
)
2091 ar
->state
= ATH10K_STATE_RESTARTED
;
2093 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
2095 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2098 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
2100 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2103 ath10k_regd_update(ar
);
2106 mutex_unlock(&ar
->conf_mutex
);
2110 static void ath10k_stop(struct ieee80211_hw
*hw
)
2112 struct ath10k
*ar
= hw
->priv
;
2114 mutex_lock(&ar
->conf_mutex
);
2115 if (ar
->state
== ATH10K_STATE_ON
||
2116 ar
->state
== ATH10K_STATE_RESTARTED
||
2117 ar
->state
== ATH10K_STATE_WEDGED
)
2120 ar
->state
= ATH10K_STATE_OFF
;
2121 mutex_unlock(&ar
->conf_mutex
);
2123 ath10k_mgmt_over_wmi_tx_purge(ar
);
2125 cancel_work_sync(&ar
->offchan_tx_work
);
2126 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
2127 cancel_work_sync(&ar
->restart_work
);
2130 static int ath10k_config_ps(struct ath10k
*ar
)
2132 struct ath10k_vif
*arvif
;
2135 lockdep_assert_held(&ar
->conf_mutex
);
2137 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2138 ret
= ath10k_mac_vif_setup_ps(arvif
);
2140 ath10k_warn("could not setup powersave (%d)\n", ret
);
2148 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
2150 struct ath10k
*ar
= hw
->priv
;
2151 struct ieee80211_conf
*conf
= &hw
->conf
;
2155 mutex_lock(&ar
->conf_mutex
);
2157 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2158 ath10k_dbg(ATH10K_DBG_MAC
,
2159 "mac config channel %d mhz flags 0x%x\n",
2160 conf
->chandef
.chan
->center_freq
,
2161 conf
->chandef
.chan
->flags
);
2163 spin_lock_bh(&ar
->data_lock
);
2164 ar
->rx_channel
= conf
->chandef
.chan
;
2165 spin_unlock_bh(&ar
->data_lock
);
2167 ath10k_config_radar_detection(ar
);
2170 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
2171 ath10k_dbg(ATH10K_DBG_MAC
, "mac config power %d\n",
2172 hw
->conf
.power_level
);
2174 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
2175 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2176 hw
->conf
.power_level
* 2);
2178 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2179 hw
->conf
.power_level
, ret
);
2181 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
2182 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2183 hw
->conf
.power_level
* 2);
2185 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2186 hw
->conf
.power_level
, ret
);
2189 if (changed
& IEEE80211_CONF_CHANGE_PS
)
2190 ath10k_config_ps(ar
);
2192 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
2193 if (conf
->flags
& IEEE80211_CONF_MONITOR
)
2194 ret
= ath10k_monitor_create(ar
);
2196 ret
= ath10k_monitor_destroy(ar
);
2199 mutex_unlock(&ar
->conf_mutex
);
2205 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2206 * because we will send mgmt frames without CCK. This requirement
2207 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2210 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
2211 struct ieee80211_vif
*vif
)
2213 struct ath10k
*ar
= hw
->priv
;
2214 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2215 enum wmi_sta_powersave_param param
;
2217 u32 value
, param_id
;
2221 mutex_lock(&ar
->conf_mutex
);
2223 memset(arvif
, 0, sizeof(*arvif
));
2228 INIT_WORK(&arvif
->wep_key_work
, ath10k_tx_wep_key_work
);
2229 INIT_LIST_HEAD(&arvif
->list
);
2231 if ((vif
->type
== NL80211_IFTYPE_MONITOR
) && ar
->monitor_present
) {
2232 ath10k_warn("Only one monitor interface allowed\n");
2237 bit
= ffs(ar
->free_vdev_map
);
2243 arvif
->vdev_id
= bit
- 1;
2244 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
2247 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
2249 switch (vif
->type
) {
2250 case NL80211_IFTYPE_UNSPECIFIED
:
2251 case NL80211_IFTYPE_STATION
:
2252 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
2254 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
2256 case NL80211_IFTYPE_ADHOC
:
2257 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
2259 case NL80211_IFTYPE_AP
:
2260 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
2263 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
2265 case NL80211_IFTYPE_MONITOR
:
2266 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
2273 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d\n",
2274 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
2276 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
2277 arvif
->vdev_subtype
, vif
->addr
);
2279 ath10k_warn("WMI vdev create failed: ret %d\n", ret
);
2283 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2284 list_add(&arvif
->list
, &ar
->arvifs
);
2286 vdev_param
= ar
->wmi
.vdev_param
->def_keyid
;
2287 ret
= ath10k_wmi_vdev_set_param(ar
, 0, vdev_param
,
2288 arvif
->def_wep_key_idx
);
2290 ath10k_warn("Failed to set default keyid: %d\n", ret
);
2291 goto err_vdev_delete
;
2294 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
2295 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2296 ATH10K_HW_TXRX_NATIVE_WIFI
);
2297 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2298 if (ret
&& ret
!= -EOPNOTSUPP
) {
2299 ath10k_warn("Failed to set TX encap: %d\n", ret
);
2300 goto err_vdev_delete
;
2303 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2304 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
2306 ath10k_warn("Failed to create peer for AP: %d\n", ret
);
2307 goto err_vdev_delete
;
2310 param_id
= ar
->wmi
.pdev_param
->sta_kickout_th
;
2312 /* Disable STA KICKOUT functionality in FW */
2313 ret
= ath10k_wmi_pdev_set_param(ar
, param_id
, 0);
2315 ath10k_warn("Failed to disable STA KICKOUT\n");
2318 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
2319 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
2320 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2321 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2324 ath10k_warn("Failed to set RX wake policy: %d\n", ret
);
2325 goto err_peer_delete
;
2328 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
2329 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
2330 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2333 ath10k_warn("Failed to set TX wake thresh: %d\n", ret
);
2334 goto err_peer_delete
;
2337 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
2338 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
2339 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2342 ath10k_warn("Failed to set PSPOLL count: %d\n", ret
);
2343 goto err_peer_delete
;
2347 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
2349 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2350 arvif
->vdev_id
, ret
);
2351 goto err_peer_delete
;
2354 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
2356 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2357 arvif
->vdev_id
, ret
);
2358 goto err_peer_delete
;
2361 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2362 ar
->monitor_present
= true;
2364 mutex_unlock(&ar
->conf_mutex
);
2368 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
2369 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
2372 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2373 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2374 list_del(&arvif
->list
);
2377 mutex_unlock(&ar
->conf_mutex
);
2382 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
2383 struct ieee80211_vif
*vif
)
2385 struct ath10k
*ar
= hw
->priv
;
2386 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2389 mutex_lock(&ar
->conf_mutex
);
2391 cancel_work_sync(&arvif
->wep_key_work
);
2393 spin_lock_bh(&ar
->data_lock
);
2394 if (arvif
->beacon
) {
2395 dev_kfree_skb_any(arvif
->beacon
);
2396 arvif
->beacon
= NULL
;
2398 spin_unlock_bh(&ar
->data_lock
);
2400 ar
->free_vdev_map
|= 1 << (arvif
->vdev_id
);
2401 list_del(&arvif
->list
);
2403 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2404 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
2406 ath10k_warn("Failed to remove peer for AP: %d\n", ret
);
2408 kfree(arvif
->u
.ap
.noa_data
);
2411 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev delete %d (remove interface)\n",
2414 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2416 ath10k_warn("WMI vdev delete failed: %d\n", ret
);
2418 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2419 ar
->monitor_present
= false;
2421 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
2423 mutex_unlock(&ar
->conf_mutex
);
2427 * FIXME: Has to be verified.
2429 #define SUPPORTED_FILTERS \
2430 (FIF_PROMISC_IN_BSS | \
2435 FIF_BCN_PRBRESP_PROMISC | \
2439 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
2440 unsigned int changed_flags
,
2441 unsigned int *total_flags
,
2444 struct ath10k
*ar
= hw
->priv
;
2447 mutex_lock(&ar
->conf_mutex
);
2449 changed_flags
&= SUPPORTED_FILTERS
;
2450 *total_flags
&= SUPPORTED_FILTERS
;
2451 ar
->filter_flags
= *total_flags
;
2453 /* Monitor must not be started if it wasn't created first.
2454 * Promiscuous mode may be started on a non-monitor interface - in
2455 * such case the monitor vdev is not created so starting the
2456 * monitor makes no sense. Since ath10k uses no special RX filters
2457 * (only BSS filter in STA mode) there's no need for any special
2459 if ((ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2460 !ar
->monitor_enabled
&& ar
->monitor_present
) {
2461 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d start\n",
2462 ar
->monitor_vdev_id
);
2464 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
2466 ath10k_warn("Unable to start monitor mode\n");
2467 } else if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2468 ar
->monitor_enabled
&& ar
->monitor_present
) {
2469 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d stop\n",
2470 ar
->monitor_vdev_id
);
2472 ret
= ath10k_monitor_stop(ar
);
2474 ath10k_warn("Unable to stop monitor mode\n");
2477 mutex_unlock(&ar
->conf_mutex
);
2480 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
2481 struct ieee80211_vif
*vif
,
2482 struct ieee80211_bss_conf
*info
,
2485 struct ath10k
*ar
= hw
->priv
;
2486 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2488 u32 vdev_param
, pdev_param
;
2490 mutex_lock(&ar
->conf_mutex
);
2492 if (changed
& BSS_CHANGED_IBSS
)
2493 ath10k_control_ibss(arvif
, info
, vif
->addr
);
2495 if (changed
& BSS_CHANGED_BEACON_INT
) {
2496 arvif
->beacon_interval
= info
->beacon_int
;
2497 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
2498 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2499 arvif
->beacon_interval
);
2500 ath10k_dbg(ATH10K_DBG_MAC
,
2501 "mac vdev %d beacon_interval %d\n",
2502 arvif
->vdev_id
, arvif
->beacon_interval
);
2505 ath10k_warn("Failed to set beacon interval for VDEV: %d\n",
2509 if (changed
& BSS_CHANGED_BEACON
) {
2510 ath10k_dbg(ATH10K_DBG_MAC
,
2511 "vdev %d set beacon tx mode to staggered\n",
2514 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
2515 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
2516 WMI_BEACON_STAGGERED_MODE
);
2518 ath10k_warn("Failed to set beacon mode for VDEV: %d\n",
2522 if (changed
& BSS_CHANGED_BEACON_INFO
) {
2523 arvif
->dtim_period
= info
->dtim_period
;
2525 ath10k_dbg(ATH10K_DBG_MAC
,
2526 "mac vdev %d dtim_period %d\n",
2527 arvif
->vdev_id
, arvif
->dtim_period
);
2529 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
2530 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2531 arvif
->dtim_period
);
2533 ath10k_warn("Failed to set dtim period for VDEV: %d\n",
2537 if (changed
& BSS_CHANGED_SSID
&&
2538 vif
->type
== NL80211_IFTYPE_AP
) {
2539 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
2541 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
2542 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
2545 if (changed
& BSS_CHANGED_BSSID
) {
2546 if (!is_zero_ether_addr(info
->bssid
)) {
2547 ath10k_dbg(ATH10K_DBG_MAC
,
2548 "mac vdev %d create peer %pM\n",
2549 arvif
->vdev_id
, info
->bssid
);
2551 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
2554 ath10k_warn("Failed to add peer %pM for vdev %d when changin bssid: %i\n",
2555 info
->bssid
, arvif
->vdev_id
, ret
);
2557 if (vif
->type
== NL80211_IFTYPE_STATION
) {
2559 * this is never erased as we it for crypto key
2560 * clearing; this is FW requirement
2562 memcpy(arvif
->u
.sta
.bssid
, info
->bssid
,
2565 ath10k_dbg(ATH10K_DBG_MAC
,
2566 "mac vdev %d start %pM\n",
2567 arvif
->vdev_id
, info
->bssid
);
2569 /* FIXME: check return value */
2570 ret
= ath10k_vdev_start(arvif
);
2574 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2575 * so driver need to store it. It is needed when leaving
2576 * IBSS in order to remove BSSID peer.
2578 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
2579 memcpy(arvif
->u
.ibss
.bssid
, info
->bssid
,
2584 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
2585 ath10k_control_beaconing(arvif
, info
);
2587 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
2589 if (info
->use_cts_prot
)
2594 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
2595 arvif
->vdev_id
, cts_prot
);
2597 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
2598 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2601 ath10k_warn("Failed to set CTS prot for VDEV: %d\n",
2605 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2607 if (info
->use_short_slot
)
2608 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
2611 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
2613 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
2614 arvif
->vdev_id
, slottime
);
2616 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
2617 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2620 ath10k_warn("Failed to set erp slot for VDEV: %d\n",
2624 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
2626 if (info
->use_short_preamble
)
2627 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
2629 preamble
= WMI_VDEV_PREAMBLE_LONG
;
2631 ath10k_dbg(ATH10K_DBG_MAC
,
2632 "mac vdev %d preamble %dn",
2633 arvif
->vdev_id
, preamble
);
2635 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
2636 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2639 ath10k_warn("Failed to set preamble for VDEV: %d\n",
2643 if (changed
& BSS_CHANGED_ASSOC
) {
2645 ath10k_bss_assoc(hw
, vif
, info
);
2648 mutex_unlock(&ar
->conf_mutex
);
2651 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
2652 struct ieee80211_vif
*vif
,
2653 struct cfg80211_scan_request
*req
)
2655 struct ath10k
*ar
= hw
->priv
;
2656 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2657 struct wmi_start_scan_arg arg
;
2661 mutex_lock(&ar
->conf_mutex
);
2663 spin_lock_bh(&ar
->data_lock
);
2664 if (ar
->scan
.in_progress
) {
2665 spin_unlock_bh(&ar
->data_lock
);
2670 reinit_completion(&ar
->scan
.started
);
2671 reinit_completion(&ar
->scan
.completed
);
2672 ar
->scan
.in_progress
= true;
2673 ar
->scan
.aborting
= false;
2674 ar
->scan
.is_roc
= false;
2675 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2676 spin_unlock_bh(&ar
->data_lock
);
2678 memset(&arg
, 0, sizeof(arg
));
2679 ath10k_wmi_start_scan_init(ar
, &arg
);
2680 arg
.vdev_id
= arvif
->vdev_id
;
2681 arg
.scan_id
= ATH10K_SCAN_ID
;
2684 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
2687 arg
.ie_len
= req
->ie_len
;
2688 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
2692 arg
.n_ssids
= req
->n_ssids
;
2693 for (i
= 0; i
< arg
.n_ssids
; i
++) {
2694 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
2695 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
2698 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2701 if (req
->n_channels
) {
2702 arg
.n_channels
= req
->n_channels
;
2703 for (i
= 0; i
< arg
.n_channels
; i
++)
2704 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
2707 ret
= ath10k_start_scan(ar
, &arg
);
2709 ath10k_warn("could not start hw scan (%d)\n", ret
);
2710 spin_lock_bh(&ar
->data_lock
);
2711 ar
->scan
.in_progress
= false;
2712 spin_unlock_bh(&ar
->data_lock
);
2716 mutex_unlock(&ar
->conf_mutex
);
2720 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
2721 struct ieee80211_vif
*vif
)
2723 struct ath10k
*ar
= hw
->priv
;
2726 mutex_lock(&ar
->conf_mutex
);
2727 ret
= ath10k_abort_scan(ar
);
2729 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
2731 ieee80211_scan_completed(hw
, 1 /* aborted */);
2733 mutex_unlock(&ar
->conf_mutex
);
2736 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
2737 struct ath10k_vif
*arvif
,
2738 enum set_key_cmd cmd
,
2739 struct ieee80211_key_conf
*key
)
2741 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
2744 /* 10.1 firmware branch requires default key index to be set to group
2745 * key index after installing it. Otherwise FW/HW Txes corrupted
2746 * frames with multi-vif APs. This is not required for main firmware
2747 * branch (e.g. 636).
2749 * FIXME: This has been tested only in AP. It remains unknown if this
2750 * is required for multi-vif STA interfaces on 10.1 */
2752 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
2755 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
2758 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
2761 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
2767 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2770 ath10k_warn("failed to set group key as default key: %d\n",
2774 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2775 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
2776 struct ieee80211_key_conf
*key
)
2778 struct ath10k
*ar
= hw
->priv
;
2779 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2780 struct ath10k_peer
*peer
;
2781 const u8
*peer_addr
;
2782 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2783 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
2786 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
2789 mutex_lock(&ar
->conf_mutex
);
2792 peer_addr
= sta
->addr
;
2793 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
2794 peer_addr
= vif
->bss_conf
.bssid
;
2796 peer_addr
= vif
->addr
;
2798 key
->hw_key_idx
= key
->keyidx
;
2800 /* the peer should not disappear in mid-way (unless FW goes awry) since
2801 * we already hold conf_mutex. we just make sure its there now. */
2802 spin_lock_bh(&ar
->data_lock
);
2803 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2804 spin_unlock_bh(&ar
->data_lock
);
2807 if (cmd
== SET_KEY
) {
2808 ath10k_warn("cannot install key for non-existent peer %pM\n",
2813 /* if the peer doesn't exist there is no key to disable
2821 arvif
->wep_keys
[key
->keyidx
] = key
;
2823 arvif
->wep_keys
[key
->keyidx
] = NULL
;
2825 if (cmd
== DISABLE_KEY
)
2826 ath10k_clear_vdev_key(arvif
, key
);
2829 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
2831 ath10k_warn("ath10k_install_key failed (%d)\n", ret
);
2835 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
2837 spin_lock_bh(&ar
->data_lock
);
2838 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
2839 if (peer
&& cmd
== SET_KEY
)
2840 peer
->keys
[key
->keyidx
] = key
;
2841 else if (peer
&& cmd
== DISABLE_KEY
)
2842 peer
->keys
[key
->keyidx
] = NULL
;
2843 else if (peer
== NULL
)
2844 /* impossible unless FW goes crazy */
2845 ath10k_warn("peer %pM disappeared!\n", peer_addr
);
2846 spin_unlock_bh(&ar
->data_lock
);
2849 mutex_unlock(&ar
->conf_mutex
);
2853 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
2854 struct ieee80211_vif
*vif
,
2855 struct ieee80211_sta
*sta
,
2856 enum ieee80211_sta_state old_state
,
2857 enum ieee80211_sta_state new_state
)
2859 struct ath10k
*ar
= hw
->priv
;
2860 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2864 mutex_lock(&ar
->conf_mutex
);
2866 if (old_state
== IEEE80211_STA_NOTEXIST
&&
2867 new_state
== IEEE80211_STA_NONE
&&
2868 vif
->type
!= NL80211_IFTYPE_STATION
) {
2870 * New station addition.
2872 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
))
2873 max_num_peers
= TARGET_10X_NUM_PEERS_MAX
- 1;
2875 max_num_peers
= TARGET_NUM_PEERS
;
2877 if (ar
->num_peers
>= max_num_peers
) {
2878 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
2879 ar
->num_peers
, max_num_peers
);
2884 ath10k_dbg(ATH10K_DBG_MAC
,
2885 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
2886 arvif
->vdev_id
, sta
->addr
, ar
->num_peers
);
2888 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
2890 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
2891 sta
->addr
, arvif
->vdev_id
, ret
);
2892 } else if ((old_state
== IEEE80211_STA_NONE
&&
2893 new_state
== IEEE80211_STA_NOTEXIST
)) {
2895 * Existing station deletion.
2897 ath10k_dbg(ATH10K_DBG_MAC
,
2898 "mac vdev %d peer delete %pM (sta gone)\n",
2899 arvif
->vdev_id
, sta
->addr
);
2900 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
2902 ath10k_warn("Failed to delete peer: %pM for VDEV: %d\n",
2903 sta
->addr
, arvif
->vdev_id
);
2905 if (vif
->type
== NL80211_IFTYPE_STATION
)
2906 ath10k_bss_disassoc(hw
, vif
);
2907 } else if (old_state
== IEEE80211_STA_AUTH
&&
2908 new_state
== IEEE80211_STA_ASSOC
&&
2909 (vif
->type
== NL80211_IFTYPE_AP
||
2910 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2914 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM associated\n",
2917 ret
= ath10k_station_assoc(ar
, arvif
, sta
);
2919 ath10k_warn("Failed to associate station: %pM\n",
2921 } else if (old_state
== IEEE80211_STA_ASSOC
&&
2922 new_state
== IEEE80211_STA_AUTH
&&
2923 (vif
->type
== NL80211_IFTYPE_AP
||
2924 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
2928 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
2931 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
2933 ath10k_warn("Failed to disassociate station: %pM\n",
2937 mutex_unlock(&ar
->conf_mutex
);
2941 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
2942 u16 ac
, bool enable
)
2944 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2948 lockdep_assert_held(&ar
->conf_mutex
);
2950 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
2954 case IEEE80211_AC_VO
:
2955 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
2956 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
2958 case IEEE80211_AC_VI
:
2959 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
2960 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
2962 case IEEE80211_AC_BE
:
2963 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
2964 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
2966 case IEEE80211_AC_BK
:
2967 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
2968 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
2973 arvif
->u
.sta
.uapsd
|= value
;
2975 arvif
->u
.sta
.uapsd
&= ~value
;
2977 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2978 WMI_STA_PS_PARAM_UAPSD
,
2979 arvif
->u
.sta
.uapsd
);
2981 ath10k_warn("could not set uapsd params %d\n", ret
);
2985 if (arvif
->u
.sta
.uapsd
)
2986 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
2988 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2990 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2991 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
2994 ath10k_warn("could not set rx wake param %d\n", ret
);
3000 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
3001 struct ieee80211_vif
*vif
, u16 ac
,
3002 const struct ieee80211_tx_queue_params
*params
)
3004 struct ath10k
*ar
= hw
->priv
;
3005 struct wmi_wmm_params_arg
*p
= NULL
;
3008 mutex_lock(&ar
->conf_mutex
);
3011 case IEEE80211_AC_VO
:
3012 p
= &ar
->wmm_params
.ac_vo
;
3014 case IEEE80211_AC_VI
:
3015 p
= &ar
->wmm_params
.ac_vi
;
3017 case IEEE80211_AC_BE
:
3018 p
= &ar
->wmm_params
.ac_be
;
3020 case IEEE80211_AC_BK
:
3021 p
= &ar
->wmm_params
.ac_bk
;
3030 p
->cwmin
= params
->cw_min
;
3031 p
->cwmax
= params
->cw_max
;
3032 p
->aifs
= params
->aifs
;
3035 * The channel time duration programmed in the HW is in absolute
3036 * microseconds, while mac80211 gives the txop in units of
3039 p
->txop
= params
->txop
* 32;
3041 /* FIXME: FW accepts wmm params per hw, not per vif */
3042 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
3044 ath10k_warn("could not set wmm params %d\n", ret
);
3048 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
3050 ath10k_warn("could not set sta uapsd %d\n", ret
);
3053 mutex_unlock(&ar
->conf_mutex
);
3057 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3059 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
3060 struct ieee80211_vif
*vif
,
3061 struct ieee80211_channel
*chan
,
3063 enum ieee80211_roc_type type
)
3065 struct ath10k
*ar
= hw
->priv
;
3066 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3067 struct wmi_start_scan_arg arg
;
3070 mutex_lock(&ar
->conf_mutex
);
3072 spin_lock_bh(&ar
->data_lock
);
3073 if (ar
->scan
.in_progress
) {
3074 spin_unlock_bh(&ar
->data_lock
);
3079 reinit_completion(&ar
->scan
.started
);
3080 reinit_completion(&ar
->scan
.completed
);
3081 reinit_completion(&ar
->scan
.on_channel
);
3082 ar
->scan
.in_progress
= true;
3083 ar
->scan
.aborting
= false;
3084 ar
->scan
.is_roc
= true;
3085 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3086 ar
->scan
.roc_freq
= chan
->center_freq
;
3087 spin_unlock_bh(&ar
->data_lock
);
3089 memset(&arg
, 0, sizeof(arg
));
3090 ath10k_wmi_start_scan_init(ar
, &arg
);
3091 arg
.vdev_id
= arvif
->vdev_id
;
3092 arg
.scan_id
= ATH10K_SCAN_ID
;
3094 arg
.channels
[0] = chan
->center_freq
;
3095 arg
.dwell_time_active
= duration
;
3096 arg
.dwell_time_passive
= duration
;
3097 arg
.max_scan_time
= 2 * duration
;
3098 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3099 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
3101 ret
= ath10k_start_scan(ar
, &arg
);
3103 ath10k_warn("could not start roc scan (%d)\n", ret
);
3104 spin_lock_bh(&ar
->data_lock
);
3105 ar
->scan
.in_progress
= false;
3106 spin_unlock_bh(&ar
->data_lock
);
3110 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
3112 ath10k_warn("could not switch to channel for roc scan\n");
3113 ath10k_abort_scan(ar
);
3120 mutex_unlock(&ar
->conf_mutex
);
3124 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
3126 struct ath10k
*ar
= hw
->priv
;
3128 mutex_lock(&ar
->conf_mutex
);
3129 ath10k_abort_scan(ar
);
3130 mutex_unlock(&ar
->conf_mutex
);
3136 * Both RTS and Fragmentation threshold are interface-specific
3137 * in ath10k, but device-specific in mac80211.
3140 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3142 struct ath10k
*ar
= hw
->priv
;
3143 struct ath10k_vif
*arvif
;
3146 mutex_lock(&ar
->conf_mutex
);
3147 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3148 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
3149 arvif
->vdev_id
, value
);
3151 ret
= ath10k_mac_set_rts(arvif
, value
);
3153 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3154 arvif
->vdev_id
, ret
);
3158 mutex_unlock(&ar
->conf_mutex
);
3163 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3165 struct ath10k
*ar
= hw
->priv
;
3166 struct ath10k_vif
*arvif
;
3169 mutex_lock(&ar
->conf_mutex
);
3170 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3171 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d fragmentation threshold %d\n",
3172 arvif
->vdev_id
, value
);
3174 ret
= ath10k_mac_set_rts(arvif
, value
);
3176 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3177 arvif
->vdev_id
, ret
);
3181 mutex_unlock(&ar
->conf_mutex
);
3186 static void ath10k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
3188 struct ath10k
*ar
= hw
->priv
;
3192 /* mac80211 doesn't care if we really xmit queued frames or not
3193 * we'll collect those frames either way if we stop/delete vdevs */
3197 mutex_lock(&ar
->conf_mutex
);
3199 if (ar
->state
== ATH10K_STATE_WEDGED
)
3202 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
3205 spin_lock_bh(&ar
->htt
.tx_lock
);
3206 empty
= (ar
->htt
.num_pending_tx
== 0);
3207 spin_unlock_bh(&ar
->htt
.tx_lock
);
3209 skip
= (ar
->state
== ATH10K_STATE_WEDGED
);
3212 }), ATH10K_FLUSH_TIMEOUT_HZ
);
3214 if (ret
<= 0 || skip
)
3215 ath10k_warn("tx not flushed\n");
3218 mutex_unlock(&ar
->conf_mutex
);
3221 /* TODO: Implement this function properly
3222 * For now it is needed to reply to Probe Requests in IBSS mode.
3223 * Propably we need this information from FW.
3225 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
3231 static int ath10k_suspend(struct ieee80211_hw
*hw
,
3232 struct cfg80211_wowlan
*wowlan
)
3234 struct ath10k
*ar
= hw
->priv
;
3237 ar
->is_target_paused
= false;
3239 ret
= ath10k_wmi_pdev_suspend_target(ar
);
3241 ath10k_warn("could not suspend target (%d)\n", ret
);
3245 ret
= wait_event_interruptible_timeout(ar
->event_queue
,
3246 ar
->is_target_paused
== true,
3249 ath10k_warn("suspend interrupted (%d)\n", ret
);
3251 } else if (ret
== 0) {
3252 ath10k_warn("suspend timed out - target pause event never came\n");
3256 ret
= ath10k_hif_suspend(ar
);
3258 ath10k_warn("could not suspend hif (%d)\n", ret
);
3264 ret
= ath10k_wmi_pdev_resume_target(ar
);
3266 ath10k_warn("could not resume target (%d)\n", ret
);
3270 static int ath10k_resume(struct ieee80211_hw
*hw
)
3272 struct ath10k
*ar
= hw
->priv
;
3275 ret
= ath10k_hif_resume(ar
);
3277 ath10k_warn("could not resume hif (%d)\n", ret
);
3281 ret
= ath10k_wmi_pdev_resume_target(ar
);
3283 ath10k_warn("could not resume target (%d)\n", ret
);
3291 static void ath10k_restart_complete(struct ieee80211_hw
*hw
)
3293 struct ath10k
*ar
= hw
->priv
;
3295 mutex_lock(&ar
->conf_mutex
);
3297 /* If device failed to restart it will be in a different state, e.g.
3298 * ATH10K_STATE_WEDGED */
3299 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
3300 ath10k_info("device successfully recovered\n");
3301 ar
->state
= ATH10K_STATE_ON
;
3304 mutex_unlock(&ar
->conf_mutex
);
3307 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
3308 struct survey_info
*survey
)
3310 struct ath10k
*ar
= hw
->priv
;
3311 struct ieee80211_supported_band
*sband
;
3312 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
3315 mutex_lock(&ar
->conf_mutex
);
3317 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
3318 if (sband
&& idx
>= sband
->n_channels
) {
3319 idx
-= sband
->n_channels
;
3324 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
3326 if (!sband
|| idx
>= sband
->n_channels
) {
3331 spin_lock_bh(&ar
->data_lock
);
3332 memcpy(survey
, ar_survey
, sizeof(*survey
));
3333 spin_unlock_bh(&ar
->data_lock
);
3335 survey
->channel
= &sband
->channels
[idx
];
3338 mutex_unlock(&ar
->conf_mutex
);
3342 /* Helper table for legacy fixed_rate/bitrate_mask */
3343 static const u8 cck_ofdm_rate
[] = {
3360 /* Check if only one bit set */
3361 static int ath10k_check_single_mask(u32 mask
)
3369 mask
&= ~BIT(bit
- 1);
3377 ath10k_default_bitrate_mask(struct ath10k
*ar
,
3378 enum ieee80211_band band
,
3379 const struct cfg80211_bitrate_mask
*mask
)
3381 u32 legacy
= 0x00ff;
3386 case IEEE80211_BAND_2GHZ
:
3390 case IEEE80211_BAND_5GHZ
:
3396 if (mask
->control
[band
].legacy
!= legacy
)
3399 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3400 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
3403 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3404 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
3411 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
3412 enum ieee80211_band band
,
3415 int ht_nss
= 0, vht_nss
= 0, i
;
3418 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
3422 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3423 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
3425 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
3434 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3435 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
3437 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
3445 if (ht_nss
> 0 && vht_nss
> 0)
3449 *fixed_nss
= ht_nss
;
3451 *fixed_nss
= vht_nss
;
3459 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
3460 enum ieee80211_band band
,
3461 enum wmi_rate_preamble
*preamble
)
3463 int legacy
= 0, ht
= 0, vht
= 0, i
;
3465 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
3468 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
3473 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3474 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
3479 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3480 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
3484 /* Currently we support only one fixed_rate */
3485 if ((legacy
+ ht
+ vht
) != 1)
3489 *preamble
= WMI_RATE_PREAMBLE_HT
;
3491 *preamble
= WMI_RATE_PREAMBLE_VHT
;
3497 ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask
*mask
,
3498 enum ieee80211_band band
,
3502 u8 rate
= 0, pream
= 0, nss
= 0, i
;
3503 enum wmi_rate_preamble preamble
;
3505 /* Check if single rate correct */
3506 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
3512 case WMI_RATE_PREAMBLE_CCK
:
3513 case WMI_RATE_PREAMBLE_OFDM
:
3514 i
= ffs(mask
->control
[band
].legacy
) - 1;
3516 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
3517 pream
= WMI_RATE_PREAMBLE_CCK
;
3519 if (band
== IEEE80211_BAND_5GHZ
)
3522 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
3525 rate
= cck_ofdm_rate
[i
];
3527 case WMI_RATE_PREAMBLE_HT
:
3528 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3529 if (mask
->control
[band
].ht_mcs
[i
])
3532 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
3535 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
3538 case WMI_RATE_PREAMBLE_VHT
:
3539 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3540 if (mask
->control
[band
].vht_mcs
[i
])
3543 if (i
== NL80211_VHT_NSS_MAX
)
3546 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
3551 *fixed_nss
= nss
+ 1;
3555 ath10k_dbg(ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3558 *fixed_rate
= pream
| nss
| rate
;
3563 static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask
*mask
,
3564 enum ieee80211_band band
,
3568 /* First check full NSS mask, if we can simply limit NSS */
3569 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
3572 /* Next Check single rate is set */
3573 return ath10k_bitrate_mask_rate(mask
, band
, fixed_rate
, fixed_nss
);
3576 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
3580 struct ath10k
*ar
= arvif
->ar
;
3584 mutex_lock(&ar
->conf_mutex
);
3586 if (arvif
->fixed_rate
== fixed_rate
&&
3587 arvif
->fixed_nss
== fixed_nss
)
3590 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
3591 ath10k_dbg(ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
3593 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
3594 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
3595 vdev_param
, fixed_rate
);
3597 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3603 arvif
->fixed_rate
= fixed_rate
;
3605 vdev_param
= ar
->wmi
.vdev_param
->nss
;
3606 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
3607 vdev_param
, fixed_nss
);
3610 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3616 arvif
->fixed_nss
= fixed_nss
;
3619 mutex_unlock(&ar
->conf_mutex
);
3623 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
3624 struct ieee80211_vif
*vif
,
3625 const struct cfg80211_bitrate_mask
*mask
)
3627 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3628 struct ath10k
*ar
= arvif
->ar
;
3629 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
3630 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
3631 u8 fixed_nss
= ar
->num_rf_chains
;
3633 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
3634 if (!ath10k_get_fixed_rate_nss(mask
, band
,
3640 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
, fixed_nss
);
3643 static const struct ieee80211_ops ath10k_ops
= {
3645 .start
= ath10k_start
,
3646 .stop
= ath10k_stop
,
3647 .config
= ath10k_config
,
3648 .add_interface
= ath10k_add_interface
,
3649 .remove_interface
= ath10k_remove_interface
,
3650 .configure_filter
= ath10k_configure_filter
,
3651 .bss_info_changed
= ath10k_bss_info_changed
,
3652 .hw_scan
= ath10k_hw_scan
,
3653 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
3654 .set_key
= ath10k_set_key
,
3655 .sta_state
= ath10k_sta_state
,
3656 .conf_tx
= ath10k_conf_tx
,
3657 .remain_on_channel
= ath10k_remain_on_channel
,
3658 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
3659 .set_rts_threshold
= ath10k_set_rts_threshold
,
3660 .set_frag_threshold
= ath10k_set_frag_threshold
,
3661 .flush
= ath10k_flush
,
3662 .tx_last_beacon
= ath10k_tx_last_beacon
,
3663 .restart_complete
= ath10k_restart_complete
,
3664 .get_survey
= ath10k_get_survey
,
3665 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
3667 .suspend
= ath10k_suspend
,
3668 .resume
= ath10k_resume
,
3672 #define RATETAB_ENT(_rate, _rateid, _flags) { \
3673 .bitrate = (_rate), \
3674 .flags = (_flags), \
3675 .hw_value = (_rateid), \
3678 #define CHAN2G(_channel, _freq, _flags) { \
3679 .band = IEEE80211_BAND_2GHZ, \
3680 .hw_value = (_channel), \
3681 .center_freq = (_freq), \
3682 .flags = (_flags), \
3683 .max_antenna_gain = 0, \
3687 #define CHAN5G(_channel, _freq, _flags) { \
3688 .band = IEEE80211_BAND_5GHZ, \
3689 .hw_value = (_channel), \
3690 .center_freq = (_freq), \
3691 .flags = (_flags), \
3692 .max_antenna_gain = 0, \
3696 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
3706 CHAN2G(10, 2457, 0),
3707 CHAN2G(11, 2462, 0),
3708 CHAN2G(12, 2467, 0),
3709 CHAN2G(13, 2472, 0),
3710 CHAN2G(14, 2484, 0),
3713 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
3714 CHAN5G(36, 5180, 0),
3715 CHAN5G(40, 5200, 0),
3716 CHAN5G(44, 5220, 0),
3717 CHAN5G(48, 5240, 0),
3718 CHAN5G(52, 5260, 0),
3719 CHAN5G(56, 5280, 0),
3720 CHAN5G(60, 5300, 0),
3721 CHAN5G(64, 5320, 0),
3722 CHAN5G(100, 5500, 0),
3723 CHAN5G(104, 5520, 0),
3724 CHAN5G(108, 5540, 0),
3725 CHAN5G(112, 5560, 0),
3726 CHAN5G(116, 5580, 0),
3727 CHAN5G(120, 5600, 0),
3728 CHAN5G(124, 5620, 0),
3729 CHAN5G(128, 5640, 0),
3730 CHAN5G(132, 5660, 0),
3731 CHAN5G(136, 5680, 0),
3732 CHAN5G(140, 5700, 0),
3733 CHAN5G(149, 5745, 0),
3734 CHAN5G(153, 5765, 0),
3735 CHAN5G(157, 5785, 0),
3736 CHAN5G(161, 5805, 0),
3737 CHAN5G(165, 5825, 0),
3740 static struct ieee80211_rate ath10k_rates
[] = {
3742 RATETAB_ENT(10, 0x82, 0),
3743 RATETAB_ENT(20, 0x84, 0),
3744 RATETAB_ENT(55, 0x8b, 0),
3745 RATETAB_ENT(110, 0x96, 0),
3747 RATETAB_ENT(60, 0x0c, 0),
3748 RATETAB_ENT(90, 0x12, 0),
3749 RATETAB_ENT(120, 0x18, 0),
3750 RATETAB_ENT(180, 0x24, 0),
3751 RATETAB_ENT(240, 0x30, 0),
3752 RATETAB_ENT(360, 0x48, 0),
3753 RATETAB_ENT(480, 0x60, 0),
3754 RATETAB_ENT(540, 0x6c, 0),
3757 #define ath10k_a_rates (ath10k_rates + 4)
3758 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
3759 #define ath10k_g_rates (ath10k_rates + 0)
3760 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
3762 struct ath10k
*ath10k_mac_create(void)
3764 struct ieee80211_hw
*hw
;
3767 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
), &ath10k_ops
);
3777 void ath10k_mac_destroy(struct ath10k
*ar
)
3779 ieee80211_free_hw(ar
->hw
);
3782 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
3785 .types
= BIT(NL80211_IFTYPE_STATION
)
3786 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
3790 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
3794 .types
= BIT(NL80211_IFTYPE_AP
)
3798 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
3801 .types
= BIT(NL80211_IFTYPE_AP
)
3805 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
3807 .limits
= ath10k_if_limits
,
3808 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
3809 .max_interfaces
= 8,
3810 .num_different_channels
= 1,
3811 .beacon_int_infra_match
= true,
3815 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
3817 .limits
= ath10k_10x_if_limits
,
3818 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
3819 .max_interfaces
= 8,
3820 .num_different_channels
= 1,
3821 .beacon_int_infra_match
= true,
3822 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
3823 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
3824 BIT(NL80211_CHAN_WIDTH_20
) |
3825 BIT(NL80211_CHAN_WIDTH_40
) |
3826 BIT(NL80211_CHAN_WIDTH_80
),
3831 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
3833 struct ieee80211_sta_vht_cap vht_cap
= {0};
3837 vht_cap
.vht_supported
= 1;
3838 vht_cap
.cap
= ar
->vht_cap_info
;
3841 for (i
= 0; i
< 8; i
++) {
3842 if (i
< ar
->num_rf_chains
)
3843 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
3845 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
3848 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
3849 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
3854 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
3857 struct ieee80211_sta_ht_cap ht_cap
= {0};
3859 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
3862 ht_cap
.ht_supported
= 1;
3863 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
3864 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
3865 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
3866 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
3867 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
3869 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
3870 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
3872 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
3873 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
3875 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
3878 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
3879 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
3884 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
3885 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
3887 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
3890 stbc
= ar
->ht_cap_info
;
3891 stbc
&= WMI_HT_CAP_RX_STBC
;
3892 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
3893 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
3894 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
3899 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
3900 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
3902 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
3903 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
3905 /* max AMSDU is implicitly taken from vht_cap_info */
3906 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
3907 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
3909 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3910 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
3912 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
3918 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
3919 struct ieee80211_vif
*vif
)
3921 struct ath10k_vif_iter
*arvif_iter
= data
;
3922 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3924 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
3925 arvif_iter
->arvif
= arvif
;
3928 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
3930 struct ath10k_vif_iter arvif_iter
;
3933 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
3934 arvif_iter
.vdev_id
= vdev_id
;
3936 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
3937 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
3939 ath10k_get_arvif_iter
,
3941 if (!arvif_iter
.arvif
) {
3942 ath10k_warn("No VIF found for VDEV: %d\n", vdev_id
);
3946 return arvif_iter
.arvif
;
3949 int ath10k_mac_register(struct ath10k
*ar
)
3951 struct ieee80211_supported_band
*band
;
3952 struct ieee80211_sta_vht_cap vht_cap
;
3953 struct ieee80211_sta_ht_cap ht_cap
;
3957 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
3959 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
3961 ht_cap
= ath10k_get_ht_cap(ar
);
3962 vht_cap
= ath10k_create_vht_cap(ar
);
3964 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
3965 channels
= kmemdup(ath10k_2ghz_channels
,
3966 sizeof(ath10k_2ghz_channels
),
3973 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
3974 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
3975 band
->channels
= channels
;
3976 band
->n_bitrates
= ath10k_g_rates_size
;
3977 band
->bitrates
= ath10k_g_rates
;
3978 band
->ht_cap
= ht_cap
;
3980 /* vht is not supported in 2.4 GHz */
3982 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
3985 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
3986 channels
= kmemdup(ath10k_5ghz_channels
,
3987 sizeof(ath10k_5ghz_channels
),
3994 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
3995 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
3996 band
->channels
= channels
;
3997 band
->n_bitrates
= ath10k_a_rates_size
;
3998 band
->bitrates
= ath10k_a_rates
;
3999 band
->ht_cap
= ht_cap
;
4000 band
->vht_cap
= vht_cap
;
4001 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
4004 ar
->hw
->wiphy
->interface_modes
=
4005 BIT(NL80211_IFTYPE_STATION
) |
4006 BIT(NL80211_IFTYPE_ADHOC
) |
4007 BIT(NL80211_IFTYPE_AP
);
4009 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
4010 ar
->hw
->wiphy
->interface_modes
|=
4011 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
4012 BIT(NL80211_IFTYPE_P2P_GO
);
4014 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
4015 IEEE80211_HW_SUPPORTS_PS
|
4016 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
4017 IEEE80211_HW_SUPPORTS_UAPSD
|
4018 IEEE80211_HW_MFP_CAPABLE
|
4019 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
4020 IEEE80211_HW_HAS_RATE_CONTROL
|
4021 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
4022 IEEE80211_HW_WANT_MONITOR_VIF
|
4023 IEEE80211_HW_AP_LINK_PS
;
4025 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4026 * bytes is used for padding/alignment if necessary. */
4027 ar
->hw
->extra_tx_headroom
+= sizeof(struct htt_data_tx_desc_frag
)*2 + 4;
4029 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
4030 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
4032 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
4033 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
4034 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
4037 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
4038 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
4040 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
4042 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
4044 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
4045 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
4047 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
4049 * on LL hardware queues are managed entirely by the FW
4050 * so we only advertise to mac we can do the queues thing
4054 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
4055 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
4056 ar
->hw
->wiphy
->n_iface_combinations
=
4057 ARRAY_SIZE(ath10k_10x_if_comb
);
4059 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
4060 ar
->hw
->wiphy
->n_iface_combinations
=
4061 ARRAY_SIZE(ath10k_if_comb
);
4064 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
4066 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
4067 /* Init ath dfs pattern detector */
4068 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
4069 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
4072 if (!ar
->dfs_detector
)
4073 ath10k_warn("dfs pattern detector init failed\n");
4076 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
4077 ath10k_reg_notifier
);
4079 ath10k_err("Regulatory initialization failed\n");
4083 ret
= ieee80211_register_hw(ar
->hw
);
4085 ath10k_err("ieee80211 registration failed: %d\n", ret
);
4089 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
4090 ret
= regulatory_hint(ar
->hw
->wiphy
,
4091 ar
->ath_common
.regulatory
.alpha2
);
4093 goto err_unregister
;
4099 ieee80211_unregister_hw(ar
->hw
);
4101 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4102 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4107 void ath10k_mac_unregister(struct ath10k
*ar
)
4109 ieee80211_unregister_hw(ar
->hw
);
4111 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
4112 ar
->dfs_detector
->exit(ar
->dfs_detector
);
4114 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4115 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4117 SET_IEEE80211_DEV(ar
->hw
, NULL
);