1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 * Linux device driver for RTL8192U
5 * Based on the r8187 driver, which is:
6 * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, 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>
27 #ifndef CONFIG_FORCE_HARD_FLOAT
28 double __floatsidf(int i)
33 unsigned int __fixunsdfsi(double d)
38 double __adddf3(double a, double b)
43 double __addsf3(float a, float b)
48 double __subdf3(double a, double b)
53 double __extendsfdf2(float a)
63 #undef RX_DONT_PASS_UL
65 #undef DEBUG_RX_VERBOSE
71 #undef DEBUG_TX_FILLDESC
76 #undef DEBUG_REGISTERS
78 #undef DEBUG_IRQ_TASKLET
82 #define CONFIG_RTL8192_IO_MAP
84 #include <asm/uaccess.h>
85 #include "r8192U_hw.h"
87 #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
88 #include "r8180_93cx6.h" /* Card EEPROM */
89 #include "r8192U_wx.h"
90 #include "r819xU_phy.h" //added by WB 4.30.2008
91 #include "r819xU_phyreg.h"
92 #include "r819xU_cmdpkt.h"
93 #include "r8192U_dm.h"
94 #include <linux/usb.h>
95 #include <linux/slab.h>
96 #include <linux/proc_fs.h>
97 #include <linux/seq_file.h>
98 // FIXME: check if 2.6.7 is ok
101 //set here to open your trace code. //WB
102 u32 rt_global_debug_component = COMP_DOWN |
104 COMP_ERR; //always open err flags on
106 #define TOTAL_CAM_ENTRY 32
107 #define CAM_CONTENT_COUNT 8
109 static const struct usb_device_id rtl8192_usb_id_tbl[] = {
111 {USB_DEVICE(0x0bda, 0x8709)},
113 {USB_DEVICE(0x07aa, 0x0043)},
115 {USB_DEVICE(0x050d, 0x805E)},
117 {USB_DEVICE(0x0df6, 0x0031)},
119 {USB_DEVICE(0x1740, 0x9201)},
121 {USB_DEVICE(0x2001, 0x3301)},
123 {USB_DEVICE(0x5a57, 0x0290)},
125 {USB_DEVICE(0x043e, 0x7a01)},
129 MODULE_LICENSE("GPL");
130 MODULE_VERSION("V 1.1");
131 MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
132 MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
134 static char *ifname = "wlan%d";
135 static int hwwep = 1; //default use hw. set 0 to use software security
136 static int channels = 0x3fff;
140 module_param(ifname, charp, S_IRUGO|S_IWUSR);
141 module_param(hwwep, int, S_IRUGO|S_IWUSR);
142 module_param(channels, int, S_IRUGO|S_IWUSR);
144 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
145 MODULE_PARM_DESC(hwwep, " Try to use hardware security support. ");
146 MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");
148 static int rtl8192_usb_probe(struct usb_interface *intf,
149 const struct usb_device_id *id);
150 static void rtl8192_usb_disconnect(struct usb_interface *intf);
153 static struct usb_driver rtl8192_usb_driver = {
154 .name = RTL819xU_MODULE_NAME, /* Driver name */
155 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
156 .probe = rtl8192_usb_probe, /* probe fn */
157 .disconnect = rtl8192_usb_disconnect, /* remove fn */
158 .suspend = NULL, /* PM suspend fn */
159 .resume = NULL, /* PM resume fn */
163 typedef struct _CHANNEL_LIST {
166 } CHANNEL_LIST, *PCHANNEL_LIST;
168 static CHANNEL_LIST ChannelPlan[] = {
169 {{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
170 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
171 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
172 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
173 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
174 {{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
175 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
176 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
177 {{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
178 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
179 {{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
182 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
184 int i, max_chan = -1, min_chan = -1;
185 struct ieee80211_device *ieee = priv->ieee80211;
186 switch (channel_plan) {
187 case COUNTRY_CODE_FCC:
188 case COUNTRY_CODE_IC:
189 case COUNTRY_CODE_ETSI:
190 case COUNTRY_CODE_SPAIN:
191 case COUNTRY_CODE_FRANCE:
192 case COUNTRY_CODE_MKK:
193 case COUNTRY_CODE_MKK1:
194 case COUNTRY_CODE_ISRAEL:
195 case COUNTRY_CODE_TELEC:
196 case COUNTRY_CODE_MIC:
198 ieee->bGlobalDomain = false;
199 //actually 8225 & 8256 rf chips only support B,G,24N mode
200 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
204 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __func__);
206 if (ChannelPlan[channel_plan].Len != 0) {
207 // Clear old channel map
208 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
209 // Set new channel map
210 for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
211 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
213 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
218 case COUNTRY_CODE_GLOBAL_DOMAIN:
219 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
221 ieee->bGlobalDomain = true;
232 static void CamResetAllEntry(struct net_device *dev)
235 //2004/02/11 In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
236 // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
237 // In this condition, Cam can not be reset because upper layer will not set this static key again.
238 ulcommand |= BIT31|BIT30;
239 write_nic_dword(dev, RWCAM, ulcommand);
244 void write_cam(struct net_device *dev, u8 addr, u32 data)
246 write_nic_dword(dev, WCAMI, data);
247 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff));
250 u32 read_cam(struct net_device *dev, u8 addr)
254 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff));
255 read_nic_dword(dev, 0xa8, &data);
259 void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
262 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
263 struct usb_device *udev = priv->udev;
265 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
266 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
267 indx|0xfe00, 0, &data, 1, HZ / 2);
270 netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n", status);
273 int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
276 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
277 struct usb_device *udev = priv->udev;
279 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
280 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
281 indx|0xfe00, 0, data, 1, HZ / 2);
284 netdev_err(dev, "%s failure status: %d\n", __func__, status);
290 //as 92U has extend page from 4 to 16, so modify functions below.
291 void write_nic_byte(struct net_device *dev, int indx, u8 data)
295 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
296 struct usb_device *udev = priv->udev;
298 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
299 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
300 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
303 netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
309 void write_nic_word(struct net_device *dev, int indx, u16 data)
314 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
315 struct usb_device *udev = priv->udev;
317 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
318 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
319 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
322 netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
327 void write_nic_dword(struct net_device *dev, int indx, u32 data)
332 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
333 struct usb_device *udev = priv->udev;
335 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
336 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
337 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
341 netdev_err(dev, "write_nic_dword TimeOut! status: %d\n", status);
347 int read_nic_byte(struct net_device *dev, int indx, u8 *data)
350 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
351 struct usb_device *udev = priv->udev;
353 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
354 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
355 (indx&0xff)|0xff00, (indx>>8)&0x0f, data, 1, HZ / 2);
358 netdev_err(dev, "%s failure status: %d\n", __func__, status);
367 int read_nic_word(struct net_device *dev, int indx, u16 *data)
370 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
371 struct usb_device *udev = priv->udev;
373 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
374 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
375 (indx&0xff)|0xff00, (indx>>8)&0x0f,
379 netdev_err(dev, "%s failure status: %d\n", __func__, status);
386 static int read_nic_word_E(struct net_device *dev, int indx, u16 *data)
389 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
390 struct usb_device *udev = priv->udev;
392 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
393 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
394 indx|0xfe00, 0, data, 2, HZ / 2);
397 netdev_err(dev, "%s failure status: %d\n", __func__, status);
404 int read_nic_dword(struct net_device *dev, int indx, u32 *data)
408 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
409 struct usb_device *udev = priv->udev;
411 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
412 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
413 (indx&0xff)|0xff00, (indx>>8)&0x0f,
417 netdev_err(dev, "%s failure status: %d\n", __func__, status);
424 /* u8 read_phy_cck(struct net_device *dev, u8 adr); */
425 /* u8 read_phy_ofdm(struct net_device *dev, u8 adr); */
426 /* this might still called in what was the PHY rtl8185/rtl8192 common code
427 * plans are to possibility turn it again in one common code...
429 inline void force_pci_posting(struct net_device *dev)
433 static struct net_device_stats *rtl8192_stats(struct net_device *dev);
434 void rtl8192_commit(struct net_device *dev);
435 void rtl8192_restart(struct work_struct *work);
436 void watch_dog_timer_callback(unsigned long data);
438 /****************************************************************************
439 * -----------------------------PROCFS STUFF-------------------------
440 *****************************************************************************
443 static struct proc_dir_entry *rtl8192_proc;
445 static int proc_get_stats_ap(struct seq_file *m, void *v)
447 struct net_device *dev = m->private;
448 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
449 struct ieee80211_device *ieee = priv->ieee80211;
450 struct ieee80211_network *target;
452 list_for_each_entry(target, &ieee->network_list, list) {
453 const char *wpa = "non_WPA";
454 if (target->wpa_ie_len > 0 || target->rsn_ie_len > 0)
457 seq_printf(m, "%s %s\n", target->ssid, wpa);
463 static int proc_get_registers(struct seq_file *m, void *v)
465 struct net_device *dev = m->private;
466 int i, n, max = 0xff;
469 seq_puts(m, "\n####################page 0##################\n ");
471 for (n = 0; n <= max;) {
472 seq_printf(m, "\nD: %2x > ", n);
474 for (i = 0; i < 16 && n <= max; i++, n++) {
475 read_nic_byte(dev, 0x000|n, &byte_rd);
476 seq_printf(m, "%2x ", byte_rd);
480 seq_puts(m, "\n####################page 1##################\n ");
481 for (n = 0; n <= max;) {
482 seq_printf(m, "\nD: %2x > ", n);
484 for (i = 0; i < 16 && n <= max; i++, n++) {
485 read_nic_byte(dev, 0x100|n, &byte_rd);
486 seq_printf(m, "%2x ", byte_rd);
490 seq_puts(m, "\n####################page 3##################\n ");
491 for (n = 0; n <= max;) {
492 seq_printf(m, "\nD: %2x > ", n);
494 for (i = 0; i < 16 && n <= max; i++, n++) {
495 read_nic_byte(dev, 0x300|n, &byte_rd);
496 seq_printf(m, "%2x ", byte_rd);
504 static int proc_get_stats_tx(struct seq_file *m, void *v)
506 struct net_device *dev = m->private;
507 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
510 "TX VI priority ok int: %lu\n"
511 "TX VI priority error int: %lu\n"
512 "TX VO priority ok int: %lu\n"
513 "TX VO priority error int: %lu\n"
514 "TX BE priority ok int: %lu\n"
515 "TX BE priority error int: %lu\n"
516 "TX BK priority ok int: %lu\n"
517 "TX BK priority error int: %lu\n"
518 "TX MANAGE priority ok int: %lu\n"
519 "TX MANAGE priority error int: %lu\n"
520 "TX BEACON priority ok int: %lu\n"
521 "TX BEACON priority error int: %lu\n"
522 "TX queue resume: %lu\n"
523 "TX queue stopped?: %d\n"
524 "TX fifo overflow: %lu\n"
529 "TX VI dropped: %lu\n"
530 "TX VO dropped: %lu\n"
531 "TX BE dropped: %lu\n"
532 "TX BK dropped: %lu\n"
533 "TX total data packets %lu\n",
534 priv->stats.txviokint,
536 priv->stats.txvookint,
538 priv->stats.txbeokint,
540 priv->stats.txbkokint,
542 priv->stats.txmanageokint,
543 priv->stats.txmanageerr,
544 priv->stats.txbeaconokint,
545 priv->stats.txbeaconerr,
546 priv->stats.txresumed,
547 netif_queue_stopped(dev),
548 priv->stats.txoverflow,
549 atomic_read(&(priv->tx_pending[VI_PRIORITY])),
550 atomic_read(&(priv->tx_pending[VO_PRIORITY])),
551 atomic_read(&(priv->tx_pending[BE_PRIORITY])),
552 atomic_read(&(priv->tx_pending[BK_PRIORITY])),
553 priv->stats.txvidrop,
554 priv->stats.txvodrop,
555 priv->stats.txbedrop,
556 priv->stats.txbkdrop,
557 priv->stats.txdatapkt
563 static int proc_get_stats_rx(struct seq_file *m, void *v)
565 struct net_device *dev = m->private;
566 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
570 "RX urb status error: %lu\n"
571 "RX invalid urb error: %lu\n",
572 priv->stats.rxoktotal,
573 priv->stats.rxstaterr,
574 priv->stats.rxurberr);
579 static void rtl8192_proc_module_init(void)
581 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
582 rtl8192_proc = proc_mkdir(RTL819xU_MODULE_NAME, init_net.proc_net);
586 * seq_file wrappers for procfile show routines.
588 static int rtl8192_proc_open(struct inode *inode, struct file *file)
590 struct net_device *dev = proc_get_parent_data(inode);
591 int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
593 return single_open(file, show, dev);
596 static const struct file_operations rtl8192_proc_fops = {
597 .open = rtl8192_proc_open,
600 .release = single_release,
604 * Table of proc files we need to create.
606 struct rtl8192_proc_file {
608 int (*show)(struct seq_file *, void *);
611 static const struct rtl8192_proc_file rtl8192_proc_files[] = {
612 { "stats-rx", &proc_get_stats_rx },
613 { "stats-tx", &proc_get_stats_tx },
614 { "stats-ap", &proc_get_stats_ap },
615 { "registers", &proc_get_registers },
619 static void rtl8192_proc_init_one(struct net_device *dev)
621 const struct rtl8192_proc_file *f;
622 struct proc_dir_entry *dir;
625 dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
627 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
632 for (f = rtl8192_proc_files; f->name[0]; f++) {
633 if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
634 &rtl8192_proc_fops, f->show)) {
635 RT_TRACE(COMP_ERR, "Unable to initialize "
636 "/proc/net/rtl8192/%s/%s\n",
644 static void rtl8192_proc_remove_one(struct net_device *dev)
646 remove_proc_subtree(dev->name, rtl8192_proc);
649 /****************************************************************************
650 -----------------------------MISC STUFF-------------------------
651 *****************************************************************************/
653 short check_nic_enough_desc(struct net_device *dev, int queue_index)
655 struct r8192_priv *priv = ieee80211_priv(dev);
656 int used = atomic_read(&priv->tx_pending[queue_index]);
658 return (used < MAX_TX_URB);
661 static void tx_timeout(struct net_device *dev)
663 struct r8192_priv *priv = ieee80211_priv(dev);
665 schedule_work(&priv->reset_wq);
669 /* this is only for debug */
670 void dump_eprom(struct net_device *dev)
673 for (i = 0; i < 63; i++)
674 RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev, i));
677 void rtl8192_update_msr(struct net_device *dev)
679 struct r8192_priv *priv = ieee80211_priv(dev);
682 read_nic_byte(dev, MSR, &msr);
683 msr &= ~MSR_LINK_MASK;
685 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
686 * msr must be updated if the state is ASSOCIATING.
687 * this is intentional and make sense for ad-hoc and
688 * master (see the create BSS/IBSS func)
690 if (priv->ieee80211->state == IEEE80211_LINKED) {
692 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
693 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
694 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
695 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
696 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
697 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
700 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
703 write_nic_byte(dev, MSR, msr);
706 void rtl8192_set_chan(struct net_device *dev, short ch)
708 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
709 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
712 /* this hack should avoid frame TX during channel setting*/
715 //need to implement rf set channel here WB
717 if (priv->rf_set_chan)
718 priv->rf_set_chan(dev, priv->chan);
723 static void rtl8192_rx_isr(struct urb *urb);
725 static u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
728 #ifdef USB_RX_AGGREGATION_SUPPORT
729 if (pstats->bisrxaggrsubframe)
730 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
731 + pstats->RxBufShift + 8);
734 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
735 + pstats->RxBufShift);
738 static int rtl8192_rx_initiate(struct net_device *dev)
740 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
743 struct rtl8192_rx_info *info;
745 /* nomal packet rx procedure */
746 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB) {
747 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
750 entry = usb_alloc_urb(0, GFP_KERNEL);
755 usb_fill_bulk_urb(entry, priv->udev,
756 usb_rcvbulkpipe(priv->udev, 3), skb_tail_pointer(skb),
757 RX_URB_SIZE, rtl8192_rx_isr, skb);
758 info = (struct rtl8192_rx_info *) skb->cb;
761 info->out_pipe = 3; //denote rx normal packet queue
762 skb_queue_tail(&priv->rx_queue, skb);
763 usb_submit_urb(entry, GFP_KERNEL);
766 /* command packet rx procedure */
767 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
768 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
771 entry = usb_alloc_urb(0, GFP_KERNEL);
776 usb_fill_bulk_urb(entry, priv->udev,
777 usb_rcvbulkpipe(priv->udev, 9), skb_tail_pointer(skb),
778 RX_URB_SIZE, rtl8192_rx_isr, skb);
779 info = (struct rtl8192_rx_info *) skb->cb;
782 info->out_pipe = 9; //denote rx cmd packet queue
783 skb_queue_tail(&priv->rx_queue, skb);
784 usb_submit_urb(entry, GFP_KERNEL);
790 void rtl8192_set_rxconf(struct net_device *dev)
792 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
795 read_nic_dword(dev, RCR, &rxconf);
796 rxconf = rxconf & ~MAC_FILTER_MASK;
797 rxconf = rxconf | RCR_AMF;
798 rxconf = rxconf | RCR_ADF;
799 rxconf = rxconf | RCR_AB;
800 rxconf = rxconf | RCR_AM;
802 if (dev->flags & IFF_PROMISC)
803 DMESG("NIC in promisc mode");
805 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR ||
806 dev->flags & IFF_PROMISC) {
807 rxconf = rxconf | RCR_AAP;
809 rxconf = rxconf | RCR_APM;
810 rxconf = rxconf | RCR_CBSSID;
814 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR) {
815 rxconf = rxconf | RCR_AICV;
816 rxconf = rxconf | RCR_APWRMGT;
819 if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
820 rxconf = rxconf | RCR_ACRC32;
823 rxconf = rxconf & ~RX_FIFO_THRESHOLD_MASK;
824 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
825 rxconf = rxconf & ~MAX_RX_DMA_MASK;
826 rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
828 rxconf = rxconf | RCR_ONLYERLPKT;
830 write_nic_dword(dev, RCR, rxconf);
833 void rtl8192_rx_enable(struct net_device *dev)
835 rtl8192_rx_initiate(dev);
839 void rtl8192_tx_enable(struct net_device *dev)
845 void rtl8192_rtx_disable(struct net_device *dev)
848 struct r8192_priv *priv = ieee80211_priv(dev);
850 struct rtl8192_rx_info *info;
852 read_nic_byte(dev, CMDR, &cmd);
853 write_nic_byte(dev, CMDR, cmd & ~(CR_TE|CR_RE));
854 force_pci_posting(dev);
857 while ((skb = __skb_dequeue(&priv->rx_queue))) {
858 info = (struct rtl8192_rx_info *) skb->cb;
862 usb_kill_urb(info->urb);
866 if (skb_queue_len(&priv->skb_queue))
867 netdev_warn(dev, "skb_queue not empty\n");
869 skb_queue_purge(&priv->skb_queue);
873 inline u16 ieeerate2rtlrate(int rate)
905 static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
906 inline u16 rtl8192_rate2rate(short rate)
908 if (rate > 11) return 0;
909 return rtl_rate[rate];
913 /* The prototype of rx_isr has changed since one version of Linux Kernel */
914 static void rtl8192_rx_isr(struct urb *urb)
916 struct sk_buff *skb = (struct sk_buff *) urb->context;
917 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
918 struct net_device *dev = info->dev;
919 struct r8192_priv *priv = ieee80211_priv(dev);
920 int out_pipe = info->out_pipe;
924 if (unlikely(urb->status)) {
926 priv->stats.rxstaterr++;
927 priv->ieee80211->stats.rx_errors++;
931 skb_unlink(skb, &priv->rx_queue);
932 skb_put(skb, urb->actual_length);
934 skb_queue_tail(&priv->skb_queue, skb);
935 tasklet_schedule(&priv->irq_rx_tasklet);
937 skb = dev_alloc_skb(RX_URB_SIZE);
938 if (unlikely(!skb)) {
940 netdev_err(dev, "%s(): can't alloc skb\n", __func__);
941 /* TODO check rx queue length and refill *somewhere* */
945 usb_fill_bulk_urb(urb, priv->udev,
946 usb_rcvbulkpipe(priv->udev, out_pipe), skb_tail_pointer(skb),
947 RX_URB_SIZE, rtl8192_rx_isr, skb);
949 info = (struct rtl8192_rx_info *) skb->cb;
952 info->out_pipe = out_pipe;
954 urb->transfer_buffer = skb_tail_pointer(skb);
956 skb_queue_tail(&priv->rx_queue, skb);
957 err = usb_submit_urb(urb, GFP_ATOMIC);
958 if (err && err != EPERM)
959 netdev_err(dev, "can not submit rxurb, err is %x, URB status is %x\n", err, urb->status);
962 static u32 rtl819xusb_rx_command_packet(struct net_device *dev,
963 struct ieee80211_rx_stats *pstats)
967 status = cmpk_message_handle_rx(dev, pstats);
969 DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
975 static void rtl8192_data_hard_stop(struct net_device *dev)
981 static void rtl8192_data_hard_resume(struct net_device *dev)
986 /* this function TX data frames when the ieee80211 stack requires this.
987 * It checks also if we need to stop the ieee tx queue, eventually do it
989 static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
991 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
994 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
995 u8 queue_index = tcb_desc->queue_index;
997 /* shall not be referred by command packet */
998 RTL8192U_ASSERT(queue_index != TXCMD_QUEUE);
1000 spin_lock_irqsave(&priv->tx_lock, flags);
1002 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1003 tcb_desc->bTxEnableFwCalcDur = 1;
1004 skb_push(skb, priv->ieee80211->tx_headroom);
1005 ret = rtl8192_tx(dev, skb);
1007 spin_unlock_irqrestore(&priv->tx_lock, flags);
1012 /* This is a rough attempt to TX a frame
1013 * This is called by the ieee 80211 stack to TX management frames.
1014 * If the ring is full packet are dropped (for data frame the queue
1015 * is stopped before this can happen).
1017 static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1019 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1021 unsigned long flags;
1022 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1023 u8 queue_index = tcb_desc->queue_index;
1026 spin_lock_irqsave(&priv->tx_lock, flags);
1028 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1029 if (queue_index == TXCMD_QUEUE) {
1030 skb_push(skb, USB_HWDESC_HEADER_LEN);
1031 rtl819xU_tx_cmd(dev, skb);
1033 spin_unlock_irqrestore(&priv->tx_lock, flags);
1036 skb_push(skb, priv->ieee80211->tx_headroom);
1037 ret = rtl8192_tx(dev, skb);
1040 spin_unlock_irqrestore(&priv->tx_lock, flags);
1046 void rtl8192_try_wake_queue(struct net_device *dev, int pri);
1048 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1049 u16 DrvAggr_PaddingAdd(struct net_device *dev, struct sk_buff *skb)
1051 u16 PaddingNum = 256 - ((skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES) % 256);
1052 return PaddingNum & 0xff;
1055 u8 MRateToHwRate8190Pci(u8 rate);
1056 u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc);
1057 u8 MapHwQueueToFirmwareQueue(u8 QueueID);
1058 struct sk_buff *DrvAggr_Aggregation(struct net_device *dev, struct ieee80211_drv_agg_txb *pSendList)
1060 struct ieee80211_device *ieee = netdev_priv(dev);
1061 struct r8192_priv *priv = ieee80211_priv(dev);
1062 cb_desc *tcb_desc = NULL;
1065 struct sk_buff *skb;
1066 struct sk_buff *agg_skb;
1067 tx_desc_819x_usb_aggr_subframe *tx_agg_desc = NULL;
1068 tx_fwinfo_819x_usb *tx_fwinfo = NULL;
1071 // Local variable initialization.
1073 /* first skb initialization */
1074 skb = pSendList->tx_agg_frames[0];
1075 TotalLength = skb->len;
1077 /* Get the total aggregation length including the padding space and
1080 for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1081 TotalLength += DrvAggr_PaddingAdd(dev, skb);
1082 skb = pSendList->tx_agg_frames[i];
1083 TotalLength += (skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1086 /* allocate skb to contain the aggregated packets */
1087 agg_skb = dev_alloc_skb(TotalLength + ieee->tx_headroom);
1088 memset(agg_skb->data, 0, agg_skb->len);
1089 skb_reserve(agg_skb, ieee->tx_headroom);
1091 /* reserve info for first subframe Tx descriptor to be set in the tx function */
1092 skb = pSendList->tx_agg_frames[0];
1093 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1094 tcb_desc->drv_agg_enable = 1;
1095 tcb_desc->pkt_size = skb->len;
1096 tcb_desc->DrvAggrNum = pSendList->nr_drv_agg_frames;
1097 netdev_dbg(dev, "DrvAggNum = %d\n", tcb_desc->DrvAggrNum);
1098 memcpy(agg_skb->cb, skb->cb, sizeof(skb->cb));
1099 memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
1101 for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1102 /* push the next sub frame to be 256 byte aline */
1103 skb_put(agg_skb, DrvAggr_PaddingAdd(dev, skb));
1105 /* Subframe drv Tx descriptor and firmware info setting */
1106 skb = pSendList->tx_agg_frames[i];
1107 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1108 tx_agg_desc = (tx_desc_819x_usb_aggr_subframe *)skb_tail_pointer(agg_skb);
1109 tx_fwinfo = (tx_fwinfo_819x_usb *)(skb_tail_pointer(agg_skb) + sizeof(tx_desc_819x_usb_aggr_subframe));
1111 memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
1113 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
1114 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
1115 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1116 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
1117 if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
1118 tx_fwinfo->AllowAggregation = 1;
1120 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
1121 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
1123 tx_fwinfo->AllowAggregation = 0;
1125 tx_fwinfo->RxMF = 0;
1126 tx_fwinfo->RxAMD = 0;
1129 /* Protection mode related */
1130 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
1131 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
1132 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
1133 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
1134 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1135 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
1136 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
1137 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
1138 (tcb_desc->bRTSUseShortGI ? 1 : 0);
1140 /* Set Bandwidth and sub-channel settings. */
1141 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
1142 if (tcb_desc->bPacketBW) {
1143 tx_fwinfo->TxBandwidth = 1;
1144 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
1146 tx_fwinfo->TxBandwidth = 0;
1147 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1150 tx_fwinfo->TxBandwidth = 0;
1151 tx_fwinfo->TxSubCarrier = 0;
1154 /* Fill Tx descriptor */
1155 memset(tx_agg_desc, 0, sizeof(tx_desc_819x_usb_aggr_subframe));
1157 tx_agg_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
1158 /* already raw data, need not to subtract header length */
1159 tx_agg_desc->PktSize = skb->len & 0xffff;
1162 tx_agg_desc->SecCAMID = 0;
1163 tx_agg_desc->RATid = tcb_desc->RATRIndex;
1164 tx_agg_desc->NoEnc = 1;
1165 tx_agg_desc->SecType = 0x0;
1167 if (tcb_desc->bHwSec) {
1168 switch (priv->ieee80211->pairwise_key_type) {
1169 case KEY_TYPE_WEP40:
1170 case KEY_TYPE_WEP104:
1171 tx_agg_desc->SecType = 0x1;
1172 tx_agg_desc->NoEnc = 0;
1175 tx_agg_desc->SecType = 0x2;
1176 tx_agg_desc->NoEnc = 0;
1179 tx_agg_desc->SecType = 0x3;
1180 tx_agg_desc->NoEnc = 0;
1183 tx_agg_desc->SecType = 0x0;
1184 tx_agg_desc->NoEnc = 1;
1189 tx_agg_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1190 tx_agg_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
1192 tx_agg_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
1193 tx_agg_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1195 tx_agg_desc->OWN = 1;
1198 /* According windows driver, it seems that there no need to fill this field */
1200 /* to fill next packet */
1201 skb_put(agg_skb, TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1202 memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
1205 for (i = 0; i < pSendList->nr_drv_agg_frames; i++)
1206 dev_kfree_skb_any(pSendList->tx_agg_frames[i]);
1212 This function return a list of PTCB which is proper to be aggregate with the input TCB.
1213 If no proper TCB is found to do aggregation, SendList will only contain the input TCB.
1215 u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb,
1216 struct ieee80211_drv_agg_txb *pSendList)
1218 struct ieee80211_device *ieee = netdev_priv(dev);
1219 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1220 u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum;
1221 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1222 u8 QueueID = tcb_desc->queue_index;
1225 pSendList->tx_agg_frames[pSendList->nr_drv_agg_frames++] = skb;
1226 if (pSendList->nr_drv_agg_frames >= nMaxAggrNum)
1229 } while ((skb = skb_dequeue(&ieee->skb_drv_aggQ[QueueID])));
1231 RT_TRACE(COMP_AMSDU, "DrvAggr_GetAggregatibleList, nAggrTcbNum = %d \n", pSendList->nr_drv_agg_frames);
1232 return pSendList->nr_drv_agg_frames;
1236 static void rtl8192_tx_isr(struct urb *tx_urb)
1238 struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
1239 struct net_device *dev = NULL;
1240 struct r8192_priv *priv = NULL;
1241 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1242 u8 queue_index = tcb_desc->queue_index;
1244 memcpy(&dev, (struct net_device *)(skb->cb), sizeof(struct net_device *));
1245 priv = ieee80211_priv(dev);
1247 if (tcb_desc->queue_index != TXCMD_QUEUE) {
1248 if (tx_urb->status == 0) {
1249 dev->trans_start = jiffies;
1250 priv->stats.txoktotal++;
1251 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
1252 priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
1254 priv->ieee80211->stats.tx_errors++;
1259 /* free skb and tx_urb */
1261 dev_kfree_skb_any(skb);
1262 usb_free_urb(tx_urb);
1263 atomic_dec(&priv->tx_pending[queue_index]);
1267 // Handle HW Beacon:
1268 // We had transfer our beacon frame to host controller at this moment.
1272 // Handling the wait queue of command packets.
1273 // For Tx command packets, we must not do TCB fragment because it is not handled right now.
1274 // We must cut the packets to match the size of TX_CMD_PKT before we send it.
1277 /* Handle MPDU in wait queue. */
1278 if (queue_index != BEACON_QUEUE) {
1279 /* Don't send data frame during scanning.*/
1280 if ((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0) &&
1281 (!(priv->ieee80211->queue_stop))) {
1282 skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]));
1284 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
1286 return; //modified by david to avoid further processing AMSDU
1288 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1289 else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index]) != 0) &&
1290 (!(priv->ieee80211->queue_stop))) {
1291 // Tx Driver Aggregation process
1292 /* The driver will aggregation the packets according to the following stats
1293 * 1. check whether there's tx irq available, for it's a completion return
1294 * function, it should contain enough tx irq;
1295 * 2. check packet type;
1296 * 3. initialize sendlist, check whether the to-be send packet no greater than 1
1297 * 4. aggregates the packets, and fill firmware info and tx desc into it, etc.
1298 * 5. check whether the packet could be sent, otherwise just insert into wait head
1300 skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
1301 if (!check_nic_enough_desc(dev, queue_index)) {
1302 skb_queue_head(&(priv->ieee80211->skb_drv_aggQ[queue_index]), skb);
1308 struct ieee80211_drv_agg_txb SendList;
1310 memset(&SendList, 0, sizeof(struct ieee80211_drv_agg_txb));
1311 if (DrvAggr_GetAggregatibleList(dev, skb, &SendList) > 1) {
1312 skb = DrvAggr_Aggregation(dev, &SendList);
1316 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
1323 static void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
1325 struct r8192_priv *priv = ieee80211_priv(dev);
1326 struct ieee80211_network *net;
1327 u8 i = 0, basic_rate = 0;
1328 net = &priv->ieee80211->current_network;
1330 for (i = 0; i < net->rates_len; i++) {
1331 basic_rate = net->rates[i]&0x7f;
1332 switch (basic_rate) {
1333 case MGN_1M: *rate_config |= RRSR_1M; break;
1334 case MGN_2M: *rate_config |= RRSR_2M; break;
1335 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1336 case MGN_11M: *rate_config |= RRSR_11M; break;
1337 case MGN_6M: *rate_config |= RRSR_6M; break;
1338 case MGN_9M: *rate_config |= RRSR_9M; break;
1339 case MGN_12M: *rate_config |= RRSR_12M; break;
1340 case MGN_18M: *rate_config |= RRSR_18M; break;
1341 case MGN_24M: *rate_config |= RRSR_24M; break;
1342 case MGN_36M: *rate_config |= RRSR_36M; break;
1343 case MGN_48M: *rate_config |= RRSR_48M; break;
1344 case MGN_54M: *rate_config |= RRSR_54M; break;
1347 for (i = 0; i < net->rates_ex_len; i++) {
1348 basic_rate = net->rates_ex[i]&0x7f;
1349 switch (basic_rate) {
1350 case MGN_1M: *rate_config |= RRSR_1M; break;
1351 case MGN_2M: *rate_config |= RRSR_2M; break;
1352 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1353 case MGN_11M: *rate_config |= RRSR_11M; break;
1354 case MGN_6M: *rate_config |= RRSR_6M; break;
1355 case MGN_9M: *rate_config |= RRSR_9M; break;
1356 case MGN_12M: *rate_config |= RRSR_12M; break;
1357 case MGN_18M: *rate_config |= RRSR_18M; break;
1358 case MGN_24M: *rate_config |= RRSR_24M; break;
1359 case MGN_36M: *rate_config |= RRSR_36M; break;
1360 case MGN_48M: *rate_config |= RRSR_48M; break;
1361 case MGN_54M: *rate_config |= RRSR_54M; break;
1367 #define SHORT_SLOT_TIME 9
1368 #define NON_SHORT_SLOT_TIME 20
1370 static void rtl8192_update_cap(struct net_device *dev, u16 cap)
1373 struct r8192_priv *priv = ieee80211_priv(dev);
1374 struct ieee80211_network *net = &priv->ieee80211->current_network;
1375 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1376 tmp = priv->basic_rate;
1377 if (priv->short_preamble)
1378 tmp |= BRSR_AckShortPmb;
1379 write_nic_dword(dev, RRSR, tmp);
1381 if (net->mode & (IEEE_G|IEEE_N_24G)) {
1383 if ((cap & WLAN_CAPABILITY_SHORT_SLOT) && (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) //short slot time
1384 slot_time = SHORT_SLOT_TIME;
1385 else //long slot time
1386 slot_time = NON_SHORT_SLOT_TIME;
1387 priv->slot_time = slot_time;
1388 write_nic_byte(dev, SLOT_TIME, slot_time);
1392 static void rtl8192_net_update(struct net_device *dev)
1395 struct r8192_priv *priv = ieee80211_priv(dev);
1396 struct ieee80211_network *net;
1397 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1398 u16 rate_config = 0;
1399 net = &priv->ieee80211->current_network;
1401 rtl8192_config_rate(dev, &rate_config);
1402 priv->basic_rate = rate_config &= 0x15f;
1404 write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
1405 write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
1407 rtl8192_update_msr(dev);
1408 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
1409 write_nic_word(dev, ATIMWND, 2);
1410 write_nic_word(dev, BCN_DMATIME, 1023);
1411 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1412 write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
1413 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1414 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1415 // TODO: BcnIFS may required to be changed on ASIC
1416 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1418 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1425 //temporary hw beacon is not used any more.
1426 //open it when necessary
1427 void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate)
1431 inline u8 rtl8192_IsWirelessBMode(u16 rate)
1433 if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
1438 u16 N_DBPSOfRate(u16 DataRate);
1440 u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
1447 if (rtl8192_IsWirelessBMode(DataRate)) {
1448 if (bManagementFrame || !bShortPreamble || DataRate == 10) // long preamble
1449 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1450 else // Short preamble
1451 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1452 if ((FrameLength*8 % (DataRate/10)) != 0) //Get the Ceilling
1454 } else { //802.11g DSSS-OFDM PLCP length field calculation.
1455 N_DBPS = N_DBPSOfRate(DataRate);
1456 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1457 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1458 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1463 u16 N_DBPSOfRate(u16 DataRate)
1507 unsigned int txqueue2outpipe(struct r8192_priv *priv, unsigned int tx_queue)
1509 if (tx_queue >= 9) {
1510 RT_TRACE(COMP_ERR, "%s():Unknown queue ID!!!\n", __func__);
1513 return priv->txqueue_to_outpipemap[tx_queue];
1516 short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1518 struct r8192_priv *priv = ieee80211_priv(dev);
1521 unsigned int idx_pipe;
1522 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
1523 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1524 u8 queue_index = tcb_desc->queue_index;
1526 atomic_inc(&priv->tx_pending[queue_index]);
1527 tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
1533 memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
1534 /* Tx descriptor ought to be set according to the skb->cb */
1535 pdesc->FirstSeg = 1;//bFirstSeg;
1536 pdesc->LastSeg = 1;//bLastSeg;
1537 pdesc->CmdInit = tcb_desc->bCmdOrInit;
1538 pdesc->TxBufferSize = tcb_desc->txbuf_size;
1540 pdesc->LINIP = tcb_desc->bLastIniPkt;
1542 //----------------------------------------------------------------------------
1543 // Fill up USB_OUT_CONTEXT.
1544 //----------------------------------------------------------------------------
1545 // Get index to out pipe from specified QueueID.
1546 #ifndef USE_ONE_PIPE
1547 idx_pipe = txqueue2outpipe(priv, queue_index);
1551 usb_fill_bulk_urb(tx_urb, priv->udev, usb_sndbulkpipe(priv->udev, idx_pipe),
1552 skb->data, skb->len, rtl8192_tx_isr, skb);
1554 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
1559 DMESGE("Error TX CMD URB, error %d", status);
1565 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1566 * in TxFwInfo data structure
1567 * 2006.10.30 by Emily
1569 * \param QUEUEID Software Queue
1571 static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1573 u8 QueueSelect = 0x0; //defualt set to
1577 QueueSelect = QSLT_BE;
1581 QueueSelect = QSLT_BK;
1585 QueueSelect = QSLT_VO;
1589 QueueSelect = QSLT_VI;
1592 QueueSelect = QSLT_MGNT;
1596 QueueSelect = QSLT_BEACON;
1599 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
1600 // TODO: Remove Assertions
1602 QueueSelect = QSLT_CMD;
1605 QueueSelect = QSLT_HIGH;
1609 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
1615 static u8 MRateToHwRate8190Pci(u8 rate)
1617 u8 ret = DESC90_RATE1M;
1620 case MGN_1M: ret = DESC90_RATE1M; break;
1621 case MGN_2M: ret = DESC90_RATE2M; break;
1622 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1623 case MGN_11M: ret = DESC90_RATE11M; break;
1624 case MGN_6M: ret = DESC90_RATE6M; break;
1625 case MGN_9M: ret = DESC90_RATE9M; break;
1626 case MGN_12M: ret = DESC90_RATE12M; break;
1627 case MGN_18M: ret = DESC90_RATE18M; break;
1628 case MGN_24M: ret = DESC90_RATE24M; break;
1629 case MGN_36M: ret = DESC90_RATE36M; break;
1630 case MGN_48M: ret = DESC90_RATE48M; break;
1631 case MGN_54M: ret = DESC90_RATE54M; break;
1633 // HT rate since here
1634 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1635 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1636 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1637 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1638 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1639 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1640 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1641 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1642 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1643 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1644 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1645 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1646 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1647 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1648 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1649 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1650 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1658 static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
1662 tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) : ((tcb_desc->bUseShortPreamble) ? 1 : 0);
1664 if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
1670 static void tx_zero_isr(struct urb *tx_urb)
1676 * The tx procedure is just as following,
1677 * skb->cb will contain all the following information,
1678 * priority, morefrag, rate, &dev.
1680 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1682 struct r8192_priv *priv = ieee80211_priv(dev);
1683 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1684 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
1685 tx_fwinfo_819x_usb *tx_fwinfo = (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
1686 struct usb_device *udev = priv->udev;
1689 struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
1690 unsigned int idx_pipe;
1691 pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
1692 /* we are locked here so the two atomic_read and inc are executed
1693 * without interleaves
1694 * !!! For debug purpose
1696 if (pend > MAX_TX_URB) {
1697 netdev_dbg(dev, "To discard skb packet!\n");
1698 dev_kfree_skb_any(skb);
1702 tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
1704 dev_kfree_skb_any(skb);
1708 /* Fill Tx firmware info */
1709 memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
1711 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
1712 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
1713 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1714 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
1715 if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
1716 tx_fwinfo->AllowAggregation = 1;
1718 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
1719 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
1721 tx_fwinfo->AllowAggregation = 0;
1723 tx_fwinfo->RxMF = 0;
1724 tx_fwinfo->RxAMD = 0;
1727 /* Protection mode related */
1728 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
1729 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
1730 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
1731 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
1732 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1733 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
1734 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
1735 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
1736 (tcb_desc->bRTSUseShortGI ? 1 : 0);
1738 /* Set Bandwidth and sub-channel settings. */
1739 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
1740 if (tcb_desc->bPacketBW) {
1741 tx_fwinfo->TxBandwidth = 1;
1742 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
1744 tx_fwinfo->TxBandwidth = 0;
1745 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1748 tx_fwinfo->TxBandwidth = 0;
1749 tx_fwinfo->TxSubCarrier = 0;
1752 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1753 if (tcb_desc->drv_agg_enable)
1754 tx_fwinfo->Tx_INFO_RSVD = (tcb_desc->DrvAggrNum & 0x1f) << 1;
1756 /* Fill Tx descriptor */
1757 memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
1760 tx_desc->CmdInit = 1;
1761 tx_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
1763 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1764 if (tcb_desc->drv_agg_enable)
1765 tx_desc->PktSize = tcb_desc->pkt_size;
1769 tx_desc->PktSize = (skb->len - TX_PACKET_SHIFT_BYTES) & 0xffff;
1773 tx_desc->SecCAMID = 0;
1774 tx_desc->RATid = tcb_desc->RATRIndex;
1776 tx_desc->SecType = 0x0;
1777 if (tcb_desc->bHwSec) {
1778 switch (priv->ieee80211->pairwise_key_type) {
1779 case KEY_TYPE_WEP40:
1780 case KEY_TYPE_WEP104:
1781 tx_desc->SecType = 0x1;
1785 tx_desc->SecType = 0x2;
1789 tx_desc->SecType = 0x3;
1793 tx_desc->SecType = 0x0;
1799 tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1800 tx_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
1802 tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
1803 tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1805 /* Fill fields that are required to be initialized in all of the descriptors */
1807 tx_desc->FirstSeg = 1;
1808 tx_desc->LastSeg = 1;
1811 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1812 if (tcb_desc->drv_agg_enable) {
1813 tx_desc->TxBufferSize = tcb_desc->pkt_size + sizeof(tx_fwinfo_819x_usb);
1818 tx_desc->TxBufferSize = (u32)(skb->len - USB_HWDESC_HEADER_LEN);
1820 /* Get index to out pipe from specified QueueID */
1821 #ifndef USE_ONE_PIPE
1822 idx_pipe = txqueue2outpipe(priv, tcb_desc->queue_index);
1827 /* To submit bulk urb */
1828 usb_fill_bulk_urb(tx_urb, udev,
1829 usb_sndbulkpipe(udev, idx_pipe), skb->data,
1830 skb->len, rtl8192_tx_isr, skb);
1832 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
1834 //we need to send 0 byte packet whenever 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has been transmitted. Otherwise, it will be halt to wait for another packet. WB. 2008.08.27
1835 bool bSend0Byte = false;
1837 if (udev->speed == USB_SPEED_HIGH) {
1838 if (skb->len > 0 && skb->len % 512 == 0)
1841 if (skb->len > 0 && skb->len % 64 == 0)
1845 tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC);
1847 RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
1850 usb_fill_bulk_urb(tx_urb_zero, udev,
1851 usb_sndbulkpipe(udev, idx_pipe), &zero,
1852 0, tx_zero_isr, dev);
1853 status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
1855 RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
1859 dev->trans_start = jiffies;
1860 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
1863 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
1869 static short rtl8192_usb_initendpoints(struct net_device *dev)
1871 struct r8192_priv *priv = ieee80211_priv(dev);
1873 priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1),
1875 if (priv->rx_urb == NULL)
1878 #ifndef JACKSON_NEW_RX
1879 for (i = 0; i < (MAX_RX_URB+1); i++) {
1881 priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
1883 priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
1885 priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
1889 #ifdef THOMAS_BEACON
1892 void *oldaddr, *newaddr;
1894 priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
1895 priv->oldaddr = kmalloc(16, GFP_KERNEL);
1896 oldaddr = priv->oldaddr;
1897 align = ((long)oldaddr) & 3;
1899 newaddr = oldaddr + 4 - align;
1900 priv->rx_urb[16]->transfer_buffer_length = 16 - 4 + align;
1903 priv->rx_urb[16]->transfer_buffer_length = 16;
1905 priv->rx_urb[16]->transfer_buffer = newaddr;
1909 memset(priv->rx_urb, 0, sizeof(struct urb *) * MAX_RX_URB);
1910 priv->pp_rxskb = kcalloc(MAX_RX_URB, sizeof(struct sk_buff *),
1912 if (!priv->pp_rxskb) {
1913 kfree(priv->rx_urb);
1915 priv->pp_rxskb = NULL;
1916 priv->rx_urb = NULL;
1918 DMESGE("Endpoint Alloc Failure");
1922 netdev_dbg(dev, "End of initendpoints\n");
1926 #ifdef THOMAS_BEACON
1927 static void rtl8192_usb_deleteendpoints(struct net_device *dev)
1930 struct r8192_priv *priv = ieee80211_priv(dev);
1933 for (i = 0; i < (MAX_RX_URB+1); i++) {
1934 usb_kill_urb(priv->rx_urb[i]);
1935 usb_free_urb(priv->rx_urb[i]);
1937 kfree(priv->rx_urb);
1938 priv->rx_urb = NULL;
1940 kfree(priv->oldaddr);
1941 priv->oldaddr = NULL;
1942 if (priv->pp_rxskb) {
1943 kfree(priv->pp_rxskb);
1944 priv->pp_rxskb = NULL;
1948 void rtl8192_usb_deleteendpoints(struct net_device *dev)
1951 struct r8192_priv *priv = ieee80211_priv(dev);
1953 #ifndef JACKSON_NEW_RX
1956 for (i = 0; i < (MAX_RX_URB+1); i++) {
1957 usb_kill_urb(priv->rx_urb[i]);
1958 kfree(priv->rx_urb[i]->transfer_buffer);
1959 usb_free_urb(priv->rx_urb[i]);
1961 kfree(priv->rx_urb);
1962 priv->rx_urb = NULL;
1966 kfree(priv->rx_urb);
1967 priv->rx_urb = NULL;
1968 kfree(priv->oldaddr);
1969 priv->oldaddr = NULL;
1970 if (priv->pp_rxskb) {
1971 kfree(priv->pp_rxskb);
1980 extern void rtl8192_update_ratr_table(struct net_device *dev);
1981 static void rtl8192_link_change(struct net_device *dev)
1983 struct r8192_priv *priv = ieee80211_priv(dev);
1984 struct ieee80211_device *ieee = priv->ieee80211;
1985 if (ieee->state == IEEE80211_LINKED) {
1986 rtl8192_net_update(dev);
1987 rtl8192_update_ratr_table(dev);
1988 //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
1989 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
1990 EnableHWSecurityConfig8192(dev);
1992 /*update timing params*/
1993 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
1995 read_nic_dword(dev, RCR, ®);
1996 if (priv->ieee80211->state == IEEE80211_LINKED)
1997 priv->ReceiveConfig = reg |= RCR_CBSSID;
1999 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
2000 write_nic_dword(dev, RCR, reg);
2004 static struct ieee80211_qos_parameters def_qos_parameters = {
2005 {3, 3, 3, 3},/* cw_min */
2006 {7, 7, 7, 7},/* cw_max */
2007 {2, 2, 2, 2},/* aifs */
2008 {0, 0, 0, 0},/* flags */
2009 {0, 0, 0, 0} /* tx_op_limit */
2013 static void rtl8192_update_beacon(struct work_struct *work)
2015 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
2016 struct net_device *dev = priv->ieee80211->dev;
2017 struct ieee80211_device *ieee = priv->ieee80211;
2018 struct ieee80211_network *net = &ieee->current_network;
2020 if (ieee->pHTInfo->bCurrentHTSupport)
2021 HTUpdateSelfAndPeerSetting(ieee, net);
2022 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
2023 rtl8192_update_cap(dev, net->capability);
2026 * background support to run QoS activate functionality
2028 static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
2029 static void rtl8192_qos_activate(struct work_struct *work)
2031 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
2032 struct net_device *dev = priv->ieee80211->dev;
2033 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
2034 u8 mode = priv->ieee80211->current_network.mode;
2039 mutex_lock(&priv->mutex);
2040 if (priv->ieee80211->state != IEEE80211_LINKED)
2042 RT_TRACE(COMP_QOS, "qos active process with associate response received\n");
2043 /* It better set slot time at first */
2044 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
2045 /* update the ac parameter to related registers */
2046 for (i = 0; i < QOS_QUEUE_NUM; i++) {
2047 //Mode G/A: slotTimeTimer = 9; Mode B: 20
2048 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
2049 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
2050 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
2051 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
2052 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2054 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2058 mutex_unlock(&priv->mutex);
2061 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
2063 struct ieee80211_network *network)
2066 u32 size = sizeof(struct ieee80211_qos_parameters);
2068 if (priv->ieee80211->state != IEEE80211_LINKED)
2071 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2074 if (network->flags & NETWORK_HAS_QOS_MASK) {
2075 if (active_network &&
2076 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
2077 network->qos_data.active = network->qos_data.supported;
2079 if ((network->qos_data.active == 1) && (active_network == 1) &&
2080 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
2081 (network->qos_data.old_param_count !=
2082 network->qos_data.param_count)) {
2083 network->qos_data.old_param_count =
2084 network->qos_data.param_count;
2085 queue_work(priv->priv_wq, &priv->qos_activate);
2086 RT_TRACE(COMP_QOS, "QoS parameters change call "
2090 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2091 &def_qos_parameters, size);
2093 if ((network->qos_data.active == 1) && (active_network == 1)) {
2094 queue_work(priv->priv_wq, &priv->qos_activate);
2095 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
2097 network->qos_data.active = 0;
2098 network->qos_data.supported = 0;
2104 /* handle and manage frame from beacon and probe response */
2105 static int rtl8192_handle_beacon(struct net_device *dev,
2106 struct ieee80211_beacon *beacon,
2107 struct ieee80211_network *network)
2109 struct r8192_priv *priv = ieee80211_priv(dev);
2111 rtl8192_qos_handle_probe_response(priv, 1, network);
2112 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
2118 * handling the beaconing responses. if we get different QoS setting
2119 * off the network from the associated setting, adjust the QoS
2122 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
2123 struct ieee80211_network *network)
2126 unsigned long flags;
2127 u32 size = sizeof(struct ieee80211_qos_parameters);
2128 int set_qos_param = 0;
2130 if ((priv == NULL) || (network == NULL))
2133 if (priv->ieee80211->state != IEEE80211_LINKED)
2136 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2139 spin_lock_irqsave(&priv->ieee80211->lock, flags);
2140 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
2141 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2142 &network->qos_data.parameters,
2143 sizeof(struct ieee80211_qos_parameters));
2144 priv->ieee80211->current_network.qos_data.active = 1;
2146 /* update qos parameter for current network */
2147 priv->ieee80211->current_network.qos_data.old_param_count =
2148 priv->ieee80211->current_network.qos_data.param_count;
2149 priv->ieee80211->current_network.qos_data.param_count =
2150 network->qos_data.param_count;
2152 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2153 &def_qos_parameters, size);
2154 priv->ieee80211->current_network.qos_data.active = 0;
2155 priv->ieee80211->current_network.qos_data.supported = 0;
2159 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
2161 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, network->flags, priv->ieee80211->current_network.qos_data.active);
2162 if (set_qos_param == 1)
2163 queue_work(priv->priv_wq, &priv->qos_activate);
2170 static int rtl8192_handle_assoc_response(struct net_device *dev,
2171 struct ieee80211_assoc_response_frame *resp,
2172 struct ieee80211_network *network)
2174 struct r8192_priv *priv = ieee80211_priv(dev);
2175 rtl8192_qos_association_resp(priv, network);
2180 void rtl8192_update_ratr_table(struct net_device *dev)
2182 struct r8192_priv *priv = ieee80211_priv(dev);
2183 struct ieee80211_device *ieee = priv->ieee80211;
2184 u8 *pMcsRate = ieee->dot11HTOperationalRateSet;
2187 rtl8192_config_rate(dev, (u16 *)(&ratr_value));
2188 ratr_value |= (*(u16 *)(pMcsRate)) << 12;
2189 switch (ieee->mode) {
2191 ratr_value &= 0x00000FF0;
2194 ratr_value &= 0x0000000F;
2197 ratr_value &= 0x00000FF7;
2201 if (ieee->pHTInfo->PeerMimoPs == 0) {//MIMO_PS_STATIC
2202 ratr_value &= 0x0007F007;
2204 if (priv->rf_type == RF_1T2R)
2205 ratr_value &= 0x000FF007;
2207 ratr_value &= 0x0F81F007;
2213 ratr_value &= 0x0FFFFFFF;
2214 if (ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz)
2215 ratr_value |= 0x80000000;
2216 else if (!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz)
2217 ratr_value |= 0x80000000;
2218 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
2219 write_nic_byte(dev, UFWP, 1);
2222 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
2223 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
2224 static bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
2226 struct r8192_priv *priv = ieee80211_priv(dev);
2227 struct ieee80211_device *ieee = priv->ieee80211;
2228 struct ieee80211_network *network = &ieee->current_network;
2229 int wpa_ie_len = ieee->wpa_ie_len;
2230 struct ieee80211_crypt_data *crypt;
2233 crypt = ieee->crypt[ieee->tx_keyidx];
2234 //we use connecting AP's capability instead of only security config on our driver to distinguish whether it should use N mode or G mode
2235 encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name, "WEP")));
2238 if (encrypt && (wpa_ie_len == 0)) {
2239 /* wep encryption, no N mode setting */
2241 } else if ((wpa_ie_len != 0)) {
2242 /* parse pairwise key type */
2243 if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) || ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4))))
2254 static bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
2257 struct r8192_priv *priv = ieee80211_priv(dev);
2258 struct ieee80211_device *ieee = priv->ieee80211;
2260 if (ieee->bHalfWirelessN24GMode == true)
2268 static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
2270 struct ieee80211_device *ieee = priv->ieee80211;
2271 //we do not consider set support rate for ABG mode, only HT MCS rate is set here.
2272 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2273 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
2275 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
2279 static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
2281 struct r8192_priv *priv = ieee80211_priv(dev);
2283 switch (priv->rf_chip) {
2287 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
2290 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
2293 ret = WIRELESS_MODE_B;
2298 static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
2300 struct r8192_priv *priv = ieee80211_priv(dev);
2301 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
2303 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode) == 0)) {
2304 if (bSupportMode & WIRELESS_MODE_N_24G) {
2305 wireless_mode = WIRELESS_MODE_N_24G;
2306 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
2307 wireless_mode = WIRELESS_MODE_N_5G;
2308 } else if ((bSupportMode & WIRELESS_MODE_A)) {
2309 wireless_mode = WIRELESS_MODE_A;
2310 } else if ((bSupportMode & WIRELESS_MODE_G)) {
2311 wireless_mode = WIRELESS_MODE_G;
2312 } else if ((bSupportMode & WIRELESS_MODE_B)) {
2313 wireless_mode = WIRELESS_MODE_B;
2315 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __func__, bSupportMode);
2316 wireless_mode = WIRELESS_MODE_B;
2319 #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
2320 ActUpdateChannelAccessSetting(pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
2322 priv->ieee80211->mode = wireless_mode;
2324 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
2325 priv->ieee80211->pHTInfo->bEnableHT = 1;
2327 priv->ieee80211->pHTInfo->bEnableHT = 0;
2328 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
2329 rtl8192_refresh_supportrate(priv);
2332 //init priv variables here. only non_zero value should be initialized here.
2333 static void rtl8192_init_priv_variable(struct net_device *dev)
2335 struct r8192_priv *priv = ieee80211_priv(dev);
2337 priv->card_8192 = NIC_8192U;
2338 priv->chan = 1; //set to channel 1
2339 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
2340 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2341 priv->ieee80211->ieee_up = 0;
2342 priv->retry_rts = DEFAULT_RETRY_RTS;
2343 priv->retry_data = DEFAULT_RETRY_DATA;
2344 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
2345 priv->ieee80211->rate = 110; //11 mbps
2346 priv->ieee80211->short_slot = 1;
2347 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2350 priv->IrpPendingCount = 1;
2351 priv->ResetProgress = RESET_TYPE_NORESET;
2352 priv->bForcedSilentReset = 0;
2353 priv->bDisableNormalResetCheck = false;
2354 priv->force_reset = false;
2356 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available.
2357 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2358 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2359 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2360 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2361 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
2362 IEEE_SOFTMAC_BEACONS;//added by amy 080604
2364 priv->ieee80211->active_scan = 1;
2365 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
2366 priv->ieee80211->host_encrypt = 1;
2367 priv->ieee80211->host_decrypt = 1;
2368 priv->ieee80211->start_send_beacons = NULL; //-by amy 080604
2369 priv->ieee80211->stop_send_beacons = NULL; //-by amy 080604
2370 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
2371 priv->ieee80211->set_chan = rtl8192_set_chan;
2372 priv->ieee80211->link_change = rtl8192_link_change;
2373 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
2374 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
2375 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
2376 priv->ieee80211->init_wmmparam_flag = 0;
2377 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2378 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
2379 priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
2380 priv->ieee80211->qos_support = 1;
2383 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
2384 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
2385 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
2387 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
2388 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xUsb;
2389 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
2391 priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
2392 priv->card_type = USB;
2394 if (Adapter->bInHctTest) {
2395 pHalData->ShortRetryLimit = 7;
2396 pHalData->LongRetryLimit = 7;
2399 priv->ShortRetryLimit = 0x30;
2400 priv->LongRetryLimit = 0x30;
2401 priv->EarlyRxThreshold = 7;
2402 priv->enable_gpio0 = 0;
2403 priv->TransmitConfig =
2404 (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)| // Max DMA Burst Size per Tx DMA Burst, 7: reserved.
2405 (priv->ShortRetryLimit<<TCR_SRL_OFFSET)| // Short retry limit
2406 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
2407 (false ? TCR_SAT : 0); // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
2409 if (Adapter->bInHctTest)
2410 pHalData->ReceiveConfig = pHalData->CSMethod |
2411 RCR_AMF | RCR_ADF | //accept management/data
2413 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2414 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2415 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
2416 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2417 (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
2418 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
2422 priv->ReceiveConfig =
2423 RCR_AMF | RCR_ADF | //accept management/data
2424 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2425 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2426 ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2427 (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
2428 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT : 0);
2430 priv->AcmControl = 0;
2431 priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL);
2433 /* rx related queue */
2434 skb_queue_head_init(&priv->rx_queue);
2435 skb_queue_head_init(&priv->skb_queue);
2437 /* Tx related queue */
2438 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2439 skb_queue_head_init(&priv->ieee80211->skb_waitQ[i]);
2440 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2441 skb_queue_head_init(&priv->ieee80211->skb_aggQ[i]);
2442 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2443 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]);
2444 priv->rf_set_chan = rtl8192_phy_SwChnl;
2448 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
2450 spin_lock_init(&priv->tx_lock);
2451 spin_lock_init(&priv->irq_lock);//added by thomas
2452 sema_init(&priv->wx_sem, 1);
2453 sema_init(&priv->rf_sem, 1);
2454 mutex_init(&priv->mutex);
2457 extern void rtl819x_watchdog_wqcallback(struct work_struct *work);
2459 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
2460 //init tasklet and wait_queue here. only 2.6 above kernel is considered
2461 #define DRV_NAME "wlan0"
2462 static void rtl8192_init_priv_task(struct net_device *dev)
2464 struct r8192_priv *priv = ieee80211_priv(dev);
2466 priv->priv_wq = create_workqueue(DRV_NAME);
2468 INIT_WORK(&priv->reset_wq, rtl8192_restart);
2470 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
2471 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
2472 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
2473 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
2474 INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
2475 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
2477 tasklet_init(&priv->irq_rx_tasklet,
2478 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
2479 (unsigned long)priv);
2482 static void rtl8192_get_eeprom_size(struct net_device *dev)
2485 struct r8192_priv *priv = ieee80211_priv(dev);
2486 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
2487 read_nic_word_E(dev, EPROM_CMD, &curCR);
2488 RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
2489 //whether need I consider BIT5?
2490 priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
2491 RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
2494 //used to swap endian. as ntohl & htonl are not necessary to swap endian, so use this instead.
2495 static inline u16 endian_swap(u16 *data)
2498 *data = (tmp >> 8) | (tmp << 8);
2501 static void rtl8192_read_eeprom_info(struct net_device *dev)
2504 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
2505 u8 bLoad_From_EEPOM = false;
2506 struct r8192_priv *priv = ieee80211_priv(dev);
2509 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
2510 wEPROM_ID = eprom_read(dev, 0); //first read EEPROM ID out;
2511 RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
2513 if (wEPROM_ID != RTL8190_EEPROM_ID) {
2514 RT_TRACE(COMP_ERR, "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n", wEPROM_ID, RTL8190_EEPROM_ID);
2516 bLoad_From_EEPOM = true;
2519 if (bLoad_From_EEPOM) {
2520 tmpValue = eprom_read(dev, (EEPROM_VID>>1));
2521 priv->eeprom_vid = endian_swap(&tmpValue);
2522 priv->eeprom_pid = eprom_read(dev, (EEPROM_PID>>1));
2523 tmpValue = eprom_read(dev, (EEPROM_ChannelPlan>>1));
2524 priv->eeprom_ChannelPlan = ((tmpValue&0xff00)>>8);
2525 priv->btxpowerdata_readfromEEPORM = true;
2526 priv->eeprom_CustomerID = eprom_read(dev, (EEPROM_Customer_ID>>1)) >>8;
2528 priv->eeprom_vid = 0;
2529 priv->eeprom_pid = 0;
2530 priv->card_8192_version = VERSION_819xU_B;
2531 priv->eeprom_ChannelPlan = 0;
2532 priv->eeprom_CustomerID = 0;
2534 RT_TRACE(COMP_EPROM, "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n", priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID, priv->eeprom_ChannelPlan);
2535 //set channelplan from eeprom
2536 priv->ChannelPlan = priv->eeprom_ChannelPlan;
2537 if (bLoad_From_EEPOM) {
2539 for (i = 0; i < 6; i += 2) {
2541 tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i)>>1));
2542 *(u16 *)(&dev->dev_addr[i]) = tmp;
2545 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
2546 //should I set IDR0 here?
2548 RT_TRACE(COMP_EPROM, "MAC addr:%pM\n", dev->dev_addr);
2549 priv->rf_type = RTL819X_DEFAULT_RF_TYPE; //default 1T2R
2550 priv->rf_chip = RF_8256;
2552 if (priv->card_8192_version == (u8)VERSION_819xU_A) {
2553 //read Tx power gain offset of legacy OFDM to HT rate
2554 if (bLoad_From_EEPOM)
2555 priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff>>1))&0xff00) >> 8;
2557 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
2558 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
2559 //read ThermalMeter from EEPROM
2560 if (bLoad_From_EEPOM)
2561 priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter>>1))&0x00ff);
2563 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2564 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
2565 //vivi, for tx power track
2566 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
2567 //read antenna tx power offset of B/C/D to A from EEPROM
2568 if (bLoad_From_EEPOM)
2569 priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff>>1))&0x0f00)>>8;
2571 priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
2572 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
2573 // Read CrystalCap from EEPROM
2574 if (bLoad_From_EEPOM)
2575 priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap>>1))&0x0f);
2577 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
2578 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
2579 //get per-channel Tx power level
2580 if (bLoad_From_EEPOM)
2581 priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver>>1))&0xff00)>>8;
2583 priv->EEPROM_Def_Ver = 1;
2584 RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
2585 if (priv->EEPROM_Def_Ver == 0) { //old eeprom definition
2587 if (bLoad_From_EEPOM)
2588 priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK>>1))&0xff) >> 8;
2590 priv->EEPROMTxPowerLevelCCK = 0x10;
2591 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
2592 for (i = 0; i < 3; i++) {
2593 if (bLoad_From_EEPOM) {
2594 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G+i)>>1);
2595 if (((EEPROM_TxPwIndex_OFDM_24G+i) % 2) == 0)
2596 tmpValue = tmpValue & 0x00ff;
2598 tmpValue = (tmpValue & 0xff00) >> 8;
2602 priv->EEPROMTxPowerLevelOFDM24G[i] = (u8) tmpValue;
2603 RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
2605 } else if (priv->EEPROM_Def_Ver == 1) {
2606 if (bLoad_From_EEPOM) {
2607 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1>>1));
2608 tmpValue = (tmpValue & 0xff00) >> 8;
2612 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
2614 if (bLoad_From_EEPOM)
2615 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2)>>1);
2618 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
2619 if (bLoad_From_EEPOM)
2620 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1>>1));
2623 *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
2624 if (bLoad_From_EEPOM)
2625 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1+2)>>1);
2628 priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
2629 }//endif EEPROM_Def_Ver == 1
2631 //update HAL variables
2633 for (i = 0; i < 14; i++) {
2635 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
2636 else if (i >= 4 && i <= 9)
2637 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
2639 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
2642 for (i = 0; i < 14; i++) {
2643 if (priv->EEPROM_Def_Ver == 0) {
2645 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
2646 else if (i >= 4 && i <= 9)
2647 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
2649 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
2650 } else if (priv->EEPROM_Def_Ver == 1) {
2652 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
2653 else if (i >= 4 && i <= 9)
2654 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
2656 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
2659 priv->TxPowerDiff = priv->EEPROMPwDiff;
2660 // Antenna B gain offset to antenna A, bit0~3
2661 priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
2662 // Antenna C gain offset to antenna A, bit4~7
2663 priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);
2664 // CrystalCap, bit12~15
2665 priv->CrystalCap = priv->EEPROMCrystalCap;
2666 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2667 // 92U does not enable TX power tracking.
2668 priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
2669 }//end if VersionID == VERSION_819xU_A
2671 //added by vivi, for dlink led, 20080416
2672 switch (priv->eeprom_CustomerID) {
2673 case EEPROM_CID_RUNTOP:
2674 priv->CustomerID = RT_CID_819x_RUNTOP;
2677 case EEPROM_CID_DLINK:
2678 priv->CustomerID = RT_CID_DLINK;
2682 priv->CustomerID = RT_CID_DEFAULT;
2687 switch (priv->CustomerID) {
2688 case RT_CID_819x_RUNTOP:
2689 priv->LedStrategy = SW_LED_MODE2;
2693 priv->LedStrategy = SW_LED_MODE4;
2697 priv->LedStrategy = SW_LED_MODE0;
2703 if (priv->rf_type == RF_1T2R) {
2704 RT_TRACE(COMP_EPROM, "\n1T2R config\n");
2706 RT_TRACE(COMP_EPROM, "\n2T4R config\n");
2709 // 2008/01/16 MH We can only know RF type in the function. So we have to init
2710 // DIG RATR table again.
2711 init_rate_adaptive(dev);
2712 //we need init DIG RATR table here again.
2714 RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
2718 static short rtl8192_get_channel_map(struct net_device *dev)
2720 struct r8192_priv *priv = ieee80211_priv(dev);
2721 if (priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN) {
2722 netdev_err(dev, "rtl8180_init: Error channel plan! Set to default.\n");
2723 priv->ChannelPlan = 0;
2725 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
2727 rtl819x_set_channel_map(priv->ChannelPlan, priv);
2731 static short rtl8192_init(struct net_device *dev)
2734 struct r8192_priv *priv = ieee80211_priv(dev);
2736 memset(&(priv->stats), 0, sizeof(struct Stats));
2737 memset(priv->txqueue_to_outpipemap, 0, 9);
2741 u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
2742 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
2746 u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 0, 4, 4};
2747 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
2750 rtl8192_init_priv_variable(dev);
2751 rtl8192_init_priv_lock(priv);
2752 rtl8192_init_priv_task(dev);
2753 rtl8192_get_eeprom_size(dev);
2754 rtl8192_read_eeprom_info(dev);
2755 rtl8192_get_channel_map(dev);
2757 init_timer(&priv->watch_dog_timer);
2758 priv->watch_dog_timer.data = (unsigned long)dev;
2759 priv->watch_dog_timer.function = watch_dog_timer_callback;
2760 if (rtl8192_usb_initendpoints(dev) != 0) {
2761 DMESG("Endopoints initialization failed");
2771 /******************************************************************************
2772 *function: This function actually only set RRSR, RATR and BW_OPMODE registers
2773 * not to do all the hw config as its name says
2774 * input: net_device dev
2777 * notice: This part need to modified according to the rate set we filtered
2778 * ****************************************************************************/
2779 static void rtl8192_hwconfig(struct net_device *dev)
2781 u32 regRATR = 0, regRRSR = 0;
2782 u8 regBwOpMode = 0, regTmp = 0;
2783 struct r8192_priv *priv = ieee80211_priv(dev);
2786 // Set RRSR, RATR, and BW_OPMODE registers
2788 switch (priv->ieee80211->mode) {
2789 case WIRELESS_MODE_B:
2790 regBwOpMode = BW_OPMODE_20MHZ;
2791 regRATR = RATE_ALL_CCK;
2792 regRRSR = RATE_ALL_CCK;
2794 case WIRELESS_MODE_A:
2795 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
2796 regRATR = RATE_ALL_OFDM_AG;
2797 regRRSR = RATE_ALL_OFDM_AG;
2799 case WIRELESS_MODE_G:
2800 regBwOpMode = BW_OPMODE_20MHZ;
2801 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2802 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2804 case WIRELESS_MODE_AUTO:
2806 if (Adapter->bInHctTest) {
2807 regBwOpMode = BW_OPMODE_20MHZ;
2808 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2809 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2814 regBwOpMode = BW_OPMODE_20MHZ;
2815 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2816 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2819 case WIRELESS_MODE_N_24G:
2820 // It support CCK rate by default.
2821 // CCK rate will be filtered out only when associated AP does not support it.
2822 regBwOpMode = BW_OPMODE_20MHZ;
2823 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2824 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2826 case WIRELESS_MODE_N_5G:
2827 regBwOpMode = BW_OPMODE_5G;
2828 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2829 regRRSR = RATE_ALL_OFDM_AG;
2833 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2834 ratr_value = regRATR;
2835 if (priv->rf_type == RF_1T2R)
2836 ratr_value &= ~(RATE_ALL_OFDM_2SS);
2837 write_nic_dword(dev, RATR0, ratr_value);
2838 write_nic_byte(dev, UFWP, 1);
2839 read_nic_byte(dev, 0x313, ®Tmp);
2840 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
2841 write_nic_dword(dev, RRSR, regRRSR);
2844 // Set Retry Limit here
2846 write_nic_word(dev, RETRY_LIMIT,
2847 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
2848 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
2849 // Set Contention Window here
2853 // Set Tx Antenna including Feedback control
2855 // Set Auto Rate fallback control
2861 //InitializeAdapter and PhyCfg
2862 static bool rtl8192_adapter_start(struct net_device *dev)
2864 struct r8192_priv *priv = ieee80211_priv(dev);
2866 bool init_status = true;
2867 u8 SECR_value = 0x0;
2869 RT_TRACE(COMP_INIT, "====>%s()\n", __func__);
2870 priv->Rf_Mode = RF_OP_By_SW_3wire;
2871 //for ASIC power on sequence
2872 write_nic_byte_E(dev, 0x5f, 0x80);
2874 write_nic_byte_E(dev, 0x5f, 0xf0);
2875 write_nic_byte_E(dev, 0x5d, 0x00);
2876 write_nic_byte_E(dev, 0x5e, 0x80);
2877 write_nic_byte(dev, 0x17, 0x37);
2879 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
2880 //config CPUReset Register
2881 //Firmware Reset or not?
2882 read_nic_dword(dev, CPU_GEN, &dwRegRead);
2883 if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
2884 dwRegRead |= CPU_GEN_SYSTEM_RESET; //do nothing here?
2885 else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
2886 dwRegRead |= CPU_GEN_FIRMWARE_RESET;
2888 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __func__, priv->pFirmware->firmware_status);
2890 write_nic_dword(dev, CPU_GEN, dwRegRead);
2892 rtl8192_BBConfig(dev);
2894 //Loopback mode or not
2895 priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
2897 read_nic_dword(dev, CPU_GEN, &dwRegRead);
2898 if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
2899 dwRegRead = ((dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
2900 else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
2901 dwRegRead |= CPU_CCK_LOOPBACK;
2903 RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __func__, priv->LoopbackMode);
2905 write_nic_dword(dev, CPU_GEN, dwRegRead);
2907 //after reset cpu, we need wait for a seconds to write in register.
2910 //xiong add for new bitfile:usb suspend reset pin set to 1. //do we need?
2911 read_nic_byte_E(dev, 0x5f, &tmp);
2912 write_nic_byte_E(dev, 0x5f, tmp|0x20);
2915 rtl8192_hwconfig(dev);
2918 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
2921 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
2922 write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
2925 write_nic_dword(dev, RCR, priv->ReceiveConfig);
2927 //Initialize Number of Reserved Pages in Firmware Queue
2928 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
2929 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
2930 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
2931 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
2932 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
2933 NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
2934 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
2935 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
2936 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
2939 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
2940 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
2942 if (priv->ResetProgress == RESET_TYPE_NORESET)
2943 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
2944 if (priv->ResetProgress == RESET_TYPE_NORESET) {
2945 CamResetAllEntry(dev);
2946 SECR_value |= SCR_TxEncEnable;
2947 SECR_value |= SCR_RxDecEnable;
2948 SECR_value |= SCR_NoSKMC;
2949 write_nic_byte(dev, SECR, SECR_value);
2953 write_nic_word(dev, ATIMWND, 2);
2954 write_nic_word(dev, BCN_INTERVAL, 100);
2956 #define DEFAULT_EDCA 0x005e4332
2959 for (i = 0; i < QOS_QUEUE_NUM; i++)
2960 write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
2962 #ifdef USB_RX_AGGREGATION_SUPPORT
2963 //3 For usb rx firmware aggregation control
2964 if (priv->ResetProgress == RESET_TYPE_NORESET) {
2966 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
2967 ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
2968 (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
2970 * If usb rx firmware aggregation is enabled,
2971 * when anyone of three threshold conditions above is reached,
2972 * firmware will send aggregated packet to driver.
2974 write_nic_dword(dev, 0x1a8, ulValue);
2975 priv->bCurrentRxAggrEnable = true;
2979 rtl8192_phy_configmac(dev);
2981 if (priv->card_8192_version == (u8) VERSION_819xU_A) {
2982 rtl8192_phy_getTxPower(dev);
2983 rtl8192_phy_setTxPower(dev, priv->chan);
2987 init_status = init_firmware(dev);
2989 RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n", __func__);
2992 RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
2995 if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
2996 if (pMgntInfo->RegRfOff == TRUE) { // User disable RF via registry.
2997 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
2998 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
2999 // Those actions will be discard in MgntActSet_RF_State because of the same state
3000 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
3001 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3002 } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) { // H/W or S/W RF OFF before sleep.
3003 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n", pMgntInfo->RfOffReason));
3004 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
3006 pHalData->eRFPowerState = eRfOn;
3007 pMgntInfo->RfOffReason = 0;
3008 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): RF is on ----------\n"));
3011 if (pHalData->eRFPowerState == eRfOff) {
3012 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
3013 // Those actions will be discard in MgntActSet_RF_State because of the same state
3014 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
3015 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3020 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3021 rtl8192_phy_RFConfig(dev);
3022 RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __func__);
3026 if (priv->ieee80211->FwRWRF)
3027 // We can force firmware to do RF-R/W
3028 priv->Rf_Mode = RF_OP_By_FW;
3030 priv->Rf_Mode = RF_OP_By_SW_3wire;
3033 rtl8192_phy_updateInitGain(dev);
3034 /*--set CCK and OFDM Block "ON"--*/
3035 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
3036 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
3038 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3041 read_nic_byte(dev, 0x301, &tmpvalue);
3042 if (tmpvalue == 0x03) {
3044 RT_TRACE(COMP_POWER_TRACKING, "D-cut\n");
3046 priv->bDcut = FALSE;
3047 RT_TRACE(COMP_POWER_TRACKING, "C-cut\n");
3049 dm_initialize_txpower_tracking(dev);
3051 if (priv->bDcut == TRUE) {
3053 u32 tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
3054 for (i = 0; i < TxBBGainTableLength; i++) {
3055 if (tmpRegA == priv->txbbgain_table[i].txbbgain_value) {
3056 priv->rfa_txpowertrackingindex = (u8)i;
3057 priv->rfa_txpowertrackingindex_real = (u8)i;
3058 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3063 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3065 for (i = 0; i < CCKTxBBGainTableLength; i++) {
3067 if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
3068 priv->cck_present_attentuation_20Mdefault = (u8) i;
3072 priv->cck_present_attentuation_40Mdefault = 0;
3073 priv->cck_present_attentuation_difference = 0;
3074 priv->cck_present_attentuation = priv->cck_present_attentuation_20Mdefault;
3078 write_nic_byte(dev, 0x87, 0x0);
3084 /* this configures registers for beacon tx and enables it via
3085 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
3086 * be used to stop beacon transmission
3088 /***************************************************************************
3089 -------------------------------NET STUFF---------------------------
3090 ***************************************************************************/
3092 static struct net_device_stats *rtl8192_stats(struct net_device *dev)
3094 struct r8192_priv *priv = ieee80211_priv(dev);
3096 return &priv->ieee80211->stats;
3099 static bool HalTxCheckStuck819xUsb(struct net_device *dev)
3101 struct r8192_priv *priv = ieee80211_priv(dev);
3103 bool bStuck = FALSE;
3104 read_nic_word(dev, 0x128, &RegTxCounter);
3105 RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n", __func__, RegTxCounter, priv->TxCounter);
3106 if (priv->TxCounter == RegTxCounter)
3109 priv->TxCounter = RegTxCounter;
3115 * <Assumption: RT_TX_SPINLOCK is acquired.>
3116 * First added: 2006.11.19 by emily
3118 static RESET_TYPE TxCheckStuck(struct net_device *dev)
3120 struct r8192_priv *priv = ieee80211_priv(dev);
3122 bool bCheckFwTxCnt = false;
3125 // Decide such threshold according to current power save mode
3128 for (QueueID = 0; QueueID <= BEACON_QUEUE; QueueID++) {
3129 if (QueueID == TXCMD_QUEUE)
3131 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
3132 if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0))
3134 if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
3138 bCheckFwTxCnt = true;
3140 if (bCheckFwTxCnt) {
3141 if (HalTxCheckStuck819xUsb(dev)) {
3142 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
3143 return RESET_TYPE_SILENT;
3146 return RESET_TYPE_NORESET;
3149 static bool HalRxCheckStuck819xUsb(struct net_device *dev)
3152 struct r8192_priv *priv = ieee80211_priv(dev);
3153 bool bStuck = FALSE;
3154 static u8 rx_chk_cnt;
3155 read_nic_word(dev, 0x130, &RegRxCounter);
3156 RT_TRACE(COMP_RESET, "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__, RegRxCounter, priv->RxCounter);
3157 // If rssi is small, we should check rx for long time because of bad rx.
3158 // or maybe it will continuous silent reset every 2 seconds.
3160 if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) {
3161 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
3162 } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
3163 ((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_40M) ||
3164 (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_20M))) {
3169 } else if (((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_40M) ||
3170 (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_20M)) &&
3171 priv->undecorated_smoothed_pwdb >= VeryLowRSSI) {
3183 if (priv->RxCounter == RegRxCounter)
3186 priv->RxCounter = RegRxCounter;
3191 static RESET_TYPE RxCheckStuck(struct net_device *dev)
3193 struct r8192_priv *priv = ieee80211_priv(dev);
3194 bool bRxCheck = FALSE;
3196 if (priv->IrpPendingCount > 1)
3200 if (HalRxCheckStuck819xUsb(dev)) {
3201 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
3202 return RESET_TYPE_SILENT;
3205 return RESET_TYPE_NORESET;
3210 * This function is called by Checkforhang to check whether we should ask OS to reset driver
3212 * \param pAdapter The adapter context for this miniport
3214 * Note:NIC with USB interface sholud not call this function because we cannot scan descriptor
3215 * to judge whether there is tx stuck.
3216 * Note: This function may be required to be rewrite for Vista OS.
3217 * <<<Assumption: Tx spinlock has been acquired >>>
3219 * 8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
3221 static RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
3223 struct r8192_priv *priv = ieee80211_priv(dev);
3224 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
3225 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
3226 RT_RF_POWER_STATE rfState;
3228 rfState = priv->ieee80211->eRFPowerState;
3230 TxResetType = TxCheckStuck(dev);
3231 if (rfState != eRfOff ||
3232 (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
3233 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
3234 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
3235 // if driver is in firmware download failure status, driver should initialize RF in the following
3236 // silent reset procedure Emily, 2008.01.21
3238 // Driver should not check RX stuck in IBSS mode because it is required to
3239 // set Check BSSID in order to send beacon, however, if check BSSID is
3240 // set, STA cannot hear any packet at all. Emily, 2008.04.12
3241 RxResetType = RxCheckStuck(dev);
3243 if (TxResetType == RESET_TYPE_NORMAL || RxResetType == RESET_TYPE_NORMAL) {
3244 return RESET_TYPE_NORMAL;
3245 } else if (TxResetType == RESET_TYPE_SILENT || RxResetType == RESET_TYPE_SILENT) {
3246 RT_TRACE(COMP_RESET, "%s():silent reset\n", __func__);
3247 return RESET_TYPE_SILENT;
3249 return RESET_TYPE_NORESET;
3254 void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
3255 int _rtl8192_up(struct net_device *dev);
3256 int rtl8192_close(struct net_device *dev);
3260 static void CamRestoreAllEntry(struct net_device *dev)
3263 struct r8192_priv *priv = ieee80211_priv(dev);
3264 u8 *MacAddr = priv->ieee80211->current_network.bssid;
3266 static u8 CAM_CONST_ADDR[4][6] = {
3267 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3268 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3269 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3270 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
3271 static u8 CAM_CONST_BROAD[] = {
3272 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3274 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
3277 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
3278 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) {
3280 for (EntryId = 0; EntryId < 4; EntryId++) {
3281 MacAddr = CAM_CONST_ADDR[EntryId];
3282 setKey(dev, EntryId, EntryId,
3283 priv->ieee80211->pairwise_key_type,
3287 } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
3289 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3290 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3291 (u8 *)dev->dev_addr, 0, NULL);
3293 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3295 } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
3297 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3298 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3299 (u8 *)dev->dev_addr, 0, NULL);
3301 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3307 if (priv->ieee80211->group_key_type == KEY_TYPE_TKIP) {
3308 MacAddr = CAM_CONST_BROAD;
3309 for (EntryId = 1; EntryId < 4; EntryId++) {
3310 setKey(dev, EntryId, EntryId,
3311 priv->ieee80211->group_key_type,
3314 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3315 setKey(dev, 0, 0, priv->ieee80211->group_key_type,
3316 CAM_CONST_ADDR[0], 0, NULL);
3317 } else if (priv->ieee80211->group_key_type == KEY_TYPE_CCMP) {
3318 MacAddr = CAM_CONST_BROAD;
3319 for (EntryId = 1; EntryId < 4; EntryId++) {
3320 setKey(dev, EntryId, EntryId,
3321 priv->ieee80211->group_key_type,
3325 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3326 setKey(dev, 0, 0, priv->ieee80211->group_key_type,
3327 CAM_CONST_ADDR[0], 0, NULL);
3330 //////////////////////////////////////////////////////////////
3331 // This function is used to fix Tx/Rx stop bug temporarily.
3332 // This function will do "system reset" to NIC when Tx or Rx is stuck.
3333 // The method checking Tx/Rx stuck of this function is supported by FW,
3334 // which reports Tx and Rx counter to register 0x128 and 0x130.
3335 //////////////////////////////////////////////////////////////
3336 static void rtl819x_ifsilentreset(struct net_device *dev)
3338 struct r8192_priv *priv = ieee80211_priv(dev);
3340 int reset_status = 0;
3341 struct ieee80211_device *ieee = priv->ieee80211;
3344 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
3345 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
3347 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3350 RT_TRACE(COMP_RESET, "=========>Reset progress!! \n");
3352 // Set the variable for reset.
3353 priv->ResetProgress = RESET_TYPE_SILENT;
3354 down(&priv->wx_sem);
3355 if (priv->up == 0) {
3356 RT_TRACE(COMP_ERR, "%s():the driver is not up! return\n", __func__);
3361 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n", __func__);
3363 rtl8192_rtx_disable(dev);
3364 rtl8192_cancel_deferred_work(priv);
3366 del_timer_sync(&priv->watch_dog_timer);
3368 ieee->sync_scan_hurryup = 1;
3369 if (ieee->state == IEEE80211_LINKED) {
3370 down(&ieee->wx_sem);
3371 netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
3372 ieee80211_stop_send_beacons(priv->ieee80211);
3373 del_timer_sync(&ieee->associate_timer);
3374 cancel_delayed_work(&ieee->associate_retry_wq);
3375 ieee80211_stop_scan(ieee);
3376 netif_carrier_off(dev);
3379 netdev_dbg(dev, "ieee->state is NOT LINKED\n");
3380 ieee80211_softmac_stop_protocol(priv->ieee80211);
3383 RT_TRACE(COMP_RESET, "%s():<==========down process is finished\n", __func__);
3384 RT_TRACE(COMP_RESET, "%s():===========>start up the driver\n", __func__);
3385 reset_status = _rtl8192_up(dev);
3387 RT_TRACE(COMP_RESET, "%s():<===========up process is finished\n", __func__);
3388 if (reset_status == -EAGAIN) {
3389 if (reset_times < 3) {
3393 RT_TRACE(COMP_ERR, " ERR!!! %s(): Reset Failed!!\n", __func__);
3396 ieee->is_silent_reset = 1;
3397 EnableHWSecurityConfig8192(dev);
3398 if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
3399 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3401 queue_work(ieee->wq, &ieee->associate_complete_wq);
3403 } else if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC) {
3404 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3405 ieee->link_change(ieee->dev);
3407 ieee80211_start_send_beacons(ieee);
3409 if (ieee->data_hard_resume)
3410 ieee->data_hard_resume(ieee->dev);
3411 netif_carrier_on(ieee->dev);
3414 CamRestoreAllEntry(dev);
3416 priv->ResetProgress = RESET_TYPE_NORESET;
3417 priv->reset_count++;
3419 priv->bForcedSilentReset = false;
3420 priv->bResetInProgress = false;
3422 // For test --> force write UFWP.
3423 write_nic_byte(dev, UFWP, 1);
3424 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
3428 void CAM_read_entry(struct net_device *dev, u32 iIndex)
3430 u32 target_command = 0;
3431 u32 target_content = 0;
3435 for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {
3436 // polling bit, and No Write enable, and address
3437 target_command = entry_i+CAM_CONTENT_COUNT*iIndex;
3438 target_command = target_command | BIT31;
3440 //Check polling bit is clear
3441 while ((i--) >= 0) {
3442 read_nic_dword(dev, RWCAM, &ulStatus);
3443 if (ulStatus & BIT31)
3448 write_nic_dword(dev, RWCAM, target_command);
3449 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A0: %x \n", target_command);
3450 read_nic_dword(dev, RCAMO, &target_content);
3451 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n", target_content);
3456 static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
3457 u32 *TotalRxDataNum)
3463 *TotalRxDataNum = 0;
3465 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
3466 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
3467 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
3468 for (i = 0; i < priv->ieee80211->LinkDetectInfo.SlotNum; i++) {
3469 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
3470 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
3475 void rtl819x_watchdog_wqcallback(struct work_struct *work)
3477 struct delayed_work *dwork = container_of(work, struct delayed_work, work);
3478 struct r8192_priv *priv = container_of(dwork, struct r8192_priv, watch_dog_wq);
3479 struct net_device *dev = priv->ieee80211->dev;
3480 struct ieee80211_device *ieee = priv->ieee80211;
3481 RESET_TYPE ResetType = RESET_TYPE_NORESET;
3482 static u8 check_reset_cnt;
3483 bool bBusyTraffic = false;
3484 u32 TotalRxBcnNum = 0;
3485 u32 TotalRxDataNum = 0;
3489 hal_dm_watchdog(dev);
3491 //to get busy traffic condition
3492 if (ieee->state == IEEE80211_LINKED) {
3493 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 666 ||
3494 ieee->LinkDetectInfo.NumTxOkInPeriod > 666 ) {
3495 bBusyTraffic = true;
3497 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3498 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3499 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
3501 //added by amy for AP roaming
3502 if (priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA) {
3504 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
3505 if ((TotalRxBcnNum+TotalRxDataNum) == 0) {
3507 if (rfState == eRfOff)
3508 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
3510 netdev_dbg(dev, "===>%s(): AP is power off, connect another one\n", __func__);
3511 priv->ieee80211->state = IEEE80211_ASSOCIATING;
3512 notify_wx_assoc_event(priv->ieee80211);
3513 RemovePeerTS(priv->ieee80211, priv->ieee80211->current_network.bssid);
3514 priv->ieee80211->link_change(dev);
3515 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
3519 priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3520 priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod = 0;
3521 //check if reset the driver
3522 if (check_reset_cnt++ >= 3) {
3523 ResetType = rtl819x_ifcheck_resetornot(dev);
3524 check_reset_cnt = 3;
3526 if ((priv->force_reset) || (priv->ResetProgress == RESET_TYPE_NORESET &&
3527 (priv->bForcedSilentReset ||
3528 (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) { // This is control by OID set in Pomelo
3529 RT_TRACE(COMP_RESET, "%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n", __func__, priv->force_reset, priv->ResetProgress, priv->bForcedSilentReset, priv->bDisableNormalResetCheck, ResetType);
3530 rtl819x_ifsilentreset(dev);
3532 priv->force_reset = false;
3533 priv->bForcedSilentReset = false;
3534 priv->bResetInProgress = false;
3535 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
3539 void watch_dog_timer_callback(unsigned long data)
3541 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
3542 queue_delayed_work(priv->priv_wq, &priv->watch_dog_wq, 0);
3543 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
3545 int _rtl8192_up(struct net_device *dev)
3547 struct r8192_priv *priv = ieee80211_priv(dev);
3548 int init_status = 0;
3550 priv->ieee80211->ieee_up = 1;
3551 RT_TRACE(COMP_INIT, "Bringing up iface");
3552 init_status = rtl8192_adapter_start(dev);
3554 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n", __func__);
3555 priv->up = priv->ieee80211->ieee_up = 0;
3558 RT_TRACE(COMP_INIT, "start adapter finished\n");
3559 rtl8192_rx_enable(dev);
3560 if (priv->ieee80211->state != IEEE80211_LINKED)
3561 ieee80211_softmac_start_protocol(priv->ieee80211);
3562 ieee80211_reset_queue(priv->ieee80211);
3563 watch_dog_timer_callback((unsigned long) dev);
3564 if (!netif_queue_stopped(dev))
3565 netif_start_queue(dev);
3567 netif_wake_queue(dev);
3573 static int rtl8192_open(struct net_device *dev)
3575 struct r8192_priv *priv = ieee80211_priv(dev);
3577 down(&priv->wx_sem);
3578 ret = rtl8192_up(dev);
3585 int rtl8192_up(struct net_device *dev)
3587 struct r8192_priv *priv = ieee80211_priv(dev);
3589 if (priv->up == 1) return -1;
3591 return _rtl8192_up(dev);
3595 int rtl8192_close(struct net_device *dev)
3597 struct r8192_priv *priv = ieee80211_priv(dev);
3600 down(&priv->wx_sem);
3602 ret = rtl8192_down(dev);
3610 int rtl8192_down(struct net_device *dev)
3612 struct r8192_priv *priv = ieee80211_priv(dev);
3615 if (priv->up == 0) return -1;
3618 priv->ieee80211->ieee_up = 0;
3619 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
3621 if (!netif_queue_stopped(dev))
3622 netif_stop_queue(dev);
3624 rtl8192_rtx_disable(dev);
3626 /* Tx related queue release */
3627 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3628 skb_queue_purge(&priv->ieee80211->skb_waitQ[i]);
3629 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3630 skb_queue_purge(&priv->ieee80211->skb_aggQ[i]);
3632 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3633 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ[i]);
3635 //as cancel_delayed_work will del work->timer, so if work is not defined as struct delayed_work, it will corrupt
3636 rtl8192_cancel_deferred_work(priv);
3638 del_timer_sync(&priv->watch_dog_timer);
3641 ieee80211_softmac_stop_protocol(priv->ieee80211);
3642 memset(&priv->ieee80211->current_network, 0, offsetof(struct ieee80211_network, list));
3643 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
3649 void rtl8192_commit(struct net_device *dev)
3651 struct r8192_priv *priv = ieee80211_priv(dev);
3652 int reset_status = 0;
3653 if (priv->up == 0) return;
3656 rtl8192_cancel_deferred_work(priv);
3657 del_timer_sync(&priv->watch_dog_timer);
3659 ieee80211_softmac_stop_protocol(priv->ieee80211);
3661 rtl8192_rtx_disable(dev);
3662 reset_status = _rtl8192_up(dev);
3666 void rtl8192_restart(struct work_struct *work)
3668 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
3669 struct net_device *dev = priv->ieee80211->dev;
3671 down(&priv->wx_sem);
3673 rtl8192_commit(dev);
3678 static void r8192_set_multicast(struct net_device *dev)
3680 struct r8192_priv *priv = ieee80211_priv(dev);
3685 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
3687 if (promisc != priv->promisc)
3689 priv->promisc = promisc;
3693 static int r8192_set_mac_adr(struct net_device *dev, void *mac)
3695 struct r8192_priv *priv = ieee80211_priv(dev);
3696 struct sockaddr *addr = mac;
3698 down(&priv->wx_sem);
3700 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
3702 schedule_work(&priv->reset_wq);
3708 /* based on ipw2200 driver */
3709 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3711 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3712 struct iwreq *wrq = (struct iwreq *)rq;
3714 struct ieee80211_device *ieee = priv->ieee80211;
3716 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3717 struct iw_point *p = &wrq->u.data;
3718 struct ieee_param *ipw = NULL;
3720 down(&priv->wx_sem);
3723 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3728 ipw = memdup_user(p->pointer, p->length);
3735 case RTL_IOCTL_WPA_SUPPLICANT:
3736 //parse here for HW security
3737 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
3738 if (ipw->u.crypt.set_tx) {
3739 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
3740 ieee->pairwise_key_type = KEY_TYPE_CCMP;
3741 } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
3742 ieee->pairwise_key_type = KEY_TYPE_TKIP;
3743 } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
3744 if (ipw->u.crypt.key_len == 13)
3745 ieee->pairwise_key_type = KEY_TYPE_WEP104;
3746 else if (ipw->u.crypt.key_len == 5)
3747 ieee->pairwise_key_type = KEY_TYPE_WEP40;
3749 ieee->pairwise_key_type = KEY_TYPE_NA;
3752 if (ieee->pairwise_key_type) {
3753 memcpy((u8 *)key, ipw->u.crypt.key, 16);
3754 EnableHWSecurityConfig8192(dev);
3755 //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!
3757 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
3758 if (ieee->auth_mode != 2)
3759 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
3762 memcpy((u8 *)key, ipw->u.crypt.key, 16);
3763 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
3764 ieee->group_key_type = KEY_TYPE_CCMP;
3765 } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
3766 ieee->group_key_type = KEY_TYPE_TKIP;
3767 } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
3768 if (ipw->u.crypt.key_len == 13)
3769 ieee->group_key_type = KEY_TYPE_WEP104;
3770 else if (ipw->u.crypt.key_len == 5)
3771 ieee->group_key_type = KEY_TYPE_WEP40;
3773 ieee->group_key_type = KEY_TYPE_NA;
3776 if (ieee->group_key_type) {
3777 setKey(dev, ipw->u.crypt.idx,
3778 ipw->u.crypt.idx, //KeyIndex
3779 ieee->group_key_type, //KeyType
3780 broadcast_addr, //MacAddr
3786 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
3800 static u8 HwRateToMRate90(bool bIsHT, u8 rate)
3806 case DESC90_RATE1M: ret_rate = MGN_1M; break;
3807 case DESC90_RATE2M: ret_rate = MGN_2M; break;
3808 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
3809 case DESC90_RATE11M: ret_rate = MGN_11M; break;
3810 case DESC90_RATE6M: ret_rate = MGN_6M; break;
3811 case DESC90_RATE9M: ret_rate = MGN_9M; break;
3812 case DESC90_RATE12M: ret_rate = MGN_12M; break;
3813 case DESC90_RATE18M: ret_rate = MGN_18M; break;
3814 case DESC90_RATE24M: ret_rate = MGN_24M; break;
3815 case DESC90_RATE36M: ret_rate = MGN_36M; break;
3816 case DESC90_RATE48M: ret_rate = MGN_48M; break;
3817 case DESC90_RATE54M: ret_rate = MGN_54M; break;
3821 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
3827 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
3828 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
3829 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
3830 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
3831 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
3832 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
3833 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
3834 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
3835 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
3836 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
3837 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
3838 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
3839 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
3840 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
3841 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
3842 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
3843 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
3847 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
3856 * Function: UpdateRxPktTimeStamp
3857 * Overview: Record the TSF time stamp when receiving a packet
3865 * (pRfd->Status.TimeStampHigh is updated)
3866 * (pRfd->Status.TimeStampLow is updated)
3870 static void UpdateRxPktTimeStamp8190(struct net_device *dev,
3871 struct ieee80211_rx_stats *stats)
3873 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3875 if (stats->bIsAMPDU && !stats->bFirstMPDU) {
3876 stats->mac_time[0] = priv->LastRxDescTSFLow;
3877 stats->mac_time[1] = priv->LastRxDescTSFHigh;
3879 priv->LastRxDescTSFLow = stats->mac_time[0];
3880 priv->LastRxDescTSFHigh = stats->mac_time[1];
3886 static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
3888 long signal_power; // in dBm.
3890 // Translate to dBm (x=0.5y-95).
3891 signal_power = (long)((signal_strength_index + 1) >> 1);
3894 return signal_power;
3898 /* 2008/01/22 MH We can not declare RSSI/EVM total value of sliding window to
3899 be a local static. Otherwise, it may increase when we return from S3/S4. The
3900 value will be kept in memory or disk. Declare the value in the adaptor
3901 and it will be reinitialized when returned from S3/S4. */
3902 static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
3903 struct ieee80211_rx_stats *pprevious_stats,
3904 struct ieee80211_rx_stats *pcurrent_stats)
3906 bool bcheck = false;
3908 u32 nspatial_stream, tmp_val;
3909 static u32 slide_rssi_index, slide_rssi_statistics;
3910 static u32 slide_evm_index, slide_evm_statistics;
3911 static u32 last_rssi, last_evm;
3913 static u32 slide_beacon_adc_pwdb_index, slide_beacon_adc_pwdb_statistics;
3914 static u32 last_beacon_adc_pwdb;
3916 struct ieee80211_hdr_3addr *hdr;
3918 unsigned int frag, seq;
3919 hdr = (struct ieee80211_hdr_3addr *)buffer;
3920 sc = le16_to_cpu(hdr->seq_ctl);
3921 frag = WLAN_GET_SEQ_FRAG(sc);
3922 seq = WLAN_GET_SEQ_SEQ(sc);
3923 //cosa add 04292008 to record the sequence number
3924 pcurrent_stats->Seq_Num = seq;
3926 // Check whether we should take the previous packet into accounting
3928 if (!pprevious_stats->bIsAMPDU) {
3929 // if previous packet is not aggregated packet
3933 if (slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
3934 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
3935 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
3936 priv->stats.slide_rssi_total -= last_rssi;
3938 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
3940 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
3941 if (slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
3942 slide_rssi_index = 0;
3944 // <1> Showed on UI for user, in dbm
3945 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
3946 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
3947 pcurrent_stats->rssi = priv->stats.signal_strength;
3949 // If the previous packet does not match the criteria, neglect it
3951 if (!pprevious_stats->bPacketMatchBSSID) {
3952 if (!pprevious_stats->bToSelfBA)
3960 //rtl8190_process_cck_rxpathsel(priv,pprevious_stats);//only rtl8190 supported
3965 priv->stats.num_process_phyinfo++;
3967 /* record the general signal strength to the sliding window. */
3970 // <2> Showed on UI for engineering
3971 // hardware does not provide rssi information for each rf path in CCK
3972 if (!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
3973 for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++) {
3974 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
3977 //Fixed by Jacken 2008-03-20
3978 if (priv->stats.rx_rssi_percentage[rfpath] == 0)
3979 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
3980 if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) {
3981 priv->stats.rx_rssi_percentage[rfpath] =
3982 ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
3983 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
3984 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
3986 priv->stats.rx_rssi_percentage[rfpath] =
3987 ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
3988 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
3990 RT_TRACE(COMP_DBG, "priv->stats.rx_rssi_percentage[rfPath] = %d \n", priv->stats.rx_rssi_percentage[rfpath]);
3998 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
3999 pprevious_stats->bIsCCK ? "CCK" : "OFDM",
4000 pprevious_stats->RxPWDBAll);
4002 if (pprevious_stats->bPacketBeacon) {
4003 /* record the beacon pwdb to the sliding window. */
4004 if (slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) {
4005 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
4006 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
4007 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
4009 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
4010 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
4011 slide_beacon_adc_pwdb_index++;
4012 if (slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
4013 slide_beacon_adc_pwdb_index = 0;
4014 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
4015 if (pprevious_stats->RxPWDBAll >= 3)
4016 pprevious_stats->RxPWDBAll -= 3;
4019 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
4020 pprevious_stats->bIsCCK ? "CCK" : "OFDM",
4021 pprevious_stats->RxPWDBAll);
4024 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4025 if (priv->undecorated_smoothed_pwdb < 0) // initialize
4026 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
4027 if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
4028 priv->undecorated_smoothed_pwdb =
4029 (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4030 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4031 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
4033 priv->undecorated_smoothed_pwdb =
4034 (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4035 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4043 /* record the general EVM to the sliding window. */
4044 if (pprevious_stats->SignalQuality) {
4045 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4046 if (slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
4047 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
4048 last_evm = priv->stats.slide_evm[slide_evm_index];
4049 priv->stats.slide_evm_total -= last_evm;
4052 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
4054 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
4055 if (slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
4056 slide_evm_index = 0;
4058 // <1> Showed on UI for user, in percentage.
4059 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
4060 priv->stats.signal_quality = tmp_val;
4061 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
4062 priv->stats.last_signal_strength_inpercent = tmp_val;
4065 // <2> Showed on UI for engineering
4066 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4067 for (nspatial_stream = 0; nspatial_stream < 2; nspatial_stream++) { // 2 spatial stream
4068 if (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) {
4069 if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
4070 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
4071 priv->stats.rx_evm_percentage[nspatial_stream] =
4072 ((priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
4073 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
4082 /*-----------------------------------------------------------------------------
4083 * Function: rtl819x_query_rxpwrpercentage()
4087 * Input: char antpower
4091 * Return: 0-100 percentage
4095 * 05/26/2008 amy Create Version 0 porting from windows code.
4097 *---------------------------------------------------------------------------*/
4098 static u8 rtl819x_query_rxpwrpercentage(char antpower)
4100 if ((antpower <= -100) || (antpower >= 20))
4102 else if (antpower >= 0)
4105 return 100 + antpower;
4107 } /* QueryRxPwrPercentage */
4109 static u8 rtl819x_evm_dbtopercentage(char value)
4119 ret_val = 0 - ret_val;
4127 // We want good-looking for signal strength/quality
4128 // 2007/7/19 01:09, by cosa.
4130 static long rtl819x_signal_scale_mapping(long currsig)
4134 // Step 1. Scale mapping.
4135 if (currsig >= 61 && currsig <= 100)
4136 retsig = 90 + ((currsig - 60) / 4);
4137 else if (currsig >= 41 && currsig <= 60)
4138 retsig = 78 + ((currsig - 40) / 2);
4139 else if (currsig >= 31 && currsig <= 40)
4140 retsig = 66 + (currsig - 30);
4141 else if (currsig >= 21 && currsig <= 30)
4142 retsig = 54 + (currsig - 20);
4143 else if (currsig >= 5 && currsig <= 20)
4144 retsig = 42 + (((currsig - 5) * 2) / 3);
4145 else if (currsig == 4)
4147 else if (currsig == 3)
4149 else if (currsig == 2)
4151 else if (currsig == 1)
4159 static inline bool rx_hal_is_cck_rate(struct rx_drvinfo_819x_usb *pdrvinfo)
4164 switch (pdrvinfo->RxRate) {
4167 case DESC90_RATE5_5M:
4168 case DESC90_RATE11M:
4175 static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
4176 struct ieee80211_rx_stats *pstats,
4177 rx_drvinfo_819x_usb *pdrvinfo,
4178 struct ieee80211_rx_stats *precord_stats,
4179 bool bpacket_match_bssid,
4180 bool bpacket_toself,
4184 phy_sts_ofdm_819xusb_t *pofdm_buf;
4185 phy_sts_cck_819xusb_t *pcck_buf;
4186 phy_ofdm_rx_status_rxsc_sgien_exintfflag *prxsc;
4188 u8 i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
4189 char rx_pwr[4], rx_pwr_all = 0;
4190 char rx_snrX, rx_evmX;
4192 u32 RSSI, total_rssi = 0;
4198 priv->stats.numqry_phystatus++;
4200 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
4202 // Record it for next packet processing
4203 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
4204 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
4205 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
4206 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;
4207 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
4208 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
4210 prxpkt = (u8 *)pdrvinfo;
4212 /* Move pointer to the 16th bytes. Phy status start address. */
4213 prxpkt += sizeof(rx_drvinfo_819x_usb);
4215 /* Initial the cck and ofdm buffer pointer */
4216 pcck_buf = (phy_sts_cck_819xusb_t *)prxpkt;
4217 pofdm_buf = (phy_sts_ofdm_819xusb_t *)prxpkt;
4219 pstats->RxMIMOSignalQuality[0] = -1;
4220 pstats->RxMIMOSignalQuality[1] = -1;
4221 precord_stats->RxMIMOSignalQuality[0] = -1;
4222 precord_stats->RxMIMOSignalQuality[1] = -1;
4226 // (1)Hardware does not provide RSSI for CCK
4230 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
4234 priv->stats.numqry_phystatusCCK++;
4236 if (!priv->bCckHighPower) {
4237 report = pcck_buf->cck_agc_rpt & 0xc0;
4240 //Fixed by Jacken from Bryant 2008-03-20
4241 //Original value is -38 , -26 , -14 , -2
4242 //Fixed value is -35 , -23 , -11 , 6
4244 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
4247 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
4250 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
4253 rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
4257 report = pcck_buf->cck_agc_rpt & 0x60;
4261 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4264 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4267 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4270 rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4275 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
4276 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
4277 pstats->RecvSignalPower = pwdb_all;
4280 // (3) Get Signal Quality (EVM)
4283 if (pstats->RxPWDBAll > 40) {
4286 sq = pcck_buf->sq_rpt;
4288 if (pcck_buf->sq_rpt > 64)
4290 else if (pcck_buf->sq_rpt < 20)
4293 sq = ((64-sq) * 100) / 44;
4295 pstats->SignalQuality = precord_stats->SignalQuality = sq;
4296 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
4297 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
4300 priv->stats.numqry_phystatusHT++;
4302 // (1)Get RSSI for HT rate
4304 for (i = RF90_PATH_A; i < priv->NumTotalRFPath; i++) {
4305 // 2008/01/30 MH we will judge RF RX path now.
4306 if (priv->brfpath_rxenable[i])
4311 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
4314 //Fixed by Jacken from Bryant 2008-03-20
4315 //Original value is 106
4316 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
4318 //Get Rx snr value in DB
4319 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
4320 rx_snrX = (char)(tmp_rxsnr);
4322 priv->stats.rxSNRdB[i] = (long)rx_snrX;
4324 /* Translate DBM to percentage. */
4325 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
4328 /* Record Signal Strength for next packet */
4329 pstats->RxMIMOSignalStrength[i] = (u8) RSSI;
4330 precord_stats->RxMIMOSignalStrength[i] = (u8) RSSI;
4335 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
4337 //Fixed by Jacken from Bryant 2008-03-20
4338 //Original value is 106
4339 rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1)& 0x7f) -106;
4340 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
4342 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
4343 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
4346 // (3)EVM of HT rate
4348 if (pdrvinfo->RxHT && pdrvinfo->RxRate >= DESC90_RATEMCS8 &&
4349 pdrvinfo->RxRate <= DESC90_RATEMCS15)
4350 max_spatial_stream = 2; //both spatial stream make sense
4352 max_spatial_stream = 1; //only spatial stream 1 makes sense
4354 for (i = 0; i < max_spatial_stream; i++) {
4355 tmp_rxevm = pofdm_buf->rxevm_X[i];
4356 rx_evmX = (char)(tmp_rxevm);
4358 // Do not use shift operation like "rx_evmX >>= 1" because the compiler of free build environment
4359 // will set the most significant bit to "zero" when doing shifting operation which may change a negative
4360 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
4363 evm = rtl819x_evm_dbtopercentage(rx_evmX);
4364 if (i == 0) // Fill value in RFD, Get the first spatial stream only
4365 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
4366 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
4370 /* record rx statistics for debug */
4371 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
4372 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
4373 if (pdrvinfo->BW) //40M channel
4374 priv->stats.received_bwtype[1+prxsc->rxsc]++;
4376 priv->stats.received_bwtype[0]++;
4379 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
4380 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
4382 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
4384 // We can judge RX path number now.
4386 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
4388 } /* QueryRxPhyStatus8190Pci */
4390 static void rtl8192_record_rxdesc_forlateruse(struct ieee80211_rx_stats *psrc_stats,
4391 struct ieee80211_rx_stats *ptarget_stats)
4393 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
4394 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
4395 ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
4399 static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
4400 struct ieee80211_rx_stats *pstats,
4401 rx_drvinfo_819x_usb *pdrvinfo)
4403 // TODO: We must only check packet for current MAC address. Not finish
4404 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4405 struct net_device *dev = info->dev;
4406 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4407 bool bpacket_match_bssid, bpacket_toself;
4408 bool bPacketBeacon = FALSE, bToSelfBA = FALSE;
4409 static struct ieee80211_rx_stats previous_stats;
4410 struct ieee80211_hdr_3addr *hdr;//by amy
4413 // Get Signal Quality for only RX data queue (but not command queue)
4418 /* Get MAC frame start address. */
4419 tmp_buf = (u8 *)skb->data;
4421 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
4422 fc = le16_to_cpu(hdr->frame_ctl);
4423 type = WLAN_FC_GET_TYPE(fc);
4424 praddr = hdr->addr1;
4426 /* Check if the received packet is acceptable. */
4427 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
4428 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
4429 && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV));
4430 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
4432 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
4433 bPacketBeacon = true;
4434 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) {
4435 if ((eqMacAddr(praddr, dev->dev_addr)))
4441 if (bpacket_match_bssid)
4442 priv->stats.numpacket_matchbssid++;
4444 priv->stats.numpacket_toself++;
4446 // Process PHY information for previous packet (RSSI/PWDB/EVM)
4448 // Because phy information is contained in the last packet of AMPDU only, so driver
4449 // should process phy information of previous packet
4450 rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
4451 rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid, bpacket_toself, bPacketBeacon, bToSelfBA);
4452 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
4457 * Function: UpdateReceivedRateHistogramStatistics
4458 * Overview: Record the received data rate
4461 * struct net_device *dev
4462 * struct ieee80211_rx_stats *stats
4466 * (priv->stats.ReceivedRateHistogram[] is updated)
4471 UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
4472 struct ieee80211_rx_stats *stats)
4474 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4475 u32 rcvType = 1; //0: Total, 1:OK, 2:CRC, 3:ICV
4477 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
4482 else if (stats->bICV)
4485 if (stats->bShortPreamble)
4486 preamble_guardinterval = 1;// short
4488 preamble_guardinterval = 0;// long
4490 switch (stats->rate) {
4494 case MGN_1M: rateIndex = 0; break;
4495 case MGN_2M: rateIndex = 1; break;
4496 case MGN_5_5M: rateIndex = 2; break;
4497 case MGN_11M: rateIndex = 3; break;
4501 case MGN_6M: rateIndex = 4; break;
4502 case MGN_9M: rateIndex = 5; break;
4503 case MGN_12M: rateIndex = 6; break;
4504 case MGN_18M: rateIndex = 7; break;
4505 case MGN_24M: rateIndex = 8; break;
4506 case MGN_36M: rateIndex = 9; break;
4507 case MGN_48M: rateIndex = 10; break;
4508 case MGN_54M: rateIndex = 11; break;
4510 // 11n High throughput rate
4512 case MGN_MCS0: rateIndex = 12; break;
4513 case MGN_MCS1: rateIndex = 13; break;
4514 case MGN_MCS2: rateIndex = 14; break;
4515 case MGN_MCS3: rateIndex = 15; break;
4516 case MGN_MCS4: rateIndex = 16; break;
4517 case MGN_MCS5: rateIndex = 17; break;
4518 case MGN_MCS6: rateIndex = 18; break;
4519 case MGN_MCS7: rateIndex = 19; break;
4520 case MGN_MCS8: rateIndex = 20; break;
4521 case MGN_MCS9: rateIndex = 21; break;
4522 case MGN_MCS10: rateIndex = 22; break;
4523 case MGN_MCS11: rateIndex = 23; break;
4524 case MGN_MCS12: rateIndex = 24; break;
4525 case MGN_MCS13: rateIndex = 25; break;
4526 case MGN_MCS14: rateIndex = 26; break;
4527 case MGN_MCS15: rateIndex = 27; break;
4528 default: rateIndex = 28; break;
4530 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
4531 priv->stats.received_rate_histogram[0][rateIndex]++; //total
4532 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
4536 static void query_rxdesc_status(struct sk_buff *skb,
4537 struct ieee80211_rx_stats *stats,
4538 bool bIsRxAggrSubframe)
4540 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4541 struct net_device *dev = info->dev;
4542 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4543 rx_drvinfo_819x_usb *driver_info = NULL;
4546 //Get Rx Descriptor Information
4548 #ifdef USB_RX_AGGREGATION_SUPPORT
4549 if (bIsRxAggrSubframe) {
4550 rx_desc_819x_usb_aggr_subframe *desc = (rx_desc_819x_usb_aggr_subframe *)skb->data;
4551 stats->Length = desc->Length;
4552 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
4553 stats->RxBufShift = 0; //RxBufShift = 2 in RxDesc, but usb didn't shift bytes in fact.
4554 stats->bICV = desc->ICV;
4555 stats->bCRC = desc->CRC32;
4556 stats->bHwError = stats->bCRC|stats->bICV;
4557 stats->Decrypted = !desc->SWDec;//RTL8190 set this bit to indicate that Hw does not decrypt packet
4561 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
4563 stats->Length = desc->Length;
4564 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
4565 stats->RxBufShift = 0;
4566 stats->bICV = desc->ICV;
4567 stats->bCRC = desc->CRC32;
4568 stats->bHwError = stats->bCRC|stats->bICV;
4569 //RTL8190 set this bit to indicate that Hw does not decrypt packet
4570 stats->Decrypted = !desc->SWDec;
4573 if ((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
4574 stats->bHwError = false;
4576 stats->bHwError = stats->bCRC|stats->bICV;
4578 if (stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
4579 stats->bHwError |= 1;
4583 // TODO: Need to verify it on FGPA platform
4584 //Driver info are written to the RxBuffer following rx desc
4585 if (stats->RxDrvInfoSize != 0) {
4586 driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) +
4590 if (!stats->bHwError) {
4592 ret_rate = HwRateToMRate90(driver_info->RxHT, driver_info->RxRate);
4593 if (ret_rate == 0xff) {
4594 // Abnormal Case: Receive CRC OK packet with Rx descriptor indicating non supported rate.
4595 // Special Error Handling here, 2008.05.16, by Emily
4597 stats->bHwError = 1;
4598 stats->rate = MGN_1M; //Set 1M rate by default
4600 stats->rate = ret_rate;
4606 stats->bShortPreamble = driver_info->SPLCP;
4609 UpdateReceivedRateHistogramStatistics8190(dev, stats);
4611 stats->bIsAMPDU = (driver_info->PartAggr == 1);
4612 stats->bFirstMPDU = (driver_info->PartAggr == 1) && (driver_info->FirstAGGR == 1);
4613 stats->TimeStampLow = driver_info->TSFL;
4614 // xiong mask it, 070514
4616 UpdateRxPktTimeStamp8190(dev, stats);
4621 if (driver_info->FirstAGGR == 1 || driver_info->PartAggr == 1)
4622 RT_TRACE(COMP_RXDESC, "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
4623 driver_info->FirstAGGR, driver_info->PartAggr);
4627 skb_pull(skb, sizeof(rx_desc_819x_usb));
4629 // Get Total offset of MPDU Frame Body
4631 if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
4633 skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
4636 #ifdef USB_RX_AGGREGATION_SUPPORT
4637 /* for the rx aggregated sub frame, the redundant space truly contained in the packet */
4638 if (bIsRxAggrSubframe)
4641 /* for debug 2008.5.29 */
4643 //added by vivi, for MP, 20080108
4644 stats->RxIs40MHzPacket = driver_info->BW;
4645 if (stats->RxDrvInfoSize != 0)
4646 TranslateRxSignalStuff819xUsb(skb, stats, driver_info);
4650 u32 GetRxPacketShiftBytes819xUsb(struct ieee80211_rx_stats *Status, bool bIsRxAggrSubframe)
4652 #ifdef USB_RX_AGGREGATION_SUPPORT
4653 if (bIsRxAggrSubframe)
4654 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
4655 + Status->RxBufShift + 8);
4658 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
4659 + Status->RxBufShift);
4662 static void rtl8192_rx_nomal(struct sk_buff *skb)
4664 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4665 struct net_device *dev = info->dev;
4666 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4667 struct ieee80211_rx_stats stats = {
4671 .freq = IEEE80211_24GHZ_BAND,
4674 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
4675 bool unicast_packet = false;
4676 #ifdef USB_RX_AGGREGATION_SUPPORT
4677 struct sk_buff *agg_skb = NULL;
4678 u32 TotalLength = 0;
4680 u32 PacketLength = 0;
4681 u32 PacketOccupiedLendth = 0;
4683 u32 PacketShiftBytes = 0;
4684 rx_desc_819x_usb_aggr_subframe *RxDescr = NULL;
4685 u8 PaddingBytes = 0;
4686 //add just for testing
4691 /* 20 is for ps-poll */
4692 if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
4693 #ifdef USB_RX_AGGREGATION_SUPPORT
4694 TempByte = *(skb->data + sizeof(rx_desc_819x_usb));
4696 /* first packet should not contain Rx aggregation header */
4697 query_rxdesc_status(skb, &stats, false);
4699 /* hardware related info */
4700 #ifdef USB_RX_AGGREGATION_SUPPORT
4701 if (TempByte & BIT0) {
4703 TotalLength = stats.Length - 4; /*sCrcLng*/
4704 /* though the head pointer has passed this position */
4705 TempDWord = *(u32 *)(agg_skb->data - 4);
4706 PacketLength = (u16)(TempDWord & 0x3FFF); /*sCrcLng*/
4707 skb = dev_alloc_skb(PacketLength);
4708 memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
4709 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false);
4712 /* Process the MPDU received */
4713 skb_trim(skb, skb->len - 4/*sCrcLng*/);
4715 rx_pkt_len = skb->len;
4716 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
4717 unicast_packet = false;
4718 if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
4720 } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
4723 /* unicast packet */
4724 unicast_packet = true;
4727 if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
4728 dev_kfree_skb_any(skb);
4730 priv->stats.rxoktotal++;
4732 priv->stats.rxbytesunicast += rx_pkt_len;
4734 #ifdef USB_RX_AGGREGATION_SUPPORT
4736 if (TotalLength > 0) {
4737 PacketOccupiedLendth = PacketLength + (PacketShiftBytes + 8);
4738 if ((PacketOccupiedLendth & 0xFF) != 0)
4739 PacketOccupiedLendth = (PacketOccupiedLendth & 0xFFFFFF00) + 256;
4740 PacketOccupiedLendth -= 8;
4741 TempDWord = PacketOccupiedLendth - PacketShiftBytes; /*- PacketLength */
4742 if (agg_skb->len > TempDWord)
4743 skb_pull(agg_skb, TempDWord);
4747 while (agg_skb->len >= GetRxPacketShiftBytes819xUsb(&stats, true)) {
4748 u8 tmpCRC = 0, tmpICV = 0;
4749 RxDescr = (rx_desc_819x_usb_aggr_subframe *)(agg_skb->data);
4750 tmpCRC = RxDescr->CRC32;
4751 tmpICV = RxDescr->ICV;
4752 memcpy(agg_skb->data, &agg_skb->data[44], 2);
4753 RxDescr->CRC32 = tmpCRC;
4754 RxDescr->ICV = tmpICV;
4756 memset(&stats, 0, sizeof(struct ieee80211_rx_stats));
4760 stats.freq = IEEE80211_24GHZ_BAND;
4761 query_rxdesc_status(agg_skb, &stats, true);
4762 PacketLength = stats.Length;
4764 if (PacketLength > agg_skb->len)
4766 /* Process the MPDU received */
4767 skb = dev_alloc_skb(PacketLength);
4768 memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
4769 skb_trim(skb, skb->len - 4/*sCrcLng*/);
4771 rx_pkt_len = skb->len;
4772 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
4773 unicast_packet = false;
4774 if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
4776 } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
4779 /* unicast packet */
4780 unicast_packet = true;
4782 if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
4783 dev_kfree_skb_any(skb);
4785 priv->stats.rxoktotal++;
4787 priv->stats.rxbytesunicast += rx_pkt_len;
4789 /* should trim the packet which has been copied to target skb */
4790 skb_pull(agg_skb, PacketLength);
4791 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, true);
4792 PacketOccupiedLendth = PacketLength + PacketShiftBytes;
4793 if ((PacketOccupiedLendth & 0xFF) != 0) {
4794 PaddingBytes = 256 - (PacketOccupiedLendth & 0xFF);
4795 if (agg_skb->len > PaddingBytes)
4796 skb_pull(agg_skb, PaddingBytes);
4801 dev_kfree_skb(agg_skb);
4805 priv->stats.rxurberr++;
4806 netdev_dbg(dev, "actual_length: %d\n", skb->len);
4807 dev_kfree_skb_any(skb);
4812 static void rtl819xusb_process_received_packet(struct net_device *dev,
4813 struct ieee80211_rx_stats *pstats)
4817 struct r8192_priv *priv = ieee80211_priv(dev);
4819 // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
4820 //porting by amy 080508
4821 pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
4822 frame = pstats->virtual_address;
4823 frame_len = pstats->packetlength;
4824 #ifdef TODO // by amy about HCT
4825 if (!Adapter->bInHctTest)
4826 CountRxErrStatistics(Adapter, pRfd);
4828 #ifdef ENABLE_PS //by amy for adding ps function in future
4829 RT_RF_POWER_STATE rtState;
4830 // When RF is off, we should not count the packet for hw/sw synchronize
4831 // reason, ie. there may be a duration while sw switch is changed and hw
4832 // switch is being changed. 2006.12.04, by shien chang.
4833 Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8 *)(&rtState));
4834 if (rtState == eRfOff)
4837 priv->stats.rxframgment++;
4840 RmMonitorSignalStrength(Adapter, pRfd);
4842 /* 2007/01/16 MH Add RX command packet handle here. */
4843 /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
4844 if (rtl819xusb_rx_command_packet(dev, pstats))
4854 static void query_rx_cmdpkt_desc_status(struct sk_buff *skb,
4855 struct ieee80211_rx_stats *stats)
4857 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
4860 //Get Rx Descriptor Information
4862 stats->virtual_address = (u8 *)skb->data;
4863 stats->Length = desc->Length;
4864 stats->RxDrvInfoSize = 0;
4865 stats->RxBufShift = 0;
4866 stats->packetlength = stats->Length-scrclng;
4867 stats->fraglength = stats->packetlength;
4868 stats->fragoffset = 0;
4869 stats->ntotalfrag = 1;
4873 static void rtl8192_rx_cmd(struct sk_buff *skb)
4875 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4876 struct net_device *dev = info->dev;
4878 struct ieee80211_rx_stats stats = {
4882 .freq = IEEE80211_24GHZ_BAND,
4885 if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
4887 query_rx_cmdpkt_desc_status(skb, &stats);
4888 // this is to be done by amy 080508 prfd->queue_id = 1;
4892 // Process the command packet received.
4895 rtl819xusb_process_received_packet(dev, &stats);
4897 dev_kfree_skb_any(skb);
4901 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
4903 struct sk_buff *skb;
4904 struct rtl8192_rx_info *info;
4906 while (NULL != (skb = skb_dequeue(&priv->skb_queue))) {
4907 info = (struct rtl8192_rx_info *)skb->cb;
4908 switch (info->out_pipe) {
4909 /* Nomal packet pipe */
4911 priv->IrpPendingCount--;
4912 rtl8192_rx_nomal(skb);
4915 /* Command packet pipe */
4917 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",
4920 rtl8192_rx_cmd(skb);
4923 default: /* should never get here! */
4924 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",
4933 static const struct net_device_ops rtl8192_netdev_ops = {
4934 .ndo_open = rtl8192_open,
4935 .ndo_stop = rtl8192_close,
4936 .ndo_get_stats = rtl8192_stats,
4937 .ndo_tx_timeout = tx_timeout,
4938 .ndo_do_ioctl = rtl8192_ioctl,
4939 .ndo_set_rx_mode = r8192_set_multicast,
4940 .ndo_set_mac_address = r8192_set_mac_adr,
4941 .ndo_validate_addr = eth_validate_addr,
4942 .ndo_change_mtu = eth_change_mtu,
4943 .ndo_start_xmit = ieee80211_xmit,
4947 /****************************************************************************
4948 ---------------------------- USB_STUFF---------------------------
4949 *****************************************************************************/
4951 static int rtl8192_usb_probe(struct usb_interface *intf,
4952 const struct usb_device_id *id)
4954 struct net_device *dev = NULL;
4955 struct r8192_priv *priv = NULL;
4956 struct usb_device *udev = interface_to_usbdev(intf);
4958 RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
4960 dev = alloc_ieee80211(sizeof(struct r8192_priv));
4964 usb_set_intfdata(intf, dev);
4965 SET_NETDEV_DEV(dev, &intf->dev);
4966 priv = ieee80211_priv(dev);
4967 priv->ieee80211 = netdev_priv(dev);
4970 dev->netdev_ops = &rtl8192_netdev_ops;
4972 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
4974 dev->type = ARPHRD_ETHER;
4976 dev->watchdog_timeo = HZ*3; //modified by john, 0805
4978 if (dev_alloc_name(dev, ifname) < 0) {
4979 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
4981 dev_alloc_name(dev, ifname);
4984 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
4985 if (rtl8192_init(dev) != 0) {
4986 RT_TRACE(COMP_ERR, "Initialization failed");
4990 netif_carrier_off(dev);
4991 netif_stop_queue(dev);
4993 ret = register_netdev(dev);
4997 RT_TRACE(COMP_INIT, "dev name=======> %s\n", dev->name);
4998 rtl8192_proc_init_one(dev);
5001 RT_TRACE(COMP_INIT, "Driver probe completed\n");
5006 kfree(priv->pFirmware);
5007 priv->pFirmware = NULL;
5008 rtl8192_usb_deleteendpoints(dev);
5009 destroy_workqueue(priv->priv_wq);
5012 free_ieee80211(dev);
5014 RT_TRACE(COMP_ERR, "wlan driver load failed\n");
5018 //detach all the work and timer structure declared or inititialize in r8192U_init function.
5019 void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
5022 cancel_work_sync(&priv->reset_wq);
5023 cancel_delayed_work(&priv->watch_dog_wq);
5024 cancel_delayed_work(&priv->update_beacon_wq);
5025 cancel_work_sync(&priv->qos_activate);
5029 static void rtl8192_usb_disconnect(struct usb_interface *intf)
5031 struct net_device *dev = usb_get_intfdata(intf);
5033 struct r8192_priv *priv = ieee80211_priv(dev);
5036 unregister_netdev(dev);
5038 RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
5039 rtl8192_proc_remove_one(dev);
5042 kfree(priv->pFirmware);
5043 priv->pFirmware = NULL;
5044 rtl8192_usb_deleteendpoints(dev);
5045 destroy_workqueue(priv->priv_wq);
5049 free_ieee80211(dev);
5050 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
5053 /* fun with the built-in ieee80211 stack... */
5054 extern int ieee80211_debug_init(void);
5055 extern void ieee80211_debug_exit(void);
5056 extern int ieee80211_crypto_init(void);
5057 extern void ieee80211_crypto_deinit(void);
5058 extern int ieee80211_crypto_tkip_init(void);
5059 extern void ieee80211_crypto_tkip_exit(void);
5060 extern int ieee80211_crypto_ccmp_init(void);
5061 extern void ieee80211_crypto_ccmp_exit(void);
5062 extern int ieee80211_crypto_wep_init(void);
5063 extern void ieee80211_crypto_wep_exit(void);
5065 static int __init rtl8192_usb_module_init(void)
5069 #ifdef CONFIG_IEEE80211_DEBUG
5070 ret = ieee80211_debug_init();
5072 pr_err("ieee80211_debug_init() failed %d\n", ret);
5076 ret = ieee80211_crypto_init();
5078 pr_err("ieee80211_crypto_init() failed %d\n", ret);
5082 ret = ieee80211_crypto_tkip_init();
5084 pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
5088 ret = ieee80211_crypto_ccmp_init();
5090 pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
5094 ret = ieee80211_crypto_wep_init();
5096 pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
5100 pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n");
5101 pr_info("Copyright (c) 2007-2008, Realsil Wlan\n");
5102 RT_TRACE(COMP_INIT, "Initializing module");
5103 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
5104 rtl8192_proc_module_init();
5105 return usb_register(&rtl8192_usb_driver);
5109 static void __exit rtl8192_usb_module_exit(void)
5111 usb_deregister(&rtl8192_usb_driver);
5113 RT_TRACE(COMP_DOWN, "Exiting");
5117 void rtl8192_try_wake_queue(struct net_device *dev, int pri)
5119 unsigned long flags;
5121 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5123 spin_lock_irqsave(&priv->tx_lock, flags);
5124 enough_desc = check_nic_enough_desc(dev, pri);
5125 spin_unlock_irqrestore(&priv->tx_lock, flags);
5128 ieee80211_wake_queue(priv->ieee80211);
5131 void EnableHWSecurityConfig8192(struct net_device *dev)
5133 u8 SECR_value = 0x0;
5134 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5135 struct ieee80211_device *ieee = priv->ieee80211;
5136 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
5137 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) {
5138 SECR_value |= SCR_RxUseDK;
5139 SECR_value |= SCR_TxUseDK;
5140 } else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) {
5141 SECR_value |= SCR_RxUseDK;
5142 SECR_value |= SCR_TxUseDK;
5144 //add HWSec active enable here.
5145 //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
5147 ieee->hwsec_active = 1;
5149 if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep) { //add hwsec_support flag to totol control hw_sec on/off
5150 ieee->hwsec_active = 0;
5151 SECR_value &= ~SCR_RxDecEnable;
5153 RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __func__,
5154 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
5155 write_nic_byte(dev, SECR, SECR_value);
5159 void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
5160 u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
5162 u32 TargetCommand = 0;
5163 u32 TargetContent = 0;
5166 if (EntryNo >= TOTAL_CAM_ENTRY)
5167 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
5169 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev, EntryNo, KeyIndex, KeyType, MacAddr);
5172 usConfig |= BIT15 | (KeyType<<2);
5174 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
5177 for (i = 0; i < CAM_CONTENT_COUNT; i++) {
5178 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
5179 TargetCommand |= BIT31|BIT16;
5181 if (i == 0) { //MAC|Config
5182 TargetContent = (u32)(*(MacAddr+0)) << 16|
5183 (u32)(*(MacAddr+1)) << 24|
5186 write_nic_dword(dev, WCAMI, TargetContent);
5187 write_nic_dword(dev, RWCAM, TargetCommand);
5188 } else if (i == 1) { //MAC
5189 TargetContent = (u32)(*(MacAddr+2)) |
5190 (u32)(*(MacAddr+3)) << 8|
5191 (u32)(*(MacAddr+4)) << 16|
5192 (u32)(*(MacAddr+5)) << 24;
5193 write_nic_dword(dev, WCAMI, TargetContent);
5194 write_nic_dword(dev, RWCAM, TargetCommand);
5197 if (KeyContent != NULL) {
5198 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)));
5199 write_nic_dword(dev, RWCAM, TargetCommand);
5206 /***************************************************************************
5207 ------------------- module init / exit stubs ----------------
5208 ****************************************************************************/
5209 module_init(rtl8192_usb_module_init);
5210 module_exit(rtl8192_usb_module_exit);