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 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_LOUD
,
80 "Firmware callback routine entered!\n");
81 complete(&rtlpriv
->firmware_loading_complete
);
83 if (rtlpriv
->cfg
->alt_fw_name
) {
84 err
= request_firmware(&firmware
,
85 rtlpriv
->cfg
->alt_fw_name
,
87 pr_info("Loading alternative firmware %s\n",
88 rtlpriv
->cfg
->alt_fw_name
);
92 pr_err("Selected firmware is not available\n");
93 rtlpriv
->max_fw_size
= 0;
97 if (firmware
->size
> rtlpriv
->max_fw_size
) {
98 pr_err("Firmware is too big!\n");
99 release_firmware(firmware
);
103 memcpy(rtlpriv
->rtlhal
.pfirmware
, firmware
->data
,
105 rtlpriv
->rtlhal
.fwsize
= firmware
->size
;
107 memcpy(rtlpriv
->rtlhal
.wowlan_firmware
, firmware
->data
,
109 rtlpriv
->rtlhal
.wowlan_fwsize
= firmware
->size
;
111 release_firmware(firmware
);
114 void rtl_fw_cb(const struct firmware
*firmware
, void *context
)
116 rtl_fw_do_work(firmware
, context
, false);
118 EXPORT_SYMBOL(rtl_fw_cb
);
120 void rtl_wowlan_fw_cb(const struct firmware
*firmware
, void *context
)
122 rtl_fw_do_work(firmware
, context
, true);
124 EXPORT_SYMBOL(rtl_wowlan_fw_cb
);
126 /*mutex for start & stop is must here. */
127 static int rtl_op_start(struct ieee80211_hw
*hw
)
130 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
131 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
133 if (!is_hal_stop(rtlhal
))
135 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
137 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
138 err
= rtlpriv
->intf_ops
->adapter_start(hw
);
140 rtl_watch_dog_timer_callback(&rtlpriv
->works
.watchdog_timer
);
141 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
145 static void rtl_op_stop(struct ieee80211_hw
*hw
)
147 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
148 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
149 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
150 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
151 bool support_remote_wakeup
= false;
153 if (is_hal_stop(rtlhal
))
156 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HAL_DEF_WOWLAN
,
157 (u8
*)(&support_remote_wakeup
));
158 /* here is must, because adhoc do stop and start,
159 * but stop with RFOFF may cause something wrong,
162 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
165 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
166 /* if wowlan supported, DON'T clear connected info */
167 if (!(support_remote_wakeup
&&
168 rtlhal
->enter_pnp_sleep
)) {
169 mac
->link_state
= MAC80211_NOLINK
;
170 eth_zero_addr(mac
->bssid
);
171 mac
->vendor
= PEER_UNKNOWN
;
174 rtl_cam_reset_sec_info(hw
);
176 rtl_deinit_deferred_work(hw
, false);
178 rtlpriv
->intf_ops
->adapter_stop(hw
);
180 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
183 static void rtl_op_tx(struct ieee80211_hw
*hw
,
184 struct ieee80211_tx_control
*control
,
187 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
188 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
189 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
190 struct rtl_tcb_desc tcb_desc
;
192 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
194 if (unlikely(is_hal_stop(rtlhal
) || ppsc
->rfpwr_state
!= ERFON
))
197 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
200 if (!rtlpriv
->intf_ops
->waitq_insert(hw
, control
->sta
, skb
))
201 rtlpriv
->intf_ops
->adapter_tx(hw
, control
->sta
, skb
, &tcb_desc
);
205 dev_kfree_skb_any(skb
);
208 static int rtl_op_add_interface(struct ieee80211_hw
*hw
,
209 struct ieee80211_vif
*vif
)
211 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
212 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
214 u8 retry_limit
= 0x30;
217 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
218 "vif has been set!! mac->vif = 0x%p\n", mac
->vif
);
222 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
226 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
227 switch (ieee80211_vif_type_p2p(vif
)) {
228 case NL80211_IFTYPE_P2P_CLIENT
:
229 mac
->p2p
= P2P_ROLE_CLIENT
;
231 case NL80211_IFTYPE_STATION
:
232 if (mac
->beacon_enabled
== 1) {
233 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
234 "NL80211_IFTYPE_STATION\n");
235 mac
->beacon_enabled
= 0;
236 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
237 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
240 case NL80211_IFTYPE_ADHOC
:
241 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
242 "NL80211_IFTYPE_ADHOC\n");
244 mac
->link_state
= MAC80211_LINKED
;
245 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
246 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
247 mac
->basic_rates
= 0xfff;
249 mac
->basic_rates
= 0xff0;
250 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
251 (u8
*)(&mac
->basic_rates
));
255 case NL80211_IFTYPE_P2P_GO
:
256 mac
->p2p
= P2P_ROLE_GO
;
258 case NL80211_IFTYPE_AP
:
259 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
260 "NL80211_IFTYPE_AP\n");
262 mac
->link_state
= MAC80211_LINKED
;
263 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
264 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
265 mac
->basic_rates
= 0xfff;
267 mac
->basic_rates
= 0xff0;
268 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
269 (u8
*)(&mac
->basic_rates
));
273 case NL80211_IFTYPE_MESH_POINT
:
274 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
275 "NL80211_IFTYPE_MESH_POINT\n");
277 mac
->link_state
= MAC80211_LINKED
;
278 rtlpriv
->cfg
->ops
->set_bcn_reg(hw
);
279 if (rtlpriv
->rtlhal
.current_bandtype
== BAND_ON_2_4G
)
280 mac
->basic_rates
= 0xfff;
282 mac
->basic_rates
= 0xff0;
283 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
284 (u8
*)(&mac
->basic_rates
));
289 pr_err("operation mode %d is not supported!\n",
296 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
297 "p2p role %x\n", vif
->type
);
298 mac
->basic_rates
= 0xff0;/*disable cck rate for p2p*/
299 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
300 (u8
*)(&mac
->basic_rates
));
303 mac
->opmode
= vif
->type
;
304 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
305 memcpy(mac
->mac_addr
, vif
->addr
, ETH_ALEN
);
306 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
308 mac
->retry_long
= retry_limit
;
309 mac
->retry_short
= retry_limit
;
310 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
311 (u8
*)(&retry_limit
));
313 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
317 static void rtl_op_remove_interface(struct ieee80211_hw
*hw
,
318 struct ieee80211_vif
*vif
)
320 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
321 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
323 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
325 /* Free beacon resources */
326 if (vif
->type
== NL80211_IFTYPE_AP
||
327 vif
->type
== NL80211_IFTYPE_ADHOC
||
328 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
329 if (mac
->beacon_enabled
== 1) {
330 mac
->beacon_enabled
= 0;
331 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
332 rtlpriv
->cfg
->maps
[RTL_IBSS_INT_MASKS
]);
337 *Note: We assume NL80211_IFTYPE_UNSPECIFIED as
338 *NO LINK for our hardware.
342 mac
->link_state
= MAC80211_NOLINK
;
343 eth_zero_addr(mac
->bssid
);
344 mac
->vendor
= PEER_UNKNOWN
;
345 mac
->opmode
= NL80211_IFTYPE_UNSPECIFIED
;
346 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
348 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
351 static int rtl_op_change_interface(struct ieee80211_hw
*hw
,
352 struct ieee80211_vif
*vif
,
353 enum nl80211_iftype new_type
, bool p2p
)
355 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
358 rtl_op_remove_interface(hw
, vif
);
360 vif
->type
= new_type
;
362 ret
= rtl_op_add_interface(hw
, vif
);
363 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
369 static u16
crc16_ccitt(u8 data
, u16 crc
)
371 u8 shift_in
, data_bit
, crc_bit11
, crc_bit4
, crc_bit15
;
375 for (i
= 0; i
< 8; i
++) {
376 crc_bit15
= ((crc
& BIT(15)) ? 1 : 0);
377 data_bit
= (data
& (BIT(0) << i
) ? 1 : 0);
378 shift_in
= crc_bit15
^ data_bit
;
386 crc_bit11
= ((crc
& BIT(11)) ? 1 : 0) ^ shift_in
;
388 result
&= (~BIT(12));
392 crc_bit4
= ((crc
& BIT(4)) ? 1 : 0) ^ shift_in
;
404 static u16
_calculate_wol_pattern_crc(u8
*pattern
, u16 len
)
409 for (i
= 0; i
< len
; i
++)
410 crc
= crc16_ccitt(pattern
[i
], crc
);
417 static void _rtl_add_wowlan_patterns(struct ieee80211_hw
*hw
,
418 struct cfg80211_wowlan
*wow
)
420 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
421 struct rtl_mac
*mac
= &rtlpriv
->mac80211
;
422 struct cfg80211_pkt_pattern
*patterns
= wow
->patterns
;
423 struct rtl_wow_pattern rtl_pattern
;
424 const u8
*pattern_os
, *mask_os
;
425 u8 mask
[MAX_WOL_BIT_MASK_SIZE
] = {0};
426 u8 content
[MAX_WOL_PATTERN_SIZE
] = {0};
427 u8 broadcast_addr
[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
428 u8 multicast_addr1
[2] = {0x33, 0x33};
429 u8 multicast_addr2
[3] = {0x01, 0x00, 0x5e};
433 for (i
= 0; i
< wow
->n_patterns
; i
++) {
434 memset(&rtl_pattern
, 0, sizeof(struct rtl_wow_pattern
));
435 memset(mask
, 0, MAX_WOL_BIT_MASK_SIZE
);
436 if (patterns
[i
].pattern_len
< 0 ||
437 patterns
[i
].pattern_len
> MAX_WOL_PATTERN_SIZE
) {
438 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_WARNING
,
439 "Pattern[%d] is too long\n", i
);
442 pattern_os
= patterns
[i
].pattern
;
443 mask_len
= DIV_ROUND_UP(patterns
[i
].pattern_len
, 8);
444 mask_os
= patterns
[i
].mask
;
445 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
446 "pattern content\n", pattern_os
,
447 patterns
[i
].pattern_len
);
448 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
449 "mask content\n", mask_os
, mask_len
);
450 /* 1. unicast? multicast? or broadcast? */
451 if (memcmp(pattern_os
, broadcast_addr
, 6) == 0)
452 rtl_pattern
.type
= BROADCAST_PATTERN
;
453 else if (memcmp(pattern_os
, multicast_addr1
, 2) == 0 ||
454 memcmp(pattern_os
, multicast_addr2
, 3) == 0)
455 rtl_pattern
.type
= MULTICAST_PATTERN
;
456 else if (memcmp(pattern_os
, mac
->mac_addr
, 6) == 0)
457 rtl_pattern
.type
= UNICAST_PATTERN
;
459 rtl_pattern
.type
= UNKNOWN_TYPE
;
461 /* 2. translate mask_from_os to mask_for_hw */
463 /******************************************************************************
464 * pattern from OS uses 'ethenet frame', like this:
466 | 6 | 6 | 2 | 20 | Variable | 4 |
467 |--------+--------+------+-----------+------------+-----|
468 | 802.3 Mac Header | IP Header | TCP Packet | FCS |
471 * BUT, packet catched by our HW is in '802.11 frame', begin from LLC,
473 | 24 or 30 | 6 | 2 | 20 | Variable | 4 |
474 |-------------------+--------+------+-----------+------------+-----|
475 | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS |
478 * Therefore, we need translate mask_from_OS to mask_to_hw.
479 * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0,
480 * because new mask[0~5] means 'SA', but our HW packet begins from LLC,
481 * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match.
482 ******************************************************************************/
485 for (j
= 0; j
< mask_len
- 1; j
++) {
486 mask
[j
] = mask_os
[j
] >> 6;
487 mask
[j
] |= (mask_os
[j
+ 1] & 0x3F) << 2;
489 mask
[j
] = (mask_os
[j
] >> 6) & 0x3F;
490 /* Set bit 0-5 to zero */
493 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
494 "mask to hw\n", mask
, mask_len
);
495 for (j
= 0; j
< (MAX_WOL_BIT_MASK_SIZE
+ 1) / 4; j
++) {
496 rtl_pattern
.mask
[j
] = mask
[j
* 4];
497 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 1] << 8);
498 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 2] << 16);
499 rtl_pattern
.mask
[j
] |= (mask
[j
* 4 + 3] << 24);
502 /* To get the wake up pattern from the mask.
503 * We do not count first 12 bits which means
504 * DA[6] and SA[6] in the pattern to match HW design.
507 for (j
= 12; j
< patterns
[i
].pattern_len
; j
++) {
508 if ((mask_os
[j
/ 8] >> (j
% 8)) & 0x01) {
509 content
[len
] = pattern_os
[j
];
514 RT_PRINT_DATA(rtlpriv
, COMP_POWER
, DBG_TRACE
,
515 "pattern to hw\n", content
, len
);
516 /* 3. calculate crc */
517 rtl_pattern
.crc
= _calculate_wol_pattern_crc(content
, len
);
518 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
519 "CRC_Remainder = 0x%x\n", rtl_pattern
.crc
);
521 /* 4. write crc & mask_for_hw to hw */
522 rtlpriv
->cfg
->ops
->add_wowlan_pattern(hw
, &rtl_pattern
, i
);
524 rtl_write_byte(rtlpriv
, 0x698, wow
->n_patterns
);
527 static int rtl_op_suspend(struct ieee80211_hw
*hw
,
528 struct cfg80211_wowlan
*wow
)
530 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
531 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
532 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
534 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
538 /* to resolve s4 can not wake up*/
539 rtlhal
->last_suspend_sec
= ktime_get_real_seconds();
541 if ((ppsc
->wo_wlan_mode
& WAKE_ON_PATTERN_MATCH
) && wow
->n_patterns
)
542 _rtl_add_wowlan_patterns(hw
, wow
);
544 rtlhal
->driver_is_goingto_unload
= true;
545 rtlhal
->enter_pnp_sleep
= true;
549 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), true);
553 static int rtl_op_resume(struct ieee80211_hw
*hw
)
555 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
556 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
557 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
560 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
, "\n");
561 rtlhal
->driver_is_goingto_unload
= false;
562 rtlhal
->enter_pnp_sleep
= false;
563 rtlhal
->wake_from_pnp_sleep
= true;
565 /* to resovle s4 can not wake up*/
566 now
= ktime_get_real_seconds();
567 if (now
- rtlhal
->last_suspend_sec
< 5)
571 device_set_wakeup_enable(wiphy_dev(hw
->wiphy
), false);
572 ieee80211_resume_disconnect(mac
->vif
);
573 rtlhal
->wake_from_pnp_sleep
= false;
578 static int rtl_op_config(struct ieee80211_hw
*hw
, u32 changed
)
580 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
581 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
582 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
583 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
584 struct ieee80211_conf
*conf
= &hw
->conf
;
589 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
590 if (changed
& IEEE80211_CONF_CHANGE_LISTEN_INTERVAL
) { /* BIT(2)*/
591 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
592 "IEEE80211_CONF_CHANGE_LISTEN_INTERVAL\n");
596 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
597 if (hw
->conf
.flags
& IEEE80211_CONF_IDLE
)
603 *although rfoff may not cause by ips, but we will
604 *check the reason in set_rf_power_state function
606 if (unlikely(ppsc
->rfpwr_state
== ERFOFF
))
611 if ((changed
& IEEE80211_CONF_CHANGE_PS
) &&
612 rtlpriv
->psc
.swctrl_lps
&& !rtlpriv
->psc
.fwctrl_lps
) {
613 cancel_delayed_work(&rtlpriv
->works
.ps_work
);
614 cancel_delayed_work(&rtlpriv
->works
.ps_rfon_wq
);
615 if (conf
->flags
& IEEE80211_CONF_PS
) {
616 rtlpriv
->psc
.sw_ps_enabled
= true;
617 /* sleep here is must, or we may recv the beacon and
618 * cause mac80211 into wrong ps state, this will cause
619 * power save nullfunc send fail, and further cause
620 * pkt loss, So sleep must quickly but not immediatly
621 * because that will cause nullfunc send by mac80211
622 * fail, and cause pkt loss, we have tested that 5mA
623 * is worked very well */
624 if (!rtlpriv
->psc
.multi_buffered
)
625 queue_delayed_work(rtlpriv
->works
.rtl_wq
,
626 &rtlpriv
->works
.ps_work
,
629 rtl_swlps_rf_awake(hw
);
630 rtlpriv
->psc
.sw_ps_enabled
= false;
634 if (changed
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
) {
635 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
636 "IEEE80211_CONF_CHANGE_RETRY_LIMITS %x\n",
637 hw
->conf
.long_frame_max_tx_count
);
638 /* brought up everything changes (changed == ~0) indicates first
639 * open, so use our default value instead of that of wiphy.
642 mac
->retry_long
= hw
->conf
.long_frame_max_tx_count
;
643 mac
->retry_short
= hw
->conf
.long_frame_max_tx_count
;
644 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RETRY_LIMIT
,
645 (u8
*)(&hw
->conf
.long_frame_max_tx_count
));
649 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
650 !rtlpriv
->proximity
.proxim_on
) {
651 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
652 enum nl80211_chan_width width
= hw
->conf
.chandef
.width
;
653 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
654 u8 wide_chan
= (u8
) channel
->hw_value
;
656 /* channel_type is for 20&40M */
657 if (width
< NL80211_CHAN_WIDTH_80
)
659 cfg80211_get_chandef_type(&hw
->conf
.chandef
);
660 if (mac
->act_scanning
)
663 if (rtlpriv
->dm
.supp_phymode_switch
&&
664 mac
->link_state
< MAC80211_LINKED
&&
665 !mac
->act_scanning
) {
666 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
667 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
671 *because we should back channel to
672 *current_network.chan in in scanning,
673 *So if set_chan == current_network.chan
675 *because mac80211 tell us wrong bw40
676 *info for cisco1253 bw20, so we modify
677 *it here based on UPPER & LOWER
680 if (width
>= NL80211_CHAN_WIDTH_80
) {
681 if (width
== NL80211_CHAN_WIDTH_80
) {
682 u32 center
= hw
->conf
.chandef
.center_freq1
;
684 (u32
)hw
->conf
.chandef
.chan
->center_freq
;
686 rtlphy
->current_chan_bw
=
690 if (center
> primary
) {
691 mac
->cur_80_prime_sc
=
692 PRIME_CHNL_OFFSET_LOWER
;
693 if (center
- primary
== 10) {
694 mac
->cur_40_prime_sc
=
695 PRIME_CHNL_OFFSET_UPPER
;
698 } else if (center
- primary
== 30) {
699 mac
->cur_40_prime_sc
=
700 PRIME_CHNL_OFFSET_LOWER
;
705 mac
->cur_80_prime_sc
=
706 PRIME_CHNL_OFFSET_UPPER
;
707 if (primary
- center
== 10) {
708 mac
->cur_40_prime_sc
=
709 PRIME_CHNL_OFFSET_LOWER
;
712 } else if (primary
- center
== 30) {
713 mac
->cur_40_prime_sc
=
714 PRIME_CHNL_OFFSET_UPPER
;
721 switch (channel_type
) {
722 case NL80211_CHAN_HT20
:
723 case NL80211_CHAN_NO_HT
:
725 mac
->cur_40_prime_sc
=
726 PRIME_CHNL_OFFSET_DONT_CARE
;
727 rtlphy
->current_chan_bw
=
732 case NL80211_CHAN_HT40MINUS
:
734 mac
->cur_40_prime_sc
=
735 PRIME_CHNL_OFFSET_UPPER
;
736 rtlphy
->current_chan_bw
=
737 HT_CHANNEL_WIDTH_20_40
;
745 case NL80211_CHAN_HT40PLUS
:
747 mac
->cur_40_prime_sc
=
748 PRIME_CHNL_OFFSET_LOWER
;
749 rtlphy
->current_chan_bw
=
750 HT_CHANNEL_WIDTH_20_40
;
761 pr_err("switch case %#x not processed\n",
770 /* In scanning, when before we offchannel we may send a ps=1
771 * null to AP, and then we may send a ps = 0 null to AP quickly,
772 * but first null may have caused AP to put lots of packet to
773 * hw tx buffer. These packets must be tx'd before we go off
774 * channel so we must delay more time to let AP flush these
775 * packets before going offchannel, or dis-association or
776 * delete BA will be caused by AP
778 if (rtlpriv
->mac80211
.offchan_delay
) {
779 rtlpriv
->mac80211
.offchan_delay
= false;
783 rtlphy
->current_channel
= wide_chan
;
785 rtlpriv
->cfg
->ops
->switch_channel(hw
);
786 rtlpriv
->cfg
->ops
->set_channel_access(hw
);
787 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, channel_type
);
790 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
795 static void rtl_op_configure_filter(struct ieee80211_hw
*hw
,
796 unsigned int changed_flags
,
797 unsigned int *new_flags
, u64 multicast
)
799 bool update_rcr
= false;
800 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
801 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
803 *new_flags
&= RTL_SUPPORTED_FILTERS
;
804 if (0 == changed_flags
)
807 /*TODO: we disable broadcase now, so enable here */
808 if (changed_flags
& FIF_ALLMULTI
) {
809 if (*new_flags
& FIF_ALLMULTI
) {
810 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
811 rtlpriv
->cfg
->maps
[MAC_RCR_AB
];
812 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
813 "Enable receive multicast frame\n");
815 mac
->rx_conf
&= ~(rtlpriv
->cfg
->maps
[MAC_RCR_AM
] |
816 rtlpriv
->cfg
->maps
[MAC_RCR_AB
]);
817 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
818 "Disable receive multicast frame\n");
823 if (changed_flags
& FIF_FCSFAIL
) {
824 if (*new_flags
& FIF_FCSFAIL
) {
825 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
826 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
827 "Enable receive FCS error frame\n");
829 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACRC32
];
830 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
831 "Disable receive FCS error frame\n");
837 /* if ssid not set to hw don't check bssid
838 * here just used for linked scanning, & linked
839 * and nolink check bssid is set in set network_type
841 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
&&
842 mac
->link_state
>= MAC80211_LINKED
) {
843 if (mac
->opmode
!= NL80211_IFTYPE_AP
&&
844 mac
->opmode
!= NL80211_IFTYPE_MESH_POINT
) {
845 if (*new_flags
& FIF_BCN_PRBRESP_PROMISC
)
846 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, false);
848 rtlpriv
->cfg
->ops
->set_chk_bssid(hw
, true);
854 if (changed_flags
& FIF_CONTROL
) {
855 if (*new_flags
& FIF_CONTROL
) {
856 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
858 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
859 "Enable receive control frame.\n");
861 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_ACF
];
862 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
863 "Disable receive control frame.\n");
869 if (changed_flags
& FIF_OTHER_BSS
) {
870 if (*new_flags
& FIF_OTHER_BSS
) {
871 mac
->rx_conf
|= rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
872 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
873 "Enable receive other BSS's frame.\n");
875 mac
->rx_conf
&= ~rtlpriv
->cfg
->maps
[MAC_RCR_AAP
];
876 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
877 "Disable receive other BSS's frame.\n");
884 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
885 (u8
*)(&mac
->rx_conf
));
888 static int rtl_op_sta_add(struct ieee80211_hw
*hw
,
889 struct ieee80211_vif
*vif
,
890 struct ieee80211_sta
*sta
)
892 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
893 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
894 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
895 struct rtl_sta_info
*sta_entry
;
898 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
899 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
900 list_add_tail(&sta_entry
->list
, &rtlpriv
->entry_list
);
901 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
902 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
903 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
904 if (sta
->supp_rates
[0] <= 0xf)
905 sta_entry
->wireless_mode
= WIRELESS_MODE_B
;
906 if (sta
->ht_cap
.ht_supported
)
907 sta_entry
->wireless_mode
= WIRELESS_MODE_N_24G
;
909 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
910 sta_entry
->wireless_mode
= WIRELESS_MODE_G
;
911 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
912 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
913 if (sta
->ht_cap
.ht_supported
)
914 sta_entry
->wireless_mode
= WIRELESS_MODE_N_5G
;
915 if (sta
->vht_cap
.vht_supported
)
916 sta_entry
->wireless_mode
= WIRELESS_MODE_AC_5G
;
918 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
919 sta_entry
->wireless_mode
= WIRELESS_MODE_A
;
921 /*disable cck rate for p2p*/
923 sta
->supp_rates
[0] &= 0xfffffff0;
925 memcpy(sta_entry
->mac_addr
, sta
->addr
, ETH_ALEN
);
926 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
927 "Add sta addr is %pM\n", sta
->addr
);
928 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0, true);
934 static int rtl_op_sta_remove(struct ieee80211_hw
*hw
,
935 struct ieee80211_vif
*vif
,
936 struct ieee80211_sta
*sta
)
938 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
939 struct rtl_sta_info
*sta_entry
;
942 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
943 "Remove sta addr is %pM\n", sta
->addr
);
944 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
945 sta_entry
->wireless_mode
= 0;
946 sta_entry
->ratr_index
= 0;
947 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
948 list_del(&sta_entry
->list
);
949 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
954 static int _rtl_get_hal_qnum(u16 queue
)
979 *for mac80211 VO = 0, VI = 1, BE = 2, BK = 3
980 *for rtl819x BE = 0, BK = 1, VI = 2, VO = 3
982 static int rtl_op_conf_tx(struct ieee80211_hw
*hw
,
983 struct ieee80211_vif
*vif
, u16 queue
,
984 const struct ieee80211_tx_queue_params
*param
)
986 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
987 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
990 if (queue
>= AC_MAX
) {
991 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
992 "queue number %d is incorrect!\n", queue
);
996 aci
= _rtl_get_hal_qnum(queue
);
997 mac
->ac
[aci
].aifs
= param
->aifs
;
998 mac
->ac
[aci
].cw_min
= cpu_to_le16(param
->cw_min
);
999 mac
->ac
[aci
].cw_max
= cpu_to_le16(param
->cw_max
);
1000 mac
->ac
[aci
].tx_op
= cpu_to_le16(param
->txop
);
1001 memcpy(&mac
->edca_param
[aci
], param
, sizeof(*param
));
1002 rtlpriv
->cfg
->ops
->set_qos(hw
, aci
);
1006 static void send_beacon_frame(struct ieee80211_hw
*hw
,
1007 struct ieee80211_vif
*vif
)
1009 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1010 struct sk_buff
*skb
= ieee80211_beacon_get(hw
, vif
);
1011 struct rtl_tcb_desc tcb_desc
;
1014 memset(&tcb_desc
, 0, sizeof(struct rtl_tcb_desc
));
1015 rtlpriv
->intf_ops
->adapter_tx(hw
, NULL
, skb
, &tcb_desc
);
1019 static void rtl_op_bss_info_changed(struct ieee80211_hw
*hw
,
1020 struct ieee80211_vif
*vif
,
1021 struct ieee80211_bss_conf
*bss_conf
,
1024 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1025 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1026 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1027 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1029 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1030 if (vif
->type
== NL80211_IFTYPE_ADHOC
||
1031 vif
->type
== NL80211_IFTYPE_AP
||
1032 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1033 if (changed
& BSS_CHANGED_BEACON
||
1034 (changed
& BSS_CHANGED_BEACON_ENABLED
&&
1035 bss_conf
->enable_beacon
)) {
1036 if (mac
->beacon_enabled
== 0) {
1037 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1038 "BSS_CHANGED_BEACON_ENABLED\n");
1040 /*start hw beacon interrupt. */
1041 /*rtlpriv->cfg->ops->set_bcn_reg(hw); */
1042 mac
->beacon_enabled
= 1;
1043 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
,
1045 [RTL_IBSS_INT_MASKS
], 0);
1047 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1048 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1049 send_beacon_frame(hw
, vif
);
1052 if ((changed
& BSS_CHANGED_BEACON_ENABLED
&&
1053 !bss_conf
->enable_beacon
)) {
1054 if (mac
->beacon_enabled
== 1) {
1055 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1056 "ADHOC DISABLE BEACON\n");
1058 mac
->beacon_enabled
= 0;
1059 rtlpriv
->cfg
->ops
->update_interrupt_mask(hw
, 0,
1061 [RTL_IBSS_INT_MASKS
]);
1064 if (changed
& BSS_CHANGED_BEACON_INT
) {
1065 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_TRACE
,
1066 "BSS_CHANGED_BEACON_INT\n");
1067 mac
->beacon_interval
= bss_conf
->beacon_int
;
1068 rtlpriv
->cfg
->ops
->set_bcn_intv(hw
);
1072 /*TODO: reference to enum ieee80211_bss_change */
1073 if (changed
& BSS_CHANGED_ASSOC
) {
1076 if (bss_conf
->assoc
) {
1077 struct ieee80211_sta
*sta
= NULL
;
1080 mstatus
= RT_MEDIA_CONNECT
;
1081 /* we should reset all sec info & cam
1082 * before set cam after linked, we should not
1083 * reset in disassoc, that will cause tkip->wep
1084 * fail because some flag will be wrong */
1085 /* reset sec info */
1086 rtl_cam_reset_sec_info(hw
);
1087 /* reset cam to fix wep fail issue
1088 * when change from wpa to wep */
1089 rtl_cam_reset_all_entry(hw
);
1091 mac
->link_state
= MAC80211_LINKED
;
1092 mac
->cnt_after_linked
= 0;
1093 mac
->assoc_id
= bss_conf
->aid
;
1094 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1096 if (rtlpriv
->cfg
->ops
->linked_set_reg
)
1097 rtlpriv
->cfg
->ops
->linked_set_reg(hw
);
1100 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1105 RT_TRACE(rtlpriv
, COMP_EASY_CONCURRENT
, DBG_LOUD
,
1106 "send PS STATIC frame\n");
1107 if (rtlpriv
->dm
.supp_phymode_switch
) {
1108 if (sta
->ht_cap
.ht_supported
)
1109 rtl_send_smps_action(hw
, sta
,
1110 IEEE80211_SMPS_STATIC
);
1113 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1114 mac
->mode
= WIRELESS_MODE_A
;
1116 if (sta
->supp_rates
[0] <= 0xf)
1117 mac
->mode
= WIRELESS_MODE_B
;
1119 mac
->mode
= WIRELESS_MODE_G
;
1122 if (sta
->ht_cap
.ht_supported
) {
1123 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1124 mac
->mode
= WIRELESS_MODE_N_24G
;
1126 mac
->mode
= WIRELESS_MODE_N_5G
;
1129 if (sta
->vht_cap
.vht_supported
) {
1130 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1131 mac
->mode
= WIRELESS_MODE_AC_5G
;
1133 mac
->mode
= WIRELESS_MODE_AC_24G
;
1136 if (vif
->type
== NL80211_IFTYPE_STATION
)
1137 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
, 0,
1141 /* to avoid AP Disassociation caused by inactivity */
1142 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1144 (u8
*)(&keep_alive
));
1146 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1147 "BSS_CHANGED_ASSOC\n");
1149 struct cfg80211_bss
*bss
= NULL
;
1151 mstatus
= RT_MEDIA_DISCONNECT
;
1153 if (mac
->link_state
== MAC80211_LINKED
)
1155 if (ppsc
->p2p_ps_info
.p2p_ps_mode
> P2P_PS_NONE
)
1156 rtl_p2p_ps_cmd(hw
, P2P_PS_DISABLE
);
1157 mac
->link_state
= MAC80211_NOLINK
;
1159 bss
= cfg80211_get_bss(hw
->wiphy
, NULL
,
1160 (u8
*)mac
->bssid
, NULL
, 0,
1161 IEEE80211_BSS_TYPE_ESS
,
1162 IEEE80211_PRIVACY_OFF
);
1164 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1165 "bssid = %pMF\n", mac
->bssid
);
1168 cfg80211_unlink_bss(hw
->wiphy
, bss
);
1169 cfg80211_put_bss(hw
->wiphy
, bss
);
1170 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1171 "cfg80211_unlink !!\n");
1174 eth_zero_addr(mac
->bssid
);
1175 mac
->vendor
= PEER_UNKNOWN
;
1178 if (rtlpriv
->dm
.supp_phymode_switch
) {
1179 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1180 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1182 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1183 "BSS_CHANGED_UN_ASSOC\n");
1185 rtlpriv
->cfg
->ops
->set_network_type(hw
, vif
->type
);
1187 * To tell firmware we have connected or disconnected
1189 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1190 HW_VAR_H2C_FW_JOINBSSRPT
,
1192 ppsc
->report_linked
= (mstatus
== RT_MEDIA_CONNECT
) ?
1195 if (rtlpriv
->cfg
->ops
->get_btc_status())
1196 rtlpriv
->btcoexist
.btc_ops
->btc_mediastatus_notify(
1200 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1201 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1202 "BSS_CHANGED_ERP_CTS_PROT\n");
1203 mac
->use_cts_protect
= bss_conf
->use_cts_prot
;
1206 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1207 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
,
1208 "BSS_CHANGED_ERP_PREAMBLE use short preamble:%x\n",
1209 bss_conf
->use_short_preamble
);
1211 mac
->short_preamble
= bss_conf
->use_short_preamble
;
1212 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ACK_PREAMBLE
,
1213 (u8
*)(&mac
->short_preamble
));
1216 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1217 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1218 "BSS_CHANGED_ERP_SLOT\n");
1220 if (bss_conf
->use_short_slot
)
1221 mac
->slot_time
= RTL_SLOT_TIME_9
;
1223 mac
->slot_time
= RTL_SLOT_TIME_20
;
1225 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
1226 (u8
*)(&mac
->slot_time
));
1229 if (changed
& BSS_CHANGED_HT
) {
1230 struct ieee80211_sta
*sta
= NULL
;
1232 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1233 "BSS_CHANGED_HT\n");
1236 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1238 if (sta
->ht_cap
.ampdu_density
>
1239 mac
->current_ampdu_density
)
1240 mac
->current_ampdu_density
=
1241 sta
->ht_cap
.ampdu_density
;
1242 if (sta
->ht_cap
.ampdu_factor
<
1243 mac
->current_ampdu_factor
)
1244 mac
->current_ampdu_factor
=
1245 sta
->ht_cap
.ampdu_factor
;
1249 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SHORTGI_DENSITY
,
1250 (u8
*)(&mac
->max_mss_density
));
1251 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_FACTOR
,
1252 &mac
->current_ampdu_factor
);
1253 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AMPDU_MIN_SPACE
,
1254 &mac
->current_ampdu_density
);
1257 if (changed
& BSS_CHANGED_BSSID
) {
1259 struct ieee80211_sta
*sta
= NULL
;
1261 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BSSID
,
1262 (u8
*)bss_conf
->bssid
);
1264 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_DMESG
,
1265 "bssid: %pM\n", bss_conf
->bssid
);
1267 mac
->vendor
= PEER_UNKNOWN
;
1268 memcpy(mac
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
1271 sta
= ieee80211_find_sta(vif
, (u8
*)bss_conf
->bssid
);
1277 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
1278 mac
->mode
= WIRELESS_MODE_A
;
1280 if (sta
->supp_rates
[0] <= 0xf)
1281 mac
->mode
= WIRELESS_MODE_B
;
1283 mac
->mode
= WIRELESS_MODE_G
;
1286 if (sta
->ht_cap
.ht_supported
) {
1287 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
)
1288 mac
->mode
= WIRELESS_MODE_N_24G
;
1290 mac
->mode
= WIRELESS_MODE_N_5G
;
1293 if (sta
->vht_cap
.vht_supported
) {
1294 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1295 mac
->mode
= WIRELESS_MODE_AC_5G
;
1297 mac
->mode
= WIRELESS_MODE_AC_24G
;
1300 /* just station need it, because ibss & ap mode will
1301 * set in sta_add, and will be NULL here */
1302 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1303 struct rtl_sta_info
*sta_entry
;
1305 sta_entry
= (struct rtl_sta_info
*)sta
->drv_priv
;
1306 sta_entry
->wireless_mode
= mac
->mode
;
1309 if (sta
->ht_cap
.ht_supported
) {
1310 mac
->ht_enable
= true;
1313 * for cisco 1252 bw20 it's wrong
1314 * if (ht_cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
1315 * mac->bw_40 = true;
1320 if (sta
->vht_cap
.vht_supported
)
1321 mac
->vht_enable
= true;
1323 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1324 /* for 5G must << RATE_6M_INDEX = 4,
1325 * because 5G have no cck rate*/
1326 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
1327 basic_rates
= sta
->supp_rates
[1] << 4;
1329 basic_rates
= sta
->supp_rates
[0];
1331 mac
->basic_rates
= basic_rates
;
1332 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_BASIC_RATE
,
1333 (u8
*)(&basic_rates
));
1338 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1341 static u64
rtl_op_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1343 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1346 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&tsf
));
1350 static void rtl_op_set_tsf(struct ieee80211_hw
*hw
,
1351 struct ieee80211_vif
*vif
, u64 tsf
)
1353 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1354 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1355 u8 bibss
= (mac
->opmode
== NL80211_IFTYPE_ADHOC
) ? 1 : 0;
1358 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_CORRECT_TSF
, (u8
*)(&bibss
));
1361 static void rtl_op_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1363 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1366 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_DUAL_TSF_RST
, (u8
*)(&tmp
));
1369 static void rtl_op_sta_notify(struct ieee80211_hw
*hw
,
1370 struct ieee80211_vif
*vif
,
1371 enum sta_notify_cmd cmd
,
1372 struct ieee80211_sta
*sta
)
1375 case STA_NOTIFY_SLEEP
:
1377 case STA_NOTIFY_AWAKE
:
1384 static int rtl_op_ampdu_action(struct ieee80211_hw
*hw
,
1385 struct ieee80211_vif
*vif
,
1386 struct ieee80211_ampdu_params
*params
)
1388 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1389 struct ieee80211_sta
*sta
= params
->sta
;
1390 enum ieee80211_ampdu_mlme_action action
= params
->action
;
1391 u16 tid
= params
->tid
;
1392 u16
*ssn
= ¶ms
->ssn
;
1395 case IEEE80211_AMPDU_TX_START
:
1396 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1397 "IEEE80211_AMPDU_TX_START: TID:%d\n", tid
);
1398 return rtl_tx_agg_start(hw
, vif
, sta
, tid
, ssn
);
1399 case IEEE80211_AMPDU_TX_STOP_CONT
:
1400 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1401 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1402 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1403 "IEEE80211_AMPDU_TX_STOP: TID:%d\n", tid
);
1404 return rtl_tx_agg_stop(hw
, vif
, sta
, tid
);
1405 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1406 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1407 "IEEE80211_AMPDU_TX_OPERATIONAL:TID:%d\n", tid
);
1408 rtl_tx_agg_oper(hw
, sta
, tid
);
1410 case IEEE80211_AMPDU_RX_START
:
1411 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1412 "IEEE80211_AMPDU_RX_START:TID:%d\n", tid
);
1413 return rtl_rx_agg_start(hw
, sta
, tid
);
1414 case IEEE80211_AMPDU_RX_STOP
:
1415 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_TRACE
,
1416 "IEEE80211_AMPDU_RX_STOP:TID:%d\n", tid
);
1417 return rtl_rx_agg_stop(hw
, sta
, tid
);
1419 pr_err("IEEE80211_AMPDU_ERR!!!!:\n");
1425 static void rtl_op_sw_scan_start(struct ieee80211_hw
*hw
,
1426 struct ieee80211_vif
*vif
,
1429 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1430 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1432 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1433 mac
->act_scanning
= true;
1434 if (rtlpriv
->link_info
.higher_busytraffic
) {
1435 mac
->skip_scan
= true;
1439 if (rtlpriv
->cfg
->ops
->get_btc_status())
1440 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 1);
1441 else if (rtlpriv
->btcoexist
.btc_ops
)
1442 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1445 if (rtlpriv
->dm
.supp_phymode_switch
) {
1446 if (rtlpriv
->cfg
->ops
->chk_switch_dmdp
)
1447 rtlpriv
->cfg
->ops
->chk_switch_dmdp(hw
);
1450 if (mac
->link_state
== MAC80211_LINKED
) {
1452 mac
->link_state
= MAC80211_LINKED_SCANNING
;
1458 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1460 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_SITE_SURVEY
);
1461 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_BACKUP_BAND0
);
1464 static void rtl_op_sw_scan_complete(struct ieee80211_hw
*hw
,
1465 struct ieee80211_vif
*vif
)
1467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1468 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1470 RT_TRACE(rtlpriv
, COMP_MAC80211
, DBG_LOUD
, "\n");
1471 mac
->act_scanning
= false;
1472 mac
->skip_scan
= false;
1474 rtlpriv
->btcoexist
.btc_info
.ap_num
= rtlpriv
->scan_list
.num
;
1476 if (rtlpriv
->link_info
.higher_busytraffic
)
1479 /* p2p will use 1/6/11 to scan */
1480 if (mac
->n_channels
== 3)
1481 mac
->p2p_in_use
= true;
1483 mac
->p2p_in_use
= false;
1484 mac
->n_channels
= 0;
1486 rtlpriv
->rtlhal
.load_imrandiqk_setting_for2g
= false;
1488 if (mac
->link_state
== MAC80211_LINKED_SCANNING
) {
1489 mac
->link_state
= MAC80211_LINKED
;
1490 if (mac
->opmode
== NL80211_IFTYPE_STATION
) {
1491 /* fix fwlps issue */
1492 rtlpriv
->cfg
->ops
->set_network_type(hw
, mac
->opmode
);
1496 rtlpriv
->cfg
->ops
->scan_operation_backup(hw
, SCAN_OPT_RESTORE
);
1497 if (rtlpriv
->cfg
->ops
->get_btc_status())
1498 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify(rtlpriv
, 0);
1499 else if (rtlpriv
->btcoexist
.btc_ops
)
1500 rtlpriv
->btcoexist
.btc_ops
->btc_scan_notify_wifi_only(rtlpriv
,
1504 static int rtl_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1505 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1506 struct ieee80211_key_conf
*key
)
1508 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1509 u8 key_type
= NO_ENCRYPTION
;
1511 bool group_key
= false;
1512 bool wep_only
= false;
1514 u8 mac_addr
[ETH_ALEN
];
1515 u8 bcast_addr
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1517 rtlpriv
->btcoexist
.btc_info
.in_4way
= false;
1519 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1520 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1521 "not open hw encryption\n");
1522 return -ENOSPC
; /*User disabled HW-crypto */
1524 /* To support IBSS, use sw-crypto for GTK */
1525 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1526 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1527 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1529 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1530 "%s hardware based encryption for keyidx: %d, mac: %pM\n",
1531 cmd
== SET_KEY
? "Using" : "Disabling", key
->keyidx
,
1532 sta
? sta
->addr
: bcast_addr
);
1533 rtlpriv
->sec
.being_setkey
= true;
1535 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1536 /* <1> get encryption alg */
1538 switch (key
->cipher
) {
1539 case WLAN_CIPHER_SUITE_WEP40
:
1540 key_type
= WEP40_ENCRYPTION
;
1541 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP40\n");
1543 case WLAN_CIPHER_SUITE_WEP104
:
1544 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:WEP104\n");
1545 key_type
= WEP104_ENCRYPTION
;
1547 case WLAN_CIPHER_SUITE_TKIP
:
1548 key_type
= TKIP_ENCRYPTION
;
1549 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:TKIP\n");
1551 case WLAN_CIPHER_SUITE_CCMP
:
1552 key_type
= AESCCMP_ENCRYPTION
;
1553 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CCMP\n");
1555 case WLAN_CIPHER_SUITE_AES_CMAC
:
1556 /* HW don't support CMAC encryption,
1557 * use software CMAC encryption
1559 key_type
= AESCMAC_ENCRYPTION
;
1560 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
, "alg:CMAC\n");
1561 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1562 "HW don't support CMAC encryption, use software CMAC encryption\n");
1566 pr_err("alg_err:%x!!!!:\n", key
->cipher
);
1569 if (key_type
== WEP40_ENCRYPTION
||
1570 key_type
== WEP104_ENCRYPTION
||
1571 vif
->type
== NL80211_IFTYPE_ADHOC
)
1572 rtlpriv
->sec
.use_defaultkey
= true;
1574 /* <2> get key_idx */
1575 key_idx
= (u8
) (key
->keyidx
);
1578 /* <3> if pairwise key enable_hw_sec */
1579 group_key
= !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1581 /* wep always be group key, but there are two conditions:
1582 * 1) wep only: is just for wep enc, in this condition
1583 * rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION
1584 * will be true & enable_hw_sec will be set when wep
1586 * 2) wep(group) + AES(pairwise): some AP like cisco
1587 * may use it, in this condition enable_hw_sec will not
1588 * be set when wep key setting */
1589 /* we must reset sec_info after lingked before set key,
1590 * or some flag will be wrong*/
1591 if (vif
->type
== NL80211_IFTYPE_AP
||
1592 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1593 if (!group_key
|| key_type
== WEP40_ENCRYPTION
||
1594 key_type
== WEP104_ENCRYPTION
) {
1597 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1600 if (!group_key
|| vif
->type
== NL80211_IFTYPE_ADHOC
||
1601 rtlpriv
->sec
.pairwise_enc_algorithm
== NO_ENCRYPTION
) {
1602 if (rtlpriv
->sec
.pairwise_enc_algorithm
==
1604 (key_type
== WEP40_ENCRYPTION
||
1605 key_type
== WEP104_ENCRYPTION
))
1607 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1608 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1609 "set enable_hw_sec, key_type:%x(OPEN:0 WEP40:1 TKIP:2 AES:4 WEP104:5)\n",
1611 rtlpriv
->cfg
->ops
->enable_hw_sec(hw
);
1614 /* <4> set key based on cmd */
1618 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1619 "set WEP(group/pairwise) key\n");
1620 /* Pairwise key with an assigned MAC address. */
1621 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1622 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1623 /*set local buf about wep key. */
1624 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1625 key
->key
, key
->keylen
);
1626 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1627 eth_zero_addr(mac_addr
);
1628 } else if (group_key
) { /* group key */
1629 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1632 rtlpriv
->sec
.group_enc_algorithm
= key_type
;
1633 /*set local buf about group key. */
1634 memcpy(rtlpriv
->sec
.key_buf
[key_idx
],
1635 key
->key
, key
->keylen
);
1636 rtlpriv
->sec
.key_len
[key_idx
] = key
->keylen
;
1637 memcpy(mac_addr
, bcast_addr
, ETH_ALEN
);
1638 } else { /* pairwise key */
1639 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1640 "set pairwise key\n");
1643 "rtlwifi: pairwise key without mac_addr\n");
1648 /* Pairwise key with an assigned MAC address. */
1649 rtlpriv
->sec
.pairwise_enc_algorithm
= key_type
;
1650 /*set local buf about pairwise key. */
1651 memcpy(rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
],
1652 key
->key
, key
->keylen
);
1653 rtlpriv
->sec
.key_len
[PAIRWISE_KEYIDX
] = key
->keylen
;
1654 rtlpriv
->sec
.pairwise_key
=
1655 rtlpriv
->sec
.key_buf
[PAIRWISE_KEYIDX
];
1656 memcpy(mac_addr
, sta
->addr
, ETH_ALEN
);
1658 rtlpriv
->cfg
->ops
->set_key(hw
, key_idx
, mac_addr
,
1659 group_key
, key_type
, wep_only
,
1661 /* <5> tell mac80211 do something: */
1662 /*must use sw generate IV, or can not work !!!!. */
1663 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1664 key
->hw_key_idx
= key_idx
;
1665 if (key_type
== TKIP_ENCRYPTION
)
1666 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1667 /*use software CCMP encryption for management frames (MFP) */
1668 if (key_type
== AESCCMP_ENCRYPTION
)
1669 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1672 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1673 "disable key delete one entry\n");
1674 /*set local buf about wep key. */
1675 if (vif
->type
== NL80211_IFTYPE_AP
||
1676 vif
->type
== NL80211_IFTYPE_MESH_POINT
) {
1678 rtl_cam_del_entry(hw
, sta
->addr
);
1680 memset(rtlpriv
->sec
.key_buf
[key_idx
], 0, key
->keylen
);
1681 rtlpriv
->sec
.key_len
[key_idx
] = 0;
1682 eth_zero_addr(mac_addr
);
1684 *mac80211 will delete entrys one by one,
1685 *so don't use rtl_cam_reset_all_entry
1686 *or clear all entry here.
1688 rtl_wait_tx_report_acked(hw
, 500); /* wait 500ms for TX ack */
1690 rtl_cam_delete_one_entry(hw
, mac_addr
, key_idx
);
1693 pr_err("cmd_err:%x!!!!:\n", cmd
);
1696 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1697 rtlpriv
->sec
.being_setkey
= false;
1701 static void rtl_op_rfkill_poll(struct ieee80211_hw
*hw
)
1703 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1709 if (!test_bit(RTL_STATUS_INTERFACE_START
, &rtlpriv
->status
))
1712 mutex_lock(&rtlpriv
->locks
.conf_mutex
);
1714 /*if Radio On return true here */
1715 radio_state
= rtlpriv
->cfg
->ops
->radio_onoff_checking(hw
, &valid
);
1718 if (unlikely(radio_state
!= rtlpriv
->rfkill
.rfkill_state
)) {
1719 rtlpriv
->rfkill
.rfkill_state
= radio_state
;
1721 RT_TRACE(rtlpriv
, COMP_RF
, DBG_DMESG
,
1722 "wireless radio switch turned %s\n",
1723 radio_state
? "on" : "off");
1725 blocked
= (rtlpriv
->rfkill
.rfkill_state
== 1) ? 0 : 1;
1726 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1730 mutex_unlock(&rtlpriv
->locks
.conf_mutex
);
1733 /* this function is called by mac80211 to flush tx buffer
1734 * before switch channle or power save, or tx buffer packet
1735 * maybe send after offchannel or rf sleep, this may cause
1736 * dis-association by AP */
1737 static void rtl_op_flush(struct ieee80211_hw
*hw
,
1738 struct ieee80211_vif
*vif
,
1742 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1744 if (rtlpriv
->intf_ops
->flush
)
1745 rtlpriv
->intf_ops
->flush(hw
, queues
, drop
);
1749 * This routine deals with the Power Configuration CMD
1750 * parsing for RTL8723/RTL8188E Series IC.
1752 * We should follow specific format that was released from HW SD.
1754 bool rtl_hal_pwrseqcmdparsing(struct rtl_priv
*rtlpriv
, u8 cut_version
,
1755 u8 faversion
, u8 interface_type
,
1756 struct wlan_pwr_cfg pwrcfgcmd
[])
1758 struct wlan_pwr_cfg cfg_cmd
;
1759 bool polling_bit
= false;
1763 u32 polling_count
= 0;
1764 u32 max_polling_cnt
= 5000;
1767 cfg_cmd
= pwrcfgcmd
[ary_idx
];
1768 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1769 "rtl_hal_pwrseqcmdparsing(): offset(%#x),cut_msk(%#x), famsk(%#x), interface_msk(%#x), base(%#x), cmd(%#x), msk(%#x), value(%#x)\n",
1770 GET_PWR_CFG_OFFSET(cfg_cmd
),
1771 GET_PWR_CFG_CUT_MASK(cfg_cmd
),
1772 GET_PWR_CFG_FAB_MASK(cfg_cmd
),
1773 GET_PWR_CFG_INTF_MASK(cfg_cmd
),
1774 GET_PWR_CFG_BASE(cfg_cmd
), GET_PWR_CFG_CMD(cfg_cmd
),
1775 GET_PWR_CFG_MASK(cfg_cmd
), GET_PWR_CFG_VALUE(cfg_cmd
));
1777 if ((GET_PWR_CFG_FAB_MASK(cfg_cmd
)&faversion
) &&
1778 (GET_PWR_CFG_CUT_MASK(cfg_cmd
)&cut_version
) &&
1779 (GET_PWR_CFG_INTF_MASK(cfg_cmd
)&interface_type
)) {
1780 switch (GET_PWR_CFG_CMD(cfg_cmd
)) {
1782 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1783 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_READ\n");
1786 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1787 "%s(): PWR_CMD_WRITE\n", __func__
);
1788 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1790 /*Read the value from system register*/
1791 value
= rtl_read_byte(rtlpriv
, offset
);
1792 value
&= (~(GET_PWR_CFG_MASK(cfg_cmd
)));
1793 value
|= (GET_PWR_CFG_VALUE(cfg_cmd
) &
1794 GET_PWR_CFG_MASK(cfg_cmd
));
1796 /*Write the value back to sytem register*/
1797 rtl_write_byte(rtlpriv
, offset
, value
);
1799 case PWR_CMD_POLLING
:
1800 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1801 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_POLLING\n");
1802 polling_bit
= false;
1803 offset
= GET_PWR_CFG_OFFSET(cfg_cmd
);
1806 value
= rtl_read_byte(rtlpriv
, offset
);
1808 value
&= GET_PWR_CFG_MASK(cfg_cmd
);
1810 (GET_PWR_CFG_VALUE(cfg_cmd
) &
1811 GET_PWR_CFG_MASK(cfg_cmd
)))
1816 if (polling_count
++ > max_polling_cnt
)
1818 } while (!polling_bit
);
1821 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1822 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_DELAY\n");
1823 if (GET_PWR_CFG_VALUE(cfg_cmd
) ==
1825 udelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1827 mdelay(GET_PWR_CFG_OFFSET(cfg_cmd
));
1830 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1831 "rtl_hal_pwrseqcmdparsing(): PWR_CMD_END\n");
1835 "rtlwifi: rtl_hal_pwrseqcmdparsing(): Unknown CMD!!\n");
1844 EXPORT_SYMBOL(rtl_hal_pwrseqcmdparsing
);
1846 bool rtl_cmd_send_packet(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1848 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1849 struct rtl_pci
*rtlpci
= rtl_pcidev(rtl_pcipriv(hw
));
1850 struct rtl8192_tx_ring
*ring
;
1851 struct rtl_tx_desc
*pdesc
;
1852 unsigned long flags
;
1853 struct sk_buff
*pskb
= NULL
;
1855 ring
= &rtlpci
->tx_ring
[BEACON_QUEUE
];
1857 spin_lock_irqsave(&rtlpriv
->locks
.irq_th_lock
, flags
);
1858 pskb
= __skb_dequeue(&ring
->queue
);
1860 dev_kfree_skb_irq(pskb
);
1862 /*this is wrong, fill_tx_cmddesc needs update*/
1863 pdesc
= &ring
->desc
[0];
1865 rtlpriv
->cfg
->ops
->fill_tx_cmddesc(hw
, (u8
*)pdesc
, 1, 1, skb
);
1867 __skb_queue_tail(&ring
->queue
, skb
);
1869 spin_unlock_irqrestore(&rtlpriv
->locks
.irq_th_lock
, flags
);
1871 rtlpriv
->cfg
->ops
->tx_polling(hw
, BEACON_QUEUE
);
1875 EXPORT_SYMBOL(rtl_cmd_send_packet
);
1876 const struct ieee80211_ops rtl_ops
= {
1877 .start
= rtl_op_start
,
1878 .stop
= rtl_op_stop
,
1880 .add_interface
= rtl_op_add_interface
,
1881 .remove_interface
= rtl_op_remove_interface
,
1882 .change_interface
= rtl_op_change_interface
,
1884 .suspend
= rtl_op_suspend
,
1885 .resume
= rtl_op_resume
,
1887 .config
= rtl_op_config
,
1888 .configure_filter
= rtl_op_configure_filter
,
1889 .set_key
= rtl_op_set_key
,
1890 .conf_tx
= rtl_op_conf_tx
,
1891 .bss_info_changed
= rtl_op_bss_info_changed
,
1892 .get_tsf
= rtl_op_get_tsf
,
1893 .set_tsf
= rtl_op_set_tsf
,
1894 .reset_tsf
= rtl_op_reset_tsf
,
1895 .sta_notify
= rtl_op_sta_notify
,
1896 .ampdu_action
= rtl_op_ampdu_action
,
1897 .sw_scan_start
= rtl_op_sw_scan_start
,
1898 .sw_scan_complete
= rtl_op_sw_scan_complete
,
1899 .rfkill_poll
= rtl_op_rfkill_poll
,
1900 .sta_add
= rtl_op_sta_add
,
1901 .sta_remove
= rtl_op_sta_remove
,
1902 .flush
= rtl_op_flush
,
1904 EXPORT_SYMBOL_GPL(rtl_ops
);
1906 bool rtl_btc_status_false(void)
1910 EXPORT_SYMBOL_GPL(rtl_btc_status_false
);
1912 void rtl_dm_diginit(struct ieee80211_hw
*hw
, u32 cur_igvalue
)
1914 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1915 struct dig_t
*dm_digtable
= &rtlpriv
->dm_digtable
;
1917 dm_digtable
->dig_enable_flag
= true;
1918 dm_digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
1919 dm_digtable
->cur_igvalue
= cur_igvalue
;
1920 dm_digtable
->pre_igvalue
= 0;
1921 dm_digtable
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
1922 dm_digtable
->presta_cstate
= DIG_STA_DISCONNECT
;
1923 dm_digtable
->curmultista_cstate
= DIG_MULTISTA_DISCONNECT
;
1924 dm_digtable
->rssi_lowthresh
= DM_DIG_THRESH_LOW
;
1925 dm_digtable
->rssi_highthresh
= DM_DIG_THRESH_HIGH
;
1926 dm_digtable
->fa_lowthresh
= DM_FALSEALARM_THRESH_LOW
;
1927 dm_digtable
->fa_highthresh
= DM_FALSEALARM_THRESH_HIGH
;
1928 dm_digtable
->rx_gain_max
= DM_DIG_MAX
;
1929 dm_digtable
->rx_gain_min
= DM_DIG_MIN
;
1930 dm_digtable
->back_val
= DM_DIG_BACKOFF_DEFAULT
;
1931 dm_digtable
->back_range_max
= DM_DIG_BACKOFF_MAX
;
1932 dm_digtable
->back_range_min
= DM_DIG_BACKOFF_MIN
;
1933 dm_digtable
->pre_cck_cca_thres
= 0xff;
1934 dm_digtable
->cur_cck_cca_thres
= 0x83;
1935 dm_digtable
->forbidden_igi
= DM_DIG_MIN
;
1936 dm_digtable
->large_fa_hit
= 0;
1937 dm_digtable
->recover_cnt
= 0;
1938 dm_digtable
->dig_min_0
= 0x25;
1939 dm_digtable
->dig_min_1
= 0x25;
1940 dm_digtable
->media_connect_0
= false;
1941 dm_digtable
->media_connect_1
= false;
1942 rtlpriv
->dm
.dm_initialgain_enable
= true;
1943 dm_digtable
->bt30_cur_igi
= 0x32;
1944 dm_digtable
->pre_cck_pd_state
= CCK_PD_STAGE_MAX
;
1945 dm_digtable
->cur_cck_pd_state
= CCK_PD_STAGE_LOWRSSI
;
1946 dm_digtable
->pre_cck_fa_state
= 0;
1947 dm_digtable
->cur_cck_fa_state
= 0;
1949 EXPORT_SYMBOL(rtl_dm_diginit
);