1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2009-2012 Realtek Corporation.*/
11 #include "btcoexist/rtl_btc.h"
12 #include <linux/firmware.h>
13 #include <linux/export.h>
14 #include <net/cfg80211.h>
16 u8 channel5g
[CHANNEL_MAX_NUMBER_5G
] = {
17 36, 38, 40, 42, 44, 46, 48, /* Band 1 */
18 52, 54, 56, 58, 60, 62, 64, /* Band 2 */
19 100, 102, 104, 106, 108, 110, 112, /* Band 3 */
20 116, 118, 120, 122, 124, 126, 128, /* Band 3 */
21 132, 134, 136, 138, 140, 142, 144, /* Band 3 */
22 149, 151, 153, 155, 157, 159, 161, /* Band 4 */
23 165, 167, 169, 171, 173, 175, 177 /* Band 4 */
25 EXPORT_SYMBOL(channel5g
);
27 u8 channel5g_80m
[CHANNEL_MAX_NUMBER_5G_80M
] = {
28 42, 58, 106, 122, 138, 155, 171
30 EXPORT_SYMBOL(channel5g_80m
);
32 void rtl_addr_delay(u32 addr
)
36 else if (addr
== 0xfd)
38 else if (addr
== 0xfc)
40 else if (addr
== 0xfb)
41 usleep_range(50, 100);
42 else if (addr
== 0xfa)
44 else if (addr
== 0xf9)
47 EXPORT_SYMBOL(rtl_addr_delay
);
49 void rtl_rfreg_delay(struct ieee80211_hw
*hw
, enum radio_path rfpath
, u32 addr
,
52 if (addr
>= 0xf9 && addr
<= 0xfe) {
55 rtl_set_rfreg(hw
, rfpath
, addr
, mask
, data
);
59 EXPORT_SYMBOL(rtl_rfreg_delay
);
61 void rtl_bb_delay(struct ieee80211_hw
*hw
, u32 addr
, u32 data
)
63 if (addr
>= 0xf9 && addr
<= 0xfe) {
66 rtl_set_bbreg(hw
, addr
, MASKDWORD
, data
);
70 EXPORT_SYMBOL(rtl_bb_delay
);
72 static void rtl_fw_do_work(const struct firmware
*firmware
, void *context
,
75 struct ieee80211_hw
*hw
= context
;
76 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
79 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_LOUD
,
80 "Firmware callback routine entered!\n");
82 if (rtlpriv
->cfg
->alt_fw_name
) {
83 err
= request_firmware(&firmware
,
84 rtlpriv
->cfg
->alt_fw_name
,
86 pr_info("Loading alternative firmware %s\n",
87 rtlpriv
->cfg
->alt_fw_name
);
91 pr_err("Selected firmware is not available\n");
92 rtlpriv
->max_fw_size
= 0;
96 if (firmware
->size
> rtlpriv
->max_fw_size
) {
97 pr_err("Firmware is too big!\n");
98 release_firmware(firmware
);
102 memcpy(rtlpriv
->rtlhal
.pfirmware
, firmware
->data
,
104 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
106 memcpy(rtlpriv
->rtlhal
.wowlan_firmware
, firmware
->data
,
108 rtlpriv
->rtlhal
.wowlan_fwsize
= firmware
->size
;
110 release_firmware(firmware
);
113 complete(&rtlpriv
->firmware_loading_complete
);
116 void rtl_fw_cb(const struct firmware
*firmware
, void *context
)
118 rtl_fw_do_work(firmware
, context
, false);
120 EXPORT_SYMBOL(rtl_fw_cb
);
122 void rtl_wowlan_fw_cb(const struct firmware
*firmware
, void *context
)
124 rtl_fw_do_work(firmware
, context
, true);
126 EXPORT_SYMBOL(rtl_wowlan_fw_cb
);
128 /*mutex for start & stop is must here. */
129 static int rtl_op_start(struct ieee80211_hw
*hw
)
132 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
133 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
135 if (!is_hal_stop(rtlhal
))
137 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
139 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
140 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
142 rtl_watch_dog_timer_callback(&rtlpriv
->works
.watchdog_timer
);
143 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
147 static void rtl_op_stop(struct ieee80211_hw
*hw
)
149 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
150 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
151 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
152 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
153 bool support_remote_wakeup
= false;
155 if (is_hal_stop(rtlhal
))
158 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
159 (u8
*)(&support_remote_wakeup
));
160 /* here is must, because adhoc do stop and start,
161 * but stop with RFOFF may cause something wrong,
164 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
167 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
168 /* if wowlan supported, DON'T clear connected info */
169 if (!(support_remote_wakeup
&&
170 rtlhal
->enter_pnp_sleep
)) {
171 mac
->link_state
= MAC80211_NOLINK
;
172 eth_zero_addr(mac
->bssid
);
173 mac
->vendor
= PEER_UNKNOWN
;
176 rtl_cam_reset_sec_info(hw
);
178 rtl_deinit_deferred_work(hw
, false);
180 rtlpriv
->intf_ops
->adapter_stop(hw
);
182 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
185 static void rtl_op_tx(struct ieee80211_hw
*hw
,
186 struct ieee80211_tx_control
*control
,
189 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
190 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
191 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
192 struct rtl_tcb_desc tcb_desc
;
194 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
196 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
199 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
202 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
203 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
207 dev_kfree_skb_any(skb
);
210 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
211 struct ieee80211_vif
*vif
)
213 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
214 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
216 u8 retry_limit
= 0x30;
219 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
220 "vif has been set!! mac->vif = 0x%p\n", mac
->vif
);
224 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
228 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
229 switch (ieee80211_vif_type_p2p(vif
)) {
230 case NL80211_IFTYPE_P2P_CLIENT
:
231 mac
->p2p
= P2P_ROLE_CLIENT
;
233 case NL80211_IFTYPE_STATION
:
234 if (mac
->beacon_enabled
== 1) {
235 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
236 "NL80211_IFTYPE_STATION\n");
237 mac
->beacon_enabled
= 0;
238 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
239 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
242 case NL80211_IFTYPE_ADHOC
:
243 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
244 "NL80211_IFTYPE_ADHOC\n");
246 mac
->link_state
= MAC80211_LINKED
;
247 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
248 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
249 mac
->basic_rates
= 0xfff;
251 mac
->basic_rates
= 0xff0;
252 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
253 (u8
*)(&mac
->basic_rates
));
257 case NL80211_IFTYPE_P2P_GO
:
258 mac
->p2p
= P2P_ROLE_GO
;
260 case NL80211_IFTYPE_AP
:
261 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
262 "NL80211_IFTYPE_AP\n");
264 mac
->link_state
= MAC80211_LINKED
;
265 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
266 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
267 mac
->basic_rates
= 0xfff;
269 mac
->basic_rates
= 0xff0;
270 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
271 (u8
*)(&mac
->basic_rates
));
275 case NL80211_IFTYPE_MESH_POINT
:
276 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
277 "NL80211_IFTYPE_MESH_POINT\n");
279 mac
->link_state
= MAC80211_LINKED
;
280 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
281 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
282 mac
->basic_rates
= 0xfff;
284 mac
->basic_rates
= 0xff0;
285 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
286 (u8
*)(&mac
->basic_rates
));
291 pr_err("operation mode %d is not supported!\n",
298 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
299 "p2p role %x\n", vif
->type
);
300 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
301 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
302 (u8
*)(&mac
->basic_rates
));
305 mac
->opmode
= vif
->type
;
306 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
307 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
308 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
310 mac
->retry_long
= retry_limit
;
311 mac
->retry_short
= retry_limit
;
312 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
313 (u8
*)(&retry_limit
));
315 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
319 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
320 struct ieee80211_vif
*vif
)
322 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
323 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
325 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
327 /* Free beacon resources */
328 if (vif
->type
== NL80211_IFTYPE_AP
||
329 vif
->type
== NL80211_IFTYPE_ADHOC
||
330 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
331 if (mac
->beacon_enabled
== 1) {
332 mac
->beacon_enabled
= 0;
333 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
334 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
339 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
340 *NO LINK for our hardware.
344 mac
->link_state
= MAC80211_NOLINK
;
345 eth_zero_addr(mac
->bssid
);
346 mac
->vendor
= PEER_UNKNOWN
;
347 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
348 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
350 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
353 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
354 struct ieee80211_vif
*vif
,
355 enum nl80211_iftype new_type
, bool p2p
)
357 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
360 rtl_op_remove_interface(hw
, vif
);
362 vif
->type
= new_type
;
364 ret
= rtl_op_add_interface(hw
, vif
);
365 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
371 static u16
crc16_ccitt(u8 data
, u16 crc
)
373 u8 shift_in
, data_bit
, crc_bit11
, crc_bit4
, crc_bit15
;
377 for (i
= 0; i
< 8; i
++) {
378 crc_bit15
= ((crc
& BIT(15)) ? 1 : 0);
379 data_bit
= (data
& (BIT(0) << i
) ? 1 : 0);
380 shift_in
= crc_bit15
^ data_bit
;
388 crc_bit11
= ((crc
& BIT(11)) ? 1 : 0) ^ shift_in
;
390 result
&= (~BIT(12));
394 crc_bit4
= ((crc
& BIT(4)) ? 1 : 0) ^ shift_in
;
406 static u16
_calculate_wol_pattern_crc(u8
*pattern
, u16 len
)
411 for (i
= 0; i
< len
; i
++)
412 crc
= crc16_ccitt(pattern
[i
], crc
);
419 static void _rtl_add_wowlan_patterns(struct ieee80211_hw
*hw
,
420 struct cfg80211_wowlan
*wow
)
422 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
423 struct rtl_mac
*mac
= &rtlpriv
->mac80211
;
424 struct cfg80211_pkt_pattern
*patterns
= wow
->patterns
;
425 struct rtl_wow_pattern rtl_pattern
;
426 const u8
*pattern_os
, *mask_os
;
427 u8 mask
[MAX_WOL_BIT_MASK_SIZE
] = {0};
428 u8 content
[MAX_WOL_PATTERN_SIZE
] = {0};
429 u8 broadcast_addr
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
430 u8 multicast_addr1
[2] = {0x33, 0x33};
431 u8 multicast_addr2
[3] = {0x01, 0x00, 0x5e};
435 for (i
= 0; i
< wow
->n_patterns
; i
++) {
436 memset(&rtl_pattern
, 0, sizeof(struct rtl_wow_pattern
));
437 memset(mask
, 0, MAX_WOL_BIT_MASK_SIZE
);
438 if (patterns
[i
].pattern_len
< 0 ||
439 patterns
[i
].pattern_len
> MAX_WOL_PATTERN_SIZE
) {
440 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_WARNING
,
441 "Pattern[%d] is too long\n", i
);
444 pattern_os
= patterns
[i
].pattern
;
445 mask_len
= DIV_ROUND_UP(patterns
[i
].pattern_len
, 8);
446 mask_os
= patterns
[i
].mask
;
447 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
448 "pattern content\n", pattern_os
,
449 patterns
[i
].pattern_len
);
450 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
451 "mask content\n", mask_os
, mask_len
);
452 /* 1. unicast? multicast? or broadcast? */
453 if (memcmp(pattern_os
, broadcast_addr
, 6) == 0)
454 rtl_pattern
.type
= BROADCAST_PATTERN
;
455 else if (memcmp(pattern_os
, multicast_addr1
, 2) == 0 ||
456 memcmp(pattern_os
, multicast_addr2
, 3) == 0)
457 rtl_pattern
.type
= MULTICAST_PATTERN
;
458 else if (memcmp(pattern_os
, mac
->mac_addr
, 6) == 0)
459 rtl_pattern
.type
= UNICAST_PATTERN
;
461 rtl_pattern
.type
= UNKNOWN_TYPE
;
463 /* 2. translate mask_from_os to mask_for_hw */
465 /******************************************************************************
466 * pattern from OS uses 'ethenet frame', like this:
468 | 6 | 6 | 2 | 20 | Variable | 4 |
469 |--------+--------+------+-----------+------------+-----|
470 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
473 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
475 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
476 |-------------------+--------+------+-----------+------------+-----|
477 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
480 * Therefore, we need translate mask_from_OS to mask_to_hw.
481 * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
482 * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
483 * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
484 ******************************************************************************/
487 for (j
= 0; j
< mask_len
- 1; j
++) {
488 mask
[j
] = mask_os
[j
] >> 6;
489 mask
[j
] |= (mask_os
[j
+ 1] & 0x3F) << 2;
491 mask
[j
] = (mask_os
[j
] >> 6) & 0x3F;
492 /* Set bit 0-5 to zero */
495 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
496 "mask to hw\n", mask
, mask_len
);
497 for (j
= 0; j
< (MAX_WOL_BIT_MASK_SIZE
+ 1) / 4; j
++) {
498 rtl_pattern
.mask
[j
] = mask
[j
* 4];
499 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 1] << 8);
500 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 2] << 16);
501 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 3] << 24);
504 /* To get the wake up pattern from the mask.
505 * We do not count first 12 bits which means
506 * DA[6] and SA[6] in the pattern to match HW design.
509 for (j
= 12; j
< patterns
[i
].pattern_len
; j
++) {
510 if ((mask_os
[j
/ 8] >> (j
% 8)) & 0x01) {
511 content
[len
] = pattern_os
[j
];
516 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
517 "pattern to hw\n", content
, len
);
518 /* 3. calculate crc */
519 rtl_pattern
.crc
= _calculate_wol_pattern_crc(content
, len
);
520 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_TRACE
,
521 "CRC_Remainder = 0x%x\n", rtl_pattern
.crc
);
523 /* 4. write crc & mask_for_hw to hw */
524 rtlpriv
->cfg
->ops
->add_wowlan_pattern(hw
, &rtl_pattern
, i
);
526 rtl_write_byte(rtlpriv
, 0x698, wow
->n_patterns
);
529 static int rtl_op_suspend(struct ieee80211_hw
*hw
,
530 struct cfg80211_wowlan
*wow
)
532 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
533 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
534 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
536 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
540 /* to resolve s4 can not wake up*/
541 rtlhal
->last_suspend_sec
= ktime_get_real_seconds();
543 if ((ppsc
->wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) && wow
->n_patterns
)
544 _rtl_add_wowlan_patterns(hw
, wow
);
546 rtlhal
->driver_is_goingto_unload
= true;
547 rtlhal
->enter_pnp_sleep
= true;
549 rtl_lps_leave(hw
, true);
551 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), true);
555 static int rtl_op_resume(struct ieee80211_hw
*hw
)
557 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
558 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
559 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
562 rtl_dbg(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
563 rtlhal
->driver_is_goingto_unload
= false;
564 rtlhal
->enter_pnp_sleep
= false;
565 rtlhal
->wake_from_pnp_sleep
= true;
567 /* to resovle s4 can not wake up*/
568 now
= ktime_get_real_seconds();
569 if (now
- rtlhal
->last_suspend_sec
< 5)
573 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), false);
574 ieee80211_resume_disconnect(mac
->vif
);
575 rtlhal
->wake_from_pnp_sleep
= false;
580 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
582 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
583 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
584 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
585 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
586 struct ieee80211_conf
*conf
= &hw
->conf
;
591 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
592 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /* BIT(2)*/
593 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
594 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
598 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
599 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
605 *although rfoff may not cause by ips, but we will
606 *check the reason in set_rf_power_state function
608 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
613 if ((changed
& IEEE80211_CONF_CHANGE_PS
) &&
614 rtlpriv
->psc
.swctrl_lps
&& !rtlpriv
->psc
.fwctrl_lps
) {
615 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
616 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
617 if (conf
->flags
& IEEE80211_CONF_PS
) {
618 rtlpriv
->psc
.sw_ps_enabled
= true;
619 /* sleep here is must, or we may recv the beacon and
620 * cause mac80211 into wrong ps state, this will cause
621 * power save nullfunc send fail, and further cause
622 * pkt loss, So sleep must quickly but not immediatly
623 * because that will cause nullfunc send by mac80211
624 * fail, and cause pkt loss, we have tested that 5mA
625 * is worked very well */
626 if (!rtlpriv
->psc
.multi_buffered
)
627 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
628 &rtlpriv
->works
.ps_work
,
631 rtl_swlps_rf_awake(hw
);
632 rtlpriv
->psc
.sw_ps_enabled
= false;
636 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
637 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
638 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
639 hw
->conf
.long_frame_max_tx_count
);
640 /* brought up everything changes (changed == ~0) indicates first
641 * open, so use our default value instead of that of wiphy.
644 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
645 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
646 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
647 (u8
*)(&hw
->conf
.long_frame_max_tx_count
));
651 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
652 !rtlpriv
->proximity
.proxim_on
) {
653 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
654 enum nl80211_chan_width width
= hw
->conf
.chandef
.width
;
655 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
656 u8 wide_chan
= (u8
) channel
->hw_value
;
658 /* channel_type is for 20&40M */
659 if (width
< NL80211_CHAN_WIDTH_80
)
661 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
662 if (mac
->act_scanning
)
665 if (rtlpriv
->dm
.supp_phymode_switch
&&
666 mac
->link_state
< MAC80211_LINKED
&&
667 !mac
->act_scanning
) {
668 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
669 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
673 *because we should back channel to
674 *current_network.chan in in scanning,
675 *So if set_chan == current_network.chan
677 *because mac80211 tell us wrong bw40
678 *info for cisco1253 bw20, so we modify
679 *it here based on UPPER & LOWER
682 if (width
>= NL80211_CHAN_WIDTH_80
) {
683 if (width
== NL80211_CHAN_WIDTH_80
) {
684 u32 center
= hw
->conf
.chandef
.center_freq1
;
686 (u32
)hw
->conf
.chandef
.chan
->center_freq
;
688 rtlphy
->current_chan_bw
=
692 if (center
> primary
) {
693 mac
->cur_80_prime_sc
=
694 PRIME_CHNL_OFFSET_LOWER
;
695 if (center
- primary
== 10) {
696 mac
->cur_40_prime_sc
=
697 PRIME_CHNL_OFFSET_UPPER
;
700 } else if (center
- primary
== 30) {
701 mac
->cur_40_prime_sc
=
702 PRIME_CHNL_OFFSET_LOWER
;
707 mac
->cur_80_prime_sc
=
708 PRIME_CHNL_OFFSET_UPPER
;
709 if (primary
- center
== 10) {
710 mac
->cur_40_prime_sc
=
711 PRIME_CHNL_OFFSET_LOWER
;
714 } else if (primary
- center
== 30) {
715 mac
->cur_40_prime_sc
=
716 PRIME_CHNL_OFFSET_UPPER
;
723 switch (channel_type
) {
724 case NL80211_CHAN_HT20
:
725 case NL80211_CHAN_NO_HT
:
727 mac
->cur_40_prime_sc
=
728 PRIME_CHNL_OFFSET_DONT_CARE
;
729 rtlphy
->current_chan_bw
=
734 case NL80211_CHAN_HT40MINUS
:
736 mac
->cur_40_prime_sc
=
737 PRIME_CHNL_OFFSET_UPPER
;
738 rtlphy
->current_chan_bw
=
739 HT_CHANNEL_WIDTH_20_40
;
747 case NL80211_CHAN_HT40PLUS
:
749 mac
->cur_40_prime_sc
=
750 PRIME_CHNL_OFFSET_LOWER
;
751 rtlphy
->current_chan_bw
=
752 HT_CHANNEL_WIDTH_20_40
;
763 pr_err("switch case %#x not processed\n",
772 /* In scanning, when before we offchannel we may send a ps=1
773 * null to AP, and then we may send a ps = 0 null to AP quickly,
774 * but first null may have caused AP to put lots of packet to
775 * hw tx buffer. These packets must be tx'd before we go off
776 * channel so we must delay more time to let AP flush these
777 * packets before going offchannel, or dis-association or
778 * delete BA will be caused by AP
780 if (rtlpriv
->mac80211
.offchan_delay
) {
781 rtlpriv
->mac80211
.offchan_delay
= false;
785 rtlphy
->current_channel
= wide_chan
;
787 rtlpriv
->cfg
->ops
->switch_channel(hw
);
788 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
789 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, channel_type
);
792 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
797 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
798 unsigned int changed_flags
,
799 unsigned int *new_flags
, u64 multicast
)
801 bool update_rcr
= false;
802 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
803 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
805 *new_flags
&= RTL_SUPPORTED_FILTERS
;
806 if (0 == changed_flags
)
809 /*TODO: we disable broadcase now, so enable here */
810 if (changed_flags
& FIF_ALLMULTI
) {
811 if (*new_flags
& FIF_ALLMULTI
) {
812 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
813 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
814 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
815 "Enable receive multicast frame\n");
817 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
818 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
819 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
820 "Disable receive multicast frame\n");
825 if (changed_flags
& FIF_FCSFAIL
) {
826 if (*new_flags
& FIF_FCSFAIL
) {
827 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
828 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
829 "Enable receive FCS error frame\n");
831 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
832 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
833 "Disable receive FCS error frame\n");
839 /* if ssid not set to hw don't check bssid
840 * here just used for linked scanning, & linked
841 * and nolink check bssid is set in set network_type
843 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
&&
844 mac
->link_state
>= MAC80211_LINKED
) {
845 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
846 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
847 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
848 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
850 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
856 if (changed_flags
& FIF_CONTROL
) {
857 if (*new_flags
& FIF_CONTROL
) {
858 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
860 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
861 "Enable receive control frame.\n");
863 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
864 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
865 "Disable receive control frame.\n");
871 if (changed_flags
& FIF_OTHER_BSS
) {
872 if (*new_flags
& FIF_OTHER_BSS
) {
873 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
874 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
875 "Enable receive other BSS's frame.\n");
877 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
878 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
879 "Disable receive other BSS's frame.\n");
886 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
887 (u8
*)(&mac
->rx_conf
));
890 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
891 struct ieee80211_vif
*vif
,
892 struct ieee80211_sta
*sta
)
894 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
895 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
896 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
897 struct rtl_sta_info
*sta_entry
;
900 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
901 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
902 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
903 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
904 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
905 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
906 if (sta
->supp_rates
[0] <= 0xf)
907 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
908 if (sta
->ht_cap
.ht_supported
)
909 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
911 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
912 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
913 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
914 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
915 if (sta
->ht_cap
.ht_supported
)
916 sta_entry
->wireless_mode
= WIRELESS_MODE_N_5G
;
917 if (sta
->vht_cap
.vht_supported
)
918 sta_entry
->wireless_mode
= WIRELESS_MODE_AC_5G
;
920 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
921 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
923 /*disable cck rate for p2p*/
925 sta
->supp_rates
[0] &= 0xfffffff0;
927 memcpy(sta_entry
->mac_addr
, sta
->addr
, ETH_ALEN
);
928 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
929 "Add sta addr is %pM\n", sta
->addr
);
930 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0, true);
936 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
937 struct ieee80211_vif
*vif
,
938 struct ieee80211_sta
*sta
)
940 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
941 struct rtl_sta_info
*sta_entry
;
944 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
945 "Remove sta addr is %pM\n", sta
->addr
);
946 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
947 sta_entry
->wireless_mode
= 0;
948 sta_entry
->ratr_index
= 0;
949 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
950 list_del(&sta_entry
->list
);
951 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
956 static int _rtl_get_hal_qnum(u16 queue
)
981 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
982 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
984 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
985 struct ieee80211_vif
*vif
, u16 queue
,
986 const struct ieee80211_tx_queue_params
*param
)
988 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
989 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
992 if (queue
>= AC_MAX
) {
993 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
994 "queue number %d is incorrect!\n", queue
);
998 aci
= _rtl_get_hal_qnum(queue
);
999 mac
->ac
[aci
].aifs
= param
->aifs
;
1000 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
1001 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
1002 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
1003 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
1004 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
1008 static void send_beacon_frame(struct ieee80211_hw
*hw
,
1009 struct ieee80211_vif
*vif
)
1011 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1012 struct sk_buff
*skb
= ieee80211_beacon_get(hw
, vif
);
1013 struct rtl_tcb_desc tcb_desc
;
1016 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1017 rtlpriv
->intf_ops
->adapter_tx(hw
, NULL
, skb
, &tcb_desc
);
1021 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
1022 struct ieee80211_vif
*vif
,
1023 struct ieee80211_bss_conf
*bss_conf
,
1026 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1027 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1028 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1029 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1031 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1032 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
1033 vif
->type
== NL80211_IFTYPE_AP
||
1034 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1035 if (changed
& BSS_CHANGED_BEACON
||
1036 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
1037 bss_conf
->enable_beacon
)) {
1038 if (mac
->beacon_enabled
== 0) {
1039 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1040 "BSS_CHANGED_BEACON_ENABLED\n");
1042 /*start hw beacon interrupt. */
1043 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
1044 mac
->beacon_enabled
= 1;
1045 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
1047 [RTL_IBSS_INT_MASKS
], 0);
1049 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1050 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1051 send_beacon_frame(hw
, vif
);
1054 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
1055 !bss_conf
->enable_beacon
)) {
1056 if (mac
->beacon_enabled
== 1) {
1057 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1058 "ADHOC DISABLE BEACON\n");
1060 mac
->beacon_enabled
= 0;
1061 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
1063 [RTL_IBSS_INT_MASKS
]);
1066 if (changed
& BSS_CHANGED_BEACON_INT
) {
1067 rtl_dbg(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
1068 "BSS_CHANGED_BEACON_INT\n");
1069 mac
->beacon_interval
= bss_conf
->beacon_int
;
1070 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
1074 /*TODO: reference to enum ieee80211_bss_change */
1075 if (changed
& BSS_CHANGED_ASSOC
) {
1078 if (bss_conf
->assoc
) {
1079 struct ieee80211_sta
*sta
= NULL
;
1082 mstatus
= RT_MEDIA_CONNECT
;
1083 /* we should reset all sec info & cam
1084 * before set cam after linked, we should not
1085 * reset in disassoc, that will cause tkip->wep
1086 * fail because some flag will be wrong */
1087 /* reset sec info */
1088 rtl_cam_reset_sec_info(hw
);
1089 /* reset cam to fix wep fail issue
1090 * when change from wpa to wep */
1091 rtl_cam_reset_all_entry(hw
);
1093 mac
->link_state
= MAC80211_LINKED
;
1094 mac
->cnt_after_linked
= 0;
1095 mac
->assoc_id
= bss_conf
->aid
;
1096 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1098 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1099 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1102 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1107 rtl_dbg(rtlpriv
, COMP_EASY_CONCURRENT
, DBG_LOUD
,
1108 "send PS STATIC frame\n");
1109 if (rtlpriv
->dm
.supp_phymode_switch
) {
1110 if (sta
->ht_cap
.ht_supported
)
1111 rtl_send_smps_action(hw
, sta
,
1112 IEEE80211_SMPS_STATIC
);
1115 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1116 mac
->mode
= WIRELESS_MODE_A
;
1118 if (sta
->supp_rates
[0] <= 0xf)
1119 mac
->mode
= WIRELESS_MODE_B
;
1121 mac
->mode
= WIRELESS_MODE_G
;
1124 if (sta
->ht_cap
.ht_supported
) {
1125 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1126 mac
->mode
= WIRELESS_MODE_N_24G
;
1128 mac
->mode
= WIRELESS_MODE_N_5G
;
1131 if (sta
->vht_cap
.vht_supported
) {
1132 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1133 mac
->mode
= WIRELESS_MODE_AC_5G
;
1135 mac
->mode
= WIRELESS_MODE_AC_24G
;
1138 if (vif
->type
== NL80211_IFTYPE_STATION
)
1139 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0,
1143 /* to avoid AP Disassociation caused by inactivity */
1144 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1146 (u8
*)(&keep_alive
));
1148 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1149 "BSS_CHANGED_ASSOC\n");
1151 struct cfg80211_bss
*bss
= NULL
;
1153 mstatus
= RT_MEDIA_DISCONNECT
;
1155 if (mac
->link_state
== MAC80211_LINKED
)
1156 rtl_lps_leave(hw
, true);
1157 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
1158 rtl_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
1159 mac
->link_state
= MAC80211_NOLINK
;
1161 bss
= cfg80211_get_bss(hw
->wiphy
, NULL
,
1162 (u8
*)mac
->bssid
, NULL
, 0,
1163 IEEE80211_BSS_TYPE_ESS
,
1164 IEEE80211_PRIVACY_OFF
);
1166 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1167 "bssid = %pMF\n", mac
->bssid
);
1170 cfg80211_unlink_bss(hw
->wiphy
, bss
);
1171 cfg80211_put_bss(hw
->wiphy
, bss
);
1172 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1173 "cfg80211_unlink !!\n");
1176 eth_zero_addr(mac
->bssid
);
1177 mac
->vendor
= PEER_UNKNOWN
;
1180 if (rtlpriv
->dm
.supp_phymode_switch
) {
1181 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1182 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1184 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1185 "BSS_CHANGED_UN_ASSOC\n");
1187 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
1189 * To tell firmware we have connected or disconnected
1191 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1192 HW_VAR_H2C_FW_JOINBSSRPT
,
1194 ppsc
->report_linked
= (mstatus
== RT_MEDIA_CONNECT
) ?
1197 if (rtlpriv
->cfg
->ops
->get_btc_status())
1198 rtlpriv
->btcoexist
.btc_ops
->btc_mediastatus_notify(
1202 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1203 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1204 "BSS_CHANGED_ERP_CTS_PROT\n");
1205 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
1208 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1209 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
1210 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
1211 bss_conf
->use_short_preamble
);
1213 mac
->short_preamble
= bss_conf
->use_short_preamble
;
1214 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
1215 (u8
*)(&mac
->short_preamble
));
1218 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1219 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1220 "BSS_CHANGED_ERP_SLOT\n");
1222 if (bss_conf
->use_short_slot
)
1223 mac
->slot_time
= RTL_SLOT_TIME_9
;
1225 mac
->slot_time
= RTL_SLOT_TIME_20
;
1227 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
1228 (u8
*)(&mac
->slot_time
));
1231 if (changed
& BSS_CHANGED_HT
) {
1232 struct ieee80211_sta
*sta
= NULL
;
1234 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1235 "BSS_CHANGED_HT\n");
1238 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1240 if (sta
->ht_cap
.ampdu_density
>
1241 mac
->current_ampdu_density
)
1242 mac
->current_ampdu_density
=
1243 sta
->ht_cap
.ampdu_density
;
1244 if (sta
->ht_cap
.ampdu_factor
<
1245 mac
->current_ampdu_factor
)
1246 mac
->current_ampdu_factor
=
1247 sta
->ht_cap
.ampdu_factor
;
1251 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
1252 (u8
*)(&mac
->max_mss_density
));
1253 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
1254 &mac
->current_ampdu_factor
);
1255 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
1256 &mac
->current_ampdu_density
);
1259 if (changed
& BSS_CHANGED_BSSID
) {
1261 struct ieee80211_sta
*sta
= NULL
;
1263 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
1264 (u8
*)bss_conf
->bssid
);
1266 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1267 "bssid: %pM\n", bss_conf
->bssid
);
1269 mac
->vendor
= PEER_UNKNOWN
;
1270 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1273 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1279 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1280 mac
->mode
= WIRELESS_MODE_A
;
1282 if (sta
->supp_rates
[0] <= 0xf)
1283 mac
->mode
= WIRELESS_MODE_B
;
1285 mac
->mode
= WIRELESS_MODE_G
;
1288 if (sta
->ht_cap
.ht_supported
) {
1289 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1290 mac
->mode
= WIRELESS_MODE_N_24G
;
1292 mac
->mode
= WIRELESS_MODE_N_5G
;
1295 if (sta
->vht_cap
.vht_supported
) {
1296 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1297 mac
->mode
= WIRELESS_MODE_AC_5G
;
1299 mac
->mode
= WIRELESS_MODE_AC_24G
;
1302 /* just station need it, because ibss & ap mode will
1303 * set in sta_add, and will be NULL here */
1304 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1305 struct rtl_sta_info
*sta_entry
;
1307 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1308 sta_entry
->wireless_mode
= mac
->mode
;
1311 if (sta
->ht_cap
.ht_supported
) {
1312 mac
->ht_enable
= true;
1315 * for cisco 1252 bw20 it's wrong
1316 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1317 * mac->bw_40 = true;
1322 if (sta
->vht_cap
.vht_supported
)
1323 mac
->vht_enable
= true;
1325 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1326 /* for 5G must << RATE_6M_INDEX = 4,
1327 * because 5G have no cck rate*/
1328 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1329 basic_rates
= sta
->supp_rates
[1] << 4;
1331 basic_rates
= sta
->supp_rates
[0];
1333 mac
->basic_rates
= basic_rates
;
1334 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
1335 (u8
*)(&basic_rates
));
1340 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1343 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1345 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1348 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&tsf
));
1352 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
,
1353 struct ieee80211_vif
*vif
, u64 tsf
)
1355 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1356 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1357 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
1360 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&bibss
));
1363 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1365 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1368 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*)(&tmp
));
1371 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
1372 struct ieee80211_vif
*vif
,
1373 enum sta_notify_cmd cmd
,
1374 struct ieee80211_sta
*sta
)
1377 case STA_NOTIFY_SLEEP
:
1379 case STA_NOTIFY_AWAKE
:
1386 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
1387 struct ieee80211_vif
*vif
,
1388 struct ieee80211_ampdu_params
*params
)
1390 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1391 struct ieee80211_sta
*sta
= params
->sta
;
1392 enum ieee80211_ampdu_mlme_action action
= params
->action
;
1393 u16 tid
= params
->tid
;
1394 u16
*ssn
= ¶ms
->ssn
;
1397 case IEEE80211_AMPDU_TX_START
:
1398 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1399 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid
);
1400 return rtl_tx_agg_start(hw
, vif
, sta
, tid
, ssn
);
1401 case IEEE80211_AMPDU_TX_STOP_CONT
:
1402 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1403 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1404 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1405 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
);
1406 return rtl_tx_agg_stop(hw
, vif
, sta
, tid
);
1407 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1408 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1409 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
);
1410 rtl_tx_agg_oper(hw
, sta
, tid
);
1412 case IEEE80211_AMPDU_RX_START
:
1413 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1414 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid
);
1415 return rtl_rx_agg_start(hw
, sta
, tid
);
1416 case IEEE80211_AMPDU_RX_STOP
:
1417 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1418 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
);
1419 return rtl_rx_agg_stop(hw
, sta
, tid
);
1421 pr_err("IEEE80211_AMPDU_ERR!!!!:\n");
1427 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
,
1428 struct ieee80211_vif
*vif
,
1431 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1432 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1434 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1435 mac
->act_scanning
= true;
1436 if (rtlpriv
->link_info
.higher_busytraffic
) {
1437 mac
->skip_scan
= true;
1441 if (rtlpriv
->cfg
->ops
->get_btc_status())
1442 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 1);
1443 else if (rtlpriv
->btcoexist
.btc_ops
)
1444 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1447 if (rtlpriv
->dm
.supp_phymode_switch
) {
1448 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1449 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1452 if (mac
->link_state
== MAC80211_LINKED
) {
1453 rtl_lps_leave(hw
, true);
1454 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1460 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1462 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1463 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP_BAND0
);
1466 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
,
1467 struct ieee80211_vif
*vif
)
1469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1470 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1472 rtl_dbg(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1473 mac
->act_scanning
= false;
1474 mac
->skip_scan
= false;
1476 rtlpriv
->btcoexist
.btc_info
.ap_num
= rtlpriv
->scan_list
.num
;
1478 if (rtlpriv
->link_info
.higher_busytraffic
)
1481 /* p2p will use 1/6/11 to scan */
1482 if (mac
->n_channels
== 3)
1483 mac
->p2p_in_use
= true;
1485 mac
->p2p_in_use
= false;
1486 mac
->n_channels
= 0;
1488 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1490 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1491 mac
->link_state
= MAC80211_LINKED
;
1492 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1493 /* fix fwlps issue */
1494 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1498 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1499 if (rtlpriv
->cfg
->ops
->get_btc_status())
1500 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 0);
1501 else if (rtlpriv
->btcoexist
.btc_ops
)
1502 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1506 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1507 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1508 struct ieee80211_key_conf
*key
)
1510 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1511 u8 key_type
= NO_ENCRYPTION
;
1513 bool group_key
= false;
1514 bool wep_only
= false;
1516 u8 mac_addr
[ETH_ALEN
];
1517 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1519 rtlpriv
->btcoexist
.btc_info
.in_4way
= false;
1521 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1522 rtl_dbg(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1523 "not open hw encryption\n");
1524 return -ENOSPC
; /*User disabled HW-crypto */
1526 /* To support IBSS, use sw-crypto for GTK */
1527 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1528 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1529 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1531 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1532 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1533 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1534 sta
? sta
->addr
: bcast_addr
);
1535 rtlpriv
->sec
.being_setkey
= true;
1537 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1538 /* <1> get encryption alg */
1540 switch (key
->cipher
) {
1541 case WLAN_CIPHER_SUITE_WEP40
:
1542 key_type
= WEP40_ENCRYPTION
;
1543 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP40\n");
1545 case WLAN_CIPHER_SUITE_WEP104
:
1546 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP104\n");
1547 key_type
= WEP104_ENCRYPTION
;
1549 case WLAN_CIPHER_SUITE_TKIP
:
1550 key_type
= TKIP_ENCRYPTION
;
1551 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:TKIP\n");
1553 case WLAN_CIPHER_SUITE_CCMP
:
1554 key_type
= AESCCMP_ENCRYPTION
;
1555 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CCMP\n");
1557 case WLAN_CIPHER_SUITE_AES_CMAC
:
1558 /* HW don't support CMAC encryption,
1559 * use software CMAC encryption
1561 key_type
= AESCMAC_ENCRYPTION
;
1562 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CMAC\n");
1563 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1564 "HW don't support CMAC encryption, use software CMAC encryption\n");
1568 pr_err("alg_err:%x!!!!:\n", key
->cipher
);
1571 if (key_type
== WEP40_ENCRYPTION
||
1572 key_type
== WEP104_ENCRYPTION
||
1573 vif
->type
== NL80211_IFTYPE_ADHOC
)
1574 rtlpriv
->sec
.use_defaultkey
= true;
1576 /* <2> get key_idx */
1577 key_idx
= (u8
) (key
->keyidx
);
1580 /* <3> if pairwise key enable_hw_sec */
1581 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1583 /* wep always be group key, but there are two conditions:
1584 * 1) wep only: is just for wep enc, in this condition
1585 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1586 * will be true & enable_hw_sec will be set when wep
1588 * 2) wep(group) + AES(pairwise): some AP like cisco
1589 * may use it, in this condition enable_hw_sec will not
1590 * be set when wep key setting */
1591 /* we must reset sec_info after lingked before set key,
1592 * or some flag will be wrong*/
1593 if (vif
->type
== NL80211_IFTYPE_AP
||
1594 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1595 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1596 key_type
== WEP104_ENCRYPTION
) {
1599 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1602 if (!group_key
|| vif
->type
== NL80211_IFTYPE_ADHOC
||
1603 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1604 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1606 (key_type
== WEP40_ENCRYPTION
||
1607 key_type
== WEP104_ENCRYPTION
))
1609 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1610 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1611 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1613 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1616 /* <4> set key based on cmd */
1620 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1621 "set WEP(group/pairwise) key\n");
1622 /* Pairwise key with an assigned MAC address. */
1623 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1624 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1625 /*set local buf about wep key. */
1626 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1627 key
->key
, key
->keylen
);
1628 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1629 eth_zero_addr(mac_addr
);
1630 } else if (group_key
) { /* group key */
1631 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1634 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1635 /*set local buf about group key. */
1636 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1637 key
->key
, key
->keylen
);
1638 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1639 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1640 } else { /* pairwise key */
1641 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1642 "set pairwise key\n");
1645 "rtlwifi: pairwise key without mac_addr\n");
1650 /* Pairwise key with an assigned MAC address. */
1651 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1652 /*set local buf about pairwise key. */
1653 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1654 key
->key
, key
->keylen
);
1655 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1656 rtlpriv
->sec
.pairwise_key
=
1657 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1658 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1660 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1661 group_key
, key_type
, wep_only
,
1663 /* <5> tell mac80211 do something: */
1664 /*must use sw generate IV, or can not work !!!!. */
1665 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1666 key
->hw_key_idx
= key_idx
;
1667 if (key_type
== TKIP_ENCRYPTION
)
1668 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1669 /*use software CCMP encryption for management frames (MFP) */
1670 if (key_type
== AESCCMP_ENCRYPTION
)
1671 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1674 rtl_dbg(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1675 "disable key delete one entry\n");
1676 /*set local buf about wep key. */
1677 if (vif
->type
== NL80211_IFTYPE_AP
||
1678 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1680 rtl_cam_del_entry(hw
, sta
->addr
);
1682 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1683 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1684 eth_zero_addr(mac_addr
);
1686 *mac80211 will delete entrys one by one,
1687 *so don't use rtl_cam_reset_all_entry
1688 *or clear all entry here.
1690 rtl_wait_tx_report_acked(hw
, 500); /* wait 500ms for TX ack */
1692 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1695 pr_err("cmd_err:%x!!!!:\n", cmd
);
1698 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1699 rtlpriv
->sec
.being_setkey
= false;
1703 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1705 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1711 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1714 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1716 /*if Radio On return true here */
1717 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1720 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1721 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1723 rtl_dbg(rtlpriv
, COMP_RF
, DBG_DMESG
,
1724 "wireless radio switch turned %s\n",
1725 radio_state
? "on" : "off");
1727 blocked
= !rtlpriv
->rfkill
.rfkill_state
;
1728 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1732 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1735 /* this function is called by mac80211 to flush tx buffer
1736 * before switch channle or power save, or tx buffer packet
1737 * maybe send after offchannel or rf sleep, this may cause
1738 * dis-association by AP */
1739 static void rtl_op_flush(struct ieee80211_hw
*hw
,
1740 struct ieee80211_vif
*vif
,
1744 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1746 if (rtlpriv
->intf_ops
->flush
)
1747 rtlpriv
->intf_ops
->flush(hw
, queues
, drop
);
1751 * This routine deals with the Power Configuration CMD
1752 * parsing for RTL8723/RTL8188E Series IC.
1754 * We should follow specific format that was released from HW SD.
1756 bool rtl_hal_pwrseqcmdparsing(struct rtl_priv
*rtlpriv
, u8 cut_version
,
1757 u8 faversion
, u8 interface_type
,
1758 struct wlan_pwr_cfg pwrcfgcmd
[])
1760 struct wlan_pwr_cfg cfg_cmd
;
1761 bool polling_bit
= false;
1765 u32 polling_count
= 0;
1766 u32 max_polling_cnt
= 5000;
1769 cfg_cmd
= pwrcfgcmd
[ary_idx
];
1770 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1771 "%s: offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n",
1773 GET_PWR_CFG_OFFSET(cfg_cmd
),
1774 GET_PWR_CFG_CUT_MASK(cfg_cmd
),
1775 GET_PWR_CFG_FAB_MASK(cfg_cmd
),
1776 GET_PWR_CFG_INTF_MASK(cfg_cmd
),
1777 GET_PWR_CFG_BASE(cfg_cmd
), GET_PWR_CFG_CMD(cfg_cmd
),
1778 GET_PWR_CFG_MASK(cfg_cmd
), GET_PWR_CFG_VALUE(cfg_cmd
));
1780 if ((GET_PWR_CFG_FAB_MASK(cfg_cmd
)&faversion
) &&
1781 (GET_PWR_CFG_CUT_MASK(cfg_cmd
)&cut_version
) &&
1782 (GET_PWR_CFG_INTF_MASK(cfg_cmd
)&interface_type
)) {
1783 switch (GET_PWR_CFG_CMD(cfg_cmd
)) {
1785 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1786 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
1789 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1790 "%s(): PWR_CMD_WRITE\n", __func__
);
1791 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1793 /*Read the value from system register*/
1794 value
= rtl_read_byte(rtlpriv
, offset
);
1795 value
&= (~(GET_PWR_CFG_MASK(cfg_cmd
)));
1796 value
|= (GET_PWR_CFG_VALUE(cfg_cmd
) &
1797 GET_PWR_CFG_MASK(cfg_cmd
));
1799 /*Write the value back to sytem register*/
1800 rtl_write_byte(rtlpriv
, offset
, value
);
1802 case PWR_CMD_POLLING
:
1803 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1804 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n");
1805 polling_bit
= false;
1806 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1809 value
= rtl_read_byte(rtlpriv
, offset
);
1811 value
&= GET_PWR_CFG_MASK(cfg_cmd
);
1813 (GET_PWR_CFG_VALUE(cfg_cmd
) &
1814 GET_PWR_CFG_MASK(cfg_cmd
)))
1819 if (polling_count
++ > max_polling_cnt
)
1821 } while (!polling_bit
);
1824 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1825 "%s: PWR_CMD_DELAY\n", __func__
);
1826 if (GET_PWR_CFG_VALUE(cfg_cmd
) ==
1828 udelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1830 mdelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1833 rtl_dbg(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1834 "%s: PWR_CMD_END\n", __func__
);
1838 "rtlwifi: rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
1847 EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing
);
1849 bool rtl_cmd_send_packet(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1851 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1852 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1853 struct rtl8192_tx_ring
*ring
;
1854 struct rtl_tx_desc
*pdesc
;
1855 unsigned long flags
;
1856 struct sk_buff
*pskb
= NULL
;
1858 ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
1860 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1861 pskb
= __skb_dequeue(&ring
->queue
);
1863 dev_kfree_skb_irq(pskb
);
1865 /*this is wrong, fill_tx_cmddesc needs update*/
1866 pdesc
= &ring
->desc
[0];
1868 rtlpriv
->cfg
->ops
->fill_tx_cmddesc(hw
, (u8
*)pdesc
, 1, 1, skb
);
1870 __skb_queue_tail(&ring
->queue
, skb
);
1872 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1874 rtlpriv
->cfg
->ops
->tx_polling(hw
, BEACON_QUEUE
);
1878 EXPORT_SYMBOL(rtl_cmd_send_packet
);
1879 const struct ieee80211_ops rtl_ops
= {
1880 .start
= rtl_op_start
,
1881 .stop
= rtl_op_stop
,
1883 .add_interface
= rtl_op_add_interface
,
1884 .remove_interface
= rtl_op_remove_interface
,
1885 .change_interface
= rtl_op_change_interface
,
1887 .suspend
= rtl_op_suspend
,
1888 .resume
= rtl_op_resume
,
1890 .config
= rtl_op_config
,
1891 .configure_filter
= rtl_op_configure_filter
,
1892 .set_key
= rtl_op_set_key
,
1893 .conf_tx
= rtl_op_conf_tx
,
1894 .bss_info_changed
= rtl_op_bss_info_changed
,
1895 .get_tsf
= rtl_op_get_tsf
,
1896 .set_tsf
= rtl_op_set_tsf
,
1897 .reset_tsf
= rtl_op_reset_tsf
,
1898 .sta_notify
= rtl_op_sta_notify
,
1899 .ampdu_action
= rtl_op_ampdu_action
,
1900 .sw_scan_start
= rtl_op_sw_scan_start
,
1901 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1902 .rfkill_poll
= rtl_op_rfkill_poll
,
1903 .sta_add
= rtl_op_sta_add
,
1904 .sta_remove
= rtl_op_sta_remove
,
1905 .flush
= rtl_op_flush
,
1907 EXPORT_SYMBOL_GPL(rtl_ops
);
1909 bool rtl_btc_status_false(void)
1913 EXPORT_SYMBOL_GPL(rtl_btc_status_false
);
1915 void rtl_dm_diginit(struct ieee80211_hw
*hw
, u32 cur_igvalue
)
1917 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1918 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
1920 dm_digtable
->dig_enable_flag
= true;
1921 dm_digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
1922 dm_digtable
->cur_igvalue
= cur_igvalue
;
1923 dm_digtable
->pre_igvalue
= 0;
1924 dm_digtable
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
1925 dm_digtable
->presta_cstate
= DIG_STA_DISCONNECT
;
1926 dm_digtable
->curmultista_cstate
= DIG_MULTISTA_DISCONNECT
;
1927 dm_digtable
->rssi_lowthresh
= DM_DIG_THRESH_LOW
;
1928 dm_digtable
->rssi_highthresh
= DM_DIG_THRESH_HIGH
;
1929 dm_digtable
->fa_lowthresh
= DM_FALSEALARM_THRESH_LOW
;
1930 dm_digtable
->fa_highthresh
= DM_FALSEALARM_THRESH_HIGH
;
1931 dm_digtable
->rx_gain_max
= DM_DIG_MAX
;
1932 dm_digtable
->rx_gain_min
= DM_DIG_MIN
;
1933 dm_digtable
->back_val
= DM_DIG_BACKOFF_DEFAULT
;
1934 dm_digtable
->back_range_max
= DM_DIG_BACKOFF_MAX
;
1935 dm_digtable
->back_range_min
= DM_DIG_BACKOFF_MIN
;
1936 dm_digtable
->pre_cck_cca_thres
= 0xff;
1937 dm_digtable
->cur_cck_cca_thres
= 0x83;
1938 dm_digtable
->forbidden_igi
= DM_DIG_MIN
;
1939 dm_digtable
->large_fa_hit
= 0;
1940 dm_digtable
->recover_cnt
= 0;
1941 dm_digtable
->dig_min_0
= 0x25;
1942 dm_digtable
->dig_min_1
= 0x25;
1943 dm_digtable
->media_connect_0
= false;
1944 dm_digtable
->media_connect_1
= false;
1945 rtlpriv
->dm
.dm_initialgain_enable
= true;
1946 dm_digtable
->bt30_cur_igi
= 0x32;
1947 dm_digtable
->pre_cck_pd_state
= CCK_PD_STAGE_MAX
;
1948 dm_digtable
->cur_cck_pd_state
= CCK_PD_STAGE_LOWRSSI
;
1949 dm_digtable
->pre_cck_fa_state
= 0;
1950 dm_digtable
->cur_cck_fa_state
= 0;
1952 EXPORT_SYMBOL(rtl_dm_diginit
);