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