2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <net/mac80211.h>
21 #include <linux/etherdevice.h>
34 static int ath10k_send_key(struct ath10k_vif
*arvif
,
35 struct ieee80211_key_conf
*key
,
39 struct wmi_vdev_install_key_arg arg
= {
40 .vdev_id
= arvif
->vdev_id
,
41 .key_idx
= key
->keyidx
,
42 .key_len
= key
->keylen
,
47 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
49 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
50 arg
.key_flags
= WMI_KEY_PAIRWISE
;
52 arg
.key_flags
= WMI_KEY_GROUP
;
54 switch (key
->cipher
) {
55 case WLAN_CIPHER_SUITE_CCMP
:
56 arg
.key_cipher
= WMI_CIPHER_AES_CCM
;
57 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
59 case WLAN_CIPHER_SUITE_TKIP
:
60 arg
.key_cipher
= WMI_CIPHER_TKIP
;
61 arg
.key_txmic_len
= 8;
62 arg
.key_rxmic_len
= 8;
64 case WLAN_CIPHER_SUITE_WEP40
:
65 case WLAN_CIPHER_SUITE_WEP104
:
66 arg
.key_cipher
= WMI_CIPHER_WEP
;
67 /* AP/IBSS mode requires self-key to be groupwise
68 * Otherwise pairwise key must be set */
69 if (memcmp(macaddr
, arvif
->vif
->addr
, ETH_ALEN
))
70 arg
.key_flags
= WMI_KEY_PAIRWISE
;
73 ath10k_warn("cipher %d is not supported\n", key
->cipher
);
77 if (cmd
== DISABLE_KEY
) {
78 arg
.key_cipher
= WMI_CIPHER_NONE
;
82 return ath10k_wmi_vdev_install_key(arvif
->ar
, &arg
);
85 static int ath10k_install_key(struct ath10k_vif
*arvif
,
86 struct ieee80211_key_conf
*key
,
90 struct ath10k
*ar
= arvif
->ar
;
93 lockdep_assert_held(&ar
->conf_mutex
);
95 reinit_completion(&ar
->install_key_done
);
97 ret
= ath10k_send_key(arvif
, key
, cmd
, macaddr
);
101 ret
= wait_for_completion_timeout(&ar
->install_key_done
, 3*HZ
);
108 static int ath10k_install_peer_wep_keys(struct ath10k_vif
*arvif
,
111 struct ath10k
*ar
= arvif
->ar
;
112 struct ath10k_peer
*peer
;
116 lockdep_assert_held(&ar
->conf_mutex
);
118 spin_lock_bh(&ar
->data_lock
);
119 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
120 spin_unlock_bh(&ar
->data_lock
);
125 for (i
= 0; i
< ARRAY_SIZE(arvif
->wep_keys
); i
++) {
126 if (arvif
->wep_keys
[i
] == NULL
)
129 ret
= ath10k_install_key(arvif
, arvif
->wep_keys
[i
], SET_KEY
,
134 peer
->keys
[i
] = arvif
->wep_keys
[i
];
140 static int ath10k_clear_peer_keys(struct ath10k_vif
*arvif
,
143 struct ath10k
*ar
= arvif
->ar
;
144 struct ath10k_peer
*peer
;
149 lockdep_assert_held(&ar
->conf_mutex
);
151 spin_lock_bh(&ar
->data_lock
);
152 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, addr
);
153 spin_unlock_bh(&ar
->data_lock
);
158 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
159 if (peer
->keys
[i
] == NULL
)
162 ret
= ath10k_install_key(arvif
, peer
->keys
[i
],
164 if (ret
&& first_errno
== 0)
168 ath10k_warn("could not remove peer wep key %d (%d)\n",
171 peer
->keys
[i
] = NULL
;
177 static int ath10k_clear_vdev_key(struct ath10k_vif
*arvif
,
178 struct ieee80211_key_conf
*key
)
180 struct ath10k
*ar
= arvif
->ar
;
181 struct ath10k_peer
*peer
;
187 lockdep_assert_held(&ar
->conf_mutex
);
190 /* since ath10k_install_key we can't hold data_lock all the
191 * time, so we try to remove the keys incrementally */
192 spin_lock_bh(&ar
->data_lock
);
194 list_for_each_entry(peer
, &ar
->peers
, list
) {
195 for (i
= 0; i
< ARRAY_SIZE(peer
->keys
); i
++) {
196 if (peer
->keys
[i
] == key
) {
197 memcpy(addr
, peer
->addr
, ETH_ALEN
);
198 peer
->keys
[i
] = NULL
;
203 if (i
< ARRAY_SIZE(peer
->keys
))
206 spin_unlock_bh(&ar
->data_lock
);
208 if (i
== ARRAY_SIZE(peer
->keys
))
211 ret
= ath10k_install_key(arvif
, key
, DISABLE_KEY
, addr
);
212 if (ret
&& first_errno
== 0)
216 ath10k_warn("could not remove key for %pM\n", addr
);
223 /*********************/
224 /* General utilities */
225 /*********************/
227 static inline enum wmi_phy_mode
228 chan_to_phymode(const struct cfg80211_chan_def
*chandef
)
230 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
232 switch (chandef
->chan
->band
) {
233 case IEEE80211_BAND_2GHZ
:
234 switch (chandef
->width
) {
235 case NL80211_CHAN_WIDTH_20_NOHT
:
238 case NL80211_CHAN_WIDTH_20
:
239 phymode
= MODE_11NG_HT20
;
241 case NL80211_CHAN_WIDTH_40
:
242 phymode
= MODE_11NG_HT40
;
244 case NL80211_CHAN_WIDTH_5
:
245 case NL80211_CHAN_WIDTH_10
:
246 case NL80211_CHAN_WIDTH_80
:
247 case NL80211_CHAN_WIDTH_80P80
:
248 case NL80211_CHAN_WIDTH_160
:
249 phymode
= MODE_UNKNOWN
;
253 case IEEE80211_BAND_5GHZ
:
254 switch (chandef
->width
) {
255 case NL80211_CHAN_WIDTH_20_NOHT
:
258 case NL80211_CHAN_WIDTH_20
:
259 phymode
= MODE_11NA_HT20
;
261 case NL80211_CHAN_WIDTH_40
:
262 phymode
= MODE_11NA_HT40
;
264 case NL80211_CHAN_WIDTH_80
:
265 phymode
= MODE_11AC_VHT80
;
267 case NL80211_CHAN_WIDTH_5
:
268 case NL80211_CHAN_WIDTH_10
:
269 case NL80211_CHAN_WIDTH_80P80
:
270 case NL80211_CHAN_WIDTH_160
:
271 phymode
= MODE_UNKNOWN
;
279 WARN_ON(phymode
== MODE_UNKNOWN
);
283 static u8
ath10k_parse_mpdudensity(u8 mpdudensity
)
286 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
287 * 0 for no restriction
296 switch (mpdudensity
) {
302 /* Our lower layer calculations limit our precision to
318 static int ath10k_peer_create(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
322 lockdep_assert_held(&ar
->conf_mutex
);
324 ret
= ath10k_wmi_peer_create(ar
, vdev_id
, addr
);
326 ath10k_warn("Failed to create wmi peer %pM on vdev %i: %i\n",
331 ret
= ath10k_wait_for_peer_created(ar
, vdev_id
, addr
);
333 ath10k_warn("Failed to wait for created wmi peer %pM on vdev %i: %i\n",
337 spin_lock_bh(&ar
->data_lock
);
339 spin_unlock_bh(&ar
->data_lock
);
344 static int ath10k_mac_set_kickout(struct ath10k_vif
*arvif
)
346 struct ath10k
*ar
= arvif
->ar
;
350 param
= ar
->wmi
.pdev_param
->sta_kickout_th
;
351 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
352 ATH10K_KICKOUT_THRESHOLD
);
354 ath10k_warn("Failed to set kickout threshold on vdev %i: %d\n",
355 arvif
->vdev_id
, ret
);
359 param
= ar
->wmi
.vdev_param
->ap_keepalive_min_idle_inactive_time_secs
;
360 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
361 ATH10K_KEEPALIVE_MIN_IDLE
);
363 ath10k_warn("Failed to set keepalive minimum idle time on vdev %i : %d\n",
364 arvif
->vdev_id
, ret
);
368 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_idle_inactive_time_secs
;
369 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
370 ATH10K_KEEPALIVE_MAX_IDLE
);
372 ath10k_warn("Failed to set keepalive maximum idle time on vdev %i: %d\n",
373 arvif
->vdev_id
, ret
);
377 param
= ar
->wmi
.vdev_param
->ap_keepalive_max_unresponsive_time_secs
;
378 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, param
,
379 ATH10K_KEEPALIVE_MAX_UNRESPONSIVE
);
381 ath10k_warn("Failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
382 arvif
->vdev_id
, ret
);
389 static int ath10k_mac_set_rts(struct ath10k_vif
*arvif
, u32 value
)
391 struct ath10k
*ar
= arvif
->ar
;
394 if (value
!= 0xFFFFFFFF)
395 value
= min_t(u32
, arvif
->ar
->hw
->wiphy
->rts_threshold
,
398 vdev_param
= ar
->wmi
.vdev_param
->rts_threshold
;
399 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
402 static int ath10k_mac_set_frag(struct ath10k_vif
*arvif
, u32 value
)
404 struct ath10k
*ar
= arvif
->ar
;
407 if (value
!= 0xFFFFFFFF)
408 value
= clamp_t(u32
, arvif
->ar
->hw
->wiphy
->frag_threshold
,
409 ATH10K_FRAGMT_THRESHOLD_MIN
,
410 ATH10K_FRAGMT_THRESHOLD_MAX
);
412 vdev_param
= ar
->wmi
.vdev_param
->fragmentation_threshold
;
413 return ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
, value
);
416 static int ath10k_peer_delete(struct ath10k
*ar
, u32 vdev_id
, const u8
*addr
)
420 lockdep_assert_held(&ar
->conf_mutex
);
422 ret
= ath10k_wmi_peer_delete(ar
, vdev_id
, addr
);
426 ret
= ath10k_wait_for_peer_deleted(ar
, vdev_id
, addr
);
430 spin_lock_bh(&ar
->data_lock
);
432 spin_unlock_bh(&ar
->data_lock
);
437 static void ath10k_peer_cleanup(struct ath10k
*ar
, u32 vdev_id
)
439 struct ath10k_peer
*peer
, *tmp
;
441 lockdep_assert_held(&ar
->conf_mutex
);
443 spin_lock_bh(&ar
->data_lock
);
444 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
445 if (peer
->vdev_id
!= vdev_id
)
448 ath10k_warn("removing stale peer %pM from vdev_id %d\n",
449 peer
->addr
, vdev_id
);
451 list_del(&peer
->list
);
455 spin_unlock_bh(&ar
->data_lock
);
458 static void ath10k_peer_cleanup_all(struct ath10k
*ar
)
460 struct ath10k_peer
*peer
, *tmp
;
462 lockdep_assert_held(&ar
->conf_mutex
);
464 spin_lock_bh(&ar
->data_lock
);
465 list_for_each_entry_safe(peer
, tmp
, &ar
->peers
, list
) {
466 list_del(&peer
->list
);
470 spin_unlock_bh(&ar
->data_lock
);
473 /************************/
474 /* Interface management */
475 /************************/
477 static inline int ath10k_vdev_setup_sync(struct ath10k
*ar
)
481 lockdep_assert_held(&ar
->conf_mutex
);
483 ret
= wait_for_completion_timeout(&ar
->vdev_setup_done
,
484 ATH10K_VDEV_SETUP_TIMEOUT_HZ
);
491 static int ath10k_vdev_start(struct ath10k_vif
*arvif
)
493 struct ath10k
*ar
= arvif
->ar
;
494 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
495 struct wmi_vdev_start_request_arg arg
= {};
498 lockdep_assert_held(&ar
->conf_mutex
);
500 reinit_completion(&ar
->vdev_setup_done
);
502 arg
.vdev_id
= arvif
->vdev_id
;
503 arg
.dtim_period
= arvif
->dtim_period
;
504 arg
.bcn_intval
= arvif
->beacon_interval
;
506 arg
.channel
.freq
= chandef
->chan
->center_freq
;
507 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
508 arg
.channel
.mode
= chan_to_phymode(chandef
);
510 arg
.channel
.min_power
= 0;
511 arg
.channel
.max_power
= chandef
->chan
->max_power
* 2;
512 arg
.channel
.max_reg_power
= chandef
->chan
->max_reg_power
* 2;
513 arg
.channel
.max_antenna_gain
= chandef
->chan
->max_antenna_gain
* 2;
515 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
516 arg
.ssid
= arvif
->u
.ap
.ssid
;
517 arg
.ssid_len
= arvif
->u
.ap
.ssid_len
;
518 arg
.hidden_ssid
= arvif
->u
.ap
.hidden_ssid
;
520 /* For now allow DFS for AP mode */
521 arg
.channel
.chan_radar
=
522 !!(chandef
->chan
->flags
& IEEE80211_CHAN_RADAR
);
523 } else if (arvif
->vdev_type
== WMI_VDEV_TYPE_IBSS
) {
524 arg
.ssid
= arvif
->vif
->bss_conf
.ssid
;
525 arg
.ssid_len
= arvif
->vif
->bss_conf
.ssid_len
;
528 ath10k_dbg(ATH10K_DBG_MAC
,
529 "mac vdev %d start center_freq %d phymode %s\n",
530 arg
.vdev_id
, arg
.channel
.freq
,
531 ath10k_wmi_phymode_str(arg
.channel
.mode
));
533 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
535 ath10k_warn("WMI vdev %i start failed: ret %d\n",
540 ret
= ath10k_vdev_setup_sync(ar
);
542 ath10k_warn("vdev %i setup failed %d\n",
550 static int ath10k_vdev_stop(struct ath10k_vif
*arvif
)
552 struct ath10k
*ar
= arvif
->ar
;
555 lockdep_assert_held(&ar
->conf_mutex
);
557 reinit_completion(&ar
->vdev_setup_done
);
559 ret
= ath10k_wmi_vdev_stop(ar
, arvif
->vdev_id
);
561 ath10k_warn("WMI vdev %i stop failed: ret %d\n",
562 arvif
->vdev_id
, ret
);
566 ret
= ath10k_vdev_setup_sync(ar
);
568 ath10k_warn("vdev %i setup sync failed %d\n",
569 arvif
->vdev_id
, ret
);
576 static int ath10k_monitor_start(struct ath10k
*ar
, int vdev_id
)
578 struct cfg80211_chan_def
*chandef
= &ar
->chandef
;
579 struct ieee80211_channel
*channel
= chandef
->chan
;
580 struct wmi_vdev_start_request_arg arg
= {};
583 lockdep_assert_held(&ar
->conf_mutex
);
585 if (!ar
->monitor_present
) {
586 ath10k_warn("mac montor stop -- monitor is not present\n");
590 arg
.vdev_id
= vdev_id
;
591 arg
.channel
.freq
= channel
->center_freq
;
592 arg
.channel
.band_center_freq1
= chandef
->center_freq1
;
594 /* TODO setup this dynamically, what in case we
595 don't have any vifs? */
596 arg
.channel
.mode
= chan_to_phymode(chandef
);
597 arg
.channel
.chan_radar
=
598 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
600 arg
.channel
.min_power
= 0;
601 arg
.channel
.max_power
= channel
->max_power
* 2;
602 arg
.channel
.max_reg_power
= channel
->max_reg_power
* 2;
603 arg
.channel
.max_antenna_gain
= channel
->max_antenna_gain
* 2;
605 ret
= ath10k_wmi_vdev_start(ar
, &arg
);
607 ath10k_warn("Monitor vdev %i start failed: ret %d\n",
612 ret
= ath10k_vdev_setup_sync(ar
);
614 ath10k_warn("Monitor vdev %i setup failed %d\n",
619 ret
= ath10k_wmi_vdev_up(ar
, vdev_id
, 0, ar
->mac_addr
);
621 ath10k_warn("Monitor vdev %i up failed: %d\n",
626 ar
->monitor_vdev_id
= vdev_id
;
627 ar
->monitor_enabled
= true;
632 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
634 ath10k_warn("Monitor vdev %i stop failed: %d\n",
635 ar
->monitor_vdev_id
, ret
);
640 static int ath10k_monitor_stop(struct ath10k
*ar
)
644 lockdep_assert_held(&ar
->conf_mutex
);
646 if (!ar
->monitor_present
) {
647 ath10k_warn("mac montor stop -- monitor is not present\n");
651 if (!ar
->monitor_enabled
) {
652 ath10k_warn("mac montor stop -- monitor is not enabled\n");
656 ret
= ath10k_wmi_vdev_down(ar
, ar
->monitor_vdev_id
);
658 ath10k_warn("Monitor vdev %i down failed: %d\n",
659 ar
->monitor_vdev_id
, ret
);
661 ret
= ath10k_wmi_vdev_stop(ar
, ar
->monitor_vdev_id
);
663 ath10k_warn("Monitor vdev %i stop failed: %d\n",
664 ar
->monitor_vdev_id
, ret
);
666 ret
= ath10k_vdev_setup_sync(ar
);
668 ath10k_warn("Monitor_down sync failed, vdev %i: %d\n",
669 ar
->monitor_vdev_id
, ret
);
671 ar
->monitor_enabled
= false;
675 static int ath10k_monitor_create(struct ath10k
*ar
)
679 lockdep_assert_held(&ar
->conf_mutex
);
681 if (ar
->monitor_present
) {
682 ath10k_warn("Monitor mode already enabled\n");
686 bit
= ffs(ar
->free_vdev_map
);
688 ath10k_warn("No free VDEV slots\n");
692 ar
->monitor_vdev_id
= bit
- 1;
693 ar
->free_vdev_map
&= ~(1 << ar
->monitor_vdev_id
);
695 ret
= ath10k_wmi_vdev_create(ar
, ar
->monitor_vdev_id
,
696 WMI_VDEV_TYPE_MONITOR
,
699 ath10k_warn("WMI vdev %i monitor create failed: ret %d\n",
700 ar
->monitor_vdev_id
, ret
);
704 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d created\n",
705 ar
->monitor_vdev_id
);
707 ar
->monitor_present
= true;
712 * Restore the ID to the global map.
714 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
718 static int ath10k_monitor_destroy(struct ath10k
*ar
)
722 lockdep_assert_held(&ar
->conf_mutex
);
724 if (!ar
->monitor_present
)
727 ret
= ath10k_wmi_vdev_delete(ar
, ar
->monitor_vdev_id
);
729 ath10k_warn("WMI vdev %i monitor delete failed: %d\n",
730 ar
->monitor_vdev_id
, ret
);
734 ar
->free_vdev_map
|= 1 << (ar
->monitor_vdev_id
);
735 ar
->monitor_present
= false;
737 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor vdev %d deleted\n",
738 ar
->monitor_vdev_id
);
742 static int ath10k_start_cac(struct ath10k
*ar
)
746 lockdep_assert_held(&ar
->conf_mutex
);
748 set_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
750 ret
= ath10k_monitor_create(ar
);
752 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
756 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
758 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
759 ath10k_monitor_destroy(ar
);
763 ath10k_dbg(ATH10K_DBG_MAC
, "mac cac start monitor vdev %d\n",
764 ar
->monitor_vdev_id
);
769 static int ath10k_stop_cac(struct ath10k
*ar
)
771 lockdep_assert_held(&ar
->conf_mutex
);
773 /* CAC is not running - do nothing */
774 if (!test_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
))
777 ath10k_monitor_stop(ar
);
778 ath10k_monitor_destroy(ar
);
779 clear_bit(ATH10K_CAC_RUNNING
, &ar
->dev_flags
);
781 ath10k_dbg(ATH10K_DBG_MAC
, "mac cac finished\n");
786 static const char *ath10k_dfs_state(enum nl80211_dfs_state dfs_state
)
789 case NL80211_DFS_USABLE
:
791 case NL80211_DFS_UNAVAILABLE
:
792 return "UNAVAILABLE";
793 case NL80211_DFS_AVAILABLE
:
801 static void ath10k_config_radar_detection(struct ath10k
*ar
)
803 struct ieee80211_channel
*chan
= ar
->hw
->conf
.chandef
.chan
;
804 bool radar
= ar
->hw
->conf
.radar_enabled
;
805 bool chan_radar
= !!(chan
->flags
& IEEE80211_CHAN_RADAR
);
806 enum nl80211_dfs_state dfs_state
= chan
->dfs_state
;
809 lockdep_assert_held(&ar
->conf_mutex
);
811 ath10k_dbg(ATH10K_DBG_MAC
,
812 "mac radar config update: chan %dMHz radar %d chan radar %d chan state %s\n",
813 chan
->center_freq
, radar
, chan_radar
,
814 ath10k_dfs_state(dfs_state
));
817 * It's safe to call it even if CAC is not started.
818 * This call here guarantees changing channel, etc. will stop CAC.
828 if (dfs_state
!= NL80211_DFS_USABLE
)
831 ret
= ath10k_start_cac(ar
);
834 * Not possible to start CAC on current channel so starting
835 * radiation is not allowed, make this channel DFS_UNAVAILABLE
836 * by indicating that radar was detected.
838 ath10k_warn("failed to start CAC (%d)\n", ret
);
839 ieee80211_radar_detected(ar
->hw
);
843 static void ath10k_control_beaconing(struct ath10k_vif
*arvif
,
844 struct ieee80211_bss_conf
*info
)
848 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
850 if (!info
->enable_beacon
) {
851 ath10k_vdev_stop(arvif
);
853 arvif
->is_started
= false;
854 arvif
->is_up
= false;
856 spin_lock_bh(&arvif
->ar
->data_lock
);
858 dma_unmap_single(arvif
->ar
->dev
,
859 ATH10K_SKB_CB(arvif
->beacon
)->paddr
,
860 arvif
->beacon
->len
, DMA_TO_DEVICE
);
861 dev_kfree_skb_any(arvif
->beacon
);
863 arvif
->beacon
= NULL
;
864 arvif
->beacon_sent
= false;
866 spin_unlock_bh(&arvif
->ar
->data_lock
);
871 arvif
->tx_seq_no
= 0x1000;
873 ret
= ath10k_vdev_start(arvif
);
878 memcpy(arvif
->bssid
, info
->bssid
, ETH_ALEN
);
880 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
883 ath10k_warn("Failed to bring up vdev %d: %i\n",
884 arvif
->vdev_id
, ret
);
885 ath10k_vdev_stop(arvif
);
889 arvif
->is_started
= true;
892 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d up\n", arvif
->vdev_id
);
895 static void ath10k_control_ibss(struct ath10k_vif
*arvif
,
896 struct ieee80211_bss_conf
*info
,
897 const u8 self_peer
[ETH_ALEN
])
902 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
904 if (!info
->ibss_joined
) {
905 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, self_peer
);
907 ath10k_warn("Failed to delete IBSS self peer:%pM for VDEV:%d ret:%d\n",
908 self_peer
, arvif
->vdev_id
, ret
);
910 if (is_zero_ether_addr(arvif
->bssid
))
913 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
,
916 ath10k_warn("Failed to delete IBSS BSSID peer:%pM for VDEV:%d ret:%d\n",
917 arvif
->bssid
, arvif
->vdev_id
, ret
);
921 memset(arvif
->bssid
, 0, ETH_ALEN
);
926 ret
= ath10k_peer_create(arvif
->ar
, arvif
->vdev_id
, self_peer
);
928 ath10k_warn("Failed to create IBSS self peer:%pM for VDEV:%d ret:%d\n",
929 self_peer
, arvif
->vdev_id
, ret
);
933 vdev_param
= arvif
->ar
->wmi
.vdev_param
->atim_window
;
934 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
, arvif
->vdev_id
, vdev_param
,
935 ATH10K_DEFAULT_ATIM
);
937 ath10k_warn("Failed to set IBSS ATIM for VDEV:%d ret:%d\n",
938 arvif
->vdev_id
, ret
);
942 * Review this when mac80211 gains per-interface powersave support.
944 static int ath10k_mac_vif_setup_ps(struct ath10k_vif
*arvif
)
946 struct ath10k
*ar
= arvif
->ar
;
947 struct ieee80211_conf
*conf
= &ar
->hw
->conf
;
948 enum wmi_sta_powersave_param param
;
949 enum wmi_sta_ps_mode psmode
;
952 lockdep_assert_held(&arvif
->ar
->conf_mutex
);
954 if (arvif
->vif
->type
!= NL80211_IFTYPE_STATION
)
957 if (conf
->flags
& IEEE80211_CONF_PS
) {
958 psmode
= WMI_STA_PS_MODE_ENABLED
;
959 param
= WMI_STA_PS_PARAM_INACTIVITY_TIME
;
961 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
, param
,
962 conf
->dynamic_ps_timeout
);
964 ath10k_warn("Failed to set inactivity time for vdev %d: %i\n",
965 arvif
->vdev_id
, ret
);
969 psmode
= WMI_STA_PS_MODE_DISABLED
;
972 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d psmode %s\n",
973 arvif
->vdev_id
, psmode
? "enable" : "disable");
975 ret
= ath10k_wmi_set_psmode(ar
, arvif
->vdev_id
, psmode
);
977 ath10k_warn("Failed to set PS Mode: %d for VDEV: %d\n",
978 psmode
, arvif
->vdev_id
);
985 /**********************/
986 /* Station management */
987 /**********************/
989 static void ath10k_peer_assoc_h_basic(struct ath10k
*ar
,
990 struct ath10k_vif
*arvif
,
991 struct ieee80211_sta
*sta
,
992 struct ieee80211_bss_conf
*bss_conf
,
993 struct wmi_peer_assoc_complete_arg
*arg
)
995 lockdep_assert_held(&ar
->conf_mutex
);
997 memcpy(arg
->addr
, sta
->addr
, ETH_ALEN
);
998 arg
->vdev_id
= arvif
->vdev_id
;
999 arg
->peer_aid
= sta
->aid
;
1000 arg
->peer_flags
|= WMI_PEER_AUTH
;
1002 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
1004 * Seems FW have problems with Power Save in STA
1005 * mode when we setup this parameter to high (eg. 5).
1006 * Often we see that FW don't send NULL (with clean P flags)
1007 * frame even there is info about buffered frames in beacons.
1008 * Sometimes we have to wait more than 10 seconds before FW
1009 * will wakeup. Often sending one ping from AP to our device
1010 * just fail (more than 50%).
1012 * Seems setting this FW parameter to 1 couse FW
1013 * will check every beacon and will wakup immediately
1014 * after detection buffered data.
1016 arg
->peer_listen_intval
= 1;
1018 arg
->peer_listen_intval
= ar
->hw
->conf
.listen_interval
;
1020 arg
->peer_num_spatial_streams
= 1;
1023 * The assoc capabilities are available only in managed mode.
1025 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
&& bss_conf
)
1026 arg
->peer_caps
= bss_conf
->assoc_capability
;
1029 static void ath10k_peer_assoc_h_crypto(struct ath10k
*ar
,
1030 struct ath10k_vif
*arvif
,
1031 struct wmi_peer_assoc_complete_arg
*arg
)
1033 struct ieee80211_vif
*vif
= arvif
->vif
;
1034 struct ieee80211_bss_conf
*info
= &vif
->bss_conf
;
1035 struct cfg80211_bss
*bss
;
1036 const u8
*rsnie
= NULL
;
1037 const u8
*wpaie
= NULL
;
1039 lockdep_assert_held(&ar
->conf_mutex
);
1041 bss
= cfg80211_get_bss(ar
->hw
->wiphy
, ar
->hw
->conf
.chandef
.chan
,
1042 info
->bssid
, NULL
, 0, 0, 0);
1044 const struct cfg80211_bss_ies
*ies
;
1047 rsnie
= ieee80211_bss_get_ie(bss
, WLAN_EID_RSN
);
1049 ies
= rcu_dereference(bss
->ies
);
1051 wpaie
= cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
1052 WLAN_OUI_TYPE_MICROSOFT_WPA
,
1056 cfg80211_put_bss(ar
->hw
->wiphy
, bss
);
1059 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1060 if (rsnie
|| wpaie
) {
1061 ath10k_dbg(ATH10K_DBG_WMI
, "%s: rsn ie found\n", __func__
);
1062 arg
->peer_flags
|= WMI_PEER_NEED_PTK_4_WAY
;
1066 ath10k_dbg(ATH10K_DBG_WMI
, "%s: wpa ie found\n", __func__
);
1067 arg
->peer_flags
|= WMI_PEER_NEED_GTK_2_WAY
;
1071 static void ath10k_peer_assoc_h_rates(struct ath10k
*ar
,
1072 struct ieee80211_sta
*sta
,
1073 struct wmi_peer_assoc_complete_arg
*arg
)
1075 struct wmi_rate_set_arg
*rateset
= &arg
->peer_legacy_rates
;
1076 const struct ieee80211_supported_band
*sband
;
1077 const struct ieee80211_rate
*rates
;
1081 lockdep_assert_held(&ar
->conf_mutex
);
1083 sband
= ar
->hw
->wiphy
->bands
[ar
->hw
->conf
.chandef
.chan
->band
];
1084 ratemask
= sta
->supp_rates
[ar
->hw
->conf
.chandef
.chan
->band
];
1085 rates
= sband
->bitrates
;
1087 rateset
->num_rates
= 0;
1089 for (i
= 0; i
< 32; i
++, ratemask
>>= 1, rates
++) {
1090 if (!(ratemask
& 1))
1093 rateset
->rates
[rateset
->num_rates
] = rates
->hw_value
;
1094 rateset
->num_rates
++;
1098 static void ath10k_peer_assoc_h_ht(struct ath10k
*ar
,
1099 struct ieee80211_sta
*sta
,
1100 struct wmi_peer_assoc_complete_arg
*arg
)
1102 const struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
1105 lockdep_assert_held(&ar
->conf_mutex
);
1107 if (!ht_cap
->ht_supported
)
1110 arg
->peer_flags
|= WMI_PEER_HT
;
1111 arg
->peer_max_mpdu
= (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1112 ht_cap
->ampdu_factor
)) - 1;
1114 arg
->peer_mpdu_density
=
1115 ath10k_parse_mpdudensity(ht_cap
->ampdu_density
);
1117 arg
->peer_ht_caps
= ht_cap
->cap
;
1118 arg
->peer_rate_caps
|= WMI_RC_HT_FLAG
;
1120 if (ht_cap
->cap
& IEEE80211_HT_CAP_LDPC_CODING
)
1121 arg
->peer_flags
|= WMI_PEER_LDPC
;
1123 if (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) {
1124 arg
->peer_flags
|= WMI_PEER_40MHZ
;
1125 arg
->peer_rate_caps
|= WMI_RC_CW40_FLAG
;
1128 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_20
)
1129 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1131 if (ht_cap
->cap
& IEEE80211_HT_CAP_SGI_40
)
1132 arg
->peer_rate_caps
|= WMI_RC_SGI_FLAG
;
1134 if (ht_cap
->cap
& IEEE80211_HT_CAP_TX_STBC
) {
1135 arg
->peer_rate_caps
|= WMI_RC_TX_STBC_FLAG
;
1136 arg
->peer_flags
|= WMI_PEER_STBC
;
1139 if (ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
) {
1141 stbc
= ht_cap
->cap
& IEEE80211_HT_CAP_RX_STBC
;
1142 stbc
= stbc
>> IEEE80211_HT_CAP_RX_STBC_SHIFT
;
1143 stbc
= stbc
<< WMI_RC_RX_STBC_FLAG_S
;
1144 arg
->peer_rate_caps
|= stbc
;
1145 arg
->peer_flags
|= WMI_PEER_STBC
;
1148 if (ht_cap
->mcs
.rx_mask
[1] && ht_cap
->mcs
.rx_mask
[2])
1149 arg
->peer_rate_caps
|= WMI_RC_TS_FLAG
;
1150 else if (ht_cap
->mcs
.rx_mask
[1])
1151 arg
->peer_rate_caps
|= WMI_RC_DS_FLAG
;
1153 for (i
= 0, n
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
*8; i
++)
1154 if (ht_cap
->mcs
.rx_mask
[i
/8] & (1 << i
%8))
1155 arg
->peer_ht_rates
.rates
[n
++] = i
;
1158 * This is a workaround for HT-enabled STAs which break the spec
1159 * and have no HT capabilities RX mask (no HT RX MCS map).
1161 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1162 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1164 * Firmware asserts if such situation occurs.
1167 arg
->peer_ht_rates
.num_rates
= 8;
1168 for (i
= 0; i
< arg
->peer_ht_rates
.num_rates
; i
++)
1169 arg
->peer_ht_rates
.rates
[i
] = i
;
1171 arg
->peer_ht_rates
.num_rates
= n
;
1172 arg
->peer_num_spatial_streams
= sta
->rx_nss
;
1175 ath10k_dbg(ATH10K_DBG_MAC
, "mac ht peer %pM mcs cnt %d nss %d\n",
1177 arg
->peer_ht_rates
.num_rates
,
1178 arg
->peer_num_spatial_streams
);
1181 static int ath10k_peer_assoc_qos_ap(struct ath10k
*ar
,
1182 struct ath10k_vif
*arvif
,
1183 struct ieee80211_sta
*sta
)
1189 lockdep_assert_held(&ar
->conf_mutex
);
1191 if (sta
->wme
&& sta
->uapsd_queues
) {
1192 ath10k_dbg(ATH10K_DBG_MAC
, "mac uapsd_queues 0x%x max_sp %d\n",
1193 sta
->uapsd_queues
, sta
->max_sp
);
1195 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
1196 uapsd
|= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN
|
1197 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN
;
1198 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
1199 uapsd
|= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN
|
1200 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN
;
1201 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
1202 uapsd
|= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN
|
1203 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN
;
1204 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
1205 uapsd
|= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN
|
1206 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN
;
1209 if (sta
->max_sp
< MAX_WMI_AP_PS_PEER_PARAM_MAX_SP
)
1210 max_sp
= sta
->max_sp
;
1212 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1214 WMI_AP_PS_PEER_PARAM_UAPSD
,
1217 ath10k_warn("failed to set ap ps peer param uapsd for vdev %i: %d\n",
1218 arvif
->vdev_id
, ret
);
1222 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
,
1224 WMI_AP_PS_PEER_PARAM_MAX_SP
,
1227 ath10k_warn("failed to set ap ps peer param max sp for vdev %i: %d\n",
1228 arvif
->vdev_id
, ret
);
1232 /* TODO setup this based on STA listen interval and
1233 beacon interval. Currently we don't know
1234 sta->listen_interval - mac80211 patch required.
1235 Currently use 10 seconds */
1236 ret
= ath10k_wmi_set_ap_ps_param(ar
, arvif
->vdev_id
, sta
->addr
,
1237 WMI_AP_PS_PEER_PARAM_AGEOUT_TIME
, 10);
1239 ath10k_warn("failed to set ap ps peer param ageout time for vdev %i: %d\n",
1240 arvif
->vdev_id
, ret
);
1248 static void ath10k_peer_assoc_h_vht(struct ath10k
*ar
,
1249 struct ieee80211_sta
*sta
,
1250 struct wmi_peer_assoc_complete_arg
*arg
)
1252 const struct ieee80211_sta_vht_cap
*vht_cap
= &sta
->vht_cap
;
1255 if (!vht_cap
->vht_supported
)
1258 arg
->peer_flags
|= WMI_PEER_VHT
;
1259 arg
->peer_vht_caps
= vht_cap
->cap
;
1262 ampdu_factor
= (vht_cap
->cap
&
1263 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
) >>
1264 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
1266 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1267 * zero in VHT IE. Using it would result in degraded throughput.
1268 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1269 * it if VHT max_mpdu is smaller. */
1270 arg
->peer_max_mpdu
= max(arg
->peer_max_mpdu
,
1271 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
1272 ampdu_factor
)) - 1);
1274 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1275 arg
->peer_flags
|= WMI_PEER_80MHZ
;
1277 arg
->peer_vht_rates
.rx_max_rate
=
1278 __le16_to_cpu(vht_cap
->vht_mcs
.rx_highest
);
1279 arg
->peer_vht_rates
.rx_mcs_set
=
1280 __le16_to_cpu(vht_cap
->vht_mcs
.rx_mcs_map
);
1281 arg
->peer_vht_rates
.tx_max_rate
=
1282 __le16_to_cpu(vht_cap
->vht_mcs
.tx_highest
);
1283 arg
->peer_vht_rates
.tx_mcs_set
=
1284 __le16_to_cpu(vht_cap
->vht_mcs
.tx_mcs_map
);
1286 ath10k_dbg(ATH10K_DBG_MAC
, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1287 sta
->addr
, arg
->peer_max_mpdu
, arg
->peer_flags
);
1290 static void ath10k_peer_assoc_h_qos(struct ath10k
*ar
,
1291 struct ath10k_vif
*arvif
,
1292 struct ieee80211_sta
*sta
,
1293 struct ieee80211_bss_conf
*bss_conf
,
1294 struct wmi_peer_assoc_complete_arg
*arg
)
1296 switch (arvif
->vdev_type
) {
1297 case WMI_VDEV_TYPE_AP
:
1299 arg
->peer_flags
|= WMI_PEER_QOS
;
1301 if (sta
->wme
&& sta
->uapsd_queues
) {
1302 arg
->peer_flags
|= WMI_PEER_APSD
;
1303 arg
->peer_rate_caps
|= WMI_RC_UAPSD_FLAG
;
1306 case WMI_VDEV_TYPE_STA
:
1308 arg
->peer_flags
|= WMI_PEER_QOS
;
1315 static void ath10k_peer_assoc_h_phymode(struct ath10k
*ar
,
1316 struct ath10k_vif
*arvif
,
1317 struct ieee80211_sta
*sta
,
1318 struct wmi_peer_assoc_complete_arg
*arg
)
1320 enum wmi_phy_mode phymode
= MODE_UNKNOWN
;
1322 switch (ar
->hw
->conf
.chandef
.chan
->band
) {
1323 case IEEE80211_BAND_2GHZ
:
1324 if (sta
->ht_cap
.ht_supported
) {
1325 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1326 phymode
= MODE_11NG_HT40
;
1328 phymode
= MODE_11NG_HT20
;
1334 case IEEE80211_BAND_5GHZ
:
1338 if (sta
->vht_cap
.vht_supported
) {
1339 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_80
)
1340 phymode
= MODE_11AC_VHT80
;
1341 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1342 phymode
= MODE_11AC_VHT40
;
1343 else if (sta
->bandwidth
== IEEE80211_STA_RX_BW_20
)
1344 phymode
= MODE_11AC_VHT20
;
1345 } else if (sta
->ht_cap
.ht_supported
) {
1346 if (sta
->bandwidth
== IEEE80211_STA_RX_BW_40
)
1347 phymode
= MODE_11NA_HT40
;
1349 phymode
= MODE_11NA_HT20
;
1359 ath10k_dbg(ATH10K_DBG_MAC
, "mac peer %pM phymode %s\n",
1360 sta
->addr
, ath10k_wmi_phymode_str(phymode
));
1362 arg
->peer_phymode
= phymode
;
1363 WARN_ON(phymode
== MODE_UNKNOWN
);
1366 static int ath10k_peer_assoc_prepare(struct ath10k
*ar
,
1367 struct ath10k_vif
*arvif
,
1368 struct ieee80211_sta
*sta
,
1369 struct ieee80211_bss_conf
*bss_conf
,
1370 struct wmi_peer_assoc_complete_arg
*arg
)
1372 lockdep_assert_held(&ar
->conf_mutex
);
1374 memset(arg
, 0, sizeof(*arg
));
1376 ath10k_peer_assoc_h_basic(ar
, arvif
, sta
, bss_conf
, arg
);
1377 ath10k_peer_assoc_h_crypto(ar
, arvif
, arg
);
1378 ath10k_peer_assoc_h_rates(ar
, sta
, arg
);
1379 ath10k_peer_assoc_h_ht(ar
, sta
, arg
);
1380 ath10k_peer_assoc_h_vht(ar
, sta
, arg
);
1381 ath10k_peer_assoc_h_qos(ar
, arvif
, sta
, bss_conf
, arg
);
1382 ath10k_peer_assoc_h_phymode(ar
, arvif
, sta
, arg
);
1387 static const u32 ath10k_smps_map
[] = {
1388 [WLAN_HT_CAP_SM_PS_STATIC
] = WMI_PEER_SMPS_STATIC
,
1389 [WLAN_HT_CAP_SM_PS_DYNAMIC
] = WMI_PEER_SMPS_DYNAMIC
,
1390 [WLAN_HT_CAP_SM_PS_INVALID
] = WMI_PEER_SMPS_PS_NONE
,
1391 [WLAN_HT_CAP_SM_PS_DISABLED
] = WMI_PEER_SMPS_PS_NONE
,
1394 static int ath10k_setup_peer_smps(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1396 const struct ieee80211_sta_ht_cap
*ht_cap
)
1400 if (!ht_cap
->ht_supported
)
1403 smps
= ht_cap
->cap
& IEEE80211_HT_CAP_SM_PS
;
1404 smps
>>= IEEE80211_HT_CAP_SM_PS_SHIFT
;
1406 if (smps
>= ARRAY_SIZE(ath10k_smps_map
))
1409 return ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, addr
,
1410 WMI_PEER_SMPS_STATE
,
1411 ath10k_smps_map
[smps
]);
1414 /* can be called only in mac80211 callbacks due to `key_count` usage */
1415 static void ath10k_bss_assoc(struct ieee80211_hw
*hw
,
1416 struct ieee80211_vif
*vif
,
1417 struct ieee80211_bss_conf
*bss_conf
)
1419 struct ath10k
*ar
= hw
->priv
;
1420 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1421 struct ieee80211_sta_ht_cap ht_cap
;
1422 struct wmi_peer_assoc_complete_arg peer_arg
;
1423 struct ieee80211_sta
*ap_sta
;
1426 lockdep_assert_held(&ar
->conf_mutex
);
1430 ap_sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1432 ath10k_warn("Failed to find station entry for %pM, vdev %i\n",
1433 bss_conf
->bssid
, arvif
->vdev_id
);
1438 /* ap_sta must be accessed only within rcu section which must be left
1439 * before calling ath10k_setup_peer_smps() which might sleep. */
1440 ht_cap
= ap_sta
->ht_cap
;
1442 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, ap_sta
,
1443 bss_conf
, &peer_arg
);
1445 ath10k_warn("Peer assoc prepare failed for %pM vdev %i\n: %d",
1446 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1453 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1455 ath10k_warn("Peer assoc failed for %pM vdev %i\n: %d",
1456 bss_conf
->bssid
, arvif
->vdev_id
, ret
);
1460 ret
= ath10k_setup_peer_smps(ar
, arvif
, bss_conf
->bssid
, &ht_cap
);
1462 ath10k_warn("failed to setup peer SMPS for vdev %i: %d\n",
1463 arvif
->vdev_id
, ret
);
1467 ath10k_dbg(ATH10K_DBG_MAC
,
1468 "mac vdev %d up (associated) bssid %pM aid %d\n",
1469 arvif
->vdev_id
, bss_conf
->bssid
, bss_conf
->aid
);
1471 arvif
->aid
= bss_conf
->aid
;
1472 memcpy(arvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1474 ret
= ath10k_wmi_vdev_up(ar
, arvif
->vdev_id
, arvif
->aid
, arvif
->bssid
);
1476 ath10k_warn("VDEV: %d up failed: ret %d\n",
1477 arvif
->vdev_id
, ret
);
1481 arvif
->is_up
= true;
1487 static void ath10k_bss_disassoc(struct ieee80211_hw
*hw
,
1488 struct ieee80211_vif
*vif
)
1490 struct ath10k
*ar
= hw
->priv
;
1491 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1494 lockdep_assert_held(&ar
->conf_mutex
);
1497 * For some reason, calling VDEV-DOWN before VDEV-STOP
1498 * makes the FW to send frames via HTT after disassociation.
1499 * No idea why this happens, even though VDEV-DOWN is supposed
1500 * to be analogous to link down, so just stop the VDEV.
1502 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d stop (disassociated\n",
1505 /* FIXME: check return value */
1506 ret
= ath10k_vdev_stop(arvif
);
1509 * If we don't call VDEV-DOWN after VDEV-STOP FW will remain active and
1510 * report beacons from previously associated network through HTT.
1511 * This in turn would spam mac80211 WARN_ON if we bring down all
1512 * interfaces as it expects there is no rx when no interface is
1515 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d down\n", arvif
->vdev_id
);
1517 /* FIXME: why don't we print error if wmi call fails? */
1518 ret
= ath10k_wmi_vdev_down(ar
, arvif
->vdev_id
);
1520 arvif
->def_wep_key_idx
= 0;
1522 arvif
->is_started
= false;
1523 arvif
->is_up
= false;
1526 static int ath10k_station_assoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1527 struct ieee80211_sta
*sta
)
1529 struct wmi_peer_assoc_complete_arg peer_arg
;
1532 lockdep_assert_held(&ar
->conf_mutex
);
1534 ret
= ath10k_peer_assoc_prepare(ar
, arvif
, sta
, NULL
, &peer_arg
);
1536 ath10k_warn("WMI peer assoc prepare failed for %pM vdev %i: %i\n",
1537 sta
->addr
, arvif
->vdev_id
, ret
);
1541 ret
= ath10k_wmi_peer_assoc(ar
, &peer_arg
);
1543 ath10k_warn("Peer assoc failed for STA %pM vdev %i: %d\n",
1544 sta
->addr
, arvif
->vdev_id
, ret
);
1548 ret
= ath10k_setup_peer_smps(ar
, arvif
, sta
->addr
, &sta
->ht_cap
);
1550 ath10k_warn("failed to setup peer SMPS for vdev: %d\n", ret
);
1554 ret
= ath10k_install_peer_wep_keys(arvif
, sta
->addr
);
1556 ath10k_warn("could not install peer wep keys for vdev %i: %d\n",
1557 arvif
->vdev_id
, ret
);
1561 ret
= ath10k_peer_assoc_qos_ap(ar
, arvif
, sta
);
1563 ath10k_warn("could not set qos params for STA %pM for vdev %i: %d\n",
1564 sta
->addr
, arvif
->vdev_id
, ret
);
1571 static int ath10k_station_disassoc(struct ath10k
*ar
, struct ath10k_vif
*arvif
,
1572 struct ieee80211_sta
*sta
)
1576 lockdep_assert_held(&ar
->conf_mutex
);
1578 ret
= ath10k_clear_peer_keys(arvif
, sta
->addr
);
1580 ath10k_warn("could not clear all peer wep keys for vdev %i: %d\n",
1581 arvif
->vdev_id
, ret
);
1592 static int ath10k_update_channel_list(struct ath10k
*ar
)
1594 struct ieee80211_hw
*hw
= ar
->hw
;
1595 struct ieee80211_supported_band
**bands
;
1596 enum ieee80211_band band
;
1597 struct ieee80211_channel
*channel
;
1598 struct wmi_scan_chan_list_arg arg
= {0};
1599 struct wmi_channel_arg
*ch
;
1605 lockdep_assert_held(&ar
->conf_mutex
);
1607 bands
= hw
->wiphy
->bands
;
1608 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1612 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1613 if (bands
[band
]->channels
[i
].flags
&
1614 IEEE80211_CHAN_DISABLED
)
1621 len
= sizeof(struct wmi_channel_arg
) * arg
.n_channels
;
1622 arg
.channels
= kzalloc(len
, GFP_KERNEL
);
1627 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1631 for (i
= 0; i
< bands
[band
]->n_channels
; i
++) {
1632 channel
= &bands
[band
]->channels
[i
];
1634 if (channel
->flags
& IEEE80211_CHAN_DISABLED
)
1637 ch
->allow_ht
= true;
1639 /* FIXME: when should we really allow VHT? */
1640 ch
->allow_vht
= true;
1643 !(channel
->flags
& IEEE80211_CHAN_NO_IR
);
1646 !(channel
->flags
& IEEE80211_CHAN_NO_HT40PLUS
);
1649 !!(channel
->flags
& IEEE80211_CHAN_RADAR
);
1651 passive
= channel
->flags
& IEEE80211_CHAN_NO_IR
;
1652 ch
->passive
= passive
;
1654 ch
->freq
= channel
->center_freq
;
1656 ch
->max_power
= channel
->max_power
* 2;
1657 ch
->max_reg_power
= channel
->max_reg_power
* 2;
1658 ch
->max_antenna_gain
= channel
->max_antenna_gain
* 2;
1659 ch
->reg_class_id
= 0; /* FIXME */
1661 /* FIXME: why use only legacy modes, why not any
1662 * HT/VHT modes? Would that even make any
1664 if (channel
->band
== IEEE80211_BAND_2GHZ
)
1665 ch
->mode
= MODE_11G
;
1667 ch
->mode
= MODE_11A
;
1669 if (WARN_ON_ONCE(ch
->mode
== MODE_UNKNOWN
))
1672 ath10k_dbg(ATH10K_DBG_WMI
,
1673 "mac channel [%zd/%d] freq %d maxpower %d regpower %d antenna %d mode %d\n",
1674 ch
- arg
.channels
, arg
.n_channels
,
1675 ch
->freq
, ch
->max_power
, ch
->max_reg_power
,
1676 ch
->max_antenna_gain
, ch
->mode
);
1682 ret
= ath10k_wmi_scan_chan_list(ar
, &arg
);
1683 kfree(arg
.channels
);
1688 static void ath10k_regd_update(struct ath10k
*ar
)
1690 struct reg_dmn_pair_mapping
*regpair
;
1693 lockdep_assert_held(&ar
->conf_mutex
);
1695 ret
= ath10k_update_channel_list(ar
);
1697 ath10k_warn("could not update channel list (%d)\n", ret
);
1699 regpair
= ar
->ath_common
.regulatory
.regpair
;
1701 /* Target allows setting up per-band regdomain but ath_common provides
1702 * a combined one only */
1703 ret
= ath10k_wmi_pdev_set_regdomain(ar
,
1704 regpair
->reg_domain
,
1705 regpair
->reg_domain
, /* 2ghz */
1706 regpair
->reg_domain
, /* 5ghz */
1707 regpair
->reg_2ghz_ctl
,
1708 regpair
->reg_5ghz_ctl
);
1710 ath10k_warn("could not set pdev regdomain (%d)\n", ret
);
1713 static void ath10k_reg_notifier(struct wiphy
*wiphy
,
1714 struct regulatory_request
*request
)
1716 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
1717 struct ath10k
*ar
= hw
->priv
;
1720 ath_reg_notifier_apply(wiphy
, request
, &ar
->ath_common
.regulatory
);
1722 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
) {
1723 ath10k_dbg(ATH10K_DBG_REGULATORY
, "dfs region 0x%x\n",
1724 request
->dfs_region
);
1725 result
= ar
->dfs_detector
->set_dfs_domain(ar
->dfs_detector
,
1726 request
->dfs_region
);
1728 ath10k_warn("dfs region 0x%X not supported, will trigger radar for every pulse\n",
1729 request
->dfs_region
);
1732 mutex_lock(&ar
->conf_mutex
);
1733 if (ar
->state
== ATH10K_STATE_ON
)
1734 ath10k_regd_update(ar
);
1735 mutex_unlock(&ar
->conf_mutex
);
1742 static u8
ath10k_tx_h_get_tid(struct ieee80211_hdr
*hdr
)
1744 if (ieee80211_is_mgmt(hdr
->frame_control
))
1745 return HTT_DATA_TX_EXT_TID_MGMT
;
1747 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1748 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1750 if (!is_unicast_ether_addr(ieee80211_get_DA(hdr
)))
1751 return HTT_DATA_TX_EXT_TID_NON_QOS_MCAST_BCAST
;
1753 return ieee80211_get_qos_ctl(hdr
)[0] & IEEE80211_QOS_CTL_TID_MASK
;
1756 static u8
ath10k_tx_h_get_vdev_id(struct ath10k
*ar
,
1757 struct ieee80211_tx_info
*info
)
1759 if (info
->control
.vif
)
1760 return ath10k_vif_to_arvif(info
->control
.vif
)->vdev_id
;
1762 if (ar
->monitor_enabled
)
1763 return ar
->monitor_vdev_id
;
1765 ath10k_warn("could not resolve vdev id\n");
1770 * Frames sent to the FW have to be in "Native Wifi" format.
1771 * Strip the QoS field from the 802.11 header.
1773 static void ath10k_tx_h_qos_workaround(struct ieee80211_hw
*hw
,
1774 struct ieee80211_tx_control
*control
,
1775 struct sk_buff
*skb
)
1777 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1780 if (!ieee80211_is_data_qos(hdr
->frame_control
))
1783 qos_ctl
= ieee80211_get_qos_ctl(hdr
);
1784 memmove(skb
->data
+ IEEE80211_QOS_CTL_LEN
,
1785 skb
->data
, (void *)qos_ctl
- (void *)skb
->data
);
1786 skb_pull(skb
, IEEE80211_QOS_CTL_LEN
);
1789 static void ath10k_tx_wep_key_work(struct work_struct
*work
)
1791 struct ath10k_vif
*arvif
= container_of(work
, struct ath10k_vif
,
1793 int ret
, keyidx
= arvif
->def_wep_key_newidx
;
1795 if (arvif
->def_wep_key_idx
== keyidx
)
1798 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d set keyidx %d\n",
1799 arvif
->vdev_id
, keyidx
);
1801 ret
= ath10k_wmi_vdev_set_param(arvif
->ar
,
1803 arvif
->ar
->wmi
.vdev_param
->def_keyid
,
1806 ath10k_warn("could not update wep keyidx (%d)\n", ret
);
1810 arvif
->def_wep_key_idx
= keyidx
;
1813 static void ath10k_tx_h_update_wep_key(struct sk_buff
*skb
)
1815 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1816 struct ieee80211_vif
*vif
= info
->control
.vif
;
1817 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1818 struct ath10k
*ar
= arvif
->ar
;
1819 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1820 struct ieee80211_key_conf
*key
= info
->control
.hw_key
;
1822 if (!ieee80211_has_protected(hdr
->frame_control
))
1828 if (key
->cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1829 key
->cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1832 if (key
->keyidx
== arvif
->def_wep_key_idx
)
1835 /* FIXME: Most likely a few frames will be TXed with an old key. Simply
1836 * queueing frames until key index is updated is not an option because
1837 * sk_buff may need more processing to be done, e.g. offchannel */
1838 arvif
->def_wep_key_newidx
= key
->keyidx
;
1839 ieee80211_queue_work(ar
->hw
, &arvif
->wep_key_work
);
1842 static void ath10k_tx_h_add_p2p_noa_ie(struct ath10k
*ar
, struct sk_buff
*skb
)
1844 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1845 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1846 struct ieee80211_vif
*vif
= info
->control
.vif
;
1847 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
1849 /* This is case only for P2P_GO */
1850 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
||
1851 arvif
->vdev_subtype
!= WMI_VDEV_SUBTYPE_P2P_GO
)
1854 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
1855 spin_lock_bh(&ar
->data_lock
);
1856 if (arvif
->u
.ap
.noa_data
)
1857 if (!pskb_expand_head(skb
, 0, arvif
->u
.ap
.noa_len
,
1859 memcpy(skb_put(skb
, arvif
->u
.ap
.noa_len
),
1860 arvif
->u
.ap
.noa_data
,
1861 arvif
->u
.ap
.noa_len
);
1862 spin_unlock_bh(&ar
->data_lock
);
1866 static void ath10k_tx_htt(struct ath10k
*ar
, struct sk_buff
*skb
)
1868 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1871 if (ar
->htt
.target_version_major
>= 3) {
1872 /* Since HTT 3.0 there is no separate mgmt tx command */
1873 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1877 if (ieee80211_is_mgmt(hdr
->frame_control
)) {
1878 if (test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1880 if (skb_queue_len(&ar
->wmi_mgmt_tx_queue
) >=
1881 ATH10K_MAX_NUM_MGMT_PENDING
) {
1882 ath10k_warn("wmi mgmt_tx queue limit reached\n");
1887 skb_queue_tail(&ar
->wmi_mgmt_tx_queue
, skb
);
1888 ieee80211_queue_work(ar
->hw
, &ar
->wmi_mgmt_tx_work
);
1890 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1892 } else if (!test_bit(ATH10K_FW_FEATURE_HAS_WMI_MGMT_TX
,
1894 ieee80211_is_nullfunc(hdr
->frame_control
)) {
1895 /* FW does not report tx status properly for NullFunc frames
1896 * unless they are sent through mgmt tx path. mac80211 sends
1897 * those frames when it detects link/beacon loss and depends
1898 * on the tx status to be correct. */
1899 ret
= ath10k_htt_mgmt_tx(&ar
->htt
, skb
);
1901 ret
= ath10k_htt_tx(&ar
->htt
, skb
);
1906 ath10k_warn("tx failed (%d). dropping packet.\n", ret
);
1907 ieee80211_free_txskb(ar
->hw
, skb
);
1911 void ath10k_offchan_tx_purge(struct ath10k
*ar
)
1913 struct sk_buff
*skb
;
1916 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1920 ieee80211_free_txskb(ar
->hw
, skb
);
1924 void ath10k_offchan_tx_work(struct work_struct
*work
)
1926 struct ath10k
*ar
= container_of(work
, struct ath10k
, offchan_tx_work
);
1927 struct ath10k_peer
*peer
;
1928 struct ieee80211_hdr
*hdr
;
1929 struct sk_buff
*skb
;
1930 const u8
*peer_addr
;
1934 /* FW requirement: We must create a peer before FW will send out
1935 * an offchannel frame. Otherwise the frame will be stuck and
1936 * never transmitted. We delete the peer upon tx completion.
1937 * It is unlikely that a peer for offchannel tx will already be
1938 * present. However it may be in some rare cases so account for that.
1939 * Otherwise we might remove a legitimate peer and break stuff. */
1942 skb
= skb_dequeue(&ar
->offchan_tx_queue
);
1946 mutex_lock(&ar
->conf_mutex
);
1948 ath10k_dbg(ATH10K_DBG_MAC
, "mac offchannel skb %p\n",
1951 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1952 peer_addr
= ieee80211_get_DA(hdr
);
1953 vdev_id
= ATH10K_SKB_CB(skb
)->vdev_id
;
1955 spin_lock_bh(&ar
->data_lock
);
1956 peer
= ath10k_peer_find(ar
, vdev_id
, peer_addr
);
1957 spin_unlock_bh(&ar
->data_lock
);
1960 /* FIXME: should this use ath10k_warn()? */
1961 ath10k_dbg(ATH10K_DBG_MAC
, "peer %pM on vdev %d already present\n",
1962 peer_addr
, vdev_id
);
1965 ret
= ath10k_peer_create(ar
, vdev_id
, peer_addr
);
1967 ath10k_warn("peer %pM on vdev %d not created (%d)\n",
1968 peer_addr
, vdev_id
, ret
);
1971 spin_lock_bh(&ar
->data_lock
);
1972 reinit_completion(&ar
->offchan_tx_completed
);
1973 ar
->offchan_tx_skb
= skb
;
1974 spin_unlock_bh(&ar
->data_lock
);
1976 ath10k_tx_htt(ar
, skb
);
1978 ret
= wait_for_completion_timeout(&ar
->offchan_tx_completed
,
1981 ath10k_warn("timed out waiting for offchannel skb %p\n",
1985 ret
= ath10k_peer_delete(ar
, vdev_id
, peer_addr
);
1987 ath10k_warn("peer %pM on vdev %d not deleted (%d)\n",
1988 peer_addr
, vdev_id
, ret
);
1991 mutex_unlock(&ar
->conf_mutex
);
1995 void ath10k_mgmt_over_wmi_tx_purge(struct ath10k
*ar
)
1997 struct sk_buff
*skb
;
2000 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2004 ieee80211_free_txskb(ar
->hw
, skb
);
2008 void ath10k_mgmt_over_wmi_tx_work(struct work_struct
*work
)
2010 struct ath10k
*ar
= container_of(work
, struct ath10k
, wmi_mgmt_tx_work
);
2011 struct sk_buff
*skb
;
2015 skb
= skb_dequeue(&ar
->wmi_mgmt_tx_queue
);
2019 ret
= ath10k_wmi_mgmt_tx(ar
, skb
);
2021 ath10k_warn("wmi mgmt_tx failed (%d)\n", ret
);
2022 ieee80211_free_txskb(ar
->hw
, skb
);
2032 * This gets called if we dont get a heart-beat during scan.
2033 * This may indicate the FW has hung and we need to abort the
2034 * scan manually to prevent cancel_hw_scan() from deadlocking
2036 void ath10k_reset_scan(unsigned long ptr
)
2038 struct ath10k
*ar
= (struct ath10k
*)ptr
;
2040 spin_lock_bh(&ar
->data_lock
);
2041 if (!ar
->scan
.in_progress
) {
2042 spin_unlock_bh(&ar
->data_lock
);
2046 ath10k_warn("scan timeout. resetting. fw issue?\n");
2048 if (ar
->scan
.is_roc
)
2049 ieee80211_remain_on_channel_expired(ar
->hw
);
2051 ieee80211_scan_completed(ar
->hw
, 1 /* aborted */);
2053 ar
->scan
.in_progress
= false;
2054 complete_all(&ar
->scan
.completed
);
2055 spin_unlock_bh(&ar
->data_lock
);
2058 static int ath10k_abort_scan(struct ath10k
*ar
)
2060 struct wmi_stop_scan_arg arg
= {
2061 .req_id
= 1, /* FIXME */
2062 .req_type
= WMI_SCAN_STOP_ONE
,
2063 .u
.scan_id
= ATH10K_SCAN_ID
,
2067 lockdep_assert_held(&ar
->conf_mutex
);
2069 del_timer_sync(&ar
->scan
.timeout
);
2071 spin_lock_bh(&ar
->data_lock
);
2072 if (!ar
->scan
.in_progress
) {
2073 spin_unlock_bh(&ar
->data_lock
);
2077 ar
->scan
.aborting
= true;
2078 spin_unlock_bh(&ar
->data_lock
);
2080 ret
= ath10k_wmi_stop_scan(ar
, &arg
);
2082 ath10k_warn("could not submit wmi stop scan (%d)\n", ret
);
2083 spin_lock_bh(&ar
->data_lock
);
2084 ar
->scan
.in_progress
= false;
2085 ath10k_offchan_tx_purge(ar
);
2086 spin_unlock_bh(&ar
->data_lock
);
2090 ret
= wait_for_completion_timeout(&ar
->scan
.completed
, 3*HZ
);
2092 ath10k_warn("timed out while waiting for scan to stop\n");
2094 /* scan completion may be done right after we timeout here, so let's
2095 * check the in_progress and tell mac80211 scan is completed. if we
2096 * don't do that and FW fails to send us scan completion indication
2097 * then userspace won't be able to scan anymore */
2100 spin_lock_bh(&ar
->data_lock
);
2101 if (ar
->scan
.in_progress
) {
2102 ath10k_warn("could not stop scan. its still in progress\n");
2103 ar
->scan
.in_progress
= false;
2104 ath10k_offchan_tx_purge(ar
);
2107 spin_unlock_bh(&ar
->data_lock
);
2112 static int ath10k_start_scan(struct ath10k
*ar
,
2113 const struct wmi_start_scan_arg
*arg
)
2117 lockdep_assert_held(&ar
->conf_mutex
);
2119 ret
= ath10k_wmi_start_scan(ar
, arg
);
2123 ret
= wait_for_completion_timeout(&ar
->scan
.started
, 1*HZ
);
2125 ath10k_abort_scan(ar
);
2129 /* the scan can complete earlier, before we even
2130 * start the timer. in that case the timer handler
2131 * checks ar->scan.in_progress and bails out if its
2132 * false. Add a 200ms margin to account event/command
2134 mod_timer(&ar
->scan
.timeout
, jiffies
+
2135 msecs_to_jiffies(arg
->max_scan_time
+200));
2139 /**********************/
2140 /* mac80211 callbacks */
2141 /**********************/
2143 static void ath10k_tx(struct ieee80211_hw
*hw
,
2144 struct ieee80211_tx_control
*control
,
2145 struct sk_buff
*skb
)
2147 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2148 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2149 struct ath10k
*ar
= hw
->priv
;
2152 /* We should disable CCK RATE due to P2P */
2153 if (info
->flags
& IEEE80211_TX_CTL_NO_CCK_RATE
)
2154 ath10k_dbg(ATH10K_DBG_MAC
, "IEEE80211_TX_CTL_NO_CCK_RATE\n");
2156 /* we must calculate tid before we apply qos workaround
2157 * as we'd lose the qos control field */
2158 tid
= ath10k_tx_h_get_tid(hdr
);
2159 vdev_id
= ath10k_tx_h_get_vdev_id(ar
, info
);
2161 /* it makes no sense to process injected frames like that */
2162 if (info
->control
.vif
&&
2163 info
->control
.vif
->type
!= NL80211_IFTYPE_MONITOR
) {
2164 ath10k_tx_h_qos_workaround(hw
, control
, skb
);
2165 ath10k_tx_h_update_wep_key(skb
);
2166 ath10k_tx_h_add_p2p_noa_ie(ar
, skb
);
2167 ath10k_tx_h_seq_no(skb
);
2170 ATH10K_SKB_CB(skb
)->vdev_id
= vdev_id
;
2171 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= false;
2172 ATH10K_SKB_CB(skb
)->htt
.tid
= tid
;
2174 if (info
->flags
& IEEE80211_TX_CTL_TX_OFFCHAN
) {
2175 spin_lock_bh(&ar
->data_lock
);
2176 ATH10K_SKB_CB(skb
)->htt
.is_offchan
= true;
2177 ATH10K_SKB_CB(skb
)->vdev_id
= ar
->scan
.vdev_id
;
2178 spin_unlock_bh(&ar
->data_lock
);
2180 ath10k_dbg(ATH10K_DBG_MAC
, "queued offchannel skb %p\n", skb
);
2182 skb_queue_tail(&ar
->offchan_tx_queue
, skb
);
2183 ieee80211_queue_work(hw
, &ar
->offchan_tx_work
);
2187 ath10k_tx_htt(ar
, skb
);
2191 * Initialize various parameters with default vaules.
2193 void ath10k_halt(struct ath10k
*ar
)
2195 lockdep_assert_held(&ar
->conf_mutex
);
2197 ath10k_stop_cac(ar
);
2198 del_timer_sync(&ar
->scan
.timeout
);
2199 ath10k_offchan_tx_purge(ar
);
2200 ath10k_mgmt_over_wmi_tx_purge(ar
);
2201 ath10k_peer_cleanup_all(ar
);
2202 ath10k_core_stop(ar
);
2203 ath10k_hif_power_down(ar
);
2205 spin_lock_bh(&ar
->data_lock
);
2206 if (ar
->scan
.in_progress
) {
2207 del_timer(&ar
->scan
.timeout
);
2208 ar
->scan
.in_progress
= false;
2209 ieee80211_scan_completed(ar
->hw
, true);
2211 spin_unlock_bh(&ar
->data_lock
);
2214 static int ath10k_start(struct ieee80211_hw
*hw
)
2216 struct ath10k
*ar
= hw
->priv
;
2219 mutex_lock(&ar
->conf_mutex
);
2221 if (ar
->state
!= ATH10K_STATE_OFF
&&
2222 ar
->state
!= ATH10K_STATE_RESTARTING
) {
2227 ret
= ath10k_hif_power_up(ar
);
2229 ath10k_err("could not init hif (%d)\n", ret
);
2230 ar
->state
= ATH10K_STATE_OFF
;
2234 ret
= ath10k_core_start(ar
);
2236 ath10k_err("could not init core (%d)\n", ret
);
2237 ath10k_hif_power_down(ar
);
2238 ar
->state
= ATH10K_STATE_OFF
;
2242 if (ar
->state
== ATH10K_STATE_OFF
)
2243 ar
->state
= ATH10K_STATE_ON
;
2244 else if (ar
->state
== ATH10K_STATE_RESTARTING
)
2245 ar
->state
= ATH10K_STATE_RESTARTED
;
2247 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->pmf_qos
, 1);
2249 ath10k_warn("could not enable WMI_PDEV_PARAM_PMF_QOS (%d)\n",
2252 ret
= ath10k_wmi_pdev_set_param(ar
, ar
->wmi
.pdev_param
->dynamic_bw
, 1);
2254 ath10k_warn("could not init WMI_PDEV_PARAM_DYNAMIC_BW (%d)\n",
2258 * By default FW set ARP frames ac to voice (6). In that case ARP
2259 * exchange is not working properly for UAPSD enabled AP. ARP requests
2260 * which arrives with access category 0 are processed by network stack
2261 * and send back with access category 0, but FW changes access category
2262 * to 6. Set ARP frames access category to best effort (0) solves
2266 ret
= ath10k_wmi_pdev_set_param(ar
,
2267 ar
->wmi
.pdev_param
->arp_ac_override
, 0);
2269 ath10k_warn("could not set arp ac override parameter: %d\n",
2274 ath10k_regd_update(ar
);
2278 mutex_unlock(&ar
->conf_mutex
);
2282 static void ath10k_stop(struct ieee80211_hw
*hw
)
2284 struct ath10k
*ar
= hw
->priv
;
2286 mutex_lock(&ar
->conf_mutex
);
2287 if (ar
->state
== ATH10K_STATE_ON
||
2288 ar
->state
== ATH10K_STATE_RESTARTED
||
2289 ar
->state
== ATH10K_STATE_WEDGED
)
2292 ar
->state
= ATH10K_STATE_OFF
;
2293 mutex_unlock(&ar
->conf_mutex
);
2295 ath10k_mgmt_over_wmi_tx_purge(ar
);
2297 cancel_work_sync(&ar
->offchan_tx_work
);
2298 cancel_work_sync(&ar
->wmi_mgmt_tx_work
);
2299 cancel_work_sync(&ar
->restart_work
);
2302 static int ath10k_config_ps(struct ath10k
*ar
)
2304 struct ath10k_vif
*arvif
;
2307 lockdep_assert_held(&ar
->conf_mutex
);
2309 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2310 ret
= ath10k_mac_vif_setup_ps(arvif
);
2312 ath10k_warn("could not setup powersave (%d)\n", ret
);
2320 static const char *chandef_get_width(enum nl80211_chan_width width
)
2323 case NL80211_CHAN_WIDTH_20_NOHT
:
2325 case NL80211_CHAN_WIDTH_20
:
2327 case NL80211_CHAN_WIDTH_40
:
2329 case NL80211_CHAN_WIDTH_80
:
2331 case NL80211_CHAN_WIDTH_80P80
:
2333 case NL80211_CHAN_WIDTH_160
:
2335 case NL80211_CHAN_WIDTH_5
:
2337 case NL80211_CHAN_WIDTH_10
:
2343 static void ath10k_config_chan(struct ath10k
*ar
)
2345 struct ath10k_vif
*arvif
;
2346 bool monitor_was_enabled
;
2349 lockdep_assert_held(&ar
->conf_mutex
);
2351 ath10k_dbg(ATH10K_DBG_MAC
,
2352 "mac config channel to %dMHz (cf1 %dMHz cf2 %dMHz width %s)\n",
2353 ar
->chandef
.chan
->center_freq
,
2354 ar
->chandef
.center_freq1
,
2355 ar
->chandef
.center_freq2
,
2356 chandef_get_width(ar
->chandef
.width
));
2358 /* First stop monitor interface. Some FW versions crash if there's a
2359 * lone monitor interface. */
2360 monitor_was_enabled
= ar
->monitor_enabled
;
2362 if (ar
->monitor_enabled
)
2363 ath10k_monitor_stop(ar
);
2365 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2366 if (!arvif
->is_started
)
2369 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2372 ret
= ath10k_vdev_stop(arvif
);
2374 ath10k_warn("could not stop vdev %d (%d)\n",
2375 arvif
->vdev_id
, ret
);
2380 /* all vdevs are now stopped - now attempt to restart them */
2382 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
2383 if (!arvif
->is_started
)
2386 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2389 ret
= ath10k_vdev_start(arvif
);
2391 ath10k_warn("could not start vdev %d (%d)\n",
2392 arvif
->vdev_id
, ret
);
2399 ret
= ath10k_wmi_vdev_up(arvif
->ar
, arvif
->vdev_id
, arvif
->aid
,
2402 ath10k_warn("could not bring vdev up %d (%d)\n",
2403 arvif
->vdev_id
, ret
);
2408 if (monitor_was_enabled
)
2409 ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
2412 static int ath10k_config(struct ieee80211_hw
*hw
, u32 changed
)
2414 struct ath10k
*ar
= hw
->priv
;
2415 struct ieee80211_conf
*conf
= &hw
->conf
;
2419 mutex_lock(&ar
->conf_mutex
);
2421 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2422 ath10k_dbg(ATH10K_DBG_MAC
,
2423 "mac config channel %d mhz flags 0x%x\n",
2424 conf
->chandef
.chan
->center_freq
,
2425 conf
->chandef
.chan
->flags
);
2427 spin_lock_bh(&ar
->data_lock
);
2428 ar
->rx_channel
= conf
->chandef
.chan
;
2429 spin_unlock_bh(&ar
->data_lock
);
2431 ath10k_config_radar_detection(ar
);
2433 if (!cfg80211_chandef_identical(&ar
->chandef
, &conf
->chandef
)) {
2434 ar
->chandef
= conf
->chandef
;
2435 ath10k_config_chan(ar
);
2439 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
2440 ath10k_dbg(ATH10K_DBG_MAC
, "mac config power %d\n",
2441 hw
->conf
.power_level
);
2443 param
= ar
->wmi
.pdev_param
->txpower_limit2g
;
2444 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2445 hw
->conf
.power_level
* 2);
2447 ath10k_warn("mac failed to set 2g txpower %d (%d)\n",
2448 hw
->conf
.power_level
, ret
);
2450 param
= ar
->wmi
.pdev_param
->txpower_limit5g
;
2451 ret
= ath10k_wmi_pdev_set_param(ar
, param
,
2452 hw
->conf
.power_level
* 2);
2454 ath10k_warn("mac failed to set 5g txpower %d (%d)\n",
2455 hw
->conf
.power_level
, ret
);
2458 if (changed
& IEEE80211_CONF_CHANGE_PS
)
2459 ath10k_config_ps(ar
);
2461 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
2462 if (conf
->flags
& IEEE80211_CONF_MONITOR
)
2463 ret
= ath10k_monitor_create(ar
);
2465 ret
= ath10k_monitor_destroy(ar
);
2468 mutex_unlock(&ar
->conf_mutex
);
2474 * Figure out how to handle WMI_VDEV_SUBTYPE_P2P_DEVICE,
2475 * because we will send mgmt frames without CCK. This requirement
2476 * for P2P_FIND/GO_NEG should be handled by checking CCK flag
2479 static int ath10k_add_interface(struct ieee80211_hw
*hw
,
2480 struct ieee80211_vif
*vif
)
2482 struct ath10k
*ar
= hw
->priv
;
2483 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2484 enum wmi_sta_powersave_param param
;
2490 mutex_lock(&ar
->conf_mutex
);
2492 memset(arvif
, 0, sizeof(*arvif
));
2497 INIT_WORK(&arvif
->wep_key_work
, ath10k_tx_wep_key_work
);
2498 INIT_LIST_HEAD(&arvif
->list
);
2500 if ((vif
->type
== NL80211_IFTYPE_MONITOR
) && ar
->monitor_present
) {
2501 ath10k_warn("Only one monitor interface allowed\n");
2506 bit
= ffs(ar
->free_vdev_map
);
2512 arvif
->vdev_id
= bit
- 1;
2513 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_NONE
;
2516 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_DEVICE
;
2518 switch (vif
->type
) {
2519 case NL80211_IFTYPE_UNSPECIFIED
:
2520 case NL80211_IFTYPE_STATION
:
2521 arvif
->vdev_type
= WMI_VDEV_TYPE_STA
;
2523 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_CLIENT
;
2525 case NL80211_IFTYPE_ADHOC
:
2526 arvif
->vdev_type
= WMI_VDEV_TYPE_IBSS
;
2528 case NL80211_IFTYPE_AP
:
2529 arvif
->vdev_type
= WMI_VDEV_TYPE_AP
;
2532 arvif
->vdev_subtype
= WMI_VDEV_SUBTYPE_P2P_GO
;
2534 case NL80211_IFTYPE_MONITOR
:
2535 arvif
->vdev_type
= WMI_VDEV_TYPE_MONITOR
;
2542 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev create %d (add interface) type %d subtype %d\n",
2543 arvif
->vdev_id
, arvif
->vdev_type
, arvif
->vdev_subtype
);
2545 ret
= ath10k_wmi_vdev_create(ar
, arvif
->vdev_id
, arvif
->vdev_type
,
2546 arvif
->vdev_subtype
, vif
->addr
);
2548 ath10k_warn("WMI vdev %i create failed: ret %d\n",
2549 arvif
->vdev_id
, ret
);
2553 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2554 list_add(&arvif
->list
, &ar
->arvifs
);
2556 vdev_param
= ar
->wmi
.vdev_param
->def_keyid
;
2557 ret
= ath10k_wmi_vdev_set_param(ar
, 0, vdev_param
,
2558 arvif
->def_wep_key_idx
);
2560 ath10k_warn("Failed to set vdev %i default keyid: %d\n",
2561 arvif
->vdev_id
, ret
);
2562 goto err_vdev_delete
;
2565 vdev_param
= ar
->wmi
.vdev_param
->tx_encap_type
;
2566 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2567 ATH10K_HW_TXRX_NATIVE_WIFI
);
2568 /* 10.X firmware does not support this VDEV parameter. Do not warn */
2569 if (ret
&& ret
!= -EOPNOTSUPP
) {
2570 ath10k_warn("Failed to set vdev %i TX encap: %d\n",
2571 arvif
->vdev_id
, ret
);
2572 goto err_vdev_delete
;
2575 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2576 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, vif
->addr
);
2578 ath10k_warn("Failed to create vdev %i peer for AP: %d\n",
2579 arvif
->vdev_id
, ret
);
2580 goto err_vdev_delete
;
2583 ret
= ath10k_mac_set_kickout(arvif
);
2585 ath10k_warn("Failed to set vdev %i kickout parameters: %d\n",
2586 arvif
->vdev_id
, ret
);
2587 goto err_peer_delete
;
2591 if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
) {
2592 param
= WMI_STA_PS_PARAM_RX_WAKE_POLICY
;
2593 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
2594 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2597 ath10k_warn("Failed to set vdev %i RX wake policy: %d\n",
2598 arvif
->vdev_id
, ret
);
2599 goto err_peer_delete
;
2602 param
= WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD
;
2603 value
= WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS
;
2604 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2607 ath10k_warn("Failed to set vdev %i TX wake thresh: %d\n",
2608 arvif
->vdev_id
, ret
);
2609 goto err_peer_delete
;
2612 param
= WMI_STA_PS_PARAM_PSPOLL_COUNT
;
2613 value
= WMI_STA_PS_PSPOLL_COUNT_NO_MAX
;
2614 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
2617 ath10k_warn("Failed to set vdev %i PSPOLL count: %d\n",
2618 arvif
->vdev_id
, ret
);
2619 goto err_peer_delete
;
2623 ret
= ath10k_mac_set_rts(arvif
, ar
->hw
->wiphy
->rts_threshold
);
2625 ath10k_warn("failed to set rts threshold for vdev %d (%d)\n",
2626 arvif
->vdev_id
, ret
);
2627 goto err_peer_delete
;
2630 ret
= ath10k_mac_set_frag(arvif
, ar
->hw
->wiphy
->frag_threshold
);
2632 ath10k_warn("failed to set frag threshold for vdev %d (%d)\n",
2633 arvif
->vdev_id
, ret
);
2634 goto err_peer_delete
;
2637 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2638 ar
->monitor_present
= true;
2640 mutex_unlock(&ar
->conf_mutex
);
2644 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
)
2645 ath10k_wmi_peer_delete(ar
, arvif
->vdev_id
, vif
->addr
);
2648 ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2649 ar
->free_vdev_map
&= ~BIT(arvif
->vdev_id
);
2650 list_del(&arvif
->list
);
2653 mutex_unlock(&ar
->conf_mutex
);
2658 static void ath10k_remove_interface(struct ieee80211_hw
*hw
,
2659 struct ieee80211_vif
*vif
)
2661 struct ath10k
*ar
= hw
->priv
;
2662 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2665 mutex_lock(&ar
->conf_mutex
);
2667 cancel_work_sync(&arvif
->wep_key_work
);
2669 spin_lock_bh(&ar
->data_lock
);
2670 if (arvif
->beacon
) {
2671 dev_kfree_skb_any(arvif
->beacon
);
2672 arvif
->beacon
= NULL
;
2674 spin_unlock_bh(&ar
->data_lock
);
2676 ar
->free_vdev_map
|= 1 << (arvif
->vdev_id
);
2677 list_del(&arvif
->list
);
2679 if (arvif
->vdev_type
== WMI_VDEV_TYPE_AP
) {
2680 ret
= ath10k_peer_delete(arvif
->ar
, arvif
->vdev_id
, vif
->addr
);
2682 ath10k_warn("Failed to remove peer for AP vdev %i: %d\n",
2683 arvif
->vdev_id
, ret
);
2685 kfree(arvif
->u
.ap
.noa_data
);
2688 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %i delete (remove interface)\n",
2691 ret
= ath10k_wmi_vdev_delete(ar
, arvif
->vdev_id
);
2693 ath10k_warn("WMI vdev %i delete failed: %d\n",
2694 arvif
->vdev_id
, ret
);
2696 if (arvif
->vdev_type
== WMI_VDEV_TYPE_MONITOR
)
2697 ar
->monitor_present
= false;
2699 ath10k_peer_cleanup(ar
, arvif
->vdev_id
);
2701 mutex_unlock(&ar
->conf_mutex
);
2705 * FIXME: Has to be verified.
2707 #define SUPPORTED_FILTERS \
2708 (FIF_PROMISC_IN_BSS | \
2713 FIF_BCN_PRBRESP_PROMISC | \
2717 static void ath10k_configure_filter(struct ieee80211_hw
*hw
,
2718 unsigned int changed_flags
,
2719 unsigned int *total_flags
,
2722 struct ath10k
*ar
= hw
->priv
;
2725 mutex_lock(&ar
->conf_mutex
);
2727 changed_flags
&= SUPPORTED_FILTERS
;
2728 *total_flags
&= SUPPORTED_FILTERS
;
2729 ar
->filter_flags
= *total_flags
;
2731 /* Monitor must not be started if it wasn't created first.
2732 * Promiscuous mode may be started on a non-monitor interface - in
2733 * such case the monitor vdev is not created so starting the
2734 * monitor makes no sense. Since ath10k uses no special RX filters
2735 * (only BSS filter in STA mode) there's no need for any special
2737 if ((ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2738 !ar
->monitor_enabled
&& ar
->monitor_present
) {
2739 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d start\n",
2740 ar
->monitor_vdev_id
);
2742 ret
= ath10k_monitor_start(ar
, ar
->monitor_vdev_id
);
2744 ath10k_warn("Unable to start monitor mode\n");
2745 } else if (!(ar
->filter_flags
& FIF_PROMISC_IN_BSS
) &&
2746 ar
->monitor_enabled
&& ar
->monitor_present
) {
2747 ath10k_dbg(ATH10K_DBG_MAC
, "mac monitor %d stop\n",
2748 ar
->monitor_vdev_id
);
2750 ret
= ath10k_monitor_stop(ar
);
2752 ath10k_warn("Unable to stop monitor mode\n");
2755 mutex_unlock(&ar
->conf_mutex
);
2758 static void ath10k_bss_info_changed(struct ieee80211_hw
*hw
,
2759 struct ieee80211_vif
*vif
,
2760 struct ieee80211_bss_conf
*info
,
2763 struct ath10k
*ar
= hw
->priv
;
2764 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2766 u32 vdev_param
, pdev_param
;
2768 mutex_lock(&ar
->conf_mutex
);
2770 if (changed
& BSS_CHANGED_IBSS
)
2771 ath10k_control_ibss(arvif
, info
, vif
->addr
);
2773 if (changed
& BSS_CHANGED_BEACON_INT
) {
2774 arvif
->beacon_interval
= info
->beacon_int
;
2775 vdev_param
= ar
->wmi
.vdev_param
->beacon_interval
;
2776 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2777 arvif
->beacon_interval
);
2778 ath10k_dbg(ATH10K_DBG_MAC
,
2779 "mac vdev %d beacon_interval %d\n",
2780 arvif
->vdev_id
, arvif
->beacon_interval
);
2783 ath10k_warn("Failed to set beacon interval for vdev %d: %i\n",
2784 arvif
->vdev_id
, ret
);
2787 if (changed
& BSS_CHANGED_BEACON
) {
2788 ath10k_dbg(ATH10K_DBG_MAC
,
2789 "vdev %d set beacon tx mode to staggered\n",
2792 pdev_param
= ar
->wmi
.pdev_param
->beacon_tx_mode
;
2793 ret
= ath10k_wmi_pdev_set_param(ar
, pdev_param
,
2794 WMI_BEACON_STAGGERED_MODE
);
2796 ath10k_warn("Failed to set beacon mode for vdev %d: %i\n",
2797 arvif
->vdev_id
, ret
);
2800 if (changed
& BSS_CHANGED_BEACON_INFO
) {
2801 arvif
->dtim_period
= info
->dtim_period
;
2803 ath10k_dbg(ATH10K_DBG_MAC
,
2804 "mac vdev %d dtim_period %d\n",
2805 arvif
->vdev_id
, arvif
->dtim_period
);
2807 vdev_param
= ar
->wmi
.vdev_param
->dtim_period
;
2808 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2809 arvif
->dtim_period
);
2811 ath10k_warn("Failed to set dtim period for vdev %d: %i\n",
2812 arvif
->vdev_id
, ret
);
2815 if (changed
& BSS_CHANGED_SSID
&&
2816 vif
->type
== NL80211_IFTYPE_AP
) {
2817 arvif
->u
.ap
.ssid_len
= info
->ssid_len
;
2819 memcpy(arvif
->u
.ap
.ssid
, info
->ssid
, info
->ssid_len
);
2820 arvif
->u
.ap
.hidden_ssid
= info
->hidden_ssid
;
2823 if (changed
& BSS_CHANGED_BSSID
) {
2824 if (!is_zero_ether_addr(info
->bssid
)) {
2825 ath10k_dbg(ATH10K_DBG_MAC
,
2826 "mac vdev %d create peer %pM\n",
2827 arvif
->vdev_id
, info
->bssid
);
2829 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
,
2832 ath10k_warn("Failed to add peer %pM for vdev %d when changing bssid: %i\n",
2833 info
->bssid
, arvif
->vdev_id
, ret
);
2835 if (vif
->type
== NL80211_IFTYPE_STATION
) {
2837 * this is never erased as we it for crypto key
2838 * clearing; this is FW requirement
2840 memcpy(arvif
->bssid
, info
->bssid
, ETH_ALEN
);
2842 ath10k_dbg(ATH10K_DBG_MAC
,
2843 "mac vdev %d start %pM\n",
2844 arvif
->vdev_id
, info
->bssid
);
2846 ret
= ath10k_vdev_start(arvif
);
2848 ath10k_warn("failed to start vdev %i: %d\n",
2849 arvif
->vdev_id
, ret
);
2853 arvif
->is_started
= true;
2857 * Mac80211 does not keep IBSS bssid when leaving IBSS,
2858 * so driver need to store it. It is needed when leaving
2859 * IBSS in order to remove BSSID peer.
2861 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
2862 memcpy(arvif
->bssid
, info
->bssid
,
2867 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
2868 ath10k_control_beaconing(arvif
, info
);
2870 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
2872 if (info
->use_cts_prot
)
2877 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d cts_prot %d\n",
2878 arvif
->vdev_id
, cts_prot
);
2880 vdev_param
= ar
->wmi
.vdev_param
->enable_rtscts
;
2881 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2884 ath10k_warn("Failed to set CTS prot for vdev %d: %d\n",
2885 arvif
->vdev_id
, ret
);
2888 if (changed
& BSS_CHANGED_ERP_SLOT
) {
2890 if (info
->use_short_slot
)
2891 slottime
= WMI_VDEV_SLOT_TIME_SHORT
; /* 9us */
2894 slottime
= WMI_VDEV_SLOT_TIME_LONG
; /* 20us */
2896 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d slot_time %d\n",
2897 arvif
->vdev_id
, slottime
);
2899 vdev_param
= ar
->wmi
.vdev_param
->slot_time
;
2900 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2903 ath10k_warn("Failed to set erp slot for vdev %d: %i\n",
2904 arvif
->vdev_id
, ret
);
2907 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
2909 if (info
->use_short_preamble
)
2910 preamble
= WMI_VDEV_PREAMBLE_SHORT
;
2912 preamble
= WMI_VDEV_PREAMBLE_LONG
;
2914 ath10k_dbg(ATH10K_DBG_MAC
,
2915 "mac vdev %d preamble %dn",
2916 arvif
->vdev_id
, preamble
);
2918 vdev_param
= ar
->wmi
.vdev_param
->preamble
;
2919 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
2922 ath10k_warn("Failed to set preamble for vdev %d: %i\n",
2923 arvif
->vdev_id
, ret
);
2926 if (changed
& BSS_CHANGED_ASSOC
) {
2928 ath10k_bss_assoc(hw
, vif
, info
);
2932 mutex_unlock(&ar
->conf_mutex
);
2935 static int ath10k_hw_scan(struct ieee80211_hw
*hw
,
2936 struct ieee80211_vif
*vif
,
2937 struct cfg80211_scan_request
*req
)
2939 struct ath10k
*ar
= hw
->priv
;
2940 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
2941 struct wmi_start_scan_arg arg
;
2945 mutex_lock(&ar
->conf_mutex
);
2947 spin_lock_bh(&ar
->data_lock
);
2948 if (ar
->scan
.in_progress
) {
2949 spin_unlock_bh(&ar
->data_lock
);
2954 reinit_completion(&ar
->scan
.started
);
2955 reinit_completion(&ar
->scan
.completed
);
2956 ar
->scan
.in_progress
= true;
2957 ar
->scan
.aborting
= false;
2958 ar
->scan
.is_roc
= false;
2959 ar
->scan
.vdev_id
= arvif
->vdev_id
;
2960 spin_unlock_bh(&ar
->data_lock
);
2962 memset(&arg
, 0, sizeof(arg
));
2963 ath10k_wmi_start_scan_init(ar
, &arg
);
2964 arg
.vdev_id
= arvif
->vdev_id
;
2965 arg
.scan_id
= ATH10K_SCAN_ID
;
2968 arg
.scan_ctrl_flags
|= WMI_SCAN_ADD_CCK_RATES
;
2971 arg
.ie_len
= req
->ie_len
;
2972 memcpy(arg
.ie
, req
->ie
, arg
.ie_len
);
2976 arg
.n_ssids
= req
->n_ssids
;
2977 for (i
= 0; i
< arg
.n_ssids
; i
++) {
2978 arg
.ssids
[i
].len
= req
->ssids
[i
].ssid_len
;
2979 arg
.ssids
[i
].ssid
= req
->ssids
[i
].ssid
;
2982 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
2985 if (req
->n_channels
) {
2986 arg
.n_channels
= req
->n_channels
;
2987 for (i
= 0; i
< arg
.n_channels
; i
++)
2988 arg
.channels
[i
] = req
->channels
[i
]->center_freq
;
2991 ret
= ath10k_start_scan(ar
, &arg
);
2993 ath10k_warn("could not start hw scan (%d)\n", ret
);
2994 spin_lock_bh(&ar
->data_lock
);
2995 ar
->scan
.in_progress
= false;
2996 spin_unlock_bh(&ar
->data_lock
);
3000 mutex_unlock(&ar
->conf_mutex
);
3004 static void ath10k_cancel_hw_scan(struct ieee80211_hw
*hw
,
3005 struct ieee80211_vif
*vif
)
3007 struct ath10k
*ar
= hw
->priv
;
3010 mutex_lock(&ar
->conf_mutex
);
3011 ret
= ath10k_abort_scan(ar
);
3013 ath10k_warn("couldn't abort scan (%d). forcefully sending scan completion to mac80211\n",
3015 ieee80211_scan_completed(hw
, 1 /* aborted */);
3017 mutex_unlock(&ar
->conf_mutex
);
3020 static void ath10k_set_key_h_def_keyidx(struct ath10k
*ar
,
3021 struct ath10k_vif
*arvif
,
3022 enum set_key_cmd cmd
,
3023 struct ieee80211_key_conf
*key
)
3025 u32 vdev_param
= arvif
->ar
->wmi
.vdev_param
->def_keyid
;
3028 /* 10.1 firmware branch requires default key index to be set to group
3029 * key index after installing it. Otherwise FW/HW Txes corrupted
3030 * frames with multi-vif APs. This is not required for main firmware
3031 * branch (e.g. 636).
3033 * FIXME: This has been tested only in AP. It remains unknown if this
3034 * is required for multi-vif STA interfaces on 10.1 */
3036 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_AP
)
3039 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
)
3042 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
3045 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
3051 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3054 ath10k_warn("failed to set vdev %i group key as default key: %d\n",
3055 arvif
->vdev_id
, ret
);
3058 static int ath10k_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3059 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
3060 struct ieee80211_key_conf
*key
)
3062 struct ath10k
*ar
= hw
->priv
;
3063 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3064 struct ath10k_peer
*peer
;
3065 const u8
*peer_addr
;
3066 bool is_wep
= key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3067 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
;
3070 if (key
->keyidx
> WMI_MAX_KEY_INDEX
)
3073 mutex_lock(&ar
->conf_mutex
);
3076 peer_addr
= sta
->addr
;
3077 else if (arvif
->vdev_type
== WMI_VDEV_TYPE_STA
)
3078 peer_addr
= vif
->bss_conf
.bssid
;
3080 peer_addr
= vif
->addr
;
3082 key
->hw_key_idx
= key
->keyidx
;
3084 /* the peer should not disappear in mid-way (unless FW goes awry) since
3085 * we already hold conf_mutex. we just make sure its there now. */
3086 spin_lock_bh(&ar
->data_lock
);
3087 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3088 spin_unlock_bh(&ar
->data_lock
);
3091 if (cmd
== SET_KEY
) {
3092 ath10k_warn("cannot install key for non-existent peer %pM\n",
3097 /* if the peer doesn't exist there is no key to disable
3105 arvif
->wep_keys
[key
->keyidx
] = key
;
3107 arvif
->wep_keys
[key
->keyidx
] = NULL
;
3109 if (cmd
== DISABLE_KEY
)
3110 ath10k_clear_vdev_key(arvif
, key
);
3113 ret
= ath10k_install_key(arvif
, key
, cmd
, peer_addr
);
3115 ath10k_warn("key installation failed for vdev %i peer %pM: %d\n",
3116 arvif
->vdev_id
, peer_addr
, ret
);
3120 ath10k_set_key_h_def_keyidx(ar
, arvif
, cmd
, key
);
3122 spin_lock_bh(&ar
->data_lock
);
3123 peer
= ath10k_peer_find(ar
, arvif
->vdev_id
, peer_addr
);
3124 if (peer
&& cmd
== SET_KEY
)
3125 peer
->keys
[key
->keyidx
] = key
;
3126 else if (peer
&& cmd
== DISABLE_KEY
)
3127 peer
->keys
[key
->keyidx
] = NULL
;
3128 else if (peer
== NULL
)
3129 /* impossible unless FW goes crazy */
3130 ath10k_warn("peer %pM disappeared!\n", peer_addr
);
3131 spin_unlock_bh(&ar
->data_lock
);
3134 mutex_unlock(&ar
->conf_mutex
);
3138 static void ath10k_sta_rc_update_wk(struct work_struct
*wk
)
3141 struct ath10k_vif
*arvif
;
3142 struct ath10k_sta
*arsta
;
3143 struct ieee80211_sta
*sta
;
3144 u32 changed
, bw
, nss
, smps
;
3147 arsta
= container_of(wk
, struct ath10k_sta
, update_wk
);
3148 sta
= container_of((void *)arsta
, struct ieee80211_sta
, drv_priv
);
3149 arvif
= arsta
->arvif
;
3152 spin_lock_bh(&ar
->data_lock
);
3154 changed
= arsta
->changed
;
3161 spin_unlock_bh(&ar
->data_lock
);
3163 mutex_lock(&ar
->conf_mutex
);
3165 if (changed
& IEEE80211_RC_BW_CHANGED
) {
3166 ath10k_dbg(ATH10K_DBG_MAC
, "mac update sta %pM peer bw %d\n",
3169 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3170 WMI_PEER_CHAN_WIDTH
, bw
);
3172 ath10k_warn("failed to update STA %pM peer bw %d: %d\n",
3173 sta
->addr
, bw
, err
);
3176 if (changed
& IEEE80211_RC_NSS_CHANGED
) {
3177 ath10k_dbg(ATH10K_DBG_MAC
, "mac update sta %pM nss %d\n",
3180 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3183 ath10k_warn("failed to update STA %pM nss %d: %d\n",
3184 sta
->addr
, nss
, err
);
3187 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
3188 ath10k_dbg(ATH10K_DBG_MAC
, "mac update sta %pM smps %d\n",
3191 err
= ath10k_wmi_peer_set_param(ar
, arvif
->vdev_id
, sta
->addr
,
3192 WMI_PEER_SMPS_STATE
, smps
);
3194 ath10k_warn("failed to update STA %pM smps %d: %d\n",
3195 sta
->addr
, smps
, err
);
3198 mutex_unlock(&ar
->conf_mutex
);
3201 static int ath10k_sta_state(struct ieee80211_hw
*hw
,
3202 struct ieee80211_vif
*vif
,
3203 struct ieee80211_sta
*sta
,
3204 enum ieee80211_sta_state old_state
,
3205 enum ieee80211_sta_state new_state
)
3207 struct ath10k
*ar
= hw
->priv
;
3208 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3209 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
3213 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3214 new_state
== IEEE80211_STA_NONE
) {
3215 memset(arsta
, 0, sizeof(*arsta
));
3216 arsta
->arvif
= arvif
;
3217 INIT_WORK(&arsta
->update_wk
, ath10k_sta_rc_update_wk
);
3220 /* cancel must be done outside the mutex to avoid deadlock */
3221 if ((old_state
== IEEE80211_STA_NONE
&&
3222 new_state
== IEEE80211_STA_NOTEXIST
))
3223 cancel_work_sync(&arsta
->update_wk
);
3225 mutex_lock(&ar
->conf_mutex
);
3227 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3228 new_state
== IEEE80211_STA_NONE
&&
3229 vif
->type
!= NL80211_IFTYPE_STATION
) {
3231 * New station addition.
3233 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
))
3234 max_num_peers
= TARGET_10X_NUM_PEERS_MAX
- 1;
3236 max_num_peers
= TARGET_NUM_PEERS
;
3238 if (ar
->num_peers
>= max_num_peers
) {
3239 ath10k_warn("Number of peers exceeded: peers number %d (max peers %d)\n",
3240 ar
->num_peers
, max_num_peers
);
3245 ath10k_dbg(ATH10K_DBG_MAC
,
3246 "mac vdev %d peer create %pM (new sta) num_peers %d\n",
3247 arvif
->vdev_id
, sta
->addr
, ar
->num_peers
);
3249 ret
= ath10k_peer_create(ar
, arvif
->vdev_id
, sta
->addr
);
3251 ath10k_warn("Failed to add peer %pM for vdev %d when adding a new sta: %i\n",
3252 sta
->addr
, arvif
->vdev_id
, ret
);
3253 } else if ((old_state
== IEEE80211_STA_NONE
&&
3254 new_state
== IEEE80211_STA_NOTEXIST
)) {
3256 * Existing station deletion.
3258 ath10k_dbg(ATH10K_DBG_MAC
,
3259 "mac vdev %d peer delete %pM (sta gone)\n",
3260 arvif
->vdev_id
, sta
->addr
);
3261 ret
= ath10k_peer_delete(ar
, arvif
->vdev_id
, sta
->addr
);
3263 ath10k_warn("Failed to delete peer %pM for vdev %d: %i\n",
3264 sta
->addr
, arvif
->vdev_id
, ret
);
3266 if (vif
->type
== NL80211_IFTYPE_STATION
)
3267 ath10k_bss_disassoc(hw
, vif
);
3268 } else if (old_state
== IEEE80211_STA_AUTH
&&
3269 new_state
== IEEE80211_STA_ASSOC
&&
3270 (vif
->type
== NL80211_IFTYPE_AP
||
3271 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
3275 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM associated\n",
3278 ret
= ath10k_station_assoc(ar
, arvif
, sta
);
3280 ath10k_warn("Failed to associate station %pM for vdev %i: %i\n",
3281 sta
->addr
, arvif
->vdev_id
, ret
);
3282 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3283 new_state
== IEEE80211_STA_AUTH
&&
3284 (vif
->type
== NL80211_IFTYPE_AP
||
3285 vif
->type
== NL80211_IFTYPE_ADHOC
)) {
3289 ath10k_dbg(ATH10K_DBG_MAC
, "mac sta %pM disassociated\n",
3292 ret
= ath10k_station_disassoc(ar
, arvif
, sta
);
3294 ath10k_warn("Failed to disassociate station: %pM vdev %i ret %i\n",
3295 sta
->addr
, arvif
->vdev_id
, ret
);
3298 mutex_unlock(&ar
->conf_mutex
);
3302 static int ath10k_conf_tx_uapsd(struct ath10k
*ar
, struct ieee80211_vif
*vif
,
3303 u16 ac
, bool enable
)
3305 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3309 lockdep_assert_held(&ar
->conf_mutex
);
3311 if (arvif
->vdev_type
!= WMI_VDEV_TYPE_STA
)
3315 case IEEE80211_AC_VO
:
3316 value
= WMI_STA_PS_UAPSD_AC3_DELIVERY_EN
|
3317 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN
;
3319 case IEEE80211_AC_VI
:
3320 value
= WMI_STA_PS_UAPSD_AC2_DELIVERY_EN
|
3321 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN
;
3323 case IEEE80211_AC_BE
:
3324 value
= WMI_STA_PS_UAPSD_AC1_DELIVERY_EN
|
3325 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN
;
3327 case IEEE80211_AC_BK
:
3328 value
= WMI_STA_PS_UAPSD_AC0_DELIVERY_EN
|
3329 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN
;
3334 arvif
->u
.sta
.uapsd
|= value
;
3336 arvif
->u
.sta
.uapsd
&= ~value
;
3338 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3339 WMI_STA_PS_PARAM_UAPSD
,
3340 arvif
->u
.sta
.uapsd
);
3342 ath10k_warn("could not set uapsd params %d\n", ret
);
3346 if (arvif
->u
.sta
.uapsd
)
3347 value
= WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD
;
3349 value
= WMI_STA_PS_RX_WAKE_POLICY_WAKE
;
3351 ret
= ath10k_wmi_set_sta_ps_param(ar
, arvif
->vdev_id
,
3352 WMI_STA_PS_PARAM_RX_WAKE_POLICY
,
3355 ath10k_warn("could not set rx wake param %d\n", ret
);
3361 static int ath10k_conf_tx(struct ieee80211_hw
*hw
,
3362 struct ieee80211_vif
*vif
, u16 ac
,
3363 const struct ieee80211_tx_queue_params
*params
)
3365 struct ath10k
*ar
= hw
->priv
;
3366 struct wmi_wmm_params_arg
*p
= NULL
;
3369 mutex_lock(&ar
->conf_mutex
);
3372 case IEEE80211_AC_VO
:
3373 p
= &ar
->wmm_params
.ac_vo
;
3375 case IEEE80211_AC_VI
:
3376 p
= &ar
->wmm_params
.ac_vi
;
3378 case IEEE80211_AC_BE
:
3379 p
= &ar
->wmm_params
.ac_be
;
3381 case IEEE80211_AC_BK
:
3382 p
= &ar
->wmm_params
.ac_bk
;
3391 p
->cwmin
= params
->cw_min
;
3392 p
->cwmax
= params
->cw_max
;
3393 p
->aifs
= params
->aifs
;
3396 * The channel time duration programmed in the HW is in absolute
3397 * microseconds, while mac80211 gives the txop in units of
3400 p
->txop
= params
->txop
* 32;
3402 /* FIXME: FW accepts wmm params per hw, not per vif */
3403 ret
= ath10k_wmi_pdev_set_wmm_params(ar
, &ar
->wmm_params
);
3405 ath10k_warn("could not set wmm params %d\n", ret
);
3409 ret
= ath10k_conf_tx_uapsd(ar
, vif
, ac
, params
->uapsd
);
3411 ath10k_warn("could not set sta uapsd %d\n", ret
);
3414 mutex_unlock(&ar
->conf_mutex
);
3418 #define ATH10K_ROC_TIMEOUT_HZ (2*HZ)
3420 static int ath10k_remain_on_channel(struct ieee80211_hw
*hw
,
3421 struct ieee80211_vif
*vif
,
3422 struct ieee80211_channel
*chan
,
3424 enum ieee80211_roc_type type
)
3426 struct ath10k
*ar
= hw
->priv
;
3427 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
3428 struct wmi_start_scan_arg arg
;
3431 mutex_lock(&ar
->conf_mutex
);
3433 spin_lock_bh(&ar
->data_lock
);
3434 if (ar
->scan
.in_progress
) {
3435 spin_unlock_bh(&ar
->data_lock
);
3440 reinit_completion(&ar
->scan
.started
);
3441 reinit_completion(&ar
->scan
.completed
);
3442 reinit_completion(&ar
->scan
.on_channel
);
3443 ar
->scan
.in_progress
= true;
3444 ar
->scan
.aborting
= false;
3445 ar
->scan
.is_roc
= true;
3446 ar
->scan
.vdev_id
= arvif
->vdev_id
;
3447 ar
->scan
.roc_freq
= chan
->center_freq
;
3448 spin_unlock_bh(&ar
->data_lock
);
3450 memset(&arg
, 0, sizeof(arg
));
3451 ath10k_wmi_start_scan_init(ar
, &arg
);
3452 arg
.vdev_id
= arvif
->vdev_id
;
3453 arg
.scan_id
= ATH10K_SCAN_ID
;
3455 arg
.channels
[0] = chan
->center_freq
;
3456 arg
.dwell_time_active
= duration
;
3457 arg
.dwell_time_passive
= duration
;
3458 arg
.max_scan_time
= 2 * duration
;
3459 arg
.scan_ctrl_flags
|= WMI_SCAN_FLAG_PASSIVE
;
3460 arg
.scan_ctrl_flags
|= WMI_SCAN_FILTER_PROBE_REQ
;
3462 ret
= ath10k_start_scan(ar
, &arg
);
3464 ath10k_warn("could not start roc scan (%d)\n", ret
);
3465 spin_lock_bh(&ar
->data_lock
);
3466 ar
->scan
.in_progress
= false;
3467 spin_unlock_bh(&ar
->data_lock
);
3471 ret
= wait_for_completion_timeout(&ar
->scan
.on_channel
, 3*HZ
);
3473 ath10k_warn("could not switch to channel for roc scan\n");
3474 ath10k_abort_scan(ar
);
3481 mutex_unlock(&ar
->conf_mutex
);
3485 static int ath10k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
3487 struct ath10k
*ar
= hw
->priv
;
3489 mutex_lock(&ar
->conf_mutex
);
3490 ath10k_abort_scan(ar
);
3491 mutex_unlock(&ar
->conf_mutex
);
3497 * Both RTS and Fragmentation threshold are interface-specific
3498 * in ath10k, but device-specific in mac80211.
3501 static int ath10k_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3503 struct ath10k
*ar
= hw
->priv
;
3504 struct ath10k_vif
*arvif
;
3507 mutex_lock(&ar
->conf_mutex
);
3508 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3509 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d rts threshold %d\n",
3510 arvif
->vdev_id
, value
);
3512 ret
= ath10k_mac_set_rts(arvif
, value
);
3514 ath10k_warn("could not set rts threshold for vdev %d (%d)\n",
3515 arvif
->vdev_id
, ret
);
3519 mutex_unlock(&ar
->conf_mutex
);
3524 static int ath10k_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3526 struct ath10k
*ar
= hw
->priv
;
3527 struct ath10k_vif
*arvif
;
3530 mutex_lock(&ar
->conf_mutex
);
3531 list_for_each_entry(arvif
, &ar
->arvifs
, list
) {
3532 ath10k_dbg(ATH10K_DBG_MAC
, "mac vdev %d fragmentation threshold %d\n",
3533 arvif
->vdev_id
, value
);
3535 ret
= ath10k_mac_set_rts(arvif
, value
);
3537 ath10k_warn("could not set fragmentation threshold for vdev %d (%d)\n",
3538 arvif
->vdev_id
, ret
);
3542 mutex_unlock(&ar
->conf_mutex
);
3547 static void ath10k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
3549 struct ath10k
*ar
= hw
->priv
;
3553 /* mac80211 doesn't care if we really xmit queued frames or not
3554 * we'll collect those frames either way if we stop/delete vdevs */
3558 mutex_lock(&ar
->conf_mutex
);
3560 if (ar
->state
== ATH10K_STATE_WEDGED
)
3563 ret
= wait_event_timeout(ar
->htt
.empty_tx_wq
, ({
3566 spin_lock_bh(&ar
->htt
.tx_lock
);
3567 empty
= (ar
->htt
.num_pending_tx
== 0);
3568 spin_unlock_bh(&ar
->htt
.tx_lock
);
3570 skip
= (ar
->state
== ATH10K_STATE_WEDGED
);
3573 }), ATH10K_FLUSH_TIMEOUT_HZ
);
3575 if (ret
<= 0 || skip
)
3576 ath10k_warn("tx not flushed (skip %i ar-state %i): %i\n",
3577 skip
, ar
->state
, ret
);
3580 mutex_unlock(&ar
->conf_mutex
);
3583 /* TODO: Implement this function properly
3584 * For now it is needed to reply to Probe Requests in IBSS mode.
3585 * Propably we need this information from FW.
3587 static int ath10k_tx_last_beacon(struct ieee80211_hw
*hw
)
3593 static int ath10k_suspend(struct ieee80211_hw
*hw
,
3594 struct cfg80211_wowlan
*wowlan
)
3596 struct ath10k
*ar
= hw
->priv
;
3599 mutex_lock(&ar
->conf_mutex
);
3601 ret
= ath10k_wait_for_suspend(ar
, WMI_PDEV_SUSPEND
);
3603 if (ret
== -ETIMEDOUT
)
3609 ret
= ath10k_hif_suspend(ar
);
3611 ath10k_warn("could not suspend hif (%d)\n", ret
);
3618 ret
= ath10k_wmi_pdev_resume_target(ar
);
3620 ath10k_warn("could not resume target (%d)\n", ret
);
3624 mutex_unlock(&ar
->conf_mutex
);
3628 static int ath10k_resume(struct ieee80211_hw
*hw
)
3630 struct ath10k
*ar
= hw
->priv
;
3633 mutex_lock(&ar
->conf_mutex
);
3635 ret
= ath10k_hif_resume(ar
);
3637 ath10k_warn("could not resume hif (%d)\n", ret
);
3642 ret
= ath10k_wmi_pdev_resume_target(ar
);
3644 ath10k_warn("could not resume target (%d)\n", ret
);
3651 mutex_unlock(&ar
->conf_mutex
);
3656 static void ath10k_restart_complete(struct ieee80211_hw
*hw
)
3658 struct ath10k
*ar
= hw
->priv
;
3660 mutex_lock(&ar
->conf_mutex
);
3662 /* If device failed to restart it will be in a different state, e.g.
3663 * ATH10K_STATE_WEDGED */
3664 if (ar
->state
== ATH10K_STATE_RESTARTED
) {
3665 ath10k_info("device successfully recovered\n");
3666 ar
->state
= ATH10K_STATE_ON
;
3669 mutex_unlock(&ar
->conf_mutex
);
3672 static int ath10k_get_survey(struct ieee80211_hw
*hw
, int idx
,
3673 struct survey_info
*survey
)
3675 struct ath10k
*ar
= hw
->priv
;
3676 struct ieee80211_supported_band
*sband
;
3677 struct survey_info
*ar_survey
= &ar
->survey
[idx
];
3680 mutex_lock(&ar
->conf_mutex
);
3682 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
3683 if (sband
&& idx
>= sband
->n_channels
) {
3684 idx
-= sband
->n_channels
;
3689 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
3691 if (!sband
|| idx
>= sband
->n_channels
) {
3696 spin_lock_bh(&ar
->data_lock
);
3697 memcpy(survey
, ar_survey
, sizeof(*survey
));
3698 spin_unlock_bh(&ar
->data_lock
);
3700 survey
->channel
= &sband
->channels
[idx
];
3703 mutex_unlock(&ar
->conf_mutex
);
3707 /* Helper table for legacy fixed_rate/bitrate_mask */
3708 static const u8 cck_ofdm_rate
[] = {
3725 /* Check if only one bit set */
3726 static int ath10k_check_single_mask(u32 mask
)
3734 mask
&= ~BIT(bit
- 1);
3742 ath10k_default_bitrate_mask(struct ath10k
*ar
,
3743 enum ieee80211_band band
,
3744 const struct cfg80211_bitrate_mask
*mask
)
3746 u32 legacy
= 0x00ff;
3751 case IEEE80211_BAND_2GHZ
:
3755 case IEEE80211_BAND_5GHZ
:
3761 if (mask
->control
[band
].legacy
!= legacy
)
3764 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3765 if (mask
->control
[band
].ht_mcs
[i
] != ht
)
3768 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
3769 if (mask
->control
[band
].vht_mcs
[i
] != vht
)
3776 ath10k_bitrate_mask_nss(const struct cfg80211_bitrate_mask
*mask
,
3777 enum ieee80211_band band
,
3780 int ht_nss
= 0, vht_nss
= 0, i
;
3783 if (ath10k_check_single_mask(mask
->control
[band
].legacy
))
3787 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++) {
3788 if (mask
->control
[band
].ht_mcs
[i
] == 0xff)
3790 else if (mask
->control
[band
].ht_mcs
[i
] == 0x00)
3799 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++) {
3800 if (mask
->control
[band
].vht_mcs
[i
] == 0x03ff)
3802 else if (mask
->control
[band
].vht_mcs
[i
] == 0x0000)
3810 if (ht_nss
> 0 && vht_nss
> 0)
3814 *fixed_nss
= ht_nss
;
3816 *fixed_nss
= vht_nss
;
3824 ath10k_bitrate_mask_correct(const struct cfg80211_bitrate_mask
*mask
,
3825 enum ieee80211_band band
,
3826 enum wmi_rate_preamble
*preamble
)
3828 int legacy
= 0, ht
= 0, vht
= 0, i
;
3830 *preamble
= WMI_RATE_PREAMBLE_OFDM
;
3833 legacy
= ath10k_check_single_mask(mask
->control
[band
].legacy
);
3838 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3839 ht
+= ath10k_check_single_mask(mask
->control
[band
].ht_mcs
[i
]);
3844 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3845 vht
+= ath10k_check_single_mask(mask
->control
[band
].vht_mcs
[i
]);
3849 /* Currently we support only one fixed_rate */
3850 if ((legacy
+ ht
+ vht
) != 1)
3854 *preamble
= WMI_RATE_PREAMBLE_HT
;
3856 *preamble
= WMI_RATE_PREAMBLE_VHT
;
3862 ath10k_bitrate_mask_rate(const struct cfg80211_bitrate_mask
*mask
,
3863 enum ieee80211_band band
,
3867 u8 rate
= 0, pream
= 0, nss
= 0, i
;
3868 enum wmi_rate_preamble preamble
;
3870 /* Check if single rate correct */
3871 if (!ath10k_bitrate_mask_correct(mask
, band
, &preamble
))
3877 case WMI_RATE_PREAMBLE_CCK
:
3878 case WMI_RATE_PREAMBLE_OFDM
:
3879 i
= ffs(mask
->control
[band
].legacy
) - 1;
3881 if (band
== IEEE80211_BAND_2GHZ
&& i
< 4)
3882 pream
= WMI_RATE_PREAMBLE_CCK
;
3884 if (band
== IEEE80211_BAND_5GHZ
)
3887 if (i
>= ARRAY_SIZE(cck_ofdm_rate
))
3890 rate
= cck_ofdm_rate
[i
];
3892 case WMI_RATE_PREAMBLE_HT
:
3893 for (i
= 0; i
< IEEE80211_HT_MCS_MASK_LEN
; i
++)
3894 if (mask
->control
[band
].ht_mcs
[i
])
3897 if (i
== IEEE80211_HT_MCS_MASK_LEN
)
3900 rate
= ffs(mask
->control
[band
].ht_mcs
[i
]) - 1;
3903 case WMI_RATE_PREAMBLE_VHT
:
3904 for (i
= 0; i
< NL80211_VHT_NSS_MAX
; i
++)
3905 if (mask
->control
[band
].vht_mcs
[i
])
3908 if (i
== NL80211_VHT_NSS_MAX
)
3911 rate
= ffs(mask
->control
[band
].vht_mcs
[i
]) - 1;
3916 *fixed_nss
= nss
+ 1;
3920 ath10k_dbg(ATH10K_DBG_MAC
, "mac fixed rate pream 0x%02x nss 0x%02x rate 0x%02x\n",
3923 *fixed_rate
= pream
| nss
| rate
;
3928 static bool ath10k_get_fixed_rate_nss(const struct cfg80211_bitrate_mask
*mask
,
3929 enum ieee80211_band band
,
3933 /* First check full NSS mask, if we can simply limit NSS */
3934 if (ath10k_bitrate_mask_nss(mask
, band
, fixed_nss
))
3937 /* Next Check single rate is set */
3938 return ath10k_bitrate_mask_rate(mask
, band
, fixed_rate
, fixed_nss
);
3941 static int ath10k_set_fixed_rate_param(struct ath10k_vif
*arvif
,
3946 struct ath10k
*ar
= arvif
->ar
;
3950 mutex_lock(&ar
->conf_mutex
);
3952 if (arvif
->fixed_rate
== fixed_rate
&&
3953 arvif
->fixed_nss
== fixed_nss
&&
3954 arvif
->force_sgi
== force_sgi
)
3957 if (fixed_rate
== WMI_FIXED_RATE_NONE
)
3958 ath10k_dbg(ATH10K_DBG_MAC
, "mac disable fixed bitrate mask\n");
3961 ath10k_dbg(ATH10K_DBG_MAC
, "mac force sgi\n");
3963 vdev_param
= ar
->wmi
.vdev_param
->fixed_rate
;
3964 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
3965 vdev_param
, fixed_rate
);
3967 ath10k_warn("Could not set fixed_rate param 0x%02x: %d\n",
3973 arvif
->fixed_rate
= fixed_rate
;
3975 vdev_param
= ar
->wmi
.vdev_param
->nss
;
3976 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
,
3977 vdev_param
, fixed_nss
);
3980 ath10k_warn("Could not set fixed_nss param %d: %d\n",
3986 arvif
->fixed_nss
= fixed_nss
;
3988 vdev_param
= ar
->wmi
.vdev_param
->sgi
;
3989 ret
= ath10k_wmi_vdev_set_param(ar
, arvif
->vdev_id
, vdev_param
,
3993 ath10k_warn("Could not set sgi param %d: %d\n",
3999 arvif
->force_sgi
= force_sgi
;
4002 mutex_unlock(&ar
->conf_mutex
);
4006 static int ath10k_set_bitrate_mask(struct ieee80211_hw
*hw
,
4007 struct ieee80211_vif
*vif
,
4008 const struct cfg80211_bitrate_mask
*mask
)
4010 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4011 struct ath10k
*ar
= arvif
->ar
;
4012 enum ieee80211_band band
= ar
->hw
->conf
.chandef
.chan
->band
;
4013 u8 fixed_rate
= WMI_FIXED_RATE_NONE
;
4014 u8 fixed_nss
= ar
->num_rf_chains
;
4017 force_sgi
= mask
->control
[band
].gi
;
4018 if (force_sgi
== NL80211_TXRATE_FORCE_LGI
)
4021 if (!ath10k_default_bitrate_mask(ar
, band
, mask
)) {
4022 if (!ath10k_get_fixed_rate_nss(mask
, band
,
4028 if (fixed_rate
== WMI_FIXED_RATE_NONE
&& force_sgi
) {
4029 ath10k_warn("Could not force SGI usage for default rate settings\n");
4033 return ath10k_set_fixed_rate_param(arvif
, fixed_rate
,
4034 fixed_nss
, force_sgi
);
4037 static void ath10k_channel_switch_beacon(struct ieee80211_hw
*hw
,
4038 struct ieee80211_vif
*vif
,
4039 struct cfg80211_chan_def
*chandef
)
4041 /* there's no need to do anything here. vif->csa_active is enough */
4045 static void ath10k_sta_rc_update(struct ieee80211_hw
*hw
,
4046 struct ieee80211_vif
*vif
,
4047 struct ieee80211_sta
*sta
,
4050 struct ath10k
*ar
= hw
->priv
;
4051 struct ath10k_sta
*arsta
= (struct ath10k_sta
*)sta
->drv_priv
;
4054 spin_lock_bh(&ar
->data_lock
);
4056 ath10k_dbg(ATH10K_DBG_MAC
,
4057 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4058 sta
->addr
, changed
, sta
->bandwidth
, sta
->rx_nss
,
4061 if (changed
& IEEE80211_RC_BW_CHANGED
) {
4062 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4064 switch (sta
->bandwidth
) {
4065 case IEEE80211_STA_RX_BW_20
:
4066 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4068 case IEEE80211_STA_RX_BW_40
:
4069 bw
= WMI_PEER_CHWIDTH_40MHZ
;
4071 case IEEE80211_STA_RX_BW_80
:
4072 bw
= WMI_PEER_CHWIDTH_80MHZ
;
4074 case IEEE80211_STA_RX_BW_160
:
4075 ath10k_warn("mac sta rc update for %pM: invalid bw %d\n",
4076 sta
->addr
, sta
->bandwidth
);
4077 bw
= WMI_PEER_CHWIDTH_20MHZ
;
4084 if (changed
& IEEE80211_RC_NSS_CHANGED
)
4085 arsta
->nss
= sta
->rx_nss
;
4087 if (changed
& IEEE80211_RC_SMPS_CHANGED
) {
4088 smps
= WMI_PEER_SMPS_PS_NONE
;
4090 switch (sta
->smps_mode
) {
4091 case IEEE80211_SMPS_AUTOMATIC
:
4092 case IEEE80211_SMPS_OFF
:
4093 smps
= WMI_PEER_SMPS_PS_NONE
;
4095 case IEEE80211_SMPS_STATIC
:
4096 smps
= WMI_PEER_SMPS_STATIC
;
4098 case IEEE80211_SMPS_DYNAMIC
:
4099 smps
= WMI_PEER_SMPS_DYNAMIC
;
4101 case IEEE80211_SMPS_NUM_MODES
:
4102 ath10k_warn("mac sta rc update for %pM: invalid smps: %d\n",
4103 sta
->addr
, sta
->smps_mode
);
4104 smps
= WMI_PEER_SMPS_PS_NONE
;
4111 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
4112 /* FIXME: Not implemented. Probably the only way to do it would
4113 * be to re-assoc the peer. */
4114 changed
&= ~IEEE80211_RC_SUPP_RATES_CHANGED
;
4115 ath10k_dbg(ATH10K_DBG_MAC
,
4116 "mac sta rc update for %pM: changing supported rates not implemented\n",
4120 arsta
->changed
|= changed
;
4122 spin_unlock_bh(&ar
->data_lock
);
4124 ieee80211_queue_work(hw
, &arsta
->update_wk
);
4127 static u64
ath10k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
4130 * FIXME: Return 0 for time being. Need to figure out whether FW
4131 * has the API to fetch 64-bit local TSF
4137 static const struct ieee80211_ops ath10k_ops
= {
4139 .start
= ath10k_start
,
4140 .stop
= ath10k_stop
,
4141 .config
= ath10k_config
,
4142 .add_interface
= ath10k_add_interface
,
4143 .remove_interface
= ath10k_remove_interface
,
4144 .configure_filter
= ath10k_configure_filter
,
4145 .bss_info_changed
= ath10k_bss_info_changed
,
4146 .hw_scan
= ath10k_hw_scan
,
4147 .cancel_hw_scan
= ath10k_cancel_hw_scan
,
4148 .set_key
= ath10k_set_key
,
4149 .sta_state
= ath10k_sta_state
,
4150 .conf_tx
= ath10k_conf_tx
,
4151 .remain_on_channel
= ath10k_remain_on_channel
,
4152 .cancel_remain_on_channel
= ath10k_cancel_remain_on_channel
,
4153 .set_rts_threshold
= ath10k_set_rts_threshold
,
4154 .set_frag_threshold
= ath10k_set_frag_threshold
,
4155 .flush
= ath10k_flush
,
4156 .tx_last_beacon
= ath10k_tx_last_beacon
,
4157 .restart_complete
= ath10k_restart_complete
,
4158 .get_survey
= ath10k_get_survey
,
4159 .set_bitrate_mask
= ath10k_set_bitrate_mask
,
4160 .channel_switch_beacon
= ath10k_channel_switch_beacon
,
4161 .sta_rc_update
= ath10k_sta_rc_update
,
4162 .get_tsf
= ath10k_get_tsf
,
4164 .suspend
= ath10k_suspend
,
4165 .resume
= ath10k_resume
,
4169 #define RATETAB_ENT(_rate, _rateid, _flags) { \
4170 .bitrate = (_rate), \
4171 .flags = (_flags), \
4172 .hw_value = (_rateid), \
4175 #define CHAN2G(_channel, _freq, _flags) { \
4176 .band = IEEE80211_BAND_2GHZ, \
4177 .hw_value = (_channel), \
4178 .center_freq = (_freq), \
4179 .flags = (_flags), \
4180 .max_antenna_gain = 0, \
4184 #define CHAN5G(_channel, _freq, _flags) { \
4185 .band = IEEE80211_BAND_5GHZ, \
4186 .hw_value = (_channel), \
4187 .center_freq = (_freq), \
4188 .flags = (_flags), \
4189 .max_antenna_gain = 0, \
4193 static const struct ieee80211_channel ath10k_2ghz_channels
[] = {
4203 CHAN2G(10, 2457, 0),
4204 CHAN2G(11, 2462, 0),
4205 CHAN2G(12, 2467, 0),
4206 CHAN2G(13, 2472, 0),
4207 CHAN2G(14, 2484, 0),
4210 static const struct ieee80211_channel ath10k_5ghz_channels
[] = {
4211 CHAN5G(36, 5180, 0),
4212 CHAN5G(40, 5200, 0),
4213 CHAN5G(44, 5220, 0),
4214 CHAN5G(48, 5240, 0),
4215 CHAN5G(52, 5260, 0),
4216 CHAN5G(56, 5280, 0),
4217 CHAN5G(60, 5300, 0),
4218 CHAN5G(64, 5320, 0),
4219 CHAN5G(100, 5500, 0),
4220 CHAN5G(104, 5520, 0),
4221 CHAN5G(108, 5540, 0),
4222 CHAN5G(112, 5560, 0),
4223 CHAN5G(116, 5580, 0),
4224 CHAN5G(120, 5600, 0),
4225 CHAN5G(124, 5620, 0),
4226 CHAN5G(128, 5640, 0),
4227 CHAN5G(132, 5660, 0),
4228 CHAN5G(136, 5680, 0),
4229 CHAN5G(140, 5700, 0),
4230 CHAN5G(149, 5745, 0),
4231 CHAN5G(153, 5765, 0),
4232 CHAN5G(157, 5785, 0),
4233 CHAN5G(161, 5805, 0),
4234 CHAN5G(165, 5825, 0),
4237 static struct ieee80211_rate ath10k_rates
[] = {
4239 RATETAB_ENT(10, 0x82, 0),
4240 RATETAB_ENT(20, 0x84, 0),
4241 RATETAB_ENT(55, 0x8b, 0),
4242 RATETAB_ENT(110, 0x96, 0),
4244 RATETAB_ENT(60, 0x0c, 0),
4245 RATETAB_ENT(90, 0x12, 0),
4246 RATETAB_ENT(120, 0x18, 0),
4247 RATETAB_ENT(180, 0x24, 0),
4248 RATETAB_ENT(240, 0x30, 0),
4249 RATETAB_ENT(360, 0x48, 0),
4250 RATETAB_ENT(480, 0x60, 0),
4251 RATETAB_ENT(540, 0x6c, 0),
4254 #define ath10k_a_rates (ath10k_rates + 4)
4255 #define ath10k_a_rates_size (ARRAY_SIZE(ath10k_rates) - 4)
4256 #define ath10k_g_rates (ath10k_rates + 0)
4257 #define ath10k_g_rates_size (ARRAY_SIZE(ath10k_rates))
4259 struct ath10k
*ath10k_mac_create(void)
4261 struct ieee80211_hw
*hw
;
4264 hw
= ieee80211_alloc_hw(sizeof(struct ath10k
), &ath10k_ops
);
4274 void ath10k_mac_destroy(struct ath10k
*ar
)
4276 ieee80211_free_hw(ar
->hw
);
4279 static const struct ieee80211_iface_limit ath10k_if_limits
[] = {
4282 .types
= BIT(NL80211_IFTYPE_STATION
)
4283 | BIT(NL80211_IFTYPE_P2P_CLIENT
)
4287 .types
= BIT(NL80211_IFTYPE_P2P_GO
)
4291 .types
= BIT(NL80211_IFTYPE_AP
)
4295 static const struct ieee80211_iface_limit ath10k_10x_if_limits
[] = {
4298 .types
= BIT(NL80211_IFTYPE_AP
)
4302 static const struct ieee80211_iface_combination ath10k_if_comb
[] = {
4304 .limits
= ath10k_if_limits
,
4305 .n_limits
= ARRAY_SIZE(ath10k_if_limits
),
4306 .max_interfaces
= 8,
4307 .num_different_channels
= 1,
4308 .beacon_int_infra_match
= true,
4312 static const struct ieee80211_iface_combination ath10k_10x_if_comb
[] = {
4314 .limits
= ath10k_10x_if_limits
,
4315 .n_limits
= ARRAY_SIZE(ath10k_10x_if_limits
),
4316 .max_interfaces
= 8,
4317 .num_different_channels
= 1,
4318 .beacon_int_infra_match
= true,
4319 #ifdef CONFIG_ATH10K_DFS_CERTIFIED
4320 .radar_detect_widths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
4321 BIT(NL80211_CHAN_WIDTH_20
) |
4322 BIT(NL80211_CHAN_WIDTH_40
) |
4323 BIT(NL80211_CHAN_WIDTH_80
),
4328 static struct ieee80211_sta_vht_cap
ath10k_create_vht_cap(struct ath10k
*ar
)
4330 struct ieee80211_sta_vht_cap vht_cap
= {0};
4334 vht_cap
.vht_supported
= 1;
4335 vht_cap
.cap
= ar
->vht_cap_info
;
4338 for (i
= 0; i
< 8; i
++) {
4339 if (i
< ar
->num_rf_chains
)
4340 mcs_map
|= IEEE80211_VHT_MCS_SUPPORT_0_9
<< (i
*2);
4342 mcs_map
|= IEEE80211_VHT_MCS_NOT_SUPPORTED
<< (i
*2);
4345 vht_cap
.vht_mcs
.rx_mcs_map
= cpu_to_le16(mcs_map
);
4346 vht_cap
.vht_mcs
.tx_mcs_map
= cpu_to_le16(mcs_map
);
4351 static struct ieee80211_sta_ht_cap
ath10k_get_ht_cap(struct ath10k
*ar
)
4354 struct ieee80211_sta_ht_cap ht_cap
= {0};
4356 if (!(ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
))
4359 ht_cap
.ht_supported
= 1;
4360 ht_cap
.ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
4361 ht_cap
.ampdu_density
= IEEE80211_HT_MPDU_DENSITY_8
;
4362 ht_cap
.cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
4363 ht_cap
.cap
|= IEEE80211_HT_CAP_DSSSCCK40
;
4364 ht_cap
.cap
|= WLAN_HT_CAP_SM_PS_STATIC
<< IEEE80211_HT_CAP_SM_PS_SHIFT
;
4366 if (ar
->ht_cap_info
& WMI_HT_CAP_HT20_SGI
)
4367 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_20
;
4369 if (ar
->ht_cap_info
& WMI_HT_CAP_HT40_SGI
)
4370 ht_cap
.cap
|= IEEE80211_HT_CAP_SGI_40
;
4372 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
) {
4375 smps
= WLAN_HT_CAP_SM_PS_DYNAMIC
;
4376 smps
<<= IEEE80211_HT_CAP_SM_PS_SHIFT
;
4381 if (ar
->ht_cap_info
& WMI_HT_CAP_TX_STBC
)
4382 ht_cap
.cap
|= IEEE80211_HT_CAP_TX_STBC
;
4384 if (ar
->ht_cap_info
& WMI_HT_CAP_RX_STBC
) {
4387 stbc
= ar
->ht_cap_info
;
4388 stbc
&= WMI_HT_CAP_RX_STBC
;
4389 stbc
>>= WMI_HT_CAP_RX_STBC_MASK_SHIFT
;
4390 stbc
<<= IEEE80211_HT_CAP_RX_STBC_SHIFT
;
4391 stbc
&= IEEE80211_HT_CAP_RX_STBC
;
4396 if (ar
->ht_cap_info
& WMI_HT_CAP_LDPC
)
4397 ht_cap
.cap
|= IEEE80211_HT_CAP_LDPC_CODING
;
4399 if (ar
->ht_cap_info
& WMI_HT_CAP_L_SIG_TXOP_PROT
)
4400 ht_cap
.cap
|= IEEE80211_HT_CAP_LSIG_TXOP_PROT
;
4402 /* max AMSDU is implicitly taken from vht_cap_info */
4403 if (ar
->vht_cap_info
& WMI_VHT_CAP_MAX_MPDU_LEN_MASK
)
4404 ht_cap
.cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
4406 for (i
= 0; i
< ar
->num_rf_chains
; i
++)
4407 ht_cap
.mcs
.rx_mask
[i
] = 0xFF;
4409 ht_cap
.mcs
.tx_params
|= IEEE80211_HT_MCS_TX_DEFINED
;
4415 static void ath10k_get_arvif_iter(void *data
, u8
*mac
,
4416 struct ieee80211_vif
*vif
)
4418 struct ath10k_vif_iter
*arvif_iter
= data
;
4419 struct ath10k_vif
*arvif
= ath10k_vif_to_arvif(vif
);
4421 if (arvif
->vdev_id
== arvif_iter
->vdev_id
)
4422 arvif_iter
->arvif
= arvif
;
4425 struct ath10k_vif
*ath10k_get_arvif(struct ath10k
*ar
, u32 vdev_id
)
4427 struct ath10k_vif_iter arvif_iter
;
4430 memset(&arvif_iter
, 0, sizeof(struct ath10k_vif_iter
));
4431 arvif_iter
.vdev_id
= vdev_id
;
4433 flags
= IEEE80211_IFACE_ITER_RESUME_ALL
;
4434 ieee80211_iterate_active_interfaces_atomic(ar
->hw
,
4436 ath10k_get_arvif_iter
,
4438 if (!arvif_iter
.arvif
) {
4439 ath10k_warn("No VIF found for vdev %d\n", vdev_id
);
4443 return arvif_iter
.arvif
;
4446 int ath10k_mac_register(struct ath10k
*ar
)
4448 struct ieee80211_supported_band
*band
;
4449 struct ieee80211_sta_vht_cap vht_cap
;
4450 struct ieee80211_sta_ht_cap ht_cap
;
4454 SET_IEEE80211_PERM_ADDR(ar
->hw
, ar
->mac_addr
);
4456 SET_IEEE80211_DEV(ar
->hw
, ar
->dev
);
4458 ht_cap
= ath10k_get_ht_cap(ar
);
4459 vht_cap
= ath10k_create_vht_cap(ar
);
4461 if (ar
->phy_capability
& WHAL_WLAN_11G_CAPABILITY
) {
4462 channels
= kmemdup(ath10k_2ghz_channels
,
4463 sizeof(ath10k_2ghz_channels
),
4470 band
= &ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
];
4471 band
->n_channels
= ARRAY_SIZE(ath10k_2ghz_channels
);
4472 band
->channels
= channels
;
4473 band
->n_bitrates
= ath10k_g_rates_size
;
4474 band
->bitrates
= ath10k_g_rates
;
4475 band
->ht_cap
= ht_cap
;
4477 /* vht is not supported in 2.4 GHz */
4479 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = band
;
4482 if (ar
->phy_capability
& WHAL_WLAN_11A_CAPABILITY
) {
4483 channels
= kmemdup(ath10k_5ghz_channels
,
4484 sizeof(ath10k_5ghz_channels
),
4491 band
= &ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
];
4492 band
->n_channels
= ARRAY_SIZE(ath10k_5ghz_channels
);
4493 band
->channels
= channels
;
4494 band
->n_bitrates
= ath10k_a_rates_size
;
4495 band
->bitrates
= ath10k_a_rates
;
4496 band
->ht_cap
= ht_cap
;
4497 band
->vht_cap
= vht_cap
;
4498 ar
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = band
;
4501 ar
->hw
->wiphy
->interface_modes
=
4502 BIT(NL80211_IFTYPE_STATION
) |
4503 BIT(NL80211_IFTYPE_ADHOC
) |
4504 BIT(NL80211_IFTYPE_AP
);
4506 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P
, ar
->fw_features
))
4507 ar
->hw
->wiphy
->interface_modes
|=
4508 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
4509 BIT(NL80211_IFTYPE_P2P_GO
);
4511 ar
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
4512 IEEE80211_HW_SUPPORTS_PS
|
4513 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
4514 IEEE80211_HW_SUPPORTS_UAPSD
|
4515 IEEE80211_HW_MFP_CAPABLE
|
4516 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
4517 IEEE80211_HW_HAS_RATE_CONTROL
|
4518 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
4519 IEEE80211_HW_WANT_MONITOR_VIF
|
4520 IEEE80211_HW_AP_LINK_PS
|
4521 IEEE80211_HW_SPECTRUM_MGMT
;
4523 /* MSDU can have HTT TX fragment pushed in front. The additional 4
4524 * bytes is used for padding/alignment if necessary. */
4525 ar
->hw
->extra_tx_headroom
+= sizeof(struct htt_data_tx_desc_frag
)*2 + 4;
4527 if (ar
->ht_cap_info
& WMI_HT_CAP_DYNAMIC_SMPS
)
4528 ar
->hw
->flags
|= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
;
4530 if (ar
->ht_cap_info
& WMI_HT_CAP_ENABLED
) {
4531 ar
->hw
->flags
|= IEEE80211_HW_AMPDU_AGGREGATION
;
4532 ar
->hw
->flags
|= IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
;
4535 ar
->hw
->wiphy
->max_scan_ssids
= WLAN_SCAN_PARAMS_MAX_SSID
;
4536 ar
->hw
->wiphy
->max_scan_ie_len
= WLAN_SCAN_PARAMS_MAX_IE_LEN
;
4538 ar
->hw
->vif_data_size
= sizeof(struct ath10k_vif
);
4539 ar
->hw
->sta_data_size
= sizeof(struct ath10k_sta
);
4541 ar
->hw
->max_listen_interval
= ATH10K_MAX_HW_LISTEN_INTERVAL
;
4543 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
4544 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
4545 ar
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
4547 ar
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
4549 * on LL hardware queues are managed entirely by the FW
4550 * so we only advertise to mac we can do the queues thing
4554 if (test_bit(ATH10K_FW_FEATURE_WMI_10X
, ar
->fw_features
)) {
4555 ar
->hw
->wiphy
->iface_combinations
= ath10k_10x_if_comb
;
4556 ar
->hw
->wiphy
->n_iface_combinations
=
4557 ARRAY_SIZE(ath10k_10x_if_comb
);
4559 ar
->hw
->wiphy
->iface_combinations
= ath10k_if_comb
;
4560 ar
->hw
->wiphy
->n_iface_combinations
=
4561 ARRAY_SIZE(ath10k_if_comb
);
4564 ar
->hw
->netdev_features
= NETIF_F_HW_CSUM
;
4566 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
)) {
4567 /* Init ath dfs pattern detector */
4568 ar
->ath_common
.debug_mask
= ATH_DBG_DFS
;
4569 ar
->dfs_detector
= dfs_pattern_detector_init(&ar
->ath_common
,
4572 if (!ar
->dfs_detector
)
4573 ath10k_warn("dfs pattern detector init failed\n");
4576 ret
= ath_regd_init(&ar
->ath_common
.regulatory
, ar
->hw
->wiphy
,
4577 ath10k_reg_notifier
);
4579 ath10k_err("Regulatory initialization failed: %i\n", ret
);
4583 ret
= ieee80211_register_hw(ar
->hw
);
4585 ath10k_err("ieee80211 registration failed: %d\n", ret
);
4589 if (!ath_is_world_regd(&ar
->ath_common
.regulatory
)) {
4590 ret
= regulatory_hint(ar
->hw
->wiphy
,
4591 ar
->ath_common
.regulatory
.alpha2
);
4593 goto err_unregister
;
4599 ieee80211_unregister_hw(ar
->hw
);
4601 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4602 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4607 void ath10k_mac_unregister(struct ath10k
*ar
)
4609 ieee80211_unregister_hw(ar
->hw
);
4611 if (config_enabled(CONFIG_ATH10K_DFS_CERTIFIED
) && ar
->dfs_detector
)
4612 ar
->dfs_detector
->exit(ar
->dfs_detector
);
4614 kfree(ar
->mac
.sbands
[IEEE80211_BAND_2GHZ
].channels
);
4615 kfree(ar
->mac
.sbands
[IEEE80211_BAND_5GHZ
].channels
);
4617 SET_IEEE80211_DEV(ar
->hw
, NULL
);