1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * Based on the r8180 driver, which is:
5 * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com>
24 ******************************************************************************/
25 #undef RX_DONT_PASS_UL
27 #undef DEBUG_RX_VERBOSE
33 #undef DEBUG_TX_FILLDESC
38 #undef DEBUG_REGISTERS
40 #undef DEBUG_IRQ_TASKLET
44 #include <linux/uaccess.h>
45 #include <linux/pci.h>
46 #include <linux/vmalloc.h>
48 #include "r8192E_phy.h"
49 #include "r8192E_phyreg.h"
50 #include "r8190P_rtl8256.h"
51 #include "r8192E_cmdpkt.h"
59 static int channels = 0x3fff;
60 static char *ifname = "wlan%d";
63 static struct rtl819x_ops rtl819xp_ops = {
64 .nic_type = NIC_8192E,
65 .get_eeprom_size = rtl8192_get_eeprom_size,
66 .init_adapter_variable = rtl8192_InitializeVariables,
67 .initialize_adapter = rtl8192_adapter_start,
68 .link_change = rtl8192_link_change,
69 .tx_fill_descriptor = rtl8192_tx_fill_desc,
70 .tx_fill_cmd_descriptor = rtl8192_tx_fill_cmd_desc,
71 .rx_query_status_descriptor = rtl8192_rx_query_status_desc,
72 .rx_command_packet_handler = NULL,
73 .stop_adapter = rtl8192_halt_adapter,
74 .update_ratr_table = rtl8192_update_ratr_table,
75 .irq_enable = rtl8192_EnableInterrupt,
76 .irq_disable = rtl8192_DisableInterrupt,
77 .irq_clear = rtl8192_ClearInterrupt,
78 .rx_enable = rtl8192_enable_rx,
79 .tx_enable = rtl8192_enable_tx,
80 .interrupt_recognized = rtl8192_interrupt_recognized,
81 .TxCheckStuckHandler = rtl8192_HalTxCheckStuck,
82 .RxCheckStuckHandler = rtl8192_HalRxCheckStuck,
85 static struct pci_device_id rtl8192_pci_id_tbl[] = {
86 {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)},
87 {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)},
88 {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)},
92 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
94 static int rtl8192_pci_probe(struct pci_dev *pdev,
95 const struct pci_device_id *id);
96 static void rtl8192_pci_disconnect(struct pci_dev *pdev);
98 static struct pci_driver rtl8192_pci_driver = {
99 .name = DRV_NAME, /* Driver name */
100 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
101 .probe = rtl8192_pci_probe, /* probe fn */
102 .remove = rtl8192_pci_disconnect, /* remove fn */
103 .suspend = rtl8192E_suspend, /* PM suspend fn */
104 .resume = rtl8192E_resume, /* PM resume fn */
107 /****************************************************************************
108 -----------------------------IO STUFF-------------------------
109 *****************************************************************************/
110 static bool PlatformIOCheckPageLegalAndGetRegMask(u32 u4bPage, u8 *pu1bPageMask)
112 bool bReturn = false;
114 *pu1bPageMask = 0xfe;
117 case 1: case 2: case 3: case 4:
118 case 8: case 9: case 10: case 12: case 13:
120 *pu1bPageMask = 0xf0;
131 void write_nic_io_byte(struct net_device *dev, int x, u8 y)
133 u32 u4bPage = (x >> 8);
135 bool bIsLegalPage = false;
138 outb(y&0xff, dev->base_addr + x);
141 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
144 u8 u1bPsr = read_nic_io_byte(dev, PSR);
146 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
148 write_nic_io_byte(dev, (x & 0xff), y);
149 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
154 void write_nic_io_word(struct net_device *dev, int x, u16 y)
156 u32 u4bPage = (x >> 8);
158 bool bIsLegalPage = false;
161 outw(y, dev->base_addr + x);
163 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
166 u8 u1bPsr = read_nic_io_byte(dev, PSR);
168 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
170 write_nic_io_word(dev, (x & 0xff), y);
171 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
177 void write_nic_io_dword(struct net_device *dev, int x, u32 y)
179 u32 u4bPage = (x >> 8);
181 bool bIsLegalPage = false;
184 outl(y, dev->base_addr + x);
186 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
189 u8 u1bPsr = read_nic_io_byte(dev, PSR);
191 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
193 write_nic_io_dword(dev, (x & 0xff), y);
194 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
199 u8 read_nic_io_byte(struct net_device *dev, int x)
201 u32 u4bPage = (x >> 8);
203 bool bIsLegalPage = false;
207 return 0xff&inb(dev->base_addr + x);
209 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
212 u8 u1bPsr = read_nic_io_byte(dev, PSR);
214 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
216 Data = read_nic_io_byte(dev, (x & 0xff));
217 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
224 u16 read_nic_io_word(struct net_device *dev, int x)
226 u32 u4bPage = (x >> 8);
228 bool bIsLegalPage = false;
232 return inw(dev->base_addr + x);
234 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
237 u8 u1bPsr = read_nic_io_byte(dev, PSR);
239 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
241 Data = read_nic_io_word(dev, (x & 0xff));
242 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
250 u32 read_nic_io_dword(struct net_device *dev, int x)
252 u32 u4bPage = (x >> 8);
254 bool bIsLegalPage = false;
258 return inl(dev->base_addr + x);
260 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
263 u8 u1bPsr = read_nic_io_byte(dev, PSR);
265 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
267 Data = read_nic_io_dword(dev, (x & 0xff));
268 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
276 u8 read_nic_byte(struct net_device *dev, int x)
278 return 0xff & readb((u8 __iomem *)dev->mem_start + x);
281 u32 read_nic_dword(struct net_device *dev, int x)
283 return readl((u8 __iomem *)dev->mem_start + x);
286 u16 read_nic_word(struct net_device *dev, int x)
288 return readw((u8 __iomem *)dev->mem_start + x);
291 void write_nic_byte(struct net_device *dev, int x, u8 y)
293 writeb(y, (u8 __iomem *)dev->mem_start + x);
298 void write_nic_dword(struct net_device *dev, int x, u32 y)
300 writel(y, (u8 __iomem *)dev->mem_start + x);
305 void write_nic_word(struct net_device *dev, int x, u16 y)
307 writew(y, (u8 __iomem *)dev->mem_start + x);
312 /****************************************************************************
313 -----------------------------GENERAL FUNCTION-------------------------
314 *****************************************************************************/
315 bool MgntActSet_RF_State(struct net_device *dev,
316 enum rt_rf_power_state StateToSet,
317 RT_RF_CHANGE_SOURCE ChangeSource,
320 struct r8192_priv *priv = rtllib_priv(dev);
321 struct rtllib_device *ieee = priv->rtllib;
322 bool bActionAllowed = false;
323 bool bConnectBySSID = false;
324 enum rt_rf_power_state rtState;
325 u16 RFWaitCounter = 0;
327 RT_TRACE((COMP_PS | COMP_RF), "===>MgntActSet_RF_State(): "
328 "StateToSet(%d)\n", StateToSet);
330 ProtectOrNot = false;
335 spin_lock_irqsave(&priv->rf_ps_lock, flag);
336 if (priv->RFChangeInProgress) {
337 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
338 RT_TRACE((COMP_PS | COMP_RF),
339 "MgntActSet_RF_State(): RF Change in "
340 "progress! Wait to set..StateToSet"
341 "(%d).\n", StateToSet);
343 while (priv->RFChangeInProgress) {
345 RT_TRACE((COMP_PS | COMP_RF),
346 "MgntActSet_RF_State(): Wait 1"
347 " ms (%d times)...\n",
351 if (RFWaitCounter > 100) {
352 RT_TRACE(COMP_ERR, "MgntActSet_"
353 "RF_State(): Wait too "
359 priv->RFChangeInProgress = true;
360 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
366 rtState = priv->rtllib->eRFPowerState;
368 switch (StateToSet) {
370 priv->rtllib->RfOffReason &= (~ChangeSource);
372 if ((ChangeSource == RF_CHANGE_BY_HW) &&
373 (priv->bHwRadioOff == true))
374 priv->bHwRadioOff = false;
376 if (!priv->rtllib->RfOffReason) {
377 priv->rtllib->RfOffReason = 0;
378 bActionAllowed = true;
381 if (rtState == eRfOff &&
382 ChangeSource >= RF_CHANGE_BY_HW)
383 bConnectBySSID = true;
385 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State - "
386 "eRfon reject pMgntInfo->RfOffReason= 0x%x,"
387 " ChangeSource=0x%X\n",
388 priv->rtllib->RfOffReason, ChangeSource);
395 if ((priv->rtllib->iw_mode == IW_MODE_INFRA) ||
396 (priv->rtllib->iw_mode == IW_MODE_ADHOC)) {
397 if ((priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS) ||
398 (ChangeSource > RF_CHANGE_BY_IPS)) {
399 if (ieee->state == RTLLIB_LINKED)
400 priv->blinked_ingpio = true;
402 priv->blinked_ingpio = false;
403 rtllib_MgntDisconnect(priv->rtllib,
407 if ((ChangeSource == RF_CHANGE_BY_HW) &&
408 (priv->bHwRadioOff == false))
409 priv->bHwRadioOff = true;
410 priv->rtllib->RfOffReason |= ChangeSource;
411 bActionAllowed = true;
415 priv->rtllib->RfOffReason |= ChangeSource;
416 bActionAllowed = true;
423 if (bActionAllowed) {
424 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Action is"
425 " allowed.... StateToSet(%d), RfOffReason(%#X)\n",
426 StateToSet, priv->rtllib->RfOffReason);
427 PHY_SetRFPowerState(dev, StateToSet);
428 if (StateToSet == eRfOn) {
430 if (bConnectBySSID && (priv->blinked_ingpio == true)) {
431 queue_delayed_work_rsl(ieee->wq,
432 &ieee->associate_procedure_wq, 0);
433 priv->blinked_ingpio = false;
437 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): "
438 "Action is rejected.... StateToSet(%d), ChangeSource"
439 "(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource,
440 priv->rtllib->RfOffReason);
444 spin_lock_irqsave(&priv->rf_ps_lock, flag);
445 priv->RFChangeInProgress = false;
446 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
449 RT_TRACE((COMP_PS | COMP_RF), "<===MgntActSet_RF_State()\n");
450 return bActionAllowed;
454 static short rtl8192_get_nic_desc_num(struct net_device *dev, int prio)
456 struct r8192_priv *priv = rtllib_priv(dev);
457 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
459 /* For now, we reserved two free descriptor as a safety boundary
460 * between the tail and the head
462 if ((prio == MGNT_QUEUE) && (skb_queue_len(&ring->queue) > 10))
463 RT_TRACE(COMP_DBG, "-----[%d]---------ring->idx=%d "
464 "queue_len=%d---------\n", prio, ring->idx,
465 skb_queue_len(&ring->queue));
466 return skb_queue_len(&ring->queue);
469 static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
471 struct r8192_priv *priv = rtllib_priv(dev);
472 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
474 if (ring->entries - skb_queue_len(&ring->queue) >= 2)
479 void rtl8192_tx_timeout(struct net_device *dev)
481 struct r8192_priv *priv = rtllib_priv(dev);
483 schedule_work(&priv->reset_wq);
484 printk(KERN_INFO "TXTIMEOUT");
487 void rtl8192_irq_enable(struct net_device *dev)
489 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
490 priv->irq_enabled = 1;
492 priv->ops->irq_enable(dev);
495 void rtl8192_irq_disable(struct net_device *dev)
497 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
499 priv->ops->irq_disable(dev);
501 priv->irq_enabled = 0;
504 void rtl8192_set_chan(struct net_device *dev, short ch)
506 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
508 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
509 if (priv->chan_forced)
514 if (priv->rf_set_chan)
515 priv->rf_set_chan(dev, priv->chan);
518 void rtl8192_update_cap(struct net_device *dev, u16 cap)
520 struct r8192_priv *priv = rtllib_priv(dev);
521 struct rtllib_network *net = &priv->rtllib->current_network;
524 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) {
525 if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT) {
526 ShortPreamble = true;
527 priv->dot11CurrentPreambleMode = PREAMBLE_SHORT;
528 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_SHORT_"
529 "PREAMBLE\n", __func__);
530 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
531 (unsigned char *)&ShortPreamble);
534 if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG) {
535 ShortPreamble = false;
536 priv->dot11CurrentPreambleMode = PREAMBLE_LONG;
537 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_LONG_"
538 "PREAMBLE\n", __func__);
539 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
540 (unsigned char *)&ShortPreamble);
544 if (net->mode & (IEEE_G|IEEE_N_24G)) {
546 u8 CurSlotTime = priv->slot_time;
548 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
549 (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime)) {
550 if (CurSlotTime != SHORT_SLOT_TIME) {
551 slot_time_val = SHORT_SLOT_TIME;
552 priv->rtllib->SetHwRegHandler(dev,
553 HW_VAR_SLOT_TIME, &slot_time_val);
556 if (CurSlotTime != NON_SHORT_SLOT_TIME) {
557 slot_time_val = NON_SHORT_SLOT_TIME;
558 priv->rtllib->SetHwRegHandler(dev,
559 HW_VAR_SLOT_TIME, &slot_time_val);
565 static struct rtllib_qos_parameters def_qos_parameters = {
573 static void rtl8192_update_beacon(void *data)
575 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
576 update_beacon_wq.work);
577 struct net_device *dev = priv->rtllib->dev;
578 struct rtllib_device *ieee = priv->rtllib;
579 struct rtllib_network *net = &ieee->current_network;
581 if (ieee->pHTInfo->bCurrentHTSupport)
582 HT_update_self_and_peer_setting(ieee, net);
583 ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
584 net->bssht.bdRT2RTLongSlotTime;
585 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
586 rtl8192_update_cap(dev, net->capability);
589 int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
591 static void rtl8192_qos_activate(void *data)
593 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
595 struct net_device *dev = priv->rtllib->dev;
598 mutex_lock(&priv->mutex);
599 if (priv->rtllib->state != RTLLIB_LINKED)
601 RT_TRACE(COMP_QOS, "qos active process with associate response "
604 for (i = 0; i < QOS_QUEUE_NUM; i++) {
605 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i));
609 mutex_unlock(&priv->mutex);
612 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
614 struct rtllib_network *network)
617 u32 size = sizeof(struct rtllib_qos_parameters);
619 if (priv->rtllib->state != RTLLIB_LINKED)
622 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
625 if (network->flags & NETWORK_HAS_QOS_MASK) {
626 if (active_network &&
627 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
628 network->qos_data.active = network->qos_data.supported;
630 if ((network->qos_data.active == 1) && (active_network == 1) &&
631 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
632 (network->qos_data.old_param_count !=
633 network->qos_data.param_count)) {
634 network->qos_data.old_param_count =
635 network->qos_data.param_count;
636 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
637 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
638 RT_TRACE(COMP_QOS, "QoS parameters change call "
642 memcpy(&priv->rtllib->current_network.qos_data.parameters,
643 &def_qos_parameters, size);
645 if ((network->qos_data.active == 1) && (active_network == 1)) {
646 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
647 RT_TRACE(COMP_QOS, "QoS was disabled call qos_"
650 network->qos_data.active = 0;
651 network->qos_data.supported = 0;
657 static int rtl8192_handle_beacon(struct net_device *dev,
658 struct rtllib_beacon *beacon,
659 struct rtllib_network *network)
661 struct r8192_priv *priv = rtllib_priv(dev);
663 rtl8192_qos_handle_probe_response(priv, 1, network);
665 queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
670 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
671 struct rtllib_network *network)
675 u32 size = sizeof(struct rtllib_qos_parameters);
676 int set_qos_param = 0;
678 if ((priv == NULL) || (network == NULL))
681 if (priv->rtllib->state != RTLLIB_LINKED)
684 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
687 spin_lock_irqsave(&priv->rtllib->lock, flags);
688 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
689 memcpy(&priv->rtllib->current_network.qos_data.parameters,
690 &network->qos_data.parameters,
691 sizeof(struct rtllib_qos_parameters));
692 priv->rtllib->current_network.qos_data.active = 1;
693 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
695 priv->rtllib->current_network.qos_data.old_param_count =
696 priv->rtllib->current_network.qos_data.param_count;
697 priv->rtllib->current_network.qos_data.param_count =
698 network->qos_data.param_count;
700 memcpy(&priv->rtllib->current_network.qos_data.parameters,
701 &def_qos_parameters, size);
702 priv->rtllib->current_network.qos_data.active = 0;
703 priv->rtllib->current_network.qos_data.supported = 0;
707 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
709 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
710 network->flags, priv->rtllib->current_network.qos_data.active);
711 if (set_qos_param == 1) {
712 dm_init_edca_turbo(priv->rtllib->dev);
713 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
718 static int rtl8192_handle_assoc_response(struct net_device *dev,
719 struct rtllib_assoc_response_frame *resp,
720 struct rtllib_network *network)
722 struct r8192_priv *priv = rtllib_priv(dev);
723 rtl8192_qos_association_resp(priv, network);
727 static void rtl8192_prepare_beacon(struct r8192_priv *priv)
729 struct net_device *dev = priv->rtllib->dev;
730 struct sk_buff *pskb = NULL, *pnewskb = NULL;
731 struct cb_desc *tcb_desc = NULL;
732 struct rtl8192_tx_ring *ring = NULL;
733 struct tx_desc *pdesc = NULL;
735 ring = &priv->tx_ring[BEACON_QUEUE];
736 pskb = __skb_dequeue(&ring->queue);
739 pnewskb = rtllib_get_beacon(priv->rtllib);
743 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
744 tcb_desc->queue_index = BEACON_QUEUE;
745 tcb_desc->data_rate = 2;
746 tcb_desc->RATRIndex = 7;
747 tcb_desc->bTxDisableRateFallBack = 1;
748 tcb_desc->bTxUseDriverAssingedRate = 1;
749 skb_push(pnewskb, priv->rtllib->tx_headroom);
751 pdesc = &ring->desc[0];
752 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
753 __skb_queue_tail(&ring->queue, pnewskb);
759 static void rtl8192_stop_beacon(struct net_device *dev)
763 void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
765 struct r8192_priv *priv = rtllib_priv(dev);
766 struct rtllib_network *net;
767 u8 i = 0, basic_rate = 0;
768 net = &priv->rtllib->current_network;
770 for (i = 0; i < net->rates_len; i++) {
771 basic_rate = net->rates[i] & 0x7f;
772 switch (basic_rate) {
774 *rate_config |= RRSR_1M;
777 *rate_config |= RRSR_2M;
780 *rate_config |= RRSR_5_5M;
783 *rate_config |= RRSR_11M;
786 *rate_config |= RRSR_6M;
789 *rate_config |= RRSR_9M;
792 *rate_config |= RRSR_12M;
795 *rate_config |= RRSR_18M;
798 *rate_config |= RRSR_24M;
801 *rate_config |= RRSR_36M;
804 *rate_config |= RRSR_48M;
807 *rate_config |= RRSR_54M;
812 for (i = 0; i < net->rates_ex_len; i++) {
813 basic_rate = net->rates_ex[i] & 0x7f;
814 switch (basic_rate) {
816 *rate_config |= RRSR_1M;
819 *rate_config |= RRSR_2M;
822 *rate_config |= RRSR_5_5M;
825 *rate_config |= RRSR_11M;
828 *rate_config |= RRSR_6M;
831 *rate_config |= RRSR_9M;
834 *rate_config |= RRSR_12M;
837 *rate_config |= RRSR_18M;
840 *rate_config |= RRSR_24M;
843 *rate_config |= RRSR_36M;
846 *rate_config |= RRSR_48M;
849 *rate_config |= RRSR_54M;
855 static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
857 struct rtllib_device *ieee = priv->rtllib;
858 if (ieee->mode == WIRELESS_MODE_N_24G ||
859 ieee->mode == WIRELESS_MODE_N_5G) {
860 memcpy(ieee->Regdot11HTOperationalRateSet,
861 ieee->RegHTSuppRateSet, 16);
862 memcpy(ieee->Regdot11TxHTOperationalRateSet,
863 ieee->RegHTSuppRateSet, 16);
866 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
871 static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
873 struct r8192_priv *priv = rtllib_priv(dev);
876 switch (priv->rf_chip) {
881 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B);
884 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
887 ret = WIRELESS_MODE_B;
893 void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
895 struct r8192_priv *priv = rtllib_priv(dev);
896 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
898 if ((wireless_mode == WIRELESS_MODE_AUTO) ||
899 ((wireless_mode & bSupportMode) == 0)) {
900 if (bSupportMode & WIRELESS_MODE_N_24G) {
901 wireless_mode = WIRELESS_MODE_N_24G;
902 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
903 wireless_mode = WIRELESS_MODE_N_5G;
904 } else if ((bSupportMode & WIRELESS_MODE_A)) {
905 wireless_mode = WIRELESS_MODE_A;
906 } else if ((bSupportMode & WIRELESS_MODE_G)) {
907 wireless_mode = WIRELESS_MODE_G;
908 } else if ((bSupportMode & WIRELESS_MODE_B)) {
909 wireless_mode = WIRELESS_MODE_B;
911 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode "
912 "supported (%x)!!!\n", __func__, bSupportMode);
913 wireless_mode = WIRELESS_MODE_B;
917 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) ==
918 (WIRELESS_MODE_G | WIRELESS_MODE_B))
919 wireless_mode = WIRELESS_MODE_G;
921 priv->rtllib->mode = wireless_mode;
923 ActUpdateChannelAccessSetting(dev, wireless_mode,
924 &priv->ChannelAccessSetting);
926 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
927 (wireless_mode == WIRELESS_MODE_N_5G)) {
928 priv->rtllib->pHTInfo->bEnableHT = 1;
929 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n",
930 __func__, wireless_mode);
932 priv->rtllib->pHTInfo->bEnableHT = 0;
933 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n",
934 __func__, wireless_mode);
937 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
938 rtl8192_refresh_supportrate(priv);
941 static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
943 struct r8192_priv *priv = rtllib_priv(dev);
944 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
945 (&(priv->rtllib->PowerSaveControl));
946 bool init_status = true;
947 priv->bDriverIsGoingToUnload = false;
948 priv->bdisable_nic = false;
951 priv->rtllib->ieee_up = 1;
953 priv->up_first_time = 0;
954 RT_TRACE(COMP_INIT, "Bringing up iface");
955 priv->bfirst_init = true;
956 init_status = priv->ops->initialize_adapter(dev);
957 if (init_status != true) {
958 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
960 priv->bfirst_init = false;
964 RT_TRACE(COMP_INIT, "start adapter finished\n");
965 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
966 priv->bfirst_init = false;
968 if (priv->polling_timer_on == 0)
969 check_rfctrl_gpio_timer((unsigned long)dev);
971 if (priv->rtllib->state != RTLLIB_LINKED)
972 rtllib_softmac_start_protocol(priv->rtllib, 0);
973 rtllib_reset_queue(priv->rtllib);
974 watch_dog_timer_callback((unsigned long) dev);
976 if (!netif_queue_stopped(dev))
977 netif_start_queue(dev);
979 netif_wake_queue(dev);
984 static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
986 struct r8192_priv *priv = rtllib_priv(dev);
987 unsigned long flags = 0;
988 u8 RFInProgressTimeOut = 0;
993 if (priv->rtllib->rtllib_ips_leave != NULL)
994 priv->rtllib->rtllib_ips_leave(dev);
996 if (priv->rtllib->state == RTLLIB_LINKED)
999 priv->bDriverIsGoingToUnload = true;
1001 priv->rtllib->ieee_up = 0;
1002 priv->bfirst_after_down = 1;
1003 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
1004 if (!netif_queue_stopped(dev))
1005 netif_stop_queue(dev);
1007 priv->rtllib->wpa_ie_len = 0;
1008 kfree(priv->rtllib->wpa_ie);
1009 priv->rtllib->wpa_ie = NULL;
1010 CamResetAllEntry(dev);
1011 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1012 rtl8192_irq_disable(dev);
1014 del_timer_sync(&priv->watch_dog_timer);
1015 rtl8192_cancel_deferred_work(priv);
1016 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
1018 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1019 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1020 while (priv->RFChangeInProgress) {
1021 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1022 if (RFInProgressTimeOut > 100) {
1023 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1026 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait "
1027 "until rf change is done.\n", __func__);
1029 RFInProgressTimeOut++;
1030 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1032 priv->RFChangeInProgress = true;
1033 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1034 priv->ops->stop_adapter(dev, false);
1035 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1036 priv->RFChangeInProgress = false;
1037 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1039 memset(&priv->rtllib->current_network, 0,
1040 offsetof(struct rtllib_network, list));
1041 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
1046 static void rtl8192_init_priv_handler(struct net_device *dev)
1048 struct r8192_priv *priv = rtllib_priv(dev);
1050 priv->rtllib->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
1051 priv->rtllib->set_chan = rtl8192_set_chan;
1052 priv->rtllib->link_change = priv->ops->link_change;
1053 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1054 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1055 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1056 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1057 priv->rtllib->get_nic_desc_num = rtl8192_get_nic_desc_num;
1058 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1059 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1060 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode;
1061 priv->rtllib->LeisurePSLeave = LeisurePSLeave;
1062 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode;
1063 priv->rf_set_chan = rtl8192_phy_SwChnl;
1065 priv->rtllib->start_send_beacons = rtl8192e_start_beacon;
1066 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
1068 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup;
1069 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep;
1070 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1072 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg;
1073 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
1074 rtl8192_GetHalfNmodeSupportByAPs;
1076 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg;
1077 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr;
1078 priv->rtllib->SetFwCmdHandler = NULL;
1079 priv->rtllib->InitialGainHandler = InitialGain819xPci;
1080 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq;
1081 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave;
1083 priv->rtllib->LedControlHandler = NULL;
1084 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1086 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192;
1088 priv->rtllib->rtllib_rfkill_poll = NULL;
1091 static void rtl8192_init_priv_constant(struct net_device *dev)
1093 struct r8192_priv *priv = rtllib_priv(dev);
1094 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1095 &(priv->rtllib->PowerSaveControl);
1097 pPSC->RegMaxLPSAwakeIntvl = 5;
1099 priv->RegPciASPM = 2;
1101 priv->RegDevicePciASPMSetting = 0x03;
1103 priv->RegHostPciASPMSetting = 0x02;
1105 priv->RegHwSwRfOffD3 = 2;
1107 priv->RegSupportPciASPM = 2;
1111 static void rtl8192_init_priv_variable(struct net_device *dev)
1113 struct r8192_priv *priv = rtllib_priv(dev);
1116 priv->AcmMethod = eAcmWay2_SW;
1117 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
1118 priv->rtllib->hwscan_sem_up = 1;
1119 priv->rtllib->status = 0;
1120 priv->H2CTxCmdSeq = 0;
1121 priv->bDisableFrameBursting = 0;
1122 priv->bDMInitialGainEnable = 1;
1123 priv->polling_timer_on = 0;
1124 priv->up_first_time = 1;
1125 priv->blinked_ingpio = false;
1126 priv->bDriverIsGoingToUnload = false;
1127 priv->being_init_adapter = false;
1128 priv->initialized_at_probe = false;
1129 priv->sw_radio_on = true;
1130 priv->bdisable_nic = false;
1131 priv->bfirst_init = false;
1132 priv->txringcount = 64;
1133 priv->rxbuffersize = 9100;
1134 priv->rxringcount = MAX_RX_COUNT;
1135 priv->irq_enabled = 0;
1137 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
1138 priv->RegChannelPlan = 0xf;
1139 priv->nrxAMPDU_size = 0;
1140 priv->nrxAMPDU_aggr_num = 0;
1141 priv->last_rxdesc_tsf_high = 0;
1142 priv->last_rxdesc_tsf_low = 0;
1143 priv->rtllib->mode = WIRELESS_MODE_AUTO;
1144 priv->rtllib->iw_mode = IW_MODE_INFRA;
1145 priv->rtllib->bNetPromiscuousMode = false;
1146 priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false;
1147 priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1149 priv->rtllib->ieee_up = 0;
1150 priv->retry_rts = DEFAULT_RETRY_RTS;
1151 priv->retry_data = DEFAULT_RETRY_DATA;
1152 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
1153 priv->rtllib->rate = 110;
1154 priv->rtllib->short_slot = 1;
1155 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
1156 priv->bcck_in_ch14 = false;
1157 priv->bfsync_processing = false;
1158 priv->CCKPresentAttentuation = 0;
1159 priv->rfa_txpowertrackingindex = 0;
1160 priv->rfc_txpowertrackingindex = 0;
1162 priv->ScanDelay = 50;
1163 priv->ResetProgress = RESET_TYPE_NORESET;
1164 priv->bForcedSilentReset = 0;
1165 priv->bDisableNormalResetCheck = false;
1166 priv->force_reset = false;
1167 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1169 memset(&priv->InterruptLog, 0, sizeof(struct log_int_8190));
1170 priv->RxCounter = 0;
1171 priv->rtllib->wx_set_enc = 0;
1172 priv->bHwRadioOff = false;
1174 priv->isRFOff = false;
1175 priv->bInPowerSaveMode = false;
1176 priv->rtllib->RfOffReason = 0;
1177 priv->RFChangeInProgress = false;
1178 priv->bHwRfOffAction = 0;
1179 priv->SetRFPowerStateInProgress = false;
1180 priv->rtllib->PowerSaveControl.bInactivePs = true;
1181 priv->rtllib->PowerSaveControl.bIPSModeBackup = false;
1182 priv->rtllib->PowerSaveControl.bLeisurePs = true;
1183 priv->rtllib->PowerSaveControl.bFwCtrlLPS = false;
1184 priv->rtllib->LPSDelayCnt = 0;
1185 priv->rtllib->sta_sleep = LPS_IS_WAKE;
1186 priv->rtllib->eRFPowerState = eRfOn;
1188 priv->txpower_checkcnt = 0;
1189 priv->thermal_readback_index = 0;
1190 priv->txpower_tracking_callback_cnt = 0;
1191 priv->ccktxpower_adjustcnt_ch14 = 0;
1192 priv->ccktxpower_adjustcnt_not_ch14 = 0;
1194 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
1195 priv->rtllib->iw_mode = IW_MODE_INFRA;
1196 priv->rtllib->active_scan = 1;
1197 priv->rtllib->be_scan_inprogress = false;
1198 priv->rtllib->modulation = RTLLIB_CCK_MODULATION |
1199 RTLLIB_OFDM_MODULATION;
1200 priv->rtllib->host_encrypt = 1;
1201 priv->rtllib->host_decrypt = 1;
1203 priv->rtllib->dot11PowerSaveMode = eActive;
1204 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
1205 priv->rtllib->MaxMssDensity = 0;
1206 priv->rtllib->MinSpaceCfg = 0;
1208 priv->card_type = PCI;
1210 priv->AcmControl = 0;
1211 priv->pFirmware = vzalloc(sizeof(struct rt_firmware));
1212 if (!priv->pFirmware)
1213 printk(KERN_ERR "rtl8192e: Unable to allocate space "
1216 skb_queue_head_init(&priv->rx_queue);
1217 skb_queue_head_init(&priv->skb_queue);
1219 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1220 skb_queue_head_init(&priv->rtllib->skb_waitQ[i]);
1221 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1222 skb_queue_head_init(&priv->rtllib->skb_aggQ[i]);
1225 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
1227 spin_lock_init(&priv->fw_scan_lock);
1228 spin_lock_init(&priv->tx_lock);
1229 spin_lock_init(&priv->irq_lock);
1230 spin_lock_init(&priv->irq_th_lock);
1231 spin_lock_init(&priv->rf_ps_lock);
1232 spin_lock_init(&priv->ps_lock);
1233 spin_lock_init(&priv->rf_lock);
1234 spin_lock_init(&priv->rt_h2c_lock);
1235 sema_init(&priv->wx_sem, 1);
1236 sema_init(&priv->rf_sem, 1);
1237 mutex_init(&priv->mutex);
1240 static void rtl8192_init_priv_task(struct net_device *dev)
1242 struct r8192_priv *priv = rtllib_priv(dev);
1244 priv->priv_wq = create_workqueue(DRV_NAME);
1245 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
1246 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)IPSLeave_wq, dev);
1247 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
1248 (void *)rtl819x_watchdog_wqcallback, dev);
1249 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
1250 (void *)dm_txpower_trackingcallback, dev);
1251 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
1252 (void *)dm_rf_pathcheck_workitemcallback, dev);
1253 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
1254 (void *)rtl8192_update_beacon, dev);
1255 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
1256 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
1257 (void *) rtl8192_hw_wakeup_wq, dev);
1258 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
1259 (void *) rtl8192_hw_sleep_wq, dev);
1260 tasklet_init(&priv->irq_rx_tasklet,
1261 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1262 (unsigned long)priv);
1263 tasklet_init(&priv->irq_tx_tasklet,
1264 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
1265 (unsigned long)priv);
1266 tasklet_init(&priv->irq_prepare_beacon_tasklet,
1267 (void(*)(unsigned long))rtl8192_prepare_beacon,
1268 (unsigned long)priv);
1271 static short rtl8192_get_channel_map(struct net_device *dev)
1275 struct r8192_priv *priv = rtllib_priv(dev);
1276 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256)
1277 && (priv->rf_chip != RF_6052)) {
1278 RT_TRACE(COMP_ERR, "%s: unknown rf chip, can't set channel "
1283 if (priv->ChannelPlan >= COUNTRY_CODE_MAX) {
1284 printk(KERN_INFO "rtl819x_init:Error channel plan! Set to "
1286 priv->ChannelPlan = COUNTRY_CODE_FCC;
1288 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
1289 dot11d_init(priv->rtllib);
1290 Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib);
1291 for (i = 1; i <= 11; i++)
1292 (priv->rtllib->active_channel_map)[i] = 1;
1293 (priv->rtllib->active_channel_map)[12] = 2;
1294 (priv->rtllib->active_channel_map)[13] = 2;
1299 static short rtl8192_init(struct net_device *dev)
1301 struct r8192_priv *priv = rtllib_priv(dev);
1303 memset(&(priv->stats), 0, sizeof(struct rt_stats));
1305 rtl8192_init_priv_handler(dev);
1306 rtl8192_init_priv_constant(dev);
1307 rtl8192_init_priv_variable(dev);
1308 rtl8192_init_priv_lock(priv);
1309 rtl8192_init_priv_task(dev);
1310 priv->ops->get_eeprom_size(dev);
1311 priv->ops->init_adapter_variable(dev);
1312 rtl8192_get_channel_map(dev);
1316 init_timer(&priv->watch_dog_timer);
1317 setup_timer(&priv->watch_dog_timer,
1318 watch_dog_timer_callback,
1319 (unsigned long) dev);
1321 init_timer(&priv->gpio_polling_timer);
1322 setup_timer(&priv->gpio_polling_timer,
1323 check_rfctrl_gpio_timer,
1324 (unsigned long)dev);
1326 rtl8192_irq_disable(dev);
1327 if (request_irq(dev->irq, (void *)rtl8192_interrupt_rsl, IRQF_SHARED,
1329 printk(KERN_ERR "Error allocating IRQ %d", dev->irq);
1332 priv->irq = dev->irq;
1333 RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq);
1336 if (rtl8192_pci_initdescring(dev) != 0) {
1337 printk(KERN_ERR "Endopoints initialization failed");
1338 free_irq(dev->irq, dev);
1345 /***************************************************************************
1346 -------------------------------WATCHDOG STUFF---------------------------
1347 ***************************************************************************/
1348 short rtl8192_is_tx_queue_empty(struct net_device *dev)
1351 struct r8192_priv *priv = rtllib_priv(dev);
1352 for (i = 0; i <= MGNT_QUEUE; i++) {
1353 if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE))
1355 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) {
1356 printk(KERN_INFO "===>tx queue is not empty:%d, %d\n",
1357 i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1364 static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
1366 struct r8192_priv *priv = rtllib_priv(dev);
1368 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1369 bool bCheckFwTxCnt = false;
1370 struct rtl8192_tx_ring *ring = NULL;
1371 struct sk_buff *skb = NULL;
1372 struct cb_desc *tcb_desc = NULL;
1373 unsigned long flags = 0;
1375 switch (priv->rtllib->ps) {
1376 case RTLLIB_PS_DISABLED:
1377 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
1379 case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
1380 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1383 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1386 spin_lock_irqsave(&priv->irq_th_lock, flags);
1387 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) {
1388 if (QueueID == TXCMD_QUEUE)
1391 if (QueueID == BEACON_QUEUE)
1394 ring = &priv->tx_ring[QueueID];
1396 if (skb_queue_len(&ring->queue) == 0) {
1399 skb = (&ring->queue)->next;
1400 tcb_desc = (struct cb_desc *)(skb->cb +
1402 tcb_desc->nStuckCount++;
1403 bCheckFwTxCnt = true;
1404 if (tcb_desc->nStuckCount > 1)
1405 printk(KERN_INFO "%s: QueueID=%d tcb_desc->n"
1406 "StuckCount=%d\n", __func__, QueueID,
1407 tcb_desc->nStuckCount);
1410 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1412 if (bCheckFwTxCnt) {
1413 if (priv->ops->TxCheckStuckHandler(dev)) {
1414 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no"
1415 " Tx condition!\n");
1416 return RESET_TYPE_SILENT;
1420 return RESET_TYPE_NORESET;
1423 static enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
1425 struct r8192_priv *priv = rtllib_priv(dev);
1427 if (priv->ops->RxCheckStuckHandler(dev)) {
1428 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
1429 return RESET_TYPE_SILENT;
1432 return RESET_TYPE_NORESET;
1435 static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
1437 struct r8192_priv *priv = rtllib_priv(dev);
1438 enum reset_type TxResetType = RESET_TYPE_NORESET;
1439 enum reset_type RxResetType = RESET_TYPE_NORESET;
1440 enum rt_rf_power_state rfState;
1442 rfState = priv->rtllib->eRFPowerState;
1444 if (rfState == eRfOn)
1445 TxResetType = rtl819x_TxCheckStuck(dev);
1447 if (rfState == eRfOn &&
1448 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1449 (priv->rtllib->state == RTLLIB_LINKED))
1450 RxResetType = rtl819x_RxCheckStuck(dev);
1452 if (TxResetType == RESET_TYPE_NORMAL ||
1453 RxResetType == RESET_TYPE_NORMAL) {
1454 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1455 __func__, TxResetType, RxResetType);
1456 return RESET_TYPE_NORMAL;
1457 } else if (TxResetType == RESET_TYPE_SILENT ||
1458 RxResetType == RESET_TYPE_SILENT) {
1459 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1460 __func__, TxResetType, RxResetType);
1461 return RESET_TYPE_SILENT;
1463 return RESET_TYPE_NORESET;
1468 static void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
1472 static void rtl819x_ifsilentreset(struct net_device *dev)
1474 struct r8192_priv *priv = rtllib_priv(dev);
1476 int reset_status = 0;
1477 struct rtllib_device *ieee = priv->rtllib;
1483 if (priv->ResetProgress == RESET_TYPE_NORESET) {
1485 RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
1487 priv->ResetProgress = RESET_TYPE_SILENT;
1489 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1490 if (priv->RFChangeInProgress) {
1491 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1494 priv->RFChangeInProgress = true;
1495 priv->bResetInProgress = true;
1496 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1500 down(&priv->wx_sem);
1502 if (priv->rtllib->state == RTLLIB_LINKED)
1503 LeisurePSLeave(dev);
1505 if (IS_NIC_DOWN(priv)) {
1506 RT_TRACE(COMP_ERR, "%s():the driver is not up! "
1507 "return\n", __func__);
1513 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n",
1516 RT_TRACE(COMP_RESET, "%s():111111111111111111111111======>start"
1517 " to down the driver\n", __func__);
1519 if (!netif_queue_stopped(dev))
1520 netif_stop_queue(dev);
1522 rtl8192_irq_disable(dev);
1523 del_timer_sync(&priv->watch_dog_timer);
1524 rtl8192_cancel_deferred_work(priv);
1526 rtllib_stop_scan_syncro(ieee);
1528 if (ieee->state == RTLLIB_LINKED) {
1529 SEM_DOWN_IEEE_WX(&ieee->wx_sem);
1530 printk(KERN_INFO "ieee->state is RTLLIB_LINKED\n");
1531 rtllib_stop_send_beacons(priv->rtllib);
1532 del_timer_sync(&ieee->associate_timer);
1533 cancel_delayed_work(&ieee->associate_retry_wq);
1534 rtllib_stop_scan(ieee);
1535 netif_carrier_off(dev);
1536 SEM_UP_IEEE_WX(&ieee->wx_sem);
1538 printk(KERN_INFO "ieee->state is NOT LINKED\n");
1539 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
1542 dm_backup_dynamic_mechanism_state(dev);
1545 RT_TRACE(COMP_RESET, "%s():<==========down process is "
1546 "finished\n", __func__);
1548 RT_TRACE(COMP_RESET, "%s():<===========up process start\n",
1550 reset_status = _rtl8192_up(dev, true);
1552 RT_TRACE(COMP_RESET, "%s():<===========up process is "
1553 "finished\n", __func__);
1554 if (reset_status == -1) {
1555 if (reset_times < 3) {
1559 RT_TRACE(COMP_ERR, " ERR!!! %s(): Reset "
1560 "Failed!!\n", __func__);
1564 ieee->is_silent_reset = 1;
1566 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1567 priv->RFChangeInProgress = false;
1568 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1570 EnableHWSecurityConfig8192(dev);
1572 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1574 ieee->set_chan(ieee->dev,
1575 ieee->current_network.channel);
1577 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1579 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1581 ieee->set_chan(ieee->dev,
1582 ieee->current_network.channel);
1583 ieee->link_change(ieee->dev);
1585 notify_wx_assoc_event(ieee);
1587 rtllib_start_send_beacons(ieee);
1589 if (ieee->data_hard_resume)
1590 ieee->data_hard_resume(ieee->dev);
1591 netif_carrier_on(ieee->dev);
1592 } else if (ieee->iw_mode == IW_MODE_MESH) {
1593 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1596 CamRestoreAllEntry(dev);
1597 dm_restore_dynamic_mechanism_state(dev);
1599 priv->ResetProgress = RESET_TYPE_NORESET;
1600 priv->reset_count++;
1602 priv->bForcedSilentReset = false;
1603 priv->bResetInProgress = false;
1605 write_nic_byte(dev, UFWP, 1);
1606 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n",
1611 static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1612 u32 *TotalRxDataNum)
1618 *TotalRxDataNum = 0;
1620 SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++) %
1621 (priv->rtllib->LinkDetectInfo.SlotNum);
1622 priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] =
1623 priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod;
1624 priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] =
1625 priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod;
1626 for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) {
1627 *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i];
1628 *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i];
1633 void rtl819x_watchdog_wqcallback(void *data)
1635 struct r8192_priv *priv = container_of_dwork_rsl(data,
1636 struct r8192_priv, watch_dog_wq);
1637 struct net_device *dev = priv->rtllib->dev;
1638 struct rtllib_device *ieee = priv->rtllib;
1639 enum reset_type ResetType = RESET_TYPE_NORESET;
1640 static u8 check_reset_cnt;
1641 unsigned long flags;
1642 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1643 (&(priv->rtllib->PowerSaveControl));
1644 bool bBusyTraffic = false;
1645 bool bHigherBusyTraffic = false;
1646 bool bHigherBusyRxTraffic = false;
1647 bool bEnterPS = false;
1649 if (IS_NIC_DOWN(priv) || (priv->bHwRadioOff == true))
1652 if (priv->rtllib->state >= RTLLIB_LINKED) {
1653 if (priv->rtllib->CntAfterLink < 2)
1654 priv->rtllib->CntAfterLink++;
1656 priv->rtllib->CntAfterLink = 0;
1659 hal_dm_watchdog(dev);
1661 if (rtllib_act_scanning(priv->rtllib, false) == false) {
1662 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
1664 (ieee->eRFPowerState == eRfOn) && !ieee->is_set_key &&
1665 (!ieee->proto_stoppping) && !ieee->wx_set_enc) {
1666 if ((ieee->PowerSaveControl.ReturnPoint ==
1667 IPS_CALLBACK_NONE) &&
1668 (!ieee->bNetPromiscuousMode)) {
1669 RT_TRACE(COMP_PS, "====================>haha: "
1675 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode ==
1676 IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode)) {
1677 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 100 ||
1678 ieee->LinkDetectInfo.NumTxOkInPeriod > 100)
1679 bBusyTraffic = true;
1682 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1683 ieee->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1684 bHigherBusyTraffic = true;
1685 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000)
1686 bHigherBusyRxTraffic = true;
1688 bHigherBusyRxTraffic = false;
1691 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1692 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1693 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1698 if (ieee->current_network.beacon_interval < 95)
1702 LeisurePSEnter(dev);
1704 LeisurePSLeave(dev);
1707 RT_TRACE(COMP_LPS, "====>no link LPS leave\n");
1708 LeisurePSLeave(dev);
1711 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
1712 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
1713 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1714 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1716 ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1717 ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1719 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1720 u32 TotalRxBcnNum = 0;
1721 u32 TotalRxDataNum = 0;
1723 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
1725 if ((TotalRxBcnNum+TotalRxDataNum) == 0)
1726 priv->check_roaming_cnt++;
1728 priv->check_roaming_cnt = 0;
1731 if (priv->check_roaming_cnt > 0) {
1732 if (ieee->eRFPowerState == eRfOff)
1733 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
1735 printk(KERN_INFO "===>%s(): AP is power off, chan:%d,"
1736 " connect another one\n", __func__, priv->chan);
1738 ieee->state = RTLLIB_ASSOCIATING;
1740 RemovePeerTS(priv->rtllib,
1741 priv->rtllib->current_network.bssid);
1742 ieee->is_roaming = true;
1743 ieee->is_set_key = false;
1744 ieee->link_change(dev);
1745 if (ieee->LedControlHandler)
1746 ieee->LedControlHandler(ieee->dev,
1747 LED_CTL_START_TO_LINK);
1749 notify_wx_assoc_event(ieee);
1751 if (!(ieee->rtllib_ap_sec_type(ieee) &
1752 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
1753 queue_delayed_work_rsl(ieee->wq,
1754 &ieee->associate_procedure_wq, 0);
1756 priv->check_roaming_cnt = 0;
1758 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
1759 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
1763 spin_lock_irqsave(&priv->tx_lock, flags);
1764 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1765 (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) {
1766 ResetType = rtl819x_ifcheck_resetornot(dev);
1767 check_reset_cnt = 3;
1769 spin_unlock_irqrestore(&priv->tx_lock, flags);
1771 if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) {
1772 priv->ResetProgress = RESET_TYPE_NORMAL;
1773 RT_TRACE(COMP_RESET, "%s(): NOMAL RESET\n", __func__);
1777 if (((priv->force_reset) || (!priv->bDisableNormalResetCheck &&
1778 ResetType == RESET_TYPE_SILENT)))
1779 rtl819x_ifsilentreset(dev);
1780 priv->force_reset = false;
1781 priv->bForcedSilentReset = false;
1782 priv->bResetInProgress = false;
1783 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1786 void watch_dog_timer_callback(unsigned long data)
1788 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
1789 queue_delayed_work_rsl(priv->priv_wq, &priv->watch_dog_wq, 0);
1790 mod_timer(&priv->watch_dog_timer, jiffies +
1791 MSECS(RTLLIB_WATCH_DOG_TIME));
1794 /****************************************************************************
1795 ---------------------------- NIC TX/RX STUFF---------------------------
1796 *****************************************************************************/
1797 void rtl8192_rx_enable(struct net_device *dev)
1799 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1800 priv->ops->rx_enable(dev);
1803 void rtl8192_tx_enable(struct net_device *dev)
1805 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1807 priv->ops->tx_enable(dev);
1809 rtllib_reset_queue(priv->rtllib);
1813 static void rtl8192_free_rx_ring(struct net_device *dev)
1815 struct r8192_priv *priv = rtllib_priv(dev);
1816 int i, rx_queue_idx;
1818 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE;
1820 for (i = 0; i < priv->rxringcount; i++) {
1821 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
1825 pci_unmap_single(priv->pdev,
1826 *((dma_addr_t *)skb->cb),
1827 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1831 pci_free_consistent(priv->pdev,
1832 sizeof(*priv->rx_ring[rx_queue_idx]) *
1834 priv->rx_ring[rx_queue_idx],
1835 priv->rx_ring_dma[rx_queue_idx]);
1836 priv->rx_ring[rx_queue_idx] = NULL;
1840 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1842 struct r8192_priv *priv = rtllib_priv(dev);
1843 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1845 while (skb_queue_len(&ring->queue)) {
1846 struct tx_desc *entry = &ring->desc[ring->idx];
1847 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1849 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1850 skb->len, PCI_DMA_TODEVICE);
1852 ring->idx = (ring->idx + 1) % ring->entries;
1855 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
1856 ring->desc, ring->dma);
1860 void rtl8192_data_hard_stop(struct net_device *dev)
1865 void rtl8192_data_hard_resume(struct net_device *dev)
1869 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1872 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1874 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1876 u8 queue_index = tcb_desc->queue_index;
1878 if ((priv->rtllib->eRFPowerState == eRfOff) || IS_NIC_DOWN(priv) ||
1879 priv->bResetInProgress) {
1884 assert(queue_index != TXCMD_QUEUE);
1887 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1888 skb_push(skb, priv->rtllib->tx_headroom);
1889 ret = rtl8192_tx(dev, skb);
1894 if (queue_index != MGNT_QUEUE) {
1895 priv->rtllib->stats.tx_bytes += (skb->len -
1896 priv->rtllib->tx_headroom);
1897 priv->rtllib->stats.tx_packets++;
1904 int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1906 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1908 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1910 u8 queue_index = tcb_desc->queue_index;
1912 if (queue_index != TXCMD_QUEUE) {
1913 if ((priv->rtllib->eRFPowerState == eRfOff) ||
1914 IS_NIC_DOWN(priv) || priv->bResetInProgress) {
1920 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1921 if (queue_index == TXCMD_QUEUE) {
1922 rtl8192_tx_cmd(dev, skb);
1926 tcb_desc->RATRIndex = 7;
1927 tcb_desc->bTxDisableRateFallBack = 1;
1928 tcb_desc->bTxUseDriverAssingedRate = 1;
1929 tcb_desc->bTxEnableFwCalcDur = 1;
1930 skb_push(skb, priv->rtllib->tx_headroom);
1931 ret = rtl8192_tx(dev, skb);
1943 static void rtl8192_tx_isr(struct net_device *dev, int prio)
1945 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1947 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1949 while (skb_queue_len(&ring->queue)) {
1950 struct tx_desc *entry = &ring->desc[ring->idx];
1951 struct sk_buff *skb;
1953 if (prio != BEACON_QUEUE) {
1956 ring->idx = (ring->idx + 1) % ring->entries;
1959 skb = __skb_dequeue(&ring->queue);
1960 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1961 skb->len, PCI_DMA_TODEVICE);
1965 if (prio != BEACON_QUEUE)
1966 tasklet_schedule(&priv->irq_tx_tasklet);
1969 void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1971 struct r8192_priv *priv = rtllib_priv(dev);
1972 struct rtl8192_tx_ring *ring;
1973 struct tx_desc_cmd *entry;
1975 struct cb_desc *tcb_desc;
1976 unsigned long flags;
1978 spin_lock_irqsave(&priv->irq_th_lock, flags);
1979 ring = &priv->tx_ring[TXCMD_QUEUE];
1981 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1982 entry = (struct tx_desc_cmd *) &ring->desc[idx];
1984 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1986 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
1988 __skb_queue_tail(&ring->queue, skb);
1989 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1994 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1996 struct r8192_priv *priv = rtllib_priv(dev);
1997 struct rtl8192_tx_ring *ring;
1998 unsigned long flags;
1999 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
2001 struct tx_desc *pdesc = NULL;
2002 struct rtllib_hdr_1addr *header = NULL;
2003 u16 fc = 0, type = 0, stype = 0;
2004 bool multi_addr = false, broad_addr = false, uni_addr = false;
2005 u8 *pda_addr = NULL;
2007 u32 fwinfo_size = 0;
2009 if (priv->bdisable_nic) {
2010 RT_TRACE(COMP_ERR, "%s: ERR!! Nic is disabled! Can't tx packet"
2011 " len=%d qidx=%d!!!\n", __func__, skb->len,
2012 tcb_desc->queue_index);
2016 priv->rtllib->bAwakePktSent = true;
2018 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
2020 header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size);
2021 fc = header->frame_ctl;
2022 type = WLAN_FC_GET_TYPE(fc);
2023 stype = WLAN_FC_GET_STYPE(fc);
2024 pda_addr = header->addr1;
2026 if (is_broadcast_ether_addr(pda_addr))
2028 else if (is_multicast_ether_addr(pda_addr))
2034 priv->stats.txbytesunicast += skb->len - fwinfo_size;
2035 else if (multi_addr)
2036 priv->stats.txbytesmulticast += skb->len - fwinfo_size;
2038 priv->stats.txbytesbroadcast += skb->len - fwinfo_size;
2040 spin_lock_irqsave(&priv->irq_th_lock, flags);
2041 ring = &priv->tx_ring[tcb_desc->queue_index];
2042 if (tcb_desc->queue_index != BEACON_QUEUE)
2043 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2047 pdesc = &ring->desc[idx];
2048 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
2049 RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d, idx = "
2050 "%d, skblen = 0x%x queuelen=%d",
2051 tcb_desc->queue_index, ring->idx, idx, skb->len,
2052 skb_queue_len(&ring->queue));
2053 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2057 if (type == RTLLIB_FTYPE_DATA) {
2058 if (priv->rtllib->LedControlHandler)
2059 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
2061 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
2062 __skb_queue_tail(&ring->queue, skb);
2064 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2065 dev->trans_start = jiffies;
2067 write_nic_word(dev, TPPoll, 0x01 << tcb_desc->queue_index);
2071 static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
2073 struct r8192_priv *priv = rtllib_priv(dev);
2074 struct rx_desc *entry = NULL;
2075 int i, rx_queue_idx;
2077 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2078 priv->rx_ring[rx_queue_idx] = pci_alloc_consistent(priv->pdev,
2079 sizeof(*priv->rx_ring[rx_queue_idx]) *
2081 &priv->rx_ring_dma[rx_queue_idx]);
2083 if (!priv->rx_ring[rx_queue_idx] ||
2084 (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
2085 RT_TRACE(COMP_ERR, "Cannot allocate RX ring\n");
2089 memset(priv->rx_ring[rx_queue_idx], 0,
2090 sizeof(*priv->rx_ring[rx_queue_idx]) *
2092 priv->rx_idx[rx_queue_idx] = 0;
2094 for (i = 0; i < priv->rxringcount; i++) {
2095 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
2096 dma_addr_t *mapping;
2097 entry = &priv->rx_ring[rx_queue_idx][i];
2101 priv->rx_buf[rx_queue_idx][i] = skb;
2102 mapping = (dma_addr_t *)skb->cb;
2103 *mapping = pci_map_single(priv->pdev,
2104 skb_tail_pointer_rsl(skb),
2106 PCI_DMA_FROMDEVICE);
2108 entry->BufferAddress = cpu_to_le32(*mapping);
2110 entry->Length = priv->rxbuffersize;
2120 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
2121 unsigned int prio, unsigned int entries)
2123 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2124 struct tx_desc *ring;
2128 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
2129 if (!ring || (unsigned long)ring & 0xFF) {
2130 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n",
2135 memset(ring, 0, sizeof(*ring)*entries);
2136 priv->tx_ring[prio].desc = ring;
2137 priv->tx_ring[prio].dma = dma;
2138 priv->tx_ring[prio].idx = 0;
2139 priv->tx_ring[prio].entries = entries;
2140 skb_queue_head_init(&priv->tx_ring[prio].queue);
2142 for (i = 0; i < entries; i++)
2143 ring[i].NextDescAddress =
2144 cpu_to_le32((u32)dma + ((i + 1) % entries) *
2151 short rtl8192_pci_initdescring(struct net_device *dev)
2155 struct r8192_priv *priv = rtllib_priv(dev);
2157 ret = rtl8192_alloc_rx_desc_ring(dev);
2161 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2162 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
2164 goto err_free_rings;
2170 rtl8192_free_rx_ring(dev);
2171 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2172 if (priv->tx_ring[i].desc)
2173 rtl8192_free_tx_ring(dev, i);
2177 void rtl8192_pci_resetdescring(struct net_device *dev)
2179 struct r8192_priv *priv = rtllib_priv(dev);
2180 int i, rx_queue_idx;
2181 unsigned long flags = 0;
2183 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2184 if (priv->rx_ring[rx_queue_idx]) {
2185 struct rx_desc *entry = NULL;
2186 for (i = 0; i < priv->rxringcount; i++) {
2187 entry = &priv->rx_ring[rx_queue_idx][i];
2190 priv->rx_idx[rx_queue_idx] = 0;
2194 spin_lock_irqsave(&priv->irq_th_lock, flags);
2195 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2196 if (priv->tx_ring[i].desc) {
2197 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
2199 while (skb_queue_len(&ring->queue)) {
2200 struct tx_desc *entry = &ring->desc[ring->idx];
2201 struct sk_buff *skb =
2202 __skb_dequeue(&ring->queue);
2204 pci_unmap_single(priv->pdev,
2205 le32_to_cpu(entry->TxBuffAddr),
2206 skb->len, PCI_DMA_TODEVICE);
2208 ring->idx = (ring->idx + 1) % ring->entries;
2213 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2216 void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
2217 struct rtllib_rx_stats *stats)
2219 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2221 if (stats->bIsAMPDU && !stats->bFirstMPDU)
2222 stats->mac_time = priv->LastRxDescTSF;
2224 priv->LastRxDescTSF = stats->mac_time;
2227 long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index)
2231 signal_power = (long)((signal_strength_index + 1) >> 1);
2234 return signal_power;
2239 rtl819x_update_rxsignalstatistics8190pci(
2240 struct r8192_priv *priv,
2241 struct rtllib_rx_stats *pprevious_stats
2247 if (priv->stats.recv_signal_power == 0)
2248 priv->stats.recv_signal_power =
2249 pprevious_stats->RecvSignalPower;
2251 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
2253 else if (pprevious_stats->RecvSignalPower <
2254 priv->stats.recv_signal_power)
2256 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 +
2257 pprevious_stats->RecvSignalPower +
2261 void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv,
2262 struct rtllib_rx_stats *pprevious_stats)
2267 u8 rtl819x_query_rxpwrpercentage(char antpower)
2269 if ((antpower <= -100) || (antpower >= 20))
2271 else if (antpower >= 0)
2274 return 100 + antpower;
2276 } /* QueryRxPwrPercentage */
2279 rtl819x_evm_dbtopercentage(
2291 ret_val = 0 - ret_val;
2299 rtl8192_record_rxdesc_forlateruse(
2300 struct rtllib_rx_stats *psrc_stats,
2301 struct rtllib_rx_stats *ptarget_stats
2304 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
2305 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
2310 static void rtl8192_rx_normal(struct net_device *dev)
2312 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2313 struct rtllib_hdr_1addr *rtllib_hdr = NULL;
2314 bool unicast_packet = false;
2315 bool bLedBlinking = true;
2316 u16 fc = 0, type = 0;
2318 int rx_queue_idx = RX_MPDU_QUEUE;
2320 struct rtllib_rx_stats stats = {
2324 .freq = RTLLIB_24GHZ_BAND,
2326 unsigned int count = priv->rxringcount;
2328 stats.nic_type = NIC_8192E;
2331 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx]
2332 [priv->rx_idx[rx_queue_idx]];
2333 struct sk_buff *skb = priv->rx_buf[rx_queue_idx]
2334 [priv->rx_idx[rx_queue_idx]];
2339 struct sk_buff *new_skb;
2341 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
2344 new_skb = dev_alloc_skb(priv->rxbuffersize);
2345 /* if allocation of new skb failed - drop current packet
2347 if (unlikely(!new_skb))
2350 pci_unmap_single(priv->pdev,
2351 *((dma_addr_t *)skb->cb),
2353 PCI_DMA_FROMDEVICE);
2355 skb_put(skb, pdesc->Length);
2356 skb_reserve(skb, stats.RxDrvInfoSize +
2358 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2359 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2360 if (!is_multicast_ether_addr(rtllib_hdr->addr1)) {
2361 /* unicast packet */
2362 unicast_packet = true;
2364 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
2365 type = WLAN_FC_GET_TYPE(fc);
2366 if (type == RTLLIB_FTYPE_MGMT)
2367 bLedBlinking = false;
2370 if (priv->rtllib->LedControlHandler)
2371 priv->rtllib->LedControlHandler(dev,
2375 if (type != RTLLIB_FTYPE_MGMT)
2376 priv->stats.rxdatacrcerr++;
2378 priv->stats.rxmgmtcrcerr++;
2383 if (!rtllib_rx(priv->rtllib, skb, &stats)) {
2384 dev_kfree_skb_any(skb);
2388 priv->stats.rxbytesunicast += skb_len;
2394 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] =
2396 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev,
2397 skb_tail_pointer_rsl(skb),
2399 PCI_DMA_FROMDEVICE);
2403 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
2405 pdesc->Length = priv->rxbuffersize;
2406 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1)
2408 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) %
2414 static void rtl8192_rx_cmd(struct net_device *dev)
2419 static void rtl8192_tx_resume(struct net_device *dev)
2421 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2422 struct rtllib_device *ieee = priv->rtllib;
2423 struct sk_buff *skb;
2426 for (queue_index = BK_QUEUE;
2427 queue_index < MAX_QUEUE_SIZE; queue_index++) {
2428 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) &&
2429 (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) {
2430 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
2431 ieee->softmac_data_hard_start_xmit(skb, dev, 0);
2436 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2438 rtl8192_tx_resume(priv->rtllib->dev);
2441 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2443 rtl8192_rx_normal(priv->rtllib->dev);
2445 if (MAX_RX_QUEUE > 1)
2446 rtl8192_rx_cmd(priv->rtllib->dev);
2448 write_nic_dword(priv->rtllib->dev, INTA_MASK,
2449 read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2452 /****************************************************************************
2453 ---------------------------- NIC START/CLOSE STUFF---------------------------
2454 *****************************************************************************/
2455 void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
2457 cancel_delayed_work(&priv->watch_dog_wq);
2458 cancel_delayed_work(&priv->update_beacon_wq);
2459 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
2460 cancel_work_sync(&priv->reset_wq);
2461 cancel_work_sync(&priv->qos_activate);
2464 int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
2466 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2472 static int rtl8192_open(struct net_device *dev)
2474 struct r8192_priv *priv = rtllib_priv(dev);
2477 down(&priv->wx_sem);
2478 ret = rtl8192_up(dev);
2485 int rtl8192_up(struct net_device *dev)
2487 struct r8192_priv *priv = rtllib_priv(dev);
2491 return _rtl8192_up(dev, false);
2495 static int rtl8192_close(struct net_device *dev)
2497 struct r8192_priv *priv = rtllib_priv(dev);
2500 if ((rtllib_act_scanning(priv->rtllib, false)) &&
2501 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) {
2502 rtllib_stop_scan(priv->rtllib);
2505 down(&priv->wx_sem);
2507 ret = rtl8192_down(dev, true);
2515 int rtl8192_down(struct net_device *dev, bool shutdownrf)
2517 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2523 void rtl8192_commit(struct net_device *dev)
2525 struct r8192_priv *priv = rtllib_priv(dev);
2529 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
2530 rtl8192_irq_disable(dev);
2531 priv->ops->stop_adapter(dev, true);
2532 _rtl8192_up(dev, false);
2535 void rtl8192_restart(void *data)
2537 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2539 struct net_device *dev = priv->rtllib->dev;
2541 down(&priv->wx_sem);
2543 rtl8192_commit(dev);
2548 static void r8192_set_multicast(struct net_device *dev)
2550 struct r8192_priv *priv = rtllib_priv(dev);
2553 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2554 priv->promisc = promisc;
2559 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
2561 struct r8192_priv *priv = rtllib_priv(dev);
2562 struct sockaddr *addr = mac;
2564 down(&priv->wx_sem);
2566 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
2568 schedule_work(&priv->reset_wq);
2574 /* based on ipw2200 driver */
2575 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2577 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2578 struct iwreq *wrq = (struct iwreq *)rq;
2580 struct rtllib_device *ieee = priv->rtllib;
2582 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2583 u8 zero_addr[6] = {0};
2584 struct iw_point *p = &wrq->u.data;
2585 struct ieee_param *ipw = NULL;
2587 down(&priv->wx_sem);
2590 case RTL_IOCTL_WPA_SUPPLICANT:
2591 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
2596 ipw = kmalloc(p->length, GFP_KERNEL);
2601 if (copy_from_user(ipw, p->pointer, p->length)) {
2607 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
2608 if (ipw->u.crypt.set_tx) {
2609 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2610 ieee->pairwise_key_type = KEY_TYPE_CCMP;
2611 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2612 ieee->pairwise_key_type = KEY_TYPE_TKIP;
2613 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2614 if (ipw->u.crypt.key_len == 13)
2615 ieee->pairwise_key_type =
2617 else if (ipw->u.crypt.key_len == 5)
2618 ieee->pairwise_key_type =
2621 ieee->pairwise_key_type = KEY_TYPE_NA;
2624 if (ieee->pairwise_key_type) {
2625 if (memcmp(ieee->ap_mac_addr, zero_addr,
2627 ieee->iw_mode = IW_MODE_ADHOC;
2628 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2629 EnableHWSecurityConfig8192(dev);
2630 set_swcam(dev, 4, ipw->u.crypt.idx,
2631 ieee->pairwise_key_type,
2632 (u8 *)ieee->ap_mac_addr,
2634 setKey(dev, 4, ipw->u.crypt.idx,
2635 ieee->pairwise_key_type,
2636 (u8 *)ieee->ap_mac_addr, 0, key);
2637 if (ieee->iw_mode == IW_MODE_ADHOC) {
2638 set_swcam(dev, ipw->u.crypt.idx,
2640 ieee->pairwise_key_type,
2641 (u8 *)ieee->ap_mac_addr,
2643 setKey(dev, ipw->u.crypt.idx,
2645 ieee->pairwise_key_type,
2646 (u8 *)ieee->ap_mac_addr,
2650 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
2651 && ieee->pHTInfo->bCurrentHTSupport) {
2652 write_nic_byte(dev, 0x173, 1);
2656 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2657 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2658 ieee->group_key_type = KEY_TYPE_CCMP;
2659 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2660 ieee->group_key_type = KEY_TYPE_TKIP;
2661 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2662 if (ipw->u.crypt.key_len == 13)
2663 ieee->group_key_type =
2665 else if (ipw->u.crypt.key_len == 5)
2666 ieee->group_key_type =
2669 ieee->group_key_type = KEY_TYPE_NA;
2671 if (ieee->group_key_type) {
2672 set_swcam(dev, ipw->u.crypt.idx,
2674 ieee->group_key_type,
2675 broadcast_addr, 0, key, 0);
2676 setKey(dev, ipw->u.crypt.idx,
2678 ieee->group_key_type,
2679 broadcast_addr, 0, key);
2684 ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data,
2700 irqreturn_type rtl8192_interrupt(int irq, void *netdev, struct pt_regs *regs)
2702 struct net_device *dev = (struct net_device *) netdev;
2703 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2704 unsigned long flags;
2709 if (priv->irq_enabled == 0)
2712 spin_lock_irqsave(&priv->irq_th_lock, flags);
2714 priv->ops->interrupt_recognized(dev, &inta, &intb);
2715 priv->stats.shints++;
2718 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2722 if (inta == 0xffff) {
2723 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2729 if (!netif_running(dev)) {
2730 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2734 if (inta & IMR_TBDOK) {
2735 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2736 priv->stats.txbeaconokint++;
2739 if (inta & IMR_TBDER) {
2740 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2741 priv->stats.txbeaconerr++;
2744 if (inta & IMR_BDOK)
2745 RT_TRACE(COMP_INTR, "beacon interrupt!\n");
2747 if (inta & IMR_MGNTDOK) {
2748 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
2749 priv->stats.txmanageokint++;
2750 rtl8192_tx_isr(dev, MGNT_QUEUE);
2751 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2752 if (priv->rtllib->ack_tx_to_ieee) {
2753 if (rtl8192_is_tx_queue_empty(dev)) {
2754 priv->rtllib->ack_tx_to_ieee = 0;
2755 rtllib_ps_tx_ack(priv->rtllib, 1);
2758 spin_lock_irqsave(&priv->irq_th_lock, flags);
2761 if (inta & IMR_COMDOK) {
2762 priv->stats.txcmdpktokint++;
2763 rtl8192_tx_isr(dev, TXCMD_QUEUE);
2766 if (inta & IMR_HIGHDOK)
2767 rtl8192_tx_isr(dev, HIGH_QUEUE);
2769 if (inta & IMR_ROK) {
2770 priv->stats.rxint++;
2771 priv->InterruptLog.nIMR_ROK++;
2772 tasklet_schedule(&priv->irq_rx_tasklet);
2775 if (inta & IMR_BcnInt) {
2776 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
2777 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
2780 if (inta & IMR_RDU) {
2781 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2782 priv->stats.rxrdu++;
2783 write_nic_dword(dev, INTA_MASK,
2784 read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
2785 tasklet_schedule(&priv->irq_rx_tasklet);
2788 if (inta & IMR_RXFOVW) {
2789 RT_TRACE(COMP_INTR, "rx overflow !\n");
2790 priv->stats.rxoverflow++;
2791 tasklet_schedule(&priv->irq_rx_tasklet);
2794 if (inta & IMR_TXFOVW)
2795 priv->stats.txoverflow++;
2797 if (inta & IMR_BKDOK) {
2798 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
2799 priv->stats.txbkokint++;
2800 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2801 rtl8192_tx_isr(dev, BK_QUEUE);
2804 if (inta & IMR_BEDOK) {
2805 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
2806 priv->stats.txbeokint++;
2807 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2808 rtl8192_tx_isr(dev, BE_QUEUE);
2811 if (inta & IMR_VIDOK) {
2812 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
2813 priv->stats.txviokint++;
2814 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2815 rtl8192_tx_isr(dev, VI_QUEUE);
2818 if (inta & IMR_VODOK) {
2819 priv->stats.txvookint++;
2820 RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
2821 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2822 rtl8192_tx_isr(dev, VO_QUEUE);
2825 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2834 /****************************************************************************
2835 ---------------------------- PCI_STUFF---------------------------
2836 *****************************************************************************/
2837 static const struct net_device_ops rtl8192_netdev_ops = {
2838 .ndo_open = rtl8192_open,
2839 .ndo_stop = rtl8192_close,
2840 .ndo_tx_timeout = rtl8192_tx_timeout,
2841 .ndo_do_ioctl = rtl8192_ioctl,
2842 .ndo_set_rx_mode = r8192_set_multicast,
2843 .ndo_set_mac_address = r8192_set_mac_adr,
2844 .ndo_validate_addr = eth_validate_addr,
2845 .ndo_change_mtu = eth_change_mtu,
2846 .ndo_start_xmit = rtllib_xmit,
2849 static int rtl8192_pci_probe(struct pci_dev *pdev,
2850 const struct pci_device_id *id)
2852 unsigned long ioaddr = 0;
2853 struct net_device *dev = NULL;
2854 struct r8192_priv *priv = NULL;
2855 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2856 unsigned long pmem_start, pmem_len, pmem_flags;
2858 bool bdma64 = false;
2861 RT_TRACE(COMP_INIT, "Configuring chip resources");
2863 if (pci_enable_device(pdev)) {
2864 RT_TRACE(COMP_ERR, "Failed to enable PCI device");
2868 pci_set_master(pdev);
2870 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2871 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
2872 printk(KERN_INFO "Unable to obtain 32bit DMA for consistent allocations\n");
2873 goto err_pci_disable;
2876 dev = alloc_rtllib(sizeof(struct r8192_priv));
2878 goto err_pci_disable;
2882 dev->features |= NETIF_F_HIGHDMA;
2884 pci_set_drvdata(pdev, dev);
2885 SET_NETDEV_DEV(dev, &pdev->dev);
2886 priv = rtllib_priv(dev);
2887 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
2889 priv->rtllib->pdev = pdev;
2890 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) &&
2891 (pdev->subsystem_device == 0x3304))
2892 priv->rtllib->bSupportRemoteWakeUp = 1;
2894 priv->rtllib->bSupportRemoteWakeUp = 0;
2896 pmem_start = pci_resource_start(pdev, 1);
2897 pmem_len = pci_resource_len(pdev, 1);
2898 pmem_flags = pci_resource_flags(pdev, 1);
2900 if (!(pmem_flags & IORESOURCE_MEM)) {
2901 RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting");
2902 goto err_rel_rtllib;
2905 printk(KERN_INFO "Memory mapped space start: 0x%08lx\n", pmem_start);
2906 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
2907 RT_TRACE(COMP_ERR, "request_mem_region failed!");
2908 goto err_rel_rtllib;
2912 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
2913 if (ioaddr == (unsigned long)NULL) {
2914 RT_TRACE(COMP_ERR, "ioremap failed!");
2918 dev->mem_start = ioaddr;
2919 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
2921 pci_read_config_byte(pdev, 0x08, &revision_id);
2922 /* If the revisionid is 0x10, the device uses rtl8192se. */
2923 if (pdev->device == 0x8192 && revision_id == 0x10)
2928 if (rtl8192_pci_findadapter(pdev, dev) == false)
2931 dev->irq = pdev->irq;
2934 dev->netdev_ops = &rtl8192_netdev_ops;
2936 dev->wireless_handlers = (struct iw_handler_def *)
2937 &r8192_wx_handlers_def;
2938 dev->ethtool_ops = &rtl819x_ethtool_ops;
2940 dev->type = ARPHRD_ETHER;
2941 dev->watchdog_timeo = HZ * 3;
2943 if (dev_alloc_name(dev, ifname) < 0) {
2944 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying "
2946 dev_alloc_name(dev, ifname);
2949 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
2950 if (rtl8192_init(dev) != 0) {
2951 RT_TRACE(COMP_ERR, "Initialization failed");
2955 netif_carrier_off(dev);
2956 netif_stop_queue(dev);
2958 if (register_netdev(dev))
2960 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name);
2962 rtl8192_proc_init_one(dev);
2964 if (priv->polling_timer_on == 0)
2965 check_rfctrl_gpio_timer((unsigned long)dev);
2967 RT_TRACE(COMP_INIT, "Driver probe completed\n");
2971 free_irq(dev->irq, dev);
2974 release_mem_region(pmem_start, pmem_len);
2978 DMESG("wlan driver load failed\n");
2979 pci_set_drvdata(pdev, NULL);
2981 pci_disable_device(pdev);
2985 static void rtl8192_pci_disconnect(struct pci_dev *pdev)
2987 struct net_device *dev = pci_get_drvdata(pdev);
2988 struct r8192_priv *priv ;
2992 unregister_netdev(dev);
2994 priv = rtllib_priv(dev);
2996 del_timer_sync(&priv->gpio_polling_timer);
2997 cancel_delayed_work(&priv->gpio_change_rf_wq);
2998 priv->polling_timer_on = 0;
2999 rtl8192_proc_remove_one(dev);
3000 rtl8192_down(dev, true);
3002 if (priv->pFirmware) {
3003 vfree(priv->pFirmware);
3004 priv->pFirmware = NULL;
3006 destroy_workqueue(priv->priv_wq);
3007 rtl8192_free_rx_ring(dev);
3008 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
3009 rtl8192_free_tx_ring(dev, i);
3012 printk(KERN_INFO "Freeing irq %d\n", dev->irq);
3013 free_irq(dev->irq, dev);
3018 kfree(priv->scan_cmd);
3020 if (dev->mem_start != 0) {
3021 iounmap((void __iomem *)dev->mem_start);
3022 release_mem_region(pci_resource_start(pdev, 1),
3023 pci_resource_len(pdev, 1));
3026 priv = rtllib_priv(dev);
3029 pci_disable_device(pdev);
3030 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
3033 bool NicIFEnableNIC(struct net_device *dev)
3035 bool init_status = true;
3036 struct r8192_priv *priv = rtllib_priv(dev);
3037 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
3038 (&(priv->rtllib->PowerSaveControl));
3040 if (IS_NIC_DOWN(priv)) {
3041 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",
3043 priv->bdisable_nic = false;
3044 return RT_STATUS_FAILURE;
3047 RT_TRACE(COMP_PS, "===========>%s()\n", __func__);
3048 priv->bfirst_init = true;
3049 init_status = priv->ops->initialize_adapter(dev);
3050 if (init_status != true) {
3051 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
3053 priv->bdisable_nic = false;
3056 RT_TRACE(COMP_INIT, "start adapter finished\n");
3057 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
3058 priv->bfirst_init = false;
3060 rtl8192_irq_enable(dev);
3061 priv->bdisable_nic = false;
3062 RT_TRACE(COMP_PS, "<===========%s()\n", __func__);
3065 bool NicIFDisableNIC(struct net_device *dev)
3068 struct r8192_priv *priv = rtllib_priv(dev);
3070 RT_TRACE(COMP_PS, "=========>%s()\n", __func__);
3071 priv->bdisable_nic = true;
3072 tmp_state = priv->rtllib->state;
3073 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
3074 priv->rtllib->state = tmp_state;
3075 rtl8192_cancel_deferred_work(priv);
3076 rtl8192_irq_disable(dev);
3078 priv->ops->stop_adapter(dev, false);
3079 RT_TRACE(COMP_PS, "<=========%s()\n", __func__);
3084 static int __init rtl8192_pci_module_init(void)
3086 printk(KERN_INFO "\nLinux kernel driver for RTL8192E WLAN cards\n");
3087 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan Driver\n");
3089 rtl8192_proc_module_init();
3090 if (0 != pci_register_driver(&rtl8192_pci_driver)) {
3091 DMESG("No device found");
3092 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3098 static void __exit rtl8192_pci_module_exit(void)
3100 pci_unregister_driver(&rtl8192_pci_driver);
3102 RT_TRACE(COMP_DOWN, "Exiting");
3103 rtl8192_proc_module_remove();
3106 void check_rfctrl_gpio_timer(unsigned long data)
3108 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
3110 priv->polling_timer_on = 1;
3112 queue_delayed_work_rsl(priv->priv_wq, &priv->gpio_change_rf_wq, 0);
3114 mod_timer(&priv->gpio_polling_timer, jiffies +
3115 MSECS(RTLLIB_WATCH_DOG_TIME));
3118 /***************************************************************************
3119 ------------------- module init / exit stubs ----------------
3120 ****************************************************************************/
3121 module_init(rtl8192_pci_module_init);
3122 module_exit(rtl8192_pci_module_exit);
3124 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
3125 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
3126 MODULE_VERSION(DRV_VERSION);
3127 MODULE_LICENSE("GPL");
3128 MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW);
3129 MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW);
3130 MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW);
3132 module_param(ifname, charp, S_IRUGO|S_IWUSR);
3133 module_param(hwwep, int, S_IRUGO|S_IWUSR);
3134 module_param(channels, int, S_IRUGO|S_IWUSR);
3136 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
3137 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");
3138 MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");