blob: 1231ca5879d6135fba5c51cac177622e507c58ed [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 = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200134 .band = NL80211_BAND_2GHZ,
Larry Finger0c817332010-12-08 11:12:31 -0600135
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 = {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200146 .band = NL80211_BAND_5GHZ,
Chaoming_Liacd48572011-04-25 12:52:54 -0500147
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
Johannes Berg57fbcce2016-04-12 15:56:15 +0200200 /*hw->wiphy->bands[NL80211_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 Fingerb03d9682016-12-15 12:22:58 -0600210 pr_info("Support phy mode switch\n");
Larry Finger0c817332010-12-08 11:12:31 -0600211
212 ht_cap->mcs.rx_mask[0] = 0xFF;
213 ht_cap->mcs.rx_mask[1] = 0xFF;
214 ht_cap->mcs.rx_mask[4] = 0x01;
215
Larry Finger17c9ac62011-02-19 16:29:57 -0600216 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
Larry Finger26634c42013-03-24 22:06:33 -0500217 } else {
218 if (get_rf_type(rtlphy) == RF_1T2R ||
219 get_rf_type(rtlphy) == RF_2T2R) {
220 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
221 "1T2R or 2T2R\n");
222 ht_cap->mcs.rx_mask[0] = 0xFF;
223 ht_cap->mcs.rx_mask[1] = 0xFF;
224 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600225
Larry Finger26634c42013-03-24 22:06:33 -0500226 ht_cap->mcs.rx_highest =
227 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
228 } else if (get_rf_type(rtlphy) == RF_1T1R) {
229 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
Larry Finger0c817332010-12-08 11:12:31 -0600230
Larry Finger26634c42013-03-24 22:06:33 -0500231 ht_cap->mcs.rx_mask[0] = 0xFF;
232 ht_cap->mcs.rx_mask[1] = 0x00;
233 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600234
Larry Finger26634c42013-03-24 22:06:33 -0500235 ht_cap->mcs.rx_highest =
236 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
237 }
Larry Finger0c817332010-12-08 11:12:31 -0600238 }
239}
240
Larry Finger9afa2e42014-09-22 09:39:21 -0500241static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw,
242 struct ieee80211_sta_vht_cap *vht_cap)
243{
244 struct rtl_priv *rtlpriv = rtl_priv(hw);
245 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
246
247 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) {
248 u16 mcs_map;
249
250 vht_cap->vht_supported = true;
251 vht_cap->cap =
252 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
253 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
254 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
255 IEEE80211_VHT_CAP_SHORT_GI_80 |
256 IEEE80211_VHT_CAP_TXSTBC |
257 IEEE80211_VHT_CAP_RXSTBC_1 |
258 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
259 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
260 IEEE80211_VHT_CAP_HTC_VHT |
261 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
262 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
263 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
264 0;
265
266 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
267 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
272 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
273 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
274
275 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
276 vht_cap->vht_mcs.rx_highest =
277 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
278 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
279 vht_cap->vht_mcs.tx_highest =
280 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
281 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
282 u16 mcs_map;
283
284 vht_cap->vht_supported = true;
285 vht_cap->cap =
286 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 |
287 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
288 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
289 IEEE80211_VHT_CAP_SHORT_GI_80 |
290 IEEE80211_VHT_CAP_TXSTBC |
291 IEEE80211_VHT_CAP_RXSTBC_1 |
292 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
293 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
294 IEEE80211_VHT_CAP_HTC_VHT |
295 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
296 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
297 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
298 0;
299
300 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
304 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
305 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
306 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
307 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
308
309 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
310 vht_cap->vht_mcs.rx_highest =
311 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
312 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
313 vht_cap->vht_mcs.tx_highest =
314 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
315 }
316}
317
Larry Finger0c817332010-12-08 11:12:31 -0600318static void _rtl_init_mac80211(struct ieee80211_hw *hw)
319{
Chaoming_Liacd48572011-04-25 12:52:54 -0500320 struct rtl_priv *rtlpriv = rtl_priv(hw);
321 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600322 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
323 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
324 struct ieee80211_supported_band *sband;
325
Larry Finger9afa2e42014-09-22 09:39:21 -0500326 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
327 rtlhal->bandset == BAND_ON_BOTH) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500328 /* 1: 2.4 G bands */
329 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200330 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600331
Johannes Berg57fbcce2016-04-12 15:56:15 +0200332 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500333 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200334 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
Chaoming_Liacd48572011-04-25 12:52:54 -0500335 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600336
Chaoming_Liacd48572011-04-25 12:52:54 -0500337 /* <3> init ht cap base on ant_num */
338 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600339
Chaoming_Liacd48572011-04-25 12:52:54 -0500340 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200341 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500342
343 /* 2: 5 G bands */
344 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200345 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500346
Johannes Berg57fbcce2016-04-12 15:56:15 +0200347 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500348 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200349 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
Chaoming_Liacd48572011-04-25 12:52:54 -0500350 sizeof(struct ieee80211_supported_band));
351
352 /* <3> init ht cap base on ant_num */
353 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
354
Larry Finger9afa2e42014-09-22 09:39:21 -0500355 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500356 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200357 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500358 } else {
359 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
360 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200361 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500362
Johannes Berg57fbcce2016-04-12 15:56:15 +0200363 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500364 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200365 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500366 &rtl_band_2ghz,
367 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500368
369 /* <3> init ht cap base on ant_num */
370 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
371
372 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200373 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500374 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
375 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200376 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500377
Johannes Berg57fbcce2016-04-12 15:56:15 +0200378 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500379 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200380 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500381 &rtl_band_5ghz,
382 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500383
384 /* <3> init ht cap base on ant_num */
385 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
386
Larry Finger9afa2e42014-09-22 09:39:21 -0500387 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500388 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200389 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500390 } else {
Larry Fingerb03d9682016-12-15 12:22:58 -0600391 pr_err("Err BAND %d\n",
392 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500393 }
394 }
Larry Finger0c817332010-12-08 11:12:31 -0600395 /* <5> set hw caps */
Johannes Berg30686bf2015-06-02 21:39:54 +0200396 ieee80211_hw_set(hw, SIGNAL_DBM);
397 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
398 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
399 ieee80211_hw_set(hw, CONNECTION_MONITOR);
400 ieee80211_hw_set(hw, MFP_CAPABLE);
401 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
Larry Finger0c817332010-12-08 11:12:31 -0600402
Chaoming_Liacd48572011-04-25 12:52:54 -0500403 /* swlps or hwlps has been set in diff chip in init_sw_vars */
Johannes Berg30686bf2015-06-02 21:39:54 +0200404 if (rtlpriv->psc.swctrl_lps) {
405 ieee80211_hw_set(hw, SUPPORTS_PS);
406 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
407 }
Ping-Ke Shihe332e2a22017-06-18 11:12:42 -0500408 if (rtlpriv->psc.fwctrl_lps) {
409 ieee80211_hw_set(hw, SUPPORTS_PS);
410 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
411 }
Larry Finger0c817332010-12-08 11:12:31 -0600412 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500413 BIT(NL80211_IFTYPE_AP) |
414 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500415 BIT(NL80211_IFTYPE_ADHOC) |
416 BIT(NL80211_IFTYPE_MESH_POINT) |
417 BIT(NL80211_IFTYPE_P2P_CLIENT) |
418 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger26634c42013-03-24 22:06:33 -0500419 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger9afa2e42014-09-22 09:39:21 -0500420
421 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
422
Larry Finger0c817332010-12-08 11:12:31 -0600423 hw->wiphy->rts_threshold = 2347;
424
425 hw->queues = AC_MAX;
426 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
427
428 /* TODO: Correct this value for our hw */
429 /* TODO: define these hard code value */
Chaoming_Liacd48572011-04-25 12:52:54 -0500430 hw->max_listen_interval = 10;
Larry Finger0c817332010-12-08 11:12:31 -0600431 hw->max_rate_tries = 4;
432 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500433 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600434
Larry Finger9afa2e42014-09-22 09:39:21 -0500435/* wowlan is not supported by kernel if CONFIG_PM is not defined */
436#ifdef CONFIG_PM
437 if (rtlpriv->psc.wo_wlan_mode) {
438 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
439 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
440 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
441 rtlpriv->wowlan.n_patterns =
442 MAX_SUPPORT_WOL_PATTERN_NUM;
443 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
444 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
445 }
446 hw->wiphy->wowlan = &rtlpriv->wowlan;
447 }
448#endif
449
Larry Finger0c817332010-12-08 11:12:31 -0600450 /* <6> mac address */
451 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
452 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
453 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600454 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
455 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
456 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600457 }
Larry Finger0c817332010-12-08 11:12:31 -0600458}
459
460static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
461{
462 struct rtl_priv *rtlpriv = rtl_priv(hw);
463
464 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600465 setup_timer(&rtlpriv->works.watchdog_timer,
466 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500467 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
468 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600469 /* <2> work queue */
470 rtlpriv->works.hw = hw;
Kees Cook598a0df2014-10-20 14:57:08 -0700471 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
Larry Finger0c817332010-12-08 11:12:31 -0600472 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
473 (void *)rtl_watchdog_wq_callback);
474 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
475 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500476 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
477 (void *)rtl_swlps_wq_callback);
478 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
479 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500480 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
481 (void *)rtl_fwevt_wq_callback);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600482 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
483 (void *)rtl_c2hcmd_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600484
485}
486
487void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
488{
489 struct rtl_priv *rtlpriv = rtl_priv(hw);
490
491 del_timer_sync(&rtlpriv->works.watchdog_timer);
492
493 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
494 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500495 cancel_delayed_work(&rtlpriv->works.ps_work);
496 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500497 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600498 cancel_delayed_work(&rtlpriv->works.c2hcmd_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600499}
Larry Finger6f334c22013-07-12 15:32:15 -0500500EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
Larry Finger0c817332010-12-08 11:12:31 -0600501
502void rtl_init_rfkill(struct ieee80211_hw *hw)
503{
504 struct rtl_priv *rtlpriv = rtl_priv(hw);
505
506 bool radio_state;
507 bool blocked;
508 u8 valid = 0;
509
Chaoming Li228bdfc2011-04-10 18:30:23 -0500510 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000511 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500512 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
513
Larry Finger0c817332010-12-08 11:12:31 -0600514 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
515
Larry Fingere6d8a812010-12-21 19:40:40 -0600516 if (valid) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500517 pr_info("rtlwifi: wireless switch is %s\n",
Joe Perches292b1192011-07-20 08:51:35 -0700518 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500519
Larry Finger0c817332010-12-08 11:12:31 -0600520 rtlpriv->rfkill.rfkill_state = radio_state;
521
522 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
523 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
524 }
525
526 wiphy_rfkill_start_polling(hw->wiphy);
527}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600528EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600529
530void rtl_deinit_rfkill(struct ieee80211_hw *hw)
531{
532 wiphy_rfkill_stop_polling(hw->wiphy);
533}
Larry Finger6f334c22013-07-12 15:32:15 -0500534EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600535
536int rtl_init_core(struct ieee80211_hw *hw)
537{
538 struct rtl_priv *rtlpriv = rtl_priv(hw);
539 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
540
541 /* <1> init mac80211 */
542 _rtl_init_mac80211(hw);
543 rtlmac->hw = hw;
544
545 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600546 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600547
548 /*
549 * <3> init CRDA must come after init
550 * mac80211 hw in _rtl_init_mac80211.
551 */
552 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Larry Fingerb03d9682016-12-15 12:22:58 -0600553 pr_err("REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600554 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600555 }
556
557 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600558 mutex_init(&rtlpriv->locks.conf_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600559 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600560 spin_lock_init(&rtlpriv->locks.irq_th_lock);
561 spin_lock_init(&rtlpriv->locks.h2c_lock);
562 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
563 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500564 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500565 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600566 spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500567 spin_lock_init(&rtlpriv->locks.scan_list_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500568 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500569 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
570 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
571 spin_lock_init(&rtlpriv->locks.lps_lock);
Larry Finger9afa2e42014-09-22 09:39:21 -0500572 spin_lock_init(&rtlpriv->locks.iqk_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500573 /* <5> init list */
574 INIT_LIST_HEAD(&rtlpriv->entry_list);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600575 INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500576 INIT_LIST_HEAD(&rtlpriv->scan_list.list);
Larry Finger0c817332010-12-08 11:12:31 -0600577
578 rtlmac->link_state = MAC80211_NOLINK;
579
Larry Finger26634c42013-03-24 22:06:33 -0500580 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600581 _rtl_init_deferred_work(hw);
582
583 return 0;
584}
Larry Finger6f334c22013-07-12 15:32:15 -0500585EXPORT_SYMBOL_GPL(rtl_init_core);
Larry Finger0c817332010-12-08 11:12:31 -0600586
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500587static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
588
Larry Finger0c817332010-12-08 11:12:31 -0600589void rtl_deinit_core(struct ieee80211_hw *hw)
590{
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600591 rtl_c2hcmd_launcher(hw, 0);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500592 rtl_free_entries_from_scan_list(hw);
Larry Finger0c817332010-12-08 11:12:31 -0600593}
Larry Finger6f334c22013-07-12 15:32:15 -0500594EXPORT_SYMBOL_GPL(rtl_deinit_core);
Larry Finger0c817332010-12-08 11:12:31 -0600595
596void rtl_init_rx_config(struct ieee80211_hw *hw)
597{
598 struct rtl_priv *rtlpriv = rtl_priv(hw);
599 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
600
601 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600602}
Larry Finger6f334c22013-07-12 15:32:15 -0500603EXPORT_SYMBOL_GPL(rtl_init_rx_config);
Larry Finger0c817332010-12-08 11:12:31 -0600604
605/*********************************************************
606 *
607 * tx information functions
608 *
609 *********************************************************/
610static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
611 struct rtl_tcb_desc *tcb_desc,
612 struct ieee80211_tx_info *info)
613{
614 struct rtl_priv *rtlpriv = rtl_priv(hw);
615 u8 rate_flag = info->control.rates[0].flags;
616
617 tcb_desc->use_shortpreamble = false;
618
619 /* 1M can only use Long Preamble. 11B spec */
620 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
621 return;
622 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
623 tcb_desc->use_shortpreamble = true;
624
625 return;
626}
627
628static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500629 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600630 struct rtl_tcb_desc *tcb_desc,
631 struct ieee80211_tx_info *info)
632{
633 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
634 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500635 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -0500636 u8 sgi_80 = 0, bw_80 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600637 tcb_desc->use_shortgi = false;
638
Chaoming_Liacd48572011-04-25 12:52:54 -0500639 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600640 return;
641
Chaoming_Liacd48572011-04-25 12:52:54 -0500642 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
643 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
Larry Finger9afa2e42014-09-22 09:39:21 -0500644 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
Chaoming_Liacd48572011-04-25 12:52:54 -0500645
Larry Finger9afa2e42014-09-22 09:39:21 -0500646 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600647 return;
648
Chaoming_Liacd48572011-04-25 12:52:54 -0500649 if (!sgi_40 && !sgi_20)
650 return;
651
Larry Finger9afa2e42014-09-22 09:39:21 -0500652 if (mac->opmode == NL80211_IFTYPE_STATION) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500653 bw_40 = mac->bw_40;
Larry Finger9afa2e42014-09-22 09:39:21 -0500654 bw_80 = mac->bw_80;
655 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500656 mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500657 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
658 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
659 bw_80 = sta->vht_cap.vht_supported;
660 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500661
Larry Finger9afa2e42014-09-22 09:39:21 -0500662 if (bw_80) {
663 if (sgi_80)
664 tcb_desc->use_shortgi = true;
665 else
666 tcb_desc->use_shortgi = false;
667 } else {
668 if (bw_40 && sgi_40)
669 tcb_desc->use_shortgi = true;
670 else if (!bw_40 && sgi_20)
671 tcb_desc->use_shortgi = true;
672 }
Larry Finger0c817332010-12-08 11:12:31 -0600673
674 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
675 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600676}
677
678static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
679 struct rtl_tcb_desc *tcb_desc,
680 struct ieee80211_tx_info *info)
681{
682 struct rtl_priv *rtlpriv = rtl_priv(hw);
683 u8 rate_flag = info->control.rates[0].flags;
684
685 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600686 tcb_desc->rts_stbc = false;
687 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600688 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600689 tcb_desc->rts_bw = false;
690 tcb_desc->rts_use_shortpreamble = false;
691 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600692
693 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
694 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600695 tcb_desc->rts_enable = true;
696 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600697 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
698 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
699 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600700 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600701 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
702 }
Larry Finger0c817332010-12-08 11:12:31 -0600703}
704
705static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500706 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600707 struct rtl_tcb_desc *tcb_desc)
708{
709 struct rtl_priv *rtlpriv = rtl_priv(hw);
710 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500711 struct rtl_sta_info *sta_entry = NULL;
712 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600713
Chaoming_Liacd48572011-04-25 12:52:54 -0500714 if (sta) {
715 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
716 ratr_index = sta_entry->ratr_index;
717 }
Larry Finger0c817332010-12-08 11:12:31 -0600718 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500719 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600720 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500721 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500722 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600723 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600724 tcb_desc->hw_rate =
725 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
726 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500727 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600728 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500729 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600730 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500731 } else if (mac->opmode == NL80211_IFTYPE_AP) {
732 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600733 }
734 }
735
Larry Finger7ea47242011-02-19 16:28:57 -0600736 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500737 tcb_desc->ratr_index = ratr_index;
738 /* TODO we will differentiate adhoc and station future */
739 if (mac->opmode == NL80211_IFTYPE_STATION ||
740 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500741 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600742
Larry Finger9afa2e42014-09-22 09:39:21 -0500743 if (mac->mode == WIRELESS_MODE_AC_5G)
744 tcb_desc->ratr_index =
745 RATR_INX_WIRELESS_AC_5N;
746 else if (mac->mode == WIRELESS_MODE_AC_24G)
747 tcb_desc->ratr_index =
748 RATR_INX_WIRELESS_AC_24N;
749 else if (mac->mode == WIRELESS_MODE_N_24G)
Chaoming_Liacd48572011-04-25 12:52:54 -0500750 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
751 else if (mac->mode == WIRELESS_MODE_N_5G)
752 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
753 else if (mac->mode & WIRELESS_MODE_G)
754 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
755 else if (mac->mode & WIRELESS_MODE_B)
756 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
757 else if (mac->mode & WIRELESS_MODE_A)
758 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
Larry Finger9afa2e42014-09-22 09:39:21 -0500759
Chaoming_Liacd48572011-04-25 12:52:54 -0500760 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500761 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500762 if (NULL != sta) {
763 if (sta->aid > 0)
764 tcb_desc->mac_id = sta->aid + 1;
765 else
766 tcb_desc->mac_id = 1;
767 } else {
768 tcb_desc->mac_id = 0;
769 }
Larry Finger0c817332010-12-08 11:12:31 -0600770 }
771 }
Larry Finger0c817332010-12-08 11:12:31 -0600772}
773
774static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500775 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600776 struct rtl_tcb_desc *tcb_desc)
777{
778 struct rtl_priv *rtlpriv = rtl_priv(hw);
779 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
780
Larry Finger7ea47242011-02-19 16:28:57 -0600781 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500782 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600783 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500784 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500785 mac->opmode == NL80211_IFTYPE_ADHOC ||
786 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500787 if (!(sta->ht_cap.ht_supported) ||
788 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Chaoming_Liacd48572011-04-25 12:52:54 -0500789 return;
790 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
791 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
792 return;
793 }
Larry Finger7ea47242011-02-19 16:28:57 -0600794 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600795 return;
796
797 /*use legency rate, shall use 20MHz */
798 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
799 return;
800
Larry Finger9afa2e42014-09-22 09:39:21 -0500801 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
802
803 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
804 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
805 if (mac->opmode == NL80211_IFTYPE_AP ||
806 mac->opmode == NL80211_IFTYPE_ADHOC ||
807 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
808 if (!(sta->vht_cap.vht_supported))
809 return;
810 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
811 if (!mac->bw_80 ||
812 !(sta->vht_cap.vht_supported))
813 return;
814 }
815 if (tcb_desc->hw_rate <=
816 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
817 return;
818 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
819 }
Larry Finger0c817332010-12-08 11:12:31 -0600820}
821
Larry Finger9afa2e42014-09-22 09:39:21 -0500822static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
823 struct ieee80211_sta *sta)
Larry Finger0c817332010-12-08 11:12:31 -0600824{
825 struct rtl_priv *rtlpriv = rtl_priv(hw);
826 struct rtl_phy *rtlphy = &(rtlpriv->phy);
827 u8 hw_rate;
Larry Finger9afa2e42014-09-22 09:39:21 -0500828 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
Larry Finger0c817332010-12-08 11:12:31 -0600829
Larry Finger9afa2e42014-09-22 09:39:21 -0500830 if ((get_rf_type(rtlphy) == RF_2T2R) &&
831 (tx_mcs_map & 0x000c) != 0x000c) {
832 if ((tx_mcs_map & 0x000c) >> 2 ==
833 IEEE80211_VHT_MCS_SUPPORT_0_7)
834 hw_rate =
835 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
836 else if ((tx_mcs_map & 0x000c) >> 2 ==
837 IEEE80211_VHT_MCS_SUPPORT_0_8)
838 hw_rate =
839 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
840 else
841 hw_rate =
842 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
843 } else {
844 if ((tx_mcs_map & 0x0003) ==
845 IEEE80211_VHT_MCS_SUPPORT_0_7)
846 hw_rate =
847 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
848 else if ((tx_mcs_map & 0x0003) ==
849 IEEE80211_VHT_MCS_SUPPORT_0_8)
850 hw_rate =
851 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
852 else
853 hw_rate =
854 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
855 }
856
857 return hw_rate;
858}
859
860static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
861 struct ieee80211_sta *sta)
862{
863 struct rtl_priv *rtlpriv = rtl_priv(hw);
864 struct rtl_phy *rtlphy = &rtlpriv->phy;
865 u8 hw_rate;
866
867 if ((get_rf_type(rtlphy) == RF_2T2R) &&
868 (sta->ht_cap.mcs.rx_mask[1] != 0))
Larry Finger0c817332010-12-08 11:12:31 -0600869 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
870 else
871 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
872
873 return hw_rate;
874}
875
Larry Finger7ad0ce32011-08-22 16:50:14 -0500876/* mac80211's rate_idx is like this:
877 *
Johannes Berg57fbcce2016-04-12 15:56:15 +0200878 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
Larry Finger7ad0ce32011-08-22 16:50:14 -0500879 *
880 * B/G rate:
881 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600882 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500883 *
884 * N rate:
885 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600886 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Finger7ad0ce32011-08-22 16:50:14 -0500887 *
Johannes Berg57fbcce2016-04-12 15:56:15 +0200888 * 5G band:rx_status->band == NL80211_BAND_5GHZ
Larry Finger7ad0ce32011-08-22 16:50:14 -0500889 * A rate:
890 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600891 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500892 *
893 * N rate:
894 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600895 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Fingerfd3cb222014-12-18 03:05:40 -0600896 *
897 * VHT rates:
898 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
899 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
Larry Finger7ad0ce32011-08-22 16:50:14 -0500900 */
Larry Fingerfd3cb222014-12-18 03:05:40 -0600901int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
902 u8 desc_rate)
Larry Finger7ad0ce32011-08-22 16:50:14 -0500903{
904 int rate_idx;
905
Larry Fingerfd3cb222014-12-18 03:05:40 -0600906 if (isvht) {
907 switch (desc_rate) {
908 case DESC_RATEVHT1SS_MCS0:
909 rate_idx = 0;
910 break;
911 case DESC_RATEVHT1SS_MCS1:
912 rate_idx = 1;
913 break;
914 case DESC_RATEVHT1SS_MCS2:
915 rate_idx = 2;
916 break;
917 case DESC_RATEVHT1SS_MCS3:
918 rate_idx = 3;
919 break;
920 case DESC_RATEVHT1SS_MCS4:
921 rate_idx = 4;
922 break;
923 case DESC_RATEVHT1SS_MCS5:
924 rate_idx = 5;
925 break;
926 case DESC_RATEVHT1SS_MCS6:
927 rate_idx = 6;
928 break;
929 case DESC_RATEVHT1SS_MCS7:
930 rate_idx = 7;
931 break;
932 case DESC_RATEVHT1SS_MCS8:
933 rate_idx = 8;
934 break;
935 case DESC_RATEVHT1SS_MCS9:
936 rate_idx = 9;
937 break;
938 case DESC_RATEVHT2SS_MCS0:
939 rate_idx = 0;
940 break;
941 case DESC_RATEVHT2SS_MCS1:
942 rate_idx = 1;
943 break;
944 case DESC_RATEVHT2SS_MCS2:
945 rate_idx = 2;
946 break;
947 case DESC_RATEVHT2SS_MCS3:
948 rate_idx = 3;
949 break;
950 case DESC_RATEVHT2SS_MCS4:
951 rate_idx = 4;
952 break;
953 case DESC_RATEVHT2SS_MCS5:
954 rate_idx = 5;
955 break;
956 case DESC_RATEVHT2SS_MCS6:
957 rate_idx = 6;
958 break;
959 case DESC_RATEVHT2SS_MCS7:
960 rate_idx = 7;
961 break;
962 case DESC_RATEVHT2SS_MCS8:
963 rate_idx = 8;
964 break;
965 case DESC_RATEVHT2SS_MCS9:
966 rate_idx = 9;
967 break;
968 default:
969 rate_idx = 0;
970 break;
971 }
972 return rate_idx;
973 }
Larry Finger7ad0ce32011-08-22 16:50:14 -0500974 if (false == isht) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200975 if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
Larry Finger7ad0ce32011-08-22 16:50:14 -0500976 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -0600977 case DESC_RATE1M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500978 rate_idx = 0;
979 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600980 case DESC_RATE2M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500981 rate_idx = 1;
982 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600983 case DESC_RATE5_5M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500984 rate_idx = 2;
985 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600986 case DESC_RATE11M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500987 rate_idx = 3;
988 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600989 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500990 rate_idx = 4;
991 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600992 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500993 rate_idx = 5;
994 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600995 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500996 rate_idx = 6;
997 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600998 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500999 rate_idx = 7;
1000 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001001 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001002 rate_idx = 8;
1003 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001004 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001005 rate_idx = 9;
1006 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001007 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001008 rate_idx = 10;
1009 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001010 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001011 rate_idx = 11;
1012 break;
1013 default:
1014 rate_idx = 0;
1015 break;
1016 }
1017 } else {
1018 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001019 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001020 rate_idx = 0;
1021 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001022 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001023 rate_idx = 1;
1024 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001025 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001026 rate_idx = 2;
1027 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001028 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001029 rate_idx = 3;
1030 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001031 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001032 rate_idx = 4;
1033 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001034 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001035 rate_idx = 5;
1036 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001037 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001038 rate_idx = 6;
1039 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001040 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001041 rate_idx = 7;
1042 break;
1043 default:
1044 rate_idx = 0;
1045 break;
1046 }
1047 }
Larry Finger7ad0ce32011-08-22 16:50:14 -05001048 } else {
Larry Finger7ad0ce32011-08-22 16:50:14 -05001049 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001050 case DESC_RATEMCS0:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001051 rate_idx = 0;
1052 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001053 case DESC_RATEMCS1:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001054 rate_idx = 1;
1055 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001056 case DESC_RATEMCS2:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001057 rate_idx = 2;
1058 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001059 case DESC_RATEMCS3:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001060 rate_idx = 3;
1061 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001062 case DESC_RATEMCS4:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001063 rate_idx = 4;
1064 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001065 case DESC_RATEMCS5:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001066 rate_idx = 5;
1067 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001068 case DESC_RATEMCS6:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001069 rate_idx = 6;
1070 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001071 case DESC_RATEMCS7:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001072 rate_idx = 7;
1073 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001074 case DESC_RATEMCS8:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001075 rate_idx = 8;
1076 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001077 case DESC_RATEMCS9:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001078 rate_idx = 9;
1079 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001080 case DESC_RATEMCS10:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001081 rate_idx = 10;
1082 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001083 case DESC_RATEMCS11:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001084 rate_idx = 11;
1085 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001086 case DESC_RATEMCS12:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001087 rate_idx = 12;
1088 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001089 case DESC_RATEMCS13:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001090 rate_idx = 13;
1091 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001092 case DESC_RATEMCS14:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001093 rate_idx = 14;
1094 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001095 case DESC_RATEMCS15:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001096 rate_idx = 15;
1097 break;
1098 default:
1099 rate_idx = 0;
1100 break;
1101 }
1102 }
1103 return rate_idx;
1104}
1105EXPORT_SYMBOL(rtlwifi_rate_mapping);
1106
Larry Finger0c817332010-12-08 11:12:31 -06001107void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1108 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -05001109 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -06001110 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1111{
1112 struct rtl_priv *rtlpriv = rtl_priv(hw);
1113 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001114 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001115 struct ieee80211_rate *txrate;
Larry Finger9afa2e42014-09-22 09:39:21 -05001116 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001117
Chaoming_Liacd48572011-04-25 12:52:54 -05001118 txrate = ieee80211_get_tx_rate(hw, info);
Larry Fingere89f7692012-04-06 16:54:17 -05001119 if (txrate)
1120 tcb_desc->hw_rate = txrate->hw_value;
Larry Finger0c817332010-12-08 11:12:31 -06001121
Ping-Ke Shih84795802017-06-18 11:12:44 -05001122 if (rtl_is_tx_report_skb(hw, skb))
1123 tcb_desc->use_spe_rpt = 1;
1124
Larry Finger0c817332010-12-08 11:12:31 -06001125 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001126 /*
Chaoming_Liacd48572011-04-25 12:52:54 -05001127 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -06001128 *in rtl_rc.c if skb is special data or
1129 *mgt which need low data rate.
1130 */
1131
1132 /*
1133 *So tcb_desc->hw_rate is just used for
1134 *special data and mgt frames
1135 */
Chaoming Li09e92f02011-10-11 21:28:48 -05001136 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -05001137 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001138 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001139 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001140
Larry Finger0c817332010-12-08 11:12:31 -06001141 tcb_desc->disable_ratefallback = 1;
1142 } else {
1143 /*
1144 *because hw will nerver use hw_rate
1145 *when tcb_desc->use_driver_rate = false
1146 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001147 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -06001148 *when tcb_desc->use_driver_rate = false
1149 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001150 if (sta && sta->vht_cap.vht_supported) {
1151 tcb_desc->hw_rate =
1152 _rtl_get_vht_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001153 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001154 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -06001155 tcb_desc->hw_rate =
Larry Finger9afa2e42014-09-22 09:39:21 -05001156 _rtl_get_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001157 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001158 if (rtlmac->mode == WIRELESS_MODE_B) {
1159 tcb_desc->hw_rate =
1160 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1161 } else {
1162 tcb_desc->hw_rate =
1163 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1164 }
Larry Finger0c817332010-12-08 11:12:31 -06001165 }
1166 }
1167 }
1168
1169 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -06001170 tcb_desc->multicast = 1;
Larry Finger0c817332010-12-08 11:12:31 -06001171 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -06001172 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -06001173
Chaoming_Liacd48572011-04-25 12:52:54 -05001174 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1175 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -06001176 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -05001177 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -06001178 _rtl_query_protection_mode(hw, tcb_desc, info);
1179 } else {
1180 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001181 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001182 tcb_desc->disable_ratefallback = 1;
1183 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001184 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -06001185 }
1186}
1187EXPORT_SYMBOL(rtl_get_tcb_desc);
1188
Larry Finger9afa2e42014-09-22 09:39:21 -05001189bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1190{
1191 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1192 struct rtl_priv *rtlpriv = rtl_priv(hw);
1193 __le16 fc = rtl_get_fc(skb);
1194
1195 if (rtlpriv->dm.supp_phymode_switch &&
1196 mac->link_state < MAC80211_LINKED &&
1197 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1198 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1199 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1200 }
1201 if (ieee80211_is_auth(fc)) {
1202 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1203 rtl_ips_nic_on(hw);
1204
1205 mac->link_state = MAC80211_LINKING;
1206 /* Dul mac */
1207 rtlpriv->phy.need_iqk = true;
1208
1209 }
1210
1211 return true;
1212}
1213EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1214
1215struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1216 u8 *bssid, u16 tid);
1217
1218static void process_agg_start(struct ieee80211_hw *hw,
1219 struct ieee80211_hdr *hdr, u16 tid)
Larry Finger26634c42013-03-24 22:06:33 -05001220{
1221 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001222 struct ieee80211_rx_status rx_status = { 0 };
Larry Finger9afa2e42014-09-22 09:39:21 -05001223 struct sk_buff *skb_delba = NULL;
Larry Finger26634c42013-03-24 22:06:33 -05001224
Larry Finger9afa2e42014-09-22 09:39:21 -05001225 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1226 if (skb_delba) {
1227 rx_status.freq = hw->conf.chandef.chan->center_freq;
1228 rx_status.band = hw->conf.chandef.chan->band;
1229 rx_status.flag |= RX_FLAG_DECRYPTED;
1230 rx_status.flag |= RX_FLAG_MACTIME_START;
1231 rx_status.rate_idx = 0;
1232 rx_status.signal = 50 + 10;
1233 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1234 &rx_status, sizeof(rx_status));
1235 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1236 "fake del\n",
1237 skb_delba->data,
1238 skb_delba->len);
1239 ieee80211_rx_irqsafe(hw, skb_delba);
Larry Finger26634c42013-03-24 22:06:33 -05001240 }
Larry Finger26634c42013-03-24 22:06:33 -05001241}
1242
Larry Finger0c817332010-12-08 11:12:31 -06001243bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1244{
1245 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001246 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001247 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001248 __le16 fc = rtl_get_fc(skb);
1249 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
Larry Finger0c817332010-12-08 11:12:31 -06001250 u8 category;
1251
1252 if (!ieee80211_is_action(fc))
1253 return true;
1254
1255 category = *act;
1256 act++;
1257 switch (category) {
1258 case ACT_CAT_BA:
1259 switch (*act) {
1260 case ACT_ADDBAREQ:
1261 if (mac->act_scanning)
1262 return false;
1263
1264 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Larry Finger9afa2e42014-09-22 09:39:21 -05001265 "%s ACT_ADDBAREQ From :%pM\n",
1266 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001267 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001268 skb->data, skb->len);
1269 if (!is_tx) {
1270 struct ieee80211_sta *sta = NULL;
1271 struct rtl_sta_info *sta_entry = NULL;
1272 struct rtl_tid_data *tid_data;
1273 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1274 u16 capab = 0, tid = 0;
1275
1276 rcu_read_lock();
1277 sta = rtl_find_sta(hw, hdr->addr3);
1278 if (sta == NULL) {
1279 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1280 DBG_DMESG, "sta is NULL\n");
1281 rcu_read_unlock();
Larry Finger26634c42013-03-24 22:06:33 -05001282 return true;
Larry Finger9afa2e42014-09-22 09:39:21 -05001283 }
1284
1285 sta_entry =
1286 (struct rtl_sta_info *)sta->drv_priv;
1287 if (!sta_entry) {
1288 rcu_read_unlock();
1289 return true;
1290 }
1291 capab =
1292 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1293 tid = (capab &
1294 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1295 tid_data = &sta_entry->tids[tid];
1296 if (tid_data->agg.rx_agg_state ==
1297 RTL_RX_AGG_START)
1298 process_agg_start(hw, hdr, tid);
1299 rcu_read_unlock();
1300 }
Larry Finger0c817332010-12-08 11:12:31 -06001301 break;
1302 case ACT_ADDBARSP:
1303 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001304 "%s ACT_ADDBARSP From :%pM\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001305 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001306 break;
1307 case ACT_DELBA:
1308 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001309 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001310 break;
1311 }
1312 break;
1313 default:
1314 break;
1315 }
1316
1317 return true;
1318}
Larry Finger6f334c22013-07-12 15:32:15 -05001319EXPORT_SYMBOL_GPL(rtl_action_proc);
Larry Finger0c817332010-12-08 11:12:31 -06001320
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001321static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
1322 int type)
Larry Finger9afa2e42014-09-22 09:39:21 -05001323{
Larry Fingerba9f93f2016-11-26 14:43:35 -06001324 struct ieee80211_hw *hw = rtlpriv->hw;
1325
Larry Finger9afa2e42014-09-22 09:39:21 -05001326 rtlpriv->ra.is_special_data = true;
1327 if (rtlpriv->cfg->ops->get_btc_status())
1328 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001329 rtlpriv, type);
Larry Fingerba9f93f2016-11-26 14:43:35 -06001330 rtl_lps_leave(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001331 ppsc->last_delaylps_stamp_jiffies = jiffies;
1332}
1333
Ping-Ke Shih84795802017-06-18 11:12:44 -05001334static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
1335 struct sk_buff *skb, bool is_enc)
Larry Finger0c817332010-12-08 11:12:31 -06001336{
1337 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001338 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
Larry Finger9afa2e42014-09-22 09:39:21 -05001339 u8 encrypt_header_len = 0;
1340 u8 offset;
Larry Finger0c817332010-12-08 11:12:31 -06001341
Larry Finger9afa2e42014-09-22 09:39:21 -05001342 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1343 case WEP40_ENCRYPTION:
1344 case WEP104_ENCRYPTION:
1345 encrypt_header_len = 4;/*WEP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001346 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001347 case TKIP_ENCRYPTION:
1348 encrypt_header_len = 8;/*TKIP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001349 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001350 case AESCCMP_ENCRYPTION:
1351 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001352 break;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001353 default:
Larry Finger9afa2e42014-09-22 09:39:21 -05001354 break;
Larry Finger0c817332010-12-08 11:12:31 -06001355 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001356
Taehee Yoocad737d2015-03-28 00:22:39 +09001357 offset = mac_hdr_len + SNAP_SIZE;
1358 if (is_enc)
1359 offset += encrypt_header_len;
Ping-Ke Shih84795802017-06-18 11:12:44 -05001360
1361 return skb->data + offset;
1362}
1363
1364/*should call before software enc*/
1365u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1366 bool is_enc)
1367{
1368 struct rtl_priv *rtlpriv = rtl_priv(hw);
1369 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1370 __le16 fc = rtl_get_fc(skb);
1371 u16 ether_type;
1372 const u8 *ether_type_ptr;
1373 const struct iphdr *ip;
1374
1375 if (!ieee80211_is_data(fc))
1376 goto end;
1377
1378 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
1379 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
Larry Finger9afa2e42014-09-22 09:39:21 -05001380
1381 if (ETH_P_IP == ether_type) {
Ping-Ke Shih84795802017-06-18 11:12:44 -05001382 ip = (struct iphdr *)((u8 *)ether_type_ptr +
Larry Finger9afa2e42014-09-22 09:39:21 -05001383 PROTOC_TYPE_SIZE);
1384 if (IPPROTO_UDP == ip->protocol) {
1385 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1386 (ip->ihl << 2));
1387 if (((((u8 *)udp)[1] == 68) &&
1388 (((u8 *)udp)[3] == 67)) ||
1389 ((((u8 *)udp)[1] == 67) &&
1390 (((u8 *)udp)[3] == 68))) {
1391 /* 68 : UDP BOOTP client
1392 * 67 : UDP BOOTP server
1393 */
1394 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1395 DBG_DMESG, "dhcp %s !!\n",
1396 (is_tx) ? "Tx" : "Rx");
1397
1398 if (is_tx)
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001399 setup_special_tx(rtlpriv, ppsc,
1400 PACKET_DHCP);
1401
Larry Finger9afa2e42014-09-22 09:39:21 -05001402 return true;
1403 }
1404 }
1405 } else if (ETH_P_ARP == ether_type) {
1406 if (is_tx)
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001407 setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
Larry Finger9afa2e42014-09-22 09:39:21 -05001408
1409 return true;
1410 } else if (ETH_P_PAE == ether_type) {
Ping-Ke Shih11f35c92017-07-02 13:12:30 -05001411 /* EAPOL is seens as in-4way */
1412 rtlpriv->btcoexist.btc_info.in_4way = true;
1413 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1414 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1415
Larry Finger9afa2e42014-09-22 09:39:21 -05001416 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1417 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1418
1419 if (is_tx) {
1420 rtlpriv->ra.is_special_data = true;
Larry Fingerba9f93f2016-11-26 14:43:35 -06001421 rtl_lps_leave(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001422 ppsc->last_delaylps_stamp_jiffies = jiffies;
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001423
1424 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
Larry Finger9afa2e42014-09-22 09:39:21 -05001425 }
1426
1427 return true;
Larry Fingerc8f03452015-02-24 09:23:01 -06001428 } else if (ETH_P_IPV6 == ether_type) {
1429 /* TODO: Handle any IPv6 cases that need special handling.
1430 * For now, always return false
1431 */
1432 goto end;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001433 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001434
1435end:
1436 rtlpriv->ra.is_special_data = false;
1437 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001438}
Larry Finger6f334c22013-07-12 15:32:15 -05001439EXPORT_SYMBOL_GPL(rtl_is_special_data);
Larry Finger0c817332010-12-08 11:12:31 -06001440
Ping-Ke Shih84795802017-06-18 11:12:44 -05001441bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1442{
1443 u16 ether_type;
1444 const u8 *ether_type_ptr;
1445
1446 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
1447 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1448
1449 /* EAPOL */
1450 if (ether_type == ETH_P_PAE)
1451 return true;
1452
1453 return false;
1454}
1455
1456static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
1457{
1458 struct rtl_priv *rtlpriv = rtl_priv(hw);
1459 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1460 u16 sn;
1461
1462 sn = atomic_inc_return(&tx_report->sn) & 0x0FFF;
1463
1464 tx_report->last_sent_sn = sn;
1465 tx_report->last_sent_time = jiffies;
1466
1467 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1468 "Send TX-Report sn=0x%X\n", sn);
1469
1470 return sn;
1471}
1472
1473void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
1474 struct ieee80211_hw *hw)
1475{
1476 if (ptcb_desc->use_spe_rpt) {
1477 u16 sn = rtl_get_tx_report_sn(hw);
1478
1479 SET_TX_DESC_SPE_RPT(pdesc, 1);
1480 SET_TX_DESC_SW_DEFINE(pdesc, sn);
1481 }
1482}
1483EXPORT_SYMBOL_GPL(rtl_get_tx_report);
1484
1485void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
1486{
1487 struct rtl_priv *rtlpriv = rtl_priv(hw);
1488 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1489 u16 sn;
1490
1491 sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
1492
1493 tx_report->last_recv_sn = sn;
1494
1495 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1496 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1497 tmp_buf[0], sn, tmp_buf[2]);
1498}
1499EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
1500
1501bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
1502{
1503 struct rtl_priv *rtlpriv = rtl_priv(hw);
1504 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1505
1506 if (tx_report->last_sent_sn == tx_report->last_recv_sn)
1507 return true;
1508
1509 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
1510 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
1511 "Check TX-Report timeout!!\n");
1512 return true; /* 3 sec. (timeout) seen as acked */
1513 }
1514
1515 return false;
1516}
1517
1518void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
1519{
1520 struct rtl_priv *rtlpriv = rtl_priv(hw);
1521 int i;
1522
1523 for (i = 0; i < wait_ms; i++) {
1524 if (rtl_check_tx_report_acked(hw))
1525 break;
1526 usleep_range(1000, 2000);
1527 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1528 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
1529 }
1530}
Larry Finger0c817332010-12-08 11:12:31 -06001531/*********************************************************
1532 *
1533 * functions called by core.c
1534 *
1535 *********************************************************/
Larry Fingerf7953b22014-09-22 09:39:20 -05001536int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1537 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001538{
1539 struct rtl_priv *rtlpriv = rtl_priv(hw);
1540 struct rtl_tid_data *tid_data;
Chaoming_Liacd48572011-04-25 12:52:54 -05001541 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001542
Chaoming_Liacd48572011-04-25 12:52:54 -05001543 if (sta == NULL)
1544 return -EINVAL;
Larry Finger0c817332010-12-08 11:12:31 -06001545
1546 if (unlikely(tid >= MAX_TID_COUNT))
1547 return -EINVAL;
1548
Chaoming_Liacd48572011-04-25 12:52:54 -05001549 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1550 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001551 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001552 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001553
Larry Finger9afa2e42014-09-22 09:39:21 -05001554 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1555 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1556 tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001557
Chaoming_Liacd48572011-04-25 12:52:54 -05001558 *ssn = tid_data->seq_number;
1559 tid_data->agg.agg_state = RTL_AGG_START;
1560
Larry Finger9afa2e42014-09-22 09:39:21 -05001561 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001562 return 0;
1563}
1564
Larry Fingerf7953b22014-09-22 09:39:20 -05001565int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1566 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001567{
Larry Finger0c817332010-12-08 11:12:31 -06001568 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001569 struct rtl_tid_data *tid_data;
Chaoming_Liacd48572011-04-25 12:52:54 -05001570 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001571
Chaoming_Liacd48572011-04-25 12:52:54 -05001572 if (sta == NULL)
1573 return -EINVAL;
1574
Larry Finger9afa2e42014-09-22 09:39:21 -05001575 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1576 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001577
Larry Finger0c817332010-12-08 11:12:31 -06001578 if (unlikely(tid >= MAX_TID_COUNT))
1579 return -EINVAL;
1580
Chaoming_Liacd48572011-04-25 12:52:54 -05001581 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Larry Finger9afa2e42014-09-22 09:39:21 -05001582 tid_data = &sta_entry->tids[tid];
Chaoming_Liacd48572011-04-25 12:52:54 -05001583 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001584
Larry Finger9afa2e42014-09-22 09:39:21 -05001585 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001586 return 0;
1587}
Larry Finger0c817332010-12-08 11:12:31 -06001588
Larry Finger26634c42013-03-24 22:06:33 -05001589int rtl_rx_agg_start(struct ieee80211_hw *hw,
1590 struct ieee80211_sta *sta, u16 tid)
1591{
1592 struct rtl_priv *rtlpriv = rtl_priv(hw);
1593 struct rtl_tid_data *tid_data;
1594 struct rtl_sta_info *sta_entry = NULL;
Ping-Ke Shih26356642017-06-18 11:12:47 -05001595 u8 reject_agg;
Larry Finger26634c42013-03-24 22:06:33 -05001596
1597 if (sta == NULL)
1598 return -EINVAL;
1599
1600 if (unlikely(tid >= MAX_TID_COUNT))
1601 return -EINVAL;
1602
Ping-Ke Shih26356642017-06-18 11:12:47 -05001603 if (rtlpriv->cfg->ops->get_btc_status()) {
1604 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
1605 &reject_agg,
1606 NULL, NULL);
1607 if (reject_agg)
1608 return -EINVAL;
1609 }
1610
Larry Finger26634c42013-03-24 22:06:33 -05001611 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1612 if (!sta_entry)
1613 return -ENXIO;
1614 tid_data = &sta_entry->tids[tid];
1615
1616 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1617 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1618 tid_data->seq_number);
1619
1620 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1621 return 0;
1622}
1623
1624int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1625 struct ieee80211_sta *sta, u16 tid)
1626{
1627 struct rtl_priv *rtlpriv = rtl_priv(hw);
1628 struct rtl_sta_info *sta_entry = NULL;
1629
1630 if (sta == NULL)
1631 return -EINVAL;
1632
Larry Finger26634c42013-03-24 22:06:33 -05001633 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1634 "on ra = %pM tid = %d\n", sta->addr, tid);
1635
1636 if (unlikely(tid >= MAX_TID_COUNT))
1637 return -EINVAL;
1638
1639 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1640 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1641
1642 return 0;
1643}
Chaoming_Liacd48572011-04-25 12:52:54 -05001644int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1645 struct ieee80211_sta *sta, u16 tid)
1646{
1647 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001648 struct rtl_sta_info *sta_entry = NULL;
1649
1650 if (sta == NULL)
1651 return -EINVAL;
1652
Larry Finger9afa2e42014-09-22 09:39:21 -05001653 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1654 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001655
1656 if (unlikely(tid >= MAX_TID_COUNT))
1657 return -EINVAL;
1658
1659 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001660 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001661
1662 return 0;
1663}
1664
Ping-Ke Shih26356642017-06-18 11:12:47 -05001665void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
1666{
1667 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
1668 u8 reject_agg, ctrl_agg_size = 0, agg_size;
1669
1670 if (rtlpriv->cfg->ops->get_btc_status())
1671 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
1672 &ctrl_agg_size, &agg_size);
1673
1674 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
1675 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1676 reject_agg, ctrl_agg_size, agg_size);
1677
1678 rtlpriv->hw->max_rx_aggregation_subframes =
1679 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
1680}
1681EXPORT_SYMBOL(rtl_rx_ampdu_apply);
1682
Larry Finger0c817332010-12-08 11:12:31 -06001683/*********************************************************
1684 *
1685 * wq & timer callback functions
1686 *
1687 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001688/* this function is used for roaming */
1689void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1690{
1691 struct rtl_priv *rtlpriv = rtl_priv(hw);
1692 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1693
1694 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1695 return;
1696
1697 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1698 return;
1699
1700 /* check if this really is a beacon */
1701 if (!ieee80211_is_beacon(hdr->frame_control) &&
1702 !ieee80211_is_probe_resp(hdr->frame_control))
1703 return;
1704
1705 /* min. beacon length + FCS_LEN */
1706 if (skb->len <= 40 + FCS_LEN)
1707 return;
1708
1709 /* and only beacons from the associated BSSID, please */
Larry Finger9afa2e42014-09-22 09:39:21 -05001710 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Larry Finger26634c42013-03-24 22:06:33 -05001711 return;
1712
1713 rtlpriv->link_info.bcn_rx_inperiod++;
1714}
Larry Finger6f334c22013-07-12 15:32:15 -05001715EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
Larry Finger26634c42013-03-24 22:06:33 -05001716
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001717static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
1718{
1719 struct rtl_priv *rtlpriv = rtl_priv(hw);
1720 struct rtl_bssid_entry *entry, *next;
1721
1722 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1723 list_del(&entry->list);
1724 kfree(entry);
1725 rtlpriv->scan_list.num--;
1726 }
1727}
1728
1729void rtl_scan_list_expire(struct ieee80211_hw *hw)
1730{
1731 struct rtl_priv *rtlpriv = rtl_priv(hw);
1732 struct rtl_bssid_entry *entry, *next;
1733 unsigned long flags;
1734
1735 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1736
1737 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1738 /* 180 seconds */
1739 if (jiffies_to_msecs(jiffies - entry->age) < 180000)
1740 continue;
1741
1742 list_del(&entry->list);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001743 rtlpriv->scan_list.num--;
1744
1745 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1746 "BSSID=%pM is expire in scan list (total=%d)\n",
1747 entry->bssid, rtlpriv->scan_list.num);
Colin Ian Kingd0116f62017-06-30 11:08:43 +01001748 kfree(entry);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001749 }
1750
1751 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1752
1753 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
1754}
1755
1756void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
1757{
1758 struct rtl_priv *rtlpriv = rtl_priv(hw);
1759 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1760 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1761 unsigned long flags;
1762
1763 struct rtl_bssid_entry *entry;
1764 bool entry_found = false;
1765
1766 /* check if it is scanning */
1767 if (!mac->act_scanning)
1768 return;
1769
1770 /* check if this really is a beacon */
1771 if (!ieee80211_is_beacon(hdr->frame_control) &&
1772 !ieee80211_is_probe_resp(hdr->frame_control))
1773 return;
1774
1775 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1776
1777 list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
1778 if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
1779 list_del_init(&entry->list);
1780 entry_found = true;
1781 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1782 "Update BSSID=%pM to scan list (total=%d)\n",
1783 hdr->addr3, rtlpriv->scan_list.num);
1784 break;
1785 }
1786 }
1787
1788 if (!entry_found) {
1789 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1790
1791 if (!entry)
1792 goto label_err;
1793
1794 memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
1795 rtlpriv->scan_list.num++;
1796
1797 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1798 "Add BSSID=%pM to scan list (total=%d)\n",
1799 hdr->addr3, rtlpriv->scan_list.num);
1800 }
1801
1802 entry->age = jiffies;
1803
1804 list_add_tail(&entry->list, &rtlpriv->scan_list.list);
1805
1806label_err:
1807 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1808}
1809EXPORT_SYMBOL(rtl_collect_scan_list);
1810
Larry Finger0c817332010-12-08 11:12:31 -06001811void rtl_watchdog_wq_callback(void *data)
1812{
1813 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1814 struct rtl_works,
1815 watchdog_wq);
1816 struct ieee80211_hw *hw = rtlworks->hw;
1817 struct rtl_priv *rtlpriv = rtl_priv(hw);
1818 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1819 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001820 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001821 bool tx_busy_traffic = false;
1822 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001823 bool higher_busytraffic = false;
1824 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001825 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001826 u32 rx_cnt_inp4eriod = 0;
1827 u32 tx_cnt_inp4eriod = 0;
1828 u32 aver_rx_cnt_inperiod = 0;
1829 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001830 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1831 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001832
1833 if (is_hal_stop(rtlhal))
1834 return;
1835
1836 /* <1> Determine if action frame is allowed */
1837 if (mac->link_state > MAC80211_NOLINK) {
1838 if (mac->cnt_after_linked < 20)
1839 mac->cnt_after_linked++;
1840 } else {
1841 mac->cnt_after_linked = 0;
1842 }
1843
Larry Finger9afa2e42014-09-22 09:39:21 -05001844 /* <2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001845 * busytraffic we don't change channel
1846 */
1847 if (mac->link_state >= MAC80211_LINKED) {
1848
1849 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1850 for (idx = 0; idx <= 2; idx++) {
1851 rtlpriv->link_info.num_rx_in4period[idx] =
1852 rtlpriv->link_info.num_rx_in4period[idx + 1];
1853 rtlpriv->link_info.num_tx_in4period[idx] =
1854 rtlpriv->link_info.num_tx_in4period[idx + 1];
1855 }
1856 rtlpriv->link_info.num_rx_in4period[3] =
1857 rtlpriv->link_info.num_rx_inperiod;
1858 rtlpriv->link_info.num_tx_in4period[3] =
1859 rtlpriv->link_info.num_tx_inperiod;
1860 for (idx = 0; idx <= 3; idx++) {
1861 rx_cnt_inp4eriod +=
1862 rtlpriv->link_info.num_rx_in4period[idx];
1863 tx_cnt_inp4eriod +=
1864 rtlpriv->link_info.num_tx_in4period[idx];
1865 }
1866 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1867 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1868
1869 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001870 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001871 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001872 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1873 rx_busy_traffic = true;
1874 else
1875 tx_busy_traffic = false;
1876 }
Larry Finger0c817332010-12-08 11:12:31 -06001877
1878 /* Higher Tx/Rx data. */
1879 if (aver_rx_cnt_inperiod > 4000 ||
1880 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001881 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001882
1883 /* Extremely high Rx data. */
1884 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001885 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001886 }
1887
1888 /* check every tid's tx traffic */
1889 for (tid = 0; tid <= 7; tid++) {
1890 for (idx = 0; idx <= 2; idx++)
1891 rtlpriv->link_info.tidtx_in4period[tid][idx] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001892 rtlpriv->link_info.tidtx_in4period[tid]
1893 [idx + 1];
Chaoming_Liacd48572011-04-25 12:52:54 -05001894 rtlpriv->link_info.tidtx_in4period[tid][3] =
1895 rtlpriv->link_info.tidtx_inperiod[tid];
1896
1897 for (idx = 0; idx <= 3; idx++)
1898 tidtx_inp4eriod[tid] +=
Larry Finger9afa2e42014-09-22 09:39:21 -05001899 rtlpriv->link_info.tidtx_in4period[tid][idx];
Chaoming_Liacd48572011-04-25 12:52:54 -05001900 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1901 if (aver_tidtx_inperiod[tid] > 5000)
1902 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001903 true;
Larry Finger0c817332010-12-08 11:12:31 -06001904 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001905 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001906 false;
Larry Finger0c817332010-12-08 11:12:31 -06001907 }
1908
Ping-Ke Shih42213f22017-06-18 11:12:49 -05001909 /* PS is controlled by coex. */
1910 if (rtlpriv->cfg->ops->get_btc_status() &&
1911 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
1912 goto label_lps_done;
1913
Larry Finger0c817332010-12-08 11:12:31 -06001914 if (((rtlpriv->link_info.num_rx_inperiod +
1915 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1916 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingerfd09ff92014-09-22 09:39:18 -05001917 rtl_lps_leave(hw);
wang yanqing873ffe12016-05-03 00:38:36 +08001918 else
1919 rtl_lps_enter(hw);
Ping-Ke Shih42213f22017-06-18 11:12:49 -05001920
1921label_lps_done:
1922 ;
Larry Finger0c817332010-12-08 11:12:31 -06001923 }
1924
1925 rtlpriv->link_info.num_rx_inperiod = 0;
1926 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001927 for (tid = 0; tid <= 7; tid++)
1928 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001929
Larry Finger7ea47242011-02-19 16:28:57 -06001930 rtlpriv->link_info.busytraffic = busytraffic;
1931 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001932 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1933 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001934 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001935
Chaoming_Liacd48572011-04-25 12:52:54 -05001936 /* <3> DM */
Larry Finger9afa2e42014-09-22 09:39:21 -05001937 if (!rtlpriv->cfg->mod_params->disable_watchdog)
1938 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001939
1940 /* <4> roaming */
1941 if (mac->link_state == MAC80211_LINKED &&
1942 mac->opmode == NL80211_IFTYPE_STATION) {
1943 if ((rtlpriv->link_info.bcn_rx_inperiod +
Larry Finger9afa2e42014-09-22 09:39:21 -05001944 rtlpriv->link_info.num_rx_inperiod) == 0) {
Larry Finger26634c42013-03-24 22:06:33 -05001945 rtlpriv->link_info.roam_times++;
1946 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1947 "AP off for %d s\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001948 (rtlpriv->link_info.roam_times * 2));
Larry Finger26634c42013-03-24 22:06:33 -05001949
Larry Finger9afa2e42014-09-22 09:39:21 -05001950 /* if we can't recv beacon for 10s,
1951 * we should reconnect this AP
Larry Finger26634c42013-03-24 22:06:33 -05001952 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001953 if (rtlpriv->link_info.roam_times >= 5) {
Larry Fingerb03d9682016-12-15 12:22:58 -06001954 pr_err("AP off, try to reconnect now\n");
Larry Finger26634c42013-03-24 22:06:33 -05001955 rtlpriv->link_info.roam_times = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -05001956 ieee80211_connection_loss(
1957 rtlpriv->mac80211.vif);
Larry Finger26634c42013-03-24 22:06:33 -05001958 }
1959 } else {
1960 rtlpriv->link_info.roam_times = 0;
1961 }
1962 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001963
1964 if (rtlpriv->cfg->ops->get_btc_status())
1965 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
1966
Ping-Ke Shih11f35c92017-07-02 13:12:30 -05001967 if (rtlpriv->btcoexist.btc_info.in_4way) {
1968 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
1969 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
1970 rtlpriv->btcoexist.btc_info.in_4way = false;
1971 }
1972
Larry Finger26634c42013-03-24 22:06:33 -05001973 rtlpriv->link_info.bcn_rx_inperiod = 0;
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001974
1975 /* <6> scan list */
1976 rtl_scan_list_expire(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001977}
1978
1979void rtl_watch_dog_timer_callback(unsigned long data)
1980{
1981 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1982 struct rtl_priv *rtlpriv = rtl_priv(hw);
1983
1984 queue_delayed_work(rtlpriv->works.rtl_wq,
1985 &rtlpriv->works.watchdog_wq, 0);
1986
1987 mod_timer(&rtlpriv->works.watchdog_timer,
1988 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1989}
Larry Finger26634c42013-03-24 22:06:33 -05001990void rtl_fwevt_wq_callback(void *data)
1991{
1992 struct rtl_works *rtlworks =
1993 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1994 struct ieee80211_hw *hw = rtlworks->hw;
1995 struct rtl_priv *rtlpriv = rtl_priv(hw);
1996
1997 rtlpriv->cfg->ops->c2h_command_handle(hw);
1998}
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06001999
2000void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
2001{
2002 struct rtl_priv *rtlpriv = rtl_priv(hw);
2003 unsigned long flags;
2004 struct rtl_c2hcmd *c2hcmd;
2005
Larry Finger893dc682017-03-21 09:24:11 -05002006 c2hcmd = kmalloc(sizeof(*c2hcmd),
2007 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06002008
2009 if (!c2hcmd)
2010 goto label_err;
2011
Larry Finger893dc682017-03-21 09:24:11 -05002012 c2hcmd->val = kmalloc(len,
2013 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06002014
2015 if (!c2hcmd->val)
2016 goto label_err2;
2017
2018 /* fill data */
2019 c2hcmd->tag = tag;
2020 c2hcmd->len = len;
2021 memcpy(c2hcmd->val, val, len);
2022
2023 /* enqueue */
2024 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2025
2026 list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
2027
2028 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2029
2030 /* wake up wq */
2031 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
2032
2033 return;
2034
2035label_err2:
2036 kfree(c2hcmd);
2037
2038label_err:
2039 RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
2040 "C2H cmd enqueue fail.\n");
2041}
2042EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
2043
2044void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
2045{
2046 struct rtl_priv *rtlpriv = rtl_priv(hw);
2047 unsigned long flags;
2048 struct rtl_c2hcmd *c2hcmd;
2049 int i;
2050
2051 for (i = 0; i < 200; i++) {
2052 /* dequeue a task */
2053 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2054
2055 c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
2056 struct rtl_c2hcmd, list);
2057
2058 if (c2hcmd)
2059 list_del(&c2hcmd->list);
2060
2061 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2062
2063 /* do it */
2064 if (!c2hcmd)
2065 break;
2066
2067 if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
2068 rtlpriv->cfg->ops->c2h_content_parsing(hw,
2069 c2hcmd->tag, c2hcmd->len, c2hcmd->val);
2070
2071 /* free */
2072 kfree(c2hcmd->val);
2073
2074 kfree(c2hcmd);
2075 }
2076}
2077
2078void rtl_c2hcmd_wq_callback(void *data)
2079{
2080 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2081 struct rtl_works,
2082 c2hcmd_wq);
2083 struct ieee80211_hw *hw = rtlworks->hw;
2084
2085 rtl_c2hcmd_launcher(hw, 1);
2086}
2087
Larry Finger26634c42013-03-24 22:06:33 -05002088void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
2089{
2090 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
2091 struct rtl_priv *rtlpriv = rtl_priv(hw);
2092 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
2093
2094 if (buddy_priv == NULL)
2095 return;
2096
2097 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
2098}
Larry Finger0c817332010-12-08 11:12:31 -06002099/*********************************************************
2100 *
Chaoming_Liacd48572011-04-25 12:52:54 -05002101 * frame process functions
2102 *
2103 *********************************************************/
2104u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
2105{
2106 struct ieee80211_mgmt *mgmt = (void *)data;
2107 u8 *pos, *end;
2108
2109 pos = (u8 *)mgmt->u.beacon.variable;
2110 end = data + len;
2111 while (pos < end) {
2112 if (pos + 2 + pos[1] > end)
2113 return NULL;
2114
2115 if (pos[0] == ie)
2116 return pos;
2117
2118 pos += 2 + pos[1];
2119 }
2120 return NULL;
2121}
2122
2123/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2124/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05002125static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002126 enum ieee80211_smps_mode smps,
2127 u8 *da, u8 *bssid)
Chaoming_Liacd48572011-04-25 12:52:54 -05002128{
2129 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2130 struct sk_buff *skb;
2131 struct ieee80211_mgmt *action_frame;
2132
2133 /* 27 = header + category + action + smps mode */
2134 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
2135 if (!skb)
2136 return NULL;
2137
2138 skb_reserve(skb, hw->extra_tx_headroom);
Johannes Bergb080db52017-06-16 14:29:19 +02002139 action_frame = skb_put_zero(skb, 27);
Chaoming_Liacd48572011-04-25 12:52:54 -05002140 memcpy(action_frame->da, da, ETH_ALEN);
2141 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
2142 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2143 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2144 IEEE80211_STYPE_ACTION);
2145 action_frame->u.action.category = WLAN_CATEGORY_HT;
2146 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
2147 switch (smps) {
2148 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
2149 case IEEE80211_SMPS_NUM_MODES:/* 4 */
2150 WARN_ON(1);
Larry Finger9afa2e42014-09-22 09:39:21 -05002151 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
2152 * According to Kernel Code, here is right.
2153 */
Chaoming_Liacd48572011-04-25 12:52:54 -05002154 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
2155 action_frame->u.action.u.ht_smps.smps_control =
2156 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
2157 break;
2158 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
2159 action_frame->u.action.u.ht_smps.smps_control =
2160 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
2161 break;
2162 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
2163 action_frame->u.action.u.ht_smps.smps_control =
2164 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
2165 break;
2166 }
2167
2168 return skb;
2169}
2170
2171int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002172 struct ieee80211_sta *sta,
2173 enum ieee80211_smps_mode smps)
Chaoming_Liacd48572011-04-25 12:52:54 -05002174{
2175 struct rtl_priv *rtlpriv = rtl_priv(hw);
2176 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2177 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05002178 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05002179 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05002180 u8 bssid[ETH_ALEN] = {0};
2181
Chaoming_Liacd48572011-04-25 12:52:54 -05002182 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
2183
2184 if (rtlpriv->mac80211.act_scanning)
2185 goto err_free;
2186
2187 if (!sta)
2188 goto err_free;
2189
2190 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
2191 goto err_free;
2192
2193 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
2194 goto err_free;
2195
Larry Finger26634c42013-03-24 22:06:33 -05002196 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
2197 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
2198 else
2199 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
2200
2201 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05002202 /* this is a type = mgmt * stype = action frame */
2203 if (skb) {
2204 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2205 struct rtl_sta_info *sta_entry =
2206 (struct rtl_sta_info *) sta->drv_priv;
2207 sta_entry->mimo_ps = smps;
Larry Finger9afa2e42014-09-22 09:39:21 -05002208 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
Chaoming_Liacd48572011-04-25 12:52:54 -05002209
2210 info->control.rates[0].idx = 0;
Karl Beldan675a0b02013-03-25 16:26:57 +01002211 info->band = hw->conf.chandef.chan->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02002212 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05002213 }
Larry Finger26634c42013-03-24 22:06:33 -05002214 return 1;
2215
Chaoming_Liacd48572011-04-25 12:52:54 -05002216err_free:
2217 return 0;
2218}
Larry Finger26634c42013-03-24 22:06:33 -05002219EXPORT_SYMBOL(rtl_send_smps_action);
2220
Larry Finger4f4826d2013-09-26 13:25:27 -05002221void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
2222{
2223 struct rtl_priv *rtlpriv = rtl_priv(hw);
2224 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2225 enum io_type iotype;
2226
2227 if (!is_hal_stop(rtlhal)) {
2228 switch (operation) {
2229 case SCAN_OPT_BACKUP:
2230 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
2231 rtlpriv->cfg->ops->set_hw_reg(hw,
2232 HW_VAR_IO_CMD,
2233 (u8 *)&iotype);
2234 break;
2235 case SCAN_OPT_RESTORE:
2236 iotype = IO_CMD_RESUME_DM_BY_SCAN;
2237 rtlpriv->cfg->ops->set_hw_reg(hw,
2238 HW_VAR_IO_CMD,
2239 (u8 *)&iotype);
2240 break;
2241 default:
Larry Fingerb03d9682016-12-15 12:22:58 -06002242 pr_err("Unknown Scan Backup operation.\n");
Larry Finger4f4826d2013-09-26 13:25:27 -05002243 break;
2244 }
2245 }
2246}
2247EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
2248
Larry Finger9afa2e42014-09-22 09:39:21 -05002249/* because mac80211 have issues when can receive del ba
2250 * so here we just make a fake del_ba if we receive a ba_req
2251 * but rx_agg was opened to let mac80211 release some ba
2252 * related resources, so please this del_ba for tx
Larry Finger26634c42013-03-24 22:06:33 -05002253 */
2254struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
2255 u8 *sa, u8 *bssid, u16 tid)
2256{
2257 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2258 struct sk_buff *skb;
2259 struct ieee80211_mgmt *action_frame;
2260 u16 params;
2261
2262 /* 27 = header + category + action + smps mode */
2263 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
2264 if (!skb)
2265 return NULL;
2266
2267 skb_reserve(skb, hw->extra_tx_headroom);
Johannes Bergb080db52017-06-16 14:29:19 +02002268 action_frame = skb_put_zero(skb, 34);
Larry Finger26634c42013-03-24 22:06:33 -05002269 memcpy(action_frame->sa, sa, ETH_ALEN);
2270 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
2271 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2272 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2273 IEEE80211_STYPE_ACTION);
2274 action_frame->u.action.category = WLAN_CATEGORY_BACK;
2275 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
2276 params = (u16)(1 << 11); /* bit 11 initiator */
Larry Finger9afa2e42014-09-22 09:39:21 -05002277 params |= (u16)(tid << 12); /* bit 15:12 TID number */
Larry Finger26634c42013-03-24 22:06:33 -05002278
2279 action_frame->u.action.u.delba.params = cpu_to_le16(params);
2280 action_frame->u.action.u.delba.reason_code =
2281 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
2282
2283 return skb;
2284}
Chaoming_Liacd48572011-04-25 12:52:54 -05002285
2286/*********************************************************
2287 *
2288 * IOT functions
2289 *
2290 *********************************************************/
2291static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002292 struct octet_string vendor_ie)
Chaoming_Liacd48572011-04-25 12:52:54 -05002293{
2294 struct rtl_priv *rtlpriv = rtl_priv(hw);
2295 bool matched = false;
2296 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
2297 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
2298 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
2299 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
2300 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
2301 static u8 racap[] = { 0x00, 0x0c, 0x43 };
2302 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
2303 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
2304
2305 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
2306 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
2307 rtlpriv->mac80211.vendor = PEER_ATH;
2308 matched = true;
2309 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
2310 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
2311 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
2312 rtlpriv->mac80211.vendor = PEER_BROAD;
2313 matched = true;
2314 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
2315 rtlpriv->mac80211.vendor = PEER_RAL;
2316 matched = true;
2317 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
2318 rtlpriv->mac80211.vendor = PEER_CISCO;
2319 matched = true;
2320 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
2321 rtlpriv->mac80211.vendor = PEER_MARV;
2322 matched = true;
2323 }
2324
2325 return matched;
2326}
2327
Larry Fingerd3bb1422011-04-25 13:23:20 -05002328static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05002329 unsigned int len)
2330{
2331 struct ieee80211_mgmt *mgmt = (void *)data;
2332 struct octet_string vendor_ie;
2333 u8 *pos, *end;
2334
2335 pos = (u8 *)mgmt->u.beacon.variable;
2336 end = data + len;
2337 while (pos < end) {
2338 if (pos[0] == 221) {
2339 vendor_ie.length = pos[1];
2340 vendor_ie.octet = &pos[2];
2341 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
2342 return true;
2343 }
2344
2345 if (pos + 2 + pos[1] > end)
2346 return false;
2347
2348 pos += 2 + pos[1];
2349 }
2350 return false;
2351}
2352
2353void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2354{
2355 struct rtl_priv *rtlpriv = rtl_priv(hw);
2356 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2357 struct ieee80211_hdr *hdr = (void *)data;
2358 u32 vendor = PEER_UNKNOWN;
2359
2360 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2361 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2362 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2363 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2364 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2365 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2366 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2367 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2368 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2369 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2370 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2371 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2372 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2373 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2374 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2375 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2376
2377 if (mac->opmode != NL80211_IFTYPE_STATION)
2378 return;
2379
2380 if (mac->link_state == MAC80211_NOLINK) {
2381 mac->vendor = PEER_UNKNOWN;
2382 return;
2383 }
2384
2385 if (mac->cnt_after_linked > 2)
2386 return;
2387
2388 /* check if this really is a beacon */
2389 if (!ieee80211_is_beacon(hdr->frame_control))
2390 return;
2391
2392 /* min. beacon length + FCS_LEN */
2393 if (len <= 40 + FCS_LEN)
2394 return;
2395
2396 /* and only beacons from the associated BSSID, please */
Julia Lawall90908e12013-12-30 19:15:02 +01002397 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05002398 return;
2399
2400 if (rtl_find_221_ie(hw, data, len))
2401 vendor = mac->vendor;
2402
2403 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2404 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2405 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2406 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2407 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2408 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2409 vendor == PEER_ATH) {
2410 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08002411 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002412 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2413 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2414 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2415 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2416 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2417 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002418 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002419 vendor = PEER_RAL;
2420 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2421 vendor == PEER_CISCO) {
2422 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08002423 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002424 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2425 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2426 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2427 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002428 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002429 vendor = PEER_BROAD;
2430 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2431 vendor == PEER_MARV) {
2432 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08002433 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002434 }
2435
2436 mac->vendor = vendor;
2437}
Larry Finger6f334c22013-07-12 15:32:15 -05002438EXPORT_SYMBOL_GPL(rtl_recognize_peer);
Chaoming_Liacd48572011-04-25 12:52:54 -05002439
Larry Finger0c817332010-12-08 11:12:31 -06002440MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2441MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2442MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2443MODULE_LICENSE("GPL");
2444MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2445
Larry Finger6f334c22013-07-12 15:32:15 -05002446struct rtl_global_var rtl_global_var = {};
2447EXPORT_SYMBOL_GPL(rtl_global_var);
Larry Finger26634c42013-03-24 22:06:33 -05002448
Larry Finger0c817332010-12-08 11:12:31 -06002449static int __init rtl_core_module_init(void)
2450{
Chaoming Li375ff4c2011-02-28 16:40:28 -06002451 if (rtl_rate_control_register())
Larry Finger9afa2e42014-09-22 09:39:21 -05002452 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002453
Larry Finger26634c42013-03-24 22:06:33 -05002454 /* init some global vars */
Larry Finger6f334c22013-07-12 15:32:15 -05002455 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2456 spin_lock_init(&rtl_global_var.glb_list_lock);
Larry Finger26634c42013-03-24 22:06:33 -05002457
Larry Finger0c817332010-12-08 11:12:31 -06002458 return 0;
2459}
2460
2461static void __exit rtl_core_module_exit(void)
2462{
Chaoming_Liacd48572011-04-25 12:52:54 -05002463 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06002464 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06002465}
2466
2467module_init(rtl_core_module_init);
2468module_exit(rtl_core_module_exit);