aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rtlwifi
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2011-05-05 13:32:35 -0400
committerJohn W. Linville <linville@tuxdriver.com>2011-05-05 13:32:35 -0400
commita70171dce9cd44cb06c7d299eba9fa87a8933045 (patch)
tree5425df5f33fadc617c7dec99578d06f0d933578e /drivers/net/wireless/rtlwifi
parent5a412ad7f4c95bb5b756aa12b52646e857e7c75d (diff)
parenteaef6a93bd52a2cc47b9fce201310010707afdb4 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6 into for-davem
Conflicts: drivers/net/wireless/libertas/if_cs.c drivers/net/wireless/rtlwifi/pci.c net/bluetooth/l2cap_sock.c
Diffstat (limited to 'drivers/net/wireless/rtlwifi')
-rw-r--r--drivers/net/wireless/rtlwifi/base.c720
-rw-r--r--drivers/net/wireless/rtlwifi/base.h60
-rw-r--r--drivers/net/wireless/rtlwifi/cam.c106
-rw-r--r--drivers/net/wireless/rtlwifi/cam.h5
-rw-r--r--drivers/net/wireless/rtlwifi/core.c408
-rw-r--r--drivers/net/wireless/rtlwifi/core.h1
-rw-r--r--drivers/net/wireless/rtlwifi/efuse.c97
-rw-r--r--drivers/net/wireless/rtlwifi/efuse.h5
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c626
-rw-r--r--drivers/net/wireless/rtlwifi/pci.h15
-rw-r--r--drivers/net/wireless/rtlwifi/ps.c258
-rw-r--r--drivers/net/wireless/rtlwifi/ps.h9
-rw-r--r--drivers/net/wireless/rtlwifi/rc.c212
-rw-r--r--drivers/net/wireless/rtlwifi/rc.h9
-rw-r--r--drivers/net/wireless/rtlwifi/regd.c97
-rw-r--r--drivers/net/wireless/rtlwifi/regd.h2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c523
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c81
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/fw_common.h4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c128
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h76
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/def.h27
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/dm.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/dm.h1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/hw.c509
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/hw.h34
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/led.c5
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/led.h2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/phy.c223
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/phy.h55
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/reg.h58
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/rf.c24
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/rf.h17
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/sw.c122
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/sw.h14
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/trx.c180
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/trx.h7
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/hw.c11
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/hw.h5
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/phy.c14
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/phy.h14
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/rf.c4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/rf.h4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/trx.c48
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/trx.h5
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c19
-rw-r--r--drivers/net/wireless/rtlwifi/usb.h2
-rw-r--r--drivers/net/wireless/rtlwifi/wifi.h155
50 files changed, 3420 insertions, 1587 deletions
diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
index b259f807ad27..ccb6da38fe22 100644
--- a/drivers/net/wireless/rtlwifi/base.c
+++ b/drivers/net/wireless/rtlwifi/base.c
@@ -50,8 +50,9 @@
50 *3) functions called by core.c 50 *3) functions called by core.c
51 *4) wq & timer callback functions 51 *4) wq & timer callback functions
52 *5) frame process functions 52 *5) frame process functions
53 *6) sysfs functions 53 *6) IOT functions
54 *7) ... 54 *7) sysfs functions
55 *8) ...
55 */ 56 */
56 57
57/********************************************************* 58/*********************************************************
@@ -59,7 +60,7 @@
59 * mac80211 init functions 60 * mac80211 init functions
60 * 61 *
61 *********************************************************/ 62 *********************************************************/
62static struct ieee80211_channel rtl_channeltable[] = { 63static struct ieee80211_channel rtl_channeltable_2g[] = {
63 {.center_freq = 2412, .hw_value = 1,}, 64 {.center_freq = 2412, .hw_value = 1,},
64 {.center_freq = 2417, .hw_value = 2,}, 65 {.center_freq = 2417, .hw_value = 2,},
65 {.center_freq = 2422, .hw_value = 3,}, 66 {.center_freq = 2422, .hw_value = 3,},
@@ -76,7 +77,34 @@ static struct ieee80211_channel rtl_channeltable[] = {
76 {.center_freq = 2484, .hw_value = 14,}, 77 {.center_freq = 2484, .hw_value = 14,},
77}; 78};
78 79
79static struct ieee80211_rate rtl_ratetable[] = { 80static struct ieee80211_channel rtl_channeltable_5g[] = {
81 {.center_freq = 5180, .hw_value = 36,},
82 {.center_freq = 5200, .hw_value = 40,},
83 {.center_freq = 5220, .hw_value = 44,},
84 {.center_freq = 5240, .hw_value = 48,},
85 {.center_freq = 5260, .hw_value = 52,},
86 {.center_freq = 5280, .hw_value = 56,},
87 {.center_freq = 5300, .hw_value = 60,},
88 {.center_freq = 5320, .hw_value = 64,},
89 {.center_freq = 5500, .hw_value = 100,},
90 {.center_freq = 5520, .hw_value = 104,},
91 {.center_freq = 5540, .hw_value = 108,},
92 {.center_freq = 5560, .hw_value = 112,},
93 {.center_freq = 5580, .hw_value = 116,},
94 {.center_freq = 5600, .hw_value = 120,},
95 {.center_freq = 5620, .hw_value = 124,},
96 {.center_freq = 5640, .hw_value = 128,},
97 {.center_freq = 5660, .hw_value = 132,},
98 {.center_freq = 5680, .hw_value = 136,},
99 {.center_freq = 5700, .hw_value = 140,},
100 {.center_freq = 5745, .hw_value = 149,},
101 {.center_freq = 5765, .hw_value = 153,},
102 {.center_freq = 5785, .hw_value = 157,},
103 {.center_freq = 5805, .hw_value = 161,},
104 {.center_freq = 5825, .hw_value = 165,},
105};
106
107static struct ieee80211_rate rtl_ratetable_2g[] = {
80 {.bitrate = 10, .hw_value = 0x00,}, 108 {.bitrate = 10, .hw_value = 0x00,},
81 {.bitrate = 20, .hw_value = 0x01,}, 109 {.bitrate = 20, .hw_value = 0x01,},
82 {.bitrate = 55, .hw_value = 0x02,}, 110 {.bitrate = 55, .hw_value = 0x02,},
@@ -91,18 +119,57 @@ static struct ieee80211_rate rtl_ratetable[] = {
91 {.bitrate = 540, .hw_value = 0x0b,}, 119 {.bitrate = 540, .hw_value = 0x0b,},
92}; 120};
93 121
122static struct ieee80211_rate rtl_ratetable_5g[] = {
123 {.bitrate = 60, .hw_value = 0x04,},
124 {.bitrate = 90, .hw_value = 0x05,},
125 {.bitrate = 120, .hw_value = 0x06,},
126 {.bitrate = 180, .hw_value = 0x07,},
127 {.bitrate = 240, .hw_value = 0x08,},
128 {.bitrate = 360, .hw_value = 0x09,},
129 {.bitrate = 480, .hw_value = 0x0a,},
130 {.bitrate = 540, .hw_value = 0x0b,},
131};
132
94static const struct ieee80211_supported_band rtl_band_2ghz = { 133static const struct ieee80211_supported_band rtl_band_2ghz = {
95 .band = IEEE80211_BAND_2GHZ, 134 .band = IEEE80211_BAND_2GHZ,
96 135
97 .channels = rtl_channeltable, 136 .channels = rtl_channeltable_2g,
98 .n_channels = ARRAY_SIZE(rtl_channeltable), 137 .n_channels = ARRAY_SIZE(rtl_channeltable_2g),
138
139 .bitrates = rtl_ratetable_2g,
140 .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g),
141
142 .ht_cap = {0},
143};
144
145static struct ieee80211_supported_band rtl_band_5ghz = {
146 .band = IEEE80211_BAND_5GHZ,
147
148 .channels = rtl_channeltable_5g,
149 .n_channels = ARRAY_SIZE(rtl_channeltable_5g),
99 150
100 .bitrates = rtl_ratetable, 151 .bitrates = rtl_ratetable_5g,
101 .n_bitrates = ARRAY_SIZE(rtl_ratetable), 152 .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g),
102 153
103 .ht_cap = {0}, 154 .ht_cap = {0},
104}; 155};
105 156
157static const u8 tid_to_ac[] = {
158 2, /* IEEE80211_AC_BE */
159 3, /* IEEE80211_AC_BK */
160 3, /* IEEE80211_AC_BK */
161 2, /* IEEE80211_AC_BE */
162 1, /* IEEE80211_AC_VI */
163 1, /* IEEE80211_AC_VI */
164 0, /* IEEE80211_AC_VO */
165 0, /* IEEE80211_AC_VO */
166};
167
168u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid)
169{
170 return tid_to_ac[tid];
171}
172
106static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, 173static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
107 struct ieee80211_sta_ht_cap *ht_cap) 174 struct ieee80211_sta_ht_cap *ht_cap)
108{ 175{
@@ -115,6 +182,9 @@ static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
115 IEEE80211_HT_CAP_SGI_20 | 182 IEEE80211_HT_CAP_SGI_20 |
116 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; 183 IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU;
117 184
185 if (rtlpriv->rtlhal.disable_amsdu_8k)
186 ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU;
187
118 /* 188 /*
119 *Maximum length of AMPDU that the STA can receive. 189 *Maximum length of AMPDU that the STA can receive.
120 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) 190 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
@@ -159,37 +229,99 @@ static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
159 229
160static void _rtl_init_mac80211(struct ieee80211_hw *hw) 230static void _rtl_init_mac80211(struct ieee80211_hw *hw)
161{ 231{
232 struct rtl_priv *rtlpriv = rtl_priv(hw);
233 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
162 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 234 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
163 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 235 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
164 struct ieee80211_supported_band *sband; 236 struct ieee80211_supported_band *sband;
165 237
166 /* <1> use mac->bands as mem for hw->wiphy->bands */
167 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
168 238
169 /* 239 if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset ==
170 * <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] 240 BAND_ON_BOTH) {
171 * to default value(1T1R) 241 /* 1: 2.4 G bands */
172 */ 242 /* <1> use mac->bands as mem for hw->wiphy->bands */
173 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz, 243 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
174 sizeof(struct ieee80211_supported_band));
175 244
176 /* <3> init ht cap base on ant_num */ 245 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
177 _rtl_init_hw_ht_capab(hw, &sband->ht_cap); 246 * to default value(1T1R) */
247 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz,
248 sizeof(struct ieee80211_supported_band));
178 249
179 /* <4> set mac->sband to wiphy->sband */ 250 /* <3> init ht cap base on ant_num */
180 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; 251 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
181 252
253 /* <4> set mac->sband to wiphy->sband */
254 hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
255
256 /* 2: 5 G bands */
257 /* <1> use mac->bands as mem for hw->wiphy->bands */
258 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
259
260 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
261 * to default value(1T1R) */
262 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz,
263 sizeof(struct ieee80211_supported_band));
264
265 /* <3> init ht cap base on ant_num */
266 _rtl_init_hw_ht_capab(hw, &sband->ht_cap);
267
268 /* <4> set mac->sband to wiphy->sband */
269 hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
270 } else {
271 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
272 /* <1> use mac->bands as mem for hw->wiphy->bands */
273 sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]);
274
275 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
276 * to default value(1T1R) */
277 memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]),
278 &rtl_band_2ghz,
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_2GHZ] = sband;
286 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
287 /* <1> use mac->bands as mem for hw->wiphy->bands */
288 sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]);
289
290 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
291 * to default value(1T1R) */
292 memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]),
293 &rtl_band_5ghz,
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_5GHZ] = sband;
301 } else {
302 RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
303 ("Err BAND %d\n",
304 rtlhal->current_bandtype));
305 }
306 }
182 /* <5> set hw caps */ 307 /* <5> set hw caps */
183 hw->flags = IEEE80211_HW_SIGNAL_DBM | 308 hw->flags = IEEE80211_HW_SIGNAL_DBM |
184 IEEE80211_HW_RX_INCLUDES_FCS | 309 IEEE80211_HW_RX_INCLUDES_FCS |
185 IEEE80211_HW_BEACON_FILTER | IEEE80211_HW_AMPDU_AGGREGATION | /*PS*/ 310 IEEE80211_HW_BEACON_FILTER |
186 /*IEEE80211_HW_SUPPORTS_PS | */ 311 IEEE80211_HW_AMPDU_AGGREGATION |
187 /*IEEE80211_HW_PS_NULLFUNC_STACK | */
188 /*IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
189 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0; 312 IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0;
190 313
314 /* swlps or hwlps has been set in diff chip in init_sw_vars */
315 if (rtlpriv->psc.swctrl_lps)
316 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
317 IEEE80211_HW_PS_NULLFUNC_STACK |
318 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
319 0;
320
191 hw->wiphy->interface_modes = 321 hw->wiphy->interface_modes =
192 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC); 322 BIT(NL80211_IFTYPE_AP) |
323 BIT(NL80211_IFTYPE_STATION) |
324 BIT(NL80211_IFTYPE_ADHOC);
193 325
194 hw->wiphy->rts_threshold = 2347; 326 hw->wiphy->rts_threshold = 2347;
195 327
@@ -199,9 +331,10 @@ static void _rtl_init_mac80211(struct ieee80211_hw *hw)
199 /* TODO: Correct this value for our hw */ 331 /* TODO: Correct this value for our hw */
200 /* TODO: define these hard code value */ 332 /* TODO: define these hard code value */
201 hw->channel_change_time = 100; 333 hw->channel_change_time = 100;
202 hw->max_listen_interval = 5; 334 hw->max_listen_interval = 10;
203 hw->max_rate_tries = 4; 335 hw->max_rate_tries = 4;
204 /* hw->max_rates = 1; */ 336 /* hw->max_rates = 1; */
337 hw->sta_data_size = sizeof(struct rtl_sta_info);
205 338
206 /* <6> mac address */ 339 /* <6> mac address */
207 if (is_valid_ether_addr(rtlefuse->dev_addr)) { 340 if (is_valid_ether_addr(rtlefuse->dev_addr)) {
@@ -230,6 +363,10 @@ static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
230 (void *)rtl_watchdog_wq_callback); 363 (void *)rtl_watchdog_wq_callback);
231 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, 364 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
232 (void *)rtl_ips_nic_off_wq_callback); 365 (void *)rtl_ips_nic_off_wq_callback);
366 INIT_DELAYED_WORK(&rtlpriv->works.ps_work,
367 (void *)rtl_swlps_wq_callback);
368 INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq,
369 (void *)rtl_swlps_rfon_wq_callback);
233 370
234} 371}
235 372
@@ -241,6 +378,8 @@ void rtl_deinit_deferred_work(struct ieee80211_hw *hw)
241 378
242 cancel_delayed_work(&rtlpriv->works.watchdog_wq); 379 cancel_delayed_work(&rtlpriv->works.watchdog_wq);
243 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); 380 cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq);
381 cancel_delayed_work(&rtlpriv->works.ps_work);
382 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
244} 383}
245 384
246void rtl_init_rfkill(struct ieee80211_hw *hw) 385void rtl_init_rfkill(struct ieee80211_hw *hw)
@@ -310,6 +449,8 @@ int rtl_init_core(struct ieee80211_hw *hw)
310 spin_lock_init(&rtlpriv->locks.rf_ps_lock); 449 spin_lock_init(&rtlpriv->locks.rf_ps_lock);
311 spin_lock_init(&rtlpriv->locks.rf_lock); 450 spin_lock_init(&rtlpriv->locks.rf_lock);
312 spin_lock_init(&rtlpriv->locks.lps_lock); 451 spin_lock_init(&rtlpriv->locks.lps_lock);
452 spin_lock_init(&rtlpriv->locks.waitq_lock);
453 spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock);
313 454
314 rtlmac->link_state = MAC80211_NOLINK; 455 rtlmac->link_state = MAC80211_NOLINK;
315 456
@@ -329,12 +470,6 @@ void rtl_init_rx_config(struct ieee80211_hw *hw)
329 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 470 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
330 471
331 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); 472 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
332 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_MGT_FILTER,
333 (u8 *) (&mac->rx_mgt_filter));
334 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CTRL_FILTER,
335 (u8 *) (&mac->rx_ctrl_filter));
336 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_DATA_FILTER,
337 (u8 *) (&mac->rx_data_filter));
338} 473}
339 474
340/********************************************************* 475/*********************************************************
@@ -361,28 +496,40 @@ static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw,
361} 496}
362 497
363static void _rtl_query_shortgi(struct ieee80211_hw *hw, 498static void _rtl_query_shortgi(struct ieee80211_hw *hw,
499 struct ieee80211_sta *sta,
364 struct rtl_tcb_desc *tcb_desc, 500 struct rtl_tcb_desc *tcb_desc,
365 struct ieee80211_tx_info *info) 501 struct ieee80211_tx_info *info)
366{ 502{
367 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 503 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
368 u8 rate_flag = info->control.rates[0].flags; 504 u8 rate_flag = info->control.rates[0].flags;
369 505 u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0;
370 tcb_desc->use_shortgi = false; 506 tcb_desc->use_shortgi = false;
371 507
372 if (!mac->ht_enable) 508 if (sta == NULL)
373 return; 509 return;
374 510
375 if (!mac->sgi_40 && !mac->sgi_20) 511 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
512 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
513
514 if (!(sta->ht_cap.ht_supported))
515 return;
516
517 if (!sgi_40 && !sgi_20)
376 return; 518 return;
377 519
378 if ((mac->bw_40 == true) && mac->sgi_40) 520 if (mac->opmode == NL80211_IFTYPE_STATION)
521 bw_40 = mac->bw_40;
522 else if (mac->opmode == NL80211_IFTYPE_AP ||
523 mac->opmode == NL80211_IFTYPE_ADHOC)
524 bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40;
525
526 if ((bw_40 == true) && sgi_40)
379 tcb_desc->use_shortgi = true; 527 tcb_desc->use_shortgi = true;
380 else if ((mac->bw_40 == false) && mac->sgi_20) 528 else if ((bw_40 == false) && sgi_20)
381 tcb_desc->use_shortgi = true; 529 tcb_desc->use_shortgi = true;
382 530
383 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) 531 if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI))
384 tcb_desc->use_shortgi = false; 532 tcb_desc->use_shortgi = false;
385
386} 533}
387 534
388static void _rtl_query_protection_mode(struct ieee80211_hw *hw, 535static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
@@ -410,19 +557,25 @@ static void _rtl_query_protection_mode(struct ieee80211_hw *hw,
410 tcb_desc->rts_enable = true; 557 tcb_desc->rts_enable = true;
411 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; 558 tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M];
412 } 559 }
413
414} 560}
415 561
416static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, 562static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
563 struct ieee80211_sta *sta,
417 struct rtl_tcb_desc *tcb_desc) 564 struct rtl_tcb_desc *tcb_desc)
418{ 565{
419 struct rtl_priv *rtlpriv = rtl_priv(hw); 566 struct rtl_priv *rtlpriv = rtl_priv(hw);
420 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 567 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
568 struct rtl_sta_info *sta_entry = NULL;
569 u8 ratr_index = 7;
421 570
571 if (sta) {
572 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
573 ratr_index = sta_entry->ratr_index;
574 }
422 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { 575 if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) {
423 if (mac->opmode == NL80211_IFTYPE_STATION) 576 if (mac->opmode == NL80211_IFTYPE_STATION) {
424 tcb_desc->ratr_index = 0; 577 tcb_desc->ratr_index = 0;
425 else if (mac->opmode == NL80211_IFTYPE_ADHOC) { 578 } else if (mac->opmode == NL80211_IFTYPE_ADHOC) {
426 if (tcb_desc->multicast || tcb_desc->broadcast) { 579 if (tcb_desc->multicast || tcb_desc->broadcast) {
427 tcb_desc->hw_rate = 580 tcb_desc->hw_rate =
428 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; 581 rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M];
@@ -430,36 +583,61 @@ static void _rtl_txrate_selectmode(struct ieee80211_hw *hw,
430 } else { 583 } else {
431 /* TODO */ 584 /* TODO */
432 } 585 }
586 tcb_desc->ratr_index = ratr_index;
587 } else if (mac->opmode == NL80211_IFTYPE_AP) {
588 tcb_desc->ratr_index = ratr_index;
433 } 589 }
434 } 590 }
435 591
436 if (rtlpriv->dm.useramask) { 592 if (rtlpriv->dm.useramask) {
437 /* TODO adhoc and station handled differently in the future */ 593 /* TODO we will differentiate adhoc and station futrue */
438 tcb_desc->mac_id = 0; 594 if (mac->opmode == NL80211_IFTYPE_STATION) {
439 595 tcb_desc->mac_id = 0;
440 if ((mac->mode == WIRELESS_MODE_N_24G) || 596
441 (mac->mode == WIRELESS_MODE_N_5G)) { 597 if (mac->mode == WIRELESS_MODE_N_24G)
442 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; 598 tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB;
443 } else if (mac->mode & WIRELESS_MODE_G) { 599 else if (mac->mode == WIRELESS_MODE_N_5G)
444 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; 600 tcb_desc->ratr_index = RATR_INX_WIRELESS_NG;
445 } else if (mac->mode & WIRELESS_MODE_B) { 601 else if (mac->mode & WIRELESS_MODE_G)
446 tcb_desc->ratr_index = RATR_INX_WIRELESS_B; 602 tcb_desc->ratr_index = RATR_INX_WIRELESS_GB;
603 else if (mac->mode & WIRELESS_MODE_B)
604 tcb_desc->ratr_index = RATR_INX_WIRELESS_B;
605 else if (mac->mode & WIRELESS_MODE_A)
606 tcb_desc->ratr_index = RATR_INX_WIRELESS_G;
607 } else if (mac->opmode == NL80211_IFTYPE_AP ||
608 mac->opmode == NL80211_IFTYPE_ADHOC) {
609 if (NULL != sta) {
610 if (sta->aid > 0)
611 tcb_desc->mac_id = sta->aid + 1;
612 else
613 tcb_desc->mac_id = 1;
614 } else {
615 tcb_desc->mac_id = 0;
616 }
447 } 617 }
448 } 618 }
449 619
450} 620}
451 621
452static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, 622static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw,
623 struct ieee80211_sta *sta,
453 struct rtl_tcb_desc *tcb_desc) 624 struct rtl_tcb_desc *tcb_desc)
454{ 625{
455 struct rtl_priv *rtlpriv = rtl_priv(hw); 626 struct rtl_priv *rtlpriv = rtl_priv(hw);
456 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 627 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
457 628
458 tcb_desc->packet_bw = false; 629 tcb_desc->packet_bw = false;
459 630 if (!sta)
460 if (!mac->bw_40 || !mac->ht_enable)
461 return; 631 return;
462 632 if (mac->opmode == NL80211_IFTYPE_AP ||
633 mac->opmode == NL80211_IFTYPE_ADHOC) {
634 if (!(sta->ht_cap.ht_supported) ||
635 !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
636 return;
637 } else if (mac->opmode == NL80211_IFTYPE_STATION) {
638 if (!mac->bw_40 || !(sta->ht_cap.ht_supported))
639 return;
640 }
463 if (tcb_desc->multicast || tcb_desc->broadcast) 641 if (tcb_desc->multicast || tcb_desc->broadcast)
464 return; 642 return;
465 643
@@ -486,22 +664,21 @@ static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw)
486 664
487void rtl_get_tcb_desc(struct ieee80211_hw *hw, 665void rtl_get_tcb_desc(struct ieee80211_hw *hw,
488 struct ieee80211_tx_info *info, 666 struct ieee80211_tx_info *info,
667 struct ieee80211_sta *sta,
489 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) 668 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc)
490{ 669{
491 struct rtl_priv *rtlpriv = rtl_priv(hw); 670 struct rtl_priv *rtlpriv = rtl_priv(hw);
492 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); 671 struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
493 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 672 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
494 struct ieee80211_rate *txrate; 673 struct ieee80211_rate *txrate;
495 __le16 fc = hdr->frame_control; 674 __le16 fc = hdr->frame_control;
496 675
497 memset(tcb_desc, 0, sizeof(struct rtl_tcb_desc)); 676 txrate = ieee80211_get_tx_rate(hw, info);
677 tcb_desc->hw_rate = txrate->hw_value;
498 678
499 if (ieee80211_is_data(fc)) { 679 if (ieee80211_is_data(fc)) {
500 txrate = ieee80211_get_tx_rate(hw, info);
501 tcb_desc->hw_rate = txrate->hw_value;
502
503 /* 680 /*
504 *we set data rate RTL_RC_CCK_RATE1M 681 *we set data rate INX 0
505 *in rtl_rc.c if skb is special data or 682 *in rtl_rc.c if skb is special data or
506 *mgt which need low data rate. 683 *mgt which need low data rate.
507 */ 684 */
@@ -510,12 +687,11 @@ void rtl_get_tcb_desc(struct ieee80211_hw *hw,
510 *So tcb_desc->hw_rate is just used for 687 *So tcb_desc->hw_rate is just used for
511 *special data and mgt frames 688 *special data and mgt frames
512 */ 689 */
513 if (tcb_desc->hw_rate < rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]) { 690 if (info->control.rates[0].idx == 0 &&
691 ieee80211_is_nullfunc(fc)) {
514 tcb_desc->use_driver_rate = true; 692 tcb_desc->use_driver_rate = true;
515 tcb_desc->ratr_index = 7; 693 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
516 694
517 tcb_desc->hw_rate =
518 rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M];
519 tcb_desc->disable_ratefallback = 1; 695 tcb_desc->disable_ratefallback = 1;
520 } else { 696 } else {
521 /* 697 /*
@@ -525,7 +701,7 @@ void rtl_get_tcb_desc(struct ieee80211_hw *hw,
525 *and N rate will all be controlled by FW 701 *and N rate will all be controlled by FW
526 *when tcb_desc->use_driver_rate = false 702 *when tcb_desc->use_driver_rate = false
527 */ 703 */
528 if (rtlmac->ht_enable) { 704 if (sta && (sta->ht_cap.ht_supported)) {
529 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw); 705 tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw);
530 } else { 706 } else {
531 if (rtlmac->mode == WIRELESS_MODE_B) { 707 if (rtlmac->mode == WIRELESS_MODE_B) {
@@ -543,43 +719,25 @@ void rtl_get_tcb_desc(struct ieee80211_hw *hw,
543 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) 719 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
544 tcb_desc->broadcast = 1; 720 tcb_desc->broadcast = 1;
545 721
546 _rtl_txrate_selectmode(hw, tcb_desc); 722 _rtl_txrate_selectmode(hw, sta, tcb_desc);
547 _rtl_query_bandwidth_mode(hw, tcb_desc); 723 _rtl_query_bandwidth_mode(hw, sta, tcb_desc);
548 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); 724 _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info);
549 _rtl_query_shortgi(hw, tcb_desc, info); 725 _rtl_query_shortgi(hw, sta, tcb_desc, info);
550 _rtl_query_protection_mode(hw, tcb_desc, info); 726 _rtl_query_protection_mode(hw, tcb_desc, info);
551 } else { 727 } else {
552 tcb_desc->use_driver_rate = true; 728 tcb_desc->use_driver_rate = true;
553 tcb_desc->ratr_index = 7; 729 tcb_desc->ratr_index = RATR_INX_WIRELESS_MC;
554 tcb_desc->disable_ratefallback = 1; 730 tcb_desc->disable_ratefallback = 1;
555 tcb_desc->mac_id = 0; 731 tcb_desc->mac_id = 0;
556 732 tcb_desc->packet_bw = false;
557 tcb_desc->hw_rate = rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M];
558 } 733 }
559} 734}
560EXPORT_SYMBOL(rtl_get_tcb_desc); 735EXPORT_SYMBOL(rtl_get_tcb_desc);
561 736
562bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb)
563{
564 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
565 struct rtl_priv *rtlpriv = rtl_priv(hw);
566 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
567 __le16 fc = hdr->frame_control;
568
569 if (ieee80211_is_auth(fc)) {
570 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n"));
571 rtl_ips_nic_on(hw);
572
573 mac->link_state = MAC80211_LINKING;
574 }
575
576 return true;
577}
578
579bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) 737bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
580{ 738{
581 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 739 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
582 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 740 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
583 struct rtl_priv *rtlpriv = rtl_priv(hw); 741 struct rtl_priv *rtlpriv = rtl_priv(hw);
584 __le16 fc = hdr->frame_control; 742 __le16 fc = hdr->frame_control;
585 u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN)); 743 u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN));
@@ -624,9 +782,8 @@ bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
624u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) 782u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
625{ 783{
626 struct rtl_priv *rtlpriv = rtl_priv(hw); 784 struct rtl_priv *rtlpriv = rtl_priv(hw);
627 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
628 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 785 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
629 __le16 fc = hdr->frame_control; 786 __le16 fc = rtl_get_fc(skb);
630 u16 ether_type; 787 u16 ether_type;
631 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); 788 u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb);
632 const struct iphdr *ip; 789 const struct iphdr *ip;
@@ -634,12 +791,11 @@ u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
634 if (!ieee80211_is_data(fc)) 791 if (!ieee80211_is_data(fc))
635 return false; 792 return false;
636 793
637 if (ieee80211_is_nullfunc(fc))
638 return true;
639 794
640 ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len + 795 ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len +
641 SNAP_SIZE + PROTOC_TYPE_SIZE); 796 SNAP_SIZE + PROTOC_TYPE_SIZE);
642 ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE); 797 ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE);
798 /* ether_type = ntohs(ether_type); */
643 799
644 if (ETH_P_IP == ether_type) { 800 if (ETH_P_IP == ether_type) {
645 if (IPPROTO_UDP == ip->protocol) { 801 if (IPPROTO_UDP == ip->protocol) {
@@ -696,61 +852,92 @@ u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
696 * functions called by core.c 852 * functions called by core.c
697 * 853 *
698 *********************************************************/ 854 *********************************************************/
699int rtl_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra, u16 tid, u16 *ssn) 855int rtl_tx_agg_start(struct ieee80211_hw *hw,
856 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
700{ 857{
701 struct rtl_priv *rtlpriv = rtl_priv(hw); 858 struct rtl_priv *rtlpriv = rtl_priv(hw);
702 struct rtl_tid_data *tid_data; 859 struct rtl_tid_data *tid_data;
703 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 860 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
861 struct rtl_sta_info *sta_entry = NULL;
704 862
705 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, 863 if (sta == NULL)
706 ("on ra = %pM tid = %d\n", ra, tid)); 864 return -EINVAL;
707 865
708 if (unlikely(tid >= MAX_TID_COUNT)) 866 if (unlikely(tid >= MAX_TID_COUNT))
709 return -EINVAL; 867 return -EINVAL;
710 868
711 if (mac->tids[tid].agg.agg_state != RTL_AGG_OFF) { 869 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
712 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 870 if (!sta_entry)
713 ("Start AGG when state is not RTL_AGG_OFF !\n"));
714 return -ENXIO; 871 return -ENXIO;
715 } 872 tid_data = &sta_entry->tids[tid];
716
717 tid_data = &mac->tids[tid];
718 *ssn = SEQ_TO_SN(tid_data->seq_number);
719 873
720 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, 874 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
721 ("HW queue is empty tid:%d\n", tid)); 875 ("on ra = %pM tid = %d seq:%d\n", sta->addr, tid,
722 tid_data->agg.agg_state = RTL_AGG_ON; 876 tid_data->seq_number));
877
878 *ssn = tid_data->seq_number;
879 tid_data->agg.agg_state = RTL_AGG_START;
723 880
724 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, ra, tid); 881 ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
725 882
726 return 0; 883 return 0;
727} 884}
728 885
729int rtl_tx_agg_stop(struct ieee80211_hw *hw, const u8 * ra, u16 tid) 886int rtl_tx_agg_stop(struct ieee80211_hw *hw,
887 struct ieee80211_sta *sta, u16 tid)
730{ 888{
731 int ssn = -1;
732 struct rtl_priv *rtlpriv = rtl_priv(hw); 889 struct rtl_priv *rtlpriv = rtl_priv(hw);
733 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 890 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
734 struct rtl_tid_data *tid_data; 891 struct rtl_tid_data *tid_data;
892 struct rtl_sta_info *sta_entry = NULL;
735 893
736 if (!ra) { 894 if (sta == NULL)
895 return -EINVAL;
896
897 if (!sta->addr) {
737 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n")); 898 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
738 return -EINVAL; 899 return -EINVAL;
739 } 900 }
740 901
902 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
903 ("on ra = %pM tid = %d\n", sta->addr, tid));
904
741 if (unlikely(tid >= MAX_TID_COUNT)) 905 if (unlikely(tid >= MAX_TID_COUNT))
742 return -EINVAL; 906 return -EINVAL;
743 907
744 if (mac->tids[tid].agg.agg_state != RTL_AGG_ON) 908 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
745 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 909 tid_data = &sta_entry->tids[tid];
746 ("Stopping AGG while state not ON or starting\n")); 910 sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP;
911
912 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid);
913
914 return 0;
915}
916
917int rtl_tx_agg_oper(struct ieee80211_hw *hw,
918 struct ieee80211_sta *sta, u16 tid)
919{
920 struct rtl_priv *rtlpriv = rtl_priv(hw);
921 struct rtl_tid_data *tid_data;
922 struct rtl_sta_info *sta_entry = NULL;
923
924 if (sta == NULL)
925 return -EINVAL;
926
927 if (!sta->addr) {
928 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("ra = NULL\n"));
929 return -EINVAL;
930 }
747 931
748 tid_data = &mac->tids[tid]; 932 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG,
749 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; 933 ("on ra = %pM tid = %d\n", sta->addr, tid));
750 934
751 mac->tids[tid].agg.agg_state = RTL_AGG_OFF; 935 if (unlikely(tid >= MAX_TID_COUNT))
936 return -EINVAL;
752 937
753 ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, ra, tid); 938 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
939 tid_data = &sta_entry->tids[tid];
940 sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL;
754 941
755 return 0; 942 return 0;
756} 943}
@@ -769,18 +956,16 @@ void rtl_watchdog_wq_callback(void *data)
769 struct rtl_priv *rtlpriv = rtl_priv(hw); 956 struct rtl_priv *rtlpriv = rtl_priv(hw);
770 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 957 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
771 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 958 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
772
773 bool busytraffic = false; 959 bool busytraffic = false;
774 bool higher_busytraffic = false; 960 bool higher_busytraffic = false;
775 bool higher_busyrxtraffic = false; 961 bool higher_busyrxtraffic = false;
776 bool higher_busytxtraffic = false; 962 u8 idx, tid;
777
778 u8 idx = 0;
779 u32 rx_cnt_inp4eriod = 0; 963 u32 rx_cnt_inp4eriod = 0;
780 u32 tx_cnt_inp4eriod = 0; 964 u32 tx_cnt_inp4eriod = 0;
781 u32 aver_rx_cnt_inperiod = 0; 965 u32 aver_rx_cnt_inperiod = 0;
782 u32 aver_tx_cnt_inperiod = 0; 966 u32 aver_tx_cnt_inperiod = 0;
783 967 u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0};
968 u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0};
784 bool enter_ps = false; 969 bool enter_ps = false;
785 970
786 if (is_hal_stop(rtlhal)) 971 if (is_hal_stop(rtlhal))
@@ -794,9 +979,6 @@ void rtl_watchdog_wq_callback(void *data)
794 mac->cnt_after_linked = 0; 979 mac->cnt_after_linked = 0;
795 } 980 }
796 981
797 /* <2> DM */
798 rtlpriv->cfg->ops->dm_watchdog(hw);
799
800 /* 982 /*
801 *<3> to check if traffic busy, if 983 *<3> to check if traffic busy, if
802 * busytraffic we don't change channel 984 * busytraffic we don't change channel
@@ -835,8 +1017,27 @@ void rtl_watchdog_wq_callback(void *data)
835 /* Extremely high Rx data. */ 1017 /* Extremely high Rx data. */
836 if (aver_rx_cnt_inperiod > 5000) 1018 if (aver_rx_cnt_inperiod > 5000)
837 higher_busyrxtraffic = true; 1019 higher_busyrxtraffic = true;
1020 }
1021
1022 /* check every tid's tx traffic */
1023 for (tid = 0; tid <= 7; tid++) {
1024 for (idx = 0; idx <= 2; idx++)
1025 rtlpriv->link_info.tidtx_in4period[tid][idx] =
1026 rtlpriv->link_info.tidtx_in4period[tid]
1027 [idx + 1];
1028 rtlpriv->link_info.tidtx_in4period[tid][3] =
1029 rtlpriv->link_info.tidtx_inperiod[tid];
1030
1031 for (idx = 0; idx <= 3; idx++)
1032 tidtx_inp4eriod[tid] +=
1033 rtlpriv->link_info.tidtx_in4period[tid][idx];
1034 aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4;
1035 if (aver_tidtx_inperiod[tid] > 5000)
1036 rtlpriv->link_info.higher_busytxtraffic[tid] =
1037 true;
838 else 1038 else
839 higher_busytxtraffic = false; 1039 rtlpriv->link_info.higher_busytxtraffic[tid] =
1040 false;
840 } 1041 }
841 1042
842 if (((rtlpriv->link_info.num_rx_inperiod + 1043 if (((rtlpriv->link_info.num_rx_inperiod +
@@ -855,11 +1056,15 @@ void rtl_watchdog_wq_callback(void *data)
855 1056
856 rtlpriv->link_info.num_rx_inperiod = 0; 1057 rtlpriv->link_info.num_rx_inperiod = 0;
857 rtlpriv->link_info.num_tx_inperiod = 0; 1058 rtlpriv->link_info.num_tx_inperiod = 0;
1059 for (tid = 0; tid <= 7; tid++)
1060 rtlpriv->link_info.tidtx_inperiod[tid] = 0;
858 1061
859 rtlpriv->link_info.busytraffic = busytraffic; 1062 rtlpriv->link_info.busytraffic = busytraffic;
860 rtlpriv->link_info.higher_busytraffic = higher_busytraffic; 1063 rtlpriv->link_info.higher_busytraffic = higher_busytraffic;
861 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; 1064 rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic;
862 1065
1066 /* <3> DM */
1067 rtlpriv->cfg->ops->dm_watchdog(hw);
863} 1068}
864 1069
865void rtl_watch_dog_timer_callback(unsigned long data) 1070void rtl_watch_dog_timer_callback(unsigned long data)
@@ -876,6 +1081,268 @@ void rtl_watch_dog_timer_callback(unsigned long data)
876 1081
877/********************************************************* 1082/*********************************************************
878 * 1083 *
1084 * frame process functions
1085 *
1086 *********************************************************/
1087u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie)
1088{
1089 struct ieee80211_mgmt *mgmt = (void *)data;
1090 u8 *pos, *end;
1091
1092 pos = (u8 *)mgmt->u.beacon.variable;
1093 end = data + len;
1094 while (pos < end) {
1095 if (pos + 2 + pos[1] > end)
1096 return NULL;
1097
1098 if (pos[0] == ie)
1099 return pos;
1100
1101 pos += 2 + pos[1];
1102 }
1103 return NULL;
1104}
1105
1106/* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1107/* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1108static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw,
1109 enum ieee80211_smps_mode smps, u8 *da, u8 *bssid)
1110{
1111 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1112 struct sk_buff *skb;
1113 struct ieee80211_mgmt *action_frame;
1114
1115 /* 27 = header + category + action + smps mode */
1116 skb = dev_alloc_skb(27 + hw->extra_tx_headroom);
1117 if (!skb)
1118 return NULL;
1119
1120 skb_reserve(skb, hw->extra_tx_headroom);
1121 action_frame = (void *)skb_put(skb, 27);
1122 memset(action_frame, 0, 27);
1123 memcpy(action_frame->da, da, ETH_ALEN);
1124 memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN);
1125 memcpy(action_frame->bssid, bssid, ETH_ALEN);
1126 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1127 IEEE80211_STYPE_ACTION);
1128 action_frame->u.action.category = WLAN_CATEGORY_HT;
1129 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
1130 switch (smps) {
1131 case IEEE80211_SMPS_AUTOMATIC:/* 0 */
1132 case IEEE80211_SMPS_NUM_MODES:/* 4 */
1133 WARN_ON(1);
1134 case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/
1135 action_frame->u.action.u.ht_smps.smps_control =
1136 WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */
1137 break;
1138 case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/
1139 action_frame->u.action.u.ht_smps.smps_control =
1140 WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */
1141 break;
1142 case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/
1143 action_frame->u.action.u.ht_smps.smps_control =
1144 WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */
1145 break;
1146 }
1147
1148 return skb;
1149}
1150
1151int rtl_send_smps_action(struct ieee80211_hw *hw,
1152 struct ieee80211_sta *sta, u8 *da, u8 *bssid,
1153 enum ieee80211_smps_mode smps)
1154{
1155 struct rtl_priv *rtlpriv = rtl_priv(hw);
1156 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1157 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1158 struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid);
1159 struct rtl_tcb_desc tcb_desc;
1160 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
1161
1162 if (rtlpriv->mac80211.act_scanning)
1163 goto err_free;
1164
1165 if (!sta)
1166 goto err_free;
1167
1168 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
1169 goto err_free;
1170
1171 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1172 goto err_free;
1173
1174 /* this is a type = mgmt * stype = action frame */
1175 if (skb) {
1176 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1177 struct rtl_sta_info *sta_entry =
1178 (struct rtl_sta_info *) sta->drv_priv;
1179 sta_entry->mimo_ps = smps;
1180 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
1181
1182 info->control.rates[0].idx = 0;
1183 info->control.sta = sta;
1184 info->band = hw->conf.channel->band;
1185 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
1186 }
1187err_free:
1188 return 0;
1189}
1190
1191/*********************************************************
1192 *
1193 * IOT functions
1194 *
1195 *********************************************************/
1196static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw,
1197 struct octet_string vendor_ie)
1198{
1199 struct rtl_priv *rtlpriv = rtl_priv(hw);
1200 bool matched = false;
1201 static u8 athcap_1[] = { 0x00, 0x03, 0x7F };
1202 static u8 athcap_2[] = { 0x00, 0x13, 0x74 };
1203 static u8 broadcap_1[] = { 0x00, 0x10, 0x18 };
1204 static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 };
1205 static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 };
1206 static u8 racap[] = { 0x00, 0x0c, 0x43 };
1207 static u8 ciscocap[] = { 0x00, 0x40, 0x96 };
1208 static u8 marvcap[] = { 0x00, 0x50, 0x43 };
1209
1210 if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 ||
1211 memcmp(vendor_ie.octet, athcap_2, 3) == 0) {
1212 rtlpriv->mac80211.vendor = PEER_ATH;
1213 matched = true;
1214 } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 ||
1215 memcmp(vendor_ie.octet, broadcap_2, 3) == 0 ||
1216 memcmp(vendor_ie.octet, broadcap_3, 3) == 0) {
1217 rtlpriv->mac80211.vendor = PEER_BROAD;
1218 matched = true;
1219 } else if (memcmp(vendor_ie.octet, racap, 3) == 0) {
1220 rtlpriv->mac80211.vendor = PEER_RAL;
1221 matched = true;
1222 } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) {
1223 rtlpriv->mac80211.vendor = PEER_CISCO;
1224 matched = true;
1225 } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) {
1226 rtlpriv->mac80211.vendor = PEER_MARV;
1227 matched = true;
1228 }
1229
1230 return matched;
1231}
1232
1233static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data,
1234 unsigned int len)
1235{
1236 struct ieee80211_mgmt *mgmt = (void *)data;
1237 struct octet_string vendor_ie;
1238 u8 *pos, *end;
1239
1240 pos = (u8 *)mgmt->u.beacon.variable;
1241 end = data + len;
1242 while (pos < end) {
1243 if (pos[0] == 221) {
1244 vendor_ie.length = pos[1];
1245 vendor_ie.octet = &pos[2];
1246 if (rtl_chk_vendor_ouisub(hw, vendor_ie))
1247 return true;
1248 }
1249
1250 if (pos + 2 + pos[1] > end)
1251 return false;
1252
1253 pos += 2 + pos[1];
1254 }
1255 return false;
1256}
1257
1258void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len)
1259{
1260 struct rtl_priv *rtlpriv = rtl_priv(hw);
1261 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1262 struct ieee80211_hdr *hdr = (void *)data;
1263 u32 vendor = PEER_UNKNOWN;
1264
1265 static u8 ap3_1[3] = { 0x00, 0x14, 0xbf };
1266 static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 };
1267 static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e };
1268 static u8 ap4_1[3] = { 0x00, 0x90, 0xcc };
1269 static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e };
1270 static u8 ap4_3[3] = { 0x00, 0x18, 0x02 };
1271 static u8 ap4_4[3] = { 0x00, 0x17, 0x3f };
1272 static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf };
1273 static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 };
1274 static u8 ap5_2[3] = { 0x00, 0x21, 0x91 };
1275 static u8 ap5_3[3] = { 0x00, 0x24, 0x01 };
1276 static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 };
1277 static u8 ap5_5[3] = { 0x00, 0x17, 0x9A };
1278 static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 };
1279 static u8 ap6_1[3] = { 0x00, 0x17, 0x94 };
1280 static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 };
1281
1282 if (mac->opmode != NL80211_IFTYPE_STATION)
1283 return;
1284
1285 if (mac->link_state == MAC80211_NOLINK) {
1286 mac->vendor = PEER_UNKNOWN;
1287 return;
1288 }
1289
1290 if (mac->cnt_after_linked > 2)
1291 return;
1292
1293 /* check if this really is a beacon */
1294 if (!ieee80211_is_beacon(hdr->frame_control))
1295 return;
1296
1297 /* min. beacon length + FCS_LEN */
1298 if (len <= 40 + FCS_LEN)
1299 return;
1300
1301 /* and only beacons from the associated BSSID, please */
1302 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
1303 return;
1304
1305 if (rtl_find_221_ie(hw, data, len))
1306 vendor = mac->vendor;
1307
1308 if ((memcmp(mac->bssid, ap5_1, 3) == 0) ||
1309 (memcmp(mac->bssid, ap5_2, 3) == 0) ||
1310 (memcmp(mac->bssid, ap5_3, 3) == 0) ||
1311 (memcmp(mac->bssid, ap5_4, 3) == 0) ||
1312 (memcmp(mac->bssid, ap5_5, 3) == 0) ||
1313 (memcmp(mac->bssid, ap5_6, 3) == 0) ||
1314 vendor == PEER_ATH) {
1315 vendor = PEER_ATH;
1316 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ath find\n"));
1317 } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) ||
1318 (memcmp(mac->bssid, ap4_5, 3) == 0) ||
1319 (memcmp(mac->bssid, ap4_1, 3) == 0) ||
1320 (memcmp(mac->bssid, ap4_2, 3) == 0) ||
1321 (memcmp(mac->bssid, ap4_3, 3) == 0) ||
1322 vendor == PEER_RAL) {
1323 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>ral findn\n"));
1324 vendor = PEER_RAL;
1325 } else if (memcmp(mac->bssid, ap6_1, 3) == 0 ||
1326 vendor == PEER_CISCO) {
1327 vendor = PEER_CISCO;
1328 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>cisco find\n"));
1329 } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) ||
1330 (memcmp(mac->bssid, ap3_2, 3) == 0) ||
1331 (memcmp(mac->bssid, ap3_3, 3) == 0) ||
1332 vendor == PEER_BROAD) {
1333 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>broad find\n"));
1334 vendor = PEER_BROAD;
1335 } else if (memcmp(mac->bssid, ap7_1, 3) == 0 ||
1336 vendor == PEER_MARV) {
1337 vendor = PEER_MARV;
1338 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("=>marv find\n"));
1339 }
1340
1341 mac->vendor = vendor;
1342}
1343
1344/*********************************************************
1345 *
879 * sysfs functions 1346 * sysfs functions
880 * 1347 *
881 *********************************************************/ 1348 *********************************************************/
@@ -941,12 +1408,13 @@ static int __init rtl_core_module_init(void)
941 if (rtl_rate_control_register()) 1408 if (rtl_rate_control_register())
942 printk(KERN_ERR "rtlwifi: Unable to register rtl_rc," 1409 printk(KERN_ERR "rtlwifi: Unable to register rtl_rc,"
943 "use default RC !!\n"); 1410 "use default RC !!\n");
1411
944 return 0; 1412 return 0;
945} 1413}
946 1414
947static void __exit rtl_core_module_exit(void) 1415static void __exit rtl_core_module_exit(void)
948{ 1416{
949 /*RC*/ 1417 /*RC*/
950 rtl_rate_control_unregister(); 1418 rtl_rate_control_unregister();
951} 1419}
952 1420
diff --git a/drivers/net/wireless/rtlwifi/base.h b/drivers/net/wireless/rtlwifi/base.h
index 043045342bc7..a91f3eee59c8 100644
--- a/drivers/net/wireless/rtlwifi/base.h
+++ b/drivers/net/wireless/rtlwifi/base.h
@@ -24,13 +24,26 @@
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net> 26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
27 *****************************************************************************/ 28 *****************************************************************************/
28 29
29#ifndef __RTL_BASE_H__ 30#ifndef __RTL_BASE_H__
30#define __RTL_BASE_H__ 31#define __RTL_BASE_H__
31 32
33enum ap_peer {
34 PEER_UNKNOWN = 0,
35 PEER_RTL = 1,
36 PEER_RTL_92SE = 2,
37 PEER_BROAD = 3,
38 PEER_RAL = 4,
39 PEER_ATH = 5,
40 PEER_CISCO = 6,
41 PEER_MARV = 7,
42 PEER_AIRGO = 9,
43 PEER_MAX = 10,
44} ;
45
32#define RTL_DUMMY_OFFSET 0 46#define RTL_DUMMY_OFFSET 0
33#define RTL_RX_DESC_SIZE 24
34#define RTL_DUMMY_UNIT 8 47#define RTL_DUMMY_UNIT 8
35#define RTL_TX_DUMMY_SIZE (RTL_DUMMY_OFFSET * RTL_DUMMY_UNIT) 48#define RTL_TX_DUMMY_SIZE (RTL_DUMMY_OFFSET * RTL_DUMMY_UNIT)
36#define RTL_TX_DESC_SIZE 32 49#define RTL_TX_DESC_SIZE 32
@@ -53,6 +66,14 @@
53#define FRAME_OFFSET_SEQUENCE 22 66#define FRAME_OFFSET_SEQUENCE 22
54#define FRAME_OFFSET_ADDRESS4 24 67#define FRAME_OFFSET_ADDRESS4 24
55 68
69#define SET_80211_HDR_FRAME_CONTROL(_hdr, _val) \
70 WRITEEF2BYTE(_hdr, _val)
71#define SET_80211_HDR_TYPE_AND_SUBTYPE(_hdr, _val) \
72 WRITEEF1BYTE(_hdr, _val)
73#define SET_80211_HDR_PWR_MGNT(_hdr, _val) \
74 SET_BITS_TO_LE_2BYTE(_hdr, 12, 1, _val)
75#define SET_80211_HDR_TO_DS(_hdr, _val) \
76 SET_BITS_TO_LE_2BYTE(_hdr, 8, 1, _val)
56 77
57#define SET_80211_PS_POLL_AID(_hdr, _val) \ 78#define SET_80211_PS_POLL_AID(_hdr, _val) \
58 (*(u16 *)((u8 *)(_hdr) + 2) = le16_to_cpu(_val)) 79 (*(u16 *)((u8 *)(_hdr) + 2) = le16_to_cpu(_val))
@@ -64,11 +85,27 @@
64#define SET_80211_HDR_DURATION(_hdr, _val) \ 85#define SET_80211_HDR_DURATION(_hdr, _val) \
65 (*(u16 *)((u8 *)(_hdr) + FRAME_OFFSET_DURATION) = le16_to_cpu(_val)) 86 (*(u16 *)((u8 *)(_hdr) + FRAME_OFFSET_DURATION) = le16_to_cpu(_val))
66#define SET_80211_HDR_ADDRESS1(_hdr, _val) \ 87#define SET_80211_HDR_ADDRESS1(_hdr, _val) \
67 memcpy((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS1, (u8*)(_val), ETH_ALEN) 88 CP_MACADDR((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS1, (u8 *)(_val))
68#define SET_80211_HDR_ADDRESS2(_hdr, _val) \ 89#define SET_80211_HDR_ADDRESS2(_hdr, _val) \
69 memcpy((u8 *)(_hdr) + FRAME_OFFSET_ADDRESS2, (u8 *)(_val), ETH_ALEN) 90 CP_MACADDR((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS2, (u8 *)(_val))
70#define SET_80211_HDR_ADDRESS3(_hdr, _val) \ 91#define SET_80211_HDR_ADDRESS3(_hdr, _val) \
71 memcpy((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS3, (u8 *)(_val), ETH_ALEN) 92 CP_MACADDR((u8 *)(_hdr)+FRAME_OFFSET_ADDRESS3, (u8 *)(_val))
93#define SET_80211_HDR_FRAGMENT_SEQUENCE(_hdr, _val) \
94 WRITEEF2BYTE((u8 *)(_hdr)+FRAME_OFFSET_SEQUENCE, _val)
95
96#define SET_BEACON_PROBE_RSP_TIME_STAMP_LOW(__phdr, __val) \
97 WRITEEF4BYTE(((u8 *)(__phdr)) + 24, __val)
98#define SET_BEACON_PROBE_RSP_TIME_STAMP_HIGH(__phdr, __val) \
99 WRITEEF4BYTE(((u8 *)(__phdr)) + 28, __val)
100#define SET_BEACON_PROBE_RSP_BEACON_INTERVAL(__phdr, __val) \
101 WRITEEF2BYTE(((u8 *)(__phdr)) + 32, __val)
102#define GET_BEACON_PROBE_RSP_CAPABILITY_INFO(__phdr) \
103 READEF2BYTE(((u8 *)(__phdr)) + 34)
104#define SET_BEACON_PROBE_RSP_CAPABILITY_INFO(__phdr, __val) \
105 WRITEEF2BYTE(((u8 *)(__phdr)) + 34, __val)
106#define MASK_BEACON_PROBE_RSP_CAPABILITY_INFO(__phdr, __val) \
107 SET_BEACON_PROBE_RSP_CAPABILITY_INFO(__phdr, \
108 (GET_BEACON_PROBE_RSP_CAPABILITY_INFO(__phdr) & (~(__val))))
72 109
73int rtl_init_core(struct ieee80211_hw *hw); 110int rtl_init_core(struct ieee80211_hw *hw);
74void rtl_deinit_core(struct ieee80211_hw *hw); 111void rtl_deinit_core(struct ieee80211_hw *hw);
@@ -80,18 +117,27 @@ void rtl_watch_dog_timer_callback(unsigned long data);
80void rtl_deinit_deferred_work(struct ieee80211_hw *hw); 117void rtl_deinit_deferred_work(struct ieee80211_hw *hw);
81 118
82bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx); 119bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx);
83bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb);
84u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx); 120u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx);
85 121
86void rtl_watch_dog_timer_callback(unsigned long data); 122void rtl_watch_dog_timer_callback(unsigned long data);
87int rtl_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra, 123int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
88 u16 tid, u16 *ssn); 124 u16 tid, u16 *ssn);
89int rtl_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid); 125int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
126 u16 tid);
127int rtl_tx_agg_oper(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
128 u16 tid);
90void rtl_watchdog_wq_callback(void *data); 129void rtl_watchdog_wq_callback(void *data);
91 130
92void rtl_get_tcb_desc(struct ieee80211_hw *hw, 131void rtl_get_tcb_desc(struct ieee80211_hw *hw,
93 struct ieee80211_tx_info *info, 132 struct ieee80211_tx_info *info,
133 struct ieee80211_sta *sta,
94 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc); 134 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc);
95 135
136int rtl_send_smps_action(struct ieee80211_hw *hw,
137 struct ieee80211_sta *sta, u8 *da, u8 *bssid,
138 enum ieee80211_smps_mode smps);
139u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie);
140void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len);
141u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid);
96extern struct attribute_group rtl_attribute_group; 142extern struct attribute_group rtl_attribute_group;
97#endif 143#endif
diff --git a/drivers/net/wireless/rtlwifi/cam.c b/drivers/net/wireless/rtlwifi/cam.c
index 52c9c1367cac..7295af0536b7 100644
--- a/drivers/net/wireless/rtlwifi/cam.c
+++ b/drivers/net/wireless/rtlwifi/cam.c
@@ -23,6 +23,8 @@
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
26 *****************************************************************************/ 28 *****************************************************************************/
27 29
28#include "wifi.h" 30#include "wifi.h"
@@ -49,7 +51,7 @@ static void rtl_cam_program_entry(struct ieee80211_hw *hw, u32 entry_no,
49 u32 target_content = 0; 51 u32 target_content = 0;
50 u8 entry_i; 52 u8 entry_i;
51 53
52 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 54 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
53 ("key_cont_128:\n %x:%x:%x:%x:%x:%x\n", 55 ("key_cont_128:\n %x:%x:%x:%x:%x:%x\n",
54 key_cont_128[0], key_cont_128[1], 56 key_cont_128[0], key_cont_128[1],
55 key_cont_128[2], key_cont_128[3], 57 key_cont_128[2], key_cont_128[3],
@@ -68,15 +70,13 @@ static void rtl_cam_program_entry(struct ieee80211_hw *hw, u32 entry_no,
68 rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], 70 rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM],
69 target_command); 71 target_command);
70 72
71 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 73 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
72 ("rtl_cam_program_entry(): " 74 ("WRITE %x: %x\n",
73 "WRITE %x: %x\n",
74 rtlpriv->cfg->maps[WCAMI], target_content)); 75 rtlpriv->cfg->maps[WCAMI], target_content));
75 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 76 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
76 ("The Key ID is %d\n", entry_no)); 77 ("The Key ID is %d\n", entry_no));
77 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 78 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
78 ("rtl_cam_program_entry(): " 79 ("WRITE %x: %x\n",
79 "WRITE %x: %x\n",
80 rtlpriv->cfg->maps[RWCAM], target_command)); 80 rtlpriv->cfg->maps[RWCAM], target_command));
81 81
82 } else if (entry_i == 1) { 82 } else if (entry_i == 1) {
@@ -91,12 +91,10 @@ static void rtl_cam_program_entry(struct ieee80211_hw *hw, u32 entry_no,
91 rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], 91 rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM],
92 target_command); 92 target_command);
93 93
94 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 94 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
95 ("rtl_cam_program_entry(): WRITE A4: %x\n", 95 ("WRITE A4: %x\n", target_content));
96 target_content)); 96 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
97 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 97 ("WRITE A0: %x\n", target_command));
98 ("rtl_cam_program_entry(): WRITE A0: %x\n",
99 target_command));
100 98
101 } else { 99 } else {
102 100
@@ -113,16 +111,14 @@ static void rtl_cam_program_entry(struct ieee80211_hw *hw, u32 entry_no,
113 target_command); 111 target_command);
114 udelay(100); 112 udelay(100);
115 113
116 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 114 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
117 ("rtl_cam_program_entry(): WRITE A4: %x\n", 115 ("WRITE A4: %x\n", target_content));
118 target_content)); 116 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
119 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 117 ("WRITE A0: %x\n", target_command));
120 ("rtl_cam_program_entry(): WRITE A0: %x\n",
121 target_command));
122 } 118 }
123 } 119 }
124 120
125 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 121 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
126 ("after set key, usconfig:%x\n", us_config)); 122 ("after set key, usconfig:%x\n", us_config));
127} 123}
128 124
@@ -289,3 +285,71 @@ void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
289 285
290} 286}
291EXPORT_SYMBOL(rtl_cam_empty_entry); 287EXPORT_SYMBOL(rtl_cam_empty_entry);
288
289u8 rtl_cam_get_free_entry(struct ieee80211_hw *hw, u8 *sta_addr)
290{
291 struct rtl_priv *rtlpriv = rtl_priv(hw);
292 u32 bitmap = (rtlpriv->sec.hwsec_cam_bitmap) >> 4;
293 u8 entry_idx = 0;
294 u8 i, *addr;
295
296 if (NULL == sta_addr) {
297 RT_TRACE(rtlpriv, COMP_SEC, DBG_EMERG,
298 ("sta_addr is NULL.\n"));
299 return TOTAL_CAM_ENTRY;
300 }
301 /* Does STA already exist? */
302 for (i = 4; i < TOTAL_CAM_ENTRY; i++) {
303 addr = rtlpriv->sec.hwsec_cam_sta_addr[i];
304 if (memcmp(addr, sta_addr, ETH_ALEN) == 0)
305 return i;
306 }
307 /* Get a free CAM entry. */
308 for (entry_idx = 4; entry_idx < TOTAL_CAM_ENTRY; entry_idx++) {
309 if ((bitmap & BIT(0)) == 0) {
310 RT_TRACE(rtlpriv, COMP_SEC, DBG_EMERG,
311 ("-----hwsec_cam_bitmap: 0x%x entry_idx=%d\n",
312 rtlpriv->sec.hwsec_cam_bitmap, entry_idx));
313 rtlpriv->sec.hwsec_cam_bitmap |= BIT(0) << entry_idx;
314 memcpy(rtlpriv->sec.hwsec_cam_sta_addr[entry_idx],
315 sta_addr, ETH_ALEN);
316 return entry_idx;
317 }
318 bitmap = bitmap >> 1;
319 }
320 return TOTAL_CAM_ENTRY;
321}
322EXPORT_SYMBOL(rtl_cam_get_free_entry);
323
324void rtl_cam_del_entry(struct ieee80211_hw *hw, u8 *sta_addr)
325{
326 struct rtl_priv *rtlpriv = rtl_priv(hw);
327 u32 bitmap;
328 u8 i, *addr;
329
330 if (NULL == sta_addr) {
331 RT_TRACE(rtlpriv, COMP_SEC, DBG_EMERG,
332 ("sta_addr is NULL.\n"));
333 }
334
335 if ((sta_addr[0]|sta_addr[1]|sta_addr[2]|sta_addr[3]|\
336 sta_addr[4]|sta_addr[5]) == 0) {
337 RT_TRACE(rtlpriv, COMP_SEC, DBG_EMERG,
338 ("sta_addr is 00:00:00:00:00:00.\n"));
339 return;
340 }
341 /* Does STA already exist? */
342 for (i = 4; i < TOTAL_CAM_ENTRY; i++) {
343 addr = rtlpriv->sec.hwsec_cam_sta_addr[i];
344 bitmap = (rtlpriv->sec.hwsec_cam_bitmap) >> i;
345 if (((bitmap & BIT(0)) == BIT(0)) &&
346 (memcmp(addr, sta_addr, ETH_ALEN) == 0)) {
347 /* Remove from HW Security CAM */
348 memset(rtlpriv->sec.hwsec_cam_sta_addr[i], 0, ETH_ALEN);
349 rtlpriv->sec.hwsec_cam_bitmap &= ~(BIT(0) << i);
350 printk(KERN_INFO "&&&&&&&&&del entry %d\n", i);
351 }
352 }
353 return;
354}
355EXPORT_SYMBOL(rtl_cam_del_entry);
diff --git a/drivers/net/wireless/rtlwifi/cam.h b/drivers/net/wireless/rtlwifi/cam.h
index dd82f057d53d..c62da4eefc75 100644
--- a/drivers/net/wireless/rtlwifi/cam.h
+++ b/drivers/net/wireless/rtlwifi/cam.h
@@ -23,12 +23,13 @@
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
26 *****************************************************************************/ 28 *****************************************************************************/
27 29
28#ifndef __RTL_CAM_H_ 30#ifndef __RTL_CAM_H_
29#define __RTL_CAM_H_ 31#define __RTL_CAM_H_
30 32
31#define TOTAL_CAM_ENTRY 32
32#define CAM_CONTENT_COUNT 8 33#define CAM_CONTENT_COUNT 8
33 34
34#define CFG_DEFAULT_KEY BIT(5) 35#define CFG_DEFAULT_KEY BIT(5)
@@ -49,5 +50,7 @@ int rtl_cam_delete_one_entry(struct ieee80211_hw *hw, u8 *mac_addr,
49void rtl_cam_mark_invalid(struct ieee80211_hw *hw, u8 uc_index); 50void rtl_cam_mark_invalid(struct ieee80211_hw *hw, u8 uc_index);
50void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index); 51void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index);
51void rtl_cam_reset_sec_info(struct ieee80211_hw *hw); 52void rtl_cam_reset_sec_info(struct ieee80211_hw *hw);
53u8 rtl_cam_get_free_entry(struct ieee80211_hw *hw, u8 *sta_addr);
54void rtl_cam_del_entry(struct ieee80211_hw *hw, u8 *sta_addr);
52 55
53#endif 56#endif
diff --git a/drivers/net/wireless/rtlwifi/core.c b/drivers/net/wireless/rtlwifi/core.c
index 8fed3c687619..fc89cd8c8320 100644
--- a/drivers/net/wireless/rtlwifi/core.c
+++ b/drivers/net/wireless/rtlwifi/core.c
@@ -24,6 +24,7 @@
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net> 26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
27 *****************************************************************************/ 28 *****************************************************************************/
28 29
29#include "wifi.h" 30#include "wifi.h"
@@ -70,6 +71,7 @@ static void rtl_op_stop(struct ieee80211_hw *hw)
70 71
71 mac->link_state = MAC80211_NOLINK; 72 mac->link_state = MAC80211_NOLINK;
72 memset(mac->bssid, 0, 6); 73 memset(mac->bssid, 0, 6);
74 mac->vendor = PEER_UNKNOWN;
73 75
74 /*reset sec info */ 76 /*reset sec info */
75 rtl_cam_reset_sec_info(hw); 77 rtl_cam_reset_sec_info(hw);
@@ -85,6 +87,8 @@ static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
85 struct rtl_priv *rtlpriv = rtl_priv(hw); 87 struct rtl_priv *rtlpriv = rtl_priv(hw);
86 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 88 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
87 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 89 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
90 struct rtl_tcb_desc tcb_desc;
91 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
88 92
89 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) 93 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
90 goto err_free; 94 goto err_free;
@@ -92,8 +96,8 @@ static void rtl_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
92 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) 96 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
93 goto err_free; 97 goto err_free;
94 98
95 99 if (!rtlpriv->intf_ops->waitq_insert(hw, skb))
96 rtlpriv->intf_ops->adapter_tx(hw, skb); 100 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
97 101
98 return; 102 return;
99 103
@@ -134,10 +138,26 @@ static int rtl_op_add_interface(struct ieee80211_hw *hw,
134 138
135 mac->link_state = MAC80211_LINKED; 139 mac->link_state = MAC80211_LINKED;
136 rtlpriv->cfg->ops->set_bcn_reg(hw); 140 rtlpriv->cfg->ops->set_bcn_reg(hw);
141 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
142 mac->basic_rates = 0xfff;
143 else
144 mac->basic_rates = 0xff0;
145 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
146 (u8 *) (&mac->basic_rates));
147
137 break; 148 break;
138 case NL80211_IFTYPE_AP: 149 case NL80211_IFTYPE_AP:
139 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, 150 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
140 ("NL80211_IFTYPE_AP\n")); 151 ("NL80211_IFTYPE_AP\n"));
152
153 mac->link_state = MAC80211_LINKED;
154 rtlpriv->cfg->ops->set_bcn_reg(hw);
155 if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G)
156 mac->basic_rates = 0xfff;
157 else
158 mac->basic_rates = 0xff0;
159 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
160 (u8 *) (&mac->basic_rates));
141 break; 161 break;
142 default: 162 default:
143 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 163 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
@@ -184,13 +204,12 @@ static void rtl_op_remove_interface(struct ieee80211_hw *hw,
184 mac->vif = NULL; 204 mac->vif = NULL;
185 mac->link_state = MAC80211_NOLINK; 205 mac->link_state = MAC80211_NOLINK;
186 memset(mac->bssid, 0, 6); 206 memset(mac->bssid, 0, 6);
207 mac->vendor = PEER_UNKNOWN;
187 mac->opmode = NL80211_IFTYPE_UNSPECIFIED; 208 mac->opmode = NL80211_IFTYPE_UNSPECIFIED;
188 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); 209 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
189
190 mutex_unlock(&rtlpriv->locks.conf_mutex); 210 mutex_unlock(&rtlpriv->locks.conf_mutex);
191} 211}
192 212
193
194static int rtl_op_config(struct ieee80211_hw *hw, u32 changed) 213static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
195{ 214{
196 struct rtl_priv *rtlpriv = rtl_priv(hw); 215 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -222,10 +241,25 @@ static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
222 241
223 /*For LPS */ 242 /*For LPS */
224 if (changed & IEEE80211_CONF_CHANGE_PS) { 243 if (changed & IEEE80211_CONF_CHANGE_PS) {
225 if (conf->flags & IEEE80211_CONF_PS) 244 cancel_delayed_work(&rtlpriv->works.ps_work);
226 rtl_lps_enter(hw); 245 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
227 else 246 if (conf->flags & IEEE80211_CONF_PS) {
228 rtl_lps_leave(hw); 247 rtlpriv->psc.sw_ps_enabled = true;
248 /* sleep here is must, or we may recv the beacon and
249 * cause mac80211 into wrong ps state, this will cause
250 * power save nullfunc send fail, and further cause
251 * pkt loss, So sleep must quickly but not immediatly
252 * because that will cause nullfunc send by mac80211
253 * fail, and cause pkt loss, we have tested that 5mA
254 * is worked very well */
255 if (!rtlpriv->psc.multi_buffered)
256 queue_delayed_work(rtlpriv->works.rtl_wq,
257 &rtlpriv->works.ps_work,
258 MSECS(5));
259 } else {
260 rtl_swlps_rf_awake(hw);
261 rtlpriv->psc.sw_ps_enabled = false;
262 }
229 } 263 }
230 264
231 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { 265 if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
@@ -257,7 +291,7 @@ static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
257 case NL80211_CHAN_NO_HT: 291 case NL80211_CHAN_NO_HT:
258 /* SC */ 292 /* SC */
259 mac->cur_40_prime_sc = 293 mac->cur_40_prime_sc =
260 PRIME_CHNL_OFFSET_DONT_CARE; 294 PRIME_CHNL_OFFSET_DONT_CARE;
261 rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20; 295 rtlphy->current_chan_bw = HT_CHANNEL_WIDTH_20;
262 mac->bw_40 = false; 296 mac->bw_40 = false;
263 break; 297 break;
@@ -265,7 +299,7 @@ static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
265 /* SC */ 299 /* SC */
266 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER; 300 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_UPPER;
267 rtlphy->current_chan_bw = 301 rtlphy->current_chan_bw =
268 HT_CHANNEL_WIDTH_20_40; 302 HT_CHANNEL_WIDTH_20_40;
269 mac->bw_40 = true; 303 mac->bw_40 = true;
270 304
271 /*wide channel */ 305 /*wide channel */
@@ -276,7 +310,7 @@ static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
276 /* SC */ 310 /* SC */
277 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER; 311 mac->cur_40_prime_sc = PRIME_CHNL_OFFSET_LOWER;
278 rtlphy->current_chan_bw = 312 rtlphy->current_chan_bw =
279 HT_CHANNEL_WIDTH_20_40; 313 HT_CHANNEL_WIDTH_20_40;
280 mac->bw_40 = true; 314 mac->bw_40 = true;
281 315
282 /*wide channel */ 316 /*wide channel */
@@ -286,16 +320,29 @@ static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
286 default: 320 default:
287 mac->bw_40 = false; 321 mac->bw_40 = false;
288 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 322 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
289 ("switch case not processed\n")); 323 ("switch case not processed\n"));
290 break; 324 break;
291 } 325 }
292 326
293 if (wide_chan <= 0) 327 if (wide_chan <= 0)
294 wide_chan = 1; 328 wide_chan = 1;
329
330 /* In scanning, before we go offchannel we may send a ps=1 null
331 * to AP, and then we may send a ps = 0 null to AP quickly, but
332 * first null may have caused AP to put lots of packet to hw tx
333 * buffer. These packets must be tx'd before we go off channel
334 * so we must delay more time to let AP flush these packets
335 * before going offchannel, or dis-association or delete BA will
336 * happen by AP
337 */
338 if (rtlpriv->mac80211.offchan_deley) {
339 rtlpriv->mac80211.offchan_deley = false;
340 mdelay(50);
341 }
295 rtlphy->current_channel = wide_chan; 342 rtlphy->current_channel = wide_chan;
296 343
297 rtlpriv->cfg->ops->set_channel_access(hw);
298 rtlpriv->cfg->ops->switch_channel(hw); 344 rtlpriv->cfg->ops->switch_channel(hw);
345 rtlpriv->cfg->ops->set_channel_access(hw);
299 rtlpriv->cfg->ops->set_bw_mode(hw, 346 rtlpriv->cfg->ops->set_bw_mode(hw,
300 hw->conf.channel_type); 347 hw->conf.channel_type);
301 } 348 }
@@ -343,27 +390,28 @@ static void rtl_op_configure_filter(struct ieee80211_hw *hw,
343 } 390 }
344 } 391 }
345 392
346 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { 393 /* if ssid not set to hw don't check bssid
347 /* 394 * here just used for linked scanning, & linked
348 *TODO: BIT(5) is probe response BIT(8) is beacon 395 * and nolink check bssid is set in set network_type */
349 *TODO: Use define for BIT(5) and BIT(8) 396 if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) &&
350 */ 397 (mac->link_state >= MAC80211_LINKED)) {
351 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) 398 if (mac->opmode != NL80211_IFTYPE_AP) {
352 mac->rx_mgt_filter |= (BIT(5) | BIT(8)); 399 if (*new_flags & FIF_BCN_PRBRESP_PROMISC) {
353 else 400 rtlpriv->cfg->ops->set_chk_bssid(hw, false);
354 mac->rx_mgt_filter &= ~(BIT(5) | BIT(8)); 401 } else {
402 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
403 }
404 }
355 } 405 }
356 406
357 if (changed_flags & FIF_CONTROL) { 407 if (changed_flags & FIF_CONTROL) {
358 if (*new_flags & FIF_CONTROL) { 408 if (*new_flags & FIF_CONTROL) {
359 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF]; 409 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
360 mac->rx_ctrl_filter |= RTL_SUPPORTED_CTRL_FILTER;
361 410
362 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, 411 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
363 ("Enable receive control frame.\n")); 412 ("Enable receive control frame.\n"));
364 } else { 413 } else {
365 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF]; 414 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
366 mac->rx_ctrl_filter &= ~RTL_SUPPORTED_CTRL_FILTER;
367 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, 415 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
368 ("Disable receive control frame.\n")); 416 ("Disable receive control frame.\n"));
369 } 417 }
@@ -380,14 +428,54 @@ static void rtl_op_configure_filter(struct ieee80211_hw *hw,
380 ("Disable receive other BSS's frame.\n")); 428 ("Disable receive other BSS's frame.\n"));
381 } 429 }
382 } 430 }
383
384 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
385 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MGT_FILTER,
386 (u8 *) (&mac->rx_mgt_filter));
387 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CTRL_FILTER,
388 (u8 *) (&mac->rx_ctrl_filter));
389} 431}
432static int rtl_op_sta_add(struct ieee80211_hw *hw,
433 struct ieee80211_vif *vif,
434 struct ieee80211_sta *sta)
435{
436 struct rtl_priv *rtlpriv = rtl_priv(hw);
437 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
438 struct rtl_sta_info *sta_entry;
439
440 if (sta) {
441 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
442 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
443 sta_entry->wireless_mode = WIRELESS_MODE_G;
444 if (sta->supp_rates[0] <= 0xf)
445 sta_entry->wireless_mode = WIRELESS_MODE_B;
446 if (sta->ht_cap.ht_supported == true)
447 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
448 } else if (rtlhal->current_bandtype == BAND_ON_5G) {
449 sta_entry->wireless_mode = WIRELESS_MODE_A;
450 if (sta->ht_cap.ht_supported == true)
451 sta_entry->wireless_mode = WIRELESS_MODE_N_24G;
452 }
453
454 /* I found some times mac80211 give wrong supp_rates for adhoc*/
455 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC)
456 sta_entry->wireless_mode = WIRELESS_MODE_G;
390 457
458 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
459 ("Add sta addr is "MAC_FMT"\n", MAC_ARG(sta->addr)));
460 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
461 }
462 return 0;
463}
464static int rtl_op_sta_remove(struct ieee80211_hw *hw,
465 struct ieee80211_vif *vif,
466 struct ieee80211_sta *sta)
467{
468 struct rtl_priv *rtlpriv = rtl_priv(hw);
469 struct rtl_sta_info *sta_entry;
470 if (sta) {
471 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
472 ("Remove sta addr is "MAC_FMT"\n", MAC_ARG(sta->addr)));
473 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
474 sta_entry->wireless_mode = 0;
475 sta_entry->ratr_index = 0;
476 }
477 return 0;
478}
391static int _rtl_get_hal_qnum(u16 queue) 479static int _rtl_get_hal_qnum(u16 queue)
392{ 480{
393 int qnum; 481 int qnum;
@@ -444,19 +532,18 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
444 struct ieee80211_bss_conf *bss_conf, u32 changed) 532 struct ieee80211_bss_conf *bss_conf, u32 changed)
445{ 533{
446 struct rtl_priv *rtlpriv = rtl_priv(hw); 534 struct rtl_priv *rtlpriv = rtl_priv(hw);
535 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
447 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 536 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
448 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 537 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
538 struct ieee80211_sta *sta = NULL;
449 539
450 mutex_lock(&rtlpriv->locks.conf_mutex); 540 mutex_lock(&rtlpriv->locks.conf_mutex);
451
452 if ((vif->type == NL80211_IFTYPE_ADHOC) || 541 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
453 (vif->type == NL80211_IFTYPE_AP) || 542 (vif->type == NL80211_IFTYPE_AP) ||
454 (vif->type == NL80211_IFTYPE_MESH_POINT)) { 543 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
455
456 if ((changed & BSS_CHANGED_BEACON) || 544 if ((changed & BSS_CHANGED_BEACON) ||
457 (changed & BSS_CHANGED_BEACON_ENABLED && 545 (changed & BSS_CHANGED_BEACON_ENABLED &&
458 bss_conf->enable_beacon)) { 546 bss_conf->enable_beacon)) {
459
460 if (mac->beacon_enabled == 0) { 547 if (mac->beacon_enabled == 0) {
461 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, 548 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
462 ("BSS_CHANGED_BEACON_ENABLED\n")); 549 ("BSS_CHANGED_BEACON_ENABLED\n"));
@@ -468,8 +555,13 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
468 rtlpriv->cfg->maps 555 rtlpriv->cfg->maps
469 [RTL_IBSS_INT_MASKS], 556 [RTL_IBSS_INT_MASKS],
470 0); 557 0);
558
559 if (rtlpriv->cfg->ops->linked_set_reg)
560 rtlpriv->cfg->ops->linked_set_reg(hw);
471 } 561 }
472 } else { 562 }
563 if ((changed & BSS_CHANGED_BEACON_ENABLED &&
564 !bss_conf->enable_beacon)) {
473 if (mac->beacon_enabled == 1) { 565 if (mac->beacon_enabled == 1) {
474 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, 566 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
475 ("ADHOC DISABLE BEACON\n")); 567 ("ADHOC DISABLE BEACON\n"));
@@ -480,7 +572,6 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
480 [RTL_IBSS_INT_MASKS]); 572 [RTL_IBSS_INT_MASKS]);
481 } 573 }
482 } 574 }
483
484 if (changed & BSS_CHANGED_BEACON_INT) { 575 if (changed & BSS_CHANGED_BEACON_INT) {
485 RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE, 576 RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE,
486 ("BSS_CHANGED_BEACON_INT\n")); 577 ("BSS_CHANGED_BEACON_INT\n"));
@@ -492,11 +583,25 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
492 /*TODO: reference to enum ieee80211_bss_change */ 583 /*TODO: reference to enum ieee80211_bss_change */
493 if (changed & BSS_CHANGED_ASSOC) { 584 if (changed & BSS_CHANGED_ASSOC) {
494 if (bss_conf->assoc) { 585 if (bss_conf->assoc) {
586 /* we should reset all sec info & cam
587 * before set cam after linked, we should not
588 * reset in disassoc, that will cause tkip->wep
589 * fail because some flag will be wrong */
590 /* reset sec info */
591 rtl_cam_reset_sec_info(hw);
592 /* reset cam to fix wep fail issue
593 * when change from wpa to wep */
594 rtl_cam_reset_all_entry(hw);
595
495 mac->link_state = MAC80211_LINKED; 596 mac->link_state = MAC80211_LINKED;
496 mac->cnt_after_linked = 0; 597 mac->cnt_after_linked = 0;
497 mac->assoc_id = bss_conf->aid; 598 mac->assoc_id = bss_conf->aid;
498 memcpy(mac->bssid, bss_conf->bssid, 6); 599 memcpy(mac->bssid, bss_conf->bssid, 6);
499 600
601 if (rtlpriv->cfg->ops->linked_set_reg)
602 rtlpriv->cfg->ops->linked_set_reg(hw);
603 if (mac->opmode == NL80211_IFTYPE_STATION && sta)
604 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
500 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, 605 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
501 ("BSS_CHANGED_ASSOC\n")); 606 ("BSS_CHANGED_ASSOC\n"));
502 } else { 607 } else {
@@ -505,9 +610,7 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
505 610
506 mac->link_state = MAC80211_NOLINK; 611 mac->link_state = MAC80211_NOLINK;
507 memset(mac->bssid, 0, 6); 612 memset(mac->bssid, 0, 6);
508 613 mac->vendor = PEER_UNKNOWN;
509 /* reset sec info */
510 rtl_cam_reset_sec_info(hw);
511 614
512 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, 615 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
513 ("BSS_CHANGED_UN_ASSOC\n")); 616 ("BSS_CHANGED_UN_ASSOC\n"));
@@ -544,14 +647,10 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
544 } 647 }
545 648
546 if (changed & BSS_CHANGED_HT) { 649 if (changed & BSS_CHANGED_HT) {
547 struct ieee80211_sta *sta = NULL;
548
549 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, 650 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
550 ("BSS_CHANGED_HT\n")); 651 ("BSS_CHANGED_HT\n"));
551
552 rcu_read_lock(); 652 rcu_read_lock();
553 sta = ieee80211_find_sta(mac->vif, mac->bssid); 653 sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
554
555 if (sta) { 654 if (sta) {
556 if (sta->ht_cap.ampdu_density > 655 if (sta->ht_cap.ampdu_density >
557 mac->current_ampdu_density) 656 mac->current_ampdu_density)
@@ -573,9 +672,7 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
573 } 672 }
574 673
575 if (changed & BSS_CHANGED_BSSID) { 674 if (changed & BSS_CHANGED_BSSID) {
576 struct ieee80211_sta *sta = NULL;
577 u32 basic_rates; 675 u32 basic_rates;
578 u8 i;
579 676
580 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID, 677 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
581 (u8 *) bss_conf->bssid); 678 (u8 *) bss_conf->bssid);
@@ -583,96 +680,65 @@ static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
583 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, 680 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
584 (MAC_FMT "\n", MAC_ARG(bss_conf->bssid))); 681 (MAC_FMT "\n", MAC_ARG(bss_conf->bssid)));
585 682
683 mac->vendor = PEER_UNKNOWN;
586 memcpy(mac->bssid, bss_conf->bssid, 6); 684 memcpy(mac->bssid, bss_conf->bssid, 6);
587 if (is_valid_ether_addr(bss_conf->bssid)) { 685 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
588 switch (vif->type) {
589 case NL80211_IFTYPE_UNSPECIFIED:
590 break;
591 case NL80211_IFTYPE_ADHOC:
592 break;
593 case NL80211_IFTYPE_STATION:
594 break;
595 case NL80211_IFTYPE_AP:
596 break;
597 default:
598 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
599 ("switch case not process\n"));
600 break;
601 }
602 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
603 } else
604 rtlpriv->cfg->ops->set_network_type(hw,
605 NL80211_IFTYPE_UNSPECIFIED);
606
607 memset(mac->mcs, 0, 16);
608 mac->ht_enable = false;
609 mac->sgi_40 = false;
610 mac->sgi_20 = false;
611
612 if (!bss_conf->use_short_slot)
613 mac->mode = WIRELESS_MODE_B;
614 else
615 mac->mode = WIRELESS_MODE_G;
616 686
617 rcu_read_lock(); 687 rcu_read_lock();
618 sta = ieee80211_find_sta(mac->vif, mac->bssid); 688 sta = get_sta(hw, vif, (u8 *)bss_conf->bssid);
689 if (!sta) {
690 rcu_read_unlock();
691 goto out;
692 }
619 693
620 if (sta) { 694 if (rtlhal->current_bandtype == BAND_ON_5G) {
621 if (sta->ht_cap.ht_supported) { 695 mac->mode = WIRELESS_MODE_A;
696 } else {
697 if (sta->supp_rates[0] <= 0xf)
698 mac->mode = WIRELESS_MODE_B;
699 else
700 mac->mode = WIRELESS_MODE_G;
701 }
702
703 if (sta->ht_cap.ht_supported) {
704 if (rtlhal->current_bandtype == BAND_ON_2_4G)
622 mac->mode = WIRELESS_MODE_N_24G; 705 mac->mode = WIRELESS_MODE_N_24G;
623 mac->ht_enable = true; 706 else
624 } 707 mac->mode = WIRELESS_MODE_N_5G;
708 }
625 709
626 if (mac->ht_enable) { 710 /* just station need it, because ibss & ap mode will
627 u16 ht_cap = sta->ht_cap.cap; 711 * set in sta_add, and will be NULL here */
628 memcpy(mac->mcs, (u8 *) (&sta->ht_cap.mcs), 16); 712 if (mac->opmode == NL80211_IFTYPE_STATION) {
629 713 struct rtl_sta_info *sta_entry;
630 for (i = 0; i < 16; i++) 714 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
631 RT_TRACE(rtlpriv, COMP_MAC80211, 715 sta_entry->wireless_mode = mac->mode;
632 DBG_LOUD, ("%x ", 716 }
633 mac->mcs[i])); 717
634 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, 718 if (sta->ht_cap.ht_supported) {
635 ("\n")); 719 mac->ht_enable = true;
636 720
637 if (ht_cap & IEEE80211_HT_CAP_SGI_40) 721 /*
638 mac->sgi_40 = true; 722 * for cisco 1252 bw20 it's wrong
639 723 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
640 if (ht_cap & IEEE80211_HT_CAP_SGI_20) 724 * mac->bw_40 = true;
641 mac->sgi_20 = true; 725 * }
642 726 * */
643 /*
644 * for cisco 1252 bw20 it's wrong
645 * if (ht_cap &
646 * IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
647 * mac->bw_40 = true;
648 * }
649 */
650 }
651 } 727 }
652 rcu_read_unlock();
653 728
654 /*mac80211 just give us CCK rates any time
655 *So we add G rate in basic rates when
656 not in B mode*/
657 if (changed & BSS_CHANGED_BASIC_RATES) { 729 if (changed & BSS_CHANGED_BASIC_RATES) {
658 if (mac->mode == WIRELESS_MODE_B) 730 /* for 5G must << RATE_6M_INDEX=4,
659 basic_rates = bss_conf->basic_rates | 0x00f; 731 * because 5G have no cck rate*/
732 if (rtlhal->current_bandtype == BAND_ON_5G)
733 basic_rates = sta->supp_rates[1] << 4;
660 else 734 else
661 basic_rates = bss_conf->basic_rates | 0xff0; 735 basic_rates = sta->supp_rates[0];
662
663 if (!vif)
664 goto out;
665 736
666 mac->basic_rates = basic_rates; 737 mac->basic_rates = basic_rates;
667 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, 738 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
668 (u8 *) (&basic_rates)); 739 (u8 *) (&basic_rates));
669
670 if (rtlpriv->dm.useramask)
671 rtlpriv->cfg->ops->update_rate_mask(hw, 0);
672 else
673 rtlpriv->cfg->ops->update_rate_table(hw);
674
675 } 740 }
741 rcu_read_unlock();
676 } 742 }
677 743
678 /* 744 /*
@@ -758,16 +824,17 @@ static int rtl_op_ampdu_action(struct ieee80211_hw *hw,
758 case IEEE80211_AMPDU_TX_START: 824 case IEEE80211_AMPDU_TX_START:
759 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, 825 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
760 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid)); 826 ("IEEE80211_AMPDU_TX_START: TID:%d\n", tid));
761 return rtl_tx_agg_start(hw, sta->addr, tid, ssn); 827 return rtl_tx_agg_start(hw, sta, tid, ssn);
762 break; 828 break;
763 case IEEE80211_AMPDU_TX_STOP: 829 case IEEE80211_AMPDU_TX_STOP:
764 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, 830 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
765 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid)); 831 ("IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid));
766 return rtl_tx_agg_stop(hw, sta->addr, tid); 832 return rtl_tx_agg_stop(hw, sta, tid);
767 break; 833 break;
768 case IEEE80211_AMPDU_TX_OPERATIONAL: 834 case IEEE80211_AMPDU_TX_OPERATIONAL:
769 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, 835 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
770 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid)); 836 ("IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid));
837 rtl_tx_agg_oper(hw, sta, tid);
771 break; 838 break;
772 case IEEE80211_AMPDU_RX_START: 839 case IEEE80211_AMPDU_RX_START:
773 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, 840 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
@@ -797,8 +864,12 @@ static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
797 if (mac->link_state == MAC80211_LINKED) { 864 if (mac->link_state == MAC80211_LINKED) {
798 rtl_lps_leave(hw); 865 rtl_lps_leave(hw);
799 mac->link_state = MAC80211_LINKED_SCANNING; 866 mac->link_state = MAC80211_LINKED_SCANNING;
800 } else 867 } else {
801 rtl_ips_nic_on(hw); 868 rtl_ips_nic_on(hw);
869 }
870
871 /* Dual mac */
872 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
802 873
803 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY); 874 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
804 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP); 875 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP);
@@ -810,22 +881,19 @@ static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
810 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 881 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
811 882
812 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n")); 883 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, ("\n"));
813
814 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
815 mac->act_scanning = false; 884 mac->act_scanning = false;
885 /* Dual mac */
886 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
887
816 if (mac->link_state == MAC80211_LINKED_SCANNING) { 888 if (mac->link_state == MAC80211_LINKED_SCANNING) {
817 mac->link_state = MAC80211_LINKED; 889 mac->link_state = MAC80211_LINKED;
818 890 if (mac->opmode == NL80211_IFTYPE_STATION) {
819 /* fix fwlps issue */ 891 /* fix fwlps issue */
820 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); 892 rtlpriv->cfg->ops->set_network_type(hw, mac->opmode);
821 893 }
822 if (rtlpriv->dm.useramask)
823 rtlpriv->cfg->ops->update_rate_mask(hw, 0);
824 else
825 rtlpriv->cfg->ops->update_rate_table(hw);
826
827 } 894 }
828 895
896 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE);
829} 897}
830 898
831static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 899static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
@@ -856,49 +924,73 @@ static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
856 rtl_ips_nic_on(hw); 924 rtl_ips_nic_on(hw);
857 mutex_lock(&rtlpriv->locks.conf_mutex); 925 mutex_lock(&rtlpriv->locks.conf_mutex);
858 /* <1> get encryption alg */ 926 /* <1> get encryption alg */
927
859 switch (key->cipher) { 928 switch (key->cipher) {
860 case WLAN_CIPHER_SUITE_WEP40: 929 case WLAN_CIPHER_SUITE_WEP40:
861 key_type = WEP40_ENCRYPTION; 930 key_type = WEP40_ENCRYPTION;
862 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n")); 931 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:WEP40\n"));
863 rtlpriv->sec.use_defaultkey = true;
864 break; 932 break;
865 case WLAN_CIPHER_SUITE_WEP104: 933 case WLAN_CIPHER_SUITE_WEP104:
866 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 934 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
867 ("alg:WEP104\n")); 935 ("alg:WEP104\n"));
868 key_type = WEP104_ENCRYPTION; 936 key_type = WEP104_ENCRYPTION;
869 rtlpriv->sec.use_defaultkey = true;
870 break; 937 break;
871 case WLAN_CIPHER_SUITE_TKIP: 938 case WLAN_CIPHER_SUITE_TKIP:
872 key_type = TKIP_ENCRYPTION; 939 key_type = TKIP_ENCRYPTION;
873 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n")); 940 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:TKIP\n"));
874 if (mac->opmode == NL80211_IFTYPE_ADHOC)
875 rtlpriv->sec.use_defaultkey = true;
876 break; 941 break;
877 case WLAN_CIPHER_SUITE_CCMP: 942 case WLAN_CIPHER_SUITE_CCMP:
878 key_type = AESCCMP_ENCRYPTION; 943 key_type = AESCCMP_ENCRYPTION;
879 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n")); 944 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("alg:CCMP\n"));
880 if (mac->opmode == NL80211_IFTYPE_ADHOC)
881 rtlpriv->sec.use_defaultkey = true;
882 break; 945 break;
883 default: 946 default:
884 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 947 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
885 ("alg_err:%x!!!!:\n", key->cipher)); 948 ("alg_err:%x!!!!:\n", key->cipher));
886 goto out_unlock; 949 goto out_unlock;
887 } 950 }
951 if (key_type == WEP40_ENCRYPTION ||
952 key_type == WEP104_ENCRYPTION ||
953 mac->opmode == NL80211_IFTYPE_ADHOC)
954 rtlpriv->sec.use_defaultkey = true;
955
888 /* <2> get key_idx */ 956 /* <2> get key_idx */
889 key_idx = (u8) (key->keyidx); 957 key_idx = (u8) (key->keyidx);
890 if (key_idx > 3) 958 if (key_idx > 3)
891 goto out_unlock; 959 goto out_unlock;
892 /* <3> if pairwise key enable_hw_sec */ 960 /* <3> if pairwise key enable_hw_sec */
893 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE); 961 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
894 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) || 962
895 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) { 963 /* wep always be group key, but there are two conditions:
896 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION && 964 * 1) wep only: is just for wep enc, in this condition
897 (key_type == WEP40_ENCRYPTION || 965 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
898 key_type == WEP104_ENCRYPTION)) 966 * will be true & enable_hw_sec will be set when wep
899 wep_only = true; 967 * ke setting.
900 rtlpriv->sec.pairwise_enc_algorithm = key_type; 968 * 2) wep(group) + AES(pairwise): some AP like cisco
901 rtlpriv->cfg->ops->enable_hw_sec(hw); 969 * may use it, in this condition enable_hw_sec will not
970 * be set when wep key setting */
971 /* we must reset sec_info after lingked before set key,
972 * or some flag will be wrong*/
973 if (mac->opmode == NL80211_IFTYPE_AP) {
974 if (!group_key || key_type == WEP40_ENCRYPTION ||
975 key_type == WEP104_ENCRYPTION) {
976 if (group_key)
977 wep_only = true;
978 rtlpriv->cfg->ops->enable_hw_sec(hw);
979 }
980 } else {
981 if ((!group_key) || (mac->opmode == NL80211_IFTYPE_ADHOC) ||
982 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
983 if (rtlpriv->sec.pairwise_enc_algorithm ==
984 NO_ENCRYPTION &&
985 (key_type == WEP40_ENCRYPTION ||
986 key_type == WEP104_ENCRYPTION))
987 wep_only = true;
988 rtlpriv->sec.pairwise_enc_algorithm = key_type;
989 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
990 ("set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1"
991 " TKIP:2 AES:4 WEP104:5)\n", key_type));
992 rtlpriv->cfg->ops->enable_hw_sec(hw);
993 }
902 } 994 }
903 /* <4> set key based on cmd */ 995 /* <4> set key based on cmd */
904 switch (cmd) { 996 switch (cmd) {
@@ -930,6 +1022,7 @@ static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
930 if (!sta) { 1022 if (!sta) {
931 RT_ASSERT(false, ("pairwise key withnot" 1023 RT_ASSERT(false, ("pairwise key withnot"
932 "mac_addr\n")); 1024 "mac_addr\n"));
1025
933 err = -EOPNOTSUPP; 1026 err = -EOPNOTSUPP;
934 goto out_unlock; 1027 goto out_unlock;
935 } 1028 }
@@ -957,6 +1050,10 @@ static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
957 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 1050 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
958 ("disable key delete one entry\n")); 1051 ("disable key delete one entry\n"));
959 /*set local buf about wep key. */ 1052 /*set local buf about wep key. */
1053 if (mac->opmode == NL80211_IFTYPE_AP) {
1054 if (sta)
1055 rtl_cam_del_entry(hw, sta->addr);
1056 }
960 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen); 1057 memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen);
961 rtlpriv->sec.key_len[key_idx] = 0; 1058 rtlpriv->sec.key_len[key_idx] = 0;
962 memcpy(mac_addr, zero_addr, ETH_ALEN); 1059 memcpy(mac_addr, zero_addr, ETH_ALEN);
@@ -1009,6 +1106,18 @@ static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1009 mutex_unlock(&rtlpriv->locks.conf_mutex); 1106 mutex_unlock(&rtlpriv->locks.conf_mutex);
1010} 1107}
1011 1108
1109/* this function is called by mac80211 to flush tx buffer
1110 * before switch channle or power save, or tx buffer packet
1111 * maybe send after offchannel or rf sleep, this may cause
1112 * dis-association by AP */
1113static void rtl_op_flush(struct ieee80211_hw *hw, bool drop)
1114{
1115 struct rtl_priv *rtlpriv = rtl_priv(hw);
1116
1117 if (rtlpriv->intf_ops->flush)
1118 rtlpriv->intf_ops->flush(hw, drop);
1119}
1120
1012const struct ieee80211_ops rtl_ops = { 1121const struct ieee80211_ops rtl_ops = {
1013 .start = rtl_op_start, 1122 .start = rtl_op_start,
1014 .stop = rtl_op_stop, 1123 .stop = rtl_op_stop,
@@ -1017,6 +1126,8 @@ const struct ieee80211_ops rtl_ops = {
1017 .remove_interface = rtl_op_remove_interface, 1126 .remove_interface = rtl_op_remove_interface,
1018 .config = rtl_op_config, 1127 .config = rtl_op_config,
1019 .configure_filter = rtl_op_configure_filter, 1128 .configure_filter = rtl_op_configure_filter,
1129 .sta_add = rtl_op_sta_add,
1130 .sta_remove = rtl_op_sta_remove,
1020 .set_key = rtl_op_set_key, 1131 .set_key = rtl_op_set_key,
1021 .conf_tx = rtl_op_conf_tx, 1132 .conf_tx = rtl_op_conf_tx,
1022 .bss_info_changed = rtl_op_bss_info_changed, 1133 .bss_info_changed = rtl_op_bss_info_changed,
@@ -1028,4 +1139,5 @@ const struct ieee80211_ops rtl_ops = {
1028 .sw_scan_start = rtl_op_sw_scan_start, 1139 .sw_scan_start = rtl_op_sw_scan_start,
1029 .sw_scan_complete = rtl_op_sw_scan_complete, 1140 .sw_scan_complete = rtl_op_sw_scan_complete,
1030 .rfkill_poll = rtl_op_rfkill_poll, 1141 .rfkill_poll = rtl_op_rfkill_poll,
1142 .flush = rtl_op_flush,
1031}; 1143};
diff --git a/drivers/net/wireless/rtlwifi/core.h b/drivers/net/wireless/rtlwifi/core.h
index 0ef31c3c6196..4b247db2861d 100644
--- a/drivers/net/wireless/rtlwifi/core.h
+++ b/drivers/net/wireless/rtlwifi/core.h
@@ -24,6 +24,7 @@
24 * Hsinchu 300, Taiwan. 24 * Hsinchu 300, Taiwan.
25 * 25 *
26 * Larry Finger <Larry.Finger@lwfinger.net> 26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
27 *****************************************************************************/ 28 *****************************************************************************/
28 29
29#ifndef __RTL_CORE_H__ 30#ifndef __RTL_CORE_H__
diff --git a/drivers/net/wireless/rtlwifi/efuse.c b/drivers/net/wireless/rtlwifi/efuse.c
index 5d73c0f7012c..510d42edb8ca 100644
--- a/drivers/net/wireless/rtlwifi/efuse.c
+++ b/drivers/net/wireless/rtlwifi/efuse.c
@@ -52,8 +52,6 @@ static const struct efuse_map RTL8712_SDIO_EFUSE_TABLE[] = {
52 {11, 0, 0, 28} 52 {11, 0, 0, 28}
53}; 53};
54 54
55static void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset,
56 u8 *pbuf);
57static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset, 55static void efuse_shadow_read_1byte(struct ieee80211_hw *hw, u16 offset,
58 u8 *value); 56 u8 *value);
59static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset, 57static void efuse_shadow_read_2byte(struct ieee80211_hw *hw, u16 offset,
@@ -79,7 +77,7 @@ static void efuse_word_enable_data_read(u8 word_en, u8 *sourdata,
79 u8 *targetdata); 77 u8 *targetdata);
80static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw, 78static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
81 u16 efuse_addr, u8 word_en, u8 *data); 79 u16 efuse_addr, u8 word_en, u8 *data);
82static void efuse_power_switch(struct ieee80211_hw *hw, u8 bwrite, 80static void efuse_power_switch(struct ieee80211_hw *hw, u8 write,
83 u8 pwrstate); 81 u8 pwrstate);
84static u16 efuse_get_current_size(struct ieee80211_hw *hw); 82static u16 efuse_get_current_size(struct ieee80211_hw *hw);
85static u8 efuse_calculate_word_cnts(u8 word_en); 83static u8 efuse_calculate_word_cnts(u8 word_en);
@@ -115,8 +113,10 @@ u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address)
115 u8 bytetemp; 113 u8 bytetemp;
116 u8 temp; 114 u8 temp;
117 u32 k = 0; 115 u32 k = 0;
116 const u32 efuse_len =
117 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
118 118
119 if (address < EFUSE_REAL_CONTENT_LEN) { 119 if (address < efuse_len) {
120 temp = address & 0xFF; 120 temp = address & 0xFF;
121 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1, 121 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL] + 1,
122 temp); 122 temp);
@@ -158,11 +158,13 @@ void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value)
158 u8 bytetemp; 158 u8 bytetemp;
159 u8 temp; 159 u8 temp;
160 u32 k = 0; 160 u32 k = 0;
161 const u32 efuse_len =
162 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
161 163
162 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, 164 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
163 ("Addr=%x Data =%x\n", address, value)); 165 ("Addr=%x Data =%x\n", address, value));
164 166
165 if (address < EFUSE_REAL_CONTENT_LEN) { 167 if (address < efuse_len) {
166 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], value); 168 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CTRL], value);
167 169
168 temp = address & 0xFF; 170 temp = address & 0xFF;
@@ -198,7 +200,7 @@ void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value)
198 200
199} 201}
200 202
201static void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf) 203void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf)
202{ 204{
203 struct rtl_priv *rtlpriv = rtl_priv(hw); 205 struct rtl_priv *rtlpriv = rtl_priv(hw);
204 u32 value32; 206 u32 value32;
@@ -233,24 +235,28 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
233{ 235{
234 struct rtl_priv *rtlpriv = rtl_priv(hw); 236 struct rtl_priv *rtlpriv = rtl_priv(hw);
235 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 237 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
236 u8 efuse_tbl[EFUSE_MAP_LEN]; 238 u8 efuse_tbl[HWSET_MAX_SIZE];
237 u8 rtemp8[1]; 239 u8 rtemp8[1];
238 u16 efuse_addr = 0; 240 u16 efuse_addr = 0;
239 u8 offset, wren; 241 u8 offset, wren;
240 u16 i; 242 u16 i;
241 u16 j; 243 u16 j;
244 const u16 efuse_max_section =
245 rtlpriv->cfg->maps[EFUSE_MAX_SECTION_MAP];
246 const u32 efuse_len =
247 rtlpriv->cfg->maps[EFUSE_REAL_CONTENT_SIZE];
242 u16 efuse_word[EFUSE_MAX_SECTION][EFUSE_MAX_WORD_UNIT]; 248 u16 efuse_word[EFUSE_MAX_SECTION][EFUSE_MAX_WORD_UNIT];
243 u16 efuse_utilized = 0; 249 u16 efuse_utilized = 0;
244 u8 efuse_usage; 250 u8 efuse_usage;
245 251
246 if ((_offset + _size_byte) > EFUSE_MAP_LEN) { 252 if ((_offset + _size_byte) > rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]) {
247 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD, 253 RT_TRACE(rtlpriv, COMP_EFUSE, DBG_LOUD,
248 ("read_efuse(): Invalid offset(%#x) with read " 254 ("read_efuse(): Invalid offset(%#x) with read "
249 "bytes(%#x)!!\n", _offset, _size_byte)); 255 "bytes(%#x)!!\n", _offset, _size_byte));
250 return; 256 return;
251 } 257 }
252 258
253 for (i = 0; i < EFUSE_MAX_SECTION; i++) 259 for (i = 0; i < efuse_max_section; i++)
254 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) 260 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++)
255 efuse_word[i][j] = 0xFFFF; 261 efuse_word[i][j] = 0xFFFF;
256 262
@@ -262,10 +268,10 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
262 efuse_addr++; 268 efuse_addr++;
263 } 269 }
264 270
265 while ((*rtemp8 != 0xFF) && (efuse_addr < EFUSE_REAL_CONTENT_LEN)) { 271 while ((*rtemp8 != 0xFF) && (efuse_addr < efuse_len)) {
266 offset = ((*rtemp8 >> 4) & 0x0f); 272 offset = ((*rtemp8 >> 4) & 0x0f);
267 273
268 if (offset < EFUSE_MAX_SECTION) { 274 if (offset < efuse_max_section) {
269 wren = (*rtemp8 & 0x0f); 275 wren = (*rtemp8 & 0x0f);
270 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL, 276 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
271 ("offset-%d Worden=%x\n", offset, wren)); 277 ("offset-%d Worden=%x\n", offset, wren));
@@ -281,7 +287,7 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
281 efuse_utilized++; 287 efuse_utilized++;
282 efuse_word[offset][i] = (*rtemp8 & 0xff); 288 efuse_word[offset][i] = (*rtemp8 & 0xff);
283 289
284 if (efuse_addr >= EFUSE_REAL_CONTENT_LEN) 290 if (efuse_addr >= efuse_len)
285 break; 291 break;
286 292
287 RTPRINT(rtlpriv, FEEPROM, 293 RTPRINT(rtlpriv, FEEPROM,
@@ -294,7 +300,7 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
294 efuse_word[offset][i] |= 300 efuse_word[offset][i] |=
295 (((u16)*rtemp8 << 8) & 0xff00); 301 (((u16)*rtemp8 << 8) & 0xff00);
296 302
297 if (efuse_addr >= EFUSE_REAL_CONTENT_LEN) 303 if (efuse_addr >= efuse_len)
298 break; 304 break;
299 } 305 }
300 306
@@ -305,13 +311,13 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
305 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL, 311 RTPRINT(rtlpriv, FEEPROM, EFUSE_READ_ALL,
306 ("Addr=%d\n", efuse_addr)); 312 ("Addr=%d\n", efuse_addr));
307 read_efuse_byte(hw, efuse_addr, rtemp8); 313 read_efuse_byte(hw, efuse_addr, rtemp8);
308 if (*rtemp8 != 0xFF && (efuse_addr < 512)) { 314 if (*rtemp8 != 0xFF && (efuse_addr < efuse_len)) {
309 efuse_utilized++; 315 efuse_utilized++;
310 efuse_addr++; 316 efuse_addr++;
311 } 317 }
312 } 318 }
313 319
314 for (i = 0; i < EFUSE_MAX_SECTION; i++) { 320 for (i = 0; i < efuse_max_section; i++) {
315 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) { 321 for (j = 0; j < EFUSE_MAX_WORD_UNIT; j++) {
316 efuse_tbl[(i * 8) + (j * 2)] = 322 efuse_tbl[(i * 8) + (j * 2)] =
317 (efuse_word[i][j] & 0xff); 323 (efuse_word[i][j] & 0xff);
@@ -324,7 +330,7 @@ void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
324 pbuf[i] = efuse_tbl[_offset + i]; 330 pbuf[i] = efuse_tbl[_offset + i];
325 331
326 rtlefuse->efuse_usedbytes = efuse_utilized; 332 rtlefuse->efuse_usedbytes = efuse_utilized;
327 efuse_usage = (u8)((efuse_utilized * 100) / EFUSE_REAL_CONTENT_LEN); 333 efuse_usage = (u8) ((efuse_utilized * 100) / efuse_len);
328 rtlefuse->efuse_usedpercentage = efuse_usage; 334 rtlefuse->efuse_usedpercentage = efuse_usage;
329 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_BYTES, 335 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_EFUSE_BYTES,
330 (u8 *)&efuse_utilized); 336 (u8 *)&efuse_utilized);
@@ -478,9 +484,10 @@ void rtl_efuse_shadow_map_update(struct ieee80211_hw *hw)
478 struct rtl_priv *rtlpriv = rtl_priv(hw); 484 struct rtl_priv *rtlpriv = rtl_priv(hw);
479 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 485 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
480 486
481 if (rtlefuse->autoload_failflag == true) { 487 if (rtlefuse->autoload_failflag == true)
482 memset(&rtlefuse->efuse_map[EFUSE_INIT_MAP][0], 0xFF, 128); 488 memset(&rtlefuse->efuse_map[EFUSE_INIT_MAP][0], 0xFF,
483 } else 489 rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE]);
490 else
484 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]); 491 efuse_read_all_map(hw, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0]);
485 492
486 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0], 493 memcpy(&rtlefuse->efuse_map[EFUSE_MODIFY_MAP][0],
@@ -632,8 +639,9 @@ static int efuse_one_byte_write(struct ieee80211_hw *hw, u16 addr, u8 data)
632 639
633static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse) 640static void efuse_read_all_map(struct ieee80211_hw *hw, u8 * efuse)
634{ 641{
642 struct rtl_priv *rtlpriv = rtl_priv(hw);
635 efuse_power_switch(hw, false, true); 643 efuse_power_switch(hw, false, true);
636 read_efuse(hw, 0, 128, efuse); 644 read_efuse(hw, 0, rtlpriv->cfg->maps[EFUSE_HWSET_MAX_SIZE], efuse);
637 efuse_power_switch(hw, false, false); 645 efuse_power_switch(hw, false, false);
638} 646}
639 647
@@ -641,7 +649,7 @@ static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
641 u8 efuse_data, u8 offset, u8 *tmpdata, 649 u8 efuse_data, u8 offset, u8 *tmpdata,
642 u8 *readstate) 650 u8 *readstate)
643{ 651{
644 bool bdataempty = true; 652 bool dataempty = true;
645 u8 hoffset; 653 u8 hoffset;
646 u8 tmpidx; 654 u8 tmpidx;
647 u8 hworden; 655 u8 hworden;
@@ -657,13 +665,13 @@ static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
657 &efuse_data)) { 665 &efuse_data)) {
658 tmpdata[tmpidx] = efuse_data; 666 tmpdata[tmpidx] = efuse_data;
659 if (efuse_data != 0xff) 667 if (efuse_data != 0xff)
660 bdataempty = true; 668 dataempty = true;
661 } 669 }
662 } 670 }
663 671
664 if (bdataempty == true) 672 if (dataempty == true) {
665 *readstate = PG_STATE_DATA; 673 *readstate = PG_STATE_DATA;
666 else { 674 } else {
667 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1; 675 *efuse_addr = *efuse_addr + (word_cnts * 2) + 1;
668 *readstate = PG_STATE_HEADER; 676 *readstate = PG_STATE_HEADER;
669 } 677 }
@@ -677,9 +685,7 @@ static void efuse_read_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
677static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data) 685static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data)
678{ 686{
679 u8 readstate = PG_STATE_HEADER; 687 u8 readstate = PG_STATE_HEADER;
680
681 bool continual = true; 688 bool continual = true;
682
683 u8 efuse_data, word_cnts = 0; 689 u8 efuse_data, word_cnts = 0;
684 u16 efuse_addr = 0; 690 u16 efuse_addr = 0;
685 u8 tmpdata[8]; 691 u8 tmpdata[8];
@@ -795,19 +801,20 @@ static void efuse_write_data_case1(struct ieee80211_hw *hw, u16 *efuse_addr,
795 tmp_word_en &= (~BIT(1)); 801 tmp_word_en &= (~BIT(1));
796 802
797 if ((target_pkt->word_en & BIT(2)) ^ 803 if ((target_pkt->word_en & BIT(2)) ^
798 (match_word_en & BIT(2))) 804 (match_word_en & BIT(2)))
799 tmp_word_en &= (~BIT(2)); 805 tmp_word_en &= (~BIT(2));
800 806
801 if ((target_pkt->word_en & BIT(3)) ^ 807 if ((target_pkt->word_en & BIT(3)) ^
802 (match_word_en & BIT(3))) 808 (match_word_en & BIT(3)))
803 tmp_word_en &= (~BIT(3)); 809 tmp_word_en &= (~BIT(3));
804 810
805 if ((tmp_word_en & 0x0F) != 0x0F) { 811 if ((tmp_word_en & 0x0F) != 0x0F) {
806 *efuse_addr = efuse_get_current_size(hw); 812 *efuse_addr = efuse_get_current_size(hw);
807 target_pkt->offset = offset; 813 target_pkt->offset = offset;
808 target_pkt->word_en = tmp_word_en; 814 target_pkt->word_en = tmp_word_en;
809 } else 815 } else {
810 *continual = false; 816 *continual = false;
817 }
811 *write_state = PG_STATE_HEADER; 818 *write_state = PG_STATE_HEADER;
812 *repeat_times += 1; 819 *repeat_times += 1;
813 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { 820 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
@@ -842,9 +849,9 @@ static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
842 efuse_one_byte_write(hw, *efuse_addr, pg_header); 849 efuse_one_byte_write(hw, *efuse_addr, pg_header);
843 efuse_one_byte_read(hw, *efuse_addr, &tmp_header); 850 efuse_one_byte_read(hw, *efuse_addr, &tmp_header);
844 851
845 if (tmp_header == pg_header) 852 if (tmp_header == pg_header) {
846 *write_state = PG_STATE_DATA; 853 *write_state = PG_STATE_DATA;
847 else if (tmp_header == 0xFF) { 854 } else if (tmp_header == 0xFF) {
848 *write_state = PG_STATE_HEADER; 855 *write_state = PG_STATE_HEADER;
849 *repeat_times += 1; 856 *repeat_times += 1;
850 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) { 857 if (*repeat_times > EFUSE_REPEAT_THRESHOLD_) {
@@ -871,11 +878,13 @@ static void efuse_write_data_case2(struct ieee80211_hw *hw, u16 *efuse_addr,
871 reorg_worden, 878 reorg_worden,
872 originaldata); 879 originaldata);
873 *efuse_addr = efuse_get_current_size(hw); 880 *efuse_addr = efuse_get_current_size(hw);
874 } else 881 } else {
875 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) 882 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2)
876 + 1; 883 + 1;
877 } else 884 }
885 } else {
878 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1; 886 *efuse_addr = *efuse_addr + (tmp_word_cnts * 2) + 1;
887 }
879 888
880 *write_state = PG_STATE_HEADER; 889 *write_state = PG_STATE_HEADER;
881 *repeat_times += 1; 890 *repeat_times += 1;
@@ -1069,10 +1078,12 @@ static u8 efuse_word_enable_data_write(struct ieee80211_hw *hw,
1069static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate) 1078static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1070{ 1079{
1071 struct rtl_priv *rtlpriv = rtl_priv(hw); 1080 struct rtl_priv *rtlpriv = rtl_priv(hw);
1081 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1072 u8 tempval; 1082 u8 tempval;
1073 u16 tmpV16; 1083 u16 tmpV16;
1074 1084
1075 if (pwrstate) { 1085 if (pwrstate && (rtlhal->hw_type !=
1086 HARDWARE_TYPE_RTL8192SE)) {
1076 tmpV16 = rtl_read_word(rtlpriv, 1087 tmpV16 = rtl_read_word(rtlpriv,
1077 rtlpriv->cfg->maps[SYS_ISO_CTRL]); 1088 rtlpriv->cfg->maps[SYS_ISO_CTRL]);
1078 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) { 1089 if (!(tmpV16 & rtlpriv->cfg->maps[EFUSE_PWC_EV12V])) {
@@ -1105,13 +1116,22 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1105 tempval = rtl_read_byte(rtlpriv, 1116 tempval = rtl_read_byte(rtlpriv,
1106 rtlpriv->cfg->maps[EFUSE_TEST] + 1117 rtlpriv->cfg->maps[EFUSE_TEST] +
1107 3); 1118 3);
1108 tempval &= 0x0F; 1119
1109 tempval |= (VOLTAGE_V25 << 4); 1120 if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) {
1121 tempval &= 0x0F;
1122 tempval |= (VOLTAGE_V25 << 4);
1123 }
1124
1110 rtl_write_byte(rtlpriv, 1125 rtl_write_byte(rtlpriv,
1111 rtlpriv->cfg->maps[EFUSE_TEST] + 3, 1126 rtlpriv->cfg->maps[EFUSE_TEST] + 3,
1112 (tempval | 0x80)); 1127 (tempval | 0x80));
1113 } 1128 }
1114 1129
1130 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1131 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1132 0x03);
1133 }
1134
1115 } else { 1135 } else {
1116 if (write) { 1136 if (write) {
1117 tempval = rtl_read_byte(rtlpriv, 1137 tempval = rtl_read_byte(rtlpriv,
@@ -1122,6 +1142,11 @@ static void efuse_power_switch(struct ieee80211_hw *hw, u8 write, u8 pwrstate)
1122 (tempval & 0x7F)); 1142 (tempval & 0x7F));
1123 } 1143 }
1124 1144
1145 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
1146 rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[EFUSE_CLK],
1147 0x02);
1148 }
1149
1125 } 1150 }
1126 1151
1127} 1152}
diff --git a/drivers/net/wireless/rtlwifi/efuse.h b/drivers/net/wireless/rtlwifi/efuse.h
index 47774dd4c2a6..164dabaa7615 100644
--- a/drivers/net/wireless/rtlwifi/efuse.h
+++ b/drivers/net/wireless/rtlwifi/efuse.h
@@ -30,9 +30,10 @@
30#ifndef __RTL_EFUSE_H_ 30#ifndef __RTL_EFUSE_H_
31#define __RTL_EFUSE_H_ 31#define __RTL_EFUSE_H_
32 32
33#define EFUSE_IC_ID_OFFSET 506
34
33#define EFUSE_REAL_CONTENT_LEN 512 35#define EFUSE_REAL_CONTENT_LEN 512
34#define EFUSE_MAP_LEN 128 36#define EFUSE_MAP_LEN 128
35#define EFUSE_MAX_SECTION 16
36#define EFUSE_MAX_WORD_UNIT 4 37#define EFUSE_MAX_WORD_UNIT 4
37 38
38#define EFUSE_INIT_MAP 0 39#define EFUSE_INIT_MAP 0
@@ -52,6 +53,7 @@
52#define _PRE_EXECUTE_READ_CMD_ 53#define _PRE_EXECUTE_READ_CMD_
53 54
54#define EFUSE_REPEAT_THRESHOLD_ 3 55#define EFUSE_REPEAT_THRESHOLD_ 3
56#define EFUSE_ERROE_HANDLE 1
55 57
56struct efuse_map { 58struct efuse_map {
57 u8 offset; 59 u8 offset;
@@ -103,6 +105,7 @@ struct efuse_priv {
103 u8 tx_power_g[14]; 105 u8 tx_power_g[14];
104}; 106};
105 107
108extern void read_efuse_byte(struct ieee80211_hw *hw, u16 _offset, u8 *pbuf);
106extern void efuse_initialize(struct ieee80211_hw *hw); 109extern void efuse_initialize(struct ieee80211_hw *hw);
107extern u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address); 110extern u8 efuse_read_1byte(struct ieee80211_hw *hw, u16 address);
108extern void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value); 111extern void efuse_write_1byte(struct ieee80211_hw *hw, u16 address, u8 value);
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index c3dd4cc678ba..3550c9fb96e5 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -32,6 +32,7 @@
32#include "pci.h" 32#include "pci.h"
33#include "base.h" 33#include "base.h"
34#include "ps.h" 34#include "ps.h"
35#include "efuse.h"
35 36
36static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = { 37static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
37 INTEL_VENDOR_ID, 38 INTEL_VENDOR_ID,
@@ -40,6 +41,31 @@ static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
40 SIS_VENDOR_ID 41 SIS_VENDOR_ID
41}; 42};
42 43
44static const u8 ac_to_hwq[] = {
45 VO_QUEUE,
46 VI_QUEUE,
47 BE_QUEUE,
48 BK_QUEUE
49};
50
51static u8 _rtl_mac_to_hwqueue(struct ieee80211_hw *hw,
52 struct sk_buff *skb)
53{
54 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
55 __le16 fc = rtl_get_fc(skb);
56 u8 queue_index = skb_get_queue_mapping(skb);
57
58 if (unlikely(ieee80211_is_beacon(fc)))
59 return BEACON_QUEUE;
60 if (ieee80211_is_mgmt(fc))
61 return MGNT_QUEUE;
62 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
63 if (ieee80211_is_nullfunc(fc))
64 return HIGH_QUEUE;
65
66 return ac_to_hwq[queue_index];
67}
68
43/* Update PCI dependent default settings*/ 69/* Update PCI dependent default settings*/
44static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw) 70static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw)
45{ 71{
@@ -48,6 +74,7 @@ static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw)
48 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 74 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
49 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 75 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
50 u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor; 76 u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
77 u8 init_aspm;
51 78
52 ppsc->reg_rfps_level = 0; 79 ppsc->reg_rfps_level = 0;
53 ppsc->support_aspm = 0; 80 ppsc->support_aspm = 0;
@@ -113,25 +140,45 @@ static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw)
113 140
114 /*Set HW definition to determine if it supports ASPM. */ 141 /*Set HW definition to determine if it supports ASPM. */
115 switch (rtlpci->const_support_pciaspm) { 142 switch (rtlpci->const_support_pciaspm) {
116 case 0: 143 case 0:{
117 /*Not support ASPM. */ 144 /*Not support ASPM. */
118 ppsc->support_aspm = false; 145 bool support_aspm = false;
119 break; 146 ppsc->support_aspm = support_aspm;
120 case 1: 147 break;
121 /*Support ASPM. */ 148 }
122 ppsc->support_aspm = true; 149 case 1:{
123 ppsc->support_backdoor = true; 150 /*Support ASPM. */
124 break; 151 bool support_aspm = true;
152 bool support_backdoor = true;
153 ppsc->support_aspm = support_aspm;
154
155 /*if (priv->oem_id == RT_CID_TOSHIBA &&
156 !priv->ndis_adapter.amd_l1_patch)
157 support_backdoor = false; */
158
159 ppsc->support_backdoor = support_backdoor;
160
161 break;
162 }
125 case 2: 163 case 2:
126 /*ASPM value set by chipset. */ 164 /*ASPM value set by chipset. */
127 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) 165 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) {
128 ppsc->support_aspm = true; 166 bool support_aspm = true;
167 ppsc->support_aspm = support_aspm;
168 }
129 break; 169 break;
130 default: 170 default:
131 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 171 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
132 ("switch case not process\n")); 172 ("switch case not process\n"));
133 break; 173 break;
134 } 174 }
175
176 /* toshiba aspm issue, toshiba will set aspm selfly
177 * so we should not set aspm in driver */
178 pci_read_config_byte(rtlpci->pdev, 0x80, &init_aspm);
179 if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8192SE &&
180 init_aspm == 0x43)
181 ppsc->support_aspm = false;
135} 182}
136 183
137static bool _rtl_pci_platform_switch_device_pci_aspm( 184static bool _rtl_pci_platform_switch_device_pci_aspm(
@@ -139,8 +186,11 @@ static bool _rtl_pci_platform_switch_device_pci_aspm(
139 u8 value) 186 u8 value)
140{ 187{
141 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 188 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
189 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
190
191 if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE)
192 value |= 0x40;
142 193
143 value |= 0x40;
144 pci_write_config_byte(rtlpci->pdev, 0x80, value); 194 pci_write_config_byte(rtlpci->pdev, 0x80, value);
145 195
146 return false; 196 return false;
@@ -150,11 +200,13 @@ static bool _rtl_pci_platform_switch_device_pci_aspm(
150static bool _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value) 200static bool _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value)
151{ 201{
152 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 202 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
153 u8 buffer; 203 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
154 204
155 buffer = value;
156 pci_write_config_byte(rtlpci->pdev, 0x81, value); 205 pci_write_config_byte(rtlpci->pdev, 0x81, value);
157 206
207 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
208 udelay(100);
209
158 return true; 210 return true;
159} 211}
160 212
@@ -175,6 +227,9 @@ static void rtl_pci_disable_aspm(struct ieee80211_hw *hw)
175 u16 aspmlevel = 0; 227 u16 aspmlevel = 0;
176 u8 tmp_u1b = 0; 228 u8 tmp_u1b = 0;
177 229
230 if (!ppsc->support_aspm)
231 return;
232
178 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { 233 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
179 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, 234 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
180 ("PCI(Bridge) UNKNOWN.\n")); 235 ("PCI(Bridge) UNKNOWN.\n"));
@@ -228,6 +283,9 @@ static void rtl_pci_enable_aspm(struct ieee80211_hw *hw)
228 u8 u_pcibridge_aspmsetting; 283 u8 u_pcibridge_aspmsetting;
229 u8 u_device_aspmsetting; 284 u8 u_device_aspmsetting;
230 285
286 if (!ppsc->support_aspm)
287 return;
288
231 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { 289 if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
232 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, 290 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
233 ("PCI(Bridge) UNKNOWN.\n")); 291 ("PCI(Bridge) UNKNOWN.\n"));
@@ -272,7 +330,7 @@ static void rtl_pci_enable_aspm(struct ieee80211_hw *hw)
272 RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0); 330 RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0);
273 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ); 331 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ);
274 } 332 }
275 udelay(200); 333 udelay(100);
276} 334}
277 335
278static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw *hw) 336static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw *hw)
@@ -309,13 +367,13 @@ static void rtl_pci_get_linkcontrol_field(struct ieee80211_hw *hw)
309 u8 capabilityoffset = pcipriv->ndis_adapter.pcibridge_pciehdr_offset; 367 u8 capabilityoffset = pcipriv->ndis_adapter.pcibridge_pciehdr_offset;
310 u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; 368 u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport;
311 u8 linkctrl_reg; 369 u8 linkctrl_reg;
312 u8 num4bBytes; 370 u8 num4bbytes;
313 371
314 num4bBytes = (capabilityoffset + 0x10) / 4; 372 num4bbytes = (capabilityoffset + 0x10) / 4;
315 373
316 /*Read Link Control Register */ 374 /*Read Link Control Register */
317 rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, 375 rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS,
318 pcicfg_addrport + (num4bBytes << 2)); 376 pcicfg_addrport + (num4bbytes << 2));
319 rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &linkctrl_reg); 377 rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &linkctrl_reg);
320 378
321 pcipriv->ndis_adapter.pcibridge_linkctrlreg = linkctrl_reg; 379 pcipriv->ndis_adapter.pcibridge_linkctrlreg = linkctrl_reg;
@@ -348,7 +406,7 @@ static void rtl_pci_parse_configuration(struct pci_dev *pdev,
348 pci_write_config_byte(pdev, 0x70f, tmp); 406 pci_write_config_byte(pdev, 0x70f, tmp);
349} 407}
350 408
351static void _rtl_pci_initialize_adapter_common(struct ieee80211_hw *hw) 409static void rtl_pci_init_aspm(struct ieee80211_hw *hw)
352{ 410{
353 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 411 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
354 412
@@ -362,52 +420,6 @@ static void _rtl_pci_initialize_adapter_common(struct ieee80211_hw *hw)
362 420
363} 421}
364 422
365static void rtl_pci_init_aspm(struct ieee80211_hw *hw)
366{
367 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
368
369 /*close ASPM for AMD defaultly */
370 rtlpci->const_amdpci_aspm = 0;
371
372 /*
373 * ASPM PS mode.
374 * 0 - Disable ASPM,
375 * 1 - Enable ASPM without Clock Req,
376 * 2 - Enable ASPM with Clock Req,
377 * 3 - Always Enable ASPM with Clock Req,
378 * 4 - Always Enable ASPM without Clock Req.
379 * set defult to RTL8192CE:3 RTL8192E:2
380 * */
381 rtlpci->const_pci_aspm = 3;
382
383 /*Setting for PCI-E device */
384 rtlpci->const_devicepci_aspm_setting = 0x03;
385
386 /*Setting for PCI-E bridge */
387 rtlpci->const_hostpci_aspm_setting = 0x02;
388
389 /*
390 * In Hw/Sw Radio Off situation.
391 * 0 - Default,
392 * 1 - From ASPM setting without low Mac Pwr,
393 * 2 - From ASPM setting with low Mac Pwr,
394 * 3 - Bus D3
395 * set default to RTL8192CE:0 RTL8192SE:2
396 */
397 rtlpci->const_hwsw_rfoff_d3 = 0;
398
399 /*
400 * This setting works for those device with
401 * backdoor ASPM setting such as EPHY setting.
402 * 0 - Not support ASPM,
403 * 1 - Support ASPM,
404 * 2 - According to chipset.
405 */
406 rtlpci->const_support_pciaspm = 1;
407
408 _rtl_pci_initialize_adapter_common(hw);
409}
410
411static void _rtl_pci_io_handler_init(struct device *dev, 423static void _rtl_pci_io_handler_init(struct device *dev,
412 struct ieee80211_hw *hw) 424 struct ieee80211_hw *hw)
413{ 425{
@@ -429,6 +441,90 @@ static void _rtl_pci_io_handler_release(struct ieee80211_hw *hw)
429{ 441{
430} 442}
431 443
444static bool _rtl_update_earlymode_info(struct ieee80211_hw *hw,
445 struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc, u8 tid)
446{
447 struct rtl_priv *rtlpriv = rtl_priv(hw);
448 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
449 u8 additionlen = FCS_LEN;
450 struct sk_buff *next_skb;
451
452 /* here open is 4, wep/tkip is 8, aes is 12*/
453 if (info->control.hw_key)
454 additionlen += info->control.hw_key->icv_len;
455
456 /* The most skb num is 6 */
457 tcb_desc->empkt_num = 0;
458 spin_lock_bh(&rtlpriv->locks.waitq_lock);
459 skb_queue_walk(&rtlpriv->mac80211.skb_waitq[tid], next_skb) {
460 struct ieee80211_tx_info *next_info;
461
462 next_info = IEEE80211_SKB_CB(next_skb);
463 if (next_info->flags & IEEE80211_TX_CTL_AMPDU) {
464 tcb_desc->empkt_len[tcb_desc->empkt_num] =
465 next_skb->len + additionlen;
466 tcb_desc->empkt_num++;
467 } else {
468 break;
469 }
470
471 if (skb_queue_is_last(&rtlpriv->mac80211.skb_waitq[tid],
472 next_skb))
473 break;
474
475 if (tcb_desc->empkt_num >= 5)
476 break;
477 }
478 spin_unlock_bh(&rtlpriv->locks.waitq_lock);
479
480 return true;
481}
482
483/* just for early mode now */
484static void _rtl_pci_tx_chk_waitq(struct ieee80211_hw *hw)
485{
486 struct rtl_priv *rtlpriv = rtl_priv(hw);
487 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
488 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
489 struct sk_buff *skb = NULL;
490 struct ieee80211_tx_info *info = NULL;
491 int tid; /* should be int */
492
493 if (!rtlpriv->rtlhal.earlymode_enable)
494 return;
495
496 /* we juse use em for BE/BK/VI/VO */
497 for (tid = 7; tid >= 0; tid--) {
498 u8 hw_queue = ac_to_hwq[rtl_tid_to_ac(hw, tid)];
499 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
500 while (!mac->act_scanning &&
501 rtlpriv->psc.rfpwr_state == ERFON) {
502 struct rtl_tcb_desc tcb_desc;
503 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
504
505 spin_lock_bh(&rtlpriv->locks.waitq_lock);
506 if (!skb_queue_empty(&mac->skb_waitq[tid]) &&
507 (ring->entries - skb_queue_len(&ring->queue) > 5)) {
508 skb = skb_dequeue(&mac->skb_waitq[tid]);
509 } else {
510 spin_unlock_bh(&rtlpriv->locks.waitq_lock);
511 break;
512 }
513 spin_unlock_bh(&rtlpriv->locks.waitq_lock);
514
515 /* Some macaddr can't do early mode. like
516 * multicast/broadcast/no_qos data */
517 info = IEEE80211_SKB_CB(skb);
518 if (info->flags & IEEE80211_TX_CTL_AMPDU)
519 _rtl_update_earlymode_info(hw, skb,
520 &tcb_desc, tid);
521
522 rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc);
523 }
524 }
525}
526
527
432static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio) 528static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
433{ 529{
434 struct rtl_priv *rtlpriv = rtl_priv(hw); 530 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -440,6 +536,8 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
440 struct rtl_tx_desc *entry = &ring->desc[ring->idx]; 536 struct rtl_tx_desc *entry = &ring->desc[ring->idx];
441 struct sk_buff *skb; 537 struct sk_buff *skb;
442 struct ieee80211_tx_info *info; 538 struct ieee80211_tx_info *info;
539 __le16 fc;
540 u8 tid;
443 541
444 u8 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry, true, 542 u8 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry, true,
445 HW_DESC_OWN); 543 HW_DESC_OWN);
@@ -460,6 +558,10 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
460 HW_DESC_TXBUFF_ADDR), 558 HW_DESC_TXBUFF_ADDR),
461 skb->len, PCI_DMA_TODEVICE); 559 skb->len, PCI_DMA_TODEVICE);
462 560
561 /* remove early mode header */
562 if (rtlpriv->rtlhal.earlymode_enable)
563 skb_pull(skb, EM_HDR_LEN);
564
463 RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE, 565 RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE,
464 ("new ring->idx:%d, " 566 ("new ring->idx:%d, "
465 "free: skb_queue_len:%d, free: seq:%x\n", 567 "free: skb_queue_len:%d, free: seq:%x\n",
@@ -467,6 +569,30 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
467 skb_queue_len(&ring->queue), 569 skb_queue_len(&ring->queue),
468 *(u16 *) (skb->data + 22))); 570 *(u16 *) (skb->data + 22)));
469 571
572 if (prio == TXCMD_QUEUE) {
573 dev_kfree_skb(skb);
574 goto tx_status_ok;
575
576 }
577
578 /* for sw LPS, just after NULL skb send out, we can
579 * sure AP kown we are sleeped, our we should not let
580 * rf to sleep*/
581 fc = rtl_get_fc(skb);
582 if (ieee80211_is_nullfunc(fc)) {
583 if (ieee80211_has_pm(fc)) {
584 rtlpriv->mac80211.offchan_deley = true;
585 rtlpriv->psc.state_inap = 1;
586 } else {
587 rtlpriv->psc.state_inap = 0;
588 }
589 }
590
591 /* update tid tx pkt num */
592 tid = rtl_get_tid(skb);
593 if (tid <= 7)
594 rtlpriv->link_info.tidtx_inperiod[tid]++;
595
470 info = IEEE80211_SKB_CB(skb); 596 info = IEEE80211_SKB_CB(skb);
471 ieee80211_tx_info_clear_status(info); 597 ieee80211_tx_info_clear_status(info);
472 598
@@ -489,7 +615,7 @@ static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
489 skb_get_queue_mapping 615 skb_get_queue_mapping
490 (skb)); 616 (skb));
491 } 617 }
492 618tx_status_ok:
493 skb = NULL; 619 skb = NULL;
494 } 620 }
495 621
@@ -561,23 +687,21 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
561 *skb_trim(skb, skb->len - 4); 687 *skb_trim(skb, skb->len - 4);
562 */ 688 */
563 689
564 hdr = (struct ieee80211_hdr *)(skb->data); 690 hdr = rtl_get_hdr(skb);
565 fc = hdr->frame_control; 691 fc = rtl_get_fc(skb);
566 692
567 if (!stats.crc) { 693 if (!stats.crc || !stats.hwerror) {
568 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, 694 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status,
569 sizeof(rx_status)); 695 sizeof(rx_status));
570 696
571 if (is_broadcast_ether_addr(hdr->addr1)) 697 if (is_broadcast_ether_addr(hdr->addr1)) {
572 ;/*TODO*/ 698 ;/*TODO*/
573 else { 699 } else if (is_multicast_ether_addr(hdr->addr1)) {
574 if (is_multicast_ether_addr(hdr->addr1)) 700 ;/*TODO*/
575 ;/*TODO*/ 701 } else {
576 else { 702 unicast = true;
577 unicast = true; 703 rtlpriv->stats.rxbytesunicast +=
578 rtlpriv->stats.rxbytesunicast += 704 skb->len;
579 skb->len;
580 }
581 } 705 }
582 706
583 rtl_is_special_data(hw, skb, false); 707 rtl_is_special_data(hw, skb, false);
@@ -591,28 +715,38 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
591 num_rx_inperiod++; 715 num_rx_inperiod++;
592 } 716 }
593 717
594 if (unlikely(!rtl_action_proc(hw, skb, 718 /* for sw lps */
595 false))) { 719 rtl_swlps_beacon(hw, (void *)skb->data,
720 skb->len);
721 rtl_recognize_peer(hw, (void *)skb->data,
722 skb->len);
723 if ((rtlpriv->mac80211.opmode ==
724 NL80211_IFTYPE_AP) &&
725 (rtlpriv->rtlhal.current_bandtype ==
726 BAND_ON_2_4G) &&
727 (ieee80211_is_beacon(fc) ||
728 ieee80211_is_probe_resp(fc))) {
596 dev_kfree_skb_any(skb); 729 dev_kfree_skb_any(skb);
597 } else { 730 } else {
598 struct sk_buff *uskb = NULL; 731 if (unlikely(!rtl_action_proc(hw, skb,
599 u8 *pdata; 732 false))) {
600 uskb = dev_alloc_skb(skb->len + 128); 733 dev_kfree_skb_any(skb);
601 if (!uskb) { 734 } else {
602 RT_TRACE(rtlpriv, 735 struct sk_buff *uskb = NULL;
603 (COMP_INTR | COMP_RECV), 736 u8 *pdata;
604 DBG_EMERG, 737 uskb = dev_alloc_skb(skb->len
605 ("can't alloc rx skb\n")); 738 + 128);
606 goto done; 739 memcpy(IEEE80211_SKB_RXCB(uskb),
740 &rx_status,
741 sizeof(rx_status));
742 pdata = (u8 *)skb_put(uskb,
743 skb->len);
744 memcpy(pdata, skb->data,
745 skb->len);
746 dev_kfree_skb_any(skb);
747
748 ieee80211_rx_irqsafe(hw, uskb);
607 } 749 }
608 memcpy(IEEE80211_SKB_RXCB(uskb),
609 &rx_status,
610 sizeof(rx_status));
611 pdata = (u8 *)skb_put(uskb, skb->len);
612 memcpy(pdata, skb->data, skb->len);
613 dev_kfree_skb_any(skb);
614
615 ieee80211_rx_irqsafe(hw, uskb);
616 } 750 }
617 } else { 751 } else {
618 dev_kfree_skb_any(skb); 752 dev_kfree_skb_any(skb);
@@ -627,7 +761,7 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
627 new_skb = dev_alloc_skb(rtlpci->rxbuffersize); 761 new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
628 if (unlikely(!new_skb)) { 762 if (unlikely(!new_skb)) {
629 RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV), 763 RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV),
630 DBG_EMERG, 764 DBG_DMESG,
631 ("can't alloc skb for rx\n")); 765 ("can't alloc skb for rx\n"));
632 goto done; 766 goto done;
633 } 767 }
@@ -645,7 +779,7 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
645 779
646 } 780 }
647done: 781done:
648 bufferaddress = (u32)(*((dma_addr_t *) skb->cb)); 782 bufferaddress = (*((dma_addr_t *)skb->cb));
649 tmp_one = 1; 783 tmp_one = 1;
650 rtlpriv->cfg->ops->set_desc((u8 *) pdesc, false, 784 rtlpriv->cfg->ops->set_desc((u8 *) pdesc, false,
651 HW_DESC_RXBUFF_ADDR, 785 HW_DESC_RXBUFF_ADDR,
@@ -674,6 +808,7 @@ static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id)
674 struct ieee80211_hw *hw = dev_id; 808 struct ieee80211_hw *hw = dev_id;
675 struct rtl_priv *rtlpriv = rtl_priv(hw); 809 struct rtl_priv *rtlpriv = rtl_priv(hw);
676 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 810 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
811 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
677 unsigned long flags; 812 unsigned long flags;
678 u32 inta = 0; 813 u32 inta = 0;
679 u32 intb = 0; 814 u32 intb = 0;
@@ -760,23 +895,36 @@ static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id)
760 _rtl_pci_tx_isr(hw, VO_QUEUE); 895 _rtl_pci_tx_isr(hw, VO_QUEUE);
761 } 896 }
762 897
898 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
899 if (inta & rtlpriv->cfg->maps[RTL_IMR_COMDOK]) {
900 rtlpriv->link_info.num_tx_inperiod++;
901
902 RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
903 ("CMD TX OK interrupt!\n"));
904 _rtl_pci_tx_isr(hw, TXCMD_QUEUE);
905 }
906 }
907
763 /*<2> Rx related */ 908 /*<2> Rx related */
764 if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) { 909 if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) {
765 RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, ("Rx ok interrupt!\n")); 910 RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, ("Rx ok interrupt!\n"));
766 tasklet_schedule(&rtlpriv->works.irq_tasklet); 911 _rtl_pci_rx_interrupt(hw);
767 } 912 }
768 913
769 if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) { 914 if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) {
770 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 915 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
771 ("rx descriptor unavailable!\n")); 916 ("rx descriptor unavailable!\n"));
772 tasklet_schedule(&rtlpriv->works.irq_tasklet); 917 _rtl_pci_rx_interrupt(hw);
773 } 918 }
774 919
775 if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) { 920 if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) {
776 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("rx overflow !\n")); 921 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("rx overflow !\n"));
777 tasklet_schedule(&rtlpriv->works.irq_tasklet); 922 _rtl_pci_rx_interrupt(hw);
778 } 923 }
779 924
925 if (rtlpriv->rtlhal.earlymode_enable)
926 tasklet_schedule(&rtlpriv->works.irq_tasklet);
927
780 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); 928 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
781 return IRQ_HANDLED; 929 return IRQ_HANDLED;
782 930
@@ -787,7 +935,7 @@ done:
787 935
788static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw) 936static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw)
789{ 937{
790 _rtl_pci_rx_interrupt(hw); 938 _rtl_pci_tx_chk_waitq(hw);
791} 939}
792 940
793static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw) 941static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
@@ -795,14 +943,15 @@ static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
795 struct rtl_priv *rtlpriv = rtl_priv(hw); 943 struct rtl_priv *rtlpriv = rtl_priv(hw);
796 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 944 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
797 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 945 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
798 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[BEACON_QUEUE]; 946 struct rtl8192_tx_ring *ring = NULL;
799 struct ieee80211_hdr *hdr = NULL; 947 struct ieee80211_hdr *hdr = NULL;
800 struct ieee80211_tx_info *info = NULL; 948 struct ieee80211_tx_info *info = NULL;
801 struct sk_buff *pskb = NULL; 949 struct sk_buff *pskb = NULL;
802 struct rtl_tx_desc *pdesc = NULL; 950 struct rtl_tx_desc *pdesc = NULL;
803 unsigned int queue_index; 951 struct rtl_tcb_desc tcb_desc;
804 u8 temp_one = 1; 952 u8 temp_one = 1;
805 953
954 memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
806 ring = &rtlpci->tx_ring[BEACON_QUEUE]; 955 ring = &rtlpci->tx_ring[BEACON_QUEUE];
807 pskb = __skb_dequeue(&ring->queue); 956 pskb = __skb_dequeue(&ring->queue);
808 if (pskb) 957 if (pskb)
@@ -812,14 +961,11 @@ static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
812 pskb = ieee80211_beacon_get(hw, mac->vif); 961 pskb = ieee80211_beacon_get(hw, mac->vif);
813 if (pskb == NULL) 962 if (pskb == NULL)
814 return; 963 return;
815 hdr = (struct ieee80211_hdr *)(pskb->data); 964 hdr = rtl_get_hdr(pskb);
816 info = IEEE80211_SKB_CB(pskb); 965 info = IEEE80211_SKB_CB(pskb);
817
818 queue_index = BEACON_QUEUE;
819
820 pdesc = &ring->desc[0]; 966 pdesc = &ring->desc[0];
821 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *) pdesc, 967 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *) pdesc,
822 info, pskb, queue_index); 968 info, pskb, BEACON_QUEUE, &tcb_desc);
823 969
824 __skb_queue_tail(&ring->queue, pskb); 970 __skb_queue_tail(&ring->queue, pskb);
825 971
@@ -861,7 +1007,6 @@ static void _rtl_pci_init_struct(struct ieee80211_hw *hw,
861 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1007 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
862 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1008 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
863 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1009 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
864 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
865 1010
866 rtlpci->up_first_time = true; 1011 rtlpci->up_first_time = true;
867 rtlpci->being_init_adapter = false; 1012 rtlpci->being_init_adapter = false;
@@ -869,31 +1014,20 @@ static void _rtl_pci_init_struct(struct ieee80211_hw *hw,
869 rtlhal->hw = hw; 1014 rtlhal->hw = hw;
870 rtlpci->pdev = pdev; 1015 rtlpci->pdev = pdev;
871 1016
872 ppsc->inactiveps = false;
873 ppsc->leisure_ps = true;
874 ppsc->fwctrl_lps = true;
875 ppsc->reg_fwctrl_lps = 3;
876 ppsc->reg_max_lps_awakeintvl = 5;
877
878 if (ppsc->reg_fwctrl_lps == 1)
879 ppsc->fwctrl_psmode = FW_PS_MIN_MODE;
880 else if (ppsc->reg_fwctrl_lps == 2)
881 ppsc->fwctrl_psmode = FW_PS_MAX_MODE;
882 else if (ppsc->reg_fwctrl_lps == 3)
883 ppsc->fwctrl_psmode = FW_PS_DTIM_MODE;
884
885 /*Tx/Rx related var */ 1017 /*Tx/Rx related var */
886 _rtl_pci_init_trx_var(hw); 1018 _rtl_pci_init_trx_var(hw);
887 1019
888 /*IBSS*/ mac->beacon_interval = 100; 1020 /*IBSS*/ mac->beacon_interval = 100;
889 1021
890 /*AMPDU*/ mac->min_space_cfg = 0; 1022 /*AMPDU*/
1023 mac->min_space_cfg = 0;
891 mac->max_mss_density = 0; 1024 mac->max_mss_density = 0;
892 /*set sane AMPDU defaults */ 1025 /*set sane AMPDU defaults */
893 mac->current_ampdu_density = 7; 1026 mac->current_ampdu_density = 7;
894 mac->current_ampdu_factor = 3; 1027 mac->current_ampdu_factor = 3;
895 1028
896 /*QOS*/ rtlpci->acm_method = eAcmWay2_SW; 1029 /*QOS*/
1030 rtlpci->acm_method = eAcmWay2_SW;
897 1031
898 /*task */ 1032 /*task */
899 tasklet_init(&rtlpriv->works.irq_tasklet, 1033 tasklet_init(&rtlpriv->works.irq_tasklet,
@@ -934,7 +1068,8 @@ static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
934 ("queue:%d, ring_addr:%p\n", prio, ring)); 1068 ("queue:%d, ring_addr:%p\n", prio, ring));
935 1069
936 for (i = 0; i < entries; i++) { 1070 for (i = 0; i < entries; i++) {
937 nextdescaddress = (u32) dma + ((i + 1) % entries) * 1071 nextdescaddress = (u32) dma +
1072 ((i + 1) % entries) *
938 sizeof(*ring); 1073 sizeof(*ring);
939 1074
940 rtlpriv->cfg->ops->set_desc((u8 *)&(ring[i]), 1075 rtlpriv->cfg->ops->set_desc((u8 *)&(ring[i]),
@@ -999,7 +1134,7 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
999 rtlpci->rxbuffersize, 1134 rtlpci->rxbuffersize,
1000 PCI_DMA_FROMDEVICE); 1135 PCI_DMA_FROMDEVICE);
1001 1136
1002 bufferaddress = (u32)(*((dma_addr_t *)skb->cb)); 1137 bufferaddress = (*((dma_addr_t *)skb->cb));
1003 rtlpriv->cfg->ops->set_desc((u8 *)entry, false, 1138 rtlpriv->cfg->ops->set_desc((u8 *)entry, false,
1004 HW_DESC_RXBUFF_ADDR, 1139 HW_DESC_RXBUFF_ADDR,
1005 (u8 *)&bufferaddress); 1140 (u8 *)&bufferaddress);
@@ -1182,72 +1317,73 @@ int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw)
1182 return 0; 1317 return 0;
1183} 1318}
1184 1319
1185static unsigned int _rtl_mac_to_hwqueue(__le16 fc, 1320static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw *hw,
1186 unsigned int mac80211_queue_index) 1321 struct sk_buff *skb)
1187{ 1322{
1188 unsigned int hw_queue_index; 1323 struct rtl_priv *rtlpriv = rtl_priv(hw);
1189 1324 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1190 if (unlikely(ieee80211_is_beacon(fc))) { 1325 struct ieee80211_sta *sta = info->control.sta;
1191 hw_queue_index = BEACON_QUEUE; 1326 struct rtl_sta_info *sta_entry = NULL;
1192 goto out; 1327 u8 tid = rtl_get_tid(skb);
1193 } 1328
1194 1329 if (!sta)
1195 if (ieee80211_is_mgmt(fc)) { 1330 return false;
1196 hw_queue_index = MGNT_QUEUE; 1331 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1197 goto out; 1332
1198 } 1333 if (!rtlpriv->rtlhal.earlymode_enable)
1199 1334 return false;
1200 switch (mac80211_queue_index) { 1335 if (sta_entry->tids[tid].agg.agg_state != RTL_AGG_OPERATIONAL)
1201 case 0: 1336 return false;
1202 hw_queue_index = VO_QUEUE; 1337 if (_rtl_mac_to_hwqueue(hw, skb) > VO_QUEUE)
1203 break; 1338 return false;
1204 case 1: 1339 if (tid > 7)
1205 hw_queue_index = VI_QUEUE; 1340 return false;
1206 break; 1341
1207 case 2: 1342 /* maybe every tid should be checked */
1208 hw_queue_index = BE_QUEUE;; 1343 if (!rtlpriv->link_info.higher_busytxtraffic[tid])
1209 break; 1344 return false;
1210 case 3: 1345
1211 hw_queue_index = BK_QUEUE; 1346 spin_lock_bh(&rtlpriv->locks.waitq_lock);
1212 break; 1347 skb_queue_tail(&rtlpriv->mac80211.skb_waitq[tid], skb);
1213 default: 1348 spin_unlock_bh(&rtlpriv->locks.waitq_lock);
1214 hw_queue_index = BE_QUEUE;
1215 RT_ASSERT(false, ("QSLT_BE queue, skb_queue:%d\n",
1216 mac80211_queue_index));
1217 break;
1218 }
1219 1349
1220out: 1350 return true;
1221 return hw_queue_index;
1222} 1351}
1223 1352
1224static int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 1353static int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
1354 struct rtl_tcb_desc *ptcb_desc)
1225{ 1355{
1226 struct rtl_priv *rtlpriv = rtl_priv(hw); 1356 struct rtl_priv *rtlpriv = rtl_priv(hw);
1227 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1357 struct rtl_sta_info *sta_entry = NULL;
1228 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1358 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1359 struct ieee80211_sta *sta = info->control.sta;
1229 struct rtl8192_tx_ring *ring; 1360 struct rtl8192_tx_ring *ring;
1230 struct rtl_tx_desc *pdesc; 1361 struct rtl_tx_desc *pdesc;
1231 u8 idx; 1362 u8 idx;
1232 unsigned int queue_index, hw_queue; 1363 u8 hw_queue = _rtl_mac_to_hwqueue(hw, skb);
1233 unsigned long flags; 1364 unsigned long flags;
1234 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 1365 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
1235 __le16 fc = hdr->frame_control; 1366 __le16 fc = rtl_get_fc(skb);
1236 u8 *pda_addr = hdr->addr1; 1367 u8 *pda_addr = hdr->addr1;
1237 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1368 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1238 /*ssn */ 1369 /*ssn */
1239 u8 *qc = NULL;
1240 u8 tid = 0; 1370 u8 tid = 0;
1241 u16 seq_number = 0; 1371 u16 seq_number = 0;
1242 u8 own; 1372 u8 own;
1243 u8 temp_one = 1; 1373 u8 temp_one = 1;
1244 1374
1245 if (ieee80211_is_mgmt(fc)) 1375 if (ieee80211_is_auth(fc)) {
1246 rtl_tx_mgmt_proc(hw, skb); 1376 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n"));
1247 rtl_action_proc(hw, skb, true); 1377 rtl_ips_nic_on(hw);
1378 }
1379
1380 if (rtlpriv->psc.sw_ps_enabled) {
1381 if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
1382 !ieee80211_has_pm(fc))
1383 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1384 }
1248 1385
1249 queue_index = skb_get_queue_mapping(skb); 1386 rtl_action_proc(hw, skb, true);
1250 hw_queue = _rtl_mac_to_hwqueue(fc, queue_index);
1251 1387
1252 if (is_multicast_ether_addr(pda_addr)) 1388 if (is_multicast_ether_addr(pda_addr))
1253 rtlpriv->stats.txbytesmulticast += skb->len; 1389 rtlpriv->stats.txbytesmulticast += skb->len;
@@ -1257,7 +1393,6 @@ static int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1257 rtlpriv->stats.txbytesunicast += skb->len; 1393 rtlpriv->stats.txbytesunicast += skb->len;
1258 1394
1259 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); 1395 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
1260
1261 ring = &rtlpci->tx_ring[hw_queue]; 1396 ring = &rtlpci->tx_ring[hw_queue];
1262 if (hw_queue != BEACON_QUEUE) 1397 if (hw_queue != BEACON_QUEUE)
1263 idx = (ring->idx + skb_queue_len(&ring->queue)) % 1398 idx = (ring->idx + skb_queue_len(&ring->queue)) %
@@ -1280,43 +1415,30 @@ static int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1280 return skb->len; 1415 return skb->len;
1281 } 1416 }
1282 1417
1283 /*
1284 *if(ieee80211_is_nullfunc(fc)) {
1285 * spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
1286 * return 1;
1287 *}
1288 */
1289
1290 if (ieee80211_is_data_qos(fc)) { 1418 if (ieee80211_is_data_qos(fc)) {
1291 qc = ieee80211_get_qos_ctl(hdr); 1419 tid = rtl_get_tid(skb);
1292 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 1420 if (sta) {
1293 1421 sta_entry = (struct rtl_sta_info *)sta->drv_priv;
1294 seq_number = mac->tids[tid].seq_number; 1422 seq_number = (le16_to_cpu(hdr->seq_ctrl) &
1295 seq_number &= IEEE80211_SCTL_SEQ; 1423 IEEE80211_SCTL_SEQ) >> 4;
1296 /* 1424 seq_number += 1;
1297 *hdr->seq_ctrl = hdr->seq_ctrl & 1425
1298 *cpu_to_le16(IEEE80211_SCTL_FRAG); 1426 if (!ieee80211_has_morefrags(hdr->frame_control))
1299 *hdr->seq_ctrl |= cpu_to_le16(seq_number); 1427 sta_entry->tids[tid].seq_number = seq_number;
1300 */ 1428 }
1301
1302 seq_number += 1;
1303 } 1429 }
1304 1430
1305 if (ieee80211_is_data(fc)) 1431 if (ieee80211_is_data(fc))
1306 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); 1432 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
1307 1433
1308 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *) pdesc, 1434 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc,
1309 info, skb, hw_queue); 1435 info, skb, hw_queue, ptcb_desc);
1310 1436
1311 __skb_queue_tail(&ring->queue, skb); 1437 __skb_queue_tail(&ring->queue, skb);
1312 1438
1313 rtlpriv->cfg->ops->set_desc((u8 *) pdesc, true, 1439 rtlpriv->cfg->ops->set_desc((u8 *)pdesc, true,
1314 HW_DESC_OWN, (u8 *)&temp_one); 1440 HW_DESC_OWN, (u8 *)&temp_one);
1315 1441
1316 if (!ieee80211_has_morefrags(hdr->frame_control)) {
1317 if (qc)
1318 mac->tids[tid].seq_number = seq_number;
1319 }
1320 1442
1321 if ((ring->entries - skb_queue_len(&ring->queue)) < 2 && 1443 if ((ring->entries - skb_queue_len(&ring->queue)) < 2 &&
1322 hw_queue != BEACON_QUEUE) { 1444 hw_queue != BEACON_QUEUE) {
@@ -1338,6 +1460,35 @@ static int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1338 return 0; 1460 return 0;
1339} 1461}
1340 1462
1463static void rtl_pci_flush(struct ieee80211_hw *hw, bool drop)
1464{
1465 struct rtl_priv *rtlpriv = rtl_priv(hw);
1466 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
1467 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1468 u16 i = 0;
1469 int queue_id;
1470 struct rtl8192_tx_ring *ring;
1471
1472 for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) {
1473 u32 queue_len;
1474 ring = &pcipriv->dev.tx_ring[queue_id];
1475 queue_len = skb_queue_len(&ring->queue);
1476 if (queue_len == 0 || queue_id == BEACON_QUEUE ||
1477 queue_id == TXCMD_QUEUE) {
1478 queue_id--;
1479 continue;
1480 } else {
1481 msleep(20);
1482 i++;
1483 }
1484
1485 /* we just wait 1s for all queues */
1486 if (rtlpriv->psc.rfpwr_state == ERFOFF ||
1487 is_hal_stop(rtlhal) || i >= 200)
1488 return;
1489 }
1490}
1491
1341static void rtl_pci_deinit(struct ieee80211_hw *hw) 1492static void rtl_pci_deinit(struct ieee80211_hw *hw)
1342{ 1493{
1343 struct rtl_priv *rtlpriv = rtl_priv(hw); 1494 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -1456,11 +1607,13 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1456 struct pci_dev *bridge_pdev = pdev->bus->self; 1607 struct pci_dev *bridge_pdev = pdev->bus->self;
1457 u16 venderid; 1608 u16 venderid;
1458 u16 deviceid; 1609 u16 deviceid;
1610 u8 revisionid;
1459 u16 irqline; 1611 u16 irqline;
1460 u8 tmp; 1612 u8 tmp;
1461 1613
1462 venderid = pdev->vendor; 1614 venderid = pdev->vendor;
1463 deviceid = pdev->device; 1615 deviceid = pdev->device;
1616 pci_read_config_byte(pdev, 0x8, &revisionid);
1464 pci_read_config_word(pdev, 0x3C, &irqline); 1617 pci_read_config_word(pdev, 0x3C, &irqline);
1465 1618
1466 if (deviceid == RTL_PCI_8192_DID || 1619 if (deviceid == RTL_PCI_8192_DID ||
@@ -1471,7 +1624,7 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1471 deviceid == RTL_PCI_8173_DID || 1624 deviceid == RTL_PCI_8173_DID ||
1472 deviceid == RTL_PCI_8172_DID || 1625 deviceid == RTL_PCI_8172_DID ||
1473 deviceid == RTL_PCI_8171_DID) { 1626 deviceid == RTL_PCI_8171_DID) {
1474 switch (pdev->revision) { 1627 switch (revisionid) {
1475 case RTL_PCI_REVISION_ID_8192PCIE: 1628 case RTL_PCI_REVISION_ID_8192PCIE:
1476 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 1629 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1477 ("8192 PCI-E is found - " 1630 ("8192 PCI-E is found - "
@@ -1500,6 +1653,12 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1500 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 1653 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1501 ("8192C PCI-E is found - " 1654 ("8192C PCI-E is found - "
1502 "vid/did=%x/%x\n", venderid, deviceid)); 1655 "vid/did=%x/%x\n", venderid, deviceid));
1656 } else if (deviceid == RTL_PCI_8192DE_DID ||
1657 deviceid == RTL_PCI_8192DE_DID2) {
1658 rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE;
1659 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1660 ("8192D PCI-E is found - "
1661 "vid/did=%x/%x\n", venderid, deviceid));
1503 } else { 1662 } else {
1504 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 1663 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1505 ("Err: Unknown device -" 1664 ("Err: Unknown device -"
@@ -1508,6 +1667,25 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1508 rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE; 1667 rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE;
1509 } 1668 }
1510 1669
1670 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) {
1671 if (revisionid == 0 || revisionid == 1) {
1672 if (revisionid == 0) {
1673 RT_TRACE(rtlpriv, COMP_INIT,
1674 DBG_LOUD, ("Find 92DE MAC0.\n"));
1675 rtlhal->interfaceindex = 0;
1676 } else if (revisionid == 1) {
1677 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1678 ("Find 92DE MAC1.\n"));
1679 rtlhal->interfaceindex = 1;
1680 }
1681 } else {
1682 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1683 ("Unknown device - "
1684 "VendorID/DeviceID=%x/%x, Revision=%x\n",
1685 venderid, deviceid, revisionid));
1686 rtlhal->interfaceindex = 0;
1687 }
1688 }
1511 /*find bus info */ 1689 /*find bus info */
1512 pcipriv->ndis_adapter.busnumber = pdev->bus->number; 1690 pcipriv->ndis_adapter.busnumber = pdev->bus->number;
1513 pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn); 1691 pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn);
@@ -1533,12 +1711,12 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1533 PCI_SLOT(bridge_pdev->devfn); 1711 PCI_SLOT(bridge_pdev->devfn);
1534 pcipriv->ndis_adapter.pcibridge_funcnum = 1712 pcipriv->ndis_adapter.pcibridge_funcnum =
1535 PCI_FUNC(bridge_pdev->devfn); 1713 PCI_FUNC(bridge_pdev->devfn);
1536 pcipriv->ndis_adapter.pcibridge_pciehdr_offset =
1537 pci_pcie_cap(bridge_pdev);
1538 pcipriv->ndis_adapter.pcicfg_addrport = 1714 pcipriv->ndis_adapter.pcicfg_addrport =
1539 (pcipriv->ndis_adapter.pcibridge_busnum << 16) | 1715 (pcipriv->ndis_adapter.pcibridge_busnum << 16) |
1540 (pcipriv->ndis_adapter.pcibridge_devnum << 11) | 1716 (pcipriv->ndis_adapter.pcibridge_devnum << 11) |
1541 (pcipriv->ndis_adapter.pcibridge_funcnum << 8) | (1 << 31); 1717 (pcipriv->ndis_adapter.pcibridge_funcnum << 8) | (1 << 31);
1718 pcipriv->ndis_adapter.pcibridge_pciehdr_offset =
1719 pci_pcie_cap(bridge_pdev);
1542 pcipriv->ndis_adapter.num4bytes = 1720 pcipriv->ndis_adapter.num4bytes =
1543 (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4; 1721 (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4;
1544 1722
@@ -1621,6 +1799,11 @@ int __devinit rtl_pci_probe(struct pci_dev *pdev,
1621 pcipriv = (void *)rtlpriv->priv; 1799 pcipriv = (void *)rtlpriv->priv;
1622 pcipriv->dev.pdev = pdev; 1800 pcipriv->dev.pdev = pdev;
1623 1801
1802 /* init cfg & intf_ops */
1803 rtlpriv->rtlhal.interface = INTF_PCI;
1804 rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
1805 rtlpriv->intf_ops = &rtl_pci_ops;
1806
1624 /* 1807 /*
1625 *init dbgp flags before all 1808 *init dbgp flags before all
1626 *other functions, because we will 1809 *other functions, because we will
@@ -1638,13 +1821,14 @@ int __devinit rtl_pci_probe(struct pci_dev *pdev,
1638 return err; 1821 return err;
1639 } 1822 }
1640 1823
1641 pmem_start = pci_resource_start(pdev, 2); 1824 pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id);
1642 pmem_len = pci_resource_len(pdev, 2); 1825 pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id);
1643 pmem_flags = pci_resource_flags(pdev, 2); 1826 pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id);
1644 1827
1645 /*shared mem start */ 1828 /*shared mem start */
1646 rtlpriv->io.pci_mem_start = 1829 rtlpriv->io.pci_mem_start =
1647 (unsigned long)pci_iomap(pdev, 2, pmem_len); 1830 (unsigned long)pci_iomap(pdev,
1831 rtlpriv->cfg->bar_id, pmem_len);
1648 if (rtlpriv->io.pci_mem_start == 0) { 1832 if (rtlpriv->io.pci_mem_start == 0) {
1649 RT_ASSERT(false, ("Can't map PCI mem\n")); 1833 RT_ASSERT(false, ("Can't map PCI mem\n"));
1650 goto fail2; 1834 goto fail2;
@@ -1663,11 +1847,6 @@ int __devinit rtl_pci_probe(struct pci_dev *pdev,
1663 pci_write_config_byte(pdev, 0x04, 0x06); 1847 pci_write_config_byte(pdev, 0x04, 0x06);
1664 pci_write_config_byte(pdev, 0x04, 0x07); 1848 pci_write_config_byte(pdev, 0x04, 0x07);
1665 1849
1666 /* init cfg & intf_ops */
1667 rtlpriv->rtlhal.interface = INTF_PCI;
1668 rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
1669 rtlpriv->intf_ops = &rtl_pci_ops;
1670
1671 /* find adapter */ 1850 /* find adapter */
1672 _rtl_pci_find_adapter(pdev, hw); 1851 _rtl_pci_find_adapter(pdev, hw);
1673 1852
@@ -1785,8 +1964,6 @@ void rtl_pci_disconnect(struct pci_dev *pdev)
1785 1964
1786 rtl_pci_deinit(hw); 1965 rtl_pci_deinit(hw);
1787 rtl_deinit_core(hw); 1966 rtl_deinit_core(hw);
1788 if (rtlpriv->cfg->ops->deinit_sw_leds)
1789 rtlpriv->cfg->ops->deinit_sw_leds(hw);
1790 _rtl_pci_io_handler_release(hw); 1967 _rtl_pci_io_handler_release(hw);
1791 rtlpriv->cfg->ops->deinit_sw_vars(hw); 1968 rtlpriv->cfg->ops->deinit_sw_vars(hw);
1792 1969
@@ -1801,6 +1978,9 @@ void rtl_pci_disconnect(struct pci_dev *pdev)
1801 } 1978 }
1802 1979
1803 pci_disable_device(pdev); 1980 pci_disable_device(pdev);
1981
1982 rtl_pci_disable_aspm(hw);
1983
1804 pci_set_drvdata(pdev, NULL); 1984 pci_set_drvdata(pdev, NULL);
1805 1985
1806 ieee80211_free_hw(hw); 1986 ieee80211_free_hw(hw);
@@ -1824,10 +2004,15 @@ no need to call hw_disable here.
1824****************************************/ 2004****************************************/
1825int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state) 2005int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1826{ 2006{
2007 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
2008 struct rtl_priv *rtlpriv = rtl_priv(hw);
2009
2010 rtlpriv->cfg->ops->hw_suspend(hw);
2011 rtl_deinit_rfkill(hw);
2012
1827 pci_save_state(pdev); 2013 pci_save_state(pdev);
1828 pci_disable_device(pdev); 2014 pci_disable_device(pdev);
1829 pci_set_power_state(pdev, PCI_D3hot); 2015 pci_set_power_state(pdev, PCI_D3hot);
1830
1831 return 0; 2016 return 0;
1832} 2017}
1833EXPORT_SYMBOL(rtl_pci_suspend); 2018EXPORT_SYMBOL(rtl_pci_suspend);
@@ -1835,6 +2020,8 @@ EXPORT_SYMBOL(rtl_pci_suspend);
1835int rtl_pci_resume(struct pci_dev *pdev) 2020int rtl_pci_resume(struct pci_dev *pdev)
1836{ 2021{
1837 int ret; 2022 int ret;
2023 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
2024 struct rtl_priv *rtlpriv = rtl_priv(hw);
1838 2025
1839 pci_set_power_state(pdev, PCI_D0); 2026 pci_set_power_state(pdev, PCI_D0);
1840 ret = pci_enable_device(pdev); 2027 ret = pci_enable_device(pdev);
@@ -1845,15 +2032,20 @@ int rtl_pci_resume(struct pci_dev *pdev)
1845 2032
1846 pci_restore_state(pdev); 2033 pci_restore_state(pdev);
1847 2034
2035 rtlpriv->cfg->ops->hw_resume(hw);
2036 rtl_init_rfkill(hw);
1848 return 0; 2037 return 0;
1849} 2038}
1850EXPORT_SYMBOL(rtl_pci_resume); 2039EXPORT_SYMBOL(rtl_pci_resume);
1851 2040
1852struct rtl_intf_ops rtl_pci_ops = { 2041struct rtl_intf_ops rtl_pci_ops = {
2042 .read_efuse_byte = read_efuse_byte,
1853 .adapter_start = rtl_pci_start, 2043 .adapter_start = rtl_pci_start,
1854 .adapter_stop = rtl_pci_stop, 2044 .adapter_stop = rtl_pci_stop,
1855 .adapter_tx = rtl_pci_tx, 2045 .adapter_tx = rtl_pci_tx,
2046 .flush = rtl_pci_flush,
1856 .reset_trx_ring = rtl_pci_reset_trx_ring, 2047 .reset_trx_ring = rtl_pci_reset_trx_ring,
2048 .waitq_insert = rtl_pci_tx_chk_waitq_insert,
1857 2049
1858 .disable_aspm = rtl_pci_disable_aspm, 2050 .disable_aspm = rtl_pci_disable_aspm,
1859 .enable_aspm = rtl_pci_enable_aspm, 2051 .enable_aspm = rtl_pci_enable_aspm,
diff --git a/drivers/net/wireless/rtlwifi/pci.h b/drivers/net/wireless/rtlwifi/pci.h
index 12747b9c71e1..671b1f5aa0cf 100644
--- a/drivers/net/wireless/rtlwifi/pci.h
+++ b/drivers/net/wireless/rtlwifi/pci.h
@@ -102,8 +102,8 @@
102#define RTL_PCI_8191CE_DID 0x8177 /*8192ce */ 102#define RTL_PCI_8191CE_DID 0x8177 /*8192ce */
103#define RTL_PCI_8188CE_DID 0x8176 /*8192ce */ 103#define RTL_PCI_8188CE_DID 0x8176 /*8192ce */
104#define RTL_PCI_8192CU_DID 0x8191 /*8192ce */ 104#define RTL_PCI_8192CU_DID 0x8191 /*8192ce */
105#define RTL_PCI_8192DE_DID 0x092D /*8192ce */ 105#define RTL_PCI_8192DE_DID 0x8193 /*8192de */
106#define RTL_PCI_8192DU_DID 0x092D /*8192ce */ 106#define RTL_PCI_8192DE_DID2 0x002B /*92DE*/
107 107
108/*8192 support 16 pages of IO registers*/ 108/*8192 support 16 pages of IO registers*/
109#define RTL_MEM_MAPPED_IO_RANGE_8190PCI 0x1000 109#define RTL_MEM_MAPPED_IO_RANGE_8190PCI 0x1000
@@ -129,6 +129,11 @@ enum pci_bridge_vendor {
129 PCI_BRIDGE_VENDOR_MAX, 129 PCI_BRIDGE_VENDOR_MAX,
130}; 130};
131 131
132struct rtl_pci_capabilities_header {
133 u8 capability_id;
134 u8 next;
135};
136
132struct rtl_rx_desc { 137struct rtl_rx_desc {
133 u32 dword[8]; 138 u32 dword[8];
134} __packed; 139} __packed;
@@ -161,7 +166,9 @@ struct rtl_pci {
161 166
162 bool driver_is_goingto_unload; 167 bool driver_is_goingto_unload;
163 bool up_first_time; 168 bool up_first_time;
169 bool first_init;
164 bool being_init_adapter; 170 bool being_init_adapter;
171 bool init_ready;
165 bool irq_enabled; 172 bool irq_enabled;
166 173
167 /*Tx */ 174 /*Tx */
@@ -197,6 +204,9 @@ struct rtl_pci {
197 204
198 /*QOS & EDCA */ 205 /*QOS & EDCA */
199 enum acm_method acm_method; 206 enum acm_method acm_method;
207
208 u16 shortretry_limit;
209 u16 longretry_limit;
200}; 210};
201 211
202struct mp_adapter { 212struct mp_adapter {
@@ -227,6 +237,7 @@ struct rtl_pci_priv {
227 struct rtl_pci dev; 237 struct rtl_pci dev;
228 struct mp_adapter ndis_adapter; 238 struct mp_adapter ndis_adapter;
229 struct rtl_led_ctl ledctl; 239 struct rtl_led_ctl ledctl;
240 struct bt_coexist_info bt_coexist;
230}; 241};
231 242
232#define rtl_pcipriv(hw) (((struct rtl_pci_priv *)(rtl_priv(hw))->priv)) 243#define rtl_pcipriv(hw) (((struct rtl_pci_priv *)(rtl_priv(hw))->priv))
diff --git a/drivers/net/wireless/rtlwifi/ps.c b/drivers/net/wireless/rtlwifi/ps.c
index c8395fb0c050..2bb71195e976 100644
--- a/drivers/net/wireless/rtlwifi/ps.c
+++ b/drivers/net/wireless/rtlwifi/ps.c
@@ -36,7 +36,6 @@ bool rtl_ps_enable_nic(struct ieee80211_hw *hw)
36 struct rtl_priv *rtlpriv = rtl_priv(hw); 36 struct rtl_priv *rtlpriv = rtl_priv(hw);
37 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 37 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
38 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 38 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
39 bool init_status = true;
40 39
41 /*<1> reset trx ring */ 40 /*<1> reset trx ring */
42 if (rtlhal->interface == INTF_PCI) 41 if (rtlhal->interface == INTF_PCI)
@@ -49,7 +48,6 @@ bool rtl_ps_enable_nic(struct ieee80211_hw *hw)
49 /*<2> Enable Adapter */ 48 /*<2> Enable Adapter */
50 rtlpriv->cfg->ops->hw_init(hw); 49 rtlpriv->cfg->ops->hw_init(hw);
51 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 50 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
52 /*init_status = false; */
53 51
54 /*<3> Enable Interrupt */ 52 /*<3> Enable Interrupt */
55 rtlpriv->cfg->ops->enable_interrupt(hw); 53 rtlpriv->cfg->ops->enable_interrupt(hw);
@@ -57,7 +55,7 @@ bool rtl_ps_enable_nic(struct ieee80211_hw *hw)
57 /*<enable timer> */ 55 /*<enable timer> */
58 rtl_watch_dog_timer_callback((unsigned long)hw); 56 rtl_watch_dog_timer_callback((unsigned long)hw);
59 57
60 return init_status; 58 return true;
61} 59}
62EXPORT_SYMBOL(rtl_ps_enable_nic); 60EXPORT_SYMBOL(rtl_ps_enable_nic);
63 61
@@ -192,12 +190,13 @@ static void _rtl_ps_inactive_ps(struct ieee80211_hw *hw)
192 190
193 ppsc->swrf_processing = true; 191 ppsc->swrf_processing = true;
194 192
195 if (ppsc->inactive_pwrstate == ERFON && rtlhal->interface == INTF_PCI) { 193 if (ppsc->inactive_pwrstate == ERFOFF &&
194 rtlhal->interface == INTF_PCI) {
196 if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) && 195 if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) &&
197 RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM) && 196 RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM) &&
198 rtlhal->interface == INTF_PCI) { 197 rtlhal->interface == INTF_PCI) {
199 rtlpriv->intf_ops->disable_aspm(hw); 198 rtlpriv->intf_ops->disable_aspm(hw);
200 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM); 199 RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
201 } 200 }
202 } 201 }
203 202
@@ -206,9 +205,10 @@ static void _rtl_ps_inactive_ps(struct ieee80211_hw *hw)
206 205
207 if (ppsc->inactive_pwrstate == ERFOFF && 206 if (ppsc->inactive_pwrstate == ERFOFF &&
208 rtlhal->interface == INTF_PCI) { 207 rtlhal->interface == INTF_PCI) {
209 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) { 208 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM &&
209 !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) {
210 rtlpriv->intf_ops->enable_aspm(hw); 210 rtlpriv->intf_ops->enable_aspm(hw);
211 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM); 211 RT_SET_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
212 } 212 }
213 } 213 }
214 214
@@ -232,6 +232,9 @@ void rtl_ips_nic_off_wq_callback(void *data)
232 return; 232 return;
233 } 233 }
234 234
235 if (mac->link_state > MAC80211_NOLINK)
236 return;
237
235 if (is_hal_stop(rtlhal)) 238 if (is_hal_stop(rtlhal))
236 return; 239 return;
237 240
@@ -283,10 +286,14 @@ void rtl_ips_nic_off(struct ieee80211_hw *hw)
283void rtl_ips_nic_on(struct ieee80211_hw *hw) 286void rtl_ips_nic_on(struct ieee80211_hw *hw)
284{ 287{
285 struct rtl_priv *rtlpriv = rtl_priv(hw); 288 struct rtl_priv *rtlpriv = rtl_priv(hw);
289 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
286 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 290 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
287 enum rf_pwrstate rtstate; 291 enum rf_pwrstate rtstate;
288 unsigned long flags; 292 unsigned long flags;
289 293
294 if (mac->opmode != NL80211_IFTYPE_STATION)
295 return;
296
290 spin_lock_irqsave(&rtlpriv->locks.ips_lock, flags); 297 spin_lock_irqsave(&rtlpriv->locks.ips_lock, flags);
291 298
292 if (ppsc->inactiveps) { 299 if (ppsc->inactiveps) {
@@ -369,8 +376,7 @@ static void rtl_lps_set_psmode(struct ieee80211_hw *hw, u8 rt_psmode)
369 * mode and set RPWM to turn RF on. 376 * mode and set RPWM to turn RF on.
370 */ 377 */
371 378
372 if ((ppsc->fwctrl_lps) && (ppsc->leisure_ps) && 379 if ((ppsc->fwctrl_lps) && ppsc->report_linked) {
373 ppsc->report_linked) {
374 bool fw_current_inps; 380 bool fw_current_inps;
375 if (ppsc->dot11_psmode == EACTIVE) { 381 if (ppsc->dot11_psmode == EACTIVE) {
376 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, 382 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
@@ -424,7 +430,7 @@ void rtl_lps_enter(struct ieee80211_hw *hw)
424 struct rtl_priv *rtlpriv = rtl_priv(hw); 430 struct rtl_priv *rtlpriv = rtl_priv(hw);
425 unsigned long flag; 431 unsigned long flag;
426 432
427 if (!(ppsc->fwctrl_lps && ppsc->leisure_ps)) 433 if (!ppsc->fwctrl_lps)
428 return; 434 return;
429 435
430 if (rtlpriv->sec.being_setkey) 436 if (rtlpriv->sec.being_setkey)
@@ -445,17 +451,16 @@ void rtl_lps_enter(struct ieee80211_hw *hw)
445 451
446 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag); 452 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag);
447 453
448 if (ppsc->leisure_ps) { 454 /* Idle for a while if we connect to AP a while ago. */
449 /* Idle for a while if we connect to AP a while ago. */ 455 if (mac->cnt_after_linked >= 2) {
450 if (mac->cnt_after_linked >= 2) { 456 if (ppsc->dot11_psmode == EACTIVE) {
451 if (ppsc->dot11_psmode == EACTIVE) { 457 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
452 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
453 ("Enter 802.11 power save mode...\n")); 458 ("Enter 802.11 power save mode...\n"));
454 459
455 rtl_lps_set_psmode(hw, EAUTOPS); 460 rtl_lps_set_psmode(hw, EAUTOPS);
456 }
457 } 461 }
458 } 462 }
463
459 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag); 464 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag);
460} 465}
461 466
@@ -469,17 +474,17 @@ void rtl_lps_leave(struct ieee80211_hw *hw)
469 474
470 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag); 475 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag);
471 476
472 if (ppsc->fwctrl_lps && ppsc->leisure_ps) { 477 if (ppsc->fwctrl_lps) {
473 if (ppsc->dot11_psmode != EACTIVE) { 478 if (ppsc->dot11_psmode != EACTIVE) {
474 479
475 /*FIX ME */ 480 /*FIX ME */
476 rtlpriv->cfg->ops->enable_interrupt(hw); 481 rtlpriv->cfg->ops->enable_interrupt(hw);
477 482
478 if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM && 483 if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM &&
479 RT_IN_PS_LEVEL(ppsc, RT_RF_LPS_LEVEL_ASPM) && 484 RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM) &&
480 rtlhal->interface == INTF_PCI) { 485 rtlhal->interface == INTF_PCI) {
481 rtlpriv->intf_ops->disable_aspm(hw); 486 rtlpriv->intf_ops->disable_aspm(hw);
482 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_LPS_LEVEL_ASPM); 487 RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
483 } 488 }
484 489
485 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, 490 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
@@ -490,3 +495,214 @@ void rtl_lps_leave(struct ieee80211_hw *hw)
490 } 495 }
491 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag); 496 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag);
492} 497}
498
499/* For sw LPS*/
500void rtl_swlps_beacon(struct ieee80211_hw *hw, void *data, unsigned int len)
501{
502 struct rtl_priv *rtlpriv = rtl_priv(hw);
503 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
504 struct ieee80211_hdr *hdr = (void *) data;
505 struct ieee80211_tim_ie *tim_ie;
506 u8 *tim;
507 u8 tim_len;
508 bool u_buffed;
509 bool m_buffed;
510
511 if (mac->opmode != NL80211_IFTYPE_STATION)
512 return;
513
514 if (!rtlpriv->psc.swctrl_lps)
515 return;
516
517 if (rtlpriv->mac80211.link_state != MAC80211_LINKED)
518 return;
519
520 if (!rtlpriv->psc.sw_ps_enabled)
521 return;
522
523 if (rtlpriv->psc.fwctrl_lps)
524 return;
525
526 if (likely(!(hw->conf.flags & IEEE80211_CONF_PS)))
527 return;
528
529 /* check if this really is a beacon */
530 if (!ieee80211_is_beacon(hdr->frame_control))
531 return;
532
533 /* min. beacon length + FCS_LEN */
534 if (len <= 40 + FCS_LEN)
535 return;
536
537 /* and only beacons from the associated BSSID, please */
538 if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid))
539 return;
540
541 rtlpriv->psc.last_beacon = jiffies;
542
543 tim = rtl_find_ie(data, len - FCS_LEN, WLAN_EID_TIM);
544 if (!tim)
545 return;
546
547 if (tim[1] < sizeof(*tim_ie))
548 return;
549
550 tim_len = tim[1];
551 tim_ie = (struct ieee80211_tim_ie *) &tim[2];
552
553 if (!WARN_ON_ONCE(!hw->conf.ps_dtim_period))
554 rtlpriv->psc.dtim_counter = tim_ie->dtim_count;
555
556 /* Check whenever the PHY can be turned off again. */
557
558 /* 1. What about buffered unicast traffic for our AID? */
559 u_buffed = ieee80211_check_tim(tim_ie, tim_len,
560 rtlpriv->mac80211.assoc_id);
561
562 /* 2. Maybe the AP wants to send multicast/broadcast data? */
563 m_buffed = tim_ie->bitmap_ctrl & 0x01;
564 rtlpriv->psc.multi_buffered = m_buffed;
565
566 /* unicast will process by mac80211 through
567 * set ~IEEE80211_CONF_PS, So we just check
568 * multicast frames here */
569 if (!m_buffed) {
570 /* back to low-power land. and delay is
571 * prevent null power save frame tx fail */
572 queue_delayed_work(rtlpriv->works.rtl_wq,
573 &rtlpriv->works.ps_work, MSECS(5));
574 } else {
575 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, ("u_bufferd: %x, "
576 "m_buffered: %x\n", u_buffed, m_buffed));
577 }
578}
579
580void rtl_swlps_rf_awake(struct ieee80211_hw *hw)
581{
582 struct rtl_priv *rtlpriv = rtl_priv(hw);
583 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
584 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
585 unsigned long flag;
586
587 if (!rtlpriv->psc.swctrl_lps)
588 return;
589 if (mac->link_state != MAC80211_LINKED)
590 return;
591
592 if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM &&
593 RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) {
594 rtlpriv->intf_ops->disable_aspm(hw);
595 RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
596 }
597
598 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag);
599 rtl_ps_set_rf_state(hw, ERFON, RF_CHANGE_BY_PS, false);
600 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag);
601}
602
603void rtl_swlps_rfon_wq_callback(void *data)
604{
605 struct rtl_works *rtlworks =
606 container_of_dwork_rtl(data, struct rtl_works, ps_rfon_wq);
607 struct ieee80211_hw *hw = rtlworks->hw;
608
609 rtl_swlps_rf_awake(hw);
610}
611
612void rtl_swlps_rf_sleep(struct ieee80211_hw *hw)
613{
614 struct rtl_priv *rtlpriv = rtl_priv(hw);
615 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
616 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
617 unsigned long flag;
618 u8 sleep_intv;
619
620 if (!rtlpriv->psc.sw_ps_enabled)
621 return;
622
623 if ((rtlpriv->sec.being_setkey) ||
624 (mac->opmode == NL80211_IFTYPE_ADHOC))
625 return;
626
627 /*sleep after linked 10s, to let DHCP and 4-way handshake ok enough!! */
628 if ((mac->link_state != MAC80211_LINKED) || (mac->cnt_after_linked < 5))
629 return;
630
631 if (rtlpriv->link_info.busytraffic)
632 return;
633
634 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
635 if (rtlpriv->psc.rfchange_inprogress) {
636 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
637 return;
638 }
639 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
640
641 spin_lock_irqsave(&rtlpriv->locks.lps_lock, flag);
642 rtl_ps_set_rf_state(hw, ERFSLEEP, RF_CHANGE_BY_PS, false);
643 spin_unlock_irqrestore(&rtlpriv->locks.lps_lock, flag);
644
645 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM &&
646 !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) {
647 rtlpriv->intf_ops->enable_aspm(hw);
648 RT_SET_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM);
649 }
650
651 /* here is power save alg, when this beacon is DTIM
652 * we will set sleep time to dtim_period * n;
653 * when this beacon is not DTIM, we will set sleep
654 * time to sleep_intv = rtlpriv->psc.dtim_counter or
655 * MAX_SW_LPS_SLEEP_INTV(default set to 5) */
656
657 if (rtlpriv->psc.dtim_counter == 0) {
658 if (hw->conf.ps_dtim_period == 1)
659 sleep_intv = hw->conf.ps_dtim_period * 2;
660 else
661 sleep_intv = hw->conf.ps_dtim_period;
662 } else {
663 sleep_intv = rtlpriv->psc.dtim_counter;
664 }
665
666 if (sleep_intv > MAX_SW_LPS_SLEEP_INTV)
667 sleep_intv = MAX_SW_LPS_SLEEP_INTV;
668
669 /* this print should always be dtim_conter = 0 &
670 * sleep = dtim_period, that meaons, we should
671 * awake before every dtim */
672 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG,
673 ("dtim_counter:%x will sleep :%d"
674 " beacon_intv\n", rtlpriv->psc.dtim_counter, sleep_intv));
675
676 /* we tested that 40ms is enough for sw & hw sw delay */
677 queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.ps_rfon_wq,
678 MSECS(sleep_intv * mac->vif->bss_conf.beacon_int - 40));
679}
680
681
682void rtl_swlps_wq_callback(void *data)
683{
684 struct rtl_works *rtlworks = container_of_dwork_rtl(data,
685 struct rtl_works,
686 ps_work);
687 struct ieee80211_hw *hw = rtlworks->hw;
688 struct rtl_priv *rtlpriv = rtl_priv(hw);
689 bool ps = false;
690
691 ps = (hw->conf.flags & IEEE80211_CONF_PS);
692
693 /* we can sleep after ps null send ok */
694 if (rtlpriv->psc.state_inap) {
695 rtl_swlps_rf_sleep(hw);
696
697 if (rtlpriv->psc.state && !ps) {
698 rtlpriv->psc.sleep_ms = jiffies_to_msecs(jiffies -
699 rtlpriv->psc.last_action);
700 }
701
702 if (ps)
703 rtlpriv->psc.last_slept = jiffies;
704
705 rtlpriv->psc.last_action = jiffies;
706 rtlpriv->psc.state = ps;
707 }
708}
diff --git a/drivers/net/wireless/rtlwifi/ps.h b/drivers/net/wireless/rtlwifi/ps.h
index ae56da801a23..e3bf89840370 100644
--- a/drivers/net/wireless/rtlwifi/ps.h
+++ b/drivers/net/wireless/rtlwifi/ps.h
@@ -30,6 +30,8 @@
30#ifndef __REALTEK_RTL_PCI_PS_H__ 30#ifndef __REALTEK_RTL_PCI_PS_H__
31#define __REALTEK_RTL_PCI_PS_H__ 31#define __REALTEK_RTL_PCI_PS_H__
32 32
33#define MAX_SW_LPS_SLEEP_INTV 5
34
33bool rtl_ps_set_rf_state(struct ieee80211_hw *hw, 35bool rtl_ps_set_rf_state(struct ieee80211_hw *hw,
34 enum rf_pwrstate state_toset, u32 changesource, 36 enum rf_pwrstate state_toset, u32 changesource,
35 bool protect_or_not); 37 bool protect_or_not);
@@ -40,4 +42,11 @@ void rtl_ips_nic_on(struct ieee80211_hw *hw);
40void rtl_ips_nic_off_wq_callback(void *data); 42void rtl_ips_nic_off_wq_callback(void *data);
41void rtl_lps_enter(struct ieee80211_hw *hw); 43void rtl_lps_enter(struct ieee80211_hw *hw);
42void rtl_lps_leave(struct ieee80211_hw *hw); 44void rtl_lps_leave(struct ieee80211_hw *hw);
45
46void rtl_swlps_beacon(struct ieee80211_hw *hw, void *data, unsigned int len);
47void rtl_swlps_wq_callback(void *data);
48void rtl_swlps_rfon_wq_callback(void *data);
49void rtl_swlps_rf_awake(struct ieee80211_hw *hw);
50void rtl_swlps_rf_sleep(struct ieee80211_hw *hw);
51
43#endif 52#endif
diff --git a/drivers/net/wireless/rtlwifi/rc.c b/drivers/net/wireless/rtlwifi/rc.c
index 91634107434a..30da68a77786 100644
--- a/drivers/net/wireless/rtlwifi/rc.c
+++ b/drivers/net/wireless/rtlwifi/rc.c
@@ -38,17 +38,14 @@
38 *CCK11M or OFDM_54M based on wireless mode. 38 *CCK11M or OFDM_54M based on wireless mode.
39 */ 39 */
40static u8 _rtl_rc_get_highest_rix(struct rtl_priv *rtlpriv, 40static u8 _rtl_rc_get_highest_rix(struct rtl_priv *rtlpriv,
41 struct ieee80211_sta *sta,
41 struct sk_buff *skb, bool not_data) 42 struct sk_buff *skb, bool not_data)
42{ 43{
43 struct rtl_mac *rtlmac = rtl_mac(rtlpriv); 44 struct rtl_mac *rtlmac = rtl_mac(rtlpriv);
44 45 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
45 /* 46 struct rtl_phy *rtlphy = &(rtlpriv->phy);
46 *mgt use 1M, although we have check it 47 struct rtl_sta_info *sta_entry = NULL;
47 *before this function use rate_control_send_low, 48 u8 wireless_mode = 0;
48 *we still check it here
49 */
50 if (not_data)
51 return rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M];
52 49
53 /* 50 /*
54 *this rate is no use for true rate, firmware 51 *this rate is no use for true rate, firmware
@@ -57,35 +54,78 @@ static u8 _rtl_rc_get_highest_rix(struct rtl_priv *rtlpriv,
57 *2.in rtl_get_tcb_desc when we check rate is 54 *2.in rtl_get_tcb_desc when we check rate is
58 * 1M we will not use FW rate but user rate. 55 * 1M we will not use FW rate but user rate.
59 */ 56 */
60 if (rtl_is_special_data(rtlpriv->mac80211.hw, skb, true)) { 57 if (rtlmac->opmode == NL80211_IFTYPE_AP ||
61 return rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]; 58 rtlmac->opmode == NL80211_IFTYPE_ADHOC) {
59 if (sta) {
60 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
61 wireless_mode = sta_entry->wireless_mode;
62 } else {
63 return 0;
64 }
65 } else {
66 wireless_mode = rtlmac->mode;
67 }
68
69 if (rtl_is_special_data(rtlpriv->mac80211.hw, skb, true) ||
70 not_data) {
71 return 0;
62 } else { 72 } else {
63 if (rtlmac->mode == WIRELESS_MODE_B) 73 if (rtlhal->current_bandtype == BAND_ON_2_4G) {
64 return rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; 74 if (wireless_mode == WIRELESS_MODE_B) {
65 else 75 return B_MODE_MAX_RIX;
66 return rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; 76 } else if (wireless_mode == WIRELESS_MODE_G) {
77 return G_MODE_MAX_RIX;
78 } else {
79 if (get_rf_type(rtlphy) != RF_2T2R)
80 return N_MODE_MCS7_RIX;
81 else
82 return N_MODE_MCS15_RIX;
83 }
84 } else {
85 if (wireless_mode == WIRELESS_MODE_A) {
86 return A_MODE_MAX_RIX;
87 } else {
88 if (get_rf_type(rtlphy) != RF_2T2R)
89 return N_MODE_MCS7_RIX;
90 else
91 return N_MODE_MCS15_RIX;
92 }
93 }
67 } 94 }
68} 95}
69 96
70static void _rtl_rc_rate_set_series(struct rtl_priv *rtlpriv, 97static void _rtl_rc_rate_set_series(struct rtl_priv *rtlpriv,
98 struct ieee80211_sta *sta,
71 struct ieee80211_tx_rate *rate, 99 struct ieee80211_tx_rate *rate,
72 struct ieee80211_tx_rate_control *txrc, 100 struct ieee80211_tx_rate_control *txrc,
73 u8 tries, u8 rix, int rtsctsenable, 101 u8 tries, char rix, int rtsctsenable,
74 bool not_data) 102 bool not_data)
75{ 103{
76 struct rtl_mac *mac = rtl_mac(rtlpriv); 104 struct rtl_mac *mac = rtl_mac(rtlpriv);
105 u8 sgi_20 = 0, sgi_40 = 0;
77 106
107 if (sta) {
108 sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20;
109 sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40;
110 }
78 rate->count = tries; 111 rate->count = tries;
79 rate->idx = (rix > 0x2) ? rix : 0x2; 112 rate->idx = rix >= 0x00 ? rix : 0x00;
80 113
81 if (!not_data) { 114 if (!not_data) {
82 if (txrc->short_preamble) 115 if (txrc->short_preamble)
83 rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE; 116 rate->flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
84 if (mac->bw_40) 117 if (mac->opmode == NL80211_IFTYPE_AP ||
85 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; 118 mac->opmode == NL80211_IFTYPE_ADHOC) {
86 if (mac->sgi_20 || mac->sgi_40) 119 if (sta && (sta->ht_cap.cap &
120 IEEE80211_HT_CAP_SUP_WIDTH_20_40))
121 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
122 } else {
123 if (mac->bw_40)
124 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
125 }
126 if (sgi_20 || sgi_40)
87 rate->flags |= IEEE80211_TX_RC_SHORT_GI; 127 rate->flags |= IEEE80211_TX_RC_SHORT_GI;
88 if (mac->ht_enable) 128 if (sta && sta->ht_cap.ht_supported)
89 rate->flags |= IEEE80211_TX_RC_MCS; 129 rate->flags |= IEEE80211_TX_RC_MCS;
90 } 130 }
91} 131}
@@ -97,39 +137,39 @@ static void rtl_get_rate(void *ppriv, struct ieee80211_sta *sta,
97 struct sk_buff *skb = txrc->skb; 137 struct sk_buff *skb = txrc->skb;
98 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); 138 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
99 struct ieee80211_tx_rate *rates = tx_info->control.rates; 139 struct ieee80211_tx_rate *rates = tx_info->control.rates;
100 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 140 __le16 fc = rtl_get_fc(skb);
101 __le16 fc = hdr->frame_control;
102 u8 try_per_rate, i, rix; 141 u8 try_per_rate, i, rix;
103 bool not_data = !ieee80211_is_data(fc); 142 bool not_data = !ieee80211_is_data(fc);
104 143
105 if (rate_control_send_low(sta, priv_sta, txrc)) 144 if (rate_control_send_low(sta, priv_sta, txrc))
106 return; 145 return;
107 146
108 rix = _rtl_rc_get_highest_rix(rtlpriv, skb, not_data); 147 rix = _rtl_rc_get_highest_rix(rtlpriv, sta, skb, not_data);
109
110 try_per_rate = 1; 148 try_per_rate = 1;
111 _rtl_rc_rate_set_series(rtlpriv, &rates[0], txrc, 149 _rtl_rc_rate_set_series(rtlpriv, sta, &rates[0], txrc,
112 try_per_rate, rix, 1, not_data); 150 try_per_rate, rix, 1, not_data);
113 151
114 if (!not_data) { 152 if (!not_data) {
115 for (i = 1; i < 4; i++) 153 for (i = 1; i < 4; i++)
116 _rtl_rc_rate_set_series(rtlpriv, &rates[i], 154 _rtl_rc_rate_set_series(rtlpriv, sta, &rates[i],
117 txrc, i, (rix - i), 1, 155 txrc, i, (rix - i), 1,
118 not_data); 156 not_data);
119 } 157 }
120} 158}
121 159
122static bool _rtl_tx_aggr_check(struct rtl_priv *rtlpriv, u16 tid) 160static bool _rtl_tx_aggr_check(struct rtl_priv *rtlpriv,
161 struct rtl_sta_info *sta_entry, u16 tid)
123{ 162{
124 struct rtl_mac *mac = rtl_mac(rtlpriv); 163 struct rtl_mac *mac = rtl_mac(rtlpriv);
125 164
126 if (mac->act_scanning) 165 if (mac->act_scanning)
127 return false; 166 return false;
128 167
129 if (mac->cnt_after_linked < 3) 168 if (mac->opmode == NL80211_IFTYPE_STATION &&
169 mac->cnt_after_linked < 3)
130 return false; 170 return false;
131 171
132 if (mac->tids[tid].agg.agg_state == RTL_AGG_OFF) 172 if (sta_entry->tids[tid].agg.agg_state == RTL_AGG_STOP)
133 return true; 173 return true;
134 174
135 return false; 175 return false;
@@ -143,11 +183,9 @@ static void rtl_tx_status(void *ppriv,
143{ 183{
144 struct rtl_priv *rtlpriv = ppriv; 184 struct rtl_priv *rtlpriv = ppriv;
145 struct rtl_mac *mac = rtl_mac(rtlpriv); 185 struct rtl_mac *mac = rtl_mac(rtlpriv);
146 struct ieee80211_hdr *hdr; 186 struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
147 __le16 fc; 187 __le16 fc = rtl_get_fc(skb);
148 188 struct rtl_sta_info *sta_entry;
149 hdr = (struct ieee80211_hdr *)skb->data;
150 fc = hdr->frame_control;
151 189
152 if (!priv_sta || !ieee80211_is_data(fc)) 190 if (!priv_sta || !ieee80211_is_data(fc))
153 return; 191 return;
@@ -159,17 +197,21 @@ static void rtl_tx_status(void *ppriv,
159 || is_broadcast_ether_addr(ieee80211_get_DA(hdr))) 197 || is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
160 return; 198 return;
161 199
162 /* Check if aggregation has to be enabled for this tid */ 200 if (sta) {
163 if (conf_is_ht(&mac->hw->conf) && 201 /* Check if aggregation has to be enabled for this tid */
164 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) { 202 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
165 if (ieee80211_is_data_qos(fc)) { 203 if ((sta->ht_cap.ht_supported == true) &&
166 u8 *qc, tid; 204 !(skb->protocol == cpu_to_be16(ETH_P_PAE))) {
167 205 if (ieee80211_is_data_qos(fc)) {
168 qc = ieee80211_get_qos_ctl(hdr); 206 u8 tid = rtl_get_tid(skb);
169 tid = qc[0] & 0xf; 207 if (_rtl_tx_aggr_check(rtlpriv, sta_entry,
170 208 tid)) {
171 if (_rtl_tx_aggr_check(rtlpriv, tid)) 209 sta_entry->tids[tid].agg.agg_state =
172 ieee80211_start_tx_ba_session(sta, tid, 5000); 210 RTL_AGG_PROGRESS;
211 ieee80211_start_tx_ba_session(sta,
212 tid, 5000);
213 }
214 }
173 } 215 }
174 } 216 }
175} 217}
@@ -178,43 +220,6 @@ static void rtl_rate_init(void *ppriv,
178 struct ieee80211_supported_band *sband, 220 struct ieee80211_supported_band *sband,
179 struct ieee80211_sta *sta, void *priv_sta) 221 struct ieee80211_sta *sta, void *priv_sta)
180{ 222{
181 struct rtl_priv *rtlpriv = ppriv;
182 struct rtl_mac *mac = rtl_mac(rtlpriv);
183 u8 is_ht = conf_is_ht(&mac->hw->conf);
184
185 if ((mac->opmode == NL80211_IFTYPE_STATION) ||
186 (mac->opmode == NL80211_IFTYPE_MESH_POINT) ||
187 (mac->opmode == NL80211_IFTYPE_ADHOC)) {
188
189 switch (sband->band) {
190 case IEEE80211_BAND_2GHZ:
191 rtlpriv->rate_priv->cur_ratetab_idx =
192 RATR_INX_WIRELESS_G;
193 if (is_ht)
194 rtlpriv->rate_priv->cur_ratetab_idx =
195 RATR_INX_WIRELESS_NGB;
196 break;
197 case IEEE80211_BAND_5GHZ:
198 rtlpriv->rate_priv->cur_ratetab_idx =
199 RATR_INX_WIRELESS_A;
200 if (is_ht)
201 rtlpriv->rate_priv->cur_ratetab_idx =
202 RATR_INX_WIRELESS_NGB;
203 break;
204 default:
205 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
206 ("Invalid band\n"));
207 rtlpriv->rate_priv->cur_ratetab_idx =
208 RATR_INX_WIRELESS_NGB;
209 break;
210 }
211
212 RT_TRACE(rtlpriv, COMP_RATE, DBG_DMESG,
213 ("Choosing rate table index: %d\n",
214 rtlpriv->rate_priv->cur_ratetab_idx));
215
216 }
217
218} 223}
219 224
220static void rtl_rate_update(void *ppriv, 225static void rtl_rate_update(void *ppriv,
@@ -223,49 +228,6 @@ static void rtl_rate_update(void *ppriv,
223 u32 changed, 228 u32 changed,
224 enum nl80211_channel_type oper_chan_type) 229 enum nl80211_channel_type oper_chan_type)
225{ 230{
226 struct rtl_priv *rtlpriv = ppriv;
227 struct rtl_mac *mac = rtl_mac(rtlpriv);
228 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
229 bool oper_cw40 = false, oper_sgi40;
230 bool local_cw40 = mac->bw_40;
231 bool local_sgi40 = mac->sgi_40;
232 u8 is_ht = conf_is_ht(&mac->hw->conf);
233
234 if (changed & IEEE80211_RC_HT_CHANGED) {
235 if (mac->opmode != NL80211_IFTYPE_STATION)
236 return;
237
238 if (rtlhal->hw->conf.channel_type == NL80211_CHAN_HT40MINUS ||
239 rtlhal->hw->conf.channel_type == NL80211_CHAN_HT40PLUS)
240 oper_cw40 = true;
241
242 oper_sgi40 = mac->sgi_40;
243
244 if ((local_cw40 != oper_cw40) || (local_sgi40 != oper_sgi40)) {
245 switch (sband->band) {
246 case IEEE80211_BAND_2GHZ:
247 rtlpriv->rate_priv->cur_ratetab_idx =
248 RATR_INX_WIRELESS_G;
249 if (is_ht)
250 rtlpriv->rate_priv->cur_ratetab_idx =
251 RATR_INX_WIRELESS_NGB;
252 break;
253 case IEEE80211_BAND_5GHZ:
254 rtlpriv->rate_priv->cur_ratetab_idx =
255 RATR_INX_WIRELESS_A;
256 if (is_ht)
257 rtlpriv->rate_priv->cur_ratetab_idx =
258 RATR_INX_WIRELESS_NGB;
259 break;
260 default:
261 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
262 ("Invalid band\n"));
263 rtlpriv->rate_priv->cur_ratetab_idx =
264 RATR_INX_WIRELESS_NGB;
265 break;
266 }
267 }
268 }
269} 231}
270 232
271static void *rtl_rate_alloc(struct ieee80211_hw *hw, 233static void *rtl_rate_alloc(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/rtlwifi/rc.h b/drivers/net/wireless/rtlwifi/rc.h
index b4667c035f0b..4afa2c20adcf 100644
--- a/drivers/net/wireless/rtlwifi/rc.h
+++ b/drivers/net/wireless/rtlwifi/rc.h
@@ -30,8 +30,15 @@
30#ifndef __RTL_RC_H__ 30#ifndef __RTL_RC_H__
31#define __RTL_RC_H__ 31#define __RTL_RC_H__
32 32
33#define B_MODE_MAX_RIX 3
34#define G_MODE_MAX_RIX 11
35#define A_MODE_MAX_RIX 7
36
37/* in mac80211 mcs0-mcs15 is idx0-idx15*/
38#define N_MODE_MCS7_RIX 7
39#define N_MODE_MCS15_RIX 15
40
33struct rtl_rate_priv { 41struct rtl_rate_priv {
34 u8 cur_ratetab_idx;
35 u8 ht_cap; 42 u8 ht_cap;
36}; 43};
37 44
diff --git a/drivers/net/wireless/rtlwifi/regd.c b/drivers/net/wireless/rtlwifi/regd.c
index d26f957981ad..8f6718f163e5 100644
--- a/drivers/net/wireless/rtlwifi/regd.c
+++ b/drivers/net/wireless/rtlwifi/regd.c
@@ -66,31 +66,83 @@ static struct country_code_to_enum_rd allCountries[] = {
66 NL80211_RRF_PASSIVE_SCAN | \ 66 NL80211_RRF_PASSIVE_SCAN | \
67 NL80211_RRF_NO_OFDM) 67 NL80211_RRF_NO_OFDM)
68 68
69/* 5G chan 36 - chan 64*/
70#define RTL819x_5GHZ_5150_5350 \
71 REG_RULE(5150-10, 5350+10, 40, 0, 30, \
72 NL80211_RRF_PASSIVE_SCAN | \
73 NL80211_RRF_NO_IBSS)
74
75/* 5G chan 100 - chan 165*/
76#define RTL819x_5GHZ_5470_5850 \
77 REG_RULE(5470-10, 5850+10, 40, 0, 30, \
78 NL80211_RRF_PASSIVE_SCAN | \
79 NL80211_RRF_NO_IBSS)
80
81/* 5G chan 149 - chan 165*/
82#define RTL819x_5GHZ_5725_5850 \
83 REG_RULE(5725-10, 5850+10, 40, 0, 30, \
84 NL80211_RRF_PASSIVE_SCAN | \
85 NL80211_RRF_NO_IBSS)
86
87#define RTL819x_5GHZ_ALL \
88 (RTL819x_5GHZ_5150_5350, RTL819x_5GHZ_5470_5850)
89
69static const struct ieee80211_regdomain rtl_regdom_11 = { 90static const struct ieee80211_regdomain rtl_regdom_11 = {
70 .n_reg_rules = 1, 91 .n_reg_rules = 1,
71 .alpha2 = "99", 92 .alpha2 = "99",
72 .reg_rules = { 93 .reg_rules = {
73 RTL819x_2GHZ_CH01_11, 94 RTL819x_2GHZ_CH01_11,
74 } 95 }
96};
97
98static const struct ieee80211_regdomain rtl_regdom_12_13 = {
99 .n_reg_rules = 2,
100 .alpha2 = "99",
101 .reg_rules = {
102 RTL819x_2GHZ_CH01_11,
103 RTL819x_2GHZ_CH12_13,
104 }
75}; 105};
76 106
77static const struct ieee80211_regdomain rtl_regdom_global = { 107static const struct ieee80211_regdomain rtl_regdom_no_midband = {
78 .n_reg_rules = 3, 108 .n_reg_rules = 3,
79 .alpha2 = "99", 109 .alpha2 = "99",
80 .reg_rules = { 110 .reg_rules = {
81 RTL819x_2GHZ_CH01_11, 111 RTL819x_2GHZ_CH01_11,
82 RTL819x_2GHZ_CH12_13, 112 RTL819x_5GHZ_5150_5350,
83 RTL819x_2GHZ_CH14, 113 RTL819x_5GHZ_5725_5850,
84 } 114 }
85}; 115};
86 116
87static const struct ieee80211_regdomain rtl_regdom_world = { 117static const struct ieee80211_regdomain rtl_regdom_60_64 = {
88 .n_reg_rules = 2, 118 .n_reg_rules = 3,
89 .alpha2 = "99", 119 .alpha2 = "99",
90 .reg_rules = { 120 .reg_rules = {
91 RTL819x_2GHZ_CH01_11, 121 RTL819x_2GHZ_CH01_11,
92 RTL819x_2GHZ_CH12_13, 122 RTL819x_2GHZ_CH12_13,
93 } 123 RTL819x_5GHZ_5725_5850,
124 }
125};
126
127static const struct ieee80211_regdomain rtl_regdom_14_60_64 = {
128 .n_reg_rules = 4,
129 .alpha2 = "99",
130 .reg_rules = {
131 RTL819x_2GHZ_CH01_11,
132 RTL819x_2GHZ_CH12_13,
133 RTL819x_2GHZ_CH14,
134 RTL819x_5GHZ_5725_5850,
135 }
136};
137
138static const struct ieee80211_regdomain rtl_regdom_14 = {
139 .n_reg_rules = 3,
140 .alpha2 = "99",
141 .reg_rules = {
142 RTL819x_2GHZ_CH01_11,
143 RTL819x_2GHZ_CH12_13,
144 RTL819x_2GHZ_CH14,
145 }
94}; 146};
95 147
96static bool _rtl_is_radar_freq(u16 center_freq) 148static bool _rtl_is_radar_freq(u16 center_freq)
@@ -162,6 +214,8 @@ static void _rtl_reg_apply_active_scan_flags(struct wiphy *wiphy,
162 u32 bandwidth = 0; 214 u32 bandwidth = 0;
163 int r; 215 int r;
164 216
217 if (!wiphy->bands[IEEE80211_BAND_2GHZ])
218 return;
165 sband = wiphy->bands[IEEE80211_BAND_2GHZ]; 219 sband = wiphy->bands[IEEE80211_BAND_2GHZ];
166 220
167 /* 221 /*
@@ -292,25 +346,26 @@ static const struct ieee80211_regdomain *_rtl_regdomain_select(
292{ 346{
293 switch (reg->country_code) { 347 switch (reg->country_code) {
294 case COUNTRY_CODE_FCC: 348 case COUNTRY_CODE_FCC:
349 return &rtl_regdom_no_midband;
295 case COUNTRY_CODE_IC: 350 case COUNTRY_CODE_IC:
296 return &rtl_regdom_11; 351 return &rtl_regdom_11;
297 case COUNTRY_CODE_ETSI: 352 case COUNTRY_CODE_ETSI:
353 case COUNTRY_CODE_TELEC_NETGEAR:
354 return &rtl_regdom_60_64;
298 case COUNTRY_CODE_SPAIN: 355 case COUNTRY_CODE_SPAIN:
299 case COUNTRY_CODE_FRANCE: 356 case COUNTRY_CODE_FRANCE:
300 case COUNTRY_CODE_ISRAEL: 357 case COUNTRY_CODE_ISRAEL:
301 case COUNTRY_CODE_TELEC_NETGEAR: 358 case COUNTRY_CODE_WORLD_WIDE_13:
302 return &rtl_regdom_world; 359 return &rtl_regdom_12_13;
303 case COUNTRY_CODE_MKK: 360 case COUNTRY_CODE_MKK:
304 case COUNTRY_CODE_MKK1: 361 case COUNTRY_CODE_MKK1:
305 case COUNTRY_CODE_TELEC: 362 case COUNTRY_CODE_TELEC:
306 case COUNTRY_CODE_MIC: 363 case COUNTRY_CODE_MIC:
307 return &rtl_regdom_global; 364 return &rtl_regdom_14_60_64;
308 case COUNTRY_CODE_GLOBAL_DOMAIN: 365 case COUNTRY_CODE_GLOBAL_DOMAIN:
309 return &rtl_regdom_global; 366 return &rtl_regdom_14;
310 case COUNTRY_CODE_WORLD_WIDE_13:
311 return &rtl_regdom_world;
312 default: 367 default:
313 return &rtl_regdom_world; 368 return &rtl_regdom_no_midband;
314 } 369 }
315} 370}
316 371
@@ -323,9 +378,11 @@ static int _rtl_regd_init_wiphy(struct rtl_regulatory *reg,
323 const struct ieee80211_regdomain *regd; 378 const struct ieee80211_regdomain *regd;
324 379
325 wiphy->reg_notifier = reg_notifier; 380 wiphy->reg_notifier = reg_notifier;
381
326 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY; 382 wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY;
327 wiphy->flags &= ~WIPHY_FLAG_STRICT_REGULATORY; 383 wiphy->flags &= ~WIPHY_FLAG_STRICT_REGULATORY;
328 wiphy->flags &= ~WIPHY_FLAG_DISABLE_BEACON_HINTS; 384 wiphy->flags &= ~WIPHY_FLAG_DISABLE_BEACON_HINTS;
385
329 regd = _rtl_regdomain_select(reg); 386 regd = _rtl_regdomain_select(reg);
330 wiphy_apply_custom_regulatory(wiphy, regd); 387 wiphy_apply_custom_regulatory(wiphy, regd);
331 _rtl_reg_apply_radar_flags(wiphy); 388 _rtl_reg_apply_radar_flags(wiphy);
@@ -355,8 +412,8 @@ int rtl_regd_init(struct ieee80211_hw *hw,
355 if (wiphy == NULL || &rtlpriv->regd == NULL) 412 if (wiphy == NULL || &rtlpriv->regd == NULL)
356 return -EINVAL; 413 return -EINVAL;
357 414
358 /* force the channel plan to world wide 13 */ 415 /* init country_code from efuse channel plan */
359 rtlpriv->regd.country_code = COUNTRY_CODE_WORLD_WIDE_13; 416 rtlpriv->regd.country_code = rtlpriv->efuse.channel_plan;
360 417
361 RT_TRACE(rtlpriv, COMP_REGD, DBG_TRACE, 418 RT_TRACE(rtlpriv, COMP_REGD, DBG_TRACE,
362 (KERN_DEBUG "rtl: EEPROM regdomain: 0x%0x\n", 419 (KERN_DEBUG "rtl: EEPROM regdomain: 0x%0x\n",
@@ -373,8 +430,8 @@ int rtl_regd_init(struct ieee80211_hw *hw,
373 country = _rtl_regd_find_country(rtlpriv->regd.country_code); 430 country = _rtl_regd_find_country(rtlpriv->regd.country_code);
374 431
375 if (country) { 432 if (country) {
376 rtlpriv->regd.alpha2[0] = country->isoName[0]; 433 rtlpriv->regd.alpha2[0] = country->iso_name[0];
377 rtlpriv->regd.alpha2[1] = country->isoName[1]; 434 rtlpriv->regd.alpha2[1] = country->iso_name[1];
378 } else { 435 } else {
379 rtlpriv->regd.alpha2[0] = '0'; 436 rtlpriv->regd.alpha2[0] = '0';
380 rtlpriv->regd.alpha2[1] = '0'; 437 rtlpriv->regd.alpha2[1] = '0';
diff --git a/drivers/net/wireless/rtlwifi/regd.h b/drivers/net/wireless/rtlwifi/regd.h
index 4cdbc4ae76d4..d23118938fac 100644
--- a/drivers/net/wireless/rtlwifi/regd.h
+++ b/drivers/net/wireless/rtlwifi/regd.h
@@ -32,7 +32,7 @@
32 32
33struct country_code_to_enum_rd { 33struct country_code_to_enum_rd {
34 u16 countrycode; 34 u16 countrycode;
35 const char *isoName; 35 const char *iso_name;
36}; 36};
37 37
38enum country_code_type_t { 38enum country_code_type_t {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
index c228b9ee3711..97183829b9be 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
@@ -28,10 +28,26 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include "dm_common.h" 30#include "dm_common.h"
31#include "phy_common.h"
32#include "../pci.h"
33#include "../base.h"
31 34
32struct dig_t dm_digtable; 35struct dig_t dm_digtable;
33static struct ps_t dm_pstable; 36static struct ps_t dm_pstable;
34 37
38#define BT_RSSI_STATE_NORMAL_POWER BIT_OFFSET_LEN_MASK_32(0, 1)
39#define BT_RSSI_STATE_AMDPU_OFF BIT_OFFSET_LEN_MASK_32(1, 1)
40#define BT_RSSI_STATE_SPECIAL_LOW BIT_OFFSET_LEN_MASK_32(2, 1)
41#define BT_RSSI_STATE_BG_EDCA_LOW BIT_OFFSET_LEN_MASK_32(3, 1)
42#define BT_RSSI_STATE_TXPOWER_LOW BIT_OFFSET_LEN_MASK_32(4, 1)
43
44#define RTLPRIV (struct rtl_priv *)
45#define GET_UNDECORATED_AVERAGE_RSSI(_priv) \
46 ((RTLPRIV(_priv))->mac80211.opmode == \
47 NL80211_IFTYPE_ADHOC) ? \
48 ((RTLPRIV(_priv))->dm.entry_min_undecoratedsmoothed_pwdb) : \
49 ((RTLPRIV(_priv))->dm.undecorated_smoothed_pwdb)
50
35static const u32 ofdmswing_table[OFDM_TABLE_SIZE] = { 51static const u32 ofdmswing_table[OFDM_TABLE_SIZE] = {
36 0x7f8001fe, 52 0x7f8001fe,
37 0x788001e2, 53 0x788001e2,
@@ -304,7 +320,7 @@ static void rtl92c_dm_ctrl_initgain_by_rssi(struct ieee80211_hw *hw)
304 320
305static void rtl92c_dm_initial_gain_multi_sta(struct ieee80211_hw *hw) 321static void rtl92c_dm_initial_gain_multi_sta(struct ieee80211_hw *hw)
306{ 322{
307 static u8 binitialized; /* initialized to false */ 323 static u8 initialized; /* initialized to false */
308 struct rtl_priv *rtlpriv = rtl_priv(hw); 324 struct rtl_priv *rtlpriv = rtl_priv(hw);
309 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 325 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
310 long rssi_strength = rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb; 326 long rssi_strength = rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
@@ -315,11 +331,11 @@ static void rtl92c_dm_initial_gain_multi_sta(struct ieee80211_hw *hw)
315 331
316 if ((multi_sta == false) || (dm_digtable.cursta_connectctate != 332 if ((multi_sta == false) || (dm_digtable.cursta_connectctate !=
317 DIG_STA_DISCONNECT)) { 333 DIG_STA_DISCONNECT)) {
318 binitialized = false; 334 initialized = false;
319 dm_digtable.dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; 335 dm_digtable.dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX;
320 return; 336 return;
321 } else if (binitialized == false) { 337 } else if (initialized == false) {
322 binitialized = true; 338 initialized = true;
323 dm_digtable.dig_ext_port_stage = DIG_EXT_PORT_STAGE_0; 339 dm_digtable.dig_ext_port_stage = DIG_EXT_PORT_STAGE_0;
324 dm_digtable.cur_igvalue = 0x20; 340 dm_digtable.cur_igvalue = 0x20;
325 rtl92c_dm_write_dig(hw); 341 rtl92c_dm_write_dig(hw);
@@ -461,10 +477,7 @@ static void rtl92c_dm_ctrl_initgain_by_twoport(struct ieee80211_hw *hw)
461 if (mac->act_scanning == true) 477 if (mac->act_scanning == true)
462 return; 478 return;
463 479
464 if ((mac->link_state > MAC80211_NOLINK) && 480 if (mac->link_state >= MAC80211_LINKED)
465 (mac->link_state < MAC80211_LINKED))
466 dm_digtable.cursta_connectctate = DIG_STA_BEFORE_CONNECT;
467 else if (mac->link_state >= MAC80211_LINKED)
468 dm_digtable.cursta_connectctate = DIG_STA_CONNECT; 481 dm_digtable.cursta_connectctate = DIG_STA_CONNECT;
469 else 482 else
470 dm_digtable.cursta_connectctate = DIG_STA_DISCONNECT; 483 dm_digtable.cursta_connectctate = DIG_STA_DISCONNECT;
@@ -562,23 +575,42 @@ EXPORT_SYMBOL(rtl92c_dm_init_edca_turbo);
562static void rtl92c_dm_check_edca_turbo(struct ieee80211_hw *hw) 575static void rtl92c_dm_check_edca_turbo(struct ieee80211_hw *hw)
563{ 576{
564 struct rtl_priv *rtlpriv = rtl_priv(hw); 577 struct rtl_priv *rtlpriv = rtl_priv(hw);
578 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
565 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 579 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
580
566 static u64 last_txok_cnt; 581 static u64 last_txok_cnt;
567 static u64 last_rxok_cnt; 582 static u64 last_rxok_cnt;
568 u64 cur_txok_cnt; 583 static u32 last_bt_edca_ul;
569 u64 cur_rxok_cnt; 584 static u32 last_bt_edca_dl;
585 u64 cur_txok_cnt = 0;
586 u64 cur_rxok_cnt = 0;
570 u32 edca_be_ul = 0x5ea42b; 587 u32 edca_be_ul = 0x5ea42b;
571 u32 edca_be_dl = 0x5ea42b; 588 u32 edca_be_dl = 0x5ea42b;
589 bool bt_change_edca = false;
572 590
573 if (mac->opmode == NL80211_IFTYPE_ADHOC) 591 if ((last_bt_edca_ul != rtlpcipriv->bt_coexist.bt_edca_ul) ||
574 goto dm_checkedcaturbo_exit; 592 (last_bt_edca_dl != rtlpcipriv->bt_coexist.bt_edca_dl)) {
593 rtlpriv->dm.current_turbo_edca = false;
594 last_bt_edca_ul = rtlpcipriv->bt_coexist.bt_edca_ul;
595 last_bt_edca_dl = rtlpcipriv->bt_coexist.bt_edca_dl;
596 }
597
598 if (rtlpcipriv->bt_coexist.bt_edca_ul != 0) {
599 edca_be_ul = rtlpcipriv->bt_coexist.bt_edca_ul;
600 bt_change_edca = true;
601 }
602
603 if (rtlpcipriv->bt_coexist.bt_edca_dl != 0) {
604 edca_be_ul = rtlpcipriv->bt_coexist.bt_edca_dl;
605 bt_change_edca = true;
606 }
575 607
576 if (mac->link_state != MAC80211_LINKED) { 608 if (mac->link_state != MAC80211_LINKED) {
577 rtlpriv->dm.current_turbo_edca = false; 609 rtlpriv->dm.current_turbo_edca = false;
578 return; 610 return;
579 } 611 }
580 612
581 if (!mac->ht_enable) { /*FIX MERGE */ 613 if ((!mac->ht_enable) && (!rtlpcipriv->bt_coexist.bt_coexistence)) {
582 if (!(edca_be_ul & 0xffff0000)) 614 if (!(edca_be_ul & 0xffff0000))
583 edca_be_ul |= 0x005e0000; 615 edca_be_ul |= 0x005e0000;
584 616
@@ -586,10 +618,12 @@ static void rtl92c_dm_check_edca_turbo(struct ieee80211_hw *hw)
586 edca_be_dl |= 0x005e0000; 618 edca_be_dl |= 0x005e0000;
587 } 619 }
588 620
589 if ((!rtlpriv->dm.is_any_nonbepkts) && 621 if ((bt_change_edca) || ((!rtlpriv->dm.is_any_nonbepkts) &&
590 (!rtlpriv->dm.disable_framebursting)) { 622 (!rtlpriv->dm.disable_framebursting))) {
623
591 cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt; 624 cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt;
592 cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt; 625 cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt;
626
593 if (cur_rxok_cnt > 4 * cur_txok_cnt) { 627 if (cur_rxok_cnt > 4 * cur_txok_cnt) {
594 if (!rtlpriv->dm.is_cur_rdlstate || 628 if (!rtlpriv->dm.is_cur_rdlstate ||
595 !rtlpriv->dm.current_turbo_edca) { 629 !rtlpriv->dm.current_turbo_edca) {
@@ -618,7 +652,6 @@ static void rtl92c_dm_check_edca_turbo(struct ieee80211_hw *hw)
618 } 652 }
619 } 653 }
620 654
621dm_checkedcaturbo_exit:
622 rtlpriv->dm.is_any_nonbepkts = false; 655 rtlpriv->dm.is_any_nonbepkts = false;
623 last_txok_cnt = rtlpriv->stats.txbytesunicast; 656 last_txok_cnt = rtlpriv->stats.txbytesunicast;
624 last_rxok_cnt = rtlpriv->stats.rxbytesunicast; 657 last_rxok_cnt = rtlpriv->stats.rxbytesunicast;
@@ -633,14 +666,14 @@ static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
633 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 666 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
634 u8 thermalvalue, delta, delta_lck, delta_iqk; 667 u8 thermalvalue, delta, delta_lck, delta_iqk;
635 long ele_a, ele_d, temp_cck, val_x, value32; 668 long ele_a, ele_d, temp_cck, val_x, value32;
636 long val_y, ele_c; 669 long val_y, ele_c = 0;
637 u8 ofdm_index[2], cck_index = 0, ofdm_index_old[2], cck_index_old = 0; 670 u8 ofdm_index[2], cck_index = 0, ofdm_index_old[2], cck_index_old = 0;
638 int i; 671 int i;
639 bool is2t = IS_92C_SERIAL(rtlhal->version); 672 bool is2t = IS_92C_SERIAL(rtlhal->version);
640 u8 txpwr_level[2] = {0, 0}; 673 u8 txpwr_level[2] = {0, 0};
641 u8 ofdm_min_index = 6, rf; 674 u8 ofdm_min_index = 6, rf;
642 675
643 rtlpriv->dm.txpower_trackingInit = true; 676 rtlpriv->dm.txpower_trackinginit = true;
644 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, 677 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
645 ("rtl92c_dm_txpower_tracking_callback_thermalmeter\n")); 678 ("rtl92c_dm_txpower_tracking_callback_thermalmeter\n"));
646 679
@@ -683,7 +716,6 @@ static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw
683 for (i = 0; i < OFDM_TABLE_LENGTH; i++) { 716 for (i = 0; i < OFDM_TABLE_LENGTH; i++) {
684 if (ele_d == (ofdmswing_table[i] & 717 if (ele_d == (ofdmswing_table[i] &
685 MASKOFDM_D)) { 718 MASKOFDM_D)) {
686 ofdm_index_old[1] = (u8) i;
687 719
688 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, 720 RT_TRACE(rtlpriv, COMP_POWER_TRACKING,
689 DBG_LOUD, 721 DBG_LOUD,
@@ -1062,7 +1094,7 @@ static void rtl92c_dm_initialize_txpower_tracking_thermalmeter(
1062 struct rtl_priv *rtlpriv = rtl_priv(hw); 1094 struct rtl_priv *rtlpriv = rtl_priv(hw);
1063 1095
1064 rtlpriv->dm.txpower_tracking = true; 1096 rtlpriv->dm.txpower_tracking = true;
1065 rtlpriv->dm.txpower_trackingInit = false; 1097 rtlpriv->dm.txpower_trackinginit = false;
1066 1098
1067 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, 1099 RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
1068 ("pMgntInfo->txpower_tracking = %d\n", 1100 ("pMgntInfo->txpower_tracking = %d\n",
@@ -1132,6 +1164,7 @@ static void rtl92c_dm_refresh_rate_adaptive_mask(struct ieee80211_hw *hw)
1132 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1164 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1133 struct rate_adaptive *p_ra = &(rtlpriv->ra); 1165 struct rate_adaptive *p_ra = &(rtlpriv->ra);
1134 u32 low_rssithresh_for_ra, high_rssithresh_for_ra; 1166 u32 low_rssithresh_for_ra, high_rssithresh_for_ra;
1167 struct ieee80211_sta *sta = NULL;
1135 1168
1136 if (is_hal_stop(rtlhal)) { 1169 if (is_hal_stop(rtlhal)) {
1137 RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD, 1170 RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD,
@@ -1145,8 +1178,8 @@ static void rtl92c_dm_refresh_rate_adaptive_mask(struct ieee80211_hw *hw)
1145 return; 1178 return;
1146 } 1179 }
1147 1180
1148 if (mac->link_state == MAC80211_LINKED) { 1181 if (mac->link_state == MAC80211_LINKED &&
1149 1182 mac->opmode == NL80211_IFTYPE_STATION) {
1150 switch (p_ra->pre_ratr_state) { 1183 switch (p_ra->pre_ratr_state) {
1151 case DM_RATR_STA_HIGH: 1184 case DM_RATR_STA_HIGH:
1152 high_rssithresh_for_ra = 50; 1185 high_rssithresh_for_ra = 50;
@@ -1185,10 +1218,13 @@ static void rtl92c_dm_refresh_rate_adaptive_mask(struct ieee80211_hw *hw)
1185 ("PreState = %d, CurState = %d\n", 1218 ("PreState = %d, CurState = %d\n",
1186 p_ra->pre_ratr_state, p_ra->ratr_state)); 1219 p_ra->pre_ratr_state, p_ra->ratr_state));
1187 1220
1188 rtlpriv->cfg->ops->update_rate_mask(hw, 1221 rcu_read_lock();
1222 sta = ieee80211_find_sta(mac->vif, mac->bssid);
1223 rtlpriv->cfg->ops->update_rate_tbl(hw, sta,
1189 p_ra->ratr_state); 1224 p_ra->ratr_state);
1190 1225
1191 p_ra->pre_ratr_state = p_ra->ratr_state; 1226 p_ra->pre_ratr_state = p_ra->ratr_state;
1227 rcu_read_unlock();
1192 } 1228 }
1193 } 1229 }
1194} 1230}
@@ -1202,51 +1238,6 @@ static void rtl92c_dm_init_dynamic_bb_powersaving(struct ieee80211_hw *hw)
1202 dm_pstable.rssi_val_min = 0; 1238 dm_pstable.rssi_val_min = 0;
1203} 1239}
1204 1240
1205static void rtl92c_dm_1r_cca(struct ieee80211_hw *hw)
1206{
1207 struct rtl_priv *rtlpriv = rtl_priv(hw);
1208 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1209
1210 if (dm_pstable.rssi_val_min != 0) {
1211 if (dm_pstable.pre_ccastate == CCA_2R) {
1212 if (dm_pstable.rssi_val_min >= 35)
1213 dm_pstable.cur_ccasate = CCA_1R;
1214 else
1215 dm_pstable.cur_ccasate = CCA_2R;
1216 } else {
1217 if (dm_pstable.rssi_val_min <= 30)
1218 dm_pstable.cur_ccasate = CCA_2R;
1219 else
1220 dm_pstable.cur_ccasate = CCA_1R;
1221 }
1222 } else {
1223 dm_pstable.cur_ccasate = CCA_MAX;
1224 }
1225
1226 if (dm_pstable.pre_ccastate != dm_pstable.cur_ccasate) {
1227 if (dm_pstable.cur_ccasate == CCA_1R) {
1228 if (get_rf_type(rtlphy) == RF_2T2R) {
1229 rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
1230 MASKBYTE0, 0x13);
1231 rtl_set_bbreg(hw, 0xe70, MASKBYTE3, 0x20);
1232 } else {
1233 rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
1234 MASKBYTE0, 0x23);
1235 rtl_set_bbreg(hw, 0xe70, 0x7fc00000, 0x10c);
1236 }
1237 } else {
1238 rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0,
1239 0x33);
1240 rtl_set_bbreg(hw, 0xe70, MASKBYTE3, 0x63);
1241 }
1242 dm_pstable.pre_ccastate = dm_pstable.cur_ccasate;
1243 }
1244
1245 RT_TRACE(rtlpriv, DBG_LOUD, DBG_LOUD, ("CCAStage = %s\n",
1246 (dm_pstable.cur_ccasate ==
1247 0) ? "1RCCA" : "2RCCA"));
1248}
1249
1250void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal) 1241void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal)
1251{ 1242{
1252 static u8 initialize; 1243 static u8 initialize;
@@ -1352,7 +1343,9 @@ static void rtl92c_dm_dynamic_bb_powersaving(struct ieee80211_hw *hw)
1352 } 1343 }
1353 1344
1354 if (IS_92C_SERIAL(rtlhal->version)) 1345 if (IS_92C_SERIAL(rtlhal->version))
1355 rtl92c_dm_1r_cca(hw); 1346 ;/* rtl92c_dm_1r_cca(hw); */
1347 else
1348 rtl92c_dm_rf_saving(hw, false);
1356} 1349}
1357 1350
1358void rtl92c_dm_init(struct ieee80211_hw *hw) 1351void rtl92c_dm_init(struct ieee80211_hw *hw)
@@ -1369,6 +1362,84 @@ void rtl92c_dm_init(struct ieee80211_hw *hw)
1369} 1362}
1370EXPORT_SYMBOL(rtl92c_dm_init); 1363EXPORT_SYMBOL(rtl92c_dm_init);
1371 1364
1365void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw)
1366{
1367 struct rtl_priv *rtlpriv = rtl_priv(hw);
1368 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1369 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1370 long undecorated_smoothed_pwdb;
1371
1372 if (!rtlpriv->dm.dynamic_txpower_enable)
1373 return;
1374
1375 if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) {
1376 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
1377 return;
1378 }
1379
1380 if ((mac->link_state < MAC80211_LINKED) &&
1381 (rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb == 0)) {
1382 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
1383 ("Not connected to any\n"));
1384
1385 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
1386
1387 rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL;
1388 return;
1389 }
1390
1391 if (mac->link_state >= MAC80211_LINKED) {
1392 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
1393 undecorated_smoothed_pwdb =
1394 rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
1395 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1396 ("AP Client PWDB = 0x%lx\n",
1397 undecorated_smoothed_pwdb));
1398 } else {
1399 undecorated_smoothed_pwdb =
1400 rtlpriv->dm.undecorated_smoothed_pwdb;
1401 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1402 ("STA Default Port PWDB = 0x%lx\n",
1403 undecorated_smoothed_pwdb));
1404 }
1405 } else {
1406 undecorated_smoothed_pwdb =
1407 rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
1408
1409 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1410 ("AP Ext Port PWDB = 0x%lx\n",
1411 undecorated_smoothed_pwdb));
1412 }
1413
1414 if (undecorated_smoothed_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) {
1415 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
1416 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1417 ("TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"));
1418 } else if ((undecorated_smoothed_pwdb <
1419 (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) &&
1420 (undecorated_smoothed_pwdb >=
1421 TX_POWER_NEAR_FIELD_THRESH_LVL1)) {
1422
1423 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1;
1424 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1425 ("TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"));
1426 } else if (undecorated_smoothed_pwdb <
1427 (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) {
1428 rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL;
1429 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1430 ("TXHIGHPWRLEVEL_NORMAL\n"));
1431 }
1432
1433 if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) {
1434 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
1435 ("PHY_SetTxPowerLevel8192S() Channel = %d\n",
1436 rtlphy->current_channel));
1437 rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel);
1438 }
1439
1440 rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl;
1441}
1442
1372void rtl92c_dm_watchdog(struct ieee80211_hw *hw) 1443void rtl92c_dm_watchdog(struct ieee80211_hw *hw)
1373{ 1444{
1374 struct rtl_priv *rtlpriv = rtl_priv(hw); 1445 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -1388,11 +1459,321 @@ void rtl92c_dm_watchdog(struct ieee80211_hw *hw)
1388 rtl92c_dm_dig(hw); 1459 rtl92c_dm_dig(hw);
1389 rtl92c_dm_false_alarm_counter_statistics(hw); 1460 rtl92c_dm_false_alarm_counter_statistics(hw);
1390 rtl92c_dm_dynamic_bb_powersaving(hw); 1461 rtl92c_dm_dynamic_bb_powersaving(hw);
1391 rtlpriv->cfg->ops->dm_dynamic_txpower(hw); 1462 rtl92c_dm_dynamic_txpower(hw);
1392 rtl92c_dm_check_txpower_tracking(hw); 1463 rtl92c_dm_check_txpower_tracking(hw);
1393 rtl92c_dm_refresh_rate_adaptive_mask(hw); 1464 rtl92c_dm_refresh_rate_adaptive_mask(hw);
1465 rtl92c_dm_bt_coexist(hw);
1394 rtl92c_dm_check_edca_turbo(hw); 1466 rtl92c_dm_check_edca_turbo(hw);
1395
1396 } 1467 }
1397} 1468}
1398EXPORT_SYMBOL(rtl92c_dm_watchdog); 1469EXPORT_SYMBOL(rtl92c_dm_watchdog);
1470
1471u8 rtl92c_bt_rssi_state_change(struct ieee80211_hw *hw)
1472{
1473 struct rtl_priv *rtlpriv = rtl_priv(hw);
1474 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1475 long undecorated_smoothed_pwdb;
1476 u8 curr_bt_rssi_state = 0x00;
1477
1478 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1479 undecorated_smoothed_pwdb =
1480 GET_UNDECORATED_AVERAGE_RSSI(rtlpriv);
1481 } else {
1482 if (rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb == 0)
1483 undecorated_smoothed_pwdb = 100;
1484 else
1485 undecorated_smoothed_pwdb =
1486 rtlpriv->dm.entry_min_undecoratedsmoothed_pwdb;
1487 }
1488
1489 /* Check RSSI to determine HighPower/NormalPower state for
1490 * BT coexistence. */
1491 if (undecorated_smoothed_pwdb >= 67)
1492 curr_bt_rssi_state &= (~BT_RSSI_STATE_NORMAL_POWER);
1493 else if (undecorated_smoothed_pwdb < 62)
1494 curr_bt_rssi_state |= BT_RSSI_STATE_NORMAL_POWER;
1495
1496 /* Check RSSI to determine AMPDU setting for BT coexistence. */
1497 if (undecorated_smoothed_pwdb >= 40)
1498 curr_bt_rssi_state &= (~BT_RSSI_STATE_AMDPU_OFF);
1499 else if (undecorated_smoothed_pwdb <= 32)
1500 curr_bt_rssi_state |= BT_RSSI_STATE_AMDPU_OFF;
1501
1502 /* Marked RSSI state. It will be used to determine BT coexistence
1503 * setting later. */
1504 if (undecorated_smoothed_pwdb < 35)
1505 curr_bt_rssi_state |= BT_RSSI_STATE_SPECIAL_LOW;
1506 else
1507 curr_bt_rssi_state &= (~BT_RSSI_STATE_SPECIAL_LOW);
1508
1509 /* Set Tx Power according to BT status. */
1510 if (undecorated_smoothed_pwdb >= 30)
1511 curr_bt_rssi_state |= BT_RSSI_STATE_TXPOWER_LOW;
1512 else if (undecorated_smoothed_pwdb < 25)
1513 curr_bt_rssi_state &= (~BT_RSSI_STATE_TXPOWER_LOW);
1514
1515 /* Check BT state related to BT_Idle in B/G mode. */
1516 if (undecorated_smoothed_pwdb < 15)
1517 curr_bt_rssi_state |= BT_RSSI_STATE_BG_EDCA_LOW;
1518 else
1519 curr_bt_rssi_state &= (~BT_RSSI_STATE_BG_EDCA_LOW);
1520
1521 if (curr_bt_rssi_state != rtlpcipriv->bt_coexist.bt_rssi_state) {
1522 rtlpcipriv->bt_coexist.bt_rssi_state = curr_bt_rssi_state;
1523 return true;
1524 } else {
1525 return false;
1526 }
1527}
1528EXPORT_SYMBOL(rtl92c_bt_rssi_state_change);
1529
1530static bool rtl92c_bt_state_change(struct ieee80211_hw *hw)
1531{
1532 struct rtl_priv *rtlpriv = rtl_priv(hw);
1533 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1534
1535 u32 polling, ratio_tx, ratio_pri;
1536 u32 bt_tx, bt_pri;
1537 u8 bt_state;
1538 u8 cur_service_type;
1539
1540 if (rtlpriv->mac80211.link_state < MAC80211_LINKED)
1541 return false;
1542
1543 bt_state = rtl_read_byte(rtlpriv, 0x4fd);
1544 bt_tx = rtl_read_dword(rtlpriv, 0x488);
1545 bt_tx = bt_tx & 0x00ffffff;
1546 bt_pri = rtl_read_dword(rtlpriv, 0x48c);
1547 bt_pri = bt_pri & 0x00ffffff;
1548 polling = rtl_read_dword(rtlpriv, 0x490);
1549
1550 if (bt_tx == 0xffffffff && bt_pri == 0xffffffff &&
1551 polling == 0xffffffff && bt_state == 0xff)
1552 return false;
1553
1554 bt_state &= BIT_OFFSET_LEN_MASK_32(0, 1);
1555 if (bt_state != rtlpcipriv->bt_coexist.bt_cur_state) {
1556 rtlpcipriv->bt_coexist.bt_cur_state = bt_state;
1557
1558 if (rtlpcipriv->bt_coexist.reg_bt_sco == 3) {
1559 rtlpcipriv->bt_coexist.bt_service = BT_IDLE;
1560
1561 bt_state = bt_state |
1562 ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
1563 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
1564 BIT_OFFSET_LEN_MASK_32(2, 1);
1565 rtl_write_byte(rtlpriv, 0x4fd, bt_state);
1566 }
1567 return true;
1568 }
1569
1570 ratio_tx = bt_tx * 1000 / polling;
1571 ratio_pri = bt_pri * 1000 / polling;
1572 rtlpcipriv->bt_coexist.ratio_tx = ratio_tx;
1573 rtlpcipriv->bt_coexist.ratio_pri = ratio_pri;
1574
1575 if (bt_state && rtlpcipriv->bt_coexist.reg_bt_sco == 3) {
1576
1577 if ((ratio_tx < 30) && (ratio_pri < 30))
1578 cur_service_type = BT_IDLE;
1579 else if ((ratio_pri > 110) && (ratio_pri < 250))
1580 cur_service_type = BT_SCO;
1581 else if ((ratio_tx >= 200) && (ratio_pri >= 200))
1582 cur_service_type = BT_BUSY;
1583 else if ((ratio_tx >= 350) && (ratio_tx < 500))
1584 cur_service_type = BT_OTHERBUSY;
1585 else if (ratio_tx >= 500)
1586 cur_service_type = BT_PAN;
1587 else
1588 cur_service_type = BT_OTHER_ACTION;
1589
1590 if (cur_service_type != rtlpcipriv->bt_coexist.bt_service) {
1591 rtlpcipriv->bt_coexist.bt_service = cur_service_type;
1592 bt_state = bt_state |
1593 ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
1594 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
1595 ((rtlpcipriv->bt_coexist.bt_service != BT_IDLE) ?
1596 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
1597
1598 /* Add interrupt migration when bt is not ini
1599 * idle state (no traffic). */
1600 if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) {
1601 rtl_write_word(rtlpriv, 0x504, 0x0ccc);
1602 rtl_write_byte(rtlpriv, 0x506, 0x54);
1603 rtl_write_byte(rtlpriv, 0x507, 0x54);
1604 } else {
1605 rtl_write_byte(rtlpriv, 0x506, 0x00);
1606 rtl_write_byte(rtlpriv, 0x507, 0x00);
1607 }
1608
1609 rtl_write_byte(rtlpriv, 0x4fd, bt_state);
1610 return true;
1611 }
1612 }
1613
1614 return false;
1615
1616}
1617
1618static bool rtl92c_bt_wifi_connect_change(struct ieee80211_hw *hw)
1619{
1620 struct rtl_priv *rtlpriv = rtl_priv(hw);
1621 static bool media_connect;
1622
1623 if (rtlpriv->mac80211.link_state < MAC80211_LINKED) {
1624 media_connect = false;
1625 } else {
1626 if (!media_connect) {
1627 media_connect = true;
1628 return true;
1629 }
1630 media_connect = true;
1631 }
1632
1633 return false;
1634}
1635
1636static void rtl92c_bt_set_normal(struct ieee80211_hw *hw)
1637{
1638 struct rtl_priv *rtlpriv = rtl_priv(hw);
1639 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1640
1641
1642 if (rtlpcipriv->bt_coexist.bt_service == BT_OTHERBUSY) {
1643 rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea72b;
1644 rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea72b;
1645 } else if (rtlpcipriv->bt_coexist.bt_service == BT_BUSY) {
1646 rtlpcipriv->bt_coexist.bt_edca_ul = 0x5eb82f;
1647 rtlpcipriv->bt_coexist.bt_edca_dl = 0x5eb82f;
1648 } else if (rtlpcipriv->bt_coexist.bt_service == BT_SCO) {
1649 if (rtlpcipriv->bt_coexist.ratio_tx > 160) {
1650 rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea72f;
1651 rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea72f;
1652 } else {
1653 rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea32b;
1654 rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea42b;
1655 }
1656 } else {
1657 rtlpcipriv->bt_coexist.bt_edca_ul = 0;
1658 rtlpcipriv->bt_coexist.bt_edca_dl = 0;
1659 }
1660
1661 if ((rtlpcipriv->bt_coexist.bt_service != BT_IDLE) &&
1662 (rtlpriv->mac80211.mode == WIRELESS_MODE_G ||
1663 (rtlpriv->mac80211.mode == (WIRELESS_MODE_G | WIRELESS_MODE_B))) &&
1664 (rtlpcipriv->bt_coexist.bt_rssi_state &
1665 BT_RSSI_STATE_BG_EDCA_LOW)) {
1666 rtlpcipriv->bt_coexist.bt_edca_ul = 0x5eb82b;
1667 rtlpcipriv->bt_coexist.bt_edca_dl = 0x5eb82b;
1668 }
1669}
1670
1671static void rtl92c_bt_ant_isolation(struct ieee80211_hw *hw)
1672{
1673 struct rtl_priv *rtlpriv = rtl_priv(hw);
1674 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1675
1676
1677 /* Only enable HW BT coexist when BT in "Busy" state. */
1678 if (rtlpriv->mac80211.vendor == PEER_CISCO &&
1679 rtlpcipriv->bt_coexist.bt_service == BT_OTHER_ACTION) {
1680 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
1681 } else {
1682 if ((rtlpcipriv->bt_coexist.bt_service == BT_BUSY) &&
1683 (rtlpcipriv->bt_coexist.bt_rssi_state &
1684 BT_RSSI_STATE_NORMAL_POWER)) {
1685 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
1686 } else if ((rtlpcipriv->bt_coexist.bt_service ==
1687 BT_OTHER_ACTION) && (rtlpriv->mac80211.mode <
1688 WIRELESS_MODE_N_24G) &&
1689 (rtlpcipriv->bt_coexist.bt_rssi_state &
1690 BT_RSSI_STATE_SPECIAL_LOW)) {
1691 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
1692 } else if (rtlpcipriv->bt_coexist.bt_service == BT_PAN) {
1693 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0x00);
1694 } else {
1695 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0x00);
1696 }
1697 }
1698
1699 if (rtlpcipriv->bt_coexist.bt_service == BT_PAN)
1700 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x10100);
1701 else
1702 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x0);
1703
1704 if (rtlpcipriv->bt_coexist.bt_rssi_state &
1705 BT_RSSI_STATE_NORMAL_POWER) {
1706 rtl92c_bt_set_normal(hw);
1707 } else {
1708 rtlpcipriv->bt_coexist.bt_edca_ul = 0;
1709 rtlpcipriv->bt_coexist.bt_edca_dl = 0;
1710 }
1711
1712 if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) {
1713 rtlpriv->cfg->ops->set_rfreg(hw,
1714 RF90_PATH_A,
1715 0x1e,
1716 0xf0, 0xf);
1717 } else {
1718 rtlpriv->cfg->ops->set_rfreg(hw,
1719 RF90_PATH_A, 0x1e, 0xf0,
1720 rtlpcipriv->bt_coexist.bt_rfreg_origin_1e);
1721 }
1722
1723 if (!rtlpriv->dm.dynamic_txpower_enable) {
1724 if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) {
1725 if (rtlpcipriv->bt_coexist.bt_rssi_state &
1726 BT_RSSI_STATE_TXPOWER_LOW) {
1727 rtlpriv->dm.dynamic_txhighpower_lvl =
1728 TXHIGHPWRLEVEL_BT2;
1729 } else {
1730 rtlpriv->dm.dynamic_txhighpower_lvl =
1731 TXHIGHPWRLEVEL_BT1;
1732 }
1733 } else {
1734 rtlpriv->dm.dynamic_txhighpower_lvl =
1735 TXHIGHPWRLEVEL_NORMAL;
1736 }
1737 rtl92c_phy_set_txpower_level(hw,
1738 rtlpriv->phy.current_channel);
1739 }
1740}
1741
1742static void rtl92c_check_bt_change(struct ieee80211_hw *hw)
1743{
1744 struct rtl_priv *rtlpriv = rtl_priv(hw);
1745 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1746
1747 if (rtlpcipriv->bt_coexist.bt_cur_state) {
1748 if (rtlpcipriv->bt_coexist.bt_ant_isolation)
1749 rtl92c_bt_ant_isolation(hw);
1750 } else {
1751 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0x00);
1752 rtlpriv->cfg->ops->set_rfreg(hw, RF90_PATH_A, 0x1e, 0xf0,
1753 rtlpcipriv->bt_coexist.bt_rfreg_origin_1e);
1754
1755 rtlpcipriv->bt_coexist.bt_edca_ul = 0;
1756 rtlpcipriv->bt_coexist.bt_edca_dl = 0;
1757 }
1758}
1759
1760void rtl92c_dm_bt_coexist(struct ieee80211_hw *hw)
1761{
1762 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1763
1764 bool wifi_connect_change;
1765 bool bt_state_change;
1766 bool rssi_state_change;
1767
1768 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1769 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
1770
1771 wifi_connect_change = rtl92c_bt_wifi_connect_change(hw);
1772 bt_state_change = rtl92c_bt_state_change(hw);
1773 rssi_state_change = rtl92c_bt_rssi_state_change(hw);
1774
1775 if (wifi_connect_change || bt_state_change || rssi_state_change)
1776 rtl92c_check_bt_change(hw);
1777 }
1778}
1779EXPORT_SYMBOL(rtl92c_dm_bt_coexist);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
index b9cbb0a3c03f..b9736d3e9a39 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.h
@@ -200,5 +200,7 @@ void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal);
200void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta); 200void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta);
201void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw); 201void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw);
202void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool recovery); 202void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool recovery);
203void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw);
204void rtl92c_dm_bt_coexist(struct ieee80211_hw *hw);
203 205
204#endif 206#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
index bc9d24134ac4..50303e1adff1 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
@@ -223,29 +223,15 @@ int rtl92c_download_fw(struct ieee80211_hw *hw)
223 u8 *pfwdata; 223 u8 *pfwdata;
224 u32 fwsize; 224 u32 fwsize;
225 enum version_8192c version = rtlhal->version; 225 enum version_8192c version = rtlhal->version;
226 const struct firmware *firmware;
227 226
228 printk(KERN_INFO "rtl8192c: Loading firmware file %s\n", 227 printk(KERN_INFO "rtl8192c: Loading firmware file %s\n",
229 rtlpriv->cfg->fw_name); 228 rtlpriv->cfg->fw_name);
230 if (request_firmware(&firmware, rtlpriv->cfg->fw_name, 229 if (!rtlhal->pfirmware)
231 rtlpriv->io.dev)) {
232 printk(KERN_ERR "rtl8192c: Firmware loading failed\n");
233 return 1; 230 return 1;
234 }
235
236 if (firmware->size > 0x4000) {
237 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
238 ("Firmware is too big!\n"));
239 release_firmware(firmware);
240 return 1;
241 }
242
243 memcpy(rtlhal->pfirmware, firmware->data, firmware->size);
244 fwsize = firmware->size;
245 release_firmware(firmware);
246 231
247 pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware; 232 pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware;
248 pfwdata = (u8 *) rtlhal->pfirmware; 233 pfwdata = (u8 *) rtlhal->pfirmware;
234 fwsize = rtlhal->fwsize;
249 235
250 if (IS_FW_HEADER_EXIST(pfwheader)) { 236 if (IS_FW_HEADER_EXIST(pfwheader)) {
251 RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG, 237 RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG,
@@ -553,6 +539,39 @@ void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode)
553} 539}
554EXPORT_SYMBOL(rtl92c_set_fw_pwrmode_cmd); 540EXPORT_SYMBOL(rtl92c_set_fw_pwrmode_cmd);
555 541
542static bool _rtl92c_cmd_send_packet(struct ieee80211_hw *hw,
543 struct sk_buff *skb)
544{
545 struct rtl_priv *rtlpriv = rtl_priv(hw);
546 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
547 struct rtl8192_tx_ring *ring;
548 struct rtl_tx_desc *pdesc;
549 u8 own;
550 unsigned long flags;
551 struct sk_buff *pskb = NULL;
552
553 ring = &rtlpci->tx_ring[BEACON_QUEUE];
554
555 pskb = __skb_dequeue(&ring->queue);
556 if (pskb)
557 kfree_skb(pskb);
558
559 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
560
561 pdesc = &ring->desc[0];
562 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc, true, HW_DESC_OWN);
563
564 rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *) pdesc, 1, 1, skb);
565
566 __skb_queue_tail(&ring->queue, skb);
567
568 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
569
570 rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE);
571
572 return true;
573}
574
556#define BEACON_PG 0 /*->1*/ 575#define BEACON_PG 0 /*->1*/
557#define PSPOLL_PG 2 576#define PSPOLL_PG 2
558#define NULL_PG 3 577#define NULL_PG 3
@@ -670,7 +689,7 @@ static u8 reserved_page_packet[TOTAL_RESERVED_PKT_LEN] = {
670 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 689 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
671}; 690};
672 691
673void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished) 692void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished)
674{ 693{
675 struct rtl_priv *rtlpriv = rtl_priv(hw); 694 struct rtl_priv *rtlpriv = rtl_priv(hw);
676 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 695 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
@@ -679,12 +698,12 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
679 u32 totalpacketlen; 698 u32 totalpacketlen;
680 bool rtstatus; 699 bool rtstatus;
681 u8 u1RsvdPageLoc[3] = {0}; 700 u8 u1RsvdPageLoc[3] = {0};
682 bool b_dlok = false; 701 bool dlok = false;
683 702
684 u8 *beacon; 703 u8 *beacon;
685 u8 *p_pspoll; 704 u8 *pspoll;
686 u8 *nullfunc; 705 u8 *nullfunc;
687 u8 *p_probersp; 706 u8 *probersp;
688 /*--------------------------------------------------------- 707 /*---------------------------------------------------------
689 (1) beacon 708 (1) beacon
690 ---------------------------------------------------------*/ 709 ---------------------------------------------------------*/
@@ -695,10 +714,10 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
695 /*------------------------------------------------------- 714 /*-------------------------------------------------------
696 (2) ps-poll 715 (2) ps-poll
697 --------------------------------------------------------*/ 716 --------------------------------------------------------*/
698 p_pspoll = &reserved_page_packet[PSPOLL_PG * 128]; 717 pspoll = &reserved_page_packet[PSPOLL_PG * 128];
699 SET_80211_PS_POLL_AID(p_pspoll, (mac->assoc_id | 0xc000)); 718 SET_80211_PS_POLL_AID(pspoll, (mac->assoc_id | 0xc000));
700 SET_80211_PS_POLL_BSSID(p_pspoll, mac->bssid); 719 SET_80211_PS_POLL_BSSID(pspoll, mac->bssid);
701 SET_80211_PS_POLL_TA(p_pspoll, mac->mac_addr); 720 SET_80211_PS_POLL_TA(pspoll, mac->mac_addr);
702 721
703 SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1RsvdPageLoc, PSPOLL_PG); 722 SET_H2CCMD_RSVDPAGE_LOC_PSPOLL(u1RsvdPageLoc, PSPOLL_PG);
704 723
@@ -715,10 +734,10 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
715 /*--------------------------------------------------------- 734 /*---------------------------------------------------------
716 (4) probe response 735 (4) probe response
717 ----------------------------------------------------------*/ 736 ----------------------------------------------------------*/
718 p_probersp = &reserved_page_packet[PROBERSP_PG * 128]; 737 probersp = &reserved_page_packet[PROBERSP_PG * 128];
719 SET_80211_HDR_ADDRESS1(p_probersp, mac->bssid); 738 SET_80211_HDR_ADDRESS1(probersp, mac->bssid);
720 SET_80211_HDR_ADDRESS2(p_probersp, mac->mac_addr); 739 SET_80211_HDR_ADDRESS2(probersp, mac->mac_addr);
721 SET_80211_HDR_ADDRESS3(p_probersp, mac->bssid); 740 SET_80211_HDR_ADDRESS3(probersp, mac->bssid);
722 741
723 SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1RsvdPageLoc, PROBERSP_PG); 742 SET_H2CCMD_RSVDPAGE_LOC_PROBE_RSP(u1RsvdPageLoc, PROBERSP_PG);
724 743
@@ -736,12 +755,12 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished)
736 memcpy((u8 *) skb_put(skb, totalpacketlen), 755 memcpy((u8 *) skb_put(skb, totalpacketlen),
737 &reserved_page_packet, totalpacketlen); 756 &reserved_page_packet, totalpacketlen);
738 757
739 rtstatus = rtlpriv->cfg->ops->cmd_send_packet(hw, skb); 758 rtstatus = _rtl92c_cmd_send_packet(hw, skb);
740 759
741 if (rtstatus) 760 if (rtstatus)
742 b_dlok = true; 761 dlok = true;
743 762
744 if (b_dlok) { 763 if (dlok) {
745 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, 764 RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
746 ("Set RSVD page location to Fw.\n")); 765 ("Set RSVD page location to Fw.\n"));
747 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG, 766 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_DMESG,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.h b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.h
index 3db33bd14666..3d5823c12621 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.h
@@ -27,8 +27,8 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#ifndef __RTL92C__FW__H__ 30#ifndef __RTL92C__FW__COMMON__H__
31#define __RTL92C__FW__H__ 31#define __RTL92C__FW__COMMON__H__
32 32
33#define FW_8192C_SIZE 0x3000 33#define FW_8192C_SIZE 0x3000
34#define FW_8192C_START_ADDRESS 0x1000 34#define FW_8192C_START_ADDRESS 0x1000
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
index a70228278398..c5424cad43cb 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
@@ -78,27 +78,29 @@ void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw,
78 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), bitmask(%#x)," 78 RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, ("regaddr(%#x), bitmask(%#x),"
79 " data(%#x)\n", regaddr, bitmask, 79 " data(%#x)\n", regaddr, bitmask,
80 data)); 80 data));
81
81} 82}
82EXPORT_SYMBOL(rtl92c_phy_set_bb_reg); 83EXPORT_SYMBOL(rtl92c_phy_set_bb_reg);
83 84
84u32 _rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw *hw, 85u32 _rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw *hw,
85 enum radio_path rfpath, u32 offset) 86 enum radio_path rfpath, u32 offset)
86{ 87{
87 RT_ASSERT(false, ("deprecated!\n")); 88 RT_ASSERT(false, ("deprecated!\n"));
88 return 0; 89 return 0;
90
89} 91}
90EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_read); 92EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_read);
91 93
92void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw, 94void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw,
93 enum radio_path rfpath, u32 offset, 95 enum radio_path rfpath, u32 offset,
94 u32 data) 96 u32 data)
95{ 97{
96 RT_ASSERT(false, ("deprecated!\n")); 98 RT_ASSERT(false, ("deprecated!\n"));
97} 99}
98EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_write); 100EXPORT_SYMBOL(_rtl92c_phy_fw_rf_serial_write);
99 101
100u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw, 102u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw,
101 enum radio_path rfpath, u32 offset) 103 enum radio_path rfpath, u32 offset)
102{ 104{
103 struct rtl_priv *rtlpriv = rtl_priv(hw); 105 struct rtl_priv *rtlpriv = rtl_priv(hw);
104 struct rtl_phy *rtlphy = &(rtlpriv->phy); 106 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -149,8 +151,8 @@ u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw,
149EXPORT_SYMBOL(_rtl92c_phy_rf_serial_read); 151EXPORT_SYMBOL(_rtl92c_phy_rf_serial_read);
150 152
151void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw, 153void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw,
152 enum radio_path rfpath, u32 offset, 154 enum radio_path rfpath, u32 offset,
153 u32 data) 155 u32 data)
154{ 156{
155 u32 data_and_addr; 157 u32 data_and_addr;
156 u32 newoffset; 158 u32 newoffset;
@@ -197,6 +199,7 @@ static void _rtl92c_phy_bb_config_1t(struct ieee80211_hw *hw)
197 rtl_set_bbreg(hw, 0xe80, 0x0c000000, 0x2); 199 rtl_set_bbreg(hw, 0xe80, 0x0c000000, 0x2);
198 rtl_set_bbreg(hw, 0xe88, 0x0c000000, 0x2); 200 rtl_set_bbreg(hw, 0xe88, 0x0c000000, 0x2);
199} 201}
202
200bool rtl92c_phy_rf_config(struct ieee80211_hw *hw) 203bool rtl92c_phy_rf_config(struct ieee80211_hw *hw)
201{ 204{
202 struct rtl_priv *rtlpriv = rtl_priv(hw); 205 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -241,13 +244,14 @@ bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw)
241 rtlphy->cck_high_power = (bool) (rtl_get_bbreg(hw, 244 rtlphy->cck_high_power = (bool) (rtl_get_bbreg(hw,
242 RFPGA0_XA_HSSIPARAMETER2, 245 RFPGA0_XA_HSSIPARAMETER2,
243 0x200)); 246 0x200));
247
244 return true; 248 return true;
245} 249}
246EXPORT_SYMBOL(_rtl92c_phy_bb8192c_config_parafile); 250EXPORT_SYMBOL(_rtl92c_phy_bb8192c_config_parafile);
247 251
248void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw, 252void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw,
249 u32 regaddr, u32 bitmask, 253 u32 regaddr, u32 bitmask,
250 u32 data) 254 u32 data)
251{ 255{
252 struct rtl_priv *rtlpriv = rtl_priv(hw); 256 struct rtl_priv *rtlpriv = rtl_priv(hw);
253 struct rtl_phy *rtlphy = &(rtlpriv->phy); 257 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -317,61 +321,48 @@ void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw,
317 } 321 }
318 if (regaddr == RTXAGC_B_RATE54_24) { 322 if (regaddr == RTXAGC_B_RATE54_24) {
319 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][9] = data; 323 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][9] = data;
320
321 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 324 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
322 ("MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n", 325 ("MCSTxPowerLevelOriginalOffset[%d][9] = 0x%x\n",
323 rtlphy->pwrgroup_cnt, 326 rtlphy->pwrgroup_cnt,
324 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][9])); 327 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][9]));
325 } 328 }
326
327 if (regaddr == RTXAGC_B_CCK1_55_MCS32) { 329 if (regaddr == RTXAGC_B_CCK1_55_MCS32) {
328 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][14] = data; 330 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][14] = data;
329
330 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 331 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
331 ("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n", 332 ("MCSTxPowerLevelOriginalOffset[%d][14] = 0x%x\n",
332 rtlphy->pwrgroup_cnt, 333 rtlphy->pwrgroup_cnt,
333 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][14])); 334 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][14]));
334 } 335 }
335
336 if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) { 336 if (regaddr == RTXAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff) {
337 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][15] = data; 337 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][15] = data;
338
339 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 338 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
340 ("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n", 339 ("MCSTxPowerLevelOriginalOffset[%d][15] = 0x%x\n",
341 rtlphy->pwrgroup_cnt, 340 rtlphy->pwrgroup_cnt,
342 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][15])); 341 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][15]));
343 } 342 }
344
345 if (regaddr == RTXAGC_B_MCS03_MCS00) { 343 if (regaddr == RTXAGC_B_MCS03_MCS00) {
346 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][10] = data; 344 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][10] = data;
347
348 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 345 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
349 ("MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n", 346 ("MCSTxPowerLevelOriginalOffset[%d][10] = 0x%x\n",
350 rtlphy->pwrgroup_cnt, 347 rtlphy->pwrgroup_cnt,
351 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][10])); 348 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][10]));
352 } 349 }
353
354 if (regaddr == RTXAGC_B_MCS07_MCS04) { 350 if (regaddr == RTXAGC_B_MCS07_MCS04) {
355 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][11] = data; 351 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][11] = data;
356
357 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 352 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
358 ("MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n", 353 ("MCSTxPowerLevelOriginalOffset[%d][11] = 0x%x\n",
359 rtlphy->pwrgroup_cnt, 354 rtlphy->pwrgroup_cnt,
360 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][11])); 355 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][11]));
361 } 356 }
362
363 if (regaddr == RTXAGC_B_MCS11_MCS08) { 357 if (regaddr == RTXAGC_B_MCS11_MCS08) {
364 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][12] = data; 358 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][12] = data;
365
366 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 359 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
367 ("MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n", 360 ("MCSTxPowerLevelOriginalOffset[%d][12] = 0x%x\n",
368 rtlphy->pwrgroup_cnt, 361 rtlphy->pwrgroup_cnt,
369 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][12])); 362 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][12]));
370 } 363 }
371
372 if (regaddr == RTXAGC_B_MCS15_MCS12) { 364 if (regaddr == RTXAGC_B_MCS15_MCS12) {
373 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][13] = data; 365 rtlphy->MCS_TXPWR[rtlphy->pwrgroup_cnt][13] = data;
374
375 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 366 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
376 ("MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n", 367 ("MCSTxPowerLevelOriginalOffset[%d][13] = 0x%x\n",
377 rtlphy->pwrgroup_cnt, 368 rtlphy->pwrgroup_cnt,
@@ -583,6 +574,7 @@ static void _rtl92c_ccxpower_index_check(struct ieee80211_hw *hw,
583 574
584 rtlphy->cur_cck_txpwridx = cckpowerlevel[0]; 575 rtlphy->cur_cck_txpwridx = cckpowerlevel[0];
585 rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0]; 576 rtlphy->cur_ofdm24g_txpwridx = ofdmpowerlevel[0];
577
586} 578}
587 579
588void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel) 580void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel)
@@ -611,7 +603,6 @@ bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, long power_indbm)
611 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 603 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
612 u8 idx; 604 u8 idx;
613 u8 rf_path; 605 u8 rf_path;
614
615 u8 ccktxpwridx = _rtl92c_phy_dbm_to_txpwr_Idx(hw, 606 u8 ccktxpwridx = _rtl92c_phy_dbm_to_txpwr_Idx(hw,
616 WIRELESS_MODE_B, 607 WIRELESS_MODE_B,
617 power_indbm); 608 power_indbm);
@@ -639,11 +630,6 @@ bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, long power_indbm)
639} 630}
640EXPORT_SYMBOL(rtl92c_phy_update_txpower_dbm); 631EXPORT_SYMBOL(rtl92c_phy_update_txpower_dbm);
641 632
642void rtl92c_phy_set_beacon_hw_reg(struct ieee80211_hw *hw, u16 beaconinterval)
643{
644}
645EXPORT_SYMBOL(rtl92c_phy_set_beacon_hw_reg);
646
647u8 _rtl92c_phy_dbm_to_txpwr_Idx(struct ieee80211_hw *hw, 633u8 _rtl92c_phy_dbm_to_txpwr_Idx(struct ieee80211_hw *hw,
648 enum wireless_mode wirelessmode, 634 enum wireless_mode wirelessmode,
649 long power_indbm) 635 long power_indbm)
@@ -741,9 +727,9 @@ void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
741 if (rtlphy->set_bwmode_inprogress) 727 if (rtlphy->set_bwmode_inprogress)
742 return; 728 return;
743 rtlphy->set_bwmode_inprogress = true; 729 rtlphy->set_bwmode_inprogress = true;
744 if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) 730 if ((!is_hal_stop(rtlhal)) && !(RT_CANNOT_IO(hw))) {
745 rtlpriv->cfg->ops->phy_set_bw_mode_callback(hw); 731 rtlphy->set_bwmode_inprogress = false;
746 else { 732 } else {
747 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 733 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
748 ("FALSE driver sleep or unload\n")); 734 ("FALSE driver sleep or unload\n"));
749 rtlphy->set_bwmode_inprogress = false; 735 rtlphy->set_bwmode_inprogress = false;
@@ -773,8 +759,9 @@ void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw)
773 mdelay(delay); 759 mdelay(delay);
774 else 760 else
775 continue; 761 continue;
776 } else 762 } else {
777 rtlphy->sw_chnl_inprogress = false; 763 rtlphy->sw_chnl_inprogress = false;
764 }
778 break; 765 break;
779 } while (true); 766 } while (true);
780 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, ("<==\n")); 767 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, ("<==\n"));
@@ -811,9 +798,32 @@ u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw)
811} 798}
812EXPORT_SYMBOL(rtl92c_phy_sw_chnl); 799EXPORT_SYMBOL(rtl92c_phy_sw_chnl);
813 800
814static bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw, 801static bool _rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
815 u8 channel, u8 *stage, u8 *step, 802 u32 cmdtableidx, u32 cmdtablesz,
816 u32 *delay) 803 enum swchnlcmd_id cmdid,
804 u32 para1, u32 para2, u32 msdelay)
805{
806 struct swchnlcmd *pcmd;
807
808 if (cmdtable == NULL) {
809 RT_ASSERT(false, ("cmdtable cannot be NULL.\n"));
810 return false;
811 }
812
813 if (cmdtableidx >= cmdtablesz)
814 return false;
815
816 pcmd = cmdtable + cmdtableidx;
817 pcmd->cmdid = cmdid;
818 pcmd->para1 = para1;
819 pcmd->para2 = para2;
820 pcmd->msdelay = msdelay;
821 return true;
822}
823
824bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
825 u8 channel, u8 *stage, u8 *step,
826 u32 *delay)
817{ 827{
818 struct rtl_priv *rtlpriv = rtl_priv(hw); 828 struct rtl_priv *rtlpriv = rtl_priv(hw);
819 struct rtl_phy *rtlphy = &(rtlpriv->phy); 829 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -917,29 +927,6 @@ static bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
917 return false; 927 return false;
918} 928}
919 929
920static bool _rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable,
921 u32 cmdtableidx, u32 cmdtablesz,
922 enum swchnlcmd_id cmdid,
923 u32 para1, u32 para2, u32 msdelay)
924{
925 struct swchnlcmd *pcmd;
926
927 if (cmdtable == NULL) {
928 RT_ASSERT(false, ("cmdtable cannot be NULL.\n"));
929 return false;
930 }
931
932 if (cmdtableidx >= cmdtablesz)
933 return false;
934
935 pcmd = cmdtable + cmdtableidx;
936 pcmd->cmdid = cmdid;
937 pcmd->para1 = para1;
938 pcmd->para2 = para2;
939 pcmd->msdelay = msdelay;
940 return true;
941}
942
943bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath) 930bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath)
944{ 931{
945 return true; 932 return true;
@@ -1002,13 +989,13 @@ static u8 _rtl92c_phy_path_b_iqk(struct ieee80211_hw *hw)
1002 reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD); 989 reg_ebc = rtl_get_bbreg(hw, 0xebc, MASKDWORD);
1003 reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD); 990 reg_ec4 = rtl_get_bbreg(hw, 0xec4, MASKDWORD);
1004 reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD); 991 reg_ecc = rtl_get_bbreg(hw, 0xecc, MASKDWORD);
992
1005 if (!(reg_eac & BIT(31)) && 993 if (!(reg_eac & BIT(31)) &&
1006 (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) && 994 (((reg_eb4 & 0x03FF0000) >> 16) != 0x142) &&
1007 (((reg_ebc & 0x03FF0000) >> 16) != 0x42)) 995 (((reg_ebc & 0x03FF0000) >> 16) != 0x42))
1008 result |= 0x01; 996 result |= 0x01;
1009 else 997 else
1010 return result; 998 return result;
1011
1012 if (!(reg_eac & BIT(30)) && 999 if (!(reg_eac & BIT(30)) &&
1013 (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) && 1000 (((reg_ec4 & 0x03FF0000) >> 16) != 0x132) &&
1014 (((reg_ecc & 0x03FF0000) >> 16) != 0x36)) 1001 (((reg_ecc & 0x03FF0000) >> 16) != 0x36))
@@ -1023,9 +1010,9 @@ static void _rtl92c_phy_path_a_fill_iqk_matrix(struct ieee80211_hw *hw,
1023 u32 oldval_0, x, tx0_a, reg; 1010 u32 oldval_0, x, tx0_a, reg;
1024 long y, tx0_c; 1011 long y, tx0_c;
1025 1012
1026 if (final_candidate == 0xFF) 1013 if (final_candidate == 0xFF) {
1027 return; 1014 return;
1028 else if (iqk_ok) { 1015 } else if (iqk_ok) {
1029 oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE, 1016 oldval_0 = (rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE,
1030 MASKDWORD) >> 22) & 0x3FF; 1017 MASKDWORD) >> 22) & 0x3FF;
1031 x = result[final_candidate][0]; 1018 x = result[final_candidate][0];
@@ -1063,9 +1050,9 @@ static void _rtl92c_phy_path_b_fill_iqk_matrix(struct ieee80211_hw *hw,
1063 u32 oldval_1, x, tx1_a, reg; 1050 u32 oldval_1, x, tx1_a, reg;
1064 long y, tx1_c; 1051 long y, tx1_c;
1065 1052
1066 if (final_candidate == 0xFF) 1053 if (final_candidate == 0xFF) {
1067 return; 1054 return;
1068 else if (iqk_ok) { 1055 } else if (iqk_ok) {
1069 oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, 1056 oldval_1 = (rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE,
1070 MASKDWORD) >> 22) & 0x3FF; 1057 MASKDWORD) >> 22) & 0x3FF;
1071 x = result[final_candidate][4]; 1058 x = result[final_candidate][4];
@@ -1282,6 +1269,7 @@ static void _rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw,
1282 RFPGA0_XA_HSSIPARAMETER1, 1269 RFPGA0_XA_HSSIPARAMETER1,
1283 BIT(8)); 1270 BIT(8));
1284 } 1271 }
1272
1285 if (!rtlphy->rfpi_enable) 1273 if (!rtlphy->rfpi_enable)
1286 _rtl92c_phy_pi_mode_switch(hw, true); 1274 _rtl92c_phy_pi_mode_switch(hw, true);
1287 if (t == 0) { 1275 if (t == 0) {
@@ -1317,9 +1305,10 @@ static void _rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw,
1317 0x3FF0000) >> 16; 1305 0x3FF0000) >> 16;
1318 break; 1306 break;
1319 } else if (i == (retrycount - 1) && patha_ok == 0x01) 1307 } else if (i == (retrycount - 1) && patha_ok == 0x01)
1308
1320 result[t][0] = (rtl_get_bbreg(hw, 0xe94, 1309 result[t][0] = (rtl_get_bbreg(hw, 0xe94,
1321 MASKDWORD) & 0x3FF0000) >> 1310 MASKDWORD) & 0x3FF0000) >>
1322 16; 1311 16;
1323 result[t][1] = 1312 result[t][1] =
1324 (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 0x3FF0000) >> 16; 1313 (rtl_get_bbreg(hw, 0xe9c, MASKDWORD) & 0x3FF0000) >> 16;
1325 1314
@@ -1375,8 +1364,7 @@ static void _rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw,
1375static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, 1364static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
1376 char delta, bool is2t) 1365 char delta, bool is2t)
1377{ 1366{
1378 /* This routine is deliberately dummied out for later fixes */ 1367#if 0 /* This routine is deliberately dummied out for later fixes */
1379#if 0
1380 struct rtl_priv *rtlpriv = rtl_priv(hw); 1368 struct rtl_priv *rtlpriv = rtl_priv(hw);
1381 struct rtl_phy *rtlphy = &(rtlpriv->phy); 1369 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1382 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1370 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
@@ -1434,7 +1422,7 @@ static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
1434 0x04db25a4, 0x0b1b25a4 1422 0x04db25a4, 0x0b1b25a4
1435 }; 1423 };
1436 1424
1437 u32 apk_offset[PATH_NUM] = { 0xb68, 0xb6c }; 1425 const u32 apk_offset[PATH_NUM] = { 0xb68, 0xb6c };
1438 1426
1439 u32 apk_normal_offset[PATH_NUM] = { 0xb28, 0xb98 }; 1427 u32 apk_normal_offset[PATH_NUM] = { 0xb28, 0xb98 };
1440 1428
@@ -1463,13 +1451,15 @@ static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
1463 0x00050006 1451 0x00050006
1464 }; 1452 };
1465 1453
1466 const u32 apk_result[PATH_NUM][APK_BB_REG_NUM]; 1454 u32 apk_result[PATH_NUM][APK_BB_REG_NUM];
1467 1455
1468 long bb_offset, delta_v, delta_offset; 1456 long bb_offset, delta_v, delta_offset;
1469 1457
1470 if (!is2t) 1458 if (!is2t)
1471 pathbound = 1; 1459 pathbound = 1;
1472 1460
1461 return;
1462
1473 for (index = 0; index < PATH_NUM; index++) { 1463 for (index = 0; index < PATH_NUM; index++) {
1474 apk_offset[index] = apk_normal_offset[index]; 1464 apk_offset[index] = apk_normal_offset[index];
1475 apk_value[index] = apk_normal_value[index]; 1465 apk_value[index] = apk_normal_value[index];
@@ -1730,8 +1720,7 @@ static void _rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw,
1730 0x08)); 1720 0x08));
1731 1721
1732 } 1722 }
1733 1723 rtlphy->b_apk_done = true;
1734 rtlphy->apk_done = true;
1735#endif 1724#endif
1736} 1725}
1737 1726
@@ -1758,6 +1747,7 @@ static void _rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw,
1758 rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x1); 1747 rtl_set_bbreg(hw, RFPGA0_XA_RFINTERFACEOE, 0x300, 0x1);
1759 1748
1760 } 1749 }
1750
1761} 1751}
1762 1752
1763#undef IQK_ADDA_REG_NUM 1753#undef IQK_ADDA_REG_NUM
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
index 53ffb0981586..9a264c0d6127 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.h
@@ -27,8 +27,8 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#ifndef __RTL92C_PHY_H__ 30#ifndef __RTL92C_PHY_COMMON_H__
31#define __RTL92C_PHY_H__ 31#define __RTL92C_PHY_COMMON_H__
32 32
33#define MAX_PRECMD_CNT 16 33#define MAX_PRECMD_CNT 16
34#define MAX_RFDEPENDCMD_CNT 16 34#define MAX_RFDEPENDCMD_CNT 16
@@ -39,6 +39,7 @@
39#define RT_CANNOT_IO(hw) false 39#define RT_CANNOT_IO(hw) false
40#define HIGHPOWER_RADIOA_ARRAYLEN 22 40#define HIGHPOWER_RADIOA_ARRAYLEN 22
41 41
42#define IQK_ADDA_REG_NUM 16
42#define MAX_TOLERANCE 5 43#define MAX_TOLERANCE 5
43#define IQK_DELAY_TIME 1 44#define IQK_DELAY_TIME 1
44 45
@@ -56,6 +57,7 @@
56#define IQK_ADDA_REG_NUM 16 57#define IQK_ADDA_REG_NUM 16
57#define IQK_MAC_REG_NUM 4 58#define IQK_MAC_REG_NUM 4
58 59
60#define IQK_DELAY_TIME 1
59#define RF90_PATH_MAX 2 61#define RF90_PATH_MAX 2
60 62
61#define CT_OFFSET_MAC_ADDR 0X16 63#define CT_OFFSET_MAC_ADDR 0X16
@@ -77,6 +79,7 @@
77 79
78#define RTL92C_MAX_PATH_NUM 2 80#define RTL92C_MAX_PATH_NUM 2
79#define LLT_LAST_ENTRY_OF_TX_PKT_BUFFER 255 81#define LLT_LAST_ENTRY_OF_TX_PKT_BUFFER 255
82
80enum swchnlcmd_id { 83enum swchnlcmd_id {
81 CMDID_END, 84 CMDID_END,
82 CMDID_SET_TXPOWEROWER_LEVEL, 85 CMDID_SET_TXPOWEROWER_LEVEL,
@@ -184,45 +187,41 @@ struct tx_power_struct {
184 u32 mcs_original_offset[4][16]; 187 u32 mcs_original_offset[4][16];
185}; 188};
186 189
187extern u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw, 190u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw,
188 u32 regaddr, u32 bitmask); 191 u32 regaddr, u32 bitmask);
189extern void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw, 192void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw,
190 u32 regaddr, u32 bitmask, u32 data); 193 u32 regaddr, u32 bitmask, u32 data);
191extern u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw, 194u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
192 enum radio_path rfpath, u32 regaddr, 195 enum radio_path rfpath, u32 regaddr,
193 u32 bitmask); 196 u32 bitmask);
194extern void rtl92c_phy_set_rf_reg(struct ieee80211_hw *hw, 197bool rtl92c_phy_mac_config(struct ieee80211_hw *hw);
195 enum radio_path rfpath, u32 regaddr, 198bool rtl92c_phy_bb_config(struct ieee80211_hw *hw);
196 u32 bitmask, u32 data); 199bool rtl92c_phy_rf_config(struct ieee80211_hw *hw);
197extern bool rtl92c_phy_mac_config(struct ieee80211_hw *hw); 200bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
198extern bool rtl92c_phy_bb_config(struct ieee80211_hw *hw);
199extern bool rtl92c_phy_rf_config(struct ieee80211_hw *hw);
200extern bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
201 enum radio_path rfpath); 201 enum radio_path rfpath);
202extern void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 202void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
203extern void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, 203void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw,
204 long *powerlevel); 204 long *powerlevel);
205extern void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 205void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
206extern bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, 206bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw,
207 long power_indbm); 207 long power_indbm);
208extern void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw, 208void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw,
209 u8 operation); 209 u8 operation);
210extern void rtl92c_phy_set_bw_mode_callback(struct ieee80211_hw *hw); 210void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
211extern void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
212 enum nl80211_channel_type ch_type); 211 enum nl80211_channel_type ch_type);
213extern void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw); 212void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw);
214extern u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw); 213u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw);
215extern void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery); 214void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery);
216extern void rtl92c_phy_set_beacon_hw_reg(struct ieee80211_hw *hw, 215void rtl92c_phy_set_beacon_hw_reg(struct ieee80211_hw *hw,
217 u16 beaconinterval); 216 u16 beaconinterval);
218void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta); 217void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta);
219void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw); 218void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw);
220void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain); 219void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain);
221bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 220bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
222 enum radio_path rfpath); 221 enum radio_path rfpath);
223extern bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, 222bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw,
224 u32 rfpath); 223 u32 rfpath);
225extern bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw, 224bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
226 enum rf_pwrstate rfpwr_state); 225 enum rf_pwrstate rfpwr_state);
227void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw); 226void rtl92ce_phy_set_rf_on(struct ieee80211_hw *hw);
228void rtl92c_phy_set_io(struct ieee80211_hw *hw); 227void rtl92c_phy_set_io(struct ieee80211_hw *hw);
@@ -235,12 +234,25 @@ u8 _rtl92c_phy_dbm_to_txpwr_Idx(struct ieee80211_hw *hw,
235 enum wireless_mode wirelessmode, 234 enum wireless_mode wirelessmode,
236 long power_indbm); 235 long power_indbm);
237void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw); 236void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw);
238static bool _rtl92c_phy_set_sw_chnl_cmdarray(struct swchnlcmd *cmdtable, 237void _rtl92c_phy_set_rf_sleep(struct ieee80211_hw *hw);
239 u32 cmdtableidx, u32 cmdtablesz, 238bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
240 enum swchnlcmd_id cmdid, u32 para1, 239 u8 channel, u8 *stage, u8 *step,
241 u32 para2, u32 msdelay); 240 u32 *delay);
242static bool _rtl92c_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw, 241u8 rtl92c_bt_rssi_state_change(struct ieee80211_hw *hw);
243 u8 channel, u8 *stage, u8 *step, 242u32 _rtl92c_phy_fw_rf_serial_read(struct ieee80211_hw *hw,
244 u32 *delay); 243 enum radio_path rfpath, u32 offset);
244void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw,
245 enum radio_path rfpath, u32 offset,
246 u32 data);
247u32 _rtl92c_phy_rf_serial_read(struct ieee80211_hw *hw,
248 enum radio_path rfpath, u32 offset);
249void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw,
250 enum radio_path rfpath, u32 offset,
251 u32 data);
252bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw);
253void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw,
254 u32 regaddr, u32 bitmask,
255 u32 data);
256bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype);
245 257
246#endif 258#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
index 2f577c8828fc..35ff7df41a1d 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/def.h
@@ -121,19 +121,6 @@
121#define CHIP_92C 0x01 121#define CHIP_92C 0x01
122#define CHIP_88C 0x00 122#define CHIP_88C 0x00
123 123
124/* Add vendor information into chip version definition.
125 * Add UMC B-Cut and RTL8723 chip info definition.
126 *
127 * BIT 7 Reserved
128 * BIT 6 UMC BCut
129 * BIT 5 Manufacturer(TSMC/UMC)
130 * BIT 4 TEST/NORMAL
131 * BIT 3 8723 Version
132 * BIT 2 8723?
133 * BIT 1 1T2R?
134 * BIT 0 88C/92C
135*/
136
137enum version_8192c { 124enum version_8192c {
138 VERSION_A_CHIP_92C = 0x01, 125 VERSION_A_CHIP_92C = 0x01,
139 VERSION_A_CHIP_88C = 0x00, 126 VERSION_A_CHIP_88C = 0x00,
@@ -280,20 +267,6 @@ struct h2c_cmd_8192c {
280 u8 *p_cmdbuffer; 267 u8 *p_cmdbuffer;
281}; 268};
282 269
283static inline u8 _rtl92c_get_chnl_group(u8 chnl)
284{
285 u8 group = 0;
286
287 if (chnl < 3)
288 group = 0;
289 else if (chnl < 9)
290 group = 1;
291 else
292 group = 2;
293
294 return group;
295}
296
297/* NOTE: reference to rtl8192c_rates struct */ 270/* NOTE: reference to rtl8192c_rates struct */
298static inline int _rtl92c_rate_mapping(struct ieee80211_hw *hw, bool isHT, 271static inline int _rtl92c_rate_mapping(struct ieee80211_hw *hw, bool isHT,
299 u8 desc_rate, bool first_ampdu) 272 u8 desc_rate, bool first_ampdu)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/dm.c b/drivers/net/wireless/rtlwifi/rtl8192ce/dm.c
index 7d76504df4d1..2df33e53e15a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/dm.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/dm.c
@@ -29,10 +29,12 @@
29 29
30#include "../wifi.h" 30#include "../wifi.h"
31#include "../base.h" 31#include "../base.h"
32#include "../pci.h"
32#include "reg.h" 33#include "reg.h"
33#include "def.h" 34#include "def.h"
34#include "phy.h" 35#include "phy.h"
35#include "dm.h" 36#include "dm.h"
37#include "../rtl8192c/fw_common.h"
36 38
37void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw) 39void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw)
38{ 40{
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/dm.h b/drivers/net/wireless/rtlwifi/rtl8192ce/dm.h
index 36302ebae4a3..07dd9552e82f 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/dm.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/dm.h
@@ -192,6 +192,7 @@ void rtl92c_dm_init_edca_turbo(struct ieee80211_hw *hw);
192void rtl92c_dm_check_txpower_tracking(struct ieee80211_hw *hw); 192void rtl92c_dm_check_txpower_tracking(struct ieee80211_hw *hw);
193void rtl92c_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw); 193void rtl92c_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw);
194void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal); 194void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal);
195void rtl92c_dm_bt_coexist(struct ieee80211_hw *hw);
195void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw); 196void rtl92ce_dm_dynamic_txpower(struct ieee80211_hw *hw);
196 197
197#endif 198#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
index 05477f465a75..4a56138eb33c 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
@@ -30,12 +30,14 @@
30#include "../wifi.h" 30#include "../wifi.h"
31#include "../efuse.h" 31#include "../efuse.h"
32#include "../base.h" 32#include "../base.h"
33#include "../regd.h"
33#include "../cam.h" 34#include "../cam.h"
34#include "../ps.h" 35#include "../ps.h"
35#include "../pci.h" 36#include "../pci.h"
36#include "reg.h" 37#include "reg.h"
37#include "def.h" 38#include "def.h"
38#include "phy.h" 39#include "phy.h"
40#include "../rtl8192c/fw_common.h"
39#include "dm.h" 41#include "dm.h"
40#include "led.h" 42#include "led.h"
41#include "hw.h" 43#include "hw.h"
@@ -137,15 +139,6 @@ void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
137 139
138 break; 140 break;
139 } 141 }
140 case HW_VAR_MGT_FILTER:
141 *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP0);
142 break;
143 case HW_VAR_CTRL_FILTER:
144 *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP1);
145 break;
146 case HW_VAR_DATA_FILTER:
147 *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP2);
148 break;
149 default: 142 default:
150 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 143 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
151 ("switch case not process\n")); 144 ("switch case not process\n"));
@@ -156,6 +149,7 @@ void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
156void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) 149void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
157{ 150{
158 struct rtl_priv *rtlpriv = rtl_priv(hw); 151 struct rtl_priv *rtlpriv = rtl_priv(hw);
152 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
159 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 153 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
160 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 154 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
161 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 155 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
@@ -178,7 +172,7 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
178 rate_cfg |= 0x01; 172 rate_cfg |= 0x01;
179 rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff); 173 rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
180 rtl_write_byte(rtlpriv, REG_RRSR + 1, 174 rtl_write_byte(rtlpriv, REG_RRSR + 1,
181 (rate_cfg >> 8)&0xff); 175 (rate_cfg >> 8) & 0xff);
182 while (rate_cfg > 0x1) { 176 while (rate_cfg > 0x1) {
183 rate_cfg = (rate_cfg >> 1); 177 rate_cfg = (rate_cfg >> 1);
184 rate_index++; 178 rate_index++;
@@ -276,13 +270,19 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
276 break; 270 break;
277 } 271 }
278 case HW_VAR_AMPDU_FACTOR:{ 272 case HW_VAR_AMPDU_FACTOR:{
279 u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 }; 273 u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
274 u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
280 275
281 u8 factor_toset; 276 u8 factor_toset;
282 u8 *p_regtoset = NULL; 277 u8 *p_regtoset = NULL;
283 u8 index = 0; 278 u8 index = 0;
284 279
285 p_regtoset = regtoset_normal; 280 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
281 (rtlpcipriv->bt_coexist.bt_coexist_type ==
282 BT_CSR_BC4))
283 p_regtoset = regtoset_bt;
284 else
285 p_regtoset = regtoset_normal;
286 286
287 factor_toset = *((u8 *) val); 287 factor_toset = *((u8 *) val);
288 if (factor_toset <= 3) { 288 if (factor_toset <= 3) {
@@ -317,45 +317,7 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
317 } 317 }
318 case HW_VAR_AC_PARAM:{ 318 case HW_VAR_AC_PARAM:{
319 u8 e_aci = *((u8 *) val); 319 u8 e_aci = *((u8 *) val);
320 u32 u4b_ac_param; 320 rtl92c_dm_init_edca_turbo(hw);
321 u16 cw_min = le16_to_cpu(mac->ac[e_aci].cw_min);
322 u16 cw_max = le16_to_cpu(mac->ac[e_aci].cw_max);
323 u16 tx_op = le16_to_cpu(mac->ac[e_aci].tx_op);
324
325 u4b_ac_param = (u32) mac->ac[e_aci].aifs;
326 u4b_ac_param |= ((u32)cw_min
327 & 0xF) << AC_PARAM_ECW_MIN_OFFSET;
328 u4b_ac_param |= ((u32)cw_max &
329 0xF) << AC_PARAM_ECW_MAX_OFFSET;
330 u4b_ac_param |= (u32)tx_op << AC_PARAM_TXOP_OFFSET;
331
332 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
333 ("queue:%x, ac_param:%x\n", e_aci,
334 u4b_ac_param));
335
336 switch (e_aci) {
337 case AC1_BK:
338 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM,
339 u4b_ac_param);
340 break;
341 case AC0_BE:
342 rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM,
343 u4b_ac_param);
344 break;
345 case AC2_VI:
346 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM,
347 u4b_ac_param);
348 break;
349 case AC3_VO:
350 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM,
351 u4b_ac_param);
352 break;
353 default:
354 RT_ASSERT(false,
355 ("SetHwReg8185(): invalid aci: %d !\n",
356 e_aci));
357 break;
358 }
359 321
360 if (rtlpci->acm_method != eAcmWay2_SW) 322 if (rtlpci->acm_method != eAcmWay2_SW)
361 rtlpriv->cfg->ops->set_hw_reg(hw, 323 rtlpriv->cfg->ops->set_hw_reg(hw,
@@ -526,9 +488,6 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
526 case HW_VAR_CORRECT_TSF:{ 488 case HW_VAR_CORRECT_TSF:{
527 u8 btype_ibss = ((u8 *) (val))[0]; 489 u8 btype_ibss = ((u8 *) (val))[0];
528 490
529 /*btype_ibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ?
530 1 : 0;*/
531
532 if (btype_ibss == true) 491 if (btype_ibss == true)
533 _rtl92ce_stop_tx_beacon(hw); 492 _rtl92ce_stop_tx_beacon(hw);
534 493
@@ -537,7 +496,7 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
537 rtl_write_dword(rtlpriv, REG_TSFTR, 496 rtl_write_dword(rtlpriv, REG_TSFTR,
538 (u32) (mac->tsf & 0xffffffff)); 497 (u32) (mac->tsf & 0xffffffff));
539 rtl_write_dword(rtlpriv, REG_TSFTR + 4, 498 rtl_write_dword(rtlpriv, REG_TSFTR + 4,
540 (u32) ((mac->tsf >> 32)&0xffffffff)); 499 (u32) ((mac->tsf >> 32) & 0xffffffff));
541 500
542 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0); 501 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
543 502
@@ -547,15 +506,6 @@ void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
547 break; 506 break;
548 507
549 } 508 }
550 case HW_VAR_MGT_FILTER:
551 rtl_write_word(rtlpriv, REG_RXFLTMAP0, *(u16 *) val);
552 break;
553 case HW_VAR_CTRL_FILTER:
554 rtl_write_word(rtlpriv, REG_RXFLTMAP1, *(u16 *) val);
555 break;
556 case HW_VAR_DATA_FILTER:
557 rtl_write_word(rtlpriv, REG_RXFLTMAP2, *(u16 *) val);
558 break;
559 default: 509 default:
560 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("switch case " 510 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("switch case "
561 "not process\n")); 511 "not process\n"));
@@ -679,12 +629,12 @@ static void _rtl92ce_gen_refresh_led_state(struct ieee80211_hw *hw)
679 rtl92ce_sw_led_on(hw, pLed0); 629 rtl92ce_sw_led_on(hw, pLed0);
680 else 630 else
681 rtl92ce_sw_led_off(hw, pLed0); 631 rtl92ce_sw_led_off(hw, pLed0);
682
683} 632}
684 633
685static bool _rtl92ce_init_mac(struct ieee80211_hw *hw) 634static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
686{ 635{
687 struct rtl_priv *rtlpriv = rtl_priv(hw); 636 struct rtl_priv *rtlpriv = rtl_priv(hw);
637 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
688 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 638 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
689 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 639 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
690 640
@@ -693,9 +643,22 @@ static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
693 u16 retry; 643 u16 retry;
694 644
695 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00); 645 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
646 if (rtlpcipriv->bt_coexist.bt_coexistence) {
647 u32 value32;
648 value32 = rtl_read_dword(rtlpriv, REG_APS_FSMCO);
649 value32 |= (SOP_ABG | SOP_AMB | XOP_BTCK);
650 rtl_write_dword(rtlpriv, REG_APS_FSMCO, value32);
651 }
696 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b); 652 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
697 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F); 653 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
698 654
655 if (rtlpcipriv->bt_coexist.bt_coexistence) {
656 u32 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
657
658 u4b_tmp &= (~0x00024800);
659 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
660 }
661
699 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0); 662 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
700 udelay(2); 663 udelay(2);
701 664
@@ -726,6 +689,11 @@ static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
726 rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82); 689 rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
727 udelay(2); 690 udelay(2);
728 691
692 if (rtlpcipriv->bt_coexist.bt_coexistence) {
693 bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL+2) & 0xfd;
694 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL+2, bytetmp);
695 }
696
729 rtl_write_word(rtlpriv, REG_CR, 0x2ff); 697 rtl_write_word(rtlpriv, REG_CR, 0x2ff);
730 698
731 if (_rtl92ce_llt_table_init(hw) == false) 699 if (_rtl92ce_llt_table_init(hw) == false)
@@ -793,6 +761,7 @@ static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
793{ 761{
794 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 762 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
795 struct rtl_priv *rtlpriv = rtl_priv(hw); 763 struct rtl_priv *rtlpriv = rtl_priv(hw);
764 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
796 u8 reg_bw_opmode; 765 u8 reg_bw_opmode;
797 u32 reg_ratr, reg_prsr; 766 u32 reg_ratr, reg_prsr;
798 767
@@ -824,7 +793,11 @@ static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
824 rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000); 793 rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
825 rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504); 794 rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
826 795
827 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841); 796 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
797 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
798 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
799 else
800 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
828 801
829 rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2); 802 rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
830 803
@@ -840,11 +813,20 @@ static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
840 rtl_write_byte(rtlpriv, REG_PIFS, 0x1C); 813 rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
841 rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16); 814 rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
842 815
843 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020); 816 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
844 817 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
845 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020); 818 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
819 rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
820 } else {
821 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
822 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
823 }
846 824
847 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666); 825 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
826 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
827 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
828 else
829 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
848 830
849 rtl_write_byte(rtlpriv, REG_ACKTO, 0x40); 831 rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
850 832
@@ -948,8 +930,8 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw)
948 } 930 }
949 931
950 rtlhal->last_hmeboxnum = 0; 932 rtlhal->last_hmeboxnum = 0;
951 rtl92ce_phy_mac_config(hw); 933 rtl92c_phy_mac_config(hw);
952 rtl92ce_phy_bb_config(hw); 934 rtl92c_phy_bb_config(hw);
953 rtlphy->rf_mode = RF_OP_BY_SW_3WIRE; 935 rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
954 rtl92c_phy_rf_config(hw); 936 rtl92c_phy_rf_config(hw);
955 rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0, 937 rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
@@ -962,15 +944,20 @@ int rtl92ce_hw_init(struct ieee80211_hw *hw)
962 _rtl92ce_hw_configure(hw); 944 _rtl92ce_hw_configure(hw);
963 rtl_cam_reset_all_entry(hw); 945 rtl_cam_reset_all_entry(hw);
964 rtl92ce_enable_hw_security_config(hw); 946 rtl92ce_enable_hw_security_config(hw);
947
965 ppsc->rfpwr_state = ERFON; 948 ppsc->rfpwr_state = ERFON;
949
966 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); 950 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
967 _rtl92ce_enable_aspm_back_door(hw); 951 _rtl92ce_enable_aspm_back_door(hw);
968 rtlpriv->intf_ops->enable_aspm(hw); 952 rtlpriv->intf_ops->enable_aspm(hw);
953
954 rtl8192ce_bt_hw_init(hw);
955
969 if (ppsc->rfpwr_state == ERFON) { 956 if (ppsc->rfpwr_state == ERFON) {
970 rtl92c_phy_set_rfpath_switch(hw, 1); 957 rtl92c_phy_set_rfpath_switch(hw, 1);
971 if (iqk_initialized) 958 if (iqk_initialized) {
972 rtl92c_phy_iq_calibrate(hw, true); 959 rtl92c_phy_iq_calibrate(hw, true);
973 else { 960 } else {
974 rtl92c_phy_iq_calibrate(hw, false); 961 rtl92c_phy_iq_calibrate(hw, false);
975 iqk_initialized = true; 962 iqk_initialized = true;
976 } 963 }
@@ -1128,75 +1115,62 @@ static int _rtl92ce_set_media_status(struct ieee80211_hw *hw,
1128 return 0; 1115 return 0;
1129} 1116}
1130 1117
1131static void _rtl92ce_set_check_bssid(struct ieee80211_hw *hw, 1118void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1132 enum nl80211_iftype type)
1133{ 1119{
1134 struct rtl_priv *rtlpriv = rtl_priv(hw); 1120 struct rtl_priv *rtlpriv = rtl_priv(hw);
1135 u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR); 1121 u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR);
1136 u8 filterout_non_associated_bssid = false;
1137 1122
1138 switch (type) { 1123 if (rtlpriv->psc.rfpwr_state != ERFON)
1139 case NL80211_IFTYPE_ADHOC: 1124 return;
1140 case NL80211_IFTYPE_STATION:
1141 filterout_non_associated_bssid = true;
1142 break;
1143 case NL80211_IFTYPE_UNSPECIFIED:
1144 case NL80211_IFTYPE_AP:
1145 default:
1146 break;
1147 }
1148 1125
1149 if (filterout_non_associated_bssid == true) { 1126 if (check_bssid == true) {
1150 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN); 1127 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1151 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, 1128 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1152 (u8 *) (&reg_rcr)); 1129 (u8 *) (&reg_rcr));
1153 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4)); 1130 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
1154 } else if (filterout_non_associated_bssid == false) { 1131 } else if (check_bssid == false) {
1155 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN)); 1132 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1156 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0); 1133 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
1157 rtlpriv->cfg->ops->set_hw_reg(hw, 1134 rtlpriv->cfg->ops->set_hw_reg(hw,
1158 HW_VAR_RCR, (u8 *) (&reg_rcr)); 1135 HW_VAR_RCR, (u8 *) (&reg_rcr));
1159 } 1136 }
1137
1160} 1138}
1161 1139
1162int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type) 1140int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
1163{ 1141{
1142 struct rtl_priv *rtlpriv = rtl_priv(hw);
1143
1164 if (_rtl92ce_set_media_status(hw, type)) 1144 if (_rtl92ce_set_media_status(hw, type))
1165 return -EOPNOTSUPP; 1145 return -EOPNOTSUPP;
1166 _rtl92ce_set_check_bssid(hw, type); 1146
1147 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1148 if (type != NL80211_IFTYPE_AP)
1149 rtl92ce_set_check_bssid(hw, true);
1150 } else {
1151 rtl92ce_set_check_bssid(hw, false);
1152 }
1153
1167 return 0; 1154 return 0;
1168} 1155}
1169 1156
1157/* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1170void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci) 1158void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci)
1171{ 1159{
1172 struct rtl_priv *rtlpriv = rtl_priv(hw); 1160 struct rtl_priv *rtlpriv = rtl_priv(hw);
1173 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1174 u32 u4b_ac_param;
1175 u16 cw_min = le16_to_cpu(mac->ac[aci].cw_min);
1176 u16 cw_max = le16_to_cpu(mac->ac[aci].cw_max);
1177 u16 tx_op = le16_to_cpu(mac->ac[aci].tx_op);
1178
1179 rtl92c_dm_init_edca_turbo(hw); 1161 rtl92c_dm_init_edca_turbo(hw);
1180 u4b_ac_param = (u32) mac->ac[aci].aifs;
1181 u4b_ac_param |= (u32) ((cw_min & 0xF) << AC_PARAM_ECW_MIN_OFFSET);
1182 u4b_ac_param |= (u32) ((cw_max & 0xF) << AC_PARAM_ECW_MAX_OFFSET);
1183 u4b_ac_param |= (u32) (tx_op << AC_PARAM_TXOP_OFFSET);
1184 RT_TRACE(rtlpriv, COMP_QOS, DBG_DMESG,
1185 ("queue:%x, ac_param:%x aifs:%x cwmin:%x cwmax:%x txop:%x\n",
1186 aci, u4b_ac_param, mac->ac[aci].aifs, cw_min,
1187 cw_max, tx_op));
1188 switch (aci) { 1162 switch (aci) {
1189 case AC1_BK: 1163 case AC1_BK:
1190 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, u4b_ac_param); 1164 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1191 break; 1165 break;
1192 case AC0_BE: 1166 case AC0_BE:
1193 rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); 1167 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
1194 break; 1168 break;
1195 case AC2_VI: 1169 case AC2_VI:
1196 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, u4b_ac_param); 1170 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1197 break; 1171 break;
1198 case AC3_VO: 1172 case AC3_VO:
1199 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, u4b_ac_param); 1173 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1200 break; 1174 break;
1201 default: 1175 default:
1202 RT_ASSERT(false, ("invalid aci: %d !\n", aci)); 1176 RT_ASSERT(false, ("invalid aci: %d !\n", aci));
@@ -1227,8 +1201,10 @@ void rtl92ce_disable_interrupt(struct ieee80211_hw *hw)
1227static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw) 1201static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
1228{ 1202{
1229 struct rtl_priv *rtlpriv = rtl_priv(hw); 1203 struct rtl_priv *rtlpriv = rtl_priv(hw);
1204 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1230 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1205 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1231 u8 u1b_tmp; 1206 u8 u1b_tmp;
1207 u32 u4b_tmp;
1232 1208
1233 rtlpriv->intf_ops->enable_aspm(hw); 1209 rtlpriv->intf_ops->enable_aspm(hw);
1234 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); 1210 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
@@ -1243,13 +1219,27 @@ static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
1243 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00); 1219 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1244 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000); 1220 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
1245 u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL); 1221 u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
1246 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 | 1222 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1247 (u1b_tmp << 8)); 1223 ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
1224 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8))) {
1225 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00F30000 |
1226 (u1b_tmp << 8));
1227 } else {
1228 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 |
1229 (u1b_tmp << 8));
1230 }
1248 rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790); 1231 rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
1249 rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080); 1232 rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
1250 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80); 1233 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
1251 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23); 1234 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
1252 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e); 1235 if (rtlpcipriv->bt_coexist.bt_coexistence) {
1236 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
1237 u4b_tmp |= 0x03824800;
1238 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
1239 } else {
1240 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
1241 }
1242
1253 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e); 1243 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1254 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10); 1244 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
1255} 1245}
@@ -1327,6 +1317,7 @@ void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw,
1327 1317
1328 RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, 1318 RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
1329 ("add_msr:%x, rm_msr:%x\n", add_msr, rm_msr)); 1319 ("add_msr:%x, rm_msr:%x\n", add_msr, rm_msr));
1320
1330 if (add_msr) 1321 if (add_msr)
1331 rtlpci->irq_mask[0] |= add_msr; 1322 rtlpci->irq_mask[0] |= add_msr;
1332 if (rm_msr) 1323 if (rm_msr)
@@ -1582,7 +1573,7 @@ static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1582 ("RTL819X Not boot from eeprom, check it !!")); 1573 ("RTL819X Not boot from eeprom, check it !!"));
1583 } 1574 }
1584 1575
1585 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_LOUD, ("MAP\n"), 1576 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, ("MAP\n"),
1586 hwinfo, HWSET_MAX_SIZE); 1577 hwinfo, HWSET_MAX_SIZE);
1587 1578
1588 eeprom_id = *((u16 *)&hwinfo[0]); 1579 eeprom_id = *((u16 *)&hwinfo[0]);
@@ -1610,6 +1601,10 @@ static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1610 rtlefuse->autoload_failflag, 1601 rtlefuse->autoload_failflag,
1611 hwinfo); 1602 hwinfo);
1612 1603
1604 rtl8192ce_read_bt_coexist_info_from_hwpg(hw,
1605 rtlefuse->autoload_failflag,
1606 hwinfo);
1607
1613 rtlefuse->eeprom_channelplan = *(u8 *)&hwinfo[EEPROM_CHANNELPLAN]; 1608 rtlefuse->eeprom_channelplan = *(u8 *)&hwinfo[EEPROM_CHANNELPLAN];
1614 rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION]; 1609 rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
1615 rtlefuse->txpwr_fromeprom = true; 1610 rtlefuse->txpwr_fromeprom = true;
@@ -1618,6 +1613,9 @@ static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1618 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, 1613 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1619 ("EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid)); 1614 ("EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid));
1620 1615
1616 /* set channel paln to world wide 13 */
1617 rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
1618
1621 if (rtlhal->oem_id == RT_CID_DEFAULT) { 1619 if (rtlhal->oem_id == RT_CID_DEFAULT) {
1622 switch (rtlefuse->eeprom_oemid) { 1620 switch (rtlefuse->eeprom_oemid) {
1623 case EEPROM_CID_DEFAULT: 1621 case EEPROM_CID_DEFAULT:
@@ -1701,30 +1699,36 @@ void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw)
1701 } else { 1699 } else {
1702 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("Autoload ERR!!\n")); 1700 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("Autoload ERR!!\n"));
1703 } 1701 }
1704
1705 _rtl92ce_hal_customized_behavior(hw); 1702 _rtl92ce_hal_customized_behavior(hw);
1706} 1703}
1707 1704
1708void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw) 1705static void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw,
1706 struct ieee80211_sta *sta)
1709{ 1707{
1710 struct rtl_priv *rtlpriv = rtl_priv(hw); 1708 struct rtl_priv *rtlpriv = rtl_priv(hw);
1709 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1711 struct rtl_phy *rtlphy = &(rtlpriv->phy); 1710 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1712 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1711 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1713 1712 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1714 u32 ratr_value = (u32) mac->basic_rates; 1713 u32 ratr_value;
1715 u8 *mcsrate = mac->mcs;
1716 u8 ratr_index = 0; 1714 u8 ratr_index = 0;
1717 u8 nmode = mac->ht_enable; 1715 u8 nmode = mac->ht_enable;
1718 u8 mimo_ps = 1; 1716 u8 mimo_ps = IEEE80211_SMPS_OFF;
1719 u16 shortgi_rate; 1717 u16 shortgi_rate;
1720 u32 tmp_ratr_value; 1718 u32 tmp_ratr_value;
1721 u8 curtxbw_40mhz = mac->bw_40; 1719 u8 curtxbw_40mhz = mac->bw_40;
1722 u8 curshortgi_40mhz = mac->sgi_40; 1720 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1723 u8 curshortgi_20mhz = mac->sgi_20; 1721 1 : 0;
1722 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1723 1 : 0;
1724 enum wireless_mode wirelessmode = mac->mode; 1724 enum wireless_mode wirelessmode = mac->mode;
1725 1725
1726 ratr_value |= ((*(u16 *) (mcsrate))) << 12; 1726 if (rtlhal->current_bandtype == BAND_ON_5G)
1727 1727 ratr_value = sta->supp_rates[1] << 4;
1728 else
1729 ratr_value = sta->supp_rates[0];
1730 ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1731 sta->ht_cap.mcs.rx_mask[0] << 12);
1728 switch (wirelessmode) { 1732 switch (wirelessmode) {
1729 case WIRELESS_MODE_B: 1733 case WIRELESS_MODE_B:
1730 if (ratr_value & 0x0000000c) 1734 if (ratr_value & 0x0000000c)
@@ -1738,7 +1742,7 @@ void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw)
1738 case WIRELESS_MODE_N_24G: 1742 case WIRELESS_MODE_N_24G:
1739 case WIRELESS_MODE_N_5G: 1743 case WIRELESS_MODE_N_5G:
1740 nmode = 1; 1744 nmode = 1;
1741 if (mimo_ps == 0) { 1745 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1742 ratr_value &= 0x0007F005; 1746 ratr_value &= 0x0007F005;
1743 } else { 1747 } else {
1744 u32 ratr_mask; 1748 u32 ratr_mask;
@@ -1761,10 +1765,19 @@ void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw)
1761 break; 1765 break;
1762 } 1766 }
1763 1767
1764 ratr_value &= 0x0FFFFFFF; 1768 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1769 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) &&
1770 (rtlpcipriv->bt_coexist.bt_cur_state) &&
1771 (rtlpcipriv->bt_coexist.bt_ant_isolation) &&
1772 ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ||
1773 (rtlpcipriv->bt_coexist.bt_service == BT_BUSY)))
1774 ratr_value &= 0x0fffcfc0;
1775 else
1776 ratr_value &= 0x0FFFFFFF;
1765 1777
1766 if (nmode && ((curtxbw_40mhz && curshortgi_40mhz) || (!curtxbw_40mhz && 1778 if (nmode && ((curtxbw_40mhz &&
1767 curshortgi_20mhz))) { 1779 curshortgi_40mhz) || (!curtxbw_40mhz &&
1780 curshortgi_20mhz))) {
1768 1781
1769 ratr_value |= 0x10000000; 1782 ratr_value |= 0x10000000;
1770 tmp_ratr_value = (ratr_value >> 12); 1783 tmp_ratr_value = (ratr_value >> 12);
@@ -1784,24 +1797,42 @@ void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw)
1784 ("%x\n", rtl_read_dword(rtlpriv, REG_ARFR0))); 1797 ("%x\n", rtl_read_dword(rtlpriv, REG_ARFR0)));
1785} 1798}
1786 1799
1787void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level) 1800static void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw,
1801 struct ieee80211_sta *sta, u8 rssi_level)
1788{ 1802{
1789 struct rtl_priv *rtlpriv = rtl_priv(hw); 1803 struct rtl_priv *rtlpriv = rtl_priv(hw);
1790 struct rtl_phy *rtlphy = &(rtlpriv->phy); 1804 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1791 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1805 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1792 u32 ratr_bitmap = (u32) mac->basic_rates; 1806 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1793 u8 *p_mcsrate = mac->mcs; 1807 struct rtl_sta_info *sta_entry = NULL;
1808 u32 ratr_bitmap;
1794 u8 ratr_index; 1809 u8 ratr_index;
1795 u8 curtxbw_40mhz = mac->bw_40; 1810 u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1796 u8 curshortgi_40mhz = mac->sgi_40; 1811 ? 1 : 0;
1797 u8 curshortgi_20mhz = mac->sgi_20; 1812 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1798 enum wireless_mode wirelessmode = mac->mode; 1813 1 : 0;
1814 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1815 1 : 0;
1816 enum wireless_mode wirelessmode = 0;
1799 bool shortgi = false; 1817 bool shortgi = false;
1800 u8 rate_mask[5]; 1818 u8 rate_mask[5];
1801 u8 macid = 0; 1819 u8 macid = 0;
1802 u8 mimops = 1; 1820 u8 mimo_ps = IEEE80211_SMPS_OFF;
1803 1821
1804 ratr_bitmap |= (p_mcsrate[1] << 20) | (p_mcsrate[0] << 12); 1822 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
1823 wirelessmode = sta_entry->wireless_mode;
1824 if (mac->opmode == NL80211_IFTYPE_STATION)
1825 curtxbw_40mhz = mac->bw_40;
1826 else if (mac->opmode == NL80211_IFTYPE_AP ||
1827 mac->opmode == NL80211_IFTYPE_ADHOC)
1828 macid = sta->aid + 1;
1829
1830 if (rtlhal->current_bandtype == BAND_ON_5G)
1831 ratr_bitmap = sta->supp_rates[1] << 4;
1832 else
1833 ratr_bitmap = sta->supp_rates[0];
1834 ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1835 sta->ht_cap.mcs.rx_mask[0] << 12);
1805 switch (wirelessmode) { 1836 switch (wirelessmode) {
1806 case WIRELESS_MODE_B: 1837 case WIRELESS_MODE_B:
1807 ratr_index = RATR_INX_WIRELESS_B; 1838 ratr_index = RATR_INX_WIRELESS_B;
@@ -1828,7 +1859,7 @@ void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level)
1828 case WIRELESS_MODE_N_5G: 1859 case WIRELESS_MODE_N_5G:
1829 ratr_index = RATR_INX_WIRELESS_NGB; 1860 ratr_index = RATR_INX_WIRELESS_NGB;
1830 1861
1831 if (mimops == 0) { 1862 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1832 if (rssi_level == 1) 1863 if (rssi_level == 1)
1833 ratr_bitmap &= 0x00070000; 1864 ratr_bitmap &= 0x00070000;
1834 else if (rssi_level == 2) 1865 else if (rssi_level == 2)
@@ -1892,8 +1923,8 @@ void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level)
1892 } 1923 }
1893 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, 1924 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1894 ("ratr_bitmap :%x\n", ratr_bitmap)); 1925 ("ratr_bitmap :%x\n", ratr_bitmap));
1895 *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) | 1926 *(u32 *)&rate_mask = EF4BYTE((ratr_bitmap & 0x0fffffff) |
1896 (ratr_index << 28); 1927 (ratr_index << 28));
1897 rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80; 1928 rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
1898 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, ("Rate_index:%x, " 1929 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, ("Rate_index:%x, "
1899 "ratr_val:%x, %x:%x:%x:%x:%x\n", 1930 "ratr_val:%x, %x:%x:%x:%x:%x\n",
@@ -1902,6 +1933,20 @@ void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level)
1902 rate_mask[2], rate_mask[3], 1933 rate_mask[2], rate_mask[3],
1903 rate_mask[4])); 1934 rate_mask[4]));
1904 rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask); 1935 rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
1936
1937 if (macid != 0)
1938 sta_entry->ratr_index = ratr_index;
1939}
1940
1941void rtl92ce_update_hal_rate_tbl(struct ieee80211_hw *hw,
1942 struct ieee80211_sta *sta, u8 rssi_level)
1943{
1944 struct rtl_priv *rtlpriv = rtl_priv(hw);
1945
1946 if (rtlpriv->dm.useramask)
1947 rtl92ce_update_hal_rate_mask(hw, sta, rssi_level);
1948 else
1949 rtl92ce_update_hal_rate_table(hw, sta);
1905} 1950}
1906 1951
1907void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw) 1952void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw)
@@ -1919,7 +1964,7 @@ void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw)
1919 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer); 1964 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
1920} 1965}
1921 1966
1922bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid) 1967bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
1923{ 1968{
1924 struct rtl_priv *rtlpriv = rtl_priv(hw); 1969 struct rtl_priv *rtlpriv = rtl_priv(hw);
1925 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 1970 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
@@ -1929,7 +1974,7 @@ bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid)
1929 bool actuallyset = false; 1974 bool actuallyset = false;
1930 unsigned long flag; 1975 unsigned long flag;
1931 1976
1932 if ((rtlpci->up_first_time == 1) || (rtlpci->being_init_adapter)) 1977 if (rtlpci->being_init_adapter)
1933 return false; 1978 return false;
1934 1979
1935 if (ppsc->swrf_processing) 1980 if (ppsc->swrf_processing)
@@ -1946,12 +1991,6 @@ bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid)
1946 1991
1947 cur_rfstate = ppsc->rfpwr_state; 1992 cur_rfstate = ppsc->rfpwr_state;
1948 1993
1949 if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) &&
1950 RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM)) {
1951 rtlpriv->intf_ops->disable_aspm(hw);
1952 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM);
1953 }
1954
1955 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv, 1994 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
1956 REG_MAC_PINMUX_CFG)&~(BIT(3))); 1995 REG_MAC_PINMUX_CFG)&~(BIT(3)));
1957 1996
@@ -1976,38 +2015,13 @@ bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid)
1976 } 2015 }
1977 2016
1978 if (actuallyset) { 2017 if (actuallyset) {
1979 if (e_rfpowerstate_toset == ERFON) {
1980 if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) &&
1981 RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM)) {
1982 rtlpriv->intf_ops->disable_aspm(hw);
1983 RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM);
1984 }
1985 }
1986
1987 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); 2018 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
1988 ppsc->rfchange_inprogress = false; 2019 ppsc->rfchange_inprogress = false;
1989 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); 2020 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
1990 2021 } else {
1991 if (e_rfpowerstate_toset == ERFOFF) {
1992 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) {
1993 rtlpriv->intf_ops->enable_aspm(hw);
1994 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM);
1995 }
1996 }
1997
1998 } else if (e_rfpowerstate_toset == ERFOFF || cur_rfstate == ERFOFF) {
1999 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) 2022 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
2000 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 2023 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2001 2024
2002 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) {
2003 rtlpriv->intf_ops->enable_aspm(hw);
2004 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM);
2005 }
2006
2007 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2008 ppsc->rfchange_inprogress = false;
2009 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2010 } else {
2011 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); 2025 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2012 ppsc->rfchange_inprogress = false; 2026 ppsc->rfchange_inprogress = false;
2013 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); 2027 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
@@ -2086,15 +2100,31 @@ void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
2086 macaddr = cam_const_broad; 2100 macaddr = cam_const_broad;
2087 entry_id = key_index; 2101 entry_id = key_index;
2088 } else { 2102 } else {
2103 if (mac->opmode == NL80211_IFTYPE_AP) {
2104 entry_id = rtl_cam_get_free_entry(hw,
2105 p_macaddr);
2106 if (entry_id >= TOTAL_CAM_ENTRY) {
2107 RT_TRACE(rtlpriv, COMP_SEC,
2108 DBG_EMERG,
2109 ("Can not find free hw"
2110 " security cam entry\n"));
2111 return;
2112 }
2113 } else {
2114 entry_id = CAM_PAIRWISE_KEY_POSITION;
2115 }
2116
2089 key_index = PAIRWISE_KEYIDX; 2117 key_index = PAIRWISE_KEYIDX;
2090 entry_id = CAM_PAIRWISE_KEY_POSITION;
2091 is_pairwise = true; 2118 is_pairwise = true;
2092 } 2119 }
2093 } 2120 }
2094 2121
2095 if (rtlpriv->sec.key_len[key_index] == 0) { 2122 if (rtlpriv->sec.key_len[key_index] == 0) {
2096 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 2123 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2097 ("delete one entry\n")); 2124 ("delete one entry, entry_id is %d\n",
2125 entry_id));
2126 if (mac->opmode == NL80211_IFTYPE_AP)
2127 rtl_cam_del_entry(hw, p_macaddr);
2098 rtl_cam_delete_one_entry(hw, p_macaddr, entry_id); 2128 rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2099 } else { 2129 } else {
2100 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD, 2130 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
@@ -2146,3 +2176,132 @@ void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
2146 } 2176 }
2147 } 2177 }
2148} 2178}
2179
2180static void rtl8192ce_bt_var_init(struct ieee80211_hw *hw)
2181{
2182 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2183
2184 rtlpcipriv->bt_coexist.bt_coexistence =
2185 rtlpcipriv->bt_coexist.eeprom_bt_coexist;
2186 rtlpcipriv->bt_coexist.bt_ant_num =
2187 rtlpcipriv->bt_coexist.eeprom_bt_ant_num;
2188 rtlpcipriv->bt_coexist.bt_coexist_type =
2189 rtlpcipriv->bt_coexist.eeprom_bt_type;
2190
2191 if (rtlpcipriv->bt_coexist.reg_bt_iso == 2)
2192 rtlpcipriv->bt_coexist.bt_ant_isolation =
2193 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation;
2194 else
2195 rtlpcipriv->bt_coexist.bt_ant_isolation =
2196 rtlpcipriv->bt_coexist.reg_bt_iso;
2197
2198 rtlpcipriv->bt_coexist.bt_radio_shared_type =
2199 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared;
2200
2201 if (rtlpcipriv->bt_coexist.bt_coexistence) {
2202
2203 if (rtlpcipriv->bt_coexist.reg_bt_sco == 1)
2204 rtlpcipriv->bt_coexist.bt_service = BT_OTHER_ACTION;
2205 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 2)
2206 rtlpcipriv->bt_coexist.bt_service = BT_SCO;
2207 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 4)
2208 rtlpcipriv->bt_coexist.bt_service = BT_BUSY;
2209 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 5)
2210 rtlpcipriv->bt_coexist.bt_service = BT_OTHERBUSY;
2211 else
2212 rtlpcipriv->bt_coexist.bt_service = BT_IDLE;
2213
2214 rtlpcipriv->bt_coexist.bt_edca_ul = 0;
2215 rtlpcipriv->bt_coexist.bt_edca_dl = 0;
2216 rtlpcipriv->bt_coexist.bt_rssi_state = 0xff;
2217 }
2218}
2219
2220void rtl8192ce_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
2221 bool auto_load_fail, u8 *hwinfo)
2222{
2223 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2224 u8 value;
2225
2226 if (!auto_load_fail) {
2227 rtlpcipriv->bt_coexist.eeprom_bt_coexist =
2228 ((hwinfo[RF_OPTION1] & 0xe0) >> 5);
2229 value = hwinfo[RF_OPTION4];
2230 rtlpcipriv->bt_coexist.eeprom_bt_type = ((value & 0xe) >> 1);
2231 rtlpcipriv->bt_coexist.eeprom_bt_ant_num = (value & 0x1);
2232 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation =
2233 ((value & 0x10) >> 4);
2234 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared =
2235 ((value & 0x20) >> 5);
2236 } else {
2237 rtlpcipriv->bt_coexist.eeprom_bt_coexist = 0;
2238 rtlpcipriv->bt_coexist.eeprom_bt_type = BT_2WIRE;
2239 rtlpcipriv->bt_coexist.eeprom_bt_ant_num = ANT_X2;
2240 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation = 0;
2241 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
2242 }
2243
2244 rtl8192ce_bt_var_init(hw);
2245}
2246
2247void rtl8192ce_bt_reg_init(struct ieee80211_hw *hw)
2248{
2249 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2250
2251 /* 0:Low, 1:High, 2:From Efuse. */
2252 rtlpcipriv->bt_coexist.reg_bt_iso = 2;
2253 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2254 rtlpcipriv->bt_coexist.reg_bt_sco = 3;
2255 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2256 rtlpcipriv->bt_coexist.reg_bt_sco = 0;
2257}
2258
2259
2260void rtl8192ce_bt_hw_init(struct ieee80211_hw *hw)
2261{
2262 struct rtl_priv *rtlpriv = rtl_priv(hw);
2263 struct rtl_phy *rtlphy = &(rtlpriv->phy);
2264 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2265
2266 u8 u1_tmp;
2267
2268 if (rtlpcipriv->bt_coexist.bt_coexistence &&
2269 ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
2270 rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8)) {
2271
2272 if (rtlpcipriv->bt_coexist.bt_ant_isolation)
2273 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
2274
2275 u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
2276 BIT_OFFSET_LEN_MASK_32(0, 1);
2277 u1_tmp = u1_tmp |
2278 ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
2279 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
2280 ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ?
2281 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
2282 rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
2283
2284 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
2285 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
2286 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
2287
2288 /* Config to 1T1R. */
2289 if (rtlphy->rf_type == RF_1T1R) {
2290 u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
2291 u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2292 rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
2293
2294 u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
2295 u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2296 rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
2297 }
2298 }
2299}
2300
2301void rtl92ce_suspend(struct ieee80211_hw *hw)
2302{
2303}
2304
2305void rtl92ce_resume(struct ieee80211_hw *hw)
2306{
2307}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.h b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.h
index a3dfdb635168..07dbe3e340a5 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/hw.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/hw.h
@@ -30,7 +30,18 @@
30#ifndef __RTL92CE_HW_H__ 30#ifndef __RTL92CE_HW_H__
31#define __RTL92CE_HW_H__ 31#define __RTL92CE_HW_H__
32 32
33#define H2C_RA_MASK 6 33static inline u8 _rtl92c_get_chnl_group(u8 chnl)
34{
35 u8 group;
36
37 if (chnl < 3)
38 group = 0;
39 else if (chnl < 9)
40 group = 1;
41 else
42 group = 2;
43 return group;
44}
34 45
35void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); 46void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val);
36void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw); 47void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw);
@@ -41,28 +52,27 @@ void rtl92ce_card_disable(struct ieee80211_hw *hw);
41void rtl92ce_enable_interrupt(struct ieee80211_hw *hw); 52void rtl92ce_enable_interrupt(struct ieee80211_hw *hw);
42void rtl92ce_disable_interrupt(struct ieee80211_hw *hw); 53void rtl92ce_disable_interrupt(struct ieee80211_hw *hw);
43int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type); 54int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type);
55void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid);
44void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci); 56void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci);
45void rtl92ce_set_beacon_related_registers(struct ieee80211_hw *hw); 57void rtl92ce_set_beacon_related_registers(struct ieee80211_hw *hw);
46void rtl92ce_set_beacon_interval(struct ieee80211_hw *hw); 58void rtl92ce_set_beacon_interval(struct ieee80211_hw *hw);
47void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw, 59void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw,
48 u32 add_msr, u32 rm_msr); 60 u32 add_msr, u32 rm_msr);
49void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); 61void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val);
50void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw); 62void rtl92ce_update_hal_rate_tbl(struct ieee80211_hw *hw,
51void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level); 63 struct ieee80211_sta *sta, u8 rssi_level);
52void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw); 64void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw);
53bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid); 65bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid);
54void rtl92ce_enable_hw_security_config(struct ieee80211_hw *hw); 66void rtl92ce_enable_hw_security_config(struct ieee80211_hw *hw);
55void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index, 67void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
56 u8 *p_macaddr, bool is_group, u8 enc_algo, 68 u8 *p_macaddr, bool is_group, u8 enc_algo,
57 bool is_wepkey, bool clear_all); 69 bool is_wepkey, bool clear_all);
58bool _rtl92ce_phy_config_mac_with_headerfile(struct ieee80211_hw *hw); 70
59void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool b_dl_finished); 71void rtl8192ce_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
60void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode); 72 bool autoload_fail, u8 *hwinfo);
61void rtl92c_set_fw_joinbss_report_cmd(struct ieee80211_hw *hw, u8 mstatus); 73void rtl8192ce_bt_reg_init(struct ieee80211_hw *hw);
62int rtl92c_download_fw(struct ieee80211_hw *hw); 74void rtl8192ce_bt_hw_init(struct ieee80211_hw *hw);
63void rtl92c_firmware_selfreset(struct ieee80211_hw *hw); 75void rtl92ce_suspend(struct ieee80211_hw *hw);
64void rtl92c_fill_h2c_cmd(struct ieee80211_hw *hw, 76void rtl92ce_resume(struct ieee80211_hw *hw);
65 u8 element_id, u32 cmd_len, u8 *p_cmdbuffer);
66bool rtl92ce_phy_mac_config(struct ieee80211_hw *hw);
67 77
68#endif 78#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/led.c b/drivers/net/wireless/rtlwifi/rtl8192ce/led.c
index d21b934b5c33..9dd1ed7b6422 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/led.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/led.c
@@ -106,12 +106,11 @@ void rtl92ce_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled)
106void rtl92ce_init_sw_leds(struct ieee80211_hw *hw) 106void rtl92ce_init_sw_leds(struct ieee80211_hw *hw)
107{ 107{
108 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 108 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
109
110 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0); 109 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led0), LED_PIN_LED0);
111 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1); 110 _rtl92ce_init_led(hw, &(pcipriv->ledctl.sw_led1), LED_PIN_LED1);
112} 111}
113 112
114void _rtl92ce_sw_led_control(struct ieee80211_hw *hw, 113static void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
115 enum led_ctl_mode ledaction) 114 enum led_ctl_mode ledaction)
116{ 115{
117 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); 116 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
@@ -146,7 +145,7 @@ void rtl92ce_led_control(struct ieee80211_hw *hw,
146 ledaction == LED_CTL_POWER_ON)) { 145 ledaction == LED_CTL_POWER_ON)) {
147 return; 146 return;
148 } 147 }
149 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, ("ledaction %d,\n", 148 RT_TRACE(rtlpriv, COMP_LED, DBG_LOUD, ("ledaction %d.\n",
150 ledaction)); 149 ledaction));
151 _rtl92ce_sw_led_control(hw, ledaction); 150 _rtl92ce_sw_led_control(hw, ledaction);
152} 151}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/led.h b/drivers/net/wireless/rtlwifi/rtl8192ce/led.h
index 94332b3af5b1..7dfccea2095b 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/led.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/led.h
@@ -34,7 +34,5 @@ void rtl92ce_init_sw_leds(struct ieee80211_hw *hw);
34void rtl92ce_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled); 34void rtl92ce_sw_led_on(struct ieee80211_hw *hw, struct rtl_led *pled);
35void rtl92ce_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled); 35void rtl92ce_sw_led_off(struct ieee80211_hw *hw, struct rtl_led *pled);
36void rtl92ce_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction); 36void rtl92ce_led_control(struct ieee80211_hw *hw, enum led_ctl_mode ledaction);
37void _rtl92ce_sw_led_control(struct ieee80211_hw *hw,
38 enum led_ctl_mode ledaction);
39 37
40#endif 38#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.c b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.c
index d0541e8c6012..73ae8a431848 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.c
@@ -38,7 +38,9 @@
38#include "dm.h" 38#include "dm.h"
39#include "table.h" 39#include "table.h"
40 40
41u32 rtl92ce_phy_query_rf_reg(struct ieee80211_hw *hw, 41static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
42
43u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
42 enum radio_path rfpath, u32 regaddr, u32 bitmask) 44 enum radio_path rfpath, u32 regaddr, u32 bitmask)
43{ 45{
44 struct rtl_priv *rtlpriv = rtl_priv(hw); 46 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -73,9 +75,47 @@ u32 rtl92ce_phy_query_rf_reg(struct ieee80211_hw *hw,
73 return readback_value; 75 return readback_value;
74} 76}
75 77
78bool rtl92c_phy_mac_config(struct ieee80211_hw *hw)
79{
80 struct rtl_priv *rtlpriv = rtl_priv(hw);
81 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
82 bool is92c = IS_92C_SERIAL(rtlhal->version);
83 bool rtstatus = _rtl92c_phy_config_mac_with_headerfile(hw);
84
85 if (is92c)
86 rtl_write_byte(rtlpriv, 0x14, 0x71);
87 return rtstatus;
88}
89
90bool rtl92c_phy_bb_config(struct ieee80211_hw *hw)
91{
92 bool rtstatus = true;
93 struct rtl_priv *rtlpriv = rtl_priv(hw);
94 u16 regval;
95 u32 regvaldw;
96 u8 reg_hwparafile = 1;
97
98 _rtl92c_phy_init_bb_rf_register_definition(hw);
99 regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
100 rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
101 regval | BIT(13) | BIT(0) | BIT(1));
102 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
103 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
104 rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
105 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
106 FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
107 FEN_BB_GLB_RSTn | FEN_BBRSTB);
108 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
109 regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
110 rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
111 if (reg_hwparafile == 1)
112 rtstatus = _rtl92c_phy_bb8192c_config_parafile(hw);
113 return rtstatus;
114}
115
76void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw, 116void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
77 enum radio_path rfpath, 117 enum radio_path rfpath,
78 u32 regaddr, u32 bitmask, u32 data) 118 u32 regaddr, u32 bitmask, u32 data)
79{ 119{
80 struct rtl_priv *rtlpriv = rtl_priv(hw); 120 struct rtl_priv *rtlpriv = rtl_priv(hw);
81 struct rtl_phy *rtlphy = &(rtlpriv->phy); 121 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -121,45 +161,7 @@ void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
121 bitmask, data, rfpath)); 161 bitmask, data, rfpath));
122} 162}
123 163
124bool rtl92ce_phy_mac_config(struct ieee80211_hw *hw) 164static bool _rtl92c_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
125{
126 struct rtl_priv *rtlpriv = rtl_priv(hw);
127 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
128 bool is92c = IS_92C_SERIAL(rtlhal->version);
129 bool rtstatus = _rtl92ce_phy_config_mac_with_headerfile(hw);
130
131 if (is92c)
132 rtl_write_byte(rtlpriv, 0x14, 0x71);
133 return rtstatus;
134}
135
136bool rtl92ce_phy_bb_config(struct ieee80211_hw *hw)
137{
138 bool rtstatus = true;
139 struct rtl_priv *rtlpriv = rtl_priv(hw);
140 u16 regval;
141 u32 regvaldw;
142 u8 reg_hwparafile = 1;
143
144 _rtl92c_phy_init_bb_rf_register_definition(hw);
145 regval = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
146 rtl_write_word(rtlpriv, REG_SYS_FUNC_EN,
147 regval | BIT(13) | BIT(0) | BIT(1));
148 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x83);
149 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL + 1, 0xdb);
150 rtl_write_byte(rtlpriv, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
151 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN,
152 FEN_PPLL | FEN_PCIEA | FEN_DIO_PCIE |
153 FEN_BB_GLB_RSTn | FEN_BBRSTB);
154 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL + 1, 0x80);
155 regvaldw = rtl_read_dword(rtlpriv, REG_LEDCFG0);
156 rtl_write_dword(rtlpriv, REG_LEDCFG0, regvaldw | BIT(23));
157 if (reg_hwparafile == 1)
158 rtstatus = _rtl92c_phy_bb8192c_config_parafile(hw);
159 return rtstatus;
160}
161
162bool _rtl92ce_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
163{ 165{
164 struct rtl_priv *rtlpriv = rtl_priv(hw); 166 struct rtl_priv *rtlpriv = rtl_priv(hw);
165 u32 i; 167 u32 i;
@@ -177,7 +179,7 @@ bool _rtl92ce_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
177} 179}
178 180
179bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 181bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
180 u8 configtype) 182 u8 configtype)
181{ 183{
182 int i; 184 int i;
183 u32 *phy_regarray_table; 185 u32 *phy_regarray_table;
@@ -236,7 +238,7 @@ bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
236} 238}
237 239
238bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw, 240bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
239 u8 configtype) 241 u8 configtype)
240{ 242{
241 struct rtl_priv *rtlpriv = rtl_priv(hw); 243 struct rtl_priv *rtlpriv = rtl_priv(hw);
242 int i; 244 int i;
@@ -274,7 +276,7 @@ bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
274 return true; 276 return true;
275} 277}
276 278
277bool rtl92ce_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 279bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
278 enum radio_path rfpath) 280 enum radio_path rfpath)
279{ 281{
280 282
@@ -364,74 +366,6 @@ bool rtl92ce_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
364 return true; 366 return true;
365} 367}
366 368
367void rtl92ce_phy_set_bw_mode_callback(struct ieee80211_hw *hw)
368{
369 struct rtl_priv *rtlpriv = rtl_priv(hw);
370 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
371 struct rtl_phy *rtlphy = &(rtlpriv->phy);
372 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
373 u8 reg_bw_opmode;
374 u8 reg_prsr_rsc;
375
376 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE,
377 ("Switch to %s bandwidth\n",
378 rtlphy->current_chan_bw == HT_CHANNEL_WIDTH_20 ?
379 "20MHz" : "40MHz"))
380
381 if (is_hal_stop(rtlhal))
382 return;
383
384 reg_bw_opmode = rtl_read_byte(rtlpriv, REG_BWOPMODE);
385 reg_prsr_rsc = rtl_read_byte(rtlpriv, REG_RRSR + 2);
386
387 switch (rtlphy->current_chan_bw) {
388 case HT_CHANNEL_WIDTH_20:
389 reg_bw_opmode |= BW_OPMODE_20MHZ;
390 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
391 break;
392
393 case HT_CHANNEL_WIDTH_20_40:
394 reg_bw_opmode &= ~BW_OPMODE_20MHZ;
395 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
396
397 reg_prsr_rsc =
398 (reg_prsr_rsc & 0x90) | (mac->cur_40_prime_sc << 5);
399 rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_prsr_rsc);
400 break;
401
402 default:
403 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
404 ("unknown bandwidth: %#X\n", rtlphy->current_chan_bw));
405 break;
406 }
407
408 switch (rtlphy->current_chan_bw) {
409 case HT_CHANNEL_WIDTH_20:
410 rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x0);
411 rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x0);
412 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
413 break;
414 case HT_CHANNEL_WIDTH_20_40:
415 rtl_set_bbreg(hw, RFPGA0_RFMOD, BRFMOD, 0x1);
416 rtl_set_bbreg(hw, RFPGA1_RFMOD, BRFMOD, 0x1);
417 rtl_set_bbreg(hw, RCCK0_SYSTEM, BCCK_SIDEBAND,
418 (mac->cur_40_prime_sc >> 1));
419 rtl_set_bbreg(hw, ROFDM1_LSTF, 0xC00, mac->cur_40_prime_sc);
420 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 0);
421 rtl_set_bbreg(hw, 0x818, (BIT(26) | BIT(27)),
422 (mac->cur_40_prime_sc ==
423 HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
424 break;
425 default:
426 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
427 ("unknown bandwidth: %#X\n", rtlphy->current_chan_bw));
428 break;
429 }
430 rtl92c_phy_rf6052_set_bandwidth(hw, rtlphy->current_chan_bw);
431 rtlphy->set_bwmode_inprogress = false;
432 RT_TRACE(rtlpriv, COMP_SCAN, DBG_TRACE, ("<==\n"));
433}
434
435void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t) 369void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
436{ 370{
437 u8 tmpreg; 371 u8 tmpreg;
@@ -477,6 +411,36 @@ void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
477 } 411 }
478} 412}
479 413
414static void _rtl92ce_phy_set_rf_sleep(struct ieee80211_hw *hw)
415{
416 u32 u4b_tmp;
417 u8 delay = 5;
418 struct rtl_priv *rtlpriv = rtl_priv(hw);
419
420 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
421 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
422 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
423 u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
424 while (u4b_tmp != 0 && delay > 0) {
425 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x0);
426 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
427 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
428 u4b_tmp = rtl_get_rfreg(hw, RF90_PATH_A, 0, RFREG_OFFSET_MASK);
429 delay--;
430 }
431 if (delay == 0) {
432 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x00);
433 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
434 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3);
435 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0x00);
436 RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
437 ("Switch RF timeout !!!.\n"));
438 return;
439 }
440 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
441 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x22);
442}
443
480static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw, 444static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
481 enum rf_pwrstate rfpwr_state) 445 enum rf_pwrstate rfpwr_state)
482{ 446{
@@ -523,33 +487,6 @@ static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
523 break; 487 break;
524 } 488 }
525 case ERFOFF:{ 489 case ERFOFF:{
526 for (queue_id = 0, i = 0;
527 queue_id < RTL_PCI_MAX_TX_QUEUE_COUNT;) {
528 ring = &pcipriv->dev.tx_ring[queue_id];
529 if (skb_queue_len(&ring->queue) == 0 ||
530 queue_id == BEACON_QUEUE) {
531 queue_id++;
532 continue;
533 } else {
534 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
535 ("eRf Off/Sleep: %d times "
536 "TcbBusyQueue[%d] "
537 "=%d before doze!\n", (i + 1),
538 queue_id,
539 skb_queue_len(&ring->queue)));
540 udelay(10);
541 i++;
542 }
543 if (i >= MAX_DOZE_WAITING_TIMES_9x) {
544 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
545 ("\nERFOFF: %d times "
546 "TcbBusyQueue[%d] = %d !\n",
547 MAX_DOZE_WAITING_TIMES_9x,
548 queue_id,
549 skb_queue_len(&ring->queue)));
550 break;
551 }
552 }
553 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) { 490 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) {
554 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, 491 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
555 ("IPS Set eRf nic disable\n")); 492 ("IPS Set eRf nic disable\n"));
@@ -581,6 +518,7 @@ static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
581 "TcbBusyQueue[%d] =%d before " 518 "TcbBusyQueue[%d] =%d before "
582 "doze!\n", (i + 1), queue_id, 519 "doze!\n", (i + 1), queue_id,
583 skb_queue_len(&ring->queue))); 520 skb_queue_len(&ring->queue)));
521
584 udelay(10); 522 udelay(10);
585 i++; 523 i++;
586 } 524 }
@@ -599,7 +537,7 @@ static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
599 jiffies_to_msecs(jiffies - 537 jiffies_to_msecs(jiffies -
600 ppsc->last_awake_jiffies))); 538 ppsc->last_awake_jiffies)));
601 ppsc->last_sleep_jiffies = jiffies; 539 ppsc->last_sleep_jiffies = jiffies;
602 _rtl92c_phy_set_rf_sleep(hw); 540 _rtl92ce_phy_set_rf_sleep(hw);
603 break; 541 break;
604 } 542 }
605 default: 543 default:
@@ -614,10 +552,11 @@ static bool _rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
614 return bresult; 552 return bresult;
615} 553}
616 554
617bool rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw, 555bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
618 enum rf_pwrstate rfpwr_state) 556 enum rf_pwrstate rfpwr_state)
619{ 557{
620 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 558 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
559
621 bool bresult = false; 560 bool bresult = false;
622 561
623 if (rfpwr_state == ppsc->rfpwr_state) 562 if (rfpwr_state == ppsc->rfpwr_state)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
index a37267e3fc22..ad580852cc76 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/phy.h
@@ -39,6 +39,7 @@
39#define RT_CANNOT_IO(hw) false 39#define RT_CANNOT_IO(hw) false
40#define HIGHPOWER_RADIOA_ARRAYLEN 22 40#define HIGHPOWER_RADIOA_ARRAYLEN 22
41 41
42#define IQK_ADDA_REG_NUM 16
42#define MAX_TOLERANCE 5 43#define MAX_TOLERANCE 5
43#define IQK_DELAY_TIME 1 44#define IQK_DELAY_TIME 1
44 45
@@ -56,6 +57,8 @@
56#define IQK_ADDA_REG_NUM 16 57#define IQK_ADDA_REG_NUM 16
57#define IQK_MAC_REG_NUM 4 58#define IQK_MAC_REG_NUM 4
58 59
60#define IQK_DELAY_TIME 1
61
59#define RF90_PATH_MAX 2 62#define RF90_PATH_MAX 2
60 63
61#define CT_OFFSET_MAC_ADDR 0X16 64#define CT_OFFSET_MAC_ADDR 0X16
@@ -76,7 +79,7 @@
76#define CT_OFFSET_CUSTOMER_ID 0x7F 79#define CT_OFFSET_CUSTOMER_ID 0x7F
77 80
78#define RTL92C_MAX_PATH_NUM 2 81#define RTL92C_MAX_PATH_NUM 2
79#define LLT_LAST_ENTRY_OF_TX_PKT_BUFFER 255 82
80enum swchnlcmd_id { 83enum swchnlcmd_id {
81 CMDID_END, 84 CMDID_END,
82 CMDID_SET_TXPOWEROWER_LEVEL, 85 CMDID_SET_TXPOWEROWER_LEVEL,
@@ -184,43 +187,44 @@ struct tx_power_struct {
184 u32 mcs_original_offset[4][16]; 187 u32 mcs_original_offset[4][16];
185}; 188};
186 189
187extern u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw, 190bool rtl92c_phy_bb_config(struct ieee80211_hw *hw);
191u32 rtl92c_phy_query_bb_reg(struct ieee80211_hw *hw,
188 u32 regaddr, u32 bitmask); 192 u32 regaddr, u32 bitmask);
189extern void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw, 193void rtl92c_phy_set_bb_reg(struct ieee80211_hw *hw,
190 u32 regaddr, u32 bitmask, u32 data); 194 u32 regaddr, u32 bitmask, u32 data);
191extern u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw, 195u32 rtl92c_phy_query_rf_reg(struct ieee80211_hw *hw,
192 enum radio_path rfpath, u32 regaddr, 196 enum radio_path rfpath, u32 regaddr,
193 u32 bitmask); 197 u32 bitmask);
194extern void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw, 198extern void rtl92ce_phy_set_rf_reg(struct ieee80211_hw *hw,
195 enum radio_path rfpath, u32 regaddr, 199 enum radio_path rfpath, u32 regaddr,
196 u32 bitmask, u32 data); 200 u32 bitmask, u32 data);
197extern bool rtl92c_phy_mac_config(struct ieee80211_hw *hw); 201bool rtl92c_phy_mac_config(struct ieee80211_hw *hw);
198bool rtl92ce_phy_bb_config(struct ieee80211_hw *hw); 202bool rtl92ce_phy_bb_config(struct ieee80211_hw *hw);
199extern bool rtl92c_phy_rf_config(struct ieee80211_hw *hw); 203bool rtl92c_phy_rf_config(struct ieee80211_hw *hw);
200extern bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw, 204bool rtl92c_phy_config_rf_with_feaderfile(struct ieee80211_hw *hw,
201 enum radio_path rfpath); 205 enum radio_path rfpath);
202extern void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw); 206void rtl92c_phy_get_hw_reg_originalvalue(struct ieee80211_hw *hw);
203extern void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw, 207void rtl92c_phy_get_txpower_level(struct ieee80211_hw *hw,
204 long *powerlevel); 208 long *powerlevel);
205extern void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel); 209void rtl92c_phy_set_txpower_level(struct ieee80211_hw *hw, u8 channel);
206extern bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw, 210bool rtl92c_phy_update_txpower_dbm(struct ieee80211_hw *hw,
207 long power_indbm); 211 long power_indbm);
208extern void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw, 212void rtl92c_phy_scan_operation_backup(struct ieee80211_hw *hw,
209 u8 operation); 213 u8 operation);
210extern void rtl92c_phy_set_bw_mode_callback(struct ieee80211_hw *hw); 214void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
211extern void rtl92c_phy_set_bw_mode(struct ieee80211_hw *hw,
212 enum nl80211_channel_type ch_type); 215 enum nl80211_channel_type ch_type);
213extern void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw); 216void rtl92c_phy_sw_chnl_callback(struct ieee80211_hw *hw);
214extern u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw); 217u8 rtl92c_phy_sw_chnl(struct ieee80211_hw *hw);
215extern void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery); 218void rtl92c_phy_iq_calibrate(struct ieee80211_hw *hw, bool b_recovery);
216extern void rtl92c_phy_set_beacon_hw_reg(struct ieee80211_hw *hw, 219void rtl92c_phy_set_beacon_hw_reg(struct ieee80211_hw *hw,
217 u16 beaconinterval); 220 u16 beaconinterval);
218void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta); 221void rtl92c_phy_ap_calibrate(struct ieee80211_hw *hw, char delta);
219void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw); 222void rtl92c_phy_lc_calibrate(struct ieee80211_hw *hw);
223void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t);
220void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain); 224void rtl92c_phy_set_rfpath_switch(struct ieee80211_hw *hw, bool bmain);
221bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 225bool rtl92c_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
222 enum radio_path rfpath); 226 enum radio_path rfpath);
223extern bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, 227bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw,
224 u32 rfpath); 228 u32 rfpath);
225bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype); 229bool rtl92c_phy_set_io_cmd(struct ieee80211_hw *hw, enum io_type iotype);
226bool rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw, 230bool rtl92ce_phy_set_rf_power_state(struct ieee80211_hw *hw,
@@ -237,9 +241,6 @@ u32 _rtl92c_phy_calculate_bit_shift(u32 bitmask);
237void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw, 241void _rtl92c_phy_rf_serial_write(struct ieee80211_hw *hw,
238 enum radio_path rfpath, u32 offset, 242 enum radio_path rfpath, u32 offset,
239 u32 data); 243 u32 data);
240void _rtl92c_store_pwrIndex_diffrate_offset(struct ieee80211_hw *hw,
241 u32 regaddr, u32 bitmask,
242 u32 data);
243void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw, 244void _rtl92c_phy_fw_rf_serial_write(struct ieee80211_hw *hw,
244 enum radio_path rfpath, u32 offset, 245 enum radio_path rfpath, u32 offset,
245 u32 data); 246 u32 data);
@@ -250,5 +251,11 @@ bool _rtl92ce_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
250void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw); 251void _rtl92c_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw);
251bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw); 252bool _rtl92c_phy_bb8192c_config_parafile(struct ieee80211_hw *hw);
252void _rtl92c_phy_set_rf_sleep(struct ieee80211_hw *hw); 253void _rtl92c_phy_set_rf_sleep(struct ieee80211_hw *hw);
254bool rtl92c_phy_set_rf_power_state(struct ieee80211_hw *hw,
255 enum rf_pwrstate rfpwr_state);
256bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
257 u8 configtype);
258bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
259 u8 configtype);
253 260
254#endif 261#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h b/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
index b0868a613841..598cecc63f41 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/reg.h
@@ -72,6 +72,7 @@
72#define REG_GPIO_IO_SEL_2 0x0062 72#define REG_GPIO_IO_SEL_2 0x0062
73/* RTL8723 WIFI/BT/GPS Multi-Function control source. */ 73/* RTL8723 WIFI/BT/GPS Multi-Function control source. */
74#define REG_MULTI_FUNC_CTRL 0x0068 74#define REG_MULTI_FUNC_CTRL 0x0068
75
75#define REG_MCUFWDL 0x0080 76#define REG_MCUFWDL 0x0080
76 77
77#define REG_HMEBOX_EXT_0 0x0088 78#define REG_HMEBOX_EXT_0 0x0088
@@ -542,7 +543,7 @@
542#define IMR_OCPINT BIT(1) 543#define IMR_OCPINT BIT(1)
543#define IMR_WLANOFF BIT(0) 544#define IMR_WLANOFF BIT(0)
544 545
545#define HWSET_MAX_SIZE 128 546#define EFUSE_REAL_CONTENT_LEN 512
546 547
547#define EEPROM_DEFAULT_TSSI 0x0 548#define EEPROM_DEFAULT_TSSI 0x0
548#define EEPROM_DEFAULT_TXPOWERDIFF 0x0 549#define EEPROM_DEFAULT_TXPOWERDIFF 0x0
@@ -656,6 +657,7 @@
656#define STOPBE BIT(1) 657#define STOPBE BIT(1)
657#define STOPBK BIT(0) 658#define STOPBK BIT(0)
658 659
660#define RCR_APPFCS BIT(31)
659#define RCR_APP_FCS BIT(31) 661#define RCR_APP_FCS BIT(31)
660#define RCR_APP_MIC BIT(30) 662#define RCR_APP_MIC BIT(30)
661#define RCR_APP_ICV BIT(29) 663#define RCR_APP_ICV BIT(29)
@@ -688,6 +690,7 @@
688 690
689#define REG_USB_INFO 0xFE17 691#define REG_USB_INFO 0xFE17
690#define REG_USB_SPECIAL_OPTION 0xFE55 692#define REG_USB_SPECIAL_OPTION 0xFE55
693
691#define REG_USB_DMA_AGG_TO 0xFE5B 694#define REG_USB_DMA_AGG_TO 0xFE5B
692#define REG_USB_AGG_TO 0xFE5C 695#define REG_USB_AGG_TO 0xFE5C
693#define REG_USB_AGG_TH 0xFE5D 696#define REG_USB_AGG_TH 0xFE5D
@@ -775,7 +778,6 @@
775 778
776#define BOOT_FROM_EEPROM BIT(4) 779#define BOOT_FROM_EEPROM BIT(4)
777#define EEPROM_EN BIT(5) 780#define EEPROM_EN BIT(5)
778#define EEPROMSEL BOOT_FROM_EEPROM
779 781
780#define AFE_BGEN BIT(0) 782#define AFE_BGEN BIT(0)
781#define AFE_MBEN BIT(1) 783#define AFE_MBEN BIT(1)
@@ -901,28 +903,7 @@
901#define BD_PKG_SEL BIT(25) 903#define BD_PKG_SEL BIT(25)
902#define BD_HCI_SEL BIT(26) 904#define BD_HCI_SEL BIT(26)
903#define TYPE_ID BIT(27) 905#define TYPE_ID BIT(27)
904 906#define RF_RL_ID (BIT(31) | BIT(30) | BIT(29) | BIT(28))
905/* REG_GPIO_OUTSTS (For RTL8723 only) */
906#define EFS_HCI_SEL (BIT(0)|BIT(1))
907#define PAD_HCI_SEL (BIT(2)|BIT(3))
908#define HCI_SEL (BIT(4)|BIT(5))
909#define PKG_SEL_HCI BIT(6)
910#define FEN_GPS BIT(7)
911#define FEN_BT BIT(8)
912#define FEN_WL BIT(9)
913#define FEN_PCI BIT(10)
914#define FEN_USB BIT(11)
915#define BTRF_HWPDN_N BIT(12)
916#define WLRF_HWPDN_N BIT(13)
917#define PDN_BT_N BIT(14)
918#define PDN_GPS_N BIT(15)
919#define BT_CTL_HWPDN BIT(16)
920#define GPS_CTL_HWPDN BIT(17)
921#define PPHY_SUSB BIT(20)
922#define UPHY_SUSB BIT(21)
923#define PCI_SUSEN BIT(22)
924#define USB_SUSEN BIT(23)
925#define RF_RL_ID (BIT(31) | BIT(30) | BIT(29) | BIT(28))
926 907
927#define CHIP_VER_RTL_MASK 0xF000 908#define CHIP_VER_RTL_MASK 0xF000
928#define CHIP_VER_RTL_SHIFT 12 909#define CHIP_VER_RTL_SHIFT 12
@@ -1077,6 +1058,7 @@
1077#define _RARF_RC8(x) (((x) & 0x1F) << 24) 1058#define _RARF_RC8(x) (((x) & 0x1F) << 24)
1078 1059
1079#define AC_PARAM_TXOP_OFFSET 16 1060#define AC_PARAM_TXOP_OFFSET 16
1061#define AC_PARAM_TXOP_LIMIT_OFFSET 16
1080#define AC_PARAM_ECW_MAX_OFFSET 12 1062#define AC_PARAM_ECW_MAX_OFFSET 12
1081#define AC_PARAM_ECW_MIN_OFFSET 8 1063#define AC_PARAM_ECW_MIN_OFFSET 8
1082#define AC_PARAM_AIFS_OFFSET 0 1064#define AC_PARAM_AIFS_OFFSET 0
@@ -1221,33 +1203,11 @@
1221#define EPROM_CMD_CONFIG 0x3 1203#define EPROM_CMD_CONFIG 0x3
1222#define EPROM_CMD_LOAD 1 1204#define EPROM_CMD_LOAD 1
1223 1205
1224#define HWSET_MAX_SIZE_92S HWSET_MAX_SIZE 1206#define HWSET_MAX_SIZE_92S HWSET_MAX_SIZE
1225 1207
1226#define HAL_8192C_HW_GPIO_WPS_BIT BIT(2)
1227
1228/* REG_MULTI_FUNC_CTRL(For RTL8723 Only) */
1229/* Enable GPIO[9] as WiFi HW PDn source */
1230#define WL_HWPDN_EN BIT(0) 1208#define WL_HWPDN_EN BIT(0)
1231/* WiFi HW PDn polarity control */ 1209
1232#define WL_HWPDN_SL BIT(1) 1210#define HAL_8192C_HW_GPIO_WPS_BIT BIT(2)
1233/* WiFi function enable */
1234#define WL_FUNC_EN BIT(2)
1235/* Enable GPIO[9] as WiFi RF HW PDn source */
1236#define WL_HWROF_EN BIT(3)
1237/* Enable GPIO[11] as BT HW PDn source */
1238#define BT_HWPDN_EN BIT(16)
1239/* BT HW PDn polarity control */
1240#define BT_HWPDN_SL BIT(17)
1241/* BT function enable */
1242#define BT_FUNC_EN BIT(18)
1243/* Enable GPIO[11] as BT/GPS RF HW PDn source */
1244#define BT_HWROF_EN BIT(19)
1245/* Enable GPIO[10] as GPS HW PDn source */
1246#define GPS_HWPDN_EN BIT(20)
1247/* GPS HW PDn polarity control */
1248#define GPS_HWPDN_SL BIT(21)
1249/* GPS function enable */
1250#define GPS_FUNC_EN BIT(22)
1251 1211
1252#define RPMAC_RESET 0x100 1212#define RPMAC_RESET 0x100
1253#define RPMAC_TXSTART 0x104 1213#define RPMAC_TXSTART 0x104
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/rf.c b/drivers/net/wireless/rtlwifi/rtl8192ce/rf.c
index e301b12e281a..90d0f2cf3b27 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/rf.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/rf.c
@@ -34,9 +34,9 @@
34#include "rf.h" 34#include "rf.h"
35#include "dm.h" 35#include "dm.h"
36 36
37static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw); 37static bool _rtl92ce_phy_rf6052_config_parafile(struct ieee80211_hw *hw);
38 38
39void rtl92c_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth) 39void rtl92ce_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
40{ 40{
41 struct rtl_priv *rtlpriv = rtl_priv(hw); 41 struct rtl_priv *rtlpriv = rtl_priv(hw);
42 struct rtl_phy *rtlphy = &(rtlpriv->phy); 42 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -62,7 +62,7 @@ void rtl92c_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
62} 62}
63 63
64void rtl92ce_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 64void rtl92ce_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
65 u8 *ppowerlevel) 65 u8 *ppowerlevel)
66{ 66{
67 struct rtl_priv *rtlpriv = rtl_priv(hw); 67 struct rtl_priv *rtlpriv = rtl_priv(hw);
68 struct rtl_phy *rtlphy = &(rtlpriv->phy); 68 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -128,8 +128,7 @@ void rtl92ce_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
128 128
129 tmpval = tx_agc[RF90_PATH_A] >> 8; 129 tmpval = tx_agc[RF90_PATH_A] >> 8;
130 130
131 if (mac->mode == WIRELESS_MODE_B) 131 tmpval = tmpval & 0xff00ffff;
132 tmpval = tmpval & 0xff00ffff;
133 132
134 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); 133 rtl_set_bbreg(hw, RTXAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
135 134
@@ -440,16 +439,17 @@ bool rtl92ce_phy_rf6052_config(struct ieee80211_hw *hw)
440 else 439 else
441 rtlphy->num_total_rfpath = 2; 440 rtlphy->num_total_rfpath = 2;
442 441
443 return _rtl92c_phy_rf6052_config_parafile(hw); 442 return _rtl92ce_phy_rf6052_config_parafile(hw);
443
444} 444}
445 445
446static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw) 446static bool _rtl92ce_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
447{ 447{
448 struct rtl_priv *rtlpriv = rtl_priv(hw); 448 struct rtl_priv *rtlpriv = rtl_priv(hw);
449 struct rtl_phy *rtlphy = &(rtlpriv->phy); 449 struct rtl_phy *rtlphy = &(rtlpriv->phy);
450 u32 u4_regvalue = 0; 450 u32 u4_regvalue = 0;
451 u8 rfpath; 451 u8 rfpath;
452 bool rtstatus; 452 bool rtstatus = true;
453 struct bb_reg_def *pphyreg; 453 struct bb_reg_def *pphyreg;
454 454
455 for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) { 455 for (rfpath = 0; rfpath < rtlphy->num_total_rfpath; rfpath++) {
@@ -484,12 +484,12 @@ static bool _rtl92c_phy_rf6052_config_parafile(struct ieee80211_hw *hw)
484 484
485 switch (rfpath) { 485 switch (rfpath) {
486 case RF90_PATH_A: 486 case RF90_PATH_A:
487 rtstatus = rtl92ce_phy_config_rf_with_headerfile(hw, 487 rtstatus = rtl92c_phy_config_rf_with_headerfile(hw,
488 (enum radio_path) rfpath); 488 (enum radio_path)rfpath);
489 break; 489 break;
490 case RF90_PATH_B: 490 case RF90_PATH_B:
491 rtstatus = rtl92ce_phy_config_rf_with_headerfile(hw, 491 rtstatus = rtl92c_phy_config_rf_with_headerfile(hw,
492 (enum radio_path) rfpath); 492 (enum radio_path)rfpath);
493 break; 493 break;
494 case RF90_PATH_C: 494 case RF90_PATH_C:
495 break; 495 break;
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/rf.h b/drivers/net/wireless/rtlwifi/rtl8192ce/rf.h
index 3aa520c1c171..39ff03685986 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/rf.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/rf.h
@@ -34,14 +34,11 @@
34#define RF6052_MAX_REG 0x3F 34#define RF6052_MAX_REG 0x3F
35#define RF6052_MAX_PATH 2 35#define RF6052_MAX_PATH 2
36 36
37extern void rtl92c_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, 37extern void rtl92ce_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw,
38 u8 bandwidth); 38 u8 bandwidth);
39extern void rtl92c_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 39extern void rtl92ce_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
40 u8 *ppowerlevel); 40 u8 *ppowerlevel);
41extern void rtl92c_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 41extern void rtl92ce_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
42 u8 *ppowerlevel, u8 channel); 42 u8 *ppowerlevel, u8 channel);
43bool rtl92ce_phy_rf6052_config(struct ieee80211_hw *hw); 43extern bool rtl92ce_phy_rf6052_config(struct ieee80211_hw *hw);
44bool rtl92ce_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
45 enum radio_path rfpath);
46
47#endif 44#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
index f4e2f3dcccae..390bbb5ee11d 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
@@ -42,10 +42,58 @@
42#include "trx.h" 42#include "trx.h"
43#include "led.h" 43#include "led.h"
44 44
45static void rtl92c_init_aspm_vars(struct ieee80211_hw *hw)
46{
47 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
48
49 /*close ASPM for AMD defaultly */
50 rtlpci->const_amdpci_aspm = 0;
51
52 /*
53 * ASPM PS mode.
54 * 0 - Disable ASPM,
55 * 1 - Enable ASPM without Clock Req,
56 * 2 - Enable ASPM with Clock Req,
57 * 3 - Alwyas Enable ASPM with Clock Req,
58 * 4 - Always Enable ASPM without Clock Req.
59 * set defult to RTL8192CE:3 RTL8192E:2
60 * */
61 rtlpci->const_pci_aspm = 3;
62
63 /*Setting for PCI-E device */
64 rtlpci->const_devicepci_aspm_setting = 0x03;
65
66 /*Setting for PCI-E bridge */
67 rtlpci->const_hostpci_aspm_setting = 0x02;
68
69 /*
70 * In Hw/Sw Radio Off situation.
71 * 0 - Default,
72 * 1 - From ASPM setting without low Mac Pwr,
73 * 2 - From ASPM setting with low Mac Pwr,
74 * 3 - Bus D3
75 * set default to RTL8192CE:0 RTL8192SE:2
76 */
77 rtlpci->const_hwsw_rfoff_d3 = 0;
78
79 /*
80 * This setting works for those device with
81 * backdoor ASPM setting such as EPHY setting.
82 * 0 - Not support ASPM,
83 * 1 - Support ASPM,
84 * 2 - According to chipset.
85 */
86 rtlpci->const_support_pciaspm = 1;
87}
88
45int rtl92c_init_sw_vars(struct ieee80211_hw *hw) 89int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
46{ 90{
91 int err;
47 struct rtl_priv *rtlpriv = rtl_priv(hw); 92 struct rtl_priv *rtlpriv = rtl_priv(hw);
48 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 93 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
94 const struct firmware *firmware;
95
96 rtl8192ce_bt_reg_init(hw);
49 97
50 rtlpriv->dm.dm_initialgain_enable = 1; 98 rtlpriv->dm.dm_initialgain_enable = 1;
51 rtlpriv->dm.dm_flag = 0; 99 rtlpriv->dm.dm_flag = 0;
@@ -53,7 +101,12 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
53 rtlpriv->dm.thermalvalue = 0; 101 rtlpriv->dm.thermalvalue = 0;
54 rtlpci->transmit_config = CFENDFORM | BIT(12) | BIT(13); 102 rtlpci->transmit_config = CFENDFORM | BIT(12) | BIT(13);
55 103
56 rtlpci->receive_config = (RCR_APP_FCS | 104 /* compatible 5G band 88ce just 2.4G band & smsp */
105 rtlpriv->rtlhal.current_bandtype = BAND_ON_2_4G;
106 rtlpriv->rtlhal.bandset = BAND_ON_2_4G;
107 rtlpriv->rtlhal.macphymode = SINGLEMAC_SINGLEPHY;
108
109 rtlpci->receive_config = (RCR_APPFCS |
57 RCR_AMF | 110 RCR_AMF |
58 RCR_ADF | 111 RCR_ADF |
59 RCR_APP_MIC | 112 RCR_APP_MIC |
@@ -76,13 +129,49 @@ int rtl92c_init_sw_vars(struct ieee80211_hw *hw)
76 129
77 rtlpci->irq_mask[1] = (u32) (IMR_CPWM | IMR_C2HCMD | 0); 130 rtlpci->irq_mask[1] = (u32) (IMR_CPWM | IMR_C2HCMD | 0);
78 131
79 rtlpriv->rtlhal.pfirmware = (u8 *) vmalloc(0x4000); 132 /* for LPS & IPS */
133 rtlpriv->psc.inactiveps = rtlpriv->cfg->mod_params->inactiveps;
134 rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps;
135 rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps;
136 rtlpriv->psc.reg_fwctrl_lps = 3;
137 rtlpriv->psc.reg_max_lps_awakeintvl = 5;
138 /* for ASPM, you can close aspm through
139 * set const_support_pciaspm = 0 */
140 rtl92c_init_aspm_vars(hw);
141
142 if (rtlpriv->psc.reg_fwctrl_lps == 1)
143 rtlpriv->psc.fwctrl_psmode = FW_PS_MIN_MODE;
144 else if (rtlpriv->psc.reg_fwctrl_lps == 2)
145 rtlpriv->psc.fwctrl_psmode = FW_PS_MAX_MODE;
146 else if (rtlpriv->psc.reg_fwctrl_lps == 3)
147 rtlpriv->psc.fwctrl_psmode = FW_PS_DTIM_MODE;
148
149 /* for firmware buf */
150 rtlpriv->rtlhal.pfirmware = vzalloc(0x4000);
80 if (!rtlpriv->rtlhal.pfirmware) { 151 if (!rtlpriv->rtlhal.pfirmware) {
81 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 152 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
82 ("Can't alloc buffer for fw.\n")); 153 ("Can't alloc buffer for fw.\n"));
83 return 1; 154 return 1;
84 } 155 }
85 156
157 /* request fw */
158 err = request_firmware(&firmware, rtlpriv->cfg->fw_name,
159 rtlpriv->io.dev);
160 if (err) {
161 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
162 ("Failed to request firmware!\n"));
163 return 1;
164 }
165 if (firmware->size > 0x4000) {
166 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
167 ("Firmware is too big!\n"));
168 release_firmware(firmware);
169 return 1;
170 }
171 memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size);
172 rtlpriv->rtlhal.fwsize = firmware->size;
173 release_firmware(firmware);
174
86 return 0; 175 return 0;
87} 176}
88 177
@@ -103,17 +192,19 @@ static struct rtl_hal_ops rtl8192ce_hal_ops = {
103 .interrupt_recognized = rtl92ce_interrupt_recognized, 192 .interrupt_recognized = rtl92ce_interrupt_recognized,
104 .hw_init = rtl92ce_hw_init, 193 .hw_init = rtl92ce_hw_init,
105 .hw_disable = rtl92ce_card_disable, 194 .hw_disable = rtl92ce_card_disable,
195 .hw_suspend = rtl92ce_suspend,
196 .hw_resume = rtl92ce_resume,
106 .enable_interrupt = rtl92ce_enable_interrupt, 197 .enable_interrupt = rtl92ce_enable_interrupt,
107 .disable_interrupt = rtl92ce_disable_interrupt, 198 .disable_interrupt = rtl92ce_disable_interrupt,
108 .set_network_type = rtl92ce_set_network_type, 199 .set_network_type = rtl92ce_set_network_type,
200 .set_chk_bssid = rtl92ce_set_check_bssid,
109 .set_qos = rtl92ce_set_qos, 201 .set_qos = rtl92ce_set_qos,
110 .set_bcn_reg = rtl92ce_set_beacon_related_registers, 202 .set_bcn_reg = rtl92ce_set_beacon_related_registers,
111 .set_bcn_intv = rtl92ce_set_beacon_interval, 203 .set_bcn_intv = rtl92ce_set_beacon_interval,
112 .update_interrupt_mask = rtl92ce_update_interrupt_mask, 204 .update_interrupt_mask = rtl92ce_update_interrupt_mask,
113 .get_hw_reg = rtl92ce_get_hw_reg, 205 .get_hw_reg = rtl92ce_get_hw_reg,
114 .set_hw_reg = rtl92ce_set_hw_reg, 206 .set_hw_reg = rtl92ce_set_hw_reg,
115 .update_rate_table = rtl92ce_update_hal_rate_table, 207 .update_rate_tbl = rtl92ce_update_hal_rate_tbl,
116 .update_rate_mask = rtl92ce_update_hal_rate_mask,
117 .fill_tx_desc = rtl92ce_tx_fill_desc, 208 .fill_tx_desc = rtl92ce_tx_fill_desc,
118 .fill_tx_cmddesc = rtl92ce_tx_fill_cmddesc, 209 .fill_tx_cmddesc = rtl92ce_tx_fill_cmddesc,
119 .query_rx_desc = rtl92ce_rx_query_desc, 210 .query_rx_desc = rtl92ce_rx_query_desc,
@@ -123,7 +214,7 @@ static struct rtl_hal_ops rtl8192ce_hal_ops = {
123 .switch_channel = rtl92c_phy_sw_chnl, 214 .switch_channel = rtl92c_phy_sw_chnl,
124 .dm_watchdog = rtl92c_dm_watchdog, 215 .dm_watchdog = rtl92c_dm_watchdog,
125 .scan_operation_backup = rtl92c_phy_scan_operation_backup, 216 .scan_operation_backup = rtl92c_phy_scan_operation_backup,
126 .set_rf_power_state = rtl92ce_phy_set_rf_power_state, 217 .set_rf_power_state = rtl92c_phy_set_rf_power_state,
127 .led_control = rtl92ce_led_control, 218 .led_control = rtl92ce_led_control,
128 .set_desc = rtl92ce_set_desc, 219 .set_desc = rtl92ce_set_desc,
129 .get_desc = rtl92ce_get_desc, 220 .get_desc = rtl92ce_get_desc,
@@ -133,24 +224,27 @@ static struct rtl_hal_ops rtl8192ce_hal_ops = {
133 .init_sw_leds = rtl92ce_init_sw_leds, 224 .init_sw_leds = rtl92ce_init_sw_leds,
134 .get_bbreg = rtl92c_phy_query_bb_reg, 225 .get_bbreg = rtl92c_phy_query_bb_reg,
135 .set_bbreg = rtl92c_phy_set_bb_reg, 226 .set_bbreg = rtl92c_phy_set_bb_reg,
136 .get_rfreg = rtl92ce_phy_query_rf_reg,
137 .set_rfreg = rtl92ce_phy_set_rf_reg, 227 .set_rfreg = rtl92ce_phy_set_rf_reg,
138 .cmd_send_packet = _rtl92c_cmd_send_packet, 228 .get_rfreg = rtl92c_phy_query_rf_reg,
139 .phy_rf6052_config = rtl92ce_phy_rf6052_config, 229 .phy_rf6052_config = rtl92ce_phy_rf6052_config,
140 .phy_rf6052_set_cck_txpower = rtl92ce_phy_rf6052_set_cck_txpower, 230 .phy_rf6052_set_cck_txpower = rtl92ce_phy_rf6052_set_cck_txpower,
141 .phy_rf6052_set_ofdm_txpower = rtl92ce_phy_rf6052_set_ofdm_txpower, 231 .phy_rf6052_set_ofdm_txpower = rtl92ce_phy_rf6052_set_ofdm_txpower,
142 .config_bb_with_headerfile = _rtl92ce_phy_config_bb_with_headerfile, 232 .config_bb_with_headerfile = _rtl92ce_phy_config_bb_with_headerfile,
143 .config_bb_with_pgheaderfile = _rtl92ce_phy_config_bb_with_pgheaderfile, 233 .config_bb_with_pgheaderfile = _rtl92ce_phy_config_bb_with_pgheaderfile,
144 .phy_lc_calibrate = _rtl92ce_phy_lc_calibrate, 234 .phy_lc_calibrate = _rtl92ce_phy_lc_calibrate,
145 .phy_set_bw_mode_callback = rtl92ce_phy_set_bw_mode_callback,
146 .dm_dynamic_txpower = rtl92ce_dm_dynamic_txpower, 235 .dm_dynamic_txpower = rtl92ce_dm_dynamic_txpower,
147}; 236};
148 237
149static struct rtl_mod_params rtl92ce_mod_params = { 238static struct rtl_mod_params rtl92ce_mod_params = {
150 .sw_crypto = 0, 239 .sw_crypto = false,
240 .inactiveps = true,
241 .swctrl_lps = false,
242 .fwctrl_lps = true,
151}; 243};
152 244
153static struct rtl_hal_cfg rtl92ce_hal_cfg = { 245static struct rtl_hal_cfg rtl92ce_hal_cfg = {
246 .bar_id = 2,
247 .write_readback = true,
154 .name = "rtl92c_pci", 248 .name = "rtl92c_pci",
155 .fw_name = "rtlwifi/rtl8192cfw.bin", 249 .fw_name = "rtlwifi/rtl8192cfw.bin",
156 .ops = &rtl8192ce_hal_ops, 250 .ops = &rtl8192ce_hal_ops,
@@ -174,6 +268,8 @@ static struct rtl_hal_cfg rtl92ce_hal_cfg = {
174 .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN, 268 .maps[EFUSE_LOADER_CLK_EN] = LOADER_CLK_EN,
175 .maps[EFUSE_ANA8M] = EFUSE_ANA8M, 269 .maps[EFUSE_ANA8M] = EFUSE_ANA8M,
176 .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE, 270 .maps[EFUSE_HWSET_MAX_SIZE] = HWSET_MAX_SIZE,
271 .maps[EFUSE_MAX_SECTION_MAP] = EFUSE_MAX_SECTION,
272 .maps[EFUSE_REAL_CONTENT_SIZE] = EFUSE_REAL_CONTENT_LEN,
177 273
178 .maps[RWCAM] = REG_CAMCMD, 274 .maps[RWCAM] = REG_CAMCMD,
179 .maps[WCAMI] = REG_CAMWRITE, 275 .maps[WCAMI] = REG_CAMWRITE,
@@ -238,7 +334,7 @@ static struct rtl_hal_cfg rtl92ce_hal_cfg = {
238 .maps[RTL_RC_HT_RATEMCS15] = DESC92C_RATEMCS15, 334 .maps[RTL_RC_HT_RATEMCS15] = DESC92C_RATEMCS15,
239}; 335};
240 336
241static struct pci_device_id rtl92ce_pci_ids[] __devinitdata = { 337DEFINE_PCI_DEVICE_TABLE(rtl92ce_pci_ids) = {
242 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8191, rtl92ce_hal_cfg)}, 338 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8191, rtl92ce_hal_cfg)},
243 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8178, rtl92ce_hal_cfg)}, 339 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8178, rtl92ce_hal_cfg)},
244 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8177, rtl92ce_hal_cfg)}, 340 {RTL_PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8177, rtl92ce_hal_cfg)},
@@ -256,7 +352,13 @@ MODULE_DESCRIPTION("Realtek 8192C/8188C 802.11n PCI wireless");
256MODULE_FIRMWARE("rtlwifi/rtl8192cfw.bin"); 352MODULE_FIRMWARE("rtlwifi/rtl8192cfw.bin");
257 353
258module_param_named(swenc, rtl92ce_mod_params.sw_crypto, bool, 0444); 354module_param_named(swenc, rtl92ce_mod_params.sw_crypto, bool, 0444);
355module_param_named(ips, rtl92ce_mod_params.inactiveps, bool, 0444);
356module_param_named(swlps, rtl92ce_mod_params.swctrl_lps, bool, 0444);
357module_param_named(fwlps, rtl92ce_mod_params.fwctrl_lps, bool, 0444);
259MODULE_PARM_DESC(swenc, "using hardware crypto (default 0 [hardware])\n"); 358MODULE_PARM_DESC(swenc, "using hardware crypto (default 0 [hardware])\n");
359MODULE_PARM_DESC(ips, "using no link power save (default 1 is open)\n");
360MODULE_PARM_DESC(fwlps, "using linked fw control power save "
361 "(default 1 is open)\n");
260 362
261static struct pci_driver rtl92ce_driver = { 363static struct pci_driver rtl92ce_driver = {
262 .name = KBUILD_MODNAME, 364 .name = KBUILD_MODNAME,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.h b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.h
index 36e657668c1e..b7dc3263e433 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.h
@@ -33,19 +33,9 @@
33int rtl92c_init_sw_vars(struct ieee80211_hw *hw); 33int rtl92c_init_sw_vars(struct ieee80211_hw *hw);
34void rtl92c_deinit_sw_vars(struct ieee80211_hw *hw); 34void rtl92c_deinit_sw_vars(struct ieee80211_hw *hw);
35void rtl92c_init_var_map(struct ieee80211_hw *hw); 35void rtl92c_init_var_map(struct ieee80211_hw *hw);
36bool _rtl92c_cmd_send_packet(struct ieee80211_hw *hw,
37 struct sk_buff *skb);
38void rtl92ce_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
39 u8 *ppowerlevel);
40void rtl92ce_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
41 u8 *ppowerlevel, u8 channel);
42bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 36bool _rtl92ce_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
43 u8 configtype); 37 u8 configtype);
44bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw, 38bool _rtl92ce_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
45 u8 configtype); 39 u8 configtype);
46void _rtl92ce_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t);
47u32 rtl92ce_phy_query_rf_reg(struct ieee80211_hw *hw,
48 enum radio_path rfpath, u32 regaddr, u32 bitmask);
49void rtl92ce_phy_set_bw_mode_callback(struct ieee80211_hw *hw);
50 40
51#endif 41#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
index aa2b5815600f..54b2bd53d36a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.c
@@ -36,42 +36,16 @@
36#include "trx.h" 36#include "trx.h"
37#include "led.h" 37#include "led.h"
38 38
39static enum rtl_desc_qsel _rtl92ce_map_hwqueue_to_fwqueue(__le16 fc, 39static u8 _rtl92ce_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
40 unsigned int
41 skb_queue)
42{ 40{
43 enum rtl_desc_qsel qsel; 41 __le16 fc = rtl_get_fc(skb);
44 42
45 if (unlikely(ieee80211_is_beacon(fc))) { 43 if (unlikely(ieee80211_is_beacon(fc)))
46 qsel = QSLT_BEACON; 44 return QSLT_BEACON;
47 return qsel; 45 if (ieee80211_is_mgmt(fc))
48 } 46 return QSLT_MGNT;
49
50 if (ieee80211_is_mgmt(fc)) {
51 qsel = QSLT_MGNT;
52 return qsel;
53 }
54 47
55 switch (skb_queue) { 48 return skb->priority;
56 case VO_QUEUE:
57 qsel = QSLT_VO;
58 break;
59 case VI_QUEUE:
60 qsel = QSLT_VI;
61 break;
62 case BE_QUEUE:
63 qsel = QSLT_BE;
64 break;
65 case BK_QUEUE:
66 qsel = QSLT_BK;
67 break;
68 default:
69 qsel = QSLT_BE;
70 RT_ASSERT(false, ("BE queue, skb_queue:%d,"
71 " set qsel = 0x%X\n", skb_queue, QSLT_BE));
72 break;
73 }
74 return qsel;
75} 49}
76 50
77static int _rtl92ce_rate_mapping(bool isht, u8 desc_rate, bool first_ampdu) 51static int _rtl92ce_rate_mapping(bool isht, u8 desc_rate, bool first_ampdu)
@@ -255,6 +229,7 @@ static void _rtl92ce_query_rxphystatus(struct ieee80211_hw *hw,
255 u8 evm, pwdb_all, rf_rx_num = 0; 229 u8 evm, pwdb_all, rf_rx_num = 0;
256 u8 i, max_spatial_stream; 230 u8 i, max_spatial_stream;
257 u32 rssi, total_rssi = 0; 231 u32 rssi, total_rssi = 0;
232 bool in_powersavemode = false;
258 bool is_cck_rate; 233 bool is_cck_rate;
259 234
260 is_cck_rate = RX_HAL_IS_CCK_RATE(pdesc); 235 is_cck_rate = RX_HAL_IS_CCK_RATE(pdesc);
@@ -270,9 +245,13 @@ static void _rtl92ce_query_rxphystatus(struct ieee80211_hw *hw,
270 u8 report, cck_highpwr; 245 u8 report, cck_highpwr;
271 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo; 246 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
272 247
273 cck_highpwr = (u8) rtl_get_bbreg(hw, 248 if (!in_powersavemode)
274 RFPGA0_XA_HSSIPARAMETER2, 249 cck_highpwr = (u8) rtl_get_bbreg(hw,
275 BIT(9)); 250 RFPGA0_XA_HSSIPARAMETER2,
251 BIT(9));
252 else
253 cck_highpwr = false;
254
276 if (!cck_highpwr) { 255 if (!cck_highpwr) {
277 u8 cck_agc_rpt = cck_buf->cck_agc_rpt; 256 u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
278 report = cck_buf->cck_agc_rpt & 0xc0; 257 report = cck_buf->cck_agc_rpt & 0xc0;
@@ -398,6 +377,7 @@ static void _rtl92ce_process_ui_rssi(struct ieee80211_hw *hw,
398 377
399 if (rtlpriv->stats.ui_rssi.total_num++ >= 378 if (rtlpriv->stats.ui_rssi.total_num++ >=
400 PHY_RSSI_SLID_WIN_MAX) { 379 PHY_RSSI_SLID_WIN_MAX) {
380
401 rtlpriv->stats.ui_rssi.total_num = 381 rtlpriv->stats.ui_rssi.total_num =
402 PHY_RSSI_SLID_WIN_MAX; 382 PHY_RSSI_SLID_WIN_MAX;
403 last_rssi = 383 last_rssi =
@@ -424,10 +404,6 @@ static void _rtl92ce_process_ui_rssi(struct ieee80211_hw *hw,
424 if (!pstats->is_cck && pstats->packet_toself) { 404 if (!pstats->is_cck && pstats->packet_toself) {
425 for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath; 405 for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
426 rfpath++) { 406 rfpath++) {
427
428 if (!rtl8192_phy_check_is_legal_rfpath(hw, rfpath))
429 continue;
430
431 if (rtlpriv->stats.rx_rssi_percentage[rfpath] == 0) { 407 if (rtlpriv->stats.rx_rssi_percentage[rfpath] == 0) {
432 rtlpriv->stats.rx_rssi_percentage[rfpath] = 408 rtlpriv->stats.rx_rssi_percentage[rfpath] =
433 pstats->rx_mimo_signalstrength[rfpath]; 409 pstats->rx_mimo_signalstrength[rfpath];
@@ -723,7 +699,7 @@ bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw,
723void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw, 699void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
724 struct ieee80211_hdr *hdr, u8 *pdesc_tx, 700 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
725 struct ieee80211_tx_info *info, struct sk_buff *skb, 701 struct ieee80211_tx_info *info, struct sk_buff *skb,
726 unsigned int queue_index) 702 u8 hw_queue, struct rtl_tcb_desc *tcb_desc)
727{ 703{
728 struct rtl_priv *rtlpriv = rtl_priv(hw); 704 struct rtl_priv *rtlpriv = rtl_priv(hw);
729 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 705 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
@@ -732,16 +708,9 @@ void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
732 bool defaultadapter = true; 708 bool defaultadapter = true;
733 struct ieee80211_sta *sta; 709 struct ieee80211_sta *sta;
734 u8 *pdesc = (u8 *) pdesc_tx; 710 u8 *pdesc = (u8 *) pdesc_tx;
735 struct rtl_tcb_desc tcb_desc;
736 u8 *qc = ieee80211_get_qos_ctl(hdr);
737 u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
738 u16 seq_number; 711 u16 seq_number;
739 __le16 fc = hdr->frame_control; 712 __le16 fc = hdr->frame_control;
740 u8 rate_flag = info->control.rates[0].flags; 713 u8 fw_qsel = _rtl92ce_map_hwqueue_to_fwqueue(skb, hw_queue);
741
742 enum rtl_desc_qsel fw_qsel =
743 _rtl92ce_map_hwqueue_to_fwqueue(fc, queue_index);
744
745 bool firstseg = ((hdr->seq_ctrl & 714 bool firstseg = ((hdr->seq_ctrl &
746 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0); 715 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
747 716
@@ -751,56 +720,68 @@ void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
751 dma_addr_t mapping = pci_map_single(rtlpci->pdev, 720 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
752 skb->data, skb->len, 721 skb->data, skb->len,
753 PCI_DMA_TODEVICE); 722 PCI_DMA_TODEVICE);
723 u8 bw_40 = 0;
724
725 rcu_read_lock();
726 sta = get_sta(hw, mac->vif, mac->bssid);
727 if (mac->opmode == NL80211_IFTYPE_STATION) {
728 bw_40 = mac->bw_40;
729 } else if (mac->opmode == NL80211_IFTYPE_AP ||
730 mac->opmode == NL80211_IFTYPE_ADHOC) {
731 if (sta)
732 bw_40 = sta->ht_cap.cap &
733 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
734 }
754 735
755 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; 736 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
756 737
757 rtl_get_tcb_desc(hw, info, skb, &tcb_desc); 738 rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc);
758 739
759 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_92c)); 740 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_92c));
760 741
742 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
743 firstseg = true;
744 lastseg = true;
745 }
761 if (firstseg) { 746 if (firstseg) {
762 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); 747 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
763 748
764 SET_TX_DESC_TX_RATE(pdesc, tcb_desc.hw_rate); 749 SET_TX_DESC_TX_RATE(pdesc, tcb_desc->hw_rate);
765 750
766 if (tcb_desc.use_shortgi || tcb_desc.use_shortpreamble) 751 if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble)
767 SET_TX_DESC_DATA_SHORTGI(pdesc, 1); 752 SET_TX_DESC_DATA_SHORTGI(pdesc, 1);
768 753
769 if (mac->tids[tid].agg.agg_state == RTL_AGG_ON && 754 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
770 info->flags & IEEE80211_TX_CTL_AMPDU) {
771 SET_TX_DESC_AGG_BREAK(pdesc, 1); 755 SET_TX_DESC_AGG_BREAK(pdesc, 1);
772 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14); 756 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
773 } 757 }
774 SET_TX_DESC_SEQ(pdesc, seq_number); 758 SET_TX_DESC_SEQ(pdesc, seq_number);
775 759
776 SET_TX_DESC_RTS_ENABLE(pdesc, ((tcb_desc.rts_enable && 760 SET_TX_DESC_RTS_ENABLE(pdesc, ((tcb_desc->rts_enable &&
777 !tcb_desc. 761 !tcb_desc->
778 cts_enable) ? 1 : 0)); 762 cts_enable) ? 1 : 0));
779 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 763 SET_TX_DESC_HW_RTS_ENABLE(pdesc,
780 ((tcb_desc.rts_enable 764 ((tcb_desc->rts_enable
781 || tcb_desc.cts_enable) ? 1 : 0)); 765 || tcb_desc->cts_enable) ? 1 : 0));
782 SET_TX_DESC_CTS2SELF(pdesc, ((tcb_desc.cts_enable) ? 1 : 0)); 766 SET_TX_DESC_CTS2SELF(pdesc, ((tcb_desc->cts_enable) ? 1 : 0));
783 SET_TX_DESC_RTS_STBC(pdesc, ((tcb_desc.rts_stbc) ? 1 : 0)); 767 SET_TX_DESC_RTS_STBC(pdesc, ((tcb_desc->rts_stbc) ? 1 : 0));
784 768
785 SET_TX_DESC_RTS_RATE(pdesc, tcb_desc.rts_rate); 769 SET_TX_DESC_RTS_RATE(pdesc, tcb_desc->rts_rate);
786 SET_TX_DESC_RTS_BW(pdesc, 0); 770 SET_TX_DESC_RTS_BW(pdesc, 0);
787 SET_TX_DESC_RTS_SC(pdesc, tcb_desc.rts_sc); 771 SET_TX_DESC_RTS_SC(pdesc, tcb_desc->rts_sc);
788 SET_TX_DESC_RTS_SHORT(pdesc, 772 SET_TX_DESC_RTS_SHORT(pdesc,
789 ((tcb_desc.rts_rate <= DESC92C_RATE54M) ? 773 ((tcb_desc->rts_rate <= DESC92C_RATE54M) ?
790 (tcb_desc.rts_use_shortpreamble ? 1 : 0) 774 (tcb_desc->rts_use_shortpreamble ? 1 : 0)
791 : (tcb_desc.rts_use_shortgi ? 1 : 0))); 775 : (tcb_desc->rts_use_shortgi ? 1 : 0)));
792 776
793 if (mac->bw_40) { 777 if (bw_40) {
794 if (tcb_desc.packet_bw) { 778 if (tcb_desc->packet_bw) {
795 SET_TX_DESC_DATA_BW(pdesc, 1); 779 SET_TX_DESC_DATA_BW(pdesc, 1);
796 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3); 780 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
797 } else { 781 } else {
798 SET_TX_DESC_DATA_BW(pdesc, 0); 782 SET_TX_DESC_DATA_BW(pdesc, 0);
799 783 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
800 if (rate_flag & IEEE80211_TX_RC_DUP_DATA) { 784 mac->cur_40_prime_sc);
801 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
802 mac->cur_40_prime_sc);
803 }
804 } 785 }
805 } else { 786 } else {
806 SET_TX_DESC_DATA_BW(pdesc, 0); 787 SET_TX_DESC_DATA_BW(pdesc, 0);
@@ -810,13 +791,10 @@ void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
810 SET_TX_DESC_LINIP(pdesc, 0); 791 SET_TX_DESC_LINIP(pdesc, 0);
811 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len); 792 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
812 793
813 rcu_read_lock();
814 sta = ieee80211_find_sta(mac->vif, mac->bssid);
815 if (sta) { 794 if (sta) {
816 u8 ampdu_density = sta->ht_cap.ampdu_density; 795 u8 ampdu_density = sta->ht_cap.ampdu_density;
817 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density); 796 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
818 } 797 }
819 rcu_read_unlock();
820 798
821 if (info->control.hw_key) { 799 if (info->control.hw_key) {
822 struct ieee80211_key_conf *keyconf = 800 struct ieee80211_key_conf *keyconf =
@@ -844,7 +822,7 @@ void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
844 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); 822 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
845 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF); 823 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
846 SET_TX_DESC_DISABLE_FB(pdesc, 0); 824 SET_TX_DESC_DISABLE_FB(pdesc, 0);
847 SET_TX_DESC_USE_RATE(pdesc, tcb_desc.use_driver_rate ? 1 : 0); 825 SET_TX_DESC_USE_RATE(pdesc, tcb_desc->use_driver_rate ? 1 : 0);
848 826
849 if (ieee80211_is_data_qos(fc)) { 827 if (ieee80211_is_data_qos(fc)) {
850 if (mac->rdg_en) { 828 if (mac->rdg_en) {
@@ -855,24 +833,24 @@ void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
855 } 833 }
856 } 834 }
857 } 835 }
836 rcu_read_unlock();
858 837
859 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); 838 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
860 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); 839 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
861 840
862 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len); 841 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
863 842
864 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping)); 843 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
865 844
866 if (rtlpriv->dm.useramask) { 845 if (rtlpriv->dm.useramask) {
867 SET_TX_DESC_RATE_ID(pdesc, tcb_desc.ratr_index); 846 SET_TX_DESC_RATE_ID(pdesc, tcb_desc->ratr_index);
868 SET_TX_DESC_MACID(pdesc, tcb_desc.mac_id); 847 SET_TX_DESC_MACID(pdesc, tcb_desc->mac_id);
869 } else { 848 } else {
870 SET_TX_DESC_RATE_ID(pdesc, 0xC + tcb_desc.ratr_index); 849 SET_TX_DESC_RATE_ID(pdesc, 0xC + tcb_desc->ratr_index);
871 SET_TX_DESC_MACID(pdesc, tcb_desc.ratr_index); 850 SET_TX_DESC_MACID(pdesc, tcb_desc->ratr_index);
872 } 851 }
873 852
874 if ((!ieee80211_is_data_qos(fc)) && ppsc->leisure_ps && 853 if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) {
875 ppsc->fwctrl_lps) {
876 SET_TX_DESC_HWSEQ_EN(pdesc, 1); 854 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
877 SET_TX_DESC_PKT_ID(pdesc, 8); 855 SET_TX_DESC_PKT_ID(pdesc, 8);
878 856
@@ -923,7 +901,7 @@ void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw *hw,
923 901
924 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len)); 902 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
925 903
926 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping)); 904 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
927 905
928 SET_TX_DESC_RATE_ID(pdesc, 7); 906 SET_TX_DESC_RATE_ID(pdesc, 7);
929 SET_TX_DESC_MACID(pdesc, 0); 907 SET_TX_DESC_MACID(pdesc, 0);
@@ -1021,7 +999,7 @@ u32 rtl92ce_get_desc(u8 *p_desc, bool istx, u8 desc_name)
1021 return ret; 999 return ret;
1022} 1000}
1023 1001
1024void rtl92ce_tx_polling(struct ieee80211_hw *hw, unsigned int hw_queue) 1002void rtl92ce_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
1025{ 1003{
1026 struct rtl_priv *rtlpriv = rtl_priv(hw); 1004 struct rtl_priv *rtlpriv = rtl_priv(hw);
1027 if (hw_queue == BEACON_QUEUE) { 1005 if (hw_queue == BEACON_QUEUE) {
@@ -1032,35 +1010,3 @@ void rtl92ce_tx_polling(struct ieee80211_hw *hw, unsigned int hw_queue)
1032 } 1010 }
1033} 1011}
1034 1012
1035bool _rtl92c_cmd_send_packet(struct ieee80211_hw *hw,
1036 struct sk_buff *skb)
1037{
1038 struct rtl_priv *rtlpriv = rtl_priv(hw);
1039 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1040 struct rtl8192_tx_ring *ring;
1041 struct rtl_tx_desc *pdesc;
1042 u8 own;
1043 unsigned long flags;
1044 struct sk_buff *pskb = NULL;
1045
1046 ring = &rtlpci->tx_ring[BEACON_QUEUE];
1047
1048 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
1049
1050 pskb = __skb_dequeue(&ring->queue);
1051 if (pskb)
1052 kfree_skb(pskb);
1053
1054 pdesc = &ring->desc[0];
1055 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc, true, HW_DESC_OWN);
1056
1057 rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *) pdesc, 1, 1, skb);
1058
1059 __skb_queue_tail(&ring->queue, skb);
1060
1061 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
1062
1063 rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE);
1064
1065 return true;
1066}
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.h b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.h
index b0b0b13dd0ae..0f1177137501 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/trx.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/trx.h
@@ -724,17 +724,16 @@ struct rx_desc_92c {
724void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw, 724void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
725 struct ieee80211_hdr *hdr, 725 struct ieee80211_hdr *hdr,
726 u8 *pdesc, struct ieee80211_tx_info *info, 726 u8 *pdesc, struct ieee80211_tx_info *info,
727 struct sk_buff *skb, unsigned int qsel); 727 struct sk_buff *skb, u8 hw_queue,
728 struct rtl_tcb_desc *ptcb_desc);
728bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw, 729bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw,
729 struct rtl_stats *stats, 730 struct rtl_stats *stats,
730 struct ieee80211_rx_status *rx_status, 731 struct ieee80211_rx_status *rx_status,
731 u8 *pdesc, struct sk_buff *skb); 732 u8 *pdesc, struct sk_buff *skb);
732void rtl92ce_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val); 733void rtl92ce_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val);
733u32 rtl92ce_get_desc(u8 *pdesc, bool istx, u8 desc_name); 734u32 rtl92ce_get_desc(u8 *pdesc, bool istx, u8 desc_name);
734void rtl92ce_tx_polling(struct ieee80211_hw *hw, unsigned int hw_queue); 735void rtl92ce_tx_polling(struct ieee80211_hw *hw, u8 hw_queue);
735void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc, 736void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
736 bool b_firstseg, bool b_lastseg, 737 bool b_firstseg, bool b_lastseg,
737 struct sk_buff *skb); 738 struct sk_buff *skb);
738bool _rtl92c_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb);
739
740#endif 739#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
index e43be2547827..52e2af58c1ed 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.c
@@ -39,6 +39,7 @@
39#include "mac.h" 39#include "mac.h"
40#include "dm.h" 40#include "dm.h"
41#include "hw.h" 41#include "hw.h"
42#include "../rtl8192ce/hw.h"
42#include "trx.h" 43#include "trx.h"
43#include "led.h" 44#include "led.h"
44#include "table.h" 45#include "table.h"
@@ -605,10 +606,10 @@ void rtl92cu_read_eeprom_info(struct ieee80211_hw *hw)
605 if (!IS_NORMAL_CHIP(rtlhal->version)) 606 if (!IS_NORMAL_CHIP(rtlhal->version))
606 return; 607 return;
607 tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR); 608 tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
608 rtlefuse->epromtype = (tmp_u1b & EEPROMSEL) ? 609 rtlefuse->epromtype = (tmp_u1b & BOOT_FROM_EEPROM) ?
609 EEPROM_93C46 : EEPROM_BOOT_EFUSE; 610 EEPROM_93C46 : EEPROM_BOOT_EFUSE;
610 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("Boot from %s\n", 611 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("Boot from %s\n",
611 (tmp_u1b & EEPROMSEL) ? "EERROM" : "EFUSE")); 612 (tmp_u1b & BOOT_FROM_EEPROM) ? "EERROM" : "EFUSE"));
612 rtlefuse->autoload_failflag = (tmp_u1b & EEPROM_EN) ? false : true; 613 rtlefuse->autoload_failflag = (tmp_u1b & EEPROM_EN) ? false : true;
613 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("Autoload %s\n", 614 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("Autoload %s\n",
614 (tmp_u1b & EEPROM_EN) ? "OK!!" : "ERR!!")); 615 (tmp_u1b & EEPROM_EN) ? "OK!!" : "ERR!!"));
@@ -977,7 +978,7 @@ static void _rtl92cu_init_wmac_setting(struct ieee80211_hw *hw)
977 struct rtl_priv *rtlpriv = rtl_priv(hw); 978 struct rtl_priv *rtlpriv = rtl_priv(hw);
978 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 979 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
979 980
980 mac->rx_conf = (RCR_APM | RCR_AM | RCR_ADF | RCR_AB | RCR_APP_FCS | 981 mac->rx_conf = (RCR_APM | RCR_AM | RCR_ADF | RCR_AB | RCR_APPFCS |
981 RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL | 982 RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL |
982 RCR_APP_MIC | RCR_APP_PHYSTS | RCR_ACRC32); 983 RCR_APP_MIC | RCR_APP_PHYSTS | RCR_ACRC32);
983 rtl_write_dword(rtlpriv, REG_RCR, mac->rx_conf); 984 rtl_write_dword(rtlpriv, REG_RCR, mac->rx_conf);
@@ -2182,7 +2183,9 @@ void rtl92cu_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
2182 } 2183 }
2183} 2184}
2184 2185
2185void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw) 2186void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw,
2187 struct ieee80211_sta *sta,
2188 u8 rssi_level)
2186{ 2189{
2187 struct rtl_priv *rtlpriv = rtl_priv(hw); 2190 struct rtl_priv *rtlpriv = rtl_priv(hw);
2188 struct rtl_phy *rtlphy = &(rtlpriv->phy); 2191 struct rtl_phy *rtlphy = &(rtlpriv->phy);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.h b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.h
index 62af555bb61c..32f85cba106a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/hw.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/hw.h
@@ -98,13 +98,14 @@ void rtl92cu_update_interrupt_mask(struct ieee80211_hw *hw,
98 u32 add_msr, u32 rm_msr); 98 u32 add_msr, u32 rm_msr);
99void rtl92cu_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); 99void rtl92cu_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val);
100void rtl92cu_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); 100void rtl92cu_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val);
101void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw); 101void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw,
102 struct ieee80211_sta *sta,
103 u8 rssi_level);
102void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level); 104void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, u8 rssi_level);
103 105
104void rtl92cu_update_channel_access_setting(struct ieee80211_hw *hw); 106void rtl92cu_update_channel_access_setting(struct ieee80211_hw *hw);
105bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid); 107bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid);
106void rtl92cu_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid); 108void rtl92cu_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid);
107u8 _rtl92c_get_chnl_group(u8 chnl);
108int rtl92c_download_fw(struct ieee80211_hw *hw); 109int rtl92c_download_fw(struct ieee80211_hw *hw);
109void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode); 110void rtl92c_set_fw_pwrmode_cmd(struct ieee80211_hw *hw, u8 mode);
110void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished); 111void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/phy.c b/drivers/net/wireless/rtlwifi/rtl8192cu/phy.c
index 4e020e654e6b..9a3d0239e27e 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/phy.c
@@ -38,7 +38,7 @@
38#include "table.h" 38#include "table.h"
39 39
40u32 rtl92cu_phy_query_rf_reg(struct ieee80211_hw *hw, 40u32 rtl92cu_phy_query_rf_reg(struct ieee80211_hw *hw,
41 enum radio_path rfpath, u32 regaddr, u32 bitmask) 41 enum radio_path rfpath, u32 regaddr, u32 bitmask)
42{ 42{
43 struct rtl_priv *rtlpriv = rtl_priv(hw); 43 struct rtl_priv *rtlpriv = rtl_priv(hw);
44 u32 original_value, readback_value, bitshift; 44 u32 original_value, readback_value, bitshift;
@@ -64,8 +64,8 @@ u32 rtl92cu_phy_query_rf_reg(struct ieee80211_hw *hw,
64} 64}
65 65
66void rtl92cu_phy_set_rf_reg(struct ieee80211_hw *hw, 66void rtl92cu_phy_set_rf_reg(struct ieee80211_hw *hw,
67 enum radio_path rfpath, 67 enum radio_path rfpath,
68 u32 regaddr, u32 bitmask, u32 data) 68 u32 regaddr, u32 bitmask, u32 data)
69{ 69{
70 struct rtl_priv *rtlpriv = rtl_priv(hw); 70 struct rtl_priv *rtlpriv = rtl_priv(hw);
71 struct rtl_phy *rtlphy = &(rtlpriv->phy); 71 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -163,7 +163,7 @@ bool _rtl92cu_phy_config_mac_with_headerfile(struct ieee80211_hw *hw)
163} 163}
164 164
165bool _rtl92cu_phy_config_bb_with_headerfile(struct ieee80211_hw *hw, 165bool _rtl92cu_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
166 u8 configtype) 166 u8 configtype)
167{ 167{
168 int i; 168 int i;
169 u32 *phy_regarray_table; 169 u32 *phy_regarray_table;
@@ -223,7 +223,7 @@ bool _rtl92cu_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
223} 223}
224 224
225bool _rtl92cu_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw, 225bool _rtl92cu_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
226 u8 configtype) 226 u8 configtype)
227{ 227{
228 struct rtl_priv *rtlpriv = rtl_priv(hw); 228 struct rtl_priv *rtlpriv = rtl_priv(hw);
229 struct rtl_phy *rtlphy = &(rtlpriv->phy); 229 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -459,7 +459,7 @@ void _rtl92cu_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t)
459 } 459 }
460} 460}
461 461
462bool _rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw, 462static bool _rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw,
463 enum rf_pwrstate rfpwr_state) 463 enum rf_pwrstate rfpwr_state)
464{ 464{
465 struct rtl_priv *rtlpriv = rtl_priv(hw); 465 struct rtl_priv *rtlpriv = rtl_priv(hw);
@@ -595,7 +595,7 @@ bool _rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw,
595} 595}
596 596
597bool rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw, 597bool rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw,
598 enum rf_pwrstate rfpwr_state) 598 enum rf_pwrstate rfpwr_state)
599{ 599{
600 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 600 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
601 bool bresult = false; 601 bool bresult = false;
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/phy.h b/drivers/net/wireless/rtlwifi/rtl8192cu/phy.h
index 06299559ab68..ff81a61729d7 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/phy.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/phy.h
@@ -34,3 +34,17 @@ bool rtl8192_phy_check_is_legal_rfpath(struct ieee80211_hw *hw, u32 rfpath);
34void rtl92c_phy_set_io(struct ieee80211_hw *hw); 34void rtl92c_phy_set_io(struct ieee80211_hw *hw);
35bool _rtl92cu_phy_config_mac_with_headerfile(struct ieee80211_hw *hw); 35bool _rtl92cu_phy_config_mac_with_headerfile(struct ieee80211_hw *hw);
36bool rtl92cu_phy_bb_config(struct ieee80211_hw *hw); 36bool rtl92cu_phy_bb_config(struct ieee80211_hw *hw);
37u32 rtl92cu_phy_query_rf_reg(struct ieee80211_hw *hw,
38 enum radio_path rfpath, u32 regaddr, u32 bitmask);
39void rtl92cu_phy_set_rf_reg(struct ieee80211_hw *hw,
40 enum radio_path rfpath,
41 u32 regaddr, u32 bitmask, u32 data);
42bool rtl92cu_phy_mac_config(struct ieee80211_hw *hw);
43bool _rtl92cu_phy_config_bb_with_pgheaderfile(struct ieee80211_hw *hw,
44 u8 configtype);
45void _rtl92cu_phy_lc_calibrate(struct ieee80211_hw *hw, bool is2t);
46bool _rtl92cu_phy_config_bb_with_headerfile(struct ieee80211_hw *hw,
47 u8 configtype);
48void rtl92cu_phy_set_bw_mode_callback(struct ieee80211_hw *hw);
49bool rtl92cu_phy_set_rf_power_state(struct ieee80211_hw *hw,
50 enum rf_pwrstate rfpwr_state);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
index 1c79c226f145..c7576ec4744e 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.c
@@ -62,7 +62,7 @@ void rtl92cu_phy_rf6052_set_bandwidth(struct ieee80211_hw *hw, u8 bandwidth)
62} 62}
63 63
64void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw, 64void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
65 u8 *ppowerlevel) 65 u8 *ppowerlevel)
66{ 66{
67 struct rtl_priv *rtlpriv = rtl_priv(hw); 67 struct rtl_priv *rtlpriv = rtl_priv(hw);
68 struct rtl_phy *rtlphy = &(rtlpriv->phy); 68 struct rtl_phy *rtlphy = &(rtlpriv->phy);
@@ -389,7 +389,7 @@ static void _rtl92c_write_ofdm_power_reg(struct ieee80211_hw *hw,
389} 389}
390 390
391void rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw, 391void rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
392 u8 *ppowerlevel, u8 channel) 392 u8 *ppowerlevel, u8 channel)
393{ 393{
394 u32 writeVal[2], powerBase0[2], powerBase1[2]; 394 u32 writeVal[2], powerBase0[2], powerBase1[2];
395 u8 index = 0; 395 u8 index = 0;
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.h b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.h
index 86c2728cfa00..500a2094b6bb 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/rf.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/rf.h
@@ -43,5 +43,9 @@ extern void rtl92c_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
43bool rtl92cu_phy_rf6052_config(struct ieee80211_hw *hw); 43bool rtl92cu_phy_rf6052_config(struct ieee80211_hw *hw);
44bool rtl92cu_phy_config_rf_with_headerfile(struct ieee80211_hw *hw, 44bool rtl92cu_phy_config_rf_with_headerfile(struct ieee80211_hw *hw,
45 enum radio_path rfpath); 45 enum radio_path rfpath);
46void rtl92cu_phy_rf6052_set_cck_txpower(struct ieee80211_hw *hw,
47 u8 *ppowerlevel);
48void rtl92cu_phy_rf6052_set_ofdm_txpower(struct ieee80211_hw *hw,
49 u8 *ppowerlevel, u8 channel);
46 50
47#endif 51#endif
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index 71244a38d49e..bee7c1480f63 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -94,7 +94,7 @@ static struct rtl_hal_ops rtl8192cu_hal_ops = {
94 .update_interrupt_mask = rtl92cu_update_interrupt_mask, 94 .update_interrupt_mask = rtl92cu_update_interrupt_mask,
95 .get_hw_reg = rtl92cu_get_hw_reg, 95 .get_hw_reg = rtl92cu_get_hw_reg,
96 .set_hw_reg = rtl92cu_set_hw_reg, 96 .set_hw_reg = rtl92cu_set_hw_reg,
97 .update_rate_table = rtl92cu_update_hal_rate_table, 97 .update_rate_tbl = rtl92cu_update_hal_rate_table,
98 .update_rate_mask = rtl92cu_update_hal_rate_mask, 98 .update_rate_mask = rtl92cu_update_hal_rate_mask,
99 .fill_tx_desc = rtl92cu_tx_fill_desc, 99 .fill_tx_desc = rtl92cu_tx_fill_desc,
100 .fill_fake_txdesc = rtl92cu_fill_fake_txdesc, 100 .fill_fake_txdesc = rtl92cu_fill_fake_txdesc,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
index 3f0cb81c424f..79c98f62175f 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.c
@@ -498,14 +498,14 @@ static void _rtl_tx_desc_checksum(u8 *txdesc)
498void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw, 498void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
499 struct ieee80211_hdr *hdr, u8 *pdesc_tx, 499 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
500 struct ieee80211_tx_info *info, struct sk_buff *skb, 500 struct ieee80211_tx_info *info, struct sk_buff *skb,
501 unsigned int queue_index) 501 u8 queue_index,
502 struct rtl_tcb_desc *tcb_desc)
502{ 503{
503 struct rtl_priv *rtlpriv = rtl_priv(hw); 504 struct rtl_priv *rtlpriv = rtl_priv(hw);
504 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 505 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
505 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 506 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
506 bool defaultadapter = true; 507 bool defaultadapter = true;
507 struct ieee80211_sta *sta; 508 struct ieee80211_sta *sta = info->control.sta = info->control.sta;
508 struct rtl_tcb_desc tcb_desc;
509 u8 *qc = ieee80211_get_qos_ctl(hdr); 509 u8 *qc = ieee80211_get_qos_ctl(hdr);
510 u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 510 u8 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
511 u16 seq_number; 511 u16 seq_number;
@@ -517,15 +517,15 @@ void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
517 u8 *txdesc; 517 u8 *txdesc;
518 518
519 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; 519 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
520 rtl_get_tcb_desc(hw, info, skb, &tcb_desc); 520 rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc);
521 txdesc = (u8 *)skb_push(skb, RTL_TX_HEADER_SIZE); 521 txdesc = (u8 *)skb_push(skb, RTL_TX_HEADER_SIZE);
522 memset(txdesc, 0, RTL_TX_HEADER_SIZE); 522 memset(txdesc, 0, RTL_TX_HEADER_SIZE);
523 SET_TX_DESC_PKT_SIZE(txdesc, pktlen); 523 SET_TX_DESC_PKT_SIZE(txdesc, pktlen);
524 SET_TX_DESC_LINIP(txdesc, 0); 524 SET_TX_DESC_LINIP(txdesc, 0);
525 SET_TX_DESC_PKT_OFFSET(txdesc, RTL_DUMMY_OFFSET); 525 SET_TX_DESC_PKT_OFFSET(txdesc, RTL_DUMMY_OFFSET);
526 SET_TX_DESC_OFFSET(txdesc, RTL_TX_HEADER_SIZE); 526 SET_TX_DESC_OFFSET(txdesc, RTL_TX_HEADER_SIZE);
527 SET_TX_DESC_TX_RATE(txdesc, tcb_desc.hw_rate); 527 SET_TX_DESC_TX_RATE(txdesc, tcb_desc->hw_rate);
528 if (tcb_desc.use_shortgi || tcb_desc.use_shortpreamble) 528 if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble)
529 SET_TX_DESC_DATA_SHORTGI(txdesc, 1); 529 SET_TX_DESC_DATA_SHORTGI(txdesc, 1);
530 if (mac->tids[tid].agg.agg_state == RTL_AGG_ON && 530 if (mac->tids[tid].agg.agg_state == RTL_AGG_ON &&
531 info->flags & IEEE80211_TX_CTL_AMPDU) { 531 info->flags & IEEE80211_TX_CTL_AMPDU) {
@@ -535,21 +535,21 @@ void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
535 SET_TX_DESC_AGG_BREAK(txdesc, 1); 535 SET_TX_DESC_AGG_BREAK(txdesc, 1);
536 } 536 }
537 SET_TX_DESC_SEQ(txdesc, seq_number); 537 SET_TX_DESC_SEQ(txdesc, seq_number);
538 SET_TX_DESC_RTS_ENABLE(txdesc, ((tcb_desc.rts_enable && 538 SET_TX_DESC_RTS_ENABLE(txdesc, ((tcb_desc->rts_enable &&
539 !tcb_desc.cts_enable) ? 1 : 0)); 539 !tcb_desc->cts_enable) ? 1 : 0));
540 SET_TX_DESC_HW_RTS_ENABLE(txdesc, ((tcb_desc.rts_enable || 540 SET_TX_DESC_HW_RTS_ENABLE(txdesc, ((tcb_desc->rts_enable ||
541 tcb_desc.cts_enable) ? 1 : 0)); 541 tcb_desc->cts_enable) ? 1 : 0));
542 SET_TX_DESC_CTS2SELF(txdesc, ((tcb_desc.cts_enable) ? 1 : 0)); 542 SET_TX_DESC_CTS2SELF(txdesc, ((tcb_desc->cts_enable) ? 1 : 0));
543 SET_TX_DESC_RTS_STBC(txdesc, ((tcb_desc.rts_stbc) ? 1 : 0)); 543 SET_TX_DESC_RTS_STBC(txdesc, ((tcb_desc->rts_stbc) ? 1 : 0));
544 SET_TX_DESC_RTS_RATE(txdesc, tcb_desc.rts_rate); 544 SET_TX_DESC_RTS_RATE(txdesc, tcb_desc->rts_rate);
545 SET_TX_DESC_RTS_BW(txdesc, 0); 545 SET_TX_DESC_RTS_BW(txdesc, 0);
546 SET_TX_DESC_RTS_SC(txdesc, tcb_desc.rts_sc); 546 SET_TX_DESC_RTS_SC(txdesc, tcb_desc->rts_sc);
547 SET_TX_DESC_RTS_SHORT(txdesc, 547 SET_TX_DESC_RTS_SHORT(txdesc,
548 ((tcb_desc.rts_rate <= DESC92C_RATE54M) ? 548 ((tcb_desc->rts_rate <= DESC92C_RATE54M) ?
549 (tcb_desc.rts_use_shortpreamble ? 1 : 0) 549 (tcb_desc->rts_use_shortpreamble ? 1 : 0)
550 : (tcb_desc.rts_use_shortgi ? 1 : 0))); 550 : (tcb_desc->rts_use_shortgi ? 1 : 0)));
551 if (mac->bw_40) { 551 if (mac->bw_40) {
552 if (tcb_desc.packet_bw) { 552 if (tcb_desc->packet_bw) {
553 SET_TX_DESC_DATA_BW(txdesc, 1); 553 SET_TX_DESC_DATA_BW(txdesc, 1);
554 SET_TX_DESC_DATA_SC(txdesc, 3); 554 SET_TX_DESC_DATA_SC(txdesc, 3);
555 } else { 555 } else {
@@ -590,7 +590,7 @@ void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
590 SET_TX_DESC_DATA_RATE_FB_LIMIT(txdesc, 0x1F); 590 SET_TX_DESC_DATA_RATE_FB_LIMIT(txdesc, 0x1F);
591 SET_TX_DESC_RTS_RATE_FB_LIMIT(txdesc, 0xF); 591 SET_TX_DESC_RTS_RATE_FB_LIMIT(txdesc, 0xF);
592 SET_TX_DESC_DISABLE_FB(txdesc, 0); 592 SET_TX_DESC_DISABLE_FB(txdesc, 0);
593 SET_TX_DESC_USE_RATE(txdesc, tcb_desc.use_driver_rate ? 1 : 0); 593 SET_TX_DESC_USE_RATE(txdesc, tcb_desc->use_driver_rate ? 1 : 0);
594 if (ieee80211_is_data_qos(fc)) { 594 if (ieee80211_is_data_qos(fc)) {
595 if (mac->rdg_en) { 595 if (mac->rdg_en) {
596 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, 596 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
@@ -600,11 +600,11 @@ void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
600 } 600 }
601 } 601 }
602 if (rtlpriv->dm.useramask) { 602 if (rtlpriv->dm.useramask) {
603 SET_TX_DESC_RATE_ID(txdesc, tcb_desc.ratr_index); 603 SET_TX_DESC_RATE_ID(txdesc, tcb_desc->ratr_index);
604 SET_TX_DESC_MACID(txdesc, tcb_desc.mac_id); 604 SET_TX_DESC_MACID(txdesc, tcb_desc->mac_id);
605 } else { 605 } else {
606 SET_TX_DESC_RATE_ID(txdesc, 0xC + tcb_desc.ratr_index); 606 SET_TX_DESC_RATE_ID(txdesc, 0xC + tcb_desc->ratr_index);
607 SET_TX_DESC_MACID(txdesc, tcb_desc.ratr_index); 607 SET_TX_DESC_MACID(txdesc, tcb_desc->ratr_index);
608 } 608 }
609 if ((!ieee80211_is_data_qos(fc)) && ppsc->leisure_ps && 609 if ((!ieee80211_is_data_qos(fc)) && ppsc->leisure_ps &&
610 ppsc->fwctrl_lps) { 610 ppsc->fwctrl_lps) {
@@ -656,7 +656,7 @@ void rtl92cu_tx_fill_cmddesc(struct ieee80211_hw *hw,
656 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 656 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
657 __le16 fc = hdr->frame_control; 657 __le16 fc = hdr->frame_control;
658 658
659 memset(pdesc, 0, RTL_TX_HEADER_SIZE); 659 memset((void *)pdesc, 0, RTL_TX_HEADER_SIZE);
660 if (firstseg) 660 if (firstseg)
661 SET_TX_DESC_OFFSET(pdesc, RTL_TX_HEADER_SIZE); 661 SET_TX_DESC_OFFSET(pdesc, RTL_TX_HEADER_SIZE);
662 SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M); 662 SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.h b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.h
index b396d46edbb7..53de5f66e242 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/trx.h
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/trx.h
@@ -37,6 +37,8 @@
37#define RTL92C_SIZE_MAX_RX_BUFFER 15360 /* 8192 */ 37#define RTL92C_SIZE_MAX_RX_BUFFER 15360 /* 8192 */
38#define RX_DRV_INFO_SIZE_UNIT 8 38#define RX_DRV_INFO_SIZE_UNIT 8
39 39
40#define RTL_AGG_ON 1
41
40enum usb_rx_agg_mode { 42enum usb_rx_agg_mode {
41 USB_RX_AGG_DISABLE, 43 USB_RX_AGG_DISABLE,
42 USB_RX_AGG_DMA, 44 USB_RX_AGG_DMA,
@@ -419,7 +421,8 @@ struct sk_buff *rtl8192c_tx_aggregate_hdl(struct ieee80211_hw *,
419void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw, 421void rtl92cu_tx_fill_desc(struct ieee80211_hw *hw,
420 struct ieee80211_hdr *hdr, u8 *pdesc_tx, 422 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
421 struct ieee80211_tx_info *info, struct sk_buff *skb, 423 struct ieee80211_tx_info *info, struct sk_buff *skb,
422 unsigned int queue_index); 424 u8 queue_index,
425 struct rtl_tcb_desc *tcb_desc);
423void rtl92cu_fill_fake_txdesc(struct ieee80211_hw *hw, u8 * pDesc, 426void rtl92cu_fill_fake_txdesc(struct ieee80211_hw *hw, u8 * pDesc,
424 u32 buffer_len, bool bIsPsPoll); 427 u32 buffer_len, bool bIsPsPoll);
425void rtl92cu_tx_fill_cmddesc(struct ieee80211_hw *hw, 428void rtl92cu_tx_fill_cmddesc(struct ieee80211_hw *hw,
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index f5d85735d642..a9367eba1ea7 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -852,6 +852,7 @@ static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
852 struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 852 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
853 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 853 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
854 struct rtl_tx_desc *pdesc = NULL; 854 struct rtl_tx_desc *pdesc = NULL;
855 struct rtl_tcb_desc tcb_desc;
855 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); 856 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
856 __le16 fc = hdr->frame_control; 857 __le16 fc = hdr->frame_control;
857 u8 *pda_addr = hdr->addr1; 858 u8 *pda_addr = hdr->addr1;
@@ -860,8 +861,17 @@ static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
860 u8 tid = 0; 861 u8 tid = 0;
861 u16 seq_number = 0; 862 u16 seq_number = 0;
862 863
863 if (ieee80211_is_mgmt(fc)) 864 if (ieee80211_is_auth(fc)) {
864 rtl_tx_mgmt_proc(hw, skb); 865 RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n"));
866 rtl_ips_nic_on(hw);
867 }
868
869 if (rtlpriv->psc.sw_ps_enabled) {
870 if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
871 !ieee80211_has_pm(fc))
872 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
873 }
874
865 rtl_action_proc(hw, skb, true); 875 rtl_action_proc(hw, skb, true);
866 if (is_multicast_ether_addr(pda_addr)) 876 if (is_multicast_ether_addr(pda_addr))
867 rtlpriv->stats.txbytesmulticast += skb->len; 877 rtlpriv->stats.txbytesmulticast += skb->len;
@@ -878,7 +888,7 @@ static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
878 seq_number <<= 4; 888 seq_number <<= 4;
879 } 889 }
880 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, skb, 890 rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, info, skb,
881 hw_queue); 891 hw_queue, &tcb_desc);
882 if (!ieee80211_has_morefrags(hdr->frame_control)) { 892 if (!ieee80211_has_morefrags(hdr->frame_control)) {
883 if (qc) 893 if (qc)
884 mac->tids[tid].seq_number = seq_number; 894 mac->tids[tid].seq_number = seq_number;
@@ -887,7 +897,8 @@ static void _rtl_usb_tx_preprocess(struct ieee80211_hw *hw, struct sk_buff *skb,
887 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); 897 rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);
888} 898}
889 899
890static int rtl_usb_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 900static int rtl_usb_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
901 struct rtl_tcb_desc *dummy)
891{ 902{
892 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); 903 struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
893 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 904 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
diff --git a/drivers/net/wireless/rtlwifi/usb.h b/drivers/net/wireless/rtlwifi/usb.h
index abadfe918d30..d2a63fb3e1e6 100644
--- a/drivers/net/wireless/rtlwifi/usb.h
+++ b/drivers/net/wireless/rtlwifi/usb.h
@@ -31,6 +31,8 @@
31#include <linux/usb.h> 31#include <linux/usb.h>
32#include <linux/skbuff.h> 32#include <linux/skbuff.h>
33 33
34#define RTL_RX_DESC_SIZE 24
35
34#define RTL_USB_DEVICE(vend, prod, cfg) \ 36#define RTL_USB_DEVICE(vend, prod, cfg) \
35 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ 37 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
36 .idVendor = (vend), \ 38 .idVendor = (vend), \
diff --git a/drivers/net/wireless/rtlwifi/wifi.h b/drivers/net/wireless/rtlwifi/wifi.h
index 2713efe07ce5..693395ee98f9 100644
--- a/drivers/net/wireless/rtlwifi/wifi.h
+++ b/drivers/net/wireless/rtlwifi/wifi.h
@@ -68,6 +68,8 @@
68#define QBSS_LOAD_SIZE 5 68#define QBSS_LOAD_SIZE 5
69#define MAX_WMMELE_LENGTH 64 69#define MAX_WMMELE_LENGTH 64
70 70
71#define TOTAL_CAM_ENTRY 32
72
71/*slot time for 11g. */ 73/*slot time for 11g. */
72#define RTL_SLOT_TIME_9 9 74#define RTL_SLOT_TIME_9 9
73#define RTL_SLOT_TIME_20 20 75#define RTL_SLOT_TIME_20 20
@@ -94,8 +96,10 @@
94#define CHANNEL_GROUP_MAX_5G 9 96#define CHANNEL_GROUP_MAX_5G 9
95#define CHANNEL_MAX_NUMBER_2G 14 97#define CHANNEL_MAX_NUMBER_2G 14
96#define AVG_THERMAL_NUM 8 98#define AVG_THERMAL_NUM 8
99#define MAX_TID_COUNT 9
97 100
98/* for early mode */ 101/* for early mode */
102#define FCS_LEN 4
99#define EM_HDR_LEN 8 103#define EM_HDR_LEN 8
100enum intf_type { 104enum intf_type {
101 INTF_PCI = 0, 105 INTF_PCI = 0,
@@ -159,6 +163,8 @@ enum hardware_type {
159(IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal)) 163(IS_HARDWARE_TYPE_8192DE(rtlhal) || IS_HARDWARE_TYPE_8192DU(rtlhal))
160#define IS_HARDWARE_TYPE_8723(rtlhal) \ 164#define IS_HARDWARE_TYPE_8723(rtlhal) \
161(IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal)) 165(IS_HARDWARE_TYPE_8723E(rtlhal) || IS_HARDWARE_TYPE_8723U(rtlhal))
166#define IS_HARDWARE_TYPE_8723U(rtlhal) \
167 (rtlhal->hw_type == HARDWARE_TYPE_RTL8723U)
162 168
163enum scan_operation_backup_opt { 169enum scan_operation_backup_opt {
164 SCAN_OPT_BACKUP = 0, 170 SCAN_OPT_BACKUP = 0,
@@ -297,6 +303,9 @@ enum hw_variables {
297 HW_VAR_DATA_FILTER, 303 HW_VAR_DATA_FILTER,
298}; 304};
299 305
306#define HWSET_MAX_SIZE 128
307#define EFUSE_MAX_SECTION 16
308
300enum _RT_MEDIA_STATUS { 309enum _RT_MEDIA_STATUS {
301 RT_MEDIA_DISCONNECT = 0, 310 RT_MEDIA_DISCONNECT = 0,
302 RT_MEDIA_CONNECT = 1 311 RT_MEDIA_CONNECT = 1
@@ -843,6 +852,7 @@ struct rtl_phy {
843 bool apk_done; 852 bool apk_done;
844 u32 reg_rf3c[2]; /* pathA / pathB */ 853 u32 reg_rf3c[2]; /* pathA / pathB */
845 854
855 /* bfsync */
846 u8 framesync; 856 u8 framesync;
847 u32 framesync_c34; 857 u32 framesync_c34;
848 858
@@ -852,6 +862,10 @@ struct rtl_phy {
852}; 862};
853 863
854#define MAX_TID_COUNT 9 864#define MAX_TID_COUNT 9
865#define RTL_AGG_STOP 0
866#define RTL_AGG_PROGRESS 1
867#define RTL_AGG_START 2
868#define RTL_AGG_OPERATIONAL 3
855#define RTL_AGG_OFF 0 869#define RTL_AGG_OFF 0
856#define RTL_AGG_ON 1 870#define RTL_AGG_ON 1
857#define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2 871#define RTL_AGG_EMPTYING_HW_QUEUE_ADDBA 2
@@ -871,6 +885,13 @@ struct rtl_tid_data {
871 struct rtl_ht_agg agg; 885 struct rtl_ht_agg agg;
872}; 886};
873 887
888struct rtl_sta_info {
889 u8 ratr_index;
890 u8 wireless_mode;
891 u8 mimo_ps;
892 struct rtl_tid_data tids[MAX_TID_COUNT];
893} __packed;
894
874struct rtl_priv; 895struct rtl_priv;
875struct rtl_io { 896struct rtl_io {
876 struct device *dev; 897 struct device *dev;
@@ -894,6 +915,7 @@ struct rtl_io {
894 u32(*read32_sync) (struct rtl_priv *rtlpriv, u32 addr); 915 u32(*read32_sync) (struct rtl_priv *rtlpriv, u32 addr);
895 int (*readN_sync) (struct rtl_priv *rtlpriv, u32 addr, u16 len, 916 int (*readN_sync) (struct rtl_priv *rtlpriv, u32 addr, u16 len,
896 u8 *pdata); 917 u8 *pdata);
918
897}; 919};
898 920
899struct rtl_mac { 921struct rtl_mac {
@@ -916,6 +938,8 @@ struct rtl_mac {
916 int n_channels; 938 int n_channels;
917 int n_bitrates; 939 int n_bitrates;
918 940
941 bool offchan_deley;
942
919 /*filters */ 943 /*filters */
920 u32 rx_conf; 944 u32 rx_conf;
921 u16 rx_mgt_filter; 945 u16 rx_mgt_filter;
@@ -1032,7 +1056,9 @@ struct rtl_security {
1032 enum rt_enc_alg pairwise_enc_algorithm; 1056 enum rt_enc_alg pairwise_enc_algorithm;
1033 /*Encryption Algorithm for Brocast/Multicast */ 1057 /*Encryption Algorithm for Brocast/Multicast */
1034 enum rt_enc_alg group_enc_algorithm; 1058 enum rt_enc_alg group_enc_algorithm;
1035 1059 /*Cam Entry Bitmap */
1060 u32 hwsec_cam_bitmap;
1061 u8 hwsec_cam_sta_addr[TOTAL_CAM_ENTRY][ETH_ALEN];
1036 /*local Key buffer, indx 0 is for 1062 /*local Key buffer, indx 0 is for
1037 pairwise key 1-4 is for agoup key. */ 1063 pairwise key 1-4 is for agoup key. */
1038 u8 key_buf[KEY_BUF_SIZE][MAX_KEY_LEN]; 1064 u8 key_buf[KEY_BUF_SIZE][MAX_KEY_LEN];
@@ -1053,7 +1079,7 @@ struct rtl_dm {
1053 bool current_turbo_edca; 1079 bool current_turbo_edca;
1054 bool is_any_nonbepkts; /*out dm */ 1080 bool is_any_nonbepkts; /*out dm */
1055 bool is_cur_rdlstate; 1081 bool is_cur_rdlstate;
1056 bool txpower_trackingInit; 1082 bool txpower_trackinginit;
1057 bool disable_framebursting; 1083 bool disable_framebursting;
1058 bool cck_inch14; 1084 bool cck_inch14;
1059 bool txpower_tracking; 1085 bool txpower_tracking;
@@ -1079,7 +1105,6 @@ struct rtl_dm {
1079 bool disable_tx_int; 1105 bool disable_tx_int;
1080 char ofdm_index[2]; 1106 char ofdm_index[2];
1081 char cck_index; 1107 char cck_index;
1082 u8 power_index_backup[6];
1083}; 1108};
1084 1109
1085#define EFUSE_MAX_LOGICAL_SIZE 256 1110#define EFUSE_MAX_LOGICAL_SIZE 256
@@ -1175,6 +1200,7 @@ struct rtl_ps_ctl {
1175 * otherwise Offset[560h] = 0x00. 1200 * otherwise Offset[560h] = 0x00.
1176 * */ 1201 * */
1177 bool support_aspm; 1202 bool support_aspm;
1203
1178 bool support_backdoor; 1204 bool support_backdoor;
1179 1205
1180 /*for LPS */ 1206 /*for LPS */
@@ -1201,7 +1227,6 @@ struct rtl_ps_ctl {
1201 1227
1202 /*just for PCIE ASPM */ 1228 /*just for PCIE ASPM */
1203 u8 const_amdpci_aspm; 1229 u8 const_amdpci_aspm;
1204
1205 bool pwrdown_mode; 1230 bool pwrdown_mode;
1206 1231
1207 enum rf_pwrstate inactive_pwrstate; 1232 enum rf_pwrstate inactive_pwrstate;
@@ -1282,6 +1307,10 @@ struct rt_link_detect {
1282 bool busytraffic; 1307 bool busytraffic;
1283 bool higher_busytraffic; 1308 bool higher_busytraffic;
1284 bool higher_busyrxtraffic; 1309 bool higher_busyrxtraffic;
1310
1311 u32 tidtx_in4period[MAX_TID_COUNT][4];
1312 u32 tidtx_inperiod[MAX_TID_COUNT];
1313 bool higher_busytxtraffic[MAX_TID_COUNT];
1285}; 1314};
1286 1315
1287struct rtl_tcb_desc { 1316struct rtl_tcb_desc {
@@ -1344,13 +1373,15 @@ struct rtl_hal_ops {
1344 u32 add_msr, u32 rm_msr); 1373 u32 add_msr, u32 rm_msr);
1345 void (*get_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val); 1374 void (*get_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
1346 void (*set_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val); 1375 void (*set_hw_reg) (struct ieee80211_hw *hw, u8 variable, u8 *val);
1347 void (*update_rate_table) (struct ieee80211_hw *hw); 1376 void (*update_rate_tbl) (struct ieee80211_hw *hw,
1377 struct ieee80211_sta *sta, u8 rssi_level);
1348 void (*update_rate_mask) (struct ieee80211_hw *hw, u8 rssi_level); 1378 void (*update_rate_mask) (struct ieee80211_hw *hw, u8 rssi_level);
1349 void (*fill_tx_desc) (struct ieee80211_hw *hw, 1379 void (*fill_tx_desc) (struct ieee80211_hw *hw,
1350 struct ieee80211_hdr *hdr, u8 *pdesc_tx, 1380 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
1351 struct ieee80211_tx_info *info, 1381 struct ieee80211_tx_info *info,
1352 struct sk_buff *skb, unsigned int queue_index); 1382 struct sk_buff *skb, u8 hw_queue,
1353 void (*fill_fake_txdesc) (struct ieee80211_hw *hw, u8 * pDesc, 1383 struct rtl_tcb_desc *ptcb_desc);
1384 void (*fill_fake_txdesc) (struct ieee80211_hw *hw, u8 *pDesc,
1354 u32 buffer_len, bool bIsPsPoll); 1385 u32 buffer_len, bool bIsPsPoll);
1355 void (*fill_tx_cmddesc) (struct ieee80211_hw *hw, u8 *pdesc, 1386 void (*fill_tx_cmddesc) (struct ieee80211_hw *hw, u8 *pdesc,
1356 bool firstseg, bool lastseg, 1387 bool firstseg, bool lastseg,
@@ -1370,10 +1401,10 @@ struct rtl_hal_ops {
1370 enum led_ctl_mode ledaction); 1401 enum led_ctl_mode ledaction);
1371 void (*set_desc) (u8 *pdesc, bool istx, u8 desc_name, u8 *val); 1402 void (*set_desc) (u8 *pdesc, bool istx, u8 desc_name, u8 *val);
1372 u32 (*get_desc) (u8 *pdesc, bool istx, u8 desc_name); 1403 u32 (*get_desc) (u8 *pdesc, bool istx, u8 desc_name);
1373 void (*tx_polling) (struct ieee80211_hw *hw, unsigned int hw_queue); 1404 void (*tx_polling) (struct ieee80211_hw *hw, u8 hw_queue);
1374 void (*enable_hw_sec) (struct ieee80211_hw *hw); 1405 void (*enable_hw_sec) (struct ieee80211_hw *hw);
1375 void (*set_key) (struct ieee80211_hw *hw, u32 key_index, 1406 void (*set_key) (struct ieee80211_hw *hw, u32 key_index,
1376 u8 *p_macaddr, bool is_group, u8 enc_algo, 1407 u8 *macaddr, bool is_group, u8 enc_algo,
1377 bool is_wepkey, bool clear_all); 1408 bool is_wepkey, bool clear_all);
1378 void (*init_sw_leds) (struct ieee80211_hw *hw); 1409 void (*init_sw_leds) (struct ieee80211_hw *hw);
1379 void (*deinit_sw_leds) (struct ieee80211_hw *hw); 1410 void (*deinit_sw_leds) (struct ieee80211_hw *hw);
@@ -1384,6 +1415,7 @@ struct rtl_hal_ops {
1384 u32 regaddr, u32 bitmask); 1415 u32 regaddr, u32 bitmask);
1385 void (*set_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath, 1416 void (*set_rfreg) (struct ieee80211_hw *hw, enum radio_path rfpath,
1386 u32 regaddr, u32 bitmask, u32 data); 1417 u32 regaddr, u32 bitmask, u32 data);
1418 void (*linked_set_reg) (struct ieee80211_hw *hw);
1387 bool (*phy_rf6052_config) (struct ieee80211_hw *hw); 1419 bool (*phy_rf6052_config) (struct ieee80211_hw *hw);
1388 void (*phy_rf6052_set_cck_txpower) (struct ieee80211_hw *hw, 1420 void (*phy_rf6052_set_cck_txpower) (struct ieee80211_hw *hw,
1389 u8 *powerlevel); 1421 u8 *powerlevel);
@@ -1404,7 +1436,9 @@ struct rtl_intf_ops {
1404 int (*adapter_start) (struct ieee80211_hw *hw); 1436 int (*adapter_start) (struct ieee80211_hw *hw);
1405 void (*adapter_stop) (struct ieee80211_hw *hw); 1437 void (*adapter_stop) (struct ieee80211_hw *hw);
1406 1438
1407 int (*adapter_tx) (struct ieee80211_hw *hw, struct sk_buff *skb); 1439 int (*adapter_tx) (struct ieee80211_hw *hw, struct sk_buff *skb,
1440 struct rtl_tcb_desc *ptcb_desc);
1441 void (*flush)(struct ieee80211_hw *hw, bool drop);
1408 int (*reset_trx_ring) (struct ieee80211_hw *hw); 1442 int (*reset_trx_ring) (struct ieee80211_hw *hw);
1409 bool (*waitq_insert) (struct ieee80211_hw *hw, struct sk_buff *skb); 1443 bool (*waitq_insert) (struct ieee80211_hw *hw, struct sk_buff *skb);
1410 1444
@@ -1418,6 +1452,15 @@ struct rtl_intf_ops {
1418struct rtl_mod_params { 1452struct rtl_mod_params {
1419 /* default: 0 = using hardware encryption */ 1453 /* default: 0 = using hardware encryption */
1420 int sw_crypto; 1454 int sw_crypto;
1455
1456 /* default: 1 = using no linked power save */
1457 bool inactiveps;
1458
1459 /* default: 1 = using linked sw power save */
1460 bool swctrl_lps;
1461
1462 /* default: 1 = using linked fw power save */
1463 bool fwctrl_lps;
1421}; 1464};
1422 1465
1423struct rtl_hal_usbint_cfg { 1466struct rtl_hal_usbint_cfg {
@@ -1445,6 +1488,7 @@ struct rtl_hal_usbint_cfg {
1445 1488
1446struct rtl_hal_cfg { 1489struct rtl_hal_cfg {
1447 u8 bar_id; 1490 u8 bar_id;
1491 bool write_readback;
1448 char *name; 1492 char *name;
1449 char *fw_name; 1493 char *fw_name;
1450 struct rtl_hal_ops *ops; 1494 struct rtl_hal_ops *ops;
@@ -1469,7 +1513,6 @@ struct rtl_locks {
1469 spinlock_t rf_lock; 1513 spinlock_t rf_lock;
1470 spinlock_t lps_lock; 1514 spinlock_t lps_lock;
1471 spinlock_t waitq_lock; 1515 spinlock_t waitq_lock;
1472 spinlock_t tx_urb_lock;
1473 1516
1474 /*Dual mac*/ 1517 /*Dual mac*/
1475 spinlock_t cck_and_rw_pagea_lock; 1518 spinlock_t cck_and_rw_pagea_lock;
@@ -1653,13 +1696,23 @@ struct bt_coexist_info {
1653#define EF4BYTE(_val) \ 1696#define EF4BYTE(_val) \
1654 (le32_to_cpu(_val)) 1697 (le32_to_cpu(_val))
1655 1698
1699/* Read data from memory */
1700#define READEF1BYTE(_ptr) \
1701 EF1BYTE(*((u8 *)(_ptr)))
1656/* Read le16 data from memory and convert to host ordering */ 1702/* Read le16 data from memory and convert to host ordering */
1657#define READEF2BYTE(_ptr) \ 1703#define READEF2BYTE(_ptr) \
1658 EF2BYTE(*((u16 *)(_ptr))) 1704 EF2BYTE(*((u16 *)(_ptr)))
1705#define READEF4BYTE(_ptr) \
1706 EF4BYTE(*((u32 *)(_ptr)))
1659 1707
1708/* Write data to memory */
1709#define WRITEEF1BYTE(_ptr, _val) \
1710 (*((u8 *)(_ptr))) = EF1BYTE(_val)
1660/* Write le16 data to memory in host ordering */ 1711/* Write le16 data to memory in host ordering */
1661#define WRITEEF2BYTE(_ptr, _val) \ 1712#define WRITEEF2BYTE(_ptr, _val) \
1662 (*((u16 *)(_ptr))) = EF2BYTE(_val) 1713 (*((u16 *)(_ptr))) = EF2BYTE(_val)
1714#define WRITEEF4BYTE(_ptr, _val) \
1715 (*((u16 *)(_ptr))) = EF2BYTE(_val)
1663 1716
1664/* Create a bit mask 1717/* Create a bit mask
1665 * Examples: 1718 * Examples:
@@ -1698,6 +1751,25 @@ struct bt_coexist_info {
1698#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \ 1751#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
1699 (EF1BYTE(*((u8 *)(__pstart)))) 1752 (EF1BYTE(*((u8 *)(__pstart))))
1700 1753
1754/*Description:
1755Translate subfield (continuous bits in little-endian) of 4-byte
1756value to host byte ordering.*/
1757#define LE_BITS_TO_4BYTE(__pstart, __bitoffset, __bitlen) \
1758 ( \
1759 (LE_P4BYTE_TO_HOST_4BYTE(__pstart) >> (__bitoffset)) & \
1760 BIT_LEN_MASK_32(__bitlen) \
1761 )
1762#define LE_BITS_TO_2BYTE(__pstart, __bitoffset, __bitlen) \
1763 ( \
1764 (LE_P2BYTE_TO_HOST_2BYTE(__pstart) >> (__bitoffset)) & \
1765 BIT_LEN_MASK_16(__bitlen) \
1766 )
1767#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
1768 ( \
1769 (LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
1770 BIT_LEN_MASK_8(__bitlen) \
1771 )
1772
1701/* Description: 1773/* Description:
1702 * Mask subfield (continuous bits in little-endian) of 4-byte value 1774 * Mask subfield (continuous bits in little-endian) of 4-byte value
1703 * and return the result in 4-byte value in host byte ordering. 1775 * and return the result in 4-byte value in host byte ordering.
@@ -1721,6 +1793,18 @@ struct bt_coexist_info {
1721/* Description: 1793/* Description:
1722 * Set subfield of little-endian 4-byte value to specified value. 1794 * Set subfield of little-endian 4-byte value to specified value.
1723 */ 1795 */
1796#define SET_BITS_TO_LE_4BYTE(__pstart, __bitoffset, __bitlen, __val) \
1797 *((u32 *)(__pstart)) = EF4BYTE \
1798 ( \
1799 LE_BITS_CLEARED_TO_4BYTE(__pstart, __bitoffset, __bitlen) | \
1800 ((((u32)__val) & BIT_LEN_MASK_32(__bitlen)) << (__bitoffset)) \
1801 );
1802#define SET_BITS_TO_LE_2BYTE(__pstart, __bitoffset, __bitlen, __val) \
1803 *((u16 *)(__pstart)) = EF2BYTE \
1804 ( \
1805 LE_BITS_CLEARED_TO_2BYTE(__pstart, __bitoffset, __bitlen) | \
1806 ((((u16)__val) & BIT_LEN_MASK_16(__bitlen)) << (__bitoffset)) \
1807 );
1724#define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \ 1808#define SET_BITS_TO_LE_1BYTE(__pstart, __bitoffset, __bitlen, __val) \
1725 *((u8 *)(__pstart)) = EF1BYTE \ 1809 *((u8 *)(__pstart)) = EF1BYTE \
1726 ( \ 1810 ( \
@@ -1728,12 +1812,16 @@ struct bt_coexist_info {
1728 ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \ 1812 ((((u8)__val) & BIT_LEN_MASK_8(__bitlen)) << (__bitoffset)) \
1729 ); 1813 );
1730 1814
1815#define N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
1816 (__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
1817
1731/**************************************** 1818/****************************************
1732 mem access macro define end 1819 mem access macro define end
1733****************************************/ 1820****************************************/
1734 1821
1735#define byte(x, n) ((x >> (8 * n)) & 0xff) 1822#define byte(x, n) ((x >> (8 * n)) & 0xff)
1736 1823
1824#define packet_get_type(_packet) (EF1BYTE((_packet).octet[0]) & 0xFC)
1737#define RTL_WATCH_DOG_TIME 2000 1825#define RTL_WATCH_DOG_TIME 2000
1738#define MSECS(t) msecs_to_jiffies(t) 1826#define MSECS(t) msecs_to_jiffies(t)
1739#define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS) 1827#define WLAN_FC_GET_VERS(fc) (le16_to_cpu(fc) & IEEE80211_FCTL_VERS)
@@ -1768,6 +1856,15 @@ struct bt_coexist_info {
1768#define container_of_dwork_rtl(x, y, z) \ 1856#define container_of_dwork_rtl(x, y, z) \
1769 container_of(container_of(x, struct delayed_work, work), y, z) 1857 container_of(container_of(x, struct delayed_work, work), y, z)
1770 1858
1859#define FILL_OCTET_STRING(_os, _octet, _len) \
1860 (_os).octet = (u8 *)(_octet); \
1861 (_os).length = (_len);
1862
1863#define CP_MACADDR(des, src) \
1864 ((des)[0] = (src)[0], (des)[1] = (src)[1],\
1865 (des)[2] = (src)[2], (des)[3] = (src)[3],\
1866 (des)[4] = (src)[4], (des)[5] = (src)[5])
1867
1771static inline u8 rtl_read_byte(struct rtl_priv *rtlpriv, u32 addr) 1868static inline u8 rtl_read_byte(struct rtl_priv *rtlpriv, u32 addr)
1772{ 1869{
1773 return rtlpriv->io.read8_sync(rtlpriv, addr); 1870 return rtlpriv->io.read8_sync(rtlpriv, addr);
@@ -1786,17 +1883,26 @@ static inline u32 rtl_read_dword(struct rtl_priv *rtlpriv, u32 addr)
1786static inline void rtl_write_byte(struct rtl_priv *rtlpriv, u32 addr, u8 val8) 1883static inline void rtl_write_byte(struct rtl_priv *rtlpriv, u32 addr, u8 val8)
1787{ 1884{
1788 rtlpriv->io.write8_async(rtlpriv, addr, val8); 1885 rtlpriv->io.write8_async(rtlpriv, addr, val8);
1886
1887 if (rtlpriv->cfg->write_readback)
1888 rtlpriv->io.read8_sync(rtlpriv, addr);
1789} 1889}
1790 1890
1791static inline void rtl_write_word(struct rtl_priv *rtlpriv, u32 addr, u16 val16) 1891static inline void rtl_write_word(struct rtl_priv *rtlpriv, u32 addr, u16 val16)
1792{ 1892{
1793 rtlpriv->io.write16_async(rtlpriv, addr, val16); 1893 rtlpriv->io.write16_async(rtlpriv, addr, val16);
1894
1895 if (rtlpriv->cfg->write_readback)
1896 rtlpriv->io.read16_sync(rtlpriv, addr);
1794} 1897}
1795 1898
1796static inline void rtl_write_dword(struct rtl_priv *rtlpriv, 1899static inline void rtl_write_dword(struct rtl_priv *rtlpriv,
1797 u32 addr, u32 val32) 1900 u32 addr, u32 val32)
1798{ 1901{
1799 rtlpriv->io.write32_async(rtlpriv, addr, val32); 1902 rtlpriv->io.write32_async(rtlpriv, addr, val32);
1903
1904 if (rtlpriv->cfg->write_readback)
1905 rtlpriv->io.read32_sync(rtlpriv, addr);
1800} 1906}
1801 1907
1802static inline u32 rtl_get_bbreg(struct ieee80211_hw *hw, 1908static inline u32 rtl_get_bbreg(struct ieee80211_hw *hw,
@@ -1855,4 +1961,31 @@ static inline u8 get_rf_type(struct rtl_phy *rtlphy)
1855 return rtlphy->rf_type; 1961 return rtlphy->rf_type;
1856} 1962}
1857 1963
1964static inline struct ieee80211_hdr *rtl_get_hdr(struct sk_buff *skb)
1965{
1966 return (struct ieee80211_hdr *)(skb->data);
1967}
1968
1969static inline __le16 rtl_get_fc(struct sk_buff *skb)
1970{
1971 return rtl_get_hdr(skb)->frame_control;
1972}
1973
1974static inline u16 rtl_get_tid_h(struct ieee80211_hdr *hdr)
1975{
1976 return (ieee80211_get_qos_ctl(hdr))[0] & IEEE80211_QOS_CTL_TID_MASK;
1977}
1978
1979static inline u16 rtl_get_tid(struct sk_buff *skb)
1980{
1981 return rtl_get_tid_h(rtl_get_hdr(skb));
1982}
1983
1984static inline struct ieee80211_sta *get_sta(struct ieee80211_hw *hw,
1985 struct ieee80211_vif *vif,
1986 u8 *bssid)
1987{
1988 return ieee80211_find_sta(vif, bssid);
1989}
1990
1858#endif 1991#endif