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