George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | c1d6604 | 2012-01-07 20:46:45 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. All rights reserved. |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * wlanfae <wlanfae@realtek.com> |
| 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 24 | * Hsinchu 300, Taiwan. |
| 25 | * |
| 26 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include "../wifi.h" |
| 31 | #include "../efuse.h" |
| 32 | #include "../base.h" |
| 33 | #include "../cam.h" |
| 34 | #include "../ps.h" |
| 35 | #include "../usb.h" |
| 36 | #include "reg.h" |
| 37 | #include "def.h" |
| 38 | #include "phy.h" |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 39 | #include "../rtl8192c/phy_common.h" |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 40 | #include "mac.h" |
| 41 | #include "dm.h" |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 42 | #include "../rtl8192c/dm_common.h" |
| 43 | #include "../rtl8192c/fw_common.h" |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 44 | #include "hw.h" |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 45 | #include "../rtl8192ce/hw.h" |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 46 | #include "trx.h" |
| 47 | #include "led.h" |
| 48 | #include "table.h" |
| 49 | |
| 50 | static void _rtl92cu_phy_param_tab_init(struct ieee80211_hw *hw) |
| 51 | { |
| 52 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 53 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 54 | struct rtl_efuse *rtlefuse = rtl_efuse(rtlpriv); |
| 55 | |
| 56 | rtlphy->hwparam_tables[MAC_REG].length = RTL8192CUMAC_2T_ARRAYLENGTH; |
| 57 | rtlphy->hwparam_tables[MAC_REG].pdata = RTL8192CUMAC_2T_ARRAY; |
| 58 | if (IS_HIGHT_PA(rtlefuse->board_type)) { |
| 59 | rtlphy->hwparam_tables[PHY_REG_PG].length = |
| 60 | RTL8192CUPHY_REG_Array_PG_HPLength; |
| 61 | rtlphy->hwparam_tables[PHY_REG_PG].pdata = |
| 62 | RTL8192CUPHY_REG_Array_PG_HP; |
| 63 | } else { |
| 64 | rtlphy->hwparam_tables[PHY_REG_PG].length = |
| 65 | RTL8192CUPHY_REG_ARRAY_PGLENGTH; |
| 66 | rtlphy->hwparam_tables[PHY_REG_PG].pdata = |
| 67 | RTL8192CUPHY_REG_ARRAY_PG; |
| 68 | } |
| 69 | /* 2T */ |
| 70 | rtlphy->hwparam_tables[PHY_REG_2T].length = |
| 71 | RTL8192CUPHY_REG_2TARRAY_LENGTH; |
| 72 | rtlphy->hwparam_tables[PHY_REG_2T].pdata = |
| 73 | RTL8192CUPHY_REG_2TARRAY; |
| 74 | rtlphy->hwparam_tables[RADIOA_2T].length = |
| 75 | RTL8192CURADIOA_2TARRAYLENGTH; |
| 76 | rtlphy->hwparam_tables[RADIOA_2T].pdata = |
| 77 | RTL8192CURADIOA_2TARRAY; |
| 78 | rtlphy->hwparam_tables[RADIOB_2T].length = |
| 79 | RTL8192CURADIOB_2TARRAYLENGTH; |
| 80 | rtlphy->hwparam_tables[RADIOB_2T].pdata = |
| 81 | RTL8192CU_RADIOB_2TARRAY; |
| 82 | rtlphy->hwparam_tables[AGCTAB_2T].length = |
| 83 | RTL8192CUAGCTAB_2TARRAYLENGTH; |
| 84 | rtlphy->hwparam_tables[AGCTAB_2T].pdata = |
| 85 | RTL8192CUAGCTAB_2TARRAY; |
| 86 | /* 1T */ |
| 87 | if (IS_HIGHT_PA(rtlefuse->board_type)) { |
| 88 | rtlphy->hwparam_tables[PHY_REG_1T].length = |
| 89 | RTL8192CUPHY_REG_1T_HPArrayLength; |
| 90 | rtlphy->hwparam_tables[PHY_REG_1T].pdata = |
| 91 | RTL8192CUPHY_REG_1T_HPArray; |
| 92 | rtlphy->hwparam_tables[RADIOA_1T].length = |
| 93 | RTL8192CURadioA_1T_HPArrayLength; |
| 94 | rtlphy->hwparam_tables[RADIOA_1T].pdata = |
| 95 | RTL8192CURadioA_1T_HPArray; |
| 96 | rtlphy->hwparam_tables[RADIOB_1T].length = |
| 97 | RTL8192CURADIOB_1TARRAYLENGTH; |
| 98 | rtlphy->hwparam_tables[RADIOB_1T].pdata = |
| 99 | RTL8192CU_RADIOB_1TARRAY; |
| 100 | rtlphy->hwparam_tables[AGCTAB_1T].length = |
| 101 | RTL8192CUAGCTAB_1T_HPArrayLength; |
| 102 | rtlphy->hwparam_tables[AGCTAB_1T].pdata = |
| 103 | Rtl8192CUAGCTAB_1T_HPArray; |
| 104 | } else { |
| 105 | rtlphy->hwparam_tables[PHY_REG_1T].length = |
| 106 | RTL8192CUPHY_REG_1TARRAY_LENGTH; |
| 107 | rtlphy->hwparam_tables[PHY_REG_1T].pdata = |
| 108 | RTL8192CUPHY_REG_1TARRAY; |
| 109 | rtlphy->hwparam_tables[RADIOA_1T].length = |
| 110 | RTL8192CURADIOA_1TARRAYLENGTH; |
| 111 | rtlphy->hwparam_tables[RADIOA_1T].pdata = |
| 112 | RTL8192CU_RADIOA_1TARRAY; |
| 113 | rtlphy->hwparam_tables[RADIOB_1T].length = |
| 114 | RTL8192CURADIOB_1TARRAYLENGTH; |
| 115 | rtlphy->hwparam_tables[RADIOB_1T].pdata = |
| 116 | RTL8192CU_RADIOB_1TARRAY; |
| 117 | rtlphy->hwparam_tables[AGCTAB_1T].length = |
| 118 | RTL8192CUAGCTAB_1TARRAYLENGTH; |
| 119 | rtlphy->hwparam_tables[AGCTAB_1T].pdata = |
| 120 | RTL8192CUAGCTAB_1TARRAY; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | static void _rtl92cu_read_txpower_info_from_hwpg(struct ieee80211_hw *hw, |
| 125 | bool autoload_fail, |
| 126 | u8 *hwinfo) |
| 127 | { |
| 128 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 129 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 130 | u8 rf_path, index, tempval; |
| 131 | u16 i; |
| 132 | |
| 133 | for (rf_path = 0; rf_path < 2; rf_path++) { |
| 134 | for (i = 0; i < 3; i++) { |
| 135 | if (!autoload_fail) { |
| 136 | rtlefuse-> |
| 137 | eeprom_chnlarea_txpwr_cck[rf_path][i] = |
| 138 | hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i]; |
| 139 | rtlefuse-> |
| 140 | eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] = |
| 141 | hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 + |
| 142 | i]; |
| 143 | } else { |
| 144 | rtlefuse-> |
| 145 | eeprom_chnlarea_txpwr_cck[rf_path][i] = |
| 146 | EEPROM_DEFAULT_TXPOWERLEVEL; |
| 147 | rtlefuse-> |
| 148 | eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] = |
| 149 | EEPROM_DEFAULT_TXPOWERLEVEL; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | for (i = 0; i < 3; i++) { |
| 154 | if (!autoload_fail) |
| 155 | tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i]; |
| 156 | else |
| 157 | tempval = EEPROM_DEFAULT_HT40_2SDIFF; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 158 | rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] = |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 159 | (tempval & 0xf); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 160 | rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] = |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 161 | ((tempval & 0xf0) >> 4); |
| 162 | } |
| 163 | for (rf_path = 0; rf_path < 2; rf_path++) |
| 164 | for (i = 0; i < 3; i++) |
| 165 | RTPRINT(rtlpriv, FINIT, INIT_EEPROM, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 166 | "RF(%d) EEPROM CCK Area(%d) = 0x%x\n", |
| 167 | rf_path, i, |
| 168 | rtlefuse-> |
| 169 | eeprom_chnlarea_txpwr_cck[rf_path][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 170 | for (rf_path = 0; rf_path < 2; rf_path++) |
| 171 | for (i = 0; i < 3; i++) |
| 172 | RTPRINT(rtlpriv, FINIT, INIT_EEPROM, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 173 | "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n", |
| 174 | rf_path, i, |
| 175 | rtlefuse-> |
| 176 | eeprom_chnlarea_txpwr_ht40_1s[rf_path][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 177 | for (rf_path = 0; rf_path < 2; rf_path++) |
| 178 | for (i = 0; i < 3; i++) |
| 179 | RTPRINT(rtlpriv, FINIT, INIT_EEPROM, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 180 | "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n", |
| 181 | rf_path, i, |
| 182 | rtlefuse-> |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 183 | eprom_chnl_txpwr_ht40_2sdf[rf_path][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 184 | for (rf_path = 0; rf_path < 2; rf_path++) { |
| 185 | for (i = 0; i < 14; i++) { |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 186 | index = rtl92c_get_chnl_group((u8)i); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 187 | rtlefuse->txpwrlevel_cck[rf_path][i] = |
| 188 | rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][index]; |
| 189 | rtlefuse->txpwrlevel_ht40_1s[rf_path][i] = |
| 190 | rtlefuse-> |
| 191 | eeprom_chnlarea_txpwr_ht40_1s[rf_path][index]; |
| 192 | if ((rtlefuse-> |
| 193 | eeprom_chnlarea_txpwr_ht40_1s[rf_path][index] - |
| 194 | rtlefuse-> |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 195 | eprom_chnl_txpwr_ht40_2sdf[rf_path][index]) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 196 | > 0) { |
| 197 | rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = |
| 198 | rtlefuse-> |
| 199 | eeprom_chnlarea_txpwr_ht40_1s[rf_path] |
| 200 | [index] - rtlefuse-> |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 201 | eprom_chnl_txpwr_ht40_2sdf[rf_path] |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 202 | [index]; |
| 203 | } else { |
| 204 | rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0; |
| 205 | } |
| 206 | } |
| 207 | for (i = 0; i < 14; i++) { |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 208 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 209 | "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n", rf_path, i, |
| 210 | rtlefuse->txpwrlevel_cck[rf_path][i], |
| 211 | rtlefuse->txpwrlevel_ht40_1s[rf_path][i], |
| 212 | rtlefuse->txpwrlevel_ht40_2s[rf_path][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | for (i = 0; i < 3; i++) { |
| 216 | if (!autoload_fail) { |
| 217 | rtlefuse->eeprom_pwrlimit_ht40[i] = |
| 218 | hwinfo[EEPROM_TXPWR_GROUP + i]; |
| 219 | rtlefuse->eeprom_pwrlimit_ht20[i] = |
| 220 | hwinfo[EEPROM_TXPWR_GROUP + 3 + i]; |
| 221 | } else { |
| 222 | rtlefuse->eeprom_pwrlimit_ht40[i] = 0; |
| 223 | rtlefuse->eeprom_pwrlimit_ht20[i] = 0; |
| 224 | } |
| 225 | } |
| 226 | for (rf_path = 0; rf_path < 2; rf_path++) { |
| 227 | for (i = 0; i < 14; i++) { |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 228 | index = rtl92c_get_chnl_group((u8)i); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 229 | if (rf_path == RF90_PATH_A) { |
| 230 | rtlefuse->pwrgroup_ht20[rf_path][i] = |
| 231 | (rtlefuse->eeprom_pwrlimit_ht20[index] |
| 232 | & 0xf); |
| 233 | rtlefuse->pwrgroup_ht40[rf_path][i] = |
| 234 | (rtlefuse->eeprom_pwrlimit_ht40[index] |
| 235 | & 0xf); |
| 236 | } else if (rf_path == RF90_PATH_B) { |
| 237 | rtlefuse->pwrgroup_ht20[rf_path][i] = |
| 238 | ((rtlefuse->eeprom_pwrlimit_ht20[index] |
| 239 | & 0xf0) >> 4); |
| 240 | rtlefuse->pwrgroup_ht40[rf_path][i] = |
| 241 | ((rtlefuse->eeprom_pwrlimit_ht40[index] |
| 242 | & 0xf0) >> 4); |
| 243 | } |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 244 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 245 | "RF-%d pwrgroup_ht20[%d] = 0x%x\n", |
| 246 | rf_path, i, |
| 247 | rtlefuse->pwrgroup_ht20[rf_path][i]); |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 248 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 249 | "RF-%d pwrgroup_ht40[%d] = 0x%x\n", |
| 250 | rf_path, i, |
| 251 | rtlefuse->pwrgroup_ht40[rf_path][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | for (i = 0; i < 14; i++) { |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 255 | index = rtl92c_get_chnl_group((u8)i); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 256 | if (!autoload_fail) |
| 257 | tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index]; |
| 258 | else |
| 259 | tempval = EEPROM_DEFAULT_HT20_DIFF; |
| 260 | rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF); |
| 261 | rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] = |
| 262 | ((tempval >> 4) & 0xF); |
| 263 | if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3)) |
| 264 | rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0; |
| 265 | if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3)) |
| 266 | rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0; |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 267 | index = rtl92c_get_chnl_group((u8)i); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 268 | if (!autoload_fail) |
| 269 | tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index]; |
| 270 | else |
| 271 | tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF; |
| 272 | rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF); |
| 273 | rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] = |
| 274 | ((tempval >> 4) & 0xF); |
| 275 | } |
| 276 | rtlefuse->legacy_ht_txpowerdiff = |
| 277 | rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7]; |
| 278 | for (i = 0; i < 14; i++) |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 279 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 280 | "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", |
| 281 | i, rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 282 | for (i = 0; i < 14; i++) |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 283 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 284 | "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", |
| 285 | i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 286 | for (i = 0; i < 14; i++) |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 287 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 288 | "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", |
| 289 | i, rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 290 | for (i = 0; i < 14; i++) |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 291 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 292 | "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", |
| 293 | i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 294 | if (!autoload_fail) |
| 295 | rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7); |
| 296 | else |
| 297 | rtlefuse->eeprom_regulatory = 0; |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 298 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 299 | "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 300 | if (!autoload_fail) { |
| 301 | rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A]; |
| 302 | rtlefuse->eeprom_tssi[RF90_PATH_B] = hwinfo[EEPROM_TSSI_B]; |
| 303 | } else { |
| 304 | rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI; |
| 305 | rtlefuse->eeprom_tssi[RF90_PATH_B] = EEPROM_DEFAULT_TSSI; |
| 306 | } |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 307 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 308 | "TSSI_A = 0x%x, TSSI_B = 0x%x\n", |
| 309 | rtlefuse->eeprom_tssi[RF90_PATH_A], |
| 310 | rtlefuse->eeprom_tssi[RF90_PATH_B]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 311 | if (!autoload_fail) |
| 312 | tempval = hwinfo[EEPROM_THERMAL_METER]; |
| 313 | else |
| 314 | tempval = EEPROM_DEFAULT_THERMALMETER; |
| 315 | rtlefuse->eeprom_thermalmeter = (tempval & 0x1f); |
| 316 | if (rtlefuse->eeprom_thermalmeter < 0x06 || |
| 317 | rtlefuse->eeprom_thermalmeter > 0x1c) |
| 318 | rtlefuse->eeprom_thermalmeter = 0x12; |
| 319 | if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail) |
| 320 | rtlefuse->apk_thermalmeterignore = true; |
| 321 | rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter; |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 322 | RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, |
Joe Perches | 4c48869 | 2012-01-04 19:40:42 -0800 | [diff] [blame] | 323 | "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void _rtl92cu_read_board_type(struct ieee80211_hw *hw, u8 *contents) |
| 327 | { |
| 328 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 329 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 330 | u8 boardType; |
| 331 | |
| 332 | if (IS_NORMAL_CHIP(rtlhal->version)) { |
| 333 | boardType = ((contents[EEPROM_RF_OPT1]) & |
| 334 | BOARD_TYPE_NORMAL_MASK) >> 5; /*bit[7:5]*/ |
| 335 | } else { |
| 336 | boardType = contents[EEPROM_RF_OPT4]; |
| 337 | boardType &= BOARD_TYPE_TEST_MASK; |
| 338 | } |
| 339 | rtlefuse->board_type = boardType; |
| 340 | if (IS_HIGHT_PA(rtlefuse->board_type)) |
| 341 | rtlefuse->external_pa = 1; |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 342 | pr_info("Board Type %x\n", rtlefuse->board_type); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 343 | } |
| 344 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 345 | static void _rtl92cu_read_adapter_info(struct ieee80211_hw *hw) |
| 346 | { |
| 347 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 348 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 349 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 350 | u16 i, usvalue; |
| 351 | u8 hwinfo[HWSET_MAX_SIZE] = {0}; |
| 352 | u16 eeprom_id; |
| 353 | |
| 354 | if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) { |
| 355 | rtl_efuse_shadow_map_update(hw); |
| 356 | memcpy((void *)hwinfo, |
| 357 | (void *)&rtlefuse->efuse_map[EFUSE_INIT_MAP][0], |
| 358 | HWSET_MAX_SIZE); |
| 359 | } else if (rtlefuse->epromtype == EEPROM_93C46) { |
| 360 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 361 | "RTL819X Not boot from eeprom, check it !!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 362 | } |
Joe Perches | af08687 | 2012-01-04 19:40:40 -0800 | [diff] [blame] | 363 | RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_LOUD, "MAP", |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 364 | hwinfo, HWSET_MAX_SIZE); |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 365 | eeprom_id = le16_to_cpu(*((__le16 *)&hwinfo[0])); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 366 | if (eeprom_id != RTL8190_EEPROM_ID) { |
| 367 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 368 | "EEPROM ID(%#x) is invalid!!\n", eeprom_id); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 369 | rtlefuse->autoload_failflag = true; |
| 370 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 371 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 372 | rtlefuse->autoload_failflag = false; |
| 373 | } |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 374 | if (rtlefuse->autoload_failflag) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 375 | return; |
| 376 | for (i = 0; i < 6; i += 2) { |
| 377 | usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i]; |
| 378 | *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue; |
| 379 | } |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 380 | pr_info("MAC address: %pM\n", rtlefuse->dev_addr); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 381 | _rtl92cu_read_txpower_info_from_hwpg(hw, |
| 382 | rtlefuse->autoload_failflag, hwinfo); |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 383 | rtlefuse->eeprom_vid = le16_to_cpu(*(__le16 *)&hwinfo[EEPROM_VID]); |
| 384 | rtlefuse->eeprom_did = le16_to_cpu(*(__le16 *)&hwinfo[EEPROM_DID]); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 385 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, " VID = 0x%02x PID = 0x%02x\n", |
| 386 | rtlefuse->eeprom_vid, rtlefuse->eeprom_did); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 387 | rtlefuse->eeprom_channelplan = hwinfo[EEPROM_CHANNELPLAN]; |
Larry Finger | abfabc9 | 2011-11-17 12:14:44 -0600 | [diff] [blame] | 388 | rtlefuse->eeprom_version = |
| 389 | le16_to_cpu(*(__le16 *)&hwinfo[EEPROM_VERSION]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 390 | rtlefuse->txpwr_fromeprom = true; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 391 | rtlefuse->eeprom_oemid = hwinfo[EEPROM_CUSTOMER_ID]; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 392 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "EEPROM Customer ID: 0x%2x\n", |
| 393 | rtlefuse->eeprom_oemid); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 394 | if (rtlhal->oem_id == RT_CID_DEFAULT) { |
| 395 | switch (rtlefuse->eeprom_oemid) { |
| 396 | case EEPROM_CID_DEFAULT: |
| 397 | if (rtlefuse->eeprom_did == 0x8176) { |
| 398 | if ((rtlefuse->eeprom_svid == 0x103C && |
| 399 | rtlefuse->eeprom_smid == 0x1629)) |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 400 | rtlhal->oem_id = RT_CID_819X_HP; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 401 | else |
| 402 | rtlhal->oem_id = RT_CID_DEFAULT; |
| 403 | } else { |
| 404 | rtlhal->oem_id = RT_CID_DEFAULT; |
| 405 | } |
| 406 | break; |
| 407 | case EEPROM_CID_TOSHIBA: |
| 408 | rtlhal->oem_id = RT_CID_TOSHIBA; |
| 409 | break; |
| 410 | case EEPROM_CID_QMI: |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 411 | rtlhal->oem_id = RT_CID_819X_QMI; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 412 | break; |
| 413 | case EEPROM_CID_WHQL: |
| 414 | default: |
| 415 | rtlhal->oem_id = RT_CID_DEFAULT; |
| 416 | break; |
| 417 | } |
| 418 | } |
| 419 | _rtl92cu_read_board_type(hw, hwinfo); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void _rtl92cu_hal_customized_behavior(struct ieee80211_hw *hw) |
| 423 | { |
| 424 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 425 | struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); |
| 426 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 427 | |
| 428 | switch (rtlhal->oem_id) { |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 429 | case RT_CID_819X_HP: |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 430 | usb_priv->ledctl.led_opendrain = true; |
| 431 | break; |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 432 | case RT_CID_819X_LENOVO: |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 433 | case RT_CID_DEFAULT: |
| 434 | case RT_CID_TOSHIBA: |
| 435 | case RT_CID_CCX: |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 436 | case RT_CID_819X_ACER: |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 437 | case RT_CID_WHQL: |
| 438 | default: |
| 439 | break; |
| 440 | } |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 441 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "RT Customized ID: 0x%02X\n", |
| 442 | rtlhal->oem_id); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void rtl92cu_read_eeprom_info(struct ieee80211_hw *hw) |
| 446 | { |
| 447 | |
| 448 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 449 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 450 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 451 | u8 tmp_u1b; |
| 452 | |
| 453 | if (!IS_NORMAL_CHIP(rtlhal->version)) |
| 454 | return; |
| 455 | tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR); |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 456 | rtlefuse->epromtype = (tmp_u1b & BOOT_FROM_EEPROM) ? |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 457 | EEPROM_93C46 : EEPROM_BOOT_EFUSE; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 458 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from %s\n", |
| 459 | tmp_u1b & BOOT_FROM_EEPROM ? "EERROM" : "EFUSE"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 460 | rtlefuse->autoload_failflag = (tmp_u1b & EEPROM_EN) ? false : true; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 461 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload %s\n", |
| 462 | tmp_u1b & EEPROM_EN ? "OK!!" : "ERR!!"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 463 | _rtl92cu_read_adapter_info(hw); |
| 464 | _rtl92cu_hal_customized_behavior(hw); |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | static int _rtl92cu_init_power_on(struct ieee80211_hw *hw) |
| 469 | { |
| 470 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 471 | int status = 0; |
| 472 | u16 value16; |
| 473 | u8 value8; |
| 474 | /* polling autoload done. */ |
| 475 | u32 pollingCount = 0; |
| 476 | |
| 477 | do { |
| 478 | if (rtl_read_byte(rtlpriv, REG_APS_FSMCO) & PFM_ALDN) { |
| 479 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 480 | "Autoload Done!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 481 | break; |
| 482 | } |
| 483 | if (pollingCount++ > 100) { |
| 484 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 485 | "Failed to polling REG_APS_FSMCO[PFM_ALDN] done!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 486 | return -ENODEV; |
| 487 | } |
| 488 | } while (true); |
| 489 | /* 0. RSV_CTRL 0x1C[7:0] = 0 unlock ISO/CLK/Power control register */ |
| 490 | rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0); |
| 491 | /* Power on when re-enter from IPS/Radio off/card disable */ |
| 492 | /* enable SPS into PWM mode */ |
| 493 | rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b); |
| 494 | udelay(100); |
| 495 | value8 = rtl_read_byte(rtlpriv, REG_LDOV12D_CTRL); |
| 496 | if (0 == (value8 & LDV12_EN)) { |
| 497 | value8 |= LDV12_EN; |
| 498 | rtl_write_byte(rtlpriv, REG_LDOV12D_CTRL, value8); |
| 499 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 500 | " power-on :REG_LDOV12D_CTRL Reg0x21:0x%02x\n", |
| 501 | value8); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 502 | udelay(100); |
| 503 | value8 = rtl_read_byte(rtlpriv, REG_SYS_ISO_CTRL); |
| 504 | value8 &= ~ISO_MD2PP; |
| 505 | rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL, value8); |
| 506 | } |
| 507 | /* auto enable WLAN */ |
| 508 | pollingCount = 0; |
| 509 | value16 = rtl_read_word(rtlpriv, REG_APS_FSMCO); |
| 510 | value16 |= APFM_ONMAC; |
| 511 | rtl_write_word(rtlpriv, REG_APS_FSMCO, value16); |
| 512 | do { |
| 513 | if (!(rtl_read_word(rtlpriv, REG_APS_FSMCO) & APFM_ONMAC)) { |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 514 | pr_info("MAC auto ON okay!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 515 | break; |
| 516 | } |
Andy Spencer | ab1796e | 2014-05-02 06:48:13 +0000 | [diff] [blame] | 517 | if (pollingCount++ > 1000) { |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 518 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 519 | "Failed to polling REG_APS_FSMCO[APFM_ONMAC] done!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 520 | return -ENODEV; |
| 521 | } |
| 522 | } while (true); |
| 523 | /* Enable Radio ,GPIO ,and LED function */ |
| 524 | rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x0812); |
| 525 | /* release RF digital isolation */ |
| 526 | value16 = rtl_read_word(rtlpriv, REG_SYS_ISO_CTRL); |
| 527 | value16 &= ~ISO_DIOR; |
| 528 | rtl_write_word(rtlpriv, REG_SYS_ISO_CTRL, value16); |
| 529 | /* Reconsider when to do this operation after asking HWSD. */ |
| 530 | pollingCount = 0; |
| 531 | rtl_write_byte(rtlpriv, REG_APSD_CTRL, (rtl_read_byte(rtlpriv, |
| 532 | REG_APSD_CTRL) & ~BIT(6))); |
| 533 | do { |
| 534 | pollingCount++; |
| 535 | } while ((pollingCount < 200) && |
| 536 | (rtl_read_byte(rtlpriv, REG_APSD_CTRL) & BIT(7))); |
| 537 | /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */ |
| 538 | value16 = rtl_read_word(rtlpriv, REG_CR); |
| 539 | value16 |= (HCI_TXDMA_EN | HCI_RXDMA_EN | TXDMA_EN | RXDMA_EN | |
| 540 | PROTOCOL_EN | SCHEDULE_EN | MACTXEN | MACRXEN | ENSEC); |
| 541 | rtl_write_word(rtlpriv, REG_CR, value16); |
| 542 | return status; |
| 543 | } |
| 544 | |
| 545 | static void _rtl92cu_init_queue_reserved_page(struct ieee80211_hw *hw, |
| 546 | bool wmm_enable, |
| 547 | u8 out_ep_num, |
| 548 | u8 queue_sel) |
| 549 | { |
| 550 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 551 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 552 | bool isChipN = IS_NORMAL_CHIP(rtlhal->version); |
| 553 | u32 outEPNum = (u32)out_ep_num; |
| 554 | u32 numHQ = 0; |
| 555 | u32 numLQ = 0; |
| 556 | u32 numNQ = 0; |
| 557 | u32 numPubQ; |
| 558 | u32 value32; |
| 559 | u8 value8; |
| 560 | u32 txQPageNum, txQPageUnit, txQRemainPage; |
| 561 | |
| 562 | if (!wmm_enable) { |
| 563 | numPubQ = (isChipN) ? CHIP_B_PAGE_NUM_PUBQ : |
| 564 | CHIP_A_PAGE_NUM_PUBQ; |
| 565 | txQPageNum = TX_TOTAL_PAGE_NUMBER - numPubQ; |
| 566 | |
| 567 | txQPageUnit = txQPageNum/outEPNum; |
| 568 | txQRemainPage = txQPageNum % outEPNum; |
| 569 | if (queue_sel & TX_SELE_HQ) |
| 570 | numHQ = txQPageUnit; |
| 571 | if (queue_sel & TX_SELE_LQ) |
| 572 | numLQ = txQPageUnit; |
| 573 | /* HIGH priority queue always present in the configuration of |
| 574 | * 2 out-ep. Remainder pages have assigned to High queue */ |
| 575 | if ((outEPNum > 1) && (txQRemainPage)) |
| 576 | numHQ += txQRemainPage; |
| 577 | /* NOTE: This step done before writting REG_RQPN. */ |
| 578 | if (isChipN) { |
| 579 | if (queue_sel & TX_SELE_NQ) |
| 580 | numNQ = txQPageUnit; |
| 581 | value8 = (u8)_NPQ(numNQ); |
| 582 | rtl_write_byte(rtlpriv, REG_RQPN_NPQ, value8); |
| 583 | } |
| 584 | } else { |
| 585 | /* for WMM ,number of out-ep must more than or equal to 2! */ |
| 586 | numPubQ = isChipN ? WMM_CHIP_B_PAGE_NUM_PUBQ : |
| 587 | WMM_CHIP_A_PAGE_NUM_PUBQ; |
| 588 | if (queue_sel & TX_SELE_HQ) { |
| 589 | numHQ = isChipN ? WMM_CHIP_B_PAGE_NUM_HPQ : |
| 590 | WMM_CHIP_A_PAGE_NUM_HPQ; |
| 591 | } |
| 592 | if (queue_sel & TX_SELE_LQ) { |
| 593 | numLQ = isChipN ? WMM_CHIP_B_PAGE_NUM_LPQ : |
| 594 | WMM_CHIP_A_PAGE_NUM_LPQ; |
| 595 | } |
| 596 | /* NOTE: This step done before writting REG_RQPN. */ |
| 597 | if (isChipN) { |
| 598 | if (queue_sel & TX_SELE_NQ) |
| 599 | numNQ = WMM_CHIP_B_PAGE_NUM_NPQ; |
| 600 | value8 = (u8)_NPQ(numNQ); |
| 601 | rtl_write_byte(rtlpriv, REG_RQPN_NPQ, value8); |
| 602 | } |
| 603 | } |
| 604 | /* TX DMA */ |
| 605 | value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN; |
| 606 | rtl_write_dword(rtlpriv, REG_RQPN, value32); |
| 607 | } |
| 608 | |
| 609 | static void _rtl92c_init_trx_buffer(struct ieee80211_hw *hw, bool wmm_enable) |
| 610 | { |
| 611 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 612 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 613 | u8 txpktbuf_bndy; |
| 614 | u8 value8; |
| 615 | |
| 616 | if (!wmm_enable) |
| 617 | txpktbuf_bndy = TX_PAGE_BOUNDARY; |
| 618 | else /* for WMM */ |
| 619 | txpktbuf_bndy = (IS_NORMAL_CHIP(rtlhal->version)) |
| 620 | ? WMM_CHIP_B_TX_PAGE_BOUNDARY |
| 621 | : WMM_CHIP_A_TX_PAGE_BOUNDARY; |
| 622 | rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy); |
| 623 | rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy); |
| 624 | rtl_write_byte(rtlpriv, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy); |
| 625 | rtl_write_byte(rtlpriv, REG_TRXFF_BNDY, txpktbuf_bndy); |
| 626 | rtl_write_byte(rtlpriv, REG_TDECTRL+1, txpktbuf_bndy); |
| 627 | rtl_write_word(rtlpriv, (REG_TRXFF_BNDY + 2), 0x27FF); |
| 628 | value8 = _PSRX(RX_PAGE_SIZE_REG_VALUE) | _PSTX(PBP_128); |
| 629 | rtl_write_byte(rtlpriv, REG_PBP, value8); |
| 630 | } |
| 631 | |
| 632 | static void _rtl92c_init_chipN_reg_priority(struct ieee80211_hw *hw, u16 beQ, |
| 633 | u16 bkQ, u16 viQ, u16 voQ, |
| 634 | u16 mgtQ, u16 hiQ) |
| 635 | { |
| 636 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 637 | u16 value16 = (rtl_read_word(rtlpriv, REG_TRXDMA_CTRL) & 0x7); |
| 638 | |
| 639 | value16 |= _TXDMA_BEQ_MAP(beQ) | _TXDMA_BKQ_MAP(bkQ) | |
| 640 | _TXDMA_VIQ_MAP(viQ) | _TXDMA_VOQ_MAP(voQ) | |
| 641 | _TXDMA_MGQ_MAP(mgtQ) | _TXDMA_HIQ_MAP(hiQ); |
| 642 | rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, value16); |
| 643 | } |
| 644 | |
| 645 | static void _rtl92cu_init_chipN_one_out_ep_priority(struct ieee80211_hw *hw, |
| 646 | bool wmm_enable, |
| 647 | u8 queue_sel) |
| 648 | { |
| 649 | u16 uninitialized_var(value); |
| 650 | |
| 651 | switch (queue_sel) { |
| 652 | case TX_SELE_HQ: |
| 653 | value = QUEUE_HIGH; |
| 654 | break; |
| 655 | case TX_SELE_LQ: |
| 656 | value = QUEUE_LOW; |
| 657 | break; |
| 658 | case TX_SELE_NQ: |
| 659 | value = QUEUE_NORMAL; |
| 660 | break; |
| 661 | default: |
| 662 | WARN_ON(1); /* Shall not reach here! */ |
| 663 | break; |
| 664 | } |
| 665 | _rtl92c_init_chipN_reg_priority(hw, value, value, value, value, |
| 666 | value, value); |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 667 | pr_info("Tx queue select: 0x%02x\n", queue_sel); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void _rtl92cu_init_chipN_two_out_ep_priority(struct ieee80211_hw *hw, |
| 671 | bool wmm_enable, |
| 672 | u8 queue_sel) |
| 673 | { |
| 674 | u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ; |
| 675 | u16 uninitialized_var(valueHi); |
| 676 | u16 uninitialized_var(valueLow); |
| 677 | |
| 678 | switch (queue_sel) { |
| 679 | case (TX_SELE_HQ | TX_SELE_LQ): |
| 680 | valueHi = QUEUE_HIGH; |
| 681 | valueLow = QUEUE_LOW; |
| 682 | break; |
| 683 | case (TX_SELE_NQ | TX_SELE_LQ): |
| 684 | valueHi = QUEUE_NORMAL; |
| 685 | valueLow = QUEUE_LOW; |
| 686 | break; |
| 687 | case (TX_SELE_HQ | TX_SELE_NQ): |
| 688 | valueHi = QUEUE_HIGH; |
| 689 | valueLow = QUEUE_NORMAL; |
| 690 | break; |
| 691 | default: |
| 692 | WARN_ON(1); |
| 693 | break; |
| 694 | } |
| 695 | if (!wmm_enable) { |
| 696 | beQ = valueLow; |
| 697 | bkQ = valueLow; |
| 698 | viQ = valueHi; |
| 699 | voQ = valueHi; |
| 700 | mgtQ = valueHi; |
| 701 | hiQ = valueHi; |
| 702 | } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */ |
| 703 | beQ = valueHi; |
| 704 | bkQ = valueLow; |
| 705 | viQ = valueLow; |
| 706 | voQ = valueHi; |
| 707 | mgtQ = valueHi; |
| 708 | hiQ = valueHi; |
| 709 | } |
| 710 | _rtl92c_init_chipN_reg_priority(hw, beQ, bkQ, viQ, voQ, mgtQ, hiQ); |
Joe Perches | 292b119 | 2011-07-20 08:51:35 -0700 | [diff] [blame] | 711 | pr_info("Tx queue select: 0x%02x\n", queue_sel); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static void _rtl92cu_init_chipN_three_out_ep_priority(struct ieee80211_hw *hw, |
| 715 | bool wmm_enable, |
| 716 | u8 queue_sel) |
| 717 | { |
| 718 | u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ; |
| 719 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 720 | |
| 721 | if (!wmm_enable) { /* typical setting */ |
| 722 | beQ = QUEUE_LOW; |
| 723 | bkQ = QUEUE_LOW; |
| 724 | viQ = QUEUE_NORMAL; |
| 725 | voQ = QUEUE_HIGH; |
| 726 | mgtQ = QUEUE_HIGH; |
| 727 | hiQ = QUEUE_HIGH; |
| 728 | } else { /* for WMM */ |
| 729 | beQ = QUEUE_LOW; |
| 730 | bkQ = QUEUE_NORMAL; |
| 731 | viQ = QUEUE_NORMAL; |
| 732 | voQ = QUEUE_HIGH; |
| 733 | mgtQ = QUEUE_HIGH; |
| 734 | hiQ = QUEUE_HIGH; |
| 735 | } |
| 736 | _rtl92c_init_chipN_reg_priority(hw, beQ, bkQ, viQ, voQ, mgtQ, hiQ); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 737 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Tx queue select :0x%02x..\n", |
| 738 | queue_sel); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static void _rtl92cu_init_chipN_queue_priority(struct ieee80211_hw *hw, |
| 742 | bool wmm_enable, |
| 743 | u8 out_ep_num, |
| 744 | u8 queue_sel) |
| 745 | { |
| 746 | switch (out_ep_num) { |
| 747 | case 1: |
| 748 | _rtl92cu_init_chipN_one_out_ep_priority(hw, wmm_enable, |
| 749 | queue_sel); |
| 750 | break; |
| 751 | case 2: |
| 752 | _rtl92cu_init_chipN_two_out_ep_priority(hw, wmm_enable, |
| 753 | queue_sel); |
| 754 | break; |
| 755 | case 3: |
| 756 | _rtl92cu_init_chipN_three_out_ep_priority(hw, wmm_enable, |
| 757 | queue_sel); |
| 758 | break; |
| 759 | default: |
| 760 | WARN_ON(1); /* Shall not reach here! */ |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | static void _rtl92cu_init_chipT_queue_priority(struct ieee80211_hw *hw, |
| 766 | bool wmm_enable, |
| 767 | u8 out_ep_num, |
| 768 | u8 queue_sel) |
| 769 | { |
Larry Finger | 9f219bd | 2011-04-13 21:00:02 -0500 | [diff] [blame] | 770 | u8 hq_sele = 0; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 771 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 772 | |
| 773 | switch (out_ep_num) { |
| 774 | case 2: /* (TX_SELE_HQ|TX_SELE_LQ) */ |
| 775 | if (!wmm_enable) /* typical setting */ |
| 776 | hq_sele = HQSEL_VOQ | HQSEL_VIQ | HQSEL_MGTQ | |
| 777 | HQSEL_HIQ; |
| 778 | else /* for WMM */ |
| 779 | hq_sele = HQSEL_VOQ | HQSEL_BEQ | HQSEL_MGTQ | |
| 780 | HQSEL_HIQ; |
| 781 | break; |
| 782 | case 1: |
| 783 | if (TX_SELE_LQ == queue_sel) { |
| 784 | /* map all endpoint to Low queue */ |
| 785 | hq_sele = 0; |
| 786 | } else if (TX_SELE_HQ == queue_sel) { |
| 787 | /* map all endpoint to High queue */ |
| 788 | hq_sele = HQSEL_VOQ | HQSEL_VIQ | HQSEL_BEQ | |
| 789 | HQSEL_BKQ | HQSEL_MGTQ | HQSEL_HIQ; |
| 790 | } |
| 791 | break; |
| 792 | default: |
| 793 | WARN_ON(1); /* Shall not reach here! */ |
| 794 | break; |
| 795 | } |
| 796 | rtl_write_byte(rtlpriv, (REG_TRXDMA_CTRL+1), hq_sele); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 797 | RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Tx queue select :0x%02x..\n", |
| 798 | hq_sele); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | static void _rtl92cu_init_queue_priority(struct ieee80211_hw *hw, |
| 802 | bool wmm_enable, |
| 803 | u8 out_ep_num, |
| 804 | u8 queue_sel) |
| 805 | { |
| 806 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 807 | if (IS_NORMAL_CHIP(rtlhal->version)) |
| 808 | _rtl92cu_init_chipN_queue_priority(hw, wmm_enable, out_ep_num, |
| 809 | queue_sel); |
| 810 | else |
| 811 | _rtl92cu_init_chipT_queue_priority(hw, wmm_enable, out_ep_num, |
| 812 | queue_sel); |
| 813 | } |
| 814 | |
| 815 | static void _rtl92cu_init_usb_aggregation(struct ieee80211_hw *hw) |
| 816 | { |
| 817 | } |
| 818 | |
| 819 | static void _rtl92cu_init_wmac_setting(struct ieee80211_hw *hw) |
| 820 | { |
| 821 | u16 value16; |
| 822 | |
| 823 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 824 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 825 | |
Chaoming_Li | 76c34f9 | 2011-04-25 12:54:05 -0500 | [diff] [blame] | 826 | mac->rx_conf = (RCR_APM | RCR_AM | RCR_ADF | RCR_AB | RCR_APPFCS | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 827 | RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL | |
| 828 | RCR_APP_MIC | RCR_APP_PHYSTS | RCR_ACRC32); |
| 829 | rtl_write_dword(rtlpriv, REG_RCR, mac->rx_conf); |
| 830 | /* Accept all multicast address */ |
| 831 | rtl_write_dword(rtlpriv, REG_MAR, 0xFFFFFFFF); |
| 832 | rtl_write_dword(rtlpriv, REG_MAR + 4, 0xFFFFFFFF); |
| 833 | /* Accept all management frames */ |
| 834 | value16 = 0xFFFF; |
| 835 | rtl92c_set_mgt_filter(hw, value16); |
| 836 | /* Reject all control frame - default value is 0 */ |
| 837 | rtl92c_set_ctrl_filter(hw, 0x0); |
| 838 | /* Accept all data frames */ |
| 839 | value16 = 0xFFFF; |
| 840 | rtl92c_set_data_filter(hw, value16); |
| 841 | } |
| 842 | |
| 843 | static int _rtl92cu_init_mac(struct ieee80211_hw *hw) |
| 844 | { |
| 845 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 846 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 847 | struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw); |
| 848 | struct rtl_usb *rtlusb = rtl_usbdev(usb_priv); |
| 849 | int err = 0; |
| 850 | u32 boundary = 0; |
| 851 | u8 wmm_enable = false; /* TODO */ |
| 852 | u8 out_ep_nums = rtlusb->out_ep_nums; |
| 853 | u8 queue_sel = rtlusb->out_queue_sel; |
| 854 | err = _rtl92cu_init_power_on(hw); |
| 855 | |
| 856 | if (err) { |
| 857 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 858 | "Failed to init power on!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 859 | return err; |
| 860 | } |
| 861 | if (!wmm_enable) { |
| 862 | boundary = TX_PAGE_BOUNDARY; |
| 863 | } else { /* for WMM */ |
| 864 | boundary = (IS_NORMAL_CHIP(rtlhal->version)) |
| 865 | ? WMM_CHIP_B_TX_PAGE_BOUNDARY |
| 866 | : WMM_CHIP_A_TX_PAGE_BOUNDARY; |
| 867 | } |
| 868 | if (false == rtl92c_init_llt_table(hw, boundary)) { |
| 869 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 870 | "Failed to init LLT Table!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 871 | return -EINVAL; |
| 872 | } |
| 873 | _rtl92cu_init_queue_reserved_page(hw, wmm_enable, out_ep_nums, |
| 874 | queue_sel); |
| 875 | _rtl92c_init_trx_buffer(hw, wmm_enable); |
| 876 | _rtl92cu_init_queue_priority(hw, wmm_enable, out_ep_nums, |
| 877 | queue_sel); |
| 878 | /* Get Rx PHY status in order to report RSSI and others. */ |
| 879 | rtl92c_init_driver_info_size(hw, RTL92C_DRIVER_INFO_SIZE); |
| 880 | rtl92c_init_interrupt(hw); |
| 881 | rtl92c_init_network_type(hw); |
| 882 | _rtl92cu_init_wmac_setting(hw); |
| 883 | rtl92c_init_adaptive_ctrl(hw); |
| 884 | rtl92c_init_edca(hw); |
| 885 | rtl92c_init_rate_fallback(hw); |
| 886 | rtl92c_init_retry_function(hw); |
| 887 | _rtl92cu_init_usb_aggregation(hw); |
| 888 | rtlpriv->cfg->ops->set_bw_mode(hw, NL80211_CHAN_HT20); |
| 889 | rtl92c_set_min_space(hw, IS_92C_SERIAL(rtlhal->version)); |
| 890 | rtl92c_init_beacon_parameters(hw, rtlhal->version); |
| 891 | rtl92c_init_ampdu_aggregation(hw); |
| 892 | rtl92c_init_beacon_max_error(hw, true); |
| 893 | return err; |
| 894 | } |
| 895 | |
| 896 | void rtl92cu_enable_hw_security_config(struct ieee80211_hw *hw) |
| 897 | { |
| 898 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 899 | u8 sec_reg_value = 0x0; |
| 900 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 901 | |
| 902 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 903 | "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n", |
| 904 | rtlpriv->sec.pairwise_enc_algorithm, |
| 905 | rtlpriv->sec.group_enc_algorithm); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 906 | if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { |
| 907 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 908 | "not open sw encryption\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 909 | return; |
| 910 | } |
| 911 | sec_reg_value = SCR_TxEncEnable | SCR_RxDecEnable; |
| 912 | if (rtlpriv->sec.use_defaultkey) { |
| 913 | sec_reg_value |= SCR_TxUseDK; |
| 914 | sec_reg_value |= SCR_RxUseDK; |
| 915 | } |
| 916 | if (IS_NORMAL_CHIP(rtlhal->version)) |
| 917 | sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK); |
| 918 | rtl_write_byte(rtlpriv, REG_CR + 1, 0x02); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 919 | RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD, "The SECR-value %x\n", |
| 920 | sec_reg_value); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 921 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value); |
| 922 | } |
| 923 | |
| 924 | static void _rtl92cu_hw_configure(struct ieee80211_hw *hw) |
| 925 | { |
| 926 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 927 | struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); |
| 928 | |
| 929 | /* To Fix MAC loopback mode fail. */ |
| 930 | rtl_write_byte(rtlpriv, REG_LDOHCI12_CTRL, 0x0f); |
| 931 | rtl_write_byte(rtlpriv, 0x15, 0xe9); |
| 932 | /* HW SEQ CTRL */ |
| 933 | /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */ |
| 934 | rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF); |
| 935 | /* fixed USB interface interference issue */ |
| 936 | rtl_write_byte(rtlpriv, 0xfe40, 0xe0); |
| 937 | rtl_write_byte(rtlpriv, 0xfe41, 0x8d); |
| 938 | rtl_write_byte(rtlpriv, 0xfe42, 0x80); |
| 939 | rtlusb->reg_bcn_ctrl_val = 0x18; |
| 940 | rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlusb->reg_bcn_ctrl_val); |
| 941 | } |
| 942 | |
| 943 | static void _InitPABias(struct ieee80211_hw *hw) |
| 944 | { |
| 945 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 946 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 947 | u8 pa_setting; |
| 948 | |
| 949 | /* FIXED PA current issue */ |
| 950 | pa_setting = efuse_read_1byte(hw, 0x1FA); |
| 951 | if (!(pa_setting & BIT(0))) { |
| 952 | rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0FFFFF, 0x0F406); |
| 953 | rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0FFFFF, 0x4F406); |
| 954 | rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0FFFFF, 0x8F406); |
| 955 | rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0FFFFF, 0xCF406); |
| 956 | } |
| 957 | if (!(pa_setting & BIT(1)) && IS_NORMAL_CHIP(rtlhal->version) && |
| 958 | IS_92C_SERIAL(rtlhal->version)) { |
| 959 | rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0FFFFF, 0x0F406); |
| 960 | rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0FFFFF, 0x4F406); |
| 961 | rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0FFFFF, 0x8F406); |
| 962 | rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0FFFFF, 0xCF406); |
| 963 | } |
| 964 | if (!(pa_setting & BIT(4))) { |
| 965 | pa_setting = rtl_read_byte(rtlpriv, 0x16); |
| 966 | pa_setting &= 0x0F; |
| 967 | rtl_write_byte(rtlpriv, 0x16, pa_setting | 0x90); |
| 968 | } |
| 969 | } |
| 970 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 971 | static void _update_mac_setting(struct ieee80211_hw *hw) |
| 972 | { |
| 973 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 974 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 975 | |
| 976 | mac->rx_conf = rtl_read_dword(rtlpriv, REG_RCR); |
| 977 | mac->rx_mgt_filter = rtl_read_word(rtlpriv, REG_RXFLTMAP0); |
| 978 | mac->rx_ctrl_filter = rtl_read_word(rtlpriv, REG_RXFLTMAP1); |
| 979 | mac->rx_data_filter = rtl_read_word(rtlpriv, REG_RXFLTMAP2); |
| 980 | } |
| 981 | |
| 982 | int rtl92cu_hw_init(struct ieee80211_hw *hw) |
| 983 | { |
| 984 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 985 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 986 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 987 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 988 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 989 | int err = 0; |
| 990 | static bool iqk_initialized; |
Larry Finger | a53268b | 2014-03-04 16:53:50 -0600 | [diff] [blame] | 991 | unsigned long flags; |
| 992 | |
| 993 | /* As this function can take a very long time (up to 350 ms) |
| 994 | * and can be called with irqs disabled, reenable the irqs |
| 995 | * to let the other devices continue being serviced. |
| 996 | * |
| 997 | * It is safe doing so since our own interrupts will only be enabled |
| 998 | * in a subsequent step. |
| 999 | */ |
| 1000 | local_save_flags(flags); |
| 1001 | local_irq_enable(); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1002 | |
| 1003 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192CU; |
| 1004 | err = _rtl92cu_init_mac(hw); |
| 1005 | if (err) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1006 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "init mac failed!\n"); |
Ben Hutchings | 3234f5b | 2014-04-26 21:59:04 +0100 | [diff] [blame] | 1007 | goto exit; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1008 | } |
| 1009 | err = rtl92c_download_fw(hw); |
| 1010 | if (err) { |
| 1011 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1012 | "Failed to download FW. Init HW without FW now..\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1013 | err = 1; |
Larry Finger | a53268b | 2014-03-04 16:53:50 -0600 | [diff] [blame] | 1014 | goto exit; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1015 | } |
| 1016 | rtlhal->last_hmeboxnum = 0; /* h2c */ |
| 1017 | _rtl92cu_phy_param_tab_init(hw); |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1018 | rtl92cu_phy_mac_config(hw); |
| 1019 | rtl92cu_phy_bb_config(hw); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1020 | rtlphy->rf_mode = RF_OP_BY_SW_3WIRE; |
| 1021 | rtl92c_phy_rf_config(hw); |
| 1022 | if (IS_VENDOR_UMC_A_CUT(rtlhal->version) && |
| 1023 | !IS_92C_SERIAL(rtlhal->version)) { |
| 1024 | rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255); |
| 1025 | rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00); |
| 1026 | } |
| 1027 | rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0, |
| 1028 | RF_CHNLBW, RFREG_OFFSET_MASK); |
| 1029 | rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1, |
| 1030 | RF_CHNLBW, RFREG_OFFSET_MASK); |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1031 | rtl92cu_bb_block_on(hw); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1032 | rtl_cam_reset_all_entry(hw); |
| 1033 | rtl92cu_enable_hw_security_config(hw); |
| 1034 | ppsc->rfpwr_state = ERFON; |
| 1035 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); |
| 1036 | if (ppsc->rfpwr_state == ERFON) { |
| 1037 | rtl92c_phy_set_rfpath_switch(hw, 1); |
| 1038 | if (iqk_initialized) { |
Mark Cave-Ayland | d3af1ce | 2013-11-18 13:06:55 -0600 | [diff] [blame] | 1039 | rtl92c_phy_iq_calibrate(hw, true); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1040 | } else { |
| 1041 | rtl92c_phy_iq_calibrate(hw, false); |
| 1042 | iqk_initialized = true; |
| 1043 | } |
| 1044 | rtl92c_dm_check_txpower_tracking(hw); |
| 1045 | rtl92c_phy_lc_calibrate(hw); |
| 1046 | } |
| 1047 | _rtl92cu_hw_configure(hw); |
| 1048 | _InitPABias(hw); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1049 | _update_mac_setting(hw); |
| 1050 | rtl92c_dm_init(hw); |
Larry Finger | a53268b | 2014-03-04 16:53:50 -0600 | [diff] [blame] | 1051 | exit: |
| 1052 | local_irq_restore(flags); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1053 | return err; |
| 1054 | } |
| 1055 | |
| 1056 | static void _DisableRFAFEAndResetBB(struct ieee80211_hw *hw) |
| 1057 | { |
| 1058 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1059 | /************************************** |
| 1060 | a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue |
| 1061 | b. RF path 0 offset 0x00 = 0x00 disable RF |
| 1062 | c. APSD_CTRL 0x600[7:0] = 0x40 |
| 1063 | d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine |
| 1064 | e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine |
| 1065 | ***************************************/ |
| 1066 | u8 eRFPath = 0, value8 = 0; |
| 1067 | rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF); |
| 1068 | rtl_set_rfreg(hw, (enum radio_path)eRFPath, 0x0, MASKBYTE0, 0x0); |
| 1069 | |
| 1070 | value8 |= APSDOFF; |
| 1071 | rtl_write_byte(rtlpriv, REG_APSD_CTRL, value8); /*0x40*/ |
| 1072 | value8 = 0; |
| 1073 | value8 |= (FEN_USBD | FEN_USBA | FEN_BB_GLB_RSTn); |
| 1074 | rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, value8);/*0x16*/ |
| 1075 | value8 &= (~FEN_BB_GLB_RSTn); |
| 1076 | rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, value8); /*0x14*/ |
| 1077 | } |
| 1078 | |
| 1079 | static void _ResetDigitalProcedure1(struct ieee80211_hw *hw, bool bWithoutHWSM) |
| 1080 | { |
| 1081 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1082 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1083 | |
| 1084 | if (rtlhal->fw_version <= 0x20) { |
| 1085 | /***************************** |
| 1086 | f. MCUFWDL 0x80[7:0]=0 reset MCU ready status |
| 1087 | g. SYS_FUNC_EN 0x02[10]= 0 reset MCU reg, (8051 reset) |
| 1088 | h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC reg, DCORE |
| 1089 | i. SYS_FUNC_EN 0x02[10]= 1 enable MCU reg, (8051 enable) |
| 1090 | ******************************/ |
| 1091 | u16 valu16 = 0; |
| 1092 | |
| 1093 | rtl_write_byte(rtlpriv, REG_MCUFWDL, 0); |
| 1094 | valu16 = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN); |
| 1095 | rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (valu16 & |
| 1096 | (~FEN_CPUEN))); /* reset MCU ,8051 */ |
| 1097 | valu16 = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN)&0x0FFF; |
| 1098 | rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (valu16 | |
| 1099 | (FEN_HWPDN|FEN_ELDR))); /* reset MAC */ |
| 1100 | valu16 = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN); |
| 1101 | rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (valu16 | |
| 1102 | FEN_CPUEN)); /* enable MCU ,8051 */ |
| 1103 | } else { |
| 1104 | u8 retry_cnts = 0; |
| 1105 | |
| 1106 | /* IF fw in RAM code, do reset */ |
| 1107 | if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(1)) { |
| 1108 | /* reset MCU ready status */ |
| 1109 | rtl_write_byte(rtlpriv, REG_MCUFWDL, 0); |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 1110 | /* 8051 reset by self */ |
| 1111 | rtl_write_byte(rtlpriv, REG_HMETFR+3, 0x20); |
| 1112 | while ((retry_cnts++ < 100) && |
| 1113 | (FEN_CPUEN & rtl_read_word(rtlpriv, |
| 1114 | REG_SYS_FUNC_EN))) { |
| 1115 | udelay(50); |
| 1116 | } |
| 1117 | if (retry_cnts >= 100) { |
| 1118 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1119 | "#####=> 8051 reset failed!.........................\n"); |
| 1120 | /* if 8051 reset fail, reset MAC. */ |
| 1121 | rtl_write_byte(rtlpriv, |
| 1122 | REG_SYS_FUNC_EN + 1, |
| 1123 | 0x50); |
| 1124 | udelay(100); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | /* Reset MAC and Enable 8051 */ |
| 1128 | rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x54); |
| 1129 | rtl_write_byte(rtlpriv, REG_MCUFWDL, 0); |
| 1130 | } |
| 1131 | if (bWithoutHWSM) { |
| 1132 | /***************************** |
| 1133 | Without HW auto state machine |
| 1134 | g.SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock |
| 1135 | h.AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL |
| 1136 | i.AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK |
| 1137 | j.SYS_ISu_CTRL 0x00[7:0] = 0xF9 isolated digital to PON |
| 1138 | ******************************/ |
| 1139 | rtl_write_word(rtlpriv, REG_SYS_CLKR, 0x70A3); |
| 1140 | rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80); |
| 1141 | rtl_write_word(rtlpriv, REG_AFE_XTAL_CTRL, 0x880F); |
| 1142 | rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL, 0xF9); |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | static void _ResetDigitalProcedure2(struct ieee80211_hw *hw) |
| 1147 | { |
| 1148 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1149 | /***************************** |
| 1150 | k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction |
| 1151 | l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock |
| 1152 | m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON |
| 1153 | ******************************/ |
| 1154 | rtl_write_word(rtlpriv, REG_SYS_CLKR, 0x70A3); |
| 1155 | rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL+1, 0x82); |
| 1156 | } |
| 1157 | |
| 1158 | static void _DisableGPIO(struct ieee80211_hw *hw) |
| 1159 | { |
| 1160 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1161 | /*************************************** |
| 1162 | j. GPIO_PIN_CTRL 0x44[31:0]=0x000 |
| 1163 | k. Value = GPIO_PIN_CTRL[7:0] |
| 1164 | l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write ext PIN level |
| 1165 | m. GPIO_MUXCFG 0x42 [15:0] = 0x0780 |
| 1166 | n. LEDCFG 0x4C[15:0] = 0x8080 |
| 1167 | ***************************************/ |
| 1168 | u8 value8; |
| 1169 | u16 value16; |
| 1170 | u32 value32; |
| 1171 | |
| 1172 | /* 1. Disable GPIO[7:0] */ |
| 1173 | rtl_write_word(rtlpriv, REG_GPIO_PIN_CTRL+2, 0x0000); |
| 1174 | value32 = rtl_read_dword(rtlpriv, REG_GPIO_PIN_CTRL) & 0xFFFF00FF; |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 1175 | value8 = (u8)(value32&0x000000FF); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1176 | value32 |= ((value8<<8) | 0x00FF0000); |
| 1177 | rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, value32); |
| 1178 | /* 2. Disable GPIO[10:8] */ |
| 1179 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG+3, 0x00); |
| 1180 | value16 = rtl_read_word(rtlpriv, REG_GPIO_MUXCFG+2) & 0xFF0F; |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 1181 | value8 = (u8)(value16&0x000F); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1182 | value16 |= ((value8<<4) | 0x0780); |
| 1183 | rtl_write_word(rtlpriv, REG_GPIO_PIN_CTRL+2, value16); |
| 1184 | /* 3. Disable LED0 & 1 */ |
| 1185 | rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080); |
| 1186 | } |
| 1187 | |
| 1188 | static void _DisableAnalog(struct ieee80211_hw *hw, bool bWithoutHWSM) |
| 1189 | { |
| 1190 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1191 | u16 value16 = 0; |
| 1192 | u8 value8 = 0; |
| 1193 | |
| 1194 | if (bWithoutHWSM) { |
| 1195 | /***************************** |
| 1196 | n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power |
| 1197 | o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power |
| 1198 | r. When driver call disable, the ASIC will turn off remaining |
| 1199 | clock automatically |
| 1200 | ******************************/ |
| 1201 | rtl_write_byte(rtlpriv, REG_LDOA15_CTRL, 0x04); |
| 1202 | value8 = rtl_read_byte(rtlpriv, REG_LDOV12D_CTRL); |
| 1203 | value8 &= (~LDV12_EN); |
| 1204 | rtl_write_byte(rtlpriv, REG_LDOV12D_CTRL, value8); |
| 1205 | } |
| 1206 | |
| 1207 | /***************************** |
| 1208 | h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode |
| 1209 | i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend |
| 1210 | ******************************/ |
| 1211 | rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23); |
| 1212 | value16 |= (APDM_HOST | AFSM_HSUS | PFM_ALDN); |
| 1213 | rtl_write_word(rtlpriv, REG_APS_FSMCO, (u16)value16); |
| 1214 | rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0E); |
| 1215 | } |
| 1216 | |
| 1217 | static void _CardDisableHWSM(struct ieee80211_hw *hw) |
| 1218 | { |
| 1219 | /* ==== RF Off Sequence ==== */ |
| 1220 | _DisableRFAFEAndResetBB(hw); |
| 1221 | /* ==== Reset digital sequence ====== */ |
| 1222 | _ResetDigitalProcedure1(hw, false); |
| 1223 | /* ==== Pull GPIO PIN to balance level and LED control ====== */ |
| 1224 | _DisableGPIO(hw); |
| 1225 | /* ==== Disable analog sequence === */ |
| 1226 | _DisableAnalog(hw, false); |
| 1227 | } |
| 1228 | |
| 1229 | static void _CardDisableWithoutHWSM(struct ieee80211_hw *hw) |
| 1230 | { |
| 1231 | /*==== RF Off Sequence ==== */ |
| 1232 | _DisableRFAFEAndResetBB(hw); |
| 1233 | /* ==== Reset digital sequence ====== */ |
| 1234 | _ResetDigitalProcedure1(hw, true); |
| 1235 | /* ==== Pull GPIO PIN to balance level and LED control ====== */ |
| 1236 | _DisableGPIO(hw); |
| 1237 | /* ==== Reset digital sequence ====== */ |
| 1238 | _ResetDigitalProcedure2(hw); |
| 1239 | /* ==== Disable analog sequence === */ |
| 1240 | _DisableAnalog(hw, true); |
| 1241 | } |
| 1242 | |
| 1243 | static void _rtl92cu_set_bcn_ctrl_reg(struct ieee80211_hw *hw, |
| 1244 | u8 set_bits, u8 clear_bits) |
| 1245 | { |
| 1246 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1247 | struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); |
| 1248 | |
| 1249 | rtlusb->reg_bcn_ctrl_val |= set_bits; |
| 1250 | rtlusb->reg_bcn_ctrl_val &= ~clear_bits; |
Larry Finger | 9f087a9 | 2014-09-26 16:40:26 -0500 | [diff] [blame] | 1251 | rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlusb->reg_bcn_ctrl_val); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | static void _rtl92cu_stop_tx_beacon(struct ieee80211_hw *hw) |
| 1255 | { |
| 1256 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1257 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 1258 | u8 tmp1byte = 0; |
| 1259 | if (IS_NORMAL_CHIP(rtlhal->version)) { |
| 1260 | tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); |
| 1261 | rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, |
| 1262 | tmp1byte & (~BIT(6))); |
| 1263 | rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64); |
| 1264 | tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); |
| 1265 | tmp1byte &= ~(BIT(0)); |
| 1266 | rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); |
| 1267 | } else { |
| 1268 | rtl_write_byte(rtlpriv, REG_TXPAUSE, |
| 1269 | rtl_read_byte(rtlpriv, REG_TXPAUSE) | BIT(6)); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static void _rtl92cu_resume_tx_beacon(struct ieee80211_hw *hw) |
| 1274 | { |
| 1275 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1276 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 1277 | u8 tmp1byte = 0; |
| 1278 | |
| 1279 | if (IS_NORMAL_CHIP(rtlhal->version)) { |
| 1280 | tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); |
| 1281 | rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, |
| 1282 | tmp1byte | BIT(6)); |
| 1283 | rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); |
| 1284 | tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); |
| 1285 | tmp1byte |= BIT(0); |
| 1286 | rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); |
| 1287 | } else { |
| 1288 | rtl_write_byte(rtlpriv, REG_TXPAUSE, |
| 1289 | rtl_read_byte(rtlpriv, REG_TXPAUSE) & (~BIT(6))); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | static void _rtl92cu_enable_bcn_sub_func(struct ieee80211_hw *hw) |
| 1294 | { |
| 1295 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1296 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 1297 | |
| 1298 | if (IS_NORMAL_CHIP(rtlhal->version)) |
| 1299 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(1)); |
| 1300 | else |
| 1301 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(4)); |
| 1302 | } |
| 1303 | |
| 1304 | static void _rtl92cu_disable_bcn_sub_func(struct ieee80211_hw *hw) |
| 1305 | { |
| 1306 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1307 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 1308 | |
| 1309 | if (IS_NORMAL_CHIP(rtlhal->version)) |
| 1310 | _rtl92cu_set_bcn_ctrl_reg(hw, BIT(1), 0); |
| 1311 | else |
| 1312 | _rtl92cu_set_bcn_ctrl_reg(hw, BIT(4), 0); |
| 1313 | } |
| 1314 | |
| 1315 | static int _rtl92cu_set_media_status(struct ieee80211_hw *hw, |
| 1316 | enum nl80211_iftype type) |
| 1317 | { |
| 1318 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1319 | u8 bt_msr = rtl_read_byte(rtlpriv, MSR); |
| 1320 | enum led_ctl_mode ledaction = LED_CTL_NO_LINK; |
| 1321 | |
| 1322 | bt_msr &= 0xfc; |
| 1323 | rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xFF); |
| 1324 | if (type == NL80211_IFTYPE_UNSPECIFIED || type == |
| 1325 | NL80211_IFTYPE_STATION) { |
| 1326 | _rtl92cu_stop_tx_beacon(hw); |
| 1327 | _rtl92cu_enable_bcn_sub_func(hw); |
| 1328 | } else if (type == NL80211_IFTYPE_ADHOC || type == NL80211_IFTYPE_AP) { |
| 1329 | _rtl92cu_resume_tx_beacon(hw); |
| 1330 | _rtl92cu_disable_bcn_sub_func(hw); |
| 1331 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1332 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1333 | "Set HW_VAR_MEDIA_STATUS:No such media status(%x)\n", |
| 1334 | type); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1335 | } |
| 1336 | switch (type) { |
| 1337 | case NL80211_IFTYPE_UNSPECIFIED: |
| 1338 | bt_msr |= MSR_NOLINK; |
| 1339 | ledaction = LED_CTL_LINK; |
| 1340 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1341 | "Set Network type to NO LINK!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1342 | break; |
| 1343 | case NL80211_IFTYPE_ADHOC: |
| 1344 | bt_msr |= MSR_ADHOC; |
| 1345 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1346 | "Set Network type to Ad Hoc!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1347 | break; |
| 1348 | case NL80211_IFTYPE_STATION: |
| 1349 | bt_msr |= MSR_INFRA; |
| 1350 | ledaction = LED_CTL_LINK; |
| 1351 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1352 | "Set Network type to STA!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1353 | break; |
| 1354 | case NL80211_IFTYPE_AP: |
| 1355 | bt_msr |= MSR_AP; |
| 1356 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1357 | "Set Network type to AP!\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1358 | break; |
| 1359 | default: |
| 1360 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1361 | "Network type %d not supported!\n", type); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1362 | goto error_out; |
| 1363 | } |
| 1364 | rtl_write_byte(rtlpriv, (MSR), bt_msr); |
| 1365 | rtlpriv->cfg->ops->led_control(hw, ledaction); |
Rickard Strandqvist | 965ec74 | 2014-06-23 23:53:55 +0200 | [diff] [blame] | 1366 | if ((bt_msr & MSR_MASK) == MSR_AP) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1367 | rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00); |
| 1368 | else |
| 1369 | rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66); |
| 1370 | return 0; |
| 1371 | error_out: |
| 1372 | return 1; |
| 1373 | } |
| 1374 | |
| 1375 | void rtl92cu_card_disable(struct ieee80211_hw *hw) |
| 1376 | { |
| 1377 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1378 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1379 | struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); |
| 1380 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1381 | enum nl80211_iftype opmode; |
| 1382 | |
| 1383 | mac->link_state = MAC80211_NOLINK; |
| 1384 | opmode = NL80211_IFTYPE_UNSPECIFIED; |
| 1385 | _rtl92cu_set_media_status(hw, opmode); |
| 1386 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF); |
| 1387 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); |
| 1388 | if (rtlusb->disableHWSM) |
| 1389 | _CardDisableHWSM(hw); |
| 1390 | else |
| 1391 | _CardDisableWithoutHWSM(hw); |
| 1392 | } |
| 1393 | |
| 1394 | void rtl92cu_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid) |
| 1395 | { |
Larry Finger | 9437a24 | 2013-03-13 10:28:13 -0500 | [diff] [blame] | 1396 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1397 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Peter Wu | e51048c | 2014-02-14 19:03:44 +0100 | [diff] [blame] | 1398 | u32 reg_rcr; |
Larry Finger | 9437a24 | 2013-03-13 10:28:13 -0500 | [diff] [blame] | 1399 | |
| 1400 | if (rtlpriv->psc.rfpwr_state != ERFON) |
| 1401 | return; |
| 1402 | |
Peter Wu | e51048c | 2014-02-14 19:03:44 +0100 | [diff] [blame] | 1403 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(®_rcr)); |
| 1404 | |
Larry Finger | 9437a24 | 2013-03-13 10:28:13 -0500 | [diff] [blame] | 1405 | if (check_bssid) { |
| 1406 | u8 tmp; |
| 1407 | if (IS_NORMAL_CHIP(rtlhal->version)) { |
| 1408 | reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN); |
| 1409 | tmp = BIT(4); |
| 1410 | } else { |
| 1411 | reg_rcr |= RCR_CBSSID; |
| 1412 | tmp = BIT(4) | BIT(5); |
| 1413 | } |
| 1414 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, |
| 1415 | (u8 *) (®_rcr)); |
| 1416 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, tmp); |
| 1417 | } else { |
| 1418 | u8 tmp; |
| 1419 | if (IS_NORMAL_CHIP(rtlhal->version)) { |
| 1420 | reg_rcr &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN); |
| 1421 | tmp = BIT(4); |
| 1422 | } else { |
| 1423 | reg_rcr &= ~RCR_CBSSID; |
| 1424 | tmp = BIT(4) | BIT(5); |
| 1425 | } |
| 1426 | reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN)); |
| 1427 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1428 | HW_VAR_RCR, (u8 *) (®_rcr)); |
| 1429 | _rtl92cu_set_bcn_ctrl_reg(hw, tmp, 0); |
| 1430 | } |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /*========================================================================== */ |
| 1434 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1435 | int rtl92cu_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type) |
| 1436 | { |
Larry Finger | 9437a24 | 2013-03-13 10:28:13 -0500 | [diff] [blame] | 1437 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1438 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1439 | if (_rtl92cu_set_media_status(hw, type)) |
| 1440 | return -EOPNOTSUPP; |
Larry Finger | 9437a24 | 2013-03-13 10:28:13 -0500 | [diff] [blame] | 1441 | |
| 1442 | if (rtlpriv->mac80211.link_state == MAC80211_LINKED) { |
| 1443 | if (type != NL80211_IFTYPE_AP) |
| 1444 | rtl92cu_set_check_bssid(hw, true); |
| 1445 | } else { |
| 1446 | rtl92cu_set_check_bssid(hw, false); |
| 1447 | } |
| 1448 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | static void _InitBeaconParameters(struct ieee80211_hw *hw) |
| 1453 | { |
| 1454 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1455 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 1456 | |
| 1457 | rtl_write_word(rtlpriv, REG_BCN_CTRL, 0x1010); |
| 1458 | |
| 1459 | /* TODO: Remove these magic number */ |
| 1460 | rtl_write_word(rtlpriv, REG_TBTT_PROHIBIT, 0x6404); |
| 1461 | rtl_write_byte(rtlpriv, REG_DRVERLYINT, DRIVER_EARLY_INT_TIME); |
| 1462 | rtl_write_byte(rtlpriv, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME); |
| 1463 | /* Change beacon AIFS to the largest number |
| 1464 | * beacause test chip does not contension before sending beacon. */ |
| 1465 | if (IS_NORMAL_CHIP(rtlhal->version)) |
| 1466 | rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660F); |
| 1467 | else |
| 1468 | rtl_write_word(rtlpriv, REG_BCNTCFG, 0x66FF); |
| 1469 | } |
| 1470 | |
| 1471 | static void _beacon_function_enable(struct ieee80211_hw *hw, bool Enable, |
| 1472 | bool Linked) |
| 1473 | { |
| 1474 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1475 | |
| 1476 | _rtl92cu_set_bcn_ctrl_reg(hw, (BIT(4) | BIT(3) | BIT(1)), 0x00); |
| 1477 | rtl_write_byte(rtlpriv, REG_RD_CTRL+1, 0x6F); |
| 1478 | } |
| 1479 | |
| 1480 | void rtl92cu_set_beacon_related_registers(struct ieee80211_hw *hw) |
| 1481 | { |
| 1482 | |
| 1483 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1484 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1485 | u16 bcn_interval, atim_window; |
| 1486 | u32 value32; |
| 1487 | |
| 1488 | bcn_interval = mac->beacon_interval; |
| 1489 | atim_window = 2; /*FIX MERGE */ |
| 1490 | rtl_write_word(rtlpriv, REG_ATIMWND, atim_window); |
| 1491 | rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); |
| 1492 | _InitBeaconParameters(hw); |
| 1493 | rtl_write_byte(rtlpriv, REG_SLOT, 0x09); |
| 1494 | /* |
| 1495 | * Force beacon frame transmission even after receiving beacon frame |
| 1496 | * from other ad hoc STA |
| 1497 | * |
| 1498 | * |
| 1499 | * Reset TSF Timer to zero, added by Roger. 2008.06.24 |
| 1500 | */ |
| 1501 | value32 = rtl_read_dword(rtlpriv, REG_TCR); |
| 1502 | value32 &= ~TSFRST; |
| 1503 | rtl_write_dword(rtlpriv, REG_TCR, value32); |
| 1504 | value32 |= TSFRST; |
| 1505 | rtl_write_dword(rtlpriv, REG_TCR, value32); |
| 1506 | RT_TRACE(rtlpriv, COMP_INIT|COMP_BEACON, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1507 | "SetBeaconRelatedRegisters8192CUsb(): Set TCR(%x)\n", |
| 1508 | value32); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1509 | /* TODO: Modify later (Find the right parameters) |
| 1510 | * NOTE: Fix test chip's bug (about contention windows's randomness) */ |
| 1511 | if ((mac->opmode == NL80211_IFTYPE_ADHOC) || |
| 1512 | (mac->opmode == NL80211_IFTYPE_AP)) { |
| 1513 | rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x50); |
| 1514 | rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x50); |
| 1515 | } |
| 1516 | _beacon_function_enable(hw, true, true); |
| 1517 | } |
| 1518 | |
| 1519 | void rtl92cu_set_beacon_interval(struct ieee80211_hw *hw) |
| 1520 | { |
| 1521 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1522 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1523 | u16 bcn_interval = mac->beacon_interval; |
| 1524 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1525 | RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG, "beacon_interval:%d\n", |
| 1526 | bcn_interval); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1527 | rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); |
| 1528 | } |
| 1529 | |
| 1530 | void rtl92cu_update_interrupt_mask(struct ieee80211_hw *hw, |
| 1531 | u32 add_msr, u32 rm_msr) |
| 1532 | { |
| 1533 | } |
| 1534 | |
| 1535 | void rtl92cu_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) |
| 1536 | { |
| 1537 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1538 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1539 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1540 | |
| 1541 | switch (variable) { |
| 1542 | case HW_VAR_RCR: |
| 1543 | *((u32 *)(val)) = mac->rx_conf; |
| 1544 | break; |
| 1545 | case HW_VAR_RF_STATE: |
| 1546 | *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state; |
| 1547 | break; |
| 1548 | case HW_VAR_FWLPS_RF_ON:{ |
| 1549 | enum rf_pwrstate rfState; |
| 1550 | u32 val_rcr; |
| 1551 | |
| 1552 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, |
| 1553 | (u8 *)(&rfState)); |
| 1554 | if (rfState == ERFOFF) { |
| 1555 | *((bool *) (val)) = true; |
| 1556 | } else { |
| 1557 | val_rcr = rtl_read_dword(rtlpriv, REG_RCR); |
| 1558 | val_rcr &= 0x00070000; |
| 1559 | if (val_rcr) |
| 1560 | *((bool *) (val)) = false; |
| 1561 | else |
| 1562 | *((bool *) (val)) = true; |
| 1563 | } |
| 1564 | break; |
| 1565 | } |
| 1566 | case HW_VAR_FW_PSMODE_STATUS: |
| 1567 | *((bool *) (val)) = ppsc->fw_current_inpsmode; |
| 1568 | break; |
| 1569 | case HW_VAR_CORRECT_TSF:{ |
| 1570 | u64 tsf; |
| 1571 | u32 *ptsf_low = (u32 *)&tsf; |
| 1572 | u32 *ptsf_high = ((u32 *)&tsf) + 1; |
| 1573 | |
| 1574 | *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4)); |
| 1575 | *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR); |
| 1576 | *((u64 *)(val)) = tsf; |
| 1577 | break; |
| 1578 | } |
| 1579 | case HW_VAR_MGT_FILTER: |
| 1580 | *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP0); |
| 1581 | break; |
| 1582 | case HW_VAR_CTRL_FILTER: |
| 1583 | *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP1); |
| 1584 | break; |
| 1585 | case HW_VAR_DATA_FILTER: |
| 1586 | *((u16 *) (val)) = rtl_read_word(rtlpriv, REG_RXFLTMAP2); |
| 1587 | break; |
| 1588 | default: |
| 1589 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1590 | "switch case not processed\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | |
Karsten Wiese | 4f2b244 | 2014-10-22 15:47:34 +0200 | [diff] [blame^] | 1595 | bool usb_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1596 | { |
| 1597 | /* Currently nothing happens here. |
| 1598 | * Traffic stops after some seconds in WPA2 802.11n mode. |
| 1599 | * Maybe because rtl8192cu chip should be set from here? |
| 1600 | * If I understand correctly, the realtek vendor driver sends some urbs |
| 1601 | * if its "here". |
| 1602 | * |
| 1603 | * This is maybe necessary: |
| 1604 | * rtlpriv->cfg->ops->fill_tx_cmddesc(hw, buffer, 1, 1, skb); |
| 1605 | */ |
| 1606 | return true; |
| 1607 | } |
| 1608 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1609 | void rtl92cu_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) |
| 1610 | { |
| 1611 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1612 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1613 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1614 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 1615 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1616 | struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw)); |
| 1617 | enum wireless_mode wirelessmode = mac->mode; |
| 1618 | u8 idx = 0; |
| 1619 | |
| 1620 | switch (variable) { |
| 1621 | case HW_VAR_ETHER_ADDR:{ |
| 1622 | for (idx = 0; idx < ETH_ALEN; idx++) { |
| 1623 | rtl_write_byte(rtlpriv, (REG_MACID + idx), |
| 1624 | val[idx]); |
| 1625 | } |
| 1626 | break; |
| 1627 | } |
| 1628 | case HW_VAR_BASIC_RATE:{ |
| 1629 | u16 rate_cfg = ((u16 *) val)[0]; |
| 1630 | u8 rate_index = 0; |
| 1631 | |
| 1632 | rate_cfg &= 0x15f; |
| 1633 | /* TODO */ |
| 1634 | /* if (mac->current_network.vender == HT_IOT_PEER_CISCO |
| 1635 | * && ((rate_cfg & 0x150) == 0)) { |
| 1636 | * rate_cfg |= 0x010; |
| 1637 | * } */ |
| 1638 | rate_cfg |= 0x01; |
| 1639 | rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff); |
| 1640 | rtl_write_byte(rtlpriv, REG_RRSR + 1, |
| 1641 | (rate_cfg >> 8) & 0xff); |
| 1642 | while (rate_cfg > 0x1) { |
| 1643 | rate_cfg >>= 1; |
| 1644 | rate_index++; |
| 1645 | } |
| 1646 | rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, |
| 1647 | rate_index); |
| 1648 | break; |
| 1649 | } |
| 1650 | case HW_VAR_BSSID:{ |
| 1651 | for (idx = 0; idx < ETH_ALEN; idx++) { |
| 1652 | rtl_write_byte(rtlpriv, (REG_BSSID + idx), |
| 1653 | val[idx]); |
| 1654 | } |
| 1655 | break; |
| 1656 | } |
| 1657 | case HW_VAR_SIFS:{ |
| 1658 | rtl_write_byte(rtlpriv, REG_SIFS_CCK + 1, val[0]); |
| 1659 | rtl_write_byte(rtlpriv, REG_SIFS_OFDM + 1, val[1]); |
| 1660 | rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]); |
| 1661 | rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]); |
| 1662 | rtl_write_byte(rtlpriv, REG_R2T_SIFS+1, val[0]); |
| 1663 | rtl_write_byte(rtlpriv, REG_T2T_SIFS+1, val[0]); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1664 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, "HW_VAR_SIFS\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1665 | break; |
| 1666 | } |
| 1667 | case HW_VAR_SLOT_TIME:{ |
| 1668 | u8 e_aci; |
| 1669 | u8 QOS_MODE = 1; |
| 1670 | |
| 1671 | rtl_write_byte(rtlpriv, REG_SLOT, val[0]); |
| 1672 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1673 | "HW_VAR_SLOT_TIME %x\n", val[0]); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1674 | if (QOS_MODE) { |
| 1675 | for (e_aci = 0; e_aci < AC_MAX; e_aci++) |
| 1676 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1677 | HW_VAR_AC_PARAM, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1678 | &e_aci); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1679 | } else { |
| 1680 | u8 sifstime = 0; |
| 1681 | u8 u1bAIFS; |
| 1682 | |
| 1683 | if (IS_WIRELESS_MODE_A(wirelessmode) || |
| 1684 | IS_WIRELESS_MODE_N_24G(wirelessmode) || |
| 1685 | IS_WIRELESS_MODE_N_5G(wirelessmode)) |
| 1686 | sifstime = 16; |
| 1687 | else |
| 1688 | sifstime = 10; |
| 1689 | u1bAIFS = sifstime + (2 * val[0]); |
| 1690 | rtl_write_byte(rtlpriv, REG_EDCA_VO_PARAM, |
| 1691 | u1bAIFS); |
| 1692 | rtl_write_byte(rtlpriv, REG_EDCA_VI_PARAM, |
| 1693 | u1bAIFS); |
| 1694 | rtl_write_byte(rtlpriv, REG_EDCA_BE_PARAM, |
| 1695 | u1bAIFS); |
| 1696 | rtl_write_byte(rtlpriv, REG_EDCA_BK_PARAM, |
| 1697 | u1bAIFS); |
| 1698 | } |
| 1699 | break; |
| 1700 | } |
| 1701 | case HW_VAR_ACK_PREAMBLE:{ |
| 1702 | u8 reg_tmp; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1703 | u8 short_preamble = (bool)*val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1704 | reg_tmp = 0; |
| 1705 | if (short_preamble) |
| 1706 | reg_tmp |= 0x80; |
| 1707 | rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp); |
| 1708 | break; |
| 1709 | } |
| 1710 | case HW_VAR_AMPDU_MIN_SPACE:{ |
| 1711 | u8 min_spacing_to_set; |
| 1712 | u8 sec_min_space; |
| 1713 | |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1714 | min_spacing_to_set = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1715 | if (min_spacing_to_set <= 7) { |
| 1716 | switch (rtlpriv->sec.pairwise_enc_algorithm) { |
| 1717 | case NO_ENCRYPTION: |
| 1718 | case AESCCMP_ENCRYPTION: |
| 1719 | sec_min_space = 0; |
| 1720 | break; |
| 1721 | case WEP40_ENCRYPTION: |
| 1722 | case WEP104_ENCRYPTION: |
| 1723 | case TKIP_ENCRYPTION: |
| 1724 | sec_min_space = 6; |
| 1725 | break; |
| 1726 | default: |
| 1727 | sec_min_space = 7; |
| 1728 | break; |
| 1729 | } |
| 1730 | if (min_spacing_to_set < sec_min_space) |
| 1731 | min_spacing_to_set = sec_min_space; |
| 1732 | mac->min_space_cfg = ((mac->min_space_cfg & |
| 1733 | 0xf8) | |
| 1734 | min_spacing_to_set); |
| 1735 | *val = min_spacing_to_set; |
| 1736 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1737 | "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n", |
| 1738 | mac->min_space_cfg); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1739 | rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, |
| 1740 | mac->min_space_cfg); |
| 1741 | } |
| 1742 | break; |
| 1743 | } |
| 1744 | case HW_VAR_SHORTGI_DENSITY:{ |
| 1745 | u8 density_to_set; |
| 1746 | |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1747 | density_to_set = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1748 | density_to_set &= 0x1f; |
| 1749 | mac->min_space_cfg &= 0x07; |
| 1750 | mac->min_space_cfg |= (density_to_set << 3); |
| 1751 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1752 | "Set HW_VAR_SHORTGI_DENSITY: %#x\n", |
| 1753 | mac->min_space_cfg); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1754 | rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, |
| 1755 | mac->min_space_cfg); |
| 1756 | break; |
| 1757 | } |
| 1758 | case HW_VAR_AMPDU_FACTOR:{ |
| 1759 | u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9}; |
| 1760 | u8 factor_toset; |
| 1761 | u8 *p_regtoset = NULL; |
| 1762 | u8 index = 0; |
| 1763 | |
| 1764 | p_regtoset = regtoset_normal; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1765 | factor_toset = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1766 | if (factor_toset <= 3) { |
| 1767 | factor_toset = (1 << (factor_toset + 2)); |
| 1768 | if (factor_toset > 0xf) |
| 1769 | factor_toset = 0xf; |
| 1770 | for (index = 0; index < 4; index++) { |
| 1771 | if ((p_regtoset[index] & 0xf0) > |
| 1772 | (factor_toset << 4)) |
| 1773 | p_regtoset[index] = |
| 1774 | (p_regtoset[index] & 0x0f) |
| 1775 | | (factor_toset << 4); |
| 1776 | if ((p_regtoset[index] & 0x0f) > |
| 1777 | factor_toset) |
| 1778 | p_regtoset[index] = |
| 1779 | (p_regtoset[index] & 0xf0) |
| 1780 | | (factor_toset); |
| 1781 | rtl_write_byte(rtlpriv, |
| 1782 | (REG_AGGLEN_LMT + index), |
| 1783 | p_regtoset[index]); |
| 1784 | } |
| 1785 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1786 | "Set HW_VAR_AMPDU_FACTOR: %#x\n", |
| 1787 | factor_toset); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1788 | } |
| 1789 | break; |
| 1790 | } |
| 1791 | case HW_VAR_AC_PARAM:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1792 | u8 e_aci = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1793 | u32 u4b_ac_param; |
| 1794 | u16 cw_min = le16_to_cpu(mac->ac[e_aci].cw_min); |
| 1795 | u16 cw_max = le16_to_cpu(mac->ac[e_aci].cw_max); |
| 1796 | u16 tx_op = le16_to_cpu(mac->ac[e_aci].tx_op); |
| 1797 | |
| 1798 | u4b_ac_param = (u32) mac->ac[e_aci].aifs; |
| 1799 | u4b_ac_param |= (u32) ((cw_min & 0xF) << |
| 1800 | AC_PARAM_ECW_MIN_OFFSET); |
| 1801 | u4b_ac_param |= (u32) ((cw_max & 0xF) << |
| 1802 | AC_PARAM_ECW_MAX_OFFSET); |
| 1803 | u4b_ac_param |= (u32) tx_op << AC_PARAM_TXOP_OFFSET; |
| 1804 | RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1805 | "queue:%x, ac_param:%x\n", |
| 1806 | e_aci, u4b_ac_param); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1807 | switch (e_aci) { |
| 1808 | case AC1_BK: |
| 1809 | rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, |
| 1810 | u4b_ac_param); |
| 1811 | break; |
| 1812 | case AC0_BE: |
| 1813 | rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, |
| 1814 | u4b_ac_param); |
| 1815 | break; |
| 1816 | case AC2_VI: |
| 1817 | rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, |
| 1818 | u4b_ac_param); |
| 1819 | break; |
| 1820 | case AC3_VO: |
| 1821 | rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, |
| 1822 | u4b_ac_param); |
| 1823 | break; |
| 1824 | default: |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 1825 | RT_ASSERT(false, |
| 1826 | "SetHwReg8185(): invalid aci: %d !\n", |
| 1827 | e_aci); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1828 | break; |
| 1829 | } |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 1830 | if (rtlusb->acm_method != EACMWAY2_SW) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1831 | rtlpriv->cfg->ops->set_hw_reg(hw, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1832 | HW_VAR_ACM_CTRL, &e_aci); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1833 | break; |
| 1834 | } |
| 1835 | case HW_VAR_ACM_CTRL:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1836 | u8 e_aci = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1837 | union aci_aifsn *p_aci_aifsn = (union aci_aifsn *) |
| 1838 | (&(mac->ac[0].aifs)); |
| 1839 | u8 acm = p_aci_aifsn->f.acm; |
| 1840 | u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL); |
| 1841 | |
| 1842 | acm_ctrl = |
| 1843 | acm_ctrl | ((rtlusb->acm_method == 2) ? 0x0 : 0x1); |
| 1844 | if (acm) { |
| 1845 | switch (e_aci) { |
| 1846 | case AC0_BE: |
| 1847 | acm_ctrl |= AcmHw_BeqEn; |
| 1848 | break; |
| 1849 | case AC2_VI: |
| 1850 | acm_ctrl |= AcmHw_ViqEn; |
| 1851 | break; |
| 1852 | case AC3_VO: |
| 1853 | acm_ctrl |= AcmHw_VoqEn; |
| 1854 | break; |
| 1855 | default: |
| 1856 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1857 | "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n", |
| 1858 | acm); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1859 | break; |
| 1860 | } |
| 1861 | } else { |
| 1862 | switch (e_aci) { |
| 1863 | case AC0_BE: |
| 1864 | acm_ctrl &= (~AcmHw_BeqEn); |
| 1865 | break; |
| 1866 | case AC2_VI: |
| 1867 | acm_ctrl &= (~AcmHw_ViqEn); |
| 1868 | break; |
| 1869 | case AC3_VO: |
| 1870 | acm_ctrl &= (~AcmHw_BeqEn); |
| 1871 | break; |
| 1872 | default: |
| 1873 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1874 | "switch case not processed\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1875 | break; |
| 1876 | } |
| 1877 | } |
| 1878 | RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1879 | "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", |
| 1880 | acm_ctrl); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1881 | rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl); |
| 1882 | break; |
| 1883 | } |
| 1884 | case HW_VAR_RCR:{ |
| 1885 | rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]); |
| 1886 | mac->rx_conf = ((u32 *) (val))[0]; |
| 1887 | RT_TRACE(rtlpriv, COMP_RECV, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1888 | "### Set RCR(0x%08x) ###\n", mac->rx_conf); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1889 | break; |
| 1890 | } |
| 1891 | case HW_VAR_RETRY_LIMIT:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1892 | u8 retry_limit = val[0]; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1893 | |
| 1894 | rtl_write_word(rtlpriv, REG_RL, |
| 1895 | retry_limit << RETRY_LIMIT_SHORT_SHIFT | |
| 1896 | retry_limit << RETRY_LIMIT_LONG_SHIFT); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1897 | RT_TRACE(rtlpriv, COMP_MLME, DBG_DMESG, |
| 1898 | "Set HW_VAR_RETRY_LIMIT(0x%08x)\n", |
| 1899 | retry_limit); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1900 | break; |
| 1901 | } |
| 1902 | case HW_VAR_DUAL_TSF_RST: |
| 1903 | rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1))); |
| 1904 | break; |
| 1905 | case HW_VAR_EFUSE_BYTES: |
| 1906 | rtlefuse->efuse_usedbytes = *((u16 *) val); |
| 1907 | break; |
| 1908 | case HW_VAR_EFUSE_USAGE: |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1909 | rtlefuse->efuse_usedpercentage = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1910 | break; |
| 1911 | case HW_VAR_IO_CMD: |
| 1912 | rtl92c_phy_set_io_cmd(hw, (*(enum io_type *)val)); |
| 1913 | break; |
| 1914 | case HW_VAR_WPA_CONFIG: |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1915 | rtl_write_byte(rtlpriv, REG_SECCFG, *val); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1916 | break; |
| 1917 | case HW_VAR_SET_RPWM:{ |
| 1918 | u8 rpwm_val = rtl_read_byte(rtlpriv, REG_USB_HRPWM); |
| 1919 | |
| 1920 | if (rpwm_val & BIT(7)) |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1921 | rtl_write_byte(rtlpriv, REG_USB_HRPWM, *val); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1922 | else |
| 1923 | rtl_write_byte(rtlpriv, REG_USB_HRPWM, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1924 | *val | BIT(7)); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1925 | break; |
| 1926 | } |
| 1927 | case HW_VAR_H2C_FW_PWRMODE:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1928 | u8 psmode = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1929 | |
| 1930 | if ((psmode != FW_PS_ACTIVE_MODE) && |
| 1931 | (!IS_92C_SERIAL(rtlhal->version))) |
| 1932 | rtl92c_dm_rf_saving(hw, true); |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1933 | rtl92c_set_fw_pwrmode_cmd(hw, (*val)); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1934 | break; |
| 1935 | } |
| 1936 | case HW_VAR_FW_PSMODE_STATUS: |
| 1937 | ppsc->fw_current_inpsmode = *((bool *) val); |
| 1938 | break; |
| 1939 | case HW_VAR_H2C_FW_JOINBSSRPT:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1940 | u8 mstatus = *val; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1941 | u8 tmp_reg422; |
| 1942 | bool recover = false; |
| 1943 | |
| 1944 | if (mstatus == RT_MEDIA_CONNECT) { |
| 1945 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1946 | HW_VAR_AID, NULL); |
| 1947 | rtl_write_byte(rtlpriv, REG_CR + 1, 0x03); |
| 1948 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(3)); |
| 1949 | _rtl92cu_set_bcn_ctrl_reg(hw, BIT(4), 0); |
| 1950 | tmp_reg422 = rtl_read_byte(rtlpriv, |
| 1951 | REG_FWHW_TXQ_CTRL + 2); |
| 1952 | if (tmp_reg422 & BIT(6)) |
| 1953 | recover = true; |
| 1954 | rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, |
| 1955 | tmp_reg422 & (~BIT(6))); |
Karsten Wiese | 4f2b244 | 2014-10-22 15:47:34 +0200 | [diff] [blame^] | 1956 | rtl92c_set_fw_rsvdpagepkt(hw, |
| 1957 | &usb_cmd_send_packet); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1958 | _rtl92cu_set_bcn_ctrl_reg(hw, BIT(3), 0); |
| 1959 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(4)); |
| 1960 | if (recover) |
| 1961 | rtl_write_byte(rtlpriv, |
| 1962 | REG_FWHW_TXQ_CTRL + 2, |
| 1963 | tmp_reg422 | BIT(6)); |
| 1964 | rtl_write_byte(rtlpriv, REG_CR + 1, 0x02); |
| 1965 | } |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1966 | rtl92c_set_fw_joinbss_report_cmd(hw, (*val)); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1967 | break; |
| 1968 | } |
| 1969 | case HW_VAR_AID:{ |
| 1970 | u16 u2btmp; |
| 1971 | |
| 1972 | u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT); |
| 1973 | u2btmp &= 0xC000; |
| 1974 | rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, |
| 1975 | (u2btmp | mac->assoc_id)); |
| 1976 | break; |
| 1977 | } |
| 1978 | case HW_VAR_CORRECT_TSF:{ |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1979 | u8 btype_ibss = val[0]; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1980 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 1981 | if (btype_ibss) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1982 | _rtl92cu_stop_tx_beacon(hw); |
| 1983 | _rtl92cu_set_bcn_ctrl_reg(hw, 0, BIT(3)); |
| 1984 | rtl_write_dword(rtlpriv, REG_TSFTR, (u32)(mac->tsf & |
| 1985 | 0xffffffff)); |
| 1986 | rtl_write_dword(rtlpriv, REG_TSFTR + 4, |
| 1987 | (u32)((mac->tsf >> 32) & 0xffffffff)); |
| 1988 | _rtl92cu_set_bcn_ctrl_reg(hw, BIT(3), 0); |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 1989 | if (btype_ibss) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 1990 | _rtl92cu_resume_tx_beacon(hw); |
| 1991 | break; |
| 1992 | } |
| 1993 | case HW_VAR_MGT_FILTER: |
| 1994 | rtl_write_word(rtlpriv, REG_RXFLTMAP0, *(u16 *)val); |
| 1995 | break; |
| 1996 | case HW_VAR_CTRL_FILTER: |
| 1997 | rtl_write_word(rtlpriv, REG_RXFLTMAP1, *(u16 *)val); |
| 1998 | break; |
| 1999 | case HW_VAR_DATA_FILTER: |
| 2000 | rtl_write_word(rtlpriv, REG_RXFLTMAP2, *(u16 *)val); |
| 2001 | break; |
| 2002 | default: |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2003 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2004 | "switch case not processed\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2005 | break; |
| 2006 | } |
| 2007 | } |
| 2008 | |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2009 | static void rtl92cu_update_hal_rate_table(struct ieee80211_hw *hw, |
| 2010 | struct ieee80211_sta *sta) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2011 | { |
| 2012 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2013 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 2014 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2015 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2016 | u32 ratr_value; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2017 | u8 ratr_index = 0; |
| 2018 | u8 nmode = mac->ht_enable; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2019 | u8 mimo_ps = IEEE80211_SMPS_OFF; |
| 2020 | u16 shortgi_rate; |
| 2021 | u32 tmp_ratr_value; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2022 | u8 curtxbw_40mhz = mac->bw_40; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2023 | u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? |
| 2024 | 1 : 0; |
| 2025 | u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? |
| 2026 | 1 : 0; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2027 | enum wireless_mode wirelessmode = mac->mode; |
| 2028 | |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2029 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 2030 | ratr_value = sta->supp_rates[1] << 4; |
| 2031 | else |
| 2032 | ratr_value = sta->supp_rates[0]; |
| 2033 | if (mac->opmode == NL80211_IFTYPE_ADHOC) |
| 2034 | ratr_value = 0xfff; |
| 2035 | |
| 2036 | ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 | |
| 2037 | sta->ht_cap.mcs.rx_mask[0] << 12); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2038 | switch (wirelessmode) { |
| 2039 | case WIRELESS_MODE_B: |
| 2040 | if (ratr_value & 0x0000000c) |
| 2041 | ratr_value &= 0x0000000d; |
| 2042 | else |
| 2043 | ratr_value &= 0x0000000f; |
| 2044 | break; |
| 2045 | case WIRELESS_MODE_G: |
| 2046 | ratr_value &= 0x00000FF5; |
| 2047 | break; |
| 2048 | case WIRELESS_MODE_N_24G: |
| 2049 | case WIRELESS_MODE_N_5G: |
| 2050 | nmode = 1; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2051 | if (mimo_ps == IEEE80211_SMPS_STATIC) { |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2052 | ratr_value &= 0x0007F005; |
| 2053 | } else { |
| 2054 | u32 ratr_mask; |
| 2055 | |
| 2056 | if (get_rf_type(rtlphy) == RF_1T2R || |
| 2057 | get_rf_type(rtlphy) == RF_1T1R) |
| 2058 | ratr_mask = 0x000ff005; |
| 2059 | else |
| 2060 | ratr_mask = 0x0f0ff005; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2061 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2062 | ratr_value &= ratr_mask; |
| 2063 | } |
| 2064 | break; |
| 2065 | default: |
| 2066 | if (rtlphy->rf_type == RF_1T2R) |
| 2067 | ratr_value &= 0x000ff0ff; |
| 2068 | else |
| 2069 | ratr_value &= 0x0f0ff0ff; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2070 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2071 | break; |
| 2072 | } |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2073 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2074 | ratr_value &= 0x0FFFFFFF; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2075 | |
| 2076 | if (nmode && ((curtxbw_40mhz && |
| 2077 | curshortgi_40mhz) || (!curtxbw_40mhz && |
| 2078 | curshortgi_20mhz))) { |
| 2079 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2080 | ratr_value |= 0x10000000; |
| 2081 | tmp_ratr_value = (ratr_value >> 12); |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2082 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2083 | for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) { |
| 2084 | if ((1 << shortgi_rate) & tmp_ratr_value) |
| 2085 | break; |
| 2086 | } |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2087 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2088 | shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) | |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2089 | (shortgi_rate << 4) | (shortgi_rate); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2090 | } |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2091 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2092 | rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value); |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2093 | |
| 2094 | RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n", |
| 2095 | rtl_read_dword(rtlpriv, REG_ARFR0)); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2096 | } |
| 2097 | |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2098 | static void rtl92cu_update_hal_rate_mask(struct ieee80211_hw *hw, |
| 2099 | struct ieee80211_sta *sta, |
| 2100 | u8 rssi_level) |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2101 | { |
| 2102 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2103 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 2104 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2105 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2106 | struct rtl_sta_info *sta_entry = NULL; |
| 2107 | u32 ratr_bitmap; |
| 2108 | u8 ratr_index; |
| 2109 | u8 curtxbw_40mhz = (sta->bandwidth >= IEEE80211_STA_RX_BW_40) ? 1 : 0; |
| 2110 | u8 curshortgi_40mhz = curtxbw_40mhz && |
| 2111 | (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? |
| 2112 | 1 : 0; |
| 2113 | u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? |
| 2114 | 1 : 0; |
| 2115 | enum wireless_mode wirelessmode = 0; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2116 | bool shortgi = false; |
| 2117 | u8 rate_mask[5]; |
| 2118 | u8 macid = 0; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2119 | u8 mimo_ps = IEEE80211_SMPS_OFF; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2120 | |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2121 | sta_entry = (struct rtl_sta_info *) sta->drv_priv; |
| 2122 | wirelessmode = sta_entry->wireless_mode; |
| 2123 | if (mac->opmode == NL80211_IFTYPE_STATION || |
| 2124 | mac->opmode == NL80211_IFTYPE_MESH_POINT) |
| 2125 | curtxbw_40mhz = mac->bw_40; |
| 2126 | else if (mac->opmode == NL80211_IFTYPE_AP || |
| 2127 | mac->opmode == NL80211_IFTYPE_ADHOC) |
| 2128 | macid = sta->aid + 1; |
| 2129 | |
| 2130 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 2131 | ratr_bitmap = sta->supp_rates[1] << 4; |
| 2132 | else |
| 2133 | ratr_bitmap = sta->supp_rates[0]; |
| 2134 | if (mac->opmode == NL80211_IFTYPE_ADHOC) |
| 2135 | ratr_bitmap = 0xfff; |
| 2136 | ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 | |
| 2137 | sta->ht_cap.mcs.rx_mask[0] << 12); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2138 | switch (wirelessmode) { |
| 2139 | case WIRELESS_MODE_B: |
| 2140 | ratr_index = RATR_INX_WIRELESS_B; |
| 2141 | if (ratr_bitmap & 0x0000000c) |
| 2142 | ratr_bitmap &= 0x0000000d; |
| 2143 | else |
| 2144 | ratr_bitmap &= 0x0000000f; |
| 2145 | break; |
| 2146 | case WIRELESS_MODE_G: |
| 2147 | ratr_index = RATR_INX_WIRELESS_GB; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2148 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2149 | if (rssi_level == 1) |
| 2150 | ratr_bitmap &= 0x00000f00; |
| 2151 | else if (rssi_level == 2) |
| 2152 | ratr_bitmap &= 0x00000ff0; |
| 2153 | else |
| 2154 | ratr_bitmap &= 0x00000ff5; |
| 2155 | break; |
| 2156 | case WIRELESS_MODE_A: |
| 2157 | ratr_index = RATR_INX_WIRELESS_A; |
| 2158 | ratr_bitmap &= 0x00000ff0; |
| 2159 | break; |
| 2160 | case WIRELESS_MODE_N_24G: |
| 2161 | case WIRELESS_MODE_N_5G: |
| 2162 | ratr_index = RATR_INX_WIRELESS_NGB; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2163 | |
| 2164 | if (mimo_ps == IEEE80211_SMPS_STATIC) { |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2165 | if (rssi_level == 1) |
| 2166 | ratr_bitmap &= 0x00070000; |
| 2167 | else if (rssi_level == 2) |
| 2168 | ratr_bitmap &= 0x0007f000; |
| 2169 | else |
| 2170 | ratr_bitmap &= 0x0007f005; |
| 2171 | } else { |
| 2172 | if (rtlphy->rf_type == RF_1T2R || |
| 2173 | rtlphy->rf_type == RF_1T1R) { |
| 2174 | if (curtxbw_40mhz) { |
| 2175 | if (rssi_level == 1) |
| 2176 | ratr_bitmap &= 0x000f0000; |
| 2177 | else if (rssi_level == 2) |
| 2178 | ratr_bitmap &= 0x000ff000; |
| 2179 | else |
| 2180 | ratr_bitmap &= 0x000ff015; |
| 2181 | } else { |
| 2182 | if (rssi_level == 1) |
| 2183 | ratr_bitmap &= 0x000f0000; |
| 2184 | else if (rssi_level == 2) |
| 2185 | ratr_bitmap &= 0x000ff000; |
| 2186 | else |
| 2187 | ratr_bitmap &= 0x000ff005; |
| 2188 | } |
| 2189 | } else { |
| 2190 | if (curtxbw_40mhz) { |
| 2191 | if (rssi_level == 1) |
| 2192 | ratr_bitmap &= 0x0f0f0000; |
| 2193 | else if (rssi_level == 2) |
| 2194 | ratr_bitmap &= 0x0f0ff000; |
| 2195 | else |
| 2196 | ratr_bitmap &= 0x0f0ff015; |
| 2197 | } else { |
| 2198 | if (rssi_level == 1) |
| 2199 | ratr_bitmap &= 0x0f0f0000; |
| 2200 | else if (rssi_level == 2) |
| 2201 | ratr_bitmap &= 0x0f0ff000; |
| 2202 | else |
| 2203 | ratr_bitmap &= 0x0f0ff005; |
| 2204 | } |
| 2205 | } |
| 2206 | } |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2207 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2208 | if ((curtxbw_40mhz && curshortgi_40mhz) || |
| 2209 | (!curtxbw_40mhz && curshortgi_20mhz)) { |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2210 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2211 | if (macid == 0) |
| 2212 | shortgi = true; |
| 2213 | else if (macid == 1) |
| 2214 | shortgi = false; |
| 2215 | } |
| 2216 | break; |
| 2217 | default: |
| 2218 | ratr_index = RATR_INX_WIRELESS_NGB; |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2219 | |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2220 | if (rtlphy->rf_type == RF_1T2R) |
| 2221 | ratr_bitmap &= 0x000ff0ff; |
| 2222 | else |
| 2223 | ratr_bitmap &= 0x0f0ff0ff; |
| 2224 | break; |
| 2225 | } |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2226 | sta_entry->ratr_index = ratr_index; |
| 2227 | |
| 2228 | RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, |
| 2229 | "ratr_bitmap :%x\n", ratr_bitmap); |
| 2230 | *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) | |
| 2231 | (ratr_index << 28); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2232 | rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2233 | RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, |
Andy Shevchenko | ed9f0ed | 2012-10-02 17:19:44 +0300 | [diff] [blame] | 2234 | "Rate_index:%x, ratr_val:%x, %5phC\n", |
| 2235 | ratr_index, ratr_bitmap, rate_mask); |
Larry Finger | 5b8df24 | 2013-05-30 18:05:55 -0500 | [diff] [blame] | 2236 | memcpy(rtlpriv->rate_mask, rate_mask, 5); |
| 2237 | /* rtl92c_fill_h2c_cmd() does USB I/O and will result in a |
| 2238 | * "scheduled while atomic" if called directly */ |
| 2239 | schedule_work(&rtlpriv->works.fill_h2c_cmd); |
| 2240 | |
| 2241 | if (macid != 0) |
| 2242 | sta_entry->ratr_index = ratr_index; |
| 2243 | } |
| 2244 | |
| 2245 | void rtl92cu_update_hal_rate_tbl(struct ieee80211_hw *hw, |
| 2246 | struct ieee80211_sta *sta, |
| 2247 | u8 rssi_level) |
| 2248 | { |
| 2249 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2250 | |
| 2251 | if (rtlpriv->dm.useramask) |
| 2252 | rtl92cu_update_hal_rate_mask(hw, sta, rssi_level); |
| 2253 | else |
| 2254 | rtl92cu_update_hal_rate_table(hw, sta); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | void rtl92cu_update_channel_access_setting(struct ieee80211_hw *hw) |
| 2258 | { |
| 2259 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2260 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 2261 | u16 sifs_timer; |
| 2262 | |
| 2263 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 2264 | &mac->slot_time); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2265 | if (!mac->ht_enable) |
| 2266 | sifs_timer = 0x0a0a; |
| 2267 | else |
| 2268 | sifs_timer = 0x0e0e; |
| 2269 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer); |
| 2270 | } |
| 2271 | |
| 2272 | bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 * valid) |
| 2273 | { |
| 2274 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2275 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 2276 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 2277 | enum rf_pwrstate e_rfpowerstate_toset, cur_rfstate; |
| 2278 | u8 u1tmp = 0; |
| 2279 | bool actuallyset = false; |
| 2280 | unsigned long flag = 0; |
| 2281 | /* to do - usb autosuspend */ |
| 2282 | u8 usb_autosuspend = 0; |
| 2283 | |
| 2284 | if (ppsc->swrf_processing) |
| 2285 | return false; |
| 2286 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); |
| 2287 | if (ppsc->rfchange_inprogress) { |
| 2288 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); |
| 2289 | return false; |
| 2290 | } else { |
| 2291 | ppsc->rfchange_inprogress = true; |
| 2292 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); |
| 2293 | } |
| 2294 | cur_rfstate = ppsc->rfpwr_state; |
| 2295 | if (usb_autosuspend) { |
| 2296 | /* to do................... */ |
| 2297 | } else { |
| 2298 | if (ppsc->pwrdown_mode) { |
| 2299 | u1tmp = rtl_read_byte(rtlpriv, REG_HSISR); |
| 2300 | e_rfpowerstate_toset = (u1tmp & BIT(7)) ? |
| 2301 | ERFOFF : ERFON; |
| 2302 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2303 | "pwrdown, 0x5c(BIT7)=%02x\n", u1tmp); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2304 | } else { |
| 2305 | rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, |
| 2306 | rtl_read_byte(rtlpriv, |
| 2307 | REG_MAC_PINMUX_CFG) & ~(BIT(3))); |
| 2308 | u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL); |
| 2309 | e_rfpowerstate_toset = (u1tmp & BIT(3)) ? |
| 2310 | ERFON : ERFOFF; |
| 2311 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2312 | "GPIO_IN=%02x\n", u1tmp); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2313 | } |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2314 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "N-SS RF =%x\n", |
| 2315 | e_rfpowerstate_toset); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2316 | } |
| 2317 | if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2318 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
| 2319 | "GPIOChangeRF - HW Radio ON, RF ON\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2320 | ppsc->hwradiooff = false; |
| 2321 | actuallyset = true; |
| 2322 | } else if ((!ppsc->hwradiooff) && (e_rfpowerstate_toset == |
| 2323 | ERFOFF)) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2324 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
| 2325 | "GPIOChangeRF - HW Radio OFF\n"); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2326 | ppsc->hwradiooff = true; |
| 2327 | actuallyset = true; |
| 2328 | } else { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2329 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
| 2330 | "pHalData->bHwRadioOff and eRfPowerStateToSet do not match: pHalData->bHwRadioOff %x, eRfPowerStateToSet %x\n", |
| 2331 | ppsc->hwradiooff, e_rfpowerstate_toset); |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2332 | } |
| 2333 | if (actuallyset) { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 2334 | ppsc->hwradiooff = true; |
George | dc0313f | 2011-02-19 16:29:22 -0600 | [diff] [blame] | 2335 | if (e_rfpowerstate_toset == ERFON) { |
| 2336 | if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) && |
| 2337 | RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM)) |
| 2338 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM); |
| 2339 | else if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_PCI_D3) |
| 2340 | && RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_PCI_D3)) |
| 2341 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_PCI_D3); |
| 2342 | } |
| 2343 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); |
| 2344 | ppsc->rfchange_inprogress = false; |
| 2345 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); |
| 2346 | /* For power down module, we need to enable register block |
| 2347 | * contrl reg at 0x1c. Then enable power down control bit |
| 2348 | * of register 0x04 BIT4 and BIT15 as 1. |
| 2349 | */ |
| 2350 | if (ppsc->pwrdown_mode && e_rfpowerstate_toset == ERFOFF) { |
| 2351 | /* Enable register area 0x0-0xc. */ |
| 2352 | rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0); |
| 2353 | if (IS_HARDWARE_TYPE_8723U(rtlhal)) { |
| 2354 | /* |
| 2355 | * We should configure HW PDn source for WiFi |
| 2356 | * ONLY, and then our HW will be set in |
| 2357 | * power-down mode if PDn source from all |
| 2358 | * functions are configured. |
| 2359 | */ |
| 2360 | u1tmp = rtl_read_byte(rtlpriv, |
| 2361 | REG_MULTI_FUNC_CTRL); |
| 2362 | rtl_write_byte(rtlpriv, REG_MULTI_FUNC_CTRL, |
| 2363 | (u1tmp|WL_HWPDN_EN)); |
| 2364 | } else { |
| 2365 | rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x8812); |
| 2366 | } |
| 2367 | } |
| 2368 | if (e_rfpowerstate_toset == ERFOFF) { |
| 2369 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) |
| 2370 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM); |
| 2371 | else if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_PCI_D3) |
| 2372 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_PCI_D3); |
| 2373 | } |
| 2374 | } else if (e_rfpowerstate_toset == ERFOFF || cur_rfstate == ERFOFF) { |
| 2375 | /* Enter D3 or ASPM after GPIO had been done. */ |
| 2376 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) |
| 2377 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_ASPM); |
| 2378 | else if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_PCI_D3) |
| 2379 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_PCI_D3); |
| 2380 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); |
| 2381 | ppsc->rfchange_inprogress = false; |
| 2382 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); |
| 2383 | } else { |
| 2384 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag); |
| 2385 | ppsc->rfchange_inprogress = false; |
| 2386 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag); |
| 2387 | } |
| 2388 | *valid = 1; |
| 2389 | return !ppsc->hwradiooff; |
| 2390 | } |