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 = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 134 | .band = NL80211_BAND_2GHZ, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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 = { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 146 | .band = NL80211_BAND_5GHZ, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 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 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 200 | /*hw->wiphy->bands[NL80211_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 | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 210 | pr_info("Support phy mode switch\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 211 | |
| 212 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 213 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 214 | ht_cap->mcs.rx_mask[4] = 0x01; |
| 215 | |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 216 | 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] | 217 | } else { |
| 218 | if (get_rf_type(rtlphy) == RF_1T2R || |
| 219 | get_rf_type(rtlphy) == RF_2T2R) { |
| 220 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 221 | "1T2R or 2T2R\n"); |
| 222 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 223 | ht_cap->mcs.rx_mask[1] = 0xFF; |
| 224 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 225 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 226 | ht_cap->mcs.rx_highest = |
| 227 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS15); |
| 228 | } else if (get_rf_type(rtlphy) == RF_1T1R) { |
| 229 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "1T1R\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 230 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 231 | ht_cap->mcs.rx_mask[0] = 0xFF; |
| 232 | ht_cap->mcs.rx_mask[1] = 0x00; |
| 233 | ht_cap->mcs.rx_mask[4] = 0x01; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 234 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 235 | ht_cap->mcs.rx_highest = |
| 236 | cpu_to_le16(MAX_BIT_RATE_40MHZ_MCS7); |
| 237 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 241 | static void _rtl_init_hw_vht_capab(struct ieee80211_hw *hw, |
| 242 | struct ieee80211_sta_vht_cap *vht_cap) |
| 243 | { |
| 244 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 245 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 246 | |
| 247 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8812AE) { |
| 248 | u16 mcs_map; |
| 249 | |
| 250 | vht_cap->vht_supported = true; |
| 251 | vht_cap->cap = |
| 252 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 | |
| 253 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | |
| 254 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 255 | IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 256 | IEEE80211_VHT_CAP_TXSTBC | |
| 257 | IEEE80211_VHT_CAP_RXSTBC_1 | |
| 258 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 259 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 260 | IEEE80211_VHT_CAP_HTC_VHT | |
| 261 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | |
| 262 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | |
| 263 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | |
| 264 | 0; |
| 265 | |
| 266 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 267 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | |
| 268 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | |
| 269 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | |
| 270 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | |
| 271 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | |
| 272 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | |
| 273 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; |
| 274 | |
| 275 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 276 | vht_cap->vht_mcs.rx_highest = |
| 277 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); |
| 278 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 279 | vht_cap->vht_mcs.tx_highest = |
| 280 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_2NSS_80MHZ_MCS9); |
| 281 | } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8821AE) { |
| 282 | u16 mcs_map; |
| 283 | |
| 284 | vht_cap->vht_supported = true; |
| 285 | vht_cap->cap = |
| 286 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895 | |
| 287 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | |
| 288 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | |
| 289 | IEEE80211_VHT_CAP_SHORT_GI_80 | |
| 290 | IEEE80211_VHT_CAP_TXSTBC | |
| 291 | IEEE80211_VHT_CAP_RXSTBC_1 | |
| 292 | IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | |
| 293 | IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | |
| 294 | IEEE80211_VHT_CAP_HTC_VHT | |
| 295 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK | |
| 296 | IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN | |
| 297 | IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN | |
| 298 | 0; |
| 299 | |
| 300 | mcs_map = IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
| 301 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 2 | |
| 302 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 4 | |
| 303 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 6 | |
| 304 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 8 | |
| 305 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 10 | |
| 306 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 12 | |
| 307 | IEEE80211_VHT_MCS_NOT_SUPPORTED << 14; |
| 308 | |
| 309 | vht_cap->vht_mcs.rx_mcs_map = cpu_to_le16(mcs_map); |
| 310 | vht_cap->vht_mcs.rx_highest = |
| 311 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); |
| 312 | vht_cap->vht_mcs.tx_mcs_map = cpu_to_le16(mcs_map); |
| 313 | vht_cap->vht_mcs.tx_highest = |
| 314 | cpu_to_le16(MAX_BIT_RATE_SHORT_GI_1NSS_80MHZ_MCS9); |
| 315 | } |
| 316 | } |
| 317 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 318 | static void _rtl_init_mac80211(struct ieee80211_hw *hw) |
| 319 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 320 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 321 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 322 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 323 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 324 | struct ieee80211_supported_band *sband; |
| 325 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 326 | if (rtlhal->macphymode == SINGLEMAC_SINGLEPHY && |
| 327 | rtlhal->bandset == BAND_ON_BOTH) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 328 | /* 1: 2.4 G bands */ |
| 329 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 330 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 331 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 332 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 333 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 334 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), &rtl_band_2ghz, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 335 | sizeof(struct ieee80211_supported_band)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 336 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 337 | /* <3> init ht cap base on ant_num */ |
| 338 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 339 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 340 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 341 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 342 | |
| 343 | /* 2: 5 G bands */ |
| 344 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 345 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 346 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 347 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 348 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 349 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), &rtl_band_5ghz, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 350 | sizeof(struct ieee80211_supported_band)); |
| 351 | |
| 352 | /* <3> init ht cap base on ant_num */ |
| 353 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 354 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 355 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 356 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 357 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 358 | } else { |
| 359 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 360 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 361 | sband = &(rtlmac->bands[NL80211_BAND_2GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 362 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 363 | /* <2> set hw->wiphy->bands[NL80211_BAND_2GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 364 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 365 | memcpy(&(rtlmac->bands[NL80211_BAND_2GHZ]), |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 366 | &rtl_band_2ghz, |
| 367 | sizeof(struct ieee80211_supported_band)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 368 | |
| 369 | /* <3> init ht cap base on ant_num */ |
| 370 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 371 | |
| 372 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 373 | hw->wiphy->bands[NL80211_BAND_2GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 374 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 375 | /* <1> use mac->bands as mem for hw->wiphy->bands */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 376 | sband = &(rtlmac->bands[NL80211_BAND_5GHZ]); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 377 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 378 | /* <2> set hw->wiphy->bands[NL80211_BAND_5GHZ] |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 379 | * to default value(1T1R) */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 380 | memcpy(&(rtlmac->bands[NL80211_BAND_5GHZ]), |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 381 | &rtl_band_5ghz, |
| 382 | sizeof(struct ieee80211_supported_band)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 383 | |
| 384 | /* <3> init ht cap base on ant_num */ |
| 385 | _rtl_init_hw_ht_capab(hw, &sband->ht_cap); |
| 386 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 387 | _rtl_init_hw_vht_capab(hw, &sband->vht_cap); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 388 | /* <4> set mac->sband to wiphy->sband */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 389 | hw->wiphy->bands[NL80211_BAND_5GHZ] = sband; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 390 | } else { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 391 | pr_err("Err BAND %d\n", |
| 392 | rtlhal->current_bandtype); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 393 | } |
| 394 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 395 | /* <5> set hw caps */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 396 | ieee80211_hw_set(hw, SIGNAL_DBM); |
| 397 | ieee80211_hw_set(hw, RX_INCLUDES_FCS); |
| 398 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
| 399 | ieee80211_hw_set(hw, CONNECTION_MONITOR); |
| 400 | ieee80211_hw_set(hw, MFP_CAPABLE); |
| 401 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 402 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 403 | /* swlps or hwlps has been set in diff chip in init_sw_vars */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 404 | if (rtlpriv->psc.swctrl_lps) { |
| 405 | ieee80211_hw_set(hw, SUPPORTS_PS); |
| 406 | ieee80211_hw_set(hw, PS_NULLFUNC_STACK); |
| 407 | } |
Ping-Ke Shih | e332e2a2 | 2017-06-18 11:12:42 -0500 | [diff] [blame] | 408 | if (rtlpriv->psc.fwctrl_lps) { |
| 409 | ieee80211_hw_set(hw, SUPPORTS_PS); |
| 410 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); |
| 411 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 412 | hw->wiphy->interface_modes = |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 413 | BIT(NL80211_IFTYPE_AP) | |
| 414 | BIT(NL80211_IFTYPE_STATION) | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 415 | BIT(NL80211_IFTYPE_ADHOC) | |
| 416 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 417 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 418 | BIT(NL80211_IFTYPE_P2P_GO); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 419 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 420 | |
| 421 | hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
| 422 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 423 | hw->wiphy->rts_threshold = 2347; |
| 424 | |
| 425 | hw->queues = AC_MAX; |
| 426 | hw->extra_tx_headroom = RTL_TX_HEADER_SIZE; |
| 427 | |
| 428 | /* TODO: Correct this value for our hw */ |
| 429 | /* TODO: define these hard code value */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 430 | hw->max_listen_interval = 10; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 431 | hw->max_rate_tries = 4; |
| 432 | /* hw->max_rates = 1; */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 433 | hw->sta_data_size = sizeof(struct rtl_sta_info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 434 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 435 | /* wowlan is not supported by kernel if CONFIG_PM is not defined */ |
| 436 | #ifdef CONFIG_PM |
| 437 | if (rtlpriv->psc.wo_wlan_mode) { |
| 438 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_MAGIC_PACKET) |
| 439 | rtlpriv->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT; |
| 440 | if (rtlpriv->psc.wo_wlan_mode & WAKE_ON_PATTERN_MATCH) { |
| 441 | rtlpriv->wowlan.n_patterns = |
| 442 | MAX_SUPPORT_WOL_PATTERN_NUM; |
| 443 | rtlpriv->wowlan.pattern_min_len = MIN_WOL_PATTERN_SIZE; |
| 444 | rtlpriv->wowlan.pattern_max_len = MAX_WOL_PATTERN_SIZE; |
| 445 | } |
| 446 | hw->wiphy->wowlan = &rtlpriv->wowlan; |
| 447 | } |
| 448 | #endif |
| 449 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 450 | /* <6> mac address */ |
| 451 | if (is_valid_ether_addr(rtlefuse->dev_addr)) { |
| 452 | SET_IEEE80211_PERM_ADDR(hw, rtlefuse->dev_addr); |
| 453 | } else { |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 454 | u8 rtlmac1[] = { 0x00, 0xe0, 0x4c, 0x81, 0x92, 0x00 }; |
| 455 | get_random_bytes((rtlmac1 + (ETH_ALEN - 1)), 1); |
| 456 | SET_IEEE80211_PERM_ADDR(hw, rtlmac1); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 457 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void _rtl_init_deferred_work(struct ieee80211_hw *hw) |
| 461 | { |
| 462 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 463 | |
| 464 | /* <1> timer */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 465 | setup_timer(&rtlpriv->works.watchdog_timer, |
| 466 | rtl_watch_dog_timer_callback, (unsigned long)hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 467 | setup_timer(&rtlpriv->works.dualmac_easyconcurrent_retrytimer, |
| 468 | rtl_easy_concurrent_retrytimer_callback, (unsigned long)hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 469 | /* <2> work queue */ |
| 470 | rtlpriv->works.hw = hw; |
Kees Cook | 598a0df | 2014-10-20 14:57:08 -0700 | [diff] [blame] | 471 | rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 472 | INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, |
| 473 | (void *)rtl_watchdog_wq_callback); |
| 474 | INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, |
| 475 | (void *)rtl_ips_nic_off_wq_callback); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 476 | INIT_DELAYED_WORK(&rtlpriv->works.ps_work, |
| 477 | (void *)rtl_swlps_wq_callback); |
| 478 | INIT_DELAYED_WORK(&rtlpriv->works.ps_rfon_wq, |
| 479 | (void *)rtl_swlps_rfon_wq_callback); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 480 | INIT_DELAYED_WORK(&rtlpriv->works.fwevt_wq, |
| 481 | (void *)rtl_fwevt_wq_callback); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 482 | INIT_DELAYED_WORK(&rtlpriv->works.c2hcmd_wq, |
| 483 | (void *)rtl_c2hcmd_wq_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 484 | |
| 485 | } |
| 486 | |
| 487 | void rtl_deinit_deferred_work(struct ieee80211_hw *hw) |
| 488 | { |
| 489 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 490 | |
| 491 | del_timer_sync(&rtlpriv->works.watchdog_timer); |
| 492 | |
| 493 | cancel_delayed_work(&rtlpriv->works.watchdog_wq); |
| 494 | cancel_delayed_work(&rtlpriv->works.ips_nic_off_wq); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 495 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 496 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 497 | cancel_delayed_work(&rtlpriv->works.fwevt_wq); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 498 | cancel_delayed_work(&rtlpriv->works.c2hcmd_wq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 499 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 500 | EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 501 | |
| 502 | void rtl_init_rfkill(struct ieee80211_hw *hw) |
| 503 | { |
| 504 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 505 | |
| 506 | bool radio_state; |
| 507 | bool blocked; |
| 508 | u8 valid = 0; |
| 509 | |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 510 | /*set init state to on */ |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 511 | rtlpriv->rfkill.rfkill_state = true; |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 512 | wiphy_rfkill_set_hw_state(hw->wiphy, 0); |
| 513 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 514 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 515 | |
Larry Finger | e6d8a81 | 2010-12-21 19:40:40 -0600 | [diff] [blame] | 516 | if (valid) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 517 | pr_info("rtlwifi: wireless switch is %s\n", |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 518 | rtlpriv->rfkill.rfkill_state ? "on" : "off"); |
Chaoming Li | 228bdfc | 2011-04-10 18:30:23 -0500 | [diff] [blame] | 519 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 520 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 521 | |
| 522 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 523 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 524 | } |
| 525 | |
| 526 | wiphy_rfkill_start_polling(hw->wiphy); |
| 527 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 528 | EXPORT_SYMBOL(rtl_init_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 529 | |
| 530 | void rtl_deinit_rfkill(struct ieee80211_hw *hw) |
| 531 | { |
| 532 | wiphy_rfkill_stop_polling(hw->wiphy); |
| 533 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 534 | EXPORT_SYMBOL_GPL(rtl_deinit_rfkill); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 535 | |
| 536 | int rtl_init_core(struct ieee80211_hw *hw) |
| 537 | { |
| 538 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 539 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
| 540 | |
| 541 | /* <1> init mac80211 */ |
| 542 | _rtl_init_mac80211(hw); |
| 543 | rtlmac->hw = hw; |
| 544 | |
| 545 | /* <2> rate control register */ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 546 | hw->rate_control_algorithm = "rtl_rc"; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * <3> init CRDA must come after init |
| 550 | * mac80211 hw in _rtl_init_mac80211. |
| 551 | */ |
| 552 | if (rtl_regd_init(hw, rtl_reg_notifier)) { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 553 | pr_err("REGD init failed\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 554 | return 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* <4> locks */ |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 558 | mutex_init(&rtlpriv->locks.conf_mutex); |
Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 559 | spin_lock_init(&rtlpriv->locks.ips_lock); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 560 | spin_lock_init(&rtlpriv->locks.irq_th_lock); |
| 561 | spin_lock_init(&rtlpriv->locks.h2c_lock); |
| 562 | spin_lock_init(&rtlpriv->locks.rf_ps_lock); |
| 563 | spin_lock_init(&rtlpriv->locks.rf_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 564 | spin_lock_init(&rtlpriv->locks.waitq_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 565 | spin_lock_init(&rtlpriv->locks.entry_list_lock); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 566 | spin_lock_init(&rtlpriv->locks.c2hcmd_lock); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 567 | spin_lock_init(&rtlpriv->locks.cck_and_rw_pagea_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 568 | spin_lock_init(&rtlpriv->locks.check_sendpkt_lock); |
| 569 | spin_lock_init(&rtlpriv->locks.fw_ps_lock); |
| 570 | spin_lock_init(&rtlpriv->locks.lps_lock); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 571 | spin_lock_init(&rtlpriv->locks.iqk_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 572 | /* <5> init list */ |
| 573 | INIT_LIST_HEAD(&rtlpriv->entry_list); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 574 | INIT_LIST_HEAD(&rtlpriv->c2hcmd_list); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 575 | |
| 576 | rtlmac->link_state = MAC80211_NOLINK; |
| 577 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 578 | /* <6> init deferred work */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 579 | _rtl_init_deferred_work(hw); |
| 580 | |
| 581 | return 0; |
| 582 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 583 | EXPORT_SYMBOL_GPL(rtl_init_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 584 | |
| 585 | void rtl_deinit_core(struct ieee80211_hw *hw) |
| 586 | { |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 587 | rtl_c2hcmd_launcher(hw, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 588 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 589 | EXPORT_SYMBOL_GPL(rtl_deinit_core); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 590 | |
| 591 | void rtl_init_rx_config(struct ieee80211_hw *hw) |
| 592 | { |
| 593 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 594 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 595 | |
| 596 | 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] | 597 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 598 | EXPORT_SYMBOL_GPL(rtl_init_rx_config); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 599 | |
| 600 | /********************************************************* |
| 601 | * |
| 602 | * tx information functions |
| 603 | * |
| 604 | *********************************************************/ |
| 605 | static void _rtl_qurey_shortpreamble_mode(struct ieee80211_hw *hw, |
| 606 | struct rtl_tcb_desc *tcb_desc, |
| 607 | struct ieee80211_tx_info *info) |
| 608 | { |
| 609 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 610 | u8 rate_flag = info->control.rates[0].flags; |
| 611 | |
| 612 | tcb_desc->use_shortpreamble = false; |
| 613 | |
| 614 | /* 1M can only use Long Preamble. 11B spec */ |
| 615 | if (tcb_desc->hw_rate == rtlpriv->cfg->maps[RTL_RC_CCK_RATE1M]) |
| 616 | return; |
| 617 | else if (rate_flag & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) |
| 618 | tcb_desc->use_shortpreamble = true; |
| 619 | |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | static void _rtl_query_shortgi(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 624 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 625 | struct rtl_tcb_desc *tcb_desc, |
| 626 | struct ieee80211_tx_info *info) |
| 627 | { |
| 628 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 629 | u8 rate_flag = info->control.rates[0].flags; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 630 | u8 sgi_40 = 0, sgi_20 = 0, bw_40 = 0; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 631 | u8 sgi_80 = 0, bw_80 = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 632 | tcb_desc->use_shortgi = false; |
| 633 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 634 | if (sta == NULL) |
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 | sgi_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40; |
| 638 | sgi_20 = sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 639 | sgi_80 = sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 640 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 641 | if ((!sta->ht_cap.ht_supported) && (!sta->vht_cap.vht_supported)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 642 | return; |
| 643 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 644 | if (!sgi_40 && !sgi_20) |
| 645 | return; |
| 646 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 647 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 648 | bw_40 = mac->bw_40; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 649 | bw_80 = mac->bw_80; |
| 650 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 651 | mac->opmode == NL80211_IFTYPE_ADHOC || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 652 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
| 653 | bw_40 = sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 654 | bw_80 = sta->vht_cap.vht_supported; |
| 655 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 656 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 657 | if (bw_80) { |
| 658 | if (sgi_80) |
| 659 | tcb_desc->use_shortgi = true; |
| 660 | else |
| 661 | tcb_desc->use_shortgi = false; |
| 662 | } else { |
| 663 | if (bw_40 && sgi_40) |
| 664 | tcb_desc->use_shortgi = true; |
| 665 | else if (!bw_40 && sgi_20) |
| 666 | tcb_desc->use_shortgi = true; |
| 667 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 668 | |
| 669 | if (!(rate_flag & IEEE80211_TX_RC_SHORT_GI)) |
| 670 | tcb_desc->use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | static void _rtl_query_protection_mode(struct ieee80211_hw *hw, |
| 674 | struct rtl_tcb_desc *tcb_desc, |
| 675 | struct ieee80211_tx_info *info) |
| 676 | { |
| 677 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 678 | u8 rate_flag = info->control.rates[0].flags; |
| 679 | |
| 680 | /* Common Settings */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 681 | tcb_desc->rts_stbc = false; |
| 682 | tcb_desc->cts_enable = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 683 | tcb_desc->rts_sc = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 684 | tcb_desc->rts_bw = false; |
| 685 | tcb_desc->rts_use_shortpreamble = false; |
| 686 | tcb_desc->rts_use_shortgi = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 687 | |
| 688 | if (rate_flag & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
| 689 | /* Use CTS-to-SELF in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 690 | tcb_desc->rts_enable = true; |
| 691 | tcb_desc->cts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 692 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 693 | } else if (rate_flag & IEEE80211_TX_RC_USE_RTS_CTS) { |
| 694 | /* Use RTS-CTS in protection mode. */ |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 695 | tcb_desc->rts_enable = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 696 | tcb_desc->rts_rate = rtlpriv->cfg->maps[RTL_RC_OFDM_RATE24M]; |
| 697 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static void _rtl_txrate_selectmode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 701 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 702 | struct rtl_tcb_desc *tcb_desc) |
| 703 | { |
| 704 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 705 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 706 | struct rtl_sta_info *sta_entry = NULL; |
| 707 | u8 ratr_index = 7; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 708 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 709 | if (sta) { |
| 710 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 711 | ratr_index = sta_entry->ratr_index; |
| 712 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 713 | if (!tcb_desc->disable_ratefallback || !tcb_desc->use_driver_rate) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 714 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 715 | tcb_desc->ratr_index = 0; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 716 | } else if (mac->opmode == NL80211_IFTYPE_ADHOC || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 717 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 718 | if (tcb_desc->multicast || tcb_desc->broadcast) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 719 | tcb_desc->hw_rate = |
| 720 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE2M]; |
| 721 | tcb_desc->use_driver_rate = 1; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 722 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 723 | } else { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 724 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 725 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 726 | } else if (mac->opmode == NL80211_IFTYPE_AP) { |
| 727 | tcb_desc->ratr_index = ratr_index; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 731 | if (rtlpriv->dm.useramask) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 732 | tcb_desc->ratr_index = ratr_index; |
| 733 | /* TODO we will differentiate adhoc and station future */ |
| 734 | if (mac->opmode == NL80211_IFTYPE_STATION || |
| 735 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 736 | tcb_desc->mac_id = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 737 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 738 | if (mac->mode == WIRELESS_MODE_AC_5G) |
| 739 | tcb_desc->ratr_index = |
| 740 | RATR_INX_WIRELESS_AC_5N; |
| 741 | else if (mac->mode == WIRELESS_MODE_AC_24G) |
| 742 | tcb_desc->ratr_index = |
| 743 | RATR_INX_WIRELESS_AC_24N; |
| 744 | else if (mac->mode == WIRELESS_MODE_N_24G) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 745 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NGB; |
| 746 | else if (mac->mode == WIRELESS_MODE_N_5G) |
| 747 | tcb_desc->ratr_index = RATR_INX_WIRELESS_NG; |
| 748 | else if (mac->mode & WIRELESS_MODE_G) |
| 749 | tcb_desc->ratr_index = RATR_INX_WIRELESS_GB; |
| 750 | else if (mac->mode & WIRELESS_MODE_B) |
| 751 | tcb_desc->ratr_index = RATR_INX_WIRELESS_B; |
| 752 | else if (mac->mode & WIRELESS_MODE_A) |
| 753 | tcb_desc->ratr_index = RATR_INX_WIRELESS_G; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 754 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 755 | } else if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 756 | mac->opmode == NL80211_IFTYPE_ADHOC) { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 757 | if (NULL != sta) { |
| 758 | if (sta->aid > 0) |
| 759 | tcb_desc->mac_id = sta->aid + 1; |
| 760 | else |
| 761 | tcb_desc->mac_id = 1; |
| 762 | } else { |
| 763 | tcb_desc->mac_id = 0; |
| 764 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 765 | } |
| 766 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static void _rtl_query_bandwidth_mode(struct ieee80211_hw *hw, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 770 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 771 | struct rtl_tcb_desc *tcb_desc) |
| 772 | { |
| 773 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 774 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 775 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 776 | tcb_desc->packet_bw = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 777 | if (!sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 778 | return; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 779 | if (mac->opmode == NL80211_IFTYPE_AP || |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 780 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 781 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 782 | if (!(sta->ht_cap.ht_supported) || |
| 783 | !(sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 784 | return; |
| 785 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 786 | if (!mac->bw_40 || !(sta->ht_cap.ht_supported)) |
| 787 | return; |
| 788 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 789 | if (tcb_desc->multicast || tcb_desc->broadcast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 790 | return; |
| 791 | |
| 792 | /*use legency rate, shall use 20MHz */ |
| 793 | if (tcb_desc->hw_rate <= rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]) |
| 794 | return; |
| 795 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 796 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_20_40; |
| 797 | |
| 798 | if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8812AE || |
| 799 | rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8821AE) { |
| 800 | if (mac->opmode == NL80211_IFTYPE_AP || |
| 801 | mac->opmode == NL80211_IFTYPE_ADHOC || |
| 802 | mac->opmode == NL80211_IFTYPE_MESH_POINT) { |
| 803 | if (!(sta->vht_cap.vht_supported)) |
| 804 | return; |
| 805 | } else if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 806 | if (!mac->bw_80 || |
| 807 | !(sta->vht_cap.vht_supported)) |
| 808 | return; |
| 809 | } |
| 810 | if (tcb_desc->hw_rate <= |
| 811 | rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]) |
| 812 | return; |
| 813 | tcb_desc->packet_bw = HT_CHANNEL_WIDTH_80; |
| 814 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 815 | } |
| 816 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 817 | static u8 _rtl_get_vht_highest_n_rate(struct ieee80211_hw *hw, |
| 818 | struct ieee80211_sta *sta) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 819 | { |
| 820 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 821 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 822 | u8 hw_rate; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 823 | 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] | 824 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 825 | if ((get_rf_type(rtlphy) == RF_2T2R) && |
| 826 | (tx_mcs_map & 0x000c) != 0x000c) { |
| 827 | if ((tx_mcs_map & 0x000c) >> 2 == |
| 828 | IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 829 | hw_rate = |
| 830 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS7]; |
| 831 | else if ((tx_mcs_map & 0x000c) >> 2 == |
| 832 | IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 833 | hw_rate = |
| 834 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; |
| 835 | else |
| 836 | hw_rate = |
| 837 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_2SS_MCS9]; |
| 838 | } else { |
| 839 | if ((tx_mcs_map & 0x0003) == |
| 840 | IEEE80211_VHT_MCS_SUPPORT_0_7) |
| 841 | hw_rate = |
| 842 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS7]; |
| 843 | else if ((tx_mcs_map & 0x0003) == |
| 844 | IEEE80211_VHT_MCS_SUPPORT_0_8) |
| 845 | hw_rate = |
| 846 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; |
| 847 | else |
| 848 | hw_rate = |
| 849 | rtlpriv->cfg->maps[RTL_RC_VHT_RATE_1SS_MCS9]; |
| 850 | } |
| 851 | |
| 852 | return hw_rate; |
| 853 | } |
| 854 | |
| 855 | static u8 _rtl_get_highest_n_rate(struct ieee80211_hw *hw, |
| 856 | struct ieee80211_sta *sta) |
| 857 | { |
| 858 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 859 | struct rtl_phy *rtlphy = &rtlpriv->phy; |
| 860 | u8 hw_rate; |
| 861 | |
| 862 | if ((get_rf_type(rtlphy) == RF_2T2R) && |
| 863 | (sta->ht_cap.mcs.rx_mask[1] != 0)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 864 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS15]; |
| 865 | else |
| 866 | hw_rate = rtlpriv->cfg->maps[RTL_RC_HT_RATEMCS7]; |
| 867 | |
| 868 | return hw_rate; |
| 869 | } |
| 870 | |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 871 | /* mac80211's rate_idx is like this: |
| 872 | * |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 873 | * 2.4G band:rx_status->band == NL80211_BAND_2GHZ |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 874 | * |
| 875 | * B/G rate: |
| 876 | * (rx_status->flag & RX_FLAG_HT) = 0, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 877 | * DESC_RATE1M-->DESC_RATE54M ==> idx is 0-->11, |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 878 | * |
| 879 | * N rate: |
| 880 | * (rx_status->flag & RX_FLAG_HT) = 1, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 881 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 882 | * |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 883 | * 5G band:rx_status->band == NL80211_BAND_5GHZ |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 884 | * A rate: |
| 885 | * (rx_status->flag & RX_FLAG_HT) = 0, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 886 | * DESC_RATE6M-->DESC_RATE54M ==> idx is 0-->7, |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 887 | * |
| 888 | * N rate: |
| 889 | * (rx_status->flag & RX_FLAG_HT) = 1, |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 890 | * DESC_RATEMCS0-->DESC_RATEMCS15 ==> idx is 0-->15 |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 891 | * |
| 892 | * VHT rates: |
| 893 | * DESC_RATEVHT1SS_MCS0-->DESC_RATEVHT1SS_MCS9 ==> idx is 0-->9 |
| 894 | * DESC_RATEVHT2SS_MCS0-->DESC_RATEVHT2SS_MCS9 ==> idx is 0-->9 |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 895 | */ |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 896 | int rtlwifi_rate_mapping(struct ieee80211_hw *hw, bool isht, bool isvht, |
| 897 | u8 desc_rate) |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 898 | { |
| 899 | int rate_idx; |
| 900 | |
Larry Finger | fd3cb22 | 2014-12-18 03:05:40 -0600 | [diff] [blame] | 901 | if (isvht) { |
| 902 | switch (desc_rate) { |
| 903 | case DESC_RATEVHT1SS_MCS0: |
| 904 | rate_idx = 0; |
| 905 | break; |
| 906 | case DESC_RATEVHT1SS_MCS1: |
| 907 | rate_idx = 1; |
| 908 | break; |
| 909 | case DESC_RATEVHT1SS_MCS2: |
| 910 | rate_idx = 2; |
| 911 | break; |
| 912 | case DESC_RATEVHT1SS_MCS3: |
| 913 | rate_idx = 3; |
| 914 | break; |
| 915 | case DESC_RATEVHT1SS_MCS4: |
| 916 | rate_idx = 4; |
| 917 | break; |
| 918 | case DESC_RATEVHT1SS_MCS5: |
| 919 | rate_idx = 5; |
| 920 | break; |
| 921 | case DESC_RATEVHT1SS_MCS6: |
| 922 | rate_idx = 6; |
| 923 | break; |
| 924 | case DESC_RATEVHT1SS_MCS7: |
| 925 | rate_idx = 7; |
| 926 | break; |
| 927 | case DESC_RATEVHT1SS_MCS8: |
| 928 | rate_idx = 8; |
| 929 | break; |
| 930 | case DESC_RATEVHT1SS_MCS9: |
| 931 | rate_idx = 9; |
| 932 | break; |
| 933 | case DESC_RATEVHT2SS_MCS0: |
| 934 | rate_idx = 0; |
| 935 | break; |
| 936 | case DESC_RATEVHT2SS_MCS1: |
| 937 | rate_idx = 1; |
| 938 | break; |
| 939 | case DESC_RATEVHT2SS_MCS2: |
| 940 | rate_idx = 2; |
| 941 | break; |
| 942 | case DESC_RATEVHT2SS_MCS3: |
| 943 | rate_idx = 3; |
| 944 | break; |
| 945 | case DESC_RATEVHT2SS_MCS4: |
| 946 | rate_idx = 4; |
| 947 | break; |
| 948 | case DESC_RATEVHT2SS_MCS5: |
| 949 | rate_idx = 5; |
| 950 | break; |
| 951 | case DESC_RATEVHT2SS_MCS6: |
| 952 | rate_idx = 6; |
| 953 | break; |
| 954 | case DESC_RATEVHT2SS_MCS7: |
| 955 | rate_idx = 7; |
| 956 | break; |
| 957 | case DESC_RATEVHT2SS_MCS8: |
| 958 | rate_idx = 8; |
| 959 | break; |
| 960 | case DESC_RATEVHT2SS_MCS9: |
| 961 | rate_idx = 9; |
| 962 | break; |
| 963 | default: |
| 964 | rate_idx = 0; |
| 965 | break; |
| 966 | } |
| 967 | return rate_idx; |
| 968 | } |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 969 | if (false == isht) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 970 | if (NL80211_BAND_2GHZ == hw->conf.chandef.chan->band) { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 971 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 972 | case DESC_RATE1M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 973 | rate_idx = 0; |
| 974 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 975 | case DESC_RATE2M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 976 | rate_idx = 1; |
| 977 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 978 | case DESC_RATE5_5M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 979 | rate_idx = 2; |
| 980 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 981 | case DESC_RATE11M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 982 | rate_idx = 3; |
| 983 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 984 | case DESC_RATE6M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 985 | rate_idx = 4; |
| 986 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 987 | case DESC_RATE9M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 988 | rate_idx = 5; |
| 989 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 990 | case DESC_RATE12M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 991 | rate_idx = 6; |
| 992 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 993 | case DESC_RATE18M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 994 | rate_idx = 7; |
| 995 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 996 | case DESC_RATE24M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 997 | rate_idx = 8; |
| 998 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 999 | case DESC_RATE36M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1000 | rate_idx = 9; |
| 1001 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1002 | case DESC_RATE48M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1003 | rate_idx = 10; |
| 1004 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1005 | case DESC_RATE54M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1006 | rate_idx = 11; |
| 1007 | break; |
| 1008 | default: |
| 1009 | rate_idx = 0; |
| 1010 | break; |
| 1011 | } |
| 1012 | } else { |
| 1013 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1014 | case DESC_RATE6M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1015 | rate_idx = 0; |
| 1016 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1017 | case DESC_RATE9M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1018 | rate_idx = 1; |
| 1019 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1020 | case DESC_RATE12M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1021 | rate_idx = 2; |
| 1022 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1023 | case DESC_RATE18M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1024 | rate_idx = 3; |
| 1025 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1026 | case DESC_RATE24M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1027 | rate_idx = 4; |
| 1028 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1029 | case DESC_RATE36M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1030 | rate_idx = 5; |
| 1031 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1032 | case DESC_RATE48M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1033 | rate_idx = 6; |
| 1034 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1035 | case DESC_RATE54M: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1036 | rate_idx = 7; |
| 1037 | break; |
| 1038 | default: |
| 1039 | rate_idx = 0; |
| 1040 | break; |
| 1041 | } |
| 1042 | } |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1043 | } else { |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1044 | switch (desc_rate) { |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1045 | case DESC_RATEMCS0: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1046 | rate_idx = 0; |
| 1047 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1048 | case DESC_RATEMCS1: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1049 | rate_idx = 1; |
| 1050 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1051 | case DESC_RATEMCS2: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1052 | rate_idx = 2; |
| 1053 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1054 | case DESC_RATEMCS3: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1055 | rate_idx = 3; |
| 1056 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1057 | case DESC_RATEMCS4: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1058 | rate_idx = 4; |
| 1059 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1060 | case DESC_RATEMCS5: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1061 | rate_idx = 5; |
| 1062 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1063 | case DESC_RATEMCS6: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1064 | rate_idx = 6; |
| 1065 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1066 | case DESC_RATEMCS7: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1067 | rate_idx = 7; |
| 1068 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1069 | case DESC_RATEMCS8: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1070 | rate_idx = 8; |
| 1071 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1072 | case DESC_RATEMCS9: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1073 | rate_idx = 9; |
| 1074 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1075 | case DESC_RATEMCS10: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1076 | rate_idx = 10; |
| 1077 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1078 | case DESC_RATEMCS11: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1079 | rate_idx = 11; |
| 1080 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1081 | case DESC_RATEMCS12: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1082 | rate_idx = 12; |
| 1083 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1084 | case DESC_RATEMCS13: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1085 | rate_idx = 13; |
| 1086 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1087 | case DESC_RATEMCS14: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1088 | rate_idx = 14; |
| 1089 | break; |
Larry Finger | e0e776a | 2014-12-18 03:05:36 -0600 | [diff] [blame] | 1090 | case DESC_RATEMCS15: |
Larry Finger | 7ad0ce3 | 2011-08-22 16:50:14 -0500 | [diff] [blame] | 1091 | rate_idx = 15; |
| 1092 | break; |
| 1093 | default: |
| 1094 | rate_idx = 0; |
| 1095 | break; |
| 1096 | } |
| 1097 | } |
| 1098 | return rate_idx; |
| 1099 | } |
| 1100 | EXPORT_SYMBOL(rtlwifi_rate_mapping); |
| 1101 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1102 | void rtl_get_tcb_desc(struct ieee80211_hw *hw, |
| 1103 | struct ieee80211_tx_info *info, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1104 | struct ieee80211_sta *sta, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1105 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc) |
| 1106 | { |
| 1107 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1108 | struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1109 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1110 | struct ieee80211_rate *txrate; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1111 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1112 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1113 | txrate = ieee80211_get_tx_rate(hw, info); |
Larry Finger | e89f769 | 2012-04-06 16:54:17 -0500 | [diff] [blame] | 1114 | if (txrate) |
| 1115 | tcb_desc->hw_rate = txrate->hw_value; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1116 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1117 | if (rtl_is_tx_report_skb(hw, skb)) |
| 1118 | tcb_desc->use_spe_rpt = 1; |
| 1119 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1120 | if (ieee80211_is_data(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1121 | /* |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1122 | *we set data rate INX 0 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1123 | *in rtl_rc.c if skb is special data or |
| 1124 | *mgt which need low data rate. |
| 1125 | */ |
| 1126 | |
| 1127 | /* |
| 1128 | *So tcb_desc->hw_rate is just used for |
| 1129 | *special data and mgt frames |
| 1130 | */ |
Chaoming Li | 09e92f0 | 2011-10-11 21:28:48 -0500 | [diff] [blame] | 1131 | if (info->control.rates[0].idx == 0 || |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1132 | ieee80211_is_nullfunc(fc)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1133 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1134 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1135 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1136 | tcb_desc->disable_ratefallback = 1; |
| 1137 | } else { |
| 1138 | /* |
| 1139 | *because hw will nerver use hw_rate |
| 1140 | *when tcb_desc->use_driver_rate = false |
| 1141 | *so we never set highest N rate here, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1142 | *and N rate will all be controlled by FW |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1143 | *when tcb_desc->use_driver_rate = false |
| 1144 | */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1145 | if (sta && sta->vht_cap.vht_supported) { |
| 1146 | tcb_desc->hw_rate = |
| 1147 | _rtl_get_vht_highest_n_rate(hw, sta); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1148 | } else { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1149 | if (sta && (sta->ht_cap.ht_supported)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1150 | tcb_desc->hw_rate = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1151 | _rtl_get_highest_n_rate(hw, sta); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1152 | } else { |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1153 | if (rtlmac->mode == WIRELESS_MODE_B) { |
| 1154 | tcb_desc->hw_rate = |
| 1155 | rtlpriv->cfg->maps[RTL_RC_CCK_RATE11M]; |
| 1156 | } else { |
| 1157 | tcb_desc->hw_rate = |
| 1158 | rtlpriv->cfg->maps[RTL_RC_OFDM_RATE54M]; |
| 1159 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1165 | tcb_desc->multicast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1166 | else if (is_broadcast_ether_addr(ieee80211_get_DA(hdr))) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1167 | tcb_desc->broadcast = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1168 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1169 | _rtl_txrate_selectmode(hw, sta, tcb_desc); |
| 1170 | _rtl_query_bandwidth_mode(hw, sta, tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1171 | _rtl_qurey_shortpreamble_mode(hw, tcb_desc, info); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1172 | _rtl_query_shortgi(hw, sta, tcb_desc, info); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1173 | _rtl_query_protection_mode(hw, tcb_desc, info); |
| 1174 | } else { |
| 1175 | tcb_desc->use_driver_rate = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1176 | tcb_desc->ratr_index = RATR_INX_WIRELESS_MC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1177 | tcb_desc->disable_ratefallback = 1; |
| 1178 | tcb_desc->mac_id = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1179 | tcb_desc->packet_bw = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1180 | } |
| 1181 | } |
| 1182 | EXPORT_SYMBOL(rtl_get_tcb_desc); |
| 1183 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1184 | bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1185 | { |
| 1186 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1187 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1188 | __le16 fc = rtl_get_fc(skb); |
| 1189 | |
| 1190 | if (rtlpriv->dm.supp_phymode_switch && |
| 1191 | mac->link_state < MAC80211_LINKED && |
| 1192 | (ieee80211_is_auth(fc) || ieee80211_is_probe_req(fc))) { |
| 1193 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 1194 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
| 1195 | } |
| 1196 | if (ieee80211_is_auth(fc)) { |
| 1197 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, "MAC80211_LINKING\n"); |
| 1198 | rtl_ips_nic_on(hw); |
| 1199 | |
| 1200 | mac->link_state = MAC80211_LINKING; |
| 1201 | /* Dul mac */ |
| 1202 | rtlpriv->phy.need_iqk = true; |
| 1203 | |
| 1204 | } |
| 1205 | |
| 1206 | return true; |
| 1207 | } |
| 1208 | EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc); |
| 1209 | |
| 1210 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, u8 *sa, |
| 1211 | u8 *bssid, u16 tid); |
| 1212 | |
| 1213 | static void process_agg_start(struct ieee80211_hw *hw, |
| 1214 | struct ieee80211_hdr *hdr, u16 tid) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1215 | { |
| 1216 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1217 | struct ieee80211_rx_status rx_status = { 0 }; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1218 | struct sk_buff *skb_delba = NULL; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1219 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1220 | skb_delba = rtl_make_del_ba(hw, hdr->addr2, hdr->addr3, tid); |
| 1221 | if (skb_delba) { |
| 1222 | rx_status.freq = hw->conf.chandef.chan->center_freq; |
| 1223 | rx_status.band = hw->conf.chandef.chan->band; |
| 1224 | rx_status.flag |= RX_FLAG_DECRYPTED; |
| 1225 | rx_status.flag |= RX_FLAG_MACTIME_START; |
| 1226 | rx_status.rate_idx = 0; |
| 1227 | rx_status.signal = 50 + 10; |
| 1228 | memcpy(IEEE80211_SKB_RXCB(skb_delba), |
| 1229 | &rx_status, sizeof(rx_status)); |
| 1230 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1231 | "fake del\n", |
| 1232 | skb_delba->data, |
| 1233 | skb_delba->len); |
| 1234 | ieee80211_rx_irqsafe(hw, skb_delba); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1235 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1236 | } |
| 1237 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1238 | bool rtl_action_proc(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx) |
| 1239 | { |
| 1240 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1241 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1242 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1243 | __le16 fc = rtl_get_fc(skb); |
| 1244 | u8 *act = (u8 *)(((u8 *)skb->data + MAC80211_3ADDR_LEN)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1245 | u8 category; |
| 1246 | |
| 1247 | if (!ieee80211_is_action(fc)) |
| 1248 | return true; |
| 1249 | |
| 1250 | category = *act; |
| 1251 | act++; |
| 1252 | switch (category) { |
| 1253 | case ACT_CAT_BA: |
| 1254 | switch (*act) { |
| 1255 | case ACT_ADDBAREQ: |
| 1256 | if (mac->act_scanning) |
| 1257 | return false; |
| 1258 | |
| 1259 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1260 | "%s ACT_ADDBAREQ From :%pM\n", |
| 1261 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1262 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "req\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1263 | skb->data, skb->len); |
| 1264 | if (!is_tx) { |
| 1265 | struct ieee80211_sta *sta = NULL; |
| 1266 | struct rtl_sta_info *sta_entry = NULL; |
| 1267 | struct rtl_tid_data *tid_data; |
| 1268 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1269 | u16 capab = 0, tid = 0; |
| 1270 | |
| 1271 | rcu_read_lock(); |
| 1272 | sta = rtl_find_sta(hw, hdr->addr3); |
| 1273 | if (sta == NULL) { |
| 1274 | RT_TRACE(rtlpriv, COMP_SEND | COMP_RECV, |
| 1275 | DBG_DMESG, "sta is NULL\n"); |
| 1276 | rcu_read_unlock(); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1277 | return true; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | sta_entry = |
| 1281 | (struct rtl_sta_info *)sta->drv_priv; |
| 1282 | if (!sta_entry) { |
| 1283 | rcu_read_unlock(); |
| 1284 | return true; |
| 1285 | } |
| 1286 | capab = |
| 1287 | le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1288 | tid = (capab & |
| 1289 | IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1290 | tid_data = &sta_entry->tids[tid]; |
| 1291 | if (tid_data->agg.rx_agg_state == |
| 1292 | RTL_RX_AGG_START) |
| 1293 | process_agg_start(hw, hdr, tid); |
| 1294 | rcu_read_unlock(); |
| 1295 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1296 | break; |
| 1297 | case ACT_ADDBARSP: |
| 1298 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1299 | "%s ACT_ADDBARSP From :%pM\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1300 | is_tx ? "Tx" : "Rx", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1301 | break; |
| 1302 | case ACT_DELBA: |
| 1303 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1304 | "ACT_ADDBADEL From :%pM\n", hdr->addr2); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1305 | break; |
| 1306 | } |
| 1307 | break; |
| 1308 | default: |
| 1309 | break; |
| 1310 | } |
| 1311 | |
| 1312 | return true; |
| 1313 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1314 | EXPORT_SYMBOL_GPL(rtl_action_proc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1315 | |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1316 | static void setup_special_tx(struct rtl_priv *rtlpriv, struct rtl_ps_ctl *ppsc, |
| 1317 | int type) |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1318 | { |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1319 | struct ieee80211_hw *hw = rtlpriv->hw; |
| 1320 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1321 | rtlpriv->ra.is_special_data = true; |
| 1322 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1323 | rtlpriv->btcoexist.btc_ops->btc_special_packet_notify( |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1324 | rtlpriv, type); |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1325 | rtl_lps_leave(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1326 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
| 1327 | } |
| 1328 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1329 | static const u8 *rtl_skb_ether_type_ptr(struct ieee80211_hw *hw, |
| 1330 | struct sk_buff *skb, bool is_enc) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1331 | { |
| 1332 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1333 | u8 mac_hdr_len = ieee80211_get_hdrlen_from_skb(skb); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1334 | u8 encrypt_header_len = 0; |
| 1335 | u8 offset; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1336 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1337 | switch (rtlpriv->sec.pairwise_enc_algorithm) { |
| 1338 | case WEP40_ENCRYPTION: |
| 1339 | case WEP104_ENCRYPTION: |
| 1340 | encrypt_header_len = 4;/*WEP_IV_LEN*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1341 | break; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1342 | case TKIP_ENCRYPTION: |
| 1343 | encrypt_header_len = 8;/*TKIP_IV_LEN*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1344 | break; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1345 | case AESCCMP_ENCRYPTION: |
| 1346 | encrypt_header_len = 8;/*CCMP_HDR_LEN;*/ |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1347 | break; |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1348 | default: |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1349 | break; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1350 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1351 | |
Taehee Yoo | cad737d | 2015-03-28 00:22:39 +0900 | [diff] [blame] | 1352 | offset = mac_hdr_len + SNAP_SIZE; |
| 1353 | if (is_enc) |
| 1354 | offset += encrypt_header_len; |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1355 | |
| 1356 | return skb->data + offset; |
| 1357 | } |
| 1358 | |
| 1359 | /*should call before software enc*/ |
| 1360 | u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx, |
| 1361 | bool is_enc) |
| 1362 | { |
| 1363 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1364 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1365 | __le16 fc = rtl_get_fc(skb); |
| 1366 | u16 ether_type; |
| 1367 | const u8 *ether_type_ptr; |
| 1368 | const struct iphdr *ip; |
| 1369 | |
| 1370 | if (!ieee80211_is_data(fc)) |
| 1371 | goto end; |
| 1372 | |
| 1373 | ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, is_enc); |
| 1374 | ether_type = be16_to_cpup((__be16 *)ether_type_ptr); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1375 | |
| 1376 | if (ETH_P_IP == ether_type) { |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1377 | ip = (struct iphdr *)((u8 *)ether_type_ptr + |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1378 | PROTOC_TYPE_SIZE); |
| 1379 | if (IPPROTO_UDP == ip->protocol) { |
| 1380 | struct udphdr *udp = (struct udphdr *)((u8 *)ip + |
| 1381 | (ip->ihl << 2)); |
| 1382 | if (((((u8 *)udp)[1] == 68) && |
| 1383 | (((u8 *)udp)[3] == 67)) || |
| 1384 | ((((u8 *)udp)[1] == 67) && |
| 1385 | (((u8 *)udp)[3] == 68))) { |
| 1386 | /* 68 : UDP BOOTP client |
| 1387 | * 67 : UDP BOOTP server |
| 1388 | */ |
| 1389 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), |
| 1390 | DBG_DMESG, "dhcp %s !!\n", |
| 1391 | (is_tx) ? "Tx" : "Rx"); |
| 1392 | |
| 1393 | if (is_tx) |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1394 | setup_special_tx(rtlpriv, ppsc, |
| 1395 | PACKET_DHCP); |
| 1396 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1397 | return true; |
| 1398 | } |
| 1399 | } |
| 1400 | } else if (ETH_P_ARP == ether_type) { |
| 1401 | if (is_tx) |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1402 | setup_special_tx(rtlpriv, ppsc, PACKET_ARP); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1403 | |
| 1404 | return true; |
| 1405 | } else if (ETH_P_PAE == ether_type) { |
| 1406 | RT_TRACE(rtlpriv, (COMP_SEND | COMP_RECV), DBG_DMESG, |
| 1407 | "802.1X %s EAPOL pkt!!\n", (is_tx) ? "Tx" : "Rx"); |
| 1408 | |
| 1409 | if (is_tx) { |
| 1410 | rtlpriv->ra.is_special_data = true; |
Larry Finger | ba9f93f | 2016-11-26 14:43:35 -0600 | [diff] [blame] | 1411 | rtl_lps_leave(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1412 | ppsc->last_delaylps_stamp_jiffies = jiffies; |
Ping-Ke Shih | 5b757ba | 2017-06-18 11:12:45 -0500 | [diff] [blame] | 1413 | |
| 1414 | setup_special_tx(rtlpriv, ppsc, PACKET_EAPOL); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | return true; |
Larry Finger | c8f0345 | 2015-02-24 09:23:01 -0600 | [diff] [blame] | 1418 | } else if (ETH_P_IPV6 == ether_type) { |
| 1419 | /* TODO: Handle any IPv6 cases that need special handling. |
| 1420 | * For now, always return false |
| 1421 | */ |
| 1422 | goto end; |
Mark Cave-Ayland | 0c5d63f | 2013-11-02 14:28:35 -0500 | [diff] [blame] | 1423 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1424 | |
| 1425 | end: |
| 1426 | rtlpriv->ra.is_special_data = false; |
| 1427 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1428 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1429 | EXPORT_SYMBOL_GPL(rtl_is_special_data); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1430 | |
Ping-Ke Shih | 8479580 | 2017-06-18 11:12:44 -0500 | [diff] [blame] | 1431 | bool rtl_is_tx_report_skb(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1432 | { |
| 1433 | u16 ether_type; |
| 1434 | const u8 *ether_type_ptr; |
| 1435 | |
| 1436 | ether_type_ptr = rtl_skb_ether_type_ptr(hw, skb, true); |
| 1437 | ether_type = be16_to_cpup((__be16 *)ether_type_ptr); |
| 1438 | |
| 1439 | /* EAPOL */ |
| 1440 | if (ether_type == ETH_P_PAE) |
| 1441 | return true; |
| 1442 | |
| 1443 | return false; |
| 1444 | } |
| 1445 | |
| 1446 | static u16 rtl_get_tx_report_sn(struct ieee80211_hw *hw) |
| 1447 | { |
| 1448 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1449 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1450 | u16 sn; |
| 1451 | |
| 1452 | sn = atomic_inc_return(&tx_report->sn) & 0x0FFF; |
| 1453 | |
| 1454 | tx_report->last_sent_sn = sn; |
| 1455 | tx_report->last_sent_time = jiffies; |
| 1456 | |
| 1457 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG, |
| 1458 | "Send TX-Report sn=0x%X\n", sn); |
| 1459 | |
| 1460 | return sn; |
| 1461 | } |
| 1462 | |
| 1463 | void rtl_get_tx_report(struct rtl_tcb_desc *ptcb_desc, u8 *pdesc, |
| 1464 | struct ieee80211_hw *hw) |
| 1465 | { |
| 1466 | if (ptcb_desc->use_spe_rpt) { |
| 1467 | u16 sn = rtl_get_tx_report_sn(hw); |
| 1468 | |
| 1469 | SET_TX_DESC_SPE_RPT(pdesc, 1); |
| 1470 | SET_TX_DESC_SW_DEFINE(pdesc, sn); |
| 1471 | } |
| 1472 | } |
| 1473 | EXPORT_SYMBOL_GPL(rtl_get_tx_report); |
| 1474 | |
| 1475 | void rtl_tx_report_handler(struct ieee80211_hw *hw, u8 *tmp_buf, u8 c2h_cmd_len) |
| 1476 | { |
| 1477 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1478 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1479 | u16 sn; |
| 1480 | |
| 1481 | sn = ((tmp_buf[7] & 0x0F) << 8) | tmp_buf[6]; |
| 1482 | |
| 1483 | tx_report->last_recv_sn = sn; |
| 1484 | |
| 1485 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_DMESG, |
| 1486 | "Recv TX-Report st=0x%02X sn=0x%X retry=0x%X\n", |
| 1487 | tmp_buf[0], sn, tmp_buf[2]); |
| 1488 | } |
| 1489 | EXPORT_SYMBOL_GPL(rtl_tx_report_handler); |
| 1490 | |
| 1491 | bool rtl_check_tx_report_acked(struct ieee80211_hw *hw) |
| 1492 | { |
| 1493 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1494 | struct rtl_tx_report *tx_report = &rtlpriv->tx_report; |
| 1495 | |
| 1496 | if (tx_report->last_sent_sn == tx_report->last_recv_sn) |
| 1497 | return true; |
| 1498 | |
| 1499 | if (time_before(tx_report->last_sent_time + 3 * HZ, jiffies)) { |
| 1500 | RT_TRACE(rtlpriv, COMP_TX_REPORT, DBG_WARNING, |
| 1501 | "Check TX-Report timeout!!\n"); |
| 1502 | return true; /* 3 sec. (timeout) seen as acked */ |
| 1503 | } |
| 1504 | |
| 1505 | return false; |
| 1506 | } |
| 1507 | |
| 1508 | void rtl_wait_tx_report_acked(struct ieee80211_hw *hw, u32 wait_ms) |
| 1509 | { |
| 1510 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1511 | int i; |
| 1512 | |
| 1513 | for (i = 0; i < wait_ms; i++) { |
| 1514 | if (rtl_check_tx_report_acked(hw)) |
| 1515 | break; |
| 1516 | usleep_range(1000, 2000); |
| 1517 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
| 1518 | "Wait 1ms (%d/%d) to disable key.\n", i, wait_ms); |
| 1519 | } |
| 1520 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1521 | /********************************************************* |
| 1522 | * |
| 1523 | * functions called by core.c |
| 1524 | * |
| 1525 | *********************************************************/ |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1526 | int rtl_tx_agg_start(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1527 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1528 | { |
| 1529 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1530 | struct rtl_tid_data *tid_data; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1531 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1532 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1533 | if (sta == NULL) |
| 1534 | return -EINVAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1535 | |
| 1536 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1537 | return -EINVAL; |
| 1538 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1539 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1540 | if (!sta_entry) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1541 | return -ENXIO; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1542 | tid_data = &sta_entry->tids[tid]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1543 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1544 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1545 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, |
| 1546 | tid_data->seq_number); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1547 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1548 | *ssn = tid_data->seq_number; |
| 1549 | tid_data->agg.agg_state = RTL_AGG_START; |
| 1550 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1551 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1552 | return 0; |
| 1553 | } |
| 1554 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1555 | int rtl_tx_agg_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1556 | struct ieee80211_sta *sta, u16 tid) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1557 | { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1558 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1559 | struct rtl_tid_data *tid_data; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1560 | struct rtl_sta_info *sta_entry = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1561 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1562 | if (sta == NULL) |
| 1563 | return -EINVAL; |
| 1564 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1565 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1566 | "on ra = %pM tid = %d\n", sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1567 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1568 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1569 | return -EINVAL; |
| 1570 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1571 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1572 | tid_data = &sta_entry->tids[tid]; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1573 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_STOP; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1574 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1575 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1576 | return 0; |
| 1577 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1578 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1579 | int rtl_rx_agg_start(struct ieee80211_hw *hw, |
| 1580 | struct ieee80211_sta *sta, u16 tid) |
| 1581 | { |
| 1582 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1583 | struct rtl_tid_data *tid_data; |
| 1584 | struct rtl_sta_info *sta_entry = NULL; |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1585 | u8 reject_agg; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1586 | |
| 1587 | if (sta == NULL) |
| 1588 | return -EINVAL; |
| 1589 | |
| 1590 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1591 | return -EINVAL; |
| 1592 | |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1593 | if (rtlpriv->cfg->ops->get_btc_status()) { |
| 1594 | rtlpriv->btcoexist.btc_ops->btc_get_ampdu_cfg(rtlpriv, |
| 1595 | &reject_agg, |
| 1596 | NULL, NULL); |
| 1597 | if (reject_agg) |
| 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1601 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1602 | if (!sta_entry) |
| 1603 | return -ENXIO; |
| 1604 | tid_data = &sta_entry->tids[tid]; |
| 1605 | |
| 1606 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, |
| 1607 | "on ra = %pM tid = %d seq:%d\n", sta->addr, tid, |
| 1608 | tid_data->seq_number); |
| 1609 | |
| 1610 | tid_data->agg.rx_agg_state = RTL_RX_AGG_START; |
| 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | int rtl_rx_agg_stop(struct ieee80211_hw *hw, |
| 1615 | struct ieee80211_sta *sta, u16 tid) |
| 1616 | { |
| 1617 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1618 | struct rtl_sta_info *sta_entry = NULL; |
| 1619 | |
| 1620 | if (sta == NULL) |
| 1621 | return -EINVAL; |
| 1622 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1623 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1624 | "on ra = %pM tid = %d\n", sta->addr, tid); |
| 1625 | |
| 1626 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1627 | return -EINVAL; |
| 1628 | |
| 1629 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1630 | sta_entry->tids[tid].agg.rx_agg_state = RTL_RX_AGG_STOP; |
| 1631 | |
| 1632 | return 0; |
| 1633 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1634 | int rtl_tx_agg_oper(struct ieee80211_hw *hw, |
| 1635 | struct ieee80211_sta *sta, u16 tid) |
| 1636 | { |
| 1637 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1638 | struct rtl_sta_info *sta_entry = NULL; |
| 1639 | |
| 1640 | if (sta == NULL) |
| 1641 | return -EINVAL; |
| 1642 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1643 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, |
| 1644 | "on ra = %pM tid = %d\n", sta->addr, tid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1645 | |
| 1646 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 1647 | return -EINVAL; |
| 1648 | |
| 1649 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1650 | sta_entry->tids[tid].agg.agg_state = RTL_AGG_OPERATIONAL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1651 | |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
Ping-Ke Shih | 2635664 | 2017-06-18 11:12:47 -0500 | [diff] [blame] | 1655 | void rtl_rx_ampdu_apply(struct rtl_priv *rtlpriv) |
| 1656 | { |
| 1657 | struct rtl_btc_ops *btc_ops = rtlpriv->btcoexist.btc_ops; |
| 1658 | u8 reject_agg, ctrl_agg_size = 0, agg_size; |
| 1659 | |
| 1660 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1661 | btc_ops->btc_get_ampdu_cfg(rtlpriv, &reject_agg, |
| 1662 | &ctrl_agg_size, &agg_size); |
| 1663 | |
| 1664 | RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, |
| 1665 | "Set RX AMPDU: coex - reject=%d, ctrl_agg_size=%d, size=%d", |
| 1666 | reject_agg, ctrl_agg_size, agg_size); |
| 1667 | |
| 1668 | rtlpriv->hw->max_rx_aggregation_subframes = |
| 1669 | (ctrl_agg_size ? agg_size : IEEE80211_MAX_AMPDU_BUF); |
| 1670 | } |
| 1671 | EXPORT_SYMBOL(rtl_rx_ampdu_apply); |
| 1672 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1673 | /********************************************************* |
| 1674 | * |
| 1675 | * wq & timer callback functions |
| 1676 | * |
| 1677 | *********************************************************/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1678 | /* this function is used for roaming */ |
| 1679 | void rtl_beacon_statistic(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1680 | { |
| 1681 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1682 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1683 | |
| 1684 | if (rtlpriv->mac80211.opmode != NL80211_IFTYPE_STATION) |
| 1685 | return; |
| 1686 | |
| 1687 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) |
| 1688 | return; |
| 1689 | |
| 1690 | /* check if this really is a beacon */ |
| 1691 | if (!ieee80211_is_beacon(hdr->frame_control) && |
| 1692 | !ieee80211_is_probe_resp(hdr->frame_control)) |
| 1693 | return; |
| 1694 | |
| 1695 | /* min. beacon length + FCS_LEN */ |
| 1696 | if (skb->len <= 40 + FCS_LEN) |
| 1697 | return; |
| 1698 | |
| 1699 | /* and only beacons from the associated BSSID, please */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1700 | if (!ether_addr_equal(hdr->addr3, rtlpriv->mac80211.bssid)) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1701 | return; |
| 1702 | |
| 1703 | rtlpriv->link_info.bcn_rx_inperiod++; |
| 1704 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1705 | EXPORT_SYMBOL_GPL(rtl_beacon_statistic); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1706 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1707 | void rtl_watchdog_wq_callback(void *data) |
| 1708 | { |
| 1709 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 1710 | struct rtl_works, |
| 1711 | watchdog_wq); |
| 1712 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1713 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1714 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1715 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1716 | bool busytraffic = false; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1717 | bool tx_busy_traffic = false; |
| 1718 | bool rx_busy_traffic = false; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1719 | bool higher_busytraffic = false; |
| 1720 | bool higher_busyrxtraffic = false; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1721 | u8 idx, tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1722 | u32 rx_cnt_inp4eriod = 0; |
| 1723 | u32 tx_cnt_inp4eriod = 0; |
| 1724 | u32 aver_rx_cnt_inperiod = 0; |
| 1725 | u32 aver_tx_cnt_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1726 | u32 aver_tidtx_inperiod[MAX_TID_COUNT] = {0}; |
| 1727 | u32 tidtx_inp4eriod[MAX_TID_COUNT] = {0}; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1728 | |
| 1729 | if (is_hal_stop(rtlhal)) |
| 1730 | return; |
| 1731 | |
| 1732 | /* <1> Determine if action frame is allowed */ |
| 1733 | if (mac->link_state > MAC80211_NOLINK) { |
| 1734 | if (mac->cnt_after_linked < 20) |
| 1735 | mac->cnt_after_linked++; |
| 1736 | } else { |
| 1737 | mac->cnt_after_linked = 0; |
| 1738 | } |
| 1739 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1740 | /* <2> to check if traffic busy, if |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1741 | * busytraffic we don't change channel |
| 1742 | */ |
| 1743 | if (mac->link_state >= MAC80211_LINKED) { |
| 1744 | |
| 1745 | /* (1) get aver_rx_cnt_inperiod & aver_tx_cnt_inperiod */ |
| 1746 | for (idx = 0; idx <= 2; idx++) { |
| 1747 | rtlpriv->link_info.num_rx_in4period[idx] = |
| 1748 | rtlpriv->link_info.num_rx_in4period[idx + 1]; |
| 1749 | rtlpriv->link_info.num_tx_in4period[idx] = |
| 1750 | rtlpriv->link_info.num_tx_in4period[idx + 1]; |
| 1751 | } |
| 1752 | rtlpriv->link_info.num_rx_in4period[3] = |
| 1753 | rtlpriv->link_info.num_rx_inperiod; |
| 1754 | rtlpriv->link_info.num_tx_in4period[3] = |
| 1755 | rtlpriv->link_info.num_tx_inperiod; |
| 1756 | for (idx = 0; idx <= 3; idx++) { |
| 1757 | rx_cnt_inp4eriod += |
| 1758 | rtlpriv->link_info.num_rx_in4period[idx]; |
| 1759 | tx_cnt_inp4eriod += |
| 1760 | rtlpriv->link_info.num_tx_in4period[idx]; |
| 1761 | } |
| 1762 | aver_rx_cnt_inperiod = rx_cnt_inp4eriod / 4; |
| 1763 | aver_tx_cnt_inperiod = tx_cnt_inp4eriod / 4; |
| 1764 | |
| 1765 | /* (2) check traffic busy */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1766 | if (aver_rx_cnt_inperiod > 100 || aver_tx_cnt_inperiod > 100) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1767 | busytraffic = true; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1768 | if (aver_rx_cnt_inperiod > aver_tx_cnt_inperiod) |
| 1769 | rx_busy_traffic = true; |
| 1770 | else |
| 1771 | tx_busy_traffic = false; |
| 1772 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1773 | |
| 1774 | /* Higher Tx/Rx data. */ |
| 1775 | if (aver_rx_cnt_inperiod > 4000 || |
| 1776 | aver_tx_cnt_inperiod > 4000) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1777 | higher_busytraffic = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1778 | |
| 1779 | /* Extremely high Rx data. */ |
| 1780 | if (aver_rx_cnt_inperiod > 5000) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1781 | higher_busyrxtraffic = true; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | /* check every tid's tx traffic */ |
| 1785 | for (tid = 0; tid <= 7; tid++) { |
| 1786 | for (idx = 0; idx <= 2; idx++) |
| 1787 | rtlpriv->link_info.tidtx_in4period[tid][idx] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1788 | rtlpriv->link_info.tidtx_in4period[tid] |
| 1789 | [idx + 1]; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1790 | rtlpriv->link_info.tidtx_in4period[tid][3] = |
| 1791 | rtlpriv->link_info.tidtx_inperiod[tid]; |
| 1792 | |
| 1793 | for (idx = 0; idx <= 3; idx++) |
| 1794 | tidtx_inp4eriod[tid] += |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1795 | rtlpriv->link_info.tidtx_in4period[tid][idx]; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1796 | aver_tidtx_inperiod[tid] = tidtx_inp4eriod[tid] / 4; |
| 1797 | if (aver_tidtx_inperiod[tid] > 5000) |
| 1798 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1799 | true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1800 | else |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1801 | rtlpriv->link_info.higher_busytxtraffic[tid] = |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1802 | false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1803 | } |
| 1804 | |
Ping-Ke Shih | 42213f2 | 2017-06-18 11:12:49 -0500 | [diff] [blame] | 1805 | /* PS is controlled by coex. */ |
| 1806 | if (rtlpriv->cfg->ops->get_btc_status() && |
| 1807 | rtlpriv->btcoexist.btc_ops->btc_is_bt_ctrl_lps(rtlpriv)) |
| 1808 | goto label_lps_done; |
| 1809 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1810 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 1811 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 1812 | (rtlpriv->link_info.num_rx_inperiod > 2)) |
Larry Finger | fd09ff9 | 2014-09-22 09:39:18 -0500 | [diff] [blame] | 1813 | rtl_lps_leave(hw); |
wang yanqing | 873ffe1 | 2016-05-03 00:38:36 +0800 | [diff] [blame] | 1814 | else |
| 1815 | rtl_lps_enter(hw); |
Ping-Ke Shih | 42213f2 | 2017-06-18 11:12:49 -0500 | [diff] [blame] | 1816 | |
| 1817 | label_lps_done: |
| 1818 | ; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | rtlpriv->link_info.num_rx_inperiod = 0; |
| 1822 | rtlpriv->link_info.num_tx_inperiod = 0; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1823 | for (tid = 0; tid <= 7; tid++) |
| 1824 | rtlpriv->link_info.tidtx_inperiod[tid] = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1825 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1826 | rtlpriv->link_info.busytraffic = busytraffic; |
| 1827 | rtlpriv->link_info.higher_busytraffic = higher_busytraffic; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1828 | rtlpriv->link_info.rx_busy_traffic = rx_busy_traffic; |
| 1829 | rtlpriv->link_info.tx_busy_traffic = tx_busy_traffic; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1830 | rtlpriv->link_info.higher_busyrxtraffic = higher_busyrxtraffic; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1831 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1832 | /* <3> DM */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1833 | if (!rtlpriv->cfg->mod_params->disable_watchdog) |
| 1834 | rtlpriv->cfg->ops->dm_watchdog(hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1835 | |
| 1836 | /* <4> roaming */ |
| 1837 | if (mac->link_state == MAC80211_LINKED && |
| 1838 | mac->opmode == NL80211_IFTYPE_STATION) { |
| 1839 | if ((rtlpriv->link_info.bcn_rx_inperiod + |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1840 | rtlpriv->link_info.num_rx_inperiod) == 0) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1841 | rtlpriv->link_info.roam_times++; |
| 1842 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
| 1843 | "AP off for %d s\n", |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1844 | (rtlpriv->link_info.roam_times * 2)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1845 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1846 | /* if we can't recv beacon for 10s, |
| 1847 | * we should reconnect this AP |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1848 | */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1849 | if (rtlpriv->link_info.roam_times >= 5) { |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 1850 | pr_err("AP off, try to reconnect now\n"); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1851 | rtlpriv->link_info.roam_times = 0; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1852 | ieee80211_connection_loss( |
| 1853 | rtlpriv->mac80211.vif); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1854 | } |
| 1855 | } else { |
| 1856 | rtlpriv->link_info.roam_times = 0; |
| 1857 | } |
| 1858 | } |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 1859 | |
| 1860 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1861 | rtlpriv->btcoexist.btc_ops->btc_periodical(rtlpriv); |
| 1862 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1863 | rtlpriv->link_info.bcn_rx_inperiod = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | void rtl_watch_dog_timer_callback(unsigned long data) |
| 1867 | { |
| 1868 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1869 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1870 | |
| 1871 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 1872 | &rtlpriv->works.watchdog_wq, 0); |
| 1873 | |
| 1874 | mod_timer(&rtlpriv->works.watchdog_timer, |
| 1875 | jiffies + MSECS(RTL_WATCH_DOG_TIME)); |
| 1876 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1877 | void rtl_fwevt_wq_callback(void *data) |
| 1878 | { |
| 1879 | struct rtl_works *rtlworks = |
| 1880 | container_of_dwork_rtl(data, struct rtl_works, fwevt_wq); |
| 1881 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1882 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1883 | |
| 1884 | rtlpriv->cfg->ops->c2h_command_handle(hw); |
| 1885 | } |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 1886 | |
| 1887 | void rtl_c2hcmd_enqueue(struct ieee80211_hw *hw, u8 tag, u8 len, u8 *val) |
| 1888 | { |
| 1889 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1890 | unsigned long flags; |
| 1891 | struct rtl_c2hcmd *c2hcmd; |
| 1892 | |
Larry Finger | 893dc68 | 2017-03-21 09:24:11 -0500 | [diff] [blame] | 1893 | c2hcmd = kmalloc(sizeof(*c2hcmd), |
| 1894 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 1895 | |
| 1896 | if (!c2hcmd) |
| 1897 | goto label_err; |
| 1898 | |
Larry Finger | 893dc68 | 2017-03-21 09:24:11 -0500 | [diff] [blame] | 1899 | c2hcmd->val = kmalloc(len, |
| 1900 | in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); |
Ping-Ke Shih | cceb0a5 | 2017-02-06 21:30:08 -0600 | [diff] [blame] | 1901 | |
| 1902 | if (!c2hcmd->val) |
| 1903 | goto label_err2; |
| 1904 | |
| 1905 | /* fill data */ |
| 1906 | c2hcmd->tag = tag; |
| 1907 | c2hcmd->len = len; |
| 1908 | memcpy(c2hcmd->val, val, len); |
| 1909 | |
| 1910 | /* enqueue */ |
| 1911 | spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags); |
| 1912 | |
| 1913 | list_add_tail(&c2hcmd->list, &rtlpriv->c2hcmd_list); |
| 1914 | |
| 1915 | spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags); |
| 1916 | |
| 1917 | /* wake up wq */ |
| 1918 | queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.c2hcmd_wq, 0); |
| 1919 | |
| 1920 | return; |
| 1921 | |
| 1922 | label_err2: |
| 1923 | kfree(c2hcmd); |
| 1924 | |
| 1925 | label_err: |
| 1926 | RT_TRACE(rtlpriv, COMP_CMD, DBG_WARNING, |
| 1927 | "C2H cmd enqueue fail.\n"); |
| 1928 | } |
| 1929 | EXPORT_SYMBOL(rtl_c2hcmd_enqueue); |
| 1930 | |
| 1931 | void rtl_c2hcmd_launcher(struct ieee80211_hw *hw, int exec) |
| 1932 | { |
| 1933 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1934 | unsigned long flags; |
| 1935 | struct rtl_c2hcmd *c2hcmd; |
| 1936 | int i; |
| 1937 | |
| 1938 | for (i = 0; i < 200; i++) { |
| 1939 | /* dequeue a task */ |
| 1940 | spin_lock_irqsave(&rtlpriv->locks.c2hcmd_lock, flags); |
| 1941 | |
| 1942 | c2hcmd = list_first_entry_or_null(&rtlpriv->c2hcmd_list, |
| 1943 | struct rtl_c2hcmd, list); |
| 1944 | |
| 1945 | if (c2hcmd) |
| 1946 | list_del(&c2hcmd->list); |
| 1947 | |
| 1948 | spin_unlock_irqrestore(&rtlpriv->locks.c2hcmd_lock, flags); |
| 1949 | |
| 1950 | /* do it */ |
| 1951 | if (!c2hcmd) |
| 1952 | break; |
| 1953 | |
| 1954 | if (rtlpriv->cfg->ops->c2h_content_parsing && exec) |
| 1955 | rtlpriv->cfg->ops->c2h_content_parsing(hw, |
| 1956 | c2hcmd->tag, c2hcmd->len, c2hcmd->val); |
| 1957 | |
| 1958 | /* free */ |
| 1959 | kfree(c2hcmd->val); |
| 1960 | |
| 1961 | kfree(c2hcmd); |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | void rtl_c2hcmd_wq_callback(void *data) |
| 1966 | { |
| 1967 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, |
| 1968 | struct rtl_works, |
| 1969 | c2hcmd_wq); |
| 1970 | struct ieee80211_hw *hw = rtlworks->hw; |
| 1971 | |
| 1972 | rtl_c2hcmd_launcher(hw, 1); |
| 1973 | } |
| 1974 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1975 | void rtl_easy_concurrent_retrytimer_callback(unsigned long data) |
| 1976 | { |
| 1977 | struct ieee80211_hw *hw = (struct ieee80211_hw *)data; |
| 1978 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1979 | struct rtl_priv *buddy_priv = rtlpriv->buddy_priv; |
| 1980 | |
| 1981 | if (buddy_priv == NULL) |
| 1982 | return; |
| 1983 | |
| 1984 | rtlpriv->cfg->ops->dualmac_easy_concurrent(hw); |
| 1985 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1986 | /********************************************************* |
| 1987 | * |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 1988 | * frame process functions |
| 1989 | * |
| 1990 | *********************************************************/ |
| 1991 | u8 *rtl_find_ie(u8 *data, unsigned int len, u8 ie) |
| 1992 | { |
| 1993 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 1994 | u8 *pos, *end; |
| 1995 | |
| 1996 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1997 | end = data + len; |
| 1998 | while (pos < end) { |
| 1999 | if (pos + 2 + pos[1] > end) |
| 2000 | return NULL; |
| 2001 | |
| 2002 | if (pos[0] == ie) |
| 2003 | return pos; |
| 2004 | |
| 2005 | pos += 2 + pos[1]; |
| 2006 | } |
| 2007 | return NULL; |
| 2008 | } |
| 2009 | |
| 2010 | /* when we use 2 rx ants we send IEEE80211_SMPS_OFF */ |
| 2011 | /* when we use 1 rx ant we send IEEE80211_SMPS_STATIC */ |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 2012 | static struct sk_buff *rtl_make_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2013 | enum ieee80211_smps_mode smps, |
| 2014 | u8 *da, u8 *bssid) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2015 | { |
| 2016 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 2017 | struct sk_buff *skb; |
| 2018 | struct ieee80211_mgmt *action_frame; |
| 2019 | |
| 2020 | /* 27 = header + category + action + smps mode */ |
| 2021 | skb = dev_alloc_skb(27 + hw->extra_tx_headroom); |
| 2022 | if (!skb) |
| 2023 | return NULL; |
| 2024 | |
| 2025 | skb_reserve(skb, hw->extra_tx_headroom); |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 2026 | action_frame = skb_put_zero(skb, 27); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2027 | memcpy(action_frame->da, da, ETH_ALEN); |
| 2028 | memcpy(action_frame->sa, rtlefuse->dev_addr, ETH_ALEN); |
| 2029 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 2030 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2031 | IEEE80211_STYPE_ACTION); |
| 2032 | action_frame->u.action.category = WLAN_CATEGORY_HT; |
| 2033 | action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS; |
| 2034 | switch (smps) { |
| 2035 | case IEEE80211_SMPS_AUTOMATIC:/* 0 */ |
| 2036 | case IEEE80211_SMPS_NUM_MODES:/* 4 */ |
| 2037 | WARN_ON(1); |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2038 | /* Here will get a 'MISSING_BREAK' in Coverity Test, just ignore it. |
| 2039 | * According to Kernel Code, here is right. |
| 2040 | */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2041 | case IEEE80211_SMPS_OFF:/* 1 */ /*MIMO_PS_NOLIMIT*/ |
| 2042 | action_frame->u.action.u.ht_smps.smps_control = |
| 2043 | WLAN_HT_SMPS_CONTROL_DISABLED;/* 0 */ |
| 2044 | break; |
| 2045 | case IEEE80211_SMPS_STATIC:/* 2 */ /*MIMO_PS_STATIC*/ |
| 2046 | action_frame->u.action.u.ht_smps.smps_control = |
| 2047 | WLAN_HT_SMPS_CONTROL_STATIC;/* 1 */ |
| 2048 | break; |
| 2049 | case IEEE80211_SMPS_DYNAMIC:/* 3 */ /*MIMO_PS_DYNAMIC*/ |
| 2050 | action_frame->u.action.u.ht_smps.smps_control = |
| 2051 | WLAN_HT_SMPS_CONTROL_DYNAMIC;/* 3 */ |
| 2052 | break; |
| 2053 | } |
| 2054 | |
| 2055 | return skb; |
| 2056 | } |
| 2057 | |
| 2058 | int rtl_send_smps_action(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2059 | struct ieee80211_sta *sta, |
| 2060 | enum ieee80211_smps_mode smps) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2061 | { |
| 2062 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2063 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2064 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2065 | struct sk_buff *skb = NULL; |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2066 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2067 | u8 bssid[ETH_ALEN] = {0}; |
| 2068 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2069 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 2070 | |
| 2071 | if (rtlpriv->mac80211.act_scanning) |
| 2072 | goto err_free; |
| 2073 | |
| 2074 | if (!sta) |
| 2075 | goto err_free; |
| 2076 | |
| 2077 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 2078 | goto err_free; |
| 2079 | |
| 2080 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 2081 | goto err_free; |
| 2082 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2083 | if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) |
| 2084 | memcpy(bssid, rtlpriv->efuse.dev_addr, ETH_ALEN); |
| 2085 | else |
| 2086 | memcpy(bssid, rtlpriv->mac80211.bssid, ETH_ALEN); |
| 2087 | |
| 2088 | skb = rtl_make_smps_action(hw, smps, sta->addr, bssid); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2089 | /* this is a type = mgmt * stype = action frame */ |
| 2090 | if (skb) { |
| 2091 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 2092 | struct rtl_sta_info *sta_entry = |
| 2093 | (struct rtl_sta_info *) sta->drv_priv; |
| 2094 | sta_entry->mimo_ps = smps; |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2095 | /* rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); */ |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2096 | |
| 2097 | info->control.rates[0].idx = 0; |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2098 | info->band = hw->conf.chandef.chan->band; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 2099 | rtlpriv->intf_ops->adapter_tx(hw, sta, skb, &tcb_desc); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2100 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2101 | return 1; |
| 2102 | |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2103 | err_free: |
| 2104 | return 0; |
| 2105 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2106 | EXPORT_SYMBOL(rtl_send_smps_action); |
| 2107 | |
Larry Finger | 4f4826d | 2013-09-26 13:25:27 -0500 | [diff] [blame] | 2108 | void rtl_phy_scan_operation_backup(struct ieee80211_hw *hw, u8 operation) |
| 2109 | { |
| 2110 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2111 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2112 | enum io_type iotype; |
| 2113 | |
| 2114 | if (!is_hal_stop(rtlhal)) { |
| 2115 | switch (operation) { |
| 2116 | case SCAN_OPT_BACKUP: |
| 2117 | iotype = IO_CMD_PAUSE_DM_BY_SCAN; |
| 2118 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 2119 | HW_VAR_IO_CMD, |
| 2120 | (u8 *)&iotype); |
| 2121 | break; |
| 2122 | case SCAN_OPT_RESTORE: |
| 2123 | iotype = IO_CMD_RESUME_DM_BY_SCAN; |
| 2124 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 2125 | HW_VAR_IO_CMD, |
| 2126 | (u8 *)&iotype); |
| 2127 | break; |
| 2128 | default: |
Larry Finger | b03d968 | 2016-12-15 12:22:58 -0600 | [diff] [blame] | 2129 | pr_err("Unknown Scan Backup operation.\n"); |
Larry Finger | 4f4826d | 2013-09-26 13:25:27 -0500 | [diff] [blame] | 2130 | break; |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | EXPORT_SYMBOL(rtl_phy_scan_operation_backup); |
| 2135 | |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2136 | /* because mac80211 have issues when can receive del ba |
| 2137 | * so here we just make a fake del_ba if we receive a ba_req |
| 2138 | * but rx_agg was opened to let mac80211 release some ba |
| 2139 | * related resources, so please this del_ba for tx |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2140 | */ |
| 2141 | struct sk_buff *rtl_make_del_ba(struct ieee80211_hw *hw, |
| 2142 | u8 *sa, u8 *bssid, u16 tid) |
| 2143 | { |
| 2144 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 2145 | struct sk_buff *skb; |
| 2146 | struct ieee80211_mgmt *action_frame; |
| 2147 | u16 params; |
| 2148 | |
| 2149 | /* 27 = header + category + action + smps mode */ |
| 2150 | skb = dev_alloc_skb(34 + hw->extra_tx_headroom); |
| 2151 | if (!skb) |
| 2152 | return NULL; |
| 2153 | |
| 2154 | skb_reserve(skb, hw->extra_tx_headroom); |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 2155 | action_frame = skb_put_zero(skb, 34); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2156 | memcpy(action_frame->sa, sa, ETH_ALEN); |
| 2157 | memcpy(action_frame->da, rtlefuse->dev_addr, ETH_ALEN); |
| 2158 | memcpy(action_frame->bssid, bssid, ETH_ALEN); |
| 2159 | action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2160 | IEEE80211_STYPE_ACTION); |
| 2161 | action_frame->u.action.category = WLAN_CATEGORY_BACK; |
| 2162 | action_frame->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 2163 | params = (u16)(1 << 11); /* bit 11 initiator */ |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2164 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2165 | |
| 2166 | action_frame->u.action.u.delba.params = cpu_to_le16(params); |
| 2167 | action_frame->u.action.u.delba.reason_code = |
| 2168 | cpu_to_le16(WLAN_REASON_QSTA_TIMEOUT); |
| 2169 | |
| 2170 | return skb; |
| 2171 | } |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2172 | |
| 2173 | /********************************************************* |
| 2174 | * |
| 2175 | * IOT functions |
| 2176 | * |
| 2177 | *********************************************************/ |
| 2178 | static bool rtl_chk_vendor_ouisub(struct ieee80211_hw *hw, |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2179 | struct octet_string vendor_ie) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2180 | { |
| 2181 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2182 | bool matched = false; |
| 2183 | static u8 athcap_1[] = { 0x00, 0x03, 0x7F }; |
| 2184 | static u8 athcap_2[] = { 0x00, 0x13, 0x74 }; |
| 2185 | static u8 broadcap_1[] = { 0x00, 0x10, 0x18 }; |
| 2186 | static u8 broadcap_2[] = { 0x00, 0x0a, 0xf7 }; |
| 2187 | static u8 broadcap_3[] = { 0x00, 0x05, 0xb5 }; |
| 2188 | static u8 racap[] = { 0x00, 0x0c, 0x43 }; |
| 2189 | static u8 ciscocap[] = { 0x00, 0x40, 0x96 }; |
| 2190 | static u8 marvcap[] = { 0x00, 0x50, 0x43 }; |
| 2191 | |
| 2192 | if (memcmp(vendor_ie.octet, athcap_1, 3) == 0 || |
| 2193 | memcmp(vendor_ie.octet, athcap_2, 3) == 0) { |
| 2194 | rtlpriv->mac80211.vendor = PEER_ATH; |
| 2195 | matched = true; |
| 2196 | } else if (memcmp(vendor_ie.octet, broadcap_1, 3) == 0 || |
| 2197 | memcmp(vendor_ie.octet, broadcap_2, 3) == 0 || |
| 2198 | memcmp(vendor_ie.octet, broadcap_3, 3) == 0) { |
| 2199 | rtlpriv->mac80211.vendor = PEER_BROAD; |
| 2200 | matched = true; |
| 2201 | } else if (memcmp(vendor_ie.octet, racap, 3) == 0) { |
| 2202 | rtlpriv->mac80211.vendor = PEER_RAL; |
| 2203 | matched = true; |
| 2204 | } else if (memcmp(vendor_ie.octet, ciscocap, 3) == 0) { |
| 2205 | rtlpriv->mac80211.vendor = PEER_CISCO; |
| 2206 | matched = true; |
| 2207 | } else if (memcmp(vendor_ie.octet, marvcap, 3) == 0) { |
| 2208 | rtlpriv->mac80211.vendor = PEER_MARV; |
| 2209 | matched = true; |
| 2210 | } |
| 2211 | |
| 2212 | return matched; |
| 2213 | } |
| 2214 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 2215 | static bool rtl_find_221_ie(struct ieee80211_hw *hw, u8 *data, |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2216 | unsigned int len) |
| 2217 | { |
| 2218 | struct ieee80211_mgmt *mgmt = (void *)data; |
| 2219 | struct octet_string vendor_ie; |
| 2220 | u8 *pos, *end; |
| 2221 | |
| 2222 | pos = (u8 *)mgmt->u.beacon.variable; |
| 2223 | end = data + len; |
| 2224 | while (pos < end) { |
| 2225 | if (pos[0] == 221) { |
| 2226 | vendor_ie.length = pos[1]; |
| 2227 | vendor_ie.octet = &pos[2]; |
| 2228 | if (rtl_chk_vendor_ouisub(hw, vendor_ie)) |
| 2229 | return true; |
| 2230 | } |
| 2231 | |
| 2232 | if (pos + 2 + pos[1] > end) |
| 2233 | return false; |
| 2234 | |
| 2235 | pos += 2 + pos[1]; |
| 2236 | } |
| 2237 | return false; |
| 2238 | } |
| 2239 | |
| 2240 | void rtl_recognize_peer(struct ieee80211_hw *hw, u8 *data, unsigned int len) |
| 2241 | { |
| 2242 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2243 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 2244 | struct ieee80211_hdr *hdr = (void *)data; |
| 2245 | u32 vendor = PEER_UNKNOWN; |
| 2246 | |
| 2247 | static u8 ap3_1[3] = { 0x00, 0x14, 0xbf }; |
| 2248 | static u8 ap3_2[3] = { 0x00, 0x1a, 0x70 }; |
| 2249 | static u8 ap3_3[3] = { 0x00, 0x1d, 0x7e }; |
| 2250 | static u8 ap4_1[3] = { 0x00, 0x90, 0xcc }; |
| 2251 | static u8 ap4_2[3] = { 0x00, 0x0e, 0x2e }; |
| 2252 | static u8 ap4_3[3] = { 0x00, 0x18, 0x02 }; |
| 2253 | static u8 ap4_4[3] = { 0x00, 0x17, 0x3f }; |
| 2254 | static u8 ap4_5[3] = { 0x00, 0x1c, 0xdf }; |
| 2255 | static u8 ap5_1[3] = { 0x00, 0x1c, 0xf0 }; |
| 2256 | static u8 ap5_2[3] = { 0x00, 0x21, 0x91 }; |
| 2257 | static u8 ap5_3[3] = { 0x00, 0x24, 0x01 }; |
| 2258 | static u8 ap5_4[3] = { 0x00, 0x15, 0xe9 }; |
| 2259 | static u8 ap5_5[3] = { 0x00, 0x17, 0x9A }; |
| 2260 | static u8 ap5_6[3] = { 0x00, 0x18, 0xE7 }; |
| 2261 | static u8 ap6_1[3] = { 0x00, 0x17, 0x94 }; |
| 2262 | static u8 ap7_1[3] = { 0x00, 0x14, 0xa4 }; |
| 2263 | |
| 2264 | if (mac->opmode != NL80211_IFTYPE_STATION) |
| 2265 | return; |
| 2266 | |
| 2267 | if (mac->link_state == MAC80211_NOLINK) { |
| 2268 | mac->vendor = PEER_UNKNOWN; |
| 2269 | return; |
| 2270 | } |
| 2271 | |
| 2272 | if (mac->cnt_after_linked > 2) |
| 2273 | return; |
| 2274 | |
| 2275 | /* check if this really is a beacon */ |
| 2276 | if (!ieee80211_is_beacon(hdr->frame_control)) |
| 2277 | return; |
| 2278 | |
| 2279 | /* min. beacon length + FCS_LEN */ |
| 2280 | if (len <= 40 + FCS_LEN) |
| 2281 | return; |
| 2282 | |
| 2283 | /* and only beacons from the associated BSSID, please */ |
Julia Lawall | 90908e1 | 2013-12-30 19:15:02 +0100 | [diff] [blame] | 2284 | if (!ether_addr_equal_64bits(hdr->addr3, rtlpriv->mac80211.bssid)) |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2285 | return; |
| 2286 | |
| 2287 | if (rtl_find_221_ie(hw, data, len)) |
| 2288 | vendor = mac->vendor; |
| 2289 | |
| 2290 | if ((memcmp(mac->bssid, ap5_1, 3) == 0) || |
| 2291 | (memcmp(mac->bssid, ap5_2, 3) == 0) || |
| 2292 | (memcmp(mac->bssid, ap5_3, 3) == 0) || |
| 2293 | (memcmp(mac->bssid, ap5_4, 3) == 0) || |
| 2294 | (memcmp(mac->bssid, ap5_5, 3) == 0) || |
| 2295 | (memcmp(mac->bssid, ap5_6, 3) == 0) || |
| 2296 | vendor == PEER_ATH) { |
| 2297 | vendor = PEER_ATH; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2298 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ath find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2299 | } else if ((memcmp(mac->bssid, ap4_4, 3) == 0) || |
| 2300 | (memcmp(mac->bssid, ap4_5, 3) == 0) || |
| 2301 | (memcmp(mac->bssid, ap4_1, 3) == 0) || |
| 2302 | (memcmp(mac->bssid, ap4_2, 3) == 0) || |
| 2303 | (memcmp(mac->bssid, ap4_3, 3) == 0) || |
| 2304 | vendor == PEER_RAL) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2305 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>ral find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2306 | vendor = PEER_RAL; |
| 2307 | } else if (memcmp(mac->bssid, ap6_1, 3) == 0 || |
| 2308 | vendor == PEER_CISCO) { |
| 2309 | vendor = PEER_CISCO; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2310 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>cisco find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2311 | } else if ((memcmp(mac->bssid, ap3_1, 3) == 0) || |
| 2312 | (memcmp(mac->bssid, ap3_2, 3) == 0) || |
| 2313 | (memcmp(mac->bssid, ap3_3, 3) == 0) || |
| 2314 | vendor == PEER_BROAD) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2315 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>broad find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2316 | vendor = PEER_BROAD; |
| 2317 | } else if (memcmp(mac->bssid, ap7_1, 3) == 0 || |
| 2318 | vendor == PEER_MARV) { |
| 2319 | vendor = PEER_MARV; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2320 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "=>marv find\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | mac->vendor = vendor; |
| 2324 | } |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2325 | EXPORT_SYMBOL_GPL(rtl_recognize_peer); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2326 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2327 | MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>"); |
| 2328 | MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>"); |
| 2329 | MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>"); |
| 2330 | MODULE_LICENSE("GPL"); |
| 2331 | MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core"); |
| 2332 | |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2333 | struct rtl_global_var rtl_global_var = {}; |
| 2334 | EXPORT_SYMBOL_GPL(rtl_global_var); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2335 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2336 | static int __init rtl_core_module_init(void) |
| 2337 | { |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 2338 | if (rtl_rate_control_register()) |
Larry Finger | 9afa2e4 | 2014-09-22 09:39:21 -0500 | [diff] [blame] | 2339 | pr_err("rtl: Unable to register rtl_rc, use default RC !!\n"); |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2340 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2341 | /* init some global vars */ |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2342 | INIT_LIST_HEAD(&rtl_global_var.glb_priv_list); |
| 2343 | spin_lock_init(&rtl_global_var.glb_list_lock); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2344 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2345 | return 0; |
| 2346 | } |
| 2347 | |
| 2348 | static void __exit rtl_core_module_exit(void) |
| 2349 | { |
Chaoming_Li | acd4857 | 2011-04-25 12:52:54 -0500 | [diff] [blame] | 2350 | /*RC*/ |
Chaoming Li | 375ff4c | 2011-02-28 16:40:28 -0600 | [diff] [blame] | 2351 | rtl_rate_control_unregister(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | module_init(rtl_core_module_init); |
| 2355 | module_exit(rtl_core_module_exit); |