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