1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2009-2012 Realtek Corporation.*/ 3 4 #include "wifi.h" 5 #include "rc.h" 6 #include "base.h" 7 #include "efuse.h" 8 #include "cam.h" 9 #include "ps.h" 10 #include "regd.h" 11 #include "pci.h" 12 #include <linux/ip.h> 13 #include <linux/module.h> 14 #include <linux/udp.h> 15 16 /* 17 *NOTICE!!!: This file will be very big, we should 18 *keep it clear under following roles: 19 * 20 *This file include following parts, so, if you add new 21 *functions into this file, please check which part it 22 *should includes. or check if you should add new part 23 *for this file: 24 * 25 *1) mac80211 init functions 26 *2) tx information functions 27 *3) functions called by core.c 28 *4) wq & timer callback functions 29 *5) frame process functions 30 *6) IOT functions 31 *7) sysfs functions 32 *8) vif functions 33 *9) ... 34 */ 35 36 /********************************************************* 37 * 38 * mac80211 init functions 39 * 40 *********************************************************/ 41 static struct ieee80211_channel rtl_channeltable_2g[] = { 42 {.center_freq = 2412, .hw_value = 1,}, 43 {.center_freq = 2417, .hw_value = 2,}, 44 {.center_freq = 2422, .hw_value = 3,}, 45 {.center_freq = 2427, .hw_value = 4,}, 46 {.center_freq = 2432, .hw_value = 5,}, 47 {.center_freq = 2437, .hw_value = 6,}, 48 {.center_freq = 2442, .hw_value = 7,}, 49 {.center_freq = 2447, .hw_value = 8,}, 50 {.center_freq = 2452, .hw_value = 9,}, 51 {.center_freq = 2457, .hw_value = 10,}, 52 {.center_freq = 2462, .hw_value = 11,}, 53 {.center_freq = 2467, .hw_value = 12,}, 54 {.center_freq = 2472, .hw_value = 13,}, 55 {.center_freq = 2484, .hw_value = 14,}, 56 }; 57 58 static struct ieee80211_channel rtl_channeltable_5g[] = { 59 {.center_freq = 5180, .hw_value = 36,}, 60 {.center_freq = 5200, .hw_value = 40,}, 61 {.center_freq = 5220, .hw_value = 44,}, 62 {.center_freq = 5240, .hw_value = 48,}, 63 {.center_freq = 5260, .hw_value = 52,}, 64 {.center_freq = 5280, .hw_value = 56,}, 65 {.center_freq = 5300, .hw_value = 60,}, 66 {.center_freq = 5320, .hw_value = 64,}, 67 {.center_freq = 5500, .hw_value = 100,}, 68 {.center_freq = 5520, .hw_value = 104,}, 69 {.center_freq = 5540, .hw_value = 108,}, 70 {.center_freq = 5560, .hw_value = 112,}, 71 {.center_freq = 5580, .hw_value = 116,}, 72 {.center_freq = 5600, .hw_value = 120,}, 73 {.center_freq = 5620, .hw_value = 124,}, 74 {.center_freq = 5640, .hw_value = 128,}, 75 {.center_freq = 5660, .hw_value = 132,}, 76 {.center_freq = 5680, .hw_value = 136,}, 77 {.center_freq = 5700, .hw_value = 140,}, 78 {.center_freq = 5745, .hw_value = 149,}, 79 {.center_freq = 5765, .hw_value = 153,}, 80 {.center_freq = 5785, .hw_value = 157,}, 81 {.center_freq = 5805, .hw_value = 161,}, 82 {.center_freq = 5825, .hw_value = 165,}, 83 }; 84 85 static struct ieee80211_rate rtl_ratetable_2g[] = { 86 {.bitrate = 10, .hw_value = 0x00,}, 87 {.bitrate = 20, .hw_value = 0x01,}, 88 {.bitrate = 55, .hw_value = 0x02,}, 89 {.bitrate = 110, .hw_value = 0x03,}, 90 {.bitrate = 60, .hw_value = 0x04,}, 91 {.bitrate = 90, .hw_value = 0x05,}, 92 {.bitrate = 120, .hw_value = 0x06,}, 93 {.bitrate = 180, .hw_value = 0x07,}, 94 {.bitrate = 240, .hw_value = 0x08,}, 95 {.bitrate = 360, .hw_value = 0x09,}, 96 {.bitrate = 480, .hw_value = 0x0a,}, 97 {.bitrate = 540, .hw_value = 0x0b,}, 98 }; 99 100 static struct ieee80211_rate rtl_ratetable_5g[] = { 101 {.bitrate = 60, .hw_value = 0x04,}, 102 {.bitrate = 90, .hw_value = 0x05,}, 103 {.bitrate = 120, .hw_value = 0x06,}, 104 {.bitrate = 180, .hw_value = 0x07,}, 105 {.bitrate = 240, .hw_value = 0x08,}, 106 {.bitrate = 360, .hw_value = 0x09,}, 107 {.bitrate = 480, .hw_value = 0x0a,}, 108 {.bitrate = 540, .hw_value = 0x0b,}, 109 }; 110 111 static const struct ieee80211_supported_band rtl_band_2ghz = { 112 .band = NL80211_BAND_2GHZ, 113 114 .channels = rtl_channeltable_2g, 115 .n_channels = ARRAY_SIZE(rtl_channeltable_2g), 116 117 .bitrates = rtl_ratetable_2g, 118 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), 119 120 .ht_cap = {0}, 121 }; 122 123 static struct ieee80211_supported_band rtl_band_5ghz = { 124 .band = NL80211_BAND_5GHZ, 125 126 .channels = rtl_channeltable_5g, 127 .n_channels = ARRAY_SIZE(rtl_channeltable_5g), 128 129 .bitrates = rtl_ratetable_5g, 130 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), 131 132 .ht_cap = {0}, 133 }; 134 135 static const u8 tid_to_ac[] = { 136 2, /* IEEE80211_AC_BE */ 137 3, /* IEEE80211_AC_BK */ 138 3, /* IEEE80211_AC_BK */ 139 2, /* IEEE80211_AC_BE */ 140 1, /* IEEE80211_AC_VI */ 141 1, /* IEEE80211_AC_VI */ 142 0, /* IEEE80211_AC_VO */ 143 0, /* IEEE80211_AC_VO */ 144 }; 145 146 u8 rtl_tid_to_ac(u8 tid) 147 { 148 return tid_to_ac[tid]; 149 } 150 EXPORT_SYMBOL_GPL(rtl_tid_to_ac); 151 152 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, 153 struct ieee80211_sta_ht_cap *ht_cap) 154 { 155 struct rtl_priv *rtlpriv = rtl_priv(hw); 156 struct rtl_phy *rtlphy = &(rtlpriv->phy); 157 158 ht_cap->ht_supported = true; 159 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 160 IEEE80211_HT_CAP_SGI_40 | 161 IEEE80211_HT_CAP_SGI_20 | 162 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; 163 164 if (rtlpriv->rtlhal.disable_amsdu_8k) 165 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; 166 167 /* 168 *Maximum length of AMPDU that the STA can receive. 169 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) 170 */ 171 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; 172 173 /*Minimum MPDU start spacing , */ 174 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; 175 176 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; 177 178 /*hw->wiphy->bands[NL80211_BAND_2GHZ] 179 *base on ant_num 180 *rx_mask: RX mask 181 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 182 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15 183 *if rx_ant >= 3 rx_mask[2]= 0xff; 184 *if BW_40 rx_mask[4]= 0x01; 185 *highest supported RX rate 186 */ 187 if (rtlpriv->dm.supp_phymode_switch) { 188 pr_info("Support phy mode switch\n"); 189 190 ht_cap->mcs.rx_mask[0] = 0xFF; 191 ht_cap->mcs.rx_mask[1] = 0xFF; 192 ht_cap->mcs.rx_mask[4] = 0x01; 193 194 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); 195 } else { 196 if (get_rf_type(rtlphy) == RF_1T2R || 197 get_rf_type(rtlphy) == RF_2T2R) { 198 rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG, 199 "1T2R or 2T2R\n"); 200 ht_cap->mcs.rx_mask[0] = 0xFF; 201 ht_cap->mcs.rx_mask[1] = 0xFF; 202 ht_cap->mcs.rx_mask[4] = 0x01; 203 204 ht_cap->mcs.rx_highest = 205 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); 206 } else if (get_rf_type(rtlphy) == RF_1T1R) { 207 rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); 208 209 ht_cap->mcs.rx_mask[0] = 0xFF; 210 ht_cap->mcs.rx_mask[1] = 0x00; 211 ht_cap->mcs.rx_mask[4] = 0x01; 212 213 ht_cap->mcs.rx_highest = 214 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); 215 } 216 } 217 } 218 219 static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw, 220 struct ieee80211_sta_vht_cap *vht_cap) 221 { 222 struct rtl_priv *rtlpriv = rtl_priv(hw); 223 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 224 225 if (!(rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT)) 226 return; 227 228 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE || 229 rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) { 230 u16 mcs_map; 231 232 vht_cap->vht_supported = true; 233 vht_cap->cap = 234 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | 235 IEEE80211_VHT_CAP_SHORT_GI_80 | 236 IEEE80211_VHT_CAP_TXSTBC | 237 IEEE80211_VHT_CAP_RXSTBC_1 | 238 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | 239 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 240 IEEE80211_VHT_CAP_HTC_VHT | 241 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | 242 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | 243 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | 244 0; 245 246 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | 247 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | 248 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | 249 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | 250 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | 251 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | 252 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | 253 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; 254 255 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); 256 vht_cap->vht_mcs.rx_highest = 257 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); 258 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); 259 vht_cap->vht_mcs.tx_highest = 260 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); 261 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) { 262 u16 mcs_map; 263 264 vht_cap->vht_supported = true; 265 vht_cap->cap = 266 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | 267 IEEE80211_VHT_CAP_SHORT_GI_80 | 268 IEEE80211_VHT_CAP_TXSTBC | 269 IEEE80211_VHT_CAP_RXSTBC_1 | 270 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | 271 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 272 IEEE80211_VHT_CAP_HTC_VHT | 273 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | 274 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | 275 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | 276 0; 277 278 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | 279 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | 280 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | 281 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | 282 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | 283 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | 284 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | 285 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; 286 287 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); 288 vht_cap->vht_mcs.rx_highest = 289 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); 290 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); 291 vht_cap->vht_mcs.tx_highest = 292 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); 293 } 294 } 295 296 static void _rtl_init_mac80211(struct ieee80211_hw *hw) 297 { 298 struct rtl_priv *rtlpriv = rtl_priv(hw); 299 struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 300 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 301 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 302 struct ieee80211_supported_band *sband; 303 304 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && 305 rtlhal->bandset == BAND_ON_BOTH) { 306 /* 1: 2.4 G bands */ 307 /* <1> use mac->bands as mem for hw->wiphy->bands */ 308 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); 309 310 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] 311 * to default value(1T1R) */ 312 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz, 313 sizeof(struct ieee80211_supported_band)); 314 315 /* <3> init ht cap base on ant_num */ 316 _rtl_init_hw_ht_capab(hw, &sband->ht_cap); 317 318 /* <4> set mac->sband to wiphy->sband */ 319 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; 320 321 /* 2: 5 G bands */ 322 /* <1> use mac->bands as mem for hw->wiphy->bands */ 323 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); 324 325 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] 326 * to default value(1T1R) */ 327 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz, 328 sizeof(struct ieee80211_supported_band)); 329 330 /* <3> init ht cap base on ant_num */ 331 _rtl_init_hw_ht_capab(hw, &sband->ht_cap); 332 333 _rtl_init_hw_vht_capab(hw, &sband->vht_cap); 334 /* <4> set mac->sband to wiphy->sband */ 335 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; 336 } else { 337 if (rtlhal->current_bandtype == BAND_ON_2_4G) { 338 /* <1> use mac->bands as mem for hw->wiphy->bands */ 339 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); 340 341 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] 342 * to default value(1T1R) */ 343 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), 344 &rtl_band_2ghz, 345 sizeof(struct ieee80211_supported_band)); 346 347 /* <3> init ht cap base on ant_num */ 348 _rtl_init_hw_ht_capab(hw, &sband->ht_cap); 349 350 /* <4> set mac->sband to wiphy->sband */ 351 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; 352 } else if (rtlhal->current_bandtype == BAND_ON_5G) { 353 /* <1> use mac->bands as mem for hw->wiphy->bands */ 354 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); 355 356 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] 357 * to default value(1T1R) */ 358 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), 359 &rtl_band_5ghz, 360 sizeof(struct ieee80211_supported_band)); 361 362 /* <3> init ht cap base on ant_num */ 363 _rtl_init_hw_ht_capab(hw, &sband->ht_cap); 364 365 _rtl_init_hw_vht_capab(hw, &sband->vht_cap); 366 /* <4> set mac->sband to wiphy->sband */ 367 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; 368 } else { 369 pr_err("Err BAND %d\n", 370 rtlhal->current_bandtype); 371 } 372 } 373 /* <5> set hw caps */ 374 ieee80211_hw_set(hw, SIGNAL_DBM); 375 ieee80211_hw_set(hw, RX_INCLUDES_FCS); 376 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 377 ieee80211_hw_set(hw, MFP_CAPABLE); 378 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 379 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 380 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 381 382 /* swlps or hwlps has been set in diff chip in init_sw_vars */ 383 if (rtlpriv->psc.swctrl_lps) { 384 ieee80211_hw_set(hw, SUPPORTS_PS); 385 ieee80211_hw_set(hw, PS_NULLFUNC_STACK); 386 } 387 if (rtlpriv->psc.fwctrl_lps) { 388 ieee80211_hw_set(hw, SUPPORTS_PS); 389 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 390 } 391 hw->wiphy->interface_modes = 392 BIT(NL80211_IFTYPE_AP) | 393 BIT(NL80211_IFTYPE_STATION) | 394 BIT(NL80211_IFTYPE_ADHOC) | 395 BIT(NL80211_IFTYPE_MESH_POINT) | 396 BIT(NL80211_IFTYPE_P2P_CLIENT) | 397 BIT(NL80211_IFTYPE_P2P_GO); 398 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 399 400 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 401 402 hw->wiphy->rts_threshold = 2347; 403 404 hw->queues = AC_MAX; 405 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; 406 407 /* TODO: Correct this value for our hw */ 408 hw->max_listen_interval = MAX_LISTEN_INTERVAL; 409 hw->max_rate_tries = MAX_RATE_TRIES; 410 /* hw->max_rates = 1; */ 411 hw->sta_data_size = sizeof(struct rtl_sta_info); 412 413 /* wowlan is not supported by kernel if CONFIG_PM is not defined */ 414 #ifdef CONFIG_PM 415 if (rtlpriv->psc.wo_wlan_mode) { 416 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET) 417 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT; 418 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) { 419 rtlpriv->wowlan.n_patterns = 420 MAX_SUPPORT_WOL_PATTERN_NUM; 421 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE; 422 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE; 423 } 424 hw->wiphy->wowlan = &rtlpriv->wowlan; 425 } 426 #endif 427 428 /* <6> mac address */ 429 if (is_valid_ether_addr(rtlefuse->dev_addr)) { 430 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); 431 } else { 432 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; 433 434 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); 435 SET_IEEE80211_PERM_ADDR(hw, rtlmac1); 436 } 437 } 438 439 static void rtl_watchdog_wq_callback(struct work_struct *work); 440 static void rtl_fwevt_wq_callback(struct work_struct *work); 441 static void rtl_c2hcmd_wq_callback(struct work_struct *work); 442 443 static int _rtl_init_deferred_work(struct ieee80211_hw *hw) 444 { 445 struct rtl_priv *rtlpriv = rtl_priv(hw); 446 struct workqueue_struct *wq; 447 448 wq = alloc_workqueue("%s", WQ_UNBOUND, 0, rtlpriv->cfg->name); 449 if (!wq) 450 return -ENOMEM; 451 452 /* <1> timer */ 453 timer_setup(&rtlpriv->works.watchdog_timer, 454 rtl_watch_dog_timer_callback, 0); 455 456 /* <2> work queue */ 457 rtlpriv->works.hw = hw; 458 rtlpriv->works.rtl_wq = wq; 459 460 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, 461 rtl_watchdog_wq_callback); 462 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, 463 rtl_ips_nic_off_wq_callback); 464 INIT_DELAYED_WORK(&rtlpriv->works.ps_work, rtl_swlps_wq_callback); 465 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, 466 rtl_swlps_rfon_wq_callback); 467 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, rtl_fwevt_wq_callback); 468 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq, rtl_c2hcmd_wq_callback); 469 return 0; 470 } 471 472 void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq) 473 { 474 struct rtl_priv *rtlpriv = rtl_priv(hw); 475 476 timer_delete_sync(&rtlpriv->works.watchdog_timer); 477 478 cancel_delayed_work_sync(&rtlpriv->works.watchdog_wq); 479 if (ips_wq) 480 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); 481 else 482 cancel_delayed_work_sync(&rtlpriv->works.ips_nic_off_wq); 483 cancel_delayed_work_sync(&rtlpriv->works.ps_work); 484 cancel_delayed_work_sync(&rtlpriv->works.ps_rfon_wq); 485 cancel_delayed_work_sync(&rtlpriv->works.fwevt_wq); 486 cancel_delayed_work_sync(&rtlpriv->works.c2hcmd_wq); 487 } 488 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work); 489 490 void rtl_init_rfkill(struct ieee80211_hw *hw) 491 { 492 struct rtl_priv *rtlpriv = rtl_priv(hw); 493 494 bool radio_state; 495 bool blocked; 496 u8 valid = 0; 497 498 /*set init state to on */ 499 rtlpriv->rfkill.rfkill_state = true; 500 wiphy_rfkill_set_hw_state(hw->wiphy, 0); 501 502 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); 503 504 if (valid) { 505 pr_info("rtlwifi: wireless switch is %s\n", 506 rtlpriv->rfkill.rfkill_state ? "on" : "off"); 507 508 rtlpriv->rfkill.rfkill_state = radio_state; 509 510 blocked = rtlpriv->rfkill.rfkill_state != 1; 511 wiphy_rfkill_set_hw_state(hw->wiphy, blocked); 512 } 513 514 wiphy_rfkill_start_polling(hw->wiphy); 515 } 516 EXPORT_SYMBOL(rtl_init_rfkill); 517 518 void rtl_deinit_rfkill(struct ieee80211_hw *hw) 519 { 520 wiphy_rfkill_stop_polling(hw->wiphy); 521 } 522 EXPORT_SYMBOL_GPL(rtl_deinit_rfkill); 523 524 int rtl_init_core(struct ieee80211_hw *hw) 525 { 526 struct rtl_priv *rtlpriv = rtl_priv(hw); 527 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 528 529 /* <1> init mac80211 */ 530 _rtl_init_mac80211(hw); 531 rtlmac->hw = hw; 532 533 /* <2> rate control register */ 534 hw->rate_control_algorithm = "rtl_rc"; 535 536 /* 537 * <3> init CRDA must come after init 538 * mac80211 hw in _rtl_init_mac80211. 539 */ 540 if (rtl_regd_init(hw, rtl_reg_notifier)) { 541 pr_err("REGD init failed\n"); 542 return 1; 543 } 544 545 /* <4> locks */ 546 mutex_init(&rtlpriv->locks.conf_mutex); 547 mutex_init(&rtlpriv->locks.ips_mutex); 548 mutex_init(&rtlpriv->locks.lps_mutex); 549 spin_lock_init(&rtlpriv->locks.irq_th_lock); 550 spin_lock_init(&rtlpriv->locks.h2c_lock); 551 spin_lock_init(&rtlpriv->locks.rf_ps_lock); 552 spin_lock_init(&rtlpriv->locks.rf_lock); 553 spin_lock_init(&rtlpriv->locks.waitq_lock); 554 spin_lock_init(&rtlpriv->locks.entry_list_lock); 555 spin_lock_init(&rtlpriv->locks.scan_list_lock); 556 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); 557 spin_lock_init(&rtlpriv->locks.fw_ps_lock); 558 spin_lock_init(&rtlpriv->locks.iqk_lock); 559 /* <5> init list */ 560 INIT_LIST_HEAD(&rtlpriv->entry_list); 561 INIT_LIST_HEAD(&rtlpriv->scan_list.list); 562 skb_queue_head_init(&rtlpriv->tx_report.queue); 563 skb_queue_head_init(&rtlpriv->c2hcmd_queue); 564 565 rtlmac->link_state = MAC80211_NOLINK; 566 567 /* <6> init deferred work */ 568 return _rtl_init_deferred_work(hw); 569 } 570 EXPORT_SYMBOL_GPL(rtl_init_core); 571 572 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw); 573 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw, 574 bool timeout); 575 576 void rtl_deinit_core(struct ieee80211_hw *hw) 577 { 578 struct rtl_priv *rtlpriv = rtl_priv(hw); 579 580 rtl_c2hcmd_launcher(hw, 0); 581 rtl_free_entries_from_scan_list(hw); 582 rtl_free_entries_from_ack_queue(hw, false); 583 if (rtlpriv->works.rtl_wq) { 584 destroy_workqueue(rtlpriv->works.rtl_wq); 585 rtlpriv->works.rtl_wq = NULL; 586 } 587 } 588 EXPORT_SYMBOL_GPL(rtl_deinit_core); 589 590 void rtl_init_rx_config(struct ieee80211_hw *hw) 591 { 592 struct rtl_priv *rtlpriv = rtl_priv(hw); 593 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 594 595 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); 596 } 597 EXPORT_SYMBOL_GPL(rtl_init_rx_config); 598 599 /********************************************************* 600 * 601 * tx information functions 602 * 603 *********************************************************/ 604 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, 605 struct rtl_tcb_desc *tcb_desc, 606 struct ieee80211_tx_info *info) 607 { 608 struct rtl_priv *rtlpriv = rtl_priv(hw); 609 u8 rate_flag = info->control.rates[0].flags; 610 611 tcb_desc->use_shortpreamble = false; 612 613 /* 1M can only use Long Preamble. 11B spec */ 614 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) 615 return; 616 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) 617 tcb_desc->use_shortpreamble = true; 618 619 return; 620 } 621 622 static void _rtl_query_shortgi(struct ieee80211_hw *hw, 623 struct ieee80211_sta *sta, 624 struct rtl_tcb_desc *tcb_desc, 625 struct ieee80211_tx_info *info) 626 { 627 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 628 u8 rate_flag = info->control.rates[0].flags; 629 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; 630 u8 sgi_80 = 0, bw_80 = 0; 631 632 tcb_desc->use_shortgi = false; 633 634 if (sta == NULL) 635 return; 636 637 sgi_40 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_40; 638 sgi_20 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SGI_20; 639 sgi_80 = sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80; 640 641 if (!sta->deflink.ht_cap.ht_supported && 642 !sta->deflink.vht_cap.vht_supported) 643 return; 644 645 if (!sgi_40 && !sgi_20) 646 return; 647 648 if (mac->opmode == NL80211_IFTYPE_STATION) { 649 bw_40 = mac->bw_40; 650 bw_80 = mac->bw_80; 651 } else if (mac->opmode == NL80211_IFTYPE_AP || 652 mac->opmode == NL80211_IFTYPE_ADHOC || 653 mac->opmode == NL80211_IFTYPE_MESH_POINT) { 654 bw_40 = sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; 655 bw_80 = sta->deflink.vht_cap.vht_supported; 656 } 657 658 if (bw_80) { 659 if (sgi_80) 660 tcb_desc->use_shortgi = true; 661 else 662 tcb_desc->use_shortgi = false; 663 } else { 664 if (bw_40 && sgi_40) 665 tcb_desc->use_shortgi = true; 666 else if (!bw_40 && sgi_20) 667 tcb_desc->use_shortgi = true; 668 } 669 670 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) 671 tcb_desc->use_shortgi = false; 672 } 673 674 static void _rtl_query_protection_mode(struct ieee80211_hw *hw, 675 struct rtl_tcb_desc *tcb_desc, 676 struct ieee80211_tx_info *info) 677 { 678 struct rtl_priv *rtlpriv = rtl_priv(hw); 679 u8 rate_flag = info->control.rates[0].flags; 680 681 /* Common Settings */ 682 tcb_desc->rts_stbc = false; 683 tcb_desc->cts_enable = false; 684 tcb_desc->rts_sc = 0; 685 tcb_desc->rts_bw = false; 686 tcb_desc->rts_use_shortpreamble = false; 687 tcb_desc->rts_use_shortgi = false; 688 689 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { 690 /* Use CTS-to-SELF in protection mode. */ 691 tcb_desc->rts_enable = true; 692 tcb_desc->cts_enable = true; 693 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; 694 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { 695 /* Use RTS-CTS in protection mode. */ 696 tcb_desc->rts_enable = true; 697 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; 698 } 699 } 700 701 u8 rtl_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index, 702 enum wireless_mode wirelessmode) 703 { 704 struct rtl_priv *rtlpriv = rtl_priv(hw); 705 struct rtl_phy *rtlphy = &rtlpriv->phy; 706 u8 ret = 0; 707 708 switch (rate_index) { 709 case RATR_INX_WIRELESS_NGB: 710 if (rtlphy->rf_type == RF_1T1R) 711 ret = RATEID_IDX_BGN_40M_1SS; 712 else 713 ret = RATEID_IDX_BGN_40M_2SS; 714 ; break; 715 case RATR_INX_WIRELESS_N: 716 case RATR_INX_WIRELESS_NG: 717 if (rtlphy->rf_type == RF_1T1R) 718 ret = RATEID_IDX_GN_N1SS; 719 else 720 ret = RATEID_IDX_GN_N2SS; 721 ; break; 722 case RATR_INX_WIRELESS_NB: 723 if (rtlphy->rf_type == RF_1T1R) 724 ret = RATEID_IDX_BGN_20M_1SS_BN; 725 else 726 ret = RATEID_IDX_BGN_20M_2SS_BN; 727 ; break; 728 case RATR_INX_WIRELESS_GB: 729 ret = RATEID_IDX_BG; 730 break; 731 case RATR_INX_WIRELESS_G: 732 ret = RATEID_IDX_G; 733 break; 734 case RATR_INX_WIRELESS_B: 735 ret = RATEID_IDX_B; 736 break; 737 case RATR_INX_WIRELESS_MC: 738 if (wirelessmode == WIRELESS_MODE_B || 739 wirelessmode == WIRELESS_MODE_G || 740 wirelessmode == WIRELESS_MODE_N_24G || 741 wirelessmode == WIRELESS_MODE_AC_24G) 742 ret = RATEID_IDX_BG; 743 else 744 ret = RATEID_IDX_G; 745 break; 746 case RATR_INX_WIRELESS_AC_5N: 747 if (rtlphy->rf_type == RF_1T1R) 748 ret = RATEID_IDX_VHT_1SS; 749 else 750 ret = RATEID_IDX_VHT_2SS; 751 break; 752 case RATR_INX_WIRELESS_AC_24N: 753 if (rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_80) { 754 if (rtlphy->rf_type == RF_1T1R) 755 ret = RATEID_IDX_VHT_1SS; 756 else 757 ret = RATEID_IDX_VHT_2SS; 758 } else { 759 if (rtlphy->rf_type == RF_1T1R) 760 ret = RATEID_IDX_MIX1; 761 else 762 ret = RATEID_IDX_MIX2; 763 } 764 break; 765 default: 766 ret = RATEID_IDX_BGN_40M_2SS; 767 break; 768 } 769 return ret; 770 } 771 EXPORT_SYMBOL(rtl_mrate_idx_to_arfr_id); 772 773 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, 774 struct ieee80211_sta *sta, 775 struct rtl_tcb_desc *tcb_desc) 776 { 777 #define SET_RATE_ID(rate_id) \ 778 ({typeof(rate_id) _id = rate_id; \ 779 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \ 780 rtl_mrate_idx_to_arfr_id(hw, _id, \ 781 (sta_entry ? sta_entry->wireless_mode : \ 782 WIRELESS_MODE_G)) : \ 783 _id); }) 784 785 struct rtl_priv *rtlpriv = rtl_priv(hw); 786 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 787 struct rtl_sta_info *sta_entry = NULL; 788 u8 ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC); 789 790 if (sta) { 791 sta_entry = (struct rtl_sta_info *) sta->drv_priv; 792 ratr_index = sta_entry->ratr_index; 793 } 794 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { 795 if (mac->opmode == NL80211_IFTYPE_STATION) { 796 tcb_desc->ratr_index = 0; 797 } else if (mac->opmode == NL80211_IFTYPE_ADHOC || 798 mac->opmode == NL80211_IFTYPE_MESH_POINT) { 799 if (tcb_desc->multicast || tcb_desc->broadcast) { 800 tcb_desc->hw_rate = 801 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; 802 tcb_desc->use_driver_rate = 1; 803 tcb_desc->ratr_index = 804 SET_RATE_ID(RATR_INX_WIRELESS_MC); 805 } else { 806 tcb_desc->ratr_index = ratr_index; 807 } 808 } else if (mac->opmode == NL80211_IFTYPE_AP) { 809 tcb_desc->ratr_index = ratr_index; 810 } 811 } 812 813 if (rtlpriv->dm.useramask) { 814 tcb_desc->ratr_index = ratr_index; 815 /* TODO we will differentiate adhoc and station future */ 816 if (mac->opmode == NL80211_IFTYPE_STATION || 817 mac->opmode == NL80211_IFTYPE_MESH_POINT) { 818 tcb_desc->mac_id = 0; 819 820 if (sta && 821 (rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID)) 822 ; /* use sta_entry->ratr_index */ 823 else if (mac->mode == WIRELESS_MODE_AC_5G) 824 tcb_desc->ratr_index = 825 SET_RATE_ID(RATR_INX_WIRELESS_AC_5N); 826 else if (mac->mode == WIRELESS_MODE_AC_24G) 827 tcb_desc->ratr_index = 828 SET_RATE_ID(RATR_INX_WIRELESS_AC_24N); 829 else if (mac->mode == WIRELESS_MODE_N_24G) 830 tcb_desc->ratr_index = 831 SET_RATE_ID(RATR_INX_WIRELESS_NGB); 832 else if (mac->mode == WIRELESS_MODE_N_5G) 833 tcb_desc->ratr_index = 834 SET_RATE_ID(RATR_INX_WIRELESS_NG); 835 else if (mac->mode & WIRELESS_MODE_G) 836 tcb_desc->ratr_index = 837 SET_RATE_ID(RATR_INX_WIRELESS_GB); 838 else if (mac->mode & WIRELESS_MODE_B) 839 tcb_desc->ratr_index = 840 SET_RATE_ID(RATR_INX_WIRELESS_B); 841 else if (mac->mode & WIRELESS_MODE_A) 842 tcb_desc->ratr_index = 843 SET_RATE_ID(RATR_INX_WIRELESS_G); 844 845 } else if (mac->opmode == NL80211_IFTYPE_AP || 846 mac->opmode == NL80211_IFTYPE_ADHOC) { 847 if (NULL != sta) { 848 if (sta->aid > 0) 849 tcb_desc->mac_id = sta->aid + 1; 850 else 851 tcb_desc->mac_id = 1; 852 } else { 853 tcb_desc->mac_id = 0; 854 } 855 } 856 } 857 #undef SET_RATE_ID 858 } 859 860 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, 861 struct ieee80211_sta *sta, 862 struct rtl_tcb_desc *tcb_desc) 863 { 864 struct rtl_priv *rtlpriv = rtl_priv(hw); 865 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 866 867 tcb_desc->packet_bw = false; 868 if (!sta) 869 return; 870 if (mac->opmode == NL80211_IFTYPE_AP || 871 mac->opmode == NL80211_IFTYPE_ADHOC || 872 mac->opmode == NL80211_IFTYPE_MESH_POINT) { 873 if (!(sta->deflink.ht_cap.ht_supported) || 874 !(sta->deflink.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) 875 return; 876 } else if (mac->opmode == NL80211_IFTYPE_STATION) { 877 if (!mac->bw_40 || !(sta->deflink.ht_cap.ht_supported)) 878 return; 879 } 880 if (tcb_desc->multicast || tcb_desc->broadcast) 881 return; 882 883 /*use legency rate, shall use 20MHz */ 884 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) 885 return; 886 887 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40; 888 889 if (rtlpriv->cfg->spec_ver & RTL_SPEC_SUPPORT_VHT) { 890 if (mac->opmode == NL80211_IFTYPE_AP || 891 mac->opmode == NL80211_IFTYPE_ADHOC || 892 mac->opmode == NL80211_IFTYPE_MESH_POINT) { 893 if (!(sta->deflink.vht_cap.vht_supported)) 894 return; 895 } else if (mac->opmode == NL80211_IFTYPE_STATION) { 896 if (!mac->bw_80 || 897 !(sta->deflink.vht_cap.vht_supported)) 898 return; 899 } 900 if (tcb_desc->hw_rate <= 901 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]) 902 return; 903 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80; 904 } 905 } 906 907 static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw, 908 struct ieee80211_sta *sta) 909 { 910 struct rtl_priv *rtlpriv = rtl_priv(hw); 911 struct rtl_phy *rtlphy = &(rtlpriv->phy); 912 u8 hw_rate; 913 u16 tx_mcs_map = le16_to_cpu(sta->deflink.vht_cap.vht_mcs.tx_mcs_map); 914 915 if ((get_rf_type(rtlphy) == RF_2T2R) && 916 (tx_mcs_map & 0x000c) != 0x000c) { 917 if ((tx_mcs_map & 0x000c) >> 2 == 918 IEEE80211_VHT_MCS_SUPPORT_0_7) 919 hw_rate = 920 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7]; 921 else if ((tx_mcs_map & 0x000c) >> 2 == 922 IEEE80211_VHT_MCS_SUPPORT_0_8) 923 hw_rate = 924 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS8]; 925 else 926 hw_rate = 927 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; 928 } else { 929 if ((tx_mcs_map & 0x0003) == 930 IEEE80211_VHT_MCS_SUPPORT_0_7) 931 hw_rate = 932 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7]; 933 else if ((tx_mcs_map & 0x0003) == 934 IEEE80211_VHT_MCS_SUPPORT_0_8) 935 hw_rate = 936 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS8]; 937 else 938 hw_rate = 939 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; 940 } 941 942 return hw_rate; 943 } 944 945 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw, 946 struct ieee80211_sta *sta) 947 { 948 struct rtl_priv *rtlpriv = rtl_priv(hw); 949 struct rtl_phy *rtlphy = &rtlpriv->phy; 950 u8 hw_rate; 951 952 if (get_rf_type(rtlphy) == RF_2T2R && 953 sta->deflink.ht_cap.mcs.rx_mask[1] != 0) 954 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; 955 else 956 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; 957 958 return hw_rate; 959 } 960 961 /* mac80211's rate_idx is like this: 962 * 963 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ 964 * 965 * B/G rate: 966 * (rx_status->flag & RX_FLAG_HT) = 0, 967 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11, 968 * 969 * N rate: 970 * (rx_status->flag & RX_FLAG_HT) = 1, 971 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 972 * 973 * 5G band:rx_status->band == NL80211_BAND_5GHZ 974 * A rate: 975 * (rx_status->flag & RX_FLAG_HT) = 0, 976 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7, 977 * 978 * N rate: 979 * (rx_status->flag & RX_FLAG_HT) = 1, 980 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 981 * 982 * VHT rates: 983 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9 984 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9 985 */ 986 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht, 987 u8 desc_rate) 988 { 989 int rate_idx; 990 991 if (isvht) { 992 switch (desc_rate) { 993 case DESC_RATEVHT1SS_MCS0: 994 rate_idx = 0; 995 break; 996 case DESC_RATEVHT1SS_MCS1: 997 rate_idx = 1; 998 break; 999 case DESC_RATEVHT1SS_MCS2: 1000 rate_idx = 2; 1001 break; 1002 case DESC_RATEVHT1SS_MCS3: 1003 rate_idx = 3; 1004 break; 1005 case DESC_RATEVHT1SS_MCS4: 1006 rate_idx = 4; 1007 break; 1008 case DESC_RATEVHT1SS_MCS5: 1009 rate_idx = 5; 1010 break; 1011 case DESC_RATEVHT1SS_MCS6: 1012 rate_idx = 6; 1013 break; 1014 case DESC_RATEVHT1SS_MCS7: 1015 rate_idx = 7; 1016 break; 1017 case DESC_RATEVHT1SS_MCS8: 1018 rate_idx = 8; 1019 break; 1020 case DESC_RATEVHT1SS_MCS9: 1021 rate_idx = 9; 1022 break; 1023 case DESC_RATEVHT2SS_MCS0: 1024 rate_idx = 0; 1025 break; 1026 case DESC_RATEVHT2SS_MCS1: 1027 rate_idx = 1; 1028 break; 1029 case DESC_RATEVHT2SS_MCS2: 1030 rate_idx = 2; 1031 break; 1032 case DESC_RATEVHT2SS_MCS3: 1033 rate_idx = 3; 1034 break; 1035 case DESC_RATEVHT2SS_MCS4: 1036 rate_idx = 4; 1037 break; 1038 case DESC_RATEVHT2SS_MCS5: 1039 rate_idx = 5; 1040 break; 1041 case DESC_RATEVHT2SS_MCS6: 1042 rate_idx = 6; 1043 break; 1044 case DESC_RATEVHT2SS_MCS7: 1045 rate_idx = 7; 1046 break; 1047 case DESC_RATEVHT2SS_MCS8: 1048 rate_idx = 8; 1049 break; 1050 case DESC_RATEVHT2SS_MCS9: 1051 rate_idx = 9; 1052 break; 1053 default: 1054 rate_idx = 0; 1055 break; 1056 } 1057 return rate_idx; 1058 } 1059 if (false == isht) { 1060 if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) { 1061 switch (desc_rate) { 1062 case DESC_RATE1M: 1063 rate_idx = 0; 1064 break; 1065 case DESC_RATE2M: 1066 rate_idx = 1; 1067 break; 1068 case DESC_RATE5_5M: 1069 rate_idx = 2; 1070 break; 1071 case DESC_RATE11M: 1072 rate_idx = 3; 1073 break; 1074 case DESC_RATE6M: 1075 rate_idx = 4; 1076 break; 1077 case DESC_RATE9M: 1078 rate_idx = 5; 1079 break; 1080 case DESC_RATE12M: 1081 rate_idx = 6; 1082 break; 1083 case DESC_RATE18M: 1084 rate_idx = 7; 1085 break; 1086 case DESC_RATE24M: 1087 rate_idx = 8; 1088 break; 1089 case DESC_RATE36M: 1090 rate_idx = 9; 1091 break; 1092 case DESC_RATE48M: 1093 rate_idx = 10; 1094 break; 1095 case DESC_RATE54M: 1096 rate_idx = 11; 1097 break; 1098 default: 1099 rate_idx = 0; 1100 break; 1101 } 1102 } else { 1103 switch (desc_rate) { 1104 case DESC_RATE6M: 1105 rate_idx = 0; 1106 break; 1107 case DESC_RATE9M: 1108 rate_idx = 1; 1109 break; 1110 case DESC_RATE12M: 1111 rate_idx = 2; 1112 break; 1113 case DESC_RATE18M: 1114 rate_idx = 3; 1115 break; 1116 case DESC_RATE24M: 1117 rate_idx = 4; 1118 break; 1119 case DESC_RATE36M: 1120 rate_idx = 5; 1121 break; 1122 case DESC_RATE48M: 1123 rate_idx = 6; 1124 break; 1125 case DESC_RATE54M: 1126 rate_idx = 7; 1127 break; 1128 default: 1129 rate_idx = 0; 1130 break; 1131 } 1132 } 1133 } else { 1134 switch (desc_rate) { 1135 case DESC_RATEMCS0: 1136 rate_idx = 0; 1137 break; 1138 case DESC_RATEMCS1: 1139 rate_idx = 1; 1140 break; 1141 case DESC_RATEMCS2: 1142 rate_idx = 2; 1143 break; 1144 case DESC_RATEMCS3: 1145 rate_idx = 3; 1146 break; 1147 case DESC_RATEMCS4: 1148 rate_idx = 4; 1149 break; 1150 case DESC_RATEMCS5: 1151 rate_idx = 5; 1152 break; 1153 case DESC_RATEMCS6: 1154 rate_idx = 6; 1155 break; 1156 case DESC_RATEMCS7: 1157 rate_idx = 7; 1158 break; 1159 case DESC_RATEMCS8: 1160 rate_idx = 8; 1161 break; 1162 case DESC_RATEMCS9: 1163 rate_idx = 9; 1164 break; 1165 case DESC_RATEMCS10: 1166 rate_idx = 10; 1167 break; 1168 case DESC_RATEMCS11: 1169 rate_idx = 11; 1170 break; 1171 case DESC_RATEMCS12: 1172 rate_idx = 12; 1173 break; 1174 case DESC_RATEMCS13: 1175 rate_idx = 13; 1176 break; 1177 case DESC_RATEMCS14: 1178 rate_idx = 14; 1179 break; 1180 case DESC_RATEMCS15: 1181 rate_idx = 15; 1182 break; 1183 default: 1184 rate_idx = 0; 1185 break; 1186 } 1187 } 1188 return rate_idx; 1189 } 1190 EXPORT_SYMBOL(rtlwifi_rate_mapping); 1191 1192 static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw, 1193 struct ieee80211_tx_info *info) 1194 { 1195 struct rtl_priv *rtlpriv = rtl_priv(hw); 1196 struct ieee80211_tx_rate *r = &info->status.rates[0]; 1197 struct ieee80211_rate *txrate; 1198 u8 hw_value = 0x0; 1199 1200 if (r->flags & IEEE80211_TX_RC_MCS) { 1201 /* HT MCS0-15 */ 1202 hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 + 1203 r->idx; 1204 } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) { 1205 /* VHT MCS0-9, NSS */ 1206 if (ieee80211_rate_get_vht_nss(r) == 2) 1207 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; 1208 else 1209 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; 1210 1211 hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r); 1212 } else { 1213 /* legacy */ 1214 txrate = ieee80211_get_tx_rate(hw, info); 1215 1216 if (txrate) 1217 hw_value = txrate->hw_value; 1218 } 1219 1220 /* check 5G band */ 1221 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G && 1222 hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M]) 1223 hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M]; 1224 1225 return hw_value; 1226 } 1227 1228 void rtl_get_tcb_desc(struct ieee80211_hw *hw, 1229 struct ieee80211_tx_info *info, 1230 struct ieee80211_sta *sta, 1231 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) 1232 { 1233 #define SET_RATE_ID(rate_id) \ 1234 ({typeof(rate_id) _id = rate_id; \ 1235 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \ 1236 rtl_mrate_idx_to_arfr_id(hw, _id, \ 1237 (sta_entry ? sta_entry->wireless_mode : \ 1238 WIRELESS_MODE_G)) : \ 1239 _id); }) 1240 1241 struct rtl_priv *rtlpriv = rtl_priv(hw); 1242 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 1243 struct ieee80211_hdr *hdr = rtl_get_hdr(skb); 1244 struct rtl_sta_info *sta_entry = 1245 (sta ? (struct rtl_sta_info *)sta->drv_priv : NULL); 1246 1247 __le16 fc = rtl_get_fc(skb); 1248 1249 tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info); 1250 1251 if (rtl_is_tx_report_skb(hw, skb)) 1252 tcb_desc->use_spe_rpt = 1; 1253 1254 if (ieee80211_is_data(fc)) { 1255 /* 1256 *we set data rate INX 0 1257 *in rtl_rc.c if skb is special data or 1258 *mgt which need low data rate. 1259 */ 1260 1261 /* 1262 *So tcb_desc->hw_rate is just used for 1263 *special data and mgt frames 1264 */ 1265 if (info->control.rates[0].idx == 0 || 1266 ieee80211_is_nullfunc(fc)) { 1267 tcb_desc->use_driver_rate = true; 1268 tcb_desc->ratr_index = 1269 SET_RATE_ID(RATR_INX_WIRELESS_MC); 1270 1271 tcb_desc->disable_ratefallback = 1; 1272 } else { 1273 /* 1274 *because hw will never use hw_rate 1275 *when tcb_desc->use_driver_rate = false 1276 *so we never set highest N rate here, 1277 *and N rate will all be controlled by FW 1278 *when tcb_desc->use_driver_rate = false 1279 */ 1280 if (sta && sta->deflink.vht_cap.vht_supported) { 1281 tcb_desc->hw_rate = 1282 _rtl_get_vht_highest_n_rate(hw, sta); 1283 } else { 1284 if (sta && sta->deflink.ht_cap.ht_supported) { 1285 tcb_desc->hw_rate = 1286 _rtl_get_highest_n_rate(hw, sta); 1287 } else { 1288 if (rtlmac->mode == WIRELESS_MODE_B) { 1289 tcb_desc->hw_rate = 1290 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; 1291 } else { 1292 tcb_desc->hw_rate = 1293 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; 1294 } 1295 } 1296 } 1297 } 1298 1299 if (is_multicast_ether_addr(hdr->addr1)) 1300 tcb_desc->multicast = 1; 1301 else if (is_broadcast_ether_addr(hdr->addr1)) 1302 tcb_desc->broadcast = 1; 1303 1304 _rtl_txrate_selectmode(hw, sta, tcb_desc); 1305 _rtl_query_bandwidth_mode(hw, sta, tcb_desc); 1306 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); 1307 _rtl_query_shortgi(hw, sta, tcb_desc, info); 1308 _rtl_query_protection_mode(hw, tcb_desc, info); 1309 } else { 1310 tcb_desc->use_driver_rate = true; 1311 tcb_desc->ratr_index = SET_RATE_ID(RATR_INX_WIRELESS_MC); 1312 tcb_desc->disable_ratefallback = 1; 1313 tcb_desc->mac_id = 0; 1314 tcb_desc->packet_bw = false; 1315 } 1316 #undef SET_RATE_ID 1317 } 1318 EXPORT_SYMBOL(rtl_get_tcb_desc); 1319 1320 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) 1321 { 1322 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1323 struct rtl_priv *rtlpriv = rtl_priv(hw); 1324 __le16 fc = rtl_get_fc(skb); 1325 1326 if (ieee80211_is_auth(fc)) { 1327 rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); 1328 1329 mac->link_state = MAC80211_LINKING; 1330 /* Dul mac */ 1331 rtlpriv->phy.need_iqk = true; 1332 1333 } 1334 1335 return true; 1336 } 1337 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc); 1338 1339 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa, 1340 u8 *bssid, u16 tid); 1341 1342 static void process_agg_start(struct ieee80211_hw *hw, 1343 struct ieee80211_hdr *hdr, u16 tid) 1344 { 1345 struct rtl_priv *rtlpriv = rtl_priv(hw); 1346 struct ieee80211_rx_status rx_status = { 0 }; 1347 struct sk_buff *skb_delba = NULL; 1348 1349 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); 1350 if (skb_delba) { 1351 rx_status.freq = hw->conf.chandef.chan->center_freq; 1352 rx_status.band = hw->conf.chandef.chan->band; 1353 rx_status.flag |= RX_FLAG_DECRYPTED; 1354 rx_status.flag |= RX_FLAG_MACTIME_START; 1355 rx_status.rate_idx = 0; 1356 rx_status.signal = 50 + 10; 1357 memcpy(IEEE80211_SKB_RXCB(skb_delba), 1358 &rx_status, sizeof(rx_status)); 1359 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, 1360 "fake del\n", 1361 skb_delba->data, 1362 skb_delba->len); 1363 ieee80211_rx_irqsafe(hw, skb_delba); 1364 } 1365 } 1366 1367 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) 1368 { 1369 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1370 struct ieee80211_hdr *hdr = rtl_get_hdr(skb); 1371 struct rtl_priv *rtlpriv = rtl_priv(hw); 1372 struct ieee80211_mgmt *mgmt; 1373 __le16 fc = rtl_get_fc(skb); 1374 1375 if (!ieee80211_is_action(fc)) 1376 return true; 1377 1378 mgmt = (void *)skb->data; 1379 if (skb->len < IEEE80211_MIN_ACTION_SIZE(action_code)) 1380 return true; 1381 1382 switch (mgmt->u.action.category) { 1383 case ACT_CAT_BA: 1384 switch (mgmt->u.action.action_code) { 1385 case ACT_ADDBAREQ: 1386 if (mac->act_scanning) 1387 return false; 1388 1389 rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, 1390 "%s ACT_ADDBAREQ From :%pM\n", 1391 is_tx ? "Tx" : "Rx", hdr->addr2); 1392 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", 1393 skb->data, skb->len); 1394 if (!is_tx) { 1395 struct ieee80211_sta *sta = NULL; 1396 struct rtl_sta_info *sta_entry = NULL; 1397 struct rtl_tid_data *tid_data; 1398 u16 capab = 0, tid = 0; 1399 1400 if (skb->len < IEEE80211_MIN_ACTION_SIZE(addba_req)) 1401 return true; 1402 1403 rcu_read_lock(); 1404 sta = rtl_find_sta(hw, hdr->addr3); 1405 if (sta == NULL) { 1406 rtl_dbg(rtlpriv, COMP_SEND | COMP_RECV, 1407 DBG_DMESG, "sta is NULL\n"); 1408 rcu_read_unlock(); 1409 return true; 1410 } 1411 1412 sta_entry = 1413 (struct rtl_sta_info *)sta->drv_priv; 1414 capab = 1415 le16_to_cpu(mgmt->u.action.addba_req.capab); 1416 tid = (capab & 1417 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; 1418 if (tid >= MAX_TID_COUNT) { 1419 rcu_read_unlock(); 1420 return true; 1421 } 1422 tid_data = &sta_entry->tids[tid]; 1423 if (tid_data->agg.rx_agg_state == 1424 RTL_RX_AGG_START) 1425 process_agg_start(hw, hdr, tid); 1426 rcu_read_unlock(); 1427 } 1428 break; 1429 case ACT_ADDBARSP: 1430 rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, 1431 "%s ACT_ADDBARSP From :%pM\n", 1432 is_tx ? "Tx" : "Rx", hdr->addr2); 1433 break; 1434 case ACT_DELBA: 1435 rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, 1436 "ACT_ADDBADEL From :%pM\n", hdr->addr2); 1437 break; 1438 } 1439 break; 1440 default: 1441 break; 1442 } 1443 1444 return true; 1445 } 1446 EXPORT_SYMBOL_GPL(rtl_action_proc); 1447 1448 static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc, 1449 int type) 1450 { 1451 struct ieee80211_hw *hw = rtlpriv->hw; 1452 1453 rtlpriv->ra.is_special_data = true; 1454 if (rtlpriv->cfg->ops->get_btc_status()) 1455 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify( 1456 rtlpriv, type); 1457 rtl_lps_leave(hw, false); 1458 ppsc->last_delaylps_stamp_jiffies = jiffies; 1459 } 1460 1461 static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw, 1462 struct sk_buff *skb, bool is_enc) 1463 { 1464 struct rtl_priv *rtlpriv = rtl_priv(hw); 1465 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); 1466 u8 encrypt_header_len = 0; 1467 u8 offset; 1468 1469 switch (rtlpriv->sec.pairwise_enc_algorithm) { 1470 case WEP40_ENCRYPTION: 1471 case WEP104_ENCRYPTION: 1472 encrypt_header_len = 4;/*WEP_IV_LEN*/ 1473 break; 1474 case TKIP_ENCRYPTION: 1475 encrypt_header_len = 8;/*TKIP_IV_LEN*/ 1476 break; 1477 case AESCCMP_ENCRYPTION: 1478 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/ 1479 break; 1480 default: 1481 break; 1482 } 1483 1484 offset = mac_hdr_len + SNAP_SIZE; 1485 if (is_enc) 1486 offset += encrypt_header_len; 1487 1488 return skb->data + offset; 1489 } 1490 1491 /*should call before software enc*/ 1492 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx, 1493 bool is_enc) 1494 { 1495 struct rtl_priv *rtlpriv = rtl_priv(hw); 1496 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 1497 __le16 fc = rtl_get_fc(skb); 1498 u16 ether_type; 1499 const u8 *ether_type_ptr; 1500 const struct iphdr *ip; 1501 1502 if (!ieee80211_is_data(fc)) 1503 goto end; 1504 1505 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc); 1506 ether_type = be16_to_cpup((__be16 *)ether_type_ptr); 1507 1508 if (ETH_P_IP == ether_type) { 1509 ip = (struct iphdr *)((u8 *)ether_type_ptr + 1510 PROTOC_TYPE_SIZE); 1511 if (IPPROTO_UDP == ip->protocol) { 1512 struct udphdr *udp = (struct udphdr *)((u8 *)ip + 1513 (ip->ihl << 2)); 1514 if (((((u8 *)udp)[1] == 68) && 1515 (((u8 *)udp)[3] == 67)) || 1516 ((((u8 *)udp)[1] == 67) && 1517 (((u8 *)udp)[3] == 68))) { 1518 /* 68 : UDP BOOTP client 1519 * 67 : UDP BOOTP server 1520 */ 1521 rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), 1522 DBG_DMESG, "dhcp %s !!\n", 1523 (is_tx) ? "Tx" : "Rx"); 1524 1525 if (is_tx) 1526 setup_special_tx(rtlpriv, ppsc, 1527 PACKET_DHCP); 1528 1529 return true; 1530 } 1531 } 1532 } else if (ETH_P_ARP == ether_type) { 1533 if (is_tx) 1534 setup_special_tx(rtlpriv, ppsc, PACKET_ARP); 1535 1536 return true; 1537 } else if (ETH_P_PAE == ether_type) { 1538 /* EAPOL is seens as in-4way */ 1539 rtlpriv->btcoexist.btc_info.in_4way = true; 1540 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies; 1541 1542 rtl_dbg(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, 1543 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx"); 1544 1545 if (is_tx) { 1546 rtlpriv->ra.is_special_data = true; 1547 rtl_lps_leave(hw, false); 1548 ppsc->last_delaylps_stamp_jiffies = jiffies; 1549 1550 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL); 1551 } 1552 1553 return true; 1554 } else if (ETH_P_IPV6 == ether_type) { 1555 /* TODO: Handle any IPv6 cases that need special handling. 1556 * For now, always return false 1557 */ 1558 goto end; 1559 } 1560 1561 end: 1562 rtlpriv->ra.is_special_data = false; 1563 return false; 1564 } 1565 EXPORT_SYMBOL_GPL(rtl_is_special_data); 1566 1567 void rtl_tx_ackqueue(struct ieee80211_hw *hw, struct sk_buff *skb) 1568 { 1569 struct rtl_priv *rtlpriv = rtl_priv(hw); 1570 struct rtl_tx_report *tx_report = &rtlpriv->tx_report; 1571 1572 __skb_queue_tail(&tx_report->queue, skb); 1573 } 1574 EXPORT_SYMBOL_GPL(rtl_tx_ackqueue); 1575 1576 static void rtl_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, 1577 bool ack) 1578 { 1579 struct rtl_priv *rtlpriv = rtl_priv(hw); 1580 struct ieee80211_tx_info *info; 1581 1582 info = IEEE80211_SKB_CB(skb); 1583 ieee80211_tx_info_clear_status(info); 1584 if (ack) { 1585 rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_LOUD, 1586 "tx report: ack\n"); 1587 info->flags |= IEEE80211_TX_STAT_ACK; 1588 } else { 1589 rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_LOUD, 1590 "tx report: not ack\n"); 1591 info->flags &= ~IEEE80211_TX_STAT_ACK; 1592 } 1593 ieee80211_tx_status_irqsafe(hw, skb); 1594 } 1595 1596 bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb) 1597 { 1598 u16 ether_type; 1599 const u8 *ether_type_ptr; 1600 __le16 fc = rtl_get_fc(skb); 1601 1602 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true); 1603 ether_type = be16_to_cpup((__be16 *)ether_type_ptr); 1604 1605 if (ether_type == ETH_P_PAE || ieee80211_is_nullfunc(fc)) 1606 return true; 1607 1608 return false; 1609 } 1610 1611 static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw, 1612 struct rtlwifi_tx_info *tx_info) 1613 { 1614 struct rtl_priv *rtlpriv = rtl_priv(hw); 1615 struct rtl_tx_report *tx_report = &rtlpriv->tx_report; 1616 u16 sn; 1617 1618 /* SW_DEFINE[11:8] are reserved (driver fills zeros) 1619 * SW_DEFINE[7:2] are used by driver 1620 * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros) 1621 */ 1622 sn = (atomic_inc_return(&tx_report->sn) & 0x003F) << 2; 1623 1624 tx_report->last_sent_sn = sn; 1625 tx_report->last_sent_time = jiffies; 1626 tx_info->sn = sn; 1627 tx_info->send_time = tx_report->last_sent_time; 1628 rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_DMESG, 1629 "Send TX-Report sn=0x%X\n", sn); 1630 1631 return sn; 1632 } 1633 1634 void rtl_set_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc, 1635 struct ieee80211_hw *hw, struct rtlwifi_tx_info *tx_info) 1636 { 1637 if (ptcb_desc->use_spe_rpt) { 1638 u16 sn = rtl_get_tx_report_sn(hw, tx_info); 1639 1640 SET_TX_DESC_SPE_RPT(pdesc, 1); 1641 SET_TX_DESC_SW_DEFINE(pdesc, sn); 1642 } 1643 } 1644 EXPORT_SYMBOL_GPL(rtl_set_tx_report); 1645 1646 void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len) 1647 { 1648 struct rtl_priv *rtlpriv = rtl_priv(hw); 1649 struct rtl_tx_report *tx_report = &rtlpriv->tx_report; 1650 struct rtlwifi_tx_info *tx_info; 1651 struct sk_buff_head *queue = &tx_report->queue; 1652 struct sk_buff *skb; 1653 u16 sn; 1654 u8 st, retry; 1655 1656 if (rtlpriv->cfg->spec_ver & RTL_SPEC_EXT_C2H) { 1657 sn = GET_TX_REPORT_SN_V2(tmp_buf); 1658 st = GET_TX_REPORT_ST_V2(tmp_buf); 1659 retry = GET_TX_REPORT_RETRY_V2(tmp_buf); 1660 } else { 1661 sn = GET_TX_REPORT_SN_V1(tmp_buf); 1662 st = GET_TX_REPORT_ST_V1(tmp_buf); 1663 retry = GET_TX_REPORT_RETRY_V1(tmp_buf); 1664 } 1665 1666 tx_report->last_recv_sn = sn; 1667 1668 skb_queue_walk(queue, skb) { 1669 tx_info = rtl_tx_skb_cb_info(skb); 1670 if (tx_info->sn == sn) { 1671 skb_unlink(skb, queue); 1672 rtl_tx_status(hw, skb, st == 0); 1673 break; 1674 } 1675 } 1676 rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_DMESG, 1677 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n", 1678 st, sn, retry); 1679 } 1680 EXPORT_SYMBOL_GPL(rtl_tx_report_handler); 1681 1682 bool rtl_check_tx_report_acked(struct ieee80211_hw *hw) 1683 { 1684 struct rtl_priv *rtlpriv = rtl_priv(hw); 1685 struct rtl_tx_report *tx_report = &rtlpriv->tx_report; 1686 1687 if (tx_report->last_sent_sn == tx_report->last_recv_sn) 1688 return true; 1689 1690 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) { 1691 rtl_dbg(rtlpriv, COMP_TX_REPORT, DBG_WARNING, 1692 "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n", 1693 tx_report->last_sent_sn, tx_report->last_recv_sn); 1694 return true; /* 3 sec. (timeout) seen as acked */ 1695 } 1696 1697 return false; 1698 } 1699 1700 void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms) 1701 { 1702 struct rtl_priv *rtlpriv = rtl_priv(hw); 1703 int i; 1704 1705 for (i = 0; i < wait_ms; i++) { 1706 if (rtl_check_tx_report_acked(hw)) 1707 break; 1708 usleep_range(1000, 2000); 1709 rtl_dbg(rtlpriv, COMP_SEC, DBG_DMESG, 1710 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms); 1711 } 1712 } 1713 1714 u32 rtl_get_hal_edca_param(struct ieee80211_hw *hw, 1715 struct ieee80211_vif *vif, 1716 enum wireless_mode wirelessmode, 1717 struct ieee80211_tx_queue_params *param) 1718 { 1719 u32 reg = 0; 1720 u8 sifstime = 10; 1721 u8 slottime = 20; 1722 1723 /* AIFS = AIFSN * slot time + SIFS */ 1724 switch (wirelessmode) { 1725 case WIRELESS_MODE_A: 1726 case WIRELESS_MODE_N_24G: 1727 case WIRELESS_MODE_N_5G: 1728 case WIRELESS_MODE_AC_5G: 1729 case WIRELESS_MODE_AC_24G: 1730 sifstime = 16; 1731 slottime = 9; 1732 break; 1733 case WIRELESS_MODE_G: 1734 slottime = (vif->bss_conf.use_short_slot ? 9 : 20); 1735 break; 1736 default: 1737 break; 1738 } 1739 1740 reg |= (param->txop & 0x7FF) << 16; 1741 reg |= (fls(param->cw_max) & 0xF) << 12; 1742 reg |= (fls(param->cw_min) & 0xF) << 8; 1743 reg |= (param->aifs & 0x0F) * slottime + sifstime; 1744 1745 return reg; 1746 } 1747 EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param); 1748 1749 /********************************************************* 1750 * 1751 * functions called by core.c 1752 * 1753 *********************************************************/ 1754 int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1755 struct ieee80211_sta *sta, u16 tid, u16 *ssn) 1756 { 1757 struct rtl_priv *rtlpriv = rtl_priv(hw); 1758 struct rtl_tid_data *tid_data; 1759 struct rtl_sta_info *sta_entry = NULL; 1760 1761 if (sta == NULL) 1762 return -EINVAL; 1763 1764 if (unlikely(tid >= MAX_TID_COUNT)) 1765 return -EINVAL; 1766 1767 sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1768 tid_data = &sta_entry->tids[tid]; 1769 1770 rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, 1771 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, 1772 *ssn); 1773 1774 tid_data->agg.agg_state = RTL_AGG_START; 1775 1776 return IEEE80211_AMPDU_TX_START_IMMEDIATE; 1777 } 1778 1779 int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1780 struct ieee80211_sta *sta, u16 tid) 1781 { 1782 struct rtl_priv *rtlpriv = rtl_priv(hw); 1783 struct rtl_sta_info *sta_entry = NULL; 1784 1785 if (sta == NULL) 1786 return -EINVAL; 1787 1788 rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, 1789 "on ra = %pM tid = %d\n", sta->addr, tid); 1790 1791 if (unlikely(tid >= MAX_TID_COUNT)) 1792 return -EINVAL; 1793 1794 sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1795 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; 1796 1797 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 1798 return 0; 1799 } 1800 1801 int rtl_rx_agg_start(struct ieee80211_hw *hw, 1802 struct ieee80211_sta *sta, u16 tid) 1803 { 1804 struct rtl_priv *rtlpriv = rtl_priv(hw); 1805 struct rtl_tid_data *tid_data; 1806 struct rtl_sta_info *sta_entry = NULL; 1807 u8 reject_agg; 1808 1809 if (sta == NULL) 1810 return -EINVAL; 1811 1812 if (unlikely(tid >= MAX_TID_COUNT)) 1813 return -EINVAL; 1814 1815 if (rtlpriv->cfg->ops->get_btc_status()) { 1816 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv, 1817 &reject_agg, 1818 NULL, NULL); 1819 if (reject_agg) 1820 return -EINVAL; 1821 } 1822 1823 sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1824 tid_data = &sta_entry->tids[tid]; 1825 1826 rtl_dbg(rtlpriv, COMP_RECV, DBG_DMESG, 1827 "on ra = %pM tid = %d\n", sta->addr, tid); 1828 1829 tid_data->agg.rx_agg_state = RTL_RX_AGG_START; 1830 return 0; 1831 } 1832 1833 int rtl_rx_agg_stop(struct ieee80211_hw *hw, 1834 struct ieee80211_sta *sta, u16 tid) 1835 { 1836 struct rtl_priv *rtlpriv = rtl_priv(hw); 1837 struct rtl_sta_info *sta_entry = NULL; 1838 1839 if (sta == NULL) 1840 return -EINVAL; 1841 1842 rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, 1843 "on ra = %pM tid = %d\n", sta->addr, tid); 1844 1845 if (unlikely(tid >= MAX_TID_COUNT)) 1846 return -EINVAL; 1847 1848 sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1849 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; 1850 1851 return 0; 1852 } 1853 1854 int rtl_tx_agg_oper(struct ieee80211_hw *hw, 1855 struct ieee80211_sta *sta, u16 tid) 1856 { 1857 struct rtl_priv *rtlpriv = rtl_priv(hw); 1858 struct rtl_sta_info *sta_entry = NULL; 1859 1860 if (sta == NULL) 1861 return -EINVAL; 1862 1863 rtl_dbg(rtlpriv, COMP_SEND, DBG_DMESG, 1864 "on ra = %pM tid = %d\n", sta->addr, tid); 1865 1866 if (unlikely(tid >= MAX_TID_COUNT)) 1867 return -EINVAL; 1868 1869 sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1870 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; 1871 1872 return 0; 1873 } 1874 1875 void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv) 1876 { 1877 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; 1878 u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0; 1879 1880 if (rtlpriv->cfg->ops->get_btc_status()) 1881 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg, 1882 &ctrl_agg_size, &agg_size); 1883 1884 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 1885 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d", 1886 reject_agg, ctrl_agg_size, agg_size); 1887 1888 rtlpriv->hw->max_rx_aggregation_subframes = 1889 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF_HT); 1890 } 1891 EXPORT_SYMBOL(rtl_rx_ampdu_apply); 1892 1893 /********************************************************* 1894 * 1895 * wq & timer callback functions 1896 * 1897 *********************************************************/ 1898 /* this function is used for roaming */ 1899 void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) 1900 { 1901 struct rtl_priv *rtlpriv = rtl_priv(hw); 1902 struct ieee80211_hdr *hdr = rtl_get_hdr(skb); 1903 1904 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) 1905 return; 1906 1907 if (rtlpriv->mac80211.link_state < MAC80211_LINKED) 1908 return; 1909 1910 /* check if this really is a beacon */ 1911 if (!ieee80211_is_beacon(hdr->frame_control) && 1912 !ieee80211_is_probe_resp(hdr->frame_control)) 1913 return; 1914 1915 /* min. beacon length + FCS_LEN */ 1916 if (skb->len <= 40 + FCS_LEN) 1917 return; 1918 1919 /* and only beacons from the associated BSSID, please */ 1920 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) 1921 return; 1922 1923 rtlpriv->link_info.bcn_rx_inperiod++; 1924 } 1925 EXPORT_SYMBOL_GPL(rtl_beacon_statistic); 1926 1927 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw) 1928 { 1929 struct rtl_priv *rtlpriv = rtl_priv(hw); 1930 struct rtl_bssid_entry *entry, *next; 1931 1932 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) { 1933 list_del(&entry->list); 1934 kfree(entry); 1935 rtlpriv->scan_list.num--; 1936 } 1937 } 1938 1939 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw *hw, 1940 bool chk_timeout) 1941 { 1942 struct rtl_priv *rtlpriv = rtl_priv(hw); 1943 struct rtl_tx_report *tx_report = &rtlpriv->tx_report; 1944 struct sk_buff_head *queue = &tx_report->queue; 1945 struct sk_buff *skb, *tmp; 1946 struct rtlwifi_tx_info *tx_info; 1947 1948 skb_queue_walk_safe(queue, skb, tmp) { 1949 tx_info = rtl_tx_skb_cb_info(skb); 1950 if (chk_timeout && 1951 time_after(tx_info->send_time + HZ, jiffies)) 1952 continue; 1953 skb_unlink(skb, queue); 1954 rtl_tx_status(hw, skb, false); 1955 } 1956 } 1957 1958 void rtl_scan_list_expire(struct ieee80211_hw *hw) 1959 { 1960 struct rtl_priv *rtlpriv = rtl_priv(hw); 1961 struct rtl_bssid_entry *entry, *next; 1962 unsigned long flags; 1963 1964 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags); 1965 1966 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) { 1967 /* 180 seconds */ 1968 if (jiffies_to_msecs(jiffies - entry->age) < 180000) 1969 continue; 1970 1971 list_del(&entry->list); 1972 rtlpriv->scan_list.num--; 1973 1974 rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 1975 "BSSID=%pM is expire in scan list (total=%d)\n", 1976 entry->bssid, rtlpriv->scan_list.num); 1977 kfree(entry); 1978 } 1979 1980 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags); 1981 1982 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num; 1983 } 1984 1985 void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb) 1986 { 1987 struct rtl_priv *rtlpriv = rtl_priv(hw); 1988 struct ieee80211_hdr *hdr = rtl_get_hdr(skb); 1989 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1990 unsigned long flags; 1991 1992 struct rtl_bssid_entry *entry = NULL, *iter; 1993 1994 /* check if it is scanning */ 1995 if (!mac->act_scanning) 1996 return; 1997 1998 /* check if this really is a beacon */ 1999 if (!ieee80211_is_beacon(hdr->frame_control) && 2000 !ieee80211_is_probe_resp(hdr->frame_control)) 2001 return; 2002 2003 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags); 2004 2005 list_for_each_entry(iter, &rtlpriv->scan_list.list, list) { 2006 if (memcmp(iter->bssid, hdr->addr3, ETH_ALEN) == 0) { 2007 list_del_init(&iter->list); 2008 entry = iter; 2009 rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 2010 "Update BSSID=%pM to scan list (total=%d)\n", 2011 hdr->addr3, rtlpriv->scan_list.num); 2012 break; 2013 } 2014 } 2015 2016 if (!entry) { 2017 entry = kmalloc_obj(*entry, GFP_ATOMIC); 2018 2019 if (!entry) 2020 goto label_err; 2021 2022 memcpy(entry->bssid, hdr->addr3, ETH_ALEN); 2023 rtlpriv->scan_list.num++; 2024 2025 rtl_dbg(rtlpriv, COMP_SCAN, DBG_LOUD, 2026 "Add BSSID=%pM to scan list (total=%d)\n", 2027 hdr->addr3, rtlpriv->scan_list.num); 2028 } 2029 2030 entry->age = jiffies; 2031 2032 list_add_tail(&entry->list, &rtlpriv->scan_list.list); 2033 2034 label_err: 2035 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags); 2036 } 2037 EXPORT_SYMBOL(rtl_collect_scan_list); 2038 2039 static void rtl_watchdog_wq_callback(struct work_struct *work) 2040 { 2041 struct rtl_works *rtlworks = container_of(work, struct rtl_works, 2042 watchdog_wq.work); 2043 struct ieee80211_hw *hw = rtlworks->hw; 2044 struct rtl_priv *rtlpriv = rtl_priv(hw); 2045 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2046 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2047 bool busytraffic = false; 2048 bool tx_busy_traffic = false; 2049 bool rx_busy_traffic = false; 2050 bool higher_busytraffic = false; 2051 bool higher_busyrxtraffic = false; 2052 u8 idx, tid; 2053 u32 rx_cnt_inp4eriod = 0; 2054 u32 tx_cnt_inp4eriod = 0; 2055 u32 aver_rx_cnt_inperiod = 0; 2056 u32 aver_tx_cnt_inperiod = 0; 2057 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; 2058 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; 2059 2060 if (is_hal_stop(rtlhal)) 2061 return; 2062 2063 /* <1> Determine if action frame is allowed */ 2064 if (mac->link_state > MAC80211_NOLINK) { 2065 if (mac->cnt_after_linked < 20) 2066 mac->cnt_after_linked++; 2067 } else { 2068 mac->cnt_after_linked = 0; 2069 } 2070 2071 /* <2> to check if traffic busy, if 2072 * busytraffic we don't change channel 2073 */ 2074 if (mac->link_state >= MAC80211_LINKED) { 2075 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ 2076 for (idx = 0; idx <= 2; idx++) { 2077 rtlpriv->link_info.num_rx_in4period[idx] = 2078 rtlpriv->link_info.num_rx_in4period[idx + 1]; 2079 rtlpriv->link_info.num_tx_in4period[idx] = 2080 rtlpriv->link_info.num_tx_in4period[idx + 1]; 2081 } 2082 rtlpriv->link_info.num_rx_in4period[3] = 2083 rtlpriv->link_info.num_rx_inperiod; 2084 rtlpriv->link_info.num_tx_in4period[3] = 2085 rtlpriv->link_info.num_tx_inperiod; 2086 for (idx = 0; idx <= 3; idx++) { 2087 rx_cnt_inp4eriod += 2088 rtlpriv->link_info.num_rx_in4period[idx]; 2089 tx_cnt_inp4eriod += 2090 rtlpriv->link_info.num_tx_in4period[idx]; 2091 } 2092 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; 2093 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; 2094 2095 /* (2) check traffic busy */ 2096 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { 2097 busytraffic = true; 2098 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) 2099 rx_busy_traffic = true; 2100 else 2101 tx_busy_traffic = false; 2102 } 2103 2104 /* Higher Tx/Rx data. */ 2105 if (aver_rx_cnt_inperiod > 4000 || 2106 aver_tx_cnt_inperiod > 4000) { 2107 higher_busytraffic = true; 2108 2109 /* Extremely high Rx data. */ 2110 if (aver_rx_cnt_inperiod > 5000) 2111 higher_busyrxtraffic = true; 2112 } 2113 2114 /* check every tid's tx traffic */ 2115 for (tid = 0; tid <= 7; tid++) { 2116 for (idx = 0; idx <= 2; idx++) 2117 rtlpriv->link_info.tidtx_in4period[tid][idx] = 2118 rtlpriv->link_info.tidtx_in4period[tid] 2119 [idx + 1]; 2120 rtlpriv->link_info.tidtx_in4period[tid][3] = 2121 rtlpriv->link_info.tidtx_inperiod[tid]; 2122 2123 for (idx = 0; idx <= 3; idx++) 2124 tidtx_inp4eriod[tid] += 2125 rtlpriv->link_info.tidtx_in4period[tid][idx]; 2126 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; 2127 if (aver_tidtx_inperiod[tid] > 5000) 2128 rtlpriv->link_info.higher_busytxtraffic[tid] = 2129 true; 2130 else 2131 rtlpriv->link_info.higher_busytxtraffic[tid] = 2132 false; 2133 } 2134 2135 /* PS is controlled by coex. */ 2136 if (rtlpriv->cfg->ops->get_btc_status() && 2137 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv)) 2138 goto label_lps_done; 2139 2140 if (rtlpriv->link_info.num_rx_inperiod + 2141 rtlpriv->link_info.num_tx_inperiod > 8 || 2142 rtlpriv->link_info.num_rx_inperiod > 2) 2143 rtl_lps_leave(hw, true); 2144 else 2145 rtl_lps_enter(hw, true); 2146 2147 label_lps_done: 2148 ; 2149 } 2150 2151 for (tid = 0; tid <= 7; tid++) 2152 rtlpriv->link_info.tidtx_inperiod[tid] = 0; 2153 2154 rtlpriv->link_info.busytraffic = busytraffic; 2155 rtlpriv->link_info.higher_busytraffic = higher_busytraffic; 2156 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; 2157 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; 2158 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; 2159 2160 rtlpriv->stats.txbytesunicast_inperiod = 2161 rtlpriv->stats.txbytesunicast - 2162 rtlpriv->stats.txbytesunicast_last; 2163 rtlpriv->stats.rxbytesunicast_inperiod = 2164 rtlpriv->stats.rxbytesunicast - 2165 rtlpriv->stats.rxbytesunicast_last; 2166 rtlpriv->stats.txbytesunicast_last = rtlpriv->stats.txbytesunicast; 2167 rtlpriv->stats.rxbytesunicast_last = rtlpriv->stats.rxbytesunicast; 2168 2169 rtlpriv->stats.txbytesunicast_inperiod_tp = 2170 (u32)(rtlpriv->stats.txbytesunicast_inperiod * 8 / 2 / 2171 1024 / 1024); 2172 rtlpriv->stats.rxbytesunicast_inperiod_tp = 2173 (u32)(rtlpriv->stats.rxbytesunicast_inperiod * 8 / 2 / 2174 1024 / 1024); 2175 2176 /* <3> DM */ 2177 if (!rtlpriv->cfg->mod_params->disable_watchdog) 2178 rtlpriv->cfg->ops->dm_watchdog(hw); 2179 2180 /* <4> roaming */ 2181 if (mac->link_state == MAC80211_LINKED && 2182 mac->opmode == NL80211_IFTYPE_STATION) { 2183 if ((rtlpriv->link_info.bcn_rx_inperiod + 2184 rtlpriv->link_info.num_rx_inperiod) == 0) { 2185 rtlpriv->link_info.roam_times++; 2186 rtl_dbg(rtlpriv, COMP_ERR, DBG_DMESG, 2187 "AP off for %d s\n", 2188 (rtlpriv->link_info.roam_times * 2)); 2189 2190 /* if we can't recv beacon for 10s, 2191 * we should reconnect this AP 2192 */ 2193 if (rtlpriv->link_info.roam_times >= 5) { 2194 pr_err("AP off, try to reconnect now\n"); 2195 rtlpriv->link_info.roam_times = 0; 2196 ieee80211_connection_loss( 2197 rtlpriv->mac80211.vif); 2198 } 2199 } else { 2200 rtlpriv->link_info.roam_times = 0; 2201 } 2202 } 2203 2204 if (rtlpriv->cfg->ops->get_btc_status()) 2205 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv); 2206 2207 if (rtlpriv->btcoexist.btc_info.in_4way) { 2208 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts + 2209 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME))) 2210 rtlpriv->btcoexist.btc_info.in_4way = false; 2211 } 2212 2213 rtlpriv->link_info.num_rx_inperiod = 0; 2214 rtlpriv->link_info.num_tx_inperiod = 0; 2215 rtlpriv->link_info.bcn_rx_inperiod = 0; 2216 2217 /* <6> scan list */ 2218 rtl_scan_list_expire(hw); 2219 2220 /* <7> check ack queue */ 2221 rtl_free_entries_from_ack_queue(hw, true); 2222 } 2223 2224 void rtl_watch_dog_timer_callback(struct timer_list *t) 2225 { 2226 struct rtl_priv *rtlpriv = timer_container_of(rtlpriv, t, 2227 works.watchdog_timer); 2228 2229 queue_delayed_work(rtlpriv->works.rtl_wq, 2230 &rtlpriv->works.watchdog_wq, 0); 2231 2232 mod_timer(&rtlpriv->works.watchdog_timer, 2233 jiffies + MSECS(RTL_WATCH_DOG_TIME)); 2234 } 2235 2236 static void rtl_fwevt_wq_callback(struct work_struct *work) 2237 { 2238 struct rtl_works *rtlworks = container_of(work, struct rtl_works, 2239 fwevt_wq.work); 2240 struct ieee80211_hw *hw = rtlworks->hw; 2241 struct rtl_priv *rtlpriv = rtl_priv(hw); 2242 2243 rtlpriv->cfg->ops->c2h_command_handle(hw); 2244 } 2245 2246 static void rtl_c2h_content_parsing(struct ieee80211_hw *hw, 2247 struct sk_buff *skb); 2248 2249 static bool rtl_c2h_fast_cmd(struct ieee80211_hw *hw, struct sk_buff *skb) 2250 { 2251 u8 cmd_id = GET_C2H_CMD_ID(skb->data); 2252 2253 switch (cmd_id) { 2254 case C2H_BT_MP: 2255 return true; 2256 default: 2257 break; 2258 } 2259 2260 return false; 2261 } 2262 2263 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, struct sk_buff *skb) 2264 { 2265 struct rtl_priv *rtlpriv = rtl_priv(hw); 2266 2267 if (rtl_c2h_fast_cmd(hw, skb)) { 2268 rtl_c2h_content_parsing(hw, skb); 2269 kfree_skb(skb); 2270 return; 2271 } 2272 2273 /* enqueue */ 2274 skb_queue_tail(&rtlpriv->c2hcmd_queue, skb); 2275 2276 /* wake up wq */ 2277 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0); 2278 } 2279 EXPORT_SYMBOL(rtl_c2hcmd_enqueue); 2280 2281 static void rtl_c2h_content_parsing(struct ieee80211_hw *hw, 2282 struct sk_buff *skb) 2283 { 2284 struct rtl_priv *rtlpriv = rtl_priv(hw); 2285 const struct rtl_hal_ops *hal_ops = rtlpriv->cfg->ops; 2286 const struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; 2287 u8 cmd_id, cmd_len; 2288 u8 *cmd_buf = NULL; 2289 2290 cmd_id = GET_C2H_CMD_ID(skb->data); 2291 cmd_len = skb->len - C2H_DATA_OFFSET; 2292 cmd_buf = GET_C2H_DATA_PTR(skb->data); 2293 2294 switch (cmd_id) { 2295 case C2H_DBG: 2296 rtl_dbg(rtlpriv, COMP_FW, DBG_LOUD, "[C2H], C2H_DBG!!\n"); 2297 break; 2298 case C2H_TXBF: 2299 rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, 2300 "[C2H], C2H_TXBF!!\n"); 2301 break; 2302 case C2H_TX_REPORT: 2303 rtl_tx_report_handler(hw, cmd_buf, cmd_len); 2304 break; 2305 case C2H_RA_RPT: 2306 if (hal_ops->c2h_ra_report_handler) 2307 hal_ops->c2h_ra_report_handler(hw, cmd_buf, cmd_len); 2308 break; 2309 case C2H_BT_INFO: 2310 rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, 2311 "[C2H], C2H_BT_INFO!!\n"); 2312 if (rtlpriv->cfg->ops->get_btc_status()) 2313 btc_ops->btc_btinfo_notify(rtlpriv, cmd_buf, cmd_len); 2314 break; 2315 case C2H_BT_MP: 2316 rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, 2317 "[C2H], C2H_BT_MP!!\n"); 2318 if (rtlpriv->cfg->ops->get_btc_status()) 2319 btc_ops->btc_btmpinfo_notify(rtlpriv, cmd_buf, cmd_len); 2320 break; 2321 default: 2322 rtl_dbg(rtlpriv, COMP_FW, DBG_TRACE, 2323 "[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id); 2324 break; 2325 } 2326 } 2327 2328 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec) 2329 { 2330 struct rtl_priv *rtlpriv = rtl_priv(hw); 2331 struct sk_buff *skb; 2332 int i; 2333 2334 for (i = 0; i < 200; i++) { 2335 /* dequeue a task */ 2336 skb = skb_dequeue(&rtlpriv->c2hcmd_queue); 2337 2338 /* do it */ 2339 if (!skb) 2340 break; 2341 2342 rtl_dbg(rtlpriv, COMP_FW, DBG_DMESG, "C2H rx_desc_shift=%d\n", 2343 *((u8 *)skb->cb)); 2344 RT_PRINT_DATA(rtlpriv, COMP_FW, DBG_DMESG, 2345 "C2H data: ", skb->data, skb->len); 2346 2347 if (exec) 2348 rtl_c2h_content_parsing(hw, skb); 2349 2350 /* free */ 2351 dev_kfree_skb_any(skb); 2352 } 2353 } 2354 2355 static void rtl_c2hcmd_wq_callback(struct work_struct *work) 2356 { 2357 struct rtl_works *rtlworks = container_of(work, struct rtl_works, 2358 c2hcmd_wq.work); 2359 struct ieee80211_hw *hw = rtlworks->hw; 2360 2361 rtl_c2hcmd_launcher(hw, 1); 2362 } 2363 2364 /********************************************************* 2365 * 2366 * frame process functions 2367 * 2368 *********************************************************/ 2369 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) 2370 { 2371 struct ieee80211_mgmt *mgmt = (void *)data; 2372 u8 *pos, *end; 2373 2374 pos = (u8 *)mgmt->u.beacon.variable; 2375 end = data + len; 2376 while (pos < end) { 2377 if (pos + 2 + pos[1] > end) 2378 return NULL; 2379 2380 if (pos[0] == ie) 2381 return pos; 2382 2383 pos += 2 + pos[1]; 2384 } 2385 return NULL; 2386 } 2387 2388 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ 2389 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ 2390 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, 2391 enum ieee80211_smps_mode smps, 2392 u8 *da, u8 *bssid) 2393 { 2394 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 2395 struct sk_buff *skb; 2396 struct ieee80211_mgmt *action_frame; 2397 2398 skb = dev_alloc_skb(IEEE80211_MIN_ACTION_SIZE(ht_smps) + 2399 hw->extra_tx_headroom); 2400 if (!skb) 2401 return NULL; 2402 2403 skb_reserve(skb, hw->extra_tx_headroom); 2404 action_frame = skb_put_zero(skb, IEEE80211_MIN_ACTION_SIZE(ht_smps)); 2405 memcpy(action_frame->da, da, ETH_ALEN); 2406 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); 2407 memcpy(action_frame->bssid, bssid, ETH_ALEN); 2408 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2409 IEEE80211_STYPE_ACTION); 2410 action_frame->u.action.category = WLAN_CATEGORY_HT; 2411 action_frame->u.action.action_code = WLAN_HT_ACTION_SMPS; 2412 switch (smps) { 2413 case IEEE80211_SMPS_AUTOMATIC:/* 0 */ 2414 case IEEE80211_SMPS_NUM_MODES:/* 4 */ 2415 WARN_ON(1); 2416 fallthrough; 2417 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ 2418 action_frame->u.action.ht_smps.smps_control = 2419 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ 2420 break; 2421 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ 2422 action_frame->u.action.ht_smps.smps_control = 2423 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ 2424 break; 2425 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ 2426 action_frame->u.action.ht_smps.smps_control = 2427 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ 2428 break; 2429 } 2430 2431 return skb; 2432 } 2433 2434 int rtl_send_smps_action(struct ieee80211_hw *hw, 2435 struct ieee80211_sta *sta, 2436 enum ieee80211_smps_mode smps) 2437 { 2438 struct rtl_priv *rtlpriv = rtl_priv(hw); 2439 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2440 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 2441 struct sk_buff *skb = NULL; 2442 struct rtl_tcb_desc tcb_desc; 2443 u8 bssid[ETH_ALEN] = {0}; 2444 2445 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); 2446 2447 if (rtlpriv->mac80211.act_scanning) 2448 goto err_free; 2449 2450 if (!sta) 2451 goto err_free; 2452 2453 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) 2454 goto err_free; 2455 2456 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) 2457 goto err_free; 2458 2459 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) 2460 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); 2461 else 2462 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); 2463 2464 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); 2465 /* this is a type = mgmt * stype = action frame */ 2466 if (skb) { 2467 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2468 struct rtl_sta_info *sta_entry = 2469 (struct rtl_sta_info *) sta->drv_priv; 2470 sta_entry->mimo_ps = smps; 2471 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */ 2472 2473 info->control.rates[0].idx = 0; 2474 info->band = hw->conf.chandef.chan->band; 2475 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); 2476 } 2477 return 1; 2478 2479 err_free: 2480 return 0; 2481 } 2482 EXPORT_SYMBOL(rtl_send_smps_action); 2483 2484 void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) 2485 { 2486 struct rtl_priv *rtlpriv = rtl_priv(hw); 2487 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2488 enum io_type iotype; 2489 2490 if (!is_hal_stop(rtlhal)) { 2491 switch (operation) { 2492 case SCAN_OPT_BACKUP: 2493 iotype = IO_CMD_PAUSE_DM_BY_SCAN; 2494 rtlpriv->cfg->ops->set_hw_reg(hw, 2495 HW_VAR_IO_CMD, 2496 (u8 *)&iotype); 2497 break; 2498 case SCAN_OPT_RESTORE: 2499 iotype = IO_CMD_RESUME_DM_BY_SCAN; 2500 rtlpriv->cfg->ops->set_hw_reg(hw, 2501 HW_VAR_IO_CMD, 2502 (u8 *)&iotype); 2503 break; 2504 default: 2505 pr_err("Unknown Scan Backup operation.\n"); 2506 break; 2507 } 2508 } 2509 } 2510 EXPORT_SYMBOL(rtl_phy_scan_operation_backup); 2511 2512 /* because mac80211 have issues when can receive del ba 2513 * so here we just make a fake del_ba if we receive a ba_req 2514 * but rx_agg was opened to let mac80211 release some ba 2515 * related resources, so please this del_ba for tx 2516 */ 2517 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, 2518 u8 *sa, u8 *bssid, u16 tid) 2519 { 2520 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 2521 struct sk_buff *skb; 2522 struct ieee80211_mgmt *action_frame; 2523 u16 params; 2524 2525 skb = dev_alloc_skb(IEEE80211_MIN_ACTION_SIZE(delba) + 2526 hw->extra_tx_headroom); 2527 if (!skb) 2528 return NULL; 2529 2530 skb_reserve(skb, hw->extra_tx_headroom); 2531 action_frame = skb_put_zero(skb, IEEE80211_MIN_ACTION_SIZE(delba)); 2532 memcpy(action_frame->sa, sa, ETH_ALEN); 2533 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); 2534 memcpy(action_frame->bssid, bssid, ETH_ALEN); 2535 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2536 IEEE80211_STYPE_ACTION); 2537 action_frame->u.action.category = WLAN_CATEGORY_BACK; 2538 action_frame->u.action.action_code = WLAN_ACTION_DELBA; 2539 params = (u16)(1 << 11); /* bit 11 initiator */ 2540 params |= (u16)(tid << 12); /* bit 15:12 TID number */ 2541 2542 action_frame->u.action.delba.params = cpu_to_le16(params); 2543 action_frame->u.action.delba.reason_code = 2544 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); 2545 2546 return skb; 2547 } 2548 2549 /********************************************************* 2550 * 2551 * IOT functions 2552 * 2553 *********************************************************/ 2554 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, 2555 struct octet_string vendor_ie) 2556 { 2557 struct rtl_priv *rtlpriv = rtl_priv(hw); 2558 bool matched = false; 2559 static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; 2560 static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; 2561 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; 2562 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; 2563 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; 2564 static u8 racap[] = { 0x00, 0x0c, 0x43 }; 2565 static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; 2566 static u8 marvcap[] = { 0x00, 0x50, 0x43 }; 2567 2568 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || 2569 memcmp(vendor_ie.octet, athcap_2, 3) == 0) { 2570 rtlpriv->mac80211.vendor = PEER_ATH; 2571 matched = true; 2572 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || 2573 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || 2574 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { 2575 rtlpriv->mac80211.vendor = PEER_BROAD; 2576 matched = true; 2577 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { 2578 rtlpriv->mac80211.vendor = PEER_RAL; 2579 matched = true; 2580 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { 2581 rtlpriv->mac80211.vendor = PEER_CISCO; 2582 matched = true; 2583 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { 2584 rtlpriv->mac80211.vendor = PEER_MARV; 2585 matched = true; 2586 } 2587 2588 return matched; 2589 } 2590 2591 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, 2592 unsigned int len) 2593 { 2594 struct ieee80211_mgmt *mgmt = (void *)data; 2595 struct octet_string vendor_ie; 2596 u8 *pos, *end; 2597 2598 pos = (u8 *)mgmt->u.beacon.variable; 2599 end = data + len; 2600 while (pos < end) { 2601 if (pos[0] == 221) { 2602 vendor_ie.length = pos[1]; 2603 vendor_ie.octet = &pos[2]; 2604 if (rtl_chk_vendor_ouisub(hw, vendor_ie)) 2605 return true; 2606 } 2607 2608 if (pos + 2 + pos[1] > end) 2609 return false; 2610 2611 pos += 2 + pos[1]; 2612 } 2613 return false; 2614 } 2615 2616 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) 2617 { 2618 struct rtl_priv *rtlpriv = rtl_priv(hw); 2619 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2620 struct ieee80211_hdr *hdr = (void *)data; 2621 u32 vendor = PEER_UNKNOWN; 2622 2623 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; 2624 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; 2625 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; 2626 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; 2627 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; 2628 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; 2629 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; 2630 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; 2631 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; 2632 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; 2633 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; 2634 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; 2635 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; 2636 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; 2637 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; 2638 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; 2639 2640 if (mac->opmode != NL80211_IFTYPE_STATION) 2641 return; 2642 2643 if (mac->link_state == MAC80211_NOLINK) { 2644 mac->vendor = PEER_UNKNOWN; 2645 return; 2646 } 2647 2648 if (mac->cnt_after_linked > 2) 2649 return; 2650 2651 /* check if this really is a beacon */ 2652 if (!ieee80211_is_beacon(hdr->frame_control)) 2653 return; 2654 2655 /* min. beacon length + FCS_LEN */ 2656 if (len <= 40 + FCS_LEN) 2657 return; 2658 2659 /* and only beacons from the associated BSSID, please */ 2660 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid)) 2661 return; 2662 2663 if (rtl_find_221_ie(hw, data, len)) 2664 vendor = mac->vendor; 2665 2666 if ((memcmp(mac->bssid, ap5_1, 3) == 0) || 2667 (memcmp(mac->bssid, ap5_2, 3) == 0) || 2668 (memcmp(mac->bssid, ap5_3, 3) == 0) || 2669 (memcmp(mac->bssid, ap5_4, 3) == 0) || 2670 (memcmp(mac->bssid, ap5_5, 3) == 0) || 2671 (memcmp(mac->bssid, ap5_6, 3) == 0) || 2672 vendor == PEER_ATH) { 2673 vendor = PEER_ATH; 2674 rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); 2675 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || 2676 (memcmp(mac->bssid, ap4_5, 3) == 0) || 2677 (memcmp(mac->bssid, ap4_1, 3) == 0) || 2678 (memcmp(mac->bssid, ap4_2, 3) == 0) || 2679 (memcmp(mac->bssid, ap4_3, 3) == 0) || 2680 vendor == PEER_RAL) { 2681 rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); 2682 vendor = PEER_RAL; 2683 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || 2684 vendor == PEER_CISCO) { 2685 vendor = PEER_CISCO; 2686 rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); 2687 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || 2688 (memcmp(mac->bssid, ap3_2, 3) == 0) || 2689 (memcmp(mac->bssid, ap3_3, 3) == 0) || 2690 vendor == PEER_BROAD) { 2691 rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); 2692 vendor = PEER_BROAD; 2693 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || 2694 vendor == PEER_MARV) { 2695 vendor = PEER_MARV; 2696 rtl_dbg(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); 2697 } 2698 2699 mac->vendor = vendor; 2700 } 2701 EXPORT_SYMBOL_GPL(rtl_recognize_peer); 2702 2703 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); 2704 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); 2705 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); 2706 MODULE_LICENSE("GPL"); 2707 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); 2708 2709 static int __init rtl_core_module_init(void) 2710 { 2711 BUILD_BUG_ON(TX_PWR_BY_RATE_NUM_RATE < TX_PWR_BY_RATE_NUM_SECTION); 2712 BUILD_BUG_ON(MAX_RATE_SECTION_NUM != MAX_RATE_SECTION); 2713 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_24G != MAX_RATE_SECTION); 2714 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_5G != (MAX_RATE_SECTION - 1)); 2715 2716 if (rtl_rate_control_register()) 2717 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n"); 2718 2719 /* add debugfs */ 2720 rtl_debugfs_add_topdir(); 2721 2722 return 0; 2723 } 2724 2725 static void __exit rtl_core_module_exit(void) 2726 { 2727 /*RC*/ 2728 rtl_rate_control_unregister(); 2729 2730 /* remove debugfs */ 2731 rtl_debugfs_remove_topdir(); 2732 } 2733 2734 module_init(rtl_core_module_init); 2735 module_exit(rtl_core_module_exit); 2736