Loading...
Note: File does not exist in v4.6.
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Implementation of mac80211 API.
4 *
5 * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
6 * Copyright (c) 2010, ST-Ericsson
7 */
8#include <linux/etherdevice.h>
9#include <net/mac80211.h>
10
11#include "sta.h"
12#include "wfx.h"
13#include "fwio.h"
14#include "bh.h"
15#include "key.h"
16#include "scan.h"
17#include "debug.h"
18#include "hif_tx.h"
19#include "hif_tx_mib.h"
20
21#define HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES 2
22
23void wfx_cooling_timeout_work(struct work_struct *work)
24{
25 struct wfx_dev *wdev = container_of(to_delayed_work(work), struct wfx_dev,
26 cooling_timeout_work);
27
28 wdev->chip_frozen = true;
29 wfx_tx_unlock(wdev);
30}
31
32void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd)
33{
34 if (cmd == STA_NOTIFY_AWAKE) {
35 /* Device recover normal temperature */
36 if (cancel_delayed_work(&wdev->cooling_timeout_work))
37 wfx_tx_unlock(wdev);
38 } else {
39 /* Device is too hot */
40 schedule_delayed_work(&wdev->cooling_timeout_work, 10 * HZ);
41 wfx_tx_lock(wdev);
42 }
43}
44
45static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
46{
47 static const struct wfx_hif_ie_table_entry filter_ies[] = {
48 {
49 .ie_id = WLAN_EID_VENDOR_SPECIFIC,
50 .has_changed = 1,
51 .no_longer = 1,
52 .has_appeared = 1,
53 .oui = { 0x50, 0x6F, 0x9A },
54 }, {
55 .ie_id = WLAN_EID_HT_OPERATION,
56 .has_changed = 1,
57 .no_longer = 1,
58 .has_appeared = 1,
59 }, {
60 .ie_id = WLAN_EID_ERP_INFO,
61 .has_changed = 1,
62 .no_longer = 1,
63 .has_appeared = 1,
64 }, {
65 .ie_id = WLAN_EID_CHANNEL_SWITCH,
66 .has_changed = 1,
67 .no_longer = 1,
68 .has_appeared = 1,
69 }
70 };
71
72 if (!filter_beacon) {
73 wfx_hif_beacon_filter_control(wvif, 0, 1);
74 } else {
75 wfx_hif_set_beacon_filter_table(wvif, ARRAY_SIZE(filter_ies), filter_ies);
76 wfx_hif_beacon_filter_control(wvif, HIF_BEACON_FILTER_ENABLE, 0);
77 }
78}
79
80void wfx_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
81 unsigned int *total_flags, u64 unused)
82{
83 bool filter_bssid, filter_prbreq, filter_beacon;
84 struct ieee80211_vif *vif = NULL;
85 struct wfx_dev *wdev = hw->priv;
86 struct wfx_vif *wvif = NULL;
87
88 /* Notes:
89 * - Probe responses (FIF_BCN_PRBRESP_PROMISC) are never filtered
90 * - PS-Poll (FIF_PSPOLL) are never filtered
91 * - RTS, CTS and Ack (FIF_CONTROL) are always filtered
92 * - Broken frames (FIF_FCSFAIL and FIF_PLCPFAIL) are always filtered
93 * - Firmware does (yet) allow to forward unicast traffic sent to other stations (aka.
94 * promiscuous mode)
95 */
96 *total_flags &= FIF_BCN_PRBRESP_PROMISC | FIF_ALLMULTI | FIF_OTHER_BSS |
97 FIF_PROBE_REQ | FIF_PSPOLL;
98
99 /* Filters are ignored during the scan. No frames are filtered. */
100 if (mutex_is_locked(&wdev->scan_lock))
101 return;
102
103 mutex_lock(&wdev->conf_mutex);
104 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
105 /* Note: FIF_BCN_PRBRESP_PROMISC covers probe response and
106 * beacons from other BSS
107 */
108 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
109 filter_beacon = false;
110 else
111 filter_beacon = true;
112 wfx_filter_beacon(wvif, filter_beacon);
113
114 if (*total_flags & FIF_OTHER_BSS)
115 filter_bssid = false;
116 else
117 filter_bssid = true;
118
119 vif = wvif_to_vif(wvif);
120 /* In AP mode, chip can reply to probe request itself */
121 if (*total_flags & FIF_PROBE_REQ && vif->type == NL80211_IFTYPE_AP) {
122 dev_dbg(wdev->dev, "do not forward probe request in AP mode\n");
123 *total_flags &= ~FIF_PROBE_REQ;
124 }
125
126 if (*total_flags & FIF_PROBE_REQ)
127 filter_prbreq = false;
128 else
129 filter_prbreq = true;
130 wfx_hif_set_rx_filter(wvif, filter_bssid, filter_prbreq);
131 }
132 mutex_unlock(&wdev->conf_mutex);
133}
134
135static int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps)
136{
137 struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
138 struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
139 struct ieee80211_vif *vif = wvif_to_vif(wvif);
140
141 WARN(!vif->cfg.assoc && enable_ps,
142 "enable_ps is reliable only if associated");
143 if (wdev_to_wvif(wvif->wdev, 0)) {
144 struct wfx_vif *wvif_ch0 = wdev_to_wvif(wvif->wdev, 0);
145 struct ieee80211_vif *vif_ch0 = wvif_to_vif(wvif_ch0);
146
147 chan0 = vif_ch0->bss_conf.chandef.chan;
148 }
149 if (wdev_to_wvif(wvif->wdev, 1)) {
150 struct wfx_vif *wvif_ch1 = wdev_to_wvif(wvif->wdev, 1);
151 struct ieee80211_vif *vif_ch1 = wvif_to_vif(wvif_ch1);
152
153 chan1 = vif_ch1->bss_conf.chandef.chan;
154 }
155 if (chan0 && chan1 && vif->type != NL80211_IFTYPE_AP) {
156 if (chan0->hw_value == chan1->hw_value) {
157 /* It is useless to enable PS if channels are the same. */
158 if (enable_ps)
159 *enable_ps = false;
160 if (vif->cfg.assoc && vif->cfg.ps)
161 dev_info(wvif->wdev->dev, "ignoring requested PS mode");
162 return -1;
163 }
164 /* It is necessary to enable PS if channels are different. */
165 if (enable_ps)
166 *enable_ps = true;
167 if (wfx_api_older_than(wvif->wdev, 3, 2))
168 return 0;
169 else
170 return 30;
171 }
172 if (enable_ps)
173 *enable_ps = vif->cfg.ps;
174 if (vif->cfg.assoc && vif->cfg.ps)
175 return conf->dynamic_ps_timeout;
176 else
177 return -1;
178}
179
180int wfx_update_pm(struct wfx_vif *wvif)
181{
182 struct ieee80211_vif *vif = wvif_to_vif(wvif);
183 int ps_timeout;
184 bool ps;
185
186 if (!vif->cfg.assoc)
187 return 0;
188 ps_timeout = wfx_get_ps_timeout(wvif, &ps);
189 if (!ps)
190 ps_timeout = 0;
191 WARN_ON(ps_timeout < 0);
192 if (wvif->uapsd_mask)
193 ps_timeout = 0;
194
195 if (!wait_for_completion_timeout(&wvif->set_pm_mode_complete, TU_TO_JIFFIES(512)))
196 dev_warn(wvif->wdev->dev, "timeout while waiting of set_pm_mode_complete\n");
197 return wfx_hif_set_pm(wvif, ps, ps_timeout);
198}
199
200int wfx_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
201 unsigned int link_id, u16 queue,
202 const struct ieee80211_tx_queue_params *params)
203{
204 struct wfx_dev *wdev = hw->priv;
205 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
206 int old_uapsd = wvif->uapsd_mask;
207
208 WARN_ON(queue >= hw->queues);
209
210 mutex_lock(&wdev->conf_mutex);
211 assign_bit(queue, &wvif->uapsd_mask, params->uapsd);
212 wfx_hif_set_edca_queue_params(wvif, queue, params);
213 if (vif->type == NL80211_IFTYPE_STATION &&
214 old_uapsd != wvif->uapsd_mask) {
215 wfx_hif_set_uapsd_info(wvif, wvif->uapsd_mask);
216 wfx_update_pm(wvif);
217 }
218 mutex_unlock(&wdev->conf_mutex);
219 return 0;
220}
221
222int wfx_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
223{
224 struct wfx_dev *wdev = hw->priv;
225 struct wfx_vif *wvif = NULL;
226
227 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
228 wfx_hif_rts_threshold(wvif, value);
229 return 0;
230}
231
232void wfx_event_report_rssi(struct wfx_vif *wvif, u8 raw_rcpi_rssi)
233{
234 /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
235 * RSSI = RCPI / 2 - 110
236 */
237 struct ieee80211_vif *vif = wvif_to_vif(wvif);
238 int rcpi_rssi;
239 int cqm_evt;
240
241 rcpi_rssi = raw_rcpi_rssi / 2 - 110;
242 if (rcpi_rssi <= vif->bss_conf.cqm_rssi_thold)
243 cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
244 else
245 cqm_evt = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
246 ieee80211_cqm_rssi_notify(vif, cqm_evt, rcpi_rssi, GFP_KERNEL);
247}
248
249static void wfx_beacon_loss_work(struct work_struct *work)
250{
251 struct wfx_vif *wvif = container_of(to_delayed_work(work), struct wfx_vif,
252 beacon_loss_work);
253 struct ieee80211_vif *vif = wvif_to_vif(wvif);
254 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
255
256 ieee80211_beacon_loss(vif);
257 schedule_delayed_work(to_delayed_work(work), msecs_to_jiffies(bss_conf->beacon_int));
258}
259
260void wfx_set_default_unicast_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif, int idx)
261{
262 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
263
264 wfx_hif_wep_default_key_id(wvif, idx);
265}
266
267void wfx_reset(struct wfx_vif *wvif)
268{
269 struct wfx_dev *wdev = wvif->wdev;
270
271 wfx_tx_lock_flush(wdev);
272 wfx_hif_reset(wvif, false);
273 wfx_tx_policy_init(wvif);
274 if (wvif_count(wdev) <= 1)
275 wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
276 wfx_tx_unlock(wdev);
277 wvif->join_in_progress = false;
278 cancel_delayed_work_sync(&wvif->beacon_loss_work);
279 wvif = NULL;
280 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
281 wfx_update_pm(wvif);
282}
283
284int wfx_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
285{
286 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
287 struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
288
289 sta_priv->vif_id = wvif->id;
290
291 if (vif->type == NL80211_IFTYPE_STATION)
292 wfx_hif_set_mfp(wvif, sta->mfp, sta->mfp);
293
294 /* In station mode, the firmware interprets new link-id as a TDLS peer */
295 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
296 return 0;
297 sta_priv->link_id = ffz(wvif->link_id_map);
298 wvif->link_id_map |= BIT(sta_priv->link_id);
299 WARN_ON(!sta_priv->link_id);
300 WARN_ON(sta_priv->link_id >= HIF_LINK_ID_MAX);
301 wfx_hif_map_link(wvif, false, sta->addr, sta_priv->link_id, sta->mfp);
302
303 return 0;
304}
305
306int wfx_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
307{
308 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
309 struct wfx_sta_priv *sta_priv = (struct wfx_sta_priv *)&sta->drv_priv;
310
311 /* See note in wfx_sta_add() */
312 if (!sta_priv->link_id)
313 return 0;
314 /* FIXME add a mutex? */
315 wfx_hif_map_link(wvif, true, sta->addr, sta_priv->link_id, false);
316 wvif->link_id_map &= ~BIT(sta_priv->link_id);
317 return 0;
318}
319
320static int wfx_upload_ap_templates(struct wfx_vif *wvif)
321{
322 struct ieee80211_vif *vif = wvif_to_vif(wvif);
323 struct sk_buff *skb;
324
325 skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
326 if (!skb)
327 return -ENOMEM;
328 wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN, API_RATE_INDEX_B_1MBPS);
329 dev_kfree_skb(skb);
330
331 skb = ieee80211_proberesp_get(wvif->wdev->hw, vif);
332 if (!skb)
333 return -ENOMEM;
334 wfx_hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES, API_RATE_INDEX_B_1MBPS);
335 dev_kfree_skb(skb);
336 return 0;
337}
338
339static int wfx_set_mfp_ap(struct wfx_vif *wvif)
340{
341 struct ieee80211_vif *vif = wvif_to_vif(wvif);
342 struct sk_buff *skb = ieee80211_beacon_get(wvif->wdev->hw, vif, 0);
343 const int ieoffset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
344 const int pairwise_cipher_suite_count_offset = 8 / sizeof(u16);
345 const int pairwise_cipher_suite_size = 4 / sizeof(u16);
346 const int akm_suite_size = 4 / sizeof(u16);
347 const u16 *ptr;
348
349 if (unlikely(!skb))
350 return -ENOMEM;
351
352 ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
353 skb->len - ieoffset);
354 if (unlikely(!ptr))
355 return -EINVAL;
356
357 ptr += pairwise_cipher_suite_count_offset;
358 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
359 return -EINVAL;
360
361 ptr += 1 + pairwise_cipher_suite_size * *ptr;
362 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
363 return -EINVAL;
364
365 ptr += 1 + akm_suite_size * *ptr;
366 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
367 return -EINVAL;
368
369 wfx_hif_set_mfp(wvif, *ptr & BIT(7), *ptr & BIT(6));
370 return 0;
371}
372
373int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
374 struct ieee80211_bss_conf *link_conf)
375{
376 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
377 struct wfx_dev *wdev = wvif->wdev;
378 int ret;
379
380 wvif = NULL;
381 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
382 wfx_update_pm(wvif);
383 wvif = (struct wfx_vif *)vif->drv_priv;
384 wfx_upload_ap_templates(wvif);
385 ret = wfx_hif_start(wvif, &vif->bss_conf, wvif->channel);
386 if (ret > 0)
387 return -EIO;
388 return wfx_set_mfp_ap(wvif);
389}
390
391void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
392 struct ieee80211_bss_conf *link_conf)
393{
394 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
395 struct wfx_dev *wdev = wvif->wdev;
396
397 wvif = NULL;
398 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
399 wfx_update_pm(wvif);
400 wvif = (struct wfx_vif *)vif->drv_priv;
401 wfx_reset(wvif);
402}
403
404static void wfx_join(struct wfx_vif *wvif)
405{
406 struct ieee80211_vif *vif = wvif_to_vif(wvif);
407 struct ieee80211_bss_conf *conf = &vif->bss_conf;
408 struct cfg80211_bss *bss = NULL;
409 u8 ssid[IEEE80211_MAX_SSID_LEN];
410 const u8 *ssid_ie = NULL;
411 int ssid_len = 0;
412 int ret;
413
414 wfx_tx_lock_flush(wvif->wdev);
415
416 bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel, conf->bssid, NULL, 0,
417 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
418 if (!bss && !vif->cfg.ibss_joined) {
419 wfx_tx_unlock(wvif->wdev);
420 return;
421 }
422
423 rcu_read_lock(); /* protect ssid_ie */
424 if (bss)
425 ssid_ie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
426 if (ssid_ie) {
427 ssid_len = ssid_ie[1];
428 if (ssid_len > IEEE80211_MAX_SSID_LEN)
429 ssid_len = IEEE80211_MAX_SSID_LEN;
430 memcpy(ssid, &ssid_ie[2], ssid_len);
431 }
432 rcu_read_unlock();
433
434 cfg80211_put_bss(wvif->wdev->hw->wiphy, bss);
435
436 wvif->join_in_progress = true;
437 ret = wfx_hif_join(wvif, conf, wvif->channel, ssid, ssid_len);
438 if (ret) {
439 ieee80211_connection_loss(vif);
440 wfx_reset(wvif);
441 } else {
442 /* Due to beacon filtering it is possible that the AP's beacon is not known for the
443 * mac80211 stack. Disable filtering temporary to make sure the stack receives at
444 * least one
445 */
446 wfx_filter_beacon(wvif, false);
447 }
448 wfx_tx_unlock(wvif->wdev);
449}
450
451static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info)
452{
453 struct ieee80211_vif *vif = wvif_to_vif(wvif);
454 struct ieee80211_sta *sta = NULL;
455 int ampdu_density = 0;
456 bool greenfield = false;
457
458 rcu_read_lock(); /* protect sta */
459 if (info->bssid && !vif->cfg.ibss_joined)
460 sta = ieee80211_find_sta(vif, info->bssid);
461 if (sta && sta->deflink.ht_cap.ht_supported)
462 ampdu_density = sta->deflink.ht_cap.ampdu_density;
463 if (sta && sta->deflink.ht_cap.ht_supported &&
464 !(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
465 greenfield = !!(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD);
466 rcu_read_unlock();
467
468 wvif->join_in_progress = false;
469 wfx_hif_set_association_mode(wvif, ampdu_density, greenfield, info->use_short_preamble);
470 wfx_hif_keep_alive_period(wvif, 0);
471 /* beacon_loss_count is defined to 7 in net/mac80211/mlme.c. Let's use the same value. */
472 wfx_hif_set_bss_params(wvif, vif->cfg.aid, 7);
473 wfx_hif_set_beacon_wakeup_period(wvif, 1, 1);
474 wfx_update_pm(wvif);
475}
476
477int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
478{
479 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
480
481 wfx_upload_ap_templates(wvif);
482 wfx_join(wvif);
483 return 0;
484}
485
486void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
487{
488 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
489
490 wfx_reset(wvif);
491}
492
493static void wfx_enable_beacon(struct wfx_vif *wvif, bool enable)
494{
495 /* Driver has Content After DTIM Beacon in queue. Driver is waiting for a signal from the
496 * firmware. Since we are going to stop to send beacons, this signal will never happens. See
497 * also wfx_suspend_resume_mc()
498 */
499 if (!enable && wfx_tx_queues_has_cab(wvif)) {
500 wvif->after_dtim_tx_allowed = true;
501 wfx_bh_request_tx(wvif->wdev);
502 }
503 wfx_hif_beacon_transmit(wvif, enable);
504}
505
506void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
507 struct ieee80211_bss_conf *info, u64 changed)
508{
509 struct wfx_dev *wdev = hw->priv;
510 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
511 int i;
512
513 mutex_lock(&wdev->conf_mutex);
514
515 if (changed & BSS_CHANGED_BASIC_RATES ||
516 changed & BSS_CHANGED_BEACON_INT ||
517 changed & BSS_CHANGED_BSSID) {
518 if (vif->type == NL80211_IFTYPE_STATION)
519 wfx_join(wvif);
520 }
521
522 if (changed & BSS_CHANGED_ASSOC) {
523 if (vif->cfg.assoc || vif->cfg.ibss_joined)
524 wfx_join_finalize(wvif, info);
525 else if (!vif->cfg.assoc && vif->type == NL80211_IFTYPE_STATION)
526 wfx_reset(wvif);
527 else
528 dev_warn(wdev->dev, "misunderstood change: ASSOC\n");
529 }
530
531 if (changed & BSS_CHANGED_BEACON_INFO) {
532 if (vif->type != NL80211_IFTYPE_STATION)
533 dev_warn(wdev->dev, "misunderstood change: BEACON_INFO\n");
534 wfx_hif_set_beacon_wakeup_period(wvif, info->dtim_period, info->dtim_period);
535 /* We temporary forwarded beacon for join process. It is now no more necessary. */
536 wfx_filter_beacon(wvif, true);
537 }
538
539 if (changed & BSS_CHANGED_ARP_FILTER) {
540 for (i = 0; i < HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES; i++) {
541 __be32 *arp_addr = &vif->cfg.arp_addr_list[i];
542
543 if (vif->cfg.arp_addr_cnt > HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES)
544 arp_addr = NULL;
545 if (i >= vif->cfg.arp_addr_cnt)
546 arp_addr = NULL;
547 wfx_hif_set_arp_ipv4_filter(wvif, i, arp_addr);
548 }
549 }
550
551 if (changed & BSS_CHANGED_AP_PROBE_RESP || changed & BSS_CHANGED_BEACON)
552 wfx_upload_ap_templates(wvif);
553
554 if (changed & BSS_CHANGED_BEACON_ENABLED)
555 wfx_enable_beacon(wvif, info->enable_beacon);
556
557 if (changed & BSS_CHANGED_KEEP_ALIVE)
558 wfx_hif_keep_alive_period(wvif,
559 info->max_idle_period * USEC_PER_TU / USEC_PER_MSEC);
560
561 if (changed & BSS_CHANGED_ERP_CTS_PROT)
562 wfx_hif_erp_use_protection(wvif, info->use_cts_prot);
563
564 if (changed & BSS_CHANGED_ERP_SLOT)
565 wfx_hif_slot_time(wvif, info->use_short_slot ? 9 : 20);
566
567 if (changed & BSS_CHANGED_CQM)
568 wfx_hif_set_rcpi_rssi_threshold(wvif, info->cqm_rssi_thold, info->cqm_rssi_hyst);
569
570 if (changed & BSS_CHANGED_TXPOWER)
571 wfx_hif_set_output_power(wvif, info->txpower);
572
573 if (changed & BSS_CHANGED_PS)
574 wfx_update_pm(wvif);
575
576 mutex_unlock(&wdev->conf_mutex);
577}
578
579static int wfx_update_tim(struct wfx_vif *wvif)
580{
581 struct ieee80211_vif *vif = wvif_to_vif(wvif);
582 struct sk_buff *skb;
583 u16 tim_offset, tim_length;
584 u8 *tim_ptr;
585
586 skb = ieee80211_beacon_get_tim(wvif->wdev->hw, vif, &tim_offset,
587 &tim_length, 0);
588 if (!skb)
589 return -ENOENT;
590 tim_ptr = skb->data + tim_offset;
591
592 if (tim_offset && tim_length >= 6) {
593 /* Firmware handles DTIM counter internally */
594 tim_ptr[2] = 0;
595
596 /* Set/reset aid0 bit */
597 if (wfx_tx_queues_has_cab(wvif))
598 tim_ptr[4] |= 1;
599 else
600 tim_ptr[4] &= ~1;
601 }
602
603 wfx_hif_update_ie_beacon(wvif, tim_ptr, tim_length);
604 dev_kfree_skb(skb);
605
606 return 0;
607}
608
609static void wfx_update_tim_work(struct work_struct *work)
610{
611 struct wfx_vif *wvif = container_of(work, struct wfx_vif, update_tim_work);
612
613 wfx_update_tim(wvif);
614}
615
616int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
617{
618 struct wfx_dev *wdev = hw->priv;
619 struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv;
620 struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
621
622 if (!wvif) {
623 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
624 return -EIO;
625 }
626 schedule_work(&wvif->update_tim_work);
627 return 0;
628}
629
630void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd)
631{
632 if (notify_cmd != STA_NOTIFY_AWAKE)
633 return;
634
635 /* Device won't be able to honor CAB if a scan is in progress on any interface. Prefer to
636 * skip this DTIM and wait for the next one.
637 */
638 if (mutex_is_locked(&wvif->wdev->scan_lock))
639 return;
640
641 if (!wfx_tx_queues_has_cab(wvif) || wvif->after_dtim_tx_allowed)
642 dev_warn(wvif->wdev->dev, "incorrect sequence (%d CAB in queue)",
643 wfx_tx_queues_has_cab(wvif));
644 wvif->after_dtim_tx_allowed = true;
645 wfx_bh_request_tx(wvif->wdev);
646}
647
648int wfx_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
649 struct ieee80211_ampdu_params *params)
650{
651 /* Aggregation is implemented fully in firmware */
652 switch (params->action) {
653 case IEEE80211_AMPDU_RX_START:
654 case IEEE80211_AMPDU_RX_STOP:
655 /* Just acknowledge it to enable frame re-ordering */
656 return 0;
657 default:
658 /* Leave the firmware doing its business for tx aggregation */
659 return -EOPNOTSUPP;
660 }
661}
662
663int wfx_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
664{
665 return 0;
666}
667
668void wfx_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
669{
670}
671
672void wfx_change_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf, u32 changed)
673{
674}
675
676int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
677 struct ieee80211_bss_conf *link_conf,
678 struct ieee80211_chanctx_conf *conf)
679{
680 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
681 struct ieee80211_channel *ch = conf->def.chan;
682
683 WARN(wvif->channel, "channel overwrite");
684 wvif->channel = ch;
685
686 return 0;
687}
688
689void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
690 struct ieee80211_bss_conf *link_conf,
691 struct ieee80211_chanctx_conf *conf)
692{
693 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
694 struct ieee80211_channel *ch = conf->def.chan;
695
696 WARN(wvif->channel != ch, "channel mismatch");
697 wvif->channel = NULL;
698}
699
700int wfx_config(struct ieee80211_hw *hw, u32 changed)
701{
702 return 0;
703}
704
705int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
706{
707 int i;
708 struct wfx_dev *wdev = hw->priv;
709 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
710
711 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
712 IEEE80211_VIF_SUPPORTS_UAPSD |
713 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
714
715 mutex_lock(&wdev->conf_mutex);
716
717 switch (vif->type) {
718 case NL80211_IFTYPE_STATION:
719 case NL80211_IFTYPE_ADHOC:
720 case NL80211_IFTYPE_AP:
721 break;
722 default:
723 mutex_unlock(&wdev->conf_mutex);
724 return -EOPNOTSUPP;
725 }
726
727 wvif->wdev = wdev;
728
729 wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
730 INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
731 INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
732
733 init_completion(&wvif->set_pm_mode_complete);
734 complete(&wvif->set_pm_mode_complete);
735 INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work);
736
737 init_completion(&wvif->scan_complete);
738 INIT_WORK(&wvif->scan_work, wfx_hw_scan_work);
739 INIT_WORK(&wvif->remain_on_channel_work, wfx_remain_on_channel_work);
740
741 wfx_tx_queues_init(wvif);
742 wfx_tx_policy_init(wvif);
743
744 for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
745 if (!wdev->vif[i]) {
746 wdev->vif[i] = vif;
747 wvif->id = i;
748 break;
749 }
750 }
751 WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported");
752
753 wfx_hif_set_macaddr(wvif, vif->addr);
754
755 mutex_unlock(&wdev->conf_mutex);
756
757 wvif = NULL;
758 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
759 /* Combo mode does not support Block Acks. We can re-enable them */
760 if (wvif_count(wdev) == 1)
761 wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
762 else
763 wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
764 }
765 return 0;
766}
767
768void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
769{
770 struct wfx_dev *wdev = hw->priv;
771 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
772
773 wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
774 wfx_tx_queues_check_empty(wvif);
775
776 mutex_lock(&wdev->conf_mutex);
777 WARN(wvif->link_id_map != 1, "corrupted state");
778
779 wfx_hif_reset(wvif, false);
780 wfx_hif_set_macaddr(wvif, NULL);
781 wfx_tx_policy_init(wvif);
782
783 cancel_delayed_work_sync(&wvif->beacon_loss_work);
784 wdev->vif[wvif->id] = NULL;
785
786 mutex_unlock(&wdev->conf_mutex);
787
788 wvif = NULL;
789 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
790 /* Combo mode does not support Block Acks. We can re-enable them */
791 if (wvif_count(wdev) == 1)
792 wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
793 else
794 wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
795 }
796}
797
798int wfx_start(struct ieee80211_hw *hw)
799{
800 return 0;
801}
802
803void wfx_stop(struct ieee80211_hw *hw)
804{
805 struct wfx_dev *wdev = hw->priv;
806
807 WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending));
808}