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