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
wfx_cooling_timeout_work(struct work_struct * work)23 void 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
wfx_suspend_hot_dev(struct wfx_dev * wdev,enum sta_notify_cmd cmd)32 void 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
wfx_filter_beacon(struct wfx_vif * wvif,bool filter_beacon)45 static 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
wfx_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * total_flags,u64 unused)80 void 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
wfx_get_ps_timeout(struct wfx_vif * wvif,bool * enable_ps)135 static 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.chanreq.oper.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.chanreq.oper.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
wfx_update_pm(struct wfx_vif * wvif)180 int 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
wfx_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id,u16 queue,const struct ieee80211_tx_queue_params * params)200 int 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
wfx_set_rts_threshold(struct ieee80211_hw * hw,u32 value)222 int 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
wfx_event_report_rssi(struct wfx_vif * wvif,u8 raw_rcpi_rssi)232 void 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
wfx_beacon_loss_work(struct work_struct * work)249 static 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
wfx_set_default_unicast_key(struct ieee80211_hw * hw,struct ieee80211_vif * vif,int idx)260 void 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
wfx_reset(struct wfx_vif * wvif)267 void 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
wfx_sta_add(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)284 int 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
wfx_sta_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)306 int 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
wfx_upload_ap_templates(struct wfx_vif * wvif)320 static 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
wfx_set_mfp_ap(struct wfx_vif * wvif)339 static 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 int ret = -EINVAL;
348 const u16 *ptr;
349
350 if (unlikely(!skb))
351 return -ENOMEM;
352
353 ptr = (u16 *)cfg80211_find_ie(WLAN_EID_RSN, skb->data + ieoffset,
354 skb->len - ieoffset);
355 if (!ptr) {
356 /* No RSN IE is fine in open networks */
357 ret = 0;
358 goto free_skb;
359 }
360
361 ptr += pairwise_cipher_suite_count_offset;
362 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
363 goto free_skb;
364
365 ptr += 1 + pairwise_cipher_suite_size * *ptr;
366 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
367 goto free_skb;
368
369 ptr += 1 + akm_suite_size * *ptr;
370 if (WARN_ON(ptr > (u16 *)skb_tail_pointer(skb)))
371 goto free_skb;
372
373 wfx_hif_set_mfp(wvif, *ptr & BIT(7), *ptr & BIT(6));
374 ret = 0;
375
376 free_skb:
377 dev_kfree_skb(skb);
378 return ret;
379 }
380
wfx_start_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)381 int wfx_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
382 struct ieee80211_bss_conf *link_conf)
383 {
384 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
385 struct wfx_dev *wdev = wvif->wdev;
386 int ret;
387
388 wvif = NULL;
389 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
390 wfx_update_pm(wvif);
391 wvif = (struct wfx_vif *)vif->drv_priv;
392 wfx_upload_ap_templates(wvif);
393 ret = wfx_hif_start(wvif, &vif->bss_conf, wvif->channel);
394 if (ret > 0)
395 return -EIO;
396 return wfx_set_mfp_ap(wvif);
397 }
398
wfx_stop_ap(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)399 void wfx_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
400 struct ieee80211_bss_conf *link_conf)
401 {
402 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
403 struct wfx_dev *wdev = wvif->wdev;
404
405 wvif = NULL;
406 while ((wvif = wvif_iterate(wdev, wvif)) != NULL)
407 wfx_update_pm(wvif);
408 wvif = (struct wfx_vif *)vif->drv_priv;
409 wfx_reset(wvif);
410 }
411
wfx_join(struct wfx_vif * wvif)412 static void wfx_join(struct wfx_vif *wvif)
413 {
414 struct ieee80211_vif *vif = wvif_to_vif(wvif);
415 struct ieee80211_bss_conf *conf = &vif->bss_conf;
416 struct cfg80211_bss *bss = NULL;
417 u8 ssid[IEEE80211_MAX_SSID_LEN];
418 const u8 *ssid_ie = NULL;
419 int ssid_len = 0;
420 int ret;
421
422 wfx_tx_lock_flush(wvif->wdev);
423
424 bss = cfg80211_get_bss(wvif->wdev->hw->wiphy, wvif->channel, conf->bssid, NULL, 0,
425 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
426 if (!bss && !vif->cfg.ibss_joined) {
427 wfx_tx_unlock(wvif->wdev);
428 return;
429 }
430
431 rcu_read_lock(); /* protect ssid_ie */
432 if (bss)
433 ssid_ie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
434 if (ssid_ie) {
435 ssid_len = ssid_ie[1];
436 if (ssid_len > IEEE80211_MAX_SSID_LEN)
437 ssid_len = IEEE80211_MAX_SSID_LEN;
438 memcpy(ssid, &ssid_ie[2], ssid_len);
439 }
440 rcu_read_unlock();
441
442 cfg80211_put_bss(wvif->wdev->hw->wiphy, bss);
443
444 wvif->join_in_progress = true;
445 ret = wfx_hif_join(wvif, conf, wvif->channel, ssid, ssid_len);
446 if (ret) {
447 ieee80211_connection_loss(vif);
448 wfx_reset(wvif);
449 } else {
450 /* Due to beacon filtering it is possible that the AP's beacon is not known for the
451 * mac80211 stack. Disable filtering temporary to make sure the stack receives at
452 * least one
453 */
454 wfx_filter_beacon(wvif, false);
455 }
456 wfx_tx_unlock(wvif->wdev);
457 }
458
wfx_join_finalize(struct wfx_vif * wvif,struct ieee80211_bss_conf * info)459 static void wfx_join_finalize(struct wfx_vif *wvif, struct ieee80211_bss_conf *info)
460 {
461 struct ieee80211_vif *vif = wvif_to_vif(wvif);
462 struct ieee80211_sta *sta = NULL;
463 int ampdu_density = 0;
464 bool greenfield = false;
465
466 rcu_read_lock(); /* protect sta */
467 if (info->bssid && !vif->cfg.ibss_joined)
468 sta = ieee80211_find_sta(vif, info->bssid);
469 if (sta && sta->deflink.ht_cap.ht_supported)
470 ampdu_density = sta->deflink.ht_cap.ampdu_density;
471 if (sta && sta->deflink.ht_cap.ht_supported &&
472 !(info->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT))
473 greenfield = !!(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD);
474 rcu_read_unlock();
475
476 wvif->join_in_progress = false;
477 wfx_hif_set_association_mode(wvif, ampdu_density, greenfield, info->use_short_preamble);
478 wfx_hif_keep_alive_period(wvif, 0);
479 /* beacon_loss_count is defined to 7 in net/mac80211/mlme.c. Let's use the same value. */
480 wfx_hif_set_bss_params(wvif, vif->cfg.aid, 7);
481 wfx_hif_set_beacon_wakeup_period(wvif, 1, 1);
482 wfx_update_pm(wvif);
483 }
484
wfx_join_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)485 int wfx_join_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
486 {
487 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
488
489 wfx_upload_ap_templates(wvif);
490 wfx_join(wvif);
491 return 0;
492 }
493
wfx_leave_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)494 void wfx_leave_ibss(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
495 {
496 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
497
498 wfx_reset(wvif);
499 }
500
wfx_enable_beacon(struct wfx_vif * wvif,bool enable)501 static void wfx_enable_beacon(struct wfx_vif *wvif, bool enable)
502 {
503 /* Driver has Content After DTIM Beacon in queue. Driver is waiting for a signal from the
504 * firmware. Since we are going to stop to send beacons, this signal will never happens. See
505 * also wfx_suspend_resume_mc()
506 */
507 if (!enable && wfx_tx_queues_has_cab(wvif)) {
508 wvif->after_dtim_tx_allowed = true;
509 wfx_bh_request_tx(wvif->wdev);
510 }
511 wfx_hif_beacon_transmit(wvif, enable);
512 }
513
wfx_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * info,u64 changed)514 void wfx_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
515 struct ieee80211_bss_conf *info, u64 changed)
516 {
517 struct wfx_dev *wdev = hw->priv;
518 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
519 int i;
520
521 mutex_lock(&wdev->conf_mutex);
522
523 if (changed & BSS_CHANGED_BASIC_RATES ||
524 changed & BSS_CHANGED_BEACON_INT ||
525 changed & BSS_CHANGED_BSSID) {
526 if (vif->type == NL80211_IFTYPE_STATION)
527 wfx_join(wvif);
528 }
529
530 if (changed & BSS_CHANGED_ASSOC) {
531 if (vif->cfg.assoc || vif->cfg.ibss_joined)
532 wfx_join_finalize(wvif, info);
533 else if (!vif->cfg.assoc && vif->type == NL80211_IFTYPE_STATION)
534 wfx_reset(wvif);
535 else
536 dev_warn(wdev->dev, "misunderstood change: ASSOC\n");
537 }
538
539 if (changed & BSS_CHANGED_BEACON_INFO) {
540 if (vif->type != NL80211_IFTYPE_STATION)
541 dev_warn(wdev->dev, "misunderstood change: BEACON_INFO\n");
542 wfx_hif_set_beacon_wakeup_period(wvif, info->dtim_period, info->dtim_period);
543 /* We temporary forwarded beacon for join process. It is now no more necessary. */
544 wfx_filter_beacon(wvif, true);
545 }
546
547 if (changed & BSS_CHANGED_ARP_FILTER) {
548 for (i = 0; i < HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES; i++) {
549 __be32 *arp_addr = &vif->cfg.arp_addr_list[i];
550
551 if (vif->cfg.arp_addr_cnt > HIF_MAX_ARP_IP_ADDRTABLE_ENTRIES)
552 arp_addr = NULL;
553 if (i >= vif->cfg.arp_addr_cnt)
554 arp_addr = NULL;
555 wfx_hif_set_arp_ipv4_filter(wvif, i, arp_addr);
556 }
557 }
558
559 if (changed & BSS_CHANGED_AP_PROBE_RESP || changed & BSS_CHANGED_BEACON)
560 wfx_upload_ap_templates(wvif);
561
562 if (changed & BSS_CHANGED_BEACON_ENABLED)
563 wfx_enable_beacon(wvif, info->enable_beacon);
564
565 if (changed & BSS_CHANGED_KEEP_ALIVE)
566 wfx_hif_keep_alive_period(wvif,
567 info->max_idle_period * USEC_PER_TU / USEC_PER_MSEC);
568
569 if (changed & BSS_CHANGED_ERP_CTS_PROT)
570 wfx_hif_erp_use_protection(wvif, info->use_cts_prot);
571
572 if (changed & BSS_CHANGED_ERP_SLOT)
573 wfx_hif_slot_time(wvif, info->use_short_slot ? 9 : 20);
574
575 if (changed & BSS_CHANGED_CQM)
576 wfx_hif_set_rcpi_rssi_threshold(wvif, info->cqm_rssi_thold, info->cqm_rssi_hyst);
577
578 if (changed & BSS_CHANGED_TXPOWER)
579 wfx_hif_set_output_power(wvif, info->txpower);
580
581 if (changed & BSS_CHANGED_PS)
582 wfx_update_pm(wvif);
583
584 mutex_unlock(&wdev->conf_mutex);
585 }
586
wfx_update_tim(struct wfx_vif * wvif)587 static int wfx_update_tim(struct wfx_vif *wvif)
588 {
589 struct ieee80211_vif *vif = wvif_to_vif(wvif);
590 struct sk_buff *skb;
591 u16 tim_offset, tim_length;
592 u8 *tim_ptr;
593
594 skb = ieee80211_beacon_get_tim(wvif->wdev->hw, vif, &tim_offset,
595 &tim_length, 0);
596 if (!skb)
597 return -ENOENT;
598 tim_ptr = skb->data + tim_offset;
599
600 if (tim_offset && tim_length >= 6) {
601 /* Firmware handles DTIM counter internally */
602 tim_ptr[2] = 0;
603
604 /* Set/reset aid0 bit */
605 if (wfx_tx_queues_has_cab(wvif))
606 tim_ptr[4] |= 1;
607 else
608 tim_ptr[4] &= ~1;
609 }
610
611 wfx_hif_update_ie_beacon(wvif, tim_ptr, tim_length);
612 dev_kfree_skb(skb);
613
614 return 0;
615 }
616
wfx_update_tim_work(struct work_struct * work)617 static void wfx_update_tim_work(struct work_struct *work)
618 {
619 struct wfx_vif *wvif = container_of(work, struct wfx_vif, update_tim_work);
620
621 wfx_update_tim(wvif);
622 }
623
wfx_set_tim(struct ieee80211_hw * hw,struct ieee80211_sta * sta,bool set)624 int wfx_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, bool set)
625 {
626 struct wfx_dev *wdev = hw->priv;
627 struct wfx_sta_priv *sta_dev = (struct wfx_sta_priv *)&sta->drv_priv;
628 struct wfx_vif *wvif = wdev_to_wvif(wdev, sta_dev->vif_id);
629
630 if (!wvif) {
631 dev_warn(wdev->dev, "%s: received event for non-existent vif\n", __func__);
632 return -EIO;
633 }
634 schedule_work(&wvif->update_tim_work);
635 return 0;
636 }
637
wfx_suspend_resume_mc(struct wfx_vif * wvif,enum sta_notify_cmd notify_cmd)638 void wfx_suspend_resume_mc(struct wfx_vif *wvif, enum sta_notify_cmd notify_cmd)
639 {
640 if (notify_cmd != STA_NOTIFY_AWAKE)
641 return;
642
643 /* Device won't be able to honor CAB if a scan is in progress on any interface. Prefer to
644 * skip this DTIM and wait for the next one.
645 */
646 if (mutex_is_locked(&wvif->wdev->scan_lock))
647 return;
648
649 if (!wfx_tx_queues_has_cab(wvif) || wvif->after_dtim_tx_allowed)
650 dev_warn(wvif->wdev->dev, "incorrect sequence (%d CAB in queue)",
651 wfx_tx_queues_has_cab(wvif));
652 wvif->after_dtim_tx_allowed = true;
653 wfx_bh_request_tx(wvif->wdev);
654 }
655
wfx_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)656 int wfx_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
657 struct ieee80211_ampdu_params *params)
658 {
659 /* Aggregation is implemented fully in firmware */
660 switch (params->action) {
661 case IEEE80211_AMPDU_RX_START:
662 case IEEE80211_AMPDU_RX_STOP:
663 /* Just acknowledge it to enable frame re-ordering */
664 return 0;
665 default:
666 /* Leave the firmware doing its business for tx aggregation */
667 return -EOPNOTSUPP;
668 }
669 }
670
wfx_add_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf)671 int wfx_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
672 {
673 return 0;
674 }
675
wfx_remove_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf)676 void wfx_remove_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf)
677 {
678 }
679
wfx_change_chanctx(struct ieee80211_hw * hw,struct ieee80211_chanctx_conf * conf,u32 changed)680 void wfx_change_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf, u32 changed)
681 {
682 }
683
wfx_assign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * conf)684 int wfx_assign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
685 struct ieee80211_bss_conf *link_conf,
686 struct ieee80211_chanctx_conf *conf)
687 {
688 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
689 struct ieee80211_channel *ch = conf->def.chan;
690
691 WARN(wvif->channel, "channel overwrite");
692 wvif->channel = ch;
693
694 return 0;
695 }
696
wfx_unassign_vif_chanctx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf,struct ieee80211_chanctx_conf * conf)697 void wfx_unassign_vif_chanctx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
698 struct ieee80211_bss_conf *link_conf,
699 struct ieee80211_chanctx_conf *conf)
700 {
701 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
702 struct ieee80211_channel *ch = conf->def.chan;
703
704 WARN(wvif->channel != ch, "channel mismatch");
705 wvif->channel = NULL;
706 }
707
wfx_config(struct ieee80211_hw * hw,u32 changed)708 int wfx_config(struct ieee80211_hw *hw, u32 changed)
709 {
710 return 0;
711 }
712
wfx_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)713 int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
714 {
715 int i;
716 struct wfx_dev *wdev = hw->priv;
717 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
718
719 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
720 IEEE80211_VIF_SUPPORTS_UAPSD |
721 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
722
723 mutex_lock(&wdev->conf_mutex);
724
725 switch (vif->type) {
726 case NL80211_IFTYPE_STATION:
727 case NL80211_IFTYPE_ADHOC:
728 case NL80211_IFTYPE_AP:
729 break;
730 default:
731 mutex_unlock(&wdev->conf_mutex);
732 return -EOPNOTSUPP;
733 }
734
735 wvif->wdev = wdev;
736
737 wvif->link_id_map = 1; /* link-id 0 is reserved for multicast */
738 INIT_WORK(&wvif->update_tim_work, wfx_update_tim_work);
739 INIT_DELAYED_WORK(&wvif->beacon_loss_work, wfx_beacon_loss_work);
740
741 init_completion(&wvif->set_pm_mode_complete);
742 complete(&wvif->set_pm_mode_complete);
743 INIT_WORK(&wvif->tx_policy_upload_work, wfx_tx_policy_upload_work);
744
745 init_completion(&wvif->scan_complete);
746 INIT_WORK(&wvif->scan_work, wfx_hw_scan_work);
747 INIT_WORK(&wvif->remain_on_channel_work, wfx_remain_on_channel_work);
748
749 wfx_tx_queues_init(wvif);
750 wfx_tx_policy_init(wvif);
751
752 for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
753 if (!wdev->vif[i]) {
754 wdev->vif[i] = vif;
755 wvif->id = i;
756 break;
757 }
758 }
759 WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported");
760
761 wfx_hif_set_macaddr(wvif, vif->addr);
762
763 mutex_unlock(&wdev->conf_mutex);
764
765 wvif = NULL;
766 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
767 /* Combo mode does not support Block Acks. We can re-enable them */
768 if (wvif_count(wdev) == 1)
769 wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
770 else
771 wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
772 }
773 return 0;
774 }
775
wfx_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)776 void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
777 {
778 struct wfx_dev *wdev = hw->priv;
779 struct wfx_vif *wvif = (struct wfx_vif *)vif->drv_priv;
780
781 wait_for_completion_timeout(&wvif->set_pm_mode_complete, msecs_to_jiffies(300));
782 wfx_tx_queues_check_empty(wvif);
783
784 mutex_lock(&wdev->conf_mutex);
785 WARN(wvif->link_id_map != 1, "corrupted state");
786
787 wfx_hif_reset(wvif, false);
788 wfx_hif_set_macaddr(wvif, NULL);
789 wfx_tx_policy_init(wvif);
790
791 cancel_delayed_work_sync(&wvif->beacon_loss_work);
792 wdev->vif[wvif->id] = NULL;
793
794 mutex_unlock(&wdev->conf_mutex);
795
796 wvif = NULL;
797 while ((wvif = wvif_iterate(wdev, wvif)) != NULL) {
798 /* Combo mode does not support Block Acks. We can re-enable them */
799 if (wvif_count(wdev) == 1)
800 wfx_hif_set_block_ack_policy(wvif, 0xFF, 0xFF);
801 else
802 wfx_hif_set_block_ack_policy(wvif, 0x00, 0x00);
803 }
804 }
805
wfx_start(struct ieee80211_hw * hw)806 int wfx_start(struct ieee80211_hw *hw)
807 {
808 return 0;
809 }
810
wfx_stop(struct ieee80211_hw * hw,bool suspend)811 void wfx_stop(struct ieee80211_hw *hw, bool suspend)
812 {
813 struct wfx_dev *wdev = hw->priv;
814
815 WARN_ON(!skb_queue_empty_lockless(&wdev->tx_pending));
816 }
817