1 /******************************************************************************
3 * Copyright(c) 2009-2012 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 *****************************************************************************/
35 *Finds the highest rate index we can use
36 *if skb is special data like DHCP/EAPOL, we set should
37 *it to lowest rate CCK_1M, otherwise we set rate to
38 *CCK11M or OFDM_54M based on wireless mode.
40 static u8
_rtl_rc_get_highest_rix(struct rtl_priv
*rtlpriv
,
41 struct ieee80211_sta
*sta
,
42 struct sk_buff
*skb
, bool not_data
)
44 struct rtl_mac
*rtlmac
= rtl_mac(rtlpriv
);
45 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
46 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
47 struct rtl_sta_info
*sta_entry
= NULL
;
51 *this rate is no use for true rate, firmware
52 *will control rate at all it just used for
53 *1.show in iwconfig in B/G mode
54 *2.in rtl_get_tcb_desc when we check rate is
55 * 1M we will not use FW rate but user rate.
57 if (rtlmac
->opmode
== NL80211_IFTYPE_AP
||
58 rtlmac
->opmode
== NL80211_IFTYPE_ADHOC
||
59 rtlmac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
61 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
62 wireless_mode
= sta_entry
->wireless_mode
;
67 wireless_mode
= rtlmac
->mode
;
70 if (rtl_is_special_data(rtlpriv
->mac80211
.hw
, skb
, true) ||
74 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
75 if (wireless_mode
== WIRELESS_MODE_B
) {
76 return B_MODE_MAX_RIX
;
77 } else if (wireless_mode
== WIRELESS_MODE_G
) {
78 return G_MODE_MAX_RIX
;
80 if (get_rf_type(rtlphy
) != RF_2T2R
)
81 return N_MODE_MCS7_RIX
;
83 return N_MODE_MCS15_RIX
;
86 if (wireless_mode
== WIRELESS_MODE_A
) {
87 return A_MODE_MAX_RIX
;
89 if (get_rf_type(rtlphy
) != RF_2T2R
)
90 return N_MODE_MCS7_RIX
;
92 return N_MODE_MCS15_RIX
;
98 static void _rtl_rc_rate_set_series(struct rtl_priv
*rtlpriv
,
99 struct ieee80211_sta
*sta
,
100 struct ieee80211_tx_rate
*rate
,
101 struct ieee80211_tx_rate_control
*txrc
,
102 u8 tries
, char rix
, int rtsctsenable
,
105 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
106 u8 sgi_20
= 0, sgi_40
= 0;
109 sgi_20
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
;
110 sgi_40
= sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
;
113 rate
->idx
= rix
>= 0x00 ? rix
: 0x00;
116 if (txrc
->short_preamble
)
117 rate
->flags
|= IEEE80211_TX_RC_USE_SHORT_PREAMBLE
;
118 if (mac
->opmode
== NL80211_IFTYPE_AP
||
119 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
120 if (sta
&& (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
))
121 rate
->flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
124 rate
->flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
126 if (sgi_20
|| sgi_40
)
127 rate
->flags
|= IEEE80211_TX_RC_SHORT_GI
;
128 if (sta
&& sta
->ht_cap
.ht_supported
)
129 rate
->flags
|= IEEE80211_TX_RC_MCS
;
133 static void rtl_get_rate(void *ppriv
, struct ieee80211_sta
*sta
,
134 void *priv_sta
, struct ieee80211_tx_rate_control
*txrc
)
136 struct rtl_priv
*rtlpriv
= ppriv
;
137 struct sk_buff
*skb
= txrc
->skb
;
138 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
139 struct ieee80211_tx_rate
*rates
= tx_info
->control
.rates
;
140 __le16 fc
= rtl_get_fc(skb
);
141 u8 try_per_rate
, i
, rix
;
142 bool not_data
= !ieee80211_is_data(fc
);
144 if (rate_control_send_low(sta
, priv_sta
, txrc
))
147 rix
= _rtl_rc_get_highest_rix(rtlpriv
, sta
, skb
, not_data
);
149 _rtl_rc_rate_set_series(rtlpriv
, sta
, &rates
[0], txrc
,
150 try_per_rate
, rix
, 1, not_data
);
153 for (i
= 1; i
< 4; i
++)
154 _rtl_rc_rate_set_series(rtlpriv
, sta
, &rates
[i
],
155 txrc
, i
, (rix
- i
), 1,
160 static bool _rtl_tx_aggr_check(struct rtl_priv
*rtlpriv
,
161 struct rtl_sta_info
*sta_entry
, u16 tid
)
163 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
165 if (mac
->act_scanning
)
168 if (mac
->opmode
== NL80211_IFTYPE_STATION
&&
169 mac
->cnt_after_linked
< 3)
172 if (sta_entry
->tids
[tid
].agg
.agg_state
== RTL_AGG_STOP
)
178 /*mac80211 Rate Control callbacks*/
179 static void rtl_tx_status(void *ppriv
,
180 struct ieee80211_supported_band
*sband
,
181 struct ieee80211_sta
*sta
, void *priv_sta
,
184 struct rtl_priv
*rtlpriv
= ppriv
;
185 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
186 struct ieee80211_hdr
*hdr
= rtl_get_hdr(skb
);
187 __le16 fc
= rtl_get_fc(skb
);
188 struct rtl_sta_info
*sta_entry
;
190 if (!priv_sta
|| !ieee80211_is_data(fc
))
193 if (rtl_is_special_data(mac
->hw
, skb
, true))
196 if (is_multicast_ether_addr(ieee80211_get_DA(hdr
))
197 || is_broadcast_ether_addr(ieee80211_get_DA(hdr
)))
201 /* Check if aggregation has to be enabled for this tid */
202 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
203 if ((sta
->ht_cap
.ht_supported
) &&
204 !(skb
->protocol
== cpu_to_be16(ETH_P_PAE
))) {
205 if (ieee80211_is_data_qos(fc
)) {
206 u8 tid
= rtl_get_tid(skb
);
207 if (_rtl_tx_aggr_check(rtlpriv
, sta_entry
,
209 sta_entry
->tids
[tid
].agg
.agg_state
=
211 ieee80211_start_tx_ba_session(sta
,
219 static void rtl_rate_init(void *ppriv
,
220 struct ieee80211_supported_band
*sband
,
221 struct cfg80211_chan_def
*chandef
,
222 struct ieee80211_sta
*sta
, void *priv_sta
)
226 static void *rtl_rate_alloc(struct ieee80211_hw
*hw
,
227 struct dentry
*debugfsdir
)
229 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
233 static void rtl_rate_free(void *rtlpriv
)
238 static void *rtl_rate_alloc_sta(void *ppriv
,
239 struct ieee80211_sta
*sta
, gfp_t gfp
)
241 struct rtl_priv
*rtlpriv
= ppriv
;
242 struct rtl_rate_priv
*rate_priv
;
244 rate_priv
= kzalloc(sizeof(struct rtl_rate_priv
), gfp
);
246 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
247 "Unable to allocate private rc structure\n");
251 rtlpriv
->rate_priv
= rate_priv
;
256 static void rtl_rate_free_sta(void *rtlpriv
,
257 struct ieee80211_sta
*sta
, void *priv_sta
)
259 struct rtl_rate_priv
*rate_priv
= priv_sta
;
263 static struct rate_control_ops rtl_rate_ops
= {
266 .alloc
= rtl_rate_alloc
,
267 .free
= rtl_rate_free
,
268 .alloc_sta
= rtl_rate_alloc_sta
,
269 .free_sta
= rtl_rate_free_sta
,
270 .rate_init
= rtl_rate_init
,
271 .tx_status
= rtl_tx_status
,
272 .get_rate
= rtl_get_rate
,
275 int rtl_rate_control_register(void)
277 return ieee80211_rate_control_register(&rtl_rate_ops
);
280 void rtl_rate_control_unregister(void)
282 ieee80211_rate_control_unregister(&rtl_rate_ops
);