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 u8 channel5g
[CHANNEL_MAX_NUMBER_5G
] = {
39 36, 38, 40, 42, 44, 46, 48, /* Band 1 */
40 52, 54, 56, 58, 60, 62, 64, /* Band 2 */
41 100, 102, 104, 106, 108, 110, 112, /* Band 3 */
42 116, 118, 120, 122, 124, 126, 128, /* Band 3 */
43 132, 134, 136, 138, 140, 142, 144, /* Band 3 */
44 149, 151, 153, 155, 157, 159, 161, /* Band 4 */
45 165, 167, 169, 171, 173, 175, 177 /* Band 4 */
47 EXPORT_SYMBOL(channel5g
);
49 u8 channel5g_80m
[CHANNEL_MAX_NUMBER_5G_80M
] = {
50 42, 58, 106, 122, 138, 155, 171
52 EXPORT_SYMBOL(channel5g_80m
);
54 void rtl_addr_delay(u32 addr
)
58 else if (addr
== 0xfd)
60 else if (addr
== 0xfc)
62 else if (addr
== 0xfb)
63 usleep_range(50, 100);
64 else if (addr
== 0xfa)
66 else if (addr
== 0xf9)
69 EXPORT_SYMBOL(rtl_addr_delay
);
71 void rtl_rfreg_delay(struct ieee80211_hw
*hw
, enum radio_path rfpath
, u32 addr
,
74 if (addr
>= 0xf9 && addr
<= 0xfe) {
77 rtl_set_rfreg(hw
, rfpath
, addr
, mask
, data
);
81 EXPORT_SYMBOL(rtl_rfreg_delay
);
83 void rtl_bb_delay(struct ieee80211_hw
*hw
, u32 addr
, u32 data
)
85 if (addr
>= 0xf9 && addr
<= 0xfe) {
88 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
92 EXPORT_SYMBOL(rtl_bb_delay
);
94 static void rtl_fw_do_work(const struct firmware
*firmware
, void *context
,
97 struct ieee80211_hw
*hw
= context
;
98 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
101 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
102 "Firmware callback routine entered!\n");
103 complete(&rtlpriv
->firmware_loading_complete
);
105 if (rtlpriv
->cfg
->alt_fw_name
) {
106 err
= request_firmware(&firmware
,
107 rtlpriv
->cfg
->alt_fw_name
,
109 pr_info("Loading alternative firmware %s\n",
110 rtlpriv
->cfg
->alt_fw_name
);
114 pr_err("Selected firmware is not available\n");
115 rtlpriv
->max_fw_size
= 0;
119 if (firmware
->size
> rtlpriv
->max_fw_size
) {
120 pr_err("Firmware is too big!\n");
121 release_firmware(firmware
);
125 memcpy(rtlpriv
->rtlhal
.pfirmware
, firmware
->data
,
127 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
129 memcpy(rtlpriv
->rtlhal
.wowlan_firmware
, firmware
->data
,
131 rtlpriv
->rtlhal
.wowlan_fwsize
= firmware
->size
;
133 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
134 release_firmware(firmware
);
137 void rtl_fw_cb(const struct firmware
*firmware
, void *context
)
139 rtl_fw_do_work(firmware
, context
, false);
141 EXPORT_SYMBOL(rtl_fw_cb
);
143 void rtl_wowlan_fw_cb(const struct firmware
*firmware
, void *context
)
145 rtl_fw_do_work(firmware
, context
, true);
147 EXPORT_SYMBOL(rtl_wowlan_fw_cb
);
149 /*mutex for start & stop is must here. */
150 static int rtl_op_start(struct ieee80211_hw
*hw
)
153 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
154 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
156 if (!is_hal_stop(rtlhal
))
158 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
160 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
161 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
163 rtl_watch_dog_timer_callback(&rtlpriv
->works
.watchdog_timer
);
164 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
168 static void rtl_op_stop(struct ieee80211_hw
*hw
)
170 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
171 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
172 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
173 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
174 bool support_remote_wakeup
= false;
176 if (is_hal_stop(rtlhal
))
179 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
180 (u8
*)(&support_remote_wakeup
));
181 /* here is must, because adhoc do stop and start,
182 * but stop with RFOFF may cause something wrong,
185 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
188 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
189 /* if wowlan supported, DON'T clear connected info */
190 if (!(support_remote_wakeup
&&
191 rtlhal
->enter_pnp_sleep
)) {
192 mac
->link_state
= MAC80211_NOLINK
;
193 eth_zero_addr(mac
->bssid
);
194 mac
->vendor
= PEER_UNKNOWN
;
197 rtl_cam_reset_sec_info(hw
);
199 rtl_deinit_deferred_work(hw
);
201 rtlpriv
->intf_ops
->adapter_stop(hw
);
203 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
206 static void rtl_op_tx(struct ieee80211_hw
*hw
,
207 struct ieee80211_tx_control
*control
,
210 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
211 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
212 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
213 struct rtl_tcb_desc tcb_desc
;
214 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
216 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
219 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
222 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
223 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
227 dev_kfree_skb_any(skb
);
230 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
231 struct ieee80211_vif
*vif
)
233 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
234 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
236 u8 retry_limit
= 0x30;
239 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
240 "vif has been set!! mac->vif = 0x%p\n", mac
->vif
);
244 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
248 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
249 switch (ieee80211_vif_type_p2p(vif
)) {
250 case NL80211_IFTYPE_P2P_CLIENT
:
251 mac
->p2p
= P2P_ROLE_CLIENT
;
253 case NL80211_IFTYPE_STATION
:
254 if (mac
->beacon_enabled
== 1) {
255 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
256 "NL80211_IFTYPE_STATION\n");
257 mac
->beacon_enabled
= 0;
258 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
259 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
262 case NL80211_IFTYPE_ADHOC
:
263 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
264 "NL80211_IFTYPE_ADHOC\n");
266 mac
->link_state
= MAC80211_LINKED
;
267 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
268 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
269 mac
->basic_rates
= 0xfff;
271 mac
->basic_rates
= 0xff0;
272 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
273 (u8
*)(&mac
->basic_rates
));
277 case NL80211_IFTYPE_P2P_GO
:
278 mac
->p2p
= P2P_ROLE_GO
;
280 case NL80211_IFTYPE_AP
:
281 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
282 "NL80211_IFTYPE_AP\n");
284 mac
->link_state
= MAC80211_LINKED
;
285 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
286 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
287 mac
->basic_rates
= 0xfff;
289 mac
->basic_rates
= 0xff0;
290 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
291 (u8
*)(&mac
->basic_rates
));
295 case NL80211_IFTYPE_MESH_POINT
:
296 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
297 "NL80211_IFTYPE_MESH_POINT\n");
299 mac
->link_state
= MAC80211_LINKED
;
300 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
301 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
302 mac
->basic_rates
= 0xfff;
304 mac
->basic_rates
= 0xff0;
305 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
306 (u8
*)(&mac
->basic_rates
));
311 pr_err("operation mode %d is not supported!\n",
318 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
319 "p2p role %x\n", vif
->type
);
320 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
321 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
322 (u8
*)(&mac
->basic_rates
));
325 mac
->opmode
= vif
->type
;
326 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
327 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
328 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
330 mac
->retry_long
= retry_limit
;
331 mac
->retry_short
= retry_limit
;
332 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
333 (u8
*)(&retry_limit
));
335 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
339 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
340 struct ieee80211_vif
*vif
)
342 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
343 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
345 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
347 /* Free beacon resources */
348 if (vif
->type
== NL80211_IFTYPE_AP
||
349 vif
->type
== NL80211_IFTYPE_ADHOC
||
350 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
351 if (mac
->beacon_enabled
== 1) {
352 mac
->beacon_enabled
= 0;
353 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
354 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
359 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
360 *NO LINK for our hardware.
364 mac
->link_state
= MAC80211_NOLINK
;
365 eth_zero_addr(mac
->bssid
);
366 mac
->vendor
= PEER_UNKNOWN
;
367 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
368 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
370 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
372 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
373 struct ieee80211_vif
*vif
,
374 enum nl80211_iftype new_type
, bool p2p
)
376 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
378 rtl_op_remove_interface(hw
, vif
);
380 vif
->type
= new_type
;
382 ret
= rtl_op_add_interface(hw
, vif
);
383 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
389 static u16
crc16_ccitt(u8 data
, u16 crc
)
391 u8 shift_in
, data_bit
, crc_bit11
, crc_bit4
, crc_bit15
;
395 for (i
= 0; i
< 8; i
++) {
396 crc_bit15
= ((crc
& BIT(15)) ? 1 : 0);
397 data_bit
= (data
& (BIT(0) << i
) ? 1 : 0);
398 shift_in
= crc_bit15
^ data_bit
;
406 crc_bit11
= ((crc
& BIT(11)) ? 1 : 0) ^ shift_in
;
408 result
&= (~BIT(12));
412 crc_bit4
= ((crc
& BIT(4)) ? 1 : 0) ^ shift_in
;
424 static u16
_calculate_wol_pattern_crc(u8
*pattern
, u16 len
)
429 for (i
= 0; i
< len
; i
++)
430 crc
= crc16_ccitt(pattern
[i
], crc
);
437 static void _rtl_add_wowlan_patterns(struct ieee80211_hw
*hw
,
438 struct cfg80211_wowlan
*wow
)
440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
441 struct rtl_mac
*mac
= &rtlpriv
->mac80211
;
442 struct cfg80211_pkt_pattern
*patterns
= wow
->patterns
;
443 struct rtl_wow_pattern rtl_pattern
;
444 const u8
*pattern_os
, *mask_os
;
445 u8 mask
[MAX_WOL_BIT_MASK_SIZE
] = {0};
446 u8 content
[MAX_WOL_PATTERN_SIZE
] = {0};
447 u8 broadcast_addr
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
448 u8 multicast_addr1
[2] = {0x33, 0x33};
449 u8 multicast_addr2
[3] = {0x01, 0x00, 0x5e};
453 for (i
= 0; i
< wow
->n_patterns
; i
++) {
454 memset(&rtl_pattern
, 0, sizeof(struct rtl_wow_pattern
));
455 memset(mask
, 0, MAX_WOL_BIT_MASK_SIZE
);
456 if (patterns
[i
].pattern_len
< 0 ||
457 patterns
[i
].pattern_len
> MAX_WOL_PATTERN_SIZE
) {
458 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_WARNING
,
459 "Pattern[%d] is too long\n", i
);
462 pattern_os
= patterns
[i
].pattern
;
463 mask_len
= DIV_ROUND_UP(patterns
[i
].pattern_len
, 8);
464 mask_os
= patterns
[i
].mask
;
465 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
466 "pattern content\n", pattern_os
,
467 patterns
[i
].pattern_len
);
468 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
469 "mask content\n", mask_os
, mask_len
);
470 /* 1. unicast? multicast? or broadcast? */
471 if (memcmp(pattern_os
, broadcast_addr
, 6) == 0)
472 rtl_pattern
.type
= BROADCAST_PATTERN
;
473 else if (memcmp(pattern_os
, multicast_addr1
, 2) == 0 ||
474 memcmp(pattern_os
, multicast_addr2
, 3) == 0)
475 rtl_pattern
.type
= MULTICAST_PATTERN
;
476 else if (memcmp(pattern_os
, mac
->mac_addr
, 6) == 0)
477 rtl_pattern
.type
= UNICAST_PATTERN
;
479 rtl_pattern
.type
= UNKNOWN_TYPE
;
481 /* 2. translate mask_from_os to mask_for_hw */
483 /******************************************************************************
484 * pattern from OS uses 'ethenet frame', like this:
486 | 6 | 6 | 2 | 20 | Variable | 4 |
487 |--------+--------+------+-----------+------------+-----|
488 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
491 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
493 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
494 |-------------------+--------+------+-----------+------------+-----|
495 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
498 * Therefore, we need translate mask_from_OS to mask_to_hw.
499 * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
500 * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
501 * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
502 ******************************************************************************/
505 for (j
= 0; j
< mask_len
- 1; j
++) {
506 mask
[j
] = mask_os
[j
] >> 6;
507 mask
[j
] |= (mask_os
[j
+ 1] & 0x3F) << 2;
509 mask
[j
] = (mask_os
[j
] >> 6) & 0x3F;
510 /* Set bit 0-5 to zero */
513 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
514 "mask to hw\n", mask
, mask_len
);
515 for (j
= 0; j
< (MAX_WOL_BIT_MASK_SIZE
+ 1) / 4; j
++) {
516 rtl_pattern
.mask
[j
] = mask
[j
* 4];
517 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 1] << 8);
518 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 2] << 16);
519 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 3] << 24);
522 /* To get the wake up pattern from the mask.
523 * We do not count first 12 bits which means
524 * DA[6] and SA[6] in the pattern to match HW design.
527 for (j
= 12; j
< patterns
[i
].pattern_len
; j
++) {
528 if ((mask_os
[j
/ 8] >> (j
% 8)) & 0x01) {
529 content
[len
] = pattern_os
[j
];
534 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
535 "pattern to hw\n", content
, len
);
536 /* 3. calculate crc */
537 rtl_pattern
.crc
= _calculate_wol_pattern_crc(content
, len
);
538 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
539 "CRC_Remainder = 0x%x\n", rtl_pattern
.crc
);
541 /* 4. write crc & mask_for_hw to hw */
542 rtlpriv
->cfg
->ops
->add_wowlan_pattern(hw
, &rtl_pattern
, i
);
544 rtl_write_byte(rtlpriv
, 0x698, wow
->n_patterns
);
547 static int rtl_op_suspend(struct ieee80211_hw
*hw
,
548 struct cfg80211_wowlan
*wow
)
550 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
551 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
552 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
554 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
558 /* to resolve s4 can not wake up*/
559 rtlhal
->last_suspend_sec
= ktime_get_real_seconds();
561 if ((ppsc
->wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) && wow
->n_patterns
)
562 _rtl_add_wowlan_patterns(hw
, wow
);
564 rtlhal
->driver_is_goingto_unload
= true;
565 rtlhal
->enter_pnp_sleep
= true;
569 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), true);
573 static int rtl_op_resume(struct ieee80211_hw
*hw
)
575 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
576 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
577 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
580 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
581 rtlhal
->driver_is_goingto_unload
= false;
582 rtlhal
->enter_pnp_sleep
= false;
583 rtlhal
->wake_from_pnp_sleep
= true;
585 /* to resovle s4 can not wake up*/
586 now
= ktime_get_real_seconds();
587 if (now
- rtlhal
->last_suspend_sec
< 5)
591 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), false);
592 ieee80211_resume_disconnect(mac
->vif
);
593 rtlhal
->wake_from_pnp_sleep
= false;
598 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
600 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
601 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
602 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
603 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
604 struct ieee80211_conf
*conf
= &hw
->conf
;
609 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
610 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /* BIT(2)*/
611 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
612 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
616 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
617 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
623 *although rfoff may not cause by ips, but we will
624 *check the reason in set_rf_power_state function
626 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
631 if ((changed
& IEEE80211_CONF_CHANGE_PS
) &&
632 rtlpriv
->psc
.swctrl_lps
&& !rtlpriv
->psc
.fwctrl_lps
) {
633 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
634 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
635 if (conf
->flags
& IEEE80211_CONF_PS
) {
636 rtlpriv
->psc
.sw_ps_enabled
= true;
637 /* sleep here is must, or we may recv the beacon and
638 * cause mac80211 into wrong ps state, this will cause
639 * power save nullfunc send fail, and further cause
640 * pkt loss, So sleep must quickly but not immediatly
641 * because that will cause nullfunc send by mac80211
642 * fail, and cause pkt loss, we have tested that 5mA
643 * is worked very well */
644 if (!rtlpriv
->psc
.multi_buffered
)
645 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
646 &rtlpriv
->works
.ps_work
,
649 rtl_swlps_rf_awake(hw
);
650 rtlpriv
->psc
.sw_ps_enabled
= false;
654 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
655 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
656 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
657 hw
->conf
.long_frame_max_tx_count
);
658 /* brought up everything changes (changed == ~0) indicates first
659 * open, so use our default value instead of that of wiphy.
662 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
663 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
664 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
665 (u8
*)(&hw
->conf
.long_frame_max_tx_count
));
669 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
670 !rtlpriv
->proximity
.proxim_on
) {
671 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
672 enum nl80211_chan_width width
= hw
->conf
.chandef
.width
;
673 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
674 u8 wide_chan
= (u8
) channel
->hw_value
;
676 /* channel_type is for 20&40M */
677 if (width
< NL80211_CHAN_WIDTH_80
)
679 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
680 if (mac
->act_scanning
)
683 if (rtlpriv
->dm
.supp_phymode_switch
&&
684 mac
->link_state
< MAC80211_LINKED
&&
685 !mac
->act_scanning
) {
686 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
687 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
691 *because we should back channel to
692 *current_network.chan in in scanning,
693 *So if set_chan == current_network.chan
695 *because mac80211 tell us wrong bw40
696 *info for cisco1253 bw20, so we modify
697 *it here based on UPPER & LOWER
700 if (width
>= NL80211_CHAN_WIDTH_80
) {
701 if (width
== NL80211_CHAN_WIDTH_80
) {
702 u32 center
= hw
->conf
.chandef
.center_freq1
;
704 (u32
)hw
->conf
.chandef
.chan
->center_freq
;
706 rtlphy
->current_chan_bw
=
710 if (center
> primary
) {
711 mac
->cur_80_prime_sc
=
712 PRIME_CHNL_OFFSET_LOWER
;
713 if (center
- primary
== 10) {
714 mac
->cur_40_prime_sc
=
715 PRIME_CHNL_OFFSET_UPPER
;
718 } else if (center
- primary
== 30) {
719 mac
->cur_40_prime_sc
=
720 PRIME_CHNL_OFFSET_LOWER
;
725 mac
->cur_80_prime_sc
=
726 PRIME_CHNL_OFFSET_UPPER
;
727 if (primary
- center
== 10) {
728 mac
->cur_40_prime_sc
=
729 PRIME_CHNL_OFFSET_LOWER
;
732 } else if (primary
- center
== 30) {
733 mac
->cur_40_prime_sc
=
734 PRIME_CHNL_OFFSET_UPPER
;
741 switch (channel_type
) {
742 case NL80211_CHAN_HT20
:
743 case NL80211_CHAN_NO_HT
:
745 mac
->cur_40_prime_sc
=
746 PRIME_CHNL_OFFSET_DONT_CARE
;
747 rtlphy
->current_chan_bw
=
752 case NL80211_CHAN_HT40MINUS
:
754 mac
->cur_40_prime_sc
=
755 PRIME_CHNL_OFFSET_UPPER
;
756 rtlphy
->current_chan_bw
=
757 HT_CHANNEL_WIDTH_20_40
;
765 case NL80211_CHAN_HT40PLUS
:
767 mac
->cur_40_prime_sc
=
768 PRIME_CHNL_OFFSET_LOWER
;
769 rtlphy
->current_chan_bw
=
770 HT_CHANNEL_WIDTH_20_40
;
781 pr_err("switch case %#x not processed\n",
790 /* In scanning, when before we offchannel we may send a ps=1
791 * null to AP, and then we may send a ps = 0 null to AP quickly,
792 * but first null may have caused AP to put lots of packet to
793 * hw tx buffer. These packets must be tx'd before we go off
794 * channel so we must delay more time to let AP flush these
795 * packets before going offchannel, or dis-association or
796 * delete BA will be caused by AP
798 if (rtlpriv
->mac80211
.offchan_delay
) {
799 rtlpriv
->mac80211
.offchan_delay
= false;
803 rtlphy
->current_channel
= wide_chan
;
805 rtlpriv
->cfg
->ops
->switch_channel(hw
);
806 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
807 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, channel_type
);
810 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
815 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
816 unsigned int changed_flags
,
817 unsigned int *new_flags
, u64 multicast
)
819 bool update_rcr
= false;
820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
821 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
823 *new_flags
&= RTL_SUPPORTED_FILTERS
;
824 if (0 == changed_flags
)
827 /*TODO: we disable broadcase now, so enable here */
828 if (changed_flags
& FIF_ALLMULTI
) {
829 if (*new_flags
& FIF_ALLMULTI
) {
830 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
831 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
832 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
833 "Enable receive multicast frame\n");
835 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
836 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
837 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
838 "Disable receive multicast frame\n");
843 if (changed_flags
& FIF_FCSFAIL
) {
844 if (*new_flags
& FIF_FCSFAIL
) {
845 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
846 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
847 "Enable receive FCS error frame\n");
849 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
850 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
851 "Disable receive FCS error frame\n");
857 /* if ssid not set to hw don't check bssid
858 * here just used for linked scanning, & linked
859 * and nolink check bssid is set in set network_type
861 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
&&
862 mac
->link_state
>= MAC80211_LINKED
) {
863 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
864 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
865 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
866 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
868 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
874 if (changed_flags
& FIF_CONTROL
) {
875 if (*new_flags
& FIF_CONTROL
) {
876 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
878 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
879 "Enable receive control frame.\n");
881 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
882 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
883 "Disable receive control frame.\n");
889 if (changed_flags
& FIF_OTHER_BSS
) {
890 if (*new_flags
& FIF_OTHER_BSS
) {
891 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
892 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
893 "Enable receive other BSS's frame.\n");
895 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
896 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
897 "Disable receive other BSS's frame.\n");
904 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
905 (u8
*)(&mac
->rx_conf
));
907 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
908 struct ieee80211_vif
*vif
,
909 struct ieee80211_sta
*sta
)
911 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
912 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
913 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
914 struct rtl_sta_info
*sta_entry
;
917 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
918 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
919 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
920 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
921 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
922 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
923 if (sta
->supp_rates
[0] <= 0xf)
924 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
925 if (sta
->ht_cap
.ht_supported
)
926 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
928 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
929 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
930 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
931 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
932 if (sta
->ht_cap
.ht_supported
)
933 sta_entry
->wireless_mode
= WIRELESS_MODE_N_5G
;
934 if (sta
->vht_cap
.vht_supported
)
935 sta_entry
->wireless_mode
= WIRELESS_MODE_AC_5G
;
937 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
938 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
940 /*disable cck rate for p2p*/
942 sta
->supp_rates
[0] &= 0xfffffff0;
944 memcpy(sta_entry
->mac_addr
, sta
->addr
, ETH_ALEN
);
945 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
946 "Add sta addr is %pM\n", sta
->addr
);
947 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0, true);
953 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
954 struct ieee80211_vif
*vif
,
955 struct ieee80211_sta
*sta
)
957 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
958 struct rtl_sta_info
*sta_entry
;
960 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
961 "Remove sta addr is %pM\n", sta
->addr
);
962 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
963 sta_entry
->wireless_mode
= 0;
964 sta_entry
->ratr_index
= 0;
965 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
966 list_del(&sta_entry
->list
);
967 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
971 static int _rtl_get_hal_qnum(u16 queue
)
996 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
997 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
999 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
1000 struct ieee80211_vif
*vif
, u16 queue
,
1001 const struct ieee80211_tx_queue_params
*param
)
1003 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1004 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1007 if (queue
>= AC_MAX
) {
1008 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1009 "queue number %d is incorrect!\n", queue
);
1013 aci
= _rtl_get_hal_qnum(queue
);
1014 mac
->ac
[aci
].aifs
= param
->aifs
;
1015 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
1016 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
1017 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
1018 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
1019 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
1023 static void send_beacon_frame(struct ieee80211_hw
*hw
,
1024 struct ieee80211_vif
*vif
)
1026 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1027 struct sk_buff
*skb
= ieee80211_beacon_get(hw
, vif
);
1028 struct rtl_tcb_desc tcb_desc
;
1031 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1032 rtlpriv
->intf_ops
->adapter_tx(hw
, NULL
, skb
, &tcb_desc
);
1036 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
1037 struct ieee80211_vif
*vif
,
1038 struct ieee80211_bss_conf
*bss_conf
,
1041 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1042 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1043 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1044 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1046 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1047 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
1048 vif
->type
== NL80211_IFTYPE_AP
||
1049 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1050 if (changed
& BSS_CHANGED_BEACON
||
1051 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
1052 bss_conf
->enable_beacon
)) {
1053 if (mac
->beacon_enabled
== 0) {
1054 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1055 "BSS_CHANGED_BEACON_ENABLED\n");
1057 /*start hw beacon interrupt. */
1058 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
1059 mac
->beacon_enabled
= 1;
1060 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
1062 [RTL_IBSS_INT_MASKS
], 0);
1064 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1065 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1066 send_beacon_frame(hw
, vif
);
1069 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
1070 !bss_conf
->enable_beacon
)) {
1071 if (mac
->beacon_enabled
== 1) {
1072 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1073 "ADHOC DISABLE BEACON\n");
1075 mac
->beacon_enabled
= 0;
1076 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
1078 [RTL_IBSS_INT_MASKS
]);
1081 if (changed
& BSS_CHANGED_BEACON_INT
) {
1082 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
1083 "BSS_CHANGED_BEACON_INT\n");
1084 mac
->beacon_interval
= bss_conf
->beacon_int
;
1085 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
1089 /*TODO: reference to enum ieee80211_bss_change */
1090 if (changed
& BSS_CHANGED_ASSOC
) {
1092 if (bss_conf
->assoc
) {
1093 struct ieee80211_sta
*sta
= NULL
;
1096 mstatus
= RT_MEDIA_CONNECT
;
1097 /* we should reset all sec info & cam
1098 * before set cam after linked, we should not
1099 * reset in disassoc, that will cause tkip->wep
1100 * fail because some flag will be wrong */
1101 /* reset sec info */
1102 rtl_cam_reset_sec_info(hw
);
1103 /* reset cam to fix wep fail issue
1104 * when change from wpa to wep */
1105 rtl_cam_reset_all_entry(hw
);
1107 mac
->link_state
= MAC80211_LINKED
;
1108 mac
->cnt_after_linked
= 0;
1109 mac
->assoc_id
= bss_conf
->aid
;
1110 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1112 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1113 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1116 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1121 RT_TRACE(rtlpriv
, COMP_EASY_CONCURRENT
, DBG_LOUD
,
1122 "send PS STATIC frame\n");
1123 if (rtlpriv
->dm
.supp_phymode_switch
) {
1124 if (sta
->ht_cap
.ht_supported
)
1125 rtl_send_smps_action(hw
, sta
,
1126 IEEE80211_SMPS_STATIC
);
1129 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1130 mac
->mode
= WIRELESS_MODE_A
;
1132 if (sta
->supp_rates
[0] <= 0xf)
1133 mac
->mode
= WIRELESS_MODE_B
;
1135 mac
->mode
= WIRELESS_MODE_G
;
1138 if (sta
->ht_cap
.ht_supported
) {
1139 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1140 mac
->mode
= WIRELESS_MODE_N_24G
;
1142 mac
->mode
= WIRELESS_MODE_N_5G
;
1145 if (sta
->vht_cap
.vht_supported
) {
1146 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1147 mac
->mode
= WIRELESS_MODE_AC_5G
;
1149 mac
->mode
= WIRELESS_MODE_AC_24G
;
1152 if (vif
->type
== NL80211_IFTYPE_STATION
)
1153 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0,
1157 /* to avoid AP Disassociation caused by inactivity */
1158 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1160 (u8
*)(&keep_alive
));
1162 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1163 "BSS_CHANGED_ASSOC\n");
1165 struct cfg80211_bss
*bss
= NULL
;
1167 mstatus
= RT_MEDIA_DISCONNECT
;
1169 if (mac
->link_state
== MAC80211_LINKED
)
1171 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
1172 rtl_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
1173 mac
->link_state
= MAC80211_NOLINK
;
1175 bss
= cfg80211_get_bss(hw
->wiphy
, NULL
,
1176 (u8
*)mac
->bssid
, NULL
, 0,
1177 IEEE80211_BSS_TYPE_ESS
,
1178 IEEE80211_PRIVACY_OFF
);
1180 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1181 "bssid = %pMF\n", mac
->bssid
);
1184 cfg80211_unlink_bss(hw
->wiphy
, bss
);
1185 cfg80211_put_bss(hw
->wiphy
, bss
);
1186 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1187 "cfg80211_unlink !!\n");
1190 eth_zero_addr(mac
->bssid
);
1191 mac
->vendor
= PEER_UNKNOWN
;
1194 if (rtlpriv
->dm
.supp_phymode_switch
) {
1195 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1196 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1198 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1199 "BSS_CHANGED_UN_ASSOC\n");
1201 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
1203 * To tell firmware we have connected or disconnected
1205 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1206 HW_VAR_H2C_FW_JOINBSSRPT
,
1208 ppsc
->report_linked
= (mstatus
== RT_MEDIA_CONNECT
) ?
1211 if (rtlpriv
->cfg
->ops
->get_btc_status())
1212 rtlpriv
->btcoexist
.btc_ops
->btc_mediastatus_notify(
1216 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1217 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1218 "BSS_CHANGED_ERP_CTS_PROT\n");
1219 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
1222 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1223 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
1224 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
1225 bss_conf
->use_short_preamble
);
1227 mac
->short_preamble
= bss_conf
->use_short_preamble
;
1228 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
1229 (u8
*)(&mac
->short_preamble
));
1232 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1233 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1234 "BSS_CHANGED_ERP_SLOT\n");
1236 if (bss_conf
->use_short_slot
)
1237 mac
->slot_time
= RTL_SLOT_TIME_9
;
1239 mac
->slot_time
= RTL_SLOT_TIME_20
;
1241 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
1242 (u8
*)(&mac
->slot_time
));
1245 if (changed
& BSS_CHANGED_HT
) {
1246 struct ieee80211_sta
*sta
= NULL
;
1248 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1249 "BSS_CHANGED_HT\n");
1252 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1254 if (sta
->ht_cap
.ampdu_density
>
1255 mac
->current_ampdu_density
)
1256 mac
->current_ampdu_density
=
1257 sta
->ht_cap
.ampdu_density
;
1258 if (sta
->ht_cap
.ampdu_factor
<
1259 mac
->current_ampdu_factor
)
1260 mac
->current_ampdu_factor
=
1261 sta
->ht_cap
.ampdu_factor
;
1265 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
1266 (u8
*)(&mac
->max_mss_density
));
1267 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
1268 &mac
->current_ampdu_factor
);
1269 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
1270 &mac
->current_ampdu_density
);
1273 if (changed
& BSS_CHANGED_BSSID
) {
1275 struct ieee80211_sta
*sta
= NULL
;
1277 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
1278 (u8
*)bss_conf
->bssid
);
1280 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1281 "bssid: %pM\n", bss_conf
->bssid
);
1283 mac
->vendor
= PEER_UNKNOWN
;
1284 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1287 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1293 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1294 mac
->mode
= WIRELESS_MODE_A
;
1296 if (sta
->supp_rates
[0] <= 0xf)
1297 mac
->mode
= WIRELESS_MODE_B
;
1299 mac
->mode
= WIRELESS_MODE_G
;
1302 if (sta
->ht_cap
.ht_supported
) {
1303 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1304 mac
->mode
= WIRELESS_MODE_N_24G
;
1306 mac
->mode
= WIRELESS_MODE_N_5G
;
1309 if (sta
->vht_cap
.vht_supported
) {
1310 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1311 mac
->mode
= WIRELESS_MODE_AC_5G
;
1313 mac
->mode
= WIRELESS_MODE_AC_24G
;
1316 /* just station need it, because ibss & ap mode will
1317 * set in sta_add, and will be NULL here */
1318 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1319 struct rtl_sta_info
*sta_entry
;
1320 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1321 sta_entry
->wireless_mode
= mac
->mode
;
1324 if (sta
->ht_cap
.ht_supported
) {
1325 mac
->ht_enable
= true;
1328 * for cisco 1252 bw20 it's wrong
1329 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1330 * mac->bw_40 = true;
1335 if (sta
->vht_cap
.vht_supported
)
1336 mac
->vht_enable
= true;
1338 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1339 /* for 5G must << RATE_6M_INDEX = 4,
1340 * because 5G have no cck rate*/
1341 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1342 basic_rates
= sta
->supp_rates
[1] << 4;
1344 basic_rates
= sta
->supp_rates
[0];
1346 mac
->basic_rates
= basic_rates
;
1347 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
1348 (u8
*)(&basic_rates
));
1353 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1356 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1358 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1361 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&tsf
));
1365 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
,
1366 struct ieee80211_vif
*vif
, u64 tsf
)
1368 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1369 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1370 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
1373 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&bibss
));
1376 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1378 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1381 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*)(&tmp
));
1384 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
1385 struct ieee80211_vif
*vif
,
1386 enum sta_notify_cmd cmd
,
1387 struct ieee80211_sta
*sta
)
1390 case STA_NOTIFY_SLEEP
:
1392 case STA_NOTIFY_AWAKE
:
1399 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
1400 struct ieee80211_vif
*vif
,
1401 struct ieee80211_ampdu_params
*params
)
1403 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1404 struct ieee80211_sta
*sta
= params
->sta
;
1405 enum ieee80211_ampdu_mlme_action action
= params
->action
;
1406 u16 tid
= params
->tid
;
1407 u16
*ssn
= ¶ms
->ssn
;
1410 case IEEE80211_AMPDU_TX_START
:
1411 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1412 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid
);
1413 return rtl_tx_agg_start(hw
, vif
, sta
, tid
, ssn
);
1414 case IEEE80211_AMPDU_TX_STOP_CONT
:
1415 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1416 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1417 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1418 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
);
1419 return rtl_tx_agg_stop(hw
, vif
, sta
, tid
);
1420 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1421 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1422 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
);
1423 rtl_tx_agg_oper(hw
, sta
, tid
);
1425 case IEEE80211_AMPDU_RX_START
:
1426 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1427 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid
);
1428 return rtl_rx_agg_start(hw
, sta
, tid
);
1429 case IEEE80211_AMPDU_RX_STOP
:
1430 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1431 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
);
1432 return rtl_rx_agg_stop(hw
, sta
, tid
);
1434 pr_err("IEEE80211_AMPDU_ERR!!!!:\n");
1440 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
,
1441 struct ieee80211_vif
*vif
,
1444 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1445 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1447 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1448 mac
->act_scanning
= true;
1449 if (rtlpriv
->link_info
.higher_busytraffic
) {
1450 mac
->skip_scan
= true;
1454 if (rtlpriv
->cfg
->ops
->get_btc_status())
1455 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 1);
1456 else if (rtlpriv
->btcoexist
.btc_ops
)
1457 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1460 if (rtlpriv
->dm
.supp_phymode_switch
) {
1461 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1462 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1465 if (mac
->link_state
== MAC80211_LINKED
) {
1467 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1473 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1475 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1476 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP_BAND0
);
1479 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
,
1480 struct ieee80211_vif
*vif
)
1482 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1483 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1485 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1486 mac
->act_scanning
= false;
1487 mac
->skip_scan
= false;
1489 rtlpriv
->btcoexist
.btc_info
.ap_num
= rtlpriv
->scan_list
.num
;
1491 if (rtlpriv
->link_info
.higher_busytraffic
)
1494 /* p2p will use 1/6/11 to scan */
1495 if (mac
->n_channels
== 3)
1496 mac
->p2p_in_use
= true;
1498 mac
->p2p_in_use
= false;
1499 mac
->n_channels
= 0;
1501 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1503 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1504 mac
->link_state
= MAC80211_LINKED
;
1505 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1506 /* fix fwlps issue */
1507 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1511 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1512 if (rtlpriv
->cfg
->ops
->get_btc_status())
1513 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 0);
1514 else if (rtlpriv
->btcoexist
.btc_ops
)
1515 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1519 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1520 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1521 struct ieee80211_key_conf
*key
)
1523 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1524 u8 key_type
= NO_ENCRYPTION
;
1526 bool group_key
= false;
1527 bool wep_only
= false;
1529 u8 mac_addr
[ETH_ALEN
];
1530 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1532 rtlpriv
->btcoexist
.btc_info
.in_4way
= false;
1534 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1535 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1536 "not open hw encryption\n");
1537 return -ENOSPC
; /*User disabled HW-crypto */
1539 /* To support IBSS, use sw-crypto for GTK */
1540 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1541 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1542 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1544 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1545 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1546 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1547 sta
? sta
->addr
: bcast_addr
);
1548 rtlpriv
->sec
.being_setkey
= true;
1550 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1551 /* <1> get encryption alg */
1553 switch (key
->cipher
) {
1554 case WLAN_CIPHER_SUITE_WEP40
:
1555 key_type
= WEP40_ENCRYPTION
;
1556 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP40\n");
1558 case WLAN_CIPHER_SUITE_WEP104
:
1559 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP104\n");
1560 key_type
= WEP104_ENCRYPTION
;
1562 case WLAN_CIPHER_SUITE_TKIP
:
1563 key_type
= TKIP_ENCRYPTION
;
1564 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:TKIP\n");
1566 case WLAN_CIPHER_SUITE_CCMP
:
1567 key_type
= AESCCMP_ENCRYPTION
;
1568 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CCMP\n");
1570 case WLAN_CIPHER_SUITE_AES_CMAC
:
1571 /* HW don't support CMAC encryption,
1572 * use software CMAC encryption
1574 key_type
= AESCMAC_ENCRYPTION
;
1575 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CMAC\n");
1576 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1577 "HW don't support CMAC encryption, use software CMAC encryption\n");
1581 pr_err("alg_err:%x!!!!:\n", key
->cipher
);
1584 if (key_type
== WEP40_ENCRYPTION
||
1585 key_type
== WEP104_ENCRYPTION
||
1586 vif
->type
== NL80211_IFTYPE_ADHOC
)
1587 rtlpriv
->sec
.use_defaultkey
= true;
1589 /* <2> get key_idx */
1590 key_idx
= (u8
) (key
->keyidx
);
1593 /* <3> if pairwise key enable_hw_sec */
1594 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1596 /* wep always be group key, but there are two conditions:
1597 * 1) wep only: is just for wep enc, in this condition
1598 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1599 * will be true & enable_hw_sec will be set when wep
1601 * 2) wep(group) + AES(pairwise): some AP like cisco
1602 * may use it, in this condition enable_hw_sec will not
1603 * be set when wep key setting */
1604 /* we must reset sec_info after lingked before set key,
1605 * or some flag will be wrong*/
1606 if (vif
->type
== NL80211_IFTYPE_AP
||
1607 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1608 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1609 key_type
== WEP104_ENCRYPTION
) {
1612 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1615 if (!group_key
|| vif
->type
== NL80211_IFTYPE_ADHOC
||
1616 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1617 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1619 (key_type
== WEP40_ENCRYPTION
||
1620 key_type
== WEP104_ENCRYPTION
))
1622 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1623 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1624 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1626 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1629 /* <4> set key based on cmd */
1633 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1634 "set WEP(group/pairwise) key\n");
1635 /* Pairwise key with an assigned MAC address. */
1636 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1637 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1638 /*set local buf about wep key. */
1639 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1640 key
->key
, key
->keylen
);
1641 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1642 eth_zero_addr(mac_addr
);
1643 } else if (group_key
) { /* group key */
1644 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1647 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1648 /*set local buf about group key. */
1649 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1650 key
->key
, key
->keylen
);
1651 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1652 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1653 } else { /* pairwise key */
1654 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1655 "set pairwise key\n");
1658 "rtlwifi: pairwise key without mac_addr\n");
1663 /* Pairwise key with an assigned MAC address. */
1664 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1665 /*set local buf about pairwise key. */
1666 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1667 key
->key
, key
->keylen
);
1668 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1669 rtlpriv
->sec
.pairwise_key
=
1670 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1671 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1673 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1674 group_key
, key_type
, wep_only
,
1676 /* <5> tell mac80211 do something: */
1677 /*must use sw generate IV, or can not work !!!!. */
1678 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1679 key
->hw_key_idx
= key_idx
;
1680 if (key_type
== TKIP_ENCRYPTION
)
1681 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1682 /*use software CCMP encryption for management frames (MFP) */
1683 if (key_type
== AESCCMP_ENCRYPTION
)
1684 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1687 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1688 "disable key delete one entry\n");
1689 /*set local buf about wep key. */
1690 if (vif
->type
== NL80211_IFTYPE_AP
||
1691 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1693 rtl_cam_del_entry(hw
, sta
->addr
);
1695 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1696 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1697 eth_zero_addr(mac_addr
);
1699 *mac80211 will delete entrys one by one,
1700 *so don't use rtl_cam_reset_all_entry
1701 *or clear all entry here.
1703 rtl_wait_tx_report_acked(hw
, 500); /* wait 500ms for TX ack */
1705 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1708 pr_err("cmd_err:%x!!!!:\n", cmd
);
1711 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1712 rtlpriv
->sec
.being_setkey
= false;
1716 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1718 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1724 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1727 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1729 /*if Radio On return true here */
1730 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1733 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1734 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1736 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
1737 "wireless radio switch turned %s\n",
1738 radio_state
? "on" : "off");
1740 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1741 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1745 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1748 /* this function is called by mac80211 to flush tx buffer
1749 * before switch channle or power save, or tx buffer packet
1750 * maybe send after offchannel or rf sleep, this may cause
1751 * dis-association by AP */
1752 static void rtl_op_flush(struct ieee80211_hw
*hw
,
1753 struct ieee80211_vif
*vif
,
1757 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1759 if (rtlpriv
->intf_ops
->flush
)
1760 rtlpriv
->intf_ops
->flush(hw
, queues
, drop
);
1764 * This routine deals with the Power Configuration CMD
1765 * parsing for RTL8723/RTL8188E Series IC.
1767 * We should follow specific format that was released from HW SD.
1769 bool rtl_hal_pwrseqcmdparsing(struct rtl_priv
*rtlpriv
, u8 cut_version
,
1770 u8 faversion
, u8 interface_type
,
1771 struct wlan_pwr_cfg pwrcfgcmd
[])
1773 struct wlan_pwr_cfg cfg_cmd
;
1774 bool polling_bit
= false;
1778 u32 polling_count
= 0;
1779 u32 max_polling_cnt
= 5000;
1782 cfg_cmd
= pwrcfgcmd
[ary_idx
];
1783 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1784 "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n",
1785 GET_PWR_CFG_OFFSET(cfg_cmd
),
1786 GET_PWR_CFG_CUT_MASK(cfg_cmd
),
1787 GET_PWR_CFG_FAB_MASK(cfg_cmd
),
1788 GET_PWR_CFG_INTF_MASK(cfg_cmd
),
1789 GET_PWR_CFG_BASE(cfg_cmd
), GET_PWR_CFG_CMD(cfg_cmd
),
1790 GET_PWR_CFG_MASK(cfg_cmd
), GET_PWR_CFG_VALUE(cfg_cmd
));
1792 if ((GET_PWR_CFG_FAB_MASK(cfg_cmd
)&faversion
) &&
1793 (GET_PWR_CFG_CUT_MASK(cfg_cmd
)&cut_version
) &&
1794 (GET_PWR_CFG_INTF_MASK(cfg_cmd
)&interface_type
)) {
1795 switch (GET_PWR_CFG_CMD(cfg_cmd
)) {
1797 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1798 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
1801 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1802 "%s(): PWR_CMD_WRITE\n", __func__
);
1803 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1805 /*Read the value from system register*/
1806 value
= rtl_read_byte(rtlpriv
, offset
);
1807 value
&= (~(GET_PWR_CFG_MASK(cfg_cmd
)));
1808 value
|= (GET_PWR_CFG_VALUE(cfg_cmd
) &
1809 GET_PWR_CFG_MASK(cfg_cmd
));
1811 /*Write the value back to sytem register*/
1812 rtl_write_byte(rtlpriv
, offset
, value
);
1814 case PWR_CMD_POLLING
:
1815 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1816 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n");
1817 polling_bit
= false;
1818 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1821 value
= rtl_read_byte(rtlpriv
, offset
);
1823 value
&= GET_PWR_CFG_MASK(cfg_cmd
);
1825 (GET_PWR_CFG_VALUE(cfg_cmd
) &
1826 GET_PWR_CFG_MASK(cfg_cmd
)))
1831 if (polling_count
++ > max_polling_cnt
)
1833 } while (!polling_bit
);
1836 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1837 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n");
1838 if (GET_PWR_CFG_VALUE(cfg_cmd
) ==
1840 udelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1842 mdelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1845 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1846 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n");
1850 "rtlwifi: rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
1859 EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing
);
1861 bool rtl_cmd_send_packet(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1863 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1864 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1865 struct rtl8192_tx_ring
*ring
;
1866 struct rtl_tx_desc
*pdesc
;
1867 unsigned long flags
;
1868 struct sk_buff
*pskb
= NULL
;
1870 ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
1872 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1873 pskb
= __skb_dequeue(&ring
->queue
);
1875 dev_kfree_skb_irq(pskb
);
1877 /*this is wrong, fill_tx_cmddesc needs update*/
1878 pdesc
= &ring
->desc
[0];
1880 rtlpriv
->cfg
->ops
->fill_tx_cmddesc(hw
, (u8
*)pdesc
, 1, 1, skb
);
1882 __skb_queue_tail(&ring
->queue
, skb
);
1884 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1886 rtlpriv
->cfg
->ops
->tx_polling(hw
, BEACON_QUEUE
);
1890 EXPORT_SYMBOL(rtl_cmd_send_packet
);
1891 const struct ieee80211_ops rtl_ops
= {
1892 .start
= rtl_op_start
,
1893 .stop
= rtl_op_stop
,
1895 .add_interface
= rtl_op_add_interface
,
1896 .remove_interface
= rtl_op_remove_interface
,
1897 .change_interface
= rtl_op_change_interface
,
1899 .suspend
= rtl_op_suspend
,
1900 .resume
= rtl_op_resume
,
1902 .config
= rtl_op_config
,
1903 .configure_filter
= rtl_op_configure_filter
,
1904 .set_key
= rtl_op_set_key
,
1905 .conf_tx
= rtl_op_conf_tx
,
1906 .bss_info_changed
= rtl_op_bss_info_changed
,
1907 .get_tsf
= rtl_op_get_tsf
,
1908 .set_tsf
= rtl_op_set_tsf
,
1909 .reset_tsf
= rtl_op_reset_tsf
,
1910 .sta_notify
= rtl_op_sta_notify
,
1911 .ampdu_action
= rtl_op_ampdu_action
,
1912 .sw_scan_start
= rtl_op_sw_scan_start
,
1913 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1914 .rfkill_poll
= rtl_op_rfkill_poll
,
1915 .sta_add
= rtl_op_sta_add
,
1916 .sta_remove
= rtl_op_sta_remove
,
1917 .flush
= rtl_op_flush
,
1919 EXPORT_SYMBOL_GPL(rtl_ops
);
1921 bool rtl_btc_status_false(void)
1925 EXPORT_SYMBOL_GPL(rtl_btc_status_false
);
1927 void rtl_dm_diginit(struct ieee80211_hw
*hw
, u32 cur_igvalue
)
1929 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1930 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
1932 dm_digtable
->dig_enable_flag
= true;
1933 dm_digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
1934 dm_digtable
->cur_igvalue
= cur_igvalue
;
1935 dm_digtable
->pre_igvalue
= 0;
1936 dm_digtable
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
1937 dm_digtable
->presta_cstate
= DIG_STA_DISCONNECT
;
1938 dm_digtable
->curmultista_cstate
= DIG_MULTISTA_DISCONNECT
;
1939 dm_digtable
->rssi_lowthresh
= DM_DIG_THRESH_LOW
;
1940 dm_digtable
->rssi_highthresh
= DM_DIG_THRESH_HIGH
;
1941 dm_digtable
->fa_lowthresh
= DM_FALSEALARM_THRESH_LOW
;
1942 dm_digtable
->fa_highthresh
= DM_FALSEALARM_THRESH_HIGH
;
1943 dm_digtable
->rx_gain_max
= DM_DIG_MAX
;
1944 dm_digtable
->rx_gain_min
= DM_DIG_MIN
;
1945 dm_digtable
->back_val
= DM_DIG_BACKOFF_DEFAULT
;
1946 dm_digtable
->back_range_max
= DM_DIG_BACKOFF_MAX
;
1947 dm_digtable
->back_range_min
= DM_DIG_BACKOFF_MIN
;
1948 dm_digtable
->pre_cck_cca_thres
= 0xff;
1949 dm_digtable
->cur_cck_cca_thres
= 0x83;
1950 dm_digtable
->forbidden_igi
= DM_DIG_MIN
;
1951 dm_digtable
->large_fa_hit
= 0;
1952 dm_digtable
->recover_cnt
= 0;
1953 dm_digtable
->dig_min_0
= 0x25;
1954 dm_digtable
->dig_min_1
= 0x25;
1955 dm_digtable
->media_connect_0
= false;
1956 dm_digtable
->media_connect_1
= false;
1957 rtlpriv
->dm
.dm_initialgain_enable
= true;
1958 dm_digtable
->bt30_cur_igi
= 0x32;
1959 dm_digtable
->pre_cck_pd_state
= CCK_PD_STAGE_MAX
;
1960 dm_digtable
->cur_cck_pd_state
= CCK_PD_STAGE_LOWRSSI
;
1962 EXPORT_SYMBOL(rtl_dm_diginit
);