staging: rtl8192e: Clean up function headers
[deliverable/linux.git] / drivers / staging / rtl8192e / r8192E_core.c
1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 * Linux device driver for RTL8190P / RTL8192E
4 *
5 * Based on the r8180 driver, which is:
6 * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
22 *
23 * Contact Information:
24 * Jerry chuang <wlanfae@realtek.com>
25 */
26
27
28 #undef LOOP_TEST
29 #undef RX_DONT_PASS_UL
30 #undef DEBUG_EPROM
31 #undef DEBUG_RX_VERBOSE
32 #undef DUMMY_RX
33 #undef DEBUG_ZERO_RX
34 #undef DEBUG_RX_SKB
35 #undef DEBUG_TX_FRAG
36 #undef DEBUG_RX_FRAG
37 #undef DEBUG_TX_FILLDESC
38 #undef DEBUG_TX
39 #undef DEBUG_IRQ
40 #undef DEBUG_RX
41 #undef DEBUG_RXALLOC
42 #undef DEBUG_REGISTERS
43 #undef DEBUG_RING
44 #undef DEBUG_IRQ_TASKLET
45 #undef DEBUG_TX_ALLOC
46 #undef DEBUG_TX_DESC
47
48 //#define CONFIG_RTL8192_IO_MAP
49 #include <linux/vmalloc.h>
50 #include <linux/slab.h>
51 #include <asm/uaccess.h>
52 #include "r8192E_hw.h"
53 #include "r8192E.h"
54 #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
55 #include "r8180_93cx6.h" /* Card EEPROM */
56 #include "r8192E_wx.h"
57 #include "r819xE_phy.h" //added by WB 4.30.2008
58 #include "r819xE_phyreg.h"
59 #include "r819xE_cmdpkt.h"
60 #include "r8192E_dm.h"
61
62 #ifdef CONFIG_PM
63 #include "r8192_pm.h"
64 #endif
65
66 #ifdef ENABLE_DOT11D
67 #include "ieee80211/dot11d.h"
68 #endif
69
70 //set here to open your trace code. //WB
71 u32 rt_global_debug_component =
72 // COMP_INIT |
73 // COMP_EPROM |
74 // COMP_PHY |
75 // COMP_RF |
76 // COMP_FIRMWARE |
77 // COMP_TRACE |
78 // COMP_DOWN |
79 // COMP_SWBW |
80 // COMP_SEC |
81 // COMP_QOS |
82 // COMP_RATE |
83 // COMP_RECV |
84 // COMP_SEND |
85 // COMP_POWER |
86 // COMP_EVENTS |
87 // COMP_RESET |
88 // COMP_CMDPKT |
89 // COMP_POWER_TRACKING |
90 // COMP_INTR |
91 COMP_ERR ; //always open err flags on
92
93 static const struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
94 #ifdef RTL8190P
95 /* Realtek */
96 /* Dlink */
97 { PCI_DEVICE(0x10ec, 0x8190) },
98 /* Corega */
99 { PCI_DEVICE(0x07aa, 0x0045) },
100 { PCI_DEVICE(0x07aa, 0x0046) },
101 #else
102 /* Realtek */
103 { PCI_DEVICE(0x10ec, 0x8192) },
104
105 /* Corega */
106 { PCI_DEVICE(0x07aa, 0x0044) },
107 { PCI_DEVICE(0x07aa, 0x0047) },
108 #endif
109 {}
110 };
111
112 static char ifname[IFNAMSIZ] = "wlan%d";
113 static int hwwep = 1; //default use hw. set 0 to use software security
114 static int channels = 0x3fff;
115
116 MODULE_LICENSE("GPL");
117 MODULE_VERSION("V 1.1");
118 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
119 //MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
120 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
121
122
123 module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
124 module_param(hwwep,int, S_IRUGO|S_IWUSR);
125 module_param(channels,int, S_IRUGO|S_IWUSR);
126
127 MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
128 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
129 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
130
131 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
132 const struct pci_device_id *id);
133 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev);
134
135 static struct pci_driver rtl8192_pci_driver = {
136 .name = RTL819xE_MODULE_NAME, /* Driver name */
137 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
138 .probe = rtl8192_pci_probe, /* probe fn */
139 .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */
140 #ifdef CONFIG_PM
141 .suspend = rtl8192E_suspend, /* PM suspend fn */
142 .resume = rtl8192E_resume, /* PM resume fn */
143 #else
144 .suspend = NULL, /* PM suspend fn */
145 .resume = NULL, /* PM resume fn */
146 #endif
147 };
148
149 static void rtl8192_start_beacon(struct net_device *dev);
150 static void rtl8192_stop_beacon(struct net_device *dev);
151 static void rtl819x_watchdog_wqcallback(struct work_struct *work);
152 static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
153 static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
154 static void rtl8192_prepare_beacon(struct r8192_priv *priv);
155 static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
156 static void rtl8192_try_wake_queue(struct net_device *dev, int pri);
157 static void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb);
158 static void rtl8192_update_ratr_table(struct net_device* dev);
159 static void rtl8192_restart(struct work_struct *work);
160 static void watch_dog_timer_callback(unsigned long data);
161 static int _rtl8192_up(struct net_device *dev);
162 static void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
163
164 #ifdef ENABLE_DOT11D
165
166 typedef struct _CHANNEL_LIST
167 {
168 u8 Channel[32];
169 u8 Len;
170 }CHANNEL_LIST, *PCHANNEL_LIST;
171
172 static const CHANNEL_LIST ChannelPlan[] = {
173 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC
174 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
175 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
176 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
177 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
178 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK
179 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
180 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
181 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, // For 11a , TELEC
182 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
183 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14} //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626
184 };
185
186 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
187 {
188 int i, max_chan=-1, min_chan=-1;
189 struct ieee80211_device* ieee = priv->ieee80211;
190 switch (channel_plan)
191 {
192 case COUNTRY_CODE_FCC:
193 case COUNTRY_CODE_IC:
194 case COUNTRY_CODE_ETSI:
195 case COUNTRY_CODE_SPAIN:
196 case COUNTRY_CODE_FRANCE:
197 case COUNTRY_CODE_MKK:
198 case COUNTRY_CODE_MKK1:
199 case COUNTRY_CODE_ISRAEL:
200 case COUNTRY_CODE_TELEC:
201 case COUNTRY_CODE_MIC:
202 {
203 Dot11d_Init(ieee);
204 ieee->bGlobalDomain = false;
205 //acturally 8225 & 8256 rf chip only support B,G,24N mode
206 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256))
207 {
208 min_chan = 1;
209 max_chan = 14;
210 }
211 else
212 {
213 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
214 }
215 if (ChannelPlan[channel_plan].Len != 0){
216 // Clear old channel map
217 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
218 // Set new channel map
219 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
220 {
221 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
222 break;
223 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
224 }
225 }
226 break;
227 }
228 case COUNTRY_CODE_GLOBAL_DOMAIN:
229 {
230 GET_DOT11D_INFO(ieee)->bEnabled = 0; //this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain setting
231 Dot11d_Reset(ieee);
232 ieee->bGlobalDomain = true;
233 break;
234 }
235 default:
236 break;
237 }
238 }
239 #endif
240
241
242 #define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
243 /* 2007/07/25 MH Defien temp tx fw info. */
244 static TX_FWINFO_T Tmp_TxFwInfo;
245
246
247 #define rx_hal_is_cck_rate(_pdrvinfo)\
248 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
249 _pdrvinfo->RxRate == DESC90_RATE2M ||\
250 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
251 _pdrvinfo->RxRate == DESC90_RATE11M) &&\
252 !_pdrvinfo->RxHT\
253
254
255 void CamResetAllEntry(struct net_device *dev)
256 {
257 //u8 ucIndex;
258 u32 ulcommand = 0;
259
260 #if 1
261 ulcommand |= BIT31|BIT30;
262 write_nic_dword(dev, RWCAM, ulcommand);
263 #else
264 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
265 CAM_mark_invalid(dev, ucIndex);
266 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
267 CAM_empty_entry(dev, ucIndex);
268 #endif
269 }
270
271
272 void write_cam(struct net_device *dev, u8 addr, u32 data)
273 {
274 write_nic_dword(dev, WCAMI, data);
275 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
276 }
277 u32 read_cam(struct net_device *dev, u8 addr)
278 {
279 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
280 return read_nic_dword(dev, 0xa8);
281 }
282
283 #ifdef CONFIG_RTL8180_IO_MAP
284
285 u8 read_nic_byte(struct net_device *dev, int x)
286 {
287 return 0xff&inb(dev->base_addr +x);
288 }
289
290 u32 read_nic_dword(struct net_device *dev, int x)
291 {
292 return inl(dev->base_addr +x);
293 }
294
295 u16 read_nic_word(struct net_device *dev, int x)
296 {
297 return inw(dev->base_addr +x);
298 }
299
300 void write_nic_byte(struct net_device *dev, int x,u8 y)
301 {
302 outb(y&0xff,dev->base_addr +x);
303 }
304
305 void write_nic_word(struct net_device *dev, int x,u16 y)
306 {
307 outw(y,dev->base_addr +x);
308 }
309
310 void write_nic_dword(struct net_device *dev, int x,u32 y)
311 {
312 outl(y,dev->base_addr +x);
313 }
314
315 #else /* RTL_IO_MAP */
316
317 u8 read_nic_byte(struct net_device *dev, int x)
318 {
319 return 0xff&readb((u8*)dev->mem_start +x);
320 }
321
322 u32 read_nic_dword(struct net_device *dev, int x)
323 {
324 return readl((u8*)dev->mem_start +x);
325 }
326
327 u16 read_nic_word(struct net_device *dev, int x)
328 {
329 return readw((u8*)dev->mem_start +x);
330 }
331
332 void write_nic_byte(struct net_device *dev, int x,u8 y)
333 {
334 writeb(y,(u8*)dev->mem_start +x);
335 udelay(20);
336 }
337
338 void write_nic_dword(struct net_device *dev, int x,u32 y)
339 {
340 writel(y,(u8*)dev->mem_start +x);
341 udelay(20);
342 }
343
344 void write_nic_word(struct net_device *dev, int x,u16 y)
345 {
346 writew(y,(u8*)dev->mem_start +x);
347 udelay(20);
348 }
349
350 #endif /* RTL_IO_MAP */
351
352 u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee)
353 {
354 //struct r8192_priv* priv = ieee80211_priv(dev);
355 //struct ieee80211_device *ieee = priv->ieee80211;
356
357 static const u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
358 static const u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
359 int wpa_ie_len= ieee->wpa_ie_len;
360 struct ieee80211_crypt_data* crypt;
361 int encrypt;
362
363 crypt = ieee->crypt[ieee->tx_keyidx];
364
365 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) ||
366 (ieee->host_encrypt && crypt && crypt->ops &&
367 (0 == strcmp(crypt->ops->name,"WEP")));
368
369 /* simply judge */
370 if(encrypt && (wpa_ie_len == 0)) {
371 // wep encryption, no N mode setting */
372 return SEC_ALG_WEP;
373 } else if((wpa_ie_len != 0)) {
374 // parse pairwise key type */
375 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) ||
376 ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
377 return SEC_ALG_CCMP;
378 else
379 return SEC_ALG_TKIP;
380 } else {
381 return SEC_ALG_NONE;
382 }
383 }
384
385 void
386 rtl8192e_SetHwReg(struct net_device *dev,u8 variable,u8* val)
387 {
388 struct r8192_priv* priv = ieee80211_priv(dev);
389
390 switch(variable)
391 {
392
393 case HW_VAR_BSSID:
394 write_nic_dword(dev, BSSIDR, ((u32*)(val))[0]);
395 write_nic_word(dev, BSSIDR+2, ((u16*)(val+2))[0]);
396 break;
397
398 case HW_VAR_MEDIA_STATUS:
399 {
400 RT_OP_MODE OpMode = *((RT_OP_MODE *)(val));
401 //LED_CTL_MODE LedAction = LED_CTL_NO_LINK;
402 u8 btMsr = read_nic_byte(dev, MSR);
403
404 btMsr &= 0xfc;
405
406 switch(OpMode)
407 {
408 case RT_OP_MODE_INFRASTRUCTURE:
409 btMsr |= MSR_INFRA;
410 //LedAction = LED_CTL_LINK;
411 break;
412
413 case RT_OP_MODE_IBSS:
414 btMsr |= MSR_ADHOC;
415 // led link set separate
416 break;
417
418 case RT_OP_MODE_AP:
419 btMsr |= MSR_AP;
420 //LedAction = LED_CTL_LINK;
421 break;
422
423 default:
424 btMsr |= MSR_NOLINK;
425 break;
426 }
427
428 write_nic_byte(dev, MSR, btMsr);
429
430 //priv->ieee80211->LedControlHandler(dev, LedAction);
431 }
432 break;
433
434 case HW_VAR_CECHK_BSSID:
435 {
436 u32 RegRCR, Type;
437
438 Type = ((u8*)(val))[0];
439 //priv->ieee80211->GetHwRegHandler(dev, HW_VAR_RCR, (u8*)(&RegRCR));
440 RegRCR = read_nic_dword(dev,RCR);
441 priv->ReceiveConfig = RegRCR;
442
443 if (Type == true)
444 RegRCR |= (RCR_CBSSID);
445 else if (Type == false)
446 RegRCR &= (~RCR_CBSSID);
447
448 //priv->ieee80211->SetHwRegHandler( dev, HW_VAR_RCR, (u8*)(&RegRCR) );
449 write_nic_dword(dev, RCR,RegRCR);
450 priv->ReceiveConfig = RegRCR;
451
452 }
453 break;
454
455 case HW_VAR_SLOT_TIME:
456 {
457 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
458 //AC_CODING eACI;
459
460 priv->slot_time = val[0];
461 write_nic_byte(dev, SLOT_TIME, val[0]);
462
463 }
464 break;
465
466 case HW_VAR_ACK_PREAMBLE:
467 {
468 u32 regTmp = 0;
469 priv->short_preamble = (bool)(*(u8*)val );
470 regTmp = priv->basic_rate;
471 if (priv->short_preamble)
472 regTmp |= BRSR_AckShortPmb;
473 write_nic_dword(dev, RRSR, regTmp);
474 }
475 break;
476
477 case HW_VAR_CPU_RST:
478 write_nic_dword(dev, CPU_GEN, ((u32*)(val))[0]);
479 break;
480
481 default:
482 break;
483 }
484
485 }
486
487 /*
488 * this might still called in what was the PHY rtl8185/rtl8192 common code
489 * plans are to possibilty turn it again in one common code...
490 */
491 void force_pci_posting(struct net_device *dev)
492 {
493 }
494
495 static struct proc_dir_entry *rtl8192_proc = NULL;
496
497 static int proc_get_stats_ap(char *page, char **start,
498 off_t offset, int count,
499 int *eof, void *data)
500 {
501 struct net_device *dev = data;
502 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
503 struct ieee80211_device *ieee = priv->ieee80211;
504 struct ieee80211_network *target;
505
506 int len = 0;
507
508 list_for_each_entry(target, &ieee->network_list, list) {
509
510 len += snprintf(page + len, count - len,
511 "%s ", target->ssid);
512
513 if(target->wpa_ie_len>0 || target->rsn_ie_len>0){
514 len += snprintf(page + len, count - len,
515 "WPA\n");
516 }
517 else{
518 len += snprintf(page + len, count - len,
519 "non_WPA\n");
520 }
521
522 }
523
524 *eof = 1;
525 return len;
526 }
527
528 static int proc_get_registers(char *page, char **start,
529 off_t offset, int count,
530 int *eof, void *data)
531 {
532 struct net_device *dev = data;
533 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
534
535 int len = 0;
536 int i,n;
537
538 int max=0xff;
539
540 /* This dump the current register page */
541 len += snprintf(page + len, count - len,
542 "\n####################page 0##################\n ");
543
544 for(n=0;n<=max;)
545 {
546 //printk( "\nD: %2x> ", n);
547 len += snprintf(page + len, count - len,
548 "\nD: %2x > ",n);
549
550 for(i=0;i<16 && n<=max;i++,n++)
551 len += snprintf(page + len, count - len,
552 "%2x ",read_nic_byte(dev,n));
553
554 // printk("%2x ",read_nic_byte(dev,n));
555 }
556 len += snprintf(page + len, count - len,"\n");
557 len += snprintf(page + len, count - len,
558 "\n####################page 1##################\n ");
559 for(n=0;n<=max;)
560 {
561 //printk( "\nD: %2x> ", n);
562 len += snprintf(page + len, count - len,
563 "\nD: %2x > ",n);
564
565 for(i=0;i<16 && n<=max;i++,n++)
566 len += snprintf(page + len, count - len,
567 "%2x ",read_nic_byte(dev,0x100|n));
568
569 // printk("%2x ",read_nic_byte(dev,n));
570 }
571
572 len += snprintf(page + len, count - len,
573 "\n####################page 3##################\n ");
574 for(n=0;n<=max;)
575 {
576 //printk( "\nD: %2x> ", n);
577 len += snprintf(page + len, count - len,
578 "\nD: %2x > ",n);
579
580 for(i=0;i<16 && n<=max;i++,n++)
581 len += snprintf(page + len, count - len,
582 "%2x ",read_nic_byte(dev,0x300|n));
583
584 // printk("%2x ",read_nic_byte(dev,n));
585 }
586
587
588 *eof = 1;
589 return len;
590
591 }
592
593
594
595 static int proc_get_stats_tx(char *page, char **start,
596 off_t offset, int count,
597 int *eof, void *data)
598 {
599 struct net_device *dev = data;
600 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
601
602 int len = 0;
603
604 len += snprintf(page + len, count - len,
605 "TX VI priority ok int: %lu\n"
606 // "TX VI priority error int: %lu\n"
607 "TX VO priority ok int: %lu\n"
608 // "TX VO priority error int: %lu\n"
609 "TX BE priority ok int: %lu\n"
610 // "TX BE priority error int: %lu\n"
611 "TX BK priority ok int: %lu\n"
612 // "TX BK priority error int: %lu\n"
613 "TX MANAGE priority ok int: %lu\n"
614 // "TX MANAGE priority error int: %lu\n"
615 "TX BEACON priority ok int: %lu\n"
616 "TX BEACON priority error int: %lu\n"
617 "TX CMDPKT priority ok int: %lu\n"
618 // "TX high priority ok int: %lu\n"
619 // "TX high priority failed error int: %lu\n"
620 // "TX queue resume: %lu\n"
621 "TX queue stopped?: %d\n"
622 "TX fifo overflow: %lu\n"
623 // "TX beacon: %lu\n"
624 // "TX VI queue: %d\n"
625 // "TX VO queue: %d\n"
626 // "TX BE queue: %d\n"
627 // "TX BK queue: %d\n"
628 // "TX HW queue: %d\n"
629 // "TX VI dropped: %lu\n"
630 // "TX VO dropped: %lu\n"
631 // "TX BE dropped: %lu\n"
632 // "TX BK dropped: %lu\n"
633 "TX total data packets %lu\n"
634 "TX total data bytes :%lu\n",
635 // "TX beacon aborted: %lu\n",
636 priv->stats.txviokint,
637 // priv->stats.txvierr,
638 priv->stats.txvookint,
639 // priv->stats.txvoerr,
640 priv->stats.txbeokint,
641 // priv->stats.txbeerr,
642 priv->stats.txbkokint,
643 // priv->stats.txbkerr,
644 priv->stats.txmanageokint,
645 // priv->stats.txmanageerr,
646 priv->stats.txbeaconokint,
647 priv->stats.txbeaconerr,
648 priv->stats.txcmdpktokint,
649 // priv->stats.txhpokint,
650 // priv->stats.txhperr,
651 // priv->stats.txresumed,
652 netif_queue_stopped(dev),
653 priv->stats.txoverflow,
654 // priv->stats.txbeacon,
655 // atomic_read(&(priv->tx_pending[VI_QUEUE])),
656 // atomic_read(&(priv->tx_pending[VO_QUEUE])),
657 // atomic_read(&(priv->tx_pending[BE_QUEUE])),
658 // atomic_read(&(priv->tx_pending[BK_QUEUE])),
659 // read_nic_byte(dev, TXFIFOCOUNT),
660 // priv->stats.txvidrop,
661 // priv->stats.txvodrop,
662 priv->ieee80211->stats.tx_packets,
663 priv->ieee80211->stats.tx_bytes
664
665
666 // priv->stats.txbedrop,
667 // priv->stats.txbkdrop
668 // priv->stats.txdatapkt
669 // priv->stats.txbeaconerr
670 );
671
672 *eof = 1;
673 return len;
674 }
675
676
677
678 static int proc_get_stats_rx(char *page, char **start,
679 off_t offset, int count,
680 int *eof, void *data)
681 {
682 struct net_device *dev = data;
683 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
684
685 int len = 0;
686
687 len += snprintf(page + len, count - len,
688 "RX packets: %lu\n"
689 "RX desc err: %lu\n"
690 "RX rx overflow error: %lu\n"
691 "RX invalid urb error: %lu\n",
692 priv->stats.rxint,
693 priv->stats.rxrdu,
694 priv->stats.rxoverflow,
695 priv->stats.rxurberr);
696
697 *eof = 1;
698 return len;
699 }
700
701 static void rtl8192_proc_module_init(void)
702 {
703 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
704 rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net);
705 }
706
707
708 static void rtl8192_proc_module_remove(void)
709 {
710 remove_proc_entry(RTL819xE_MODULE_NAME, init_net.proc_net);
711 }
712
713
714 static void rtl8192_proc_remove_one(struct net_device *dev)
715 {
716 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
717
718 printk("dev name=======> %s\n",dev->name);
719
720 if (priv->dir_dev) {
721 // remove_proc_entry("stats-hw", priv->dir_dev);
722 remove_proc_entry("stats-tx", priv->dir_dev);
723 remove_proc_entry("stats-rx", priv->dir_dev);
724 // remove_proc_entry("stats-ieee", priv->dir_dev);
725 remove_proc_entry("stats-ap", priv->dir_dev);
726 remove_proc_entry("registers", priv->dir_dev);
727 // remove_proc_entry("cck-registers",priv->dir_dev);
728 // remove_proc_entry("ofdm-registers",priv->dir_dev);
729 //remove_proc_entry(dev->name, rtl8192_proc);
730 remove_proc_entry("wlan0", rtl8192_proc);
731 priv->dir_dev = NULL;
732 }
733 }
734
735
736 static void rtl8192_proc_init_one(struct net_device *dev)
737 {
738 struct proc_dir_entry *e;
739 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
740 priv->dir_dev = create_proc_entry(dev->name,
741 S_IFDIR | S_IRUGO | S_IXUGO,
742 rtl8192_proc);
743 if (!priv->dir_dev) {
744 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
745 dev->name);
746 return;
747 }
748 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
749 priv->dir_dev, proc_get_stats_rx, dev);
750
751 if (!e) {
752 RT_TRACE(COMP_ERR,"Unable to initialize "
753 "/proc/net/rtl8192/%s/stats-rx\n",
754 dev->name);
755 }
756
757
758 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
759 priv->dir_dev, proc_get_stats_tx, dev);
760
761 if (!e) {
762 RT_TRACE(COMP_ERR, "Unable to initialize "
763 "/proc/net/rtl8192/%s/stats-tx\n",
764 dev->name);
765 }
766
767 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
768 priv->dir_dev, proc_get_stats_ap, dev);
769
770 if (!e) {
771 RT_TRACE(COMP_ERR, "Unable to initialize "
772 "/proc/net/rtl8192/%s/stats-ap\n",
773 dev->name);
774 }
775
776 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
777 priv->dir_dev, proc_get_registers, dev);
778 if (!e) {
779 RT_TRACE(COMP_ERR, "Unable to initialize "
780 "/proc/net/rtl8192/%s/registers\n",
781 dev->name);
782 }
783 }
784
785 short check_nic_enough_desc(struct net_device *dev, int prio)
786 {
787 struct r8192_priv *priv = ieee80211_priv(dev);
788 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
789
790 /* for now we reserve two free descriptor as a safety boundary
791 * between the tail and the head
792 */
793 return (ring->entries - skb_queue_len(&ring->queue) >= 2);
794 }
795
796 static void tx_timeout(struct net_device *dev)
797 {
798 struct r8192_priv *priv = ieee80211_priv(dev);
799 //rtl8192_commit(dev);
800
801 schedule_work(&priv->reset_wq);
802 printk("TXTIMEOUT");
803 }
804
805 static void rtl8192_irq_enable(struct net_device *dev)
806 {
807 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
808 priv->irq_enabled = 1;
809 write_nic_dword(dev,INTA_MASK, priv->irq_mask);
810 }
811
812 void rtl8192_irq_disable(struct net_device *dev)
813 {
814 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
815
816 write_nic_dword(dev,INTA_MASK,0);
817 force_pci_posting(dev);
818 priv->irq_enabled = 0;
819 }
820
821
822 #if 0
823 static void rtl8192_set_mode(struct net_device *dev,int mode)
824 {
825 u8 ecmd;
826 ecmd=read_nic_byte(dev, EPROM_CMD);
827 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
828 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
829 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
830 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
831 write_nic_byte(dev, EPROM_CMD, ecmd);
832 }
833 #endif
834
835 void rtl8192_update_msr(struct net_device *dev)
836 {
837 struct r8192_priv *priv = ieee80211_priv(dev);
838 u8 msr;
839
840 msr = read_nic_byte(dev, MSR);
841 msr &= ~ MSR_LINK_MASK;
842
843 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
844 * msr must be updated if the state is ASSOCIATING.
845 * this is intentional and make sense for ad-hoc and
846 * master (see the create BSS/IBSS func)
847 */
848 if (priv->ieee80211->state == IEEE80211_LINKED){
849
850 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
851 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
852 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
853 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
854 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
855 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
856
857 }else
858 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
859
860 write_nic_byte(dev, MSR, msr);
861 }
862
863 void rtl8192_set_chan(struct net_device *dev,short ch)
864 {
865 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
866 RT_TRACE(COMP_RF, "=====>%s()====ch:%d\n", __FUNCTION__, ch);
867 priv->chan=ch;
868 #if 0
869 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC ||
870 priv->ieee80211->iw_mode == IW_MODE_MASTER){
871
872 priv->ieee80211->link_state = WLAN_LINK_ASSOCIATED;
873 priv->ieee80211->master_chan = ch;
874 rtl8192_update_beacon_ch(dev);
875 }
876 #endif
877
878 /* this hack should avoid frame TX during channel setting*/
879
880
881 // tx = read_nic_dword(dev,TX_CONF);
882 // tx &= ~TX_LOOPBACK_MASK;
883
884 #ifndef LOOP_TEST
885 //TODO
886 // write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
887
888 //need to implement rf set channel here WB
889
890 if (priv->rf_set_chan)
891 priv->rf_set_chan(dev,priv->chan);
892 // mdelay(10);
893 // write_nic_dword(dev,TX_CONF,tx | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT));
894 #endif
895 }
896
897 void rtl8192_rx_enable(struct net_device *dev)
898 {
899 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
900 write_nic_dword(dev, RDQDA,priv->rx_ring_dma);
901 }
902
903 /* the TX_DESC_BASE setting is according to the following queue index
904 * BK_QUEUE ===> 0
905 * BE_QUEUE ===> 1
906 * VI_QUEUE ===> 2
907 * VO_QUEUE ===> 3
908 * HCCA_QUEUE ===> 4
909 * TXCMD_QUEUE ===> 5
910 * MGNT_QUEUE ===> 6
911 * HIGH_QUEUE ===> 7
912 * BEACON_QUEUE ===> 8
913 * */
914 static const u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA};
915 void rtl8192_tx_enable(struct net_device *dev)
916 {
917 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
918 u32 i;
919 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
920 write_nic_dword(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma);
921
922 ieee80211_reset_queue(priv->ieee80211);
923 }
924
925
926 static void rtl8192_free_rx_ring(struct net_device *dev)
927 {
928 struct r8192_priv *priv = ieee80211_priv(dev);
929 int i;
930
931 for (i = 0; i < priv->rxringcount; i++) {
932 struct sk_buff *skb = priv->rx_buf[i];
933 if (!skb)
934 continue;
935
936 pci_unmap_single(priv->pdev,
937 *((dma_addr_t *)skb->cb),
938 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
939 kfree_skb(skb);
940 }
941
942 pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount,
943 priv->rx_ring, priv->rx_ring_dma);
944 priv->rx_ring = NULL;
945 }
946
947 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
948 {
949 struct r8192_priv *priv = ieee80211_priv(dev);
950 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
951
952 while (skb_queue_len(&ring->queue)) {
953 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
954 struct sk_buff *skb = __skb_dequeue(&ring->queue);
955
956 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
957 skb->len, PCI_DMA_TODEVICE);
958 kfree_skb(skb);
959 ring->idx = (ring->idx + 1) % ring->entries;
960 }
961
962 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
963 ring->desc, ring->dma);
964 ring->desc = NULL;
965 }
966
967 void PHY_SetRtl8192eRfOff(struct net_device* dev)
968 {
969 //disable RF-Chip A/B
970 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
971 //analog to digital off, for power save
972 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0);
973 //digital to analog off, for power save
974 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0);
975 //rx antenna off
976 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
977 //rx antenna off
978 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
979 //analog to digital part2 off, for power save
980 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0);
981 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0);
982 // Analog parameter!!Change bias and Lbus control.
983 write_nic_byte(dev, ANAPAR_FOR_8192PciE, 0x07);
984
985 }
986
987 void rtl8192_halt_adapter(struct net_device *dev, bool reset)
988 {
989 //u8 cmd;
990 struct r8192_priv *priv = ieee80211_priv(dev);
991 int i;
992 u8 OpMode;
993 u8 u1bTmp;
994 u32 ulRegRead;
995
996 OpMode = RT_OP_MODE_NO_LINK;
997 priv->ieee80211->SetHwRegHandler(dev, HW_VAR_MEDIA_STATUS, &OpMode);
998
999 #if 1
1000 if(!priv->ieee80211->bSupportRemoteWakeUp)
1001 {
1002 u1bTmp = 0x0; // disable tx/rx. In 8185 we write 0x10 (Reset bit), but here we make reference to WMAC and wirte 0x0. 2006.11.21 Emily
1003 //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_COMMAND, &u1bTmp ); // Using HW_VAR_COMMAND instead of writing CMDR directly. Rewrited by Annie, 2006-04-07.
1004 write_nic_byte(dev, CMDR, u1bTmp);
1005 }
1006 #else
1007 cmd=read_nic_byte(dev,CMDR);
1008 write_nic_byte(dev, CMDR, cmd &~ (CR_TE|CR_RE));
1009 #endif
1010
1011 mdelay(20);
1012
1013 if(!reset)
1014 {
1015 //PlatformStallExecution(150000);
1016 mdelay(150);
1017
1018 #ifdef RTL8192E
1019 priv->bHwRfOffAction = 2;
1020 #endif
1021
1022 //
1023 // Call MgntActSet_RF_State instead to prevent RF config race condition.
1024 // By Bruce, 2008-01-17.
1025 //
1026 if(!priv->ieee80211->bSupportRemoteWakeUp)
1027 {
1028 //MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_INIT);
1029 //MgntActSet_RF_State(Adapter, eRfOff, Adapter->MgntInfo.RfOffReason);
1030 //if(Adapter->HardwareType == HARDWARE_TYPE_RTL8190P)
1031
1032 PHY_SetRtl8192eRfOff(dev);
1033
1034 // 2006.11.30. System reset bit
1035 //priv->ieee80211->GetHwRegHandler(dev, HW_VAR_CPU_RST, (u32*)(&ulRegRead) );
1036 ulRegRead = read_nic_dword(dev,CPU_GEN);
1037 ulRegRead|=CPU_GEN_SYSTEM_RESET;
1038 //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_CPU_RST, &ulRegRead);
1039 write_nic_dword(dev,CPU_GEN, ulRegRead);
1040 }
1041 else
1042 {
1043 //2008.06.03 for WOL
1044 write_nic_dword(dev, WFCRC0, 0xffffffff);
1045 write_nic_dword(dev, WFCRC1, 0xffffffff);
1046 write_nic_dword(dev, WFCRC2, 0xffffffff);
1047
1048 //Write PMR register
1049 write_nic_byte(dev, PMR, 0x5);
1050 //Disable tx, enanble rx
1051 write_nic_byte(dev, MacBlkCtrl, 0xa);
1052 }
1053 }
1054
1055 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
1056 skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
1057 }
1058 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
1059 skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
1060 }
1061
1062 skb_queue_purge(&priv->skb_queue);
1063 }
1064
1065 static const u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
1066 inline u16 rtl8192_rate2rate(short rate)
1067 {
1068 if (rate >11) return 0;
1069 return rtl_rate[rate];
1070 }
1071
1072 static void rtl8192_data_hard_stop(struct net_device *dev)
1073 {
1074 //FIXME !!
1075 #if 0
1076 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1077 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1078 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1079 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1080 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1081 #endif
1082 }
1083
1084
1085 static void rtl8192_data_hard_resume(struct net_device *dev)
1086 {
1087 // FIXME !!
1088 #if 0
1089 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1090 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1091 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1092 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1093 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1094 #endif
1095 }
1096
1097 /*
1098 * this function TX data frames when the ieee80211 stack requires this.
1099 * It checks also if we need to stop the ieee tx queue, eventually do it
1100 */
1101 static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1102 {
1103 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1104 int ret;
1105 //unsigned long flags;
1106 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1107 u8 queue_index = tcb_desc->queue_index;
1108 /* shall not be referred by command packet */
1109 assert(queue_index != TXCMD_QUEUE);
1110
1111 if (priv->bHwRadioOff ||(!priv->up))
1112 {
1113 kfree_skb(skb);
1114 return;
1115 }
1116
1117 //spin_lock_irqsave(&priv->tx_lock,flags);
1118
1119 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1120 #if 0
1121 tcb_desc->RATRIndex = 7;
1122 tcb_desc->bTxDisableRateFallBack = 1;
1123 tcb_desc->bTxUseDriverAssingedRate = 1;
1124 tcb_desc->bTxEnableFwCalcDur = 1;
1125 #endif
1126 skb_push(skb, priv->ieee80211->tx_headroom);
1127 ret = rtl8192_tx(dev, skb);
1128 if(ret != 0) {
1129 kfree_skb(skb);
1130 };
1131
1132 //
1133 if(queue_index!=MGNT_QUEUE) {
1134 priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1135 priv->ieee80211->stats.tx_packets++;
1136 }
1137
1138 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1139
1140 // return ret;
1141 }
1142
1143 /*
1144 * This is a rough attempt to TX a frame
1145 * This is called by the ieee 80211 stack to TX management frames.
1146 * If the ring is full packet are dropped (for data frame the queue
1147 * is stopped before this can happen).
1148 */
1149 static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
1150 {
1151 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1152
1153
1154 int ret;
1155 //unsigned long flags;
1156 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1157 u8 queue_index = tcb_desc->queue_index;
1158
1159 if(queue_index != TXCMD_QUEUE){
1160 if (priv->bHwRadioOff ||(!priv->up))
1161 {
1162 kfree_skb(skb);
1163 return 0;
1164 }
1165 }
1166
1167 //spin_lock_irqsave(&priv->tx_lock,flags);
1168
1169 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1170 if(queue_index == TXCMD_QUEUE) {
1171 // skb_push(skb, USB_HWDESC_HEADER_LEN);
1172 rtl819xE_tx_cmd(dev, skb);
1173 ret = 0;
1174 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1175 return ret;
1176 } else {
1177 // RT_TRACE(COMP_SEND, "To send management packet\n");
1178 tcb_desc->RATRIndex = 7;
1179 tcb_desc->bTxDisableRateFallBack = 1;
1180 tcb_desc->bTxUseDriverAssingedRate = 1;
1181 tcb_desc->bTxEnableFwCalcDur = 1;
1182 skb_push(skb, priv->ieee80211->tx_headroom);
1183 ret = rtl8192_tx(dev, skb);
1184 if(ret != 0) {
1185 kfree_skb(skb);
1186 };
1187 }
1188
1189 // priv->ieee80211->stats.tx_bytes+=skb->len;
1190 // priv->ieee80211->stats.tx_packets++;
1191
1192 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1193
1194 return ret;
1195
1196 }
1197
1198
1199 static void rtl8192_tx_isr(struct net_device *dev, int prio)
1200 {
1201 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1202
1203 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1204
1205 while (skb_queue_len(&ring->queue)) {
1206 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1207 struct sk_buff *skb;
1208
1209 /* beacon packet will only use the first descriptor defaultly,
1210 * and the OWN may not be cleared by the hardware
1211 * */
1212 if(prio != BEACON_QUEUE) {
1213 if(entry->OWN)
1214 return;
1215 ring->idx = (ring->idx + 1) % ring->entries;
1216 }
1217
1218 skb = __skb_dequeue(&ring->queue);
1219 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1220 skb->len, PCI_DMA_TODEVICE);
1221
1222 kfree_skb(skb);
1223 }
1224 if (prio == MGNT_QUEUE){
1225 if (priv->ieee80211->ack_tx_to_ieee){
1226 if (rtl8192_is_tx_queue_empty(dev)){
1227 priv->ieee80211->ack_tx_to_ieee = 0;
1228 ieee80211_ps_tx_ack(priv->ieee80211, 1);
1229 }
1230 }
1231 }
1232
1233 if(prio != BEACON_QUEUE) {
1234 /* try to deal with the pending packets */
1235 tasklet_schedule(&priv->irq_tx_tasklet);
1236 }
1237
1238 }
1239
1240 static void rtl8192_stop_beacon(struct net_device *dev)
1241 {
1242 }
1243
1244 static void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
1245 {
1246 struct r8192_priv *priv = ieee80211_priv(dev);
1247 struct ieee80211_network *net;
1248 u8 i=0, basic_rate = 0;
1249 net = & priv->ieee80211->current_network;
1250
1251 for (i=0; i<net->rates_len; i++)
1252 {
1253 basic_rate = net->rates[i]&0x7f;
1254 switch(basic_rate)
1255 {
1256 case MGN_1M: *rate_config |= RRSR_1M; break;
1257 case MGN_2M: *rate_config |= RRSR_2M; break;
1258 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1259 case MGN_11M: *rate_config |= RRSR_11M; break;
1260 case MGN_6M: *rate_config |= RRSR_6M; break;
1261 case MGN_9M: *rate_config |= RRSR_9M; break;
1262 case MGN_12M: *rate_config |= RRSR_12M; break;
1263 case MGN_18M: *rate_config |= RRSR_18M; break;
1264 case MGN_24M: *rate_config |= RRSR_24M; break;
1265 case MGN_36M: *rate_config |= RRSR_36M; break;
1266 case MGN_48M: *rate_config |= RRSR_48M; break;
1267 case MGN_54M: *rate_config |= RRSR_54M; break;
1268 }
1269 }
1270 for (i=0; i<net->rates_ex_len; i++)
1271 {
1272 basic_rate = net->rates_ex[i]&0x7f;
1273 switch(basic_rate)
1274 {
1275 case MGN_1M: *rate_config |= RRSR_1M; break;
1276 case MGN_2M: *rate_config |= RRSR_2M; break;
1277 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1278 case MGN_11M: *rate_config |= RRSR_11M; break;
1279 case MGN_6M: *rate_config |= RRSR_6M; break;
1280 case MGN_9M: *rate_config |= RRSR_9M; break;
1281 case MGN_12M: *rate_config |= RRSR_12M; break;
1282 case MGN_18M: *rate_config |= RRSR_18M; break;
1283 case MGN_24M: *rate_config |= RRSR_24M; break;
1284 case MGN_36M: *rate_config |= RRSR_36M; break;
1285 case MGN_48M: *rate_config |= RRSR_48M; break;
1286 case MGN_54M: *rate_config |= RRSR_54M; break;
1287 }
1288 }
1289 }
1290
1291
1292 #define SHORT_SLOT_TIME 9
1293 #define NON_SHORT_SLOT_TIME 20
1294
1295 static void rtl8192_update_cap(struct net_device* dev, u16 cap)
1296 {
1297 u32 tmp = 0;
1298 struct r8192_priv *priv = ieee80211_priv(dev);
1299 struct ieee80211_network *net = &priv->ieee80211->current_network;
1300 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1301 tmp = priv->basic_rate;
1302 if (priv->short_preamble)
1303 tmp |= BRSR_AckShortPmb;
1304 write_nic_dword(dev, RRSR, tmp);
1305
1306 if (net->mode & (IEEE_G|IEEE_N_24G))
1307 {
1308 u8 slot_time = 0;
1309 if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
1310 {//short slot time
1311 slot_time = SHORT_SLOT_TIME;
1312 }
1313 else //long slot time
1314 slot_time = NON_SHORT_SLOT_TIME;
1315 priv->slot_time = slot_time;
1316 write_nic_byte(dev, SLOT_TIME, slot_time);
1317 }
1318
1319 }
1320
1321 static void rtl8192_net_update(struct net_device *dev)
1322 {
1323
1324 struct r8192_priv *priv = ieee80211_priv(dev);
1325 struct ieee80211_network *net;
1326 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1327 u16 rate_config = 0;
1328 net = &priv->ieee80211->current_network;
1329 //update Basic rate: RR, BRSR
1330 rtl8192_config_rate(dev, &rate_config);
1331 // 2007.01.16, by Emily
1332 // Select RRSR (in Legacy-OFDM and CCK)
1333 // For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate.
1334 // We do not use other rates.
1335 priv->basic_rate = rate_config &= 0x15f;
1336 //BSSID
1337 write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
1338 write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
1339 #if 0
1340 //MSR
1341 rtl8192_update_msr(dev);
1342 #endif
1343
1344
1345 // rtl8192_update_cap(dev, net->capability);
1346 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1347 {
1348 write_nic_word(dev, ATIMWND, 2);
1349 write_nic_word(dev, BCN_DMATIME, 256);
1350 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1351 // write_nic_word(dev, BcnIntTime, 100);
1352 //BIT15 of BCN_DRV_EARLY_INT will indicate whether software beacon or hw beacon is applied.
1353 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
1354 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1355
1356 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1357 // TODO: BcnIFS may required to be changed on ASIC
1358 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1359
1360 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1361 }
1362
1363
1364 }
1365
1366 void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1367 {
1368 struct r8192_priv *priv = ieee80211_priv(dev);
1369 struct rtl8192_tx_ring *ring;
1370 tx_desc_819x_pci *entry;
1371 unsigned int idx;
1372 dma_addr_t mapping;
1373 cb_desc *tcb_desc;
1374 unsigned long flags;
1375
1376 ring = &priv->tx_ring[TXCMD_QUEUE];
1377 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1378
1379 spin_lock_irqsave(&priv->irq_th_lock,flags);
1380 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1381 entry = &ring->desc[idx];
1382
1383 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1384 memset(entry,0,12);
1385 entry->LINIP = tcb_desc->bLastIniPkt;
1386 entry->FirstSeg = 1;//first segment
1387 entry->LastSeg = 1; //last segment
1388 if(tcb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) {
1389 entry->CmdInit = DESC_PACKET_TYPE_INIT;
1390 } else {
1391 entry->CmdInit = DESC_PACKET_TYPE_NORMAL;
1392 entry->Offset = sizeof(TX_FWINFO_8190PCI) + 8;
1393 entry->PktSize = (u16)(tcb_desc->pkt_size + entry->Offset);
1394 entry->QueueSelect = QSLT_CMD;
1395 entry->TxFWInfoSize = 0x08;
1396 entry->RATid = (u8)DESC_PACKET_TYPE_INIT;
1397 }
1398 entry->TxBufferSize = skb->len;
1399 entry->TxBuffAddr = cpu_to_le32(mapping);
1400 entry->OWN = 1;
1401
1402 #ifdef JOHN_DUMP_TXDESC
1403 { int i;
1404 tx_desc_819x_pci *entry1 = &ring->desc[0];
1405 unsigned int *ptr= (unsigned int *)entry1;
1406 printk("<Tx descriptor>:\n");
1407 for (i = 0; i < 8; i++)
1408 printk("%8x ", ptr[i]);
1409 printk("\n");
1410 }
1411 #endif
1412 __skb_queue_tail(&ring->queue, skb);
1413 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1414
1415 write_nic_byte(dev, TPPoll, TPPoll_CQ);
1416
1417 return;
1418 }
1419
1420 /*
1421 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1422 * in TxFwInfo data structure
1423 */
1424 static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1425 {
1426 u8 QueueSelect = 0x0; //defualt set to
1427
1428 switch(QueueID) {
1429 case BE_QUEUE:
1430 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority;
1431 break;
1432
1433 case BK_QUEUE:
1434 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority;
1435 break;
1436
1437 case VO_QUEUE:
1438 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority;
1439 break;
1440
1441 case VI_QUEUE:
1442 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority;
1443 break;
1444 case MGNT_QUEUE:
1445 QueueSelect = QSLT_MGNT;
1446 break;
1447
1448 case BEACON_QUEUE:
1449 QueueSelect = QSLT_BEACON;
1450 break;
1451
1452 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
1453 // TODO: Remove Assertions
1454 //#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
1455 case TXCMD_QUEUE:
1456 QueueSelect = QSLT_CMD;
1457 break;
1458 //#endif
1459 case HIGH_QUEUE:
1460 //QueueSelect = QSLT_HIGH;
1461 //break;
1462
1463 default:
1464 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
1465 break;
1466 }
1467 return QueueSelect;
1468 }
1469
1470 static u8 MRateToHwRate8190Pci(u8 rate)
1471 {
1472 u8 ret = DESC90_RATE1M;
1473
1474 switch(rate) {
1475 case MGN_1M: ret = DESC90_RATE1M; break;
1476 case MGN_2M: ret = DESC90_RATE2M; break;
1477 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1478 case MGN_11M: ret = DESC90_RATE11M; break;
1479 case MGN_6M: ret = DESC90_RATE6M; break;
1480 case MGN_9M: ret = DESC90_RATE9M; break;
1481 case MGN_12M: ret = DESC90_RATE12M; break;
1482 case MGN_18M: ret = DESC90_RATE18M; break;
1483 case MGN_24M: ret = DESC90_RATE24M; break;
1484 case MGN_36M: ret = DESC90_RATE36M; break;
1485 case MGN_48M: ret = DESC90_RATE48M; break;
1486 case MGN_54M: ret = DESC90_RATE54M; break;
1487
1488 // HT rate since here
1489 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1490 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1491 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1492 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1493 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1494 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1495 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1496 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1497 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1498 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1499 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1500 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1501 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1502 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1503 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1504 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1505 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1506
1507 default: break;
1508 }
1509 return ret;
1510 }
1511
1512
1513 static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
1514 {
1515 u8 tmp_Short;
1516
1517 tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
1518
1519 if(TxHT==1 && TxRate != DESC90_RATEMCS15)
1520 tmp_Short = 0;
1521
1522 return tmp_Short;
1523 }
1524
1525 /*
1526 * The tx procedure is just as following,
1527 * skb->cb will contain all the following information,
1528 * priority, morefrag, rate, &dev.
1529 */
1530 short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
1531 {
1532 struct r8192_priv *priv = ieee80211_priv(dev);
1533 struct rtl8192_tx_ring *ring;
1534 unsigned long flags;
1535 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1536 tx_desc_819x_pci *pdesc = NULL;
1537 TX_FWINFO_8190PCI *pTxFwInfo = NULL;
1538 dma_addr_t mapping;
1539 bool multi_addr=false,broad_addr=false,uni_addr=false;
1540 u8* pda_addr = NULL;
1541 int idx;
1542
1543 if(priv->bdisable_nic){
1544 RT_TRACE(COMP_ERR,"%s: ERR!! Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n", __FUNCTION__, skb->len, tcb_desc->queue_index);
1545 return skb->len;
1546 }
1547
1548 #ifdef ENABLE_LPS
1549 priv->ieee80211->bAwakePktSent = true;
1550 #endif
1551
1552 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1553 /* collect the tx packets statitcs */
1554 pda_addr = ((u8*)skb->data) + sizeof(TX_FWINFO_8190PCI);
1555 if(is_multicast_ether_addr(pda_addr))
1556 multi_addr = true;
1557 else if(is_broadcast_ether_addr(pda_addr))
1558 broad_addr = true;
1559 else
1560 uni_addr = true;
1561
1562 if(uni_addr)
1563 priv->stats.txbytesunicast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1564 else if(multi_addr)
1565 priv->stats.txbytesmulticast +=(u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1566 else
1567 priv->stats.txbytesbroadcast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1568
1569 /* fill tx firmware */
1570 pTxFwInfo = (PTX_FWINFO_8190PCI)skb->data;
1571 memset(pTxFwInfo,0,sizeof(TX_FWINFO_8190PCI));
1572 pTxFwInfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
1573 pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)tcb_desc->data_rate);
1574 pTxFwInfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1575 pTxFwInfo->Short = QueryIsShort(pTxFwInfo->TxHT, pTxFwInfo->TxRate, tcb_desc);
1576
1577 /* Aggregation related */
1578 if(tcb_desc->bAMPDUEnable) {
1579 pTxFwInfo->AllowAggregation = 1;
1580 pTxFwInfo->RxMF = tcb_desc->ampdu_factor;
1581 pTxFwInfo->RxAMD = tcb_desc->ampdu_density;
1582 } else {
1583 pTxFwInfo->AllowAggregation = 0;
1584 pTxFwInfo->RxMF = 0;
1585 pTxFwInfo->RxAMD = 0;
1586 }
1587
1588 //
1589 // Protection mode related
1590 //
1591 pTxFwInfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
1592 pTxFwInfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
1593 pTxFwInfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
1594 pTxFwInfo->RtsHT= (tcb_desc->rts_rate&0x80)?1:0;
1595 pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1596 pTxFwInfo->RtsBandwidth = 0;
1597 pTxFwInfo->RtsSubcarrier = tcb_desc->RTSSC;
1598 pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):(tcb_desc->bRTSUseShortGI?1:0);
1599 //
1600 // Set Bandwidth and sub-channel settings.
1601 //
1602 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1603 {
1604 if(tcb_desc->bPacketBW)
1605 {
1606 pTxFwInfo->TxBandwidth = 1;
1607 #ifdef RTL8190P
1608 pTxFwInfo->TxSubCarrier = 3;
1609 #else
1610 pTxFwInfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode, cosa 04012008
1611 #endif
1612 }
1613 else
1614 {
1615 pTxFwInfo->TxBandwidth = 0;
1616 pTxFwInfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1617 }
1618 } else {
1619 pTxFwInfo->TxBandwidth = 0;
1620 pTxFwInfo->TxSubCarrier = 0;
1621 }
1622
1623 if (0)
1624 {
1625 /* 2007/07/25 MH Copy current TX FW info.*/
1626 memcpy((void*)(&Tmp_TxFwInfo), (void*)(pTxFwInfo), sizeof(TX_FWINFO_8190PCI));
1627 printk("&&&&&&&&&&&&&&&&&&&&&&====>print out fwinf\n");
1628 printk("===>enable fwcacl:%d\n", Tmp_TxFwInfo.EnableCPUDur);
1629 printk("===>RTS STBC:%d\n", Tmp_TxFwInfo.RtsSTBC);
1630 printk("===>RTS Subcarrier:%d\n", Tmp_TxFwInfo.RtsSubcarrier);
1631 printk("===>Allow Aggregation:%d\n", Tmp_TxFwInfo.AllowAggregation);
1632 printk("===>TX HT bit:%d\n", Tmp_TxFwInfo.TxHT);
1633 printk("===>Tx rate:%d\n", Tmp_TxFwInfo.TxRate);
1634 printk("===>Received AMPDU Density:%d\n", Tmp_TxFwInfo.RxAMD);
1635 printk("===>Received MPDU Factor:%d\n", Tmp_TxFwInfo.RxMF);
1636 printk("===>TxBandwidth:%d\n", Tmp_TxFwInfo.TxBandwidth);
1637 printk("===>TxSubCarrier:%d\n", Tmp_TxFwInfo.TxSubCarrier);
1638
1639 printk("<=====**********************out of print\n");
1640
1641 }
1642 spin_lock_irqsave(&priv->irq_th_lock,flags);
1643 ring = &priv->tx_ring[tcb_desc->queue_index];
1644 if (tcb_desc->queue_index != BEACON_QUEUE) {
1645 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1646 } else {
1647 idx = 0;
1648 }
1649
1650 pdesc = &ring->desc[idx];
1651 if((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
1652 RT_TRACE(COMP_ERR,"No more TX desc@%d, ring->idx = %d,idx = %d,%x",
1653 tcb_desc->queue_index,ring->idx, idx,skb->len);
1654 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1655 return skb->len;
1656 }
1657
1658 /* fill tx descriptor */
1659 memset((u8*)pdesc,0,12);
1660 /*DWORD 0*/
1661 pdesc->LINIP = 0;
1662 pdesc->CmdInit = 1;
1663 pdesc->Offset = sizeof(TX_FWINFO_8190PCI) + 8; //We must add 8!! Emily
1664 pdesc->PktSize = (u16)skb->len-sizeof(TX_FWINFO_8190PCI);
1665
1666 /*DWORD 1*/
1667 pdesc->SecCAMID= 0;
1668 pdesc->RATid = tcb_desc->RATRIndex;
1669
1670
1671 pdesc->NoEnc = 1;
1672 pdesc->SecType = 0x0;
1673 if (tcb_desc->bHwSec) {
1674 switch (priv->ieee80211->pairwise_key_type) {
1675 case KEY_TYPE_WEP40:
1676 case KEY_TYPE_WEP104:
1677 pdesc->SecType = 0x1;
1678 pdesc->NoEnc = 0;
1679 break;
1680 case KEY_TYPE_TKIP:
1681 pdesc->SecType = 0x2;
1682 pdesc->NoEnc = 0;
1683 break;
1684 case KEY_TYPE_CCMP:
1685 pdesc->SecType = 0x3;
1686 pdesc->NoEnc = 0;
1687 break;
1688 case KEY_TYPE_NA:
1689 pdesc->SecType = 0x0;
1690 pdesc->NoEnc = 1;
1691 break;
1692 }
1693 }
1694
1695 //
1696 // Set Packet ID
1697 //
1698 pdesc->PktId = 0x0;
1699
1700 pdesc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1701 pdesc->TxFWInfoSize = sizeof(TX_FWINFO_8190PCI);
1702
1703 pdesc->DISFB = tcb_desc->bTxDisableRateFallBack;
1704 pdesc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1705
1706 pdesc->FirstSeg =1;
1707 pdesc->LastSeg = 1;
1708 pdesc->TxBufferSize = skb->len;
1709
1710 pdesc->TxBuffAddr = cpu_to_le32(mapping);
1711 __skb_queue_tail(&ring->queue, skb);
1712 pdesc->OWN = 1;
1713 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1714 dev->trans_start = jiffies;
1715 write_nic_word(dev,TPPoll,0x01<<tcb_desc->queue_index);
1716 return 0;
1717 }
1718
1719 static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
1720 {
1721 struct r8192_priv *priv = ieee80211_priv(dev);
1722 rx_desc_819x_pci *entry = NULL;
1723 int i;
1724
1725 priv->rx_ring = pci_alloc_consistent(priv->pdev,
1726 sizeof(*priv->rx_ring) * priv->rxringcount, &priv->rx_ring_dma);
1727
1728 if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) {
1729 RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n");
1730 return -ENOMEM;
1731 }
1732
1733 memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * priv->rxringcount);
1734 priv->rx_idx = 0;
1735
1736 for (i = 0; i < priv->rxringcount; i++) {
1737 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
1738 dma_addr_t *mapping;
1739 entry = &priv->rx_ring[i];
1740 if (!skb)
1741 return 0;
1742 priv->rx_buf[i] = skb;
1743 mapping = (dma_addr_t *)skb->cb;
1744 *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb),
1745 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1746
1747 entry->BufferAddress = cpu_to_le32(*mapping);
1748
1749 entry->Length = priv->rxbuffersize;
1750 entry->OWN = 1;
1751 }
1752
1753 entry->EOR = 1;
1754 return 0;
1755 }
1756
1757 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
1758 unsigned int prio, unsigned int entries)
1759 {
1760 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1761 tx_desc_819x_pci *ring;
1762 dma_addr_t dma;
1763 int i;
1764
1765 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
1766 if (!ring || (unsigned long)ring & 0xFF) {
1767 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio);
1768 return -ENOMEM;
1769 }
1770
1771 memset(ring, 0, sizeof(*ring)*entries);
1772 priv->tx_ring[prio].desc = ring;
1773 priv->tx_ring[prio].dma = dma;
1774 priv->tx_ring[prio].idx = 0;
1775 priv->tx_ring[prio].entries = entries;
1776 skb_queue_head_init(&priv->tx_ring[prio].queue);
1777
1778 for (i = 0; i < entries; i++)
1779 ring[i].NextDescAddress =
1780 cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring));
1781
1782 return 0;
1783 }
1784
1785
1786 static short rtl8192_pci_initdescring(struct net_device *dev)
1787 {
1788 u32 ret;
1789 int i;
1790 struct r8192_priv *priv = ieee80211_priv(dev);
1791
1792 ret = rtl8192_alloc_rx_desc_ring(dev);
1793 if (ret) {
1794 return ret;
1795 }
1796
1797
1798 /* general process for other queue */
1799 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1800 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
1801 if (ret)
1802 goto err_free_rings;
1803 }
1804
1805 #if 0
1806 /* specific process for hardware beacon process */
1807 ret = rtl8192_alloc_tx_desc_ring(dev, MAX_TX_QUEUE_COUNT - 1, 2);
1808 if (ret)
1809 goto err_free_rings;
1810 #endif
1811
1812 return 0;
1813
1814 err_free_rings:
1815 rtl8192_free_rx_ring(dev);
1816 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
1817 if (priv->tx_ring[i].desc)
1818 rtl8192_free_tx_ring(dev, i);
1819 return 1;
1820 }
1821
1822 static void rtl8192_pci_resetdescring(struct net_device *dev)
1823 {
1824 struct r8192_priv *priv = ieee80211_priv(dev);
1825 int i;
1826
1827 /* force the rx_idx to the first one */
1828 if(priv->rx_ring) {
1829 rx_desc_819x_pci *entry = NULL;
1830 for (i = 0; i < priv->rxringcount; i++) {
1831 entry = &priv->rx_ring[i];
1832 entry->OWN = 1;
1833 }
1834 priv->rx_idx = 0;
1835 }
1836
1837 /* after reset, release previous pending packet, and force the
1838 * tx idx to the first one */
1839 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1840 if (priv->tx_ring[i].desc) {
1841 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
1842
1843 while (skb_queue_len(&ring->queue)) {
1844 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1845 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1846
1847 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1848 skb->len, PCI_DMA_TODEVICE);
1849 kfree_skb(skb);
1850 ring->idx = (ring->idx + 1) % ring->entries;
1851 }
1852 ring->idx = 0;
1853 }
1854 }
1855 }
1856
1857 static void rtl8192_link_change(struct net_device *dev)
1858 {
1859 struct r8192_priv *priv = ieee80211_priv(dev);
1860 struct ieee80211_device* ieee = priv->ieee80211;
1861 //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval);
1862 if (ieee->state == IEEE80211_LINKED)
1863 {
1864 rtl8192_net_update(dev);
1865 rtl8192_update_ratr_table(dev);
1866 #if 1
1867 //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08
1868 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
1869 EnableHWSecurityConfig8192(dev);
1870 #endif
1871 }
1872 else
1873 {
1874 write_nic_byte(dev, 0x173, 0);
1875 }
1876 /*update timing params*/
1877 //rtl8192_set_chan(dev, priv->chan);
1878 //MSR
1879 rtl8192_update_msr(dev);
1880
1881 // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have
1882 // // To set CBSSID bit when link with any AP or STA.
1883 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
1884 {
1885 u32 reg = 0;
1886 reg = read_nic_dword(dev, RCR);
1887 if (priv->ieee80211->state == IEEE80211_LINKED)
1888 priv->ReceiveConfig = reg |= RCR_CBSSID;
1889 else
1890 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
1891 write_nic_dword(dev, RCR, reg);
1892 }
1893 }
1894
1895
1896 static const struct ieee80211_qos_parameters def_qos_parameters = {
1897 {3,3,3,3},/* cw_min */
1898 {7,7,7,7},/* cw_max */
1899 {2,2,2,2},/* aifs */
1900 {0,0,0,0},/* flags */
1901 {0,0,0,0} /* tx_op_limit */
1902 };
1903
1904 static void rtl8192_update_beacon(struct work_struct * work)
1905 {
1906 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
1907 struct net_device *dev = priv->ieee80211->dev;
1908 struct ieee80211_device* ieee = priv->ieee80211;
1909 struct ieee80211_network* net = &ieee->current_network;
1910
1911 if (ieee->pHTInfo->bCurrentHTSupport)
1912 HTUpdateSelfAndPeerSetting(ieee, net);
1913 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
1914 rtl8192_update_cap(dev, net->capability);
1915 }
1916
1917 /*
1918 * background support to run QoS activate functionality
1919 */
1920 static const int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
1921 static void rtl8192_qos_activate(struct work_struct * work)
1922 {
1923 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
1924 struct net_device *dev = priv->ieee80211->dev;
1925 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
1926 u8 mode = priv->ieee80211->current_network.mode;
1927 u8 u1bAIFS;
1928 u32 u4bAcParam;
1929 int i;
1930
1931 mutex_lock(&priv->mutex);
1932 if(priv->ieee80211->state != IEEE80211_LINKED)
1933 goto success;
1934 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
1935 /* It better set slot time at first */
1936 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
1937 /* update the ac parameter to related registers */
1938 for(i = 0; i < QOS_QUEUE_NUM; i++) {
1939 //Mode G/A: slotTimeTimer = 9; Mode B: 20
1940 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
1941 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
1942 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
1943 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
1944 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
1945 //printk("===>u4bAcParam:%x, ", u4bAcParam);
1946 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
1947 //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
1948 }
1949
1950 success:
1951 mutex_unlock(&priv->mutex);
1952 }
1953
1954 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
1955 int active_network,
1956 struct ieee80211_network *network)
1957 {
1958 int ret = 0;
1959 u32 size = sizeof(struct ieee80211_qos_parameters);
1960
1961 if(priv->ieee80211->state !=IEEE80211_LINKED)
1962 return ret;
1963
1964 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
1965 return ret;
1966
1967 if (network->flags & NETWORK_HAS_QOS_MASK) {
1968 if (active_network &&
1969 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
1970 network->qos_data.active = network->qos_data.supported;
1971
1972 if ((network->qos_data.active == 1) && (active_network == 1) &&
1973 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
1974 (network->qos_data.old_param_count !=
1975 network->qos_data.param_count)) {
1976 network->qos_data.old_param_count =
1977 network->qos_data.param_count;
1978 queue_work(priv->priv_wq, &priv->qos_activate);
1979 RT_TRACE (COMP_QOS, "QoS parameters change call "
1980 "qos_activate\n");
1981 }
1982 } else {
1983 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
1984 &def_qos_parameters, size);
1985
1986 if ((network->qos_data.active == 1) && (active_network == 1)) {
1987 queue_work(priv->priv_wq, &priv->qos_activate);
1988 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
1989 }
1990 network->qos_data.active = 0;
1991 network->qos_data.supported = 0;
1992 }
1993
1994 return 0;
1995 }
1996
1997 /* handle manage frame frame beacon and probe response */
1998 static int rtl8192_handle_beacon(struct net_device * dev,
1999 struct ieee80211_beacon * beacon,
2000 struct ieee80211_network * network)
2001 {
2002 struct r8192_priv *priv = ieee80211_priv(dev);
2003
2004 rtl8192_qos_handle_probe_response(priv,1,network);
2005
2006 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
2007 return 0;
2008
2009 }
2010
2011 /*
2012 * handling the beaconing responses. if we get different QoS setting
2013 * off the network from the associated setting, adjust the QoS setting
2014 */
2015 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
2016 struct ieee80211_network *network)
2017 {
2018 int ret = 0;
2019 unsigned long flags;
2020 u32 size = sizeof(struct ieee80211_qos_parameters);
2021 int set_qos_param = 0;
2022
2023 if ((priv == NULL) || (network == NULL))
2024 return ret;
2025
2026 if(priv->ieee80211->state !=IEEE80211_LINKED)
2027 return ret;
2028
2029 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2030 return ret;
2031
2032 spin_lock_irqsave(&priv->ieee80211->lock, flags);
2033 if(network->flags & NETWORK_HAS_QOS_PARAMETERS) {
2034 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2035 &network->qos_data.parameters,
2036 sizeof(struct ieee80211_qos_parameters));
2037 priv->ieee80211->current_network.qos_data.active = 1;
2038 #if 0
2039 if((priv->ieee80211->current_network.qos_data.param_count !=
2040 network->qos_data.param_count))
2041 #endif
2042 {
2043 set_qos_param = 1;
2044 /* update qos parameter for current network */
2045 priv->ieee80211->current_network.qos_data.old_param_count =
2046 priv->ieee80211->current_network.qos_data.param_count;
2047 priv->ieee80211->current_network.qos_data.param_count =
2048 network->qos_data.param_count;
2049 }
2050 } else {
2051 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2052 &def_qos_parameters, size);
2053 priv->ieee80211->current_network.qos_data.active = 0;
2054 priv->ieee80211->current_network.qos_data.supported = 0;
2055 set_qos_param = 1;
2056 }
2057
2058 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
2059
2060 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active);
2061 if (set_qos_param == 1)
2062 queue_work(priv->priv_wq, &priv->qos_activate);
2063
2064 return ret;
2065 }
2066
2067
2068 static int rtl8192_handle_assoc_response(struct net_device *dev,
2069 struct ieee80211_assoc_response_frame *resp,
2070 struct ieee80211_network *network)
2071 {
2072 struct r8192_priv *priv = ieee80211_priv(dev);
2073 rtl8192_qos_association_resp(priv, network);
2074 return 0;
2075 }
2076
2077
2078 /* updateRATRTabel for MCS only. Basic rate is not implemented. */
2079 static void rtl8192_update_ratr_table(struct net_device* dev)
2080 {
2081 struct r8192_priv* priv = ieee80211_priv(dev);
2082 struct ieee80211_device* ieee = priv->ieee80211;
2083 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
2084 u32 ratr_value = 0;
2085 u8 rate_index = 0;
2086
2087 rtl8192_config_rate(dev, (u16*)(&ratr_value));
2088 ratr_value |= (*(u16*)(pMcsRate)) << 12;
2089
2090 switch (ieee->mode)
2091 {
2092 case IEEE_A:
2093 ratr_value &= 0x00000FF0;
2094 break;
2095 case IEEE_B:
2096 ratr_value &= 0x0000000F;
2097 break;
2098 case IEEE_G:
2099 ratr_value &= 0x00000FF7;
2100 break;
2101 case IEEE_N_24G:
2102 case IEEE_N_5G:
2103 if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
2104 ratr_value &= 0x0007F007;
2105 else{
2106 if (priv->rf_type == RF_1T2R)
2107 ratr_value &= 0x000FF007;
2108 else
2109 ratr_value &= 0x0F81F007;
2110 }
2111 break;
2112 default:
2113 break;
2114 }
2115 ratr_value &= 0x0FFFFFFF;
2116 if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
2117 ratr_value |= 0x80000000;
2118 }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
2119 ratr_value |= 0x80000000;
2120 }
2121 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
2122 write_nic_byte(dev, UFWP, 1);
2123 }
2124
2125 static bool GetNmodeSupportBySecCfg8190Pci(struct net_device*dev)
2126 {
2127 #if 1
2128
2129 struct r8192_priv *priv = ieee80211_priv(dev);
2130 struct ieee80211_device *ieee = priv->ieee80211;
2131 return !(ieee->rtllib_ap_sec_type &&
2132 (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP)));
2133 #else
2134 struct r8192_priv* priv = ieee80211_priv(dev);
2135 struct ieee80211_device* ieee = priv->ieee80211;
2136 int wpa_ie_len= ieee->wpa_ie_len;
2137 struct ieee80211_crypt_data* crypt;
2138 int encrypt;
2139
2140 crypt = ieee->crypt[ieee->tx_keyidx];
2141 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP")));
2142
2143 /* simply judge */
2144 if(encrypt && (wpa_ie_len == 0)) {
2145 /* wep encryption, no N mode setting */
2146 return false;
2147 // } else if((wpa_ie_len != 0)&&(memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) {
2148 } else if((wpa_ie_len != 0)) {
2149 /* parse pairwise key type */
2150 //if((pairwisekey = WEP40)||(pairwisekey = WEP104)||(pairwisekey = TKIP))
2151 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
2152 return true;
2153 else
2154 return false;
2155 } else {
2156 //RT_TRACE(COMP_ERR,"In %s The GroupEncAlgorithm is [4]\n",__FUNCTION__ );
2157 return true;
2158 }
2159
2160 return true;
2161 #endif
2162 }
2163
2164 static void rtl8192_refresh_supportrate(struct r8192_priv* priv)
2165 {
2166 struct ieee80211_device* ieee = priv->ieee80211;
2167 //we donot consider set support rate for ABG mode, only HT MCS rate is set here.
2168 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2169 {
2170 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
2171 //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16);
2172 //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16);
2173 }
2174 else
2175 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
2176 }
2177
2178 static u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
2179 {
2180 struct r8192_priv *priv = ieee80211_priv(dev);
2181 u8 ret = 0;
2182 switch(priv->rf_chip)
2183 {
2184 case RF_8225:
2185 case RF_8256:
2186 case RF_PSEUDO_11N:
2187 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
2188 break;
2189 case RF_8258:
2190 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
2191 break;
2192 default:
2193 ret = WIRELESS_MODE_B;
2194 break;
2195 }
2196 return ret;
2197 }
2198
2199 static void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
2200 {
2201 struct r8192_priv *priv = ieee80211_priv(dev);
2202 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
2203
2204 #if 1
2205 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
2206 {
2207 if(bSupportMode & WIRELESS_MODE_N_24G)
2208 {
2209 wireless_mode = WIRELESS_MODE_N_24G;
2210 }
2211 else if(bSupportMode & WIRELESS_MODE_N_5G)
2212 {
2213 wireless_mode = WIRELESS_MODE_N_5G;
2214 }
2215 else if((bSupportMode & WIRELESS_MODE_A))
2216 {
2217 wireless_mode = WIRELESS_MODE_A;
2218 }
2219 else if((bSupportMode & WIRELESS_MODE_G))
2220 {
2221 wireless_mode = WIRELESS_MODE_G;
2222 }
2223 else if((bSupportMode & WIRELESS_MODE_B))
2224 {
2225 wireless_mode = WIRELESS_MODE_B;
2226 }
2227 else{
2228 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
2229 wireless_mode = WIRELESS_MODE_B;
2230 }
2231 }
2232 #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
2233 ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting );
2234 #endif
2235 priv->ieee80211->mode = wireless_mode;
2236
2237 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
2238 priv->ieee80211->pHTInfo->bEnableHT = 1;
2239 else
2240 priv->ieee80211->pHTInfo->bEnableHT = 0;
2241 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
2242 rtl8192_refresh_supportrate(priv);
2243 #endif
2244
2245 }
2246
2247 static bool GetHalfNmodeSupportByAPs819xPci(struct net_device* dev)
2248 {
2249 struct r8192_priv* priv = ieee80211_priv(dev);
2250 struct ieee80211_device* ieee = priv->ieee80211;
2251
2252 return ieee->bHalfWirelessN24GMode;
2253 }
2254
2255 short rtl8192_is_tx_queue_empty(struct net_device *dev)
2256 {
2257 int i=0;
2258 struct r8192_priv *priv = ieee80211_priv(dev);
2259 for (i=0; i<=MGNT_QUEUE; i++)
2260 {
2261 if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) )
2262 continue;
2263 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){
2264 printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue));
2265 return 0;
2266 }
2267 }
2268 return 1;
2269 }
2270
2271 static void rtl8192_hw_sleep_down(struct net_device *dev)
2272 {
2273 struct r8192_priv *priv = ieee80211_priv(dev);
2274 unsigned long flags = 0;
2275
2276 spin_lock_irqsave(&priv->rf_ps_lock,flags);
2277 if (priv->RFChangeInProgress) {
2278 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2279 RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n");
2280 printk("rtl8192_hw_sleep_down(): RF Change in progress!\n");
2281 return;
2282 }
2283 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2284
2285 MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
2286 }
2287
2288 static void rtl8192_hw_sleep_wq (struct work_struct *work)
2289 {
2290 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
2291 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
2292 struct net_device *dev = ieee->dev;
2293
2294 rtl8192_hw_sleep_down(dev);
2295 }
2296
2297 static void rtl8192_hw_wakeup(struct net_device* dev)
2298 {
2299 struct r8192_priv *priv = ieee80211_priv(dev);
2300 unsigned long flags = 0;
2301
2302 spin_lock_irqsave(&priv->rf_ps_lock,flags);
2303 if (priv->RFChangeInProgress) {
2304 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2305 RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n");
2306 printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n");
2307 queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->hw_wakeup_wq,MSECS(10));//PowerSave is not supported if kernel version is below 2.6.20
2308 return;
2309 }
2310 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2311
2312 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);
2313 }
2314
2315 void rtl8192_hw_wakeup_wq (struct work_struct *work)
2316 {
2317 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
2318 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
2319 struct net_device *dev = ieee->dev;
2320 rtl8192_hw_wakeup(dev);
2321
2322 }
2323
2324 #define MIN_SLEEP_TIME 50
2325 #define MAX_SLEEP_TIME 10000
2326 static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
2327 {
2328 struct r8192_priv *priv = ieee80211_priv(dev);
2329
2330 u32 rb = jiffies;
2331 unsigned long flags;
2332
2333 spin_lock_irqsave(&priv->ps_lock,flags);
2334
2335 // Writing HW register with 0 equals to disable
2336 // the timer, that is not really what we want
2337 //
2338 tl -= MSECS(8+16+7);
2339
2340 // If the interval in witch we are requested to sleep is too
2341 // short then give up and remain awake
2342 // when we sleep after send null frame, the timer will be too short to sleep.
2343 //
2344 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2345 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2346 spin_unlock_irqrestore(&priv->ps_lock,flags);
2347 printk("too short to sleep::%x, %x, %lx\n",tl, rb, MSECS(MIN_SLEEP_TIME));
2348 return;
2349 }
2350
2351 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
2352 ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
2353 ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
2354 printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME));
2355 spin_unlock_irqrestore(&priv->ps_lock,flags);
2356 return;
2357 }
2358 {
2359 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
2360 queue_delayed_work(priv->ieee80211->wq,
2361 &priv->ieee80211->hw_wakeup_wq,tmp);
2362 //PowerSave not supported when kernel version less 2.6.20
2363 }
2364 queue_delayed_work(priv->ieee80211->wq,
2365 (void *)&priv->ieee80211->hw_sleep_wq,0);
2366 spin_unlock_irqrestore(&priv->ps_lock,flags);
2367
2368 }
2369
2370 static void rtl8192_init_priv_variable(struct net_device* dev)
2371 {
2372 struct r8192_priv *priv = ieee80211_priv(dev);
2373 u8 i;
2374 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
2375
2376 // Default Halt the NIC if RF is OFF.
2377 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC;
2378 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_CLK_REQ;
2379 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM;
2380 pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM;
2381 pPSC->bLeisurePs = true;
2382 pPSC->RegMaxLPSAwakeIntvl = 5;
2383 priv->bHwRadioOff = false;
2384
2385 priv->being_init_adapter = false;
2386 priv->txbuffsize = 1600;//1024;
2387 priv->txfwbuffersize = 4096;
2388 priv->txringcount = 64;//32;
2389 //priv->txbeaconcount = priv->txringcount;
2390 priv->txbeaconcount = 2;
2391 priv->rxbuffersize = 9100;//2048;//1024;
2392 priv->rxringcount = MAX_RX_COUNT;//64;
2393 priv->irq_enabled=0;
2394 priv->card_8192 = NIC_8192E;
2395 priv->rx_skb_complete = 1;
2396 priv->chan = 1; //set to channel 1
2397 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
2398 priv->RegChannelPlan = 0xf;
2399 priv->nrxAMPDU_size = 0;
2400 priv->nrxAMPDU_aggr_num = 0;
2401 priv->last_rxdesc_tsf_high = 0;
2402 priv->last_rxdesc_tsf_low = 0;
2403 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
2404 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2405 priv->ieee80211->ieee_up=0;
2406 priv->retry_rts = DEFAULT_RETRY_RTS;
2407 priv->retry_data = DEFAULT_RETRY_DATA;
2408 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
2409 priv->ieee80211->rate = 110; //11 mbps
2410 priv->ieee80211->short_slot = 1;
2411 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
2412 priv->bcck_in_ch14 = false;
2413 priv->bfsync_processing = false;
2414 priv->CCKPresentAttentuation = 0;
2415 priv->rfa_txpowertrackingindex = 0;
2416 priv->rfc_txpowertrackingindex = 0;
2417 priv->CckPwEnl = 6;
2418 priv->ScanDelay = 50;//for Scan TODO
2419 //added by amy for silent reset
2420 priv->ResetProgress = RESET_TYPE_NORESET;
2421 priv->bForcedSilentReset = 0;
2422 priv->bDisableNormalResetCheck = false;
2423 priv->force_reset = false;
2424 //added by amy for power save
2425 priv->RegRfOff = 0;
2426 priv->ieee80211->RfOffReason = 0;
2427 priv->RFChangeInProgress = false;
2428 priv->bHwRfOffAction = 0;
2429 priv->SetRFPowerStateInProgress = false;
2430 priv->ieee80211->PowerSaveControl.bInactivePs = true;
2431 priv->ieee80211->PowerSaveControl.bIPSModeBackup = false;
2432 //just for debug
2433 priv->txpower_checkcnt = 0;
2434 priv->thermal_readback_index =0;
2435 priv->txpower_tracking_callback_cnt = 0;
2436 priv->ccktxpower_adjustcnt_ch14 = 0;
2437 priv->ccktxpower_adjustcnt_not_ch14 = 0;
2438
2439 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2440 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2441 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2442 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2443 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;/* |
2444 IEEE_SOFTMAC_BEACONS;*///added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE;
2445
2446 priv->ieee80211->active_scan = 1;
2447 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
2448 priv->ieee80211->host_encrypt = 1;
2449 priv->ieee80211->host_decrypt = 1;
2450 //priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
2451 //priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
2452 priv->ieee80211->start_send_beacons = rtl8192_start_beacon;//+by david 081107
2453 priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;//+by david 081107
2454 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
2455 priv->ieee80211->set_chan = rtl8192_set_chan;
2456 priv->ieee80211->link_change = rtl8192_link_change;
2457 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
2458 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
2459 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
2460 priv->ieee80211->init_wmmparam_flag = 0;
2461 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2462 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
2463 priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI);
2464 priv->ieee80211->qos_support = 1;
2465 priv->ieee80211->dot11PowerSaveMode = 0;
2466 //added by WB
2467 // priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
2468 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
2469 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
2470 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
2471
2472 priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup;
2473 // priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack;
2474 priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep;
2475 priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
2476 //added by david
2477 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci;
2478 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
2479 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci;
2480
2481 //added by amy
2482 priv->ieee80211->InitialGainHandler = InitialGain819xPci;
2483
2484 #ifdef ENABLE_IPS
2485 priv->ieee80211->ieee80211_ips_leave_wq = ieee80211_ips_leave_wq;
2486 priv->ieee80211->ieee80211_ips_leave = ieee80211_ips_leave;
2487 #endif
2488 #ifdef ENABLE_LPS
2489 priv->ieee80211->LeisurePSLeave = LeisurePSLeave;
2490 #endif
2491
2492 priv->ieee80211->SetHwRegHandler = rtl8192e_SetHwReg;
2493 priv->ieee80211->rtllib_ap_sec_type = rtl8192e_ap_sec_type;
2494
2495 priv->card_type = USB;
2496 {
2497 priv->ShortRetryLimit = 0x30;
2498 priv->LongRetryLimit = 0x30;
2499 }
2500 priv->EarlyRxThreshold = 7;
2501 priv->enable_gpio0 = 0;
2502
2503 priv->TransmitConfig = 0;
2504
2505 priv->ReceiveConfig = RCR_ADD3 |
2506 RCR_AMF | RCR_ADF | //accept management/data
2507 RCR_AICV | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2508 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2509 RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) |
2510 ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT;
2511
2512 priv->irq_mask = (u32)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK |
2513 IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK |
2514 IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW |
2515 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2516
2517 priv->AcmControl = 0;
2518 priv->pFirmware = (rt_firmware*)vmalloc(sizeof(rt_firmware));
2519 if (priv->pFirmware)
2520 memset(priv->pFirmware, 0, sizeof(rt_firmware));
2521
2522 /* rx related queue */
2523 skb_queue_head_init(&priv->rx_queue);
2524 skb_queue_head_init(&priv->skb_queue);
2525
2526 /* Tx related queue */
2527 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2528 skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
2529 }
2530 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2531 skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
2532 }
2533 priv->rf_set_chan = rtl8192_phy_SwChnl;
2534 }
2535
2536 static void rtl8192_init_priv_lock(struct r8192_priv* priv)
2537 {
2538 spin_lock_init(&priv->tx_lock);
2539 spin_lock_init(&priv->irq_lock);//added by thomas
2540 spin_lock_init(&priv->irq_th_lock);
2541 spin_lock_init(&priv->rf_ps_lock);
2542 spin_lock_init(&priv->ps_lock);
2543 //spin_lock_init(&priv->rf_lock);
2544 sema_init(&priv->wx_sem,1);
2545 sema_init(&priv->rf_sem,1);
2546 mutex_init(&priv->mutex);
2547 }
2548
2549 /* init tasklet and wait_queue here */
2550 #define DRV_NAME "wlan0"
2551 static void rtl8192_init_priv_task(struct net_device* dev)
2552 {
2553 struct r8192_priv *priv = ieee80211_priv(dev);
2554
2555 #ifdef PF_SYNCTHREAD
2556 priv->priv_wq = create_workqueue(DRV_NAME,0);
2557 #else
2558 priv->priv_wq = create_workqueue(DRV_NAME);
2559 #endif
2560
2561 #ifdef ENABLE_IPS
2562 INIT_WORK(&priv->ieee80211->ips_leave_wq, (void*)IPSLeave_wq);
2563 #endif
2564
2565 // INIT_WORK(&priv->reset_wq, (void(*)(void*)) rtl8192_restart);
2566 INIT_WORK(&priv->reset_wq, rtl8192_restart);
2567 // INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
2568 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
2569 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
2570 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
2571 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
2572 //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem);
2573 //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem);
2574 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
2575 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq);
2576 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq);
2577
2578 tasklet_init(&priv->irq_rx_tasklet,
2579 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
2580 (unsigned long)priv);
2581 tasklet_init(&priv->irq_tx_tasklet,
2582 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
2583 (unsigned long)priv);
2584 tasklet_init(&priv->irq_prepare_beacon_tasklet,
2585 (void(*)(unsigned long))rtl8192_prepare_beacon,
2586 (unsigned long)priv);
2587 }
2588
2589 static void rtl8192_get_eeprom_size(struct net_device* dev)
2590 {
2591 u16 curCR = 0;
2592 struct r8192_priv *priv = ieee80211_priv(dev);
2593 RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__);
2594 curCR = read_nic_dword(dev, EPROM_CMD);
2595 RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR);
2596 //whether need I consider BIT5?
2597 priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EPROM_93c56 : EPROM_93c46;
2598 RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
2599 }
2600
2601 /*
2602 * used to swap endian. as ntohl & htonl are not
2603 * neccessary to swap endian, so use this instead.
2604 */
2605 static inline u16 endian_swap(u16* data)
2606 {
2607 u16 tmp = *data;
2608 *data = (tmp >> 8) | (tmp << 8);
2609 return *data;
2610 }
2611
2612 /*
2613 * Adapter->EEPROMAddressSize should be set before this function call.
2614 * EEPROM address size can be got through GetEEPROMSize8185()
2615 */
2616 static void rtl8192_read_eeprom_info(struct net_device* dev)
2617 {
2618 struct r8192_priv *priv = ieee80211_priv(dev);
2619
2620 u8 tempval;
2621 #ifdef RTL8192E
2622 u8 ICVer8192, ICVer8256;
2623 #endif
2624 u16 i,usValue, IC_Version;
2625 u16 EEPROMId;
2626 #ifdef RTL8190P
2627 u8 offset;
2628 u8 EepromTxPower[100];
2629 #endif
2630 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01};
2631 RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n");
2632
2633
2634 // TODO: I don't know if we need to apply EF function to EEPROM read function
2635
2636 //2 Read EEPROM ID to make sure autoload is success
2637 EEPROMId = eprom_read(dev, 0);
2638 if( EEPROMId != RTL8190_EEPROM_ID )
2639 {
2640 RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID);
2641 priv->AutoloadFailFlag=true;
2642 }
2643 else
2644 {
2645 priv->AutoloadFailFlag=false;
2646 }
2647
2648 //
2649 // Assign Chip Version ID
2650 //
2651 // Read IC Version && Channel Plan
2652 if(!priv->AutoloadFailFlag)
2653 {
2654 // VID, PID
2655 priv->eeprom_vid = eprom_read(dev, (EEPROM_VID >> 1));
2656 priv->eeprom_did = eprom_read(dev, (EEPROM_DID >> 1));
2657
2658 usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8 ;
2659 priv->eeprom_CustomerID = (u8)( usValue & 0xff);
2660 usValue = eprom_read(dev, (EEPROM_ICVersion_ChannelPlan>>1));
2661 priv->eeprom_ChannelPlan = usValue&0xff;
2662 IC_Version = ((usValue&0xff00)>>8);
2663
2664 #ifdef RTL8190P
2665 priv->card_8192_version = (VERSION_8190)(IC_Version);
2666 #else
2667 #ifdef RTL8192E
2668 ICVer8192 = (IC_Version&0xf); //bit0~3; 1:A cut, 2:B cut, 3:C cut...
2669 ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut...
2670 RT_TRACE(COMP_INIT, "\nICVer8192 = 0x%x\n", ICVer8192);
2671 RT_TRACE(COMP_INIT, "\nICVer8256 = 0x%x\n", ICVer8256);
2672 if(ICVer8192 == 0x2) //B-cut
2673 {
2674 if(ICVer8256 == 0x5) //E-cut
2675 priv->card_8192_version= VERSION_8190_BE;
2676 }
2677 #endif
2678 #endif
2679 switch(priv->card_8192_version)
2680 {
2681 case VERSION_8190_BD:
2682 case VERSION_8190_BE:
2683 break;
2684 default:
2685 priv->card_8192_version = VERSION_8190_BD;
2686 break;
2687 }
2688 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", priv->card_8192_version);
2689 }
2690 else
2691 {
2692 priv->card_8192_version = VERSION_8190_BD;
2693 priv->eeprom_vid = 0;
2694 priv->eeprom_did = 0;
2695 priv->eeprom_CustomerID = 0;
2696 priv->eeprom_ChannelPlan = 0;
2697 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", 0xff);
2698 }
2699
2700 RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
2701 RT_TRACE(COMP_INIT, "EEPROM DID = 0x%4x\n", priv->eeprom_did);
2702 RT_TRACE(COMP_INIT,"EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID);
2703
2704 //2 Read Permanent MAC address
2705 if(!priv->AutoloadFailFlag)
2706 {
2707 for(i = 0; i < 6; i += 2)
2708 {
2709 usValue = eprom_read(dev, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1));
2710 *(u16*)(&dev->dev_addr[i]) = usValue;
2711 }
2712 } else {
2713 // when auto load failed, the last address byte set to be a random one.
2714 // added by david woo.2007/11/7
2715 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
2716 }
2717
2718 RT_TRACE(COMP_INIT, "Permanent Address = %pM\n", dev->dev_addr);
2719
2720 //2 TX Power Check EEPROM Fail or not
2721 if(priv->card_8192_version > VERSION_8190_BD) {
2722 priv->bTXPowerDataReadFromEEPORM = true;
2723 } else {
2724 priv->bTXPowerDataReadFromEEPORM = false;
2725 }
2726
2727 // 2007/11/15 MH 8190PCI Default=2T4R, 8192PCIE default=1T2R
2728 priv->rf_type = RTL819X_DEFAULT_RF_TYPE;
2729
2730 if(priv->card_8192_version > VERSION_8190_BD)
2731 {
2732 // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate.
2733 if(!priv->AutoloadFailFlag)
2734 {
2735 tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff>>1))) & 0xff;
2736 priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; // bit[3:0]
2737
2738 if (tempval&0x80) //RF-indication, bit[7]
2739 priv->rf_type = RF_1T2R;
2740 else
2741 priv->rf_type = RF_2T4R;
2742 }
2743 else
2744 {
2745 priv->EEPROMLegacyHTTxPowerDiff = EEPROM_Default_LegacyHTTxPowerDiff;
2746 }
2747 RT_TRACE(COMP_INIT, "EEPROMLegacyHTTxPowerDiff = %d\n",
2748 priv->EEPROMLegacyHTTxPowerDiff);
2749
2750 // Read ThermalMeter from EEPROM
2751 if(!priv->AutoloadFailFlag)
2752 {
2753 priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8);
2754 }
2755 else
2756 {
2757 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2758 }
2759 RT_TRACE(COMP_INIT, "ThermalMeter = %d\n", priv->EEPROMThermalMeter);
2760 //vivi, for tx power track
2761 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
2762
2763 if(priv->epromtype == EPROM_93c46)
2764 {
2765 // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM
2766 if(!priv->AutoloadFailFlag)
2767 {
2768 usValue = eprom_read(dev, (EEPROM_TxPwDiff_CrystalCap>>1));
2769 priv->EEPROMAntPwDiff = (usValue&0x0fff);
2770 priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12);
2771 }
2772 else
2773 {
2774 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2775 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2776 }
2777 RT_TRACE(COMP_INIT, "EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2778 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2779
2780 //
2781 // Get per-channel Tx Power Level
2782 //
2783 for(i=0; i<14; i+=2)
2784 {
2785 if(!priv->AutoloadFailFlag)
2786 {
2787 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) );
2788 }
2789 else
2790 {
2791 usValue = EEPROM_Default_TxPower;
2792 }
2793 *((u16*)(&priv->EEPROMTxPowerLevelCCK[i])) = usValue;
2794 RT_TRACE(COMP_INIT,"CCK Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK[i]);
2795 RT_TRACE(COMP_INIT, "CCK Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelCCK[i+1]);
2796 }
2797 for(i=0; i<14; i+=2)
2798 {
2799 if(!priv->AutoloadFailFlag)
2800 {
2801 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) );
2802 }
2803 else
2804 {
2805 usValue = EEPROM_Default_TxPower;
2806 }
2807 *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[i])) = usValue;
2808 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelOFDM24G[i]);
2809 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelOFDM24G[i+1]);
2810 }
2811 }
2812 else if(priv->epromtype== EPROM_93c56)
2813 {
2814 #ifdef RTL8190P
2815 // Read CrystalCap from EEPROM
2816 if(!priv->AutoloadFailFlag)
2817 {
2818 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2819 priv->EEPROMCrystalCap = (u8)(((eprom_read(dev, (EEPROM_C56_CrystalCap>>1))) & 0xf000)>>12);
2820 }
2821 else
2822 {
2823 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2824 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2825 }
2826 RT_TRACE(COMP_INIT,"EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2827 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2828
2829 // Get Tx Power Level by Channel
2830 if(!priv->AutoloadFailFlag)
2831 {
2832 // Read Tx power of Channel 1 ~ 14 from EEPROM.
2833 for(i = 0; i < 12; i+=2)
2834 {
2835 if (i <6)
2836 offset = EEPROM_C56_RfA_CCK_Chnl1_TxPwIndex + i;
2837 else
2838 offset = EEPROM_C56_RfC_CCK_Chnl1_TxPwIndex + i - 6;
2839 usValue = eprom_read(dev, (offset>>1));
2840 *((u16*)(&EepromTxPower[i])) = usValue;
2841 }
2842
2843 for(i = 0; i < 12; i++)
2844 {
2845 if (i <= 2)
2846 priv->EEPROMRfACCKChnl1TxPwLevel[i] = EepromTxPower[i];
2847 else if ((i >=3 )&&(i <= 5))
2848 priv->EEPROMRfAOfdmChnlTxPwLevel[i-3] = EepromTxPower[i];
2849 else if ((i >=6 )&&(i <= 8))
2850 priv->EEPROMRfCCCKChnl1TxPwLevel[i-6] = EepromTxPower[i];
2851 else
2852 priv->EEPROMRfCOfdmChnlTxPwLevel[i-9] = EepromTxPower[i];
2853 }
2854 }
2855 else
2856 {
2857 priv->EEPROMRfACCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2858 priv->EEPROMRfACCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2859 priv->EEPROMRfACCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2860
2861 priv->EEPROMRfAOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2862 priv->EEPROMRfAOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2863 priv->EEPROMRfAOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2864
2865 priv->EEPROMRfCCCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2866 priv->EEPROMRfCCCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2867 priv->EEPROMRfCCCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2868
2869 priv->EEPROMRfCOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2870 priv->EEPROMRfCOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2871 priv->EEPROMRfCOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2872 }
2873 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[0]);
2874 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[1]);
2875 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[2]);
2876 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[0]);
2877 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[1]);
2878 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[2]);
2879 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[0]);
2880 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[1]);
2881 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[2]);
2882 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[0]);
2883 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[1]);
2884 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[2]);
2885 #endif
2886
2887 }
2888 //
2889 // Update HAL variables.
2890 //
2891 if(priv->epromtype == EPROM_93c46)
2892 {
2893 for(i=0; i<14; i++)
2894 {
2895 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK[i];
2896 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[i];
2897 }
2898 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
2899 // Antenna B gain offset to antenna A, bit0~3
2900 priv->AntennaTxPwDiff[0] = (priv->EEPROMAntPwDiff & 0xf);
2901 // Antenna C gain offset to antenna A, bit4~7
2902 priv->AntennaTxPwDiff[1] = ((priv->EEPROMAntPwDiff & 0xf0)>>4);
2903 // Antenna D gain offset to antenna A, bit8~11
2904 priv->AntennaTxPwDiff[2] = ((priv->EEPROMAntPwDiff & 0xf00)>>8);
2905 // CrystalCap, bit12~15
2906 priv->CrystalCap = priv->EEPROMCrystalCap;
2907 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2908 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
2909 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
2910 }
2911 else if(priv->epromtype == EPROM_93c56)
2912 {
2913 //char cck_pwr_diff_a=0, cck_pwr_diff_c=0;
2914
2915 //cck_pwr_diff_a = pHalData->EEPROMRfACCKChnl7TxPwLevel - pHalData->EEPROMRfAOfdmChnlTxPwLevel[1];
2916 //cck_pwr_diff_c = pHalData->EEPROMRfCCCKChnl7TxPwLevel - pHalData->EEPROMRfCOfdmChnlTxPwLevel[1];
2917 for(i=0; i<3; i++) // channel 1~3 use the same Tx Power Level.
2918 {
2919 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[0];
2920 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[0];
2921 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[0];
2922 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[0];
2923 }
2924 for(i=3; i<9; i++) // channel 4~9 use the same Tx Power Level
2925 {
2926 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[1];
2927 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[1];
2928 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[1];
2929 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[1];
2930 }
2931 for(i=9; i<14; i++) // channel 10~14 use the same Tx Power Level
2932 {
2933 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[2];
2934 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[2];
2935 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[2];
2936 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[2];
2937 }
2938 for(i=0; i<14; i++)
2939 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_A[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_A[i]);
2940 for(i=0; i<14; i++)
2941 RT_TRACE(COMP_INIT,"priv->TxPowerLevelOFDM24G_A[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_A[i]);
2942 for(i=0; i<14; i++)
2943 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_C[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_C[i]);
2944 for(i=0; i<14; i++)
2945 RT_TRACE(COMP_INIT, "priv->TxPowerLevelOFDM24G_C[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_C[i]);
2946 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
2947 priv->AntennaTxPwDiff[0] = 0;
2948 priv->AntennaTxPwDiff[1] = 0;
2949 priv->AntennaTxPwDiff[2] = 0;
2950 priv->CrystalCap = priv->EEPROMCrystalCap;
2951 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2952 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
2953 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
2954 }
2955 }
2956
2957 if(priv->rf_type == RF_1T2R)
2958 {
2959 RT_TRACE(COMP_INIT, "\n1T2R config\n");
2960 }
2961 else if (priv->rf_type == RF_2T4R)
2962 {
2963 RT_TRACE(COMP_INIT, "\n2T4R config\n");
2964 }
2965
2966 // 2008/01/16 MH We can only know RF type in the function. So we have to init
2967 // DIG RATR table again.
2968 init_rate_adaptive(dev);
2969
2970 //1 Make a copy for following variables and we can change them if we want
2971
2972 priv->rf_chip= RF_8256;
2973
2974 if(priv->RegChannelPlan == 0xf)
2975 {
2976 priv->ChannelPlan = priv->eeprom_ChannelPlan;
2977 }
2978 else
2979 {
2980 priv->ChannelPlan = priv->RegChannelPlan;
2981 }
2982
2983 //
2984 // Used PID and DID to Set CustomerID
2985 //
2986 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304 )
2987 {
2988 priv->CustomerID = RT_CID_DLINK;
2989 }
2990
2991 switch(priv->eeprom_CustomerID)
2992 {
2993 case EEPROM_CID_DEFAULT:
2994 priv->CustomerID = RT_CID_DEFAULT;
2995 break;
2996 case EEPROM_CID_CAMEO:
2997 priv->CustomerID = RT_CID_819x_CAMEO;
2998 break;
2999 case EEPROM_CID_RUNTOP:
3000 priv->CustomerID = RT_CID_819x_RUNTOP;
3001 break;
3002 case EEPROM_CID_NetCore:
3003 priv->CustomerID = RT_CID_819x_Netcore;
3004 break;
3005 case EEPROM_CID_TOSHIBA: // Merge by Jacken, 2008/01/31
3006 priv->CustomerID = RT_CID_TOSHIBA;
3007 if(priv->eeprom_ChannelPlan&0x80)
3008 priv->ChannelPlan = priv->eeprom_ChannelPlan&0x7f;
3009 else
3010 priv->ChannelPlan = 0x0;
3011 RT_TRACE(COMP_INIT, "Toshiba ChannelPlan = 0x%x\n",
3012 priv->ChannelPlan);
3013 break;
3014 case EEPROM_CID_Nettronix:
3015 priv->ScanDelay = 100; //cosa add for scan
3016 priv->CustomerID = RT_CID_Nettronix;
3017 break;
3018 case EEPROM_CID_Pronet:
3019 priv->CustomerID = RT_CID_PRONET;
3020 break;
3021 case EEPROM_CID_DLINK:
3022 priv->CustomerID = RT_CID_DLINK;
3023 break;
3024
3025 case EEPROM_CID_WHQL:
3026 //Adapter->bInHctTest = TRUE;//do not supported
3027
3028 //priv->bSupportTurboMode = FALSE;
3029 //priv->bAutoTurboBy8186 = FALSE;
3030
3031 //pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
3032 //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
3033 //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
3034
3035 break;
3036 default:
3037 // value from RegCustomerID
3038 break;
3039 }
3040
3041 //Avoid the channel plan array overflow, by Bruce, 2007-08-27.
3042 if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1)
3043 priv->ChannelPlan = 0; //FCC
3044
3045 switch(priv->CustomerID)
3046 {
3047 case RT_CID_DEFAULT:
3048 #ifdef RTL8190P
3049 priv->LedStrategy = HW_LED;
3050 #else
3051 #ifdef RTL8192E
3052 priv->LedStrategy = SW_LED_MODE1;
3053 #endif
3054 #endif
3055 break;
3056
3057 case RT_CID_819x_CAMEO:
3058 priv->LedStrategy = SW_LED_MODE2;
3059 break;
3060
3061 case RT_CID_819x_RUNTOP:
3062 priv->LedStrategy = SW_LED_MODE3;
3063 break;
3064
3065 case RT_CID_819x_Netcore:
3066 priv->LedStrategy = SW_LED_MODE4;
3067 break;
3068
3069 case RT_CID_Nettronix:
3070 priv->LedStrategy = SW_LED_MODE5;
3071 break;
3072
3073 case RT_CID_PRONET:
3074 priv->LedStrategy = SW_LED_MODE6;
3075 break;
3076
3077 case RT_CID_TOSHIBA: //Modify by Jacken 2008/01/31
3078 // Do nothing.
3079 //break;
3080
3081 default:
3082 #ifdef RTL8190P
3083 priv->LedStrategy = HW_LED;
3084 #else
3085 #ifdef RTL8192E
3086 priv->LedStrategy = SW_LED_MODE1;
3087 #endif
3088 #endif
3089 break;
3090 }
3091
3092
3093 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304)
3094 priv->ieee80211->bSupportRemoteWakeUp = true;
3095 else
3096 priv->ieee80211->bSupportRemoteWakeUp = false;
3097
3098
3099 RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan);
3100 RT_TRACE(COMP_INIT, "ChannelPlan = %d \n", priv->ChannelPlan);
3101 RT_TRACE(COMP_INIT, "LedStrategy = %d \n", priv->LedStrategy);
3102 RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n");
3103
3104 return ;
3105 }
3106
3107
3108 static short rtl8192_get_channel_map(struct net_device * dev)
3109 {
3110 struct r8192_priv *priv = ieee80211_priv(dev);
3111 #ifdef ENABLE_DOT11D
3112 if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){
3113 printk("rtl8180_init:Error channel plan! Set to default.\n");
3114 priv->ChannelPlan= 0;
3115 }
3116 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
3117
3118 rtl819x_set_channel_map(priv->ChannelPlan, priv);
3119 #else
3120 int ch,i;
3121 //Set Default Channel Plan
3122 if(!channels){
3123 DMESG("No channels, aborting");
3124 return -1;
3125 }
3126 ch=channels;
3127 priv->ChannelPlan= 0;//hikaru
3128 // set channels 1..14 allowed in given locale
3129 for (i=1; i<=14; i++) {
3130 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
3131 ch >>= 1;
3132 }
3133 #endif
3134 return 0;
3135 }
3136
3137 static short rtl8192_init(struct net_device *dev)
3138 {
3139 struct r8192_priv *priv = ieee80211_priv(dev);
3140 memset(&(priv->stats),0,sizeof(struct Stats));
3141 rtl8192_init_priv_variable(dev);
3142 rtl8192_init_priv_lock(priv);
3143 rtl8192_init_priv_task(dev);
3144 rtl8192_get_eeprom_size(dev);
3145 rtl8192_read_eeprom_info(dev);
3146 rtl8192_get_channel_map(dev);
3147 init_hal_dm(dev);
3148 init_timer(&priv->watch_dog_timer);
3149 priv->watch_dog_timer.data = (unsigned long)dev;
3150 priv->watch_dog_timer.function = watch_dog_timer_callback;
3151 #if defined(IRQF_SHARED)
3152 if(request_irq(dev->irq, (void*)rtl8192_interrupt, IRQF_SHARED, dev->name, dev)){
3153 #else
3154 if(request_irq(dev->irq, (void *)rtl8192_interrupt, SA_SHIRQ, dev->name, dev)){
3155 #endif
3156 printk("Error allocating IRQ %d",dev->irq);
3157 return -1;
3158 }else{
3159 priv->irq=dev->irq;
3160 printk("IRQ %d",dev->irq);
3161 }
3162 if(rtl8192_pci_initdescring(dev)!=0){
3163 printk("Endopoints initialization failed");
3164 return -1;
3165 }
3166
3167 //rtl8192_rx_enable(dev);
3168 //rtl8192_adapter_start(dev);
3169 return 0;
3170 }
3171
3172 /*
3173 * Actually only set RRSR, RATR and BW_OPMODE registers
3174 * not to do all the hw config as its name says
3175 * This part need to modified according to the rate set we filtered
3176 */
3177 static void rtl8192_hwconfig(struct net_device* dev)
3178 {
3179 u32 regRATR = 0, regRRSR = 0;
3180 u8 regBwOpMode = 0, regTmp = 0;
3181 struct r8192_priv *priv = ieee80211_priv(dev);
3182
3183 // Set RRSR, RATR, and BW_OPMODE registers
3184 //
3185 switch(priv->ieee80211->mode)
3186 {
3187 case WIRELESS_MODE_B:
3188 regBwOpMode = BW_OPMODE_20MHZ;
3189 regRATR = RATE_ALL_CCK;
3190 regRRSR = RATE_ALL_CCK;
3191 break;
3192 case WIRELESS_MODE_A:
3193 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
3194 regRATR = RATE_ALL_OFDM_AG;
3195 regRRSR = RATE_ALL_OFDM_AG;
3196 break;
3197 case WIRELESS_MODE_G:
3198 regBwOpMode = BW_OPMODE_20MHZ;
3199 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3200 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3201 break;
3202 case WIRELESS_MODE_AUTO:
3203 case WIRELESS_MODE_N_24G:
3204 // It support CCK rate by default.
3205 // CCK rate will be filtered out only when associated AP does not support it.
3206 regBwOpMode = BW_OPMODE_20MHZ;
3207 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
3208 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3209 break;
3210 case WIRELESS_MODE_N_5G:
3211 regBwOpMode = BW_OPMODE_5G;
3212 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
3213 regRRSR = RATE_ALL_OFDM_AG;
3214 break;
3215 }
3216
3217 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3218 {
3219 u32 ratr_value = 0;
3220 ratr_value = regRATR;
3221 if (priv->rf_type == RF_1T2R)
3222 {
3223 ratr_value &= ~(RATE_ALL_OFDM_2SS);
3224 }
3225 write_nic_dword(dev, RATR0, ratr_value);
3226 write_nic_byte(dev, UFWP, 1);
3227 }
3228 regTmp = read_nic_byte(dev, 0x313);
3229 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
3230 write_nic_dword(dev, RRSR, regRRSR);
3231
3232 //
3233 // Set Retry Limit here
3234 //
3235 write_nic_word(dev, RETRY_LIMIT,
3236 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
3237 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
3238 // Set Contention Window here
3239
3240 // Set Tx AGC
3241
3242 // Set Tx Antenna including Feedback control
3243
3244 // Set Auto Rate fallback control
3245
3246
3247 }
3248
3249
3250 static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
3251 {
3252 struct r8192_priv *priv = ieee80211_priv(dev);
3253 // struct ieee80211_device *ieee = priv->ieee80211;
3254 u32 ulRegRead;
3255 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
3256 //u8 eRFPath;
3257 u8 tmpvalue;
3258 #ifdef RTL8192E
3259 u8 ICVersion,SwitchingRegulatorOutput;
3260 #endif
3261 bool bfirmwareok = true;
3262 #ifdef RTL8190P
3263 u8 ucRegRead;
3264 #endif
3265 u32 tmpRegA, tmpRegC, TempCCk;
3266 int i =0;
3267
3268 RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
3269 priv->being_init_adapter = true;
3270 rtl8192_pci_resetdescring(dev);
3271 // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W.
3272 priv->Rf_Mode = RF_OP_By_SW_3wire;
3273 #ifdef RTL8192E
3274 //dPLL on
3275 if(priv->ResetProgress == RESET_TYPE_NORESET)
3276 {
3277 write_nic_byte(dev, ANAPAR, 0x37);
3278 // Accordign to designer's explain, LBUS active will never > 10ms. We delay 10ms
3279 // Joseph increae the time to prevent firmware download fail
3280 mdelay(500);
3281 }
3282 #endif
3283 //PlatformSleepUs(10000);
3284 // For any kind of InitializeAdapter process, we shall use system now!!
3285 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
3286
3287 // Set to eRfoff in order not to count receive count.
3288 if(priv->RegRfOff == TRUE)
3289 priv->ieee80211->eRFPowerState = eRfOff;
3290
3291 //
3292 //3 //Config CPUReset Register
3293 //3//
3294 //3 Firmware Reset Or Not
3295 ulRegRead = read_nic_dword(dev, CPU_GEN);
3296 if(priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
3297 { //called from MPInitialized. do nothing
3298 ulRegRead |= CPU_GEN_SYSTEM_RESET;
3299 }else if(priv->pFirmware->firmware_status == FW_STATUS_5_READY)
3300 ulRegRead |= CPU_GEN_FIRMWARE_RESET; // Called from MPReset
3301 else
3302 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status);
3303
3304 #ifdef RTL8190P
3305 //2008.06.03, for WOL 90 hw bug
3306 ulRegRead &= (~(CPU_GEN_GPIO_UART));
3307 #endif
3308
3309 write_nic_dword(dev, CPU_GEN, ulRegRead);
3310 //mdelay(100);
3311
3312 #ifdef RTL8192E
3313
3314 //3//
3315 //3 //Fix the issue of E-cut high temperature issue
3316 //3//
3317 // TODO: E cut only
3318 ICVersion = read_nic_byte(dev, IC_VERRSION);
3319 if(ICVersion >= 0x4) //E-cut only
3320 {
3321 // HW SD suggest that we should not wirte this register too often, so driver
3322 // should readback this register. This register will be modified only when
3323 // power on reset
3324 SwitchingRegulatorOutput = read_nic_byte(dev, SWREGULATOR);
3325 if(SwitchingRegulatorOutput != 0xb8)
3326 {
3327 write_nic_byte(dev, SWREGULATOR, 0xa8);
3328 mdelay(1);
3329 write_nic_byte(dev, SWREGULATOR, 0xb8);
3330 }
3331 }
3332 #endif
3333
3334
3335 //3//
3336 //3// Initialize BB before MAC
3337 //3//
3338 RT_TRACE(COMP_INIT, "BB Config Start!\n");
3339 rtStatus = rtl8192_BBConfig(dev);
3340 if(rtStatus != RT_STATUS_SUCCESS)
3341 {
3342 RT_TRACE(COMP_ERR, "BB Config failed\n");
3343 return rtStatus;
3344 }
3345 RT_TRACE(COMP_INIT,"BB Config Finished!\n");
3346
3347 //3//Set Loopback mode or Normal mode
3348 //3//
3349 //2006.12.13 by emily. Note!We should not merge these two CPU_GEN register writings
3350 // because setting of System_Reset bit reset MAC to default transmission mode.
3351 //Loopback mode or not
3352 priv->LoopbackMode = RTL819X_NO_LOOPBACK;
3353 //priv->LoopbackMode = RTL819X_MAC_LOOPBACK;
3354 if(priv->ResetProgress == RESET_TYPE_NORESET)
3355 {
3356 ulRegRead = read_nic_dword(dev, CPU_GEN);
3357 if(priv->LoopbackMode == RTL819X_NO_LOOPBACK)
3358 {
3359 ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
3360 }
3361 else if (priv->LoopbackMode == RTL819X_MAC_LOOPBACK )
3362 {
3363 ulRegRead |= CPU_CCK_LOOPBACK;
3364 }
3365 else
3366 {
3367 RT_TRACE(COMP_ERR,"Serious error: wrong loopback mode setting\n");
3368 }
3369
3370 //2008.06.03, for WOL
3371 //ulRegRead &= (~(CPU_GEN_GPIO_UART));
3372 write_nic_dword(dev, CPU_GEN, ulRegRead);
3373
3374 // 2006.11.29. After reset cpu, we sholud wait for a second, otherwise, it may fail to write registers. Emily
3375 udelay(500);
3376 }
3377 //3Set Hardware(Do nothing now)
3378 rtl8192_hwconfig(dev);
3379 //2=======================================================
3380 // Common Setting for all of the FPGA platform. (part 1)
3381 //2=======================================================
3382 // If there is changes, please make sure it applies to all of the FPGA version
3383 //3 Turn on Tx/Rx
3384 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
3385
3386 //2Set Tx dma burst
3387 #ifdef RTL8190P
3388 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
3389 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) |
3390 (1<<MULRW_SHIFT)));
3391 #else
3392 #ifdef RTL8192E
3393 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
3394 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) ));
3395 #endif
3396 #endif
3397 //set IDR0 here
3398 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
3399 write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]);
3400 //set RCR
3401 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3402
3403 //3 Initialize Number of Reserved Pages in Firmware Queue
3404 #ifdef TO_DO_LIST
3405 if(priv->bInHctTest)
3406 {
3407 PlatformEFIOWrite4Byte(Adapter, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
3408 NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
3409 NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
3410 NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3411 PlatformEFIOWrite4Byte(Adapter, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3412 PlatformEFIOWrite4Byte(Adapter, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
3413 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
3414 NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3415 }
3416 else
3417 #endif
3418 {
3419 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
3420 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
3421 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
3422 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3423 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3424 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
3425 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
3426 NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3427 }
3428
3429 rtl8192_tx_enable(dev);
3430 rtl8192_rx_enable(dev);
3431 //3Set Response Rate Setting Register
3432 // CCK rate is supported by default.
3433 // CCK rate will be filtered out only when associated AP does not support it.
3434 ulRegRead = (0xFFF00000 & read_nic_dword(dev, RRSR)) | RATE_ALL_OFDM_AG | RATE_ALL_CCK;
3435 write_nic_dword(dev, RRSR, ulRegRead);
3436 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
3437
3438 //2Set AckTimeout
3439 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
3440 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
3441
3442 //rtl8192_actset_wirelessmode(dev,priv->RegWirelessMode);
3443 if(priv->ResetProgress == RESET_TYPE_NORESET)
3444 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
3445 //-----------------------------------------------------------------------------
3446 // Set up security related. 070106, by rcnjko:
3447 // 1. Clear all H/W keys.
3448 // 2. Enable H/W encryption/decryption.
3449 //-----------------------------------------------------------------------------
3450 CamResetAllEntry(dev);
3451 {
3452 u8 SECR_value = 0x0;
3453 SECR_value |= SCR_TxEncEnable;
3454 SECR_value |= SCR_RxDecEnable;
3455 SECR_value |= SCR_NoSKMC;
3456 write_nic_byte(dev, SECR, SECR_value);
3457 }
3458 //3Beacon related
3459 write_nic_word(dev, ATIMWND, 2);
3460 write_nic_word(dev, BCN_INTERVAL, 100);
3461 for (i=0; i<QOS_QUEUE_NUM; i++)
3462 write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
3463 //
3464 // Switching regulator controller: This is set temporarily.
3465 // It's not sure if this can be removed in the future.
3466 // PJ advised to leave it by default.
3467 //
3468 write_nic_byte(dev, 0xbe, 0xc0);
3469
3470 //2=======================================================
3471 // Set PHY related configuration defined in MAC register bank
3472 //2=======================================================
3473 rtl8192_phy_configmac(dev);
3474
3475 if (priv->card_8192_version > (u8) VERSION_8190_BD) {
3476 rtl8192_phy_getTxPower(dev);
3477 rtl8192_phy_setTxPower(dev, priv->chan);
3478 }
3479
3480 //if D or C cut
3481 tmpvalue = read_nic_byte(dev, IC_VERRSION);
3482 priv->IC_Cut = tmpvalue;
3483 RT_TRACE(COMP_INIT, "priv->IC_Cut = 0x%x\n", priv->IC_Cut);
3484 if(priv->IC_Cut >= IC_VersionCut_D)
3485 {
3486 //pHalData->bDcut = TRUE;
3487 if(priv->IC_Cut == IC_VersionCut_D)
3488 RT_TRACE(COMP_INIT, "D-cut\n");
3489 if(priv->IC_Cut == IC_VersionCut_E)
3490 {
3491 RT_TRACE(COMP_INIT, "E-cut\n");
3492 // HW SD suggest that we should not wirte this register too often, so driver
3493 // should readback this register. This register will be modified only when
3494 // power on reset
3495 }
3496 }
3497 else
3498 {
3499 //pHalData->bDcut = FALSE;
3500 RT_TRACE(COMP_INIT, "Before C-cut\n");
3501 }
3502
3503 #if 1
3504 //Firmware download
3505 RT_TRACE(COMP_INIT, "Load Firmware!\n");
3506 bfirmwareok = init_firmware(dev);
3507 if(bfirmwareok != true) {
3508 rtStatus = RT_STATUS_FAILURE;
3509 return rtStatus;
3510 }
3511 RT_TRACE(COMP_INIT, "Load Firmware finished!\n");
3512 #endif
3513 //RF config
3514 if(priv->ResetProgress == RESET_TYPE_NORESET)
3515 {
3516 RT_TRACE(COMP_INIT, "RF Config Started!\n");
3517 rtStatus = rtl8192_phy_RFConfig(dev);
3518 if(rtStatus != RT_STATUS_SUCCESS)
3519 {
3520 RT_TRACE(COMP_ERR, "RF Config failed\n");
3521 return rtStatus;
3522 }
3523 RT_TRACE(COMP_INIT, "RF Config Finished!\n");
3524 }
3525 rtl8192_phy_updateInitGain(dev);
3526
3527 /*---- Set CCK and OFDM Block "ON"----*/
3528 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
3529 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
3530
3531 #ifdef RTL8192E
3532 //Enable Led
3533 write_nic_byte(dev, 0x87, 0x0);
3534 #endif
3535 #ifdef RTL8190P
3536 //2008.06.03, for WOL
3537 ucRegRead = read_nic_byte(dev, GPE);
3538 ucRegRead |= BIT0;
3539 write_nic_byte(dev, GPE, ucRegRead);
3540
3541 ucRegRead = read_nic_byte(dev, GPO);
3542 ucRegRead &= ~BIT0;
3543 write_nic_byte(dev, GPO, ucRegRead);
3544 #endif
3545
3546 //2=======================================================
3547 // RF Power Save
3548 //2=======================================================
3549 #ifdef ENABLE_IPS
3550
3551 {
3552 if(priv->RegRfOff == TRUE)
3553 { // User disable RF via registry.
3554 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RegRfOff ----------\n",__FUNCTION__);
3555 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_SW);
3556 #if 0//cosa, ask SD3 willis and he doesn't know what is this for
3557 // Those action will be discard in MgntActSet_RF_State because off the same state
3558 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
3559 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3560 #endif
3561 }
3562 else if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
3563 { // H/W or S/W RF OFF before sleep.
3564 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3565 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3566 }
3567 else if(priv->ieee80211->RfOffReason >= RF_CHANGE_BY_IPS)
3568 { // H/W or S/W RF OFF before sleep.
3569 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3570 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3571 }
3572 else
3573 {
3574 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__);
3575 priv->ieee80211->eRFPowerState = eRfOn;
3576 priv->ieee80211->RfOffReason = 0;
3577 //DrvIFIndicateCurrentPhyStatus(Adapter);
3578 // LED control
3579 //Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_ON);
3580
3581 //
3582 // If inactive power mode is enabled, disable rf while in disconnected state.
3583 // But we should still tell upper layer we are in rf on state.
3584 // 2007.07.16, by shien chang.
3585 //
3586 //if(!Adapter->bInHctTest)
3587 //IPSEnter(Adapter);
3588
3589 }
3590 }
3591 #endif
3592 if(1){
3593 #ifdef RTL8192E
3594 // We can force firmware to do RF-R/W
3595 if(priv->ieee80211->FwRWRF)
3596 priv->Rf_Mode = RF_OP_By_FW;
3597 else
3598 priv->Rf_Mode = RF_OP_By_SW_3wire;
3599 #else
3600 priv->Rf_Mode = RF_OP_By_SW_3wire;
3601 #endif
3602 }
3603 #ifdef RTL8190P
3604 if(priv->ResetProgress == RESET_TYPE_NORESET)
3605 {
3606 dm_initialize_txpower_tracking(dev);
3607
3608 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3609 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3610
3611 if(priv->rf_type == RF_2T4R){
3612 for(i = 0; i<TxBBGainTableLength; i++)
3613 {
3614 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3615 {
3616 priv->rfa_txpowertrackingindex= (u8)i;
3617 priv->rfa_txpowertrackingindex_real= (u8)i;
3618 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3619 break;
3620 }
3621 }
3622 }
3623 for(i = 0; i<TxBBGainTableLength; i++)
3624 {
3625 if(tmpRegC == priv->txbbgain_table[i].txbbgain_value)
3626 {
3627 priv->rfc_txpowertrackingindex= (u8)i;
3628 priv->rfc_txpowertrackingindex_real= (u8)i;
3629 priv->rfc_txpowertracking_default = priv->rfc_txpowertrackingindex;
3630 break;
3631 }
3632 }
3633 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3634
3635 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3636 {
3637 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3638 {
3639 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3640 break;
3641 }
3642 }
3643 priv->CCKPresentAttentuation_40Mdefault = 0;
3644 priv->CCKPresentAttentuation_difference = 0;
3645 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3646 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3647 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3648 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_initial = %d\n", priv->rfc_txpowertrackingindex);
3649 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real_initial = %d\n", priv->rfc_txpowertrackingindex_real);
3650 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3651 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3652 }
3653 #else
3654 #ifdef RTL8192E
3655 if(priv->ResetProgress == RESET_TYPE_NORESET)
3656 {
3657 dm_initialize_txpower_tracking(dev);
3658
3659 if(priv->IC_Cut >= IC_VersionCut_D)
3660 {
3661 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3662 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3663 for(i = 0; i<TxBBGainTableLength; i++)
3664 {
3665 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3666 {
3667 priv->rfa_txpowertrackingindex= (u8)i;
3668 priv->rfa_txpowertrackingindex_real= (u8)i;
3669 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3670 break;
3671 }
3672 }
3673
3674 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3675
3676 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3677 {
3678 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3679 {
3680 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3681 break;
3682 }
3683 }
3684 priv->CCKPresentAttentuation_40Mdefault = 0;
3685 priv->CCKPresentAttentuation_difference = 0;
3686 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3687 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3688 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3689 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3690 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3691 priv->btxpower_tracking = FALSE;//TEMPLY DISABLE
3692 }
3693 }
3694 #endif
3695 #endif
3696 rtl8192_irq_enable(dev);
3697 priv->being_init_adapter = false;
3698 return rtStatus;
3699
3700 }
3701
3702 static void rtl8192_prepare_beacon(struct r8192_priv *priv)
3703 {
3704 struct sk_buff *skb;
3705 //unsigned long flags;
3706 cb_desc *tcb_desc;
3707
3708 skb = ieee80211_get_beacon(priv->ieee80211);
3709 tcb_desc = (cb_desc *)(skb->cb + 8);
3710 //spin_lock_irqsave(&priv->tx_lock,flags);
3711 /* prepare misc info for the beacon xmit */
3712 tcb_desc->queue_index = BEACON_QUEUE;
3713 /* IBSS does not support HT yet, use 1M defaultly */
3714 tcb_desc->data_rate = 2;
3715 tcb_desc->RATRIndex = 7;
3716 tcb_desc->bTxDisableRateFallBack = 1;
3717 tcb_desc->bTxUseDriverAssingedRate = 1;
3718
3719 skb_push(skb, priv->ieee80211->tx_headroom);
3720 if(skb){
3721 rtl8192_tx(priv->ieee80211->dev,skb);
3722 }
3723 //spin_unlock_irqrestore (&priv->tx_lock, flags);
3724 }
3725
3726
3727 /*
3728 * configure registers for beacon tx and enables it via
3729 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
3730 * be used to stop beacon transmission
3731 */
3732 static void rtl8192_start_beacon(struct net_device *dev)
3733 {
3734 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3735 struct ieee80211_network *net = &priv->ieee80211->current_network;
3736 u16 BcnTimeCfg = 0;
3737 u16 BcnCW = 6;
3738 u16 BcnIFS = 0xf;
3739
3740 DMESG("Enabling beacon TX");
3741 //rtl8192_prepare_beacon(dev);
3742 rtl8192_irq_disable(dev);
3743 //rtl8192_beacon_tx_enable(dev);
3744
3745 /* ATIM window */
3746 write_nic_word(dev, ATIMWND, 2);
3747
3748 /* Beacon interval (in unit of TU) */
3749 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
3750
3751 /*
3752 * DrvErlyInt (in unit of TU).
3753 * (Time to send interrupt to notify driver to c
3754 * hange beacon content)
3755 * */
3756 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
3757
3758 /*
3759 * BcnDMATIM(in unit of us).
3760 * Indicates the time before TBTT to perform beacon queue DMA
3761 * */
3762 write_nic_word(dev, BCN_DMATIME, 256);
3763
3764 /*
3765 * Force beacon frame transmission even after receiving
3766 * beacon frame from other ad hoc STA
3767 * */
3768 write_nic_byte(dev, BCN_ERR_THRESH, 100);
3769
3770 /* Set CW and IFS */
3771 BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT;
3772 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
3773 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
3774
3775
3776 /* enable the interrupt for ad-hoc process */
3777 rtl8192_irq_enable(dev);
3778 }
3779
3780 static bool HalTxCheckStuck8190Pci(struct net_device *dev)
3781 {
3782 u16 RegTxCounter = read_nic_word(dev, 0x128);
3783 struct r8192_priv *priv = ieee80211_priv(dev);
3784 bool bStuck = FALSE;
3785 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
3786 if(priv->TxCounter==RegTxCounter)
3787 bStuck = TRUE;
3788
3789 priv->TxCounter = RegTxCounter;
3790
3791 return bStuck;
3792 }
3793
3794 /*
3795 * Assumption: RT_TX_SPINLOCK is acquired.
3796 */
3797 static RESET_TYPE
3798 TxCheckStuck(struct net_device *dev)
3799 {
3800 struct r8192_priv *priv = ieee80211_priv(dev);
3801 u8 QueueID;
3802 ptx_ring head=NULL,tail=NULL,txring = NULL;
3803 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3804 bool bCheckFwTxCnt = false;
3805
3806 //
3807 // Decide Stuch threshold according to current power save mode
3808 //
3809 switch (priv->ieee80211->dot11PowerSaveMode)
3810 {
3811 // The threshold value may required to be adjusted .
3812 case eActive: // Active/Continuous access.
3813 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
3814 break;
3815 case eMaxPs: // Max power save mode.
3816 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3817 break;
3818 case eFastPs: // Fast power save mode.
3819 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3820 break;
3821 }
3822
3823 //
3824 // Check whether specific tcb has been queued for a specific time
3825 //
3826 for(QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++)
3827 {
3828
3829
3830 if(QueueID == TXCMD_QUEUE)
3831 continue;
3832
3833 switch(QueueID) {
3834 case MGNT_QUEUE:
3835 tail=priv->txmapringtail;
3836 head=priv->txmapringhead;
3837 break;
3838
3839 case BK_QUEUE:
3840 tail=priv->txbkpringtail;
3841 head=priv->txbkpringhead;
3842 break;
3843
3844 case BE_QUEUE:
3845 tail=priv->txbepringtail;
3846 head=priv->txbepringhead;
3847 break;
3848
3849 case VI_QUEUE:
3850 tail=priv->txvipringtail;
3851 head=priv->txvipringhead;
3852 break;
3853
3854 case VO_QUEUE:
3855 tail=priv->txvopringtail;
3856 head=priv->txvopringhead;
3857 break;
3858
3859 default:
3860 tail=head=NULL;
3861 break;
3862 }
3863
3864 if(tail == head)
3865 continue;
3866 else
3867 {
3868 txring = head;
3869 if(txring == NULL)
3870 {
3871 RT_TRACE(COMP_ERR,"%s():txring is NULL , BUG!\n",__FUNCTION__);
3872 continue;
3873 }
3874 txring->nStuckCount++;
3875 bCheckFwTxCnt = TRUE;
3876 }
3877 }
3878 #if 1
3879 if(bCheckFwTxCnt)
3880 {
3881 if(HalTxCheckStuck8190Pci(dev))
3882 {
3883 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
3884 return RESET_TYPE_SILENT;
3885 }
3886 }
3887 #endif
3888 return RESET_TYPE_NORESET;
3889 }
3890
3891
3892 static bool HalRxCheckStuck8190Pci(struct net_device *dev)
3893 {
3894 struct r8192_priv *priv = ieee80211_priv(dev);
3895 u16 RegRxCounter = read_nic_word(dev, 0x130);
3896 bool bStuck = FALSE;
3897 static u8 rx_chk_cnt = 0;
3898 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
3899 // If rssi is small, we should check rx for long time because of bad rx.
3900 // or maybe it will continuous silent reset every 2 seconds.
3901 rx_chk_cnt++;
3902 if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
3903 {
3904 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
3905 }
3906 else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
3907 ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
3908 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
3909
3910 {
3911 if(rx_chk_cnt < 2)
3912 {
3913 return bStuck;
3914 }
3915 else
3916 {
3917 rx_chk_cnt = 0;
3918 }
3919 }
3920 else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
3921 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
3922 priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
3923 {
3924 if(rx_chk_cnt < 4)
3925 {
3926 //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
3927 return bStuck;
3928 }
3929 else
3930 {
3931 rx_chk_cnt = 0;
3932 //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
3933 }
3934 }
3935 else
3936 {
3937 if(rx_chk_cnt < 8)
3938 {
3939 //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI);
3940 return bStuck;
3941 }
3942 else
3943 {
3944 rx_chk_cnt = 0;
3945 //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI);
3946 }
3947 }
3948 if(priv->RxCounter==RegRxCounter)
3949 bStuck = TRUE;
3950
3951 priv->RxCounter = RegRxCounter;
3952
3953 return bStuck;
3954 }
3955
3956 static RESET_TYPE RxCheckStuck(struct net_device *dev)
3957 {
3958
3959 if(HalRxCheckStuck8190Pci(dev))
3960 {
3961 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
3962 return RESET_TYPE_SILENT;
3963 }
3964
3965 return RESET_TYPE_NORESET;
3966 }
3967
3968 static RESET_TYPE
3969 rtl819x_ifcheck_resetornot(struct net_device *dev)
3970 {
3971 struct r8192_priv *priv = ieee80211_priv(dev);
3972 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
3973 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
3974 RT_RF_POWER_STATE rfState;
3975
3976 rfState = priv->ieee80211->eRFPowerState;
3977
3978 TxResetType = TxCheckStuck(dev);
3979 #if 1
3980 if( rfState != eRfOff &&
3981 /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
3982 (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
3983 {
3984 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
3985 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
3986 // if driver is in firmware download failure status, driver should initialize RF in the following
3987 // silent reset procedure Emily, 2008.01.21
3988
3989 // Driver should not check RX stuck in IBSS mode because it is required to
3990 // set Check BSSID in order to send beacon, however, if check BSSID is
3991 // set, STA cannot hear any packet a all. Emily, 2008.04.12
3992 RxResetType = RxCheckStuck(dev);
3993 }
3994 #endif
3995
3996 RT_TRACE(COMP_RESET,"%s(): TxResetType is %d, RxResetType is %d\n",__FUNCTION__,TxResetType,RxResetType);
3997 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
3998 return RESET_TYPE_NORMAL;
3999 else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT)
4000 return RESET_TYPE_SILENT;
4001 else
4002 return RESET_TYPE_NORESET;
4003
4004 }
4005
4006
4007 static void CamRestoreAllEntry(struct net_device *dev)
4008 {
4009 u8 EntryId = 0;
4010 struct r8192_priv *priv = ieee80211_priv(dev);
4011 const u8* MacAddr = priv->ieee80211->current_network.bssid;
4012
4013 static const u8 CAM_CONST_ADDR[4][6] = {
4014 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
4015 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
4016 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
4017 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
4018 static const u8 CAM_CONST_BROAD[] =
4019 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4020
4021 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
4022
4023
4024 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
4025 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
4026 {
4027
4028 for(EntryId=0; EntryId<4; EntryId++)
4029 {
4030 {
4031 MacAddr = CAM_CONST_ADDR[EntryId];
4032 setKey(dev,
4033 EntryId ,
4034 EntryId,
4035 priv->ieee80211->pairwise_key_type,
4036 MacAddr,
4037 0,
4038 NULL);
4039 }
4040 }
4041
4042 }
4043 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
4044 {
4045
4046 {
4047 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4048 setKey(dev,
4049 4,
4050 0,
4051 priv->ieee80211->pairwise_key_type,
4052 (u8*)dev->dev_addr,
4053 0,
4054 NULL);
4055 else
4056 setKey(dev,
4057 4,
4058 0,
4059 priv->ieee80211->pairwise_key_type,
4060 MacAddr,
4061 0,
4062 NULL);
4063 }
4064 }
4065 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
4066 {
4067
4068 {
4069 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4070 setKey(dev,
4071 4,
4072 0,
4073 priv->ieee80211->pairwise_key_type,
4074 (u8*)dev->dev_addr,
4075 0,
4076 NULL);
4077 else
4078 setKey(dev,
4079 4,
4080 0,
4081 priv->ieee80211->pairwise_key_type,
4082 MacAddr,
4083 0,
4084 NULL);
4085 }
4086 }
4087
4088
4089
4090 if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
4091 {
4092 MacAddr = CAM_CONST_BROAD;
4093 for(EntryId=1 ; EntryId<4 ; EntryId++)
4094 {
4095 {
4096 setKey(dev,
4097 EntryId,
4098 EntryId,
4099 priv->ieee80211->group_key_type,
4100 MacAddr,
4101 0,
4102 NULL);
4103 }
4104 }
4105 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4106 setKey(dev,
4107 0,
4108 0,
4109 priv->ieee80211->group_key_type,
4110 CAM_CONST_ADDR[0],
4111 0,
4112 NULL);
4113 }
4114 else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
4115 {
4116 MacAddr = CAM_CONST_BROAD;
4117 for(EntryId=1; EntryId<4 ; EntryId++)
4118 {
4119 {
4120 setKey(dev,
4121 EntryId ,
4122 EntryId,
4123 priv->ieee80211->group_key_type,
4124 MacAddr,
4125 0,
4126 NULL);
4127 }
4128 }
4129
4130 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4131 setKey(dev,
4132 0 ,
4133 0,
4134 priv->ieee80211->group_key_type,
4135 CAM_CONST_ADDR[0],
4136 0,
4137 NULL);
4138 }
4139 }
4140
4141 /*
4142 * This function is used to fix Tx/Rx stop bug temporarily.
4143 * This function will do "system reset" to NIC when Tx or Rx is stuck.
4144 * The method checking Tx/Rx stuck of this function is supported by FW,
4145 * which reports Tx and Rx counter to register 0x128 and 0x130.
4146 */
4147 static void rtl819x_ifsilentreset(struct net_device *dev)
4148 {
4149 struct r8192_priv *priv = ieee80211_priv(dev);
4150 u8 reset_times = 0;
4151 int reset_status = 0;
4152 struct ieee80211_device *ieee = priv->ieee80211;
4153
4154
4155 return;
4156
4157 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
4158 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
4159
4160 if(priv->ResetProgress==RESET_TYPE_NORESET)
4161 {
4162 RESET_START:
4163 #ifdef ENABLE_LPS
4164 //LZM for PS-Poll AID issue. 090429
4165 if(priv->ieee80211->state == IEEE80211_LINKED)
4166 LeisurePSLeave(dev);
4167 #endif
4168
4169 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
4170
4171 // Set the variable for reset.
4172 priv->ResetProgress = RESET_TYPE_SILENT;
4173 // rtl8192_close(dev);
4174 #if 1
4175 down(&priv->wx_sem);
4176 if(priv->up == 0)
4177 {
4178 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
4179 up(&priv->wx_sem);
4180 return ;
4181 }
4182 priv->up = 0;
4183 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
4184 if(!netif_queue_stopped(dev))
4185 netif_stop_queue(dev);
4186
4187 dm_backup_dynamic_mechanism_state(dev);
4188
4189 rtl8192_irq_disable(dev);
4190 rtl8192_cancel_deferred_work(priv);
4191 deinit_hal_dm(dev);
4192 del_timer_sync(&priv->watch_dog_timer);
4193 ieee->sync_scan_hurryup = 1;
4194 if(ieee->state == IEEE80211_LINKED)
4195 {
4196 down(&ieee->wx_sem);
4197 printk("ieee->state is IEEE80211_LINKED\n");
4198 ieee80211_stop_send_beacons(priv->ieee80211);
4199 del_timer_sync(&ieee->associate_timer);
4200 cancel_delayed_work(&ieee->associate_retry_wq);
4201 ieee80211_stop_scan(ieee);
4202 up(&ieee->wx_sem);
4203 }
4204 else{
4205 printk("ieee->state is NOT LINKED\n");
4206 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4207 }
4208 rtl8192_halt_adapter(dev, true);
4209 up(&priv->wx_sem);
4210 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
4211 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
4212 reset_status = _rtl8192_up(dev);
4213
4214 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
4215 if(reset_status == -1)
4216 {
4217 if(reset_times < 3)
4218 {
4219 reset_times++;
4220 goto RESET_START;
4221 }
4222 else
4223 {
4224 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n",__FUNCTION__);
4225 }
4226 }
4227 #endif
4228 ieee->is_silent_reset = 1;
4229 #if 1
4230 EnableHWSecurityConfig8192(dev);
4231 #if 1
4232 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4233 {
4234 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4235
4236 #if 1
4237 queue_work(ieee->wq, &ieee->associate_complete_wq);
4238 #endif
4239
4240 }
4241 else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
4242 {
4243 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4244 ieee->link_change(ieee->dev);
4245
4246 // notify_wx_assoc_event(ieee);
4247
4248 ieee80211_start_send_beacons(ieee);
4249
4250 if (ieee->data_hard_resume)
4251 ieee->data_hard_resume(ieee->dev);
4252 netif_carrier_on(ieee->dev);
4253 }
4254 #endif
4255
4256 CamRestoreAllEntry(dev);
4257
4258 // Restore the previous setting for all dynamic mechanism
4259 dm_restore_dynamic_mechanism_state(dev);
4260
4261 priv->ResetProgress = RESET_TYPE_NORESET;
4262 priv->reset_count++;
4263
4264 priv->bForcedSilentReset =false;
4265 priv->bResetInProgress = false;
4266
4267 // For test --> force write UFWP.
4268 write_nic_byte(dev, UFWP, 1);
4269 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
4270 #endif
4271 }
4272 }
4273
4274 #ifdef ENABLE_IPS
4275 void InactivePsWorkItemCallback(struct net_device *dev)
4276 {
4277 struct r8192_priv *priv = ieee80211_priv(dev);
4278 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4279
4280 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() ---------> \n");
4281 //
4282 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
4283 // is really scheduled.
4284 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
4285 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
4286 // blocks the IPS procedure of switching RF.
4287 // By Bruce, 2007-12-25.
4288 //
4289 pPSC->bSwRfProcessing = TRUE;
4290
4291 RT_TRACE(COMP_RF, "InactivePsWorkItemCallback(): Set RF to %s.\n",
4292 pPSC->eInactivePowerState == eRfOff?"OFF":"ON");
4293
4294
4295 MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
4296
4297 //
4298 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
4299 //
4300 pPSC->bSwRfProcessing = FALSE;
4301 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <--------- \n");
4302 }
4303
4304 #ifdef ENABLE_LPS
4305 /* Change current and default preamble mode. */
4306 bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev, u8 rtPsMode)
4307 {
4308 struct r8192_priv *priv = ieee80211_priv(dev);
4309
4310 // Currently, we do not change power save mode on IBSS mode.
4311 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4312 {
4313 return false;
4314 }
4315
4316 //
4317 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
4318 // some AP will not response to our mgnt frames with PwrMgt bit set,
4319 // e.g. cannot associate the AP.
4320 // So I commented out it. 2005.02.16, by rcnjko.
4321 //
4322 // // Change device's power save mode.
4323 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
4324
4325 // Update power save mode configured.
4326 //RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode);
4327 if(!priv->ps_force) {
4328 priv->ieee80211->ps = rtPsMode;
4329 }
4330
4331 // Awake immediately
4332 if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED)
4333 {
4334 unsigned long flags;
4335
4336 //PlatformSetTimer(Adapter, &(pMgntInfo->AwakeTimer), 0);
4337 // Notify the AP we awke.
4338 rtl8192_hw_wakeup(dev);
4339 priv->ieee80211->sta_sleep = 0;
4340
4341 spin_lock_irqsave(&(priv->ieee80211->mgmt_tx_lock), flags);
4342 printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n");
4343 ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0);
4344 spin_unlock_irqrestore(&(priv->ieee80211->mgmt_tx_lock), flags);
4345 }
4346
4347 return true;
4348 }
4349
4350 /* Enter the leisure power save mode. */
4351 void LeisurePSEnter(struct net_device *dev)
4352 {
4353 struct r8192_priv *priv = ieee80211_priv(dev);
4354 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4355
4356 //RT_TRACE(COMP_PS, "LeisurePSEnter()...\n");
4357 //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n",
4358 // pPSC->bLeisurePs, priv->ieee80211->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD);
4359
4360 if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) &&
4361 (priv->ieee80211->state == IEEE80211_LINKED)) ||
4362 (priv->ieee80211->iw_mode == IW_MODE_ADHOC) ||
4363 (priv->ieee80211->iw_mode == IW_MODE_MASTER))
4364 return;
4365
4366 if (pPSC->bLeisurePs)
4367 {
4368 // Idle for a while if we connect to AP a while ago.
4369 if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) // 4 Sec
4370 {
4371
4372 if(priv->ieee80211->ps == IEEE80211_PS_DISABLED)
4373 {
4374
4375 //RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n");
4376 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
4377
4378 }
4379 }
4380 else
4381 pPSC->LpsIdleCount++;
4382 }
4383 }
4384
4385
4386 /* Leave leisure power save mode. */
4387 void LeisurePSLeave(struct net_device *dev)
4388 {
4389 struct r8192_priv *priv = ieee80211_priv(dev);
4390 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4391
4392 if (pPSC->bLeisurePs)
4393 {
4394 if(priv->ieee80211->ps != IEEE80211_PS_DISABLED)
4395 {
4396 // move to lps_wakecomplete()
4397 //RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n");
4398 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_DISABLED);
4399
4400 }
4401 }
4402 }
4403 #endif
4404
4405
4406 /* Enter the inactive power save mode. RF will be off */
4407 void
4408 IPSEnter(struct net_device *dev)
4409 {
4410 struct r8192_priv *priv = ieee80211_priv(dev);
4411 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4412 RT_RF_POWER_STATE rtState;
4413
4414 if (pPSC->bInactivePs)
4415 {
4416 rtState = priv->ieee80211->eRFPowerState;
4417 //
4418 // Added by Bruce, 2007-12-25.
4419 // Do not enter IPS in the following conditions:
4420 // (1) RF is already OFF or Sleep
4421 // (2) bSwRfProcessing (indicates the IPS is still under going)
4422 // (3) Connectted (only disconnected can trigger IPS)
4423 // (4) IBSS (send Beacon)
4424 // (5) AP mode (send Beacon)
4425 //
4426 if (rtState == eRfOn && !pPSC->bSwRfProcessing
4427 && (priv->ieee80211->state != IEEE80211_LINKED) )
4428 {
4429 RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n");
4430 //printk("IPSEnter(): Turn off RF.\n");
4431 pPSC->eInactivePowerState = eRfOff;
4432 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4433 InactivePsWorkItemCallback(dev);
4434 }
4435 }
4436 }
4437
4438 //
4439 // Description:
4440 // Leave the inactive power save mode, RF will be on.
4441 // 2007.08.17, by shien chang.
4442 //
4443 void
4444 IPSLeave(struct net_device *dev)
4445 {
4446 struct r8192_priv *priv = ieee80211_priv(dev);
4447 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4448 RT_RF_POWER_STATE rtState;
4449
4450 if (pPSC->bInactivePs)
4451 {
4452 rtState = priv->ieee80211->eRFPowerState;
4453 if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->ieee80211->RfOffReason <= RF_CHANGE_BY_IPS)
4454 {
4455 RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n");
4456 //printk("IPSLeave(): Turn on RF.\n");
4457 pPSC->eInactivePowerState = eRfOn;
4458 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4459 InactivePsWorkItemCallback(dev);
4460 }
4461 }
4462 }
4463
4464 void IPSLeave_wq(void *data)
4465 {
4466 struct ieee80211_device *ieee = container_of(data,struct ieee80211_device,ips_leave_wq);
4467 struct net_device *dev = ieee->dev;
4468
4469 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4470 down(&priv->ieee80211->ips_sem);
4471 IPSLeave(dev);
4472 up(&priv->ieee80211->ips_sem);
4473 }
4474
4475 void ieee80211_ips_leave_wq(struct net_device *dev)
4476 {
4477 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4478 RT_RF_POWER_STATE rtState;
4479 rtState = priv->ieee80211->eRFPowerState;
4480
4481 if(priv->ieee80211->PowerSaveControl.bInactivePs){
4482 if(rtState == eRfOff){
4483 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
4484 {
4485 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
4486 return;
4487 }
4488 else{
4489 printk("=========>%s(): IPSLeave\n",__FUNCTION__);
4490 queue_work(priv->ieee80211->wq,&priv->ieee80211->ips_leave_wq);
4491 }
4492 }
4493 }
4494 }
4495 //added by amy 090331 end
4496 void ieee80211_ips_leave(struct net_device *dev)
4497 {
4498 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4499 down(&priv->ieee80211->ips_sem);
4500 IPSLeave(dev);
4501 up(&priv->ieee80211->ips_sem);
4502 }
4503 #endif
4504
4505 static void rtl819x_update_rxcounts(
4506 struct r8192_priv *priv,
4507 u32* TotalRxBcnNum,
4508 u32* TotalRxDataNum
4509 )
4510 {
4511 u16 SlotIndex;
4512 u8 i;
4513
4514 *TotalRxBcnNum = 0;
4515 *TotalRxDataNum = 0;
4516
4517 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
4518 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
4519 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
4520 for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
4521 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
4522 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
4523 }
4524 }
4525
4526
4527 static void rtl819x_watchdog_wqcallback(struct work_struct *work)
4528 {
4529 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
4530 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
4531 struct net_device *dev = priv->ieee80211->dev;
4532 struct ieee80211_device* ieee = priv->ieee80211;
4533 RESET_TYPE ResetType = RESET_TYPE_NORESET;
4534 static u8 check_reset_cnt=0;
4535 unsigned long flags;
4536 bool bBusyTraffic = false;
4537 static u8 last_time = 0;
4538 bool bEnterPS = false;
4539
4540 if ((!priv->up) || priv->bHwRadioOff)
4541 return;
4542
4543 if(!priv->up)
4544 return;
4545 hal_dm_watchdog(dev);
4546 #ifdef ENABLE_IPS
4547 // printk("watch_dog ENABLE_IPS\n");
4548 if(ieee->actscanning == false){
4549 //printk("%d,%d,%d,%d\n", ieee->eRFPowerState, ieee->is_set_key, ieee->proto_stoppping, ieee->wx_set_enc);
4550 if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) &&
4551 (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key &&
4552 (!ieee->proto_stoppping) && !ieee->wx_set_enc){
4553 if(ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){
4554 //printk("====================>haha:IPSEnter()\n");
4555 IPSEnter(dev);
4556 //ieee80211_stop_scan(priv->ieee80211);
4557 }
4558 }
4559 }
4560 #endif
4561 {//to get busy traffic condition
4562 if(ieee->state == IEEE80211_LINKED)
4563 {
4564 if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 ||
4565 ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) {
4566 bBusyTraffic = true;
4567 }
4568
4569 #ifdef ENABLE_LPS
4570 //added by amy for Leisure PS
4571 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
4572 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
4573 {
4574 //printk("ieee->LinkDetectInfo.NumRxUnicastOkInPeriod is %d,ieee->LinkDetectInfo.NumTxOkInPeriod is %d\n",
4575 // ieee->LinkDetectInfo.NumRxUnicastOkInPeriod,ieee->LinkDetectInfo.NumTxOkInPeriod);
4576 bEnterPS= false;
4577 }
4578 else
4579 {
4580 bEnterPS= true;
4581 }
4582
4583 //printk("***bEnterPS = %d\n", bEnterPS);
4584 // LeisurePS only work in infra mode.
4585 if(bEnterPS)
4586 {
4587 LeisurePSEnter(dev);
4588 }
4589 else
4590 {
4591 LeisurePSLeave(dev);
4592 }
4593 #endif
4594
4595 }
4596 else
4597 {
4598 #ifdef ENABLE_LPS
4599 //RT_TRACE(COMP_LPS,"====>no link LPS leave\n");
4600 LeisurePSLeave(dev);
4601 #endif
4602 }
4603
4604 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
4605 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
4606 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
4607 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
4608 }
4609
4610
4611 //added by amy for AP roaming
4612 if (1)
4613 {
4614 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4615 {
4616 u32 TotalRxBcnNum = 0;
4617 u32 TotalRxDataNum = 0;
4618
4619 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
4620 if((TotalRxBcnNum+TotalRxDataNum) == 0)
4621 {
4622 if( ieee->eRFPowerState == eRfOff)
4623 RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
4624 printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
4625 // Dot11d_Reset(dev);
4626 ieee->state = IEEE80211_ASSOCIATING;
4627 notify_wx_assoc_event(priv->ieee80211);
4628 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
4629 ieee->is_roaming = true;
4630 ieee->is_set_key = false;
4631 ieee->link_change(dev);
4632 queue_work(ieee->wq, &ieee->associate_procedure_wq);
4633 }
4634 }
4635 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
4636 ieee->LinkDetectInfo.NumRecvDataInPeriod=0;
4637
4638 }
4639 //check if reset the driver
4640 spin_lock_irqsave(&priv->tx_lock,flags);
4641 if(check_reset_cnt++ >= 3 && !ieee->is_roaming && (last_time != 1))
4642 {
4643 ResetType = rtl819x_ifcheck_resetornot(dev);
4644 check_reset_cnt = 3;
4645 //DbgPrint("Start to check silent reset\n");
4646 }
4647 spin_unlock_irqrestore(&priv->tx_lock,flags);
4648 if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL)
4649 {
4650 priv->ResetProgress = RESET_TYPE_NORMAL;
4651 RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__FUNCTION__);
4652 return;
4653 }
4654 /* disable silent reset temply 2008.9.11*/
4655 #if 1
4656 if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo
4657 {
4658 last_time = 1;
4659 rtl819x_ifsilentreset(dev);
4660 }
4661 else
4662 last_time = 0;
4663 #endif
4664 priv->force_reset = false;
4665 priv->bForcedSilentReset = false;
4666 priv->bResetInProgress = false;
4667 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
4668
4669 }
4670
4671 void watch_dog_timer_callback(unsigned long data)
4672 {
4673 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
4674 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0);
4675 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
4676
4677 }
4678
4679 static int _rtl8192_up(struct net_device *dev)
4680 {
4681 struct r8192_priv *priv = ieee80211_priv(dev);
4682 //int i;
4683 RT_STATUS init_status = RT_STATUS_SUCCESS;
4684 priv->up=1;
4685 priv->ieee80211->ieee_up=1;
4686 priv->bdisable_nic = false; //YJ,add,091111
4687 RT_TRACE(COMP_INIT, "Bringing up iface");
4688
4689 init_status = rtl8192_adapter_start(dev);
4690 if(init_status != RT_STATUS_SUCCESS)
4691 {
4692 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
4693 return -1;
4694 }
4695 RT_TRACE(COMP_INIT, "start adapter finished\n");
4696 #ifdef RTL8192E
4697 if(priv->ieee80211->eRFPowerState!=eRfOn)
4698 MgntActSet_RF_State(dev, eRfOn, priv->ieee80211->RfOffReason);
4699 #endif
4700 if(priv->ieee80211->state != IEEE80211_LINKED)
4701 ieee80211_softmac_start_protocol(priv->ieee80211);
4702 ieee80211_reset_queue(priv->ieee80211);
4703 watch_dog_timer_callback((unsigned long) dev);
4704 if(!netif_queue_stopped(dev))
4705 netif_start_queue(dev);
4706 else
4707 netif_wake_queue(dev);
4708
4709 return 0;
4710 }
4711
4712
4713 static int rtl8192_open(struct net_device *dev)
4714 {
4715 struct r8192_priv *priv = ieee80211_priv(dev);
4716 int ret;
4717
4718 down(&priv->wx_sem);
4719 ret = rtl8192_up(dev);
4720 up(&priv->wx_sem);
4721 return ret;
4722
4723 }
4724
4725
4726 int rtl8192_up(struct net_device *dev)
4727 {
4728 struct r8192_priv *priv = ieee80211_priv(dev);
4729
4730 if (priv->up == 1) return -1;
4731
4732 return _rtl8192_up(dev);
4733 }
4734
4735
4736 static int rtl8192_close(struct net_device *dev)
4737 {
4738 struct r8192_priv *priv = ieee80211_priv(dev);
4739 int ret;
4740
4741 down(&priv->wx_sem);
4742
4743 ret = rtl8192_down(dev);
4744
4745 up(&priv->wx_sem);
4746
4747 return ret;
4748
4749 }
4750
4751 int rtl8192_down(struct net_device *dev)
4752 {
4753 struct r8192_priv *priv = ieee80211_priv(dev);
4754
4755 if (priv->up == 0) return -1;
4756
4757 #ifdef ENABLE_LPS
4758 //LZM for PS-Poll AID issue. 090429
4759 if(priv->ieee80211->state == IEEE80211_LINKED)
4760 LeisurePSLeave(dev);
4761 #endif
4762
4763 priv->up=0;
4764 priv->ieee80211->ieee_up = 0;
4765 RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
4766 /* FIXME */
4767 if (!netif_queue_stopped(dev))
4768 netif_stop_queue(dev);
4769
4770 rtl8192_irq_disable(dev);
4771 rtl8192_cancel_deferred_work(priv);
4772 deinit_hal_dm(dev);
4773 del_timer_sync(&priv->watch_dog_timer);
4774
4775 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4776
4777 rtl8192_halt_adapter(dev,false);
4778 memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
4779
4780 RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
4781
4782 return 0;
4783 }
4784
4785
4786 void rtl8192_commit(struct net_device *dev)
4787 {
4788 struct r8192_priv *priv = ieee80211_priv(dev);
4789
4790 if (priv->up == 0) return ;
4791
4792
4793 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4794
4795 rtl8192_irq_disable(dev);
4796 rtl8192_halt_adapter(dev,true);
4797 _rtl8192_up(dev);
4798 }
4799
4800 static void rtl8192_restart(struct work_struct *work)
4801 {
4802 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
4803 struct net_device *dev = priv->ieee80211->dev;
4804
4805 down(&priv->wx_sem);
4806
4807 rtl8192_commit(dev);
4808
4809 up(&priv->wx_sem);
4810 }
4811
4812 static void r8192_set_multicast(struct net_device *dev)
4813 {
4814 struct r8192_priv *priv = ieee80211_priv(dev);
4815 short promisc;
4816
4817 //down(&priv->wx_sem);
4818
4819 /* FIXME FIXME */
4820
4821 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4822
4823 if (promisc != priv->promisc) {
4824 ;
4825 // rtl8192_commit(dev);
4826 }
4827
4828 priv->promisc = promisc;
4829
4830 //schedule_work(&priv->reset_wq);
4831 //up(&priv->wx_sem);
4832 }
4833
4834
4835 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
4836 {
4837 struct r8192_priv *priv = ieee80211_priv(dev);
4838 struct sockaddr *addr = mac;
4839
4840 down(&priv->wx_sem);
4841
4842 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
4843
4844 schedule_work(&priv->reset_wq);
4845 up(&priv->wx_sem);
4846
4847 return 0;
4848 }
4849
4850 /* based on ipw2200 driver */
4851 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
4852 {
4853 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4854 struct iwreq *wrq = (struct iwreq *)rq;
4855 int ret=-1;
4856 struct ieee80211_device *ieee = priv->ieee80211;
4857 u32 key[4];
4858 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
4859 struct iw_point *p = &wrq->u.data;
4860 struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
4861
4862 down(&priv->wx_sem);
4863
4864
4865 if (p->length < sizeof(struct ieee_param) || !p->pointer){
4866 ret = -EINVAL;
4867 goto out;
4868 }
4869
4870 ipw = kmalloc(p->length, GFP_KERNEL);
4871 if (ipw == NULL){
4872 ret = -ENOMEM;
4873 goto out;
4874 }
4875 if (copy_from_user(ipw, p->pointer, p->length)) {
4876 kfree(ipw);
4877 ret = -EFAULT;
4878 goto out;
4879 }
4880
4881 switch (cmd) {
4882 case RTL_IOCTL_WPA_SUPPLICANT:
4883 //parse here for HW security
4884 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
4885 {
4886 if (ipw->u.crypt.set_tx)
4887 {
4888 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4889 ieee->pairwise_key_type = KEY_TYPE_CCMP;
4890 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4891 ieee->pairwise_key_type = KEY_TYPE_TKIP;
4892 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4893 {
4894 if (ipw->u.crypt.key_len == 13)
4895 ieee->pairwise_key_type = KEY_TYPE_WEP104;
4896 else if (ipw->u.crypt.key_len == 5)
4897 ieee->pairwise_key_type = KEY_TYPE_WEP40;
4898 }
4899 else
4900 ieee->pairwise_key_type = KEY_TYPE_NA;
4901
4902 if (ieee->pairwise_key_type)
4903 {
4904 memcpy((u8*)key, ipw->u.crypt.key, 16);
4905 EnableHWSecurityConfig8192(dev);
4906 //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
4907 //added by WB.
4908 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4909 if (ieee->auth_mode != 2) //LEAP WEP will never set this.
4910 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4911 }
4912 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){
4913 write_nic_byte(dev, 0x173, 1); //fix aes bug
4914 }
4915
4916 }
4917 else //if (ipw->u.crypt.idx) //group key use idx > 0
4918 {
4919 memcpy((u8*)key, ipw->u.crypt.key, 16);
4920 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4921 ieee->group_key_type= KEY_TYPE_CCMP;
4922 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4923 ieee->group_key_type = KEY_TYPE_TKIP;
4924 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4925 {
4926 if (ipw->u.crypt.key_len == 13)
4927 ieee->group_key_type = KEY_TYPE_WEP104;
4928 else if (ipw->u.crypt.key_len == 5)
4929 ieee->group_key_type = KEY_TYPE_WEP40;
4930 }
4931 else
4932 ieee->group_key_type = KEY_TYPE_NA;
4933
4934 if (ieee->group_key_type)
4935 {
4936 setKey( dev,
4937 ipw->u.crypt.idx,
4938 ipw->u.crypt.idx, //KeyIndex
4939 ieee->group_key_type, //KeyType
4940 broadcast_addr, //MacAddr
4941 0, //DefaultKey
4942 key); //KeyContent
4943 }
4944 }
4945 }
4946 #ifdef JOHN_DEBUG
4947 //john's test 0711
4948 {
4949 int i;
4950 printk("@@ wrq->u pointer = ");
4951 for(i=0;i<wrq->u.data.length;i++){
4952 if(i%10==0) printk("\n");
4953 printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] );
4954 }
4955 printk("\n");
4956 }
4957 #endif /*JOHN_DEBUG*/
4958 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
4959 break;
4960
4961 default:
4962 ret = -EOPNOTSUPP;
4963 break;
4964 }
4965
4966 kfree(ipw);
4967 out:
4968 up(&priv->wx_sem);
4969
4970 return ret;
4971 }
4972
4973 static u8 HwRateToMRate90(bool bIsHT, u8 rate)
4974 {
4975 u8 ret_rate = 0x02;
4976
4977 if(!bIsHT) {
4978 switch(rate) {
4979 case DESC90_RATE1M: ret_rate = MGN_1M; break;
4980 case DESC90_RATE2M: ret_rate = MGN_2M; break;
4981 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
4982 case DESC90_RATE11M: ret_rate = MGN_11M; break;
4983 case DESC90_RATE6M: ret_rate = MGN_6M; break;
4984 case DESC90_RATE9M: ret_rate = MGN_9M; break;
4985 case DESC90_RATE12M: ret_rate = MGN_12M; break;
4986 case DESC90_RATE18M: ret_rate = MGN_18M; break;
4987 case DESC90_RATE24M: ret_rate = MGN_24M; break;
4988 case DESC90_RATE36M: ret_rate = MGN_36M; break;
4989 case DESC90_RATE48M: ret_rate = MGN_48M; break;
4990 case DESC90_RATE54M: ret_rate = MGN_54M; break;
4991
4992 default:
4993 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
4994 break;
4995 }
4996
4997 } else {
4998 switch(rate) {
4999 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
5000 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
5001 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
5002 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
5003 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
5004 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
5005 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
5006 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
5007 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
5008 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
5009 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
5010 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
5011 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
5012 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
5013 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
5014 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
5015 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
5016
5017 default:
5018 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
5019 break;
5020 }
5021 }
5022
5023 return ret_rate;
5024 }
5025
5026 /* Record the TSF time stamp when receiving a packet */
5027 static void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
5028 {
5029 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5030
5031 if(stats->bIsAMPDU && !stats->bFirstMPDU) {
5032 stats->mac_time[0] = priv->LastRxDescTSFLow;
5033 stats->mac_time[1] = priv->LastRxDescTSFHigh;
5034 } else {
5035 priv->LastRxDescTSFLow = stats->mac_time[0];
5036 priv->LastRxDescTSFHigh = stats->mac_time[1];
5037 }
5038 }
5039
5040 static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
5041 {
5042 long signal_power; // in dBm.
5043
5044 // Translate to dBm (x=0.5y-95).
5045 signal_power = (long)((signal_strength_index + 1) >> 1);
5046 signal_power -= 95;
5047
5048 return signal_power;
5049 }
5050
5051 /*
5052 * Update Rx signal related information in the packet reeived
5053 * to RxStats. User application can query RxStats to realize
5054 * current Rx signal status.
5055 *
5056 * In normal operation, user only care about the information of the BSS
5057 * and we shall invoke this function if the packet received is from the BSS.
5058 */
5059 static void
5060 rtl819x_update_rxsignalstatistics8190pci(
5061 struct r8192_priv * priv,
5062 struct ieee80211_rx_stats * pprevious_stats
5063 )
5064 {
5065 int weighting = 0;
5066
5067 //2 <ToDo> Update Rx Statistics (such as signal strength and signal quality).
5068
5069 // Initila state
5070 if(priv->stats.recv_signal_power == 0)
5071 priv->stats.recv_signal_power = pprevious_stats->RecvSignalPower;
5072
5073 // To avoid the past result restricting the statistics sensitivity, weight the current power (5/6) to speed up the
5074 // reaction of smoothed Signal Power.
5075 if(pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
5076 weighting = 5;
5077 else if(pprevious_stats->RecvSignalPower < priv->stats.recv_signal_power)
5078 weighting = (-5);
5079 //
5080 // We need more correct power of received packets and the "SignalStrength" of RxStats have been beautified or translated,
5081 // so we record the correct power in Dbm here. By Bruce, 2008-03-07.
5082 //
5083 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 + pprevious_stats->RecvSignalPower + weighting) / 6;
5084 }
5085
5086 static void
5087 rtl8190_process_cck_rxpathsel(
5088 struct r8192_priv * priv,
5089 struct ieee80211_rx_stats * pprevious_stats
5090 )
5091 {
5092 #ifdef RTL8190P //Only 90P 2T4R need to check
5093 char last_cck_adc_pwdb[4]={0,0,0,0};
5094 u8 i;
5095 //cosa add for Rx path selection
5096 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable)
5097 {
5098 if(pprevious_stats->bIsCCK &&
5099 (pprevious_stats->bPacketToSelf ||pprevious_stats->bPacketBeacon))
5100 {
5101 /* record the cck adc_pwdb to the sliding window. */
5102 if(priv->stats.cck_adc_pwdb.TotalNum++ >= PHY_RSSI_SLID_WIN_MAX)
5103 {
5104 priv->stats.cck_adc_pwdb.TotalNum = PHY_RSSI_SLID_WIN_MAX;
5105 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5106 {
5107 last_cck_adc_pwdb[i] = priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index];
5108 priv->stats.cck_adc_pwdb.TotalVal[i] -= last_cck_adc_pwdb[i];
5109 }
5110 }
5111 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5112 {
5113 priv->stats.cck_adc_pwdb.TotalVal[i] += pprevious_stats->cck_adc_pwdb[i];
5114 priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index] = pprevious_stats->cck_adc_pwdb[i];
5115 }
5116 priv->stats.cck_adc_pwdb.index++;
5117 if(priv->stats.cck_adc_pwdb.index >= PHY_RSSI_SLID_WIN_MAX)
5118 priv->stats.cck_adc_pwdb.index = 0;
5119
5120 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5121 {
5122 DM_RxPathSelTable.cck_pwdb_sta[i] = priv->stats.cck_adc_pwdb.TotalVal[i]/priv->stats.cck_adc_pwdb.TotalNum;
5123 }
5124
5125 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5126 {
5127 if(pprevious_stats->cck_adc_pwdb[i] > (char)priv->undecorated_smoothed_cck_adc_pwdb[i])
5128 {
5129 priv->undecorated_smoothed_cck_adc_pwdb[i] =
5130 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
5131 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
5132 priv->undecorated_smoothed_cck_adc_pwdb[i] = priv->undecorated_smoothed_cck_adc_pwdb[i] + 1;
5133 }
5134 else
5135 {
5136 priv->undecorated_smoothed_cck_adc_pwdb[i] =
5137 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
5138 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
5139 }
5140 }
5141 }
5142 }
5143 #endif
5144 }
5145
5146
5147 /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to
5148 be a local static. Otherwise, it may increase when we return from S3/S4. The
5149 value will be kept in memory or disk. We must delcare the value in adapter
5150 and it will be reinitialized when return from S3/S4. */
5151 static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
5152 {
5153 bool bcheck = false;
5154 u8 rfpath;
5155 u32 nspatial_stream, tmp_val;
5156 //u8 i;
5157 static u32 slide_rssi_index=0, slide_rssi_statistics=0;
5158 static u32 slide_evm_index=0, slide_evm_statistics=0;
5159 static u32 last_rssi=0, last_evm=0;
5160 //cosa add for rx path selection
5161 // static long slide_cck_adc_pwdb_index=0, slide_cck_adc_pwdb_statistics=0;
5162 // static char last_cck_adc_pwdb[4]={0,0,0,0};
5163 //cosa add for beacon rssi smoothing
5164 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
5165 static u32 last_beacon_adc_pwdb=0;
5166
5167 struct ieee80211_hdr_3addr *hdr;
5168 u16 sc ;
5169 unsigned int frag,seq;
5170 hdr = (struct ieee80211_hdr_3addr *)buffer;
5171 sc = le16_to_cpu(hdr->seq_ctl);
5172 frag = WLAN_GET_SEQ_FRAG(sc);
5173 seq = WLAN_GET_SEQ_SEQ(sc);
5174 //cosa add 04292008 to record the sequence number
5175 pcurrent_stats->Seq_Num = seq;
5176 //
5177 // Check whether we should take the previous packet into accounting
5178 //
5179 if(!pprevious_stats->bIsAMPDU)
5180 {
5181 // if previous packet is not aggregated packet
5182 bcheck = true;
5183 }else
5184 {
5185 //remve for that we don't use AMPDU to calculate PWDB,because the reported PWDB of some AP is fault.
5186 #if 0
5187 // if previous packet is aggregated packet, and current packet
5188 // (1) is not AMPDU
5189 // (2) is the first packet of one AMPDU
5190 // that means the previous packet is the last one aggregated packet
5191 if( !pcurrent_stats->bIsAMPDU || pcurrent_stats->bFirstMPDU)
5192 bcheck = true;
5193 #endif
5194 }
5195
5196 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
5197 {
5198 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
5199 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
5200 priv->stats.slide_rssi_total -= last_rssi;
5201 }
5202 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
5203
5204 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
5205 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
5206 slide_rssi_index = 0;
5207
5208 // <1> Showed on UI for user, in dbm
5209 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
5210 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
5211 pcurrent_stats->rssi = priv->stats.signal_strength;
5212 //
5213 // If the previous packet does not match the criteria, neglect it
5214 //
5215 if(!pprevious_stats->bPacketMatchBSSID)
5216 {
5217 if(!pprevious_stats->bToSelfBA)
5218 return;
5219 }
5220
5221 if(!bcheck)
5222 return;
5223
5224 rtl8190_process_cck_rxpathsel(priv,pprevious_stats);
5225
5226 //
5227 // Check RSSI
5228 //
5229 priv->stats.num_process_phyinfo++;
5230 #if 0
5231 /* record the general signal strength to the sliding window. */
5232 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
5233 {
5234 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
5235 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
5236 priv->stats.slide_rssi_total -= last_rssi;
5237 }
5238 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
5239
5240 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
5241 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
5242 slide_rssi_index = 0;
5243
5244 // <1> Showed on UI for user, in dbm
5245 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
5246 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
5247
5248 #endif
5249 // <2> Showed on UI for engineering
5250 // hardware does not provide rssi information for each rf path in CCK
5251 if(!pprevious_stats->bIsCCK && pprevious_stats->bPacketToSelf)
5252 {
5253 for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++)
5254 {
5255 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
5256 continue;
5257 RT_TRACE(COMP_DBG,"Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d \n" ,pprevious_stats->RxMIMOSignalStrength[rfpath] );
5258 //Fixed by Jacken 2008-03-20
5259 if(priv->stats.rx_rssi_percentage[rfpath] == 0)
5260 {
5261 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
5262 //DbgPrint("MIMO RSSI initialize \n");
5263 }
5264 if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath])
5265 {
5266 priv->stats.rx_rssi_percentage[rfpath] =
5267 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5268 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5269 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
5270 }
5271 else
5272 {
5273 priv->stats.rx_rssi_percentage[rfpath] =
5274 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5275 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5276 }
5277 RT_TRACE(COMP_DBG,"Jacken -> priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
5278 }
5279 }
5280
5281
5282 //
5283 // Check PWDB.
5284 //
5285 //cosa add for beacon rssi smoothing by average.
5286 if(pprevious_stats->bPacketBeacon)
5287 {
5288 /* record the beacon pwdb to the sliding window. */
5289 if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5290 {
5291 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
5292 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
5293 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
5294 //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n",
5295 // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
5296 }
5297 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
5298 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
5299 //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll);
5300 slide_beacon_adc_pwdb_index++;
5301 if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5302 slide_beacon_adc_pwdb_index = 0;
5303 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
5304 if(pprevious_stats->RxPWDBAll >= 3)
5305 pprevious_stats->RxPWDBAll -= 3;
5306 }
5307
5308 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
5309 pprevious_stats->bIsCCK? "CCK": "OFDM",
5310 pprevious_stats->RxPWDBAll);
5311
5312 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5313 {
5314 if(priv->undecorated_smoothed_pwdb < 0) // initialize
5315 {
5316 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
5317 //DbgPrint("First pwdb initialize \n");
5318 }
5319 #if 1
5320 if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
5321 {
5322 priv->undecorated_smoothed_pwdb =
5323 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5324 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5325 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
5326 }
5327 else
5328 {
5329 priv->undecorated_smoothed_pwdb =
5330 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5331 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5332 }
5333 #else
5334 //Fixed by Jacken 2008-03-20
5335 if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB)
5336 {
5337 pHalData->UndecoratedSmoothedPWDB =
5338 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5339 pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1;
5340 }
5341 else
5342 {
5343 pHalData->UndecoratedSmoothedPWDB =
5344 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5345 }
5346 #endif
5347 rtl819x_update_rxsignalstatistics8190pci(priv,pprevious_stats);
5348 }
5349
5350 //
5351 // Check EVM
5352 //
5353 /* record the general EVM to the sliding window. */
5354 if(pprevious_stats->SignalQuality == 0)
5355 {
5356 }
5357 else
5358 {
5359 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
5360 if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
5361 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
5362 last_evm = priv->stats.slide_evm[slide_evm_index];
5363 priv->stats.slide_evm_total -= last_evm;
5364 }
5365
5366 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
5367
5368 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
5369 if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
5370 slide_evm_index = 0;
5371
5372 // <1> Showed on UI for user, in percentage.
5373 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
5374 priv->stats.signal_quality = tmp_val;
5375 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
5376 priv->stats.last_signal_strength_inpercent = tmp_val;
5377 }
5378
5379 // <2> Showed on UI for engineering
5380 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5381 {
5382 for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
5383 {
5384 if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
5385 {
5386 if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
5387 {
5388 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
5389 }
5390 priv->stats.rx_evm_percentage[nspatial_stream] =
5391 ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
5392 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
5393 }
5394 }
5395 }
5396 }
5397
5398 }
5399
5400 static u8 rtl819x_query_rxpwrpercentage(
5401 char antpower
5402 )
5403 {
5404 if ((antpower <= -100) || (antpower >= 20))
5405 {
5406 return 0;
5407 }
5408 else if (antpower >= 0)
5409 {
5410 return 100;
5411 }
5412 else
5413 {
5414 return (100+antpower);
5415 }
5416
5417 }
5418
5419 static u8
5420 rtl819x_evm_dbtopercentage(
5421 char value
5422 )
5423 {
5424 char ret_val;
5425
5426 ret_val = value;
5427
5428 if(ret_val >= 0)
5429 ret_val = 0;
5430 if(ret_val <= -33)
5431 ret_val = -33;
5432 ret_val = 0 - ret_val;
5433 ret_val*=3;
5434 if(ret_val == 99)
5435 ret_val = 100;
5436 return ret_val;
5437 }
5438
5439 /* We want good-looking for signal strength/quality */
5440 static long rtl819x_signal_scale_mapping(long currsig)
5441 {
5442 long retsig;
5443
5444 // Step 1. Scale mapping.
5445 if(currsig >= 61 && currsig <= 100)
5446 {
5447 retsig = 90 + ((currsig - 60) / 4);
5448 }
5449 else if(currsig >= 41 && currsig <= 60)
5450 {
5451 retsig = 78 + ((currsig - 40) / 2);
5452 }
5453 else if(currsig >= 31 && currsig <= 40)
5454 {
5455 retsig = 66 + (currsig - 30);
5456 }
5457 else if(currsig >= 21 && currsig <= 30)
5458 {
5459 retsig = 54 + (currsig - 20);
5460 }
5461 else if(currsig >= 5 && currsig <= 20)
5462 {
5463 retsig = 42 + (((currsig - 5) * 2) / 3);
5464 }
5465 else if(currsig == 4)
5466 {
5467 retsig = 36;
5468 }
5469 else if(currsig == 3)
5470 {
5471 retsig = 27;
5472 }
5473 else if(currsig == 2)
5474 {
5475 retsig = 18;
5476 }
5477 else if(currsig == 1)
5478 {
5479 retsig = 9;
5480 }
5481 else
5482 {
5483 retsig = currsig;
5484 }
5485
5486 return retsig;
5487 }
5488
5489 static void rtl8192_query_rxphystatus(
5490 struct r8192_priv * priv,
5491 struct ieee80211_rx_stats * pstats,
5492 prx_desc_819x_pci pdesc,
5493 prx_fwinfo_819x_pci pdrvinfo,
5494 struct ieee80211_rx_stats * precord_stats,
5495 bool bpacket_match_bssid,
5496 bool bpacket_toself,
5497 bool bPacketBeacon,
5498 bool bToSelfBA
5499 )
5500 {
5501 //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status);
5502 phy_sts_ofdm_819xpci_t* pofdm_buf;
5503 phy_sts_cck_819xpci_t * pcck_buf;
5504 phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
5505 u8 *prxpkt;
5506 u8 i,max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
5507 char rx_pwr[4], rx_pwr_all=0;
5508 //long rx_avg_pwr = 0;
5509 char rx_snrX, rx_evmX;
5510 u8 evm, pwdb_all;
5511 u32 RSSI, total_rssi=0;//, total_evm=0;
5512 // long signal_strength_index = 0;
5513 u8 is_cck_rate=0;
5514 u8 rf_rx_num = 0;
5515
5516 /* 2007/07/04 MH For OFDM RSSI. For high power or not. */
5517 static u8 check_reg824 = 0;
5518 static u32 reg824_bit9 = 0;
5519
5520 priv->stats.numqry_phystatus++;
5521
5522 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
5523
5524 // Record it for next packet processing
5525 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
5526 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
5527 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
5528 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
5529 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
5530 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
5531 /*2007.08.30 requested by SD3 Jerry */
5532 if(check_reg824 == 0)
5533 {
5534 reg824_bit9 = rtl8192_QueryBBReg(priv->ieee80211->dev, rFPGA0_XA_HSSIParameter2, 0x200);
5535 check_reg824 = 1;
5536 }
5537
5538
5539 prxpkt = (u8*)pdrvinfo;
5540
5541 /* Move pointer to the 16th bytes. Phy status start address. */
5542 prxpkt += sizeof(rx_fwinfo_819x_pci);
5543
5544 /* Initial the cck and ofdm buffer pointer */
5545 pcck_buf = (phy_sts_cck_819xpci_t *)prxpkt;
5546 pofdm_buf = (phy_sts_ofdm_819xpci_t *)prxpkt;
5547
5548 pstats->RxMIMOSignalQuality[0] = -1;
5549 pstats->RxMIMOSignalQuality[1] = -1;
5550 precord_stats->RxMIMOSignalQuality[0] = -1;
5551 precord_stats->RxMIMOSignalQuality[1] = -1;
5552
5553 if(is_cck_rate)
5554 {
5555 //
5556 // (1)Hardware does not provide RSSI for CCK
5557 //
5558
5559 //
5560 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5561 //
5562 u8 report;//, cck_agc_rpt;
5563 #ifdef RTL8190P
5564 u8 tmp_pwdb;
5565 char cck_adc_pwdb[4];
5566 #endif
5567 priv->stats.numqry_phystatusCCK++;
5568
5569 #ifdef RTL8190P //Only 90P 2T4R need to check
5570 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable && bpacket_match_bssid)
5571 {
5572 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5573 {
5574 tmp_pwdb = pcck_buf->adc_pwdb_X[i];
5575 cck_adc_pwdb[i] = (char)tmp_pwdb;
5576 cck_adc_pwdb[i] /= 2;
5577 pstats->cck_adc_pwdb[i] = precord_stats->cck_adc_pwdb[i] = cck_adc_pwdb[i];
5578 //DbgPrint("RF-%d tmp_pwdb = 0x%x, cck_adc_pwdb = %d", i, tmp_pwdb, cck_adc_pwdb[i]);
5579 }
5580 }
5581 #endif
5582
5583 if(!reg824_bit9)
5584 {
5585 report = pcck_buf->cck_agc_rpt & 0xc0;
5586 report = report>>6;
5587 switch(report)
5588 {
5589 //Fixed by Jacken from Bryant 2008-03-20
5590 //Original value is -38 , -26 , -14 , -2
5591 //Fixed value is -35 , -23 , -11 , 6
5592 case 0x3:
5593 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
5594 break;
5595 case 0x2:
5596 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
5597 break;
5598 case 0x1:
5599 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
5600 break;
5601 case 0x0:
5602 rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e);
5603 break;
5604 }
5605 }
5606 else
5607 {
5608 report = pcck_buf->cck_agc_rpt & 0x60;
5609 report = report>>5;
5610 switch(report)
5611 {
5612 case 0x3:
5613 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5614 break;
5615 case 0x2:
5616 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
5617 break;
5618 case 0x1:
5619 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5620 break;
5621 case 0x0:
5622 rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5623 break;
5624 }
5625 }
5626
5627 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5628 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5629 pstats->RecvSignalPower = rx_pwr_all;
5630
5631 //
5632 // (3) Get Signal Quality (EVM)
5633 //
5634 if(bpacket_match_bssid)
5635 {
5636 u8 sq;
5637
5638 if(pstats->RxPWDBAll > 40)
5639 {
5640 sq = 100;
5641 }else
5642 {
5643 sq = pcck_buf->sq_rpt;
5644
5645 if(pcck_buf->sq_rpt > 64)
5646 sq = 0;
5647 else if (pcck_buf->sq_rpt < 20)
5648 sq = 100;
5649 else
5650 sq = ((64-sq) * 100) / 44;
5651 }
5652 pstats->SignalQuality = precord_stats->SignalQuality = sq;
5653 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
5654 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
5655 }
5656 }
5657 else
5658 {
5659 priv->stats.numqry_phystatusHT++;
5660 //
5661 // (1)Get RSSI for HT rate
5662 //
5663 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5664 {
5665 // 2008/01/30 MH we will judge RF RX path now.
5666 if (priv->brfpath_rxenable[i])
5667 rf_rx_num++;
5668 //else
5669 //continue;
5670
5671 //Fixed by Jacken from Bryant 2008-03-20
5672 //Original value is 106
5673 #ifdef RTL8190P //Modify by Jacken 2008/03/31
5674 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
5675 #else
5676 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 110;
5677 #endif
5678
5679 //Get Rx snr value in DB
5680 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
5681 rx_snrX = (char)(tmp_rxsnr);
5682 rx_snrX /= 2;
5683 priv->stats.rxSNRdB[i] = (long)rx_snrX;
5684
5685 /* Translate DBM to percentage. */
5686 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
5687 if (priv->brfpath_rxenable[i])
5688 total_rssi += RSSI;
5689
5690 /* Record Signal Strength for next packet */
5691 if(bpacket_match_bssid)
5692 {
5693 pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
5694 precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
5695 }
5696 }
5697
5698
5699 //
5700 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5701 //
5702 //Fixed by Jacken from Bryant 2008-03-20
5703 //Original value is 106
5704 rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
5705 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5706
5707 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5708 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
5709 pstats->RecvSignalPower = rx_pwr_all;
5710 //
5711 // (3)EVM of HT rate
5712 //
5713 if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
5714 pdrvinfo->RxRate<=DESC90_RATEMCS15)
5715 max_spatial_stream = 2; //both spatial stream make sense
5716 else
5717 max_spatial_stream = 1; //only spatial stream 1 makes sense
5718
5719 for(i=0; i<max_spatial_stream; i++)
5720 {
5721 tmp_rxevm = pofdm_buf->rxevm_X[i];
5722 rx_evmX = (char)(tmp_rxevm);
5723
5724 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
5725 // fill most significant bit to "zero" when doing shifting operation which may change a negative
5726 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
5727 rx_evmX /= 2; //dbm
5728
5729 evm = rtl819x_evm_dbtopercentage(rx_evmX);
5730 #if 0
5731 EVM = SignalScaleMapping(EVM);//make it good looking, from 0~100
5732 #endif
5733 if(bpacket_match_bssid)
5734 {
5735 if(i==0) // Fill value in RFD, Get the first spatial stream only
5736 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
5737 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
5738 }
5739 }
5740
5741
5742 /* record rx statistics for debug */
5743 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
5744 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
5745 if(pdrvinfo->BW) //40M channel
5746 priv->stats.received_bwtype[1+prxsc->rxsc]++;
5747 else //20M channel
5748 priv->stats.received_bwtype[0]++;
5749 }
5750
5751 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
5752 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
5753 if(is_cck_rate)
5754 {
5755 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;
5756
5757 }
5758 else
5759 {
5760 //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u1Byte)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u1Byte)(total_rssi/=RF90_PATH_MAX);
5761 // We can judge RX path number now.
5762 if (rf_rx_num != 0)
5763 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
5764 }
5765 }
5766
5767 static void
5768 rtl8192_record_rxdesc_forlateruse(
5769 struct ieee80211_rx_stats * psrc_stats,
5770 struct ieee80211_rx_stats * ptarget_stats
5771 )
5772 {
5773 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
5774 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
5775 //ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
5776 }
5777
5778
5779
5780 static void TranslateRxSignalStuff819xpci(struct net_device *dev,
5781 struct sk_buff *skb,
5782 struct ieee80211_rx_stats * pstats,
5783 prx_desc_819x_pci pdesc,
5784 prx_fwinfo_819x_pci pdrvinfo)
5785 {
5786 // TODO: We must only check packet for current MAC address. Not finish
5787 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5788 bool bpacket_match_bssid, bpacket_toself;
5789 bool bPacketBeacon=false, bToSelfBA=false;
5790 static struct ieee80211_rx_stats previous_stats;
5791 struct ieee80211_hdr_3addr *hdr;
5792 u16 fc,type;
5793
5794 // Get Signal Quality for only RX data queue (but not command queue)
5795
5796 u8* tmp_buf;
5797 u8 *praddr;
5798
5799 /* Get MAC frame start address. */
5800 tmp_buf = skb->data;
5801
5802 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
5803 fc = le16_to_cpu(hdr->frame_ctl);
5804 type = WLAN_FC_GET_TYPE(fc);
5805 praddr = hdr->addr1;
5806
5807 /* Check if the received packet is acceptabe. */
5808 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
5809 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
5810 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
5811 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
5812 #if 1//cosa
5813 if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
5814 {
5815 bPacketBeacon = true;
5816 //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
5817 }
5818 if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
5819 {
5820 if((eqMacAddr(praddr,dev->dev_addr)))
5821 bToSelfBA = true;
5822 //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
5823 }
5824
5825 #endif
5826 if(bpacket_match_bssid)
5827 {
5828 priv->stats.numpacket_matchbssid++;
5829 }
5830 if(bpacket_toself){
5831 priv->stats.numpacket_toself++;
5832 }
5833 //
5834 // Process PHY information for previous packet (RSSI/PWDB/EVM)
5835 //
5836 // Because phy information is contained in the last packet of AMPDU only, so driver
5837 // should process phy information of previous packet
5838 rtl8192_process_phyinfo(priv, tmp_buf,&previous_stats, pstats);
5839 rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, &previous_stats, bpacket_match_bssid,
5840 bpacket_toself ,bPacketBeacon, bToSelfBA);
5841 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
5842
5843 }
5844
5845
5846 static void rtl8192_tx_resume(struct net_device *dev)
5847 {
5848 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5849 struct ieee80211_device *ieee = priv->ieee80211;
5850 struct sk_buff *skb;
5851 int queue_index;
5852
5853 for(queue_index = BK_QUEUE; queue_index < TXCMD_QUEUE;queue_index++) {
5854 while((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&&
5855 (priv->ieee80211->check_nic_enough_desc(dev,queue_index) > 0)) {
5856 /* 1. dequeue the packet from the wait queue */
5857 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
5858 /* 2. tx the packet directly */
5859 ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/);
5860 #if 0
5861 if(queue_index!=MGNT_QUEUE) {
5862 ieee->stats.tx_packets++;
5863 ieee->stats.tx_bytes += skb->len;
5864 }
5865 #endif
5866 }
5867 }
5868 }
5869
5870 static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
5871 {
5872 rtl8192_tx_resume(priv->ieee80211->dev);
5873 }
5874
5875 /* Record the received data rate */
5876 static void UpdateReceivedRateHistogramStatistics8190(
5877 struct net_device *dev,
5878 struct ieee80211_rx_stats* pstats
5879 )
5880 {
5881 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5882 u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV
5883 u32 rateIndex;
5884 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
5885
5886 if(pstats->bCRC)
5887 rcvType = 2;
5888 else if(pstats->bICV)
5889 rcvType = 3;
5890
5891 if(pstats->bShortPreamble)
5892 preamble_guardinterval = 1;// short
5893 else
5894 preamble_guardinterval = 0;// long
5895
5896 switch(pstats->rate)
5897 {
5898 //
5899 // CCK rate
5900 //
5901 case MGN_1M: rateIndex = 0; break;
5902 case MGN_2M: rateIndex = 1; break;
5903 case MGN_5_5M: rateIndex = 2; break;
5904 case MGN_11M: rateIndex = 3; break;
5905 //
5906 // Legacy OFDM rate
5907 //
5908 case MGN_6M: rateIndex = 4; break;
5909 case MGN_9M: rateIndex = 5; break;
5910 case MGN_12M: rateIndex = 6; break;
5911 case MGN_18M: rateIndex = 7; break;
5912 case MGN_24M: rateIndex = 8; break;
5913 case MGN_36M: rateIndex = 9; break;
5914 case MGN_48M: rateIndex = 10; break;
5915 case MGN_54M: rateIndex = 11; break;
5916 //
5917 // 11n High throughput rate
5918 //
5919 case MGN_MCS0: rateIndex = 12; break;
5920 case MGN_MCS1: rateIndex = 13; break;
5921 case MGN_MCS2: rateIndex = 14; break;
5922 case MGN_MCS3: rateIndex = 15; break;
5923 case MGN_MCS4: rateIndex = 16; break;
5924 case MGN_MCS5: rateIndex = 17; break;
5925 case MGN_MCS6: rateIndex = 18; break;
5926 case MGN_MCS7: rateIndex = 19; break;
5927 case MGN_MCS8: rateIndex = 20; break;
5928 case MGN_MCS9: rateIndex = 21; break;
5929 case MGN_MCS10: rateIndex = 22; break;
5930 case MGN_MCS11: rateIndex = 23; break;
5931 case MGN_MCS12: rateIndex = 24; break;
5932 case MGN_MCS13: rateIndex = 25; break;
5933 case MGN_MCS14: rateIndex = 26; break;
5934 case MGN_MCS15: rateIndex = 27; break;
5935 default: rateIndex = 28; break;
5936 }
5937 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
5938 priv->stats.received_rate_histogram[0][rateIndex]++; //total
5939 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
5940 }
5941
5942 static void rtl8192_rx(struct net_device *dev)
5943 {
5944 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5945 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
5946 bool unicast_packet = false;
5947 struct ieee80211_rx_stats stats = {
5948 .signal = 0,
5949 .noise = -98,
5950 .rate = 0,
5951 .freq = IEEE80211_24GHZ_BAND,
5952 };
5953 unsigned int count = priv->rxringcount;
5954
5955 stats.nic_type = NIC_8192E;
5956
5957 while (count--) {
5958 rx_desc_819x_pci *pdesc = &priv->rx_ring[priv->rx_idx];//rx descriptor
5959 struct sk_buff *skb = priv->rx_buf[priv->rx_idx];//rx pkt
5960
5961 if (pdesc->OWN){
5962 /* wait data to be filled by hardware */
5963 return;
5964 } else {
5965 stats.bICV = pdesc->ICV;
5966 stats.bCRC = pdesc->CRC32;
5967 stats.bHwError = pdesc->CRC32 | pdesc->ICV;
5968
5969 stats.Length = pdesc->Length;
5970 if(stats.Length < 24)
5971 stats.bHwError |= 1;
5972
5973 if(stats.bHwError) {
5974 stats.bShift = false;
5975
5976 if(pdesc->CRC32) {
5977 if (pdesc->Length <500)
5978 priv->stats.rxcrcerrmin++;
5979 else if (pdesc->Length >1000)
5980 priv->stats.rxcrcerrmax++;
5981 else
5982 priv->stats.rxcrcerrmid++;
5983 }
5984 goto done;
5985 } else {
5986 prx_fwinfo_819x_pci pDrvInfo = NULL;
5987 struct sk_buff *new_skb = dev_alloc_skb(priv->rxbuffersize);
5988
5989 if (unlikely(!new_skb)) {
5990 goto done;
5991 }
5992
5993 stats.RxDrvInfoSize = pdesc->RxDrvInfoSize;
5994 stats.RxBufShift = ((pdesc->Shift)&0x03);
5995 stats.Decrypted = !pdesc->SWDec;
5996
5997 pci_dma_sync_single_for_cpu(priv->pdev,
5998 *((dma_addr_t *)skb->cb),
5999 priv->rxbuffersize,
6000 PCI_DMA_FROMDEVICE);
6001 skb_put(skb, pdesc->Length);
6002 pDrvInfo = (rx_fwinfo_819x_pci *)(skb->data + stats.RxBufShift);
6003 skb_reserve(skb, stats.RxDrvInfoSize + stats.RxBufShift);
6004
6005 stats.rate = HwRateToMRate90((bool)pDrvInfo->RxHT, (u8)pDrvInfo->RxRate);
6006 stats.bShortPreamble = pDrvInfo->SPLCP;
6007
6008 /* it is debug only. It should be disabled in released driver.
6009 * 2007.1.11 by Emily
6010 * */
6011 UpdateReceivedRateHistogramStatistics8190(dev, &stats);
6012
6013 stats.bIsAMPDU = (pDrvInfo->PartAggr==1);
6014 stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1);
6015
6016 stats.TimeStampLow = pDrvInfo->TSFL;
6017 stats.TimeStampHigh = read_nic_dword(dev, TSFR+4);
6018
6019 UpdateRxPktTimeStamp8190(dev, &stats);
6020
6021 //
6022 // Get Total offset of MPDU Frame Body
6023 //
6024 if((stats.RxBufShift + stats.RxDrvInfoSize) > 0)
6025 stats.bShift = 1;
6026
6027 stats.RxIs40MHzPacket = pDrvInfo->BW;
6028
6029 /* ???? */
6030 TranslateRxSignalStuff819xpci(dev,skb, &stats, pdesc, pDrvInfo);
6031
6032 /* Rx A-MPDU */
6033 if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1)
6034 RT_TRACE(COMP_RXDESC, "pDrvInfo->FirstAGGR = %d, pDrvInfo->PartAggr = %d\n",
6035 pDrvInfo->FirstAGGR, pDrvInfo->PartAggr);
6036 skb_trim(skb, skb->len - 4/*sCrcLng*/);
6037 /* rx packets statistics */
6038 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
6039 unicast_packet = false;
6040
6041 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
6042 //TODO
6043 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
6044 //TODO
6045 }else {
6046 /* unicast packet */
6047 unicast_packet = true;
6048 }
6049
6050 stats.packetlength = stats.Length-4;
6051 stats.fraglength = stats.packetlength;
6052 stats.fragoffset = 0;
6053 stats.ntotalfrag = 1;
6054
6055 if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){
6056 dev_kfree_skb_any(skb);
6057 } else {
6058 priv->stats.rxok++;
6059 if(unicast_packet) {
6060 priv->stats.rxbytesunicast += skb->len;
6061 }
6062 }
6063
6064 skb = new_skb;
6065 priv->rx_buf[priv->rx_idx] = skb;
6066 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE);
6067 }
6068
6069 }
6070 done:
6071 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
6072 pdesc->OWN = 1;
6073 pdesc->Length = priv->rxbuffersize;
6074 if (priv->rx_idx == priv->rxringcount-1)
6075 pdesc->EOR = 1;
6076 priv->rx_idx = (priv->rx_idx + 1) % priv->rxringcount;
6077 }
6078
6079 }
6080
6081 static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
6082 {
6083 rtl8192_rx(priv->ieee80211->dev);
6084 /* unmask RDU */
6085 write_nic_dword(priv->ieee80211->dev, INTA_MASK,read_nic_dword(priv->ieee80211->dev, INTA_MASK) | IMR_RDU);
6086 }
6087
6088 static const struct net_device_ops rtl8192_netdev_ops = {
6089 .ndo_open = rtl8192_open,
6090 .ndo_stop = rtl8192_close,
6091 .ndo_tx_timeout = tx_timeout,
6092 .ndo_do_ioctl = rtl8192_ioctl,
6093 .ndo_set_multicast_list = r8192_set_multicast,
6094 .ndo_set_mac_address = r8192_set_mac_adr,
6095 .ndo_start_xmit = ieee80211_rtl_xmit,
6096 };
6097
6098 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
6099 const struct pci_device_id *id)
6100 {
6101 unsigned long ioaddr = 0;
6102 struct net_device *dev = NULL;
6103 struct r8192_priv *priv= NULL;
6104 u8 unit = 0;
6105 int ret = -ENODEV;
6106
6107 #ifdef CONFIG_RTL8192_IO_MAP
6108 unsigned long pio_start, pio_len, pio_flags;
6109 #else
6110 unsigned long pmem_start, pmem_len, pmem_flags;
6111 #endif //end #ifdef RTL_IO_MAP
6112
6113 RT_TRACE(COMP_INIT,"Configuring chip resources");
6114
6115 if( pci_enable_device (pdev) ){
6116 RT_TRACE(COMP_ERR,"Failed to enable PCI device");
6117 return -EIO;
6118 }
6119
6120 pci_set_master(pdev);
6121 //pci_set_wmi(pdev);
6122 pci_set_dma_mask(pdev, 0xffffff00ULL);
6123 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
6124 dev = alloc_ieee80211(sizeof(struct r8192_priv));
6125 if (!dev) {
6126 ret = -ENOMEM;
6127 goto fail_free;
6128 }
6129
6130 pci_set_drvdata(pdev, dev);
6131 SET_NETDEV_DEV(dev, &pdev->dev);
6132 priv = ieee80211_priv(dev);
6133 priv->ieee80211 = netdev_priv(dev);
6134 priv->pdev=pdev;
6135 if((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304)){
6136 priv->ieee80211->bSupportRemoteWakeUp = 1;
6137 } else
6138 {
6139 priv->ieee80211->bSupportRemoteWakeUp = 0;
6140 }
6141
6142 #ifdef CONFIG_RTL8192_IO_MAP
6143
6144 pio_start = (unsigned long)pci_resource_start (pdev, 0);
6145 pio_len = (unsigned long)pci_resource_len (pdev, 0);
6146 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
6147
6148 if (!(pio_flags & IORESOURCE_IO)) {
6149 RT_TRACE(COMP_ERR,"region #0 not a PIO resource, aborting");
6150 goto fail;
6151 }
6152
6153 //DMESG("IO space @ 0x%08lx", pio_start );
6154 if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){
6155 RT_TRACE(COMP_ERR,"request_region failed!");
6156 goto fail;
6157 }
6158
6159 ioaddr = pio_start;
6160 dev->base_addr = ioaddr; // device I/O address
6161
6162 #else
6163
6164 pmem_start = pci_resource_start(pdev, 1);
6165 pmem_len = pci_resource_len(pdev, 1);
6166 pmem_flags = pci_resource_flags (pdev, 1);
6167
6168 if (!(pmem_flags & IORESOURCE_MEM)) {
6169 RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting");
6170 goto fail;
6171 }
6172
6173 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
6174 if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) {
6175 RT_TRACE(COMP_ERR,"request_mem_region failed!");
6176 goto fail;
6177 }
6178
6179
6180 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
6181 if( ioaddr == (unsigned long)NULL ){
6182 RT_TRACE(COMP_ERR,"ioremap failed!");
6183 // release_mem_region( pmem_start, pmem_len );
6184 goto fail1;
6185 }
6186
6187 dev->mem_start = ioaddr; // shared mem start
6188 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
6189
6190 #endif //end #ifdef RTL_IO_MAP
6191
6192 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6193 * PCI Tx retries from interfering with C3 CPU state */
6194 pci_write_config_byte(pdev, 0x41, 0x00);
6195
6196
6197 pci_read_config_byte(pdev, 0x05, &unit);
6198 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
6199
6200 dev->irq = pdev->irq;
6201 priv->irq = 0;
6202
6203 dev->netdev_ops = &rtl8192_netdev_ops;
6204 #if 0
6205 dev->open = rtl8192_open;
6206 dev->stop = rtl8192_close;
6207 //dev->hard_start_xmit = rtl8192_8023_hard_start_xmit;
6208 dev->tx_timeout = tx_timeout;
6209 //dev->wireless_handlers = &r8192_wx_handlers_def;
6210 dev->do_ioctl = rtl8192_ioctl;
6211 dev->set_multicast_list = r8192_set_multicast;
6212 dev->set_mac_address = r8192_set_mac_adr;
6213 #endif
6214
6215 //DMESG("Oops: i'm coming\n");
6216 #if WIRELESS_EXT >= 12
6217 #if WIRELESS_EXT < 17
6218 dev->get_wireless_stats = r8192_get_wireless_stats;
6219 #endif
6220 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
6221 #endif
6222 //dev->get_wireless_stats = r8192_get_wireless_stats;
6223 dev->type=ARPHRD_ETHER;
6224
6225 dev->watchdog_timeo = HZ*3; //modified by john, 0805
6226
6227 if (dev_alloc_name(dev, ifname) < 0){
6228 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
6229 strcpy(ifname, "wlan%d");
6230 dev_alloc_name(dev, ifname);
6231 }
6232
6233 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
6234 if(rtl8192_init(dev)!=0){
6235 RT_TRACE(COMP_ERR, "Initialization failed");
6236 goto fail;
6237 }
6238
6239 netif_carrier_off(dev);
6240 netif_stop_queue(dev);
6241
6242 register_netdev(dev);
6243 RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
6244 rtl8192_proc_init_one(dev);
6245
6246
6247 RT_TRACE(COMP_INIT, "Driver probe completed\n");
6248 return 0;
6249
6250 fail1:
6251
6252 #ifdef CONFIG_RTL8180_IO_MAP
6253
6254 if( dev->base_addr != 0 ){
6255
6256 release_region(dev->base_addr,
6257 pci_resource_len(pdev, 0) );
6258 }
6259 #else
6260 if( dev->mem_start != (unsigned long)NULL ){
6261 iounmap( (void *)dev->mem_start );
6262 release_mem_region( pci_resource_start(pdev, 1),
6263 pci_resource_len(pdev, 1) );
6264 }
6265 #endif //end #ifdef RTL_IO_MAP
6266
6267 fail:
6268 if(dev){
6269
6270 if (priv->irq) {
6271 free_irq(dev->irq, dev);
6272 dev->irq=0;
6273 }
6274 free_ieee80211(dev);
6275 }
6276
6277 fail_free:
6278 pci_disable_device(pdev);
6279
6280 DMESG("wlan driver load failed\n");
6281 pci_set_drvdata(pdev, NULL);
6282 return ret;
6283
6284 }
6285
6286 /* detach all the work and timer structure declared or inititialized
6287 * in r8192_init function.
6288 * */
6289 static void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
6290 {
6291 /* call cancel_work_sync instead of cancel_delayed_work if and only if Linux_version_code
6292 * is or is newer than 2.6.20 and work structure is defined to be struct work_struct.
6293 * Otherwise call cancel_delayed_work is enough.
6294 * FIXME (2.6.20 should 2.6.22, work_struct should not cancel)
6295 * */
6296 cancel_delayed_work(&priv->watch_dog_wq);
6297 cancel_delayed_work(&priv->update_beacon_wq);
6298 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
6299 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
6300 #ifdef RTL8192E
6301 cancel_delayed_work(&priv->gpio_change_rf_wq);
6302 #endif
6303 cancel_work_sync(&priv->reset_wq);
6304 cancel_work_sync(&priv->qos_activate);
6305 //cancel_work_sync(&priv->SetBWModeWorkItem);
6306 //cancel_work_sync(&priv->SwChnlWorkItem);
6307
6308 }
6309
6310
6311 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
6312 {
6313 struct net_device *dev = pci_get_drvdata(pdev);
6314 struct r8192_priv *priv ;
6315
6316 if(dev){
6317
6318 unregister_netdev(dev);
6319
6320 priv=ieee80211_priv(dev);
6321
6322 rtl8192_proc_remove_one(dev);
6323
6324 rtl8192_down(dev);
6325 if (priv->pFirmware)
6326 {
6327 vfree(priv->pFirmware);
6328 priv->pFirmware = NULL;
6329 }
6330 // priv->rf_close(dev);
6331 // rtl8192_usb_deleteendpoints(dev);
6332 destroy_workqueue(priv->priv_wq);
6333 /* redundant with rtl8192_down */
6334 // rtl8192_irq_disable(dev);
6335 // rtl8192_reset(dev);
6336 // mdelay(10);
6337 {
6338 u32 i;
6339 /* free tx/rx rings */
6340 rtl8192_free_rx_ring(dev);
6341 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
6342 rtl8192_free_tx_ring(dev, i);
6343 }
6344 }
6345 if(priv->irq){
6346
6347 printk("Freeing irq %d\n",dev->irq);
6348 free_irq(dev->irq, dev);
6349 priv->irq=0;
6350
6351 }
6352
6353
6354
6355 // free_beacon_desc_ring(dev,priv->txbeaconcount);
6356
6357 #ifdef CONFIG_RTL8180_IO_MAP
6358
6359 if( dev->base_addr != 0 ){
6360
6361 release_region(dev->base_addr,
6362 pci_resource_len(pdev, 0) );
6363 }
6364 #else
6365 if( dev->mem_start != (unsigned long)NULL ){
6366 iounmap( (void *)dev->mem_start );
6367 release_mem_region( pci_resource_start(pdev, 1),
6368 pci_resource_len(pdev, 1) );
6369 }
6370 #endif /*end #ifdef RTL_IO_MAP*/
6371 free_ieee80211(dev);
6372
6373 }
6374
6375 pci_disable_device(pdev);
6376 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
6377 }
6378
6379 extern int ieee80211_rtl_init(void);
6380 extern void ieee80211_rtl_exit(void);
6381
6382 static int __init rtl8192_pci_module_init(void)
6383 {
6384 int retval;
6385
6386 retval = ieee80211_rtl_init();
6387 if (retval)
6388 return retval;
6389
6390 printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
6391 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
6392 RT_TRACE(COMP_INIT, "Initializing module");
6393 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
6394 rtl8192_proc_module_init();
6395 if(0!=pci_register_driver(&rtl8192_pci_driver))
6396 {
6397 DMESG("No device found");
6398 /*pci_unregister_driver (&rtl8192_pci_driver);*/
6399 return -ENODEV;
6400 }
6401 return 0;
6402 }
6403
6404
6405 static void __exit rtl8192_pci_module_exit(void)
6406 {
6407 pci_unregister_driver(&rtl8192_pci_driver);
6408
6409 RT_TRACE(COMP_DOWN, "Exiting");
6410 rtl8192_proc_module_remove();
6411 ieee80211_rtl_exit();
6412 }
6413
6414 //warning message WB
6415 static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
6416 {
6417 struct net_device *dev = (struct net_device *) netdev;
6418 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6419 unsigned long flags;
6420 u32 inta;
6421 /* We should return IRQ_NONE, but for now let me keep this */
6422 if(priv->irq_enabled == 0){
6423 return IRQ_HANDLED;
6424 }
6425
6426 spin_lock_irqsave(&priv->irq_th_lock,flags);
6427
6428 //ISR: 4bytes
6429
6430 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
6431 write_nic_dword(dev,ISR,inta); // reset int situation
6432
6433 priv->stats.shints++;
6434 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
6435 if(!inta){
6436 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6437 return IRQ_HANDLED;
6438 /*
6439 most probably we can safely return IRQ_NONE,
6440 but for now is better to avoid problems
6441 */
6442 }
6443
6444 if(inta == 0xffff){
6445 /* HW disappared */
6446 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6447 return IRQ_HANDLED;
6448 }
6449
6450 priv->stats.ints++;
6451 #ifdef DEBUG_IRQ
6452 DMESG("NIC irq %x",inta);
6453 #endif
6454 //priv->irqpending = inta;
6455
6456
6457 if(!netif_running(dev)) {
6458 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6459 return IRQ_HANDLED;
6460 }
6461
6462 if(inta & IMR_TIMEOUT0){
6463 // write_nic_dword(dev, TimerInt, 0);
6464 //DMESG("=================>waking up");
6465 // rtl8180_hw_wakeup(dev);
6466 }
6467
6468 if(inta & IMR_TBDOK){
6469 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
6470 rtl8192_tx_isr(dev, BEACON_QUEUE);
6471 priv->stats.txbeaconokint++;
6472 }
6473
6474 if(inta & IMR_TBDER){
6475 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
6476 rtl8192_tx_isr(dev, BEACON_QUEUE);
6477 priv->stats.txbeaconerr++;
6478 }
6479
6480 if(inta & IMR_MGNTDOK ) {
6481 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
6482 priv->stats.txmanageokint++;
6483 rtl8192_tx_isr(dev,MGNT_QUEUE);
6484
6485 }
6486
6487 if(inta & IMR_COMDOK)
6488 {
6489 priv->stats.txcmdpktokint++;
6490 rtl8192_tx_isr(dev,TXCMD_QUEUE);
6491 }
6492
6493 if(inta & IMR_ROK){
6494 #ifdef DEBUG_RX
6495 DMESG("Frame arrived !");
6496 #endif
6497 priv->stats.rxint++;
6498 tasklet_schedule(&priv->irq_rx_tasklet);
6499 }
6500
6501 if(inta & IMR_BcnInt) {
6502 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
6503 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
6504 }
6505
6506 if(inta & IMR_RDU){
6507 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
6508 priv->stats.rxrdu++;
6509 /* reset int situation */
6510 write_nic_dword(dev,INTA_MASK,read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
6511 tasklet_schedule(&priv->irq_rx_tasklet);
6512 }
6513
6514 if(inta & IMR_RXFOVW){
6515 RT_TRACE(COMP_INTR, "rx overflow !\n");
6516 priv->stats.rxoverflow++;
6517 tasklet_schedule(&priv->irq_rx_tasklet);
6518 }
6519
6520 if(inta & IMR_TXFOVW) priv->stats.txoverflow++;
6521
6522 if(inta & IMR_BKDOK){
6523 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
6524 priv->stats.txbkokint++;
6525 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6526 rtl8192_tx_isr(dev,BK_QUEUE);
6527 rtl8192_try_wake_queue(dev, BK_QUEUE);
6528 }
6529
6530 if(inta & IMR_BEDOK){
6531 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
6532 priv->stats.txbeokint++;
6533 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6534 rtl8192_tx_isr(dev,BE_QUEUE);
6535 rtl8192_try_wake_queue(dev, BE_QUEUE);
6536 }
6537
6538 if(inta & IMR_VIDOK){
6539 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
6540 priv->stats.txviokint++;
6541 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6542 rtl8192_tx_isr(dev,VI_QUEUE);
6543 rtl8192_try_wake_queue(dev, VI_QUEUE);
6544 }
6545
6546 if(inta & IMR_VODOK){
6547 priv->stats.txvookint++;
6548 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6549 rtl8192_tx_isr(dev,VO_QUEUE);
6550 rtl8192_try_wake_queue(dev, VO_QUEUE);
6551 }
6552
6553 force_pci_posting(dev);
6554 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6555
6556 return IRQ_HANDLED;
6557 }
6558
6559 static void rtl8192_try_wake_queue(struct net_device *dev, int pri)
6560 {
6561 }
6562
6563
6564 void EnableHWSecurityConfig8192(struct net_device *dev)
6565 {
6566 u8 SECR_value = 0x0;
6567 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6568 struct ieee80211_device* ieee = priv->ieee80211;
6569
6570 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
6571 #if 1
6572 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
6573 {
6574 SECR_value |= SCR_RxUseDK;
6575 SECR_value |= SCR_TxUseDK;
6576 }
6577 else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
6578 {
6579 SECR_value |= SCR_RxUseDK;
6580 SECR_value |= SCR_TxUseDK;
6581 }
6582
6583 #endif
6584
6585 //add HWSec active enable here.
6586 //default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4
6587 ieee->hwsec_active = 1;
6588
6589 if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep)//!ieee->hwsec_support) //add hwsec_support flag to totol control hw_sec on/off
6590 {
6591 ieee->hwsec_active = 0;
6592 SECR_value &= ~SCR_RxDecEnable;
6593 }
6594
6595 RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__,
6596 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
6597 {
6598 write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK );
6599 }
6600
6601 }
6602 #define TOTAL_CAM_ENTRY 32
6603 //#define CAM_CONTENT_COUNT 8
6604 void setKey( struct net_device *dev,
6605 u8 EntryNo,
6606 u8 KeyIndex,
6607 u16 KeyType,
6608 const u8 *MacAddr,
6609 u8 DefaultKey,
6610 u32 *KeyContent )
6611 {
6612 u32 TargetCommand = 0;
6613 u32 TargetContent = 0;
6614 u16 usConfig = 0;
6615 u8 i;
6616 #ifdef ENABLE_IPS
6617 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6618 RT_RF_POWER_STATE rtState;
6619 rtState = priv->ieee80211->eRFPowerState;
6620 if(priv->ieee80211->PowerSaveControl.bInactivePs){
6621 if(rtState == eRfOff){
6622 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
6623 {
6624 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
6625 //up(&priv->wx_sem);
6626 return ;
6627 }
6628 else{
6629 down(&priv->ieee80211->ips_sem);
6630 IPSLeave(dev);
6631 up(&priv->ieee80211->ips_sem);
6632 }
6633 }
6634 }
6635 priv->ieee80211->is_set_key = true;
6636 #endif
6637 if (EntryNo >= TOTAL_CAM_ENTRY)
6638 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
6639
6640 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr);
6641
6642 if (DefaultKey)
6643 usConfig |= BIT15 | (KeyType<<2);
6644 else
6645 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
6646 // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
6647
6648
6649 for(i=0 ; i<CAM_CONTENT_COUNT; i++){
6650 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
6651 TargetCommand |= BIT31|BIT16;
6652
6653 if(i==0){//MAC|Config
6654 TargetContent = (u32)(*(MacAddr+0)) << 16|
6655 (u32)(*(MacAddr+1)) << 24|
6656 (u32)usConfig;
6657
6658 write_nic_dword(dev, WCAMI, TargetContent);
6659 write_nic_dword(dev, RWCAM, TargetCommand);
6660 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
6661 }
6662 else if(i==1){//MAC
6663 TargetContent = (u32)(*(MacAddr+2)) |
6664 (u32)(*(MacAddr+3)) << 8|
6665 (u32)(*(MacAddr+4)) << 16|
6666 (u32)(*(MacAddr+5)) << 24;
6667 write_nic_dword(dev, WCAMI, TargetContent);
6668 write_nic_dword(dev, RWCAM, TargetCommand);
6669 }
6670 else { //Key Material
6671 if(KeyContent != NULL)
6672 {
6673 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
6674 write_nic_dword(dev, RWCAM, TargetCommand);
6675 }
6676 }
6677 }
6678 RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig);
6679 }
6680
6681 bool NicIFEnableNIC(struct net_device* dev)
6682 {
6683 RT_STATUS init_status = RT_STATUS_SUCCESS;
6684 struct r8192_priv* priv = ieee80211_priv(dev);
6685 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
6686
6687 //YJ,add,091109
6688 if (priv->up == 0){
6689 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__FUNCTION__);
6690 priv->bdisable_nic = false; //YJ,add,091111
6691 return false;
6692 }
6693 // <1> Reset memory: descriptor, buffer,..
6694 //NicIFResetMemory(Adapter);
6695
6696 // <2> Enable Adapter
6697 //priv->bfirst_init = true;
6698 init_status = rtl8192_adapter_start(dev);
6699 if (init_status != RT_STATUS_SUCCESS) {
6700 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
6701 priv->bdisable_nic = false; //YJ,add,091111
6702 return -1;
6703 }
6704 //printk("start adapter finished\n");
6705 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
6706 //priv->bfirst_init = false;
6707
6708 // <3> Enable Interrupt
6709 rtl8192_irq_enable(dev);
6710 priv->bdisable_nic = false;
6711
6712 return (init_status == RT_STATUS_SUCCESS);
6713 }
6714
6715 bool NicIFDisableNIC(struct net_device* dev)
6716 {
6717 bool status = true;
6718 struct r8192_priv* priv = ieee80211_priv(dev);
6719 u8 tmp_state = 0;
6720 // <1> Disable Interrupt
6721
6722 priv->bdisable_nic = true; //YJ,move,091109
6723 tmp_state = priv->ieee80211->state;
6724
6725 ieee80211_softmac_stop_protocol(priv->ieee80211, false);
6726
6727 priv->ieee80211->state = tmp_state;
6728 rtl8192_cancel_deferred_work(priv);
6729 rtl8192_irq_disable(dev);
6730 // <2> Stop all timer
6731
6732 // <3> Disable Adapter
6733 rtl8192_halt_adapter(dev, false);
6734 // priv->bdisable_nic = true;
6735
6736 return status;
6737 }
6738
6739 module_init(rtl8192_pci_module_init);
6740 module_exit(rtl8192_pci_module_exit);
This page took 0.166297 seconds and 6 git commands to generate.