blob: 074f716020aae4e28d3e8340da846514065a94db [file] [log] [blame]
Larry Finger0c817332010-12-08 11:12:31 -06001/******************************************************************************
2 *
Larry Fingera8d76062012-01-07 20:46:42 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Larry Finger0c817332010-12-08 11:12:31 -06004 *
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 *
Larry Finger0c817332010-12-08 11:12:31 -060014 * 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
Larry Finger0c817332010-12-08 11:12:31 -060026#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"
Larry Finger9afa2e42014-09-22 09:39:21 -050033#include "pci.h"
Larry Fingerd273bb22012-01-27 13:59:25 -060034#include <linux/ip.h>
35#include <linux/module.h>
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -050036#include <linux/udp.h>
Larry Fingerd273bb22012-01-27 13:59:25 -060037
Larry Finger0c817332010-12-08 11:12:31 -060038/*
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010039 *NOTICE!!!: This file will be very big, we should
40 *keep it clear under following roles:
Larry Finger0c817332010-12-08 11:12:31 -060041 *
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010042 *This file include following parts, so, if you add new
Larry Finger0c817332010-12-08 11:12:31 -060043 *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
Chaoming_Liacd48572011-04-25 12:52:54 -050052 *6) IOT functions
53 *7) sysfs functions
Larry Finger26634c42013-03-24 22:06:33 -050054 *8) vif functions
55 *9) ...
Larry Finger0c817332010-12-08 11:12:31 -060056 */
57
58/*********************************************************
59 *
60 * mac80211 init functions
61 *
62 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -050063static struct ieee80211_channel rtl_channeltable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -060064 {.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
Chaoming_Liacd48572011-04-25 12:52:54 -050080static 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
107static struct ieee80211_rate rtl_ratetable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -0600108 {.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
Chaoming_Liacd48572011-04-25 12:52:54 -0500122static 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
Larry Finger0c817332010-12-08 11:12:31 -0600133static const struct ieee80211_supported_band rtl_band_2ghz = {
134 .band = IEEE80211_BAND_2GHZ,
135
Chaoming_Liacd48572011-04-25 12:52:54 -0500136 .channels = rtl_channeltable_2g,
137 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600138
Chaoming_Liacd48572011-04-25 12:52:54 -0500139 .bitrates = rtl_ratetable_2g,
140 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600141
142 .ht_cap = {0},
143};
144
Chaoming_Liacd48572011-04-25 12:52:54 -0500145static struct ieee80211_supported_band rtl_band_5ghz = {
146 .band = IEEE80211_BAND_5GHZ,
147
148 .channels = rtl_channeltable_5g,
149 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
150
151 .bitrates = rtl_ratetable_5g,
152 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
153
154 .ht_cap = {0},
155};
156
157static 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
Larry Finger2a00def2012-07-11 14:32:33 -0500168u8 rtl_tid_to_ac(u8 tid)
Chaoming_Liacd48572011-04-25 12:52:54 -0500169{
170 return tid_to_ac[tid];
171}
Larry Finger6f334c22013-07-12 15:32:15 -0500172EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
Chaoming_Liacd48572011-04-25 12:52:54 -0500173
Larry Finger0c817332010-12-08 11:12:31 -0600174static 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
Chaoming_Liacd48572011-04-25 12:52:54 -0500186 if (rtlpriv->rtlhal.disable_amsdu_8k)
187 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
188
Larry Finger0c817332010-12-08 11:12:31 -0600189 /*
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
Larry Finger26634c42013-03-24 22:06:33 -0500200 /*hw->wiphy->bands[IEEE80211_BAND_2GHZ]
Larry Finger0c817332010-12-08 11:12:31 -0600201 *base on ant_num
202 *rx_mask: RX mask
Larry Finger26634c42013-03-24 22:06:33 -0500203 *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;
Larry Finger0c817332010-12-08 11:12:31 -0600207 *highest supported RX rate
208 */
Larry Finger26634c42013-03-24 22:06:33 -0500209 if (rtlpriv->dm.supp_phymode_switch) {
Larry Finger26634c42013-03-24 22:06:33 -0500210 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
211 "Support phy mode switch\n");
Larry Finger0c817332010-12-08 11:12:31 -0600212
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
Larry Finger17c9ac62011-02-19 16:29:57 -0600217 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
Larry Finger26634c42013-03-24 22:06:33 -0500218 } 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;
Larry Finger0c817332010-12-08 11:12:31 -0600226
Larry Finger26634c42013-03-24 22:06:33 -0500227 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");
Larry Finger0c817332010-12-08 11:12:31 -0600231
Larry Finger26634c42013-03-24 22:06:33 -0500232 ht_cap->mcs.rx_mask[0] = 0xFF;
233 ht_cap->mcs.rx_mask[1] = 0x00;
234 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600235
Larry Finger26634c42013-03-24 22:06:33 -0500236 ht_cap->mcs.rx_highest =
237 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
238 }
Larry Finger0c817332010-12-08 11:12:31 -0600239 }
240}
241
Larry Finger9afa2e42014-09-22 09:39:21 -0500242static 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
Larry Finger0c817332010-12-08 11:12:31 -0600319static void _rtl_init_mac80211(struct ieee80211_hw *hw)
320{
Chaoming_Liacd48572011-04-25 12:52:54 -0500321 struct rtl_priv *rtlpriv = rtl_priv(hw);
322 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600323 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
Larry Finger9afa2e42014-09-22 09:39:21 -0500327 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
328 rtlhal->bandset == BAND_ON_BOTH) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500329 /* 1: 2.4 G bands */
330 /* <1> use mac->bands as mem for hw->wiphy->bands */
331 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600332
Chaoming_Liacd48572011-04-25 12:52:54 -0500333 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
334 * to default value(1T1R) */
335 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
336 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600337
Chaoming_Liacd48572011-04-25 12:52:54 -0500338 /* <3> init ht cap base on ant_num */
339 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600340
Chaoming_Liacd48572011-04-25 12:52:54 -0500341 /* <4> set mac->sband to wiphy->sband */
342 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
343
344 /* 2: 5 G bands */
345 /* <1> use mac->bands as mem for hw->wiphy->bands */
346 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
347
348 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
349 * to default value(1T1R) */
350 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
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
Larry Finger9afa2e42014-09-22 09:39:21 -0500356 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500357 /* <4> set mac->sband to wiphy->sband */
358 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
359 } else {
360 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
361 /* <1> use mac->bands as mem for hw->wiphy->bands */
362 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
363
364 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
365 * to default value(1T1R) */
366 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500367 &rtl_band_2ghz,
368 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500369
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 */
374 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
375 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
376 /* <1> use mac->bands as mem for hw->wiphy->bands */
377 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
378
379 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
380 * to default value(1T1R) */
381 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500382 &rtl_band_5ghz,
383 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500384
385 /* <3> init ht cap base on ant_num */
386 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
387
Larry Finger9afa2e42014-09-22 09:39:21 -0500388 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500389 /* <4> set mac->sband to wiphy->sband */
390 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
391 } else {
Joe Perchesf30d7502012-01-04 19:40:41 -0800392 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
393 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500394 }
395 }
Larry Finger0c817332010-12-08 11:12:31 -0600396 /* <5> set hw caps */
397 hw->flags = IEEE80211_HW_SIGNAL_DBM |
398 IEEE80211_HW_RX_INCLUDES_FCS |
Chaoming_Liacd48572011-04-25 12:52:54 -0500399 IEEE80211_HW_AMPDU_AGGREGATION |
Chaoming Li09e92f02011-10-11 21:28:48 -0500400 IEEE80211_HW_CONNECTION_MONITOR |
401 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
Larry Finger26634c42013-03-24 22:06:33 -0500402 IEEE80211_HW_MFP_CAPABLE |
Larry Finger0c817332010-12-08 11:12:31 -0600403 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
404
Chaoming_Liacd48572011-04-25 12:52:54 -0500405 /* swlps or hwlps has been set in diff chip in init_sw_vars */
406 if (rtlpriv->psc.swctrl_lps)
407 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
408 IEEE80211_HW_PS_NULLFUNC_STACK |
409 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
410 0;
Larry Finger0c817332010-12-08 11:12:31 -0600411 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500412 BIT(NL80211_IFTYPE_AP) |
413 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500414 BIT(NL80211_IFTYPE_ADHOC) |
415 BIT(NL80211_IFTYPE_MESH_POINT) |
416 BIT(NL80211_IFTYPE_P2P_CLIENT) |
417 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger26634c42013-03-24 22:06:33 -0500418 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger9afa2e42014-09-22 09:39:21 -0500419
420 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
421
Larry Finger0c817332010-12-08 11:12:31 -0600422 hw->wiphy->rts_threshold = 2347;
423
424 hw->queues = AC_MAX;
425 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
426
427 /* TODO: Correct this value for our hw */
428 /* TODO: define these hard code value */
Chaoming_Liacd48572011-04-25 12:52:54 -0500429 hw->max_listen_interval = 10;
Larry Finger0c817332010-12-08 11:12:31 -0600430 hw->max_rate_tries = 4;
431 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500432 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600433
Larry Finger9afa2e42014-09-22 09:39:21 -0500434/* wowlan is not supported by kernel if CONFIG_PM is not defined */
435#ifdef CONFIG_PM
436 if (rtlpriv->psc.wo_wlan_mode) {
437 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
438 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
439 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
440 rtlpriv->wowlan.n_patterns =
441 MAX_SUPPORT_WOL_PATTERN_NUM;
442 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
443 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
444 }
445 hw->wiphy->wowlan = &rtlpriv->wowlan;
446 }
447#endif
448
Larry Finger0c817332010-12-08 11:12:31 -0600449 /* <6> mac address */
450 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
451 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
452 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600453 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
454 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
455 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600456 }
Larry Finger0c817332010-12-08 11:12:31 -0600457}
458
459static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
460{
461 struct rtl_priv *rtlpriv = rtl_priv(hw);
462
463 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600464 setup_timer(&rtlpriv->works.watchdog_timer,
465 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500466 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
467 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600468 /* <2> work queue */
469 rtlpriv->works.hw = hw;
Kees Cook598a0df2014-10-20 14:57:08 -0700470 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
Larry Finger0c817332010-12-08 11:12:31 -0600471 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
472 (void *)rtl_watchdog_wq_callback);
473 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
474 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500475 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
476 (void *)rtl_swlps_wq_callback);
477 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
478 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500479 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
480 (void *)rtl_fwevt_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600481
482}
483
484void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
485{
486 struct rtl_priv *rtlpriv = rtl_priv(hw);
487
488 del_timer_sync(&rtlpriv->works.watchdog_timer);
489
490 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
491 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500492 cancel_delayed_work(&rtlpriv->works.ps_work);
493 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500494 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600495}
Larry Finger6f334c22013-07-12 15:32:15 -0500496EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
Larry Finger0c817332010-12-08 11:12:31 -0600497
498void rtl_init_rfkill(struct ieee80211_hw *hw)
499{
500 struct rtl_priv *rtlpriv = rtl_priv(hw);
501
502 bool radio_state;
503 bool blocked;
504 u8 valid = 0;
505
Chaoming Li228bdfc2011-04-10 18:30:23 -0500506 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000507 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500508 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
509
Larry Finger0c817332010-12-08 11:12:31 -0600510 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
511
Larry Fingere6d8a812010-12-21 19:40:40 -0600512 if (valid) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500513 pr_info("rtlwifi: wireless switch is %s\n",
Joe Perches292b1192011-07-20 08:51:35 -0700514 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500515
Larry Finger0c817332010-12-08 11:12:31 -0600516 rtlpriv->rfkill.rfkill_state = radio_state;
517
518 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
519 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
520 }
521
522 wiphy_rfkill_start_polling(hw->wiphy);
523}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600524EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600525
526void rtl_deinit_rfkill(struct ieee80211_hw *hw)
527{
528 wiphy_rfkill_stop_polling(hw->wiphy);
529}
Larry Finger6f334c22013-07-12 15:32:15 -0500530EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600531
532int rtl_init_core(struct ieee80211_hw *hw)
533{
534 struct rtl_priv *rtlpriv = rtl_priv(hw);
535 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
536
537 /* <1> init mac80211 */
538 _rtl_init_mac80211(hw);
539 rtlmac->hw = hw;
540
541 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600542 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600543
544 /*
545 * <3> init CRDA must come after init
546 * mac80211 hw in _rtl_init_mac80211.
547 */
548 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Joe Perchesf30d7502012-01-04 19:40:41 -0800549 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600550 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600551 }
552
553 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600554 mutex_init(&rtlpriv->locks.conf_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600555 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600556 spin_lock_init(&rtlpriv->locks.irq_th_lock);
557 spin_lock_init(&rtlpriv->locks.h2c_lock);
558 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
559 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500560 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500561 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500562 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500563 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
564 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
565 spin_lock_init(&rtlpriv->locks.lps_lock);
Larry Finger9afa2e42014-09-22 09:39:21 -0500566 spin_lock_init(&rtlpriv->locks.iqk_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500567 /* <5> init list */
568 INIT_LIST_HEAD(&rtlpriv->entry_list);
Larry Finger0c817332010-12-08 11:12:31 -0600569
570 rtlmac->link_state = MAC80211_NOLINK;
571
Larry Finger26634c42013-03-24 22:06:33 -0500572 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600573 _rtl_init_deferred_work(hw);
574
575 return 0;
576}
Larry Finger6f334c22013-07-12 15:32:15 -0500577EXPORT_SYMBOL_GPL(rtl_init_core);
Larry Finger0c817332010-12-08 11:12:31 -0600578
579void rtl_deinit_core(struct ieee80211_hw *hw)
580{
Larry Finger0c817332010-12-08 11:12:31 -0600581}
Larry Finger6f334c22013-07-12 15:32:15 -0500582EXPORT_SYMBOL_GPL(rtl_deinit_core);
Larry Finger0c817332010-12-08 11:12:31 -0600583
584void rtl_init_rx_config(struct ieee80211_hw *hw)
585{
586 struct rtl_priv *rtlpriv = rtl_priv(hw);
587 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
588
589 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600590}
Larry Finger6f334c22013-07-12 15:32:15 -0500591EXPORT_SYMBOL_GPL(rtl_init_rx_config);
Larry Finger0c817332010-12-08 11:12:31 -0600592
593/*********************************************************
594 *
595 * tx information functions
596 *
597 *********************************************************/
598static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
599 struct rtl_tcb_desc *tcb_desc,
600 struct ieee80211_tx_info *info)
601{
602 struct rtl_priv *rtlpriv = rtl_priv(hw);
603 u8 rate_flag = info->control.rates[0].flags;
604
605 tcb_desc->use_shortpreamble = false;
606
607 /* 1M can only use Long Preamble. 11B spec */
608 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
609 return;
610 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
611 tcb_desc->use_shortpreamble = true;
612
613 return;
614}
615
616static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500617 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600618 struct rtl_tcb_desc *tcb_desc,
619 struct ieee80211_tx_info *info)
620{
621 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
622 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500623 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -0500624 u8 sgi_80 = 0, bw_80 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600625 tcb_desc->use_shortgi = false;
626
Chaoming_Liacd48572011-04-25 12:52:54 -0500627 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600628 return;
629
Chaoming_Liacd48572011-04-25 12:52:54 -0500630 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
631 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
Larry Finger9afa2e42014-09-22 09:39:21 -0500632 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
Chaoming_Liacd48572011-04-25 12:52:54 -0500633
Larry Finger9afa2e42014-09-22 09:39:21 -0500634 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600635 return;
636
Chaoming_Liacd48572011-04-25 12:52:54 -0500637 if (!sgi_40 && !sgi_20)
638 return;
639
Larry Finger9afa2e42014-09-22 09:39:21 -0500640 if (mac->opmode == NL80211_IFTYPE_STATION) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500641 bw_40 = mac->bw_40;
Larry Finger9afa2e42014-09-22 09:39:21 -0500642 bw_80 = mac->bw_80;
643 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500644 mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500645 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
646 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
647 bw_80 = sta->vht_cap.vht_supported;
648 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500649
Larry Finger9afa2e42014-09-22 09:39:21 -0500650 if (bw_80) {
651 if (sgi_80)
652 tcb_desc->use_shortgi = true;
653 else
654 tcb_desc->use_shortgi = false;
655 } else {
656 if (bw_40 && sgi_40)
657 tcb_desc->use_shortgi = true;
658 else if (!bw_40 && sgi_20)
659 tcb_desc->use_shortgi = true;
660 }
Larry Finger0c817332010-12-08 11:12:31 -0600661
662 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
663 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600664}
665
666static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
667 struct rtl_tcb_desc *tcb_desc,
668 struct ieee80211_tx_info *info)
669{
670 struct rtl_priv *rtlpriv = rtl_priv(hw);
671 u8 rate_flag = info->control.rates[0].flags;
672
673 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600674 tcb_desc->rts_stbc = false;
675 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600676 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600677 tcb_desc->rts_bw = false;
678 tcb_desc->rts_use_shortpreamble = false;
679 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600680
681 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
682 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600683 tcb_desc->rts_enable = true;
684 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600685 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
686 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
687 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600688 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600689 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
690 }
Larry Finger0c817332010-12-08 11:12:31 -0600691}
692
693static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500694 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600695 struct rtl_tcb_desc *tcb_desc)
696{
697 struct rtl_priv *rtlpriv = rtl_priv(hw);
698 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500699 struct rtl_sta_info *sta_entry = NULL;
700 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600701
Chaoming_Liacd48572011-04-25 12:52:54 -0500702 if (sta) {
703 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
704 ratr_index = sta_entry->ratr_index;
705 }
Larry Finger0c817332010-12-08 11:12:31 -0600706 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500707 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600708 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500709 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500710 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600711 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600712 tcb_desc->hw_rate =
713 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
714 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500715 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600716 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500717 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600718 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500719 } else if (mac->opmode == NL80211_IFTYPE_AP) {
720 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600721 }
722 }
723
Larry Finger7ea47242011-02-19 16:28:57 -0600724 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500725 tcb_desc->ratr_index = ratr_index;
726 /* TODO we will differentiate adhoc and station future */
727 if (mac->opmode == NL80211_IFTYPE_STATION ||
728 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500729 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600730
Larry Finger9afa2e42014-09-22 09:39:21 -0500731 if (mac->mode == WIRELESS_MODE_AC_5G)
732 tcb_desc->ratr_index =
733 RATR_INX_WIRELESS_AC_5N;
734 else if (mac->mode == WIRELESS_MODE_AC_24G)
735 tcb_desc->ratr_index =
736 RATR_INX_WIRELESS_AC_24N;
737 else if (mac->mode == WIRELESS_MODE_N_24G)
Chaoming_Liacd48572011-04-25 12:52:54 -0500738 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
739 else if (mac->mode == WIRELESS_MODE_N_5G)
740 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
741 else if (mac->mode & WIRELESS_MODE_G)
742 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
743 else if (mac->mode & WIRELESS_MODE_B)
744 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
745 else if (mac->mode & WIRELESS_MODE_A)
746 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
Larry Finger9afa2e42014-09-22 09:39:21 -0500747
Chaoming_Liacd48572011-04-25 12:52:54 -0500748 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500749 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500750 if (NULL != sta) {
751 if (sta->aid > 0)
752 tcb_desc->mac_id = sta->aid + 1;
753 else
754 tcb_desc->mac_id = 1;
755 } else {
756 tcb_desc->mac_id = 0;
757 }
Larry Finger0c817332010-12-08 11:12:31 -0600758 }
759 }
Larry Finger0c817332010-12-08 11:12:31 -0600760}
761
762static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500763 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600764 struct rtl_tcb_desc *tcb_desc)
765{
766 struct rtl_priv *rtlpriv = rtl_priv(hw);
767 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
768
Larry Finger7ea47242011-02-19 16:28:57 -0600769 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500770 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600771 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500772 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500773 mac->opmode == NL80211_IFTYPE_ADHOC ||
774 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500775 if (!(sta->ht_cap.ht_supported) ||
776 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Chaoming_Liacd48572011-04-25 12:52:54 -0500777 return;
778 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
779 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
780 return;
781 }
Larry Finger7ea47242011-02-19 16:28:57 -0600782 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600783 return;
784
785 /*use legency rate, shall use 20MHz */
786 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
787 return;
788
Larry Finger9afa2e42014-09-22 09:39:21 -0500789 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
790
791 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
792 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
793 if (mac->opmode == NL80211_IFTYPE_AP ||
794 mac->opmode == NL80211_IFTYPE_ADHOC ||
795 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
796 if (!(sta->vht_cap.vht_supported))
797 return;
798 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
799 if (!mac->bw_80 ||
800 !(sta->vht_cap.vht_supported))
801 return;
802 }
803 if (tcb_desc->hw_rate <=
804 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
805 return;
806 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
807 }
Larry Finger0c817332010-12-08 11:12:31 -0600808}
809
Larry Finger9afa2e42014-09-22 09:39:21 -0500810static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
811 struct ieee80211_sta *sta)
Larry Finger0c817332010-12-08 11:12:31 -0600812{
813 struct rtl_priv *rtlpriv = rtl_priv(hw);
814 struct rtl_phy *rtlphy = &(rtlpriv->phy);
815 u8 hw_rate;
Larry Finger9afa2e42014-09-22 09:39:21 -0500816 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
Larry Finger0c817332010-12-08 11:12:31 -0600817
Larry Finger9afa2e42014-09-22 09:39:21 -0500818 if ((get_rf_type(rtlphy) == RF_2T2R) &&
819 (tx_mcs_map & 0x000c) != 0x000c) {
820 if ((tx_mcs_map & 0x000c) >> 2 ==
821 IEEE80211_VHT_MCS_SUPPORT_0_7)
822 hw_rate =
823 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
824 else if ((tx_mcs_map & 0x000c) >> 2 ==
825 IEEE80211_VHT_MCS_SUPPORT_0_8)
826 hw_rate =
827 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
828 else
829 hw_rate =
830 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
831 } else {
832 if ((tx_mcs_map & 0x0003) ==
833 IEEE80211_VHT_MCS_SUPPORT_0_7)
834 hw_rate =
835 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
836 else if ((tx_mcs_map & 0x0003) ==
837 IEEE80211_VHT_MCS_SUPPORT_0_8)
838 hw_rate =
839 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
840 else
841 hw_rate =
842 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
843 }
844
845 return hw_rate;
846}
847
848static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
849 struct ieee80211_sta *sta)
850{
851 struct rtl_priv *rtlpriv = rtl_priv(hw);
852 struct rtl_phy *rtlphy = &rtlpriv->phy;
853 u8 hw_rate;
854
855 if ((get_rf_type(rtlphy) == RF_2T2R) &&
856 (sta->ht_cap.mcs.rx_mask[1] != 0))
Larry Finger0c817332010-12-08 11:12:31 -0600857 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
858 else
859 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
860
861 return hw_rate;
862}
863
Larry Finger7ad0ce32011-08-22 16:50:14 -0500864/* mac80211's rate_idx is like this:
865 *
866 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
867 *
868 * B/G rate:
869 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600870 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500871 *
872 * N rate:
873 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600874 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Finger7ad0ce32011-08-22 16:50:14 -0500875 *
876 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
877 * A rate:
878 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600879 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500880 *
881 * N rate:
882 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600883 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Fingerfd3cb222014-12-18 03:05:40 -0600884 *
885 * VHT rates:
886 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
887 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
Larry Finger7ad0ce32011-08-22 16:50:14 -0500888 */
Larry Fingerfd3cb222014-12-18 03:05:40 -0600889int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
890 u8 desc_rate)
Larry Finger7ad0ce32011-08-22 16:50:14 -0500891{
892 int rate_idx;
893
Larry Fingerfd3cb222014-12-18 03:05:40 -0600894 if (isvht) {
895 switch (desc_rate) {
896 case DESC_RATEVHT1SS_MCS0:
897 rate_idx = 0;
898 break;
899 case DESC_RATEVHT1SS_MCS1:
900 rate_idx = 1;
901 break;
902 case DESC_RATEVHT1SS_MCS2:
903 rate_idx = 2;
904 break;
905 case DESC_RATEVHT1SS_MCS3:
906 rate_idx = 3;
907 break;
908 case DESC_RATEVHT1SS_MCS4:
909 rate_idx = 4;
910 break;
911 case DESC_RATEVHT1SS_MCS5:
912 rate_idx = 5;
913 break;
914 case DESC_RATEVHT1SS_MCS6:
915 rate_idx = 6;
916 break;
917 case DESC_RATEVHT1SS_MCS7:
918 rate_idx = 7;
919 break;
920 case DESC_RATEVHT1SS_MCS8:
921 rate_idx = 8;
922 break;
923 case DESC_RATEVHT1SS_MCS9:
924 rate_idx = 9;
925 break;
926 case DESC_RATEVHT2SS_MCS0:
927 rate_idx = 0;
928 break;
929 case DESC_RATEVHT2SS_MCS1:
930 rate_idx = 1;
931 break;
932 case DESC_RATEVHT2SS_MCS2:
933 rate_idx = 2;
934 break;
935 case DESC_RATEVHT2SS_MCS3:
936 rate_idx = 3;
937 break;
938 case DESC_RATEVHT2SS_MCS4:
939 rate_idx = 4;
940 break;
941 case DESC_RATEVHT2SS_MCS5:
942 rate_idx = 5;
943 break;
944 case DESC_RATEVHT2SS_MCS6:
945 rate_idx = 6;
946 break;
947 case DESC_RATEVHT2SS_MCS7:
948 rate_idx = 7;
949 break;
950 case DESC_RATEVHT2SS_MCS8:
951 rate_idx = 8;
952 break;
953 case DESC_RATEVHT2SS_MCS9:
954 rate_idx = 9;
955 break;
956 default:
957 rate_idx = 0;
958 break;
959 }
960 return rate_idx;
961 }
Larry Finger7ad0ce32011-08-22 16:50:14 -0500962 if (false == isht) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100963 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
Larry Finger7ad0ce32011-08-22 16:50:14 -0500964 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -0600965 case DESC_RATE1M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500966 rate_idx = 0;
967 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600968 case DESC_RATE2M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500969 rate_idx = 1;
970 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600971 case DESC_RATE5_5M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500972 rate_idx = 2;
973 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600974 case DESC_RATE11M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500975 rate_idx = 3;
976 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600977 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500978 rate_idx = 4;
979 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600980 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500981 rate_idx = 5;
982 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600983 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500984 rate_idx = 6;
985 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600986 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500987 rate_idx = 7;
988 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600989 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500990 rate_idx = 8;
991 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600992 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500993 rate_idx = 9;
994 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600995 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500996 rate_idx = 10;
997 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600998 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500999 rate_idx = 11;
1000 break;
1001 default:
1002 rate_idx = 0;
1003 break;
1004 }
1005 } else {
1006 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001007 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001008 rate_idx = 0;
1009 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001010 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001011 rate_idx = 1;
1012 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001013 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001014 rate_idx = 2;
1015 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001016 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001017 rate_idx = 3;
1018 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001019 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001020 rate_idx = 4;
1021 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001022 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001023 rate_idx = 5;
1024 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001025 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001026 rate_idx = 6;
1027 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001028 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001029 rate_idx = 7;
1030 break;
1031 default:
1032 rate_idx = 0;
1033 break;
1034 }
1035 }
Larry Finger7ad0ce32011-08-22 16:50:14 -05001036 } else {
Larry Finger7ad0ce32011-08-22 16:50:14 -05001037 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001038 case DESC_RATEMCS0:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001039 rate_idx = 0;
1040 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001041 case DESC_RATEMCS1:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001042 rate_idx = 1;
1043 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001044 case DESC_RATEMCS2:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001045 rate_idx = 2;
1046 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001047 case DESC_RATEMCS3:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001048 rate_idx = 3;
1049 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001050 case DESC_RATEMCS4:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001051 rate_idx = 4;
1052 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001053 case DESC_RATEMCS5:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001054 rate_idx = 5;
1055 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001056 case DESC_RATEMCS6:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001057 rate_idx = 6;
1058 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001059 case DESC_RATEMCS7:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001060 rate_idx = 7;
1061 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001062 case DESC_RATEMCS8:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001063 rate_idx = 8;
1064 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001065 case DESC_RATEMCS9:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001066 rate_idx = 9;
1067 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001068 case DESC_RATEMCS10:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001069 rate_idx = 10;
1070 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001071 case DESC_RATEMCS11:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001072 rate_idx = 11;
1073 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001074 case DESC_RATEMCS12:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001075 rate_idx = 12;
1076 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001077 case DESC_RATEMCS13:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001078 rate_idx = 13;
1079 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001080 case DESC_RATEMCS14:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001081 rate_idx = 14;
1082 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001083 case DESC_RATEMCS15:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001084 rate_idx = 15;
1085 break;
1086 default:
1087 rate_idx = 0;
1088 break;
1089 }
1090 }
1091 return rate_idx;
1092}
1093EXPORT_SYMBOL(rtlwifi_rate_mapping);
1094
Larry Finger0c817332010-12-08 11:12:31 -06001095void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1096 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -05001097 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -06001098 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1099{
1100 struct rtl_priv *rtlpriv = rtl_priv(hw);
1101 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001102 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001103 struct ieee80211_rate *txrate;
Larry Finger9afa2e42014-09-22 09:39:21 -05001104 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001105
Chaoming_Liacd48572011-04-25 12:52:54 -05001106 txrate = ieee80211_get_tx_rate(hw, info);
Larry Fingere89f7692012-04-06 16:54:17 -05001107 if (txrate)
1108 tcb_desc->hw_rate = txrate->hw_value;
Larry Finger0c817332010-12-08 11:12:31 -06001109
1110 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001111 /*
Chaoming_Liacd48572011-04-25 12:52:54 -05001112 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -06001113 *in rtl_rc.c if skb is special data or
1114 *mgt which need low data rate.
1115 */
1116
1117 /*
1118 *So tcb_desc->hw_rate is just used for
1119 *special data and mgt frames
1120 */
Chaoming Li09e92f02011-10-11 21:28:48 -05001121 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -05001122 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001123 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001124 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001125
Larry Finger0c817332010-12-08 11:12:31 -06001126 tcb_desc->disable_ratefallback = 1;
1127 } else {
1128 /*
1129 *because hw will nerver use hw_rate
1130 *when tcb_desc->use_driver_rate = false
1131 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001132 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -06001133 *when tcb_desc->use_driver_rate = false
1134 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001135 if (sta && sta->vht_cap.vht_supported) {
1136 tcb_desc->hw_rate =
1137 _rtl_get_vht_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001138 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001139 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -06001140 tcb_desc->hw_rate =
Larry Finger9afa2e42014-09-22 09:39:21 -05001141 _rtl_get_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001142 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001143 if (rtlmac->mode == WIRELESS_MODE_B) {
1144 tcb_desc->hw_rate =
1145 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1146 } else {
1147 tcb_desc->hw_rate =
1148 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1149 }
Larry Finger0c817332010-12-08 11:12:31 -06001150 }
1151 }
1152 }
1153
1154 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -06001155 tcb_desc->multicast = 1;
Larry Finger0c817332010-12-08 11:12:31 -06001156 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -06001157 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -06001158
Chaoming_Liacd48572011-04-25 12:52:54 -05001159 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1160 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -06001161 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -05001162 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -06001163 _rtl_query_protection_mode(hw, tcb_desc, info);
1164 } else {
1165 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001166 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001167 tcb_desc->disable_ratefallback = 1;
1168 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001169 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -06001170 }
1171}
1172EXPORT_SYMBOL(rtl_get_tcb_desc);
1173
Larry Finger9afa2e42014-09-22 09:39:21 -05001174bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1175{
1176 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1177 struct rtl_priv *rtlpriv = rtl_priv(hw);
1178 __le16 fc = rtl_get_fc(skb);
1179
1180 if (rtlpriv->dm.supp_phymode_switch &&
1181 mac->link_state < MAC80211_LINKED &&
1182 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1183 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1184 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1185 }
1186 if (ieee80211_is_auth(fc)) {
1187 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1188 rtl_ips_nic_on(hw);
1189
1190 mac->link_state = MAC80211_LINKING;
1191 /* Dul mac */
1192 rtlpriv->phy.need_iqk = true;
1193
1194 }
1195
1196 return true;
1197}
1198EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1199
1200struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1201 u8 *bssid, u16 tid);
1202
1203static void process_agg_start(struct ieee80211_hw *hw,
1204 struct ieee80211_hdr *hdr, u16 tid)
Larry Finger26634c42013-03-24 22:06:33 -05001205{
1206 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001207 struct ieee80211_rx_status rx_status = { 0 };
Larry Finger9afa2e42014-09-22 09:39:21 -05001208 struct sk_buff *skb_delba = NULL;
Larry Finger26634c42013-03-24 22:06:33 -05001209
Larry Finger9afa2e42014-09-22 09:39:21 -05001210 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1211 if (skb_delba) {
1212 rx_status.freq = hw->conf.chandef.chan->center_freq;
1213 rx_status.band = hw->conf.chandef.chan->band;
1214 rx_status.flag |= RX_FLAG_DECRYPTED;
1215 rx_status.flag |= RX_FLAG_MACTIME_START;
1216 rx_status.rate_idx = 0;
1217 rx_status.signal = 50 + 10;
1218 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1219 &rx_status, sizeof(rx_status));
1220 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1221 "fake del\n",
1222 skb_delba->data,
1223 skb_delba->len);
1224 ieee80211_rx_irqsafe(hw, skb_delba);
Larry Finger26634c42013-03-24 22:06:33 -05001225 }
Larry Finger26634c42013-03-24 22:06:33 -05001226}
1227
Larry Finger0c817332010-12-08 11:12:31 -06001228bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1229{
1230 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001231 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001232 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001233 __le16 fc = rtl_get_fc(skb);
1234 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
Larry Finger0c817332010-12-08 11:12:31 -06001235 u8 category;
1236
1237 if (!ieee80211_is_action(fc))
1238 return true;
1239
1240 category = *act;
1241 act++;
1242 switch (category) {
1243 case ACT_CAT_BA:
1244 switch (*act) {
1245 case ACT_ADDBAREQ:
1246 if (mac->act_scanning)
1247 return false;
1248
1249 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Larry Finger9afa2e42014-09-22 09:39:21 -05001250 "%s ACT_ADDBAREQ From :%pM\n",
1251 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001252 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001253 skb->data, skb->len);
1254 if (!is_tx) {
1255 struct ieee80211_sta *sta = NULL;
1256 struct rtl_sta_info *sta_entry = NULL;
1257 struct rtl_tid_data *tid_data;
1258 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1259 u16 capab = 0, tid = 0;
1260
1261 rcu_read_lock();
1262 sta = rtl_find_sta(hw, hdr->addr3);
1263 if (sta == NULL) {
1264 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1265 DBG_DMESG, "sta is NULL\n");
1266 rcu_read_unlock();
Larry Finger26634c42013-03-24 22:06:33 -05001267 return true;
Larry Finger9afa2e42014-09-22 09:39:21 -05001268 }
1269
1270 sta_entry =
1271 (struct rtl_sta_info *)sta->drv_priv;
1272 if (!sta_entry) {
1273 rcu_read_unlock();
1274 return true;
1275 }
1276 capab =
1277 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1278 tid = (capab &
1279 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1280 tid_data = &sta_entry->tids[tid];
1281 if (tid_data->agg.rx_agg_state ==
1282 RTL_RX_AGG_START)
1283 process_agg_start(hw, hdr, tid);
1284 rcu_read_unlock();
1285 }
Larry Finger0c817332010-12-08 11:12:31 -06001286 break;
1287 case ACT_ADDBARSP:
1288 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001289 "%s ACT_ADDBARSP From :%pM\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001290 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001291 break;
1292 case ACT_DELBA:
1293 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001294 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001295 break;
1296 }
1297 break;
1298 default:
1299 break;
1300 }
1301
1302 return true;
1303}
Larry Finger6f334c22013-07-12 15:32:15 -05001304EXPORT_SYMBOL_GPL(rtl_action_proc);
Larry Finger0c817332010-12-08 11:12:31 -06001305
Larry Finger9afa2e42014-09-22 09:39:21 -05001306static void setup_arp_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc)
1307{
1308 rtlpriv->ra.is_special_data = true;
1309 if (rtlpriv->cfg->ops->get_btc_status())
1310 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
1311 rtlpriv, 1);
1312 rtlpriv->enter_ps = false;
1313 schedule_work(&rtlpriv->works.lps_change_work);
1314 ppsc->last_delaylps_stamp_jiffies = jiffies;
1315}
1316
Larry Finger0c817332010-12-08 11:12:31 -06001317/*should call before software enc*/
1318u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1319{
1320 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001321 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001322 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001323 u16 ether_type;
1324 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
Larry Finger9afa2e42014-09-22 09:39:21 -05001325 u8 encrypt_header_len = 0;
1326 u8 offset;
Larry Finger0c817332010-12-08 11:12:31 -06001327 const struct iphdr *ip;
1328
1329 if (!ieee80211_is_data(fc))
Larry Finger9afa2e42014-09-22 09:39:21 -05001330 goto end;
Larry Finger0c817332010-12-08 11:12:31 -06001331
Larry Finger9afa2e42014-09-22 09:39:21 -05001332 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1333 case WEP40_ENCRYPTION:
1334 case WEP104_ENCRYPTION:
1335 encrypt_header_len = 4;/*WEP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001336 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001337 case TKIP_ENCRYPTION:
1338 encrypt_header_len = 8;/*TKIP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001339 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001340 case AESCCMP_ENCRYPTION:
1341 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001342 break;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001343 default:
Larry Finger9afa2e42014-09-22 09:39:21 -05001344 break;
Larry Finger0c817332010-12-08 11:12:31 -06001345 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001346
1347 offset = mac_hdr_len + SNAP_SIZE + encrypt_header_len;
1348 ether_type = be16_to_cpup((__be16 *)(skb->data + offset));
1349
1350 if (ETH_P_IP == ether_type) {
1351 ip = (struct iphdr *)((u8 *)skb->data + offset +
1352 PROTOC_TYPE_SIZE);
1353 if (IPPROTO_UDP == ip->protocol) {
1354 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1355 (ip->ihl << 2));
1356 if (((((u8 *)udp)[1] == 68) &&
1357 (((u8 *)udp)[3] == 67)) ||
1358 ((((u8 *)udp)[1] == 67) &&
1359 (((u8 *)udp)[3] == 68))) {
1360 /* 68 : UDP BOOTP client
1361 * 67 : UDP BOOTP server
1362 */
1363 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1364 DBG_DMESG, "dhcp %s !!\n",
1365 (is_tx) ? "Tx" : "Rx");
1366
1367 if (is_tx)
1368 setup_arp_tx(rtlpriv, ppsc);
1369 return true;
1370 }
1371 }
1372 } else if (ETH_P_ARP == ether_type) {
1373 if (is_tx)
1374 setup_arp_tx(rtlpriv, ppsc);
1375
1376 return true;
1377 } else if (ETH_P_PAE == ether_type) {
1378 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1379 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1380
1381 if (is_tx) {
1382 rtlpriv->ra.is_special_data = true;
1383 rtlpriv->enter_ps = false;
1384 schedule_work(&rtlpriv->works.lps_change_work);
1385 ppsc->last_delaylps_stamp_jiffies = jiffies;
1386 }
1387
1388 return true;
Larry Fingerc8f03452015-02-24 09:23:01 -06001389 } else if (ETH_P_IPV6 == ether_type) {
1390 /* TODO: Handle any IPv6 cases that need special handling.
1391 * For now, always return false
1392 */
1393 goto end;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001394 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001395
1396end:
1397 rtlpriv->ra.is_special_data = false;
1398 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001399}
Larry Finger6f334c22013-07-12 15:32:15 -05001400EXPORT_SYMBOL_GPL(rtl_is_special_data);
Larry Finger0c817332010-12-08 11:12:31 -06001401
1402/*********************************************************
1403 *
1404 * functions called by core.c
1405 *
1406 *********************************************************/
Larry Fingerf7953b22014-09-22 09:39:20 -05001407int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1408 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001409{
1410 struct rtl_priv *rtlpriv = rtl_priv(hw);
1411 struct rtl_tid_data *tid_data;
Chaoming_Liacd48572011-04-25 12:52:54 -05001412 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001413
Chaoming_Liacd48572011-04-25 12:52:54 -05001414 if (sta == NULL)
1415 return -EINVAL;
Larry Finger0c817332010-12-08 11:12:31 -06001416
1417 if (unlikely(tid >= MAX_TID_COUNT))
1418 return -EINVAL;
1419
Chaoming_Liacd48572011-04-25 12:52:54 -05001420 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1421 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001422 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001423 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001424
Larry Finger9afa2e42014-09-22 09:39:21 -05001425 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1426 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1427 tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001428
Chaoming_Liacd48572011-04-25 12:52:54 -05001429 *ssn = tid_data->seq_number;
1430 tid_data->agg.agg_state = RTL_AGG_START;
1431
Larry Finger9afa2e42014-09-22 09:39:21 -05001432 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001433 return 0;
1434}
1435
Larry Fingerf7953b22014-09-22 09:39:20 -05001436int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1437 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001438{
Larry Finger0c817332010-12-08 11:12:31 -06001439 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001440 struct rtl_tid_data *tid_data;
Chaoming_Liacd48572011-04-25 12:52:54 -05001441 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001442
Chaoming_Liacd48572011-04-25 12:52:54 -05001443 if (sta == NULL)
1444 return -EINVAL;
1445
Larry Finger9afa2e42014-09-22 09:39:21 -05001446 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1447 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001448
Larry Finger0c817332010-12-08 11:12:31 -06001449 if (unlikely(tid >= MAX_TID_COUNT))
1450 return -EINVAL;
1451
Chaoming_Liacd48572011-04-25 12:52:54 -05001452 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Larry Finger9afa2e42014-09-22 09:39:21 -05001453 tid_data = &sta_entry->tids[tid];
Chaoming_Liacd48572011-04-25 12:52:54 -05001454 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001455
Larry Finger9afa2e42014-09-22 09:39:21 -05001456 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001457 return 0;
1458}
Larry Finger0c817332010-12-08 11:12:31 -06001459
Larry Finger26634c42013-03-24 22:06:33 -05001460int rtl_rx_agg_start(struct ieee80211_hw *hw,
1461 struct ieee80211_sta *sta, u16 tid)
1462{
1463 struct rtl_priv *rtlpriv = rtl_priv(hw);
1464 struct rtl_tid_data *tid_data;
1465 struct rtl_sta_info *sta_entry = NULL;
1466
1467 if (sta == NULL)
1468 return -EINVAL;
1469
1470 if (unlikely(tid >= MAX_TID_COUNT))
1471 return -EINVAL;
1472
1473 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1474 if (!sta_entry)
1475 return -ENXIO;
1476 tid_data = &sta_entry->tids[tid];
1477
1478 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1479 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1480 tid_data->seq_number);
1481
1482 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1483 return 0;
1484}
1485
1486int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1487 struct ieee80211_sta *sta, u16 tid)
1488{
1489 struct rtl_priv *rtlpriv = rtl_priv(hw);
1490 struct rtl_sta_info *sta_entry = NULL;
1491
1492 if (sta == NULL)
1493 return -EINVAL;
1494
Larry Finger26634c42013-03-24 22:06:33 -05001495 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1496 "on ra = %pM tid = %d\n", sta->addr, tid);
1497
1498 if (unlikely(tid >= MAX_TID_COUNT))
1499 return -EINVAL;
1500
1501 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1502 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1503
1504 return 0;
1505}
Chaoming_Liacd48572011-04-25 12:52:54 -05001506int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1507 struct ieee80211_sta *sta, u16 tid)
1508{
1509 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001510 struct rtl_sta_info *sta_entry = NULL;
1511
1512 if (sta == NULL)
1513 return -EINVAL;
1514
Larry Finger9afa2e42014-09-22 09:39:21 -05001515 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1516 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001517
1518 if (unlikely(tid >= MAX_TID_COUNT))
1519 return -EINVAL;
1520
1521 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001522 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001523
1524 return 0;
1525}
1526
1527/*********************************************************
1528 *
1529 * wq & timer callback functions
1530 *
1531 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001532/* this function is used for roaming */
1533void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1534{
1535 struct rtl_priv *rtlpriv = rtl_priv(hw);
1536 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1537
1538 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1539 return;
1540
1541 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1542 return;
1543
1544 /* check if this really is a beacon */
1545 if (!ieee80211_is_beacon(hdr->frame_control) &&
1546 !ieee80211_is_probe_resp(hdr->frame_control))
1547 return;
1548
1549 /* min. beacon length + FCS_LEN */
1550 if (skb->len <= 40 + FCS_LEN)
1551 return;
1552
1553 /* and only beacons from the associated BSSID, please */
Larry Finger9afa2e42014-09-22 09:39:21 -05001554 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Larry Finger26634c42013-03-24 22:06:33 -05001555 return;
1556
1557 rtlpriv->link_info.bcn_rx_inperiod++;
1558}
Larry Finger6f334c22013-07-12 15:32:15 -05001559EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
Larry Finger26634c42013-03-24 22:06:33 -05001560
Larry Finger0c817332010-12-08 11:12:31 -06001561void rtl_watchdog_wq_callback(void *data)
1562{
1563 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1564 struct rtl_works,
1565 watchdog_wq);
1566 struct ieee80211_hw *hw = rtlworks->hw;
1567 struct rtl_priv *rtlpriv = rtl_priv(hw);
1568 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1569 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001570 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001571 bool tx_busy_traffic = false;
1572 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001573 bool higher_busytraffic = false;
1574 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001575 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001576 u32 rx_cnt_inp4eriod = 0;
1577 u32 tx_cnt_inp4eriod = 0;
1578 u32 aver_rx_cnt_inperiod = 0;
1579 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001580 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1581 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001582
1583 if (is_hal_stop(rtlhal))
1584 return;
1585
1586 /* <1> Determine if action frame is allowed */
1587 if (mac->link_state > MAC80211_NOLINK) {
1588 if (mac->cnt_after_linked < 20)
1589 mac->cnt_after_linked++;
1590 } else {
1591 mac->cnt_after_linked = 0;
1592 }
1593
Larry Finger9afa2e42014-09-22 09:39:21 -05001594 /* <2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001595 * busytraffic we don't change channel
1596 */
1597 if (mac->link_state >= MAC80211_LINKED) {
1598
1599 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1600 for (idx = 0; idx <= 2; idx++) {
1601 rtlpriv->link_info.num_rx_in4period[idx] =
1602 rtlpriv->link_info.num_rx_in4period[idx + 1];
1603 rtlpriv->link_info.num_tx_in4period[idx] =
1604 rtlpriv->link_info.num_tx_in4period[idx + 1];
1605 }
1606 rtlpriv->link_info.num_rx_in4period[3] =
1607 rtlpriv->link_info.num_rx_inperiod;
1608 rtlpriv->link_info.num_tx_in4period[3] =
1609 rtlpriv->link_info.num_tx_inperiod;
1610 for (idx = 0; idx <= 3; idx++) {
1611 rx_cnt_inp4eriod +=
1612 rtlpriv->link_info.num_rx_in4period[idx];
1613 tx_cnt_inp4eriod +=
1614 rtlpriv->link_info.num_tx_in4period[idx];
1615 }
1616 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1617 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1618
1619 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001620 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001621 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001622 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1623 rx_busy_traffic = true;
1624 else
1625 tx_busy_traffic = false;
1626 }
Larry Finger0c817332010-12-08 11:12:31 -06001627
1628 /* Higher Tx/Rx data. */
1629 if (aver_rx_cnt_inperiod > 4000 ||
1630 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001631 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001632
1633 /* Extremely high Rx data. */
1634 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001635 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001636 }
1637
1638 /* check every tid's tx traffic */
1639 for (tid = 0; tid <= 7; tid++) {
1640 for (idx = 0; idx <= 2; idx++)
1641 rtlpriv->link_info.tidtx_in4period[tid][idx] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001642 rtlpriv->link_info.tidtx_in4period[tid]
1643 [idx + 1];
Chaoming_Liacd48572011-04-25 12:52:54 -05001644 rtlpriv->link_info.tidtx_in4period[tid][3] =
1645 rtlpriv->link_info.tidtx_inperiod[tid];
1646
1647 for (idx = 0; idx <= 3; idx++)
1648 tidtx_inp4eriod[tid] +=
Larry Finger9afa2e42014-09-22 09:39:21 -05001649 rtlpriv->link_info.tidtx_in4period[tid][idx];
Chaoming_Liacd48572011-04-25 12:52:54 -05001650 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1651 if (aver_tidtx_inperiod[tid] > 5000)
1652 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001653 true;
Larry Finger0c817332010-12-08 11:12:31 -06001654 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001655 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001656 false;
Larry Finger0c817332010-12-08 11:12:31 -06001657 }
1658
1659 if (((rtlpriv->link_info.num_rx_inperiod +
1660 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1661 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingerfd09ff92014-09-22 09:39:18 -05001662 rtl_lps_enter(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001663 else
Larry Fingerfd09ff92014-09-22 09:39:18 -05001664 rtl_lps_leave(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001665 }
1666
1667 rtlpriv->link_info.num_rx_inperiod = 0;
1668 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001669 for (tid = 0; tid <= 7; tid++)
1670 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001671
Larry Finger7ea47242011-02-19 16:28:57 -06001672 rtlpriv->link_info.busytraffic = busytraffic;
1673 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001674 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1675 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001676 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001677
Chaoming_Liacd48572011-04-25 12:52:54 -05001678 /* <3> DM */
Larry Finger9afa2e42014-09-22 09:39:21 -05001679 if (!rtlpriv->cfg->mod_params->disable_watchdog)
1680 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001681
1682 /* <4> roaming */
1683 if (mac->link_state == MAC80211_LINKED &&
1684 mac->opmode == NL80211_IFTYPE_STATION) {
1685 if ((rtlpriv->link_info.bcn_rx_inperiod +
Larry Finger9afa2e42014-09-22 09:39:21 -05001686 rtlpriv->link_info.num_rx_inperiod) == 0) {
Larry Finger26634c42013-03-24 22:06:33 -05001687 rtlpriv->link_info.roam_times++;
1688 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1689 "AP off for %d s\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001690 (rtlpriv->link_info.roam_times * 2));
Larry Finger26634c42013-03-24 22:06:33 -05001691
Larry Finger9afa2e42014-09-22 09:39:21 -05001692 /* if we can't recv beacon for 10s,
1693 * we should reconnect this AP
Larry Finger26634c42013-03-24 22:06:33 -05001694 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001695 if (rtlpriv->link_info.roam_times >= 5) {
Larry Finger26634c42013-03-24 22:06:33 -05001696 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1697 "AP off, try to reconnect now\n");
1698 rtlpriv->link_info.roam_times = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -05001699 ieee80211_connection_loss(
1700 rtlpriv->mac80211.vif);
Larry Finger26634c42013-03-24 22:06:33 -05001701 }
1702 } else {
1703 rtlpriv->link_info.roam_times = 0;
1704 }
1705 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001706
1707 if (rtlpriv->cfg->ops->get_btc_status())
1708 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
1709
Larry Finger26634c42013-03-24 22:06:33 -05001710 rtlpriv->link_info.bcn_rx_inperiod = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001711}
1712
1713void rtl_watch_dog_timer_callback(unsigned long data)
1714{
1715 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1716 struct rtl_priv *rtlpriv = rtl_priv(hw);
1717
1718 queue_delayed_work(rtlpriv->works.rtl_wq,
1719 &rtlpriv->works.watchdog_wq, 0);
1720
1721 mod_timer(&rtlpriv->works.watchdog_timer,
1722 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1723}
Larry Finger26634c42013-03-24 22:06:33 -05001724void rtl_fwevt_wq_callback(void *data)
1725{
1726 struct rtl_works *rtlworks =
1727 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1728 struct ieee80211_hw *hw = rtlworks->hw;
1729 struct rtl_priv *rtlpriv = rtl_priv(hw);
1730
1731 rtlpriv->cfg->ops->c2h_command_handle(hw);
1732}
Larry Finger26634c42013-03-24 22:06:33 -05001733void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
1734{
1735 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1736 struct rtl_priv *rtlpriv = rtl_priv(hw);
1737 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
1738
1739 if (buddy_priv == NULL)
1740 return;
1741
1742 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
1743}
Larry Finger0c817332010-12-08 11:12:31 -06001744/*********************************************************
1745 *
Chaoming_Liacd48572011-04-25 12:52:54 -05001746 * frame process functions
1747 *
1748 *********************************************************/
1749u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1750{
1751 struct ieee80211_mgmt *mgmt = (void *)data;
1752 u8 *pos, *end;
1753
1754 pos = (u8 *)mgmt->u.beacon.variable;
1755 end = data + len;
1756 while (pos < end) {
1757 if (pos + 2 + pos[1] > end)
1758 return NULL;
1759
1760 if (pos[0] == ie)
1761 return pos;
1762
1763 pos += 2 + pos[1];
1764 }
1765 return NULL;
1766}
1767
1768/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1769/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05001770static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05001771 enum ieee80211_smps_mode smps,
1772 u8 *da, u8 *bssid)
Chaoming_Liacd48572011-04-25 12:52:54 -05001773{
1774 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1775 struct sk_buff *skb;
1776 struct ieee80211_mgmt *action_frame;
1777
1778 /* 27 = header + category + action + smps mode */
1779 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1780 if (!skb)
1781 return NULL;
1782
1783 skb_reserve(skb, hw->extra_tx_headroom);
1784 action_frame = (void *)skb_put(skb, 27);
1785 memset(action_frame, 0, 27);
1786 memcpy(action_frame->da, da, ETH_ALEN);
1787 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1788 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1789 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1790 IEEE80211_STYPE_ACTION);
1791 action_frame->u.action.category = WLAN_CATEGORY_HT;
1792 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1793 switch (smps) {
1794 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1795 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1796 WARN_ON(1);
Larry Finger9afa2e42014-09-22 09:39:21 -05001797 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
1798 * According to Kernel Code, here is right.
1799 */
Chaoming_Liacd48572011-04-25 12:52:54 -05001800 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1801 action_frame->u.action.u.ht_smps.smps_control =
1802 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1803 break;
1804 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1805 action_frame->u.action.u.ht_smps.smps_control =
1806 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1807 break;
1808 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1809 action_frame->u.action.u.ht_smps.smps_control =
1810 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1811 break;
1812 }
1813
1814 return skb;
1815}
1816
1817int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05001818 struct ieee80211_sta *sta,
1819 enum ieee80211_smps_mode smps)
Chaoming_Liacd48572011-04-25 12:52:54 -05001820{
1821 struct rtl_priv *rtlpriv = rtl_priv(hw);
1822 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1823 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05001824 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05001825 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05001826 u8 bssid[ETH_ALEN] = {0};
1827
Chaoming_Liacd48572011-04-25 12:52:54 -05001828 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1829
1830 if (rtlpriv->mac80211.act_scanning)
1831 goto err_free;
1832
1833 if (!sta)
1834 goto err_free;
1835
1836 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1837 goto err_free;
1838
1839 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1840 goto err_free;
1841
Larry Finger26634c42013-03-24 22:06:33 -05001842 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
1843 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
1844 else
1845 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
1846
1847 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001848 /* this is a type = mgmt * stype = action frame */
1849 if (skb) {
1850 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1851 struct rtl_sta_info *sta_entry =
1852 (struct rtl_sta_info *) sta->drv_priv;
1853 sta_entry->mimo_ps = smps;
Larry Finger9afa2e42014-09-22 09:39:21 -05001854 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
Chaoming_Liacd48572011-04-25 12:52:54 -05001855
1856 info->control.rates[0].idx = 0;
Karl Beldan675a0b02013-03-25 16:26:57 +01001857 info->band = hw->conf.chandef.chan->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02001858 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05001859 }
Larry Finger26634c42013-03-24 22:06:33 -05001860 return 1;
1861
Chaoming_Liacd48572011-04-25 12:52:54 -05001862err_free:
1863 return 0;
1864}
Larry Finger26634c42013-03-24 22:06:33 -05001865EXPORT_SYMBOL(rtl_send_smps_action);
1866
Larry Finger4f4826d2013-09-26 13:25:27 -05001867void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
1868{
1869 struct rtl_priv *rtlpriv = rtl_priv(hw);
1870 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1871 enum io_type iotype;
1872
1873 if (!is_hal_stop(rtlhal)) {
1874 switch (operation) {
1875 case SCAN_OPT_BACKUP:
1876 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
1877 rtlpriv->cfg->ops->set_hw_reg(hw,
1878 HW_VAR_IO_CMD,
1879 (u8 *)&iotype);
1880 break;
1881 case SCAN_OPT_RESTORE:
1882 iotype = IO_CMD_RESUME_DM_BY_SCAN;
1883 rtlpriv->cfg->ops->set_hw_reg(hw,
1884 HW_VAR_IO_CMD,
1885 (u8 *)&iotype);
1886 break;
1887 default:
1888 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1889 "Unknown Scan Backup operation.\n");
1890 break;
1891 }
1892 }
1893}
1894EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
1895
Larry Finger9afa2e42014-09-22 09:39:21 -05001896/* because mac80211 have issues when can receive del ba
1897 * so here we just make a fake del_ba if we receive a ba_req
1898 * but rx_agg was opened to let mac80211 release some ba
1899 * related resources, so please this del_ba for tx
Larry Finger26634c42013-03-24 22:06:33 -05001900 */
1901struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
1902 u8 *sa, u8 *bssid, u16 tid)
1903{
1904 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1905 struct sk_buff *skb;
1906 struct ieee80211_mgmt *action_frame;
1907 u16 params;
1908
1909 /* 27 = header + category + action + smps mode */
1910 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
1911 if (!skb)
1912 return NULL;
1913
1914 skb_reserve(skb, hw->extra_tx_headroom);
1915 action_frame = (void *)skb_put(skb, 34);
1916 memset(action_frame, 0, 34);
1917 memcpy(action_frame->sa, sa, ETH_ALEN);
1918 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
1919 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1920 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1921 IEEE80211_STYPE_ACTION);
1922 action_frame->u.action.category = WLAN_CATEGORY_BACK;
1923 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1924 params = (u16)(1 << 11); /* bit 11 initiator */
Larry Finger9afa2e42014-09-22 09:39:21 -05001925 params |= (u16)(tid << 12); /* bit 15:12 TID number */
Larry Finger26634c42013-03-24 22:06:33 -05001926
1927 action_frame->u.action.u.delba.params = cpu_to_le16(params);
1928 action_frame->u.action.u.delba.reason_code =
1929 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
1930
1931 return skb;
1932}
Chaoming_Liacd48572011-04-25 12:52:54 -05001933
1934/*********************************************************
1935 *
1936 * IOT functions
1937 *
1938 *********************************************************/
1939static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05001940 struct octet_string vendor_ie)
Chaoming_Liacd48572011-04-25 12:52:54 -05001941{
1942 struct rtl_priv *rtlpriv = rtl_priv(hw);
1943 bool matched = false;
1944 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1945 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1946 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1947 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1948 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1949 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1950 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1951 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1952
1953 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1954 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1955 rtlpriv->mac80211.vendor = PEER_ATH;
1956 matched = true;
1957 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1958 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1959 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1960 rtlpriv->mac80211.vendor = PEER_BROAD;
1961 matched = true;
1962 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1963 rtlpriv->mac80211.vendor = PEER_RAL;
1964 matched = true;
1965 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1966 rtlpriv->mac80211.vendor = PEER_CISCO;
1967 matched = true;
1968 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1969 rtlpriv->mac80211.vendor = PEER_MARV;
1970 matched = true;
1971 }
1972
1973 return matched;
1974}
1975
Larry Fingerd3bb1422011-04-25 13:23:20 -05001976static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05001977 unsigned int len)
1978{
1979 struct ieee80211_mgmt *mgmt = (void *)data;
1980 struct octet_string vendor_ie;
1981 u8 *pos, *end;
1982
1983 pos = (u8 *)mgmt->u.beacon.variable;
1984 end = data + len;
1985 while (pos < end) {
1986 if (pos[0] == 221) {
1987 vendor_ie.length = pos[1];
1988 vendor_ie.octet = &pos[2];
1989 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1990 return true;
1991 }
1992
1993 if (pos + 2 + pos[1] > end)
1994 return false;
1995
1996 pos += 2 + pos[1];
1997 }
1998 return false;
1999}
2000
2001void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2002{
2003 struct rtl_priv *rtlpriv = rtl_priv(hw);
2004 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2005 struct ieee80211_hdr *hdr = (void *)data;
2006 u32 vendor = PEER_UNKNOWN;
2007
2008 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2009 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2010 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2011 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2012 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2013 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2014 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2015 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2016 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2017 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2018 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2019 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2020 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2021 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2022 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2023 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2024
2025 if (mac->opmode != NL80211_IFTYPE_STATION)
2026 return;
2027
2028 if (mac->link_state == MAC80211_NOLINK) {
2029 mac->vendor = PEER_UNKNOWN;
2030 return;
2031 }
2032
2033 if (mac->cnt_after_linked > 2)
2034 return;
2035
2036 /* check if this really is a beacon */
2037 if (!ieee80211_is_beacon(hdr->frame_control))
2038 return;
2039
2040 /* min. beacon length + FCS_LEN */
2041 if (len <= 40 + FCS_LEN)
2042 return;
2043
2044 /* and only beacons from the associated BSSID, please */
Julia Lawall90908e12013-12-30 19:15:02 +01002045 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05002046 return;
2047
2048 if (rtl_find_221_ie(hw, data, len))
2049 vendor = mac->vendor;
2050
2051 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2052 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2053 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2054 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2055 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2056 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2057 vendor == PEER_ATH) {
2058 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08002059 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002060 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2061 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2062 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2063 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2064 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2065 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002066 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002067 vendor = PEER_RAL;
2068 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2069 vendor == PEER_CISCO) {
2070 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08002071 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002072 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2073 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2074 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2075 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002076 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002077 vendor = PEER_BROAD;
2078 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2079 vendor == PEER_MARV) {
2080 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08002081 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002082 }
2083
2084 mac->vendor = vendor;
2085}
Larry Finger6f334c22013-07-12 15:32:15 -05002086EXPORT_SYMBOL_GPL(rtl_recognize_peer);
Chaoming_Liacd48572011-04-25 12:52:54 -05002087
2088/*********************************************************
2089 *
Larry Finger0c817332010-12-08 11:12:31 -06002090 * sysfs functions
2091 *
2092 *********************************************************/
2093static ssize_t rtl_show_debug_level(struct device *d,
2094 struct device_attribute *attr, char *buf)
2095{
2096 struct ieee80211_hw *hw = dev_get_drvdata(d);
2097 struct rtl_priv *rtlpriv = rtl_priv(hw);
2098
2099 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
2100}
2101
2102static ssize_t rtl_store_debug_level(struct device *d,
2103 struct device_attribute *attr,
2104 const char *buf, size_t count)
2105{
2106 struct ieee80211_hw *hw = dev_get_drvdata(d);
2107 struct rtl_priv *rtlpriv = rtl_priv(hw);
2108 unsigned long val;
2109 int ret;
2110
Jingoo Han27d7f472013-05-31 21:24:06 +00002111 ret = kstrtoul(buf, 0, &val);
Larry Finger0c817332010-12-08 11:12:31 -06002112 if (ret) {
Larry Finger9afa2e42014-09-22 09:39:21 -05002113 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2114 "%s is not in hex or decimal form.\n", buf);
Larry Finger0c817332010-12-08 11:12:31 -06002115 } else {
2116 rtlpriv->dbg.global_debuglevel = val;
Larry Finger9afa2e42014-09-22 09:39:21 -05002117 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
2118 "debuglevel:%x\n",
2119 rtlpriv->dbg.global_debuglevel);
Larry Finger0c817332010-12-08 11:12:31 -06002120 }
2121
2122 return strnlen(buf, count);
2123}
2124
2125static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2126 rtl_show_debug_level, rtl_store_debug_level);
2127
2128static struct attribute *rtl_sysfs_entries[] = {
2129
2130 &dev_attr_debug_level.attr,
2131
2132 NULL
2133};
2134
2135/*
2136 * "name" is folder name witch will be
2137 * put in device directory like :
2138 * sys/devices/pci0000:00/0000:00:1c.4/
2139 * 0000:06:00.0/rtl_sysfs
2140 */
2141struct attribute_group rtl_attribute_group = {
2142 .name = "rtlsysfs",
2143 .attrs = rtl_sysfs_entries,
2144};
Larry Finger6f334c22013-07-12 15:32:15 -05002145EXPORT_SYMBOL_GPL(rtl_attribute_group);
Larry Finger0c817332010-12-08 11:12:31 -06002146
2147MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2148MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2149MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2150MODULE_LICENSE("GPL");
2151MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2152
Larry Finger6f334c22013-07-12 15:32:15 -05002153struct rtl_global_var rtl_global_var = {};
2154EXPORT_SYMBOL_GPL(rtl_global_var);
Larry Finger26634c42013-03-24 22:06:33 -05002155
Larry Finger0c817332010-12-08 11:12:31 -06002156static int __init rtl_core_module_init(void)
2157{
Chaoming Li375ff4c2011-02-28 16:40:28 -06002158 if (rtl_rate_control_register())
Larry Finger9afa2e42014-09-22 09:39:21 -05002159 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002160
Larry Finger26634c42013-03-24 22:06:33 -05002161 /* init some global vars */
Larry Finger6f334c22013-07-12 15:32:15 -05002162 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2163 spin_lock_init(&rtl_global_var.glb_list_lock);
Larry Finger26634c42013-03-24 22:06:33 -05002164
Larry Finger0c817332010-12-08 11:12:31 -06002165 return 0;
2166}
2167
2168static void __exit rtl_core_module_exit(void)
2169{
Chaoming_Liacd48572011-04-25 12:52:54 -05002170 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06002171 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06002172}
2173
2174module_init(rtl_core_module_init);
2175module_exit(rtl_core_module_exit);