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 |
| 57 | *8) ... |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 58 | */ |
| 59 | |
| 60 | /********************************************************* |
| 61 | * |
| 62 | * mac80211 init functions |
| 63 | * |
| 64 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 65 | static struct ieee80211_channel rtl_channeltable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 66 | {.center_freq = 2412, .hw_value = 1,}, |
| 67 | {.center_freq = 2417, .hw_value = 2,}, |
| 68 | {.center_freq = 2422, .hw_value = 3,}, |
| 69 | {.center_freq = 2427, .hw_value = 4,}, |
| 70 | {.center_freq = 2432, .hw_value = 5,}, |
| 71 | {.center_freq = 2437, .hw_value = 6,}, |
| 72 | {.center_freq = 2442, .hw_value = 7,}, |
| 73 | {.center_freq = 2447, .hw_value = 8,}, |
| 74 | {.center_freq = 2452, .hw_value = 9,}, |
| 75 | {.center_freq = 2457, .hw_value = 10,}, |
| 76 | {.center_freq = 2462, .hw_value = 11,}, |
| 77 | {.center_freq = 2467, .hw_value = 12,}, |
| 78 | {.center_freq = 2472, .hw_value = 13,}, |
| 79 | {.center_freq = 2484, .hw_value = 14,}, |
| 80 | }; |
| 81 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 82 | static struct ieee80211_channel rtl_channeltable_5g[] = { |
| 83 | {.center_freq = 5180, .hw_value = 36,}, |
| 84 | {.center_freq = 5200, .hw_value = 40,}, |
| 85 | {.center_freq = 5220, .hw_value = 44,}, |
| 86 | {.center_freq = 5240, .hw_value = 48,}, |
| 87 | {.center_freq = 5260, .hw_value = 52,}, |
| 88 | {.center_freq = 5280, .hw_value = 56,}, |
| 89 | {.center_freq = 5300, .hw_value = 60,}, |
| 90 | {.center_freq = 5320, .hw_value = 64,}, |
| 91 | {.center_freq = 5500, .hw_value = 100,}, |
| 92 | {.center_freq = 5520, .hw_value = 104,}, |
| 93 | {.center_freq = 5540, .hw_value = 108,}, |
| 94 | {.center_freq = 5560, .hw_value = 112,}, |
| 95 | {.center_freq = 5580, .hw_value = 116,}, |
| 96 | {.center_freq = 5600, .hw_value = 120,}, |
| 97 | {.center_freq = 5620, .hw_value = 124,}, |
| 98 | {.center_freq = 5640, .hw_value = 128,}, |
| 99 | {.center_freq = 5660, .hw_value = 132,}, |
| 100 | {.center_freq = 5680, .hw_value = 136,}, |
| 101 | {.center_freq = 5700, .hw_value = 140,}, |
| 102 | {.center_freq = 5745, .hw_value = 149,}, |
| 103 | {.center_freq = 5765, .hw_value = 153,}, |
| 104 | {.center_freq = 5785, .hw_value = 157,}, |
| 105 | {.center_freq = 5805, .hw_value = 161,}, |
| 106 | {.center_freq = 5825, .hw_value = 165,}, |
| 107 | }; |
| 108 | |
| 109 | static struct ieee80211_rate rtl_ratetable_2g[] = { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 110 | {.bitrate = 10, .hw_value = 0x00,}, |
| 111 | {.bitrate = 20, .hw_value = 0x01,}, |
| 112 | {.bitrate = 55, .hw_value = 0x02,}, |
| 113 | {.bitrate = 110, .hw_value = 0x03,}, |
| 114 | {.bitrate = 60, .hw_value = 0x04,}, |
| 115 | {.bitrate = 90, .hw_value = 0x05,}, |
| 116 | {.bitrate = 120, .hw_value = 0x06,}, |
| 117 | {.bitrate = 180, .hw_value = 0x07,}, |
| 118 | {.bitrate = 240, .hw_value = 0x08,}, |
| 119 | {.bitrate = 360, .hw_value = 0x09,}, |
| 120 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 121 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 122 | }; |
| 123 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 124 | static struct ieee80211_rate rtl_ratetable_5g[] = { |
| 125 | {.bitrate = 60, .hw_value = 0x04,}, |
| 126 | {.bitrate = 90, .hw_value = 0x05,}, |
| 127 | {.bitrate = 120, .hw_value = 0x06,}, |
| 128 | {.bitrate = 180, .hw_value = 0x07,}, |
| 129 | {.bitrate = 240, .hw_value = 0x08,}, |
| 130 | {.bitrate = 360, .hw_value = 0x09,}, |
| 131 | {.bitrate = 480, .hw_value = 0x0a,}, |
| 132 | {.bitrate = 540, .hw_value = 0x0b,}, |
| 133 | }; |
| 134 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 135 | static const struct ieee80211_supported_band rtl_band_2ghz = { |
| 136 | .band = IEEE80211_BAND_2GHZ, |
| 137 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 138 | .channels = rtl_channeltable_2g, |
| 139 | .n_channels = ARRAY_SIZE(rtl_channeltable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 140 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 141 | .bitrates = rtl_ratetable_2g, |
| 142 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_2g), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 143 | |
| 144 | .ht_cap = {0}, |
| 145 | }; |
| 146 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 147 | static struct ieee80211_supported_band rtl_band_5ghz = { |
| 148 | .band = IEEE80211_BAND_5GHZ, |
| 149 | |
| 150 | .channels = rtl_channeltable_5g, |
| 151 | .n_channels = ARRAY_SIZE(rtl_channeltable_5g), |
| 152 | |
| 153 | .bitrates = rtl_ratetable_5g, |
| 154 | .n_bitrates = ARRAY_SIZE(rtl_ratetable_5g), |
| 155 | |
| 156 | .ht_cap = {0}, |
| 157 | }; |
| 158 | |
| 159 | static const u8 tid_to_ac[] = { |
| 160 | 2, /* IEEE80211_AC_BE */ |
| 161 | 3, /* IEEE80211_AC_BK */ |
| 162 | 3, /* IEEE80211_AC_BK */ |
| 163 | 2, /* IEEE80211_AC_BE */ |
| 164 | 1, /* IEEE80211_AC_VI */ |
| 165 | 1, /* IEEE80211_AC_VI */ |
| 166 | 0, /* IEEE80211_AC_VO */ |
| 167 | 0, /* IEEE80211_AC_VO */ |
| 168 | }; |
| 169 | |
| 170 | u8 rtl_tid_to_ac(struct ieee80211_hw *hw, u8 tid) |
| 171 | { |
| 172 | return tid_to_ac[tid]; |
| 173 | } |
| 174 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 175 | static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw, |
| 176 | struct ieee80211_sta_ht_cap *ht_cap) |
| 177 | { |
| 178 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 179 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 180 | |
| 181 | ht_cap->ht_supported = true; |
| 182 | ht_cap->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
| 183 | IEEE80211_HT_CAP_SGI_40 | |
| 184 | IEEE80211_HT_CAP_SGI_20 | |
| 185 | IEEE80211_HT_CAP_DSSSCCK40 | IEEE80211_HT_CAP_MAX_AMSDU; |
| 186 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 187 | if (rtlpriv->rtlhal.disable_amsdu_8k) |
| 188 | ht_cap->cap &= ~IEEE80211_HT_CAP_MAX_AMSDU; |
| 189 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 190 | /* |
| 191 | *Maximum length of AMPDU that the STA can receive. |
| 192 | *Length = 2 ^ (13 + max_ampdu_length_exp) - 1 (octets) |
| 193 | */ |
| 194 | ht_cap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K; |
| 195 | |
| 196 | /*Minimum MPDU start spacing , */ |
| 197 | ht_cap->ampdu_density = IEEE80211_HT_MPDU_DENSITY_16; |
| 198 | |
| 199 | ht_cap->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; |
| 200 | |
| 201 | /* |
| 202 | *hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 203 | *base on ant_num |
| 204 | *rx_mask: RX mask |
| 205 | *if rx_ant =1 rx_mask[0]=0xff;==>MCS0-MCS7 |
| 206 | *if rx_ant =2 rx_mask[1]=0xff;==>MCS8-MCS15 |
| 207 | *if rx_ant >=3 rx_mask[2]=0xff; |
| 208 | *if BW_40 rx_mask[4]=0x01; |
| 209 | *highest supported RX rate |
| 210 | */ |
| 211 | if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_2T2R) { |
| 212 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 213 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T2R or 2T2R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 214 | |
| 215 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 216 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 217 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 218 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 219 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 220 | } else if (get_rf_type(rtlphy) == RF_1T1R) { |
| 221 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 222 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 223 | |
| 224 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 225 | ht_cap->mcs.rx_mask[1] = 0x00; |
| 226 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 227 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 228 | ht_cap->mcs.rx_highest = cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
| 233 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 234 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 235 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 236 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 237 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 238 | struct ieee80211_supported_band *sband; |
| 239 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 240 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 241 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && rtlhal->bandset == |
| 242 | BAND_ON_BOTH) { |
| 243 | /* 1: 2.4 G bands */ |
| 244 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 245 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 246 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 247 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 248 | * to default value(1T1R) */ |
| 249 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), &rtl_band_2ghz, |
| 250 | sizeof(struct ieee80211_supported_band)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 251 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 252 | /* <3> init ht cap base on ant_num */ |
| 253 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
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 | /* <4> set mac->sband to wiphy->sband */ |
| 256 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 257 | |
| 258 | /* 2: 5 G bands */ |
| 259 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 260 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 261 | |
| 262 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 263 | * to default value(1T1R) */ |
| 264 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), &rtl_band_5ghz, |
| 265 | sizeof(struct ieee80211_supported_band)); |
| 266 | |
| 267 | /* <3> init ht cap base on ant_num */ |
| 268 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 269 | |
| 270 | /* <4> set mac->sband to wiphy->sband */ |
| 271 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 272 | } else { |
| 273 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 274 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 275 | sband = &(rtlmac->bands[IEEE80211_BAND_2GHZ]); |
| 276 | |
| 277 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_2GHZ] |
| 278 | * to default value(1T1R) */ |
| 279 | memcpy(&(rtlmac->bands[IEEE80211_BAND_2GHZ]), |
| 280 | &rtl_band_2ghz, |
| 281 | sizeof(struct ieee80211_supported_band)); |
| 282 | |
| 283 | /* <3> init ht cap base on ant_num */ |
| 284 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 285 | |
| 286 | /* <4> set mac->sband to wiphy->sband */ |
| 287 | hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband; |
| 288 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 289 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
| 290 | sband = &(rtlmac->bands[IEEE80211_BAND_5GHZ]); |
| 291 | |
| 292 | /* <2> set hw->wiphy->bands[IEEE80211_BAND_5GHZ] |
| 293 | * to default value(1T1R) */ |
| 294 | memcpy(&(rtlmac->bands[IEEE80211_BAND_5GHZ]), |
| 295 | &rtl_band_5ghz, |
| 296 | sizeof(struct ieee80211_supported_band)); |
| 297 | |
| 298 | /* <3> init ht cap base on ant_num */ |
| 299 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 300 | |
| 301 | /* <4> set mac->sband to wiphy->sband */ |
| 302 | hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband; |
| 303 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 304 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Err BAND %d\n", |
| 305 | rtlhal->current_bandtype); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 306 | } |
| 307 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 308 | /* <5> set hw caps */ |
| 309 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
| 310 | IEEE80211_HW_RX_INCLUDES_FCS | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 311 | IEEE80211_HW_AMPDU_AGGREGATION | |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 312 | IEEE80211_HW_CONNECTION_MONITOR | |
| 313 | /* IEEE80211_HW_SUPPORTS_CQM_RSSI | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 314 | IEEE80211_HW_REPORTS_TX_ACK_STATUS | 0; |
| 315 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 316 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
| 317 | if (rtlpriv->psc.swctrl_lps) |
| 318 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
| 319 | IEEE80211_HW_PS_NULLFUNC_STACK | |
| 320 | /* IEEE80211_HW_SUPPORTS_DYNAMIC_PS | */ |
| 321 | 0; |
| 322 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 323 | hw->wiphy->interface_modes = |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 324 | BIT(NL80211_IFTYPE_AP) | |
| 325 | BIT(NL80211_IFTYPE_STATION) | |
| 326 | BIT(NL80211_IFTYPE_ADHOC); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 327 | |
| 328 | hw->wiphy->rts_threshold = 2347; |
| 329 | |
| 330 | hw->queues = AC_MAX; |
| 331 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; |
| 332 | |
| 333 | /* TODO: Correct this value for our hw */ |
| 334 | /* TODO: define these hard code value */ |
| 335 | hw->channel_change_time = 100; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 336 | hw->max_listen_interval = 10; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 337 | hw->max_rate_tries = 4; |
| 338 | /* hw->max_rates = 1; */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 339 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 340 | |
| 341 | /* <6> mac address */ |
| 342 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { |
| 343 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); |
| 344 | } else { |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 345 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
| 346 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); |
| 347 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | } |
| 351 | |
| 352 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) |
| 353 | { |
| 354 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 355 | |
| 356 | /* <1> timer */ |
| 357 | init_timer(&rtlpriv->works.watchdog_timer); |
| 358 | setup_timer(&rtlpriv->works.watchdog_timer, |
| 359 | rtl_watch_dog_timer_callback, (unsigned long)hw); |
| 360 | |
| 361 | /* <2> work queue */ |
| 362 | rtlpriv->works.hw = hw; |
John W. Linville | 3d986b2 | 2010-12-16 14:59:49 -0500 | [diff] [blame] | 363 | rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 364 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
| 365 | (void *)rtl_watchdog_wq_callback); |
| 366 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, |
| 367 | (void *)rtl_ips_nic_off_wq_callback); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 368 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
| 369 | (void *)rtl_swlps_wq_callback); |
| 370 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, |
| 371 | (void *)rtl_swlps_rfon_wq_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 372 | |
| 373 | } |
| 374 | |
| 375 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) |
| 376 | { |
| 377 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 378 | |
| 379 | del_timer_sync(&rtlpriv->works.watchdog_timer); |
| 380 | |
| 381 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); |
| 382 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 383 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 384 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void rtl_init_rfkill(struct ieee80211_hw *hw) |
| 388 | { |
| 389 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 390 | |
| 391 | bool radio_state; |
| 392 | bool blocked; |
| 393 | u8 valid = 0; |
| 394 | |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 395 | /*set init state to on */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 396 | rtlpriv->rfkill.rfkill_state = true; |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 397 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
| 398 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 399 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 400 | |
Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 401 | if (valid) { |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 402 | pr_info("wireless switch is %s\n", |
| 403 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 404 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 405 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 406 | |
| 407 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 408 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 409 | } |
| 410 | |
| 411 | wiphy_rfkill_start_polling(hw->wiphy); |
| 412 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 413 | EXPORT_SYMBOL(rtl_init_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 414 | |
| 415 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) |
| 416 | { |
| 417 | wiphy_rfkill_stop_polling(hw->wiphy); |
| 418 | } |
| 419 | |
| 420 | int rtl_init_core(struct ieee80211_hw *hw) |
| 421 | { |
| 422 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 423 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 424 | |
| 425 | /* <1> init mac80211 */ |
| 426 | _rtl_init_mac80211(hw); |
| 427 | rtlmac->hw = hw; |
| 428 | |
| 429 | /* <2> rate control register */ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 430 | hw->rate_control_algorithm = "rtl_rc"; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * <3> init CRDA must come after init |
| 434 | * mac80211 hw in _rtl_init_mac80211. |
| 435 | */ |
| 436 | if (rtl_regd_init(hw, rtl_reg_notifier)) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 437 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "REGD init failed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 438 | return 1; |
| 439 | } else { |
| 440 | /* CRDA regd hint must after init CRDA */ |
| 441 | if (regulatory_hint(hw->wiphy, rtlpriv->regd.alpha2)) { |
| 442 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 443 | "regulatory_hint fail\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | /* <4> locks */ |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 448 | mutex_init(&rtlpriv->locks.conf_mutex); |
Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 449 | mutex_init(&rtlpriv->locks.ps_mutex); |
Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 450 | spin_lock_init(&rtlpriv->locks.ips_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 451 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
| 452 | spin_lock_init(&rtlpriv->locks.h2c_lock); |
| 453 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); |
| 454 | spin_lock_init(&rtlpriv->locks.rf_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 455 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
| 456 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 457 | |
| 458 | rtlmac->link_state = MAC80211_NOLINK; |
| 459 | |
| 460 | /* <5> init deferred work */ |
| 461 | _rtl_init_deferred_work(hw); |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | void rtl_deinit_core(struct ieee80211_hw *hw) |
| 467 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void rtl_init_rx_config(struct ieee80211_hw *hw) |
| 471 | { |
| 472 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 473 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 474 | |
| 475 | 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] | 476 | } |
| 477 | |
| 478 | /********************************************************* |
| 479 | * |
| 480 | * tx information functions |
| 481 | * |
| 482 | *********************************************************/ |
| 483 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, |
| 484 | struct rtl_tcb_desc *tcb_desc, |
| 485 | struct ieee80211_tx_info *info) |
| 486 | { |
| 487 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 488 | u8 rate_flag = info->control.rates[0].flags; |
| 489 | |
| 490 | tcb_desc->use_shortpreamble = false; |
| 491 | |
| 492 | /* 1M can only use Long Preamble. 11B spec */ |
| 493 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) |
| 494 | return; |
| 495 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 496 | tcb_desc->use_shortpreamble = true; |
| 497 | |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 502 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 503 | struct rtl_tcb_desc *tcb_desc, |
| 504 | struct ieee80211_tx_info *info) |
| 505 | { |
| 506 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 507 | u8 rate_flag = info->control.rates[0].flags; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 508 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 509 | tcb_desc->use_shortgi = false; |
| 510 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 511 | if (sta == NULL) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 512 | return; |
| 513 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 514 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
| 515 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; |
| 516 | |
| 517 | if (!(sta->ht_cap.ht_supported)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 518 | return; |
| 519 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 520 | if (!sgi_40 && !sgi_20) |
| 521 | return; |
| 522 | |
| 523 | if (mac->opmode == NL80211_IFTYPE_STATION) |
| 524 | bw_40 = mac->bw_40; |
| 525 | else if (mac->opmode == NL80211_IFTYPE_AP || |
| 526 | mac->opmode == NL80211_IFTYPE_ADHOC) |
| 527 | bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 528 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 529 | if (bw_40 && sgi_40) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 530 | tcb_desc->use_shortgi = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 531 | else if ((bw_40 == false) && sgi_20) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 532 | tcb_desc->use_shortgi = true; |
| 533 | |
| 534 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) |
| 535 | tcb_desc->use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, |
| 539 | struct rtl_tcb_desc *tcb_desc, |
| 540 | struct ieee80211_tx_info *info) |
| 541 | { |
| 542 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 543 | u8 rate_flag = info->control.rates[0].flags; |
| 544 | |
| 545 | /* Common Settings */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 546 | tcb_desc->rts_stbc = false; |
| 547 | tcb_desc->cts_enable = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 548 | tcb_desc->rts_sc = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 549 | tcb_desc->rts_bw = false; |
| 550 | tcb_desc->rts_use_shortpreamble = false; |
| 551 | tcb_desc->rts_use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 552 | |
| 553 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 554 | /* Use CTS-to-SELF in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 555 | tcb_desc->rts_enable = true; |
| 556 | tcb_desc->cts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 557 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 558 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 559 | /* Use RTS-CTS in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 560 | tcb_desc->rts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 561 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 562 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 566 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 567 | struct rtl_tcb_desc *tcb_desc) |
| 568 | { |
| 569 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 570 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 571 | struct rtl_sta_info *sta_entry = NULL; |
| 572 | u8 ratr_index = 7; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 573 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 574 | if (sta) { |
| 575 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 576 | ratr_index = sta_entry->ratr_index; |
| 577 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 578 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 579 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 580 | tcb_desc->ratr_index = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 581 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 582 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 583 | tcb_desc->hw_rate = |
| 584 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; |
| 585 | tcb_desc->use_driver_rate = 1; |
| 586 | } else { |
| 587 | /* TODO */ |
| 588 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 589 | tcb_desc->ratr_index = ratr_index; |
| 590 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
| 591 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 592 | } |
| 593 | } |
| 594 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 595 | if (rtlpriv->dm.useramask) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 596 | /* TODO we will differentiate adhoc and station futrue */ |
| 597 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 598 | tcb_desc->mac_id = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 599 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 600 | if (mac->mode == WIRELESS_MODE_N_24G) |
| 601 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; |
| 602 | else if (mac->mode == WIRELESS_MODE_N_5G) |
| 603 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; |
| 604 | else if (mac->mode & WIRELESS_MODE_G) |
| 605 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; |
| 606 | else if (mac->mode & WIRELESS_MODE_B) |
| 607 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; |
| 608 | else if (mac->mode & WIRELESS_MODE_A) |
| 609 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; |
| 610 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
| 611 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
| 612 | if (NULL != sta) { |
| 613 | if (sta->aid > 0) |
| 614 | tcb_desc->mac_id = sta->aid + 1; |
| 615 | else |
| 616 | tcb_desc->mac_id = 1; |
| 617 | } else { |
| 618 | tcb_desc->mac_id = 0; |
| 619 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
| 623 | } |
| 624 | |
| 625 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 626 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 627 | struct rtl_tcb_desc *tcb_desc) |
| 628 | { |
| 629 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 630 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 631 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 632 | tcb_desc->packet_bw = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 633 | if (!sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 634 | return; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 635 | if (mac->opmode == NL80211_IFTYPE_AP || |
| 636 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
| 637 | if (!(sta->ht_cap.ht_supported) || |
| 638 | !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
| 639 | return; |
| 640 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 641 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) |
| 642 | return; |
| 643 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 644 | if (tcb_desc->multicast || tcb_desc->broadcast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 645 | return; |
| 646 | |
| 647 | /*use legency rate, shall use 20MHz */ |
| 648 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) |
| 649 | return; |
| 650 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 651 | tcb_desc->packet_bw = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw) |
| 655 | { |
| 656 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 657 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 658 | u8 hw_rate; |
| 659 | |
| 660 | if (get_rf_type(rtlphy) == RF_2T2R) |
| 661 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
| 662 | else |
| 663 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; |
| 664 | |
| 665 | return hw_rate; |
| 666 | } |
| 667 | |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 668 | /* mac80211's rate_idx is like this: |
| 669 | * |
| 670 | * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ |
| 671 | * |
| 672 | * B/G rate: |
| 673 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 674 | * DESC92_RATE1M-->DESC92_RATE54M ==> idx is 0-->11, |
| 675 | * |
| 676 | * N rate: |
| 677 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 678 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 679 | * |
| 680 | * 5G band:rx_status->band == IEEE80211_BAND_5GHZ |
| 681 | * A rate: |
| 682 | * (rx_status->flag & RX_FLAG_HT) = 0, |
| 683 | * DESC92_RATE6M-->DESC92_RATE54M ==> idx is 0-->7, |
| 684 | * |
| 685 | * N rate: |
| 686 | * (rx_status->flag & RX_FLAG_HT) = 1, |
| 687 | * DESC92_RATEMCS0-->DESC92_RATEMCS15 ==> idx is 0-->15 |
| 688 | */ |
| 689 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, |
| 690 | bool isht, u8 desc_rate, bool first_ampdu) |
| 691 | { |
| 692 | int rate_idx; |
| 693 | |
| 694 | if (false == isht) { |
| 695 | if (IEEE80211_BAND_2GHZ == hw->conf.channel->band) { |
| 696 | switch (desc_rate) { |
| 697 | case DESC92_RATE1M: |
| 698 | rate_idx = 0; |
| 699 | break; |
| 700 | case DESC92_RATE2M: |
| 701 | rate_idx = 1; |
| 702 | break; |
| 703 | case DESC92_RATE5_5M: |
| 704 | rate_idx = 2; |
| 705 | break; |
| 706 | case DESC92_RATE11M: |
| 707 | rate_idx = 3; |
| 708 | break; |
| 709 | case DESC92_RATE6M: |
| 710 | rate_idx = 4; |
| 711 | break; |
| 712 | case DESC92_RATE9M: |
| 713 | rate_idx = 5; |
| 714 | break; |
| 715 | case DESC92_RATE12M: |
| 716 | rate_idx = 6; |
| 717 | break; |
| 718 | case DESC92_RATE18M: |
| 719 | rate_idx = 7; |
| 720 | break; |
| 721 | case DESC92_RATE24M: |
| 722 | rate_idx = 8; |
| 723 | break; |
| 724 | case DESC92_RATE36M: |
| 725 | rate_idx = 9; |
| 726 | break; |
| 727 | case DESC92_RATE48M: |
| 728 | rate_idx = 10; |
| 729 | break; |
| 730 | case DESC92_RATE54M: |
| 731 | rate_idx = 11; |
| 732 | break; |
| 733 | default: |
| 734 | rate_idx = 0; |
| 735 | break; |
| 736 | } |
| 737 | } else { |
| 738 | switch (desc_rate) { |
| 739 | case DESC92_RATE6M: |
| 740 | rate_idx = 0; |
| 741 | break; |
| 742 | case DESC92_RATE9M: |
| 743 | rate_idx = 1; |
| 744 | break; |
| 745 | case DESC92_RATE12M: |
| 746 | rate_idx = 2; |
| 747 | break; |
| 748 | case DESC92_RATE18M: |
| 749 | rate_idx = 3; |
| 750 | break; |
| 751 | case DESC92_RATE24M: |
| 752 | rate_idx = 4; |
| 753 | break; |
| 754 | case DESC92_RATE36M: |
| 755 | rate_idx = 5; |
| 756 | break; |
| 757 | case DESC92_RATE48M: |
| 758 | rate_idx = 6; |
| 759 | break; |
| 760 | case DESC92_RATE54M: |
| 761 | rate_idx = 7; |
| 762 | break; |
| 763 | default: |
| 764 | rate_idx = 0; |
| 765 | break; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | } else { |
| 770 | |
| 771 | switch (desc_rate) { |
| 772 | case DESC92_RATEMCS0: |
| 773 | rate_idx = 0; |
| 774 | break; |
| 775 | case DESC92_RATEMCS1: |
| 776 | rate_idx = 1; |
| 777 | break; |
| 778 | case DESC92_RATEMCS2: |
| 779 | rate_idx = 2; |
| 780 | break; |
| 781 | case DESC92_RATEMCS3: |
| 782 | rate_idx = 3; |
| 783 | break; |
| 784 | case DESC92_RATEMCS4: |
| 785 | rate_idx = 4; |
| 786 | break; |
| 787 | case DESC92_RATEMCS5: |
| 788 | rate_idx = 5; |
| 789 | break; |
| 790 | case DESC92_RATEMCS6: |
| 791 | rate_idx = 6; |
| 792 | break; |
| 793 | case DESC92_RATEMCS7: |
| 794 | rate_idx = 7; |
| 795 | break; |
| 796 | case DESC92_RATEMCS8: |
| 797 | rate_idx = 8; |
| 798 | break; |
| 799 | case DESC92_RATEMCS9: |
| 800 | rate_idx = 9; |
| 801 | break; |
| 802 | case DESC92_RATEMCS10: |
| 803 | rate_idx = 10; |
| 804 | break; |
| 805 | case DESC92_RATEMCS11: |
| 806 | rate_idx = 11; |
| 807 | break; |
| 808 | case DESC92_RATEMCS12: |
| 809 | rate_idx = 12; |
| 810 | break; |
| 811 | case DESC92_RATEMCS13: |
| 812 | rate_idx = 13; |
| 813 | break; |
| 814 | case DESC92_RATEMCS14: |
| 815 | rate_idx = 14; |
| 816 | break; |
| 817 | case DESC92_RATEMCS15: |
| 818 | rate_idx = 15; |
| 819 | break; |
| 820 | default: |
| 821 | rate_idx = 0; |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | return rate_idx; |
| 826 | } |
| 827 | EXPORT_SYMBOL(rtlwifi_rate_mapping); |
| 828 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 829 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
| 830 | struct ieee80211_tx_info *info, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 831 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 832 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
| 833 | { |
| 834 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 835 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 836 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 837 | struct ieee80211_rate *txrate; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 838 | __le16 fc = hdr->frame_control; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 839 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 840 | txrate = ieee80211_get_tx_rate(hw, info); |
| 841 | tcb_desc->hw_rate = txrate->hw_value; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 842 | |
| 843 | if (ieee80211_is_data(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 844 | /* |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 845 | *we set data rate INX 0 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 846 | *in rtl_rc.c if skb is special data or |
| 847 | *mgt which need low data rate. |
| 848 | */ |
| 849 | |
| 850 | /* |
| 851 | *So tcb_desc->hw_rate is just used for |
| 852 | *special data and mgt frames |
| 853 | */ |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 854 | if (info->control.rates[0].idx == 0 || |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 855 | ieee80211_is_nullfunc(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 856 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 857 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 858 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 859 | tcb_desc->disable_ratefallback = 1; |
| 860 | } else { |
| 861 | /* |
| 862 | *because hw will nerver use hw_rate |
| 863 | *when tcb_desc->use_driver_rate = false |
| 864 | *so we never set highest N rate here, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 865 | *and N rate will all be controlled by FW |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 866 | *when tcb_desc->use_driver_rate = false |
| 867 | */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 868 | if (sta && (sta->ht_cap.ht_supported)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 869 | tcb_desc->hw_rate = _rtl_get_highest_n_rate(hw); |
| 870 | } else { |
| 871 | if (rtlmac->mode == WIRELESS_MODE_B) { |
| 872 | tcb_desc->hw_rate = |
| 873 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; |
| 874 | } else { |
| 875 | tcb_desc->hw_rate = |
| 876 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; |
| 877 | } |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 882 | tcb_desc->multicast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 883 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 884 | tcb_desc->broadcast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 885 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 886 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
| 887 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 888 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 889 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 890 | _rtl_query_protection_mode(hw, tcb_desc, info); |
| 891 | } else { |
| 892 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 893 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 894 | tcb_desc->disable_ratefallback = 1; |
| 895 | tcb_desc->mac_id = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 896 | tcb_desc->packet_bw = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | EXPORT_SYMBOL(rtl_get_tcb_desc); |
| 900 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 901 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 902 | { |
| 903 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 904 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 905 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 906 | __le16 fc = hdr->frame_control; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 907 | u8 *act = (u8 *) (((u8 *) skb->data + MAC80211_3ADDR_LEN)); |
| 908 | u8 category; |
| 909 | |
| 910 | if (!ieee80211_is_action(fc)) |
| 911 | return true; |
| 912 | |
| 913 | category = *act; |
| 914 | act++; |
| 915 | switch (category) { |
| 916 | case ACT_CAT_BA: |
| 917 | switch (*act) { |
| 918 | case ACT_ADDBAREQ: |
| 919 | if (mac->act_scanning) |
| 920 | return false; |
| 921 | |
| 922 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 923 | "%s ACT_ADDBAREQ From :%pM\n", |
| 924 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 925 | break; |
| 926 | case ACT_ADDBARSP: |
| 927 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 928 | "%s ACT_ADDBARSP From :%pM\n", |
| 929 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 930 | break; |
| 931 | case ACT_DELBA: |
| 932 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 933 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 934 | break; |
| 935 | } |
| 936 | break; |
| 937 | default: |
| 938 | break; |
| 939 | } |
| 940 | |
| 941 | return true; |
| 942 | } |
| 943 | |
| 944 | /*should call before software enc*/ |
| 945 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 946 | { |
| 947 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 948 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 949 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 950 | u16 ether_type; |
| 951 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); |
| 952 | const struct iphdr *ip; |
| 953 | |
| 954 | if (!ieee80211_is_data(fc)) |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 955 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 956 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 957 | |
| 958 | ip = (struct iphdr *)((u8 *) skb->data + mac_hdr_len + |
| 959 | SNAP_SIZE + PROTOC_TYPE_SIZE); |
| 960 | ether_type = *(u16 *) ((u8 *) skb->data + mac_hdr_len + SNAP_SIZE); |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 961 | /* ether_type = ntohs(ether_type); */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 962 | |
| 963 | if (ETH_P_IP == ether_type) { |
| 964 | if (IPPROTO_UDP == ip->protocol) { |
| 965 | struct udphdr *udp = (struct udphdr *)((u8 *) ip + |
| 966 | (ip->ihl << 2)); |
| 967 | if (((((u8 *) udp)[1] == 68) && |
| 968 | (((u8 *) udp)[3] == 67)) || |
| 969 | ((((u8 *) udp)[1] == 67) && |
| 970 | (((u8 *) udp)[3] == 68))) { |
| 971 | /* |
| 972 | * 68 : UDP BOOTP client |
| 973 | * 67 : UDP BOOTP server |
| 974 | */ |
| 975 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 976 | DBG_DMESG, "dhcp %s !!\n", |
| 977 | is_tx ? "Tx" : "Rx"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 978 | |
| 979 | if (is_tx) { |
| 980 | rtl_lps_leave(hw); |
| 981 | ppsc->last_delaylps_stamp_jiffies = |
| 982 | jiffies; |
| 983 | } |
| 984 | |
| 985 | return true; |
| 986 | } |
| 987 | } |
| 988 | } else if (ETH_P_ARP == ether_type) { |
| 989 | if (is_tx) { |
| 990 | rtl_lps_leave(hw); |
| 991 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 992 | } |
| 993 | |
| 994 | return true; |
| 995 | } else if (ETH_P_PAE == ether_type) { |
| 996 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 997 | "802.1X %s EAPOL pkt!!\n", is_tx ? "Tx" : "Rx"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 998 | |
| 999 | if (is_tx) { |
| 1000 | rtl_lps_leave(hw); |
| 1001 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1002 | } |
| 1003 | |
| 1004 | return true; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 1005 | } else if (ETH_P_IPV6 == ether_type) { |
| 1006 | /* IPv6 */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1007 | return true; |
| 1008 | } |
| 1009 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1010 | return false; |
| 1011 | } |
| 1012 | |
| 1013 | /********************************************************* |
| 1014 | * |
| 1015 | * functions called by core.c |
| 1016 | * |
| 1017 | *********************************************************/ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1018 | int rtl_tx_agg_start(struct ieee80211_hw *hw, |
| 1019 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1020 | { |
| 1021 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1022 | struct rtl_tid_data *tid_data; |
| 1023 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1024 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1025 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1026 | if (sta == NULL) |
| 1027 | return -EINVAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1028 | |
| 1029 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1030 | return -EINVAL; |
| 1031 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1032 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1033 | if (!sta_entry) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1034 | return -ENXIO; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1035 | tid_data = &sta_entry->tids[tid]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1036 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1037 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d seq:%d\n", |
| 1038 | sta->addr, tid, tid_data->seq_number); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1039 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1040 | *ssn = tid_data->seq_number; |
| 1041 | tid_data->agg.agg_state = RTL_AGG_START; |
| 1042 | |
| 1043 | ieee80211_start_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1048 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, |
| 1049 | struct ieee80211_sta *sta, u16 tid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1050 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1051 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1052 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1053 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1054 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1055 | if (sta == NULL) |
| 1056 | return -EINVAL; |
| 1057 | |
| 1058 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1059 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1063 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1064 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1065 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1066 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1067 | return -EINVAL; |
| 1068 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1069 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1070 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1071 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1072 | ieee80211_stop_tx_ba_cb_irqsafe(mac->vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1073 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1074 | return 0; |
| 1075 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1076 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1077 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
| 1078 | struct ieee80211_sta *sta, u16 tid) |
| 1079 | { |
| 1080 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1081 | struct rtl_sta_info *sta_entry = NULL; |
| 1082 | |
| 1083 | if (sta == NULL) |
| 1084 | return -EINVAL; |
| 1085 | |
| 1086 | if (!sta->addr) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1087 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "ra = NULL\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1091 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "on ra = %pM tid = %d\n", |
| 1092 | sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1093 | |
| 1094 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1095 | return -EINVAL; |
| 1096 | |
| 1097 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1098 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1099 | |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | /********************************************************* |
| 1104 | * |
| 1105 | * wq & timer callback functions |
| 1106 | * |
| 1107 | *********************************************************/ |
| 1108 | void rtl_watchdog_wq_callback(void *data) |
| 1109 | { |
| 1110 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 1111 | struct rtl_works, |
| 1112 | watchdog_wq); |
| 1113 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1114 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1115 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1116 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1117 | bool busytraffic = false; |
| 1118 | bool higher_busytraffic = false; |
| 1119 | bool higher_busyrxtraffic = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1120 | u8 idx, tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1121 | u32 rx_cnt_inp4eriod = 0; |
| 1122 | u32 tx_cnt_inp4eriod = 0; |
| 1123 | u32 aver_rx_cnt_inperiod = 0; |
| 1124 | u32 aver_tx_cnt_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1125 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
| 1126 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1127 | bool enter_ps = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1128 | |
| 1129 | if (is_hal_stop(rtlhal)) |
| 1130 | return; |
| 1131 | |
| 1132 | /* <1> Determine if action frame is allowed */ |
| 1133 | if (mac->link_state > MAC80211_NOLINK) { |
| 1134 | if (mac->cnt_after_linked < 20) |
| 1135 | mac->cnt_after_linked++; |
| 1136 | } else { |
| 1137 | mac->cnt_after_linked = 0; |
| 1138 | } |
| 1139 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1140 | /* |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 1141 | *<2> to check if traffic busy, if |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1142 | * busytraffic we don't change channel |
| 1143 | */ |
| 1144 | if (mac->link_state >= MAC80211_LINKED) { |
| 1145 | |
| 1146 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ |
| 1147 | for (idx = 0; idx <= 2; idx++) { |
| 1148 | rtlpriv->link_info.num_rx_in4period[idx] = |
| 1149 | rtlpriv->link_info.num_rx_in4period[idx + 1]; |
| 1150 | rtlpriv->link_info.num_tx_in4period[idx] = |
| 1151 | rtlpriv->link_info.num_tx_in4period[idx + 1]; |
| 1152 | } |
| 1153 | rtlpriv->link_info.num_rx_in4period[3] = |
| 1154 | rtlpriv->link_info.num_rx_inperiod; |
| 1155 | rtlpriv->link_info.num_tx_in4period[3] = |
| 1156 | rtlpriv->link_info.num_tx_inperiod; |
| 1157 | for (idx = 0; idx <= 3; idx++) { |
| 1158 | rx_cnt_inp4eriod += |
| 1159 | rtlpriv->link_info.num_rx_in4period[idx]; |
| 1160 | tx_cnt_inp4eriod += |
| 1161 | rtlpriv->link_info.num_tx_in4period[idx]; |
| 1162 | } |
| 1163 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; |
| 1164 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; |
| 1165 | |
| 1166 | /* (2) check traffic busy */ |
| 1167 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1168 | busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1169 | |
| 1170 | /* Higher Tx/Rx data. */ |
| 1171 | if (aver_rx_cnt_inperiod > 4000 || |
| 1172 | aver_tx_cnt_inperiod > 4000) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1173 | higher_busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1174 | |
| 1175 | /* Extremely high Rx data. */ |
| 1176 | if (aver_rx_cnt_inperiod > 5000) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1177 | higher_busyrxtraffic = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | /* check every tid's tx traffic */ |
| 1181 | for (tid = 0; tid <= 7; tid++) { |
| 1182 | for (idx = 0; idx <= 2; idx++) |
| 1183 | rtlpriv->link_info.tidtx_in4period[tid][idx] = |
| 1184 | rtlpriv->link_info.tidtx_in4period[tid] |
| 1185 | [idx + 1]; |
| 1186 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
| 1187 | rtlpriv->link_info.tidtx_inperiod[tid]; |
| 1188 | |
| 1189 | for (idx = 0; idx <= 3; idx++) |
| 1190 | tidtx_inp4eriod[tid] += |
| 1191 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
| 1192 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
| 1193 | if (aver_tidtx_inperiod[tid] > 5000) |
| 1194 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1195 | true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1196 | else |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1197 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
| 1198 | false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 1202 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 1203 | (rtlpriv->link_info.num_rx_inperiod > 2)) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1204 | enter_ps = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1205 | else |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1206 | enter_ps = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1207 | |
| 1208 | /* LeisurePS only work in infra mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1209 | if (enter_ps) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1210 | rtl_lps_enter(hw); |
| 1211 | else |
| 1212 | rtl_lps_leave(hw); |
| 1213 | } |
| 1214 | |
| 1215 | rtlpriv->link_info.num_rx_inperiod = 0; |
| 1216 | rtlpriv->link_info.num_tx_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1217 | for (tid = 0; tid <= 7; tid++) |
| 1218 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1219 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1220 | rtlpriv->link_info.busytraffic = busytraffic; |
| 1221 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; |
| 1222 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1223 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1224 | /* <3> DM */ |
| 1225 | rtlpriv->cfg->ops->dm_watchdog(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | void rtl_watch_dog_timer_callback(unsigned long data) |
| 1229 | { |
| 1230 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1231 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1232 | |
| 1233 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 1234 | &rtlpriv->works.watchdog_wq, 0); |
| 1235 | |
| 1236 | mod_timer(&rtlpriv->works.watchdog_timer, |
| 1237 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); |
| 1238 | } |
| 1239 | |
| 1240 | /********************************************************* |
| 1241 | * |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1242 | * frame process functions |
| 1243 | * |
| 1244 | *********************************************************/ |
| 1245 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) |
| 1246 | { |
| 1247 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1248 | u8 *pos, *end; |
| 1249 | |
| 1250 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1251 | end = data + len; |
| 1252 | while (pos < end) { |
| 1253 | if (pos + 2 + pos[1] > end) |
| 1254 | return NULL; |
| 1255 | |
| 1256 | if (pos[0] == ie) |
| 1257 | return pos; |
| 1258 | |
| 1259 | pos += 2 + pos[1]; |
| 1260 | } |
| 1261 | return NULL; |
| 1262 | } |
| 1263 | |
| 1264 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ |
| 1265 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1266 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1267 | enum ieee80211_smps_mode smps, u8 *da, u8 *bssid) |
| 1268 | { |
| 1269 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1270 | struct sk_buff *skb; |
| 1271 | struct ieee80211_mgmt *action_frame; |
| 1272 | |
| 1273 | /* 27 = header + category + action + smps mode */ |
| 1274 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); |
| 1275 | if (!skb) |
| 1276 | return NULL; |
| 1277 | |
| 1278 | skb_reserve(skb, hw->extra_tx_headroom); |
| 1279 | action_frame = (void *)skb_put(skb, 27); |
| 1280 | memset(action_frame, 0, 27); |
| 1281 | memcpy(action_frame->da, da, ETH_ALEN); |
| 1282 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); |
| 1283 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 1284 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1285 | IEEE80211_STYPE_ACTION); |
| 1286 | action_frame->u.action.category = WLAN_CATEGORY_HT; |
| 1287 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; |
| 1288 | switch (smps) { |
| 1289 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ |
| 1290 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ |
| 1291 | WARN_ON(1); |
| 1292 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
| 1293 | action_frame->u.action.u.ht_smps.smps_control = |
| 1294 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ |
| 1295 | break; |
| 1296 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ |
| 1297 | action_frame->u.action.u.ht_smps.smps_control = |
| 1298 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ |
| 1299 | break; |
| 1300 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ |
| 1301 | action_frame->u.action.u.ht_smps.smps_control = |
| 1302 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ |
| 1303 | break; |
| 1304 | } |
| 1305 | |
| 1306 | return skb; |
| 1307 | } |
| 1308 | |
| 1309 | int rtl_send_smps_action(struct ieee80211_hw *hw, |
| 1310 | struct ieee80211_sta *sta, u8 *da, u8 *bssid, |
| 1311 | enum ieee80211_smps_mode smps) |
| 1312 | { |
| 1313 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1314 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1315 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1316 | struct sk_buff *skb = rtl_make_smps_action(hw, smps, da, bssid); |
| 1317 | struct rtl_tcb_desc tcb_desc; |
| 1318 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 1319 | |
| 1320 | if (rtlpriv->mac80211.act_scanning) |
| 1321 | goto err_free; |
| 1322 | |
| 1323 | if (!sta) |
| 1324 | goto err_free; |
| 1325 | |
| 1326 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 1327 | goto err_free; |
| 1328 | |
| 1329 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 1330 | goto err_free; |
| 1331 | |
| 1332 | /* this is a type = mgmt * stype = action frame */ |
| 1333 | if (skb) { |
| 1334 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1335 | struct rtl_sta_info *sta_entry = |
| 1336 | (struct rtl_sta_info *) sta->drv_priv; |
| 1337 | sta_entry->mimo_ps = smps; |
| 1338 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
| 1339 | |
| 1340 | info->control.rates[0].idx = 0; |
| 1341 | info->control.sta = sta; |
| 1342 | info->band = hw->conf.channel->band; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1343 | rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1344 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1345 | err_free: |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
| 1349 | /********************************************************* |
| 1350 | * |
| 1351 | * IOT functions |
| 1352 | * |
| 1353 | *********************************************************/ |
| 1354 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, |
| 1355 | struct octet_string vendor_ie) |
| 1356 | { |
| 1357 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1358 | bool matched = false; |
| 1359 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; |
| 1360 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; |
| 1361 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; |
| 1362 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; |
| 1363 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; |
| 1364 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; |
| 1365 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; |
| 1366 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; |
| 1367 | |
| 1368 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || |
| 1369 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { |
| 1370 | rtlpriv->mac80211.vendor = PEER_ATH; |
| 1371 | matched = true; |
| 1372 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || |
| 1373 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || |
| 1374 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { |
| 1375 | rtlpriv->mac80211.vendor = PEER_BROAD; |
| 1376 | matched = true; |
| 1377 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { |
| 1378 | rtlpriv->mac80211.vendor = PEER_RAL; |
| 1379 | matched = true; |
| 1380 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { |
| 1381 | rtlpriv->mac80211.vendor = PEER_CISCO; |
| 1382 | matched = true; |
| 1383 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { |
| 1384 | rtlpriv->mac80211.vendor = PEER_MARV; |
| 1385 | matched = true; |
| 1386 | } |
| 1387 | |
| 1388 | return matched; |
| 1389 | } |
| 1390 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1391 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1392 | unsigned int len) |
| 1393 | { |
| 1394 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1395 | struct octet_string vendor_ie; |
| 1396 | u8 *pos, *end; |
| 1397 | |
| 1398 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1399 | end = data + len; |
| 1400 | while (pos < end) { |
| 1401 | if (pos[0] == 221) { |
| 1402 | vendor_ie.length = pos[1]; |
| 1403 | vendor_ie.octet = &pos[2]; |
| 1404 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) |
| 1405 | return true; |
| 1406 | } |
| 1407 | |
| 1408 | if (pos + 2 + pos[1] > end) |
| 1409 | return false; |
| 1410 | |
| 1411 | pos += 2 + pos[1]; |
| 1412 | } |
| 1413 | return false; |
| 1414 | } |
| 1415 | |
| 1416 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) |
| 1417 | { |
| 1418 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1419 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1420 | struct ieee80211_hdr *hdr = (void *)data; |
| 1421 | u32 vendor = PEER_UNKNOWN; |
| 1422 | |
| 1423 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; |
| 1424 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; |
| 1425 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; |
| 1426 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; |
| 1427 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; |
| 1428 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; |
| 1429 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; |
| 1430 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; |
| 1431 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; |
| 1432 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; |
| 1433 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; |
| 1434 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; |
| 1435 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; |
| 1436 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; |
| 1437 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; |
| 1438 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; |
| 1439 | |
| 1440 | if (mac->opmode != NL80211_IFTYPE_STATION) |
| 1441 | return; |
| 1442 | |
| 1443 | if (mac->link_state == MAC80211_NOLINK) { |
| 1444 | mac->vendor = PEER_UNKNOWN; |
| 1445 | return; |
| 1446 | } |
| 1447 | |
| 1448 | if (mac->cnt_after_linked > 2) |
| 1449 | return; |
| 1450 | |
| 1451 | /* check if this really is a beacon */ |
| 1452 | if (!ieee80211_is_beacon(hdr->frame_control)) |
| 1453 | return; |
| 1454 | |
| 1455 | /* min. beacon length + FCS_LEN */ |
| 1456 | if (len <= 40 + FCS_LEN) |
| 1457 | return; |
| 1458 | |
| 1459 | /* and only beacons from the associated BSSID, please */ |
| 1460 | if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid)) |
| 1461 | return; |
| 1462 | |
| 1463 | if (rtl_find_221_ie(hw, data, len)) |
| 1464 | vendor = mac->vendor; |
| 1465 | |
| 1466 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || |
| 1467 | (memcmp(mac->bssid, ap5_2, 3) == 0) || |
| 1468 | (memcmp(mac->bssid, ap5_3, 3) == 0) || |
| 1469 | (memcmp(mac->bssid, ap5_4, 3) == 0) || |
| 1470 | (memcmp(mac->bssid, ap5_5, 3) == 0) || |
| 1471 | (memcmp(mac->bssid, ap5_6, 3) == 0) || |
| 1472 | vendor == PEER_ATH) { |
| 1473 | vendor = PEER_ATH; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1474 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1475 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
| 1476 | (memcmp(mac->bssid, ap4_5, 3) == 0) || |
| 1477 | (memcmp(mac->bssid, ap4_1, 3) == 0) || |
| 1478 | (memcmp(mac->bssid, ap4_2, 3) == 0) || |
| 1479 | (memcmp(mac->bssid, ap4_3, 3) == 0) || |
| 1480 | vendor == PEER_RAL) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1481 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1482 | vendor = PEER_RAL; |
| 1483 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || |
| 1484 | vendor == PEER_CISCO) { |
| 1485 | vendor = PEER_CISCO; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1486 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1487 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
| 1488 | (memcmp(mac->bssid, ap3_2, 3) == 0) || |
| 1489 | (memcmp(mac->bssid, ap3_3, 3) == 0) || |
| 1490 | vendor == PEER_BROAD) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1491 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1492 | vendor = PEER_BROAD; |
| 1493 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || |
| 1494 | vendor == PEER_MARV) { |
| 1495 | vendor = PEER_MARV; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1496 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | mac->vendor = vendor; |
| 1500 | } |
| 1501 | |
| 1502 | /********************************************************* |
| 1503 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1504 | * sysfs functions |
| 1505 | * |
| 1506 | *********************************************************/ |
| 1507 | static ssize_t rtl_show_debug_level(struct device *d, |
| 1508 | struct device_attribute *attr, char *buf) |
| 1509 | { |
| 1510 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1511 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1512 | |
| 1513 | return sprintf(buf, "0x%08X\n", rtlpriv->dbg.global_debuglevel); |
| 1514 | } |
| 1515 | |
| 1516 | static ssize_t rtl_store_debug_level(struct device *d, |
| 1517 | struct device_attribute *attr, |
| 1518 | const char *buf, size_t count) |
| 1519 | { |
| 1520 | struct ieee80211_hw *hw = dev_get_drvdata(d); |
| 1521 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1522 | unsigned long val; |
| 1523 | int ret; |
| 1524 | |
| 1525 | ret = strict_strtoul(buf, 0, &val); |
| 1526 | if (ret) { |
| 1527 | printk(KERN_DEBUG "%s is not in hex or decimal form.\n", buf); |
| 1528 | } else { |
| 1529 | rtlpriv->dbg.global_debuglevel = val; |
| 1530 | printk(KERN_DEBUG "debuglevel:%x\n", |
| 1531 | rtlpriv->dbg.global_debuglevel); |
| 1532 | } |
| 1533 | |
| 1534 | return strnlen(buf, count); |
| 1535 | } |
| 1536 | |
| 1537 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1538 | rtl_show_debug_level, rtl_store_debug_level); |
| 1539 | |
| 1540 | static struct attribute *rtl_sysfs_entries[] = { |
| 1541 | |
| 1542 | &dev_attr_debug_level.attr, |
| 1543 | |
| 1544 | NULL |
| 1545 | }; |
| 1546 | |
| 1547 | /* |
| 1548 | * "name" is folder name witch will be |
| 1549 | * put in device directory like : |
| 1550 | * sys/devices/pci0000:00/0000:00:1c.4/ |
| 1551 | * 0000:06:00.0/rtl_sysfs |
| 1552 | */ |
| 1553 | struct attribute_group rtl_attribute_group = { |
| 1554 | .name = "rtlsysfs", |
| 1555 | .attrs = rtl_sysfs_entries, |
| 1556 | }; |
| 1557 | |
| 1558 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); |
| 1559 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); |
| 1560 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); |
| 1561 | MODULE_LICENSE("GPL"); |
| 1562 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); |
| 1563 | |
| 1564 | static int __init rtl_core_module_init(void) |
| 1565 | { |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1566 | if (rtl_rate_control_register()) |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 1567 | pr_err("Unable to register rtl_rc, use default RC !!\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1568 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1569 | return 0; |
| 1570 | } |
| 1571 | |
| 1572 | static void __exit rtl_core_module_exit(void) |
| 1573 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1574 | /*RC*/ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 1575 | rtl_rate_control_unregister(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | module_init(rtl_core_module_init); |
| 1579 | module_exit(rtl_core_module_exit); |