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>
35 static int ath10k_send_key(struct ath10k_vif
*arvif
,
36 struct ieee80211_key_conf
*key
,
40 struct ath10k
*ar
= arvif
->ar
;
41 struct wmi_vdev_install_key_arg arg
= {
42 .vdev_id
= arvif
->vdev_id
,
43 .key_idx
= key
->keyidx
,
44 .key_len
= key
->keylen
,
49 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
51 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
52 arg
.key_flags
= WMI_KEY_PAIRWISE
;
54 arg
.key_flags
= WMI_KEY_GROUP
;
56 switch (key
->cipher
) {
57 case WLAN_CIPHER_SUITE_CCMP
:
58 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
59 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
60 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT
;
62 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
64 case WLAN_CIPHER_SUITE_TKIP
:
65 arg
.key_cipher
= WMI_CIPHER_TKIP
;
66 arg
.key_txmic_len
= 8;
67 arg
.key_rxmic_len
= 8;
69 case WLAN_CIPHER_SUITE_WEP40
:
70 case WLAN_CIPHER_SUITE_WEP104
:
71 arg
.key_cipher
= WMI_CIPHER_WEP
;
72 /* AP/IBSS mode requires self-key to be groupwise
73 * Otherwise pairwise key must be set */
74 if (memcmp(macaddr
, arvif
->vif
->addr
, ETH_ALEN
))
75 arg
.key_flags
= WMI_KEY_PAIRWISE
;
78 ath10k_warn(ar
, "cipher %d is not supported\n", key
->cipher
);
82 if (cmd
== DISABLE_KEY
) {
83 arg
.key_cipher
= WMI_CIPHER_NONE
;
87 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
90 static int ath10k_install_key(struct ath10k_vif
*arvif
,
91 struct ieee80211_key_conf
*key
,
95 struct ath10k
*ar
= arvif
->ar
;
98 lockdep_assert_held(&ar
->conf_mutex
);
100 reinit_completion(&ar
->install_key_done
);
102 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
);
106 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
113 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
116 struct ath10k
*ar
= arvif
->ar
;
117 struct ath10k_peer
*peer
;
121 lockdep_assert_held(&ar
->conf_mutex
);
123 spin_lock_bh(&ar
->data_lock
);
124 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
125 spin_unlock_bh(&ar
->data_lock
);
130 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
131 if (arvif
->wep_keys
[i
] == NULL
)
134 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
139 peer
->keys
[i
] = arvif
->wep_keys
[i
];
145 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
148 struct ath10k
*ar
= arvif
->ar
;
149 struct ath10k_peer
*peer
;
154 lockdep_assert_held(&ar
->conf_mutex
);
156 spin_lock_bh(&ar
->data_lock
);
157 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
158 spin_unlock_bh(&ar
->data_lock
);
163 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
164 if (peer
->keys
[i
] == NULL
)
167 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
169 if (ret
&& first_errno
== 0)
173 ath10k_warn(ar
, "failed to remove peer wep key %d: %d\n",
176 peer
->keys
[i
] = NULL
;
182 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
183 struct ieee80211_key_conf
*key
)
185 struct ath10k
*ar
= arvif
->ar
;
186 struct ath10k_peer
*peer
;
192 lockdep_assert_held(&ar
->conf_mutex
);
195 /* since ath10k_install_key we can't hold data_lock all the
196 * time, so we try to remove the keys incrementally */
197 spin_lock_bh(&ar
->data_lock
);
199 list_for_each_entry(peer
, &ar
->peers
, list
) {
200 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
201 if (peer
->keys
[i
] == key
) {
202 memcpy(addr
, peer
->addr
, ETH_ALEN
);
203 peer
->keys
[i
] = NULL
;
208 if (i
< ARRAY_SIZE(peer
->keys
))
211 spin_unlock_bh(&ar
->data_lock
);
213 if (i
== ARRAY_SIZE(peer
->keys
))
216 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
);
217 if (ret
&& first_errno
== 0)
221 ath10k_warn(ar
, "failed to remove key for %pM: %d\n",
229 /*********************/
230 /* General utilities */
231 /*********************/
233 static inline enum wmi_phy_mode
234 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
236 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
238 switch (chandef
->chan
->band
) {
239 case IEEE80211_BAND_2GHZ
:
240 switch (chandef
->width
) {
241 case NL80211_CHAN_WIDTH_20_NOHT
:
244 case NL80211_CHAN_WIDTH_20
:
245 phymode
= MODE_11NG_HT20
;
247 case NL80211_CHAN_WIDTH_40
:
248 phymode
= MODE_11NG_HT40
;
250 case NL80211_CHAN_WIDTH_5
:
251 case NL80211_CHAN_WIDTH_10
:
252 case NL80211_CHAN_WIDTH_80
:
253 case NL80211_CHAN_WIDTH_80P80
:
254 case NL80211_CHAN_WIDTH_160
:
255 phymode
= MODE_UNKNOWN
;
259 case IEEE80211_BAND_5GHZ
:
260 switch (chandef
->width
) {
261 case NL80211_CHAN_WIDTH_20_NOHT
:
264 case NL80211_CHAN_WIDTH_20
:
265 phymode
= MODE_11NA_HT20
;
267 case NL80211_CHAN_WIDTH_40
:
268 phymode
= MODE_11NA_HT40
;
270 case NL80211_CHAN_WIDTH_80
:
271 phymode
= MODE_11AC_VHT80
;
273 case NL80211_CHAN_WIDTH_5
:
274 case NL80211_CHAN_WIDTH_10
:
275 case NL80211_CHAN_WIDTH_80P80
:
276 case NL80211_CHAN_WIDTH_160
:
277 phymode
= MODE_UNKNOWN
;
285 WARN_ON(phymode
== MODE_UNKNOWN
);
289 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
292 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
293 * 0 for no restriction
302 switch (mpdudensity
) {
308 /* Our lower layer calculations limit our precision to
324 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
328 lockdep_assert_held(&ar
->conf_mutex
);
330 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
332 ath10k_warn(ar
, "failed to create wmi peer %pM on vdev %i: %i\n",
337 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
339 ath10k_warn(ar
, "failed to wait for created wmi peer %pM on vdev %i: %i\n",
343 spin_lock_bh(&ar
->data_lock
);
345 spin_unlock_bh(&ar
->data_lock
);
350 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
352 struct ath10k
*ar
= arvif
->ar
;
356 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
357 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
358 ATH10K_KICKOUT_THRESHOLD
);
360 ath10k_warn(ar
, "failed to set kickout threshold on vdev %i: %d\n",
361 arvif
->vdev_id
, ret
);
365 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
366 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
367 ATH10K_KEEPALIVE_MIN_IDLE
);
369 ath10k_warn(ar
, "failed to set keepalive minimum idle time on vdev %i: %d\n",
370 arvif
->vdev_id
, ret
);
374 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
375 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
376 ATH10K_KEEPALIVE_MAX_IDLE
);
378 ath10k_warn(ar
, "failed to set keepalive maximum idle time on vdev %i: %d\n",
379 arvif
->vdev_id
, ret
);
383 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
384 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
385 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
387 ath10k_warn(ar
, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
388 arvif
->vdev_id
, ret
);
395 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
397 struct ath10k
*ar
= arvif
->ar
;
400 if (value
!= 0xFFFFFFFF)
401 value
= min_t(u32
, arvif
->ar
->hw
->wiphy
->rts_threshold
,
404 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
405 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
408 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
410 struct ath10k
*ar
= arvif
->ar
;
413 if (value
!= 0xFFFFFFFF)
414 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
415 ATH10K_FRAGMT_THRESHOLD_MIN
,
416 ATH10K_FRAGMT_THRESHOLD_MAX
);
418 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
419 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
422 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
426 lockdep_assert_held(&ar
->conf_mutex
);
428 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
432 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
436 spin_lock_bh(&ar
->data_lock
);
438 spin_unlock_bh(&ar
->data_lock
);
443 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
445 struct ath10k_peer
*peer
, *tmp
;
447 lockdep_assert_held(&ar
->conf_mutex
);
449 spin_lock_bh(&ar
->data_lock
);
450 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
451 if (peer
->vdev_id
!= vdev_id
)
454 ath10k_warn(ar
, "removing stale peer %pM from vdev_id %d\n",
455 peer
->addr
, vdev_id
);
457 list_del(&peer
->list
);
461 spin_unlock_bh(&ar
->data_lock
);
464 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
466 struct ath10k_peer
*peer
, *tmp
;
468 lockdep_assert_held(&ar
->conf_mutex
);
470 spin_lock_bh(&ar
->data_lock
);
471 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
472 list_del(&peer
->list
);
476 spin_unlock_bh(&ar
->data_lock
);
479 /************************/
480 /* Interface management */
481 /************************/
483 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
487 lockdep_assert_held(&ar
->conf_mutex
);
489 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
490 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
497 static int ath10k_monitor_vdev_start(struct ath10k
*ar
, int vdev_id
)
499 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
500 struct ieee80211_channel
*channel
= chandef
->chan
;
501 struct wmi_vdev_start_request_arg arg
= {};
504 lockdep_assert_held(&ar
->conf_mutex
);
506 arg
.vdev_id
= vdev_id
;
507 arg
.channel
.freq
= channel
->center_freq
;
508 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
510 /* TODO setup this dynamically, what in case we
511 don't have any vifs? */
512 arg
.channel
.mode
= chan_to_phymode(chandef
);
513 arg
.channel
.chan_radar
=
514 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
516 arg
.channel
.min_power
= 0;
517 arg
.channel
.max_power
= channel
->max_power
* 2;
518 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
519 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
521 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
523 ath10k_warn(ar
, "failed to request monitor vdev %i start: %d\n",
528 ret
= ath10k_vdev_setup_sync(ar
);
530 ath10k_warn(ar
, "failed to synchronize setup for monitor vdev %i: %d\n",
535 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
537 ath10k_warn(ar
, "failed to put up monitor vdev %i: %d\n",
542 ar
->monitor_vdev_id
= vdev_id
;
544 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i started\n",
545 ar
->monitor_vdev_id
);
549 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
551 ath10k_warn(ar
, "failed to stop monitor vdev %i after start failure: %d\n",
552 ar
->monitor_vdev_id
, ret
);
557 static int ath10k_monitor_vdev_stop(struct ath10k
*ar
)
561 lockdep_assert_held(&ar
->conf_mutex
);
563 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
565 ath10k_warn(ar
, "failed to put down monitor vdev %i: %d\n",
566 ar
->monitor_vdev_id
, ret
);
568 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
570 ath10k_warn(ar
, "failed to to request monitor vdev %i stop: %d\n",
571 ar
->monitor_vdev_id
, ret
);
573 ret
= ath10k_vdev_setup_sync(ar
);
575 ath10k_warn(ar
, "failed to synchronise monitor vdev %i: %d\n",
576 ar
->monitor_vdev_id
, ret
);
578 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %i stopped\n",
579 ar
->monitor_vdev_id
);
583 static int ath10k_monitor_vdev_create(struct ath10k
*ar
)
587 lockdep_assert_held(&ar
->conf_mutex
);
589 if (ar
->free_vdev_map
== 0) {
590 ath10k_warn(ar
, "failed to find free vdev id for monitor vdev\n");
594 bit
= ffs(ar
->free_vdev_map
);
596 ar
->monitor_vdev_id
= bit
- 1;
598 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
599 WMI_VDEV_TYPE_MONITOR
,
602 ath10k_warn(ar
, "failed to request monitor vdev %i creation: %d\n",
603 ar
->monitor_vdev_id
, ret
);
607 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
608 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
609 ar
->monitor_vdev_id
);
614 static int ath10k_monitor_vdev_delete(struct ath10k
*ar
)
618 lockdep_assert_held(&ar
->conf_mutex
);
620 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
622 ath10k_warn(ar
, "failed to request wmi monitor vdev %i removal: %d\n",
623 ar
->monitor_vdev_id
, ret
);
627 ar
->free_vdev_map
|= 1 << ar
->monitor_vdev_id
;
629 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
630 ar
->monitor_vdev_id
);
634 static int ath10k_monitor_start(struct ath10k
*ar
)
638 lockdep_assert_held(&ar
->conf_mutex
);
640 ret
= ath10k_monitor_vdev_create(ar
);
642 ath10k_warn(ar
, "failed to create monitor vdev: %d\n", ret
);
646 ret
= ath10k_monitor_vdev_start(ar
, ar
->monitor_vdev_id
);
648 ath10k_warn(ar
, "failed to start monitor vdev: %d\n", ret
);
649 ath10k_monitor_vdev_delete(ar
);
653 ar
->monitor_started
= true;
654 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor started\n");
659 static int ath10k_monitor_stop(struct ath10k
*ar
)
663 lockdep_assert_held(&ar
->conf_mutex
);
665 ret
= ath10k_monitor_vdev_stop(ar
);
667 ath10k_warn(ar
, "failed to stop monitor vdev: %d\n", ret
);
671 ret
= ath10k_monitor_vdev_delete(ar
);
673 ath10k_warn(ar
, "failed to delete monitor vdev: %d\n", ret
);
677 ar
->monitor_started
= false;
678 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac monitor stopped\n");
683 static int ath10k_monitor_recalc(struct ath10k
*ar
)
687 lockdep_assert_held(&ar
->conf_mutex
);
689 should_start
= ar
->monitor
||
690 ar
->filter_flags
& FIF_PROMISC_IN_BSS
||
691 test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
693 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
694 "mac monitor recalc started? %d should? %d\n",
695 ar
->monitor_started
, should_start
);
697 if (should_start
== ar
->monitor_started
)
701 return ath10k_monitor_start(ar
);
703 return ath10k_monitor_stop(ar
);
706 static int ath10k_recalc_rtscts_prot(struct ath10k_vif
*arvif
)
708 struct ath10k
*ar
= arvif
->ar
;
709 u32 vdev_param
, rts_cts
= 0;
711 lockdep_assert_held(&ar
->conf_mutex
);
713 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
715 if (arvif
->use_cts_prot
|| arvif
->num_legacy_stations
> 0)
716 rts_cts
|= SM(WMI_RTSCTS_ENABLED
, WMI_RTSCTS_SET
);
718 if (arvif
->num_legacy_stations
> 0)
719 rts_cts
|= SM(WMI_RTSCTS_ACROSS_SW_RETRIES
,
722 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
726 static int ath10k_start_cac(struct ath10k
*ar
)
730 lockdep_assert_held(&ar
->conf_mutex
);
732 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
734 ret
= ath10k_monitor_recalc(ar
);
736 ath10k_warn(ar
, "failed to start monitor (cac): %d\n", ret
);
737 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
741 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
742 ar
->monitor_vdev_id
);
747 static int ath10k_stop_cac(struct ath10k
*ar
)
749 lockdep_assert_held(&ar
->conf_mutex
);
751 /* CAC is not running - do nothing */
752 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
755 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
756 ath10k_monitor_stop(ar
);
758 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac cac finished\n");
763 static void ath10k_recalc_radar_detection(struct ath10k
*ar
)
767 lockdep_assert_held(&ar
->conf_mutex
);
771 if (!ar
->radar_enabled
)
774 if (ar
->num_started_vdevs
> 0)
777 ret
= ath10k_start_cac(ar
);
780 * Not possible to start CAC on current channel so starting
781 * radiation is not allowed, make this channel DFS_UNAVAILABLE
782 * by indicating that radar was detected.
784 ath10k_warn(ar
, "failed to start CAC: %d\n", ret
);
785 ieee80211_radar_detected(ar
->hw
);
789 static int ath10k_vdev_start_restart(struct ath10k_vif
*arvif
, bool restart
)
791 struct ath10k
*ar
= arvif
->ar
;
792 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
793 struct wmi_vdev_start_request_arg arg
= {};
796 lockdep_assert_held(&ar
->conf_mutex
);
798 reinit_completion(&ar
->vdev_setup_done
);
800 arg
.vdev_id
= arvif
->vdev_id
;
801 arg
.dtim_period
= arvif
->dtim_period
;
802 arg
.bcn_intval
= arvif
->beacon_interval
;
804 arg
.channel
.freq
= chandef
->chan
->center_freq
;
805 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
806 arg
.channel
.mode
= chan_to_phymode(chandef
);
808 arg
.channel
.min_power
= 0;
809 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
810 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
811 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
813 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
814 arg
.ssid
= arvif
->u
.ap
.ssid
;
815 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
816 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
818 /* For now allow DFS for AP mode */
819 arg
.channel
.chan_radar
=
820 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
821 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
822 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
823 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
826 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
827 "mac vdev %d start center_freq %d phymode %s\n",
828 arg
.vdev_id
, arg
.channel
.freq
,
829 ath10k_wmi_phymode_str(arg
.channel
.mode
));
832 ret
= ath10k_wmi_vdev_restart(ar
, &arg
);
834 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
837 ath10k_warn(ar
, "failed to start WMI vdev %i: %d\n",
842 ret
= ath10k_vdev_setup_sync(ar
);
844 ath10k_warn(ar
, "failed to synchronise setup for vdev %i: %d\n",
849 ar
->num_started_vdevs
++;
850 ath10k_recalc_radar_detection(ar
);
855 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
857 return ath10k_vdev_start_restart(arvif
, false);
860 static int ath10k_vdev_restart(struct ath10k_vif
*arvif
)
862 return ath10k_vdev_start_restart(arvif
, true);
865 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
867 struct ath10k
*ar
= arvif
->ar
;
870 lockdep_assert_held(&ar
->conf_mutex
);
872 reinit_completion(&ar
->vdev_setup_done
);
874 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
876 ath10k_warn(ar
, "failed to stop WMI vdev %i: %d\n",
877 arvif
->vdev_id
, ret
);
881 ret
= ath10k_vdev_setup_sync(ar
);
883 ath10k_warn(ar
, "failed to syncronise setup for vdev %i: %d\n",
884 arvif
->vdev_id
, ret
);
888 WARN_ON(ar
->num_started_vdevs
== 0);
890 if (ar
->num_started_vdevs
!= 0) {
891 ar
->num_started_vdevs
--;
892 ath10k_recalc_radar_detection(ar
);
898 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
899 struct ieee80211_bss_conf
*info
)
901 struct ath10k
*ar
= arvif
->ar
;
904 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
906 if (!info
->enable_beacon
) {
907 ath10k_vdev_stop(arvif
);
909 arvif
->is_started
= false;
910 arvif
->is_up
= false;
912 spin_lock_bh(&arvif
->ar
->data_lock
);
914 dma_unmap_single(arvif
->ar
->dev
,
915 ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
916 arvif
->beacon
->len
, DMA_TO_DEVICE
);
917 dev_kfree_skb_any(arvif
->beacon
);
919 arvif
->beacon
= NULL
;
920 arvif
->beacon_sent
= false;
922 spin_unlock_bh(&arvif
->ar
->data_lock
);
927 arvif
->tx_seq_no
= 0x1000;
929 ret
= ath10k_vdev_start(arvif
);
934 memcpy(arvif
->bssid
, info
->bssid
, ETH_ALEN
);
936 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
939 ath10k_warn(ar
, "failed to bring up vdev %d: %i\n",
940 arvif
->vdev_id
, ret
);
941 ath10k_vdev_stop(arvif
);
945 arvif
->is_started
= true;
948 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
951 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
952 struct ieee80211_bss_conf
*info
,
953 const u8 self_peer
[ETH_ALEN
])
955 struct ath10k
*ar
= arvif
->ar
;
959 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
961 if (!info
->ibss_joined
) {
962 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
964 ath10k_warn(ar
, "failed to delete IBSS self peer %pM for vdev %d: %d\n",
965 self_peer
, arvif
->vdev_id
, ret
);
967 if (is_zero_ether_addr(arvif
->bssid
))
970 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
973 ath10k_warn(ar
, "failed to delete IBSS BSSID peer %pM for vdev %d: %d\n",
974 arvif
->bssid
, arvif
->vdev_id
, ret
);
978 memset(arvif
->bssid
, 0, ETH_ALEN
);
983 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
985 ath10k_warn(ar
, "failed to create IBSS self peer %pM for vdev %d: %d\n",
986 self_peer
, arvif
->vdev_id
, ret
);
990 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
991 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
992 ATH10K_DEFAULT_ATIM
);
994 ath10k_warn(ar
, "failed to set IBSS ATIM for vdev %d: %d\n",
995 arvif
->vdev_id
, ret
);
999 * Review this when mac80211 gains per-interface powersave support.
1001 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
1003 struct ath10k
*ar
= arvif
->ar
;
1004 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
1005 enum wmi_sta_powersave_param param
;
1006 enum wmi_sta_ps_mode psmode
;
1009 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
1011 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
1014 if (conf
->flags
& IEEE80211_CONF_PS
) {
1015 psmode
= WMI_STA_PS_MODE_ENABLED
;
1016 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
1018 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
1019 conf
->dynamic_ps_timeout
);
1021 ath10k_warn(ar
, "failed to set inactivity time for vdev %d: %i\n",
1022 arvif
->vdev_id
, ret
);
1026 psmode
= WMI_STA_PS_MODE_DISABLED
;
1029 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
1030 arvif
->vdev_id
, psmode
? "enable" : "disable");
1032 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
1034 ath10k_warn(ar
, "failed to set PS Mode %d for vdev %d: %d\n",
1035 psmode
, arvif
->vdev_id
, ret
);
1042 /**********************/
1043 /* Station management */
1044 /**********************/
1046 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
1047 struct ath10k_vif
*arvif
,
1048 struct ieee80211_sta
*sta
,
1049 struct ieee80211_bss_conf
*bss_conf
,
1050 struct wmi_peer_assoc_complete_arg
*arg
)
1052 lockdep_assert_held(&ar
->conf_mutex
);
1054 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
1055 arg
->vdev_id
= arvif
->vdev_id
;
1056 arg
->peer_aid
= sta
->aid
;
1057 arg
->peer_flags
|= WMI_PEER_AUTH
;
1059 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
1061 * Seems FW have problems with Power Save in STA
1062 * mode when we setup this parameter to high (eg. 5).
1063 * Often we see that FW don't send NULL (with clean P flags)
1064 * frame even there is info about buffered frames in beacons.
1065 * Sometimes we have to wait more than 10 seconds before FW
1066 * will wakeup. Often sending one ping from AP to our device
1067 * just fail (more than 50%).
1069 * Seems setting this FW parameter to 1 couse FW
1070 * will check every beacon and will wakup immediately
1071 * after detection buffered data.
1073 arg
->peer_listen_intval
= 1;
1075 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
1077 arg
->peer_num_spatial_streams
= 1;
1080 * The assoc capabilities are available only in managed mode.
1082 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
1083 arg
->peer_caps
= bss_conf
->assoc_capability
;
1086 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1087 struct ath10k_vif
*arvif
,
1088 struct wmi_peer_assoc_complete_arg
*arg
)
1090 struct ieee80211_vif
*vif
= arvif
->vif
;
1091 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1092 struct cfg80211_bss
*bss
;
1093 const u8
*rsnie
= NULL
;
1094 const u8
*wpaie
= NULL
;
1096 lockdep_assert_held(&ar
->conf_mutex
);
1098 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
1099 info
->bssid
, NULL
, 0, 0, 0);
1101 const struct cfg80211_bss_ies
*ies
;
1104 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1106 ies
= rcu_dereference(bss
->ies
);
1108 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1109 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1113 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1116 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1117 if (rsnie
|| wpaie
) {
1118 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1119 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1123 ath10k_dbg(ar
, ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1124 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1128 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1129 struct ieee80211_sta
*sta
,
1130 struct wmi_peer_assoc_complete_arg
*arg
)
1132 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1133 const struct ieee80211_supported_band
*sband
;
1134 const struct ieee80211_rate
*rates
;
1138 lockdep_assert_held(&ar
->conf_mutex
);
1140 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1141 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1142 rates
= sband
->bitrates
;
1144 rateset
->num_rates
= 0;
1146 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1147 if (!(ratemask
& 1))
1150 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
1151 rateset
->num_rates
++;
1155 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1156 struct ieee80211_sta
*sta
,
1157 struct wmi_peer_assoc_complete_arg
*arg
)
1159 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1162 lockdep_assert_held(&ar
->conf_mutex
);
1164 if (!ht_cap
->ht_supported
)
1167 arg
->peer_flags
|= WMI_PEER_HT
;
1168 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1169 ht_cap
->ampdu_factor
)) - 1;
1171 arg
->peer_mpdu_density
=
1172 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1174 arg
->peer_ht_caps
= ht_cap
->cap
;
1175 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1177 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1178 arg
->peer_flags
|= WMI_PEER_LDPC
;
1180 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1181 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1182 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1185 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1186 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1188 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1189 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1191 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1192 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1193 arg
->peer_flags
|= WMI_PEER_STBC
;
1196 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1198 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1199 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1200 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1201 arg
->peer_rate_caps
|= stbc
;
1202 arg
->peer_flags
|= WMI_PEER_STBC
;
1205 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1206 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1207 else if (ht_cap
->mcs
.rx_mask
[1])
1208 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1210 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1211 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1212 arg
->peer_ht_rates
.rates
[n
++] = i
;
1215 * This is a workaround for HT-enabled STAs which break the spec
1216 * and have no HT capabilities RX mask (no HT RX MCS map).
1218 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1219 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1221 * Firmware asserts if such situation occurs.
1224 arg
->peer_ht_rates
.num_rates
= 8;
1225 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
1226 arg
->peer_ht_rates
.rates
[i
] = i
;
1228 arg
->peer_ht_rates
.num_rates
= n
;
1229 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
1232 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1234 arg
->peer_ht_rates
.num_rates
,
1235 arg
->peer_num_spatial_streams
);
1238 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
1239 struct ath10k_vif
*arvif
,
1240 struct ieee80211_sta
*sta
)
1246 lockdep_assert_held(&ar
->conf_mutex
);
1248 if (sta
->wme
&& sta
->uapsd_queues
) {
1249 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1250 sta
->uapsd_queues
, sta
->max_sp
);
1252 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1253 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1254 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1255 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1256 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1257 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1258 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1259 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1260 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1261 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1262 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1263 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1266 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1267 max_sp
= sta
->max_sp
;
1269 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1271 WMI_AP_PS_PEER_PARAM_UAPSD
,
1274 ath10k_warn(ar
, "failed to set ap ps peer param uapsd for vdev %i: %d\n",
1275 arvif
->vdev_id
, ret
);
1279 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1281 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1284 ath10k_warn(ar
, "failed to set ap ps peer param max sp for vdev %i: %d\n",
1285 arvif
->vdev_id
, ret
);
1289 /* TODO setup this based on STA listen interval and
1290 beacon interval. Currently we don't know
1291 sta->listen_interval - mac80211 patch required.
1292 Currently use 10 seconds */
1293 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
1294 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
, 10);
1296 ath10k_warn(ar
, "failed to set ap ps peer param ageout time for vdev %i: %d\n",
1297 arvif
->vdev_id
, ret
);
1305 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1306 struct ieee80211_sta
*sta
,
1307 struct wmi_peer_assoc_complete_arg
*arg
)
1309 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1312 if (!vht_cap
->vht_supported
)
1315 arg
->peer_flags
|= WMI_PEER_VHT
;
1316 arg
->peer_vht_caps
= vht_cap
->cap
;
1319 ampdu_factor
= (vht_cap
->cap
&
1320 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1321 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1323 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1324 * zero in VHT IE. Using it would result in degraded throughput.
1325 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1326 * it if VHT max_mpdu is smaller. */
1327 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1328 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1329 ampdu_factor
)) - 1);
1331 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1332 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1334 arg
->peer_vht_rates
.rx_max_rate
=
1335 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1336 arg
->peer_vht_rates
.rx_mcs_set
=
1337 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1338 arg
->peer_vht_rates
.tx_max_rate
=
1339 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1340 arg
->peer_vht_rates
.tx_mcs_set
=
1341 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1343 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1344 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1347 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1348 struct ath10k_vif
*arvif
,
1349 struct ieee80211_sta
*sta
,
1350 struct ieee80211_bss_conf
*bss_conf
,
1351 struct wmi_peer_assoc_complete_arg
*arg
)
1353 switch (arvif
->vdev_type
) {
1354 case WMI_VDEV_TYPE_AP
:
1356 arg
->peer_flags
|= WMI_PEER_QOS
;
1358 if (sta
->wme
&& sta
->uapsd_queues
) {
1359 arg
->peer_flags
|= WMI_PEER_APSD
;
1360 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1363 case WMI_VDEV_TYPE_STA
:
1365 arg
->peer_flags
|= WMI_PEER_QOS
;
1372 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1373 struct ath10k_vif
*arvif
,
1374 struct ieee80211_sta
*sta
,
1375 struct wmi_peer_assoc_complete_arg
*arg
)
1377 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1379 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1380 case IEEE80211_BAND_2GHZ
:
1381 if (sta
->ht_cap
.ht_supported
) {
1382 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1383 phymode
= MODE_11NG_HT40
;
1385 phymode
= MODE_11NG_HT20
;
1391 case IEEE80211_BAND_5GHZ
:
1395 if (sta
->vht_cap
.vht_supported
) {
1396 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1397 phymode
= MODE_11AC_VHT80
;
1398 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1399 phymode
= MODE_11AC_VHT40
;
1400 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1401 phymode
= MODE_11AC_VHT20
;
1402 } else if (sta
->ht_cap
.ht_supported
) {
1403 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1404 phymode
= MODE_11NA_HT40
;
1406 phymode
= MODE_11NA_HT20
;
1416 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1417 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1419 arg
->peer_phymode
= phymode
;
1420 WARN_ON(phymode
== MODE_UNKNOWN
);
1423 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1424 struct ath10k_vif
*arvif
,
1425 struct ieee80211_sta
*sta
,
1426 struct ieee80211_bss_conf
*bss_conf
,
1427 struct wmi_peer_assoc_complete_arg
*arg
)
1429 lockdep_assert_held(&ar
->conf_mutex
);
1431 memset(arg
, 0, sizeof(*arg
));
1433 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, arg
);
1434 ath10k_peer_assoc_h_crypto(ar
, arvif
, arg
);
1435 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1436 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1437 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1438 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, arg
);
1439 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, arg
);
1444 static const u32 ath10k_smps_map
[] = {
1445 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
1446 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
1447 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
1448 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
1451 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1453 const struct ieee80211_sta_ht_cap
*ht_cap
)
1457 if (!ht_cap
->ht_supported
)
1460 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
1461 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
1463 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
1466 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
1467 WMI_PEER_SMPS_STATE
,
1468 ath10k_smps_map
[smps
]);
1471 /* can be called only in mac80211 callbacks due to `key_count` usage */
1472 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1473 struct ieee80211_vif
*vif
,
1474 struct ieee80211_bss_conf
*bss_conf
)
1476 struct ath10k
*ar
= hw
->priv
;
1477 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1478 struct ieee80211_sta_ht_cap ht_cap
;
1479 struct wmi_peer_assoc_complete_arg peer_arg
;
1480 struct ieee80211_sta
*ap_sta
;
1483 lockdep_assert_held(&ar
->conf_mutex
);
1487 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1489 ath10k_warn(ar
, "failed to find station entry for bss %pM vdev %i\n",
1490 bss_conf
->bssid
, arvif
->vdev_id
);
1495 /* ap_sta must be accessed only within rcu section which must be left
1496 * before calling ath10k_setup_peer_smps() which might sleep. */
1497 ht_cap
= ap_sta
->ht_cap
;
1499 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, ap_sta
,
1500 bss_conf
, &peer_arg
);
1502 ath10k_warn(ar
, "failed to prepare peer assoc for %pM vdev %i: %d\n",
1503 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1510 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1512 ath10k_warn(ar
, "failed to run peer assoc for %pM vdev %i: %d\n",
1513 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1517 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
1519 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %i: %d\n",
1520 arvif
->vdev_id
, ret
);
1524 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
1525 "mac vdev %d up (associated) bssid %pM aid %d\n",
1526 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1528 arvif
->aid
= bss_conf
->aid
;
1529 memcpy(arvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1531 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
1533 ath10k_warn(ar
, "failed to set vdev %d up: %d\n",
1534 arvif
->vdev_id
, ret
);
1538 arvif
->is_up
= true;
1544 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1545 struct ieee80211_vif
*vif
)
1547 struct ath10k
*ar
= hw
->priv
;
1548 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1551 lockdep_assert_held(&ar
->conf_mutex
);
1554 * For some reason, calling VDEV-DOWN before VDEV-STOP
1555 * makes the FW to send frames via HTT after disassociation.
1556 * No idea why this happens, even though VDEV-DOWN is supposed
1557 * to be analogous to link down, so just stop the VDEV.
1559 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d stop (disassociated\n",
1562 /* FIXME: check return value */
1563 ret
= ath10k_vdev_stop(arvif
);
1566 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1567 * report beacons from previously associated network through HTT.
1568 * This in turn would spam mac80211 WARN_ON if we bring down all
1569 * interfaces as it expects there is no rx when no interface is
1572 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d down\n", arvif
->vdev_id
);
1574 /* FIXME: why don't we print error if wmi call fails? */
1575 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1577 arvif
->def_wep_key_idx
= 0;
1579 arvif
->is_started
= false;
1580 arvif
->is_up
= false;
1583 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1584 struct ieee80211_sta
*sta
, bool reassoc
)
1586 struct wmi_peer_assoc_complete_arg peer_arg
;
1589 lockdep_assert_held(&ar
->conf_mutex
);
1591 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, sta
, NULL
, &peer_arg
);
1593 ath10k_warn(ar
, "failed to prepare WMI peer assoc for %pM vdev %i: %i\n",
1594 sta
->addr
, arvif
->vdev_id
, ret
);
1598 peer_arg
.peer_reassoc
= reassoc
;
1599 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1601 ath10k_warn(ar
, "failed to run peer assoc for STA %pM vdev %i: %d\n",
1602 sta
->addr
, arvif
->vdev_id
, ret
);
1606 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
, &sta
->ht_cap
);
1608 ath10k_warn(ar
, "failed to setup peer SMPS for vdev %d: %d\n",
1609 arvif
->vdev_id
, ret
);
1613 if (!sta
->wme
&& !reassoc
) {
1614 arvif
->num_legacy_stations
++;
1615 ret
= ath10k_recalc_rtscts_prot(arvif
);
1617 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1618 arvif
->vdev_id
, ret
);
1623 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1625 ath10k_warn(ar
, "failed to install peer wep keys for vdev %i: %d\n",
1626 arvif
->vdev_id
, ret
);
1630 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
1632 ath10k_warn(ar
, "failed to set qos params for STA %pM for vdev %i: %d\n",
1633 sta
->addr
, arvif
->vdev_id
, ret
);
1640 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1641 struct ieee80211_sta
*sta
)
1645 lockdep_assert_held(&ar
->conf_mutex
);
1648 arvif
->num_legacy_stations
--;
1649 ret
= ath10k_recalc_rtscts_prot(arvif
);
1651 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
1652 arvif
->vdev_id
, ret
);
1657 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1659 ath10k_warn(ar
, "failed to clear all peer wep keys for vdev %i: %d\n",
1660 arvif
->vdev_id
, ret
);
1671 static int ath10k_update_channel_list(struct ath10k
*ar
)
1673 struct ieee80211_hw
*hw
= ar
->hw
;
1674 struct ieee80211_supported_band
**bands
;
1675 enum ieee80211_band band
;
1676 struct ieee80211_channel
*channel
;
1677 struct wmi_scan_chan_list_arg arg
= {0};
1678 struct wmi_channel_arg
*ch
;
1684 lockdep_assert_held(&ar
->conf_mutex
);
1686 bands
= hw
->wiphy
->bands
;
1687 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1691 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1692 if (bands
[band
]->channels
[i
].flags
&
1693 IEEE80211_CHAN_DISABLED
)
1700 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1701 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1706 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1710 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1711 channel
= &bands
[band
]->channels
[i
];
1713 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1716 ch
->allow_ht
= true;
1718 /* FIXME: when should we really allow VHT? */
1719 ch
->allow_vht
= true;
1722 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
1725 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1728 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1730 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
1731 ch
->passive
= passive
;
1733 ch
->freq
= channel
->center_freq
;
1735 ch
->max_power
= channel
->max_power
* 2;
1736 ch
->max_reg_power
= channel
->max_reg_power
* 2;
1737 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
1738 ch
->reg_class_id
= 0; /* FIXME */
1740 /* FIXME: why use only legacy modes, why not any
1741 * HT/VHT modes? Would that even make any
1743 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1744 ch
->mode
= MODE_11G
;
1746 ch
->mode
= MODE_11A
;
1748 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1751 ath10k_dbg(ar
, ATH10K_DBG_WMI
,
1752 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1753 ch
- arg
.channels
, arg
.n_channels
,
1754 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1755 ch
->max_antenna_gain
, ch
->mode
);
1761 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1762 kfree(arg
.channels
);
1767 static enum wmi_dfs_region
1768 ath10k_mac_get_dfs_region(enum nl80211_dfs_regions dfs_region
)
1770 switch (dfs_region
) {
1771 case NL80211_DFS_UNSET
:
1772 return WMI_UNINIT_DFS_DOMAIN
;
1773 case NL80211_DFS_FCC
:
1774 return WMI_FCC_DFS_DOMAIN
;
1775 case NL80211_DFS_ETSI
:
1776 return WMI_ETSI_DFS_DOMAIN
;
1777 case NL80211_DFS_JP
:
1778 return WMI_MKK4_DFS_DOMAIN
;
1780 return WMI_UNINIT_DFS_DOMAIN
;
1783 static void ath10k_regd_update(struct ath10k
*ar
)
1785 struct reg_dmn_pair_mapping
*regpair
;
1787 enum wmi_dfs_region wmi_dfs_reg
;
1788 enum nl80211_dfs_regions nl_dfs_reg
;
1790 lockdep_assert_held(&ar
->conf_mutex
);
1792 ret
= ath10k_update_channel_list(ar
);
1794 ath10k_warn(ar
, "failed to update channel list: %d\n", ret
);
1796 regpair
= ar
->ath_common
.regulatory
.regpair
;
1798 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
1799 nl_dfs_reg
= ar
->dfs_detector
->region
;
1800 wmi_dfs_reg
= ath10k_mac_get_dfs_region(nl_dfs_reg
);
1802 wmi_dfs_reg
= WMI_UNINIT_DFS_DOMAIN
;
1805 /* Target allows setting up per-band regdomain but ath_common provides
1806 * a combined one only */
1807 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1808 regpair
->reg_domain
,
1809 regpair
->reg_domain
, /* 2ghz */
1810 regpair
->reg_domain
, /* 5ghz */
1811 regpair
->reg_2ghz_ctl
,
1812 regpair
->reg_5ghz_ctl
,
1815 ath10k_warn(ar
, "failed to set pdev regdomain: %d\n", ret
);
1818 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1819 struct regulatory_request
*request
)
1821 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1822 struct ath10k
*ar
= hw
->priv
;
1825 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1827 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
1828 ath10k_dbg(ar
, ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
1829 request
->dfs_region
);
1830 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
1831 request
->dfs_region
);
1833 ath10k_warn(ar
, "DFS region 0x%X not supported, will trigger radar for every pulse\n",
1834 request
->dfs_region
);
1837 mutex_lock(&ar
->conf_mutex
);
1838 if (ar
->state
== ATH10K_STATE_ON
)
1839 ath10k_regd_update(ar
);
1840 mutex_unlock(&ar
->conf_mutex
);
1847 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
1849 if (ieee80211_is_mgmt(hdr
->frame_control
))
1850 return HTT_DATA_TX_EXT_TID_MGMT
;
1852 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1853 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1855 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
1856 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1858 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
1861 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
, struct ieee80211_vif
*vif
)
1864 return ath10k_vif_to_arvif(vif
)->vdev_id
;
1866 if (ar
->monitor_started
)
1867 return ar
->monitor_vdev_id
;
1869 ath10k_warn(ar
, "failed to resolve vdev id\n");
1873 /* HTT Tx uses Native Wifi tx mode which expects 802.11 frames without QoS
1874 * Control in the header.
1876 static void ath10k_tx_h_nwifi(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1878 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1879 struct ath10k_skb_cb
*cb
= ATH10K_SKB_CB(skb
);
1882 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1885 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1886 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
1887 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
1888 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
1890 /* Fw/Hw generates a corrupted QoS Control Field for QoS NullFunc
1891 * frames. Powersave is handled by the fw/hw so QoS NyllFunc frames are
1892 * used only for CQM purposes (e.g. hostapd station keepalive ping) so
1893 * it is safe to downgrade to NullFunc.
1895 if (ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
1896 hdr
->frame_control
&= ~__cpu_to_le16(IEEE80211_STYPE_QOS_DATA
);
1897 cb
->htt
.tid
= HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1901 static void ath10k_tx_wep_key_work(struct work_struct
*work
)
1903 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1905 struct ath10k
*ar
= arvif
->ar
;
1906 int ret
, keyidx
= arvif
->def_wep_key_newidx
;
1908 mutex_lock(&arvif
->ar
->conf_mutex
);
1910 if (arvif
->ar
->state
!= ATH10K_STATE_ON
)
1913 if (arvif
->def_wep_key_idx
== keyidx
)
1916 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
1917 arvif
->vdev_id
, keyidx
);
1919 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
1921 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
1924 ath10k_warn(ar
, "failed to update wep key index for vdev %d: %d\n",
1930 arvif
->def_wep_key_idx
= keyidx
;
1933 mutex_unlock(&arvif
->ar
->conf_mutex
);
1936 static void ath10k_tx_h_update_wep_key(struct ieee80211_vif
*vif
,
1937 struct ieee80211_key_conf
*key
,
1938 struct sk_buff
*skb
)
1940 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1941 struct ath10k
*ar
= arvif
->ar
;
1942 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1944 if (!ieee80211_has_protected(hdr
->frame_control
))
1950 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1951 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1954 if (key
->keyidx
== arvif
->def_wep_key_idx
)
1957 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1958 * queueing frames until key index is updated is not an option because
1959 * sk_buff may need more processing to be done, e.g. offchannel */
1960 arvif
->def_wep_key_newidx
= key
->keyidx
;
1961 ieee80211_queue_work(ar
->hw
, &arvif
->wep_key_work
);
1964 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
,
1965 struct ieee80211_vif
*vif
,
1966 struct sk_buff
*skb
)
1968 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1969 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1971 /* This is case only for P2P_GO */
1972 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1973 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1976 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1977 spin_lock_bh(&ar
->data_lock
);
1978 if (arvif
->u
.ap
.noa_data
)
1979 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1981 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1982 arvif
->u
.ap
.noa_data
,
1983 arvif
->u
.ap
.noa_len
);
1984 spin_unlock_bh(&ar
->data_lock
);
1988 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1990 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1993 if (ar
->htt
.target_version_major
>= 3) {
1994 /* Since HTT 3.0 there is no separate mgmt tx command */
1995 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1999 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
2000 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2002 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
2003 ATH10K_MAX_NUM_MGMT_PENDING
) {
2004 ath10k_warn(ar
, "reached WMI management transmit queue limit\n");
2009 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
2010 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
2012 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2014 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
2016 ieee80211_is_nullfunc(hdr
->frame_control
)) {
2017 /* FW does not report tx status properly for NullFunc frames
2018 * unless they are sent through mgmt tx path. mac80211 sends
2019 * those frames when it detects link/beacon loss and depends
2020 * on the tx status to be correct. */
2021 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
2023 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
2028 ath10k_warn(ar
, "failed to transmit packet, dropping: %d\n",
2030 ieee80211_free_txskb(ar
->hw
, skb
);
2034 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
2036 struct sk_buff
*skb
;
2039 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2043 ieee80211_free_txskb(ar
->hw
, skb
);
2047 void ath10k_offchan_tx_work(struct work_struct
*work
)
2049 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
2050 struct ath10k_peer
*peer
;
2051 struct ieee80211_hdr
*hdr
;
2052 struct sk_buff
*skb
;
2053 const u8
*peer_addr
;
2057 /* FW requirement: We must create a peer before FW will send out
2058 * an offchannel frame. Otherwise the frame will be stuck and
2059 * never transmitted. We delete the peer upon tx completion.
2060 * It is unlikely that a peer for offchannel tx will already be
2061 * present. However it may be in some rare cases so account for that.
2062 * Otherwise we might remove a legitimate peer and break stuff. */
2065 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
2069 mutex_lock(&ar
->conf_mutex
);
2071 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
2074 hdr
= (struct ieee80211_hdr
*)skb
->data
;
2075 peer_addr
= ieee80211_get_DA(hdr
);
2076 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
2078 spin_lock_bh(&ar
->data_lock
);
2079 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
2080 spin_unlock_bh(&ar
->data_lock
);
2083 /* FIXME: should this use ath10k_warn()? */
2084 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
2085 peer_addr
, vdev_id
);
2088 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
2090 ath10k_warn(ar
, "failed to create peer %pM on vdev %d: %d\n",
2091 peer_addr
, vdev_id
, ret
);
2094 spin_lock_bh(&ar
->data_lock
);
2095 reinit_completion(&ar
->offchan_tx_completed
);
2096 ar
->offchan_tx_skb
= skb
;
2097 spin_unlock_bh(&ar
->data_lock
);
2099 ath10k_tx_htt(ar
, skb
);
2101 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
2104 ath10k_warn(ar
, "timed out waiting for offchannel skb %p\n",
2108 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
2110 ath10k_warn(ar
, "failed to delete peer %pM on vdev %d: %d\n",
2111 peer_addr
, vdev_id
, ret
);
2114 mutex_unlock(&ar
->conf_mutex
);
2118 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
2120 struct sk_buff
*skb
;
2123 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2127 ieee80211_free_txskb(ar
->hw
, skb
);
2131 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
2133 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
2134 struct sk_buff
*skb
;
2138 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2142 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
2144 ath10k_warn(ar
, "failed to transmit management frame via WMI: %d\n",
2146 ieee80211_free_txskb(ar
->hw
, skb
);
2155 void __ath10k_scan_finish(struct ath10k
*ar
)
2157 lockdep_assert_held(&ar
->data_lock
);
2159 switch (ar
->scan
.state
) {
2160 case ATH10K_SCAN_IDLE
:
2162 case ATH10K_SCAN_RUNNING
:
2163 case ATH10K_SCAN_ABORTING
:
2164 if (ar
->scan
.is_roc
)
2165 ieee80211_remain_on_channel_expired(ar
->hw
);
2167 ieee80211_scan_completed(ar
->hw
,
2169 ATH10K_SCAN_ABORTING
));
2171 case ATH10K_SCAN_STARTING
:
2172 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
2173 ar
->scan_channel
= NULL
;
2174 ath10k_offchan_tx_purge(ar
);
2175 cancel_delayed_work(&ar
->scan
.timeout
);
2176 complete_all(&ar
->scan
.completed
);
2181 void ath10k_scan_finish(struct ath10k
*ar
)
2183 spin_lock_bh(&ar
->data_lock
);
2184 __ath10k_scan_finish(ar
);
2185 spin_unlock_bh(&ar
->data_lock
);
2188 static int ath10k_scan_stop(struct ath10k
*ar
)
2190 struct wmi_stop_scan_arg arg
= {
2191 .req_id
= 1, /* FIXME */
2192 .req_type
= WMI_SCAN_STOP_ONE
,
2193 .u
.scan_id
= ATH10K_SCAN_ID
,
2197 lockdep_assert_held(&ar
->conf_mutex
);
2199 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
2201 ath10k_warn(ar
, "failed to stop wmi scan: %d\n", ret
);
2205 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
2207 ath10k_warn(ar
, "failed to receive scan abortion completion: timed out\n");
2209 } else if (ret
> 0) {
2214 /* Scan state should be updated upon scan completion but in case
2215 * firmware fails to deliver the event (for whatever reason) it is
2216 * desired to clean up scan state anyway. Firmware may have just
2217 * dropped the scan completion event delivery due to transport pipe
2218 * being overflown with data and/or it can recover on its own before
2219 * next scan request is submitted.
2221 spin_lock_bh(&ar
->data_lock
);
2222 if (ar
->scan
.state
!= ATH10K_SCAN_IDLE
)
2223 __ath10k_scan_finish(ar
);
2224 spin_unlock_bh(&ar
->data_lock
);
2229 static void ath10k_scan_abort(struct ath10k
*ar
)
2233 lockdep_assert_held(&ar
->conf_mutex
);
2235 spin_lock_bh(&ar
->data_lock
);
2237 switch (ar
->scan
.state
) {
2238 case ATH10K_SCAN_IDLE
:
2239 /* This can happen if timeout worker kicked in and called
2240 * abortion while scan completion was being processed.
2243 case ATH10K_SCAN_STARTING
:
2244 case ATH10K_SCAN_ABORTING
:
2245 ath10k_warn(ar
, "refusing scan abortion due to invalid scan state: %s (%d)\n",
2246 ath10k_scan_state_str(ar
->scan
.state
),
2249 case ATH10K_SCAN_RUNNING
:
2250 ar
->scan
.state
= ATH10K_SCAN_ABORTING
;
2251 spin_unlock_bh(&ar
->data_lock
);
2253 ret
= ath10k_scan_stop(ar
);
2255 ath10k_warn(ar
, "failed to abort scan: %d\n", ret
);
2257 spin_lock_bh(&ar
->data_lock
);
2261 spin_unlock_bh(&ar
->data_lock
);
2264 void ath10k_scan_timeout_work(struct work_struct
*work
)
2266 struct ath10k
*ar
= container_of(work
, struct ath10k
,
2269 mutex_lock(&ar
->conf_mutex
);
2270 ath10k_scan_abort(ar
);
2271 mutex_unlock(&ar
->conf_mutex
);
2274 static int ath10k_start_scan(struct ath10k
*ar
,
2275 const struct wmi_start_scan_arg
*arg
)
2279 lockdep_assert_held(&ar
->conf_mutex
);
2281 ret
= ath10k_wmi_start_scan(ar
, arg
);
2285 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
2287 ret
= ath10k_scan_stop(ar
);
2289 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
2294 /* Add a 200ms margin to account for event/command processing */
2295 ieee80211_queue_delayed_work(ar
->hw
, &ar
->scan
.timeout
,
2296 msecs_to_jiffies(arg
->max_scan_time
+200));
2300 /**********************/
2301 /* mac80211 callbacks */
2302 /**********************/
2304 static void ath10k_tx(struct ieee80211_hw
*hw
,
2305 struct ieee80211_tx_control
*control
,
2306 struct sk_buff
*skb
)
2308 struct ath10k
*ar
= hw
->priv
;
2309 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2310 struct ieee80211_vif
*vif
= info
->control
.vif
;
2311 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
2312 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2314 /* We should disable CCK RATE due to P2P */
2315 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
2316 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2318 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
2319 ATH10K_SKB_CB(skb
)->htt
.tid
= ath10k_tx_h_get_tid(hdr
);
2320 ATH10K_SKB_CB(skb
)->vdev_id
= ath10k_tx_h_get_vdev_id(ar
, vif
);
2322 /* it makes no sense to process injected frames like that */
2323 if (vif
&& vif
->type
!= NL80211_IFTYPE_MONITOR
) {
2324 ath10k_tx_h_nwifi(hw
, skb
);
2325 ath10k_tx_h_update_wep_key(vif
, key
, skb
);
2326 ath10k_tx_h_add_p2p_noa_ie(ar
, vif
, skb
);
2327 ath10k_tx_h_seq_no(vif
, skb
);
2330 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
2331 spin_lock_bh(&ar
->data_lock
);
2332 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
2333 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
2334 spin_unlock_bh(&ar
->data_lock
);
2336 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "queued offchannel skb %p\n",
2339 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
2340 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
2344 ath10k_tx_htt(ar
, skb
);
2347 /* Must not be called with conf_mutex held as workers can use that also. */
2348 static void ath10k_drain_tx(struct ath10k
*ar
)
2350 /* make sure rcu-protected mac80211 tx path itself is drained */
2353 ath10k_offchan_tx_purge(ar
);
2354 ath10k_mgmt_over_wmi_tx_purge(ar
);
2356 cancel_work_sync(&ar
->offchan_tx_work
);
2357 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
2360 void ath10k_halt(struct ath10k
*ar
)
2362 struct ath10k_vif
*arvif
;
2364 lockdep_assert_held(&ar
->conf_mutex
);
2366 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
2367 ar
->filter_flags
= 0;
2368 ar
->monitor
= false;
2370 if (ar
->monitor_started
)
2371 ath10k_monitor_stop(ar
);
2373 ar
->monitor_started
= false;
2375 ath10k_scan_finish(ar
);
2376 ath10k_peer_cleanup_all(ar
);
2377 ath10k_core_stop(ar
);
2378 ath10k_hif_power_down(ar
);
2380 spin_lock_bh(&ar
->data_lock
);
2381 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2385 dma_unmap_single(arvif
->ar
->dev
,
2386 ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
2387 arvif
->beacon
->len
, DMA_TO_DEVICE
);
2388 dev_kfree_skb_any(arvif
->beacon
);
2389 arvif
->beacon
= NULL
;
2391 spin_unlock_bh(&ar
->data_lock
);
2394 static int ath10k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
2396 struct ath10k
*ar
= hw
->priv
;
2398 mutex_lock(&ar
->conf_mutex
);
2400 if (ar
->cfg_tx_chainmask
) {
2401 *tx_ant
= ar
->cfg_tx_chainmask
;
2402 *rx_ant
= ar
->cfg_rx_chainmask
;
2404 *tx_ant
= ar
->supp_tx_chainmask
;
2405 *rx_ant
= ar
->supp_rx_chainmask
;
2408 mutex_unlock(&ar
->conf_mutex
);
2413 static int __ath10k_set_antenna(struct ath10k
*ar
, u32 tx_ant
, u32 rx_ant
)
2417 lockdep_assert_held(&ar
->conf_mutex
);
2419 ar
->cfg_tx_chainmask
= tx_ant
;
2420 ar
->cfg_rx_chainmask
= rx_ant
;
2422 if ((ar
->state
!= ATH10K_STATE_ON
) &&
2423 (ar
->state
!= ATH10K_STATE_RESTARTED
))
2426 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->tx_chain_mask
,
2429 ath10k_warn(ar
, "failed to set tx-chainmask: %d, req 0x%x\n",
2434 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->rx_chain_mask
,
2437 ath10k_warn(ar
, "failed to set rx-chainmask: %d, req 0x%x\n",
2445 static int ath10k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
2447 struct ath10k
*ar
= hw
->priv
;
2450 mutex_lock(&ar
->conf_mutex
);
2451 ret
= __ath10k_set_antenna(ar
, tx_ant
, rx_ant
);
2452 mutex_unlock(&ar
->conf_mutex
);
2456 static int ath10k_start(struct ieee80211_hw
*hw
)
2458 struct ath10k
*ar
= hw
->priv
;
2462 * This makes sense only when restarting hw. It is harmless to call
2463 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2464 * commands will be submitted while restarting.
2466 ath10k_drain_tx(ar
);
2468 mutex_lock(&ar
->conf_mutex
);
2470 switch (ar
->state
) {
2471 case ATH10K_STATE_OFF
:
2472 ar
->state
= ATH10K_STATE_ON
;
2474 case ATH10K_STATE_RESTARTING
:
2476 ar
->state
= ATH10K_STATE_RESTARTED
;
2478 case ATH10K_STATE_ON
:
2479 case ATH10K_STATE_RESTARTED
:
2480 case ATH10K_STATE_WEDGED
:
2484 case ATH10K_STATE_UTF
:
2489 ret
= ath10k_hif_power_up(ar
);
2491 ath10k_err(ar
, "Could not init hif: %d\n", ret
);
2495 ret
= ath10k_core_start(ar
, ATH10K_FIRMWARE_MODE_NORMAL
);
2497 ath10k_err(ar
, "Could not init core: %d\n", ret
);
2498 goto err_power_down
;
2501 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
2503 ath10k_warn(ar
, "failed to enable PMF QOS: %d\n", ret
);
2507 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
2509 ath10k_warn(ar
, "failed to enable dynamic BW: %d\n", ret
);
2513 if (ar
->cfg_tx_chainmask
)
2514 __ath10k_set_antenna(ar
, ar
->cfg_tx_chainmask
,
2515 ar
->cfg_rx_chainmask
);
2518 * By default FW set ARP frames ac to voice (6). In that case ARP
2519 * exchange is not working properly for UAPSD enabled AP. ARP requests
2520 * which arrives with access category 0 are processed by network stack
2521 * and send back with access category 0, but FW changes access category
2522 * to 6. Set ARP frames access category to best effort (0) solves
2526 ret
= ath10k_wmi_pdev_set_param(ar
,
2527 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
2529 ath10k_warn(ar
, "failed to set arp ac override parameter: %d\n",
2534 ar
->num_started_vdevs
= 0;
2535 ath10k_regd_update(ar
);
2537 ath10k_spectral_start(ar
);
2539 mutex_unlock(&ar
->conf_mutex
);
2543 ath10k_core_stop(ar
);
2546 ath10k_hif_power_down(ar
);
2549 ar
->state
= ATH10K_STATE_OFF
;
2552 mutex_unlock(&ar
->conf_mutex
);
2556 static void ath10k_stop(struct ieee80211_hw
*hw
)
2558 struct ath10k
*ar
= hw
->priv
;
2560 ath10k_drain_tx(ar
);
2562 mutex_lock(&ar
->conf_mutex
);
2563 if (ar
->state
!= ATH10K_STATE_OFF
) {
2565 ar
->state
= ATH10K_STATE_OFF
;
2567 mutex_unlock(&ar
->conf_mutex
);
2569 cancel_delayed_work_sync(&ar
->scan
.timeout
);
2570 cancel_work_sync(&ar
->restart_work
);
2573 static int ath10k_config_ps(struct ath10k
*ar
)
2575 struct ath10k_vif
*arvif
;
2578 lockdep_assert_held(&ar
->conf_mutex
);
2580 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2581 ret
= ath10k_mac_vif_setup_ps(arvif
);
2583 ath10k_warn(ar
, "failed to setup powersave: %d\n", ret
);
2591 static const char *chandef_get_width(enum nl80211_chan_width width
)
2594 case NL80211_CHAN_WIDTH_20_NOHT
:
2596 case NL80211_CHAN_WIDTH_20
:
2598 case NL80211_CHAN_WIDTH_40
:
2600 case NL80211_CHAN_WIDTH_80
:
2602 case NL80211_CHAN_WIDTH_80P80
:
2604 case NL80211_CHAN_WIDTH_160
:
2606 case NL80211_CHAN_WIDTH_5
:
2608 case NL80211_CHAN_WIDTH_10
:
2614 static void ath10k_config_chan(struct ath10k
*ar
)
2616 struct ath10k_vif
*arvif
;
2619 lockdep_assert_held(&ar
->conf_mutex
);
2621 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2622 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2623 ar
->chandef
.chan
->center_freq
,
2624 ar
->chandef
.center_freq1
,
2625 ar
->chandef
.center_freq2
,
2626 chandef_get_width(ar
->chandef
.width
));
2628 /* First stop monitor interface. Some FW versions crash if there's a
2629 * lone monitor interface. */
2630 if (ar
->monitor_started
)
2631 ath10k_monitor_stop(ar
);
2633 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2634 if (!arvif
->is_started
)
2640 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2643 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
2645 ath10k_warn(ar
, "failed to down vdev %d: %d\n",
2646 arvif
->vdev_id
, ret
);
2651 /* all vdevs are downed now - attempt to restart and re-up them */
2653 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2654 if (!arvif
->is_started
)
2657 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2660 ret
= ath10k_vdev_restart(arvif
);
2662 ath10k_warn(ar
, "failed to restart vdev %d: %d\n",
2663 arvif
->vdev_id
, ret
);
2670 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
2673 ath10k_warn(ar
, "failed to bring vdev up %d: %d\n",
2674 arvif
->vdev_id
, ret
);
2679 ath10k_monitor_recalc(ar
);
2682 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
2684 struct ath10k
*ar
= hw
->priv
;
2685 struct ieee80211_conf
*conf
= &hw
->conf
;
2689 mutex_lock(&ar
->conf_mutex
);
2691 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2692 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
2693 "mac config channel %dMHz flags 0x%x radar %d\n",
2694 conf
->chandef
.chan
->center_freq
,
2695 conf
->chandef
.chan
->flags
,
2696 conf
->radar_enabled
);
2698 spin_lock_bh(&ar
->data_lock
);
2699 ar
->rx_channel
= conf
->chandef
.chan
;
2700 spin_unlock_bh(&ar
->data_lock
);
2702 ar
->radar_enabled
= conf
->radar_enabled
;
2703 ath10k_recalc_radar_detection(ar
);
2705 if (!cfg80211_chandef_identical(&ar
->chandef
, &conf
->chandef
)) {
2706 ar
->chandef
= conf
->chandef
;
2707 ath10k_config_chan(ar
);
2711 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
2712 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac config power %d\n",
2713 hw
->conf
.power_level
);
2715 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
2716 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2717 hw
->conf
.power_level
* 2);
2719 ath10k_warn(ar
, "failed to set 2g txpower %d: %d\n",
2720 hw
->conf
.power_level
, ret
);
2722 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
2723 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2724 hw
->conf
.power_level
* 2);
2726 ath10k_warn(ar
, "failed to set 5g txpower %d: %d\n",
2727 hw
->conf
.power_level
, ret
);
2730 if (changed
& IEEE80211_CONF_CHANGE_PS
)
2731 ath10k_config_ps(ar
);
2733 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
2734 ar
->monitor
= conf
->flags
& IEEE80211_CONF_MONITOR
;
2735 ret
= ath10k_monitor_recalc(ar
);
2737 ath10k_warn(ar
, "failed to recalc monitor: %d\n", ret
);
2740 mutex_unlock(&ar
->conf_mutex
);
2746 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2747 * because we will send mgmt frames without CCK. This requirement
2748 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2751 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
2752 struct ieee80211_vif
*vif
)
2754 struct ath10k
*ar
= hw
->priv
;
2755 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2756 enum wmi_sta_powersave_param param
;
2762 mutex_lock(&ar
->conf_mutex
);
2764 memset(arvif
, 0, sizeof(*arvif
));
2769 INIT_WORK(&arvif
->wep_key_work
, ath10k_tx_wep_key_work
);
2770 INIT_LIST_HEAD(&arvif
->list
);
2772 if (ar
->free_vdev_map
== 0) {
2773 ath10k_warn(ar
, "Free vdev map is empty, no more interfaces allowed.\n");
2777 bit
= ffs(ar
->free_vdev_map
);
2779 arvif
->vdev_id
= bit
- 1;
2780 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
2783 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
2785 switch (vif
->type
) {
2786 case NL80211_IFTYPE_UNSPECIFIED
:
2787 case NL80211_IFTYPE_STATION
:
2788 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
2790 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
2792 case NL80211_IFTYPE_ADHOC
:
2793 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
2795 case NL80211_IFTYPE_AP
:
2796 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
2799 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
2801 case NL80211_IFTYPE_MONITOR
:
2802 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
2809 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d\n",
2810 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
2812 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
2813 arvif
->vdev_subtype
, vif
->addr
);
2815 ath10k_warn(ar
, "failed to create WMI vdev %i: %d\n",
2816 arvif
->vdev_id
, ret
);
2820 ar
->free_vdev_map
&= ~(1 << arvif
->vdev_id
);
2821 list_add(&arvif
->list
, &ar
->arvifs
);
2823 vdev_param
= ar
->wmi
.vdev_param
->def_keyid
;
2824 ret
= ath10k_wmi_vdev_set_param(ar
, 0, vdev_param
,
2825 arvif
->def_wep_key_idx
);
2827 ath10k_warn(ar
, "failed to set vdev %i default key id: %d\n",
2828 arvif
->vdev_id
, ret
);
2829 goto err_vdev_delete
;
2832 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
2833 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2834 ATH10K_HW_TXRX_NATIVE_WIFI
);
2835 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2836 if (ret
&& ret
!= -EOPNOTSUPP
) {
2837 ath10k_warn(ar
, "failed to set vdev %i TX encapsulation: %d\n",
2838 arvif
->vdev_id
, ret
);
2839 goto err_vdev_delete
;
2842 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2843 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
2845 ath10k_warn(ar
, "failed to create vdev %i peer for AP: %d\n",
2846 arvif
->vdev_id
, ret
);
2847 goto err_vdev_delete
;
2850 ret
= ath10k_mac_set_kickout(arvif
);
2852 ath10k_warn(ar
, "failed to set vdev %i kickout parameters: %d\n",
2853 arvif
->vdev_id
, ret
);
2854 goto err_peer_delete
;
2858 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
2859 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
2860 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2861 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2864 ath10k_warn(ar
, "failed to set vdev %i RX wake policy: %d\n",
2865 arvif
->vdev_id
, ret
);
2866 goto err_peer_delete
;
2869 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
2870 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
2871 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2874 ath10k_warn(ar
, "failed to set vdev %i TX wake thresh: %d\n",
2875 arvif
->vdev_id
, ret
);
2876 goto err_peer_delete
;
2879 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
2880 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
2881 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2884 ath10k_warn(ar
, "failed to set vdev %i PSPOLL count: %d\n",
2885 arvif
->vdev_id
, ret
);
2886 goto err_peer_delete
;
2890 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
2892 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
2893 arvif
->vdev_id
, ret
);
2894 goto err_peer_delete
;
2897 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
2899 ath10k_warn(ar
, "failed to set frag threshold for vdev %d: %d\n",
2900 arvif
->vdev_id
, ret
);
2901 goto err_peer_delete
;
2904 mutex_unlock(&ar
->conf_mutex
);
2908 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
2909 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
2912 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2913 ar
->free_vdev_map
|= 1 << arvif
->vdev_id
;
2914 list_del(&arvif
->list
);
2917 mutex_unlock(&ar
->conf_mutex
);
2922 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
2923 struct ieee80211_vif
*vif
)
2925 struct ath10k
*ar
= hw
->priv
;
2926 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2929 mutex_lock(&ar
->conf_mutex
);
2931 cancel_work_sync(&arvif
->wep_key_work
);
2933 spin_lock_bh(&ar
->data_lock
);
2934 if (arvif
->beacon
) {
2935 dma_unmap_single(arvif
->ar
->dev
,
2936 ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
2937 arvif
->beacon
->len
, DMA_TO_DEVICE
);
2938 dev_kfree_skb_any(arvif
->beacon
);
2939 arvif
->beacon
= NULL
;
2942 spin_unlock_bh(&ar
->data_lock
);
2944 ret
= ath10k_spectral_vif_stop(arvif
);
2946 ath10k_warn(ar
, "failed to stop spectral for vdev %i: %d\n",
2947 arvif
->vdev_id
, ret
);
2949 ar
->free_vdev_map
|= 1 << arvif
->vdev_id
;
2950 list_del(&arvif
->list
);
2952 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2953 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
2955 ath10k_warn(ar
, "failed to remove peer for AP vdev %i: %d\n",
2956 arvif
->vdev_id
, ret
);
2958 kfree(arvif
->u
.ap
.noa_data
);
2961 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
2964 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2966 ath10k_warn(ar
, "failed to delete WMI vdev %i: %d\n",
2967 arvif
->vdev_id
, ret
);
2969 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
2971 mutex_unlock(&ar
->conf_mutex
);
2975 * FIXME: Has to be verified.
2977 #define SUPPORTED_FILTERS \
2978 (FIF_PROMISC_IN_BSS | \
2983 FIF_BCN_PRBRESP_PROMISC | \
2987 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
2988 unsigned int changed_flags
,
2989 unsigned int *total_flags
,
2992 struct ath10k
*ar
= hw
->priv
;
2995 mutex_lock(&ar
->conf_mutex
);
2997 changed_flags
&= SUPPORTED_FILTERS
;
2998 *total_flags
&= SUPPORTED_FILTERS
;
2999 ar
->filter_flags
= *total_flags
;
3001 ret
= ath10k_monitor_recalc(ar
);
3003 ath10k_warn(ar
, "failed to recalc montior: %d\n", ret
);
3005 mutex_unlock(&ar
->conf_mutex
);
3008 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
3009 struct ieee80211_vif
*vif
,
3010 struct ieee80211_bss_conf
*info
,
3013 struct ath10k
*ar
= hw
->priv
;
3014 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3016 u32 vdev_param
, pdev_param
;
3018 mutex_lock(&ar
->conf_mutex
);
3020 if (changed
& BSS_CHANGED_IBSS
)
3021 ath10k_control_ibss(arvif
, info
, vif
->addr
);
3023 if (changed
& BSS_CHANGED_BEACON_INT
) {
3024 arvif
->beacon_interval
= info
->beacon_int
;
3025 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
3026 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3027 arvif
->beacon_interval
);
3028 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3029 "mac vdev %d beacon_interval %d\n",
3030 arvif
->vdev_id
, arvif
->beacon_interval
);
3033 ath10k_warn(ar
, "failed to set beacon interval for vdev %d: %i\n",
3034 arvif
->vdev_id
, ret
);
3037 if (changed
& BSS_CHANGED_BEACON
) {
3038 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3039 "vdev %d set beacon tx mode to staggered\n",
3042 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
3043 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
3044 WMI_BEACON_STAGGERED_MODE
);
3046 ath10k_warn(ar
, "failed to set beacon mode for vdev %d: %i\n",
3047 arvif
->vdev_id
, ret
);
3050 if (changed
& BSS_CHANGED_BEACON_INFO
) {
3051 arvif
->dtim_period
= info
->dtim_period
;
3053 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3054 "mac vdev %d dtim_period %d\n",
3055 arvif
->vdev_id
, arvif
->dtim_period
);
3057 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
3058 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3059 arvif
->dtim_period
);
3061 ath10k_warn(ar
, "failed to set dtim period for vdev %d: %i\n",
3062 arvif
->vdev_id
, ret
);
3065 if (changed
& BSS_CHANGED_SSID
&&
3066 vif
->type
== NL80211_IFTYPE_AP
) {
3067 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
3069 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
3070 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
3074 * Firmware manages AP self-peer internally so make sure to not create
3075 * it in driver. Otherwise AP self-peer deletion may timeout later.
3077 if (changed
& BSS_CHANGED_BSSID
&&
3078 vif
->type
!= NL80211_IFTYPE_AP
) {
3079 if (!is_zero_ether_addr(info
->bssid
)) {
3080 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3081 "mac vdev %d create peer %pM\n",
3082 arvif
->vdev_id
, info
->bssid
);
3084 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
3087 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when changing bssid: %i\n",
3088 info
->bssid
, arvif
->vdev_id
, ret
);
3090 if (vif
->type
== NL80211_IFTYPE_STATION
) {
3092 * this is never erased as we it for crypto key
3093 * clearing; this is FW requirement
3095 memcpy(arvif
->bssid
, info
->bssid
, ETH_ALEN
);
3097 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3098 "mac vdev %d start %pM\n",
3099 arvif
->vdev_id
, info
->bssid
);
3101 ret
= ath10k_vdev_start(arvif
);
3103 ath10k_warn(ar
, "failed to start vdev %i: %d\n",
3104 arvif
->vdev_id
, ret
);
3108 arvif
->is_started
= true;
3112 * Mac80211 does not keep IBSS bssid when leaving IBSS,
3113 * so driver need to store it. It is needed when leaving
3114 * IBSS in order to remove BSSID peer.
3116 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
3117 memcpy(arvif
->bssid
, info
->bssid
,
3122 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
3123 ath10k_control_beaconing(arvif
, info
);
3125 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3126 arvif
->use_cts_prot
= info
->use_cts_prot
;
3127 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
3128 arvif
->vdev_id
, info
->use_cts_prot
);
3130 ret
= ath10k_recalc_rtscts_prot(arvif
);
3132 ath10k_warn(ar
, "failed to recalculate rts/cts prot for vdev %d: %d\n",
3133 arvif
->vdev_id
, ret
);
3136 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3138 if (info
->use_short_slot
)
3139 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
3142 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
3144 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
3145 arvif
->vdev_id
, slottime
);
3147 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
3148 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3151 ath10k_warn(ar
, "failed to set erp slot for vdev %d: %i\n",
3152 arvif
->vdev_id
, ret
);
3155 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3157 if (info
->use_short_preamble
)
3158 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
3160 preamble
= WMI_VDEV_PREAMBLE_LONG
;
3162 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3163 "mac vdev %d preamble %dn",
3164 arvif
->vdev_id
, preamble
);
3166 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
3167 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3170 ath10k_warn(ar
, "failed to set preamble for vdev %d: %i\n",
3171 arvif
->vdev_id
, ret
);
3174 if (changed
& BSS_CHANGED_ASSOC
) {
3176 /* Workaround: Make sure monitor vdev is not running
3177 * when associating to prevent some firmware revisions
3178 * (e.g. 10.1 and 10.2) from crashing.
3180 if (ar
->monitor_started
)
3181 ath10k_monitor_stop(ar
);
3182 ath10k_bss_assoc(hw
, vif
, info
);
3183 ath10k_monitor_recalc(ar
);
3188 mutex_unlock(&ar
->conf_mutex
);
3191 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
3192 struct ieee80211_vif
*vif
,
3193 struct ieee80211_scan_request
*hw_req
)
3195 struct ath10k
*ar
= hw
->priv
;
3196 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3197 struct cfg80211_scan_request
*req
= &hw_req
->req
;
3198 struct wmi_start_scan_arg arg
;
3202 mutex_lock(&ar
->conf_mutex
);
3204 spin_lock_bh(&ar
->data_lock
);
3205 switch (ar
->scan
.state
) {
3206 case ATH10K_SCAN_IDLE
:
3207 reinit_completion(&ar
->scan
.started
);
3208 reinit_completion(&ar
->scan
.completed
);
3209 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
3210 ar
->scan
.is_roc
= false;
3211 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3214 case ATH10K_SCAN_STARTING
:
3215 case ATH10K_SCAN_RUNNING
:
3216 case ATH10K_SCAN_ABORTING
:
3220 spin_unlock_bh(&ar
->data_lock
);
3225 memset(&arg
, 0, sizeof(arg
));
3226 ath10k_wmi_start_scan_init(ar
, &arg
);
3227 arg
.vdev_id
= arvif
->vdev_id
;
3228 arg
.scan_id
= ATH10K_SCAN_ID
;
3231 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
3234 arg
.ie_len
= req
->ie_len
;
3235 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
3239 arg
.n_ssids
= req
->n_ssids
;
3240 for (i
= 0; i
< arg
.n_ssids
; i
++) {
3241 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
3242 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
3245 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3248 if (req
->n_channels
) {
3249 arg
.n_channels
= req
->n_channels
;
3250 for (i
= 0; i
< arg
.n_channels
; i
++)
3251 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
3254 ret
= ath10k_start_scan(ar
, &arg
);
3256 ath10k_warn(ar
, "failed to start hw scan: %d\n", ret
);
3257 spin_lock_bh(&ar
->data_lock
);
3258 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3259 spin_unlock_bh(&ar
->data_lock
);
3263 mutex_unlock(&ar
->conf_mutex
);
3267 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
3268 struct ieee80211_vif
*vif
)
3270 struct ath10k
*ar
= hw
->priv
;
3272 mutex_lock(&ar
->conf_mutex
);
3273 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3274 ath10k_scan_abort(ar
);
3275 mutex_unlock(&ar
->conf_mutex
);
3278 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
3279 struct ath10k_vif
*arvif
,
3280 enum set_key_cmd cmd
,
3281 struct ieee80211_key_conf
*key
)
3283 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
3286 /* 10.1 firmware branch requires default key index to be set to group
3287 * key index after installing it. Otherwise FW/HW Txes corrupted
3288 * frames with multi-vif APs. This is not required for main firmware
3289 * branch (e.g. 636).
3291 * FIXME: This has been tested only in AP. It remains unknown if this
3292 * is required for multi-vif STA interfaces on 10.1 */
3294 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
3297 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
3300 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
3303 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3309 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3312 ath10k_warn(ar
, "failed to set vdev %i group key as default key: %d\n",
3313 arvif
->vdev_id
, ret
);
3316 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3317 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
3318 struct ieee80211_key_conf
*key
)
3320 struct ath10k
*ar
= hw
->priv
;
3321 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3322 struct ath10k_peer
*peer
;
3323 const u8
*peer_addr
;
3324 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3325 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
3328 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
3331 mutex_lock(&ar
->conf_mutex
);
3334 peer_addr
= sta
->addr
;
3335 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
3336 peer_addr
= vif
->bss_conf
.bssid
;
3338 peer_addr
= vif
->addr
;
3340 key
->hw_key_idx
= key
->keyidx
;
3342 /* the peer should not disappear in mid-way (unless FW goes awry) since
3343 * we already hold conf_mutex. we just make sure its there now. */
3344 spin_lock_bh(&ar
->data_lock
);
3345 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3346 spin_unlock_bh(&ar
->data_lock
);
3349 if (cmd
== SET_KEY
) {
3350 ath10k_warn(ar
, "failed to install key for non-existent peer %pM\n",
3355 /* if the peer doesn't exist there is no key to disable
3363 arvif
->wep_keys
[key
->keyidx
] = key
;
3365 arvif
->wep_keys
[key
->keyidx
] = NULL
;
3367 if (cmd
== DISABLE_KEY
)
3368 ath10k_clear_vdev_key(arvif
, key
);
3371 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
3373 ath10k_warn(ar
, "failed to install key for vdev %i peer %pM: %d\n",
3374 arvif
->vdev_id
, peer_addr
, ret
);
3378 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
3380 spin_lock_bh(&ar
->data_lock
);
3381 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3382 if (peer
&& cmd
== SET_KEY
)
3383 peer
->keys
[key
->keyidx
] = key
;
3384 else if (peer
&& cmd
== DISABLE_KEY
)
3385 peer
->keys
[key
->keyidx
] = NULL
;
3386 else if (peer
== NULL
)
3387 /* impossible unless FW goes crazy */
3388 ath10k_warn(ar
, "Peer %pM disappeared!\n", peer_addr
);
3389 spin_unlock_bh(&ar
->data_lock
);
3392 mutex_unlock(&ar
->conf_mutex
);
3396 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
3399 struct ath10k_vif
*arvif
;
3400 struct ath10k_sta
*arsta
;
3401 struct ieee80211_sta
*sta
;
3402 u32 changed
, bw
, nss
, smps
;
3405 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
3406 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
3407 arvif
= arsta
->arvif
;
3410 spin_lock_bh(&ar
->data_lock
);
3412 changed
= arsta
->changed
;
3419 spin_unlock_bh(&ar
->data_lock
);
3421 mutex_lock(&ar
->conf_mutex
);
3423 if (changed
& IEEE80211_RC_BW_CHANGED
) {
3424 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
3427 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3428 WMI_PEER_CHAN_WIDTH
, bw
);
3430 ath10k_warn(ar
, "failed to update STA %pM peer bw %d: %d\n",
3431 sta
->addr
, bw
, err
);
3434 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
3435 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
3438 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3441 ath10k_warn(ar
, "failed to update STA %pM nss %d: %d\n",
3442 sta
->addr
, nss
, err
);
3445 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
3446 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
3449 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3450 WMI_PEER_SMPS_STATE
, smps
);
3452 ath10k_warn(ar
, "failed to update STA %pM smps %d: %d\n",
3453 sta
->addr
, smps
, err
);
3456 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
3457 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac update sta %pM supp rates\n",
3460 err
= ath10k_station_assoc(ar
, arvif
, sta
, true);
3462 ath10k_warn(ar
, "failed to reassociate station: %pM\n",
3466 mutex_unlock(&ar
->conf_mutex
);
3469 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
3470 struct ieee80211_vif
*vif
,
3471 struct ieee80211_sta
*sta
,
3472 enum ieee80211_sta_state old_state
,
3473 enum ieee80211_sta_state new_state
)
3475 struct ath10k
*ar
= hw
->priv
;
3476 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3477 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3481 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3482 new_state
== IEEE80211_STA_NONE
) {
3483 memset(arsta
, 0, sizeof(*arsta
));
3484 arsta
->arvif
= arvif
;
3485 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
3488 /* cancel must be done outside the mutex to avoid deadlock */
3489 if ((old_state
== IEEE80211_STA_NONE
&&
3490 new_state
== IEEE80211_STA_NOTEXIST
))
3491 cancel_work_sync(&arsta
->update_wk
);
3493 mutex_lock(&ar
->conf_mutex
);
3495 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3496 new_state
== IEEE80211_STA_NONE
&&
3497 vif
->type
!= NL80211_IFTYPE_STATION
) {
3499 * New station addition.
3501 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
))
3502 max_num_peers
= TARGET_10X_NUM_PEERS_MAX
- 1;
3504 max_num_peers
= TARGET_NUM_PEERS
;
3506 if (ar
->num_peers
>= max_num_peers
) {
3507 ath10k_warn(ar
, "number of peers exceeded: peers number %d (max peers %d)\n",
3508 ar
->num_peers
, max_num_peers
);
3513 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3514 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3515 arvif
->vdev_id
, sta
->addr
, ar
->num_peers
);
3517 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
3519 ath10k_warn(ar
, "failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3520 sta
->addr
, arvif
->vdev_id
, ret
);
3521 } else if ((old_state
== IEEE80211_STA_NONE
&&
3522 new_state
== IEEE80211_STA_NOTEXIST
)) {
3524 * Existing station deletion.
3526 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
3527 "mac vdev %d peer delete %pM (sta gone)\n",
3528 arvif
->vdev_id
, sta
->addr
);
3529 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
3531 ath10k_warn(ar
, "failed to delete peer %pM for vdev %d: %i\n",
3532 sta
->addr
, arvif
->vdev_id
, ret
);
3534 if (vif
->type
== NL80211_IFTYPE_STATION
)
3535 ath10k_bss_disassoc(hw
, vif
);
3536 } else if (old_state
== IEEE80211_STA_AUTH
&&
3537 new_state
== IEEE80211_STA_ASSOC
&&
3538 (vif
->type
== NL80211_IFTYPE_AP
||
3539 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
3543 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM associated\n",
3546 ret
= ath10k_station_assoc(ar
, arvif
, sta
, false);
3548 ath10k_warn(ar
, "failed to associate station %pM for vdev %i: %i\n",
3549 sta
->addr
, arvif
->vdev_id
, ret
);
3550 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3551 new_state
== IEEE80211_STA_AUTH
&&
3552 (vif
->type
== NL80211_IFTYPE_AP
||
3553 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
3557 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
3560 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
3562 ath10k_warn(ar
, "failed to disassociate station: %pM vdev %i: %i\n",
3563 sta
->addr
, arvif
->vdev_id
, ret
);
3566 mutex_unlock(&ar
->conf_mutex
);
3570 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3571 u16 ac
, bool enable
)
3573 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3577 lockdep_assert_held(&ar
->conf_mutex
);
3579 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
3583 case IEEE80211_AC_VO
:
3584 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
3585 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
3587 case IEEE80211_AC_VI
:
3588 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
3589 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
3591 case IEEE80211_AC_BE
:
3592 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
3593 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
3595 case IEEE80211_AC_BK
:
3596 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
3597 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
3602 arvif
->u
.sta
.uapsd
|= value
;
3604 arvif
->u
.sta
.uapsd
&= ~value
;
3606 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3607 WMI_STA_PS_PARAM_UAPSD
,
3608 arvif
->u
.sta
.uapsd
);
3610 ath10k_warn(ar
, "failed to set uapsd params: %d\n", ret
);
3614 if (arvif
->u
.sta
.uapsd
)
3615 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
3617 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
3619 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3620 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
3623 ath10k_warn(ar
, "failed to set rx wake param: %d\n", ret
);
3629 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
3630 struct ieee80211_vif
*vif
, u16 ac
,
3631 const struct ieee80211_tx_queue_params
*params
)
3633 struct ath10k
*ar
= hw
->priv
;
3634 struct wmi_wmm_params_arg
*p
= NULL
;
3637 mutex_lock(&ar
->conf_mutex
);
3640 case IEEE80211_AC_VO
:
3641 p
= &ar
->wmm_params
.ac_vo
;
3643 case IEEE80211_AC_VI
:
3644 p
= &ar
->wmm_params
.ac_vi
;
3646 case IEEE80211_AC_BE
:
3647 p
= &ar
->wmm_params
.ac_be
;
3649 case IEEE80211_AC_BK
:
3650 p
= &ar
->wmm_params
.ac_bk
;
3659 p
->cwmin
= params
->cw_min
;
3660 p
->cwmax
= params
->cw_max
;
3661 p
->aifs
= params
->aifs
;
3664 * The channel time duration programmed in the HW is in absolute
3665 * microseconds, while mac80211 gives the txop in units of
3668 p
->txop
= params
->txop
* 32;
3670 /* FIXME: FW accepts wmm params per hw, not per vif */
3671 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
3673 ath10k_warn(ar
, "failed to set wmm params: %d\n", ret
);
3677 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
3679 ath10k_warn(ar
, "failed to set sta uapsd: %d\n", ret
);
3682 mutex_unlock(&ar
->conf_mutex
);
3686 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3688 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
3689 struct ieee80211_vif
*vif
,
3690 struct ieee80211_channel
*chan
,
3692 enum ieee80211_roc_type type
)
3694 struct ath10k
*ar
= hw
->priv
;
3695 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3696 struct wmi_start_scan_arg arg
;
3699 mutex_lock(&ar
->conf_mutex
);
3701 spin_lock_bh(&ar
->data_lock
);
3702 switch (ar
->scan
.state
) {
3703 case ATH10K_SCAN_IDLE
:
3704 reinit_completion(&ar
->scan
.started
);
3705 reinit_completion(&ar
->scan
.completed
);
3706 reinit_completion(&ar
->scan
.on_channel
);
3707 ar
->scan
.state
= ATH10K_SCAN_STARTING
;
3708 ar
->scan
.is_roc
= true;
3709 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3710 ar
->scan
.roc_freq
= chan
->center_freq
;
3713 case ATH10K_SCAN_STARTING
:
3714 case ATH10K_SCAN_RUNNING
:
3715 case ATH10K_SCAN_ABORTING
:
3719 spin_unlock_bh(&ar
->data_lock
);
3724 memset(&arg
, 0, sizeof(arg
));
3725 ath10k_wmi_start_scan_init(ar
, &arg
);
3726 arg
.vdev_id
= arvif
->vdev_id
;
3727 arg
.scan_id
= ATH10K_SCAN_ID
;
3729 arg
.channels
[0] = chan
->center_freq
;
3730 arg
.dwell_time_active
= duration
;
3731 arg
.dwell_time_passive
= duration
;
3732 arg
.max_scan_time
= 2 * duration
;
3733 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3734 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
3736 ret
= ath10k_start_scan(ar
, &arg
);
3738 ath10k_warn(ar
, "failed to start roc scan: %d\n", ret
);
3739 spin_lock_bh(&ar
->data_lock
);
3740 ar
->scan
.state
= ATH10K_SCAN_IDLE
;
3741 spin_unlock_bh(&ar
->data_lock
);
3745 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
3747 ath10k_warn(ar
, "failed to switch to channel for roc scan\n");
3749 ret
= ath10k_scan_stop(ar
);
3751 ath10k_warn(ar
, "failed to stop scan: %d\n", ret
);
3759 mutex_unlock(&ar
->conf_mutex
);
3763 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
3765 struct ath10k
*ar
= hw
->priv
;
3767 mutex_lock(&ar
->conf_mutex
);
3768 cancel_delayed_work_sync(&ar
->scan
.timeout
);
3769 ath10k_scan_abort(ar
);
3770 mutex_unlock(&ar
->conf_mutex
);
3776 * Both RTS and Fragmentation threshold are interface-specific
3777 * in ath10k, but device-specific in mac80211.
3780 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3782 struct ath10k
*ar
= hw
->priv
;
3783 struct ath10k_vif
*arvif
;
3786 mutex_lock(&ar
->conf_mutex
);
3787 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3788 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
3789 arvif
->vdev_id
, value
);
3791 ret
= ath10k_mac_set_rts(arvif
, value
);
3793 ath10k_warn(ar
, "failed to set rts threshold for vdev %d: %d\n",
3794 arvif
->vdev_id
, ret
);
3798 mutex_unlock(&ar
->conf_mutex
);
3803 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3805 struct ath10k
*ar
= hw
->priv
;
3806 struct ath10k_vif
*arvif
;
3809 mutex_lock(&ar
->conf_mutex
);
3810 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3811 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac vdev %d fragmentation threshold %d\n",
3812 arvif
->vdev_id
, value
);
3814 ret
= ath10k_mac_set_rts(arvif
, value
);
3816 ath10k_warn(ar
, "failed to set fragmentation threshold for vdev %d: %d\n",
3817 arvif
->vdev_id
, ret
);
3821 mutex_unlock(&ar
->conf_mutex
);
3826 static void ath10k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
3827 u32 queues
, bool drop
)
3829 struct ath10k
*ar
= hw
->priv
;
3833 /* mac80211 doesn't care if we really xmit queued frames or not
3834 * we'll collect those frames either way if we stop/delete vdevs */
3838 mutex_lock(&ar
->conf_mutex
);
3840 if (ar
->state
== ATH10K_STATE_WEDGED
)
3843 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
3846 spin_lock_bh(&ar
->htt
.tx_lock
);
3847 empty
= (ar
->htt
.num_pending_tx
== 0);
3848 spin_unlock_bh(&ar
->htt
.tx_lock
);
3850 skip
= (ar
->state
== ATH10K_STATE_WEDGED
);
3853 }), ATH10K_FLUSH_TIMEOUT_HZ
);
3855 if (ret
<= 0 || skip
)
3856 ath10k_warn(ar
, "failed to flush transmit queue (skip %i ar-state %i): %i\n",
3857 skip
, ar
->state
, ret
);
3860 mutex_unlock(&ar
->conf_mutex
);
3863 /* TODO: Implement this function properly
3864 * For now it is needed to reply to Probe Requests in IBSS mode.
3865 * Propably we need this information from FW.
3867 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
3873 static int ath10k_suspend(struct ieee80211_hw
*hw
,
3874 struct cfg80211_wowlan
*wowlan
)
3876 struct ath10k
*ar
= hw
->priv
;
3879 mutex_lock(&ar
->conf_mutex
);
3881 ret
= ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND
);
3883 if (ret
== -ETIMEDOUT
)
3889 ret
= ath10k_hif_suspend(ar
);
3891 ath10k_warn(ar
, "failed to suspend hif: %d\n", ret
);
3898 ret
= ath10k_wmi_pdev_resume_target(ar
);
3900 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
3904 mutex_unlock(&ar
->conf_mutex
);
3908 static int ath10k_resume(struct ieee80211_hw
*hw
)
3910 struct ath10k
*ar
= hw
->priv
;
3913 mutex_lock(&ar
->conf_mutex
);
3915 ret
= ath10k_hif_resume(ar
);
3917 ath10k_warn(ar
, "failed to resume hif: %d\n", ret
);
3922 ret
= ath10k_wmi_pdev_resume_target(ar
);
3924 ath10k_warn(ar
, "failed to resume target: %d\n", ret
);
3931 mutex_unlock(&ar
->conf_mutex
);
3936 static void ath10k_restart_complete(struct ieee80211_hw
*hw
)
3938 struct ath10k
*ar
= hw
->priv
;
3940 mutex_lock(&ar
->conf_mutex
);
3942 /* If device failed to restart it will be in a different state, e.g.
3943 * ATH10K_STATE_WEDGED */
3944 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
3945 ath10k_info(ar
, "device successfully recovered\n");
3946 ar
->state
= ATH10K_STATE_ON
;
3949 mutex_unlock(&ar
->conf_mutex
);
3952 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
3953 struct survey_info
*survey
)
3955 struct ath10k
*ar
= hw
->priv
;
3956 struct ieee80211_supported_band
*sband
;
3957 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
3960 mutex_lock(&ar
->conf_mutex
);
3962 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
3963 if (sband
&& idx
>= sband
->n_channels
) {
3964 idx
-= sband
->n_channels
;
3969 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
3971 if (!sband
|| idx
>= sband
->n_channels
) {
3976 spin_lock_bh(&ar
->data_lock
);
3977 memcpy(survey
, ar_survey
, sizeof(*survey
));
3978 spin_unlock_bh(&ar
->data_lock
);
3980 survey
->channel
= &sband
->channels
[idx
];
3983 mutex_unlock(&ar
->conf_mutex
);
3987 /* Helper table for legacy fixed_rate/bitrate_mask */
3988 static const u8 cck_ofdm_rate
[] = {
4005 /* Check if only one bit set */
4006 static int ath10k_check_single_mask(u32 mask
)
4014 mask
&= ~BIT(bit
- 1);
4022 ath10k_default_bitrate_mask(struct ath10k
*ar
,
4023 enum ieee80211_band band
,
4024 const struct cfg80211_bitrate_mask
*mask
)
4026 u32 legacy
= 0x00ff;
4031 case IEEE80211_BAND_2GHZ
:
4035 case IEEE80211_BAND_5GHZ
:
4041 if (mask
->control
[band
].legacy
!= legacy
)
4044 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
4045 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
4048 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
4049 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
4056 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
4057 enum ieee80211_band band
,
4060 int ht_nss
= 0, vht_nss
= 0, i
;
4063 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
4067 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
4068 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
4070 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
4079 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
4080 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
4082 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
4090 if (ht_nss
> 0 && vht_nss
> 0)
4094 *fixed_nss
= ht_nss
;
4096 *fixed_nss
= vht_nss
;
4104 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
4105 enum ieee80211_band band
,
4106 enum wmi_rate_preamble
*preamble
)
4108 int legacy
= 0, ht
= 0, vht
= 0, i
;
4110 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
4113 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
4118 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4119 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
4124 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4125 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
4129 /* Currently we support only one fixed_rate */
4130 if ((legacy
+ ht
+ vht
) != 1)
4134 *preamble
= WMI_RATE_PREAMBLE_HT
;
4136 *preamble
= WMI_RATE_PREAMBLE_VHT
;
4142 ath10k_bitrate_mask_rate(struct ath10k
*ar
,
4143 const struct cfg80211_bitrate_mask
*mask
,
4144 enum ieee80211_band band
,
4148 u8 rate
= 0, pream
= 0, nss
= 0, i
;
4149 enum wmi_rate_preamble preamble
;
4151 /* Check if single rate correct */
4152 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
4158 case WMI_RATE_PREAMBLE_CCK
:
4159 case WMI_RATE_PREAMBLE_OFDM
:
4160 i
= ffs(mask
->control
[band
].legacy
) - 1;
4162 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
4163 pream
= WMI_RATE_PREAMBLE_CCK
;
4165 if (band
== IEEE80211_BAND_5GHZ
)
4168 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
4171 rate
= cck_ofdm_rate
[i
];
4173 case WMI_RATE_PREAMBLE_HT
:
4174 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
4175 if (mask
->control
[band
].ht_mcs
[i
])
4178 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
4181 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
4184 case WMI_RATE_PREAMBLE_VHT
:
4185 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
4186 if (mask
->control
[band
].vht_mcs
[i
])
4189 if (i
== NL80211_VHT_NSS_MAX
)
4192 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
4197 *fixed_nss
= nss
+ 1;
4201 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
4204 *fixed_rate
= pream
| nss
| rate
;
4209 static bool ath10k_get_fixed_rate_nss(struct ath10k
*ar
,
4210 const struct cfg80211_bitrate_mask
*mask
,
4211 enum ieee80211_band band
,
4215 /* First check full NSS mask, if we can simply limit NSS */
4216 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
4219 /* Next Check single rate is set */
4220 return ath10k_bitrate_mask_rate(ar
, mask
, band
, fixed_rate
, fixed_nss
);
4223 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
4228 struct ath10k
*ar
= arvif
->ar
;
4232 mutex_lock(&ar
->conf_mutex
);
4234 if (arvif
->fixed_rate
== fixed_rate
&&
4235 arvif
->fixed_nss
== fixed_nss
&&
4236 arvif
->force_sgi
== force_sgi
)
4239 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
4240 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
4243 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac force sgi\n");
4245 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
4246 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4247 vdev_param
, fixed_rate
);
4249 ath10k_warn(ar
, "failed to set fixed rate param 0x%02x: %d\n",
4255 arvif
->fixed_rate
= fixed_rate
;
4257 vdev_param
= ar
->wmi
.vdev_param
->nss
;
4258 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
4259 vdev_param
, fixed_nss
);
4262 ath10k_warn(ar
, "failed to set fixed nss param %d: %d\n",
4268 arvif
->fixed_nss
= fixed_nss
;
4270 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
4271 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
4275 ath10k_warn(ar
, "failed to set sgi param %d: %d\n",
4281 arvif
->force_sgi
= force_sgi
;
4284 mutex_unlock(&ar
->conf_mutex
);
4288 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
4289 struct ieee80211_vif
*vif
,
4290 const struct cfg80211_bitrate_mask
*mask
)
4292 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4293 struct ath10k
*ar
= arvif
->ar
;
4294 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
4295 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
4296 u8 fixed_nss
= ar
->num_rf_chains
;
4299 force_sgi
= mask
->control
[band
].gi
;
4300 if (force_sgi
== NL80211_TXRATE_FORCE_LGI
)
4303 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
4304 if (!ath10k_get_fixed_rate_nss(ar
, mask
, band
,
4310 if (fixed_rate
== WMI_FIXED_RATE_NONE
&& force_sgi
) {
4311 ath10k_warn(ar
, "failed to force SGI usage for default rate settings\n");
4315 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
,
4316 fixed_nss
, force_sgi
);
4319 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
4320 struct ieee80211_vif
*vif
,
4321 struct ieee80211_sta
*sta
,
4324 struct ath10k
*ar
= hw
->priv
;
4325 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4328 spin_lock_bh(&ar
->data_lock
);
4330 ath10k_dbg(ar
, ATH10K_DBG_MAC
,
4331 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4332 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
4335 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4336 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4338 switch (sta
->bandwidth
) {
4339 case IEEE80211_STA_RX_BW_20
:
4340 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4342 case IEEE80211_STA_RX_BW_40
:
4343 bw
= WMI_PEER_CHWIDTH_40MHZ
;
4345 case IEEE80211_STA_RX_BW_80
:
4346 bw
= WMI_PEER_CHWIDTH_80MHZ
;
4348 case IEEE80211_STA_RX_BW_160
:
4349 ath10k_warn(ar
, "Invalid bandwith %d in rc update for %pM\n",
4350 sta
->bandwidth
, sta
->addr
);
4351 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4358 if (changed
& IEEE80211_RC_NSS_CHANGED
)
4359 arsta
->nss
= sta
->rx_nss
;
4361 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
4362 smps
= WMI_PEER_SMPS_PS_NONE
;
4364 switch (sta
->smps_mode
) {
4365 case IEEE80211_SMPS_AUTOMATIC
:
4366 case IEEE80211_SMPS_OFF
:
4367 smps
= WMI_PEER_SMPS_PS_NONE
;
4369 case IEEE80211_SMPS_STATIC
:
4370 smps
= WMI_PEER_SMPS_STATIC
;
4372 case IEEE80211_SMPS_DYNAMIC
:
4373 smps
= WMI_PEER_SMPS_DYNAMIC
;
4375 case IEEE80211_SMPS_NUM_MODES
:
4376 ath10k_warn(ar
, "Invalid smps %d in sta rc update for %pM\n",
4377 sta
->smps_mode
, sta
->addr
);
4378 smps
= WMI_PEER_SMPS_PS_NONE
;
4385 arsta
->changed
|= changed
;
4387 spin_unlock_bh(&ar
->data_lock
);
4389 ieee80211_queue_work(hw
, &arsta
->update_wk
);
4392 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
4395 * FIXME: Return 0 for time being. Need to figure out whether FW
4396 * has the API to fetch 64-bit local TSF
4402 static int ath10k_ampdu_action(struct ieee80211_hw
*hw
,
4403 struct ieee80211_vif
*vif
,
4404 enum ieee80211_ampdu_mlme_action action
,
4405 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4408 struct ath10k
*ar
= hw
->priv
;
4409 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4411 ath10k_dbg(ar
, ATH10K_DBG_MAC
, "mac ampdu vdev_id %i sta %pM tid %hu action %d\n",
4412 arvif
->vdev_id
, sta
->addr
, tid
, action
);
4415 case IEEE80211_AMPDU_RX_START
:
4416 case IEEE80211_AMPDU_RX_STOP
:
4417 /* HTT AddBa/DelBa events trigger mac80211 Rx BA session
4418 * creation/removal. Do we need to verify this?
4421 case IEEE80211_AMPDU_TX_START
:
4422 case IEEE80211_AMPDU_TX_STOP_CONT
:
4423 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
4424 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
4425 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4426 /* Firmware offloads Tx aggregation entirely so deny mac80211
4427 * Tx aggregation requests.
4435 static const struct ieee80211_ops ath10k_ops
= {
4437 .start
= ath10k_start
,
4438 .stop
= ath10k_stop
,
4439 .config
= ath10k_config
,
4440 .add_interface
= ath10k_add_interface
,
4441 .remove_interface
= ath10k_remove_interface
,
4442 .configure_filter
= ath10k_configure_filter
,
4443 .bss_info_changed
= ath10k_bss_info_changed
,
4444 .hw_scan
= ath10k_hw_scan
,
4445 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
4446 .set_key
= ath10k_set_key
,
4447 .sta_state
= ath10k_sta_state
,
4448 .conf_tx
= ath10k_conf_tx
,
4449 .remain_on_channel
= ath10k_remain_on_channel
,
4450 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
4451 .set_rts_threshold
= ath10k_set_rts_threshold
,
4452 .set_frag_threshold
= ath10k_set_frag_threshold
,
4453 .flush
= ath10k_flush
,
4454 .tx_last_beacon
= ath10k_tx_last_beacon
,
4455 .set_antenna
= ath10k_set_antenna
,
4456 .get_antenna
= ath10k_get_antenna
,
4457 .restart_complete
= ath10k_restart_complete
,
4458 .get_survey
= ath10k_get_survey
,
4459 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
4460 .sta_rc_update
= ath10k_sta_rc_update
,
4461 .get_tsf
= ath10k_get_tsf
,
4462 .ampdu_action
= ath10k_ampdu_action
,
4464 CFG80211_TESTMODE_CMD(ath10k_tm_cmd
)
4467 .suspend
= ath10k_suspend
,
4468 .resume
= ath10k_resume
,
4472 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4473 .bitrate = (_rate), \
4474 .flags = (_flags), \
4475 .hw_value = (_rateid), \
4478 #define CHAN2G(_channel, _freq, _flags) { \
4479 .band = IEEE80211_BAND_2GHZ, \
4480 .hw_value = (_channel), \
4481 .center_freq = (_freq), \
4482 .flags = (_flags), \
4483 .max_antenna_gain = 0, \
4487 #define CHAN5G(_channel, _freq, _flags) { \
4488 .band = IEEE80211_BAND_5GHZ, \
4489 .hw_value = (_channel), \
4490 .center_freq = (_freq), \
4491 .flags = (_flags), \
4492 .max_antenna_gain = 0, \
4496 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
4506 CHAN2G(10, 2457, 0),
4507 CHAN2G(11, 2462, 0),
4508 CHAN2G(12, 2467, 0),
4509 CHAN2G(13, 2472, 0),
4510 CHAN2G(14, 2484, 0),
4513 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
4514 CHAN5G(36, 5180, 0),
4515 CHAN5G(40, 5200, 0),
4516 CHAN5G(44, 5220, 0),
4517 CHAN5G(48, 5240, 0),
4518 CHAN5G(52, 5260, 0),
4519 CHAN5G(56, 5280, 0),
4520 CHAN5G(60, 5300, 0),
4521 CHAN5G(64, 5320, 0),
4522 CHAN5G(100, 5500, 0),
4523 CHAN5G(104, 5520, 0),
4524 CHAN5G(108, 5540, 0),
4525 CHAN5G(112, 5560, 0),
4526 CHAN5G(116, 5580, 0),
4527 CHAN5G(120, 5600, 0),
4528 CHAN5G(124, 5620, 0),
4529 CHAN5G(128, 5640, 0),
4530 CHAN5G(132, 5660, 0),
4531 CHAN5G(136, 5680, 0),
4532 CHAN5G(140, 5700, 0),
4533 CHAN5G(149, 5745, 0),
4534 CHAN5G(153, 5765, 0),
4535 CHAN5G(157, 5785, 0),
4536 CHAN5G(161, 5805, 0),
4537 CHAN5G(165, 5825, 0),
4540 static struct ieee80211_rate ath10k_rates
[] = {
4542 RATETAB_ENT(10, 0x82, 0),
4543 RATETAB_ENT(20, 0x84, 0),
4544 RATETAB_ENT(55, 0x8b, 0),
4545 RATETAB_ENT(110, 0x96, 0),
4547 RATETAB_ENT(60, 0x0c, 0),
4548 RATETAB_ENT(90, 0x12, 0),
4549 RATETAB_ENT(120, 0x18, 0),
4550 RATETAB_ENT(180, 0x24, 0),
4551 RATETAB_ENT(240, 0x30, 0),
4552 RATETAB_ENT(360, 0x48, 0),
4553 RATETAB_ENT(480, 0x60, 0),
4554 RATETAB_ENT(540, 0x6c, 0),
4557 #define ath10k_a_rates (ath10k_rates + 4)
4558 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4559 #define ath10k_g_rates (ath10k_rates + 0)
4560 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4562 struct ath10k
*ath10k_mac_create(size_t priv_size
)
4564 struct ieee80211_hw
*hw
;
4567 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
) + priv_size
, &ath10k_ops
);
4577 void ath10k_mac_destroy(struct ath10k
*ar
)
4579 ieee80211_free_hw(ar
->hw
);
4582 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
4585 .types
= BIT(NL80211_IFTYPE_STATION
)
4586 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
4590 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
4594 .types
= BIT(NL80211_IFTYPE_AP
)
4598 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
4601 .types
= BIT(NL80211_IFTYPE_AP
)
4605 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
4607 .limits
= ath10k_if_limits
,
4608 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
4609 .max_interfaces
= 8,
4610 .num_different_channels
= 1,
4611 .beacon_int_infra_match
= true,
4615 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
4617 .limits
= ath10k_10x_if_limits
,
4618 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
4619 .max_interfaces
= 8,
4620 .num_different_channels
= 1,
4621 .beacon_int_infra_match
= true,
4622 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4623 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
4624 BIT(NL80211_CHAN_WIDTH_20
) |
4625 BIT(NL80211_CHAN_WIDTH_40
) |
4626 BIT(NL80211_CHAN_WIDTH_80
),
4631 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
4633 struct ieee80211_sta_vht_cap vht_cap
= {0};
4637 vht_cap
.vht_supported
= 1;
4638 vht_cap
.cap
= ar
->vht_cap_info
;
4641 for (i
= 0; i
< 8; i
++) {
4642 if (i
< ar
->num_rf_chains
)
4643 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
4645 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
4648 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
4649 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
4654 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
4657 struct ieee80211_sta_ht_cap ht_cap
= {0};
4659 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
4662 ht_cap
.ht_supported
= 1;
4663 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
4664 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
4665 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
4666 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
4667 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
4669 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
4670 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
4672 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
4673 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
4675 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
4678 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
4679 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
4684 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
4685 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
4687 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
4690 stbc
= ar
->ht_cap_info
;
4691 stbc
&= WMI_HT_CAP_RX_STBC
;
4692 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
4693 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
4694 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
4699 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
4700 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
4702 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
4703 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
4705 /* max AMSDU is implicitly taken from vht_cap_info */
4706 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
4707 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
4709 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
4710 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
4712 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
4718 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
4719 struct ieee80211_vif
*vif
)
4721 struct ath10k_vif_iter
*arvif_iter
= data
;
4722 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4724 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
4725 arvif_iter
->arvif
= arvif
;
4728 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
4730 struct ath10k_vif_iter arvif_iter
;
4733 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
4734 arvif_iter
.vdev_id
= vdev_id
;
4736 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
4737 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
4739 ath10k_get_arvif_iter
,
4741 if (!arvif_iter
.arvif
) {
4742 ath10k_warn(ar
, "No VIF found for vdev %d\n", vdev_id
);
4746 return arvif_iter
.arvif
;
4749 int ath10k_mac_register(struct ath10k
*ar
)
4751 struct ieee80211_supported_band
*band
;
4752 struct ieee80211_sta_vht_cap vht_cap
;
4753 struct ieee80211_sta_ht_cap ht_cap
;
4757 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
4759 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
4761 ht_cap
= ath10k_get_ht_cap(ar
);
4762 vht_cap
= ath10k_create_vht_cap(ar
);
4764 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
4765 channels
= kmemdup(ath10k_2ghz_channels
,
4766 sizeof(ath10k_2ghz_channels
),
4773 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
4774 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
4775 band
->channels
= channels
;
4776 band
->n_bitrates
= ath10k_g_rates_size
;
4777 band
->bitrates
= ath10k_g_rates
;
4778 band
->ht_cap
= ht_cap
;
4780 /* vht is not supported in 2.4 GHz */
4782 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
4785 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
4786 channels
= kmemdup(ath10k_5ghz_channels
,
4787 sizeof(ath10k_5ghz_channels
),
4794 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
4795 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
4796 band
->channels
= channels
;
4797 band
->n_bitrates
= ath10k_a_rates_size
;
4798 band
->bitrates
= ath10k_a_rates
;
4799 band
->ht_cap
= ht_cap
;
4800 band
->vht_cap
= vht_cap
;
4801 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
4804 ar
->hw
->wiphy
->interface_modes
=
4805 BIT(NL80211_IFTYPE_STATION
) |
4806 BIT(NL80211_IFTYPE_AP
);
4808 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
4809 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4810 ar
->supp_tx_chainmask
= TARGET_10X_TX_CHAIN_MASK
;
4811 ar
->supp_rx_chainmask
= TARGET_10X_RX_CHAIN_MASK
;
4813 ar
->supp_tx_chainmask
= TARGET_TX_CHAIN_MASK
;
4814 ar
->supp_rx_chainmask
= TARGET_RX_CHAIN_MASK
;
4817 ar
->hw
->wiphy
->available_antennas_rx
= ar
->supp_rx_chainmask
;
4818 ar
->hw
->wiphy
->available_antennas_tx
= ar
->supp_tx_chainmask
;
4820 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
4821 ar
->hw
->wiphy
->interface_modes
|=
4822 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
4823 BIT(NL80211_IFTYPE_P2P_GO
);
4825 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
4826 IEEE80211_HW_SUPPORTS_PS
|
4827 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
4828 IEEE80211_HW_SUPPORTS_UAPSD
|
4829 IEEE80211_HW_MFP_CAPABLE
|
4830 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
4831 IEEE80211_HW_HAS_RATE_CONTROL
|
4832 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
4833 IEEE80211_HW_AP_LINK_PS
|
4834 IEEE80211_HW_SPECTRUM_MGMT
;
4836 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4837 * bytes is used for padding/alignment if necessary. */
4838 ar
->hw
->extra_tx_headroom
+= sizeof(struct htt_data_tx_desc_frag
)*2 + 4;
4840 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
4841 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
4843 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
4844 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
4845 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
4848 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
4849 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
4851 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
4852 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
4854 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
4856 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
4857 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
4858 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
4860 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
4862 * on LL hardware queues are managed entirely by the FW
4863 * so we only advertise to mac we can do the queues thing
4867 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
4868 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
4869 ar
->hw
->wiphy
->n_iface_combinations
=
4870 ARRAY_SIZE(ath10k_10x_if_comb
);
4872 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
4873 ar
->hw
->wiphy
->n_iface_combinations
=
4874 ARRAY_SIZE(ath10k_if_comb
);
4876 ar
->hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
4879 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
4881 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
4882 /* Init ath dfs pattern detector */
4883 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
4884 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
4887 if (!ar
->dfs_detector
)
4888 ath10k_warn(ar
, "failed to initialise DFS pattern detector\n");
4891 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
4892 ath10k_reg_notifier
);
4894 ath10k_err(ar
, "failed to initialise regulatory: %i\n", ret
);
4898 ret
= ieee80211_register_hw(ar
->hw
);
4900 ath10k_err(ar
, "failed to register ieee80211: %d\n", ret
);
4904 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
4905 ret
= regulatory_hint(ar
->hw
->wiphy
,
4906 ar
->ath_common
.regulatory
.alpha2
);
4908 goto err_unregister
;
4914 ieee80211_unregister_hw(ar
->hw
);
4916 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4917 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4922 void ath10k_mac_unregister(struct ath10k
*ar
)
4924 ieee80211_unregister_hw(ar
->hw
);
4926 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
4927 ar
->dfs_detector
->exit(ar
->dfs_detector
);
4929 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4930 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4932 SET_IEEE80211_DEV(ar
->hw
, NULL
);