1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
42 *NOTICE!!!: This file will be very big, we hsould
43 *keep it clear under follwing roles:
45 *This file include follwing part, so, if you add new
46 *functions into this file, please check which part it
47 *should includes. or check if you should add new part
50 *1) mac80211 init functions
51 *2) tx information functions
52 *3) functions called by core.c
53 *4) wq & timer callback functions
54 *5) frame process functions
60 /*********************************************************
62 * mac80211 init functions
64 *********************************************************/
65 static struct ieee80211_channel rtl_channeltable_2g
[] = {
66 {.center_freq
= 2412, .hw_value
= 1,},
67 {.center_freq
= 2417, .hw_value
= 2,},
68 {.center_freq
= 2422, .hw_value
= 3,},
69 {.center_freq
= 2427, .hw_value
= 4,},
70 {.center_freq
= 2432, .hw_value
= 5,},
71 {.center_freq
= 2437, .hw_value
= 6,},
72 {.center_freq
= 2442, .hw_value
= 7,},
73 {.center_freq
= 2447, .hw_value
= 8,},
74 {.center_freq
= 2452, .hw_value
= 9,},
75 {.center_freq
= 2457, .hw_value
= 10,},
76 {.center_freq
= 2462, .hw_value
= 11,},
77 {.center_freq
= 2467, .hw_value
= 12,},
78 {.center_freq
= 2472, .hw_value
= 13,},
79 {.center_freq
= 2484, .hw_value
= 14,},
82 static struct ieee80211_channel rtl_channeltable_5g
[] = {
83 {.center_freq
= 5180, .hw_value
= 36,},
84 {.center_freq
= 5200, .hw_value
= 40,},
85 {.center_freq
= 5220, .hw_value
= 44,},
86 {.center_freq
= 5240, .hw_value
= 48,},
87 {.center_freq
= 5260, .hw_value
= 52,},
88 {.center_freq
= 5280, .hw_value
= 56,},
89 {.center_freq
= 5300, .hw_value
= 60,},
90 {.center_freq
= 5320, .hw_value
= 64,},
91 {.center_freq
= 5500, .hw_value
= 100,},
92 {.center_freq
= 5520, .hw_value
= 104,},
93 {.center_freq
= 5540, .hw_value
= 108,},
94 {.center_freq
= 5560, .hw_value
= 112,},
95 {.center_freq
= 5580, .hw_value
= 116,},
96 {.center_freq
= 5600, .hw_value
= 120,},
97 {.center_freq
= 5620, .hw_value
= 124,},
98 {.center_freq
= 5640, .hw_value
= 128,},
99 {.center_freq
= 5660, .hw_value
= 132,},
100 {.center_freq
= 5680, .hw_value
= 136,},
101 {.center_freq
= 5700, .hw_value
= 140,},
102 {.center_freq
= 5745, .hw_value
= 149,},
103 {.center_freq
= 5765, .hw_value
= 153,},
104 {.center_freq
= 5785, .hw_value
= 157,},
105 {.center_freq
= 5805, .hw_value
= 161,},
106 {.center_freq
= 5825, .hw_value
= 165,},
109 static struct ieee80211_rate rtl_ratetable_2g
[] = {
110 {.bitrate
= 10, .hw_value
= 0x00,},
111 {.bitrate
= 20, .hw_value
= 0x01,},
112 {.bitrate
= 55, .hw_value
= 0x02,},
113 {.bitrate
= 110, .hw_value
= 0x03,},
114 {.bitrate
= 60, .hw_value
= 0x04,},
115 {.bitrate
= 90, .hw_value
= 0x05,},
116 {.bitrate
= 120, .hw_value
= 0x06,},
117 {.bitrate
= 180, .hw_value
= 0x07,},
118 {.bitrate
= 240, .hw_value
= 0x08,},
119 {.bitrate
= 360, .hw_value
= 0x09,},
120 {.bitrate
= 480, .hw_value
= 0x0a,},
121 {.bitrate
= 540, .hw_value
= 0x0b,},
124 static struct ieee80211_rate rtl_ratetable_5g
[] = {
125 {.bitrate
= 60, .hw_value
= 0x04,},
126 {.bitrate
= 90, .hw_value
= 0x05,},
127 {.bitrate
= 120, .hw_value
= 0x06,},
128 {.bitrate
= 180, .hw_value
= 0x07,},
129 {.bitrate
= 240, .hw_value
= 0x08,},
130 {.bitrate
= 360, .hw_value
= 0x09,},
131 {.bitrate
= 480, .hw_value
= 0x0a,},
132 {.bitrate
= 540, .hw_value
= 0x0b,},
135 static const struct ieee80211_supported_band rtl_band_2ghz
= {
136 .band
= IEEE80211_BAND_2GHZ
,
138 .channels
= rtl_channeltable_2g
,
139 .n_channels
= ARRAY_SIZE(rtl_channeltable_2g
),
141 .bitrates
= rtl_ratetable_2g
,
142 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_2g
),
147 static struct ieee80211_supported_band rtl_band_5ghz
= {
148 .band
= IEEE80211_BAND_5GHZ
,
150 .channels
= rtl_channeltable_5g
,
151 .n_channels
= ARRAY_SIZE(rtl_channeltable_5g
),
153 .bitrates
= rtl_ratetable_5g
,
154 .n_bitrates
= ARRAY_SIZE(rtl_ratetable_5g
),
159 static const u8 tid_to_ac
[] = {
160 2, /* IEEE80211_AC_BE */
161 3, /* IEEE80211_AC_BK */
162 3, /* IEEE80211_AC_BK */
163 2, /* IEEE80211_AC_BE */
164 1, /* IEEE80211_AC_VI */
165 1, /* IEEE80211_AC_VI */
166 0, /* IEEE80211_AC_VO */
167 0, /* IEEE80211_AC_VO */
170 u8
rtl_tid_to_ac(struct ieee80211_hw
*hw
, u8 tid
)
172 return tid_to_ac
[tid
];
175 static void _rtl_init_hw_ht_capab(struct ieee80211_hw
*hw
,
176 struct ieee80211_sta_ht_cap
*ht_cap
)
178 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
179 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
181 ht_cap
->ht_supported
= true;
182 ht_cap
->cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
183 IEEE80211_HT_CAP_SGI_40
|
184 IEEE80211_HT_CAP_SGI_20
|
185 IEEE80211_HT_CAP_DSSSCCK40
| IEEE80211_HT_CAP_MAX_AMSDU
;
187 if (rtlpriv
->rtlhal
.disable_amsdu_8k
)
188 ht_cap
->cap
&= ~IEEE80211_HT_CAP_MAX_AMSDU
;
191 *Maximum length of AMPDU that the STA can receive.
192 *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets)
194 ht_cap
->ampdu_factor
= IEEE80211_HT_MAX_AMPDU_64K
;
196 /*Minimum MPDU start spacing , */
197 ht_cap
->ampdu_density
= IEEE80211_HT_MPDU_DENSITY_16
;
199 ht_cap
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
202 *hw->wiphy->bands[IEEE80211_BAND_2GHZ]
205 *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7
206 *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15
207 *if rx_ant >=3 rx_mask[2]=0xff;
208 *if BW_40 rx_mask[4]=0x01;
209 *highest supported RX rate
211 if (get_rf_type(rtlphy
) == RF_1T2R
|| get_rf_type(rtlphy
) == RF_2T2R
) {
213 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("1T2R or 2T2R\n"));
215 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
216 ht_cap
->mcs
.rx_mask
[1] = 0xFF;
217 ht_cap
->mcs
.rx_mask
[4] = 0x01;
219 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15
);
220 } else if (get_rf_type(rtlphy
) == RF_1T1R
) {
222 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("1T1R\n"));
224 ht_cap
->mcs
.rx_mask
[0] = 0xFF;
225 ht_cap
->mcs
.rx_mask
[1] = 0x00;
226 ht_cap
->mcs
.rx_mask
[4] = 0x01;
228 ht_cap
->mcs
.rx_highest
= cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7
);
232 static void _rtl_init_mac80211(struct ieee80211_hw
*hw
)
234 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
235 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
236 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
237 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
238 struct ieee80211_supported_band
*sband
;
241 if (rtlhal
->macphymode
== SINGLEMAC_SINGLEPHY
&& rtlhal
->bandset
==
244 /* <1> use mac->bands as mem for hw->wiphy->bands */
245 sband
= &(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]);
247 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
248 * to default value(1T1R) */
249 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]), &rtl_band_2ghz
,
250 sizeof(struct ieee80211_supported_band
));
252 /* <3> init ht cap base on ant_num */
253 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
255 /* <4> set mac->sband to wiphy->sband */
256 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = sband
;
259 /* <1> use mac->bands as mem for hw->wiphy->bands */
260 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
262 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
263 * to default value(1T1R) */
264 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]), &rtl_band_5ghz
,
265 sizeof(struct ieee80211_supported_band
));
267 /* <3> init ht cap base on ant_num */
268 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
270 /* <4> set mac->sband to wiphy->sband */
271 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = sband
;
273 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
274 /* <1> use mac->bands as mem for hw->wiphy->bands */
275 sband
= &(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]);
277 /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ]
278 * to default value(1T1R) */
279 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_2GHZ
]),
281 sizeof(struct ieee80211_supported_band
));
283 /* <3> init ht cap base on ant_num */
284 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
286 /* <4> set mac->sband to wiphy->sband */
287 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = sband
;
288 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
289 /* <1> use mac->bands as mem for hw->wiphy->bands */
290 sband
= &(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]);
292 /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ]
293 * to default value(1T1R) */
294 memcpy(&(rtlmac
->bands
[IEEE80211_BAND_5GHZ
]),
296 sizeof(struct ieee80211_supported_band
));
298 /* <3> init ht cap base on ant_num */
299 _rtl_init_hw_ht_capab(hw
, &sband
->ht_cap
);
301 /* <4> set mac->sband to wiphy->sband */
302 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = sband
;
304 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
306 rtlhal
->current_bandtype
));
309 /* <5> set hw caps */
310 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
311 IEEE80211_HW_RX_INCLUDES_FCS
|
312 IEEE80211_HW_BEACON_FILTER
|
313 IEEE80211_HW_AMPDU_AGGREGATION
|
314 IEEE80211_HW_CONNECTION_MONITOR
|
315 /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */
316 IEEE80211_HW_REPORTS_TX_ACK_STATUS
| 0;
318 /* swlps or hwlps has been set in diff chip in init_sw_vars */
319 if (rtlpriv
->psc
.swctrl_lps
)
320 hw
->flags
|= IEEE80211_HW_SUPPORTS_PS
|
321 IEEE80211_HW_PS_NULLFUNC_STACK
|
322 /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */
325 hw
->wiphy
->interface_modes
=
326 BIT(NL80211_IFTYPE_AP
) |
327 BIT(NL80211_IFTYPE_STATION
) |
328 BIT(NL80211_IFTYPE_ADHOC
);
330 hw
->wiphy
->rts_threshold
= 2347;
333 hw
->extra_tx_headroom
= RTL_TX_HEADER_SIZE
;
335 /* TODO: Correct this value for our hw */
336 /* TODO: define these hard code value */
337 hw
->channel_change_time
= 100;
338 hw
->max_listen_interval
= 10;
339 hw
->max_rate_tries
= 4;
340 /* hw->max_rates = 1; */
341 hw
->sta_data_size
= sizeof(struct rtl_sta_info
);
343 /* <6> mac address */
344 if (is_valid_ether_addr(rtlefuse
->dev_addr
)) {
345 SET_IEEE80211_PERM_ADDR(hw
, rtlefuse
->dev_addr
);
347 u8 rtlmac
[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 };
348 get_random_bytes((rtlmac
+ (ETH_ALEN
- 1)), 1);
349 SET_IEEE80211_PERM_ADDR(hw
, rtlmac
);
354 static void _rtl_init_deferred_work(struct ieee80211_hw
*hw
)
356 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
359 init_timer(&rtlpriv
->works
.watchdog_timer
);
360 setup_timer(&rtlpriv
->works
.watchdog_timer
,
361 rtl_watch_dog_timer_callback
, (unsigned long)hw
);
364 rtlpriv
->works
.hw
= hw
;
365 rtlpriv
->works
.rtl_wq
= alloc_workqueue(rtlpriv
->cfg
->name
, 0, 0);
366 INIT_DELAYED_WORK(&rtlpriv
->works
.watchdog_wq
,
367 (void *)rtl_watchdog_wq_callback
);
368 INIT_DELAYED_WORK(&rtlpriv
->works
.ips_nic_off_wq
,
369 (void *)rtl_ips_nic_off_wq_callback
);
370 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_work
,
371 (void *)rtl_swlps_wq_callback
);
372 INIT_DELAYED_WORK(&rtlpriv
->works
.ps_rfon_wq
,
373 (void *)rtl_swlps_rfon_wq_callback
);
377 void rtl_deinit_deferred_work(struct ieee80211_hw
*hw
)
379 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
381 del_timer_sync(&rtlpriv
->works
.watchdog_timer
);
383 cancel_delayed_work(&rtlpriv
->works
.watchdog_wq
);
384 cancel_delayed_work(&rtlpriv
->works
.ips_nic_off_wq
);
385 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
386 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
389 void rtl_init_rfkill(struct ieee80211_hw
*hw
)
391 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
397 /*set init state to on */
398 rtlpriv
->rfkill
.rfkill_state
= 1;
399 wiphy_rfkill_set_hw_state(hw
->wiphy
, 0);
401 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
404 pr_info("wireless switch is %s\n",
405 rtlpriv
->rfkill
.rfkill_state
? "on" : "off");
407 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
409 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
410 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
413 wiphy_rfkill_start_polling(hw
->wiphy
);
416 void rtl_deinit_rfkill(struct ieee80211_hw
*hw
)
418 wiphy_rfkill_stop_polling(hw
->wiphy
);
421 int rtl_init_core(struct ieee80211_hw
*hw
)
423 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
424 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
426 /* <1> init mac80211 */
427 _rtl_init_mac80211(hw
);
430 /* <2> rate control register */
431 hw
->rate_control_algorithm
= "rtl_rc";
434 * <3> init CRDA must come after init
435 * mac80211 hw in _rtl_init_mac80211.
437 if (rtl_regd_init(hw
, rtl_reg_notifier
)) {
438 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("REGD init failed\n"));
441 /* CRDA regd hint must after init CRDA */
442 if (regulatory_hint(hw
->wiphy
, rtlpriv
->regd
.alpha2
)) {
443 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
444 ("regulatory_hint fail\n"));
449 mutex_init(&rtlpriv
->locks
.conf_mutex
);
450 spin_lock_init(&rtlpriv
->locks
.ips_lock
);
451 spin_lock_init(&rtlpriv
->locks
.irq_th_lock
);
452 spin_lock_init(&rtlpriv
->locks
.h2c_lock
);
453 spin_lock_init(&rtlpriv
->locks
.rf_ps_lock
);
454 spin_lock_init(&rtlpriv
->locks
.rf_lock
);
455 spin_lock_init(&rtlpriv
->locks
.lps_lock
);
456 spin_lock_init(&rtlpriv
->locks
.waitq_lock
);
457 spin_lock_init(&rtlpriv
->locks
.cck_and_rw_pagea_lock
);
459 rtlmac
->link_state
= MAC80211_NOLINK
;
461 /* <5> init deferred work */
462 _rtl_init_deferred_work(hw
);
467 void rtl_deinit_core(struct ieee80211_hw
*hw
)
471 void rtl_init_rx_config(struct ieee80211_hw
*hw
)
473 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
474 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
476 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RCR
, (u8
*) (&mac
->rx_conf
));
479 /*********************************************************
481 * tx information functions
483 *********************************************************/
484 static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw
*hw
,
485 struct rtl_tcb_desc
*tcb_desc
,
486 struct ieee80211_tx_info
*info
)
488 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
489 u8 rate_flag
= info
->control
.rates
[0].flags
;
491 tcb_desc
->use_shortpreamble
= false;
493 /* 1M can only use Long Preamble. 11B spec */
494 if (tcb_desc
->hw_rate
== rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE1M
])
496 else if (rate_flag
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
497 tcb_desc
->use_shortpreamble
= true;
502 static void _rtl_query_shortgi(struct ieee80211_hw
*hw
,
503 struct ieee80211_sta
*sta
,
504 struct rtl_tcb_desc
*tcb_desc
,
505 struct ieee80211_tx_info
*info
)
507 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
508 u8 rate_flag
= info
->control
.rates
[0].flags
;
509 u8 sgi_40
= 0, sgi_20
= 0, bw_40
= 0;
510 tcb_desc
->use_shortgi
= false;
515 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
516 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
518 if (!(sta
->ht_cap
.ht_supported
))
521 if (!sgi_40
&& !sgi_20
)
524 if (mac
->opmode
== NL80211_IFTYPE_STATION
)
526 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
527 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
528 bw_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
531 tcb_desc
->use_shortgi
= true;
532 else if ((bw_40
== false) && sgi_20
)
533 tcb_desc
->use_shortgi
= true;
535 if (!(rate_flag
& IEEE80211_TX_RC_SHORT_GI
))
536 tcb_desc
->use_shortgi
= false;
539 static void _rtl_query_protection_mode(struct ieee80211_hw
*hw
,
540 struct rtl_tcb_desc
*tcb_desc
,
541 struct ieee80211_tx_info
*info
)
543 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
544 u8 rate_flag
= info
->control
.rates
[0].flags
;
546 /* Common Settings */
547 tcb_desc
->rts_stbc
= false;
548 tcb_desc
->cts_enable
= false;
549 tcb_desc
->rts_sc
= 0;
550 tcb_desc
->rts_bw
= false;
551 tcb_desc
->rts_use_shortpreamble
= false;
552 tcb_desc
->rts_use_shortgi
= false;
554 if (rate_flag
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
555 /* Use CTS-to-SELF in protection mode. */
556 tcb_desc
->rts_enable
= true;
557 tcb_desc
->cts_enable
= true;
558 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
559 } else if (rate_flag
& IEEE80211_TX_RC_USE_RTS_CTS
) {
560 /* Use RTS-CTS in protection mode. */
561 tcb_desc
->rts_enable
= true;
562 tcb_desc
->rts_rate
= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE24M
];
566 static void _rtl_txrate_selectmode(struct ieee80211_hw
*hw
,
567 struct ieee80211_sta
*sta
,
568 struct rtl_tcb_desc
*tcb_desc
)
570 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
571 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
572 struct rtl_sta_info
*sta_entry
= NULL
;
576 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
577 ratr_index
= sta_entry
->ratr_index
;
579 if (!tcb_desc
->disable_ratefallback
|| !tcb_desc
->use_driver_rate
) {
580 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
581 tcb_desc
->ratr_index
= 0;
582 } else if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
583 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
) {
585 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE2M
];
586 tcb_desc
->use_driver_rate
= 1;
590 tcb_desc
->ratr_index
= ratr_index
;
591 } else if (mac
->opmode
== NL80211_IFTYPE_AP
) {
592 tcb_desc
->ratr_index
= ratr_index
;
596 if (rtlpriv
->dm
.useramask
) {
597 /* TODO we will differentiate adhoc and station futrue */
598 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
599 tcb_desc
->mac_id
= 0;
601 if (mac
->mode
== WIRELESS_MODE_N_24G
)
602 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NGB
;
603 else if (mac
->mode
== WIRELESS_MODE_N_5G
)
604 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_NG
;
605 else if (mac
->mode
& WIRELESS_MODE_G
)
606 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_GB
;
607 else if (mac
->mode
& WIRELESS_MODE_B
)
608 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_B
;
609 else if (mac
->mode
& WIRELESS_MODE_A
)
610 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_G
;
611 } else if (mac
->opmode
== NL80211_IFTYPE_AP
||
612 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
615 tcb_desc
->mac_id
= sta
->aid
+ 1;
617 tcb_desc
->mac_id
= 1;
619 tcb_desc
->mac_id
= 0;
626 static void _rtl_query_bandwidth_mode(struct ieee80211_hw
*hw
,
627 struct ieee80211_sta
*sta
,
628 struct rtl_tcb_desc
*tcb_desc
)
630 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
631 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
633 tcb_desc
->packet_bw
= false;
636 if (mac
->opmode
== NL80211_IFTYPE_AP
||
637 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
638 if (!(sta
->ht_cap
.ht_supported
) ||
639 !(sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
))
641 } else if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
642 if (!mac
->bw_40
|| !(sta
->ht_cap
.ht_supported
))
645 if (tcb_desc
->multicast
|| tcb_desc
->broadcast
)
648 /*use legency rate, shall use 20MHz */
649 if (tcb_desc
->hw_rate
<= rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
])
652 tcb_desc
->packet_bw
= true;
655 static u8
_rtl_get_highest_n_rate(struct ieee80211_hw
*hw
)
657 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
658 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
661 if (get_rf_type(rtlphy
) == RF_2T2R
)
662 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS15
];
664 hw_rate
= rtlpriv
->cfg
->maps
[RTL_RC_HT_RATEMCS7
];
669 /* mac80211's rate_idx is like this:
671 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
674 * (rx_status->flag & RX_FLAG_HT) = 0,
675 * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11,
678 * (rx_status->flag & RX_FLAG_HT) = 1,
679 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
681 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
683 * (rx_status->flag & RX_FLAG_HT) = 0,
684 * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7,
687 * (rx_status->flag & RX_FLAG_HT) = 1,
688 * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15
690 int rtlwifi_rate_mapping(struct ieee80211_hw
*hw
,
691 bool isht
, u8 desc_rate
, bool first_ampdu
)
696 if (IEEE80211_BAND_2GHZ
== hw
->conf
.channel
->band
) {
704 case DESC92_RATE5_5M
:
773 case DESC92_RATEMCS0
:
776 case DESC92_RATEMCS1
:
779 case DESC92_RATEMCS2
:
782 case DESC92_RATEMCS3
:
785 case DESC92_RATEMCS4
:
788 case DESC92_RATEMCS5
:
791 case DESC92_RATEMCS6
:
794 case DESC92_RATEMCS7
:
797 case DESC92_RATEMCS8
:
800 case DESC92_RATEMCS9
:
803 case DESC92_RATEMCS10
:
806 case DESC92_RATEMCS11
:
809 case DESC92_RATEMCS12
:
812 case DESC92_RATEMCS13
:
815 case DESC92_RATEMCS14
:
818 case DESC92_RATEMCS15
:
828 EXPORT_SYMBOL(rtlwifi_rate_mapping
);
830 void rtl_get_tcb_desc(struct ieee80211_hw
*hw
,
831 struct ieee80211_tx_info
*info
,
832 struct ieee80211_sta
*sta
,
833 struct sk_buff
*skb
, struct rtl_tcb_desc
*tcb_desc
)
835 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
836 struct rtl_mac
*rtlmac
= rtl_mac(rtl_priv(hw
));
837 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
838 struct ieee80211_rate
*txrate
;
839 __le16 fc
= hdr
->frame_control
;
841 txrate
= ieee80211_get_tx_rate(hw
, info
);
842 tcb_desc
->hw_rate
= txrate
->hw_value
;
844 if (ieee80211_is_data(fc
)) {
846 *we set data rate INX 0
847 *in rtl_rc.c if skb is special data or
848 *mgt which need low data rate.
852 *So tcb_desc->hw_rate is just used for
853 *special data and mgt frames
855 if (info
->control
.rates
[0].idx
== 0 ||
856 ieee80211_is_nullfunc(fc
)) {
857 tcb_desc
->use_driver_rate
= true;
858 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
860 tcb_desc
->disable_ratefallback
= 1;
863 *because hw will nerver use hw_rate
864 *when tcb_desc->use_driver_rate = false
865 *so we never set highest N rate here,
866 *and N rate will all be controlled by FW
867 *when tcb_desc->use_driver_rate = false
869 if (sta
&& (sta
->ht_cap
.ht_supported
)) {
870 tcb_desc
->hw_rate
= _rtl_get_highest_n_rate(hw
);
872 if (rtlmac
->mode
== WIRELESS_MODE_B
) {
874 rtlpriv
->cfg
->maps
[RTL_RC_CCK_RATE11M
];
877 rtlpriv
->cfg
->maps
[RTL_RC_OFDM_RATE54M
];
882 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
)))
883 tcb_desc
->multicast
= 1;
884 else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
885 tcb_desc
->broadcast
= 1;
887 _rtl_txrate_selectmode(hw
, sta
, tcb_desc
);
888 _rtl_query_bandwidth_mode(hw
, sta
, tcb_desc
);
889 _rtl_qurey_shortpreamble_mode(hw
, tcb_desc
, info
);
890 _rtl_query_shortgi(hw
, sta
, tcb_desc
, info
);
891 _rtl_query_protection_mode(hw
, tcb_desc
, info
);
893 tcb_desc
->use_driver_rate
= true;
894 tcb_desc
->ratr_index
= RATR_INX_WIRELESS_MC
;
895 tcb_desc
->disable_ratefallback
= 1;
896 tcb_desc
->mac_id
= 0;
897 tcb_desc
->packet_bw
= false;
900 EXPORT_SYMBOL(rtl_get_tcb_desc
);
902 bool rtl_action_proc(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
904 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
905 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
906 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
907 __le16 fc
= hdr
->frame_control
;
908 u8
*act
= (u8
*) (((u8
*) skb
->data
+ MAC80211_3ADDR_LEN
));
911 if (!ieee80211_is_action(fc
))
920 if (mac
->act_scanning
)
923 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
924 ("%s ACT_ADDBAREQ From :%pM\n",
925 is_tx
? "Tx" : "Rx", hdr
->addr2
));
928 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
929 ("%s ACT_ADDBARSP From :%pM\n",
930 is_tx
? "Tx" : "Rx", hdr
->addr2
));
933 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
934 ("ACT_ADDBADEL From :%pM\n", hdr
->addr2
));
945 /*should call before software enc*/
946 u8
rtl_is_special_data(struct ieee80211_hw
*hw
, struct sk_buff
*skb
, u8 is_tx
)
948 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
949 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
950 __le16 fc
= rtl_get_fc(skb
);
952 u8 mac_hdr_len
= ieee80211_get_hdrlen_from_skb(skb
);
953 const struct iphdr
*ip
;
955 if (!ieee80211_is_data(fc
))
959 ip
= (struct iphdr
*)((u8
*) skb
->data
+ mac_hdr_len
+
960 SNAP_SIZE
+ PROTOC_TYPE_SIZE
);
961 ether_type
= *(u16
*) ((u8
*) skb
->data
+ mac_hdr_len
+ SNAP_SIZE
);
962 /* ether_type = ntohs(ether_type); */
964 if (ETH_P_IP
== ether_type
) {
965 if (IPPROTO_UDP
== ip
->protocol
) {
966 struct udphdr
*udp
= (struct udphdr
*)((u8
*) ip
+
968 if (((((u8
*) udp
)[1] == 68) &&
969 (((u8
*) udp
)[3] == 67)) ||
970 ((((u8
*) udp
)[1] == 67) &&
971 (((u8
*) udp
)[3] == 68))) {
973 * 68 : UDP BOOTP client
974 * 67 : UDP BOOTP server
976 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
),
977 DBG_DMESG
, ("dhcp %s !!\n",
978 (is_tx
) ? "Tx" : "Rx"));
982 ppsc
->last_delaylps_stamp_jiffies
=
989 } else if (ETH_P_ARP
== ether_type
) {
992 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
996 } else if (ETH_P_PAE
== ether_type
) {
997 RT_TRACE(rtlpriv
, (COMP_SEND
| COMP_RECV
), DBG_DMESG
,
998 ("802.1X %s EAPOL pkt!!\n", (is_tx
) ? "Tx" : "Rx"));
1002 ppsc
->last_delaylps_stamp_jiffies
= jiffies
;
1006 } else if (ETH_P_IPV6
== ether_type
) {
1014 /*********************************************************
1016 * functions called by core.c
1018 *********************************************************/
1019 int rtl_tx_agg_start(struct ieee80211_hw
*hw
,
1020 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1022 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1023 struct rtl_tid_data
*tid_data
;
1024 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1025 struct rtl_sta_info
*sta_entry
= NULL
;
1030 if (unlikely(tid
>= MAX_TID_COUNT
))
1033 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1036 tid_data
= &sta_entry
->tids
[tid
];
1038 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1039 ("on ra = %pM tid = %d seq:%d\n", sta
->addr
, tid
,
1040 tid_data
->seq_number
));
1042 *ssn
= tid_data
->seq_number
;
1043 tid_data
->agg
.agg_state
= RTL_AGG_START
;
1045 ieee80211_start_tx_ba_cb_irqsafe(mac
->vif
, sta
->addr
, tid
);
1050 int rtl_tx_agg_stop(struct ieee80211_hw
*hw
,
1051 struct ieee80211_sta
*sta
, u16 tid
)
1053 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1054 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1055 struct rtl_sta_info
*sta_entry
= NULL
;
1061 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("ra = NULL\n"));
1065 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1066 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1068 if (unlikely(tid
>= MAX_TID_COUNT
))
1071 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1072 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_STOP
;
1074 ieee80211_stop_tx_ba_cb_irqsafe(mac
->vif
, sta
->addr
, tid
);
1079 int rtl_tx_agg_oper(struct ieee80211_hw
*hw
,
1080 struct ieee80211_sta
*sta
, u16 tid
)
1082 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1083 struct rtl_sta_info
*sta_entry
= NULL
;
1089 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("ra = NULL\n"));
1093 RT_TRACE(rtlpriv
, COMP_SEND
, DBG_DMESG
,
1094 ("on ra = %pM tid = %d\n", sta
->addr
, tid
));
1096 if (unlikely(tid
>= MAX_TID_COUNT
))
1099 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1100 sta_entry
->tids
[tid
].agg
.agg_state
= RTL_AGG_OPERATIONAL
;
1105 /*********************************************************
1107 * wq & timer callback functions
1109 *********************************************************/
1110 void rtl_watchdog_wq_callback(void *data
)
1112 struct rtl_works
*rtlworks
= container_of_dwork_rtl(data
,
1115 struct ieee80211_hw
*hw
= rtlworks
->hw
;
1116 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1117 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1118 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1119 bool busytraffic
= false;
1120 bool higher_busytraffic
= false;
1121 bool higher_busyrxtraffic
= false;
1123 u32 rx_cnt_inp4eriod
= 0;
1124 u32 tx_cnt_inp4eriod
= 0;
1125 u32 aver_rx_cnt_inperiod
= 0;
1126 u32 aver_tx_cnt_inperiod
= 0;
1127 u32 aver_tidtx_inperiod
[MAX_TID_COUNT
] = {0};
1128 u32 tidtx_inp4eriod
[MAX_TID_COUNT
] = {0};
1129 bool enter_ps
= false;
1131 if (is_hal_stop(rtlhal
))
1134 /* <1> Determine if action frame is allowed */
1135 if (mac
->link_state
> MAC80211_NOLINK
) {
1136 if (mac
->cnt_after_linked
< 20)
1137 mac
->cnt_after_linked
++;
1139 mac
->cnt_after_linked
= 0;
1143 *<2> to check if traffic busy, if
1144 * busytraffic we don't change channel
1146 if (mac
->link_state
>= MAC80211_LINKED
) {
1148 /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */
1149 for (idx
= 0; idx
<= 2; idx
++) {
1150 rtlpriv
->link_info
.num_rx_in4period
[idx
] =
1151 rtlpriv
->link_info
.num_rx_in4period
[idx
+ 1];
1152 rtlpriv
->link_info
.num_tx_in4period
[idx
] =
1153 rtlpriv
->link_info
.num_tx_in4period
[idx
+ 1];
1155 rtlpriv
->link_info
.num_rx_in4period
[3] =
1156 rtlpriv
->link_info
.num_rx_inperiod
;
1157 rtlpriv
->link_info
.num_tx_in4period
[3] =
1158 rtlpriv
->link_info
.num_tx_inperiod
;
1159 for (idx
= 0; idx
<= 3; idx
++) {
1161 rtlpriv
->link_info
.num_rx_in4period
[idx
];
1163 rtlpriv
->link_info
.num_tx_in4period
[idx
];
1165 aver_rx_cnt_inperiod
= rx_cnt_inp4eriod
/ 4;
1166 aver_tx_cnt_inperiod
= tx_cnt_inp4eriod
/ 4;
1168 /* (2) check traffic busy */
1169 if (aver_rx_cnt_inperiod
> 100 || aver_tx_cnt_inperiod
> 100)
1172 /* Higher Tx/Rx data. */
1173 if (aver_rx_cnt_inperiod
> 4000 ||
1174 aver_tx_cnt_inperiod
> 4000) {
1175 higher_busytraffic
= true;
1177 /* Extremely high Rx data. */
1178 if (aver_rx_cnt_inperiod
> 5000)
1179 higher_busyrxtraffic
= true;
1182 /* check every tid's tx traffic */
1183 for (tid
= 0; tid
<= 7; tid
++) {
1184 for (idx
= 0; idx
<= 2; idx
++)
1185 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
] =
1186 rtlpriv
->link_info
.tidtx_in4period
[tid
]
1188 rtlpriv
->link_info
.tidtx_in4period
[tid
][3] =
1189 rtlpriv
->link_info
.tidtx_inperiod
[tid
];
1191 for (idx
= 0; idx
<= 3; idx
++)
1192 tidtx_inp4eriod
[tid
] +=
1193 rtlpriv
->link_info
.tidtx_in4period
[tid
][idx
];
1194 aver_tidtx_inperiod
[tid
] = tidtx_inp4eriod
[tid
] / 4;
1195 if (aver_tidtx_inperiod
[tid
] > 5000)
1196 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1199 rtlpriv
->link_info
.higher_busytxtraffic
[tid
] =
1203 if (((rtlpriv
->link_info
.num_rx_inperiod
+
1204 rtlpriv
->link_info
.num_tx_inperiod
) > 8) ||
1205 (rtlpriv
->link_info
.num_rx_inperiod
> 2))
1210 /* LeisurePS only work in infra mode. */
1217 rtlpriv
->link_info
.num_rx_inperiod
= 0;
1218 rtlpriv
->link_info
.num_tx_inperiod
= 0;
1219 for (tid
= 0; tid
<= 7; tid
++)
1220 rtlpriv
->link_info
.tidtx_inperiod
[tid
] = 0;
1222 rtlpriv
->link_info
.busytraffic
= busytraffic
;
1223 rtlpriv
->link_info
.higher_busytraffic
= higher_busytraffic
;
1224 rtlpriv
->link_info
.higher_busyrxtraffic
= higher_busyrxtraffic
;
1227 rtlpriv
->cfg
->ops
->dm_watchdog(hw
);
1230 void rtl_watch_dog_timer_callback(unsigned long data
)
1232 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*)data
;
1233 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1235 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
1236 &rtlpriv
->works
.watchdog_wq
, 0);
1238 mod_timer(&rtlpriv
->works
.watchdog_timer
,
1239 jiffies
+ MSECS(RTL_WATCH_DOG_TIME
));
1242 /*********************************************************
1244 * frame process functions
1246 *********************************************************/
1247 u8
*rtl_find_ie(u8
*data
, unsigned int len
, u8 ie
)
1249 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1252 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1255 if (pos
+ 2 + pos
[1] > end
)
1266 /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */
1267 /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */
1268 static struct sk_buff
*rtl_make_smps_action(struct ieee80211_hw
*hw
,
1269 enum ieee80211_smps_mode smps
, u8
*da
, u8
*bssid
)
1271 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1272 struct sk_buff
*skb
;
1273 struct ieee80211_mgmt
*action_frame
;
1275 /* 27 = header + category + action + smps mode */
1276 skb
= dev_alloc_skb(27 + hw
->extra_tx_headroom
);
1280 skb_reserve(skb
, hw
->extra_tx_headroom
);
1281 action_frame
= (void *)skb_put(skb
, 27);
1282 memset(action_frame
, 0, 27);
1283 memcpy(action_frame
->da
, da
, ETH_ALEN
);
1284 memcpy(action_frame
->sa
, rtlefuse
->dev_addr
, ETH_ALEN
);
1285 memcpy(action_frame
->bssid
, bssid
, ETH_ALEN
);
1286 action_frame
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
1287 IEEE80211_STYPE_ACTION
);
1288 action_frame
->u
.action
.category
= WLAN_CATEGORY_HT
;
1289 action_frame
->u
.action
.u
.ht_smps
.action
= WLAN_HT_ACTION_SMPS
;
1291 case IEEE80211_SMPS_AUTOMATIC
:/* 0 */
1292 case IEEE80211_SMPS_NUM_MODES
:/* 4 */
1294 case IEEE80211_SMPS_OFF
:/* 1 */ /*MIMO_PS_NOLIMIT*/
1295 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1296 WLAN_HT_SMPS_CONTROL_DISABLED
;/* 0 */
1298 case IEEE80211_SMPS_STATIC
:/* 2 */ /*MIMO_PS_STATIC*/
1299 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1300 WLAN_HT_SMPS_CONTROL_STATIC
;/* 1 */
1302 case IEEE80211_SMPS_DYNAMIC
:/* 3 */ /*MIMO_PS_DYNAMIC*/
1303 action_frame
->u
.action
.u
.ht_smps
.smps_control
=
1304 WLAN_HT_SMPS_CONTROL_DYNAMIC
;/* 3 */
1311 int rtl_send_smps_action(struct ieee80211_hw
*hw
,
1312 struct ieee80211_sta
*sta
, u8
*da
, u8
*bssid
,
1313 enum ieee80211_smps_mode smps
)
1315 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1316 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1317 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1318 struct sk_buff
*skb
= rtl_make_smps_action(hw
, smps
, da
, bssid
);
1319 struct rtl_tcb_desc tcb_desc
;
1320 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1322 if (rtlpriv
->mac80211
.act_scanning
)
1328 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
1331 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1334 /* this is a type = mgmt * stype = action frame */
1336 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1337 struct rtl_sta_info
*sta_entry
=
1338 (struct rtl_sta_info
*) sta
->drv_priv
;
1339 sta_entry
->mimo_ps
= smps
;
1340 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
1342 info
->control
.rates
[0].idx
= 0;
1343 info
->control
.sta
= sta
;
1344 info
->band
= hw
->conf
.channel
->band
;
1345 rtlpriv
->intf_ops
->adapter_tx(hw
, skb
, &tcb_desc
);
1351 /*********************************************************
1355 *********************************************************/
1356 static bool rtl_chk_vendor_ouisub(struct ieee80211_hw
*hw
,
1357 struct octet_string vendor_ie
)
1359 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1360 bool matched
= false;
1361 static u8 athcap_1
[] = { 0x00, 0x03, 0x7F };
1362 static u8 athcap_2
[] = { 0x00, 0x13, 0x74 };
1363 static u8 broadcap_1
[] = { 0x00, 0x10, 0x18 };
1364 static u8 broadcap_2
[] = { 0x00, 0x0a, 0xf7 };
1365 static u8 broadcap_3
[] = { 0x00, 0x05, 0xb5 };
1366 static u8 racap
[] = { 0x00, 0x0c, 0x43 };
1367 static u8 ciscocap
[] = { 0x00, 0x40, 0x96 };
1368 static u8 marvcap
[] = { 0x00, 0x50, 0x43 };
1370 if (memcmp(vendor_ie
.octet
, athcap_1
, 3) == 0 ||
1371 memcmp(vendor_ie
.octet
, athcap_2
, 3) == 0) {
1372 rtlpriv
->mac80211
.vendor
= PEER_ATH
;
1374 } else if (memcmp(vendor_ie
.octet
, broadcap_1
, 3) == 0 ||
1375 memcmp(vendor_ie
.octet
, broadcap_2
, 3) == 0 ||
1376 memcmp(vendor_ie
.octet
, broadcap_3
, 3) == 0) {
1377 rtlpriv
->mac80211
.vendor
= PEER_BROAD
;
1379 } else if (memcmp(vendor_ie
.octet
, racap
, 3) == 0) {
1380 rtlpriv
->mac80211
.vendor
= PEER_RAL
;
1382 } else if (memcmp(vendor_ie
.octet
, ciscocap
, 3) == 0) {
1383 rtlpriv
->mac80211
.vendor
= PEER_CISCO
;
1385 } else if (memcmp(vendor_ie
.octet
, marvcap
, 3) == 0) {
1386 rtlpriv
->mac80211
.vendor
= PEER_MARV
;
1393 static bool rtl_find_221_ie(struct ieee80211_hw
*hw
, u8
*data
,
1396 struct ieee80211_mgmt
*mgmt
= (void *)data
;
1397 struct octet_string vendor_ie
;
1400 pos
= (u8
*)mgmt
->u
.beacon
.variable
;
1403 if (pos
[0] == 221) {
1404 vendor_ie
.length
= pos
[1];
1405 vendor_ie
.octet
= &pos
[2];
1406 if (rtl_chk_vendor_ouisub(hw
, vendor_ie
))
1410 if (pos
+ 2 + pos
[1] > end
)
1418 void rtl_recognize_peer(struct ieee80211_hw
*hw
, u8
*data
, unsigned int len
)
1420 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1421 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1422 struct ieee80211_hdr
*hdr
= (void *)data
;
1423 u32 vendor
= PEER_UNKNOWN
;
1425 static u8 ap3_1
[3] = { 0x00, 0x14, 0xbf };
1426 static u8 ap3_2
[3] = { 0x00, 0x1a, 0x70 };
1427 static u8 ap3_3
[3] = { 0x00, 0x1d, 0x7e };
1428 static u8 ap4_1
[3] = { 0x00, 0x90, 0xcc };
1429 static u8 ap4_2
[3] = { 0x00, 0x0e, 0x2e };
1430 static u8 ap4_3
[3] = { 0x00, 0x18, 0x02 };
1431 static u8 ap4_4
[3] = { 0x00, 0x17, 0x3f };
1432 static u8 ap4_5
[3] = { 0x00, 0x1c, 0xdf };
1433 static u8 ap5_1
[3] = { 0x00, 0x1c, 0xf0 };
1434 static u8 ap5_2
[3] = { 0x00, 0x21, 0x91 };
1435 static u8 ap5_3
[3] = { 0x00, 0x24, 0x01 };
1436 static u8 ap5_4
[3] = { 0x00, 0x15, 0xe9 };
1437 static u8 ap5_5
[3] = { 0x00, 0x17, 0x9A };
1438 static u8 ap5_6
[3] = { 0x00, 0x18, 0xE7 };
1439 static u8 ap6_1
[3] = { 0x00, 0x17, 0x94 };
1440 static u8 ap7_1
[3] = { 0x00, 0x14, 0xa4 };
1442 if (mac
->opmode
!= NL80211_IFTYPE_STATION
)
1445 if (mac
->link_state
== MAC80211_NOLINK
) {
1446 mac
->vendor
= PEER_UNKNOWN
;
1450 if (mac
->cnt_after_linked
> 2)
1453 /* check if this really is a beacon */
1454 if (!ieee80211_is_beacon(hdr
->frame_control
))
1457 /* min. beacon length + FCS_LEN */
1458 if (len
<= 40 + FCS_LEN
)
1461 /* and only beacons from the associated BSSID, please */
1462 if (compare_ether_addr(hdr
->addr3
, rtlpriv
->mac80211
.bssid
))
1465 if (rtl_find_221_ie(hw
, data
, len
))
1466 vendor
= mac
->vendor
;
1468 if ((memcmp(mac
->bssid
, ap5_1
, 3) == 0) ||
1469 (memcmp(mac
->bssid
, ap5_2
, 3) == 0) ||
1470 (memcmp(mac
->bssid
, ap5_3
, 3) == 0) ||
1471 (memcmp(mac
->bssid
, ap5_4
, 3) == 0) ||
1472 (memcmp(mac
->bssid
, ap5_5
, 3) == 0) ||
1473 (memcmp(mac
->bssid
, ap5_6
, 3) == 0) ||
1474 vendor
== PEER_ATH
) {
1476 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>ath find\n"));
1477 } else if ((memcmp(mac
->bssid
, ap4_4
, 3) == 0) ||
1478 (memcmp(mac
->bssid
, ap4_5
, 3) == 0) ||
1479 (memcmp(mac
->bssid
, ap4_1
, 3) == 0) ||
1480 (memcmp(mac
->bssid
, ap4_2
, 3) == 0) ||
1481 (memcmp(mac
->bssid
, ap4_3
, 3) == 0) ||
1482 vendor
== PEER_RAL
) {
1483 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>ral findn\n"));
1485 } else if (memcmp(mac
->bssid
, ap6_1
, 3) == 0 ||
1486 vendor
== PEER_CISCO
) {
1487 vendor
= PEER_CISCO
;
1488 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>cisco find\n"));
1489 } else if ((memcmp(mac
->bssid
, ap3_1
, 3) == 0) ||
1490 (memcmp(mac
->bssid
, ap3_2
, 3) == 0) ||
1491 (memcmp(mac
->bssid
, ap3_3
, 3) == 0) ||
1492 vendor
== PEER_BROAD
) {
1493 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>broad find\n"));
1494 vendor
= PEER_BROAD
;
1495 } else if (memcmp(mac
->bssid
, ap7_1
, 3) == 0 ||
1496 vendor
== PEER_MARV
) {
1498 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, ("=>marv find\n"));
1501 mac
->vendor
= vendor
;
1504 /*********************************************************
1508 *********************************************************/
1509 static ssize_t
rtl_show_debug_level(struct device
*d
,
1510 struct device_attribute
*attr
, char *buf
)
1512 struct ieee80211_hw
*hw
= dev_get_drvdata(d
);
1513 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1515 return sprintf(buf
, "0x%08X\n", rtlpriv
->dbg
.global_debuglevel
);
1518 static ssize_t
rtl_store_debug_level(struct device
*d
,
1519 struct device_attribute
*attr
,
1520 const char *buf
, size_t count
)
1522 struct ieee80211_hw
*hw
= dev_get_drvdata(d
);
1523 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1527 ret
= strict_strtoul(buf
, 0, &val
);
1529 printk(KERN_DEBUG
"%s is not in hex or decimal form.\n", buf
);
1531 rtlpriv
->dbg
.global_debuglevel
= val
;
1532 printk(KERN_DEBUG
"debuglevel:%x\n",
1533 rtlpriv
->dbg
.global_debuglevel
);
1536 return strnlen(buf
, count
);
1539 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1540 rtl_show_debug_level
, rtl_store_debug_level
);
1542 static struct attribute
*rtl_sysfs_entries
[] = {
1544 &dev_attr_debug_level
.attr
,
1550 * "name" is folder name witch will be
1551 * put in device directory like :
1552 * sys/devices/pci0000:00/0000:00:1c.4/
1553 * 0000:06:00.0/rtl_sysfs
1555 struct attribute_group rtl_attribute_group
= {
1557 .attrs
= rtl_sysfs_entries
,
1560 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
1561 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
1562 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
1563 MODULE_LICENSE("GPL");
1564 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
1566 static int __init
rtl_core_module_init(void)
1568 if (rtl_rate_control_register())
1569 pr_err("Unable to register rtl_rc, use default RC !!\n");
1574 static void __exit
rtl_core_module_exit(void)
1577 rtl_rate_control_unregister();
1580 module_init(rtl_core_module_init
);
1581 module_exit(rtl_core_module_exit
);