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