]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/rtl8192e/rtl8192e/rtl_core.c
rtl8192e: delete local copy of iee80211 reason codes.
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / rtl8192e / rtl8192e / rtl_core.c
CommitLineData
94a79942
LF
1/******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 *
4 * Based on the r8180 driver, which is:
559a4c31 5 * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al.
94a79942
LF
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.
9 *
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.
14 *
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
18 *
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
21 *
22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com>
24******************************************************************************/
94a79942
LF
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
43
1344ee25 44#include <linux/uaccess.h>
94a79942 45#include <linux/pci.h>
09ebd6f2 46#include <linux/vmalloc.h>
acd442db 47#include <linux/ieee80211.h>
94a79942
LF
48#include "rtl_core.h"
49#include "r8192E_phy.h"
50#include "r8192E_phyreg.h"
51#include "r8190P_rtl8256.h"
52#include "r8192E_cmdpkt.h"
53
54#include "rtl_wx.h"
94a79942 55#include "rtl_dm.h"
94a79942 56
94a79942 57#include "rtl_pm.h"
94a79942
LF
58
59int hwwep = 1;
60static int channels = 0x3fff;
49aab5fd 61static char *ifname = "wlan%d";
94a79942
LF
62
63
49aab5fd 64static struct rtl819x_ops rtl819xp_ops = {
1344ee25
LF
65 .nic_type = NIC_8192E,
66 .get_eeprom_size = rtl8192_get_eeprom_size,
94a79942 67 .init_adapter_variable = rtl8192_InitializeVariables,
1344ee25
LF
68 .initialize_adapter = rtl8192_adapter_start,
69 .link_change = rtl8192_link_change,
70 .tx_fill_descriptor = rtl8192_tx_fill_desc,
71 .tx_fill_cmd_descriptor = rtl8192_tx_fill_cmd_desc,
94a79942
LF
72 .rx_query_status_descriptor = rtl8192_rx_query_status_desc,
73 .rx_command_packet_handler = NULL,
1344ee25
LF
74 .stop_adapter = rtl8192_halt_adapter,
75 .update_ratr_table = rtl8192_update_ratr_table,
76 .irq_enable = rtl8192_EnableInterrupt,
77 .irq_disable = rtl8192_DisableInterrupt,
78 .irq_clear = rtl8192_ClearInterrupt,
79 .rx_enable = rtl8192_enable_rx,
80 .tx_enable = rtl8192_enable_tx,
94a79942
LF
81 .interrupt_recognized = rtl8192_interrupt_recognized,
82 .TxCheckStuckHandler = rtl8192_HalTxCheckStuck,
83 .RxCheckStuckHandler = rtl8192_HalRxCheckStuck,
84};
85
83f5789c 86static struct pci_device_id rtl8192_pci_id_tbl[] = {
94a79942
LF
87 {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)},
88 {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)},
89 {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)},
90 {}
91};
92
93MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
94
c506fff1 95static int rtl8192_pci_probe(struct pci_dev *pdev,
1344ee25 96 const struct pci_device_id *id);
1387b461 97static void rtl8192_pci_disconnect(struct pci_dev *pdev);
30224b5e 98static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
94a79942
LF
99
100static struct pci_driver rtl8192_pci_driver = {
1344ee25
LF
101 .name = DRV_NAME, /* Driver name */
102 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
103 .probe = rtl8192_pci_probe, /* probe fn */
c08561c5 104 .remove = rtl8192_pci_disconnect, /* remove fn */
1344ee25
LF
105 .suspend = rtl8192E_suspend, /* PM suspend fn */
106 .resume = rtl8192E_resume, /* PM resume fn */
94a79942
LF
107};
108
109/****************************************************************************
110 -----------------------------IO STUFF-------------------------
111*****************************************************************************/
49aab5fd 112static bool PlatformIOCheckPageLegalAndGetRegMask(u32 u4bPage, u8 *pu1bPageMask)
94a79942
LF
113{
114 bool bReturn = false;
1344ee25 115
94a79942
LF
116 *pu1bPageMask = 0xfe;
117
1344ee25
LF
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;
94a79942 124
1344ee25
LF
125 default:
126 bReturn = false;
127 break;
94a79942
LF
128 }
129
130 return bReturn;
131}
132
1344ee25 133void write_nic_io_byte(struct net_device *dev, int x, u8 y)
94a79942 134{
9f491da9 135 u32 u4bPage = x >> 8;
94a79942
LF
136 u8 u1PageMask = 0;
137 bool bIsLegalPage = false;
138
1344ee25
LF
139 if (u4bPage == 0) {
140 outb(y&0xff, dev->base_addr + x);
141
142 } else {
143 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
144 &u1PageMask);
145 if (bIsLegalPage) {
94a79942
LF
146 u8 u1bPsr = read_nic_io_byte(dev, PSR);
147
1344ee25
LF
148 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
149 (u8)u4bPage));
94a79942
LF
150 write_nic_io_byte(dev, (x & 0xff), y);
151 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
94a79942
LF
152 }
153 }
94a79942
LF
154}
155
1344ee25 156void write_nic_io_word(struct net_device *dev, int x, u16 y)
94a79942 157{
9f491da9 158 u32 u4bPage = x >> 8;
94a79942
LF
159 u8 u1PageMask = 0;
160 bool bIsLegalPage = false;
161
1344ee25
LF
162 if (u4bPage == 0) {
163 outw(y, dev->base_addr + x);
164 } else {
165 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
166 &u1PageMask);
167 if (bIsLegalPage) {
94a79942
LF
168 u8 u1bPsr = read_nic_io_byte(dev, PSR);
169
1344ee25
LF
170 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
171 (u8)u4bPage));
94a79942
LF
172 write_nic_io_word(dev, (x & 0xff), y);
173 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
174
94a79942
LF
175 }
176 }
94a79942
LF
177}
178
1344ee25 179void write_nic_io_dword(struct net_device *dev, int x, u32 y)
94a79942 180{
9f491da9 181 u32 u4bPage = x >> 8;
94a79942
LF
182 u8 u1PageMask = 0;
183 bool bIsLegalPage = false;
184
1344ee25
LF
185 if (u4bPage == 0) {
186 outl(y, dev->base_addr + x);
187 } else {
188 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
189 &u1PageMask);
190 if (bIsLegalPage) {
94a79942
LF
191 u8 u1bPsr = read_nic_io_byte(dev, PSR);
192
1344ee25
LF
193 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
194 (u8)u4bPage));
94a79942
LF
195 write_nic_io_dword(dev, (x & 0xff), y);
196 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
94a79942
LF
197 }
198 }
94a79942 199}
1344ee25 200
94a79942
LF
201u8 read_nic_io_byte(struct net_device *dev, int x)
202{
9f491da9 203 u32 u4bPage = x >> 8;
94a79942
LF
204 u8 u1PageMask = 0;
205 bool bIsLegalPage = false;
206 u8 Data = 0;
207
285b7c00 208 if (u4bPage == 0)
1344ee25 209 return 0xff&inb(dev->base_addr + x);
94a79942 210
285b7c00
MK
211 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
212 &u1PageMask);
213 if (bIsLegalPage) {
214 u8 u1bPsr = read_nic_io_byte(dev, PSR);
215
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));
94a79942
LF
220 }
221
222 return Data;
223}
224
225u16 read_nic_io_word(struct net_device *dev, int x)
226{
9f491da9 227 u32 u4bPage = x >> 8;
94a79942
LF
228 u8 u1PageMask = 0;
229 bool bIsLegalPage = false;
230 u16 Data = 0;
231
285b7c00 232 if (u4bPage == 0)
1344ee25 233 return inw(dev->base_addr + x);
285b7c00
MK
234 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
235 &u1PageMask);
236 if (bIsLegalPage) {
237 u8 u1bPsr = read_nic_io_byte(dev, PSR);
238
239 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
240 (u8)u4bPage));
241 Data = read_nic_io_word(dev, (x & 0xff));
242 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
94a79942
LF
243 }
244
245 return Data;
246}
247
248u32 read_nic_io_dword(struct net_device *dev, int x)
249{
9f491da9 250 u32 u4bPage = x >> 8;
94a79942
LF
251 u8 u1PageMask = 0;
252 bool bIsLegalPage = false;
253 u32 Data = 0;
254
285b7c00 255 if (u4bPage == 0)
1344ee25 256 return inl(dev->base_addr + x);
285b7c00
MK
257 bIsLegalPage = PlatformIOCheckPageLegalAndGetRegMask(u4bPage,
258 &u1PageMask);
259 if (bIsLegalPage) {
260 u8 u1bPsr = read_nic_io_byte(dev, PSR);
261
262 write_nic_io_byte(dev, PSR, ((u1bPsr & u1PageMask) |
263 (u8)u4bPage));
264 Data = read_nic_io_dword(dev, (x & 0xff));
265 write_nic_io_byte(dev, PSR, (u1bPsr & u1PageMask));
94a79942
LF
266 }
267
268 return Data;
269}
270
271u8 read_nic_byte(struct net_device *dev, int x)
272{
49aab5fd 273 return 0xff & readb((u8 __iomem *)dev->mem_start + x);
94a79942
LF
274}
275
276u32 read_nic_dword(struct net_device *dev, int x)
277{
49aab5fd 278 return readl((u8 __iomem *)dev->mem_start + x);
94a79942
LF
279}
280
281u16 read_nic_word(struct net_device *dev, int x)
282{
49aab5fd 283 return readw((u8 __iomem *)dev->mem_start + x);
94a79942
LF
284}
285
1344ee25 286void write_nic_byte(struct net_device *dev, int x, u8 y)
94a79942 287{
49aab5fd 288 writeb(y, (u8 __iomem *)dev->mem_start + x);
94a79942 289
94a79942 290 udelay(20);
94a79942
LF
291}
292
1344ee25 293void write_nic_dword(struct net_device *dev, int x, u32 y)
94a79942 294{
49aab5fd 295 writel(y, (u8 __iomem *)dev->mem_start + x);
94a79942 296
94a79942 297 udelay(20);
94a79942
LF
298}
299
1344ee25 300void write_nic_word(struct net_device *dev, int x, u16 y)
94a79942 301{
49aab5fd 302 writew(y, (u8 __iomem *)dev->mem_start + x);
94a79942 303
94a79942 304 udelay(20);
94a79942
LF
305}
306
307/****************************************************************************
308 -----------------------------GENERAL FUNCTION-------------------------
309*****************************************************************************/
1344ee25
LF
310bool MgntActSet_RF_State(struct net_device *dev,
311 enum rt_rf_power_state StateToSet,
312 RT_RF_CHANGE_SOURCE ChangeSource,
313 bool ProtectOrNot)
94a79942
LF
314{
315 struct r8192_priv *priv = rtllib_priv(dev);
1344ee25 316 struct rtllib_device *ieee = priv->rtllib;
94a79942
LF
317 bool bActionAllowed = false;
318 bool bConnectBySSID = false;
de7c885a 319 enum rt_rf_power_state rtState;
94a79942
LF
320 u16 RFWaitCounter = 0;
321 unsigned long flag;
3a6b70c3 322
0822339b
MK
323 RT_TRACE((COMP_PS | COMP_RF),
324 "===>MgntActSet_RF_State(): StateToSet(%d)\n", StateToSet);
94a79942 325
94a79942 326 ProtectOrNot = false;
94a79942
LF
327
328
1344ee25
LF
329 if (!ProtectOrNot) {
330 while (true) {
331 spin_lock_irqsave(&priv->rf_ps_lock, flag);
332 if (priv->RFChangeInProgress) {
333 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
334 RT_TRACE((COMP_PS | COMP_RF),
0822339b
MK
335 "MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n",
336 StateToSet);
1344ee25
LF
337
338 while (priv->RFChangeInProgress) {
339 RFWaitCounter++;
340 RT_TRACE((COMP_PS | COMP_RF),
0822339b 341 "MgntActSet_RF_State(): Wait 1 ms (%d times)...\n",
1344ee25
LF
342 RFWaitCounter);
343 mdelay(1);
344
345 if (RFWaitCounter > 100) {
0822339b
MK
346 RT_TRACE(COMP_ERR,
347 "MgntActSet_RF_State(): Wait too logn to set RF\n");
1344ee25
LF
348 return false;
349 }
94a79942 350 }
1344ee25
LF
351 } else {
352 priv->RFChangeInProgress = true;
353 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
354 break;
94a79942 355 }
94a79942 356 }
94a79942
LF
357 }
358
359 rtState = priv->rtllib->eRFPowerState;
360
1344ee25 361 switch (StateToSet) {
94a79942 362 case eRfOn:
94a79942
LF
363 priv->rtllib->RfOffReason &= (~ChangeSource);
364
4bb01423 365 if ((ChangeSource == RF_CHANGE_BY_HW) && priv->bHwRadioOff)
94a79942 366 priv->bHwRadioOff = false;
94a79942 367
1344ee25 368 if (!priv->rtllib->RfOffReason) {
94a79942
LF
369 priv->rtllib->RfOffReason = 0;
370 bActionAllowed = true;
371
372
1344ee25
LF
373 if (rtState == eRfOff &&
374 ChangeSource >= RF_CHANGE_BY_HW)
94a79942 375 bConnectBySSID = true;
1344ee25 376 } else {
0822339b
MK
377 RT_TRACE((COMP_PS | COMP_RF),
378 "MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n",
1344ee25
LF
379 priv->rtllib->RfOffReason, ChangeSource);
380 }
94a79942
LF
381
382 break;
383
384 case eRfOff:
385
1344ee25
LF
386 if ((priv->rtllib->iw_mode == IW_MODE_INFRA) ||
387 (priv->rtllib->iw_mode == IW_MODE_ADHOC)) {
388 if ((priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS) ||
389 (ChangeSource > RF_CHANGE_BY_IPS)) {
94a79942
LF
390 if (ieee->state == RTLLIB_LINKED)
391 priv->blinked_ingpio = true;
392 else
393 priv->blinked_ingpio = false;
1344ee25 394 rtllib_MgntDisconnect(priv->rtllib,
acd442db 395 WLAN_REASON_DISASSOC_STA_HAS_LEFT);
94a79942
LF
396 }
397 }
4bb01423 398 if ((ChangeSource == RF_CHANGE_BY_HW) && !priv->bHwRadioOff)
94a79942 399 priv->bHwRadioOff = true;
94a79942
LF
400 priv->rtllib->RfOffReason |= ChangeSource;
401 bActionAllowed = true;
402 break;
403
404 case eRfSleep:
405 priv->rtllib->RfOffReason |= ChangeSource;
406 bActionAllowed = true;
407 break;
408
409 default:
410 break;
411 }
412
1344ee25 413 if (bActionAllowed) {
0822339b
MK
414 RT_TRACE((COMP_PS | COMP_RF),
415 "MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n",
1344ee25 416 StateToSet, priv->rtllib->RfOffReason);
94a79942 417 PHY_SetRFPowerState(dev, StateToSet);
1344ee25 418 if (StateToSet == eRfOn) {
94a79942 419
4bb01423 420 if (bConnectBySSID && priv->blinked_ingpio) {
1344ee25
LF
421 queue_delayed_work_rsl(ieee->wq,
422 &ieee->associate_procedure_wq, 0);
94a79942 423 priv->blinked_ingpio = false;
94a79942
LF
424 }
425 }
426 } else {
0822339b
MK
427 RT_TRACE((COMP_PS | COMP_RF),
428 "MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n",
429 StateToSet, ChangeSource, priv->rtllib->RfOffReason);
94a79942
LF
430 }
431
1344ee25
LF
432 if (!ProtectOrNot) {
433 spin_lock_irqsave(&priv->rf_ps_lock, flag);
434 priv->RFChangeInProgress = false;
435 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
94a79942
LF
436 }
437
35f8673d 438 RT_TRACE((COMP_PS | COMP_RF), "<===MgntActSet_RF_State()\n");
94a79942
LF
439 return bActionAllowed;
440}
441
442
49aab5fd 443static short rtl8192_get_nic_desc_num(struct net_device *dev, int prio)
94a79942 444{
1344ee25
LF
445 struct r8192_priv *priv = rtllib_priv(dev);
446 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
94a79942 447
1344ee25
LF
448 /* For now, we reserved two free descriptor as a safety boundary
449 * between the tail and the head
450 */
451 if ((prio == MGNT_QUEUE) && (skb_queue_len(&ring->queue) > 10))
0822339b
MK
452 RT_TRACE(COMP_DBG,
453 "-----[%d]---------ring->idx=%d queue_len=%d---------\n",
454 prio, ring->idx, skb_queue_len(&ring->queue));
1344ee25 455 return skb_queue_len(&ring->queue);
94a79942
LF
456}
457
49aab5fd 458static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
94a79942 459{
1344ee25
LF
460 struct r8192_priv *priv = rtllib_priv(dev);
461 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
94a79942 462
1344ee25
LF
463 if (ring->entries - skb_queue_len(&ring->queue) >= 2)
464 return 1;
465 return 0;
94a79942
LF
466}
467
468void rtl8192_tx_timeout(struct net_device *dev)
469{
1344ee25 470 struct r8192_priv *priv = rtllib_priv(dev);
94a79942 471
1344ee25 472 schedule_work(&priv->reset_wq);
d69d2054 473 netdev_info(dev, "TXTIMEOUT");
94a79942
LF
474}
475
476void rtl8192_irq_enable(struct net_device *dev)
477{
478 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
3a6b70c3 479
94a79942
LF
480 priv->irq_enabled = 1;
481
482 priv->ops->irq_enable(dev);
483}
484
485void rtl8192_irq_disable(struct net_device *dev)
486{
487 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
488
489 priv->ops->irq_disable(dev);
490
491 priv->irq_enabled = 0;
492}
493
1344ee25 494void rtl8192_set_chan(struct net_device *dev, short ch)
94a79942 495{
1344ee25 496 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
94a79942 497
1344ee25
LF
498 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
499 if (priv->chan_forced)
500 return;
94a79942 501
1344ee25 502 priv->chan = ch;
94a79942 503
1344ee25
LF
504 if (priv->rf_set_chan)
505 priv->rf_set_chan(dev, priv->chan);
94a79942
LF
506}
507
1344ee25 508void rtl8192_update_cap(struct net_device *dev, u16 cap)
94a79942
LF
509{
510 struct r8192_priv *priv = rtllib_priv(dev);
511 struct rtllib_network *net = &priv->rtllib->current_network;
1344ee25
LF
512 bool ShortPreamble;
513
514 if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) {
515 if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT) {
516 ShortPreamble = true;
517 priv->dot11CurrentPreambleMode = PREAMBLE_SHORT;
0822339b
MK
518 RT_TRACE(COMP_DBG,
519 "%s(): WLAN_CAPABILITY_SHORT_PREAMBLE\n",
520 __func__);
1344ee25
LF
521 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
522 (unsigned char *)&ShortPreamble);
94a79942 523 }
1344ee25
LF
524 } else {
525 if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG) {
526 ShortPreamble = false;
527 priv->dot11CurrentPreambleMode = PREAMBLE_LONG;
0822339b
MK
528 RT_TRACE(COMP_DBG,
529 "%s(): WLAN_CAPABILITY_LONG_PREAMBLE\n",
530 __func__);
1344ee25
LF
531 priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE,
532 (unsigned char *)&ShortPreamble);
94a79942
LF
533 }
534 }
535
1344ee25 536 if (net->mode & (IEEE_G|IEEE_N_24G)) {
94a79942
LF
537 u8 slot_time_val;
538 u8 CurSlotTime = priv->slot_time;
539
1344ee25
LF
540 if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
541 (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime)) {
542 if (CurSlotTime != SHORT_SLOT_TIME) {
94a79942 543 slot_time_val = SHORT_SLOT_TIME;
1344ee25
LF
544 priv->rtllib->SetHwRegHandler(dev,
545 HW_VAR_SLOT_TIME, &slot_time_val);
94a79942 546 }
1344ee25
LF
547 } else {
548 if (CurSlotTime != NON_SHORT_SLOT_TIME) {
94a79942 549 slot_time_val = NON_SHORT_SLOT_TIME;
1344ee25
LF
550 priv->rtllib->SetHwRegHandler(dev,
551 HW_VAR_SLOT_TIME, &slot_time_val);
94a79942
LF
552 }
553 }
554 }
555}
556
557static struct rtllib_qos_parameters def_qos_parameters = {
34e987e6
RK
558 {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)},
559 {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)},
1344ee25
LF
560 {2, 2, 2, 2},
561 {0, 0, 0, 0},
562 {0, 0, 0, 0}
94a79942
LF
563};
564
49aab5fd 565static void rtl8192_update_beacon(void *data)
94a79942 566{
1344ee25
LF
567 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
568 update_beacon_wq.work);
94a79942 569 struct net_device *dev = priv->rtllib->dev;
1344ee25
LF
570 struct rtllib_device *ieee = priv->rtllib;
571 struct rtllib_network *net = &ieee->current_network;
94a79942
LF
572
573 if (ieee->pHTInfo->bCurrentHTSupport)
976d5341 574 HT_update_self_and_peer_setting(ieee, net);
1344ee25
LF
575 ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
576 net->bssht.bdRT2RTLongSlotTime;
94a79942
LF
577 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
578 rtl8192_update_cap(dev, net->capability);
579}
580
49aab5fd 581static void rtl8192_qos_activate(void *data)
94a79942 582{
1344ee25
LF
583 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
584 qos_activate);
94a79942 585 struct net_device *dev = priv->rtllib->dev;
1344ee25 586 int i;
94a79942 587
1344ee25
LF
588 mutex_lock(&priv->mutex);
589 if (priv->rtllib->state != RTLLIB_LINKED)
94a79942 590 goto success;
0822339b
MK
591 RT_TRACE(COMP_QOS,
592 "qos active process with associate response received\n");
94a79942 593
fe40a0b3 594 for (i = 0; i < QOS_QUEUE_NUM; i++)
1344ee25 595 priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i));
fe40a0b3 596
94a79942
LF
597
598success:
1344ee25 599 mutex_unlock(&priv->mutex);
94a79942
LF
600}
601
602static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
603 int active_network,
604 struct rtllib_network *network)
605{
606 int ret = 0;
607 u32 size = sizeof(struct rtllib_qos_parameters);
608
1344ee25
LF
609 if (priv->rtllib->state != RTLLIB_LINKED)
610 return ret;
94a79942 611
025b8bbe 612 if (priv->rtllib->iw_mode != IW_MODE_INFRA)
94a79942
LF
613 return ret;
614
615 if (network->flags & NETWORK_HAS_QOS_MASK) {
616 if (active_network &&
617 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
618 network->qos_data.active = network->qos_data.supported;
619
620 if ((network->qos_data.active == 1) && (active_network == 1) &&
621 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
622 (network->qos_data.old_param_count !=
1344ee25 623 network->qos_data.param_count)) {
94a79942
LF
624 network->qos_data.old_param_count =
625 network->qos_data.param_count;
1344ee25 626 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
94a79942 627 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
0822339b
MK
628 RT_TRACE(COMP_QOS,
629 "QoS parameters change call qos_activate\n");
94a79942
LF
630 }
631 } else {
1344ee25 632 memcpy(&priv->rtllib->current_network.qos_data.parameters,
94a79942
LF
633 &def_qos_parameters, size);
634
635 if ((network->qos_data.active == 1) && (active_network == 1)) {
636 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
0822339b
MK
637 RT_TRACE(COMP_QOS,
638 "QoS was disabled call qos_activate\n");
94a79942
LF
639 }
640 network->qos_data.active = 0;
641 network->qos_data.supported = 0;
642 }
643
644 return 0;
645}
646
1344ee25
LF
647static int rtl8192_handle_beacon(struct net_device *dev,
648 struct rtllib_beacon *beacon,
649 struct rtllib_network *network)
94a79942
LF
650{
651 struct r8192_priv *priv = rtllib_priv(dev);
652
1344ee25 653 rtl8192_qos_handle_probe_response(priv, 1, network);
94a79942
LF
654
655 queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
656 return 0;
657
658}
659
660static int rtl8192_qos_association_resp(struct r8192_priv *priv,
1344ee25 661 struct rtllib_network *network)
94a79942 662{
1344ee25
LF
663 unsigned long flags;
664 u32 size = sizeof(struct rtllib_qos_parameters);
665 int set_qos_param = 0;
94a79942 666
1344ee25 667 if ((priv == NULL) || (network == NULL))
5c8b3961 668 return 0;
94a79942 669
1344ee25 670 if (priv->rtllib->state != RTLLIB_LINKED)
5c8b3961 671 return 0;
94a79942 672
025b8bbe 673 if (priv->rtllib->iw_mode != IW_MODE_INFRA)
5c8b3961 674 return 0;
94a79942 675
1344ee25 676 spin_lock_irqsave(&priv->rtllib->lock, flags);
94a79942 677 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
1344ee25
LF
678 memcpy(&priv->rtllib->current_network.qos_data.parameters,
679 &network->qos_data.parameters,
680 sizeof(struct rtllib_qos_parameters));
94a79942 681 priv->rtllib->current_network.qos_data.active = 1;
1344ee25 682 priv->rtllib->wmm_acm = network->qos_data.wmm_acm;
94a79942
LF
683 set_qos_param = 1;
684 priv->rtllib->current_network.qos_data.old_param_count =
1344ee25 685 priv->rtllib->current_network.qos_data.param_count;
94a79942 686 priv->rtllib->current_network.qos_data.param_count =
1344ee25
LF
687 network->qos_data.param_count;
688 } else {
94a79942 689 memcpy(&priv->rtllib->current_network.qos_data.parameters,
1344ee25 690 &def_qos_parameters, size);
94a79942
LF
691 priv->rtllib->current_network.qos_data.active = 0;
692 priv->rtllib->current_network.qos_data.supported = 0;
1344ee25
LF
693 set_qos_param = 1;
694 }
94a79942 695
1344ee25 696 spin_unlock_irqrestore(&priv->rtllib->lock, flags);
94a79942
LF
697
698 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
1344ee25 699 network->flags, priv->rtllib->current_network.qos_data.active);
94a79942
LF
700 if (set_qos_param == 1) {
701 dm_init_edca_turbo(priv->rtllib->dev);
702 queue_work_rsl(priv->priv_wq, &priv->qos_activate);
703 }
5c8b3961 704 return 0;
94a79942
LF
705}
706
707static int rtl8192_handle_assoc_response(struct net_device *dev,
1344ee25
LF
708 struct rtllib_assoc_response_frame *resp,
709 struct rtllib_network *network)
94a79942 710{
1344ee25 711 struct r8192_priv *priv = rtllib_priv(dev);
3a6b70c3 712
1344ee25
LF
713 rtl8192_qos_association_resp(priv, network);
714 return 0;
94a79942
LF
715}
716
49aab5fd 717static void rtl8192_prepare_beacon(struct r8192_priv *priv)
94a79942
LF
718{
719 struct net_device *dev = priv->rtllib->dev;
720 struct sk_buff *pskb = NULL, *pnewskb = NULL;
3b83db43 721 struct cb_desc *tcb_desc = NULL;
94a79942 722 struct rtl8192_tx_ring *ring = NULL;
bc27e89b 723 struct tx_desc *pdesc = NULL;
94a79942
LF
724
725 ring = &priv->tx_ring[BEACON_QUEUE];
726 pskb = __skb_dequeue(&ring->queue);
085b5018 727 kfree_skb(pskb);
94a79942
LF
728
729 pnewskb = rtllib_get_beacon(priv->rtllib);
730 if (!pnewskb)
731 return;
732
3b83db43 733 tcb_desc = (struct cb_desc *)(pnewskb->cb + 8);
94a79942
LF
734 tcb_desc->queue_index = BEACON_QUEUE;
735 tcb_desc->data_rate = 2;
736 tcb_desc->RATRIndex = 7;
737 tcb_desc->bTxDisableRateFallBack = 1;
738 tcb_desc->bTxUseDriverAssingedRate = 1;
739 skb_push(pnewskb, priv->rtllib->tx_headroom);
740
741 pdesc = &ring->desc[0];
742 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb);
743 __skb_queue_tail(&ring->queue, pnewskb);
744 pdesc->OWN = 1;
94a79942
LF
745}
746
49aab5fd 747static void rtl8192_stop_beacon(struct net_device *dev)
94a79942
LF
748{
749}
750
1344ee25
LF
751void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
752{
753 struct r8192_priv *priv = rtllib_priv(dev);
754 struct rtllib_network *net;
755 u8 i = 0, basic_rate = 0;
3a6b70c3 756
1344ee25
LF
757 net = &priv->rtllib->current_network;
758
759 for (i = 0; i < net->rates_len; i++) {
760 basic_rate = net->rates[i] & 0x7f;
761 switch (basic_rate) {
762 case MGN_1M:
763 *rate_config |= RRSR_1M;
764 break;
765 case MGN_2M:
766 *rate_config |= RRSR_2M;
767 break;
768 case MGN_5_5M:
769 *rate_config |= RRSR_5_5M;
770 break;
771 case MGN_11M:
772 *rate_config |= RRSR_11M;
773 break;
774 case MGN_6M:
775 *rate_config |= RRSR_6M;
776 break;
777 case MGN_9M:
778 *rate_config |= RRSR_9M;
779 break;
780 case MGN_12M:
781 *rate_config |= RRSR_12M;
782 break;
783 case MGN_18M:
784 *rate_config |= RRSR_18M;
785 break;
786 case MGN_24M:
787 *rate_config |= RRSR_24M;
788 break;
789 case MGN_36M:
790 *rate_config |= RRSR_36M;
791 break;
792 case MGN_48M:
793 *rate_config |= RRSR_48M;
794 break;
795 case MGN_54M:
796 *rate_config |= RRSR_54M;
797 break;
798 }
799 }
800
801 for (i = 0; i < net->rates_ex_len; i++) {
802 basic_rate = net->rates_ex[i] & 0x7f;
803 switch (basic_rate) {
804 case MGN_1M:
805 *rate_config |= RRSR_1M;
806 break;
807 case MGN_2M:
808 *rate_config |= RRSR_2M;
809 break;
810 case MGN_5_5M:
811 *rate_config |= RRSR_5_5M;
812 break;
813 case MGN_11M:
814 *rate_config |= RRSR_11M;
815 break;
816 case MGN_6M:
817 *rate_config |= RRSR_6M;
818 break;
819 case MGN_9M:
820 *rate_config |= RRSR_9M;
821 break;
822 case MGN_12M:
823 *rate_config |= RRSR_12M;
824 break;
825 case MGN_18M:
826 *rate_config |= RRSR_18M;
827 break;
828 case MGN_24M:
829 *rate_config |= RRSR_24M;
830 break;
831 case MGN_36M:
832 *rate_config |= RRSR_36M;
833 break;
834 case MGN_48M:
835 *rate_config |= RRSR_48M;
836 break;
837 case MGN_54M:
838 *rate_config |= RRSR_54M;
839 break;
840 }
841 }
842}
843
49aab5fd 844static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
1344ee25
LF
845{
846 struct rtllib_device *ieee = priv->rtllib;
3a6b70c3 847
1344ee25
LF
848 if (ieee->mode == WIRELESS_MODE_N_24G ||
849 ieee->mode == WIRELESS_MODE_N_5G) {
850 memcpy(ieee->Regdot11HTOperationalRateSet,
851 ieee->RegHTSuppRateSet, 16);
852 memcpy(ieee->Regdot11TxHTOperationalRateSet,
853 ieee->RegHTSuppRateSet, 16);
94a79942 854
94a79942
LF
855 } else {
856 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
857 }
94a79942
LF
858}
859
49aab5fd 860static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
94a79942
LF
861{
862 struct r8192_priv *priv = rtllib_priv(dev);
863 u8 ret = 0;
864
865 switch (priv->rf_chip) {
866 case RF_8225:
867 case RF_8256:
868 case RF_6052:
869 case RF_PSEUDO_11N:
870 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B);
871 break;
872 case RF_8258:
873 ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G);
874 break;
875 default:
876 ret = WIRELESS_MODE_B;
877 break;
878 }
879 return ret;
880}
881
1344ee25 882void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
94a79942
LF
883{
884 struct r8192_priv *priv = rtllib_priv(dev);
885 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
886
1344ee25
LF
887 if ((wireless_mode == WIRELESS_MODE_AUTO) ||
888 ((wireless_mode & bSupportMode) == 0)) {
94a79942
LF
889 if (bSupportMode & WIRELESS_MODE_N_24G) {
890 wireless_mode = WIRELESS_MODE_N_24G;
891 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
892 wireless_mode = WIRELESS_MODE_N_5G;
893 } else if ((bSupportMode & WIRELESS_MODE_A)) {
894 wireless_mode = WIRELESS_MODE_A;
895 } else if ((bSupportMode & WIRELESS_MODE_G)) {
896 wireless_mode = WIRELESS_MODE_G;
897 } else if ((bSupportMode & WIRELESS_MODE_B)) {
898 wireless_mode = WIRELESS_MODE_B;
899 } else {
0822339b
MK
900 RT_TRACE(COMP_ERR,
901 "%s(), No valid wireless mode supported (%x)!!!\n",
902 __func__, bSupportMode);
94a79942
LF
903 wireless_mode = WIRELESS_MODE_B;
904 }
905 }
906
1344ee25
LF
907 if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) ==
908 (WIRELESS_MODE_G | WIRELESS_MODE_B))
94a79942
LF
909 wireless_mode = WIRELESS_MODE_G;
910
911 priv->rtllib->mode = wireless_mode;
912
1344ee25
LF
913 ActUpdateChannelAccessSetting(dev, wireless_mode,
914 &priv->ChannelAccessSetting);
94a79942 915
1344ee25
LF
916 if ((wireless_mode == WIRELESS_MODE_N_24G) ||
917 (wireless_mode == WIRELESS_MODE_N_5G)) {
94a79942 918 priv->rtllib->pHTInfo->bEnableHT = 1;
1344ee25
LF
919 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n",
920 __func__, wireless_mode);
921 } else {
94a79942 922 priv->rtllib->pHTInfo->bEnableHT = 0;
1344ee25
LF
923 RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n",
924 __func__, wireless_mode);
925 }
94a79942
LF
926
927 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
928 rtl8192_refresh_supportrate(priv);
929}
930
49aab5fd 931static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
94a79942
LF
932{
933 struct r8192_priv *priv = rtllib_priv(dev);
1344ee25
LF
934 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
935 (&(priv->rtllib->PowerSaveControl));
94a79942 936 bool init_status = true;
3a6b70c3 937
94a79942
LF
938 priv->bDriverIsGoingToUnload = false;
939 priv->bdisable_nic = false;
940
1344ee25
LF
941 priv->up = 1;
942 priv->rtllib->ieee_up = 1;
94a79942
LF
943
944 priv->up_first_time = 0;
945 RT_TRACE(COMP_INIT, "Bringing up iface");
946 priv->bfirst_init = true;
947 init_status = priv->ops->initialize_adapter(dev);
4bb01423 948 if (!init_status) {
1344ee25
LF
949 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
950 __func__);
94a79942
LF
951 priv->bfirst_init = false;
952 return -1;
953 }
954
955 RT_TRACE(COMP_INIT, "start adapter finished\n");
956 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
957 priv->bfirst_init = false;
94a79942 958
1344ee25 959 if (priv->polling_timer_on == 0)
94a79942 960 check_rfctrl_gpio_timer((unsigned long)dev);
94a79942
LF
961
962 if (priv->rtllib->state != RTLLIB_LINKED)
1344ee25 963 rtllib_softmac_start_protocol(priv->rtllib, 0);
94a79942 964 rtllib_reset_queue(priv->rtllib);
94a79942 965 watch_dog_timer_callback((unsigned long) dev);
94a79942 966
94a79942
LF
967 if (!netif_queue_stopped(dev))
968 netif_start_queue(dev);
969 else
970 netif_wake_queue(dev);
971
972 return 0;
973}
974
49aab5fd 975static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
94a79942
LF
976{
977 struct r8192_priv *priv = rtllib_priv(dev);
978 unsigned long flags = 0;
979 u8 RFInProgressTimeOut = 0;
980
1344ee25
LF
981 if (priv->up == 0)
982 return -1;
94a79942
LF
983
984 if (priv->rtllib->rtllib_ips_leave != NULL)
985 priv->rtllib->rtllib_ips_leave(dev);
986
987 if (priv->rtllib->state == RTLLIB_LINKED)
988 LeisurePSLeave(dev);
989
990 priv->bDriverIsGoingToUnload = true;
1344ee25 991 priv->up = 0;
94a79942 992 priv->rtllib->ieee_up = 0;
014e4c27 993 priv->bfirst_after_down = true;
94a79942
LF
994 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
995 if (!netif_queue_stopped(dev))
996 netif_stop_queue(dev);
997
998 priv->rtllib->wpa_ie_len = 0;
1344ee25 999 kfree(priv->rtllib->wpa_ie);
94a79942
LF
1000 priv->rtllib->wpa_ie = NULL;
1001 CamResetAllEntry(dev);
1344ee25 1002 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
94a79942
LF
1003 rtl8192_irq_disable(dev);
1004
1005 del_timer_sync(&priv->watch_dog_timer);
1006 rtl8192_cancel_deferred_work(priv);
94a79942 1007 cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
94a79942
LF
1008
1009 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
1344ee25
LF
1010 spin_lock_irqsave(&priv->rf_ps_lock, flags);
1011 while (priv->RFChangeInProgress) {
1012 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
1013 if (RFInProgressTimeOut > 100) {
1014 spin_lock_irqsave(&priv->rf_ps_lock, flags);
94a79942
LF
1015 break;
1016 }
0822339b
MK
1017 RT_TRACE(COMP_DBG,
1018 "===>%s():RF is in progress, need to wait until rf change is done.\n",
1019 __func__);
94a79942 1020 mdelay(1);
1344ee25
LF
1021 RFInProgressTimeOut++;
1022 spin_lock_irqsave(&priv->rf_ps_lock, flags);
94a79942
LF
1023 }
1024 priv->RFChangeInProgress = true;
1344ee25 1025 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
94a79942 1026 priv->ops->stop_adapter(dev, false);
1344ee25 1027 spin_lock_irqsave(&priv->rf_ps_lock, flags);
94a79942 1028 priv->RFChangeInProgress = false;
1344ee25 1029 spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
94a79942 1030 udelay(100);
1344ee25
LF
1031 memset(&priv->rtllib->current_network, 0,
1032 offsetof(struct rtllib_network, list));
94a79942
LF
1033 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
1034
1035 return 0;
1036}
1037
1344ee25 1038static void rtl8192_init_priv_handler(struct net_device *dev)
94a79942
LF
1039{
1040 struct r8192_priv *priv = rtllib_priv(dev);
1041
1042 priv->rtllib->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
1344ee25
LF
1043 priv->rtllib->set_chan = rtl8192_set_chan;
1044 priv->rtllib->link_change = priv->ops->link_change;
94a79942
LF
1045 priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
1046 priv->rtllib->data_hard_stop = rtl8192_data_hard_stop;
1047 priv->rtllib->data_hard_resume = rtl8192_data_hard_resume;
1048 priv->rtllib->check_nic_enough_desc = rtl8192_check_nic_enough_desc;
1049 priv->rtllib->get_nic_desc_num = rtl8192_get_nic_desc_num;
1050 priv->rtllib->handle_assoc_response = rtl8192_handle_assoc_response;
1051 priv->rtllib->handle_beacon = rtl8192_handle_beacon;
1052 priv->rtllib->SetWirelessMode = rtl8192_SetWirelessMode;
1053 priv->rtllib->LeisurePSLeave = LeisurePSLeave;
1054 priv->rtllib->SetBWModeHandler = rtl8192_SetBWMode;
1055 priv->rf_set_chan = rtl8192_phy_SwChnl;
1056
94a79942
LF
1057 priv->rtllib->start_send_beacons = rtl8192e_start_beacon;
1058 priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
94a79942
LF
1059
1060 priv->rtllib->sta_wake_up = rtl8192_hw_wakeup;
1061 priv->rtllib->enter_sleep_state = rtl8192_hw_to_sleep;
1062 priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
1063
1064 priv->rtllib->GetNmodeSupportBySecCfg = rtl8192_GetNmodeSupportBySecCfg;
1344ee25
LF
1065 priv->rtllib->GetHalfNmodeSupportByAPsHandler =
1066 rtl8192_GetHalfNmodeSupportByAPs;
94a79942
LF
1067
1068 priv->rtllib->SetHwRegHandler = rtl8192e_SetHwReg;
1069 priv->rtllib->AllowAllDestAddrHandler = rtl8192_AllowAllDestAddr;
1070 priv->rtllib->SetFwCmdHandler = NULL;
1071 priv->rtllib->InitialGainHandler = InitialGain819xPci;
1072 priv->rtllib->rtllib_ips_leave_wq = rtllib_ips_leave_wq;
1073 priv->rtllib->rtllib_ips_leave = rtllib_ips_leave;
1074
1075 priv->rtllib->LedControlHandler = NULL;
1076 priv->rtllib->UpdateBeaconInterruptHandler = NULL;
1077
1078 priv->rtllib->ScanOperationBackupHandler = PHY_ScanOperationBackup8192;
1079
94a79942 1080 priv->rtllib->rtllib_rfkill_poll = NULL;
94a79942
LF
1081}
1082
1344ee25 1083static void rtl8192_init_priv_constant(struct net_device *dev)
94a79942 1084{
94a79942 1085 struct r8192_priv *priv = rtllib_priv(dev);
1344ee25
LF
1086 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1087 &(priv->rtllib->PowerSaveControl);
94a79942 1088
94a79942 1089 pPSC->RegMaxLPSAwakeIntvl = 5;
94a79942 1090
94a79942
LF
1091 priv->RegPciASPM = 2;
1092
1093 priv->RegDevicePciASPMSetting = 0x03;
1094
1095 priv->RegHostPciASPMSetting = 0x02;
1096
1097 priv->RegHwSwRfOffD3 = 2;
1098
1099 priv->RegSupportPciASPM = 2;
94a79942
LF
1100}
1101
1102
1344ee25 1103static void rtl8192_init_priv_variable(struct net_device *dev)
94a79942
LF
1104{
1105 struct r8192_priv *priv = rtllib_priv(dev);
1106 u8 i;
1107
1108 priv->AcmMethod = eAcmWay2_SW;
1109 priv->dot11CurrentPreambleMode = PREAMBLE_AUTO;
1110 priv->rtllib->hwscan_sem_up = 1;
1111 priv->rtllib->status = 0;
1112 priv->H2CTxCmdSeq = 0;
014e4c27
VM
1113 priv->bDisableFrameBursting = false;
1114 priv->bDMInitialGainEnable = true;
94a79942
LF
1115 priv->polling_timer_on = 0;
1116 priv->up_first_time = 1;
1117 priv->blinked_ingpio = false;
1118 priv->bDriverIsGoingToUnload = false;
1119 priv->being_init_adapter = false;
1120 priv->initialized_at_probe = false;
1121 priv->sw_radio_on = true;
1122 priv->bdisable_nic = false;
1123 priv->bfirst_init = false;
1124 priv->txringcount = 64;
1125 priv->rxbuffersize = 9100;
1126 priv->rxringcount = MAX_RX_COUNT;
1344ee25 1127 priv->irq_enabled = 0;
94a79942
LF
1128 priv->chan = 1;
1129 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
1130 priv->RegChannelPlan = 0xf;
1131 priv->nrxAMPDU_size = 0;
1132 priv->nrxAMPDU_aggr_num = 0;
1133 priv->last_rxdesc_tsf_high = 0;
1134 priv->last_rxdesc_tsf_low = 0;
1135 priv->rtllib->mode = WIRELESS_MODE_AUTO;
1136 priv->rtllib->iw_mode = IW_MODE_INFRA;
1137 priv->rtllib->bNetPromiscuousMode = false;
1138 priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false;
1344ee25
LF
1139 priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
1140 false;
1141 priv->rtllib->ieee_up = 0;
94a79942
LF
1142 priv->retry_rts = DEFAULT_RETRY_RTS;
1143 priv->retry_data = DEFAULT_RETRY_DATA;
1144 priv->rtllib->rts = DEFAULT_RTS_THRESHOLD;
1145 priv->rtllib->rate = 110;
1146 priv->rtllib->short_slot = 1;
1344ee25 1147 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
94a79942
LF
1148 priv->bcck_in_ch14 = false;
1149 priv->bfsync_processing = false;
1150 priv->CCKPresentAttentuation = 0;
1151 priv->rfa_txpowertrackingindex = 0;
1152 priv->rfc_txpowertrackingindex = 0;
1153 priv->CckPwEnl = 6;
1154 priv->ScanDelay = 50;
1155 priv->ResetProgress = RESET_TYPE_NORESET;
014e4c27 1156 priv->bForcedSilentReset = false;
94a79942
LF
1157 priv->bDisableNormalResetCheck = false;
1158 priv->force_reset = false;
1344ee25 1159 memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32);
94a79942 1160
1344ee25 1161 memset(&priv->InterruptLog, 0, sizeof(struct log_int_8190));
94a79942 1162 priv->RxCounter = 0;
1344ee25 1163 priv->rtllib->wx_set_enc = 0;
94a79942 1164 priv->bHwRadioOff = false;
014e4c27 1165 priv->RegRfOff = false;
94a79942
LF
1166 priv->isRFOff = false;
1167 priv->bInPowerSaveMode = false;
1168 priv->rtllib->RfOffReason = 0;
1169 priv->RFChangeInProgress = false;
1170 priv->bHwRfOffAction = 0;
1171 priv->SetRFPowerStateInProgress = false;
1172 priv->rtllib->PowerSaveControl.bInactivePs = true;
1173 priv->rtllib->PowerSaveControl.bIPSModeBackup = false;
1174 priv->rtllib->PowerSaveControl.bLeisurePs = true;
1175 priv->rtllib->PowerSaveControl.bFwCtrlLPS = false;
1176 priv->rtllib->LPSDelayCnt = 0;
1177 priv->rtllib->sta_sleep = LPS_IS_WAKE;
1178 priv->rtllib->eRFPowerState = eRfOn;
1179
1180 priv->txpower_checkcnt = 0;
1344ee25 1181 priv->thermal_readback_index = 0;
94a79942
LF
1182 priv->txpower_tracking_callback_cnt = 0;
1183 priv->ccktxpower_adjustcnt_ch14 = 0;
1184 priv->ccktxpower_adjustcnt_not_ch14 = 0;
1185
94a79942
LF
1186 priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
1187 priv->rtllib->iw_mode = IW_MODE_INFRA;
1188 priv->rtllib->active_scan = 1;
1189 priv->rtllib->be_scan_inprogress = false;
1344ee25
LF
1190 priv->rtllib->modulation = RTLLIB_CCK_MODULATION |
1191 RTLLIB_OFDM_MODULATION;
94a79942
LF
1192 priv->rtllib->host_encrypt = 1;
1193 priv->rtllib->host_decrypt = 1;
1194
1195 priv->rtllib->dot11PowerSaveMode = eActive;
1196 priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD;
1197 priv->rtllib->MaxMssDensity = 0;
1198 priv->rtllib->MinSpaceCfg = 0;
1199
1200 priv->card_type = PCI;
1201
1202 priv->AcmControl = 0;
49aab5fd
LF
1203 priv->pFirmware = vzalloc(sizeof(struct rt_firmware));
1204 if (!priv->pFirmware)
d69d2054
MK
1205 netdev_err(dev,
1206 "rtl8192e: Unable to allocate space for firmware\n");
94a79942 1207
1344ee25 1208 skb_queue_head_init(&priv->rx_queue);
94a79942
LF
1209 skb_queue_head_init(&priv->skb_queue);
1210
1344ee25
LF
1211 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1212 skb_queue_head_init(&priv->rtllib->skb_waitQ[i]);
1213 for (i = 0; i < MAX_QUEUE_SIZE; i++)
1214 skb_queue_head_init(&priv->rtllib->skb_aggQ[i]);
94a79942
LF
1215}
1216
1344ee25 1217static void rtl8192_init_priv_lock(struct r8192_priv *priv)
94a79942
LF
1218{
1219 spin_lock_init(&priv->fw_scan_lock);
1220 spin_lock_init(&priv->tx_lock);
1221 spin_lock_init(&priv->irq_lock);
1222 spin_lock_init(&priv->irq_th_lock);
1223 spin_lock_init(&priv->rf_ps_lock);
1224 spin_lock_init(&priv->ps_lock);
1225 spin_lock_init(&priv->rf_lock);
1226 spin_lock_init(&priv->rt_h2c_lock);
1344ee25
LF
1227 sema_init(&priv->wx_sem, 1);
1228 sema_init(&priv->rf_sem, 1);
94a79942 1229 mutex_init(&priv->mutex);
94a79942
LF
1230}
1231
1344ee25 1232static void rtl8192_init_priv_task(struct net_device *dev)
94a79942
LF
1233{
1234 struct r8192_priv *priv = rtllib_priv(dev);
1235
94a79942 1236 priv->priv_wq = create_workqueue(DRV_NAME);
1344ee25
LF
1237 INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
1238 INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)IPSLeave_wq, dev);
1239 INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
1240 (void *)rtl819x_watchdog_wqcallback, dev);
1241 INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
1242 (void *)dm_txpower_trackingcallback, dev);
1243 INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
1244 (void *)dm_rf_pathcheck_workitemcallback, dev);
1245 INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
1246 (void *)rtl8192_update_beacon, dev);
1247 INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
1248 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
1249 (void *) rtl8192_hw_wakeup_wq, dev);
1250 INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
1251 (void *) rtl8192_hw_sleep_wq, dev);
94a79942 1252 tasklet_init(&priv->irq_rx_tasklet,
1344ee25
LF
1253 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
1254 (unsigned long)priv);
94a79942 1255 tasklet_init(&priv->irq_tx_tasklet,
1344ee25
LF
1256 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
1257 (unsigned long)priv);
1258 tasklet_init(&priv->irq_prepare_beacon_tasklet,
1259 (void(*)(unsigned long))rtl8192_prepare_beacon,
1260 (unsigned long)priv);
94a79942
LF
1261}
1262
49aab5fd 1263static short rtl8192_get_channel_map(struct net_device *dev)
94a79942
LF
1264{
1265 int i;
1266
94a79942 1267 struct r8192_priv *priv = rtllib_priv(dev);
3a6b70c3 1268
94a79942
LF
1269 if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256)
1270 && (priv->rf_chip != RF_6052)) {
0822339b
MK
1271 RT_TRACE(COMP_ERR,
1272 "%s: unknown rf chip, can't set channel map\n",
1273 __func__);
94a79942
LF
1274 return -1;
1275 }
1276
8f019bfe 1277 if (priv->ChannelPlan >= COUNTRY_CODE_MAX) {
d69d2054
MK
1278 netdev_info(dev,
1279 "rtl819x_init:Error channel plan! Set to default.\n");
1344ee25 1280 priv->ChannelPlan = COUNTRY_CODE_FCC;
94a79942 1281 }
1344ee25 1282 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
976d5341 1283 dot11d_init(priv->rtllib);
94a79942 1284 Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib);
1344ee25 1285 for (i = 1; i <= 11; i++)
94a79942 1286 (priv->rtllib->active_channel_map)[i] = 1;
94a79942
LF
1287 (priv->rtllib->active_channel_map)[12] = 2;
1288 (priv->rtllib->active_channel_map)[13] = 2;
1289
1290 return 0;
1291}
1292
49aab5fd 1293static short rtl8192_init(struct net_device *dev)
94a79942
LF
1294{
1295 struct r8192_priv *priv = rtllib_priv(dev);
1296
1344ee25 1297 memset(&(priv->stats), 0, sizeof(struct rt_stats));
94a79942 1298
94a79942
LF
1299 rtl8192_init_priv_handler(dev);
1300 rtl8192_init_priv_constant(dev);
1301 rtl8192_init_priv_variable(dev);
1302 rtl8192_init_priv_lock(priv);
1303 rtl8192_init_priv_task(dev);
1304 priv->ops->get_eeprom_size(dev);
1305 priv->ops->init_adapter_variable(dev);
1306 rtl8192_get_channel_map(dev);
1307
94a79942
LF
1308 init_hal_dm(dev);
1309
94a79942
LF
1310 init_timer(&priv->watch_dog_timer);
1311 setup_timer(&priv->watch_dog_timer,
1312 watch_dog_timer_callback,
1313 (unsigned long) dev);
1314
1315 init_timer(&priv->gpio_polling_timer);
1316 setup_timer(&priv->gpio_polling_timer,
1317 check_rfctrl_gpio_timer,
1318 (unsigned long)dev);
1319
1320 rtl8192_irq_disable(dev);
30224b5e 1321 if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED,
1344ee25 1322 dev->name, dev)) {
d69d2054 1323 netdev_err(dev, "Error allocating IRQ %d", dev->irq);
94a79942 1324 return -1;
94a79942
LF
1325 }
1326
285b7c00
MK
1327 priv->irq = dev->irq;
1328 RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq);
1329
94a79942 1330 if (rtl8192_pci_initdescring(dev) != 0) {
d69d2054 1331 netdev_err(dev, "Endopoints initialization failed");
35f8673d 1332 free_irq(dev->irq, dev);
94a79942
LF
1333 return -1;
1334 }
1335
1336 return 0;
1337}
1338
94a79942 1339/***************************************************************************
1344ee25 1340 -------------------------------WATCHDOG STUFF---------------------------
94a79942
LF
1341***************************************************************************/
1342short rtl8192_is_tx_queue_empty(struct net_device *dev)
1343{
1344ee25 1344 int i = 0;
94a79942 1345 struct r8192_priv *priv = rtllib_priv(dev);
3a6b70c3 1346
1344ee25
LF
1347 for (i = 0; i <= MGNT_QUEUE; i++) {
1348 if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE))
94a79942 1349 continue;
1344ee25 1350 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) {
d69d2054 1351 netdev_info(dev, "===>tx queue is not empty:%d, %d\n",
1344ee25 1352 i, skb_queue_len(&(&priv->tx_ring[i])->queue));
94a79942
LF
1353 return 0;
1354 }
1355 }
1356 return 1;
1357}
1358
49aab5fd 1359static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
94a79942
LF
1360{
1361 struct r8192_priv *priv = rtllib_priv(dev);
1344ee25
LF
1362 u8 QueueID;
1363 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1364 bool bCheckFwTxCnt = false;
94a79942 1365 struct rtl8192_tx_ring *ring = NULL;
1344ee25
LF
1366 struct sk_buff *skb = NULL;
1367 struct cb_desc *tcb_desc = NULL;
94a79942
LF
1368 unsigned long flags = 0;
1369
1344ee25
LF
1370 switch (priv->rtllib->ps) {
1371 case RTLLIB_PS_DISABLED:
1372 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
1373 break;
1374 case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
1375 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1376 break;
1377 default:
1378 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
1379 break;
94a79942 1380 }
1344ee25
LF
1381 spin_lock_irqsave(&priv->irq_th_lock, flags);
1382 for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) {
94a79942
LF
1383 if (QueueID == TXCMD_QUEUE)
1384 continue;
1385
1386 if (QueueID == BEACON_QUEUE)
1387 continue;
1388
1389 ring = &priv->tx_ring[QueueID];
1390
1344ee25 1391 if (skb_queue_len(&ring->queue) == 0) {
94a79942 1392 continue;
1344ee25 1393 } else {
94a79942 1394 skb = (&ring->queue)->next;
1344ee25
LF
1395 tcb_desc = (struct cb_desc *)(skb->cb +
1396 MAX_DEV_ADDR_SIZE);
94a79942
LF
1397 tcb_desc->nStuckCount++;
1398 bCheckFwTxCnt = true;
1399 if (tcb_desc->nStuckCount > 1)
d69d2054
MK
1400 netdev_info(dev,
1401 "%s: QueueID=%d tcb_desc->nStuckCount=%d\n",
1402 __func__, QueueID,
1403 tcb_desc->nStuckCount);
94a79942
LF
1404 }
1405 }
1344ee25 1406 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
1407
1408 if (bCheckFwTxCnt) {
1344ee25 1409 if (priv->ops->TxCheckStuckHandler(dev)) {
0822339b
MK
1410 RT_TRACE(COMP_RESET,
1411 "TxCheckStuck(): Fw indicates no Tx condition!\n");
94a79942
LF
1412 return RESET_TYPE_SILENT;
1413 }
1414 }
1415
1416 return RESET_TYPE_NORESET;
1417}
1418
49aab5fd 1419static enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
94a79942
LF
1420{
1421 struct r8192_priv *priv = rtllib_priv(dev);
1422
1344ee25 1423 if (priv->ops->RxCheckStuckHandler(dev)) {
94a79942
LF
1424 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
1425 return RESET_TYPE_SILENT;
1426 }
1427
1428 return RESET_TYPE_NORESET;
1429}
1430
49aab5fd 1431static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
94a79942
LF
1432{
1433 struct r8192_priv *priv = rtllib_priv(dev);
ab0d7cca
LF
1434 enum reset_type TxResetType = RESET_TYPE_NORESET;
1435 enum reset_type RxResetType = RESET_TYPE_NORESET;
de7c885a 1436 enum rt_rf_power_state rfState;
94a79942
LF
1437
1438 rfState = priv->rtllib->eRFPowerState;
1439
1440 if (rfState == eRfOn)
1441 TxResetType = rtl819x_TxCheckStuck(dev);
1442
1344ee25 1443 if (rfState == eRfOn &&
94a79942 1444 (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
1344ee25 1445 (priv->rtllib->state == RTLLIB_LINKED))
94a79942 1446 RxResetType = rtl819x_RxCheckStuck(dev);
94a79942 1447
1344ee25
LF
1448 if (TxResetType == RESET_TYPE_NORMAL ||
1449 RxResetType == RESET_TYPE_NORMAL) {
d69d2054
MK
1450 netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n",
1451 __func__, TxResetType, RxResetType);
94a79942 1452 return RESET_TYPE_NORMAL;
1344ee25
LF
1453 } else if (TxResetType == RESET_TYPE_SILENT ||
1454 RxResetType == RESET_TYPE_SILENT) {
d69d2054
MK
1455 netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n",
1456 __func__, TxResetType, RxResetType);
94a79942
LF
1457 return RESET_TYPE_SILENT;
1458 } else {
1459 return RESET_TYPE_NORESET;
1460 }
1461
1462}
1463
49aab5fd 1464static void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
94a79942
LF
1465{
1466}
1467
49aab5fd 1468static void rtl819x_ifsilentreset(struct net_device *dev)
94a79942
LF
1469{
1470 struct r8192_priv *priv = rtllib_priv(dev);
1471 u8 reset_times = 0;
1472 int reset_status = 0;
1473 struct rtllib_device *ieee = priv->rtllib;
1474 unsigned long flag;
1475
1476 u8 IsPortal = 0;
1477
1478
1344ee25 1479 if (priv->ResetProgress == RESET_TYPE_NORESET) {
94a79942 1480
1344ee25 1481 RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
94a79942
LF
1482
1483 priv->ResetProgress = RESET_TYPE_SILENT;
1484
1344ee25
LF
1485 spin_lock_irqsave(&priv->rf_ps_lock, flag);
1486 if (priv->RFChangeInProgress) {
1487 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
94a79942
LF
1488 goto END;
1489 }
1490 priv->RFChangeInProgress = true;
1491 priv->bResetInProgress = true;
1344ee25 1492 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
94a79942
LF
1493
1494RESET_START:
1495
1496 down(&priv->wx_sem);
1497
1498 if (priv->rtllib->state == RTLLIB_LINKED)
1499 LeisurePSLeave(dev);
1500
5dc42962 1501 if (priv->up) {
0822339b
MK
1502 RT_TRACE(COMP_ERR,
1503 "%s():the driver is not up! return\n",
1504 __func__);
94a79942 1505 up(&priv->wx_sem);
fe40a0b3 1506 return;
94a79942
LF
1507 }
1508 priv->up = 0;
1509
1344ee25
LF
1510 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n",
1511 __func__);
94a79942 1512 mdelay(1000);
0822339b
MK
1513 RT_TRACE(COMP_RESET,
1514 "%s():111111111111111111111111======>start to down the driver\n",
1515 __func__);
94a79942
LF
1516
1517 if (!netif_queue_stopped(dev))
1518 netif_stop_queue(dev);
1519
1520 rtl8192_irq_disable(dev);
1521 del_timer_sync(&priv->watch_dog_timer);
1522 rtl8192_cancel_deferred_work(priv);
1523 deinit_hal_dm(dev);
1524 rtllib_stop_scan_syncro(ieee);
1525
1526 if (ieee->state == RTLLIB_LINKED) {
1527 SEM_DOWN_IEEE_WX(&ieee->wx_sem);
d69d2054 1528 netdev_info(dev, "ieee->state is RTLLIB_LINKED\n");
94a79942
LF
1529 rtllib_stop_send_beacons(priv->rtllib);
1530 del_timer_sync(&ieee->associate_timer);
1531 cancel_delayed_work(&ieee->associate_retry_wq);
1532 rtllib_stop_scan(ieee);
1533 netif_carrier_off(dev);
1534 SEM_UP_IEEE_WX(&ieee->wx_sem);
1535 } else {
d69d2054 1536 netdev_info(dev, "ieee->state is NOT LINKED\n");
f6692285 1537 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
94a79942
LF
1538 }
1539
94a79942 1540 dm_backup_dynamic_mechanism_state(dev);
94a79942
LF
1541
1542 up(&priv->wx_sem);
0822339b
MK
1543 RT_TRACE(COMP_RESET,
1544 "%s():<==========down process is finished\n",
1545 __func__);
94a79942 1546
1344ee25
LF
1547 RT_TRACE(COMP_RESET, "%s():<===========up process start\n",
1548 __func__);
1549 reset_status = _rtl8192_up(dev, true);
94a79942 1550
0822339b
MK
1551 RT_TRACE(COMP_RESET,
1552 "%s():<===========up process is finished\n", __func__);
94a79942
LF
1553 if (reset_status == -1) {
1554 if (reset_times < 3) {
1555 reset_times++;
1556 goto RESET_START;
1557 } else {
0822339b
MK
1558 RT_TRACE(COMP_ERR,
1559 " ERR!!! %s(): Reset Failed!!\n",
1560 __func__);
94a79942
LF
1561 }
1562 }
1563
1564 ieee->is_silent_reset = 1;
1565
1344ee25 1566 spin_lock_irqsave(&priv->rf_ps_lock, flag);
94a79942 1567 priv->RFChangeInProgress = false;
1344ee25 1568 spin_unlock_irqrestore(&priv->rf_ps_lock, flag);
94a79942
LF
1569
1570 EnableHWSecurityConfig8192(dev);
1571
1344ee25
LF
1572 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1573 IW_MODE_INFRA) {
1574 ieee->set_chan(ieee->dev,
1575 ieee->current_network.channel);
94a79942
LF
1576
1577 queue_work_rsl(ieee->wq, &ieee->associate_complete_wq);
1578
1344ee25
LF
1579 } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode ==
1580 IW_MODE_ADHOC) {
1581 ieee->set_chan(ieee->dev,
1582 ieee->current_network.channel);
94a79942
LF
1583 ieee->link_change(ieee->dev);
1584
1585 notify_wx_assoc_event(ieee);
1586
1587 rtllib_start_send_beacons(ieee);
1588
1589 if (ieee->data_hard_resume)
1590 ieee->data_hard_resume(ieee->dev);
1591 netif_carrier_on(ieee->dev);
1592 } else if (ieee->iw_mode == IW_MODE_MESH) {
1593 rtl819x_silentreset_mesh_bk(dev, IsPortal);
1594 }
1595
1596 CamRestoreAllEntry(dev);
94a79942 1597 dm_restore_dynamic_mechanism_state(dev);
94a79942
LF
1598END:
1599 priv->ResetProgress = RESET_TYPE_NORESET;
1600 priv->reset_count++;
1601
1344ee25 1602 priv->bForcedSilentReset = false;
94a79942
LF
1603 priv->bResetInProgress = false;
1604
94a79942 1605 write_nic_byte(dev, UFWP, 1);
1344ee25
LF
1606 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n",
1607 priv->reset_count);
94a79942
LF
1608 }
1609}
1610
49aab5fd
LF
1611static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
1612 u32 *TotalRxDataNum)
94a79942 1613{
1344ee25
LF
1614 u16 SlotIndex;
1615 u8 i;
94a79942
LF
1616
1617 *TotalRxBcnNum = 0;
1618 *TotalRxDataNum = 0;
1619
1344ee25
LF
1620 SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++) %
1621 (priv->rtllib->LinkDetectInfo.SlotNum);
1622 priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] =
1623 priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod;
1624 priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] =
1625 priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod;
94a79942
LF
1626 for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) {
1627 *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i];
1628 *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i];
1629 }
1630}
1631
1632
1633void rtl819x_watchdog_wqcallback(void *data)
1634{
1344ee25
LF
1635 struct r8192_priv *priv = container_of_dwork_rsl(data,
1636 struct r8192_priv, watch_dog_wq);
94a79942 1637 struct net_device *dev = priv->rtllib->dev;
1344ee25 1638 struct rtllib_device *ieee = priv->rtllib;
ab0d7cca 1639 enum reset_type ResetType = RESET_TYPE_NORESET;
1344ee25 1640 static u8 check_reset_cnt;
94a79942 1641 unsigned long flags;
1344ee25
LF
1642 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
1643 (&(priv->rtllib->PowerSaveControl));
94a79942
LF
1644 bool bBusyTraffic = false;
1645 bool bHigherBusyTraffic = false;
1646 bool bHigherBusyRxTraffic = false;
1647 bool bEnterPS = false;
1648
5dc42962 1649 if (!priv->up || priv->bHwRadioOff)
94a79942
LF
1650 return;
1651
1652 if (priv->rtllib->state >= RTLLIB_LINKED) {
1344ee25 1653 if (priv->rtllib->CntAfterLink < 2)
94a79942
LF
1654 priv->rtllib->CntAfterLink++;
1655 } else {
1656 priv->rtllib->CntAfterLink = 0;
1657 }
1658
1659 hal_dm_watchdog(dev);
1660
1344ee25
LF
1661 if (rtllib_act_scanning(priv->rtllib, false) == false) {
1662 if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state ==
1663 RTLLIB_NOLINK) &&
1664 (ieee->eRFPowerState == eRfOn) && !ieee->is_set_key &&
1665 (!ieee->proto_stoppping) && !ieee->wx_set_enc) {
1666 if ((ieee->PowerSaveControl.ReturnPoint ==
1667 IPS_CALLBACK_NONE) &&
1668 (!ieee->bNetPromiscuousMode)) {
0822339b
MK
1669 RT_TRACE(COMP_PS,
1670 "====================>haha: IPSEnter()\n");
94a79942
LF
1671 IPSEnter(dev);
1672 }
1673 }
1674 }
1344ee25
LF
1675 if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode ==
1676 IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode)) {
1677 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 100 ||
1678 ieee->LinkDetectInfo.NumTxOkInPeriod > 100)
1679 bBusyTraffic = true;
94a79942
LF
1680
1681
1344ee25
LF
1682 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 ||
1683 ieee->LinkDetectInfo.NumTxOkInPeriod > 4000) {
1684 bHigherBusyTraffic = true;
1685 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000)
1686 bHigherBusyRxTraffic = true;
94a79942 1687 else
1344ee25
LF
1688 bHigherBusyRxTraffic = false;
1689 }
94a79942 1690
1344ee25
LF
1691 if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod +
1692 ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) ||
1693 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2))
1694 bEnterPS = false;
1695 else
1696 bEnterPS = true;
94a79942 1697
1344ee25
LF
1698 if (ieee->current_network.beacon_interval < 95)
1699 bEnterPS = false;
94a79942 1700
1344ee25
LF
1701 if (bEnterPS)
1702 LeisurePSEnter(dev);
1703 else
94a79942 1704 LeisurePSLeave(dev);
94a79942 1705
1344ee25
LF
1706 } else {
1707 RT_TRACE(COMP_LPS, "====>no link LPS leave\n");
1708 LeisurePSLeave(dev);
1709 }
94a79942 1710
1344ee25
LF
1711 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
1712 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
1713 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
1714 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
94a79942 1715
1344ee25
LF
1716 ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic;
1717 ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic;
94a79942 1718
1344ee25
LF
1719 if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
1720 u32 TotalRxBcnNum = 0;
1721 u32 TotalRxDataNum = 0;
94a79942 1722
1344ee25 1723 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
94a79942 1724
1344ee25
LF
1725 if ((TotalRxBcnNum+TotalRxDataNum) == 0)
1726 priv->check_roaming_cnt++;
1727 else
1728 priv->check_roaming_cnt = 0;
94a79942
LF
1729
1730
1344ee25
LF
1731 if (priv->check_roaming_cnt > 0) {
1732 if (ieee->eRFPowerState == eRfOff)
1733 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
94a79942 1734
d69d2054
MK
1735 netdev_info(dev,
1736 "===>%s(): AP is power off, chan:%d, connect another one\n",
1737 __func__, priv->chan);
94a79942 1738
1344ee25 1739 ieee->state = RTLLIB_ASSOCIATING;
94a79942 1740
1344ee25
LF
1741 RemovePeerTS(priv->rtllib,
1742 priv->rtllib->current_network.bssid);
1743 ieee->is_roaming = true;
1744 ieee->is_set_key = false;
1745 ieee->link_change(dev);
1746 if (ieee->LedControlHandler)
1747 ieee->LedControlHandler(ieee->dev,
1748 LED_CTL_START_TO_LINK);
94a79942 1749
1344ee25 1750 notify_wx_assoc_event(ieee);
94a79942 1751
1344ee25
LF
1752 if (!(ieee->rtllib_ap_sec_type(ieee) &
1753 (SEC_ALG_CCMP|SEC_ALG_TKIP)))
1754 queue_delayed_work_rsl(ieee->wq,
1755 &ieee->associate_procedure_wq, 0);
94a79942 1756
1344ee25 1757 priv->check_roaming_cnt = 0;
94a79942 1758 }
1344ee25
LF
1759 ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
1760 ieee->LinkDetectInfo.NumRecvDataInPeriod = 0;
94a79942
LF
1761
1762 }
1763
1344ee25 1764 spin_lock_irqsave(&priv->tx_lock, flags);
94a79942 1765 if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
1344ee25 1766 (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) {
94a79942
LF
1767 ResetType = rtl819x_ifcheck_resetornot(dev);
1768 check_reset_cnt = 3;
1769 }
1344ee25 1770 spin_unlock_irqrestore(&priv->tx_lock, flags);
94a79942 1771
1344ee25 1772 if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) {
94a79942 1773 priv->ResetProgress = RESET_TYPE_NORMAL;
1344ee25 1774 RT_TRACE(COMP_RESET, "%s(): NOMAL RESET\n", __func__);
94a79942
LF
1775 return;
1776 }
1777
1344ee25
LF
1778 if (((priv->force_reset) || (!priv->bDisableNormalResetCheck &&
1779 ResetType == RESET_TYPE_SILENT)))
94a79942 1780 rtl819x_ifsilentreset(dev);
94a79942
LF
1781 priv->force_reset = false;
1782 priv->bForcedSilentReset = false;
1783 priv->bResetInProgress = false;
1784 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
1785}
1786
1787void watch_dog_timer_callback(unsigned long data)
1788{
1344ee25 1789 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
3a6b70c3 1790
1344ee25
LF
1791 queue_delayed_work_rsl(priv->priv_wq, &priv->watch_dog_wq, 0);
1792 mod_timer(&priv->watch_dog_timer, jiffies +
8b9733c1 1793 msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME));
94a79942
LF
1794}
1795
1796/****************************************************************************
1797 ---------------------------- NIC TX/RX STUFF---------------------------
1798*****************************************************************************/
1799void rtl8192_rx_enable(struct net_device *dev)
1800{
1344ee25 1801 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
3a6b70c3 1802
94a79942
LF
1803 priv->ops->rx_enable(dev);
1804}
1805
1806void rtl8192_tx_enable(struct net_device *dev)
1807{
1344ee25 1808 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
94a79942
LF
1809
1810 priv->ops->tx_enable(dev);
1811
1344ee25 1812 rtllib_reset_queue(priv->rtllib);
94a79942
LF
1813}
1814
1815
1816static void rtl8192_free_rx_ring(struct net_device *dev)
1817{
1344ee25
LF
1818 struct r8192_priv *priv = rtllib_priv(dev);
1819 int i, rx_queue_idx;
94a79942 1820
1344ee25
LF
1821 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE;
1822 rx_queue_idx++) {
1823 for (i = 0; i < priv->rxringcount; i++) {
94a79942 1824 struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i];
3a6b70c3 1825
1344ee25
LF
1826 if (!skb)
1827 continue;
94a79942 1828
1344ee25
LF
1829 pci_unmap_single(priv->pdev,
1830 *((dma_addr_t *)skb->cb),
1831 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1832 kfree_skb(skb);
1833 }
94a79942 1834
1344ee25
LF
1835 pci_free_consistent(priv->pdev,
1836 sizeof(*priv->rx_ring[rx_queue_idx]) *
1837 priv->rxringcount,
1838 priv->rx_ring[rx_queue_idx],
1839 priv->rx_ring_dma[rx_queue_idx]);
94a79942
LF
1840 priv->rx_ring[rx_queue_idx] = NULL;
1841 }
1842}
1843
1844static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
1845{
1344ee25
LF
1846 struct r8192_priv *priv = rtllib_priv(dev);
1847 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
94a79942 1848
1344ee25
LF
1849 while (skb_queue_len(&ring->queue)) {
1850 struct tx_desc *entry = &ring->desc[ring->idx];
1851 struct sk_buff *skb = __skb_dequeue(&ring->queue);
94a79942 1852
466bc7f2 1853 pci_unmap_single(priv->pdev, entry->TxBuffAddr,
1344ee25
LF
1854 skb->len, PCI_DMA_TODEVICE);
1855 kfree_skb(skb);
1856 ring->idx = (ring->idx + 1) % ring->entries;
1857 }
94a79942 1858
1344ee25
LF
1859 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
1860 ring->desc, ring->dma);
1861 ring->desc = NULL;
94a79942
LF
1862}
1863
1864void rtl8192_data_hard_stop(struct net_device *dev)
1865{
1866}
1867
1868
1869void rtl8192_data_hard_resume(struct net_device *dev)
1870{
1871}
1872
1344ee25
LF
1873void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1874 int rate)
94a79942
LF
1875{
1876 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1877 int ret;
1344ee25
LF
1878 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1879 MAX_DEV_ADDR_SIZE);
94a79942
LF
1880 u8 queue_index = tcb_desc->queue_index;
1881
5dc42962 1882 if ((priv->rtllib->eRFPowerState == eRfOff) || !priv->up ||
1344ee25 1883 priv->bResetInProgress) {
94a79942
LF
1884 kfree_skb(skb);
1885 return;
1886 }
1887
1888 assert(queue_index != TXCMD_QUEUE);
1889
1890
1344ee25 1891 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
94a79942
LF
1892 skb_push(skb, priv->rtllib->tx_headroom);
1893 ret = rtl8192_tx(dev, skb);
a22526e4 1894 if (ret != 0)
94a79942 1895 kfree_skb(skb);
94a79942 1896
1344ee25
LF
1897 if (queue_index != MGNT_QUEUE) {
1898 priv->rtllib->stats.tx_bytes += (skb->len -
1899 priv->rtllib->tx_headroom);
94a79942
LF
1900 priv->rtllib->stats.tx_packets++;
1901 }
94a79942
LF
1902}
1903
1344ee25 1904int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
94a79942
LF
1905{
1906 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
1907 int ret;
1344ee25
LF
1908 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1909 MAX_DEV_ADDR_SIZE);
94a79942
LF
1910 u8 queue_index = tcb_desc->queue_index;
1911
1344ee25
LF
1912 if (queue_index != TXCMD_QUEUE) {
1913 if ((priv->rtllib->eRFPowerState == eRfOff) ||
5dc42962 1914 !priv->up || priv->bResetInProgress) {
94a79942
LF
1915 kfree_skb(skb);
1916 return 0;
1917 }
1918 }
1919
1344ee25 1920 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
94a79942
LF
1921 if (queue_index == TXCMD_QUEUE) {
1922 rtl8192_tx_cmd(dev, skb);
26e2fa76 1923 return 0;
94a79942
LF
1924 }
1925
285b7c00
MK
1926 tcb_desc->RATRIndex = 7;
1927 tcb_desc->bTxDisableRateFallBack = 1;
1928 tcb_desc->bTxUseDriverAssingedRate = 1;
1929 tcb_desc->bTxEnableFwCalcDur = 1;
1930 skb_push(skb, priv->rtllib->tx_headroom);
1931 ret = rtl8192_tx(dev, skb);
1932 if (ret != 0)
1933 kfree_skb(skb);
94a79942 1934 return ret;
94a79942
LF
1935}
1936
49aab5fd 1937static void rtl8192_tx_isr(struct net_device *dev, int prio)
94a79942 1938{
1344ee25 1939 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
94a79942 1940
1344ee25 1941 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
94a79942 1942
1344ee25
LF
1943 while (skb_queue_len(&ring->queue)) {
1944 struct tx_desc *entry = &ring->desc[ring->idx];
1945 struct sk_buff *skb;
94a79942 1946
1344ee25
LF
1947 if (prio != BEACON_QUEUE) {
1948 if (entry->OWN)
1949 return;
1950 ring->idx = (ring->idx + 1) % ring->entries;
1951 }
94a79942 1952
1344ee25 1953 skb = __skb_dequeue(&ring->queue);
466bc7f2 1954 pci_unmap_single(priv->pdev, entry->TxBuffAddr,
1344ee25 1955 skb->len, PCI_DMA_TODEVICE);
94a79942 1956
1344ee25
LF
1957 kfree_skb(skb);
1958 }
1959 if (prio != BEACON_QUEUE)
1960 tasklet_schedule(&priv->irq_tx_tasklet);
94a79942
LF
1961}
1962
1963void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1964{
1344ee25
LF
1965 struct r8192_priv *priv = rtllib_priv(dev);
1966 struct rtl8192_tx_ring *ring;
1967 struct tx_desc_cmd *entry;
1968 unsigned int idx;
1969 struct cb_desc *tcb_desc;
1970 unsigned long flags;
94a79942 1971
1344ee25
LF
1972 spin_lock_irqsave(&priv->irq_th_lock, flags);
1973 ring = &priv->tx_ring[TXCMD_QUEUE];
94a79942 1974
1344ee25
LF
1975 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1976 entry = (struct tx_desc_cmd *) &ring->desc[idx];
94a79942 1977
1344ee25 1978 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
94a79942 1979
1344ee25 1980 priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb);
94a79942 1981
1344ee25
LF
1982 __skb_queue_tail(&ring->queue, skb);
1983 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
1984}
1985
1344ee25 1986short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
94a79942
LF
1987{
1988 struct r8192_priv *priv = rtllib_priv(dev);
1989 struct rtl8192_tx_ring *ring;
1990 unsigned long flags;
1344ee25
LF
1991 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb +
1992 MAX_DEV_ADDR_SIZE);
bc27e89b 1993 struct tx_desc *pdesc = NULL;
1344ee25
LF
1994 struct rtllib_hdr_1addr *header = NULL;
1995 u16 fc = 0, type = 0, stype = 0;
1996 bool multi_addr = false, broad_addr = false, uni_addr = false;
1997 u8 *pda_addr = NULL;
94a79942
LF
1998 int idx;
1999 u32 fwinfo_size = 0;
2000
1344ee25 2001 if (priv->bdisable_nic) {
0822339b
MK
2002 RT_TRACE(COMP_ERR,
2003 "%s: ERR!! Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n",
2004 __func__, skb->len, tcb_desc->queue_index);
1344ee25 2005 return skb->len;
94a79942
LF
2006 }
2007
2008 priv->rtllib->bAwakePktSent = true;
2009
a07dc3d1 2010 fwinfo_size = sizeof(struct tx_fwinfo_8190pci);
94a79942 2011
1344ee25 2012 header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size);
34e987e6 2013 fc = le16_to_cpu(header->frame_ctl);
94a79942
LF
2014 type = WLAN_FC_GET_TYPE(fc);
2015 stype = WLAN_FC_GET_STYPE(fc);
2016 pda_addr = header->addr1;
2017
14fc4235 2018 if (is_broadcast_ether_addr(pda_addr))
94a79942 2019 broad_addr = true;
14fc4235
JP
2020 else if (is_multicast_ether_addr(pda_addr))
2021 multi_addr = true;
1344ee25 2022 else
94a79942 2023 uni_addr = true;
94a79942
LF
2024
2025 if (uni_addr)
2026 priv->stats.txbytesunicast += skb->len - fwinfo_size;
2027 else if (multi_addr)
2028 priv->stats.txbytesmulticast += skb->len - fwinfo_size;
2029 else
2030 priv->stats.txbytesbroadcast += skb->len - fwinfo_size;
2031
1344ee25 2032 spin_lock_irqsave(&priv->irq_th_lock, flags);
94a79942 2033 ring = &priv->tx_ring[tcb_desc->queue_index];
1344ee25 2034 if (tcb_desc->queue_index != BEACON_QUEUE)
94a79942 2035 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1344ee25 2036 else
94a79942 2037 idx = 0;
94a79942
LF
2038
2039 pdesc = &ring->desc[idx];
2040 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
0822339b
MK
2041 RT_TRACE(COMP_ERR,
2042 "No more TX desc@%d, ring->idx = %d, idx = %d, skblen = 0x%x queuelen=%d",
1344ee25
LF
2043 tcb_desc->queue_index, ring->idx, idx, skb->len,
2044 skb_queue_len(&ring->queue));
2045 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2046 return skb->len;
2047 }
2048
1344ee25 2049 if (type == RTLLIB_FTYPE_DATA) {
94a79942
LF
2050 if (priv->rtllib->LedControlHandler)
2051 priv->rtllib->LedControlHandler(dev, LED_CTL_TX);
2052 }
2053 priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb);
2054 __skb_queue_tail(&ring->queue, skb);
2055 pdesc->OWN = 1;
1344ee25 2056 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2057 dev->trans_start = jiffies;
2058
1344ee25 2059 write_nic_word(dev, TPPoll, 0x01 << tcb_desc->queue_index);
94a79942
LF
2060 return 0;
2061}
2062
49aab5fd 2063static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
94a79942
LF
2064{
2065 struct r8192_priv *priv = rtllib_priv(dev);
4f534b36 2066 struct rx_desc *entry = NULL;
94a79942
LF
2067 int i, rx_queue_idx;
2068
1344ee25 2069 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
8b983be5
JP
2070 priv->rx_ring[rx_queue_idx] =
2071 pci_zalloc_consistent(priv->pdev,
2072 sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount,
2073 &priv->rx_ring_dma[rx_queue_idx]);
1344ee25
LF
2074 if (!priv->rx_ring[rx_queue_idx] ||
2075 (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) {
2076 RT_TRACE(COMP_ERR, "Cannot allocate RX ring\n");
94a79942
LF
2077 return -ENOMEM;
2078 }
2079
94a79942
LF
2080 priv->rx_idx[rx_queue_idx] = 0;
2081
2082 for (i = 0; i < priv->rxringcount; i++) {
2083 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
2084 dma_addr_t *mapping;
3a6b70c3 2085
94a79942
LF
2086 entry = &priv->rx_ring[rx_queue_idx][i];
2087 if (!skb)
2088 return 0;
2089 skb->dev = dev;
2090 priv->rx_buf[rx_queue_idx][i] = skb;
2091 mapping = (dma_addr_t *)skb->cb;
1344ee25
LF
2092 *mapping = pci_map_single(priv->pdev,
2093 skb_tail_pointer_rsl(skb),
2094 priv->rxbuffersize,
2095 PCI_DMA_FROMDEVICE);
2dcb4a29
LF
2096 if (pci_dma_mapping_error(priv->pdev, *mapping)) {
2097 dev_kfree_skb_any(skb);
2098 return -1;
2099 }
34e987e6 2100 entry->BufferAddress = *mapping;
94a79942
LF
2101
2102 entry->Length = priv->rxbuffersize;
2103 entry->OWN = 1;
2104 }
2105
f6692285 2106 if (entry)
35f8673d 2107 entry->EOR = 1;
94a79942
LF
2108 }
2109 return 0;
2110}
2111
2112static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
1344ee25 2113 unsigned int prio, unsigned int entries)
94a79942 2114{
1344ee25
LF
2115 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2116 struct tx_desc *ring;
2117 dma_addr_t dma;
2118 int i;
94a79942 2119
8b983be5 2120 ring = pci_zalloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
1344ee25
LF
2121 if (!ring || (unsigned long)ring & 0xFF) {
2122 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n",
2123 prio);
2124 return -ENOMEM;
2125 }
94a79942 2126
1344ee25
LF
2127 priv->tx_ring[prio].desc = ring;
2128 priv->tx_ring[prio].dma = dma;
2129 priv->tx_ring[prio].idx = 0;
2130 priv->tx_ring[prio].entries = entries;
2131 skb_queue_head_init(&priv->tx_ring[prio].queue);
94a79942 2132
1344ee25
LF
2133 for (i = 0; i < entries; i++)
2134 ring[i].NextDescAddress =
34e987e6
RK
2135 (u32)dma + ((i + 1) % entries) *
2136 sizeof(*ring);
94a79942 2137
1344ee25 2138 return 0;
94a79942
LF
2139}
2140
2141
2142short rtl8192_pci_initdescring(struct net_device *dev)
2143{
1344ee25
LF
2144 u32 ret;
2145 int i;
2146 struct r8192_priv *priv = rtllib_priv(dev);
94a79942 2147
1344ee25
LF
2148 ret = rtl8192_alloc_rx_desc_ring(dev);
2149 if (ret)
2150 return ret;
94a79942 2151
1344ee25
LF
2152 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2153 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
2154 if (ret)
2155 goto err_free_rings;
2156 }
94a79942 2157
1344ee25 2158 return 0;
94a79942
LF
2159
2160err_free_rings:
1344ee25
LF
2161 rtl8192_free_rx_ring(dev);
2162 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2163 if (priv->tx_ring[i].desc)
2164 rtl8192_free_tx_ring(dev, i);
2165 return 1;
94a79942
LF
2166}
2167
2168void rtl8192_pci_resetdescring(struct net_device *dev)
2169{
1344ee25
LF
2170 struct r8192_priv *priv = rtllib_priv(dev);
2171 int i, rx_queue_idx;
2172 unsigned long flags = 0;
94a79942 2173
1344ee25 2174 for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) {
94a79942 2175 if (priv->rx_ring[rx_queue_idx]) {
4f534b36 2176 struct rx_desc *entry = NULL;
3a6b70c3 2177
94a79942
LF
2178 for (i = 0; i < priv->rxringcount; i++) {
2179 entry = &priv->rx_ring[rx_queue_idx][i];
2180 entry->OWN = 1;
2181 }
2182 priv->rx_idx[rx_queue_idx] = 0;
2183 }
2184 }
2185
1344ee25
LF
2186 spin_lock_irqsave(&priv->irq_th_lock, flags);
2187 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
2188 if (priv->tx_ring[i].desc) {
2189 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
94a79942 2190
1344ee25
LF
2191 while (skb_queue_len(&ring->queue)) {
2192 struct tx_desc *entry = &ring->desc[ring->idx];
2193 struct sk_buff *skb =
2194 __skb_dequeue(&ring->queue);
94a79942 2195
1344ee25 2196 pci_unmap_single(priv->pdev,
466bc7f2 2197 entry->TxBuffAddr,
1344ee25
LF
2198 skb->len, PCI_DMA_TODEVICE);
2199 kfree_skb(skb);
2200 ring->idx = (ring->idx + 1) % ring->entries;
2201 }
2202 ring->idx = 0;
2203 }
2204 }
2205 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2206}
2207
1344ee25
LF
2208void rtl819x_UpdateRxPktTimeStamp(struct net_device *dev,
2209 struct rtllib_rx_stats *stats)
94a79942
LF
2210{
2211 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2212
0dd56506
LF
2213 if (stats->bIsAMPDU && !stats->bFirstMPDU)
2214 stats->mac_time = priv->LastRxDescTSF;
2215 else
2216 priv->LastRxDescTSF = stats->mac_time;
94a79942
LF
2217}
2218
1344ee25 2219long rtl819x_translate_todbm(struct r8192_priv *priv, u8 signal_strength_index)
94a79942
LF
2220{
2221 long signal_power;
2222
2223 signal_power = (long)((signal_strength_index + 1) >> 1);
2224 signal_power -= 95;
2225
2226 return signal_power;
2227}
2228
2229
2230void
2231rtl819x_update_rxsignalstatistics8190pci(
1344ee25
LF
2232 struct r8192_priv *priv,
2233 struct rtllib_rx_stats *pprevious_stats
94a79942
LF
2234 )
2235{
2236 int weighting = 0;
2237
2238
2239 if (priv->stats.recv_signal_power == 0)
1344ee25
LF
2240 priv->stats.recv_signal_power =
2241 pprevious_stats->RecvSignalPower;
94a79942
LF
2242
2243 if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
2244 weighting = 5;
1344ee25
LF
2245 else if (pprevious_stats->RecvSignalPower <
2246 priv->stats.recv_signal_power)
94a79942 2247 weighting = (-5);
1344ee25
LF
2248 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 +
2249 pprevious_stats->RecvSignalPower +
2250 weighting) / 6;
94a79942
LF
2251}
2252
1344ee25
LF
2253void rtl819x_process_cck_rxpathsel(struct r8192_priv *priv,
2254 struct rtllib_rx_stats *pprevious_stats)
94a79942 2255{
94a79942
LF
2256}
2257
2258
1344ee25 2259u8 rtl819x_query_rxpwrpercentage(char antpower)
94a79942
LF
2260{
2261 if ((antpower <= -100) || (antpower >= 20))
94a79942 2262 return 0;
94a79942 2263 else if (antpower >= 0)
94a79942 2264 return 100;
94a79942 2265 else
1344ee25 2266 return 100 + antpower;
94a79942
LF
2267
2268} /* QueryRxPwrPercentage */
2269
2270u8
2271rtl819x_evm_dbtopercentage(
2272 char value
2273 )
2274{
2275 char ret_val;
2276
2277 ret_val = value;
2278
2279 if (ret_val >= 0)
2280 ret_val = 0;
2281 if (ret_val <= -33)
2282 ret_val = -33;
2283 ret_val = 0 - ret_val;
1344ee25 2284 ret_val *= 3;
94a79942
LF
2285 if (ret_val == 99)
2286 ret_val = 100;
1344ee25 2287 return ret_val;
94a79942
LF
2288}
2289
2290void
2291rtl8192_record_rxdesc_forlateruse(
1344ee25
LF
2292 struct rtllib_rx_stats *psrc_stats,
2293 struct rtllib_rx_stats *ptarget_stats
94a79942
LF
2294)
2295{
2296 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
2297 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
2298}
2299
2300
2301
49aab5fd 2302static void rtl8192_rx_normal(struct net_device *dev)
94a79942
LF
2303{
2304 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2305 struct rtllib_hdr_1addr *rtllib_hdr = NULL;
2306 bool unicast_packet = false;
1344ee25
LF
2307 bool bLedBlinking = true;
2308 u16 fc = 0, type = 0;
94a79942
LF
2309 u32 skb_len = 0;
2310 int rx_queue_idx = RX_MPDU_QUEUE;
2311
2312 struct rtllib_rx_stats stats = {
2313 .signal = 0,
2314 .noise = -98,
2315 .rate = 0,
2316 .freq = RTLLIB_24GHZ_BAND,
2317 };
2318 unsigned int count = priv->rxringcount;
2319
2320 stats.nic_type = NIC_8192E;
2321
2322 while (count--) {
1344ee25
LF
2323 struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx]
2324 [priv->rx_idx[rx_queue_idx]];
2325 struct sk_buff *skb = priv->rx_buf[rx_queue_idx]
2326 [priv->rx_idx[rx_queue_idx]];
285b7c00 2327 struct sk_buff *new_skb;
94a79942 2328
285b7c00 2329 if (pdesc->OWN)
94a79942 2330 return;
285b7c00
MK
2331 if (!priv->ops->rx_query_status_descriptor(dev, &stats,
2332 pdesc, skb))
2333 goto done;
2334 new_skb = dev_alloc_skb(priv->rxbuffersize);
2335 /* if allocation of new skb failed - drop current packet
14b40d92
MK
2336 * and reuse skb
2337 */
285b7c00
MK
2338 if (unlikely(!new_skb))
2339 goto done;
2340
2341 pci_unmap_single(priv->pdev,
2342 *((dma_addr_t *)skb->cb),
2343 priv->rxbuffersize,
2344 PCI_DMA_FROMDEVICE);
2345
2346 skb_put(skb, pdesc->Length);
2347 skb_reserve(skb, stats.RxDrvInfoSize +
2348 stats.RxBufShift);
2349 skb_trim(skb, skb->len - 4/*sCrcLng*/);
2350 rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data;
2351 if (!is_multicast_ether_addr(rtllib_hdr->addr1)) {
2352 /* unicast packet */
2353 unicast_packet = true;
2354 }
2355 fc = le16_to_cpu(rtllib_hdr->frame_ctl);
2356 type = WLAN_FC_GET_TYPE(fc);
2357 if (type == RTLLIB_FTYPE_MGMT)
2358 bLedBlinking = false;
2359
2360 if (bLedBlinking)
2361 if (priv->rtllib->LedControlHandler)
2362 priv->rtllib->LedControlHandler(dev,
2363 LED_CTL_RX);
2364
2365 if (stats.bCRC) {
2366 if (type != RTLLIB_FTYPE_MGMT)
2367 priv->stats.rxdatacrcerr++;
2368 else
2369 priv->stats.rxmgmtcrcerr++;
2370 }
94a79942 2371
285b7c00 2372 skb_len = skb->len;
4f6807e8 2373
285b7c00
MK
2374 if (!rtllib_rx(priv->rtllib, skb, &stats)) {
2375 dev_kfree_skb_any(skb);
2376 } else {
2377 priv->stats.rxok++;
2378 if (unicast_packet)
2379 priv->stats.rxbytesunicast += skb_len;
2380 }
4f6807e8 2381
285b7c00
MK
2382 skb = new_skb;
2383 skb->dev = dev;
2384
2385 priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] =
2386 skb;
2387 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev,
2388 skb_tail_pointer_rsl(skb),
2389 priv->rxbuffersize,
2390 PCI_DMA_FROMDEVICE);
2391 if (pci_dma_mapping_error(priv->pdev,
2392 *((dma_addr_t *)skb->cb))) {
2393 dev_kfree_skb_any(skb);
2394 return;
94a79942
LF
2395 }
2396done:
34e987e6 2397 pdesc->BufferAddress = *((dma_addr_t *)skb->cb);
94a79942
LF
2398 pdesc->OWN = 1;
2399 pdesc->Length = priv->rxbuffersize;
2400 if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1)
2401 pdesc->EOR = 1;
1344ee25
LF
2402 priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) %
2403 priv->rxringcount;
94a79942
LF
2404 }
2405
2406}
2407
49aab5fd 2408static void rtl8192_rx_cmd(struct net_device *dev)
94a79942 2409{
94a79942
LF
2410}
2411
2412
49aab5fd 2413static void rtl8192_tx_resume(struct net_device *dev)
94a79942
LF
2414{
2415 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2416 struct rtllib_device *ieee = priv->rtllib;
2417 struct sk_buff *skb;
2418 int queue_index;
2419
1344ee25
LF
2420 for (queue_index = BK_QUEUE;
2421 queue_index < MAX_QUEUE_SIZE; queue_index++) {
2422 while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) &&
2423 (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) {
94a79942 2424 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
1344ee25 2425 ieee->softmac_data_hard_start_xmit(skb, dev, 0);
94a79942
LF
2426 }
2427 }
2428}
2429
2430void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
2431{
1344ee25 2432 rtl8192_tx_resume(priv->rtllib->dev);
94a79942
LF
2433}
2434
2435void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
2436{
2437 rtl8192_rx_normal(priv->rtllib->dev);
2438
2439 if (MAX_RX_QUEUE > 1)
2440 rtl8192_rx_cmd(priv->rtllib->dev);
2441
1344ee25
LF
2442 write_nic_dword(priv->rtllib->dev, INTA_MASK,
2443 read_nic_dword(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
94a79942
LF
2444}
2445
2446/****************************************************************************
2447 ---------------------------- NIC START/CLOSE STUFF---------------------------
2448*****************************************************************************/
1344ee25 2449void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
94a79942 2450{
94a79942
LF
2451 cancel_delayed_work(&priv->watch_dog_wq);
2452 cancel_delayed_work(&priv->update_beacon_wq);
94a79942 2453 cancel_delayed_work(&priv->rtllib->hw_sleep_wq);
94a79942
LF
2454 cancel_work_sync(&priv->reset_wq);
2455 cancel_work_sync(&priv->qos_activate);
94a79942
LF
2456}
2457
1344ee25 2458int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
94a79942
LF
2459{
2460 if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
2461 return -1;
2462 return 0;
2463}
2464
2465
49aab5fd 2466static int rtl8192_open(struct net_device *dev)
94a79942
LF
2467{
2468 struct r8192_priv *priv = rtllib_priv(dev);
2469 int ret;
2470
2471 down(&priv->wx_sem);
2472 ret = rtl8192_up(dev);
2473 up(&priv->wx_sem);
2474 return ret;
2475
2476}
2477
2478
2479int rtl8192_up(struct net_device *dev)
2480{
2481 struct r8192_priv *priv = rtllib_priv(dev);
2482
1344ee25
LF
2483 if (priv->up == 1)
2484 return -1;
2485 return _rtl8192_up(dev, false);
94a79942
LF
2486}
2487
2488
49aab5fd 2489static int rtl8192_close(struct net_device *dev)
94a79942
LF
2490{
2491 struct r8192_priv *priv = rtllib_priv(dev);
2492 int ret;
2493
2494 if ((rtllib_act_scanning(priv->rtllib, false)) &&
1344ee25 2495 !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) {
94a79942
LF
2496 rtllib_stop_scan(priv->rtllib);
2497 }
2498
2499 down(&priv->wx_sem);
2500
1344ee25 2501 ret = rtl8192_down(dev, true);
94a79942
LF
2502
2503 up(&priv->wx_sem);
2504
2505 return ret;
2506
2507}
2508
2509int rtl8192_down(struct net_device *dev, bool shutdownrf)
2510{
94a79942
LF
2511 if (rtl8192_sta_down(dev, shutdownrf) == -1)
2512 return -1;
2513
94a79942
LF
2514 return 0;
2515}
2516
2517void rtl8192_commit(struct net_device *dev)
2518{
2519 struct r8192_priv *priv = rtllib_priv(dev);
2520
1344ee25
LF
2521 if (priv->up == 0)
2522 return;
f6692285 2523 rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
94a79942
LF
2524 rtl8192_irq_disable(dev);
2525 priv->ops->stop_adapter(dev, true);
1344ee25 2526 _rtl8192_up(dev, false);
94a79942
LF
2527}
2528
2529void rtl8192_restart(void *data)
2530{
1344ee25
LF
2531 struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
2532 reset_wq);
94a79942 2533 struct net_device *dev = priv->rtllib->dev;
94a79942
LF
2534
2535 down(&priv->wx_sem);
2536
2537 rtl8192_commit(dev);
2538
2539 up(&priv->wx_sem);
2540}
2541
2542static void r8192_set_multicast(struct net_device *dev)
2543{
2544 struct r8192_priv *priv = rtllib_priv(dev);
2545 short promisc;
2546
1344ee25 2547 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
94a79942
LF
2548 priv->promisc = promisc;
2549
2550}
2551
2552
49aab5fd 2553static int r8192_set_mac_adr(struct net_device *dev, void *mac)
94a79942
LF
2554{
2555 struct r8192_priv *priv = rtllib_priv(dev);
2556 struct sockaddr *addr = mac;
2557
2558 down(&priv->wx_sem);
2559
1f3aefb5 2560 ether_addr_copy(dev->dev_addr, addr->sa_data);
94a79942 2561
94a79942 2562 schedule_work(&priv->reset_wq);
94a79942
LF
2563 up(&priv->wx_sem);
2564
2565 return 0;
2566}
2567
2568/* based on ipw2200 driver */
49aab5fd 2569static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
94a79942
LF
2570{
2571 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2572 struct iwreq *wrq = (struct iwreq *)rq;
1344ee25 2573 int ret = -1;
94a79942
LF
2574 struct rtllib_device *ieee = priv->rtllib;
2575 u32 key[4];
1344ee25 2576 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
94a79942
LF
2577 u8 zero_addr[6] = {0};
2578 struct iw_point *p = &wrq->u.data;
1344ee25 2579 struct ieee_param *ipw = NULL;
94a79942
LF
2580
2581 down(&priv->wx_sem);
2582
2583 switch (cmd) {
1344ee25
LF
2584 case RTL_IOCTL_WPA_SUPPLICANT:
2585 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
2586 ret = -EINVAL;
2587 goto out;
2588 }
94a79942 2589
21624981
TB
2590 ipw = memdup_user(p->pointer, p->length);
2591 if (IS_ERR(ipw)) {
2592 ret = PTR_ERR(ipw);
1344ee25
LF
2593 goto out;
2594 }
94a79942 2595
1344ee25
LF
2596 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
2597 if (ipw->u.crypt.set_tx) {
2598 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2599 ieee->pairwise_key_type = KEY_TYPE_CCMP;
2600 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2601 ieee->pairwise_key_type = KEY_TYPE_TKIP;
2602 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2603 if (ipw->u.crypt.key_len == 13)
2604 ieee->pairwise_key_type =
2605 KEY_TYPE_WEP104;
2606 else if (ipw->u.crypt.key_len == 5)
2607 ieee->pairwise_key_type =
2608 KEY_TYPE_WEP40;
2609 } else {
2610 ieee->pairwise_key_type = KEY_TYPE_NA;
94a79942 2611 }
1344ee25
LF
2612
2613 if (ieee->pairwise_key_type) {
2614 if (memcmp(ieee->ap_mac_addr, zero_addr,
2615 6) == 0)
2616 ieee->iw_mode = IW_MODE_ADHOC;
2617 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2618 EnableHWSecurityConfig8192(dev);
2619 set_swcam(dev, 4, ipw->u.crypt.idx,
2620 ieee->pairwise_key_type,
2621 (u8 *)ieee->ap_mac_addr,
2622 0, key, 0);
2623 setKey(dev, 4, ipw->u.crypt.idx,
2624 ieee->pairwise_key_type,
2625 (u8 *)ieee->ap_mac_addr, 0, key);
2626 if (ieee->iw_mode == IW_MODE_ADHOC) {
2627 set_swcam(dev, ipw->u.crypt.idx,
2628 ipw->u.crypt.idx,
2629 ieee->pairwise_key_type,
2630 (u8 *)ieee->ap_mac_addr,
2631 0, key, 0);
2632 setKey(dev, ipw->u.crypt.idx,
2633 ipw->u.crypt.idx,
2634 ieee->pairwise_key_type,
2635 (u8 *)ieee->ap_mac_addr,
2636 0, key);
94a79942
LF
2637 }
2638 }
1344ee25
LF
2639 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP)
2640 && ieee->pHTInfo->bCurrentHTSupport) {
2641 write_nic_byte(dev, 0x173, 1);
2642 }
22466983 2643
1344ee25
LF
2644 } else {
2645 memcpy((u8 *)key, ipw->u.crypt.key, 16);
2646 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
2647 ieee->group_key_type = KEY_TYPE_CCMP;
2648 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
2649 ieee->group_key_type = KEY_TYPE_TKIP;
2650 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
2651 if (ipw->u.crypt.key_len == 13)
2652 ieee->group_key_type =
2653 KEY_TYPE_WEP104;
2654 else if (ipw->u.crypt.key_len == 5)
2655 ieee->group_key_type =
2656 KEY_TYPE_WEP40;
2657 } else
2658 ieee->group_key_type = KEY_TYPE_NA;
2659
2660 if (ieee->group_key_type) {
2661 set_swcam(dev, ipw->u.crypt.idx,
2662 ipw->u.crypt.idx,
2663 ieee->group_key_type,
2664 broadcast_addr, 0, key, 0);
2665 setKey(dev, ipw->u.crypt.idx,
2666 ipw->u.crypt.idx,
2667 ieee->group_key_type,
2668 broadcast_addr, 0, key);
2669 }
2670 }
94a79942 2671 }
1344ee25
LF
2672
2673 ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data,
2674 0);
2675 kfree(ipw);
2676 break;
2677 default:
2678 ret = -EOPNOTSUPP;
2679 break;
94a79942
LF
2680 }
2681
2682out:
2683 up(&priv->wx_sem);
2684
2685 return ret;
2686}
2687
94a79942 2688
fa63c9ce 2689static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
94a79942
LF
2690{
2691 struct net_device *dev = (struct net_device *) netdev;
2692 struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
2693 unsigned long flags;
2694 u32 inta;
2695 u32 intb;
3a6b70c3 2696
94a79942
LF
2697 intb = 0;
2698
1344ee25 2699 if (priv->irq_enabled == 0)
94a79942 2700 goto done;
94a79942 2701
1344ee25 2702 spin_lock_irqsave(&priv->irq_th_lock, flags);
94a79942
LF
2703
2704 priv->ops->interrupt_recognized(dev, &inta, &intb);
2705 priv->stats.shints++;
2706
2707 if (!inta) {
1344ee25 2708 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2709 goto done;
2710 }
2711
2712 if (inta == 0xffff) {
1344ee25 2713 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2714 goto done;
2715 }
2716
2717 priv->stats.ints++;
2718
2719 if (!netif_running(dev)) {
1344ee25 2720 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2721 goto done;
2722 }
2723
1344ee25 2724 if (inta & IMR_TBDOK) {
94a79942
LF
2725 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2726 priv->stats.txbeaconokint++;
2727 }
2728
1344ee25 2729 if (inta & IMR_TBDER) {
94a79942
LF
2730 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
2731 priv->stats.txbeaconerr++;
2732 }
94a79942 2733
1344ee25 2734 if (inta & IMR_BDOK)
94a79942 2735 RT_TRACE(COMP_INTR, "beacon interrupt!\n");
94a79942 2736
1344ee25 2737 if (inta & IMR_MGNTDOK) {
94a79942
LF
2738 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
2739 priv->stats.txmanageokint++;
1344ee25
LF
2740 rtl8192_tx_isr(dev, MGNT_QUEUE);
2741 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
2742 if (priv->rtllib->ack_tx_to_ieee) {
2743 if (rtl8192_is_tx_queue_empty(dev)) {
94a79942
LF
2744 priv->rtllib->ack_tx_to_ieee = 0;
2745 rtllib_ps_tx_ack(priv->rtllib, 1);
2746 }
2747 }
1344ee25 2748 spin_lock_irqsave(&priv->irq_th_lock, flags);
94a79942
LF
2749 }
2750
94a79942
LF
2751 if (inta & IMR_COMDOK) {
2752 priv->stats.txcmdpktokint++;
1344ee25 2753 rtl8192_tx_isr(dev, TXCMD_QUEUE);
94a79942 2754 }
94a79942 2755
1344ee25
LF
2756 if (inta & IMR_HIGHDOK)
2757 rtl8192_tx_isr(dev, HIGH_QUEUE);
94a79942 2758
1344ee25 2759 if (inta & IMR_ROK) {
94a79942
LF
2760 priv->stats.rxint++;
2761 priv->InterruptLog.nIMR_ROK++;
2762 tasklet_schedule(&priv->irq_rx_tasklet);
2763 }
2764
2765 if (inta & IMR_BcnInt) {
2766 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
94a79942 2767 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
94a79942
LF
2768 }
2769
2770 if (inta & IMR_RDU) {
2771 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
2772 priv->stats.rxrdu++;
1344ee25
LF
2773 write_nic_dword(dev, INTA_MASK,
2774 read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
94a79942
LF
2775 tasklet_schedule(&priv->irq_rx_tasklet);
2776 }
2777
2778 if (inta & IMR_RXFOVW) {
2779 RT_TRACE(COMP_INTR, "rx overflow !\n");
2780 priv->stats.rxoverflow++;
2781 tasklet_schedule(&priv->irq_rx_tasklet);
2782 }
2783
1344ee25
LF
2784 if (inta & IMR_TXFOVW)
2785 priv->stats.txoverflow++;
94a79942
LF
2786
2787 if (inta & IMR_BKDOK) {
2788 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
2789 priv->stats.txbkokint++;
2790 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
1344ee25 2791 rtl8192_tx_isr(dev, BK_QUEUE);
94a79942
LF
2792 }
2793
2794 if (inta & IMR_BEDOK) {
2795 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
2796 priv->stats.txbeokint++;
2797 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
1344ee25 2798 rtl8192_tx_isr(dev, BE_QUEUE);
94a79942
LF
2799 }
2800
2801 if (inta & IMR_VIDOK) {
2802 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
2803 priv->stats.txviokint++;
2804 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
1344ee25 2805 rtl8192_tx_isr(dev, VI_QUEUE);
94a79942
LF
2806 }
2807
2808 if (inta & IMR_VODOK) {
2809 priv->stats.txvookint++;
2810 RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
2811 priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
1344ee25 2812 rtl8192_tx_isr(dev, VO_QUEUE);
94a79942
LF
2813 }
2814
1344ee25 2815 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
94a79942
LF
2816
2817done:
2818
94a79942 2819 return IRQ_HANDLED;
94a79942
LF
2820}
2821
2822
2823
2824/****************************************************************************
1344ee25 2825 ---------------------------- PCI_STUFF---------------------------
94a79942 2826*****************************************************************************/
94a79942
LF
2827static const struct net_device_ops rtl8192_netdev_ops = {
2828 .ndo_open = rtl8192_open,
2829 .ndo_stop = rtl8192_close,
2830 .ndo_tx_timeout = rtl8192_tx_timeout,
2831 .ndo_do_ioctl = rtl8192_ioctl,
faae60d2 2832 .ndo_set_rx_mode = r8192_set_multicast,
94a79942
LF
2833 .ndo_set_mac_address = r8192_set_mac_adr,
2834 .ndo_validate_addr = eth_validate_addr,
2835 .ndo_change_mtu = eth_change_mtu,
2836 .ndo_start_xmit = rtllib_xmit,
2837};
94a79942 2838
c506fff1 2839static int rtl8192_pci_probe(struct pci_dev *pdev,
1344ee25 2840 const struct pci_device_id *id)
94a79942
LF
2841{
2842 unsigned long ioaddr = 0;
2843 struct net_device *dev = NULL;
1344ee25 2844 struct r8192_priv *priv = NULL;
94a79942 2845 struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data);
94a79942 2846 unsigned long pmem_start, pmem_len, pmem_flags;
35f8673d 2847 int err = -ENOMEM;
94a79942 2848 bool bdma64 = false;
1ec3e2f2 2849 u8 revision_id;
94a79942 2850
1344ee25 2851 RT_TRACE(COMP_INIT, "Configuring chip resources");
94a79942 2852
1344ee25
LF
2853 if (pci_enable_device(pdev)) {
2854 RT_TRACE(COMP_ERR, "Failed to enable PCI device");
94a79942
LF
2855 return -EIO;
2856 }
2857
2858 pci_set_master(pdev);
2859
1344ee25
LF
2860 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2861 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
d69d2054
MK
2862 dev_info(&pdev->dev,
2863 "Unable to obtain 32bit DMA for consistent allocations\n");
35f8673d 2864 goto err_pci_disable;
94a79942
LF
2865 }
2866 }
2867 dev = alloc_rtllib(sizeof(struct r8192_priv));
2868 if (!dev)
35f8673d 2869 goto err_pci_disable;
94a79942 2870
35f8673d 2871 err = -ENODEV;
1344ee25 2872 if (bdma64)
94a79942 2873 dev->features |= NETIF_F_HIGHDMA;
94a79942 2874
94a79942 2875 pci_set_drvdata(pdev, dev);
94a79942 2876 SET_NETDEV_DEV(dev, &pdev->dev);
94a79942
LF
2877 priv = rtllib_priv(dev);
2878 priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev);
1344ee25
LF
2879 priv->pdev = pdev;
2880 priv->rtllib->pdev = pdev;
2881 if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) &&
2882 (pdev->subsystem_device == 0x3304))
94a79942 2883 priv->rtllib->bSupportRemoteWakeUp = 1;
cb762154 2884 else
94a79942 2885 priv->rtllib->bSupportRemoteWakeUp = 0;
94a79942 2886
94a79942
LF
2887 pmem_start = pci_resource_start(pdev, 1);
2888 pmem_len = pci_resource_len(pdev, 1);
1344ee25 2889 pmem_flags = pci_resource_flags(pdev, 1);
94a79942
LF
2890
2891 if (!(pmem_flags & IORESOURCE_MEM)) {
1344ee25 2892 RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting");
35f8673d 2893 goto err_rel_rtllib;
94a79942
LF
2894 }
2895
d69d2054
MK
2896 dev_info(&pdev->dev, "Memory mapped space start: 0x%08lx\n",
2897 pmem_start);
94a79942 2898 if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) {
1344ee25 2899 RT_TRACE(COMP_ERR, "request_mem_region failed!");
35f8673d 2900 goto err_rel_rtllib;
94a79942
LF
2901 }
2902
2903
1344ee25
LF
2904 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
2905 if (ioaddr == (unsigned long)NULL) {
2906 RT_TRACE(COMP_ERR, "ioremap failed!");
35f8673d 2907 goto err_rel_mem;
94a79942
LF
2908 }
2909
2910 dev->mem_start = ioaddr;
2911 dev->mem_end = ioaddr + pci_resource_len(pdev, 0);
2912
1ec3e2f2
MM
2913 pci_read_config_byte(pdev, 0x08, &revision_id);
2914 /* If the revisionid is 0x10, the device uses rtl8192se. */
2915 if (pdev->device == 0x8192 && revision_id == 0x10)
35f8673d 2916 goto err_rel_mem;
1ec3e2f2 2917
94a79942 2918 priv->ops = ops;
94a79942
LF
2919
2920 if (rtl8192_pci_findadapter(pdev, dev) == false)
35f8673d 2921 goto err_rel_mem;
94a79942
LF
2922
2923 dev->irq = pdev->irq;
2924 priv->irq = 0;
2925
94a79942 2926 dev->netdev_ops = &rtl8192_netdev_ops;
94a79942 2927
5169af23 2928 dev->wireless_handlers = &r8192_wx_handlers_def;
94a79942 2929 dev->ethtool_ops = &rtl819x_ethtool_ops;
94a79942
LF
2930
2931 dev->type = ARPHRD_ETHER;
1344ee25 2932 dev->watchdog_timeo = HZ * 3;
94a79942 2933
1344ee25 2934 if (dev_alloc_name(dev, ifname) < 0) {
0822339b
MK
2935 RT_TRACE(COMP_INIT,
2936 "Oops: devname already taken! Trying wlan%%d...\n");
1344ee25
LF
2937 dev_alloc_name(dev, ifname);
2938 }
94a79942
LF
2939
2940 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
1344ee25 2941 if (rtl8192_init(dev) != 0) {
94a79942 2942 RT_TRACE(COMP_ERR, "Initialization failed");
35f8673d 2943 goto err_free_irq;
94a79942
LF
2944 }
2945
94a79942
LF
2946 netif_carrier_off(dev);
2947 netif_stop_queue(dev);
2948
4087641b
KAM
2949 if (register_netdev(dev))
2950 goto err_free_irq;
1344ee25 2951 RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name);
80c0d83a 2952
1344ee25 2953 if (priv->polling_timer_on == 0)
94a79942 2954 check_rfctrl_gpio_timer((unsigned long)dev);
94a79942 2955
94a79942
LF
2956 RT_TRACE(COMP_INIT, "Driver probe completed\n");
2957 return 0;
2958
35f8673d
LF
2959err_free_irq:
2960 free_irq(dev->irq, dev);
2961 priv->irq = 0;
2962err_rel_mem:
2963 release_mem_region(pmem_start, pmem_len);
2964err_rel_rtllib:
2965 free_rtllib(dev);
94a79942
LF
2966
2967 DMESG("wlan driver load failed\n");
35f8673d
LF
2968err_pci_disable:
2969 pci_disable_device(pdev);
2970 return err;
94a79942
LF
2971}
2972
1387b461 2973static void rtl8192_pci_disconnect(struct pci_dev *pdev)
94a79942
LF
2974{
2975 struct net_device *dev = pci_get_drvdata(pdev);
dc986e3e 2976 struct r8192_priv *priv;
1344ee25
LF
2977 u32 i;
2978
2979 if (dev) {
94a79942
LF
2980 unregister_netdev(dev);
2981
2982 priv = rtllib_priv(dev);
2983
94a79942 2984 del_timer_sync(&priv->gpio_polling_timer);
94a79942 2985 cancel_delayed_work(&priv->gpio_change_rf_wq);
94a79942 2986 priv->polling_timer_on = 0;
1344ee25 2987 rtl8192_down(dev, true);
94a79942 2988 deinit_hal_dm(dev);
cb762154 2989 if (priv->pFirmware) {
94a79942
LF
2990 vfree(priv->pFirmware);
2991 priv->pFirmware = NULL;
2992 }
94a79942 2993 destroy_workqueue(priv->priv_wq);
1344ee25
LF
2994 rtl8192_free_rx_ring(dev);
2995 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2996 rtl8192_free_tx_ring(dev, i);
94a79942 2997
1344ee25 2998 if (priv->irq) {
d69d2054 2999 dev_info(&pdev->dev, "Freeing irq %d\n", dev->irq);
94a79942 3000 free_irq(dev->irq, dev);
1344ee25 3001 priv->irq = 0;
94a79942 3002 }
94a79942
LF
3003 free_rtllib(dev);
3004
1344ee25 3005 kfree(priv->scan_cmd);
94a79942 3006
66898177 3007 if (dev->mem_start != 0) {
49aab5fd 3008 iounmap((void __iomem *)dev->mem_start);
66898177 3009 release_mem_region(pci_resource_start(pdev, 1),
1344ee25 3010 pci_resource_len(pdev, 1));
66898177 3011 }
1344ee25
LF
3012 } else {
3013 priv = rtllib_priv(dev);
3014 }
94a79942
LF
3015
3016 pci_disable_device(pdev);
94a79942
LF
3017 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
3018}
3019
1344ee25 3020bool NicIFEnableNIC(struct net_device *dev)
94a79942
LF
3021{
3022 bool init_status = true;
1344ee25
LF
3023 struct r8192_priv *priv = rtllib_priv(dev);
3024 struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
3025 (&(priv->rtllib->PowerSaveControl));
94a79942 3026
5dc42962 3027 if (!priv->up) {
1344ee25
LF
3028 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",
3029 __func__);
94a79942 3030 priv->bdisable_nic = false;
7626e3d0 3031 return false;
94a79942
LF
3032 }
3033
1344ee25 3034 RT_TRACE(COMP_PS, "===========>%s()\n", __func__);
94a79942
LF
3035 priv->bfirst_init = true;
3036 init_status = priv->ops->initialize_adapter(dev);
4bb01423 3037 if (!init_status) {
1344ee25
LF
3038 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization is failed!\n",
3039 __func__);
94a79942 3040 priv->bdisable_nic = false;
7626e3d0 3041 return false;
94a79942
LF
3042 }
3043 RT_TRACE(COMP_INIT, "start adapter finished\n");
3044 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
3045 priv->bfirst_init = false;
3046
3047 rtl8192_irq_enable(dev);
3048 priv->bdisable_nic = false;
1344ee25 3049 RT_TRACE(COMP_PS, "<===========%s()\n", __func__);
94a79942
LF
3050 return init_status;
3051}
1344ee25 3052bool NicIFDisableNIC(struct net_device *dev)
94a79942 3053{
1344ee25 3054 struct r8192_priv *priv = rtllib_priv(dev);
94a79942 3055 u8 tmp_state = 0;
3a6b70c3 3056
1344ee25 3057 RT_TRACE(COMP_PS, "=========>%s()\n", __func__);
94a79942
LF
3058 priv->bdisable_nic = true;
3059 tmp_state = priv->rtllib->state;
3060 rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
3061 priv->rtllib->state = tmp_state;
3062 rtl8192_cancel_deferred_work(priv);
3063 rtl8192_irq_disable(dev);
3064
3065 priv->ops->stop_adapter(dev, false);
1344ee25 3066 RT_TRACE(COMP_PS, "<=========%s()\n", __func__);
94a79942 3067
e623d0f3 3068 return true;
94a79942
LF
3069}
3070
3071static int __init rtl8192_pci_module_init(void)
3072{
d69d2054
MK
3073 pr_info("\nLinux kernel driver for RTL8192E WLAN cards\n");
3074 pr_info("Copyright (c) 2007-2008, Realsil Wlan Driver\n");
94a79942 3075
1344ee25 3076 if (0 != pci_register_driver(&rtl8192_pci_driver)) {
94a79942
LF
3077 DMESG("No device found");
3078 /*pci_unregister_driver (&rtl8192_pci_driver);*/
3079 return -ENODEV;
3080 }
3081 return 0;
94a79942
LF
3082}
3083
3084static void __exit rtl8192_pci_module_exit(void)
3085{
3086 pci_unregister_driver(&rtl8192_pci_driver);
3087
3088 RT_TRACE(COMP_DOWN, "Exiting");
94a79942
LF
3089}
3090
3091void check_rfctrl_gpio_timer(unsigned long data)
3092{
1344ee25 3093 struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
94a79942
LF
3094
3095 priv->polling_timer_on = 1;
3096
1344ee25 3097 queue_delayed_work_rsl(priv->priv_wq, &priv->gpio_change_rf_wq, 0);
94a79942 3098
1344ee25 3099 mod_timer(&priv->gpio_polling_timer, jiffies +
8b9733c1 3100 msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME));
94a79942
LF
3101}
3102
3103/***************************************************************************
1344ee25 3104 ------------------- module init / exit stubs ----------------
94a79942
LF
3105****************************************************************************/
3106module_init(rtl8192_pci_module_init);
3107module_exit(rtl8192_pci_module_exit);
3108
3109MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
3110MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
94a79942 3111MODULE_VERSION(DRV_VERSION);
94a79942 3112MODULE_LICENSE("GPL");
7f34f412
TG
3113MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW);
3114MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW);
3115MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW);
94a79942 3116
1344ee25
LF
3117module_param(ifname, charp, S_IRUGO|S_IWUSR);
3118module_param(hwwep, int, S_IRUGO|S_IWUSR);
3119module_param(channels, int, S_IRUGO|S_IWUSR);
94a79942 3120
1344ee25
LF
3121MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
3122MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");
3123MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");