Commit | Line | Data |
---|---|---|
0c817338 LF |
1 | /****************************************************************************** |
2 | * | |
a8d76066 | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
0c817338 LF |
4 | * |
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. | |
8 | * | |
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 | |
12 | * more details. | |
13 | * | |
0c817338 LF |
14 | * The full GNU General Public License is included in this distribution in the |
15 | * file called LICENSE. | |
16 | * | |
17 | * Contact Information: | |
18 | * wlanfae <wlanfae@realtek.com> | |
19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | |
20 | * Hsinchu 300, Taiwan. | |
21 | * | |
22 | * Larry Finger <Larry.Finger@lwfinger.net> | |
23 | * | |
24 | *****************************************************************************/ | |
25 | ||
0c817338 LF |
26 | #include "wifi.h" |
27 | #include "rc.h" | |
28 | #include "base.h" | |
29 | #include "efuse.h" | |
30 | #include "cam.h" | |
31 | #include "ps.h" | |
32 | #include "regd.h" | |
9afa2e44 | 33 | #include "pci.h" |
d273bb20 LF |
34 | #include <linux/ip.h> |
35 | #include <linux/module.h> | |
0c5d63f0 | 36 | #include <linux/udp.h> |
d273bb20 | 37 | |
0c817338 | 38 | /* |
e1fa7460 TP |
39 | *NOTICE!!!: This file will be very big, we should |
40 | *keep it clear under following roles: | |
0c817338 | 41 | * |
e1fa7460 | 42 | *This file include following parts, so, if you add new |
0c817338 LF |
43 | *functions into this file, please check which part it |
44 | *should includes. or check if you should add new part | |
45 | *for this file: | |
46 | * | |
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 | |
acd48572 C |
52 | *6) IOT functions |
53 | *7) sysfs functions | |
26634c4b LF |
54 | *8) vif functions |
55 | *9) ... | |
0c817338 LF |
56 | */ |
57 | ||
58 | /********************************************************* | |
59 | * | |
60 | * mac80211 init functions | |
61 | * | |
62 | *********************************************************/ | |
acd48572 | 63 | static struct ieee80211_channel rtl_channeltable_2g[] = { |
0c817338 LF |
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,}, | |
78 | }; | |
79 | ||
acd48572 C |
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,}, | |
105 | }; | |
106 | ||
107 | static struct ieee80211_rate rtl_ratetable_2g[] = { | |
0c817338 LF |
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,}, | |
120 | }; | |
121 | ||
acd48572 C |
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,}, | |
131 | }; | |
132 | ||
0c817338 | 133 | static const struct ieee80211_supported_band rtl_band_2ghz = { |
57fbcce3 | 134 | .band = NL80211_BAND_2GHZ, |
0c817338 | 135 | |
acd48572 C |
136 | .channels = rtl_channeltable_2g, |
137 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), | |
0c817338 | 138 | |
acd48572 C |
139 | .bitrates = rtl_ratetable_2g, |
140 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), | |
0c817338 LF |
141 | |
142 | .ht_cap = {0}, | |
143 | }; | |
144 | ||
acd48572 | 145 | static struct ieee80211_supported_band rtl_band_5ghz = { |
57fbcce3 | 146 | .band = NL80211_BAND_5GHZ, |
acd48572 C |
147 | |
148 | .channels = rtl_channeltable_5g, | |
149 | .n_channels = ARRAY_SIZE(rtl_channeltable_5g), | |
0c817338 | 150 | |
acd48572 C |
151 | .bitrates = rtl_ratetable_5g, |
152 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), | |
0c817338 LF |
153 | |
154 | .ht_cap = {0}, | |
155 | }; | |
156 | ||
acd48572 C |
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 */ | |
166 | }; | |
167 | ||
2a00def4 | 168 | u8 rtl_tid_to_ac(u8 tid) |
acd48572 C |
169 | { |
170 | return tid_to_ac[tid]; | |
171 | } | |
6f334c2b | 172 | EXPORT_SYMBOL_GPL(rtl_tid_to_ac); |
acd48572 | 173 | |
0c817338 LF |
174 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, |
175 | struct ieee80211_sta_ht_cap *ht_cap) | |
176 | { | |
177 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
178 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | |
179 | ||
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; | |
185 | ||
acd48572 C |
186 | if (rtlpriv->rtlhal.disable_amsdu_8k) |
187 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; | |
188 | ||
0c817338 LF |
189 | /* |
190 | *Maximum length of AMPDU that the STA can receive. | |
191 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) | |
192 | */ | |
193 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; | |
194 | ||
195 | /*Minimum MPDU start spacing , */ | |
196 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; | |
197 | ||
198 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
199 | ||
57fbcce3 | 200 | /*hw->wiphy->bands[NL80211_BAND_2GHZ] |
0c817338 LF |
201 | *base on ant_num |
202 | *rx_mask: RX mask | |
26634c4b LF |
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; | |
0c817338 LF |
207 | *highest supported RX rate |
208 | */ | |
26634c4b | 209 | if (rtlpriv->dm.supp_phymode_switch) { |
26634c4b LF |
210 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, |
211 | "Support phy mode switch\n"); | |
0c817338 LF |
212 | |
213 | ht_cap->mcs.rx_mask[0] = 0xFF; | |
214 | ht_cap->mcs.rx_mask[1] = 0xFF; | |
215 | ht_cap->mcs.rx_mask[4] = 0x01; | |
216 | ||
17c9ac62 | 217 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
26634c4b LF |
218 | } else { |
219 | if (get_rf_type(rtlphy) == RF_1T2R || | |
220 | get_rf_type(rtlphy) == RF_2T2R) { | |
221 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, | |
222 | "1T2R or 2T2R\n"); | |
223 | ht_cap->mcs.rx_mask[0] = 0xFF; | |
224 | ht_cap->mcs.rx_mask[1] = 0xFF; | |
225 | ht_cap->mcs.rx_mask[4] = 0x01; | |
226 | ||
227 | ht_cap->mcs.rx_highest = | |
228 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); | |
229 | } else if (get_rf_type(rtlphy) == RF_1T1R) { | |
230 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); | |
231 | ||
232 | ht_cap->mcs.rx_mask[0] = 0xFF; | |
233 | ht_cap->mcs.rx_mask[1] = 0x00; | |
234 | ht_cap->mcs.rx_mask[4] = 0x01; | |
235 | ||
236 | ht_cap->mcs.rx_highest = | |
237 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); | |
238 | } | |
0c817338 LF |
239 | } |
240 | } | |
241 | ||
9afa2e44 LF |
242 | static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw, |
243 | struct ieee80211_sta_vht_cap *vht_cap) | |
244 | { | |
245 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
246 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | |
247 | ||
248 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) { | |
249 | u16 mcs_map; | |
250 | ||
251 | vht_cap->vht_supported = true; | |
252 | vht_cap->cap = | |
253 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 | | |
254 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | | |
255 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | |
256 | IEEE80211_VHT_CAP_SHORT_GI_80 | | |
257 | IEEE80211_VHT_CAP_TXSTBC | | |
258 | IEEE80211_VHT_CAP_RXSTBC_1 | | |
259 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
260 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
261 | IEEE80211_VHT_CAP_HTC_VHT | | |
262 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | | |
263 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | | |
264 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | | |
265 | 0; | |
266 | ||
267 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | | |
268 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | | |
269 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | | |
270 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | | |
271 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | | |
272 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | | |
273 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | | |
274 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; | |
275 | ||
276 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); | |
277 | vht_cap->vht_mcs.rx_highest = | |
278 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); | |
279 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); | |
280 | vht_cap->vht_mcs.tx_highest = | |
281 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); | |
282 | } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) { | |
283 | u16 mcs_map; | |
284 | ||
285 | vht_cap->vht_supported = true; | |
286 | vht_cap->cap = | |
287 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 | | |
288 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | | |
289 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | |
290 | IEEE80211_VHT_CAP_SHORT_GI_80 | | |
291 | IEEE80211_VHT_CAP_TXSTBC | | |
292 | IEEE80211_VHT_CAP_RXSTBC_1 | | |
293 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | | |
294 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | | |
295 | IEEE80211_VHT_CAP_HTC_VHT | | |
296 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | | |
297 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | | |
298 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | | |
299 | 0; | |
300 | ||
301 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | | |
302 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | | |
303 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | | |
304 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | | |
305 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | | |
306 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | | |
307 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | | |
308 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; | |
309 | ||
310 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); | |
311 | vht_cap->vht_mcs.rx_highest = | |
312 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); | |
313 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); | |
314 | vht_cap->vht_mcs.tx_highest = | |
315 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); | |
316 | } | |
317 | } | |
318 | ||
0c817338 LF |
319 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
320 | { | |
acd48572 C |
321 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
322 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | |
0c817338 LF |
323 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
324 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | |
325 | struct ieee80211_supported_band *sband; | |
326 | ||
9afa2e44 LF |
327 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && |
328 | rtlhal->bandset == BAND_ON_BOTH) { | |
acd48572 C |
329 | /* 1: 2.4 G bands */ |
330 | /* <1> use mac->bands as mem for hw->wiphy->bands */ | |
57fbcce3 | 331 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
0c817338 | 332 | |
57fbcce3 | 333 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
acd48572 | 334 | * to default value(1T1R) */ |
57fbcce3 | 335 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz, |
acd48572 | 336 | sizeof(struct ieee80211_supported_band)); |
0c817338 | 337 | |
acd48572 C |
338 | /* <3> init ht cap base on ant_num */ |
339 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | |
0c817338 | 340 | |
acd48572 | 341 | /* <4> set mac->sband to wiphy->sband */ |
57fbcce3 | 342 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
0c817338 | 343 | |
acd48572 C |
344 | /* 2: 5 G bands */ |
345 | /* <1> use mac->bands as mem for hw->wiphy->bands */ | |
57fbcce3 | 346 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
acd48572 | 347 | |
57fbcce3 | 348 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
acd48572 | 349 | * to default value(1T1R) */ |
57fbcce3 | 350 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz, |
acd48572 C |
351 | sizeof(struct ieee80211_supported_band)); |
352 | ||
353 | /* <3> init ht cap base on ant_num */ | |
354 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | |
355 | ||
9afa2e44 | 356 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
acd48572 | 357 | /* <4> set mac->sband to wiphy->sband */ |
57fbcce3 | 358 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
acd48572 C |
359 | } else { |
360 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { | |
361 | /* <1> use mac->bands as mem for hw->wiphy->bands */ | |
57fbcce3 | 362 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
acd48572 | 363 | |
57fbcce3 | 364 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
acd48572 | 365 | * to default value(1T1R) */ |
57fbcce3 | 366 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), |
9afa2e44 LF |
367 | &rtl_band_2ghz, |
368 | sizeof(struct ieee80211_supported_band)); | |
acd48572 C |
369 | |
370 | /* <3> init ht cap base on ant_num */ | |
371 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | |
372 | ||
373 | /* <4> set mac->sband to wiphy->sband */ | |
57fbcce3 | 374 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
acd48572 C |
375 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
376 | /* <1> use mac->bands as mem for hw->wiphy->bands */ | |
57fbcce3 | 377 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
acd48572 | 378 | |
57fbcce3 | 379 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
acd48572 | 380 | * to default value(1T1R) */ |
57fbcce3 | 381 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), |
9afa2e44 LF |
382 | &rtl_band_5ghz, |
383 | sizeof(struct ieee80211_supported_band)); | |
acd48572 C |
384 | |
385 | /* <3> init ht cap base on ant_num */ | |
386 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); | |
387 | ||
9afa2e44 | 388 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
acd48572 | 389 | /* <4> set mac->sband to wiphy->sband */ |
57fbcce3 | 390 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
acd48572 | 391 | } else { |
f30d7507 JP |
392 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n", |
393 | rtlhal->current_bandtype); | |
acd48572 C |
394 | } |
395 | } | |
0c817338 | 396 | /* <5> set hw caps */ |
30686bf7 JB |
397 | ieee80211_hw_set(hw, SIGNAL_DBM); |
398 | ieee80211_hw_set(hw, RX_INCLUDES_FCS); | |
399 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); | |
400 | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
401 | ieee80211_hw_set(hw, MFP_CAPABLE); | |
402 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); | |
0c817338 | 403 | |
acd48572 | 404 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
30686bf7 JB |
405 | if (rtlpriv->psc.swctrl_lps) { |
406 | ieee80211_hw_set(hw, SUPPORTS_PS); | |
407 | ieee80211_hw_set(hw, PS_NULLFUNC_STACK); | |
408 | } | |
0c817338 | 409 | hw->wiphy->interface_modes = |
acd48572 C |
410 | BIT(NL80211_IFTYPE_AP) | |
411 | BIT(NL80211_IFTYPE_STATION) | | |
26634c4b LF |
412 | BIT(NL80211_IFTYPE_ADHOC) | |
413 | BIT(NL80211_IFTYPE_MESH_POINT) | | |
414 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
415 | BIT(NL80211_IFTYPE_P2P_GO); | |
26634c4b | 416 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
9afa2e44 LF |
417 | |
418 | hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; | |
419 | ||
0c817338 LF |
420 | hw->wiphy->rts_threshold = 2347; |
421 | ||
422 | hw->queues = AC_MAX; | |
423 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; | |
424 | ||
425 | /* TODO: Correct this value for our hw */ | |
426 | /* TODO: define these hard code value */ | |
acd48572 | 427 | hw->max_listen_interval = 10; |
0c817338 LF |
428 | hw->max_rate_tries = 4; |
429 | /* hw->max_rates = 1; */ | |
acd48572 | 430 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
0c817338 | 431 | |
9afa2e44 LF |
432 | /* wowlan is not supported by kernel if CONFIG_PM is not defined */ |
433 | #ifdef CONFIG_PM | |
434 | if (rtlpriv->psc.wo_wlan_mode) { | |
435 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET) | |
436 | rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT; | |
437 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) { | |
438 | rtlpriv->wowlan.n_patterns = | |
439 | MAX_SUPPORT_WOL_PATTERN_NUM; | |
440 | rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE; | |
441 | rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE; | |
442 | } | |
443 | hw->wiphy->wowlan = &rtlpriv->wowlan; | |
444 | } | |
445 | #endif | |
446 | ||
0c817338 LF |
447 | /* <6> mac address */ |
448 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { | |
449 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); | |
450 | } else { | |
abfabc9b LF |
451 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
452 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); | |
453 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); | |
0c817338 | 454 | } |
0c817338 LF |
455 | } |
456 | ||
457 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) | |
458 | { | |
459 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
460 | ||
461 | /* <1> timer */ | |
0c817338 LF |
462 | setup_timer(&rtlpriv->works.watchdog_timer, |
463 | rtl_watch_dog_timer_callback, (unsigned long)hw); | |
26634c4b LF |
464 | setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer, |
465 | rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw); | |
0c817338 LF |
466 | /* <2> work queue */ |
467 | rtlpriv->works.hw = hw; | |
598a0df0 | 468 | rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name); |
0c817338 LF |
469 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
470 | (void *)rtl_watchdog_wq_callback); | |
471 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, | |
472 | (void *)rtl_ips_nic_off_wq_callback); | |
acd48572 C |
473 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
474 | (void *)rtl_swlps_wq_callback); | |
475 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, | |
476 | (void *)rtl_swlps_rfon_wq_callback); | |
26634c4b LF |
477 | INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, |
478 | (void *)rtl_fwevt_wq_callback); | |
0c817338 LF |
479 | |
480 | } | |
481 | ||
482 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) | |
483 | { | |
484 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
485 | ||
486 | del_timer_sync(&rtlpriv->works.watchdog_timer); | |
487 | ||
488 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); | |
489 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); | |
acd48572 C |
490 | cancel_delayed_work(&rtlpriv->works.ps_work); |
491 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); | |
26634c4b | 492 | cancel_delayed_work(&rtlpriv->works.fwevt_wq); |
0c817338 | 493 | } |
6f334c2b | 494 | EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work); |
0c817338 LF |
495 | |
496 | void rtl_init_rfkill(struct ieee80211_hw *hw) | |
497 | { | |
498 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
499 | ||
500 | bool radio_state; | |
501 | bool blocked; | |
502 | u8 valid = 0; | |
503 | ||
228bdfca | 504 | /*set init state to on */ |
3db1cd5c | 505 | rtlpriv->rfkill.rfkill_state = true; |
228bdfca | 506 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
0c817338 | 507 | |
228bdfca | 508 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
0c817338 | 509 | |
e6d8a817 | 510 | if (valid) { |
9afa2e44 | 511 | pr_info("rtlwifi: wireless switch is %s\n", |
292b1192 | 512 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
228bdfca | 513 | |
0c817338 LF |
514 | rtlpriv->rfkill.rfkill_state = radio_state; |
515 | ||
516 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; | |
517 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); | |
518 | } | |
519 | ||
520 | wiphy_rfkill_start_polling(hw->wiphy); | |
521 | } | |
b0302aba | 522 | EXPORT_SYMBOL(rtl_init_rfkill); |
0c817338 LF |
523 | |
524 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) | |
525 | { | |
526 | wiphy_rfkill_stop_polling(hw->wiphy); | |
527 | } | |
6f334c2b | 528 | EXPORT_SYMBOL_GPL(rtl_deinit_rfkill); |
0c817338 LF |
529 | |
530 | int rtl_init_core(struct ieee80211_hw *hw) | |
531 | { | |
532 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
533 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | |
534 | ||
535 | /* <1> init mac80211 */ | |
536 | _rtl_init_mac80211(hw); | |
537 | rtlmac->hw = hw; | |
538 | ||
539 | /* <2> rate control register */ | |
375ff4c7 | 540 | hw->rate_control_algorithm = "rtl_rc"; |
0c817338 LF |
541 | |
542 | /* | |
543 | * <3> init CRDA must come after init | |
544 | * mac80211 hw in _rtl_init_mac80211. | |
545 | */ | |
546 | if (rtl_regd_init(hw, rtl_reg_notifier)) { | |
f30d7507 | 547 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n"); |
0c817338 | 548 | return 1; |
0c817338 LF |
549 | } |
550 | ||
551 | /* <4> locks */ | |
8a09d6d8 | 552 | mutex_init(&rtlpriv->locks.conf_mutex); |
b9116b9a | 553 | spin_lock_init(&rtlpriv->locks.ips_lock); |
0c817338 LF |
554 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
555 | spin_lock_init(&rtlpriv->locks.h2c_lock); | |
556 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); | |
557 | spin_lock_init(&rtlpriv->locks.rf_lock); | |
acd48572 | 558 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
26634c4b | 559 | spin_lock_init(&rtlpriv->locks.entry_list_lock); |
acd48572 | 560 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
26634c4b LF |
561 | spin_lock_init(&rtlpriv->locks.check_sendpkt_lock); |
562 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); | |
563 | spin_lock_init(&rtlpriv->locks.lps_lock); | |
9afa2e44 | 564 | spin_lock_init(&rtlpriv->locks.iqk_lock); |
26634c4b LF |
565 | /* <5> init list */ |
566 | INIT_LIST_HEAD(&rtlpriv->entry_list); | |
0c817338 LF |
567 | |
568 | rtlmac->link_state = MAC80211_NOLINK; | |
569 | ||
26634c4b | 570 | /* <6> init deferred work */ |
0c817338 LF |
571 | _rtl_init_deferred_work(hw); |
572 | ||
573 | return 0; | |
574 | } | |
6f334c2b | 575 | EXPORT_SYMBOL_GPL(rtl_init_core); |
0c817338 LF |
576 | |
577 | void rtl_deinit_core(struct ieee80211_hw *hw) | |
578 | { | |
0c817338 | 579 | } |
6f334c2b | 580 | EXPORT_SYMBOL_GPL(rtl_deinit_core); |
0c817338 LF |
581 | |
582 | void rtl_init_rx_config(struct ieee80211_hw *hw) | |
583 | { | |
584 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
585 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
586 | ||
587 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); | |
0c817338 | 588 | } |
6f334c2b | 589 | EXPORT_SYMBOL_GPL(rtl_init_rx_config); |
0c817338 LF |
590 | |
591 | /********************************************************* | |
592 | * | |
593 | * tx information functions | |
594 | * | |
595 | *********************************************************/ | |
596 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, | |
597 | struct rtl_tcb_desc *tcb_desc, | |
598 | struct ieee80211_tx_info *info) | |
599 | { | |
600 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
601 | u8 rate_flag = info->control.rates[0].flags; | |
602 | ||
603 | tcb_desc->use_shortpreamble = false; | |
604 | ||
605 | /* 1M can only use Long Preamble. 11B spec */ | |
606 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) | |
607 | return; | |
608 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | |
609 | tcb_desc->use_shortpreamble = true; | |
610 | ||
611 | return; | |
612 | } | |
613 | ||
614 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, | |
acd48572 | 615 | struct ieee80211_sta *sta, |
0c817338 LF |
616 | struct rtl_tcb_desc *tcb_desc, |
617 | struct ieee80211_tx_info *info) | |
618 | { | |
619 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
620 | u8 rate_flag = info->control.rates[0].flags; | |
acd48572 | 621 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
9afa2e44 | 622 | u8 sgi_80 = 0, bw_80 = 0; |
0c817338 LF |
623 | tcb_desc->use_shortgi = false; |
624 | ||
acd48572 | 625 | if (sta == NULL) |
0c817338 LF |
626 | return; |
627 | ||
acd48572 C |
628 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
629 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; | |
9afa2e44 | 630 | sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80; |
acd48572 | 631 | |
9afa2e44 | 632 | if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported)) |
0c817338 LF |
633 | return; |
634 | ||
acd48572 | 635 | if (!sgi_40 && !sgi_20) |
0c817338 LF |
636 | return; |
637 | ||
9afa2e44 | 638 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
acd48572 | 639 | bw_40 = mac->bw_40; |
9afa2e44 LF |
640 | bw_80 = mac->bw_80; |
641 | } else if (mac->opmode == NL80211_IFTYPE_AP || | |
26634c4b | 642 | mac->opmode == NL80211_IFTYPE_ADHOC || |
9afa2e44 LF |
643 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
644 | bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
645 | bw_80 = sta->vht_cap.vht_supported; | |
646 | } | |
acd48572 | 647 | |
9afa2e44 LF |
648 | if (bw_80) { |
649 | if (sgi_80) | |
650 | tcb_desc->use_shortgi = true; | |
651 | else | |
652 | tcb_desc->use_shortgi = false; | |
653 | } else { | |
654 | if (bw_40 && sgi_40) | |
655 | tcb_desc->use_shortgi = true; | |
656 | else if (!bw_40 && sgi_20) | |
657 | tcb_desc->use_shortgi = true; | |
658 | } | |
0c817338 LF |
659 | |
660 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) | |
661 | tcb_desc->use_shortgi = false; | |
0c817338 LF |
662 | } |
663 | ||
664 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, | |
665 | struct rtl_tcb_desc *tcb_desc, | |
666 | struct ieee80211_tx_info *info) | |
667 | { | |
668 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
669 | u8 rate_flag = info->control.rates[0].flags; | |
670 | ||
671 | /* Common Settings */ | |
7ea47240 LF |
672 | tcb_desc->rts_stbc = false; |
673 | tcb_desc->cts_enable = false; | |
0c817338 | 674 | tcb_desc->rts_sc = 0; |
7ea47240 LF |
675 | tcb_desc->rts_bw = false; |
676 | tcb_desc->rts_use_shortpreamble = false; | |
677 | tcb_desc->rts_use_shortgi = false; | |
0c817338 LF |
678 | |
679 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { | |
680 | /* Use CTS-to-SELF in protection mode. */ | |
7ea47240 LF |
681 | tcb_desc->rts_enable = true; |
682 | tcb_desc->cts_enable = true; | |
0c817338 LF |
683 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
684 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { | |
685 | /* Use RTS-CTS in protection mode. */ | |
7ea47240 | 686 | tcb_desc->rts_enable = true; |
0c817338 LF |
687 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
688 | } | |
0c817338 LF |
689 | } |
690 | ||
691 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, | |
acd48572 | 692 | struct ieee80211_sta *sta, |
0c817338 LF |
693 | struct rtl_tcb_desc *tcb_desc) |
694 | { | |
695 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
696 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
acd48572 C |
697 | struct rtl_sta_info *sta_entry = NULL; |
698 | u8 ratr_index = 7; | |
0c817338 | 699 | |
acd48572 C |
700 | if (sta) { |
701 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; | |
702 | ratr_index = sta_entry->ratr_index; | |
703 | } | |
0c817338 | 704 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
acd48572 | 705 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
0c817338 | 706 | tcb_desc->ratr_index = 0; |
26634c4b | 707 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC || |
9afa2e44 | 708 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
7ea47240 | 709 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
0c817338 LF |
710 | tcb_desc->hw_rate = |
711 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; | |
712 | tcb_desc->use_driver_rate = 1; | |
26634c4b | 713 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
0c817338 | 714 | } else { |
26634c4b | 715 | tcb_desc->ratr_index = ratr_index; |
0c817338 | 716 | } |
acd48572 C |
717 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
718 | tcb_desc->ratr_index = ratr_index; | |
0c817338 LF |
719 | } |
720 | } | |
721 | ||
7ea47240 | 722 | if (rtlpriv->dm.useramask) { |
26634c4b LF |
723 | tcb_desc->ratr_index = ratr_index; |
724 | /* TODO we will differentiate adhoc and station future */ | |
725 | if (mac->opmode == NL80211_IFTYPE_STATION || | |
726 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { | |
acd48572 C |
727 | tcb_desc->mac_id = 0; |
728 | ||
9afa2e44 LF |
729 | if (mac->mode == WIRELESS_MODE_AC_5G) |
730 | tcb_desc->ratr_index = | |
731 | RATR_INX_WIRELESS_AC_5N; | |
732 | else if (mac->mode == WIRELESS_MODE_AC_24G) | |
733 | tcb_desc->ratr_index = | |
734 | RATR_INX_WIRELESS_AC_24N; | |
735 | else if (mac->mode == WIRELESS_MODE_N_24G) | |
acd48572 C |
736 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; |
737 | else if (mac->mode == WIRELESS_MODE_N_5G) | |
738 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; | |
739 | else if (mac->mode & WIRELESS_MODE_G) | |
740 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; | |
741 | else if (mac->mode & WIRELESS_MODE_B) | |
742 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; | |
743 | else if (mac->mode & WIRELESS_MODE_A) | |
744 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; | |
9afa2e44 | 745 | |
acd48572 | 746 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
9afa2e44 | 747 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
acd48572 C |
748 | if (NULL != sta) { |
749 | if (sta->aid > 0) | |
750 | tcb_desc->mac_id = sta->aid + 1; | |
751 | else | |
752 | tcb_desc->mac_id = 1; | |
753 | } else { | |
754 | tcb_desc->mac_id = 0; | |
755 | } | |
0c817338 LF |
756 | } |
757 | } | |
0c817338 LF |
758 | } |
759 | ||
760 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, | |
acd48572 | 761 | struct ieee80211_sta *sta, |
0c817338 LF |
762 | struct rtl_tcb_desc *tcb_desc) |
763 | { | |
764 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
765 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
766 | ||
7ea47240 | 767 | tcb_desc->packet_bw = false; |
acd48572 | 768 | if (!sta) |
0c817338 | 769 | return; |
acd48572 | 770 | if (mac->opmode == NL80211_IFTYPE_AP || |
26634c4b LF |
771 | mac->opmode == NL80211_IFTYPE_ADHOC || |
772 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { | |
9afa2e44 LF |
773 | if (!(sta->ht_cap.ht_supported) || |
774 | !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) | |
acd48572 C |
775 | return; |
776 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { | |
777 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) | |
778 | return; | |
779 | } | |
7ea47240 | 780 | if (tcb_desc->multicast || tcb_desc->broadcast) |
0c817338 LF |
781 | return; |
782 | ||
783 | /*use legency rate, shall use 20MHz */ | |
784 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) | |
785 | return; | |
786 | ||
9afa2e44 LF |
787 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40; |
788 | ||
789 | if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE || | |
790 | rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) { | |
791 | if (mac->opmode == NL80211_IFTYPE_AP || | |
792 | mac->opmode == NL80211_IFTYPE_ADHOC || | |
793 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { | |
794 | if (!(sta->vht_cap.vht_supported)) | |
795 | return; | |
796 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { | |
797 | if (!mac->bw_80 || | |
798 | !(sta->vht_cap.vht_supported)) | |
799 | return; | |
800 | } | |
801 | if (tcb_desc->hw_rate <= | |
802 | rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]) | |
803 | return; | |
804 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80; | |
805 | } | |
0c817338 LF |
806 | } |
807 | ||
9afa2e44 LF |
808 | static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw, |
809 | struct ieee80211_sta *sta) | |
0c817338 LF |
810 | { |
811 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
812 | struct rtl_phy *rtlphy = &(rtlpriv->phy); | |
813 | u8 hw_rate; | |
9afa2e44 LF |
814 | u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map); |
815 | ||
816 | if ((get_rf_type(rtlphy) == RF_2T2R) && | |
817 | (tx_mcs_map & 0x000c) != 0x000c) { | |
818 | if ((tx_mcs_map & 0x000c) >> 2 == | |
819 | IEEE80211_VHT_MCS_SUPPORT_0_7) | |
820 | hw_rate = | |
821 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7]; | |
822 | else if ((tx_mcs_map & 0x000c) >> 2 == | |
823 | IEEE80211_VHT_MCS_SUPPORT_0_8) | |
824 | hw_rate = | |
825 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; | |
826 | else | |
827 | hw_rate = | |
828 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; | |
829 | } else { | |
830 | if ((tx_mcs_map & 0x0003) == | |
831 | IEEE80211_VHT_MCS_SUPPORT_0_7) | |
832 | hw_rate = | |
833 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7]; | |
834 | else if ((tx_mcs_map & 0x0003) == | |
835 | IEEE80211_VHT_MCS_SUPPORT_0_8) | |
836 | hw_rate = | |
837 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; | |
838 | else | |
839 | hw_rate = | |
840 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; | |
841 | } | |
842 | ||
843 | return hw_rate; | |
844 | } | |
845 | ||
846 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw, | |
847 | struct ieee80211_sta *sta) | |
848 | { | |
849 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
850 | struct rtl_phy *rtlphy = &rtlpriv->phy; | |
851 | u8 hw_rate; | |
0c817338 | 852 | |
9afa2e44 LF |
853 | if ((get_rf_type(rtlphy) == RF_2T2R) && |
854 | (sta->ht_cap.mcs.rx_mask[1] != 0)) | |
0c817338 LF |
855 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
856 | else | |
857 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; | |
858 | ||
859 | return hw_rate; | |
860 | } | |
861 | ||
7ad0ce35 LF |
862 | /* mac80211's rate_idx is like this: |
863 | * | |
57fbcce3 | 864 | * 2.4G band:rx_status->band == NL80211_BAND_2GHZ |
7ad0ce35 LF |
865 | * |
866 | * B/G rate: | |
867 | * (rx_status->flag & RX_FLAG_HT) = 0, | |
e0e776a3 | 868 | * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11, |
7ad0ce35 LF |
869 | * |
870 | * N rate: | |
871 | * (rx_status->flag & RX_FLAG_HT) = 1, | |
e0e776a3 | 872 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
7ad0ce35 | 873 | * |
57fbcce3 | 874 | * 5G band:rx_status->band == NL80211_BAND_5GHZ |
7ad0ce35 LF |
875 | * A rate: |
876 | * (rx_status->flag & RX_FLAG_HT) = 0, | |
e0e776a3 | 877 | * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7, |
7ad0ce35 LF |
878 | * |
879 | * N rate: | |
880 | * (rx_status->flag & RX_FLAG_HT) = 1, | |
e0e776a3 | 881 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
fd3cb22a LF |
882 | * |
883 | * VHT rates: | |
884 | * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9 | |
885 | * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9 | |
7ad0ce35 | 886 | */ |
fd3cb22a LF |
887 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht, |
888 | u8 desc_rate) | |
7ad0ce35 LF |
889 | { |
890 | int rate_idx; | |
891 | ||
fd3cb22a LF |
892 | if (isvht) { |
893 | switch (desc_rate) { | |
894 | case DESC_RATEVHT1SS_MCS0: | |
895 | rate_idx = 0; | |
896 | break; | |
897 | case DESC_RATEVHT1SS_MCS1: | |
898 | rate_idx = 1; | |
899 | break; | |
900 | case DESC_RATEVHT1SS_MCS2: | |
901 | rate_idx = 2; | |
902 | break; | |
903 | case DESC_RATEVHT1SS_MCS3: | |
904 | rate_idx = 3; | |
905 | break; | |
906 | case DESC_RATEVHT1SS_MCS4: | |
907 | rate_idx = 4; | |
908 | break; | |
909 | case DESC_RATEVHT1SS_MCS5: | |
910 | rate_idx = 5; | |
911 | break; | |
912 | case DESC_RATEVHT1SS_MCS6: | |
913 | rate_idx = 6; | |
914 | break; | |
915 | case DESC_RATEVHT1SS_MCS7: | |
916 | rate_idx = 7; | |
917 | break; | |
918 | case DESC_RATEVHT1SS_MCS8: | |
919 | rate_idx = 8; | |
920 | break; | |
921 | case DESC_RATEVHT1SS_MCS9: | |
922 | rate_idx = 9; | |
923 | break; | |
924 | case DESC_RATEVHT2SS_MCS0: | |
925 | rate_idx = 0; | |
926 | break; | |
927 | case DESC_RATEVHT2SS_MCS1: | |
928 | rate_idx = 1; | |
929 | break; | |
930 | case DESC_RATEVHT2SS_MCS2: | |
931 | rate_idx = 2; | |
932 | break; | |
933 | case DESC_RATEVHT2SS_MCS3: | |
934 | rate_idx = 3; | |
935 | break; | |
936 | case DESC_RATEVHT2SS_MCS4: | |
937 | rate_idx = 4; | |
938 | break; | |
939 | case DESC_RATEVHT2SS_MCS5: | |
940 | rate_idx = 5; | |
941 | break; | |
942 | case DESC_RATEVHT2SS_MCS6: | |
943 | rate_idx = 6; | |
944 | break; | |
945 | case DESC_RATEVHT2SS_MCS7: | |
946 | rate_idx = 7; | |
947 | break; | |
948 | case DESC_RATEVHT2SS_MCS8: | |
949 | rate_idx = 8; | |
950 | break; | |
951 | case DESC_RATEVHT2SS_MCS9: | |
952 | rate_idx = 9; | |
953 | break; | |
954 | default: | |
955 | rate_idx = 0; | |
956 | break; | |
957 | } | |
958 | return rate_idx; | |
959 | } | |
7ad0ce35 | 960 | if (false == isht) { |
57fbcce3 | 961 | if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
7ad0ce35 | 962 | switch (desc_rate) { |
e0e776a3 | 963 | case DESC_RATE1M: |
7ad0ce35 LF |
964 | rate_idx = 0; |
965 | break; | |
e0e776a3 | 966 | case DESC_RATE2M: |
7ad0ce35 LF |
967 | rate_idx = 1; |
968 | break; | |
e0e776a3 | 969 | case DESC_RATE5_5M: |
7ad0ce35 LF |
970 | rate_idx = 2; |
971 | break; | |
e0e776a3 | 972 | case DESC_RATE11M: |
7ad0ce35 LF |
973 | rate_idx = 3; |
974 | break; | |
e0e776a3 | 975 | case DESC_RATE6M: |
7ad0ce35 LF |
976 | rate_idx = 4; |
977 | break; | |
e0e776a3 | 978 | case DESC_RATE9M: |
7ad0ce35 LF |
979 | rate_idx = 5; |
980 | break; | |
e0e776a3 | 981 | case DESC_RATE12M: |
7ad0ce35 LF |
982 | rate_idx = 6; |
983 | break; | |
e0e776a3 | 984 | case DESC_RATE18M: |
7ad0ce35 LF |
985 | rate_idx = 7; |
986 | break; | |
e0e776a3 | 987 | case DESC_RATE24M: |
7ad0ce35 LF |
988 | rate_idx = 8; |
989 | break; | |
e0e776a3 | 990 | case DESC_RATE36M: |
7ad0ce35 LF |
991 | rate_idx = 9; |
992 | break; | |
e0e776a3 | 993 | case DESC_RATE48M: |
7ad0ce35 LF |
994 | rate_idx = 10; |
995 | break; | |
e0e776a3 | 996 | case DESC_RATE54M: |
7ad0ce35 LF |
997 | rate_idx = 11; |
998 | break; | |
999 | default: | |
1000 | rate_idx = 0; | |
1001 | break; | |
1002 | } | |
1003 | } else { | |
1004 | switch (desc_rate) { | |
e0e776a3 | 1005 | case DESC_RATE6M: |
7ad0ce35 LF |
1006 | rate_idx = 0; |
1007 | break; | |
e0e776a3 | 1008 | case DESC_RATE9M: |
7ad0ce35 LF |
1009 | rate_idx = 1; |
1010 | break; | |
e0e776a3 | 1011 | case DESC_RATE12M: |
7ad0ce35 LF |
1012 | rate_idx = 2; |
1013 | break; | |
e0e776a3 | 1014 | case DESC_RATE18M: |
7ad0ce35 LF |
1015 | rate_idx = 3; |
1016 | break; | |
e0e776a3 | 1017 | case DESC_RATE24M: |
7ad0ce35 LF |
1018 | rate_idx = 4; |
1019 | break; | |
e0e776a3 | 1020 | case DESC_RATE36M: |
7ad0ce35 LF |
1021 | rate_idx = 5; |
1022 | break; | |
e0e776a3 | 1023 | case DESC_RATE48M: |
7ad0ce35 LF |
1024 | rate_idx = 6; |
1025 | break; | |
e0e776a3 | 1026 | case DESC_RATE54M: |
7ad0ce35 LF |
1027 | rate_idx = 7; |
1028 | break; | |
1029 | default: | |
1030 | rate_idx = 0; | |
1031 | break; | |
1032 | } | |
1033 | } | |
7ad0ce35 | 1034 | } else { |
7ad0ce35 | 1035 | switch (desc_rate) { |
e0e776a3 | 1036 | case DESC_RATEMCS0: |
7ad0ce35 LF |
1037 | rate_idx = 0; |
1038 | break; | |
e0e776a3 | 1039 | case DESC_RATEMCS1: |
7ad0ce35 LF |
1040 | rate_idx = 1; |
1041 | break; | |
e0e776a3 | 1042 | case DESC_RATEMCS2: |
7ad0ce35 LF |
1043 | rate_idx = 2; |
1044 | break; | |
e0e776a3 | 1045 | case DESC_RATEMCS3: |
7ad0ce35 LF |
1046 | rate_idx = 3; |
1047 | break; | |
e0e776a3 | 1048 | case DESC_RATEMCS4: |
7ad0ce35 LF |
1049 | rate_idx = 4; |
1050 | break; | |
e0e776a3 | 1051 | case DESC_RATEMCS5: |
7ad0ce35 LF |
1052 | rate_idx = 5; |
1053 | break; | |
e0e776a3 | 1054 | case DESC_RATEMCS6: |
7ad0ce35 LF |
1055 | rate_idx = 6; |
1056 | break; | |
e0e776a3 | 1057 | case DESC_RATEMCS7: |
7ad0ce35 LF |
1058 | rate_idx = 7; |
1059 | break; | |
e0e776a3 | 1060 | case DESC_RATEMCS8: |
7ad0ce35 LF |
1061 | rate_idx = 8; |
1062 | break; | |
e0e776a3 | 1063 | case DESC_RATEMCS9: |
7ad0ce35 LF |
1064 | rate_idx = 9; |
1065 | break; | |
e0e776a3 | 1066 | case DESC_RATEMCS10: |
7ad0ce35 LF |
1067 | rate_idx = 10; |
1068 | break; | |
e0e776a3 | 1069 | case DESC_RATEMCS11: |
7ad0ce35 LF |
1070 | rate_idx = 11; |
1071 | break; | |
e0e776a3 | 1072 | case DESC_RATEMCS12: |
7ad0ce35 LF |
1073 | rate_idx = 12; |
1074 | break; | |
e0e776a3 | 1075 | case DESC_RATEMCS13: |
7ad0ce35 LF |
1076 | rate_idx = 13; |
1077 | break; | |
e0e776a3 | 1078 | case DESC_RATEMCS14: |
7ad0ce35 LF |
1079 | rate_idx = 14; |
1080 | break; | |
e0e776a3 | 1081 | case DESC_RATEMCS15: |
7ad0ce35 LF |
1082 | rate_idx = 15; |
1083 | break; | |
1084 | default: | |
1085 | rate_idx = 0; | |
1086 | break; | |
1087 | } | |
1088 | } | |
1089 | return rate_idx; | |
1090 | } | |
1091 | EXPORT_SYMBOL(rtlwifi_rate_mapping); | |
1092 | ||
0c817338 LF |
1093 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
1094 | struct ieee80211_tx_info *info, | |
acd48572 | 1095 | struct ieee80211_sta *sta, |
0c817338 LF |
1096 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
1097 | { | |
1098 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1099 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); | |
acd48572 | 1100 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
0c817338 | 1101 | struct ieee80211_rate *txrate; |
9afa2e44 | 1102 | __le16 fc = rtl_get_fc(skb); |
0c817338 | 1103 | |
acd48572 | 1104 | txrate = ieee80211_get_tx_rate(hw, info); |
e89f7690 LF |
1105 | if (txrate) |
1106 | tcb_desc->hw_rate = txrate->hw_value; | |
0c817338 LF |
1107 | |
1108 | if (ieee80211_is_data(fc)) { | |
0c817338 | 1109 | /* |
acd48572 | 1110 | *we set data rate INX 0 |
0c817338 LF |
1111 | *in rtl_rc.c if skb is special data or |
1112 | *mgt which need low data rate. | |
1113 | */ | |
1114 | ||
1115 | /* | |
1116 | *So tcb_desc->hw_rate is just used for | |
1117 | *special data and mgt frames | |
1118 | */ | |
09e92f0b | 1119 | if (info->control.rates[0].idx == 0 || |
acd48572 | 1120 | ieee80211_is_nullfunc(fc)) { |
0c817338 | 1121 | tcb_desc->use_driver_rate = true; |
acd48572 | 1122 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
0c817338 | 1123 | |
0c817338 LF |
1124 | tcb_desc->disable_ratefallback = 1; |
1125 | } else { | |
1126 | /* | |
1127 | *because hw will nerver use hw_rate | |
1128 | *when tcb_desc->use_driver_rate = false | |
1129 | *so we never set highest N rate here, | |
25985edc | 1130 | *and N rate will all be controlled by FW |
0c817338 LF |
1131 | *when tcb_desc->use_driver_rate = false |
1132 | */ | |
9afa2e44 LF |
1133 | if (sta && sta->vht_cap.vht_supported) { |
1134 | tcb_desc->hw_rate = | |
1135 | _rtl_get_vht_highest_n_rate(hw, sta); | |
0c817338 | 1136 | } else { |
9afa2e44 | 1137 | if (sta && (sta->ht_cap.ht_supported)) { |
0c817338 | 1138 | tcb_desc->hw_rate = |
9afa2e44 | 1139 | _rtl_get_highest_n_rate(hw, sta); |
0c817338 | 1140 | } else { |
9afa2e44 LF |
1141 | if (rtlmac->mode == WIRELESS_MODE_B) { |
1142 | tcb_desc->hw_rate = | |
1143 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; | |
1144 | } else { | |
1145 | tcb_desc->hw_rate = | |
1146 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; | |
1147 | } | |
0c817338 LF |
1148 | } |
1149 | } | |
1150 | } | |
1151 | ||
1152 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) | |
7ea47240 | 1153 | tcb_desc->multicast = 1; |
0c817338 | 1154 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
7ea47240 | 1155 | tcb_desc->broadcast = 1; |
0c817338 | 1156 | |
acd48572 C |
1157 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
1158 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); | |
0c817338 | 1159 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
acd48572 | 1160 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
0c817338 LF |
1161 | _rtl_query_protection_mode(hw, tcb_desc, info); |
1162 | } else { | |
1163 | tcb_desc->use_driver_rate = true; | |
acd48572 | 1164 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
0c817338 LF |
1165 | tcb_desc->disable_ratefallback = 1; |
1166 | tcb_desc->mac_id = 0; | |
acd48572 | 1167 | tcb_desc->packet_bw = false; |
0c817338 LF |
1168 | } |
1169 | } | |
1170 | EXPORT_SYMBOL(rtl_get_tcb_desc); | |
1171 | ||
9afa2e44 | 1172 | bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) |
26634c4b | 1173 | { |
9afa2e44 | 1174 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
26634c4b | 1175 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
9afa2e44 | 1176 | __le16 fc = rtl_get_fc(skb); |
26634c4b | 1177 | |
9afa2e44 LF |
1178 | if (rtlpriv->dm.supp_phymode_switch && |
1179 | mac->link_state < MAC80211_LINKED && | |
1180 | (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) { | |
1181 | if (rtlpriv->cfg->ops->chk_switch_dmdp) | |
1182 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); | |
26634c4b | 1183 | } |
9afa2e44 LF |
1184 | if (ieee80211_is_auth(fc)) { |
1185 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); | |
1186 | rtl_ips_nic_on(hw); | |
1187 | ||
1188 | mac->link_state = MAC80211_LINKING; | |
1189 | /* Dul mac */ | |
1190 | rtlpriv->phy.need_iqk = true; | |
26634c4b | 1191 | |
26634c4b | 1192 | } |
9afa2e44 LF |
1193 | |
1194 | return true; | |
1195 | } | |
1196 | EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc); | |
1197 | ||
1198 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa, | |
1199 | u8 *bssid, u16 tid); | |
1200 | ||
1201 | static void process_agg_start(struct ieee80211_hw *hw, | |
1202 | struct ieee80211_hdr *hdr, u16 tid) | |
1203 | { | |
1204 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1205 | struct ieee80211_rx_status rx_status = { 0 }; | |
1206 | struct sk_buff *skb_delba = NULL; | |
1207 | ||
1208 | skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); | |
1209 | if (skb_delba) { | |
1210 | rx_status.freq = hw->conf.chandef.chan->center_freq; | |
1211 | rx_status.band = hw->conf.chandef.chan->band; | |
1212 | rx_status.flag |= RX_FLAG_DECRYPTED; | |
1213 | rx_status.flag |= RX_FLAG_MACTIME_START; | |
1214 | rx_status.rate_idx = 0; | |
1215 | rx_status.signal = 50 + 10; | |
1216 | memcpy(IEEE80211_SKB_RXCB(skb_delba), | |
1217 | &rx_status, sizeof(rx_status)); | |
1218 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, | |
1219 | "fake del\n", | |
1220 | skb_delba->data, | |
1221 | skb_delba->len); | |
1222 | ieee80211_rx_irqsafe(hw, skb_delba); | |
26634c4b | 1223 | } |
26634c4b LF |
1224 | } |
1225 | ||
0c817338 LF |
1226 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
1227 | { | |
1228 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
acd48572 | 1229 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
0c817338 | 1230 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
9afa2e44 LF |
1231 | __le16 fc = rtl_get_fc(skb); |
1232 | u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN)); | |
0c817338 LF |
1233 | u8 category; |
1234 | ||
1235 | if (!ieee80211_is_action(fc)) | |
1236 | return true; | |
1237 | ||
1238 | category = *act; | |
1239 | act++; | |
1240 | switch (category) { | |
1241 | case ACT_CAT_BA: | |
1242 | switch (*act) { | |
1243 | case ACT_ADDBAREQ: | |
1244 | if (mac->act_scanning) | |
1245 | return false; | |
1246 | ||
1247 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | |
9afa2e44 LF |
1248 | "%s ACT_ADDBAREQ From :%pM\n", |
1249 | is_tx ? "Tx" : "Rx", hdr->addr2); | |
26634c4b | 1250 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", |
9afa2e44 LF |
1251 | skb->data, skb->len); |
1252 | if (!is_tx) { | |
1253 | struct ieee80211_sta *sta = NULL; | |
1254 | struct rtl_sta_info *sta_entry = NULL; | |
1255 | struct rtl_tid_data *tid_data; | |
1256 | struct ieee80211_mgmt *mgmt = (void *)skb->data; | |
1257 | u16 capab = 0, tid = 0; | |
1258 | ||
1259 | rcu_read_lock(); | |
1260 | sta = rtl_find_sta(hw, hdr->addr3); | |
1261 | if (sta == NULL) { | |
1262 | RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV, | |
1263 | DBG_DMESG, "sta is NULL\n"); | |
1264 | rcu_read_unlock(); | |
1265 | return true; | |
1266 | } | |
1267 | ||
1268 | sta_entry = | |
1269 | (struct rtl_sta_info *)sta->drv_priv; | |
1270 | if (!sta_entry) { | |
1271 | rcu_read_unlock(); | |
26634c4b | 1272 | return true; |
9afa2e44 LF |
1273 | } |
1274 | capab = | |
1275 | le16_to_cpu(mgmt->u.action.u.addba_req.capab); | |
1276 | tid = (capab & | |
1277 | IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; | |
1278 | tid_data = &sta_entry->tids[tid]; | |
1279 | if (tid_data->agg.rx_agg_state == | |
1280 | RTL_RX_AGG_START) | |
1281 | process_agg_start(hw, hdr, tid); | |
1282 | rcu_read_unlock(); | |
1283 | } | |
0c817338 LF |
1284 | break; |
1285 | case ACT_ADDBARSP: | |
1286 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | |
f30d7507 | 1287 | "%s ACT_ADDBARSP From :%pM\n", |
9afa2e44 | 1288 | is_tx ? "Tx" : "Rx", hdr->addr2); |
0c817338 LF |
1289 | break; |
1290 | case ACT_DELBA: | |
1291 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | |
f30d7507 | 1292 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
0c817338 LF |
1293 | break; |
1294 | } | |
1295 | break; | |
1296 | default: | |
1297 | break; | |
1298 | } | |
1299 | ||
1300 | return true; | |
1301 | } | |
6f334c2b | 1302 | EXPORT_SYMBOL_GPL(rtl_action_proc); |
0c817338 | 1303 | |
9afa2e44 LF |
1304 | static void setup_arp_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc) |
1305 | { | |
1306 | rtlpriv->ra.is_special_data = true; | |
1307 | if (rtlpriv->cfg->ops->get_btc_status()) | |
1308 | rtlpriv->btcoexist.btc_ops->btc_special_packet_notify( | |
1309 | rtlpriv, 1); | |
1310 | rtlpriv->enter_ps = false; | |
1311 | schedule_work(&rtlpriv->works.lps_change_work); | |
1312 | ppsc->last_delaylps_stamp_jiffies = jiffies; | |
1313 | } | |
1314 | ||
0c817338 | 1315 | /*should call before software enc*/ |
cad737df TY |
1316 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx, |
1317 | bool is_enc) | |
0c817338 LF |
1318 | { |
1319 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
0c817338 | 1320 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
acd48572 | 1321 | __le16 fc = rtl_get_fc(skb); |
0c817338 LF |
1322 | u16 ether_type; |
1323 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); | |
9afa2e44 LF |
1324 | u8 encrypt_header_len = 0; |
1325 | u8 offset; | |
0c817338 LF |
1326 | const struct iphdr *ip; |
1327 | ||
1328 | if (!ieee80211_is_data(fc)) | |
9afa2e44 | 1329 | goto end; |
0c5d63f0 | 1330 | |
9afa2e44 LF |
1331 | switch (rtlpriv->sec.pairwise_enc_algorithm) { |
1332 | case WEP40_ENCRYPTION: | |
1333 | case WEP104_ENCRYPTION: | |
1334 | encrypt_header_len = 4;/*WEP_IV_LEN*/ | |
0c5d63f0 | 1335 | break; |
9afa2e44 LF |
1336 | case TKIP_ENCRYPTION: |
1337 | encrypt_header_len = 8;/*TKIP_IV_LEN*/ | |
0c5d63f0 | 1338 | break; |
9afa2e44 LF |
1339 | case AESCCMP_ENCRYPTION: |
1340 | encrypt_header_len = 8;/*CCMP_HDR_LEN;*/ | |
0c5d63f0 | 1341 | break; |
0c5d63f0 | 1342 | default: |
9afa2e44 | 1343 | break; |
0c817338 | 1344 | } |
9afa2e44 | 1345 | |
cad737df TY |
1346 | offset = mac_hdr_len + SNAP_SIZE; |
1347 | if (is_enc) | |
1348 | offset += encrypt_header_len; | |
9afa2e44 LF |
1349 | ether_type = be16_to_cpup((__be16 *)(skb->data + offset)); |
1350 | ||
1351 | if (ETH_P_IP == ether_type) { | |
1352 | ip = (struct iphdr *)((u8 *)skb->data + offset + | |
1353 | PROTOC_TYPE_SIZE); | |
1354 | if (IPPROTO_UDP == ip->protocol) { | |
1355 | struct udphdr *udp = (struct udphdr *)((u8 *)ip + | |
1356 | (ip->ihl << 2)); | |
1357 | if (((((u8 *)udp)[1] == 68) && | |
1358 | (((u8 *)udp)[3] == 67)) || | |
1359 | ((((u8 *)udp)[1] == 67) && | |
1360 | (((u8 *)udp)[3] == 68))) { | |
1361 | /* 68 : UDP BOOTP client | |
1362 | * 67 : UDP BOOTP server | |
1363 | */ | |
1364 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), | |
1365 | DBG_DMESG, "dhcp %s !!\n", | |
1366 | (is_tx) ? "Tx" : "Rx"); | |
1367 | ||
1368 | if (is_tx) | |
1369 | setup_arp_tx(rtlpriv, ppsc); | |
1370 | return true; | |
1371 | } | |
1372 | } | |
1373 | } else if (ETH_P_ARP == ether_type) { | |
1374 | if (is_tx) | |
1375 | setup_arp_tx(rtlpriv, ppsc); | |
1376 | ||
1377 | return true; | |
1378 | } else if (ETH_P_PAE == ether_type) { | |
1379 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, | |
1380 | "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx"); | |
1381 | ||
1382 | if (is_tx) { | |
1383 | rtlpriv->ra.is_special_data = true; | |
1384 | rtlpriv->enter_ps = false; | |
1385 | schedule_work(&rtlpriv->works.lps_change_work); | |
1386 | ppsc->last_delaylps_stamp_jiffies = jiffies; | |
1387 | } | |
1388 | ||
1389 | return true; | |
c8f03455 LF |
1390 | } else if (ETH_P_IPV6 == ether_type) { |
1391 | /* TODO: Handle any IPv6 cases that need special handling. | |
1392 | * For now, always return false | |
1393 | */ | |
1394 | goto end; | |
0c5d63f0 | 1395 | } |
9afa2e44 LF |
1396 | |
1397 | end: | |
1398 | rtlpriv->ra.is_special_data = false; | |
1399 | return false; | |
0c817338 | 1400 | } |
6f334c2b | 1401 | EXPORT_SYMBOL_GPL(rtl_is_special_data); |
0c817338 LF |
1402 | |
1403 | /********************************************************* | |
1404 | * | |
1405 | * functions called by core.c | |
1406 | * | |
1407 | *********************************************************/ | |
f7953b2a LF |
1408 | int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
1409 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | |
0c817338 LF |
1410 | { |
1411 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1412 | struct rtl_tid_data *tid_data; | |
acd48572 | 1413 | struct rtl_sta_info *sta_entry = NULL; |
0c817338 | 1414 | |
acd48572 C |
1415 | if (sta == NULL) |
1416 | return -EINVAL; | |
0c817338 LF |
1417 | |
1418 | if (unlikely(tid >= MAX_TID_COUNT)) | |
1419 | return -EINVAL; | |
1420 | ||
acd48572 C |
1421 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
1422 | if (!sta_entry) | |
0c817338 | 1423 | return -ENXIO; |
acd48572 | 1424 | tid_data = &sta_entry->tids[tid]; |
0c817338 | 1425 | |
9afa2e44 LF |
1426 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
1427 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, | |
1428 | tid_data->seq_number); | |
0c817338 | 1429 | |
acd48572 C |
1430 | *ssn = tid_data->seq_number; |
1431 | tid_data->agg.agg_state = RTL_AGG_START; | |
0c817338 | 1432 | |
9afa2e44 | 1433 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
0c817338 LF |
1434 | return 0; |
1435 | } | |
1436 | ||
f7953b2a LF |
1437 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
1438 | struct ieee80211_sta *sta, u16 tid) | |
0c817338 | 1439 | { |
0c817338 | 1440 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
9afa2e44 | 1441 | struct rtl_tid_data *tid_data; |
acd48572 | 1442 | struct rtl_sta_info *sta_entry = NULL; |
0c817338 | 1443 | |
acd48572 C |
1444 | if (sta == NULL) |
1445 | return -EINVAL; | |
0c817338 | 1446 | |
9afa2e44 LF |
1447 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
1448 | "on ra = %pM tid = %d\n", sta->addr, tid); | |
acd48572 | 1449 | |
0c817338 LF |
1450 | if (unlikely(tid >= MAX_TID_COUNT)) |
1451 | return -EINVAL; | |
1452 | ||
acd48572 | 1453 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
9afa2e44 | 1454 | tid_data = &sta_entry->tids[tid]; |
acd48572 | 1455 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
0c817338 | 1456 | |
9afa2e44 | 1457 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
acd48572 C |
1458 | return 0; |
1459 | } | |
1460 | ||
26634c4b LF |
1461 | int rtl_rx_agg_start(struct ieee80211_hw *hw, |
1462 | struct ieee80211_sta *sta, u16 tid) | |
1463 | { | |
1464 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1465 | struct rtl_tid_data *tid_data; | |
1466 | struct rtl_sta_info *sta_entry = NULL; | |
1467 | ||
1468 | if (sta == NULL) | |
1469 | return -EINVAL; | |
1470 | ||
1471 | if (unlikely(tid >= MAX_TID_COUNT)) | |
1472 | return -EINVAL; | |
1473 | ||
1474 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | |
1475 | if (!sta_entry) | |
1476 | return -ENXIO; | |
1477 | tid_data = &sta_entry->tids[tid]; | |
1478 | ||
1479 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, | |
1480 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, | |
1481 | tid_data->seq_number); | |
1482 | ||
1483 | tid_data->agg.rx_agg_state = RTL_RX_AGG_START; | |
1484 | return 0; | |
1485 | } | |
1486 | ||
1487 | int rtl_rx_agg_stop(struct ieee80211_hw *hw, | |
1488 | struct ieee80211_sta *sta, u16 tid) | |
1489 | { | |
1490 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1491 | struct rtl_sta_info *sta_entry = NULL; | |
1492 | ||
1493 | if (sta == NULL) | |
1494 | return -EINVAL; | |
1495 | ||
26634c4b LF |
1496 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
1497 | "on ra = %pM tid = %d\n", sta->addr, tid); | |
1498 | ||
1499 | if (unlikely(tid >= MAX_TID_COUNT)) | |
1500 | return -EINVAL; | |
1501 | ||
1502 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; | |
1503 | sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; | |
1504 | ||
1505 | return 0; | |
1506 | } | |
acd48572 C |
1507 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
1508 | struct ieee80211_sta *sta, u16 tid) | |
1509 | { | |
1510 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
acd48572 | 1511 | struct rtl_sta_info *sta_entry = NULL; |
0c817338 | 1512 | |
acd48572 C |
1513 | if (sta == NULL) |
1514 | return -EINVAL; | |
1515 | ||
9afa2e44 LF |
1516 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
1517 | "on ra = %pM tid = %d\n", sta->addr, tid); | |
0c817338 | 1518 | |
acd48572 C |
1519 | if (unlikely(tid >= MAX_TID_COUNT)) |
1520 | return -EINVAL; | |
0c817338 | 1521 | |
acd48572 | 1522 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
acd48572 | 1523 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
0c817338 LF |
1524 | |
1525 | return 0; | |
1526 | } | |
1527 | ||
1528 | /********************************************************* | |
1529 | * | |
1530 | * wq & timer callback functions | |
1531 | * | |
1532 | *********************************************************/ | |
26634c4b LF |
1533 | /* this function is used for roaming */ |
1534 | void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) | |
1535 | { | |
1536 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1537 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; | |
1538 | ||
1539 | if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) | |
1540 | return; | |
1541 | ||
1542 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) | |
1543 | return; | |
1544 | ||
1545 | /* check if this really is a beacon */ | |
1546 | if (!ieee80211_is_beacon(hdr->frame_control) && | |
1547 | !ieee80211_is_probe_resp(hdr->frame_control)) | |
1548 | return; | |
1549 | ||
1550 | /* min. beacon length + FCS_LEN */ | |
1551 | if (skb->len <= 40 + FCS_LEN) | |
1552 | return; | |
1553 | ||
1554 | /* and only beacons from the associated BSSID, please */ | |
9afa2e44 | 1555 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
26634c4b LF |
1556 | return; |
1557 | ||
1558 | rtlpriv->link_info.bcn_rx_inperiod++; | |
1559 | } | |
6f334c2b | 1560 | EXPORT_SYMBOL_GPL(rtl_beacon_statistic); |
26634c4b | 1561 | |
0c817338 LF |
1562 | void rtl_watchdog_wq_callback(void *data) |
1563 | { | |
1564 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, | |
1565 | struct rtl_works, | |
1566 | watchdog_wq); | |
1567 | struct ieee80211_hw *hw = rtlworks->hw; | |
1568 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1569 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
1570 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
7ea47240 | 1571 | bool busytraffic = false; |
26634c4b LF |
1572 | bool tx_busy_traffic = false; |
1573 | bool rx_busy_traffic = false; | |
7ea47240 LF |
1574 | bool higher_busytraffic = false; |
1575 | bool higher_busyrxtraffic = false; | |
acd48572 | 1576 | u8 idx, tid; |
0c817338 LF |
1577 | u32 rx_cnt_inp4eriod = 0; |
1578 | u32 tx_cnt_inp4eriod = 0; | |
1579 | u32 aver_rx_cnt_inperiod = 0; | |
1580 | u32 aver_tx_cnt_inperiod = 0; | |
acd48572 C |
1581 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
1582 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; | |
0c817338 LF |
1583 | |
1584 | if (is_hal_stop(rtlhal)) | |
1585 | return; | |
1586 | ||
1587 | /* <1> Determine if action frame is allowed */ | |
1588 | if (mac->link_state > MAC80211_NOLINK) { | |
1589 | if (mac->cnt_after_linked < 20) | |
1590 | mac->cnt_after_linked++; | |
1591 | } else { | |
1592 | mac->cnt_after_linked = 0; | |
1593 | } | |
1594 | ||
9afa2e44 | 1595 | /* <2> to check if traffic busy, if |
0c817338 LF |
1596 | * busytraffic we don't change channel |
1597 | */ | |
1598 | if (mac->link_state >= MAC80211_LINKED) { | |
1599 | ||
1600 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ | |
1601 | for (idx = 0; idx <= 2; idx++) { | |
1602 | rtlpriv->link_info.num_rx_in4period[idx] = | |
1603 | rtlpriv->link_info.num_rx_in4period[idx + 1]; | |
1604 | rtlpriv->link_info.num_tx_in4period[idx] = | |
1605 | rtlpriv->link_info.num_tx_in4period[idx + 1]; | |
1606 | } | |
1607 | rtlpriv->link_info.num_rx_in4period[3] = | |
1608 | rtlpriv->link_info.num_rx_inperiod; | |
1609 | rtlpriv->link_info.num_tx_in4period[3] = | |
1610 | rtlpriv->link_info.num_tx_inperiod; | |
1611 | for (idx = 0; idx <= 3; idx++) { | |
1612 | rx_cnt_inp4eriod += | |
1613 | rtlpriv->link_info.num_rx_in4period[idx]; | |
1614 | tx_cnt_inp4eriod += | |
1615 | rtlpriv->link_info.num_tx_in4period[idx]; | |
1616 | } | |
1617 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; | |
1618 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; | |
1619 | ||
1620 | /* (2) check traffic busy */ | |
26634c4b | 1621 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { |
7ea47240 | 1622 | busytraffic = true; |
26634c4b LF |
1623 | if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) |
1624 | rx_busy_traffic = true; | |
1625 | else | |
1626 | tx_busy_traffic = false; | |
1627 | } | |
0c817338 LF |
1628 | |
1629 | /* Higher Tx/Rx data. */ | |
1630 | if (aver_rx_cnt_inperiod > 4000 || | |
1631 | aver_tx_cnt_inperiod > 4000) { | |
7ea47240 | 1632 | higher_busytraffic = true; |
0c817338 LF |
1633 | |
1634 | /* Extremely high Rx data. */ | |
1635 | if (aver_rx_cnt_inperiod > 5000) | |
7ea47240 | 1636 | higher_busyrxtraffic = true; |
acd48572 C |
1637 | } |
1638 | ||
1639 | /* check every tid's tx traffic */ | |
1640 | for (tid = 0; tid <= 7; tid++) { | |
1641 | for (idx = 0; idx <= 2; idx++) | |
1642 | rtlpriv->link_info.tidtx_in4period[tid][idx] = | |
9afa2e44 LF |
1643 | rtlpriv->link_info.tidtx_in4period[tid] |
1644 | [idx + 1]; | |
acd48572 C |
1645 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
1646 | rtlpriv->link_info.tidtx_inperiod[tid]; | |
1647 | ||
1648 | for (idx = 0; idx <= 3; idx++) | |
1649 | tidtx_inp4eriod[tid] += | |
9afa2e44 | 1650 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
acd48572 C |
1651 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
1652 | if (aver_tidtx_inperiod[tid] > 5000) | |
1653 | rtlpriv->link_info.higher_busytxtraffic[tid] = | |
9afa2e44 | 1654 | true; |
0c817338 | 1655 | else |
acd48572 | 1656 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
9afa2e44 | 1657 | false; |
0c817338 LF |
1658 | } |
1659 | ||
1660 | if (((rtlpriv->link_info.num_rx_inperiod + | |
1661 | rtlpriv->link_info.num_tx_inperiod) > 8) || | |
1662 | (rtlpriv->link_info.num_rx_inperiod > 2)) | |
fd09ff95 | 1663 | rtl_lps_leave(hw); |
873ffe15 | 1664 | else |
1665 | rtl_lps_enter(hw); | |
0c817338 LF |
1666 | } |
1667 | ||
1668 | rtlpriv->link_info.num_rx_inperiod = 0; | |
1669 | rtlpriv->link_info.num_tx_inperiod = 0; | |
acd48572 C |
1670 | for (tid = 0; tid <= 7; tid++) |
1671 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; | |
0c817338 | 1672 | |
7ea47240 LF |
1673 | rtlpriv->link_info.busytraffic = busytraffic; |
1674 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; | |
26634c4b LF |
1675 | rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; |
1676 | rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; | |
7ea47240 | 1677 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
0c817338 | 1678 | |
acd48572 | 1679 | /* <3> DM */ |
9afa2e44 LF |
1680 | if (!rtlpriv->cfg->mod_params->disable_watchdog) |
1681 | rtlpriv->cfg->ops->dm_watchdog(hw); | |
26634c4b LF |
1682 | |
1683 | /* <4> roaming */ | |
1684 | if (mac->link_state == MAC80211_LINKED && | |
1685 | mac->opmode == NL80211_IFTYPE_STATION) { | |
1686 | if ((rtlpriv->link_info.bcn_rx_inperiod + | |
9afa2e44 | 1687 | rtlpriv->link_info.num_rx_inperiod) == 0) { |
26634c4b LF |
1688 | rtlpriv->link_info.roam_times++; |
1689 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, | |
1690 | "AP off for %d s\n", | |
9afa2e44 | 1691 | (rtlpriv->link_info.roam_times * 2)); |
26634c4b | 1692 | |
9afa2e44 LF |
1693 | /* if we can't recv beacon for 10s, |
1694 | * we should reconnect this AP | |
26634c4b | 1695 | */ |
9afa2e44 | 1696 | if (rtlpriv->link_info.roam_times >= 5) { |
26634c4b LF |
1697 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
1698 | "AP off, try to reconnect now\n"); | |
1699 | rtlpriv->link_info.roam_times = 0; | |
9afa2e44 LF |
1700 | ieee80211_connection_loss( |
1701 | rtlpriv->mac80211.vif); | |
26634c4b LF |
1702 | } |
1703 | } else { | |
1704 | rtlpriv->link_info.roam_times = 0; | |
1705 | } | |
1706 | } | |
9afa2e44 LF |
1707 | |
1708 | if (rtlpriv->cfg->ops->get_btc_status()) | |
1709 | rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv); | |
1710 | ||
26634c4b | 1711 | rtlpriv->link_info.bcn_rx_inperiod = 0; |
0c817338 LF |
1712 | } |
1713 | ||
1714 | void rtl_watch_dog_timer_callback(unsigned long data) | |
1715 | { | |
1716 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; | |
1717 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1718 | ||
1719 | queue_delayed_work(rtlpriv->works.rtl_wq, | |
1720 | &rtlpriv->works.watchdog_wq, 0); | |
1721 | ||
1722 | mod_timer(&rtlpriv->works.watchdog_timer, | |
1723 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); | |
1724 | } | |
26634c4b LF |
1725 | void rtl_fwevt_wq_callback(void *data) |
1726 | { | |
1727 | struct rtl_works *rtlworks = | |
1728 | container_of_dwork_rtl(data, struct rtl_works, fwevt_wq); | |
1729 | struct ieee80211_hw *hw = rtlworks->hw; | |
1730 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1731 | ||
1732 | rtlpriv->cfg->ops->c2h_command_handle(hw); | |
1733 | } | |
26634c4b LF |
1734 | void rtl_easy_concurrent_retrytimer_callback(unsigned long data) |
1735 | { | |
1736 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; | |
1737 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1738 | struct rtl_priv *buddy_priv = rtlpriv->buddy_priv; | |
1739 | ||
1740 | if (buddy_priv == NULL) | |
1741 | return; | |
1742 | ||
1743 | rtlpriv->cfg->ops->dualmac_easy_concurrent(hw); | |
1744 | } | |
acd48572 C |
1745 | /********************************************************* |
1746 | * | |
1747 | * frame process functions | |
1748 | * | |
1749 | *********************************************************/ | |
1750 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) | |
1751 | { | |
1752 | struct ieee80211_mgmt *mgmt = (void *)data; | |
1753 | u8 *pos, *end; | |
1754 | ||
1755 | pos = (u8 *)mgmt->u.beacon.variable; | |
1756 | end = data + len; | |
1757 | while (pos < end) { | |
1758 | if (pos + 2 + pos[1] > end) | |
1759 | return NULL; | |
1760 | ||
1761 | if (pos[0] == ie) | |
1762 | return pos; | |
1763 | ||
1764 | pos += 2 + pos[1]; | |
1765 | } | |
1766 | return NULL; | |
1767 | } | |
1768 | ||
1769 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ | |
1770 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ | |
d3bb1429 | 1771 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
9afa2e44 LF |
1772 | enum ieee80211_smps_mode smps, |
1773 | u8 *da, u8 *bssid) | |
acd48572 C |
1774 | { |
1775 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | |
1776 | struct sk_buff *skb; | |
1777 | struct ieee80211_mgmt *action_frame; | |
1778 | ||
1779 | /* 27 = header + category + action + smps mode */ | |
1780 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); | |
1781 | if (!skb) | |
1782 | return NULL; | |
1783 | ||
1784 | skb_reserve(skb, hw->extra_tx_headroom); | |
1785 | action_frame = (void *)skb_put(skb, 27); | |
1786 | memset(action_frame, 0, 27); | |
1787 | memcpy(action_frame->da, da, ETH_ALEN); | |
1788 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); | |
1789 | memcpy(action_frame->bssid, bssid, ETH_ALEN); | |
1790 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
1791 | IEEE80211_STYPE_ACTION); | |
1792 | action_frame->u.action.category = WLAN_CATEGORY_HT; | |
1793 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; | |
1794 | switch (smps) { | |
1795 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ | |
1796 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ | |
1797 | WARN_ON(1); | |
9afa2e44 LF |
1798 | /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it. |
1799 | * According to Kernel Code, here is right. | |
1800 | */ | |
acd48572 C |
1801 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
1802 | action_frame->u.action.u.ht_smps.smps_control = | |
1803 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ | |
1804 | break; | |
1805 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ | |
1806 | action_frame->u.action.u.ht_smps.smps_control = | |
1807 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ | |
1808 | break; | |
1809 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ | |
1810 | action_frame->u.action.u.ht_smps.smps_control = | |
1811 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ | |
1812 | break; | |
1813 | } | |
1814 | ||
1815 | return skb; | |
1816 | } | |
1817 | ||
1818 | int rtl_send_smps_action(struct ieee80211_hw *hw, | |
9afa2e44 LF |
1819 | struct ieee80211_sta *sta, |
1820 | enum ieee80211_smps_mode smps) | |
acd48572 C |
1821 | { |
1822 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1823 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
1824 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
26634c4b | 1825 | struct sk_buff *skb = NULL; |
acd48572 | 1826 | struct rtl_tcb_desc tcb_desc; |
26634c4b LF |
1827 | u8 bssid[ETH_ALEN] = {0}; |
1828 | ||
acd48572 C |
1829 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
1830 | ||
1831 | if (rtlpriv->mac80211.act_scanning) | |
1832 | goto err_free; | |
1833 | ||
1834 | if (!sta) | |
1835 | goto err_free; | |
1836 | ||
1837 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) | |
1838 | goto err_free; | |
1839 | ||
1840 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) | |
1841 | goto err_free; | |
1842 | ||
26634c4b LF |
1843 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) |
1844 | memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); | |
1845 | else | |
1846 | memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); | |
1847 | ||
1848 | skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); | |
acd48572 C |
1849 | /* this is a type = mgmt * stype = action frame */ |
1850 | if (skb) { | |
1851 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | |
1852 | struct rtl_sta_info *sta_entry = | |
1853 | (struct rtl_sta_info *) sta->drv_priv; | |
1854 | sta_entry->mimo_ps = smps; | |
9afa2e44 | 1855 | /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */ |
acd48572 C |
1856 | |
1857 | info->control.rates[0].idx = 0; | |
675a0b04 | 1858 | info->band = hw->conf.chandef.chan->band; |
36323f81 | 1859 | rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); |
acd48572 | 1860 | } |
26634c4b LF |
1861 | return 1; |
1862 | ||
acd48572 C |
1863 | err_free: |
1864 | return 0; | |
1865 | } | |
26634c4b LF |
1866 | EXPORT_SYMBOL(rtl_send_smps_action); |
1867 | ||
4f4826da LF |
1868 | void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) |
1869 | { | |
1870 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1871 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | |
1872 | enum io_type iotype; | |
1873 | ||
1874 | if (!is_hal_stop(rtlhal)) { | |
1875 | switch (operation) { | |
1876 | case SCAN_OPT_BACKUP: | |
1877 | iotype = IO_CMD_PAUSE_DM_BY_SCAN; | |
1878 | rtlpriv->cfg->ops->set_hw_reg(hw, | |
1879 | HW_VAR_IO_CMD, | |
1880 | (u8 *)&iotype); | |
1881 | break; | |
1882 | case SCAN_OPT_RESTORE: | |
1883 | iotype = IO_CMD_RESUME_DM_BY_SCAN; | |
1884 | rtlpriv->cfg->ops->set_hw_reg(hw, | |
1885 | HW_VAR_IO_CMD, | |
1886 | (u8 *)&iotype); | |
1887 | break; | |
1888 | default: | |
1889 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | |
1890 | "Unknown Scan Backup operation.\n"); | |
1891 | break; | |
1892 | } | |
1893 | } | |
1894 | } | |
1895 | EXPORT_SYMBOL(rtl_phy_scan_operation_backup); | |
1896 | ||
9afa2e44 LF |
1897 | /* because mac80211 have issues when can receive del ba |
1898 | * so here we just make a fake del_ba if we receive a ba_req | |
1899 | * but rx_agg was opened to let mac80211 release some ba | |
1900 | * related resources, so please this del_ba for tx | |
26634c4b LF |
1901 | */ |
1902 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, | |
1903 | u8 *sa, u8 *bssid, u16 tid) | |
1904 | { | |
1905 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | |
1906 | struct sk_buff *skb; | |
1907 | struct ieee80211_mgmt *action_frame; | |
1908 | u16 params; | |
1909 | ||
1910 | /* 27 = header + category + action + smps mode */ | |
1911 | skb = dev_alloc_skb(34 + hw->extra_tx_headroom); | |
1912 | if (!skb) | |
1913 | return NULL; | |
1914 | ||
1915 | skb_reserve(skb, hw->extra_tx_headroom); | |
1916 | action_frame = (void *)skb_put(skb, 34); | |
1917 | memset(action_frame, 0, 34); | |
1918 | memcpy(action_frame->sa, sa, ETH_ALEN); | |
1919 | memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); | |
1920 | memcpy(action_frame->bssid, bssid, ETH_ALEN); | |
1921 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
1922 | IEEE80211_STYPE_ACTION); | |
1923 | action_frame->u.action.category = WLAN_CATEGORY_BACK; | |
1924 | action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA; | |
1925 | params = (u16)(1 << 11); /* bit 11 initiator */ | |
9afa2e44 | 1926 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
26634c4b LF |
1927 | |
1928 | action_frame->u.action.u.delba.params = cpu_to_le16(params); | |
1929 | action_frame->u.action.u.delba.reason_code = | |
1930 | cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); | |
1931 | ||
1932 | return skb; | |
1933 | } | |
acd48572 C |
1934 | |
1935 | /********************************************************* | |
1936 | * | |
1937 | * IOT functions | |
1938 | * | |
1939 | *********************************************************/ | |
1940 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, | |
9afa2e44 | 1941 | struct octet_string vendor_ie) |
acd48572 C |
1942 | { |
1943 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
1944 | bool matched = false; | |
1945 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; | |
1946 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; | |
1947 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; | |
1948 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; | |
1949 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; | |
1950 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; | |
1951 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; | |
1952 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; | |
1953 | ||
1954 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || | |
1955 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { | |
1956 | rtlpriv->mac80211.vendor = PEER_ATH; | |
1957 | matched = true; | |
1958 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || | |
1959 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || | |
1960 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { | |
1961 | rtlpriv->mac80211.vendor = PEER_BROAD; | |
1962 | matched = true; | |
1963 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { | |
1964 | rtlpriv->mac80211.vendor = PEER_RAL; | |
1965 | matched = true; | |
1966 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { | |
1967 | rtlpriv->mac80211.vendor = PEER_CISCO; | |
1968 | matched = true; | |
1969 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { | |
1970 | rtlpriv->mac80211.vendor = PEER_MARV; | |
1971 | matched = true; | |
1972 | } | |
1973 | ||
1974 | return matched; | |
1975 | } | |
1976 | ||
d3bb1429 | 1977 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
acd48572 C |
1978 | unsigned int len) |
1979 | { | |
1980 | struct ieee80211_mgmt *mgmt = (void *)data; | |
1981 | struct octet_string vendor_ie; | |
1982 | u8 *pos, *end; | |
1983 | ||
1984 | pos = (u8 *)mgmt->u.beacon.variable; | |
1985 | end = data + len; | |
1986 | while (pos < end) { | |
1987 | if (pos[0] == 221) { | |
1988 | vendor_ie.length = pos[1]; | |
1989 | vendor_ie.octet = &pos[2]; | |
1990 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) | |
1991 | return true; | |
1992 | } | |
1993 | ||
1994 | if (pos + 2 + pos[1] > end) | |
1995 | return false; | |
1996 | ||
1997 | pos += 2 + pos[1]; | |
1998 | } | |
1999 | return false; | |
2000 | } | |
2001 | ||
2002 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) | |
2003 | { | |
2004 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
2005 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
2006 | struct ieee80211_hdr *hdr = (void *)data; | |
2007 | u32 vendor = PEER_UNKNOWN; | |
2008 | ||
2009 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; | |
2010 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; | |
2011 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; | |
2012 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; | |
2013 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; | |
2014 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; | |
2015 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; | |
2016 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; | |
2017 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; | |
2018 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; | |
2019 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; | |
2020 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; | |
2021 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; | |
2022 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; | |
2023 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; | |
2024 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; | |
2025 | ||
2026 | if (mac->opmode != NL80211_IFTYPE_STATION) | |
2027 | return; | |
2028 | ||
2029 | if (mac->link_state == MAC80211_NOLINK) { | |
2030 | mac->vendor = PEER_UNKNOWN; | |
2031 | return; | |
2032 | } | |
2033 | ||
2034 | if (mac->cnt_after_linked > 2) | |
2035 | return; | |
2036 | ||
2037 | /* check if this really is a beacon */ | |
2038 | if (!ieee80211_is_beacon(hdr->frame_control)) | |
2039 | return; | |
2040 | ||
2041 | /* min. beacon length + FCS_LEN */ | |
2042 | if (len <= 40 + FCS_LEN) | |
2043 | return; | |
2044 | ||
2045 | /* and only beacons from the associated BSSID, please */ | |
90908e1c | 2046 | if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid)) |
acd48572 C |
2047 | return; |
2048 | ||
2049 | if (rtl_find_221_ie(hw, data, len)) | |
2050 | vendor = mac->vendor; | |
2051 | ||
2052 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || | |
2053 | (memcmp(mac->bssid, ap5_2, 3) == 0) || | |
2054 | (memcmp(mac->bssid, ap5_3, 3) == 0) || | |
2055 | (memcmp(mac->bssid, ap5_4, 3) == 0) || | |
2056 | (memcmp(mac->bssid, ap5_5, 3) == 0) || | |
2057 | (memcmp(mac->bssid, ap5_6, 3) == 0) || | |
2058 | vendor == PEER_ATH) { | |
2059 | vendor = PEER_ATH; | |
f30d7507 | 2060 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
acd48572 C |
2061 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
2062 | (memcmp(mac->bssid, ap4_5, 3) == 0) || | |
2063 | (memcmp(mac->bssid, ap4_1, 3) == 0) || | |
2064 | (memcmp(mac->bssid, ap4_2, 3) == 0) || | |
2065 | (memcmp(mac->bssid, ap4_3, 3) == 0) || | |
2066 | vendor == PEER_RAL) { | |
f30d7507 | 2067 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
acd48572 C |
2068 | vendor = PEER_RAL; |
2069 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || | |
2070 | vendor == PEER_CISCO) { | |
2071 | vendor = PEER_CISCO; | |
f30d7507 | 2072 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
acd48572 C |
2073 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
2074 | (memcmp(mac->bssid, ap3_2, 3) == 0) || | |
2075 | (memcmp(mac->bssid, ap3_3, 3) == 0) || | |
2076 | vendor == PEER_BROAD) { | |
f30d7507 | 2077 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
acd48572 C |
2078 | vendor = PEER_BROAD; |
2079 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || | |
2080 | vendor == PEER_MARV) { | |
2081 | vendor = PEER_MARV; | |
f30d7507 | 2082 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
acd48572 C |
2083 | } |
2084 | ||
2085 | mac->vendor = vendor; | |
2086 | } | |
6f334c2b | 2087 | EXPORT_SYMBOL_GPL(rtl_recognize_peer); |
acd48572 | 2088 | |
0c817338 LF |
2089 | /********************************************************* |
2090 | * | |
2091 | * sysfs functions | |
2092 | * | |
2093 | *********************************************************/ | |
2094 | static ssize_t rtl_show_debug_level(struct device *d, | |
2095 | struct device_attribute *attr, char *buf) | |
2096 | { | |
2097 | struct ieee80211_hw *hw = dev_get_drvdata(d); | |
2098 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
2099 | ||
2100 | return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel); | |
2101 | } | |
2102 | ||
2103 | static ssize_t rtl_store_debug_level(struct device *d, | |
2104 | struct device_attribute *attr, | |
2105 | const char *buf, size_t count) | |
2106 | { | |
2107 | struct ieee80211_hw *hw = dev_get_drvdata(d); | |
2108 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
2109 | unsigned long val; | |
2110 | int ret; | |
2111 | ||
27d7f477 | 2112 | ret = kstrtoul(buf, 0, &val); |
0c817338 | 2113 | if (ret) { |
9afa2e44 LF |
2114 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
2115 | "%s is not in hex or decimal form.\n", buf); | |
0c817338 LF |
2116 | } else { |
2117 | rtlpriv->dbg.global_debuglevel = val; | |
9afa2e44 LF |
2118 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
2119 | "debuglevel:%x\n", | |
2120 | rtlpriv->dbg.global_debuglevel); | |
0c817338 LF |
2121 | } |
2122 | ||
2123 | return strnlen(buf, count); | |
2124 | } | |
2125 | ||
2126 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, | |
2127 | rtl_show_debug_level, rtl_store_debug_level); | |
2128 | ||
2129 | static struct attribute *rtl_sysfs_entries[] = { | |
2130 | ||
2131 | &dev_attr_debug_level.attr, | |
2132 | ||
2133 | NULL | |
2134 | }; | |
2135 | ||
2136 | /* | |
2137 | * "name" is folder name witch will be | |
2138 | * put in device directory like : | |
2139 | * sys/devices/pci0000:00/0000:00:1c.4/ | |
2140 | * 0000:06:00.0/rtl_sysfs | |
2141 | */ | |
2142 | struct attribute_group rtl_attribute_group = { | |
2143 | .name = "rtlsysfs", | |
2144 | .attrs = rtl_sysfs_entries, | |
2145 | }; | |
6f334c2b | 2146 | EXPORT_SYMBOL_GPL(rtl_attribute_group); |
0c817338 LF |
2147 | |
2148 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); | |
2149 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); | |
2150 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); | |
2151 | MODULE_LICENSE("GPL"); | |
2152 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); | |
2153 | ||
6f334c2b LF |
2154 | struct rtl_global_var rtl_global_var = {}; |
2155 | EXPORT_SYMBOL_GPL(rtl_global_var); | |
26634c4b | 2156 | |
0c817338 LF |
2157 | static int __init rtl_core_module_init(void) |
2158 | { | |
375ff4c7 | 2159 | if (rtl_rate_control_register()) |
9afa2e44 | 2160 | pr_err("rtl: Unable to register rtl_rc, use default RC !!\n"); |
acd48572 | 2161 | |
26634c4b | 2162 | /* init some global vars */ |
6f334c2b LF |
2163 | INIT_LIST_HEAD(&rtl_global_var.glb_priv_list); |
2164 | spin_lock_init(&rtl_global_var.glb_list_lock); | |
26634c4b | 2165 | |
0c817338 LF |
2166 | return 0; |
2167 | } | |
2168 | ||
2169 | static void __exit rtl_core_module_exit(void) | |
2170 | { | |
acd48572 | 2171 | /*RC*/ |
375ff4c7 | 2172 | rtl_rate_control_unregister(); |
0c817338 LF |
2173 | } |
2174 | ||
2175 | module_init(rtl_core_module_init); | |
2176 | module_exit(rtl_core_module_exit); |