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 static void rtl_fw_do_work(const struct firmware
*firmware
, void *context
,
101 struct ieee80211_hw
*hw
= context
;
102 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
105 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
106 "Firmware callback routine entered!\n");
107 complete(&rtlpriv
->firmware_loading_complete
);
109 if (rtlpriv
->cfg
->alt_fw_name
) {
110 err
= request_firmware(&firmware
,
111 rtlpriv
->cfg
->alt_fw_name
,
113 pr_info("Loading alternative firmware %s\n",
114 rtlpriv
->cfg
->alt_fw_name
);
118 pr_err("Firmware %s not available\n", rtlpriv
->cfg
->fw_name
);
119 rtlpriv
->max_fw_size
= 0;
123 if (firmware
->size
> rtlpriv
->max_fw_size
) {
124 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
125 "Firmware is too big!\n");
126 release_firmware(firmware
);
130 memcpy(rtlpriv
->rtlhal
.pfirmware
, firmware
->data
,
132 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
134 memcpy(rtlpriv
->rtlhal
.wowlan_firmware
, firmware
->data
,
136 rtlpriv
->rtlhal
.wowlan_fwsize
= firmware
->size
;
138 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
139 release_firmware(firmware
);
142 void rtl_fw_cb(const struct firmware
*firmware
, void *context
)
144 rtl_fw_do_work(firmware
, context
, false);
146 EXPORT_SYMBOL(rtl_fw_cb
);
148 void rtl_wowlan_fw_cb(const struct firmware
*firmware
, void *context
)
150 rtl_fw_do_work(firmware
, context
, true);
152 EXPORT_SYMBOL(rtl_wowlan_fw_cb
);
154 /*mutex for start & stop is must here. */
155 static int rtl_op_start(struct ieee80211_hw
*hw
)
158 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
159 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
161 if (!is_hal_stop(rtlhal
))
163 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
165 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
166 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
168 rtl_watch_dog_timer_callback((unsigned long)hw
);
169 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
173 static void rtl_op_stop(struct ieee80211_hw
*hw
)
175 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
176 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
177 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
178 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
179 bool support_remote_wakeup
= false;
181 if (is_hal_stop(rtlhal
))
184 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
185 (u8
*)(&support_remote_wakeup
));
186 /* here is must, because adhoc do stop and start,
187 * but stop with RFOFF may cause something wrong,
190 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
193 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
194 /* if wowlan supported, DON'T clear connected info */
195 if (!(support_remote_wakeup
&&
196 rtlhal
->enter_pnp_sleep
)) {
197 mac
->link_state
= MAC80211_NOLINK
;
198 eth_zero_addr(mac
->bssid
);
199 mac
->vendor
= PEER_UNKNOWN
;
202 rtl_cam_reset_sec_info(hw
);
204 rtl_deinit_deferred_work(hw
);
206 rtlpriv
->intf_ops
->adapter_stop(hw
);
208 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
211 static void rtl_op_tx(struct ieee80211_hw
*hw
,
212 struct ieee80211_tx_control
*control
,
215 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
216 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
217 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
218 struct rtl_tcb_desc tcb_desc
;
219 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
221 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
224 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
227 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
228 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
232 dev_kfree_skb_any(skb
);
235 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
236 struct ieee80211_vif
*vif
)
238 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
239 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
243 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
244 "vif has been set!! mac->vif = 0x%p\n", mac
->vif
);
248 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
252 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
253 switch (ieee80211_vif_type_p2p(vif
)) {
254 case NL80211_IFTYPE_P2P_CLIENT
:
255 mac
->p2p
= P2P_ROLE_CLIENT
;
257 case NL80211_IFTYPE_STATION
:
258 if (mac
->beacon_enabled
== 1) {
259 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
260 "NL80211_IFTYPE_STATION\n");
261 mac
->beacon_enabled
= 0;
262 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
263 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
266 case NL80211_IFTYPE_ADHOC
:
267 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
268 "NL80211_IFTYPE_ADHOC\n");
270 mac
->link_state
= MAC80211_LINKED
;
271 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
272 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
273 mac
->basic_rates
= 0xfff;
275 mac
->basic_rates
= 0xff0;
276 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
277 (u8
*)(&mac
->basic_rates
));
280 case NL80211_IFTYPE_P2P_GO
:
281 mac
->p2p
= P2P_ROLE_GO
;
283 case NL80211_IFTYPE_AP
:
284 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
285 "NL80211_IFTYPE_AP\n");
287 mac
->link_state
= MAC80211_LINKED
;
288 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
289 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
290 mac
->basic_rates
= 0xfff;
292 mac
->basic_rates
= 0xff0;
293 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
294 (u8
*)(&mac
->basic_rates
));
296 case NL80211_IFTYPE_MESH_POINT
:
297 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
298 "NL80211_IFTYPE_MESH_POINT\n");
300 mac
->link_state
= MAC80211_LINKED
;
301 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
302 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
303 mac
->basic_rates
= 0xfff;
305 mac
->basic_rates
= 0xff0;
306 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
307 (u8
*)(&mac
->basic_rates
));
310 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
311 "operation mode %d is not support!\n", vif
->type
);
317 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
318 "p2p role %x\n", vif
->type
);
319 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
320 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
321 (u8
*)(&mac
->basic_rates
));
324 mac
->opmode
= vif
->type
;
325 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
326 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
327 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
330 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
334 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
335 struct ieee80211_vif
*vif
)
337 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
338 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
340 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
342 /* Free beacon resources */
343 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
344 (vif
->type
== NL80211_IFTYPE_ADHOC
) ||
345 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
346 if (mac
->beacon_enabled
== 1) {
347 mac
->beacon_enabled
= 0;
348 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
349 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
354 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
355 *NO LINK for our hardware.
359 mac
->link_state
= MAC80211_NOLINK
;
360 eth_zero_addr(mac
->bssid
);
361 mac
->vendor
= PEER_UNKNOWN
;
362 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
363 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
365 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
367 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
368 struct ieee80211_vif
*vif
,
369 enum nl80211_iftype new_type
, bool p2p
)
371 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
373 rtl_op_remove_interface(hw
, vif
);
375 vif
->type
= new_type
;
377 ret
= rtl_op_add_interface(hw
, vif
);
378 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
384 static u16
crc16_ccitt(u8 data
, u16 crc
)
386 u8 shift_in
, data_bit
, crc_bit11
, crc_bit4
, crc_bit15
;
390 for (i
= 0; i
< 8; i
++) {
391 crc_bit15
= ((crc
& BIT(15)) ? 1 : 0);
392 data_bit
= (data
& (BIT(0) << i
) ? 1 : 0);
393 shift_in
= crc_bit15
^ data_bit
;
401 crc_bit11
= ((crc
& BIT(11)) ? 1 : 0) ^ shift_in
;
403 result
&= (~BIT(12));
407 crc_bit4
= ((crc
& BIT(4)) ? 1 : 0) ^ shift_in
;
419 static u16
_calculate_wol_pattern_crc(u8
*pattern
, u16 len
)
424 for (i
= 0; i
< len
; i
++)
425 crc
= crc16_ccitt(pattern
[i
], crc
);
432 static void _rtl_add_wowlan_patterns(struct ieee80211_hw
*hw
,
433 struct cfg80211_wowlan
*wow
)
435 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
436 struct rtl_mac
*mac
= &rtlpriv
->mac80211
;
437 struct cfg80211_pkt_pattern
*patterns
= wow
->patterns
;
438 struct rtl_wow_pattern rtl_pattern
;
439 const u8
*pattern_os
, *mask_os
;
440 u8 mask
[MAX_WOL_BIT_MASK_SIZE
] = {0};
441 u8 content
[MAX_WOL_PATTERN_SIZE
] = {0};
442 u8 broadcast_addr
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
443 u8 multicast_addr1
[2] = {0x33, 0x33};
444 u8 multicast_addr2
[3] = {0x01, 0x00, 0x5e};
448 for (i
= 0; i
< wow
->n_patterns
; i
++) {
449 memset(&rtl_pattern
, 0, sizeof(struct rtl_wow_pattern
));
450 memset(mask
, 0, MAX_WOL_BIT_MASK_SIZE
);
451 if (patterns
[i
].pattern_len
> MAX_WOL_PATTERN_SIZE
) {
452 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_WARNING
,
453 "Pattern[%d] is too long\n", i
);
456 pattern_os
= patterns
[i
].pattern
;
457 mask_len
= DIV_ROUND_UP(patterns
[i
].pattern_len
, 8);
458 mask_os
= patterns
[i
].mask
;
459 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
460 "pattern content\n", pattern_os
,
461 patterns
[i
].pattern_len
);
462 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
463 "mask content\n", mask_os
, mask_len
);
464 /* 1. unicast? multicast? or broadcast? */
465 if (memcmp(pattern_os
, broadcast_addr
, 6) == 0)
466 rtl_pattern
.type
= BROADCAST_PATTERN
;
467 else if (memcmp(pattern_os
, multicast_addr1
, 2) == 0 ||
468 memcmp(pattern_os
, multicast_addr2
, 3) == 0)
469 rtl_pattern
.type
= MULTICAST_PATTERN
;
470 else if (memcmp(pattern_os
, mac
->mac_addr
, 6) == 0)
471 rtl_pattern
.type
= UNICAST_PATTERN
;
473 rtl_pattern
.type
= UNKNOWN_TYPE
;
475 /* 2. translate mask_from_os to mask_for_hw */
477 /******************************************************************************
478 * pattern from OS uses 'ethenet frame', like this:
480 | 6 | 6 | 2 | 20 | Variable | 4 |
481 |--------+--------+------+-----------+------------+-----|
482 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
485 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
487 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
488 |-------------------+--------+------+-----------+------------+-----|
489 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
492 * Therefore, we need translate mask_from_OS to mask_to_hw.
493 * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
494 * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
495 * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
496 ******************************************************************************/
499 for (j
= 0; j
< mask_len
- 1; j
++) {
500 mask
[j
] = mask_os
[j
] >> 6;
501 mask
[j
] |= (mask_os
[j
+ 1] & 0x3F) << 2;
503 mask
[j
] = (mask_os
[j
] >> 6) & 0x3F;
504 /* Set bit 0-5 to zero */
507 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
508 "mask to hw\n", mask
, mask_len
);
509 for (j
= 0; j
< (MAX_WOL_BIT_MASK_SIZE
+ 1) / 4; j
++) {
510 rtl_pattern
.mask
[j
] = mask
[j
* 4];
511 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 1] << 8);
512 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 2] << 16);
513 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 3] << 24);
516 /* To get the wake up pattern from the mask.
517 * We do not count first 12 bits which means
518 * DA[6] and SA[6] in the pattern to match HW design.
521 for (j
= 12; j
< patterns
[i
].pattern_len
; j
++) {
522 if ((mask_os
[j
/ 8] >> (j
% 8)) & 0x01) {
523 content
[len
] = pattern_os
[j
];
528 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
529 "pattern to hw\n", content
, len
);
530 /* 3. calculate crc */
531 rtl_pattern
.crc
= _calculate_wol_pattern_crc(content
, len
);
532 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
533 "CRC_Remainder = 0x%x", rtl_pattern
.crc
);
535 /* 4. write crc & mask_for_hw to hw */
536 rtlpriv
->cfg
->ops
->add_wowlan_pattern(hw
, &rtl_pattern
, i
);
538 rtl_write_byte(rtlpriv
, 0x698, wow
->n_patterns
);
541 static int rtl_op_suspend(struct ieee80211_hw
*hw
,
542 struct cfg80211_wowlan
*wow
)
544 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
545 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
546 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
549 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
553 /* to resolve s4 can not wake up*/
554 do_gettimeofday(&ts
);
555 rtlhal
->last_suspend_sec
= ts
.tv_sec
;
557 if ((ppsc
->wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) && wow
->n_patterns
)
558 _rtl_add_wowlan_patterns(hw
, wow
);
560 rtlhal
->driver_is_goingto_unload
= true;
561 rtlhal
->enter_pnp_sleep
= true;
565 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), true);
569 static int rtl_op_resume(struct ieee80211_hw
*hw
)
571 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
572 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
573 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
576 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
577 rtlhal
->driver_is_goingto_unload
= false;
578 rtlhal
->enter_pnp_sleep
= false;
579 rtlhal
->wake_from_pnp_sleep
= true;
581 /* to resovle s4 can not wake up*/
582 do_gettimeofday(&ts
);
583 if (ts
.tv_sec
- rtlhal
->last_suspend_sec
< 5)
587 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), false);
588 ieee80211_resume_disconnect(mac
->vif
);
589 rtlhal
->wake_from_pnp_sleep
= false;
594 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
596 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
597 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
598 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
599 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
600 struct ieee80211_conf
*conf
= &hw
->conf
;
605 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
606 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /* BIT(2)*/
607 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
608 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
612 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
613 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
619 *although rfoff may not cause by ips, but we will
620 *check the reason in set_rf_power_state function
622 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
627 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
628 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
629 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
630 if (conf
->flags
& IEEE80211_CONF_PS
) {
631 rtlpriv
->psc
.sw_ps_enabled
= true;
632 /* sleep here is must, or we may recv the beacon and
633 * cause mac80211 into wrong ps state, this will cause
634 * power save nullfunc send fail, and further cause
635 * pkt loss, So sleep must quickly but not immediatly
636 * because that will cause nullfunc send by mac80211
637 * fail, and cause pkt loss, we have tested that 5mA
638 * is worked very well */
639 if (!rtlpriv
->psc
.multi_buffered
)
640 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
641 &rtlpriv
->works
.ps_work
,
644 rtl_swlps_rf_awake(hw
);
645 rtlpriv
->psc
.sw_ps_enabled
= false;
649 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
650 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
651 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
652 hw
->conf
.long_frame_max_tx_count
);
653 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
654 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
655 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
656 (u8
*)(&hw
->conf
.long_frame_max_tx_count
));
659 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
660 !rtlpriv
->proximity
.proxim_on
) {
661 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
662 enum nl80211_chan_width width
= hw
->conf
.chandef
.width
;
663 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
664 u8 wide_chan
= (u8
) channel
->hw_value
;
666 /* channel_type is for 20&40M */
667 if (width
< NL80211_CHAN_WIDTH_80
)
669 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
670 if (mac
->act_scanning
)
673 if (rtlpriv
->dm
.supp_phymode_switch
&&
674 mac
->link_state
< MAC80211_LINKED
&&
675 !mac
->act_scanning
) {
676 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
677 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
681 *because we should back channel to
682 *current_network.chan in in scanning,
683 *So if set_chan == current_network.chan
685 *because mac80211 tell us wrong bw40
686 *info for cisco1253 bw20, so we modify
687 *it here based on UPPER & LOWER
690 if (width
>= NL80211_CHAN_WIDTH_80
) {
691 if (width
== NL80211_CHAN_WIDTH_80
) {
692 u32 center
= hw
->conf
.chandef
.center_freq1
;
694 (u32
)hw
->conf
.chandef
.chan
->center_freq
;
696 rtlphy
->current_chan_bw
=
700 if (center
> primary
) {
701 mac
->cur_80_prime_sc
=
702 PRIME_CHNL_OFFSET_LOWER
;
703 if (center
- primary
== 10) {
704 mac
->cur_40_prime_sc
=
705 PRIME_CHNL_OFFSET_UPPER
;
708 } else if (center
- primary
== 30) {
709 mac
->cur_40_prime_sc
=
710 PRIME_CHNL_OFFSET_LOWER
;
715 mac
->cur_80_prime_sc
=
716 PRIME_CHNL_OFFSET_UPPER
;
717 if (primary
- center
== 10) {
718 mac
->cur_40_prime_sc
=
719 PRIME_CHNL_OFFSET_LOWER
;
722 } else if (primary
- center
== 30) {
723 mac
->cur_40_prime_sc
=
724 PRIME_CHNL_OFFSET_UPPER
;
731 switch (channel_type
) {
732 case NL80211_CHAN_HT20
:
733 case NL80211_CHAN_NO_HT
:
735 mac
->cur_40_prime_sc
=
736 PRIME_CHNL_OFFSET_DONT_CARE
;
737 rtlphy
->current_chan_bw
=
742 case NL80211_CHAN_HT40MINUS
:
744 mac
->cur_40_prime_sc
=
745 PRIME_CHNL_OFFSET_UPPER
;
746 rtlphy
->current_chan_bw
=
747 HT_CHANNEL_WIDTH_20_40
;
755 case NL80211_CHAN_HT40PLUS
:
757 mac
->cur_40_prime_sc
=
758 PRIME_CHNL_OFFSET_LOWER
;
759 rtlphy
->current_chan_bw
=
760 HT_CHANNEL_WIDTH_20_40
;
771 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
772 "switch case not processed\n");
780 /* In scanning, when before we offchannel we may send a ps=1
781 * null to AP, and then we may send a ps = 0 null to AP quickly,
782 * but first null may have caused AP to put lots of packet to
783 * hw tx buffer. These packets must be tx'd before we go off
784 * channel so we must delay more time to let AP flush these
785 * packets before going offchannel, or dis-association or
786 * delete BA will be caused by AP
788 if (rtlpriv
->mac80211
.offchan_delay
) {
789 rtlpriv
->mac80211
.offchan_delay
= false;
793 rtlphy
->current_channel
= wide_chan
;
795 rtlpriv
->cfg
->ops
->switch_channel(hw
);
796 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
797 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, channel_type
);
800 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
805 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
806 unsigned int changed_flags
,
807 unsigned int *new_flags
, u64 multicast
)
809 bool update_rcr
= false;
810 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
811 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
813 *new_flags
&= RTL_SUPPORTED_FILTERS
;
814 if (0 == changed_flags
)
817 /*TODO: we disable broadcase now, so enable here */
818 if (changed_flags
& FIF_ALLMULTI
) {
819 if (*new_flags
& FIF_ALLMULTI
) {
820 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
821 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
822 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
823 "Enable receive multicast frame\n");
825 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
826 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
827 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
828 "Disable receive multicast frame\n");
833 if (changed_flags
& FIF_FCSFAIL
) {
834 if (*new_flags
& FIF_FCSFAIL
) {
835 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
836 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
837 "Enable receive FCS error frame\n");
839 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
840 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
841 "Disable receive FCS error frame\n");
847 /* if ssid not set to hw don't check bssid
848 * here just used for linked scanning, & linked
849 * and nolink check bssid is set in set network_type
851 if ((changed_flags
& FIF_BCN_PRBRESP_PROMISC
) &&
852 (mac
->link_state
>= MAC80211_LINKED
)) {
853 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
854 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
855 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
856 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
858 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
864 if (changed_flags
& FIF_CONTROL
) {
865 if (*new_flags
& FIF_CONTROL
) {
866 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
868 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
869 "Enable receive control frame.\n");
871 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
872 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
873 "Disable receive control frame.\n");
879 if (changed_flags
& FIF_OTHER_BSS
) {
880 if (*new_flags
& FIF_OTHER_BSS
) {
881 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
882 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
883 "Enable receive other BSS's frame.\n");
885 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
886 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
887 "Disable receive other BSS's frame.\n");
894 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
895 (u8
*)(&mac
->rx_conf
));
897 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
898 struct ieee80211_vif
*vif
,
899 struct ieee80211_sta
*sta
)
901 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
902 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
903 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
904 struct rtl_sta_info
*sta_entry
;
907 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
908 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
909 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
910 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
911 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
912 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
913 if (sta
->supp_rates
[0] <= 0xf)
914 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
915 if (sta
->ht_cap
.ht_supported
)
916 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
918 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
919 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
920 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
921 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
922 if (sta
->ht_cap
.ht_supported
)
923 sta_entry
->wireless_mode
= WIRELESS_MODE_N_5G
;
924 if (sta
->vht_cap
.vht_supported
)
925 sta_entry
->wireless_mode
= WIRELESS_MODE_AC_5G
;
927 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
928 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
930 /*disable cck rate for p2p*/
932 sta
->supp_rates
[0] &= 0xfffffff0;
934 memcpy(sta_entry
->mac_addr
, sta
->addr
, ETH_ALEN
);
935 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
936 "Add sta addr is %pM\n", sta
->addr
);
937 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
943 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
944 struct ieee80211_vif
*vif
,
945 struct ieee80211_sta
*sta
)
947 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
948 struct rtl_sta_info
*sta_entry
;
950 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
951 "Remove sta addr is %pM\n", sta
->addr
);
952 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
953 sta_entry
->wireless_mode
= 0;
954 sta_entry
->ratr_index
= 0;
955 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
956 list_del(&sta_entry
->list
);
957 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
961 static int _rtl_get_hal_qnum(u16 queue
)
986 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
987 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
989 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
990 struct ieee80211_vif
*vif
, u16 queue
,
991 const struct ieee80211_tx_queue_params
*param
)
993 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
994 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
997 if (queue
>= AC_MAX
) {
998 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
999 "queue number %d is incorrect!\n", queue
);
1003 aci
= _rtl_get_hal_qnum(queue
);
1004 mac
->ac
[aci
].aifs
= param
->aifs
;
1005 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
1006 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
1007 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
1008 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
1009 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
1013 static void send_beacon_frame(struct ieee80211_hw
*hw
,
1014 struct ieee80211_vif
*vif
)
1016 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1017 struct sk_buff
*skb
= ieee80211_beacon_get(hw
, vif
);
1018 struct rtl_tcb_desc tcb_desc
;
1021 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1022 rtlpriv
->intf_ops
->adapter_tx(hw
, NULL
, skb
, &tcb_desc
);
1026 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
1027 struct ieee80211_vif
*vif
,
1028 struct ieee80211_bss_conf
*bss_conf
,
1031 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1032 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1033 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1034 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1036 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1037 if ((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1038 (vif
->type
== NL80211_IFTYPE_AP
) ||
1039 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) {
1040 if ((changed
& BSS_CHANGED_BEACON
) ||
1041 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
1042 bss_conf
->enable_beacon
)) {
1043 if (mac
->beacon_enabled
== 0) {
1044 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1045 "BSS_CHANGED_BEACON_ENABLED\n");
1047 /*start hw beacon interrupt. */
1048 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
1049 mac
->beacon_enabled
= 1;
1050 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
1052 [RTL_IBSS_INT_MASKS
], 0);
1054 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1055 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1056 send_beacon_frame(hw
, vif
);
1059 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
1060 !bss_conf
->enable_beacon
)) {
1061 if (mac
->beacon_enabled
== 1) {
1062 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1063 "ADHOC DISABLE BEACON\n");
1065 mac
->beacon_enabled
= 0;
1066 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
1068 [RTL_IBSS_INT_MASKS
]);
1071 if (changed
& BSS_CHANGED_BEACON_INT
) {
1072 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
1073 "BSS_CHANGED_BEACON_INT\n");
1074 mac
->beacon_interval
= bss_conf
->beacon_int
;
1075 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
1079 /*TODO: reference to enum ieee80211_bss_change */
1080 if (changed
& BSS_CHANGED_ASSOC
) {
1082 if (bss_conf
->assoc
) {
1083 struct ieee80211_sta
*sta
= NULL
;
1086 mstatus
= RT_MEDIA_CONNECT
;
1087 /* we should reset all sec info & cam
1088 * before set cam after linked, we should not
1089 * reset in disassoc, that will cause tkip->wep
1090 * fail because some flag will be wrong */
1091 /* reset sec info */
1092 rtl_cam_reset_sec_info(hw
);
1093 /* reset cam to fix wep fail issue
1094 * when change from wpa to wep */
1095 rtl_cam_reset_all_entry(hw
);
1097 mac
->link_state
= MAC80211_LINKED
;
1098 mac
->cnt_after_linked
= 0;
1099 mac
->assoc_id
= bss_conf
->aid
;
1100 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1102 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1103 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1106 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1111 RT_TRACE(rtlpriv
, COMP_EASY_CONCURRENT
, DBG_LOUD
,
1112 "send PS STATIC frame\n");
1113 if (rtlpriv
->dm
.supp_phymode_switch
) {
1114 if (sta
->ht_cap
.ht_supported
)
1115 rtl_send_smps_action(hw
, sta
,
1116 IEEE80211_SMPS_STATIC
);
1119 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1120 mac
->mode
= WIRELESS_MODE_A
;
1122 if (sta
->supp_rates
[0] <= 0xf)
1123 mac
->mode
= WIRELESS_MODE_B
;
1125 mac
->mode
= WIRELESS_MODE_G
;
1128 if (sta
->ht_cap
.ht_supported
) {
1129 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1130 mac
->mode
= WIRELESS_MODE_N_24G
;
1132 mac
->mode
= WIRELESS_MODE_N_5G
;
1135 if (sta
->vht_cap
.vht_supported
) {
1136 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1137 mac
->mode
= WIRELESS_MODE_AC_5G
;
1139 mac
->mode
= WIRELESS_MODE_AC_24G
;
1142 if (vif
->type
== NL80211_IFTYPE_STATION
&& sta
)
1143 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0);
1146 /* to avoid AP Disassociation caused by inactivity */
1147 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1149 (u8
*)(&keep_alive
));
1151 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1152 "BSS_CHANGED_ASSOC\n");
1154 mstatus
= RT_MEDIA_DISCONNECT
;
1156 if (mac
->link_state
== MAC80211_LINKED
) {
1157 rtlpriv
->enter_ps
= false;
1158 schedule_work(&rtlpriv
->works
.lps_change_work
);
1160 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
1161 rtl_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
1162 mac
->link_state
= MAC80211_NOLINK
;
1163 eth_zero_addr(mac
->bssid
);
1164 mac
->vendor
= PEER_UNKNOWN
;
1167 if (rtlpriv
->dm
.supp_phymode_switch
) {
1168 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1169 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1171 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1172 "BSS_CHANGED_UN_ASSOC\n");
1174 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
1176 * To tell firmware we have connected or disconnected
1178 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1179 HW_VAR_H2C_FW_JOINBSSRPT
,
1181 ppsc
->report_linked
= (mstatus
== RT_MEDIA_CONNECT
) ?
1184 if (rtlpriv
->cfg
->ops
->get_btc_status())
1185 rtlpriv
->btcoexist
.btc_ops
->btc_mediastatus_notify(
1189 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1190 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1191 "BSS_CHANGED_ERP_CTS_PROT\n");
1192 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
1195 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1196 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
1197 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
1198 bss_conf
->use_short_preamble
);
1200 mac
->short_preamble
= bss_conf
->use_short_preamble
;
1201 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
1202 (u8
*)(&mac
->short_preamble
));
1205 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1206 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1207 "BSS_CHANGED_ERP_SLOT\n");
1209 if (bss_conf
->use_short_slot
)
1210 mac
->slot_time
= RTL_SLOT_TIME_9
;
1212 mac
->slot_time
= RTL_SLOT_TIME_20
;
1214 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
1215 (u8
*)(&mac
->slot_time
));
1218 if (changed
& BSS_CHANGED_HT
) {
1219 struct ieee80211_sta
*sta
= NULL
;
1221 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1222 "BSS_CHANGED_HT\n");
1225 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1227 if (sta
->ht_cap
.ampdu_density
>
1228 mac
->current_ampdu_density
)
1229 mac
->current_ampdu_density
=
1230 sta
->ht_cap
.ampdu_density
;
1231 if (sta
->ht_cap
.ampdu_factor
<
1232 mac
->current_ampdu_factor
)
1233 mac
->current_ampdu_factor
=
1234 sta
->ht_cap
.ampdu_factor
;
1238 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
1239 (u8
*)(&mac
->max_mss_density
));
1240 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
1241 &mac
->current_ampdu_factor
);
1242 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
1243 &mac
->current_ampdu_density
);
1246 if (changed
& BSS_CHANGED_BSSID
) {
1248 struct ieee80211_sta
*sta
= NULL
;
1250 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
1251 (u8
*)bss_conf
->bssid
);
1253 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1254 "bssid: %pM\n", bss_conf
->bssid
);
1256 mac
->vendor
= PEER_UNKNOWN
;
1257 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1260 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1266 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1267 mac
->mode
= WIRELESS_MODE_A
;
1269 if (sta
->supp_rates
[0] <= 0xf)
1270 mac
->mode
= WIRELESS_MODE_B
;
1272 mac
->mode
= WIRELESS_MODE_G
;
1275 if (sta
->ht_cap
.ht_supported
) {
1276 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1277 mac
->mode
= WIRELESS_MODE_N_24G
;
1279 mac
->mode
= WIRELESS_MODE_N_5G
;
1282 if (sta
->vht_cap
.vht_supported
) {
1283 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1284 mac
->mode
= WIRELESS_MODE_AC_5G
;
1286 mac
->mode
= WIRELESS_MODE_AC_24G
;
1289 /* just station need it, because ibss & ap mode will
1290 * set in sta_add, and will be NULL here */
1291 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1292 struct rtl_sta_info
*sta_entry
;
1293 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1294 sta_entry
->wireless_mode
= mac
->mode
;
1297 if (sta
->ht_cap
.ht_supported
) {
1298 mac
->ht_enable
= true;
1301 * for cisco 1252 bw20 it's wrong
1302 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1303 * mac->bw_40 = true;
1308 if (sta
->vht_cap
.vht_supported
)
1309 mac
->vht_enable
= true;
1311 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1312 /* for 5G must << RATE_6M_INDEX = 4,
1313 * because 5G have no cck rate*/
1314 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1315 basic_rates
= sta
->supp_rates
[1] << 4;
1317 basic_rates
= sta
->supp_rates
[0];
1319 mac
->basic_rates
= basic_rates
;
1320 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
1321 (u8
*)(&basic_rates
));
1326 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1329 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1331 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1334 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&tsf
));
1338 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
,
1339 struct ieee80211_vif
*vif
, u64 tsf
)
1341 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1342 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1343 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
1346 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&bibss
));
1349 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1351 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1354 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*)(&tmp
));
1357 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
1358 struct ieee80211_vif
*vif
,
1359 enum sta_notify_cmd cmd
,
1360 struct ieee80211_sta
*sta
)
1363 case STA_NOTIFY_SLEEP
:
1365 case STA_NOTIFY_AWAKE
:
1372 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
1373 struct ieee80211_vif
*vif
,
1374 enum ieee80211_ampdu_mlme_action action
,
1375 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
1376 u8 buf_size
, bool amsdu
)
1378 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1381 case IEEE80211_AMPDU_TX_START
:
1382 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1383 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid
);
1384 return rtl_tx_agg_start(hw
, vif
, sta
, tid
, ssn
);
1385 case IEEE80211_AMPDU_TX_STOP_CONT
:
1386 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1387 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1388 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1389 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
);
1390 return rtl_tx_agg_stop(hw
, vif
, sta
, tid
);
1391 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1392 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1393 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
);
1394 rtl_tx_agg_oper(hw
, sta
, tid
);
1396 case IEEE80211_AMPDU_RX_START
:
1397 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1398 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid
);
1399 return rtl_rx_agg_start(hw
, sta
, tid
);
1400 case IEEE80211_AMPDU_RX_STOP
:
1401 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1402 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
);
1403 return rtl_rx_agg_stop(hw
, sta
, tid
);
1405 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1406 "IEEE80211_AMPDU_ERR!!!!:\n");
1412 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
,
1413 struct ieee80211_vif
*vif
,
1416 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1417 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1419 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1420 mac
->act_scanning
= true;
1421 if (rtlpriv
->link_info
.higher_busytraffic
) {
1422 mac
->skip_scan
= true;
1426 if (rtlpriv
->cfg
->ops
->get_btc_status())
1427 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 1);
1429 if (rtlpriv
->dm
.supp_phymode_switch
) {
1430 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1431 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1434 if (mac
->link_state
== MAC80211_LINKED
) {
1435 rtlpriv
->enter_ps
= false;
1436 schedule_work(&rtlpriv
->works
.lps_change_work
);
1437 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1443 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1445 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1446 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP_BAND0
);
1449 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
,
1450 struct ieee80211_vif
*vif
)
1452 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1453 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1455 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1456 mac
->act_scanning
= false;
1457 mac
->skip_scan
= false;
1458 if (rtlpriv
->link_info
.higher_busytraffic
)
1461 /* p2p will use 1/6/11 to scan */
1462 if (mac
->n_channels
== 3)
1463 mac
->p2p_in_use
= true;
1465 mac
->p2p_in_use
= false;
1466 mac
->n_channels
= 0;
1468 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1470 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1471 mac
->link_state
= MAC80211_LINKED
;
1472 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1473 /* fix fwlps issue */
1474 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1478 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1479 if (rtlpriv
->cfg
->ops
->get_btc_status())
1480 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 0);
1483 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1484 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1485 struct ieee80211_key_conf
*key
)
1487 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1488 u8 key_type
= NO_ENCRYPTION
;
1490 bool group_key
= false;
1491 bool wep_only
= false;
1493 u8 mac_addr
[ETH_ALEN
];
1494 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1496 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1497 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1498 "not open hw encryption\n");
1499 return -ENOSPC
; /*User disabled HW-crypto */
1501 /* To support IBSS, use sw-crypto for GTK */
1502 if (((vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1503 (vif
->type
== NL80211_IFTYPE_MESH_POINT
)) &&
1504 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1506 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1507 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1508 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1509 sta
? sta
->addr
: bcast_addr
);
1510 rtlpriv
->sec
.being_setkey
= true;
1512 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1513 /* <1> get encryption alg */
1515 switch (key
->cipher
) {
1516 case WLAN_CIPHER_SUITE_WEP40
:
1517 key_type
= WEP40_ENCRYPTION
;
1518 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP40\n");
1520 case WLAN_CIPHER_SUITE_WEP104
:
1521 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP104\n");
1522 key_type
= WEP104_ENCRYPTION
;
1524 case WLAN_CIPHER_SUITE_TKIP
:
1525 key_type
= TKIP_ENCRYPTION
;
1526 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:TKIP\n");
1528 case WLAN_CIPHER_SUITE_CCMP
:
1529 key_type
= AESCCMP_ENCRYPTION
;
1530 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CCMP\n");
1532 case WLAN_CIPHER_SUITE_AES_CMAC
:
1533 /* HW don't support CMAC encryption,
1534 * use software CMAC encryption
1536 key_type
= AESCMAC_ENCRYPTION
;
1537 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CMAC\n");
1538 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1539 "HW don't support CMAC encrypiton, use software CMAC encrypiton\n");
1543 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1544 "alg_err:%x!!!!:\n", key
->cipher
);
1547 if (key_type
== WEP40_ENCRYPTION
||
1548 key_type
== WEP104_ENCRYPTION
||
1549 vif
->type
== NL80211_IFTYPE_ADHOC
)
1550 rtlpriv
->sec
.use_defaultkey
= true;
1552 /* <2> get key_idx */
1553 key_idx
= (u8
) (key
->keyidx
);
1556 /* <3> if pairwise key enable_hw_sec */
1557 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1559 /* wep always be group key, but there are two conditions:
1560 * 1) wep only: is just for wep enc, in this condition
1561 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1562 * will be true & enable_hw_sec will be set when wep
1564 * 2) wep(group) + AES(pairwise): some AP like cisco
1565 * may use it, in this condition enable_hw_sec will not
1566 * be set when wep key setting */
1567 /* we must reset sec_info after lingked before set key,
1568 * or some flag will be wrong*/
1569 if (vif
->type
== NL80211_IFTYPE_AP
||
1570 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1571 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1572 key_type
== WEP104_ENCRYPTION
) {
1575 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1578 if ((!group_key
) || (vif
->type
== NL80211_IFTYPE_ADHOC
) ||
1579 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1580 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1582 (key_type
== WEP40_ENCRYPTION
||
1583 key_type
== WEP104_ENCRYPTION
))
1585 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1586 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1587 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1589 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1592 /* <4> set key based on cmd */
1596 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1597 "set WEP(group/pairwise) key\n");
1598 /* Pairwise key with an assigned MAC address. */
1599 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1600 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1601 /*set local buf about wep key. */
1602 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1603 key
->key
, key
->keylen
);
1604 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1605 eth_zero_addr(mac_addr
);
1606 } else if (group_key
) { /* group key */
1607 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1610 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1611 /*set local buf about group key. */
1612 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1613 key
->key
, key
->keylen
);
1614 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1615 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1616 } else { /* pairwise key */
1617 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1618 "set pairwise key\n");
1621 "pairwise key without mac_addr\n");
1626 /* Pairwise key with an assigned MAC address. */
1627 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1628 /*set local buf about pairwise key. */
1629 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1630 key
->key
, key
->keylen
);
1631 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1632 rtlpriv
->sec
.pairwise_key
=
1633 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1634 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1636 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1637 group_key
, key_type
, wep_only
,
1639 /* <5> tell mac80211 do something: */
1640 /*must use sw generate IV, or can not work !!!!. */
1641 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1642 key
->hw_key_idx
= key_idx
;
1643 if (key_type
== TKIP_ENCRYPTION
)
1644 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1645 /*use software CCMP encryption for management frames (MFP) */
1646 if (key_type
== AESCCMP_ENCRYPTION
)
1647 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1650 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1651 "disable key delete one entry\n");
1652 /*set local buf about wep key. */
1653 if (vif
->type
== NL80211_IFTYPE_AP
||
1654 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1656 rtl_cam_del_entry(hw
, sta
->addr
);
1658 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1659 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1660 eth_zero_addr(mac_addr
);
1662 *mac80211 will delete entrys one by one,
1663 *so don't use rtl_cam_reset_all_entry
1664 *or clear all entry here.
1666 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1669 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1670 "cmd_err:%x!!!!:\n", cmd
);
1673 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1674 rtlpriv
->sec
.being_setkey
= false;
1678 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1680 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1686 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1689 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1691 /*if Radio On return true here */
1692 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1695 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1696 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1698 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
1699 "wireless radio switch turned %s\n",
1700 radio_state
? "on" : "off");
1702 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1703 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1707 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1710 /* this function is called by mac80211 to flush tx buffer
1711 * before switch channle or power save, or tx buffer packet
1712 * maybe send after offchannel or rf sleep, this may cause
1713 * dis-association by AP */
1714 static void rtl_op_flush(struct ieee80211_hw
*hw
,
1715 struct ieee80211_vif
*vif
,
1719 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1721 if (rtlpriv
->intf_ops
->flush
)
1722 rtlpriv
->intf_ops
->flush(hw
, queues
, drop
);
1726 * This routine deals with the Power Configuration CMD
1727 * parsing for RTL8723/RTL8188E Series IC.
1729 * We should follow specific format that was released from HW SD.
1731 bool rtl_hal_pwrseqcmdparsing(struct rtl_priv
*rtlpriv
, u8 cut_version
,
1732 u8 faversion
, u8 interface_type
,
1733 struct wlan_pwr_cfg pwrcfgcmd
[])
1735 struct wlan_pwr_cfg cfg_cmd
= {0};
1736 bool polling_bit
= false;
1740 u32 polling_count
= 0;
1741 u32 max_polling_cnt
= 5000;
1744 cfg_cmd
= pwrcfgcmd
[ary_idx
];
1745 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1746 "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n",
1747 GET_PWR_CFG_OFFSET(cfg_cmd
),
1748 GET_PWR_CFG_CUT_MASK(cfg_cmd
),
1749 GET_PWR_CFG_FAB_MASK(cfg_cmd
),
1750 GET_PWR_CFG_INTF_MASK(cfg_cmd
),
1751 GET_PWR_CFG_BASE(cfg_cmd
), GET_PWR_CFG_CMD(cfg_cmd
),
1752 GET_PWR_CFG_MASK(cfg_cmd
), GET_PWR_CFG_VALUE(cfg_cmd
));
1754 if ((GET_PWR_CFG_FAB_MASK(cfg_cmd
)&faversion
) &&
1755 (GET_PWR_CFG_CUT_MASK(cfg_cmd
)&cut_version
) &&
1756 (GET_PWR_CFG_INTF_MASK(cfg_cmd
)&interface_type
)) {
1757 switch (GET_PWR_CFG_CMD(cfg_cmd
)) {
1759 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1760 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
1763 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1764 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_WRITE\n");
1765 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1767 /*Read the value from system register*/
1768 value
= rtl_read_byte(rtlpriv
, offset
);
1769 value
&= (~(GET_PWR_CFG_MASK(cfg_cmd
)));
1770 value
|= (GET_PWR_CFG_VALUE(cfg_cmd
) &
1771 GET_PWR_CFG_MASK(cfg_cmd
));
1773 /*Write the value back to sytem register*/
1774 rtl_write_byte(rtlpriv
, offset
, value
);
1776 case PWR_CMD_POLLING
:
1777 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1778 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n");
1779 polling_bit
= false;
1780 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1783 value
= rtl_read_byte(rtlpriv
, offset
);
1785 value
&= GET_PWR_CFG_MASK(cfg_cmd
);
1787 (GET_PWR_CFG_VALUE(cfg_cmd
) &
1788 GET_PWR_CFG_MASK(cfg_cmd
)))
1793 if (polling_count
++ > max_polling_cnt
)
1795 } while (!polling_bit
);
1798 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1799 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n");
1800 if (GET_PWR_CFG_VALUE(cfg_cmd
) ==
1802 udelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1804 mdelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1807 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1808 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n");
1812 "rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
1821 EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing
);
1823 bool rtl_cmd_send_packet(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1825 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1826 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1827 struct rtl8192_tx_ring
*ring
;
1828 struct rtl_tx_desc
*pdesc
;
1829 unsigned long flags
;
1830 struct sk_buff
*pskb
= NULL
;
1832 ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
1834 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1835 pskb
= __skb_dequeue(&ring
->queue
);
1839 /*this is wrong, fill_tx_cmddesc needs update*/
1840 pdesc
= &ring
->desc
[0];
1842 rtlpriv
->cfg
->ops
->fill_tx_cmddesc(hw
, (u8
*)pdesc
, 1, 1, skb
);
1844 __skb_queue_tail(&ring
->queue
, skb
);
1846 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1848 rtlpriv
->cfg
->ops
->tx_polling(hw
, BEACON_QUEUE
);
1852 EXPORT_SYMBOL(rtl_cmd_send_packet
);
1853 const struct ieee80211_ops rtl_ops
= {
1854 .start
= rtl_op_start
,
1855 .stop
= rtl_op_stop
,
1857 .add_interface
= rtl_op_add_interface
,
1858 .remove_interface
= rtl_op_remove_interface
,
1859 .change_interface
= rtl_op_change_interface
,
1861 .suspend
= rtl_op_suspend
,
1862 .resume
= rtl_op_resume
,
1864 .config
= rtl_op_config
,
1865 .configure_filter
= rtl_op_configure_filter
,
1866 .set_key
= rtl_op_set_key
,
1867 .conf_tx
= rtl_op_conf_tx
,
1868 .bss_info_changed
= rtl_op_bss_info_changed
,
1869 .get_tsf
= rtl_op_get_tsf
,
1870 .set_tsf
= rtl_op_set_tsf
,
1871 .reset_tsf
= rtl_op_reset_tsf
,
1872 .sta_notify
= rtl_op_sta_notify
,
1873 .ampdu_action
= rtl_op_ampdu_action
,
1874 .sw_scan_start
= rtl_op_sw_scan_start
,
1875 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1876 .rfkill_poll
= rtl_op_rfkill_poll
,
1877 .sta_add
= rtl_op_sta_add
,
1878 .sta_remove
= rtl_op_sta_remove
,
1879 .flush
= rtl_op_flush
,
1881 EXPORT_SYMBOL_GPL(rtl_ops
);
1883 bool rtl_btc_status_false(void)
1887 EXPORT_SYMBOL_GPL(rtl_btc_status_false
);
1889 void rtl_dm_diginit(struct ieee80211_hw
*hw
, u32 cur_igvalue
)
1891 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1892 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
1894 dm_digtable
->dig_enable_flag
= true;
1895 dm_digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
1896 dm_digtable
->cur_igvalue
= cur_igvalue
;
1897 dm_digtable
->pre_igvalue
= 0;
1898 dm_digtable
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
1899 dm_digtable
->presta_cstate
= DIG_STA_DISCONNECT
;
1900 dm_digtable
->curmultista_cstate
= DIG_MULTISTA_DISCONNECT
;
1901 dm_digtable
->rssi_lowthresh
= DM_DIG_THRESH_LOW
;
1902 dm_digtable
->rssi_highthresh
= DM_DIG_THRESH_HIGH
;
1903 dm_digtable
->fa_lowthresh
= DM_FALSEALARM_THRESH_LOW
;
1904 dm_digtable
->fa_highthresh
= DM_FALSEALARM_THRESH_HIGH
;
1905 dm_digtable
->rx_gain_max
= DM_DIG_MAX
;
1906 dm_digtable
->rx_gain_min
= DM_DIG_MIN
;
1907 dm_digtable
->back_val
= DM_DIG_BACKOFF_DEFAULT
;
1908 dm_digtable
->back_range_max
= DM_DIG_BACKOFF_MAX
;
1909 dm_digtable
->back_range_min
= DM_DIG_BACKOFF_MIN
;
1910 dm_digtable
->pre_cck_cca_thres
= 0xff;
1911 dm_digtable
->cur_cck_cca_thres
= 0x83;
1912 dm_digtable
->forbidden_igi
= DM_DIG_MIN
;
1913 dm_digtable
->large_fa_hit
= 0;
1914 dm_digtable
->recover_cnt
= 0;
1915 dm_digtable
->dig_min_0
= 0x25;
1916 dm_digtable
->dig_min_1
= 0x25;
1917 dm_digtable
->media_connect_0
= false;
1918 dm_digtable
->media_connect_1
= false;
1919 rtlpriv
->dm
.dm_initialgain_enable
= true;
1920 dm_digtable
->bt30_cur_igi
= 0x32;
1921 dm_digtable
->pre_cck_pd_state
= CCK_PD_STAGE_MAX
;
1922 dm_digtable
->cur_cck_pd_state
= CCK_PD_STAGE_LOWRSSI
;
1924 EXPORT_SYMBOL(rtl_dm_diginit
);