Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | fc61685 | 2012-01-07 20:46:43 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -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 | |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 30 | #include <linux/export.h> |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 31 | #include "dm_common.h" |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 32 | #include "phy_common.h" |
| 33 | #include "../pci.h" |
| 34 | #include "../base.h" |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 35 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 36 | #define BT_RSSI_STATE_NORMAL_POWER BIT_OFFSET_LEN_MASK_32(0, 1) |
| 37 | #define BT_RSSI_STATE_AMDPU_OFF BIT_OFFSET_LEN_MASK_32(1, 1) |
| 38 | #define BT_RSSI_STATE_SPECIAL_LOW BIT_OFFSET_LEN_MASK_32(2, 1) |
| 39 | #define BT_RSSI_STATE_BG_EDCA_LOW BIT_OFFSET_LEN_MASK_32(3, 1) |
| 40 | #define BT_RSSI_STATE_TXPOWER_LOW BIT_OFFSET_LEN_MASK_32(4, 1) |
| 41 | |
| 42 | #define RTLPRIV (struct rtl_priv *) |
| 43 | #define GET_UNDECORATED_AVERAGE_RSSI(_priv) \ |
| 44 | ((RTLPRIV(_priv))->mac80211.opmode == \ |
| 45 | NL80211_IFTYPE_ADHOC) ? \ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 46 | ((RTLPRIV(_priv))->dm.entry_min_undec_sm_pwdb) : \ |
| 47 | ((RTLPRIV(_priv))->dm.undec_sm_pwdb) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 48 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 49 | static const u32 ofdmswing_table[OFDM_TABLE_SIZE] = { |
| 50 | 0x7f8001fe, |
| 51 | 0x788001e2, |
| 52 | 0x71c001c7, |
| 53 | 0x6b8001ae, |
| 54 | 0x65400195, |
| 55 | 0x5fc0017f, |
| 56 | 0x5a400169, |
| 57 | 0x55400155, |
| 58 | 0x50800142, |
| 59 | 0x4c000130, |
| 60 | 0x47c0011f, |
| 61 | 0x43c0010f, |
| 62 | 0x40000100, |
| 63 | 0x3c8000f2, |
| 64 | 0x390000e4, |
| 65 | 0x35c000d7, |
| 66 | 0x32c000cb, |
| 67 | 0x300000c0, |
| 68 | 0x2d4000b5, |
| 69 | 0x2ac000ab, |
| 70 | 0x288000a2, |
| 71 | 0x26000098, |
| 72 | 0x24000090, |
| 73 | 0x22000088, |
| 74 | 0x20000080, |
| 75 | 0x1e400079, |
| 76 | 0x1c800072, |
| 77 | 0x1b00006c, |
| 78 | 0x19800066, |
| 79 | 0x18000060, |
| 80 | 0x16c0005b, |
| 81 | 0x15800056, |
| 82 | 0x14400051, |
| 83 | 0x1300004c, |
| 84 | 0x12000048, |
| 85 | 0x11000044, |
| 86 | 0x10000040, |
| 87 | }; |
| 88 | |
| 89 | static const u8 cckswing_table_ch1ch13[CCK_TABLE_SIZE][8] = { |
| 90 | {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, |
| 91 | {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, |
| 92 | {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, |
| 93 | {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, |
| 94 | {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, |
| 95 | {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, |
| 96 | {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, |
| 97 | {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, |
| 98 | {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, |
| 99 | {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, |
| 100 | {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, |
| 101 | {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, |
| 102 | {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, |
| 103 | {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, |
| 104 | {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, |
| 105 | {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, |
| 106 | {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, |
| 107 | {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, |
| 108 | {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, |
| 109 | {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, |
| 110 | {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, |
| 111 | {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, |
| 112 | {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, |
| 113 | {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, |
| 114 | {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, |
| 115 | {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, |
| 116 | {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, |
| 117 | {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, |
| 118 | {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, |
| 119 | {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, |
| 120 | {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, |
| 121 | {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, |
| 122 | {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} |
| 123 | }; |
| 124 | |
| 125 | static const u8 cckswing_table_ch14[CCK_TABLE_SIZE][8] = { |
| 126 | {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, |
| 127 | {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, |
| 128 | {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, |
| 129 | {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, |
| 130 | {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, |
| 131 | {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, |
| 132 | {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, |
| 133 | {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, |
| 134 | {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, |
| 135 | {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, |
| 136 | {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, |
| 137 | {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, |
| 138 | {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, |
| 139 | {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, |
| 140 | {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, |
| 141 | {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, |
| 142 | {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, |
| 143 | {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, |
| 144 | {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, |
| 145 | {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, |
| 146 | {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, |
| 147 | {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, |
| 148 | {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, |
| 149 | {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, |
| 150 | {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, |
| 151 | {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, |
| 152 | {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, |
| 153 | {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, |
| 154 | {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, |
| 155 | {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, |
| 156 | {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, |
| 157 | {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, |
| 158 | {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} |
| 159 | }; |
| 160 | |
Larry Finger | 97204e9 | 2013-11-18 11:11:32 -0600 | [diff] [blame^] | 161 | static u32 power_index_reg[6] = {0xc90, 0xc91, 0xc92, 0xc98, 0xc99, 0xc9a}; |
| 162 | |
| 163 | void dm_restorepowerindex(struct ieee80211_hw *hw) |
| 164 | { |
| 165 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 166 | u8 index; |
| 167 | |
| 168 | for (index = 0; index < 6; index++) |
| 169 | rtl_write_byte(rtlpriv, power_index_reg[index], |
| 170 | rtlpriv->dm.powerindex_backup[index]); |
| 171 | } |
| 172 | EXPORT_SYMBOL_GPL(dm_restorepowerindex); |
| 173 | |
| 174 | void dm_writepowerindex(struct ieee80211_hw *hw, u8 value) |
| 175 | { |
| 176 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 177 | u8 index; |
| 178 | |
| 179 | for (index = 0; index < 6; index++) |
| 180 | rtl_write_byte(rtlpriv, power_index_reg[index], value); |
| 181 | } |
| 182 | EXPORT_SYMBOL_GPL(dm_writepowerindex); |
| 183 | |
| 184 | void dm_savepowerindex(struct ieee80211_hw *hw) |
| 185 | { |
| 186 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 187 | u8 index; |
| 188 | u8 tmp; |
| 189 | |
| 190 | for (index = 0; index < 6; index++) { |
| 191 | tmp = rtl_read_byte(rtlpriv, power_index_reg[index]); |
| 192 | rtlpriv->dm.powerindex_backup[index] = tmp; |
| 193 | } |
| 194 | } |
| 195 | EXPORT_SYMBOL_GPL(dm_savepowerindex); |
| 196 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 197 | static void rtl92c_dm_diginit(struct ieee80211_hw *hw) |
| 198 | { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 199 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 200 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
| 201 | |
| 202 | dm_digtable->dig_enable_flag = true; |
| 203 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
| 204 | dm_digtable->cur_igvalue = 0x20; |
| 205 | dm_digtable->pre_igvalue = 0x0; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 206 | dm_digtable->cursta_cstate = DIG_STA_DISCONNECT; |
| 207 | dm_digtable->presta_cstate = DIG_STA_DISCONNECT; |
| 208 | dm_digtable->curmultista_cstate = DIG_MULTISTA_DISCONNECT; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 209 | dm_digtable->rssi_lowthresh = DM_DIG_THRESH_LOW; |
| 210 | dm_digtable->rssi_highthresh = DM_DIG_THRESH_HIGH; |
| 211 | dm_digtable->fa_lowthresh = DM_FALSEALARM_THRESH_LOW; |
| 212 | dm_digtable->fa_highthresh = DM_FALSEALARM_THRESH_HIGH; |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 213 | dm_digtable->rx_gain_max = DM_DIG_MAX; |
| 214 | dm_digtable->rx_gain_min = DM_DIG_MIN; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 215 | dm_digtable->back_val = DM_DIG_BACKOFF_DEFAULT; |
| 216 | dm_digtable->back_range_max = DM_DIG_BACKOFF_MAX; |
| 217 | dm_digtable->back_range_min = DM_DIG_BACKOFF_MIN; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 218 | dm_digtable->pre_cck_pd_state = CCK_PD_STAGE_MAX; |
| 219 | dm_digtable->cur_cck_pd_state = CCK_PD_STAGE_MAX; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static u8 rtl92c_dm_initial_gain_min_pwdb(struct ieee80211_hw *hw) |
| 223 | { |
| 224 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 225 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 226 | long rssi_val_min = 0; |
| 227 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 228 | if ((dm_digtable->curmultista_cstate == DIG_MULTISTA_CONNECT) && |
| 229 | (dm_digtable->cursta_cstate == DIG_STA_CONNECT)) { |
| 230 | if (rtlpriv->dm.entry_min_undec_sm_pwdb != 0) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 231 | rssi_val_min = |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 232 | (rtlpriv->dm.entry_min_undec_sm_pwdb > |
| 233 | rtlpriv->dm.undec_sm_pwdb) ? |
| 234 | rtlpriv->dm.undec_sm_pwdb : |
| 235 | rtlpriv->dm.entry_min_undec_sm_pwdb; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 236 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 237 | rssi_val_min = rtlpriv->dm.undec_sm_pwdb; |
| 238 | } else if (dm_digtable->cursta_cstate == DIG_STA_CONNECT || |
| 239 | dm_digtable->cursta_cstate == DIG_STA_BEFORE_CONNECT) { |
| 240 | rssi_val_min = rtlpriv->dm.undec_sm_pwdb; |
| 241 | } else if (dm_digtable->curmultista_cstate == DIG_MULTISTA_CONNECT) { |
| 242 | rssi_val_min = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | return (u8) rssi_val_min; |
| 246 | } |
| 247 | |
| 248 | static void rtl92c_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw) |
| 249 | { |
| 250 | u32 ret_value; |
| 251 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 252 | struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); |
| 253 | |
| 254 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER1, MASKDWORD); |
| 255 | falsealm_cnt->cnt_parity_fail = ((ret_value & 0xffff0000) >> 16); |
| 256 | |
| 257 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER2, MASKDWORD); |
| 258 | falsealm_cnt->cnt_rate_illegal = (ret_value & 0xffff); |
| 259 | falsealm_cnt->cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16); |
| 260 | |
| 261 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER3, MASKDWORD); |
| 262 | falsealm_cnt->cnt_mcs_fail = (ret_value & 0xffff); |
| 263 | falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail + |
| 264 | falsealm_cnt->cnt_rate_illegal + |
| 265 | falsealm_cnt->cnt_crc8_fail + falsealm_cnt->cnt_mcs_fail; |
| 266 | |
| 267 | rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, BIT(14), 1); |
| 268 | ret_value = rtl_get_bbreg(hw, RCCK0_FACOUNTERLOWER, MASKBYTE0); |
| 269 | falsealm_cnt->cnt_cck_fail = ret_value; |
| 270 | |
| 271 | ret_value = rtl_get_bbreg(hw, RCCK0_FACOUNTERUPPER, MASKBYTE3); |
| 272 | falsealm_cnt->cnt_cck_fail += (ret_value & 0xff) << 8; |
| 273 | falsealm_cnt->cnt_all = (falsealm_cnt->cnt_parity_fail + |
| 274 | falsealm_cnt->cnt_rate_illegal + |
| 275 | falsealm_cnt->cnt_crc8_fail + |
| 276 | falsealm_cnt->cnt_mcs_fail + |
| 277 | falsealm_cnt->cnt_cck_fail); |
| 278 | |
| 279 | rtl_set_bbreg(hw, ROFDM1_LSTF, 0x08000000, 1); |
| 280 | rtl_set_bbreg(hw, ROFDM1_LSTF, 0x08000000, 0); |
| 281 | rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, 0x0000c000, 0); |
| 282 | rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, 0x0000c000, 2); |
| 283 | |
| 284 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 285 | "cnt_parity_fail = %d, cnt_rate_illegal = %d, cnt_crc8_fail = %d, cnt_mcs_fail = %d\n", |
| 286 | falsealm_cnt->cnt_parity_fail, |
| 287 | falsealm_cnt->cnt_rate_illegal, |
| 288 | falsealm_cnt->cnt_crc8_fail, falsealm_cnt->cnt_mcs_fail); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 289 | |
| 290 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 291 | "cnt_ofdm_fail = %x, cnt_cck_fail = %x, cnt_all = %x\n", |
| 292 | falsealm_cnt->cnt_ofdm_fail, |
| 293 | falsealm_cnt->cnt_cck_fail, falsealm_cnt->cnt_all); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void rtl92c_dm_ctrl_initgain_by_fa(struct ieee80211_hw *hw) |
| 297 | { |
| 298 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 299 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
| 300 | u8 value_igi = dm_digtable->cur_igvalue; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 301 | |
| 302 | if (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH0) |
| 303 | value_igi--; |
| 304 | else if (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH1) |
| 305 | value_igi += 0; |
| 306 | else if (rtlpriv->falsealm_cnt.cnt_all < DM_DIG_FA_TH2) |
| 307 | value_igi++; |
| 308 | else if (rtlpriv->falsealm_cnt.cnt_all >= DM_DIG_FA_TH2) |
| 309 | value_igi += 2; |
| 310 | if (value_igi > DM_DIG_FA_UPPER) |
| 311 | value_igi = DM_DIG_FA_UPPER; |
| 312 | else if (value_igi < DM_DIG_FA_LOWER) |
| 313 | value_igi = DM_DIG_FA_LOWER; |
| 314 | if (rtlpriv->falsealm_cnt.cnt_all > 10000) |
| 315 | value_igi = 0x32; |
| 316 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 317 | dm_digtable->cur_igvalue = value_igi; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 318 | rtl92c_dm_write_dig(hw); |
| 319 | } |
| 320 | |
| 321 | static void rtl92c_dm_ctrl_initgain_by_rssi(struct ieee80211_hw *hw) |
| 322 | { |
| 323 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 324 | struct dig_t *digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 325 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 326 | if (rtlpriv->falsealm_cnt.cnt_all > digtable->fa_highthresh) { |
| 327 | if ((digtable->back_val - 2) < digtable->back_range_min) |
| 328 | digtable->back_val = digtable->back_range_min; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 329 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 330 | digtable->back_val -= 2; |
| 331 | } else if (rtlpriv->falsealm_cnt.cnt_all < digtable->fa_lowthresh) { |
| 332 | if ((digtable->back_val + 2) > digtable->back_range_max) |
| 333 | digtable->back_val = digtable->back_range_max; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 334 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 335 | digtable->back_val += 2; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 336 | } |
| 337 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 338 | if ((digtable->rssi_val_min + 10 - digtable->back_val) > |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 339 | digtable->rx_gain_max) |
| 340 | digtable->cur_igvalue = digtable->rx_gain_max; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 341 | else if ((digtable->rssi_val_min + 10 - |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 342 | digtable->back_val) < digtable->rx_gain_min) |
| 343 | digtable->cur_igvalue = digtable->rx_gain_min; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 344 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 345 | digtable->cur_igvalue = digtable->rssi_val_min + 10 - |
| 346 | digtable->back_val; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 347 | |
| 348 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 349 | "rssi_val_min = %x back_val %x\n", |
| 350 | digtable->rssi_val_min, digtable->back_val); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 351 | |
| 352 | rtl92c_dm_write_dig(hw); |
| 353 | } |
| 354 | |
| 355 | static void rtl92c_dm_initial_gain_multi_sta(struct ieee80211_hw *hw) |
| 356 | { |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 357 | static u8 initialized; /* initialized to false */ |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 358 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 359 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 360 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 361 | long rssi_strength = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 362 | bool multi_sta = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 363 | |
| 364 | if (mac->opmode == NL80211_IFTYPE_ADHOC) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 365 | multi_sta = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 366 | |
Joe Perches | 23677ce | 2012-02-09 11:17:23 +0000 | [diff] [blame] | 367 | if (!multi_sta || |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 368 | dm_digtable->cursta_cstate != DIG_STA_DISCONNECT) { |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 369 | initialized = false; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 370 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 371 | return; |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 372 | } else if (initialized == false) { |
| 373 | initialized = true; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 374 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_0; |
| 375 | dm_digtable->cur_igvalue = 0x20; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 376 | rtl92c_dm_write_dig(hw); |
| 377 | } |
| 378 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 379 | if (dm_digtable->curmultista_cstate == DIG_MULTISTA_CONNECT) { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 380 | if ((rssi_strength < dm_digtable->rssi_lowthresh) && |
| 381 | (dm_digtable->dig_ext_port_stage != DIG_EXT_PORT_STAGE_1)) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 382 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 383 | if (dm_digtable->dig_ext_port_stage == |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 384 | DIG_EXT_PORT_STAGE_2) { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 385 | dm_digtable->cur_igvalue = 0x20; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 386 | rtl92c_dm_write_dig(hw); |
| 387 | } |
| 388 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 389 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_1; |
| 390 | } else if (rssi_strength > dm_digtable->rssi_highthresh) { |
| 391 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_2; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 392 | rtl92c_dm_ctrl_initgain_by_fa(hw); |
| 393 | } |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 394 | } else if (dm_digtable->dig_ext_port_stage != DIG_EXT_PORT_STAGE_0) { |
| 395 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_0; |
| 396 | dm_digtable->cur_igvalue = 0x20; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 397 | rtl92c_dm_write_dig(hw); |
| 398 | } |
| 399 | |
| 400 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 401 | "curmultista_cstate = %x dig_ext_port_stage %x\n", |
| 402 | dm_digtable->curmultista_cstate, |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 403 | dm_digtable->dig_ext_port_stage); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void rtl92c_dm_initial_gain_sta(struct ieee80211_hw *hw) |
| 407 | { |
| 408 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 409 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 410 | |
| 411 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 412 | "presta_cstate = %x, cursta_cstate = %x\n", |
| 413 | dm_digtable->presta_cstate, dm_digtable->cursta_cstate); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 414 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 415 | if (dm_digtable->presta_cstate == dm_digtable->cursta_cstate || |
| 416 | dm_digtable->cursta_cstate == DIG_STA_BEFORE_CONNECT || |
| 417 | dm_digtable->cursta_cstate == DIG_STA_CONNECT) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 418 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 419 | if (dm_digtable->cursta_cstate != DIG_STA_DISCONNECT) { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 420 | dm_digtable->rssi_val_min = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 421 | rtl92c_dm_initial_gain_min_pwdb(hw); |
| 422 | rtl92c_dm_ctrl_initgain_by_rssi(hw); |
| 423 | } |
| 424 | } else { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 425 | dm_digtable->rssi_val_min = 0; |
| 426 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 427 | dm_digtable->back_val = DM_DIG_BACKOFF_DEFAULT; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 428 | dm_digtable->cur_igvalue = 0x20; |
| 429 | dm_digtable->pre_igvalue = 0; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 430 | rtl92c_dm_write_dig(hw); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | static void rtl92c_dm_cck_packet_detection_thresh(struct ieee80211_hw *hw) |
| 435 | { |
| 436 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 437 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 438 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 439 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 440 | if (dm_digtable->cursta_cstate == DIG_STA_CONNECT) { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 441 | dm_digtable->rssi_val_min = rtl92c_dm_initial_gain_min_pwdb(hw); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 442 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 443 | if (dm_digtable->pre_cck_pd_state == CCK_PD_STAGE_LowRssi) { |
| 444 | if (dm_digtable->rssi_val_min <= 25) |
| 445 | dm_digtable->cur_cck_pd_state = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 446 | CCK_PD_STAGE_LowRssi; |
| 447 | else |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 448 | dm_digtable->cur_cck_pd_state = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 449 | CCK_PD_STAGE_HighRssi; |
| 450 | } else { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 451 | if (dm_digtable->rssi_val_min <= 20) |
| 452 | dm_digtable->cur_cck_pd_state = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 453 | CCK_PD_STAGE_LowRssi; |
| 454 | else |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 455 | dm_digtable->cur_cck_pd_state = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 456 | CCK_PD_STAGE_HighRssi; |
| 457 | } |
| 458 | } else { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 459 | dm_digtable->cur_cck_pd_state = CCK_PD_STAGE_MAX; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 460 | } |
| 461 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 462 | if (dm_digtable->pre_cck_pd_state != dm_digtable->cur_cck_pd_state) { |
| 463 | if (dm_digtable->cur_cck_pd_state == CCK_PD_STAGE_LowRssi) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 464 | if (rtlpriv->falsealm_cnt.cnt_cck_fail > 800) |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 465 | dm_digtable->cur_cck_fa_state = |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 466 | CCK_FA_STAGE_High; |
| 467 | else |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 468 | dm_digtable->cur_cck_fa_state = CCK_FA_STAGE_Low; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 469 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 470 | if (dm_digtable->pre_cck_fa_state != |
| 471 | dm_digtable->cur_cck_fa_state) { |
| 472 | if (dm_digtable->cur_cck_fa_state == |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 473 | CCK_FA_STAGE_Low) |
| 474 | rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, |
| 475 | 0x83); |
| 476 | else |
| 477 | rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, |
| 478 | 0xcd); |
| 479 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 480 | dm_digtable->pre_cck_fa_state = |
| 481 | dm_digtable->cur_cck_fa_state; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | rtl_set_bbreg(hw, RCCK0_SYSTEM, MASKBYTE1, 0x40); |
| 485 | |
| 486 | if (IS_92C_SERIAL(rtlhal->version)) |
| 487 | rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, |
| 488 | MASKBYTE2, 0xd7); |
| 489 | } else { |
| 490 | rtl_set_bbreg(hw, RCCK0_CCA, MASKBYTE2, 0xcd); |
| 491 | rtl_set_bbreg(hw, RCCK0_SYSTEM, MASKBYTE1, 0x47); |
| 492 | |
| 493 | if (IS_92C_SERIAL(rtlhal->version)) |
| 494 | rtl_set_bbreg(hw, RCCK0_FALSEALARMREPORT, |
| 495 | MASKBYTE2, 0xd3); |
| 496 | } |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 497 | dm_digtable->pre_cck_pd_state = dm_digtable->cur_cck_pd_state; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 498 | } |
| 499 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 500 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, "CCKPDStage=%x\n", |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 501 | dm_digtable->cur_cck_pd_state); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 502 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 503 | RT_TRACE(rtlpriv, COMP_DIG, DBG_TRACE, "is92C=%x\n", |
| 504 | IS_92C_SERIAL(rtlhal->version)); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | static void rtl92c_dm_ctrl_initgain_by_twoport(struct ieee80211_hw *hw) |
| 508 | { |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 509 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 510 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 511 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 512 | |
Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 513 | if (mac->act_scanning) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 514 | return; |
| 515 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 516 | if (mac->link_state >= MAC80211_LINKED) |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 517 | dm_digtable->cursta_cstate = DIG_STA_CONNECT; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 518 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 519 | dm_digtable->cursta_cstate = DIG_STA_DISCONNECT; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 520 | |
| 521 | rtl92c_dm_initial_gain_sta(hw); |
| 522 | rtl92c_dm_initial_gain_multi_sta(hw); |
| 523 | rtl92c_dm_cck_packet_detection_thresh(hw); |
| 524 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 525 | dm_digtable->presta_cstate = dm_digtable->cursta_cstate; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 526 | |
| 527 | } |
| 528 | |
| 529 | static void rtl92c_dm_dig(struct ieee80211_hw *hw) |
| 530 | { |
| 531 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 532 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 533 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 534 | if (rtlpriv->dm.dm_initialgain_enable == false) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 535 | return; |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 536 | if (dm_digtable->dig_enable_flag == false) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 537 | return; |
| 538 | |
| 539 | rtl92c_dm_ctrl_initgain_by_twoport(hw); |
| 540 | |
| 541 | } |
| 542 | |
| 543 | static void rtl92c_dm_init_dynamic_txpower(struct ieee80211_hw *hw) |
| 544 | { |
| 545 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 546 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 547 | rtlpriv->dm.dynamic_txpower_enable = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 548 | |
| 549 | rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 550 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 551 | } |
| 552 | |
| 553 | void rtl92c_dm_write_dig(struct ieee80211_hw *hw) |
| 554 | { |
| 555 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 556 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 557 | |
| 558 | RT_TRACE(rtlpriv, COMP_DIG, DBG_LOUD, |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 559 | "cur_igvalue = 0x%x, pre_igvalue = 0x%x, back_val = %d\n", |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 560 | dm_digtable->cur_igvalue, dm_digtable->pre_igvalue, |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 561 | dm_digtable->back_val); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 562 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 563 | dm_digtable->cur_igvalue += 2; |
| 564 | if (dm_digtable->cur_igvalue > 0x3f) |
| 565 | dm_digtable->cur_igvalue = 0x3f; |
Jingjun Wu | a9b89e2 | 2012-03-02 20:52:14 -0600 | [diff] [blame] | 566 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 567 | if (dm_digtable->pre_igvalue != dm_digtable->cur_igvalue) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 568 | rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, 0x7f, |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 569 | dm_digtable->cur_igvalue); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 570 | rtl_set_bbreg(hw, ROFDM0_XBAGCCORE1, 0x7f, |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 571 | dm_digtable->cur_igvalue); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 572 | |
Larry Finger | 40332e5 | 2012-04-19 16:32:41 -0500 | [diff] [blame] | 573 | dm_digtable->pre_igvalue = dm_digtable->cur_igvalue; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 574 | } |
| 575 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 576 | EXPORT_SYMBOL(rtl92c_dm_write_dig); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 577 | |
| 578 | static void rtl92c_dm_pwdb_monitor(struct ieee80211_hw *hw) |
| 579 | { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | void rtl92c_dm_init_edca_turbo(struct ieee80211_hw *hw) |
| 583 | { |
| 584 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 585 | rtlpriv->dm.current_turbo_edca = false; |
| 586 | rtlpriv->dm.is_any_nonbepkts = false; |
| 587 | rtlpriv->dm.is_cur_rdlstate = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 588 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 589 | EXPORT_SYMBOL(rtl92c_dm_init_edca_turbo); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 590 | |
| 591 | static void rtl92c_dm_check_edca_turbo(struct ieee80211_hw *hw) |
| 592 | { |
| 593 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 594 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 595 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 596 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 597 | static u64 last_txok_cnt; |
| 598 | static u64 last_rxok_cnt; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 599 | static u32 last_bt_edca_ul; |
| 600 | static u32 last_bt_edca_dl; |
| 601 | u64 cur_txok_cnt = 0; |
| 602 | u64 cur_rxok_cnt = 0; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 603 | u32 edca_be_ul = 0x5ea42b; |
| 604 | u32 edca_be_dl = 0x5ea42b; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 605 | bool bt_change_edca = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 606 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 607 | if ((last_bt_edca_ul != rtlpcipriv->bt_coexist.bt_edca_ul) || |
| 608 | (last_bt_edca_dl != rtlpcipriv->bt_coexist.bt_edca_dl)) { |
| 609 | rtlpriv->dm.current_turbo_edca = false; |
| 610 | last_bt_edca_ul = rtlpcipriv->bt_coexist.bt_edca_ul; |
| 611 | last_bt_edca_dl = rtlpcipriv->bt_coexist.bt_edca_dl; |
| 612 | } |
| 613 | |
| 614 | if (rtlpcipriv->bt_coexist.bt_edca_ul != 0) { |
| 615 | edca_be_ul = rtlpcipriv->bt_coexist.bt_edca_ul; |
| 616 | bt_change_edca = true; |
| 617 | } |
| 618 | |
| 619 | if (rtlpcipriv->bt_coexist.bt_edca_dl != 0) { |
| 620 | edca_be_ul = rtlpcipriv->bt_coexist.bt_edca_dl; |
| 621 | bt_change_edca = true; |
| 622 | } |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 623 | |
| 624 | if (mac->link_state != MAC80211_LINKED) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 625 | rtlpriv->dm.current_turbo_edca = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 626 | return; |
| 627 | } |
| 628 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 629 | if ((!mac->ht_enable) && (!rtlpcipriv->bt_coexist.bt_coexistence)) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 630 | if (!(edca_be_ul & 0xffff0000)) |
| 631 | edca_be_ul |= 0x005e0000; |
| 632 | |
| 633 | if (!(edca_be_dl & 0xffff0000)) |
| 634 | edca_be_dl |= 0x005e0000; |
| 635 | } |
| 636 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 637 | if ((bt_change_edca) || ((!rtlpriv->dm.is_any_nonbepkts) && |
| 638 | (!rtlpriv->dm.disable_framebursting))) { |
| 639 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 640 | cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt; |
| 641 | cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 642 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 643 | if (cur_rxok_cnt > 4 * cur_txok_cnt) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 644 | if (!rtlpriv->dm.is_cur_rdlstate || |
| 645 | !rtlpriv->dm.current_turbo_edca) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 646 | rtl_write_dword(rtlpriv, |
| 647 | REG_EDCA_BE_PARAM, |
| 648 | edca_be_dl); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 649 | rtlpriv->dm.is_cur_rdlstate = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 650 | } |
| 651 | } else { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 652 | if (rtlpriv->dm.is_cur_rdlstate || |
| 653 | !rtlpriv->dm.current_turbo_edca) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 654 | rtl_write_dword(rtlpriv, |
| 655 | REG_EDCA_BE_PARAM, |
| 656 | edca_be_ul); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 657 | rtlpriv->dm.is_cur_rdlstate = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 658 | } |
| 659 | } |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 660 | rtlpriv->dm.current_turbo_edca = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 661 | } else { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 662 | if (rtlpriv->dm.current_turbo_edca) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 663 | u8 tmp = AC0_BE; |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 664 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, |
| 665 | &tmp); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 666 | rtlpriv->dm.current_turbo_edca = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 670 | rtlpriv->dm.is_any_nonbepkts = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 671 | last_txok_cnt = rtlpriv->stats.txbytesunicast; |
| 672 | last_rxok_cnt = rtlpriv->stats.rxbytesunicast; |
| 673 | } |
| 674 | |
| 675 | static void rtl92c_dm_txpower_tracking_callback_thermalmeter(struct ieee80211_hw |
| 676 | *hw) |
| 677 | { |
| 678 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 679 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 680 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 681 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 682 | u8 thermalvalue, delta, delta_lck, delta_iqk; |
| 683 | long ele_a, ele_d, temp_cck, val_x, value32; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 684 | long val_y, ele_c = 0; |
Han Shen | 7c8f0db | 2013-04-22 13:35:07 -0700 | [diff] [blame] | 685 | u8 ofdm_index[2], ofdm_index_old[2] = {0, 0}, cck_index_old = 0; |
Larry Finger | 8a8e31c | 2013-02-01 10:40:24 -0600 | [diff] [blame] | 686 | s8 cck_index = 0; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 687 | int i; |
| 688 | bool is2t = IS_92C_SERIAL(rtlhal->version); |
Larry Finger | d0df71dc | 2013-09-25 12:57:45 -0500 | [diff] [blame] | 689 | s8 txpwr_level[3] = {0, 0, 0}; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 690 | u8 ofdm_min_index = 6, rf; |
| 691 | |
Chaoming_Li | 3dad618 | 2011-04-25 12:52:49 -0500 | [diff] [blame] | 692 | rtlpriv->dm.txpower_trackinginit = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 693 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 694 | "rtl92c_dm_txpower_tracking_callback_thermalmeter\n"); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 695 | |
| 696 | thermalvalue = (u8) rtl_get_rfreg(hw, RF90_PATH_A, RF_T_METER, 0x1f); |
| 697 | |
| 698 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 699 | "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x\n", |
| 700 | thermalvalue, rtlpriv->dm.thermalvalue, |
| 701 | rtlefuse->eeprom_thermalmeter); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 702 | |
| 703 | rtl92c_phy_ap_calibrate(hw, (thermalvalue - |
| 704 | rtlefuse->eeprom_thermalmeter)); |
| 705 | if (is2t) |
| 706 | rf = 2; |
| 707 | else |
| 708 | rf = 1; |
| 709 | |
| 710 | if (thermalvalue) { |
| 711 | ele_d = rtl_get_bbreg(hw, ROFDM0_XATXIQIMBALANCE, |
| 712 | MASKDWORD) & MASKOFDM_D; |
| 713 | |
| 714 | for (i = 0; i < OFDM_TABLE_LENGTH; i++) { |
| 715 | if (ele_d == (ofdmswing_table[i] & MASKOFDM_D)) { |
| 716 | ofdm_index_old[0] = (u8) i; |
| 717 | |
| 718 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 719 | "Initial pathA ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n", |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 720 | ROFDM0_XATXIQIMBALANCE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 721 | ele_d, ofdm_index_old[0]); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 722 | break; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | if (is2t) { |
| 727 | ele_d = rtl_get_bbreg(hw, ROFDM0_XBTXIQIMBALANCE, |
| 728 | MASKDWORD) & MASKOFDM_D; |
| 729 | |
| 730 | for (i = 0; i < OFDM_TABLE_LENGTH; i++) { |
| 731 | if (ele_d == (ofdmswing_table[i] & |
| 732 | MASKOFDM_D)) { |
Han Shen | 7c8f0db | 2013-04-22 13:35:07 -0700 | [diff] [blame] | 733 | ofdm_index_old[1] = (u8) i; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 734 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 735 | DBG_LOUD, |
| 736 | "Initial pathB ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n", |
| 737 | ROFDM0_XBTXIQIMBALANCE, ele_d, |
| 738 | ofdm_index_old[1]); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | temp_cck = |
| 745 | rtl_get_bbreg(hw, RCCK0_TXFILTER2, MASKDWORD) & MASKCCK; |
| 746 | |
| 747 | for (i = 0; i < CCK_TABLE_LENGTH; i++) { |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 748 | if (rtlpriv->dm.cck_inch14) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 749 | if (memcmp((void *)&temp_cck, |
| 750 | (void *)&cckswing_table_ch14[i][2], |
| 751 | 4) == 0) { |
| 752 | cck_index_old = (u8) i; |
| 753 | |
| 754 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, |
| 755 | DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 756 | "Initial reg0x%x = 0x%lx, cck_index=0x%x, ch 14 %d\n", |
| 757 | RCCK0_TXFILTER2, temp_cck, |
| 758 | cck_index_old, |
| 759 | rtlpriv->dm.cck_inch14); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 760 | break; |
| 761 | } |
| 762 | } else { |
| 763 | if (memcmp((void *)&temp_cck, |
| 764 | (void *) |
| 765 | &cckswing_table_ch1ch13[i][2], |
| 766 | 4) == 0) { |
| 767 | cck_index_old = (u8) i; |
| 768 | |
| 769 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, |
| 770 | DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 771 | "Initial reg0x%x = 0x%lx, cck_index=0x%x, ch14 %d\n", |
| 772 | RCCK0_TXFILTER2, temp_cck, |
| 773 | cck_index_old, |
| 774 | rtlpriv->dm.cck_inch14); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 775 | break; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | if (!rtlpriv->dm.thermalvalue) { |
| 781 | rtlpriv->dm.thermalvalue = |
| 782 | rtlefuse->eeprom_thermalmeter; |
| 783 | rtlpriv->dm.thermalvalue_lck = thermalvalue; |
| 784 | rtlpriv->dm.thermalvalue_iqk = thermalvalue; |
| 785 | for (i = 0; i < rf; i++) |
| 786 | rtlpriv->dm.ofdm_index[i] = ofdm_index_old[i]; |
| 787 | rtlpriv->dm.cck_index = cck_index_old; |
| 788 | } |
| 789 | |
| 790 | delta = (thermalvalue > rtlpriv->dm.thermalvalue) ? |
| 791 | (thermalvalue - rtlpriv->dm.thermalvalue) : |
| 792 | (rtlpriv->dm.thermalvalue - thermalvalue); |
| 793 | |
| 794 | delta_lck = (thermalvalue > rtlpriv->dm.thermalvalue_lck) ? |
| 795 | (thermalvalue - rtlpriv->dm.thermalvalue_lck) : |
| 796 | (rtlpriv->dm.thermalvalue_lck - thermalvalue); |
| 797 | |
| 798 | delta_iqk = (thermalvalue > rtlpriv->dm.thermalvalue_iqk) ? |
| 799 | (thermalvalue - rtlpriv->dm.thermalvalue_iqk) : |
| 800 | (rtlpriv->dm.thermalvalue_iqk - thermalvalue); |
| 801 | |
| 802 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 803 | "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x delta 0x%x delta_lck 0x%x delta_iqk 0x%x\n", |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 804 | thermalvalue, rtlpriv->dm.thermalvalue, |
| 805 | rtlefuse->eeprom_thermalmeter, delta, delta_lck, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 806 | delta_iqk); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 807 | |
| 808 | if (delta_lck > 1) { |
| 809 | rtlpriv->dm.thermalvalue_lck = thermalvalue; |
| 810 | rtl92c_phy_lc_calibrate(hw); |
| 811 | } |
| 812 | |
| 813 | if (delta > 0 && rtlpriv->dm.txpower_track_control) { |
| 814 | if (thermalvalue > rtlpriv->dm.thermalvalue) { |
| 815 | for (i = 0; i < rf; i++) |
| 816 | rtlpriv->dm.ofdm_index[i] -= delta; |
| 817 | rtlpriv->dm.cck_index -= delta; |
| 818 | } else { |
| 819 | for (i = 0; i < rf; i++) |
| 820 | rtlpriv->dm.ofdm_index[i] += delta; |
| 821 | rtlpriv->dm.cck_index += delta; |
| 822 | } |
| 823 | |
| 824 | if (is2t) { |
| 825 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 826 | "temp OFDM_A_index=0x%x, OFDM_B_index=0x%x, cck_index=0x%x\n", |
| 827 | rtlpriv->dm.ofdm_index[0], |
| 828 | rtlpriv->dm.ofdm_index[1], |
| 829 | rtlpriv->dm.cck_index); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 830 | } else { |
| 831 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 832 | "temp OFDM_A_index=0x%x, cck_index=0x%x\n", |
| 833 | rtlpriv->dm.ofdm_index[0], |
| 834 | rtlpriv->dm.cck_index); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | if (thermalvalue > rtlefuse->eeprom_thermalmeter) { |
| 838 | for (i = 0; i < rf; i++) |
| 839 | ofdm_index[i] = |
| 840 | rtlpriv->dm.ofdm_index[i] |
| 841 | + 1; |
| 842 | cck_index = rtlpriv->dm.cck_index + 1; |
| 843 | } else { |
| 844 | for (i = 0; i < rf; i++) |
| 845 | ofdm_index[i] = |
| 846 | rtlpriv->dm.ofdm_index[i]; |
| 847 | cck_index = rtlpriv->dm.cck_index; |
| 848 | } |
| 849 | |
| 850 | for (i = 0; i < rf; i++) { |
| 851 | if (txpwr_level[i] >= 0 && |
| 852 | txpwr_level[i] <= 26) { |
| 853 | if (thermalvalue > |
| 854 | rtlefuse->eeprom_thermalmeter) { |
| 855 | if (delta < 5) |
| 856 | ofdm_index[i] -= 1; |
| 857 | |
| 858 | else |
| 859 | ofdm_index[i] -= 2; |
| 860 | } else if (delta > 5 && thermalvalue < |
| 861 | rtlefuse-> |
| 862 | eeprom_thermalmeter) { |
| 863 | ofdm_index[i] += 1; |
| 864 | } |
| 865 | } else if (txpwr_level[i] >= 27 && |
| 866 | txpwr_level[i] <= 32 |
| 867 | && thermalvalue > |
| 868 | rtlefuse->eeprom_thermalmeter) { |
| 869 | if (delta < 5) |
| 870 | ofdm_index[i] -= 1; |
| 871 | |
| 872 | else |
| 873 | ofdm_index[i] -= 2; |
| 874 | } else if (txpwr_level[i] >= 32 && |
| 875 | txpwr_level[i] <= 38 && |
| 876 | thermalvalue > |
| 877 | rtlefuse->eeprom_thermalmeter |
| 878 | && delta > 5) { |
| 879 | ofdm_index[i] -= 1; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | if (txpwr_level[i] >= 0 && txpwr_level[i] <= 26) { |
| 884 | if (thermalvalue > |
| 885 | rtlefuse->eeprom_thermalmeter) { |
| 886 | if (delta < 5) |
| 887 | cck_index -= 1; |
| 888 | |
| 889 | else |
| 890 | cck_index -= 2; |
| 891 | } else if (delta > 5 && thermalvalue < |
| 892 | rtlefuse->eeprom_thermalmeter) { |
| 893 | cck_index += 1; |
| 894 | } |
| 895 | } else if (txpwr_level[i] >= 27 && |
| 896 | txpwr_level[i] <= 32 && |
| 897 | thermalvalue > |
| 898 | rtlefuse->eeprom_thermalmeter) { |
| 899 | if (delta < 5) |
| 900 | cck_index -= 1; |
| 901 | |
| 902 | else |
| 903 | cck_index -= 2; |
| 904 | } else if (txpwr_level[i] >= 32 && |
| 905 | txpwr_level[i] <= 38 && |
| 906 | thermalvalue > rtlefuse->eeprom_thermalmeter |
| 907 | && delta > 5) { |
| 908 | cck_index -= 1; |
| 909 | } |
| 910 | |
| 911 | for (i = 0; i < rf; i++) { |
| 912 | if (ofdm_index[i] > OFDM_TABLE_SIZE - 1) |
| 913 | ofdm_index[i] = OFDM_TABLE_SIZE - 1; |
| 914 | |
| 915 | else if (ofdm_index[i] < ofdm_min_index) |
| 916 | ofdm_index[i] = ofdm_min_index; |
| 917 | } |
| 918 | |
| 919 | if (cck_index > CCK_TABLE_SIZE - 1) |
| 920 | cck_index = CCK_TABLE_SIZE - 1; |
| 921 | else if (cck_index < 0) |
| 922 | cck_index = 0; |
| 923 | |
| 924 | if (is2t) { |
| 925 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 926 | "new OFDM_A_index=0x%x, OFDM_B_index=0x%x, cck_index=0x%x\n", |
| 927 | ofdm_index[0], ofdm_index[1], |
| 928 | cck_index); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 929 | } else { |
| 930 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 931 | "new OFDM_A_index=0x%x, cck_index=0x%x\n", |
| 932 | ofdm_index[0], cck_index); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | if (rtlpriv->dm.txpower_track_control && delta != 0) { |
| 937 | ele_d = |
| 938 | (ofdmswing_table[ofdm_index[0]] & 0xFFC00000) >> 22; |
| 939 | val_x = rtlphy->reg_e94; |
| 940 | val_y = rtlphy->reg_e9c; |
| 941 | |
| 942 | if (val_x != 0) { |
| 943 | if ((val_x & 0x00000200) != 0) |
| 944 | val_x = val_x | 0xFFFFFC00; |
| 945 | ele_a = ((val_x * ele_d) >> 8) & 0x000003FF; |
| 946 | |
| 947 | if ((val_y & 0x00000200) != 0) |
| 948 | val_y = val_y | 0xFFFFFC00; |
| 949 | ele_c = ((val_y * ele_d) >> 8) & 0x000003FF; |
| 950 | |
| 951 | value32 = (ele_d << 22) | |
| 952 | ((ele_c & 0x3F) << 16) | ele_a; |
| 953 | |
| 954 | rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, |
| 955 | MASKDWORD, value32); |
| 956 | |
| 957 | value32 = (ele_c & 0x000003C0) >> 6; |
| 958 | rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS, |
| 959 | value32); |
| 960 | |
| 961 | value32 = ((val_x * ele_d) >> 7) & 0x01; |
| 962 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 963 | BIT(31), value32); |
| 964 | |
| 965 | value32 = ((val_y * ele_d) >> 7) & 0x01; |
| 966 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 967 | BIT(29), value32); |
| 968 | } else { |
| 969 | rtl_set_bbreg(hw, ROFDM0_XATXIQIMBALANCE, |
| 970 | MASKDWORD, |
| 971 | ofdmswing_table[ofdm_index[0]]); |
| 972 | |
| 973 | rtl_set_bbreg(hw, ROFDM0_XCTXAFE, MASKH4BITS, |
| 974 | 0x00); |
| 975 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 976 | BIT(31) | BIT(29), 0x00); |
| 977 | } |
| 978 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 979 | if (!rtlpriv->dm.cck_inch14) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 980 | rtl_write_byte(rtlpriv, 0xa22, |
| 981 | cckswing_table_ch1ch13[cck_index] |
| 982 | [0]); |
| 983 | rtl_write_byte(rtlpriv, 0xa23, |
| 984 | cckswing_table_ch1ch13[cck_index] |
| 985 | [1]); |
| 986 | rtl_write_byte(rtlpriv, 0xa24, |
| 987 | cckswing_table_ch1ch13[cck_index] |
| 988 | [2]); |
| 989 | rtl_write_byte(rtlpriv, 0xa25, |
| 990 | cckswing_table_ch1ch13[cck_index] |
| 991 | [3]); |
| 992 | rtl_write_byte(rtlpriv, 0xa26, |
| 993 | cckswing_table_ch1ch13[cck_index] |
| 994 | [4]); |
| 995 | rtl_write_byte(rtlpriv, 0xa27, |
| 996 | cckswing_table_ch1ch13[cck_index] |
| 997 | [5]); |
| 998 | rtl_write_byte(rtlpriv, 0xa28, |
| 999 | cckswing_table_ch1ch13[cck_index] |
| 1000 | [6]); |
| 1001 | rtl_write_byte(rtlpriv, 0xa29, |
| 1002 | cckswing_table_ch1ch13[cck_index] |
| 1003 | [7]); |
| 1004 | } else { |
| 1005 | rtl_write_byte(rtlpriv, 0xa22, |
| 1006 | cckswing_table_ch14[cck_index] |
| 1007 | [0]); |
| 1008 | rtl_write_byte(rtlpriv, 0xa23, |
| 1009 | cckswing_table_ch14[cck_index] |
| 1010 | [1]); |
| 1011 | rtl_write_byte(rtlpriv, 0xa24, |
| 1012 | cckswing_table_ch14[cck_index] |
| 1013 | [2]); |
| 1014 | rtl_write_byte(rtlpriv, 0xa25, |
| 1015 | cckswing_table_ch14[cck_index] |
| 1016 | [3]); |
| 1017 | rtl_write_byte(rtlpriv, 0xa26, |
| 1018 | cckswing_table_ch14[cck_index] |
| 1019 | [4]); |
| 1020 | rtl_write_byte(rtlpriv, 0xa27, |
| 1021 | cckswing_table_ch14[cck_index] |
| 1022 | [5]); |
| 1023 | rtl_write_byte(rtlpriv, 0xa28, |
| 1024 | cckswing_table_ch14[cck_index] |
| 1025 | [6]); |
| 1026 | rtl_write_byte(rtlpriv, 0xa29, |
| 1027 | cckswing_table_ch14[cck_index] |
| 1028 | [7]); |
| 1029 | } |
| 1030 | |
| 1031 | if (is2t) { |
| 1032 | ele_d = (ofdmswing_table[ofdm_index[1]] & |
| 1033 | 0xFFC00000) >> 22; |
| 1034 | |
| 1035 | val_x = rtlphy->reg_eb4; |
| 1036 | val_y = rtlphy->reg_ebc; |
| 1037 | |
| 1038 | if (val_x != 0) { |
| 1039 | if ((val_x & 0x00000200) != 0) |
| 1040 | val_x = val_x | 0xFFFFFC00; |
| 1041 | ele_a = ((val_x * ele_d) >> 8) & |
| 1042 | 0x000003FF; |
| 1043 | |
| 1044 | if ((val_y & 0x00000200) != 0) |
| 1045 | val_y = val_y | 0xFFFFFC00; |
| 1046 | ele_c = ((val_y * ele_d) >> 8) & |
| 1047 | 0x00003FF; |
| 1048 | |
| 1049 | value32 = (ele_d << 22) | |
| 1050 | ((ele_c & 0x3F) << 16) | ele_a; |
| 1051 | rtl_set_bbreg(hw, |
| 1052 | ROFDM0_XBTXIQIMBALANCE, |
| 1053 | MASKDWORD, value32); |
| 1054 | |
| 1055 | value32 = (ele_c & 0x000003C0) >> 6; |
| 1056 | rtl_set_bbreg(hw, ROFDM0_XDTXAFE, |
| 1057 | MASKH4BITS, value32); |
| 1058 | |
| 1059 | value32 = ((val_x * ele_d) >> 7) & 0x01; |
| 1060 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 1061 | BIT(27), value32); |
| 1062 | |
| 1063 | value32 = ((val_y * ele_d) >> 7) & 0x01; |
| 1064 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 1065 | BIT(25), value32); |
| 1066 | } else { |
| 1067 | rtl_set_bbreg(hw, |
| 1068 | ROFDM0_XBTXIQIMBALANCE, |
| 1069 | MASKDWORD, |
| 1070 | ofdmswing_table[ofdm_index |
| 1071 | [1]]); |
| 1072 | rtl_set_bbreg(hw, ROFDM0_XDTXAFE, |
| 1073 | MASKH4BITS, 0x00); |
| 1074 | rtl_set_bbreg(hw, ROFDM0_ECCATHRESHOLD, |
| 1075 | BIT(27) | BIT(25), 0x00); |
| 1076 | } |
| 1077 | |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | if (delta_iqk > 3) { |
| 1082 | rtlpriv->dm.thermalvalue_iqk = thermalvalue; |
| 1083 | rtl92c_phy_iq_calibrate(hw, false); |
| 1084 | } |
| 1085 | |
| 1086 | if (rtlpriv->dm.txpower_track_control) |
| 1087 | rtlpriv->dm.thermalvalue = thermalvalue; |
| 1088 | } |
| 1089 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1090 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, "<===\n"); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1091 | |
| 1092 | } |
| 1093 | |
| 1094 | static void rtl92c_dm_initialize_txpower_tracking_thermalmeter( |
| 1095 | struct ieee80211_hw *hw) |
| 1096 | { |
| 1097 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1098 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1099 | rtlpriv->dm.txpower_tracking = true; |
Chaoming_Li | 3dad618 | 2011-04-25 12:52:49 -0500 | [diff] [blame] | 1100 | rtlpriv->dm.txpower_trackinginit = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1101 | |
| 1102 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1103 | "pMgntInfo->txpower_tracking = %d\n", |
| 1104 | rtlpriv->dm.txpower_tracking); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | static void rtl92c_dm_initialize_txpower_tracking(struct ieee80211_hw *hw) |
| 1108 | { |
| 1109 | rtl92c_dm_initialize_txpower_tracking_thermalmeter(hw); |
| 1110 | } |
| 1111 | |
| 1112 | static void rtl92c_dm_txpower_tracking_directcall(struct ieee80211_hw *hw) |
| 1113 | { |
| 1114 | rtl92c_dm_txpower_tracking_callback_thermalmeter(hw); |
| 1115 | } |
| 1116 | |
| 1117 | static void rtl92c_dm_check_txpower_tracking_thermal_meter( |
| 1118 | struct ieee80211_hw *hw) |
| 1119 | { |
| 1120 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1121 | static u8 tm_trigger; |
| 1122 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1123 | if (!rtlpriv->dm.txpower_tracking) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1124 | return; |
| 1125 | |
| 1126 | if (!tm_trigger) { |
| 1127 | rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER, RFREG_OFFSET_MASK, |
| 1128 | 0x60); |
| 1129 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1130 | "Trigger 92S Thermal Meter!!\n"); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1131 | tm_trigger = 1; |
| 1132 | return; |
| 1133 | } else { |
| 1134 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1135 | "Schedule TxPowerTracking direct call!!\n"); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1136 | rtl92c_dm_txpower_tracking_directcall(hw); |
| 1137 | tm_trigger = 0; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | void rtl92c_dm_check_txpower_tracking(struct ieee80211_hw *hw) |
| 1142 | { |
| 1143 | rtl92c_dm_check_txpower_tracking_thermal_meter(hw); |
| 1144 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1145 | EXPORT_SYMBOL(rtl92c_dm_check_txpower_tracking); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1146 | |
| 1147 | void rtl92c_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw) |
| 1148 | { |
| 1149 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1150 | struct rate_adaptive *p_ra = &(rtlpriv->ra); |
| 1151 | |
| 1152 | p_ra->ratr_state = DM_RATR_STA_INIT; |
| 1153 | p_ra->pre_ratr_state = DM_RATR_STA_INIT; |
| 1154 | |
| 1155 | if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER) |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1156 | rtlpriv->dm.useramask = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1157 | else |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1158 | rtlpriv->dm.useramask = false; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1159 | |
| 1160 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1161 | EXPORT_SYMBOL(rtl92c_dm_init_rate_adaptive_mask); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1162 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1163 | static void rtl92c_dm_init_dynamic_bb_powersaving(struct ieee80211_hw *hw) |
| 1164 | { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1165 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1166 | struct ps_t *dm_pstable = &rtlpriv->dm_pstable; |
| 1167 | |
| 1168 | dm_pstable->pre_ccastate = CCA_MAX; |
| 1169 | dm_pstable->cur_ccasate = CCA_MAX; |
| 1170 | dm_pstable->pre_rfstate = RF_MAX; |
| 1171 | dm_pstable->cur_rfstate = RF_MAX; |
| 1172 | dm_pstable->rssi_val_min = 0; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1173 | } |
| 1174 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1175 | void rtl92c_dm_rf_saving(struct ieee80211_hw *hw, u8 bforce_in_normal) |
| 1176 | { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1177 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1178 | struct ps_t *dm_pstable = &rtlpriv->dm_pstable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1179 | static u8 initialize; |
| 1180 | static u32 reg_874, reg_c70, reg_85c, reg_a74; |
| 1181 | |
| 1182 | if (initialize == 0) { |
| 1183 | reg_874 = (rtl_get_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, |
| 1184 | MASKDWORD) & 0x1CC000) >> 14; |
| 1185 | |
| 1186 | reg_c70 = (rtl_get_bbreg(hw, ROFDM0_AGCPARAMETER1, |
| 1187 | MASKDWORD) & BIT(3)) >> 3; |
| 1188 | |
| 1189 | reg_85c = (rtl_get_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL, |
| 1190 | MASKDWORD) & 0xFF000000) >> 24; |
| 1191 | |
| 1192 | reg_a74 = (rtl_get_bbreg(hw, 0xa74, MASKDWORD) & 0xF000) >> 12; |
| 1193 | |
| 1194 | initialize = 1; |
| 1195 | } |
| 1196 | |
| 1197 | if (!bforce_in_normal) { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1198 | if (dm_pstable->rssi_val_min != 0) { |
| 1199 | if (dm_pstable->pre_rfstate == RF_NORMAL) { |
| 1200 | if (dm_pstable->rssi_val_min >= 30) |
| 1201 | dm_pstable->cur_rfstate = RF_SAVE; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1202 | else |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1203 | dm_pstable->cur_rfstate = RF_NORMAL; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1204 | } else { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1205 | if (dm_pstable->rssi_val_min <= 25) |
| 1206 | dm_pstable->cur_rfstate = RF_NORMAL; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1207 | else |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1208 | dm_pstable->cur_rfstate = RF_SAVE; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1209 | } |
| 1210 | } else { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1211 | dm_pstable->cur_rfstate = RF_MAX; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1212 | } |
| 1213 | } else { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1214 | dm_pstable->cur_rfstate = RF_NORMAL; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1215 | } |
| 1216 | |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1217 | if (dm_pstable->pre_rfstate != dm_pstable->cur_rfstate) { |
| 1218 | if (dm_pstable->cur_rfstate == RF_SAVE) { |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1219 | rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, |
| 1220 | 0x1C0000, 0x2); |
| 1221 | rtl_set_bbreg(hw, ROFDM0_AGCPARAMETER1, BIT(3), 0); |
| 1222 | rtl_set_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL, |
| 1223 | 0xFF000000, 0x63); |
| 1224 | rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, |
| 1225 | 0xC000, 0x2); |
| 1226 | rtl_set_bbreg(hw, 0xa74, 0xF000, 0x3); |
| 1227 | rtl_set_bbreg(hw, 0x818, BIT(28), 0x0); |
| 1228 | rtl_set_bbreg(hw, 0x818, BIT(28), 0x1); |
| 1229 | } else { |
| 1230 | rtl_set_bbreg(hw, RFPGA0_XCD_RFINTERFACESW, |
| 1231 | 0x1CC000, reg_874); |
| 1232 | rtl_set_bbreg(hw, ROFDM0_AGCPARAMETER1, BIT(3), |
| 1233 | reg_c70); |
| 1234 | rtl_set_bbreg(hw, RFPGA0_XCD_SWITCHCONTROL, 0xFF000000, |
| 1235 | reg_85c); |
| 1236 | rtl_set_bbreg(hw, 0xa74, 0xF000, reg_a74); |
| 1237 | rtl_set_bbreg(hw, 0x818, BIT(28), 0x0); |
| 1238 | } |
| 1239 | |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1240 | dm_pstable->pre_rfstate = dm_pstable->cur_rfstate; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1241 | } |
| 1242 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1243 | EXPORT_SYMBOL(rtl92c_dm_rf_saving); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1244 | |
| 1245 | static void rtl92c_dm_dynamic_bb_powersaving(struct ieee80211_hw *hw) |
| 1246 | { |
| 1247 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1248 | struct ps_t *dm_pstable = &rtlpriv->dm_pstable; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1249 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1250 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1251 | |
| 1252 | if (((mac->link_state == MAC80211_NOLINK)) && |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1253 | (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1254 | dm_pstable->rssi_val_min = 0; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1255 | RT_TRACE(rtlpriv, DBG_LOUD, DBG_LOUD, "Not connected to any\n"); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | if (mac->link_state == MAC80211_LINKED) { |
| 1259 | if (mac->opmode == NL80211_IFTYPE_ADHOC) { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1260 | dm_pstable->rssi_val_min = |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1261 | rtlpriv->dm.entry_min_undec_sm_pwdb; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1262 | RT_TRACE(rtlpriv, DBG_LOUD, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1263 | "AP Client PWDB = 0x%lx\n", |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1264 | dm_pstable->rssi_val_min); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1265 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1266 | dm_pstable->rssi_val_min = rtlpriv->dm.undec_sm_pwdb; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1267 | RT_TRACE(rtlpriv, DBG_LOUD, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1268 | "STA Default Port PWDB = 0x%lx\n", |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1269 | dm_pstable->rssi_val_min); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1270 | } |
| 1271 | } else { |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1272 | dm_pstable->rssi_val_min = |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1273 | rtlpriv->dm.entry_min_undec_sm_pwdb; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1274 | |
| 1275 | RT_TRACE(rtlpriv, DBG_LOUD, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1276 | "AP Ext Port PWDB = 0x%lx\n", |
Larry Finger | d10dc6d | 2012-04-19 16:32:42 -0500 | [diff] [blame] | 1277 | dm_pstable->rssi_val_min); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | if (IS_92C_SERIAL(rtlhal->version)) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1281 | ;/* rtl92c_dm_1r_cca(hw); */ |
| 1282 | else |
| 1283 | rtl92c_dm_rf_saving(hw, false); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | void rtl92c_dm_init(struct ieee80211_hw *hw) |
| 1287 | { |
| 1288 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1289 | |
| 1290 | rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER; |
| 1291 | rtl92c_dm_diginit(hw); |
| 1292 | rtl92c_dm_init_dynamic_txpower(hw); |
| 1293 | rtl92c_dm_init_edca_turbo(hw); |
| 1294 | rtl92c_dm_init_rate_adaptive_mask(hw); |
| 1295 | rtl92c_dm_initialize_txpower_tracking(hw); |
| 1296 | rtl92c_dm_init_dynamic_bb_powersaving(hw); |
| 1297 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1298 | EXPORT_SYMBOL(rtl92c_dm_init); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1299 | |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1300 | void rtl92c_dm_dynamic_txpower(struct ieee80211_hw *hw) |
| 1301 | { |
| 1302 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1303 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 1304 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1305 | long undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1306 | |
| 1307 | if (!rtlpriv->dm.dynamic_txpower_enable) |
| 1308 | return; |
| 1309 | |
| 1310 | if (rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) { |
| 1311 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 1312 | return; |
| 1313 | } |
| 1314 | |
| 1315 | if ((mac->link_state < MAC80211_LINKED) && |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1316 | (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1317 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1318 | "Not connected to any\n"); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1319 | |
| 1320 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 1321 | |
| 1322 | rtlpriv->dm.last_dtp_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 1323 | return; |
| 1324 | } |
| 1325 | |
| 1326 | if (mac->link_state >= MAC80211_LINKED) { |
| 1327 | if (mac->opmode == NL80211_IFTYPE_ADHOC) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1328 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1329 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1330 | "AP Client PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1331 | undec_sm_pwdb); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1332 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1333 | undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1334 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1335 | "STA Default Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1336 | undec_sm_pwdb); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1337 | } |
| 1338 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1339 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1340 | |
| 1341 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1342 | "AP Ext Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1343 | undec_sm_pwdb); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1344 | } |
| 1345 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1346 | if (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL2) { |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1347 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 1348 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1349 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n"); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1350 | } else if ((undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL2 - 3)) && |
| 1351 | (undec_sm_pwdb >= TX_POWER_NEAR_FIELD_THRESH_LVL1)) { |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1352 | |
| 1353 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_LEVEL1; |
| 1354 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1355 | "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n"); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1356 | } else if (undec_sm_pwdb < (TX_POWER_NEAR_FIELD_THRESH_LVL1 - 5)) { |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1357 | rtlpriv->dm.dynamic_txhighpower_lvl = TXHIGHPWRLEVEL_NORMAL; |
| 1358 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1359 | "TXHIGHPWRLEVEL_NORMAL\n"); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) { |
| 1363 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1364 | "PHY_SetTxPowerLevel8192S() Channel = %d\n", |
| 1365 | rtlphy->current_channel); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1366 | rtl92c_phy_set_txpower_level(hw, rtlphy->current_channel); |
| 1367 | } |
| 1368 | |
| 1369 | rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; |
| 1370 | } |
| 1371 | |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1372 | void rtl92c_dm_watchdog(struct ieee80211_hw *hw) |
| 1373 | { |
| 1374 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1375 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1376 | bool fw_current_inpsmode = false; |
| 1377 | bool fw_ps_awake = true; |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1378 | |
| 1379 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS, |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1380 | (u8 *) (&fw_current_inpsmode)); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1381 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_FWLPS_RF_ON, |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1382 | (u8 *) (&fw_ps_awake)); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1383 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1384 | if (ppsc->p2p_ps_info.p2p_ps_mode) |
| 1385 | fw_ps_awake = false; |
| 1386 | |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 1387 | if ((ppsc->rfpwr_state == ERFON) && ((!fw_current_inpsmode) && |
| 1388 | fw_ps_awake) |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1389 | && (!ppsc->rfchange_inprogress)) { |
| 1390 | rtl92c_dm_pwdb_monitor(hw); |
| 1391 | rtl92c_dm_dig(hw); |
| 1392 | rtl92c_dm_false_alarm_counter_statistics(hw); |
| 1393 | rtl92c_dm_dynamic_bb_powersaving(hw); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1394 | rtl92c_dm_dynamic_txpower(hw); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1395 | rtl92c_dm_check_txpower_tracking(hw); |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1396 | /* rtl92c_dm_refresh_rate_adaptive_mask(hw); */ |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1397 | rtl92c_dm_bt_coexist(hw); |
Larry Finger | 8c96fcf | 2011-02-11 14:33:58 -0600 | [diff] [blame] | 1398 | rtl92c_dm_check_edca_turbo(hw); |
| 1399 | } |
| 1400 | } |
Larry Finger | 1472d3a | 2011-02-23 10:24:58 -0600 | [diff] [blame] | 1401 | EXPORT_SYMBOL(rtl92c_dm_watchdog); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1402 | |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 1403 | u8 rtl92c_bt_rssi_state_change(struct ieee80211_hw *hw) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1404 | { |
| 1405 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1406 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1407 | long undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1408 | u8 curr_bt_rssi_state = 0x00; |
| 1409 | |
| 1410 | if (rtlpriv->mac80211.link_state == MAC80211_LINKED) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1411 | undec_sm_pwdb = GET_UNDECORATED_AVERAGE_RSSI(rtlpriv); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1412 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1413 | if (rtlpriv->dm.entry_min_undec_sm_pwdb == 0) |
| 1414 | undec_sm_pwdb = 100; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1415 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1416 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | /* Check RSSI to determine HighPower/NormalPower state for |
| 1420 | * BT coexistence. */ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1421 | if (undec_sm_pwdb >= 67) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1422 | curr_bt_rssi_state &= (~BT_RSSI_STATE_NORMAL_POWER); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1423 | else if (undec_sm_pwdb < 62) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1424 | curr_bt_rssi_state |= BT_RSSI_STATE_NORMAL_POWER; |
| 1425 | |
| 1426 | /* Check RSSI to determine AMPDU setting for BT coexistence. */ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1427 | if (undec_sm_pwdb >= 40) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1428 | curr_bt_rssi_state &= (~BT_RSSI_STATE_AMDPU_OFF); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1429 | else if (undec_sm_pwdb <= 32) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1430 | curr_bt_rssi_state |= BT_RSSI_STATE_AMDPU_OFF; |
| 1431 | |
| 1432 | /* Marked RSSI state. It will be used to determine BT coexistence |
| 1433 | * setting later. */ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1434 | if (undec_sm_pwdb < 35) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1435 | curr_bt_rssi_state |= BT_RSSI_STATE_SPECIAL_LOW; |
| 1436 | else |
| 1437 | curr_bt_rssi_state &= (~BT_RSSI_STATE_SPECIAL_LOW); |
| 1438 | |
| 1439 | /* Set Tx Power according to BT status. */ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1440 | if (undec_sm_pwdb >= 30) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1441 | curr_bt_rssi_state |= BT_RSSI_STATE_TXPOWER_LOW; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1442 | else if (undec_sm_pwdb < 25) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1443 | curr_bt_rssi_state &= (~BT_RSSI_STATE_TXPOWER_LOW); |
| 1444 | |
| 1445 | /* Check BT state related to BT_Idle in B/G mode. */ |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 1446 | if (undec_sm_pwdb < 15) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1447 | curr_bt_rssi_state |= BT_RSSI_STATE_BG_EDCA_LOW; |
| 1448 | else |
| 1449 | curr_bt_rssi_state &= (~BT_RSSI_STATE_BG_EDCA_LOW); |
| 1450 | |
| 1451 | if (curr_bt_rssi_state != rtlpcipriv->bt_coexist.bt_rssi_state) { |
| 1452 | rtlpcipriv->bt_coexist.bt_rssi_state = curr_bt_rssi_state; |
| 1453 | return true; |
| 1454 | } else { |
| 1455 | return false; |
| 1456 | } |
| 1457 | } |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 1458 | EXPORT_SYMBOL(rtl92c_bt_rssi_state_change); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1459 | |
| 1460 | static bool rtl92c_bt_state_change(struct ieee80211_hw *hw) |
| 1461 | { |
| 1462 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1463 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
| 1464 | |
| 1465 | u32 polling, ratio_tx, ratio_pri; |
| 1466 | u32 bt_tx, bt_pri; |
| 1467 | u8 bt_state; |
| 1468 | u8 cur_service_type; |
| 1469 | |
| 1470 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) |
| 1471 | return false; |
| 1472 | |
| 1473 | bt_state = rtl_read_byte(rtlpriv, 0x4fd); |
| 1474 | bt_tx = rtl_read_dword(rtlpriv, 0x488); |
| 1475 | bt_tx = bt_tx & 0x00ffffff; |
| 1476 | bt_pri = rtl_read_dword(rtlpriv, 0x48c); |
| 1477 | bt_pri = bt_pri & 0x00ffffff; |
| 1478 | polling = rtl_read_dword(rtlpriv, 0x490); |
| 1479 | |
| 1480 | if (bt_tx == 0xffffffff && bt_pri == 0xffffffff && |
| 1481 | polling == 0xffffffff && bt_state == 0xff) |
| 1482 | return false; |
| 1483 | |
| 1484 | bt_state &= BIT_OFFSET_LEN_MASK_32(0, 1); |
| 1485 | if (bt_state != rtlpcipriv->bt_coexist.bt_cur_state) { |
| 1486 | rtlpcipriv->bt_coexist.bt_cur_state = bt_state; |
| 1487 | |
| 1488 | if (rtlpcipriv->bt_coexist.reg_bt_sco == 3) { |
| 1489 | rtlpcipriv->bt_coexist.bt_service = BT_IDLE; |
| 1490 | |
| 1491 | bt_state = bt_state | |
| 1492 | ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ? |
| 1493 | 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) | |
| 1494 | BIT_OFFSET_LEN_MASK_32(2, 1); |
| 1495 | rtl_write_byte(rtlpriv, 0x4fd, bt_state); |
| 1496 | } |
| 1497 | return true; |
| 1498 | } |
| 1499 | |
| 1500 | ratio_tx = bt_tx * 1000 / polling; |
| 1501 | ratio_pri = bt_pri * 1000 / polling; |
| 1502 | rtlpcipriv->bt_coexist.ratio_tx = ratio_tx; |
| 1503 | rtlpcipriv->bt_coexist.ratio_pri = ratio_pri; |
| 1504 | |
| 1505 | if (bt_state && rtlpcipriv->bt_coexist.reg_bt_sco == 3) { |
| 1506 | |
| 1507 | if ((ratio_tx < 30) && (ratio_pri < 30)) |
| 1508 | cur_service_type = BT_IDLE; |
| 1509 | else if ((ratio_pri > 110) && (ratio_pri < 250)) |
| 1510 | cur_service_type = BT_SCO; |
| 1511 | else if ((ratio_tx >= 200) && (ratio_pri >= 200)) |
| 1512 | cur_service_type = BT_BUSY; |
| 1513 | else if ((ratio_tx >= 350) && (ratio_tx < 500)) |
| 1514 | cur_service_type = BT_OTHERBUSY; |
| 1515 | else if (ratio_tx >= 500) |
| 1516 | cur_service_type = BT_PAN; |
| 1517 | else |
| 1518 | cur_service_type = BT_OTHER_ACTION; |
| 1519 | |
| 1520 | if (cur_service_type != rtlpcipriv->bt_coexist.bt_service) { |
| 1521 | rtlpcipriv->bt_coexist.bt_service = cur_service_type; |
| 1522 | bt_state = bt_state | |
| 1523 | ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ? |
| 1524 | 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) | |
| 1525 | ((rtlpcipriv->bt_coexist.bt_service != BT_IDLE) ? |
| 1526 | 0 : BIT_OFFSET_LEN_MASK_32(2, 1)); |
| 1527 | |
| 1528 | /* Add interrupt migration when bt is not ini |
| 1529 | * idle state (no traffic). */ |
| 1530 | if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) { |
| 1531 | rtl_write_word(rtlpriv, 0x504, 0x0ccc); |
| 1532 | rtl_write_byte(rtlpriv, 0x506, 0x54); |
| 1533 | rtl_write_byte(rtlpriv, 0x507, 0x54); |
| 1534 | } else { |
| 1535 | rtl_write_byte(rtlpriv, 0x506, 0x00); |
| 1536 | rtl_write_byte(rtlpriv, 0x507, 0x00); |
| 1537 | } |
| 1538 | |
| 1539 | rtl_write_byte(rtlpriv, 0x4fd, bt_state); |
| 1540 | return true; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | return false; |
| 1545 | |
| 1546 | } |
| 1547 | |
| 1548 | static bool rtl92c_bt_wifi_connect_change(struct ieee80211_hw *hw) |
| 1549 | { |
| 1550 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1551 | static bool media_connect; |
| 1552 | |
| 1553 | if (rtlpriv->mac80211.link_state < MAC80211_LINKED) { |
| 1554 | media_connect = false; |
| 1555 | } else { |
| 1556 | if (!media_connect) { |
| 1557 | media_connect = true; |
| 1558 | return true; |
| 1559 | } |
| 1560 | media_connect = true; |
| 1561 | } |
| 1562 | |
| 1563 | return false; |
| 1564 | } |
| 1565 | |
| 1566 | static void rtl92c_bt_set_normal(struct ieee80211_hw *hw) |
| 1567 | { |
| 1568 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1569 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
| 1570 | |
| 1571 | |
| 1572 | if (rtlpcipriv->bt_coexist.bt_service == BT_OTHERBUSY) { |
| 1573 | rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea72b; |
| 1574 | rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea72b; |
| 1575 | } else if (rtlpcipriv->bt_coexist.bt_service == BT_BUSY) { |
| 1576 | rtlpcipriv->bt_coexist.bt_edca_ul = 0x5eb82f; |
| 1577 | rtlpcipriv->bt_coexist.bt_edca_dl = 0x5eb82f; |
| 1578 | } else if (rtlpcipriv->bt_coexist.bt_service == BT_SCO) { |
| 1579 | if (rtlpcipriv->bt_coexist.ratio_tx > 160) { |
| 1580 | rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea72f; |
| 1581 | rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea72f; |
| 1582 | } else { |
| 1583 | rtlpcipriv->bt_coexist.bt_edca_ul = 0x5ea32b; |
| 1584 | rtlpcipriv->bt_coexist.bt_edca_dl = 0x5ea42b; |
| 1585 | } |
| 1586 | } else { |
| 1587 | rtlpcipriv->bt_coexist.bt_edca_ul = 0; |
| 1588 | rtlpcipriv->bt_coexist.bt_edca_dl = 0; |
| 1589 | } |
| 1590 | |
| 1591 | if ((rtlpcipriv->bt_coexist.bt_service != BT_IDLE) && |
| 1592 | (rtlpriv->mac80211.mode == WIRELESS_MODE_G || |
| 1593 | (rtlpriv->mac80211.mode == (WIRELESS_MODE_G | WIRELESS_MODE_B))) && |
| 1594 | (rtlpcipriv->bt_coexist.bt_rssi_state & |
| 1595 | BT_RSSI_STATE_BG_EDCA_LOW)) { |
| 1596 | rtlpcipriv->bt_coexist.bt_edca_ul = 0x5eb82b; |
| 1597 | rtlpcipriv->bt_coexist.bt_edca_dl = 0x5eb82b; |
| 1598 | } |
| 1599 | } |
| 1600 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1601 | static void rtl92c_bt_ant_isolation(struct ieee80211_hw *hw, u8 tmp1byte) |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1602 | { |
| 1603 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1604 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
| 1605 | |
| 1606 | |
| 1607 | /* Only enable HW BT coexist when BT in "Busy" state. */ |
| 1608 | if (rtlpriv->mac80211.vendor == PEER_CISCO && |
| 1609 | rtlpcipriv->bt_coexist.bt_service == BT_OTHER_ACTION) { |
| 1610 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0); |
| 1611 | } else { |
| 1612 | if ((rtlpcipriv->bt_coexist.bt_service == BT_BUSY) && |
| 1613 | (rtlpcipriv->bt_coexist.bt_rssi_state & |
| 1614 | BT_RSSI_STATE_NORMAL_POWER)) { |
| 1615 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0); |
| 1616 | } else if ((rtlpcipriv->bt_coexist.bt_service == |
| 1617 | BT_OTHER_ACTION) && (rtlpriv->mac80211.mode < |
| 1618 | WIRELESS_MODE_N_24G) && |
| 1619 | (rtlpcipriv->bt_coexist.bt_rssi_state & |
| 1620 | BT_RSSI_STATE_SPECIAL_LOW)) { |
| 1621 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0); |
| 1622 | } else if (rtlpcipriv->bt_coexist.bt_service == BT_PAN) { |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1623 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, tmp1byte); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1624 | } else { |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1625 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, tmp1byte); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | if (rtlpcipriv->bt_coexist.bt_service == BT_PAN) |
| 1630 | rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x10100); |
| 1631 | else |
| 1632 | rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x0); |
| 1633 | |
| 1634 | if (rtlpcipriv->bt_coexist.bt_rssi_state & |
| 1635 | BT_RSSI_STATE_NORMAL_POWER) { |
| 1636 | rtl92c_bt_set_normal(hw); |
| 1637 | } else { |
| 1638 | rtlpcipriv->bt_coexist.bt_edca_ul = 0; |
| 1639 | rtlpcipriv->bt_coexist.bt_edca_dl = 0; |
| 1640 | } |
| 1641 | |
| 1642 | if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) { |
| 1643 | rtlpriv->cfg->ops->set_rfreg(hw, |
| 1644 | RF90_PATH_A, |
| 1645 | 0x1e, |
| 1646 | 0xf0, 0xf); |
| 1647 | } else { |
| 1648 | rtlpriv->cfg->ops->set_rfreg(hw, |
| 1649 | RF90_PATH_A, 0x1e, 0xf0, |
| 1650 | rtlpcipriv->bt_coexist.bt_rfreg_origin_1e); |
| 1651 | } |
| 1652 | |
| 1653 | if (!rtlpriv->dm.dynamic_txpower_enable) { |
| 1654 | if (rtlpcipriv->bt_coexist.bt_service != BT_IDLE) { |
| 1655 | if (rtlpcipriv->bt_coexist.bt_rssi_state & |
| 1656 | BT_RSSI_STATE_TXPOWER_LOW) { |
| 1657 | rtlpriv->dm.dynamic_txhighpower_lvl = |
| 1658 | TXHIGHPWRLEVEL_BT2; |
| 1659 | } else { |
| 1660 | rtlpriv->dm.dynamic_txhighpower_lvl = |
| 1661 | TXHIGHPWRLEVEL_BT1; |
| 1662 | } |
| 1663 | } else { |
| 1664 | rtlpriv->dm.dynamic_txhighpower_lvl = |
| 1665 | TXHIGHPWRLEVEL_NORMAL; |
| 1666 | } |
| 1667 | rtl92c_phy_set_txpower_level(hw, |
| 1668 | rtlpriv->phy.current_channel); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | static void rtl92c_check_bt_change(struct ieee80211_hw *hw) |
| 1673 | { |
| 1674 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1675 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1676 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1677 | u8 tmp1byte = 0; |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1678 | |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1679 | if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version) && |
| 1680 | rtlpcipriv->bt_coexist.bt_coexistence) |
| 1681 | tmp1byte |= BIT(5); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1682 | if (rtlpcipriv->bt_coexist.bt_cur_state) { |
| 1683 | if (rtlpcipriv->bt_coexist.bt_ant_isolation) |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1684 | rtl92c_bt_ant_isolation(hw, tmp1byte); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1685 | } else { |
Larry Finger | 3a16b41 | 2013-03-24 22:06:40 -0500 | [diff] [blame] | 1686 | rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, tmp1byte); |
Chaoming_Li | beb5bc4 | 2011-04-25 12:53:35 -0500 | [diff] [blame] | 1687 | rtlpriv->cfg->ops->set_rfreg(hw, RF90_PATH_A, 0x1e, 0xf0, |
| 1688 | rtlpcipriv->bt_coexist.bt_rfreg_origin_1e); |
| 1689 | |
| 1690 | rtlpcipriv->bt_coexist.bt_edca_ul = 0; |
| 1691 | rtlpcipriv->bt_coexist.bt_edca_dl = 0; |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | void rtl92c_dm_bt_coexist(struct ieee80211_hw *hw) |
| 1696 | { |
| 1697 | struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw); |
| 1698 | |
| 1699 | bool wifi_connect_change; |
| 1700 | bool bt_state_change; |
| 1701 | bool rssi_state_change; |
| 1702 | |
| 1703 | if ((rtlpcipriv->bt_coexist.bt_coexistence) && |
| 1704 | (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) { |
| 1705 | |
| 1706 | wifi_connect_change = rtl92c_bt_wifi_connect_change(hw); |
| 1707 | bt_state_change = rtl92c_bt_state_change(hw); |
| 1708 | rssi_state_change = rtl92c_bt_rssi_state_change(hw); |
| 1709 | |
| 1710 | if (wifi_connect_change || bt_state_change || rssi_state_change) |
| 1711 | rtl92c_check_bt_change(hw); |
| 1712 | } |
| 1713 | } |
Chaoming_Li | 2b8359f | 2011-04-25 12:53:55 -0500 | [diff] [blame] | 1714 | EXPORT_SYMBOL(rtl92c_dm_bt_coexist); |