Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | a8d7606 | 2012-01-07 20:46:42 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 14 | * The full GNU General Public License is included in this distribution in the |
| 15 | * file called LICENSE. |
| 16 | * |
| 17 | * Contact Information: |
| 18 | * wlanfae <wlanfae@realtek.com> |
| 19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 20 | * Hsinchu 300, Taiwan. |
| 21 | * |
| 22 | * Larry Finger <Larry.Finger@lwfinger.net> |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 23 | * |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 24 | *****************************************************************************/ |
| 25 | |
| 26 | #include "wifi.h" |
| 27 | #include "core.h" |
| 28 | #include "cam.h" |
| 29 | #include "base.h" |
| 30 | #include "ps.h" |
Larry Finger | 34ed780 | 2014-09-22 09:39:27 -0500 | [diff] [blame] | 31 | #include "pwrseqcmd.h" |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 32 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 33 | #include "btcoexist/rtl_btc.h" |
| 34 | #include <linux/firmware.h> |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 35 | #include <linux/export.h> |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 36 | #include <net/cfg80211.h> |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 37 | |
Larry Finger | 25b13db | 2014-03-04 16:53:48 -0600 | [diff] [blame] | 38 | void rtl_addr_delay(u32 addr) |
| 39 | { |
| 40 | if (addr == 0xfe) |
| 41 | mdelay(50); |
| 42 | else if (addr == 0xfd) |
| 43 | mdelay(5); |
| 44 | else if (addr == 0xfc) |
| 45 | mdelay(1); |
| 46 | else if (addr == 0xfb) |
| 47 | udelay(50); |
| 48 | else if (addr == 0xfa) |
| 49 | udelay(5); |
| 50 | else if (addr == 0xf9) |
| 51 | udelay(1); |
| 52 | } |
| 53 | EXPORT_SYMBOL(rtl_addr_delay); |
| 54 | |
| 55 | void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr, |
| 56 | u32 mask, u32 data) |
| 57 | { |
| 58 | if (addr == 0xfe) { |
| 59 | mdelay(50); |
| 60 | } else if (addr == 0xfd) { |
| 61 | mdelay(5); |
| 62 | } else if (addr == 0xfc) { |
| 63 | mdelay(1); |
| 64 | } else if (addr == 0xfb) { |
| 65 | udelay(50); |
| 66 | } else if (addr == 0xfa) { |
| 67 | udelay(5); |
| 68 | } else if (addr == 0xf9) { |
| 69 | udelay(1); |
| 70 | } else { |
| 71 | rtl_set_rfreg(hw, rfpath, addr, mask, data); |
| 72 | udelay(1); |
| 73 | } |
| 74 | } |
| 75 | EXPORT_SYMBOL(rtl_rfreg_delay); |
| 76 | |
| 77 | void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data) |
| 78 | { |
| 79 | if (addr == 0xfe) { |
| 80 | mdelay(50); |
| 81 | } else if (addr == 0xfd) { |
| 82 | mdelay(5); |
| 83 | } else if (addr == 0xfc) { |
| 84 | mdelay(1); |
| 85 | } else if (addr == 0xfb) { |
| 86 | udelay(50); |
| 87 | } else if (addr == 0xfa) { |
| 88 | udelay(5); |
| 89 | } else if (addr == 0xf9) { |
| 90 | udelay(1); |
| 91 | } else { |
| 92 | rtl_set_bbreg(hw, addr, MASKDWORD, data); |
| 93 | udelay(1); |
| 94 | } |
| 95 | } |
| 96 | EXPORT_SYMBOL(rtl_bb_delay); |
| 97 | |
Troy Tan | fe89707 | 2014-12-18 03:05:25 -0600 | [diff] [blame] | 98 | static void rtl_fw_do_work(const struct firmware *firmware, void *context, |
| 99 | bool is_wow) |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 100 | { |
| 101 | struct ieee80211_hw *hw = context; |
| 102 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 103 | int err; |
| 104 | |
| 105 | RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 106 | "Firmware callback routine entered!\n"); |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 107 | complete(&rtlpriv->firmware_loading_complete); |
| 108 | if (!firmware) { |
Larry Finger | 62009b7 | 2013-11-18 11:11:26 -0600 | [diff] [blame] | 109 | if (rtlpriv->cfg->alt_fw_name) { |
| 110 | err = request_firmware(&firmware, |
| 111 | rtlpriv->cfg->alt_fw_name, |
| 112 | rtlpriv->io.dev); |
| 113 | pr_info("Loading alternative firmware %s\n", |
| 114 | rtlpriv->cfg->alt_fw_name); |
| 115 | if (!err) |
| 116 | goto found_alt; |
| 117 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 118 | pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name); |
| 119 | rtlpriv->max_fw_size = 0; |
| 120 | return; |
| 121 | } |
Larry Finger | 62009b7 | 2013-11-18 11:11:26 -0600 | [diff] [blame] | 122 | found_alt: |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 123 | if (firmware->size > rtlpriv->max_fw_size) { |
| 124 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 125 | "Firmware is too big!\n"); |
| 126 | release_firmware(firmware); |
| 127 | return; |
| 128 | } |
Troy Tan | fe89707 | 2014-12-18 03:05:25 -0600 | [diff] [blame] | 129 | if (!is_wow) { |
| 130 | memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, |
| 131 | firmware->size); |
| 132 | rtlpriv->rtlhal.fwsize = firmware->size; |
| 133 | } else { |
| 134 | memcpy(rtlpriv->rtlhal.wowlan_firmware, firmware->data, |
| 135 | firmware->size); |
| 136 | rtlpriv->rtlhal.wowlan_fwsize = firmware->size; |
| 137 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 138 | rtlpriv->rtlhal.fwsize = firmware->size; |
| 139 | release_firmware(firmware); |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 140 | } |
Troy Tan | fe89707 | 2014-12-18 03:05:25 -0600 | [diff] [blame] | 141 | |
| 142 | void rtl_fw_cb(const struct firmware *firmware, void *context) |
| 143 | { |
| 144 | rtl_fw_do_work(firmware, context, false); |
| 145 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 146 | EXPORT_SYMBOL(rtl_fw_cb); |
| 147 | |
Troy Tan | fe89707 | 2014-12-18 03:05:25 -0600 | [diff] [blame] | 148 | void rtl_wowlan_fw_cb(const struct firmware *firmware, void *context) |
| 149 | { |
| 150 | rtl_fw_do_work(firmware, context, true); |
| 151 | } |
| 152 | EXPORT_SYMBOL(rtl_wowlan_fw_cb); |
| 153 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 154 | /*mutex for start & stop is must here. */ |
| 155 | static int rtl_op_start(struct ieee80211_hw *hw) |
| 156 | { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 157 | int err = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 158 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 159 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 160 | |
| 161 | if (!is_hal_stop(rtlhal)) |
| 162 | return 0; |
| 163 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 164 | return 0; |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 165 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 166 | err = rtlpriv->intf_ops->adapter_start(hw); |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 167 | if (!err) |
| 168 | rtl_watch_dog_timer_callback((unsigned long)hw); |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 169 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 170 | return err; |
| 171 | } |
| 172 | |
| 173 | static void rtl_op_stop(struct ieee80211_hw *hw) |
| 174 | { |
| 175 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 176 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 177 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 178 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 179 | bool support_remote_wakeup = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 180 | |
| 181 | if (is_hal_stop(rtlhal)) |
| 182 | return; |
| 183 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 184 | rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN, |
| 185 | (u8 *)(&support_remote_wakeup)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 186 | /* here is must, because adhoc do stop and start, |
| 187 | * but stop with RFOFF may cause something wrong, |
| 188 | * like adhoc TP |
| 189 | */ |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 190 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 191 | rtl_ips_nic_on(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 192 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 193 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 194 | /* if wowlan supported, DON'T clear connected info */ |
| 195 | if (!(support_remote_wakeup && |
| 196 | rtlhal->enter_pnp_sleep)) { |
| 197 | mac->link_state = MAC80211_NOLINK; |
| 198 | memset(mac->bssid, 0, 6); |
| 199 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 200 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 201 | /* reset sec info */ |
| 202 | rtl_cam_reset_sec_info(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 203 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 204 | rtl_deinit_deferred_work(hw); |
| 205 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 206 | rtlpriv->intf_ops->adapter_stop(hw); |
| 207 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 208 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 211 | static void rtl_op_tx(struct ieee80211_hw *hw, |
| 212 | struct ieee80211_tx_control *control, |
| 213 | struct sk_buff *skb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 214 | { |
| 215 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 216 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 217 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 218 | struct rtl_tcb_desc tcb_desc; |
| 219 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 220 | |
| 221 | if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON)) |
| 222 | goto err_free; |
| 223 | |
| 224 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 225 | goto err_free; |
| 226 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 227 | if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb)) |
| 228 | rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 229 | return; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 230 | |
| 231 | err_free: |
| 232 | dev_kfree_skb_any(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static int rtl_op_add_interface(struct ieee80211_hw *hw, |
| 236 | struct ieee80211_vif *vif) |
| 237 | { |
| 238 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 239 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 240 | int err = 0; |
| 241 | |
| 242 | if (mac->vif) { |
| 243 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 244 | "vif has been set!! mac->vif = 0x%p\n", mac->vif); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 245 | return -EOPNOTSUPP; |
| 246 | } |
| 247 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 248 | vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER; |
| 249 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 250 | rtl_ips_nic_on(hw); |
| 251 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 252 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 253 | switch (ieee80211_vif_type_p2p(vif)) { |
| 254 | case NL80211_IFTYPE_P2P_CLIENT: |
| 255 | mac->p2p = P2P_ROLE_CLIENT; |
| 256 | /*fall through*/ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 257 | case NL80211_IFTYPE_STATION: |
| 258 | if (mac->beacon_enabled == 1) { |
| 259 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 260 | "NL80211_IFTYPE_STATION\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 261 | mac->beacon_enabled = 0; |
| 262 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 263 | rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 264 | } |
| 265 | break; |
| 266 | case NL80211_IFTYPE_ADHOC: |
| 267 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 268 | "NL80211_IFTYPE_ADHOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 269 | |
| 270 | mac->link_state = MAC80211_LINKED; |
| 271 | rtlpriv->cfg->ops->set_bcn_reg(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 272 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
| 273 | mac->basic_rates = 0xfff; |
| 274 | else |
| 275 | mac->basic_rates = 0xff0; |
| 276 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 277 | (u8 *)(&mac->basic_rates)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 278 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 279 | break; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 280 | case NL80211_IFTYPE_P2P_GO: |
| 281 | mac->p2p = P2P_ROLE_GO; |
| 282 | /*fall through*/ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 283 | case NL80211_IFTYPE_AP: |
| 284 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 285 | "NL80211_IFTYPE_AP\n"); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 286 | |
| 287 | mac->link_state = MAC80211_LINKED; |
| 288 | rtlpriv->cfg->ops->set_bcn_reg(hw); |
| 289 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
| 290 | mac->basic_rates = 0xfff; |
| 291 | else |
| 292 | mac->basic_rates = 0xff0; |
| 293 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 294 | (u8 *)(&mac->basic_rates)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 295 | break; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 296 | case NL80211_IFTYPE_MESH_POINT: |
| 297 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 298 | "NL80211_IFTYPE_MESH_POINT\n"); |
| 299 | |
| 300 | mac->link_state = MAC80211_LINKED; |
| 301 | rtlpriv->cfg->ops->set_bcn_reg(hw); |
| 302 | if (rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G) |
| 303 | mac->basic_rates = 0xfff; |
| 304 | else |
| 305 | mac->basic_rates = 0xff0; |
| 306 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
| 307 | (u8 *)(&mac->basic_rates)); |
| 308 | break; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 309 | default: |
| 310 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 311 | "operation mode %d is not support!\n", vif->type); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 312 | err = -EOPNOTSUPP; |
| 313 | goto out; |
| 314 | } |
| 315 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 316 | if (mac->p2p) { |
| 317 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 318 | "p2p role %x\n", vif->type); |
| 319 | mac->basic_rates = 0xff0;/*disable cck rate for p2p*/ |
| 320 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
| 321 | (u8 *)(&mac->basic_rates)); |
| 322 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 323 | mac->vif = vif; |
| 324 | mac->opmode = vif->type; |
| 325 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); |
| 326 | memcpy(mac->mac_addr, vif->addr, ETH_ALEN); |
| 327 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); |
| 328 | |
| 329 | out: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 330 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 331 | return err; |
| 332 | } |
| 333 | |
| 334 | static void rtl_op_remove_interface(struct ieee80211_hw *hw, |
| 335 | struct ieee80211_vif *vif) |
| 336 | { |
| 337 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 338 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 339 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 340 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 341 | |
| 342 | /* Free beacon resources */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 343 | if ((vif->type == NL80211_IFTYPE_AP) || |
| 344 | (vif->type == NL80211_IFTYPE_ADHOC) || |
| 345 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 | if (mac->beacon_enabled == 1) { |
| 347 | mac->beacon_enabled = 0; |
| 348 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 349 | rtlpriv->cfg->maps[RTL_IBSS_INT_MASKS]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | *Note: We assume NL80211_IFTYPE_UNSPECIFIED as |
| 355 | *NO LINK for our hardware. |
| 356 | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 357 | mac->p2p = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 358 | mac->vif = NULL; |
| 359 | mac->link_state = MAC80211_NOLINK; |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 360 | memset(mac->bssid, 0, ETH_ALEN); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 361 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 362 | mac->opmode = NL80211_IFTYPE_UNSPECIFIED; |
| 363 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 364 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 365 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 366 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 367 | static int rtl_op_change_interface(struct ieee80211_hw *hw, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 368 | struct ieee80211_vif *vif, |
| 369 | enum nl80211_iftype new_type, bool p2p) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 370 | { |
| 371 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 372 | int ret; |
| 373 | rtl_op_remove_interface(hw, vif); |
| 374 | |
| 375 | vif->type = new_type; |
| 376 | vif->p2p = p2p; |
| 377 | ret = rtl_op_add_interface(hw, vif); |
| 378 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 379 | "p2p %x\n", p2p); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 380 | return ret; |
| 381 | } |
| 382 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 383 | #ifdef CONFIG_PM |
| 384 | static u16 crc16_ccitt(u8 data, u16 crc) |
| 385 | { |
| 386 | u8 shift_in, data_bit, crc_bit11, crc_bit4, crc_bit15; |
| 387 | u8 i; |
| 388 | u16 result; |
| 389 | |
| 390 | for (i = 0; i < 8; i++) { |
| 391 | crc_bit15 = ((crc & BIT(15)) ? 1 : 0); |
| 392 | data_bit = (data & (BIT(0) << i) ? 1 : 0); |
| 393 | shift_in = crc_bit15 ^ data_bit; |
| 394 | |
| 395 | result = crc << 1; |
| 396 | if (shift_in == 0) |
| 397 | result &= (~BIT(0)); |
| 398 | else |
| 399 | result |= BIT(0); |
| 400 | |
| 401 | crc_bit11 = ((crc & BIT(11)) ? 1 : 0) ^ shift_in; |
| 402 | if (crc_bit11 == 0) |
| 403 | result &= (~BIT(12)); |
| 404 | else |
| 405 | result |= BIT(12); |
| 406 | |
| 407 | crc_bit4 = ((crc & BIT(4)) ? 1 : 0) ^ shift_in; |
| 408 | if (crc_bit4 == 0) |
| 409 | result &= (~BIT(5)); |
| 410 | else |
| 411 | result |= BIT(5); |
| 412 | |
| 413 | crc = result; |
| 414 | } |
| 415 | |
| 416 | return crc; |
| 417 | } |
| 418 | |
| 419 | static u16 _calculate_wol_pattern_crc(u8 *pattern, u16 len) |
| 420 | { |
| 421 | u16 crc = 0xffff; |
| 422 | u32 i; |
| 423 | |
| 424 | for (i = 0; i < len; i++) |
| 425 | crc = crc16_ccitt(pattern[i], crc); |
| 426 | |
| 427 | crc = ~crc; |
| 428 | |
| 429 | return crc; |
| 430 | } |
| 431 | |
| 432 | static void _rtl_add_wowlan_patterns(struct ieee80211_hw *hw, |
| 433 | struct cfg80211_wowlan *wow) |
| 434 | { |
| 435 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 436 | struct rtl_mac *mac = &rtlpriv->mac80211; |
| 437 | struct cfg80211_pkt_pattern *patterns = wow->patterns; |
| 438 | struct rtl_wow_pattern rtl_pattern; |
| 439 | const u8 *pattern_os, *mask_os; |
| 440 | u8 mask[MAX_WOL_BIT_MASK_SIZE] = {0}; |
| 441 | u8 content[MAX_WOL_PATTERN_SIZE] = {0}; |
| 442 | u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 443 | u8 multicast_addr1[2] = {0x33, 0x33}; |
| 444 | u8 multicast_addr2[3] = {0x01, 0x00, 0x5e}; |
| 445 | u8 i, mask_len; |
| 446 | u16 j, len; |
| 447 | |
| 448 | for (i = 0; i < wow->n_patterns; i++) { |
| 449 | memset(&rtl_pattern, 0, sizeof(struct rtl_wow_pattern)); |
| 450 | memset(mask, 0, MAX_WOL_BIT_MASK_SIZE); |
| 451 | if (patterns[i].pattern_len > MAX_WOL_PATTERN_SIZE) { |
| 452 | RT_TRACE(rtlpriv, COMP_POWER, DBG_WARNING, |
| 453 | "Pattern[%d] is too long\n", i); |
| 454 | continue; |
| 455 | } |
| 456 | pattern_os = patterns[i].pattern; |
| 457 | mask_len = DIV_ROUND_UP(patterns[i].pattern_len, 8); |
| 458 | mask_os = patterns[i].mask; |
| 459 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, |
| 460 | "pattern content\n", pattern_os, |
| 461 | patterns[i].pattern_len); |
| 462 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, |
| 463 | "mask content\n", mask_os, mask_len); |
| 464 | /* 1. unicast? multicast? or broadcast? */ |
| 465 | if (memcmp(pattern_os, broadcast_addr, 6) == 0) |
| 466 | rtl_pattern.type = BROADCAST_PATTERN; |
| 467 | else if (memcmp(pattern_os, multicast_addr1, 2) == 0 || |
| 468 | memcmp(pattern_os, multicast_addr2, 3) == 0) |
| 469 | rtl_pattern.type = MULTICAST_PATTERN; |
| 470 | else if (memcmp(pattern_os, mac->mac_addr, 6) == 0) |
| 471 | rtl_pattern.type = UNICAST_PATTERN; |
| 472 | else |
| 473 | rtl_pattern.type = UNKNOWN_TYPE; |
| 474 | |
| 475 | /* 2. translate mask_from_os to mask_for_hw */ |
| 476 | |
| 477 | /****************************************************************************** |
| 478 | * pattern from OS uses 'ethenet frame', like this: |
| 479 | |
| 480 | | 6 | 6 | 2 | 20 | Variable | 4 | |
| 481 | |--------+--------+------+-----------+------------+-----| |
| 482 | | 802.3 Mac Header | IP Header | TCP Packet | FCS | |
| 483 | | DA | SA | Type | |
| 484 | |
| 485 | * BUT, packet catched by our HW is in '802.11 frame', begin from LLC, |
| 486 | |
| 487 | | 24 or 30 | 6 | 2 | 20 | Variable | 4 | |
| 488 | |-------------------+--------+------+-----------+------------+-----| |
| 489 | | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS | |
| 490 | | Others | Tpye | |
| 491 | |
| 492 | * Therefore, we need translate mask_from_OS to mask_to_hw. |
| 493 | * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0, |
| 494 | * because new mask[0~5] means 'SA', but our HW packet begins from LLC, |
| 495 | * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match. |
| 496 | ******************************************************************************/ |
| 497 | |
| 498 | /* Shift 6 bits */ |
| 499 | for (j = 0; j < mask_len - 1; j++) { |
| 500 | mask[j] = mask_os[j] >> 6; |
| 501 | mask[j] |= (mask_os[j + 1] & 0x3F) << 2; |
| 502 | } |
| 503 | mask[j] = (mask_os[j] >> 6) & 0x3F; |
| 504 | /* Set bit 0-5 to zero */ |
| 505 | mask[0] &= 0xC0; |
| 506 | |
| 507 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, |
| 508 | "mask to hw\n", mask, mask_len); |
| 509 | for (j = 0; j < (MAX_WOL_BIT_MASK_SIZE + 1) / 4; j++) { |
| 510 | rtl_pattern.mask[j] = mask[j * 4]; |
| 511 | rtl_pattern.mask[j] |= (mask[j * 4 + 1] << 8); |
| 512 | rtl_pattern.mask[j] |= (mask[j * 4 + 2] << 16); |
| 513 | rtl_pattern.mask[j] |= (mask[j * 4 + 3] << 24); |
| 514 | } |
| 515 | |
| 516 | /* To get the wake up pattern from the mask. |
| 517 | * We do not count first 12 bits which means |
| 518 | * DA[6] and SA[6] in the pattern to match HW design. |
| 519 | */ |
| 520 | len = 0; |
| 521 | for (j = 12; j < patterns[i].pattern_len; j++) { |
| 522 | if ((mask_os[j / 8] >> (j % 8)) & 0x01) { |
| 523 | content[len] = pattern_os[j]; |
| 524 | len++; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | RT_PRINT_DATA(rtlpriv, COMP_POWER, DBG_TRACE, |
| 529 | "pattern to hw\n", content, len); |
| 530 | /* 3. calculate crc */ |
| 531 | rtl_pattern.crc = _calculate_wol_pattern_crc(content, len); |
| 532 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
| 533 | "CRC_Remainder = 0x%x", rtl_pattern.crc); |
| 534 | |
| 535 | /* 4. write crc & mask_for_hw to hw */ |
| 536 | rtlpriv->cfg->ops->add_wowlan_pattern(hw, &rtl_pattern, i); |
| 537 | } |
| 538 | rtl_write_byte(rtlpriv, 0x698, wow->n_patterns); |
| 539 | } |
| 540 | |
| 541 | static int rtl_op_suspend(struct ieee80211_hw *hw, |
| 542 | struct cfg80211_wowlan *wow) |
| 543 | { |
| 544 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 545 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 546 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 547 | struct timeval ts; |
| 548 | |
| 549 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); |
| 550 | if (WARN_ON(!wow)) |
| 551 | return -EINVAL; |
| 552 | |
| 553 | /* to resolve s4 can not wake up*/ |
| 554 | do_gettimeofday(&ts); |
| 555 | rtlhal->last_suspend_sec = ts.tv_sec; |
| 556 | |
| 557 | if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns) |
| 558 | _rtl_add_wowlan_patterns(hw, wow); |
| 559 | |
| 560 | rtlhal->driver_is_goingto_unload = true; |
| 561 | rtlhal->enter_pnp_sleep = true; |
| 562 | |
| 563 | rtl_lps_leave(hw); |
| 564 | rtl_op_stop(hw); |
| 565 | device_set_wakeup_enable(wiphy_dev(hw->wiphy), true); |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | static int rtl_op_resume(struct ieee80211_hw *hw) |
| 570 | { |
| 571 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 572 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
| 573 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 574 | struct timeval ts; |
| 575 | |
| 576 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n"); |
| 577 | rtlhal->driver_is_goingto_unload = false; |
| 578 | rtlhal->enter_pnp_sleep = false; |
| 579 | rtlhal->wake_from_pnp_sleep = true; |
| 580 | |
| 581 | /* to resovle s4 can not wake up*/ |
| 582 | do_gettimeofday(&ts); |
| 583 | if (ts.tv_sec - rtlhal->last_suspend_sec < 5) |
| 584 | return -1; |
| 585 | |
| 586 | rtl_op_start(hw); |
| 587 | device_set_wakeup_enable(wiphy_dev(hw->wiphy), false); |
| 588 | ieee80211_resume_disconnect(mac->vif); |
| 589 | rtlhal->wake_from_pnp_sleep = false; |
| 590 | return 0; |
| 591 | } |
| 592 | #endif |
| 593 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 594 | static int rtl_op_config(struct ieee80211_hw *hw, u32 changed) |
| 595 | { |
| 596 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 597 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 598 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 599 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 600 | struct ieee80211_conf *conf = &hw->conf; |
| 601 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 602 | if (mac->skip_scan) |
| 603 | return 1; |
| 604 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 605 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 606 | if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) { /* BIT(2)*/ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 607 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 608 | "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /*For IPS */ |
| 612 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 613 | if (hw->conf.flags & IEEE80211_CONF_IDLE) |
| 614 | rtl_ips_nic_off(hw); |
| 615 | else |
| 616 | rtl_ips_nic_on(hw); |
| 617 | } else { |
| 618 | /* |
| 619 | *although rfoff may not cause by ips, but we will |
| 620 | *check the reason in set_rf_power_state function |
| 621 | */ |
| 622 | if (unlikely(ppsc->rfpwr_state == ERFOFF)) |
| 623 | rtl_ips_nic_on(hw); |
| 624 | } |
| 625 | |
| 626 | /*For LPS */ |
| 627 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 628 | cancel_delayed_work(&rtlpriv->works.ps_work); |
| 629 | cancel_delayed_work(&rtlpriv->works.ps_rfon_wq); |
| 630 | if (conf->flags & IEEE80211_CONF_PS) { |
| 631 | rtlpriv->psc.sw_ps_enabled = true; |
| 632 | /* sleep here is must, or we may recv the beacon and |
| 633 | * cause mac80211 into wrong ps state, this will cause |
| 634 | * power save nullfunc send fail, and further cause |
| 635 | * pkt loss, So sleep must quickly but not immediatly |
| 636 | * because that will cause nullfunc send by mac80211 |
| 637 | * fail, and cause pkt loss, we have tested that 5mA |
| 638 | * is worked very well */ |
Larry Finger | 3eda95d | 2012-01-31 10:29:22 -0600 | [diff] [blame] | 639 | if (!rtlpriv->psc.multi_buffered) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 640 | queue_delayed_work(rtlpriv->works.rtl_wq, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 641 | &rtlpriv->works.ps_work, |
| 642 | MSECS(5)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 643 | } else { |
| 644 | rtl_swlps_rf_awake(hw); |
| 645 | rtlpriv->psc.sw_ps_enabled = false; |
| 646 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) { |
| 650 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 651 | "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n", |
| 652 | hw->conf.long_frame_max_tx_count); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 653 | mac->retry_long = hw->conf.long_frame_max_tx_count; |
| 654 | mac->retry_short = hw->conf.long_frame_max_tx_count; |
| 655 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 656 | (u8 *)(&hw->conf.long_frame_max_tx_count)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 657 | } |
| 658 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 659 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL && |
| 660 | !rtlpriv->proximity.proxim_on) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 661 | struct ieee80211_channel *channel = hw->conf.chandef.chan; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 662 | enum nl80211_chan_width width = hw->conf.chandef.width; |
| 663 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 664 | u8 wide_chan = (u8) channel->hw_value; |
| 665 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 666 | /* channel_type is for 20&40M */ |
| 667 | if (width < NL80211_CHAN_WIDTH_80) |
| 668 | channel_type = |
| 669 | cfg80211_get_chandef_type(&hw->conf.chandef); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 670 | if (mac->act_scanning) |
| 671 | mac->n_channels++; |
| 672 | |
| 673 | if (rtlpriv->dm.supp_phymode_switch && |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 674 | mac->link_state < MAC80211_LINKED && |
| 675 | !mac->act_scanning) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 676 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 677 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
| 678 | } |
| 679 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 680 | /* |
| 681 | *because we should back channel to |
| 682 | *current_network.chan in in scanning, |
| 683 | *So if set_chan == current_network.chan |
| 684 | *we should set it. |
| 685 | *because mac80211 tell us wrong bw40 |
| 686 | *info for cisco1253 bw20, so we modify |
| 687 | *it here based on UPPER & LOWER |
| 688 | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 689 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 690 | if (width >= NL80211_CHAN_WIDTH_80) { |
| 691 | if (width == NL80211_CHAN_WIDTH_80) { |
| 692 | u32 center = hw->conf.chandef.center_freq1; |
| 693 | u32 primary = |
| 694 | (u32)hw->conf.chandef.chan->center_freq; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 695 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 696 | rtlphy->current_chan_bw = |
| 697 | HT_CHANNEL_WIDTH_80; |
| 698 | mac->bw_80 = true; |
| 699 | mac->bw_40 = true; |
| 700 | if (center > primary) { |
| 701 | mac->cur_80_prime_sc = |
| 702 | PRIME_CHNL_OFFSET_LOWER; |
| 703 | if (center - primary == 10) { |
| 704 | mac->cur_40_prime_sc = |
| 705 | PRIME_CHNL_OFFSET_UPPER; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 706 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 707 | wide_chan += 2; |
| 708 | } else if (center - primary == 30) { |
| 709 | mac->cur_40_prime_sc = |
| 710 | PRIME_CHNL_OFFSET_LOWER; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 711 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 712 | wide_chan += 6; |
| 713 | } |
| 714 | } else { |
| 715 | mac->cur_80_prime_sc = |
| 716 | PRIME_CHNL_OFFSET_UPPER; |
| 717 | if (primary - center == 10) { |
| 718 | mac->cur_40_prime_sc = |
| 719 | PRIME_CHNL_OFFSET_LOWER; |
| 720 | |
| 721 | wide_chan -= 2; |
| 722 | } else if (primary - center == 30) { |
| 723 | mac->cur_40_prime_sc = |
| 724 | PRIME_CHNL_OFFSET_UPPER; |
| 725 | |
| 726 | wide_chan -= 6; |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | } else { |
| 731 | switch (channel_type) { |
| 732 | case NL80211_CHAN_HT20: |
| 733 | case NL80211_CHAN_NO_HT: |
| 734 | /* SC */ |
| 735 | mac->cur_40_prime_sc = |
| 736 | PRIME_CHNL_OFFSET_DONT_CARE; |
| 737 | rtlphy->current_chan_bw = |
| 738 | HT_CHANNEL_WIDTH_20; |
| 739 | mac->bw_40 = false; |
| 740 | mac->bw_80 = false; |
| 741 | break; |
| 742 | case NL80211_CHAN_HT40MINUS: |
| 743 | /* SC */ |
| 744 | mac->cur_40_prime_sc = |
| 745 | PRIME_CHNL_OFFSET_UPPER; |
| 746 | rtlphy->current_chan_bw = |
| 747 | HT_CHANNEL_WIDTH_20_40; |
| 748 | mac->bw_40 = true; |
| 749 | mac->bw_80 = false; |
| 750 | |
| 751 | /*wide channel */ |
| 752 | wide_chan -= 2; |
| 753 | |
| 754 | break; |
| 755 | case NL80211_CHAN_HT40PLUS: |
| 756 | /* SC */ |
| 757 | mac->cur_40_prime_sc = |
| 758 | PRIME_CHNL_OFFSET_LOWER; |
| 759 | rtlphy->current_chan_bw = |
| 760 | HT_CHANNEL_WIDTH_20_40; |
| 761 | mac->bw_40 = true; |
| 762 | mac->bw_80 = false; |
| 763 | |
| 764 | /*wide channel */ |
| 765 | wide_chan += 2; |
| 766 | |
| 767 | break; |
| 768 | default: |
| 769 | mac->bw_40 = false; |
| 770 | mac->bw_80 = false; |
| 771 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 772 | "switch case not processed\n"); |
| 773 | break; |
| 774 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | if (wide_chan <= 0) |
| 778 | wide_chan = 1; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 779 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 780 | /* In scanning, when before we offchannel we may send a ps=1 |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 781 | * null to AP, and then we may send a ps = 0 null to AP quickly, |
| 782 | * but first null may have caused AP to put lots of packet to |
| 783 | * hw tx buffer. These packets must be tx'd before we go off |
| 784 | * channel so we must delay more time to let AP flush these |
| 785 | * packets before going offchannel, or dis-association or |
| 786 | * delete BA will be caused by AP |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 787 | */ |
Mike McCormack | 9c05044 | 2011-06-20 10:44:58 +0900 | [diff] [blame] | 788 | if (rtlpriv->mac80211.offchan_delay) { |
| 789 | rtlpriv->mac80211.offchan_delay = false; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 790 | mdelay(50); |
| 791 | } |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 792 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 793 | rtlphy->current_channel = wide_chan; |
| 794 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 795 | rtlpriv->cfg->ops->switch_channel(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 796 | rtlpriv->cfg->ops->set_channel_access(hw); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 797 | rtlpriv->cfg->ops->set_bw_mode(hw, channel_type); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 798 | } |
| 799 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 800 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | static void rtl_op_configure_filter(struct ieee80211_hw *hw, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 806 | unsigned int changed_flags, |
| 807 | unsigned int *new_flags, u64 multicast) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 808 | { |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 809 | bool update_rcr = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 810 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 811 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 812 | |
| 813 | *new_flags &= RTL_SUPPORTED_FILTERS; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 814 | if (0 == changed_flags) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 815 | return; |
| 816 | |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 817 | /*TODO: we disable broadcase now, so enable here */ |
| 818 | if (changed_flags & FIF_ALLMULTI) { |
| 819 | if (*new_flags & FIF_ALLMULTI) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 820 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AM] | |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 821 | rtlpriv->cfg->maps[MAC_RCR_AB]; |
| 822 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 823 | "Enable receive multicast frame\n"); |
| 824 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 825 | mac->rx_conf &= ~(rtlpriv->cfg->maps[MAC_RCR_AM] | |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 826 | rtlpriv->cfg->maps[MAC_RCR_AB]); |
| 827 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 828 | "Disable receive multicast frame\n"); |
| 829 | } |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 830 | update_rcr = true; |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | if (changed_flags & FIF_FCSFAIL) { |
| 834 | if (*new_flags & FIF_FCSFAIL) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 835 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 836 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 837 | "Enable receive FCS error frame\n"); |
| 838 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 839 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACRC32]; |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 840 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
| 841 | "Disable receive FCS error frame\n"); |
| 842 | } |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 843 | if (!update_rcr) |
| 844 | update_rcr = true; |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 845 | } |
| 846 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 847 | /* if ssid not set to hw don't check bssid |
| 848 | * here just used for linked scanning, & linked |
| 849 | * and nolink check bssid is set in set network_type |
| 850 | */ |
| 851 | if ((changed_flags & FIF_BCN_PRBRESP_PROMISC) && |
| 852 | (mac->link_state >= MAC80211_LINKED)) { |
| 853 | if (mac->opmode != NL80211_IFTYPE_AP && |
| 854 | mac->opmode != NL80211_IFTYPE_MESH_POINT) { |
| 855 | if (*new_flags & FIF_BCN_PRBRESP_PROMISC) |
| 856 | rtlpriv->cfg->ops->set_chk_bssid(hw, false); |
| 857 | else |
| 858 | rtlpriv->cfg->ops->set_chk_bssid(hw, true); |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 859 | if (update_rcr) |
| 860 | update_rcr = false; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 861 | } |
| 862 | } |
Peter Wu | 711f145 | 2014-02-14 19:03:45 +0100 | [diff] [blame] | 863 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 864 | if (changed_flags & FIF_CONTROL) { |
| 865 | if (*new_flags & FIF_CONTROL) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 866 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 867 | |
| 868 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 869 | "Enable receive control frame.\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 870 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 871 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 872 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 873 | "Disable receive control frame.\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 874 | } |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 875 | if (!update_rcr) |
| 876 | update_rcr = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | if (changed_flags & FIF_OTHER_BSS) { |
| 880 | if (*new_flags & FIF_OTHER_BSS) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 881 | mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_AAP]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 882 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 883 | "Enable receive other BSS's frame.\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 884 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 885 | mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_AAP]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 886 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 887 | "Disable receive other BSS's frame.\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 888 | } |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 889 | if (!update_rcr) |
| 890 | update_rcr = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 891 | } |
Lorenzo Bianconi | 9995858 | 2014-11-22 12:18:26 +0100 | [diff] [blame] | 892 | |
| 893 | if (update_rcr) |
| 894 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, |
| 895 | (u8 *)(&mac->rx_conf)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 896 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 897 | static int rtl_op_sta_add(struct ieee80211_hw *hw, |
| 898 | struct ieee80211_vif *vif, |
| 899 | struct ieee80211_sta *sta) |
| 900 | { |
| 901 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 902 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 903 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 904 | struct rtl_sta_info *sta_entry; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 905 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 906 | if (sta) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 907 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 908 | spin_lock_bh(&rtlpriv->locks.entry_list_lock); |
| 909 | list_add_tail(&sta_entry->list, &rtlpriv->entry_list); |
| 910 | spin_unlock_bh(&rtlpriv->locks.entry_list_lock); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 911 | if (rtlhal->current_bandtype == BAND_ON_2_4G) { |
| 912 | sta_entry->wireless_mode = WIRELESS_MODE_G; |
| 913 | if (sta->supp_rates[0] <= 0xf) |
| 914 | sta_entry->wireless_mode = WIRELESS_MODE_B; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 915 | if (sta->ht_cap.ht_supported) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 916 | sta_entry->wireless_mode = WIRELESS_MODE_N_24G; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 917 | |
| 918 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 919 | sta_entry->wireless_mode = WIRELESS_MODE_G; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 920 | } else if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 921 | sta_entry->wireless_mode = WIRELESS_MODE_A; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 922 | if (sta->ht_cap.ht_supported) |
| 923 | sta_entry->wireless_mode = WIRELESS_MODE_N_5G; |
| 924 | if (sta->vht_cap.vht_supported) |
| 925 | sta_entry->wireless_mode = WIRELESS_MODE_AC_5G; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 926 | |
| 927 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 928 | sta_entry->wireless_mode = WIRELESS_MODE_A; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 929 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 930 | /*disable cck rate for p2p*/ |
| 931 | if (mac->p2p) |
| 932 | sta->supp_rates[0] &= 0xfffffff0; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 933 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 934 | memcpy(sta_entry->mac_addr, sta->addr, ETH_ALEN); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 935 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 936 | "Add sta addr is %pM\n", sta->addr); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 937 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
| 938 | } |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 939 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 940 | return 0; |
| 941 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 942 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 943 | static int rtl_op_sta_remove(struct ieee80211_hw *hw, |
| 944 | struct ieee80211_vif *vif, |
| 945 | struct ieee80211_sta *sta) |
| 946 | { |
| 947 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 948 | struct rtl_sta_info *sta_entry; |
| 949 | if (sta) { |
| 950 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 951 | "Remove sta addr is %pM\n", sta->addr); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 952 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 953 | sta_entry->wireless_mode = 0; |
| 954 | sta_entry->ratr_index = 0; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 955 | spin_lock_bh(&rtlpriv->locks.entry_list_lock); |
| 956 | list_del(&sta_entry->list); |
| 957 | spin_unlock_bh(&rtlpriv->locks.entry_list_lock); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 958 | } |
| 959 | return 0; |
| 960 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 961 | static int _rtl_get_hal_qnum(u16 queue) |
| 962 | { |
| 963 | int qnum; |
| 964 | |
| 965 | switch (queue) { |
| 966 | case 0: |
| 967 | qnum = AC3_VO; |
| 968 | break; |
| 969 | case 1: |
| 970 | qnum = AC2_VI; |
| 971 | break; |
| 972 | case 2: |
| 973 | qnum = AC0_BE; |
| 974 | break; |
| 975 | case 3: |
| 976 | qnum = AC1_BK; |
| 977 | break; |
| 978 | default: |
| 979 | qnum = AC0_BE; |
| 980 | break; |
| 981 | } |
| 982 | return qnum; |
| 983 | } |
| 984 | |
| 985 | /* |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 986 | *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3 |
| 987 | *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3 |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 988 | */ |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 989 | static int rtl_op_conf_tx(struct ieee80211_hw *hw, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 990 | struct ieee80211_vif *vif, u16 queue, |
| 991 | const struct ieee80211_tx_queue_params *param) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 992 | { |
| 993 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 994 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 995 | int aci; |
| 996 | |
| 997 | if (queue >= AC_MAX) { |
| 998 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 999 | "queue number %d is incorrect!\n", queue); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | |
| 1003 | aci = _rtl_get_hal_qnum(queue); |
| 1004 | mac->ac[aci].aifs = param->aifs; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 1005 | mac->ac[aci].cw_min = cpu_to_le16(param->cw_min); |
| 1006 | mac->ac[aci].cw_max = cpu_to_le16(param->cw_max); |
| 1007 | mac->ac[aci].tx_op = cpu_to_le16(param->txop); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1008 | memcpy(&mac->edca_param[aci], param, sizeof(*param)); |
| 1009 | rtlpriv->cfg->ops->set_qos(hw, aci); |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
| 1013 | static void rtl_op_bss_info_changed(struct ieee80211_hw *hw, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1014 | struct ieee80211_vif *vif, |
| 1015 | struct ieee80211_bss_conf *bss_conf, |
| 1016 | u32 changed) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1017 | { |
| 1018 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1019 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1020 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1021 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1022 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1023 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1024 | if ((vif->type == NL80211_IFTYPE_ADHOC) || |
| 1025 | (vif->type == NL80211_IFTYPE_AP) || |
| 1026 | (vif->type == NL80211_IFTYPE_MESH_POINT)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1027 | if ((changed & BSS_CHANGED_BEACON) || |
| 1028 | (changed & BSS_CHANGED_BEACON_ENABLED && |
| 1029 | bss_conf->enable_beacon)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1030 | if (mac->beacon_enabled == 0) { |
| 1031 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1032 | "BSS_CHANGED_BEACON_ENABLED\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1033 | |
| 1034 | /*start hw beacon interrupt. */ |
| 1035 | /*rtlpriv->cfg->ops->set_bcn_reg(hw); */ |
| 1036 | mac->beacon_enabled = 1; |
| 1037 | rtlpriv->cfg->ops->update_interrupt_mask(hw, |
| 1038 | rtlpriv->cfg->maps |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1039 | [RTL_IBSS_INT_MASKS], 0); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1040 | |
| 1041 | if (rtlpriv->cfg->ops->linked_set_reg) |
| 1042 | rtlpriv->cfg->ops->linked_set_reg(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1043 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1044 | } |
| 1045 | if ((changed & BSS_CHANGED_BEACON_ENABLED && |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1046 | !bss_conf->enable_beacon)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1047 | if (mac->beacon_enabled == 1) { |
| 1048 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1049 | "ADHOC DISABLE BEACON\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1050 | |
| 1051 | mac->beacon_enabled = 0; |
| 1052 | rtlpriv->cfg->ops->update_interrupt_mask(hw, 0, |
| 1053 | rtlpriv->cfg->maps |
| 1054 | [RTL_IBSS_INT_MASKS]); |
| 1055 | } |
| 1056 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1057 | if (changed & BSS_CHANGED_BEACON_INT) { |
| 1058 | RT_TRACE(rtlpriv, COMP_BEACON, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1059 | "BSS_CHANGED_BEACON_INT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1060 | mac->beacon_interval = bss_conf->beacon_int; |
| 1061 | rtlpriv->cfg->ops->set_bcn_intv(hw); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /*TODO: reference to enum ieee80211_bss_change */ |
| 1066 | if (changed & BSS_CHANGED_ASSOC) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1067 | u8 mstatus; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1068 | if (bss_conf->assoc) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1069 | struct ieee80211_sta *sta = NULL; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1070 | u8 keep_alive = 10; |
| 1071 | |
| 1072 | mstatus = RT_MEDIA_CONNECT; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1073 | /* we should reset all sec info & cam |
| 1074 | * before set cam after linked, we should not |
| 1075 | * reset in disassoc, that will cause tkip->wep |
| 1076 | * fail because some flag will be wrong */ |
| 1077 | /* reset sec info */ |
| 1078 | rtl_cam_reset_sec_info(hw); |
| 1079 | /* reset cam to fix wep fail issue |
| 1080 | * when change from wpa to wep */ |
| 1081 | rtl_cam_reset_all_entry(hw); |
| 1082 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1083 | mac->link_state = MAC80211_LINKED; |
| 1084 | mac->cnt_after_linked = 0; |
| 1085 | mac->assoc_id = bss_conf->aid; |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 1086 | memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1087 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1088 | if (rtlpriv->cfg->ops->linked_set_reg) |
| 1089 | rtlpriv->cfg->ops->linked_set_reg(hw); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1090 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1091 | rcu_read_lock(); |
| 1092 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 1093 | if (!sta) { |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 1094 | rcu_read_unlock(); |
| 1095 | goto out; |
| 1096 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1097 | RT_TRACE(rtlpriv, COMP_EASY_CONCURRENT, DBG_LOUD, |
| 1098 | "send PS STATIC frame\n"); |
| 1099 | if (rtlpriv->dm.supp_phymode_switch) { |
| 1100 | if (sta->ht_cap.ht_supported) |
| 1101 | rtl_send_smps_action(hw, sta, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1102 | IEEE80211_SMPS_STATIC); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1103 | } |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1104 | |
| 1105 | if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 1106 | mac->mode = WIRELESS_MODE_A; |
| 1107 | } else { |
| 1108 | if (sta->supp_rates[0] <= 0xf) |
| 1109 | mac->mode = WIRELESS_MODE_B; |
| 1110 | else |
| 1111 | mac->mode = WIRELESS_MODE_G; |
| 1112 | } |
| 1113 | |
| 1114 | if (sta->ht_cap.ht_supported) { |
| 1115 | if (rtlhal->current_bandtype == BAND_ON_2_4G) |
| 1116 | mac->mode = WIRELESS_MODE_N_24G; |
| 1117 | else |
| 1118 | mac->mode = WIRELESS_MODE_N_5G; |
| 1119 | } |
| 1120 | |
| 1121 | if (sta->vht_cap.vht_supported) { |
| 1122 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 1123 | mac->mode = WIRELESS_MODE_AC_5G; |
| 1124 | else |
| 1125 | mac->mode = WIRELESS_MODE_AC_24G; |
| 1126 | } |
| 1127 | |
| 1128 | if (vif->type == NL80211_IFTYPE_STATION && sta) |
| 1129 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1130 | rcu_read_unlock(); |
| 1131 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1132 | /* to avoid AP Disassociation caused by inactivity */ |
| 1133 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1134 | HW_VAR_KEEP_ALIVE, |
| 1135 | (u8 *)(&keep_alive)); |
| 1136 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1137 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1138 | "BSS_CHANGED_ASSOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1139 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1140 | mstatus = RT_MEDIA_DISCONNECT; |
| 1141 | |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1142 | if (mac->link_state == MAC80211_LINKED) { |
| 1143 | rtlpriv->enter_ps = false; |
| 1144 | schedule_work(&rtlpriv->works.lps_change_work); |
| 1145 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1146 | if (ppsc->p2p_ps_info.p2p_ps_mode > P2P_PS_NONE) |
| 1147 | rtl_p2p_ps_cmd(hw, P2P_PS_DISABLE); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1148 | mac->link_state = MAC80211_NOLINK; |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 1149 | memset(mac->bssid, 0, ETH_ALEN); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1150 | mac->vendor = PEER_UNKNOWN; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1151 | mac->mode = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1152 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1153 | if (rtlpriv->dm.supp_phymode_switch) { |
| 1154 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 1155 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
| 1156 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1157 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1158 | "BSS_CHANGED_UN_ASSOC\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1159 | } |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1160 | rtlpriv->cfg->ops->set_network_type(hw, vif->type); |
| 1161 | /* For FW LPS: |
| 1162 | * To tell firmware we have connected or disconnected |
| 1163 | */ |
| 1164 | rtlpriv->cfg->ops->set_hw_reg(hw, |
| 1165 | HW_VAR_H2C_FW_JOINBSSRPT, |
| 1166 | (u8 *)(&mstatus)); |
| 1167 | ppsc->report_linked = (mstatus == RT_MEDIA_CONNECT) ? |
| 1168 | true : false; |
| 1169 | |
| 1170 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1171 | rtlpriv->btcoexist.btc_ops->btc_mediastatus_notify( |
| 1172 | rtlpriv, mstatus); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
| 1176 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1177 | "BSS_CHANGED_ERP_CTS_PROT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1178 | mac->use_cts_protect = bss_conf->use_cts_prot; |
| 1179 | } |
| 1180 | |
| 1181 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { |
| 1182 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1183 | "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n", |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1184 | bss_conf->use_short_preamble); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1185 | |
| 1186 | mac->short_preamble = bss_conf->use_short_preamble; |
| 1187 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACK_PREAMBLE, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1188 | (u8 *)(&mac->short_preamble)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1192 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1193 | "BSS_CHANGED_ERP_SLOT\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1194 | |
| 1195 | if (bss_conf->use_short_slot) |
| 1196 | mac->slot_time = RTL_SLOT_TIME_9; |
| 1197 | else |
| 1198 | mac->slot_time = RTL_SLOT_TIME_20; |
| 1199 | |
| 1200 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1201 | (u8 *)(&mac->slot_time)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | if (changed & BSS_CHANGED_HT) { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1205 | struct ieee80211_sta *sta = NULL; |
| 1206 | |
| 1207 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
| 1208 | "BSS_CHANGED_HT\n"); |
| 1209 | |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 1210 | rcu_read_lock(); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1211 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1212 | if (sta) { |
| 1213 | if (sta->ht_cap.ampdu_density > |
| 1214 | mac->current_ampdu_density) |
| 1215 | mac->current_ampdu_density = |
| 1216 | sta->ht_cap.ampdu_density; |
| 1217 | if (sta->ht_cap.ampdu_factor < |
| 1218 | mac->current_ampdu_factor) |
| 1219 | mac->current_ampdu_factor = |
| 1220 | sta->ht_cap.ampdu_factor; |
| 1221 | } |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 1222 | rcu_read_unlock(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1223 | |
| 1224 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SHORTGI_DENSITY, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1225 | (u8 *)(&mac->max_mss_density)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1226 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_FACTOR, |
| 1227 | &mac->current_ampdu_factor); |
| 1228 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AMPDU_MIN_SPACE, |
| 1229 | &mac->current_ampdu_density); |
| 1230 | } |
| 1231 | |
| 1232 | if (changed & BSS_CHANGED_BSSID) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1233 | u32 basic_rates; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1234 | struct ieee80211_sta *sta = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1235 | |
| 1236 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1237 | (u8 *)bss_conf->bssid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1238 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1239 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG, |
| 1240 | "bssid: %pM\n", bss_conf->bssid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1241 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1242 | mac->vendor = PEER_UNKNOWN; |
Joe Perches | d458cdf | 2013-10-01 19:04:40 -0700 | [diff] [blame] | 1243 | memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1244 | |
Alessio Igor Bogani | 701c2be | 2011-02-28 18:46:44 +0100 | [diff] [blame] | 1245 | rcu_read_lock(); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1246 | sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1247 | if (!sta) { |
| 1248 | rcu_read_unlock(); |
| 1249 | goto out; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1250 | } |
| 1251 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1252 | if (rtlhal->current_bandtype == BAND_ON_5G) { |
| 1253 | mac->mode = WIRELESS_MODE_A; |
| 1254 | } else { |
| 1255 | if (sta->supp_rates[0] <= 0xf) |
| 1256 | mac->mode = WIRELESS_MODE_B; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1257 | else |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1258 | mac->mode = WIRELESS_MODE_G; |
| 1259 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1260 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1261 | if (sta->ht_cap.ht_supported) { |
| 1262 | if (rtlhal->current_bandtype == BAND_ON_2_4G) |
| 1263 | mac->mode = WIRELESS_MODE_N_24G; |
| 1264 | else |
| 1265 | mac->mode = WIRELESS_MODE_N_5G; |
| 1266 | } |
| 1267 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1268 | if (sta->vht_cap.vht_supported) { |
| 1269 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 1270 | mac->mode = WIRELESS_MODE_AC_5G; |
| 1271 | else |
| 1272 | mac->mode = WIRELESS_MODE_AC_24G; |
| 1273 | } |
| 1274 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1275 | /* just station need it, because ibss & ap mode will |
| 1276 | * set in sta_add, and will be NULL here */ |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1277 | if (vif->type == NL80211_IFTYPE_STATION) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1278 | struct rtl_sta_info *sta_entry; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1279 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1280 | sta_entry->wireless_mode = mac->mode; |
| 1281 | } |
| 1282 | |
| 1283 | if (sta->ht_cap.ht_supported) { |
| 1284 | mac->ht_enable = true; |
| 1285 | |
| 1286 | /* |
| 1287 | * for cisco 1252 bw20 it's wrong |
| 1288 | * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
| 1289 | * mac->bw_40 = true; |
| 1290 | * } |
| 1291 | * */ |
| 1292 | } |
| 1293 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1294 | if (sta->vht_cap.vht_supported) |
| 1295 | mac->vht_enable = true; |
| 1296 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1297 | if (changed & BSS_CHANGED_BASIC_RATES) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1298 | /* for 5G must << RATE_6M_INDEX = 4, |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1299 | * because 5G have no cck rate*/ |
| 1300 | if (rtlhal->current_bandtype == BAND_ON_5G) |
| 1301 | basic_rates = sta->supp_rates[1] << 4; |
| 1302 | else |
| 1303 | basic_rates = sta->supp_rates[0]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1304 | |
| 1305 | mac->basic_rates = basic_rates; |
| 1306 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE, |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 1307 | (u8 *)(&basic_rates)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1308 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1309 | rcu_read_unlock(); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1310 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1311 | out: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1312 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1313 | } |
| 1314 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1315 | static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1316 | { |
| 1317 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1318 | u64 tsf; |
| 1319 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1320 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&tsf)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1321 | return tsf; |
| 1322 | } |
| 1323 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1324 | static void rtl_op_set_tsf(struct ieee80211_hw *hw, |
| 1325 | struct ieee80211_vif *vif, u64 tsf) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1326 | { |
| 1327 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1328 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 1329 | u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1330 | |
| 1331 | mac->tsf = tsf; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1332 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&bibss)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1333 | } |
| 1334 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1335 | static void rtl_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1336 | { |
| 1337 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1338 | u8 tmp = 0; |
| 1339 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1340 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *)(&tmp)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | static void rtl_op_sta_notify(struct ieee80211_hw *hw, |
| 1344 | struct ieee80211_vif *vif, |
| 1345 | enum sta_notify_cmd cmd, |
| 1346 | struct ieee80211_sta *sta) |
| 1347 | { |
| 1348 | switch (cmd) { |
| 1349 | case STA_NOTIFY_SLEEP: |
| 1350 | break; |
| 1351 | case STA_NOTIFY_AWAKE: |
| 1352 | break; |
| 1353 | default: |
| 1354 | break; |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | static int rtl_op_ampdu_action(struct ieee80211_hw *hw, |
| 1359 | struct ieee80211_vif *vif, |
| 1360 | enum ieee80211_ampdu_mlme_action action, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1361 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
| 1362 | u8 buf_size) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1363 | { |
| 1364 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1365 | |
| 1366 | switch (action) { |
| 1367 | case IEEE80211_AMPDU_TX_START: |
| 1368 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1369 | "IEEE80211_AMPDU_TX_START: TID:%d\n", tid); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1370 | return rtl_tx_agg_start(hw, vif, sta, tid, ssn); |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 1371 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 1372 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 1373 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1374 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1375 | "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1376 | return rtl_tx_agg_stop(hw, vif, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1377 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 1378 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1379 | "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1380 | rtl_tx_agg_oper(hw, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1381 | break; |
| 1382 | case IEEE80211_AMPDU_RX_START: |
| 1383 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1384 | "IEEE80211_AMPDU_RX_START:TID:%d\n", tid); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1385 | return rtl_rx_agg_start(hw, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1386 | case IEEE80211_AMPDU_RX_STOP: |
| 1387 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1388 | "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1389 | return rtl_rx_agg_stop(hw, sta, tid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1390 | default: |
| 1391 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1392 | "IEEE80211_AMPDU_ERR!!!!:\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1393 | return -EOPNOTSUPP; |
| 1394 | } |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 1398 | static void rtl_op_sw_scan_start(struct ieee80211_hw *hw, |
| 1399 | struct ieee80211_vif *vif, |
| 1400 | const u8 *mac_addr) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1401 | { |
| 1402 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1403 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1404 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1405 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1406 | mac->act_scanning = true; |
| 1407 | if (rtlpriv->link_info.higher_busytraffic) { |
| 1408 | mac->skip_scan = true; |
| 1409 | return; |
| 1410 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1411 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1412 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1413 | rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 1); |
| 1414 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1415 | if (rtlpriv->dm.supp_phymode_switch) { |
| 1416 | if (rtlpriv->cfg->ops->chk_switch_dmdp) |
| 1417 | rtlpriv->cfg->ops->chk_switch_dmdp(hw); |
| 1418 | } |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1419 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1420 | if (mac->link_state == MAC80211_LINKED) { |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1421 | rtlpriv->enter_ps = false; |
| 1422 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1423 | mac->link_state = MAC80211_LINKED_SCANNING; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1424 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1425 | rtl_ips_nic_on(hw); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1428 | /* Dul mac */ |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1429 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1430 | |
| 1431 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1432 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP_BAND0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1433 | } |
| 1434 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 1435 | static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw, |
| 1436 | struct ieee80211_vif *vif) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1437 | { |
| 1438 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1439 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1440 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1441 | RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD, "\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1442 | mac->act_scanning = false; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1443 | mac->skip_scan = false; |
| 1444 | if (rtlpriv->link_info.higher_busytraffic) |
| 1445 | return; |
| 1446 | |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1447 | /* p2p will use 1/6/11 to scan */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1448 | if (mac->n_channels == 3) |
| 1449 | mac->p2p_in_use = true; |
| 1450 | else |
| 1451 | mac->p2p_in_use = false; |
| 1452 | mac->n_channels = 0; |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1453 | /* Dul mac */ |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1454 | rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false; |
| 1455 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1456 | if (mac->link_state == MAC80211_LINKED_SCANNING) { |
| 1457 | mac->link_state = MAC80211_LINKED; |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1458 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
| 1459 | /* fix fwlps issue */ |
| 1460 | rtlpriv->cfg->ops->set_network_type(hw, mac->opmode); |
| 1461 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1462 | } |
| 1463 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1464 | rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_RESTORE); |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1465 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1466 | rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 0); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | static int rtl_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
| 1470 | struct ieee80211_vif *vif, struct ieee80211_sta *sta, |
| 1471 | struct ieee80211_key_conf *key) |
| 1472 | { |
| 1473 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1474 | u8 key_type = NO_ENCRYPTION; |
| 1475 | u8 key_idx; |
| 1476 | bool group_key = false; |
| 1477 | bool wep_only = false; |
| 1478 | int err = 0; |
| 1479 | u8 mac_addr[ETH_ALEN]; |
| 1480 | u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1481 | |
| 1482 | if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { |
| 1483 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1484 | "not open hw encryption\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1485 | return -ENOSPC; /*User disabled HW-crypto */ |
| 1486 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1487 | /* To support IBSS, use sw-crypto for GTK */ |
| 1488 | if (((vif->type == NL80211_IFTYPE_ADHOC) || |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1489 | (vif->type == NL80211_IFTYPE_MESH_POINT)) && |
| 1490 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1491 | return -ENOSPC; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1492 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1493 | "%s hardware based encryption for keyidx: %d, mac: %pM\n", |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1494 | cmd == SET_KEY ? "Using" : "Disabling", key->keyidx, |
| 1495 | sta ? sta->addr : bcast_addr); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1496 | rtlpriv->sec.being_setkey = true; |
| 1497 | rtl_ips_nic_on(hw); |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1498 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1499 | /* <1> get encryption alg */ |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1500 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1501 | switch (key->cipher) { |
| 1502 | case WLAN_CIPHER_SUITE_WEP40: |
| 1503 | key_type = WEP40_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1504 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP40\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1505 | break; |
| 1506 | case WLAN_CIPHER_SUITE_WEP104: |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1507 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1508 | key_type = WEP104_ENCRYPTION; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1509 | break; |
| 1510 | case WLAN_CIPHER_SUITE_TKIP: |
| 1511 | key_type = TKIP_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1512 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1513 | break; |
| 1514 | case WLAN_CIPHER_SUITE_CCMP: |
| 1515 | key_type = AESCCMP_ENCRYPTION; |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1516 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1517 | break; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1518 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1519 | /* HW don't support CMAC encryption, |
| 1520 | * use software CMAC encryption |
| 1521 | */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1522 | key_type = AESCMAC_ENCRYPTION; |
| 1523 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CMAC\n"); |
| 1524 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1525 | "HW don't support CMAC encrypiton, use software CMAC encrypiton\n"); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1526 | err = -EOPNOTSUPP; |
| 1527 | goto out_unlock; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1528 | default: |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1529 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1530 | "alg_err:%x!!!!:\n", key->cipher); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1531 | goto out_unlock; |
| 1532 | } |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1533 | if (key_type == WEP40_ENCRYPTION || |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1534 | key_type == WEP104_ENCRYPTION || |
| 1535 | vif->type == NL80211_IFTYPE_ADHOC) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1536 | rtlpriv->sec.use_defaultkey = true; |
| 1537 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1538 | /* <2> get key_idx */ |
| 1539 | key_idx = (u8) (key->keyidx); |
| 1540 | if (key_idx > 3) |
| 1541 | goto out_unlock; |
| 1542 | /* <3> if pairwise key enable_hw_sec */ |
| 1543 | group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1544 | |
| 1545 | /* wep always be group key, but there are two conditions: |
| 1546 | * 1) wep only: is just for wep enc, in this condition |
| 1547 | * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION |
| 1548 | * will be true & enable_hw_sec will be set when wep |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1549 | * ke setting. |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1550 | * 2) wep(group) + AES(pairwise): some AP like cisco |
| 1551 | * may use it, in this condition enable_hw_sec will not |
| 1552 | * be set when wep key setting */ |
| 1553 | /* we must reset sec_info after lingked before set key, |
| 1554 | * or some flag will be wrong*/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1555 | if (vif->type == NL80211_IFTYPE_AP || |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1556 | vif->type == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1557 | if (!group_key || key_type == WEP40_ENCRYPTION || |
| 1558 | key_type == WEP104_ENCRYPTION) { |
| 1559 | if (group_key) |
| 1560 | wep_only = true; |
| 1561 | rtlpriv->cfg->ops->enable_hw_sec(hw); |
| 1562 | } |
| 1563 | } else { |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1564 | if ((!group_key) || (vif->type == NL80211_IFTYPE_ADHOC) || |
| 1565 | rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1566 | if (rtlpriv->sec.pairwise_enc_algorithm == |
| 1567 | NO_ENCRYPTION && |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1568 | (key_type == WEP40_ENCRYPTION || |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1569 | key_type == WEP104_ENCRYPTION)) |
| 1570 | wep_only = true; |
| 1571 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 1572 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1573 | "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n", |
| 1574 | key_type); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1575 | rtlpriv->cfg->ops->enable_hw_sec(hw); |
| 1576 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1577 | } |
| 1578 | /* <4> set key based on cmd */ |
| 1579 | switch (cmd) { |
| 1580 | case SET_KEY: |
| 1581 | if (wep_only) { |
| 1582 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1583 | "set WEP(group/pairwise) key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1584 | /* Pairwise key with an assigned MAC address. */ |
| 1585 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 1586 | rtlpriv->sec.group_enc_algorithm = key_type; |
| 1587 | /*set local buf about wep key. */ |
| 1588 | memcpy(rtlpriv->sec.key_buf[key_idx], |
| 1589 | key->key, key->keylen); |
| 1590 | rtlpriv->sec.key_len[key_idx] = key->keylen; |
Wei Yongjun | ccd9536 | 2012-11-15 21:24:57 +0800 | [diff] [blame] | 1591 | eth_zero_addr(mac_addr); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1592 | } else if (group_key) { /* group key */ |
| 1593 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1594 | "set group key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1595 | /* group key */ |
| 1596 | rtlpriv->sec.group_enc_algorithm = key_type; |
| 1597 | /*set local buf about group key. */ |
| 1598 | memcpy(rtlpriv->sec.key_buf[key_idx], |
| 1599 | key->key, key->keylen); |
| 1600 | rtlpriv->sec.key_len[key_idx] = key->keylen; |
| 1601 | memcpy(mac_addr, bcast_addr, ETH_ALEN); |
| 1602 | } else { /* pairwise key */ |
| 1603 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1604 | "set pairwise key\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1605 | if (!sta) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 1606 | RT_ASSERT(false, |
| 1607 | "pairwise key without mac_addr\n"); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1608 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1609 | err = -EOPNOTSUPP; |
| 1610 | goto out_unlock; |
| 1611 | } |
| 1612 | /* Pairwise key with an assigned MAC address. */ |
| 1613 | rtlpriv->sec.pairwise_enc_algorithm = key_type; |
| 1614 | /*set local buf about pairwise key. */ |
| 1615 | memcpy(rtlpriv->sec.key_buf[PAIRWISE_KEYIDX], |
| 1616 | key->key, key->keylen); |
| 1617 | rtlpriv->sec.key_len[PAIRWISE_KEYIDX] = key->keylen; |
| 1618 | rtlpriv->sec.pairwise_key = |
| 1619 | rtlpriv->sec.key_buf[PAIRWISE_KEYIDX]; |
| 1620 | memcpy(mac_addr, sta->addr, ETH_ALEN); |
| 1621 | } |
| 1622 | rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr, |
| 1623 | group_key, key_type, wep_only, |
| 1624 | false); |
| 1625 | /* <5> tell mac80211 do something: */ |
| 1626 | /*must use sw generate IV, or can not work !!!!. */ |
| 1627 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1628 | key->hw_key_idx = key_idx; |
| 1629 | if (key_type == TKIP_ENCRYPTION) |
| 1630 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1631 | /*use software CCMP encryption for management frames (MFP) */ |
| 1632 | if (key_type == AESCCMP_ENCRYPTION) |
| 1633 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1634 | break; |
| 1635 | case DISABLE_KEY: |
| 1636 | RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1637 | "disable key delete one entry\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1638 | /*set local buf about wep key. */ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1639 | if (vif->type == NL80211_IFTYPE_AP || |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1640 | vif->type == NL80211_IFTYPE_MESH_POINT) { |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1641 | if (sta) |
| 1642 | rtl_cam_del_entry(hw, sta->addr); |
| 1643 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1644 | memset(rtlpriv->sec.key_buf[key_idx], 0, key->keylen); |
| 1645 | rtlpriv->sec.key_len[key_idx] = 0; |
Wei Yongjun | ccd9536 | 2012-11-15 21:24:57 +0800 | [diff] [blame] | 1646 | eth_zero_addr(mac_addr); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1647 | /* |
| 1648 | *mac80211 will delete entrys one by one, |
| 1649 | *so don't use rtl_cam_reset_all_entry |
| 1650 | *or clear all entry here. |
| 1651 | */ |
| 1652 | rtl_cam_delete_one_entry(hw, mac_addr, key_idx); |
| 1653 | break; |
| 1654 | default: |
| 1655 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1656 | "cmd_err:%x!!!!:\n", cmd); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1657 | } |
| 1658 | out_unlock: |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1659 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1660 | rtlpriv->sec.being_setkey = false; |
| 1661 | return err; |
| 1662 | } |
| 1663 | |
| 1664 | static void rtl_op_rfkill_poll(struct ieee80211_hw *hw) |
| 1665 | { |
| 1666 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1667 | |
| 1668 | bool radio_state; |
| 1669 | bool blocked; |
| 1670 | u8 valid = 0; |
| 1671 | |
| 1672 | if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status)) |
| 1673 | return; |
| 1674 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1675 | mutex_lock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1676 | |
| 1677 | /*if Radio On return true here */ |
| 1678 | radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid); |
| 1679 | |
| 1680 | if (valid) { |
| 1681 | if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) { |
| 1682 | rtlpriv->rfkill.rfkill_state = radio_state; |
| 1683 | |
| 1684 | RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1685 | "wireless radio switch turned %s\n", |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1686 | radio_state ? "on" : "off"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1687 | |
| 1688 | blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1; |
| 1689 | wiphy_rfkill_set_hw_state(hw->wiphy, blocked); |
| 1690 | } |
| 1691 | } |
| 1692 | |
Larry Finger | 8a09d6d | 2010-12-16 11:13:57 -0600 | [diff] [blame] | 1693 | mutex_unlock(&rtlpriv->locks.conf_mutex); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1694 | } |
| 1695 | |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1696 | /* this function is called by mac80211 to flush tx buffer |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1697 | * before switch channle or power save, or tx buffer packet |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1698 | * maybe send after offchannel or rf sleep, this may cause |
| 1699 | * dis-association by AP */ |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1700 | static void rtl_op_flush(struct ieee80211_hw *hw, |
| 1701 | struct ieee80211_vif *vif, |
| 1702 | u32 queues, |
| 1703 | bool drop) |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1704 | { |
| 1705 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1706 | |
| 1707 | if (rtlpriv->intf_ops->flush) |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1708 | rtlpriv->intf_ops->flush(hw, queues, drop); |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1709 | } |
| 1710 | |
Larry Finger | 34ed780 | 2014-09-22 09:39:27 -0500 | [diff] [blame] | 1711 | /* Description: |
| 1712 | * This routine deals with the Power Configuration CMD |
| 1713 | * parsing for RTL8723/RTL8188E Series IC. |
| 1714 | * Assumption: |
| 1715 | * We should follow specific format that was released from HW SD. |
| 1716 | */ |
| 1717 | bool rtl_hal_pwrseqcmdparsing(struct rtl_priv *rtlpriv, u8 cut_version, |
| 1718 | u8 faversion, u8 interface_type, |
| 1719 | struct wlan_pwr_cfg pwrcfgcmd[]) |
| 1720 | { |
| 1721 | struct wlan_pwr_cfg cfg_cmd = {0}; |
| 1722 | bool polling_bit = false; |
| 1723 | u32 ary_idx = 0; |
| 1724 | u8 value = 0; |
| 1725 | u32 offset = 0; |
| 1726 | u32 polling_count = 0; |
| 1727 | u32 max_polling_cnt = 5000; |
| 1728 | |
| 1729 | do { |
| 1730 | cfg_cmd = pwrcfgcmd[ary_idx]; |
| 1731 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1732 | "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n", |
| 1733 | GET_PWR_CFG_OFFSET(cfg_cmd), |
| 1734 | GET_PWR_CFG_CUT_MASK(cfg_cmd), |
| 1735 | GET_PWR_CFG_FAB_MASK(cfg_cmd), |
| 1736 | GET_PWR_CFG_INTF_MASK(cfg_cmd), |
| 1737 | GET_PWR_CFG_BASE(cfg_cmd), GET_PWR_CFG_CMD(cfg_cmd), |
| 1738 | GET_PWR_CFG_MASK(cfg_cmd), GET_PWR_CFG_VALUE(cfg_cmd)); |
| 1739 | |
| 1740 | if ((GET_PWR_CFG_FAB_MASK(cfg_cmd)&faversion) && |
| 1741 | (GET_PWR_CFG_CUT_MASK(cfg_cmd)&cut_version) && |
| 1742 | (GET_PWR_CFG_INTF_MASK(cfg_cmd)&interface_type)) { |
| 1743 | switch (GET_PWR_CFG_CMD(cfg_cmd)) { |
| 1744 | case PWR_CMD_READ: |
| 1745 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1746 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n"); |
| 1747 | break; |
| 1748 | case PWR_CMD_WRITE: |
| 1749 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1750 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_WRITE\n"); |
| 1751 | offset = GET_PWR_CFG_OFFSET(cfg_cmd); |
| 1752 | |
| 1753 | /*Read the value from system register*/ |
| 1754 | value = rtl_read_byte(rtlpriv, offset); |
| 1755 | value &= (~(GET_PWR_CFG_MASK(cfg_cmd))); |
| 1756 | value |= (GET_PWR_CFG_VALUE(cfg_cmd) & |
| 1757 | GET_PWR_CFG_MASK(cfg_cmd)); |
| 1758 | |
| 1759 | /*Write the value back to sytem register*/ |
| 1760 | rtl_write_byte(rtlpriv, offset, value); |
| 1761 | break; |
| 1762 | case PWR_CMD_POLLING: |
| 1763 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1764 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n"); |
| 1765 | polling_bit = false; |
| 1766 | offset = GET_PWR_CFG_OFFSET(cfg_cmd); |
| 1767 | |
| 1768 | do { |
| 1769 | value = rtl_read_byte(rtlpriv, offset); |
| 1770 | |
| 1771 | value &= GET_PWR_CFG_MASK(cfg_cmd); |
| 1772 | if (value == |
| 1773 | (GET_PWR_CFG_VALUE(cfg_cmd) & |
| 1774 | GET_PWR_CFG_MASK(cfg_cmd))) |
| 1775 | polling_bit = true; |
| 1776 | else |
| 1777 | udelay(10); |
| 1778 | |
| 1779 | if (polling_count++ > max_polling_cnt) |
| 1780 | return false; |
| 1781 | } while (!polling_bit); |
| 1782 | break; |
| 1783 | case PWR_CMD_DELAY: |
| 1784 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1785 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n"); |
| 1786 | if (GET_PWR_CFG_VALUE(cfg_cmd) == |
| 1787 | PWRSEQ_DELAY_US) |
| 1788 | udelay(GET_PWR_CFG_OFFSET(cfg_cmd)); |
| 1789 | else |
| 1790 | mdelay(GET_PWR_CFG_OFFSET(cfg_cmd)); |
| 1791 | break; |
| 1792 | case PWR_CMD_END: |
| 1793 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 1794 | "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n"); |
| 1795 | return true; |
| 1796 | default: |
| 1797 | RT_ASSERT(false, |
| 1798 | "rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n"); |
| 1799 | break; |
| 1800 | } |
| 1801 | } |
| 1802 | ary_idx++; |
| 1803 | } while (1); |
| 1804 | |
| 1805 | return true; |
| 1806 | } |
| 1807 | EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing); |
Larry Finger | 557f933 | 2014-09-26 16:40:27 -0500 | [diff] [blame] | 1808 | |
| 1809 | bool rtl_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb) |
| 1810 | { |
| 1811 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1812 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1813 | struct rtl8192_tx_ring *ring; |
| 1814 | struct rtl_tx_desc *pdesc; |
| 1815 | unsigned long flags; |
| 1816 | struct sk_buff *pskb = NULL; |
| 1817 | |
| 1818 | ring = &rtlpci->tx_ring[BEACON_QUEUE]; |
| 1819 | |
| 1820 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
| 1821 | pskb = __skb_dequeue(&ring->queue); |
| 1822 | if (pskb) |
| 1823 | kfree_skb(pskb); |
| 1824 | |
| 1825 | /*this is wrong, fill_tx_cmddesc needs update*/ |
| 1826 | pdesc = &ring->desc[0]; |
| 1827 | |
| 1828 | rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *)pdesc, 1, 1, skb); |
| 1829 | |
| 1830 | __skb_queue_tail(&ring->queue, skb); |
| 1831 | |
| 1832 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1833 | |
| 1834 | rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE); |
| 1835 | |
| 1836 | return true; |
| 1837 | } |
| 1838 | EXPORT_SYMBOL(rtl_cmd_send_packet); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1839 | const struct ieee80211_ops rtl_ops = { |
| 1840 | .start = rtl_op_start, |
| 1841 | .stop = rtl_op_stop, |
| 1842 | .tx = rtl_op_tx, |
| 1843 | .add_interface = rtl_op_add_interface, |
| 1844 | .remove_interface = rtl_op_remove_interface, |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1845 | .change_interface = rtl_op_change_interface, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1846 | #ifdef CONFIG_PM |
| 1847 | .suspend = rtl_op_suspend, |
| 1848 | .resume = rtl_op_resume, |
| 1849 | #endif |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1850 | .config = rtl_op_config, |
| 1851 | .configure_filter = rtl_op_configure_filter, |
| 1852 | .set_key = rtl_op_set_key, |
| 1853 | .conf_tx = rtl_op_conf_tx, |
| 1854 | .bss_info_changed = rtl_op_bss_info_changed, |
| 1855 | .get_tsf = rtl_op_get_tsf, |
| 1856 | .set_tsf = rtl_op_set_tsf, |
| 1857 | .reset_tsf = rtl_op_reset_tsf, |
| 1858 | .sta_notify = rtl_op_sta_notify, |
| 1859 | .ampdu_action = rtl_op_ampdu_action, |
| 1860 | .sw_scan_start = rtl_op_sw_scan_start, |
| 1861 | .sw_scan_complete = rtl_op_sw_scan_complete, |
| 1862 | .rfkill_poll = rtl_op_rfkill_poll, |
Larry Finger | f7953b2 | 2014-09-22 09:39:20 -0500 | [diff] [blame] | 1863 | .sta_add = rtl_op_sta_add, |
| 1864 | .sta_remove = rtl_op_sta_remove, |
Chaoming_Li | 0baa0fd | 2011-04-25 13:23:10 -0500 | [diff] [blame] | 1865 | .flush = rtl_op_flush, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1866 | }; |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 1867 | EXPORT_SYMBOL_GPL(rtl_ops); |
Larry Finger | c0386f1 | 2014-10-29 23:17:08 -0500 | [diff] [blame] | 1868 | |
| 1869 | bool rtl_btc_status_false(void) |
| 1870 | { |
| 1871 | return false; |
| 1872 | } |
| 1873 | EXPORT_SYMBOL_GPL(rtl_btc_status_false); |
Larry Finger | 6f8214b | 2015-01-06 09:58:04 -0600 | [diff] [blame] | 1874 | |
| 1875 | void rtl_dm_diginit(struct ieee80211_hw *hw, u32 cur_igvalue) |
| 1876 | { |
| 1877 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1878 | struct dig_t *dm_digtable = &rtlpriv->dm_digtable; |
| 1879 | |
| 1880 | dm_digtable->dig_enable_flag = true; |
Larry Finger | 3424a00 | 2015-01-06 09:58:06 -0600 | [diff] [blame^] | 1881 | dm_digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
Larry Finger | 6f8214b | 2015-01-06 09:58:04 -0600 | [diff] [blame] | 1882 | dm_digtable->cur_igvalue = cur_igvalue; |
| 1883 | dm_digtable->pre_igvalue = 0; |
| 1884 | dm_digtable->cur_sta_cstate = DIG_STA_DISCONNECT; |
| 1885 | dm_digtable->presta_cstate = DIG_STA_DISCONNECT; |
| 1886 | dm_digtable->curmultista_cstate = DIG_MULTISTA_DISCONNECT; |
| 1887 | dm_digtable->rssi_lowthresh = DM_DIG_THRESH_LOW; |
| 1888 | dm_digtable->rssi_highthresh = DM_DIG_THRESH_HIGH; |
| 1889 | dm_digtable->fa_lowthresh = DM_FALSEALARM_THRESH_LOW; |
| 1890 | dm_digtable->fa_highthresh = DM_FALSEALARM_THRESH_HIGH; |
| 1891 | dm_digtable->rx_gain_max = DM_DIG_MAX; |
| 1892 | dm_digtable->rx_gain_min = DM_DIG_MIN; |
| 1893 | dm_digtable->back_val = DM_DIG_BACKOFF_DEFAULT; |
| 1894 | dm_digtable->back_range_max = DM_DIG_BACKOFF_MAX; |
| 1895 | dm_digtable->back_range_min = DM_DIG_BACKOFF_MIN; |
| 1896 | dm_digtable->pre_cck_cca_thres = 0xff; |
| 1897 | dm_digtable->cur_cck_cca_thres = 0x83; |
| 1898 | dm_digtable->forbidden_igi = DM_DIG_MIN; |
| 1899 | dm_digtable->large_fa_hit = 0; |
| 1900 | dm_digtable->recover_cnt = 0; |
| 1901 | dm_digtable->dig_min_0 = 0x25; |
| 1902 | dm_digtable->dig_min_1 = 0x25; |
| 1903 | dm_digtable->media_connect_0 = false; |
| 1904 | dm_digtable->media_connect_1 = false; |
| 1905 | rtlpriv->dm.dm_initialgain_enable = true; |
| 1906 | dm_digtable->bt30_cur_igi = 0x32; |
Larry Finger | 3424a00 | 2015-01-06 09:58:06 -0600 | [diff] [blame^] | 1907 | dm_digtable->pre_cck_pd_state = CCK_PD_STAGE_MAX; |
| 1908 | dm_digtable->cur_cck_pd_state = CCK_PD_STAGE_LOWRSSI; |
Larry Finger | 6f8214b | 2015-01-06 09:58:04 -0600 | [diff] [blame] | 1909 | } |
| 1910 | EXPORT_SYMBOL(rtl_dm_diginit); |