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 <andrea.merello@gmail.com>, 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);
97 static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
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 = rtl8192_pci_disconnect, /* remove fn */
104 .suspend = rtl8192E_suspend, /* PM suspend fn */
105 .resume = rtl8192E_resume, /* PM resume fn */
108 /****************************************************************************
109 -----------------------------IO STUFF-------------------------
110 *****************************************************************************/
111 static bool PlatformIOCheckPageLegalAndGetRegMask(u32 u4bPage, u8 *pu1bPageMask)
113 bool bReturn = false;
115 *pu1bPageMask = 0xfe;
118 case 1: case 2: case 3: case 4:
119 case 8: case 9: case 10: case 12: case 13:
121 *pu1bPageMask = 0xf0;
132 void write_nic_io_byte(struct net_device *dev, int x, u8 y)
134 u32 u4bPage = (x >> 8);
136 bool bIsLegalPage = false;
139 outb(y&0xff, dev->base_addr + x);
142 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
145 u8 u1bPsr = read_nic_io_byte(dev, PSR);
147 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
149 write_nic_io_byte(dev, (x & 0xff), y);
150 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
155 void write_nic_io_word(struct net_device *dev, int x, u16 y)
157 u32 u4bPage = (x >> 8);
159 bool bIsLegalPage = false;
162 outw(y, dev->base_addr + x);
164 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
167 u8 u1bPsr = read_nic_io_byte(dev, PSR);
169 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
171 write_nic_io_word(dev, (x & 0xff), y);
172 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
178 void write_nic_io_dword(struct net_device *dev, int x, u32 y)
180 u32 u4bPage = (x >> 8);
182 bool bIsLegalPage = false;
185 outl(y, dev->base_addr + x);
187 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
190 u8 u1bPsr = read_nic_io_byte(dev, PSR);
192 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
194 write_nic_io_dword(dev, (x & 0xff), y);
195 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
200 u8 read_nic_io_byte(struct net_device *dev, int x)
202 u32 u4bPage = (x >> 8);
204 bool bIsLegalPage = false;
208 return 0xff&inb(dev->base_addr + x);
210 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
213 u8 u1bPsr = read_nic_io_byte(dev, PSR);
215 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
217 Data = read_nic_io_byte(dev, (x & 0xff));
218 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
225 u16 read_nic_io_word(struct net_device *dev, int x)
227 u32 u4bPage = (x >> 8);
229 bool bIsLegalPage = false;
233 return inw(dev->base_addr + x);
235 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
238 u8 u1bPsr = read_nic_io_byte(dev, PSR);
240 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
242 Data = read_nic_io_word(dev, (x & 0xff));
243 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
251 u32 read_nic_io_dword(struct net_device *dev, int x)
253 u32 u4bPage = (x >> 8);
255 bool bIsLegalPage = false;
259 return inl(dev->base_addr + x);
261 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
264 u8 u1bPsr = read_nic_io_byte(dev, PSR);
266 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
268 Data = read_nic_io_dword(dev, (x & 0xff));
269 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
277 u8 read_nic_byte(struct net_device *dev, int x)
279 return 0xff & readb((u8 __iomem *)dev->mem_start + x);
282 u32 read_nic_dword(struct net_device *dev, int x)
284 return readl((u8 __iomem *)dev->mem_start + x);
287 u16 read_nic_word(struct net_device *dev, int x)
289 return readw((u8 __iomem *)dev->mem_start + x);
292 void write_nic_byte(struct net_device *dev, int x, u8 y)
294 writeb(y, (u8 __iomem *)dev->mem_start + x);
299 void write_nic_dword(struct net_device *dev, int x, u32 y)
301 writel(y, (u8 __iomem *)dev->mem_start + x);
306 void write_nic_word(struct net_device *dev, int x, u16 y)
308 writew(y, (u8 __iomem *)dev->mem_start + x);
313 /****************************************************************************
314 -----------------------------GENERAL FUNCTION-------------------------
315 *****************************************************************************/
316 bool MgntActSet_RF_State(struct net_device *dev,
317 enum rt_rf_power_state StateToSet,
318 RT_RF_CHANGE_SOURCE ChangeSource,
321 struct r8192_priv *priv = rtllib_priv(dev);
322 struct rtllib_device *ieee = priv->rtllib;
323 bool bActionAllowed = false;
324 bool bConnectBySSID = false;
325 enum rt_rf_power_state rtState;
326 u16 RFWaitCounter = 0;
328 RT_TRACE((COMP_PS | COMP_RF), "===>MgntActSet_RF_State(): "
329 "StateToSet(%d)\n", StateToSet);
331 ProtectOrNot = false;
336 spin_lock_irqsave(&priv->rf_ps_lock, flag);
337 if (priv->RFChangeInProgress) {
338 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
339 RT_TRACE((COMP_PS | COMP_RF),
340 "MgntActSet_RF_State(): RF Change in "
341 "progress! Wait to set..StateToSet"
342 "(%d).\n", StateToSet);
344 while (priv->RFChangeInProgress) {
346 RT_TRACE((COMP_PS | COMP_RF),
347 "MgntActSet_RF_State(): Wait 1"
348 " ms (%d times)...\n",
352 if (RFWaitCounter > 100) {
353 RT_TRACE(COMP_ERR, "MgntActSet_"
354 "RF_State(): Wait too "
360 priv->RFChangeInProgress = true;
361 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
367 rtState = priv->rtllib->eRFPowerState;
369 switch (StateToSet) {
371 priv->rtllib->RfOffReason &= (~ChangeSource);
373 if ((ChangeSource == RF_CHANGE_BY_HW) && priv->bHwRadioOff)
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) && !priv->bHwRadioOff)
408 priv->bHwRadioOff = true;
409 priv->rtllib->RfOffReason |= ChangeSource;
410 bActionAllowed = true;
414 priv->rtllib->RfOffReason |= ChangeSource;
415 bActionAllowed = true;
422 if (bActionAllowed) {
423 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Action is"
424 " allowed.... StateToSet(%d), RfOffReason(%#X)\n",
425 StateToSet, priv->rtllib->RfOffReason);
426 PHY_SetRFPowerState(dev, StateToSet);
427 if (StateToSet == eRfOn) {
429 if (bConnectBySSID && priv->blinked_ingpio) {
430 queue_delayed_work_rsl(ieee->wq,
431 &ieee->associate_procedure_wq, 0);
432 priv->blinked_ingpio = false;
436 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): "
437 "Action is rejected.... StateToSet(%d), ChangeSource"
438 "(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource,
439 priv->rtllib->RfOffReason);
443 spin_lock_irqsave(&priv->rf_ps_lock, flag);
444 priv->RFChangeInProgress = false;
445 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
448 RT_TRACE((COMP_PS | COMP_RF), "<===MgntActSet_RF_State()\n");
449 return bActionAllowed;
453 static short rtl8192_get_nic_desc_num(struct net_device *dev, int prio)
455 struct r8192_priv *priv = rtllib_priv(dev);
456 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
458 /* For now, we reserved two free descriptor as a safety boundary
459 * between the tail and the head
461 if ((prio == MGNT_QUEUE) && (skb_queue_len(&ring->queue) > 10))
462 RT_TRACE(COMP_DBG, "-----[%d]---------ring->idx=%d "
463 "queue_len=%d---------\n", prio, ring->idx,
464 skb_queue_len(&ring->queue));
465 return skb_queue_len(&ring->queue);
468 static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
470 struct r8192_priv *priv = rtllib_priv(dev);
471 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
473 if (ring->entries - skb_queue_len(&ring->queue) >= 2)
478 void rtl8192_tx_timeout(struct net_device *dev)
480 struct r8192_priv *priv = rtllib_priv(dev);
482 schedule_work(&priv->reset_wq);
483 printk(KERN_INFO "TXTIMEOUT");
486 void rtl8192_irq_enable(struct net_device *dev)
488 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
489 priv->irq_enabled = 1;
491 priv->ops->irq_enable(dev);
494 void rtl8192_irq_disable(struct net_device *dev)
496 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
498 priv->ops->irq_disable(dev);
500 priv->irq_enabled = 0;
503 void rtl8192_set_chan(struct net_device *dev, short ch)
505 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
507 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
508 if (priv->chan_forced)
513 if (priv->rf_set_chan)
514 priv->rf_set_chan(dev, priv->chan);
517 void rtl8192_update_cap(struct net_device *dev, u16 cap)
519 struct r8192_priv *priv = rtllib_priv(dev);
520 struct rtllib_network *net = &priv->rtllib->current_network;
523 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) {
524 if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT) {
525 ShortPreamble = true;
526 priv->dot11CurrentPreambleMode = PREAMBLE_SHORT;
527 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_SHORT_"
528 "PREAMBLE\n", __func__);
529 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
530 (unsigned char *)&ShortPreamble);
533 if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG) {
534 ShortPreamble = false;
535 priv->dot11CurrentPreambleMode = PREAMBLE_LONG;
536 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_LONG_"
537 "PREAMBLE\n", __func__);
538 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
539 (unsigned char *)&ShortPreamble);
543 if (net->mode & (IEEE_G|IEEE_N_24G)) {
545 u8 CurSlotTime = priv->slot_time;
547 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
548 (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime)) {
549 if (CurSlotTime != SHORT_SLOT_TIME) {
550 slot_time_val = SHORT_SLOT_TIME;
551 priv->rtllib->SetHwRegHandler(dev,
552 HW_VAR_SLOT_TIME, &slot_time_val);
555 if (CurSlotTime != NON_SHORT_SLOT_TIME) {
556 slot_time_val = NON_SHORT_SLOT_TIME;
557 priv->rtllib->SetHwRegHandler(dev,
558 HW_VAR_SLOT_TIME, &slot_time_val);
564 static struct rtllib_qos_parameters def_qos_parameters = {
565 {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)},
566 {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)},
572 static void rtl8192_update_beacon(void *data)
574 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
575 update_beacon_wq.work);
576 struct net_device *dev = priv->rtllib->dev;
577 struct rtllib_device *ieee = priv->rtllib;
578 struct rtllib_network *net = &ieee->current_network;
580 if (ieee->pHTInfo->bCurrentHTSupport)
581 HT_update_self_and_peer_setting(ieee, net);
582 ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
583 net->bssht.bdRT2RTLongSlotTime;
584 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
585 rtl8192_update_cap(dev, net->capability);
588 static void rtl8192_qos_activate(void *data)
590 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
592 struct net_device *dev = priv->rtllib->dev;
595 mutex_lock(&priv->mutex);
596 if (priv->rtllib->state != RTLLIB_LINKED)
598 RT_TRACE(COMP_QOS, "qos active process with associate response "
601 for (i = 0; i < QOS_QUEUE_NUM; i++) {
602 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i));
606 mutex_unlock(&priv->mutex);
609 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
611 struct rtllib_network *network)
614 u32 size = sizeof(struct rtllib_qos_parameters);
616 if (priv->rtllib->state != RTLLIB_LINKED)
619 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
622 if (network->flags & NETWORK_HAS_QOS_MASK) {
623 if (active_network &&
624 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
625 network->qos_data.active = network->qos_data.supported;
627 if ((network->qos_data.active == 1) && (active_network == 1) &&
628 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
629 (network->qos_data.old_param_count !=
630 network->qos_data.param_count)) {
631 network->qos_data.old_param_count =
632 network->qos_data.param_count;
633 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
634 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
635 RT_TRACE(COMP_QOS, "QoS parameters change call "
639 memcpy(&priv->rtllib->current_network.qos_data.parameters,
640 &def_qos_parameters, size);
642 if ((network->qos_data.active == 1) && (active_network == 1)) {
643 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
644 RT_TRACE(COMP_QOS, "QoS was disabled call qos_"
647 network->qos_data.active = 0;
648 network->qos_data.supported = 0;
654 static int rtl8192_handle_beacon(struct net_device *dev,
655 struct rtllib_beacon *beacon,
656 struct rtllib_network *network)
658 struct r8192_priv *priv = rtllib_priv(dev);
660 rtl8192_qos_handle_probe_response(priv, 1, network);
662 queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
667 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
668 struct rtllib_network *network)
672 u32 size = sizeof(struct rtllib_qos_parameters);
673 int set_qos_param = 0;
675 if ((priv == NULL) || (network == NULL))
678 if (priv->rtllib->state != RTLLIB_LINKED)
681 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
684 spin_lock_irqsave(&priv->rtllib->lock, flags);
685 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
686 memcpy(&priv->rtllib->current_network.qos_data.parameters,
687 &network->qos_data.parameters,
688 sizeof(struct rtllib_qos_parameters));
689 priv->rtllib->current_network.qos_data.active = 1;
690 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
692 priv->rtllib->current_network.qos_data.old_param_count =
693 priv->rtllib->current_network.qos_data.param_count;
694 priv->rtllib->current_network.qos_data.param_count =
695 network->qos_data.param_count;
697 memcpy(&priv->rtllib->current_network.qos_data.parameters,
698 &def_qos_parameters, size);
699 priv->rtllib->current_network.qos_data.active = 0;
700 priv->rtllib->current_network.qos_data.supported = 0;
704 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
706 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
707 network->flags, priv->rtllib->current_network.qos_data.active);
708 if (set_qos_param == 1) {
709 dm_init_edca_turbo(priv->rtllib->dev);
710 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
715 static int rtl8192_handle_assoc_response(struct net_device *dev,
716 struct rtllib_assoc_response_frame *resp,
717 struct rtllib_network *network)
719 struct r8192_priv *priv = rtllib_priv(dev);
720 rtl8192_qos_association_resp(priv, network);
724 static void rtl8192_prepare_beacon(struct r8192_priv *priv)
726 struct net_device *dev = priv->rtllib->dev;
727 struct sk_buff *pskb = NULL, *pnewskb = NULL;
728 struct cb_desc *tcb_desc = NULL;
729 struct rtl8192_tx_ring *ring = NULL;
730 struct tx_desc *pdesc = NULL;
732 ring = &priv->tx_ring[BEACON_QUEUE];
733 pskb = __skb_dequeue(&ring->queue);
736 pnewskb = rtllib_get_beacon(priv->rtllib);
740 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
741 tcb_desc->queue_index = BEACON_QUEUE;
742 tcb_desc->data_rate = 2;
743 tcb_desc->RATRIndex = 7;
744 tcb_desc->bTxDisableRateFallBack = 1;
745 tcb_desc->bTxUseDriverAssingedRate = 1;
746 skb_push(pnewskb, priv->rtllib->tx_headroom);
748 pdesc = &ring->desc[0];
749 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
750 __skb_queue_tail(&ring->queue, pnewskb);
756 static void rtl8192_stop_beacon(struct net_device *dev)
760 void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
762 struct r8192_priv *priv = rtllib_priv(dev);
763 struct rtllib_network *net;
764 u8 i = 0, basic_rate = 0;
765 net = &priv->rtllib->current_network;
767 for (i = 0; i < net->rates_len; i++) {
768 basic_rate = net->rates[i] & 0x7f;
769 switch (basic_rate) {
771 *rate_config |= RRSR_1M;
774 *rate_config |= RRSR_2M;
777 *rate_config |= RRSR_5_5M;
780 *rate_config |= RRSR_11M;
783 *rate_config |= RRSR_6M;
786 *rate_config |= RRSR_9M;
789 *rate_config |= RRSR_12M;
792 *rate_config |= RRSR_18M;
795 *rate_config |= RRSR_24M;
798 *rate_config |= RRSR_36M;
801 *rate_config |= RRSR_48M;
804 *rate_config |= RRSR_54M;
809 for (i = 0; i < net->rates_ex_len; i++) {
810 basic_rate = net->rates_ex[i] & 0x7f;
811 switch (basic_rate) {
813 *rate_config |= RRSR_1M;
816 *rate_config |= RRSR_2M;
819 *rate_config |= RRSR_5_5M;
822 *rate_config |= RRSR_11M;
825 *rate_config |= RRSR_6M;
828 *rate_config |= RRSR_9M;
831 *rate_config |= RRSR_12M;
834 *rate_config |= RRSR_18M;
837 *rate_config |= RRSR_24M;
840 *rate_config |= RRSR_36M;
843 *rate_config |= RRSR_48M;
846 *rate_config |= RRSR_54M;
852 static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
854 struct rtllib_device *ieee = priv->rtllib;
855 if (ieee->mode == WIRELESS_MODE_N_24G ||
856 ieee->mode == WIRELESS_MODE_N_5G) {
857 memcpy(ieee->Regdot11HTOperationalRateSet,
858 ieee->RegHTSuppRateSet, 16);
859 memcpy(ieee->Regdot11TxHTOperationalRateSet,
860 ieee->RegHTSuppRateSet, 16);
863 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
868 static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
870 struct r8192_priv *priv = rtllib_priv(dev);
873 switch (priv->rf_chip) {
878 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B);
881 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
884 ret = WIRELESS_MODE_B;
890 void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
892 struct r8192_priv *priv = rtllib_priv(dev);
893 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
895 if ((wireless_mode == WIRELESS_MODE_AUTO) ||
896 ((wireless_mode & bSupportMode) == 0)) {
897 if (bSupportMode & WIRELESS_MODE_N_24G) {
898 wireless_mode = WIRELESS_MODE_N_24G;
899 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
900 wireless_mode = WIRELESS_MODE_N_5G;
901 } else if ((bSupportMode & WIRELESS_MODE_A)) {
902 wireless_mode = WIRELESS_MODE_A;
903 } else if ((bSupportMode & WIRELESS_MODE_G)) {
904 wireless_mode = WIRELESS_MODE_G;
905 } else if ((bSupportMode & WIRELESS_MODE_B)) {
906 wireless_mode = WIRELESS_MODE_B;
908 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode "
909 "supported (%x)!!!\n", __func__, bSupportMode);
910 wireless_mode = WIRELESS_MODE_B;
914 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) ==
915 (WIRELESS_MODE_G | WIRELESS_MODE_B))
916 wireless_mode = WIRELESS_MODE_G;
918 priv->rtllib->mode = wireless_mode;
920 ActUpdateChannelAccessSetting(dev, wireless_mode,
921 &priv->ChannelAccessSetting);
923 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
924 (wireless_mode == WIRELESS_MODE_N_5G)) {
925 priv->rtllib->pHTInfo->bEnableHT = 1;
926 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n",
927 __func__, wireless_mode);
929 priv->rtllib->pHTInfo->bEnableHT = 0;
930 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n",
931 __func__, wireless_mode);
934 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
935 rtl8192_refresh_supportrate(priv);
938 static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
940 struct r8192_priv *priv = rtllib_priv(dev);
941 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
942 (&(priv->rtllib->PowerSaveControl));
943 bool init_status = true;
944 priv->bDriverIsGoingToUnload = false;
945 priv->bdisable_nic = false;
948 priv->rtllib->ieee_up = 1;
950 priv->up_first_time = 0;
951 RT_TRACE(COMP_INIT, "Bringing up iface");
952 priv->bfirst_init = true;
953 init_status = priv->ops->initialize_adapter(dev);
955 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
957 priv->bfirst_init = false;
961 RT_TRACE(COMP_INIT, "start adapter finished\n");
962 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
963 priv->bfirst_init = false;
965 if (priv->polling_timer_on == 0)
966 check_rfctrl_gpio_timer((unsigned long)dev);
968 if (priv->rtllib->state != RTLLIB_LINKED)
969 rtllib_softmac_start_protocol(priv->rtllib, 0);
970 rtllib_reset_queue(priv->rtllib);
971 watch_dog_timer_callback((unsigned long) dev);
973 if (!netif_queue_stopped(dev))
974 netif_start_queue(dev);
976 netif_wake_queue(dev);
981 static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
983 struct r8192_priv *priv = rtllib_priv(dev);
984 unsigned long flags = 0;
985 u8 RFInProgressTimeOut = 0;
990 if (priv->rtllib->rtllib_ips_leave != NULL)
991 priv->rtllib->rtllib_ips_leave(dev);
993 if (priv->rtllib->state == RTLLIB_LINKED)
996 priv->bDriverIsGoingToUnload = true;
998 priv->rtllib->ieee_up = 0;
999 priv->bfirst_after_down = true;
1000 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
1001 if (!netif_queue_stopped(dev))
1002 netif_stop_queue(dev);
1004 priv->rtllib->wpa_ie_len = 0;
1005 kfree(priv->rtllib->wpa_ie);
1006 priv->rtllib->wpa_ie = NULL;
1007 CamResetAllEntry(dev);
1008 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1009 rtl8192_irq_disable(dev);
1011 del_timer_sync(&priv->watch_dog_timer);
1012 rtl8192_cancel_deferred_work(priv);
1013 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
1015 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1016 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1017 while (priv->RFChangeInProgress) {
1018 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1019 if (RFInProgressTimeOut > 100) {
1020 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1023 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait "
1024 "until rf change is done.\n", __func__);
1026 RFInProgressTimeOut++;
1027 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1029 priv->RFChangeInProgress = true;
1030 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1031 priv->ops->stop_adapter(dev, false);
1032 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1033 priv->RFChangeInProgress = false;
1034 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1036 memset(&priv->rtllib->current_network, 0,
1037 offsetof(struct rtllib_network, list));
1038 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
1043 static void rtl8192_init_priv_handler(struct net_device *dev)
1045 struct r8192_priv *priv = rtllib_priv(dev);
1047 priv->rtllib->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
1048 priv->rtllib->set_chan = rtl8192_set_chan;
1049 priv->rtllib->link_change = priv->ops->link_change;
1050 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1051 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1052 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1053 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1054 priv->rtllib->get_nic_desc_num = rtl8192_get_nic_desc_num;
1055 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1056 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1057 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode;
1058 priv->rtllib->LeisurePSLeave = LeisurePSLeave;
1059 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode;
1060 priv->rf_set_chan = rtl8192_phy_SwChnl;
1062 priv->rtllib->start_send_beacons = rtl8192e_start_beacon;
1063 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
1065 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup;
1066 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep;
1067 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1069 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg;
1070 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
1071 rtl8192_GetHalfNmodeSupportByAPs;
1073 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg;
1074 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr;
1075 priv->rtllib->SetFwCmdHandler = NULL;
1076 priv->rtllib->InitialGainHandler = InitialGain819xPci;
1077 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq;
1078 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave;
1080 priv->rtllib->LedControlHandler = NULL;
1081 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1083 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192;
1085 priv->rtllib->rtllib_rfkill_poll = NULL;
1088 static void rtl8192_init_priv_constant(struct net_device *dev)
1090 struct r8192_priv *priv = rtllib_priv(dev);
1091 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1092 &(priv->rtllib->PowerSaveControl);
1094 pPSC->RegMaxLPSAwakeIntvl = 5;
1096 priv->RegPciASPM = 2;
1098 priv->RegDevicePciASPMSetting = 0x03;
1100 priv->RegHostPciASPMSetting = 0x02;
1102 priv->RegHwSwRfOffD3 = 2;
1104 priv->RegSupportPciASPM = 2;
1108 static void rtl8192_init_priv_variable(struct net_device *dev)
1110 struct r8192_priv *priv = rtllib_priv(dev);
1113 priv->AcmMethod = eAcmWay2_SW;
1114 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
1115 priv->rtllib->hwscan_sem_up = 1;
1116 priv->rtllib->status = 0;
1117 priv->H2CTxCmdSeq = 0;
1118 priv->bDisableFrameBursting = false;
1119 priv->bDMInitialGainEnable = true;
1120 priv->polling_timer_on = 0;
1121 priv->up_first_time = 1;
1122 priv->blinked_ingpio = false;
1123 priv->bDriverIsGoingToUnload = false;
1124 priv->being_init_adapter = false;
1125 priv->initialized_at_probe = false;
1126 priv->sw_radio_on = true;
1127 priv->bdisable_nic = false;
1128 priv->bfirst_init = false;
1129 priv->txringcount = 64;
1130 priv->rxbuffersize = 9100;
1131 priv->rxringcount = MAX_RX_COUNT;
1132 priv->irq_enabled = 0;
1134 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
1135 priv->RegChannelPlan = 0xf;
1136 priv->nrxAMPDU_size = 0;
1137 priv->nrxAMPDU_aggr_num = 0;
1138 priv->last_rxdesc_tsf_high = 0;
1139 priv->last_rxdesc_tsf_low = 0;
1140 priv->rtllib->mode = WIRELESS_MODE_AUTO;
1141 priv->rtllib->iw_mode = IW_MODE_INFRA;
1142 priv->rtllib->bNetPromiscuousMode = false;
1143 priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false;
1144 priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1146 priv->rtllib->ieee_up = 0;
1147 priv->retry_rts = DEFAULT_RETRY_RTS;
1148 priv->retry_data = DEFAULT_RETRY_DATA;
1149 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
1150 priv->rtllib->rate = 110;
1151 priv->rtllib->short_slot = 1;
1152 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
1153 priv->bcck_in_ch14 = false;
1154 priv->bfsync_processing = false;
1155 priv->CCKPresentAttentuation = 0;
1156 priv->rfa_txpowertrackingindex = 0;
1157 priv->rfc_txpowertrackingindex = 0;
1159 priv->ScanDelay = 50;
1160 priv->ResetProgress = RESET_TYPE_NORESET;
1161 priv->bForcedSilentReset = false;
1162 priv->bDisableNormalResetCheck = false;
1163 priv->force_reset = false;
1164 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1166 memset(&priv->InterruptLog, 0, sizeof(struct log_int_8190));
1167 priv->RxCounter = 0;
1168 priv->rtllib->wx_set_enc = 0;
1169 priv->bHwRadioOff = false;
1170 priv->RegRfOff = false;
1171 priv->isRFOff = false;
1172 priv->bInPowerSaveMode = false;
1173 priv->rtllib->RfOffReason = 0;
1174 priv->RFChangeInProgress = false;
1175 priv->bHwRfOffAction = 0;
1176 priv->SetRFPowerStateInProgress = false;
1177 priv->rtllib->PowerSaveControl.bInactivePs = true;
1178 priv->rtllib->PowerSaveControl.bIPSModeBackup = false;
1179 priv->rtllib->PowerSaveControl.bLeisurePs = true;
1180 priv->rtllib->PowerSaveControl.bFwCtrlLPS = false;
1181 priv->rtllib->LPSDelayCnt = 0;
1182 priv->rtllib->sta_sleep = LPS_IS_WAKE;
1183 priv->rtllib->eRFPowerState = eRfOn;
1185 priv->txpower_checkcnt = 0;
1186 priv->thermal_readback_index = 0;
1187 priv->txpower_tracking_callback_cnt = 0;
1188 priv->ccktxpower_adjustcnt_ch14 = 0;
1189 priv->ccktxpower_adjustcnt_not_ch14 = 0;
1191 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
1192 priv->rtllib->iw_mode = IW_MODE_INFRA;
1193 priv->rtllib->active_scan = 1;
1194 priv->rtllib->be_scan_inprogress = false;
1195 priv->rtllib->modulation = RTLLIB_CCK_MODULATION |
1196 RTLLIB_OFDM_MODULATION;
1197 priv->rtllib->host_encrypt = 1;
1198 priv->rtllib->host_decrypt = 1;
1200 priv->rtllib->dot11PowerSaveMode = eActive;
1201 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
1202 priv->rtllib->MaxMssDensity = 0;
1203 priv->rtllib->MinSpaceCfg = 0;
1205 priv->card_type = PCI;
1207 priv->AcmControl = 0;
1208 priv->pFirmware = vzalloc(sizeof(struct rt_firmware));
1209 if (!priv->pFirmware)
1210 printk(KERN_ERR "rtl8192e: Unable to allocate space "
1213 skb_queue_head_init(&priv->rx_queue);
1214 skb_queue_head_init(&priv->skb_queue);
1216 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1217 skb_queue_head_init(&priv->rtllib->skb_waitQ[i]);
1218 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1219 skb_queue_head_init(&priv->rtllib->skb_aggQ[i]);
1222 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
1224 spin_lock_init(&priv->fw_scan_lock);
1225 spin_lock_init(&priv->tx_lock);
1226 spin_lock_init(&priv->irq_lock);
1227 spin_lock_init(&priv->irq_th_lock);
1228 spin_lock_init(&priv->rf_ps_lock);
1229 spin_lock_init(&priv->ps_lock);
1230 spin_lock_init(&priv->rf_lock);
1231 spin_lock_init(&priv->rt_h2c_lock);
1232 sema_init(&priv->wx_sem, 1);
1233 sema_init(&priv->rf_sem, 1);
1234 mutex_init(&priv->mutex);
1237 static void rtl8192_init_priv_task(struct net_device *dev)
1239 struct r8192_priv *priv = rtllib_priv(dev);
1241 priv->priv_wq = create_workqueue(DRV_NAME);
1242 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
1243 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)IPSLeave_wq, dev);
1244 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
1245 (void *)rtl819x_watchdog_wqcallback, dev);
1246 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
1247 (void *)dm_txpower_trackingcallback, dev);
1248 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
1249 (void *)dm_rf_pathcheck_workitemcallback, dev);
1250 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
1251 (void *)rtl8192_update_beacon, dev);
1252 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
1253 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
1254 (void *) rtl8192_hw_wakeup_wq, dev);
1255 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
1256 (void *) rtl8192_hw_sleep_wq, dev);
1257 tasklet_init(&priv->irq_rx_tasklet,
1258 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1259 (unsigned long)priv);
1260 tasklet_init(&priv->irq_tx_tasklet,
1261 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
1262 (unsigned long)priv);
1263 tasklet_init(&priv->irq_prepare_beacon_tasklet,
1264 (void(*)(unsigned long))rtl8192_prepare_beacon,
1265 (unsigned long)priv);
1268 static short rtl8192_get_channel_map(struct net_device *dev)
1272 struct r8192_priv *priv = rtllib_priv(dev);
1273 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256)
1274 && (priv->rf_chip != RF_6052)) {
1275 RT_TRACE(COMP_ERR, "%s: unknown rf chip, can't set channel "
1280 if (priv->ChannelPlan >= COUNTRY_CODE_MAX) {
1281 printk(KERN_INFO "rtl819x_init:Error channel plan! Set to "
1283 priv->ChannelPlan = COUNTRY_CODE_FCC;
1285 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
1286 dot11d_init(priv->rtllib);
1287 Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib);
1288 for (i = 1; i <= 11; i++)
1289 (priv->rtllib->active_channel_map)[i] = 1;
1290 (priv->rtllib->active_channel_map)[12] = 2;
1291 (priv->rtllib->active_channel_map)[13] = 2;
1296 static short rtl8192_init(struct net_device *dev)
1298 struct r8192_priv *priv = rtllib_priv(dev);
1300 memset(&(priv->stats), 0, sizeof(struct rt_stats));
1302 rtl8192_init_priv_handler(dev);
1303 rtl8192_init_priv_constant(dev);
1304 rtl8192_init_priv_variable(dev);
1305 rtl8192_init_priv_lock(priv);
1306 rtl8192_init_priv_task(dev);
1307 priv->ops->get_eeprom_size(dev);
1308 priv->ops->init_adapter_variable(dev);
1309 rtl8192_get_channel_map(dev);
1313 init_timer(&priv->watch_dog_timer);
1314 setup_timer(&priv->watch_dog_timer,
1315 watch_dog_timer_callback,
1316 (unsigned long) dev);
1318 init_timer(&priv->gpio_polling_timer);
1319 setup_timer(&priv->gpio_polling_timer,
1320 check_rfctrl_gpio_timer,
1321 (unsigned long)dev);
1323 rtl8192_irq_disable(dev);
1324 if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED,
1326 printk(KERN_ERR "Error allocating IRQ %d", dev->irq);
1329 priv->irq = dev->irq;
1330 RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq);
1333 if (rtl8192_pci_initdescring(dev) != 0) {
1334 printk(KERN_ERR "Endopoints initialization failed");
1335 free_irq(dev->irq, dev);
1342 /***************************************************************************
1343 -------------------------------WATCHDOG STUFF---------------------------
1344 ***************************************************************************/
1345 short rtl8192_is_tx_queue_empty(struct net_device *dev)
1348 struct r8192_priv *priv = rtllib_priv(dev);
1349 for (i = 0; i <= MGNT_QUEUE; i++) {
1350 if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE))
1352 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) {
1353 printk(KERN_INFO "===>tx queue is not empty:%d, %d\n",
1354 i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1361 static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
1363 struct r8192_priv *priv = rtllib_priv(dev);
1365 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1366 bool bCheckFwTxCnt = false;
1367 struct rtl8192_tx_ring *ring = NULL;
1368 struct sk_buff *skb = NULL;
1369 struct cb_desc *tcb_desc = NULL;
1370 unsigned long flags = 0;
1372 switch (priv->rtllib->ps) {
1373 case RTLLIB_PS_DISABLED:
1374 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
1376 case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
1377 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1380 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1383 spin_lock_irqsave(&priv->irq_th_lock, flags);
1384 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) {
1385 if (QueueID == TXCMD_QUEUE)
1388 if (QueueID == BEACON_QUEUE)
1391 ring = &priv->tx_ring[QueueID];
1393 if (skb_queue_len(&ring->queue) == 0) {
1396 skb = (&ring->queue)->next;
1397 tcb_desc = (struct cb_desc *)(skb->cb +
1399 tcb_desc->nStuckCount++;
1400 bCheckFwTxCnt = true;
1401 if (tcb_desc->nStuckCount > 1)
1402 printk(KERN_INFO "%s: QueueID=%d tcb_desc->n"
1403 "StuckCount=%d\n", __func__, QueueID,
1404 tcb_desc->nStuckCount);
1407 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1409 if (bCheckFwTxCnt) {
1410 if (priv->ops->TxCheckStuckHandler(dev)) {
1411 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no"
1412 " Tx condition!\n");
1413 return RESET_TYPE_SILENT;
1417 return RESET_TYPE_NORESET;
1420 static enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
1422 struct r8192_priv *priv = rtllib_priv(dev);
1424 if (priv->ops->RxCheckStuckHandler(dev)) {
1425 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
1426 return RESET_TYPE_SILENT;
1429 return RESET_TYPE_NORESET;
1432 static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
1434 struct r8192_priv *priv = rtllib_priv(dev);
1435 enum reset_type TxResetType = RESET_TYPE_NORESET;
1436 enum reset_type RxResetType = RESET_TYPE_NORESET;
1437 enum rt_rf_power_state rfState;
1439 rfState = priv->rtllib->eRFPowerState;
1441 if (rfState == eRfOn)
1442 TxResetType = rtl819x_TxCheckStuck(dev);
1444 if (rfState == eRfOn &&
1445 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1446 (priv->rtllib->state == RTLLIB_LINKED))
1447 RxResetType = rtl819x_RxCheckStuck(dev);
1449 if (TxResetType == RESET_TYPE_NORMAL ||
1450 RxResetType == RESET_TYPE_NORMAL) {
1451 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1452 __func__, TxResetType, RxResetType);
1453 return RESET_TYPE_NORMAL;
1454 } else if (TxResetType == RESET_TYPE_SILENT ||
1455 RxResetType == RESET_TYPE_SILENT) {
1456 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1457 __func__, TxResetType, RxResetType);
1458 return RESET_TYPE_SILENT;
1460 return RESET_TYPE_NORESET;
1465 static void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
1469 static void rtl819x_ifsilentreset(struct net_device *dev)
1471 struct r8192_priv *priv = rtllib_priv(dev);
1473 int reset_status = 0;
1474 struct rtllib_device *ieee = priv->rtllib;
1480 if (priv->ResetProgress == RESET_TYPE_NORESET) {
1482 RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
1484 priv->ResetProgress = RESET_TYPE_SILENT;
1486 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1487 if (priv->RFChangeInProgress) {
1488 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1491 priv->RFChangeInProgress = true;
1492 priv->bResetInProgress = true;
1493 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1497 down(&priv->wx_sem);
1499 if (priv->rtllib->state == RTLLIB_LINKED)
1500 LeisurePSLeave(dev);
1502 if (IS_NIC_DOWN(priv)) {
1503 RT_TRACE(COMP_ERR, "%s():the driver is not up! "
1504 "return\n", __func__);
1510 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n",
1513 RT_TRACE(COMP_RESET, "%s():111111111111111111111111======>start"
1514 " to down the driver\n", __func__);
1516 if (!netif_queue_stopped(dev))
1517 netif_stop_queue(dev);
1519 rtl8192_irq_disable(dev);
1520 del_timer_sync(&priv->watch_dog_timer);
1521 rtl8192_cancel_deferred_work(priv);
1523 rtllib_stop_scan_syncro(ieee);
1525 if (ieee->state == RTLLIB_LINKED) {
1526 SEM_DOWN_IEEE_WX(&ieee->wx_sem);
1527 printk(KERN_INFO "ieee->state is RTLLIB_LINKED\n");
1528 rtllib_stop_send_beacons(priv->rtllib);
1529 del_timer_sync(&ieee->associate_timer);
1530 cancel_delayed_work(&ieee->associate_retry_wq);
1531 rtllib_stop_scan(ieee);
1532 netif_carrier_off(dev);
1533 SEM_UP_IEEE_WX(&ieee->wx_sem);
1535 printk(KERN_INFO "ieee->state is NOT LINKED\n");
1536 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
1539 dm_backup_dynamic_mechanism_state(dev);
1542 RT_TRACE(COMP_RESET, "%s():<==========down process is "
1543 "finished\n", __func__);
1545 RT_TRACE(COMP_RESET, "%s():<===========up process start\n",
1547 reset_status = _rtl8192_up(dev, true);
1549 RT_TRACE(COMP_RESET, "%s():<===========up process is "
1550 "finished\n", __func__);
1551 if (reset_status == -1) {
1552 if (reset_times < 3) {
1556 RT_TRACE(COMP_ERR, " ERR!!! %s(): Reset "
1557 "Failed!!\n", __func__);
1561 ieee->is_silent_reset = 1;
1563 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1564 priv->RFChangeInProgress = false;
1565 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1567 EnableHWSecurityConfig8192(dev);
1569 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1571 ieee->set_chan(ieee->dev,
1572 ieee->current_network.channel);
1574 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1576 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1578 ieee->set_chan(ieee->dev,
1579 ieee->current_network.channel);
1580 ieee->link_change(ieee->dev);
1582 notify_wx_assoc_event(ieee);
1584 rtllib_start_send_beacons(ieee);
1586 if (ieee->data_hard_resume)
1587 ieee->data_hard_resume(ieee->dev);
1588 netif_carrier_on(ieee->dev);
1589 } else if (ieee->iw_mode == IW_MODE_MESH) {
1590 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1593 CamRestoreAllEntry(dev);
1594 dm_restore_dynamic_mechanism_state(dev);
1596 priv->ResetProgress = RESET_TYPE_NORESET;
1597 priv->reset_count++;
1599 priv->bForcedSilentReset = false;
1600 priv->bResetInProgress = false;
1602 write_nic_byte(dev, UFWP, 1);
1603 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n",
1608 static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1609 u32 *TotalRxDataNum)
1615 *TotalRxDataNum = 0;
1617 SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++) %
1618 (priv->rtllib->LinkDetectInfo.SlotNum);
1619 priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] =
1620 priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod;
1621 priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] =
1622 priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod;
1623 for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) {
1624 *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i];
1625 *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i];
1630 void rtl819x_watchdog_wqcallback(void *data)
1632 struct r8192_priv *priv = container_of_dwork_rsl(data,
1633 struct r8192_priv, watch_dog_wq);
1634 struct net_device *dev = priv->rtllib->dev;
1635 struct rtllib_device *ieee = priv->rtllib;
1636 enum reset_type ResetType = RESET_TYPE_NORESET;
1637 static u8 check_reset_cnt;
1638 unsigned long flags;
1639 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1640 (&(priv->rtllib->PowerSaveControl));
1641 bool bBusyTraffic = false;
1642 bool bHigherBusyTraffic = false;
1643 bool bHigherBusyRxTraffic = false;
1644 bool bEnterPS = false;
1646 if (IS_NIC_DOWN(priv) || priv->bHwRadioOff)
1649 if (priv->rtllib->state >= RTLLIB_LINKED) {
1650 if (priv->rtllib->CntAfterLink < 2)
1651 priv->rtllib->CntAfterLink++;
1653 priv->rtllib->CntAfterLink = 0;
1656 hal_dm_watchdog(dev);
1658 if (rtllib_act_scanning(priv->rtllib, false) == false) {
1659 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
1661 (ieee->eRFPowerState == eRfOn) && !ieee->is_set_key &&
1662 (!ieee->proto_stoppping) && !ieee->wx_set_enc) {
1663 if ((ieee->PowerSaveControl.ReturnPoint ==
1664 IPS_CALLBACK_NONE) &&
1665 (!ieee->bNetPromiscuousMode)) {
1666 RT_TRACE(COMP_PS, "====================>haha: "
1672 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode ==
1673 IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode)) {
1674 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 100 ||
1675 ieee->LinkDetectInfo.NumTxOkInPeriod > 100)
1676 bBusyTraffic = true;
1679 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1680 ieee->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1681 bHigherBusyTraffic = true;
1682 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000)
1683 bHigherBusyRxTraffic = true;
1685 bHigherBusyRxTraffic = false;
1688 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1689 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1690 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1695 if (ieee->current_network.beacon_interval < 95)
1699 LeisurePSEnter(dev);
1701 LeisurePSLeave(dev);
1704 RT_TRACE(COMP_LPS, "====>no link LPS leave\n");
1705 LeisurePSLeave(dev);
1708 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
1709 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
1710 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1711 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1713 ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1714 ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1716 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1717 u32 TotalRxBcnNum = 0;
1718 u32 TotalRxDataNum = 0;
1720 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
1722 if ((TotalRxBcnNum+TotalRxDataNum) == 0)
1723 priv->check_roaming_cnt++;
1725 priv->check_roaming_cnt = 0;
1728 if (priv->check_roaming_cnt > 0) {
1729 if (ieee->eRFPowerState == eRfOff)
1730 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
1732 printk(KERN_INFO "===>%s(): AP is power off, chan:%d,"
1733 " connect another one\n", __func__, priv->chan);
1735 ieee->state = RTLLIB_ASSOCIATING;
1737 RemovePeerTS(priv->rtllib,
1738 priv->rtllib->current_network.bssid);
1739 ieee->is_roaming = true;
1740 ieee->is_set_key = false;
1741 ieee->link_change(dev);
1742 if (ieee->LedControlHandler)
1743 ieee->LedControlHandler(ieee->dev,
1744 LED_CTL_START_TO_LINK);
1746 notify_wx_assoc_event(ieee);
1748 if (!(ieee->rtllib_ap_sec_type(ieee) &
1749 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
1750 queue_delayed_work_rsl(ieee->wq,
1751 &ieee->associate_procedure_wq, 0);
1753 priv->check_roaming_cnt = 0;
1755 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
1756 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
1760 spin_lock_irqsave(&priv->tx_lock, flags);
1761 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1762 (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) {
1763 ResetType = rtl819x_ifcheck_resetornot(dev);
1764 check_reset_cnt = 3;
1766 spin_unlock_irqrestore(&priv->tx_lock, flags);
1768 if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) {
1769 priv->ResetProgress = RESET_TYPE_NORMAL;
1770 RT_TRACE(COMP_RESET, "%s(): NOMAL RESET\n", __func__);
1774 if (((priv->force_reset) || (!priv->bDisableNormalResetCheck &&
1775 ResetType == RESET_TYPE_SILENT)))
1776 rtl819x_ifsilentreset(dev);
1777 priv->force_reset = false;
1778 priv->bForcedSilentReset = false;
1779 priv->bResetInProgress = false;
1780 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1783 void watch_dog_timer_callback(unsigned long data)
1785 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
1786 queue_delayed_work_rsl(priv->priv_wq, &priv->watch_dog_wq, 0);
1787 mod_timer(&priv->watch_dog_timer, jiffies +
1788 MSECS(RTLLIB_WATCH_DOG_TIME));
1791 /****************************************************************************
1792 ---------------------------- NIC TX/RX STUFF---------------------------
1793 *****************************************************************************/
1794 void rtl8192_rx_enable(struct net_device *dev)
1796 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1797 priv->ops->rx_enable(dev);
1800 void rtl8192_tx_enable(struct net_device *dev)
1802 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1804 priv->ops->tx_enable(dev);
1806 rtllib_reset_queue(priv->rtllib);
1810 static void rtl8192_free_rx_ring(struct net_device *dev)
1812 struct r8192_priv *priv = rtllib_priv(dev);
1813 int i, rx_queue_idx;
1815 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE;
1817 for (i = 0; i < priv->rxringcount; i++) {
1818 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
1822 pci_unmap_single(priv->pdev,
1823 *((dma_addr_t *)skb->cb),
1824 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1828 pci_free_consistent(priv->pdev,
1829 sizeof(*priv->rx_ring[rx_queue_idx]) *
1831 priv->rx_ring[rx_queue_idx],
1832 priv->rx_ring_dma[rx_queue_idx]);
1833 priv->rx_ring[rx_queue_idx] = NULL;
1837 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1839 struct r8192_priv *priv = rtllib_priv(dev);
1840 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1842 while (skb_queue_len(&ring->queue)) {
1843 struct tx_desc *entry = &ring->desc[ring->idx];
1844 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1846 pci_unmap_single(priv->pdev, entry->TxBuffAddr,
1847 skb->len, PCI_DMA_TODEVICE);
1849 ring->idx = (ring->idx + 1) % ring->entries;
1852 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
1853 ring->desc, ring->dma);
1857 void rtl8192_data_hard_stop(struct net_device *dev)
1862 void rtl8192_data_hard_resume(struct net_device *dev)
1866 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1869 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1871 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1873 u8 queue_index = tcb_desc->queue_index;
1875 if ((priv->rtllib->eRFPowerState == eRfOff) || IS_NIC_DOWN(priv) ||
1876 priv->bResetInProgress) {
1881 assert(queue_index != TXCMD_QUEUE);
1884 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1885 skb_push(skb, priv->rtllib->tx_headroom);
1886 ret = rtl8192_tx(dev, skb);
1890 if (queue_index != MGNT_QUEUE) {
1891 priv->rtllib->stats.tx_bytes += (skb->len -
1892 priv->rtllib->tx_headroom);
1893 priv->rtllib->stats.tx_packets++;
1899 int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1901 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1903 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1905 u8 queue_index = tcb_desc->queue_index;
1907 if (queue_index != TXCMD_QUEUE) {
1908 if ((priv->rtllib->eRFPowerState == eRfOff) ||
1909 IS_NIC_DOWN(priv) || priv->bResetInProgress) {
1915 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1916 if (queue_index == TXCMD_QUEUE) {
1917 rtl8192_tx_cmd(dev, skb);
1920 tcb_desc->RATRIndex = 7;
1921 tcb_desc->bTxDisableRateFallBack = 1;
1922 tcb_desc->bTxUseDriverAssingedRate = 1;
1923 tcb_desc->bTxEnableFwCalcDur = 1;
1924 skb_push(skb, priv->rtllib->tx_headroom);
1925 ret = rtl8192_tx(dev, skb);
1933 static void rtl8192_tx_isr(struct net_device *dev, int prio)
1935 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1937 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1939 while (skb_queue_len(&ring->queue)) {
1940 struct tx_desc *entry = &ring->desc[ring->idx];
1941 struct sk_buff *skb;
1943 if (prio != BEACON_QUEUE) {
1946 ring->idx = (ring->idx + 1) % ring->entries;
1949 skb = __skb_dequeue(&ring->queue);
1950 pci_unmap_single(priv->pdev, entry->TxBuffAddr,
1951 skb->len, PCI_DMA_TODEVICE);
1955 if (prio != BEACON_QUEUE)
1956 tasklet_schedule(&priv->irq_tx_tasklet);
1959 void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1961 struct r8192_priv *priv = rtllib_priv(dev);
1962 struct rtl8192_tx_ring *ring;
1963 struct tx_desc_cmd *entry;
1965 struct cb_desc *tcb_desc;
1966 unsigned long flags;
1968 spin_lock_irqsave(&priv->irq_th_lock, flags);
1969 ring = &priv->tx_ring[TXCMD_QUEUE];
1971 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1972 entry = (struct tx_desc_cmd *) &ring->desc[idx];
1974 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1976 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
1978 __skb_queue_tail(&ring->queue, skb);
1979 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1984 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1986 struct r8192_priv *priv = rtllib_priv(dev);
1987 struct rtl8192_tx_ring *ring;
1988 unsigned long flags;
1989 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1991 struct tx_desc *pdesc = NULL;
1992 struct rtllib_hdr_1addr *header = NULL;
1993 u16 fc = 0, type = 0, stype = 0;
1994 bool multi_addr = false, broad_addr = false, uni_addr = false;
1995 u8 *pda_addr = NULL;
1997 u32 fwinfo_size = 0;
1999 if (priv->bdisable_nic) {
2000 RT_TRACE(COMP_ERR, "%s: ERR!! Nic is disabled! Can't tx packet"
2001 " len=%d qidx=%d!!!\n", __func__, skb->len,
2002 tcb_desc->queue_index);
2006 priv->rtllib->bAwakePktSent = true;
2008 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
2010 header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size);
2011 fc = le16_to_cpu(header->frame_ctl);
2012 type = WLAN_FC_GET_TYPE(fc);
2013 stype = WLAN_FC_GET_STYPE(fc);
2014 pda_addr = header->addr1;
2016 if (is_broadcast_ether_addr(pda_addr))
2018 else if (is_multicast_ether_addr(pda_addr))
2024 priv->stats.txbytesunicast += skb->len - fwinfo_size;
2025 else if (multi_addr)
2026 priv->stats.txbytesmulticast += skb->len - fwinfo_size;
2028 priv->stats.txbytesbroadcast += skb->len - fwinfo_size;
2030 spin_lock_irqsave(&priv->irq_th_lock, flags);
2031 ring = &priv->tx_ring[tcb_desc->queue_index];
2032 if (tcb_desc->queue_index != BEACON_QUEUE)
2033 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2037 pdesc = &ring->desc[idx];
2038 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
2039 RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d, idx = "
2040 "%d, skblen = 0x%x queuelen=%d",
2041 tcb_desc->queue_index, ring->idx, idx, skb->len,
2042 skb_queue_len(&ring->queue));
2043 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2047 if (type == RTLLIB_FTYPE_DATA) {
2048 if (priv->rtllib->LedControlHandler)
2049 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
2051 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
2052 __skb_queue_tail(&ring->queue, skb);
2054 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2055 dev->trans_start = jiffies;
2057 write_nic_word(dev, TPPoll, 0x01 << tcb_desc->queue_index);
2061 static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
2063 struct r8192_priv *priv = rtllib_priv(dev);
2064 struct rx_desc *entry = NULL;
2065 int i, rx_queue_idx;
2067 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2068 priv->rx_ring[rx_queue_idx] =
2069 pci_zalloc_consistent(priv->pdev,
2070 sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
2071 &priv->rx_ring_dma[rx_queue_idx]);
2072 if (!priv->rx_ring[rx_queue_idx] ||
2073 (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
2074 RT_TRACE(COMP_ERR, "Cannot allocate RX ring\n");
2078 priv->rx_idx[rx_queue_idx] = 0;
2080 for (i = 0; i < priv->rxringcount; i++) {
2081 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
2082 dma_addr_t *mapping;
2083 entry = &priv->rx_ring[rx_queue_idx][i];
2087 priv->rx_buf[rx_queue_idx][i] = skb;
2088 mapping = (dma_addr_t *)skb->cb;
2089 *mapping = pci_map_single(priv->pdev,
2090 skb_tail_pointer_rsl(skb),
2092 PCI_DMA_FROMDEVICE);
2093 if (pci_dma_mapping_error(priv->pdev, *mapping)) {
2094 dev_kfree_skb_any(skb);
2097 entry->BufferAddress = *mapping;
2099 entry->Length = priv->rxbuffersize;
2109 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
2110 unsigned int prio, unsigned int entries)
2112 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2113 struct tx_desc *ring;
2117 ring = pci_zalloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
2118 if (!ring || (unsigned long)ring & 0xFF) {
2119 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n",
2124 priv->tx_ring[prio].desc = ring;
2125 priv->tx_ring[prio].dma = dma;
2126 priv->tx_ring[prio].idx = 0;
2127 priv->tx_ring[prio].entries = entries;
2128 skb_queue_head_init(&priv->tx_ring[prio].queue);
2130 for (i = 0; i < entries; i++)
2131 ring[i].NextDescAddress =
2132 (u32)dma + ((i + 1) % entries) *
2139 short rtl8192_pci_initdescring(struct net_device *dev)
2143 struct r8192_priv *priv = rtllib_priv(dev);
2145 ret = rtl8192_alloc_rx_desc_ring(dev);
2149 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2150 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
2152 goto err_free_rings;
2158 rtl8192_free_rx_ring(dev);
2159 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2160 if (priv->tx_ring[i].desc)
2161 rtl8192_free_tx_ring(dev, i);
2165 void rtl8192_pci_resetdescring(struct net_device *dev)
2167 struct r8192_priv *priv = rtllib_priv(dev);
2168 int i, rx_queue_idx;
2169 unsigned long flags = 0;
2171 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2172 if (priv->rx_ring[rx_queue_idx]) {
2173 struct rx_desc *entry = NULL;
2174 for (i = 0; i < priv->rxringcount; i++) {
2175 entry = &priv->rx_ring[rx_queue_idx][i];
2178 priv->rx_idx[rx_queue_idx] = 0;
2182 spin_lock_irqsave(&priv->irq_th_lock, flags);
2183 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2184 if (priv->tx_ring[i].desc) {
2185 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
2187 while (skb_queue_len(&ring->queue)) {
2188 struct tx_desc *entry = &ring->desc[ring->idx];
2189 struct sk_buff *skb =
2190 __skb_dequeue(&ring->queue);
2192 pci_unmap_single(priv->pdev,
2194 skb->len, PCI_DMA_TODEVICE);
2196 ring->idx = (ring->idx + 1) % ring->entries;
2201 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2204 void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
2205 struct rtllib_rx_stats *stats)
2207 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2209 if (stats->bIsAMPDU && !stats->bFirstMPDU)
2210 stats->mac_time = priv->LastRxDescTSF;
2212 priv->LastRxDescTSF = stats->mac_time;
2215 long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index)
2219 signal_power = (long)((signal_strength_index + 1) >> 1);
2222 return signal_power;
2227 rtl819x_update_rxsignalstatistics8190pci(
2228 struct r8192_priv *priv,
2229 struct rtllib_rx_stats *pprevious_stats
2235 if (priv->stats.recv_signal_power == 0)
2236 priv->stats.recv_signal_power =
2237 pprevious_stats->RecvSignalPower;
2239 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
2241 else if (pprevious_stats->RecvSignalPower <
2242 priv->stats.recv_signal_power)
2244 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 +
2245 pprevious_stats->RecvSignalPower +
2249 void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv,
2250 struct rtllib_rx_stats *pprevious_stats)
2255 u8 rtl819x_query_rxpwrpercentage(char antpower)
2257 if ((antpower <= -100) || (antpower >= 20))
2259 else if (antpower >= 0)
2262 return 100 + antpower;
2264 } /* QueryRxPwrPercentage */
2267 rtl819x_evm_dbtopercentage(
2279 ret_val = 0 - ret_val;
2287 rtl8192_record_rxdesc_forlateruse(
2288 struct rtllib_rx_stats *psrc_stats,
2289 struct rtllib_rx_stats *ptarget_stats
2292 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
2293 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
2298 static void rtl8192_rx_normal(struct net_device *dev)
2300 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2301 struct rtllib_hdr_1addr *rtllib_hdr = NULL;
2302 bool unicast_packet = false;
2303 bool bLedBlinking = true;
2304 u16 fc = 0, type = 0;
2306 int rx_queue_idx = RX_MPDU_QUEUE;
2308 struct rtllib_rx_stats stats = {
2312 .freq = RTLLIB_24GHZ_BAND,
2314 unsigned int count = priv->rxringcount;
2316 stats.nic_type = NIC_8192E;
2319 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx]
2320 [priv->rx_idx[rx_queue_idx]];
2321 struct sk_buff *skb = priv->rx_buf[rx_queue_idx]
2322 [priv->rx_idx[rx_queue_idx]];
2327 struct sk_buff *new_skb;
2329 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
2332 new_skb = dev_alloc_skb(priv->rxbuffersize);
2333 /* if allocation of new skb failed - drop current packet
2335 if (unlikely(!new_skb))
2338 pci_unmap_single(priv->pdev,
2339 *((dma_addr_t *)skb->cb),
2341 PCI_DMA_FROMDEVICE);
2343 skb_put(skb, pdesc->Length);
2344 skb_reserve(skb, stats.RxDrvInfoSize +
2346 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2347 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2348 if (!is_multicast_ether_addr(rtllib_hdr->addr1)) {
2349 /* unicast packet */
2350 unicast_packet = true;
2352 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
2353 type = WLAN_FC_GET_TYPE(fc);
2354 if (type == RTLLIB_FTYPE_MGMT)
2355 bLedBlinking = false;
2358 if (priv->rtllib->LedControlHandler)
2359 priv->rtllib->LedControlHandler(dev,
2363 if (type != RTLLIB_FTYPE_MGMT)
2364 priv->stats.rxdatacrcerr++;
2366 priv->stats.rxmgmtcrcerr++;
2371 if (!rtllib_rx(priv->rtllib, skb, &stats)) {
2372 dev_kfree_skb_any(skb);
2376 priv->stats.rxbytesunicast += skb_len;
2382 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] =
2384 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev,
2385 skb_tail_pointer_rsl(skb),
2387 PCI_DMA_FROMDEVICE);
2388 if (pci_dma_mapping_error(priv->pdev,
2389 *((dma_addr_t *)skb->cb))) {
2390 dev_kfree_skb_any(skb);
2395 pdesc->BufferAddress = *((dma_addr_t *)skb->cb);
2397 pdesc->Length = priv->rxbuffersize;
2398 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1)
2400 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) %
2406 static void rtl8192_rx_cmd(struct net_device *dev)
2411 static void rtl8192_tx_resume(struct net_device *dev)
2413 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2414 struct rtllib_device *ieee = priv->rtllib;
2415 struct sk_buff *skb;
2418 for (queue_index = BK_QUEUE;
2419 queue_index < MAX_QUEUE_SIZE; queue_index++) {
2420 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) &&
2421 (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) {
2422 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
2423 ieee->softmac_data_hard_start_xmit(skb, dev, 0);
2428 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2430 rtl8192_tx_resume(priv->rtllib->dev);
2433 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2435 rtl8192_rx_normal(priv->rtllib->dev);
2437 if (MAX_RX_QUEUE > 1)
2438 rtl8192_rx_cmd(priv->rtllib->dev);
2440 write_nic_dword(priv->rtllib->dev, INTA_MASK,
2441 read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2444 /****************************************************************************
2445 ---------------------------- NIC START/CLOSE STUFF---------------------------
2446 *****************************************************************************/
2447 void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
2449 cancel_delayed_work(&priv->watch_dog_wq);
2450 cancel_delayed_work(&priv->update_beacon_wq);
2451 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
2452 cancel_work_sync(&priv->reset_wq);
2453 cancel_work_sync(&priv->qos_activate);
2456 int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
2458 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2464 static int rtl8192_open(struct net_device *dev)
2466 struct r8192_priv *priv = rtllib_priv(dev);
2469 down(&priv->wx_sem);
2470 ret = rtl8192_up(dev);
2477 int rtl8192_up(struct net_device *dev)
2479 struct r8192_priv *priv = rtllib_priv(dev);
2483 return _rtl8192_up(dev, false);
2487 static int rtl8192_close(struct net_device *dev)
2489 struct r8192_priv *priv = rtllib_priv(dev);
2492 if ((rtllib_act_scanning(priv->rtllib, false)) &&
2493 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) {
2494 rtllib_stop_scan(priv->rtllib);
2497 down(&priv->wx_sem);
2499 ret = rtl8192_down(dev, true);
2507 int rtl8192_down(struct net_device *dev, bool shutdownrf)
2509 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2515 void rtl8192_commit(struct net_device *dev)
2517 struct r8192_priv *priv = rtllib_priv(dev);
2521 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
2522 rtl8192_irq_disable(dev);
2523 priv->ops->stop_adapter(dev, true);
2524 _rtl8192_up(dev, false);
2527 void rtl8192_restart(void *data)
2529 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2531 struct net_device *dev = priv->rtllib->dev;
2533 down(&priv->wx_sem);
2535 rtl8192_commit(dev);
2540 static void r8192_set_multicast(struct net_device *dev)
2542 struct r8192_priv *priv = rtllib_priv(dev);
2545 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2546 priv->promisc = promisc;
2551 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
2553 struct r8192_priv *priv = rtllib_priv(dev);
2554 struct sockaddr *addr = mac;
2556 down(&priv->wx_sem);
2558 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
2560 schedule_work(&priv->reset_wq);
2566 /* based on ipw2200 driver */
2567 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2569 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2570 struct iwreq *wrq = (struct iwreq *)rq;
2572 struct rtllib_device *ieee = priv->rtllib;
2574 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2575 u8 zero_addr[6] = {0};
2576 struct iw_point *p = &wrq->u.data;
2577 struct ieee_param *ipw = NULL;
2579 down(&priv->wx_sem);
2582 case RTL_IOCTL_WPA_SUPPLICANT:
2583 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
2588 ipw = memdup_user(p->pointer, p->length);
2594 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
2595 if (ipw->u.crypt.set_tx) {
2596 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2597 ieee->pairwise_key_type = KEY_TYPE_CCMP;
2598 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2599 ieee->pairwise_key_type = KEY_TYPE_TKIP;
2600 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2601 if (ipw->u.crypt.key_len == 13)
2602 ieee->pairwise_key_type =
2604 else if (ipw->u.crypt.key_len == 5)
2605 ieee->pairwise_key_type =
2608 ieee->pairwise_key_type = KEY_TYPE_NA;
2611 if (ieee->pairwise_key_type) {
2612 if (memcmp(ieee->ap_mac_addr, zero_addr,
2614 ieee->iw_mode = IW_MODE_ADHOC;
2615 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2616 EnableHWSecurityConfig8192(dev);
2617 set_swcam(dev, 4, ipw->u.crypt.idx,
2618 ieee->pairwise_key_type,
2619 (u8 *)ieee->ap_mac_addr,
2621 setKey(dev, 4, ipw->u.crypt.idx,
2622 ieee->pairwise_key_type,
2623 (u8 *)ieee->ap_mac_addr, 0, key);
2624 if (ieee->iw_mode == IW_MODE_ADHOC) {
2625 set_swcam(dev, ipw->u.crypt.idx,
2627 ieee->pairwise_key_type,
2628 (u8 *)ieee->ap_mac_addr,
2630 setKey(dev, ipw->u.crypt.idx,
2632 ieee->pairwise_key_type,
2633 (u8 *)ieee->ap_mac_addr,
2637 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
2638 && ieee->pHTInfo->bCurrentHTSupport) {
2639 write_nic_byte(dev, 0x173, 1);
2643 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2644 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2645 ieee->group_key_type = KEY_TYPE_CCMP;
2646 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2647 ieee->group_key_type = KEY_TYPE_TKIP;
2648 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2649 if (ipw->u.crypt.key_len == 13)
2650 ieee->group_key_type =
2652 else if (ipw->u.crypt.key_len == 5)
2653 ieee->group_key_type =
2656 ieee->group_key_type = KEY_TYPE_NA;
2658 if (ieee->group_key_type) {
2659 set_swcam(dev, ipw->u.crypt.idx,
2661 ieee->group_key_type,
2662 broadcast_addr, 0, key, 0);
2663 setKey(dev, ipw->u.crypt.idx,
2665 ieee->group_key_type,
2666 broadcast_addr, 0, key);
2671 ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data,
2687 static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
2689 struct net_device *dev = (struct net_device *) netdev;
2690 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2691 unsigned long flags;
2696 if (priv->irq_enabled == 0)
2699 spin_lock_irqsave(&priv->irq_th_lock, flags);
2701 priv->ops->interrupt_recognized(dev, &inta, &intb);
2702 priv->stats.shints++;
2705 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2709 if (inta == 0xffff) {
2710 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2716 if (!netif_running(dev)) {
2717 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2721 if (inta & IMR_TBDOK) {
2722 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2723 priv->stats.txbeaconokint++;
2726 if (inta & IMR_TBDER) {
2727 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2728 priv->stats.txbeaconerr++;
2731 if (inta & IMR_BDOK)
2732 RT_TRACE(COMP_INTR, "beacon interrupt!\n");
2734 if (inta & IMR_MGNTDOK) {
2735 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
2736 priv->stats.txmanageokint++;
2737 rtl8192_tx_isr(dev, MGNT_QUEUE);
2738 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2739 if (priv->rtllib->ack_tx_to_ieee) {
2740 if (rtl8192_is_tx_queue_empty(dev)) {
2741 priv->rtllib->ack_tx_to_ieee = 0;
2742 rtllib_ps_tx_ack(priv->rtllib, 1);
2745 spin_lock_irqsave(&priv->irq_th_lock, flags);
2748 if (inta & IMR_COMDOK) {
2749 priv->stats.txcmdpktokint++;
2750 rtl8192_tx_isr(dev, TXCMD_QUEUE);
2753 if (inta & IMR_HIGHDOK)
2754 rtl8192_tx_isr(dev, HIGH_QUEUE);
2756 if (inta & IMR_ROK) {
2757 priv->stats.rxint++;
2758 priv->InterruptLog.nIMR_ROK++;
2759 tasklet_schedule(&priv->irq_rx_tasklet);
2762 if (inta & IMR_BcnInt) {
2763 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
2764 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
2767 if (inta & IMR_RDU) {
2768 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2769 priv->stats.rxrdu++;
2770 write_nic_dword(dev, INTA_MASK,
2771 read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
2772 tasklet_schedule(&priv->irq_rx_tasklet);
2775 if (inta & IMR_RXFOVW) {
2776 RT_TRACE(COMP_INTR, "rx overflow !\n");
2777 priv->stats.rxoverflow++;
2778 tasklet_schedule(&priv->irq_rx_tasklet);
2781 if (inta & IMR_TXFOVW)
2782 priv->stats.txoverflow++;
2784 if (inta & IMR_BKDOK) {
2785 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
2786 priv->stats.txbkokint++;
2787 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2788 rtl8192_tx_isr(dev, BK_QUEUE);
2791 if (inta & IMR_BEDOK) {
2792 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
2793 priv->stats.txbeokint++;
2794 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2795 rtl8192_tx_isr(dev, BE_QUEUE);
2798 if (inta & IMR_VIDOK) {
2799 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
2800 priv->stats.txviokint++;
2801 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2802 rtl8192_tx_isr(dev, VI_QUEUE);
2805 if (inta & IMR_VODOK) {
2806 priv->stats.txvookint++;
2807 RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
2808 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2809 rtl8192_tx_isr(dev, VO_QUEUE);
2812 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2821 /****************************************************************************
2822 ---------------------------- PCI_STUFF---------------------------
2823 *****************************************************************************/
2824 static const struct net_device_ops rtl8192_netdev_ops = {
2825 .ndo_open = rtl8192_open,
2826 .ndo_stop = rtl8192_close,
2827 .ndo_tx_timeout = rtl8192_tx_timeout,
2828 .ndo_do_ioctl = rtl8192_ioctl,
2829 .ndo_set_rx_mode = r8192_set_multicast,
2830 .ndo_set_mac_address = r8192_set_mac_adr,
2831 .ndo_validate_addr = eth_validate_addr,
2832 .ndo_change_mtu = eth_change_mtu,
2833 .ndo_start_xmit = rtllib_xmit,
2836 static int rtl8192_pci_probe(struct pci_dev *pdev,
2837 const struct pci_device_id *id)
2839 unsigned long ioaddr = 0;
2840 struct net_device *dev = NULL;
2841 struct r8192_priv *priv = NULL;
2842 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2843 unsigned long pmem_start, pmem_len, pmem_flags;
2845 bool bdma64 = false;
2848 RT_TRACE(COMP_INIT, "Configuring chip resources");
2850 if (pci_enable_device(pdev)) {
2851 RT_TRACE(COMP_ERR, "Failed to enable PCI device");
2855 pci_set_master(pdev);
2857 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2858 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
2859 printk(KERN_INFO "Unable to obtain 32bit DMA for consistent allocations\n");
2860 goto err_pci_disable;
2863 dev = alloc_rtllib(sizeof(struct r8192_priv));
2865 goto err_pci_disable;
2869 dev->features |= NETIF_F_HIGHDMA;
2871 pci_set_drvdata(pdev, dev);
2872 SET_NETDEV_DEV(dev, &pdev->dev);
2873 priv = rtllib_priv(dev);
2874 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
2876 priv->rtllib->pdev = pdev;
2877 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) &&
2878 (pdev->subsystem_device == 0x3304))
2879 priv->rtllib->bSupportRemoteWakeUp = 1;
2881 priv->rtllib->bSupportRemoteWakeUp = 0;
2883 pmem_start = pci_resource_start(pdev, 1);
2884 pmem_len = pci_resource_len(pdev, 1);
2885 pmem_flags = pci_resource_flags(pdev, 1);
2887 if (!(pmem_flags & IORESOURCE_MEM)) {
2888 RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting");
2889 goto err_rel_rtllib;
2892 printk(KERN_INFO "Memory mapped space start: 0x%08lx\n", pmem_start);
2893 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
2894 RT_TRACE(COMP_ERR, "request_mem_region failed!");
2895 goto err_rel_rtllib;
2899 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
2900 if (ioaddr == (unsigned long)NULL) {
2901 RT_TRACE(COMP_ERR, "ioremap failed!");
2905 dev->mem_start = ioaddr;
2906 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
2908 pci_read_config_byte(pdev, 0x08, &revision_id);
2909 /* If the revisionid is 0x10, the device uses rtl8192se. */
2910 if (pdev->device == 0x8192 && revision_id == 0x10)
2915 if (rtl8192_pci_findadapter(pdev, dev) == false)
2918 dev->irq = pdev->irq;
2921 dev->netdev_ops = &rtl8192_netdev_ops;
2923 dev->wireless_handlers = &r8192_wx_handlers_def;
2924 dev->ethtool_ops = &rtl819x_ethtool_ops;
2926 dev->type = ARPHRD_ETHER;
2927 dev->watchdog_timeo = HZ * 3;
2929 if (dev_alloc_name(dev, ifname) < 0) {
2930 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying "
2932 dev_alloc_name(dev, ifname);
2935 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
2936 if (rtl8192_init(dev) != 0) {
2937 RT_TRACE(COMP_ERR, "Initialization failed");
2941 netif_carrier_off(dev);
2942 netif_stop_queue(dev);
2944 if (register_netdev(dev))
2946 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name);
2948 if (priv->polling_timer_on == 0)
2949 check_rfctrl_gpio_timer((unsigned long)dev);
2951 RT_TRACE(COMP_INIT, "Driver probe completed\n");
2955 free_irq(dev->irq, dev);
2958 release_mem_region(pmem_start, pmem_len);
2962 DMESG("wlan driver load failed\n");
2964 pci_disable_device(pdev);
2968 static void rtl8192_pci_disconnect(struct pci_dev *pdev)
2970 struct net_device *dev = pci_get_drvdata(pdev);
2971 struct r8192_priv *priv ;
2975 unregister_netdev(dev);
2977 priv = rtllib_priv(dev);
2979 del_timer_sync(&priv->gpio_polling_timer);
2980 cancel_delayed_work(&priv->gpio_change_rf_wq);
2981 priv->polling_timer_on = 0;
2982 rtl8192_down(dev, true);
2984 if (priv->pFirmware) {
2985 vfree(priv->pFirmware);
2986 priv->pFirmware = NULL;
2988 destroy_workqueue(priv->priv_wq);
2989 rtl8192_free_rx_ring(dev);
2990 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2991 rtl8192_free_tx_ring(dev, i);
2994 printk(KERN_INFO "Freeing irq %d\n", dev->irq);
2995 free_irq(dev->irq, dev);
3000 kfree(priv->scan_cmd);
3002 if (dev->mem_start != 0) {
3003 iounmap((void __iomem *)dev->mem_start);
3004 release_mem_region(pci_resource_start(pdev, 1),
3005 pci_resource_len(pdev, 1));
3008 priv = rtllib_priv(dev);
3011 pci_disable_device(pdev);
3012 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
3015 bool NicIFEnableNIC(struct net_device *dev)
3017 bool init_status = true;
3018 struct r8192_priv *priv = rtllib_priv(dev);
3019 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
3020 (&(priv->rtllib->PowerSaveControl));
3022 if (IS_NIC_DOWN(priv)) {
3023 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",
3025 priv->bdisable_nic = false;
3029 RT_TRACE(COMP_PS, "===========>%s()\n", __func__);
3030 priv->bfirst_init = true;
3031 init_status = priv->ops->initialize_adapter(dev);
3033 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
3035 priv->bdisable_nic = false;
3038 RT_TRACE(COMP_INIT, "start adapter finished\n");
3039 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
3040 priv->bfirst_init = false;
3042 rtl8192_irq_enable(dev);
3043 priv->bdisable_nic = false;
3044 RT_TRACE(COMP_PS, "<===========%s()\n", __func__);
3047 bool NicIFDisableNIC(struct net_device *dev)
3050 struct r8192_priv *priv = rtllib_priv(dev);
3052 RT_TRACE(COMP_PS, "=========>%s()\n", __func__);
3053 priv->bdisable_nic = true;
3054 tmp_state = priv->rtllib->state;
3055 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
3056 priv->rtllib->state = tmp_state;
3057 rtl8192_cancel_deferred_work(priv);
3058 rtl8192_irq_disable(dev);
3060 priv->ops->stop_adapter(dev, false);
3061 RT_TRACE(COMP_PS, "<=========%s()\n", __func__);
3066 static int __init rtl8192_pci_module_init(void)
3068 printk(KERN_INFO "\nLinux kernel driver for RTL8192E WLAN cards\n");
3069 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan Driver\n");
3071 if (0 != pci_register_driver(&rtl8192_pci_driver)) {
3072 DMESG("No device found");
3073 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3079 static void __exit rtl8192_pci_module_exit(void)
3081 pci_unregister_driver(&rtl8192_pci_driver);
3083 RT_TRACE(COMP_DOWN, "Exiting");
3086 void check_rfctrl_gpio_timer(unsigned long data)
3088 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
3090 priv->polling_timer_on = 1;
3092 queue_delayed_work_rsl(priv->priv_wq, &priv->gpio_change_rf_wq, 0);
3094 mod_timer(&priv->gpio_polling_timer, jiffies +
3095 MSECS(RTLLIB_WATCH_DOG_TIME));
3098 /***************************************************************************
3099 ------------------- module init / exit stubs ----------------
3100 ****************************************************************************/
3101 module_init(rtl8192_pci_module_init);
3102 module_exit(rtl8192_pci_module_exit);
3104 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
3105 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
3106 MODULE_VERSION(DRV_VERSION);
3107 MODULE_LICENSE("GPL");
3108 MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW);
3109 MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW);
3110 MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW);
3112 module_param(ifname, charp, S_IRUGO|S_IWUSR);
3113 module_param(hwwep, int, S_IRUGO|S_IWUSR);
3114 module_param(channels, int, S_IRUGO|S_IWUSR);
3116 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
3117 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");
3118 MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");