1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 * Linux device driver for RTL8190P / RTL8192E
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.
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
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
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
23 * Contact Information:
24 * Jerry chuang <wlanfae@realtek.com>
29 #undef RX_DONT_PASS_UL
31 #undef DEBUG_RX_VERBOSE
37 #undef DEBUG_TX_FILLDESC
42 #undef DEBUG_REGISTERS
44 #undef DEBUG_IRQ_TASKLET
48 //#define CONFIG_RTL8192_IO_MAP
49 #include <linux/vmalloc.h>
50 #include <linux/slab.h>
51 #include <asm/uaccess.h>
52 #include "r8192E_hw.h"
54 #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
55 #include "r8180_93cx6.h" /* Card EEPROM */
56 #include "r8192E_wx.h"
57 #include "r819xE_phy.h" //added by WB 4.30.2008
58 #include "r819xE_phyreg.h"
59 #include "r819xE_cmdpkt.h"
60 #include "r8192E_dm.h"
61 //#include "r8192xU_phyreg.h"
62 //#include <linux/usb.h>
63 // FIXME: check if 2.6.7 is ok
70 #include "ieee80211/dot11d.h"
73 //set here to open your trace code. //WB
74 u32 rt_global_debug_component = \
92 // COMP_POWER_TRACKING |
94 COMP_ERR ; //always open err flags on
96 #define PCI_DEVICE(vend,dev)\
97 .vendor=(vend),.device=(dev),\
98 .subvendor=PCI_ANY_ID,.subdevice=PCI_ANY_ID
100 static struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = {
104 { PCI_DEVICE(0x10ec, 0x8190) },
106 { PCI_DEVICE(0x07aa, 0x0045) },
107 { PCI_DEVICE(0x07aa, 0x0046) },
110 { PCI_DEVICE(0x10ec, 0x8192) },
113 { PCI_DEVICE(0x07aa, 0x0044) },
114 { PCI_DEVICE(0x07aa, 0x0047) },
119 static char* ifname = "wlan%d";
120 static int hwwep = 1; //default use hw. set 0 to use software security
121 static int channels = 0x3fff;
123 MODULE_LICENSE("GPL");
124 MODULE_VERSION("V 1.1");
125 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
126 //MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
127 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
130 module_param(ifname, charp, S_IRUGO|S_IWUSR );
131 //module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
132 module_param(hwwep,int, S_IRUGO|S_IWUSR);
133 module_param(channels,int, S_IRUGO|S_IWUSR);
135 MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
136 //MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
137 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
138 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
140 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
141 const struct pci_device_id *id);
142 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev);
144 static struct pci_driver rtl8192_pci_driver = {
145 .name = RTL819xE_MODULE_NAME, /* Driver name */
146 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
147 .probe = rtl8192_pci_probe, /* probe fn */
148 .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */
150 .suspend = rtl8192E_suspend, /* PM suspend fn */
151 .resume = rtl8192E_resume, /* PM resume fn */
153 .suspend = NULL, /* PM suspend fn */
154 .resume = NULL, /* PM resume fn */
160 typedef struct _CHANNEL_LIST
164 }CHANNEL_LIST, *PCHANNEL_LIST;
166 static CHANNEL_LIST ChannelPlan[] = {
167 {{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
168 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
169 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
170 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
171 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
172 {{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
173 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
174 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
175 {{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
176 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
177 {{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
180 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
182 int i, max_chan=-1, min_chan=-1;
183 struct ieee80211_device* ieee = priv->ieee80211;
184 switch (channel_plan)
186 case COUNTRY_CODE_FCC:
187 case COUNTRY_CODE_IC:
188 case COUNTRY_CODE_ETSI:
189 case COUNTRY_CODE_SPAIN:
190 case COUNTRY_CODE_FRANCE:
191 case COUNTRY_CODE_MKK:
192 case COUNTRY_CODE_MKK1:
193 case COUNTRY_CODE_ISRAEL:
194 case COUNTRY_CODE_TELEC:
195 case COUNTRY_CODE_MIC:
198 ieee->bGlobalDomain = false;
199 //acturally 8225 & 8256 rf chip only support B,G,24N mode
200 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256))
207 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
209 if (ChannelPlan[channel_plan].Len != 0){
210 // Clear old channel map
211 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
212 // Set new channel map
213 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
215 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
217 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
222 case COUNTRY_CODE_GLOBAL_DOMAIN:
224 GET_DOT11D_INFO(ieee)->bEnabled = 0; //this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain setting
226 ieee->bGlobalDomain = true;
236 #define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
237 /* 2007/07/25 MH Defien temp tx fw info. */
238 static TX_FWINFO_T Tmp_TxFwInfo;
241 #define rx_hal_is_cck_rate(_pdrvinfo)\
242 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
243 _pdrvinfo->RxRate == DESC90_RATE2M ||\
244 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
245 _pdrvinfo->RxRate == DESC90_RATE11M) &&\
249 void CamResetAllEntry(struct net_device *dev)
255 ulcommand |= BIT31|BIT30;
256 write_nic_dword(dev, RWCAM, ulcommand);
258 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
259 CAM_mark_invalid(dev, ucIndex);
260 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
261 CAM_empty_entry(dev, ucIndex);
266 void write_cam(struct net_device *dev, u8 addr, u32 data)
268 write_nic_dword(dev, WCAMI, data);
269 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
271 u32 read_cam(struct net_device *dev, u8 addr)
273 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
274 return read_nic_dword(dev, 0xa8);
277 ////////////////////////////////////////////////////////////
278 #ifdef CONFIG_RTL8180_IO_MAP
280 u8 read_nic_byte(struct net_device *dev, int x)
282 return 0xff&inb(dev->base_addr +x);
285 u32 read_nic_dword(struct net_device *dev, int x)
287 return inl(dev->base_addr +x);
290 u16 read_nic_word(struct net_device *dev, int x)
292 return inw(dev->base_addr +x);
295 void write_nic_byte(struct net_device *dev, int x,u8 y)
297 outb(y&0xff,dev->base_addr +x);
300 void write_nic_word(struct net_device *dev, int x,u16 y)
302 outw(y,dev->base_addr +x);
305 void write_nic_dword(struct net_device *dev, int x,u32 y)
307 outl(y,dev->base_addr +x);
310 #else /* RTL_IO_MAP */
312 u8 read_nic_byte(struct net_device *dev, int x)
314 return 0xff&readb((u8*)dev->mem_start +x);
317 u32 read_nic_dword(struct net_device *dev, int x)
319 return readl((u8*)dev->mem_start +x);
322 u16 read_nic_word(struct net_device *dev, int x)
324 return readw((u8*)dev->mem_start +x);
327 void write_nic_byte(struct net_device *dev, int x,u8 y)
329 writeb(y,(u8*)dev->mem_start +x);
333 void write_nic_dword(struct net_device *dev, int x,u32 y)
335 writel(y,(u8*)dev->mem_start +x);
339 void write_nic_word(struct net_device *dev, int x,u16 y)
341 writew(y,(u8*)dev->mem_start +x);
345 #endif /* RTL_IO_MAP */
347 u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee)
349 //struct r8192_priv* priv = ieee80211_priv(dev);
350 //struct ieee80211_device *ieee = priv->ieee80211;
352 static u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
353 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
354 int wpa_ie_len= ieee->wpa_ie_len;
355 struct ieee80211_crypt_data* crypt;
358 crypt = ieee->crypt[ieee->tx_keyidx];
360 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) ||\
361 (ieee->host_encrypt && crypt && crypt->ops && \
362 (0 == strcmp(crypt->ops->name,"WEP")));
365 if(encrypt && (wpa_ie_len == 0)) {
366 // wep encryption, no N mode setting */
368 } else if((wpa_ie_len != 0)) {
369 // parse pairwise key type */
370 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) ||
371 ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
381 rtl8192e_SetHwReg(struct net_device *dev,u8 variable,u8* val)
383 struct r8192_priv* priv = ieee80211_priv(dev);
389 write_nic_dword(dev, BSSIDR, ((u32*)(val))[0]);
390 write_nic_word(dev, BSSIDR+2, ((u16*)(val+2))[0]);
393 case HW_VAR_MEDIA_STATUS:
395 RT_OP_MODE OpMode = *((RT_OP_MODE *)(val));
396 //LED_CTL_MODE LedAction = LED_CTL_NO_LINK;
397 u8 btMsr = read_nic_byte(dev, MSR);
403 case RT_OP_MODE_INFRASTRUCTURE:
405 //LedAction = LED_CTL_LINK;
408 case RT_OP_MODE_IBSS:
410 // led link set separate
415 //LedAction = LED_CTL_LINK;
423 write_nic_byte(dev, MSR, btMsr);
425 //priv->ieee80211->LedControlHandler(dev, LedAction);
429 case HW_VAR_CECHK_BSSID:
433 Type = ((u8*)(val))[0];
434 //priv->ieee80211->GetHwRegHandler(dev, HW_VAR_RCR, (u8*)(&RegRCR));
435 RegRCR = read_nic_dword(dev,RCR);
436 priv->ReceiveConfig = RegRCR;
439 RegRCR |= (RCR_CBSSID);
440 else if (Type == false)
441 RegRCR &= (~RCR_CBSSID);
443 //priv->ieee80211->SetHwRegHandler( dev, HW_VAR_RCR, (u8*)(&RegRCR) );
444 write_nic_dword(dev, RCR,RegRCR);
445 priv->ReceiveConfig = RegRCR;
450 case HW_VAR_SLOT_TIME:
452 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
455 priv->slot_time = val[0];
456 write_nic_byte(dev, SLOT_TIME, val[0]);
461 case HW_VAR_ACK_PREAMBLE:
464 priv->short_preamble = (bool)(*(u8*)val );
465 regTmp = priv->basic_rate;
466 if (priv->short_preamble)
467 regTmp |= BRSR_AckShortPmb;
468 write_nic_dword(dev, RRSR, regTmp);
473 write_nic_dword(dev, CPU_GEN, ((u32*)(val))[0]);
483 ///////////////////////////////////////////////////////////
485 //u8 read_phy_cck(struct net_device *dev, u8 adr);
486 //u8 read_phy_ofdm(struct net_device *dev, u8 adr);
487 /* this might still called in what was the PHY rtl8185/rtl8192 common code
488 * plans are to possibilty turn it again in one common code...
490 inline void force_pci_posting(struct net_device *dev)
496 irqreturn_t rtl8192_interrupt(int irq, void *netdev);
497 //static struct net_device_stats *rtl8192_stats(struct net_device *dev);
498 void rtl8192_commit(struct net_device *dev);
499 //void rtl8192_restart(struct net_device *dev);
500 void rtl8192_restart(struct work_struct *work);
501 //void rtl8192_rq_tx_ack(struct work_struct *work);
503 void watch_dog_timer_callback(unsigned long data);
504 /****************************************************************************
505 -----------------------------PROCFS STUFF-------------------------
506 *****************************************************************************/
508 static struct proc_dir_entry *rtl8192_proc = NULL;
512 static int proc_get_stats_ap(char *page, char **start,
513 off_t offset, int count,
514 int *eof, void *data)
516 struct net_device *dev = data;
517 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
518 struct ieee80211_device *ieee = priv->ieee80211;
519 struct ieee80211_network *target;
523 list_for_each_entry(target, &ieee->network_list, list) {
525 len += snprintf(page + len, count - len,
526 "%s ", target->ssid);
528 if(target->wpa_ie_len>0 || target->rsn_ie_len>0){
529 len += snprintf(page + len, count - len,
533 len += snprintf(page + len, count - len,
543 static int proc_get_registers(char *page, char **start,
544 off_t offset, int count,
545 int *eof, void *data)
547 struct net_device *dev = data;
548 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
555 /* This dump the current register page */
556 len += snprintf(page + len, count - len,
557 "\n####################page 0##################\n ");
561 //printk( "\nD: %2x> ", n);
562 len += snprintf(page + len, count - len,
565 for(i=0;i<16 && n<=max;i++,n++)
566 len += snprintf(page + len, count - len,
567 "%2x ",read_nic_byte(dev,n));
569 // printk("%2x ",read_nic_byte(dev,n));
571 len += snprintf(page + len, count - len,"\n");
572 len += snprintf(page + len, count - len,
573 "\n####################page 1##################\n ");
576 //printk( "\nD: %2x> ", n);
577 len += snprintf(page + len, count - len,
580 for(i=0;i<16 && n<=max;i++,n++)
581 len += snprintf(page + len, count - len,
582 "%2x ",read_nic_byte(dev,0x100|n));
584 // printk("%2x ",read_nic_byte(dev,n));
587 len += snprintf(page + len, count - len,
588 "\n####################page 3##################\n ");
591 //printk( "\nD: %2x> ", n);
592 len += snprintf(page + len, count - len,
595 for(i=0;i<16 && n<=max;i++,n++)
596 len += snprintf(page + len, count - len,
597 "%2x ",read_nic_byte(dev,0x300|n));
599 // printk("%2x ",read_nic_byte(dev,n));
610 static int proc_get_stats_tx(char *page, char **start,
611 off_t offset, int count,
612 int *eof, void *data)
614 struct net_device *dev = data;
615 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
619 len += snprintf(page + len, count - len,
620 "TX VI priority ok int: %lu\n"
621 // "TX VI priority error int: %lu\n"
622 "TX VO priority ok int: %lu\n"
623 // "TX VO priority error int: %lu\n"
624 "TX BE priority ok int: %lu\n"
625 // "TX BE priority error int: %lu\n"
626 "TX BK priority ok int: %lu\n"
627 // "TX BK priority error int: %lu\n"
628 "TX MANAGE priority ok int: %lu\n"
629 // "TX MANAGE priority error int: %lu\n"
630 "TX BEACON priority ok int: %lu\n"
631 "TX BEACON priority error int: %lu\n"
632 "TX CMDPKT priority ok int: %lu\n"
633 // "TX high priority ok int: %lu\n"
634 // "TX high priority failed error int: %lu\n"
635 // "TX queue resume: %lu\n"
636 "TX queue stopped?: %d\n"
637 "TX fifo overflow: %lu\n"
638 // "TX beacon: %lu\n"
639 // "TX VI queue: %d\n"
640 // "TX VO queue: %d\n"
641 // "TX BE queue: %d\n"
642 // "TX BK queue: %d\n"
643 // "TX HW queue: %d\n"
644 // "TX VI dropped: %lu\n"
645 // "TX VO dropped: %lu\n"
646 // "TX BE dropped: %lu\n"
647 // "TX BK dropped: %lu\n"
648 "TX total data packets %lu\n"
649 "TX total data bytes :%lu\n",
650 // "TX beacon aborted: %lu\n",
651 priv->stats.txviokint,
652 // priv->stats.txvierr,
653 priv->stats.txvookint,
654 // priv->stats.txvoerr,
655 priv->stats.txbeokint,
656 // priv->stats.txbeerr,
657 priv->stats.txbkokint,
658 // priv->stats.txbkerr,
659 priv->stats.txmanageokint,
660 // priv->stats.txmanageerr,
661 priv->stats.txbeaconokint,
662 priv->stats.txbeaconerr,
663 priv->stats.txcmdpktokint,
664 // priv->stats.txhpokint,
665 // priv->stats.txhperr,
666 // priv->stats.txresumed,
667 netif_queue_stopped(dev),
668 priv->stats.txoverflow,
669 // priv->stats.txbeacon,
670 // atomic_read(&(priv->tx_pending[VI_QUEUE])),
671 // atomic_read(&(priv->tx_pending[VO_QUEUE])),
672 // atomic_read(&(priv->tx_pending[BE_QUEUE])),
673 // atomic_read(&(priv->tx_pending[BK_QUEUE])),
674 // read_nic_byte(dev, TXFIFOCOUNT),
675 // priv->stats.txvidrop,
676 // priv->stats.txvodrop,
677 priv->ieee80211->stats.tx_packets,
678 priv->ieee80211->stats.tx_bytes
681 // priv->stats.txbedrop,
682 // priv->stats.txbkdrop
683 // priv->stats.txdatapkt
684 // priv->stats.txbeaconerr
693 static int proc_get_stats_rx(char *page, char **start,
694 off_t offset, int count,
695 int *eof, void *data)
697 struct net_device *dev = data;
698 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
702 len += snprintf(page + len, count - len,
705 "RX rx overflow error: %lu\n"
706 "RX invalid urb error: %lu\n",
709 priv->stats.rxoverflow,
710 priv->stats.rxurberr);
716 static void rtl8192_proc_module_init(void)
718 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
719 rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net);
723 static void rtl8192_proc_module_remove(void)
725 remove_proc_entry(RTL819xE_MODULE_NAME, init_net.proc_net);
729 static void rtl8192_proc_remove_one(struct net_device *dev)
731 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
733 printk("dev name=======> %s\n",dev->name);
736 // remove_proc_entry("stats-hw", priv->dir_dev);
737 remove_proc_entry("stats-tx", priv->dir_dev);
738 remove_proc_entry("stats-rx", priv->dir_dev);
739 // remove_proc_entry("stats-ieee", priv->dir_dev);
740 remove_proc_entry("stats-ap", priv->dir_dev);
741 remove_proc_entry("registers", priv->dir_dev);
742 // remove_proc_entry("cck-registers",priv->dir_dev);
743 // remove_proc_entry("ofdm-registers",priv->dir_dev);
744 //remove_proc_entry(dev->name, rtl8192_proc);
745 remove_proc_entry("wlan0", rtl8192_proc);
746 priv->dir_dev = NULL;
751 static void rtl8192_proc_init_one(struct net_device *dev)
753 struct proc_dir_entry *e;
754 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
755 priv->dir_dev = create_proc_entry(dev->name,
756 S_IFDIR | S_IRUGO | S_IXUGO,
758 if (!priv->dir_dev) {
759 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
763 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
764 priv->dir_dev, proc_get_stats_rx, dev);
767 RT_TRACE(COMP_ERR,"Unable to initialize "
768 "/proc/net/rtl8192/%s/stats-rx\n",
773 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
774 priv->dir_dev, proc_get_stats_tx, dev);
777 RT_TRACE(COMP_ERR, "Unable to initialize "
778 "/proc/net/rtl8192/%s/stats-tx\n",
782 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
783 priv->dir_dev, proc_get_stats_ap, dev);
786 RT_TRACE(COMP_ERR, "Unable to initialize "
787 "/proc/net/rtl8192/%s/stats-ap\n",
791 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
792 priv->dir_dev, proc_get_registers, dev);
794 RT_TRACE(COMP_ERR, "Unable to initialize "
795 "/proc/net/rtl8192/%s/registers\n",
799 /****************************************************************************
800 -----------------------------MISC STUFF-------------------------
801 *****************************************************************************/
803 short check_nic_enough_desc(struct net_device *dev, int prio)
805 struct r8192_priv *priv = ieee80211_priv(dev);
806 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
808 /* for now we reserve two free descriptor as a safety boundary
809 * between the tail and the head
811 if (ring->entries - skb_queue_len(&ring->queue) >= 2) {
818 static void tx_timeout(struct net_device *dev)
820 struct r8192_priv *priv = ieee80211_priv(dev);
821 //rtl8192_commit(dev);
823 schedule_work(&priv->reset_wq);
828 /****************************************************************************
829 ------------------------------HW STUFF---------------------------
830 *****************************************************************************/
833 static void rtl8192_irq_enable(struct net_device *dev)
835 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
836 priv->irq_enabled = 1;
837 write_nic_dword(dev,INTA_MASK, priv->irq_mask);
841 void rtl8192_irq_disable(struct net_device *dev)
843 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
845 write_nic_dword(dev,INTA_MASK,0);
846 force_pci_posting(dev);
847 priv->irq_enabled = 0;
852 static void rtl8192_set_mode(struct net_device *dev,int mode)
855 ecmd=read_nic_byte(dev, EPROM_CMD);
856 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
857 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
858 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
859 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
860 write_nic_byte(dev, EPROM_CMD, ecmd);
864 void rtl8192_update_msr(struct net_device *dev)
866 struct r8192_priv *priv = ieee80211_priv(dev);
869 msr = read_nic_byte(dev, MSR);
870 msr &= ~ MSR_LINK_MASK;
872 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
873 * msr must be updated if the state is ASSOCIATING.
874 * this is intentional and make sense for ad-hoc and
875 * master (see the create BSS/IBSS func)
877 if (priv->ieee80211->state == IEEE80211_LINKED){
879 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
880 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
881 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
882 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
883 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
884 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
887 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
889 write_nic_byte(dev, MSR, msr);
892 void rtl8192_set_chan(struct net_device *dev,short ch)
894 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
895 RT_TRACE(COMP_RF, "=====>%s()====ch:%d\n", __FUNCTION__, ch);
898 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC ||
899 priv->ieee80211->iw_mode == IW_MODE_MASTER){
901 priv->ieee80211->link_state = WLAN_LINK_ASSOCIATED;
902 priv->ieee80211->master_chan = ch;
903 rtl8192_update_beacon_ch(dev);
907 /* this hack should avoid frame TX during channel setting*/
910 // tx = read_nic_dword(dev,TX_CONF);
911 // tx &= ~TX_LOOPBACK_MASK;
915 // write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
917 //need to implement rf set channel here WB
919 if (priv->rf_set_chan)
920 priv->rf_set_chan(dev,priv->chan);
922 // write_nic_dword(dev,TX_CONF,tx | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT));
926 void rtl8192_rx_enable(struct net_device *dev)
928 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
929 write_nic_dword(dev, RDQDA,priv->rx_ring_dma);
932 /* the TX_DESC_BASE setting is according to the following queue index
941 * BEACON_QUEUE ===> 8
943 static u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA};
944 void rtl8192_tx_enable(struct net_device *dev)
946 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
948 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
949 write_nic_dword(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma);
951 ieee80211_reset_queue(priv->ieee80211);
955 static void rtl8192_free_rx_ring(struct net_device *dev)
957 struct r8192_priv *priv = ieee80211_priv(dev);
960 for (i = 0; i < priv->rxringcount; i++) {
961 struct sk_buff *skb = priv->rx_buf[i];
965 pci_unmap_single(priv->pdev,
966 *((dma_addr_t *)skb->cb),
967 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
971 pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount,
972 priv->rx_ring, priv->rx_ring_dma);
973 priv->rx_ring = NULL;
976 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
978 struct r8192_priv *priv = ieee80211_priv(dev);
979 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
981 while (skb_queue_len(&ring->queue)) {
982 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
983 struct sk_buff *skb = __skb_dequeue(&ring->queue);
985 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
986 skb->len, PCI_DMA_TODEVICE);
988 ring->idx = (ring->idx + 1) % ring->entries;
991 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
992 ring->desc, ring->dma);
997 static void rtl8192_beacon_disable(struct net_device *dev)
999 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1002 reg = read_nic_dword(priv->ieee80211->dev,INTA_MASK);
1004 /* disable Beacon realted interrupt signal */
1005 reg &= ~(IMR_BcnInt | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
1006 write_nic_dword(priv->ieee80211->dev, INTA_MASK, reg);
1010 void PHY_SetRtl8192eRfOff(struct net_device* dev )
1012 //struct r8192_priv *priv = ieee80211_priv(dev);
1014 //disable RF-Chip A/B
1015 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
1016 //analog to digital off, for power save
1017 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0);
1018 //digital to analog off, for power save
1019 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0);
1021 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
1023 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
1024 //analog to digital part2 off, for power save
1025 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0);
1026 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0);
1027 // Analog parameter!!Change bias and Lbus control.
1028 write_nic_byte(dev, ANAPAR_FOR_8192PciE, 0x07);
1032 void rtl8192_halt_adapter(struct net_device *dev, bool reset)
1035 struct r8192_priv *priv = ieee80211_priv(dev);
1041 OpMode = RT_OP_MODE_NO_LINK;
1042 priv->ieee80211->SetHwRegHandler(dev, HW_VAR_MEDIA_STATUS, &OpMode);
1045 if(!priv->ieee80211->bSupportRemoteWakeUp)
1047 u1bTmp = 0x0; // disable tx/rx. In 8185 we write 0x10 (Reset bit), but here we make reference to WMAC and wirte 0x0. 2006.11.21 Emily
1048 //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_COMMAND, &u1bTmp ); // Using HW_VAR_COMMAND instead of writing CMDR directly. Rewrited by Annie, 2006-04-07.
1049 write_nic_byte(dev, CMDR, u1bTmp);
1052 cmd=read_nic_byte(dev,CMDR);
1053 write_nic_byte(dev, CMDR, cmd &~ (CR_TE|CR_RE));
1060 //PlatformStallExecution(150000);
1064 priv->bHwRfOffAction = 2;
1068 // Call MgntActSet_RF_State instead to prevent RF config race condition.
1069 // By Bruce, 2008-01-17.
1071 if(!priv->ieee80211->bSupportRemoteWakeUp)
1073 //MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_INIT);
1074 //MgntActSet_RF_State(Adapter, eRfOff, Adapter->MgntInfo.RfOffReason);
1075 //if(Adapter->HardwareType == HARDWARE_TYPE_RTL8190P)
1077 PHY_SetRtl8192eRfOff(dev);
1079 // 2006.11.30. System reset bit
1080 //priv->ieee80211->GetHwRegHandler(dev, HW_VAR_CPU_RST, (u32*)(&ulRegRead) );
1081 ulRegRead = read_nic_dword(dev,CPU_GEN);
1082 ulRegRead|=CPU_GEN_SYSTEM_RESET;
1083 //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_CPU_RST, &ulRegRead);
1084 write_nic_dword(dev,CPU_GEN, ulRegRead);
1088 //2008.06.03 for WOL
1089 write_nic_dword(dev, WFCRC0, 0xffffffff);
1090 write_nic_dword(dev, WFCRC1, 0xffffffff);
1091 write_nic_dword(dev, WFCRC2, 0xffffffff);
1093 //Write PMR register
1094 write_nic_byte(dev, PMR, 0x5);
1095 //Disable tx, enanble rx
1096 write_nic_byte(dev, MacBlkCtrl, 0xa);
1100 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
1101 skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
1103 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
1104 skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
1107 skb_queue_purge(&priv->skb_queue);
1112 static void rtl8192_reset(struct net_device *dev)
1114 rtl8192_irq_disable(dev);
1115 printk("This is RTL819xP Reset procedure\n");
1119 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
1120 inline u16 rtl8192_rate2rate(short rate)
1122 if (rate >11) return 0;
1123 return rtl_rate[rate];
1129 static void rtl8192_data_hard_stop(struct net_device *dev)
1133 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1134 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1135 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1136 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1137 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1142 static void rtl8192_data_hard_resume(struct net_device *dev)
1146 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1147 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1148 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1149 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1150 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1154 /* this function TX data frames when the ieee80211 stack requires this.
1155 * It checks also if we need to stop the ieee tx queue, eventually do it
1157 static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1159 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1161 //unsigned long flags;
1162 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1163 u8 queue_index = tcb_desc->queue_index;
1164 /* shall not be referred by command packet */
1165 assert(queue_index != TXCMD_QUEUE);
1167 if((priv->bHwRadioOff == true)||(!priv->up))
1173 //spin_lock_irqsave(&priv->tx_lock,flags);
1175 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1177 tcb_desc->RATRIndex = 7;
1178 tcb_desc->bTxDisableRateFallBack = 1;
1179 tcb_desc->bTxUseDriverAssingedRate = 1;
1180 tcb_desc->bTxEnableFwCalcDur = 1;
1182 skb_push(skb, priv->ieee80211->tx_headroom);
1183 ret = rtl8192_tx(dev, skb);
1189 if(queue_index!=MGNT_QUEUE) {
1190 priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1191 priv->ieee80211->stats.tx_packets++;
1194 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1200 /* This is a rough attempt to TX a frame
1201 * This is called by the ieee 80211 stack to TX management frames.
1202 * If the ring is full packet are dropped (for data frame the queue
1203 * is stopped before this can happen).
1205 static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
1207 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1211 //unsigned long flags;
1212 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1213 u8 queue_index = tcb_desc->queue_index;
1215 if(queue_index != TXCMD_QUEUE){
1216 if((priv->bHwRadioOff == true)||(!priv->up))
1223 //spin_lock_irqsave(&priv->tx_lock,flags);
1225 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1226 if(queue_index == TXCMD_QUEUE) {
1227 // skb_push(skb, USB_HWDESC_HEADER_LEN);
1228 rtl819xE_tx_cmd(dev, skb);
1230 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1233 // RT_TRACE(COMP_SEND, "To send management packet\n");
1234 tcb_desc->RATRIndex = 7;
1235 tcb_desc->bTxDisableRateFallBack = 1;
1236 tcb_desc->bTxUseDriverAssingedRate = 1;
1237 tcb_desc->bTxEnableFwCalcDur = 1;
1238 skb_push(skb, priv->ieee80211->tx_headroom);
1239 ret = rtl8192_tx(dev, skb);
1245 // priv->ieee80211->stats.tx_bytes+=skb->len;
1246 // priv->ieee80211->stats.tx_packets++;
1248 //spin_unlock_irqrestore(&priv->tx_lock,flags);
1255 void rtl8192_try_wake_queue(struct net_device *dev, int pri);
1257 static void rtl8192_tx_isr(struct net_device *dev, int prio)
1259 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1261 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1263 while (skb_queue_len(&ring->queue)) {
1264 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1265 struct sk_buff *skb;
1267 /* beacon packet will only use the first descriptor defaultly,
1268 * and the OWN may not be cleared by the hardware
1270 if(prio != BEACON_QUEUE) {
1273 ring->idx = (ring->idx + 1) % ring->entries;
1276 skb = __skb_dequeue(&ring->queue);
1277 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1278 skb->len, PCI_DMA_TODEVICE);
1282 if (prio == MGNT_QUEUE){
1283 if (priv->ieee80211->ack_tx_to_ieee){
1284 if (rtl8192_is_tx_queue_empty(dev)){
1285 priv->ieee80211->ack_tx_to_ieee = 0;
1286 ieee80211_ps_tx_ack(priv->ieee80211, 1);
1291 if(prio != BEACON_QUEUE) {
1292 /* try to deal with the pending packets */
1293 tasklet_schedule(&priv->irq_tx_tasklet);
1298 static void rtl8192_stop_beacon(struct net_device *dev)
1300 //rtl8192_beacon_disable(dev);
1303 static void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
1305 struct r8192_priv *priv = ieee80211_priv(dev);
1306 struct ieee80211_network *net;
1307 u8 i=0, basic_rate = 0;
1308 net = & priv->ieee80211->current_network;
1310 for (i=0; i<net->rates_len; i++)
1312 basic_rate = net->rates[i]&0x7f;
1315 case MGN_1M: *rate_config |= RRSR_1M; break;
1316 case MGN_2M: *rate_config |= RRSR_2M; break;
1317 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1318 case MGN_11M: *rate_config |= RRSR_11M; break;
1319 case MGN_6M: *rate_config |= RRSR_6M; break;
1320 case MGN_9M: *rate_config |= RRSR_9M; break;
1321 case MGN_12M: *rate_config |= RRSR_12M; break;
1322 case MGN_18M: *rate_config |= RRSR_18M; break;
1323 case MGN_24M: *rate_config |= RRSR_24M; break;
1324 case MGN_36M: *rate_config |= RRSR_36M; break;
1325 case MGN_48M: *rate_config |= RRSR_48M; break;
1326 case MGN_54M: *rate_config |= RRSR_54M; break;
1329 for (i=0; i<net->rates_ex_len; i++)
1331 basic_rate = net->rates_ex[i]&0x7f;
1334 case MGN_1M: *rate_config |= RRSR_1M; break;
1335 case MGN_2M: *rate_config |= RRSR_2M; break;
1336 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1337 case MGN_11M: *rate_config |= RRSR_11M; break;
1338 case MGN_6M: *rate_config |= RRSR_6M; break;
1339 case MGN_9M: *rate_config |= RRSR_9M; break;
1340 case MGN_12M: *rate_config |= RRSR_12M; break;
1341 case MGN_18M: *rate_config |= RRSR_18M; break;
1342 case MGN_24M: *rate_config |= RRSR_24M; break;
1343 case MGN_36M: *rate_config |= RRSR_36M; break;
1344 case MGN_48M: *rate_config |= RRSR_48M; break;
1345 case MGN_54M: *rate_config |= RRSR_54M; break;
1351 #define SHORT_SLOT_TIME 9
1352 #define NON_SHORT_SLOT_TIME 20
1354 static void rtl8192_update_cap(struct net_device* dev, u16 cap)
1357 struct r8192_priv *priv = ieee80211_priv(dev);
1358 struct ieee80211_network *net = &priv->ieee80211->current_network;
1359 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1360 tmp = priv->basic_rate;
1361 if (priv->short_preamble)
1362 tmp |= BRSR_AckShortPmb;
1363 write_nic_dword(dev, RRSR, tmp);
1365 if (net->mode & (IEEE_G|IEEE_N_24G))
1368 if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
1370 slot_time = SHORT_SLOT_TIME;
1372 else //long slot time
1373 slot_time = NON_SHORT_SLOT_TIME;
1374 priv->slot_time = slot_time;
1375 write_nic_byte(dev, SLOT_TIME, slot_time);
1380 static void rtl8192_net_update(struct net_device *dev)
1383 struct r8192_priv *priv = ieee80211_priv(dev);
1384 struct ieee80211_network *net;
1385 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1386 u16 rate_config = 0;
1387 net = &priv->ieee80211->current_network;
1388 //update Basic rate: RR, BRSR
1389 rtl8192_config_rate(dev, &rate_config);
1390 // 2007.01.16, by Emily
1391 // Select RRSR (in Legacy-OFDM and CCK)
1392 // For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate.
1393 // We do not use other rates.
1394 priv->basic_rate = rate_config &= 0x15f;
1396 write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
1397 write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
1400 rtl8192_update_msr(dev);
1404 // rtl8192_update_cap(dev, net->capability);
1405 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1407 write_nic_word(dev, ATIMWND, 2);
1408 write_nic_word(dev, BCN_DMATIME, 256);
1409 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1410 // write_nic_word(dev, BcnIntTime, 100);
1411 //BIT15 of BCN_DRV_EARLY_INT will indicate whether software beacon or hw beacon is applied.
1412 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
1413 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1415 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1416 // TODO: BcnIFS may required to be changed on ASIC
1417 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1419 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1425 void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1427 struct r8192_priv *priv = ieee80211_priv(dev);
1428 struct rtl8192_tx_ring *ring;
1429 tx_desc_819x_pci *entry;
1433 unsigned long flags;
1435 ring = &priv->tx_ring[TXCMD_QUEUE];
1436 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1438 spin_lock_irqsave(&priv->irq_th_lock,flags);
1439 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1440 entry = &ring->desc[idx];
1442 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1444 entry->LINIP = tcb_desc->bLastIniPkt;
1445 entry->FirstSeg = 1;//first segment
1446 entry->LastSeg = 1; //last segment
1447 if(tcb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) {
1448 entry->CmdInit = DESC_PACKET_TYPE_INIT;
1450 entry->CmdInit = DESC_PACKET_TYPE_NORMAL;
1451 entry->Offset = sizeof(TX_FWINFO_8190PCI) + 8;
1452 entry->PktSize = (u16)(tcb_desc->pkt_size + entry->Offset);
1453 entry->QueueSelect = QSLT_CMD;
1454 entry->TxFWInfoSize = 0x08;
1455 entry->RATid = (u8)DESC_PACKET_TYPE_INIT;
1457 entry->TxBufferSize = skb->len;
1458 entry->TxBuffAddr = cpu_to_le32(mapping);
1461 #ifdef JOHN_DUMP_TXDESC
1463 tx_desc_819x_pci *entry1 = &ring->desc[0];
1464 unsigned int *ptr= (unsigned int *)entry1;
1465 printk("<Tx descriptor>:\n");
1466 for (i = 0; i < 8; i++)
1467 printk("%8x ", ptr[i]);
1471 __skb_queue_tail(&ring->queue, skb);
1472 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1474 write_nic_byte(dev, TPPoll, TPPoll_CQ);
1480 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1481 * in TxFwInfo data structure
1482 * 2006.10.30 by Emily
1484 * \param QUEUEID Software Queue
1486 static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1488 u8 QueueSelect = 0x0; //defualt set to
1492 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority;
1496 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority;
1500 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority;
1504 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority;
1507 QueueSelect = QSLT_MGNT;
1511 QueueSelect = QSLT_BEACON;
1514 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
1515 // TODO: Remove Assertions
1516 //#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
1518 QueueSelect = QSLT_CMD;
1522 //QueueSelect = QSLT_HIGH;
1526 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
1532 static u8 MRateToHwRate8190Pci(u8 rate)
1534 u8 ret = DESC90_RATE1M;
1537 case MGN_1M: ret = DESC90_RATE1M; break;
1538 case MGN_2M: ret = DESC90_RATE2M; break;
1539 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1540 case MGN_11M: ret = DESC90_RATE11M; break;
1541 case MGN_6M: ret = DESC90_RATE6M; break;
1542 case MGN_9M: ret = DESC90_RATE9M; break;
1543 case MGN_12M: ret = DESC90_RATE12M; break;
1544 case MGN_18M: ret = DESC90_RATE18M; break;
1545 case MGN_24M: ret = DESC90_RATE24M; break;
1546 case MGN_36M: ret = DESC90_RATE36M; break;
1547 case MGN_48M: ret = DESC90_RATE48M; break;
1548 case MGN_54M: ret = DESC90_RATE54M; break;
1550 // HT rate since here
1551 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1552 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1553 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1554 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1555 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1556 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1557 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1558 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1559 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1560 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1561 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1562 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1563 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1564 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1565 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1566 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1567 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1575 static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
1579 tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
1581 if(TxHT==1 && TxRate != DESC90_RATEMCS15)
1588 * The tx procedure is just as following,
1589 * skb->cb will contain all the following information,
1590 * priority, morefrag, rate, &dev.
1592 short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
1594 struct r8192_priv *priv = ieee80211_priv(dev);
1595 struct rtl8192_tx_ring *ring;
1596 unsigned long flags;
1597 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1598 tx_desc_819x_pci *pdesc = NULL;
1599 TX_FWINFO_8190PCI *pTxFwInfo = NULL;
1601 bool multi_addr=false,broad_addr=false,uni_addr=false;
1602 u8* pda_addr = NULL;
1605 if(priv->bdisable_nic){
1606 RT_TRACE(COMP_ERR,"%s: ERR!! Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n", __FUNCTION__, skb->len, tcb_desc->queue_index);
1611 priv->ieee80211->bAwakePktSent = true;
1614 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1615 /* collect the tx packets statitcs */
1616 pda_addr = ((u8*)skb->data) + sizeof(TX_FWINFO_8190PCI);
1617 if(is_multicast_ether_addr(pda_addr))
1619 else if(is_broadcast_ether_addr(pda_addr))
1625 priv->stats.txbytesunicast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1627 priv->stats.txbytesmulticast +=(u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1629 priv->stats.txbytesbroadcast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1631 /* fill tx firmware */
1632 pTxFwInfo = (PTX_FWINFO_8190PCI)skb->data;
1633 memset(pTxFwInfo,0,sizeof(TX_FWINFO_8190PCI));
1634 pTxFwInfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
1635 pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)tcb_desc->data_rate);
1636 pTxFwInfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1637 pTxFwInfo->Short = QueryIsShort(pTxFwInfo->TxHT, pTxFwInfo->TxRate, tcb_desc);
1639 /* Aggregation related */
1640 if(tcb_desc->bAMPDUEnable) {
1641 pTxFwInfo->AllowAggregation = 1;
1642 pTxFwInfo->RxMF = tcb_desc->ampdu_factor;
1643 pTxFwInfo->RxAMD = tcb_desc->ampdu_density;
1645 pTxFwInfo->AllowAggregation = 0;
1646 pTxFwInfo->RxMF = 0;
1647 pTxFwInfo->RxAMD = 0;
1651 // Protection mode related
1653 pTxFwInfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
1654 pTxFwInfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
1655 pTxFwInfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
1656 pTxFwInfo->RtsHT= (tcb_desc->rts_rate&0x80)?1:0;
1657 pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1658 pTxFwInfo->RtsBandwidth = 0;
1659 pTxFwInfo->RtsSubcarrier = tcb_desc->RTSSC;
1660 pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):(tcb_desc->bRTSUseShortGI?1:0);
1662 // Set Bandwidth and sub-channel settings.
1664 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1666 if(tcb_desc->bPacketBW)
1668 pTxFwInfo->TxBandwidth = 1;
1670 pTxFwInfo->TxSubCarrier = 3;
1672 pTxFwInfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode, cosa 04012008
1677 pTxFwInfo->TxBandwidth = 0;
1678 pTxFwInfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1681 pTxFwInfo->TxBandwidth = 0;
1682 pTxFwInfo->TxSubCarrier = 0;
1687 /* 2007/07/25 MH Copy current TX FW info.*/
1688 memcpy((void*)(&Tmp_TxFwInfo), (void*)(pTxFwInfo), sizeof(TX_FWINFO_8190PCI));
1689 printk("&&&&&&&&&&&&&&&&&&&&&&====>print out fwinf\n");
1690 printk("===>enable fwcacl:%d\n", Tmp_TxFwInfo.EnableCPUDur);
1691 printk("===>RTS STBC:%d\n", Tmp_TxFwInfo.RtsSTBC);
1692 printk("===>RTS Subcarrier:%d\n", Tmp_TxFwInfo.RtsSubcarrier);
1693 printk("===>Allow Aggregation:%d\n", Tmp_TxFwInfo.AllowAggregation);
1694 printk("===>TX HT bit:%d\n", Tmp_TxFwInfo.TxHT);
1695 printk("===>Tx rate:%d\n", Tmp_TxFwInfo.TxRate);
1696 printk("===>Received AMPDU Density:%d\n", Tmp_TxFwInfo.RxAMD);
1697 printk("===>Received MPDU Factor:%d\n", Tmp_TxFwInfo.RxMF);
1698 printk("===>TxBandwidth:%d\n", Tmp_TxFwInfo.TxBandwidth);
1699 printk("===>TxSubCarrier:%d\n", Tmp_TxFwInfo.TxSubCarrier);
1701 printk("<=====**********************out of print\n");
1704 spin_lock_irqsave(&priv->irq_th_lock,flags);
1705 ring = &priv->tx_ring[tcb_desc->queue_index];
1706 if (tcb_desc->queue_index != BEACON_QUEUE) {
1707 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1712 pdesc = &ring->desc[idx];
1713 if((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
1714 RT_TRACE(COMP_ERR,"No more TX desc@%d, ring->idx = %d,idx = %d,%x", \
1715 tcb_desc->queue_index,ring->idx, idx,skb->len);
1716 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1720 /* fill tx descriptor */
1721 memset((u8*)pdesc,0,12);
1725 pdesc->Offset = sizeof(TX_FWINFO_8190PCI) + 8; //We must add 8!! Emily
1726 pdesc->PktSize = (u16)skb->len-sizeof(TX_FWINFO_8190PCI);
1730 pdesc->RATid = tcb_desc->RATRIndex;
1734 pdesc->SecType = 0x0;
1735 if (tcb_desc->bHwSec) {
1738 printk("==>================hw sec\n");
1741 switch (priv->ieee80211->pairwise_key_type) {
1742 case KEY_TYPE_WEP40:
1743 case KEY_TYPE_WEP104:
1744 pdesc->SecType = 0x1;
1748 pdesc->SecType = 0x2;
1752 pdesc->SecType = 0x3;
1756 pdesc->SecType = 0x0;
1767 pdesc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1768 pdesc->TxFWInfoSize = sizeof(TX_FWINFO_8190PCI);
1770 pdesc->DISFB = tcb_desc->bTxDisableRateFallBack;
1771 pdesc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1775 pdesc->TxBufferSize = skb->len;
1777 pdesc->TxBuffAddr = cpu_to_le32(mapping);
1778 __skb_queue_tail(&ring->queue, skb);
1780 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1781 dev->trans_start = jiffies;
1782 write_nic_word(dev,TPPoll,0x01<<tcb_desc->queue_index);
1786 static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
1788 struct r8192_priv *priv = ieee80211_priv(dev);
1789 rx_desc_819x_pci *entry = NULL;
1792 priv->rx_ring = pci_alloc_consistent(priv->pdev,
1793 sizeof(*priv->rx_ring) * priv->rxringcount, &priv->rx_ring_dma);
1795 if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) {
1796 RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n");
1800 memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * priv->rxringcount);
1803 for (i = 0; i < priv->rxringcount; i++) {
1804 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
1805 dma_addr_t *mapping;
1806 entry = &priv->rx_ring[i];
1809 priv->rx_buf[i] = skb;
1810 mapping = (dma_addr_t *)skb->cb;
1811 *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb),
1812 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1814 entry->BufferAddress = cpu_to_le32(*mapping);
1816 entry->Length = priv->rxbuffersize;
1824 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
1825 unsigned int prio, unsigned int entries)
1827 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1828 tx_desc_819x_pci *ring;
1832 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
1833 if (!ring || (unsigned long)ring & 0xFF) {
1834 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio);
1838 memset(ring, 0, sizeof(*ring)*entries);
1839 priv->tx_ring[prio].desc = ring;
1840 priv->tx_ring[prio].dma = dma;
1841 priv->tx_ring[prio].idx = 0;
1842 priv->tx_ring[prio].entries = entries;
1843 skb_queue_head_init(&priv->tx_ring[prio].queue);
1845 for (i = 0; i < entries; i++)
1846 ring[i].NextDescAddress =
1847 cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring));
1853 static short rtl8192_pci_initdescring(struct net_device *dev)
1857 struct r8192_priv *priv = ieee80211_priv(dev);
1859 ret = rtl8192_alloc_rx_desc_ring(dev);
1865 /* general process for other queue */
1866 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1867 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
1869 goto err_free_rings;
1873 /* specific process for hardware beacon process */
1874 ret = rtl8192_alloc_tx_desc_ring(dev, MAX_TX_QUEUE_COUNT - 1, 2);
1876 goto err_free_rings;
1882 rtl8192_free_rx_ring(dev);
1883 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
1884 if (priv->tx_ring[i].desc)
1885 rtl8192_free_tx_ring(dev, i);
1889 static void rtl8192_pci_resetdescring(struct net_device *dev)
1891 struct r8192_priv *priv = ieee80211_priv(dev);
1894 /* force the rx_idx to the first one */
1896 rx_desc_819x_pci *entry = NULL;
1897 for (i = 0; i < priv->rxringcount; i++) {
1898 entry = &priv->rx_ring[i];
1904 /* after reset, release previous pending packet, and force the
1905 * tx idx to the first one */
1906 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1907 if (priv->tx_ring[i].desc) {
1908 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
1910 while (skb_queue_len(&ring->queue)) {
1911 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1912 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1914 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1915 skb->len, PCI_DMA_TODEVICE);
1917 ring->idx = (ring->idx + 1) % ring->entries;
1925 extern void rtl8192_update_ratr_table(struct net_device* dev);
1926 static void rtl8192_link_change(struct net_device *dev)
1930 struct r8192_priv *priv = ieee80211_priv(dev);
1931 struct ieee80211_device* ieee = priv->ieee80211;
1932 //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval);
1933 if (ieee->state == IEEE80211_LINKED)
1935 rtl8192_net_update(dev);
1936 rtl8192_update_ratr_table(dev);
1938 //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
1939 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
1940 EnableHWSecurityConfig8192(dev);
1945 write_nic_byte(dev, 0x173, 0);
1947 /*update timing params*/
1948 //rtl8192_set_chan(dev, priv->chan);
1950 rtl8192_update_msr(dev);
1952 // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have
1953 // // To set CBSSID bit when link with any AP or STA.
1954 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
1957 reg = read_nic_dword(dev, RCR);
1958 if (priv->ieee80211->state == IEEE80211_LINKED)
1959 priv->ReceiveConfig = reg |= RCR_CBSSID;
1961 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
1962 write_nic_dword(dev, RCR, reg);
1968 static struct ieee80211_qos_parameters def_qos_parameters = {
1969 {3,3,3,3},/* cw_min */
1970 {7,7,7,7},/* cw_max */
1971 {2,2,2,2},/* aifs */
1972 {0,0,0,0},/* flags */
1973 {0,0,0,0} /* tx_op_limit */
1976 static void rtl8192_update_beacon(struct work_struct * work)
1978 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
1979 struct net_device *dev = priv->ieee80211->dev;
1980 struct ieee80211_device* ieee = priv->ieee80211;
1981 struct ieee80211_network* net = &ieee->current_network;
1983 if (ieee->pHTInfo->bCurrentHTSupport)
1984 HTUpdateSelfAndPeerSetting(ieee, net);
1985 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
1986 rtl8192_update_cap(dev, net->capability);
1989 * background support to run QoS activate functionality
1991 static int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
1992 static void rtl8192_qos_activate(struct work_struct * work)
1994 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
1995 struct net_device *dev = priv->ieee80211->dev;
1996 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
1997 u8 mode = priv->ieee80211->current_network.mode;
1998 // u32 size = sizeof(struct ieee80211_qos_parameters);
2003 mutex_lock(&priv->mutex);
2004 if(priv->ieee80211->state != IEEE80211_LINKED)
2006 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
2007 /* It better set slot time at first */
2008 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
2009 /* update the ac parameter to related registers */
2010 for(i = 0; i < QOS_QUEUE_NUM; i++) {
2011 //Mode G/A: slotTimeTimer = 9; Mode B: 20
2012 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
2013 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
2014 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
2015 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
2016 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2017 //printk("===>u4bAcParam:%x, ", u4bAcParam);
2018 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2019 //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
2023 mutex_unlock(&priv->mutex);
2026 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
2028 struct ieee80211_network *network)
2031 u32 size = sizeof(struct ieee80211_qos_parameters);
2033 if(priv->ieee80211->state !=IEEE80211_LINKED)
2036 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2039 if (network->flags & NETWORK_HAS_QOS_MASK) {
2040 if (active_network &&
2041 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
2042 network->qos_data.active = network->qos_data.supported;
2044 if ((network->qos_data.active == 1) && (active_network == 1) &&
2045 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
2046 (network->qos_data.old_param_count !=
2047 network->qos_data.param_count)) {
2048 network->qos_data.old_param_count =
2049 network->qos_data.param_count;
2050 queue_work(priv->priv_wq, &priv->qos_activate);
2051 RT_TRACE (COMP_QOS, "QoS parameters change call "
2055 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2056 &def_qos_parameters, size);
2058 if ((network->qos_data.active == 1) && (active_network == 1)) {
2059 queue_work(priv->priv_wq, &priv->qos_activate);
2060 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
2062 network->qos_data.active = 0;
2063 network->qos_data.supported = 0;
2069 /* handle manage frame frame beacon and probe response */
2070 static int rtl8192_handle_beacon(struct net_device * dev,
2071 struct ieee80211_beacon * beacon,
2072 struct ieee80211_network * network)
2074 struct r8192_priv *priv = ieee80211_priv(dev);
2076 rtl8192_qos_handle_probe_response(priv,1,network);
2078 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
2084 * handling the beaconing responses. if we get different QoS setting
2085 * off the network from the associated setting, adjust the QoS
2088 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
2089 struct ieee80211_network *network)
2092 unsigned long flags;
2093 u32 size = sizeof(struct ieee80211_qos_parameters);
2094 int set_qos_param = 0;
2096 if ((priv == NULL) || (network == NULL))
2099 if(priv->ieee80211->state !=IEEE80211_LINKED)
2102 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2105 spin_lock_irqsave(&priv->ieee80211->lock, flags);
2106 if(network->flags & NETWORK_HAS_QOS_PARAMETERS) {
2107 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2108 &network->qos_data.parameters,\
2109 sizeof(struct ieee80211_qos_parameters));
2110 priv->ieee80211->current_network.qos_data.active = 1;
2112 if((priv->ieee80211->current_network.qos_data.param_count != \
2113 network->qos_data.param_count))
2117 /* update qos parameter for current network */
2118 priv->ieee80211->current_network.qos_data.old_param_count = \
2119 priv->ieee80211->current_network.qos_data.param_count;
2120 priv->ieee80211->current_network.qos_data.param_count = \
2121 network->qos_data.param_count;
2124 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2125 &def_qos_parameters, size);
2126 priv->ieee80211->current_network.qos_data.active = 0;
2127 priv->ieee80211->current_network.qos_data.supported = 0;
2131 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
2133 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active);
2134 if (set_qos_param == 1)
2135 queue_work(priv->priv_wq, &priv->qos_activate);
2141 static int rtl8192_handle_assoc_response(struct net_device *dev,
2142 struct ieee80211_assoc_response_frame *resp,
2143 struct ieee80211_network *network)
2145 struct r8192_priv *priv = ieee80211_priv(dev);
2146 rtl8192_qos_association_resp(priv, network);
2151 //updateRATRTabel for MCS only. Basic rate is not implement.
2152 void rtl8192_update_ratr_table(struct net_device* dev)
2153 // POCTET_STRING posLegacyRate,
2155 // PRT_WLAN_STA pEntry)
2157 struct r8192_priv* priv = ieee80211_priv(dev);
2158 struct ieee80211_device* ieee = priv->ieee80211;
2159 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
2160 //struct ieee80211_network *net = &ieee->current_network;
2164 rtl8192_config_rate(dev, (u16*)(&ratr_value));
2165 ratr_value |= (*(u16*)(pMcsRate)) << 12;
2166 // switch (net->mode)
2170 ratr_value &= 0x00000FF0;
2173 ratr_value &= 0x0000000F;
2176 ratr_value &= 0x00000FF7;
2180 if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
2181 ratr_value &= 0x0007F007;
2183 if (priv->rf_type == RF_1T2R)
2184 ratr_value &= 0x000FF007;
2186 ratr_value &= 0x0F81F007;
2192 ratr_value &= 0x0FFFFFFF;
2193 if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
2194 ratr_value |= 0x80000000;
2195 }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
2196 ratr_value |= 0x80000000;
2198 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
2199 write_nic_byte(dev, UFWP, 1);
2203 static u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
2204 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
2207 static bool GetNmodeSupportBySecCfg8190Pci(struct net_device*dev)
2211 struct r8192_priv *priv = ieee80211_priv(dev);
2212 struct ieee80211_device *ieee = priv->ieee80211;
2213 if (ieee->rtllib_ap_sec_type &&
2214 (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP))) {
2220 struct r8192_priv* priv = ieee80211_priv(dev);
2221 struct ieee80211_device* ieee = priv->ieee80211;
2222 int wpa_ie_len= ieee->wpa_ie_len;
2223 struct ieee80211_crypt_data* crypt;
2226 crypt = ieee->crypt[ieee->tx_keyidx];
2227 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP")));
2230 if(encrypt && (wpa_ie_len == 0)) {
2231 /* wep encryption, no N mode setting */
2233 // } else if((wpa_ie_len != 0)&&(memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) {
2234 } else if((wpa_ie_len != 0)) {
2235 /* parse pairwise key type */
2236 //if((pairwisekey = WEP40)||(pairwisekey = WEP104)||(pairwisekey = TKIP))
2237 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
2242 //RT_TRACE(COMP_ERR,"In %s The GroupEncAlgorithm is [4]\n",__FUNCTION__ );
2250 static void rtl8192_refresh_supportrate(struct r8192_priv* priv)
2252 struct ieee80211_device* ieee = priv->ieee80211;
2253 //we donot consider set support rate for ABG mode, only HT MCS rate is set here.
2254 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2256 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
2257 //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16);
2258 //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16);
2261 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
2265 static u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
2267 struct r8192_priv *priv = ieee80211_priv(dev);
2269 switch(priv->rf_chip)
2274 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
2277 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
2280 ret = WIRELESS_MODE_B;
2286 static void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
2288 struct r8192_priv *priv = ieee80211_priv(dev);
2289 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
2292 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
2294 if(bSupportMode & WIRELESS_MODE_N_24G)
2296 wireless_mode = WIRELESS_MODE_N_24G;
2298 else if(bSupportMode & WIRELESS_MODE_N_5G)
2300 wireless_mode = WIRELESS_MODE_N_5G;
2302 else if((bSupportMode & WIRELESS_MODE_A))
2304 wireless_mode = WIRELESS_MODE_A;
2306 else if((bSupportMode & WIRELESS_MODE_G))
2308 wireless_mode = WIRELESS_MODE_G;
2310 else if((bSupportMode & WIRELESS_MODE_B))
2312 wireless_mode = WIRELESS_MODE_B;
2315 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
2316 wireless_mode = WIRELESS_MODE_B;
2319 #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
2320 ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting );
2322 priv->ieee80211->mode = wireless_mode;
2324 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
2325 priv->ieee80211->pHTInfo->bEnableHT = 1;
2327 priv->ieee80211->pHTInfo->bEnableHT = 0;
2328 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
2329 rtl8192_refresh_supportrate(priv);
2333 //init priv variables here
2335 static bool GetHalfNmodeSupportByAPs819xPci(struct net_device* dev)
2338 struct r8192_priv* priv = ieee80211_priv(dev);
2339 struct ieee80211_device* ieee = priv->ieee80211;
2341 if(ieee->bHalfWirelessN24GMode == true)
2349 short rtl8192_is_tx_queue_empty(struct net_device *dev)
2352 struct r8192_priv *priv = ieee80211_priv(dev);
2353 for (i=0; i<=MGNT_QUEUE; i++)
2355 if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) )
2357 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){
2358 printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue));
2364 static void rtl8192_hw_sleep_down(struct net_device *dev)
2366 struct r8192_priv *priv = ieee80211_priv(dev);
2367 unsigned long flags = 0;
2369 spin_lock_irqsave(&priv->rf_ps_lock,flags);
2370 if (priv->RFChangeInProgress) {
2371 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2372 RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n");
2373 printk("rtl8192_hw_sleep_down(): RF Change in progress!\n");
2376 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2377 //RT_TRACE(COMP_PS, "%s()============>come to sleep down\n", __FUNCTION__);
2379 MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
2381 static void rtl8192_hw_sleep_wq (struct work_struct *work)
2383 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
2384 // struct ieee80211_device * ieee = (struct ieee80211_device*)
2385 // container_of(work, struct ieee80211_device, watch_dog_wq);
2386 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
2387 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
2388 struct net_device *dev = ieee->dev;
2390 rtl8192_hw_sleep_down(dev);
2393 static void rtl8192_hw_wakeup(struct net_device* dev)
2395 struct r8192_priv *priv = ieee80211_priv(dev);
2396 unsigned long flags = 0;
2398 spin_lock_irqsave(&priv->rf_ps_lock,flags);
2399 if (priv->RFChangeInProgress) {
2400 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2401 RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n");
2402 printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n");
2403 queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->hw_wakeup_wq,MSECS(10));//PowerSave is not supported if kernel version is below 2.6.20
2406 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2408 //RT_TRACE(COMP_PS, "%s()============>come to wake up\n", __FUNCTION__);
2409 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);
2412 void rtl8192_hw_wakeup_wq (struct work_struct *work)
2414 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
2415 // struct ieee80211_device * ieee = (struct ieee80211_device*)
2416 // container_of(work, struct ieee80211_device, watch_dog_wq);
2417 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
2418 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
2419 struct net_device *dev = ieee->dev;
2420 rtl8192_hw_wakeup(dev);
2424 #define MIN_SLEEP_TIME 50
2425 #define MAX_SLEEP_TIME 10000
2426 static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
2428 struct r8192_priv *priv = ieee80211_priv(dev);
2431 unsigned long flags;
2433 spin_lock_irqsave(&priv->ps_lock,flags);
2435 // Writing HW register with 0 equals to disable
2436 // the timer, that is not really what we want
2438 tl -= MSECS(8+16+7);
2440 // If the interval in witch we are requested to sleep is too
2441 // short then give up and remain awake
2442 // when we sleep after send null frame, the timer will be too short to sleep.
2444 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2445 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2446 spin_unlock_irqrestore(&priv->ps_lock,flags);
2447 printk("too short to sleep::%x, %x, %lx\n",tl, rb, MSECS(MIN_SLEEP_TIME));
2451 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
2452 ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
2453 ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
2454 printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME));
2455 spin_unlock_irqrestore(&priv->ps_lock,flags);
2459 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
2460 queue_delayed_work(priv->ieee80211->wq,
2461 &priv->ieee80211->hw_wakeup_wq,tmp);
2462 //PowerSave not supported when kernel version less 2.6.20
2464 queue_delayed_work(priv->ieee80211->wq,
2465 (void *)&priv->ieee80211->hw_sleep_wq,0);
2466 spin_unlock_irqrestore(&priv->ps_lock,flags);
2469 static void rtl8192_init_priv_variable(struct net_device* dev)
2471 struct r8192_priv *priv = ieee80211_priv(dev);
2473 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
2475 // Default Halt the NIC if RF is OFF.
2476 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC;
2477 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_CLK_REQ;
2478 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM;
2479 pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM;
2480 pPSC->bLeisurePs = true;
2481 pPSC->RegMaxLPSAwakeIntvl = 5;
2482 priv->bHwRadioOff = false;
2484 priv->being_init_adapter = false;
2485 priv->txbuffsize = 1600;//1024;
2486 priv->txfwbuffersize = 4096;
2487 priv->txringcount = 64;//32;
2488 //priv->txbeaconcount = priv->txringcount;
2489 priv->txbeaconcount = 2;
2490 priv->rxbuffersize = 9100;//2048;//1024;
2491 priv->rxringcount = MAX_RX_COUNT;//64;
2492 priv->irq_enabled=0;
2493 priv->card_8192 = NIC_8192E;
2494 priv->rx_skb_complete = 1;
2495 priv->chan = 1; //set to channel 1
2496 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
2497 priv->RegChannelPlan = 0xf;
2498 priv->nrxAMPDU_size = 0;
2499 priv->nrxAMPDU_aggr_num = 0;
2500 priv->last_rxdesc_tsf_high = 0;
2501 priv->last_rxdesc_tsf_low = 0;
2502 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
2503 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2504 priv->ieee80211->ieee_up=0;
2505 priv->retry_rts = DEFAULT_RETRY_RTS;
2506 priv->retry_data = DEFAULT_RETRY_DATA;
2507 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
2508 priv->ieee80211->rate = 110; //11 mbps
2509 priv->ieee80211->short_slot = 1;
2510 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
2511 priv->bcck_in_ch14 = false;
2512 priv->bfsync_processing = false;
2513 priv->CCKPresentAttentuation = 0;
2514 priv->rfa_txpowertrackingindex = 0;
2515 priv->rfc_txpowertrackingindex = 0;
2517 priv->ScanDelay = 50;//for Scan TODO
2518 //added by amy for silent reset
2519 priv->ResetProgress = RESET_TYPE_NORESET;
2520 priv->bForcedSilentReset = 0;
2521 priv->bDisableNormalResetCheck = false;
2522 priv->force_reset = false;
2523 //added by amy for power save
2525 priv->ieee80211->RfOffReason = 0;
2526 priv->RFChangeInProgress = false;
2527 priv->bHwRfOffAction = 0;
2528 priv->SetRFPowerStateInProgress = false;
2529 priv->ieee80211->PowerSaveControl.bInactivePs = true;
2530 priv->ieee80211->PowerSaveControl.bIPSModeBackup = false;
2532 priv->txpower_checkcnt = 0;
2533 priv->thermal_readback_index =0;
2534 priv->txpower_tracking_callback_cnt = 0;
2535 priv->ccktxpower_adjustcnt_ch14 = 0;
2536 priv->ccktxpower_adjustcnt_not_ch14 = 0;
2538 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2539 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2540 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2541 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2542 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;/* |
2543 IEEE_SOFTMAC_BEACONS;*///added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE;
2545 priv->ieee80211->active_scan = 1;
2546 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
2547 priv->ieee80211->host_encrypt = 1;
2548 priv->ieee80211->host_decrypt = 1;
2549 //priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
2550 //priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
2551 priv->ieee80211->start_send_beacons = rtl8192_start_beacon;//+by david 081107
2552 priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;//+by david 081107
2553 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
2554 priv->ieee80211->set_chan = rtl8192_set_chan;
2555 priv->ieee80211->link_change = rtl8192_link_change;
2556 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
2557 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
2558 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
2559 priv->ieee80211->init_wmmparam_flag = 0;
2560 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2561 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
2562 priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI);
2563 priv->ieee80211->qos_support = 1;
2564 priv->ieee80211->dot11PowerSaveMode = 0;
2566 // priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
2567 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
2568 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
2569 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
2571 priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup;
2572 // priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack;
2573 priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep;
2574 priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
2576 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci;
2577 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
2578 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci;
2581 priv->ieee80211->InitialGainHandler = InitialGain819xPci;
2584 priv->ieee80211->ieee80211_ips_leave_wq = ieee80211_ips_leave_wq;
2585 priv->ieee80211->ieee80211_ips_leave = ieee80211_ips_leave;
2588 priv->ieee80211->LeisurePSLeave = LeisurePSLeave;
2591 priv->ieee80211->SetHwRegHandler = rtl8192e_SetHwReg;
2592 priv->ieee80211->rtllib_ap_sec_type = rtl8192e_ap_sec_type;
2594 priv->card_type = USB;
2596 priv->ShortRetryLimit = 0x30;
2597 priv->LongRetryLimit = 0x30;
2599 priv->EarlyRxThreshold = 7;
2600 priv->enable_gpio0 = 0;
2602 priv->TransmitConfig = 0;
2604 priv->ReceiveConfig = RCR_ADD3 |
2605 RCR_AMF | RCR_ADF | //accept management/data
2606 RCR_AICV | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2607 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2608 RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) |
2609 ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT;
2611 priv->irq_mask = (u32)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK |\
2612 IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK |\
2613 IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW |\
2614 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2616 priv->AcmControl = 0;
2617 priv->pFirmware = (rt_firmware*)vmalloc(sizeof(rt_firmware));
2618 if (priv->pFirmware)
2619 memset(priv->pFirmware, 0, sizeof(rt_firmware));
2621 /* rx related queue */
2622 skb_queue_head_init(&priv->rx_queue);
2623 skb_queue_head_init(&priv->skb_queue);
2625 /* Tx related queue */
2626 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2627 skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
2629 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2630 skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
2632 priv->rf_set_chan = rtl8192_phy_SwChnl;
2636 static void rtl8192_init_priv_lock(struct r8192_priv* priv)
2638 spin_lock_init(&priv->tx_lock);
2639 spin_lock_init(&priv->irq_lock);//added by thomas
2640 spin_lock_init(&priv->irq_th_lock);
2641 spin_lock_init(&priv->rf_ps_lock);
2642 spin_lock_init(&priv->ps_lock);
2643 //spin_lock_init(&priv->rf_lock);
2644 sema_init(&priv->wx_sem,1);
2645 sema_init(&priv->rf_sem,1);
2646 mutex_init(&priv->mutex);
2649 extern void rtl819x_watchdog_wqcallback(struct work_struct *work);
2651 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
2652 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
2653 void rtl8192_prepare_beacon(struct r8192_priv *priv);
2654 //init tasklet and wait_queue here. only 2.6 above kernel is considered
2655 #define DRV_NAME "wlan0"
2656 static void rtl8192_init_priv_task(struct net_device* dev)
2658 struct r8192_priv *priv = ieee80211_priv(dev);
2660 #ifdef PF_SYNCTHREAD
2661 priv->priv_wq = create_workqueue(DRV_NAME,0);
2663 priv->priv_wq = create_workqueue(DRV_NAME);
2667 INIT_WORK(&priv->ieee80211->ips_leave_wq, (void*)IPSLeave_wq);
2670 // INIT_WORK(&priv->reset_wq, (void(*)(void*)) rtl8192_restart);
2671 INIT_WORK(&priv->reset_wq, rtl8192_restart);
2672 // INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
2673 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
2674 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
2675 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
2676 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
2677 //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem);
2678 //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem);
2679 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
2680 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq);
2681 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq);
2683 tasklet_init(&priv->irq_rx_tasklet,
2684 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
2685 (unsigned long)priv);
2686 tasklet_init(&priv->irq_tx_tasklet,
2687 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
2688 (unsigned long)priv);
2689 tasklet_init(&priv->irq_prepare_beacon_tasklet,
2690 (void(*)(unsigned long))rtl8192_prepare_beacon,
2691 (unsigned long)priv);
2694 static void rtl8192_get_eeprom_size(struct net_device* dev)
2697 struct r8192_priv *priv = ieee80211_priv(dev);
2698 RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__);
2699 curCR = read_nic_dword(dev, EPROM_CMD);
2700 RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR);
2701 //whether need I consider BIT5?
2702 priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EPROM_93c56 : EPROM_93c46;
2703 RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
2706 //used to swap endian. as ntohl & htonl are not neccessary to swap endian, so use this instead.
2707 static inline u16 endian_swap(u16* data)
2710 *data = (tmp >> 8) | (tmp << 8);
2715 * Note: Adapter->EEPROMAddressSize should be set before this function call.
2716 * EEPROM address size can be got through GetEEPROMSize8185()
2718 static void rtl8192_read_eeprom_info(struct net_device* dev)
2720 struct r8192_priv *priv = ieee80211_priv(dev);
2724 u8 ICVer8192, ICVer8256;
2726 u16 i,usValue, IC_Version;
2729 u8 offset;//, tmpAFR;
2730 u8 EepromTxPower[100];
2732 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01};
2733 RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n");
2736 // TODO: I don't know if we need to apply EF function to EEPROM read function
2738 //2 Read EEPROM ID to make sure autoload is success
2739 EEPROMId = eprom_read(dev, 0);
2740 if( EEPROMId != RTL8190_EEPROM_ID )
2742 RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID);
2743 priv->AutoloadFailFlag=true;
2747 priv->AutoloadFailFlag=false;
2751 // Assign Chip Version ID
2753 // Read IC Version && Channel Plan
2754 if(!priv->AutoloadFailFlag)
2757 priv->eeprom_vid = eprom_read(dev, (EEPROM_VID >> 1));
2758 priv->eeprom_did = eprom_read(dev, (EEPROM_DID >> 1));
2760 usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8 ;
2761 priv->eeprom_CustomerID = (u8)( usValue & 0xff);
2762 usValue = eprom_read(dev, (EEPROM_ICVersion_ChannelPlan>>1));
2763 priv->eeprom_ChannelPlan = usValue&0xff;
2764 IC_Version = ((usValue&0xff00)>>8);
2767 priv->card_8192_version = (VERSION_8190)(IC_Version);
2770 ICVer8192 = (IC_Version&0xf); //bit0~3; 1:A cut, 2:B cut, 3:C cut...
2771 ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut...
2772 RT_TRACE(COMP_INIT, "\nICVer8192 = 0x%x\n", ICVer8192);
2773 RT_TRACE(COMP_INIT, "\nICVer8256 = 0x%x\n", ICVer8256);
2774 if(ICVer8192 == 0x2) //B-cut
2776 if(ICVer8256 == 0x5) //E-cut
2777 priv->card_8192_version= VERSION_8190_BE;
2781 switch(priv->card_8192_version)
2783 case VERSION_8190_BD:
2784 case VERSION_8190_BE:
2787 priv->card_8192_version = VERSION_8190_BD;
2790 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", priv->card_8192_version);
2794 priv->card_8192_version = VERSION_8190_BD;
2795 priv->eeprom_vid = 0;
2796 priv->eeprom_did = 0;
2797 priv->eeprom_CustomerID = 0;
2798 priv->eeprom_ChannelPlan = 0;
2799 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", 0xff);
2802 RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
2803 RT_TRACE(COMP_INIT, "EEPROM DID = 0x%4x\n", priv->eeprom_did);
2804 RT_TRACE(COMP_INIT,"EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID);
2806 //2 Read Permanent MAC address
2807 if(!priv->AutoloadFailFlag)
2809 for(i = 0; i < 6; i += 2)
2811 usValue = eprom_read(dev, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1));
2812 *(u16*)(&dev->dev_addr[i]) = usValue;
2815 // when auto load failed, the last address byte set to be a random one.
2816 // added by david woo.2007/11/7
2817 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
2820 RT_TRACE(COMP_INIT, "Permanent Address = %pM\n", dev->dev_addr);
2822 //2 TX Power Check EEPROM Fail or not
2823 if(priv->card_8192_version > VERSION_8190_BD) {
2824 priv->bTXPowerDataReadFromEEPORM = true;
2826 priv->bTXPowerDataReadFromEEPORM = false;
2829 // 2007/11/15 MH 8190PCI Default=2T4R, 8192PCIE default=1T2R
2830 priv->rf_type = RTL819X_DEFAULT_RF_TYPE;
2832 if(priv->card_8192_version > VERSION_8190_BD)
2834 // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate.
2835 if(!priv->AutoloadFailFlag)
2837 tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff>>1))) & 0xff;
2838 priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; // bit[3:0]
2840 if (tempval&0x80) //RF-indication, bit[7]
2841 priv->rf_type = RF_1T2R;
2843 priv->rf_type = RF_2T4R;
2847 priv->EEPROMLegacyHTTxPowerDiff = EEPROM_Default_LegacyHTTxPowerDiff;
2849 RT_TRACE(COMP_INIT, "EEPROMLegacyHTTxPowerDiff = %d\n",
2850 priv->EEPROMLegacyHTTxPowerDiff);
2852 // Read ThermalMeter from EEPROM
2853 if(!priv->AutoloadFailFlag)
2855 priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8);
2859 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2861 RT_TRACE(COMP_INIT, "ThermalMeter = %d\n", priv->EEPROMThermalMeter);
2862 //vivi, for tx power track
2863 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
2865 if(priv->epromtype == EPROM_93c46)
2867 // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM
2868 if(!priv->AutoloadFailFlag)
2870 usValue = eprom_read(dev, (EEPROM_TxPwDiff_CrystalCap>>1));
2871 priv->EEPROMAntPwDiff = (usValue&0x0fff);
2872 priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12);
2876 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2877 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2879 RT_TRACE(COMP_INIT, "EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2880 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2883 // Get per-channel Tx Power Level
2885 for(i=0; i<14; i+=2)
2887 if(!priv->AutoloadFailFlag)
2889 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) );
2893 usValue = EEPROM_Default_TxPower;
2895 *((u16*)(&priv->EEPROMTxPowerLevelCCK[i])) = usValue;
2896 RT_TRACE(COMP_INIT,"CCK Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK[i]);
2897 RT_TRACE(COMP_INIT, "CCK Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelCCK[i+1]);
2899 for(i=0; i<14; i+=2)
2901 if(!priv->AutoloadFailFlag)
2903 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) );
2907 usValue = EEPROM_Default_TxPower;
2909 *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[i])) = usValue;
2910 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelOFDM24G[i]);
2911 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelOFDM24G[i+1]);
2914 else if(priv->epromtype== EPROM_93c56)
2917 // Read CrystalCap from EEPROM
2918 if(!priv->AutoloadFailFlag)
2920 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2921 priv->EEPROMCrystalCap = (u8)(((eprom_read(dev, (EEPROM_C56_CrystalCap>>1))) & 0xf000)>>12);
2925 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2926 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2928 RT_TRACE(COMP_INIT,"EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2929 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2931 // Get Tx Power Level by Channel
2932 if(!priv->AutoloadFailFlag)
2934 // Read Tx power of Channel 1 ~ 14 from EEPROM.
2935 for(i = 0; i < 12; i+=2)
2938 offset = EEPROM_C56_RfA_CCK_Chnl1_TxPwIndex + i;
2940 offset = EEPROM_C56_RfC_CCK_Chnl1_TxPwIndex + i - 6;
2941 usValue = eprom_read(dev, (offset>>1));
2942 *((u16*)(&EepromTxPower[i])) = usValue;
2945 for(i = 0; i < 12; i++)
2948 priv->EEPROMRfACCKChnl1TxPwLevel[i] = EepromTxPower[i];
2949 else if ((i >=3 )&&(i <= 5))
2950 priv->EEPROMRfAOfdmChnlTxPwLevel[i-3] = EepromTxPower[i];
2951 else if ((i >=6 )&&(i <= 8))
2952 priv->EEPROMRfCCCKChnl1TxPwLevel[i-6] = EepromTxPower[i];
2954 priv->EEPROMRfCOfdmChnlTxPwLevel[i-9] = EepromTxPower[i];
2959 priv->EEPROMRfACCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2960 priv->EEPROMRfACCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2961 priv->EEPROMRfACCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2963 priv->EEPROMRfAOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2964 priv->EEPROMRfAOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2965 priv->EEPROMRfAOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2967 priv->EEPROMRfCCCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2968 priv->EEPROMRfCCCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2969 priv->EEPROMRfCCCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2971 priv->EEPROMRfCOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2972 priv->EEPROMRfCOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2973 priv->EEPROMRfCOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2975 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[0]);
2976 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[1]);
2977 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[2]);
2978 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[0]);
2979 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[1]);
2980 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[2]);
2981 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[0]);
2982 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[1]);
2983 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[2]);
2984 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[0]);
2985 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[1]);
2986 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[2]);
2991 // Update HAL variables.
2993 if(priv->epromtype == EPROM_93c46)
2997 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK[i];
2998 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[i];
3000 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
3001 // Antenna B gain offset to antenna A, bit0~3
3002 priv->AntennaTxPwDiff[0] = (priv->EEPROMAntPwDiff & 0xf);
3003 // Antenna C gain offset to antenna A, bit4~7
3004 priv->AntennaTxPwDiff[1] = ((priv->EEPROMAntPwDiff & 0xf0)>>4);
3005 // Antenna D gain offset to antenna A, bit8~11
3006 priv->AntennaTxPwDiff[2] = ((priv->EEPROMAntPwDiff & 0xf00)>>8);
3007 // CrystalCap, bit12~15
3008 priv->CrystalCap = priv->EEPROMCrystalCap;
3009 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
3010 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
3011 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
3013 else if(priv->epromtype == EPROM_93c56)
3015 //char cck_pwr_diff_a=0, cck_pwr_diff_c=0;
3017 //cck_pwr_diff_a = pHalData->EEPROMRfACCKChnl7TxPwLevel - pHalData->EEPROMRfAOfdmChnlTxPwLevel[1];
3018 //cck_pwr_diff_c = pHalData->EEPROMRfCCCKChnl7TxPwLevel - pHalData->EEPROMRfCOfdmChnlTxPwLevel[1];
3019 for(i=0; i<3; i++) // channel 1~3 use the same Tx Power Level.
3021 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[0];
3022 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[0];
3023 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[0];
3024 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[0];
3026 for(i=3; i<9; i++) // channel 4~9 use the same Tx Power Level
3028 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[1];
3029 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[1];
3030 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[1];
3031 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[1];
3033 for(i=9; i<14; i++) // channel 10~14 use the same Tx Power Level
3035 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[2];
3036 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[2];
3037 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[2];
3038 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[2];
3041 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_A[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_A[i]);
3043 RT_TRACE(COMP_INIT,"priv->TxPowerLevelOFDM24G_A[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_A[i]);
3045 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_C[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_C[i]);
3047 RT_TRACE(COMP_INIT, "priv->TxPowerLevelOFDM24G_C[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_C[i]);
3048 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
3049 priv->AntennaTxPwDiff[0] = 0;
3050 priv->AntennaTxPwDiff[1] = 0;
3051 priv->AntennaTxPwDiff[2] = 0;
3052 priv->CrystalCap = priv->EEPROMCrystalCap;
3053 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
3054 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
3055 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
3059 if(priv->rf_type == RF_1T2R)
3061 RT_TRACE(COMP_INIT, "\n1T2R config\n");
3063 else if (priv->rf_type == RF_2T4R)
3065 RT_TRACE(COMP_INIT, "\n2T4R config\n");
3068 // 2008/01/16 MH We can only know RF type in the function. So we have to init
3069 // DIG RATR table again.
3070 init_rate_adaptive(dev);
3072 //1 Make a copy for following variables and we can change them if we want
3074 priv->rf_chip= RF_8256;
3076 if(priv->RegChannelPlan == 0xf)
3078 priv->ChannelPlan = priv->eeprom_ChannelPlan;
3082 priv->ChannelPlan = priv->RegChannelPlan;
3086 // Used PID and DID to Set CustomerID
3088 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304 )
3090 priv->CustomerID = RT_CID_DLINK;
3093 switch(priv->eeprom_CustomerID)
3095 case EEPROM_CID_DEFAULT:
3096 priv->CustomerID = RT_CID_DEFAULT;
3098 case EEPROM_CID_CAMEO:
3099 priv->CustomerID = RT_CID_819x_CAMEO;
3101 case EEPROM_CID_RUNTOP:
3102 priv->CustomerID = RT_CID_819x_RUNTOP;
3104 case EEPROM_CID_NetCore:
3105 priv->CustomerID = RT_CID_819x_Netcore;
3107 case EEPROM_CID_TOSHIBA: // Merge by Jacken, 2008/01/31
3108 priv->CustomerID = RT_CID_TOSHIBA;
3109 if(priv->eeprom_ChannelPlan&0x80)
3110 priv->ChannelPlan = priv->eeprom_ChannelPlan&0x7f;
3112 priv->ChannelPlan = 0x0;
3113 RT_TRACE(COMP_INIT, "Toshiba ChannelPlan = 0x%x\n",
3116 case EEPROM_CID_Nettronix:
3117 priv->ScanDelay = 100; //cosa add for scan
3118 priv->CustomerID = RT_CID_Nettronix;
3120 case EEPROM_CID_Pronet:
3121 priv->CustomerID = RT_CID_PRONET;
3123 case EEPROM_CID_DLINK:
3124 priv->CustomerID = RT_CID_DLINK;
3127 case EEPROM_CID_WHQL:
3128 //Adapter->bInHctTest = TRUE;//do not supported
3130 //priv->bSupportTurboMode = FALSE;
3131 //priv->bAutoTurboBy8186 = FALSE;
3133 //pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
3134 //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
3135 //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
3139 // value from RegCustomerID
3143 //Avoid the channel plan array overflow, by Bruce, 2007-08-27.
3144 if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1)
3145 priv->ChannelPlan = 0; //FCC
3147 switch(priv->CustomerID)
3149 case RT_CID_DEFAULT:
3151 priv->LedStrategy = HW_LED;
3154 priv->LedStrategy = SW_LED_MODE1;
3159 case RT_CID_819x_CAMEO:
3160 priv->LedStrategy = SW_LED_MODE2;
3163 case RT_CID_819x_RUNTOP:
3164 priv->LedStrategy = SW_LED_MODE3;
3167 case RT_CID_819x_Netcore:
3168 priv->LedStrategy = SW_LED_MODE4;
3171 case RT_CID_Nettronix:
3172 priv->LedStrategy = SW_LED_MODE5;
3176 priv->LedStrategy = SW_LED_MODE6;
3179 case RT_CID_TOSHIBA: //Modify by Jacken 2008/01/31
3185 priv->LedStrategy = HW_LED;
3188 priv->LedStrategy = SW_LED_MODE1;
3195 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304)
3196 priv->ieee80211->bSupportRemoteWakeUp = true;
3198 priv->ieee80211->bSupportRemoteWakeUp = false;
3201 RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan);
3202 RT_TRACE(COMP_INIT, "ChannelPlan = %d \n", priv->ChannelPlan);
3203 RT_TRACE(COMP_INIT, "LedStrategy = %d \n", priv->LedStrategy);
3204 RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n");
3210 static short rtl8192_get_channel_map(struct net_device * dev)
3212 struct r8192_priv *priv = ieee80211_priv(dev);
3213 #ifdef ENABLE_DOT11D
3214 if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){
3215 printk("rtl8180_init:Error channel plan! Set to default.\n");
3216 priv->ChannelPlan= 0;
3218 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
3220 rtl819x_set_channel_map(priv->ChannelPlan, priv);
3223 //Set Default Channel Plan
3225 DMESG("No channels, aborting");
3229 priv->ChannelPlan= 0;//hikaru
3230 // set channels 1..14 allowed in given locale
3231 for (i=1; i<=14; i++) {
3232 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
3239 static short rtl8192_init(struct net_device *dev)
3241 struct r8192_priv *priv = ieee80211_priv(dev);
3242 memset(&(priv->stats),0,sizeof(struct Stats));
3243 rtl8192_init_priv_variable(dev);
3244 rtl8192_init_priv_lock(priv);
3245 rtl8192_init_priv_task(dev);
3246 rtl8192_get_eeprom_size(dev);
3247 rtl8192_read_eeprom_info(dev);
3248 rtl8192_get_channel_map(dev);
3250 init_timer(&priv->watch_dog_timer);
3251 priv->watch_dog_timer.data = (unsigned long)dev;
3252 priv->watch_dog_timer.function = watch_dog_timer_callback;
3253 #if defined(IRQF_SHARED)
3254 if(request_irq(dev->irq, (void*)rtl8192_interrupt, IRQF_SHARED, dev->name, dev)){
3256 if(request_irq(dev->irq, (void *)rtl8192_interrupt, SA_SHIRQ, dev->name, dev)){
3258 printk("Error allocating IRQ %d",dev->irq);
3262 printk("IRQ %d",dev->irq);
3264 if(rtl8192_pci_initdescring(dev)!=0){
3265 printk("Endopoints initialization failed");
3269 //rtl8192_rx_enable(dev);
3270 //rtl8192_adapter_start(dev);
3274 /******************************************************************************
3275 *function: This function actually only set RRSR, RATR and BW_OPMODE registers
3276 * not to do all the hw config as its name says
3277 * input: net_device dev
3280 * notice: This part need to modified according to the rate set we filtered
3281 * ****************************************************************************/
3282 static void rtl8192_hwconfig(struct net_device* dev)
3284 u32 regRATR = 0, regRRSR = 0;
3285 u8 regBwOpMode = 0, regTmp = 0;
3286 struct r8192_priv *priv = ieee80211_priv(dev);
3288 // Set RRSR, RATR, and BW_OPMODE registers
3290 switch(priv->ieee80211->mode)
3292 case WIRELESS_MODE_B:
3293 regBwOpMode = BW_OPMODE_20MHZ;
3294 regRATR = RATE_ALL_CCK;
3295 regRRSR = RATE_ALL_CCK;
3297 case WIRELESS_MODE_A:
3298 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
3299 regRATR = RATE_ALL_OFDM_AG;
3300 regRRSR = RATE_ALL_OFDM_AG;
3302 case WIRELESS_MODE_G:
3303 regBwOpMode = BW_OPMODE_20MHZ;
3304 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3305 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3307 case WIRELESS_MODE_AUTO:
3308 case WIRELESS_MODE_N_24G:
3309 // It support CCK rate by default.
3310 // CCK rate will be filtered out only when associated AP does not support it.
3311 regBwOpMode = BW_OPMODE_20MHZ;
3312 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
3313 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
3315 case WIRELESS_MODE_N_5G:
3316 regBwOpMode = BW_OPMODE_5G;
3317 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
3318 regRRSR = RATE_ALL_OFDM_AG;
3322 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
3325 ratr_value = regRATR;
3326 if (priv->rf_type == RF_1T2R)
3328 ratr_value &= ~(RATE_ALL_OFDM_2SS);
3330 write_nic_dword(dev, RATR0, ratr_value);
3331 write_nic_byte(dev, UFWP, 1);
3333 regTmp = read_nic_byte(dev, 0x313);
3334 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
3335 write_nic_dword(dev, RRSR, regRRSR);
3338 // Set Retry Limit here
3340 write_nic_word(dev, RETRY_LIMIT,
3341 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | \
3342 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
3343 // Set Contention Window here
3347 // Set Tx Antenna including Feedback control
3349 // Set Auto Rate fallback control
3355 static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
3357 struct r8192_priv *priv = ieee80211_priv(dev);
3358 // struct ieee80211_device *ieee = priv->ieee80211;
3360 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
3361 // static char szMACPHYRegFile[] = RTL819X_PHY_MACPHY_REG;
3362 // static char szMACPHYRegPGFile[] = RTL819X_PHY_MACPHY_REG_PG;
3366 u8 ICVersion,SwitchingRegulatorOutput;
3368 bool bfirmwareok = true;
3372 u32 tmpRegA, tmpRegC, TempCCk;
3374 // u32 dwRegRead = 0;
3376 RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
3377 priv->being_init_adapter = true;
3378 rtl8192_pci_resetdescring(dev);
3379 // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W.
3380 priv->Rf_Mode = RF_OP_By_SW_3wire;
3383 if(priv->ResetProgress == RESET_TYPE_NORESET)
3385 write_nic_byte(dev, ANAPAR, 0x37);
3386 // Accordign to designer's explain, LBUS active will never > 10ms. We delay 10ms
3387 // Joseph increae the time to prevent firmware download fail
3391 //PlatformSleepUs(10000);
3392 // For any kind of InitializeAdapter process, we shall use system now!!
3393 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
3395 // Set to eRfoff in order not to count receive count.
3396 if(priv->RegRfOff == TRUE)
3397 priv->ieee80211->eRFPowerState = eRfOff;
3400 //3 //Config CPUReset Register
3402 //3 Firmware Reset Or Not
3403 ulRegRead = read_nic_dword(dev, CPU_GEN);
3404 if(priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
3405 { //called from MPInitialized. do nothing
3406 ulRegRead |= CPU_GEN_SYSTEM_RESET;
3407 }else if(priv->pFirmware->firmware_status == FW_STATUS_5_READY)
3408 ulRegRead |= CPU_GEN_FIRMWARE_RESET; // Called from MPReset
3410 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status);
3413 //2008.06.03, for WOL 90 hw bug
3414 ulRegRead &= (~(CPU_GEN_GPIO_UART));
3417 write_nic_dword(dev, CPU_GEN, ulRegRead);
3423 //3 //Fix the issue of E-cut high temperature issue
3426 ICVersion = read_nic_byte(dev, IC_VERRSION);
3427 if(ICVersion >= 0x4) //E-cut only
3429 // HW SD suggest that we should not wirte this register too often, so driver
3430 // should readback this register. This register will be modified only when
3432 SwitchingRegulatorOutput = read_nic_byte(dev, SWREGULATOR);
3433 if(SwitchingRegulatorOutput != 0xb8)
3435 write_nic_byte(dev, SWREGULATOR, 0xa8);
3437 write_nic_byte(dev, SWREGULATOR, 0xb8);
3444 //3// Initialize BB before MAC
3446 RT_TRACE(COMP_INIT, "BB Config Start!\n");
3447 rtStatus = rtl8192_BBConfig(dev);
3448 if(rtStatus != RT_STATUS_SUCCESS)
3450 RT_TRACE(COMP_ERR, "BB Config failed\n");
3453 RT_TRACE(COMP_INIT,"BB Config Finished!\n");
3455 //3//Set Loopback mode or Normal mode
3457 //2006.12.13 by emily. Note!We should not merge these two CPU_GEN register writings
3458 // because setting of System_Reset bit reset MAC to default transmission mode.
3459 //Loopback mode or not
3460 priv->LoopbackMode = RTL819X_NO_LOOPBACK;
3461 //priv->LoopbackMode = RTL819X_MAC_LOOPBACK;
3462 if(priv->ResetProgress == RESET_TYPE_NORESET)
3464 ulRegRead = read_nic_dword(dev, CPU_GEN);
3465 if(priv->LoopbackMode == RTL819X_NO_LOOPBACK)
3467 ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
3469 else if (priv->LoopbackMode == RTL819X_MAC_LOOPBACK )
3471 ulRegRead |= CPU_CCK_LOOPBACK;
3475 RT_TRACE(COMP_ERR,"Serious error: wrong loopback mode setting\n");
3478 //2008.06.03, for WOL
3479 //ulRegRead &= (~(CPU_GEN_GPIO_UART));
3480 write_nic_dword(dev, CPU_GEN, ulRegRead);
3482 // 2006.11.29. After reset cpu, we sholud wait for a second, otherwise, it may fail to write registers. Emily
3485 //3Set Hardware(Do nothing now)
3486 rtl8192_hwconfig(dev);
3487 //2=======================================================
3488 // Common Setting for all of the FPGA platform. (part 1)
3489 //2=======================================================
3490 // If there is changes, please make sure it applies to all of the FPGA version
3492 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
3496 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) | \
3497 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) | \
3501 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |\
3502 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) ));
3506 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
3507 write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]);
3509 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3511 //3 Initialize Number of Reserved Pages in Firmware Queue
3513 if(priv->bInHctTest)
3515 PlatformEFIOWrite4Byte(Adapter, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM << RSVD_FW_QUEUE_PAGE_BK_SHIFT |\
3516 NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM << RSVD_FW_QUEUE_PAGE_BE_SHIFT | \
3517 NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM << RSVD_FW_QUEUE_PAGE_VI_SHIFT | \
3518 NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3519 PlatformEFIOWrite4Byte(Adapter, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3520 PlatformEFIOWrite4Byte(Adapter, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| \
3521 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|\
3522 NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3527 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |\
3528 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT | \
3529 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT | \
3530 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3531 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3532 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| \
3533 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|\
3534 NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3537 rtl8192_tx_enable(dev);
3538 rtl8192_rx_enable(dev);
3539 //3Set Response Rate Setting Register
3540 // CCK rate is supported by default.
3541 // CCK rate will be filtered out only when associated AP does not support it.
3542 ulRegRead = (0xFFF00000 & read_nic_dword(dev, RRSR)) | RATE_ALL_OFDM_AG | RATE_ALL_CCK;
3543 write_nic_dword(dev, RRSR, ulRegRead);
3544 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
3547 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
3548 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
3550 //rtl8192_actset_wirelessmode(dev,priv->RegWirelessMode);
3551 if(priv->ResetProgress == RESET_TYPE_NORESET)
3552 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
3553 //-----------------------------------------------------------------------------
3554 // Set up security related. 070106, by rcnjko:
3555 // 1. Clear all H/W keys.
3556 // 2. Enable H/W encryption/decryption.
3557 //-----------------------------------------------------------------------------
3558 CamResetAllEntry(dev);
3560 u8 SECR_value = 0x0;
3561 SECR_value |= SCR_TxEncEnable;
3562 SECR_value |= SCR_RxDecEnable;
3563 SECR_value |= SCR_NoSKMC;
3564 write_nic_byte(dev, SECR, SECR_value);
3567 write_nic_word(dev, ATIMWND, 2);
3568 write_nic_word(dev, BCN_INTERVAL, 100);
3569 for (i=0; i<QOS_QUEUE_NUM; i++)
3570 write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
3572 // Switching regulator controller: This is set temporarily.
3573 // It's not sure if this can be removed in the future.
3574 // PJ advised to leave it by default.
3576 write_nic_byte(dev, 0xbe, 0xc0);
3578 //2=======================================================
3579 // Set PHY related configuration defined in MAC register bank
3580 //2=======================================================
3581 rtl8192_phy_configmac(dev);
3583 if (priv->card_8192_version > (u8) VERSION_8190_BD) {
3584 rtl8192_phy_getTxPower(dev);
3585 rtl8192_phy_setTxPower(dev, priv->chan);
3589 tmpvalue = read_nic_byte(dev, IC_VERRSION);
3590 priv->IC_Cut = tmpvalue;
3591 RT_TRACE(COMP_INIT, "priv->IC_Cut = 0x%x\n", priv->IC_Cut);
3592 if(priv->IC_Cut >= IC_VersionCut_D)
3594 //pHalData->bDcut = TRUE;
3595 if(priv->IC_Cut == IC_VersionCut_D)
3596 RT_TRACE(COMP_INIT, "D-cut\n");
3597 if(priv->IC_Cut == IC_VersionCut_E)
3599 RT_TRACE(COMP_INIT, "E-cut\n");
3600 // HW SD suggest that we should not wirte this register too often, so driver
3601 // should readback this register. This register will be modified only when
3607 //pHalData->bDcut = FALSE;
3608 RT_TRACE(COMP_INIT, "Before C-cut\n");
3613 RT_TRACE(COMP_INIT, "Load Firmware!\n");
3614 bfirmwareok = init_firmware(dev);
3615 if(bfirmwareok != true) {
3616 rtStatus = RT_STATUS_FAILURE;
3619 RT_TRACE(COMP_INIT, "Load Firmware finished!\n");
3622 if(priv->ResetProgress == RESET_TYPE_NORESET)
3624 RT_TRACE(COMP_INIT, "RF Config Started!\n");
3625 rtStatus = rtl8192_phy_RFConfig(dev);
3626 if(rtStatus != RT_STATUS_SUCCESS)
3628 RT_TRACE(COMP_ERR, "RF Config failed\n");
3631 RT_TRACE(COMP_INIT, "RF Config Finished!\n");
3633 rtl8192_phy_updateInitGain(dev);
3635 /*---- Set CCK and OFDM Block "ON"----*/
3636 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
3637 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
3641 write_nic_byte(dev, 0x87, 0x0);
3644 //2008.06.03, for WOL
3645 ucRegRead = read_nic_byte(dev, GPE);
3647 write_nic_byte(dev, GPE, ucRegRead);
3649 ucRegRead = read_nic_byte(dev, GPO);
3651 write_nic_byte(dev, GPO, ucRegRead);
3654 //2=======================================================
3656 //2=======================================================
3660 if(priv->RegRfOff == TRUE)
3661 { // User disable RF via registry.
3662 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RegRfOff ----------\n",__FUNCTION__);
3663 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_SW);
3664 #if 0//cosa, ask SD3 willis and he doesn't know what is this for
3665 // Those action will be discard in MgntActSet_RF_State because off the same state
3666 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
3667 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3670 else if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
3671 { // H/W or S/W RF OFF before sleep.
3672 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3673 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3675 else if(priv->ieee80211->RfOffReason >= RF_CHANGE_BY_IPS)
3676 { // H/W or S/W RF OFF before sleep.
3677 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3678 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3682 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__);
3683 priv->ieee80211->eRFPowerState = eRfOn;
3684 priv->ieee80211->RfOffReason = 0;
3685 //DrvIFIndicateCurrentPhyStatus(Adapter);
3687 //Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_ON);
3690 // If inactive power mode is enabled, disable rf while in disconnected state.
3691 // But we should still tell upper layer we are in rf on state.
3692 // 2007.07.16, by shien chang.
3694 //if(!Adapter->bInHctTest)
3695 //IPSEnter(Adapter);
3702 // We can force firmware to do RF-R/W
3703 if(priv->ieee80211->FwRWRF)
3704 priv->Rf_Mode = RF_OP_By_FW;
3706 priv->Rf_Mode = RF_OP_By_SW_3wire;
3708 priv->Rf_Mode = RF_OP_By_SW_3wire;
3712 if(priv->ResetProgress == RESET_TYPE_NORESET)
3714 dm_initialize_txpower_tracking(dev);
3716 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3717 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3719 if(priv->rf_type == RF_2T4R){
3720 for(i = 0; i<TxBBGainTableLength; i++)
3722 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3724 priv->rfa_txpowertrackingindex= (u8)i;
3725 priv->rfa_txpowertrackingindex_real= (u8)i;
3726 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3731 for(i = 0; i<TxBBGainTableLength; i++)
3733 if(tmpRegC == priv->txbbgain_table[i].txbbgain_value)
3735 priv->rfc_txpowertrackingindex= (u8)i;
3736 priv->rfc_txpowertrackingindex_real= (u8)i;
3737 priv->rfc_txpowertracking_default = priv->rfc_txpowertrackingindex;
3741 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3743 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3745 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3747 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3751 priv->CCKPresentAttentuation_40Mdefault = 0;
3752 priv->CCKPresentAttentuation_difference = 0;
3753 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3754 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3755 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3756 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_initial = %d\n", priv->rfc_txpowertrackingindex);
3757 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real_initial = %d\n", priv->rfc_txpowertrackingindex_real);
3758 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3759 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3763 if(priv->ResetProgress == RESET_TYPE_NORESET)
3765 dm_initialize_txpower_tracking(dev);
3767 if(priv->IC_Cut >= IC_VersionCut_D)
3769 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3770 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3771 for(i = 0; i<TxBBGainTableLength; i++)
3773 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3775 priv->rfa_txpowertrackingindex= (u8)i;
3776 priv->rfa_txpowertrackingindex_real= (u8)i;
3777 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3782 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3784 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3786 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3788 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3792 priv->CCKPresentAttentuation_40Mdefault = 0;
3793 priv->CCKPresentAttentuation_difference = 0;
3794 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3795 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3796 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3797 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3798 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3799 priv->btxpower_tracking = FALSE;//TEMPLY DISABLE
3804 rtl8192_irq_enable(dev);
3805 priv->being_init_adapter = false;
3810 void rtl8192_prepare_beacon(struct r8192_priv *priv)
3812 struct sk_buff *skb;
3813 //unsigned long flags;
3816 skb = ieee80211_get_beacon(priv->ieee80211);
3817 tcb_desc = (cb_desc *)(skb->cb + 8);
3818 //printk("===========> %s\n", __FUNCTION__);
3819 //spin_lock_irqsave(&priv->tx_lock,flags);
3820 /* prepare misc info for the beacon xmit */
3821 tcb_desc->queue_index = BEACON_QUEUE;
3822 /* IBSS does not support HT yet, use 1M defaultly */
3823 tcb_desc->data_rate = 2;
3824 tcb_desc->RATRIndex = 7;
3825 tcb_desc->bTxDisableRateFallBack = 1;
3826 tcb_desc->bTxUseDriverAssingedRate = 1;
3828 skb_push(skb, priv->ieee80211->tx_headroom);
3830 rtl8192_tx(priv->ieee80211->dev,skb);
3832 //spin_unlock_irqrestore (&priv->tx_lock, flags);
3836 /* this configures registers for beacon tx and enables it via
3837 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
3838 * be used to stop beacon transmission
3840 void rtl8192_start_beacon(struct net_device *dev)
3842 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3843 struct ieee80211_network *net = &priv->ieee80211->current_network;
3848 DMESG("Enabling beacon TX");
3849 //rtl8192_prepare_beacon(dev);
3850 rtl8192_irq_disable(dev);
3851 //rtl8192_beacon_tx_enable(dev);
3854 write_nic_word(dev, ATIMWND, 2);
3856 /* Beacon interval (in unit of TU) */
3857 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
3860 * DrvErlyInt (in unit of TU).
3861 * (Time to send interrupt to notify driver to c
3862 * hange beacon content)
3864 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
3867 * BcnDMATIM(in unit of us).
3868 * Indicates the time before TBTT to perform beacon queue DMA
3870 write_nic_word(dev, BCN_DMATIME, 256);
3873 * Force beacon frame transmission even after receiving
3874 * beacon frame from other ad hoc STA
3876 write_nic_byte(dev, BCN_ERR_THRESH, 100);
3878 /* Set CW and IFS */
3879 BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT;
3880 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
3881 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
3884 /* enable the interrupt for ad-hoc process */
3885 rtl8192_irq_enable(dev);
3887 /***************************************************************************
3888 -------------------------------NET STUFF---------------------------
3889 ***************************************************************************/
3893 static bool HalTxCheckStuck8190Pci(struct net_device *dev)
3895 u16 RegTxCounter = read_nic_word(dev, 0x128);
3896 struct r8192_priv *priv = ieee80211_priv(dev);
3897 bool bStuck = FALSE;
3898 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
3899 if(priv->TxCounter==RegTxCounter)
3902 priv->TxCounter = RegTxCounter;
3908 * <Assumption: RT_TX_SPINLOCK is acquired.>
3909 * First added: 2006.11.19 by emily
3912 TxCheckStuck(struct net_device *dev)
3914 struct r8192_priv *priv = ieee80211_priv(dev);
3916 ptx_ring head=NULL,tail=NULL,txring = NULL;
3917 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3918 bool bCheckFwTxCnt = false;
3919 //unsigned long flags;
3922 // Decide Stuch threshold according to current power save mode
3924 //printk("++++++++++++>%s()\n",__FUNCTION__);
3925 switch (priv->ieee80211->dot11PowerSaveMode)
3927 // The threshold value may required to be adjusted .
3928 case eActive: // Active/Continuous access.
3929 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
3931 case eMaxPs: // Max power save mode.
3932 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3934 case eFastPs: // Fast power save mode.
3935 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3940 // Check whether specific tcb has been queued for a specific time
3942 for(QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++)
3946 if(QueueID == TXCMD_QUEUE)
3951 tail=priv->txmapringtail;
3952 head=priv->txmapringhead;
3956 tail=priv->txbkpringtail;
3957 head=priv->txbkpringhead;
3961 tail=priv->txbepringtail;
3962 head=priv->txbepringhead;
3966 tail=priv->txvipringtail;
3967 head=priv->txvipringhead;
3971 tail=priv->txvopringtail;
3972 head=priv->txvopringhead;
3987 RT_TRACE(COMP_ERR,"%s():txring is NULL , BUG!\n",__FUNCTION__);
3990 txring->nStuckCount++;
3991 bCheckFwTxCnt = TRUE;
3997 if(HalTxCheckStuck8190Pci(dev))
3999 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
4000 return RESET_TYPE_SILENT;
4004 return RESET_TYPE_NORESET;
4008 static bool HalRxCheckStuck8190Pci(struct net_device *dev)
4010 struct r8192_priv *priv = ieee80211_priv(dev);
4011 u16 RegRxCounter = read_nic_word(dev, 0x130);
4012 bool bStuck = FALSE;
4013 static u8 rx_chk_cnt = 0;
4014 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
4015 // If rssi is small, we should check rx for long time because of bad rx.
4016 // or maybe it will continuous silent reset every 2 seconds.
4018 if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
4020 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
4022 else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
4023 ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
4024 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
4036 else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
4037 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
4038 priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
4042 //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
4048 //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
4055 //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI);
4061 //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI);
4064 if(priv->RxCounter==RegRxCounter)
4067 priv->RxCounter = RegRxCounter;
4072 static RESET_TYPE RxCheckStuck(struct net_device *dev)
4075 if(HalRxCheckStuck8190Pci(dev))
4077 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
4078 return RESET_TYPE_SILENT;
4081 return RESET_TYPE_NORESET;
4085 rtl819x_ifcheck_resetornot(struct net_device *dev)
4087 struct r8192_priv *priv = ieee80211_priv(dev);
4088 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
4089 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
4090 RT_RF_POWER_STATE rfState;
4092 rfState = priv->ieee80211->eRFPowerState;
4094 TxResetType = TxCheckStuck(dev);
4096 if( rfState != eRfOff &&
4097 /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
4098 (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
4100 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
4101 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
4102 // if driver is in firmware download failure status, driver should initialize RF in the following
4103 // silent reset procedure Emily, 2008.01.21
4105 // Driver should not check RX stuck in IBSS mode because it is required to
4106 // set Check BSSID in order to send beacon, however, if check BSSID is
4107 // set, STA cannot hear any packet a all. Emily, 2008.04.12
4108 RxResetType = RxCheckStuck(dev);
4112 RT_TRACE(COMP_RESET,"%s(): TxResetType is %d, RxResetType is %d\n",__FUNCTION__,TxResetType,RxResetType);
4113 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
4114 return RESET_TYPE_NORMAL;
4115 else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT)
4116 return RESET_TYPE_SILENT;
4118 return RESET_TYPE_NORESET;
4123 static void CamRestoreAllEntry(struct net_device *dev)
4126 struct r8192_priv *priv = ieee80211_priv(dev);
4127 u8* MacAddr = priv->ieee80211->current_network.bssid;
4129 static u8 CAM_CONST_ADDR[4][6] = {
4130 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
4131 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
4132 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
4133 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
4134 static u8 CAM_CONST_BROAD[] =
4135 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4137 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
4140 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
4141 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
4144 for(EntryId=0; EntryId<4; EntryId++)
4147 MacAddr = CAM_CONST_ADDR[EntryId];
4151 priv->ieee80211->pairwise_key_type,
4159 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
4163 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4167 priv->ieee80211->pairwise_key_type,
4175 priv->ieee80211->pairwise_key_type,
4181 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
4185 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4189 priv->ieee80211->pairwise_key_type,
4197 priv->ieee80211->pairwise_key_type,
4206 if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
4208 MacAddr = CAM_CONST_BROAD;
4209 for(EntryId=1 ; EntryId<4 ; EntryId++)
4215 priv->ieee80211->group_key_type,
4221 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4225 priv->ieee80211->group_key_type,
4230 else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
4232 MacAddr = CAM_CONST_BROAD;
4233 for(EntryId=1; EntryId<4 ; EntryId++)
4239 priv->ieee80211->group_key_type,
4246 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4250 priv->ieee80211->group_key_type,
4257 void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
4258 int _rtl8192_up(struct net_device *dev);
4261 * This function is used to fix Tx/Rx stop bug temporarily.
4262 * This function will do "system reset" to NIC when Tx or Rx is stuck.
4263 * The method checking Tx/Rx stuck of this function is supported by FW,
4264 * which reports Tx and Rx counter to register 0x128 and 0x130.
4266 static void rtl819x_ifsilentreset(struct net_device *dev)
4268 struct r8192_priv *priv = ieee80211_priv(dev);
4270 int reset_status = 0;
4271 struct ieee80211_device *ieee = priv->ieee80211;
4276 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
4277 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
4279 if(priv->ResetProgress==RESET_TYPE_NORESET)
4283 //LZM for PS-Poll AID issue. 090429
4284 if(priv->ieee80211->state == IEEE80211_LINKED)
4285 LeisurePSLeave(dev);
4288 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
4290 // Set the variable for reset.
4291 priv->ResetProgress = RESET_TYPE_SILENT;
4292 // rtl8192_close(dev);
4294 down(&priv->wx_sem);
4297 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
4302 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
4303 if(!netif_queue_stopped(dev))
4304 netif_stop_queue(dev);
4306 dm_backup_dynamic_mechanism_state(dev);
4308 rtl8192_irq_disable(dev);
4309 rtl8192_cancel_deferred_work(priv);
4311 del_timer_sync(&priv->watch_dog_timer);
4312 ieee->sync_scan_hurryup = 1;
4313 if(ieee->state == IEEE80211_LINKED)
4315 down(&ieee->wx_sem);
4316 printk("ieee->state is IEEE80211_LINKED\n");
4317 ieee80211_stop_send_beacons(priv->ieee80211);
4318 del_timer_sync(&ieee->associate_timer);
4319 cancel_delayed_work(&ieee->associate_retry_wq);
4320 ieee80211_stop_scan(ieee);
4321 netif_carrier_off(dev);
4325 printk("ieee->state is NOT LINKED\n");
4326 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4328 rtl8192_halt_adapter(dev, true);
4330 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
4331 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
4332 reset_status = _rtl8192_up(dev);
4334 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
4335 if(reset_status == -1)
4344 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n",__FUNCTION__);
4348 ieee->is_silent_reset = 1;
4350 EnableHWSecurityConfig8192(dev);
4352 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4354 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4357 queue_work(ieee->wq, &ieee->associate_complete_wq);
4361 else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
4363 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4364 ieee->link_change(ieee->dev);
4366 // notify_wx_assoc_event(ieee);
4368 ieee80211_start_send_beacons(ieee);
4370 if (ieee->data_hard_resume)
4371 ieee->data_hard_resume(ieee->dev);
4372 netif_carrier_on(ieee->dev);
4376 CamRestoreAllEntry(dev);
4378 // Restore the previous setting for all dynamic mechanism
4379 dm_restore_dynamic_mechanism_state(dev);
4381 priv->ResetProgress = RESET_TYPE_NORESET;
4382 priv->reset_count++;
4384 priv->bForcedSilentReset =false;
4385 priv->bResetInProgress = false;
4387 // For test --> force write UFWP.
4388 write_nic_byte(dev, UFWP, 1);
4389 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
4395 void InactivePsWorkItemCallback(struct net_device *dev)
4397 struct r8192_priv *priv = ieee80211_priv(dev);
4398 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4401 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() ---------> \n");
4403 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
4404 // is really scheduled.
4405 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
4406 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
4407 // blocks the IPS procedure of switching RF.
4408 // By Bruce, 2007-12-25.
4410 pPSC->bSwRfProcessing = TRUE;
4412 RT_TRACE(COMP_RF, "InactivePsWorkItemCallback(): Set RF to %s.\n", \
4413 pPSC->eInactivePowerState == eRfOff?"OFF":"ON");
4416 MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
4419 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
4421 pPSC->bSwRfProcessing = FALSE;
4422 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <--------- \n");
4427 // Change current and default preamble mode.
4428 // 2005.01.06, by rcnjko.
4430 bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev, u8 rtPsMode)
4432 struct r8192_priv *priv = ieee80211_priv(dev);
4433 //PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4434 //u8 RpwmVal, FwPwrMode;
4436 // Currently, we do not change power save mode on IBSS mode.
4437 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4443 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
4444 // some AP will not response to our mgnt frames with PwrMgt bit set,
4445 // e.g. cannot associate the AP.
4446 // So I commented out it. 2005.02.16, by rcnjko.
4448 // // Change device's power save mode.
4449 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
4451 // Update power save mode configured.
4452 //RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode);
4453 if(!priv->ps_force) {
4454 priv->ieee80211->ps = rtPsMode;
4457 // Awake immediately
4458 if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED)
4460 unsigned long flags;
4462 //PlatformSetTimer(Adapter, &(pMgntInfo->AwakeTimer), 0);
4463 // Notify the AP we awke.
4464 rtl8192_hw_wakeup(dev);
4465 priv->ieee80211->sta_sleep = 0;
4467 spin_lock_irqsave(&(priv->ieee80211->mgmt_tx_lock), flags);
4468 printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n");
4469 ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0);
4470 spin_unlock_irqrestore(&(priv->ieee80211->mgmt_tx_lock), flags);
4476 //================================================================================
4477 // Leisure Power Save in linked state.
4478 //================================================================================
4482 // Enter the leisure power save mode.
4484 void LeisurePSEnter(struct net_device *dev)
4486 struct r8192_priv *priv = ieee80211_priv(dev);
4487 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4489 //RT_TRACE(COMP_PS, "LeisurePSEnter()...\n");
4490 //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n",
4491 // pPSC->bLeisurePs, priv->ieee80211->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD);
4493 if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) &&
4494 (priv->ieee80211->state == IEEE80211_LINKED)) ||
4495 (priv->ieee80211->iw_mode == IW_MODE_ADHOC) ||
4496 (priv->ieee80211->iw_mode == IW_MODE_MASTER))
4499 if (pPSC->bLeisurePs)
4501 // Idle for a while if we connect to AP a while ago.
4502 if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) // 4 Sec
4505 if(priv->ieee80211->ps == IEEE80211_PS_DISABLED)
4508 //RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n");
4509 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
4514 pPSC->LpsIdleCount++;
4521 // Leave the leisure power save mode.
4523 void LeisurePSLeave(struct net_device *dev)
4525 struct r8192_priv *priv = ieee80211_priv(dev);
4526 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4529 //RT_TRACE(COMP_PS, "LeisurePSLeave()...\n");
4530 //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d\n",
4531 // pPSC->bLeisurePs, priv->ieee80211->ps);
4533 if (pPSC->bLeisurePs)
4535 if(priv->ieee80211->ps != IEEE80211_PS_DISABLED)
4537 // move to lps_wakecomplete()
4538 //RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n");
4539 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_DISABLED);
4549 // Enter the inactive power save mode. RF will be off
4550 // 2007.08.17, by shien chang.
4553 IPSEnter(struct net_device *dev)
4555 struct r8192_priv *priv = ieee80211_priv(dev);
4556 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4557 RT_RF_POWER_STATE rtState;
4559 if (pPSC->bInactivePs)
4561 rtState = priv->ieee80211->eRFPowerState;
4563 // Added by Bruce, 2007-12-25.
4564 // Do not enter IPS in the following conditions:
4565 // (1) RF is already OFF or Sleep
4566 // (2) bSwRfProcessing (indicates the IPS is still under going)
4567 // (3) Connectted (only disconnected can trigger IPS)
4568 // (4) IBSS (send Beacon)
4569 // (5) AP mode (send Beacon)
4571 if (rtState == eRfOn && !pPSC->bSwRfProcessing
4572 && (priv->ieee80211->state != IEEE80211_LINKED) )
4574 RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n");
4575 //printk("IPSEnter(): Turn off RF.\n");
4576 pPSC->eInactivePowerState = eRfOff;
4577 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4578 InactivePsWorkItemCallback(dev);
4585 // Leave the inactive power save mode, RF will be on.
4586 // 2007.08.17, by shien chang.
4589 IPSLeave(struct net_device *dev)
4591 struct r8192_priv *priv = ieee80211_priv(dev);
4592 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4593 RT_RF_POWER_STATE rtState;
4595 if (pPSC->bInactivePs)
4597 rtState = priv->ieee80211->eRFPowerState;
4598 if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->ieee80211->RfOffReason <= RF_CHANGE_BY_IPS)
4600 RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n");
4601 //printk("IPSLeave(): Turn on RF.\n");
4602 pPSC->eInactivePowerState = eRfOn;
4603 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4604 InactivePsWorkItemCallback(dev);
4609 void IPSLeave_wq(void *data)
4611 struct ieee80211_device *ieee = container_of(data,struct ieee80211_device,ips_leave_wq);
4612 struct net_device *dev = ieee->dev;
4614 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4615 down(&priv->ieee80211->ips_sem);
4617 up(&priv->ieee80211->ips_sem);
4620 void ieee80211_ips_leave_wq(struct net_device *dev)
4622 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4623 RT_RF_POWER_STATE rtState;
4624 rtState = priv->ieee80211->eRFPowerState;
4626 if(priv->ieee80211->PowerSaveControl.bInactivePs){
4627 if(rtState == eRfOff){
4628 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
4630 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
4634 printk("=========>%s(): IPSLeave\n",__FUNCTION__);
4635 queue_work(priv->ieee80211->wq,&priv->ieee80211->ips_leave_wq);
4640 //added by amy 090331 end
4641 void ieee80211_ips_leave(struct net_device *dev)
4643 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4644 down(&priv->ieee80211->ips_sem);
4646 up(&priv->ieee80211->ips_sem);
4650 static void rtl819x_update_rxcounts(
4651 struct r8192_priv *priv,
4660 *TotalRxDataNum = 0;
4662 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
4663 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
4664 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
4665 for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
4666 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
4667 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
4672 void rtl819x_watchdog_wqcallback(struct work_struct *work)
4674 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
4675 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
4676 struct net_device *dev = priv->ieee80211->dev;
4677 struct ieee80211_device* ieee = priv->ieee80211;
4678 RESET_TYPE ResetType = RESET_TYPE_NORESET;
4679 static u8 check_reset_cnt=0;
4680 unsigned long flags;
4681 bool bBusyTraffic = false;
4682 static u8 last_time = 0;
4683 bool bEnterPS = false;
4685 if((!priv->up) || (priv->bHwRadioOff == true))
4690 hal_dm_watchdog(dev);
4692 // printk("watch_dog ENABLE_IPS\n");
4693 if(ieee->actscanning == false){
4694 //printk("%d,%d,%d,%d\n", ieee->eRFPowerState, ieee->is_set_key, ieee->proto_stoppping, ieee->wx_set_enc);
4695 if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) &&\
4696 (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key &&\
4697 (!ieee->proto_stoppping) && !ieee->wx_set_enc){
4698 if(ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){
4699 //printk("====================>haha:IPSEnter()\n");
4701 //ieee80211_stop_scan(priv->ieee80211);
4706 {//to get busy traffic condition
4707 if(ieee->state == IEEE80211_LINKED)
4709 if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 ||
4710 ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) {
4711 bBusyTraffic = true;
4715 //added by amy for Leisure PS
4716 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
4717 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
4719 //printk("ieee->LinkDetectInfo.NumRxUnicastOkInPeriod is %d,ieee->LinkDetectInfo.NumTxOkInPeriod is %d\n",
4720 // ieee->LinkDetectInfo.NumRxUnicastOkInPeriod,ieee->LinkDetectInfo.NumTxOkInPeriod);
4728 //printk("***bEnterPS = %d\n", bEnterPS);
4729 // LeisurePS only work in infra mode.
4732 LeisurePSEnter(dev);
4736 LeisurePSLeave(dev);
4744 //RT_TRACE(COMP_LPS,"====>no link LPS leave\n");
4745 LeisurePSLeave(dev);
4749 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
4750 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
4751 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
4752 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
4756 //added by amy for AP roaming
4759 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4761 u32 TotalRxBcnNum = 0;
4762 u32 TotalRxDataNum = 0;
4764 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
4765 if((TotalRxBcnNum+TotalRxDataNum) == 0)
4767 if( ieee->eRFPowerState == eRfOff)
4768 RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
4769 printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
4770 // Dot11d_Reset(dev);
4771 ieee->state = IEEE80211_ASSOCIATING;
4772 notify_wx_assoc_event(priv->ieee80211);
4773 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
4774 ieee->is_roaming = true;
4775 ieee->is_set_key = false;
4776 ieee->link_change(dev);
4777 queue_work(ieee->wq, &ieee->associate_procedure_wq);
4780 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
4781 ieee->LinkDetectInfo.NumRecvDataInPeriod=0;
4784 //check if reset the driver
4785 spin_lock_irqsave(&priv->tx_lock,flags);
4786 if(check_reset_cnt++ >= 3 && !ieee->is_roaming && (last_time != 1))
4788 ResetType = rtl819x_ifcheck_resetornot(dev);
4789 check_reset_cnt = 3;
4790 //DbgPrint("Start to check silent reset\n");
4792 spin_unlock_irqrestore(&priv->tx_lock,flags);
4793 if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL)
4795 priv->ResetProgress = RESET_TYPE_NORMAL;
4796 RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__FUNCTION__);
4799 /* disable silent reset temply 2008.9.11*/
4801 if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo
4804 rtl819x_ifsilentreset(dev);
4809 priv->force_reset = false;
4810 priv->bForcedSilentReset = false;
4811 priv->bResetInProgress = false;
4812 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
4816 void watch_dog_timer_callback(unsigned long data)
4818 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
4819 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0);
4820 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
4823 int _rtl8192_up(struct net_device *dev)
4825 struct r8192_priv *priv = ieee80211_priv(dev);
4827 RT_STATUS init_status = RT_STATUS_SUCCESS;
4829 priv->ieee80211->ieee_up=1;
4830 priv->bdisable_nic = false; //YJ,add,091111
4831 RT_TRACE(COMP_INIT, "Bringing up iface");
4833 init_status = rtl8192_adapter_start(dev);
4834 if(init_status != RT_STATUS_SUCCESS)
4836 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
4839 RT_TRACE(COMP_INIT, "start adapter finished\n");
4841 if(priv->ieee80211->eRFPowerState!=eRfOn)
4842 MgntActSet_RF_State(dev, eRfOn, priv->ieee80211->RfOffReason);
4844 if(priv->ieee80211->state != IEEE80211_LINKED)
4845 ieee80211_softmac_start_protocol(priv->ieee80211);
4846 ieee80211_reset_queue(priv->ieee80211);
4847 watch_dog_timer_callback((unsigned long) dev);
4848 if(!netif_queue_stopped(dev))
4849 netif_start_queue(dev);
4851 netif_wake_queue(dev);
4857 static int rtl8192_open(struct net_device *dev)
4859 struct r8192_priv *priv = ieee80211_priv(dev);
4862 down(&priv->wx_sem);
4863 ret = rtl8192_up(dev);
4870 int rtl8192_up(struct net_device *dev)
4872 struct r8192_priv *priv = ieee80211_priv(dev);
4874 if (priv->up == 1) return -1;
4876 return _rtl8192_up(dev);
4880 static int rtl8192_close(struct net_device *dev)
4882 struct r8192_priv *priv = ieee80211_priv(dev);
4885 down(&priv->wx_sem);
4887 ret = rtl8192_down(dev);
4895 int rtl8192_down(struct net_device *dev)
4897 struct r8192_priv *priv = ieee80211_priv(dev);
4903 if (priv->up == 0) return -1;
4906 //LZM for PS-Poll AID issue. 090429
4907 if(priv->ieee80211->state == IEEE80211_LINKED)
4908 LeisurePSLeave(dev);
4912 priv->ieee80211->ieee_up = 0;
4913 RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
4915 if (!netif_queue_stopped(dev))
4916 netif_stop_queue(dev);
4918 rtl8192_irq_disable(dev);
4920 if(!priv->ieee80211->bSupportRemoteWakeUp) {
4921 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_INIT);
4922 // 2006.11.30. System reset bit
4923 ulRegRead = read_nic_dword(dev, CPU_GEN);
4924 ulRegRead|=CPU_GEN_SYSTEM_RESET;
4925 write_nic_dword(dev, CPU_GEN, ulRegRead);
4927 //2008.06.03 for WOL
4928 write_nic_dword(dev, WFCRC0, 0xffffffff);
4929 write_nic_dword(dev, WFCRC1, 0xffffffff);
4930 write_nic_dword(dev, WFCRC2, 0xffffffff);
4933 ucRegRead = read_nic_byte(dev, GPO);
4935 write_nic_byte(dev, GPO, ucRegRead);
4937 //Write PMR register
4938 write_nic_byte(dev, PMR, 0x5);
4939 //Disable tx, enanble rx
4940 write_nic_byte(dev, MacBlkCtrl, 0xa);
4943 // flush_scheduled_work();
4944 rtl8192_cancel_deferred_work(priv);
4946 del_timer_sync(&priv->watch_dog_timer);
4948 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4950 rtl8192_halt_adapter(dev,false);
4951 memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
4953 RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
4959 void rtl8192_commit(struct net_device *dev)
4961 struct r8192_priv *priv = ieee80211_priv(dev);
4963 if (priv->up == 0) return ;
4966 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4968 rtl8192_irq_disable(dev);
4969 rtl8192_halt_adapter(dev,true);
4973 void rtl8192_restart(struct work_struct *work)
4975 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
4976 struct net_device *dev = priv->ieee80211->dev;
4978 down(&priv->wx_sem);
4980 rtl8192_commit(dev);
4985 static void r8192_set_multicast(struct net_device *dev)
4987 struct r8192_priv *priv = ieee80211_priv(dev);
4990 //down(&priv->wx_sem);
4994 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4996 if (promisc != priv->promisc) {
4998 // rtl8192_commit(dev);
5001 priv->promisc = promisc;
5003 //schedule_work(&priv->reset_wq);
5004 //up(&priv->wx_sem);
5008 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
5010 struct r8192_priv *priv = ieee80211_priv(dev);
5011 struct sockaddr *addr = mac;
5013 down(&priv->wx_sem);
5015 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5017 schedule_work(&priv->reset_wq);
5023 /* based on ipw2200 driver */
5024 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5026 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5027 struct iwreq *wrq = (struct iwreq *)rq;
5029 struct ieee80211_device *ieee = priv->ieee80211;
5031 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
5032 struct iw_point *p = &wrq->u.data;
5033 struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
5035 down(&priv->wx_sem);
5038 if (p->length < sizeof(struct ieee_param) || !p->pointer){
5043 ipw = kmalloc(p->length, GFP_KERNEL);
5048 if (copy_from_user(ipw, p->pointer, p->length)) {
5055 case RTL_IOCTL_WPA_SUPPLICANT:
5056 //parse here for HW security
5057 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
5059 if (ipw->u.crypt.set_tx)
5061 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5062 ieee->pairwise_key_type = KEY_TYPE_CCMP;
5063 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5064 ieee->pairwise_key_type = KEY_TYPE_TKIP;
5065 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5067 if (ipw->u.crypt.key_len == 13)
5068 ieee->pairwise_key_type = KEY_TYPE_WEP104;
5069 else if (ipw->u.crypt.key_len == 5)
5070 ieee->pairwise_key_type = KEY_TYPE_WEP40;
5073 ieee->pairwise_key_type = KEY_TYPE_NA;
5075 if (ieee->pairwise_key_type)
5077 memcpy((u8*)key, ipw->u.crypt.key, 16);
5078 EnableHWSecurityConfig8192(dev);
5079 //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
5081 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5082 if (ieee->auth_mode != 2) //LEAP WEP will never set this.
5083 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5085 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){
5086 write_nic_byte(dev, 0x173, 1); //fix aes bug
5090 else //if (ipw->u.crypt.idx) //group key use idx > 0
5092 memcpy((u8*)key, ipw->u.crypt.key, 16);
5093 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5094 ieee->group_key_type= KEY_TYPE_CCMP;
5095 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5096 ieee->group_key_type = KEY_TYPE_TKIP;
5097 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5099 if (ipw->u.crypt.key_len == 13)
5100 ieee->group_key_type = KEY_TYPE_WEP104;
5101 else if (ipw->u.crypt.key_len == 5)
5102 ieee->group_key_type = KEY_TYPE_WEP40;
5105 ieee->group_key_type = KEY_TYPE_NA;
5107 if (ieee->group_key_type)
5111 ipw->u.crypt.idx, //KeyIndex
5112 ieee->group_key_type, //KeyType
5113 broadcast_addr, //MacAddr
5123 printk("@@ wrq->u pointer = ");
5124 for(i=0;i<wrq->u.data.length;i++){
5125 if(i%10==0) printk("\n");
5126 printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] );
5130 #endif /*JOHN_DEBUG*/
5131 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5146 static u8 HwRateToMRate90(bool bIsHT, u8 rate)
5152 case DESC90_RATE1M: ret_rate = MGN_1M; break;
5153 case DESC90_RATE2M: ret_rate = MGN_2M; break;
5154 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
5155 case DESC90_RATE11M: ret_rate = MGN_11M; break;
5156 case DESC90_RATE6M: ret_rate = MGN_6M; break;
5157 case DESC90_RATE9M: ret_rate = MGN_9M; break;
5158 case DESC90_RATE12M: ret_rate = MGN_12M; break;
5159 case DESC90_RATE18M: ret_rate = MGN_18M; break;
5160 case DESC90_RATE24M: ret_rate = MGN_24M; break;
5161 case DESC90_RATE36M: ret_rate = MGN_36M; break;
5162 case DESC90_RATE48M: ret_rate = MGN_48M; break;
5163 case DESC90_RATE54M: ret_rate = MGN_54M; break;
5166 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
5172 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
5173 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
5174 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
5175 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
5176 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
5177 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
5178 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
5179 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
5180 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
5181 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
5182 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
5183 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
5184 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
5185 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
5186 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
5187 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
5188 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
5191 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
5200 * Function: UpdateRxPktTimeStamp
5201 * Overview: Recored down the TSF time stamp when receiving a packet
5209 * (pRfd->Status.TimeStampHigh is updated)
5210 * (pRfd->Status.TimeStampLow is updated)
5214 static void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
5216 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5218 if(stats->bIsAMPDU && !stats->bFirstMPDU) {
5219 stats->mac_time[0] = priv->LastRxDescTSFLow;
5220 stats->mac_time[1] = priv->LastRxDescTSFHigh;
5222 priv->LastRxDescTSFLow = stats->mac_time[0];
5223 priv->LastRxDescTSFHigh = stats->mac_time[1];
5227 static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
5229 long signal_power; // in dBm.
5231 // Translate to dBm (x=0.5y-95).
5232 signal_power = (long)((signal_strength_index + 1) >> 1);
5235 return signal_power;
5240 // Update Rx signal related information in the packet reeived
5241 // to RxStats. User application can query RxStats to realize
5242 // current Rx signal status.
5245 // In normal operation, user only care about the information of the BSS
5246 // and we shall invoke this function if the packet received is from the BSS.
5249 rtl819x_update_rxsignalstatistics8190pci(
5250 struct r8192_priv * priv,
5251 struct ieee80211_rx_stats * pprevious_stats
5256 //2 <ToDo> Update Rx Statistics (such as signal strength and signal quality).
5259 if(priv->stats.recv_signal_power == 0)
5260 priv->stats.recv_signal_power = pprevious_stats->RecvSignalPower;
5262 // To avoid the past result restricting the statistics sensitivity, weight the current power (5/6) to speed up the
5263 // reaction of smoothed Signal Power.
5264 if(pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power)
5266 else if(pprevious_stats->RecvSignalPower < priv->stats.recv_signal_power)
5269 // We need more correct power of received packets and the "SignalStrength" of RxStats have been beautified or translated,
5270 // so we record the correct power in Dbm here. By Bruce, 2008-03-07.
5272 priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 + pprevious_stats->RecvSignalPower + weighting) / 6;
5276 rtl8190_process_cck_rxpathsel(
5277 struct r8192_priv * priv,
5278 struct ieee80211_rx_stats * pprevious_stats
5281 #ifdef RTL8190P //Only 90P 2T4R need to check
5282 char last_cck_adc_pwdb[4]={0,0,0,0};
5284 //cosa add for Rx path selection
5285 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable)
5287 if(pprevious_stats->bIsCCK &&
5288 (pprevious_stats->bPacketToSelf ||pprevious_stats->bPacketBeacon))
5290 /* record the cck adc_pwdb to the sliding window. */
5291 if(priv->stats.cck_adc_pwdb.TotalNum++ >= PHY_RSSI_SLID_WIN_MAX)
5293 priv->stats.cck_adc_pwdb.TotalNum = PHY_RSSI_SLID_WIN_MAX;
5294 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5296 last_cck_adc_pwdb[i] = priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index];
5297 priv->stats.cck_adc_pwdb.TotalVal[i] -= last_cck_adc_pwdb[i];
5300 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5302 priv->stats.cck_adc_pwdb.TotalVal[i] += pprevious_stats->cck_adc_pwdb[i];
5303 priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index] = pprevious_stats->cck_adc_pwdb[i];
5305 priv->stats.cck_adc_pwdb.index++;
5306 if(priv->stats.cck_adc_pwdb.index >= PHY_RSSI_SLID_WIN_MAX)
5307 priv->stats.cck_adc_pwdb.index = 0;
5309 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5311 DM_RxPathSelTable.cck_pwdb_sta[i] = priv->stats.cck_adc_pwdb.TotalVal[i]/priv->stats.cck_adc_pwdb.TotalNum;
5314 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5316 if(pprevious_stats->cck_adc_pwdb[i] > (char)priv->undecorated_smoothed_cck_adc_pwdb[i])
5318 priv->undecorated_smoothed_cck_adc_pwdb[i] =
5319 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
5320 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
5321 priv->undecorated_smoothed_cck_adc_pwdb[i] = priv->undecorated_smoothed_cck_adc_pwdb[i] + 1;
5325 priv->undecorated_smoothed_cck_adc_pwdb[i] =
5326 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
5327 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
5336 /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to
5337 be a local static. Otherwise, it may increase when we return from S3/S4. The
5338 value will be kept in memory or disk. We must delcare the value in adapter
5339 and it will be reinitialized when return from S3/S4. */
5340 static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
5342 bool bcheck = false;
5344 u32 nspatial_stream, tmp_val;
5346 static u32 slide_rssi_index=0, slide_rssi_statistics=0;
5347 static u32 slide_evm_index=0, slide_evm_statistics=0;
5348 static u32 last_rssi=0, last_evm=0;
5349 //cosa add for rx path selection
5350 // static long slide_cck_adc_pwdb_index=0, slide_cck_adc_pwdb_statistics=0;
5351 // static char last_cck_adc_pwdb[4]={0,0,0,0};
5352 //cosa add for beacon rssi smoothing
5353 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
5354 static u32 last_beacon_adc_pwdb=0;
5356 struct ieee80211_hdr_3addr *hdr;
5358 unsigned int frag,seq;
5359 hdr = (struct ieee80211_hdr_3addr *)buffer;
5360 sc = le16_to_cpu(hdr->seq_ctl);
5361 frag = WLAN_GET_SEQ_FRAG(sc);
5362 seq = WLAN_GET_SEQ_SEQ(sc);
5363 //cosa add 04292008 to record the sequence number
5364 pcurrent_stats->Seq_Num = seq;
5366 // Check whether we should take the previous packet into accounting
5368 if(!pprevious_stats->bIsAMPDU)
5370 // if previous packet is not aggregated packet
5374 //remve for that we don't use AMPDU to calculate PWDB,because the reported PWDB of some AP is fault.
5376 // if previous packet is aggregated packet, and current packet
5378 // (2) is the first packet of one AMPDU
5379 // that means the previous packet is the last one aggregated packet
5380 if( !pcurrent_stats->bIsAMPDU || pcurrent_stats->bFirstMPDU)
5385 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
5387 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
5388 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
5389 priv->stats.slide_rssi_total -= last_rssi;
5391 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
5393 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
5394 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
5395 slide_rssi_index = 0;
5397 // <1> Showed on UI for user, in dbm
5398 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
5399 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
5400 pcurrent_stats->rssi = priv->stats.signal_strength;
5402 // If the previous packet does not match the criteria, neglect it
5404 if(!pprevious_stats->bPacketMatchBSSID)
5406 if(!pprevious_stats->bToSelfBA)
5413 rtl8190_process_cck_rxpathsel(priv,pprevious_stats);
5418 priv->stats.num_process_phyinfo++;
5420 /* record the general signal strength to the sliding window. */
5421 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
5423 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
5424 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
5425 priv->stats.slide_rssi_total -= last_rssi;
5427 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
5429 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
5430 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
5431 slide_rssi_index = 0;
5433 // <1> Showed on UI for user, in dbm
5434 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
5435 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
5438 // <2> Showed on UI for engineering
5439 // hardware does not provide rssi information for each rf path in CCK
5440 if(!pprevious_stats->bIsCCK && pprevious_stats->bPacketToSelf)
5442 for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++)
5444 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
5446 RT_TRACE(COMP_DBG,"Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d \n" ,pprevious_stats->RxMIMOSignalStrength[rfpath] );
5447 //Fixed by Jacken 2008-03-20
5448 if(priv->stats.rx_rssi_percentage[rfpath] == 0)
5450 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
5451 //DbgPrint("MIMO RSSI initialize \n");
5453 if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath])
5455 priv->stats.rx_rssi_percentage[rfpath] =
5456 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5457 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5458 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
5462 priv->stats.rx_rssi_percentage[rfpath] =
5463 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5464 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5466 RT_TRACE(COMP_DBG,"Jacken -> priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
5474 //cosa add for beacon rssi smoothing by average.
5475 if(pprevious_stats->bPacketBeacon)
5477 /* record the beacon pwdb to the sliding window. */
5478 if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5480 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
5481 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
5482 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
5483 //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n",
5484 // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
5486 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
5487 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
5488 //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll);
5489 slide_beacon_adc_pwdb_index++;
5490 if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5491 slide_beacon_adc_pwdb_index = 0;
5492 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
5493 if(pprevious_stats->RxPWDBAll >= 3)
5494 pprevious_stats->RxPWDBAll -= 3;
5497 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
5498 pprevious_stats->bIsCCK? "CCK": "OFDM",
5499 pprevious_stats->RxPWDBAll);
5501 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5503 if(priv->undecorated_smoothed_pwdb < 0) // initialize
5505 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
5506 //DbgPrint("First pwdb initialize \n");
5509 if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
5511 priv->undecorated_smoothed_pwdb =
5512 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5513 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5514 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
5518 priv->undecorated_smoothed_pwdb =
5519 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5520 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5523 //Fixed by Jacken 2008-03-20
5524 if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB)
5526 pHalData->UndecoratedSmoothedPWDB =
5527 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5528 pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1;
5532 pHalData->UndecoratedSmoothedPWDB =
5533 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5536 rtl819x_update_rxsignalstatistics8190pci(priv,pprevious_stats);
5542 /* record the general EVM to the sliding window. */
5543 if(pprevious_stats->SignalQuality == 0)
5548 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
5549 if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
5550 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
5551 last_evm = priv->stats.slide_evm[slide_evm_index];
5552 priv->stats.slide_evm_total -= last_evm;
5555 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
5557 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
5558 if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
5559 slide_evm_index = 0;
5561 // <1> Showed on UI for user, in percentage.
5562 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
5563 priv->stats.signal_quality = tmp_val;
5564 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
5565 priv->stats.last_signal_strength_inpercent = tmp_val;
5568 // <2> Showed on UI for engineering
5569 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5571 for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
5573 if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
5575 if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
5577 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
5579 priv->stats.rx_evm_percentage[nspatial_stream] =
5580 ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
5581 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
5589 /*-----------------------------------------------------------------------------
5590 * Function: rtl819x_query_rxpwrpercentage()
5594 * Input: char antpower
5598 * Return: 0-100 percentage
5602 * 05/26/2008 amy Create Version 0 porting from windows code.
5604 *---------------------------------------------------------------------------*/
5605 static u8 rtl819x_query_rxpwrpercentage(
5609 if ((antpower <= -100) || (antpower >= 20))
5613 else if (antpower >= 0)
5619 return (100+antpower);
5622 } /* QueryRxPwrPercentage */
5625 rtl819x_evm_dbtopercentage(
5637 ret_val = 0 - ret_val;
5646 // We want good-looking for signal strength/quality
5647 // 2007/7/19 01:09, by cosa.
5649 static long rtl819x_signal_scale_mapping(long currsig)
5653 // Step 1. Scale mapping.
5654 if(currsig >= 61 && currsig <= 100)
5656 retsig = 90 + ((currsig - 60) / 4);
5658 else if(currsig >= 41 && currsig <= 60)
5660 retsig = 78 + ((currsig - 40) / 2);
5662 else if(currsig >= 31 && currsig <= 40)
5664 retsig = 66 + (currsig - 30);
5666 else if(currsig >= 21 && currsig <= 30)
5668 retsig = 54 + (currsig - 20);
5670 else if(currsig >= 5 && currsig <= 20)
5672 retsig = 42 + (((currsig - 5) * 2) / 3);
5674 else if(currsig == 4)
5678 else if(currsig == 3)
5682 else if(currsig == 2)
5686 else if(currsig == 1)
5698 static void rtl8192_query_rxphystatus(
5699 struct r8192_priv * priv,
5700 struct ieee80211_rx_stats * pstats,
5701 prx_desc_819x_pci pdesc,
5702 prx_fwinfo_819x_pci pdrvinfo,
5703 struct ieee80211_rx_stats * precord_stats,
5704 bool bpacket_match_bssid,
5705 bool bpacket_toself,
5710 //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status);
5711 phy_sts_ofdm_819xpci_t* pofdm_buf;
5712 phy_sts_cck_819xpci_t * pcck_buf;
5713 phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
5715 u8 i,max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
5716 char rx_pwr[4], rx_pwr_all=0;
5717 //long rx_avg_pwr = 0;
5718 char rx_snrX, rx_evmX;
5720 u32 RSSI, total_rssi=0;//, total_evm=0;
5721 // long signal_strength_index = 0;
5725 /* 2007/07/04 MH For OFDM RSSI. For high power or not. */
5726 static u8 check_reg824 = 0;
5727 static u32 reg824_bit9 = 0;
5729 priv->stats.numqry_phystatus++;
5731 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
5733 // Record it for next packet processing
5734 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
5735 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
5736 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
5737 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
5738 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
5739 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
5740 /*2007.08.30 requested by SD3 Jerry */
5741 if(check_reg824 == 0)
5743 reg824_bit9 = rtl8192_QueryBBReg(priv->ieee80211->dev, rFPGA0_XA_HSSIParameter2, 0x200);
5748 prxpkt = (u8*)pdrvinfo;
5750 /* Move pointer to the 16th bytes. Phy status start address. */
5751 prxpkt += sizeof(rx_fwinfo_819x_pci);
5753 /* Initial the cck and ofdm buffer pointer */
5754 pcck_buf = (phy_sts_cck_819xpci_t *)prxpkt;
5755 pofdm_buf = (phy_sts_ofdm_819xpci_t *)prxpkt;
5757 pstats->RxMIMOSignalQuality[0] = -1;
5758 pstats->RxMIMOSignalQuality[1] = -1;
5759 precord_stats->RxMIMOSignalQuality[0] = -1;
5760 precord_stats->RxMIMOSignalQuality[1] = -1;
5765 // (1)Hardware does not provide RSSI for CCK
5769 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5771 u8 report;//, cck_agc_rpt;
5774 char cck_adc_pwdb[4];
5776 priv->stats.numqry_phystatusCCK++;
5778 #ifdef RTL8190P //Only 90P 2T4R need to check
5779 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable && bpacket_match_bssid)
5781 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5783 tmp_pwdb = pcck_buf->adc_pwdb_X[i];
5784 cck_adc_pwdb[i] = (char)tmp_pwdb;
5785 cck_adc_pwdb[i] /= 2;
5786 pstats->cck_adc_pwdb[i] = precord_stats->cck_adc_pwdb[i] = cck_adc_pwdb[i];
5787 //DbgPrint("RF-%d tmp_pwdb = 0x%x, cck_adc_pwdb = %d", i, tmp_pwdb, cck_adc_pwdb[i]);
5794 report = pcck_buf->cck_agc_rpt & 0xc0;
5798 //Fixed by Jacken from Bryant 2008-03-20
5799 //Original value is -38 , -26 , -14 , -2
5800 //Fixed value is -35 , -23 , -11 , 6
5802 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
5805 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
5808 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
5811 rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e);
5817 report = pcck_buf->cck_agc_rpt & 0x60;
5822 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5825 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
5828 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5831 rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5836 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5837 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5838 pstats->RecvSignalPower = rx_pwr_all;
5841 // (3) Get Signal Quality (EVM)
5843 if(bpacket_match_bssid)
5847 if(pstats->RxPWDBAll > 40)
5852 sq = pcck_buf->sq_rpt;
5854 if(pcck_buf->sq_rpt > 64)
5856 else if (pcck_buf->sq_rpt < 20)
5859 sq = ((64-sq) * 100) / 44;
5861 pstats->SignalQuality = precord_stats->SignalQuality = sq;
5862 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
5863 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
5868 priv->stats.numqry_phystatusHT++;
5870 // (1)Get RSSI for HT rate
5872 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5874 // 2008/01/30 MH we will judge RF RX path now.
5875 if (priv->brfpath_rxenable[i])
5880 //Fixed by Jacken from Bryant 2008-03-20
5881 //Original value is 106
5882 #ifdef RTL8190P //Modify by Jacken 2008/03/31
5883 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
5885 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 110;
5888 //Get Rx snr value in DB
5889 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
5890 rx_snrX = (char)(tmp_rxsnr);
5892 priv->stats.rxSNRdB[i] = (long)rx_snrX;
5894 /* Translate DBM to percentage. */
5895 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
5896 if (priv->brfpath_rxenable[i])
5899 /* Record Signal Strength for next packet */
5900 if(bpacket_match_bssid)
5902 pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
5903 precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
5909 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5911 //Fixed by Jacken from Bryant 2008-03-20
5912 //Original value is 106
5913 rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
5914 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5916 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5917 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
5918 pstats->RecvSignalPower = rx_pwr_all;
5920 // (3)EVM of HT rate
5922 if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
5923 pdrvinfo->RxRate<=DESC90_RATEMCS15)
5924 max_spatial_stream = 2; //both spatial stream make sense
5926 max_spatial_stream = 1; //only spatial stream 1 makes sense
5928 for(i=0; i<max_spatial_stream; i++)
5930 tmp_rxevm = pofdm_buf->rxevm_X[i];
5931 rx_evmX = (char)(tmp_rxevm);
5933 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
5934 // fill most significant bit to "zero" when doing shifting operation which may change a negative
5935 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
5938 evm = rtl819x_evm_dbtopercentage(rx_evmX);
5940 EVM = SignalScaleMapping(EVM);//make it good looking, from 0~100
5942 if(bpacket_match_bssid)
5944 if(i==0) // Fill value in RFD, Get the first spatial stream only
5945 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
5946 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
5951 /* record rx statistics for debug */
5952 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
5953 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
5954 if(pdrvinfo->BW) //40M channel
5955 priv->stats.received_bwtype[1+prxsc->rxsc]++;
5957 priv->stats.received_bwtype[0]++;
5960 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
5961 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
5964 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;
5969 //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u1Byte)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u1Byte)(total_rssi/=RF90_PATH_MAX);
5970 // We can judge RX path number now.
5972 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
5974 } /* QueryRxPhyStatus8190Pci */
5977 rtl8192_record_rxdesc_forlateruse(
5978 struct ieee80211_rx_stats * psrc_stats,
5979 struct ieee80211_rx_stats * ptarget_stats
5982 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
5983 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
5984 //ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
5989 static void TranslateRxSignalStuff819xpci(struct net_device *dev,
5990 struct sk_buff *skb,
5991 struct ieee80211_rx_stats * pstats,
5992 prx_desc_819x_pci pdesc,
5993 prx_fwinfo_819x_pci pdrvinfo)
5995 // TODO: We must only check packet for current MAC address. Not finish
5996 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5997 bool bpacket_match_bssid, bpacket_toself;
5998 bool bPacketBeacon=false, bToSelfBA=false;
5999 static struct ieee80211_rx_stats previous_stats;
6000 struct ieee80211_hdr_3addr *hdr;
6003 // Get Signal Quality for only RX data queue (but not command queue)
6008 /* Get MAC frame start address. */
6009 tmp_buf = skb->data;
6011 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
6012 fc = le16_to_cpu(hdr->frame_ctl);
6013 type = WLAN_FC_GET_TYPE(fc);
6014 praddr = hdr->addr1;
6016 /* Check if the received packet is acceptabe. */
6017 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
6018 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
6019 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
6020 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
6022 if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
6024 bPacketBeacon = true;
6025 //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6027 if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
6029 if((eqMacAddr(praddr,dev->dev_addr)))
6031 //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6035 if(bpacket_match_bssid)
6037 priv->stats.numpacket_matchbssid++;
6040 priv->stats.numpacket_toself++;
6043 // Process PHY information for previous packet (RSSI/PWDB/EVM)
6045 // Because phy information is contained in the last packet of AMPDU only, so driver
6046 // should process phy information of previous packet
6047 rtl8192_process_phyinfo(priv, tmp_buf,&previous_stats, pstats);
6048 rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, &previous_stats, bpacket_match_bssid,
6049 bpacket_toself ,bPacketBeacon, bToSelfBA);
6050 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
6055 static void rtl8192_tx_resume(struct net_device *dev)
6057 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6058 struct ieee80211_device *ieee = priv->ieee80211;
6059 struct sk_buff *skb;
6062 for(queue_index = BK_QUEUE; queue_index < TXCMD_QUEUE;queue_index++) {
6063 while((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&&
6064 (priv->ieee80211->check_nic_enough_desc(dev,queue_index) > 0)) {
6065 /* 1. dequeue the packet from the wait queue */
6066 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
6067 /* 2. tx the packet directly */
6068 ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/);
6070 if(queue_index!=MGNT_QUEUE) {
6071 ieee->stats.tx_packets++;
6072 ieee->stats.tx_bytes += skb->len;
6079 void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
6081 rtl8192_tx_resume(priv->ieee80211->dev);
6085 * Function: UpdateReceivedRateHistogramStatistics
6086 * Overview: Recored down the received data rate
6094 * (Adapter->RxStats.ReceivedRateHistogram[] is updated)
6098 static void UpdateReceivedRateHistogramStatistics8190(
6099 struct net_device *dev,
6100 struct ieee80211_rx_stats* pstats
6103 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6104 u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV
6106 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
6108 /* 2007/03/09 MH We will not update rate of packet from rx cmd queue. */
6110 if (pRfd->queue_id == CMPK_RX_QUEUE_ID)
6115 else if(pstats->bICV)
6118 if(pstats->bShortPreamble)
6119 preamble_guardinterval = 1;// short
6121 preamble_guardinterval = 0;// long
6123 switch(pstats->rate)
6128 case MGN_1M: rateIndex = 0; break;
6129 case MGN_2M: rateIndex = 1; break;
6130 case MGN_5_5M: rateIndex = 2; break;
6131 case MGN_11M: rateIndex = 3; break;
6135 case MGN_6M: rateIndex = 4; break;
6136 case MGN_9M: rateIndex = 5; break;
6137 case MGN_12M: rateIndex = 6; break;
6138 case MGN_18M: rateIndex = 7; break;
6139 case MGN_24M: rateIndex = 8; break;
6140 case MGN_36M: rateIndex = 9; break;
6141 case MGN_48M: rateIndex = 10; break;
6142 case MGN_54M: rateIndex = 11; break;
6144 // 11n High throughput rate
6146 case MGN_MCS0: rateIndex = 12; break;
6147 case MGN_MCS1: rateIndex = 13; break;
6148 case MGN_MCS2: rateIndex = 14; break;
6149 case MGN_MCS3: rateIndex = 15; break;
6150 case MGN_MCS4: rateIndex = 16; break;
6151 case MGN_MCS5: rateIndex = 17; break;
6152 case MGN_MCS6: rateIndex = 18; break;
6153 case MGN_MCS7: rateIndex = 19; break;
6154 case MGN_MCS8: rateIndex = 20; break;
6155 case MGN_MCS9: rateIndex = 21; break;
6156 case MGN_MCS10: rateIndex = 22; break;
6157 case MGN_MCS11: rateIndex = 23; break;
6158 case MGN_MCS12: rateIndex = 24; break;
6159 case MGN_MCS13: rateIndex = 25; break;
6160 case MGN_MCS14: rateIndex = 26; break;
6161 case MGN_MCS15: rateIndex = 27; break;
6162 default: rateIndex = 28; break;
6164 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
6165 priv->stats.received_rate_histogram[0][rateIndex]++; //total
6166 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
6169 static void rtl8192_rx(struct net_device *dev)
6171 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6172 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
6173 bool unicast_packet = false;
6174 struct ieee80211_rx_stats stats = {
6178 .freq = IEEE80211_24GHZ_BAND,
6180 unsigned int count = priv->rxringcount;
6182 stats.nic_type = NIC_8192E;
6185 rx_desc_819x_pci *pdesc = &priv->rx_ring[priv->rx_idx];//rx descriptor
6186 struct sk_buff *skb = priv->rx_buf[priv->rx_idx];//rx pkt
6189 /* wait data to be filled by hardware */
6192 stats.bICV = pdesc->ICV;
6193 stats.bCRC = pdesc->CRC32;
6194 stats.bHwError = pdesc->CRC32 | pdesc->ICV;
6196 stats.Length = pdesc->Length;
6197 if(stats.Length < 24)
6198 stats.bHwError |= 1;
6200 if(stats.bHwError) {
6201 stats.bShift = false;
6204 if (pdesc->Length <500)
6205 priv->stats.rxcrcerrmin++;
6206 else if (pdesc->Length >1000)
6207 priv->stats.rxcrcerrmax++;
6209 priv->stats.rxcrcerrmid++;
6213 prx_fwinfo_819x_pci pDrvInfo = NULL;
6214 struct sk_buff *new_skb = dev_alloc_skb(priv->rxbuffersize);
6216 if (unlikely(!new_skb)) {
6220 stats.RxDrvInfoSize = pdesc->RxDrvInfoSize;
6221 stats.RxBufShift = ((pdesc->Shift)&0x03);
6222 stats.Decrypted = !pdesc->SWDec;
6224 pci_dma_sync_single_for_cpu(priv->pdev,
6225 *((dma_addr_t *)skb->cb),
6227 PCI_DMA_FROMDEVICE);
6228 skb_put(skb, pdesc->Length);
6229 pDrvInfo = (rx_fwinfo_819x_pci *)(skb->data + stats.RxBufShift);
6230 skb_reserve(skb, stats.RxDrvInfoSize + stats.RxBufShift);
6232 stats.rate = HwRateToMRate90((bool)pDrvInfo->RxHT, (u8)pDrvInfo->RxRate);
6233 stats.bShortPreamble = pDrvInfo->SPLCP;
6235 /* it is debug only. It should be disabled in released driver.
6236 * 2007.1.11 by Emily
6238 UpdateReceivedRateHistogramStatistics8190(dev, &stats);
6240 stats.bIsAMPDU = (pDrvInfo->PartAggr==1);
6241 stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1);
6243 stats.TimeStampLow = pDrvInfo->TSFL;
6244 stats.TimeStampHigh = read_nic_dword(dev, TSFR+4);
6246 UpdateRxPktTimeStamp8190(dev, &stats);
6249 // Get Total offset of MPDU Frame Body
6251 if((stats.RxBufShift + stats.RxDrvInfoSize) > 0)
6254 stats.RxIs40MHzPacket = pDrvInfo->BW;
6257 TranslateRxSignalStuff819xpci(dev,skb, &stats, pdesc, pDrvInfo);
6260 if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1)
6261 RT_TRACE(COMP_RXDESC, "pDrvInfo->FirstAGGR = %d, pDrvInfo->PartAggr = %d\n",
6262 pDrvInfo->FirstAGGR, pDrvInfo->PartAggr);
6263 skb_trim(skb, skb->len - 4/*sCrcLng*/);
6264 /* rx packets statistics */
6265 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
6266 unicast_packet = false;
6268 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
6270 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
6273 /* unicast packet */
6274 unicast_packet = true;
6277 stats.packetlength = stats.Length-4;
6278 stats.fraglength = stats.packetlength;
6279 stats.fragoffset = 0;
6280 stats.ntotalfrag = 1;
6282 if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){
6283 dev_kfree_skb_any(skb);
6286 if(unicast_packet) {
6287 priv->stats.rxbytesunicast += skb->len;
6292 priv->rx_buf[priv->rx_idx] = skb;
6293 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE);
6298 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
6300 pdesc->Length = priv->rxbuffersize;
6301 if (priv->rx_idx == priv->rxringcount-1)
6303 priv->rx_idx = (priv->rx_idx + 1) % priv->rxringcount;
6308 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
6310 rtl8192_rx(priv->ieee80211->dev);
6312 write_nic_dword(priv->ieee80211->dev, INTA_MASK,read_nic_dword(priv->ieee80211->dev, INTA_MASK) | IMR_RDU);
6315 static const struct net_device_ops rtl8192_netdev_ops = {
6316 .ndo_open = rtl8192_open,
6317 .ndo_stop = rtl8192_close,
6318 /* .ndo_get_stats = rtl8192_stats, */
6319 .ndo_tx_timeout = tx_timeout,
6320 .ndo_do_ioctl = rtl8192_ioctl,
6321 .ndo_set_multicast_list = r8192_set_multicast,
6322 .ndo_set_mac_address = r8192_set_mac_adr,
6323 .ndo_start_xmit = ieee80211_rtl_xmit,
6326 /****************************************************************************
6327 ---------------------------- PCI_STUFF---------------------------
6328 *****************************************************************************/
6330 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
6331 const struct pci_device_id *id)
6333 unsigned long ioaddr = 0;
6334 struct net_device *dev = NULL;
6335 struct r8192_priv *priv= NULL;
6338 #ifdef CONFIG_RTL8192_IO_MAP
6339 unsigned long pio_start, pio_len, pio_flags;
6341 unsigned long pmem_start, pmem_len, pmem_flags;
6342 #endif //end #ifdef RTL_IO_MAP
6344 RT_TRACE(COMP_INIT,"Configuring chip resources");
6346 if( pci_enable_device (pdev) ){
6347 RT_TRACE(COMP_ERR,"Failed to enable PCI device");
6351 pci_set_master(pdev);
6352 //pci_set_wmi(pdev);
6353 pci_set_dma_mask(pdev, 0xffffff00ULL);
6354 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
6355 dev = alloc_ieee80211(sizeof(struct r8192_priv));
6359 pci_set_drvdata(pdev, dev);
6360 SET_NETDEV_DEV(dev, &pdev->dev);
6361 priv = ieee80211_priv(dev);
6362 priv->ieee80211 = netdev_priv(dev);
6364 if((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304)){
6365 priv->ieee80211->bSupportRemoteWakeUp = 1;
6368 priv->ieee80211->bSupportRemoteWakeUp = 0;
6371 #ifdef CONFIG_RTL8192_IO_MAP
6373 pio_start = (unsigned long)pci_resource_start (pdev, 0);
6374 pio_len = (unsigned long)pci_resource_len (pdev, 0);
6375 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
6377 if (!(pio_flags & IORESOURCE_IO)) {
6378 RT_TRACE(COMP_ERR,"region #0 not a PIO resource, aborting");
6382 //DMESG("IO space @ 0x%08lx", pio_start );
6383 if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){
6384 RT_TRACE(COMP_ERR,"request_region failed!");
6389 dev->base_addr = ioaddr; // device I/O address
6393 pmem_start = pci_resource_start(pdev, 1);
6394 pmem_len = pci_resource_len(pdev, 1);
6395 pmem_flags = pci_resource_flags (pdev, 1);
6397 if (!(pmem_flags & IORESOURCE_MEM)) {
6398 RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting");
6402 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
6403 if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) {
6404 RT_TRACE(COMP_ERR,"request_mem_region failed!");
6409 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
6410 if( ioaddr == (unsigned long)NULL ){
6411 RT_TRACE(COMP_ERR,"ioremap failed!");
6412 // release_mem_region( pmem_start, pmem_len );
6416 dev->mem_start = ioaddr; // shared mem start
6417 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
6419 #endif //end #ifdef RTL_IO_MAP
6421 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6422 * PCI Tx retries from interfering with C3 CPU state */
6423 pci_write_config_byte(pdev, 0x41, 0x00);
6426 pci_read_config_byte(pdev, 0x05, &unit);
6427 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
6429 dev->irq = pdev->irq;
6432 dev->netdev_ops = &rtl8192_netdev_ops;
6434 dev->open = rtl8192_open;
6435 dev->stop = rtl8192_close;
6436 //dev->hard_start_xmit = rtl8192_8023_hard_start_xmit;
6437 dev->tx_timeout = tx_timeout;
6438 //dev->wireless_handlers = &r8192_wx_handlers_def;
6439 dev->do_ioctl = rtl8192_ioctl;
6440 dev->set_multicast_list = r8192_set_multicast;
6441 dev->set_mac_address = r8192_set_mac_adr;
6444 //DMESG("Oops: i'm coming\n");
6445 #if WIRELESS_EXT >= 12
6446 #if WIRELESS_EXT < 17
6447 dev->get_wireless_stats = r8192_get_wireless_stats;
6449 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
6451 //dev->get_wireless_stats = r8192_get_wireless_stats;
6452 dev->type=ARPHRD_ETHER;
6454 dev->watchdog_timeo = HZ*3; //modified by john, 0805
6456 if (dev_alloc_name(dev, ifname) < 0){
6457 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
6459 dev_alloc_name(dev, ifname);
6462 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
6463 if(rtl8192_init(dev)!=0){
6464 RT_TRACE(COMP_ERR, "Initialization failed");
6468 netif_carrier_off(dev);
6469 netif_stop_queue(dev);
6471 register_netdev(dev);
6472 RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
6473 rtl8192_proc_init_one(dev);
6476 RT_TRACE(COMP_INIT, "Driver probe completed\n");
6481 #ifdef CONFIG_RTL8180_IO_MAP
6483 if( dev->base_addr != 0 ){
6485 release_region(dev->base_addr,
6486 pci_resource_len(pdev, 0) );
6489 if( dev->mem_start != (unsigned long)NULL ){
6490 iounmap( (void *)dev->mem_start );
6491 release_mem_region( pci_resource_start(pdev, 1),
6492 pci_resource_len(pdev, 1) );
6494 #endif //end #ifdef RTL_IO_MAP
6500 free_irq(dev->irq, dev);
6503 free_ieee80211(dev);
6506 pci_disable_device(pdev);
6508 DMESG("wlan driver load failed\n");
6509 pci_set_drvdata(pdev, NULL);
6514 /* detach all the work and timer structure declared or inititialized
6515 * in r8192_init function.
6517 void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
6519 /* call cancel_work_sync instead of cancel_delayed_work if and only if Linux_version_code
6520 * is or is newer than 2.6.20 and work structure is defined to be struct work_struct.
6521 * Otherwise call cancel_delayed_work is enough.
6522 * FIXME (2.6.20 should 2.6.22, work_struct should not cancel)
6524 cancel_delayed_work(&priv->watch_dog_wq);
6525 cancel_delayed_work(&priv->update_beacon_wq);
6526 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
6527 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
6529 cancel_delayed_work(&priv->gpio_change_rf_wq);
6531 cancel_work_sync(&priv->reset_wq);
6532 cancel_work_sync(&priv->qos_activate);
6533 //cancel_work_sync(&priv->SetBWModeWorkItem);
6534 //cancel_work_sync(&priv->SwChnlWorkItem);
6539 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
6541 struct net_device *dev = pci_get_drvdata(pdev);
6542 struct r8192_priv *priv ;
6546 unregister_netdev(dev);
6548 priv=ieee80211_priv(dev);
6550 rtl8192_proc_remove_one(dev);
6553 if (priv->pFirmware)
6555 vfree(priv->pFirmware);
6556 priv->pFirmware = NULL;
6558 // priv->rf_close(dev);
6559 // rtl8192_usb_deleteendpoints(dev);
6560 destroy_workqueue(priv->priv_wq);
6561 /* redundant with rtl8192_down */
6562 // rtl8192_irq_disable(dev);
6563 // rtl8192_reset(dev);
6567 /* free tx/rx rings */
6568 rtl8192_free_rx_ring(dev);
6569 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
6570 rtl8192_free_tx_ring(dev, i);
6575 printk("Freeing irq %d\n",dev->irq);
6576 free_irq(dev->irq, dev);
6583 // free_beacon_desc_ring(dev,priv->txbeaconcount);
6585 #ifdef CONFIG_RTL8180_IO_MAP
6587 if( dev->base_addr != 0 ){
6589 release_region(dev->base_addr,
6590 pci_resource_len(pdev, 0) );
6593 if( dev->mem_start != (unsigned long)NULL ){
6594 iounmap( (void *)dev->mem_start );
6595 release_mem_region( pci_resource_start(pdev, 1),
6596 pci_resource_len(pdev, 1) );
6598 #endif /*end #ifdef RTL_IO_MAP*/
6599 free_ieee80211(dev);
6603 pci_disable_device(pdev);
6604 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
6607 extern int ieee80211_rtl_init(void);
6608 extern void ieee80211_rtl_exit(void);
6610 static int __init rtl8192_pci_module_init(void)
6614 retval = ieee80211_rtl_init();
6618 printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
6619 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
6620 RT_TRACE(COMP_INIT, "Initializing module");
6621 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
6622 rtl8192_proc_module_init();
6623 if(0!=pci_register_driver(&rtl8192_pci_driver))
6625 DMESG("No device found");
6626 /*pci_unregister_driver (&rtl8192_pci_driver);*/
6633 static void __exit rtl8192_pci_module_exit(void)
6635 pci_unregister_driver(&rtl8192_pci_driver);
6637 RT_TRACE(COMP_DOWN, "Exiting");
6638 rtl8192_proc_module_remove();
6639 ieee80211_rtl_exit();
6642 //warning message WB
6643 irqreturn_t rtl8192_interrupt(int irq, void *netdev)
6645 struct net_device *dev = (struct net_device *) netdev;
6646 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6647 unsigned long flags;
6649 /* We should return IRQ_NONE, but for now let me keep this */
6650 if(priv->irq_enabled == 0){
6654 spin_lock_irqsave(&priv->irq_th_lock,flags);
6658 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
6659 write_nic_dword(dev,ISR,inta); // reset int situation
6661 priv->stats.shints++;
6662 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
6664 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6667 most probably we can safely return IRQ_NONE,
6668 but for now is better to avoid problems
6674 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6680 DMESG("NIC irq %x",inta);
6682 //priv->irqpending = inta;
6685 if(!netif_running(dev)) {
6686 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6690 if(inta & IMR_TIMEOUT0){
6691 // write_nic_dword(dev, TimerInt, 0);
6692 //DMESG("=================>waking up");
6693 // rtl8180_hw_wakeup(dev);
6696 if(inta & IMR_TBDOK){
6697 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
6698 rtl8192_tx_isr(dev, BEACON_QUEUE);
6699 priv->stats.txbeaconokint++;
6702 if(inta & IMR_TBDER){
6703 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
6704 rtl8192_tx_isr(dev, BEACON_QUEUE);
6705 priv->stats.txbeaconerr++;
6708 if(inta & IMR_MGNTDOK ) {
6709 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
6710 priv->stats.txmanageokint++;
6711 rtl8192_tx_isr(dev,MGNT_QUEUE);
6715 if(inta & IMR_COMDOK)
6717 priv->stats.txcmdpktokint++;
6718 rtl8192_tx_isr(dev,TXCMD_QUEUE);
6723 DMESG("Frame arrived !");
6725 priv->stats.rxint++;
6726 tasklet_schedule(&priv->irq_rx_tasklet);
6729 if(inta & IMR_BcnInt) {
6730 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
6731 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
6735 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
6736 priv->stats.rxrdu++;
6737 /* reset int situation */
6738 write_nic_dword(dev,INTA_MASK,read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
6739 tasklet_schedule(&priv->irq_rx_tasklet);
6742 if(inta & IMR_RXFOVW){
6743 RT_TRACE(COMP_INTR, "rx overflow !\n");
6744 priv->stats.rxoverflow++;
6745 tasklet_schedule(&priv->irq_rx_tasklet);
6748 if(inta & IMR_TXFOVW) priv->stats.txoverflow++;
6750 if(inta & IMR_BKDOK){
6751 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
6752 priv->stats.txbkokint++;
6753 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6754 rtl8192_tx_isr(dev,BK_QUEUE);
6755 rtl8192_try_wake_queue(dev, BK_QUEUE);
6758 if(inta & IMR_BEDOK){
6759 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
6760 priv->stats.txbeokint++;
6761 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6762 rtl8192_tx_isr(dev,BE_QUEUE);
6763 rtl8192_try_wake_queue(dev, BE_QUEUE);
6766 if(inta & IMR_VIDOK){
6767 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
6768 priv->stats.txviokint++;
6769 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6770 rtl8192_tx_isr(dev,VI_QUEUE);
6771 rtl8192_try_wake_queue(dev, VI_QUEUE);
6774 if(inta & IMR_VODOK){
6775 priv->stats.txvookint++;
6776 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
6777 rtl8192_tx_isr(dev,VO_QUEUE);
6778 rtl8192_try_wake_queue(dev, VO_QUEUE);
6781 force_pci_posting(dev);
6782 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6787 void rtl8192_try_wake_queue(struct net_device *dev, int pri)
6790 unsigned long flags;
6792 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6794 spin_lock_irqsave(&priv->tx_lock,flags);
6795 enough_desc = check_nic_enough_desc(dev,pri);
6796 spin_unlock_irqrestore(&priv->tx_lock,flags);
6799 ieee80211_rtl_wake_queue(priv->ieee80211);
6804 void EnableHWSecurityConfig8192(struct net_device *dev)
6806 u8 SECR_value = 0x0;
6807 // struct ieee80211_device* ieee1 = container_of(&dev, struct ieee80211_device, dev);
6808 //printk("==>ieee1:%p, dev:%p\n", ieee1, dev);
6809 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6810 struct ieee80211_device* ieee = priv->ieee80211;
6811 //printk("==>ieee:%p, dev:%p\n", ieee, dev);
6812 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
6814 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
6816 SECR_value |= SCR_RxUseDK;
6817 SECR_value |= SCR_TxUseDK;
6819 else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
6821 SECR_value |= SCR_RxUseDK;
6822 SECR_value |= SCR_TxUseDK;
6827 //add HWSec active enable here.
6828 //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
6829 ieee->hwsec_active = 1;
6831 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
6833 ieee->hwsec_active = 0;
6834 SECR_value &= ~SCR_RxDecEnable;
6837 RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, \
6838 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
6840 write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK );
6844 #define TOTAL_CAM_ENTRY 32
6845 //#define CAM_CONTENT_COUNT 8
6846 void setKey( struct net_device *dev,
6854 u32 TargetCommand = 0;
6855 u32 TargetContent = 0;
6859 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6860 RT_RF_POWER_STATE rtState;
6861 rtState = priv->ieee80211->eRFPowerState;
6862 if(priv->ieee80211->PowerSaveControl.bInactivePs){
6863 if(rtState == eRfOff){
6864 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
6866 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
6867 //up(&priv->wx_sem);
6871 down(&priv->ieee80211->ips_sem);
6873 up(&priv->ieee80211->ips_sem);
6877 priv->ieee80211->is_set_key = true;
6879 if (EntryNo >= TOTAL_CAM_ENTRY)
6880 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
6882 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr);
6885 usConfig |= BIT15 | (KeyType<<2);
6887 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
6888 // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
6891 for(i=0 ; i<CAM_CONTENT_COUNT; i++){
6892 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
6893 TargetCommand |= BIT31|BIT16;
6895 if(i==0){//MAC|Config
6896 TargetContent = (u32)(*(MacAddr+0)) << 16|
6897 (u32)(*(MacAddr+1)) << 24|
6900 write_nic_dword(dev, WCAMI, TargetContent);
6901 write_nic_dword(dev, RWCAM, TargetCommand);
6902 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
6905 TargetContent = (u32)(*(MacAddr+2)) |
6906 (u32)(*(MacAddr+3)) << 8|
6907 (u32)(*(MacAddr+4)) << 16|
6908 (u32)(*(MacAddr+5)) << 24;
6909 write_nic_dword(dev, WCAMI, TargetContent);
6910 write_nic_dword(dev, RWCAM, TargetCommand);
6912 else { //Key Material
6913 if(KeyContent != NULL)
6915 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
6916 write_nic_dword(dev, RWCAM, TargetCommand);
6920 RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig);
6922 // This function seems not ready! WB
6923 void CamPrintDbgReg(struct net_device* dev)
6925 unsigned long rvalue;
6926 unsigned char ucValue;
6927 write_nic_dword(dev, DCAM, 0x80000000);
6929 rvalue = read_nic_dword(dev, DCAM); //delay_ms(40);
6930 RT_TRACE(COMP_SEC, " TX CAM=%8lX ",rvalue);
6931 if((rvalue & 0x40000000) != 0x4000000)
6932 RT_TRACE(COMP_SEC, "-->TX Key Not Found ");
6934 write_nic_dword(dev, DCAM, 0x00000000); //delay_ms(40);
6935 rvalue = read_nic_dword(dev, DCAM); //delay_ms(40);
6936 RT_TRACE(COMP_SEC, "RX CAM=%8lX ",rvalue);
6937 if((rvalue & 0x40000000) != 0x4000000)
6938 RT_TRACE(COMP_SEC, "-->CAM Key Not Found ");
6939 ucValue = read_nic_byte(dev, SECR);
6940 RT_TRACE(COMP_SEC, "WPA_Config=%x \n",ucValue);
6943 bool NicIFEnableNIC(struct net_device* dev)
6945 RT_STATUS init_status = RT_STATUS_SUCCESS;
6946 struct r8192_priv* priv = ieee80211_priv(dev);
6947 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
6951 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__FUNCTION__);
6952 priv->bdisable_nic = false; //YJ,add,091111
6955 // <1> Reset memory: descriptor, buffer,..
6956 //NicIFResetMemory(Adapter);
6958 // <2> Enable Adapter
6959 //printk("===========>%s()\n",__FUNCTION__);
6960 //priv->bfirst_init = true;
6961 init_status = rtl8192_adapter_start(dev);
6962 if (init_status != RT_STATUS_SUCCESS) {
6963 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
6964 priv->bdisable_nic = false; //YJ,add,091111
6967 //printk("start adapter finished\n");
6968 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
6969 //priv->bfirst_init = false;
6971 // <3> Enable Interrupt
6972 rtl8192_irq_enable(dev);
6973 priv->bdisable_nic = false;
6974 //RT_TRACE(COMP_PS,"<===========%s()\n",__FUNCTION__);
6975 return (init_status == RT_STATUS_SUCCESS) ? true:false;
6977 bool NicIFDisableNIC(struct net_device* dev)
6980 struct r8192_priv* priv = ieee80211_priv(dev);
6982 // <1> Disable Interrupt
6983 //RT_TRACE(COMP_PS, "=========>%s()\n",__FUNCTION__);
6984 priv->bdisable_nic = true; //YJ,move,091109
6985 tmp_state = priv->ieee80211->state;
6987 ieee80211_softmac_stop_protocol(priv->ieee80211, false);
6989 priv->ieee80211->state = tmp_state;
6990 rtl8192_cancel_deferred_work(priv);
6991 rtl8192_irq_disable(dev);
6992 // <2> Stop all timer
6994 // <3> Disable Adapter
6995 rtl8192_halt_adapter(dev, false);
6996 // priv->bdisable_nic = true;
6997 //RT_TRACE(COMP_PS, "<=========%s()\n",__FUNCTION__);
7003 /***************************************************************************
7004 ------------------- module init / exit stubs ----------------
7005 ****************************************************************************/
7006 module_init(rtl8192_pci_module_init);
7007 module_exit(rtl8192_pci_module_exit);