staging: rtl8192e: Cleanup checkpatch -f warnings and errors - Part VIII
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / rtl8192e / rtl_core.c
blob9554eef1fcb4ad2c35897780d2515f5304e3f2b0
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
13 * more details.
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
26 #undef DEBUG_EPROM
27 #undef DEBUG_RX_VERBOSE
28 #undef DUMMY_RX
29 #undef DEBUG_ZERO_RX
30 #undef DEBUG_RX_SKB
31 #undef DEBUG_TX_FRAG
32 #undef DEBUG_RX_FRAG
33 #undef DEBUG_TX_FILLDESC
34 #undef DEBUG_TX
35 #undef DEBUG_IRQ
36 #undef DEBUG_RX
37 #undef DEBUG_RXALLOC
38 #undef DEBUG_REGISTERS
39 #undef DEBUG_RING
40 #undef DEBUG_IRQ_TASKLET
41 #undef DEBUG_TX_ALLOC
42 #undef DEBUG_TX_DESC
44 #include <linux/uaccess.h>
45 #include <linux/pci.h>
46 #include <linux/vmalloc.h>
47 #include "rtl_core.h"
48 #include "r8192E_phy.h"
49 #include "r8192E_phyreg.h"
50 #include "r8190P_rtl8256.h"
51 #include "r8192E_cmdpkt.h"
53 #include "rtl_wx.h"
54 #include "rtl_dm.h"
56 #ifdef CONFIG_PM_RTL
57 #include "rtl_pm.h"
58 #endif
60 int hwwep = 1;
61 static int channels = 0x3fff;
62 char *ifname = "wlan%d";
65 struct rtl819x_ops rtl819xp_ops = {
66 .nic_type = NIC_8192E,
67 .get_eeprom_size = rtl8192_get_eeprom_size,
68 .init_adapter_variable = rtl8192_InitializeVariables,
69 .initialize_adapter = rtl8192_adapter_start,
70 .link_change = rtl8192_link_change,
71 .tx_fill_descriptor = rtl8192_tx_fill_desc,
72 .tx_fill_cmd_descriptor = rtl8192_tx_fill_cmd_desc,
73 .rx_query_status_descriptor = rtl8192_rx_query_status_desc,
74 .rx_command_packet_handler = NULL,
75 .stop_adapter = rtl8192_halt_adapter,
76 .update_ratr_table = rtl8192_update_ratr_table,
77 .irq_enable = rtl8192_EnableInterrupt,
78 .irq_disable = rtl8192_DisableInterrupt,
79 .irq_clear = rtl8192_ClearInterrupt,
80 .rx_enable = rtl8192_enable_rx,
81 .tx_enable = rtl8192_enable_tx,
82 .interrupt_recognized = rtl8192_interrupt_recognized,
83 .TxCheckStuckHandler = rtl8192_HalTxCheckStuck,
84 .RxCheckStuckHandler = rtl8192_HalRxCheckStuck,
87 static struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
88 {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)},
89 {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)},
90 {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)},
94 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
96 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
97 const struct pci_device_id *id);
98 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev);
100 static struct pci_driver rtl8192_pci_driver = {
101 .name = DRV_NAME, /* Driver name */
102 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
103 .probe = rtl8192_pci_probe, /* probe fn */
104 .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */
105 .suspend = rtl8192E_suspend, /* PM suspend fn */
106 .resume = rtl8192E_resume, /* PM resume fn */
109 /****************************************************************************
110 -----------------------------IO STUFF-------------------------
111 *****************************************************************************/
112 bool PlatformIOCheckPageLegalAndGetRegMask(u32 u4bPage, u8 *pu1bPageMask)
114 bool bReturn = false;
116 *pu1bPageMask = 0xfe;
118 switch (u4bPage) {
119 case 1: case 2: case 3: case 4:
120 case 8: case 9: case 10: case 12: case 13:
121 bReturn = true;
122 *pu1bPageMask = 0xf0;
123 break;
125 default:
126 bReturn = false;
127 break;
130 return bReturn;
133 void write_nic_io_byte(struct net_device *dev, int x, u8 y)
135 u32 u4bPage = (x >> 8);
136 u8 u1PageMask = 0;
137 bool bIsLegalPage = false;
139 if (u4bPage == 0) {
140 outb(y&0xff, dev->base_addr + x);
142 } else {
143 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
144 &u1PageMask);
145 if (bIsLegalPage) {
146 u8 u1bPsr = read_nic_io_byte(dev, PSR);
148 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
149 (u8)u4bPage));
150 write_nic_io_byte(dev, (x & 0xff), y);
151 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
156 void write_nic_io_word(struct net_device *dev, int x, u16 y)
158 u32 u4bPage = (x >> 8);
159 u8 u1PageMask = 0;
160 bool bIsLegalPage = false;
162 if (u4bPage == 0) {
163 outw(y, dev->base_addr + x);
164 } else {
165 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
166 &u1PageMask);
167 if (bIsLegalPage) {
168 u8 u1bPsr = read_nic_io_byte(dev, PSR);
170 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
171 (u8)u4bPage));
172 write_nic_io_word(dev, (x & 0xff), y);
173 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
179 void write_nic_io_dword(struct net_device *dev, int x, u32 y)
181 u32 u4bPage = (x >> 8);
182 u8 u1PageMask = 0;
183 bool bIsLegalPage = false;
185 if (u4bPage == 0) {
186 outl(y, dev->base_addr + x);
187 } else {
188 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
189 &u1PageMask);
190 if (bIsLegalPage) {
191 u8 u1bPsr = read_nic_io_byte(dev, PSR);
193 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
194 (u8)u4bPage));
195 write_nic_io_dword(dev, (x & 0xff), y);
196 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
201 u8 read_nic_io_byte(struct net_device *dev, int x)
203 u32 u4bPage = (x >> 8);
204 u8 u1PageMask = 0;
205 bool bIsLegalPage = false;
206 u8 Data = 0;
208 if (u4bPage == 0) {
209 return 0xff&inb(dev->base_addr + x);
210 } else {
211 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
212 &u1PageMask);
213 if (bIsLegalPage) {
214 u8 u1bPsr = read_nic_io_byte(dev, PSR);
216 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
217 (u8)u4bPage));
218 Data = read_nic_io_byte(dev, (x & 0xff));
219 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
223 return Data;
226 u16 read_nic_io_word(struct net_device *dev, int x)
228 u32 u4bPage = (x >> 8);
229 u8 u1PageMask = 0;
230 bool bIsLegalPage = false;
231 u16 Data = 0;
233 if (u4bPage == 0) {
234 return inw(dev->base_addr + x);
235 } else {
236 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
237 &u1PageMask);
238 if (bIsLegalPage) {
239 u8 u1bPsr = read_nic_io_byte(dev, PSR);
241 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
242 (u8)u4bPage));
243 Data = read_nic_io_word(dev, (x & 0xff));
244 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
249 return Data;
252 u32 read_nic_io_dword(struct net_device *dev, int x)
254 u32 u4bPage = (x >> 8);
255 u8 u1PageMask = 0;
256 bool bIsLegalPage = false;
257 u32 Data = 0;
259 if (u4bPage == 0) {
260 return inl(dev->base_addr + x);
261 } else {
262 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
263 &u1PageMask);
264 if (bIsLegalPage) {
265 u8 u1bPsr = read_nic_io_byte(dev, PSR);
267 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
268 (u8)u4bPage));
269 Data = read_nic_io_dword(dev, (x & 0xff));
270 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
275 return Data;
278 u8 read_nic_byte(struct net_device *dev, int x)
280 return 0xff & readb((u8 *)dev->mem_start + x);
283 u32 read_nic_dword(struct net_device *dev, int x)
285 return readl((u8 *)dev->mem_start + x);
288 u16 read_nic_word(struct net_device *dev, int x)
290 return readw((u8 *)dev->mem_start + x);
293 void write_nic_byte(struct net_device *dev, int x, u8 y)
295 writeb(y, (u8 *)dev->mem_start + x);
297 udelay(20);
300 void write_nic_dword(struct net_device *dev, int x, u32 y)
302 writel(y, (u8 *)dev->mem_start + x);
304 udelay(20);
307 void write_nic_word(struct net_device *dev, int x, u16 y)
309 writew(y, (u8 *)dev->mem_start + x);
311 udelay(20);
314 /****************************************************************************
315 -----------------------------GENERAL FUNCTION-------------------------
316 *****************************************************************************/
317 bool MgntActSet_RF_State(struct net_device *dev,
318 enum rt_rf_power_state StateToSet,
319 RT_RF_CHANGE_SOURCE ChangeSource,
320 bool ProtectOrNot)
322 struct r8192_priv *priv = rtllib_priv(dev);
323 struct rtllib_device *ieee = priv->rtllib;
324 bool bActionAllowed = false;
325 bool bConnectBySSID = false;
326 enum rt_rf_power_state rtState;
327 u16 RFWaitCounter = 0;
328 unsigned long flag;
329 RT_TRACE((COMP_PS | COMP_RF), "===>MgntActSet_RF_State(): "
330 "StateToSet(%d)\n", StateToSet);
332 ProtectOrNot = false;
335 if (!ProtectOrNot) {
336 while (true) {
337 spin_lock_irqsave(&priv->rf_ps_lock, flag);
338 if (priv->RFChangeInProgress) {
339 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
340 RT_TRACE((COMP_PS | COMP_RF),
341 "MgntActSet_RF_State(): RF Change in "
342 "progress! Wait to set..StateToSet"
343 "(%d).\n", StateToSet);
345 while (priv->RFChangeInProgress) {
346 RFWaitCounter++;
347 RT_TRACE((COMP_PS | COMP_RF),
348 "MgntActSet_RF_State(): Wait 1"
349 " ms (%d times)...\n",
350 RFWaitCounter);
351 mdelay(1);
353 if (RFWaitCounter > 100) {
354 RT_TRACE(COMP_ERR, "MgntActSet_"
355 "RF_State(): Wait too "
356 "logn to set RF\n");
357 return false;
360 } else {
361 priv->RFChangeInProgress = true;
362 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
363 break;
368 rtState = priv->rtllib->eRFPowerState;
370 switch (StateToSet) {
371 case eRfOn:
372 priv->rtllib->RfOffReason &= (~ChangeSource);
374 if ((ChangeSource == RF_CHANGE_BY_HW) &&
375 (priv->bHwRadioOff == true))
376 priv->bHwRadioOff = false;
378 if (!priv->rtllib->RfOffReason) {
379 priv->rtllib->RfOffReason = 0;
380 bActionAllowed = true;
383 if (rtState == eRfOff &&
384 ChangeSource >= RF_CHANGE_BY_HW)
385 bConnectBySSID = true;
386 } else {
387 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State - "
388 "eRfon reject pMgntInfo->RfOffReason= 0x%x,"
389 " ChangeSource=0x%X\n",
390 priv->rtllib->RfOffReason, ChangeSource);
393 break;
395 case eRfOff:
397 if ((priv->rtllib->iw_mode == IW_MODE_INFRA) ||
398 (priv->rtllib->iw_mode == IW_MODE_ADHOC)) {
399 if ((priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS) ||
400 (ChangeSource > RF_CHANGE_BY_IPS)) {
401 if (ieee->state == RTLLIB_LINKED)
402 priv->blinked_ingpio = true;
403 else
404 priv->blinked_ingpio = false;
405 rtllib_MgntDisconnect(priv->rtllib,
406 disas_lv_ss);
409 if ((ChangeSource == RF_CHANGE_BY_HW) &&
410 (priv->bHwRadioOff == false))
411 priv->bHwRadioOff = true;
412 priv->rtllib->RfOffReason |= ChangeSource;
413 bActionAllowed = true;
414 break;
416 case eRfSleep:
417 priv->rtllib->RfOffReason |= ChangeSource;
418 bActionAllowed = true;
419 break;
421 default:
422 break;
425 if (bActionAllowed) {
426 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): Action is"
427 " allowed.... StateToSet(%d), RfOffReason(%#X)\n",
428 StateToSet, priv->rtllib->RfOffReason);
429 PHY_SetRFPowerState(dev, StateToSet);
430 if (StateToSet == eRfOn) {
432 if (bConnectBySSID && (priv->blinked_ingpio == true)) {
433 queue_delayed_work_rsl(ieee->wq,
434 &ieee->associate_procedure_wq, 0);
435 priv->blinked_ingpio = false;
438 } else {
439 RT_TRACE((COMP_PS | COMP_RF), "MgntActSet_RF_State(): "
440 "Action is rejected.... StateToSet(%d), ChangeSource"
441 "(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource,
442 priv->rtllib->RfOffReason);
445 if (!ProtectOrNot) {
446 spin_lock_irqsave(&priv->rf_ps_lock, flag);
447 priv->RFChangeInProgress = false;
448 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
451 RT_TRACE((COMP_PS && COMP_RF), "<===MgntActSet_RF_State()\n");
452 return bActionAllowed;
456 short rtl8192_get_nic_desc_num(struct net_device *dev, int prio)
458 struct r8192_priv *priv = rtllib_priv(dev);
459 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
461 /* For now, we reserved two free descriptor as a safety boundary
462 * between the tail and the head
464 if ((prio == MGNT_QUEUE) && (skb_queue_len(&ring->queue) > 10))
465 RT_TRACE(COMP_DBG, "-----[%d]---------ring->idx=%d "
466 "queue_len=%d---------\n", prio, ring->idx,
467 skb_queue_len(&ring->queue));
468 return skb_queue_len(&ring->queue);
471 short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
473 struct r8192_priv *priv = rtllib_priv(dev);
474 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
476 if (ring->entries - skb_queue_len(&ring->queue) >= 2)
477 return 1;
478 return 0;
481 void rtl8192_tx_timeout(struct net_device *dev)
483 struct r8192_priv *priv = rtllib_priv(dev);
485 schedule_work(&priv->reset_wq);
486 printk(KERN_INFO "TXTIMEOUT");
489 void rtl8192_irq_enable(struct net_device *dev)
491 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
492 priv->irq_enabled = 1;
494 priv->ops->irq_enable(dev);
497 void rtl8192_irq_disable(struct net_device *dev)
499 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
501 priv->ops->irq_disable(dev);
503 priv->irq_enabled = 0;
506 void rtl8192_irq_clear(struct net_device *dev)
508 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
510 priv->ops->irq_clear(dev);
514 void rtl8192_set_chan(struct net_device *dev, short ch)
516 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
518 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
519 if (priv->chan_forced)
520 return;
522 priv->chan = ch;
524 if (priv->rf_set_chan)
525 priv->rf_set_chan(dev, priv->chan);
528 void rtl8192_update_cap(struct net_device *dev, u16 cap)
530 struct r8192_priv *priv = rtllib_priv(dev);
531 struct rtllib_network *net = &priv->rtllib->current_network;
532 bool ShortPreamble;
534 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) {
535 if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT) {
536 ShortPreamble = true;
537 priv->dot11CurrentPreambleMode = PREAMBLE_SHORT;
538 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_SHORT_"
539 "PREAMBLE\n", __func__);
540 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
541 (unsigned char *)&ShortPreamble);
543 } else {
544 if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG) {
545 ShortPreamble = false;
546 priv->dot11CurrentPreambleMode = PREAMBLE_LONG;
547 RT_TRACE(COMP_DBG, "%s(): WLAN_CAPABILITY_LONG_"
548 "PREAMBLE\n", __func__);
549 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
550 (unsigned char *)&ShortPreamble);
554 if (net->mode & (IEEE_G|IEEE_N_24G)) {
555 u8 slot_time_val;
556 u8 CurSlotTime = priv->slot_time;
558 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
559 (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime)) {
560 if (CurSlotTime != SHORT_SLOT_TIME) {
561 slot_time_val = SHORT_SLOT_TIME;
562 priv->rtllib->SetHwRegHandler(dev,
563 HW_VAR_SLOT_TIME, &slot_time_val);
565 } else {
566 if (CurSlotTime != NON_SHORT_SLOT_TIME) {
567 slot_time_val = NON_SHORT_SLOT_TIME;
568 priv->rtllib->SetHwRegHandler(dev,
569 HW_VAR_SLOT_TIME, &slot_time_val);
575 static struct rtllib_qos_parameters def_qos_parameters = {
576 {3, 3, 3, 3},
577 {7, 7, 7, 7},
578 {2, 2, 2, 2},
579 {0, 0, 0, 0},
580 {0, 0, 0, 0}
583 void rtl8192_update_beacon(void *data)
585 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
586 update_beacon_wq.work);
587 struct net_device *dev = priv->rtllib->dev;
588 struct rtllib_device *ieee = priv->rtllib;
589 struct rtllib_network *net = &ieee->current_network;
591 if (ieee->pHTInfo->bCurrentHTSupport)
592 HTUpdateSelfAndPeerSetting(ieee, net);
593 ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
594 net->bssht.bdRT2RTLongSlotTime;
595 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
596 rtl8192_update_cap(dev, net->capability);
599 #define MOVE_INTO_HANDLER
600 int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
602 void rtl8192_qos_activate(void *data)
604 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
605 qos_activate);
606 struct net_device *dev = priv->rtllib->dev;
607 #ifndef MOVE_INTO_HANDLER
608 struct rtllib_qos_parameters *qos_parameters =
609 &priv->rtllib->current_network.qos_data.parameters;
610 u8 mode = priv->rtllib->current_network.mode;
611 u8 u1bAIFS;
612 u32 u4bAcParam;
613 #endif
614 int i;
616 if (priv == NULL)
617 return;
619 mutex_lock(&priv->mutex);
620 if (priv->rtllib->state != RTLLIB_LINKED)
621 goto success;
622 RT_TRACE(COMP_QOS, "qos active process with associate response "
623 "received\n");
625 for (i = 0; i < QOS_QUEUE_NUM; i++) {
626 #ifndef MOVE_INTO_HANDLER
627 u1bAIFS = qos_parameters->aifs[i] *
628 ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
629 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i])) <<
630 AC_PARAM_TXOP_LIMIT_OFFSET) |
631 (((u32)(qos_parameters->cw_max[i])) <<
632 AC_PARAM_ECW_MAX_OFFSET) |
633 (((u32)(qos_parameters->cw_min[i])) <<
634 AC_PARAM_ECW_MIN_OFFSET) |
635 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
636 RT_TRACE(COMP_DBG, "===>ACI:%d:u4bAcParam:%x\n", i, u4bAcParam);
637 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
638 #else
639 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i));
640 #endif
643 success:
644 mutex_unlock(&priv->mutex);
647 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
648 int active_network,
649 struct rtllib_network *network)
651 int ret = 0;
652 u32 size = sizeof(struct rtllib_qos_parameters);
654 if (priv->rtllib->state != RTLLIB_LINKED)
655 return ret;
657 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
658 return ret;
660 if (network->flags & NETWORK_HAS_QOS_MASK) {
661 if (active_network &&
662 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
663 network->qos_data.active = network->qos_data.supported;
665 if ((network->qos_data.active == 1) && (active_network == 1) &&
666 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
667 (network->qos_data.old_param_count !=
668 network->qos_data.param_count)) {
669 network->qos_data.old_param_count =
670 network->qos_data.param_count;
671 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
672 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
673 RT_TRACE(COMP_QOS, "QoS parameters change call "
674 "qos_activate\n");
676 } else {
677 memcpy(&priv->rtllib->current_network.qos_data.parameters,
678 &def_qos_parameters, size);
680 if ((network->qos_data.active == 1) && (active_network == 1)) {
681 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
682 RT_TRACE(COMP_QOS, "QoS was disabled call qos_"
683 "activate\n");
685 network->qos_data.active = 0;
686 network->qos_data.supported = 0;
689 return 0;
692 static int rtl8192_handle_beacon(struct net_device *dev,
693 struct rtllib_beacon *beacon,
694 struct rtllib_network *network)
696 struct r8192_priv *priv = rtllib_priv(dev);
698 rtl8192_qos_handle_probe_response(priv, 1, network);
700 queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
701 return 0;
705 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
706 struct rtllib_network *network)
708 int ret = 0;
709 unsigned long flags;
710 u32 size = sizeof(struct rtllib_qos_parameters);
711 int set_qos_param = 0;
713 if ((priv == NULL) || (network == NULL))
714 return ret;
716 if (priv->rtllib->state != RTLLIB_LINKED)
717 return ret;
719 if ((priv->rtllib->iw_mode != IW_MODE_INFRA))
720 return ret;
722 spin_lock_irqsave(&priv->rtllib->lock, flags);
723 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
724 memcpy(&priv->rtllib->current_network.qos_data.parameters,
725 &network->qos_data.parameters,
726 sizeof(struct rtllib_qos_parameters));
727 priv->rtllib->current_network.qos_data.active = 1;
728 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
729 set_qos_param = 1;
730 priv->rtllib->current_network.qos_data.old_param_count =
731 priv->rtllib->current_network.qos_data.param_count;
732 priv->rtllib->current_network.qos_data.param_count =
733 network->qos_data.param_count;
734 } else {
735 memcpy(&priv->rtllib->current_network.qos_data.parameters,
736 &def_qos_parameters, size);
737 priv->rtllib->current_network.qos_data.active = 0;
738 priv->rtllib->current_network.qos_data.supported = 0;
739 set_qos_param = 1;
742 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
744 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
745 network->flags, priv->rtllib->current_network.qos_data.active);
746 if (set_qos_param == 1) {
747 dm_init_edca_turbo(priv->rtllib->dev);
748 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
750 return ret;
753 static int rtl8192_handle_assoc_response(struct net_device *dev,
754 struct rtllib_assoc_response_frame *resp,
755 struct rtllib_network *network)
757 struct r8192_priv *priv = rtllib_priv(dev);
758 rtl8192_qos_association_resp(priv, network);
759 return 0;
762 void rtl8192_prepare_beacon(struct r8192_priv *priv)
764 struct net_device *dev = priv->rtllib->dev;
765 struct sk_buff *pskb = NULL, *pnewskb = NULL;
766 struct cb_desc *tcb_desc = NULL;
767 struct rtl8192_tx_ring *ring = NULL;
768 struct tx_desc *pdesc = NULL;
770 ring = &priv->tx_ring[BEACON_QUEUE];
771 pskb = __skb_dequeue(&ring->queue);
772 if (pskb)
773 kfree_skb(pskb);
775 pnewskb = rtllib_get_beacon(priv->rtllib);
776 if (!pnewskb)
777 return;
779 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
780 tcb_desc->queue_index = BEACON_QUEUE;
781 tcb_desc->data_rate = 2;
782 tcb_desc->RATRIndex = 7;
783 tcb_desc->bTxDisableRateFallBack = 1;
784 tcb_desc->bTxUseDriverAssingedRate = 1;
785 skb_push(pnewskb, priv->rtllib->tx_headroom);
787 pdesc = &ring->desc[0];
788 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
789 __skb_queue_tail(&ring->queue, pnewskb);
790 pdesc->OWN = 1;
792 return;
795 void rtl8192_stop_beacon(struct net_device *dev)
799 void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
801 struct r8192_priv *priv = rtllib_priv(dev);
802 struct rtllib_network *net;
803 u8 i = 0, basic_rate = 0;
804 net = &priv->rtllib->current_network;
806 for (i = 0; i < net->rates_len; i++) {
807 basic_rate = net->rates[i] & 0x7f;
808 switch (basic_rate) {
809 case MGN_1M:
810 *rate_config |= RRSR_1M;
811 break;
812 case MGN_2M:
813 *rate_config |= RRSR_2M;
814 break;
815 case MGN_5_5M:
816 *rate_config |= RRSR_5_5M;
817 break;
818 case MGN_11M:
819 *rate_config |= RRSR_11M;
820 break;
821 case MGN_6M:
822 *rate_config |= RRSR_6M;
823 break;
824 case MGN_9M:
825 *rate_config |= RRSR_9M;
826 break;
827 case MGN_12M:
828 *rate_config |= RRSR_12M;
829 break;
830 case MGN_18M:
831 *rate_config |= RRSR_18M;
832 break;
833 case MGN_24M:
834 *rate_config |= RRSR_24M;
835 break;
836 case MGN_36M:
837 *rate_config |= RRSR_36M;
838 break;
839 case MGN_48M:
840 *rate_config |= RRSR_48M;
841 break;
842 case MGN_54M:
843 *rate_config |= RRSR_54M;
844 break;
848 for (i = 0; i < net->rates_ex_len; i++) {
849 basic_rate = net->rates_ex[i] & 0x7f;
850 switch (basic_rate) {
851 case MGN_1M:
852 *rate_config |= RRSR_1M;
853 break;
854 case MGN_2M:
855 *rate_config |= RRSR_2M;
856 break;
857 case MGN_5_5M:
858 *rate_config |= RRSR_5_5M;
859 break;
860 case MGN_11M:
861 *rate_config |= RRSR_11M;
862 break;
863 case MGN_6M:
864 *rate_config |= RRSR_6M;
865 break;
866 case MGN_9M:
867 *rate_config |= RRSR_9M;
868 break;
869 case MGN_12M:
870 *rate_config |= RRSR_12M;
871 break;
872 case MGN_18M:
873 *rate_config |= RRSR_18M;
874 break;
875 case MGN_24M:
876 *rate_config |= RRSR_24M;
877 break;
878 case MGN_36M:
879 *rate_config |= RRSR_36M;
880 break;
881 case MGN_48M:
882 *rate_config |= RRSR_48M;
883 break;
884 case MGN_54M:
885 *rate_config |= RRSR_54M;
886 break;
891 void rtl8192_refresh_supportrate(struct r8192_priv *priv)
893 struct rtllib_device *ieee = priv->rtllib;
894 if (ieee->mode == WIRELESS_MODE_N_24G ||
895 ieee->mode == WIRELESS_MODE_N_5G) {
896 memcpy(ieee->Regdot11HTOperationalRateSet,
897 ieee->RegHTSuppRateSet, 16);
898 memcpy(ieee->Regdot11TxHTOperationalRateSet,
899 ieee->RegHTSuppRateSet, 16);
901 } else {
902 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
904 return;
907 u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
909 struct r8192_priv *priv = rtllib_priv(dev);
910 u8 ret = 0;
912 switch (priv->rf_chip) {
913 case RF_8225:
914 case RF_8256:
915 case RF_6052:
916 case RF_PSEUDO_11N:
917 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B);
918 break;
919 case RF_8258:
920 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
921 break;
922 default:
923 ret = WIRELESS_MODE_B;
924 break;
926 return ret;
929 void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
931 struct r8192_priv *priv = rtllib_priv(dev);
932 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
934 if ((wireless_mode == WIRELESS_MODE_AUTO) ||
935 ((wireless_mode & bSupportMode) == 0)) {
936 if (bSupportMode & WIRELESS_MODE_N_24G) {
937 wireless_mode = WIRELESS_MODE_N_24G;
938 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
939 wireless_mode = WIRELESS_MODE_N_5G;
940 } else if ((bSupportMode & WIRELESS_MODE_A)) {
941 wireless_mode = WIRELESS_MODE_A;
942 } else if ((bSupportMode & WIRELESS_MODE_G)) {
943 wireless_mode = WIRELESS_MODE_G;
944 } else if ((bSupportMode & WIRELESS_MODE_B)) {
945 wireless_mode = WIRELESS_MODE_B;
946 } else {
947 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode "
948 "supported (%x)!!!\n", __func__, bSupportMode);
949 wireless_mode = WIRELESS_MODE_B;
953 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) ==
954 (WIRELESS_MODE_G | WIRELESS_MODE_B))
955 wireless_mode = WIRELESS_MODE_G;
957 priv->rtllib->mode = wireless_mode;
959 ActUpdateChannelAccessSetting(dev, wireless_mode,
960 &priv->ChannelAccessSetting);
962 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
963 (wireless_mode == WIRELESS_MODE_N_5G)) {
964 priv->rtllib->pHTInfo->bEnableHT = 1;
965 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n",
966 __func__, wireless_mode);
967 } else {
968 priv->rtllib->pHTInfo->bEnableHT = 0;
969 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n",
970 __func__, wireless_mode);
973 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
974 rtl8192_refresh_supportrate(priv);
977 int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
979 struct r8192_priv *priv = rtllib_priv(dev);
980 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
981 (&(priv->rtllib->PowerSaveControl));
982 bool init_status = true;
983 priv->bDriverIsGoingToUnload = false;
984 priv->bdisable_nic = false;
986 priv->up = 1;
987 priv->rtllib->ieee_up = 1;
989 priv->up_first_time = 0;
990 RT_TRACE(COMP_INIT, "Bringing up iface");
991 priv->bfirst_init = true;
992 init_status = priv->ops->initialize_adapter(dev);
993 if (init_status != true) {
994 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
995 __func__);
996 priv->bfirst_init = false;
997 return -1;
1000 RT_TRACE(COMP_INIT, "start adapter finished\n");
1001 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
1002 priv->bfirst_init = false;
1004 if (priv->polling_timer_on == 0)
1005 check_rfctrl_gpio_timer((unsigned long)dev);
1007 if (priv->rtllib->state != RTLLIB_LINKED)
1008 rtllib_softmac_start_protocol(priv->rtllib, 0);
1009 rtllib_reset_queue(priv->rtllib);
1010 watch_dog_timer_callback((unsigned long) dev);
1012 if (!netif_queue_stopped(dev))
1013 netif_start_queue(dev);
1014 else
1015 netif_wake_queue(dev);
1017 return 0;
1020 int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
1022 struct r8192_priv *priv = rtllib_priv(dev);
1023 unsigned long flags = 0;
1024 u8 RFInProgressTimeOut = 0;
1026 if (priv->up == 0)
1027 return -1;
1029 if (priv->rtllib->rtllib_ips_leave != NULL)
1030 priv->rtllib->rtllib_ips_leave(dev);
1032 if (priv->rtllib->state == RTLLIB_LINKED)
1033 LeisurePSLeave(dev);
1035 priv->bDriverIsGoingToUnload = true;
1036 priv->up = 0;
1037 priv->rtllib->ieee_up = 0;
1038 priv->bfirst_after_down = 1;
1039 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
1040 if (!netif_queue_stopped(dev))
1041 netif_stop_queue(dev);
1043 priv->rtllib->wpa_ie_len = 0;
1044 kfree(priv->rtllib->wpa_ie);
1045 priv->rtllib->wpa_ie = NULL;
1046 CamResetAllEntry(dev);
1047 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1048 rtl8192_irq_disable(dev);
1050 del_timer_sync(&priv->watch_dog_timer);
1051 rtl8192_cancel_deferred_work(priv);
1052 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
1054 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1055 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1056 while (priv->RFChangeInProgress) {
1057 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1058 if (RFInProgressTimeOut > 100) {
1059 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1060 break;
1062 RT_TRACE(COMP_DBG, "===>%s():RF is in progress, need to wait "
1063 "until rf chang is done.\n", __func__);
1064 mdelay(1);
1065 RFInProgressTimeOut++;
1066 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1068 priv->RFChangeInProgress = true;
1069 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1070 priv->ops->stop_adapter(dev, false);
1071 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1072 priv->RFChangeInProgress = false;
1073 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1074 udelay(100);
1075 memset(&priv->rtllib->current_network, 0,
1076 offsetof(struct rtllib_network, list));
1077 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
1079 return 0;
1082 static void rtl8192_init_priv_handler(struct net_device *dev)
1084 struct r8192_priv *priv = rtllib_priv(dev);
1086 priv->rtllib->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
1087 priv->rtllib->set_chan = rtl8192_set_chan;
1088 priv->rtllib->link_change = priv->ops->link_change;
1089 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1090 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1091 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1092 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1093 priv->rtllib->get_nic_desc_num = rtl8192_get_nic_desc_num;
1094 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1095 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1096 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode;
1097 priv->rtllib->LeisurePSLeave = LeisurePSLeave;
1098 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode;
1099 priv->rf_set_chan = rtl8192_phy_SwChnl;
1101 priv->rtllib->start_send_beacons = rtl8192e_start_beacon;
1102 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
1104 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup;
1105 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep;
1106 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1108 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg;
1109 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
1110 rtl8192_GetHalfNmodeSupportByAPs;
1112 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg;
1113 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr;
1114 priv->rtllib->SetFwCmdHandler = NULL;
1115 priv->rtllib->InitialGainHandler = InitialGain819xPci;
1116 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq;
1117 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave;
1119 priv->rtllib->LedControlHandler = NULL;
1120 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1122 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192;
1124 priv->rtllib->rtllib_rfkill_poll = NULL;
1127 static void rtl8192_init_priv_constant(struct net_device *dev)
1129 struct r8192_priv *priv = rtllib_priv(dev);
1130 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1131 &(priv->rtllib->PowerSaveControl);
1133 pPSC->RegMaxLPSAwakeIntvl = 5;
1135 priv->RegPciASPM = 2;
1137 priv->RegDevicePciASPMSetting = 0x03;
1139 priv->RegHostPciASPMSetting = 0x02;
1141 priv->RegHwSwRfOffD3 = 2;
1143 priv->RegSupportPciASPM = 2;
1147 static void rtl8192_init_priv_variable(struct net_device *dev)
1149 struct r8192_priv *priv = rtllib_priv(dev);
1150 u8 i;
1152 priv->AcmMethod = eAcmWay2_SW;
1153 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
1154 priv->rtllib->hwscan_sem_up = 1;
1155 priv->rtllib->status = 0;
1156 priv->H2CTxCmdSeq = 0;
1157 priv->bDisableFrameBursting = 0;
1158 priv->bDMInitialGainEnable = 1;
1159 priv->polling_timer_on = 0;
1160 priv->up_first_time = 1;
1161 priv->blinked_ingpio = false;
1162 priv->bDriverIsGoingToUnload = false;
1163 priv->being_init_adapter = false;
1164 priv->initialized_at_probe = false;
1165 priv->sw_radio_on = true;
1166 priv->bdisable_nic = false;
1167 priv->bfirst_init = false;
1168 priv->txringcount = 64;
1169 priv->rxbuffersize = 9100;
1170 priv->rxringcount = MAX_RX_COUNT;
1171 priv->irq_enabled = 0;
1172 priv->chan = 1;
1173 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
1174 priv->RegChannelPlan = 0xf;
1175 priv->nrxAMPDU_size = 0;
1176 priv->nrxAMPDU_aggr_num = 0;
1177 priv->last_rxdesc_tsf_high = 0;
1178 priv->last_rxdesc_tsf_low = 0;
1179 priv->rtllib->mode = WIRELESS_MODE_AUTO;
1180 priv->rtllib->iw_mode = IW_MODE_INFRA;
1181 priv->rtllib->bNetPromiscuousMode = false;
1182 priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false;
1183 priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1184 false;
1185 priv->rtllib->ieee_up = 0;
1186 priv->retry_rts = DEFAULT_RETRY_RTS;
1187 priv->retry_data = DEFAULT_RETRY_DATA;
1188 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
1189 priv->rtllib->rate = 110;
1190 priv->rtllib->short_slot = 1;
1191 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
1192 priv->bcck_in_ch14 = false;
1193 priv->bfsync_processing = false;
1194 priv->CCKPresentAttentuation = 0;
1195 priv->rfa_txpowertrackingindex = 0;
1196 priv->rfc_txpowertrackingindex = 0;
1197 priv->CckPwEnl = 6;
1198 priv->ScanDelay = 50;
1199 priv->ResetProgress = RESET_TYPE_NORESET;
1200 priv->bForcedSilentReset = 0;
1201 priv->bDisableNormalResetCheck = false;
1202 priv->force_reset = false;
1203 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
1205 memset(&priv->InterruptLog, 0, sizeof(struct log_int_8190));
1206 priv->RxCounter = 0;
1207 priv->rtllib->wx_set_enc = 0;
1208 priv->bHwRadioOff = false;
1209 priv->RegRfOff = 0;
1210 priv->isRFOff = false;
1211 priv->bInPowerSaveMode = false;
1212 priv->rtllib->RfOffReason = 0;
1213 priv->RFChangeInProgress = false;
1214 priv->bHwRfOffAction = 0;
1215 priv->SetRFPowerStateInProgress = false;
1216 priv->rtllib->PowerSaveControl.bInactivePs = true;
1217 priv->rtllib->PowerSaveControl.bIPSModeBackup = false;
1218 priv->rtllib->PowerSaveControl.bLeisurePs = true;
1219 priv->rtllib->PowerSaveControl.bFwCtrlLPS = false;
1220 priv->rtllib->LPSDelayCnt = 0;
1221 priv->rtllib->sta_sleep = LPS_IS_WAKE;
1222 priv->rtllib->eRFPowerState = eRfOn;
1224 priv->txpower_checkcnt = 0;
1225 priv->thermal_readback_index = 0;
1226 priv->txpower_tracking_callback_cnt = 0;
1227 priv->ccktxpower_adjustcnt_ch14 = 0;
1228 priv->ccktxpower_adjustcnt_not_ch14 = 0;
1230 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
1231 priv->rtllib->iw_mode = IW_MODE_INFRA;
1232 priv->rtllib->active_scan = 1;
1233 priv->rtllib->be_scan_inprogress = false;
1234 priv->rtllib->modulation = RTLLIB_CCK_MODULATION |
1235 RTLLIB_OFDM_MODULATION;
1236 priv->rtllib->host_encrypt = 1;
1237 priv->rtllib->host_decrypt = 1;
1239 priv->rtllib->dot11PowerSaveMode = eActive;
1240 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
1241 priv->rtllib->MaxMssDensity = 0;
1242 priv->rtllib->MinSpaceCfg = 0;
1244 priv->card_type = PCI;
1246 priv->AcmControl = 0;
1247 priv->pFirmware = vmalloc(sizeof(struct rt_firmware));
1248 if (priv->pFirmware)
1249 memset(priv->pFirmware, 0, sizeof(struct rt_firmware));
1251 skb_queue_head_init(&priv->rx_queue);
1252 skb_queue_head_init(&priv->skb_queue);
1254 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1255 skb_queue_head_init(&priv->rtllib->skb_waitQ[i]);
1256 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1257 skb_queue_head_init(&priv->rtllib->skb_aggQ[i]);
1260 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
1262 spin_lock_init(&priv->fw_scan_lock);
1263 spin_lock_init(&priv->tx_lock);
1264 spin_lock_init(&priv->irq_lock);
1265 spin_lock_init(&priv->irq_th_lock);
1266 spin_lock_init(&priv->rf_ps_lock);
1267 spin_lock_init(&priv->ps_lock);
1268 spin_lock_init(&priv->rf_lock);
1269 spin_lock_init(&priv->rt_h2c_lock);
1270 sema_init(&priv->wx_sem, 1);
1271 sema_init(&priv->rf_sem, 1);
1272 mutex_init(&priv->mutex);
1275 static void rtl8192_init_priv_task(struct net_device *dev)
1277 struct r8192_priv *priv = rtllib_priv(dev);
1279 priv->priv_wq = create_workqueue(DRV_NAME);
1280 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
1281 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)IPSLeave_wq, dev);
1282 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
1283 (void *)rtl819x_watchdog_wqcallback, dev);
1284 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
1285 (void *)dm_txpower_trackingcallback, dev);
1286 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
1287 (void *)dm_rf_pathcheck_workitemcallback, dev);
1288 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
1289 (void *)rtl8192_update_beacon, dev);
1290 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
1291 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
1292 (void *) rtl8192_hw_wakeup_wq, dev);
1293 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
1294 (void *) rtl8192_hw_sleep_wq, dev);
1295 tasklet_init(&priv->irq_rx_tasklet,
1296 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1297 (unsigned long)priv);
1298 tasklet_init(&priv->irq_tx_tasklet,
1299 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
1300 (unsigned long)priv);
1301 tasklet_init(&priv->irq_prepare_beacon_tasklet,
1302 (void(*)(unsigned long))rtl8192_prepare_beacon,
1303 (unsigned long)priv);
1306 short rtl8192_get_channel_map(struct net_device *dev)
1308 int i;
1310 struct r8192_priv *priv = rtllib_priv(dev);
1311 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256)
1312 && (priv->rf_chip != RF_6052)) {
1313 RT_TRACE(COMP_ERR, "%s: unknown rf chip, can't set channel "
1314 "map\n", __func__);
1315 return -1;
1318 if (priv->ChannelPlan > COUNTRY_CODE_MAX) {
1319 printk(KERN_INFO "rtl819x_init:Error channel plan! Set to "
1320 "default.\n");
1321 priv->ChannelPlan = COUNTRY_CODE_FCC;
1323 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
1324 Dot11d_Init(priv->rtllib);
1325 Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib);
1326 for (i = 1; i <= 11; i++)
1327 (priv->rtllib->active_channel_map)[i] = 1;
1328 (priv->rtllib->active_channel_map)[12] = 2;
1329 (priv->rtllib->active_channel_map)[13] = 2;
1331 return 0;
1334 short rtl8192_init(struct net_device *dev)
1336 struct r8192_priv *priv = rtllib_priv(dev);
1338 memset(&(priv->stats), 0, sizeof(struct rt_stats));
1340 rtl8192_dbgp_flag_init(dev);
1341 rtl8192_init_priv_handler(dev);
1342 rtl8192_init_priv_constant(dev);
1343 rtl8192_init_priv_variable(dev);
1344 rtl8192_init_priv_lock(priv);
1345 rtl8192_init_priv_task(dev);
1346 priv->ops->get_eeprom_size(dev);
1347 priv->ops->init_adapter_variable(dev);
1348 rtl8192_get_channel_map(dev);
1350 init_hal_dm(dev);
1352 init_timer(&priv->watch_dog_timer);
1353 setup_timer(&priv->watch_dog_timer,
1354 watch_dog_timer_callback,
1355 (unsigned long) dev);
1357 init_timer(&priv->gpio_polling_timer);
1358 setup_timer(&priv->gpio_polling_timer,
1359 check_rfctrl_gpio_timer,
1360 (unsigned long)dev);
1362 rtl8192_irq_disable(dev);
1363 if (request_irq(dev->irq, (void *)rtl8192_interrupt_rsl, IRQF_SHARED,
1364 dev->name, dev)) {
1365 printk(KERN_ERR "Error allocating IRQ %d", dev->irq);
1366 return -1;
1367 } else {
1368 priv->irq = dev->irq;
1369 RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq);
1372 if (rtl8192_pci_initdescring(dev) != 0) {
1373 printk(KERN_ERR "Endopoints initialization failed");
1374 return -1;
1377 return 0;
1380 /***************************************************************************
1381 -------------------------------WATCHDOG STUFF---------------------------
1382 ***************************************************************************/
1383 short rtl8192_is_tx_queue_empty(struct net_device *dev)
1385 int i = 0;
1386 struct r8192_priv *priv = rtllib_priv(dev);
1387 for (i = 0; i <= MGNT_QUEUE; i++) {
1388 if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE))
1389 continue;
1390 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) {
1391 printk(KERN_INFO "===>tx queue is not empty:%d, %d\n",
1392 i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1393 return 0;
1396 return 1;
1399 enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
1401 struct r8192_priv *priv = rtllib_priv(dev);
1402 u8 QueueID;
1403 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1404 bool bCheckFwTxCnt = false;
1405 struct rtl8192_tx_ring *ring = NULL;
1406 struct sk_buff *skb = NULL;
1407 struct cb_desc *tcb_desc = NULL;
1408 unsigned long flags = 0;
1410 switch (priv->rtllib->ps) {
1411 case RTLLIB_PS_DISABLED:
1412 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
1413 break;
1414 case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
1415 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1416 break;
1417 default:
1418 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1419 break;
1421 spin_lock_irqsave(&priv->irq_th_lock, flags);
1422 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) {
1423 if (QueueID == TXCMD_QUEUE)
1424 continue;
1426 if (QueueID == BEACON_QUEUE)
1427 continue;
1429 ring = &priv->tx_ring[QueueID];
1431 if (skb_queue_len(&ring->queue) == 0) {
1432 continue;
1433 } else {
1434 skb = (&ring->queue)->next;
1435 tcb_desc = (struct cb_desc *)(skb->cb +
1436 MAX_DEV_ADDR_SIZE);
1437 tcb_desc->nStuckCount++;
1438 bCheckFwTxCnt = true;
1439 if (tcb_desc->nStuckCount > 1)
1440 printk(KERN_INFO "%s: QueueID=%d tcb_desc->n"
1441 "StuckCount=%d\n", __func__, QueueID,
1442 tcb_desc->nStuckCount);
1445 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1447 if (bCheckFwTxCnt) {
1448 if (priv->ops->TxCheckStuckHandler(dev)) {
1449 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no"
1450 " Tx condition!\n");
1451 return RESET_TYPE_SILENT;
1455 return RESET_TYPE_NORESET;
1458 enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
1460 struct r8192_priv *priv = rtllib_priv(dev);
1462 if (priv->ops->RxCheckStuckHandler(dev)) {
1463 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
1464 return RESET_TYPE_SILENT;
1467 return RESET_TYPE_NORESET;
1470 enum reset_type
1471 rtl819x_ifcheck_resetornot(struct net_device *dev)
1473 struct r8192_priv *priv = rtllib_priv(dev);
1474 enum reset_type TxResetType = RESET_TYPE_NORESET;
1475 enum reset_type RxResetType = RESET_TYPE_NORESET;
1476 enum rt_rf_power_state rfState;
1478 rfState = priv->rtllib->eRFPowerState;
1480 if (rfState == eRfOn)
1481 TxResetType = rtl819x_TxCheckStuck(dev);
1483 if (rfState == eRfOn &&
1484 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1485 (priv->rtllib->state == RTLLIB_LINKED))
1486 RxResetType = rtl819x_RxCheckStuck(dev);
1488 if (TxResetType == RESET_TYPE_NORMAL ||
1489 RxResetType == RESET_TYPE_NORMAL) {
1490 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1491 __func__, TxResetType, RxResetType);
1492 return RESET_TYPE_NORMAL;
1493 } else if (TxResetType == RESET_TYPE_SILENT ||
1494 RxResetType == RESET_TYPE_SILENT) {
1495 printk(KERN_INFO "%s(): TxResetType is %d, RxResetType is %d\n",
1496 __func__, TxResetType, RxResetType);
1497 return RESET_TYPE_SILENT;
1498 } else {
1499 return RESET_TYPE_NORESET;
1504 void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
1508 void rtl819x_ifsilentreset(struct net_device *dev)
1510 struct r8192_priv *priv = rtllib_priv(dev);
1511 u8 reset_times = 0;
1512 int reset_status = 0;
1513 struct rtllib_device *ieee = priv->rtllib;
1514 unsigned long flag;
1516 u8 IsPortal = 0;
1519 if (priv->ResetProgress == RESET_TYPE_NORESET) {
1521 RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
1523 priv->ResetProgress = RESET_TYPE_SILENT;
1525 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1526 if (priv->RFChangeInProgress) {
1527 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1528 goto END;
1530 priv->RFChangeInProgress = true;
1531 priv->bResetInProgress = true;
1532 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1534 RESET_START:
1536 down(&priv->wx_sem);
1538 if (priv->rtllib->state == RTLLIB_LINKED)
1539 LeisurePSLeave(dev);
1541 if (IS_NIC_DOWN(priv)) {
1542 RT_TRACE(COMP_ERR, "%s():the driver is not up! "
1543 "return\n", __func__);
1544 up(&priv->wx_sem);
1545 return ;
1547 priv->up = 0;
1549 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n",
1550 __func__);
1551 mdelay(1000);
1552 RT_TRACE(COMP_RESET, "%s():111111111111111111111111======>start"
1553 " to down the driver\n", __func__);
1555 if (!netif_queue_stopped(dev))
1556 netif_stop_queue(dev);
1558 rtl8192_irq_disable(dev);
1559 del_timer_sync(&priv->watch_dog_timer);
1560 rtl8192_cancel_deferred_work(priv);
1561 deinit_hal_dm(dev);
1562 rtllib_stop_scan_syncro(ieee);
1564 if (ieee->state == RTLLIB_LINKED) {
1565 SEM_DOWN_IEEE_WX(&ieee->wx_sem);
1566 printk(KERN_INFO "ieee->state is RTLLIB_LINKED\n");
1567 rtllib_stop_send_beacons(priv->rtllib);
1568 del_timer_sync(&ieee->associate_timer);
1569 cancel_delayed_work(&ieee->associate_retry_wq);
1570 rtllib_stop_scan(ieee);
1571 netif_carrier_off(dev);
1572 SEM_UP_IEEE_WX(&ieee->wx_sem);
1573 } else {
1574 printk(KERN_INFO "ieee->state is NOT LINKED\n");
1575 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
1578 dm_backup_dynamic_mechanism_state(dev);
1580 up(&priv->wx_sem);
1581 RT_TRACE(COMP_RESET, "%s():<==========down process is "
1582 "finished\n", __func__);
1584 RT_TRACE(COMP_RESET, "%s():<===========up process start\n",
1585 __func__);
1586 reset_status = _rtl8192_up(dev, true);
1588 RT_TRACE(COMP_RESET, "%s():<===========up process is "
1589 "finished\n", __func__);
1590 if (reset_status == -1) {
1591 if (reset_times < 3) {
1592 reset_times++;
1593 goto RESET_START;
1594 } else {
1595 RT_TRACE(COMP_ERR, " ERR!!! %s(): Reset "
1596 "Failed!!\n", __func__);
1600 ieee->is_silent_reset = 1;
1602 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1603 priv->RFChangeInProgress = false;
1604 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
1606 EnableHWSecurityConfig8192(dev);
1608 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1609 IW_MODE_INFRA) {
1610 ieee->set_chan(ieee->dev,
1611 ieee->current_network.channel);
1613 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1615 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1616 IW_MODE_ADHOC) {
1617 ieee->set_chan(ieee->dev,
1618 ieee->current_network.channel);
1619 ieee->link_change(ieee->dev);
1621 notify_wx_assoc_event(ieee);
1623 rtllib_start_send_beacons(ieee);
1625 if (ieee->data_hard_resume)
1626 ieee->data_hard_resume(ieee->dev);
1627 netif_carrier_on(ieee->dev);
1628 } else if (ieee->iw_mode == IW_MODE_MESH) {
1629 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1632 CamRestoreAllEntry(dev);
1633 dm_restore_dynamic_mechanism_state(dev);
1634 END:
1635 priv->ResetProgress = RESET_TYPE_NORESET;
1636 priv->reset_count++;
1638 priv->bForcedSilentReset = false;
1639 priv->bResetInProgress = false;
1641 write_nic_byte(dev, UFWP, 1);
1642 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n",
1643 priv->reset_count);
1647 void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1648 u32 *TotalRxDataNum)
1650 u16 SlotIndex;
1651 u8 i;
1653 *TotalRxBcnNum = 0;
1654 *TotalRxDataNum = 0;
1656 SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++) %
1657 (priv->rtllib->LinkDetectInfo.SlotNum);
1658 priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] =
1659 priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod;
1660 priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] =
1661 priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod;
1662 for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) {
1663 *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i];
1664 *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i];
1669 void rtl819x_watchdog_wqcallback(void *data)
1671 struct r8192_priv *priv = container_of_dwork_rsl(data,
1672 struct r8192_priv, watch_dog_wq);
1673 struct net_device *dev = priv->rtllib->dev;
1674 struct rtllib_device *ieee = priv->rtllib;
1675 enum reset_type ResetType = RESET_TYPE_NORESET;
1676 static u8 check_reset_cnt;
1677 unsigned long flags;
1678 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1679 (&(priv->rtllib->PowerSaveControl));
1680 bool bBusyTraffic = false;
1681 bool bHigherBusyTraffic = false;
1682 bool bHigherBusyRxTraffic = false;
1683 bool bEnterPS = false;
1685 if (IS_NIC_DOWN(priv) || (priv->bHwRadioOff == true))
1686 return;
1688 if (priv->rtllib->state >= RTLLIB_LINKED) {
1689 if (priv->rtllib->CntAfterLink < 2)
1690 priv->rtllib->CntAfterLink++;
1691 } else {
1692 priv->rtllib->CntAfterLink = 0;
1695 hal_dm_watchdog(dev);
1697 if (rtllib_act_scanning(priv->rtllib, false) == false) {
1698 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
1699 RTLLIB_NOLINK) &&
1700 (ieee->eRFPowerState == eRfOn) && !ieee->is_set_key &&
1701 (!ieee->proto_stoppping) && !ieee->wx_set_enc) {
1702 if ((ieee->PowerSaveControl.ReturnPoint ==
1703 IPS_CALLBACK_NONE) &&
1704 (!ieee->bNetPromiscuousMode)) {
1705 RT_TRACE(COMP_PS, "====================>haha: "
1706 "IPSEnter()\n");
1707 IPSEnter(dev);
1711 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode ==
1712 IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode)) {
1713 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 100 ||
1714 ieee->LinkDetectInfo.NumTxOkInPeriod > 100)
1715 bBusyTraffic = true;
1718 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1719 ieee->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1720 bHigherBusyTraffic = true;
1721 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000)
1722 bHigherBusyRxTraffic = true;
1723 else
1724 bHigherBusyRxTraffic = false;
1727 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1728 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1729 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1730 bEnterPS = false;
1731 else
1732 bEnterPS = true;
1734 if (ieee->current_network.beacon_interval < 95)
1735 bEnterPS = false;
1737 if (bEnterPS)
1738 LeisurePSEnter(dev);
1739 else
1740 LeisurePSLeave(dev);
1742 } else {
1743 RT_TRACE(COMP_LPS, "====>no link LPS leave\n");
1744 LeisurePSLeave(dev);
1747 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
1748 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
1749 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1750 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
1752 ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1753 ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
1755 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1756 u32 TotalRxBcnNum = 0;
1757 u32 TotalRxDataNum = 0;
1759 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
1761 if ((TotalRxBcnNum+TotalRxDataNum) == 0)
1762 priv->check_roaming_cnt++;
1763 else
1764 priv->check_roaming_cnt = 0;
1767 if (priv->check_roaming_cnt > 0) {
1768 if (ieee->eRFPowerState == eRfOff)
1769 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
1771 printk(KERN_INFO "===>%s(): AP is power off, chan:%d,"
1772 " connect another one\n", __func__, priv->chan);
1774 ieee->state = RTLLIB_ASSOCIATING;
1776 RemovePeerTS(priv->rtllib,
1777 priv->rtllib->current_network.bssid);
1778 ieee->is_roaming = true;
1779 ieee->is_set_key = false;
1780 ieee->link_change(dev);
1781 if (ieee->LedControlHandler)
1782 ieee->LedControlHandler(ieee->dev,
1783 LED_CTL_START_TO_LINK);
1785 notify_wx_assoc_event(ieee);
1787 if (!(ieee->rtllib_ap_sec_type(ieee) &
1788 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
1789 queue_delayed_work_rsl(ieee->wq,
1790 &ieee->associate_procedure_wq, 0);
1792 priv->check_roaming_cnt = 0;
1794 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
1795 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
1799 spin_lock_irqsave(&priv->tx_lock, flags);
1800 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1801 (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) {
1802 ResetType = rtl819x_ifcheck_resetornot(dev);
1803 check_reset_cnt = 3;
1805 spin_unlock_irqrestore(&priv->tx_lock, flags);
1807 if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) {
1808 priv->ResetProgress = RESET_TYPE_NORMAL;
1809 RT_TRACE(COMP_RESET, "%s(): NOMAL RESET\n", __func__);
1810 return;
1813 if (((priv->force_reset) || (!priv->bDisableNormalResetCheck &&
1814 ResetType == RESET_TYPE_SILENT)))
1815 rtl819x_ifsilentreset(dev);
1816 priv->force_reset = false;
1817 priv->bForcedSilentReset = false;
1818 priv->bResetInProgress = false;
1819 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1822 void watch_dog_timer_callback(unsigned long data)
1824 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
1825 queue_delayed_work_rsl(priv->priv_wq, &priv->watch_dog_wq, 0);
1826 mod_timer(&priv->watch_dog_timer, jiffies +
1827 MSECS(RTLLIB_WATCH_DOG_TIME));
1830 /****************************************************************************
1831 ---------------------------- NIC TX/RX STUFF---------------------------
1832 *****************************************************************************/
1833 void rtl8192_rx_enable(struct net_device *dev)
1835 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1836 priv->ops->rx_enable(dev);
1839 void rtl8192_tx_enable(struct net_device *dev)
1841 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1843 priv->ops->tx_enable(dev);
1845 rtllib_reset_queue(priv->rtllib);
1849 static void rtl8192_free_rx_ring(struct net_device *dev)
1851 struct r8192_priv *priv = rtllib_priv(dev);
1852 int i, rx_queue_idx;
1854 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE;
1855 rx_queue_idx++) {
1856 for (i = 0; i < priv->rxringcount; i++) {
1857 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
1858 if (!skb)
1859 continue;
1861 pci_unmap_single(priv->pdev,
1862 *((dma_addr_t *)skb->cb),
1863 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1864 kfree_skb(skb);
1867 pci_free_consistent(priv->pdev,
1868 sizeof(*priv->rx_ring[rx_queue_idx]) *
1869 priv->rxringcount,
1870 priv->rx_ring[rx_queue_idx],
1871 priv->rx_ring_dma[rx_queue_idx]);
1872 priv->rx_ring[rx_queue_idx] = NULL;
1876 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1878 struct r8192_priv *priv = rtllib_priv(dev);
1879 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1881 while (skb_queue_len(&ring->queue)) {
1882 struct tx_desc *entry = &ring->desc[ring->idx];
1883 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1885 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1886 skb->len, PCI_DMA_TODEVICE);
1887 kfree_skb(skb);
1888 ring->idx = (ring->idx + 1) % ring->entries;
1891 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
1892 ring->desc, ring->dma);
1893 ring->desc = NULL;
1896 void rtl8192_data_hard_stop(struct net_device *dev)
1901 void rtl8192_data_hard_resume(struct net_device *dev)
1905 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1906 int rate)
1908 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1909 int ret;
1910 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1911 MAX_DEV_ADDR_SIZE);
1912 u8 queue_index = tcb_desc->queue_index;
1914 if ((priv->rtllib->eRFPowerState == eRfOff) || IS_NIC_DOWN(priv) ||
1915 priv->bResetInProgress) {
1916 kfree_skb(skb);
1917 return;
1920 assert(queue_index != TXCMD_QUEUE);
1923 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1924 skb_push(skb, priv->rtllib->tx_headroom);
1925 ret = rtl8192_tx(dev, skb);
1926 if (ret != 0) {
1927 kfree_skb(skb);
1930 if (queue_index != MGNT_QUEUE) {
1931 priv->rtllib->stats.tx_bytes += (skb->len -
1932 priv->rtllib->tx_headroom);
1933 priv->rtllib->stats.tx_packets++;
1937 return;
1940 int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1942 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1943 int ret;
1944 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1945 MAX_DEV_ADDR_SIZE);
1946 u8 queue_index = tcb_desc->queue_index;
1948 if (queue_index != TXCMD_QUEUE) {
1949 if ((priv->rtllib->eRFPowerState == eRfOff) ||
1950 IS_NIC_DOWN(priv) || priv->bResetInProgress) {
1951 kfree_skb(skb);
1952 return 0;
1956 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1957 if (queue_index == TXCMD_QUEUE) {
1958 rtl8192_tx_cmd(dev, skb);
1959 ret = 0;
1960 return ret;
1961 } else {
1962 tcb_desc->RATRIndex = 7;
1963 tcb_desc->bTxDisableRateFallBack = 1;
1964 tcb_desc->bTxUseDriverAssingedRate = 1;
1965 tcb_desc->bTxEnableFwCalcDur = 1;
1966 skb_push(skb, priv->rtllib->tx_headroom);
1967 ret = rtl8192_tx(dev, skb);
1968 if (ret != 0) {
1969 kfree_skb(skb);
1975 return ret;
1979 void rtl8192_tx_isr(struct net_device *dev, int prio)
1981 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1983 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1985 while (skb_queue_len(&ring->queue)) {
1986 struct tx_desc *entry = &ring->desc[ring->idx];
1987 struct sk_buff *skb;
1989 if (prio != BEACON_QUEUE) {
1990 if (entry->OWN)
1991 return;
1992 ring->idx = (ring->idx + 1) % ring->entries;
1995 skb = __skb_dequeue(&ring->queue);
1996 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1997 skb->len, PCI_DMA_TODEVICE);
1999 kfree_skb(skb);
2001 if (prio != BEACON_QUEUE)
2002 tasklet_schedule(&priv->irq_tx_tasklet);
2005 void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
2007 struct r8192_priv *priv = rtllib_priv(dev);
2008 struct rtl8192_tx_ring *ring;
2009 struct tx_desc_cmd *entry;
2010 unsigned int idx;
2011 struct cb_desc *tcb_desc;
2012 unsigned long flags;
2014 spin_lock_irqsave(&priv->irq_th_lock, flags);
2015 ring = &priv->tx_ring[TXCMD_QUEUE];
2017 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2018 entry = (struct tx_desc_cmd *) &ring->desc[idx];
2020 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2022 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
2024 __skb_queue_tail(&ring->queue, skb);
2025 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2027 return;
2030 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
2032 struct r8192_priv *priv = rtllib_priv(dev);
2033 struct rtl8192_tx_ring *ring;
2034 unsigned long flags;
2035 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
2036 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;
2042 int idx;
2043 u32 fwinfo_size = 0;
2045 if (priv->bdisable_nic) {
2046 RT_TRACE(COMP_ERR, "%s: ERR!! Nic is disabled! Can't tx packet"
2047 " len=%d qidx=%d!!!\n", __func__, skb->len,
2048 tcb_desc->queue_index);
2049 return skb->len;
2052 priv->rtllib->bAwakePktSent = true;
2054 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
2056 header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size);
2057 fc = header->frame_ctl;
2058 type = WLAN_FC_GET_TYPE(fc);
2059 stype = WLAN_FC_GET_STYPE(fc);
2060 pda_addr = header->addr1;
2062 if (is_multicast_ether_addr(pda_addr))
2063 multi_addr = true;
2064 else if (is_broadcast_ether_addr(pda_addr))
2065 broad_addr = true;
2066 else
2067 uni_addr = true;
2069 if (uni_addr)
2070 priv->stats.txbytesunicast += skb->len - fwinfo_size;
2071 else if (multi_addr)
2072 priv->stats.txbytesmulticast += skb->len - fwinfo_size;
2073 else
2074 priv->stats.txbytesbroadcast += skb->len - fwinfo_size;
2076 spin_lock_irqsave(&priv->irq_th_lock, flags);
2077 ring = &priv->tx_ring[tcb_desc->queue_index];
2078 if (tcb_desc->queue_index != BEACON_QUEUE)
2079 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
2080 else
2081 idx = 0;
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 = "
2086 "%d, skblen = 0x%x queuelen=%d",
2087 tcb_desc->queue_index, ring->idx, idx, skb->len,
2088 skb_queue_len(&ring->queue));
2089 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2090 return skb->len;
2093 if (type == RTLLIB_FTYPE_DATA) {
2094 if (priv->rtllib->LedControlHandler)
2095 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
2097 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
2098 __skb_queue_tail(&ring->queue, skb);
2099 pdesc->OWN = 1;
2100 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2101 dev->trans_start = jiffies;
2103 write_nic_word(dev, TPPoll, 0x01 << tcb_desc->queue_index);
2104 return 0;
2107 short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
2109 struct r8192_priv *priv = rtllib_priv(dev);
2110 struct rx_desc *entry = NULL;
2111 int i, rx_queue_idx;
2113 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2114 priv->rx_ring[rx_queue_idx] = pci_alloc_consistent(priv->pdev,
2115 sizeof(*priv->rx_ring[rx_queue_idx]) *
2116 priv->rxringcount,
2117 &priv->rx_ring_dma[rx_queue_idx]);
2119 if (!priv->rx_ring[rx_queue_idx] ||
2120 (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
2121 RT_TRACE(COMP_ERR, "Cannot allocate RX ring\n");
2122 return -ENOMEM;
2125 memset(priv->rx_ring[rx_queue_idx], 0,
2126 sizeof(*priv->rx_ring[rx_queue_idx]) *
2127 priv->rxringcount);
2128 priv->rx_idx[rx_queue_idx] = 0;
2130 for (i = 0; i < priv->rxringcount; i++) {
2131 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
2132 dma_addr_t *mapping;
2133 entry = &priv->rx_ring[rx_queue_idx][i];
2134 if (!skb)
2135 return 0;
2136 skb->dev = dev;
2137 priv->rx_buf[rx_queue_idx][i] = skb;
2138 mapping = (dma_addr_t *)skb->cb;
2139 *mapping = pci_map_single(priv->pdev,
2140 skb_tail_pointer_rsl(skb),
2141 priv->rxbuffersize,
2142 PCI_DMA_FROMDEVICE);
2144 entry->BufferAddress = cpu_to_le32(*mapping);
2146 entry->Length = priv->rxbuffersize;
2147 entry->OWN = 1;
2150 entry->EOR = 1;
2152 return 0;
2155 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
2156 unsigned int prio, unsigned int entries)
2158 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2159 struct tx_desc *ring;
2160 dma_addr_t dma;
2161 int i;
2163 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
2164 if (!ring || (unsigned long)ring & 0xFF) {
2165 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n",
2166 prio);
2167 return -ENOMEM;
2170 memset(ring, 0, sizeof(*ring)*entries);
2171 priv->tx_ring[prio].desc = ring;
2172 priv->tx_ring[prio].dma = dma;
2173 priv->tx_ring[prio].idx = 0;
2174 priv->tx_ring[prio].entries = entries;
2175 skb_queue_head_init(&priv->tx_ring[prio].queue);
2177 for (i = 0; i < entries; i++)
2178 ring[i].NextDescAddress =
2179 cpu_to_le32((u32)dma + ((i + 1) % entries) *
2180 sizeof(*ring));
2182 return 0;
2186 short rtl8192_pci_initdescring(struct net_device *dev)
2188 u32 ret;
2189 int i;
2190 struct r8192_priv *priv = rtllib_priv(dev);
2192 ret = rtl8192_alloc_rx_desc_ring(dev);
2193 if (ret)
2194 return ret;
2196 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2197 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
2198 if (ret)
2199 goto err_free_rings;
2202 return 0;
2204 err_free_rings:
2205 rtl8192_free_rx_ring(dev);
2206 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2207 if (priv->tx_ring[i].desc)
2208 rtl8192_free_tx_ring(dev, i);
2209 return 1;
2212 void rtl8192_pci_resetdescring(struct net_device *dev)
2214 struct r8192_priv *priv = rtllib_priv(dev);
2215 int i, rx_queue_idx;
2216 unsigned long flags = 0;
2218 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
2219 if (priv->rx_ring[rx_queue_idx]) {
2220 struct rx_desc *entry = NULL;
2221 for (i = 0; i < priv->rxringcount; i++) {
2222 entry = &priv->rx_ring[rx_queue_idx][i];
2223 entry->OWN = 1;
2225 priv->rx_idx[rx_queue_idx] = 0;
2229 spin_lock_irqsave(&priv->irq_th_lock, flags);
2230 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2231 if (priv->tx_ring[i].desc) {
2232 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
2234 while (skb_queue_len(&ring->queue)) {
2235 struct tx_desc *entry = &ring->desc[ring->idx];
2236 struct sk_buff *skb =
2237 __skb_dequeue(&ring->queue);
2239 pci_unmap_single(priv->pdev,
2240 le32_to_cpu(entry->TxBuffAddr),
2241 skb->len, PCI_DMA_TODEVICE);
2242 kfree_skb(skb);
2243 ring->idx = (ring->idx + 1) % ring->entries;
2245 ring->idx = 0;
2248 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2251 void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
2252 struct rtllib_rx_stats *stats)
2254 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2256 if (stats->bIsAMPDU && !stats->bFirstMPDU)
2257 stats->mac_time = priv->LastRxDescTSF;
2258 else
2259 priv->LastRxDescTSF = stats->mac_time;
2262 long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index)
2264 long signal_power;
2266 signal_power = (long)((signal_strength_index + 1) >> 1);
2267 signal_power -= 95;
2269 return signal_power;
2273 void
2274 rtl819x_update_rxsignalstatistics8190pci(
2275 struct r8192_priv *priv,
2276 struct rtllib_rx_stats *pprevious_stats
2279 int weighting = 0;
2282 if (priv->stats.recv_signal_power == 0)
2283 priv->stats.recv_signal_power =
2284 pprevious_stats->RecvSignalPower;
2286 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
2287 weighting = 5;
2288 else if (pprevious_stats->RecvSignalPower <
2289 priv->stats.recv_signal_power)
2290 weighting = (-5);
2291 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 +
2292 pprevious_stats->RecvSignalPower +
2293 weighting) / 6;
2296 void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv,
2297 struct rtllib_rx_stats *pprevious_stats)
2302 u8 rtl819x_query_rxpwrpercentage(char antpower)
2304 if ((antpower <= -100) || (antpower >= 20))
2305 return 0;
2306 else if (antpower >= 0)
2307 return 100;
2308 else
2309 return 100 + antpower;
2311 } /* QueryRxPwrPercentage */
2314 rtl819x_evm_dbtopercentage(
2315 char value
2318 char ret_val;
2320 ret_val = value;
2322 if (ret_val >= 0)
2323 ret_val = 0;
2324 if (ret_val <= -33)
2325 ret_val = -33;
2326 ret_val = 0 - ret_val;
2327 ret_val *= 3;
2328 if (ret_val == 99)
2329 ret_val = 100;
2330 return ret_val;
2333 void
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;
2351 u16 fc = 0, type = 0;
2352 u32 skb_len = 0;
2353 int rx_queue_idx = RX_MPDU_QUEUE;
2355 struct rtllib_rx_stats stats = {
2356 .signal = 0,
2357 .noise = -98,
2358 .rate = 0,
2359 .freq = RTLLIB_24GHZ_BAND,
2361 unsigned int count = priv->rxringcount;
2363 stats.nic_type = NIC_8192E;
2365 while (count--) {
2366 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx]
2367 [priv->rx_idx[rx_queue_idx]];
2368 struct sk_buff *skb = priv->rx_buf[rx_queue_idx]
2369 [priv->rx_idx[rx_queue_idx]];
2371 if (pdesc->OWN) {
2372 return;
2373 } else {
2374 struct sk_buff *new_skb;
2376 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
2377 pdesc, skb))
2378 goto done;
2379 new_skb = dev_alloc_skb(priv->rxbuffersize);
2380 /* if allocation of new skb failed - drop current packet
2381 * and reuse skb */
2382 if (unlikely(!new_skb))
2383 goto done;
2385 pci_unmap_single(priv->pdev,
2386 *((dma_addr_t *)skb->cb),
2387 priv->rxbuffersize,
2388 PCI_DMA_FROMDEVICE);
2390 skb_put(skb, pdesc->Length);
2391 skb_reserve(skb, stats.RxDrvInfoSize +
2392 stats.RxBufShift);
2393 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2394 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2395 if (!is_broadcast_ether_addr(rtllib_hdr->addr1) &&
2396 !is_multicast_ether_addr(rtllib_hdr->addr1)) {
2397 /* unicast packet */
2398 unicast_packet = true;
2400 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
2401 type = WLAN_FC_GET_TYPE(fc);
2402 if (type == RTLLIB_FTYPE_MGMT)
2403 bLedBlinking = false;
2405 if (bLedBlinking)
2406 if (priv->rtllib->LedControlHandler)
2407 priv->rtllib->LedControlHandler(dev,
2408 LED_CTL_RX);
2410 if (stats.bCRC) {
2411 if (type != RTLLIB_FTYPE_MGMT)
2412 priv->stats.rxdatacrcerr++;
2413 else
2414 priv->stats.rxmgmtcrcerr++;
2417 skb_len = skb->len;
2419 if (!rtllib_rx(priv->rtllib, skb, &stats)) {
2420 dev_kfree_skb_any(skb);
2421 } else {
2422 priv->stats.rxok++;
2423 if (unicast_packet)
2424 priv->stats.rxbytesunicast += skb_len;
2427 skb = new_skb;
2428 skb->dev = dev;
2430 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] =
2431 skb;
2432 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev,
2433 skb_tail_pointer_rsl(skb),
2434 priv->rxbuffersize,
2435 PCI_DMA_FROMDEVICE);
2438 done:
2439 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
2440 pdesc->OWN = 1;
2441 pdesc->Length = priv->rxbuffersize;
2442 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1)
2443 pdesc->EOR = 1;
2444 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) %
2445 priv->rxringcount;
2450 void rtl8192_rx_cmd(struct net_device *dev)
2455 void rtl8192_tx_resume(struct net_device *dev)
2457 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2458 struct rtllib_device *ieee = priv->rtllib;
2459 struct sk_buff *skb;
2460 int queue_index;
2462 for (queue_index = BK_QUEUE;
2463 queue_index < MAX_QUEUE_SIZE; queue_index++) {
2464 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) &&
2465 (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) {
2466 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
2467 ieee->softmac_data_hard_start_xmit(skb, dev, 0);
2472 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2474 rtl8192_tx_resume(priv->rtllib->dev);
2477 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2479 rtl8192_rx_normal(priv->rtllib->dev);
2481 if (MAX_RX_QUEUE > 1)
2482 rtl8192_rx_cmd(priv->rtllib->dev);
2484 write_nic_dword(priv->rtllib->dev, INTA_MASK,
2485 read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
2488 /****************************************************************************
2489 ---------------------------- NIC START/CLOSE STUFF---------------------------
2490 *****************************************************************************/
2491 void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
2493 cancel_delayed_work(&priv->watch_dog_wq);
2494 cancel_delayed_work(&priv->update_beacon_wq);
2495 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
2496 cancel_work_sync(&priv->reset_wq);
2497 cancel_work_sync(&priv->qos_activate);
2500 int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
2502 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2503 return -1;
2504 return 0;
2508 int rtl8192_open(struct net_device *dev)
2510 struct r8192_priv *priv = rtllib_priv(dev);
2511 int ret;
2513 down(&priv->wx_sem);
2514 ret = rtl8192_up(dev);
2515 up(&priv->wx_sem);
2516 return ret;
2521 int rtl8192_up(struct net_device *dev)
2523 struct r8192_priv *priv = rtllib_priv(dev);
2525 if (priv->up == 1)
2526 return -1;
2527 return _rtl8192_up(dev, false);
2531 int rtl8192_close(struct net_device *dev)
2533 struct r8192_priv *priv = rtllib_priv(dev);
2534 int ret;
2536 if ((rtllib_act_scanning(priv->rtllib, false)) &&
2537 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) {
2538 rtllib_stop_scan(priv->rtllib);
2541 down(&priv->wx_sem);
2543 ret = rtl8192_down(dev, true);
2545 up(&priv->wx_sem);
2547 return ret;
2551 int rtl8192_down(struct net_device *dev, bool shutdownrf)
2553 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2554 return -1;
2556 return 0;
2559 void rtl8192_commit(struct net_device *dev)
2561 struct r8192_priv *priv = rtllib_priv(dev);
2563 if (priv->up == 0)
2564 return;
2565 rtllib_softmac_stop_protocol(priv->rtllib, 0 , true);
2566 rtl8192_irq_disable(dev);
2567 priv->ops->stop_adapter(dev, true);
2568 _rtl8192_up(dev, false);
2571 void rtl8192_restart(void *data)
2573 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2574 reset_wq);
2575 struct net_device *dev = priv->rtllib->dev;
2577 down(&priv->wx_sem);
2579 rtl8192_commit(dev);
2581 up(&priv->wx_sem);
2584 static void r8192_set_multicast(struct net_device *dev)
2586 struct r8192_priv *priv = rtllib_priv(dev);
2587 short promisc;
2589 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2590 priv->promisc = promisc;
2595 int r8192_set_mac_adr(struct net_device *dev, void *mac)
2597 struct r8192_priv *priv = rtllib_priv(dev);
2598 struct sockaddr *addr = mac;
2600 down(&priv->wx_sem);
2602 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
2604 schedule_work(&priv->reset_wq);
2605 up(&priv->wx_sem);
2607 return 0;
2610 /* based on ipw2200 driver */
2611 int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2613 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2614 struct iwreq *wrq = (struct iwreq *)rq;
2615 int ret = -1;
2616 struct rtllib_device *ieee = priv->rtllib;
2617 u32 key[4];
2618 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2619 u8 zero_addr[6] = {0};
2620 struct iw_point *p = &wrq->u.data;
2621 struct ieee_param *ipw = NULL;
2623 down(&priv->wx_sem);
2625 switch (cmd) {
2626 case RTL_IOCTL_WPA_SUPPLICANT:
2627 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
2628 ret = -EINVAL;
2629 goto out;
2632 ipw = kmalloc(p->length, GFP_KERNEL);
2633 if (ipw == NULL) {
2634 ret = -ENOMEM;
2635 goto out;
2637 if (copy_from_user(ipw, p->pointer, p->length)) {
2638 kfree(ipw);
2639 ret = -EFAULT;
2640 goto out;
2643 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
2644 if (ipw->u.crypt.set_tx) {
2645 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2646 ieee->pairwise_key_type = KEY_TYPE_CCMP;
2647 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2648 ieee->pairwise_key_type = KEY_TYPE_TKIP;
2649 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2650 if (ipw->u.crypt.key_len == 13)
2651 ieee->pairwise_key_type =
2652 KEY_TYPE_WEP104;
2653 else if (ipw->u.crypt.key_len == 5)
2654 ieee->pairwise_key_type =
2655 KEY_TYPE_WEP40;
2656 } else {
2657 ieee->pairwise_key_type = KEY_TYPE_NA;
2660 if (ieee->pairwise_key_type) {
2661 if (memcmp(ieee->ap_mac_addr, zero_addr,
2662 6) == 0)
2663 ieee->iw_mode = IW_MODE_ADHOC;
2664 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2665 EnableHWSecurityConfig8192(dev);
2666 set_swcam(dev, 4, ipw->u.crypt.idx,
2667 ieee->pairwise_key_type,
2668 (u8 *)ieee->ap_mac_addr,
2669 0, key, 0);
2670 setKey(dev, 4, ipw->u.crypt.idx,
2671 ieee->pairwise_key_type,
2672 (u8 *)ieee->ap_mac_addr, 0, key);
2673 if (ieee->iw_mode == IW_MODE_ADHOC) {
2674 set_swcam(dev, ipw->u.crypt.idx,
2675 ipw->u.crypt.idx,
2676 ieee->pairwise_key_type,
2677 (u8 *)ieee->ap_mac_addr,
2678 0, key, 0);
2679 setKey(dev, ipw->u.crypt.idx,
2680 ipw->u.crypt.idx,
2681 ieee->pairwise_key_type,
2682 (u8 *)ieee->ap_mac_addr,
2683 0, key);
2686 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
2687 && ieee->pHTInfo->bCurrentHTSupport) {
2688 write_nic_byte(dev, 0x173, 1);
2691 } else {
2692 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2693 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2694 ieee->group_key_type = KEY_TYPE_CCMP;
2695 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2696 ieee->group_key_type = KEY_TYPE_TKIP;
2697 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2698 if (ipw->u.crypt.key_len == 13)
2699 ieee->group_key_type =
2700 KEY_TYPE_WEP104;
2701 else if (ipw->u.crypt.key_len == 5)
2702 ieee->group_key_type =
2703 KEY_TYPE_WEP40;
2704 } else
2705 ieee->group_key_type = KEY_TYPE_NA;
2707 if (ieee->group_key_type) {
2708 set_swcam(dev, ipw->u.crypt.idx,
2709 ipw->u.crypt.idx,
2710 ieee->group_key_type,
2711 broadcast_addr, 0, key, 0);
2712 setKey(dev, ipw->u.crypt.idx,
2713 ipw->u.crypt.idx,
2714 ieee->group_key_type,
2715 broadcast_addr, 0, key);
2720 ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data,
2722 kfree(ipw);
2723 break;
2724 default:
2725 ret = -EOPNOTSUPP;
2726 break;
2729 out:
2730 up(&priv->wx_sem);
2732 return ret;
2735 void FairBeacon(struct net_device *dev)
2737 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2738 struct rtllib_network *net = &priv->rtllib->current_network;
2739 static u8 i = 100;
2740 static u8 forceturn;
2741 u16 beaconint = net->beacon_interval;
2743 if (priv->rtllib->iw_mode != IW_MODE_ADHOC)
2744 return;
2746 if (priv->bIbssCoordinator) {
2747 i--;
2749 if (forceturn == 2) {
2750 forceturn = 0;
2751 priv->rtllib->SetHwRegHandler(dev,
2752 HW_VAR_BEACON_INTERVAL,
2753 (u8 *)(&beaconint));
2754 i = 100;
2757 if (i <= 94) {
2758 beaconint = beaconint+2;
2759 priv->rtllib->SetHwRegHandler(dev,
2760 HW_VAR_BEACON_INTERVAL,
2761 (u8 *)(&beaconint));
2762 forceturn = 1;
2764 } else {
2765 i++;
2767 if (forceturn == 1) {
2768 forceturn = 0;
2769 priv->rtllib->SetHwRegHandler(dev,
2770 HW_VAR_BEACON_INTERVAL,
2771 (u8 *)(&beaconint));
2772 i = 100;
2775 if (i >= 106) {
2776 beaconint = beaconint-2;
2777 priv->rtllib->SetHwRegHandler(dev,
2778 HW_VAR_BEACON_INTERVAL,
2779 (u8 *)(&beaconint));
2780 forceturn = 2;
2786 irqreturn_type rtl8192_interrupt(int irq, void *netdev, struct pt_regs *regs)
2788 struct net_device *dev = (struct net_device *) netdev;
2789 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2790 unsigned long flags;
2791 u32 inta;
2792 u32 intb;
2793 intb = 0;
2795 if (priv->irq_enabled == 0)
2796 goto done;
2798 spin_lock_irqsave(&priv->irq_th_lock, flags);
2800 priv->ops->interrupt_recognized(dev, &inta, &intb);
2801 priv->stats.shints++;
2803 if (!inta) {
2804 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2805 goto done;
2808 if (inta == 0xffff) {
2809 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2810 goto done;
2813 priv->stats.ints++;
2815 if (!netif_running(dev)) {
2816 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2817 goto done;
2820 if (inta & IMR_TBDOK) {
2821 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2822 priv->stats.txbeaconokint++;
2825 if (inta & IMR_TBDER) {
2826 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2827 priv->stats.txbeaconerr++;
2830 if (inta & IMR_BDOK)
2831 RT_TRACE(COMP_INTR, "beacon interrupt!\n");
2833 if (inta & IMR_MGNTDOK) {
2834 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
2835 priv->stats.txmanageokint++;
2836 rtl8192_tx_isr(dev, MGNT_QUEUE);
2837 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2838 if (priv->rtllib->ack_tx_to_ieee) {
2839 if (rtl8192_is_tx_queue_empty(dev)) {
2840 priv->rtllib->ack_tx_to_ieee = 0;
2841 rtllib_ps_tx_ack(priv->rtllib, 1);
2844 spin_lock_irqsave(&priv->irq_th_lock, flags);
2847 if (inta & IMR_COMDOK) {
2848 priv->stats.txcmdpktokint++;
2849 rtl8192_tx_isr(dev, TXCMD_QUEUE);
2852 if (inta & IMR_HIGHDOK)
2853 rtl8192_tx_isr(dev, HIGH_QUEUE);
2855 if (inta & IMR_ROK) {
2856 priv->stats.rxint++;
2857 priv->InterruptLog.nIMR_ROK++;
2858 tasklet_schedule(&priv->irq_rx_tasklet);
2861 if (inta & IMR_BcnInt) {
2862 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
2863 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
2866 if (inta & IMR_RDU) {
2867 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2868 priv->stats.rxrdu++;
2869 write_nic_dword(dev, INTA_MASK,
2870 read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
2871 tasklet_schedule(&priv->irq_rx_tasklet);
2874 if (inta & IMR_RXFOVW) {
2875 RT_TRACE(COMP_INTR, "rx overflow !\n");
2876 priv->stats.rxoverflow++;
2877 tasklet_schedule(&priv->irq_rx_tasklet);
2880 if (inta & IMR_TXFOVW)
2881 priv->stats.txoverflow++;
2883 if (inta & IMR_BKDOK) {
2884 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
2885 priv->stats.txbkokint++;
2886 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2887 rtl8192_tx_isr(dev, BK_QUEUE);
2890 if (inta & IMR_BEDOK) {
2891 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
2892 priv->stats.txbeokint++;
2893 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2894 rtl8192_tx_isr(dev, BE_QUEUE);
2897 if (inta & IMR_VIDOK) {
2898 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
2899 priv->stats.txviokint++;
2900 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2901 rtl8192_tx_isr(dev, VI_QUEUE);
2904 if (inta & IMR_VODOK) {
2905 priv->stats.txvookint++;
2906 RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
2907 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
2908 rtl8192_tx_isr(dev, VO_QUEUE);
2911 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2913 done:
2915 return IRQ_HANDLED;
2920 /****************************************************************************
2921 ---------------------------- PCI_STUFF---------------------------
2922 *****************************************************************************/
2923 #ifdef HAVE_NET_DEVICE_OPS
2924 static const struct net_device_ops rtl8192_netdev_ops = {
2925 .ndo_open = rtl8192_open,
2926 .ndo_stop = rtl8192_close,
2927 .ndo_tx_timeout = rtl8192_tx_timeout,
2928 .ndo_do_ioctl = rtl8192_ioctl,
2929 .ndo_set_multicast_list = r8192_set_multicast,
2930 .ndo_set_mac_address = r8192_set_mac_adr,
2931 .ndo_validate_addr = eth_validate_addr,
2932 .ndo_change_mtu = eth_change_mtu,
2933 .ndo_start_xmit = rtllib_xmit,
2935 #endif
2937 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
2938 const struct pci_device_id *id)
2940 unsigned long ioaddr = 0;
2941 struct net_device *dev = NULL;
2942 struct r8192_priv *priv = NULL;
2943 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
2944 unsigned long pmem_start, pmem_len, pmem_flags;
2945 int err = 0;
2946 bool bdma64 = false;
2947 u8 revision_id;
2949 RT_TRACE(COMP_INIT, "Configuring chip resources");
2951 if (pci_enable_device(pdev)) {
2952 RT_TRACE(COMP_ERR, "Failed to enable PCI device");
2953 return -EIO;
2956 pci_set_master(pdev);
2958 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2959 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
2960 printk(KERN_INFO "Unable to obtain 32bit DMA for consistent allocations\n");
2961 pci_disable_device(pdev);
2962 return -ENOMEM;
2965 dev = alloc_rtllib(sizeof(struct r8192_priv));
2966 if (!dev)
2967 return -ENOMEM;
2969 if (bdma64)
2970 dev->features |= NETIF_F_HIGHDMA;
2972 pci_set_drvdata(pdev, dev);
2973 SET_NETDEV_DEV(dev, &pdev->dev);
2974 priv = rtllib_priv(dev);
2975 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
2976 priv->pdev = pdev;
2977 priv->rtllib->pdev = pdev;
2978 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) &&
2979 (pdev->subsystem_device == 0x3304))
2980 priv->rtllib->bSupportRemoteWakeUp = 1;
2981 else
2982 priv->rtllib->bSupportRemoteWakeUp = 0;
2984 pmem_start = pci_resource_start(pdev, 1);
2985 pmem_len = pci_resource_len(pdev, 1);
2986 pmem_flags = pci_resource_flags(pdev, 1);
2988 if (!(pmem_flags & IORESOURCE_MEM)) {
2989 RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting");
2990 goto fail;
2993 printk(KERN_INFO "Memory mapped space start: 0x%08lx\n", pmem_start);
2994 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
2995 RT_TRACE(COMP_ERR, "request_mem_region failed!");
2996 goto fail;
3000 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
3001 if (ioaddr == (unsigned long)NULL) {
3002 RT_TRACE(COMP_ERR, "ioremap failed!");
3003 goto fail1;
3006 dev->mem_start = ioaddr;
3007 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
3009 pci_read_config_byte(pdev, 0x08, &revision_id);
3010 /* If the revisionid is 0x10, the device uses rtl8192se. */
3011 if (pdev->device == 0x8192 && revision_id == 0x10)
3012 goto fail1;
3014 priv->ops = ops;
3016 if (rtl8192_pci_findadapter(pdev, dev) == false)
3017 goto fail1;
3019 dev->irq = pdev->irq;
3020 priv->irq = 0;
3022 #ifdef HAVE_NET_DEVICE_OPS
3023 dev->netdev_ops = &rtl8192_netdev_ops;
3024 #else
3025 dev->open = rtl8192_open;
3026 dev->stop = rtl8192_close;
3027 dev->tx_timeout = rtl8192_tx_timeout;
3028 dev->do_ioctl = rtl8192_ioctl;
3029 dev->set_multicast_list = r8192_set_multicast;
3030 dev->set_mac_address = r8192_set_mac_adr;
3031 dev->hard_start_xmit = rtllib_xmit;
3032 #endif
3034 dev->wireless_handlers = (struct iw_handler_def *)
3035 &r8192_wx_handlers_def;
3036 dev->ethtool_ops = &rtl819x_ethtool_ops;
3038 dev->type = ARPHRD_ETHER;
3039 dev->watchdog_timeo = HZ * 3;
3041 if (dev_alloc_name(dev, ifname) < 0) {
3042 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying "
3043 "wlan%%d...\n");
3044 dev_alloc_name(dev, ifname);
3047 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
3048 if (rtl8192_init(dev) != 0) {
3049 RT_TRACE(COMP_ERR, "Initialization failed");
3050 goto fail1;
3053 netif_carrier_off(dev);
3054 netif_stop_queue(dev);
3056 register_netdev(dev);
3057 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name);
3058 err = rtl_debug_module_init(priv, dev->name);
3059 if (err)
3060 RT_TRACE(COMP_DBG, "failed to create debugfs files. Ignoring "
3061 "error: %d\n", err);
3062 rtl8192_proc_init_one(dev);
3064 if (priv->polling_timer_on == 0)
3065 check_rfctrl_gpio_timer((unsigned long)dev);
3067 RT_TRACE(COMP_INIT, "Driver probe completed\n");
3068 return 0;
3070 fail1:
3071 if (dev->mem_start != (unsigned long)NULL) {
3072 iounmap((void *)dev->mem_start);
3073 release_mem_region(pci_resource_start(pdev, 1),
3074 pci_resource_len(pdev, 1));
3077 fail:
3078 if (dev) {
3079 if (priv->irq) {
3080 free_irq(dev->irq, dev);
3081 dev->irq = 0;
3083 free_rtllib(dev);
3086 pci_disable_device(pdev);
3088 DMESG("wlan driver load failed\n");
3089 pci_set_drvdata(pdev, NULL);
3090 return -ENODEV;
3094 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
3096 struct net_device *dev = pci_get_drvdata(pdev);
3097 struct r8192_priv *priv ;
3098 u32 i;
3100 if (dev) {
3101 unregister_netdev(dev);
3103 priv = rtllib_priv(dev);
3105 del_timer_sync(&priv->gpio_polling_timer);
3106 cancel_delayed_work(&priv->gpio_change_rf_wq);
3107 priv->polling_timer_on = 0;
3108 rtl_debug_module_remove(priv);
3109 rtl8192_proc_remove_one(dev);
3110 rtl8192_down(dev, true);
3111 deinit_hal_dm(dev);
3112 if (priv->pFirmware) {
3113 vfree(priv->pFirmware);
3114 priv->pFirmware = NULL;
3116 destroy_workqueue(priv->priv_wq);
3117 rtl8192_free_rx_ring(dev);
3118 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
3119 rtl8192_free_tx_ring(dev, i);
3121 if (priv->irq) {
3122 printk(KERN_INFO "Freeing irq %d\n", dev->irq);
3123 free_irq(dev->irq, dev);
3124 priv->irq = 0;
3126 free_rtllib(dev);
3128 kfree(priv->scan_cmd);
3130 if (dev->mem_start != 0) {
3131 iounmap((void *)dev->mem_start);
3132 release_mem_region(pci_resource_start(pdev, 1),
3133 pci_resource_len(pdev, 1));
3135 } else {
3136 priv = rtllib_priv(dev);
3139 pci_disable_device(pdev);
3140 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
3143 bool NicIFEnableNIC(struct net_device *dev)
3145 bool init_status = true;
3146 struct r8192_priv *priv = rtllib_priv(dev);
3147 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
3148 (&(priv->rtllib->PowerSaveControl));
3150 if (IS_NIC_DOWN(priv)) {
3151 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",
3152 __func__);
3153 priv->bdisable_nic = false;
3154 return RT_STATUS_FAILURE;
3157 RT_TRACE(COMP_PS, "===========>%s()\n", __func__);
3158 priv->bfirst_init = true;
3159 init_status = priv->ops->initialize_adapter(dev);
3160 if (init_status != true) {
3161 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
3162 __func__);
3163 priv->bdisable_nic = false;
3164 return -1;
3166 RT_TRACE(COMP_INIT, "start adapter finished\n");
3167 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
3168 priv->bfirst_init = false;
3170 rtl8192_irq_enable(dev);
3171 priv->bdisable_nic = false;
3172 RT_TRACE(COMP_PS, "<===========%s()\n", __func__);
3173 return init_status;
3175 bool NicIFDisableNIC(struct net_device *dev)
3177 bool status = true;
3178 struct r8192_priv *priv = rtllib_priv(dev);
3179 u8 tmp_state = 0;
3180 RT_TRACE(COMP_PS, "=========>%s()\n", __func__);
3181 priv->bdisable_nic = true;
3182 tmp_state = priv->rtllib->state;
3183 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
3184 priv->rtllib->state = tmp_state;
3185 rtl8192_cancel_deferred_work(priv);
3186 rtl8192_irq_disable(dev);
3188 priv->ops->stop_adapter(dev, false);
3189 RT_TRACE(COMP_PS, "<=========%s()\n", __func__);
3191 return status;
3194 static int __init rtl8192_pci_module_init(void)
3196 int ret;
3197 int error;
3199 ret = rtllib_init();
3200 if (ret) {
3201 printk(KERN_ERR "rtllib_init() failed %d\n", ret);
3202 return ret;
3204 ret = rtllib_crypto_init();
3205 if (ret) {
3206 printk(KERN_ERR "rtllib_crypto_init() failed %d\n", ret);
3207 return ret;
3209 ret = rtllib_crypto_tkip_init();
3210 if (ret) {
3211 printk(KERN_ERR "rtllib_crypto_tkip_init() failed %d\n", ret);
3212 return ret;
3214 ret = rtllib_crypto_ccmp_init();
3215 if (ret) {
3216 printk(KERN_ERR "rtllib_crypto_ccmp_init() failed %d\n", ret);
3217 return ret;
3219 ret = rtllib_crypto_wep_init();
3220 if (ret) {
3221 printk(KERN_ERR "rtllib_crypto_wep_init() failed %d\n", ret);
3222 return ret;
3224 printk(KERN_INFO "\nLinux kernel driver for RTL8192E WLAN cards\n");
3225 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan Driver\n");
3227 error = rtl_create_debugfs_root();
3228 if (error) {
3229 RT_TRACE(COMP_DBG, "Create debugfs root fail: %d\n", error);
3230 goto err_out;
3233 rtl8192_proc_module_init();
3234 if (0 != pci_register_driver(&rtl8192_pci_driver)) {
3235 DMESG("No device found");
3236 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3237 return -ENODEV;
3239 return 0;
3240 err_out:
3241 return error;
3245 static void __exit rtl8192_pci_module_exit(void)
3247 pci_unregister_driver(&rtl8192_pci_driver);
3249 RT_TRACE(COMP_DOWN, "Exiting");
3250 rtl8192_proc_module_remove();
3251 rtl_remove_debugfs_root();
3252 rtllib_crypto_tkip_exit();
3253 rtllib_crypto_ccmp_exit();
3254 rtllib_crypto_wep_exit();
3255 rtllib_crypto_deinit();
3256 rtllib_exit();
3259 void check_rfctrl_gpio_timer(unsigned long data)
3261 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
3263 priv->polling_timer_on = 1;
3265 queue_delayed_work_rsl(priv->priv_wq, &priv->gpio_change_rf_wq, 0);
3267 mod_timer(&priv->gpio_polling_timer, jiffies +
3268 MSECS(RTLLIB_WATCH_DOG_TIME));
3271 /***************************************************************************
3272 ------------------- module init / exit stubs ----------------
3273 ****************************************************************************/
3274 module_init(rtl8192_pci_module_init);
3275 module_exit(rtl8192_pci_module_exit);
3277 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
3278 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
3279 MODULE_VERSION(DRV_VERSION);
3280 MODULE_LICENSE("GPL");
3282 module_param(ifname, charp, S_IRUGO|S_IWUSR);
3283 module_param(hwwep, int, S_IRUGO|S_IWUSR);
3284 module_param(channels, int, S_IRUGO|S_IWUSR);
3286 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
3287 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");
3288 MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");