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