blob: f8a2d9f28e468f00a67ad51c7eeb57d5335bd80e [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 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
Larry Finger0c817332010-12-08 11:12:31 -060030#include "wifi.h"
31#include "rc.h"
32#include "base.h"
33#include "efuse.h"
34#include "cam.h"
35#include "ps.h"
36#include "regd.h"
37
Larry Fingerd273bb22012-01-27 13:59:25 -060038#include <linux/ip.h>
39#include <linux/module.h>
40
Larry Finger0c817332010-12-08 11:12:31 -060041/*
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010042 *NOTICE!!!: This file will be very big, we should
43 *keep it clear under following roles:
Larry Finger0c817332010-12-08 11:12:31 -060044 *
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010045 *This file include following parts, so, if you add new
Larry Finger0c817332010-12-08 11:12:31 -060046 *functions into this file, please check which part it
47 *should includes. or check if you should add new part
48 *for this file:
49 *
50 *1) mac80211 init functions
51 *2) tx information functions
52 *3) functions called by core.c
53 *4) wq & timer callback functions
54 *5) frame process functions
Chaoming_Liacd48572011-04-25 12:52:54 -050055 *6) IOT functions
56 *7) sysfs functions
Larry Finger26634c42013-03-24 22:06:33 -050057 *8) vif functions
58 *9) ...
Larry Finger0c817332010-12-08 11:12:31 -060059 */
60
61/*********************************************************
62 *
63 * mac80211 init functions
64 *
65 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -050066static struct ieee80211_channel rtl_channeltable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -060067 {.center_freq = 2412, .hw_value = 1,},
68 {.center_freq = 2417, .hw_value = 2,},
69 {.center_freq = 2422, .hw_value = 3,},
70 {.center_freq = 2427, .hw_value = 4,},
71 {.center_freq = 2432, .hw_value = 5,},
72 {.center_freq = 2437, .hw_value = 6,},
73 {.center_freq = 2442, .hw_value = 7,},
74 {.center_freq = 2447, .hw_value = 8,},
75 {.center_freq = 2452, .hw_value = 9,},
76 {.center_freq = 2457, .hw_value = 10,},
77 {.center_freq = 2462, .hw_value = 11,},
78 {.center_freq = 2467, .hw_value = 12,},
79 {.center_freq = 2472, .hw_value = 13,},
80 {.center_freq = 2484, .hw_value = 14,},
81};
82
Chaoming_Liacd48572011-04-25 12:52:54 -050083static struct ieee80211_channel rtl_channeltable_5g[] = {
84 {.center_freq = 5180, .hw_value = 36,},
85 {.center_freq = 5200, .hw_value = 40,},
86 {.center_freq = 5220, .hw_value = 44,},
87 {.center_freq = 5240, .hw_value = 48,},
88 {.center_freq = 5260, .hw_value = 52,},
89 {.center_freq = 5280, .hw_value = 56,},
90 {.center_freq = 5300, .hw_value = 60,},
91 {.center_freq = 5320, .hw_value = 64,},
92 {.center_freq = 5500, .hw_value = 100,},
93 {.center_freq = 5520, .hw_value = 104,},
94 {.center_freq = 5540, .hw_value = 108,},
95 {.center_freq = 5560, .hw_value = 112,},
96 {.center_freq = 5580, .hw_value = 116,},
97 {.center_freq = 5600, .hw_value = 120,},
98 {.center_freq = 5620, .hw_value = 124,},
99 {.center_freq = 5640, .hw_value = 128,},
100 {.center_freq = 5660, .hw_value = 132,},
101 {.center_freq = 5680, .hw_value = 136,},
102 {.center_freq = 5700, .hw_value = 140,},
103 {.center_freq = 5745, .hw_value = 149,},
104 {.center_freq = 5765, .hw_value = 153,},
105 {.center_freq = 5785, .hw_value = 157,},
106 {.center_freq = 5805, .hw_value = 161,},
107 {.center_freq = 5825, .hw_value = 165,},
108};
109
110static struct ieee80211_rate rtl_ratetable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -0600111 {.bitrate = 10, .hw_value = 0x00,},
112 {.bitrate = 20, .hw_value = 0x01,},
113 {.bitrate = 55, .hw_value = 0x02,},
114 {.bitrate = 110, .hw_value = 0x03,},
115 {.bitrate = 60, .hw_value = 0x04,},
116 {.bitrate = 90, .hw_value = 0x05,},
117 {.bitrate = 120, .hw_value = 0x06,},
118 {.bitrate = 180, .hw_value = 0x07,},
119 {.bitrate = 240, .hw_value = 0x08,},
120 {.bitrate = 360, .hw_value = 0x09,},
121 {.bitrate = 480, .hw_value = 0x0a,},
122 {.bitrate = 540, .hw_value = 0x0b,},
123};
124
Chaoming_Liacd48572011-04-25 12:52:54 -0500125static struct ieee80211_rate rtl_ratetable_5g[] = {
126 {.bitrate = 60, .hw_value = 0x04,},
127 {.bitrate = 90, .hw_value = 0x05,},
128 {.bitrate = 120, .hw_value = 0x06,},
129 {.bitrate = 180, .hw_value = 0x07,},
130 {.bitrate = 240, .hw_value = 0x08,},
131 {.bitrate = 360, .hw_value = 0x09,},
132 {.bitrate = 480, .hw_value = 0x0a,},
133 {.bitrate = 540, .hw_value = 0x0b,},
134};
135
Larry Finger0c817332010-12-08 11:12:31 -0600136static const struct ieee80211_supported_band rtl_band_2ghz = {
137 .band = IEEE80211_BAND_2GHZ,
138
Chaoming_Liacd48572011-04-25 12:52:54 -0500139 .channels = rtl_channeltable_2g,
140 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600141
Chaoming_Liacd48572011-04-25 12:52:54 -0500142 .bitrates = rtl_ratetable_2g,
143 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600144
145 .ht_cap = {0},
146};
147
Chaoming_Liacd48572011-04-25 12:52:54 -0500148static struct ieee80211_supported_band rtl_band_5ghz = {
149 .band = IEEE80211_BAND_5GHZ,
150
151 .channels = rtl_channeltable_5g,
152 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
153
154 .bitrates = rtl_ratetable_5g,
155 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
156
157 .ht_cap = {0},
158};
159
160static const u8 tid_to_ac[] = {
161 2, /* IEEE80211_AC_BE */
162 3, /* IEEE80211_AC_BK */
163 3, /* IEEE80211_AC_BK */
164 2, /* IEEE80211_AC_BE */
165 1, /* IEEE80211_AC_VI */
166 1, /* IEEE80211_AC_VI */
167 0, /* IEEE80211_AC_VO */
168 0, /* IEEE80211_AC_VO */
169};
170
Larry Finger2a00def2012-07-11 14:32:33 -0500171u8 rtl_tid_to_ac(u8 tid)
Chaoming_Liacd48572011-04-25 12:52:54 -0500172{
173 return tid_to_ac[tid];
174}
175
Larry Finger0c817332010-12-08 11:12:31 -0600176static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
177 struct ieee80211_sta_ht_cap *ht_cap)
178{
179 struct rtl_priv *rtlpriv = rtl_priv(hw);
180 struct rtl_phy *rtlphy = &(rtlpriv->phy);
181
182 ht_cap->ht_supported = true;
183 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
184 IEEE80211_HT_CAP_SGI_40 |
185 IEEE80211_HT_CAP_SGI_20 |
186 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
187
Chaoming_Liacd48572011-04-25 12:52:54 -0500188 if (rtlpriv->rtlhal.disable_amsdu_8k)
189 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
190
Larry Finger0c817332010-12-08 11:12:31 -0600191 /*
192 *Maximum length of AMPDU that the STA can receive.
193 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
194 */
195 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
196
197 /*Minimum MPDU start spacing , */
198 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
199
200 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
201
Larry Finger26634c42013-03-24 22:06:33 -0500202 /*hw->wiphy->bands[IEEE80211_BAND_2GHZ]
Larry Finger0c817332010-12-08 11:12:31 -0600203 *base on ant_num
204 *rx_mask: RX mask
Larry Finger26634c42013-03-24 22:06:33 -0500205 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
206 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
207 *if rx_ant >= 3 rx_mask[2]= 0xff;
208 *if BW_40 rx_mask[4]= 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600209 *highest supported RX rate
210 */
Larry Finger26634c42013-03-24 22:06:33 -0500211 if (rtlpriv->dm.supp_phymode_switch) {
Larry Finger0c817332010-12-08 11:12:31 -0600212
Larry Finger26634c42013-03-24 22:06:33 -0500213 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
214 "Support phy mode switch\n");
Larry Finger0c817332010-12-08 11:12:31 -0600215
216 ht_cap->mcs.rx_mask[0] = 0xFF;
217 ht_cap->mcs.rx_mask[1] = 0xFF;
218 ht_cap->mcs.rx_mask[4] = 0x01;
219
Larry Finger17c9ac62011-02-19 16:29:57 -0600220 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
Larry Finger26634c42013-03-24 22:06:33 -0500221 } else {
222 if (get_rf_type(rtlphy) == RF_1T2R ||
223 get_rf_type(rtlphy) == RF_2T2R) {
224 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
225 "1T2R or 2T2R\n");
226 ht_cap->mcs.rx_mask[0] = 0xFF;
227 ht_cap->mcs.rx_mask[1] = 0xFF;
228 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600229
Larry Finger26634c42013-03-24 22:06:33 -0500230 ht_cap->mcs.rx_highest =
231 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
232 } else if (get_rf_type(rtlphy) == RF_1T1R) {
233 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
Larry Finger0c817332010-12-08 11:12:31 -0600234
Larry Finger26634c42013-03-24 22:06:33 -0500235 ht_cap->mcs.rx_mask[0] = 0xFF;
236 ht_cap->mcs.rx_mask[1] = 0x00;
237 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600238
Larry Finger26634c42013-03-24 22:06:33 -0500239 ht_cap->mcs.rx_highest =
240 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
241 }
Larry Finger0c817332010-12-08 11:12:31 -0600242 }
243}
244
245static void _rtl_init_mac80211(struct ieee80211_hw *hw)
246{
Chaoming_Liacd48572011-04-25 12:52:54 -0500247 struct rtl_priv *rtlpriv = rtl_priv(hw);
248 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600249 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
250 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
251 struct ieee80211_supported_band *sband;
252
Larry Finger0c817332010-12-08 11:12:31 -0600253
Chaoming_Liacd48572011-04-25 12:52:54 -0500254 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
255 BAND_ON_BOTH) {
256 /* 1: 2.4 G bands */
257 /* <1> use mac->bands as mem for hw->wiphy->bands */
258 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600259
Chaoming_Liacd48572011-04-25 12:52:54 -0500260 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
261 * to default value(1T1R) */
262 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
263 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600264
Chaoming_Liacd48572011-04-25 12:52:54 -0500265 /* <3> init ht cap base on ant_num */
266 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600267
Chaoming_Liacd48572011-04-25 12:52:54 -0500268 /* <4> set mac->sband to wiphy->sband */
269 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
270
271 /* 2: 5 G bands */
272 /* <1> use mac->bands as mem for hw->wiphy->bands */
273 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
274
275 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
276 * to default value(1T1R) */
277 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
278 sizeof(struct ieee80211_supported_band));
279
280 /* <3> init ht cap base on ant_num */
281 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
282
283 /* <4> set mac->sband to wiphy->sband */
284 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
285 } else {
286 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
287 /* <1> use mac->bands as mem for hw->wiphy->bands */
288 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
289
290 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
291 * to default value(1T1R) */
292 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
293 &rtl_band_2ghz,
294 sizeof(struct ieee80211_supported_band));
295
296 /* <3> init ht cap base on ant_num */
297 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
298
299 /* <4> set mac->sband to wiphy->sband */
300 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
301 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
302 /* <1> use mac->bands as mem for hw->wiphy->bands */
303 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
304
305 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
306 * to default value(1T1R) */
307 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
308 &rtl_band_5ghz,
309 sizeof(struct ieee80211_supported_band));
310
311 /* <3> init ht cap base on ant_num */
312 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
313
314 /* <4> set mac->sband to wiphy->sband */
315 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
316 } else {
Joe Perchesf30d7502012-01-04 19:40:41 -0800317 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
318 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500319 }
320 }
Larry Finger0c817332010-12-08 11:12:31 -0600321 /* <5> set hw caps */
322 hw->flags = IEEE80211_HW_SIGNAL_DBM |
323 IEEE80211_HW_RX_INCLUDES_FCS |
Chaoming_Liacd48572011-04-25 12:52:54 -0500324 IEEE80211_HW_AMPDU_AGGREGATION |
Chaoming Li09e92f02011-10-11 21:28:48 -0500325 IEEE80211_HW_CONNECTION_MONITOR |
326 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
Larry Finger26634c42013-03-24 22:06:33 -0500327 IEEE80211_HW_CONNECTION_MONITOR |
328 IEEE80211_HW_MFP_CAPABLE |
Larry Finger0c817332010-12-08 11:12:31 -0600329 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
330
Chaoming_Liacd48572011-04-25 12:52:54 -0500331 /* swlps or hwlps has been set in diff chip in init_sw_vars */
332 if (rtlpriv->psc.swctrl_lps)
333 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
334 IEEE80211_HW_PS_NULLFUNC_STACK |
335 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
336 0;
337
Larry Finger0c817332010-12-08 11:12:31 -0600338 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500339 BIT(NL80211_IFTYPE_AP) |
340 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500341 BIT(NL80211_IFTYPE_ADHOC) |
342 BIT(NL80211_IFTYPE_MESH_POINT) |
343 BIT(NL80211_IFTYPE_P2P_CLIENT) |
344 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger0c817332010-12-08 11:12:31 -0600345
Larry Finger26634c42013-03-24 22:06:33 -0500346 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger0c817332010-12-08 11:12:31 -0600347 hw->wiphy->rts_threshold = 2347;
348
349 hw->queues = AC_MAX;
350 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
351
352 /* TODO: Correct this value for our hw */
353 /* TODO: define these hard code value */
354 hw->channel_change_time = 100;
Chaoming_Liacd48572011-04-25 12:52:54 -0500355 hw->max_listen_interval = 10;
Larry Finger0c817332010-12-08 11:12:31 -0600356 hw->max_rate_tries = 4;
357 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500358 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600359
360 /* <6> mac address */
361 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
362 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
363 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600364 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
365 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
366 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600367 }
368
369}
370
371static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
372{
373 struct rtl_priv *rtlpriv = rtl_priv(hw);
374
375 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600376 setup_timer(&rtlpriv->works.watchdog_timer,
377 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500378 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
379 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600380
381 /* <2> work queue */
382 rtlpriv->works.hw = hw;
John W. Linville3d986b22010-12-16 14:59:49 -0500383 rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
Larry Finger0c817332010-12-08 11:12:31 -0600384 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
385 (void *)rtl_watchdog_wq_callback);
386 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
387 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500388 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
389 (void *)rtl_swlps_wq_callback);
390 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
391 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500392 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
393 (void *)rtl_fwevt_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600394
395}
396
397void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
398{
399 struct rtl_priv *rtlpriv = rtl_priv(hw);
400
401 del_timer_sync(&rtlpriv->works.watchdog_timer);
402
403 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
404 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500405 cancel_delayed_work(&rtlpriv->works.ps_work);
406 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500407 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600408}
409
410void rtl_init_rfkill(struct ieee80211_hw *hw)
411{
412 struct rtl_priv *rtlpriv = rtl_priv(hw);
413
414 bool radio_state;
415 bool blocked;
416 u8 valid = 0;
417
Chaoming Li228bdfc2011-04-10 18:30:23 -0500418 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000419 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500420 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
421
Larry Finger0c817332010-12-08 11:12:31 -0600422 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
423
Larry Fingere6d8a812010-12-21 19:40:40 -0600424 if (valid) {
Joe Perches292b1192011-07-20 08:51:35 -0700425 pr_info("wireless switch is %s\n",
426 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500427
Larry Finger0c817332010-12-08 11:12:31 -0600428 rtlpriv->rfkill.rfkill_state = radio_state;
429
430 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
431 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
432 }
433
434 wiphy_rfkill_start_polling(hw->wiphy);
435}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600436EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600437
438void rtl_deinit_rfkill(struct ieee80211_hw *hw)
439{
440 wiphy_rfkill_stop_polling(hw->wiphy);
441}
442
443int rtl_init_core(struct ieee80211_hw *hw)
444{
445 struct rtl_priv *rtlpriv = rtl_priv(hw);
446 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
447
448 /* <1> init mac80211 */
449 _rtl_init_mac80211(hw);
450 rtlmac->hw = hw;
451
452 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600453 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600454
455 /*
456 * <3> init CRDA must come after init
457 * mac80211 hw in _rtl_init_mac80211.
458 */
459 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Joe Perchesf30d7502012-01-04 19:40:41 -0800460 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600461 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600462 }
463
464 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600465 mutex_init(&rtlpriv->locks.conf_mutex);
Stanislaw Gruszka65393062011-12-12 12:43:24 +0100466 mutex_init(&rtlpriv->locks.ps_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600467 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600468 spin_lock_init(&rtlpriv->locks.irq_th_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500469 spin_lock_init(&rtlpriv->locks.irq_pci_lock);
470 spin_lock_init(&rtlpriv->locks.tx_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600471 spin_lock_init(&rtlpriv->locks.h2c_lock);
472 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
473 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500474 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500475 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500476 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500477 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
478 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
479 spin_lock_init(&rtlpriv->locks.lps_lock);
480
481 /* <5> init list */
482 INIT_LIST_HEAD(&rtlpriv->entry_list);
Larry Finger0c817332010-12-08 11:12:31 -0600483
484 rtlmac->link_state = MAC80211_NOLINK;
485
Larry Finger26634c42013-03-24 22:06:33 -0500486 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600487 _rtl_init_deferred_work(hw);
488
489 return 0;
490}
491
492void rtl_deinit_core(struct ieee80211_hw *hw)
493{
Larry Finger0c817332010-12-08 11:12:31 -0600494}
495
496void rtl_init_rx_config(struct ieee80211_hw *hw)
497{
498 struct rtl_priv *rtlpriv = rtl_priv(hw);
499 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
500
501 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600502}
503
504/*********************************************************
505 *
506 * tx information functions
507 *
508 *********************************************************/
509static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
510 struct rtl_tcb_desc *tcb_desc,
511 struct ieee80211_tx_info *info)
512{
513 struct rtl_priv *rtlpriv = rtl_priv(hw);
514 u8 rate_flag = info->control.rates[0].flags;
515
516 tcb_desc->use_shortpreamble = false;
517
518 /* 1M can only use Long Preamble. 11B spec */
519 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
520 return;
521 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
522 tcb_desc->use_shortpreamble = true;
523
524 return;
525}
526
527static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500528 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600529 struct rtl_tcb_desc *tcb_desc,
530 struct ieee80211_tx_info *info)
531{
532 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
533 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500534 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600535 tcb_desc->use_shortgi = false;
536
Chaoming_Liacd48572011-04-25 12:52:54 -0500537 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600538 return;
539
Chaoming_Liacd48572011-04-25 12:52:54 -0500540 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
541 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
542
543 if (!(sta->ht_cap.ht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600544 return;
545
Chaoming_Liacd48572011-04-25 12:52:54 -0500546 if (!sgi_40 && !sgi_20)
547 return;
548
549 if (mac->opmode == NL80211_IFTYPE_STATION)
550 bw_40 = mac->bw_40;
551 else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500552 mac->opmode == NL80211_IFTYPE_ADHOC ||
553 mac->opmode == NL80211_IFTYPE_MESH_POINT)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100554 bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
Chaoming_Liacd48572011-04-25 12:52:54 -0500555
Mike McCormacke10542c2011-06-20 10:47:51 +0900556 if (bw_40 && sgi_40)
Larry Finger0c817332010-12-08 11:12:31 -0600557 tcb_desc->use_shortgi = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500558 else if ((bw_40 == false) && sgi_20)
Larry Finger0c817332010-12-08 11:12:31 -0600559 tcb_desc->use_shortgi = true;
560
561 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
562 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600563}
564
565static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
566 struct rtl_tcb_desc *tcb_desc,
567 struct ieee80211_tx_info *info)
568{
569 struct rtl_priv *rtlpriv = rtl_priv(hw);
570 u8 rate_flag = info->control.rates[0].flags;
571
572 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600573 tcb_desc->rts_stbc = false;
574 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600575 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600576 tcb_desc->rts_bw = false;
577 tcb_desc->rts_use_shortpreamble = false;
578 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600579
580 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
581 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600582 tcb_desc->rts_enable = true;
583 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600584 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
585 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
586 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600587 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600588 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
589 }
Larry Finger0c817332010-12-08 11:12:31 -0600590}
591
592static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500593 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600594 struct rtl_tcb_desc *tcb_desc)
595{
596 struct rtl_priv *rtlpriv = rtl_priv(hw);
597 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500598 struct rtl_sta_info *sta_entry = NULL;
599 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600600
Chaoming_Liacd48572011-04-25 12:52:54 -0500601 if (sta) {
602 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
603 ratr_index = sta_entry->ratr_index;
604 }
Larry Finger0c817332010-12-08 11:12:31 -0600605 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500606 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600607 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500608 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
609 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600610 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600611 tcb_desc->hw_rate =
612 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
613 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500614 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600615 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500616 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600617 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500618 } else if (mac->opmode == NL80211_IFTYPE_AP) {
619 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600620 }
621 }
622
Larry Finger7ea47242011-02-19 16:28:57 -0600623 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500624 tcb_desc->ratr_index = ratr_index;
625 /* TODO we will differentiate adhoc and station future */
626 if (mac->opmode == NL80211_IFTYPE_STATION ||
627 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500628 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600629
Chaoming_Liacd48572011-04-25 12:52:54 -0500630 if (mac->mode == WIRELESS_MODE_N_24G)
631 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
632 else if (mac->mode == WIRELESS_MODE_N_5G)
633 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
634 else if (mac->mode & WIRELESS_MODE_G)
635 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
636 else if (mac->mode & WIRELESS_MODE_B)
637 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
638 else if (mac->mode & WIRELESS_MODE_A)
639 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
640 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500641 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500642 if (NULL != sta) {
643 if (sta->aid > 0)
644 tcb_desc->mac_id = sta->aid + 1;
645 else
646 tcb_desc->mac_id = 1;
647 } else {
648 tcb_desc->mac_id = 0;
649 }
Larry Finger0c817332010-12-08 11:12:31 -0600650 }
651 }
Larry Finger0c817332010-12-08 11:12:31 -0600652}
653
654static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500655 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600656 struct rtl_tcb_desc *tcb_desc)
657{
658 struct rtl_priv *rtlpriv = rtl_priv(hw);
659 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
660
Larry Finger7ea47242011-02-19 16:28:57 -0600661 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500662 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600663 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500664 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500665 mac->opmode == NL80211_IFTYPE_ADHOC ||
666 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100667 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
Chaoming_Liacd48572011-04-25 12:52:54 -0500668 return;
669 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
670 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
671 return;
672 }
Larry Finger7ea47242011-02-19 16:28:57 -0600673 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600674 return;
675
676 /*use legency rate, shall use 20MHz */
677 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
678 return;
679
Larry Finger7ea47242011-02-19 16:28:57 -0600680 tcb_desc->packet_bw = true;
Larry Finger0c817332010-12-08 11:12:31 -0600681}
682
683static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
684{
685 struct rtl_priv *rtlpriv = rtl_priv(hw);
686 struct rtl_phy *rtlphy = &(rtlpriv->phy);
687 u8 hw_rate;
688
689 if (get_rf_type(rtlphy) == RF_2T2R)
690 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
691 else
692 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
693
694 return hw_rate;
695}
696
Larry Finger7ad0ce32011-08-22 16:50:14 -0500697/* mac80211's rate_idx is like this:
698 *
699 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
700 *
701 * B/G rate:
702 * (rx_status->flag & RX_FLAG_HT) = 0,
703 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
704 *
705 * N rate:
706 * (rx_status->flag & RX_FLAG_HT) = 1,
707 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
708 *
709 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
710 * A rate:
711 * (rx_status->flag & RX_FLAG_HT) = 0,
712 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
713 *
714 * N rate:
715 * (rx_status->flag & RX_FLAG_HT) = 1,
716 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
717 */
718int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
719 bool isht, u8 desc_rate, bool first_ampdu)
720{
721 int rate_idx;
722
723 if (false == isht) {
724 if (IEEE80211_BAND_2GHZ == hw->conf.channel->band) {
725 switch (desc_rate) {
726 case DESC92_RATE1M:
727 rate_idx = 0;
728 break;
729 case DESC92_RATE2M:
730 rate_idx = 1;
731 break;
732 case DESC92_RATE5_5M:
733 rate_idx = 2;
734 break;
735 case DESC92_RATE11M:
736 rate_idx = 3;
737 break;
738 case DESC92_RATE6M:
739 rate_idx = 4;
740 break;
741 case DESC92_RATE9M:
742 rate_idx = 5;
743 break;
744 case DESC92_RATE12M:
745 rate_idx = 6;
746 break;
747 case DESC92_RATE18M:
748 rate_idx = 7;
749 break;
750 case DESC92_RATE24M:
751 rate_idx = 8;
752 break;
753 case DESC92_RATE36M:
754 rate_idx = 9;
755 break;
756 case DESC92_RATE48M:
757 rate_idx = 10;
758 break;
759 case DESC92_RATE54M:
760 rate_idx = 11;
761 break;
762 default:
763 rate_idx = 0;
764 break;
765 }
766 } else {
767 switch (desc_rate) {
768 case DESC92_RATE6M:
769 rate_idx = 0;
770 break;
771 case DESC92_RATE9M:
772 rate_idx = 1;
773 break;
774 case DESC92_RATE12M:
775 rate_idx = 2;
776 break;
777 case DESC92_RATE18M:
778 rate_idx = 3;
779 break;
780 case DESC92_RATE24M:
781 rate_idx = 4;
782 break;
783 case DESC92_RATE36M:
784 rate_idx = 5;
785 break;
786 case DESC92_RATE48M:
787 rate_idx = 6;
788 break;
789 case DESC92_RATE54M:
790 rate_idx = 7;
791 break;
792 default:
793 rate_idx = 0;
794 break;
795 }
796 }
797
798 } else {
799
800 switch (desc_rate) {
801 case DESC92_RATEMCS0:
802 rate_idx = 0;
803 break;
804 case DESC92_RATEMCS1:
805 rate_idx = 1;
806 break;
807 case DESC92_RATEMCS2:
808 rate_idx = 2;
809 break;
810 case DESC92_RATEMCS3:
811 rate_idx = 3;
812 break;
813 case DESC92_RATEMCS4:
814 rate_idx = 4;
815 break;
816 case DESC92_RATEMCS5:
817 rate_idx = 5;
818 break;
819 case DESC92_RATEMCS6:
820 rate_idx = 6;
821 break;
822 case DESC92_RATEMCS7:
823 rate_idx = 7;
824 break;
825 case DESC92_RATEMCS8:
826 rate_idx = 8;
827 break;
828 case DESC92_RATEMCS9:
829 rate_idx = 9;
830 break;
831 case DESC92_RATEMCS10:
832 rate_idx = 10;
833 break;
834 case DESC92_RATEMCS11:
835 rate_idx = 11;
836 break;
837 case DESC92_RATEMCS12:
838 rate_idx = 12;
839 break;
840 case DESC92_RATEMCS13:
841 rate_idx = 13;
842 break;
843 case DESC92_RATEMCS14:
844 rate_idx = 14;
845 break;
846 case DESC92_RATEMCS15:
847 rate_idx = 15;
848 break;
849 default:
850 rate_idx = 0;
851 break;
852 }
853 }
854 return rate_idx;
855}
856EXPORT_SYMBOL(rtlwifi_rate_mapping);
857
Larry Finger0f015452012-10-25 13:46:46 -0500858bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
859{
860 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
861 struct rtl_priv *rtlpriv = rtl_priv(hw);
862 __le16 fc = rtl_get_fc(skb);
863
864 if (rtlpriv->dm.supp_phymode_switch &&
865 mac->link_state < MAC80211_LINKED &&
866 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
Larry Finger26634c42013-03-24 22:06:33 -0500867 if (rtlpriv->cfg->ops->chk_switch_dmdp)
868 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
Larry Finger0f015452012-10-25 13:46:46 -0500869 }
870 if (ieee80211_is_auth(fc)) {
871 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
872 rtl_ips_nic_on(hw);
873
874 mac->link_state = MAC80211_LINKING;
875 /* Dual mac */
876 rtlpriv->phy.need_iqk = true;
877 }
878
879 return true;
880}
881
Larry Finger0c817332010-12-08 11:12:31 -0600882void rtl_get_tcb_desc(struct ieee80211_hw *hw,
883 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -0500884 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600885 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
886{
887 struct rtl_priv *rtlpriv = rtl_priv(hw);
888 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500889 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -0600890 struct ieee80211_rate *txrate;
Larry Finger17c9ac62011-02-19 16:29:57 -0600891 __le16 fc = hdr->frame_control;
Larry Finger0c817332010-12-08 11:12:31 -0600892
Chaoming_Liacd48572011-04-25 12:52:54 -0500893 txrate = ieee80211_get_tx_rate(hw, info);
Larry Fingere89f7692012-04-06 16:54:17 -0500894 if (txrate)
895 tcb_desc->hw_rate = txrate->hw_value;
896 else
897 tcb_desc->hw_rate = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600898
899 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600900 /*
Chaoming_Liacd48572011-04-25 12:52:54 -0500901 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -0600902 *in rtl_rc.c if skb is special data or
903 *mgt which need low data rate.
904 */
905
906 /*
907 *So tcb_desc->hw_rate is just used for
908 *special data and mgt frames
909 */
Chaoming Li09e92f02011-10-11 21:28:48 -0500910 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -0500911 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600912 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500913 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600914
Larry Finger0c817332010-12-08 11:12:31 -0600915 tcb_desc->disable_ratefallback = 1;
916 } else {
917 /*
918 *because hw will nerver use hw_rate
919 *when tcb_desc->use_driver_rate = false
920 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300921 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -0600922 *when tcb_desc->use_driver_rate = false
923 */
Chaoming_Liacd48572011-04-25 12:52:54 -0500924 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -0600925 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
926 } else {
927 if (rtlmac->mode == WIRELESS_MODE_B) {
928 tcb_desc->hw_rate =
929 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
930 } else {
931 tcb_desc->hw_rate =
932 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
933 }
934 }
935 }
936
937 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600938 tcb_desc->multicast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600939 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600940 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600941
Chaoming_Liacd48572011-04-25 12:52:54 -0500942 _rtl_txrate_selectmode(hw, sta, tcb_desc);
943 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600944 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -0500945 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -0600946 _rtl_query_protection_mode(hw, tcb_desc, info);
947 } else {
948 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500949 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600950 tcb_desc->disable_ratefallback = 1;
951 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -0500952 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -0600953 }
954}
955EXPORT_SYMBOL(rtl_get_tcb_desc);
956
Larry Finger26634c42013-03-24 22:06:33 -0500957static bool addbareq_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
958{
959 struct rtl_priv *rtlpriv = rtl_priv(hw);
960 struct ieee80211_sta *sta = NULL;
961 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
962 struct rtl_sta_info *sta_entry = NULL;
963 struct ieee80211_mgmt *mgmt = (void *)skb->data;
964 u16 capab = 0, tid = 0;
965 struct rtl_tid_data *tid_data;
966 struct sk_buff *skb_delba = NULL;
967 struct ieee80211_rx_status rx_status = { 0 };
968
969 rcu_read_lock();
970 sta = rtl_find_sta(hw, hdr->addr3);
971 if (sta == NULL) {
972 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_EMERG,
973 "sta is NULL\n");
974 rcu_read_unlock();
975 return true;
976 }
977
978 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
979 if (!sta_entry) {
980 rcu_read_unlock();
981 return true;
982 }
983 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
984 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
985 tid_data = &sta_entry->tids[tid];
986 if (tid_data->agg.rx_agg_state == RTL_RX_AGG_START) {
987 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
988 if (skb_delba) {
989 rx_status.freq = hw->conf.channel->center_freq;
990 rx_status.band = hw->conf.channel->band;
991 rx_status.flag |= RX_FLAG_DECRYPTED;
992 rx_status.flag |= RX_FLAG_MACTIME_END;
993 rx_status.rate_idx = 0;
994 rx_status.signal = 50 + 10;
995 memcpy(IEEE80211_SKB_RXCB(skb_delba), &rx_status,
996 sizeof(rx_status));
997 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
998 "fake del\n", skb_delba->data,
999 skb_delba->len);
1000 ieee80211_rx_irqsafe(hw, skb_delba);
1001 }
1002 }
1003 rcu_read_unlock();
1004 return false;
1005}
1006
Larry Finger0c817332010-12-08 11:12:31 -06001007bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1008{
1009 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001010 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001011 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger17c9ac62011-02-19 16:29:57 -06001012 __le16 fc = hdr->frame_control;
Joe Perches2c208892012-06-04 12:44:17 +00001013 u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN;
Larry Finger0c817332010-12-08 11:12:31 -06001014 u8 category;
1015
1016 if (!ieee80211_is_action(fc))
1017 return true;
1018
1019 category = *act;
1020 act++;
1021 switch (category) {
1022 case ACT_CAT_BA:
1023 switch (*act) {
1024 case ACT_ADDBAREQ:
1025 if (mac->act_scanning)
1026 return false;
1027
1028 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001029 "%s ACT_ADDBAREQ From :%pM\n",
1030 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001031 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1032 skb->data, skb->len);
1033 if (!is_tx)
1034 if (addbareq_rx(hw, skb))
1035 return true;
Larry Finger0c817332010-12-08 11:12:31 -06001036 break;
1037 case ACT_ADDBARSP:
1038 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001039 "%s ACT_ADDBARSP From :%pM\n",
1040 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001041 break;
1042 case ACT_DELBA:
1043 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001044 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001045 break;
1046 }
1047 break;
1048 default:
1049 break;
1050 }
1051
1052 return true;
1053}
1054
1055/*should call before software enc*/
1056u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1057{
1058 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001059 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001060 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001061 u16 ether_type;
1062 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1063 const struct iphdr *ip;
1064
1065 if (!ieee80211_is_data(fc))
Larry Finger32473282011-03-27 16:19:57 -05001066 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001067
Larry Finger0c817332010-12-08 11:12:31 -06001068
1069 ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
1070 SNAP_SIZE + PROTOC_TYPE_SIZE);
1071 ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
Larry Fingerd3bb1422011-04-25 13:23:20 -05001072 /* ether_type = ntohs(ether_type); */
Larry Finger0c817332010-12-08 11:12:31 -06001073
1074 if (ETH_P_IP == ether_type) {
1075 if (IPPROTO_UDP == ip->protocol) {
1076 struct udphdr *udp = (struct udphdr *)((u8 *) ip +
1077 (ip->ihl << 2));
1078 if (((((u8 *) udp)[1] == 68) &&
1079 (((u8 *) udp)[3] == 67)) ||
1080 ((((u8 *) udp)[1] == 67) &&
1081 (((u8 *) udp)[3] == 68))) {
1082 /*
1083 * 68 : UDP BOOTP client
1084 * 67 : UDP BOOTP server
1085 */
1086 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV),
Joe Perchesf30d7502012-01-04 19:40:41 -08001087 DBG_DMESG, "dhcp %s !!\n",
1088 is_tx ? "Tx" : "Rx");
Larry Finger0c817332010-12-08 11:12:31 -06001089
1090 if (is_tx) {
Larry Fingera2699132013-03-24 22:06:41 -05001091 rtlpriv->enter_ps = false;
Larry Fingera5ffbe02013-02-02 15:55:00 -06001092 schedule_work(&rtlpriv->
Larry Fingera2699132013-03-24 22:06:41 -05001093 works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001094 ppsc->last_delaylps_stamp_jiffies =
1095 jiffies;
1096 }
1097
1098 return true;
1099 }
1100 }
1101 } else if (ETH_P_ARP == ether_type) {
1102 if (is_tx) {
Larry Fingera2699132013-03-24 22:06:41 -05001103 rtlpriv->enter_ps = false;
1104 schedule_work(&rtlpriv->works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001105 ppsc->last_delaylps_stamp_jiffies = jiffies;
1106 }
1107
1108 return true;
1109 } else if (ETH_P_PAE == ether_type) {
1110 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001111 "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx");
Larry Finger0c817332010-12-08 11:12:31 -06001112
1113 if (is_tx) {
Larry Fingera2699132013-03-24 22:06:41 -05001114 rtlpriv->enter_ps = false;
1115 schedule_work(&rtlpriv->works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001116 ppsc->last_delaylps_stamp_jiffies = jiffies;
1117 }
1118
1119 return true;
Larry Finger17c9ac62011-02-19 16:29:57 -06001120 } else if (ETH_P_IPV6 == ether_type) {
1121 /* IPv6 */
Larry Finger0c817332010-12-08 11:12:31 -06001122 return true;
1123 }
1124
Larry Finger0c817332010-12-08 11:12:31 -06001125 return false;
1126}
1127
1128/*********************************************************
1129 *
1130 * functions called by core.c
1131 *
1132 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -05001133int rtl_tx_agg_start(struct ieee80211_hw *hw,
1134 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001135{
1136 struct rtl_priv *rtlpriv = rtl_priv(hw);
1137 struct rtl_tid_data *tid_data;
1138 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001139 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001140
Chaoming_Liacd48572011-04-25 12:52:54 -05001141 if (sta == NULL)
1142 return -EINVAL;
Larry Finger0c817332010-12-08 11:12:31 -06001143
1144 if (unlikely(tid >= MAX_TID_COUNT))
1145 return -EINVAL;
1146
Chaoming_Liacd48572011-04-25 12:52:54 -05001147 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1148 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001149 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001150 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001151
Joe Perchesf30d7502012-01-04 19:40:41 -08001152 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n",
1153 sta->addr, tid, tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001154
Chaoming_Liacd48572011-04-25 12:52:54 -05001155 *ssn = tid_data->seq_number;
1156 tid_data->agg.agg_state = RTL_AGG_START;
1157
1158 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001159
1160 return 0;
1161}
1162
Chaoming_Liacd48572011-04-25 12:52:54 -05001163int rtl_tx_agg_stop(struct ieee80211_hw *hw,
1164 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001165{
Larry Finger0c817332010-12-08 11:12:31 -06001166 struct rtl_priv *rtlpriv = rtl_priv(hw);
1167 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001168 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001169
Chaoming_Liacd48572011-04-25 12:52:54 -05001170 if (sta == NULL)
1171 return -EINVAL;
1172
1173 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001174 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Larry Finger0c817332010-12-08 11:12:31 -06001175 return -EINVAL;
1176 }
1177
Joe Perchesf30d7502012-01-04 19:40:41 -08001178 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1179 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001180
Larry Finger0c817332010-12-08 11:12:31 -06001181 if (unlikely(tid >= MAX_TID_COUNT))
1182 return -EINVAL;
1183
Chaoming_Liacd48572011-04-25 12:52:54 -05001184 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001185 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001186
Chaoming_Liacd48572011-04-25 12:52:54 -05001187 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001188
Chaoming_Liacd48572011-04-25 12:52:54 -05001189 return 0;
1190}
Larry Finger0c817332010-12-08 11:12:31 -06001191
Larry Finger26634c42013-03-24 22:06:33 -05001192int rtl_rx_agg_start(struct ieee80211_hw *hw,
1193 struct ieee80211_sta *sta, u16 tid)
1194{
1195 struct rtl_priv *rtlpriv = rtl_priv(hw);
1196 struct rtl_tid_data *tid_data;
1197 struct rtl_sta_info *sta_entry = NULL;
1198
1199 if (sta == NULL)
1200 return -EINVAL;
1201
1202 if (unlikely(tid >= MAX_TID_COUNT))
1203 return -EINVAL;
1204
1205 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1206 if (!sta_entry)
1207 return -ENXIO;
1208 tid_data = &sta_entry->tids[tid];
1209
1210 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1211 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1212 tid_data->seq_number);
1213
1214 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1215 return 0;
1216}
1217
1218int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1219 struct ieee80211_sta *sta, u16 tid)
1220{
1221 struct rtl_priv *rtlpriv = rtl_priv(hw);
1222 struct rtl_sta_info *sta_entry = NULL;
1223
1224 if (sta == NULL)
1225 return -EINVAL;
1226
1227 if (!sta->addr) {
1228 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
1229 return -EINVAL;
1230 }
1231
1232 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1233 "on ra = %pM tid = %d\n", sta->addr, tid);
1234
1235 if (unlikely(tid >= MAX_TID_COUNT))
1236 return -EINVAL;
1237
1238 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1239 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1240
1241 return 0;
1242}
1243
Chaoming_Liacd48572011-04-25 12:52:54 -05001244int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1245 struct ieee80211_sta *sta, u16 tid)
1246{
1247 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001248 struct rtl_sta_info *sta_entry = NULL;
1249
1250 if (sta == NULL)
1251 return -EINVAL;
1252
1253 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001254 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001255 return -EINVAL;
1256 }
1257
Joe Perchesf30d7502012-01-04 19:40:41 -08001258 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1259 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001260
1261 if (unlikely(tid >= MAX_TID_COUNT))
1262 return -EINVAL;
1263
1264 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001265 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001266
1267 return 0;
1268}
1269
1270/*********************************************************
1271 *
1272 * wq & timer callback functions
1273 *
1274 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001275/* this function is used for roaming */
1276void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1277{
1278 struct rtl_priv *rtlpriv = rtl_priv(hw);
1279 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1280
1281 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1282 return;
1283
1284 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1285 return;
1286
1287 /* check if this really is a beacon */
1288 if (!ieee80211_is_beacon(hdr->frame_control) &&
1289 !ieee80211_is_probe_resp(hdr->frame_control))
1290 return;
1291
1292 /* min. beacon length + FCS_LEN */
1293 if (skb->len <= 40 + FCS_LEN)
1294 return;
1295
1296 /* and only beacons from the associated BSSID, please */
1297 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
1298 return;
1299
1300 rtlpriv->link_info.bcn_rx_inperiod++;
1301}
1302
Larry Finger0c817332010-12-08 11:12:31 -06001303void rtl_watchdog_wq_callback(void *data)
1304{
1305 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1306 struct rtl_works,
1307 watchdog_wq);
1308 struct ieee80211_hw *hw = rtlworks->hw;
1309 struct rtl_priv *rtlpriv = rtl_priv(hw);
1310 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1311 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001312 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001313 bool tx_busy_traffic = false;
1314 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001315 bool higher_busytraffic = false;
1316 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001317 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001318 u32 rx_cnt_inp4eriod = 0;
1319 u32 tx_cnt_inp4eriod = 0;
1320 u32 aver_rx_cnt_inperiod = 0;
1321 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001322 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1323 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001324
1325 if (is_hal_stop(rtlhal))
1326 return;
1327
1328 /* <1> Determine if action frame is allowed */
1329 if (mac->link_state > MAC80211_NOLINK) {
1330 if (mac->cnt_after_linked < 20)
1331 mac->cnt_after_linked++;
1332 } else {
1333 mac->cnt_after_linked = 0;
1334 }
1335
Larry Finger0c817332010-12-08 11:12:31 -06001336 /*
Chaoming Li09e92f02011-10-11 21:28:48 -05001337 *<2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001338 * busytraffic we don't change channel
1339 */
1340 if (mac->link_state >= MAC80211_LINKED) {
1341
1342 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1343 for (idx = 0; idx <= 2; idx++) {
1344 rtlpriv->link_info.num_rx_in4period[idx] =
1345 rtlpriv->link_info.num_rx_in4period[idx + 1];
1346 rtlpriv->link_info.num_tx_in4period[idx] =
1347 rtlpriv->link_info.num_tx_in4period[idx + 1];
1348 }
1349 rtlpriv->link_info.num_rx_in4period[3] =
1350 rtlpriv->link_info.num_rx_inperiod;
1351 rtlpriv->link_info.num_tx_in4period[3] =
1352 rtlpriv->link_info.num_tx_inperiod;
1353 for (idx = 0; idx <= 3; idx++) {
1354 rx_cnt_inp4eriod +=
1355 rtlpriv->link_info.num_rx_in4period[idx];
1356 tx_cnt_inp4eriod +=
1357 rtlpriv->link_info.num_tx_in4period[idx];
1358 }
1359 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1360 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1361
1362 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001363 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001364 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001365 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1366 rx_busy_traffic = true;
1367 else
1368 tx_busy_traffic = false;
1369 }
Larry Finger0c817332010-12-08 11:12:31 -06001370
1371 /* Higher Tx/Rx data. */
1372 if (aver_rx_cnt_inperiod > 4000 ||
1373 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001374 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001375
1376 /* Extremely high Rx data. */
1377 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001378 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001379 }
1380
1381 /* check every tid's tx traffic */
1382 for (tid = 0; tid <= 7; tid++) {
1383 for (idx = 0; idx <= 2; idx++)
1384 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1385 rtlpriv->link_info.tidtx_in4period[tid]
1386 [idx + 1];
1387 rtlpriv->link_info.tidtx_in4period[tid][3] =
1388 rtlpriv->link_info.tidtx_inperiod[tid];
1389
1390 for (idx = 0; idx <= 3; idx++)
1391 tidtx_inp4eriod[tid] +=
1392 rtlpriv->link_info.tidtx_in4period[tid][idx];
1393 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1394 if (aver_tidtx_inperiod[tid] > 5000)
1395 rtlpriv->link_info.higher_busytxtraffic[tid] =
1396 true;
Larry Finger0c817332010-12-08 11:12:31 -06001397 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001398 rtlpriv->link_info.higher_busytxtraffic[tid] =
1399 false;
Larry Finger0c817332010-12-08 11:12:31 -06001400 }
1401
1402 if (((rtlpriv->link_info.num_rx_inperiod +
1403 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1404 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingera2699132013-03-24 22:06:41 -05001405 rtlpriv->enter_ps = true;
Larry Finger0c817332010-12-08 11:12:31 -06001406 else
Larry Fingera2699132013-03-24 22:06:41 -05001407 rtlpriv->enter_ps = false;
Larry Finger0c817332010-12-08 11:12:31 -06001408
1409 /* LeisurePS only work in infra mode. */
Larry Fingera2699132013-03-24 22:06:41 -05001410 schedule_work(&rtlpriv->works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001411 }
1412
1413 rtlpriv->link_info.num_rx_inperiod = 0;
1414 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001415 for (tid = 0; tid <= 7; tid++)
1416 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001417
Larry Finger7ea47242011-02-19 16:28:57 -06001418 rtlpriv->link_info.busytraffic = busytraffic;
1419 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001420 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1421 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001422 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001423
Chaoming_Liacd48572011-04-25 12:52:54 -05001424 /* <3> DM */
1425 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001426
1427 /* <4> roaming */
1428 if (mac->link_state == MAC80211_LINKED &&
1429 mac->opmode == NL80211_IFTYPE_STATION) {
1430 if ((rtlpriv->link_info.bcn_rx_inperiod +
1431 rtlpriv->link_info.num_rx_inperiod) == 0) {
1432 rtlpriv->link_info.roam_times++;
1433 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1434 "AP off for %d s\n",
1435 (rtlpriv->link_info.roam_times * 2));
1436
1437 /* if we can't recv beacon for 6s, we should
1438 * reconnect this AP
1439 */
1440 if (rtlpriv->link_info.roam_times >= 3) {
1441 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1442 "AP off, try to reconnect now\n");
1443 rtlpriv->link_info.roam_times = 0;
1444 ieee80211_connection_loss(rtlpriv->mac80211.vif);
1445 }
1446 } else {
1447 rtlpriv->link_info.roam_times = 0;
1448 }
1449 }
1450 rtlpriv->link_info.bcn_rx_inperiod = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001451}
1452
1453void rtl_watch_dog_timer_callback(unsigned long data)
1454{
1455 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1456 struct rtl_priv *rtlpriv = rtl_priv(hw);
1457
1458 queue_delayed_work(rtlpriv->works.rtl_wq,
1459 &rtlpriv->works.watchdog_wq, 0);
1460
1461 mod_timer(&rtlpriv->works.watchdog_timer,
1462 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1463}
1464
Larry Finger26634c42013-03-24 22:06:33 -05001465void rtl_fwevt_wq_callback(void *data)
1466{
1467 struct rtl_works *rtlworks =
1468 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1469 struct ieee80211_hw *hw = rtlworks->hw;
1470 struct rtl_priv *rtlpriv = rtl_priv(hw);
1471
1472 rtlpriv->cfg->ops->c2h_command_handle(hw);
1473}
1474
1475void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
1476{
1477 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1478 struct rtl_priv *rtlpriv = rtl_priv(hw);
1479 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
1480
1481 if (buddy_priv == NULL)
1482 return;
1483
1484 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
1485}
1486
Larry Finger0c817332010-12-08 11:12:31 -06001487/*********************************************************
1488 *
Chaoming_Liacd48572011-04-25 12:52:54 -05001489 * frame process functions
1490 *
1491 *********************************************************/
1492u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1493{
1494 struct ieee80211_mgmt *mgmt = (void *)data;
1495 u8 *pos, *end;
1496
1497 pos = (u8 *)mgmt->u.beacon.variable;
1498 end = data + len;
1499 while (pos < end) {
1500 if (pos + 2 + pos[1] > end)
1501 return NULL;
1502
1503 if (pos[0] == ie)
1504 return pos;
1505
1506 pos += 2 + pos[1];
1507 }
1508 return NULL;
1509}
1510
1511/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1512/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05001513static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -05001514 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1515{
1516 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1517 struct sk_buff *skb;
1518 struct ieee80211_mgmt *action_frame;
1519
1520 /* 27 = header + category + action + smps mode */
1521 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1522 if (!skb)
1523 return NULL;
1524
1525 skb_reserve(skb, hw->extra_tx_headroom);
1526 action_frame = (void *)skb_put(skb, 27);
1527 memset(action_frame, 0, 27);
1528 memcpy(action_frame->da, da, ETH_ALEN);
1529 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1530 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1531 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1532 IEEE80211_STYPE_ACTION);
1533 action_frame->u.action.category = WLAN_CATEGORY_HT;
1534 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1535 switch (smps) {
1536 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1537 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1538 WARN_ON(1);
1539 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1540 action_frame->u.action.u.ht_smps.smps_control =
1541 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1542 break;
1543 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1544 action_frame->u.action.u.ht_smps.smps_control =
1545 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1546 break;
1547 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1548 action_frame->u.action.u.ht_smps.smps_control =
1549 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1550 break;
1551 }
1552
1553 return skb;
1554}
1555
1556int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger26634c42013-03-24 22:06:33 -05001557 struct ieee80211_sta *sta,
Chaoming_Liacd48572011-04-25 12:52:54 -05001558 enum ieee80211_smps_mode smps)
1559{
1560 struct rtl_priv *rtlpriv = rtl_priv(hw);
1561 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1562 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05001563 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05001564 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05001565 u8 bssid[ETH_ALEN] = {0};
1566
Chaoming_Liacd48572011-04-25 12:52:54 -05001567 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1568
1569 if (rtlpriv->mac80211.act_scanning)
1570 goto err_free;
1571
1572 if (!sta)
1573 goto err_free;
1574
1575 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1576 goto err_free;
1577
1578 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1579 goto err_free;
1580
Larry Finger26634c42013-03-24 22:06:33 -05001581 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
1582 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
1583 else
1584 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
1585
1586 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001587 /* this is a type = mgmt * stype = action frame */
1588 if (skb) {
1589 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1590 struct rtl_sta_info *sta_entry =
1591 (struct rtl_sta_info *) sta->drv_priv;
1592 sta_entry->mimo_ps = smps;
Chaoming_Liacd48572011-04-25 12:52:54 -05001593
1594 info->control.rates[0].idx = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001595 info->band = hw->conf.channel->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02001596 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05001597 }
Larry Finger26634c42013-03-24 22:06:33 -05001598 return 1;
1599
Chaoming_Liacd48572011-04-25 12:52:54 -05001600err_free:
1601 return 0;
1602}
Larry Finger26634c42013-03-24 22:06:33 -05001603EXPORT_SYMBOL(rtl_send_smps_action);
1604
1605/* There seem to be issues in mac80211 regarding when del ba frames can be
1606 * received. As a work around, we make a fake del_ba if we receive a ba_req;
1607 * however, rx_agg was opened to let mac80211 release some ba related
1608 * resources. This del_ba is for tx only.
1609 */
1610struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
1611 u8 *sa, u8 *bssid, u16 tid)
1612{
1613 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1614 struct sk_buff *skb;
1615 struct ieee80211_mgmt *action_frame;
1616 u16 params;
1617
1618 /* 27 = header + category + action + smps mode */
1619 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
1620 if (!skb)
1621 return NULL;
1622
1623 skb_reserve(skb, hw->extra_tx_headroom);
1624 action_frame = (void *)skb_put(skb, 34);
1625 memset(action_frame, 0, 34);
1626 memcpy(action_frame->sa, sa, ETH_ALEN);
1627 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
1628 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1629 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1630 IEEE80211_STYPE_ACTION);
1631 action_frame->u.action.category = WLAN_CATEGORY_BACK;
1632 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1633 params = (u16)(1 << 11); /* bit 11 initiator */
1634 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1635
1636 action_frame->u.action.u.delba.params = cpu_to_le16(params);
1637 action_frame->u.action.u.delba.reason_code =
1638 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
1639
1640 return skb;
1641}
Chaoming_Liacd48572011-04-25 12:52:54 -05001642
1643/*********************************************************
1644 *
1645 * IOT functions
1646 *
1647 *********************************************************/
1648static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1649 struct octet_string vendor_ie)
1650{
1651 struct rtl_priv *rtlpriv = rtl_priv(hw);
1652 bool matched = false;
1653 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1654 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1655 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1656 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1657 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1658 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1659 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1660 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1661
1662 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1663 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1664 rtlpriv->mac80211.vendor = PEER_ATH;
1665 matched = true;
1666 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1667 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1668 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1669 rtlpriv->mac80211.vendor = PEER_BROAD;
1670 matched = true;
1671 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1672 rtlpriv->mac80211.vendor = PEER_RAL;
1673 matched = true;
1674 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1675 rtlpriv->mac80211.vendor = PEER_CISCO;
1676 matched = true;
1677 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1678 rtlpriv->mac80211.vendor = PEER_MARV;
1679 matched = true;
1680 }
1681
1682 return matched;
1683}
1684
Larry Fingerd3bb1422011-04-25 13:23:20 -05001685static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05001686 unsigned int len)
1687{
1688 struct ieee80211_mgmt *mgmt = (void *)data;
1689 struct octet_string vendor_ie;
1690 u8 *pos, *end;
1691
1692 pos = (u8 *)mgmt->u.beacon.variable;
1693 end = data + len;
1694 while (pos < end) {
1695 if (pos[0] == 221) {
1696 vendor_ie.length = pos[1];
1697 vendor_ie.octet = &pos[2];
1698 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1699 return true;
1700 }
1701
1702 if (pos + 2 + pos[1] > end)
1703 return false;
1704
1705 pos += 2 + pos[1];
1706 }
1707 return false;
1708}
1709
1710void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1711{
1712 struct rtl_priv *rtlpriv = rtl_priv(hw);
1713 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1714 struct ieee80211_hdr *hdr = (void *)data;
1715 u32 vendor = PEER_UNKNOWN;
1716
1717 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1718 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1719 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1720 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1721 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1722 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1723 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1724 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1725 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1726 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1727 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1728 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1729 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1730 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1731 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1732 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1733
1734 if (mac->opmode != NL80211_IFTYPE_STATION)
1735 return;
1736
1737 if (mac->link_state == MAC80211_NOLINK) {
1738 mac->vendor = PEER_UNKNOWN;
1739 return;
1740 }
1741
1742 if (mac->cnt_after_linked > 2)
1743 return;
1744
1745 /* check if this really is a beacon */
1746 if (!ieee80211_is_beacon(hdr->frame_control))
1747 return;
1748
1749 /* min. beacon length + FCS_LEN */
1750 if (len <= 40 + FCS_LEN)
1751 return;
1752
1753 /* and only beacons from the associated BSSID, please */
Joe Perches2e42e472012-05-09 17:17:46 +00001754 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05001755 return;
1756
1757 if (rtl_find_221_ie(hw, data, len))
1758 vendor = mac->vendor;
1759
1760 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1761 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1762 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1763 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1764 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1765 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1766 vendor == PEER_ATH) {
1767 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08001768 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001769 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1770 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1771 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1772 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1773 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1774 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001775 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001776 vendor = PEER_RAL;
1777 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1778 vendor == PEER_CISCO) {
1779 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08001780 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001781 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1782 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1783 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1784 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001785 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001786 vendor = PEER_BROAD;
1787 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1788 vendor == PEER_MARV) {
1789 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08001790 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001791 }
1792
1793 mac->vendor = vendor;
1794}
1795
1796/*********************************************************
1797 *
Larry Finger0c817332010-12-08 11:12:31 -06001798 * sysfs functions
1799 *
1800 *********************************************************/
1801static ssize_t rtl_show_debug_level(struct device *d,
1802 struct device_attribute *attr, char *buf)
1803{
1804 struct ieee80211_hw *hw = dev_get_drvdata(d);
1805 struct rtl_priv *rtlpriv = rtl_priv(hw);
1806
1807 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
1808}
1809
1810static ssize_t rtl_store_debug_level(struct device *d,
1811 struct device_attribute *attr,
1812 const char *buf, size_t count)
1813{
1814 struct ieee80211_hw *hw = dev_get_drvdata(d);
1815 struct rtl_priv *rtlpriv = rtl_priv(hw);
1816 unsigned long val;
1817 int ret;
1818
1819 ret = strict_strtoul(buf, 0, &val);
1820 if (ret) {
1821 printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
1822 } else {
1823 rtlpriv->dbg.global_debuglevel = val;
1824 printk(KERN_DEBUG "debuglevel:%x\n",
1825 rtlpriv->dbg.global_debuglevel);
1826 }
1827
1828 return strnlen(buf, count);
1829}
1830
1831static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1832 rtl_show_debug_level, rtl_store_debug_level);
1833
1834static struct attribute *rtl_sysfs_entries[] = {
1835
1836 &dev_attr_debug_level.attr,
1837
1838 NULL
1839};
1840
1841/*
1842 * "name" is folder name witch will be
1843 * put in device directory like :
1844 * sys/devices/pci0000:00/0000:00:1c.4/
1845 * 0000:06:00.0/rtl_sysfs
1846 */
1847struct attribute_group rtl_attribute_group = {
1848 .name = "rtlsysfs",
1849 .attrs = rtl_sysfs_entries,
1850};
1851
1852MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1853MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1854MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1855MODULE_LICENSE("GPL");
1856MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1857
Larry Finger26634c42013-03-24 22:06:33 -05001858struct rtl_global_var global_var = {};
1859
Larry Finger0c817332010-12-08 11:12:31 -06001860static int __init rtl_core_module_init(void)
1861{
Chaoming Li375ff4c2011-02-28 16:40:28 -06001862 if (rtl_rate_control_register())
Joe Perches292b1192011-07-20 08:51:35 -07001863 pr_err("Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001864
Larry Finger26634c42013-03-24 22:06:33 -05001865 /* init some global vars */
1866 INIT_LIST_HEAD(&global_var.glb_priv_list);
1867 spin_lock_init(&global_var.glb_list_lock);
1868
Larry Finger0c817332010-12-08 11:12:31 -06001869 return 0;
1870}
1871
1872static void __exit rtl_core_module_exit(void)
1873{
Chaoming_Liacd48572011-04-25 12:52:54 -05001874 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06001875 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06001876}
1877
1878module_init(rtl_core_module_init);
1879module_exit(rtl_core_module_exit);