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