Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | a8d7606 | 2012-01-07 20:46:42 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * wlanfae <wlanfae@realtek.com> |
| 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 24 | * Hsinchu 300, Taiwan. |
| 25 | * |
| 26 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 30 | #include "wifi.h" |
| 31 | #include "rc.h" |
| 32 | #include "base.h" |
| 33 | #include "efuse.h" |
| 34 | #include "cam.h" |
| 35 | #include "ps.h" |
| 36 | #include "regd.h" |
| 37 | |
Larry Finger | d273bb2 | 2012-01-27 13:59:25 -0600 | [diff] [blame] | 38 | #include <linux/ip.h> |
| 39 | #include <linux/module.h> |
| 40 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 41 | /* |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 42 | *NOTICE!!!: This file will be very big, we should |
| 43 | *keep it clear under following roles: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 44 | * |
Tristan Pourcelot | e1fa746 | 2012-02-09 14:48:09 +0100 | [diff] [blame] | 45 | *This file include following parts, so, if you add new |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 46 | *functions into this file, please check which part it |
| 47 | *should includes. or check if you should add new part |
| 48 | *for this file: |
| 49 | * |
| 50 | *1) mac80211 init functions |
| 51 | *2) tx information functions |
| 52 | *3) functions called by core.c |
| 53 | *4) wq & timer callback functions |
| 54 | *5) frame process functions |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 55 | *6) IOT functions |
| 56 | *7) sysfs functions |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 57 | *8) vif functions |
| 58 | *9) ... |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 59 | */ |
| 60 | |
| 61 | /********************************************************* |
| 62 | * |
| 63 | * mac80211 init functions |
| 64 | * |
| 65 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 66 | static struct ieee80211_channel rtl_channeltable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 67 | {.center_freq = 2412, .hw_value = 1,}, |
| 68 | {.center_freq = 2417, .hw_value = 2,}, |
| 69 | {.center_freq = 2422, .hw_value = 3,}, |
| 70 | {.center_freq = 2427, .hw_value = 4,}, |
| 71 | {.center_freq = 2432, .hw_value = 5,}, |
| 72 | {.center_freq = 2437, .hw_value = 6,}, |
| 73 | {.center_freq = 2442, .hw_value = 7,}, |
| 74 | {.center_freq = 2447, .hw_value = 8,}, |
| 75 | {.center_freq = 2452, .hw_value = 9,}, |
| 76 | {.center_freq = 2457, .hw_value = 10,}, |
| 77 | {.center_freq = 2462, .hw_value = 11,}, |
| 78 | {.center_freq = 2467, .hw_value = 12,}, |
| 79 | {.center_freq = 2472, .hw_value = 13,}, |
| 80 | {.center_freq = 2484, .hw_value = 14,}, |
| 81 | }; |
| 82 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 83 | static struct ieee80211_channel rtl_channeltable_5g[] = { |
| 84 | {.center_freq = 5180, .hw_value = 36,}, |
| 85 | {.center_freq = 5200, .hw_value = 40,}, |
| 86 | {.center_freq = 5220, .hw_value = 44,}, |
| 87 | {.center_freq = 5240, .hw_value = 48,}, |
| 88 | {.center_freq = 5260, .hw_value = 52,}, |
| 89 | {.center_freq = 5280, .hw_value = 56,}, |
| 90 | {.center_freq = 5300, .hw_value = 60,}, |
| 91 | {.center_freq = 5320, .hw_value = 64,}, |
| 92 | {.center_freq = 5500, .hw_value = 100,}, |
| 93 | {.center_freq = 5520, .hw_value = 104,}, |
| 94 | {.center_freq = 5540, .hw_value = 108,}, |
| 95 | {.center_freq = 5560, .hw_value = 112,}, |
| 96 | {.center_freq = 5580, .hw_value = 116,}, |
| 97 | {.center_freq = 5600, .hw_value = 120,}, |
| 98 | {.center_freq = 5620, .hw_value = 124,}, |
| 99 | {.center_freq = 5640, .hw_value = 128,}, |
| 100 | {.center_freq = 5660, .hw_value = 132,}, |
| 101 | {.center_freq = 5680, .hw_value = 136,}, |
| 102 | {.center_freq = 5700, .hw_value = 140,}, |
| 103 | {.center_freq = 5745, .hw_value = 149,}, |
| 104 | {.center_freq = 5765, .hw_value = 153,}, |
| 105 | {.center_freq = 5785, .hw_value = 157,}, |
| 106 | {.center_freq = 5805, .hw_value = 161,}, |
| 107 | {.center_freq = 5825, .hw_value = 165,}, |
| 108 | }; |
| 109 | |
| 110 | static struct ieee80211_rate rtl_ratetable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 111 | {.bitrate = 10, .hw_value = 0x00,}, |
| 112 | {.bitrate = 20, .hw_value = 0x01,}, |
| 113 | {.bitrate = 55, .hw_value = 0x02,}, |
| 114 | {.bitrate = 110, .hw_value = 0x03,}, |
| 115 | {.bitrate = 60, .hw_value = 0x04,}, |
| 116 | {.bitrate = 90, .hw_value = 0x05,}, |
| 117 | {.bitrate = 120, .hw_value = 0x06,}, |
| 118 | {.bitrate = 180, .hw_value = 0x07,}, |
| 119 | {.bitrate = 240, .hw_value = 0x08,}, |
| 120 | {.bitrate = 360, .hw_value = 0x09,}, |
| 121 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 122 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 123 | }; |
| 124 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 125 | static struct ieee80211_rate rtl_ratetable_5g[] = { |
| 126 | {.bitrate = 60, .hw_value = 0x04,}, |
| 127 | {.bitrate = 90, .hw_value = 0x05,}, |
| 128 | {.bitrate = 120, .hw_value = 0x06,}, |
| 129 | {.bitrate = 180, .hw_value = 0x07,}, |
| 130 | {.bitrate = 240, .hw_value = 0x08,}, |
| 131 | {.bitrate = 360, .hw_value = 0x09,}, |
| 132 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 133 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 134 | }; |
| 135 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 136 | static const struct ieee80211_supported_band rtl_band_2ghz = { |
| 137 | .band = IEEE80211_BAND_2GHZ, |
| 138 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 139 | .channels = rtl_channeltable_2g, |
| 140 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 141 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 142 | .bitrates = rtl_ratetable_2g, |
| 143 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 144 | |
| 145 | .ht_cap = {0}, |
| 146 | }; |
| 147 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 148 | static struct ieee80211_supported_band rtl_band_5ghz = { |
| 149 | .band = IEEE80211_BAND_5GHZ, |
| 150 | |
| 151 | .channels = rtl_channeltable_5g, |
| 152 | .n_channels = ARRAY_SIZE(rtl_channeltable_5g), |
| 153 | |
| 154 | .bitrates = rtl_ratetable_5g, |
| 155 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), |
| 156 | |
| 157 | .ht_cap = {0}, |
| 158 | }; |
| 159 | |
| 160 | static const u8 tid_to_ac[] = { |
| 161 | 2, /* IEEE80211_AC_BE */ |
| 162 | 3, /* IEEE80211_AC_BK */ |
| 163 | 3, /* IEEE80211_AC_BK */ |
| 164 | 2, /* IEEE80211_AC_BE */ |
| 165 | 1, /* IEEE80211_AC_VI */ |
| 166 | 1, /* IEEE80211_AC_VI */ |
| 167 | 0, /* IEEE80211_AC_VO */ |
| 168 | 0, /* IEEE80211_AC_VO */ |
| 169 | }; |
| 170 | |
Larry Finger | 2a00def | 2012-07-11 14:32:33 -0500 | [diff] [blame] | 171 | u8 rtl_tid_to_ac(u8 tid) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 172 | { |
| 173 | return tid_to_ac[tid]; |
| 174 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 175 | EXPORT_SYMBOL_GPL(rtl_tid_to_ac); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 176 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 177 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, |
| 178 | struct ieee80211_sta_ht_cap *ht_cap) |
| 179 | { |
| 180 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 181 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 182 | |
| 183 | ht_cap->ht_supported = true; |
| 184 | ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 185 | IEEE80211_HT_CAP_SGI_40 | |
| 186 | IEEE80211_HT_CAP_SGI_20 | |
| 187 | IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; |
| 188 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 189 | if (rtlpriv->rtlhal.disable_amsdu_8k) |
| 190 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; |
| 191 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 192 | /* |
| 193 | *Maximum length of AMPDU that the STA can receive. |
| 194 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) |
| 195 | */ |
| 196 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 197 | |
| 198 | /*Minimum MPDU start spacing , */ |
| 199 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 200 | |
| 201 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 202 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 203 | /*hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 204 | *base on ant_num |
| 205 | *rx_mask: RX mask |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 206 | *if rx_ant = 1 rx_mask[0]= 0xff;==>MCS0-MCS7 |
| 207 | *if rx_ant = 2 rx_mask[1]= 0xff;==>MCS8-MCS15 |
| 208 | *if rx_ant >= 3 rx_mask[2]= 0xff; |
| 209 | *if BW_40 rx_mask[4]= 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 210 | *highest supported RX rate |
| 211 | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 212 | if (rtlpriv->dm.supp_phymode_switch) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 213 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 214 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, |
| 215 | "Support phy mode switch\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 216 | |
| 217 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 218 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 219 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 220 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 221 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 222 | } else { |
| 223 | if (get_rf_type(rtlphy) == RF_1T2R || |
| 224 | get_rf_type(rtlphy) == RF_2T2R) { |
| 225 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 226 | "1T2R or 2T2R\n"); |
| 227 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 228 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 229 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 230 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 231 | ht_cap->mcs.rx_highest = |
| 232 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
| 233 | } else if (get_rf_type(rtlphy) == RF_1T1R) { |
| 234 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 235 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 236 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 237 | ht_cap->mcs.rx_mask[1] = 0x00; |
| 238 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 239 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 240 | ht_cap->mcs.rx_highest = |
| 241 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
| 242 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
| 247 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 248 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 249 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 250 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 251 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 252 | struct ieee80211_supported_band *sband; |
| 253 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 254 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 255 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset == |
| 256 | BAND_ON_BOTH) { |
| 257 | /* 1: 2.4 G bands */ |
| 258 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 259 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 260 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 261 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 262 | * to default value(1T1R) */ |
| 263 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz, |
| 264 | sizeof(struct ieee80211_supported_band)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 265 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 266 | /* <3> init ht cap base on ant_num */ |
| 267 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 268 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 269 | /* <4> set mac->sband to wiphy->sband */ |
| 270 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 271 | |
| 272 | /* 2: 5 G bands */ |
| 273 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 274 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 275 | |
| 276 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 277 | * to default value(1T1R) */ |
| 278 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz, |
| 279 | sizeof(struct ieee80211_supported_band)); |
| 280 | |
| 281 | /* <3> init ht cap base on ant_num */ |
| 282 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 283 | |
| 284 | /* <4> set mac->sband to wiphy->sband */ |
| 285 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 286 | } else { |
| 287 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 288 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 289 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
| 290 | |
| 291 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 292 | * to default value(1T1R) */ |
| 293 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), |
| 294 | &rtl_band_2ghz, |
| 295 | sizeof(struct ieee80211_supported_band)); |
| 296 | |
| 297 | /* <3> init ht cap base on ant_num */ |
| 298 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 299 | |
| 300 | /* <4> set mac->sband to wiphy->sband */ |
| 301 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 302 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 303 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 304 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 305 | |
| 306 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 307 | * to default value(1T1R) */ |
| 308 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), |
| 309 | &rtl_band_5ghz, |
| 310 | sizeof(struct ieee80211_supported_band)); |
| 311 | |
| 312 | /* <3> init ht cap base on ant_num */ |
| 313 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 314 | |
| 315 | /* <4> set mac->sband to wiphy->sband */ |
| 316 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 317 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 318 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n", |
| 319 | rtlhal->current_bandtype); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 320 | } |
| 321 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 322 | /* <5> set hw caps */ |
| 323 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 324 | IEEE80211_HW_RX_INCLUDES_FCS | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 325 | IEEE80211_HW_AMPDU_AGGREGATION | |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 326 | IEEE80211_HW_CONNECTION_MONITOR | |
| 327 | /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 328 | IEEE80211_HW_CONNECTION_MONITOR | |
| 329 | IEEE80211_HW_MFP_CAPABLE | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 330 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0; |
| 331 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 332 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
| 333 | if (rtlpriv->psc.swctrl_lps) |
| 334 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
| 335 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 336 | /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */ |
| 337 | 0; |
| 338 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 339 | hw->wiphy->interface_modes = |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 340 | BIT(NL80211_IFTYPE_AP) | |
| 341 | BIT(NL80211_IFTYPE_STATION) | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 342 | BIT(NL80211_IFTYPE_ADHOC) | |
| 343 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 344 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 345 | BIT(NL80211_IFTYPE_P2P_GO); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 347 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 348 | hw->wiphy->rts_threshold = 2347; |
| 349 | |
| 350 | hw->queues = AC_MAX; |
| 351 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; |
| 352 | |
| 353 | /* TODO: Correct this value for our hw */ |
| 354 | /* TODO: define these hard code value */ |
| 355 | hw->channel_change_time = 100; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 356 | hw->max_listen_interval = 10; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 357 | hw->max_rate_tries = 4; |
| 358 | /* hw->max_rates = 1; */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 359 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 360 | |
| 361 | /* <6> mac address */ |
| 362 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { |
| 363 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); |
| 364 | } else { |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 365 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
| 366 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); |
| 367 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | } |
| 371 | |
| 372 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) |
| 373 | { |
| 374 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 375 | |
| 376 | /* <1> timer */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 377 | setup_timer(&rtlpriv->works.watchdog_timer, |
| 378 | rtl_watch_dog_timer_callback, (unsigned long)hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 379 | setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer, |
| 380 | rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 381 | |
| 382 | /* <2> work queue */ |
| 383 | rtlpriv->works.hw = hw; |
Kees Cook | d853754 | 2013-07-03 15:04:57 -0700 | [diff] [blame] | 384 | rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 385 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
| 386 | (void *)rtl_watchdog_wq_callback); |
| 387 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, |
| 388 | (void *)rtl_ips_nic_off_wq_callback); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 389 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
| 390 | (void *)rtl_swlps_wq_callback); |
| 391 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, |
| 392 | (void *)rtl_swlps_rfon_wq_callback); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 393 | INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, |
| 394 | (void *)rtl_fwevt_wq_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 395 | |
| 396 | } |
| 397 | |
| 398 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) |
| 399 | { |
| 400 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 401 | |
| 402 | del_timer_sync(&rtlpriv->works.watchdog_timer); |
| 403 | |
| 404 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); |
| 405 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 406 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 407 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 408 | cancel_delayed_work(&rtlpriv->works.fwevt_wq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 409 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 410 | EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 411 | |
| 412 | void rtl_init_rfkill(struct ieee80211_hw *hw) |
| 413 | { |
| 414 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 415 | |
| 416 | bool radio_state; |
| 417 | bool blocked; |
| 418 | u8 valid = 0; |
| 419 | |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 420 | /*set init state to on */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 421 | rtlpriv->rfkill.rfkill_state = true; |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 422 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
| 423 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 424 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 425 | |
Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 426 | if (valid) { |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 427 | pr_info("wireless switch is %s\n", |
| 428 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 429 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 430 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 431 | |
| 432 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 433 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 434 | } |
| 435 | |
| 436 | wiphy_rfkill_start_polling(hw->wiphy); |
| 437 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 438 | EXPORT_SYMBOL(rtl_init_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 439 | |
| 440 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) |
| 441 | { |
| 442 | wiphy_rfkill_stop_polling(hw->wiphy); |
| 443 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 444 | EXPORT_SYMBOL_GPL(rtl_deinit_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 445 | |
| 446 | int rtl_init_core(struct ieee80211_hw *hw) |
| 447 | { |
| 448 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 449 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 450 | |
| 451 | /* <1> init mac80211 */ |
| 452 | _rtl_init_mac80211(hw); |
| 453 | rtlmac->hw = hw; |
| 454 | |
| 455 | /* <2> rate control register */ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 456 | hw->rate_control_algorithm = "rtl_rc"; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 457 | |
| 458 | /* |
| 459 | * <3> init CRDA must come after init |
| 460 | * mac80211 hw in _rtl_init_mac80211. |
| 461 | */ |
| 462 | if (rtl_regd_init(hw, rtl_reg_notifier)) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 463 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 464 | return 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* <4> locks */ |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 468 | mutex_init(&rtlpriv->locks.conf_mutex); |
Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 469 | mutex_init(&rtlpriv->locks.ps_mutex); |
Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 470 | spin_lock_init(&rtlpriv->locks.ips_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 471 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 472 | spin_lock_init(&rtlpriv->locks.irq_pci_lock); |
| 473 | spin_lock_init(&rtlpriv->locks.tx_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 474 | spin_lock_init(&rtlpriv->locks.h2c_lock); |
| 475 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); |
| 476 | spin_lock_init(&rtlpriv->locks.rf_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 477 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 478 | spin_lock_init(&rtlpriv->locks.entry_list_lock); |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 479 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 480 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 481 | spin_lock_init(&rtlpriv->locks.check_sendpkt_lock); |
| 482 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
| 483 | spin_lock_init(&rtlpriv->locks.lps_lock); |
| 484 | |
| 485 | /* <5> init list */ |
| 486 | INIT_LIST_HEAD(&rtlpriv->entry_list); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 487 | |
| 488 | rtlmac->link_state = MAC80211_NOLINK; |
| 489 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 490 | /* <6> init deferred work */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 491 | _rtl_init_deferred_work(hw); |
| 492 | |
| 493 | return 0; |
| 494 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 495 | EXPORT_SYMBOL_GPL(rtl_init_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 496 | |
| 497 | void rtl_deinit_core(struct ieee80211_hw *hw) |
| 498 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 499 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 500 | EXPORT_SYMBOL_GPL(rtl_deinit_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 501 | |
| 502 | void rtl_init_rx_config(struct ieee80211_hw *hw) |
| 503 | { |
| 504 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 505 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 506 | |
| 507 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 508 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 509 | EXPORT_SYMBOL_GPL(rtl_init_rx_config); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 510 | |
| 511 | /********************************************************* |
| 512 | * |
| 513 | * tx information functions |
| 514 | * |
| 515 | *********************************************************/ |
| 516 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, |
| 517 | struct rtl_tcb_desc *tcb_desc, |
| 518 | struct ieee80211_tx_info *info) |
| 519 | { |
| 520 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 521 | u8 rate_flag = info->control.rates[0].flags; |
| 522 | |
| 523 | tcb_desc->use_shortpreamble = false; |
| 524 | |
| 525 | /* 1M can only use Long Preamble. 11B spec */ |
| 526 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) |
| 527 | return; |
| 528 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 529 | tcb_desc->use_shortpreamble = true; |
| 530 | |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 535 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 536 | struct rtl_tcb_desc *tcb_desc, |
| 537 | struct ieee80211_tx_info *info) |
| 538 | { |
| 539 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 540 | u8 rate_flag = info->control.rates[0].flags; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 541 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 542 | tcb_desc->use_shortgi = false; |
| 543 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 544 | if (sta == NULL) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 545 | return; |
| 546 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 547 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
| 548 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; |
| 549 | |
| 550 | if (!(sta->ht_cap.ht_supported)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 551 | return; |
| 552 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 553 | if (!sgi_40 && !sgi_20) |
| 554 | return; |
| 555 | |
| 556 | if (mac->opmode == NL80211_IFTYPE_STATION) |
| 557 | bw_40 = mac->bw_40; |
| 558 | else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 559 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 560 | mac->opmode == NL80211_IFTYPE_MESH_POINT) |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 561 | bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 562 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 563 | if (bw_40 && sgi_40) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 564 | tcb_desc->use_shortgi = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 565 | else if ((bw_40 == false) && sgi_20) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 566 | tcb_desc->use_shortgi = true; |
| 567 | |
| 568 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) |
| 569 | tcb_desc->use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, |
| 573 | struct rtl_tcb_desc *tcb_desc, |
| 574 | struct ieee80211_tx_info *info) |
| 575 | { |
| 576 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 577 | u8 rate_flag = info->control.rates[0].flags; |
| 578 | |
| 579 | /* Common Settings */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 580 | tcb_desc->rts_stbc = false; |
| 581 | tcb_desc->cts_enable = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 582 | tcb_desc->rts_sc = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 583 | tcb_desc->rts_bw = false; |
| 584 | tcb_desc->rts_use_shortpreamble = false; |
| 585 | tcb_desc->rts_use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 586 | |
| 587 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 588 | /* Use CTS-to-SELF in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 589 | tcb_desc->rts_enable = true; |
| 590 | tcb_desc->cts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 591 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 592 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 593 | /* Use RTS-CTS in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 594 | tcb_desc->rts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 595 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 596 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 600 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 601 | struct rtl_tcb_desc *tcb_desc) |
| 602 | { |
| 603 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 604 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 605 | struct rtl_sta_info *sta_entry = NULL; |
| 606 | u8 ratr_index = 7; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 607 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 608 | if (sta) { |
| 609 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 610 | ratr_index = sta_entry->ratr_index; |
| 611 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 612 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 613 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 614 | tcb_desc->ratr_index = 0; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 615 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC || |
| 616 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 617 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 618 | tcb_desc->hw_rate = |
| 619 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; |
| 620 | tcb_desc->use_driver_rate = 1; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 621 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 622 | } else { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 623 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 624 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 625 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
| 626 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 630 | if (rtlpriv->dm.useramask) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 631 | tcb_desc->ratr_index = ratr_index; |
| 632 | /* TODO we will differentiate adhoc and station future */ |
| 633 | if (mac->opmode == NL80211_IFTYPE_STATION || |
| 634 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 635 | tcb_desc->mac_id = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 636 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 637 | if (mac->mode == WIRELESS_MODE_N_24G) |
| 638 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; |
| 639 | else if (mac->mode == WIRELESS_MODE_N_5G) |
| 640 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; |
| 641 | else if (mac->mode & WIRELESS_MODE_G) |
| 642 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; |
| 643 | else if (mac->mode & WIRELESS_MODE_B) |
| 644 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; |
| 645 | else if (mac->mode & WIRELESS_MODE_A) |
| 646 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; |
| 647 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 648 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 649 | if (NULL != sta) { |
| 650 | if (sta->aid > 0) |
| 651 | tcb_desc->mac_id = sta->aid + 1; |
| 652 | else |
| 653 | tcb_desc->mac_id = 1; |
| 654 | } else { |
| 655 | tcb_desc->mac_id = 0; |
| 656 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 657 | } |
| 658 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 662 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 663 | struct rtl_tcb_desc *tcb_desc) |
| 664 | { |
| 665 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 666 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 667 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 668 | tcb_desc->packet_bw = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 669 | if (!sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 670 | return; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 671 | if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 672 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 673 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 674 | if (sta->bandwidth == IEEE80211_STA_RX_BW_20) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 675 | return; |
| 676 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 677 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) |
| 678 | return; |
| 679 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 680 | if (tcb_desc->multicast || tcb_desc->broadcast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 681 | return; |
| 682 | |
| 683 | /*use legency rate, shall use 20MHz */ |
| 684 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) |
| 685 | return; |
| 686 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 687 | tcb_desc->packet_bw = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw) |
| 691 | { |
| 692 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 693 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 694 | u8 hw_rate; |
| 695 | |
| 696 | if (get_rf_type(rtlphy) == RF_2T2R) |
| 697 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
| 698 | else |
| 699 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; |
| 700 | |
| 701 | return hw_rate; |
| 702 | } |
| 703 | |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 704 | /* mac80211's rate_idx is like this: |
| 705 | * |
| 706 | * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ |
| 707 | * |
| 708 | * B/G rate: |
| 709 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 710 | * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11, |
| 711 | * |
| 712 | * N rate: |
| 713 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 714 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 715 | * |
| 716 | * 5G band:rx_status->band == IEEE80211_BAND_5GHZ |
| 717 | * A rate: |
| 718 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 719 | * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7, |
| 720 | * |
| 721 | * N rate: |
| 722 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 723 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 724 | */ |
| 725 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, |
| 726 | bool isht, u8 desc_rate, bool first_ampdu) |
| 727 | { |
| 728 | int rate_idx; |
| 729 | |
| 730 | if (false == isht) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 731 | if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 732 | switch (desc_rate) { |
| 733 | case DESC92_RATE1M: |
| 734 | rate_idx = 0; |
| 735 | break; |
| 736 | case DESC92_RATE2M: |
| 737 | rate_idx = 1; |
| 738 | break; |
| 739 | case DESC92_RATE5_5M: |
| 740 | rate_idx = 2; |
| 741 | break; |
| 742 | case DESC92_RATE11M: |
| 743 | rate_idx = 3; |
| 744 | break; |
| 745 | case DESC92_RATE6M: |
| 746 | rate_idx = 4; |
| 747 | break; |
| 748 | case DESC92_RATE9M: |
| 749 | rate_idx = 5; |
| 750 | break; |
| 751 | case DESC92_RATE12M: |
| 752 | rate_idx = 6; |
| 753 | break; |
| 754 | case DESC92_RATE18M: |
| 755 | rate_idx = 7; |
| 756 | break; |
| 757 | case DESC92_RATE24M: |
| 758 | rate_idx = 8; |
| 759 | break; |
| 760 | case DESC92_RATE36M: |
| 761 | rate_idx = 9; |
| 762 | break; |
| 763 | case DESC92_RATE48M: |
| 764 | rate_idx = 10; |
| 765 | break; |
| 766 | case DESC92_RATE54M: |
| 767 | rate_idx = 11; |
| 768 | break; |
| 769 | default: |
| 770 | rate_idx = 0; |
| 771 | break; |
| 772 | } |
| 773 | } else { |
| 774 | switch (desc_rate) { |
| 775 | case DESC92_RATE6M: |
| 776 | rate_idx = 0; |
| 777 | break; |
| 778 | case DESC92_RATE9M: |
| 779 | rate_idx = 1; |
| 780 | break; |
| 781 | case DESC92_RATE12M: |
| 782 | rate_idx = 2; |
| 783 | break; |
| 784 | case DESC92_RATE18M: |
| 785 | rate_idx = 3; |
| 786 | break; |
| 787 | case DESC92_RATE24M: |
| 788 | rate_idx = 4; |
| 789 | break; |
| 790 | case DESC92_RATE36M: |
| 791 | rate_idx = 5; |
| 792 | break; |
| 793 | case DESC92_RATE48M: |
| 794 | rate_idx = 6; |
| 795 | break; |
| 796 | case DESC92_RATE54M: |
| 797 | rate_idx = 7; |
| 798 | break; |
| 799 | default: |
| 800 | rate_idx = 0; |
| 801 | break; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | } else { |
| 806 | |
| 807 | switch (desc_rate) { |
| 808 | case DESC92_RATEMCS0: |
| 809 | rate_idx = 0; |
| 810 | break; |
| 811 | case DESC92_RATEMCS1: |
| 812 | rate_idx = 1; |
| 813 | break; |
| 814 | case DESC92_RATEMCS2: |
| 815 | rate_idx = 2; |
| 816 | break; |
| 817 | case DESC92_RATEMCS3: |
| 818 | rate_idx = 3; |
| 819 | break; |
| 820 | case DESC92_RATEMCS4: |
| 821 | rate_idx = 4; |
| 822 | break; |
| 823 | case DESC92_RATEMCS5: |
| 824 | rate_idx = 5; |
| 825 | break; |
| 826 | case DESC92_RATEMCS6: |
| 827 | rate_idx = 6; |
| 828 | break; |
| 829 | case DESC92_RATEMCS7: |
| 830 | rate_idx = 7; |
| 831 | break; |
| 832 | case DESC92_RATEMCS8: |
| 833 | rate_idx = 8; |
| 834 | break; |
| 835 | case DESC92_RATEMCS9: |
| 836 | rate_idx = 9; |
| 837 | break; |
| 838 | case DESC92_RATEMCS10: |
| 839 | rate_idx = 10; |
| 840 | break; |
| 841 | case DESC92_RATEMCS11: |
| 842 | rate_idx = 11; |
| 843 | break; |
| 844 | case DESC92_RATEMCS12: |
| 845 | rate_idx = 12; |
| 846 | break; |
| 847 | case DESC92_RATEMCS13: |
| 848 | rate_idx = 13; |
| 849 | break; |
| 850 | case DESC92_RATEMCS14: |
| 851 | rate_idx = 14; |
| 852 | break; |
| 853 | case DESC92_RATEMCS15: |
| 854 | rate_idx = 15; |
| 855 | break; |
| 856 | default: |
| 857 | rate_idx = 0; |
| 858 | break; |
| 859 | } |
| 860 | } |
| 861 | return rate_idx; |
| 862 | } |
| 863 | EXPORT_SYMBOL(rtlwifi_rate_mapping); |
| 864 | |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 865 | bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 866 | { |
| 867 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 868 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 869 | __le16 fc = rtl_get_fc(skb); |
| 870 | |
| 871 | if (rtlpriv->dm.supp_phymode_switch && |
| 872 | mac->link_state < MAC80211_LINKED && |
| 873 | (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 874 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 875 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 876 | } |
| 877 | if (ieee80211_is_auth(fc)) { |
| 878 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); |
| 879 | rtl_ips_nic_on(hw); |
| 880 | |
| 881 | mac->link_state = MAC80211_LINKING; |
| 882 | /* Dual mac */ |
| 883 | rtlpriv->phy.need_iqk = true; |
| 884 | } |
| 885 | |
| 886 | return true; |
| 887 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 888 | EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc); |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 889 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 890 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
| 891 | struct ieee80211_tx_info *info, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 892 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 893 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
| 894 | { |
| 895 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 896 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 897 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 898 | struct ieee80211_rate *txrate; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 899 | __le16 fc = hdr->frame_control; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 900 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 901 | txrate = ieee80211_get_tx_rate(hw, info); |
Larry Finger | e89f769 | 2012-04-06 16:54:17 -0500 | [diff] [blame] | 902 | if (txrate) |
| 903 | tcb_desc->hw_rate = txrate->hw_value; |
| 904 | else |
| 905 | tcb_desc->hw_rate = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 906 | |
| 907 | if (ieee80211_is_data(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 908 | /* |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 909 | *we set data rate INX 0 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 910 | *in rtl_rc.c if skb is special data or |
| 911 | *mgt which need low data rate. |
| 912 | */ |
| 913 | |
| 914 | /* |
| 915 | *So tcb_desc->hw_rate is just used for |
| 916 | *special data and mgt frames |
| 917 | */ |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 918 | if (info->control.rates[0].idx == 0 || |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 919 | ieee80211_is_nullfunc(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 920 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 921 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 922 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 923 | tcb_desc->disable_ratefallback = 1; |
| 924 | } else { |
| 925 | /* |
| 926 | *because hw will nerver use hw_rate |
| 927 | *when tcb_desc->use_driver_rate = false |
| 928 | *so we never set highest N rate here, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 929 | *and N rate will all be controlled by FW |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 930 | *when tcb_desc->use_driver_rate = false |
| 931 | */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 932 | if (sta && (sta->ht_cap.ht_supported)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 933 | tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw); |
| 934 | } else { |
| 935 | if (rtlmac->mode == WIRELESS_MODE_B) { |
| 936 | tcb_desc->hw_rate = |
| 937 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; |
| 938 | } else { |
| 939 | tcb_desc->hw_rate = |
| 940 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 946 | tcb_desc->multicast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 947 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 948 | tcb_desc->broadcast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 949 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 950 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
| 951 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 952 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 953 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 954 | _rtl_query_protection_mode(hw, tcb_desc, info); |
| 955 | } else { |
| 956 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 957 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 958 | tcb_desc->disable_ratefallback = 1; |
| 959 | tcb_desc->mac_id = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 960 | tcb_desc->packet_bw = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | EXPORT_SYMBOL(rtl_get_tcb_desc); |
| 964 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 965 | static bool addbareq_rx(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 966 | { |
| 967 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 968 | struct ieee80211_sta *sta = NULL; |
| 969 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
| 970 | struct rtl_sta_info *sta_entry = NULL; |
| 971 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 972 | u16 capab = 0, tid = 0; |
| 973 | struct rtl_tid_data *tid_data; |
| 974 | struct sk_buff *skb_delba = NULL; |
| 975 | struct ieee80211_rx_status rx_status = { 0 }; |
| 976 | |
| 977 | rcu_read_lock(); |
| 978 | sta = rtl_find_sta(hw, hdr->addr3); |
| 979 | if (sta == NULL) { |
| 980 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_EMERG, |
| 981 | "sta is NULL\n"); |
| 982 | rcu_read_unlock(); |
| 983 | return true; |
| 984 | } |
| 985 | |
| 986 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 987 | if (!sta_entry) { |
| 988 | rcu_read_unlock(); |
| 989 | return true; |
| 990 | } |
| 991 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 992 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 993 | tid_data = &sta_entry->tids[tid]; |
| 994 | if (tid_data->agg.rx_agg_state == RTL_RX_AGG_START) { |
| 995 | skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); |
| 996 | if (skb_delba) { |
John W. Linville | 655d8e2 | 2013-04-10 14:09:54 -0400 | [diff] [blame] | 997 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 998 | rx_status.band = hw->conf.chandef.chan->band; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 999 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 1000 | rx_status.flag |= RX_FLAG_MACTIME_END; |
| 1001 | rx_status.rate_idx = 0; |
| 1002 | rx_status.signal = 50 + 10; |
| 1003 | memcpy(IEEE80211_SKB_RXCB(skb_delba), &rx_status, |
| 1004 | sizeof(rx_status)); |
| 1005 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1006 | "fake del\n", skb_delba->data, |
| 1007 | skb_delba->len); |
| 1008 | ieee80211_rx_irqsafe(hw, skb_delba); |
| 1009 | } |
| 1010 | } |
| 1011 | rcu_read_unlock(); |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1015 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1016 | { |
| 1017 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1018 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1019 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 1020 | __le16 fc = hdr->frame_control; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1021 | u8 *act = (u8 *)skb->data + MAC80211_3ADDR_LEN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1022 | u8 category; |
| 1023 | |
| 1024 | if (!ieee80211_is_action(fc)) |
| 1025 | return true; |
| 1026 | |
| 1027 | category = *act; |
| 1028 | act++; |
| 1029 | switch (category) { |
| 1030 | case ACT_CAT_BA: |
| 1031 | switch (*act) { |
| 1032 | case ACT_ADDBAREQ: |
| 1033 | if (mac->act_scanning) |
| 1034 | return false; |
| 1035 | |
| 1036 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1037 | "%s ACT_ADDBAREQ From :%pM\n", |
| 1038 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1039 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", |
| 1040 | skb->data, skb->len); |
| 1041 | if (!is_tx) |
| 1042 | if (addbareq_rx(hw, skb)) |
| 1043 | return true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1044 | break; |
| 1045 | case ACT_ADDBARSP: |
| 1046 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1047 | "%s ACT_ADDBARSP From :%pM\n", |
| 1048 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1049 | break; |
| 1050 | case ACT_DELBA: |
| 1051 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1052 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1053 | break; |
| 1054 | } |
| 1055 | break; |
| 1056 | default: |
| 1057 | break; |
| 1058 | } |
| 1059 | |
| 1060 | return true; |
| 1061 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1062 | EXPORT_SYMBOL_GPL(rtl_action_proc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1063 | |
| 1064 | /*should call before software enc*/ |
| 1065 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1066 | { |
| 1067 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1068 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1069 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1070 | u16 ether_type; |
| 1071 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); |
| 1072 | const struct iphdr *ip; |
| 1073 | |
| 1074 | if (!ieee80211_is_data(fc)) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 1075 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1076 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1077 | |
| 1078 | ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len + |
| 1079 | SNAP_SIZE + PROTOC_TYPE_SIZE); |
| 1080 | ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE); |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1081 | /* ether_type = ntohs(ether_type); */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1082 | |
| 1083 | if (ETH_P_IP == ether_type) { |
| 1084 | if (IPPROTO_UDP == ip->protocol) { |
| 1085 | struct udphdr *udp = (struct udphdr *)((u8 *) ip + |
| 1086 | (ip->ihl << 2)); |
| 1087 | if (((((u8 *) udp)[1] == 68) && |
| 1088 | (((u8 *) udp)[3] == 67)) || |
| 1089 | ((((u8 *) udp)[1] == 67) && |
| 1090 | (((u8 *) udp)[3] == 68))) { |
| 1091 | /* |
| 1092 | * 68 : UDP BOOTP client |
| 1093 | * 67 : UDP BOOTP server |
| 1094 | */ |
| 1095 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1096 | DBG_DMESG, "dhcp %s !!\n", |
| 1097 | is_tx ? "Tx" : "Rx"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1098 | |
| 1099 | if (is_tx) { |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1100 | rtlpriv->enter_ps = false; |
Larry Finger | a5ffbe0 | 2013-02-02 15:55:00 -0600 | [diff] [blame] | 1101 | schedule_work(&rtlpriv-> |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1102 | works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1103 | ppsc->last_delaylps_stamp_jiffies = |
| 1104 | jiffies; |
| 1105 | } |
| 1106 | |
| 1107 | return true; |
| 1108 | } |
| 1109 | } |
| 1110 | } else if (ETH_P_ARP == ether_type) { |
| 1111 | if (is_tx) { |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1112 | rtlpriv->enter_ps = false; |
| 1113 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1114 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1115 | } |
| 1116 | |
| 1117 | return true; |
| 1118 | } else if (ETH_P_PAE == ether_type) { |
| 1119 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1120 | "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1121 | |
| 1122 | if (is_tx) { |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1123 | rtlpriv->enter_ps = false; |
| 1124 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1125 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1126 | } |
| 1127 | |
| 1128 | return true; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 1129 | } else if (ETH_P_IPV6 == ether_type) { |
| 1130 | /* IPv6 */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1131 | return true; |
| 1132 | } |
| 1133 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1134 | return false; |
| 1135 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1136 | EXPORT_SYMBOL_GPL(rtl_is_special_data); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1137 | |
| 1138 | /********************************************************* |
| 1139 | * |
| 1140 | * functions called by core.c |
| 1141 | * |
| 1142 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1143 | int rtl_tx_agg_start(struct ieee80211_hw *hw, |
| 1144 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1145 | { |
| 1146 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1147 | struct rtl_tid_data *tid_data; |
| 1148 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1149 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1150 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1151 | if (sta == NULL) |
| 1152 | return -EINVAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1153 | |
| 1154 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1155 | return -EINVAL; |
| 1156 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1157 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1158 | if (!sta_entry) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1159 | return -ENXIO; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1160 | tid_data = &sta_entry->tids[tid]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1161 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1162 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n", |
| 1163 | sta->addr, tid, tid_data->seq_number); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1164 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1165 | *ssn = tid_data->seq_number; |
| 1166 | tid_data->agg.agg_state = RTL_AGG_START; |
| 1167 | |
| 1168 | ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1173 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, |
| 1174 | struct ieee80211_sta *sta, u16 tid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1175 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1176 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1177 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1178 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1179 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1180 | if (sta == NULL) |
| 1181 | return -EINVAL; |
| 1182 | |
| 1183 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1184 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1185 | return -EINVAL; |
| 1186 | } |
| 1187 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1188 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1189 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1190 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1191 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1192 | return -EINVAL; |
| 1193 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1194 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1195 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1196 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1197 | ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1198 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1199 | return 0; |
| 1200 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1201 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1202 | int rtl_rx_agg_start(struct ieee80211_hw *hw, |
| 1203 | struct ieee80211_sta *sta, u16 tid) |
| 1204 | { |
| 1205 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1206 | struct rtl_tid_data *tid_data; |
| 1207 | struct rtl_sta_info *sta_entry = NULL; |
| 1208 | |
| 1209 | if (sta == NULL) |
| 1210 | return -EINVAL; |
| 1211 | |
| 1212 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1213 | return -EINVAL; |
| 1214 | |
| 1215 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1216 | if (!sta_entry) |
| 1217 | return -ENXIO; |
| 1218 | tid_data = &sta_entry->tids[tid]; |
| 1219 | |
| 1220 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, |
| 1221 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, |
| 1222 | tid_data->seq_number); |
| 1223 | |
| 1224 | tid_data->agg.rx_agg_state = RTL_RX_AGG_START; |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | int rtl_rx_agg_stop(struct ieee80211_hw *hw, |
| 1229 | struct ieee80211_sta *sta, u16 tid) |
| 1230 | { |
| 1231 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1232 | struct rtl_sta_info *sta_entry = NULL; |
| 1233 | |
| 1234 | if (sta == NULL) |
| 1235 | return -EINVAL; |
| 1236 | |
| 1237 | if (!sta->addr) { |
| 1238 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
| 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | |
| 1242 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1243 | "on ra = %pM tid = %d\n", sta->addr, tid); |
| 1244 | |
| 1245 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1246 | return -EINVAL; |
| 1247 | |
| 1248 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1249 | sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; |
| 1250 | |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1254 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
| 1255 | struct ieee80211_sta *sta, u16 tid) |
| 1256 | { |
| 1257 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1258 | struct rtl_sta_info *sta_entry = NULL; |
| 1259 | |
| 1260 | if (sta == NULL) |
| 1261 | return -EINVAL; |
| 1262 | |
| 1263 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1264 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1265 | return -EINVAL; |
| 1266 | } |
| 1267 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1268 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1269 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1270 | |
| 1271 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1272 | return -EINVAL; |
| 1273 | |
| 1274 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1275 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1276 | |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | /********************************************************* |
| 1281 | * |
| 1282 | * wq & timer callback functions |
| 1283 | * |
| 1284 | *********************************************************/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1285 | /* this function is used for roaming */ |
| 1286 | void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1287 | { |
| 1288 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1289 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1290 | |
| 1291 | if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) |
| 1292 | return; |
| 1293 | |
| 1294 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) |
| 1295 | return; |
| 1296 | |
| 1297 | /* check if this really is a beacon */ |
| 1298 | if (!ieee80211_is_beacon(hdr->frame_control) && |
| 1299 | !ieee80211_is_probe_resp(hdr->frame_control)) |
| 1300 | return; |
| 1301 | |
| 1302 | /* min. beacon length + FCS_LEN */ |
| 1303 | if (skb->len <= 40 + FCS_LEN) |
| 1304 | return; |
| 1305 | |
| 1306 | /* and only beacons from the associated BSSID, please */ |
Joe Perches | 7367d0b | 2013-09-01 11:51:23 -0700 | [diff] [blame] | 1307 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1308 | return; |
| 1309 | |
| 1310 | rtlpriv->link_info.bcn_rx_inperiod++; |
| 1311 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1312 | EXPORT_SYMBOL_GPL(rtl_beacon_statistic); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1313 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1314 | void rtl_watchdog_wq_callback(void *data) |
| 1315 | { |
| 1316 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 1317 | struct rtl_works, |
| 1318 | watchdog_wq); |
| 1319 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1320 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1321 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1322 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1323 | bool busytraffic = false; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1324 | bool tx_busy_traffic = false; |
| 1325 | bool rx_busy_traffic = false; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1326 | bool higher_busytraffic = false; |
| 1327 | bool higher_busyrxtraffic = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1328 | u8 idx, tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1329 | u32 rx_cnt_inp4eriod = 0; |
| 1330 | u32 tx_cnt_inp4eriod = 0; |
| 1331 | u32 aver_rx_cnt_inperiod = 0; |
| 1332 | u32 aver_tx_cnt_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1333 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
| 1334 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1335 | |
| 1336 | if (is_hal_stop(rtlhal)) |
| 1337 | return; |
| 1338 | |
| 1339 | /* <1> Determine if action frame is allowed */ |
| 1340 | if (mac->link_state > MAC80211_NOLINK) { |
| 1341 | if (mac->cnt_after_linked < 20) |
| 1342 | mac->cnt_after_linked++; |
| 1343 | } else { |
| 1344 | mac->cnt_after_linked = 0; |
| 1345 | } |
| 1346 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1347 | /* |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 1348 | *<2> to check if traffic busy, if |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1349 | * busytraffic we don't change channel |
| 1350 | */ |
| 1351 | if (mac->link_state >= MAC80211_LINKED) { |
| 1352 | |
| 1353 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ |
| 1354 | for (idx = 0; idx <= 2; idx++) { |
| 1355 | rtlpriv->link_info.num_rx_in4period[idx] = |
| 1356 | rtlpriv->link_info.num_rx_in4period[idx + 1]; |
| 1357 | rtlpriv->link_info.num_tx_in4period[idx] = |
| 1358 | rtlpriv->link_info.num_tx_in4period[idx + 1]; |
| 1359 | } |
| 1360 | rtlpriv->link_info.num_rx_in4period[3] = |
| 1361 | rtlpriv->link_info.num_rx_inperiod; |
| 1362 | rtlpriv->link_info.num_tx_in4period[3] = |
| 1363 | rtlpriv->link_info.num_tx_inperiod; |
| 1364 | for (idx = 0; idx <= 3; idx++) { |
| 1365 | rx_cnt_inp4eriod += |
| 1366 | rtlpriv->link_info.num_rx_in4period[idx]; |
| 1367 | tx_cnt_inp4eriod += |
| 1368 | rtlpriv->link_info.num_tx_in4period[idx]; |
| 1369 | } |
| 1370 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; |
| 1371 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; |
| 1372 | |
| 1373 | /* (2) check traffic busy */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1374 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1375 | busytraffic = true; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1376 | if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) |
| 1377 | rx_busy_traffic = true; |
| 1378 | else |
| 1379 | tx_busy_traffic = false; |
| 1380 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1381 | |
| 1382 | /* Higher Tx/Rx data. */ |
| 1383 | if (aver_rx_cnt_inperiod > 4000 || |
| 1384 | aver_tx_cnt_inperiod > 4000) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1385 | higher_busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1386 | |
| 1387 | /* Extremely high Rx data. */ |
| 1388 | if (aver_rx_cnt_inperiod > 5000) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1389 | higher_busyrxtraffic = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /* check every tid's tx traffic */ |
| 1393 | for (tid = 0; tid <= 7; tid++) { |
| 1394 | for (idx = 0; idx <= 2; idx++) |
| 1395 | rtlpriv->link_info.tidtx_in4period[tid][idx] = |
| 1396 | rtlpriv->link_info.tidtx_in4period[tid] |
| 1397 | [idx + 1]; |
| 1398 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
| 1399 | rtlpriv->link_info.tidtx_inperiod[tid]; |
| 1400 | |
| 1401 | for (idx = 0; idx <= 3; idx++) |
| 1402 | tidtx_inp4eriod[tid] += |
| 1403 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
| 1404 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
| 1405 | if (aver_tidtx_inperiod[tid] > 5000) |
| 1406 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1407 | true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1408 | else |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1409 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1410 | false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 1414 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 1415 | (rtlpriv->link_info.num_rx_inperiod > 2)) |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1416 | rtlpriv->enter_ps = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1417 | else |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1418 | rtlpriv->enter_ps = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1419 | |
| 1420 | /* LeisurePS only work in infra mode. */ |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1421 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | rtlpriv->link_info.num_rx_inperiod = 0; |
| 1425 | rtlpriv->link_info.num_tx_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1426 | for (tid = 0; tid <= 7; tid++) |
| 1427 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1428 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1429 | rtlpriv->link_info.busytraffic = busytraffic; |
| 1430 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1431 | rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; |
| 1432 | rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1433 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1434 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1435 | /* <3> DM */ |
| 1436 | rtlpriv->cfg->ops->dm_watchdog(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1437 | |
| 1438 | /* <4> roaming */ |
| 1439 | if (mac->link_state == MAC80211_LINKED && |
| 1440 | mac->opmode == NL80211_IFTYPE_STATION) { |
| 1441 | if ((rtlpriv->link_info.bcn_rx_inperiod + |
| 1442 | rtlpriv->link_info.num_rx_inperiod) == 0) { |
| 1443 | rtlpriv->link_info.roam_times++; |
| 1444 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
| 1445 | "AP off for %d s\n", |
| 1446 | (rtlpriv->link_info.roam_times * 2)); |
| 1447 | |
| 1448 | /* if we can't recv beacon for 6s, we should |
| 1449 | * reconnect this AP |
| 1450 | */ |
| 1451 | if (rtlpriv->link_info.roam_times >= 3) { |
| 1452 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1453 | "AP off, try to reconnect now\n"); |
| 1454 | rtlpriv->link_info.roam_times = 0; |
| 1455 | ieee80211_connection_loss(rtlpriv->mac80211.vif); |
| 1456 | } |
| 1457 | } else { |
| 1458 | rtlpriv->link_info.roam_times = 0; |
| 1459 | } |
| 1460 | } |
| 1461 | rtlpriv->link_info.bcn_rx_inperiod = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | void rtl_watch_dog_timer_callback(unsigned long data) |
| 1465 | { |
| 1466 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1467 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1468 | |
| 1469 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 1470 | &rtlpriv->works.watchdog_wq, 0); |
| 1471 | |
| 1472 | mod_timer(&rtlpriv->works.watchdog_timer, |
| 1473 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); |
| 1474 | } |
| 1475 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1476 | void rtl_fwevt_wq_callback(void *data) |
| 1477 | { |
| 1478 | struct rtl_works *rtlworks = |
| 1479 | container_of_dwork_rtl(data, struct rtl_works, fwevt_wq); |
| 1480 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1481 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1482 | |
| 1483 | rtlpriv->cfg->ops->c2h_command_handle(hw); |
| 1484 | } |
| 1485 | |
| 1486 | void rtl_easy_concurrent_retrytimer_callback(unsigned long data) |
| 1487 | { |
| 1488 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1489 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1490 | struct rtl_priv *buddy_priv = rtlpriv->buddy_priv; |
| 1491 | |
| 1492 | if (buddy_priv == NULL) |
| 1493 | return; |
| 1494 | |
| 1495 | rtlpriv->cfg->ops->dualmac_easy_concurrent(hw); |
| 1496 | } |
| 1497 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1498 | /********************************************************* |
| 1499 | * |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1500 | * frame process functions |
| 1501 | * |
| 1502 | *********************************************************/ |
| 1503 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) |
| 1504 | { |
| 1505 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1506 | u8 *pos, *end; |
| 1507 | |
| 1508 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1509 | end = data + len; |
| 1510 | while (pos < end) { |
| 1511 | if (pos + 2 + pos[1] > end) |
| 1512 | return NULL; |
| 1513 | |
| 1514 | if (pos[0] == ie) |
| 1515 | return pos; |
| 1516 | |
| 1517 | pos += 2 + pos[1]; |
| 1518 | } |
| 1519 | return NULL; |
| 1520 | } |
| 1521 | |
| 1522 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ |
| 1523 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1524 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1525 | enum ieee80211_smps_mode smps, u8 *da, u8 *bssid) |
| 1526 | { |
| 1527 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1528 | struct sk_buff *skb; |
| 1529 | struct ieee80211_mgmt *action_frame; |
| 1530 | |
| 1531 | /* 27 = header + category + action + smps mode */ |
| 1532 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); |
| 1533 | if (!skb) |
| 1534 | return NULL; |
| 1535 | |
| 1536 | skb_reserve(skb, hw->extra_tx_headroom); |
| 1537 | action_frame = (void *)skb_put(skb, 27); |
| 1538 | memset(action_frame, 0, 27); |
| 1539 | memcpy(action_frame->da, da, ETH_ALEN); |
| 1540 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); |
| 1541 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 1542 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1543 | IEEE80211_STYPE_ACTION); |
| 1544 | action_frame->u.action.category = WLAN_CATEGORY_HT; |
| 1545 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; |
| 1546 | switch (smps) { |
| 1547 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ |
| 1548 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ |
| 1549 | WARN_ON(1); |
| 1550 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
| 1551 | action_frame->u.action.u.ht_smps.smps_control = |
| 1552 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ |
| 1553 | break; |
| 1554 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ |
| 1555 | action_frame->u.action.u.ht_smps.smps_control = |
| 1556 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ |
| 1557 | break; |
| 1558 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ |
| 1559 | action_frame->u.action.u.ht_smps.smps_control = |
| 1560 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ |
| 1561 | break; |
| 1562 | } |
| 1563 | |
| 1564 | return skb; |
| 1565 | } |
| 1566 | |
| 1567 | int rtl_send_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1568 | struct ieee80211_sta *sta, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1569 | enum ieee80211_smps_mode smps) |
| 1570 | { |
| 1571 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1572 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1573 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1574 | struct sk_buff *skb = NULL; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1575 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1576 | u8 bssid[ETH_ALEN] = {0}; |
| 1577 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1578 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 1579 | |
| 1580 | if (rtlpriv->mac80211.act_scanning) |
| 1581 | goto err_free; |
| 1582 | |
| 1583 | if (!sta) |
| 1584 | goto err_free; |
| 1585 | |
| 1586 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 1587 | goto err_free; |
| 1588 | |
| 1589 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 1590 | goto err_free; |
| 1591 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1592 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) |
| 1593 | memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); |
| 1594 | else |
| 1595 | memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); |
| 1596 | |
| 1597 | skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1598 | /* this is a type = mgmt * stype = action frame */ |
| 1599 | if (skb) { |
| 1600 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1601 | struct rtl_sta_info *sta_entry = |
| 1602 | (struct rtl_sta_info *) sta->drv_priv; |
| 1603 | sta_entry->mimo_ps = smps; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1604 | |
| 1605 | info->control.rates[0].idx = 0; |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 1606 | info->band = hw->conf.chandef.chan->band; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1607 | rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1608 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1609 | return 1; |
| 1610 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1611 | err_free: |
| 1612 | return 0; |
| 1613 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1614 | EXPORT_SYMBOL(rtl_send_smps_action); |
| 1615 | |
Larry Finger | 4f4826d | 2013-09-26 13:25:27 -0500 | [diff] [blame] | 1616 | void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) |
| 1617 | { |
| 1618 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1619 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1620 | enum io_type iotype; |
| 1621 | |
| 1622 | if (!is_hal_stop(rtlhal)) { |
| 1623 | switch (operation) { |
| 1624 | case SCAN_OPT_BACKUP: |
| 1625 | iotype = IO_CMD_PAUSE_DM_BY_SCAN; |
| 1626 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1627 | HW_VAR_IO_CMD, |
| 1628 | (u8 *)&iotype); |
| 1629 | break; |
| 1630 | case SCAN_OPT_RESTORE: |
| 1631 | iotype = IO_CMD_RESUME_DM_BY_SCAN; |
| 1632 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1633 | HW_VAR_IO_CMD, |
| 1634 | (u8 *)&iotype); |
| 1635 | break; |
| 1636 | default: |
| 1637 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1638 | "Unknown Scan Backup operation.\n"); |
| 1639 | break; |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | EXPORT_SYMBOL(rtl_phy_scan_operation_backup); |
| 1644 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1645 | /* There seem to be issues in mac80211 regarding when del ba frames can be |
| 1646 | * received. As a work around, we make a fake del_ba if we receive a ba_req; |
| 1647 | * however, rx_agg was opened to let mac80211 release some ba related |
| 1648 | * resources. This del_ba is for tx only. |
| 1649 | */ |
| 1650 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, |
| 1651 | u8 *sa, u8 *bssid, u16 tid) |
| 1652 | { |
| 1653 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1654 | struct sk_buff *skb; |
| 1655 | struct ieee80211_mgmt *action_frame; |
| 1656 | u16 params; |
| 1657 | |
| 1658 | /* 27 = header + category + action + smps mode */ |
| 1659 | skb = dev_alloc_skb(34 + hw->extra_tx_headroom); |
| 1660 | if (!skb) |
| 1661 | return NULL; |
| 1662 | |
| 1663 | skb_reserve(skb, hw->extra_tx_headroom); |
| 1664 | action_frame = (void *)skb_put(skb, 34); |
| 1665 | memset(action_frame, 0, 34); |
| 1666 | memcpy(action_frame->sa, sa, ETH_ALEN); |
| 1667 | memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); |
| 1668 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 1669 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1670 | IEEE80211_STYPE_ACTION); |
| 1671 | action_frame->u.action.category = WLAN_CATEGORY_BACK; |
| 1672 | action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 1673 | params = (u16)(1 << 11); /* bit 11 initiator */ |
| 1674 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
| 1675 | |
| 1676 | action_frame->u.action.u.delba.params = cpu_to_le16(params); |
| 1677 | action_frame->u.action.u.delba.reason_code = |
| 1678 | cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); |
| 1679 | |
| 1680 | return skb; |
| 1681 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1682 | |
| 1683 | /********************************************************* |
| 1684 | * |
| 1685 | * IOT functions |
| 1686 | * |
| 1687 | *********************************************************/ |
| 1688 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, |
| 1689 | struct octet_string vendor_ie) |
| 1690 | { |
| 1691 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1692 | bool matched = false; |
| 1693 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; |
| 1694 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; |
| 1695 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; |
| 1696 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; |
| 1697 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; |
| 1698 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; |
| 1699 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; |
| 1700 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; |
| 1701 | |
| 1702 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || |
| 1703 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { |
| 1704 | rtlpriv->mac80211.vendor = PEER_ATH; |
| 1705 | matched = true; |
| 1706 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || |
| 1707 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || |
| 1708 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { |
| 1709 | rtlpriv->mac80211.vendor = PEER_BROAD; |
| 1710 | matched = true; |
| 1711 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { |
| 1712 | rtlpriv->mac80211.vendor = PEER_RAL; |
| 1713 | matched = true; |
| 1714 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { |
| 1715 | rtlpriv->mac80211.vendor = PEER_CISCO; |
| 1716 | matched = true; |
| 1717 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { |
| 1718 | rtlpriv->mac80211.vendor = PEER_MARV; |
| 1719 | matched = true; |
| 1720 | } |
| 1721 | |
| 1722 | return matched; |
| 1723 | } |
| 1724 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1725 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1726 | unsigned int len) |
| 1727 | { |
| 1728 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1729 | struct octet_string vendor_ie; |
| 1730 | u8 *pos, *end; |
| 1731 | |
| 1732 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1733 | end = data + len; |
| 1734 | while (pos < end) { |
| 1735 | if (pos[0] == 221) { |
| 1736 | vendor_ie.length = pos[1]; |
| 1737 | vendor_ie.octet = &pos[2]; |
| 1738 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) |
| 1739 | return true; |
| 1740 | } |
| 1741 | |
| 1742 | if (pos + 2 + pos[1] > end) |
| 1743 | return false; |
| 1744 | |
| 1745 | pos += 2 + pos[1]; |
| 1746 | } |
| 1747 | return false; |
| 1748 | } |
| 1749 | |
| 1750 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) |
| 1751 | { |
| 1752 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1753 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1754 | struct ieee80211_hdr *hdr = (void *)data; |
| 1755 | u32 vendor = PEER_UNKNOWN; |
| 1756 | |
| 1757 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; |
| 1758 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; |
| 1759 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; |
| 1760 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; |
| 1761 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; |
| 1762 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; |
| 1763 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; |
| 1764 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; |
| 1765 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; |
| 1766 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; |
| 1767 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; |
| 1768 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; |
| 1769 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; |
| 1770 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; |
| 1771 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; |
| 1772 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; |
| 1773 | |
| 1774 | if (mac->opmode != NL80211_IFTYPE_STATION) |
| 1775 | return; |
| 1776 | |
| 1777 | if (mac->link_state == MAC80211_NOLINK) { |
| 1778 | mac->vendor = PEER_UNKNOWN; |
| 1779 | return; |
| 1780 | } |
| 1781 | |
| 1782 | if (mac->cnt_after_linked > 2) |
| 1783 | return; |
| 1784 | |
| 1785 | /* check if this really is a beacon */ |
| 1786 | if (!ieee80211_is_beacon(hdr->frame_control)) |
| 1787 | return; |
| 1788 | |
| 1789 | /* min. beacon length + FCS_LEN */ |
| 1790 | if (len <= 40 + FCS_LEN) |
| 1791 | return; |
| 1792 | |
| 1793 | /* and only beacons from the associated BSSID, please */ |
Joe Perches | 2e42e47 | 2012-05-09 17:17:46 +0000 | [diff] [blame] | 1794 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1795 | return; |
| 1796 | |
| 1797 | if (rtl_find_221_ie(hw, data, len)) |
| 1798 | vendor = mac->vendor; |
| 1799 | |
| 1800 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || |
| 1801 | (memcmp(mac->bssid, ap5_2, 3) == 0) || |
| 1802 | (memcmp(mac->bssid, ap5_3, 3) == 0) || |
| 1803 | (memcmp(mac->bssid, ap5_4, 3) == 0) || |
| 1804 | (memcmp(mac->bssid, ap5_5, 3) == 0) || |
| 1805 | (memcmp(mac->bssid, ap5_6, 3) == 0) || |
| 1806 | vendor == PEER_ATH) { |
| 1807 | vendor = PEER_ATH; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1808 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1809 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
| 1810 | (memcmp(mac->bssid, ap4_5, 3) == 0) || |
| 1811 | (memcmp(mac->bssid, ap4_1, 3) == 0) || |
| 1812 | (memcmp(mac->bssid, ap4_2, 3) == 0) || |
| 1813 | (memcmp(mac->bssid, ap4_3, 3) == 0) || |
| 1814 | vendor == PEER_RAL) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1815 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1816 | vendor = PEER_RAL; |
| 1817 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || |
| 1818 | vendor == PEER_CISCO) { |
| 1819 | vendor = PEER_CISCO; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1820 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1821 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
| 1822 | (memcmp(mac->bssid, ap3_2, 3) == 0) || |
| 1823 | (memcmp(mac->bssid, ap3_3, 3) == 0) || |
| 1824 | vendor == PEER_BROAD) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1825 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1826 | vendor = PEER_BROAD; |
| 1827 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || |
| 1828 | vendor == PEER_MARV) { |
| 1829 | vendor = PEER_MARV; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1830 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | mac->vendor = vendor; |
| 1834 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1835 | EXPORT_SYMBOL_GPL(rtl_recognize_peer); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1836 | |
| 1837 | /********************************************************* |
| 1838 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1839 | * sysfs functions |
| 1840 | * |
| 1841 | *********************************************************/ |
| 1842 | static ssize_t rtl_show_debug_level(struct device *d, |
| 1843 | struct device_attribute *attr, char *buf) |
| 1844 | { |
| 1845 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1846 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1847 | |
| 1848 | return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel); |
| 1849 | } |
| 1850 | |
| 1851 | static ssize_t rtl_store_debug_level(struct device *d, |
| 1852 | struct device_attribute *attr, |
| 1853 | const char *buf, size_t count) |
| 1854 | { |
| 1855 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1856 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1857 | unsigned long val; |
| 1858 | int ret; |
| 1859 | |
Jingoo Han | 27d7f47 | 2013-05-31 21:24:06 +0000 | [diff] [blame] | 1860 | ret = kstrtoul(buf, 0, &val); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1861 | if (ret) { |
| 1862 | printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf); |
| 1863 | } else { |
| 1864 | rtlpriv->dbg.global_debuglevel = val; |
| 1865 | printk(KERN_DEBUG "debuglevel:%x\n", |
| 1866 | rtlpriv->dbg.global_debuglevel); |
| 1867 | } |
| 1868 | |
| 1869 | return strnlen(buf, count); |
| 1870 | } |
| 1871 | |
| 1872 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1873 | rtl_show_debug_level, rtl_store_debug_level); |
| 1874 | |
| 1875 | static struct attribute *rtl_sysfs_entries[] = { |
| 1876 | |
| 1877 | &dev_attr_debug_level.attr, |
| 1878 | |
| 1879 | NULL |
| 1880 | }; |
| 1881 | |
| 1882 | /* |
| 1883 | * "name" is folder name witch will be |
| 1884 | * put in device directory like : |
| 1885 | * sys/devices/pci0000:00/0000:00:1c.4/ |
| 1886 | * 0000:06:00.0/rtl_sysfs |
| 1887 | */ |
| 1888 | struct attribute_group rtl_attribute_group = { |
| 1889 | .name = "rtlsysfs", |
| 1890 | .attrs = rtl_sysfs_entries, |
| 1891 | }; |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1892 | EXPORT_SYMBOL_GPL(rtl_attribute_group); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1893 | |
| 1894 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); |
| 1895 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); |
| 1896 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); |
| 1897 | MODULE_LICENSE("GPL"); |
| 1898 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); |
| 1899 | |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1900 | struct rtl_global_var rtl_global_var = {}; |
| 1901 | EXPORT_SYMBOL_GPL(rtl_global_var); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1902 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1903 | static int __init rtl_core_module_init(void) |
| 1904 | { |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1905 | if (rtl_rate_control_register()) |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 1906 | pr_err("Unable to register rtl_rc, use default RC !!\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1907 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1908 | /* init some global vars */ |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1909 | INIT_LIST_HEAD(&rtl_global_var.glb_priv_list); |
| 1910 | spin_lock_init(&rtl_global_var.glb_list_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1911 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1912 | return 0; |
| 1913 | } |
| 1914 | |
| 1915 | static void __exit rtl_core_module_exit(void) |
| 1916 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1917 | /*RC*/ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1918 | rtl_rate_control_unregister(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | module_init(rtl_core_module_init); |
| 1922 | module_exit(rtl_core_module_exit); |