1e16e7f07SJérôme Pouiller // SPDX-License-Identifier: GPL-2.0-only
2e16e7f07SJérôme Pouiller /*
3e16e7f07SJérôme Pouiller * Implementation of mac80211 API.
4e16e7f07SJérôme Pouiller *
5f9dc9f37SJérôme Pouiller * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6e16e7f07SJérôme Pouiller * Copyright (c) 2010, ST-Ericsson
7e16e7f07SJérôme Pouiller */
816d7586dSGreg Kroah-Hartman #include <linux/etherdevice.h>
9e16e7f07SJérôme Pouiller #include <net/mac80211.h>
10e16e7f07SJérôme Pouiller
11e16e7f07SJérôme Pouiller #include "sta.h"
12e16e7f07SJérôme Pouiller #include "wfx.h"
1316d7586dSGreg Kroah-Hartman #include "bus.h"
1416d7586dSGreg Kroah-Hartman #include "fwio.h"
1516d7586dSGreg Kroah-Hartman #include "bh.h"
161a61af0fSJérôme Pouiller #include "key.h"
1716d7586dSGreg Kroah-Hartman #include "scan.h"
1816d7586dSGreg Kroah-Hartman #include "debug.h"
191a61af0fSJérôme Pouiller #include "hif_tx.h"
20e16e7f07SJérôme Pouiller #include "hif_tx_mib.h"
2140115bbcSJérôme Pouiller
2240115bbcSJérôme Pouiller #define HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES 2
231d52d299SJérôme Pouiller
wfx_cooling_timeout_work(struct work_struct * work)241d52d299SJérôme Pouiller void wfx_cooling_timeout_work(struct work_struct *work)
25381d3295SJérôme Pouiller {
261d52d299SJérôme Pouiller struct wfx_dev *wdev = container_of(to_delayed_work(work), struct wfx_dev,
271d52d299SJérôme Pouiller cooling_timeout_work);
281d52d299SJérôme Pouiller
291d52d299SJérôme Pouiller wdev->chip_frozen = true;
301d52d299SJérôme Pouiller wfx_tx_unlock(wdev);
311d52d299SJérôme Pouiller }
321d52d299SJérôme Pouiller
wfx_suspend_hot_dev(struct wfx_dev * wdev,enum sta_notify_cmd cmd)331d52d299SJérôme Pouiller void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd)
341d52d299SJérôme Pouiller {
3563aac5dbSJérôme Pouiller if (cmd == STA_NOTIFY_AWAKE) {
361d52d299SJérôme Pouiller /* Device recover normal temperature */
371d52d299SJérôme Pouiller if (cancel_delayed_work(&wdev->cooling_timeout_work))
381d52d299SJérôme Pouiller wfx_tx_unlock(wdev);
3963aac5dbSJérôme Pouiller } else {
401d52d299SJérôme Pouiller /* Device is too hot */
411d52d299SJérôme Pouiller schedule_delayed_work(&wdev->cooling_timeout_work, 10 * HZ);
421d52d299SJérôme Pouiller wfx_tx_lock(wdev);
431d52d299SJérôme Pouiller }
441d52d299SJérôme Pouiller }
452c69b2daSJérôme Pouiller
wfx_filter_beacon(struct wfx_vif * wvif,bool filter_beacon)4640115bbcSJérôme Pouiller static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
479d3586feSJérôme Pouiller {
4840115bbcSJérôme Pouiller static const struct wfx_hif_ie_table_entry filter_ies[] = {
4940115bbcSJérôme Pouiller {
5040115bbcSJérôme Pouiller .ie_id = WLAN_EID_VENDOR_SPECIFIC,
5140115bbcSJérôme Pouiller .has_changed = 1,
5240115bbcSJérôme Pouiller .no_longer = 1,
5340115bbcSJérôme Pouiller .has_appeared = 1,
5440115bbcSJérôme Pouiller .oui = { 0x50, 0x6F, 0x9A },
5540115bbcSJérôme Pouiller }, {
5640115bbcSJérôme Pouiller .ie_id = WLAN_EID_HT_OPERATION,
5740115bbcSJérôme Pouiller .has_changed = 1,
5840115bbcSJérôme Pouiller .no_longer = 1,
5940115bbcSJérôme Pouiller .has_appeared = 1,
6040115bbcSJérôme Pouiller }, {
6140115bbcSJérôme Pouiller .ie_id = WLAN_EID_ERP_INFO,
6240115bbcSJérôme Pouiller .has_changed = 1,
6340115bbcSJérôme Pouiller .no_longer = 1,
64583f188eSJérôme Pouiller .has_appeared = 1,
65583f188eSJérôme Pouiller }, {
66583f188eSJérôme Pouiller .ie_id = WLAN_EID_CHANNEL_SWITCH,
67583f188eSJérôme Pouiller .has_changed = 1,
68583f188eSJérôme Pouiller .no_longer = 1,
6940115bbcSJérôme Pouiller .has_appeared = 1,
7040115bbcSJérôme Pouiller }
7140115bbcSJérôme Pouiller };
722c69b2daSJérôme Pouiller
731c780482SJérôme Pouiller if (!filter_beacon) {
7440115bbcSJérôme Pouiller wfx_hif_beacon_filter_control(wvif, 0, 1);
75381d3295SJérôme Pouiller } else {
76381d3295SJérôme Pouiller wfx_hif_set_beacon_filter_table(wvif, ARRAY_SIZE(filter_ies), filter_ies);
7740115bbcSJérôme Pouiller wfx_hif_beacon_filter_control(wvif, HIF_BEACON_FILTER_ENABLE, 0);
782c69b2daSJérôme Pouiller }
792c69b2daSJérôme Pouiller }
80b356aed9SJérôme Pouiller
wfx_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 unused)81b356aed9SJérôme Pouiller void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
8240115bbcSJérôme Pouiller unsigned int *total_flags, u64 unused)
8399cd05d6SJérôme Pouiller {
842c33360bSJaehee Park bool filter_bssid, filter_prbreq, filter_beacon;
852c33360bSJaehee Park struct ieee80211_vif *vif = NULL;
862c33360bSJaehee Park struct wfx_dev *wdev = hw->priv;
8740115bbcSJérôme Pouiller struct wfx_vif *wvif = NULL;
8863aac5dbSJérôme Pouiller
8963aac5dbSJérôme Pouiller /* Notes:
9063aac5dbSJérôme Pouiller * - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered
9163aac5dbSJérôme Pouiller * - PS-Poll (FIF_PSPOLL) are never filtered
9263aac5dbSJérôme Pouiller * - RTS, CTS and Ack (FIF_CONTROL) are always filtered
93f545b23dSJérôme Pouiller * - Broken frames (FIF_FCSFAIL and FIF_PLCPFAIL) are always filtered
94f545b23dSJérôme Pouiller * - Firmware does (yet) allow to forward unicast traffic sent to other stations (aka.
9563aac5dbSJérôme Pouiller * promiscuous mode)
96b460713aSJérôme Pouiller */
97b460713aSJérôme Pouiller *total_flags &= FIF_BCN_PRBRESP_PROMISC | FIF_ALLMULTI | FIF_OTHER_BSS |
9840115bbcSJérôme Pouiller FIF_PROBE_REQ | FIF_PSPOLL;
99f091bcb6SJérôme Pouiller
10004106ec5SJérôme Pouiller /* Filters are ignored during the scan. No frames are filtered. */
101f091bcb6SJérôme Pouiller if (mutex_is_locked(&wdev->scan_lock))
102f091bcb6SJérôme Pouiller return;
1030f66c31eSJérôme Pouiller
10440115bbcSJérôme Pouiller mutex_lock(&wdev->conf_mutex);
10563aac5dbSJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
10663aac5dbSJérôme Pouiller /* Note: FIF_BCN_PRBRESP_PROMISC covers probe response and
10763aac5dbSJérôme Pouiller * beacons from other BSS
108b460713aSJérôme Pouiller */
1092c69b2daSJérôme Pouiller if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
110b460713aSJérôme Pouiller filter_beacon = false;
1112c69b2daSJérôme Pouiller else
1122c69b2daSJérôme Pouiller filter_beacon = true;
113b460713aSJérôme Pouiller wfx_filter_beacon(wvif, filter_beacon);
114b460713aSJérôme Pouiller
115a558395dSJérôme Pouiller if (*total_flags & FIF_OTHER_BSS)
116b460713aSJérôme Pouiller filter_bssid = false;
117a558395dSJérôme Pouiller else
118b460713aSJérôme Pouiller filter_bssid = true;
1192c33360bSJaehee Park
12063aac5dbSJérôme Pouiller vif = wvif_to_vif(wvif);
1212c33360bSJaehee Park /* In AP mode, chip can reply to probe request itself */
122ed4a707dSJérôme Pouiller if (*total_flags & FIF_PROBE_REQ && vif->type == NL80211_IFTYPE_AP) {
123ed4a707dSJérôme Pouiller dev_dbg(wdev->dev, "do not forward probe request in AP mode\n");
124ed4a707dSJérôme Pouiller *total_flags &= ~FIF_PROBE_REQ;
125ed4a707dSJérôme Pouiller }
126b460713aSJérôme Pouiller
127a558395dSJérôme Pouiller if (*total_flags & FIF_PROBE_REQ)
128b460713aSJérôme Pouiller filter_prbreq = false;
129a558395dSJérôme Pouiller else
1301c780482SJérôme Pouiller filter_prbreq = true;
13140115bbcSJérôme Pouiller wfx_hif_set_rx_filter(wvif, filter_bssid, filter_prbreq);
1320f66c31eSJérôme Pouiller }
13340115bbcSJérôme Pouiller mutex_unlock(&wdev->conf_mutex);
13440115bbcSJérôme Pouiller }
135ce59858bSJulius Hemanth Pitti
wfx_get_ps_timeout(struct wfx_vif * wvif,bool * enable_ps)13697e587bdSJérôme Pouiller static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
137f98138a1SJérôme Pouiller {
138398999daSJérôme Pouiller struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
1392c33360bSJaehee Park struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
14097e587bdSJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
141f276e20bSJohannes Berg
142398999daSJérôme Pouiller WARN(!vif->cfg.assoc && enable_ps,
1432c33360bSJaehee Park "enable_ps is reliable only if associated");
1442c33360bSJaehee Park if (wdev_to_wvif(wvif->wdev, 0)) {
1452c33360bSJaehee Park struct wfx_vif *wvif_ch0 = wdev_to_wvif(wvif->wdev, 0);
1462c33360bSJaehee Park struct ieee80211_vif *vif_ch0 = wvif_to_vif(wvif_ch0);
1476092077aSJohannes Berg
1482c33360bSJaehee Park chan0 = vif_ch0->bss_conf.chanreq.oper.chan;
1492c33360bSJaehee Park }
1502c33360bSJaehee Park if (wdev_to_wvif(wvif->wdev, 1)) {
1512c33360bSJaehee Park struct wfx_vif *wvif_ch1 = wdev_to_wvif(wvif->wdev, 1);
1522c33360bSJaehee Park struct ieee80211_vif *vif_ch1 = wvif_to_vif(wvif_ch1);
1536092077aSJohannes Berg
1542c33360bSJaehee Park chan1 = vif_ch1->bss_conf.chanreq.oper.chan;
1552c33360bSJaehee Park }
156a5a8eb1fSJérôme Pouiller if (chan0 && chan1 && vif->type != NL80211_IFTYPE_AP) {
15763aac5dbSJérôme Pouiller if (chan0->hw_value == chan1->hw_value) {
158a5a8eb1fSJérôme Pouiller /* It is useless to enable PS if channels are the same. */
159a5a8eb1fSJérôme Pouiller if (enable_ps)
160a3b8008dSJohannes Berg *enable_ps = false;
161a5a8eb1fSJérôme Pouiller if (vif->cfg.assoc && vif->cfg.ps)
162a5a8eb1fSJérôme Pouiller dev_info(wvif->wdev->dev, "ignoring requested PS mode");
163cc5e3fffSSrivathsa Dara return -1;
164f545b23dSJérôme Pouiller }
165398999daSJérôme Pouiller /* It is necessary to enable PS if channels are different. */
166398999daSJérôme Pouiller if (enable_ps)
16742f14190SJérôme Pouiller *enable_ps = true;
168398999daSJérôme Pouiller if (wfx_api_older_than(wvif->wdev, 3, 2))
16914442181SJérôme Pouiller return 0;
17014442181SJérôme Pouiller else
17197e587bdSJérôme Pouiller return 30;
172398999daSJérôme Pouiller }
173a3b8008dSJohannes Berg if (enable_ps)
174a3b8008dSJohannes Berg *enable_ps = vif->cfg.ps;
175398999daSJérôme Pouiller if (vif->cfg.assoc && vif->cfg.ps)
176398999daSJérôme Pouiller return conf->dynamic_ps_timeout;
177398999daSJérôme Pouiller else
178398999daSJérôme Pouiller return -1;
179398999daSJérôme Pouiller }
18001d2ffa4SJérôme Pouiller
wfx_update_pm(struct wfx_vif * wvif)181398999daSJérôme Pouiller int wfx_update_pm(struct wfx_vif *wvif)
1822c33360bSJaehee Park {
183398999daSJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
184398999daSJérôme Pouiller int ps_timeout;
185398999daSJérôme Pouiller bool ps;
186f276e20bSJohannes Berg
187398999daSJérôme Pouiller if (!vif->cfg.assoc)
188398999daSJérôme Pouiller return 0;
189398999daSJérôme Pouiller ps_timeout = wfx_get_ps_timeout(wvif, &ps);
190398999daSJérôme Pouiller if (!ps)
191398999daSJérôme Pouiller ps_timeout = 0;
192398999daSJérôme Pouiller WARN_ON(ps_timeout < 0);
193398999daSJérôme Pouiller if (wvif->uapsd_mask)
19497e587bdSJérôme Pouiller ps_timeout = 0;
195381d3295SJérôme Pouiller
196381d3295SJérôme Pouiller if (!wait_for_completion_timeout(&wvif->set_pm_mode_complete, TU_TO_JIFFIES(512)))
1971c780482SJérôme Pouiller dev_warn(wvif->wdev->dev, "timeout while waiting of set_pm_mode_complete\n");
19897e587bdSJérôme Pouiller return wfx_hif_set_pm(wvif, ps, ps_timeout);
19997e587bdSJérôme Pouiller }
20040115bbcSJérôme Pouiller
wfx_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 queue,const struct ieee80211_tx_queue_params * params)201b3e2130bSJohannes Berg int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
202b3e2130bSJohannes Berg unsigned int link_id, u16 queue,
20340115bbcSJérôme Pouiller const struct ieee80211_tx_queue_params *params)
20440115bbcSJérôme Pouiller {
20540115bbcSJérôme Pouiller struct wfx_dev *wdev = hw->priv;
2069b90910fSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
20740115bbcSJérôme Pouiller int old_uapsd = wvif->uapsd_mask;
208c91ba8c8SJérôme Pouiller
209c91ba8c8SJérôme Pouiller WARN_ON(queue >= hw->queues);
21040115bbcSJérôme Pouiller
2117e2b32f5SJérôme Pouiller mutex_lock(&wdev->conf_mutex);
2121c780482SJérôme Pouiller assign_bit(queue, &wvif->uapsd_mask, params->uapsd);
2132c33360bSJaehee Park wfx_hif_set_edca_queue_params(wvif, queue, params);
2142c33360bSJaehee Park if (vif->type == NL80211_IFTYPE_STATION &&
2151c780482SJérôme Pouiller old_uapsd != wvif->uapsd_mask) {
216963aff57SJérôme Pouiller wfx_hif_set_uapsd_info(wvif, wvif->uapsd_mask);
21740115bbcSJérôme Pouiller wfx_update_pm(wvif);
21840115bbcSJérôme Pouiller }
21902a33f8eSKaaira Gupta mutex_unlock(&wdev->conf_mutex);
22040115bbcSJérôme Pouiller return 0;
22140115bbcSJérôme Pouiller }
22240115bbcSJérôme Pouiller
wfx_set_rts_threshold(struct ieee80211_hw * hw,int radio_idx,u32 value)22340115bbcSJérôme Pouiller int wfx_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx, u32 value)
22440115bbcSJérôme Pouiller {
22540115bbcSJérôme Pouiller struct wfx_dev *wdev = hw->priv;
22640115bbcSJérôme Pouiller struct wfx_vif *wvif = NULL;
22740115bbcSJérôme Pouiller
2281c780482SJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
22940115bbcSJérôme Pouiller wfx_hif_rts_threshold(wvif, value);
23040115bbcSJérôme Pouiller return 0;
23140115bbcSJérôme Pouiller }
232988cf07bSJérôme Pouiller
wfx_event_report_rssi(struct wfx_vif * wvif,u8 raw_rcpi_rssi)23340115bbcSJérôme Pouiller void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
23440115bbcSJérôme Pouiller {
23540115bbcSJérôme Pouiller /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
23640115bbcSJérôme Pouiller * RSSI = RCPI / 2 - 110
2372c33360bSJaehee Park */
23840115bbcSJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
23940115bbcSJérôme Pouiller int rcpi_rssi;
24040115bbcSJérôme Pouiller int cqm_evt;
24140115bbcSJérôme Pouiller
2422c33360bSJaehee Park rcpi_rssi = raw_rcpi_rssi / 2 - 110;
24340115bbcSJérôme Pouiller if (rcpi_rssi <= vif->bss_conf.cqm_rssi_thold)
24440115bbcSJérôme Pouiller cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
24540115bbcSJérôme Pouiller else
2462c33360bSJaehee Park cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
24740115bbcSJérôme Pouiller ieee80211_cqm_rssi_notify(vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
24840115bbcSJérôme Pouiller }
2495a0af698SJérôme Pouiller
wfx_beacon_loss_work(struct work_struct * work)2505a0af698SJérôme Pouiller static void wfx_beacon_loss_work(struct work_struct *work)
251381d3295SJérôme Pouiller {
252381d3295SJérôme Pouiller struct wfx_vif *wvif = container_of(to_delayed_work(work), struct wfx_vif,
2532c33360bSJaehee Park beacon_loss_work);
2542c33360bSJaehee Park struct ieee80211_vif *vif = wvif_to_vif(wvif);
2555a0af698SJérôme Pouiller struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2562c33360bSJaehee Park
257381d3295SJérôme Pouiller ieee80211_beacon_loss(vif);
2585a0af698SJérôme Pouiller schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(bss_conf->beacon_int));
2595a0af698SJérôme Pouiller }
260381d3295SJérôme Pouiller
wfx_set_default_unicast_key(struct ieee80211_hw * hw,struct ieee80211_vif * vif,int idx)2617a44644cSJérôme Pouiller void wfx_set_default_unicast_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int idx)
2627a44644cSJérôme Pouiller {
2637a44644cSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
2641c780482SJérôme Pouiller
2657a44644cSJérôme Pouiller wfx_hif_wep_default_key_id(wvif, idx);
2667a44644cSJérôme Pouiller }
2675a48a4a3SJérôme Pouiller
wfx_reset(struct wfx_vif * wvif)2685a48a4a3SJérôme Pouiller void wfx_reset(struct wfx_vif *wvif)
269f75818c2SJérôme Pouiller {
270f75818c2SJérôme Pouiller struct wfx_dev *wdev = wvif->wdev;
271f75818c2SJérôme Pouiller
2721c780482SJérôme Pouiller wfx_tx_lock_flush(wdev);
2735a48a4a3SJérôme Pouiller wfx_hif_reset(wvif, false);
274f75818c2SJérôme Pouiller wfx_tx_policy_init(wvif);
2751c780482SJérôme Pouiller if (wvif_count(wdev) <= 1)
276f75818c2SJérôme Pouiller wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
277f214b7b6SJérôme Pouiller wfx_tx_unlock(wdev);
2785a48a4a3SJérôme Pouiller wvif->join_in_progress = false;
279f75818c2SJérôme Pouiller cancel_delayed_work_sync(&wvif->beacon_loss_work);
280f75818c2SJérôme Pouiller wvif = NULL;
281f75818c2SJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
2825a48a4a3SJérôme Pouiller wfx_update_pm(wvif);
2835a48a4a3SJérôme Pouiller }
284381d3295SJérôme Pouiller
wfx_sta_add(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)28540115bbcSJérôme Pouiller int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
28640115bbcSJérôme Pouiller {
28740115bbcSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
28840115bbcSJérôme Pouiller struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
28940115bbcSJérôme Pouiller
29040115bbcSJérôme Pouiller sta_priv->vif_id = wvif->id;
291d1e0de31SJérôme Pouiller
2921c780482SJérôme Pouiller if (vif->type == NL80211_IFTYPE_STATION)
293d1e0de31SJérôme Pouiller wfx_hif_set_mfp(wvif, sta->mfp, sta->mfp);
29463aac5dbSJérôme Pouiller
2957508f5d9SJérôme Pouiller /* In station mode, the firmware interprets new link-id as a TDLS peer */
296d6aeba57SJérôme Pouiller if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
297d6aeba57SJérôme Pouiller return 0;
298d6aeba57SJérôme Pouiller sta_priv->link_id = ffz(wvif->link_id_map);
299d6aeba57SJérôme Pouiller wvif->link_id_map |= BIT(sta_priv->link_id);
300d7dcf8a5SJérôme Pouiller WARN_ON(!sta_priv->link_id);
3011c780482SJérôme Pouiller WARN_ON(sta_priv->link_id >= HIF_LINK_ID_MAX);
302d6aeba57SJérôme Pouiller wfx_hif_map_link(wvif, false, sta->addr, sta_priv->link_id, sta->mfp);
30340115bbcSJérôme Pouiller
30440115bbcSJérôme Pouiller return 0;
30540115bbcSJérôme Pouiller }
306381d3295SJérôme Pouiller
wfx_sta_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)30740115bbcSJérôme Pouiller int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
30840115bbcSJérôme Pouiller {
30940115bbcSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
31040115bbcSJérôme Pouiller struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
31163aac5dbSJérôme Pouiller
3127508f5d9SJérôme Pouiller /* See note in wfx_sta_add() */
31340115bbcSJérôme Pouiller if (!sta_priv->link_id)
31463aac5dbSJérôme Pouiller return 0;
3151c780482SJérôme Pouiller /* FIXME add a mutex? */
316d6aeba57SJérôme Pouiller wfx_hif_map_link(wvif, true, sta->addr, sta_priv->link_id, false);
31740115bbcSJérôme Pouiller wvif->link_id_map &= ~BIT(sta_priv->link_id);
31840115bbcSJérôme Pouiller return 0;
31940115bbcSJérôme Pouiller }
320d8a92d91SJérôme Pouiller
wfx_upload_ap_templates(struct wfx_vif * wvif)32140115bbcSJérôme Pouiller static int wfx_upload_ap_templates(struct wfx_vif *wvif)
3222c33360bSJaehee Park {
323094ecec9SJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
32440115bbcSJérôme Pouiller struct sk_buff *skb;
3256e8912a5SShaul Triebitz
32640115bbcSJérôme Pouiller skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
32740115bbcSJérôme Pouiller if (!skb)
328381d3295SJérôme Pouiller return -ENOMEM;
329305f7109SJérôme Pouiller wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN, API_RATE_INDEX_B_1MBPS);
33040115bbcSJérôme Pouiller dev_kfree_skb(skb);
3312c33360bSJaehee Park
332305f7109SJérôme Pouiller skb = ieee80211_proberesp_get(wvif->wdev->hw, vif);
333305f7109SJérôme Pouiller if (!skb)
334381d3295SJérôme Pouiller return -ENOMEM;
33540115bbcSJérôme Pouiller wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES, API_RATE_INDEX_B_1MBPS);
336094ecec9SJérôme Pouiller dev_kfree_skb(skb);
33740115bbcSJérôme Pouiller return 0;
33840115bbcSJérôme Pouiller }
339fe0a7776SDmitry Antipov
wfx_set_mfp_ap(struct wfx_vif * wvif)340268bceecSJérôme Pouiller static int wfx_set_mfp_ap(struct wfx_vif *wvif)
3412c33360bSJaehee Park {
3426e8912a5SShaul Triebitz struct ieee80211_vif *vif = wvif_to_vif(wvif);
343268bceecSJérôme Pouiller struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
344268bceecSJérôme Pouiller const int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
345268bceecSJérôme Pouiller const int pairwise_cipher_suite_count_offset = 8 / sizeof(u16);
346268bceecSJérôme Pouiller const int pairwise_cipher_suite_size = 4 / sizeof(u16);
347b8cfb7c8SJérôme Pouiller const int akm_suite_size = 4 / sizeof(u16);
348fe0a7776SDmitry Antipov int ret = -EINVAL;
349268bceecSJérôme Pouiller const u16 *ptr;
350fe0a7776SDmitry Antipov
351fe0a7776SDmitry Antipov if (unlikely(!skb))
352fe0a7776SDmitry Antipov return -ENOMEM;
353fe0a7776SDmitry Antipov
354fe0a7776SDmitry Antipov ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
355*6d30bb88SAlexander Sverdlin skb->len - ieoffset);
356*6d30bb88SAlexander Sverdlin if (!ptr) {
357*6d30bb88SAlexander Sverdlin /* No RSN IE is fine in open networks */
358b8cfb7c8SJérôme Pouiller ret = 0;
359*6d30bb88SAlexander Sverdlin goto free_skb;
360fe0a7776SDmitry Antipov }
361268bceecSJérôme Pouiller
362268bceecSJérôme Pouiller ptr += pairwise_cipher_suite_count_offset;
363b8cfb7c8SJérôme Pouiller if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
364fe0a7776SDmitry Antipov goto free_skb;
365268bceecSJérôme Pouiller
366268bceecSJérôme Pouiller ptr += 1 + pairwise_cipher_suite_size * *ptr;
367b8cfb7c8SJérôme Pouiller if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
368fe0a7776SDmitry Antipov goto free_skb;
369268bceecSJérôme Pouiller
370268bceecSJérôme Pouiller ptr += 1 + akm_suite_size * *ptr;
371b8cfb7c8SJérôme Pouiller if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
372fe0a7776SDmitry Antipov goto free_skb;
3731c780482SJérôme Pouiller
374b8cfb7c8SJérôme Pouiller wfx_hif_set_mfp(wvif, *ptr & BIT(7), *ptr & BIT(6));
375b8cfb7c8SJérôme Pouiller ret = 0;
376b8cfb7c8SJérôme Pouiller
377b8cfb7c8SJérôme Pouiller free_skb:
378b8cfb7c8SJérôme Pouiller dev_kfree_skb(skb);
379268bceecSJérôme Pouiller return ret;
380268bceecSJérôme Pouiller }
381ae7ba17bSShaul Triebitz
wfx_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)382b327c84cSGregory Greenman int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
383cba1d897SJérôme Pouiller struct ieee80211_bss_conf *link_conf)
384cba1d897SJérôme Pouiller {
385f75818c2SJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
386a1ae4d07SJérôme Pouiller struct wfx_dev *wdev = wvif->wdev;
387cba1d897SJérôme Pouiller int ret;
388f75818c2SJérôme Pouiller
389f75818c2SJérôme Pouiller wvif = NULL;
390f75818c2SJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
391f75818c2SJérôme Pouiller wfx_update_pm(wvif);
392cba1d897SJérôme Pouiller wvif = (struct wfx_vif *)vif->drv_priv;
3931c780482SJérôme Pouiller wfx_upload_ap_templates(wvif);
394a1ae4d07SJérôme Pouiller ret = wfx_hif_start(wvif, &vif->bss_conf, wvif->channel);
395a1ae4d07SJérôme Pouiller if (ret > 0)
396fe0a7776SDmitry Antipov return -EIO;
397cba1d897SJérôme Pouiller return wfx_set_mfp_ap(wvif);
398cba1d897SJérôme Pouiller }
399ae7ba17bSShaul Triebitz
wfx_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)400b327c84cSGregory Greenman void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
401cba1d897SJérôme Pouiller struct ieee80211_bss_conf *link_conf)
402cba1d897SJérôme Pouiller {
4038b27aed2SJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
404cba1d897SJérôme Pouiller struct wfx_dev *wdev = wvif->wdev;
4058b27aed2SJérôme Pouiller
4068b27aed2SJérôme Pouiller wvif = NULL;
4078b27aed2SJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
4088b27aed2SJérôme Pouiller wfx_update_pm(wvif);
409b3a71adfSJérôme Pouiller wvif = (struct wfx_vif *)vif->drv_priv;
410cba1d897SJérôme Pouiller wfx_reset(wvif);
411cba1d897SJérôme Pouiller }
412178b8943SJérôme Pouiller
wfx_join(struct wfx_vif * wvif)413178b8943SJérôme Pouiller static void wfx_join(struct wfx_vif *wvif)
4142c33360bSJaehee Park {
4152c33360bSJaehee Park struct ieee80211_vif *vif = wvif_to_vif(wvif);
416178b8943SJérôme Pouiller struct ieee80211_bss_conf *conf = &vif->bss_conf;
417178b8943SJérôme Pouiller struct cfg80211_bss *bss = NULL;
4180cc4dfbbSJaehee Park u8 ssid[IEEE80211_MAX_SSID_LEN];
4190cc4dfbbSJaehee Park const u8 *ssid_ie = NULL;
4202c33360bSJaehee Park int ssid_len = 0;
421178b8943SJérôme Pouiller int ret;
422178b8943SJérôme Pouiller
423178b8943SJérôme Pouiller wfx_tx_lock_flush(wvif->wdev);
424381d3295SJérôme Pouiller
425178b8943SJérôme Pouiller bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel, conf->bssid, NULL, 0,
426f276e20bSJohannes Berg IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
427178b8943SJérôme Pouiller if (!bss && !vif->cfg.ibss_joined) {
428178b8943SJérôme Pouiller wfx_tx_unlock(wvif->wdev);
429178b8943SJérôme Pouiller return;
430178b8943SJérôme Pouiller }
4310cc4dfbbSJaehee Park
432178b8943SJérôme Pouiller rcu_read_lock(); /* protect ssid_ie */
4330cc4dfbbSJaehee Park if (bss)
4340cc4dfbbSJaehee Park ssid_ie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
4350cc4dfbbSJaehee Park if (ssid_ie) {
4360cc4dfbbSJaehee Park ssid_len = ssid_ie[1];
4370cc4dfbbSJaehee Park if (ssid_len > IEEE80211_MAX_SSID_LEN)
4380cc4dfbbSJaehee Park ssid_len = IEEE80211_MAX_SSID_LEN;
439178b8943SJérôme Pouiller memcpy(ssid, &ssid_ie[2], ssid_len);
440178b8943SJérôme Pouiller }
441178b8943SJérôme Pouiller rcu_read_unlock();
442178b8943SJérôme Pouiller
443178b8943SJérôme Pouiller cfg80211_put_bss(wvif->wdev->hw->wiphy, bss);
444178b8943SJérôme Pouiller
4450cc4dfbbSJaehee Park wvif->join_in_progress = true;
446178b8943SJérôme Pouiller ret = wfx_hif_join(wvif, conf, wvif->channel, ssid, ssid_len);
4472c33360bSJaehee Park if (ret) {
448178b8943SJérôme Pouiller ieee80211_connection_loss(vif);
449178b8943SJérôme Pouiller wfx_reset(wvif);
450f545b23dSJérôme Pouiller } else {
451f545b23dSJérôme Pouiller /* Due to beacon filtering it is possible that the AP's beacon is not known for the
452f545b23dSJérôme Pouiller * mac80211 stack. Disable filtering temporary to make sure the stack receives at
453178b8943SJérôme Pouiller * least one
454178b8943SJérôme Pouiller */
455178b8943SJérôme Pouiller wfx_filter_beacon(wvif, false);
456178b8943SJérôme Pouiller }
457178b8943SJérôme Pouiller wfx_tx_unlock(wvif->wdev);
458178b8943SJérôme Pouiller }
4595265c43dSJérôme Pouiller
wfx_join_finalize(struct wfx_vif * wvif,struct ieee80211_bss_conf * info)46040115bbcSJérôme Pouiller static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info)
4612c33360bSJaehee Park {
4622a8f7264SJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
4632a8f7264SJérôme Pouiller struct ieee80211_sta *sta = NULL;
4642a8f7264SJérôme Pouiller int ampdu_density = 0;
4652a8f7264SJérôme Pouiller bool greenfield = false;
46663aac5dbSJérôme Pouiller
467f276e20bSJohannes Berg rcu_read_lock(); /* protect sta */
4682c33360bSJaehee Park if (info->bssid && !vif->cfg.ibss_joined)
469046d2e7cSSriram R sta = ieee80211_find_sta(vif, info->bssid);
470046d2e7cSSriram R if (sta && sta->deflink.ht_cap.ht_supported)
471046d2e7cSSriram R ampdu_density = sta->deflink.ht_cap.ampdu_density;
4722a8f7264SJérôme Pouiller if (sta && sta->deflink.ht_cap.ht_supported &&
473046d2e7cSSriram R !(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
4742a8f7264SJérôme Pouiller greenfield = !!(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD);
4752a8f7264SJérôme Pouiller rcu_read_unlock();
476f214b7b6SJérôme Pouiller
477381d3295SJérôme Pouiller wvif->join_in_progress = false;
4781c780482SJérôme Pouiller wfx_hif_set_association_mode(wvif, ampdu_density, greenfield, info->use_short_preamble);
479f545b23dSJérôme Pouiller wfx_hif_keep_alive_period(wvif, 0);
480f276e20bSJohannes Berg /* beacon_loss_count is defined to 7 in net/mac80211/mlme.c. Let's use the same value. */
4811c780482SJérôme Pouiller wfx_hif_set_bss_params(wvif, vif->cfg.aid, 7);
4828dd5bb66SJérôme Pouiller wfx_hif_set_beacon_wakeup_period(wvif, 1, 1);
48340115bbcSJérôme Pouiller wfx_update_pm(wvif);
48440115bbcSJérôme Pouiller }
485e836ad4eSJérôme Pouiller
wfx_join_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)486e836ad4eSJérôme Pouiller int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
487e836ad4eSJérôme Pouiller {
488e836ad4eSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
489e836ad4eSJérôme Pouiller
490178b8943SJérôme Pouiller wfx_upload_ap_templates(wvif);
491e836ad4eSJérôme Pouiller wfx_join(wvif);
492e836ad4eSJérôme Pouiller return 0;
493e836ad4eSJérôme Pouiller }
494e836ad4eSJérôme Pouiller
wfx_leave_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)495e836ad4eSJérôme Pouiller void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
496e836ad4eSJérôme Pouiller {
497e836ad4eSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
4985a48a4a3SJérôme Pouiller
499e836ad4eSJérôme Pouiller wfx_reset(wvif);
500e836ad4eSJérôme Pouiller }
501bcd8795aSJérôme Pouiller
wfx_enable_beacon(struct wfx_vif * wvif,bool enable)5024fb6036aSJérôme Pouiller static void wfx_enable_beacon(struct wfx_vif *wvif, bool enable)
503f545b23dSJérôme Pouiller {
504f545b23dSJérôme Pouiller /* Driver has Content After DTIM Beacon in queue. Driver is waiting for a signal from the
505f545b23dSJérôme Pouiller * firmware. Since we are going to stop to send beacons, this signal will never happens. See
50663aac5dbSJérôme Pouiller * also wfx_suspend_resume_mc()
5074fb6036aSJérôme Pouiller */
5084fb6036aSJérôme Pouiller if (!enable && wfx_tx_queues_has_cab(wvif)) {
5094fb6036aSJérôme Pouiller wvif->after_dtim_tx_allowed = true;
5104fb6036aSJérôme Pouiller wfx_bh_request_tx(wvif->wdev);
5111c780482SJérôme Pouiller }
5124fb6036aSJérôme Pouiller wfx_hif_beacon_transmit(wvif, enable);
5134fb6036aSJérôme Pouiller }
514b356aed9SJérôme Pouiller
wfx_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)5157b7090b4SJohannes Berg void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
51640115bbcSJérôme Pouiller struct ieee80211_bss_conf *info, u64 changed)
51740115bbcSJérôme Pouiller {
51840115bbcSJérôme Pouiller struct wfx_dev *wdev = hw->priv;
51940115bbcSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
52040115bbcSJérôme Pouiller int i;
52140115bbcSJérôme Pouiller
52240115bbcSJérôme Pouiller mutex_lock(&wdev->conf_mutex);
5239abb6b26SJérôme Pouiller
5249abb6b26SJérôme Pouiller if (changed & BSS_CHANGED_BASIC_RATES ||
5259abb6b26SJérôme Pouiller changed & BSS_CHANGED_BEACON_INT ||
526e836ad4eSJérôme Pouiller changed & BSS_CHANGED_BSSID) {
527178b8943SJérôme Pouiller if (vif->type == NL80211_IFTYPE_STATION)
5289abb6b26SJérôme Pouiller wfx_join(wvif);
5299abb6b26SJérôme Pouiller }
530468f3386SJérôme Pouiller
531f276e20bSJohannes Berg if (changed & BSS_CHANGED_ASSOC) {
532468f3386SJérôme Pouiller if (vif->cfg.assoc || vif->cfg.ibss_joined)
533f276e20bSJohannes Berg wfx_join_finalize(wvif, info);
534468f3386SJérôme Pouiller else if (!vif->cfg.assoc && vif->type == NL80211_IFTYPE_STATION)
535468f3386SJérôme Pouiller wfx_reset(wvif);
536ea174822SJérôme Pouiller else
537468f3386SJérôme Pouiller dev_warn(wdev->dev, "misunderstood change: ASSOC\n");
53840115bbcSJérôme Pouiller }
539e269060eSJérôme Pouiller
540e269060eSJérôme Pouiller if (changed & BSS_CHANGED_BEACON_INFO) {
541ea174822SJérôme Pouiller if (vif->type != NL80211_IFTYPE_STATION)
542381d3295SJérôme Pouiller dev_warn(wdev->dev, "misunderstood change: BEACON_INFO\n");
543f545b23dSJérôme Pouiller wfx_hif_set_beacon_wakeup_period(wvif, info->dtim_period, info->dtim_period);
5442c69b2daSJérôme Pouiller /* We temporary forwarded beacon for join process. It is now no more necessary. */
545e269060eSJérôme Pouiller wfx_filter_beacon(wvif, true);
546b0674e06SJérôme Pouiller }
547468f3386SJérôme Pouiller
548468f3386SJérôme Pouiller if (changed & BSS_CHANGED_ARP_FILTER) {
549f276e20bSJohannes Berg for (i = 0; i < HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES; i++) {
550468f3386SJérôme Pouiller __be32 *arp_addr = &vif->cfg.arp_addr_list[i];
551f276e20bSJohannes Berg
552468f3386SJérôme Pouiller if (vif->cfg.arp_addr_cnt > HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES)
553f276e20bSJohannes Berg arp_addr = NULL;
554468f3386SJérôme Pouiller if (i >= vif->cfg.arp_addr_cnt)
5551c780482SJérôme Pouiller arp_addr = NULL;
55640115bbcSJérôme Pouiller wfx_hif_set_arp_ipv4_filter(wvif, i, arp_addr);
557468f3386SJérôme Pouiller }
558468f3386SJérôme Pouiller }
559381d3295SJérôme Pouiller
560468f3386SJérôme Pouiller if (changed & BSS_CHANGED_AP_PROBE_RESP || changed & BSS_CHANGED_BEACON)
561468f3386SJérôme Pouiller wfx_upload_ap_templates(wvif);
562468f3386SJérôme Pouiller
563468f3386SJérôme Pouiller if (changed & BSS_CHANGED_BEACON_ENABLED)
56440115bbcSJérôme Pouiller wfx_enable_beacon(wvif, info->enable_beacon);
565eeab4787SJérôme Pouiller
5665265c43dSJérôme Pouiller if (changed & BSS_CHANGED_KEEP_ALIVE)
5675265c43dSJérôme Pouiller wfx_hif_keep_alive_period(wvif,
568eeab4787SJérôme Pouiller info->max_idle_period * USEC_PER_TU / USEC_PER_MSEC);
5697b063f3bSJérôme Pouiller
5701c780482SJérôme Pouiller if (changed & BSS_CHANGED_ERP_CTS_PROT)
57140115bbcSJérôme Pouiller wfx_hif_erp_use_protection(wvif, info->use_cts_prot);
572974dfbf8SJérôme Pouiller
5731c780482SJérôme Pouiller if (changed & BSS_CHANGED_ERP_SLOT)
57440115bbcSJérôme Pouiller wfx_hif_slot_time(wvif, info->use_short_slot ? 9 : 20);
575974dfbf8SJérôme Pouiller
576381d3295SJérôme Pouiller if (changed & BSS_CHANGED_CQM)
57740115bbcSJérôme Pouiller wfx_hif_set_rcpi_rssi_threshold(wvif, info->cqm_rssi_thold, info->cqm_rssi_hyst);
578f050f3daSJérôme Pouiller
5791c780482SJérôme Pouiller if (changed & BSS_CHANGED_TXPOWER)
5808d97a12fSJérôme Pouiller wfx_hif_set_output_power(wvif, info->txpower);
5818d97a12fSJérôme Pouiller
5828d97a12fSJérôme Pouiller if (changed & BSS_CHANGED_PS)
5838d97a12fSJérôme Pouiller wfx_update_pm(wvif);
58440115bbcSJérôme Pouiller
58540115bbcSJérôme Pouiller mutex_unlock(&wdev->conf_mutex);
58640115bbcSJérôme Pouiller }
58736cbb5d2SJérôme Pouiller
wfx_update_tim(struct wfx_vif * wvif)5889bca45f3SJérôme Pouiller static int wfx_update_tim(struct wfx_vif *wvif)
5892c33360bSJaehee Park {
5909bca45f3SJérôme Pouiller struct ieee80211_vif *vif = wvif_to_vif(wvif);
5919bca45f3SJérôme Pouiller struct sk_buff *skb;
5929bca45f3SJérôme Pouiller u16 tim_offset, tim_length;
5939bca45f3SJérôme Pouiller u8 *tim_ptr;
5942c33360bSJaehee Park
5956e8912a5SShaul Triebitz skb = ieee80211_beacon_get_tim(wvif->wdev->hw, vif, &tim_offset,
5964c6b3837SJérôme Pouiller &tim_length, 0);
5979bca45f3SJérôme Pouiller if (!skb)
5989bca45f3SJérôme Pouiller return -ENOENT;
5999bca45f3SJérôme Pouiller tim_ptr = skb->data + tim_offset;
6009bca45f3SJérôme Pouiller
6019885474dSJérôme Pouiller if (tim_offset && tim_length >= 6) {
6029bca45f3SJérôme Pouiller /* Firmware handles DTIM counter internally */
6039bca45f3SJérôme Pouiller tim_ptr[2] = 0;
6049bca45f3SJérôme Pouiller
605b6ef1549SJérôme Pouiller /* Set/reset aid0 bit */
6069bca45f3SJérôme Pouiller if (wfx_tx_queues_has_cab(wvif))
6079bca45f3SJérôme Pouiller tim_ptr[4] |= 1;
6089bca45f3SJérôme Pouiller else
6099bca45f3SJérôme Pouiller tim_ptr[4] &= ~1;
6109bca45f3SJérôme Pouiller }
6111c780482SJérôme Pouiller
6129bca45f3SJérôme Pouiller wfx_hif_update_ie_beacon(wvif, tim_ptr, tim_length);
6139bca45f3SJérôme Pouiller dev_kfree_skb(skb);
6149bca45f3SJérôme Pouiller
6159bca45f3SJérôme Pouiller return 0;
6169bca45f3SJérôme Pouiller }
61736cbb5d2SJérôme Pouiller
wfx_update_tim_work(struct work_struct * work)61840115bbcSJérôme Pouiller static void wfx_update_tim_work(struct work_struct *work)
61936cbb5d2SJérôme Pouiller {
62040115bbcSJérôme Pouiller struct wfx_vif *wvif = container_of(work, struct wfx_vif, update_tim_work);
62136cbb5d2SJérôme Pouiller
62240115bbcSJérôme Pouiller wfx_update_tim(wvif);
62340115bbcSJérôme Pouiller }
62440115bbcSJérôme Pouiller
wfx_set_tim(struct ieee80211_hw * hw,struct ieee80211_sta * sta,bool set)62540115bbcSJérôme Pouiller int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
62640115bbcSJérôme Pouiller {
62740115bbcSJérôme Pouiller struct wfx_dev *wdev = hw->priv;
62840115bbcSJérôme Pouiller struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv;
62940115bbcSJérôme Pouiller struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
630bb97bc28SJérôme Pouiller
631bb97bc28SJérôme Pouiller if (!wvif) {
632bb97bc28SJérôme Pouiller dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
633bb97bc28SJérôme Pouiller return -EIO;
63436cbb5d2SJérôme Pouiller }
63540115bbcSJérôme Pouiller schedule_work(&wvif->update_tim_work);
63640115bbcSJérôme Pouiller return 0;
63740115bbcSJérôme Pouiller }
638a3c529a8SJérôme Pouiller
wfx_suspend_resume_mc(struct wfx_vif * wvif,enum sta_notify_cmd notify_cmd)6399bca45f3SJérôme Pouiller void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd)
6408e47df5fSJérôme Pouiller {
6418e47df5fSJérôme Pouiller if (notify_cmd != STA_NOTIFY_AWAKE)
6420ccb2c9dSJérôme Pouiller return;
643f545b23dSJérôme Pouiller
644f545b23dSJérôme Pouiller /* Device won't be able to honor CAB if a scan is in progress on any interface. Prefer to
6450ccb2c9dSJérôme Pouiller * skip this DTIM and wait for the next one.
64604106ec5SJérôme Pouiller */
6470ccb2c9dSJérôme Pouiller if (mutex_is_locked(&wvif->wdev->scan_lock))
6480ccb2c9dSJérôme Pouiller return;
64922af4990SJérôme Pouiller
65022af4990SJérôme Pouiller if (!wfx_tx_queues_has_cab(wvif) || wvif->after_dtim_tx_allowed)
65122af4990SJérôme Pouiller dev_warn(wvif->wdev->dev, "incorrect sequence (%d CAB in queue)",
652a3c529a8SJérôme Pouiller wfx_tx_queues_has_cab(wvif));
6539bca45f3SJérôme Pouiller wvif->after_dtim_tx_allowed = true;
6549bca45f3SJérôme Pouiller wfx_bh_request_tx(wvif->wdev);
6559bca45f3SJérôme Pouiller }
656381d3295SJérôme Pouiller
wfx_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)65740115bbcSJérôme Pouiller int wfx_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
65840115bbcSJérôme Pouiller struct ieee80211_ampdu_params *params)
65963aac5dbSJérôme Pouiller {
6607373f31cSJérôme Pouiller /* Aggregation is implemented fully in firmware */
6617373f31cSJérôme Pouiller switch (params->action) {
6627373f31cSJérôme Pouiller case IEEE80211_AMPDU_RX_START:
66363aac5dbSJérôme Pouiller case IEEE80211_AMPDU_RX_STOP:
6647373f31cSJérôme Pouiller /* Just acknowledge it to enable frame re-ordering */
6657373f31cSJérôme Pouiller return 0;
66663aac5dbSJérôme Pouiller default:
667cbba71c2SJérôme Pouiller /* Leave the firmware doing its business for tx aggregation */
66840115bbcSJérôme Pouiller return -EOPNOTSUPP;
6697373f31cSJérôme Pouiller }
67040115bbcSJérôme Pouiller }
671381d3295SJérôme Pouiller
wfx_add_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf)67240115bbcSJérôme Pouiller int wfx_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
67340115bbcSJérôme Pouiller {
67440115bbcSJérôme Pouiller return 0;
67540115bbcSJérôme Pouiller }
676381d3295SJérôme Pouiller
wfx_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf)67740115bbcSJérôme Pouiller void wfx_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
67840115bbcSJérôme Pouiller {
67940115bbcSJérôme Pouiller }
680381d3295SJérôme Pouiller
wfx_change_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf,u32 changed)68140115bbcSJérôme Pouiller void wfx_change_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf, u32 changed)
68240115bbcSJérôme Pouiller {
68340115bbcSJérôme Pouiller }
68440115bbcSJérôme Pouiller
wfx_assign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * conf)685727eff4dSGregory Greenman int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
68640115bbcSJérôme Pouiller struct ieee80211_bss_conf *link_conf,
68740115bbcSJérôme Pouiller struct ieee80211_chanctx_conf *conf)
68840115bbcSJérôme Pouiller {
68940115bbcSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
69040115bbcSJérôme Pouiller struct ieee80211_channel *ch = conf->def.chan;
69140115bbcSJérôme Pouiller
69240115bbcSJérôme Pouiller WARN(wvif->channel, "channel overwrite");
69340115bbcSJérôme Pouiller wvif->channel = ch;
69440115bbcSJérôme Pouiller
69540115bbcSJérôme Pouiller return 0;
69640115bbcSJérôme Pouiller }
697381d3295SJérôme Pouiller
wfx_unassign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * conf)698727eff4dSGregory Greenman void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
69940115bbcSJérôme Pouiller struct ieee80211_bss_conf *link_conf,
70040115bbcSJérôme Pouiller struct ieee80211_chanctx_conf *conf)
70140115bbcSJérôme Pouiller {
70240115bbcSJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
70340115bbcSJérôme Pouiller struct ieee80211_channel *ch = conf->def.chan;
70440115bbcSJérôme Pouiller
70540115bbcSJérôme Pouiller WARN(wvif->channel != ch, "channel mismatch");
70640115bbcSJérôme Pouiller wvif->channel = NULL;
70740115bbcSJérôme Pouiller }
70840115bbcSJérôme Pouiller
wfx_config(struct ieee80211_hw * hw,int radio_idx,u32 changed)70940115bbcSJérôme Pouiller int wfx_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)
7108d97a12fSJérôme Pouiller {
71140115bbcSJérôme Pouiller return 0;
71240115bbcSJérôme Pouiller }
713e16e7f07SJérôme Pouiller
wfx_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)714e16e7f07SJérôme Pouiller int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
715063cf5f5SJérôme Pouiller {
716e16e7f07SJérôme Pouiller int i;
717e16e7f07SJérôme Pouiller struct wfx_dev *wdev = hw->priv;
718e16e7f07SJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
71940115bbcSJérôme Pouiller
72040115bbcSJérôme Pouiller vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
72140115bbcSJérôme Pouiller IEEE80211_VIF_SUPPORTS_UAPSD |
72240115bbcSJérôme Pouiller IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7231a61af0fSJérôme Pouiller
7241a61af0fSJérôme Pouiller mutex_lock(&wdev->conf_mutex);
72540115bbcSJérôme Pouiller
72640115bbcSJérôme Pouiller switch (vif->type) {
72740115bbcSJérôme Pouiller case NL80211_IFTYPE_STATION:
72840115bbcSJérôme Pouiller case NL80211_IFTYPE_ADHOC:
72940115bbcSJérôme Pouiller case NL80211_IFTYPE_AP:
73040115bbcSJérôme Pouiller break;
73140115bbcSJérôme Pouiller default:
73240115bbcSJérôme Pouiller mutex_unlock(&wdev->conf_mutex);
73340115bbcSJérôme Pouiller return -EOPNOTSUPP;
73440115bbcSJérôme Pouiller }
735e16e7f07SJérôme Pouiller
736e16e7f07SJérôme Pouiller wvif->wdev = wdev;
73763aac5dbSJérôme Pouiller
73836cbb5d2SJérôme Pouiller wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
7395a0af698SJérôme Pouiller INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
7409bca45f3SJérôme Pouiller INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
74140115bbcSJérôme Pouiller
74240115bbcSJérôme Pouiller init_completion(&wvif->set_pm_mode_complete);
74399879121SJérôme Pouiller complete(&wvif->set_pm_mode_complete);
744d1c015b4SJérôme Pouiller INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work);
745d1c015b4SJérôme Pouiller
7463827e33dSJérôme Pouiller init_completion(&wvif->scan_complete);
747fc627dadSJérôme Pouiller INIT_WORK(&wvif->scan_work, wfx_hw_scan_work);
748d1c015b4SJérôme Pouiller INIT_WORK(&wvif->remain_on_channel_work, wfx_remain_on_channel_work);
749ce3653a8SJérôme Pouiller
750ce3653a8SJérôme Pouiller wfx_tx_queues_init(wvif);
751ce3653a8SJérôme Pouiller wfx_tx_policy_init(wvif);
752ce3653a8SJérôme Pouiller
753ce3653a8SJérôme Pouiller for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
754ce3653a8SJérôme Pouiller if (!wdev->vif[i]) {
755ce3653a8SJérôme Pouiller wdev->vif[i] = vif;
756ce3653a8SJérôme Pouiller wvif->id = i;
757ce3653a8SJérôme Pouiller break;
758ce3653a8SJérôme Pouiller }
759ce3653a8SJérôme Pouiller }
76040115bbcSJérôme Pouiller WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported");
7611c780482SJérôme Pouiller
76240115bbcSJérôme Pouiller wfx_hif_set_macaddr(wvif, vif->addr);
763ce3653a8SJérôme Pouiller
764ce3653a8SJérôme Pouiller mutex_unlock(&wdev->conf_mutex);
76540115bbcSJérôme Pouiller
76640115bbcSJérôme Pouiller wvif = NULL;
76763aac5dbSJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
76840115bbcSJérôme Pouiller /* Combo mode does not support Block Acks. We can re-enable them */
7691c780482SJérôme Pouiller if (wvif_count(wdev) == 1)
77040115bbcSJérôme Pouiller wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
7711c780482SJérôme Pouiller else
77240115bbcSJérôme Pouiller wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
773063cf5f5SJérôme Pouiller }
774e16e7f07SJérôme Pouiller return 0;
775e16e7f07SJérôme Pouiller }
776b356aed9SJérôme Pouiller
wfx_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)777e16e7f07SJérôme Pouiller void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
77840115bbcSJérôme Pouiller {
7799bca45f3SJérôme Pouiller struct wfx_dev *wdev = hw->priv;
7809bca45f3SJérôme Pouiller struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
78140115bbcSJérôme Pouiller
7822a30cb16SJérôme Pouiller wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
78340115bbcSJérôme Pouiller wfx_tx_queues_check_empty(wvif);
78440115bbcSJérôme Pouiller
785d6aeba57SJérôme Pouiller mutex_lock(&wdev->conf_mutex);
786cf24a82bSJérôme Pouiller WARN(wvif->link_id_map != 1, "corrupted state");
7871c780482SJérôme Pouiller
7881c780482SJérôme Pouiller wfx_hif_reset(wvif, false);
789cf24a82bSJérôme Pouiller wfx_hif_set_macaddr(wvif, NULL);
79040115bbcSJérôme Pouiller wfx_tx_policy_init(wvif);
7915a0af698SJérôme Pouiller
79240115bbcSJérôme Pouiller cancel_delayed_work_sync(&wvif->beacon_loss_work);
79340115bbcSJérôme Pouiller wdev->vif[wvif->id] = NULL;
79440115bbcSJérôme Pouiller
795ce3653a8SJérôme Pouiller mutex_unlock(&wdev->conf_mutex);
79640115bbcSJérôme Pouiller
79740115bbcSJérôme Pouiller wvif = NULL;
79863aac5dbSJérôme Pouiller while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
79940115bbcSJérôme Pouiller /* Combo mode does not support Block Acks. We can re-enable them */
8001c780482SJérôme Pouiller if (wvif_count(wdev) == 1)
80140115bbcSJérôme Pouiller wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
8021c780482SJérôme Pouiller else
80340115bbcSJérôme Pouiller wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
804e16e7f07SJérôme Pouiller }
805e16e7f07SJérôme Pouiller }
806e16e7f07SJérôme Pouiller
807e16e7f07SJérôme Pouiller #ifdef CONFIG_PM
wfx_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)808e16e7f07SJérôme Pouiller int wfx_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
809e16e7f07SJérôme Pouiller {
810e16e7f07SJérôme Pouiller /* FIXME: hardware also support WIPHY_WOWLAN_MAGIC_PKT and other filters */
8111decf05dSEmmanuel Grumbach if (!wowlan->any || !wowlan->disconnect)
812e16e7f07SJérôme Pouiller return -EINVAL;
8139bca45f3SJérôme Pouiller return 0;
8149bca45f3SJérôme Pouiller }
8152a30cb16SJérôme Pouiller
wfx_resume(struct ieee80211_hw * hw)816e16e7f07SJérôme Pouiller int wfx_resume(struct ieee80211_hw *hw)
817 {
818 return 0;
819 }
820
wfx_set_wakeup(struct ieee80211_hw * hw,bool enabled)821 void wfx_set_wakeup(struct ieee80211_hw *hw, bool enabled)
822 {
823 struct wfx_dev *wdev = hw->priv;
824
825 if (enabled)
826 dev_info(wdev->dev, "support for WoWLAN is experimental\n");
827 wdev->hwbus_ops->set_wakeup(wdev->hwbus_priv, enabled);
828 }
829 #endif
830
wfx_start(struct ieee80211_hw * hw)831 int wfx_start(struct ieee80211_hw *hw)
832 {
833 return 0;
834 }
835
wfx_stop(struct ieee80211_hw * hw,bool suspend)836 void wfx_stop(struct ieee80211_hw *hw, bool suspend)
837 {
838 struct wfx_dev *wdev = hw->priv;
839
840 WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending));
841 }
842