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