1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
35 #include <linux/module.h>
36 #include <linux/udp.h>
39 *NOTICE!!!: This file will be very big, we should
40 *keep it clear under following roles:
42 *This file include following parts, so, if you add new
43 *functions into this file, please check which part it
44 *should includes. or check if you should add new part
47 *1) mac80211 init functions
48 *2) tx information functions
49 *3) functions called by core.c
50 *4) wq & timer callback functions
51 *5) frame process functions
58 /*********************************************************
60 * mac80211 init functions
62 *********************************************************/
63 static struct ieee80211_channel rtl_channeltable_2g[] = {
64 {.center_freq = 2412, .hw_value = 1,},
65 {.center_freq = 2417, .hw_value = 2,},
66 {.center_freq = 2422, .hw_value = 3,},
67 {.center_freq = 2427, .hw_value = 4,},
68 {.center_freq = 2432, .hw_value = 5,},
69 {.center_freq = 2437, .hw_value = 6,},
70 {.center_freq = 2442, .hw_value = 7,},
71 {.center_freq = 2447, .hw_value = 8,},
72 {.center_freq = 2452, .hw_value = 9,},
73 {.center_freq = 2457, .hw_value = 10,},
74 {.center_freq = 2462, .hw_value = 11,},
75 {.center_freq = 2467, .hw_value = 12,},
76 {.center_freq = 2472, .hw_value = 13,},
77 {.center_freq = 2484, .hw_value = 14,},
80 static struct ieee80211_channel rtl_channeltable_5g[] = {
81 {.center_freq = 5180, .hw_value = 36,},
82 {.center_freq = 5200, .hw_value = 40,},
83 {.center_freq = 5220, .hw_value = 44,},
84 {.center_freq = 5240, .hw_value = 48,},
85 {.center_freq = 5260, .hw_value = 52,},
86 {.center_freq = 5280, .hw_value = 56,},
87 {.center_freq = 5300, .hw_value = 60,},
88 {.center_freq = 5320, .hw_value = 64,},
89 {.center_freq = 5500, .hw_value = 100,},
90 {.center_freq = 5520, .hw_value = 104,},
91 {.center_freq = 5540, .hw_value = 108,},
92 {.center_freq = 5560, .hw_value = 112,},
93 {.center_freq = 5580, .hw_value = 116,},
94 {.center_freq = 5600, .hw_value = 120,},
95 {.center_freq = 5620, .hw_value = 124,},
96 {.center_freq = 5640, .hw_value = 128,},
97 {.center_freq = 5660, .hw_value = 132,},
98 {.center_freq = 5680, .hw_value = 136,},
99 {.center_freq = 5700, .hw_value = 140,},
100 {.center_freq = 5745, .hw_value = 149,},
101 {.center_freq = 5765, .hw_value = 153,},
102 {.center_freq = 5785, .hw_value = 157,},
103 {.center_freq = 5805, .hw_value = 161,},
104 {.center_freq = 5825, .hw_value = 165,},
107 static struct ieee80211_rate rtl_ratetable_2g[] = {
108 {.bitrate = 10, .hw_value = 0x00,},
109 {.bitrate = 20, .hw_value = 0x01,},
110 {.bitrate = 55, .hw_value = 0x02,},
111 {.bitrate = 110, .hw_value = 0x03,},
112 {.bitrate = 60, .hw_value = 0x04,},
113 {.bitrate = 90, .hw_value = 0x05,},
114 {.bitrate = 120, .hw_value = 0x06,},
115 {.bitrate = 180, .hw_value = 0x07,},
116 {.bitrate = 240, .hw_value = 0x08,},
117 {.bitrate = 360, .hw_value = 0x09,},
118 {.bitrate = 480, .hw_value = 0x0a,},
119 {.bitrate = 540, .hw_value = 0x0b,},
122 static struct ieee80211_rate rtl_ratetable_5g[] = {
123 {.bitrate = 60, .hw_value = 0x04,},
124 {.bitrate = 90, .hw_value = 0x05,},
125 {.bitrate = 120, .hw_value = 0x06,},
126 {.bitrate = 180, .hw_value = 0x07,},
127 {.bitrate = 240, .hw_value = 0x08,},
128 {.bitrate = 360, .hw_value = 0x09,},
129 {.bitrate = 480, .hw_value = 0x0a,},
130 {.bitrate = 540, .hw_value = 0x0b,},
133 static const struct ieee80211_supported_band rtl_band_2ghz = {
134 .band = NL80211_BAND_2GHZ,
136 .channels = rtl_channeltable_2g,
137 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
139 .bitrates = rtl_ratetable_2g,
140 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
145 static struct ieee80211_supported_band rtl_band_5ghz = {
146 .band = NL80211_BAND_5GHZ,
148 .channels = rtl_channeltable_5g,
149 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
151 .bitrates = rtl_ratetable_5g,
152 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
157 static const u8 tid_to_ac[] = {
158 2, /* IEEE80211_AC_BE */
159 3, /* IEEE80211_AC_BK */
160 3, /* IEEE80211_AC_BK */
161 2, /* IEEE80211_AC_BE */
162 1, /* IEEE80211_AC_VI */
163 1, /* IEEE80211_AC_VI */
164 0, /* IEEE80211_AC_VO */
165 0, /* IEEE80211_AC_VO */
168 u8 rtl_tid_to_ac(u8 tid)
170 return tid_to_ac[tid];
172 EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
174 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
175 struct ieee80211_sta_ht_cap *ht_cap)
177 struct rtl_priv *rtlpriv = rtl_priv(hw);
178 struct rtl_phy *rtlphy = &(rtlpriv->phy);
180 ht_cap->ht_supported = true;
181 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
182 IEEE80211_HT_CAP_SGI_40 |
183 IEEE80211_HT_CAP_SGI_20 |
184 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
186 if (rtlpriv->rtlhal.disable_amsdu_8k)
187 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
190 *Maximum length of AMPDU that the STA can receive.
191 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
193 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
195 /*Minimum MPDU start spacing , */
196 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
198 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
200 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
203 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
204 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
205 *if rx_ant >= 3 rx_mask[2]= 0xff;
206 *if BW_40 rx_mask[4]= 0x01;
207 *highest supported RX rate
209 if (rtlpriv->dm.supp_phymode_switch) {
210 pr_info("Support phy mode switch\n");
212 ht_cap->mcs.rx_mask[0] = 0xFF;
213 ht_cap->mcs.rx_mask[1] = 0xFF;
214 ht_cap->mcs.rx_mask[4] = 0x01;
216 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
218 if (get_rf_type(rtlphy) == RF_1T2R ||
219 get_rf_type(rtlphy) == RF_2T2R) {
220 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
222 ht_cap->mcs.rx_mask[0] = 0xFF;
223 ht_cap->mcs.rx_mask[1] = 0xFF;
224 ht_cap->mcs.rx_mask[4] = 0x01;
226 ht_cap->mcs.rx_highest =
227 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
228 } else if (get_rf_type(rtlphy) == RF_1T1R) {
229 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
231 ht_cap->mcs.rx_mask[0] = 0xFF;
232 ht_cap->mcs.rx_mask[1] = 0x00;
233 ht_cap->mcs.rx_mask[4] = 0x01;
235 ht_cap->mcs.rx_highest =
236 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
241 static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
242 struct ieee80211_sta_vht_cap *vht_cap)
244 struct rtl_priv *rtlpriv = rtl_priv(hw);
245 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
247 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
250 vht_cap->vht_supported = true;
252 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
253 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
254 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
255 IEEE80211_VHT_CAP_SHORT_GI_80 |
256 IEEE80211_VHT_CAP_TXSTBC |
257 IEEE80211_VHT_CAP_RXSTBC_1 |
258 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
259 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
260 IEEE80211_VHT_CAP_HTC_VHT |
261 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
262 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
263 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
266 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
267 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
272 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
273 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
275 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
276 vht_cap->vht_mcs.rx_highest =
277 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
278 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
279 vht_cap->vht_mcs.tx_highest =
280 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
281 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
284 vht_cap->vht_supported = true;
286 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
287 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
288 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
289 IEEE80211_VHT_CAP_SHORT_GI_80 |
290 IEEE80211_VHT_CAP_TXSTBC |
291 IEEE80211_VHT_CAP_RXSTBC_1 |
292 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
293 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
294 IEEE80211_VHT_CAP_HTC_VHT |
295 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
296 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
297 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
300 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
304 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
305 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
306 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
307 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
309 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
310 vht_cap->vht_mcs.rx_highest =
311 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
312 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
313 vht_cap->vht_mcs.tx_highest =
314 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
318 static void _rtl_init_mac80211(struct ieee80211_hw *hw)
320 struct rtl_priv *rtlpriv = rtl_priv(hw);
321 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
322 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
323 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
324 struct ieee80211_supported_band *sband;
326 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
327 rtlhal->bandset == BAND_ON_BOTH) {
329 /* <1> use mac->bands as mem for hw->wiphy->bands */
330 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
332 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
333 * to default value(1T1R) */
334 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
335 sizeof(struct ieee80211_supported_band));
337 /* <3> init ht cap base on ant_num */
338 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
340 /* <4> set mac->sband to wiphy->sband */
341 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
344 /* <1> use mac->bands as mem for hw->wiphy->bands */
345 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
347 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
348 * to default value(1T1R) */
349 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
350 sizeof(struct ieee80211_supported_band));
352 /* <3> init ht cap base on ant_num */
353 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
355 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
356 /* <4> set mac->sband to wiphy->sband */
357 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
359 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
360 /* <1> use mac->bands as mem for hw->wiphy->bands */
361 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
363 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
364 * to default value(1T1R) */
365 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
367 sizeof(struct ieee80211_supported_band));
369 /* <3> init ht cap base on ant_num */
370 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
372 /* <4> set mac->sband to wiphy->sband */
373 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
374 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
375 /* <1> use mac->bands as mem for hw->wiphy->bands */
376 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
378 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
379 * to default value(1T1R) */
380 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
382 sizeof(struct ieee80211_supported_band));
384 /* <3> init ht cap base on ant_num */
385 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
387 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
388 /* <4> set mac->sband to wiphy->sband */
389 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
391 pr_err("Err BAND %d\n",
392 rtlhal->current_bandtype);
395 /* <5> set hw caps */
396 ieee80211_hw_set(hw, SIGNAL_DBM);
397 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
398 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
399 ieee80211_hw_set(hw, CONNECTION_MONITOR);
400 ieee80211_hw_set(hw, MFP_CAPABLE);
401 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
403 /* swlps or hwlps has been set in diff chip in init_sw_vars */
404 if (rtlpriv->psc.swctrl_lps) {
405 ieee80211_hw_set(hw, SUPPORTS_PS);
406 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
408 if (rtlpriv->psc.fwctrl_lps) {
409 ieee80211_hw_set(hw, SUPPORTS_PS);
410 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
412 hw->wiphy->interface_modes =
413 BIT(NL80211_IFTYPE_AP) |
414 BIT(NL80211_IFTYPE_STATION) |
415 BIT(NL80211_IFTYPE_ADHOC) |
416 BIT(NL80211_IFTYPE_MESH_POINT) |
417 BIT(NL80211_IFTYPE_P2P_CLIENT) |
418 BIT(NL80211_IFTYPE_P2P_GO);
419 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
421 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
423 hw->wiphy->rts_threshold = 2347;
426 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
428 /* TODO: Correct this value for our hw */
429 hw->max_listen_interval = MAX_LISTEN_INTERVAL;
430 hw->max_rate_tries = MAX_RATE_TRIES;
431 /* hw->max_rates = 1; */
432 hw->sta_data_size = sizeof(struct rtl_sta_info);
434 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
436 if (rtlpriv->psc.wo_wlan_mode) {
437 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
438 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
439 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
440 rtlpriv->wowlan.n_patterns =
441 MAX_SUPPORT_WOL_PATTERN_NUM;
442 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
443 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
445 hw->wiphy->wowlan = &rtlpriv->wowlan;
449 /* <6> mac address */
450 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
451 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
453 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
454 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
455 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
459 static int _rtl_init_deferred_work(struct ieee80211_hw *hw)
461 struct rtl_priv *rtlpriv = rtl_priv(hw);
462 struct workqueue_struct *wq;
464 wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
469 setup_timer(&rtlpriv->works.watchdog_timer,
470 rtl_watch_dog_timer_callback, (unsigned long)hw);
471 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
472 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
474 rtlpriv->works.hw = hw;
475 rtlpriv->works.rtl_wq = wq;
477 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
478 (void *)rtl_watchdog_wq_callback);
479 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
480 (void *)rtl_ips_nic_off_wq_callback);
481 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
482 (void *)rtl_swlps_wq_callback);
483 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
484 (void *)rtl_swlps_rfon_wq_callback);
485 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
486 (void *)rtl_fwevt_wq_callback);
487 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
488 (void *)rtl_c2hcmd_wq_callback);
492 void rtl_deinit_deferred_work(struct ieee80211_hw *hw, bool ips_wq)
494 struct rtl_priv *rtlpriv = rtl_priv(hw);
496 del_timer_sync(&rtlpriv->works.watchdog_timer);
498 cancel_delayed_work_sync(&rtlpriv->works.watchdog_wq);
500 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
502 cancel_delayed_work_sync(&rtlpriv->works.ips_nic_off_wq);
503 cancel_delayed_work_sync(&rtlpriv->works.ps_work);
504 cancel_delayed_work_sync(&rtlpriv->works.ps_rfon_wq);
505 cancel_delayed_work_sync(&rtlpriv->works.fwevt_wq);
506 cancel_delayed_work_sync(&rtlpriv->works.c2hcmd_wq);
508 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
510 void rtl_init_rfkill(struct ieee80211_hw *hw)
512 struct rtl_priv *rtlpriv = rtl_priv(hw);
518 /*set init state to on */
519 rtlpriv->rfkill.rfkill_state = true;
520 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
522 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
525 pr_info("rtlwifi: wireless switch is %s\n",
526 rtlpriv->rfkill.rfkill_state ? "on" : "off");
528 rtlpriv->rfkill.rfkill_state = radio_state;
530 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
531 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
534 wiphy_rfkill_start_polling(hw->wiphy);
536 EXPORT_SYMBOL(rtl_init_rfkill);
538 void rtl_deinit_rfkill(struct ieee80211_hw *hw)
540 wiphy_rfkill_stop_polling(hw->wiphy);
542 EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
544 int rtl_init_core(struct ieee80211_hw *hw)
546 struct rtl_priv *rtlpriv = rtl_priv(hw);
547 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
549 /* <1> init mac80211 */
550 _rtl_init_mac80211(hw);
553 /* <2> rate control register */
554 hw->rate_control_algorithm = "rtl_rc";
557 * <3> init CRDA must come after init
558 * mac80211 hw in _rtl_init_mac80211.
560 if (rtl_regd_init(hw, rtl_reg_notifier)) {
561 pr_err("REGD init failed\n");
566 mutex_init(&rtlpriv->locks.conf_mutex);
567 spin_lock_init(&rtlpriv->locks.ips_lock);
568 spin_lock_init(&rtlpriv->locks.irq_th_lock);
569 spin_lock_init(&rtlpriv->locks.h2c_lock);
570 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
571 spin_lock_init(&rtlpriv->locks.rf_lock);
572 spin_lock_init(&rtlpriv->locks.waitq_lock);
573 spin_lock_init(&rtlpriv->locks.entry_list_lock);
574 spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
575 spin_lock_init(&rtlpriv->locks.scan_list_lock);
576 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
577 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
578 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
579 spin_lock_init(&rtlpriv->locks.lps_lock);
580 spin_lock_init(&rtlpriv->locks.iqk_lock);
582 INIT_LIST_HEAD(&rtlpriv->entry_list);
583 INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
584 INIT_LIST_HEAD(&rtlpriv->scan_list.list);
586 rtlmac->link_state = MAC80211_NOLINK;
588 /* <6> init deferred work */
589 return _rtl_init_deferred_work(hw);
591 EXPORT_SYMBOL_GPL(rtl_init_core);
593 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
595 void rtl_deinit_core(struct ieee80211_hw *hw)
597 rtl_c2hcmd_launcher(hw, 0);
598 rtl_free_entries_from_scan_list(hw);
600 EXPORT_SYMBOL_GPL(rtl_deinit_core);
602 void rtl_init_rx_config(struct ieee80211_hw *hw)
604 struct rtl_priv *rtlpriv = rtl_priv(hw);
605 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
607 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
609 EXPORT_SYMBOL_GPL(rtl_init_rx_config);
611 /*********************************************************
613 * tx information functions
615 *********************************************************/
616 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
617 struct rtl_tcb_desc *tcb_desc,
618 struct ieee80211_tx_info *info)
620 struct rtl_priv *rtlpriv = rtl_priv(hw);
621 u8 rate_flag = info->control.rates[0].flags;
623 tcb_desc->use_shortpreamble = false;
625 /* 1M can only use Long Preamble. 11B spec */
626 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
628 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
629 tcb_desc->use_shortpreamble = true;
634 static void _rtl_query_shortgi(struct ieee80211_hw *hw,
635 struct ieee80211_sta *sta,
636 struct rtl_tcb_desc *tcb_desc,
637 struct ieee80211_tx_info *info)
639 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
640 u8 rate_flag = info->control.rates[0].flags;
641 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
642 u8 sgi_80 = 0, bw_80 = 0;
643 tcb_desc->use_shortgi = false;
648 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
649 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
650 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
652 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
655 if (!sgi_40 && !sgi_20)
658 if (mac->opmode == NL80211_IFTYPE_STATION) {
661 } else if (mac->opmode == NL80211_IFTYPE_AP ||
662 mac->opmode == NL80211_IFTYPE_ADHOC ||
663 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
664 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
665 bw_80 = sta->vht_cap.vht_supported;
670 tcb_desc->use_shortgi = true;
672 tcb_desc->use_shortgi = false;
675 tcb_desc->use_shortgi = true;
676 else if (!bw_40 && sgi_20)
677 tcb_desc->use_shortgi = true;
680 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
681 tcb_desc->use_shortgi = false;
684 static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
685 struct rtl_tcb_desc *tcb_desc,
686 struct ieee80211_tx_info *info)
688 struct rtl_priv *rtlpriv = rtl_priv(hw);
689 u8 rate_flag = info->control.rates[0].flags;
691 /* Common Settings */
692 tcb_desc->rts_stbc = false;
693 tcb_desc->cts_enable = false;
694 tcb_desc->rts_sc = 0;
695 tcb_desc->rts_bw = false;
696 tcb_desc->rts_use_shortpreamble = false;
697 tcb_desc->rts_use_shortgi = false;
699 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
700 /* Use CTS-to-SELF in protection mode. */
701 tcb_desc->rts_enable = true;
702 tcb_desc->cts_enable = true;
703 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
704 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
705 /* Use RTS-CTS in protection mode. */
706 tcb_desc->rts_enable = true;
707 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
711 static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
712 struct ieee80211_sta *sta,
713 struct rtl_tcb_desc *tcb_desc)
715 struct rtl_priv *rtlpriv = rtl_priv(hw);
716 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
717 struct rtl_sta_info *sta_entry = NULL;
721 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
722 ratr_index = sta_entry->ratr_index;
724 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
725 if (mac->opmode == NL80211_IFTYPE_STATION) {
726 tcb_desc->ratr_index = 0;
727 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
728 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
729 if (tcb_desc->multicast || tcb_desc->broadcast) {
731 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
732 tcb_desc->use_driver_rate = 1;
733 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
735 tcb_desc->ratr_index = ratr_index;
737 } else if (mac->opmode == NL80211_IFTYPE_AP) {
738 tcb_desc->ratr_index = ratr_index;
742 if (rtlpriv->dm.useramask) {
743 tcb_desc->ratr_index = ratr_index;
744 /* TODO we will differentiate adhoc and station future */
745 if (mac->opmode == NL80211_IFTYPE_STATION ||
746 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
747 tcb_desc->mac_id = 0;
749 if (mac->mode == WIRELESS_MODE_AC_5G)
750 tcb_desc->ratr_index =
751 RATR_INX_WIRELESS_AC_5N;
752 else if (mac->mode == WIRELESS_MODE_AC_24G)
753 tcb_desc->ratr_index =
754 RATR_INX_WIRELESS_AC_24N;
755 else if (mac->mode == WIRELESS_MODE_N_24G)
756 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
757 else if (mac->mode == WIRELESS_MODE_N_5G)
758 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
759 else if (mac->mode & WIRELESS_MODE_G)
760 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
761 else if (mac->mode & WIRELESS_MODE_B)
762 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
763 else if (mac->mode & WIRELESS_MODE_A)
764 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
766 } else if (mac->opmode == NL80211_IFTYPE_AP ||
767 mac->opmode == NL80211_IFTYPE_ADHOC) {
770 tcb_desc->mac_id = sta->aid + 1;
772 tcb_desc->mac_id = 1;
774 tcb_desc->mac_id = 0;
780 static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
781 struct ieee80211_sta *sta,
782 struct rtl_tcb_desc *tcb_desc)
784 struct rtl_priv *rtlpriv = rtl_priv(hw);
785 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
787 tcb_desc->packet_bw = false;
790 if (mac->opmode == NL80211_IFTYPE_AP ||
791 mac->opmode == NL80211_IFTYPE_ADHOC ||
792 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
793 if (!(sta->ht_cap.ht_supported) ||
794 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
796 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
797 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
800 if (tcb_desc->multicast || tcb_desc->broadcast)
803 /*use legency rate, shall use 20MHz */
804 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
807 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
809 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
810 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
811 if (mac->opmode == NL80211_IFTYPE_AP ||
812 mac->opmode == NL80211_IFTYPE_ADHOC ||
813 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
814 if (!(sta->vht_cap.vht_supported))
816 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
818 !(sta->vht_cap.vht_supported))
821 if (tcb_desc->hw_rate <=
822 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
824 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
828 static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
829 struct ieee80211_sta *sta)
831 struct rtl_priv *rtlpriv = rtl_priv(hw);
832 struct rtl_phy *rtlphy = &(rtlpriv->phy);
834 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
836 if ((get_rf_type(rtlphy) == RF_2T2R) &&
837 (tx_mcs_map & 0x000c) != 0x000c) {
838 if ((tx_mcs_map & 0x000c) >> 2 ==
839 IEEE80211_VHT_MCS_SUPPORT_0_7)
841 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
842 else if ((tx_mcs_map & 0x000c) >> 2 ==
843 IEEE80211_VHT_MCS_SUPPORT_0_8)
845 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
848 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
850 if ((tx_mcs_map & 0x0003) ==
851 IEEE80211_VHT_MCS_SUPPORT_0_7)
853 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
854 else if ((tx_mcs_map & 0x0003) ==
855 IEEE80211_VHT_MCS_SUPPORT_0_8)
857 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
860 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
866 static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
867 struct ieee80211_sta *sta)
869 struct rtl_priv *rtlpriv = rtl_priv(hw);
870 struct rtl_phy *rtlphy = &rtlpriv->phy;
873 if ((get_rf_type(rtlphy) == RF_2T2R) &&
874 (sta->ht_cap.mcs.rx_mask[1] != 0))
875 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
877 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
882 /* mac80211's rate_idx is like this:
884 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
887 * (rx_status->flag & RX_FLAG_HT) = 0,
888 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
891 * (rx_status->flag & RX_FLAG_HT) = 1,
892 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
894 * 5G band:rx_status->band == NL80211_BAND_5GHZ
896 * (rx_status->flag & RX_FLAG_HT) = 0,
897 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
900 * (rx_status->flag & RX_FLAG_HT) = 1,
901 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
904 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
905 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
907 int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
914 case DESC_RATEVHT1SS_MCS0:
917 case DESC_RATEVHT1SS_MCS1:
920 case DESC_RATEVHT1SS_MCS2:
923 case DESC_RATEVHT1SS_MCS3:
926 case DESC_RATEVHT1SS_MCS4:
929 case DESC_RATEVHT1SS_MCS5:
932 case DESC_RATEVHT1SS_MCS6:
935 case DESC_RATEVHT1SS_MCS7:
938 case DESC_RATEVHT1SS_MCS8:
941 case DESC_RATEVHT1SS_MCS9:
944 case DESC_RATEVHT2SS_MCS0:
947 case DESC_RATEVHT2SS_MCS1:
950 case DESC_RATEVHT2SS_MCS2:
953 case DESC_RATEVHT2SS_MCS3:
956 case DESC_RATEVHT2SS_MCS4:
959 case DESC_RATEVHT2SS_MCS5:
962 case DESC_RATEVHT2SS_MCS6:
965 case DESC_RATEVHT2SS_MCS7:
968 case DESC_RATEVHT2SS_MCS8:
971 case DESC_RATEVHT2SS_MCS9:
981 if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
1024 switch (desc_rate) {
1055 switch (desc_rate) {
1086 case DESC_RATEMCS10:
1089 case DESC_RATEMCS11:
1092 case DESC_RATEMCS12:
1095 case DESC_RATEMCS13:
1098 case DESC_RATEMCS14:
1101 case DESC_RATEMCS15:
1111 EXPORT_SYMBOL(rtlwifi_rate_mapping);
1113 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1114 struct ieee80211_tx_info *info,
1115 struct ieee80211_sta *sta,
1116 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1118 struct rtl_priv *rtlpriv = rtl_priv(hw);
1119 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
1120 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1121 struct ieee80211_rate *txrate;
1122 __le16 fc = rtl_get_fc(skb);
1124 txrate = ieee80211_get_tx_rate(hw, info);
1126 tcb_desc->hw_rate = txrate->hw_value;
1128 if (rtl_is_tx_report_skb(hw, skb))
1129 tcb_desc->use_spe_rpt = 1;
1131 if (ieee80211_is_data(fc)) {
1133 *we set data rate INX 0
1134 *in rtl_rc.c if skb is special data or
1135 *mgt which need low data rate.
1139 *So tcb_desc->hw_rate is just used for
1140 *special data and mgt frames
1142 if (info->control.rates[0].idx == 0 ||
1143 ieee80211_is_nullfunc(fc)) {
1144 tcb_desc->use_driver_rate = true;
1145 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
1147 tcb_desc->disable_ratefallback = 1;
1150 *because hw will nerver use hw_rate
1151 *when tcb_desc->use_driver_rate = false
1152 *so we never set highest N rate here,
1153 *and N rate will all be controlled by FW
1154 *when tcb_desc->use_driver_rate = false
1156 if (sta && sta->vht_cap.vht_supported) {
1158 _rtl_get_vht_highest_n_rate(hw, sta);
1160 if (sta && (sta->ht_cap.ht_supported)) {
1162 _rtl_get_highest_n_rate(hw, sta);
1164 if (rtlmac->mode == WIRELESS_MODE_B) {
1166 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1169 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1175 if (is_multicast_ether_addr(hdr->addr1))
1176 tcb_desc->multicast = 1;
1177 else if (is_broadcast_ether_addr(hdr->addr1))
1178 tcb_desc->broadcast = 1;
1180 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1181 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
1182 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
1183 _rtl_query_shortgi(hw, sta, tcb_desc, info);
1184 _rtl_query_protection_mode(hw, tcb_desc, info);
1186 tcb_desc->use_driver_rate = true;
1187 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
1188 tcb_desc->disable_ratefallback = 1;
1189 tcb_desc->mac_id = 0;
1190 tcb_desc->packet_bw = false;
1193 EXPORT_SYMBOL(rtl_get_tcb_desc);
1195 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1197 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1198 struct rtl_priv *rtlpriv = rtl_priv(hw);
1199 __le16 fc = rtl_get_fc(skb);
1201 if (rtlpriv->dm.supp_phymode_switch &&
1202 mac->link_state < MAC80211_LINKED &&
1203 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1204 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1205 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1207 if (ieee80211_is_auth(fc)) {
1208 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1211 mac->link_state = MAC80211_LINKING;
1213 rtlpriv->phy.need_iqk = true;
1219 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1221 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1222 u8 *bssid, u16 tid);
1224 static void process_agg_start(struct ieee80211_hw *hw,
1225 struct ieee80211_hdr *hdr, u16 tid)
1227 struct rtl_priv *rtlpriv = rtl_priv(hw);
1228 struct ieee80211_rx_status rx_status = { 0 };
1229 struct sk_buff *skb_delba = NULL;
1231 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1233 rx_status.freq = hw->conf.chandef.chan->center_freq;
1234 rx_status.band = hw->conf.chandef.chan->band;
1235 rx_status.flag |= RX_FLAG_DECRYPTED;
1236 rx_status.flag |= RX_FLAG_MACTIME_START;
1237 rx_status.rate_idx = 0;
1238 rx_status.signal = 50 + 10;
1239 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1240 &rx_status, sizeof(rx_status));
1241 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1245 ieee80211_rx_irqsafe(hw, skb_delba);
1249 bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1251 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1252 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1253 struct rtl_priv *rtlpriv = rtl_priv(hw);
1254 __le16 fc = rtl_get_fc(skb);
1255 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
1258 if (!ieee80211_is_action(fc))
1267 if (mac->act_scanning)
1270 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1271 "%s ACT_ADDBAREQ From :%pM\n",
1272 is_tx ? "Tx" : "Rx", hdr->addr2);
1273 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1274 skb->data, skb->len);
1276 struct ieee80211_sta *sta = NULL;
1277 struct rtl_sta_info *sta_entry = NULL;
1278 struct rtl_tid_data *tid_data;
1279 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1280 u16 capab = 0, tid = 0;
1283 sta = rtl_find_sta(hw, hdr->addr3);
1285 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1286 DBG_DMESG, "sta is NULL\n");
1292 (struct rtl_sta_info *)sta->drv_priv;
1298 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1300 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1301 tid_data = &sta_entry->tids[tid];
1302 if (tid_data->agg.rx_agg_state ==
1304 process_agg_start(hw, hdr, tid);
1309 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1310 "%s ACT_ADDBARSP From :%pM\n",
1311 is_tx ? "Tx" : "Rx", hdr->addr2);
1314 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1315 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
1325 EXPORT_SYMBOL_GPL(rtl_action_proc);
1327 static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
1330 struct ieee80211_hw *hw = rtlpriv->hw;
1332 rtlpriv->ra.is_special_data = true;
1333 if (rtlpriv->cfg->ops->get_btc_status())
1334 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
1337 ppsc->last_delaylps_stamp_jiffies = jiffies;
1340 static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
1341 struct sk_buff *skb, bool is_enc)
1343 struct rtl_priv *rtlpriv = rtl_priv(hw);
1344 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1345 u8 encrypt_header_len = 0;
1348 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1349 case WEP40_ENCRYPTION:
1350 case WEP104_ENCRYPTION:
1351 encrypt_header_len = 4;/*WEP_IV_LEN*/
1353 case TKIP_ENCRYPTION:
1354 encrypt_header_len = 8;/*TKIP_IV_LEN*/
1356 case AESCCMP_ENCRYPTION:
1357 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
1363 offset = mac_hdr_len + SNAP_SIZE;
1365 offset += encrypt_header_len;
1367 return skb->data + offset;
1370 /*should call before software enc*/
1371 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1374 struct rtl_priv *rtlpriv = rtl_priv(hw);
1375 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1376 __le16 fc = rtl_get_fc(skb);
1378 const u8 *ether_type_ptr;
1379 const struct iphdr *ip;
1381 if (!ieee80211_is_data(fc))
1384 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
1385 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1387 if (ETH_P_IP == ether_type) {
1388 ip = (struct iphdr *)((u8 *)ether_type_ptr +
1390 if (IPPROTO_UDP == ip->protocol) {
1391 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1393 if (((((u8 *)udp)[1] == 68) &&
1394 (((u8 *)udp)[3] == 67)) ||
1395 ((((u8 *)udp)[1] == 67) &&
1396 (((u8 *)udp)[3] == 68))) {
1397 /* 68 : UDP BOOTP client
1398 * 67 : UDP BOOTP server
1400 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1401 DBG_DMESG, "dhcp %s !!\n",
1402 (is_tx) ? "Tx" : "Rx");
1405 setup_special_tx(rtlpriv, ppsc,
1411 } else if (ETH_P_ARP == ether_type) {
1413 setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
1416 } else if (ETH_P_PAE == ether_type) {
1417 /* EAPOL is seens as in-4way */
1418 rtlpriv->btcoexist.btc_info.in_4way = true;
1419 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1420 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1422 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1423 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1426 rtlpriv->ra.is_special_data = true;
1428 ppsc->last_delaylps_stamp_jiffies = jiffies;
1430 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
1434 } else if (ETH_P_IPV6 == ether_type) {
1435 /* TODO: Handle any IPv6 cases that need special handling.
1436 * For now, always return false
1442 rtlpriv->ra.is_special_data = false;
1445 EXPORT_SYMBOL_GPL(rtl_is_special_data);
1447 bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1450 const u8 *ether_type_ptr;
1452 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
1453 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1456 if (ether_type == ETH_P_PAE)
1462 static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
1464 struct rtl_priv *rtlpriv = rtl_priv(hw);
1465 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1468 sn = atomic_inc_return(&tx_report->sn) & 0x0FFF;
1470 tx_report->last_sent_sn = sn;
1471 tx_report->last_sent_time = jiffies;
1473 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1474 "Send TX-Report sn=0x%X\n", sn);
1479 void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
1480 struct ieee80211_hw *hw)
1482 if (ptcb_desc->use_spe_rpt) {
1483 u16 sn = rtl_get_tx_report_sn(hw);
1485 SET_TX_DESC_SPE_RPT(pdesc, 1);
1486 SET_TX_DESC_SW_DEFINE(pdesc, sn);
1489 EXPORT_SYMBOL_GPL(rtl_get_tx_report);
1491 void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
1493 struct rtl_priv *rtlpriv = rtl_priv(hw);
1494 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1497 sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
1499 tx_report->last_recv_sn = sn;
1501 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1502 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1503 tmp_buf[0], sn, tmp_buf[2]);
1505 EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
1507 bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
1509 struct rtl_priv *rtlpriv = rtl_priv(hw);
1510 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1512 if (tx_report->last_sent_sn == tx_report->last_recv_sn)
1515 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
1516 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
1517 "Check TX-Report timeout!!\n");
1518 return true; /* 3 sec. (timeout) seen as acked */
1524 void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
1526 struct rtl_priv *rtlpriv = rtl_priv(hw);
1529 for (i = 0; i < wait_ms; i++) {
1530 if (rtl_check_tx_report_acked(hw))
1532 usleep_range(1000, 2000);
1533 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1534 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
1537 /*********************************************************
1539 * functions called by core.c
1541 *********************************************************/
1542 int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1543 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1545 struct rtl_priv *rtlpriv = rtl_priv(hw);
1546 struct rtl_tid_data *tid_data;
1547 struct rtl_sta_info *sta_entry = NULL;
1552 if (unlikely(tid >= MAX_TID_COUNT))
1555 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1558 tid_data = &sta_entry->tids[tid];
1560 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1561 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1562 tid_data->seq_number);
1564 *ssn = tid_data->seq_number;
1565 tid_data->agg.agg_state = RTL_AGG_START;
1567 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1571 int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1572 struct ieee80211_sta *sta, u16 tid)
1574 struct rtl_priv *rtlpriv = rtl_priv(hw);
1575 struct rtl_tid_data *tid_data;
1576 struct rtl_sta_info *sta_entry = NULL;
1581 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1582 "on ra = %pM tid = %d\n", sta->addr, tid);
1584 if (unlikely(tid >= MAX_TID_COUNT))
1587 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1588 tid_data = &sta_entry->tids[tid];
1589 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
1591 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1595 int rtl_rx_agg_start(struct ieee80211_hw *hw,
1596 struct ieee80211_sta *sta, u16 tid)
1598 struct rtl_priv *rtlpriv = rtl_priv(hw);
1599 struct rtl_tid_data *tid_data;
1600 struct rtl_sta_info *sta_entry = NULL;
1606 if (unlikely(tid >= MAX_TID_COUNT))
1609 if (rtlpriv->cfg->ops->get_btc_status()) {
1610 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
1617 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1620 tid_data = &sta_entry->tids[tid];
1622 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1623 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1624 tid_data->seq_number);
1626 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1630 int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1631 struct ieee80211_sta *sta, u16 tid)
1633 struct rtl_priv *rtlpriv = rtl_priv(hw);
1634 struct rtl_sta_info *sta_entry = NULL;
1639 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1640 "on ra = %pM tid = %d\n", sta->addr, tid);
1642 if (unlikely(tid >= MAX_TID_COUNT))
1645 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1646 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1650 int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1651 struct ieee80211_sta *sta, u16 tid)
1653 struct rtl_priv *rtlpriv = rtl_priv(hw);
1654 struct rtl_sta_info *sta_entry = NULL;
1659 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1660 "on ra = %pM tid = %d\n", sta->addr, tid);
1662 if (unlikely(tid >= MAX_TID_COUNT))
1665 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1666 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
1671 void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
1673 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
1674 u8 reject_agg = 0, ctrl_agg_size = 0, agg_size = 0;
1676 if (rtlpriv->cfg->ops->get_btc_status())
1677 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
1678 &ctrl_agg_size, &agg_size);
1680 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
1681 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1682 reject_agg, ctrl_agg_size, agg_size);
1684 rtlpriv->hw->max_rx_aggregation_subframes =
1685 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
1687 EXPORT_SYMBOL(rtl_rx_ampdu_apply);
1689 /*********************************************************
1691 * wq & timer callback functions
1693 *********************************************************/
1694 /* this function is used for roaming */
1695 void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1697 struct rtl_priv *rtlpriv = rtl_priv(hw);
1698 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1700 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1703 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1706 /* check if this really is a beacon */
1707 if (!ieee80211_is_beacon(hdr->frame_control) &&
1708 !ieee80211_is_probe_resp(hdr->frame_control))
1711 /* min. beacon length + FCS_LEN */
1712 if (skb->len <= 40 + FCS_LEN)
1715 /* and only beacons from the associated BSSID, please */
1716 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
1719 rtlpriv->link_info.bcn_rx_inperiod++;
1721 EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
1723 static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
1725 struct rtl_priv *rtlpriv = rtl_priv(hw);
1726 struct rtl_bssid_entry *entry, *next;
1728 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1729 list_del(&entry->list);
1731 rtlpriv->scan_list.num--;
1735 void rtl_scan_list_expire(struct ieee80211_hw *hw)
1737 struct rtl_priv *rtlpriv = rtl_priv(hw);
1738 struct rtl_bssid_entry *entry, *next;
1739 unsigned long flags;
1741 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1743 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1745 if (jiffies_to_msecs(jiffies - entry->age) < 180000)
1748 list_del(&entry->list);
1749 rtlpriv->scan_list.num--;
1751 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1752 "BSSID=%pM is expire in scan list (total=%d)\n",
1753 entry->bssid, rtlpriv->scan_list.num);
1757 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1759 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
1762 void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
1764 struct rtl_priv *rtlpriv = rtl_priv(hw);
1765 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1766 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1767 unsigned long flags;
1769 struct rtl_bssid_entry *entry;
1770 bool entry_found = false;
1772 /* check if it is scanning */
1773 if (!mac->act_scanning)
1776 /* check if this really is a beacon */
1777 if (!ieee80211_is_beacon(hdr->frame_control) &&
1778 !ieee80211_is_probe_resp(hdr->frame_control))
1781 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1783 list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
1784 if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
1785 list_del_init(&entry->list);
1787 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1788 "Update BSSID=%pM to scan list (total=%d)\n",
1789 hdr->addr3, rtlpriv->scan_list.num);
1795 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1800 memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
1801 rtlpriv->scan_list.num++;
1803 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1804 "Add BSSID=%pM to scan list (total=%d)\n",
1805 hdr->addr3, rtlpriv->scan_list.num);
1808 entry->age = jiffies;
1810 list_add_tail(&entry->list, &rtlpriv->scan_list.list);
1813 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1815 EXPORT_SYMBOL(rtl_collect_scan_list);
1817 void rtl_watchdog_wq_callback(void *data)
1819 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1822 struct ieee80211_hw *hw = rtlworks->hw;
1823 struct rtl_priv *rtlpriv = rtl_priv(hw);
1824 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1825 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1826 bool busytraffic = false;
1827 bool tx_busy_traffic = false;
1828 bool rx_busy_traffic = false;
1829 bool higher_busytraffic = false;
1830 bool higher_busyrxtraffic = false;
1832 u32 rx_cnt_inp4eriod = 0;
1833 u32 tx_cnt_inp4eriod = 0;
1834 u32 aver_rx_cnt_inperiod = 0;
1835 u32 aver_tx_cnt_inperiod = 0;
1836 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1837 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
1839 if (is_hal_stop(rtlhal))
1842 /* <1> Determine if action frame is allowed */
1843 if (mac->link_state > MAC80211_NOLINK) {
1844 if (mac->cnt_after_linked < 20)
1845 mac->cnt_after_linked++;
1847 mac->cnt_after_linked = 0;
1850 /* <2> to check if traffic busy, if
1851 * busytraffic we don't change channel
1853 if (mac->link_state >= MAC80211_LINKED) {
1855 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1856 for (idx = 0; idx <= 2; idx++) {
1857 rtlpriv->link_info.num_rx_in4period[idx] =
1858 rtlpriv->link_info.num_rx_in4period[idx + 1];
1859 rtlpriv->link_info.num_tx_in4period[idx] =
1860 rtlpriv->link_info.num_tx_in4period[idx + 1];
1862 rtlpriv->link_info.num_rx_in4period[3] =
1863 rtlpriv->link_info.num_rx_inperiod;
1864 rtlpriv->link_info.num_tx_in4period[3] =
1865 rtlpriv->link_info.num_tx_inperiod;
1866 for (idx = 0; idx <= 3; idx++) {
1868 rtlpriv->link_info.num_rx_in4period[idx];
1870 rtlpriv->link_info.num_tx_in4period[idx];
1872 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1873 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1875 /* (2) check traffic busy */
1876 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
1878 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1879 rx_busy_traffic = true;
1881 tx_busy_traffic = false;
1884 /* Higher Tx/Rx data. */
1885 if (aver_rx_cnt_inperiod > 4000 ||
1886 aver_tx_cnt_inperiod > 4000) {
1887 higher_busytraffic = true;
1889 /* Extremely high Rx data. */
1890 if (aver_rx_cnt_inperiod > 5000)
1891 higher_busyrxtraffic = true;
1894 /* check every tid's tx traffic */
1895 for (tid = 0; tid <= 7; tid++) {
1896 for (idx = 0; idx <= 2; idx++)
1897 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1898 rtlpriv->link_info.tidtx_in4period[tid]
1900 rtlpriv->link_info.tidtx_in4period[tid][3] =
1901 rtlpriv->link_info.tidtx_inperiod[tid];
1903 for (idx = 0; idx <= 3; idx++)
1904 tidtx_inp4eriod[tid] +=
1905 rtlpriv->link_info.tidtx_in4period[tid][idx];
1906 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1907 if (aver_tidtx_inperiod[tid] > 5000)
1908 rtlpriv->link_info.higher_busytxtraffic[tid] =
1911 rtlpriv->link_info.higher_busytxtraffic[tid] =
1915 /* PS is controlled by coex. */
1916 if (rtlpriv->cfg->ops->get_btc_status() &&
1917 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
1918 goto label_lps_done;
1920 if (((rtlpriv->link_info.num_rx_inperiod +
1921 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1922 (rtlpriv->link_info.num_rx_inperiod > 2))
1931 rtlpriv->link_info.num_rx_inperiod = 0;
1932 rtlpriv->link_info.num_tx_inperiod = 0;
1933 for (tid = 0; tid <= 7; tid++)
1934 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
1936 rtlpriv->link_info.busytraffic = busytraffic;
1937 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
1938 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1939 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
1940 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
1943 if (!rtlpriv->cfg->mod_params->disable_watchdog)
1944 rtlpriv->cfg->ops->dm_watchdog(hw);
1947 if (mac->link_state == MAC80211_LINKED &&
1948 mac->opmode == NL80211_IFTYPE_STATION) {
1949 if ((rtlpriv->link_info.bcn_rx_inperiod +
1950 rtlpriv->link_info.num_rx_inperiod) == 0) {
1951 rtlpriv->link_info.roam_times++;
1952 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1953 "AP off for %d s\n",
1954 (rtlpriv->link_info.roam_times * 2));
1956 /* if we can't recv beacon for 10s,
1957 * we should reconnect this AP
1959 if (rtlpriv->link_info.roam_times >= 5) {
1960 pr_err("AP off, try to reconnect now\n");
1961 rtlpriv->link_info.roam_times = 0;
1962 ieee80211_connection_loss(
1963 rtlpriv->mac80211.vif);
1966 rtlpriv->link_info.roam_times = 0;
1970 if (rtlpriv->cfg->ops->get_btc_status())
1971 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
1973 if (rtlpriv->btcoexist.btc_info.in_4way) {
1974 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
1975 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
1976 rtlpriv->btcoexist.btc_info.in_4way = false;
1979 rtlpriv->link_info.bcn_rx_inperiod = 0;
1982 rtl_scan_list_expire(hw);
1985 void rtl_watch_dog_timer_callback(unsigned long data)
1987 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1988 struct rtl_priv *rtlpriv = rtl_priv(hw);
1990 queue_delayed_work(rtlpriv->works.rtl_wq,
1991 &rtlpriv->works.watchdog_wq, 0);
1993 mod_timer(&rtlpriv->works.watchdog_timer,
1994 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1996 void rtl_fwevt_wq_callback(void *data)
1998 struct rtl_works *rtlworks =
1999 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
2000 struct ieee80211_hw *hw = rtlworks->hw;
2001 struct rtl_priv *rtlpriv = rtl_priv(hw);
2003 rtlpriv->cfg->ops->c2h_command_handle(hw);
2006 void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
2008 struct rtl_priv *rtlpriv = rtl_priv(hw);
2009 unsigned long flags;
2010 struct rtl_c2hcmd *c2hcmd;
2012 c2hcmd = kmalloc(sizeof(*c2hcmd),
2013 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
2018 c2hcmd->val = kmalloc(len,
2019 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
2027 memcpy(c2hcmd->val, val, len);
2030 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2032 list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
2034 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2037 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
2045 RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
2046 "C2H cmd enqueue fail.\n");
2048 EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
2050 void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
2052 struct rtl_priv *rtlpriv = rtl_priv(hw);
2053 unsigned long flags;
2054 struct rtl_c2hcmd *c2hcmd;
2057 for (i = 0; i < 200; i++) {
2058 /* dequeue a task */
2059 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2061 c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
2062 struct rtl_c2hcmd, list);
2065 list_del(&c2hcmd->list);
2067 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2073 if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
2074 rtlpriv->cfg->ops->c2h_content_parsing(hw,
2075 c2hcmd->tag, c2hcmd->len, c2hcmd->val);
2084 void rtl_c2hcmd_wq_callback(void *data)
2086 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2089 struct ieee80211_hw *hw = rtlworks->hw;
2091 rtl_c2hcmd_launcher(hw, 1);
2094 void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
2096 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
2097 struct rtl_priv *rtlpriv = rtl_priv(hw);
2098 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
2100 if (buddy_priv == NULL)
2103 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
2105 /*********************************************************
2107 * frame process functions
2109 *********************************************************/
2110 u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
2112 struct ieee80211_mgmt *mgmt = (void *)data;
2115 pos = (u8 *)mgmt->u.beacon.variable;
2118 if (pos + 2 + pos[1] > end)
2129 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2130 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
2131 static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
2132 enum ieee80211_smps_mode smps,
2135 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2136 struct sk_buff *skb;
2137 struct ieee80211_mgmt *action_frame;
2139 /* 27 = header + category + action + smps mode */
2140 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
2144 skb_reserve(skb, hw->extra_tx_headroom);
2145 action_frame = skb_put_zero(skb, 27);
2146 memcpy(action_frame->da, da, ETH_ALEN);
2147 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
2148 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2149 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2150 IEEE80211_STYPE_ACTION);
2151 action_frame->u.action.category = WLAN_CATEGORY_HT;
2152 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
2154 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
2155 case IEEE80211_SMPS_NUM_MODES:/* 4 */
2157 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
2158 * According to Kernel Code, here is right.
2160 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
2161 action_frame->u.action.u.ht_smps.smps_control =
2162 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
2164 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
2165 action_frame->u.action.u.ht_smps.smps_control =
2166 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
2168 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
2169 action_frame->u.action.u.ht_smps.smps_control =
2170 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
2177 int rtl_send_smps_action(struct ieee80211_hw *hw,
2178 struct ieee80211_sta *sta,
2179 enum ieee80211_smps_mode smps)
2181 struct rtl_priv *rtlpriv = rtl_priv(hw);
2182 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2183 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2184 struct sk_buff *skb = NULL;
2185 struct rtl_tcb_desc tcb_desc;
2186 u8 bssid[ETH_ALEN] = {0};
2188 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
2190 if (rtlpriv->mac80211.act_scanning)
2196 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
2199 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
2202 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
2203 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
2205 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
2207 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
2208 /* this is a type = mgmt * stype = action frame */
2210 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2211 struct rtl_sta_info *sta_entry =
2212 (struct rtl_sta_info *) sta->drv_priv;
2213 sta_entry->mimo_ps = smps;
2214 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
2216 info->control.rates[0].idx = 0;
2217 info->band = hw->conf.chandef.chan->band;
2218 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
2225 EXPORT_SYMBOL(rtl_send_smps_action);
2227 void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
2229 struct rtl_priv *rtlpriv = rtl_priv(hw);
2230 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2231 enum io_type iotype;
2233 if (!is_hal_stop(rtlhal)) {
2234 switch (operation) {
2235 case SCAN_OPT_BACKUP:
2236 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
2237 rtlpriv->cfg->ops->set_hw_reg(hw,
2241 case SCAN_OPT_RESTORE:
2242 iotype = IO_CMD_RESUME_DM_BY_SCAN;
2243 rtlpriv->cfg->ops->set_hw_reg(hw,
2248 pr_err("Unknown Scan Backup operation.\n");
2253 EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
2255 /* because mac80211 have issues when can receive del ba
2256 * so here we just make a fake del_ba if we receive a ba_req
2257 * but rx_agg was opened to let mac80211 release some ba
2258 * related resources, so please this del_ba for tx
2260 struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
2261 u8 *sa, u8 *bssid, u16 tid)
2263 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2264 struct sk_buff *skb;
2265 struct ieee80211_mgmt *action_frame;
2268 /* 27 = header + category + action + smps mode */
2269 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
2273 skb_reserve(skb, hw->extra_tx_headroom);
2274 action_frame = skb_put_zero(skb, 34);
2275 memcpy(action_frame->sa, sa, ETH_ALEN);
2276 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
2277 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2278 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2279 IEEE80211_STYPE_ACTION);
2280 action_frame->u.action.category = WLAN_CATEGORY_BACK;
2281 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
2282 params = (u16)(1 << 11); /* bit 11 initiator */
2283 params |= (u16)(tid << 12); /* bit 15:12 TID number */
2285 action_frame->u.action.u.delba.params = cpu_to_le16(params);
2286 action_frame->u.action.u.delba.reason_code =
2287 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
2292 /*********************************************************
2296 *********************************************************/
2297 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
2298 struct octet_string vendor_ie)
2300 struct rtl_priv *rtlpriv = rtl_priv(hw);
2301 bool matched = false;
2302 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
2303 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
2304 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
2305 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
2306 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
2307 static u8 racap[] = { 0x00, 0x0c, 0x43 };
2308 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
2309 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
2311 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
2312 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
2313 rtlpriv->mac80211.vendor = PEER_ATH;
2315 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
2316 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
2317 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
2318 rtlpriv->mac80211.vendor = PEER_BROAD;
2320 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
2321 rtlpriv->mac80211.vendor = PEER_RAL;
2323 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
2324 rtlpriv->mac80211.vendor = PEER_CISCO;
2326 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
2327 rtlpriv->mac80211.vendor = PEER_MARV;
2334 static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
2337 struct ieee80211_mgmt *mgmt = (void *)data;
2338 struct octet_string vendor_ie;
2341 pos = (u8 *)mgmt->u.beacon.variable;
2344 if (pos[0] == 221) {
2345 vendor_ie.length = pos[1];
2346 vendor_ie.octet = &pos[2];
2347 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
2351 if (pos + 2 + pos[1] > end)
2359 void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2361 struct rtl_priv *rtlpriv = rtl_priv(hw);
2362 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2363 struct ieee80211_hdr *hdr = (void *)data;
2364 u32 vendor = PEER_UNKNOWN;
2366 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2367 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2368 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2369 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2370 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2371 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2372 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2373 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2374 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2375 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2376 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2377 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2378 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2379 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2380 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2381 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2383 if (mac->opmode != NL80211_IFTYPE_STATION)
2386 if (mac->link_state == MAC80211_NOLINK) {
2387 mac->vendor = PEER_UNKNOWN;
2391 if (mac->cnt_after_linked > 2)
2394 /* check if this really is a beacon */
2395 if (!ieee80211_is_beacon(hdr->frame_control))
2398 /* min. beacon length + FCS_LEN */
2399 if (len <= 40 + FCS_LEN)
2402 /* and only beacons from the associated BSSID, please */
2403 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
2406 if (rtl_find_221_ie(hw, data, len))
2407 vendor = mac->vendor;
2409 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2410 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2411 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2412 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2413 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2414 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2415 vendor == PEER_ATH) {
2417 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
2418 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2419 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2420 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2421 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2422 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2423 vendor == PEER_RAL) {
2424 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
2426 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2427 vendor == PEER_CISCO) {
2428 vendor = PEER_CISCO;
2429 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
2430 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2431 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2432 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2433 vendor == PEER_BROAD) {
2434 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
2435 vendor = PEER_BROAD;
2436 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2437 vendor == PEER_MARV) {
2439 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
2442 mac->vendor = vendor;
2444 EXPORT_SYMBOL_GPL(rtl_recognize_peer);
2446 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2447 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2448 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2449 MODULE_LICENSE("GPL");
2450 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2452 struct rtl_global_var rtl_global_var = {};
2453 EXPORT_SYMBOL_GPL(rtl_global_var);
2455 static int __init rtl_core_module_init(void)
2457 if (rtl_rate_control_register())
2458 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2460 /* init some global vars */
2461 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2462 spin_lock_init(&rtl_global_var.glb_list_lock);
2467 static void __exit rtl_core_module_exit(void)
2470 rtl_rate_control_unregister();
2473 module_init(rtl_core_module_init);
2474 module_exit(rtl_core_module_exit);