1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* Copyright(c) 2018-2019 Realtek Corporation 3 */ 4 5 #include "main.h" 6 #include "sec.h" 7 #include "tx.h" 8 #include "fw.h" 9 #include "mac.h" 10 #include "coex.h" 11 #include "ps.h" 12 #include "reg.h" 13 #include "bf.h" 14 #include "debug.h" 15 #include "wow.h" 16 #include "sar.h" 17 18 static void rtw_ops_tx(struct ieee80211_hw *hw, 19 struct ieee80211_tx_control *control, 20 struct sk_buff *skb) 21 { 22 struct rtw_dev *rtwdev = hw->priv; 23 24 if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags)) { 25 ieee80211_free_txskb(hw, skb); 26 return; 27 } 28 29 rtw_tx(rtwdev, control, skb); 30 } 31 32 static void rtw_ops_wake_tx_queue(struct ieee80211_hw *hw, 33 struct ieee80211_txq *txq) 34 { 35 struct rtw_dev *rtwdev = hw->priv; 36 struct rtw_txq *rtwtxq = (struct rtw_txq *)txq->drv_priv; 37 38 if (!test_bit(RTW_FLAG_RUNNING, rtwdev->flags)) 39 return; 40 41 spin_lock_bh(&rtwdev->txq_lock); 42 if (list_empty(&rtwtxq->list)) 43 list_add_tail(&rtwtxq->list, &rtwdev->txqs); 44 spin_unlock_bh(&rtwdev->txq_lock); 45 46 queue_work(rtwdev->tx_wq, &rtwdev->tx_work); 47 } 48 49 static int rtw_ops_start(struct ieee80211_hw *hw) 50 { 51 struct rtw_dev *rtwdev = hw->priv; 52 int ret; 53 54 mutex_lock(&rtwdev->mutex); 55 ret = rtw_core_start(rtwdev); 56 mutex_unlock(&rtwdev->mutex); 57 58 return ret; 59 } 60 61 static void rtw_ops_stop(struct ieee80211_hw *hw) 62 { 63 struct rtw_dev *rtwdev = hw->priv; 64 65 mutex_lock(&rtwdev->mutex); 66 rtw_core_stop(rtwdev); 67 mutex_unlock(&rtwdev->mutex); 68 } 69 70 static int rtw_ops_config(struct ieee80211_hw *hw, u32 changed) 71 { 72 struct rtw_dev *rtwdev = hw->priv; 73 int ret = 0; 74 75 /* let previous ips work finish to ensure we don't leave ips twice */ 76 cancel_work_sync(&rtwdev->ips_work); 77 78 mutex_lock(&rtwdev->mutex); 79 80 rtw_leave_lps_deep(rtwdev); 81 82 if ((changed & IEEE80211_CONF_CHANGE_IDLE) && 83 !(hw->conf.flags & IEEE80211_CONF_IDLE)) { 84 ret = rtw_leave_ips(rtwdev); 85 if (ret) { 86 rtw_err(rtwdev, "failed to leave idle state\n"); 87 goto out; 88 } 89 } 90 91 if (changed & IEEE80211_CONF_CHANGE_PS) { 92 if (hw->conf.flags & IEEE80211_CONF_PS) { 93 rtwdev->ps_enabled = true; 94 } else { 95 rtwdev->ps_enabled = false; 96 rtw_leave_lps(rtwdev); 97 } 98 } 99 100 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) 101 rtw_set_channel(rtwdev); 102 103 if ((changed & IEEE80211_CONF_CHANGE_IDLE) && 104 (hw->conf.flags & IEEE80211_CONF_IDLE)) 105 rtw_enter_ips(rtwdev); 106 107 out: 108 mutex_unlock(&rtwdev->mutex); 109 return ret; 110 } 111 112 static const struct rtw_vif_port rtw_vif_port[] = { 113 [0] = { 114 .mac_addr = {.addr = 0x0610}, 115 .bssid = {.addr = 0x0618}, 116 .net_type = {.addr = 0x0100, .mask = 0x30000}, 117 .aid = {.addr = 0x06a8, .mask = 0x7ff}, 118 .bcn_ctrl = {.addr = 0x0550, .mask = 0xff}, 119 }, 120 [1] = { 121 .mac_addr = {.addr = 0x0700}, 122 .bssid = {.addr = 0x0708}, 123 .net_type = {.addr = 0x0100, .mask = 0xc0000}, 124 .aid = {.addr = 0x0710, .mask = 0x7ff}, 125 .bcn_ctrl = {.addr = 0x0551, .mask = 0xff}, 126 }, 127 [2] = { 128 .mac_addr = {.addr = 0x1620}, 129 .bssid = {.addr = 0x1628}, 130 .net_type = {.addr = 0x1100, .mask = 0x3}, 131 .aid = {.addr = 0x1600, .mask = 0x7ff}, 132 .bcn_ctrl = {.addr = 0x0578, .mask = 0xff}, 133 }, 134 [3] = { 135 .mac_addr = {.addr = 0x1630}, 136 .bssid = {.addr = 0x1638}, 137 .net_type = {.addr = 0x1100, .mask = 0xc}, 138 .aid = {.addr = 0x1604, .mask = 0x7ff}, 139 .bcn_ctrl = {.addr = 0x0579, .mask = 0xff}, 140 }, 141 [4] = { 142 .mac_addr = {.addr = 0x1640}, 143 .bssid = {.addr = 0x1648}, 144 .net_type = {.addr = 0x1100, .mask = 0x30}, 145 .aid = {.addr = 0x1608, .mask = 0x7ff}, 146 .bcn_ctrl = {.addr = 0x057a, .mask = 0xff}, 147 }, 148 }; 149 150 static int rtw_ops_add_interface(struct ieee80211_hw *hw, 151 struct ieee80211_vif *vif) 152 { 153 struct rtw_dev *rtwdev = hw->priv; 154 struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 155 enum rtw_net_type net_type; 156 u32 config = 0; 157 u8 port = 0; 158 u8 bcn_ctrl = 0; 159 160 if (rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_BCN_FILTER)) 161 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 162 IEEE80211_VIF_SUPPORTS_CQM_RSSI; 163 rtwvif->port = port; 164 rtwvif->stats.tx_unicast = 0; 165 rtwvif->stats.rx_unicast = 0; 166 rtwvif->stats.tx_cnt = 0; 167 rtwvif->stats.rx_cnt = 0; 168 rtwvif->scan_req = NULL; 169 memset(&rtwvif->bfee, 0, sizeof(struct rtw_bfee)); 170 rtwvif->conf = &rtw_vif_port[port]; 171 rtw_txq_init(rtwdev, vif->txq); 172 INIT_LIST_HEAD(&rtwvif->rsvd_page_list); 173 174 mutex_lock(&rtwdev->mutex); 175 176 rtw_leave_lps_deep(rtwdev); 177 178 switch (vif->type) { 179 case NL80211_IFTYPE_AP: 180 case NL80211_IFTYPE_MESH_POINT: 181 rtw_add_rsvd_page_bcn(rtwdev, rtwvif); 182 net_type = RTW_NET_AP_MODE; 183 bcn_ctrl = BIT_EN_BCN_FUNCTION | BIT_DIS_TSF_UDT; 184 break; 185 case NL80211_IFTYPE_ADHOC: 186 rtw_add_rsvd_page_bcn(rtwdev, rtwvif); 187 net_type = RTW_NET_AD_HOC; 188 bcn_ctrl = BIT_EN_BCN_FUNCTION | BIT_DIS_TSF_UDT; 189 break; 190 case NL80211_IFTYPE_STATION: 191 rtw_add_rsvd_page_sta(rtwdev, rtwvif); 192 net_type = RTW_NET_NO_LINK; 193 bcn_ctrl = BIT_EN_BCN_FUNCTION; 194 break; 195 default: 196 WARN_ON(1); 197 mutex_unlock(&rtwdev->mutex); 198 return -EINVAL; 199 } 200 201 ether_addr_copy(rtwvif->mac_addr, vif->addr); 202 config |= PORT_SET_MAC_ADDR; 203 rtwvif->net_type = net_type; 204 config |= PORT_SET_NET_TYPE; 205 rtwvif->bcn_ctrl = bcn_ctrl; 206 config |= PORT_SET_BCN_CTRL; 207 rtw_vif_port_config(rtwdev, rtwvif, config); 208 209 mutex_unlock(&rtwdev->mutex); 210 211 rtw_dbg(rtwdev, RTW_DBG_STATE, "start vif %pM on port %d\n", vif->addr, rtwvif->port); 212 return 0; 213 } 214 215 static void rtw_ops_remove_interface(struct ieee80211_hw *hw, 216 struct ieee80211_vif *vif) 217 { 218 struct rtw_dev *rtwdev = hw->priv; 219 struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 220 u32 config = 0; 221 222 rtw_dbg(rtwdev, RTW_DBG_STATE, "stop vif %pM on port %d\n", vif->addr, rtwvif->port); 223 224 mutex_lock(&rtwdev->mutex); 225 226 rtw_leave_lps_deep(rtwdev); 227 228 rtw_txq_cleanup(rtwdev, vif->txq); 229 rtw_remove_rsvd_page(rtwdev, rtwvif); 230 231 eth_zero_addr(rtwvif->mac_addr); 232 config |= PORT_SET_MAC_ADDR; 233 rtwvif->net_type = RTW_NET_NO_LINK; 234 config |= PORT_SET_NET_TYPE; 235 rtwvif->bcn_ctrl = 0; 236 config |= PORT_SET_BCN_CTRL; 237 rtw_vif_port_config(rtwdev, rtwvif, config); 238 239 mutex_unlock(&rtwdev->mutex); 240 } 241 242 static int rtw_ops_change_interface(struct ieee80211_hw *hw, 243 struct ieee80211_vif *vif, 244 enum nl80211_iftype type, bool p2p) 245 { 246 struct rtw_dev *rtwdev = hw->priv; 247 248 rtw_dbg(rtwdev, RTW_DBG_STATE, "change vif %pM (%d)->(%d), p2p (%d)->(%d)\n", 249 vif->addr, vif->type, type, vif->p2p, p2p); 250 251 rtw_ops_remove_interface(hw, vif); 252 253 vif->type = type; 254 vif->p2p = p2p; 255 256 return rtw_ops_add_interface(hw, vif); 257 } 258 259 static void rtw_ops_configure_filter(struct ieee80211_hw *hw, 260 unsigned int changed_flags, 261 unsigned int *new_flags, 262 u64 multicast) 263 { 264 struct rtw_dev *rtwdev = hw->priv; 265 266 *new_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_FCSFAIL | 267 FIF_BCN_PRBRESP_PROMISC; 268 269 mutex_lock(&rtwdev->mutex); 270 271 rtw_leave_lps_deep(rtwdev); 272 273 if (changed_flags & FIF_ALLMULTI) { 274 if (*new_flags & FIF_ALLMULTI) 275 rtwdev->hal.rcr |= BIT_AM | BIT_AB; 276 else 277 rtwdev->hal.rcr &= ~(BIT_AM | BIT_AB); 278 } 279 if (changed_flags & FIF_FCSFAIL) { 280 if (*new_flags & FIF_FCSFAIL) 281 rtwdev->hal.rcr |= BIT_ACRC32; 282 else 283 rtwdev->hal.rcr &= ~(BIT_ACRC32); 284 } 285 if (changed_flags & FIF_OTHER_BSS) { 286 if (*new_flags & FIF_OTHER_BSS) 287 rtwdev->hal.rcr |= BIT_AAP; 288 else 289 rtwdev->hal.rcr &= ~(BIT_AAP); 290 } 291 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { 292 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) 293 rtwdev->hal.rcr &= ~(BIT_CBSSID_BCN | BIT_CBSSID_DATA); 294 else 295 rtwdev->hal.rcr |= BIT_CBSSID_BCN; 296 } 297 298 rtw_dbg(rtwdev, RTW_DBG_RX, 299 "config rx filter, changed=0x%08x, new=0x%08x, rcr=0x%08x\n", 300 changed_flags, *new_flags, rtwdev->hal.rcr); 301 302 rtw_write32(rtwdev, REG_RCR, rtwdev->hal.rcr); 303 304 mutex_unlock(&rtwdev->mutex); 305 } 306 307 /* Only have one group of EDCA parameters now */ 308 static const u32 ac_to_edca_param[IEEE80211_NUM_ACS] = { 309 [IEEE80211_AC_VO] = REG_EDCA_VO_PARAM, 310 [IEEE80211_AC_VI] = REG_EDCA_VI_PARAM, 311 [IEEE80211_AC_BE] = REG_EDCA_BE_PARAM, 312 [IEEE80211_AC_BK] = REG_EDCA_BK_PARAM, 313 }; 314 315 static u8 rtw_aifsn_to_aifs(struct rtw_dev *rtwdev, 316 struct rtw_vif *rtwvif, u8 aifsn) 317 { 318 struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif); 319 u8 slot_time; 320 u8 sifs; 321 322 slot_time = vif->bss_conf.use_short_slot ? 9 : 20; 323 sifs = rtwdev->hal.current_band_type == RTW_BAND_5G ? 16 : 10; 324 325 return aifsn * slot_time + sifs; 326 } 327 328 static void __rtw_conf_tx(struct rtw_dev *rtwdev, 329 struct rtw_vif *rtwvif, u16 ac) 330 { 331 struct ieee80211_tx_queue_params *params = &rtwvif->tx_params[ac]; 332 u32 edca_param = ac_to_edca_param[ac]; 333 u8 ecw_max, ecw_min; 334 u8 aifs; 335 336 /* 2^ecw - 1 = cw; ecw = log2(cw + 1) */ 337 ecw_max = ilog2(params->cw_max + 1); 338 ecw_min = ilog2(params->cw_min + 1); 339 aifs = rtw_aifsn_to_aifs(rtwdev, rtwvif, params->aifs); 340 rtw_write32_mask(rtwdev, edca_param, BIT_MASK_TXOP_LMT, params->txop); 341 rtw_write32_mask(rtwdev, edca_param, BIT_MASK_CWMAX, ecw_max); 342 rtw_write32_mask(rtwdev, edca_param, BIT_MASK_CWMIN, ecw_min); 343 rtw_write32_mask(rtwdev, edca_param, BIT_MASK_AIFS, aifs); 344 } 345 346 static void rtw_conf_tx(struct rtw_dev *rtwdev, 347 struct rtw_vif *rtwvif) 348 { 349 u16 ac; 350 351 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 352 __rtw_conf_tx(rtwdev, rtwvif, ac); 353 } 354 355 static void rtw_ops_bss_info_changed(struct ieee80211_hw *hw, 356 struct ieee80211_vif *vif, 357 struct ieee80211_bss_conf *conf, 358 u32 changed) 359 { 360 struct rtw_dev *rtwdev = hw->priv; 361 struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 362 struct rtw_coex *coex = &rtwdev->coex; 363 struct rtw_coex_stat *coex_stat = &coex->stat; 364 u32 config = 0; 365 366 mutex_lock(&rtwdev->mutex); 367 368 rtw_leave_lps_deep(rtwdev); 369 370 if (changed & BSS_CHANGED_ASSOC) { 371 rtw_vif_assoc_changed(rtwvif, conf); 372 if (conf->assoc) { 373 rtw_coex_connect_notify(rtwdev, COEX_ASSOCIATE_FINISH); 374 375 rtw_fw_download_rsvd_page(rtwdev); 376 rtw_send_rsvd_page_h2c(rtwdev); 377 rtw_coex_media_status_notify(rtwdev, conf->assoc); 378 if (rtw_bf_support) 379 rtw_bf_assoc(rtwdev, vif, conf); 380 rtw_store_op_chan(rtwdev); 381 } else { 382 rtw_leave_lps(rtwdev); 383 rtw_bf_disassoc(rtwdev, vif, conf); 384 /* Abort ongoing scan if cancel_scan isn't issued 385 * when disconnected by peer 386 */ 387 if (test_bit(RTW_FLAG_SCANNING, rtwdev->flags)) 388 rtw_hw_scan_abort(rtwdev, vif); 389 } 390 391 config |= PORT_SET_NET_TYPE; 392 config |= PORT_SET_AID; 393 } 394 395 if (changed & BSS_CHANGED_BSSID) { 396 ether_addr_copy(rtwvif->bssid, conf->bssid); 397 config |= PORT_SET_BSSID; 398 } 399 400 if (changed & BSS_CHANGED_BEACON_INT) { 401 if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_STATION) 402 coex_stat->wl_beacon_interval = conf->beacon_int; 403 } 404 405 if (changed & BSS_CHANGED_BEACON) 406 rtw_fw_download_rsvd_page(rtwdev); 407 408 if (changed & BSS_CHANGED_BEACON_ENABLED) { 409 if (conf->enable_beacon) 410 rtw_write32_set(rtwdev, REG_FWHW_TXQ_CTRL, 411 BIT_EN_BCNQ_DL); 412 else 413 rtw_write32_clr(rtwdev, REG_FWHW_TXQ_CTRL, 414 BIT_EN_BCNQ_DL); 415 } 416 if (changed & BSS_CHANGED_CQM) 417 rtw_fw_beacon_filter_config(rtwdev, true, vif); 418 419 if (changed & BSS_CHANGED_MU_GROUPS) 420 rtw_chip_set_gid_table(rtwdev, vif, conf); 421 422 if (changed & BSS_CHANGED_ERP_SLOT) 423 rtw_conf_tx(rtwdev, rtwvif); 424 425 rtw_vif_port_config(rtwdev, rtwvif, config); 426 427 mutex_unlock(&rtwdev->mutex); 428 } 429 430 static int rtw_ops_conf_tx(struct ieee80211_hw *hw, 431 struct ieee80211_vif *vif, u16 ac, 432 const struct ieee80211_tx_queue_params *params) 433 { 434 struct rtw_dev *rtwdev = hw->priv; 435 struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 436 437 mutex_lock(&rtwdev->mutex); 438 439 rtw_leave_lps_deep(rtwdev); 440 441 rtwvif->tx_params[ac] = *params; 442 __rtw_conf_tx(rtwdev, rtwvif, ac); 443 444 mutex_unlock(&rtwdev->mutex); 445 446 return 0; 447 } 448 449 static int rtw_ops_sta_add(struct ieee80211_hw *hw, 450 struct ieee80211_vif *vif, 451 struct ieee80211_sta *sta) 452 { 453 struct rtw_dev *rtwdev = hw->priv; 454 int ret = 0; 455 456 mutex_lock(&rtwdev->mutex); 457 ret = rtw_sta_add(rtwdev, sta, vif); 458 mutex_unlock(&rtwdev->mutex); 459 460 return ret; 461 } 462 463 static int rtw_ops_sta_remove(struct ieee80211_hw *hw, 464 struct ieee80211_vif *vif, 465 struct ieee80211_sta *sta) 466 { 467 struct rtw_dev *rtwdev = hw->priv; 468 469 rtw_fw_beacon_filter_config(rtwdev, false, vif); 470 mutex_lock(&rtwdev->mutex); 471 rtw_sta_remove(rtwdev, sta, true); 472 mutex_unlock(&rtwdev->mutex); 473 474 return 0; 475 } 476 477 static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 478 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 479 struct ieee80211_key_conf *key) 480 { 481 struct rtw_dev *rtwdev = hw->priv; 482 struct rtw_sec_desc *sec = &rtwdev->sec; 483 u8 hw_key_type; 484 u8 hw_key_idx; 485 int ret = 0; 486 487 switch (key->cipher) { 488 case WLAN_CIPHER_SUITE_WEP40: 489 hw_key_type = RTW_CAM_WEP40; 490 break; 491 case WLAN_CIPHER_SUITE_WEP104: 492 hw_key_type = RTW_CAM_WEP104; 493 break; 494 case WLAN_CIPHER_SUITE_TKIP: 495 hw_key_type = RTW_CAM_TKIP; 496 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 497 break; 498 case WLAN_CIPHER_SUITE_CCMP: 499 hw_key_type = RTW_CAM_AES; 500 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; 501 break; 502 case WLAN_CIPHER_SUITE_AES_CMAC: 503 case WLAN_CIPHER_SUITE_BIP_CMAC_256: 504 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 505 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 506 case WLAN_CIPHER_SUITE_CCMP_256: 507 case WLAN_CIPHER_SUITE_GCMP: 508 case WLAN_CIPHER_SUITE_GCMP_256: 509 /* suppress error messages */ 510 return -EOPNOTSUPP; 511 default: 512 return -ENOTSUPP; 513 } 514 515 mutex_lock(&rtwdev->mutex); 516 517 rtw_leave_lps_deep(rtwdev); 518 519 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { 520 hw_key_idx = rtw_sec_get_free_cam(sec); 521 } else { 522 /* multiple interfaces? */ 523 hw_key_idx = key->keyidx; 524 } 525 526 if (hw_key_idx > sec->total_cam_num) { 527 ret = -ENOSPC; 528 goto out; 529 } 530 531 switch (cmd) { 532 case SET_KEY: 533 /* need sw generated IV */ 534 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 535 key->hw_key_idx = hw_key_idx; 536 rtw_sec_write_cam(rtwdev, sec, sta, key, 537 hw_key_type, hw_key_idx); 538 break; 539 case DISABLE_KEY: 540 rtw_hci_flush_all_queues(rtwdev, false); 541 rtw_mac_flush_all_queues(rtwdev, false); 542 rtw_sec_clear_cam(rtwdev, sec, key->hw_key_idx); 543 break; 544 } 545 546 /* download new cam settings for PG to backup */ 547 if (rtw_get_lps_deep_mode(rtwdev) == LPS_DEEP_MODE_PG) 548 rtw_fw_download_rsvd_page(rtwdev); 549 550 out: 551 mutex_unlock(&rtwdev->mutex); 552 553 return ret; 554 } 555 556 static int rtw_ops_ampdu_action(struct ieee80211_hw *hw, 557 struct ieee80211_vif *vif, 558 struct ieee80211_ampdu_params *params) 559 { 560 struct ieee80211_sta *sta = params->sta; 561 u16 tid = params->tid; 562 struct ieee80211_txq *txq = sta->txq[tid]; 563 struct rtw_txq *rtwtxq = (struct rtw_txq *)txq->drv_priv; 564 565 switch (params->action) { 566 case IEEE80211_AMPDU_TX_START: 567 return IEEE80211_AMPDU_TX_START_IMMEDIATE; 568 case IEEE80211_AMPDU_TX_STOP_CONT: 569 case IEEE80211_AMPDU_TX_STOP_FLUSH: 570 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 571 clear_bit(RTW_TXQ_AMPDU, &rtwtxq->flags); 572 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 573 break; 574 case IEEE80211_AMPDU_TX_OPERATIONAL: 575 set_bit(RTW_TXQ_AMPDU, &rtwtxq->flags); 576 break; 577 case IEEE80211_AMPDU_RX_START: 578 case IEEE80211_AMPDU_RX_STOP: 579 break; 580 default: 581 WARN_ON(1); 582 return -ENOTSUPP; 583 } 584 585 return 0; 586 } 587 588 static bool rtw_ops_can_aggregate_in_amsdu(struct ieee80211_hw *hw, 589 struct sk_buff *head, 590 struct sk_buff *skb) 591 { 592 struct rtw_dev *rtwdev = hw->priv; 593 struct rtw_hal *hal = &rtwdev->hal; 594 595 /* we don't want to enable TX AMSDU on 2.4G */ 596 if (hal->current_band_type == RTW_BAND_2G) 597 return false; 598 599 return true; 600 } 601 602 static void rtw_ops_sw_scan_start(struct ieee80211_hw *hw, 603 struct ieee80211_vif *vif, 604 const u8 *mac_addr) 605 { 606 struct rtw_dev *rtwdev = hw->priv; 607 struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 608 609 mutex_lock(&rtwdev->mutex); 610 rtw_core_scan_start(rtwdev, rtwvif, mac_addr, false); 611 mutex_unlock(&rtwdev->mutex); 612 } 613 614 static void rtw_ops_sw_scan_complete(struct ieee80211_hw *hw, 615 struct ieee80211_vif *vif) 616 { 617 struct rtw_dev *rtwdev = hw->priv; 618 619 mutex_lock(&rtwdev->mutex); 620 rtw_core_scan_complete(rtwdev, vif, false); 621 mutex_unlock(&rtwdev->mutex); 622 } 623 624 static void rtw_ops_mgd_prepare_tx(struct ieee80211_hw *hw, 625 struct ieee80211_vif *vif, 626 struct ieee80211_prep_tx_info *info) 627 { 628 struct rtw_dev *rtwdev = hw->priv; 629 630 mutex_lock(&rtwdev->mutex); 631 rtw_leave_lps_deep(rtwdev); 632 rtw_coex_connect_notify(rtwdev, COEX_ASSOCIATE_START); 633 rtw_chip_prepare_tx(rtwdev); 634 mutex_unlock(&rtwdev->mutex); 635 } 636 637 static int rtw_ops_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 638 { 639 struct rtw_dev *rtwdev = hw->priv; 640 641 mutex_lock(&rtwdev->mutex); 642 rtwdev->rts_threshold = value; 643 mutex_unlock(&rtwdev->mutex); 644 645 return 0; 646 } 647 648 static void rtw_ops_sta_statistics(struct ieee80211_hw *hw, 649 struct ieee80211_vif *vif, 650 struct ieee80211_sta *sta, 651 struct station_info *sinfo) 652 { 653 struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv; 654 655 sinfo->txrate = si->ra_report.txrate; 656 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 657 } 658 659 static void rtw_ops_flush(struct ieee80211_hw *hw, 660 struct ieee80211_vif *vif, 661 u32 queues, bool drop) 662 { 663 struct rtw_dev *rtwdev = hw->priv; 664 665 mutex_lock(&rtwdev->mutex); 666 rtw_leave_lps_deep(rtwdev); 667 668 rtw_hci_flush_queues(rtwdev, queues, drop); 669 rtw_mac_flush_queues(rtwdev, queues, drop); 670 mutex_unlock(&rtwdev->mutex); 671 } 672 673 struct rtw_iter_bitrate_mask_data { 674 struct rtw_dev *rtwdev; 675 struct ieee80211_vif *vif; 676 const struct cfg80211_bitrate_mask *mask; 677 }; 678 679 static void rtw_ra_mask_info_update_iter(void *data, struct ieee80211_sta *sta) 680 { 681 struct rtw_iter_bitrate_mask_data *br_data = data; 682 struct rtw_sta_info *si = (struct rtw_sta_info *)sta->drv_priv; 683 684 if (si->vif != br_data->vif) 685 return; 686 687 /* free previous mask setting */ 688 kfree(si->mask); 689 si->mask = kmemdup(br_data->mask, sizeof(struct cfg80211_bitrate_mask), 690 GFP_ATOMIC); 691 if (!si->mask) { 692 si->use_cfg_mask = false; 693 return; 694 } 695 696 si->use_cfg_mask = true; 697 rtw_update_sta_info(br_data->rtwdev, si); 698 } 699 700 static void rtw_ra_mask_info_update(struct rtw_dev *rtwdev, 701 struct ieee80211_vif *vif, 702 const struct cfg80211_bitrate_mask *mask) 703 { 704 struct rtw_iter_bitrate_mask_data br_data; 705 706 br_data.rtwdev = rtwdev; 707 br_data.vif = vif; 708 br_data.mask = mask; 709 rtw_iterate_stas_atomic(rtwdev, rtw_ra_mask_info_update_iter, &br_data); 710 } 711 712 static int rtw_ops_set_bitrate_mask(struct ieee80211_hw *hw, 713 struct ieee80211_vif *vif, 714 const struct cfg80211_bitrate_mask *mask) 715 { 716 struct rtw_dev *rtwdev = hw->priv; 717 718 rtw_ra_mask_info_update(rtwdev, vif, mask); 719 720 return 0; 721 } 722 723 static int rtw_ops_set_antenna(struct ieee80211_hw *hw, 724 u32 tx_antenna, 725 u32 rx_antenna) 726 { 727 struct rtw_dev *rtwdev = hw->priv; 728 struct rtw_chip_info *chip = rtwdev->chip; 729 int ret; 730 731 if (!chip->ops->set_antenna) 732 return -EOPNOTSUPP; 733 734 mutex_lock(&rtwdev->mutex); 735 ret = chip->ops->set_antenna(rtwdev, tx_antenna, rx_antenna); 736 mutex_unlock(&rtwdev->mutex); 737 738 return ret; 739 } 740 741 static int rtw_ops_get_antenna(struct ieee80211_hw *hw, 742 u32 *tx_antenna, 743 u32 *rx_antenna) 744 { 745 struct rtw_dev *rtwdev = hw->priv; 746 struct rtw_hal *hal = &rtwdev->hal; 747 748 *tx_antenna = hal->antenna_tx; 749 *rx_antenna = hal->antenna_rx; 750 751 return 0; 752 } 753 754 #ifdef CONFIG_PM 755 static int rtw_ops_suspend(struct ieee80211_hw *hw, 756 struct cfg80211_wowlan *wowlan) 757 { 758 struct rtw_dev *rtwdev = hw->priv; 759 int ret; 760 761 mutex_lock(&rtwdev->mutex); 762 ret = rtw_wow_suspend(rtwdev, wowlan); 763 if (ret) 764 rtw_err(rtwdev, "failed to suspend for wow %d\n", ret); 765 mutex_unlock(&rtwdev->mutex); 766 767 return ret ? 1 : 0; 768 } 769 770 static int rtw_ops_resume(struct ieee80211_hw *hw) 771 { 772 struct rtw_dev *rtwdev = hw->priv; 773 int ret; 774 775 mutex_lock(&rtwdev->mutex); 776 ret = rtw_wow_resume(rtwdev); 777 if (ret) 778 rtw_err(rtwdev, "failed to resume for wow %d\n", ret); 779 mutex_unlock(&rtwdev->mutex); 780 781 return ret ? 1 : 0; 782 } 783 784 static void rtw_ops_set_wakeup(struct ieee80211_hw *hw, bool enabled) 785 { 786 struct rtw_dev *rtwdev = hw->priv; 787 788 device_set_wakeup_enable(rtwdev->dev, enabled); 789 } 790 #endif 791 792 static void rtw_reconfig_complete(struct ieee80211_hw *hw, 793 enum ieee80211_reconfig_type reconfig_type) 794 { 795 struct rtw_dev *rtwdev = hw->priv; 796 797 mutex_lock(&rtwdev->mutex); 798 if (reconfig_type == IEEE80211_RECONFIG_TYPE_RESTART) 799 clear_bit(RTW_FLAG_RESTARTING, rtwdev->flags); 800 mutex_unlock(&rtwdev->mutex); 801 } 802 803 static int rtw_ops_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 804 struct ieee80211_scan_request *req) 805 { 806 struct rtw_dev *rtwdev = hw->priv; 807 int ret; 808 809 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_SCAN_OFFLOAD)) 810 return 1; 811 812 if (test_bit(RTW_FLAG_SCANNING, rtwdev->flags)) 813 return -EBUSY; 814 815 mutex_lock(&rtwdev->mutex); 816 rtw_hw_scan_start(rtwdev, vif, req); 817 ret = rtw_hw_scan_offload(rtwdev, vif, true); 818 if (ret) { 819 rtw_hw_scan_abort(rtwdev, vif); 820 rtw_err(rtwdev, "HW scan failed with status: %d\n", ret); 821 } 822 mutex_unlock(&rtwdev->mutex); 823 824 return ret; 825 } 826 827 static void rtw_ops_cancel_hw_scan(struct ieee80211_hw *hw, 828 struct ieee80211_vif *vif) 829 { 830 struct rtw_dev *rtwdev = hw->priv; 831 832 if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_SCAN_OFFLOAD)) 833 return; 834 835 if (!test_bit(RTW_FLAG_SCANNING, rtwdev->flags)) 836 return; 837 838 mutex_lock(&rtwdev->mutex); 839 rtw_hw_scan_abort(rtwdev, vif); 840 mutex_unlock(&rtwdev->mutex); 841 } 842 843 static int rtw_ops_set_sar_specs(struct ieee80211_hw *hw, 844 const struct cfg80211_sar_specs *sar) 845 { 846 struct rtw_dev *rtwdev = hw->priv; 847 848 rtw_set_sar_specs(rtwdev, sar); 849 850 return 0; 851 } 852 853 const struct ieee80211_ops rtw_ops = { 854 .tx = rtw_ops_tx, 855 .wake_tx_queue = rtw_ops_wake_tx_queue, 856 .start = rtw_ops_start, 857 .stop = rtw_ops_stop, 858 .config = rtw_ops_config, 859 .add_interface = rtw_ops_add_interface, 860 .remove_interface = rtw_ops_remove_interface, 861 .change_interface = rtw_ops_change_interface, 862 .configure_filter = rtw_ops_configure_filter, 863 .bss_info_changed = rtw_ops_bss_info_changed, 864 .conf_tx = rtw_ops_conf_tx, 865 .sta_add = rtw_ops_sta_add, 866 .sta_remove = rtw_ops_sta_remove, 867 .set_key = rtw_ops_set_key, 868 .ampdu_action = rtw_ops_ampdu_action, 869 .can_aggregate_in_amsdu = rtw_ops_can_aggregate_in_amsdu, 870 .sw_scan_start = rtw_ops_sw_scan_start, 871 .sw_scan_complete = rtw_ops_sw_scan_complete, 872 .mgd_prepare_tx = rtw_ops_mgd_prepare_tx, 873 .set_rts_threshold = rtw_ops_set_rts_threshold, 874 .sta_statistics = rtw_ops_sta_statistics, 875 .flush = rtw_ops_flush, 876 .set_bitrate_mask = rtw_ops_set_bitrate_mask, 877 .set_antenna = rtw_ops_set_antenna, 878 .get_antenna = rtw_ops_get_antenna, 879 .reconfig_complete = rtw_reconfig_complete, 880 .hw_scan = rtw_ops_hw_scan, 881 .cancel_hw_scan = rtw_ops_cancel_hw_scan, 882 .set_sar_specs = rtw_ops_set_sar_specs, 883 #ifdef CONFIG_PM 884 .suspend = rtw_ops_suspend, 885 .resume = rtw_ops_resume, 886 .set_wakeup = rtw_ops_set_wakeup, 887 #endif 888 }; 889 EXPORT_SYMBOL(rtw_ops); 890