1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
5 * Based on the r8180 driver, which is:
6 * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
8 * Contact Information: wlanfae <wlanfae@realtek.com>
10 #include <linux/uaccess.h>
11 #include <linux/pci.h>
12 #include <linux/vmalloc.h>
13 #include <linux/ieee80211.h>
15 #include "r8192E_phy.h"
16 #include "r8192E_phyreg.h"
17 #include "r8190P_rtl8256.h"
18 #include "r8192E_cmdpkt.h"
26 static char *ifname = "wlan%d";
28 static const struct rtl819x_ops rtl819xp_ops = {
29 .nic_type = NIC_8192E,
30 .initialize_adapter = rtl92e_start_adapter,
31 .link_change = rtl92e_link_change,
32 .tx_fill_descriptor = rtl92e_fill_tx_desc,
33 .tx_fill_cmd_descriptor = rtl92e_fill_tx_cmd_desc,
34 .rx_query_status_descriptor = rtl92e_get_rx_stats,
35 .rx_command_packet_handler = NULL,
36 .stop_adapter = rtl92e_stop_adapter,
37 .update_ratr_table = rtl92e_update_ratr_table,
38 .irq_enable = rtl92e_enable_irq,
39 .irq_disable = rtl92e_disable_irq,
40 .irq_clear = rtl92e_clear_irq,
41 .rx_enable = rtl92e_enable_rx,
42 .tx_enable = rtl92e_enable_tx,
43 .interrupt_recognized = rtl92e_ack_irq,
44 .tx_check_stuck_handler = rtl92e_is_tx_stuck,
45 .rx_check_stuck_handler = rtl92e_is_rx_stuck,
48 static struct pci_device_id rtl8192_pci_id_tbl[] = {
49 {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)},
50 {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)},
51 {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)},
55 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
57 static int _rtl92e_pci_probe(struct pci_dev *pdev,
58 const struct pci_device_id *id);
59 static void _rtl92e_pci_disconnect(struct pci_dev *pdev);
60 static irqreturn_t _rtl92e_irq(int irq, void *netdev);
62 static SIMPLE_DEV_PM_OPS(rtl92e_pm_ops, rtl92e_suspend, rtl92e_resume);
64 static struct pci_driver rtl8192_pci_driver = {
65 .name = DRV_NAME, /* Driver name */
66 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
67 .probe = _rtl92e_pci_probe, /* probe fn */
68 .remove = _rtl92e_pci_disconnect, /* remove fn */
69 .driver.pm = &rtl92e_pm_ops,
72 static short _rtl92e_is_tx_queue_empty(struct net_device *dev);
73 static void _rtl92e_watchdog_wq_cb(void *data);
74 static void _rtl92e_watchdog_timer_cb(struct timer_list *t);
75 static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
77 static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
78 static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb);
79 static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb);
80 static short _rtl92e_pci_initdescring(struct net_device *dev);
81 static void _rtl92e_irq_tx_tasklet(struct tasklet_struct *t);
82 static void _rtl92e_irq_rx_tasklet(struct tasklet_struct *t);
83 static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv);
84 static int _rtl92e_up(struct net_device *dev, bool is_silent_reset);
85 static int _rtl92e_try_up(struct net_device *dev);
86 static int _rtl92e_down(struct net_device *dev, bool shutdownrf);
87 static void _rtl92e_restart(void *data);
89 /****************************************************************************
90 * -----------------------------IO STUFF-------------------------
91 ****************************************************************************/
93 u8 rtl92e_readb(struct net_device *dev, int x)
95 return 0xff & readb((u8 __iomem *)dev->mem_start + x);
98 u32 rtl92e_readl(struct net_device *dev, int x)
100 return readl((u8 __iomem *)dev->mem_start + x);
103 u16 rtl92e_readw(struct net_device *dev, int x)
105 return readw((u8 __iomem *)dev->mem_start + x);
108 void rtl92e_writeb(struct net_device *dev, int x, u8 y)
110 writeb(y, (u8 __iomem *)dev->mem_start + x);
115 void rtl92e_writel(struct net_device *dev, int x, u32 y)
117 writel(y, (u8 __iomem *)dev->mem_start + x);
122 void rtl92e_writew(struct net_device *dev, int x, u16 y)
124 writew(y, (u8 __iomem *)dev->mem_start + x);
129 /****************************************************************************
130 * -----------------------------GENERAL FUNCTION-------------------------
131 ****************************************************************************/
132 bool rtl92e_set_rf_state(struct net_device *dev,
133 enum rt_rf_power_state state_to_set,
134 RT_RF_CHANGE_SOURCE change_source)
136 struct r8192_priv *priv = rtllib_priv(dev);
137 struct rtllib_device *ieee = priv->rtllib;
138 bool action_allowed = false;
139 bool connect_by_ssid = false;
140 enum rt_rf_power_state rt_state;
141 u16 rf_wait_counter = 0;
145 spin_lock_irqsave(&priv->rf_ps_lock, flag);
146 if (priv->rf_change_in_progress) {
147 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
149 while (priv->rf_change_in_progress) {
153 if (rf_wait_counter > 100) {
155 "%s(): Timeout waiting for RF change.\n",
161 priv->rf_change_in_progress = true;
162 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
167 rt_state = priv->rtllib->rf_power_state;
169 switch (state_to_set) {
171 priv->rtllib->rf_off_reason &= (~change_source);
173 if ((change_source == RF_CHANGE_BY_HW) && priv->hw_radio_off)
174 priv->hw_radio_off = false;
176 if (!priv->rtllib->rf_off_reason) {
177 priv->rtllib->rf_off_reason = 0;
178 action_allowed = true;
180 if (rt_state == rf_off &&
181 change_source >= RF_CHANGE_BY_HW)
182 connect_by_ssid = true;
188 if ((priv->rtllib->iw_mode == IW_MODE_INFRA) ||
189 (priv->rtllib->iw_mode == IW_MODE_ADHOC)) {
190 if ((priv->rtllib->rf_off_reason > RF_CHANGE_BY_IPS) ||
191 (change_source > RF_CHANGE_BY_IPS)) {
192 if (ieee->state == RTLLIB_LINKED)
193 priv->blinked_ingpio = true;
195 priv->blinked_ingpio = false;
196 rtllib_MgntDisconnect(priv->rtllib,
197 WLAN_REASON_DISASSOC_STA_HAS_LEFT);
200 if ((change_source == RF_CHANGE_BY_HW) && !priv->hw_radio_off)
201 priv->hw_radio_off = true;
202 priv->rtllib->rf_off_reason |= change_source;
203 action_allowed = true;
207 priv->rtllib->rf_off_reason |= change_source;
208 action_allowed = true;
215 if (action_allowed) {
216 rtl92e_set_rf_power_state(dev, state_to_set);
217 if (state_to_set == rf_on) {
218 if (connect_by_ssid && priv->blinked_ingpio) {
219 schedule_delayed_work(
220 &ieee->associate_procedure_wq, 0);
221 priv->blinked_ingpio = false;
226 spin_lock_irqsave(&priv->rf_ps_lock, flag);
227 priv->rf_change_in_progress = false;
228 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
229 return action_allowed;
232 static short _rtl92e_check_nic_enough_desc(struct net_device *dev, int prio)
234 struct r8192_priv *priv = rtllib_priv(dev);
235 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
237 if (ring->entries - skb_queue_len(&ring->queue) >= 2)
242 static void _rtl92e_tx_timeout(struct net_device *dev, unsigned int txqueue)
244 struct r8192_priv *priv = rtllib_priv(dev);
246 schedule_work(&priv->reset_wq);
247 netdev_info(dev, "TXTIMEOUT");
250 void rtl92e_irq_enable(struct net_device *dev)
252 struct r8192_priv *priv = rtllib_priv(dev);
254 priv->irq_enabled = 1;
256 priv->ops->irq_enable(dev);
259 void rtl92e_irq_disable(struct net_device *dev)
261 struct r8192_priv *priv = rtllib_priv(dev);
263 priv->ops->irq_disable(dev);
265 priv->irq_enabled = 0;
268 static void _rtl92e_set_chan(struct net_device *dev, short ch)
270 struct r8192_priv *priv = rtllib_priv(dev);
272 if (priv->chan_forced)
277 if (priv->rf_set_chan)
278 priv->rf_set_chan(dev, priv->chan);
281 static void _rtl92e_update_cap(struct net_device *dev, u16 cap)
283 struct r8192_priv *priv = rtllib_priv(dev);
284 struct rtllib_network *net = &priv->rtllib->current_network;
287 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) {
288 if (priv->dot11_current_preamble_mode != PREAMBLE_SHORT) {
289 ShortPreamble = true;
290 priv->dot11_current_preamble_mode = PREAMBLE_SHORT;
291 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
292 (unsigned char *)&ShortPreamble);
295 if (priv->dot11_current_preamble_mode != PREAMBLE_LONG) {
296 ShortPreamble = false;
297 priv->dot11_current_preamble_mode = PREAMBLE_LONG;
298 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
299 (unsigned char *)&ShortPreamble);
303 if (net->mode & (IEEE_G | IEEE_N_24G)) {
305 u8 cur_slot_time = priv->slot_time;
307 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
308 (!priv->rtllib->ht_info->current_rt2rt_long_slot_time)) {
309 if (cur_slot_time != SHORT_SLOT_TIME) {
310 slot_time_val = SHORT_SLOT_TIME;
311 priv->rtllib->SetHwRegHandler(dev,
312 HW_VAR_SLOT_TIME, &slot_time_val);
315 if (cur_slot_time != NON_SHORT_SLOT_TIME) {
316 slot_time_val = NON_SHORT_SLOT_TIME;
317 priv->rtllib->SetHwRegHandler(dev,
318 HW_VAR_SLOT_TIME, &slot_time_val);
324 static const struct rtllib_qos_parameters def_qos_parameters = {
325 {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)},
326 {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)},
332 static void _rtl92e_update_beacon(void *data)
334 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
335 update_beacon_wq.work);
336 struct net_device *dev = priv->rtllib->dev;
337 struct rtllib_device *ieee = priv->rtllib;
338 struct rtllib_network *net = &ieee->current_network;
340 if (ieee->ht_info->bCurrentHTSupport)
341 HT_update_self_and_peer_setting(ieee, net);
342 ieee->ht_info->current_rt2rt_long_slot_time = net->bssht.bd_rt2rt_long_slot_time;
343 ieee->ht_info->RT2RT_HT_Mode = net->bssht.rt2rt_ht_mode;
344 _rtl92e_update_cap(dev, net->capability);
347 static void _rtl92e_qos_activate(void *data)
349 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
351 struct net_device *dev = priv->rtllib->dev;
354 mutex_lock(&priv->mutex);
355 if (priv->rtllib->state != RTLLIB_LINKED)
358 for (i = 0; i < QOS_QUEUE_NUM; i++)
359 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i));
362 mutex_unlock(&priv->mutex);
365 static int _rtl92e_qos_handle_probe_response(struct r8192_priv *priv,
367 struct rtllib_network *network)
370 u32 size = sizeof(struct rtllib_qos_parameters);
372 if (priv->rtllib->state != RTLLIB_LINKED)
375 if (priv->rtllib->iw_mode != IW_MODE_INFRA)
378 if (network->flags & NETWORK_HAS_QOS_MASK) {
379 if (active_network &&
380 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
381 network->qos_data.active = network->qos_data.supported;
383 if ((network->qos_data.active == 1) && (active_network == 1) &&
384 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
385 (network->qos_data.old_param_count !=
386 network->qos_data.param_count)) {
387 network->qos_data.old_param_count =
388 network->qos_data.param_count;
389 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
390 schedule_work(&priv->qos_activate);
393 memcpy(&priv->rtllib->current_network.qos_data.parameters,
394 &def_qos_parameters, size);
396 if ((network->qos_data.active == 1) && (active_network == 1))
397 schedule_work(&priv->qos_activate);
399 network->qos_data.active = 0;
400 network->qos_data.supported = 0;
406 static int _rtl92e_handle_beacon(struct net_device *dev,
407 struct rtllib_beacon *beacon,
408 struct rtllib_network *network)
410 struct r8192_priv *priv = rtllib_priv(dev);
412 _rtl92e_qos_handle_probe_response(priv, 1, network);
414 schedule_delayed_work(&priv->update_beacon_wq, 0);
418 static int _rtl92e_qos_assoc_resp(struct r8192_priv *priv,
419 struct rtllib_network *network)
422 u32 size = sizeof(struct rtllib_qos_parameters);
423 int set_qos_param = 0;
425 if (!priv || !network)
428 if (priv->rtllib->state != RTLLIB_LINKED)
431 if (priv->rtllib->iw_mode != IW_MODE_INFRA)
434 spin_lock_irqsave(&priv->rtllib->lock, flags);
435 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
436 memcpy(&priv->rtllib->current_network.qos_data.parameters,
437 &network->qos_data.parameters,
438 sizeof(struct rtllib_qos_parameters));
439 priv->rtllib->current_network.qos_data.active = 1;
440 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
442 priv->rtllib->current_network.qos_data.old_param_count =
443 priv->rtllib->current_network.qos_data.param_count;
444 priv->rtllib->current_network.qos_data.param_count =
445 network->qos_data.param_count;
447 memcpy(&priv->rtllib->current_network.qos_data.parameters,
448 &def_qos_parameters, size);
449 priv->rtllib->current_network.qos_data.active = 0;
450 priv->rtllib->current_network.qos_data.supported = 0;
454 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
456 if (set_qos_param == 1) {
457 rtl92e_dm_init_edca_turbo(priv->rtllib->dev);
458 schedule_work(&priv->qos_activate);
463 static int _rtl92e_handle_assoc_response(struct net_device *dev,
464 struct rtllib_assoc_response_frame *resp,
465 struct rtllib_network *network)
467 struct r8192_priv *priv = rtllib_priv(dev);
469 _rtl92e_qos_assoc_resp(priv, network);
473 static void _rtl92e_prepare_beacon(struct tasklet_struct *t)
475 struct r8192_priv *priv = from_tasklet(priv, t,
476 irq_prepare_beacon_tasklet);
477 struct net_device *dev = priv->rtllib->dev;
478 struct sk_buff *pskb = NULL, *pnewskb = NULL;
479 struct cb_desc *tcb_desc = NULL;
480 struct rtl8192_tx_ring *ring = NULL;
481 struct tx_desc *pdesc = NULL;
483 ring = &priv->tx_ring[BEACON_QUEUE];
484 pskb = __skb_dequeue(&ring->queue);
487 pnewskb = rtllib_get_beacon(priv->rtllib);
491 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
492 tcb_desc->queue_index = BEACON_QUEUE;
493 tcb_desc->data_rate = 2;
494 tcb_desc->RATRIndex = 7;
495 tcb_desc->tx_dis_rate_fallback = 1;
496 tcb_desc->tx_use_drv_assinged_rate = 1;
497 skb_push(pnewskb, priv->rtllib->tx_headroom);
499 pdesc = &ring->desc[0];
500 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
501 __skb_queue_tail(&ring->queue, pnewskb);
505 static void _rtl92e_stop_beacon(struct net_device *dev)
509 void rtl92e_config_rate(struct net_device *dev, u16 *rate_config)
511 struct r8192_priv *priv = rtllib_priv(dev);
512 struct rtllib_network *net;
513 u8 i = 0, basic_rate = 0;
515 net = &priv->rtllib->current_network;
517 for (i = 0; i < net->rates_len; i++) {
518 basic_rate = net->rates[i] & 0x7f;
519 switch (basic_rate) {
521 *rate_config |= RRSR_1M;
524 *rate_config |= RRSR_2M;
527 *rate_config |= RRSR_5_5M;
530 *rate_config |= RRSR_11M;
533 *rate_config |= RRSR_6M;
536 *rate_config |= RRSR_9M;
539 *rate_config |= RRSR_12M;
542 *rate_config |= RRSR_18M;
545 *rate_config |= RRSR_24M;
548 *rate_config |= RRSR_36M;
551 *rate_config |= RRSR_48M;
554 *rate_config |= RRSR_54M;
559 for (i = 0; i < net->rates_ex_len; i++) {
560 basic_rate = net->rates_ex[i] & 0x7f;
561 switch (basic_rate) {
563 *rate_config |= RRSR_1M;
566 *rate_config |= RRSR_2M;
569 *rate_config |= RRSR_5_5M;
572 *rate_config |= RRSR_11M;
575 *rate_config |= RRSR_6M;
578 *rate_config |= RRSR_9M;
581 *rate_config |= RRSR_12M;
584 *rate_config |= RRSR_18M;
587 *rate_config |= RRSR_24M;
590 *rate_config |= RRSR_36M;
593 *rate_config |= RRSR_48M;
596 *rate_config |= RRSR_54M;
602 static void _rtl92e_refresh_support_rate(struct r8192_priv *priv)
604 struct rtllib_device *ieee = priv->rtllib;
606 if (ieee->mode == WIRELESS_MODE_N_24G ||
607 ieee->mode == WIRELESS_MODE_N_5G) {
608 memcpy(ieee->reg_dot11ht_oper_rate_set,
609 ieee->reg_ht_supp_rate_set, 16);
610 memcpy(ieee->reg_dot11tx_ht_oper_rate_set,
611 ieee->reg_ht_supp_rate_set, 16);
614 memset(ieee->reg_dot11ht_oper_rate_set, 0, 16);
618 static u8 _rtl92e_get_supported_wireless_mode(struct net_device *dev)
620 struct r8192_priv *priv = rtllib_priv(dev);
623 switch (priv->rf_chip) {
628 ret = (WIRELESS_MODE_N_24G | WIRELESS_MODE_G | WIRELESS_MODE_B);
631 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
634 ret = WIRELESS_MODE_B;
640 void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode)
642 struct r8192_priv *priv = rtllib_priv(dev);
643 u8 support_mode = _rtl92e_get_supported_wireless_mode(dev);
645 if ((wireless_mode == WIRELESS_MODE_AUTO) ||
646 ((wireless_mode & support_mode) == 0)) {
647 if (support_mode & WIRELESS_MODE_N_24G) {
648 wireless_mode = WIRELESS_MODE_N_24G;
649 } else if (support_mode & WIRELESS_MODE_N_5G) {
650 wireless_mode = WIRELESS_MODE_N_5G;
651 } else if ((support_mode & WIRELESS_MODE_A)) {
652 wireless_mode = WIRELESS_MODE_A;
653 } else if ((support_mode & WIRELESS_MODE_G)) {
654 wireless_mode = WIRELESS_MODE_G;
655 } else if ((support_mode & WIRELESS_MODE_B)) {
656 wireless_mode = WIRELESS_MODE_B;
659 "%s(): Unsupported mode requested. Fallback to 802.11b\n",
661 wireless_mode = WIRELESS_MODE_B;
665 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) ==
666 (WIRELESS_MODE_G | WIRELESS_MODE_B))
667 wireless_mode = WIRELESS_MODE_G;
669 priv->rtllib->mode = wireless_mode;
671 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
672 (wireless_mode == WIRELESS_MODE_N_5G)) {
673 priv->rtllib->ht_info->enable_ht = 1;
675 priv->rtllib->ht_info->enable_ht = 0;
677 _rtl92e_refresh_support_rate(priv);
680 static int _rtl92e_sta_up(struct net_device *dev, bool is_silent_reset)
682 struct r8192_priv *priv = rtllib_priv(dev);
683 struct rt_pwr_save_ctrl *psc = (struct rt_pwr_save_ctrl *)
684 (&priv->rtllib->pwr_save_ctrl);
687 priv->bdisable_nic = false;
690 priv->rtllib->ieee_up = 1;
692 priv->up_first_time = 0;
693 init_status = priv->ops->initialize_adapter(dev);
695 netdev_err(dev, "%s(): Initialization failed!\n", __func__);
699 RT_CLEAR_PS_LEVEL(psc, RT_RF_OFF_LEVL_HALT_NIC);
701 if (priv->polling_timer_on == 0)
702 rtl92e_check_rfctrl_gpio_timer(&priv->gpio_polling_timer);
704 if (priv->rtllib->state != RTLLIB_LINKED)
705 rtllib_softmac_start_protocol(priv->rtllib, 0);
706 rtllib_reset_queue(priv->rtllib);
707 _rtl92e_watchdog_timer_cb(&priv->watch_dog_timer);
709 if (!netif_queue_stopped(dev))
710 netif_start_queue(dev);
712 netif_wake_queue(dev);
717 static int _rtl92e_sta_down(struct net_device *dev, bool shutdownrf)
719 struct r8192_priv *priv = rtllib_priv(dev);
720 unsigned long flags = 0;
721 u8 rf_in_progress_timeout = 0;
726 if (priv->rtllib->rtllib_ips_leave)
727 priv->rtllib->rtllib_ips_leave(dev);
729 if (priv->rtllib->state == RTLLIB_LINKED)
730 rtl92e_leisure_ps_leave(dev);
733 priv->rtllib->ieee_up = 0;
734 priv->bfirst_after_down = true;
735 if (!netif_queue_stopped(dev))
736 netif_stop_queue(dev);
738 priv->rtllib->wpa_ie_len = 0;
739 kfree(priv->rtllib->wpa_ie);
740 priv->rtllib->wpa_ie = NULL;
741 rtl92e_cam_reset(dev);
742 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
743 rtl92e_irq_disable(dev);
745 del_timer_sync(&priv->watch_dog_timer);
746 _rtl92e_cancel_deferred_work(priv);
747 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
749 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
750 spin_lock_irqsave(&priv->rf_ps_lock, flags);
751 while (priv->rf_change_in_progress) {
752 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
753 if (rf_in_progress_timeout > 100) {
754 spin_lock_irqsave(&priv->rf_ps_lock, flags);
758 rf_in_progress_timeout++;
759 spin_lock_irqsave(&priv->rf_ps_lock, flags);
761 priv->rf_change_in_progress = true;
762 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
763 priv->ops->stop_adapter(dev, false);
764 spin_lock_irqsave(&priv->rf_ps_lock, flags);
765 priv->rf_change_in_progress = false;
766 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
768 memset(&priv->rtllib->current_network, 0,
769 offsetof(struct rtllib_network, list));
774 static void _rtl92e_init_priv_handler(struct net_device *dev)
776 struct r8192_priv *priv = rtllib_priv(dev);
778 priv->rtllib->softmac_hard_start_xmit = _rtl92e_hard_start_xmit;
779 priv->rtllib->set_chan = _rtl92e_set_chan;
780 priv->rtllib->link_change = priv->ops->link_change;
781 priv->rtllib->softmac_data_hard_start_xmit = _rtl92e_hard_data_xmit;
782 priv->rtllib->check_nic_enough_desc = _rtl92e_check_nic_enough_desc;
783 priv->rtllib->handle_assoc_response = _rtl92e_handle_assoc_response;
784 priv->rtllib->handle_beacon = _rtl92e_handle_beacon;
785 priv->rtllib->SetWirelessMode = rtl92e_set_wireless_mode;
786 priv->rtllib->LeisurePSLeave = rtl92e_leisure_ps_leave;
787 priv->rtllib->SetBWModeHandler = rtl92e_set_bw_mode;
788 priv->rf_set_chan = rtl92e_set_channel;
790 priv->rtllib->start_send_beacons = rtl92e_start_beacon;
791 priv->rtllib->stop_send_beacons = _rtl92e_stop_beacon;
793 priv->rtllib->sta_wake_up = rtl92e_hw_wakeup;
794 priv->rtllib->enter_sleep_state = rtl92e_enter_sleep;
795 priv->rtllib->ps_is_queue_empty = _rtl92e_is_tx_queue_empty;
797 priv->rtllib->GetNmodeSupportBySecCfg = rtl92e_get_nmode_support_by_sec;
798 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
799 rtl92e_is_halfn_supported_by_ap;
801 priv->rtllib->SetHwRegHandler = rtl92e_set_reg;
802 priv->rtllib->AllowAllDestAddrHandler = rtl92e_set_monitor_mode;
803 priv->rtllib->SetFwCmdHandler = NULL;
804 priv->rtllib->InitialGainHandler = rtl92e_init_gain;
805 priv->rtllib->rtllib_ips_leave_wq = rtl92e_rtllib_ips_leave_wq;
806 priv->rtllib->rtllib_ips_leave = rtl92e_rtllib_ips_leave;
808 priv->rtllib->LedControlHandler = NULL;
809 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
811 priv->rtllib->ScanOperationBackupHandler = rtl92e_scan_op_backup;
814 static void _rtl92e_init_priv_constant(struct net_device *dev)
816 struct r8192_priv *priv = rtllib_priv(dev);
817 struct rt_pwr_save_ctrl *psc = (struct rt_pwr_save_ctrl *)
818 &priv->rtllib->pwr_save_ctrl;
820 psc->reg_max_lps_awake_intvl = 5;
823 static void _rtl92e_init_priv_variable(struct net_device *dev)
825 struct r8192_priv *priv = rtllib_priv(dev);
828 priv->dot11_current_preamble_mode = PREAMBLE_AUTO;
829 priv->rtllib->status = 0;
830 priv->polling_timer_on = 0;
831 priv->up_first_time = 1;
832 priv->blinked_ingpio = false;
833 priv->being_init_adapter = false;
834 priv->bdisable_nic = false;
835 priv->txringcount = 64;
836 priv->rxbuffersize = 9100;
837 priv->rxringcount = MAX_RX_COUNT;
838 priv->irq_enabled = 0;
840 priv->reg_chnl_plan = 0xf;
841 priv->rtllib->mode = WIRELESS_MODE_AUTO;
842 priv->rtllib->iw_mode = IW_MODE_INFRA;
843 priv->rtllib->net_promiscuous_md = false;
844 priv->rtllib->intel_promiscuous_md_info.promiscuous_on = false;
845 priv->rtllib->intel_promiscuous_md_info.fltr_src_sta_frame =
847 priv->rtllib->ieee_up = 0;
848 priv->retry_rts = DEFAULT_RETRY_RTS;
849 priv->retry_data = DEFAULT_RETRY_DATA;
850 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
851 priv->rtllib->rate = 110;
852 priv->rtllib->short_slot = 1;
853 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
854 priv->bcck_in_ch14 = false;
855 priv->bfsync_processing = false;
856 priv->cck_present_attn = 0;
857 priv->rfa_txpowertrackingindex = 0;
858 priv->rfc_txpowertrackingindex = 0;
859 priv->cck_pwr_enl = 6;
860 priv->rst_progress = RESET_TYPE_NORESET;
861 priv->force_reset = false;
862 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
864 priv->rtllib->wx_set_enc = 0;
865 priv->hw_radio_off = false;
866 priv->rtllib->rf_off_reason = 0;
867 priv->rf_change_in_progress = false;
868 priv->hw_rf_off_action = 0;
869 priv->set_rf_pwr_state_in_progress = false;
870 priv->rtllib->pwr_save_ctrl.bLeisurePs = true;
871 priv->rtllib->LPSDelayCnt = 0;
872 priv->rtllib->sta_sleep = LPS_IS_WAKE;
873 priv->rtllib->rf_power_state = rf_on;
875 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
876 priv->rtllib->iw_mode = IW_MODE_INFRA;
877 priv->rtllib->active_scan = 1;
878 priv->rtllib->be_scan_inprogress = false;
879 priv->rtllib->modulation = RTLLIB_CCK_MODULATION |
880 RTLLIB_OFDM_MODULATION;
881 priv->rtllib->host_encrypt = 1;
882 priv->rtllib->host_decrypt = 1;
884 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
886 priv->card_type = PCI;
888 priv->fw_info = vzalloc(sizeof(struct rt_firmware));
891 "rtl8192e: Unable to allocate space for firmware\n");
893 skb_queue_head_init(&priv->skb_queue);
895 for (i = 0; i < MAX_QUEUE_SIZE; i++)
896 skb_queue_head_init(&priv->rtllib->skb_waitQ[i]);
899 static void _rtl92e_init_priv_lock(struct r8192_priv *priv)
901 spin_lock_init(&priv->tx_lock);
902 spin_lock_init(&priv->irq_th_lock);
903 spin_lock_init(&priv->rf_ps_lock);
904 spin_lock_init(&priv->ps_lock);
905 mutex_init(&priv->wx_mutex);
906 mutex_init(&priv->rf_mutex);
907 mutex_init(&priv->mutex);
910 static void _rtl92e_init_priv_task(struct net_device *dev)
912 struct r8192_priv *priv = rtllib_priv(dev);
914 INIT_WORK_RSL(&priv->reset_wq, (void *)_rtl92e_restart, dev);
915 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)rtl92e_ips_leave_wq,
917 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
918 (void *)_rtl92e_watchdog_wq_cb, dev);
919 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
920 (void *)rtl92e_dm_txpower_tracking_wq, dev);
921 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
922 (void *)rtl92e_dm_rf_pathcheck_wq, dev);
923 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
924 (void *)_rtl92e_update_beacon, dev);
925 INIT_WORK_RSL(&priv->qos_activate, (void *)_rtl92e_qos_activate, dev);
926 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
927 (void *)rtl92e_hw_wakeup_wq, dev);
928 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
929 (void *)rtl92e_hw_sleep_wq, dev);
930 tasklet_setup(&priv->irq_rx_tasklet, _rtl92e_irq_rx_tasklet);
931 tasklet_setup(&priv->irq_tx_tasklet, _rtl92e_irq_tx_tasklet);
932 tasklet_setup(&priv->irq_prepare_beacon_tasklet,
933 _rtl92e_prepare_beacon);
936 static short _rtl92e_get_channel_map(struct net_device *dev)
940 struct r8192_priv *priv = rtllib_priv(dev);
942 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256) &&
943 (priv->rf_chip != RF_6052)) {
944 netdev_err(dev, "%s: unknown rf chip, can't set channel map\n",
949 if (priv->chnl_plan >= COUNTRY_CODE_MAX) {
951 "rtl819x_init:Error channel plan! Set to default.\n");
952 priv->chnl_plan = COUNTRY_CODE_FCC;
954 dot11d_init(priv->rtllib);
955 dot11d_channel_map(priv->chnl_plan, priv->rtllib);
956 for (i = 1; i <= 11; i++)
957 (priv->rtllib->active_channel_map)[i] = 1;
958 (priv->rtllib->active_channel_map)[12] = 2;
959 (priv->rtllib->active_channel_map)[13] = 2;
964 static short _rtl92e_init(struct net_device *dev)
966 struct r8192_priv *priv = rtllib_priv(dev);
968 memset(&priv->stats, 0, sizeof(struct rt_stats));
970 _rtl92e_init_priv_handler(dev);
971 _rtl92e_init_priv_constant(dev);
972 _rtl92e_init_priv_variable(dev);
973 _rtl92e_init_priv_lock(priv);
974 _rtl92e_init_priv_task(dev);
975 rtl92e_get_eeprom_size(dev);
976 rtl92e_init_variables(dev);
977 _rtl92e_get_channel_map(dev);
981 timer_setup(&priv->watch_dog_timer, _rtl92e_watchdog_timer_cb, 0);
983 timer_setup(&priv->gpio_polling_timer, rtl92e_check_rfctrl_gpio_timer,
986 rtl92e_irq_disable(dev);
987 if (request_irq(dev->irq, _rtl92e_irq, IRQF_SHARED, dev->name, dev)) {
988 netdev_err(dev, "Error allocating IRQ %d", dev->irq);
992 priv->irq = dev->irq;
994 if (_rtl92e_pci_initdescring(dev) != 0) {
995 netdev_err(dev, "Endopoints initialization failed");
996 free_irq(dev->irq, dev);
1003 /***************************************************************************
1004 * -------------------------------WATCHDOG STUFF---------------------------
1005 **************************************************************************/
1006 static short _rtl92e_is_tx_queue_empty(struct net_device *dev)
1009 struct r8192_priv *priv = rtllib_priv(dev);
1011 for (i = 0; i <= MGNT_QUEUE; i++) {
1012 if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE))
1014 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) {
1015 netdev_info(dev, "===>tx queue is not empty:%d, %d\n",
1016 i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1023 static enum reset_type _rtl92e_tx_check_stuck(struct net_device *dev)
1025 struct r8192_priv *priv = rtllib_priv(dev);
1027 bool bCheckFwTxCnt = false;
1028 struct rtl8192_tx_ring *ring = NULL;
1029 struct sk_buff *skb = NULL;
1030 struct cb_desc *tcb_desc = NULL;
1031 unsigned long flags = 0;
1033 switch (priv->rtllib->ps) {
1034 case RTLLIB_PS_DISABLED:
1036 case (RTLLIB_PS_MBCAST | RTLLIB_PS_UNICAST):
1041 spin_lock_irqsave(&priv->irq_th_lock, flags);
1042 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) {
1043 if (QueueID == TXCMD_QUEUE)
1046 if (QueueID == BEACON_QUEUE)
1049 ring = &priv->tx_ring[QueueID];
1051 if (skb_queue_len(&ring->queue) == 0) {
1054 skb = __skb_peek(&ring->queue);
1055 tcb_desc = (struct cb_desc *)(skb->cb +
1057 tcb_desc->nStuckCount++;
1058 bCheckFwTxCnt = true;
1059 if (tcb_desc->nStuckCount > 1)
1061 "%s: QueueID=%d tcb_desc->nStuckCount=%d\n",
1063 tcb_desc->nStuckCount);
1066 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1068 if (bCheckFwTxCnt) {
1069 if (priv->ops->tx_check_stuck_handler(dev))
1070 return RESET_TYPE_SILENT;
1073 return RESET_TYPE_NORESET;
1076 static enum reset_type _rtl92e_rx_check_stuck(struct net_device *dev)
1078 struct r8192_priv *priv = rtllib_priv(dev);
1080 if (priv->ops->rx_check_stuck_handler(dev))
1081 return RESET_TYPE_SILENT;
1083 return RESET_TYPE_NORESET;
1086 static enum reset_type _rtl92e_if_check_reset(struct net_device *dev)
1088 struct r8192_priv *priv = rtllib_priv(dev);
1089 enum reset_type TxResetType = RESET_TYPE_NORESET;
1090 enum reset_type RxResetType = RESET_TYPE_NORESET;
1091 enum rt_rf_power_state rfState;
1093 rfState = priv->rtllib->rf_power_state;
1095 if (rfState == rf_on)
1096 TxResetType = _rtl92e_tx_check_stuck(dev);
1098 if (rfState == rf_on &&
1099 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1100 (priv->rtllib->state == RTLLIB_LINKED))
1101 RxResetType = _rtl92e_rx_check_stuck(dev);
1103 if (TxResetType == RESET_TYPE_NORMAL ||
1104 RxResetType == RESET_TYPE_NORMAL) {
1105 netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n",
1106 __func__, TxResetType, RxResetType);
1107 return RESET_TYPE_NORMAL;
1108 } else if (TxResetType == RESET_TYPE_SILENT ||
1109 RxResetType == RESET_TYPE_SILENT) {
1110 netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n",
1111 __func__, TxResetType, RxResetType);
1112 return RESET_TYPE_SILENT;
1114 return RESET_TYPE_NORESET;
1118 static void _rtl92e_if_silent_reset(struct net_device *dev)
1120 struct r8192_priv *priv = rtllib_priv(dev);
1122 int reset_status = 0;
1123 struct rtllib_device *ieee = priv->rtllib;
1126 if (priv->rst_progress == RESET_TYPE_NORESET) {
1127 priv->rst_progress = RESET_TYPE_SILENT;
1129 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1130 if (priv->rf_change_in_progress) {
1131 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1134 priv->rf_change_in_progress = true;
1135 priv->reset_in_progress = true;
1136 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1140 mutex_lock(&priv->wx_mutex);
1142 if (priv->rtllib->state == RTLLIB_LINKED)
1143 rtl92e_leisure_ps_leave(dev);
1146 netdev_info(dev, "%s():the driver is not up.\n",
1148 mutex_unlock(&priv->wx_mutex);
1155 if (!netif_queue_stopped(dev))
1156 netif_stop_queue(dev);
1158 rtl92e_irq_disable(dev);
1159 del_timer_sync(&priv->watch_dog_timer);
1160 _rtl92e_cancel_deferred_work(priv);
1161 rtl92e_dm_deinit(dev);
1162 rtllib_stop_scan_syncro(ieee);
1164 if (ieee->state == RTLLIB_LINKED) {
1165 mutex_lock(&ieee->wx_mutex);
1166 netdev_info(dev, "ieee->state is RTLLIB_LINKED\n");
1167 rtllib_stop_send_beacons(priv->rtllib);
1168 del_timer_sync(&ieee->associate_timer);
1169 cancel_delayed_work(&ieee->associate_retry_wq);
1170 rtllib_stop_scan(ieee);
1171 netif_carrier_off(dev);
1172 mutex_unlock(&ieee->wx_mutex);
1174 netdev_info(dev, "ieee->state is NOT LINKED\n");
1175 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1178 rtl92e_dm_backup_state(dev);
1180 mutex_unlock(&priv->wx_mutex);
1181 reset_status = _rtl92e_up(dev, true);
1183 if (reset_status == -1) {
1184 if (reset_times < 3) {
1188 netdev_warn(dev, "%s(): Reset Failed\n",
1193 ieee->is_silent_reset = 1;
1195 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1196 priv->rf_change_in_progress = false;
1197 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1199 rtl92e_enable_hw_security_config(dev);
1201 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1203 ieee->set_chan(ieee->dev,
1204 ieee->current_network.channel);
1206 schedule_work(&ieee->associate_complete_wq);
1208 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1210 ieee->set_chan(ieee->dev,
1211 ieee->current_network.channel);
1212 ieee->link_change(ieee->dev);
1214 notify_wx_assoc_event(ieee);
1216 rtllib_start_send_beacons(ieee);
1218 netif_carrier_on(ieee->dev);
1221 rtl92e_cam_restore(dev);
1222 rtl92e_dm_restore_state(dev);
1224 priv->rst_progress = RESET_TYPE_NORESET;
1225 priv->reset_count++;
1226 priv->reset_in_progress = false;
1228 rtl92e_writeb(dev, UFWP, 1);
1232 static void _rtl92e_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1233 u32 *TotalRxDataNum)
1239 *TotalRxDataNum = 0;
1241 SlotIndex = (priv->rtllib->link_detect_info.SlotIndex++) %
1242 (priv->rtllib->link_detect_info.SlotNum);
1243 priv->rtllib->link_detect_info.RxBcnNum[SlotIndex] =
1244 priv->rtllib->link_detect_info.NumRecvBcnInPeriod;
1245 priv->rtllib->link_detect_info.RxDataNum[SlotIndex] =
1246 priv->rtllib->link_detect_info.NumRecvDataInPeriod;
1247 for (i = 0; i < priv->rtllib->link_detect_info.SlotNum; i++) {
1248 *TotalRxBcnNum += priv->rtllib->link_detect_info.RxBcnNum[i];
1249 *TotalRxDataNum += priv->rtllib->link_detect_info.RxDataNum[i];
1253 static void _rtl92e_watchdog_wq_cb(void *data)
1255 struct r8192_priv *priv = container_of_dwork_rsl(data,
1256 struct r8192_priv, watch_dog_wq);
1257 struct net_device *dev = priv->rtllib->dev;
1258 struct rtllib_device *ieee = priv->rtllib;
1259 enum reset_type ResetType = RESET_TYPE_NORESET;
1260 static u8 check_reset_cnt;
1261 unsigned long flags;
1262 struct rt_pwr_save_ctrl *psc = (struct rt_pwr_save_ctrl *)
1263 (&priv->rtllib->pwr_save_ctrl);
1264 bool bBusyTraffic = false;
1265 bool bHigherBusyTraffic = false;
1266 bool bHigherBusyRxTraffic = false;
1267 bool bEnterPS = false;
1269 if (!priv->up || priv->hw_radio_off)
1272 if (priv->rtllib->state >= RTLLIB_LINKED) {
1273 if (priv->rtllib->CntAfterLink < 2)
1274 priv->rtllib->CntAfterLink++;
1276 priv->rtllib->CntAfterLink = 0;
1279 rtl92e_dm_watchdog(dev);
1281 if (!rtllib_act_scanning(priv->rtllib, false)) {
1282 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
1284 (ieee->rf_power_state == rf_on) && !ieee->is_set_key &&
1285 (!ieee->proto_stoppping) && !ieee->wx_set_enc) {
1286 if ((ieee->pwr_save_ctrl.ReturnPoint ==
1287 IPS_CALLBACK_NONE) &&
1288 (!ieee->net_promiscuous_md)) {
1289 rtl92e_ips_enter(dev);
1293 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode ==
1294 IW_MODE_INFRA) && (!ieee->net_promiscuous_md)) {
1295 if (ieee->link_detect_info.NumRxOkInPeriod > 100 ||
1296 ieee->link_detect_info.NumTxOkInPeriod > 100)
1297 bBusyTraffic = true;
1299 if (ieee->link_detect_info.NumRxOkInPeriod > 4000 ||
1300 ieee->link_detect_info.NumTxOkInPeriod > 4000) {
1301 bHigherBusyTraffic = true;
1302 if (ieee->link_detect_info.NumRxOkInPeriod > 5000)
1303 bHigherBusyRxTraffic = true;
1305 bHigherBusyRxTraffic = false;
1308 if (((ieee->link_detect_info.NumRxUnicastOkInPeriod +
1309 ieee->link_detect_info.NumTxOkInPeriod) > 8) ||
1310 (ieee->link_detect_info.NumRxUnicastOkInPeriod > 2))
1315 if (ieee->current_network.beacon_interval < 95)
1319 rtl92e_leisure_ps_enter(dev);
1321 rtl92e_leisure_ps_leave(dev);
1324 rtl92e_leisure_ps_leave(dev);
1327 ieee->link_detect_info.NumRxOkInPeriod = 0;
1328 ieee->link_detect_info.NumTxOkInPeriod = 0;
1329 ieee->link_detect_info.NumRxUnicastOkInPeriod = 0;
1330 ieee->link_detect_info.bBusyTraffic = bBusyTraffic;
1332 ieee->link_detect_info.bHigherBusyTraffic = bHigherBusyTraffic;
1333 ieee->link_detect_info.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1335 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1336 u32 TotalRxBcnNum = 0;
1337 u32 TotalRxDataNum = 0;
1339 _rtl92e_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
1341 if ((TotalRxBcnNum + TotalRxDataNum) == 0)
1342 priv->check_roaming_cnt++;
1344 priv->check_roaming_cnt = 0;
1346 if (priv->check_roaming_cnt > 0) {
1347 if (ieee->rf_power_state == rf_off)
1348 netdev_info(dev, "%s(): RF is off\n", __func__);
1351 "===>%s(): AP is power off, chan:%d, connect another one\n",
1352 __func__, priv->chan);
1354 ieee->state = RTLLIB_ASSOCIATING;
1356 RemovePeerTS(priv->rtllib,
1357 priv->rtllib->current_network.bssid);
1358 ieee->is_roaming = true;
1359 ieee->is_set_key = false;
1360 ieee->link_change(dev);
1361 if (ieee->LedControlHandler)
1362 ieee->LedControlHandler(ieee->dev,
1363 LED_CTL_START_TO_LINK);
1365 notify_wx_assoc_event(ieee);
1367 if (!(ieee->rtllib_ap_sec_type(ieee) &
1368 (SEC_ALG_CCMP | SEC_ALG_TKIP)))
1369 schedule_delayed_work(
1370 &ieee->associate_procedure_wq, 0);
1372 priv->check_roaming_cnt = 0;
1374 ieee->link_detect_info.NumRecvBcnInPeriod = 0;
1375 ieee->link_detect_info.NumRecvDataInPeriod = 0;
1378 spin_lock_irqsave(&priv->tx_lock, flags);
1379 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1380 (!priv->rf_change_in_progress) && (!psc->bSwRfProcessing)) {
1381 ResetType = _rtl92e_if_check_reset(dev);
1382 check_reset_cnt = 3;
1384 spin_unlock_irqrestore(&priv->tx_lock, flags);
1386 if (ResetType == RESET_TYPE_NORMAL) {
1387 priv->rst_progress = RESET_TYPE_NORMAL;
1391 if ((priv->force_reset || ResetType == RESET_TYPE_SILENT))
1392 _rtl92e_if_silent_reset(dev);
1393 priv->force_reset = false;
1394 priv->reset_in_progress = false;
1397 static void _rtl92e_watchdog_timer_cb(struct timer_list *t)
1399 struct r8192_priv *priv = from_timer(priv, t, watch_dog_timer);
1401 schedule_delayed_work(&priv->watch_dog_wq, 0);
1402 mod_timer(&priv->watch_dog_timer, jiffies +
1403 msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME));
1406 /****************************************************************************
1407 * ---------------------------- NIC TX/RX STUFF---------------------------
1408 ****************************************************************************/
1409 void rtl92e_rx_enable(struct net_device *dev)
1411 struct r8192_priv *priv = rtllib_priv(dev);
1413 priv->ops->rx_enable(dev);
1416 void rtl92e_tx_enable(struct net_device *dev)
1418 struct r8192_priv *priv = rtllib_priv(dev);
1420 priv->ops->tx_enable(dev);
1422 rtllib_reset_queue(priv->rtllib);
1425 static void _rtl92e_free_rx_ring(struct net_device *dev)
1427 struct r8192_priv *priv = rtllib_priv(dev);
1428 int i, rx_queue_idx;
1430 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE;
1432 for (i = 0; i < priv->rxringcount; i++) {
1433 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
1438 dma_unmap_single(&priv->pdev->dev,
1439 *((dma_addr_t *)skb->cb),
1440 priv->rxbuffersize, DMA_FROM_DEVICE);
1444 dma_free_coherent(&priv->pdev->dev,
1445 sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
1446 priv->rx_ring[rx_queue_idx],
1447 priv->rx_ring_dma[rx_queue_idx]);
1448 priv->rx_ring[rx_queue_idx] = NULL;
1452 static void _rtl92e_free_tx_ring(struct net_device *dev, unsigned int prio)
1454 struct r8192_priv *priv = rtllib_priv(dev);
1455 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1457 while (skb_queue_len(&ring->queue)) {
1458 struct tx_desc *entry = &ring->desc[ring->idx];
1459 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1461 dma_unmap_single(&priv->pdev->dev, entry->TxBuffAddr,
1462 skb->len, DMA_TO_DEVICE);
1464 ring->idx = (ring->idx + 1) % ring->entries;
1467 dma_free_coherent(&priv->pdev->dev,
1468 sizeof(*ring->desc) * ring->entries, ring->desc,
1473 static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1476 struct r8192_priv *priv = rtllib_priv(dev);
1478 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1480 u8 queue_index = tcb_desc->queue_index;
1482 if ((priv->rtllib->rf_power_state == rf_off) || !priv->up ||
1483 priv->reset_in_progress) {
1488 if (queue_index == TXCMD_QUEUE)
1489 netdev_warn(dev, "%s(): queue index == TXCMD_QUEUE\n",
1492 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1493 skb_push(skb, priv->rtllib->tx_headroom);
1494 ret = _rtl92e_tx(dev, skb);
1496 if (queue_index != MGNT_QUEUE) {
1497 priv->rtllib->stats.tx_bytes += (skb->len -
1498 priv->rtllib->tx_headroom);
1499 priv->rtllib->stats.tx_packets++;
1506 static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1508 struct r8192_priv *priv = rtllib_priv(dev);
1510 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1512 u8 queue_index = tcb_desc->queue_index;
1514 if (queue_index != TXCMD_QUEUE) {
1515 if ((priv->rtllib->rf_power_state == rf_off) ||
1516 !priv->up || priv->reset_in_progress) {
1522 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1523 if (queue_index == TXCMD_QUEUE) {
1524 _rtl92e_tx_cmd(dev, skb);
1528 tcb_desc->RATRIndex = 7;
1529 tcb_desc->tx_dis_rate_fallback = 1;
1530 tcb_desc->tx_use_drv_assinged_rate = 1;
1531 tcb_desc->bTxEnableFwCalcDur = 1;
1532 skb_push(skb, priv->rtllib->tx_headroom);
1533 ret = _rtl92e_tx(dev, skb);
1539 static void _rtl92e_tx_isr(struct net_device *dev, int prio)
1541 struct r8192_priv *priv = rtllib_priv(dev);
1543 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1545 while (skb_queue_len(&ring->queue)) {
1546 struct tx_desc *entry = &ring->desc[ring->idx];
1547 struct sk_buff *skb;
1549 if (prio != BEACON_QUEUE) {
1552 ring->idx = (ring->idx + 1) % ring->entries;
1555 skb = __skb_dequeue(&ring->queue);
1556 dma_unmap_single(&priv->pdev->dev, entry->TxBuffAddr,
1557 skb->len, DMA_TO_DEVICE);
1561 if (prio != BEACON_QUEUE)
1562 tasklet_schedule(&priv->irq_tx_tasklet);
1565 static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1567 struct r8192_priv *priv = rtllib_priv(dev);
1568 struct rtl8192_tx_ring *ring;
1569 struct tx_desc_cmd *entry;
1571 struct cb_desc *tcb_desc;
1572 unsigned long flags;
1574 spin_lock_irqsave(&priv->irq_th_lock, flags);
1575 ring = &priv->tx_ring[TXCMD_QUEUE];
1577 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1578 entry = (struct tx_desc_cmd *)&ring->desc[idx];
1580 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1582 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
1584 __skb_queue_tail(&ring->queue, skb);
1585 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1588 static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb)
1590 struct r8192_priv *priv = rtllib_priv(dev);
1591 struct rtl8192_tx_ring *ring;
1592 unsigned long flags;
1593 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1595 struct tx_desc *pdesc = NULL;
1596 struct rtllib_hdr_1addr *header = NULL;
1597 u16 fc = 0, type = 0;
1598 u8 *pda_addr = NULL;
1600 u32 fwinfo_size = 0;
1602 if (priv->bdisable_nic) {
1603 netdev_warn(dev, "%s: Nic is disabled! Can't tx packet.\n",
1608 priv->rtllib->bAwakePktSent = true;
1610 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
1612 header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size);
1613 fc = le16_to_cpu(header->frame_ctl);
1614 type = WLAN_FC_GET_TYPE(fc);
1615 pda_addr = header->addr1;
1617 if (!is_broadcast_ether_addr(pda_addr) && !is_multicast_ether_addr(pda_addr))
1618 priv->stats.txbytesunicast += skb->len - fwinfo_size;
1620 spin_lock_irqsave(&priv->irq_th_lock, flags);
1621 ring = &priv->tx_ring[tcb_desc->queue_index];
1622 if (tcb_desc->queue_index != BEACON_QUEUE)
1623 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1627 pdesc = &ring->desc[idx];
1628 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
1630 "No more TX desc@%d, ring->idx = %d, idx = %d, skblen = 0x%x queuelen=%d",
1631 tcb_desc->queue_index, ring->idx, idx, skb->len,
1632 skb_queue_len(&ring->queue));
1633 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1637 if (type == RTLLIB_FTYPE_DATA) {
1638 if (priv->rtllib->LedControlHandler)
1639 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
1641 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
1642 __skb_queue_tail(&ring->queue, skb);
1644 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1645 netif_trans_update(dev);
1647 rtl92e_writew(dev, TP_POLL, 0x01 << tcb_desc->queue_index);
1651 static short _rtl92e_alloc_rx_ring(struct net_device *dev)
1653 struct r8192_priv *priv = rtllib_priv(dev);
1654 struct rx_desc *entry = NULL;
1655 int i, rx_queue_idx;
1657 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
1658 priv->rx_ring[rx_queue_idx] = dma_alloc_coherent(&priv->pdev->dev,
1659 sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
1660 &priv->rx_ring_dma[rx_queue_idx],
1662 if (!priv->rx_ring[rx_queue_idx] ||
1663 (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
1664 netdev_warn(dev, "Cannot allocate RX ring\n");
1668 priv->rx_idx[rx_queue_idx] = 0;
1670 for (i = 0; i < priv->rxringcount; i++) {
1671 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
1672 dma_addr_t *mapping;
1674 entry = &priv->rx_ring[rx_queue_idx][i];
1678 priv->rx_buf[rx_queue_idx][i] = skb;
1679 mapping = (dma_addr_t *)skb->cb;
1680 *mapping = dma_map_single(&priv->pdev->dev,
1681 skb_tail_pointer_rsl(skb),
1682 priv->rxbuffersize, DMA_FROM_DEVICE);
1683 if (dma_mapping_error(&priv->pdev->dev, *mapping)) {
1684 dev_kfree_skb_any(skb);
1687 entry->BufferAddress = *mapping;
1689 entry->Length = priv->rxbuffersize;
1699 static int _rtl92e_alloc_tx_ring(struct net_device *dev, unsigned int prio,
1700 unsigned int entries)
1702 struct r8192_priv *priv = rtllib_priv(dev);
1703 struct tx_desc *ring;
1707 ring = dma_alloc_coherent(&priv->pdev->dev, sizeof(*ring) * entries,
1709 if (!ring || (unsigned long)ring & 0xFF) {
1710 netdev_warn(dev, "Cannot allocate TX ring (prio = %d)\n", prio);
1714 priv->tx_ring[prio].desc = ring;
1715 priv->tx_ring[prio].dma = dma;
1716 priv->tx_ring[prio].idx = 0;
1717 priv->tx_ring[prio].entries = entries;
1718 skb_queue_head_init(&priv->tx_ring[prio].queue);
1720 for (i = 0; i < entries; i++)
1721 ring[i].NextDescAddress =
1722 (u32)dma + ((i + 1) % entries) *
1728 static short _rtl92e_pci_initdescring(struct net_device *dev)
1732 struct r8192_priv *priv = rtllib_priv(dev);
1734 ret = _rtl92e_alloc_rx_ring(dev);
1738 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1739 ret = _rtl92e_alloc_tx_ring(dev, i, priv->txringcount);
1741 goto err_free_rings;
1747 _rtl92e_free_rx_ring(dev);
1748 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
1749 if (priv->tx_ring[i].desc)
1750 _rtl92e_free_tx_ring(dev, i);
1754 void rtl92e_reset_desc_ring(struct net_device *dev)
1756 struct r8192_priv *priv = rtllib_priv(dev);
1757 int i, rx_queue_idx;
1758 unsigned long flags = 0;
1760 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
1761 if (priv->rx_ring[rx_queue_idx]) {
1762 struct rx_desc *entry = NULL;
1764 for (i = 0; i < priv->rxringcount; i++) {
1765 entry = &priv->rx_ring[rx_queue_idx][i];
1768 priv->rx_idx[rx_queue_idx] = 0;
1772 spin_lock_irqsave(&priv->irq_th_lock, flags);
1773 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1774 if (priv->tx_ring[i].desc) {
1775 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
1777 while (skb_queue_len(&ring->queue)) {
1778 struct tx_desc *entry = &ring->desc[ring->idx];
1779 struct sk_buff *skb =
1780 __skb_dequeue(&ring->queue);
1782 dma_unmap_single(&priv->pdev->dev,
1783 entry->TxBuffAddr, skb->len,
1786 ring->idx = (ring->idx + 1) % ring->entries;
1791 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1794 void rtl92e_update_rx_pkt_timestamp(struct net_device *dev,
1795 struct rtllib_rx_stats *stats)
1797 struct r8192_priv *priv = rtllib_priv(dev);
1799 if (stats->bIsAMPDU && !stats->bFirstMPDU)
1800 stats->mac_time = priv->last_rx_desc_tsf;
1802 priv->last_rx_desc_tsf = stats->mac_time;
1805 long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index)
1809 signal_power = (long)((signal_strength_index + 1) >> 1);
1812 return signal_power;
1815 void rtl92e_update_rx_statistics(struct r8192_priv *priv,
1816 struct rtllib_rx_stats *pprevious_stats)
1820 if (priv->stats.recv_signal_power == 0)
1821 priv->stats.recv_signal_power =
1822 pprevious_stats->RecvSignalPower;
1824 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
1826 else if (pprevious_stats->RecvSignalPower <
1827 priv->stats.recv_signal_power)
1829 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 +
1830 pprevious_stats->RecvSignalPower +
1834 u8 rtl92e_rx_db_to_percent(s8 antpower)
1836 if ((antpower <= -100) || (antpower >= 20))
1838 else if (antpower >= 0)
1841 return 100 + antpower;
1843 } /* QueryRxPwrPercentage */
1845 u8 rtl92e_evm_db_to_percent(s8 value)
1847 s8 ret_val = clamp(-value, 0, 33) * 3;
1855 void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
1856 struct rtllib_rx_stats *ptarget_stats)
1858 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
1859 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
1862 static void _rtl92e_rx_normal(struct net_device *dev)
1864 struct r8192_priv *priv = rtllib_priv(dev);
1865 struct rtllib_hdr_1addr *rtllib_hdr = NULL;
1866 bool unicast_packet = false;
1867 bool bLedBlinking = true;
1868 u16 fc = 0, type = 0;
1870 int rx_queue_idx = RX_MPDU_QUEUE;
1872 struct rtllib_rx_stats stats = {
1876 .freq = RTLLIB_24GHZ_BAND,
1878 unsigned int count = priv->rxringcount;
1880 stats.nic_type = NIC_8192E;
1883 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx]
1884 [priv->rx_idx[rx_queue_idx]];
1885 struct sk_buff *skb = priv->rx_buf[rx_queue_idx]
1886 [priv->rx_idx[rx_queue_idx]];
1887 struct sk_buff *new_skb;
1891 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
1894 new_skb = dev_alloc_skb(priv->rxbuffersize);
1895 /* if allocation of new skb failed - drop current packet
1898 if (unlikely(!new_skb))
1901 dma_unmap_single(&priv->pdev->dev, *((dma_addr_t *)skb->cb),
1902 priv->rxbuffersize, DMA_FROM_DEVICE);
1904 skb_put(skb, pdesc->Length);
1905 skb_reserve(skb, stats.RxDrvInfoSize +
1907 skb_trim(skb, skb->len - S_CRC_LEN);
1908 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
1909 if (!is_multicast_ether_addr(rtllib_hdr->addr1)) {
1910 /* unicast packet */
1911 unicast_packet = true;
1913 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
1914 type = WLAN_FC_GET_TYPE(fc);
1915 if (type == RTLLIB_FTYPE_MGMT)
1916 bLedBlinking = false;
1919 if (priv->rtllib->LedControlHandler)
1920 priv->rtllib->LedControlHandler(dev,
1925 if (!rtllib_rx(priv->rtllib, skb, &stats)) {
1926 dev_kfree_skb_any(skb);
1929 priv->stats.rxbytesunicast += skb_len;
1935 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] =
1937 *((dma_addr_t *)skb->cb) = dma_map_single(&priv->pdev->dev,
1938 skb_tail_pointer_rsl(skb),
1939 priv->rxbuffersize, DMA_FROM_DEVICE);
1940 if (dma_mapping_error(&priv->pdev->dev, *((dma_addr_t *)skb->cb))) {
1941 dev_kfree_skb_any(skb);
1945 pdesc->BufferAddress = *((dma_addr_t *)skb->cb);
1947 pdesc->Length = priv->rxbuffersize;
1948 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount - 1)
1950 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) %
1955 static void _rtl92e_tx_resume(struct net_device *dev)
1957 struct r8192_priv *priv = rtllib_priv(dev);
1958 struct rtllib_device *ieee = priv->rtllib;
1959 struct sk_buff *skb;
1962 for (queue_index = BK_QUEUE;
1963 queue_index < MAX_QUEUE_SIZE; queue_index++) {
1964 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) &&
1965 (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) {
1966 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
1967 ieee->softmac_data_hard_start_xmit(skb, dev, 0);
1972 static void _rtl92e_irq_tx_tasklet(struct tasklet_struct *t)
1974 struct r8192_priv *priv = from_tasklet(priv, t, irq_tx_tasklet);
1976 _rtl92e_tx_resume(priv->rtllib->dev);
1979 static void _rtl92e_irq_rx_tasklet(struct tasklet_struct *t)
1981 struct r8192_priv *priv = from_tasklet(priv, t, irq_rx_tasklet);
1983 _rtl92e_rx_normal(priv->rtllib->dev);
1985 rtl92e_writel(priv->rtllib->dev, INTA_MASK,
1986 rtl92e_readl(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
1989 /****************************************************************************
1990 * ---------------------------- NIC START/CLOSE STUFF---------------------------
1991 ****************************************************************************/
1992 static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv)
1994 cancel_delayed_work_sync(&priv->watch_dog_wq);
1995 cancel_delayed_work_sync(&priv->update_beacon_wq);
1996 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
1997 cancel_work_sync(&priv->reset_wq);
1998 cancel_work_sync(&priv->qos_activate);
2001 static int _rtl92e_up(struct net_device *dev, bool is_silent_reset)
2003 if (_rtl92e_sta_up(dev, is_silent_reset) == -1)
2008 static int _rtl92e_open(struct net_device *dev)
2010 struct r8192_priv *priv = rtllib_priv(dev);
2013 mutex_lock(&priv->wx_mutex);
2014 ret = _rtl92e_try_up(dev);
2015 mutex_unlock(&priv->wx_mutex);
2019 static int _rtl92e_try_up(struct net_device *dev)
2021 struct r8192_priv *priv = rtllib_priv(dev);
2025 return _rtl92e_up(dev, false);
2028 static int _rtl92e_close(struct net_device *dev)
2030 struct r8192_priv *priv = rtllib_priv(dev);
2033 if ((rtllib_act_scanning(priv->rtllib, false)) &&
2034 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) {
2035 rtllib_stop_scan(priv->rtllib);
2038 mutex_lock(&priv->wx_mutex);
2040 ret = _rtl92e_down(dev, true);
2042 mutex_unlock(&priv->wx_mutex);
2047 static int _rtl92e_down(struct net_device *dev, bool shutdownrf)
2049 if (_rtl92e_sta_down(dev, shutdownrf) == -1)
2055 void rtl92e_commit(struct net_device *dev)
2057 struct r8192_priv *priv = rtllib_priv(dev);
2061 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
2062 rtl92e_irq_disable(dev);
2063 priv->ops->stop_adapter(dev, true);
2064 _rtl92e_up(dev, false);
2067 static void _rtl92e_restart(void *data)
2069 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2071 struct net_device *dev = priv->rtllib->dev;
2073 mutex_lock(&priv->wx_mutex);
2077 mutex_unlock(&priv->wx_mutex);
2080 static void _rtl92e_set_multicast(struct net_device *dev)
2082 struct r8192_priv *priv = rtllib_priv(dev);
2085 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2086 priv->promisc = promisc;
2089 static int _rtl92e_set_mac_adr(struct net_device *dev, void *mac)
2091 struct r8192_priv *priv = rtllib_priv(dev);
2092 struct sockaddr *addr = mac;
2094 mutex_lock(&priv->wx_mutex);
2096 eth_hw_addr_set(dev, addr->sa_data);
2098 schedule_work(&priv->reset_wq);
2099 mutex_unlock(&priv->wx_mutex);
2104 static irqreturn_t _rtl92e_irq(int irq, void *netdev)
2106 struct net_device *dev = netdev;
2107 struct r8192_priv *priv = rtllib_priv(dev);
2108 unsigned long flags;
2114 if (priv->irq_enabled == 0)
2117 spin_lock_irqsave(&priv->irq_th_lock, flags);
2119 priv->ops->interrupt_recognized(dev, &inta, &intb);
2122 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2126 if (inta == 0xffff) {
2127 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2131 if (!netif_running(dev)) {
2132 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2136 if (inta & IMR_MGNTDOK) {
2137 _rtl92e_tx_isr(dev, MGNT_QUEUE);
2138 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2139 if (priv->rtllib->ack_tx_to_ieee) {
2140 if (_rtl92e_is_tx_queue_empty(dev)) {
2141 priv->rtllib->ack_tx_to_ieee = 0;
2142 rtllib_ps_tx_ack(priv->rtllib, 1);
2145 spin_lock_irqsave(&priv->irq_th_lock, flags);
2148 if (inta & IMR_COMDOK)
2149 _rtl92e_tx_isr(dev, TXCMD_QUEUE);
2151 if (inta & IMR_HIGHDOK)
2152 _rtl92e_tx_isr(dev, HIGH_QUEUE);
2155 tasklet_schedule(&priv->irq_rx_tasklet);
2157 if (inta & IMR_BcnInt)
2158 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
2160 if (inta & IMR_RDU) {
2161 rtl92e_writel(dev, INTA_MASK,
2162 rtl92e_readl(dev, INTA_MASK) & ~IMR_RDU);
2163 tasklet_schedule(&priv->irq_rx_tasklet);
2166 if (inta & IMR_RXFOVW)
2167 tasklet_schedule(&priv->irq_rx_tasklet);
2169 if (inta & IMR_BKDOK) {
2170 priv->rtllib->link_detect_info.NumTxOkInPeriod++;
2171 _rtl92e_tx_isr(dev, BK_QUEUE);
2174 if (inta & IMR_BEDOK) {
2175 priv->rtllib->link_detect_info.NumTxOkInPeriod++;
2176 _rtl92e_tx_isr(dev, BE_QUEUE);
2179 if (inta & IMR_VIDOK) {
2180 priv->rtllib->link_detect_info.NumTxOkInPeriod++;
2181 _rtl92e_tx_isr(dev, VI_QUEUE);
2184 if (inta & IMR_VODOK) {
2185 priv->rtllib->link_detect_info.NumTxOkInPeriod++;
2186 _rtl92e_tx_isr(dev, VO_QUEUE);
2189 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2196 /****************************************************************************
2197 * ---------------------------- PCI_STUFF---------------------------
2198 ****************************************************************************/
2199 static const struct net_device_ops rtl8192_netdev_ops = {
2200 .ndo_open = _rtl92e_open,
2201 .ndo_stop = _rtl92e_close,
2202 .ndo_tx_timeout = _rtl92e_tx_timeout,
2203 .ndo_set_rx_mode = _rtl92e_set_multicast,
2204 .ndo_set_mac_address = _rtl92e_set_mac_adr,
2205 .ndo_validate_addr = eth_validate_addr,
2206 .ndo_start_xmit = rtllib_xmit,
2209 static int _rtl92e_pci_probe(struct pci_dev *pdev,
2210 const struct pci_device_id *id)
2212 unsigned long ioaddr = 0;
2213 struct net_device *dev = NULL;
2214 struct r8192_priv *priv = NULL;
2215 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2216 unsigned long pmem_start, pmem_len, pmem_flags;
2220 if (pci_enable_device(pdev)) {
2221 dev_err(&pdev->dev, "Failed to enable PCI device");
2225 pci_set_master(pdev);
2227 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
2228 if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32))) {
2229 dev_info(&pdev->dev,
2230 "Unable to obtain 32bit DMA for consistent allocations\n");
2231 goto err_pci_disable;
2234 dev = alloc_rtllib(sizeof(struct r8192_priv));
2236 goto err_pci_disable;
2240 pci_set_drvdata(pdev, dev);
2241 SET_NETDEV_DEV(dev, &pdev->dev);
2242 priv = rtllib_priv(dev);
2243 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
2245 priv->rtllib->pdev = pdev;
2246 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) &&
2247 (pdev->subsystem_device == 0x3304))
2248 priv->rtllib->bSupportRemoteWakeUp = 1;
2250 priv->rtllib->bSupportRemoteWakeUp = 0;
2252 pmem_start = pci_resource_start(pdev, 1);
2253 pmem_len = pci_resource_len(pdev, 1);
2254 pmem_flags = pci_resource_flags(pdev, 1);
2256 if (!(pmem_flags & IORESOURCE_MEM)) {
2257 netdev_err(dev, "region #1 not a MMIO resource, aborting");
2258 goto err_rel_rtllib;
2261 dev_info(&pdev->dev, "Memory mapped space start: 0x%08lx\n",
2263 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
2264 netdev_err(dev, "request_mem_region failed!");
2265 goto err_rel_rtllib;
2268 ioaddr = (unsigned long)ioremap(pmem_start, pmem_len);
2269 if (ioaddr == (unsigned long)NULL) {
2270 netdev_err(dev, "ioremap failed!");
2274 dev->mem_start = ioaddr;
2275 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
2277 pci_read_config_byte(pdev, 0x08, &revision_id);
2278 /* If the revisionid is 0x10, the device uses rtl8192se. */
2279 if (pdev->device == 0x8192 && revision_id == 0x10)
2284 if (!rtl92e_check_adapter(pdev, dev))
2287 dev->irq = pdev->irq;
2290 dev->netdev_ops = &rtl8192_netdev_ops;
2292 dev->wireless_handlers = &r8192_wx_handlers_def;
2293 dev->ethtool_ops = &rtl819x_ethtool_ops;
2295 dev->type = ARPHRD_ETHER;
2296 dev->watchdog_timeo = HZ * 3;
2298 if (dev_alloc_name(dev, ifname) < 0)
2299 dev_alloc_name(dev, ifname);
2301 if (_rtl92e_init(dev) != 0) {
2302 netdev_warn(dev, "Initialization failed");
2306 netif_carrier_off(dev);
2307 netif_stop_queue(dev);
2309 if (register_netdev(dev))
2312 if (priv->polling_timer_on == 0)
2313 rtl92e_check_rfctrl_gpio_timer(&priv->gpio_polling_timer);
2318 free_irq(dev->irq, dev);
2321 iounmap((void __iomem *)ioaddr);
2323 release_mem_region(pmem_start, pmem_len);
2327 pci_disable_device(pdev);
2331 static void _rtl92e_pci_disconnect(struct pci_dev *pdev)
2333 struct net_device *dev = pci_get_drvdata(pdev);
2334 struct r8192_priv *priv;
2338 unregister_netdev(dev);
2340 priv = rtllib_priv(dev);
2342 del_timer_sync(&priv->gpio_polling_timer);
2343 cancel_delayed_work_sync(&priv->gpio_change_rf_wq);
2344 priv->polling_timer_on = 0;
2345 _rtl92e_down(dev, true);
2346 rtl92e_dm_deinit(dev);
2347 vfree(priv->fw_info);
2348 priv->fw_info = NULL;
2349 _rtl92e_free_rx_ring(dev);
2350 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2351 _rtl92e_free_tx_ring(dev, i);
2354 dev_info(&pdev->dev, "Freeing irq %d\n", dev->irq);
2355 free_irq(dev->irq, dev);
2359 if (dev->mem_start != 0) {
2360 iounmap((void __iomem *)dev->mem_start);
2361 release_mem_region(pci_resource_start(pdev, 1),
2362 pci_resource_len(pdev, 1));
2368 pci_disable_device(pdev);
2371 bool rtl92e_enable_nic(struct net_device *dev)
2373 bool init_status = true;
2374 struct r8192_priv *priv = rtllib_priv(dev);
2375 struct rt_pwr_save_ctrl *psc = (struct rt_pwr_save_ctrl *)
2376 (&priv->rtllib->pwr_save_ctrl);
2379 netdev_warn(dev, "%s(): Driver is already down!\n", __func__);
2380 priv->bdisable_nic = false;
2384 init_status = priv->ops->initialize_adapter(dev);
2386 netdev_warn(dev, "%s(): Initialization failed!\n", __func__);
2387 priv->bdisable_nic = false;
2390 RT_CLEAR_PS_LEVEL(psc, RT_RF_OFF_LEVL_HALT_NIC);
2392 rtl92e_irq_enable(dev);
2393 priv->bdisable_nic = false;
2397 bool rtl92e_disable_nic(struct net_device *dev)
2399 struct r8192_priv *priv = rtllib_priv(dev);
2402 priv->bdisable_nic = true;
2403 tmp_state = priv->rtllib->state;
2404 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
2405 priv->rtllib->state = tmp_state;
2406 _rtl92e_cancel_deferred_work(priv);
2407 rtl92e_irq_disable(dev);
2409 priv->ops->stop_adapter(dev, false);
2413 module_pci_driver(rtl8192_pci_driver);
2415 void rtl92e_check_rfctrl_gpio_timer(struct timer_list *t)
2417 struct r8192_priv *priv = from_timer(priv, t, gpio_polling_timer);
2419 priv->polling_timer_on = 1;
2421 schedule_delayed_work(&priv->gpio_change_rf_wq, 0);
2423 mod_timer(&priv->gpio_polling_timer, jiffies +
2424 msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME));
2427 /***************************************************************************
2428 * ------------------- module init / exit stubs ----------------
2429 ***************************************************************************/
2430 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
2431 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
2432 MODULE_VERSION(DRV_VERSION);
2433 MODULE_LICENSE("GPL");
2434 MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW);
2435 MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW);
2436 MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW);
2438 module_param(ifname, charp, 0644);
2439 module_param(hwwep, int, 0644);
2441 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
2442 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");