1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
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.
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
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
31 #include "pwrseqcmd.h"
33 #include "btcoexist/rtl_btc.h"
34 #include <linux/firmware.h>
35 #include <linux/export.h>
36 #include <net/cfg80211.h>
38 void rtl_addr_delay(u32 addr)
42 else if (addr == 0xfd)
44 else if (addr == 0xfc)
46 else if (addr == 0xfb)
48 else if (addr == 0xfa)
50 else if (addr == 0xf9)
53 EXPORT_SYMBOL(rtl_addr_delay);
55 void rtl_rfreg_delay(struct ieee80211_hw *hw, enum radio_path rfpath, u32 addr,
60 } else if (addr == 0xfd) {
62 } else if (addr == 0xfc) {
64 } else if (addr == 0xfb) {
66 } else if (addr == 0xfa) {
68 } else if (addr == 0xf9) {
71 rtl_set_rfreg(hw, rfpath, addr, mask, data);
75 EXPORT_SYMBOL(rtl_rfreg_delay);
77 void rtl_bb_delay(struct ieee80211_hw *hw, u32 addr, u32 data)
81 } else if (addr == 0xfd) {
83 } else if (addr == 0xfc) {
85 } else if (addr == 0xfb) {
87 } else if (addr == 0xfa) {
89 } else if (addr == 0xf9) {
92 rtl_set_bbreg(hw, addr, MASKDWORD, data);
96 EXPORT_SYMBOL(rtl_bb_delay);
98 void rtl_fw_cb(const struct firmware *firmware, void *context)
100 struct ieee80211_hw *hw = context;
101 struct rtl_priv *rtlpriv = rtl_priv(hw);
104 RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
105 "Firmware callback routine entered!\n");
106 complete(&rtlpriv->firmware_loading_complete);
108 if (rtlpriv->cfg->alt_fw_name) {
109 err = request_firmware(&firmware,
110 rtlpriv->cfg->alt_fw_name,
112 pr_info("Loading alternative firmware %s\n",
113 rtlpriv->cfg->alt_fw_name);
117 pr_err("Firmware %s not available\n", rtlpriv->cfg->fw_name);
118 rtlpriv->max_fw_size = 0;
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);
128 memcpy(rtlpriv->rtlhal.pfirmware, firmware->data, firmware->size);
129 rtlpriv->rtlhal.fwsize = firmware->size;
130 release_firmware(firmware);
132 EXPORT_SYMBOL(rtl_fw_cb);
134 /*mutex for start & stop is must here. */
135 static int rtl_op_start(struct ieee80211_hw *hw)
138 struct rtl_priv *rtlpriv = rtl_priv(hw);
139 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
141 if (!is_hal_stop(rtlhal))
143 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
145 mutex_lock(&rtlpriv->locks.conf_mutex);
146 err = rtlpriv->intf_ops->adapter_start(hw);
148 rtl_watch_dog_timer_callback((unsigned long)hw);
149 mutex_unlock(&rtlpriv->locks.conf_mutex);
153 static void rtl_op_stop(struct ieee80211_hw *hw)
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;
161 if (is_hal_stop(rtlhal))
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,
170 if (unlikely(ppsc->rfpwr_state == ERFOFF))
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;
182 rtl_cam_reset_sec_info(hw);
184 rtl_deinit_deferred_work(hw);
186 rtlpriv->intf_ops->adapter_stop(hw);
188 mutex_unlock(&rtlpriv->locks.conf_mutex);
191 static void rtl_op_tx(struct ieee80211_hw *hw,
192 struct ieee80211_tx_control *control,
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));
201 if (unlikely(is_hal_stop(rtlhal) || ppsc->rfpwr_state != ERFON))
204 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
207 if (!rtlpriv->intf_ops->waitq_insert(hw, control->sta, skb))
208 rtlpriv->intf_ops->adapter_tx(hw, control->sta, skb, &tcb_desc);
212 dev_kfree_skb_any(skb);
215 static int rtl_op_add_interface(struct ieee80211_hw *hw,
216 struct ieee80211_vif *vif)
218 struct rtl_priv *rtlpriv = rtl_priv(hw);
219 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
223 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
224 "vif has been set!! mac->vif = 0x%p\n", mac->vif);
228 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
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;
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]);
246 case NL80211_IFTYPE_ADHOC:
247 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
248 "NL80211_IFTYPE_ADHOC\n");
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;
255 mac->basic_rates = 0xff0;
256 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
257 (u8 *)(&mac->basic_rates));
260 case NL80211_IFTYPE_P2P_GO:
261 mac->p2p = P2P_ROLE_GO;
263 case NL80211_IFTYPE_AP:
264 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
265 "NL80211_IFTYPE_AP\n");
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;
272 mac->basic_rates = 0xff0;
273 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
274 (u8 *)(&mac->basic_rates));
276 case NL80211_IFTYPE_MESH_POINT:
277 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
278 "NL80211_IFTYPE_MESH_POINT\n");
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;
285 mac->basic_rates = 0xff0;
286 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
287 (u8 *)(&mac->basic_rates));
290 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
291 "operation mode %d is not support!\n", vif->type);
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));
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);
310 mutex_unlock(&rtlpriv->locks.conf_mutex);
314 static void rtl_op_remove_interface(struct ieee80211_hw *hw,
315 struct ieee80211_vif *vif)
317 struct rtl_priv *rtlpriv = rtl_priv(hw);
318 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
320 mutex_lock(&rtlpriv->locks.conf_mutex);
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]);
334 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
335 *NO LINK for our hardware.
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);
345 mutex_unlock(&rtlpriv->locks.conf_mutex);
347 static int rtl_op_change_interface(struct ieee80211_hw *hw,
348 struct ieee80211_vif *vif,
349 enum nl80211_iftype new_type, bool p2p)
351 struct rtl_priv *rtlpriv = rtl_priv(hw);
353 rtl_op_remove_interface(hw, vif);
355 vif->type = new_type;
357 ret = rtl_op_add_interface(hw, vif);
358 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
364 static u16 crc16_ccitt(u8 data, u16 crc)
366 u8 shift_in, data_bit, crc_bit11, crc_bit4, crc_bit15;
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;
381 crc_bit11 = ((crc & BIT(11)) ? 1 : 0) ^ shift_in;
383 result &= (~BIT(12));
387 crc_bit4 = ((crc & BIT(4)) ? 1 : 0) ^ shift_in;
399 static u16 _calculate_wol_pattern_crc(u8 *pattern, u16 len)
404 for (i = 0; i < len; i++)
405 crc = crc16_ccitt(pattern[i], crc);
412 static void _rtl_add_wowlan_patterns(struct ieee80211_hw *hw,
413 struct cfg80211_wowlan *wow)
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};
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);
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;
453 rtl_pattern.type = UNKNOWN_TYPE;
455 /* 2. translate mask_from_os to mask_for_hw */
457 /******************************************************************************
458 * pattern from OS uses 'ethenet frame', like this:
460 | 6 | 6 | 2 | 20 | Variable | 4 |
461 |--------+--------+------+-----------+------------+-----|
462 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
465 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
467 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
468 |-------------------+--------+------+-----------+------------+-----|
469 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
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 ******************************************************************************/
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;
483 mask[j] = (mask_os[j] >> 6) & 0x3F;
484 /* Set bit 0-5 to zero */
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);
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.
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];
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);
515 /* 4. write crc & mask_for_hw to hw */
516 rtlpriv->cfg->ops->add_wowlan_pattern(hw, &rtl_pattern, i);
518 rtl_write_byte(rtlpriv, 0x698, wow->n_patterns);
521 static int rtl_op_suspend(struct ieee80211_hw *hw,
522 struct cfg80211_wowlan *wow)
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));
529 RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, "\n");
533 /* to resolve s4 can not wake up*/
534 do_gettimeofday(&ts);
535 rtlhal->last_suspend_sec = ts.tv_sec;
537 if ((ppsc->wo_wlan_mode & WAKE_ON_PATTERN_MATCH) && wow->n_patterns)
538 _rtl_add_wowlan_patterns(hw, wow);
540 rtlhal->driver_is_goingto_unload = true;
541 rtlhal->enter_pnp_sleep = true;
545 device_set_wakeup_enable(wiphy_dev(hw->wiphy), true);
549 static int rtl_op_resume(struct ieee80211_hw *hw)
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));
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;
561 /* to resovle s4 can not wake up*/
562 do_gettimeofday(&ts);
563 if (ts.tv_sec - rtlhal->last_suspend_sec < 5)
567 device_set_wakeup_enable(wiphy_dev(hw->wiphy), false);
568 ieee80211_resume_disconnect(mac->vif);
569 rtlhal->wake_from_pnp_sleep = false;
574 static int rtl_op_config(struct ieee80211_hw *hw, u32 changed)
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;
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");
592 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
593 if (hw->conf.flags & IEEE80211_CONF_IDLE)
599 *although rfoff may not cause by ips, but we will
600 *check the reason in set_rf_power_state function
602 if (unlikely(ppsc->rfpwr_state == ERFOFF))
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,
624 rtl_swlps_rf_awake(hw);
625 rtlpriv->psc.sw_ps_enabled = false;
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));
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;
646 /* channel_type is for 20&40M */
647 if (width < NL80211_CHAN_WIDTH_80)
649 cfg80211_get_chandef_type(&hw->conf.chandef);
650 if (mac->act_scanning)
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);
661 *because we should back channel to
662 *current_network.chan in in scanning,
663 *So if set_chan == current_network.chan
665 *because mac80211 tell us wrong bw40
666 *info for cisco1253 bw20, so we modify
667 *it here based on UPPER & LOWER
670 if (width >= NL80211_CHAN_WIDTH_80) {
671 if (width == NL80211_CHAN_WIDTH_80) {
672 u32 center = hw->conf.chandef.center_freq1;
674 (u32)hw->conf.chandef.chan->center_freq;
676 rtlphy->current_chan_bw =
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;
688 } else if (center - primary == 30) {
689 mac->cur_40_prime_sc =
690 PRIME_CHNL_OFFSET_LOWER;
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;
702 } else if (primary - center == 30) {
703 mac->cur_40_prime_sc =
704 PRIME_CHNL_OFFSET_UPPER;
711 switch (channel_type) {
712 case NL80211_CHAN_HT20:
713 case NL80211_CHAN_NO_HT:
715 mac->cur_40_prime_sc =
716 PRIME_CHNL_OFFSET_DONT_CARE;
717 rtlphy->current_chan_bw =
722 case NL80211_CHAN_HT40MINUS:
724 mac->cur_40_prime_sc =
725 PRIME_CHNL_OFFSET_UPPER;
726 rtlphy->current_chan_bw =
727 HT_CHANNEL_WIDTH_20_40;
735 case NL80211_CHAN_HT40PLUS:
737 mac->cur_40_prime_sc =
738 PRIME_CHNL_OFFSET_LOWER;
739 rtlphy->current_chan_bw =
740 HT_CHANNEL_WIDTH_20_40;
751 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
752 "switch case not processed\n");
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
768 if (rtlpriv->mac80211.offchan_delay) {
769 rtlpriv->mac80211.offchan_delay = false;
773 rtlphy->current_channel = wide_chan;
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);
780 mutex_unlock(&rtlpriv->locks.conf_mutex);
785 static void rtl_op_configure_filter(struct ieee80211_hw *hw,
786 unsigned int changed_flags,
787 unsigned int *new_flags, u64 multicast)
789 struct rtl_priv *rtlpriv = rtl_priv(hw);
790 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
792 *new_flags &= RTL_SUPPORTED_FILTERS;
793 if (0 == changed_flags)
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");
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");
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");
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");
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
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);
834 rtlpriv->cfg->ops->set_chk_bssid(hw, true);
838 if (changed_flags & FIF_CONTROL) {
839 if (*new_flags & FIF_CONTROL) {
840 mac->rx_conf |= rtlpriv->cfg->maps[MAC_RCR_ACF];
842 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
843 "Enable receive control frame.\n");
845 mac->rx_conf &= ~rtlpriv->cfg->maps[MAC_RCR_ACF];
846 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_LOUD,
847 "Disable receive control frame.\n");
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");
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");
863 static int rtl_op_sta_add(struct ieee80211_hw *hw,
864 struct ieee80211_vif *vif,
865 struct ieee80211_sta *sta)
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;
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;
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;
893 if (vif->type == NL80211_IFTYPE_ADHOC)
894 sta_entry->wireless_mode = WIRELESS_MODE_A;
896 /*disable cck rate for p2p*/
898 sta->supp_rates[0] &= 0xfffffff0;
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);
909 static int rtl_op_sta_remove(struct ieee80211_hw *hw,
910 struct ieee80211_vif *vif,
911 struct ieee80211_sta *sta)
913 struct rtl_priv *rtlpriv = rtl_priv(hw);
914 struct rtl_sta_info *sta_entry;
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);
927 static int _rtl_get_hal_qnum(u16 queue)
952 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
953 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
955 static int rtl_op_conf_tx(struct ieee80211_hw *hw,
956 struct ieee80211_vif *vif, u16 queue,
957 const struct ieee80211_tx_queue_params *param)
959 struct rtl_priv *rtlpriv = rtl_priv(hw);
960 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
963 if (queue >= AC_MAX) {
964 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
965 "queue number %d is incorrect!\n", queue);
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);
979 static void rtl_op_bss_info_changed(struct ieee80211_hw *hw,
980 struct ieee80211_vif *vif,
981 struct ieee80211_bss_conf *bss_conf,
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));
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");
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,
1005 [RTL_IBSS_INT_MASKS], 0);
1007 if (rtlpriv->cfg->ops->linked_set_reg)
1008 rtlpriv->cfg->ops->linked_set_reg(hw);
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");
1017 mac->beacon_enabled = 0;
1018 rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
1020 [RTL_IBSS_INT_MASKS]);
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);
1031 /*TODO: reference to enum ieee80211_bss_change */
1032 if (changed & BSS_CHANGED_ASSOC) {
1034 if (bss_conf->assoc) {
1035 struct ieee80211_sta *sta = NULL;
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);
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);
1054 if (rtlpriv->cfg->ops->linked_set_reg)
1055 rtlpriv->cfg->ops->linked_set_reg(hw);
1058 sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
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);
1071 if (rtlhal->current_bandtype == BAND_ON_5G) {
1072 mac->mode = WIRELESS_MODE_A;
1074 if (sta->supp_rates[0] <= 0xf)
1075 mac->mode = WIRELESS_MODE_B;
1077 mac->mode = WIRELESS_MODE_G;
1080 if (sta->ht_cap.ht_supported) {
1081 if (rtlhal->current_bandtype == BAND_ON_2_4G)
1082 mac->mode = WIRELESS_MODE_N_24G;
1084 mac->mode = WIRELESS_MODE_N_5G;
1087 if (sta->vht_cap.vht_supported) {
1088 if (rtlhal->current_bandtype == BAND_ON_5G)
1089 mac->mode = WIRELESS_MODE_AC_5G;
1091 mac->mode = WIRELESS_MODE_AC_24G;
1094 if (vif->type == NL80211_IFTYPE_STATION && sta)
1095 rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 0);
1098 /* to avoid AP Disassociation caused by inactivity */
1099 rtlpriv->cfg->ops->set_hw_reg(hw,
1101 (u8 *)(&keep_alive));
1103 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
1104 "BSS_CHANGED_ASSOC\n");
1106 mstatus = RT_MEDIA_DISCONNECT;
1108 if (mac->link_state == MAC80211_LINKED) {
1109 rtlpriv->enter_ps = false;
1110 schedule_work(&rtlpriv->works.lps_change_work);
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;
1119 if (rtlpriv->dm.supp_phymode_switch) {
1120 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1121 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
1123 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
1124 "BSS_CHANGED_UN_ASSOC\n");
1126 rtlpriv->cfg->ops->set_network_type(hw, vif->type);
1128 * To tell firmware we have connected or disconnected
1130 rtlpriv->cfg->ops->set_hw_reg(hw,
1131 HW_VAR_H2C_FW_JOINBSSRPT,
1133 ppsc->report_linked = (mstatus == RT_MEDIA_CONNECT) ?
1136 if (rtlpriv->cfg->ops->get_btc_status())
1137 rtlpriv->btcoexist.btc_ops->btc_mediastatus_notify(
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;
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);
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));
1157 if (changed & BSS_CHANGED_ERP_SLOT) {
1158 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1159 "BSS_CHANGED_ERP_SLOT\n");
1161 if (bss_conf->use_short_slot)
1162 mac->slot_time = RTL_SLOT_TIME_9;
1164 mac->slot_time = RTL_SLOT_TIME_20;
1166 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
1167 (u8 *)(&mac->slot_time));
1170 if (changed & BSS_CHANGED_HT) {
1171 struct ieee80211_sta *sta = NULL;
1173 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_TRACE,
1174 "BSS_CHANGED_HT\n");
1177 sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
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;
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);
1198 if (changed & BSS_CHANGED_BSSID) {
1200 struct ieee80211_sta *sta = NULL;
1202 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BSSID,
1203 (u8 *)bss_conf->bssid);
1205 RT_TRACE(rtlpriv, COMP_MAC80211, DBG_DMESG,
1206 "bssid: %pM\n", bss_conf->bssid);
1208 mac->vendor = PEER_UNKNOWN;
1209 memcpy(mac->bssid, bss_conf->bssid, ETH_ALEN);
1212 sta = ieee80211_find_sta(vif, (u8 *)bss_conf->bssid);
1218 if (rtlhal->current_bandtype == BAND_ON_5G) {
1219 mac->mode = WIRELESS_MODE_A;
1221 if (sta->supp_rates[0] <= 0xf)
1222 mac->mode = WIRELESS_MODE_B;
1224 mac->mode = WIRELESS_MODE_G;
1227 if (sta->ht_cap.ht_supported) {
1228 if (rtlhal->current_bandtype == BAND_ON_2_4G)
1229 mac->mode = WIRELESS_MODE_N_24G;
1231 mac->mode = WIRELESS_MODE_N_5G;
1234 if (sta->vht_cap.vht_supported) {
1235 if (rtlhal->current_bandtype == BAND_ON_5G)
1236 mac->mode = WIRELESS_MODE_AC_5G;
1238 mac->mode = WIRELESS_MODE_AC_24G;
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;
1249 if (sta->ht_cap.ht_supported) {
1250 mac->ht_enable = true;
1253 * for cisco 1252 bw20 it's wrong
1254 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1255 * mac->bw_40 = true;
1260 if (sta->vht_cap.vht_supported)
1261 mac->vht_enable = true;
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;
1269 basic_rates = sta->supp_rates[0];
1271 mac->basic_rates = basic_rates;
1272 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_BASIC_RATE,
1273 (u8 *)(&basic_rates));
1278 mutex_unlock(&rtlpriv->locks.conf_mutex);
1281 static u64 rtl_op_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1283 struct rtl_priv *rtlpriv = rtl_priv(hw);
1286 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&tsf));
1290 static void rtl_op_set_tsf(struct ieee80211_hw *hw,
1291 struct ieee80211_vif *vif, u64 tsf)
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;
1298 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_CORRECT_TSF, (u8 *)(&bibss));
1301 static void rtl_op_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1303 struct rtl_priv *rtlpriv = rtl_priv(hw);
1306 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_DUAL_TSF_RST, (u8 *)(&tmp));
1309 static 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)
1315 case STA_NOTIFY_SLEEP:
1317 case STA_NOTIFY_AWAKE:
1324 static 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,
1330 struct rtl_priv *rtlpriv = rtl_priv(hw);
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);
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);
1357 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1358 "IEEE80211_AMPDU_ERR!!!!:\n");
1364 static void rtl_op_sw_scan_start(struct ieee80211_hw *hw)
1366 struct rtl_priv *rtlpriv = rtl_priv(hw);
1367 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
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;
1376 if (rtlpriv->cfg->ops->get_btc_status())
1377 rtlpriv->btcoexist.btc_ops->btc_scan_notify(rtlpriv, 1);
1379 if (rtlpriv->dm.supp_phymode_switch) {
1380 if (rtlpriv->cfg->ops->chk_switch_dmdp)
1381 rtlpriv->cfg->ops->chk_switch_dmdp(hw);
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;
1393 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
1395 rtlpriv->cfg->ops->led_control(hw, LED_CTL_SITE_SURVEY);
1396 rtlpriv->cfg->ops->scan_operation_backup(hw, SCAN_OPT_BACKUP_BAND0);
1399 static void rtl_op_sw_scan_complete(struct ieee80211_hw *hw)
1401 struct rtl_priv *rtlpriv = rtl_priv(hw);
1402 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
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)
1410 /* p2p will use 1/6/11 to scan */
1411 if (mac->n_channels == 3)
1412 mac->p2p_in_use = true;
1414 mac->p2p_in_use = false;
1415 mac->n_channels = 0;
1417 rtlpriv->rtlhal.load_imrandiqk_setting_for2g = false;
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);
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);
1432 static 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)
1436 struct rtl_priv *rtlpriv = rtl_priv(hw);
1437 u8 key_type = NO_ENCRYPTION;
1439 bool group_key = false;
1440 bool wep_only = false;
1442 u8 mac_addr[ETH_ALEN];
1443 u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
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 */
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))
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;
1461 mutex_lock(&rtlpriv->locks.conf_mutex);
1462 /* <1> get encryption alg */
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");
1469 case WLAN_CIPHER_SUITE_WEP104:
1470 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:WEP104\n");
1471 key_type = WEP104_ENCRYPTION;
1473 case WLAN_CIPHER_SUITE_TKIP:
1474 key_type = TKIP_ENCRYPTION;
1475 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:TKIP\n");
1477 case WLAN_CIPHER_SUITE_CCMP:
1478 key_type = AESCCMP_ENCRYPTION;
1479 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "alg:CCMP\n");
1481 case WLAN_CIPHER_SUITE_AES_CMAC:
1482 /* HW don't support CMAC encryption,
1483 * use software CMAC encryption
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");
1492 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1493 "alg_err:%x!!!!:\n", key->cipher);
1496 if (key_type == WEP40_ENCRYPTION ||
1497 key_type == WEP104_ENCRYPTION ||
1498 vif->type == NL80211_IFTYPE_ADHOC)
1499 rtlpriv->sec.use_defaultkey = true;
1501 /* <2> get key_idx */
1502 key_idx = (u8) (key->keyidx);
1505 /* <3> if pairwise key enable_hw_sec */
1506 group_key = !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE);
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
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) {
1524 rtlpriv->cfg->ops->enable_hw_sec(hw);
1527 if ((!group_key) || (vif->type == NL80211_IFTYPE_ADHOC) ||
1528 rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION) {
1529 if (rtlpriv->sec.pairwise_enc_algorithm ==
1531 (key_type == WEP40_ENCRYPTION ||
1532 key_type == WEP104_ENCRYPTION))
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",
1538 rtlpriv->cfg->ops->enable_hw_sec(hw);
1541 /* <4> set key based on cmd */
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,
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");
1570 "pairwise key without mac_addr\n");
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);
1585 rtlpriv->cfg->ops->set_key(hw, key_idx, mac_addr,
1586 group_key, key_type, wep_only,
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;
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) {
1605 rtl_cam_del_entry(hw, sta->addr);
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);
1611 *mac80211 will delete entrys one by one,
1612 *so don't use rtl_cam_reset_all_entry
1613 *or clear all entry here.
1615 rtl_cam_delete_one_entry(hw, mac_addr, key_idx);
1618 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1619 "cmd_err:%x!!!!:\n", cmd);
1622 mutex_unlock(&rtlpriv->locks.conf_mutex);
1623 rtlpriv->sec.being_setkey = false;
1627 static void rtl_op_rfkill_poll(struct ieee80211_hw *hw)
1629 struct rtl_priv *rtlpriv = rtl_priv(hw);
1635 if (!test_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status))
1638 mutex_lock(&rtlpriv->locks.conf_mutex);
1640 /*if Radio On return true here */
1641 radio_state = rtlpriv->cfg->ops->radio_onoff_checking(hw, &valid);
1644 if (unlikely(radio_state != rtlpriv->rfkill.rfkill_state)) {
1645 rtlpriv->rfkill.rfkill_state = radio_state;
1647 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1648 "wireless radio switch turned %s\n",
1649 radio_state ? "on" : "off");
1651 blocked = (rtlpriv->rfkill.rfkill_state == 1) ? 0 : 1;
1652 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1656 mutex_unlock(&rtlpriv->locks.conf_mutex);
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 */
1663 static void rtl_op_flush(struct ieee80211_hw *hw,
1664 struct ieee80211_vif *vif,
1668 struct rtl_priv *rtlpriv = rtl_priv(hw);
1670 if (rtlpriv->intf_ops->flush)
1671 rtlpriv->intf_ops->flush(hw, queues, drop);
1675 * This routine deals with the Power Configuration CMD
1676 * parsing for RTL8723/RTL8188E Series IC.
1678 * We should follow specific format that was released from HW SD.
1680 bool rtl_hal_pwrseqcmdparsing(struct rtl_priv *rtlpriv, u8 cut_version,
1681 u8 faversion, u8 interface_type,
1682 struct wlan_pwr_cfg pwrcfgcmd[])
1684 struct wlan_pwr_cfg cfg_cmd = {0};
1685 bool polling_bit = false;
1689 u32 polling_count = 0;
1690 u32 max_polling_cnt = 5000;
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));
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)) {
1708 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1709 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
1712 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1713 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_WRITE\n");
1714 offset = GET_PWR_CFG_OFFSET(cfg_cmd);
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));
1722 /*Write the value back to sytem register*/
1723 rtl_write_byte(rtlpriv, offset, value);
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);
1732 value = rtl_read_byte(rtlpriv, offset);
1734 value &= GET_PWR_CFG_MASK(cfg_cmd);
1736 (GET_PWR_CFG_VALUE(cfg_cmd) &
1737 GET_PWR_CFG_MASK(cfg_cmd)))
1742 if (polling_count++ > max_polling_cnt)
1744 } while (!polling_bit);
1747 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1748 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n");
1749 if (GET_PWR_CFG_VALUE(cfg_cmd) ==
1751 udelay(GET_PWR_CFG_OFFSET(cfg_cmd));
1753 mdelay(GET_PWR_CFG_OFFSET(cfg_cmd));
1756 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1757 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n");
1761 "rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
1770 EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing);
1772 bool rtl_cmd_send_packet(struct ieee80211_hw *hw, struct sk_buff *skb)
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;
1781 ring = &rtlpci->tx_ring[BEACON_QUEUE];
1783 spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
1784 pskb = __skb_dequeue(&ring->queue);
1788 /*this is wrong, fill_tx_cmddesc needs update*/
1789 pdesc = &ring->desc[0];
1791 rtlpriv->cfg->ops->fill_tx_cmddesc(hw, (u8 *)pdesc, 1, 1, skb);
1793 __skb_queue_tail(&ring->queue, skb);
1795 spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
1797 rtlpriv->cfg->ops->tx_polling(hw, BEACON_QUEUE);
1801 EXPORT_SYMBOL(rtl_cmd_send_packet);
1802 const struct ieee80211_ops rtl_ops = {
1803 .start = rtl_op_start,
1804 .stop = rtl_op_stop,
1806 .add_interface = rtl_op_add_interface,
1807 .remove_interface = rtl_op_remove_interface,
1808 .change_interface = rtl_op_change_interface,
1810 .suspend = rtl_op_suspend,
1811 .resume = rtl_op_resume,
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,
1830 EXPORT_SYMBOL_GPL(rtl_ops);