blob: e37d4c765f8725a89af0d6ba28128a72f8b7f8d5 [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 =
Larry Finger9afa2e42014-09-22 09:39:21 -0500252 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
253 IEEE80211_VHT_CAP_SHORT_GI_80 |
254 IEEE80211_VHT_CAP_TXSTBC |
255 IEEE80211_VHT_CAP_RXSTBC_1 |
256 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
257 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
258 IEEE80211_VHT_CAP_HTC_VHT |
259 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
260 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
261 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
262 0;
263
264 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
265 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
266 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
267 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
268 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
269 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
270 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
271 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
272
273 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
274 vht_cap->vht_mcs.rx_highest =
275 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
276 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
277 vht_cap->vht_mcs.tx_highest =
278 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9);
279 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) {
280 u16 mcs_map;
281
282 vht_cap->vht_supported = true;
283 vht_cap->cap =
Larry Finger9afa2e42014-09-22 09:39:21 -0500284 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
285 IEEE80211_VHT_CAP_SHORT_GI_80 |
286 IEEE80211_VHT_CAP_TXSTBC |
287 IEEE80211_VHT_CAP_RXSTBC_1 |
288 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
289 IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
290 IEEE80211_VHT_CAP_HTC_VHT |
291 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK |
292 IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
293 IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
294 0;
295
296 mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
297 IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 |
298 IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 |
299 IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 |
300 IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 |
301 IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 |
302 IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 |
303 IEEE80211_VHT_MCS_NOT_SUPPORTED << 14;
304
305 vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map);
306 vht_cap->vht_mcs.rx_highest =
307 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
308 vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map);
309 vht_cap->vht_mcs.tx_highest =
310 cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9);
311 }
312}
313
Larry Finger0c817332010-12-08 11:12:31 -0600314static void _rtl_init_mac80211(struct ieee80211_hw *hw)
315{
Chaoming_Liacd48572011-04-25 12:52:54 -0500316 struct rtl_priv *rtlpriv = rtl_priv(hw);
317 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600318 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
319 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
320 struct ieee80211_supported_band *sband;
321
Larry Finger9afa2e42014-09-22 09:39:21 -0500322 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY &&
323 rtlhal->bandset == BAND_ON_BOTH) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500324 /* 1: 2.4 G bands */
325 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200326 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600327
Johannes Berg57fbcce2016-04-12 15:56:15 +0200328 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500329 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200330 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz,
Chaoming_Liacd48572011-04-25 12:52:54 -0500331 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600332
Chaoming_Liacd48572011-04-25 12:52:54 -0500333 /* <3> init ht cap base on ant_num */
334 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600335
Chaoming_Liacd48572011-04-25 12:52:54 -0500336 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200337 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500338
339 /* 2: 5 G bands */
340 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200341 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500342
Johannes Berg57fbcce2016-04-12 15:56:15 +0200343 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500344 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200345 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz,
Chaoming_Liacd48572011-04-25 12:52:54 -0500346 sizeof(struct ieee80211_supported_band));
347
348 /* <3> init ht cap base on ant_num */
349 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
350
Larry Finger9afa2e42014-09-22 09:39:21 -0500351 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500352 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200353 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500354 } else {
355 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
356 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200357 sband = &(rtlmac->bands[NL80211_BAND_2GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500358
Johannes Berg57fbcce2016-04-12 15:56:15 +0200359 /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500360 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200361 memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500362 &rtl_band_2ghz,
363 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500364
365 /* <3> init ht cap base on ant_num */
366 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
367
368 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200369 hw->wiphy->bands[NL80211_BAND_2GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500370 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
371 /* <1> use mac->bands as mem for hw->wiphy->bands */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200372 sband = &(rtlmac->bands[NL80211_BAND_5GHZ]);
Chaoming_Liacd48572011-04-25 12:52:54 -0500373
Johannes Berg57fbcce2016-04-12 15:56:15 +0200374 /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ]
Chaoming_Liacd48572011-04-25 12:52:54 -0500375 * to default value(1T1R) */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200376 memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]),
Larry Finger9afa2e42014-09-22 09:39:21 -0500377 &rtl_band_5ghz,
378 sizeof(struct ieee80211_supported_band));
Chaoming_Liacd48572011-04-25 12:52:54 -0500379
380 /* <3> init ht cap base on ant_num */
381 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
382
Larry Finger9afa2e42014-09-22 09:39:21 -0500383 _rtl_init_hw_vht_capab(hw, &sband->vht_cap);
Chaoming_Liacd48572011-04-25 12:52:54 -0500384 /* <4> set mac->sband to wiphy->sband */
Johannes Berg57fbcce2016-04-12 15:56:15 +0200385 hw->wiphy->bands[NL80211_BAND_5GHZ] = sband;
Chaoming_Liacd48572011-04-25 12:52:54 -0500386 } else {
Larry Fingerb03d9682016-12-15 12:22:58 -0600387 pr_err("Err BAND %d\n",
388 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500389 }
390 }
Larry Finger0c817332010-12-08 11:12:31 -0600391 /* <5> set hw caps */
Johannes Berg30686bf2015-06-02 21:39:54 +0200392 ieee80211_hw_set(hw, SIGNAL_DBM);
393 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
394 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
395 ieee80211_hw_set(hw, CONNECTION_MONITOR);
396 ieee80211_hw_set(hw, MFP_CAPABLE);
397 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
Larry Finger0c817332010-12-08 11:12:31 -0600398
Chaoming_Liacd48572011-04-25 12:52:54 -0500399 /* swlps or hwlps has been set in diff chip in init_sw_vars */
Johannes Berg30686bf2015-06-02 21:39:54 +0200400 if (rtlpriv->psc.swctrl_lps) {
401 ieee80211_hw_set(hw, SUPPORTS_PS);
402 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
403 }
Ping-Ke Shihe332e2a22017-06-18 11:12:42 -0500404 if (rtlpriv->psc.fwctrl_lps) {
405 ieee80211_hw_set(hw, SUPPORTS_PS);
406 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
407 }
Larry Finger0c817332010-12-08 11:12:31 -0600408 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500409 BIT(NL80211_IFTYPE_AP) |
410 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500411 BIT(NL80211_IFTYPE_ADHOC) |
412 BIT(NL80211_IFTYPE_MESH_POINT) |
413 BIT(NL80211_IFTYPE_P2P_CLIENT) |
414 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger26634c42013-03-24 22:06:33 -0500415 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger9afa2e42014-09-22 09:39:21 -0500416
417 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
418
Larry Finger0c817332010-12-08 11:12:31 -0600419 hw->wiphy->rts_threshold = 2347;
420
421 hw->queues = AC_MAX;
422 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
423
424 /* TODO: Correct this value for our hw */
Souptick Joarder9d546192017-08-02 17:59:15 +0530425 hw->max_listen_interval = MAX_LISTEN_INTERVAL;
426 hw->max_rate_tries = MAX_RATE_TRIES;
Larry Finger0c817332010-12-08 11:12:31 -0600427 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500428 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600429
Larry Finger9afa2e42014-09-22 09:39:21 -0500430/* wowlan is not supported by kernel if CONFIG_PM is not defined */
431#ifdef CONFIG_PM
432 if (rtlpriv->psc.wo_wlan_mode) {
433 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET)
434 rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT;
435 if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) {
436 rtlpriv->wowlan.n_patterns =
437 MAX_SUPPORT_WOL_PATTERN_NUM;
438 rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE;
439 rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE;
440 }
441 hw->wiphy->wowlan = &rtlpriv->wowlan;
442 }
443#endif
444
Larry Finger0c817332010-12-08 11:12:31 -0600445 /* <6> mac address */
446 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
447 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
448 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600449 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
450 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
451 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600452 }
Larry Finger0c817332010-12-08 11:12:31 -0600453}
454
455static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
456{
457 struct rtl_priv *rtlpriv = rtl_priv(hw);
458
459 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600460 setup_timer(&rtlpriv->works.watchdog_timer,
461 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500462 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
463 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600464 /* <2> work queue */
465 rtlpriv->works.hw = hw;
Kees Cook598a0df2014-10-20 14:57:08 -0700466 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
Larry Finger0c817332010-12-08 11:12:31 -0600467 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
468 (void *)rtl_watchdog_wq_callback);
469 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
470 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500471 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
472 (void *)rtl_swlps_wq_callback);
473 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
474 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500475 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
476 (void *)rtl_fwevt_wq_callback);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600477 INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq,
478 (void *)rtl_c2hcmd_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600479
480}
481
482void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
483{
484 struct rtl_priv *rtlpriv = rtl_priv(hw);
485
486 del_timer_sync(&rtlpriv->works.watchdog_timer);
487
488 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
489 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500490 cancel_delayed_work(&rtlpriv->works.ps_work);
491 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500492 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600493 cancel_delayed_work(&rtlpriv->works.c2hcmd_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600494}
Larry Finger6f334c22013-07-12 15:32:15 -0500495EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
Larry Finger0c817332010-12-08 11:12:31 -0600496
497void rtl_init_rfkill(struct ieee80211_hw *hw)
498{
499 struct rtl_priv *rtlpriv = rtl_priv(hw);
500
501 bool radio_state;
502 bool blocked;
503 u8 valid = 0;
504
Chaoming Li228bdfc2011-04-10 18:30:23 -0500505 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000506 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500507 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
508
Larry Finger0c817332010-12-08 11:12:31 -0600509 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
510
Larry Fingere6d8a812010-12-21 19:40:40 -0600511 if (valid) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500512 pr_info("rtlwifi: wireless switch is %s\n",
Joe Perches292b1192011-07-20 08:51:35 -0700513 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500514
Larry Finger0c817332010-12-08 11:12:31 -0600515 rtlpriv->rfkill.rfkill_state = radio_state;
516
517 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
518 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
519 }
520
521 wiphy_rfkill_start_polling(hw->wiphy);
522}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600523EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600524
525void rtl_deinit_rfkill(struct ieee80211_hw *hw)
526{
527 wiphy_rfkill_stop_polling(hw->wiphy);
528}
Larry Finger6f334c22013-07-12 15:32:15 -0500529EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600530
531int rtl_init_core(struct ieee80211_hw *hw)
532{
533 struct rtl_priv *rtlpriv = rtl_priv(hw);
534 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
535
536 /* <1> init mac80211 */
537 _rtl_init_mac80211(hw);
538 rtlmac->hw = hw;
539
540 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600541 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600542
543 /*
544 * <3> init CRDA must come after init
545 * mac80211 hw in _rtl_init_mac80211.
546 */
547 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Larry Fingerb03d9682016-12-15 12:22:58 -0600548 pr_err("REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600549 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600550 }
551
552 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600553 mutex_init(&rtlpriv->locks.conf_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600554 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600555 spin_lock_init(&rtlpriv->locks.irq_th_lock);
556 spin_lock_init(&rtlpriv->locks.h2c_lock);
557 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
558 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500559 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500560 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600561 spin_lock_init(&rtlpriv->locks.c2hcmd_lock);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500562 spin_lock_init(&rtlpriv->locks.scan_list_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500563 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500564 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
565 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
566 spin_lock_init(&rtlpriv->locks.lps_lock);
Larry Finger9afa2e42014-09-22 09:39:21 -0500567 spin_lock_init(&rtlpriv->locks.iqk_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500568 /* <5> init list */
569 INIT_LIST_HEAD(&rtlpriv->entry_list);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600570 INIT_LIST_HEAD(&rtlpriv->c2hcmd_list);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500571 INIT_LIST_HEAD(&rtlpriv->scan_list.list);
Larry Finger0c817332010-12-08 11:12:31 -0600572
573 rtlmac->link_state = MAC80211_NOLINK;
574
Larry Finger26634c42013-03-24 22:06:33 -0500575 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600576 _rtl_init_deferred_work(hw);
577
578 return 0;
579}
Larry Finger6f334c22013-07-12 15:32:15 -0500580EXPORT_SYMBOL_GPL(rtl_init_core);
Larry Finger0c817332010-12-08 11:12:31 -0600581
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500582static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw);
583
Larry Finger0c817332010-12-08 11:12:31 -0600584void rtl_deinit_core(struct ieee80211_hw *hw)
585{
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -0600586 rtl_c2hcmd_launcher(hw, 0);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -0500587 rtl_free_entries_from_scan_list(hw);
Larry Finger0c817332010-12-08 11:12:31 -0600588}
Larry Finger6f334c22013-07-12 15:32:15 -0500589EXPORT_SYMBOL_GPL(rtl_deinit_core);
Larry Finger0c817332010-12-08 11:12:31 -0600590
591void rtl_init_rx_config(struct ieee80211_hw *hw)
592{
593 struct rtl_priv *rtlpriv = rtl_priv(hw);
594 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
595
596 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600597}
Larry Finger6f334c22013-07-12 15:32:15 -0500598EXPORT_SYMBOL_GPL(rtl_init_rx_config);
Larry Finger0c817332010-12-08 11:12:31 -0600599
600/*********************************************************
601 *
602 * tx information functions
603 *
604 *********************************************************/
605static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
606 struct rtl_tcb_desc *tcb_desc,
607 struct ieee80211_tx_info *info)
608{
609 struct rtl_priv *rtlpriv = rtl_priv(hw);
610 u8 rate_flag = info->control.rates[0].flags;
611
612 tcb_desc->use_shortpreamble = false;
613
614 /* 1M can only use Long Preamble. 11B spec */
615 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
616 return;
617 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
618 tcb_desc->use_shortpreamble = true;
619
620 return;
621}
622
623static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500624 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600625 struct rtl_tcb_desc *tcb_desc,
626 struct ieee80211_tx_info *info)
627{
628 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
629 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500630 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -0500631 u8 sgi_80 = 0, bw_80 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600632 tcb_desc->use_shortgi = false;
633
Chaoming_Liacd48572011-04-25 12:52:54 -0500634 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600635 return;
636
Chaoming_Liacd48572011-04-25 12:52:54 -0500637 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
638 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
Larry Finger9afa2e42014-09-22 09:39:21 -0500639 sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80;
Chaoming_Liacd48572011-04-25 12:52:54 -0500640
Larry Finger9afa2e42014-09-22 09:39:21 -0500641 if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600642 return;
643
Chaoming_Liacd48572011-04-25 12:52:54 -0500644 if (!sgi_40 && !sgi_20)
645 return;
646
Larry Finger9afa2e42014-09-22 09:39:21 -0500647 if (mac->opmode == NL80211_IFTYPE_STATION) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500648 bw_40 = mac->bw_40;
Larry Finger9afa2e42014-09-22 09:39:21 -0500649 bw_80 = mac->bw_80;
650 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500651 mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500652 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
653 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
654 bw_80 = sta->vht_cap.vht_supported;
655 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500656
Larry Finger9afa2e42014-09-22 09:39:21 -0500657 if (bw_80) {
658 if (sgi_80)
659 tcb_desc->use_shortgi = true;
660 else
661 tcb_desc->use_shortgi = false;
662 } else {
663 if (bw_40 && sgi_40)
664 tcb_desc->use_shortgi = true;
665 else if (!bw_40 && sgi_20)
666 tcb_desc->use_shortgi = true;
667 }
Larry Finger0c817332010-12-08 11:12:31 -0600668
669 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
670 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600671}
672
673static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
674 struct rtl_tcb_desc *tcb_desc,
675 struct ieee80211_tx_info *info)
676{
677 struct rtl_priv *rtlpriv = rtl_priv(hw);
678 u8 rate_flag = info->control.rates[0].flags;
679
680 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600681 tcb_desc->rts_stbc = false;
682 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600683 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600684 tcb_desc->rts_bw = false;
685 tcb_desc->rts_use_shortpreamble = false;
686 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600687
688 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
689 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600690 tcb_desc->rts_enable = true;
691 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600692 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
693 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
694 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600695 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600696 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
697 }
Larry Finger0c817332010-12-08 11:12:31 -0600698}
699
700static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500701 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600702 struct rtl_tcb_desc *tcb_desc)
703{
704 struct rtl_priv *rtlpriv = rtl_priv(hw);
705 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500706 struct rtl_sta_info *sta_entry = NULL;
707 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600708
Chaoming_Liacd48572011-04-25 12:52:54 -0500709 if (sta) {
710 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
711 ratr_index = sta_entry->ratr_index;
712 }
Larry Finger0c817332010-12-08 11:12:31 -0600713 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500714 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600715 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500716 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500717 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600718 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600719 tcb_desc->hw_rate =
720 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
721 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500722 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600723 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500724 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600725 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500726 } else if (mac->opmode == NL80211_IFTYPE_AP) {
727 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600728 }
729 }
730
Larry Finger7ea47242011-02-19 16:28:57 -0600731 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500732 tcb_desc->ratr_index = ratr_index;
733 /* TODO we will differentiate adhoc and station future */
734 if (mac->opmode == NL80211_IFTYPE_STATION ||
735 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500736 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600737
Larry Finger9afa2e42014-09-22 09:39:21 -0500738 if (mac->mode == WIRELESS_MODE_AC_5G)
739 tcb_desc->ratr_index =
740 RATR_INX_WIRELESS_AC_5N;
741 else if (mac->mode == WIRELESS_MODE_AC_24G)
742 tcb_desc->ratr_index =
743 RATR_INX_WIRELESS_AC_24N;
744 else if (mac->mode == WIRELESS_MODE_N_24G)
Chaoming_Liacd48572011-04-25 12:52:54 -0500745 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
746 else if (mac->mode == WIRELESS_MODE_N_5G)
747 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
748 else if (mac->mode & WIRELESS_MODE_G)
749 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
750 else if (mac->mode & WIRELESS_MODE_B)
751 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
752 else if (mac->mode & WIRELESS_MODE_A)
753 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
Larry Finger9afa2e42014-09-22 09:39:21 -0500754
Chaoming_Liacd48572011-04-25 12:52:54 -0500755 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger9afa2e42014-09-22 09:39:21 -0500756 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500757 if (NULL != sta) {
758 if (sta->aid > 0)
759 tcb_desc->mac_id = sta->aid + 1;
760 else
761 tcb_desc->mac_id = 1;
762 } else {
763 tcb_desc->mac_id = 0;
764 }
Larry Finger0c817332010-12-08 11:12:31 -0600765 }
766 }
Larry Finger0c817332010-12-08 11:12:31 -0600767}
768
769static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500770 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600771 struct rtl_tcb_desc *tcb_desc)
772{
773 struct rtl_priv *rtlpriv = rtl_priv(hw);
774 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
775
Larry Finger7ea47242011-02-19 16:28:57 -0600776 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500777 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600778 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500779 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500780 mac->opmode == NL80211_IFTYPE_ADHOC ||
781 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger9afa2e42014-09-22 09:39:21 -0500782 if (!(sta->ht_cap.ht_supported) ||
783 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
Chaoming_Liacd48572011-04-25 12:52:54 -0500784 return;
785 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
786 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
787 return;
788 }
Larry Finger7ea47242011-02-19 16:28:57 -0600789 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600790 return;
791
792 /*use legency rate, shall use 20MHz */
793 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
794 return;
795
Larry Finger9afa2e42014-09-22 09:39:21 -0500796 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40;
797
798 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE ||
799 rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) {
800 if (mac->opmode == NL80211_IFTYPE_AP ||
801 mac->opmode == NL80211_IFTYPE_ADHOC ||
802 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
803 if (!(sta->vht_cap.vht_supported))
804 return;
805 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
806 if (!mac->bw_80 ||
807 !(sta->vht_cap.vht_supported))
808 return;
809 }
810 if (tcb_desc->hw_rate <=
811 rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15])
812 return;
813 tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80;
814 }
Larry Finger0c817332010-12-08 11:12:31 -0600815}
816
Larry Finger9afa2e42014-09-22 09:39:21 -0500817static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw,
818 struct ieee80211_sta *sta)
Larry Finger0c817332010-12-08 11:12:31 -0600819{
820 struct rtl_priv *rtlpriv = rtl_priv(hw);
821 struct rtl_phy *rtlphy = &(rtlpriv->phy);
822 u8 hw_rate;
Larry Finger9afa2e42014-09-22 09:39:21 -0500823 u16 tx_mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.tx_mcs_map);
Larry Finger0c817332010-12-08 11:12:31 -0600824
Larry Finger9afa2e42014-09-22 09:39:21 -0500825 if ((get_rf_type(rtlphy) == RF_2T2R) &&
826 (tx_mcs_map & 0x000c) != 0x000c) {
827 if ((tx_mcs_map & 0x000c) >> 2 ==
828 IEEE80211_VHT_MCS_SUPPORT_0_7)
829 hw_rate =
830 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7];
831 else if ((tx_mcs_map & 0x000c) >> 2 ==
832 IEEE80211_VHT_MCS_SUPPORT_0_8)
833 hw_rate =
834 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
835 else
836 hw_rate =
837 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
838 } else {
839 if ((tx_mcs_map & 0x0003) ==
840 IEEE80211_VHT_MCS_SUPPORT_0_7)
841 hw_rate =
842 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7];
843 else if ((tx_mcs_map & 0x0003) ==
844 IEEE80211_VHT_MCS_SUPPORT_0_8)
845 hw_rate =
846 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
847 else
848 hw_rate =
849 rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
850 }
851
852 return hw_rate;
853}
854
855static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw,
856 struct ieee80211_sta *sta)
857{
858 struct rtl_priv *rtlpriv = rtl_priv(hw);
859 struct rtl_phy *rtlphy = &rtlpriv->phy;
860 u8 hw_rate;
861
862 if ((get_rf_type(rtlphy) == RF_2T2R) &&
863 (sta->ht_cap.mcs.rx_mask[1] != 0))
Larry Finger0c817332010-12-08 11:12:31 -0600864 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
865 else
866 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
867
868 return hw_rate;
869}
870
Larry Finger7ad0ce32011-08-22 16:50:14 -0500871/* mac80211's rate_idx is like this:
872 *
Johannes Berg57fbcce2016-04-12 15:56:15 +0200873 * 2.4G band:rx_status->band == NL80211_BAND_2GHZ
Larry Finger7ad0ce32011-08-22 16:50:14 -0500874 *
875 * B/G rate:
876 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600877 * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500878 *
879 * N rate:
880 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600881 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Finger7ad0ce32011-08-22 16:50:14 -0500882 *
Johannes Berg57fbcce2016-04-12 15:56:15 +0200883 * 5G band:rx_status->band == NL80211_BAND_5GHZ
Larry Finger7ad0ce32011-08-22 16:50:14 -0500884 * A rate:
885 * (rx_status->flag & RX_FLAG_HT) = 0,
Larry Fingere0e776a2014-12-18 03:05:36 -0600886 * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7,
Larry Finger7ad0ce32011-08-22 16:50:14 -0500887 *
888 * N rate:
889 * (rx_status->flag & RX_FLAG_HT) = 1,
Larry Fingere0e776a2014-12-18 03:05:36 -0600890 * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15
Larry Fingerfd3cb222014-12-18 03:05:40 -0600891 *
892 * VHT rates:
893 * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9
894 * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9
Larry Finger7ad0ce32011-08-22 16:50:14 -0500895 */
Larry Fingerfd3cb222014-12-18 03:05:40 -0600896int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht,
897 u8 desc_rate)
Larry Finger7ad0ce32011-08-22 16:50:14 -0500898{
899 int rate_idx;
900
Larry Fingerfd3cb222014-12-18 03:05:40 -0600901 if (isvht) {
902 switch (desc_rate) {
903 case DESC_RATEVHT1SS_MCS0:
904 rate_idx = 0;
905 break;
906 case DESC_RATEVHT1SS_MCS1:
907 rate_idx = 1;
908 break;
909 case DESC_RATEVHT1SS_MCS2:
910 rate_idx = 2;
911 break;
912 case DESC_RATEVHT1SS_MCS3:
913 rate_idx = 3;
914 break;
915 case DESC_RATEVHT1SS_MCS4:
916 rate_idx = 4;
917 break;
918 case DESC_RATEVHT1SS_MCS5:
919 rate_idx = 5;
920 break;
921 case DESC_RATEVHT1SS_MCS6:
922 rate_idx = 6;
923 break;
924 case DESC_RATEVHT1SS_MCS7:
925 rate_idx = 7;
926 break;
927 case DESC_RATEVHT1SS_MCS8:
928 rate_idx = 8;
929 break;
930 case DESC_RATEVHT1SS_MCS9:
931 rate_idx = 9;
932 break;
933 case DESC_RATEVHT2SS_MCS0:
934 rate_idx = 0;
935 break;
936 case DESC_RATEVHT2SS_MCS1:
937 rate_idx = 1;
938 break;
939 case DESC_RATEVHT2SS_MCS2:
940 rate_idx = 2;
941 break;
942 case DESC_RATEVHT2SS_MCS3:
943 rate_idx = 3;
944 break;
945 case DESC_RATEVHT2SS_MCS4:
946 rate_idx = 4;
947 break;
948 case DESC_RATEVHT2SS_MCS5:
949 rate_idx = 5;
950 break;
951 case DESC_RATEVHT2SS_MCS6:
952 rate_idx = 6;
953 break;
954 case DESC_RATEVHT2SS_MCS7:
955 rate_idx = 7;
956 break;
957 case DESC_RATEVHT2SS_MCS8:
958 rate_idx = 8;
959 break;
960 case DESC_RATEVHT2SS_MCS9:
961 rate_idx = 9;
962 break;
963 default:
964 rate_idx = 0;
965 break;
966 }
967 return rate_idx;
968 }
Larry Finger7ad0ce32011-08-22 16:50:14 -0500969 if (false == isht) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200970 if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
Larry Finger7ad0ce32011-08-22 16:50:14 -0500971 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -0600972 case DESC_RATE1M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500973 rate_idx = 0;
974 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600975 case DESC_RATE2M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500976 rate_idx = 1;
977 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600978 case DESC_RATE5_5M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500979 rate_idx = 2;
980 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600981 case DESC_RATE11M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500982 rate_idx = 3;
983 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600984 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500985 rate_idx = 4;
986 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600987 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500988 rate_idx = 5;
989 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600990 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500991 rate_idx = 6;
992 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600993 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500994 rate_idx = 7;
995 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600996 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -0500997 rate_idx = 8;
998 break;
Larry Fingere0e776a2014-12-18 03:05:36 -0600999 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001000 rate_idx = 9;
1001 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001002 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001003 rate_idx = 10;
1004 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001005 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001006 rate_idx = 11;
1007 break;
1008 default:
1009 rate_idx = 0;
1010 break;
1011 }
1012 } else {
1013 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001014 case DESC_RATE6M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001015 rate_idx = 0;
1016 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001017 case DESC_RATE9M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001018 rate_idx = 1;
1019 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001020 case DESC_RATE12M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001021 rate_idx = 2;
1022 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001023 case DESC_RATE18M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001024 rate_idx = 3;
1025 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001026 case DESC_RATE24M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001027 rate_idx = 4;
1028 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001029 case DESC_RATE36M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001030 rate_idx = 5;
1031 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001032 case DESC_RATE48M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001033 rate_idx = 6;
1034 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001035 case DESC_RATE54M:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001036 rate_idx = 7;
1037 break;
1038 default:
1039 rate_idx = 0;
1040 break;
1041 }
1042 }
Larry Finger7ad0ce32011-08-22 16:50:14 -05001043 } else {
Larry Finger7ad0ce32011-08-22 16:50:14 -05001044 switch (desc_rate) {
Larry Fingere0e776a2014-12-18 03:05:36 -06001045 case DESC_RATEMCS0:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001046 rate_idx = 0;
1047 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001048 case DESC_RATEMCS1:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001049 rate_idx = 1;
1050 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001051 case DESC_RATEMCS2:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001052 rate_idx = 2;
1053 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001054 case DESC_RATEMCS3:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001055 rate_idx = 3;
1056 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001057 case DESC_RATEMCS4:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001058 rate_idx = 4;
1059 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001060 case DESC_RATEMCS5:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001061 rate_idx = 5;
1062 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001063 case DESC_RATEMCS6:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001064 rate_idx = 6;
1065 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001066 case DESC_RATEMCS7:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001067 rate_idx = 7;
1068 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001069 case DESC_RATEMCS8:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001070 rate_idx = 8;
1071 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001072 case DESC_RATEMCS9:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001073 rate_idx = 9;
1074 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001075 case DESC_RATEMCS10:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001076 rate_idx = 10;
1077 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001078 case DESC_RATEMCS11:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001079 rate_idx = 11;
1080 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001081 case DESC_RATEMCS12:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001082 rate_idx = 12;
1083 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001084 case DESC_RATEMCS13:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001085 rate_idx = 13;
1086 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001087 case DESC_RATEMCS14:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001088 rate_idx = 14;
1089 break;
Larry Fingere0e776a2014-12-18 03:05:36 -06001090 case DESC_RATEMCS15:
Larry Finger7ad0ce32011-08-22 16:50:14 -05001091 rate_idx = 15;
1092 break;
1093 default:
1094 rate_idx = 0;
1095 break;
1096 }
1097 }
1098 return rate_idx;
1099}
1100EXPORT_SYMBOL(rtlwifi_rate_mapping);
1101
Ping-Ke Shihcdc9c7a2017-09-29 14:47:54 -05001102static u8 _rtl_get_tx_hw_rate(struct ieee80211_hw *hw,
1103 struct ieee80211_tx_info *info)
1104{
1105 struct rtl_priv *rtlpriv = rtl_priv(hw);
1106 struct ieee80211_tx_rate *r = &info->status.rates[0];
1107 struct ieee80211_rate *txrate;
1108 u8 hw_value = 0x0;
1109
1110 if (r->flags & IEEE80211_TX_RC_MCS) {
1111 /* HT MCS0-15 */
1112 hw_value = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15] - 15 +
1113 r->idx;
1114 } else if (r->flags & IEEE80211_TX_RC_VHT_MCS) {
1115 /* VHT MCS0-9, NSS */
1116 if (ieee80211_rate_get_vht_nss(r) == 2)
1117 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9];
1118 else
1119 hw_value = rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9];
1120
1121 hw_value = hw_value - 9 + ieee80211_rate_get_vht_mcs(r);
1122 } else {
1123 /* legacy */
1124 txrate = ieee80211_get_tx_rate(hw, info);
1125
1126 if (txrate)
1127 hw_value = txrate->hw_value;
1128 }
1129
1130 /* check 5G band */
1131 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G &&
1132 hw_value < rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M])
1133 hw_value = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE6M];
1134
1135 return hw_value;
1136}
1137
Larry Finger0c817332010-12-08 11:12:31 -06001138void rtl_get_tcb_desc(struct ieee80211_hw *hw,
1139 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -05001140 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -06001141 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
1142{
1143 struct rtl_priv *rtlpriv = rtl_priv(hw);
1144 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001145 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Ping-Ke Shihcdc9c7a2017-09-29 14:47:54 -05001146
Larry Finger9afa2e42014-09-22 09:39:21 -05001147 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001148
Ping-Ke Shihcdc9c7a2017-09-29 14:47:54 -05001149 tcb_desc->hw_rate = _rtl_get_tx_hw_rate(hw, info);
Larry Finger0c817332010-12-08 11:12:31 -06001150
Ping-Ke Shih84795802017-06-18 11:12:44 -05001151 if (rtl_is_tx_report_skb(hw, skb))
1152 tcb_desc->use_spe_rpt = 1;
1153
Larry Finger0c817332010-12-08 11:12:31 -06001154 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001155 /*
Chaoming_Liacd48572011-04-25 12:52:54 -05001156 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -06001157 *in rtl_rc.c if skb is special data or
1158 *mgt which need low data rate.
1159 */
1160
1161 /*
1162 *So tcb_desc->hw_rate is just used for
1163 *special data and mgt frames
1164 */
Chaoming Li09e92f02011-10-11 21:28:48 -05001165 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -05001166 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -06001167 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001168 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001169
Larry Finger0c817332010-12-08 11:12:31 -06001170 tcb_desc->disable_ratefallback = 1;
1171 } else {
1172 /*
1173 *because hw will nerver use hw_rate
1174 *when tcb_desc->use_driver_rate = false
1175 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001176 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -06001177 *when tcb_desc->use_driver_rate = false
1178 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001179 if (sta && sta->vht_cap.vht_supported) {
1180 tcb_desc->hw_rate =
1181 _rtl_get_vht_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001182 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001183 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -06001184 tcb_desc->hw_rate =
Larry Finger9afa2e42014-09-22 09:39:21 -05001185 _rtl_get_highest_n_rate(hw, sta);
Larry Finger0c817332010-12-08 11:12:31 -06001186 } else {
Larry Finger9afa2e42014-09-22 09:39:21 -05001187 if (rtlmac->mode == WIRELESS_MODE_B) {
1188 tcb_desc->hw_rate =
1189 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
1190 } else {
1191 tcb_desc->hw_rate =
1192 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
1193 }
Larry Finger0c817332010-12-08 11:12:31 -06001194 }
1195 }
1196 }
1197
Ping-Ke Shihe7c52862017-07-02 13:12:36 -05001198 if (is_multicast_ether_addr(hdr->addr1))
Larry Finger7ea47242011-02-19 16:28:57 -06001199 tcb_desc->multicast = 1;
Ping-Ke Shihe7c52862017-07-02 13:12:36 -05001200 else if (is_broadcast_ether_addr(hdr->addr1))
Larry Finger7ea47242011-02-19 16:28:57 -06001201 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -06001202
Chaoming_Liacd48572011-04-25 12:52:54 -05001203 _rtl_txrate_selectmode(hw, sta, tcb_desc);
1204 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -06001205 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -05001206 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -06001207 _rtl_query_protection_mode(hw, tcb_desc, info);
1208 } else {
1209 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001210 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -06001211 tcb_desc->disable_ratefallback = 1;
1212 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001213 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -06001214 }
1215}
1216EXPORT_SYMBOL(rtl_get_tcb_desc);
1217
Larry Finger9afa2e42014-09-22 09:39:21 -05001218bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
1219{
1220 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1221 struct rtl_priv *rtlpriv = rtl_priv(hw);
1222 __le16 fc = rtl_get_fc(skb);
1223
1224 if (rtlpriv->dm.supp_phymode_switch &&
1225 mac->link_state < MAC80211_LINKED &&
1226 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
1227 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1228 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1229 }
1230 if (ieee80211_is_auth(fc)) {
1231 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
1232 rtl_ips_nic_on(hw);
1233
1234 mac->link_state = MAC80211_LINKING;
1235 /* Dul mac */
1236 rtlpriv->phy.need_iqk = true;
1237
1238 }
1239
1240 return true;
1241}
1242EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
1243
1244struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa,
1245 u8 *bssid, u16 tid);
1246
1247static void process_agg_start(struct ieee80211_hw *hw,
1248 struct ieee80211_hdr *hdr, u16 tid)
Larry Finger26634c42013-03-24 22:06:33 -05001249{
1250 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001251 struct ieee80211_rx_status rx_status = { 0 };
Larry Finger9afa2e42014-09-22 09:39:21 -05001252 struct sk_buff *skb_delba = NULL;
Larry Finger26634c42013-03-24 22:06:33 -05001253
Larry Finger9afa2e42014-09-22 09:39:21 -05001254 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
1255 if (skb_delba) {
1256 rx_status.freq = hw->conf.chandef.chan->center_freq;
1257 rx_status.band = hw->conf.chandef.chan->band;
1258 rx_status.flag |= RX_FLAG_DECRYPTED;
1259 rx_status.flag |= RX_FLAG_MACTIME_START;
1260 rx_status.rate_idx = 0;
1261 rx_status.signal = 50 + 10;
1262 memcpy(IEEE80211_SKB_RXCB(skb_delba),
1263 &rx_status, sizeof(rx_status));
1264 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1265 "fake del\n",
1266 skb_delba->data,
1267 skb_delba->len);
1268 ieee80211_rx_irqsafe(hw, skb_delba);
Larry Finger26634c42013-03-24 22:06:33 -05001269 }
Larry Finger26634c42013-03-24 22:06:33 -05001270}
1271
Larry Finger0c817332010-12-08 11:12:31 -06001272bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1273{
1274 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001275 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001276 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001277 __le16 fc = rtl_get_fc(skb);
1278 u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN));
Larry Finger0c817332010-12-08 11:12:31 -06001279 u8 category;
1280
1281 if (!ieee80211_is_action(fc))
1282 return true;
1283
1284 category = *act;
1285 act++;
1286 switch (category) {
1287 case ACT_CAT_BA:
1288 switch (*act) {
1289 case ACT_ADDBAREQ:
1290 if (mac->act_scanning)
1291 return false;
1292
1293 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Larry Finger9afa2e42014-09-22 09:39:21 -05001294 "%s ACT_ADDBAREQ From :%pM\n",
1295 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001296 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001297 skb->data, skb->len);
1298 if (!is_tx) {
1299 struct ieee80211_sta *sta = NULL;
1300 struct rtl_sta_info *sta_entry = NULL;
1301 struct rtl_tid_data *tid_data;
1302 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1303 u16 capab = 0, tid = 0;
1304
1305 rcu_read_lock();
1306 sta = rtl_find_sta(hw, hdr->addr3);
1307 if (sta == NULL) {
1308 RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV,
1309 DBG_DMESG, "sta is NULL\n");
1310 rcu_read_unlock();
Larry Finger26634c42013-03-24 22:06:33 -05001311 return true;
Larry Finger9afa2e42014-09-22 09:39:21 -05001312 }
1313
1314 sta_entry =
1315 (struct rtl_sta_info *)sta->drv_priv;
1316 if (!sta_entry) {
1317 rcu_read_unlock();
1318 return true;
1319 }
1320 capab =
1321 le16_to_cpu(mgmt->u.action.u.addba_req.capab);
1322 tid = (capab &
1323 IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1324 tid_data = &sta_entry->tids[tid];
1325 if (tid_data->agg.rx_agg_state ==
1326 RTL_RX_AGG_START)
1327 process_agg_start(hw, hdr, tid);
1328 rcu_read_unlock();
1329 }
Larry Finger0c817332010-12-08 11:12:31 -06001330 break;
1331 case ACT_ADDBARSP:
1332 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001333 "%s ACT_ADDBARSP From :%pM\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001334 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001335 break;
1336 case ACT_DELBA:
1337 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001338 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001339 break;
1340 }
1341 break;
1342 default:
1343 break;
1344 }
1345
1346 return true;
1347}
Larry Finger6f334c22013-07-12 15:32:15 -05001348EXPORT_SYMBOL_GPL(rtl_action_proc);
Larry Finger0c817332010-12-08 11:12:31 -06001349
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001350static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc,
1351 int type)
Larry Finger9afa2e42014-09-22 09:39:21 -05001352{
Larry Fingerba9f93f2016-11-26 14:43:35 -06001353 struct ieee80211_hw *hw = rtlpriv->hw;
1354
Larry Finger9afa2e42014-09-22 09:39:21 -05001355 rtlpriv->ra.is_special_data = true;
1356 if (rtlpriv->cfg->ops->get_btc_status())
1357 rtlpriv->btcoexist.btc_ops->btc_special_packet_notify(
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001358 rtlpriv, type);
Larry Fingerba9f93f2016-11-26 14:43:35 -06001359 rtl_lps_leave(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001360 ppsc->last_delaylps_stamp_jiffies = jiffies;
1361}
1362
Ping-Ke Shih84795802017-06-18 11:12:44 -05001363static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw,
1364 struct sk_buff *skb, bool is_enc)
Larry Finger0c817332010-12-08 11:12:31 -06001365{
1366 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001367 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
Larry Finger9afa2e42014-09-22 09:39:21 -05001368 u8 encrypt_header_len = 0;
1369 u8 offset;
Larry Finger0c817332010-12-08 11:12:31 -06001370
Larry Finger9afa2e42014-09-22 09:39:21 -05001371 switch (rtlpriv->sec.pairwise_enc_algorithm) {
1372 case WEP40_ENCRYPTION:
1373 case WEP104_ENCRYPTION:
1374 encrypt_header_len = 4;/*WEP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001375 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001376 case TKIP_ENCRYPTION:
1377 encrypt_header_len = 8;/*TKIP_IV_LEN*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001378 break;
Larry Finger9afa2e42014-09-22 09:39:21 -05001379 case AESCCMP_ENCRYPTION:
1380 encrypt_header_len = 8;/*CCMP_HDR_LEN;*/
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001381 break;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001382 default:
Larry Finger9afa2e42014-09-22 09:39:21 -05001383 break;
Larry Finger0c817332010-12-08 11:12:31 -06001384 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001385
Taehee Yoocad737d2015-03-28 00:22:39 +09001386 offset = mac_hdr_len + SNAP_SIZE;
1387 if (is_enc)
1388 offset += encrypt_header_len;
Ping-Ke Shih84795802017-06-18 11:12:44 -05001389
1390 return skb->data + offset;
1391}
1392
1393/*should call before software enc*/
1394u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx,
1395 bool is_enc)
1396{
1397 struct rtl_priv *rtlpriv = rtl_priv(hw);
1398 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1399 __le16 fc = rtl_get_fc(skb);
1400 u16 ether_type;
1401 const u8 *ether_type_ptr;
1402 const struct iphdr *ip;
1403
1404 if (!ieee80211_is_data(fc))
1405 goto end;
1406
1407 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc);
1408 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
Larry Finger9afa2e42014-09-22 09:39:21 -05001409
1410 if (ETH_P_IP == ether_type) {
Ping-Ke Shih84795802017-06-18 11:12:44 -05001411 ip = (struct iphdr *)((u8 *)ether_type_ptr +
Larry Finger9afa2e42014-09-22 09:39:21 -05001412 PROTOC_TYPE_SIZE);
1413 if (IPPROTO_UDP == ip->protocol) {
1414 struct udphdr *udp = (struct udphdr *)((u8 *)ip +
1415 (ip->ihl << 2));
1416 if (((((u8 *)udp)[1] == 68) &&
1417 (((u8 *)udp)[3] == 67)) ||
1418 ((((u8 *)udp)[1] == 67) &&
1419 (((u8 *)udp)[3] == 68))) {
1420 /* 68 : UDP BOOTP client
1421 * 67 : UDP BOOTP server
1422 */
1423 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
1424 DBG_DMESG, "dhcp %s !!\n",
1425 (is_tx) ? "Tx" : "Rx");
1426
1427 if (is_tx)
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001428 setup_special_tx(rtlpriv, ppsc,
1429 PACKET_DHCP);
1430
Larry Finger9afa2e42014-09-22 09:39:21 -05001431 return true;
1432 }
1433 }
1434 } else if (ETH_P_ARP == ether_type) {
1435 if (is_tx)
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001436 setup_special_tx(rtlpriv, ppsc, PACKET_ARP);
Larry Finger9afa2e42014-09-22 09:39:21 -05001437
1438 return true;
1439 } else if (ETH_P_PAE == ether_type) {
Ping-Ke Shih11f35c92017-07-02 13:12:30 -05001440 /* EAPOL is seens as in-4way */
1441 rtlpriv->btcoexist.btc_info.in_4way = true;
1442 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1443 rtlpriv->btcoexist.btc_info.in_4way_ts = jiffies;
1444
Larry Finger9afa2e42014-09-22 09:39:21 -05001445 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1446 "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx");
1447
1448 if (is_tx) {
1449 rtlpriv->ra.is_special_data = true;
Larry Fingerba9f93f2016-11-26 14:43:35 -06001450 rtl_lps_leave(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001451 ppsc->last_delaylps_stamp_jiffies = jiffies;
Ping-Ke Shih5b757ba2017-06-18 11:12:45 -05001452
1453 setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL);
Larry Finger9afa2e42014-09-22 09:39:21 -05001454 }
1455
1456 return true;
Larry Fingerc8f03452015-02-24 09:23:01 -06001457 } else if (ETH_P_IPV6 == ether_type) {
1458 /* TODO: Handle any IPv6 cases that need special handling.
1459 * For now, always return false
1460 */
1461 goto end;
Mark Cave-Ayland0c5d63f2013-11-02 14:28:35 -05001462 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001463
1464end:
1465 rtlpriv->ra.is_special_data = false;
1466 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001467}
Larry Finger6f334c22013-07-12 15:32:15 -05001468EXPORT_SYMBOL_GPL(rtl_is_special_data);
Larry Finger0c817332010-12-08 11:12:31 -06001469
Ping-Ke Shih84795802017-06-18 11:12:44 -05001470bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb)
1471{
1472 u16 ether_type;
1473 const u8 *ether_type_ptr;
1474
1475 ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true);
1476 ether_type = be16_to_cpup((__be16 *)ether_type_ptr);
1477
1478 /* EAPOL */
1479 if (ether_type == ETH_P_PAE)
1480 return true;
1481
1482 return false;
1483}
1484
1485static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw)
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 = atomic_inc_return(&tx_report->sn) & 0x0FFF;
1492
1493 tx_report->last_sent_sn = sn;
1494 tx_report->last_sent_time = jiffies;
1495
1496 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1497 "Send TX-Report sn=0x%X\n", sn);
1498
1499 return sn;
1500}
1501
1502void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc,
1503 struct ieee80211_hw *hw)
1504{
1505 if (ptcb_desc->use_spe_rpt) {
1506 u16 sn = rtl_get_tx_report_sn(hw);
1507
1508 SET_TX_DESC_SPE_RPT(pdesc, 1);
1509 SET_TX_DESC_SW_DEFINE(pdesc, sn);
1510 }
1511}
1512EXPORT_SYMBOL_GPL(rtl_get_tx_report);
1513
1514void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len)
1515{
1516 struct rtl_priv *rtlpriv = rtl_priv(hw);
1517 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1518 u16 sn;
1519
1520 sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6];
1521
1522 tx_report->last_recv_sn = sn;
1523
1524 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG,
1525 "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n",
1526 tmp_buf[0], sn, tmp_buf[2]);
1527}
1528EXPORT_SYMBOL_GPL(rtl_tx_report_handler);
1529
1530bool rtl_check_tx_report_acked(struct ieee80211_hw *hw)
1531{
1532 struct rtl_priv *rtlpriv = rtl_priv(hw);
1533 struct rtl_tx_report *tx_report = &rtlpriv->tx_report;
1534
1535 if (tx_report->last_sent_sn == tx_report->last_recv_sn)
1536 return true;
1537
1538 if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) {
1539 RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING,
1540 "Check TX-Report timeout!!\n");
1541 return true; /* 3 sec. (timeout) seen as acked */
1542 }
1543
1544 return false;
1545}
1546
1547void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms)
1548{
1549 struct rtl_priv *rtlpriv = rtl_priv(hw);
1550 int i;
1551
1552 for (i = 0; i < wait_ms; i++) {
1553 if (rtl_check_tx_report_acked(hw))
1554 break;
1555 usleep_range(1000, 2000);
1556 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
1557 "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms);
1558 }
1559}
Larry Finger0c817332010-12-08 11:12:31 -06001560/*********************************************************
1561 *
1562 * functions called by core.c
1563 *
1564 *********************************************************/
Larry Fingerf7953b22014-09-22 09:39:20 -05001565int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1566 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001567{
1568 struct rtl_priv *rtlpriv = rtl_priv(hw);
1569 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;
Larry Finger0c817332010-12-08 11:12:31 -06001574
1575 if (unlikely(tid >= MAX_TID_COUNT))
1576 return -EINVAL;
1577
Chaoming_Liacd48572011-04-25 12:52:54 -05001578 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1579 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001580 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001581 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001582
Larry Finger9afa2e42014-09-22 09:39:21 -05001583 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1584 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1585 tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001586
Chaoming_Liacd48572011-04-25 12:52:54 -05001587 *ssn = tid_data->seq_number;
1588 tid_data->agg.agg_state = RTL_AGG_START;
1589
Larry Finger9afa2e42014-09-22 09:39:21 -05001590 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001591 return 0;
1592}
1593
Larry Fingerf7953b22014-09-22 09:39:20 -05001594int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1595 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001596{
Larry Finger0c817332010-12-08 11:12:31 -06001597 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger9afa2e42014-09-22 09:39:21 -05001598 struct rtl_tid_data *tid_data;
Chaoming_Liacd48572011-04-25 12:52:54 -05001599 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001600
Chaoming_Liacd48572011-04-25 12:52:54 -05001601 if (sta == NULL)
1602 return -EINVAL;
1603
Larry Finger9afa2e42014-09-22 09:39:21 -05001604 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1605 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001606
Larry Finger0c817332010-12-08 11:12:31 -06001607 if (unlikely(tid >= MAX_TID_COUNT))
1608 return -EINVAL;
1609
Chaoming_Liacd48572011-04-25 12:52:54 -05001610 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Larry Finger9afa2e42014-09-22 09:39:21 -05001611 tid_data = &sta_entry->tids[tid];
Chaoming_Liacd48572011-04-25 12:52:54 -05001612 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001613
Larry Finger9afa2e42014-09-22 09:39:21 -05001614 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001615 return 0;
1616}
Larry Finger0c817332010-12-08 11:12:31 -06001617
Larry Finger26634c42013-03-24 22:06:33 -05001618int rtl_rx_agg_start(struct ieee80211_hw *hw,
1619 struct ieee80211_sta *sta, u16 tid)
1620{
1621 struct rtl_priv *rtlpriv = rtl_priv(hw);
1622 struct rtl_tid_data *tid_data;
1623 struct rtl_sta_info *sta_entry = NULL;
Ping-Ke Shih26356642017-06-18 11:12:47 -05001624 u8 reject_agg;
Larry Finger26634c42013-03-24 22:06:33 -05001625
1626 if (sta == NULL)
1627 return -EINVAL;
1628
1629 if (unlikely(tid >= MAX_TID_COUNT))
1630 return -EINVAL;
1631
Ping-Ke Shih26356642017-06-18 11:12:47 -05001632 if (rtlpriv->cfg->ops->get_btc_status()) {
1633 rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv,
1634 &reject_agg,
1635 NULL, NULL);
1636 if (reject_agg)
1637 return -EINVAL;
1638 }
1639
Larry Finger26634c42013-03-24 22:06:33 -05001640 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1641 if (!sta_entry)
1642 return -ENXIO;
1643 tid_data = &sta_entry->tids[tid];
1644
1645 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1646 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1647 tid_data->seq_number);
1648
1649 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1650 return 0;
1651}
1652
1653int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1654 struct ieee80211_sta *sta, u16 tid)
1655{
1656 struct rtl_priv *rtlpriv = rtl_priv(hw);
1657 struct rtl_sta_info *sta_entry = NULL;
1658
1659 if (sta == NULL)
1660 return -EINVAL;
1661
Larry Finger26634c42013-03-24 22:06:33 -05001662 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1663 "on ra = %pM tid = %d\n", sta->addr, tid);
1664
1665 if (unlikely(tid >= MAX_TID_COUNT))
1666 return -EINVAL;
1667
1668 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1669 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1670
1671 return 0;
1672}
Chaoming_Liacd48572011-04-25 12:52:54 -05001673int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1674 struct ieee80211_sta *sta, u16 tid)
1675{
1676 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001677 struct rtl_sta_info *sta_entry = NULL;
1678
1679 if (sta == NULL)
1680 return -EINVAL;
1681
Larry Finger9afa2e42014-09-22 09:39:21 -05001682 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1683 "on ra = %pM tid = %d\n", sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001684
1685 if (unlikely(tid >= MAX_TID_COUNT))
1686 return -EINVAL;
1687
1688 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001689 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001690
1691 return 0;
1692}
1693
Ping-Ke Shih26356642017-06-18 11:12:47 -05001694void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv)
1695{
1696 struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops;
1697 u8 reject_agg, ctrl_agg_size = 0, agg_size;
1698
1699 if (rtlpriv->cfg->ops->get_btc_status())
1700 btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg,
1701 &ctrl_agg_size, &agg_size);
1702
1703 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
1704 "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d",
1705 reject_agg, ctrl_agg_size, agg_size);
1706
1707 rtlpriv->hw->max_rx_aggregation_subframes =
1708 (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF);
1709}
1710EXPORT_SYMBOL(rtl_rx_ampdu_apply);
1711
Larry Finger0c817332010-12-08 11:12:31 -06001712/*********************************************************
1713 *
1714 * wq & timer callback functions
1715 *
1716 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001717/* this function is used for roaming */
1718void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1719{
1720 struct rtl_priv *rtlpriv = rtl_priv(hw);
1721 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1722
1723 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1724 return;
1725
1726 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1727 return;
1728
1729 /* check if this really is a beacon */
1730 if (!ieee80211_is_beacon(hdr->frame_control) &&
1731 !ieee80211_is_probe_resp(hdr->frame_control))
1732 return;
1733
1734 /* min. beacon length + FCS_LEN */
1735 if (skb->len <= 40 + FCS_LEN)
1736 return;
1737
1738 /* and only beacons from the associated BSSID, please */
Larry Finger9afa2e42014-09-22 09:39:21 -05001739 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Larry Finger26634c42013-03-24 22:06:33 -05001740 return;
1741
1742 rtlpriv->link_info.bcn_rx_inperiod++;
1743}
Larry Finger6f334c22013-07-12 15:32:15 -05001744EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
Larry Finger26634c42013-03-24 22:06:33 -05001745
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001746static void rtl_free_entries_from_scan_list(struct ieee80211_hw *hw)
1747{
1748 struct rtl_priv *rtlpriv = rtl_priv(hw);
1749 struct rtl_bssid_entry *entry, *next;
1750
1751 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1752 list_del(&entry->list);
1753 kfree(entry);
1754 rtlpriv->scan_list.num--;
1755 }
1756}
1757
1758void rtl_scan_list_expire(struct ieee80211_hw *hw)
1759{
1760 struct rtl_priv *rtlpriv = rtl_priv(hw);
1761 struct rtl_bssid_entry *entry, *next;
1762 unsigned long flags;
1763
1764 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1765
1766 list_for_each_entry_safe(entry, next, &rtlpriv->scan_list.list, list) {
1767 /* 180 seconds */
1768 if (jiffies_to_msecs(jiffies - entry->age) < 180000)
1769 continue;
1770
1771 list_del(&entry->list);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001772 rtlpriv->scan_list.num--;
1773
1774 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1775 "BSSID=%pM is expire in scan list (total=%d)\n",
1776 entry->bssid, rtlpriv->scan_list.num);
Colin Ian Kingd0116f62017-06-30 11:08:43 +01001777 kfree(entry);
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05001778 }
1779
1780 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1781
1782 rtlpriv->btcoexist.btc_info.ap_num = rtlpriv->scan_list.num;
1783}
1784
1785void rtl_collect_scan_list(struct ieee80211_hw *hw, struct sk_buff *skb)
1786{
1787 struct rtl_priv *rtlpriv = rtl_priv(hw);
1788 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1789 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1790 unsigned long flags;
1791
1792 struct rtl_bssid_entry *entry;
1793 bool entry_found = false;
1794
1795 /* check if it is scanning */
1796 if (!mac->act_scanning)
1797 return;
1798
1799 /* check if this really is a beacon */
1800 if (!ieee80211_is_beacon(hdr->frame_control) &&
1801 !ieee80211_is_probe_resp(hdr->frame_control))
1802 return;
1803
1804 spin_lock_irqsave(&rtlpriv->locks.scan_list_lock, flags);
1805
1806 list_for_each_entry(entry, &rtlpriv->scan_list.list, list) {
1807 if (memcmp(entry->bssid, hdr->addr3, ETH_ALEN) == 0) {
1808 list_del_init(&entry->list);
1809 entry_found = true;
1810 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1811 "Update BSSID=%pM to scan list (total=%d)\n",
1812 hdr->addr3, rtlpriv->scan_list.num);
1813 break;
1814 }
1815 }
1816
1817 if (!entry_found) {
1818 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1819
1820 if (!entry)
1821 goto label_err;
1822
1823 memcpy(entry->bssid, hdr->addr3, ETH_ALEN);
1824 rtlpriv->scan_list.num++;
1825
1826 RT_TRACE(rtlpriv, COMP_SCAN, DBG_LOUD,
1827 "Add BSSID=%pM to scan list (total=%d)\n",
1828 hdr->addr3, rtlpriv->scan_list.num);
1829 }
1830
1831 entry->age = jiffies;
1832
1833 list_add_tail(&entry->list, &rtlpriv->scan_list.list);
1834
1835label_err:
1836 spin_unlock_irqrestore(&rtlpriv->locks.scan_list_lock, flags);
1837}
1838EXPORT_SYMBOL(rtl_collect_scan_list);
1839
Larry Finger0c817332010-12-08 11:12:31 -06001840void rtl_watchdog_wq_callback(void *data)
1841{
1842 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1843 struct rtl_works,
1844 watchdog_wq);
1845 struct ieee80211_hw *hw = rtlworks->hw;
1846 struct rtl_priv *rtlpriv = rtl_priv(hw);
1847 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1848 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001849 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001850 bool tx_busy_traffic = false;
1851 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001852 bool higher_busytraffic = false;
1853 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001854 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001855 u32 rx_cnt_inp4eriod = 0;
1856 u32 tx_cnt_inp4eriod = 0;
1857 u32 aver_rx_cnt_inperiod = 0;
1858 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001859 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1860 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001861
1862 if (is_hal_stop(rtlhal))
1863 return;
1864
1865 /* <1> Determine if action frame is allowed */
1866 if (mac->link_state > MAC80211_NOLINK) {
1867 if (mac->cnt_after_linked < 20)
1868 mac->cnt_after_linked++;
1869 } else {
1870 mac->cnt_after_linked = 0;
1871 }
1872
Larry Finger9afa2e42014-09-22 09:39:21 -05001873 /* <2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001874 * busytraffic we don't change channel
1875 */
1876 if (mac->link_state >= MAC80211_LINKED) {
1877
1878 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1879 for (idx = 0; idx <= 2; idx++) {
1880 rtlpriv->link_info.num_rx_in4period[idx] =
1881 rtlpriv->link_info.num_rx_in4period[idx + 1];
1882 rtlpriv->link_info.num_tx_in4period[idx] =
1883 rtlpriv->link_info.num_tx_in4period[idx + 1];
1884 }
1885 rtlpriv->link_info.num_rx_in4period[3] =
1886 rtlpriv->link_info.num_rx_inperiod;
1887 rtlpriv->link_info.num_tx_in4period[3] =
1888 rtlpriv->link_info.num_tx_inperiod;
1889 for (idx = 0; idx <= 3; idx++) {
1890 rx_cnt_inp4eriod +=
1891 rtlpriv->link_info.num_rx_in4period[idx];
1892 tx_cnt_inp4eriod +=
1893 rtlpriv->link_info.num_tx_in4period[idx];
1894 }
1895 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1896 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1897
1898 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001899 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001900 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001901 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1902 rx_busy_traffic = true;
1903 else
1904 tx_busy_traffic = false;
1905 }
Larry Finger0c817332010-12-08 11:12:31 -06001906
1907 /* Higher Tx/Rx data. */
1908 if (aver_rx_cnt_inperiod > 4000 ||
1909 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001910 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001911
1912 /* Extremely high Rx data. */
1913 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001914 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001915 }
1916
1917 /* check every tid's tx traffic */
1918 for (tid = 0; tid <= 7; tid++) {
1919 for (idx = 0; idx <= 2; idx++)
1920 rtlpriv->link_info.tidtx_in4period[tid][idx] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001921 rtlpriv->link_info.tidtx_in4period[tid]
1922 [idx + 1];
Chaoming_Liacd48572011-04-25 12:52:54 -05001923 rtlpriv->link_info.tidtx_in4period[tid][3] =
1924 rtlpriv->link_info.tidtx_inperiod[tid];
1925
1926 for (idx = 0; idx <= 3; idx++)
1927 tidtx_inp4eriod[tid] +=
Larry Finger9afa2e42014-09-22 09:39:21 -05001928 rtlpriv->link_info.tidtx_in4period[tid][idx];
Chaoming_Liacd48572011-04-25 12:52:54 -05001929 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1930 if (aver_tidtx_inperiod[tid] > 5000)
1931 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001932 true;
Larry Finger0c817332010-12-08 11:12:31 -06001933 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001934 rtlpriv->link_info.higher_busytxtraffic[tid] =
Larry Finger9afa2e42014-09-22 09:39:21 -05001935 false;
Larry Finger0c817332010-12-08 11:12:31 -06001936 }
1937
Ping-Ke Shih42213f22017-06-18 11:12:49 -05001938 /* PS is controlled by coex. */
1939 if (rtlpriv->cfg->ops->get_btc_status() &&
1940 rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv))
1941 goto label_lps_done;
1942
Larry Finger0c817332010-12-08 11:12:31 -06001943 if (((rtlpriv->link_info.num_rx_inperiod +
1944 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1945 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingerfd09ff92014-09-22 09:39:18 -05001946 rtl_lps_leave(hw);
wang yanqing873ffe12016-05-03 00:38:36 +08001947 else
1948 rtl_lps_enter(hw);
Ping-Ke Shih42213f22017-06-18 11:12:49 -05001949
1950label_lps_done:
1951 ;
Larry Finger0c817332010-12-08 11:12:31 -06001952 }
1953
1954 rtlpriv->link_info.num_rx_inperiod = 0;
1955 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001956 for (tid = 0; tid <= 7; tid++)
1957 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001958
Larry Finger7ea47242011-02-19 16:28:57 -06001959 rtlpriv->link_info.busytraffic = busytraffic;
1960 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001961 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1962 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001963 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001964
Chaoming_Liacd48572011-04-25 12:52:54 -05001965 /* <3> DM */
Larry Finger9afa2e42014-09-22 09:39:21 -05001966 if (!rtlpriv->cfg->mod_params->disable_watchdog)
1967 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001968
1969 /* <4> roaming */
1970 if (mac->link_state == MAC80211_LINKED &&
1971 mac->opmode == NL80211_IFTYPE_STATION) {
1972 if ((rtlpriv->link_info.bcn_rx_inperiod +
Larry Finger9afa2e42014-09-22 09:39:21 -05001973 rtlpriv->link_info.num_rx_inperiod) == 0) {
Larry Finger26634c42013-03-24 22:06:33 -05001974 rtlpriv->link_info.roam_times++;
1975 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1976 "AP off for %d s\n",
Larry Finger9afa2e42014-09-22 09:39:21 -05001977 (rtlpriv->link_info.roam_times * 2));
Larry Finger26634c42013-03-24 22:06:33 -05001978
Larry Finger9afa2e42014-09-22 09:39:21 -05001979 /* if we can't recv beacon for 10s,
1980 * we should reconnect this AP
Larry Finger26634c42013-03-24 22:06:33 -05001981 */
Larry Finger9afa2e42014-09-22 09:39:21 -05001982 if (rtlpriv->link_info.roam_times >= 5) {
Larry Fingerb03d9682016-12-15 12:22:58 -06001983 pr_err("AP off, try to reconnect now\n");
Larry Finger26634c42013-03-24 22:06:33 -05001984 rtlpriv->link_info.roam_times = 0;
Larry Finger9afa2e42014-09-22 09:39:21 -05001985 ieee80211_connection_loss(
1986 rtlpriv->mac80211.vif);
Larry Finger26634c42013-03-24 22:06:33 -05001987 }
1988 } else {
1989 rtlpriv->link_info.roam_times = 0;
1990 }
1991 }
Larry Finger9afa2e42014-09-22 09:39:21 -05001992
1993 if (rtlpriv->cfg->ops->get_btc_status())
1994 rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv);
1995
Ping-Ke Shih11f35c92017-07-02 13:12:30 -05001996 if (rtlpriv->btcoexist.btc_info.in_4way) {
1997 if (time_after(jiffies, rtlpriv->btcoexist.btc_info.in_4way_ts +
1998 msecs_to_jiffies(IN_4WAY_TIMEOUT_TIME)))
1999 rtlpriv->btcoexist.btc_info.in_4way = false;
2000 }
2001
Larry Finger26634c42013-03-24 22:06:33 -05002002 rtlpriv->link_info.bcn_rx_inperiod = 0;
Ping-Ke Shihc76ab8e2017-06-21 12:15:37 -05002003
2004 /* <6> scan list */
2005 rtl_scan_list_expire(hw);
Larry Finger0c817332010-12-08 11:12:31 -06002006}
2007
2008void rtl_watch_dog_timer_callback(unsigned long data)
2009{
2010 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
2011 struct rtl_priv *rtlpriv = rtl_priv(hw);
2012
2013 queue_delayed_work(rtlpriv->works.rtl_wq,
2014 &rtlpriv->works.watchdog_wq, 0);
2015
2016 mod_timer(&rtlpriv->works.watchdog_timer,
2017 jiffies + MSECS(RTL_WATCH_DOG_TIME));
2018}
Larry Finger26634c42013-03-24 22:06:33 -05002019void rtl_fwevt_wq_callback(void *data)
2020{
2021 struct rtl_works *rtlworks =
2022 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
2023 struct ieee80211_hw *hw = rtlworks->hw;
2024 struct rtl_priv *rtlpriv = rtl_priv(hw);
2025
2026 rtlpriv->cfg->ops->c2h_command_handle(hw);
2027}
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06002028
2029void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val)
2030{
2031 struct rtl_priv *rtlpriv = rtl_priv(hw);
2032 unsigned long flags;
2033 struct rtl_c2hcmd *c2hcmd;
2034
Larry Finger893dc682017-03-21 09:24:11 -05002035 c2hcmd = kmalloc(sizeof(*c2hcmd),
2036 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06002037
2038 if (!c2hcmd)
2039 goto label_err;
2040
Larry Finger893dc682017-03-21 09:24:11 -05002041 c2hcmd->val = kmalloc(len,
2042 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
Ping-Ke Shihcceb0a52017-02-06 21:30:08 -06002043
2044 if (!c2hcmd->val)
2045 goto label_err2;
2046
2047 /* fill data */
2048 c2hcmd->tag = tag;
2049 c2hcmd->len = len;
2050 memcpy(c2hcmd->val, val, len);
2051
2052 /* enqueue */
2053 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2054
2055 list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list);
2056
2057 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2058
2059 /* wake up wq */
2060 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0);
2061
2062 return;
2063
2064label_err2:
2065 kfree(c2hcmd);
2066
2067label_err:
2068 RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING,
2069 "C2H cmd enqueue fail.\n");
2070}
2071EXPORT_SYMBOL(rtl_c2hcmd_enqueue);
2072
2073void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec)
2074{
2075 struct rtl_priv *rtlpriv = rtl_priv(hw);
2076 unsigned long flags;
2077 struct rtl_c2hcmd *c2hcmd;
2078 int i;
2079
2080 for (i = 0; i < 200; i++) {
2081 /* dequeue a task */
2082 spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags);
2083
2084 c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list,
2085 struct rtl_c2hcmd, list);
2086
2087 if (c2hcmd)
2088 list_del(&c2hcmd->list);
2089
2090 spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags);
2091
2092 /* do it */
2093 if (!c2hcmd)
2094 break;
2095
2096 if (rtlpriv->cfg->ops->c2h_content_parsing && exec)
2097 rtlpriv->cfg->ops->c2h_content_parsing(hw,
2098 c2hcmd->tag, c2hcmd->len, c2hcmd->val);
2099
2100 /* free */
2101 kfree(c2hcmd->val);
2102
2103 kfree(c2hcmd);
2104 }
2105}
2106
2107void rtl_c2hcmd_wq_callback(void *data)
2108{
2109 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
2110 struct rtl_works,
2111 c2hcmd_wq);
2112 struct ieee80211_hw *hw = rtlworks->hw;
2113
2114 rtl_c2hcmd_launcher(hw, 1);
2115}
2116
Larry Finger26634c42013-03-24 22:06:33 -05002117void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
2118{
2119 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
2120 struct rtl_priv *rtlpriv = rtl_priv(hw);
2121 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
2122
2123 if (buddy_priv == NULL)
2124 return;
2125
2126 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
2127}
Larry Finger0c817332010-12-08 11:12:31 -06002128/*********************************************************
2129 *
Chaoming_Liacd48572011-04-25 12:52:54 -05002130 * frame process functions
2131 *
2132 *********************************************************/
2133u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
2134{
2135 struct ieee80211_mgmt *mgmt = (void *)data;
2136 u8 *pos, *end;
2137
2138 pos = (u8 *)mgmt->u.beacon.variable;
2139 end = data + len;
2140 while (pos < end) {
2141 if (pos + 2 + pos[1] > end)
2142 return NULL;
2143
2144 if (pos[0] == ie)
2145 return pos;
2146
2147 pos += 2 + pos[1];
2148 }
2149 return NULL;
2150}
2151
2152/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
2153/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05002154static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002155 enum ieee80211_smps_mode smps,
2156 u8 *da, u8 *bssid)
Chaoming_Liacd48572011-04-25 12:52:54 -05002157{
2158 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2159 struct sk_buff *skb;
2160 struct ieee80211_mgmt *action_frame;
2161
2162 /* 27 = header + category + action + smps mode */
2163 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
2164 if (!skb)
2165 return NULL;
2166
2167 skb_reserve(skb, hw->extra_tx_headroom);
Johannes Bergb080db52017-06-16 14:29:19 +02002168 action_frame = skb_put_zero(skb, 27);
Chaoming_Liacd48572011-04-25 12:52:54 -05002169 memcpy(action_frame->da, da, ETH_ALEN);
2170 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
2171 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2172 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2173 IEEE80211_STYPE_ACTION);
2174 action_frame->u.action.category = WLAN_CATEGORY_HT;
2175 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
2176 switch (smps) {
2177 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
2178 case IEEE80211_SMPS_NUM_MODES:/* 4 */
2179 WARN_ON(1);
Larry Finger9afa2e42014-09-22 09:39:21 -05002180 /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it.
2181 * According to Kernel Code, here is right.
2182 */
Chaoming_Liacd48572011-04-25 12:52:54 -05002183 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
2184 action_frame->u.action.u.ht_smps.smps_control =
2185 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
2186 break;
2187 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
2188 action_frame->u.action.u.ht_smps.smps_control =
2189 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
2190 break;
2191 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
2192 action_frame->u.action.u.ht_smps.smps_control =
2193 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
2194 break;
2195 }
2196
2197 return skb;
2198}
2199
2200int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002201 struct ieee80211_sta *sta,
2202 enum ieee80211_smps_mode smps)
Chaoming_Liacd48572011-04-25 12:52:54 -05002203{
2204 struct rtl_priv *rtlpriv = rtl_priv(hw);
2205 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2206 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05002207 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05002208 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05002209 u8 bssid[ETH_ALEN] = {0};
2210
Chaoming_Liacd48572011-04-25 12:52:54 -05002211 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
2212
2213 if (rtlpriv->mac80211.act_scanning)
2214 goto err_free;
2215
2216 if (!sta)
2217 goto err_free;
2218
2219 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
2220 goto err_free;
2221
2222 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
2223 goto err_free;
2224
Larry Finger26634c42013-03-24 22:06:33 -05002225 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
2226 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
2227 else
2228 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
2229
2230 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05002231 /* this is a type = mgmt * stype = action frame */
2232 if (skb) {
2233 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2234 struct rtl_sta_info *sta_entry =
2235 (struct rtl_sta_info *) sta->drv_priv;
2236 sta_entry->mimo_ps = smps;
Larry Finger9afa2e42014-09-22 09:39:21 -05002237 /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */
Chaoming_Liacd48572011-04-25 12:52:54 -05002238
2239 info->control.rates[0].idx = 0;
Karl Beldan675a0b02013-03-25 16:26:57 +01002240 info->band = hw->conf.chandef.chan->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02002241 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05002242 }
Larry Finger26634c42013-03-24 22:06:33 -05002243 return 1;
2244
Chaoming_Liacd48572011-04-25 12:52:54 -05002245err_free:
2246 return 0;
2247}
Larry Finger26634c42013-03-24 22:06:33 -05002248EXPORT_SYMBOL(rtl_send_smps_action);
2249
Larry Finger4f4826d2013-09-26 13:25:27 -05002250void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation)
2251{
2252 struct rtl_priv *rtlpriv = rtl_priv(hw);
2253 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
2254 enum io_type iotype;
2255
2256 if (!is_hal_stop(rtlhal)) {
2257 switch (operation) {
2258 case SCAN_OPT_BACKUP:
2259 iotype = IO_CMD_PAUSE_DM_BY_SCAN;
2260 rtlpriv->cfg->ops->set_hw_reg(hw,
2261 HW_VAR_IO_CMD,
2262 (u8 *)&iotype);
2263 break;
2264 case SCAN_OPT_RESTORE:
2265 iotype = IO_CMD_RESUME_DM_BY_SCAN;
2266 rtlpriv->cfg->ops->set_hw_reg(hw,
2267 HW_VAR_IO_CMD,
2268 (u8 *)&iotype);
2269 break;
2270 default:
Larry Fingerb03d9682016-12-15 12:22:58 -06002271 pr_err("Unknown Scan Backup operation.\n");
Larry Finger4f4826d2013-09-26 13:25:27 -05002272 break;
2273 }
2274 }
2275}
2276EXPORT_SYMBOL(rtl_phy_scan_operation_backup);
2277
Larry Finger9afa2e42014-09-22 09:39:21 -05002278/* because mac80211 have issues when can receive del ba
2279 * so here we just make a fake del_ba if we receive a ba_req
2280 * but rx_agg was opened to let mac80211 release some ba
2281 * related resources, so please this del_ba for tx
Larry Finger26634c42013-03-24 22:06:33 -05002282 */
2283struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
2284 u8 *sa, u8 *bssid, u16 tid)
2285{
2286 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2287 struct sk_buff *skb;
2288 struct ieee80211_mgmt *action_frame;
2289 u16 params;
2290
2291 /* 27 = header + category + action + smps mode */
2292 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
2293 if (!skb)
2294 return NULL;
2295
2296 skb_reserve(skb, hw->extra_tx_headroom);
Johannes Bergb080db52017-06-16 14:29:19 +02002297 action_frame = skb_put_zero(skb, 34);
Larry Finger26634c42013-03-24 22:06:33 -05002298 memcpy(action_frame->sa, sa, ETH_ALEN);
2299 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
2300 memcpy(action_frame->bssid, bssid, ETH_ALEN);
2301 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2302 IEEE80211_STYPE_ACTION);
2303 action_frame->u.action.category = WLAN_CATEGORY_BACK;
2304 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
2305 params = (u16)(1 << 11); /* bit 11 initiator */
Larry Finger9afa2e42014-09-22 09:39:21 -05002306 params |= (u16)(tid << 12); /* bit 15:12 TID number */
Larry Finger26634c42013-03-24 22:06:33 -05002307
2308 action_frame->u.action.u.delba.params = cpu_to_le16(params);
2309 action_frame->u.action.u.delba.reason_code =
2310 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
2311
2312 return skb;
2313}
Chaoming_Liacd48572011-04-25 12:52:54 -05002314
2315/*********************************************************
2316 *
2317 * IOT functions
2318 *
2319 *********************************************************/
2320static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
Larry Finger9afa2e42014-09-22 09:39:21 -05002321 struct octet_string vendor_ie)
Chaoming_Liacd48572011-04-25 12:52:54 -05002322{
2323 struct rtl_priv *rtlpriv = rtl_priv(hw);
2324 bool matched = false;
2325 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
2326 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
2327 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
2328 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
2329 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
2330 static u8 racap[] = { 0x00, 0x0c, 0x43 };
2331 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
2332 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
2333
2334 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
2335 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
2336 rtlpriv->mac80211.vendor = PEER_ATH;
2337 matched = true;
2338 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
2339 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
2340 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
2341 rtlpriv->mac80211.vendor = PEER_BROAD;
2342 matched = true;
2343 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
2344 rtlpriv->mac80211.vendor = PEER_RAL;
2345 matched = true;
2346 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
2347 rtlpriv->mac80211.vendor = PEER_CISCO;
2348 matched = true;
2349 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
2350 rtlpriv->mac80211.vendor = PEER_MARV;
2351 matched = true;
2352 }
2353
2354 return matched;
2355}
2356
Larry Fingerd3bb1422011-04-25 13:23:20 -05002357static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05002358 unsigned int len)
2359{
2360 struct ieee80211_mgmt *mgmt = (void *)data;
2361 struct octet_string vendor_ie;
2362 u8 *pos, *end;
2363
2364 pos = (u8 *)mgmt->u.beacon.variable;
2365 end = data + len;
2366 while (pos < end) {
2367 if (pos[0] == 221) {
2368 vendor_ie.length = pos[1];
2369 vendor_ie.octet = &pos[2];
2370 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
2371 return true;
2372 }
2373
2374 if (pos + 2 + pos[1] > end)
2375 return false;
2376
2377 pos += 2 + pos[1];
2378 }
2379 return false;
2380}
2381
2382void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
2383{
2384 struct rtl_priv *rtlpriv = rtl_priv(hw);
2385 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2386 struct ieee80211_hdr *hdr = (void *)data;
2387 u32 vendor = PEER_UNKNOWN;
2388
2389 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
2390 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
2391 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
2392 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
2393 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
2394 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
2395 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
2396 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
2397 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
2398 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
2399 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
2400 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
2401 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
2402 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
2403 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
2404 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
2405
2406 if (mac->opmode != NL80211_IFTYPE_STATION)
2407 return;
2408
2409 if (mac->link_state == MAC80211_NOLINK) {
2410 mac->vendor = PEER_UNKNOWN;
2411 return;
2412 }
2413
2414 if (mac->cnt_after_linked > 2)
2415 return;
2416
2417 /* check if this really is a beacon */
2418 if (!ieee80211_is_beacon(hdr->frame_control))
2419 return;
2420
2421 /* min. beacon length + FCS_LEN */
2422 if (len <= 40 + FCS_LEN)
2423 return;
2424
2425 /* and only beacons from the associated BSSID, please */
Julia Lawall90908e12013-12-30 19:15:02 +01002426 if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05002427 return;
2428
2429 if (rtl_find_221_ie(hw, data, len))
2430 vendor = mac->vendor;
2431
2432 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
2433 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
2434 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
2435 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
2436 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
2437 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
2438 vendor == PEER_ATH) {
2439 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08002440 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002441 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
2442 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
2443 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
2444 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
2445 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
2446 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002447 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002448 vendor = PEER_RAL;
2449 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
2450 vendor == PEER_CISCO) {
2451 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08002452 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002453 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
2454 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
2455 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
2456 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08002457 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002458 vendor = PEER_BROAD;
2459 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
2460 vendor == PEER_MARV) {
2461 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08002462 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002463 }
2464
2465 mac->vendor = vendor;
2466}
Larry Finger6f334c22013-07-12 15:32:15 -05002467EXPORT_SYMBOL_GPL(rtl_recognize_peer);
Chaoming_Liacd48572011-04-25 12:52:54 -05002468
Larry Finger0c817332010-12-08 11:12:31 -06002469MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2470MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2471MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
2472MODULE_LICENSE("GPL");
2473MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2474
Larry Finger6f334c22013-07-12 15:32:15 -05002475struct rtl_global_var rtl_global_var = {};
2476EXPORT_SYMBOL_GPL(rtl_global_var);
Larry Finger26634c42013-03-24 22:06:33 -05002477
Larry Finger0c817332010-12-08 11:12:31 -06002478static int __init rtl_core_module_init(void)
2479{
Chaoming Li375ff4c2011-02-28 16:40:28 -06002480 if (rtl_rate_control_register())
Larry Finger9afa2e42014-09-22 09:39:21 -05002481 pr_err("rtl: Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05002482
Larry Finger26634c42013-03-24 22:06:33 -05002483 /* init some global vars */
Larry Finger6f334c22013-07-12 15:32:15 -05002484 INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2485 spin_lock_init(&rtl_global_var.glb_list_lock);
Larry Finger26634c42013-03-24 22:06:33 -05002486
Larry Finger0c817332010-12-08 11:12:31 -06002487 return 0;
2488}
2489
2490static void __exit rtl_core_module_exit(void)
2491{
Chaoming_Liacd48572011-04-25 12:52:54 -05002492 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06002493 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06002494}
2495
2496module_init(rtl_core_module_init);
2497module_exit(rtl_core_module_exit);