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