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>
28 #undef RX_DONT_PASS_UL
30 #undef DEBUG_RX_VERBOSE
36 #undef DEBUG_TX_FILLDESC
41 #undef DEBUG_REGISTERS
43 #undef DEBUG_IRQ_TASKLET
47 //#define CONFIG_RTL8192_IO_MAP
48 #include <linux/vmalloc.h>
49 #include <linux/slab.h>
50 #include <asm/uaccess.h>
51 #include "r8192E_hw.h"
53 #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
54 #include "r8180_93cx6.h" /* Card EEPROM */
55 #include "r8192E_wx.h"
56 #include "r819xE_phy.h" //added by WB 4.30.2008
57 #include "r819xE_phyreg.h"
58 #include "r819xE_cmdpkt.h"
59 #include "r8192E_dm.h"
66 #include "ieee80211/dot11d.h"
69 //set here to open your trace code. //WB
70 u32 rt_global_debug_component =
88 // COMP_POWER_TRACKING |
90 COMP_ERR ; //always open err flags on
92 static DEFINE_PCI_DEVICE_TABLE(rtl8192_pci_id_tbl) = {
96 { PCI_DEVICE(0x10ec, 0x8190) },
98 { PCI_DEVICE(0x07aa, 0x0045) },
99 { PCI_DEVICE(0x07aa, 0x0046) },
102 { PCI_DEVICE(0x10ec, 0x8192) },
105 { PCI_DEVICE(0x07aa, 0x0044) },
106 { PCI_DEVICE(0x07aa, 0x0047) },
111 static char ifname[IFNAMSIZ] = "wlan%d";
112 static int hwwep = 1; //default use hw. set 0 to use software security
113 static int channels = 0x3fff;
115 MODULE_LICENSE("GPL");
116 MODULE_VERSION("V 1.1");
117 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
118 //MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
119 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
122 module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
123 module_param(hwwep,int, S_IRUGO|S_IWUSR);
124 module_param(channels,int, S_IRUGO|S_IWUSR);
126 MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
127 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
128 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
130 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
131 const struct pci_device_id *id);
132 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev);
134 static struct pci_driver rtl8192_pci_driver = {
135 .name = RTL819xE_MODULE_NAME, /* Driver name */
136 .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */
137 .probe = rtl8192_pci_probe, /* probe fn */
138 .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */
140 .suspend = rtl8192E_suspend, /* PM suspend fn */
141 .resume = rtl8192E_resume, /* PM resume fn */
143 .suspend = NULL, /* PM suspend fn */
144 .resume = NULL, /* PM resume fn */
148 static void rtl8192_start_beacon(struct net_device *dev);
149 static void rtl8192_stop_beacon(struct net_device *dev);
150 static void rtl819x_watchdog_wqcallback(struct work_struct *work);
151 static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
152 static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
153 static void rtl8192_prepare_beacon(struct r8192_priv *priv);
154 static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
155 static void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb);
156 static void rtl8192_update_ratr_table(struct net_device* dev);
157 static void rtl8192_restart(struct work_struct *work);
158 static void watch_dog_timer_callback(unsigned long data);
159 static int _rtl8192_up(struct net_device *dev);
160 static void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
164 typedef struct _CHANNEL_LIST
168 }CHANNEL_LIST, *PCHANNEL_LIST;
170 static const CHANNEL_LIST ChannelPlan[] = {
171 {{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
172 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
173 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
174 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
175 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
176 {{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
177 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
178 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
179 {{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
180 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
181 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14} //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626
184 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
186 int i, max_chan=-1, min_chan=-1;
187 struct ieee80211_device* ieee = priv->ieee80211;
188 switch (channel_plan)
190 case COUNTRY_CODE_FCC:
191 case COUNTRY_CODE_IC:
192 case COUNTRY_CODE_ETSI:
193 case COUNTRY_CODE_SPAIN:
194 case COUNTRY_CODE_FRANCE:
195 case COUNTRY_CODE_MKK:
196 case COUNTRY_CODE_MKK1:
197 case COUNTRY_CODE_ISRAEL:
198 case COUNTRY_CODE_TELEC:
199 case COUNTRY_CODE_MIC:
202 ieee->bGlobalDomain = false;
203 //acturally 8225 & 8256 rf chip only support B,G,24N mode
204 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256))
211 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
213 if (ChannelPlan[channel_plan].Len != 0){
214 // Clear old channel map
215 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
216 // Set new channel map
217 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
219 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
221 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
226 case COUNTRY_CODE_GLOBAL_DOMAIN:
228 GET_DOT11D_INFO(ieee)->bEnabled = 0; //this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain setting
230 ieee->bGlobalDomain = true;
239 static inline bool rx_hal_is_cck_rate(prx_fwinfo_819x_pci pdrvinfo)
241 return (pdrvinfo->RxRate == DESC90_RATE1M ||
242 pdrvinfo->RxRate == DESC90_RATE2M ||
243 pdrvinfo->RxRate == DESC90_RATE5_5M ||
244 pdrvinfo->RxRate == DESC90_RATE11M) &&
248 void CamResetAllEntry(struct net_device *dev)
250 write_nic_dword(dev, RWCAM, BIT31|BIT30);
254 void write_cam(struct net_device *dev, u8 addr, u32 data)
256 write_nic_dword(dev, WCAMI, data);
257 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
259 u32 read_cam(struct net_device *dev, u8 addr)
261 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
262 return read_nic_dword(dev, 0xa8);
265 #ifdef CONFIG_RTL8180_IO_MAP
267 u8 read_nic_byte(struct net_device *dev, int x)
269 return 0xff&inb(dev->base_addr +x);
272 u32 read_nic_dword(struct net_device *dev, int x)
274 return inl(dev->base_addr +x);
277 u16 read_nic_word(struct net_device *dev, int x)
279 return inw(dev->base_addr +x);
282 void write_nic_byte(struct net_device *dev, int x,u8 y)
284 outb(y&0xff,dev->base_addr +x);
287 void write_nic_word(struct net_device *dev, int x,u16 y)
289 outw(y,dev->base_addr +x);
292 void write_nic_dword(struct net_device *dev, int x,u32 y)
294 outl(y,dev->base_addr +x);
297 #else /* RTL_IO_MAP */
299 u8 read_nic_byte(struct net_device *dev, int x)
301 return 0xff&readb((u8*)dev->mem_start +x);
304 u32 read_nic_dword(struct net_device *dev, int x)
306 return readl((u8*)dev->mem_start +x);
309 u16 read_nic_word(struct net_device *dev, int x)
311 return readw((u8*)dev->mem_start +x);
314 void write_nic_byte(struct net_device *dev, int x,u8 y)
316 writeb(y,(u8*)dev->mem_start +x);
320 void write_nic_dword(struct net_device *dev, int x,u32 y)
322 writel(y,(u8*)dev->mem_start +x);
326 void write_nic_word(struct net_device *dev, int x,u16 y)
328 writew(y,(u8*)dev->mem_start +x);
332 #endif /* RTL_IO_MAP */
334 u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee)
336 static const u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
337 static const u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
338 int wpa_ie_len= ieee->wpa_ie_len;
339 struct ieee80211_crypt_data* crypt;
342 crypt = ieee->crypt[ieee->tx_keyidx];
344 encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) ||
345 (ieee->host_encrypt && crypt && crypt->ops &&
346 (0 == strcmp(crypt->ops->name,"WEP")));
349 if(encrypt && (wpa_ie_len == 0)) {
350 // wep encryption, no N mode setting */
352 } else if((wpa_ie_len != 0)) {
353 // parse pairwise key type */
354 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) ||
355 ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4))))
365 rtl8192e_SetHwReg(struct net_device *dev,u8 variable,u8* val)
367 struct r8192_priv* priv = ieee80211_priv(dev);
373 write_nic_dword(dev, BSSIDR, ((u32*)(val))[0]);
374 write_nic_word(dev, BSSIDR+2, ((u16*)(val+2))[0]);
377 case HW_VAR_MEDIA_STATUS:
379 RT_OP_MODE OpMode = *((RT_OP_MODE *)(val));
380 u8 btMsr = read_nic_byte(dev, MSR);
386 case RT_OP_MODE_INFRASTRUCTURE:
390 case RT_OP_MODE_IBSS:
403 write_nic_byte(dev, MSR, btMsr);
407 case HW_VAR_CHECK_BSSID:
411 Type = ((u8*)(val))[0];
412 RegRCR = read_nic_dword(dev,RCR);
413 priv->ReceiveConfig = RegRCR;
416 RegRCR |= (RCR_CBSSID);
417 else if (Type == false)
418 RegRCR &= (~RCR_CBSSID);
420 write_nic_dword(dev, RCR,RegRCR);
421 priv->ReceiveConfig = RegRCR;
426 case HW_VAR_SLOT_TIME:
428 priv->slot_time = val[0];
429 write_nic_byte(dev, SLOT_TIME, val[0]);
434 case HW_VAR_ACK_PREAMBLE:
437 priv->short_preamble = (bool)(*(u8*)val );
438 regTmp = priv->basic_rate;
439 if (priv->short_preamble)
440 regTmp |= BRSR_AckShortPmb;
441 write_nic_dword(dev, RRSR, regTmp);
446 write_nic_dword(dev, CPU_GEN, ((u32*)(val))[0]);
455 static struct proc_dir_entry *rtl8192_proc = NULL;
457 static int proc_get_stats_ap(char *page, char **start,
458 off_t offset, int count,
459 int *eof, void *data)
461 struct net_device *dev = data;
462 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
463 struct ieee80211_device *ieee = priv->ieee80211;
464 struct ieee80211_network *target;
467 list_for_each_entry(target, &ieee->network_list, list) {
469 len += snprintf(page + len, count - len,
470 "%s ", target->ssid);
472 if(target->wpa_ie_len>0 || target->rsn_ie_len>0){
473 len += snprintf(page + len, count - len,
477 len += snprintf(page + len, count - len,
487 static int proc_get_registers(char *page, char **start,
488 off_t offset, int count,
489 int *eof, void *data)
491 struct net_device *dev = data;
496 /* This dump the current register page */
497 len += snprintf(page + len, count - len,
498 "\n####################page 0##################\n ");
502 len += snprintf(page + len, count - len,
505 for(i=0;i<16 && n<=max;i++,n++)
506 len += snprintf(page + len, count - len,
507 "%2x ",read_nic_byte(dev,n));
509 len += snprintf(page + len, count - len,"\n");
510 len += snprintf(page + len, count - len,
511 "\n####################page 1##################\n ");
514 len += snprintf(page + len, count - len,
517 for(i=0;i<16 && n<=max;i++,n++)
518 len += snprintf(page + len, count - len,
519 "%2x ",read_nic_byte(dev,0x100|n));
522 len += snprintf(page + len, count - len,
523 "\n####################page 3##################\n ");
526 len += snprintf(page + len, count - len,
529 for(i=0;i<16 && n<=max;i++,n++)
530 len += snprintf(page + len, count - len,
531 "%2x ",read_nic_byte(dev,0x300|n));
539 static int proc_get_stats_tx(char *page, char **start,
540 off_t offset, int count,
541 int *eof, void *data)
543 struct net_device *dev = data;
544 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
548 len += snprintf(page + len, count - len,
549 "TX VI priority ok int: %lu\n"
550 "TX VO priority ok int: %lu\n"
551 "TX BE priority ok int: %lu\n"
552 "TX BK priority ok int: %lu\n"
553 "TX MANAGE priority ok int: %lu\n"
554 "TX BEACON priority ok int: %lu\n"
555 "TX BEACON priority error int: %lu\n"
556 "TX CMDPKT priority ok int: %lu\n"
557 "TX queue stopped?: %d\n"
558 "TX fifo overflow: %lu\n"
559 "TX total data packets %lu\n"
560 "TX total data bytes :%lu\n",
561 priv->stats.txviokint,
562 priv->stats.txvookint,
563 priv->stats.txbeokint,
564 priv->stats.txbkokint,
565 priv->stats.txmanageokint,
566 priv->stats.txbeaconokint,
567 priv->stats.txbeaconerr,
568 priv->stats.txcmdpktokint,
569 netif_queue_stopped(dev),
570 priv->stats.txoverflow,
571 priv->ieee80211->stats.tx_packets,
572 priv->ieee80211->stats.tx_bytes);
580 static int proc_get_stats_rx(char *page, char **start,
581 off_t offset, int count,
582 int *eof, void *data)
584 struct net_device *dev = data;
585 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
589 len += snprintf(page + len, count - len,
592 "RX rx overflow error: %lu\n",
595 priv->stats.rxoverflow);
601 static void rtl8192_proc_module_init(void)
603 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
604 rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net);
608 static void rtl8192_proc_module_remove(void)
610 remove_proc_entry(RTL819xE_MODULE_NAME, init_net.proc_net);
614 static void rtl8192_proc_remove_one(struct net_device *dev)
616 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
618 printk("dev name=======> %s\n",dev->name);
621 // remove_proc_entry("stats-hw", priv->dir_dev);
622 remove_proc_entry("stats-tx", priv->dir_dev);
623 remove_proc_entry("stats-rx", priv->dir_dev);
624 // remove_proc_entry("stats-ieee", priv->dir_dev);
625 remove_proc_entry("stats-ap", priv->dir_dev);
626 remove_proc_entry("registers", priv->dir_dev);
627 // remove_proc_entry("cck-registers",priv->dir_dev);
628 // remove_proc_entry("ofdm-registers",priv->dir_dev);
629 //remove_proc_entry(dev->name, rtl8192_proc);
630 remove_proc_entry("wlan0", rtl8192_proc);
631 priv->dir_dev = NULL;
636 static void rtl8192_proc_init_one(struct net_device *dev)
638 struct proc_dir_entry *e;
639 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
640 priv->dir_dev = create_proc_entry(dev->name,
641 S_IFDIR | S_IRUGO | S_IXUGO,
643 if (!priv->dir_dev) {
644 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
648 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
649 priv->dir_dev, proc_get_stats_rx, dev);
652 RT_TRACE(COMP_ERR,"Unable to initialize "
653 "/proc/net/rtl8192/%s/stats-rx\n",
658 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
659 priv->dir_dev, proc_get_stats_tx, dev);
662 RT_TRACE(COMP_ERR, "Unable to initialize "
663 "/proc/net/rtl8192/%s/stats-tx\n",
667 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
668 priv->dir_dev, proc_get_stats_ap, dev);
671 RT_TRACE(COMP_ERR, "Unable to initialize "
672 "/proc/net/rtl8192/%s/stats-ap\n",
676 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
677 priv->dir_dev, proc_get_registers, dev);
679 RT_TRACE(COMP_ERR, "Unable to initialize "
680 "/proc/net/rtl8192/%s/registers\n",
685 short check_nic_enough_desc(struct net_device *dev, int prio)
687 struct r8192_priv *priv = ieee80211_priv(dev);
688 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
690 /* for now we reserve two free descriptor as a safety boundary
691 * between the tail and the head
693 return (ring->entries - skb_queue_len(&ring->queue) >= 2);
696 static void tx_timeout(struct net_device *dev)
698 struct r8192_priv *priv = ieee80211_priv(dev);
700 schedule_work(&priv->reset_wq);
704 static void rtl8192_irq_enable(struct net_device *dev)
706 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
707 priv->irq_enabled = 1;
708 write_nic_dword(dev,INTA_MASK, priv->irq_mask);
711 void rtl8192_irq_disable(struct net_device *dev)
713 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
715 write_nic_dword(dev,INTA_MASK,0);
716 priv->irq_enabled = 0;
719 void rtl8192_update_msr(struct net_device *dev)
721 struct r8192_priv *priv = ieee80211_priv(dev);
724 msr = read_nic_byte(dev, MSR);
725 msr &= ~ MSR_LINK_MASK;
727 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
728 * msr must be updated if the state is ASSOCIATING.
729 * this is intentional and make sense for ad-hoc and
730 * master (see the create BSS/IBSS func)
732 if (priv->ieee80211->state == IEEE80211_LINKED){
734 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
735 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
736 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
737 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
738 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
739 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
742 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
744 write_nic_byte(dev, MSR, msr);
747 void rtl8192_set_chan(struct net_device *dev,short ch)
749 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
753 /* need to implement rf set channel here WB */
755 if (priv->rf_set_chan)
756 priv->rf_set_chan(dev, priv->chan);
759 void rtl8192_rx_enable(struct net_device *dev)
761 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
763 write_nic_dword(dev, RDQDA,priv->rx_ring_dma);
766 /* the TX_DESC_BASE setting is according to the following queue index
775 * BEACON_QUEUE ===> 8
777 static const u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA};
778 void rtl8192_tx_enable(struct net_device *dev)
780 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
783 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
784 write_nic_dword(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma);
786 ieee80211_reset_queue(priv->ieee80211);
790 static void rtl8192_free_rx_ring(struct net_device *dev)
792 struct r8192_priv *priv = ieee80211_priv(dev);
795 for (i = 0; i < priv->rxringcount; i++) {
796 struct sk_buff *skb = priv->rx_buf[i];
800 pci_unmap_single(priv->pdev,
801 *((dma_addr_t *)skb->cb),
802 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
806 pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount,
807 priv->rx_ring, priv->rx_ring_dma);
808 priv->rx_ring = NULL;
811 static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
813 struct r8192_priv *priv = ieee80211_priv(dev);
814 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
816 while (skb_queue_len(&ring->queue)) {
817 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
818 struct sk_buff *skb = __skb_dequeue(&ring->queue);
820 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
821 skb->len, PCI_DMA_TODEVICE);
823 ring->idx = (ring->idx + 1) % ring->entries;
826 pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries,
827 ring->desc, ring->dma);
831 void PHY_SetRtl8192eRfOff(struct net_device* dev)
833 //disable RF-Chip A/B
834 rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
835 //analog to digital off, for power save
836 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0);
837 //digital to analog off, for power save
838 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0);
840 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
842 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
843 //analog to digital part2 off, for power save
844 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0);
845 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0);
846 // Analog parameter!!Change bias and Lbus control.
847 write_nic_byte(dev, ANAPAR_FOR_8192PciE, 0x07);
851 void rtl8192_halt_adapter(struct net_device *dev, bool reset)
853 struct r8192_priv *priv = ieee80211_priv(dev);
858 OpMode = RT_OP_MODE_NO_LINK;
859 priv->ieee80211->SetHwRegHandler(dev, HW_VAR_MEDIA_STATUS, &OpMode);
861 if (!priv->ieee80211->bSupportRemoteWakeUp) {
863 * disable tx/rx. In 8185 we write 0x10 (Reset bit),
864 * but here we make reference to WMAC and wirte 0x0
866 write_nic_byte(dev, CMDR, 0);
875 priv->bHwRfOffAction = 2;
879 * Call MgntActSet_RF_State instead to
880 * prevent RF config race condition.
882 if (!priv->ieee80211->bSupportRemoteWakeUp) {
883 PHY_SetRtl8192eRfOff(dev);
884 ulRegRead = read_nic_dword(dev,CPU_GEN);
885 ulRegRead |= CPU_GEN_SYSTEM_RESET;
886 write_nic_dword(dev,CPU_GEN, ulRegRead);
889 write_nic_dword(dev, WFCRC0, 0xffffffff);
890 write_nic_dword(dev, WFCRC1, 0xffffffff);
891 write_nic_dword(dev, WFCRC2, 0xffffffff);
893 /* Write PMR register */
894 write_nic_byte(dev, PMR, 0x5);
895 /* Disable tx, enanble rx */
896 write_nic_byte(dev, MacBlkCtrl, 0xa);
900 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
901 skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
903 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
904 skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
907 skb_queue_purge(&priv->skb_queue);
910 static const u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
911 inline u16 rtl8192_rate2rate(short rate)
913 if (rate >11) return 0;
914 return rtl_rate[rate];
917 static void rtl8192_data_hard_stop(struct net_device *dev)
921 static void rtl8192_data_hard_resume(struct net_device *dev)
926 * this function TX data frames when the ieee80211 stack requires this.
927 * It checks also if we need to stop the ieee tx queue, eventually do it
929 static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
931 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
933 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
934 u8 queue_index = tcb_desc->queue_index;
936 /* shall not be referred by command packet */
937 BUG_ON(queue_index == TXCMD_QUEUE);
939 if (priv->bHwRadioOff || (!priv->up))
945 memcpy(skb->cb, &dev, sizeof(dev));
947 skb_push(skb, priv->ieee80211->tx_headroom);
948 ret = rtl8192_tx(dev, skb);
953 if (queue_index != MGNT_QUEUE) {
954 priv->ieee80211->stats.tx_bytes += (skb->len - priv->ieee80211->tx_headroom);
955 priv->ieee80211->stats.tx_packets++;
960 * This is a rough attempt to TX a frame
961 * This is called by the ieee 80211 stack to TX management frames.
962 * If the ring is full packet are dropped (for data frame the queue
963 * is stopped before this can happen).
965 static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
967 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
969 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
970 u8 queue_index = tcb_desc->queue_index;
972 if (queue_index != TXCMD_QUEUE) {
973 if (priv->bHwRadioOff || (!priv->up))
980 memcpy(skb->cb, &dev, sizeof(dev));
981 if (queue_index == TXCMD_QUEUE) {
982 rtl819xE_tx_cmd(dev, skb);
986 tcb_desc->RATRIndex = 7;
987 tcb_desc->bTxDisableRateFallBack = 1;
988 tcb_desc->bTxUseDriverAssingedRate = 1;
989 tcb_desc->bTxEnableFwCalcDur = 1;
990 skb_push(skb, priv->ieee80211->tx_headroom);
991 ret = rtl8192_tx(dev, skb);
1001 static void rtl8192_tx_isr(struct net_device *dev, int prio)
1003 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1004 struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
1006 while (skb_queue_len(&ring->queue)) {
1007 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1008 struct sk_buff *skb;
1011 * beacon packet will only use the first descriptor defaultly,
1012 * and the OWN may not be cleared by the hardware
1014 if (prio != BEACON_QUEUE) {
1017 ring->idx = (ring->idx + 1) % ring->entries;
1020 skb = __skb_dequeue(&ring->queue);
1021 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1022 skb->len, PCI_DMA_TODEVICE);
1026 if (prio == MGNT_QUEUE) {
1027 if (priv->ieee80211->ack_tx_to_ieee) {
1028 if (rtl8192_is_tx_queue_empty(dev)) {
1029 priv->ieee80211->ack_tx_to_ieee = 0;
1030 ieee80211_ps_tx_ack(priv->ieee80211, 1);
1035 if (prio != BEACON_QUEUE) {
1036 /* try to deal with the pending packets */
1037 tasklet_schedule(&priv->irq_tx_tasklet);
1041 static void rtl8192_stop_beacon(struct net_device *dev)
1045 static void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
1047 struct r8192_priv *priv = ieee80211_priv(dev);
1048 struct ieee80211_network *net;
1049 u8 i=0, basic_rate = 0;
1050 net = & priv->ieee80211->current_network;
1052 for (i=0; i<net->rates_len; i++)
1054 basic_rate = net->rates[i]&0x7f;
1057 case MGN_1M: *rate_config |= RRSR_1M; break;
1058 case MGN_2M: *rate_config |= RRSR_2M; break;
1059 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1060 case MGN_11M: *rate_config |= RRSR_11M; break;
1061 case MGN_6M: *rate_config |= RRSR_6M; break;
1062 case MGN_9M: *rate_config |= RRSR_9M; break;
1063 case MGN_12M: *rate_config |= RRSR_12M; break;
1064 case MGN_18M: *rate_config |= RRSR_18M; break;
1065 case MGN_24M: *rate_config |= RRSR_24M; break;
1066 case MGN_36M: *rate_config |= RRSR_36M; break;
1067 case MGN_48M: *rate_config |= RRSR_48M; break;
1068 case MGN_54M: *rate_config |= RRSR_54M; break;
1071 for (i=0; i<net->rates_ex_len; i++)
1073 basic_rate = net->rates_ex[i]&0x7f;
1076 case MGN_1M: *rate_config |= RRSR_1M; break;
1077 case MGN_2M: *rate_config |= RRSR_2M; break;
1078 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1079 case MGN_11M: *rate_config |= RRSR_11M; break;
1080 case MGN_6M: *rate_config |= RRSR_6M; break;
1081 case MGN_9M: *rate_config |= RRSR_9M; break;
1082 case MGN_12M: *rate_config |= RRSR_12M; break;
1083 case MGN_18M: *rate_config |= RRSR_18M; break;
1084 case MGN_24M: *rate_config |= RRSR_24M; break;
1085 case MGN_36M: *rate_config |= RRSR_36M; break;
1086 case MGN_48M: *rate_config |= RRSR_48M; break;
1087 case MGN_54M: *rate_config |= RRSR_54M; break;
1093 #define SHORT_SLOT_TIME 9
1094 #define NON_SHORT_SLOT_TIME 20
1096 static void rtl8192_update_cap(struct net_device* dev, u16 cap)
1099 struct r8192_priv *priv = ieee80211_priv(dev);
1100 struct ieee80211_network *net = &priv->ieee80211->current_network;
1101 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1102 tmp = priv->basic_rate;
1103 if (priv->short_preamble)
1104 tmp |= BRSR_AckShortPmb;
1105 write_nic_dword(dev, RRSR, tmp);
1107 if (net->mode & (IEEE_G|IEEE_N_24G))
1110 if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
1112 slot_time = SHORT_SLOT_TIME;
1114 else //long slot time
1115 slot_time = NON_SHORT_SLOT_TIME;
1116 priv->slot_time = slot_time;
1117 write_nic_byte(dev, SLOT_TIME, slot_time);
1122 static void rtl8192_net_update(struct net_device *dev)
1124 struct r8192_priv *priv = ieee80211_priv(dev);
1125 struct ieee80211_network *net;
1126 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1127 u16 rate_config = 0;
1128 net = &priv->ieee80211->current_network;
1130 /* update Basic rate: RR, BRSR */
1131 rtl8192_config_rate(dev, &rate_config);
1134 * Select RRSR (in Legacy-OFDM and CCK)
1135 * For 8190, we select only 24M, 12M, 6M, 11M, 5.5M,
1136 * 2M, and 1M from the Basic rate.
1137 * We do not use other rates.
1139 priv->basic_rate = rate_config &= 0x15f;
1142 write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
1143 write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
1145 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1147 write_nic_word(dev, ATIMWND, 2);
1148 write_nic_word(dev, BCN_DMATIME, 256);
1149 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1151 * BIT15 of BCN_DRV_EARLY_INT will indicate
1152 * whether software beacon or hw beacon is applied.
1154 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
1155 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1157 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1158 /* TODO: BcnIFS may required to be changed on ASIC */
1159 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1160 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1164 void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1166 struct r8192_priv *priv = ieee80211_priv(dev);
1167 struct rtl8192_tx_ring *ring;
1168 tx_desc_819x_pci *entry;
1172 unsigned long flags;
1174 ring = &priv->tx_ring[TXCMD_QUEUE];
1175 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1177 spin_lock_irqsave(&priv->irq_th_lock,flags);
1178 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1179 entry = &ring->desc[idx];
1181 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1183 entry->LINIP = tcb_desc->bLastIniPkt;
1184 entry->FirstSeg = 1;//first segment
1185 entry->LastSeg = 1; //last segment
1186 if(tcb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) {
1187 entry->CmdInit = DESC_PACKET_TYPE_INIT;
1189 entry->CmdInit = DESC_PACKET_TYPE_NORMAL;
1190 entry->Offset = sizeof(TX_FWINFO_8190PCI) + 8;
1191 entry->PktSize = (u16)(tcb_desc->pkt_size + entry->Offset);
1192 entry->QueueSelect = QSLT_CMD;
1193 entry->TxFWInfoSize = 0x08;
1194 entry->RATid = (u8)DESC_PACKET_TYPE_INIT;
1196 entry->TxBufferSize = skb->len;
1197 entry->TxBuffAddr = cpu_to_le32(mapping);
1200 __skb_queue_tail(&ring->queue, skb);
1201 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
1203 write_nic_byte(dev, TPPoll, TPPoll_CQ);
1209 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1210 * in TxFwInfo data structure
1212 static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1218 QueueSelect = QSLT_BE;
1222 QueueSelect = QSLT_BK;
1226 QueueSelect = QSLT_VO;
1230 QueueSelect = QSLT_VI;
1234 QueueSelect = QSLT_MGNT;
1238 QueueSelect = QSLT_BEACON;
1242 QueueSelect = QSLT_CMD;
1247 RT_TRACE(COMP_ERR, "Impossible Queue Selection: %d\n", QueueID);
1253 static u8 MRateToHwRate8190Pci(u8 rate)
1255 u8 ret = DESC90_RATE1M;
1258 case MGN_1M: ret = DESC90_RATE1M; break;
1259 case MGN_2M: ret = DESC90_RATE2M; break;
1260 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1261 case MGN_11M: ret = DESC90_RATE11M; break;
1262 case MGN_6M: ret = DESC90_RATE6M; break;
1263 case MGN_9M: ret = DESC90_RATE9M; break;
1264 case MGN_12M: ret = DESC90_RATE12M; break;
1265 case MGN_18M: ret = DESC90_RATE18M; break;
1266 case MGN_24M: ret = DESC90_RATE24M; break;
1267 case MGN_36M: ret = DESC90_RATE36M; break;
1268 case MGN_48M: ret = DESC90_RATE48M; break;
1269 case MGN_54M: ret = DESC90_RATE54M; break;
1271 // HT rate since here
1272 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1273 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1274 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1275 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1276 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1277 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1278 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1279 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1280 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1281 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1282 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1283 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1284 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1285 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1286 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1287 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1288 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1296 static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
1300 tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
1302 if(TxHT==1 && TxRate != DESC90_RATEMCS15)
1309 * The tx procedure is just as following,
1310 * skb->cb will contain all the following information,
1311 * priority, morefrag, rate, &dev.
1313 short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
1315 struct r8192_priv *priv = ieee80211_priv(dev);
1316 struct rtl8192_tx_ring *ring;
1317 unsigned long flags;
1318 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1319 tx_desc_819x_pci *pdesc = NULL;
1320 TX_FWINFO_8190PCI *pTxFwInfo = NULL;
1322 bool multi_addr = false, broad_addr = false, uni_addr = false;
1323 u8 *pda_addr = NULL;
1326 if (priv->bdisable_nic) {
1327 RT_TRACE(COMP_ERR, "Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n",
1328 skb->len, tcb_desc->queue_index);
1333 priv->ieee80211->bAwakePktSent = true;
1336 mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE);
1338 /* collect the tx packets statitcs */
1339 pda_addr = ((u8 *)skb->data) + sizeof(TX_FWINFO_8190PCI);
1340 if (is_multicast_ether_addr(pda_addr))
1342 else if (is_broadcast_ether_addr(pda_addr))
1348 priv->stats.txbytesunicast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI);
1350 /* fill tx firmware */
1351 pTxFwInfo = (PTX_FWINFO_8190PCI)skb->data;
1352 memset(pTxFwInfo, 0, sizeof(TX_FWINFO_8190PCI));
1353 pTxFwInfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
1354 pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)tcb_desc->data_rate);
1355 pTxFwInfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1356 pTxFwInfo->Short = QueryIsShort(pTxFwInfo->TxHT, pTxFwInfo->TxRate, tcb_desc);
1358 /* Aggregation related */
1359 if (tcb_desc->bAMPDUEnable) {
1360 pTxFwInfo->AllowAggregation = 1;
1361 pTxFwInfo->RxMF = tcb_desc->ampdu_factor;
1362 pTxFwInfo->RxAMD = tcb_desc->ampdu_density;
1364 pTxFwInfo->AllowAggregation = 0;
1365 pTxFwInfo->RxMF = 0;
1366 pTxFwInfo->RxAMD = 0;
1369 /* Protection mode related */
1370 pTxFwInfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
1371 pTxFwInfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
1372 pTxFwInfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
1373 pTxFwInfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
1374 pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1375 pTxFwInfo->RtsBandwidth = 0;
1376 pTxFwInfo->RtsSubcarrier = tcb_desc->RTSSC;
1377 pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) : (tcb_desc->bRTSUseShortGI? 1 : 0);
1379 /* Set Bandwidth and sub-channel settings. */
1380 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
1381 if (tcb_desc->bPacketBW) {
1382 pTxFwInfo->TxBandwidth = 1;
1384 pTxFwInfo->TxSubCarrier = 3;
1386 /* use duplicated mode */
1387 pTxFwInfo->TxSubCarrier = 0;
1390 pTxFwInfo->TxBandwidth = 0;
1391 pTxFwInfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1394 pTxFwInfo->TxBandwidth = 0;
1395 pTxFwInfo->TxSubCarrier = 0;
1398 spin_lock_irqsave(&priv->irq_th_lock, flags);
1399 ring = &priv->tx_ring[tcb_desc->queue_index];
1400 if (tcb_desc->queue_index != BEACON_QUEUE)
1401 idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries;
1405 pdesc = &ring->desc[idx];
1406 if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
1407 RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d,idx = %d,%x",
1408 tcb_desc->queue_index, ring->idx, idx, skb->len);
1409 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1413 /* fill tx descriptor */
1414 memset(pdesc, 0, 12);
1419 pdesc->Offset = sizeof(TX_FWINFO_8190PCI) + 8; /* We must add 8!! */
1420 pdesc->PktSize = (u16)skb->len-sizeof(TX_FWINFO_8190PCI);
1423 pdesc->SecCAMID = 0;
1424 pdesc->RATid = tcb_desc->RATRIndex;
1427 pdesc->SecType = 0x0;
1428 if (tcb_desc->bHwSec) {
1429 switch (priv->ieee80211->pairwise_key_type) {
1430 case KEY_TYPE_WEP40:
1431 case KEY_TYPE_WEP104:
1432 pdesc->SecType = 0x1;
1436 pdesc->SecType = 0x2;
1440 pdesc->SecType = 0x3;
1444 pdesc->SecType = 0x0;
1453 pdesc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1454 pdesc->TxFWInfoSize = sizeof(TX_FWINFO_8190PCI);
1456 pdesc->DISFB = tcb_desc->bTxDisableRateFallBack;
1457 pdesc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1459 pdesc->FirstSeg = 1;
1461 pdesc->TxBufferSize = skb->len;
1463 pdesc->TxBuffAddr = cpu_to_le32(mapping);
1464 __skb_queue_tail(&ring->queue, skb);
1466 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
1467 dev->trans_start = jiffies;
1468 write_nic_word(dev, TPPoll, 0x01<<tcb_desc->queue_index);
1472 static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
1474 struct r8192_priv *priv = ieee80211_priv(dev);
1475 rx_desc_819x_pci *entry = NULL;
1478 priv->rx_ring = pci_alloc_consistent(priv->pdev,
1479 sizeof(*priv->rx_ring) * priv->rxringcount, &priv->rx_ring_dma);
1481 if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) {
1482 RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n");
1486 memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * priv->rxringcount);
1489 for (i = 0; i < priv->rxringcount; i++) {
1490 struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize);
1491 dma_addr_t *mapping;
1492 entry = &priv->rx_ring[i];
1495 priv->rx_buf[i] = skb;
1496 mapping = (dma_addr_t *)skb->cb;
1497 *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb),
1498 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
1500 entry->BufferAddress = cpu_to_le32(*mapping);
1502 entry->Length = priv->rxbuffersize;
1510 static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
1511 unsigned int prio, unsigned int entries)
1513 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1514 tx_desc_819x_pci *ring;
1518 ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma);
1519 if (!ring || (unsigned long)ring & 0xFF) {
1520 RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio);
1524 memset(ring, 0, sizeof(*ring)*entries);
1525 priv->tx_ring[prio].desc = ring;
1526 priv->tx_ring[prio].dma = dma;
1527 priv->tx_ring[prio].idx = 0;
1528 priv->tx_ring[prio].entries = entries;
1529 skb_queue_head_init(&priv->tx_ring[prio].queue);
1531 for (i = 0; i < entries; i++)
1532 ring[i].NextDescAddress =
1533 cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring));
1538 static short rtl8192_pci_initdescring(struct net_device *dev)
1542 struct r8192_priv *priv = ieee80211_priv(dev);
1544 ret = rtl8192_alloc_rx_desc_ring(dev);
1548 /* general process for other queue */
1549 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1550 ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
1552 goto err_free_rings;
1558 rtl8192_free_rx_ring(dev);
1559 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
1560 if (priv->tx_ring[i].desc)
1561 rtl8192_free_tx_ring(dev, i);
1565 static void rtl8192_pci_resetdescring(struct net_device *dev)
1567 struct r8192_priv *priv = ieee80211_priv(dev);
1570 /* force the rx_idx to the first one */
1572 rx_desc_819x_pci *entry = NULL;
1573 for (i = 0; i < priv->rxringcount; i++) {
1574 entry = &priv->rx_ring[i];
1580 /* after reset, release previous pending packet, and force the
1581 * tx idx to the first one */
1582 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
1583 if (priv->tx_ring[i].desc) {
1584 struct rtl8192_tx_ring *ring = &priv->tx_ring[i];
1586 while (skb_queue_len(&ring->queue)) {
1587 tx_desc_819x_pci *entry = &ring->desc[ring->idx];
1588 struct sk_buff *skb = __skb_dequeue(&ring->queue);
1590 pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr),
1591 skb->len, PCI_DMA_TODEVICE);
1593 ring->idx = (ring->idx + 1) % ring->entries;
1600 static void rtl8192_link_change(struct net_device *dev)
1602 struct r8192_priv *priv = ieee80211_priv(dev);
1603 struct ieee80211_device* ieee = priv->ieee80211;
1604 //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval);
1605 if (ieee->state == IEEE80211_LINKED)
1607 rtl8192_net_update(dev);
1608 rtl8192_update_ratr_table(dev);
1610 //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
1611 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
1612 EnableHWSecurityConfig8192(dev);
1617 write_nic_byte(dev, 0x173, 0);
1619 /*update timing params*/
1620 //rtl8192_set_chan(dev, priv->chan);
1622 rtl8192_update_msr(dev);
1624 // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have
1625 // // To set CBSSID bit when link with any AP or STA.
1626 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
1629 reg = read_nic_dword(dev, RCR);
1630 if (priv->ieee80211->state == IEEE80211_LINKED)
1631 priv->ReceiveConfig = reg |= RCR_CBSSID;
1633 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
1634 write_nic_dword(dev, RCR, reg);
1639 static const struct ieee80211_qos_parameters def_qos_parameters = {
1640 {3,3,3,3},/* cw_min */
1641 {7,7,7,7},/* cw_max */
1642 {2,2,2,2},/* aifs */
1643 {0,0,0,0},/* flags */
1644 {0,0,0,0} /* tx_op_limit */
1647 static void rtl8192_update_beacon(struct work_struct * work)
1649 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
1650 struct net_device *dev = priv->ieee80211->dev;
1651 struct ieee80211_device* ieee = priv->ieee80211;
1652 struct ieee80211_network* net = &ieee->current_network;
1654 if (ieee->pHTInfo->bCurrentHTSupport)
1655 HTUpdateSelfAndPeerSetting(ieee, net);
1656 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
1657 rtl8192_update_cap(dev, net->capability);
1661 * background support to run QoS activate functionality
1663 static const int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
1664 static void rtl8192_qos_activate(struct work_struct * work)
1666 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
1667 struct net_device *dev = priv->ieee80211->dev;
1668 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
1669 u8 mode = priv->ieee80211->current_network.mode;
1674 mutex_lock(&priv->mutex);
1675 if(priv->ieee80211->state != IEEE80211_LINKED)
1677 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
1678 /* It better set slot time at first */
1679 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
1680 /* update the ac parameter to related registers */
1681 for(i = 0; i < QOS_QUEUE_NUM; i++) {
1682 //Mode G/A: slotTimeTimer = 9; Mode B: 20
1683 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
1684 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
1685 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
1686 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
1687 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
1688 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
1689 //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
1693 mutex_unlock(&priv->mutex);
1696 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
1698 struct ieee80211_network *network)
1701 u32 size = sizeof(struct ieee80211_qos_parameters);
1703 if(priv->ieee80211->state !=IEEE80211_LINKED)
1706 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
1709 if (network->flags & NETWORK_HAS_QOS_MASK) {
1710 if (active_network &&
1711 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
1712 network->qos_data.active = network->qos_data.supported;
1714 if ((network->qos_data.active == 1) && (active_network == 1) &&
1715 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
1716 (network->qos_data.old_param_count !=
1717 network->qos_data.param_count)) {
1718 network->qos_data.old_param_count =
1719 network->qos_data.param_count;
1720 queue_work(priv->priv_wq, &priv->qos_activate);
1721 RT_TRACE (COMP_QOS, "QoS parameters change call "
1725 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
1726 &def_qos_parameters, size);
1728 if ((network->qos_data.active == 1) && (active_network == 1)) {
1729 queue_work(priv->priv_wq, &priv->qos_activate);
1730 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
1732 network->qos_data.active = 0;
1733 network->qos_data.supported = 0;
1739 /* handle manage frame frame beacon and probe response */
1740 static int rtl8192_handle_beacon(struct net_device * dev,
1741 struct ieee80211_beacon * beacon,
1742 struct ieee80211_network * network)
1744 struct r8192_priv *priv = ieee80211_priv(dev);
1746 rtl8192_qos_handle_probe_response(priv,1,network);
1748 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
1754 * handling the beaconing responses. if we get different QoS setting
1755 * off the network from the associated setting, adjust the QoS setting
1757 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
1758 struct ieee80211_network *network)
1761 unsigned long flags;
1762 u32 size = sizeof(struct ieee80211_qos_parameters);
1763 int set_qos_param = 0;
1765 if ((priv == NULL) || (network == NULL))
1768 if (priv->ieee80211->state != IEEE80211_LINKED)
1771 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
1774 spin_lock_irqsave(&priv->ieee80211->lock, flags);
1775 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
1776 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
1777 &network->qos_data.parameters,
1778 sizeof(struct ieee80211_qos_parameters));
1779 priv->ieee80211->current_network.qos_data.active = 1;
1781 /* update qos parameter for current network */
1782 priv->ieee80211->current_network.qos_data.old_param_count =
1783 priv->ieee80211->current_network.qos_data.param_count;
1784 priv->ieee80211->current_network.qos_data.param_count =
1785 network->qos_data.param_count;
1788 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
1789 &def_qos_parameters, size);
1790 priv->ieee80211->current_network.qos_data.active = 0;
1791 priv->ieee80211->current_network.qos_data.supported = 0;
1795 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
1797 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __FUNCTION__,
1798 network->flags, priv->ieee80211->current_network.qos_data.active);
1799 if (set_qos_param == 1)
1800 queue_work(priv->priv_wq, &priv->qos_activate);
1806 static int rtl8192_handle_assoc_response(struct net_device *dev,
1807 struct ieee80211_assoc_response_frame *resp,
1808 struct ieee80211_network *network)
1810 struct r8192_priv *priv = ieee80211_priv(dev);
1811 rtl8192_qos_association_resp(priv, network);
1816 /* updateRATRTabel for MCS only. Basic rate is not implemented. */
1817 static void rtl8192_update_ratr_table(struct net_device* dev)
1819 struct r8192_priv* priv = ieee80211_priv(dev);
1820 struct ieee80211_device* ieee = priv->ieee80211;
1821 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
1825 rtl8192_config_rate(dev, (u16*)(&ratr_value));
1826 ratr_value |= (*(u16*)(pMcsRate)) << 12;
1831 ratr_value &= 0x00000FF0;
1834 ratr_value &= 0x0000000F;
1837 ratr_value &= 0x00000FF7;
1841 if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
1842 ratr_value &= 0x0007F007;
1844 if (priv->rf_type == RF_1T2R)
1845 ratr_value &= 0x000FF007;
1847 ratr_value &= 0x0F81F007;
1853 ratr_value &= 0x0FFFFFFF;
1854 if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
1855 ratr_value |= 0x80000000;
1856 }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
1857 ratr_value |= 0x80000000;
1859 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
1860 write_nic_byte(dev, UFWP, 1);
1863 static bool GetNmodeSupportBySecCfg8190Pci(struct net_device*dev)
1865 struct r8192_priv *priv = ieee80211_priv(dev);
1866 struct ieee80211_device *ieee = priv->ieee80211;
1868 return !(ieee->rtllib_ap_sec_type &&
1869 (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP)));
1872 static void rtl8192_refresh_supportrate(struct r8192_priv* priv)
1874 struct ieee80211_device* ieee = priv->ieee80211;
1875 //we donot consider set support rate for ABG mode, only HT MCS rate is set here.
1876 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
1878 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
1881 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
1884 static u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
1886 struct r8192_priv *priv = ieee80211_priv(dev);
1888 switch(priv->rf_chip)
1893 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
1896 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
1899 ret = WIRELESS_MODE_B;
1905 static void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
1907 struct r8192_priv *priv = ieee80211_priv(dev);
1908 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
1910 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
1912 if(bSupportMode & WIRELESS_MODE_N_24G)
1914 wireless_mode = WIRELESS_MODE_N_24G;
1916 else if(bSupportMode & WIRELESS_MODE_N_5G)
1918 wireless_mode = WIRELESS_MODE_N_5G;
1920 else if((bSupportMode & WIRELESS_MODE_A))
1922 wireless_mode = WIRELESS_MODE_A;
1924 else if((bSupportMode & WIRELESS_MODE_G))
1926 wireless_mode = WIRELESS_MODE_G;
1928 else if((bSupportMode & WIRELESS_MODE_B))
1930 wireless_mode = WIRELESS_MODE_B;
1933 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
1934 wireless_mode = WIRELESS_MODE_B;
1937 priv->ieee80211->mode = wireless_mode;
1939 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
1940 priv->ieee80211->pHTInfo->bEnableHT = 1;
1942 priv->ieee80211->pHTInfo->bEnableHT = 0;
1943 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
1944 rtl8192_refresh_supportrate(priv);
1947 static bool GetHalfNmodeSupportByAPs819xPci(struct net_device* dev)
1949 struct r8192_priv* priv = ieee80211_priv(dev);
1950 struct ieee80211_device* ieee = priv->ieee80211;
1952 return ieee->bHalfWirelessN24GMode;
1955 short rtl8192_is_tx_queue_empty(struct net_device *dev)
1958 struct r8192_priv *priv = ieee80211_priv(dev);
1959 for (i=0; i<=MGNT_QUEUE; i++)
1961 if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) )
1963 if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){
1964 printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue));
1971 static void rtl8192_hw_sleep_down(struct net_device *dev)
1973 struct r8192_priv *priv = ieee80211_priv(dev);
1974 unsigned long flags = 0;
1976 spin_lock_irqsave(&priv->rf_ps_lock,flags);
1977 if (priv->RFChangeInProgress) {
1978 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
1979 RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n");
1980 printk("rtl8192_hw_sleep_down(): RF Change in progress!\n");
1983 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
1985 MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
1988 static void rtl8192_hw_sleep_wq (struct work_struct *work)
1990 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
1991 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
1992 struct net_device *dev = ieee->dev;
1994 rtl8192_hw_sleep_down(dev);
1997 static void rtl8192_hw_wakeup(struct net_device* dev)
1999 struct r8192_priv *priv = ieee80211_priv(dev);
2000 unsigned long flags = 0;
2002 spin_lock_irqsave(&priv->rf_ps_lock,flags);
2003 if (priv->RFChangeInProgress) {
2004 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2005 RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n");
2006 printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n");
2007 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
2010 spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
2012 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);
2015 void rtl8192_hw_wakeup_wq (struct work_struct *work)
2017 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
2018 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
2019 struct net_device *dev = ieee->dev;
2020 rtl8192_hw_wakeup(dev);
2024 #define MIN_SLEEP_TIME 50
2025 #define MAX_SLEEP_TIME 10000
2026 static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
2028 struct r8192_priv *priv = ieee80211_priv(dev);
2031 unsigned long flags;
2033 spin_lock_irqsave(&priv->ps_lock,flags);
2035 // Writing HW register with 0 equals to disable
2036 // the timer, that is not really what we want
2038 tl -= MSECS(8+16+7);
2040 // If the interval in witch we are requested to sleep is too
2041 // short then give up and remain awake
2042 // when we sleep after send null frame, the timer will be too short to sleep.
2044 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2045 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2046 spin_unlock_irqrestore(&priv->ps_lock,flags);
2047 printk("too short to sleep::%x, %x, %lx\n",tl, rb, MSECS(MIN_SLEEP_TIME));
2051 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
2052 ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
2053 ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
2054 printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME));
2055 spin_unlock_irqrestore(&priv->ps_lock,flags);
2059 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
2060 queue_delayed_work(priv->ieee80211->wq,
2061 &priv->ieee80211->hw_wakeup_wq,tmp);
2062 //PowerSave not supported when kernel version less 2.6.20
2064 queue_delayed_work(priv->ieee80211->wq,
2065 (void *)&priv->ieee80211->hw_sleep_wq,0);
2066 spin_unlock_irqrestore(&priv->ps_lock,flags);
2070 static void rtl8192_init_priv_variable(struct net_device* dev)
2072 struct r8192_priv *priv = ieee80211_priv(dev);
2074 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
2076 // Default Halt the NIC if RF is OFF.
2077 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC;
2078 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_CLK_REQ;
2079 pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM;
2080 pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM;
2081 pPSC->bLeisurePs = true;
2082 pPSC->RegMaxLPSAwakeIntvl = 5;
2083 priv->bHwRadioOff = false;
2085 priv->being_init_adapter = false;
2086 priv->txringcount = 64;//32;
2087 priv->rxbuffersize = 9100;//2048;//1024;
2088 priv->rxringcount = MAX_RX_COUNT;//64;
2089 priv->irq_enabled=0;
2090 priv->card_8192 = NIC_8192E;
2091 priv->rx_skb_complete = 1;
2092 priv->chan = 1; //set to channel 1
2093 priv->RegWirelessMode = WIRELESS_MODE_AUTO;
2094 priv->RegChannelPlan = 0xf;
2095 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
2096 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2097 priv->ieee80211->ieee_up=0;
2098 priv->retry_rts = DEFAULT_RETRY_RTS;
2099 priv->retry_data = DEFAULT_RETRY_DATA;
2100 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
2101 priv->ieee80211->rate = 110; //11 mbps
2102 priv->ieee80211->short_slot = 1;
2103 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
2104 priv->bcck_in_ch14 = false;
2105 priv->CCKPresentAttentuation = 0;
2106 priv->rfa_txpowertrackingindex = 0;
2107 priv->rfc_txpowertrackingindex = 0;
2109 //added by amy for silent reset
2110 priv->ResetProgress = RESET_TYPE_NORESET;
2111 priv->bForcedSilentReset = 0;
2112 priv->bDisableNormalResetCheck = false;
2113 priv->force_reset = false;
2114 //added by amy for power save
2115 priv->ieee80211->RfOffReason = 0;
2116 priv->RFChangeInProgress = false;
2117 priv->bHwRfOffAction = 0;
2118 priv->SetRFPowerStateInProgress = false;
2119 priv->ieee80211->PowerSaveControl.bInactivePs = true;
2120 priv->ieee80211->PowerSaveControl.bIPSModeBackup = false;
2122 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2123 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2124 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2125 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2126 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;/* |
2127 IEEE_SOFTMAC_BEACONS;*///added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE;
2129 priv->ieee80211->active_scan = 1;
2130 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
2131 priv->ieee80211->host_encrypt = 1;
2132 priv->ieee80211->host_decrypt = 1;
2133 //priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
2134 //priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
2135 priv->ieee80211->start_send_beacons = rtl8192_start_beacon;//+by david 081107
2136 priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;//+by david 081107
2137 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
2138 priv->ieee80211->set_chan = rtl8192_set_chan;
2139 priv->ieee80211->link_change = rtl8192_link_change;
2140 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
2141 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
2142 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
2143 priv->ieee80211->init_wmmparam_flag = 0;
2144 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2145 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
2146 priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI);
2147 priv->ieee80211->qos_support = 1;
2148 priv->ieee80211->dot11PowerSaveMode = 0;
2150 // priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
2151 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
2152 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
2153 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
2155 priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup;
2156 // priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack;
2157 priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep;
2158 priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
2160 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci;
2161 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
2162 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci;
2165 priv->ieee80211->InitialGainHandler = InitialGain819xPci;
2168 priv->ieee80211->ieee80211_ips_leave_wq = ieee80211_ips_leave_wq;
2169 priv->ieee80211->ieee80211_ips_leave = ieee80211_ips_leave;
2172 priv->ieee80211->LeisurePSLeave = LeisurePSLeave;
2175 priv->ieee80211->SetHwRegHandler = rtl8192e_SetHwReg;
2176 priv->ieee80211->rtllib_ap_sec_type = rtl8192e_ap_sec_type;
2178 priv->ShortRetryLimit = 0x30;
2179 priv->LongRetryLimit = 0x30;
2181 priv->ReceiveConfig = RCR_ADD3 |
2182 RCR_AMF | RCR_ADF | //accept management/data
2183 RCR_AICV | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2184 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2185 RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) |
2186 ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT;
2188 priv->irq_mask = (u32)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK |
2189 IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK |
2190 IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW |
2191 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2193 priv->pFirmware = vzalloc(sizeof(rt_firmware));
2195 /* rx related queue */
2196 skb_queue_head_init(&priv->skb_queue);
2198 /* Tx related queue */
2199 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2200 skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
2202 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
2203 skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
2205 priv->rf_set_chan = rtl8192_phy_SwChnl;
2208 static void rtl8192_init_priv_lock(struct r8192_priv* priv)
2210 spin_lock_init(&priv->tx_lock);
2211 spin_lock_init(&priv->irq_th_lock);
2212 spin_lock_init(&priv->rf_ps_lock);
2213 spin_lock_init(&priv->ps_lock);
2214 sema_init(&priv->wx_sem,1);
2215 sema_init(&priv->rf_sem,1);
2216 mutex_init(&priv->mutex);
2219 /* init tasklet and wait_queue here */
2220 #define DRV_NAME "wlan0"
2221 static void rtl8192_init_priv_task(struct net_device* dev)
2223 struct r8192_priv *priv = ieee80211_priv(dev);
2225 priv->priv_wq = create_workqueue(DRV_NAME);
2228 INIT_WORK(&priv->ieee80211->ips_leave_wq, (void*)IPSLeave_wq);
2231 // INIT_WORK(&priv->reset_wq, (void(*)(void*)) rtl8192_restart);
2232 INIT_WORK(&priv->reset_wq, rtl8192_restart);
2233 // INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
2234 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
2235 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
2236 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
2237 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
2238 //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem);
2239 //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem);
2240 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
2241 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq);
2242 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq);
2244 tasklet_init(&priv->irq_rx_tasklet,
2245 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
2246 (unsigned long)priv);
2247 tasklet_init(&priv->irq_tx_tasklet,
2248 (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
2249 (unsigned long)priv);
2250 tasklet_init(&priv->irq_prepare_beacon_tasklet,
2251 (void(*)(unsigned long))rtl8192_prepare_beacon,
2252 (unsigned long)priv);
2255 static void rtl8192_get_eeprom_size(struct net_device* dev)
2258 struct r8192_priv *priv = ieee80211_priv(dev);
2259 RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__);
2260 curCR = read_nic_dword(dev, EPROM_CMD);
2261 RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR);
2262 //whether need I consider BIT5?
2263 priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EPROM_93c56 : EPROM_93c46;
2264 RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
2268 * used to swap endian. as ntohl & htonl are not
2269 * neccessary to swap endian, so use this instead.
2271 static inline u16 endian_swap(u16* data)
2274 *data = (tmp >> 8) | (tmp << 8);
2279 * Adapter->EEPROMAddressSize should be set before this function call.
2280 * EEPROM address size can be got through GetEEPROMSize8185()
2282 static void rtl8192_read_eeprom_info(struct net_device* dev)
2284 struct r8192_priv *priv = ieee80211_priv(dev);
2288 u8 ICVer8192, ICVer8256;
2290 u16 i,usValue, IC_Version;
2294 u8 EepromTxPower[100];
2296 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01};
2297 RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n");
2300 // TODO: I don't know if we need to apply EF function to EEPROM read function
2302 //2 Read EEPROM ID to make sure autoload is success
2303 EEPROMId = eprom_read(dev, 0);
2304 if( EEPROMId != RTL8190_EEPROM_ID )
2306 RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID);
2307 priv->AutoloadFailFlag=true;
2311 priv->AutoloadFailFlag=false;
2315 // Assign Chip Version ID
2317 // Read IC Version && Channel Plan
2318 if(!priv->AutoloadFailFlag)
2321 priv->eeprom_vid = eprom_read(dev, (EEPROM_VID >> 1));
2322 priv->eeprom_did = eprom_read(dev, (EEPROM_DID >> 1));
2324 usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8 ;
2325 priv->eeprom_CustomerID = (u8)( usValue & 0xff);
2326 usValue = eprom_read(dev, (EEPROM_ICVersion_ChannelPlan>>1));
2327 priv->eeprom_ChannelPlan = usValue&0xff;
2328 IC_Version = ((usValue&0xff00)>>8);
2331 priv->card_8192_version = (VERSION_8190)(IC_Version);
2334 ICVer8192 = (IC_Version&0xf); //bit0~3; 1:A cut, 2:B cut, 3:C cut...
2335 ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut...
2336 RT_TRACE(COMP_INIT, "\nICVer8192 = 0x%x\n", ICVer8192);
2337 RT_TRACE(COMP_INIT, "\nICVer8256 = 0x%x\n", ICVer8256);
2338 if(ICVer8192 == 0x2) //B-cut
2340 if(ICVer8256 == 0x5) //E-cut
2341 priv->card_8192_version= VERSION_8190_BE;
2345 switch(priv->card_8192_version)
2347 case VERSION_8190_BD:
2348 case VERSION_8190_BE:
2351 priv->card_8192_version = VERSION_8190_BD;
2354 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", priv->card_8192_version);
2358 priv->card_8192_version = VERSION_8190_BD;
2359 priv->eeprom_vid = 0;
2360 priv->eeprom_did = 0;
2361 priv->eeprom_CustomerID = 0;
2362 priv->eeprom_ChannelPlan = 0;
2363 RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", 0xff);
2366 RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
2367 RT_TRACE(COMP_INIT, "EEPROM DID = 0x%4x\n", priv->eeprom_did);
2368 RT_TRACE(COMP_INIT,"EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID);
2370 //2 Read Permanent MAC address
2371 if(!priv->AutoloadFailFlag)
2373 for(i = 0; i < 6; i += 2)
2375 usValue = eprom_read(dev, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1));
2376 *(u16*)(&dev->dev_addr[i]) = usValue;
2379 // when auto load failed, the last address byte set to be a random one.
2380 // added by david woo.2007/11/7
2381 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
2384 RT_TRACE(COMP_INIT, "Permanent Address = %pM\n", dev->dev_addr);
2386 //2 TX Power Check EEPROM Fail or not
2387 if(priv->card_8192_version > VERSION_8190_BD) {
2388 priv->bTXPowerDataReadFromEEPORM = true;
2390 priv->bTXPowerDataReadFromEEPORM = false;
2393 // 2007/11/15 MH 8190PCI Default=2T4R, 8192PCIE default=1T2R
2394 priv->rf_type = RTL819X_DEFAULT_RF_TYPE;
2396 if(priv->card_8192_version > VERSION_8190_BD)
2398 // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate.
2399 if(!priv->AutoloadFailFlag)
2401 tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff>>1))) & 0xff;
2402 priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; // bit[3:0]
2404 if (tempval&0x80) //RF-indication, bit[7]
2405 priv->rf_type = RF_1T2R;
2407 priv->rf_type = RF_2T4R;
2411 priv->EEPROMLegacyHTTxPowerDiff = EEPROM_Default_LegacyHTTxPowerDiff;
2413 RT_TRACE(COMP_INIT, "EEPROMLegacyHTTxPowerDiff = %d\n",
2414 priv->EEPROMLegacyHTTxPowerDiff);
2416 // Read ThermalMeter from EEPROM
2417 if(!priv->AutoloadFailFlag)
2419 priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8);
2423 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2425 RT_TRACE(COMP_INIT, "ThermalMeter = %d\n", priv->EEPROMThermalMeter);
2426 //vivi, for tx power track
2427 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
2429 if(priv->epromtype == EPROM_93c46)
2431 // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM
2432 if(!priv->AutoloadFailFlag)
2434 usValue = eprom_read(dev, (EEPROM_TxPwDiff_CrystalCap>>1));
2435 priv->EEPROMAntPwDiff = (usValue&0x0fff);
2436 priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12);
2440 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2441 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2443 RT_TRACE(COMP_INIT, "EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2444 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2447 // Get per-channel Tx Power Level
2449 for(i=0; i<14; i+=2)
2451 if(!priv->AutoloadFailFlag)
2453 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) );
2457 usValue = EEPROM_Default_TxPower;
2459 *((u16*)(&priv->EEPROMTxPowerLevelCCK[i])) = usValue;
2460 RT_TRACE(COMP_INIT,"CCK Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK[i]);
2461 RT_TRACE(COMP_INIT, "CCK Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelCCK[i+1]);
2463 for(i=0; i<14; i+=2)
2465 if(!priv->AutoloadFailFlag)
2467 usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) );
2471 usValue = EEPROM_Default_TxPower;
2473 *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[i])) = usValue;
2474 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelOFDM24G[i]);
2475 RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelOFDM24G[i+1]);
2478 else if(priv->epromtype== EPROM_93c56)
2481 // Read CrystalCap from EEPROM
2482 if(!priv->AutoloadFailFlag)
2484 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2485 priv->EEPROMCrystalCap = (u8)(((eprom_read(dev, (EEPROM_C56_CrystalCap>>1))) & 0xf000)>>12);
2489 priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff;
2490 priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap;
2492 RT_TRACE(COMP_INIT,"EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff);
2493 RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap);
2495 // Get Tx Power Level by Channel
2496 if(!priv->AutoloadFailFlag)
2498 // Read Tx power of Channel 1 ~ 14 from EEPROM.
2499 for(i = 0; i < 12; i+=2)
2502 offset = EEPROM_C56_RfA_CCK_Chnl1_TxPwIndex + i;
2504 offset = EEPROM_C56_RfC_CCK_Chnl1_TxPwIndex + i - 6;
2505 usValue = eprom_read(dev, (offset>>1));
2506 *((u16*)(&EepromTxPower[i])) = usValue;
2509 for(i = 0; i < 12; i++)
2512 priv->EEPROMRfACCKChnl1TxPwLevel[i] = EepromTxPower[i];
2513 else if ((i >=3 )&&(i <= 5))
2514 priv->EEPROMRfAOfdmChnlTxPwLevel[i-3] = EepromTxPower[i];
2515 else if ((i >=6 )&&(i <= 8))
2516 priv->EEPROMRfCCCKChnl1TxPwLevel[i-6] = EepromTxPower[i];
2518 priv->EEPROMRfCOfdmChnlTxPwLevel[i-9] = EepromTxPower[i];
2523 priv->EEPROMRfACCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2524 priv->EEPROMRfACCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2525 priv->EEPROMRfACCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2527 priv->EEPROMRfAOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2528 priv->EEPROMRfAOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2529 priv->EEPROMRfAOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2531 priv->EEPROMRfCCCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2532 priv->EEPROMRfCCCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2533 priv->EEPROMRfCCCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2535 priv->EEPROMRfCOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel;
2536 priv->EEPROMRfCOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel;
2537 priv->EEPROMRfCOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel;
2539 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[0]);
2540 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[1]);
2541 RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[2]);
2542 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[0]);
2543 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[1]);
2544 RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[2]);
2545 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[0]);
2546 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[1]);
2547 RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[2]);
2548 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[0]);
2549 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[1]);
2550 RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[2]);
2555 // Update HAL variables.
2557 if(priv->epromtype == EPROM_93c46)
2561 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK[i];
2562 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[i];
2564 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
2565 // Antenna B gain offset to antenna A, bit0~3
2566 priv->AntennaTxPwDiff[0] = (priv->EEPROMAntPwDiff & 0xf);
2567 // Antenna C gain offset to antenna A, bit4~7
2568 priv->AntennaTxPwDiff[1] = ((priv->EEPROMAntPwDiff & 0xf0)>>4);
2569 // Antenna D gain offset to antenna A, bit8~11
2570 priv->AntennaTxPwDiff[2] = ((priv->EEPROMAntPwDiff & 0xf00)>>8);
2571 // CrystalCap, bit12~15
2572 priv->CrystalCap = priv->EEPROMCrystalCap;
2573 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2574 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
2575 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
2577 else if(priv->epromtype == EPROM_93c56)
2579 //char cck_pwr_diff_a=0, cck_pwr_diff_c=0;
2581 //cck_pwr_diff_a = pHalData->EEPROMRfACCKChnl7TxPwLevel - pHalData->EEPROMRfAOfdmChnlTxPwLevel[1];
2582 //cck_pwr_diff_c = pHalData->EEPROMRfCCCKChnl7TxPwLevel - pHalData->EEPROMRfCOfdmChnlTxPwLevel[1];
2583 for(i=0; i<3; i++) // channel 1~3 use the same Tx Power Level.
2585 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[0];
2586 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[0];
2587 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[0];
2588 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[0];
2590 for(i=3; i<9; i++) // channel 4~9 use the same Tx Power Level
2592 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[1];
2593 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[1];
2594 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[1];
2595 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[1];
2597 for(i=9; i<14; i++) // channel 10~14 use the same Tx Power Level
2599 priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[2];
2600 priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[2];
2601 priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[2];
2602 priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[2];
2605 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_A[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_A[i]);
2607 RT_TRACE(COMP_INIT,"priv->TxPowerLevelOFDM24G_A[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_A[i]);
2609 RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_C[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_C[i]);
2611 RT_TRACE(COMP_INIT, "priv->TxPowerLevelOFDM24G_C[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_C[i]);
2612 priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff;
2613 priv->AntennaTxPwDiff[0] = 0;
2614 priv->AntennaTxPwDiff[1] = 0;
2615 priv->AntennaTxPwDiff[2] = 0;
2616 priv->CrystalCap = priv->EEPROMCrystalCap;
2617 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2618 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf);
2619 priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4);
2623 if(priv->rf_type == RF_1T2R)
2625 RT_TRACE(COMP_INIT, "\n1T2R config\n");
2627 else if (priv->rf_type == RF_2T4R)
2629 RT_TRACE(COMP_INIT, "\n2T4R config\n");
2632 // 2008/01/16 MH We can only know RF type in the function. So we have to init
2633 // DIG RATR table again.
2634 init_rate_adaptive(dev);
2636 //1 Make a copy for following variables and we can change them if we want
2638 priv->rf_chip= RF_8256;
2640 if(priv->RegChannelPlan == 0xf)
2642 priv->ChannelPlan = priv->eeprom_ChannelPlan;
2646 priv->ChannelPlan = priv->RegChannelPlan;
2650 // Used PID and DID to Set CustomerID
2652 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304 )
2654 priv->CustomerID = RT_CID_DLINK;
2657 switch(priv->eeprom_CustomerID)
2659 case EEPROM_CID_DEFAULT:
2660 priv->CustomerID = RT_CID_DEFAULT;
2662 case EEPROM_CID_CAMEO:
2663 priv->CustomerID = RT_CID_819x_CAMEO;
2665 case EEPROM_CID_RUNTOP:
2666 priv->CustomerID = RT_CID_819x_RUNTOP;
2668 case EEPROM_CID_NetCore:
2669 priv->CustomerID = RT_CID_819x_Netcore;
2671 case EEPROM_CID_TOSHIBA: // Merge by Jacken, 2008/01/31
2672 priv->CustomerID = RT_CID_TOSHIBA;
2673 if(priv->eeprom_ChannelPlan&0x80)
2674 priv->ChannelPlan = priv->eeprom_ChannelPlan&0x7f;
2676 priv->ChannelPlan = 0x0;
2677 RT_TRACE(COMP_INIT, "Toshiba ChannelPlan = 0x%x\n",
2680 case EEPROM_CID_Nettronix:
2681 priv->CustomerID = RT_CID_Nettronix;
2683 case EEPROM_CID_Pronet:
2684 priv->CustomerID = RT_CID_PRONET;
2686 case EEPROM_CID_DLINK:
2687 priv->CustomerID = RT_CID_DLINK;
2690 case EEPROM_CID_WHQL:
2691 //Adapter->bInHctTest = TRUE;//do not supported
2693 //priv->bSupportTurboMode = FALSE;
2694 //priv->bAutoTurboBy8186 = FALSE;
2696 //pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
2697 //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
2698 //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
2702 // value from RegCustomerID
2706 //Avoid the channel plan array overflow, by Bruce, 2007-08-27.
2707 if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1)
2708 priv->ChannelPlan = 0; //FCC
2710 switch(priv->CustomerID)
2712 case RT_CID_DEFAULT:
2714 priv->LedStrategy = HW_LED;
2717 priv->LedStrategy = SW_LED_MODE1;
2722 case RT_CID_819x_CAMEO:
2723 priv->LedStrategy = SW_LED_MODE2;
2726 case RT_CID_819x_RUNTOP:
2727 priv->LedStrategy = SW_LED_MODE3;
2730 case RT_CID_819x_Netcore:
2731 priv->LedStrategy = SW_LED_MODE4;
2734 case RT_CID_Nettronix:
2735 priv->LedStrategy = SW_LED_MODE5;
2739 priv->LedStrategy = SW_LED_MODE6;
2742 case RT_CID_TOSHIBA: //Modify by Jacken 2008/01/31
2748 priv->LedStrategy = HW_LED;
2751 priv->LedStrategy = SW_LED_MODE1;
2758 if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304)
2759 priv->ieee80211->bSupportRemoteWakeUp = true;
2761 priv->ieee80211->bSupportRemoteWakeUp = false;
2764 RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan);
2765 RT_TRACE(COMP_INIT, "ChannelPlan = %d \n", priv->ChannelPlan);
2766 RT_TRACE(COMP_INIT, "LedStrategy = %d \n", priv->LedStrategy);
2767 RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n");
2773 static short rtl8192_get_channel_map(struct net_device * dev)
2775 struct r8192_priv *priv = ieee80211_priv(dev);
2776 #ifdef ENABLE_DOT11D
2777 if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){
2778 printk("rtl8180_init:Error channel plan! Set to default.\n");
2779 priv->ChannelPlan= 0;
2781 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
2783 rtl819x_set_channel_map(priv->ChannelPlan, priv);
2786 //Set Default Channel Plan
2788 DMESG("No channels, aborting");
2792 priv->ChannelPlan= 0;//hikaru
2793 // set channels 1..14 allowed in given locale
2794 for (i=1; i<=14; i++) {
2795 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
2802 static short rtl8192_init(struct net_device *dev)
2804 struct r8192_priv *priv = ieee80211_priv(dev);
2805 memset(&(priv->stats),0,sizeof(struct Stats));
2806 rtl8192_init_priv_variable(dev);
2807 rtl8192_init_priv_lock(priv);
2808 rtl8192_init_priv_task(dev);
2809 rtl8192_get_eeprom_size(dev);
2810 rtl8192_read_eeprom_info(dev);
2811 rtl8192_get_channel_map(dev);
2813 init_timer(&priv->watch_dog_timer);
2814 priv->watch_dog_timer.data = (unsigned long)dev;
2815 priv->watch_dog_timer.function = watch_dog_timer_callback;
2816 if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED, dev->name, dev)) {
2817 printk("Error allocating IRQ %d",dev->irq);
2821 printk("IRQ %d",dev->irq);
2823 if(rtl8192_pci_initdescring(dev)!=0){
2824 printk("Endopoints initialization failed");
2828 //rtl8192_rx_enable(dev);
2829 //rtl8192_adapter_start(dev);
2834 * Actually only set RRSR, RATR and BW_OPMODE registers
2835 * not to do all the hw config as its name says
2836 * This part need to modified according to the rate set we filtered
2838 static void rtl8192_hwconfig(struct net_device* dev)
2840 u32 regRATR = 0, regRRSR = 0;
2841 u8 regBwOpMode = 0, regTmp = 0;
2842 struct r8192_priv *priv = ieee80211_priv(dev);
2844 // Set RRSR, RATR, and BW_OPMODE registers
2846 switch(priv->ieee80211->mode)
2848 case WIRELESS_MODE_B:
2849 regBwOpMode = BW_OPMODE_20MHZ;
2850 regRATR = RATE_ALL_CCK;
2851 regRRSR = RATE_ALL_CCK;
2853 case WIRELESS_MODE_A:
2854 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
2855 regRATR = RATE_ALL_OFDM_AG;
2856 regRRSR = RATE_ALL_OFDM_AG;
2858 case WIRELESS_MODE_G:
2859 regBwOpMode = BW_OPMODE_20MHZ;
2860 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2861 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2863 case WIRELESS_MODE_AUTO:
2864 case WIRELESS_MODE_N_24G:
2865 // It support CCK rate by default.
2866 // CCK rate will be filtered out only when associated AP does not support it.
2867 regBwOpMode = BW_OPMODE_20MHZ;
2868 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2869 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2871 case WIRELESS_MODE_N_5G:
2872 regBwOpMode = BW_OPMODE_5G;
2873 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2874 regRRSR = RATE_ALL_OFDM_AG;
2878 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2881 ratr_value = regRATR;
2882 if (priv->rf_type == RF_1T2R)
2884 ratr_value &= ~(RATE_ALL_OFDM_2SS);
2886 write_nic_dword(dev, RATR0, ratr_value);
2887 write_nic_byte(dev, UFWP, 1);
2889 regTmp = read_nic_byte(dev, 0x313);
2890 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
2891 write_nic_dword(dev, RRSR, regRRSR);
2894 // Set Retry Limit here
2896 write_nic_word(dev, RETRY_LIMIT,
2897 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
2898 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
2899 // Set Contention Window here
2903 // Set Tx Antenna including Feedback control
2905 // Set Auto Rate fallback control
2911 static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
2913 struct r8192_priv *priv = ieee80211_priv(dev);
2914 // struct ieee80211_device *ieee = priv->ieee80211;
2916 RT_STATUS rtStatus = RT_STATUS_SUCCESS;
2920 u8 ICVersion,SwitchingRegulatorOutput;
2922 bool bfirmwareok = true;
2926 u32 tmpRegA, tmpRegC, TempCCk;
2929 RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
2930 priv->being_init_adapter = true;
2931 rtl8192_pci_resetdescring(dev);
2932 // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W.
2933 priv->Rf_Mode = RF_OP_By_SW_3wire;
2936 if(priv->ResetProgress == RESET_TYPE_NORESET)
2938 write_nic_byte(dev, ANAPAR, 0x37);
2939 // Accordign to designer's explain, LBUS active will never > 10ms. We delay 10ms
2940 // Joseph increae the time to prevent firmware download fail
2944 //PlatformSleepUs(10000);
2945 // For any kind of InitializeAdapter process, we shall use system now!!
2946 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
2949 //3 //Config CPUReset Register
2951 //3 Firmware Reset Or Not
2952 ulRegRead = read_nic_dword(dev, CPU_GEN);
2953 if(priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
2954 { //called from MPInitialized. do nothing
2955 ulRegRead |= CPU_GEN_SYSTEM_RESET;
2956 }else if(priv->pFirmware->firmware_status == FW_STATUS_5_READY)
2957 ulRegRead |= CPU_GEN_FIRMWARE_RESET; // Called from MPReset
2959 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status);
2962 //2008.06.03, for WOL 90 hw bug
2963 ulRegRead &= (~(CPU_GEN_GPIO_UART));
2966 write_nic_dword(dev, CPU_GEN, ulRegRead);
2972 //3 //Fix the issue of E-cut high temperature issue
2975 ICVersion = read_nic_byte(dev, IC_VERRSION);
2976 if(ICVersion >= 0x4) //E-cut only
2978 // HW SD suggest that we should not wirte this register too often, so driver
2979 // should readback this register. This register will be modified only when
2981 SwitchingRegulatorOutput = read_nic_byte(dev, SWREGULATOR);
2982 if(SwitchingRegulatorOutput != 0xb8)
2984 write_nic_byte(dev, SWREGULATOR, 0xa8);
2986 write_nic_byte(dev, SWREGULATOR, 0xb8);
2993 //3// Initialize BB before MAC
2995 RT_TRACE(COMP_INIT, "BB Config Start!\n");
2996 rtStatus = rtl8192_BBConfig(dev);
2997 if(rtStatus != RT_STATUS_SUCCESS)
2999 RT_TRACE(COMP_ERR, "BB Config failed\n");
3002 RT_TRACE(COMP_INIT,"BB Config Finished!\n");
3004 //3//Set Loopback mode or Normal mode
3006 //2006.12.13 by emily. Note!We should not merge these two CPU_GEN register writings
3007 // because setting of System_Reset bit reset MAC to default transmission mode.
3008 //Loopback mode or not
3009 priv->LoopbackMode = RTL819X_NO_LOOPBACK;
3010 //priv->LoopbackMode = RTL819X_MAC_LOOPBACK;
3011 if(priv->ResetProgress == RESET_TYPE_NORESET)
3013 ulRegRead = read_nic_dword(dev, CPU_GEN);
3014 if(priv->LoopbackMode == RTL819X_NO_LOOPBACK)
3016 ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
3018 else if (priv->LoopbackMode == RTL819X_MAC_LOOPBACK )
3020 ulRegRead |= CPU_CCK_LOOPBACK;
3024 RT_TRACE(COMP_ERR,"Serious error: wrong loopback mode setting\n");
3027 //2008.06.03, for WOL
3028 //ulRegRead &= (~(CPU_GEN_GPIO_UART));
3029 write_nic_dword(dev, CPU_GEN, ulRegRead);
3031 // 2006.11.29. After reset cpu, we sholud wait for a second, otherwise, it may fail to write registers. Emily
3034 //3Set Hardware(Do nothing now)
3035 rtl8192_hwconfig(dev);
3036 //2=======================================================
3037 // Common Setting for all of the FPGA platform. (part 1)
3038 //2=======================================================
3039 // If there is changes, please make sure it applies to all of the FPGA version
3041 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
3045 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
3046 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) |
3050 write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
3051 (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) ));
3055 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
3056 write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]);
3058 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3060 //3 Initialize Number of Reserved Pages in Firmware Queue
3062 if(priv->bInHctTest)
3064 PlatformEFIOWrite4Byte(Adapter, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
3065 NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
3066 NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
3067 NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3068 PlatformEFIOWrite4Byte(Adapter, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3069 PlatformEFIOWrite4Byte(Adapter, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
3070 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
3071 NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3076 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
3077 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
3078 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
3079 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
3080 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
3081 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
3082 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
3083 NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
3086 rtl8192_tx_enable(dev);
3087 rtl8192_rx_enable(dev);
3088 //3Set Response Rate Setting Register
3089 // CCK rate is supported by default.
3090 // CCK rate will be filtered out only when associated AP does not support it.
3091 ulRegRead = (0xFFF00000 & read_nic_dword(dev, RRSR)) | RATE_ALL_OFDM_AG | RATE_ALL_CCK;
3092 write_nic_dword(dev, RRSR, ulRegRead);
3093 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
3096 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
3097 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
3099 //rtl8192_actset_wirelessmode(dev,priv->RegWirelessMode);
3100 if(priv->ResetProgress == RESET_TYPE_NORESET)
3101 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
3102 //-----------------------------------------------------------------------------
3103 // Set up security related. 070106, by rcnjko:
3104 // 1. Clear all H/W keys.
3105 // 2. Enable H/W encryption/decryption.
3106 //-----------------------------------------------------------------------------
3107 CamResetAllEntry(dev);
3109 u8 SECR_value = 0x0;
3110 SECR_value |= SCR_TxEncEnable;
3111 SECR_value |= SCR_RxDecEnable;
3112 SECR_value |= SCR_NoSKMC;
3113 write_nic_byte(dev, SECR, SECR_value);
3116 write_nic_word(dev, ATIMWND, 2);
3117 write_nic_word(dev, BCN_INTERVAL, 100);
3118 for (i=0; i<QOS_QUEUE_NUM; i++)
3119 write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
3121 // Switching regulator controller: This is set temporarily.
3122 // It's not sure if this can be removed in the future.
3123 // PJ advised to leave it by default.
3125 write_nic_byte(dev, 0xbe, 0xc0);
3127 //2=======================================================
3128 // Set PHY related configuration defined in MAC register bank
3129 //2=======================================================
3130 rtl8192_phy_configmac(dev);
3132 if (priv->card_8192_version > (u8) VERSION_8190_BD) {
3133 rtl8192_phy_getTxPower(dev);
3134 rtl8192_phy_setTxPower(dev, priv->chan);
3138 tmpvalue = read_nic_byte(dev, IC_VERRSION);
3139 priv->IC_Cut = tmpvalue;
3140 RT_TRACE(COMP_INIT, "priv->IC_Cut = 0x%x\n", priv->IC_Cut);
3141 if(priv->IC_Cut >= IC_VersionCut_D)
3143 //pHalData->bDcut = TRUE;
3144 if(priv->IC_Cut == IC_VersionCut_D)
3145 RT_TRACE(COMP_INIT, "D-cut\n");
3146 if(priv->IC_Cut == IC_VersionCut_E)
3148 RT_TRACE(COMP_INIT, "E-cut\n");
3149 // HW SD suggest that we should not wirte this register too often, so driver
3150 // should readback this register. This register will be modified only when
3156 //pHalData->bDcut = FALSE;
3157 RT_TRACE(COMP_INIT, "Before C-cut\n");
3162 RT_TRACE(COMP_INIT, "Load Firmware!\n");
3163 bfirmwareok = init_firmware(dev);
3164 if(bfirmwareok != true) {
3165 rtStatus = RT_STATUS_FAILURE;
3168 RT_TRACE(COMP_INIT, "Load Firmware finished!\n");
3171 if(priv->ResetProgress == RESET_TYPE_NORESET)
3173 RT_TRACE(COMP_INIT, "RF Config Started!\n");
3174 rtStatus = rtl8192_phy_RFConfig(dev);
3175 if(rtStatus != RT_STATUS_SUCCESS)
3177 RT_TRACE(COMP_ERR, "RF Config failed\n");
3180 RT_TRACE(COMP_INIT, "RF Config Finished!\n");
3182 rtl8192_phy_updateInitGain(dev);
3184 /*---- Set CCK and OFDM Block "ON"----*/
3185 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
3186 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
3190 write_nic_byte(dev, 0x87, 0x0);
3193 //2008.06.03, for WOL
3194 ucRegRead = read_nic_byte(dev, GPE);
3196 write_nic_byte(dev, GPE, ucRegRead);
3198 ucRegRead = read_nic_byte(dev, GPO);
3200 write_nic_byte(dev, GPO, ucRegRead);
3203 //2=======================================================
3205 //2=======================================================
3209 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
3210 { // H/W or S/W RF OFF before sleep.
3211 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3212 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3214 else if(priv->ieee80211->RfOffReason >= RF_CHANGE_BY_IPS)
3215 { // H/W or S/W RF OFF before sleep.
3216 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
3217 MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
3221 RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__);
3222 priv->ieee80211->eRFPowerState = eRfOn;
3223 priv->ieee80211->RfOffReason = 0;
3224 //DrvIFIndicateCurrentPhyStatus(Adapter);
3226 //Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_ON);
3229 // If inactive power mode is enabled, disable rf while in disconnected state.
3230 // But we should still tell upper layer we are in rf on state.
3231 // 2007.07.16, by shien chang.
3233 //if(!Adapter->bInHctTest)
3234 //IPSEnter(Adapter);
3241 // We can force firmware to do RF-R/W
3242 if(priv->ieee80211->FwRWRF)
3243 priv->Rf_Mode = RF_OP_By_FW;
3245 priv->Rf_Mode = RF_OP_By_SW_3wire;
3247 priv->Rf_Mode = RF_OP_By_SW_3wire;
3251 if(priv->ResetProgress == RESET_TYPE_NORESET)
3253 dm_initialize_txpower_tracking(dev);
3255 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3256 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3258 if(priv->rf_type == RF_2T4R){
3259 for(i = 0; i<TxBBGainTableLength; i++)
3261 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3263 priv->rfa_txpowertrackingindex= (u8)i;
3264 priv->rfa_txpowertrackingindex_real= (u8)i;
3265 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3270 for(i = 0; i<TxBBGainTableLength; i++)
3272 if(tmpRegC == priv->txbbgain_table[i].txbbgain_value)
3274 priv->rfc_txpowertrackingindex= (u8)i;
3275 priv->rfc_txpowertrackingindex_real= (u8)i;
3276 priv->rfc_txpowertracking_default = priv->rfc_txpowertrackingindex;
3280 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3282 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3284 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3286 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3290 priv->CCKPresentAttentuation_40Mdefault = 0;
3291 priv->CCKPresentAttentuation_difference = 0;
3292 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3293 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3294 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3295 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_initial = %d\n", priv->rfc_txpowertrackingindex);
3296 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real_initial = %d\n", priv->rfc_txpowertrackingindex_real);
3297 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3298 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3302 if(priv->ResetProgress == RESET_TYPE_NORESET)
3304 dm_initialize_txpower_tracking(dev);
3306 if(priv->IC_Cut >= IC_VersionCut_D)
3308 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
3309 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
3310 for(i = 0; i<TxBBGainTableLength; i++)
3312 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
3314 priv->rfa_txpowertrackingindex= (u8)i;
3315 priv->rfa_txpowertrackingindex_real= (u8)i;
3316 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3321 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3323 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
3325 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
3327 priv->CCKPresentAttentuation_20Mdefault =(u8) i;
3331 priv->CCKPresentAttentuation_40Mdefault = 0;
3332 priv->CCKPresentAttentuation_difference = 0;
3333 priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault;
3334 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex);
3335 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real);
3336 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference);
3337 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation);
3338 priv->btxpower_tracking = FALSE;//TEMPLY DISABLE
3343 rtl8192_irq_enable(dev);
3344 priv->being_init_adapter = false;
3349 static void rtl8192_prepare_beacon(struct r8192_priv *priv)
3351 struct sk_buff *skb;
3352 //unsigned long flags;
3355 skb = ieee80211_get_beacon(priv->ieee80211);
3356 tcb_desc = (cb_desc *)(skb->cb + 8);
3357 //spin_lock_irqsave(&priv->tx_lock,flags);
3358 /* prepare misc info for the beacon xmit */
3359 tcb_desc->queue_index = BEACON_QUEUE;
3360 /* IBSS does not support HT yet, use 1M defaultly */
3361 tcb_desc->data_rate = 2;
3362 tcb_desc->RATRIndex = 7;
3363 tcb_desc->bTxDisableRateFallBack = 1;
3364 tcb_desc->bTxUseDriverAssingedRate = 1;
3366 skb_push(skb, priv->ieee80211->tx_headroom);
3368 rtl8192_tx(priv->ieee80211->dev,skb);
3370 //spin_unlock_irqrestore (&priv->tx_lock, flags);
3375 * configure registers for beacon tx and enables it via
3376 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
3377 * be used to stop beacon transmission
3379 static void rtl8192_start_beacon(struct net_device *dev)
3381 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3382 struct ieee80211_network *net = &priv->ieee80211->current_network;
3387 DMESG("Enabling beacon TX");
3388 //rtl8192_prepare_beacon(dev);
3389 rtl8192_irq_disable(dev);
3390 //rtl8192_beacon_tx_enable(dev);
3393 write_nic_word(dev, ATIMWND, 2);
3395 /* Beacon interval (in unit of TU) */
3396 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
3399 * DrvErlyInt (in unit of TU).
3400 * (Time to send interrupt to notify driver to c
3401 * hange beacon content)
3403 write_nic_word(dev, BCN_DRV_EARLY_INT, 10);
3406 * BcnDMATIM(in unit of us).
3407 * Indicates the time before TBTT to perform beacon queue DMA
3409 write_nic_word(dev, BCN_DMATIME, 256);
3412 * Force beacon frame transmission even after receiving
3413 * beacon frame from other ad hoc STA
3415 write_nic_byte(dev, BCN_ERR_THRESH, 100);
3417 /* Set CW and IFS */
3418 BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT;
3419 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
3420 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
3423 /* enable the interrupt for ad-hoc process */
3424 rtl8192_irq_enable(dev);
3427 static bool HalTxCheckStuck8190Pci(struct net_device *dev)
3429 u16 RegTxCounter = read_nic_word(dev, 0x128);
3430 struct r8192_priv *priv = ieee80211_priv(dev);
3431 bool bStuck = FALSE;
3432 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
3433 if(priv->TxCounter==RegTxCounter)
3436 priv->TxCounter = RegTxCounter;
3442 * Assumption: RT_TX_SPINLOCK is acquired.
3445 TxCheckStuck(struct net_device *dev)
3447 struct r8192_priv *priv = ieee80211_priv(dev);
3448 u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3449 bool bCheckFwTxCnt = false;
3452 // Decide Stuch threshold according to current power save mode
3454 switch (priv->ieee80211->dot11PowerSaveMode)
3456 // The threshold value may required to be adjusted .
3457 case eActive: // Active/Continuous access.
3458 ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
3460 case eMaxPs: // Max power save mode.
3461 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3463 case eFastPs: // Fast power save mode.
3464 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
3471 if(HalTxCheckStuck8190Pci(dev))
3473 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
3474 return RESET_TYPE_SILENT;
3478 return RESET_TYPE_NORESET;
3482 static bool HalRxCheckStuck8190Pci(struct net_device *dev)
3484 struct r8192_priv *priv = ieee80211_priv(dev);
3485 u16 RegRxCounter = read_nic_word(dev, 0x130);
3486 bool bStuck = FALSE;
3488 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
3489 // If rssi is small, we should check rx for long time because of bad rx.
3490 // or maybe it will continuous silent reset every 2 seconds.
3492 if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
3494 priv->rx_chk_cnt = 0; /* high rssi, check rx stuck right now. */
3496 else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
3497 ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
3498 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
3501 if(priv->rx_chk_cnt < 2)
3507 priv->rx_chk_cnt = 0;
3510 else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
3511 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
3512 priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
3514 if(priv->rx_chk_cnt < 4)
3520 priv->rx_chk_cnt = 0;
3525 if(priv->rx_chk_cnt < 8)
3531 priv->rx_chk_cnt = 0;
3534 if(priv->RxCounter==RegRxCounter)
3537 priv->RxCounter = RegRxCounter;
3542 static RESET_TYPE RxCheckStuck(struct net_device *dev)
3545 if(HalRxCheckStuck8190Pci(dev))
3547 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
3548 return RESET_TYPE_SILENT;
3551 return RESET_TYPE_NORESET;
3555 rtl819x_ifcheck_resetornot(struct net_device *dev)
3557 struct r8192_priv *priv = ieee80211_priv(dev);
3558 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
3559 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
3560 RT_RF_POWER_STATE rfState;
3562 rfState = priv->ieee80211->eRFPowerState;
3564 TxResetType = TxCheckStuck(dev);
3566 if( rfState != eRfOff &&
3567 /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
3568 (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
3570 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
3571 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
3572 // if driver is in firmware download failure status, driver should initialize RF in the following
3573 // silent reset procedure Emily, 2008.01.21
3575 // Driver should not check RX stuck in IBSS mode because it is required to
3576 // set Check BSSID in order to send beacon, however, if check BSSID is
3577 // set, STA cannot hear any packet a all. Emily, 2008.04.12
3578 RxResetType = RxCheckStuck(dev);
3582 RT_TRACE(COMP_RESET,"%s(): TxResetType is %d, RxResetType is %d\n",__FUNCTION__,TxResetType,RxResetType);
3583 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
3584 return RESET_TYPE_NORMAL;
3585 else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT)
3586 return RESET_TYPE_SILENT;
3588 return RESET_TYPE_NORESET;
3593 static void CamRestoreAllEntry(struct net_device *dev)
3596 struct r8192_priv *priv = ieee80211_priv(dev);
3597 const u8* MacAddr = priv->ieee80211->current_network.bssid;
3599 static const u8 CAM_CONST_ADDR[4][6] = {
3600 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3601 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3602 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3603 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
3604 static const u8 CAM_CONST_BROAD[] =
3605 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3607 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
3610 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
3611 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
3614 for(EntryId=0; EntryId<4; EntryId++)
3617 MacAddr = CAM_CONST_ADDR[EntryId];
3621 priv->ieee80211->pairwise_key_type,
3629 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
3633 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3637 priv->ieee80211->pairwise_key_type,
3645 priv->ieee80211->pairwise_key_type,
3651 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
3655 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3659 priv->ieee80211->pairwise_key_type,
3667 priv->ieee80211->pairwise_key_type,
3676 if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
3678 MacAddr = CAM_CONST_BROAD;
3679 for(EntryId=1 ; EntryId<4 ; EntryId++)
3685 priv->ieee80211->group_key_type,
3691 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3695 priv->ieee80211->group_key_type,
3700 else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
3702 MacAddr = CAM_CONST_BROAD;
3703 for(EntryId=1; EntryId<4 ; EntryId++)
3709 priv->ieee80211->group_key_type,
3716 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3720 priv->ieee80211->group_key_type,
3728 * This function is used to fix Tx/Rx stop bug temporarily.
3729 * This function will do "system reset" to NIC when Tx or Rx is stuck.
3730 * The method checking Tx/Rx stuck of this function is supported by FW,
3731 * which reports Tx and Rx counter to register 0x128 and 0x130.
3733 static void rtl819x_ifsilentreset(struct net_device *dev)
3735 struct r8192_priv *priv = ieee80211_priv(dev);
3737 int reset_status = 0;
3738 struct ieee80211_device *ieee = priv->ieee80211;
3743 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
3744 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
3746 if(priv->ResetProgress==RESET_TYPE_NORESET)
3750 //LZM for PS-Poll AID issue. 090429
3751 if(priv->ieee80211->state == IEEE80211_LINKED)
3752 LeisurePSLeave(dev);
3755 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
3757 // Set the variable for reset.
3758 priv->ResetProgress = RESET_TYPE_SILENT;
3759 // rtl8192_close(dev);
3761 down(&priv->wx_sem);
3764 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
3769 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
3770 if(!netif_queue_stopped(dev))
3771 netif_stop_queue(dev);
3773 dm_backup_dynamic_mechanism_state(dev);
3775 rtl8192_irq_disable(dev);
3776 rtl8192_cancel_deferred_work(priv);
3778 del_timer_sync(&priv->watch_dog_timer);
3779 ieee->sync_scan_hurryup = 1;
3780 if(ieee->state == IEEE80211_LINKED)
3782 down(&ieee->wx_sem);
3783 printk("ieee->state is IEEE80211_LINKED\n");
3784 ieee80211_stop_send_beacons(priv->ieee80211);
3785 del_timer_sync(&ieee->associate_timer);
3786 cancel_delayed_work(&ieee->associate_retry_wq);
3787 ieee80211_stop_scan(ieee);
3791 printk("ieee->state is NOT LINKED\n");
3792 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
3794 rtl8192_halt_adapter(dev, true);
3796 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
3797 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
3798 reset_status = _rtl8192_up(dev);
3800 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
3801 if(reset_status == -1)
3810 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n",__FUNCTION__);
3814 ieee->is_silent_reset = 1;
3816 EnableHWSecurityConfig8192(dev);
3818 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
3820 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3823 queue_work(ieee->wq, &ieee->associate_complete_wq);
3827 else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
3829 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3830 ieee->link_change(ieee->dev);
3832 // notify_wx_assoc_event(ieee);
3834 ieee80211_start_send_beacons(ieee);
3836 if (ieee->data_hard_resume)
3837 ieee->data_hard_resume(ieee->dev);
3838 netif_carrier_on(ieee->dev);
3842 CamRestoreAllEntry(dev);
3844 // Restore the previous setting for all dynamic mechanism
3845 dm_restore_dynamic_mechanism_state(dev);
3847 priv->ResetProgress = RESET_TYPE_NORESET;
3848 priv->reset_count++;
3850 priv->bForcedSilentReset =false;
3851 priv->bResetInProgress = false;
3853 // For test --> force write UFWP.
3854 write_nic_byte(dev, UFWP, 1);
3855 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
3861 void InactivePsWorkItemCallback(struct net_device *dev)
3863 struct r8192_priv *priv = ieee80211_priv(dev);
3864 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
3866 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() ---------> \n");
3868 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
3869 // is really scheduled.
3870 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
3871 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
3872 // blocks the IPS procedure of switching RF.
3873 // By Bruce, 2007-12-25.
3875 pPSC->bSwRfProcessing = TRUE;
3877 RT_TRACE(COMP_RF, "InactivePsWorkItemCallback(): Set RF to %s.\n",
3878 pPSC->eInactivePowerState == eRfOff?"OFF":"ON");
3881 MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
3884 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
3886 pPSC->bSwRfProcessing = FALSE;
3887 RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <--------- \n");
3891 /* Change current and default preamble mode. */
3892 bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev, u8 rtPsMode)
3894 struct r8192_priv *priv = ieee80211_priv(dev);
3896 // Currently, we do not change power save mode on IBSS mode.
3897 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3903 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
3904 // some AP will not response to our mgnt frames with PwrMgt bit set,
3905 // e.g. cannot associate the AP.
3906 // So I commented out it. 2005.02.16, by rcnjko.
3908 // // Change device's power save mode.
3909 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
3911 // Update power save mode configured.
3912 //RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode);
3913 if(!priv->ps_force) {
3914 priv->ieee80211->ps = rtPsMode;
3917 // Awake immediately
3918 if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED)
3920 unsigned long flags;
3922 //PlatformSetTimer(Adapter, &(pMgntInfo->AwakeTimer), 0);
3923 // Notify the AP we awke.
3924 rtl8192_hw_wakeup(dev);
3925 priv->ieee80211->sta_sleep = 0;
3927 spin_lock_irqsave(&(priv->ieee80211->mgmt_tx_lock), flags);
3928 printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n");
3929 ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0);
3930 spin_unlock_irqrestore(&(priv->ieee80211->mgmt_tx_lock), flags);
3936 /* Enter the leisure power save mode. */
3937 void LeisurePSEnter(struct net_device *dev)
3939 struct r8192_priv *priv = ieee80211_priv(dev);
3940 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
3942 //RT_TRACE(COMP_PS, "LeisurePSEnter()...\n");
3943 //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n",
3944 // pPSC->bLeisurePs, priv->ieee80211->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD);
3946 if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) &&
3947 (priv->ieee80211->state == IEEE80211_LINKED)) ||
3948 (priv->ieee80211->iw_mode == IW_MODE_ADHOC) ||
3949 (priv->ieee80211->iw_mode == IW_MODE_MASTER))
3952 if (pPSC->bLeisurePs)
3954 // Idle for a while if we connect to AP a while ago.
3955 if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) // 4 Sec
3958 if(priv->ieee80211->ps == IEEE80211_PS_DISABLED)
3961 //RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n");
3962 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
3967 pPSC->LpsIdleCount++;
3972 /* Leave leisure power save mode. */
3973 void LeisurePSLeave(struct net_device *dev)
3975 struct r8192_priv *priv = ieee80211_priv(dev);
3976 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
3978 if (pPSC->bLeisurePs)
3980 if(priv->ieee80211->ps != IEEE80211_PS_DISABLED)
3982 // move to lps_wakecomplete()
3983 //RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n");
3984 MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_DISABLED);
3992 /* Enter the inactive power save mode. RF will be off */
3994 IPSEnter(struct net_device *dev)
3996 struct r8192_priv *priv = ieee80211_priv(dev);
3997 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
3998 RT_RF_POWER_STATE rtState;
4000 if (pPSC->bInactivePs)
4002 rtState = priv->ieee80211->eRFPowerState;
4004 // Added by Bruce, 2007-12-25.
4005 // Do not enter IPS in the following conditions:
4006 // (1) RF is already OFF or Sleep
4007 // (2) bSwRfProcessing (indicates the IPS is still under going)
4008 // (3) Connectted (only disconnected can trigger IPS)
4009 // (4) IBSS (send Beacon)
4010 // (5) AP mode (send Beacon)
4012 if (rtState == eRfOn && !pPSC->bSwRfProcessing
4013 && (priv->ieee80211->state != IEEE80211_LINKED) )
4015 RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n");
4016 pPSC->eInactivePowerState = eRfOff;
4017 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4018 InactivePsWorkItemCallback(dev);
4025 // Leave the inactive power save mode, RF will be on.
4026 // 2007.08.17, by shien chang.
4029 IPSLeave(struct net_device *dev)
4031 struct r8192_priv *priv = ieee80211_priv(dev);
4032 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
4033 RT_RF_POWER_STATE rtState;
4035 if (pPSC->bInactivePs)
4037 rtState = priv->ieee80211->eRFPowerState;
4038 if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->ieee80211->RfOffReason <= RF_CHANGE_BY_IPS)
4040 RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n");
4041 pPSC->eInactivePowerState = eRfOn;
4042 // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
4043 InactivePsWorkItemCallback(dev);
4048 void IPSLeave_wq(void *data)
4050 struct ieee80211_device *ieee = container_of(data,struct ieee80211_device,ips_leave_wq);
4051 struct net_device *dev = ieee->dev;
4053 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4054 down(&priv->ieee80211->ips_sem);
4056 up(&priv->ieee80211->ips_sem);
4059 void ieee80211_ips_leave_wq(struct net_device *dev)
4061 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4062 RT_RF_POWER_STATE rtState;
4063 rtState = priv->ieee80211->eRFPowerState;
4065 if(priv->ieee80211->PowerSaveControl.bInactivePs){
4066 if(rtState == eRfOff){
4067 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
4069 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
4073 printk("=========>%s(): IPSLeave\n",__FUNCTION__);
4074 queue_work(priv->ieee80211->wq,&priv->ieee80211->ips_leave_wq);
4079 //added by amy 090331 end
4080 void ieee80211_ips_leave(struct net_device *dev)
4082 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4083 down(&priv->ieee80211->ips_sem);
4085 up(&priv->ieee80211->ips_sem);
4089 static void rtl819x_update_rxcounts(
4090 struct r8192_priv *priv,
4099 *TotalRxDataNum = 0;
4101 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
4102 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
4103 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
4104 for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
4105 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
4106 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
4111 static void rtl819x_watchdog_wqcallback(struct work_struct *work)
4113 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
4114 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
4115 struct net_device *dev = priv->ieee80211->dev;
4116 struct ieee80211_device* ieee = priv->ieee80211;
4117 RESET_TYPE ResetType = RESET_TYPE_NORESET;
4118 unsigned long flags;
4119 bool bBusyTraffic = false;
4120 bool bEnterPS = false;
4122 if ((!priv->up) || priv->bHwRadioOff)
4127 hal_dm_watchdog(dev);
4129 if(ieee->actscanning == false){
4130 if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) &&
4131 (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key &&
4132 (!ieee->proto_stoppping) && !ieee->wx_set_enc){
4133 if(ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){
4135 //ieee80211_stop_scan(priv->ieee80211);
4140 {//to get busy traffic condition
4141 if(ieee->state == IEEE80211_LINKED)
4143 if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 ||
4144 ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) {
4145 bBusyTraffic = true;
4149 //added by amy for Leisure PS
4150 if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) ||
4151 (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) )
4160 // LeisurePS only work in infra mode.
4163 LeisurePSEnter(dev);
4167 LeisurePSLeave(dev);
4175 //RT_TRACE(COMP_LPS,"====>no link LPS leave\n");
4176 LeisurePSLeave(dev);
4180 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
4181 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
4182 ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0;
4183 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
4187 //added by amy for AP roaming
4190 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4192 u32 TotalRxBcnNum = 0;
4193 u32 TotalRxDataNum = 0;
4195 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
4196 if((TotalRxBcnNum+TotalRxDataNum) == 0)
4198 if( ieee->eRFPowerState == eRfOff)
4199 RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
4200 printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
4201 // Dot11d_Reset(dev);
4202 ieee->state = IEEE80211_ASSOCIATING;
4203 notify_wx_assoc_event(priv->ieee80211);
4204 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
4205 ieee->is_roaming = true;
4206 ieee->is_set_key = false;
4207 ieee->link_change(dev);
4208 queue_work(ieee->wq, &ieee->associate_procedure_wq);
4211 ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
4212 ieee->LinkDetectInfo.NumRecvDataInPeriod=0;
4215 //check if reset the driver
4216 spin_lock_irqsave(&priv->tx_lock,flags);
4217 if (priv->watchdog_check_reset_cnt++ >= 3 && !ieee->is_roaming &&
4218 priv->watchdog_last_time != 1)
4220 ResetType = rtl819x_ifcheck_resetornot(dev);
4221 priv->watchdog_check_reset_cnt = 3;
4223 spin_unlock_irqrestore(&priv->tx_lock,flags);
4224 if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL)
4226 priv->ResetProgress = RESET_TYPE_NORMAL;
4227 RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__FUNCTION__);
4230 /* disable silent reset temply 2008.9.11*/
4232 if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo
4234 priv->watchdog_last_time = 1;
4235 rtl819x_ifsilentreset(dev);
4238 priv->watchdog_last_time = 0;
4240 priv->force_reset = false;
4241 priv->bForcedSilentReset = false;
4242 priv->bResetInProgress = false;
4243 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
4247 void watch_dog_timer_callback(unsigned long data)
4249 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
4250 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0);
4251 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
4255 static int _rtl8192_up(struct net_device *dev)
4257 struct r8192_priv *priv = ieee80211_priv(dev);
4259 RT_STATUS init_status = RT_STATUS_SUCCESS;
4261 priv->ieee80211->ieee_up=1;
4262 priv->bdisable_nic = false; //YJ,add,091111
4263 RT_TRACE(COMP_INIT, "Bringing up iface");
4265 init_status = rtl8192_adapter_start(dev);
4266 if(init_status != RT_STATUS_SUCCESS)
4268 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
4271 RT_TRACE(COMP_INIT, "start adapter finished\n");
4273 if(priv->ieee80211->eRFPowerState!=eRfOn)
4274 MgntActSet_RF_State(dev, eRfOn, priv->ieee80211->RfOffReason);
4276 if(priv->ieee80211->state != IEEE80211_LINKED)
4277 ieee80211_softmac_start_protocol(priv->ieee80211);
4278 ieee80211_reset_queue(priv->ieee80211);
4279 watch_dog_timer_callback((unsigned long) dev);
4280 if(!netif_queue_stopped(dev))
4281 netif_start_queue(dev);
4283 netif_wake_queue(dev);
4289 static int rtl8192_open(struct net_device *dev)
4291 struct r8192_priv *priv = ieee80211_priv(dev);
4294 down(&priv->wx_sem);
4295 ret = rtl8192_up(dev);
4302 int rtl8192_up(struct net_device *dev)
4304 struct r8192_priv *priv = ieee80211_priv(dev);
4306 if (priv->up == 1) return -1;
4308 return _rtl8192_up(dev);
4312 static int rtl8192_close(struct net_device *dev)
4314 struct r8192_priv *priv = ieee80211_priv(dev);
4317 down(&priv->wx_sem);
4319 ret = rtl8192_down(dev);
4327 int rtl8192_down(struct net_device *dev)
4329 struct r8192_priv *priv = ieee80211_priv(dev);
4331 if (priv->up == 0) return -1;
4334 //LZM for PS-Poll AID issue. 090429
4335 if(priv->ieee80211->state == IEEE80211_LINKED)
4336 LeisurePSLeave(dev);
4340 priv->ieee80211->ieee_up = 0;
4341 RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
4343 if (!netif_queue_stopped(dev))
4344 netif_stop_queue(dev);
4346 rtl8192_irq_disable(dev);
4347 rtl8192_cancel_deferred_work(priv);
4349 del_timer_sync(&priv->watch_dog_timer);
4351 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4353 rtl8192_halt_adapter(dev,false);
4354 memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
4356 RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
4362 void rtl8192_commit(struct net_device *dev)
4364 struct r8192_priv *priv = ieee80211_priv(dev);
4366 if (priv->up == 0) return ;
4369 ieee80211_softmac_stop_protocol(priv->ieee80211,true);
4371 rtl8192_irq_disable(dev);
4372 rtl8192_halt_adapter(dev,true);
4376 static void rtl8192_restart(struct work_struct *work)
4378 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
4379 struct net_device *dev = priv->ieee80211->dev;
4381 down(&priv->wx_sem);
4383 rtl8192_commit(dev);
4388 static void r8192_set_multicast(struct net_device *dev)
4390 struct r8192_priv *priv = ieee80211_priv(dev);
4393 //down(&priv->wx_sem);
4397 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4399 if (promisc != priv->promisc) {
4401 // rtl8192_commit(dev);
4404 priv->promisc = promisc;
4406 //schedule_work(&priv->reset_wq);
4407 //up(&priv->wx_sem);
4411 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
4413 struct r8192_priv *priv = ieee80211_priv(dev);
4414 struct sockaddr *addr = mac;
4416 down(&priv->wx_sem);
4418 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
4420 schedule_work(&priv->reset_wq);
4426 /* based on ipw2200 driver */
4427 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
4429 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4430 struct iwreq *wrq = (struct iwreq *)rq;
4432 struct ieee80211_device *ieee = priv->ieee80211;
4434 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
4435 struct iw_point *p = &wrq->u.data;
4436 struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
4438 down(&priv->wx_sem);
4441 if (p->length < sizeof(struct ieee_param) || !p->pointer){
4446 ipw = kmalloc(p->length, GFP_KERNEL);
4451 if (copy_from_user(ipw, p->pointer, p->length)) {
4458 case RTL_IOCTL_WPA_SUPPLICANT:
4459 //parse here for HW security
4460 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
4462 if (ipw->u.crypt.set_tx)
4464 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4465 ieee->pairwise_key_type = KEY_TYPE_CCMP;
4466 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4467 ieee->pairwise_key_type = KEY_TYPE_TKIP;
4468 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4470 if (ipw->u.crypt.key_len == 13)
4471 ieee->pairwise_key_type = KEY_TYPE_WEP104;
4472 else if (ipw->u.crypt.key_len == 5)
4473 ieee->pairwise_key_type = KEY_TYPE_WEP40;
4476 ieee->pairwise_key_type = KEY_TYPE_NA;
4478 if (ieee->pairwise_key_type)
4480 memcpy((u8*)key, ipw->u.crypt.key, 16);
4481 EnableHWSecurityConfig8192(dev);
4482 //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!
4484 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4485 if (ieee->auth_mode != 2) //LEAP WEP will never set this.
4486 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4488 if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){
4489 write_nic_byte(dev, 0x173, 1); //fix aes bug
4493 else //if (ipw->u.crypt.idx) //group key use idx > 0
4495 memcpy((u8*)key, ipw->u.crypt.key, 16);
4496 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4497 ieee->group_key_type= KEY_TYPE_CCMP;
4498 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4499 ieee->group_key_type = KEY_TYPE_TKIP;
4500 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4502 if (ipw->u.crypt.key_len == 13)
4503 ieee->group_key_type = KEY_TYPE_WEP104;
4504 else if (ipw->u.crypt.key_len == 5)
4505 ieee->group_key_type = KEY_TYPE_WEP40;
4508 ieee->group_key_type = KEY_TYPE_NA;
4510 if (ieee->group_key_type)
4514 ipw->u.crypt.idx, //KeyIndex
4515 ieee->group_key_type, //KeyType
4516 broadcast_addr, //MacAddr
4522 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
4537 static u8 HwRateToMRate90(bool bIsHT, u8 rate)
4543 case DESC90_RATE1M: ret_rate = MGN_1M; break;
4544 case DESC90_RATE2M: ret_rate = MGN_2M; break;
4545 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
4546 case DESC90_RATE11M: ret_rate = MGN_11M; break;
4547 case DESC90_RATE6M: ret_rate = MGN_6M; break;
4548 case DESC90_RATE9M: ret_rate = MGN_9M; break;
4549 case DESC90_RATE12M: ret_rate = MGN_12M; break;
4550 case DESC90_RATE18M: ret_rate = MGN_18M; break;
4551 case DESC90_RATE24M: ret_rate = MGN_24M; break;
4552 case DESC90_RATE36M: ret_rate = MGN_36M; break;
4553 case DESC90_RATE48M: ret_rate = MGN_48M; break;
4554 case DESC90_RATE54M: ret_rate = MGN_54M; break;
4557 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
4563 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
4564 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
4565 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
4566 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
4567 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
4568 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
4569 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
4570 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
4571 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
4572 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
4573 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
4574 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
4575 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
4576 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
4577 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
4578 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
4579 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
4582 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
4590 /* Record the TSF time stamp when receiving a packet */
4591 static void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
4593 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4595 if(stats->bIsAMPDU && !stats->bFirstMPDU) {
4596 stats->mac_time[0] = priv->LastRxDescTSFLow;
4597 stats->mac_time[1] = priv->LastRxDescTSFHigh;
4599 priv->LastRxDescTSFLow = stats->mac_time[0];
4600 priv->LastRxDescTSFHigh = stats->mac_time[1];
4604 static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
4606 long signal_power; // in dBm.
4608 // Translate to dBm (x=0.5y-95).
4609 signal_power = (long)((signal_strength_index + 1) >> 1);
4612 return signal_power;
4616 rtl8190_process_cck_rxpathsel(
4617 struct r8192_priv * priv,
4618 struct ieee80211_rx_stats * pprevious_stats
4621 #ifdef RTL8190P //Only 90P 2T4R need to check
4622 char last_cck_adc_pwdb[4]={0,0,0,0};
4624 //cosa add for Rx path selection
4625 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable)
4627 if(pprevious_stats->bIsCCK &&
4628 (pprevious_stats->bPacketToSelf ||pprevious_stats->bPacketBeacon))
4630 /* record the cck adc_pwdb to the sliding window. */
4631 if(priv->stats.cck_adc_pwdb.TotalNum++ >= PHY_RSSI_SLID_WIN_MAX)
4633 priv->stats.cck_adc_pwdb.TotalNum = PHY_RSSI_SLID_WIN_MAX;
4634 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
4636 last_cck_adc_pwdb[i] = priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index];
4637 priv->stats.cck_adc_pwdb.TotalVal[i] -= last_cck_adc_pwdb[i];
4640 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
4642 priv->stats.cck_adc_pwdb.TotalVal[i] += pprevious_stats->cck_adc_pwdb[i];
4643 priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index] = pprevious_stats->cck_adc_pwdb[i];
4645 priv->stats.cck_adc_pwdb.index++;
4646 if(priv->stats.cck_adc_pwdb.index >= PHY_RSSI_SLID_WIN_MAX)
4647 priv->stats.cck_adc_pwdb.index = 0;
4649 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
4651 DM_RxPathSelTable.cck_pwdb_sta[i] = priv->stats.cck_adc_pwdb.TotalVal[i]/priv->stats.cck_adc_pwdb.TotalNum;
4654 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
4656 if(pprevious_stats->cck_adc_pwdb[i] > (char)priv->undecorated_smoothed_cck_adc_pwdb[i])
4658 priv->undecorated_smoothed_cck_adc_pwdb[i] =
4659 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
4660 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
4661 priv->undecorated_smoothed_cck_adc_pwdb[i] = priv->undecorated_smoothed_cck_adc_pwdb[i] + 1;
4665 priv->undecorated_smoothed_cck_adc_pwdb[i] =
4666 ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) +
4667 (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor);
4676 /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to
4677 be a local static. Otherwise, it may increase when we return from S3/S4. The
4678 value will be kept in memory or disk. We must delcare the value in adapter
4679 and it will be reinitialized when return from S3/S4. */
4680 static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
4682 bool bcheck = false;
4684 u32 nspatial_stream, tmp_val;
4686 static u32 slide_rssi_index=0, slide_rssi_statistics=0;
4687 static u32 slide_evm_index=0, slide_evm_statistics=0;
4688 static u32 last_rssi=0, last_evm=0;
4689 //cosa add for rx path selection
4690 // static long slide_cck_adc_pwdb_index=0, slide_cck_adc_pwdb_statistics=0;
4691 // static char last_cck_adc_pwdb[4]={0,0,0,0};
4692 //cosa add for beacon rssi smoothing
4693 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
4694 static u32 last_beacon_adc_pwdb=0;
4696 struct ieee80211_hdr_3addr *hdr;
4698 unsigned int frag,seq;
4699 hdr = (struct ieee80211_hdr_3addr *)buffer;
4700 sc = le16_to_cpu(hdr->seq_ctl);
4701 frag = WLAN_GET_SEQ_FRAG(sc);
4702 seq = WLAN_GET_SEQ_SEQ(sc);
4703 //cosa add 04292008 to record the sequence number
4704 pcurrent_stats->Seq_Num = seq;
4706 // Check whether we should take the previous packet into accounting
4708 if(!pprevious_stats->bIsAMPDU)
4710 // if previous packet is not aggregated packet
4714 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
4716 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
4717 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
4718 priv->stats.slide_rssi_total -= last_rssi;
4720 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
4722 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
4723 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
4724 slide_rssi_index = 0;
4726 // <1> Showed on UI for user, in dbm
4727 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
4728 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
4729 pcurrent_stats->rssi = priv->stats.signal_strength;
4731 // If the previous packet does not match the criteria, neglect it
4733 if(!pprevious_stats->bPacketMatchBSSID)
4735 if(!pprevious_stats->bToSelfBA)
4742 rtl8190_process_cck_rxpathsel(priv,pprevious_stats);
4744 // <2> Showed on UI for engineering
4745 // hardware does not provide rssi information for each rf path in CCK
4746 if(!pprevious_stats->bIsCCK && pprevious_stats->bPacketToSelf)
4748 for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++)
4750 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
4752 RT_TRACE(COMP_DBG,"Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d \n" ,pprevious_stats->RxMIMOSignalStrength[rfpath] );
4753 //Fixed by Jacken 2008-03-20
4754 if(priv->stats.rx_rssi_percentage[rfpath] == 0)
4756 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
4758 if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath])
4760 priv->stats.rx_rssi_percentage[rfpath] =
4761 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
4762 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
4763 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
4767 priv->stats.rx_rssi_percentage[rfpath] =
4768 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
4769 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
4771 RT_TRACE(COMP_DBG,"Jacken -> priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
4779 //cosa add for beacon rssi smoothing by average.
4780 if(pprevious_stats->bPacketBeacon)
4782 /* record the beacon pwdb to the sliding window. */
4783 if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
4785 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
4786 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
4787 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
4788 // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
4790 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
4791 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
4792 slide_beacon_adc_pwdb_index++;
4793 if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
4794 slide_beacon_adc_pwdb_index = 0;
4795 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
4796 if(pprevious_stats->RxPWDBAll >= 3)
4797 pprevious_stats->RxPWDBAll -= 3;
4800 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
4801 pprevious_stats->bIsCCK? "CCK": "OFDM",
4802 pprevious_stats->RxPWDBAll);
4804 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
4806 if(priv->undecorated_smoothed_pwdb < 0) // initialize
4808 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
4811 if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
4813 priv->undecorated_smoothed_pwdb =
4814 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4815 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4816 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
4820 priv->undecorated_smoothed_pwdb =
4821 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4822 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4825 //Fixed by Jacken 2008-03-20
4826 if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB)
4828 pHalData->UndecoratedSmoothedPWDB =
4829 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
4830 pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1;
4834 pHalData->UndecoratedSmoothedPWDB =
4835 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
4843 /* record the general EVM to the sliding window. */
4844 if(pprevious_stats->SignalQuality == 0)
4849 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
4850 if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
4851 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
4852 last_evm = priv->stats.slide_evm[slide_evm_index];
4853 priv->stats.slide_evm_total -= last_evm;
4856 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
4858 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
4859 if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
4860 slide_evm_index = 0;
4862 // <1> Showed on UI for user, in percentage.
4863 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
4864 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
4867 // <2> Showed on UI for engineering
4868 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
4870 for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
4872 if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
4874 if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
4876 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
4878 priv->stats.rx_evm_percentage[nspatial_stream] =
4879 ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
4880 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
4888 static u8 rtl819x_query_rxpwrpercentage(
4892 if ((antpower <= -100) || (antpower >= 20))
4896 else if (antpower >= 0)
4902 return (100+antpower);
4908 rtl819x_evm_dbtopercentage(
4920 ret_val = 0 - ret_val;
4927 /* We want good-looking for signal strength/quality */
4928 static long rtl819x_signal_scale_mapping(long currsig)
4932 // Step 1. Scale mapping.
4933 if(currsig >= 61 && currsig <= 100)
4935 retsig = 90 + ((currsig - 60) / 4);
4937 else if(currsig >= 41 && currsig <= 60)
4939 retsig = 78 + ((currsig - 40) / 2);
4941 else if(currsig >= 31 && currsig <= 40)
4943 retsig = 66 + (currsig - 30);
4945 else if(currsig >= 21 && currsig <= 30)
4947 retsig = 54 + (currsig - 20);
4949 else if(currsig >= 5 && currsig <= 20)
4951 retsig = 42 + (((currsig - 5) * 2) / 3);
4953 else if(currsig == 4)
4957 else if(currsig == 3)
4961 else if(currsig == 2)
4965 else if(currsig == 1)
4977 static void rtl8192_query_rxphystatus(
4978 struct r8192_priv * priv,
4979 struct ieee80211_rx_stats * pstats,
4980 prx_desc_819x_pci pdesc,
4981 prx_fwinfo_819x_pci pdrvinfo,
4982 struct ieee80211_rx_stats * precord_stats,
4983 bool bpacket_match_bssid,
4984 bool bpacket_toself,
4989 //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status);
4990 phy_sts_ofdm_819xpci_t* pofdm_buf;
4991 phy_sts_cck_819xpci_t * pcck_buf;
4992 phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
4994 u8 i,max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
4995 char rx_pwr[4], rx_pwr_all=0;
4996 //long rx_avg_pwr = 0;
4997 char rx_snrX, rx_evmX;
4999 u32 RSSI, total_rssi=0;//, total_evm=0;
5000 // long signal_strength_index = 0;
5004 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
5006 // Record it for next packet processing
5007 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
5008 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
5009 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
5010 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
5011 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
5012 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
5013 /*2007.08.30 requested by SD3 Jerry */
5014 if (priv->phy_check_reg824 == 0)
5016 priv->phy_reg824_bit9 = rtl8192_QueryBBReg(priv->ieee80211->dev, rFPGA0_XA_HSSIParameter2, 0x200);
5017 priv->phy_check_reg824 = 1;
5021 prxpkt = (u8*)pdrvinfo;
5023 /* Move pointer to the 16th bytes. Phy status start address. */
5024 prxpkt += sizeof(rx_fwinfo_819x_pci);
5026 /* Initial the cck and ofdm buffer pointer */
5027 pcck_buf = (phy_sts_cck_819xpci_t *)prxpkt;
5028 pofdm_buf = (phy_sts_ofdm_819xpci_t *)prxpkt;
5030 pstats->RxMIMOSignalQuality[0] = -1;
5031 pstats->RxMIMOSignalQuality[1] = -1;
5032 precord_stats->RxMIMOSignalQuality[0] = -1;
5033 precord_stats->RxMIMOSignalQuality[1] = -1;
5038 // (1)Hardware does not provide RSSI for CCK
5042 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5044 u8 report;//, cck_agc_rpt;
5047 char cck_adc_pwdb[4];
5050 #ifdef RTL8190P //Only 90P 2T4R need to check
5051 if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable && bpacket_match_bssid)
5053 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5055 tmp_pwdb = pcck_buf->adc_pwdb_X[i];
5056 cck_adc_pwdb[i] = (char)tmp_pwdb;
5057 cck_adc_pwdb[i] /= 2;
5058 pstats->cck_adc_pwdb[i] = precord_stats->cck_adc_pwdb[i] = cck_adc_pwdb[i];
5063 if (!priv->phy_reg824_bit9)
5065 report = pcck_buf->cck_agc_rpt & 0xc0;
5069 //Fixed by Jacken from Bryant 2008-03-20
5070 //Original value is -38 , -26 , -14 , -2
5071 //Fixed value is -35 , -23 , -11 , 6
5073 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
5076 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
5079 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
5082 rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e);
5088 report = pcck_buf->cck_agc_rpt & 0x60;
5093 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5096 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
5099 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5102 rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
5107 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5108 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5109 pstats->RecvSignalPower = rx_pwr_all;
5112 // (3) Get Signal Quality (EVM)
5114 if(bpacket_match_bssid)
5118 if(pstats->RxPWDBAll > 40)
5123 sq = pcck_buf->sq_rpt;
5125 if(pcck_buf->sq_rpt > 64)
5127 else if (pcck_buf->sq_rpt < 20)
5130 sq = ((64-sq) * 100) / 44;
5132 pstats->SignalQuality = precord_stats->SignalQuality = sq;
5133 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
5134 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
5140 // (1)Get RSSI for HT rate
5142 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
5144 // 2008/01/30 MH we will judge RF RX path now.
5145 if (priv->brfpath_rxenable[i])
5150 //Fixed by Jacken from Bryant 2008-03-20
5151 //Original value is 106
5152 #ifdef RTL8190P //Modify by Jacken 2008/03/31
5153 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
5155 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 110;
5158 //Get Rx snr value in DB
5159 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
5160 rx_snrX = (char)(tmp_rxsnr);
5163 /* Translate DBM to percentage. */
5164 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
5165 if (priv->brfpath_rxenable[i])
5168 /* Record Signal Strength for next packet */
5169 if(bpacket_match_bssid)
5171 pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
5172 precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
5178 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
5180 //Fixed by Jacken from Bryant 2008-03-20
5181 //Original value is 106
5182 rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
5183 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
5185 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
5186 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
5187 pstats->RecvSignalPower = rx_pwr_all;
5189 // (3)EVM of HT rate
5191 if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
5192 pdrvinfo->RxRate<=DESC90_RATEMCS15)
5193 max_spatial_stream = 2; //both spatial stream make sense
5195 max_spatial_stream = 1; //only spatial stream 1 makes sense
5197 for(i=0; i<max_spatial_stream; i++)
5199 tmp_rxevm = pofdm_buf->rxevm_X[i];
5200 rx_evmX = (char)(tmp_rxevm);
5202 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
5203 // fill most significant bit to "zero" when doing shifting operation which may change a negative
5204 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
5207 evm = rtl819x_evm_dbtopercentage(rx_evmX);
5208 if(bpacket_match_bssid)
5210 if(i==0) // Fill value in RFD, Get the first spatial stream only
5211 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
5212 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
5217 /* record rx statistics for debug */
5218 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
5219 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
5222 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
5223 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
5226 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;
5231 //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u1Byte)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u1Byte)(total_rssi/=RF90_PATH_MAX);
5232 // We can judge RX path number now.
5234 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
5239 rtl8192_record_rxdesc_forlateruse(
5240 struct ieee80211_rx_stats * psrc_stats,
5241 struct ieee80211_rx_stats * ptarget_stats
5244 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
5245 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
5246 //ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
5251 static void TranslateRxSignalStuff819xpci(struct net_device *dev,
5252 struct sk_buff *skb,
5253 struct ieee80211_rx_stats * pstats,
5254 prx_desc_819x_pci pdesc,
5255 prx_fwinfo_819x_pci pdrvinfo)
5257 // TODO: We must only check packet for current MAC address. Not finish
5258 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5259 bool bpacket_match_bssid, bpacket_toself;
5260 bool bPacketBeacon=false, bToSelfBA=false;
5261 struct ieee80211_hdr_3addr *hdr;
5264 // Get Signal Quality for only RX data queue (but not command queue)
5269 /* Get MAC frame start address. */
5270 tmp_buf = skb->data;
5272 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
5273 fc = le16_to_cpu(hdr->frame_ctl);
5274 type = WLAN_FC_GET_TYPE(fc);
5275 praddr = hdr->addr1;
5277 /* Check if the received packet is acceptabe. */
5278 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
5279 (!compare_ether_addr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
5280 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
5281 bpacket_toself = bpacket_match_bssid & (!compare_ether_addr(praddr, priv->ieee80211->dev->dev_addr));
5283 if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
5285 bPacketBeacon = true;
5287 if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
5289 if((!compare_ether_addr(praddr,dev->dev_addr)))
5296 // Process PHY information for previous packet (RSSI/PWDB/EVM)
5298 // Because phy information is contained in the last packet of AMPDU only, so driver
5299 // should process phy information of previous packet
5300 rtl8192_process_phyinfo(priv, tmp_buf, &priv->previous_stats, pstats);
5301 rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, &priv->previous_stats, bpacket_match_bssid,
5302 bpacket_toself ,bPacketBeacon, bToSelfBA);
5303 rtl8192_record_rxdesc_forlateruse(pstats, &priv->previous_stats);
5308 static void rtl8192_tx_resume(struct net_device *dev)
5310 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5311 struct ieee80211_device *ieee = priv->ieee80211;
5312 struct sk_buff *skb;
5315 for(queue_index = BK_QUEUE; queue_index < TXCMD_QUEUE;queue_index++) {
5316 while((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&&
5317 (priv->ieee80211->check_nic_enough_desc(dev,queue_index) > 0)) {
5318 /* 1. dequeue the packet from the wait queue */
5319 skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
5320 /* 2. tx the packet directly */
5321 ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/);
5326 static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
5328 rtl8192_tx_resume(priv->ieee80211->dev);
5331 /* Record the received data rate */
5332 static void UpdateReceivedRateHistogramStatistics8190(
5333 struct net_device *dev,
5334 struct ieee80211_rx_stats* pstats
5337 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5338 u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV
5340 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
5344 else if(pstats->bICV)
5347 if(pstats->bShortPreamble)
5348 preamble_guardinterval = 1;// short
5350 preamble_guardinterval = 0;// long
5352 switch(pstats->rate)
5357 case MGN_1M: rateIndex = 0; break;
5358 case MGN_2M: rateIndex = 1; break;
5359 case MGN_5_5M: rateIndex = 2; break;
5360 case MGN_11M: rateIndex = 3; break;
5364 case MGN_6M: rateIndex = 4; break;
5365 case MGN_9M: rateIndex = 5; break;
5366 case MGN_12M: rateIndex = 6; break;
5367 case MGN_18M: rateIndex = 7; break;
5368 case MGN_24M: rateIndex = 8; break;
5369 case MGN_36M: rateIndex = 9; break;
5370 case MGN_48M: rateIndex = 10; break;
5371 case MGN_54M: rateIndex = 11; break;
5373 // 11n High throughput rate
5375 case MGN_MCS0: rateIndex = 12; break;
5376 case MGN_MCS1: rateIndex = 13; break;
5377 case MGN_MCS2: rateIndex = 14; break;
5378 case MGN_MCS3: rateIndex = 15; break;
5379 case MGN_MCS4: rateIndex = 16; break;
5380 case MGN_MCS5: rateIndex = 17; break;
5381 case MGN_MCS6: rateIndex = 18; break;
5382 case MGN_MCS7: rateIndex = 19; break;
5383 case MGN_MCS8: rateIndex = 20; break;
5384 case MGN_MCS9: rateIndex = 21; break;
5385 case MGN_MCS10: rateIndex = 22; break;
5386 case MGN_MCS11: rateIndex = 23; break;
5387 case MGN_MCS12: rateIndex = 24; break;
5388 case MGN_MCS13: rateIndex = 25; break;
5389 case MGN_MCS14: rateIndex = 26; break;
5390 case MGN_MCS15: rateIndex = 27; break;
5391 default: rateIndex = 28; break;
5393 priv->stats.received_rate_histogram[0][rateIndex]++; //total
5394 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
5397 static void rtl8192_rx(struct net_device *dev)
5399 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5400 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
5401 bool unicast_packet = false;
5402 struct ieee80211_rx_stats stats = {
5406 .freq = IEEE80211_24GHZ_BAND,
5408 unsigned int count = priv->rxringcount;
5410 stats.nic_type = NIC_8192E;
5413 rx_desc_819x_pci *pdesc = &priv->rx_ring[priv->rx_idx];//rx descriptor
5414 struct sk_buff *skb = priv->rx_buf[priv->rx_idx];//rx pkt
5417 /* wait data to be filled by hardware */
5420 stats.bICV = pdesc->ICV;
5421 stats.bCRC = pdesc->CRC32;
5422 stats.bHwError = pdesc->CRC32 | pdesc->ICV;
5424 stats.Length = pdesc->Length;
5425 if(stats.Length < 24)
5426 stats.bHwError |= 1;
5428 if(stats.bHwError) {
5429 stats.bShift = false;
5432 prx_fwinfo_819x_pci pDrvInfo = NULL;
5433 struct sk_buff *new_skb = dev_alloc_skb(priv->rxbuffersize);
5435 if (unlikely(!new_skb)) {
5439 stats.RxDrvInfoSize = pdesc->RxDrvInfoSize;
5440 stats.RxBufShift = ((pdesc->Shift)&0x03);
5441 stats.Decrypted = !pdesc->SWDec;
5443 pci_dma_sync_single_for_cpu(priv->pdev,
5444 *((dma_addr_t *)skb->cb),
5446 PCI_DMA_FROMDEVICE);
5447 skb_put(skb, pdesc->Length);
5448 pDrvInfo = (rx_fwinfo_819x_pci *)(skb->data + stats.RxBufShift);
5449 skb_reserve(skb, stats.RxDrvInfoSize + stats.RxBufShift);
5451 stats.rate = HwRateToMRate90((bool)pDrvInfo->RxHT, (u8)pDrvInfo->RxRate);
5452 stats.bShortPreamble = pDrvInfo->SPLCP;
5454 /* it is debug only. It should be disabled in released driver.
5455 * 2007.1.11 by Emily
5457 UpdateReceivedRateHistogramStatistics8190(dev, &stats);
5459 stats.bIsAMPDU = (pDrvInfo->PartAggr==1);
5460 stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1);
5462 stats.TimeStampLow = pDrvInfo->TSFL;
5463 stats.TimeStampHigh = read_nic_dword(dev, TSFR+4);
5465 UpdateRxPktTimeStamp8190(dev, &stats);
5468 // Get Total offset of MPDU Frame Body
5470 if((stats.RxBufShift + stats.RxDrvInfoSize) > 0)
5473 stats.RxIs40MHzPacket = pDrvInfo->BW;
5476 TranslateRxSignalStuff819xpci(dev,skb, &stats, pdesc, pDrvInfo);
5479 if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1)
5480 RT_TRACE(COMP_RXDESC, "pDrvInfo->FirstAGGR = %d, pDrvInfo->PartAggr = %d\n",
5481 pDrvInfo->FirstAGGR, pDrvInfo->PartAggr);
5482 skb_trim(skb, skb->len - 4/*sCrcLng*/);
5483 /* rx packets statistics */
5484 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
5485 unicast_packet = false;
5487 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
5489 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
5492 /* unicast packet */
5493 unicast_packet = true;
5496 stats.packetlength = stats.Length-4;
5497 stats.fraglength = stats.packetlength;
5498 stats.fragoffset = 0;
5499 stats.ntotalfrag = 1;
5501 if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){
5502 dev_kfree_skb_any(skb);
5505 if(unicast_packet) {
5506 priv->stats.rxbytesunicast += skb->len;
5510 pci_unmap_single(priv->pdev, *((dma_addr_t *) skb->cb),
5511 priv->rxbuffersize, PCI_DMA_FROMDEVICE);
5514 priv->rx_buf[priv->rx_idx] = skb;
5515 *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE);
5520 pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb));
5522 pdesc->Length = priv->rxbuffersize;
5523 if (priv->rx_idx == priv->rxringcount-1)
5525 priv->rx_idx = (priv->rx_idx + 1) % priv->rxringcount;
5530 static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
5532 rtl8192_rx(priv->ieee80211->dev);
5534 write_nic_dword(priv->ieee80211->dev, INTA_MASK,read_nic_dword(priv->ieee80211->dev, INTA_MASK) | IMR_RDU);
5537 static const struct net_device_ops rtl8192_netdev_ops = {
5538 .ndo_open = rtl8192_open,
5539 .ndo_stop = rtl8192_close,
5540 .ndo_tx_timeout = tx_timeout,
5541 .ndo_do_ioctl = rtl8192_ioctl,
5542 .ndo_set_multicast_list = r8192_set_multicast,
5543 .ndo_set_mac_address = r8192_set_mac_adr,
5544 .ndo_start_xmit = ieee80211_rtl_xmit,
5547 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
5548 const struct pci_device_id *id)
5550 unsigned long ioaddr = 0;
5551 struct net_device *dev = NULL;
5552 struct r8192_priv *priv= NULL;
5556 #ifdef CONFIG_RTL8192_IO_MAP
5557 unsigned long pio_start, pio_len, pio_flags;
5559 unsigned long pmem_start, pmem_len, pmem_flags;
5560 #endif //end #ifdef RTL_IO_MAP
5562 RT_TRACE(COMP_INIT,"Configuring chip resources");
5564 if( pci_enable_device (pdev) ){
5565 RT_TRACE(COMP_ERR,"Failed to enable PCI device");
5569 pci_set_master(pdev);
5570 //pci_set_wmi(pdev);
5571 pci_set_dma_mask(pdev, 0xffffff00ULL);
5572 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
5573 dev = alloc_ieee80211(sizeof(struct r8192_priv));
5579 pci_set_drvdata(pdev, dev);
5580 SET_NETDEV_DEV(dev, &pdev->dev);
5581 priv = ieee80211_priv(dev);
5582 priv->ieee80211 = netdev_priv(dev);
5584 if((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304)){
5585 priv->ieee80211->bSupportRemoteWakeUp = 1;
5588 priv->ieee80211->bSupportRemoteWakeUp = 0;
5591 #ifdef CONFIG_RTL8192_IO_MAP
5593 pio_start = (unsigned long)pci_resource_start (pdev, 0);
5594 pio_len = (unsigned long)pci_resource_len (pdev, 0);
5595 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
5597 if (!(pio_flags & IORESOURCE_IO)) {
5598 RT_TRACE(COMP_ERR,"region #0 not a PIO resource, aborting");
5602 //DMESG("IO space @ 0x%08lx", pio_start );
5603 if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){
5604 RT_TRACE(COMP_ERR,"request_region failed!");
5609 dev->base_addr = ioaddr; // device I/O address
5613 pmem_start = pci_resource_start(pdev, 1);
5614 pmem_len = pci_resource_len(pdev, 1);
5615 pmem_flags = pci_resource_flags (pdev, 1);
5617 if (!(pmem_flags & IORESOURCE_MEM)) {
5618 RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting");
5622 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
5623 if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) {
5624 RT_TRACE(COMP_ERR,"request_mem_region failed!");
5629 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
5630 if( ioaddr == (unsigned long)NULL ){
5631 RT_TRACE(COMP_ERR,"ioremap failed!");
5632 // release_mem_region( pmem_start, pmem_len );
5636 dev->mem_start = ioaddr; // shared mem start
5637 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
5639 #endif //end #ifdef RTL_IO_MAP
5641 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5642 * PCI Tx retries from interfering with C3 CPU state */
5643 pci_write_config_byte(pdev, 0x41, 0x00);
5646 pci_read_config_byte(pdev, 0x05, &unit);
5647 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
5649 dev->irq = pdev->irq;
5652 dev->netdev_ops = &rtl8192_netdev_ops;
5654 dev->wireless_handlers = &r8192_wx_handlers_def;
5655 dev->type=ARPHRD_ETHER;
5657 dev->watchdog_timeo = HZ*3;
5659 if (dev_alloc_name(dev, ifname) < 0){
5660 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
5661 strcpy(ifname, "wlan%d");
5662 dev_alloc_name(dev, ifname);
5665 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
5666 if(rtl8192_init(dev)!=0){
5667 RT_TRACE(COMP_ERR, "Initialization failed");
5671 register_netdev(dev);
5672 RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
5673 rtl8192_proc_init_one(dev);
5676 RT_TRACE(COMP_INIT, "Driver probe completed\n");
5681 #ifdef CONFIG_RTL8180_IO_MAP
5683 if( dev->base_addr != 0 ){
5685 release_region(dev->base_addr,
5686 pci_resource_len(pdev, 0) );
5689 if( dev->mem_start != (unsigned long)NULL ){
5690 iounmap( (void *)dev->mem_start );
5691 release_mem_region( pci_resource_start(pdev, 1),
5692 pci_resource_len(pdev, 1) );
5694 #endif //end #ifdef RTL_IO_MAP
5700 free_irq(dev->irq, dev);
5703 free_ieee80211(dev);
5707 pci_disable_device(pdev);
5709 DMESG("wlan driver load failed\n");
5710 pci_set_drvdata(pdev, NULL);
5715 /* detach all the work and timer structure declared or inititialized
5716 * in r8192_init function.
5718 static void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
5720 /* call cancel_work_sync instead of cancel_delayed_work if and only if Linux_version_code
5721 * is or is newer than 2.6.20 and work structure is defined to be struct work_struct.
5722 * Otherwise call cancel_delayed_work is enough.
5723 * FIXME (2.6.20 should 2.6.22, work_struct should not cancel)
5725 cancel_delayed_work(&priv->watch_dog_wq);
5726 cancel_delayed_work(&priv->update_beacon_wq);
5727 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5728 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5730 cancel_delayed_work(&priv->gpio_change_rf_wq);
5732 cancel_work_sync(&priv->reset_wq);
5733 cancel_work_sync(&priv->qos_activate);
5734 //cancel_work_sync(&priv->SetBWModeWorkItem);
5735 //cancel_work_sync(&priv->SwChnlWorkItem);
5740 static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
5742 struct net_device *dev = pci_get_drvdata(pdev);
5743 struct r8192_priv *priv ;
5747 unregister_netdev(dev);
5749 priv=ieee80211_priv(dev);
5751 rtl8192_proc_remove_one(dev);
5754 if (priv->pFirmware)
5756 vfree(priv->pFirmware);
5757 priv->pFirmware = NULL;
5759 // priv->rf_close(dev);
5760 // rtl8192_usb_deleteendpoints(dev);
5761 destroy_workqueue(priv->priv_wq);
5762 /* redundant with rtl8192_down */
5763 // rtl8192_irq_disable(dev);
5764 // rtl8192_reset(dev);
5768 /* free tx/rx rings */
5769 rtl8192_free_rx_ring(dev);
5770 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
5771 rtl8192_free_tx_ring(dev, i);
5776 printk("Freeing irq %d\n",dev->irq);
5777 free_irq(dev->irq, dev);
5782 #ifdef CONFIG_RTL8180_IO_MAP
5784 if( dev->base_addr != 0 ){
5786 release_region(dev->base_addr,
5787 pci_resource_len(pdev, 0) );
5790 if( dev->mem_start != (unsigned long)NULL ){
5791 iounmap( (void *)dev->mem_start );
5792 release_mem_region( pci_resource_start(pdev, 1),
5793 pci_resource_len(pdev, 1) );
5795 #endif /*end #ifdef RTL_IO_MAP*/
5796 free_ieee80211(dev);
5800 pci_disable_device(pdev);
5801 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
5804 extern int ieee80211_rtl_init(void);
5805 extern void ieee80211_rtl_exit(void);
5807 static int __init rtl8192_pci_module_init(void)
5811 retval = ieee80211_rtl_init();
5815 printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
5816 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
5817 RT_TRACE(COMP_INIT, "Initializing module");
5818 rtl8192_proc_module_init();
5819 if(0!=pci_register_driver(&rtl8192_pci_driver))
5821 DMESG("No device found");
5822 /*pci_unregister_driver (&rtl8192_pci_driver);*/
5829 static void __exit rtl8192_pci_module_exit(void)
5831 pci_unregister_driver(&rtl8192_pci_driver);
5833 RT_TRACE(COMP_DOWN, "Exiting");
5834 rtl8192_proc_module_remove();
5835 ieee80211_rtl_exit();
5838 static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
5840 struct net_device *dev = (struct net_device *) netdev;
5841 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5842 unsigned long flags;
5844 irqreturn_t ret = IRQ_HANDLED;
5846 spin_lock_irqsave(&priv->irq_th_lock, flags);
5848 /* We should return IRQ_NONE, but for now let me keep this */
5849 if (priv->irq_enabled == 0)
5854 inta = read_nic_dword(dev, ISR); /* & priv->IntrMask; */
5855 write_nic_dword(dev, ISR, inta); /* reset int situation */
5859 * most probably we can safely return IRQ_NONE,
5860 * but for now is better to avoid problems
5865 if (inta == 0xffff) {
5870 if (!netif_running(dev))
5873 if (inta & IMR_TBDOK) {
5874 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
5875 rtl8192_tx_isr(dev, BEACON_QUEUE);
5876 priv->stats.txbeaconokint++;
5879 if (inta & IMR_TBDER) {
5880 RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
5881 rtl8192_tx_isr(dev, BEACON_QUEUE);
5882 priv->stats.txbeaconerr++;
5885 if (inta & IMR_MGNTDOK ) {
5886 RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
5887 priv->stats.txmanageokint++;
5888 rtl8192_tx_isr(dev,MGNT_QUEUE);
5891 if (inta & IMR_COMDOK)
5893 priv->stats.txcmdpktokint++;
5894 rtl8192_tx_isr(dev, TXCMD_QUEUE);
5897 if (inta & IMR_ROK) {
5898 priv->stats.rxint++;
5899 tasklet_schedule(&priv->irq_rx_tasklet);
5902 if (inta & IMR_BcnInt) {
5903 RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n");
5904 tasklet_schedule(&priv->irq_prepare_beacon_tasklet);
5907 if (inta & IMR_RDU) {
5908 RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n");
5909 priv->stats.rxrdu++;
5910 /* reset int situation */
5911 write_nic_dword(dev, INTA_MASK, read_nic_dword(dev, INTA_MASK) & ~IMR_RDU);
5912 tasklet_schedule(&priv->irq_rx_tasklet);
5915 if (inta & IMR_RXFOVW) {
5916 RT_TRACE(COMP_INTR, "rx overflow !\n");
5917 priv->stats.rxoverflow++;
5918 tasklet_schedule(&priv->irq_rx_tasklet);
5921 if (inta & IMR_TXFOVW)
5922 priv->stats.txoverflow++;
5924 if (inta & IMR_BKDOK) {
5925 RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
5926 priv->stats.txbkokint++;
5927 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
5928 rtl8192_tx_isr(dev, BK_QUEUE);
5931 if (inta & IMR_BEDOK) {
5932 RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
5933 priv->stats.txbeokint++;
5934 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
5935 rtl8192_tx_isr(dev, BE_QUEUE);
5938 if (inta & IMR_VIDOK) {
5939 RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
5940 priv->stats.txviokint++;
5941 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
5942 rtl8192_tx_isr(dev, VI_QUEUE);
5945 if (inta & IMR_VODOK) {
5946 priv->stats.txvookint++;
5947 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
5948 rtl8192_tx_isr(dev, VO_QUEUE);
5952 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
5957 void EnableHWSecurityConfig8192(struct net_device *dev)
5959 u8 SECR_value = 0x0;
5960 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5961 struct ieee80211_device* ieee = priv->ieee80211;
5963 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
5965 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
5967 SECR_value |= SCR_RxUseDK;
5968 SECR_value |= SCR_TxUseDK;
5970 else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
5972 SECR_value |= SCR_RxUseDK;
5973 SECR_value |= SCR_TxUseDK;
5978 //add HWSec active enable here.
5979 //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
5980 ieee->hwsec_active = 1;
5982 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
5984 ieee->hwsec_active = 0;
5985 SECR_value &= ~SCR_RxDecEnable;
5988 RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__,
5989 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
5991 write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK );
5995 #define TOTAL_CAM_ENTRY 32
5996 //#define CAM_CONTENT_COUNT 8
5997 void setKey( struct net_device *dev,
6005 u32 TargetCommand = 0;
6006 u32 TargetContent = 0;
6010 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6011 RT_RF_POWER_STATE rtState;
6012 rtState = priv->ieee80211->eRFPowerState;
6013 if(priv->ieee80211->PowerSaveControl.bInactivePs){
6014 if(rtState == eRfOff){
6015 if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
6017 RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
6018 //up(&priv->wx_sem);
6022 down(&priv->ieee80211->ips_sem);
6024 up(&priv->ieee80211->ips_sem);
6028 priv->ieee80211->is_set_key = true;
6030 if (EntryNo >= TOTAL_CAM_ENTRY)
6031 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
6033 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr);
6036 usConfig |= BIT15 | (KeyType<<2);
6038 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
6039 // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
6042 for(i=0 ; i<CAM_CONTENT_COUNT; i++){
6043 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
6044 TargetCommand |= BIT31|BIT16;
6046 if(i==0){//MAC|Config
6047 TargetContent = (u32)(*(MacAddr+0)) << 16|
6048 (u32)(*(MacAddr+1)) << 24|
6051 write_nic_dword(dev, WCAMI, TargetContent);
6052 write_nic_dword(dev, RWCAM, TargetCommand);
6055 TargetContent = (u32)(*(MacAddr+2)) |
6056 (u32)(*(MacAddr+3)) << 8|
6057 (u32)(*(MacAddr+4)) << 16|
6058 (u32)(*(MacAddr+5)) << 24;
6059 write_nic_dword(dev, WCAMI, TargetContent);
6060 write_nic_dword(dev, RWCAM, TargetCommand);
6062 else { //Key Material
6063 if(KeyContent != NULL)
6065 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
6066 write_nic_dword(dev, RWCAM, TargetCommand);
6070 RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig);
6073 bool NicIFEnableNIC(struct net_device* dev)
6075 RT_STATUS init_status = RT_STATUS_SUCCESS;
6076 struct r8192_priv* priv = ieee80211_priv(dev);
6077 PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
6081 RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__FUNCTION__);
6082 priv->bdisable_nic = false; //YJ,add,091111
6085 // <1> Reset memory: descriptor, buffer,..
6086 //NicIFResetMemory(Adapter);
6088 // <2> Enable Adapter
6089 //priv->bfirst_init = true;
6090 init_status = rtl8192_adapter_start(dev);
6091 if (init_status != RT_STATUS_SUCCESS) {
6092 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
6093 priv->bdisable_nic = false; //YJ,add,091111
6096 RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC);
6097 //priv->bfirst_init = false;
6099 // <3> Enable Interrupt
6100 rtl8192_irq_enable(dev);
6101 priv->bdisable_nic = false;
6103 return (init_status == RT_STATUS_SUCCESS);
6106 bool NicIFDisableNIC(struct net_device* dev)
6109 struct r8192_priv* priv = ieee80211_priv(dev);
6111 // <1> Disable Interrupt
6113 priv->bdisable_nic = true; //YJ,move,091109
6114 tmp_state = priv->ieee80211->state;
6116 ieee80211_softmac_stop_protocol(priv->ieee80211, false);
6118 priv->ieee80211->state = tmp_state;
6119 rtl8192_cancel_deferred_work(priv);
6120 rtl8192_irq_disable(dev);
6121 // <2> Stop all timer
6123 // <3> Disable Adapter
6124 rtl8192_halt_adapter(dev, false);
6125 // priv->bdisable_nic = true;
6130 module_init(rtl8192_pci_module_init);
6131 module_exit(rtl8192_pci_module_exit);