1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
13 #include <linux/module.h>
14 #include <linux/udp.h>
17 *NOTICE!!!: This file will be very big, we should
18 *keep it clear under following roles:
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
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
36 /*********************************************************
38 * mac80211 init functions
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,},
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,},
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,},
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,},
111 static const struct ieee80211_supported_band rtl_band_2ghz
= {
112 .band
= NL80211_BAND_2GHZ
,
114 .channels
= rtl_channeltable_2g
,
115 .n_channels
= ARRAY_SIZE(rtl_channeltable_2g
),
117 .bitrates
= rtl_ratetable_2g
,
118 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_2g
),
123 static struct ieee80211_supported_band rtl_band_5ghz
= {
124 .band
= NL80211_BAND_5GHZ
,
126 .channels
= rtl_channeltable_5g
,
127 .n_channels
= ARRAY_SIZE(rtl_channeltable_5g
),
129 .bitrates
= rtl_ratetable_5g
,
130 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_5g
),
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 */
146 u8
rtl_tid_to_ac(u8 tid
)
148 return tid_to_ac
[tid
];
150 EXPORT_SYMBOL_GPL(rtl_tid_to_ac
);
152 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
153 struct ieee80211_sta_ht_cap
*ht_cap
)
155 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
156 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
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
;
164 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
165 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
168 *Maximum length of AMPDU that the STA can receive.
169 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
171 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
173 /*Minimum MPDU start spacing , */
174 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
176 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
178 /*hw->wiphy->bands[NL80211_BAND_2GHZ]
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
187 if (rtlpriv
->dm
.supp_phymode_switch
) {
188 pr_info("Support phy mode switch\n");
190 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
191 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
192 ht_cap
->mcs
.rx_mask
[4] = 0x01;
194 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
196 if (get_rf_type(rtlphy
) == RF_1T2R
||
197 get_rf_type(rtlphy
) == RF_2T2R
) {
198 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_DMESG
,
200 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
201 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
202 ht_cap
->mcs
.rx_mask
[4] = 0x01;
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");
209 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
210 ht_cap
->mcs
.rx_mask
[1] = 0x00;
211 ht_cap
->mcs
.rx_mask
[4] = 0x01;
213 ht_cap
->mcs
.rx_highest
=
214 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
219 static void _rtl_init_hw_vht_capab(struct ieee80211_hw
*hw
,
220 struct ieee80211_sta_vht_cap
*vht_cap
)
222 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
223 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
225 if (!(rtlpriv
->cfg
->spec_ver
& RTL_SPEC_SUPPORT_VHT
))
228 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8812AE
||
229 rtlhal
->hw_type
== HARDWARE_TYPE_RTL8822BE
) {
232 vht_cap
->vht_supported
= true;
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
|
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;
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
) {
264 vht_cap
->vht_supported
= true;
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
|
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;
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
);
296 static void _rtl_init_mac80211(struct ieee80211_hw
*hw
)
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
;
304 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&&
305 rtlhal
->bandset
== BAND_ON_BOTH
) {
307 /* <1> use mac->bands as mem for hw->wiphy->bands */
308 sband
= &(rtlmac
->bands
[NL80211_BAND_2GHZ
]);
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
));
315 /* <3> init ht cap base on ant_num */
316 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
318 /* <4> set mac->sband to wiphy->sband */
319 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] = sband
;
322 /* <1> use mac->bands as mem for hw->wiphy->bands */
323 sband
= &(rtlmac
->bands
[NL80211_BAND_5GHZ
]);
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
));
330 /* <3> init ht cap base on ant_num */
331 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
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
;
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
]);
341 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
342 * to default value(1T1R) */
343 memcpy(&(rtlmac
->bands
[NL80211_BAND_2GHZ
]),
345 sizeof(struct ieee80211_supported_band
));
347 /* <3> init ht cap base on ant_num */
348 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
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
]);
356 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
357 * to default value(1T1R) */
358 memcpy(&(rtlmac
->bands
[NL80211_BAND_5GHZ
]),
360 sizeof(struct ieee80211_supported_band
));
362 /* <3> init ht cap base on ant_num */
363 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
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
;
369 pr_err("Err BAND %d\n",
370 rtlhal
->current_bandtype
);
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
);
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
);
387 if (rtlpriv
->psc
.fwctrl_lps
) {
388 ieee80211_hw_set(hw
, SUPPORTS_PS
);
389 ieee80211_hw_set(hw
, SUPPORTS_DYNAMIC_PS
);
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
;
400 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
402 hw
->wiphy
->rts_threshold
= 2347;
405 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
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
);
413 /* wowlan is not supported by kernel if CONFIG_PM is not defined */
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
;
424 hw
->wiphy
->wowlan
= &rtlpriv
->wowlan
;
428 /* <6> mac address */
429 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
430 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
432 u8 rtlmac1
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
434 get_random_bytes((rtlmac1
+ (ETH_ALEN
- 1)), 1);
435 SET_IEEE80211_PERM_ADDR(hw
, rtlmac1
);
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
);
443 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
445 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
448 timer_setup(&rtlpriv
->works
.watchdog_timer
,
449 rtl_watch_dog_timer_callback
, 0);
450 timer_setup(&rtlpriv
->works
.dualmac_easyconcurrent_retrytimer
,
451 rtl_easy_concurrent_retrytimer_callback
, 0);
453 rtlpriv
->works
.hw
= hw
;
454 rtlpriv
->works
.rtl_wq
= alloc_workqueue("%s", 0, 0, rtlpriv
->cfg
->name
);
455 if (unlikely(!rtlpriv
->works
.rtl_wq
)) {
456 pr_err("Failed to allocate work queue\n");
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
);
471 void rtl_deinit_deferred_work(struct ieee80211_hw
*hw
, bool ips_wq
)
473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
475 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
477 cancel_delayed_work_sync(&rtlpriv
->works
.watchdog_wq
);
479 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
481 cancel_delayed_work_sync(&rtlpriv
->works
.ips_nic_off_wq
);
482 cancel_delayed_work_sync(&rtlpriv
->works
.ps_work
);
483 cancel_delayed_work_sync(&rtlpriv
->works
.ps_rfon_wq
);
484 cancel_delayed_work_sync(&rtlpriv
->works
.fwevt_wq
);
485 cancel_delayed_work_sync(&rtlpriv
->works
.c2hcmd_wq
);
487 EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work
);
489 void rtl_init_rfkill(struct ieee80211_hw
*hw
)
491 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
497 /*set init state to on */
498 rtlpriv
->rfkill
.rfkill_state
= true;
499 wiphy_rfkill_set_hw_state(hw
->wiphy
, 0);
501 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
504 pr_info("rtlwifi: wireless switch is %s\n",
505 rtlpriv
->rfkill
.rfkill_state
? "on" : "off");
507 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
509 blocked
= rtlpriv
->rfkill
.rfkill_state
!= 1;
510 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
513 wiphy_rfkill_start_polling(hw
->wiphy
);
515 EXPORT_SYMBOL(rtl_init_rfkill
);
517 void rtl_deinit_rfkill(struct ieee80211_hw
*hw
)
519 wiphy_rfkill_stop_polling(hw
->wiphy
);
521 EXPORT_SYMBOL_GPL(rtl_deinit_rfkill
);
523 int rtl_init_core(struct ieee80211_hw
*hw
)
525 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
526 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
528 /* <1> init mac80211 */
529 _rtl_init_mac80211(hw
);
532 /* <2> rate control register */
533 hw
->rate_control_algorithm
= "rtl_rc";
536 * <3> init CRDA must come after init
537 * mac80211 hw in _rtl_init_mac80211.
539 if (rtl_regd_init(hw
, rtl_reg_notifier
)) {
540 pr_err("REGD init failed\n");
545 mutex_init(&rtlpriv
->locks
.conf_mutex
);
546 mutex_init(&rtlpriv
->locks
.ips_mutex
);
547 mutex_init(&rtlpriv
->locks
.lps_mutex
);
548 spin_lock_init(&rtlpriv
->locks
.irq_th_lock
);
549 spin_lock_init(&rtlpriv
->locks
.h2c_lock
);
550 spin_lock_init(&rtlpriv
->locks
.rf_ps_lock
);
551 spin_lock_init(&rtlpriv
->locks
.rf_lock
);
552 spin_lock_init(&rtlpriv
->locks
.waitq_lock
);
553 spin_lock_init(&rtlpriv
->locks
.entry_list_lock
);
554 spin_lock_init(&rtlpriv
->locks
.c2hcmd_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
);
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
);
565 rtlmac
->link_state
= MAC80211_NOLINK
;
567 /* <6> init deferred work */
568 _rtl_init_deferred_work(hw
);
572 EXPORT_SYMBOL_GPL(rtl_init_core
);
574 static void rtl_free_entries_from_scan_list(struct ieee80211_hw
*hw
);
575 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw
*hw
,
578 void rtl_deinit_core(struct ieee80211_hw
*hw
)
580 rtl_c2hcmd_launcher(hw
, 0);
581 rtl_free_entries_from_scan_list(hw
);
582 rtl_free_entries_from_ack_queue(hw
, false);
584 EXPORT_SYMBOL_GPL(rtl_deinit_core
);
586 void rtl_init_rx_config(struct ieee80211_hw
*hw
)
588 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
589 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
591 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*) (&mac
->rx_conf
));
593 EXPORT_SYMBOL_GPL(rtl_init_rx_config
);
595 /*********************************************************
597 * tx information functions
599 *********************************************************/
600 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
601 struct rtl_tcb_desc
*tcb_desc
,
602 struct ieee80211_tx_info
*info
)
604 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
605 u8 rate_flag
= info
->control
.rates
[0].flags
;
607 tcb_desc
->use_shortpreamble
= false;
609 /* 1M can only use Long Preamble. 11B spec */
610 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
612 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
613 tcb_desc
->use_shortpreamble
= true;
618 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
619 struct ieee80211_sta
*sta
,
620 struct rtl_tcb_desc
*tcb_desc
,
621 struct ieee80211_tx_info
*info
)
623 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
624 u8 rate_flag
= info
->control
.rates
[0].flags
;
625 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
626 u8 sgi_80
= 0, bw_80
= 0;
628 tcb_desc
->use_shortgi
= false;
633 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
634 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
635 sgi_80
= sta
->vht_cap
.cap
& IEEE80211_VHT_CAP_SHORT_GI_80
;
637 if ((!sta
->ht_cap
.ht_supported
) && (!sta
->vht_cap
.vht_supported
))
640 if (!sgi_40
&& !sgi_20
)
643 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
646 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
647 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
648 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
649 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
650 bw_80
= sta
->vht_cap
.vht_supported
;
655 tcb_desc
->use_shortgi
= true;
657 tcb_desc
->use_shortgi
= false;
660 tcb_desc
->use_shortgi
= true;
661 else if (!bw_40
&& sgi_20
)
662 tcb_desc
->use_shortgi
= true;
665 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
666 tcb_desc
->use_shortgi
= false;
669 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
670 struct rtl_tcb_desc
*tcb_desc
,
671 struct ieee80211_tx_info
*info
)
673 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
674 u8 rate_flag
= info
->control
.rates
[0].flags
;
676 /* Common Settings */
677 tcb_desc
->rts_stbc
= false;
678 tcb_desc
->cts_enable
= false;
679 tcb_desc
->rts_sc
= 0;
680 tcb_desc
->rts_bw
= false;
681 tcb_desc
->rts_use_shortpreamble
= false;
682 tcb_desc
->rts_use_shortgi
= false;
684 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
685 /* Use CTS-to-SELF in protection mode. */
686 tcb_desc
->rts_enable
= true;
687 tcb_desc
->cts_enable
= true;
688 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
689 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
690 /* Use RTS-CTS in protection mode. */
691 tcb_desc
->rts_enable
= true;
692 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
696 u8
rtl_mrate_idx_to_arfr_id(struct ieee80211_hw
*hw
, u8 rate_index
,
697 enum wireless_mode wirelessmode
)
699 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
700 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
703 switch (rate_index
) {
704 case RATR_INX_WIRELESS_NGB
:
705 if (rtlphy
->rf_type
== RF_1T1R
)
706 ret
= RATEID_IDX_BGN_40M_1SS
;
708 ret
= RATEID_IDX_BGN_40M_2SS
;
710 case RATR_INX_WIRELESS_N
:
711 case RATR_INX_WIRELESS_NG
:
712 if (rtlphy
->rf_type
== RF_1T1R
)
713 ret
= RATEID_IDX_GN_N1SS
;
715 ret
= RATEID_IDX_GN_N2SS
;
717 case RATR_INX_WIRELESS_NB
:
718 if (rtlphy
->rf_type
== RF_1T1R
)
719 ret
= RATEID_IDX_BGN_20M_1SS_BN
;
721 ret
= RATEID_IDX_BGN_20M_2SS_BN
;
723 case RATR_INX_WIRELESS_GB
:
726 case RATR_INX_WIRELESS_G
:
729 case RATR_INX_WIRELESS_B
:
732 case RATR_INX_WIRELESS_MC
:
733 if (wirelessmode
== WIRELESS_MODE_B
||
734 wirelessmode
== WIRELESS_MODE_G
||
735 wirelessmode
== WIRELESS_MODE_N_24G
||
736 wirelessmode
== WIRELESS_MODE_AC_24G
)
741 case RATR_INX_WIRELESS_AC_5N
:
742 if (rtlphy
->rf_type
== RF_1T1R
)
743 ret
= RATEID_IDX_VHT_1SS
;
745 ret
= RATEID_IDX_VHT_2SS
;
747 case RATR_INX_WIRELESS_AC_24N
:
748 if (rtlphy
->current_chan_bw
== HT_CHANNEL_WIDTH_80
) {
749 if (rtlphy
->rf_type
== RF_1T1R
)
750 ret
= RATEID_IDX_VHT_1SS
;
752 ret
= RATEID_IDX_VHT_2SS
;
754 if (rtlphy
->rf_type
== RF_1T1R
)
755 ret
= RATEID_IDX_MIX1
;
757 ret
= RATEID_IDX_MIX2
;
761 ret
= RATEID_IDX_BGN_40M_2SS
;
766 EXPORT_SYMBOL(rtl_mrate_idx_to_arfr_id
);
768 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
769 struct ieee80211_sta
*sta
,
770 struct rtl_tcb_desc
*tcb_desc
)
772 #define SET_RATE_ID(rate_id) \
773 ({typeof(rate_id) _id = rate_id; \
774 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
775 rtl_mrate_idx_to_arfr_id(hw, _id, \
776 (sta_entry ? sta_entry->wireless_mode : \
777 WIRELESS_MODE_G)) : \
780 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
781 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
782 struct rtl_sta_info
*sta_entry
= NULL
;
783 u8 ratr_index
= SET_RATE_ID(RATR_INX_WIRELESS_MC
);
786 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
787 ratr_index
= sta_entry
->ratr_index
;
789 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
790 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
791 tcb_desc
->ratr_index
= 0;
792 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
||
793 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
794 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
) {
796 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
797 tcb_desc
->use_driver_rate
= 1;
798 tcb_desc
->ratr_index
=
799 SET_RATE_ID(RATR_INX_WIRELESS_MC
);
801 tcb_desc
->ratr_index
= ratr_index
;
803 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
804 tcb_desc
->ratr_index
= ratr_index
;
808 if (rtlpriv
->dm
.useramask
) {
809 tcb_desc
->ratr_index
= ratr_index
;
810 /* TODO we will differentiate adhoc and station future */
811 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
812 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
813 tcb_desc
->mac_id
= 0;
816 (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_NEW_RATEID
))
817 ; /* use sta_entry->ratr_index */
818 else if (mac
->mode
== WIRELESS_MODE_AC_5G
)
819 tcb_desc
->ratr_index
=
820 SET_RATE_ID(RATR_INX_WIRELESS_AC_5N
);
821 else if (mac
->mode
== WIRELESS_MODE_AC_24G
)
822 tcb_desc
->ratr_index
=
823 SET_RATE_ID(RATR_INX_WIRELESS_AC_24N
);
824 else if (mac
->mode
== WIRELESS_MODE_N_24G
)
825 tcb_desc
->ratr_index
=
826 SET_RATE_ID(RATR_INX_WIRELESS_NGB
);
827 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
828 tcb_desc
->ratr_index
=
829 SET_RATE_ID(RATR_INX_WIRELESS_NG
);
830 else if (mac
->mode
& WIRELESS_MODE_G
)
831 tcb_desc
->ratr_index
=
832 SET_RATE_ID(RATR_INX_WIRELESS_GB
);
833 else if (mac
->mode
& WIRELESS_MODE_B
)
834 tcb_desc
->ratr_index
=
835 SET_RATE_ID(RATR_INX_WIRELESS_B
);
836 else if (mac
->mode
& WIRELESS_MODE_A
)
837 tcb_desc
->ratr_index
=
838 SET_RATE_ID(RATR_INX_WIRELESS_G
);
840 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
841 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
844 tcb_desc
->mac_id
= sta
->aid
+ 1;
846 tcb_desc
->mac_id
= 1;
848 tcb_desc
->mac_id
= 0;
855 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
856 struct ieee80211_sta
*sta
,
857 struct rtl_tcb_desc
*tcb_desc
)
859 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
860 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
862 tcb_desc
->packet_bw
= false;
865 if (mac
->opmode
== NL80211_IFTYPE_AP
||
866 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
867 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
868 if (!(sta
->ht_cap
.ht_supported
) ||
869 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
871 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
872 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
875 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
)
878 /*use legency rate, shall use 20MHz */
879 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
882 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_20_40
;
884 if (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_SUPPORT_VHT
) {
885 if (mac
->opmode
== NL80211_IFTYPE_AP
||
886 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
887 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
888 if (!(sta
->vht_cap
.vht_supported
))
890 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
892 !(sta
->vht_cap
.vht_supported
))
895 if (tcb_desc
->hw_rate
<=
896 rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
])
898 tcb_desc
->packet_bw
= HT_CHANNEL_WIDTH_80
;
902 static u8
_rtl_get_vht_highest_n_rate(struct ieee80211_hw
*hw
,
903 struct ieee80211_sta
*sta
)
905 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
906 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
908 u16 tx_mcs_map
= le16_to_cpu(sta
->vht_cap
.vht_mcs
.tx_mcs_map
);
910 if ((get_rf_type(rtlphy
) == RF_2T2R
) &&
911 (tx_mcs_map
& 0x000c) != 0x000c) {
912 if ((tx_mcs_map
& 0x000c) >> 2 ==
913 IEEE80211_VHT_MCS_SUPPORT_0_7
)
915 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS7
];
916 else if ((tx_mcs_map
& 0x000c) >> 2 ==
917 IEEE80211_VHT_MCS_SUPPORT_0_8
)
919 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS8
];
922 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
924 if ((tx_mcs_map
& 0x0003) ==
925 IEEE80211_VHT_MCS_SUPPORT_0_7
)
927 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS7
];
928 else if ((tx_mcs_map
& 0x0003) ==
929 IEEE80211_VHT_MCS_SUPPORT_0_8
)
931 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS8
];
934 rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
940 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
,
941 struct ieee80211_sta
*sta
)
943 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
944 struct rtl_phy
*rtlphy
= &rtlpriv
->phy
;
947 if (get_rf_type(rtlphy
) == RF_2T2R
&&
948 sta
->ht_cap
.mcs
.rx_mask
[1] != 0)
949 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
951 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
956 /* mac80211's rate_idx is like this:
958 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
961 * (rx_status->flag & RX_FLAG_HT) = 0,
962 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
965 * (rx_status->flag & RX_FLAG_HT) = 1,
966 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
968 * 5G band:rx_status->band == NL80211_BAND_5GHZ
970 * (rx_status->flag & RX_FLAG_HT) = 0,
971 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
974 * (rx_status->flag & RX_FLAG_HT) = 1,
975 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
978 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
979 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
981 int rtlwifi_rate_mapping(struct ieee80211_hw
*hw
, bool isht
, bool isvht
,
988 case DESC_RATEVHT1SS_MCS0
:
991 case DESC_RATEVHT1SS_MCS1
:
994 case DESC_RATEVHT1SS_MCS2
:
997 case DESC_RATEVHT1SS_MCS3
:
1000 case DESC_RATEVHT1SS_MCS4
:
1003 case DESC_RATEVHT1SS_MCS5
:
1006 case DESC_RATEVHT1SS_MCS6
:
1009 case DESC_RATEVHT1SS_MCS7
:
1012 case DESC_RATEVHT1SS_MCS8
:
1015 case DESC_RATEVHT1SS_MCS9
:
1018 case DESC_RATEVHT2SS_MCS0
:
1021 case DESC_RATEVHT2SS_MCS1
:
1024 case DESC_RATEVHT2SS_MCS2
:
1027 case DESC_RATEVHT2SS_MCS3
:
1030 case DESC_RATEVHT2SS_MCS4
:
1033 case DESC_RATEVHT2SS_MCS5
:
1036 case DESC_RATEVHT2SS_MCS6
:
1039 case DESC_RATEVHT2SS_MCS7
:
1042 case DESC_RATEVHT2SS_MCS8
:
1045 case DESC_RATEVHT2SS_MCS9
:
1054 if (false == isht
) {
1055 if (NL80211_BAND_2GHZ
== hw
->conf
.chandef
.chan
->band
) {
1056 switch (desc_rate
) {
1098 switch (desc_rate
) {
1129 switch (desc_rate
) {
1160 case DESC_RATEMCS10
:
1163 case DESC_RATEMCS11
:
1166 case DESC_RATEMCS12
:
1169 case DESC_RATEMCS13
:
1172 case DESC_RATEMCS14
:
1175 case DESC_RATEMCS15
:
1185 EXPORT_SYMBOL(rtlwifi_rate_mapping
);
1187 static u8
_rtl_get_tx_hw_rate(struct ieee80211_hw
*hw
,
1188 struct ieee80211_tx_info
*info
)
1190 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1191 struct ieee80211_tx_rate
*r
= &info
->status
.rates
[0];
1192 struct ieee80211_rate
*txrate
;
1195 if (r
->flags
& IEEE80211_TX_RC_MCS
) {
1197 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
] - 15 +
1199 } else if (r
->flags
& IEEE80211_TX_RC_VHT_MCS
) {
1200 /* VHT MCS0-9, NSS */
1201 if (ieee80211_rate_get_vht_nss(r
) == 2)
1202 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_2SS_MCS9
];
1204 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_VHT_RATE_1SS_MCS9
];
1206 hw_value
= hw_value
- 9 + ieee80211_rate_get_vht_mcs(r
);
1209 txrate
= ieee80211_get_tx_rate(hw
, info
);
1212 hw_value
= txrate
->hw_value
;
1216 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_5G
&&
1217 hw_value
< rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE6M
])
1218 hw_value
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE6M
];
1223 void rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
1224 struct ieee80211_tx_info
*info
,
1225 struct ieee80211_sta
*sta
,
1226 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
1228 #define SET_RATE_ID(rate_id) \
1229 ({typeof(rate_id) _id = rate_id; \
1230 ((rtlpriv->cfg->spec_ver & RTL_SPEC_NEW_RATEID) ? \
1231 rtl_mrate_idx_to_arfr_id(hw, _id, \
1232 (sta_entry ? sta_entry->wireless_mode : \
1233 WIRELESS_MODE_G)) : \
1236 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1237 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
1238 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1239 struct rtl_sta_info
*sta_entry
=
1240 (sta
? (struct rtl_sta_info
*)sta
->drv_priv
: NULL
);
1242 __le16 fc
= rtl_get_fc(skb
);
1244 tcb_desc
->hw_rate
= _rtl_get_tx_hw_rate(hw
, info
);
1246 if (rtl_is_tx_report_skb(hw
, skb
))
1247 tcb_desc
->use_spe_rpt
= 1;
1249 if (ieee80211_is_data(fc
)) {
1251 *we set data rate INX 0
1252 *in rtl_rc.c if skb is special data or
1253 *mgt which need low data rate.
1257 *So tcb_desc->hw_rate is just used for
1258 *special data and mgt frames
1260 if (info
->control
.rates
[0].idx
== 0 ||
1261 ieee80211_is_nullfunc(fc
)) {
1262 tcb_desc
->use_driver_rate
= true;
1263 tcb_desc
->ratr_index
=
1264 SET_RATE_ID(RATR_INX_WIRELESS_MC
);
1266 tcb_desc
->disable_ratefallback
= 1;
1269 *because hw will nerver use hw_rate
1270 *when tcb_desc->use_driver_rate = false
1271 *so we never set highest N rate here,
1272 *and N rate will all be controlled by FW
1273 *when tcb_desc->use_driver_rate = false
1275 if (sta
&& sta
->vht_cap
.vht_supported
) {
1277 _rtl_get_vht_highest_n_rate(hw
, sta
);
1279 if (sta
&& sta
->ht_cap
.ht_supported
) {
1281 _rtl_get_highest_n_rate(hw
, sta
);
1283 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
1285 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
1288 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
1294 if (is_multicast_ether_addr(hdr
->addr1
))
1295 tcb_desc
->multicast
= 1;
1296 else if (is_broadcast_ether_addr(hdr
->addr1
))
1297 tcb_desc
->broadcast
= 1;
1299 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
1300 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
1301 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
1302 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
1303 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
1305 tcb_desc
->use_driver_rate
= true;
1306 tcb_desc
->ratr_index
= SET_RATE_ID(RATR_INX_WIRELESS_MC
);
1307 tcb_desc
->disable_ratefallback
= 1;
1308 tcb_desc
->mac_id
= 0;
1309 tcb_desc
->packet_bw
= false;
1313 EXPORT_SYMBOL(rtl_get_tcb_desc
);
1315 bool rtl_tx_mgmt_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1317 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1318 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1319 __le16 fc
= rtl_get_fc(skb
);
1321 if (rtlpriv
->dm
.supp_phymode_switch
&&
1322 mac
->link_state
< MAC80211_LINKED
&&
1323 (ieee80211_is_auth(fc
) || ieee80211_is_probe_req(fc
))) {
1324 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1325 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1327 if (ieee80211_is_auth(fc
)) {
1328 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_DMESG
, "MAC80211_LINKING\n");
1330 mac
->link_state
= MAC80211_LINKING
;
1332 rtlpriv
->phy
.need_iqk
= true;
1338 EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc
);
1340 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
, u8
*sa
,
1341 u8
*bssid
, u16 tid
);
1343 static void process_agg_start(struct ieee80211_hw
*hw
,
1344 struct ieee80211_hdr
*hdr
, u16 tid
)
1346 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1347 struct ieee80211_rx_status rx_status
= { 0 };
1348 struct sk_buff
*skb_delba
= NULL
;
1350 skb_delba
= rtl_make_del_ba(hw
, hdr
->addr2
, hdr
->addr3
, tid
);
1352 rx_status
.freq
= hw
->conf
.chandef
.chan
->center_freq
;
1353 rx_status
.band
= hw
->conf
.chandef
.chan
->band
;
1354 rx_status
.flag
|= RX_FLAG_DECRYPTED
;
1355 rx_status
.flag
|= RX_FLAG_MACTIME_START
;
1356 rx_status
.rate_idx
= 0;
1357 rx_status
.signal
= 50 + 10;
1358 memcpy(IEEE80211_SKB_RXCB(skb_delba
),
1359 &rx_status
, sizeof(rx_status
));
1360 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_DMESG
,
1364 ieee80211_rx_irqsafe(hw
, skb_delba
);
1368 bool rtl_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
1370 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1371 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
1372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1373 __le16 fc
= rtl_get_fc(skb
);
1374 u8
*act
= (u8
*)(((u8
*)skb
->data
+ MAC80211_3ADDR_LEN
));
1377 if (!ieee80211_is_action(fc
))
1386 if (mac
->act_scanning
)
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
);
1395 struct ieee80211_sta
*sta
= NULL
;
1396 struct rtl_sta_info
*sta_entry
= NULL
;
1397 struct rtl_tid_data
*tid_data
;
1398 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1399 u16 capab
= 0, tid
= 0;
1402 sta
= rtl_find_sta(hw
, hdr
->addr3
);
1404 rtl_dbg(rtlpriv
, COMP_SEND
| COMP_RECV
,
1405 DBG_DMESG
, "sta is NULL\n");
1411 (struct rtl_sta_info
*)sta
->drv_priv
;
1417 le16_to_cpu(mgmt
->u
.action
.u
.addba_req
.capab
);
1419 IEEE80211_ADDBA_PARAM_TID_MASK
) >> 2;
1420 if (tid
>= MAX_TID_COUNT
) {
1424 tid_data
= &sta_entry
->tids
[tid
];
1425 if (tid_data
->agg
.rx_agg_state
==
1427 process_agg_start(hw
, hdr
, tid
);
1432 rtl_dbg(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1433 "%s ACT_ADDBARSP From :%pM\n",
1434 is_tx
? "Tx" : "Rx", hdr
->addr2
);
1437 rtl_dbg(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1438 "ACT_ADDBADEL From :%pM\n", hdr
->addr2
);
1448 EXPORT_SYMBOL_GPL(rtl_action_proc
);
1450 static void setup_special_tx(struct rtl_priv
*rtlpriv
, struct rtl_ps_ctl
*ppsc
,
1453 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
1455 rtlpriv
->ra
.is_special_data
= true;
1456 if (rtlpriv
->cfg
->ops
->get_btc_status())
1457 rtlpriv
->btcoexist
.btc_ops
->btc_special_packet_notify(
1459 rtl_lps_leave(hw
, false);
1460 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1463 static const u8
*rtl_skb_ether_type_ptr(struct ieee80211_hw
*hw
,
1464 struct sk_buff
*skb
, bool is_enc
)
1466 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1467 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
1468 u8 encrypt_header_len
= 0;
1471 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1472 case WEP40_ENCRYPTION
:
1473 case WEP104_ENCRYPTION
:
1474 encrypt_header_len
= 4;/*WEP_IV_LEN*/
1476 case TKIP_ENCRYPTION
:
1477 encrypt_header_len
= 8;/*TKIP_IV_LEN*/
1479 case AESCCMP_ENCRYPTION
:
1480 encrypt_header_len
= 8;/*CCMP_HDR_LEN;*/
1486 offset
= mac_hdr_len
+ SNAP_SIZE
;
1488 offset
+= encrypt_header_len
;
1490 return skb
->data
+ offset
;
1493 /*should call before software enc*/
1494 u8
rtl_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
,
1497 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1498 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1499 __le16 fc
= rtl_get_fc(skb
);
1501 const u8
*ether_type_ptr
;
1502 const struct iphdr
*ip
;
1504 if (!ieee80211_is_data(fc
))
1507 ether_type_ptr
= rtl_skb_ether_type_ptr(hw
, skb
, is_enc
);
1508 ether_type
= be16_to_cpup((__be16
*)ether_type_ptr
);
1510 if (ETH_P_IP
== ether_type
) {
1511 ip
= (struct iphdr
*)((u8
*)ether_type_ptr
+
1513 if (IPPROTO_UDP
== ip
->protocol
) {
1514 struct udphdr
*udp
= (struct udphdr
*)((u8
*)ip
+
1516 if (((((u8
*)udp
)[1] == 68) &&
1517 (((u8
*)udp
)[3] == 67)) ||
1518 ((((u8
*)udp
)[1] == 67) &&
1519 (((u8
*)udp
)[3] == 68))) {
1520 /* 68 : UDP BOOTP client
1521 * 67 : UDP BOOTP server
1523 rtl_dbg(rtlpriv
, (COMP_SEND
| COMP_RECV
),
1524 DBG_DMESG
, "dhcp %s !!\n",
1525 (is_tx
) ? "Tx" : "Rx");
1528 setup_special_tx(rtlpriv
, ppsc
,
1534 } else if (ETH_P_ARP
== ether_type
) {
1536 setup_special_tx(rtlpriv
, ppsc
, PACKET_ARP
);
1539 } else if (ETH_P_PAE
== ether_type
) {
1540 /* EAPOL is seens as in-4way */
1541 rtlpriv
->btcoexist
.btc_info
.in_4way
= true;
1542 rtlpriv
->btcoexist
.btc_info
.in_4way_ts
= jiffies
;
1544 rtl_dbg(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
1545 "802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx");
1548 rtlpriv
->ra
.is_special_data
= true;
1549 rtl_lps_leave(hw
, false);
1550 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1552 setup_special_tx(rtlpriv
, ppsc
, PACKET_EAPOL
);
1556 } else if (ETH_P_IPV6
== ether_type
) {
1557 /* TODO: Handle any IPv6 cases that need special handling.
1558 * For now, always return false
1564 rtlpriv
->ra
.is_special_data
= false;
1567 EXPORT_SYMBOL_GPL(rtl_is_special_data
);
1569 void rtl_tx_ackqueue(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1571 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1572 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1574 __skb_queue_tail(&tx_report
->queue
, skb
);
1576 EXPORT_SYMBOL_GPL(rtl_tx_ackqueue
);
1578 static void rtl_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
1581 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1582 struct ieee80211_tx_info
*info
;
1584 info
= IEEE80211_SKB_CB(skb
);
1585 ieee80211_tx_info_clear_status(info
);
1587 rtl_dbg(rtlpriv
, COMP_TX_REPORT
, DBG_LOUD
,
1588 "tx report: ack\n");
1589 info
->flags
|= IEEE80211_TX_STAT_ACK
;
1591 rtl_dbg(rtlpriv
, COMP_TX_REPORT
, DBG_LOUD
,
1592 "tx report: not ack\n");
1593 info
->flags
&= ~IEEE80211_TX_STAT_ACK
;
1595 ieee80211_tx_status_irqsafe(hw
, skb
);
1598 bool rtl_is_tx_report_skb(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1601 const u8
*ether_type_ptr
;
1602 __le16 fc
= rtl_get_fc(skb
);
1604 ether_type_ptr
= rtl_skb_ether_type_ptr(hw
, skb
, true);
1605 ether_type
= be16_to_cpup((__be16
*)ether_type_ptr
);
1607 if (ether_type
== ETH_P_PAE
|| ieee80211_is_nullfunc(fc
))
1613 static u16
rtl_get_tx_report_sn(struct ieee80211_hw
*hw
,
1614 struct rtlwifi_tx_info
*tx_info
)
1616 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1617 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1620 /* SW_DEFINE[11:8] are reserved (driver fills zeros)
1621 * SW_DEFINE[7:2] are used by driver
1622 * SW_DEFINE[1:0] are reserved for firmware (driver fills zeros)
1624 sn
= (atomic_inc_return(&tx_report
->sn
) & 0x003F) << 2;
1626 tx_report
->last_sent_sn
= sn
;
1627 tx_report
->last_sent_time
= jiffies
;
1629 tx_info
->send_time
= tx_report
->last_sent_time
;
1630 rtl_dbg(rtlpriv
, COMP_TX_REPORT
, DBG_DMESG
,
1631 "Send TX-Report sn=0x%X\n", sn
);
1636 void rtl_set_tx_report(struct rtl_tcb_desc
*ptcb_desc
, u8
*pdesc
,
1637 struct ieee80211_hw
*hw
, struct rtlwifi_tx_info
*tx_info
)
1639 if (ptcb_desc
->use_spe_rpt
) {
1640 u16 sn
= rtl_get_tx_report_sn(hw
, tx_info
);
1642 SET_TX_DESC_SPE_RPT(pdesc
, 1);
1643 SET_TX_DESC_SW_DEFINE(pdesc
, sn
);
1646 EXPORT_SYMBOL_GPL(rtl_set_tx_report
);
1648 void rtl_tx_report_handler(struct ieee80211_hw
*hw
, u8
*tmp_buf
, u8 c2h_cmd_len
)
1650 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1651 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1652 struct rtlwifi_tx_info
*tx_info
;
1653 struct sk_buff_head
*queue
= &tx_report
->queue
;
1654 struct sk_buff
*skb
;
1658 if (rtlpriv
->cfg
->spec_ver
& RTL_SPEC_EXT_C2H
) {
1659 sn
= GET_TX_REPORT_SN_V2(tmp_buf
);
1660 st
= GET_TX_REPORT_ST_V2(tmp_buf
);
1661 retry
= GET_TX_REPORT_RETRY_V2(tmp_buf
);
1663 sn
= GET_TX_REPORT_SN_V1(tmp_buf
);
1664 st
= GET_TX_REPORT_ST_V1(tmp_buf
);
1665 retry
= GET_TX_REPORT_RETRY_V1(tmp_buf
);
1668 tx_report
->last_recv_sn
= sn
;
1670 skb_queue_walk(queue
, skb
) {
1671 tx_info
= rtl_tx_skb_cb_info(skb
);
1672 if (tx_info
->sn
== sn
) {
1673 skb_unlink(skb
, queue
);
1674 rtl_tx_status(hw
, skb
, st
== 0);
1678 rtl_dbg(rtlpriv
, COMP_TX_REPORT
, DBG_DMESG
,
1679 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1682 EXPORT_SYMBOL_GPL(rtl_tx_report_handler
);
1684 bool rtl_check_tx_report_acked(struct ieee80211_hw
*hw
)
1686 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1687 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1689 if (tx_report
->last_sent_sn
== tx_report
->last_recv_sn
)
1692 if (time_before(tx_report
->last_sent_time
+ 3 * HZ
, jiffies
)) {
1693 rtl_dbg(rtlpriv
, COMP_TX_REPORT
, DBG_WARNING
,
1694 "Check TX-Report timeout!! s_sn=0x%X r_sn=0x%X\n",
1695 tx_report
->last_sent_sn
, tx_report
->last_recv_sn
);
1696 return true; /* 3 sec. (timeout) seen as acked */
1702 void rtl_wait_tx_report_acked(struct ieee80211_hw
*hw
, u32 wait_ms
)
1704 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1707 for (i
= 0; i
< wait_ms
; i
++) {
1708 if (rtl_check_tx_report_acked(hw
))
1710 usleep_range(1000, 2000);
1711 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1712 "Wait 1ms (%d/%d) to disable key.\n", i
, wait_ms
);
1716 u32
rtl_get_hal_edca_param(struct ieee80211_hw
*hw
,
1717 struct ieee80211_vif
*vif
,
1718 enum wireless_mode wirelessmode
,
1719 struct ieee80211_tx_queue_params
*param
)
1725 /* AIFS = AIFSN * slot time + SIFS */
1726 switch (wirelessmode
) {
1727 case WIRELESS_MODE_A
:
1728 case WIRELESS_MODE_N_24G
:
1729 case WIRELESS_MODE_N_5G
:
1730 case WIRELESS_MODE_AC_5G
:
1731 case WIRELESS_MODE_AC_24G
:
1735 case WIRELESS_MODE_G
:
1736 slottime
= (vif
->bss_conf
.use_short_slot
? 9 : 20);
1742 reg
|= (param
->txop
& 0x7FF) << 16;
1743 reg
|= (fls(param
->cw_max
) & 0xF) << 12;
1744 reg
|= (fls(param
->cw_min
) & 0xF) << 8;
1745 reg
|= (param
->aifs
& 0x0F) * slottime
+ sifstime
;
1749 EXPORT_SYMBOL_GPL(rtl_get_hal_edca_param
);
1751 /*********************************************************
1753 * functions called by core.c
1755 *********************************************************/
1756 int rtl_tx_agg_start(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1757 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1759 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1760 struct rtl_tid_data
*tid_data
;
1761 struct rtl_sta_info
*sta_entry
= NULL
;
1766 if (unlikely(tid
>= MAX_TID_COUNT
))
1769 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1772 tid_data
= &sta_entry
->tids
[tid
];
1774 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1775 "on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1778 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1780 return IEEE80211_AMPDU_TX_START_IMMEDIATE
;
1783 int rtl_tx_agg_stop(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1784 struct ieee80211_sta
*sta
, u16 tid
)
1786 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1787 struct rtl_sta_info
*sta_entry
= NULL
;
1792 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1793 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1795 if (unlikely(tid
>= MAX_TID_COUNT
))
1798 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1799 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1801 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1805 int rtl_rx_agg_start(struct ieee80211_hw
*hw
,
1806 struct ieee80211_sta
*sta
, u16 tid
)
1808 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1809 struct rtl_tid_data
*tid_data
;
1810 struct rtl_sta_info
*sta_entry
= NULL
;
1816 if (unlikely(tid
>= MAX_TID_COUNT
))
1819 if (rtlpriv
->cfg
->ops
->get_btc_status()) {
1820 rtlpriv
->btcoexist
.btc_ops
->btc_get_ampdu_cfg(rtlpriv
,
1827 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1830 tid_data
= &sta_entry
->tids
[tid
];
1832 rtl_dbg(rtlpriv
, COMP_RECV
, DBG_DMESG
,
1833 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1835 tid_data
->agg
.rx_agg_state
= RTL_RX_AGG_START
;
1839 int rtl_rx_agg_stop(struct ieee80211_hw
*hw
,
1840 struct ieee80211_sta
*sta
, u16 tid
)
1842 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1843 struct rtl_sta_info
*sta_entry
= NULL
;
1848 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1849 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1851 if (unlikely(tid
>= MAX_TID_COUNT
))
1854 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1855 sta_entry
->tids
[tid
].agg
.rx_agg_state
= RTL_RX_AGG_STOP
;
1860 int rtl_tx_agg_oper(struct ieee80211_hw
*hw
,
1861 struct ieee80211_sta
*sta
, u16 tid
)
1863 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1864 struct rtl_sta_info
*sta_entry
= NULL
;
1869 rtl_dbg(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1870 "on ra = %pM tid = %d\n", sta
->addr
, tid
);
1872 if (unlikely(tid
>= MAX_TID_COUNT
))
1875 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1876 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1881 void rtl_rx_ampdu_apply(struct rtl_priv
*rtlpriv
)
1883 struct rtl_btc_ops
*btc_ops
= rtlpriv
->btcoexist
.btc_ops
;
1884 u8 reject_agg
= 0, ctrl_agg_size
= 0, agg_size
= 0;
1886 if (rtlpriv
->cfg
->ops
->get_btc_status())
1887 btc_ops
->btc_get_ampdu_cfg(rtlpriv
, &reject_agg
,
1888 &ctrl_agg_size
, &agg_size
);
1890 rtl_dbg(rtlpriv
, COMP_BT_COEXIST
, DBG_DMESG
,
1891 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1892 reject_agg
, ctrl_agg_size
, agg_size
);
1894 rtlpriv
->hw
->max_rx_aggregation_subframes
=
1895 (ctrl_agg_size
? agg_size
: IEEE80211_MAX_AMPDU_BUF_HT
);
1897 EXPORT_SYMBOL(rtl_rx_ampdu_apply
);
1899 /*********************************************************
1901 * wq & timer callback functions
1903 *********************************************************/
1904 /* this function is used for roaming */
1905 void rtl_beacon_statistic(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1907 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1908 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1910 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
1913 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
1916 /* check if this really is a beacon */
1917 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
1918 !ieee80211_is_probe_resp(hdr
->frame_control
))
1921 /* min. beacon length + FCS_LEN */
1922 if (skb
->len
<= 40 + FCS_LEN
)
1925 /* and only beacons from the associated BSSID, please */
1926 if (!ether_addr_equal(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1929 rtlpriv
->link_info
.bcn_rx_inperiod
++;
1931 EXPORT_SYMBOL_GPL(rtl_beacon_statistic
);
1933 static void rtl_free_entries_from_scan_list(struct ieee80211_hw
*hw
)
1935 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1936 struct rtl_bssid_entry
*entry
, *next
;
1938 list_for_each_entry_safe(entry
, next
, &rtlpriv
->scan_list
.list
, list
) {
1939 list_del(&entry
->list
);
1941 rtlpriv
->scan_list
.num
--;
1945 static void rtl_free_entries_from_ack_queue(struct ieee80211_hw
*hw
,
1948 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1949 struct rtl_tx_report
*tx_report
= &rtlpriv
->tx_report
;
1950 struct sk_buff_head
*queue
= &tx_report
->queue
;
1951 struct sk_buff
*skb
, *tmp
;
1952 struct rtlwifi_tx_info
*tx_info
;
1954 skb_queue_walk_safe(queue
, skb
, tmp
) {
1955 tx_info
= rtl_tx_skb_cb_info(skb
);
1957 time_after(tx_info
->send_time
+ HZ
, jiffies
))
1959 skb_unlink(skb
, queue
);
1960 rtl_tx_status(hw
, skb
, false);
1964 void rtl_scan_list_expire(struct ieee80211_hw
*hw
)
1966 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1967 struct rtl_bssid_entry
*entry
, *next
;
1968 unsigned long flags
;
1970 spin_lock_irqsave(&rtlpriv
->locks
.scan_list_lock
, flags
);
1972 list_for_each_entry_safe(entry
, next
, &rtlpriv
->scan_list
.list
, list
) {
1974 if (jiffies_to_msecs(jiffies
- entry
->age
) < 180000)
1977 list_del(&entry
->list
);
1978 rtlpriv
->scan_list
.num
--;
1980 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
1981 "BSSID=%pM is expire in scan list (total=%d)\n",
1982 entry
->bssid
, rtlpriv
->scan_list
.num
);
1986 spin_unlock_irqrestore(&rtlpriv
->locks
.scan_list_lock
, flags
);
1988 rtlpriv
->btcoexist
.btc_info
.ap_num
= rtlpriv
->scan_list
.num
;
1991 void rtl_collect_scan_list(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1993 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1994 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1995 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1996 unsigned long flags
;
1998 struct rtl_bssid_entry
*entry
;
1999 bool entry_found
= false;
2001 /* check if it is scanning */
2002 if (!mac
->act_scanning
)
2005 /* check if this really is a beacon */
2006 if (!ieee80211_is_beacon(hdr
->frame_control
) &&
2007 !ieee80211_is_probe_resp(hdr
->frame_control
))
2010 spin_lock_irqsave(&rtlpriv
->locks
.scan_list_lock
, flags
);
2012 list_for_each_entry(entry
, &rtlpriv
->scan_list
.list
, list
) {
2013 if (memcmp(entry
->bssid
, hdr
->addr3
, ETH_ALEN
) == 0) {
2014 list_del_init(&entry
->list
);
2016 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
2017 "Update BSSID=%pM to scan list (total=%d)\n",
2018 hdr
->addr3
, rtlpriv
->scan_list
.num
);
2024 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
2029 memcpy(entry
->bssid
, hdr
->addr3
, ETH_ALEN
);
2030 rtlpriv
->scan_list
.num
++;
2032 rtl_dbg(rtlpriv
, COMP_SCAN
, DBG_LOUD
,
2033 "Add BSSID=%pM to scan list (total=%d)\n",
2034 hdr
->addr3
, rtlpriv
->scan_list
.num
);
2037 entry
->age
= jiffies
;
2039 list_add_tail(&entry
->list
, &rtlpriv
->scan_list
.list
);
2042 spin_unlock_irqrestore(&rtlpriv
->locks
.scan_list_lock
, flags
);
2044 EXPORT_SYMBOL(rtl_collect_scan_list
);
2046 static void rtl_watchdog_wq_callback(struct work_struct
*work
)
2048 struct rtl_works
*rtlworks
= container_of(work
, struct rtl_works
,
2050 struct ieee80211_hw
*hw
= rtlworks
->hw
;
2051 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2052 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2053 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2054 bool busytraffic
= false;
2055 bool tx_busy_traffic
= false;
2056 bool rx_busy_traffic
= false;
2057 bool higher_busytraffic
= false;
2058 bool higher_busyrxtraffic
= false;
2060 u32 rx_cnt_inp4eriod
= 0;
2061 u32 tx_cnt_inp4eriod
= 0;
2062 u32 aver_rx_cnt_inperiod
= 0;
2063 u32 aver_tx_cnt_inperiod
= 0;
2064 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
2065 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
2067 if (is_hal_stop(rtlhal
))
2070 /* <1> Determine if action frame is allowed */
2071 if (mac
->link_state
> MAC80211_NOLINK
) {
2072 if (mac
->cnt_after_linked
< 20)
2073 mac
->cnt_after_linked
++;
2075 mac
->cnt_after_linked
= 0;
2078 /* <2> to check if traffic busy, if
2079 * busytraffic we don't change channel
2081 if (mac
->link_state
>= MAC80211_LINKED
) {
2082 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
2083 for (idx
= 0; idx
<= 2; idx
++) {
2084 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
2085 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
2086 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
2087 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
2089 rtlpriv
->link_info
.num_rx_in4period
[3] =
2090 rtlpriv
->link_info
.num_rx_inperiod
;
2091 rtlpriv
->link_info
.num_tx_in4period
[3] =
2092 rtlpriv
->link_info
.num_tx_inperiod
;
2093 for (idx
= 0; idx
<= 3; idx
++) {
2095 rtlpriv
->link_info
.num_rx_in4period
[idx
];
2097 rtlpriv
->link_info
.num_tx_in4period
[idx
];
2099 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
2100 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
2102 /* (2) check traffic busy */
2103 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100) {
2105 if (aver_rx_cnt_inperiod
> aver_tx_cnt_inperiod
)
2106 rx_busy_traffic
= true;
2108 tx_busy_traffic
= false;
2111 /* Higher Tx/Rx data. */
2112 if (aver_rx_cnt_inperiod
> 4000 ||
2113 aver_tx_cnt_inperiod
> 4000) {
2114 higher_busytraffic
= true;
2116 /* Extremely high Rx data. */
2117 if (aver_rx_cnt_inperiod
> 5000)
2118 higher_busyrxtraffic
= true;
2121 /* check every tid's tx traffic */
2122 for (tid
= 0; tid
<= 7; tid
++) {
2123 for (idx
= 0; idx
<= 2; idx
++)
2124 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
2125 rtlpriv
->link_info
.tidtx_in4period
[tid
]
2127 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
2128 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
2130 for (idx
= 0; idx
<= 3; idx
++)
2131 tidtx_inp4eriod
[tid
] +=
2132 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
2133 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
2134 if (aver_tidtx_inperiod
[tid
] > 5000)
2135 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
2138 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
2142 /* PS is controlled by coex. */
2143 if (rtlpriv
->cfg
->ops
->get_btc_status() &&
2144 rtlpriv
->btcoexist
.btc_ops
->btc_is_bt_ctrl_lps(rtlpriv
))
2145 goto label_lps_done
;
2147 if (rtlpriv
->link_info
.num_rx_inperiod
+
2148 rtlpriv
->link_info
.num_tx_inperiod
> 8 ||
2149 rtlpriv
->link_info
.num_rx_inperiod
> 2)
2150 rtl_lps_leave(hw
, true);
2152 rtl_lps_enter(hw
, true);
2158 for (tid
= 0; tid
<= 7; tid
++)
2159 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
2161 rtlpriv
->link_info
.busytraffic
= busytraffic
;
2162 rtlpriv
->link_info
.higher_busytraffic
= higher_busytraffic
;
2163 rtlpriv
->link_info
.rx_busy_traffic
= rx_busy_traffic
;
2164 rtlpriv
->link_info
.tx_busy_traffic
= tx_busy_traffic
;
2165 rtlpriv
->link_info
.higher_busyrxtraffic
= higher_busyrxtraffic
;
2167 rtlpriv
->stats
.txbytesunicast_inperiod
=
2168 rtlpriv
->stats
.txbytesunicast
-
2169 rtlpriv
->stats
.txbytesunicast_last
;
2170 rtlpriv
->stats
.rxbytesunicast_inperiod
=
2171 rtlpriv
->stats
.rxbytesunicast
-
2172 rtlpriv
->stats
.rxbytesunicast_last
;
2173 rtlpriv
->stats
.txbytesunicast_last
= rtlpriv
->stats
.txbytesunicast
;
2174 rtlpriv
->stats
.rxbytesunicast_last
= rtlpriv
->stats
.rxbytesunicast
;
2176 rtlpriv
->stats
.txbytesunicast_inperiod_tp
=
2177 (u32
)(rtlpriv
->stats
.txbytesunicast_inperiod
* 8 / 2 /
2179 rtlpriv
->stats
.rxbytesunicast_inperiod_tp
=
2180 (u32
)(rtlpriv
->stats
.rxbytesunicast_inperiod
* 8 / 2 /
2184 if (!rtlpriv
->cfg
->mod_params
->disable_watchdog
)
2185 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
2188 if (mac
->link_state
== MAC80211_LINKED
&&
2189 mac
->opmode
== NL80211_IFTYPE_STATION
) {
2190 if ((rtlpriv
->link_info
.bcn_rx_inperiod
+
2191 rtlpriv
->link_info
.num_rx_inperiod
) == 0) {
2192 rtlpriv
->link_info
.roam_times
++;
2193 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_DMESG
,
2194 "AP off for %d s\n",
2195 (rtlpriv
->link_info
.roam_times
* 2));
2197 /* if we can't recv beacon for 10s,
2198 * we should reconnect this AP
2200 if (rtlpriv
->link_info
.roam_times
>= 5) {
2201 pr_err("AP off, try to reconnect now\n");
2202 rtlpriv
->link_info
.roam_times
= 0;
2203 ieee80211_connection_loss(
2204 rtlpriv
->mac80211
.vif
);
2207 rtlpriv
->link_info
.roam_times
= 0;
2211 if (rtlpriv
->cfg
->ops
->get_btc_status())
2212 rtlpriv
->btcoexist
.btc_ops
->btc_periodical(rtlpriv
);
2214 if (rtlpriv
->btcoexist
.btc_info
.in_4way
) {
2215 if (time_after(jiffies
, rtlpriv
->btcoexist
.btc_info
.in_4way_ts
+
2216 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME
)))
2217 rtlpriv
->btcoexist
.btc_info
.in_4way
= false;
2220 rtlpriv
->link_info
.num_rx_inperiod
= 0;
2221 rtlpriv
->link_info
.num_tx_inperiod
= 0;
2222 rtlpriv
->link_info
.bcn_rx_inperiod
= 0;
2225 rtl_scan_list_expire(hw
);
2227 /* <7> check ack queue */
2228 rtl_free_entries_from_ack_queue(hw
, true);
2231 void rtl_watch_dog_timer_callback(struct timer_list
*t
)
2233 struct rtl_priv
*rtlpriv
= from_timer(rtlpriv
, t
, works
.watchdog_timer
);
2235 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
2236 &rtlpriv
->works
.watchdog_wq
, 0);
2238 mod_timer(&rtlpriv
->works
.watchdog_timer
,
2239 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
2242 static void rtl_fwevt_wq_callback(struct work_struct
*work
)
2244 struct rtl_works
*rtlworks
= container_of(work
, struct rtl_works
,
2246 struct ieee80211_hw
*hw
= rtlworks
->hw
;
2247 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2249 rtlpriv
->cfg
->ops
->c2h_command_handle(hw
);
2252 static void rtl_c2h_content_parsing(struct ieee80211_hw
*hw
,
2253 struct sk_buff
*skb
);
2255 static bool rtl_c2h_fast_cmd(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2257 u8 cmd_id
= GET_C2H_CMD_ID(skb
->data
);
2269 void rtl_c2hcmd_enqueue(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2271 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2272 unsigned long flags
;
2274 if (rtl_c2h_fast_cmd(hw
, skb
)) {
2275 rtl_c2h_content_parsing(hw
, skb
);
2281 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2283 __skb_queue_tail(&rtlpriv
->c2hcmd_queue
, skb
);
2285 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2288 queue_delayed_work(rtlpriv
->works
.rtl_wq
, &rtlpriv
->works
.c2hcmd_wq
, 0);
2290 EXPORT_SYMBOL(rtl_c2hcmd_enqueue
);
2292 static void rtl_c2h_content_parsing(struct ieee80211_hw
*hw
,
2293 struct sk_buff
*skb
)
2295 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2296 struct rtl_hal_ops
*hal_ops
= rtlpriv
->cfg
->ops
;
2297 const struct rtl_btc_ops
*btc_ops
= rtlpriv
->btcoexist
.btc_ops
;
2301 cmd_id
= GET_C2H_CMD_ID(skb
->data
);
2302 cmd_len
= skb
->len
- C2H_DATA_OFFSET
;
2303 cmd_buf
= GET_C2H_DATA_PTR(skb
->data
);
2307 rtl_dbg(rtlpriv
, COMP_FW
, DBG_LOUD
, "[C2H], C2H_DBG!!\n");
2310 rtl_dbg(rtlpriv
, COMP_FW
, DBG_TRACE
,
2311 "[C2H], C2H_TXBF!!\n");
2314 rtl_tx_report_handler(hw
, cmd_buf
, cmd_len
);
2317 if (hal_ops
->c2h_ra_report_handler
)
2318 hal_ops
->c2h_ra_report_handler(hw
, cmd_buf
, cmd_len
);
2321 rtl_dbg(rtlpriv
, COMP_FW
, DBG_TRACE
,
2322 "[C2H], C2H_BT_INFO!!\n");
2323 if (rtlpriv
->cfg
->ops
->get_btc_status())
2324 btc_ops
->btc_btinfo_notify(rtlpriv
, cmd_buf
, cmd_len
);
2327 rtl_dbg(rtlpriv
, COMP_FW
, DBG_TRACE
,
2328 "[C2H], C2H_BT_MP!!\n");
2329 if (rtlpriv
->cfg
->ops
->get_btc_status())
2330 btc_ops
->btc_btmpinfo_notify(rtlpriv
, cmd_buf
, cmd_len
);
2333 rtl_dbg(rtlpriv
, COMP_FW
, DBG_TRACE
,
2334 "[C2H], Unknown packet!! cmd_id(%#X)!\n", cmd_id
);
2339 void rtl_c2hcmd_launcher(struct ieee80211_hw
*hw
, int exec
)
2341 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2342 struct sk_buff
*skb
;
2343 unsigned long flags
;
2346 for (i
= 0; i
< 200; i
++) {
2347 /* dequeue a task */
2348 spin_lock_irqsave(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2350 skb
= __skb_dequeue(&rtlpriv
->c2hcmd_queue
);
2352 spin_unlock_irqrestore(&rtlpriv
->locks
.c2hcmd_lock
, flags
);
2358 rtl_dbg(rtlpriv
, COMP_FW
, DBG_DMESG
, "C2H rx_desc_shift=%d\n",
2360 RT_PRINT_DATA(rtlpriv
, COMP_FW
, DBG_DMESG
,
2361 "C2H data: ", skb
->data
, skb
->len
);
2364 rtl_c2h_content_parsing(hw
, skb
);
2367 dev_kfree_skb_any(skb
);
2371 static void rtl_c2hcmd_wq_callback(struct work_struct
*work
)
2373 struct rtl_works
*rtlworks
= container_of(work
, struct rtl_works
,
2375 struct ieee80211_hw
*hw
= rtlworks
->hw
;
2377 rtl_c2hcmd_launcher(hw
, 1);
2380 void rtl_easy_concurrent_retrytimer_callback(struct timer_list
*t
)
2382 struct rtl_priv
*rtlpriv
=
2383 from_timer(rtlpriv
, t
, works
.dualmac_easyconcurrent_retrytimer
);
2384 struct ieee80211_hw
*hw
= rtlpriv
->hw
;
2385 struct rtl_priv
*buddy_priv
= rtlpriv
->buddy_priv
;
2387 if (buddy_priv
== NULL
)
2390 rtlpriv
->cfg
->ops
->dualmac_easy_concurrent(hw
);
2393 /*********************************************************
2395 * frame process functions
2397 *********************************************************/
2398 u8
*rtl_find_ie(u8
*data
, unsigned int len
, u8 ie
)
2400 struct ieee80211_mgmt
*mgmt
= (void *)data
;
2403 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
2406 if (pos
+ 2 + pos
[1] > end
)
2417 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2418 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
2419 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
2420 enum ieee80211_smps_mode smps
,
2423 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2424 struct sk_buff
*skb
;
2425 struct ieee80211_mgmt
*action_frame
;
2427 /* 27 = header + category + action + smps mode */
2428 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
2432 skb_reserve(skb
, hw
->extra_tx_headroom
);
2433 action_frame
= skb_put_zero(skb
, 27);
2434 memcpy(action_frame
->da
, da
, ETH_ALEN
);
2435 memcpy(action_frame
->sa
, rtlefuse
->dev_addr
, ETH_ALEN
);
2436 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
2437 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2438 IEEE80211_STYPE_ACTION
);
2439 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
2440 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
2442 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
2443 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
2446 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
2447 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2448 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
2450 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
2451 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2452 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
2454 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
2455 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
2456 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
2463 int rtl_send_smps_action(struct ieee80211_hw
*hw
,
2464 struct ieee80211_sta
*sta
,
2465 enum ieee80211_smps_mode smps
)
2467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2468 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2469 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2470 struct sk_buff
*skb
= NULL
;
2471 struct rtl_tcb_desc tcb_desc
;
2472 u8 bssid
[ETH_ALEN
] = {0};
2474 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
2476 if (rtlpriv
->mac80211
.act_scanning
)
2482 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
2485 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
2488 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
)
2489 memcpy(bssid
, rtlpriv
->efuse
.dev_addr
, ETH_ALEN
);
2491 memcpy(bssid
, rtlpriv
->mac80211
.bssid
, ETH_ALEN
);
2493 skb
= rtl_make_smps_action(hw
, smps
, sta
->addr
, bssid
);
2494 /* this is a type = mgmt * stype = action frame */
2496 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2497 struct rtl_sta_info
*sta_entry
=
2498 (struct rtl_sta_info
*) sta
->drv_priv
;
2499 sta_entry
->mimo_ps
= smps
;
2500 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0, true); */
2502 info
->control
.rates
[0].idx
= 0;
2503 info
->band
= hw
->conf
.chandef
.chan
->band
;
2504 rtlpriv
->intf_ops
->adapter_tx(hw
, sta
, skb
, &tcb_desc
);
2511 EXPORT_SYMBOL(rtl_send_smps_action
);
2513 void rtl_phy_scan_operation_backup(struct ieee80211_hw
*hw
, u8 operation
)
2515 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2516 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2517 enum io_type iotype
;
2519 if (!is_hal_stop(rtlhal
)) {
2520 switch (operation
) {
2521 case SCAN_OPT_BACKUP
:
2522 iotype
= IO_CMD_PAUSE_DM_BY_SCAN
;
2523 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2527 case SCAN_OPT_RESTORE
:
2528 iotype
= IO_CMD_RESUME_DM_BY_SCAN
;
2529 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2534 pr_err("Unknown Scan Backup operation.\n");
2539 EXPORT_SYMBOL(rtl_phy_scan_operation_backup
);
2541 /* because mac80211 have issues when can receive del ba
2542 * so here we just make a fake del_ba if we receive a ba_req
2543 * but rx_agg was opened to let mac80211 release some ba
2544 * related resources, so please this del_ba for tx
2546 struct sk_buff
*rtl_make_del_ba(struct ieee80211_hw
*hw
,
2547 u8
*sa
, u8
*bssid
, u16 tid
)
2549 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
2550 struct sk_buff
*skb
;
2551 struct ieee80211_mgmt
*action_frame
;
2554 /* 27 = header + category + action + smps mode */
2555 skb
= dev_alloc_skb(34 + hw
->extra_tx_headroom
);
2559 skb_reserve(skb
, hw
->extra_tx_headroom
);
2560 action_frame
= skb_put_zero(skb
, 34);
2561 memcpy(action_frame
->sa
, sa
, ETH_ALEN
);
2562 memcpy(action_frame
->da
, rtlefuse
->dev_addr
, ETH_ALEN
);
2563 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
2564 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
2565 IEEE80211_STYPE_ACTION
);
2566 action_frame
->u
.action
.category
= WLAN_CATEGORY_BACK
;
2567 action_frame
->u
.action
.u
.delba
.action_code
= WLAN_ACTION_DELBA
;
2568 params
= (u16
)(1 << 11); /* bit 11 initiator */
2569 params
|= (u16
)(tid
<< 12); /* bit 15:12 TID number */
2571 action_frame
->u
.action
.u
.delba
.params
= cpu_to_le16(params
);
2572 action_frame
->u
.action
.u
.delba
.reason_code
=
2573 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT
);
2578 /*********************************************************
2582 *********************************************************/
2583 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
2584 struct octet_string vendor_ie
)
2586 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2587 bool matched
= false;
2588 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
2589 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
2590 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
2591 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
2592 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
2593 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
2594 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
2595 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
2597 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
2598 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
2599 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
2601 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
2602 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
2603 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
2604 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
2606 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
2607 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
2609 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
2610 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
2612 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
2613 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
2620 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
,
2623 struct ieee80211_mgmt
*mgmt
= (void *)data
;
2624 struct octet_string vendor_ie
;
2627 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
2630 if (pos
[0] == 221) {
2631 vendor_ie
.length
= pos
[1];
2632 vendor_ie
.octet
= &pos
[2];
2633 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
2637 if (pos
+ 2 + pos
[1] > end
)
2645 void rtl_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
2647 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2648 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2649 struct ieee80211_hdr
*hdr
= (void *)data
;
2650 u32 vendor
= PEER_UNKNOWN
;
2652 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
2653 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
2654 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
2655 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
2656 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
2657 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
2658 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
2659 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
2660 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
2661 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
2662 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
2663 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
2664 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
2665 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
2666 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
2667 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
2669 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
2672 if (mac
->link_state
== MAC80211_NOLINK
) {
2673 mac
->vendor
= PEER_UNKNOWN
;
2677 if (mac
->cnt_after_linked
> 2)
2680 /* check if this really is a beacon */
2681 if (!ieee80211_is_beacon(hdr
->frame_control
))
2684 /* min. beacon length + FCS_LEN */
2685 if (len
<= 40 + FCS_LEN
)
2688 /* and only beacons from the associated BSSID, please */
2689 if (!ether_addr_equal_64bits(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
2692 if (rtl_find_221_ie(hw
, data
, len
))
2693 vendor
= mac
->vendor
;
2695 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
2696 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
2697 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
2698 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
2699 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
2700 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
2701 vendor
== PEER_ATH
) {
2703 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ath find\n");
2704 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
2705 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
2706 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
2707 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
2708 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
2709 vendor
== PEER_RAL
) {
2710 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>ral find\n");
2712 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
2713 vendor
== PEER_CISCO
) {
2714 vendor
= PEER_CISCO
;
2715 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>cisco find\n");
2716 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
2717 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
2718 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
2719 vendor
== PEER_BROAD
) {
2720 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>broad find\n");
2721 vendor
= PEER_BROAD
;
2722 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
2723 vendor
== PEER_MARV
) {
2725 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "=>marv find\n");
2728 mac
->vendor
= vendor
;
2730 EXPORT_SYMBOL_GPL(rtl_recognize_peer
);
2732 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2733 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2734 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2735 MODULE_LICENSE("GPL");
2736 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2738 struct rtl_global_var rtl_global_var
= {};
2739 EXPORT_SYMBOL_GPL(rtl_global_var
);
2741 static int __init
rtl_core_module_init(void)
2743 BUILD_BUG_ON(TX_PWR_BY_RATE_NUM_RATE
< TX_PWR_BY_RATE_NUM_SECTION
);
2744 BUILD_BUG_ON(MAX_RATE_SECTION_NUM
!= MAX_RATE_SECTION
);
2745 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_24G
!= MAX_RATE_SECTION
);
2746 BUILD_BUG_ON(MAX_BASE_NUM_IN_PHY_REG_PG_5G
!= (MAX_RATE_SECTION
- 1));
2748 if (rtl_rate_control_register())
2749 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
2752 rtl_debugfs_add_topdir();
2754 /* init some global vars */
2755 INIT_LIST_HEAD(&rtl_global_var
.glb_priv_list
);
2756 spin_lock_init(&rtl_global_var
.glb_list_lock
);
2761 static void __exit
rtl_core_module_exit(void)
2764 rtl_rate_control_unregister();
2766 /* remove debugfs */
2767 rtl_debugfs_remove_topdir();
2770 module_init(rtl_core_module_init
);
2771 module_exit(rtl_core_module_exit
);