blob: 3698028c910dca2ed1982ec0b947d7c36ccf38af [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>
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -050040#include <linux/udp.h>
Larry Fingerd273bb22012-01-27 13:59:25 -060041
Larry Finger0c817332010-12-08 11:12:31 -060042/*
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010043 *NOTICE!!!: This file will be very big, we should
44 *keep it clear under following roles:
Larry Finger0c817332010-12-08 11:12:31 -060045 *
Tristan Pourcelote1fa7462012-02-09 14:48:09 +010046 *This file include following parts, so, if you add new
Larry Finger0c817332010-12-08 11:12:31 -060047 *functions into this file, please check which part it
48 *should includes. or check if you should add new part
49 *for this file:
50 *
51 *1) mac80211 init functions
52 *2) tx information functions
53 *3) functions called by core.c
54 *4) wq & timer callback functions
55 *5) frame process functions
Chaoming_Liacd48572011-04-25 12:52:54 -050056 *6) IOT functions
57 *7) sysfs functions
Larry Finger26634c42013-03-24 22:06:33 -050058 *8) vif functions
59 *9) ...
Larry Finger0c817332010-12-08 11:12:31 -060060 */
61
62/*********************************************************
63 *
64 * mac80211 init functions
65 *
66 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -050067static struct ieee80211_channel rtl_channeltable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -060068 {.center_freq = 2412, .hw_value = 1,},
69 {.center_freq = 2417, .hw_value = 2,},
70 {.center_freq = 2422, .hw_value = 3,},
71 {.center_freq = 2427, .hw_value = 4,},
72 {.center_freq = 2432, .hw_value = 5,},
73 {.center_freq = 2437, .hw_value = 6,},
74 {.center_freq = 2442, .hw_value = 7,},
75 {.center_freq = 2447, .hw_value = 8,},
76 {.center_freq = 2452, .hw_value = 9,},
77 {.center_freq = 2457, .hw_value = 10,},
78 {.center_freq = 2462, .hw_value = 11,},
79 {.center_freq = 2467, .hw_value = 12,},
80 {.center_freq = 2472, .hw_value = 13,},
81 {.center_freq = 2484, .hw_value = 14,},
82};
83
Chaoming_Liacd48572011-04-25 12:52:54 -050084static struct ieee80211_channel rtl_channeltable_5g[] = {
85 {.center_freq = 5180, .hw_value = 36,},
86 {.center_freq = 5200, .hw_value = 40,},
87 {.center_freq = 5220, .hw_value = 44,},
88 {.center_freq = 5240, .hw_value = 48,},
89 {.center_freq = 5260, .hw_value = 52,},
90 {.center_freq = 5280, .hw_value = 56,},
91 {.center_freq = 5300, .hw_value = 60,},
92 {.center_freq = 5320, .hw_value = 64,},
93 {.center_freq = 5500, .hw_value = 100,},
94 {.center_freq = 5520, .hw_value = 104,},
95 {.center_freq = 5540, .hw_value = 108,},
96 {.center_freq = 5560, .hw_value = 112,},
97 {.center_freq = 5580, .hw_value = 116,},
98 {.center_freq = 5600, .hw_value = 120,},
99 {.center_freq = 5620, .hw_value = 124,},
100 {.center_freq = 5640, .hw_value = 128,},
101 {.center_freq = 5660, .hw_value = 132,},
102 {.center_freq = 5680, .hw_value = 136,},
103 {.center_freq = 5700, .hw_value = 140,},
104 {.center_freq = 5745, .hw_value = 149,},
105 {.center_freq = 5765, .hw_value = 153,},
106 {.center_freq = 5785, .hw_value = 157,},
107 {.center_freq = 5805, .hw_value = 161,},
108 {.center_freq = 5825, .hw_value = 165,},
109};
110
111static struct ieee80211_rate rtl_ratetable_2g[] = {
Larry Finger0c817332010-12-08 11:12:31 -0600112 {.bitrate = 10, .hw_value = 0x00,},
113 {.bitrate = 20, .hw_value = 0x01,},
114 {.bitrate = 55, .hw_value = 0x02,},
115 {.bitrate = 110, .hw_value = 0x03,},
116 {.bitrate = 60, .hw_value = 0x04,},
117 {.bitrate = 90, .hw_value = 0x05,},
118 {.bitrate = 120, .hw_value = 0x06,},
119 {.bitrate = 180, .hw_value = 0x07,},
120 {.bitrate = 240, .hw_value = 0x08,},
121 {.bitrate = 360, .hw_value = 0x09,},
122 {.bitrate = 480, .hw_value = 0x0a,},
123 {.bitrate = 540, .hw_value = 0x0b,},
124};
125
Chaoming_Liacd48572011-04-25 12:52:54 -0500126static struct ieee80211_rate rtl_ratetable_5g[] = {
127 {.bitrate = 60, .hw_value = 0x04,},
128 {.bitrate = 90, .hw_value = 0x05,},
129 {.bitrate = 120, .hw_value = 0x06,},
130 {.bitrate = 180, .hw_value = 0x07,},
131 {.bitrate = 240, .hw_value = 0x08,},
132 {.bitrate = 360, .hw_value = 0x09,},
133 {.bitrate = 480, .hw_value = 0x0a,},
134 {.bitrate = 540, .hw_value = 0x0b,},
135};
136
Larry Finger0c817332010-12-08 11:12:31 -0600137static const struct ieee80211_supported_band rtl_band_2ghz = {
138 .band = IEEE80211_BAND_2GHZ,
139
Chaoming_Liacd48572011-04-25 12:52:54 -0500140 .channels = rtl_channeltable_2g,
141 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600142
Chaoming_Liacd48572011-04-25 12:52:54 -0500143 .bitrates = rtl_ratetable_2g,
144 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
Larry Finger0c817332010-12-08 11:12:31 -0600145
146 .ht_cap = {0},
147};
148
Chaoming_Liacd48572011-04-25 12:52:54 -0500149static struct ieee80211_supported_band rtl_band_5ghz = {
150 .band = IEEE80211_BAND_5GHZ,
151
152 .channels = rtl_channeltable_5g,
153 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
154
155 .bitrates = rtl_ratetable_5g,
156 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
157
158 .ht_cap = {0},
159};
160
161static const u8 tid_to_ac[] = {
162 2, /* IEEE80211_AC_BE */
163 3, /* IEEE80211_AC_BK */
164 3, /* IEEE80211_AC_BK */
165 2, /* IEEE80211_AC_BE */
166 1, /* IEEE80211_AC_VI */
167 1, /* IEEE80211_AC_VI */
168 0, /* IEEE80211_AC_VO */
169 0, /* IEEE80211_AC_VO */
170};
171
Larry Finger2a00def2012-07-11 14:32:33 -0500172u8 rtl_tid_to_ac(u8 tid)
Chaoming_Liacd48572011-04-25 12:52:54 -0500173{
174 return tid_to_ac[tid];
175}
176
Larry Finger0c817332010-12-08 11:12:31 -0600177static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
178 struct ieee80211_sta_ht_cap *ht_cap)
179{
180 struct rtl_priv *rtlpriv = rtl_priv(hw);
181 struct rtl_phy *rtlphy = &(rtlpriv->phy);
182
183 ht_cap->ht_supported = true;
184 ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
185 IEEE80211_HT_CAP_SGI_40 |
186 IEEE80211_HT_CAP_SGI_20 |
187 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
188
Chaoming_Liacd48572011-04-25 12:52:54 -0500189 if (rtlpriv->rtlhal.disable_amsdu_8k)
190 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
191
Larry Finger0c817332010-12-08 11:12:31 -0600192 /*
193 *Maximum length of AMPDU that the STA can receive.
194 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
195 */
196 ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
197
198 /*Minimum MPDU start spacing , */
199 ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
200
201 ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
202
Larry Finger26634c42013-03-24 22:06:33 -0500203 /*hw->wiphy->bands[IEEE80211_BAND_2GHZ]
Larry Finger0c817332010-12-08 11:12:31 -0600204 *base on ant_num
205 *rx_mask: RX mask
Larry Finger26634c42013-03-24 22:06:33 -0500206 *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7
207 *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15
208 *if rx_ant >= 3 rx_mask[2]= 0xff;
209 *if BW_40 rx_mask[4]= 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600210 *highest supported RX rate
211 */
Larry Finger26634c42013-03-24 22:06:33 -0500212 if (rtlpriv->dm.supp_phymode_switch) {
Larry Finger0c817332010-12-08 11:12:31 -0600213
Larry Finger26634c42013-03-24 22:06:33 -0500214 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
215 "Support phy mode switch\n");
Larry Finger0c817332010-12-08 11:12:31 -0600216
217 ht_cap->mcs.rx_mask[0] = 0xFF;
218 ht_cap->mcs.rx_mask[1] = 0xFF;
219 ht_cap->mcs.rx_mask[4] = 0x01;
220
Larry Finger17c9ac62011-02-19 16:29:57 -0600221 ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
Larry Finger26634c42013-03-24 22:06:33 -0500222 } else {
223 if (get_rf_type(rtlphy) == RF_1T2R ||
224 get_rf_type(rtlphy) == RF_2T2R) {
225 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
226 "1T2R or 2T2R\n");
227 ht_cap->mcs.rx_mask[0] = 0xFF;
228 ht_cap->mcs.rx_mask[1] = 0xFF;
229 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600230
Larry Finger26634c42013-03-24 22:06:33 -0500231 ht_cap->mcs.rx_highest =
232 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15);
233 } else if (get_rf_type(rtlphy) == RF_1T1R) {
234 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n");
Larry Finger0c817332010-12-08 11:12:31 -0600235
Larry Finger26634c42013-03-24 22:06:33 -0500236 ht_cap->mcs.rx_mask[0] = 0xFF;
237 ht_cap->mcs.rx_mask[1] = 0x00;
238 ht_cap->mcs.rx_mask[4] = 0x01;
Larry Finger0c817332010-12-08 11:12:31 -0600239
Larry Finger26634c42013-03-24 22:06:33 -0500240 ht_cap->mcs.rx_highest =
241 cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7);
242 }
Larry Finger0c817332010-12-08 11:12:31 -0600243 }
244}
245
246static void _rtl_init_mac80211(struct ieee80211_hw *hw)
247{
Chaoming_Liacd48572011-04-25 12:52:54 -0500248 struct rtl_priv *rtlpriv = rtl_priv(hw);
249 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
Larry Finger0c817332010-12-08 11:12:31 -0600250 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
251 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
252 struct ieee80211_supported_band *sband;
253
Larry Finger0c817332010-12-08 11:12:31 -0600254
Chaoming_Liacd48572011-04-25 12:52:54 -0500255 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
256 BAND_ON_BOTH) {
257 /* 1: 2.4 G bands */
258 /* <1> use mac->bands as mem for hw->wiphy->bands */
259 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
Larry Finger0c817332010-12-08 11:12:31 -0600260
Chaoming_Liacd48572011-04-25 12:52:54 -0500261 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
262 * to default value(1T1R) */
263 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
264 sizeof(struct ieee80211_supported_band));
Larry Finger0c817332010-12-08 11:12:31 -0600265
Chaoming_Liacd48572011-04-25 12:52:54 -0500266 /* <3> init ht cap base on ant_num */
267 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
Larry Finger0c817332010-12-08 11:12:31 -0600268
Chaoming_Liacd48572011-04-25 12:52:54 -0500269 /* <4> set mac->sband to wiphy->sband */
270 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
271
272 /* 2: 5 G bands */
273 /* <1> use mac->bands as mem for hw->wiphy->bands */
274 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
275
276 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
277 * to default value(1T1R) */
278 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
279 sizeof(struct ieee80211_supported_band));
280
281 /* <3> init ht cap base on ant_num */
282 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
283
284 /* <4> set mac->sband to wiphy->sband */
285 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
286 } else {
287 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
288 /* <1> use mac->bands as mem for hw->wiphy->bands */
289 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
290
291 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
292 * to default value(1T1R) */
293 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
294 &rtl_band_2ghz,
295 sizeof(struct ieee80211_supported_band));
296
297 /* <3> init ht cap base on ant_num */
298 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
299
300 /* <4> set mac->sband to wiphy->sband */
301 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
302 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
303 /* <1> use mac->bands as mem for hw->wiphy->bands */
304 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
305
306 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
307 * to default value(1T1R) */
308 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
309 &rtl_band_5ghz,
310 sizeof(struct ieee80211_supported_band));
311
312 /* <3> init ht cap base on ant_num */
313 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
314
315 /* <4> set mac->sband to wiphy->sband */
316 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
317 } else {
Joe Perchesf30d7502012-01-04 19:40:41 -0800318 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n",
319 rtlhal->current_bandtype);
Chaoming_Liacd48572011-04-25 12:52:54 -0500320 }
321 }
Larry Finger0c817332010-12-08 11:12:31 -0600322 /* <5> set hw caps */
323 hw->flags = IEEE80211_HW_SIGNAL_DBM |
324 IEEE80211_HW_RX_INCLUDES_FCS |
Chaoming_Liacd48572011-04-25 12:52:54 -0500325 IEEE80211_HW_AMPDU_AGGREGATION |
Chaoming Li09e92f02011-10-11 21:28:48 -0500326 IEEE80211_HW_CONNECTION_MONITOR |
327 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
Larry Finger26634c42013-03-24 22:06:33 -0500328 IEEE80211_HW_CONNECTION_MONITOR |
329 IEEE80211_HW_MFP_CAPABLE |
Larry Finger0c817332010-12-08 11:12:31 -0600330 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
331
Chaoming_Liacd48572011-04-25 12:52:54 -0500332 /* swlps or hwlps has been set in diff chip in init_sw_vars */
333 if (rtlpriv->psc.swctrl_lps)
334 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
335 IEEE80211_HW_PS_NULLFUNC_STACK |
336 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
337 0;
338
Larry Finger0c817332010-12-08 11:12:31 -0600339 hw->wiphy->interface_modes =
Chaoming_Liacd48572011-04-25 12:52:54 -0500340 BIT(NL80211_IFTYPE_AP) |
341 BIT(NL80211_IFTYPE_STATION) |
Larry Finger26634c42013-03-24 22:06:33 -0500342 BIT(NL80211_IFTYPE_ADHOC) |
343 BIT(NL80211_IFTYPE_MESH_POINT) |
344 BIT(NL80211_IFTYPE_P2P_CLIENT) |
345 BIT(NL80211_IFTYPE_P2P_GO);
Larry Finger0c817332010-12-08 11:12:31 -0600346
Larry Finger26634c42013-03-24 22:06:33 -0500347 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Larry Finger0c817332010-12-08 11:12:31 -0600348 hw->wiphy->rts_threshold = 2347;
349
350 hw->queues = AC_MAX;
351 hw->extra_tx_headroom = RTL_TX_HEADER_SIZE;
352
353 /* TODO: Correct this value for our hw */
354 /* TODO: define these hard code value */
355 hw->channel_change_time = 100;
Chaoming_Liacd48572011-04-25 12:52:54 -0500356 hw->max_listen_interval = 10;
Larry Finger0c817332010-12-08 11:12:31 -0600357 hw->max_rate_tries = 4;
358 /* hw->max_rates = 1; */
Chaoming_Liacd48572011-04-25 12:52:54 -0500359 hw->sta_data_size = sizeof(struct rtl_sta_info);
Larry Finger0c817332010-12-08 11:12:31 -0600360
361 /* <6> mac address */
362 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
363 SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr);
364 } else {
Larry Fingerabfabc92011-11-17 12:14:44 -0600365 u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
366 get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1);
367 SET_IEEE80211_PERM_ADDR(hw, rtlmac1);
Larry Finger0c817332010-12-08 11:12:31 -0600368 }
369
370}
371
372static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
373{
374 struct rtl_priv *rtlpriv = rtl_priv(hw);
375
376 /* <1> timer */
Larry Finger0c817332010-12-08 11:12:31 -0600377 setup_timer(&rtlpriv->works.watchdog_timer,
378 rtl_watch_dog_timer_callback, (unsigned long)hw);
Larry Finger26634c42013-03-24 22:06:33 -0500379 setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer,
380 rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw);
Larry Finger0c817332010-12-08 11:12:31 -0600381
382 /* <2> work queue */
383 rtlpriv->works.hw = hw;
John W. Linville3d986b22010-12-16 14:59:49 -0500384 rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0);
Larry Finger0c817332010-12-08 11:12:31 -0600385 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
386 (void *)rtl_watchdog_wq_callback);
387 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
388 (void *)rtl_ips_nic_off_wq_callback);
Chaoming_Liacd48572011-04-25 12:52:54 -0500389 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
390 (void *)rtl_swlps_wq_callback);
391 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
392 (void *)rtl_swlps_rfon_wq_callback);
Larry Finger26634c42013-03-24 22:06:33 -0500393 INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq,
394 (void *)rtl_fwevt_wq_callback);
Larry Finger0c817332010-12-08 11:12:31 -0600395
396}
397
398void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
399{
400 struct rtl_priv *rtlpriv = rtl_priv(hw);
401
402 del_timer_sync(&rtlpriv->works.watchdog_timer);
403
404 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
405 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
Chaoming_Liacd48572011-04-25 12:52:54 -0500406 cancel_delayed_work(&rtlpriv->works.ps_work);
407 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
Larry Finger26634c42013-03-24 22:06:33 -0500408 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
Larry Finger0c817332010-12-08 11:12:31 -0600409}
410
411void rtl_init_rfkill(struct ieee80211_hw *hw)
412{
413 struct rtl_priv *rtlpriv = rtl_priv(hw);
414
415 bool radio_state;
416 bool blocked;
417 u8 valid = 0;
418
Chaoming Li228bdfc2011-04-10 18:30:23 -0500419 /*set init state to on */
Rusty Russell3db1cd52011-12-19 13:56:45 +0000420 rtlpriv->rfkill.rfkill_state = true;
Chaoming Li228bdfc2011-04-10 18:30:23 -0500421 wiphy_rfkill_set_hw_state(hw->wiphy, 0);
422
Larry Finger0c817332010-12-08 11:12:31 -0600423 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
424
Larry Fingere6d8a812010-12-21 19:40:40 -0600425 if (valid) {
Joe Perches292b1192011-07-20 08:51:35 -0700426 pr_info("wireless switch is %s\n",
427 rtlpriv->rfkill.rfkill_state ? "on" : "off");
Chaoming Li228bdfc2011-04-10 18:30:23 -0500428
Larry Finger0c817332010-12-08 11:12:31 -0600429 rtlpriv->rfkill.rfkill_state = radio_state;
430
431 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
432 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
433 }
434
435 wiphy_rfkill_start_polling(hw->wiphy);
436}
Larry Fingerb0302ab2012-01-30 09:54:49 -0600437EXPORT_SYMBOL(rtl_init_rfkill);
Larry Finger0c817332010-12-08 11:12:31 -0600438
439void rtl_deinit_rfkill(struct ieee80211_hw *hw)
440{
441 wiphy_rfkill_stop_polling(hw->wiphy);
442}
443
444int rtl_init_core(struct ieee80211_hw *hw)
445{
446 struct rtl_priv *rtlpriv = rtl_priv(hw);
447 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
448
449 /* <1> init mac80211 */
450 _rtl_init_mac80211(hw);
451 rtlmac->hw = hw;
452
453 /* <2> rate control register */
Chaoming Li375ff4c2011-02-28 16:40:28 -0600454 hw->rate_control_algorithm = "rtl_rc";
Larry Finger0c817332010-12-08 11:12:31 -0600455
456 /*
457 * <3> init CRDA must come after init
458 * mac80211 hw in _rtl_init_mac80211.
459 */
460 if (rtl_regd_init(hw, rtl_reg_notifier)) {
Joe Perchesf30d7502012-01-04 19:40:41 -0800461 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n");
Larry Finger0c817332010-12-08 11:12:31 -0600462 return 1;
Larry Finger0c817332010-12-08 11:12:31 -0600463 }
464
465 /* <4> locks */
Larry Finger8a09d6d2010-12-16 11:13:57 -0600466 mutex_init(&rtlpriv->locks.conf_mutex);
Stanislaw Gruszka65393062011-12-12 12:43:24 +0100467 mutex_init(&rtlpriv->locks.ps_mutex);
Larry Fingerb9116b9a2011-12-16 21:17:16 -0600468 spin_lock_init(&rtlpriv->locks.ips_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600469 spin_lock_init(&rtlpriv->locks.irq_th_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500470 spin_lock_init(&rtlpriv->locks.irq_pci_lock);
471 spin_lock_init(&rtlpriv->locks.tx_lock);
Larry Finger0c817332010-12-08 11:12:31 -0600472 spin_lock_init(&rtlpriv->locks.h2c_lock);
473 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
474 spin_lock_init(&rtlpriv->locks.rf_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500475 spin_lock_init(&rtlpriv->locks.waitq_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500476 spin_lock_init(&rtlpriv->locks.entry_list_lock);
Larry Fingere6deaf82013-03-24 22:06:55 -0500477 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
Chaoming_Liacd48572011-04-25 12:52:54 -0500478 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
Larry Finger26634c42013-03-24 22:06:33 -0500479 spin_lock_init(&rtlpriv->locks.check_sendpkt_lock);
480 spin_lock_init(&rtlpriv->locks.fw_ps_lock);
481 spin_lock_init(&rtlpriv->locks.lps_lock);
482
483 /* <5> init list */
484 INIT_LIST_HEAD(&rtlpriv->entry_list);
Larry Finger0c817332010-12-08 11:12:31 -0600485
486 rtlmac->link_state = MAC80211_NOLINK;
487
Larry Finger26634c42013-03-24 22:06:33 -0500488 /* <6> init deferred work */
Larry Finger0c817332010-12-08 11:12:31 -0600489 _rtl_init_deferred_work(hw);
490
491 return 0;
492}
493
494void rtl_deinit_core(struct ieee80211_hw *hw)
495{
Larry Finger0c817332010-12-08 11:12:31 -0600496}
497
498void rtl_init_rx_config(struct ieee80211_hw *hw)
499{
500 struct rtl_priv *rtlpriv = rtl_priv(hw);
501 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
502
503 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
Larry Finger0c817332010-12-08 11:12:31 -0600504}
505
506/*********************************************************
507 *
508 * tx information functions
509 *
510 *********************************************************/
511static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
512 struct rtl_tcb_desc *tcb_desc,
513 struct ieee80211_tx_info *info)
514{
515 struct rtl_priv *rtlpriv = rtl_priv(hw);
516 u8 rate_flag = info->control.rates[0].flags;
517
518 tcb_desc->use_shortpreamble = false;
519
520 /* 1M can only use Long Preamble. 11B spec */
521 if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M])
522 return;
523 else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
524 tcb_desc->use_shortpreamble = true;
525
526 return;
527}
528
529static void _rtl_query_shortgi(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500530 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600531 struct rtl_tcb_desc *tcb_desc,
532 struct ieee80211_tx_info *info)
533{
534 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
535 u8 rate_flag = info->control.rates[0].flags;
Chaoming_Liacd48572011-04-25 12:52:54 -0500536 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600537 tcb_desc->use_shortgi = false;
538
Chaoming_Liacd48572011-04-25 12:52:54 -0500539 if (sta == NULL)
Larry Finger0c817332010-12-08 11:12:31 -0600540 return;
541
Chaoming_Liacd48572011-04-25 12:52:54 -0500542 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
543 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
544
545 if (!(sta->ht_cap.ht_supported))
Larry Finger0c817332010-12-08 11:12:31 -0600546 return;
547
Chaoming_Liacd48572011-04-25 12:52:54 -0500548 if (!sgi_40 && !sgi_20)
549 return;
550
551 if (mac->opmode == NL80211_IFTYPE_STATION)
552 bw_40 = mac->bw_40;
553 else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500554 mac->opmode == NL80211_IFTYPE_ADHOC ||
555 mac->opmode == NL80211_IFTYPE_MESH_POINT)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100556 bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
Chaoming_Liacd48572011-04-25 12:52:54 -0500557
Mike McCormacke10542c2011-06-20 10:47:51 +0900558 if (bw_40 && sgi_40)
Larry Finger0c817332010-12-08 11:12:31 -0600559 tcb_desc->use_shortgi = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500560 else if ((bw_40 == false) && sgi_20)
Larry Finger0c817332010-12-08 11:12:31 -0600561 tcb_desc->use_shortgi = true;
562
563 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
564 tcb_desc->use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600565}
566
567static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
568 struct rtl_tcb_desc *tcb_desc,
569 struct ieee80211_tx_info *info)
570{
571 struct rtl_priv *rtlpriv = rtl_priv(hw);
572 u8 rate_flag = info->control.rates[0].flags;
573
574 /* Common Settings */
Larry Finger7ea47242011-02-19 16:28:57 -0600575 tcb_desc->rts_stbc = false;
576 tcb_desc->cts_enable = false;
Larry Finger0c817332010-12-08 11:12:31 -0600577 tcb_desc->rts_sc = 0;
Larry Finger7ea47242011-02-19 16:28:57 -0600578 tcb_desc->rts_bw = false;
579 tcb_desc->rts_use_shortpreamble = false;
580 tcb_desc->rts_use_shortgi = false;
Larry Finger0c817332010-12-08 11:12:31 -0600581
582 if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) {
583 /* Use CTS-to-SELF in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600584 tcb_desc->rts_enable = true;
585 tcb_desc->cts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600586 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
587 } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) {
588 /* Use RTS-CTS in protection mode. */
Larry Finger7ea47242011-02-19 16:28:57 -0600589 tcb_desc->rts_enable = true;
Larry Finger0c817332010-12-08 11:12:31 -0600590 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
591 }
Larry Finger0c817332010-12-08 11:12:31 -0600592}
593
594static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500595 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600596 struct rtl_tcb_desc *tcb_desc)
597{
598 struct rtl_priv *rtlpriv = rtl_priv(hw);
599 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500600 struct rtl_sta_info *sta_entry = NULL;
601 u8 ratr_index = 7;
Larry Finger0c817332010-12-08 11:12:31 -0600602
Chaoming_Liacd48572011-04-25 12:52:54 -0500603 if (sta) {
604 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
605 ratr_index = sta_entry->ratr_index;
606 }
Larry Finger0c817332010-12-08 11:12:31 -0600607 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500608 if (mac->opmode == NL80211_IFTYPE_STATION) {
Larry Finger0c817332010-12-08 11:12:31 -0600609 tcb_desc->ratr_index = 0;
Larry Finger26634c42013-03-24 22:06:33 -0500610 } else if (mac->opmode == NL80211_IFTYPE_ADHOC ||
611 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Larry Finger7ea47242011-02-19 16:28:57 -0600612 if (tcb_desc->multicast || tcb_desc->broadcast) {
Larry Finger0c817332010-12-08 11:12:31 -0600613 tcb_desc->hw_rate =
614 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
615 tcb_desc->use_driver_rate = 1;
Larry Finger26634c42013-03-24 22:06:33 -0500616 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600617 } else {
Larry Finger26634c42013-03-24 22:06:33 -0500618 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600619 }
Chaoming_Liacd48572011-04-25 12:52:54 -0500620 } else if (mac->opmode == NL80211_IFTYPE_AP) {
621 tcb_desc->ratr_index = ratr_index;
Larry Finger0c817332010-12-08 11:12:31 -0600622 }
623 }
624
Larry Finger7ea47242011-02-19 16:28:57 -0600625 if (rtlpriv->dm.useramask) {
Larry Finger26634c42013-03-24 22:06:33 -0500626 tcb_desc->ratr_index = ratr_index;
627 /* TODO we will differentiate adhoc and station future */
628 if (mac->opmode == NL80211_IFTYPE_STATION ||
629 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500630 tcb_desc->mac_id = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600631
Chaoming_Liacd48572011-04-25 12:52:54 -0500632 if (mac->mode == WIRELESS_MODE_N_24G)
633 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
634 else if (mac->mode == WIRELESS_MODE_N_5G)
635 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
636 else if (mac->mode & WIRELESS_MODE_G)
637 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
638 else if (mac->mode & WIRELESS_MODE_B)
639 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
640 else if (mac->mode & WIRELESS_MODE_A)
641 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
642 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500643 mac->opmode == NL80211_IFTYPE_ADHOC) {
Chaoming_Liacd48572011-04-25 12:52:54 -0500644 if (NULL != sta) {
645 if (sta->aid > 0)
646 tcb_desc->mac_id = sta->aid + 1;
647 else
648 tcb_desc->mac_id = 1;
649 } else {
650 tcb_desc->mac_id = 0;
651 }
Larry Finger0c817332010-12-08 11:12:31 -0600652 }
653 }
Larry Finger0c817332010-12-08 11:12:31 -0600654}
655
656static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -0500657 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600658 struct rtl_tcb_desc *tcb_desc)
659{
660 struct rtl_priv *rtlpriv = rtl_priv(hw);
661 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
662
Larry Finger7ea47242011-02-19 16:28:57 -0600663 tcb_desc->packet_bw = false;
Chaoming_Liacd48572011-04-25 12:52:54 -0500664 if (!sta)
Larry Finger0c817332010-12-08 11:12:31 -0600665 return;
Chaoming_Liacd48572011-04-25 12:52:54 -0500666 if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger26634c42013-03-24 22:06:33 -0500667 mac->opmode == NL80211_IFTYPE_ADHOC ||
668 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100669 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
Chaoming_Liacd48572011-04-25 12:52:54 -0500670 return;
671 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
672 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
673 return;
674 }
Larry Finger7ea47242011-02-19 16:28:57 -0600675 if (tcb_desc->multicast || tcb_desc->broadcast)
Larry Finger0c817332010-12-08 11:12:31 -0600676 return;
677
678 /*use legency rate, shall use 20MHz */
679 if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M])
680 return;
681
Larry Finger7ea47242011-02-19 16:28:57 -0600682 tcb_desc->packet_bw = true;
Larry Finger0c817332010-12-08 11:12:31 -0600683}
684
685static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
686{
687 struct rtl_priv *rtlpriv = rtl_priv(hw);
688 struct rtl_phy *rtlphy = &(rtlpriv->phy);
689 u8 hw_rate;
690
691 if (get_rf_type(rtlphy) == RF_2T2R)
692 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15];
693 else
694 hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7];
695
696 return hw_rate;
697}
698
Larry Finger7ad0ce32011-08-22 16:50:14 -0500699/* mac80211's rate_idx is like this:
700 *
701 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
702 *
703 * B/G rate:
704 * (rx_status->flag & RX_FLAG_HT) = 0,
705 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
706 *
707 * N rate:
708 * (rx_status->flag & RX_FLAG_HT) = 1,
709 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
710 *
711 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
712 * A rate:
713 * (rx_status->flag & RX_FLAG_HT) = 0,
714 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
715 *
716 * N rate:
717 * (rx_status->flag & RX_FLAG_HT) = 1,
718 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
719 */
720int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
721 bool isht, u8 desc_rate, bool first_ampdu)
722{
723 int rate_idx;
724
725 if (false == isht) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100726 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
Larry Finger7ad0ce32011-08-22 16:50:14 -0500727 switch (desc_rate) {
728 case DESC92_RATE1M:
729 rate_idx = 0;
730 break;
731 case DESC92_RATE2M:
732 rate_idx = 1;
733 break;
734 case DESC92_RATE5_5M:
735 rate_idx = 2;
736 break;
737 case DESC92_RATE11M:
738 rate_idx = 3;
739 break;
740 case DESC92_RATE6M:
741 rate_idx = 4;
742 break;
743 case DESC92_RATE9M:
744 rate_idx = 5;
745 break;
746 case DESC92_RATE12M:
747 rate_idx = 6;
748 break;
749 case DESC92_RATE18M:
750 rate_idx = 7;
751 break;
752 case DESC92_RATE24M:
753 rate_idx = 8;
754 break;
755 case DESC92_RATE36M:
756 rate_idx = 9;
757 break;
758 case DESC92_RATE48M:
759 rate_idx = 10;
760 break;
761 case DESC92_RATE54M:
762 rate_idx = 11;
763 break;
764 default:
765 rate_idx = 0;
766 break;
767 }
768 } else {
769 switch (desc_rate) {
770 case DESC92_RATE6M:
771 rate_idx = 0;
772 break;
773 case DESC92_RATE9M:
774 rate_idx = 1;
775 break;
776 case DESC92_RATE12M:
777 rate_idx = 2;
778 break;
779 case DESC92_RATE18M:
780 rate_idx = 3;
781 break;
782 case DESC92_RATE24M:
783 rate_idx = 4;
784 break;
785 case DESC92_RATE36M:
786 rate_idx = 5;
787 break;
788 case DESC92_RATE48M:
789 rate_idx = 6;
790 break;
791 case DESC92_RATE54M:
792 rate_idx = 7;
793 break;
794 default:
795 rate_idx = 0;
796 break;
797 }
798 }
799
800 } else {
801
802 switch (desc_rate) {
803 case DESC92_RATEMCS0:
804 rate_idx = 0;
805 break;
806 case DESC92_RATEMCS1:
807 rate_idx = 1;
808 break;
809 case DESC92_RATEMCS2:
810 rate_idx = 2;
811 break;
812 case DESC92_RATEMCS3:
813 rate_idx = 3;
814 break;
815 case DESC92_RATEMCS4:
816 rate_idx = 4;
817 break;
818 case DESC92_RATEMCS5:
819 rate_idx = 5;
820 break;
821 case DESC92_RATEMCS6:
822 rate_idx = 6;
823 break;
824 case DESC92_RATEMCS7:
825 rate_idx = 7;
826 break;
827 case DESC92_RATEMCS8:
828 rate_idx = 8;
829 break;
830 case DESC92_RATEMCS9:
831 rate_idx = 9;
832 break;
833 case DESC92_RATEMCS10:
834 rate_idx = 10;
835 break;
836 case DESC92_RATEMCS11:
837 rate_idx = 11;
838 break;
839 case DESC92_RATEMCS12:
840 rate_idx = 12;
841 break;
842 case DESC92_RATEMCS13:
843 rate_idx = 13;
844 break;
845 case DESC92_RATEMCS14:
846 rate_idx = 14;
847 break;
848 case DESC92_RATEMCS15:
849 rate_idx = 15;
850 break;
851 default:
852 rate_idx = 0;
853 break;
854 }
855 }
856 return rate_idx;
857}
858EXPORT_SYMBOL(rtlwifi_rate_mapping);
859
Larry Finger0f015452012-10-25 13:46:46 -0500860bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
861{
862 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
863 struct rtl_priv *rtlpriv = rtl_priv(hw);
864 __le16 fc = rtl_get_fc(skb);
865
866 if (rtlpriv->dm.supp_phymode_switch &&
867 mac->link_state < MAC80211_LINKED &&
868 (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) {
Larry Finger26634c42013-03-24 22:06:33 -0500869 if (rtlpriv->cfg->ops->chk_switch_dmdp)
870 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
Larry Finger0f015452012-10-25 13:46:46 -0500871 }
872 if (ieee80211_is_auth(fc)) {
873 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n");
874 rtl_ips_nic_on(hw);
875
876 mac->link_state = MAC80211_LINKING;
877 /* Dual mac */
878 rtlpriv->phy.need_iqk = true;
879 }
880
881 return true;
882}
883
Larry Finger0c817332010-12-08 11:12:31 -0600884void rtl_get_tcb_desc(struct ieee80211_hw *hw,
885 struct ieee80211_tx_info *info,
Chaoming_Liacd48572011-04-25 12:52:54 -0500886 struct ieee80211_sta *sta,
Larry Finger0c817332010-12-08 11:12:31 -0600887 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
888{
889 struct rtl_priv *rtlpriv = rtl_priv(hw);
890 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -0500891 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -0600892 struct ieee80211_rate *txrate;
Larry Finger17c9ac62011-02-19 16:29:57 -0600893 __le16 fc = hdr->frame_control;
Larry Finger0c817332010-12-08 11:12:31 -0600894
Chaoming_Liacd48572011-04-25 12:52:54 -0500895 txrate = ieee80211_get_tx_rate(hw, info);
Larry Fingere89f7692012-04-06 16:54:17 -0500896 if (txrate)
897 tcb_desc->hw_rate = txrate->hw_value;
898 else
899 tcb_desc->hw_rate = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600900
901 if (ieee80211_is_data(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600902 /*
Chaoming_Liacd48572011-04-25 12:52:54 -0500903 *we set data rate INX 0
Larry Finger0c817332010-12-08 11:12:31 -0600904 *in rtl_rc.c if skb is special data or
905 *mgt which need low data rate.
906 */
907
908 /*
909 *So tcb_desc->hw_rate is just used for
910 *special data and mgt frames
911 */
Chaoming Li09e92f02011-10-11 21:28:48 -0500912 if (info->control.rates[0].idx == 0 ||
Chaoming_Liacd48572011-04-25 12:52:54 -0500913 ieee80211_is_nullfunc(fc)) {
Larry Finger0c817332010-12-08 11:12:31 -0600914 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500915 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600916
Larry Finger0c817332010-12-08 11:12:31 -0600917 tcb_desc->disable_ratefallback = 1;
918 } else {
919 /*
920 *because hw will nerver use hw_rate
921 *when tcb_desc->use_driver_rate = false
922 *so we never set highest N rate here,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300923 *and N rate will all be controlled by FW
Larry Finger0c817332010-12-08 11:12:31 -0600924 *when tcb_desc->use_driver_rate = false
925 */
Chaoming_Liacd48572011-04-25 12:52:54 -0500926 if (sta && (sta->ht_cap.ht_supported)) {
Larry Finger0c817332010-12-08 11:12:31 -0600927 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
928 } else {
929 if (rtlmac->mode == WIRELESS_MODE_B) {
930 tcb_desc->hw_rate =
931 rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M];
932 } else {
933 tcb_desc->hw_rate =
934 rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M];
935 }
936 }
937 }
938
939 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600940 tcb_desc->multicast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600941 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
Larry Finger7ea47242011-02-19 16:28:57 -0600942 tcb_desc->broadcast = 1;
Larry Finger0c817332010-12-08 11:12:31 -0600943
Chaoming_Liacd48572011-04-25 12:52:54 -0500944 _rtl_txrate_selectmode(hw, sta, tcb_desc);
945 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600946 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
Chaoming_Liacd48572011-04-25 12:52:54 -0500947 _rtl_query_shortgi(hw, sta, tcb_desc, info);
Larry Finger0c817332010-12-08 11:12:31 -0600948 _rtl_query_protection_mode(hw, tcb_desc, info);
949 } else {
950 tcb_desc->use_driver_rate = true;
Chaoming_Liacd48572011-04-25 12:52:54 -0500951 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
Larry Finger0c817332010-12-08 11:12:31 -0600952 tcb_desc->disable_ratefallback = 1;
953 tcb_desc->mac_id = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -0500954 tcb_desc->packet_bw = false;
Larry Finger0c817332010-12-08 11:12:31 -0600955 }
956}
957EXPORT_SYMBOL(rtl_get_tcb_desc);
958
Larry Finger26634c42013-03-24 22:06:33 -0500959static bool addbareq_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
960{
961 struct rtl_priv *rtlpriv = rtl_priv(hw);
962 struct ieee80211_sta *sta = NULL;
963 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
964 struct rtl_sta_info *sta_entry = NULL;
965 struct ieee80211_mgmt *mgmt = (void *)skb->data;
966 u16 capab = 0, tid = 0;
967 struct rtl_tid_data *tid_data;
968 struct sk_buff *skb_delba = NULL;
969 struct ieee80211_rx_status rx_status = { 0 };
970
971 rcu_read_lock();
972 sta = rtl_find_sta(hw, hdr->addr3);
973 if (sta == NULL) {
974 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_EMERG,
975 "sta is NULL\n");
976 rcu_read_unlock();
977 return true;
978 }
979
980 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
981 if (!sta_entry) {
982 rcu_read_unlock();
983 return true;
984 }
985 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
986 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
987 tid_data = &sta_entry->tids[tid];
988 if (tid_data->agg.rx_agg_state == RTL_RX_AGG_START) {
989 skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid);
990 if (skb_delba) {
John W. Linville655d8e22013-04-10 14:09:54 -0400991 rx_status.freq = hw->conf.chandef.chan->center_freq;
992 rx_status.band = hw->conf.chandef.chan->band;
Larry Finger26634c42013-03-24 22:06:33 -0500993 rx_status.flag |= RX_FLAG_DECRYPTED;
994 rx_status.flag |= RX_FLAG_MACTIME_END;
995 rx_status.rate_idx = 0;
996 rx_status.signal = 50 + 10;
997 memcpy(IEEE80211_SKB_RXCB(skb_delba), &rx_status,
998 sizeof(rx_status));
999 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG,
1000 "fake del\n", skb_delba->data,
1001 skb_delba->len);
1002 ieee80211_rx_irqsafe(hw, skb_delba);
1003 }
1004 }
1005 rcu_read_unlock();
1006 return false;
1007}
1008
Larry Finger0c817332010-12-08 11:12:31 -06001009bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1010{
1011 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001012 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001013 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger17c9ac62011-02-19 16:29:57 -06001014 __le16 fc = hdr->frame_control;
Joe Perches2c208892012-06-04 12:44:17 +00001015 u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN;
Larry Finger0c817332010-12-08 11:12:31 -06001016 u8 category;
1017
1018 if (!ieee80211_is_action(fc))
1019 return true;
1020
1021 category = *act;
1022 act++;
1023 switch (category) {
1024 case ACT_CAT_BA:
1025 switch (*act) {
1026 case ACT_ADDBAREQ:
1027 if (mac->act_scanning)
1028 return false;
1029
1030 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001031 "%s ACT_ADDBAREQ From :%pM\n",
1032 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger26634c42013-03-24 22:06:33 -05001033 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n",
1034 skb->data, skb->len);
1035 if (!is_tx)
1036 if (addbareq_rx(hw, skb))
1037 return true;
Larry Finger0c817332010-12-08 11:12:31 -06001038 break;
1039 case ACT_ADDBARSP:
1040 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001041 "%s ACT_ADDBARSP From :%pM\n",
1042 is_tx ? "Tx" : "Rx", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001043 break;
1044 case ACT_DELBA:
1045 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001046 "ACT_ADDBADEL From :%pM\n", hdr->addr2);
Larry Finger0c817332010-12-08 11:12:31 -06001047 break;
1048 }
1049 break;
1050 default:
1051 break;
1052 }
1053
1054 return true;
1055}
1056
1057/*should call before software enc*/
1058u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
1059{
1060 struct rtl_priv *rtlpriv = rtl_priv(hw);
Larry Finger0c817332010-12-08 11:12:31 -06001061 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001062 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -06001063 u16 ether_type;
1064 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
1065 const struct iphdr *ip;
1066
1067 if (!ieee80211_is_data(fc))
Larry Finger32473282011-03-27 16:19:57 -05001068 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001069
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001070 ip = (const struct iphdr *)(skb->data + mac_hdr_len +
1071 SNAP_SIZE + PROTOC_TYPE_SIZE);
1072 ether_type = be16_to_cpup((__be16 *)
1073 (skb->data + mac_hdr_len + SNAP_SIZE));
Larry Finger0c817332010-12-08 11:12:31 -06001074
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001075 switch (ether_type) {
1076 case ETH_P_IP: {
1077 struct udphdr *udp;
1078 u16 src;
1079 u16 dst;
Larry Finger0c817332010-12-08 11:12:31 -06001080
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001081 if (ip->protocol != IPPROTO_UDP)
1082 return false;
1083 udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
1084 src = be16_to_cpu(udp->source);
1085 dst = be16_to_cpu(udp->dest);
Larry Finger0c817332010-12-08 11:12:31 -06001086
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001087 /* If this case involves port 68 (UDP BOOTP client) connecting
1088 * with port 67 (UDP BOOTP server), then return true so that
1089 * the lowest speed is used.
1090 */
1091 if (!((src == 68 && dst == 67) || (src == 67 && dst == 68)))
1092 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001093
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001094 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
1095 "dhcp %s !!\n", is_tx ? "Tx" : "Rx");
1096 break;
1097 }
1098 case ETH_P_ARP:
1099 break;
1100 case ETH_P_PAE:
Larry Finger0c817332010-12-08 11:12:31 -06001101 RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG,
Joe Perchesf30d7502012-01-04 19:40:41 -08001102 "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx");
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001103 break;
1104 case ETH_P_IPV6:
1105 /* TODO: Is this right? */
1106 return false;
1107 default:
1108 return false;
Larry Finger0c817332010-12-08 11:12:31 -06001109 }
Mark Cave-Aylanddea4a822013-11-02 14:28:35 -05001110 if (is_tx) {
1111 rtlpriv->enter_ps = false;
1112 schedule_work(&rtlpriv->works.lps_change_work);
1113 ppsc->last_delaylps_stamp_jiffies = jiffies;
1114 }
1115 return true;
Larry Finger0c817332010-12-08 11:12:31 -06001116}
1117
1118/*********************************************************
1119 *
1120 * functions called by core.c
1121 *
1122 *********************************************************/
Chaoming_Liacd48572011-04-25 12:52:54 -05001123int rtl_tx_agg_start(struct ieee80211_hw *hw,
1124 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Larry Finger0c817332010-12-08 11:12:31 -06001125{
1126 struct rtl_priv *rtlpriv = rtl_priv(hw);
1127 struct rtl_tid_data *tid_data;
1128 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001129 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001130
Chaoming_Liacd48572011-04-25 12:52:54 -05001131 if (sta == NULL)
1132 return -EINVAL;
Larry Finger0c817332010-12-08 11:12:31 -06001133
1134 if (unlikely(tid >= MAX_TID_COUNT))
1135 return -EINVAL;
1136
Chaoming_Liacd48572011-04-25 12:52:54 -05001137 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1138 if (!sta_entry)
Larry Finger0c817332010-12-08 11:12:31 -06001139 return -ENXIO;
Chaoming_Liacd48572011-04-25 12:52:54 -05001140 tid_data = &sta_entry->tids[tid];
Larry Finger0c817332010-12-08 11:12:31 -06001141
Joe Perchesf30d7502012-01-04 19:40:41 -08001142 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n",
1143 sta->addr, tid, tid_data->seq_number);
Larry Finger0c817332010-12-08 11:12:31 -06001144
Chaoming_Liacd48572011-04-25 12:52:54 -05001145 *ssn = tid_data->seq_number;
1146 tid_data->agg.agg_state = RTL_AGG_START;
1147
1148 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001149
1150 return 0;
1151}
1152
Chaoming_Liacd48572011-04-25 12:52:54 -05001153int rtl_tx_agg_stop(struct ieee80211_hw *hw,
1154 struct ieee80211_sta *sta, u16 tid)
Larry Finger0c817332010-12-08 11:12:31 -06001155{
Larry Finger0c817332010-12-08 11:12:31 -06001156 struct rtl_priv *rtlpriv = rtl_priv(hw);
1157 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Chaoming_Liacd48572011-04-25 12:52:54 -05001158 struct rtl_sta_info *sta_entry = NULL;
Larry Finger0c817332010-12-08 11:12:31 -06001159
Chaoming_Liacd48572011-04-25 12:52:54 -05001160 if (sta == NULL)
1161 return -EINVAL;
1162
1163 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001164 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Larry Finger0c817332010-12-08 11:12:31 -06001165 return -EINVAL;
1166 }
1167
Joe Perchesf30d7502012-01-04 19:40:41 -08001168 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1169 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001170
Larry Finger0c817332010-12-08 11:12:31 -06001171 if (unlikely(tid >= MAX_TID_COUNT))
1172 return -EINVAL;
1173
Chaoming_Liacd48572011-04-25 12:52:54 -05001174 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001175 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
Larry Finger0c817332010-12-08 11:12:31 -06001176
Chaoming_Liacd48572011-04-25 12:52:54 -05001177 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
Larry Finger0c817332010-12-08 11:12:31 -06001178
Chaoming_Liacd48572011-04-25 12:52:54 -05001179 return 0;
1180}
Larry Finger0c817332010-12-08 11:12:31 -06001181
Larry Finger26634c42013-03-24 22:06:33 -05001182int rtl_rx_agg_start(struct ieee80211_hw *hw,
1183 struct ieee80211_sta *sta, u16 tid)
1184{
1185 struct rtl_priv *rtlpriv = rtl_priv(hw);
1186 struct rtl_tid_data *tid_data;
1187 struct rtl_sta_info *sta_entry = NULL;
1188
1189 if (sta == NULL)
1190 return -EINVAL;
1191
1192 if (unlikely(tid >= MAX_TID_COUNT))
1193 return -EINVAL;
1194
1195 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1196 if (!sta_entry)
1197 return -ENXIO;
1198 tid_data = &sta_entry->tids[tid];
1199
1200 RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG,
1201 "on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
1202 tid_data->seq_number);
1203
1204 tid_data->agg.rx_agg_state = RTL_RX_AGG_START;
1205 return 0;
1206}
1207
1208int rtl_rx_agg_stop(struct ieee80211_hw *hw,
1209 struct ieee80211_sta *sta, u16 tid)
1210{
1211 struct rtl_priv *rtlpriv = rtl_priv(hw);
1212 struct rtl_sta_info *sta_entry = NULL;
1213
1214 if (sta == NULL)
1215 return -EINVAL;
1216
1217 if (!sta->addr) {
1218 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
1219 return -EINVAL;
1220 }
1221
1222 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
1223 "on ra = %pM tid = %d\n", sta->addr, tid);
1224
1225 if (unlikely(tid >= MAX_TID_COUNT))
1226 return -EINVAL;
1227
1228 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1229 sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP;
1230
1231 return 0;
1232}
1233
Chaoming_Liacd48572011-04-25 12:52:54 -05001234int rtl_tx_agg_oper(struct ieee80211_hw *hw,
1235 struct ieee80211_sta *sta, u16 tid)
1236{
1237 struct rtl_priv *rtlpriv = rtl_priv(hw);
Chaoming_Liacd48572011-04-25 12:52:54 -05001238 struct rtl_sta_info *sta_entry = NULL;
1239
1240 if (sta == NULL)
1241 return -EINVAL;
1242
1243 if (!sta->addr) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001244 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001245 return -EINVAL;
1246 }
1247
Joe Perchesf30d7502012-01-04 19:40:41 -08001248 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n",
1249 sta->addr, tid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001250
1251 if (unlikely(tid >= MAX_TID_COUNT))
1252 return -EINVAL;
1253
1254 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
Chaoming_Liacd48572011-04-25 12:52:54 -05001255 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
Larry Finger0c817332010-12-08 11:12:31 -06001256
1257 return 0;
1258}
1259
1260/*********************************************************
1261 *
1262 * wq & timer callback functions
1263 *
1264 *********************************************************/
Larry Finger26634c42013-03-24 22:06:33 -05001265/* this function is used for roaming */
1266void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb)
1267{
1268 struct rtl_priv *rtlpriv = rtl_priv(hw);
1269 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1270
1271 if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION)
1272 return;
1273
1274 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1275 return;
1276
1277 /* check if this really is a beacon */
1278 if (!ieee80211_is_beacon(hdr->frame_control) &&
1279 !ieee80211_is_probe_resp(hdr->frame_control))
1280 return;
1281
1282 /* min. beacon length + FCS_LEN */
1283 if (skb->len <= 40 + FCS_LEN)
1284 return;
1285
1286 /* and only beacons from the associated BSSID, please */
1287 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
1288 return;
1289
1290 rtlpriv->link_info.bcn_rx_inperiod++;
1291}
1292
Larry Finger0c817332010-12-08 11:12:31 -06001293void rtl_watchdog_wq_callback(void *data)
1294{
1295 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
1296 struct rtl_works,
1297 watchdog_wq);
1298 struct ieee80211_hw *hw = rtlworks->hw;
1299 struct rtl_priv *rtlpriv = rtl_priv(hw);
1300 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1301 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -06001302 bool busytraffic = false;
Larry Finger26634c42013-03-24 22:06:33 -05001303 bool tx_busy_traffic = false;
1304 bool rx_busy_traffic = false;
Larry Finger7ea47242011-02-19 16:28:57 -06001305 bool higher_busytraffic = false;
1306 bool higher_busyrxtraffic = false;
Chaoming_Liacd48572011-04-25 12:52:54 -05001307 u8 idx, tid;
Larry Finger0c817332010-12-08 11:12:31 -06001308 u32 rx_cnt_inp4eriod = 0;
1309 u32 tx_cnt_inp4eriod = 0;
1310 u32 aver_rx_cnt_inperiod = 0;
1311 u32 aver_tx_cnt_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001312 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
1313 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
Larry Finger0c817332010-12-08 11:12:31 -06001314
1315 if (is_hal_stop(rtlhal))
1316 return;
1317
1318 /* <1> Determine if action frame is allowed */
1319 if (mac->link_state > MAC80211_NOLINK) {
1320 if (mac->cnt_after_linked < 20)
1321 mac->cnt_after_linked++;
1322 } else {
1323 mac->cnt_after_linked = 0;
1324 }
1325
Larry Finger0c817332010-12-08 11:12:31 -06001326 /*
Chaoming Li09e92f02011-10-11 21:28:48 -05001327 *<2> to check if traffic busy, if
Larry Finger0c817332010-12-08 11:12:31 -06001328 * busytraffic we don't change channel
1329 */
1330 if (mac->link_state >= MAC80211_LINKED) {
1331
1332 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1333 for (idx = 0; idx <= 2; idx++) {
1334 rtlpriv->link_info.num_rx_in4period[idx] =
1335 rtlpriv->link_info.num_rx_in4period[idx + 1];
1336 rtlpriv->link_info.num_tx_in4period[idx] =
1337 rtlpriv->link_info.num_tx_in4period[idx + 1];
1338 }
1339 rtlpriv->link_info.num_rx_in4period[3] =
1340 rtlpriv->link_info.num_rx_inperiod;
1341 rtlpriv->link_info.num_tx_in4period[3] =
1342 rtlpriv->link_info.num_tx_inperiod;
1343 for (idx = 0; idx <= 3; idx++) {
1344 rx_cnt_inp4eriod +=
1345 rtlpriv->link_info.num_rx_in4period[idx];
1346 tx_cnt_inp4eriod +=
1347 rtlpriv->link_info.num_tx_in4period[idx];
1348 }
1349 aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4;
1350 aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4;
1351
1352 /* (2) check traffic busy */
Larry Finger26634c42013-03-24 22:06:33 -05001353 if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) {
Larry Finger7ea47242011-02-19 16:28:57 -06001354 busytraffic = true;
Larry Finger26634c42013-03-24 22:06:33 -05001355 if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod)
1356 rx_busy_traffic = true;
1357 else
1358 tx_busy_traffic = false;
1359 }
Larry Finger0c817332010-12-08 11:12:31 -06001360
1361 /* Higher Tx/Rx data. */
1362 if (aver_rx_cnt_inperiod > 4000 ||
1363 aver_tx_cnt_inperiod > 4000) {
Larry Finger7ea47242011-02-19 16:28:57 -06001364 higher_busytraffic = true;
Larry Finger0c817332010-12-08 11:12:31 -06001365
1366 /* Extremely high Rx data. */
1367 if (aver_rx_cnt_inperiod > 5000)
Larry Finger7ea47242011-02-19 16:28:57 -06001368 higher_busyrxtraffic = true;
Chaoming_Liacd48572011-04-25 12:52:54 -05001369 }
1370
1371 /* check every tid's tx traffic */
1372 for (tid = 0; tid <= 7; tid++) {
1373 for (idx = 0; idx <= 2; idx++)
1374 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1375 rtlpriv->link_info.tidtx_in4period[tid]
1376 [idx + 1];
1377 rtlpriv->link_info.tidtx_in4period[tid][3] =
1378 rtlpriv->link_info.tidtx_inperiod[tid];
1379
1380 for (idx = 0; idx <= 3; idx++)
1381 tidtx_inp4eriod[tid] +=
1382 rtlpriv->link_info.tidtx_in4period[tid][idx];
1383 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1384 if (aver_tidtx_inperiod[tid] > 5000)
1385 rtlpriv->link_info.higher_busytxtraffic[tid] =
1386 true;
Larry Finger0c817332010-12-08 11:12:31 -06001387 else
Chaoming_Liacd48572011-04-25 12:52:54 -05001388 rtlpriv->link_info.higher_busytxtraffic[tid] =
1389 false;
Larry Finger0c817332010-12-08 11:12:31 -06001390 }
1391
1392 if (((rtlpriv->link_info.num_rx_inperiod +
1393 rtlpriv->link_info.num_tx_inperiod) > 8) ||
1394 (rtlpriv->link_info.num_rx_inperiod > 2))
Larry Fingera2699132013-03-24 22:06:41 -05001395 rtlpriv->enter_ps = true;
Larry Finger0c817332010-12-08 11:12:31 -06001396 else
Larry Fingera2699132013-03-24 22:06:41 -05001397 rtlpriv->enter_ps = false;
Larry Finger0c817332010-12-08 11:12:31 -06001398
1399 /* LeisurePS only work in infra mode. */
Larry Fingera2699132013-03-24 22:06:41 -05001400 schedule_work(&rtlpriv->works.lps_change_work);
Larry Finger0c817332010-12-08 11:12:31 -06001401 }
1402
1403 rtlpriv->link_info.num_rx_inperiod = 0;
1404 rtlpriv->link_info.num_tx_inperiod = 0;
Chaoming_Liacd48572011-04-25 12:52:54 -05001405 for (tid = 0; tid <= 7; tid++)
1406 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001407
Larry Finger7ea47242011-02-19 16:28:57 -06001408 rtlpriv->link_info.busytraffic = busytraffic;
1409 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
Larry Finger26634c42013-03-24 22:06:33 -05001410 rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic;
1411 rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic;
Larry Finger7ea47242011-02-19 16:28:57 -06001412 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
Larry Finger0c817332010-12-08 11:12:31 -06001413
Chaoming_Liacd48572011-04-25 12:52:54 -05001414 /* <3> DM */
1415 rtlpriv->cfg->ops->dm_watchdog(hw);
Larry Finger26634c42013-03-24 22:06:33 -05001416
1417 /* <4> roaming */
1418 if (mac->link_state == MAC80211_LINKED &&
1419 mac->opmode == NL80211_IFTYPE_STATION) {
1420 if ((rtlpriv->link_info.bcn_rx_inperiod +
1421 rtlpriv->link_info.num_rx_inperiod) == 0) {
1422 rtlpriv->link_info.roam_times++;
1423 RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
1424 "AP off for %d s\n",
1425 (rtlpriv->link_info.roam_times * 2));
1426
1427 /* if we can't recv beacon for 6s, we should
1428 * reconnect this AP
1429 */
1430 if (rtlpriv->link_info.roam_times >= 3) {
1431 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1432 "AP off, try to reconnect now\n");
1433 rtlpriv->link_info.roam_times = 0;
1434 ieee80211_connection_loss(rtlpriv->mac80211.vif);
1435 }
1436 } else {
1437 rtlpriv->link_info.roam_times = 0;
1438 }
1439 }
1440 rtlpriv->link_info.bcn_rx_inperiod = 0;
Larry Finger0c817332010-12-08 11:12:31 -06001441}
1442
1443void rtl_watch_dog_timer_callback(unsigned long data)
1444{
1445 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1446 struct rtl_priv *rtlpriv = rtl_priv(hw);
1447
1448 queue_delayed_work(rtlpriv->works.rtl_wq,
1449 &rtlpriv->works.watchdog_wq, 0);
1450
1451 mod_timer(&rtlpriv->works.watchdog_timer,
1452 jiffies + MSECS(RTL_WATCH_DOG_TIME));
1453}
1454
Larry Finger26634c42013-03-24 22:06:33 -05001455void rtl_fwevt_wq_callback(void *data)
1456{
1457 struct rtl_works *rtlworks =
1458 container_of_dwork_rtl(data, struct rtl_works, fwevt_wq);
1459 struct ieee80211_hw *hw = rtlworks->hw;
1460 struct rtl_priv *rtlpriv = rtl_priv(hw);
1461
1462 rtlpriv->cfg->ops->c2h_command_handle(hw);
1463}
1464
1465void rtl_easy_concurrent_retrytimer_callback(unsigned long data)
1466{
1467 struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
1468 struct rtl_priv *rtlpriv = rtl_priv(hw);
1469 struct rtl_priv *buddy_priv = rtlpriv->buddy_priv;
1470
1471 if (buddy_priv == NULL)
1472 return;
1473
1474 rtlpriv->cfg->ops->dualmac_easy_concurrent(hw);
1475}
1476
Larry Finger0c817332010-12-08 11:12:31 -06001477/*********************************************************
1478 *
Chaoming_Liacd48572011-04-25 12:52:54 -05001479 * frame process functions
1480 *
1481 *********************************************************/
1482u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1483{
1484 struct ieee80211_mgmt *mgmt = (void *)data;
1485 u8 *pos, *end;
1486
1487 pos = (u8 *)mgmt->u.beacon.variable;
1488 end = data + len;
1489 while (pos < end) {
1490 if (pos + 2 + pos[1] > end)
1491 return NULL;
1492
1493 if (pos[0] == ie)
1494 return pos;
1495
1496 pos += 2 + pos[1];
1497 }
1498 return NULL;
1499}
1500
1501/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1502/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
Larry Fingerd3bb1422011-04-25 13:23:20 -05001503static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
Chaoming_Liacd48572011-04-25 12:52:54 -05001504 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1505{
1506 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1507 struct sk_buff *skb;
1508 struct ieee80211_mgmt *action_frame;
1509
1510 /* 27 = header + category + action + smps mode */
1511 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1512 if (!skb)
1513 return NULL;
1514
1515 skb_reserve(skb, hw->extra_tx_headroom);
1516 action_frame = (void *)skb_put(skb, 27);
1517 memset(action_frame, 0, 27);
1518 memcpy(action_frame->da, da, ETH_ALEN);
1519 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1520 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1521 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1522 IEEE80211_STYPE_ACTION);
1523 action_frame->u.action.category = WLAN_CATEGORY_HT;
1524 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1525 switch (smps) {
1526 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1527 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1528 WARN_ON(1);
1529 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1530 action_frame->u.action.u.ht_smps.smps_control =
1531 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1532 break;
1533 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1534 action_frame->u.action.u.ht_smps.smps_control =
1535 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1536 break;
1537 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1538 action_frame->u.action.u.ht_smps.smps_control =
1539 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1540 break;
1541 }
1542
1543 return skb;
1544}
1545
1546int rtl_send_smps_action(struct ieee80211_hw *hw,
Larry Finger26634c42013-03-24 22:06:33 -05001547 struct ieee80211_sta *sta,
Chaoming_Liacd48572011-04-25 12:52:54 -05001548 enum ieee80211_smps_mode smps)
1549{
1550 struct rtl_priv *rtlpriv = rtl_priv(hw);
1551 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1552 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger26634c42013-03-24 22:06:33 -05001553 struct sk_buff *skb = NULL;
Chaoming_Liacd48572011-04-25 12:52:54 -05001554 struct rtl_tcb_desc tcb_desc;
Larry Finger26634c42013-03-24 22:06:33 -05001555 u8 bssid[ETH_ALEN] = {0};
1556
Chaoming_Liacd48572011-04-25 12:52:54 -05001557 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1558
1559 if (rtlpriv->mac80211.act_scanning)
1560 goto err_free;
1561
1562 if (!sta)
1563 goto err_free;
1564
1565 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1566 goto err_free;
1567
1568 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1569 goto err_free;
1570
Larry Finger26634c42013-03-24 22:06:33 -05001571 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP)
1572 memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN);
1573 else
1574 memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN);
1575
1576 skb = rtl_make_smps_action(hw, smps, sta->addr, bssid);
Chaoming_Liacd48572011-04-25 12:52:54 -05001577 /* this is a type = mgmt * stype = action frame */
1578 if (skb) {
1579 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1580 struct rtl_sta_info *sta_entry =
1581 (struct rtl_sta_info *) sta->drv_priv;
1582 sta_entry->mimo_ps = smps;
Chaoming_Liacd48572011-04-25 12:52:54 -05001583
1584 info->control.rates[0].idx = 0;
Karl Beldan675a0b02013-03-25 16:26:57 +01001585 info->band = hw->conf.chandef.chan->band;
Thomas Huehn36323f82012-07-23 21:33:42 +02001586 rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc);
Chaoming_Liacd48572011-04-25 12:52:54 -05001587 }
Larry Finger26634c42013-03-24 22:06:33 -05001588 return 1;
1589
Chaoming_Liacd48572011-04-25 12:52:54 -05001590err_free:
1591 return 0;
1592}
Larry Finger26634c42013-03-24 22:06:33 -05001593EXPORT_SYMBOL(rtl_send_smps_action);
1594
1595/* There seem to be issues in mac80211 regarding when del ba frames can be
1596 * received. As a work around, we make a fake del_ba if we receive a ba_req;
1597 * however, rx_agg was opened to let mac80211 release some ba related
1598 * resources. This del_ba is for tx only.
1599 */
1600struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw,
1601 u8 *sa, u8 *bssid, u16 tid)
1602{
1603 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1604 struct sk_buff *skb;
1605 struct ieee80211_mgmt *action_frame;
1606 u16 params;
1607
1608 /* 27 = header + category + action + smps mode */
1609 skb = dev_alloc_skb(34 + hw->extra_tx_headroom);
1610 if (!skb)
1611 return NULL;
1612
1613 skb_reserve(skb, hw->extra_tx_headroom);
1614 action_frame = (void *)skb_put(skb, 34);
1615 memset(action_frame, 0, 34);
1616 memcpy(action_frame->sa, sa, ETH_ALEN);
1617 memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN);
1618 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1619 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1620 IEEE80211_STYPE_ACTION);
1621 action_frame->u.action.category = WLAN_CATEGORY_BACK;
1622 action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
1623 params = (u16)(1 << 11); /* bit 11 initiator */
1624 params |= (u16)(tid << 12); /* bit 15:12 TID number */
1625
1626 action_frame->u.action.u.delba.params = cpu_to_le16(params);
1627 action_frame->u.action.u.delba.reason_code =
1628 cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT);
1629
1630 return skb;
1631}
Chaoming_Liacd48572011-04-25 12:52:54 -05001632
1633/*********************************************************
1634 *
1635 * IOT functions
1636 *
1637 *********************************************************/
1638static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1639 struct octet_string vendor_ie)
1640{
1641 struct rtl_priv *rtlpriv = rtl_priv(hw);
1642 bool matched = false;
1643 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1644 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1645 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1646 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1647 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1648 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1649 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1650 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1651
1652 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1653 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1654 rtlpriv->mac80211.vendor = PEER_ATH;
1655 matched = true;
1656 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1657 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1658 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1659 rtlpriv->mac80211.vendor = PEER_BROAD;
1660 matched = true;
1661 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1662 rtlpriv->mac80211.vendor = PEER_RAL;
1663 matched = true;
1664 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1665 rtlpriv->mac80211.vendor = PEER_CISCO;
1666 matched = true;
1667 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1668 rtlpriv->mac80211.vendor = PEER_MARV;
1669 matched = true;
1670 }
1671
1672 return matched;
1673}
1674
Larry Fingerd3bb1422011-04-25 13:23:20 -05001675static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
Chaoming_Liacd48572011-04-25 12:52:54 -05001676 unsigned int len)
1677{
1678 struct ieee80211_mgmt *mgmt = (void *)data;
1679 struct octet_string vendor_ie;
1680 u8 *pos, *end;
1681
1682 pos = (u8 *)mgmt->u.beacon.variable;
1683 end = data + len;
1684 while (pos < end) {
1685 if (pos[0] == 221) {
1686 vendor_ie.length = pos[1];
1687 vendor_ie.octet = &pos[2];
1688 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1689 return true;
1690 }
1691
1692 if (pos + 2 + pos[1] > end)
1693 return false;
1694
1695 pos += 2 + pos[1];
1696 }
1697 return false;
1698}
1699
1700void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1701{
1702 struct rtl_priv *rtlpriv = rtl_priv(hw);
1703 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1704 struct ieee80211_hdr *hdr = (void *)data;
1705 u32 vendor = PEER_UNKNOWN;
1706
1707 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1708 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1709 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1710 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1711 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1712 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1713 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1714 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1715 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1716 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1717 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1718 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1719 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1720 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1721 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1722 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1723
1724 if (mac->opmode != NL80211_IFTYPE_STATION)
1725 return;
1726
1727 if (mac->link_state == MAC80211_NOLINK) {
1728 mac->vendor = PEER_UNKNOWN;
1729 return;
1730 }
1731
1732 if (mac->cnt_after_linked > 2)
1733 return;
1734
1735 /* check if this really is a beacon */
1736 if (!ieee80211_is_beacon(hdr->frame_control))
1737 return;
1738
1739 /* min. beacon length + FCS_LEN */
1740 if (len <= 40 + FCS_LEN)
1741 return;
1742
1743 /* and only beacons from the associated BSSID, please */
Joe Perches2e42e472012-05-09 17:17:46 +00001744 if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid))
Chaoming_Liacd48572011-04-25 12:52:54 -05001745 return;
1746
1747 if (rtl_find_221_ie(hw, data, len))
1748 vendor = mac->vendor;
1749
1750 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1751 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1752 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1753 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1754 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1755 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1756 vendor == PEER_ATH) {
1757 vendor = PEER_ATH;
Joe Perchesf30d7502012-01-04 19:40:41 -08001758 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001759 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1760 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1761 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1762 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1763 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1764 vendor == PEER_RAL) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001765 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001766 vendor = PEER_RAL;
1767 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1768 vendor == PEER_CISCO) {
1769 vendor = PEER_CISCO;
Joe Perchesf30d7502012-01-04 19:40:41 -08001770 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001771 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1772 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1773 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1774 vendor == PEER_BROAD) {
Joe Perchesf30d7502012-01-04 19:40:41 -08001775 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001776 vendor = PEER_BROAD;
1777 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1778 vendor == PEER_MARV) {
1779 vendor = PEER_MARV;
Joe Perchesf30d7502012-01-04 19:40:41 -08001780 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001781 }
1782
1783 mac->vendor = vendor;
1784}
1785
1786/*********************************************************
1787 *
Larry Finger0c817332010-12-08 11:12:31 -06001788 * sysfs functions
1789 *
1790 *********************************************************/
1791static ssize_t rtl_show_debug_level(struct device *d,
1792 struct device_attribute *attr, char *buf)
1793{
1794 struct ieee80211_hw *hw = dev_get_drvdata(d);
1795 struct rtl_priv *rtlpriv = rtl_priv(hw);
1796
1797 return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel);
1798}
1799
1800static ssize_t rtl_store_debug_level(struct device *d,
1801 struct device_attribute *attr,
1802 const char *buf, size_t count)
1803{
1804 struct ieee80211_hw *hw = dev_get_drvdata(d);
1805 struct rtl_priv *rtlpriv = rtl_priv(hw);
1806 unsigned long val;
1807 int ret;
1808
1809 ret = strict_strtoul(buf, 0, &val);
1810 if (ret) {
1811 printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf);
1812 } else {
1813 rtlpriv->dbg.global_debuglevel = val;
1814 printk(KERN_DEBUG "debuglevel:%x\n",
1815 rtlpriv->dbg.global_debuglevel);
1816 }
1817
1818 return strnlen(buf, count);
1819}
1820
1821static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1822 rtl_show_debug_level, rtl_store_debug_level);
1823
1824static struct attribute *rtl_sysfs_entries[] = {
1825
1826 &dev_attr_debug_level.attr,
1827
1828 NULL
1829};
1830
1831/*
1832 * "name" is folder name witch will be
1833 * put in device directory like :
1834 * sys/devices/pci0000:00/0000:00:1c.4/
1835 * 0000:06:00.0/rtl_sysfs
1836 */
1837struct attribute_group rtl_attribute_group = {
1838 .name = "rtlsysfs",
1839 .attrs = rtl_sysfs_entries,
1840};
1841
1842MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1843MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1844MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1845MODULE_LICENSE("GPL");
1846MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1847
Larry Finger26634c42013-03-24 22:06:33 -05001848struct rtl_global_var global_var = {};
1849
Larry Finger0c817332010-12-08 11:12:31 -06001850static int __init rtl_core_module_init(void)
1851{
Chaoming Li375ff4c2011-02-28 16:40:28 -06001852 if (rtl_rate_control_register())
Joe Perches292b1192011-07-20 08:51:35 -07001853 pr_err("Unable to register rtl_rc, use default RC !!\n");
Chaoming_Liacd48572011-04-25 12:52:54 -05001854
Larry Finger26634c42013-03-24 22:06:33 -05001855 /* init some global vars */
1856 INIT_LIST_HEAD(&global_var.glb_priv_list);
1857 spin_lock_init(&global_var.glb_list_lock);
1858
Larry Finger0c817332010-12-08 11:12:31 -06001859 return 0;
1860}
1861
1862static void __exit rtl_core_module_exit(void)
1863{
Chaoming_Liacd48572011-04-25 12:52:54 -05001864 /*RC*/
Chaoming Li375ff4c2011-02-28 16:40:28 -06001865 rtl_rate_control_unregister();
Larry Finger0c817332010-12-08 11:12:31 -06001866}
1867
1868module_init(rtl_core_module_init);
1869module_exit(rtl_core_module_exit);