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 <asm/uaccess.h>
45 #include <linux/pci.h>
47 #include "r8192E_phy.h"
48 #include "r8192E_phyreg.h"
49 #include "r8190P_rtl8256.h"
50 #include "r8192E_cmdpkt.h"
60 static int channels = 0x3fff;
61 char* ifname = "wlan%d";
64 struct rtl819x_ops rtl819xp_ops = {
65 .nic_type = NIC_8192E,
66 .get_eeprom_size = rtl8192_get_eeprom_size,
67 .init_adapter_variable = rtl8192_InitializeVariables,
68 .initialize_adapter = rtl8192_adapter_start,
69 .link_change = rtl8192_link_change,
70 .tx_fill_descriptor = rtl8192_tx_fill_desc,
71 .tx_fill_cmd_descriptor = rtl8192_tx_fill_cmd_desc,
72 .rx_query_status_descriptor = rtl8192_rx_query_status_desc,
73 .rx_command_packet_handler = NULL,
74 .stop_adapter = rtl8192_halt_adapter,
75 .update_ratr_table = rtl8192_update_ratr_table,
76 .irq_enable = rtl8192_EnableInterrupt,
77 .irq_disable = rtl8192_DisableInterrupt,
78 .irq_clear = rtl8192_ClearInterrupt,
79 .rx_enable = rtl8192_enable_rx,
80 .tx_enable = rtl8192_enable_tx,
81 .interrupt_recognized = rtl8192_interrupt_recognized,
82 .TxCheckStuckHandler = rtl8192_HalTxCheckStuck,
83 .RxCheckStuckHandler = rtl8192_HalRxCheckStuck,
86 static struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
87 {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)},
88 {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)},
89 {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)},
93 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
95 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
96 const struct pci_device_id *id);
97 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev);
99 static struct pci_driver rtl8192_pci_driver = {
100 .name = DRV_NAME, /* Driver name */
101 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
102 .probe = rtl8192_pci_probe, /* probe fn */
103 .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */
104 .suspend = rtl8192E_suspend, /* PM suspend fn */
105 .resume = rtl8192E_resume, /* PM resume fn */
108 /****************************************************************************
109 -----------------------------IO STUFF-------------------------
110 *****************************************************************************/
112 PlatformIOCheckPageLegalAndGetRegMask(
117 bool bReturn = false;
118 *pu1bPageMask = 0xfe;
122 case 1: case 2: case 3: case 4:
123 case 8: case 9: case 10: case 12: case 13:
125 *pu1bPageMask = 0xf0;
136 void write_nic_io_byte(struct net_device *dev, int x,u8 y)
138 u32 u4bPage = (x >> 8);
140 bool bIsLegalPage = false;
144 outb(y&0xff,dev->base_addr +x);
147 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
150 u8 u1bPsr = read_nic_io_byte(dev, PSR);
152 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
153 write_nic_io_byte(dev, (x & 0xff), y);
154 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
165 void write_nic_io_word(struct net_device *dev, int x,u16 y)
167 u32 u4bPage = (x >> 8);
169 bool bIsLegalPage = false;
173 outw(y,dev->base_addr +x);
176 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
179 u8 u1bPsr = read_nic_io_byte(dev, PSR);
181 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
182 write_nic_io_word(dev, (x & 0xff), y);
183 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
193 void write_nic_io_dword(struct net_device *dev, int x,u32 y)
195 u32 u4bPage = (x >> 8);
197 bool bIsLegalPage = false;
201 outl(y,dev->base_addr +x);
204 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
207 u8 u1bPsr = read_nic_io_byte(dev, PSR);
209 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
210 write_nic_io_dword(dev, (x & 0xff), y);
211 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
220 u8 read_nic_io_byte(struct net_device *dev, int x)
222 u32 u4bPage = (x >> 8);
224 bool bIsLegalPage = false;
229 return 0xff&inb(dev->base_addr +x);
232 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
235 u8 u1bPsr = read_nic_io_byte(dev, PSR);
237 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
238 Data = read_nic_io_byte(dev, (x & 0xff));
239 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
250 u16 read_nic_io_word(struct net_device *dev, int x)
252 u32 u4bPage = (x >> 8);
254 bool bIsLegalPage = false;
259 return inw(dev->base_addr +x);
262 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
265 u8 u1bPsr = read_nic_io_byte(dev, PSR);
267 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
268 Data = read_nic_io_word(dev, (x & 0xff));
269 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
280 u32 read_nic_io_dword(struct net_device *dev, int x)
282 u32 u4bPage = (x >> 8);
284 bool bIsLegalPage = false;
289 return inl(dev->base_addr +x);
292 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage, &u1PageMask);
295 u8 u1bPsr = read_nic_io_byte(dev, PSR);
297 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) | (u8)u4bPage));
298 Data = read_nic_io_dword(dev, (x & 0xff));
299 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
310 u8 read_nic_byte(struct net_device *dev, int x)
312 return 0xff&readb((u8*)dev->mem_start +x);
315 u32 read_nic_dword(struct net_device *dev, int x)
317 return readl((u8*)dev->mem_start +x);
320 u16 read_nic_word(struct net_device *dev, int x)
322 return readw((u8*)dev->mem_start +x);
325 void write_nic_byte(struct net_device *dev, int x,u8 y)
327 writeb(y,(u8*)dev->mem_start +x);
332 void write_nic_dword(struct net_device *dev, int x,u32 y)
334 writel(y,(u8*)dev->mem_start +x);
339 void write_nic_word(struct net_device *dev, int x,u16 y)
341 writew(y,(u8*)dev->mem_start +x);
346 /****************************************************************************
347 -----------------------------GENERAL FUNCTION-------------------------
348 *****************************************************************************/
351 struct net_device* dev,
352 enum rt_rf_power_state StateToSet,
353 RT_RF_CHANGE_SOURCE ChangeSource,
357 struct r8192_priv *priv = rtllib_priv(dev);
358 struct rtllib_device * ieee = priv->rtllib;
359 bool bActionAllowed = false;
360 bool bConnectBySSID = false;
361 enum rt_rf_power_state rtState;
362 u16 RFWaitCounter = 0;
364 RT_TRACE((COMP_PS | COMP_RF), "===>MgntActSet_RF_State(): StateToSet(%d)\n",StateToSet);
366 ProtectOrNot = false;
373 spin_lock_irqsave(&priv->rf_ps_lock,flag);
374 if (priv->RFChangeInProgress)
376 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
377 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet);
379 while(priv->RFChangeInProgress)
382 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter);
385 if (RFWaitCounter > 100)
387 RT_TRACE(COMP_ERR, "MgntActSet_RF_State(): Wait too logn to set RF\n");
394 priv->RFChangeInProgress = true;
395 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
401 rtState = priv->rtllib->eRFPowerState;
407 priv->rtllib->RfOffReason &= (~ChangeSource);
409 if ((ChangeSource == RF_CHANGE_BY_HW) && (priv->bHwRadioOff == true)){
410 priv->bHwRadioOff = false;
413 if (! priv->rtllib->RfOffReason)
415 priv->rtllib->RfOffReason = 0;
416 bActionAllowed = true;
419 if (rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW )
421 bConnectBySSID = true;
425 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", priv->rtllib->RfOffReason, ChangeSource);
432 if ((priv->rtllib->iw_mode == IW_MODE_INFRA) || (priv->rtllib->iw_mode == IW_MODE_ADHOC))
434 if ((priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS) || (ChangeSource > RF_CHANGE_BY_IPS))
436 if (ieee->state == RTLLIB_LINKED)
437 priv->blinked_ingpio = true;
439 priv->blinked_ingpio = false;
440 rtllib_MgntDisconnect(priv->rtllib,disas_lv_ss);
446 if ((ChangeSource == RF_CHANGE_BY_HW) && (priv->bHwRadioOff == false)){
447 priv->bHwRadioOff = true;
449 priv->rtllib->RfOffReason |= ChangeSource;
450 bActionAllowed = true;
454 priv->rtllib->RfOffReason |= ChangeSource;
455 bActionAllowed = true;
464 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, priv->rtllib->RfOffReason);
465 PHY_SetRFPowerState(dev, StateToSet);
466 if (StateToSet == eRfOn)
469 if (bConnectBySSID && (priv->blinked_ingpio == true))
471 queue_delayed_work_rsl(ieee->wq, &ieee->associate_procedure_wq, 0);
472 priv->blinked_ingpio = false;
477 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource, priv->rtllib->RfOffReason);
482 spin_lock_irqsave(&priv->rf_ps_lock,flag);
483 priv->RFChangeInProgress = false;
484 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
487 RT_TRACE((COMP_PS && COMP_RF), "<===MgntActSet_RF_State()\n");
488 return bActionAllowed;
492 short rtl8192_get_nic_desc_num(struct net_device *dev, int prio)
494 struct r8192_priv *priv = rtllib_priv(dev);
495 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
497 /* For now, we reserved two free descriptor as a safety boundary
498 * between the tail and the head
500 if ((prio == MGNT_QUEUE) &&(skb_queue_len(&ring->queue)>10))
501 RT_TRACE(COMP_DBG, "-----[%d]---------ring->idx=%d queue_len=%d---------\n",
502 prio,ring->idx, skb_queue_len(&ring->queue));
503 return skb_queue_len(&ring->queue);
506 short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
508 struct r8192_priv *priv = rtllib_priv(dev);
509 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
511 if (ring->entries - skb_queue_len(&ring->queue) >= 2) {
518 void rtl8192_tx_timeout(struct net_device *dev)
520 struct r8192_priv *priv = rtllib_priv(dev);
522 schedule_work(&priv->reset_wq);
526 void rtl8192_irq_enable(struct net_device *dev)
528 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
529 priv->irq_enabled = 1;
531 priv->ops->irq_enable(dev);
534 void rtl8192_irq_disable(struct net_device *dev)
536 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
538 priv->ops->irq_disable(dev);
540 priv->irq_enabled = 0;
543 void rtl8192_irq_clear(struct net_device *dev)
545 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
547 priv->ops->irq_clear(dev);
551 void rtl8192_set_chan(struct net_device *dev,short ch)
553 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
555 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
556 if (priv->chan_forced)
561 if (priv->rf_set_chan)
562 priv->rf_set_chan(dev,priv->chan);
565 void rtl8192_update_cap(struct net_device* dev, u16 cap)
567 struct r8192_priv *priv = rtllib_priv(dev);
568 struct rtllib_network *net = &priv->rtllib->current_network;
574 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE)
576 if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT)
578 ShortPreamble = true;
579 priv->dot11CurrentPreambleMode = PREAMBLE_SHORT;
580 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_SHORT_PREAMBLE\n", __func__);
581 priv->rtllib->SetHwRegHandler( dev, HW_VAR_ACK_PREAMBLE, (unsigned char *)&ShortPreamble );
586 if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG)
588 ShortPreamble = false;
589 priv->dot11CurrentPreambleMode = PREAMBLE_LONG;
590 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_LONG_PREAMBLE\n", __func__);
591 priv->rtllib->SetHwRegHandler( dev, HW_VAR_ACK_PREAMBLE, (unsigned char *)&ShortPreamble );
596 if (net->mode & (IEEE_G|IEEE_N_24G))
599 u8 CurSlotTime = priv->slot_time;
601 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) && (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime))
603 if (CurSlotTime != SHORT_SLOT_TIME)
605 slot_time_val = SHORT_SLOT_TIME;
606 priv->rtllib->SetHwRegHandler( dev, HW_VAR_SLOT_TIME, &slot_time_val );
611 if (CurSlotTime != NON_SHORT_SLOT_TIME)
613 slot_time_val = NON_SHORT_SLOT_TIME;
614 priv->rtllib->SetHwRegHandler( dev, HW_VAR_SLOT_TIME, &slot_time_val );
620 static struct rtllib_qos_parameters def_qos_parameters = {
628 void rtl8192_update_beacon(void *data)
630 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, update_beacon_wq.work);
631 struct net_device *dev = priv->rtllib->dev;
632 struct rtllib_device* ieee = priv->rtllib;
633 struct rtllib_network* net = &ieee->current_network;
635 if (ieee->pHTInfo->bCurrentHTSupport)
636 HTUpdateSelfAndPeerSetting(ieee, net);
637 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
638 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
639 rtl8192_update_cap(dev, net->capability);
642 #define MOVE_INTO_HANDLER
643 int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
645 void rtl8192_qos_activate(void *data)
647 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, qos_activate);
648 struct net_device *dev = priv->rtllib->dev;
649 #ifndef MOVE_INTO_HANDLER
650 struct rtllib_qos_parameters *qos_parameters = &priv->rtllib->current_network.qos_data.parameters;
651 u8 mode = priv->rtllib->current_network.mode;
660 mutex_lock(&priv->mutex);
661 if (priv->rtllib->state != RTLLIB_LINKED)
663 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
665 for (i = 0; i < QOS_QUEUE_NUM; i++) {
666 #ifndef MOVE_INTO_HANDLER
667 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
668 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
669 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
670 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
671 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
672 RT_TRACE(COMP_DBG, "===>ACI:%d:u4bAcParam:%x\n", i, u4bAcParam);
673 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
675 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8*)(&i));
680 mutex_unlock(&priv->mutex);
683 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
685 struct rtllib_network *network)
688 u32 size = sizeof(struct rtllib_qos_parameters);
690 if (priv->rtllib->state !=RTLLIB_LINKED)
693 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
696 if (network->flags & NETWORK_HAS_QOS_MASK) {
697 if (active_network &&
698 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
699 network->qos_data.active = network->qos_data.supported;
701 if ((network->qos_data.active == 1) && (active_network == 1) &&
702 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
703 (network->qos_data.old_param_count !=
704 network->qos_data.param_count)) {
705 network->qos_data.old_param_count =
706 network->qos_data.param_count;
707 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
708 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
709 RT_TRACE (COMP_QOS, "QoS parameters change call "
713 memcpy(&priv->rtllib->current_network.qos_data.parameters,\
714 &def_qos_parameters, size);
716 if ((network->qos_data.active == 1) && (active_network == 1)) {
717 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
718 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
720 network->qos_data.active = 0;
721 network->qos_data.supported = 0;
727 static int rtl8192_handle_beacon(struct net_device * dev,
728 struct rtllib_beacon * beacon,
729 struct rtllib_network * network)
731 struct r8192_priv *priv = rtllib_priv(dev);
733 rtl8192_qos_handle_probe_response(priv,1,network);
735 queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
740 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
741 struct rtllib_network *network)
745 u32 size = sizeof(struct rtllib_qos_parameters);
746 int set_qos_param = 0;
748 if ((priv == NULL) || (network == NULL))
751 if (priv->rtllib->state !=RTLLIB_LINKED)
754 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
757 spin_lock_irqsave(&priv->rtllib->lock, flags);
758 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
759 memcpy(&priv->rtllib->current_network.qos_data.parameters,\
760 &network->qos_data.parameters,\
761 sizeof(struct rtllib_qos_parameters));
762 priv->rtllib->current_network.qos_data.active = 1;
763 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
765 priv->rtllib->current_network.qos_data.old_param_count =
766 priv->rtllib->current_network.qos_data.param_count;
767 priv->rtllib->current_network.qos_data.param_count =
768 network->qos_data.param_count;
770 memcpy(&priv->rtllib->current_network.qos_data.parameters,
771 &def_qos_parameters, size);
772 priv->rtllib->current_network.qos_data.active = 0;
773 priv->rtllib->current_network.qos_data.supported = 0;
777 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
779 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
780 network->flags ,priv->rtllib->current_network.qos_data.active);
781 if (set_qos_param == 1) {
782 dm_init_edca_turbo(priv->rtllib->dev);
783 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
788 static int rtl8192_handle_assoc_response(struct net_device *dev,
789 struct rtllib_assoc_response_frame *resp,
790 struct rtllib_network *network)
792 struct r8192_priv *priv = rtllib_priv(dev);
793 rtl8192_qos_association_resp(priv, network);
797 void rtl8192_prepare_beacon(struct r8192_priv *priv)
799 struct net_device *dev = priv->rtllib->dev;
800 struct sk_buff *pskb = NULL, *pnewskb = NULL;
801 struct cb_desc *tcb_desc = NULL;
802 struct rtl8192_tx_ring *ring = NULL;
803 struct tx_desc *pdesc = NULL;
805 ring = &priv->tx_ring[BEACON_QUEUE];
806 pskb = __skb_dequeue(&ring->queue);
810 pnewskb = rtllib_get_beacon(priv->rtllib);
814 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
815 tcb_desc->queue_index = BEACON_QUEUE;
816 tcb_desc->data_rate = 2;
817 tcb_desc->RATRIndex = 7;
818 tcb_desc->bTxDisableRateFallBack = 1;
819 tcb_desc->bTxUseDriverAssingedRate = 1;
820 skb_push(pnewskb, priv->rtllib->tx_headroom);
822 pdesc = &ring->desc[0];
823 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
824 __skb_queue_tail(&ring->queue, pnewskb);
830 void rtl8192_stop_beacon(struct net_device *dev)
834 void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
836 struct r8192_priv *priv = rtllib_priv(dev);
837 struct rtllib_network *net;
838 u8 i=0, basic_rate = 0;
839 net = & priv->rtllib->current_network;
841 for (i = 0; i < net->rates_len; i++) {
842 basic_rate = net->rates[i] & 0x7f;
843 switch (basic_rate) {
845 *rate_config |= RRSR_1M;
848 *rate_config |= RRSR_2M;
851 *rate_config |= RRSR_5_5M;
854 *rate_config |= RRSR_11M;
857 *rate_config |= RRSR_6M;
860 *rate_config |= RRSR_9M;
863 *rate_config |= RRSR_12M;
866 *rate_config |= RRSR_18M;
869 *rate_config |= RRSR_24M;
872 *rate_config |= RRSR_36M;
875 *rate_config |= RRSR_48M;
878 *rate_config |= RRSR_54M;
883 for (i = 0; i < net->rates_ex_len; i++) {
884 basic_rate = net->rates_ex[i] & 0x7f;
885 switch (basic_rate) {
887 *rate_config |= RRSR_1M;
890 *rate_config |= RRSR_2M;
893 *rate_config |= RRSR_5_5M;
896 *rate_config |= RRSR_11M;
899 *rate_config |= RRSR_6M;
902 *rate_config |= RRSR_9M;
905 *rate_config |= RRSR_12M;
908 *rate_config |= RRSR_18M;
911 *rate_config |= RRSR_24M;
914 *rate_config |= RRSR_36M;
917 *rate_config |= RRSR_48M;
920 *rate_config |= RRSR_54M;
926 void rtl8192_refresh_supportrate(struct r8192_priv * priv)
928 struct rtllib_device* ieee = priv->rtllib;
929 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G) {
930 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
931 memcpy(ieee->Regdot11TxHTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
934 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
939 u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
941 struct r8192_priv *priv = rtllib_priv(dev);
944 switch (priv->rf_chip) {
949 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B);
952 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
955 ret = WIRELESS_MODE_B;
961 void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
963 struct r8192_priv *priv = rtllib_priv(dev);
964 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
966 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode & bSupportMode) == 0)) {
967 if (bSupportMode & WIRELESS_MODE_N_24G) {
968 wireless_mode = WIRELESS_MODE_N_24G;
969 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
970 wireless_mode = WIRELESS_MODE_N_5G;
971 } else if ((bSupportMode & WIRELESS_MODE_A)) {
972 wireless_mode = WIRELESS_MODE_A;
973 } else if ((bSupportMode & WIRELESS_MODE_G)) {
974 wireless_mode = WIRELESS_MODE_G;
975 } else if ((bSupportMode & WIRELESS_MODE_B)) {
976 wireless_mode = WIRELESS_MODE_B;
978 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported (%x)!!!\n",
979 __func__, bSupportMode);
980 wireless_mode = WIRELESS_MODE_B;
984 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) == (WIRELESS_MODE_G | WIRELESS_MODE_B))
985 wireless_mode = WIRELESS_MODE_G;
987 priv->rtllib->mode = wireless_mode;
989 ActUpdateChannelAccessSetting( dev, wireless_mode, &priv->ChannelAccessSetting);
991 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G)){
992 priv->rtllib->pHTInfo->bEnableHT = 1;
993 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n", __func__,wireless_mode);
995 priv->rtllib->pHTInfo->bEnableHT = 0;
996 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n", __func__,wireless_mode);
999 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
1000 rtl8192_refresh_supportrate(priv);
1003 int _rtl8192_sta_up(struct net_device *dev,bool is_silent_reset)
1005 struct r8192_priv *priv = rtllib_priv(dev);
1006 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)(&(priv->rtllib->PowerSaveControl));
1007 bool init_status = true;
1008 priv->bDriverIsGoingToUnload = false;
1009 priv->bdisable_nic = false;
1012 priv->rtllib->ieee_up=1;
1014 priv->up_first_time = 0;
1015 RT_TRACE(COMP_INIT, "Bringing up iface");
1016 priv->bfirst_init = true;
1017 init_status = priv->ops->initialize_adapter(dev);
1018 if (init_status != true)
1020 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__func__);
1021 priv->bfirst_init = false;
1025 RT_TRACE(COMP_INIT, "start adapter finished\n");
1026 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
1027 priv->bfirst_init = false;
1029 if (priv->polling_timer_on == 0){
1030 check_rfctrl_gpio_timer((unsigned long)dev);
1033 if (priv->rtllib->state != RTLLIB_LINKED)
1034 rtllib_softmac_start_protocol(priv->rtllib, 0);
1035 rtllib_reset_queue(priv->rtllib);
1036 watch_dog_timer_callback((unsigned long) dev);
1039 if (!netif_queue_stopped(dev))
1040 netif_start_queue(dev);
1042 netif_wake_queue(dev);
1047 int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
1049 struct r8192_priv *priv = rtllib_priv(dev);
1050 unsigned long flags = 0;
1051 u8 RFInProgressTimeOut = 0;
1053 if (priv->up == 0) return -1;
1055 if (priv->rtllib->rtllib_ips_leave != NULL)
1056 priv->rtllib->rtllib_ips_leave(dev);
1058 if (priv->rtllib->state == RTLLIB_LINKED)
1059 LeisurePSLeave(dev);
1061 priv->bDriverIsGoingToUnload = true;
1063 priv->rtllib->ieee_up = 0;
1064 priv->bfirst_after_down = 1;
1065 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
1066 if (!netif_queue_stopped(dev))
1067 netif_stop_queue(dev);
1069 priv->rtllib->wpa_ie_len = 0;
1070 if (priv->rtllib->wpa_ie)
1071 kfree(priv->rtllib->wpa_ie);
1072 priv->rtllib->wpa_ie = NULL;
1073 CamResetAllEntry(dev);
1074 memset(priv->rtllib->swcamtable,0,sizeof(struct sw_cam_table)*32);
1075 rtl8192_irq_disable(dev);
1077 del_timer_sync(&priv->watch_dog_timer);
1078 rtl8192_cancel_deferred_work(priv);
1079 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
1081 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1082 spin_lock_irqsave(&priv->rf_ps_lock,flags);
1083 while(priv->RFChangeInProgress)
1085 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
1086 if (RFInProgressTimeOut > 100)
1088 spin_lock_irqsave(&priv->rf_ps_lock,flags);
1091 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait until rf chang is done.\n",__func__);
1093 RFInProgressTimeOut ++;
1094 spin_lock_irqsave(&priv->rf_ps_lock,flags);
1096 priv->RFChangeInProgress = true;
1097 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
1098 priv->ops->stop_adapter(dev, false);
1099 spin_lock_irqsave(&priv->rf_ps_lock,flags);
1100 priv->RFChangeInProgress = false;
1101 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
1103 memset(&priv->rtllib->current_network, 0 , offsetof(struct rtllib_network, list));
1104 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
1109 static void rtl8192_init_priv_handler(struct net_device* dev)
1111 struct r8192_priv *priv = rtllib_priv(dev);
1113 priv->rtllib->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
1114 priv->rtllib->set_chan = rtl8192_set_chan;
1115 priv->rtllib->link_change = priv->ops->link_change;
1116 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1117 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1118 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1119 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1120 priv->rtllib->get_nic_desc_num = rtl8192_get_nic_desc_num;
1121 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1122 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1123 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode;
1124 priv->rtllib->LeisurePSLeave = LeisurePSLeave;
1125 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode;
1126 priv->rf_set_chan = rtl8192_phy_SwChnl;
1128 priv->rtllib->start_send_beacons = rtl8192e_start_beacon;
1129 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
1131 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup;
1132 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep;
1133 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1135 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg;
1136 priv->rtllib->GetHalfNmodeSupportByAPsHandler = rtl8192_GetHalfNmodeSupportByAPs;
1138 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg;
1139 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr;
1140 priv->rtllib->SetFwCmdHandler = NULL;
1141 priv->rtllib->InitialGainHandler = InitialGain819xPci;
1142 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq;
1143 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave;
1145 priv->rtllib->LedControlHandler = NULL;
1146 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1148 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192;
1150 priv->rtllib->rtllib_rfkill_poll = NULL;
1153 static void rtl8192_init_priv_constant(struct net_device* dev)
1155 struct r8192_priv *priv = rtllib_priv(dev);
1156 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)(&(priv->rtllib->PowerSaveControl));
1158 pPSC->RegMaxLPSAwakeIntvl = 5;
1160 priv->RegPciASPM = 2;
1162 priv->RegDevicePciASPMSetting = 0x03;
1164 priv->RegHostPciASPMSetting = 0x02;
1166 priv->RegHwSwRfOffD3 = 2;
1168 priv->RegSupportPciASPM = 2;
1172 static void rtl8192_init_priv_variable(struct net_device* dev)
1174 struct r8192_priv *priv = rtllib_priv(dev);
1177 priv->AcmMethod = eAcmWay2_SW;
1178 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
1179 priv->rtllib->hwscan_sem_up = 1;
1180 priv->rtllib->status = 0;
1181 priv->H2CTxCmdSeq = 0;
1182 priv->bDisableFrameBursting = 0;
1183 priv->bDMInitialGainEnable = 1;
1184 priv->polling_timer_on = 0;
1185 priv->up_first_time = 1;
1186 priv->blinked_ingpio = false;
1187 priv->bDriverIsGoingToUnload = false;
1188 priv->being_init_adapter = false;
1189 priv->initialized_at_probe = false;
1190 priv->sw_radio_on = true;
1191 priv->bdisable_nic = false;
1192 priv->bfirst_init = false;
1193 priv->txringcount = 64;
1194 priv->rxbuffersize = 9100;
1195 priv->rxringcount = MAX_RX_COUNT;
1196 priv->irq_enabled=0;
1198 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
1199 priv->RegChannelPlan = 0xf;
1200 priv->nrxAMPDU_size = 0;
1201 priv->nrxAMPDU_aggr_num = 0;
1202 priv->last_rxdesc_tsf_high = 0;
1203 priv->last_rxdesc_tsf_low = 0;
1204 priv->rtllib->mode = WIRELESS_MODE_AUTO;
1205 priv->rtllib->iw_mode = IW_MODE_INFRA;
1206 priv->rtllib->bNetPromiscuousMode = false;
1207 priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false;
1208 priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame = false;
1209 priv->rtllib->ieee_up=0;
1210 priv->retry_rts = DEFAULT_RETRY_RTS;
1211 priv->retry_data = DEFAULT_RETRY_DATA;
1212 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
1213 priv->rtllib->rate = 110;
1214 priv->rtllib->short_slot = 1;
1215 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
1216 priv->bcck_in_ch14 = false;
1217 priv->bfsync_processing = false;
1218 priv->CCKPresentAttentuation = 0;
1219 priv->rfa_txpowertrackingindex = 0;
1220 priv->rfc_txpowertrackingindex = 0;
1222 priv->ScanDelay = 50;
1223 priv->ResetProgress = RESET_TYPE_NORESET;
1224 priv->bForcedSilentReset = 0;
1225 priv->bDisableNormalResetCheck = false;
1226 priv->force_reset = false;
1227 memset(priv->rtllib->swcamtable,0,sizeof(struct sw_cam_table)*32);
1229 memset(&priv->InterruptLog,0,sizeof(struct log_int_8190));
1230 priv->RxCounter = 0;
1231 priv->rtllib->wx_set_enc = 0;
1232 priv->bHwRadioOff = false;
1234 priv->isRFOff = false;
1235 priv->bInPowerSaveMode = false;
1236 priv->rtllib->RfOffReason = 0;
1237 priv->RFChangeInProgress = false;
1238 priv->bHwRfOffAction = 0;
1239 priv->SetRFPowerStateInProgress = false;
1240 priv->rtllib->PowerSaveControl.bInactivePs = true;
1241 priv->rtllib->PowerSaveControl.bIPSModeBackup = false;
1242 priv->rtllib->PowerSaveControl.bLeisurePs = true;
1243 priv->rtllib->PowerSaveControl.bFwCtrlLPS = false;
1244 priv->rtllib->LPSDelayCnt = 0;
1245 priv->rtllib->sta_sleep = LPS_IS_WAKE;
1246 priv->rtllib->eRFPowerState = eRfOn;
1248 priv->txpower_checkcnt = 0;
1249 priv->thermal_readback_index =0;
1250 priv->txpower_tracking_callback_cnt = 0;
1251 priv->ccktxpower_adjustcnt_ch14 = 0;
1252 priv->ccktxpower_adjustcnt_not_ch14 = 0;
1254 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
1255 priv->rtllib->iw_mode = IW_MODE_INFRA;
1256 priv->rtllib->active_scan = 1;
1257 priv->rtllib->be_scan_inprogress = false;
1258 priv->rtllib->modulation = RTLLIB_CCK_MODULATION | RTLLIB_OFDM_MODULATION;
1259 priv->rtllib->host_encrypt = 1;
1260 priv->rtllib->host_decrypt = 1;
1262 priv->rtllib->dot11PowerSaveMode = eActive;
1263 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
1264 priv->rtllib->MaxMssDensity = 0;
1265 priv->rtllib->MinSpaceCfg = 0;
1267 priv->card_type = PCI;
1269 priv->AcmControl = 0;
1270 priv->pFirmware = (struct rt_firmware *)vmalloc(sizeof(struct rt_firmware));
1271 if (priv->pFirmware)
1272 memset(priv->pFirmware, 0, sizeof(struct rt_firmware));
1274 skb_queue_head_init(&priv->rx_queue);
1275 skb_queue_head_init(&priv->skb_queue);
1277 for (i = 0; i < MAX_QUEUE_SIZE; i++) {
1278 skb_queue_head_init(&priv->rtllib->skb_waitQ [i]);
1280 for (i = 0; i < MAX_QUEUE_SIZE; i++) {
1281 skb_queue_head_init(&priv->rtllib->skb_aggQ [i]);
1286 static void rtl8192_init_priv_lock(struct r8192_priv * priv)
1288 spin_lock_init(&priv->fw_scan_lock);
1289 spin_lock_init(&priv->tx_lock);
1290 spin_lock_init(&priv->irq_lock);
1291 spin_lock_init(&priv->irq_th_lock);
1292 spin_lock_init(&priv->rf_ps_lock);
1293 spin_lock_init(&priv->ps_lock);
1294 spin_lock_init(&priv->rf_lock);
1295 spin_lock_init(&priv->rt_h2c_lock);
1296 sema_init(&priv->wx_sem,1);
1297 sema_init(&priv->rf_sem,1);
1298 mutex_init(&priv->mutex);
1301 static void rtl8192_init_priv_task(struct net_device* dev)
1303 struct r8192_priv *priv = rtllib_priv(dev);
1305 priv->priv_wq = create_workqueue(DRV_NAME);
1306 INIT_WORK_RSL(&priv->reset_wq, (void*)rtl8192_restart, dev);
1307 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void*)IPSLeave_wq, dev);
1308 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq, (void*)rtl819x_watchdog_wqcallback, dev);
1309 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq, (void*)dm_txpower_trackingcallback, dev);
1310 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq, (void*)dm_rf_pathcheck_workitemcallback, dev);
1311 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq, (void*)rtl8192_update_beacon, dev);
1312 INIT_WORK_RSL(&priv->qos_activate, (void*)rtl8192_qos_activate, dev);
1313 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq, dev);
1314 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq, dev);
1315 tasklet_init(&priv->irq_rx_tasklet,
1316 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1317 (unsigned long)priv);
1318 tasklet_init(&priv->irq_tx_tasklet,
1319 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
1320 (unsigned long)priv);
1321 tasklet_init(&priv->irq_prepare_beacon_tasklet,
1322 (void(*)(unsigned long))rtl8192_prepare_beacon,
1323 (unsigned long)priv);
1326 short rtl8192_get_channel_map(struct net_device * dev)
1330 struct r8192_priv *priv = rtllib_priv(dev);
1331 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256)
1332 && (priv->rf_chip != RF_6052)) {
1333 RT_TRACE(COMP_ERR, "%s: unknown rf chip, can't set channel map\n", __func__);
1337 if (priv->ChannelPlan > COUNTRY_CODE_MAX) {
1338 printk("rtl819x_init:Error channel plan! Set to default.\n");
1339 priv->ChannelPlan= COUNTRY_CODE_FCC;
1341 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
1342 Dot11d_Init(priv->rtllib);
1343 Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib);
1344 for (i = 1; i <= 11; i++) {
1345 (priv->rtllib->active_channel_map)[i] = 1;
1347 (priv->rtllib->active_channel_map)[12] = 2;
1348 (priv->rtllib->active_channel_map)[13] = 2;
1353 short rtl8192_init(struct net_device *dev)
1355 struct r8192_priv *priv = rtllib_priv(dev);
1357 memset(&(priv->stats),0,sizeof(struct rt_stats));
1359 rtl8192_dbgp_flag_init(dev);
1361 rtl8192_init_priv_handler(dev);
1362 rtl8192_init_priv_constant(dev);
1363 rtl8192_init_priv_variable(dev);
1364 rtl8192_init_priv_lock(priv);
1365 rtl8192_init_priv_task(dev);
1366 priv->ops->get_eeprom_size(dev);
1367 priv->ops->init_adapter_variable(dev);
1368 rtl8192_get_channel_map(dev);
1372 init_timer(&priv->watch_dog_timer);
1373 setup_timer(&priv->watch_dog_timer,
1374 watch_dog_timer_callback,
1375 (unsigned long) dev);
1377 init_timer(&priv->gpio_polling_timer);
1378 setup_timer(&priv->gpio_polling_timer,
1379 check_rfctrl_gpio_timer,
1380 (unsigned long)dev);
1382 rtl8192_irq_disable(dev);
1383 if (request_irq(dev->irq, (void*)rtl8192_interrupt_rsl, IRQF_SHARED, dev->name, dev))
1385 printk("Error allocating IRQ %d",dev->irq);
1389 RT_TRACE(COMP_INIT, "IRQ %d\n",dev->irq);
1392 if (rtl8192_pci_initdescring(dev) != 0) {
1393 printk("Endopoints initialization failed");
1400 /***************************************************************************
1401 -------------------------------WATCHDOG STUFF---------------------------
1402 ***************************************************************************/
1403 short rtl8192_is_tx_queue_empty(struct net_device *dev)
1406 struct r8192_priv *priv = rtllib_priv(dev);
1407 for (i=0; i<=MGNT_QUEUE; i++)
1409 if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) )
1411 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){
1412 printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1420 rtl819x_TxCheckStuck(struct net_device *dev)
1422 struct r8192_priv *priv = rtllib_priv(dev);
1424 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1425 bool bCheckFwTxCnt = false;
1426 struct rtl8192_tx_ring *ring = NULL;
1427 struct sk_buff* skb = NULL;
1428 struct cb_desc * tcb_desc = NULL;
1429 unsigned long flags = 0;
1431 switch (priv->rtllib->ps)
1433 case RTLLIB_PS_DISABLED:
1434 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
1436 case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
1437 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1440 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1443 spin_lock_irqsave(&priv->irq_th_lock,flags);
1444 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++)
1446 if (QueueID == TXCMD_QUEUE)
1449 if (QueueID == BEACON_QUEUE)
1452 ring = &priv->tx_ring[QueueID];
1454 if (skb_queue_len(&ring->queue) == 0)
1458 skb = (&ring->queue)->next;
1459 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1460 tcb_desc->nStuckCount++;
1461 bCheckFwTxCnt = true;
1462 if (tcb_desc->nStuckCount > 1)
1463 printk("%s: QueueID=%d tcb_desc->nStuckCount=%d\n",__func__,QueueID,tcb_desc->nStuckCount);
1466 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1468 if (bCheckFwTxCnt) {
1469 if (priv->ops->TxCheckStuckHandler(dev))
1471 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
1472 return RESET_TYPE_SILENT;
1476 return RESET_TYPE_NORESET;
1479 enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
1481 struct r8192_priv *priv = rtllib_priv(dev);
1483 if (priv->ops->RxCheckStuckHandler(dev))
1485 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
1486 return RESET_TYPE_SILENT;
1489 return RESET_TYPE_NORESET;
1493 rtl819x_ifcheck_resetornot(struct net_device *dev)
1495 struct r8192_priv *priv = rtllib_priv(dev);
1496 enum reset_type TxResetType = RESET_TYPE_NORESET;
1497 enum reset_type RxResetType = RESET_TYPE_NORESET;
1498 enum rt_rf_power_state rfState;
1500 rfState = priv->rtllib->eRFPowerState;
1502 if (rfState == eRfOn)
1503 TxResetType = rtl819x_TxCheckStuck(dev);
1505 if ( rfState == eRfOn &&
1506 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1507 (priv->rtllib->state == RTLLIB_LINKED)) {
1509 RxResetType = rtl819x_RxCheckStuck(dev);
1512 if (TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL){
1513 printk("%s(): TxResetType is %d, RxResetType is %d\n",__func__,TxResetType,RxResetType);
1514 return RESET_TYPE_NORMAL;
1515 } else if (TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT){
1516 printk("%s(): TxResetType is %d, RxResetType is %d\n",__func__,TxResetType,RxResetType);
1517 return RESET_TYPE_SILENT;
1519 return RESET_TYPE_NORESET;
1524 void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
1528 void rtl819x_ifsilentreset(struct net_device *dev)
1530 struct r8192_priv *priv = rtllib_priv(dev);
1532 int reset_status = 0;
1533 struct rtllib_device *ieee = priv->rtllib;
1539 if (priv->ResetProgress==RESET_TYPE_NORESET) {
1541 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
1543 priv->ResetProgress = RESET_TYPE_SILENT;
1545 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1546 if (priv->RFChangeInProgress)
1548 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1551 priv->RFChangeInProgress = true;
1552 priv->bResetInProgress = true;
1553 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1557 down(&priv->wx_sem);
1559 if (priv->rtllib->state == RTLLIB_LINKED)
1560 LeisurePSLeave(dev);
1562 if (IS_NIC_DOWN(priv)) {
1563 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__func__);
1569 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__func__);
1571 RT_TRACE(COMP_RESET,"%s():111111111111111111111111======>start to down the driver\n",__func__);
1573 if (!netif_queue_stopped(dev))
1574 netif_stop_queue(dev);
1576 rtl8192_irq_disable(dev);
1577 del_timer_sync(&priv->watch_dog_timer);
1578 rtl8192_cancel_deferred_work(priv);
1580 rtllib_stop_scan_syncro(ieee);
1582 if (ieee->state == RTLLIB_LINKED) {
1583 SEM_DOWN_IEEE_WX(&ieee->wx_sem);
1584 printk("ieee->state is RTLLIB_LINKED\n");
1585 rtllib_stop_send_beacons(priv->rtllib);
1586 del_timer_sync(&ieee->associate_timer);
1587 cancel_delayed_work(&ieee->associate_retry_wq);
1588 rtllib_stop_scan(ieee);
1589 netif_carrier_off(dev);
1590 SEM_UP_IEEE_WX(&ieee->wx_sem);
1592 printk("ieee->state is NOT LINKED\n");
1593 rtllib_softmac_stop_protocol(priv->rtllib, 0 ,true);
1596 dm_backup_dynamic_mechanism_state(dev);
1599 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__func__);
1601 RT_TRACE(COMP_RESET,"%s():<===========up process start\n",__func__);
1602 reset_status = _rtl8192_up(dev,true);
1604 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__func__);
1605 if (reset_status == -1) {
1606 if (reset_times < 3) {
1610 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n",__func__);
1614 ieee->is_silent_reset = 1;
1616 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1617 priv->RFChangeInProgress = false;
1618 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1620 EnableHWSecurityConfig8192(dev);
1622 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1623 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1625 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1627 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_ADHOC) {
1628 ieee->set_chan(ieee->dev, ieee->current_network.channel);
1629 ieee->link_change(ieee->dev);
1631 notify_wx_assoc_event(ieee);
1633 rtllib_start_send_beacons(ieee);
1635 if (ieee->data_hard_resume)
1636 ieee->data_hard_resume(ieee->dev);
1637 netif_carrier_on(ieee->dev);
1638 } else if (ieee->iw_mode == IW_MODE_MESH) {
1639 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1642 CamRestoreAllEntry(dev);
1643 dm_restore_dynamic_mechanism_state(dev);
1645 priv->ResetProgress = RESET_TYPE_NORESET;
1646 priv->reset_count++;
1648 priv->bForcedSilentReset =false;
1649 priv->bResetInProgress = false;
1651 write_nic_byte(dev, UFWP, 1);
1652 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
1656 void rtl819x_update_rxcounts(struct r8192_priv *priv,
1658 u32 *TotalRxDataNum)
1664 *TotalRxDataNum = 0;
1666 SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++)%(priv->rtllib->LinkDetectInfo.SlotNum);
1667 priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod;
1668 priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] = priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod;
1669 for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) {
1670 *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i];
1671 *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i];
1676 void rtl819x_watchdog_wqcallback(void *data)
1678 struct r8192_priv *priv = container_of_dwork_rsl(data, struct r8192_priv, watch_dog_wq);
1679 struct net_device *dev = priv->rtllib->dev;
1680 struct rtllib_device* ieee = priv->rtllib;
1681 enum reset_type ResetType = RESET_TYPE_NORESET;
1682 static u8 check_reset_cnt = 0;
1683 unsigned long flags;
1684 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)(&(priv->rtllib->PowerSaveControl));
1685 bool bBusyTraffic = false;
1686 bool bHigherBusyTraffic = false;
1687 bool bHigherBusyRxTraffic = false;
1688 bool bEnterPS = false;
1690 if (IS_NIC_DOWN(priv) || (priv->bHwRadioOff == true))
1693 if (priv->rtllib->state >= RTLLIB_LINKED) {
1694 if (priv->rtllib->CntAfterLink<2)
1695 priv->rtllib->CntAfterLink++;
1697 priv->rtllib->CntAfterLink = 0;
1700 hal_dm_watchdog(dev);
1702 if (rtllib_act_scanning(priv->rtllib,false) == false){
1703 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == RTLLIB_NOLINK) &&\
1704 (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key &&\
1705 (!ieee->proto_stoppping) && !ieee->wx_set_enc
1707 if ((ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE)&&
1708 (!ieee->bNetPromiscuousMode))
1710 RT_TRACE(COMP_PS, "====================>haha:IPSEnter()\n");
1716 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode == IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode))
1718 if ( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 ||
1719 ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) {
1720 bBusyTraffic = true;
1724 if ( ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1725 ieee->LinkDetectInfo.NumTxOkInPeriod > 4000 )
1727 bHigherBusyTraffic = true;
1728 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000)
1729 bHigherBusyRxTraffic = true;
1731 bHigherBusyRxTraffic = false;
1734 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1735 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1740 if (ieee->current_network.beacon_interval < 95)
1744 LeisurePSEnter(dev);
1746 LeisurePSLeave(dev);
1749 RT_TRACE(COMP_LPS,"====>no link LPS leave\n");
1750 LeisurePSLeave(dev);
1753 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
1754 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
1755 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1756 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1758 ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1759 ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1764 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA)
1766 u32 TotalRxBcnNum = 0;
1767 u32 TotalRxDataNum = 0;
1769 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
1771 if ((TotalRxBcnNum+TotalRxDataNum) == 0)
1772 priv->check_roaming_cnt ++;
1774 priv->check_roaming_cnt = 0;
1777 if (priv->check_roaming_cnt > 0)
1779 if ( ieee->eRFPowerState == eRfOff)
1780 RT_TRACE(COMP_ERR,"========>%s()\n",__func__);
1782 printk("===>%s(): AP is power off,chan:%d, connect another one\n",__func__, priv->chan);
1784 ieee->state = RTLLIB_ASSOCIATING;
1786 RemovePeerTS(priv->rtllib,priv->rtllib->current_network.bssid);
1787 ieee->is_roaming = true;
1788 ieee->is_set_key = false;
1789 ieee->link_change(dev);
1790 if (ieee->LedControlHandler)
1791 ieee->LedControlHandler(ieee->dev, LED_CTL_START_TO_LINK);
1793 notify_wx_assoc_event(ieee);
1795 if (!(ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_CCMP|SEC_ALG_TKIP)))
1796 queue_delayed_work_rsl(ieee->wq, &ieee->associate_procedure_wq, 0);
1798 priv->check_roaming_cnt = 0;
1801 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
1802 ieee->LinkDetectInfo.NumRecvDataInPeriod=0;
1806 spin_lock_irqsave(&priv->tx_lock,flags);
1807 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1808 (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing))
1810 ResetType = rtl819x_ifcheck_resetornot(dev);
1811 check_reset_cnt = 3;
1813 spin_unlock_irqrestore(&priv->tx_lock,flags);
1815 if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL)
1817 priv->ResetProgress = RESET_TYPE_NORMAL;
1818 RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__func__);
1822 if ( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT)))
1824 rtl819x_ifsilentreset(dev);
1826 priv->force_reset = false;
1827 priv->bForcedSilentReset = false;
1828 priv->bResetInProgress = false;
1829 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1832 void watch_dog_timer_callback(unsigned long data)
1834 struct r8192_priv *priv = rtllib_priv((struct net_device *) data);
1835 queue_delayed_work_rsl(priv->priv_wq,&priv->watch_dog_wq,0);
1836 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(RTLLIB_WATCH_DOG_TIME));
1839 /****************************************************************************
1840 ---------------------------- NIC TX/RX STUFF---------------------------
1841 *****************************************************************************/
1842 void rtl8192_rx_enable(struct net_device *dev)
1844 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1845 priv->ops->rx_enable(dev);
1848 void rtl8192_tx_enable(struct net_device *dev)
1850 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1852 priv->ops->tx_enable(dev);
1854 rtllib_reset_queue(priv->rtllib);
1858 static void rtl8192_free_rx_ring(struct net_device *dev)
1860 struct r8192_priv *priv = rtllib_priv(dev);
1863 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx ++){
1864 for (i = 0; i < priv->rxringcount; i++) {
1865 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
1869 pci_unmap_single(priv->pdev,
1870 *((dma_addr_t *)skb->cb),
1871 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1875 pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
1876 priv->rx_ring[rx_queue_idx], priv->rx_ring_dma[rx_queue_idx]);
1877 priv->rx_ring[rx_queue_idx] = NULL;
1881 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1883 struct r8192_priv *priv = rtllib_priv(dev);
1884 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1886 while (skb_queue_len(&ring->queue)) {
1887 struct tx_desc *entry = &ring->desc[ring->idx];
1888 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1890 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1891 skb->len, PCI_DMA_TODEVICE);
1893 ring->idx = (ring->idx + 1) % ring->entries;
1896 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
1897 ring->desc, ring->dma);
1901 void rtl8192_data_hard_stop(struct net_device *dev)
1906 void rtl8192_data_hard_resume(struct net_device *dev)
1910 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1912 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1914 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1915 u8 queue_index = tcb_desc->queue_index;
1917 if ((priv->rtllib->eRFPowerState == eRfOff) || IS_NIC_DOWN(priv) || priv->bResetInProgress){
1922 assert(queue_index != TXCMD_QUEUE);
1925 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1926 skb_push(skb, priv->rtllib->tx_headroom);
1927 ret = rtl8192_tx(dev, skb);
1932 if (queue_index!=MGNT_QUEUE) {
1933 priv->rtllib->stats.tx_bytes+=(skb->len - priv->rtllib->tx_headroom);
1934 priv->rtllib->stats.tx_packets++;
1941 int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
1943 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1945 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1946 u8 queue_index = tcb_desc->queue_index;
1948 if (queue_index != TXCMD_QUEUE){
1949 if ((priv->rtllib->eRFPowerState == eRfOff) ||IS_NIC_DOWN(priv) || priv->bResetInProgress){
1955 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1956 if (queue_index == TXCMD_QUEUE) {
1957 rtl8192_tx_cmd(dev, skb);
1961 tcb_desc->RATRIndex = 7;
1962 tcb_desc->bTxDisableRateFallBack = 1;
1963 tcb_desc->bTxUseDriverAssingedRate = 1;
1964 tcb_desc->bTxEnableFwCalcDur = 1;
1965 skb_push(skb, priv->rtllib->tx_headroom);
1966 ret = rtl8192_tx(dev, skb);
1978 void rtl8192_tx_isr(struct net_device *dev, int prio)
1980 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1982 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1984 while (skb_queue_len(&ring->queue)) {
1985 struct tx_desc *entry = &ring->desc[ring->idx];
1986 struct sk_buff *skb;
1988 if (prio != BEACON_QUEUE) {
1991 ring->idx = (ring->idx + 1) % ring->entries;
1994 skb = __skb_dequeue(&ring->queue);
1995 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1996 skb->len, PCI_DMA_TODEVICE);
2000 if (prio != BEACON_QUEUE) {
2001 tasklet_schedule(&priv->irq_tx_tasklet);
2006 void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
2008 struct r8192_priv *priv = rtllib_priv(dev);
2009 struct rtl8192_tx_ring *ring;
2010 struct tx_desc_cmd * entry;
2012 struct cb_desc *tcb_desc;
2013 unsigned long flags;
2015 spin_lock_irqsave(&priv->irq_th_lock,flags);
2016 ring = &priv->tx_ring[TXCMD_QUEUE];
2018 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2019 entry = (struct tx_desc_cmd *) &ring->desc[idx];
2021 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2023 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
2025 __skb_queue_tail(&ring->queue, skb);
2026 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2031 short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
2033 struct r8192_priv *priv = rtllib_priv(dev);
2034 struct rtl8192_tx_ring *ring;
2035 unsigned long flags;
2036 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2037 struct tx_desc *pdesc = NULL;
2038 struct rtllib_hdr_1addr * header = NULL;
2039 u16 fc=0, type=0,stype=0;
2040 bool multi_addr=false,broad_addr=false,uni_addr=false;
2041 u8* pda_addr = NULL;
2043 u32 fwinfo_size = 0;
2045 if (priv->bdisable_nic){
2046 RT_TRACE(COMP_ERR,"%s: ERR!! Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n", __func__, skb->len, tcb_desc->queue_index);
2050 priv->rtllib->bAwakePktSent = true;
2052 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
2054 header = (struct rtllib_hdr_1addr *)(((u8*)skb->data) + fwinfo_size);
2055 fc = header->frame_ctl;
2056 type = WLAN_FC_GET_TYPE(fc);
2057 stype = WLAN_FC_GET_STYPE(fc);
2058 pda_addr = header->addr1;
2060 if (is_multicast_ether_addr(pda_addr))
2062 else if (is_broadcast_ether_addr(pda_addr))
2069 priv->stats.txbytesunicast += skb->len - fwinfo_size;
2070 else if (multi_addr)
2071 priv->stats.txbytesmulticast += skb->len - fwinfo_size;
2073 priv->stats.txbytesbroadcast += skb->len - fwinfo_size;
2075 spin_lock_irqsave(&priv->irq_th_lock,flags);
2076 ring = &priv->tx_ring[tcb_desc->queue_index];
2077 if (tcb_desc->queue_index != BEACON_QUEUE) {
2078 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2083 pdesc = &ring->desc[idx];
2084 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
2085 RT_TRACE(COMP_ERR,"No more TX desc@%d, ring->idx = %d,idx = %d, skblen = 0x%x queuelen=%d", \
2086 tcb_desc->queue_index,ring->idx, idx,skb->len, skb_queue_len(&ring->queue));
2087 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2091 if (tcb_desc->queue_index == MGNT_QUEUE){
2094 if (type == RTLLIB_FTYPE_DATA){
2095 if (priv->rtllib->LedControlHandler)
2096 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
2098 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
2099 __skb_queue_tail(&ring->queue, skb);
2101 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2102 dev->trans_start = jiffies;
2104 write_nic_word(dev,TPPoll,0x01<<tcb_desc->queue_index);
2108 short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
2110 struct r8192_priv *priv = rtllib_priv(dev);
2111 struct rx_desc *entry = NULL;
2112 int i, rx_queue_idx;
2114 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx ++){
2115 priv->rx_ring[rx_queue_idx] = pci_alloc_consistent(priv->pdev,
2116 sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount, &priv->rx_ring_dma[rx_queue_idx]);
2118 if (!priv->rx_ring[rx_queue_idx] || (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
2119 RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n");
2123 memset(priv->rx_ring[rx_queue_idx], 0, sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount);
2124 priv->rx_idx[rx_queue_idx] = 0;
2126 for (i = 0; i < priv->rxringcount; i++) {
2127 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
2128 dma_addr_t *mapping;
2129 entry = &priv->rx_ring[rx_queue_idx][i];
2133 priv->rx_buf[rx_queue_idx][i] = skb;
2134 mapping = (dma_addr_t *)skb->cb;
2135 *mapping = pci_map_single(priv->pdev, skb_tail_pointer_rsl(skb),
2136 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
2138 entry->BufferAddress = cpu_to_le32(*mapping);
2140 entry->Length = priv->rxbuffersize;
2149 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
2150 unsigned int prio, unsigned int entries)
2152 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2153 struct tx_desc *ring;
2157 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
2158 if (!ring || (unsigned long)ring & 0xFF) {
2159 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio);
2163 memset(ring, 0, sizeof(*ring)*entries);
2164 priv->tx_ring[prio].desc = ring;
2165 priv->tx_ring[prio].dma = dma;
2166 priv->tx_ring[prio].idx = 0;
2167 priv->tx_ring[prio].entries = entries;
2168 skb_queue_head_init(&priv->tx_ring[prio].queue);
2170 for (i = 0; i < entries; i++)
2171 ring[i].NextDescAddress =
2172 cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring));
2178 short rtl8192_pci_initdescring(struct net_device *dev)
2182 struct r8192_priv *priv = rtllib_priv(dev);
2184 ret = rtl8192_alloc_rx_desc_ring(dev);
2190 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2191 if ((ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount)))
2192 goto err_free_rings;
2198 rtl8192_free_rx_ring(dev);
2199 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2200 if (priv->tx_ring[i].desc)
2201 rtl8192_free_tx_ring(dev, i);
2205 void rtl8192_pci_resetdescring(struct net_device *dev)
2207 struct r8192_priv *priv = rtllib_priv(dev);
2209 unsigned long flags = 0;
2211 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx ++){
2212 if (priv->rx_ring[rx_queue_idx]) {
2213 struct rx_desc *entry = NULL;
2214 for (i = 0; i < priv->rxringcount; i++) {
2215 entry = &priv->rx_ring[rx_queue_idx][i];
2218 priv->rx_idx[rx_queue_idx] = 0;
2222 spin_lock_irqsave(&priv->irq_th_lock,flags);
2223 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2224 if (priv->tx_ring[i].desc) {
2225 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
2227 while (skb_queue_len(&ring->queue)) {
2228 struct tx_desc *entry = &ring->desc[ring->idx];
2229 struct sk_buff *skb = __skb_dequeue(&ring->queue);
2231 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
2232 skb->len, PCI_DMA_TODEVICE);
2234 ring->idx = (ring->idx + 1) % ring->entries;
2239 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2242 void rtl819x_UpdateRxPktTimeStamp (struct net_device *dev, struct rtllib_rx_stats *stats)
2244 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2246 if (stats->bIsAMPDU && !stats->bFirstMPDU) {
2247 stats->mac_time[0] = priv->LastRxDescTSFLow;
2248 stats->mac_time[1] = priv->LastRxDescTSFHigh;
2250 priv->LastRxDescTSFLow = stats->mac_time[0];
2251 priv->LastRxDescTSFHigh = stats->mac_time[1];
2255 long rtl819x_translate_todbm(struct r8192_priv * priv, u8 signal_strength_index )
2259 signal_power = (long)((signal_strength_index + 1) >> 1);
2262 return signal_power;
2267 rtl819x_update_rxsignalstatistics8190pci(
2268 struct r8192_priv * priv,
2269 struct rtllib_rx_stats * pprevious_stats
2275 if (priv->stats.recv_signal_power == 0)
2276 priv->stats.recv_signal_power = pprevious_stats->RecvSignalPower;
2278 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
2280 else if (pprevious_stats->RecvSignalPower < priv->stats.recv_signal_power)
2282 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 + pprevious_stats->RecvSignalPower + weighting) / 6;
2286 rtl819x_process_cck_rxpathsel(
2287 struct r8192_priv * priv,
2288 struct rtllib_rx_stats * pprevious_stats
2294 u8 rtl819x_query_rxpwrpercentage(
2298 if ((antpower <= -100) || (antpower >= 20))
2302 else if (antpower >= 0)
2308 return (100+antpower);
2311 } /* QueryRxPwrPercentage */
2314 rtl819x_evm_dbtopercentage(
2326 ret_val = 0 - ret_val;
2334 rtl8192_record_rxdesc_forlateruse(
2335 struct rtllib_rx_stats * psrc_stats,
2336 struct rtllib_rx_stats * ptarget_stats
2339 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
2340 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
2345 void rtl8192_rx_normal(struct net_device *dev)
2347 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2348 struct rtllib_hdr_1addr *rtllib_hdr = NULL;
2349 bool unicast_packet = false;
2350 bool bLedBlinking=true;
2353 int rx_queue_idx = RX_MPDU_QUEUE;
2355 struct rtllib_rx_stats stats = {
2359 .freq = RTLLIB_24GHZ_BAND,
2361 unsigned int count = priv->rxringcount;
2363 stats.nic_type = NIC_8192E;
2366 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx][priv->rx_idx[rx_queue_idx]];
2367 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]];
2372 struct sk_buff *new_skb;
2374 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
2377 new_skb = dev_alloc_skb(priv->rxbuffersize);
2378 /* if allocation of new skb failed - drop current packet
2380 if (unlikely(!new_skb))
2383 pci_unmap_single(priv->pdev,
2384 *((dma_addr_t *)skb->cb),
2386 PCI_DMA_FROMDEVICE);
2388 skb_put(skb, pdesc->Length);
2389 skb_reserve(skb, stats.RxDrvInfoSize +
2391 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2392 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2393 if (!is_broadcast_ether_addr(rtllib_hdr->addr1) &&
2394 !is_multicast_ether_addr(rtllib_hdr->addr1)) {
2395 /* unicast packet */
2396 unicast_packet = true;
2398 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
2399 type = WLAN_FC_GET_TYPE(fc);
2400 if (type == RTLLIB_FTYPE_MGMT)
2401 bLedBlinking = false;
2404 if (priv->rtllib->LedControlHandler)
2405 priv->rtllib->LedControlHandler(dev,
2409 if (type != RTLLIB_FTYPE_MGMT)
2410 priv->stats.rxdatacrcerr ++;
2412 priv->stats.rxmgmtcrcerr ++;
2417 if (!rtllib_rx(priv->rtllib, skb, &stats)){
2418 dev_kfree_skb_any(skb);
2422 priv->stats.rxbytesunicast += skb_len;
2428 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] = skb;
2429 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer_rsl(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE);
2433 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
2435 pdesc->Length = priv->rxbuffersize;
2436 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1)
2438 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) % priv->rxringcount;
2443 void rtl8192_rx_cmd(struct net_device *dev)
2448 void rtl8192_tx_resume(struct net_device *dev)
2450 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2451 struct rtllib_device *ieee = priv->rtllib;
2452 struct sk_buff *skb;
2455 for (queue_index = BK_QUEUE; queue_index < MAX_QUEUE_SIZE;queue_index++) {
2456 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&&
2457 (priv->rtllib->check_nic_enough_desc(dev,queue_index) > 0)) {
2458 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
2459 ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/);
2464 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2466 rtl8192_tx_resume(priv->rtllib->dev);
2469 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2471 rtl8192_rx_normal(priv->rtllib->dev);
2473 if (MAX_RX_QUEUE > 1)
2474 rtl8192_rx_cmd(priv->rtllib->dev);
2476 write_nic_dword(priv->rtllib->dev, INTA_MASK,read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2479 /****************************************************************************
2480 ---------------------------- NIC START/CLOSE STUFF---------------------------
2481 *****************************************************************************/
2482 void rtl8192_cancel_deferred_work(struct r8192_priv * priv)
2484 cancel_delayed_work(&priv->watch_dog_wq);
2485 cancel_delayed_work(&priv->update_beacon_wq);
2486 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
2487 cancel_work_sync(&priv->reset_wq);
2488 cancel_work_sync(&priv->qos_activate);
2491 int _rtl8192_up(struct net_device *dev,bool is_silent_reset)
2493 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2499 int rtl8192_open(struct net_device *dev)
2501 struct r8192_priv *priv = rtllib_priv(dev);
2504 down(&priv->wx_sem);
2505 ret = rtl8192_up(dev);
2512 int rtl8192_up(struct net_device *dev)
2514 struct r8192_priv *priv = rtllib_priv(dev);
2516 if (priv->up == 1) return -1;
2517 return _rtl8192_up(dev,false);
2521 int rtl8192_close(struct net_device *dev)
2523 struct r8192_priv *priv = rtllib_priv(dev);
2526 if ((rtllib_act_scanning(priv->rtllib, false)) &&
2527 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)){
2528 rtllib_stop_scan(priv->rtllib);
2531 down(&priv->wx_sem);
2533 ret = rtl8192_down(dev,true);
2541 int rtl8192_down(struct net_device *dev, bool shutdownrf)
2543 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2549 void rtl8192_commit(struct net_device *dev)
2551 struct r8192_priv *priv = rtllib_priv(dev);
2553 if (priv->up == 0) return ;
2554 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
2555 rtl8192_irq_disable(dev);
2556 priv->ops->stop_adapter(dev, true);
2557 _rtl8192_up(dev,false);
2560 void rtl8192_restart(void *data)
2562 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, reset_wq);
2563 struct net_device *dev = priv->rtllib->dev;
2565 down(&priv->wx_sem);
2567 rtl8192_commit(dev);
2572 static void r8192_set_multicast(struct net_device *dev)
2574 struct r8192_priv *priv = rtllib_priv(dev);
2579 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
2581 if (promisc != priv->promisc) {
2585 priv->promisc = promisc;
2590 int r8192_set_mac_adr(struct net_device *dev, void *mac)
2592 struct r8192_priv *priv = rtllib_priv(dev);
2593 struct sockaddr *addr = mac;
2595 down(&priv->wx_sem);
2597 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
2599 schedule_work(&priv->reset_wq);
2605 /* based on ipw2200 driver */
2606 int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2608 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2609 struct iwreq *wrq = (struct iwreq *)rq;
2611 struct rtllib_device *ieee = priv->rtllib;
2613 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
2614 u8 zero_addr[6] = {0};
2615 struct iw_point *p = &wrq->u.data;
2617 down(&priv->wx_sem);
2620 case RTL_IOCTL_WPA_SUPPLICANT:
2622 struct ieee_param *ipw = NULL;
2623 if (p->length < sizeof(struct ieee_param) || !p->pointer){
2628 ipw = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
2633 if (copy_from_user(ipw, p->pointer, p->length)) {
2639 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
2641 if (ipw->u.crypt.set_tx)
2643 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2644 ieee->pairwise_key_type = KEY_TYPE_CCMP;
2645 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2646 ieee->pairwise_key_type = KEY_TYPE_TKIP;
2647 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
2649 if (ipw->u.crypt.key_len == 13)
2650 ieee->pairwise_key_type = KEY_TYPE_WEP104;
2651 else if (ipw->u.crypt.key_len == 5)
2652 ieee->pairwise_key_type = KEY_TYPE_WEP40;
2655 ieee->pairwise_key_type = KEY_TYPE_NA;
2657 if (ieee->pairwise_key_type)
2659 if (memcmp(ieee->ap_mac_addr, zero_addr, 6) == 0)
2660 ieee->iw_mode = IW_MODE_ADHOC;
2662 memcpy((u8*)key, ipw->u.crypt.key, 16);
2663 EnableHWSecurityConfig8192(dev);
2664 set_swcam(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key,0);
2665 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
2666 if (ieee->iw_mode == IW_MODE_ADHOC){
2667 set_swcam(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key,0);
2668 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
2671 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){
2672 write_nic_byte(dev, 0x173, 1);
2678 memcpy((u8*)key, ipw->u.crypt.key, 16);
2679 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2680 ieee->group_key_type= KEY_TYPE_CCMP;
2681 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2682 ieee->group_key_type = KEY_TYPE_TKIP;
2683 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
2685 if (ipw->u.crypt.key_len == 13)
2686 ieee->group_key_type = KEY_TYPE_WEP104;
2687 else if (ipw->u.crypt.key_len == 5)
2688 ieee->group_key_type = KEY_TYPE_WEP40;
2691 ieee->group_key_type = KEY_TYPE_NA;
2693 if (ieee->group_key_type)
2698 ieee->group_key_type,
2706 ieee->group_key_type,
2714 ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data, 0);
2729 void FairBeacon(struct net_device *dev)
2731 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2732 struct rtllib_network *net = &priv->rtllib->current_network;
2734 static u8 forceturn =0;
2735 u16 beaconint = net->beacon_interval;
2737 if (priv->rtllib->iw_mode != IW_MODE_ADHOC)
2740 if (priv->bIbssCoordinator){
2745 priv->rtllib->SetHwRegHandler(dev, HW_VAR_BEACON_INTERVAL, (u8*)(&beaconint));
2750 beaconint=beaconint+2;
2751 priv->rtllib->SetHwRegHandler(dev, HW_VAR_BEACON_INTERVAL, (u8*)(&beaconint));
2759 priv->rtllib->SetHwRegHandler(dev, HW_VAR_BEACON_INTERVAL, (u8*)(&beaconint));
2764 beaconint=beaconint-2;
2765 priv->rtllib->SetHwRegHandler(dev, HW_VAR_BEACON_INTERVAL, (u8*)(&beaconint));
2772 irqreturn_type rtl8192_interrupt(int irq, void *netdev, struct pt_regs *regs)
2774 struct net_device *dev = (struct net_device *) netdev;
2775 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2776 unsigned long flags;
2781 if (priv->irq_enabled == 0){
2785 spin_lock_irqsave(&priv->irq_th_lock,flags);
2787 priv->ops->interrupt_recognized(dev, &inta, &intb);
2788 priv->stats.shints++;
2791 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2795 if (inta == 0xffff) {
2796 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2802 if (!netif_running(dev)) {
2803 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2807 if (inta & IMR_TBDOK){
2808 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2809 priv->stats.txbeaconokint++;
2812 if (inta & IMR_TBDER){
2813 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2814 priv->stats.txbeaconerr++;
2817 if (inta & IMR_BDOK) {
2818 RT_TRACE(COMP_INTR, "beacon interrupt!\n");
2821 if (inta & IMR_MGNTDOK ) {
2822 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
2823 priv->stats.txmanageokint++;
2824 rtl8192_tx_isr(dev,MGNT_QUEUE);
2825 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2826 if (priv->rtllib->ack_tx_to_ieee){
2827 if (rtl8192_is_tx_queue_empty(dev)){
2828 priv->rtllib->ack_tx_to_ieee = 0;
2829 rtllib_ps_tx_ack(priv->rtllib, 1);
2832 spin_lock_irqsave(&priv->irq_th_lock,flags);
2835 if (inta & IMR_COMDOK) {
2836 priv->stats.txcmdpktokint++;
2837 rtl8192_tx_isr(dev,TXCMD_QUEUE);
2840 if (inta & IMR_HIGHDOK) {
2841 rtl8192_tx_isr(dev,HIGH_QUEUE);
2846 priv->stats.rxint++;
2847 priv->InterruptLog.nIMR_ROK++;
2848 tasklet_schedule(&priv->irq_rx_tasklet);
2851 if (inta & IMR_BcnInt) {
2852 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
2853 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
2856 if (inta & IMR_RDU) {
2857 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2858 priv->stats.rxrdu++;
2859 write_nic_dword(dev,INTA_MASK,read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
2860 tasklet_schedule(&priv->irq_rx_tasklet);
2863 if (inta & IMR_RXFOVW) {
2864 RT_TRACE(COMP_INTR, "rx overflow !\n");
2865 priv->stats.rxoverflow++;
2866 tasklet_schedule(&priv->irq_rx_tasklet);
2869 if (inta & IMR_TXFOVW) priv->stats.txoverflow++;
2871 if (inta & IMR_BKDOK) {
2872 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
2873 priv->stats.txbkokint++;
2874 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2875 rtl8192_tx_isr(dev,BK_QUEUE);
2878 if (inta & IMR_BEDOK) {
2879 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
2880 priv->stats.txbeokint++;
2881 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2882 rtl8192_tx_isr(dev,BE_QUEUE);
2885 if (inta & IMR_VIDOK) {
2886 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
2887 priv->stats.txviokint++;
2888 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2889 rtl8192_tx_isr(dev,VI_QUEUE);
2892 if (inta & IMR_VODOK) {
2893 priv->stats.txvookint++;
2894 RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
2895 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2896 rtl8192_tx_isr(dev,VO_QUEUE);
2899 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
2908 /****************************************************************************
2909 ---------------------------- PCI_STUFF---------------------------
2910 *****************************************************************************/
2911 #ifdef HAVE_NET_DEVICE_OPS
2912 static const struct net_device_ops rtl8192_netdev_ops = {
2913 .ndo_open = rtl8192_open,
2914 .ndo_stop = rtl8192_close,
2915 .ndo_tx_timeout = rtl8192_tx_timeout,
2916 .ndo_do_ioctl = rtl8192_ioctl,
2917 .ndo_set_multicast_list = r8192_set_multicast,
2918 .ndo_set_mac_address = r8192_set_mac_adr,
2919 .ndo_validate_addr = eth_validate_addr,
2920 .ndo_change_mtu = eth_change_mtu,
2921 .ndo_start_xmit = rtllib_xmit,
2925 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
2926 const struct pci_device_id *id)
2928 unsigned long ioaddr = 0;
2929 struct net_device *dev = NULL;
2930 struct r8192_priv *priv= NULL;
2931 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2932 unsigned long pmem_start, pmem_len, pmem_flags;
2934 bool bdma64 = false;
2937 RT_TRACE(COMP_INIT,"Configuring chip resources");
2939 if ( pci_enable_device (pdev) ){
2940 RT_TRACE(COMP_ERR,"Failed to enable PCI device");
2944 pci_set_master(pdev);
2947 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2948 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
2949 printk( "Unable to obtain 32bit DMA for consistent allocations\n");
2950 pci_disable_device(pdev);
2955 dev = alloc_rtllib(sizeof(struct r8192_priv));
2960 dev->features |= NETIF_F_HIGHDMA;
2963 pci_set_drvdata(pdev, dev);
2964 SET_NETDEV_DEV(dev, &pdev->dev);
2965 priv = rtllib_priv(dev);
2966 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
2968 priv->rtllib->pdev=pdev;
2969 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304))
2970 priv->rtllib->bSupportRemoteWakeUp = 1;
2972 priv->rtllib->bSupportRemoteWakeUp = 0;
2974 pmem_start = pci_resource_start(pdev, 1);
2975 pmem_len = pci_resource_len(pdev, 1);
2976 pmem_flags = pci_resource_flags (pdev, 1);
2978 if (!(pmem_flags & IORESOURCE_MEM)) {
2979 RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting");
2983 printk("Memory mapped space start: 0x%08lx \n", pmem_start);
2984 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
2985 RT_TRACE(COMP_ERR,"request_mem_region failed!");
2990 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
2991 if ( ioaddr == (unsigned long)NULL ){
2992 RT_TRACE(COMP_ERR,"ioremap failed!");
2996 dev->mem_start = ioaddr;
2997 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
2999 pci_read_config_byte(pdev, 0x08, &revision_id);
3000 /* If the revisionid is 0x10, the device uses rtl8192se. */
3001 if (pdev->device == 0x8192 && revision_id == 0x10)
3006 if (rtl8192_pci_findadapter(pdev, dev) == false)
3009 dev->irq = pdev->irq;
3012 #ifdef HAVE_NET_DEVICE_OPS
3013 dev->netdev_ops = &rtl8192_netdev_ops;
3015 dev->open = rtl8192_open;
3016 dev->stop = rtl8192_close;
3017 dev->tx_timeout = rtl8192_tx_timeout;
3018 dev->do_ioctl = rtl8192_ioctl;
3019 dev->set_multicast_list = r8192_set_multicast;
3020 dev->set_mac_address = r8192_set_mac_adr;
3021 dev->hard_start_xmit = rtllib_xmit;
3024 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
3025 dev->ethtool_ops = &rtl819x_ethtool_ops;
3027 dev->type = ARPHRD_ETHER;
3028 dev->watchdog_timeo = HZ*3;
3030 if (dev_alloc_name(dev, ifname) < 0){
3031 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
3032 dev_alloc_name(dev, ifname);
3035 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
3036 if (rtl8192_init(dev)!=0){
3037 RT_TRACE(COMP_ERR, "Initialization failed");
3041 netif_carrier_off(dev);
3042 netif_stop_queue(dev);
3044 register_netdev(dev);
3045 RT_TRACE(COMP_INIT, "dev name: %s\n",dev->name);
3046 err = rtl_debug_module_init(priv, dev->name);
3048 RT_TRACE(COMP_DBG, "failed to create debugfs files. Ignoring error: %d\n", err);
3050 rtl8192_proc_init_one(dev);
3052 if (priv->polling_timer_on == 0){
3053 check_rfctrl_gpio_timer((unsigned long)dev);
3056 RT_TRACE(COMP_INIT, "Driver probe completed\n");
3060 if ( dev->mem_start != (unsigned long)NULL ){
3061 iounmap( (void *)dev->mem_start );
3062 release_mem_region( pci_resource_start(pdev, 1),
3063 pci_resource_len(pdev, 1) );
3070 free_irq(dev->irq, dev);
3076 pci_disable_device(pdev);
3078 DMESG("wlan driver load failed\n");
3079 pci_set_drvdata(pdev, NULL);
3084 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
3086 struct net_device *dev = pci_get_drvdata(pdev);
3087 struct r8192_priv *priv ;
3089 unregister_netdev(dev);
3091 priv = rtllib_priv(dev);
3093 del_timer_sync(&priv->gpio_polling_timer);
3094 cancel_delayed_work(&priv->gpio_change_rf_wq);
3095 priv->polling_timer_on = 0;
3096 rtl_debug_module_remove(priv);
3097 rtl8192_proc_remove_one(dev);
3098 rtl8192_down(dev,true);
3100 if (priv->pFirmware) {
3101 vfree(priv->pFirmware);
3102 priv->pFirmware = NULL;
3104 destroy_workqueue(priv->priv_wq);
3107 rtl8192_free_rx_ring(dev);
3108 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
3109 rtl8192_free_tx_ring(dev, i);
3115 printk("Freeing irq %d\n",dev->irq);
3116 free_irq(dev->irq, dev);
3123 kfree(priv->scan_cmd);
3125 if (dev->mem_start != 0) {
3126 iounmap((void *)dev->mem_start);
3127 release_mem_region(pci_resource_start(pdev, 1),
3128 pci_resource_len(pdev, 1));
3131 priv=rtllib_priv(dev);
3134 pci_disable_device(pdev);
3135 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
3138 bool NicIFEnableNIC(struct net_device* dev)
3140 bool init_status = true;
3141 struct r8192_priv * priv = rtllib_priv(dev);
3142 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)(&(priv->rtllib->PowerSaveControl));
3144 if (IS_NIC_DOWN(priv)){
3145 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__func__);
3146 priv->bdisable_nic = false;
3147 return RT_STATUS_FAILURE;
3150 RT_TRACE(COMP_PS, "===========>%s()\n",__func__);
3151 priv->bfirst_init = true;
3152 init_status = priv->ops->initialize_adapter(dev);
3153 if (init_status != true) {
3154 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__func__);
3155 priv->bdisable_nic = false;
3158 RT_TRACE(COMP_INIT, "start adapter finished\n");
3159 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
3160 priv->bfirst_init = false;
3162 rtl8192_irq_enable(dev);
3163 priv->bdisable_nic = false;
3164 RT_TRACE(COMP_PS,"<===========%s()\n",__func__);
3167 bool NicIFDisableNIC(struct net_device* dev)
3170 struct r8192_priv * priv = rtllib_priv(dev);
3172 RT_TRACE(COMP_PS, "=========>%s()\n",__func__);
3173 priv->bdisable_nic = true;
3174 tmp_state = priv->rtllib->state;
3175 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
3176 priv->rtllib->state = tmp_state;
3177 rtl8192_cancel_deferred_work(priv);
3178 rtl8192_irq_disable(dev);
3180 priv->ops->stop_adapter(dev, false);
3181 RT_TRACE(COMP_PS, "<=========%s()\n",__func__);
3186 static int __init rtl8192_pci_module_init(void)
3191 ret = rtllib_init();
3193 printk(KERN_ERR "rtllib_init() failed %d\n", ret);
3196 ret = rtllib_crypto_init();
3198 printk(KERN_ERR "rtllib_crypto_init() failed %d\n", ret);
3201 ret = rtllib_crypto_tkip_init();
3203 printk(KERN_ERR "rtllib_crypto_tkip_init() failed %d\n", ret);
3206 ret = rtllib_crypto_ccmp_init();
3208 printk(KERN_ERR "rtllib_crypto_ccmp_init() failed %d\n", ret);
3211 ret = rtllib_crypto_wep_init();
3213 printk(KERN_ERR "rtllib_crypto_wep_init() failed %d\n", ret);
3216 printk(KERN_INFO "\nLinux kernel driver for RTL8192E WLAN cards\n");
3217 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan Driver\n");
3219 error = rtl_create_debugfs_root();
3221 RT_TRACE(COMP_DBG, "Create debugfs root fail: %d\n", error);
3225 rtl8192_proc_module_init();
3226 if (0!=pci_register_driver(&rtl8192_pci_driver)) {
3227 DMESG("No device found");
3228 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3237 static void __exit rtl8192_pci_module_exit(void)
3239 pci_unregister_driver(&rtl8192_pci_driver);
3241 RT_TRACE(COMP_DOWN, "Exiting");
3242 rtl8192_proc_module_remove();
3243 rtl_remove_debugfs_root();
3244 rtllib_crypto_tkip_exit();
3245 rtllib_crypto_ccmp_exit();
3246 rtllib_crypto_wep_exit();
3247 rtllib_crypto_deinit();
3251 void check_rfctrl_gpio_timer(unsigned long data)
3253 struct r8192_priv * priv = rtllib_priv((struct net_device *)data);
3255 priv->polling_timer_on = 1;
3257 queue_delayed_work_rsl(priv->priv_wq,&priv->gpio_change_rf_wq,0);
3259 mod_timer(&priv->gpio_polling_timer, jiffies + MSECS(RTLLIB_WATCH_DOG_TIME));
3262 /***************************************************************************
3263 ------------------- module init / exit stubs ----------------
3264 ****************************************************************************/
3265 module_init(rtl8192_pci_module_init);
3266 module_exit(rtl8192_pci_module_exit);
3268 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
3269 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
3270 MODULE_VERSION(DRV_VERSION);
3271 MODULE_LICENSE("GPL");
3273 module_param(ifname, charp, S_IRUGO|S_IWUSR );
3274 module_param(hwwep,int, S_IRUGO|S_IWUSR);
3275 module_param(channels,int, S_IRUGO|S_IWUSR);
3277 MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
3278 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support(default use hw. set 0 to use software security)");
3279 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");