1 // SPDX-License-Identifier: GPL-2.0-only
3 * Implementation of mac80211 API.
5 * Copyright (c) 2017-2019, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
8 #include <net/mac80211.h>
18 #include "hif_tx_mib.h"
21 #define HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES 2
23 static u32 wfx_rate_mask_to_hw(struct wfx_dev *wdev, u32 rates)
27 // WFx only support 2GHz
28 struct ieee80211_supported_band *sband = wdev->hw->wiphy->bands[NL80211_BAND_2GHZ];
30 for (i = 0; i < sband->n_bitrates; i++) {
32 if (i >= sband->n_bitrates)
33 dev_warn(wdev->dev, "unsupported basic rate\n");
35 ret |= BIT(sband->bitrates[i].hw_value);
41 static void __wfx_free_event_queue(struct list_head *list)
43 struct wfx_hif_event *event, *tmp;
45 list_for_each_entry_safe(event, tmp, list, link) {
46 list_del(&event->link);
51 static void wfx_free_event_queue(struct wfx_vif *wvif)
55 spin_lock(&wvif->event_queue_lock);
56 list_splice_init(&wvif->event_queue, &list);
57 spin_unlock(&wvif->event_queue_lock);
59 __wfx_free_event_queue(&list);
62 void wfx_cqm_bssloss_sm(struct wfx_vif *wvif, int init, int good, int bad)
66 mutex_lock(&wvif->bss_loss_lock);
67 wvif->delayed_link_loss = 0;
68 cancel_work_sync(&wvif->bss_params_work);
70 /* If we have a pending unjoin */
71 if (wvif->delayed_unjoin)
75 schedule_delayed_work(&wvif->bss_loss_work, HZ);
76 wvif->bss_loss_state = 0;
78 if (!atomic_read(&wvif->wdev->tx_lock))
81 cancel_delayed_work_sync(&wvif->bss_loss_work);
82 wvif->bss_loss_state = 0;
83 schedule_work(&wvif->bss_params_work);
85 /* FIXME Should we just keep going until we time out? */
86 if (wvif->bss_loss_state < 3)
89 cancel_delayed_work_sync(&wvif->bss_loss_work);
90 wvif->bss_loss_state = 0;
93 /* Spit out a NULL packet to our AP if necessary */
94 // FIXME: call ieee80211_beacon_loss/ieee80211_connection_loss instead
98 wvif->bss_loss_state++;
100 skb = ieee80211_nullfunc_get(wvif->wdev->hw, wvif->vif, false);
103 memset(IEEE80211_SKB_CB(skb), 0,
104 sizeof(*IEEE80211_SKB_CB(skb)));
105 IEEE80211_SKB_CB(skb)->control.vif = wvif->vif;
106 IEEE80211_SKB_CB(skb)->driver_rates[0].idx = 0;
107 IEEE80211_SKB_CB(skb)->driver_rates[0].count = 1;
108 IEEE80211_SKB_CB(skb)->driver_rates[1].idx = -1;
109 wfx_tx(wvif->wdev->hw, NULL, skb);
112 mutex_unlock(&wvif->bss_loss_lock);
115 static int wfx_set_uapsd_param(struct wfx_vif *wvif,
116 const struct wfx_edca_params *arg)
118 /* Here's the mapping AC [queue, bit]
119 * VO [0,3], VI [1, 2], BE [2, 1], BK [3, 0]
122 if (arg->uapsd_enable[IEEE80211_AC_VO])
123 wvif->uapsd_info.trig_voice = 1;
125 wvif->uapsd_info.trig_voice = 0;
127 if (arg->uapsd_enable[IEEE80211_AC_VI])
128 wvif->uapsd_info.trig_video = 1;
130 wvif->uapsd_info.trig_video = 0;
132 if (arg->uapsd_enable[IEEE80211_AC_BE])
133 wvif->uapsd_info.trig_be = 1;
135 wvif->uapsd_info.trig_be = 0;
137 if (arg->uapsd_enable[IEEE80211_AC_BK])
138 wvif->uapsd_info.trig_bckgrnd = 1;
140 wvif->uapsd_info.trig_bckgrnd = 0;
142 /* Currently pseudo U-APSD operation is not supported, so setting
143 * MinAutoTriggerInterval, MaxAutoTriggerInterval and
144 * AutoTriggerStep to 0
146 wvif->uapsd_info.min_auto_trigger_interval = 0;
147 wvif->uapsd_info.max_auto_trigger_interval = 0;
148 wvif->uapsd_info.auto_trigger_step = 0;
150 return hif_set_uapsd_info(wvif, &wvif->uapsd_info);
153 int wfx_fwd_probe_req(struct wfx_vif *wvif, bool enable)
155 wvif->fwd_probe_req = enable;
156 return hif_set_rx_filter(wvif, wvif->filter_bssid,
157 wvif->fwd_probe_req);
160 static int wfx_set_mcast_filter(struct wfx_vif *wvif,
161 struct wfx_grp_addr_table *fp)
164 struct hif_mib_config_data_filter config = { };
165 struct hif_mib_set_data_filtering filter_data = { };
166 struct hif_mib_mac_addr_data_frame_condition filter_addr_val = { };
167 struct hif_mib_uc_mc_bc_data_frame_condition filter_addr_type = { };
169 // Temporary workaround for filters
170 return hif_set_data_filtering(wvif, &filter_data);
173 filter_data.enable = 0;
174 return hif_set_data_filtering(wvif, &filter_data);
177 // A1 Address match on list
178 for (i = 0; i < fp->num_addresses; i++) {
179 filter_addr_val.condition_idx = i;
180 filter_addr_val.address_type = HIF_MAC_ADDR_A1;
181 ether_addr_copy(filter_addr_val.mac_address,
182 fp->address_list[i]);
183 ret = hif_set_mac_addr_condition(wvif,
187 config.mac_cond |= 1 << i;
190 // Accept unicast and broadcast
191 filter_addr_type.condition_idx = 0;
192 filter_addr_type.param.bits.type_unicast = 1;
193 filter_addr_type.param.bits.type_broadcast = 1;
194 ret = hif_set_uc_mc_bc_condition(wvif, &filter_addr_type);
198 config.uc_mc_bc_cond = 1;
199 config.filter_idx = 0; // TODO #define MULTICAST_FILTERING 0
201 ret = hif_set_config_data_filter(wvif, &config);
205 // discard all data frames except match filter
206 filter_data.enable = 1;
207 filter_data.default_filter = 1; // discard all
208 ret = hif_set_data_filtering(wvif, &filter_data);
213 void wfx_update_filtering(struct wfx_vif *wvif)
216 bool is_sta = wvif->vif && NL80211_IFTYPE_STATION == wvif->vif->type;
217 bool filter_bssid = wvif->filter_bssid;
218 bool fwd_probe_req = wvif->fwd_probe_req;
219 struct hif_mib_bcn_filter_enable bf_ctrl;
220 struct hif_ie_table_entry filter_ies[] = {
222 .ie_id = WLAN_EID_VENDOR_SPECIFIC,
226 .oui = { 0x50, 0x6F, 0x9A },
228 .ie_id = WLAN_EID_HT_OPERATION,
233 .ie_id = WLAN_EID_ERP_INFO,
241 if (wvif->state == WFX_STATE_PASSIVE)
244 if (wvif->disable_beacon_filter) {
246 bf_ctrl.bcn_count = 1;
248 } else if (!is_sta) {
249 bf_ctrl.enable = HIF_BEACON_FILTER_ENABLE |
250 HIF_BEACON_FILTER_AUTO_ERP;
251 bf_ctrl.bcn_count = 0;
254 bf_ctrl.enable = HIF_BEACON_FILTER_ENABLE;
255 bf_ctrl.bcn_count = 0;
259 ret = hif_set_rx_filter(wvif, filter_bssid, fwd_probe_req);
261 ret = hif_set_beacon_filter_table(wvif, n_filter_ies,
264 ret = hif_beacon_filter_control(wvif, bf_ctrl.enable,
267 ret = wfx_set_mcast_filter(wvif, &wvif->mcast_filter);
269 dev_err(wvif->wdev->dev, "update filtering failed: %d\n", ret);
272 static void wfx_update_filtering_work(struct work_struct *work)
274 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
275 update_filtering_work);
277 wfx_update_filtering(wvif);
280 u64 wfx_prepare_multicast(struct ieee80211_hw *hw,
281 struct netdev_hw_addr_list *mc_list)
284 struct netdev_hw_addr *ha;
285 struct wfx_vif *wvif = NULL;
286 struct wfx_dev *wdev = hw->priv;
287 int count = netdev_hw_addr_list_count(mc_list);
289 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
290 memset(&wvif->mcast_filter, 0x00, sizeof(wvif->mcast_filter));
292 count > ARRAY_SIZE(wvif->mcast_filter.address_list))
296 netdev_hw_addr_list_for_each(ha, mc_list) {
297 ether_addr_copy(wvif->mcast_filter.address_list[i],
301 wvif->mcast_filter.enable = true;
302 wvif->mcast_filter.num_addresses = count;
308 void wfx_configure_filter(struct ieee80211_hw *hw,
309 unsigned int changed_flags,
310 unsigned int *total_flags,
313 struct wfx_vif *wvif = NULL;
314 struct wfx_dev *wdev = hw->priv;
316 *total_flags &= FIF_OTHER_BSS | FIF_FCSFAIL | FIF_PROBE_REQ;
318 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
319 down(&wvif->scan.lock);
320 wvif->filter_bssid = (*total_flags &
321 (FIF_OTHER_BSS | FIF_PROBE_REQ)) ? 0 : 1;
322 wvif->disable_beacon_filter = !(*total_flags & FIF_PROBE_REQ);
323 wfx_fwd_probe_req(wvif, true);
324 wfx_update_filtering(wvif);
325 up(&wvif->scan.lock);
329 int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
330 u16 queue, const struct ieee80211_tx_queue_params *params)
332 struct wfx_dev *wdev = hw->priv;
333 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
335 /* To prevent re-applying PM request OID again and again*/
336 u16 old_uapsd_flags, new_uapsd_flags;
337 struct hif_req_edca_queue_params *edca;
339 mutex_lock(&wdev->conf_mutex);
341 if (queue < hw->queues) {
342 old_uapsd_flags = *((u16 *) &wvif->uapsd_info);
343 edca = &wvif->edca.params[queue];
345 wvif->edca.uapsd_enable[queue] = params->uapsd;
346 edca->aifsn = params->aifs;
347 edca->cw_min = params->cw_min;
348 edca->cw_max = params->cw_max;
349 edca->tx_op_limit = params->txop * TXOP_UNIT;
350 edca->allowed_medium_time = 0;
351 ret = hif_set_edca_queue_params(wvif, edca);
357 if (wvif->vif->type == NL80211_IFTYPE_STATION) {
358 ret = wfx_set_uapsd_param(wvif, &wvif->edca);
359 new_uapsd_flags = *((u16 *) &wvif->uapsd_info);
360 if (!ret && wvif->setbssparams_done &&
361 wvif->state == WFX_STATE_STA &&
362 old_uapsd_flags != new_uapsd_flags)
363 ret = wfx_set_pm(wvif, &wvif->powersave_mode);
370 mutex_unlock(&wdev->conf_mutex);
374 int wfx_set_pm(struct wfx_vif *wvif, const struct hif_req_set_pm_mode *arg)
376 struct hif_req_set_pm_mode pm = *arg;
380 if (wvif->state != WFX_STATE_STA || !wvif->bss_params.aid)
383 memcpy(&uapsd_flags, &wvif->uapsd_info, sizeof(uapsd_flags));
385 if (uapsd_flags != 0)
386 pm.pm_mode.fast_psm = 0;
388 // Kernel disable PowerSave when multiple vifs are in use. In contrary,
389 // it is absolutly necessary to enable PowerSave for WF200
390 if (wvif_count(wvif->wdev) > 1) {
391 pm.pm_mode.enter_psm = 1;
392 pm.pm_mode.fast_psm = 0;
395 if (!wait_for_completion_timeout(&wvif->set_pm_mode_complete,
396 msecs_to_jiffies(300)))
397 dev_warn(wvif->wdev->dev,
398 "timeout while waiting of set_pm_mode_complete\n");
399 ret = hif_set_pm(wvif, &pm);
401 if (-ETIMEDOUT == wvif->scan.status)
402 wvif->scan.status = 1;
406 int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
408 struct wfx_dev *wdev = hw->priv;
409 struct wfx_vif *wvif = NULL;
411 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
412 hif_rts_threshold(wvif, value);
416 /* If successful, LOCKS the TX queue! */
417 static int __wfx_flush(struct wfx_dev *wdev, bool drop)
423 wfx_tx_queues_clear(wdev);
425 ret = wait_event_timeout(
426 wdev->tx_queue_stats.wait_link_id_empty,
427 wfx_tx_queues_is_empty(wdev),
431 if (!drop && ret <= 0) {
437 wfx_tx_lock_flush(wdev);
438 if (!wfx_tx_queues_is_empty(wdev)) {
439 /* Highly unlikely: WSM requeued frames. */
448 void wfx_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
449 u32 queues, bool drop)
451 struct wfx_dev *wdev = hw->priv;
452 struct wfx_vif *wvif;
455 wvif = (struct wfx_vif *) vif->drv_priv;
456 if (wvif->vif->type == NL80211_IFTYPE_MONITOR)
458 if (wvif->vif->type == NL80211_IFTYPE_AP &&
459 !wvif->enable_beacon)
463 // FIXME: only flush requested vif
464 if (!__wfx_flush(wdev, drop))
470 static void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
472 /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
473 * RSSI = RCPI / 2 - 110
478 rcpi_rssi = raw_rcpi_rssi / 2 - 110;
479 if (rcpi_rssi <= wvif->cqm_rssi_thold)
480 cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
482 cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
483 ieee80211_cqm_rssi_notify(wvif->vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
486 static void wfx_event_handler_work(struct work_struct *work)
488 struct wfx_vif *wvif =
489 container_of(work, struct wfx_vif, event_handler_work);
490 struct wfx_hif_event *event;
494 spin_lock(&wvif->event_queue_lock);
495 list_splice_init(&wvif->event_queue, &list);
496 spin_unlock(&wvif->event_queue_lock);
498 list_for_each_entry(event, &list, link) {
499 switch (event->evt.event_id) {
500 case HIF_EVENT_IND_BSSLOST:
501 cancel_work_sync(&wvif->unjoin_work);
502 if (!down_trylock(&wvif->scan.lock)) {
503 wfx_cqm_bssloss_sm(wvif, 1, 0, 0);
504 up(&wvif->scan.lock);
506 /* Scan is in progress. Delay reporting.
507 * Scan complete will trigger bss_loss_work
509 wvif->delayed_link_loss = 1;
510 /* Also start a watchdog. */
511 schedule_delayed_work(&wvif->bss_loss_work,
515 case HIF_EVENT_IND_BSSREGAINED:
516 wfx_cqm_bssloss_sm(wvif, 0, 0, 0);
517 cancel_work_sync(&wvif->unjoin_work);
519 case HIF_EVENT_IND_RCPI_RSSI:
520 wfx_event_report_rssi(wvif,
521 event->evt.event_data.rcpi_rssi);
523 case HIF_EVENT_IND_PS_MODE_ERROR:
524 dev_warn(wvif->wdev->dev,
525 "error while processing power save request\n");
528 dev_warn(wvif->wdev->dev,
529 "unhandled event indication: %.2x\n",
530 event->evt.event_id);
534 __wfx_free_event_queue(&list);
537 static void wfx_bss_loss_work(struct work_struct *work)
539 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
542 ieee80211_connection_loss(wvif->vif);
545 static void wfx_bss_params_work(struct work_struct *work)
547 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
550 mutex_lock(&wvif->wdev->conf_mutex);
551 wvif->bss_params.bss_flags.lost_count_only = 1;
552 hif_set_bss_params(wvif, &wvif->bss_params);
553 wvif->bss_params.bss_flags.lost_count_only = 0;
554 mutex_unlock(&wvif->wdev->conf_mutex);
557 static void wfx_set_beacon_wakeup_period_work(struct work_struct *work)
559 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
560 set_beacon_wakeup_period_work);
562 hif_set_beacon_wakeup_period(wvif, wvif->dtim_period,
566 static void wfx_do_unjoin(struct wfx_vif *wvif)
568 mutex_lock(&wvif->wdev->conf_mutex);
570 if (atomic_read(&wvif->scan.in_progress)) {
571 if (wvif->delayed_unjoin)
572 dev_dbg(wvif->wdev->dev,
573 "delayed unjoin is already scheduled\n");
575 wvif->delayed_unjoin = true;
579 wvif->delayed_link_loss = false;
584 if (wvif->state == WFX_STATE_AP)
587 cancel_work_sync(&wvif->update_filtering_work);
588 cancel_work_sync(&wvif->set_beacon_wakeup_period_work);
589 wvif->state = WFX_STATE_PASSIVE;
591 /* Unjoin is a reset. */
592 wfx_tx_flush(wvif->wdev);
593 hif_keep_alive_period(wvif, 0);
594 hif_reset(wvif, false);
595 hif_set_output_power(wvif, wvif->wdev->output_power * 10);
596 wvif->dtim_period = 0;
597 hif_set_macaddr(wvif, wvif->vif->addr);
598 wfx_free_event_queue(wvif);
599 cancel_work_sync(&wvif->event_handler_work);
600 wfx_cqm_bssloss_sm(wvif, 0, 0, 0);
602 /* Disable Block ACKs */
603 hif_set_block_ack_policy(wvif, 0, 0);
605 wvif->disable_beacon_filter = false;
606 wfx_update_filtering(wvif);
607 memset(&wvif->bss_params, 0, sizeof(wvif->bss_params));
608 wvif->setbssparams_done = false;
609 memset(&wvif->ht_info, 0, sizeof(wvif->ht_info));
612 mutex_unlock(&wvif->wdev->conf_mutex);
615 static void wfx_set_mfp(struct wfx_vif *wvif,
616 struct cfg80211_bss *bss)
618 const int pairwise_cipher_suite_count_offset = 8 / sizeof(u16);
619 const int pairwise_cipher_suite_size = 4 / sizeof(u16);
620 const int akm_suite_size = 4 / sizeof(u16);
621 const u16 *ptr = NULL;
625 /* 802.11w protected mgmt frames */
627 /* retrieve MFPC and MFPR flags from beacon or PBRSP */
631 ptr = (const u16 *) ieee80211_bss_get_ie(bss,
635 ptr += pairwise_cipher_suite_count_offset;
636 ptr += 1 + pairwise_cipher_suite_size * *ptr;
637 ptr += 1 + akm_suite_size * *ptr;
638 mfpr = *ptr & BIT(6);
639 mfpc = *ptr & BIT(7);
643 hif_set_mfp(wvif, mfpc, mfpr);
646 /* MUST be called with tx_lock held! It will be unlocked for us. */
647 static void wfx_do_join(struct wfx_vif *wvif)
650 struct ieee80211_bss_conf *conf = &wvif->vif->bss_conf;
651 struct cfg80211_bss *bss = NULL;
652 struct hif_req_join join = {
653 .mode = conf->ibss_joined ? HIF_MODE_IBSS : HIF_MODE_BSS,
654 .preamble_type = conf->use_short_preamble ? HIF_PREAMBLE_SHORT : HIF_PREAMBLE_LONG,
657 .basic_rate_set = wfx_rate_mask_to_hw(wvif->wdev,
661 if (wvif->channel->flags & IEEE80211_CHAN_NO_IR)
662 join.probe_for_join = 0;
667 bssid = wvif->vif->bss_conf.bssid;
669 bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel,
671 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
673 if (!bss && !conf->ibss_joined) {
674 wfx_tx_unlock(wvif->wdev);
678 mutex_lock(&wvif->wdev->conf_mutex);
680 /* Under the conf lock: check scan status and
681 * bail out if it is in progress.
683 if (atomic_read(&wvif->scan.in_progress)) {
684 wfx_tx_unlock(wvif->wdev);
688 /* Sanity check basic rates */
689 if (!join.basic_rate_set)
690 join.basic_rate_set = 7;
692 /* Sanity check beacon interval */
693 if (!wvif->beacon_int)
694 wvif->beacon_int = 1;
696 join.beacon_interval = wvif->beacon_int;
698 // DTIM period will be set on first Beacon
699 wvif->dtim_period = 0;
701 join.channel_number = wvif->channel->hw_value;
702 memcpy(join.bssid, bssid, sizeof(join.bssid));
704 if (!conf->ibss_joined) {
708 ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
710 join.ssid_length = ssidie[1];
711 memcpy(join.ssid, &ssidie[2], join.ssid_length);
716 wfx_tx_flush(wvif->wdev);
718 if (wvif_count(wvif->wdev) <= 1)
719 hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
721 wfx_set_mfp(wvif, bss);
723 /* Perform actual join */
724 wvif->wdev->tx_burst_idx = -1;
725 if (hif_join(wvif, &join)) {
726 ieee80211_connection_loss(wvif->vif);
727 wvif->join_complete_status = -1;
728 /* Tx lock still held, unjoin will clear it. */
729 if (!schedule_work(&wvif->unjoin_work))
730 wfx_tx_unlock(wvif->wdev);
732 wvif->join_complete_status = 0;
733 if (wvif->vif->type == NL80211_IFTYPE_ADHOC)
734 wvif->state = WFX_STATE_IBSS;
736 wvif->state = WFX_STATE_PRE_STA;
737 wfx_tx_unlock(wvif->wdev);
740 wfx_upload_keys(wvif);
742 /* Due to beacon filtering it is possible that the
743 * AP's beacon is not known for the mac80211 stack.
744 * Disable filtering temporary to make sure the stack
745 * receives at least one
747 wvif->disable_beacon_filter = true;
749 wfx_update_filtering(wvif);
752 mutex_unlock(&wvif->wdev->conf_mutex);
754 cfg80211_put_bss(wvif->wdev->hw->wiphy, bss);
757 static void wfx_unjoin_work(struct work_struct *work)
759 struct wfx_vif *wvif = container_of(work, struct wfx_vif, unjoin_work);
762 wfx_tx_unlock(wvif->wdev);
765 int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
766 struct ieee80211_sta *sta)
768 struct wfx_dev *wdev = hw->priv;
769 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
770 struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *) &sta->drv_priv;
771 struct wfx_link_entry *entry;
774 if (wvif->vif->type != NL80211_IFTYPE_AP)
777 sta_priv->vif_id = wvif->id;
778 sta_priv->link_id = wfx_find_link_id(wvif, sta->addr);
779 if (!sta_priv->link_id) {
780 dev_warn(wdev->dev, "mo more link-id available\n");
784 entry = &wvif->link_id_db[sta_priv->link_id - 1];
785 spin_lock_bh(&wvif->ps_state_lock);
786 if ((sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) ==
787 IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
788 wvif->sta_asleep_mask |= BIT(sta_priv->link_id);
789 entry->status = WFX_LINK_HARD;
790 while ((skb = skb_dequeue(&entry->rx_queue)))
791 ieee80211_rx_irqsafe(wdev->hw, skb);
792 spin_unlock_bh(&wvif->ps_state_lock);
796 int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
797 struct ieee80211_sta *sta)
799 struct wfx_dev *wdev = hw->priv;
800 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
801 struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *) &sta->drv_priv;
802 struct wfx_link_entry *entry;
804 if (wvif->vif->type != NL80211_IFTYPE_AP || !sta_priv->link_id)
807 entry = &wvif->link_id_db[sta_priv->link_id - 1];
808 spin_lock_bh(&wvif->ps_state_lock);
809 entry->status = WFX_LINK_RESERVE;
810 entry->timestamp = jiffies;
812 if (!schedule_work(&wvif->link_id_work))
814 spin_unlock_bh(&wvif->ps_state_lock);
815 flush_work(&wvif->link_id_work);
819 static void wfx_set_cts_work(struct work_struct *work)
821 struct wfx_vif *wvif = container_of(work, struct wfx_vif, set_cts_work);
822 u8 erp_ie[3] = { WLAN_EID_ERP_INFO, 1, 0 };
823 struct hif_ie_flags target_frame = {
827 mutex_lock(&wvif->wdev->conf_mutex);
828 erp_ie[2] = wvif->erp_info;
829 mutex_unlock(&wvif->wdev->conf_mutex);
831 hif_erp_use_protection(wvif, erp_ie[2] & WLAN_ERP_USE_PROTECTION);
833 if (wvif->vif->type != NL80211_IFTYPE_STATION)
834 hif_update_ie(wvif, &target_frame, erp_ie, sizeof(erp_ie));
837 static int wfx_start_ap(struct wfx_vif *wvif)
840 struct ieee80211_bss_conf *conf = &wvif->vif->bss_conf;
841 struct hif_req_start start = {
842 .channel_number = wvif->channel->hw_value,
843 .beacon_interval = conf->beacon_int,
844 .dtim_period = conf->dtim_period,
845 .preamble_type = conf->use_short_preamble ? HIF_PREAMBLE_SHORT : HIF_PREAMBLE_LONG,
846 .basic_rate_set = wfx_rate_mask_to_hw(wvif->wdev,
850 memset(start.ssid, 0, sizeof(start.ssid));
851 if (!conf->hidden_ssid) {
852 start.ssid_length = conf->ssid_len;
853 memcpy(start.ssid, conf->ssid, start.ssid_length);
856 wvif->beacon_int = conf->beacon_int;
857 wvif->dtim_period = conf->dtim_period;
859 memset(&wvif->link_id_db, 0, sizeof(wvif->link_id_db));
861 wvif->wdev->tx_burst_idx = -1;
862 ret = hif_start(wvif, &start);
864 ret = wfx_upload_keys(wvif);
866 if (wvif_count(wvif->wdev) <= 1)
867 hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
868 wvif->state = WFX_STATE_AP;
869 wfx_update_filtering(wvif);
874 static int wfx_update_beaconing(struct wfx_vif *wvif)
876 struct ieee80211_bss_conf *conf = &wvif->vif->bss_conf;
878 if (wvif->vif->type == NL80211_IFTYPE_AP) {
879 /* TODO: check if changed channel, band */
880 if (wvif->state != WFX_STATE_AP ||
881 wvif->beacon_int != conf->beacon_int) {
882 wfx_tx_lock_flush(wvif->wdev);
883 if (wvif->state != WFX_STATE_PASSIVE)
884 hif_reset(wvif, false);
885 wvif->state = WFX_STATE_PASSIVE;
887 wfx_tx_unlock(wvif->wdev);
894 static int wfx_upload_beacon(struct wfx_vif *wvif)
897 struct sk_buff *skb = NULL;
898 struct ieee80211_mgmt *mgmt;
899 struct hif_mib_template_frame *p;
901 if (wvif->vif->type == NL80211_IFTYPE_STATION ||
902 wvif->vif->type == NL80211_IFTYPE_MONITOR ||
903 wvif->vif->type == NL80211_IFTYPE_UNSPECIFIED)
906 skb = ieee80211_beacon_get(wvif->wdev->hw, wvif->vif);
911 p = (struct hif_mib_template_frame *) skb_push(skb, 4);
912 p->frame_type = HIF_TMPLT_BCN;
913 p->init_rate = API_RATE_INDEX_B_1MBPS; /* 1Mbps DSSS */
914 p->frame_length = cpu_to_le16(skb->len - 4);
916 ret = hif_set_template_frame(wvif, p);
922 /* TODO: Distill probe resp; remove TIM and any other beacon-specific
925 mgmt = (void *)skb->data;
926 mgmt->frame_control =
927 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
929 p->frame_type = HIF_TMPLT_PRBRES;
931 ret = hif_set_template_frame(wvif, p);
932 wfx_fwd_probe_req(wvif, false);
939 static int wfx_is_ht(const struct wfx_ht_info *ht_info)
941 return ht_info->channel_type != NL80211_CHAN_NO_HT;
944 static int wfx_ht_greenfield(const struct wfx_ht_info *ht_info)
946 return wfx_is_ht(ht_info) &&
947 (ht_info->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
948 !(ht_info->operation_mode &
949 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
952 static int wfx_ht_ampdu_density(const struct wfx_ht_info *ht_info)
954 if (!wfx_is_ht(ht_info))
956 return ht_info->ht_cap.ampdu_density;
959 static void wfx_join_finalize(struct wfx_vif *wvif,
960 struct ieee80211_bss_conf *info)
962 struct ieee80211_sta *sta = NULL;
963 struct hif_mib_set_association_mode association_mode = { };
965 if (info->dtim_period)
966 wvif->dtim_period = info->dtim_period;
967 wvif->beacon_int = info->beacon_int;
970 if (info->bssid && !info->ibss_joined)
971 sta = ieee80211_find_sta(wvif->vif, info->bssid);
973 wvif->ht_info.ht_cap = sta->ht_cap;
974 wvif->bss_params.operational_rate_set =
975 wfx_rate_mask_to_hw(wvif->wdev, sta->supp_rates[wvif->channel->band]);
976 wvif->ht_info.operation_mode = info->ht_operation_mode;
978 memset(&wvif->ht_info, 0, sizeof(wvif->ht_info));
979 wvif->bss_params.operational_rate_set = -1;
983 /* Non Greenfield stations present */
984 if (wvif->ht_info.operation_mode &
985 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
986 hif_dual_cts_protection(wvif, true);
988 hif_dual_cts_protection(wvif, false);
990 association_mode.preambtype_use = 1;
991 association_mode.mode = 1;
992 association_mode.rateset = 1;
993 association_mode.spacing = 1;
994 association_mode.preamble_type = info->use_short_preamble ? HIF_PREAMBLE_SHORT : HIF_PREAMBLE_LONG;
995 association_mode.basic_rate_set = cpu_to_le32(wfx_rate_mask_to_hw(wvif->wdev, info->basic_rates));
996 association_mode.mixed_or_greenfield_type = wfx_ht_greenfield(&wvif->ht_info);
997 association_mode.mpdu_start_spacing = wfx_ht_ampdu_density(&wvif->ht_info);
999 wfx_cqm_bssloss_sm(wvif, 0, 0, 0);
1000 cancel_work_sync(&wvif->unjoin_work);
1002 wvif->bss_params.beacon_lost_count = 20;
1003 wvif->bss_params.aid = info->aid;
1005 if (wvif->dtim_period < 1)
1006 wvif->dtim_period = 1;
1008 hif_set_association_mode(wvif, &association_mode);
1010 if (!info->ibss_joined) {
1011 hif_keep_alive_period(wvif, 30 /* sec */);
1012 hif_set_bss_params(wvif, &wvif->bss_params);
1013 wvif->setbssparams_done = true;
1014 wfx_set_beacon_wakeup_period_work(&wvif->set_beacon_wakeup_period_work);
1015 wfx_set_pm(wvif, &wvif->powersave_mode);
1019 void wfx_bss_info_changed(struct ieee80211_hw *hw,
1020 struct ieee80211_vif *vif,
1021 struct ieee80211_bss_conf *info,
1024 struct wfx_dev *wdev = hw->priv;
1025 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1026 bool do_join = false;
1030 mutex_lock(&wdev->conf_mutex);
1032 /* TODO: BSS_CHANGED_QOS */
1033 if (changed & BSS_CHANGED_ARP_FILTER) {
1034 struct hif_mib_arp_ip_addr_table filter = { };
1036 nb_arp_addr = info->arp_addr_cnt;
1037 if (nb_arp_addr <= 0 || nb_arp_addr > HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES)
1040 for (i = 0; i < HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES; i++) {
1041 filter.condition_idx = i;
1042 if (i < nb_arp_addr) {
1043 // Caution: type of arp_addr_list[i] is __be32
1044 memcpy(filter.ipv4_address,
1045 &info->arp_addr_list[i],
1046 sizeof(filter.ipv4_address));
1047 filter.arp_enable = HIF_ARP_NS_FILTERING_ENABLE;
1049 filter.arp_enable = HIF_ARP_NS_FILTERING_DISABLE;
1051 hif_set_arp_ipv4_filter(wvif, &filter);
1056 (BSS_CHANGED_BEACON | BSS_CHANGED_AP_PROBE_RESP |
1057 BSS_CHANGED_BSSID | BSS_CHANGED_SSID | BSS_CHANGED_IBSS)) {
1058 wvif->beacon_int = info->beacon_int;
1059 wfx_update_beaconing(wvif);
1060 wfx_upload_beacon(wvif);
1063 if (changed & BSS_CHANGED_BEACON_ENABLED &&
1064 wvif->state != WFX_STATE_IBSS) {
1065 if (wvif->enable_beacon != info->enable_beacon) {
1066 hif_beacon_transmit(wvif, info->enable_beacon);
1067 wvif->enable_beacon = info->enable_beacon;
1071 /* assoc/disassoc, or maybe AID changed */
1072 if (changed & BSS_CHANGED_ASSOC) {
1073 wfx_tx_lock_flush(wdev);
1074 wvif->wep_default_key_id = -1;
1075 wfx_tx_unlock(wdev);
1078 if (changed & BSS_CHANGED_ASSOC && !info->assoc &&
1079 (wvif->state == WFX_STATE_STA || wvif->state == WFX_STATE_IBSS)) {
1080 /* Shedule unjoin work */
1082 if (!schedule_work(&wvif->unjoin_work))
1083 wfx_tx_unlock(wdev);
1085 if (changed & BSS_CHANGED_BEACON_INT) {
1086 if (info->ibss_joined)
1088 else if (wvif->state == WFX_STATE_AP)
1089 wfx_update_beaconing(wvif);
1092 if (changed & BSS_CHANGED_BSSID)
1096 (BSS_CHANGED_ASSOC | BSS_CHANGED_BSSID |
1097 BSS_CHANGED_IBSS | BSS_CHANGED_BASIC_RATES |
1100 if (wvif->state < WFX_STATE_PRE_STA) {
1101 ieee80211_connection_loss(vif);
1102 mutex_unlock(&wdev->conf_mutex);
1104 } else if (wvif->state == WFX_STATE_PRE_STA) {
1105 wvif->state = WFX_STATE_STA;
1111 if (info->assoc || info->ibss_joined)
1112 wfx_join_finalize(wvif, info);
1114 memset(&wvif->bss_params, 0,
1115 sizeof(wvif->bss_params));
1119 /* ERP Protection */
1120 if (changed & (BSS_CHANGED_ASSOC |
1121 BSS_CHANGED_ERP_CTS_PROT |
1122 BSS_CHANGED_ERP_PREAMBLE)) {
1123 u32 prev_erp_info = wvif->erp_info;
1125 if (info->use_cts_prot)
1126 wvif->erp_info |= WLAN_ERP_USE_PROTECTION;
1127 else if (!(prev_erp_info & WLAN_ERP_NON_ERP_PRESENT))
1128 wvif->erp_info &= ~WLAN_ERP_USE_PROTECTION;
1130 if (info->use_short_preamble)
1131 wvif->erp_info |= WLAN_ERP_BARKER_PREAMBLE;
1133 wvif->erp_info &= ~WLAN_ERP_BARKER_PREAMBLE;
1135 if (prev_erp_info != wvif->erp_info)
1136 schedule_work(&wvif->set_cts_work);
1139 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_SLOT))
1140 hif_slot_time(wvif, info->use_short_slot ? 9 : 20);
1142 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_CQM)) {
1143 struct hif_mib_rcpi_rssi_threshold th = {
1144 .rolling_average_count = 8,
1148 wvif->cqm_rssi_thold = info->cqm_rssi_thold;
1150 if (!info->cqm_rssi_thold && !info->cqm_rssi_hyst) {
1154 /* FIXME It's not a correct way of setting threshold.
1155 * Upper and lower must be set equal here and adjusted
1156 * in callback. However current implementation is much
1157 * more reliable and stable.
1159 /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
1160 * RSSI = RCPI / 2 - 110
1162 th.upper_threshold = info->cqm_rssi_thold + info->cqm_rssi_hyst;
1163 th.upper_threshold = (th.upper_threshold + 110) * 2;
1164 th.lower_threshold = info->cqm_rssi_thold;
1165 th.lower_threshold = (th.lower_threshold + 110) * 2;
1167 hif_set_rcpi_rssi_threshold(wvif, &th);
1170 if (changed & BSS_CHANGED_TXPOWER &&
1171 info->txpower != wdev->output_power) {
1172 wdev->output_power = info->txpower;
1173 hif_set_output_power(wvif, wdev->output_power * 10);
1175 mutex_unlock(&wdev->conf_mutex);
1178 wfx_tx_lock_flush(wdev);
1179 wfx_do_join(wvif); /* Will unlock it for us */
1183 static void wfx_ps_notify(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd,
1188 spin_lock_bh(&wvif->ps_state_lock);
1189 /* Zero link id means "for all link IDs" */
1192 } else if (notify_cmd != STA_NOTIFY_AWAKE) {
1193 dev_warn(wvif->wdev->dev, "unsupported notify command\n");
1196 bit = wvif->link_id_map;
1198 prev = wvif->sta_asleep_mask & bit;
1200 switch (notify_cmd) {
1201 case STA_NOTIFY_SLEEP:
1203 if (wvif->mcast_buffered && !wvif->sta_asleep_mask)
1204 schedule_work(&wvif->mcast_start_work);
1205 wvif->sta_asleep_mask |= bit;
1208 case STA_NOTIFY_AWAKE:
1210 wvif->sta_asleep_mask &= ~bit;
1211 wvif->pspoll_mask &= ~bit;
1212 if (link_id && !wvif->sta_asleep_mask)
1213 schedule_work(&wvif->mcast_stop_work);
1214 wfx_bh_request_tx(wvif->wdev);
1218 spin_unlock_bh(&wvif->ps_state_lock);
1221 void wfx_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1222 enum sta_notify_cmd notify_cmd, struct ieee80211_sta *sta)
1224 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1225 struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *) &sta->drv_priv;
1227 wfx_ps_notify(wvif, notify_cmd, sta_priv->link_id);
1230 static int wfx_set_tim_impl(struct wfx_vif *wvif, bool aid0_bit_set)
1232 struct sk_buff *skb;
1233 struct hif_ie_flags target_frame = {
1236 u16 tim_offset, tim_length;
1239 skb = ieee80211_beacon_get_tim(wvif->wdev->hw, wvif->vif,
1240 &tim_offset, &tim_length);
1242 if (!__wfx_flush(wvif->wdev, true))
1243 wfx_tx_unlock(wvif->wdev);
1246 tim_ptr = skb->data + tim_offset;
1248 if (tim_offset && tim_length >= 6) {
1249 /* Ignore DTIM count from mac80211:
1250 * firmware handles DTIM internally.
1254 /* Set/reset aid0 bit */
1261 hif_update_ie(wvif, &target_frame, tim_ptr, tim_length);
1267 static void wfx_set_tim_work(struct work_struct *work)
1269 struct wfx_vif *wvif = container_of(work, struct wfx_vif, set_tim_work);
1271 wfx_set_tim_impl(wvif, wvif->aid0_bit_set);
1274 int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
1276 struct wfx_dev *wdev = hw->priv;
1277 struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *) &sta->drv_priv;
1278 struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
1280 schedule_work(&wvif->set_tim_work);
1284 static void wfx_mcast_start_work(struct work_struct *work)
1286 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
1288 long tmo = wvif->dtim_period * TU_TO_JIFFIES(wvif->beacon_int + 20);
1290 cancel_work_sync(&wvif->mcast_stop_work);
1291 if (!wvif->aid0_bit_set) {
1292 wfx_tx_lock_flush(wvif->wdev);
1293 wfx_set_tim_impl(wvif, true);
1294 wvif->aid0_bit_set = true;
1295 mod_timer(&wvif->mcast_timeout, jiffies + tmo);
1296 wfx_tx_unlock(wvif->wdev);
1300 static void wfx_mcast_stop_work(struct work_struct *work)
1302 struct wfx_vif *wvif = container_of(work, struct wfx_vif,
1305 if (wvif->aid0_bit_set) {
1306 del_timer_sync(&wvif->mcast_timeout);
1307 wfx_tx_lock_flush(wvif->wdev);
1308 wvif->aid0_bit_set = false;
1309 wfx_set_tim_impl(wvif, false);
1310 wfx_tx_unlock(wvif->wdev);
1314 static void wfx_mcast_timeout(struct timer_list *t)
1316 struct wfx_vif *wvif = from_timer(wvif, t, mcast_timeout);
1318 dev_warn(wvif->wdev->dev, "multicast delivery timeout\n");
1319 spin_lock_bh(&wvif->ps_state_lock);
1320 wvif->mcast_tx = wvif->aid0_bit_set && wvif->mcast_buffered;
1322 wfx_bh_request_tx(wvif->wdev);
1323 spin_unlock_bh(&wvif->ps_state_lock);
1326 int wfx_ampdu_action(struct ieee80211_hw *hw,
1327 struct ieee80211_vif *vif,
1328 struct ieee80211_ampdu_params *params)
1330 /* Aggregation is implemented fully in firmware,
1331 * including block ack negotiation. Do not allow
1332 * mac80211 stack to do anything: it interferes with
1336 /* Note that we still need this function stubbed. */
1341 void wfx_suspend_resume(struct wfx_vif *wvif,
1342 struct hif_ind_suspend_resume_tx *arg)
1344 if (arg->suspend_resume_flags.bc_mc_only) {
1345 bool cancel_tmo = false;
1347 spin_lock_bh(&wvif->ps_state_lock);
1348 if (!arg->suspend_resume_flags.resume)
1349 wvif->mcast_tx = false;
1351 wvif->mcast_tx = wvif->aid0_bit_set &&
1352 wvif->mcast_buffered;
1353 if (wvif->mcast_tx) {
1355 wfx_bh_request_tx(wvif->wdev);
1357 spin_unlock_bh(&wvif->ps_state_lock);
1359 del_timer_sync(&wvif->mcast_timeout);
1360 } else if (arg->suspend_resume_flags.resume) {
1361 // FIXME: should change each station status independently
1362 wfx_ps_notify(wvif, STA_NOTIFY_AWAKE, 0);
1363 wfx_bh_request_tx(wvif->wdev);
1365 // FIXME: should change each station status independently
1366 wfx_ps_notify(wvif, STA_NOTIFY_SLEEP, 0);
1370 int wfx_add_chanctx(struct ieee80211_hw *hw,
1371 struct ieee80211_chanctx_conf *conf)
1376 void wfx_remove_chanctx(struct ieee80211_hw *hw,
1377 struct ieee80211_chanctx_conf *conf)
1381 void wfx_change_chanctx(struct ieee80211_hw *hw,
1382 struct ieee80211_chanctx_conf *conf,
1387 int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1388 struct ieee80211_chanctx_conf *conf)
1390 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1391 struct ieee80211_channel *ch = conf->def.chan;
1393 WARN(wvif->channel, "channel overwrite");
1395 wvif->ht_info.channel_type = cfg80211_get_chandef_type(&conf->def);
1400 void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw,
1401 struct ieee80211_vif *vif,
1402 struct ieee80211_chanctx_conf *conf)
1404 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1405 struct ieee80211_channel *ch = conf->def.chan;
1407 WARN(wvif->channel != ch, "channel mismatch");
1408 wvif->channel = NULL;
1411 int wfx_config(struct ieee80211_hw *hw, u32 changed)
1414 struct wfx_dev *wdev = hw->priv;
1415 struct ieee80211_conf *conf = &hw->conf;
1416 struct wfx_vif *wvif;
1418 // FIXME: Interface id should not been hardcoded
1419 wvif = wdev_to_wvif(wdev, 0);
1421 WARN(1, "interface 0 does not exist anymore");
1425 down(&wvif->scan.lock);
1426 mutex_lock(&wdev->conf_mutex);
1427 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1428 wdev->output_power = conf->power_level;
1429 hif_set_output_power(wvif, wdev->output_power * 10);
1432 if (changed & IEEE80211_CONF_CHANGE_PS) {
1434 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
1435 memset(&wvif->powersave_mode, 0,
1436 sizeof(wvif->powersave_mode));
1437 if (conf->flags & IEEE80211_CONF_PS) {
1438 wvif->powersave_mode.pm_mode.enter_psm = 1;
1439 if (conf->dynamic_ps_timeout > 0) {
1440 wvif->powersave_mode.pm_mode.fast_psm = 1;
1442 * Firmware does not support more than
1445 wvif->powersave_mode.fast_psm_idle_period =
1446 min(conf->dynamic_ps_timeout *
1450 if (wvif->state == WFX_STATE_STA && wvif->bss_params.aid)
1451 wfx_set_pm(wvif, &wvif->powersave_mode);
1453 wvif = wdev_to_wvif(wdev, 0);
1456 mutex_unlock(&wdev->conf_mutex);
1457 up(&wvif->scan.lock);
1461 int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1464 struct wfx_dev *wdev = hw->priv;
1465 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1466 // FIXME: parameters are set by kernel juste after interface_add.
1467 // Keep struct hif_req_edca_queue_params blank?
1468 struct hif_req_edca_queue_params default_edca_params[] = {
1469 [IEEE80211_AC_VO] = {
1470 .queue_id = HIF_QUEUE_ID_VOICE,
1474 .tx_op_limit = TXOP_UNIT * 47,
1476 [IEEE80211_AC_VI] = {
1477 .queue_id = HIF_QUEUE_ID_VIDEO,
1481 .tx_op_limit = TXOP_UNIT * 94,
1483 [IEEE80211_AC_BE] = {
1484 .queue_id = HIF_QUEUE_ID_BESTEFFORT,
1488 .tx_op_limit = TXOP_UNIT * 0,
1490 [IEEE80211_AC_BK] = {
1491 .queue_id = HIF_QUEUE_ID_BACKGROUND,
1495 .tx_op_limit = TXOP_UNIT * 0,
1499 BUILD_BUG_ON(ARRAY_SIZE(default_edca_params) != ARRAY_SIZE(wvif->edca.params));
1500 if (wfx_api_older_than(wdev, 2, 0)) {
1501 default_edca_params[IEEE80211_AC_BE].queue_id = HIF_QUEUE_ID_BACKGROUND;
1502 default_edca_params[IEEE80211_AC_BK].queue_id = HIF_QUEUE_ID_BESTEFFORT;
1505 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1506 IEEE80211_VIF_SUPPORTS_UAPSD |
1507 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1509 mutex_lock(&wdev->conf_mutex);
1511 switch (vif->type) {
1512 case NL80211_IFTYPE_STATION:
1513 case NL80211_IFTYPE_ADHOC:
1514 case NL80211_IFTYPE_AP:
1517 mutex_unlock(&wdev->conf_mutex);
1521 for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
1522 if (!wdev->vif[i]) {
1528 if (i == ARRAY_SIZE(wdev->vif)) {
1529 mutex_unlock(&wdev->conf_mutex);
1532 // FIXME: prefer use of container_of() to get vif
1536 INIT_WORK(&wvif->link_id_work, wfx_link_id_work);
1537 INIT_DELAYED_WORK(&wvif->link_id_gc_work, wfx_link_id_gc_work);
1539 spin_lock_init(&wvif->ps_state_lock);
1540 INIT_WORK(&wvif->set_tim_work, wfx_set_tim_work);
1542 INIT_WORK(&wvif->mcast_start_work, wfx_mcast_start_work);
1543 INIT_WORK(&wvif->mcast_stop_work, wfx_mcast_stop_work);
1544 timer_setup(&wvif->mcast_timeout, wfx_mcast_timeout, 0);
1546 wvif->setbssparams_done = false;
1547 mutex_init(&wvif->bss_loss_lock);
1548 INIT_DELAYED_WORK(&wvif->bss_loss_work, wfx_bss_loss_work);
1550 wvif->wep_default_key_id = -1;
1551 INIT_WORK(&wvif->wep_key_work, wfx_wep_key_work);
1553 sema_init(&wvif->scan.lock, 1);
1554 INIT_WORK(&wvif->scan.work, wfx_scan_work);
1555 INIT_DELAYED_WORK(&wvif->scan.timeout, wfx_scan_timeout);
1557 spin_lock_init(&wvif->event_queue_lock);
1558 INIT_LIST_HEAD(&wvif->event_queue);
1559 INIT_WORK(&wvif->event_handler_work, wfx_event_handler_work);
1561 init_completion(&wvif->set_pm_mode_complete);
1562 complete(&wvif->set_pm_mode_complete);
1563 INIT_WORK(&wvif->set_beacon_wakeup_period_work,
1564 wfx_set_beacon_wakeup_period_work);
1565 INIT_WORK(&wvif->update_filtering_work, wfx_update_filtering_work);
1566 INIT_WORK(&wvif->bss_params_work, wfx_bss_params_work);
1567 INIT_WORK(&wvif->set_cts_work, wfx_set_cts_work);
1568 INIT_WORK(&wvif->unjoin_work, wfx_unjoin_work);
1570 mutex_unlock(&wdev->conf_mutex);
1572 hif_set_macaddr(wvif, vif->addr);
1573 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1574 memcpy(&wvif->edca.params[i], &default_edca_params[i],
1575 sizeof(default_edca_params[i]));
1576 wvif->edca.uapsd_enable[i] = false;
1577 hif_set_edca_queue_params(wvif, &wvif->edca.params[i]);
1579 wfx_set_uapsd_param(wvif, &wvif->edca);
1581 wfx_tx_policy_init(wvif);
1583 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
1584 // Combo mode does not support Block Acks. We can re-enable them
1585 if (wvif_count(wdev) == 1)
1586 hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
1588 hif_set_block_ack_policy(wvif, 0x00, 0x00);
1589 // Combo force powersave mode. We can re-enable it now
1590 wfx_set_pm(wvif, &wvif->powersave_mode);
1595 void wfx_remove_interface(struct ieee80211_hw *hw,
1596 struct ieee80211_vif *vif)
1598 struct wfx_dev *wdev = hw->priv;
1599 struct wfx_vif *wvif = (struct wfx_vif *) vif->drv_priv;
1602 // If scan is in progress, stop it
1603 while (down_trylock(&wvif->scan.lock))
1605 up(&wvif->scan.lock);
1606 wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
1608 mutex_lock(&wdev->conf_mutex);
1609 switch (wvif->state) {
1610 case WFX_STATE_PRE_STA:
1612 case WFX_STATE_IBSS:
1613 wfx_tx_lock_flush(wdev);
1614 if (!schedule_work(&wvif->unjoin_work))
1615 wfx_tx_unlock(wdev);
1618 for (i = 0; wvif->link_id_map; ++i) {
1619 if (wvif->link_id_map & BIT(i)) {
1620 wfx_unmap_link(wvif, i);
1621 wvif->link_id_map &= ~BIT(i);
1624 memset(wvif->link_id_db, 0, sizeof(wvif->link_id_db));
1625 wvif->sta_asleep_mask = 0;
1626 wvif->enable_beacon = false;
1627 wvif->mcast_tx = false;
1628 wvif->aid0_bit_set = false;
1629 wvif->mcast_buffered = false;
1630 wvif->pspoll_mask = 0;
1631 /* reset.link_id = 0; */
1632 hif_reset(wvif, false);
1638 wvif->state = WFX_STATE_PASSIVE;
1639 wfx_tx_queues_wait_empty_vif(wvif);
1640 wfx_tx_unlock(wdev);
1642 /* FIXME: In add to reset MAC address, try to reset interface */
1643 hif_set_macaddr(wvif, NULL);
1645 cancel_delayed_work_sync(&wvif->scan.timeout);
1647 wfx_cqm_bssloss_sm(wvif, 0, 0, 0);
1648 cancel_work_sync(&wvif->unjoin_work);
1649 cancel_delayed_work_sync(&wvif->link_id_gc_work);
1650 del_timer_sync(&wvif->mcast_timeout);
1651 wfx_free_event_queue(wvif);
1653 wdev->vif[wvif->id] = NULL;
1656 mutex_unlock(&wdev->conf_mutex);
1658 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
1659 // Combo mode does not support Block Acks. We can re-enable them
1660 if (wvif_count(wdev) == 1)
1661 hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
1663 hif_set_block_ack_policy(wvif, 0x00, 0x00);
1664 // Combo force powersave mode. We can re-enable it now
1665 wfx_set_pm(wvif, &wvif->powersave_mode);
1669 int wfx_start(struct ieee80211_hw *hw)
1674 void wfx_stop(struct ieee80211_hw *hw)
1676 struct wfx_dev *wdev = hw->priv;
1678 wfx_tx_lock_flush(wdev);
1679 mutex_lock(&wdev->conf_mutex);
1680 wfx_tx_queues_clear(wdev);
1681 mutex_unlock(&wdev->conf_mutex);
1682 wfx_tx_unlock(wdev);
1683 WARN(atomic_read(&wdev->tx_lock), "tx_lock is locked");