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 <andreamrl@tiscali.it>, et al.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
23 * Contact Information:
24 * Jerry chuang <wlanfae@realtek.com>
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
100 #ifdef CONFIG_RTL8192_PM
101 #include "r8192_pm.h"
105 //set here to open your trace code. //WB
106 u32 rt_global_debug_component = COMP_DOWN |
108 COMP_ERR; //always open err flags on
110 #define TOTAL_CAM_ENTRY 32
111 #define CAM_CONTENT_COUNT 8
113 static const struct usb_device_id rtl8192_usb_id_tbl[] = {
115 {USB_DEVICE(0x0bda, 0x8709)},
117 {USB_DEVICE(0x07aa, 0x0043)},
119 {USB_DEVICE(0x050d, 0x805E)},
121 {USB_DEVICE(0x0df6, 0x0031)},
123 {USB_DEVICE(0x1740, 0x9201)},
125 {USB_DEVICE(0x2001, 0x3301)},
127 {USB_DEVICE(0x5a57, 0x0290)},
129 {USB_DEVICE(0x043e, 0x7a01)},
133 MODULE_LICENSE("GPL");
134 MODULE_VERSION("V 1.1");
135 MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
136 MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
138 static char *ifname = "wlan%d";
139 static int hwwep = 1; //default use hw. set 0 to use software security
140 static int channels = 0x3fff;
144 module_param(ifname, charp, S_IRUGO|S_IWUSR);
145 module_param(hwwep, int, S_IRUGO|S_IWUSR);
146 module_param(channels, int, S_IRUGO|S_IWUSR);
148 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
149 MODULE_PARM_DESC(hwwep, " Try to use hardware security support. ");
150 MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI");
152 static int rtl8192_usb_probe(struct usb_interface *intf,
153 const struct usb_device_id *id);
154 static void rtl8192_usb_disconnect(struct usb_interface *intf);
157 static struct usb_driver rtl8192_usb_driver = {
158 .name = RTL819xU_MODULE_NAME, /* Driver name */
159 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
160 .probe = rtl8192_usb_probe, /* probe fn */
161 .disconnect = rtl8192_usb_disconnect, /* remove fn */
162 #ifdef CONFIG_RTL8192_PM
163 .suspend = rtl8192_suspend, /* PM suspend fn */
164 .resume = rtl8192_resume, /* PM resume fn */
166 .suspend = NULL, /* PM suspend fn */
167 .resume = NULL, /* PM resume fn */
172 typedef struct _CHANNEL_LIST {
175 } CHANNEL_LIST, *PCHANNEL_LIST;
177 static CHANNEL_LIST ChannelPlan[] = {
178 {{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
179 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
180 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
181 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
182 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
183 {{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
184 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
185 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
186 {{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
187 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
188 {{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
191 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
193 int i, max_chan = -1, min_chan = -1;
194 struct ieee80211_device *ieee = priv->ieee80211;
195 switch (channel_plan) {
196 case COUNTRY_CODE_FCC:
197 case COUNTRY_CODE_IC:
198 case COUNTRY_CODE_ETSI:
199 case COUNTRY_CODE_SPAIN:
200 case COUNTRY_CODE_FRANCE:
201 case COUNTRY_CODE_MKK:
202 case COUNTRY_CODE_MKK1:
203 case COUNTRY_CODE_ISRAEL:
204 case COUNTRY_CODE_TELEC:
205 case COUNTRY_CODE_MIC:
207 ieee->bGlobalDomain = false;
208 //actually 8225 & 8256 rf chips only support B,G,24N mode
209 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
213 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __func__);
215 if (ChannelPlan[channel_plan].Len != 0) {
216 // Clear old channel map
217 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
218 // Set new channel map
219 for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
220 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
222 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
227 case COUNTRY_CODE_GLOBAL_DOMAIN:
228 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
230 ieee->bGlobalDomain = true;
239 #define rx_hal_is_cck_rate(_pdrvinfo)\
240 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
241 _pdrvinfo->RxRate == DESC90_RATE2M ||\
242 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
243 _pdrvinfo->RxRate == DESC90_RATE11M) &&\
247 void CamResetAllEntry(struct net_device *dev)
250 //2004/02/11 In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
251 // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
252 // In this condition, Cam can not be reset because upper layer will not set this static key again.
253 ulcommand |= BIT31|BIT30;
254 write_nic_dword(dev, RWCAM, ulcommand);
259 void write_cam(struct net_device *dev, u8 addr, u32 data)
261 write_nic_dword(dev, WCAMI, data);
262 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff));
265 u32 read_cam(struct net_device *dev, u8 addr)
267 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff));
268 return read_nic_dword(dev, 0xa8);
271 void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
274 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
275 struct usb_device *udev = priv->udev;
277 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
278 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
279 indx|0xfe00, 0, &data, 1, HZ / 2);
282 netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n", status);
285 u8 read_nic_byte_E(struct net_device *dev, int indx)
289 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
290 struct usb_device *udev = priv->udev;
292 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
293 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
294 indx|0xfe00, 0, &data, 1, HZ / 2);
297 netdev_err(dev, "read_nic_byte_E TimeOut! status: %d\n", status);
301 //as 92U has extend page from 4 to 16, so modify functions below.
302 void write_nic_byte(struct net_device *dev, int indx, u8 data)
306 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
307 struct usb_device *udev = priv->udev;
309 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
310 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
311 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
314 netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
320 void write_nic_word(struct net_device *dev, int indx, u16 data)
325 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
326 struct usb_device *udev = priv->udev;
328 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
329 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
330 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
333 netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
338 void write_nic_dword(struct net_device *dev, int indx, u32 data)
343 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
344 struct usb_device *udev = priv->udev;
346 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
347 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
348 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
352 netdev_err(dev, "write_nic_dword TimeOut! status: %d\n", status);
358 u8 read_nic_byte(struct net_device *dev, int indx)
362 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
363 struct usb_device *udev = priv->udev;
365 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
366 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
367 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
370 netdev_err(dev, "read_nic_byte TimeOut! status: %d\n", status);
377 u16 read_nic_word(struct net_device *dev, int indx)
381 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
382 struct usb_device *udev = priv->udev;
384 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
385 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
386 (indx&0xff)|0xff00, (indx>>8)&0x0f,
390 netdev_err(dev, "read_nic_word TimeOut! status: %d\n", status);
395 u16 read_nic_word_E(struct net_device *dev, int indx)
399 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
400 struct usb_device *udev = priv->udev;
402 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
403 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
404 indx|0xfe00, 0, &data, 2, HZ / 2);
407 netdev_err(dev, "read_nic_word TimeOut! status: %d\n", status);
412 u32 read_nic_dword(struct net_device *dev, int indx)
417 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
418 struct usb_device *udev = priv->udev;
420 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
421 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
422 (indx&0xff)|0xff00, (indx>>8)&0x0f,
426 netdev_err(dev, "read_nic_dword TimeOut! status:%d\n", status);
431 /* u8 read_phy_cck(struct net_device *dev, u8 adr); */
432 /* u8 read_phy_ofdm(struct net_device *dev, u8 adr); */
433 /* this might still called in what was the PHY rtl8185/rtl8192 common code
434 * plans are to possibility turn it again in one common code...
436 inline void force_pci_posting(struct net_device *dev)
440 static struct net_device_stats *rtl8192_stats(struct net_device *dev);
441 void rtl8192_commit(struct net_device *dev);
442 void rtl8192_restart(struct work_struct *work);
443 void watch_dog_timer_callback(unsigned long data);
445 /****************************************************************************
446 * -----------------------------PROCFS STUFF-------------------------
447 *****************************************************************************
450 static struct proc_dir_entry *rtl8192_proc;
452 static int proc_get_stats_ap(struct seq_file *m, void *v)
454 struct net_device *dev = m->private;
455 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
456 struct ieee80211_device *ieee = priv->ieee80211;
457 struct ieee80211_network *target;
459 list_for_each_entry(target, &ieee->network_list, list) {
460 const char *wpa = "non_WPA";
461 if (target->wpa_ie_len > 0 || target->rsn_ie_len > 0)
464 seq_printf(m, "%s %s\n", target->ssid, wpa);
470 static int proc_get_registers(struct seq_file *m, void *v)
472 struct net_device *dev = m->private;
473 int i, n, max = 0xff;
475 seq_puts(m, "\n####################page 0##################\n ");
477 for (n = 0; n <= max;) {
478 seq_printf(m, "\nD: %2x > ", n);
480 for (i = 0; i < 16 && n <= max; i++, n++)
481 seq_printf(m, "%2x ", read_nic_byte(dev, 0x000|n));
484 seq_puts(m, "\n####################page 1##################\n ");
485 for (n = 0; n <= max;) {
486 seq_printf(m, "\nD: %2x > ", n);
488 for (i = 0; i < 16 && n <= max; i++, n++)
489 seq_printf(m, "%2x ", read_nic_byte(dev, 0x100|n));
492 seq_puts(m, "\n####################page 3##################\n ");
493 for (n = 0; n <= max;) {
494 seq_printf(m, "\nD: %2x > ", n);
496 for (i = 0; i < 16 && n <= max; i++, n++)
497 seq_printf(m, "%2x ", read_nic_byte(dev, 0x300|n));
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 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 void rtl8192_proc_module_remove(void)
588 remove_proc_entry(RTL819xU_MODULE_NAME, init_net.proc_net);
592 * seq_file wrappers for procfile show routines.
594 static int rtl8192_proc_open(struct inode *inode, struct file *file)
596 struct net_device *dev = proc_get_parent_data(inode);
597 int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
599 return single_open(file, show, dev);
602 static const struct file_operations rtl8192_proc_fops = {
603 .open = rtl8192_proc_open,
606 .release = single_release,
610 * Table of proc files we need to create.
612 struct rtl8192_proc_file {
614 int (*show)(struct seq_file *, void *);
617 static const struct rtl8192_proc_file rtl8192_proc_files[] = {
618 { "stats-rx", &proc_get_stats_rx },
619 { "stats-tx", &proc_get_stats_tx },
620 { "stats-ap", &proc_get_stats_ap },
621 { "registers", &proc_get_registers },
625 void rtl8192_proc_init_one(struct net_device *dev)
627 const struct rtl8192_proc_file *f;
628 struct proc_dir_entry *dir;
631 dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
633 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
638 for (f = rtl8192_proc_files; f->name[0]; f++) {
639 if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
640 &rtl8192_proc_fops, f->show)) {
641 RT_TRACE(COMP_ERR, "Unable to initialize "
642 "/proc/net/rtl8192/%s/%s\n",
650 void rtl8192_proc_remove_one(struct net_device *dev)
652 remove_proc_subtree(dev->name, rtl8192_proc);
655 /****************************************************************************
656 -----------------------------MISC STUFF-------------------------
657 *****************************************************************************/
659 short check_nic_enough_desc(struct net_device *dev, int queue_index)
661 struct r8192_priv *priv = ieee80211_priv(dev);
662 int used = atomic_read(&priv->tx_pending[queue_index]);
664 return (used < MAX_TX_URB);
667 void tx_timeout(struct net_device *dev)
669 struct r8192_priv *priv = ieee80211_priv(dev);
671 schedule_work(&priv->reset_wq);
675 /* this is only for debug */
676 void dump_eprom(struct net_device *dev)
679 for (i = 0; i < 63; i++)
680 RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev, i));
684 /****************************************************************************
685 ------------------------------HW STUFF---------------------------
686 *****************************************************************************/
689 void rtl8192_set_mode(struct net_device *dev, int mode)
692 ecmd = read_nic_byte(dev, EPROM_CMD);
693 ecmd = ecmd & ~EPROM_CMD_OPERATING_MODE_MASK;
694 ecmd = ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
695 ecmd = ecmd & ~(1<<EPROM_CS_SHIFT);
696 ecmd = ecmd & ~(1<<EPROM_CK_SHIFT);
697 write_nic_byte(dev, EPROM_CMD, ecmd);
701 void rtl8192_update_msr(struct net_device *dev)
703 struct r8192_priv *priv = ieee80211_priv(dev);
706 msr = read_nic_byte(dev, MSR);
707 msr &= ~MSR_LINK_MASK;
709 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
710 * msr must be updated if the state is ASSOCIATING.
711 * this is intentional and make sense for ad-hoc and
712 * master (see the create BSS/IBSS func)
714 if (priv->ieee80211->state == IEEE80211_LINKED) {
716 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
717 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
718 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
719 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
720 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
721 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
724 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
727 write_nic_byte(dev, MSR, msr);
730 void rtl8192_set_chan(struct net_device *dev, short ch)
732 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
733 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
736 /* this hack should avoid frame TX during channel setting*/
739 //need to implement rf set channel here WB
741 if (priv->rf_set_chan)
742 priv->rf_set_chan(dev, priv->chan);
747 static void rtl8192_rx_isr(struct urb *urb);
749 u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
752 #ifdef USB_RX_AGGREGATION_SUPPORT
753 if (pstats->bisrxaggrsubframe)
754 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
755 + pstats->RxBufShift + 8);
758 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
759 + pstats->RxBufShift);
762 static int rtl8192_rx_initiate(struct net_device *dev)
764 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
767 struct rtl8192_rx_info *info;
769 /* nomal packet rx procedure */
770 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB) {
771 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
774 entry = usb_alloc_urb(0, GFP_KERNEL);
779 usb_fill_bulk_urb(entry, priv->udev,
780 usb_rcvbulkpipe(priv->udev, 3), skb_tail_pointer(skb),
781 RX_URB_SIZE, rtl8192_rx_isr, skb);
782 info = (struct rtl8192_rx_info *) skb->cb;
785 info->out_pipe = 3; //denote rx normal packet queue
786 skb_queue_tail(&priv->rx_queue, skb);
787 usb_submit_urb(entry, GFP_KERNEL);
790 /* command packet rx procedure */
791 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
792 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
795 entry = usb_alloc_urb(0, GFP_KERNEL);
800 usb_fill_bulk_urb(entry, priv->udev,
801 usb_rcvbulkpipe(priv->udev, 9), skb_tail_pointer(skb),
802 RX_URB_SIZE, rtl8192_rx_isr, skb);
803 info = (struct rtl8192_rx_info *) skb->cb;
806 info->out_pipe = 9; //denote rx cmd packet queue
807 skb_queue_tail(&priv->rx_queue, skb);
808 usb_submit_urb(entry, GFP_KERNEL);
814 void rtl8192_set_rxconf(struct net_device *dev)
816 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
819 rxconf = read_nic_dword(dev, RCR);
820 rxconf = rxconf & ~MAC_FILTER_MASK;
821 rxconf = rxconf | RCR_AMF;
822 rxconf = rxconf | RCR_ADF;
823 rxconf = rxconf | RCR_AB;
824 rxconf = rxconf | RCR_AM;
826 if (dev->flags & IFF_PROMISC)
827 DMESG("NIC in promisc mode");
829 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR ||
830 dev->flags & IFF_PROMISC) {
831 rxconf = rxconf | RCR_AAP;
833 rxconf = rxconf | RCR_APM;
834 rxconf = rxconf | RCR_CBSSID;
838 if (priv->ieee80211->iw_mode == IW_MODE_MONITOR) {
839 rxconf = rxconf | RCR_AICV;
840 rxconf = rxconf | RCR_APWRMGT;
843 if (priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
844 rxconf = rxconf | RCR_ACRC32;
847 rxconf = rxconf & ~RX_FIFO_THRESHOLD_MASK;
848 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
849 rxconf = rxconf & ~MAX_RX_DMA_MASK;
850 rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
852 rxconf = rxconf | RCR_ONLYERLPKT;
854 write_nic_dword(dev, RCR, rxconf);
857 DMESG("rxconf: %x %x", rxconf, read_nic_dword(dev, RCR));
861 void rtl8192_rx_enable(struct net_device *dev)
863 rtl8192_rx_initiate(dev);
867 void rtl8192_tx_enable(struct net_device *dev)
873 void rtl8192_rtx_disable(struct net_device *dev)
876 struct r8192_priv *priv = ieee80211_priv(dev);
878 struct rtl8192_rx_info *info;
880 cmd = read_nic_byte(dev, CMDR);
881 write_nic_byte(dev, CMDR, cmd & ~(CR_TE|CR_RE));
882 force_pci_posting(dev);
885 while ((skb = __skb_dequeue(&priv->rx_queue))) {
886 info = (struct rtl8192_rx_info *) skb->cb;
890 usb_kill_urb(info->urb);
894 if (skb_queue_len(&priv->skb_queue))
895 netdev_warn(dev, "skb_queue not empty\n");
897 skb_queue_purge(&priv->skb_queue);
902 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
907 inline u16 ieeerate2rtlrate(int rate)
939 static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
940 inline u16 rtl8192_rate2rate(short rate)
942 if (rate > 11) return 0;
943 return rtl_rate[rate];
947 /* The prototype of rx_isr has changed since one version of Linux Kernel */
948 static void rtl8192_rx_isr(struct urb *urb)
950 struct sk_buff *skb = (struct sk_buff *) urb->context;
951 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
952 struct net_device *dev = info->dev;
953 struct r8192_priv *priv = ieee80211_priv(dev);
954 int out_pipe = info->out_pipe;
958 if (unlikely(urb->status)) {
960 priv->stats.rxstaterr++;
961 priv->ieee80211->stats.rx_errors++;
965 skb_unlink(skb, &priv->rx_queue);
966 skb_put(skb, urb->actual_length);
968 skb_queue_tail(&priv->skb_queue, skb);
969 tasklet_schedule(&priv->irq_rx_tasklet);
971 skb = dev_alloc_skb(RX_URB_SIZE);
972 if (unlikely(!skb)) {
974 netdev_err(dev, "%s(): can't alloc skb\n", __func__);
975 /* TODO check rx queue length and refill *somewhere* */
979 usb_fill_bulk_urb(urb, priv->udev,
980 usb_rcvbulkpipe(priv->udev, out_pipe), skb_tail_pointer(skb),
981 RX_URB_SIZE, rtl8192_rx_isr, skb);
983 info = (struct rtl8192_rx_info *) skb->cb;
986 info->out_pipe = out_pipe;
988 urb->transfer_buffer = skb_tail_pointer(skb);
990 skb_queue_tail(&priv->rx_queue, skb);
991 err = usb_submit_urb(urb, GFP_ATOMIC);
992 if (err && err != EPERM)
993 netdev_err(dev, "can not submit rxurb, err is %x, URB status is %x\n", err, urb->status);
996 u32 rtl819xusb_rx_command_packet(struct net_device *dev,
997 struct ieee80211_rx_stats *pstats)
1001 status = cmpk_message_handle_rx(dev, pstats);
1003 DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
1009 void rtl8192_data_hard_stop(struct net_device *dev)
1015 void rtl8192_data_hard_resume(struct net_device *dev)
1020 /* this function TX data frames when the ieee80211 stack requires this.
1021 * It checks also if we need to stop the ieee tx queue, eventually do it
1023 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1025 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1027 unsigned long flags;
1028 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1029 u8 queue_index = tcb_desc->queue_index;
1031 /* shall not be referred by command packet */
1032 assert(queue_index != TXCMD_QUEUE);
1034 spin_lock_irqsave(&priv->tx_lock, flags);
1036 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1037 tcb_desc->bTxEnableFwCalcDur = 1;
1038 skb_push(skb, priv->ieee80211->tx_headroom);
1039 ret = rtl8192_tx(dev, skb);
1041 spin_unlock_irqrestore(&priv->tx_lock, flags);
1046 /* This is a rough attempt to TX a frame
1047 * This is called by the ieee 80211 stack to TX management frames.
1048 * If the ring is full packet are dropped (for data frame the queue
1049 * is stopped before this can happen).
1051 int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1053 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1055 unsigned long flags;
1056 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1057 u8 queue_index = tcb_desc->queue_index;
1060 spin_lock_irqsave(&priv->tx_lock, flags);
1062 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
1063 if (queue_index == TXCMD_QUEUE) {
1064 skb_push(skb, USB_HWDESC_HEADER_LEN);
1065 rtl819xU_tx_cmd(dev, skb);
1067 spin_unlock_irqrestore(&priv->tx_lock, flags);
1070 skb_push(skb, priv->ieee80211->tx_headroom);
1071 ret = rtl8192_tx(dev, skb);
1074 spin_unlock_irqrestore(&priv->tx_lock, flags);
1080 void rtl8192_try_wake_queue(struct net_device *dev, int pri);
1082 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1083 u16 DrvAggr_PaddingAdd(struct net_device *dev, struct sk_buff *skb)
1085 u16 PaddingNum = 256 - ((skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES) % 256);
1086 return PaddingNum & 0xff;
1089 u8 MRateToHwRate8190Pci(u8 rate);
1090 u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc);
1091 u8 MapHwQueueToFirmwareQueue(u8 QueueID);
1092 struct sk_buff *DrvAggr_Aggregation(struct net_device *dev, struct ieee80211_drv_agg_txb *pSendList)
1094 struct ieee80211_device *ieee = netdev_priv(dev);
1095 struct r8192_priv *priv = ieee80211_priv(dev);
1096 cb_desc *tcb_desc = NULL;
1099 struct sk_buff *skb;
1100 struct sk_buff *agg_skb;
1101 tx_desc_819x_usb_aggr_subframe *tx_agg_desc = NULL;
1102 tx_fwinfo_819x_usb *tx_fwinfo = NULL;
1105 // Local variable initialization.
1107 /* first skb initialization */
1108 skb = pSendList->tx_agg_frames[0];
1109 TotalLength = skb->len;
1111 /* Get the total aggregation length including the padding space and
1114 for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1115 TotalLength += DrvAggr_PaddingAdd(dev, skb);
1116 skb = pSendList->tx_agg_frames[i];
1117 TotalLength += (skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1120 /* allocate skb to contain the aggregated packets */
1121 agg_skb = dev_alloc_skb(TotalLength + ieee->tx_headroom);
1122 memset(agg_skb->data, 0, agg_skb->len);
1123 skb_reserve(agg_skb, ieee->tx_headroom);
1125 /* reserve info for first subframe Tx descriptor to be set in the tx function */
1126 skb = pSendList->tx_agg_frames[0];
1127 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1128 tcb_desc->drv_agg_enable = 1;
1129 tcb_desc->pkt_size = skb->len;
1130 tcb_desc->DrvAggrNum = pSendList->nr_drv_agg_frames;
1131 netdev_dbg(dev, "DrvAggNum = %d\n", tcb_desc->DrvAggrNum);
1132 memcpy(agg_skb->cb, skb->cb, sizeof(skb->cb));
1133 memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
1135 for (i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1136 /* push the next sub frame to be 256 byte aline */
1137 skb_put(agg_skb, DrvAggr_PaddingAdd(dev, skb));
1139 /* Subframe drv Tx descriptor and firmware info setting */
1140 skb = pSendList->tx_agg_frames[i];
1141 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1142 tx_agg_desc = (tx_desc_819x_usb_aggr_subframe *)agg_skb->tail;
1143 tx_fwinfo = (tx_fwinfo_819x_usb *)(agg_skb->tail + sizeof(tx_desc_819x_usb_aggr_subframe));
1145 memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
1147 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
1148 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
1149 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1150 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
1151 if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
1152 tx_fwinfo->AllowAggregation = 1;
1154 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
1155 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
1157 tx_fwinfo->AllowAggregation = 0;
1159 tx_fwinfo->RxMF = 0;
1160 tx_fwinfo->RxAMD = 0;
1163 /* Protection mode related */
1164 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
1165 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
1166 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
1167 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
1168 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1169 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
1170 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
1171 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
1172 (tcb_desc->bRTSUseShortGI ? 1 : 0);
1174 /* Set Bandwidth and sub-channel settings. */
1175 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
1176 if (tcb_desc->bPacketBW) {
1177 tx_fwinfo->TxBandwidth = 1;
1178 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
1180 tx_fwinfo->TxBandwidth = 0;
1181 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1184 tx_fwinfo->TxBandwidth = 0;
1185 tx_fwinfo->TxSubCarrier = 0;
1188 /* Fill Tx descriptor */
1189 memset(tx_agg_desc, 0, sizeof(tx_desc_819x_usb_aggr_subframe));
1191 tx_agg_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
1192 /* already raw data, need not to subtract header length */
1193 tx_agg_desc->PktSize = skb->len & 0xffff;
1196 tx_agg_desc->SecCAMID = 0;
1197 tx_agg_desc->RATid = tcb_desc->RATRIndex;
1198 tx_agg_desc->NoEnc = 1;
1199 tx_agg_desc->SecType = 0x0;
1201 if (tcb_desc->bHwSec) {
1202 switch (priv->ieee80211->pairwise_key_type) {
1203 case KEY_TYPE_WEP40:
1204 case KEY_TYPE_WEP104:
1205 tx_agg_desc->SecType = 0x1;
1206 tx_agg_desc->NoEnc = 0;
1209 tx_agg_desc->SecType = 0x2;
1210 tx_agg_desc->NoEnc = 0;
1213 tx_agg_desc->SecType = 0x3;
1214 tx_agg_desc->NoEnc = 0;
1217 tx_agg_desc->SecType = 0x0;
1218 tx_agg_desc->NoEnc = 1;
1223 tx_agg_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1224 tx_agg_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
1226 tx_agg_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
1227 tx_agg_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1229 tx_agg_desc->OWN = 1;
1232 /* According windows driver, it seems that there no need to fill this field */
1234 /* to fill next packet */
1235 skb_put(agg_skb, TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1236 memcpy(skb_put(agg_skb, skb->len), skb->data, skb->len);
1239 for (i = 0; i < pSendList->nr_drv_agg_frames; i++)
1240 dev_kfree_skb_any(pSendList->tx_agg_frames[i]);
1246 This function return a list of PTCB which is proper to be aggregate with the input TCB.
1247 If no proper TCB is found to do aggregation, SendList will only contain the input TCB.
1249 u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb,
1250 struct ieee80211_drv_agg_txb *pSendList)
1252 struct ieee80211_device *ieee = netdev_priv(dev);
1253 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1254 u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum;
1255 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1256 u8 QueueID = tcb_desc->queue_index;
1259 pSendList->tx_agg_frames[pSendList->nr_drv_agg_frames++] = skb;
1260 if (pSendList->nr_drv_agg_frames >= nMaxAggrNum)
1263 } while ((skb = skb_dequeue(&ieee->skb_drv_aggQ[QueueID])));
1265 RT_TRACE(COMP_AMSDU, "DrvAggr_GetAggregatibleList, nAggrTcbNum = %d \n", pSendList->nr_drv_agg_frames);
1266 return pSendList->nr_drv_agg_frames;
1270 static void rtl8192_tx_isr(struct urb *tx_urb)
1272 struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
1273 struct net_device *dev = NULL;
1274 struct r8192_priv *priv = NULL;
1275 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1276 u8 queue_index = tcb_desc->queue_index;
1278 memcpy(&dev, (struct net_device *)(skb->cb), sizeof(struct net_device *));
1279 priv = ieee80211_priv(dev);
1281 if (tcb_desc->queue_index != TXCMD_QUEUE) {
1282 if (tx_urb->status == 0) {
1283 dev->trans_start = jiffies;
1284 priv->stats.txoktotal++;
1285 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
1286 priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
1288 priv->ieee80211->stats.tx_errors++;
1293 /* free skb and tx_urb */
1295 dev_kfree_skb_any(skb);
1296 usb_free_urb(tx_urb);
1297 atomic_dec(&priv->tx_pending[queue_index]);
1301 // Handle HW Beacon:
1302 // We had transfer our beacon frame to host controller at this moment.
1306 // Handling the wait queue of command packets.
1307 // For Tx command packets, we must not do TCB fragment because it is not handled right now.
1308 // We must cut the packets to match the size of TX_CMD_PKT before we send it.
1311 /* Handle MPDU in wait queue. */
1312 if (queue_index != BEACON_QUEUE) {
1313 /* Don't send data frame during scanning.*/
1314 if ((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0) &&
1315 (!(priv->ieee80211->queue_stop))) {
1316 if (NULL != (skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]))))
1317 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
1319 return; //modified by david to avoid further processing AMSDU
1321 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1322 else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index]) != 0) &&
1323 (!(priv->ieee80211->queue_stop))) {
1324 // Tx Driver Aggregation process
1325 /* The driver will aggregation the packets according to the following stats
1326 * 1. check whether there's tx irq available, for it's a completion return
1327 * function, it should contain enough tx irq;
1328 * 2. check packet type;
1329 * 3. initialize sendlist, check whether the to-be send packet no greater than 1
1330 * 4. aggregates the packets, and fill firmware info and tx desc into it, etc.
1331 * 5. check whether the packet could be sent, otherwise just insert into wait head
1333 skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
1334 if (!check_nic_enough_desc(dev, queue_index)) {
1335 skb_queue_head(&(priv->ieee80211->skb_drv_aggQ[queue_index]), skb);
1341 struct ieee80211_drv_agg_txb SendList;
1343 memset(&SendList, 0, sizeof(struct ieee80211_drv_agg_txb));
1344 if (DrvAggr_GetAggregatibleList(dev, skb, &SendList) > 1) {
1345 skb = DrvAggr_Aggregation(dev, &SendList);
1349 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
1356 void rtl8192_beacon_stop(struct net_device *dev)
1359 struct r8192_priv *priv = ieee80211_priv(dev);
1361 msr = read_nic_byte(dev, MSR);
1362 msrm = msr & MSR_LINK_MASK;
1363 msr2 = msr & ~MSR_LINK_MASK;
1365 if (NIC_8192U == priv->card_8192)
1366 usb_kill_urb(priv->rx_urb[MAX_RX_URB]);
1367 if ((msrm == (MSR_LINK_ADHOC<<MSR_LINK_SHIFT) ||
1368 (msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))) {
1369 write_nic_byte(dev, MSR, msr2 | MSR_LINK_NONE);
1370 write_nic_byte(dev, MSR, msr);
1374 void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
1376 struct r8192_priv *priv = ieee80211_priv(dev);
1377 struct ieee80211_network *net;
1378 u8 i = 0, basic_rate = 0;
1379 net = & priv->ieee80211->current_network;
1381 for (i = 0; i < net->rates_len; i++) {
1382 basic_rate = net->rates[i]&0x7f;
1383 switch (basic_rate) {
1384 case MGN_1M: *rate_config |= RRSR_1M; break;
1385 case MGN_2M: *rate_config |= RRSR_2M; break;
1386 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1387 case MGN_11M: *rate_config |= RRSR_11M; break;
1388 case MGN_6M: *rate_config |= RRSR_6M; break;
1389 case MGN_9M: *rate_config |= RRSR_9M; break;
1390 case MGN_12M: *rate_config |= RRSR_12M; break;
1391 case MGN_18M: *rate_config |= RRSR_18M; break;
1392 case MGN_24M: *rate_config |= RRSR_24M; break;
1393 case MGN_36M: *rate_config |= RRSR_36M; break;
1394 case MGN_48M: *rate_config |= RRSR_48M; break;
1395 case MGN_54M: *rate_config |= RRSR_54M; break;
1398 for (i = 0; i < net->rates_ex_len; i++) {
1399 basic_rate = net->rates_ex[i]&0x7f;
1400 switch (basic_rate) {
1401 case MGN_1M: *rate_config |= RRSR_1M; break;
1402 case MGN_2M: *rate_config |= RRSR_2M; break;
1403 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1404 case MGN_11M: *rate_config |= RRSR_11M; break;
1405 case MGN_6M: *rate_config |= RRSR_6M; break;
1406 case MGN_9M: *rate_config |= RRSR_9M; break;
1407 case MGN_12M: *rate_config |= RRSR_12M; break;
1408 case MGN_18M: *rate_config |= RRSR_18M; break;
1409 case MGN_24M: *rate_config |= RRSR_24M; break;
1410 case MGN_36M: *rate_config |= RRSR_36M; break;
1411 case MGN_48M: *rate_config |= RRSR_48M; break;
1412 case MGN_54M: *rate_config |= RRSR_54M; break;
1418 #define SHORT_SLOT_TIME 9
1419 #define NON_SHORT_SLOT_TIME 20
1421 void rtl8192_update_cap(struct net_device *dev, u16 cap)
1424 struct r8192_priv *priv = ieee80211_priv(dev);
1425 struct ieee80211_network *net = &priv->ieee80211->current_network;
1426 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1427 tmp = priv->basic_rate;
1428 if (priv->short_preamble)
1429 tmp |= BRSR_AckShortPmb;
1430 write_nic_dword(dev, RRSR, tmp);
1432 if (net->mode & (IEEE_G|IEEE_N_24G)) {
1434 if ((cap & WLAN_CAPABILITY_SHORT_SLOT) && (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) //short slot time
1435 slot_time = SHORT_SLOT_TIME;
1436 else //long slot time
1437 slot_time = NON_SHORT_SLOT_TIME;
1438 priv->slot_time = slot_time;
1439 write_nic_byte(dev, SLOT_TIME, slot_time);
1443 void rtl8192_net_update(struct net_device *dev)
1446 struct r8192_priv *priv = ieee80211_priv(dev);
1447 struct ieee80211_network *net;
1448 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1449 u16 rate_config = 0;
1450 net = & priv->ieee80211->current_network;
1452 rtl8192_config_rate(dev, &rate_config);
1453 priv->basic_rate = rate_config &= 0x15f;
1455 write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
1456 write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
1458 rtl8192_update_msr(dev);
1459 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
1460 write_nic_word(dev, ATIMWND, 2);
1461 write_nic_word(dev, BCN_DMATIME, 1023);
1462 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1463 write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
1464 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1465 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1466 // TODO: BcnIFS may required to be changed on ASIC
1467 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1469 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1476 //temporary hw beacon is not used any more.
1477 //open it when necessary
1478 void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate)
1482 inline u8 rtl8192_IsWirelessBMode(u16 rate)
1484 if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
1489 u16 N_DBPSOfRate(u16 DataRate);
1491 u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
1498 if (rtl8192_IsWirelessBMode(DataRate)) {
1499 if (bManagementFrame || !bShortPreamble || DataRate == 10) // long preamble
1500 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1501 else // Short preamble
1502 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1503 if ((FrameLength*8 % (DataRate/10)) != 0) //Get the Ceilling
1505 } else { //802.11g DSSS-OFDM PLCP length field calculation.
1506 N_DBPS = N_DBPSOfRate(DataRate);
1507 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1508 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1509 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1514 u16 N_DBPSOfRate(u16 DataRate)
1558 void rtl819xU_cmd_isr(struct urb *tx_cmd_urb, struct pt_regs *regs)
1560 usb_free_urb(tx_cmd_urb);
1563 unsigned int txqueue2outpipe(struct r8192_priv *priv, unsigned int tx_queue)
1565 if (tx_queue >= 9) {
1566 RT_TRACE(COMP_ERR, "%s():Unknown queue ID!!!\n", __func__);
1569 return priv->txqueue_to_outpipemap[tx_queue];
1572 short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1574 struct r8192_priv *priv = ieee80211_priv(dev);
1577 unsigned int idx_pipe;
1578 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
1579 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1580 u8 queue_index = tcb_desc->queue_index;
1582 atomic_inc(&priv->tx_pending[queue_index]);
1583 tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
1589 memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
1590 /* Tx descriptor ought to be set according to the skb->cb */
1591 pdesc->FirstSeg = 1;//bFirstSeg;
1592 pdesc->LastSeg = 1;//bLastSeg;
1593 pdesc->CmdInit = tcb_desc->bCmdOrInit;
1594 pdesc->TxBufferSize = tcb_desc->txbuf_size;
1596 pdesc->LINIP = tcb_desc->bLastIniPkt;
1598 //----------------------------------------------------------------------------
1599 // Fill up USB_OUT_CONTEXT.
1600 //----------------------------------------------------------------------------
1601 // Get index to out pipe from specified QueueID.
1602 #ifndef USE_ONE_PIPE
1603 idx_pipe = txqueue2outpipe(priv, queue_index);
1607 #ifdef JOHN_DUMP_TXDESC
1609 printk("<Tx descriptor>--rate %x---", rate);
1610 for (i = 0; i < 8; i++)
1611 printk("%8x ", tx[i]);
1614 usb_fill_bulk_urb(tx_urb, priv->udev, usb_sndbulkpipe(priv->udev, idx_pipe),
1615 skb->data, skb->len, rtl8192_tx_isr, skb);
1617 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
1622 DMESGE("Error TX CMD URB, error %d", status);
1628 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1629 * in TxFwInfo data structure
1630 * 2006.10.30 by Emily
1632 * \param QUEUEID Software Queue
1634 u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1636 u8 QueueSelect = 0x0; //defualt set to
1640 QueueSelect = QSLT_BE;
1644 QueueSelect = QSLT_BK;
1648 QueueSelect = QSLT_VO;
1652 QueueSelect = QSLT_VI;
1655 QueueSelect = QSLT_MGNT;
1659 QueueSelect = QSLT_BEACON;
1662 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
1663 // TODO: Remove Assertions
1665 QueueSelect = QSLT_CMD;
1668 QueueSelect = QSLT_HIGH;
1672 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
1678 u8 MRateToHwRate8190Pci(u8 rate)
1680 u8 ret = DESC90_RATE1M;
1683 case MGN_1M: ret = DESC90_RATE1M; break;
1684 case MGN_2M: ret = DESC90_RATE2M; break;
1685 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1686 case MGN_11M: ret = DESC90_RATE11M; break;
1687 case MGN_6M: ret = DESC90_RATE6M; break;
1688 case MGN_9M: ret = DESC90_RATE9M; break;
1689 case MGN_12M: ret = DESC90_RATE12M; break;
1690 case MGN_18M: ret = DESC90_RATE18M; break;
1691 case MGN_24M: ret = DESC90_RATE24M; break;
1692 case MGN_36M: ret = DESC90_RATE36M; break;
1693 case MGN_48M: ret = DESC90_RATE48M; break;
1694 case MGN_54M: ret = DESC90_RATE54M; break;
1696 // HT rate since here
1697 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1698 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1699 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1700 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1701 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1702 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1703 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1704 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1705 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1706 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1707 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1708 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1709 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1710 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1711 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1712 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1713 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1721 u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
1725 tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) : ((tcb_desc->bUseShortPreamble) ? 1 : 0);
1727 if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
1733 static void tx_zero_isr(struct urb *tx_urb)
1739 * The tx procedure is just as following,
1740 * skb->cb will contain all the following information,
1741 * priority, morefrag, rate, &dev.
1743 short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1745 struct r8192_priv *priv = ieee80211_priv(dev);
1746 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1747 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
1748 tx_fwinfo_819x_usb *tx_fwinfo = (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
1749 struct usb_device *udev = priv->udev;
1752 struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
1753 unsigned int idx_pipe;
1754 pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
1755 /* we are locked here so the two atomic_read and inc are executed
1756 * without interleaves
1757 * !!! For debug purpose
1759 if (pend > MAX_TX_URB) {
1760 netdev_dbg(dev, "To discard skb packet!\n");
1761 dev_kfree_skb_any(skb);
1765 tx_urb = usb_alloc_urb(0, GFP_ATOMIC);
1767 dev_kfree_skb_any(skb);
1771 /* Fill Tx firmware info */
1772 memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
1774 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
1775 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
1776 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1777 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
1778 if (tcb_desc->bAMPDUEnable) {//AMPDU enabled
1779 tx_fwinfo->AllowAggregation = 1;
1781 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
1782 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
1784 tx_fwinfo->AllowAggregation = 0;
1786 tx_fwinfo->RxMF = 0;
1787 tx_fwinfo->RxAMD = 0;
1790 /* Protection mode related */
1791 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
1792 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
1793 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
1794 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
1795 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1796 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
1797 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
1798 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
1799 (tcb_desc->bRTSUseShortGI ? 1 : 0);
1801 /* Set Bandwidth and sub-channel settings. */
1802 if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
1803 if (tcb_desc->bPacketBW) {
1804 tx_fwinfo->TxBandwidth = 1;
1805 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
1807 tx_fwinfo->TxBandwidth = 0;
1808 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1811 tx_fwinfo->TxBandwidth = 0;
1812 tx_fwinfo->TxSubCarrier = 0;
1815 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1816 if (tcb_desc->drv_agg_enable)
1817 tx_fwinfo->Tx_INFO_RSVD = (tcb_desc->DrvAggrNum & 0x1f) << 1;
1819 /* Fill Tx descriptor */
1820 memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
1823 tx_desc->CmdInit = 1;
1824 tx_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
1826 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1827 if (tcb_desc->drv_agg_enable)
1828 tx_desc->PktSize = tcb_desc->pkt_size;
1832 tx_desc->PktSize = (skb->len - TX_PACKET_SHIFT_BYTES) & 0xffff;
1836 tx_desc->SecCAMID = 0;
1837 tx_desc->RATid = tcb_desc->RATRIndex;
1839 tx_desc->SecType = 0x0;
1840 if (tcb_desc->bHwSec) {
1841 switch (priv->ieee80211->pairwise_key_type) {
1842 case KEY_TYPE_WEP40:
1843 case KEY_TYPE_WEP104:
1844 tx_desc->SecType = 0x1;
1848 tx_desc->SecType = 0x2;
1852 tx_desc->SecType = 0x3;
1856 tx_desc->SecType = 0x0;
1862 tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1863 tx_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
1865 tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
1866 tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1868 /* Fill fields that are required to be initialized in all of the descriptors */
1870 tx_desc->FirstSeg = 1;
1871 tx_desc->LastSeg = 1;
1874 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1875 if (tcb_desc->drv_agg_enable) {
1876 tx_desc->TxBufferSize = tcb_desc->pkt_size + sizeof(tx_fwinfo_819x_usb);
1881 tx_desc->TxBufferSize = (u32)(skb->len - USB_HWDESC_HEADER_LEN);
1883 /* Get index to out pipe from specified QueueID */
1884 #ifndef USE_ONE_PIPE
1885 idx_pipe = txqueue2outpipe(priv, tcb_desc->queue_index);
1890 /* To submit bulk urb */
1891 usb_fill_bulk_urb(tx_urb, udev,
1892 usb_sndbulkpipe(udev, idx_pipe), skb->data,
1893 skb->len, rtl8192_tx_isr, skb);
1895 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
1897 //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
1898 bool bSend0Byte = false;
1900 if (udev->speed == USB_SPEED_HIGH) {
1901 if (skb->len > 0 && skb->len % 512 == 0)
1904 if (skb->len > 0 && skb->len % 64 == 0)
1908 tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC);
1910 RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
1913 usb_fill_bulk_urb(tx_urb_zero, udev,
1914 usb_sndbulkpipe(udev, idx_pipe), &zero,
1915 0, tx_zero_isr, dev);
1916 status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
1918 RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
1922 dev->trans_start = jiffies;
1923 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
1926 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
1932 short rtl8192_usb_initendpoints(struct net_device *dev)
1934 struct r8192_priv *priv = ieee80211_priv(dev);
1936 priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1),
1938 if (priv->rx_urb == NULL)
1941 #ifndef JACKSON_NEW_RX
1942 for (i = 0; i < (MAX_RX_URB+1); i++) {
1944 priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
1946 priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
1948 priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
1952 #ifdef THOMAS_BEACON
1955 void *oldaddr, *newaddr;
1957 priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
1958 priv->oldaddr = kmalloc(16, GFP_KERNEL);
1959 oldaddr = priv->oldaddr;
1960 align = ((long)oldaddr) & 3;
1962 newaddr = oldaddr + 4 - align;
1963 priv->rx_urb[16]->transfer_buffer_length = 16 - 4 + align;
1966 priv->rx_urb[16]->transfer_buffer_length = 16;
1968 priv->rx_urb[16]->transfer_buffer = newaddr;
1972 memset(priv->rx_urb, 0, sizeof(struct urb *) * MAX_RX_URB);
1973 priv->pp_rxskb = kcalloc(MAX_RX_URB, sizeof(struct sk_buff *),
1975 if (!priv->pp_rxskb) {
1976 kfree(priv->rx_urb);
1978 priv->pp_rxskb = NULL;
1979 priv->rx_urb = NULL;
1981 DMESGE("Endpoint Alloc Failure");
1985 netdev_dbg(dev, "End of initendpoints\n");
1989 #ifdef THOMAS_BEACON
1990 void rtl8192_usb_deleteendpoints(struct net_device *dev)
1993 struct r8192_priv *priv = ieee80211_priv(dev);
1996 for (i = 0; i < (MAX_RX_URB+1); i++) {
1997 usb_kill_urb(priv->rx_urb[i]);
1998 usb_free_urb(priv->rx_urb[i]);
2000 kfree(priv->rx_urb);
2001 priv->rx_urb = NULL;
2003 kfree(priv->oldaddr);
2004 priv->oldaddr = NULL;
2005 if (priv->pp_rxskb) {
2006 kfree(priv->pp_rxskb);
2011 void rtl8192_usb_deleteendpoints(struct net_device *dev)
2014 struct r8192_priv *priv = ieee80211_priv(dev);
2016 #ifndef JACKSON_NEW_RX
2019 for (i = 0; i < (MAX_RX_URB+1); i++) {
2020 usb_kill_urb(priv->rx_urb[i]);
2021 kfree(priv->rx_urb[i]->transfer_buffer);
2022 usb_free_urb(priv->rx_urb[i]);
2024 kfree(priv->rx_urb);
2025 priv->rx_urb = NULL;
2029 kfree(priv->rx_urb);
2030 priv->rx_urb = NULL;
2031 kfree(priv->oldaddr);
2032 priv->oldaddr = NULL;
2033 if (priv->pp_rxskb) {
2034 kfree(priv->pp_rxskb);
2043 extern void rtl8192_update_ratr_table(struct net_device *dev);
2044 void rtl8192_link_change(struct net_device *dev)
2046 struct r8192_priv *priv = ieee80211_priv(dev);
2047 struct ieee80211_device *ieee = priv->ieee80211;
2048 if (ieee->state == IEEE80211_LINKED) {
2049 rtl8192_net_update(dev);
2050 rtl8192_update_ratr_table(dev);
2051 //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
2052 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
2053 EnableHWSecurityConfig8192(dev);
2055 /*update timing params*/
2056 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
2058 reg = read_nic_dword(dev, RCR);
2059 if (priv->ieee80211->state == IEEE80211_LINKED)
2060 priv->ReceiveConfig = reg |= RCR_CBSSID;
2062 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
2063 write_nic_dword(dev, RCR, reg);
2067 static struct ieee80211_qos_parameters def_qos_parameters = {
2068 {3, 3, 3, 3},/* cw_min */
2069 {7, 7, 7, 7},/* cw_max */
2070 {2, 2, 2, 2},/* aifs */
2071 {0, 0, 0, 0},/* flags */
2072 {0, 0, 0, 0} /* tx_op_limit */
2076 void rtl8192_update_beacon(struct work_struct *work)
2078 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
2079 struct net_device *dev = priv->ieee80211->dev;
2080 struct ieee80211_device *ieee = priv->ieee80211;
2081 struct ieee80211_network *net = &ieee->current_network;
2083 if (ieee->pHTInfo->bCurrentHTSupport)
2084 HTUpdateSelfAndPeerSetting(ieee, net);
2085 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
2086 rtl8192_update_cap(dev, net->capability);
2089 * background support to run QoS activate functionality
2091 int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
2092 void rtl8192_qos_activate(struct work_struct *work)
2094 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
2095 struct net_device *dev = priv->ieee80211->dev;
2096 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
2097 u8 mode = priv->ieee80211->current_network.mode;
2105 mutex_lock(&priv->mutex);
2106 if (priv->ieee80211->state != IEEE80211_LINKED)
2108 RT_TRACE(COMP_QOS, "qos active process with associate response received\n");
2109 /* It better set slot time at first */
2110 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
2111 /* update the ac parameter to related registers */
2112 for (i = 0; i < QOS_QUEUE_NUM; i++) {
2113 //Mode G/A: slotTimeTimer = 9; Mode B: 20
2114 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
2115 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
2116 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
2117 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
2118 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2120 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2124 mutex_unlock(&priv->mutex);
2127 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
2129 struct ieee80211_network *network)
2132 u32 size = sizeof(struct ieee80211_qos_parameters);
2134 if (priv->ieee80211->state != IEEE80211_LINKED)
2137 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2140 if (network->flags & NETWORK_HAS_QOS_MASK) {
2141 if (active_network &&
2142 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
2143 network->qos_data.active = network->qos_data.supported;
2145 if ((network->qos_data.active == 1) && (active_network == 1) &&
2146 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
2147 (network->qos_data.old_param_count !=
2148 network->qos_data.param_count)) {
2149 network->qos_data.old_param_count =
2150 network->qos_data.param_count;
2151 queue_work(priv->priv_wq, &priv->qos_activate);
2152 RT_TRACE(COMP_QOS, "QoS parameters change call "
2156 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2157 &def_qos_parameters, size);
2159 if ((network->qos_data.active == 1) && (active_network == 1)) {
2160 queue_work(priv->priv_wq, &priv->qos_activate);
2161 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
2163 network->qos_data.active = 0;
2164 network->qos_data.supported = 0;
2170 /* handle and manage frame from beacon and probe response */
2171 static int rtl8192_handle_beacon(struct net_device *dev,
2172 struct ieee80211_beacon *beacon,
2173 struct ieee80211_network *network)
2175 struct r8192_priv *priv = ieee80211_priv(dev);
2177 rtl8192_qos_handle_probe_response(priv, 1, network);
2178 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
2184 * handling the beaconing responses. if we get different QoS setting
2185 * off the network from the associated setting, adjust the QoS
2188 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
2189 struct ieee80211_network *network)
2192 unsigned long flags;
2193 u32 size = sizeof(struct ieee80211_qos_parameters);
2194 int set_qos_param = 0;
2196 if ((priv == NULL) || (network == NULL))
2199 if (priv->ieee80211->state != IEEE80211_LINKED)
2202 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2205 spin_lock_irqsave(&priv->ieee80211->lock, flags);
2206 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
2207 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2208 &network->qos_data.parameters,
2209 sizeof(struct ieee80211_qos_parameters));
2210 priv->ieee80211->current_network.qos_data.active = 1;
2212 /* update qos parameter for current network */
2213 priv->ieee80211->current_network.qos_data.old_param_count =
2214 priv->ieee80211->current_network.qos_data.param_count;
2215 priv->ieee80211->current_network.qos_data.param_count =
2216 network->qos_data.param_count;
2218 memcpy(&priv->ieee80211->current_network.qos_data.parameters,
2219 &def_qos_parameters, size);
2220 priv->ieee80211->current_network.qos_data.active = 0;
2221 priv->ieee80211->current_network.qos_data.supported = 0;
2225 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
2227 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, network->flags, priv->ieee80211->current_network.qos_data.active);
2228 if (set_qos_param == 1)
2229 queue_work(priv->priv_wq, &priv->qos_activate);
2236 static int rtl8192_handle_assoc_response(struct net_device *dev,
2237 struct ieee80211_assoc_response_frame *resp,
2238 struct ieee80211_network *network)
2240 struct r8192_priv *priv = ieee80211_priv(dev);
2241 rtl8192_qos_association_resp(priv, network);
2246 void rtl8192_update_ratr_table(struct net_device *dev)
2248 struct r8192_priv *priv = ieee80211_priv(dev);
2249 struct ieee80211_device *ieee = priv->ieee80211;
2250 u8 *pMcsRate = ieee->dot11HTOperationalRateSet;
2253 rtl8192_config_rate(dev, (u16 *)(&ratr_value));
2254 ratr_value |= (*(u16 *)(pMcsRate)) << 12;
2255 switch (ieee->mode) {
2257 ratr_value &= 0x00000FF0;
2260 ratr_value &= 0x0000000F;
2263 ratr_value &= 0x00000FF7;
2267 if (ieee->pHTInfo->PeerMimoPs == 0) {//MIMO_PS_STATIC
2268 ratr_value &= 0x0007F007;
2270 if (priv->rf_type == RF_1T2R)
2271 ratr_value &= 0x000FF007;
2273 ratr_value &= 0x0F81F007;
2279 ratr_value &= 0x0FFFFFFF;
2280 if (ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz)
2281 ratr_value |= 0x80000000;
2282 else if (!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz)
2283 ratr_value |= 0x80000000;
2284 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
2285 write_nic_byte(dev, UFWP, 1);
2288 static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04};
2289 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
2290 bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
2292 struct r8192_priv *priv = ieee80211_priv(dev);
2293 struct ieee80211_device *ieee = priv->ieee80211;
2294 struct ieee80211_network *network = &ieee->current_network;
2295 int wpa_ie_len = ieee->wpa_ie_len;
2296 struct ieee80211_crypt_data *crypt;
2299 crypt = ieee->crypt[ieee->tx_keyidx];
2300 //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
2301 encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name, "WEP")));
2304 if (encrypt && (wpa_ie_len == 0)) {
2305 /* wep encryption, no N mode setting */
2307 } else if ((wpa_ie_len != 0)) {
2308 /* parse pairwise key type */
2309 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))))
2320 bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
2323 struct r8192_priv *priv = ieee80211_priv(dev);
2324 struct ieee80211_device *ieee = priv->ieee80211;
2326 if (ieee->bHalfWirelessN24GMode == true)
2334 void rtl8192_refresh_supportrate(struct r8192_priv *priv)
2336 struct ieee80211_device *ieee = priv->ieee80211;
2337 //we do not consider set support rate for ABG mode, only HT MCS rate is set here.
2338 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2339 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
2341 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
2345 u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
2347 struct r8192_priv *priv = ieee80211_priv(dev);
2349 switch (priv->rf_chip) {
2353 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
2356 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
2359 ret = WIRELESS_MODE_B;
2364 void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
2366 struct r8192_priv *priv = ieee80211_priv(dev);
2367 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
2369 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode) == 0)) {
2370 if (bSupportMode & WIRELESS_MODE_N_24G) {
2371 wireless_mode = WIRELESS_MODE_N_24G;
2372 } else if (bSupportMode & WIRELESS_MODE_N_5G) {
2373 wireless_mode = WIRELESS_MODE_N_5G;
2374 } else if ((bSupportMode & WIRELESS_MODE_A)) {
2375 wireless_mode = WIRELESS_MODE_A;
2376 } else if ((bSupportMode & WIRELESS_MODE_G)) {
2377 wireless_mode = WIRELESS_MODE_G;
2378 } else if ((bSupportMode & WIRELESS_MODE_B)) {
2379 wireless_mode = WIRELESS_MODE_B;
2381 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __func__, bSupportMode);
2382 wireless_mode = WIRELESS_MODE_B;
2385 #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
2386 ActUpdateChannelAccessSetting(pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
2388 priv->ieee80211->mode = wireless_mode;
2390 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
2391 priv->ieee80211->pHTInfo->bEnableHT = 1;
2393 priv->ieee80211->pHTInfo->bEnableHT = 0;
2394 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
2395 rtl8192_refresh_supportrate(priv);
2398 //init priv variables here. only non_zero value should be initialized here.
2399 static void rtl8192_init_priv_variable(struct net_device *dev)
2401 struct r8192_priv *priv = ieee80211_priv(dev);
2403 priv->card_8192 = NIC_8192U;
2404 priv->chan = 1; //set to channel 1
2405 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
2406 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2407 priv->ieee80211->ieee_up = 0;
2408 priv->retry_rts = DEFAULT_RETRY_RTS;
2409 priv->retry_data = DEFAULT_RETRY_DATA;
2410 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
2411 priv->ieee80211->rate = 110; //11 mbps
2412 priv->ieee80211->short_slot = 1;
2413 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2416 priv->IrpPendingCount = 1;
2417 priv->ResetProgress = RESET_TYPE_NORESET;
2418 priv->bForcedSilentReset = 0;
2419 priv->bDisableNormalResetCheck = false;
2420 priv->force_reset = false;
2422 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available.
2423 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2424 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2425 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2426 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2427 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
2428 IEEE_SOFTMAC_BEACONS;//added by amy 080604
2430 priv->ieee80211->active_scan = 1;
2431 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
2432 priv->ieee80211->host_encrypt = 1;
2433 priv->ieee80211->host_decrypt = 1;
2434 priv->ieee80211->start_send_beacons = NULL; //-by amy 080604
2435 priv->ieee80211->stop_send_beacons = NULL; //-by amy 080604
2436 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
2437 priv->ieee80211->set_chan = rtl8192_set_chan;
2438 priv->ieee80211->link_change = rtl8192_link_change;
2439 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
2440 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
2441 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
2442 priv->ieee80211->init_wmmparam_flag = 0;
2443 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2444 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
2445 priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
2446 priv->ieee80211->qos_support = 1;
2449 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
2450 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
2451 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
2453 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
2454 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xUsb;
2455 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
2457 priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
2458 priv->card_type = USB;
2460 if (Adapter->bInHctTest) {
2461 pHalData->ShortRetryLimit = 7;
2462 pHalData->LongRetryLimit = 7;
2465 priv->ShortRetryLimit = 0x30;
2466 priv->LongRetryLimit = 0x30;
2467 priv->EarlyRxThreshold = 7;
2468 priv->enable_gpio0 = 0;
2469 priv->TransmitConfig =
2470 (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)| // Max DMA Burst Size per Tx DMA Burst, 7: reserved.
2471 (priv->ShortRetryLimit<<TCR_SRL_OFFSET)| // Short retry limit
2472 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
2473 (false ? TCR_SAT : 0); // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
2475 if (Adapter->bInHctTest)
2476 pHalData->ReceiveConfig = pHalData->CSMethod |
2477 RCR_AMF | RCR_ADF | //accept management/data
2479 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2480 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2481 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
2482 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2483 (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
2484 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
2488 priv->ReceiveConfig =
2489 RCR_AMF | RCR_ADF | //accept management/data
2490 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2491 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2492 ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2493 (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
2494 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT : 0);
2496 priv->AcmControl = 0;
2497 priv->pFirmware = kzalloc(sizeof(rt_firmware), GFP_KERNEL);
2499 /* rx related queue */
2500 skb_queue_head_init(&priv->rx_queue);
2501 skb_queue_head_init(&priv->skb_queue);
2503 /* Tx related queue */
2504 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2505 skb_queue_head_init(&priv->ieee80211->skb_waitQ[i]);
2506 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2507 skb_queue_head_init(&priv->ieee80211->skb_aggQ[i]);
2508 for (i = 0; i < MAX_QUEUE_SIZE; i++)
2509 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ[i]);
2510 priv->rf_set_chan = rtl8192_phy_SwChnl;
2514 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
2516 spin_lock_init(&priv->tx_lock);
2517 spin_lock_init(&priv->irq_lock);//added by thomas
2518 sema_init(&priv->wx_sem, 1);
2519 sema_init(&priv->rf_sem, 1);
2520 mutex_init(&priv->mutex);
2523 extern void rtl819x_watchdog_wqcallback(struct work_struct *work);
2525 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
2526 //init tasklet and wait_queue here. only 2.6 above kernel is considered
2527 #define DRV_NAME "wlan0"
2528 static void rtl8192_init_priv_task(struct net_device *dev)
2530 struct r8192_priv *priv = ieee80211_priv(dev);
2532 priv->priv_wq = create_workqueue(DRV_NAME);
2534 INIT_WORK(&priv->reset_wq, rtl8192_restart);
2536 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
2537 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
2538 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
2539 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
2540 INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
2541 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
2543 tasklet_init(&priv->irq_rx_tasklet,
2544 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
2545 (unsigned long)priv);
2548 static void rtl8192_get_eeprom_size(struct net_device *dev)
2551 struct r8192_priv *priv = ieee80211_priv(dev);
2552 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
2553 curCR = read_nic_word_E(dev, EPROM_CMD);
2554 RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
2555 //whether need I consider BIT5?
2556 priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
2557 RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
2560 //used to swap endian. as ntohl & htonl are not necessary to swap endian, so use this instead.
2561 static inline u16 endian_swap(u16 *data)
2564 *data = (tmp >> 8) | (tmp << 8);
2567 static void rtl8192_read_eeprom_info(struct net_device *dev)
2570 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
2571 u8 bLoad_From_EEPOM = false;
2572 struct r8192_priv *priv = ieee80211_priv(dev);
2575 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
2576 wEPROM_ID = eprom_read(dev, 0); //first read EEPROM ID out;
2577 RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
2579 if (wEPROM_ID != RTL8190_EEPROM_ID) {
2580 RT_TRACE(COMP_ERR, "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n", wEPROM_ID, RTL8190_EEPROM_ID);
2582 bLoad_From_EEPOM = true;
2585 if (bLoad_From_EEPOM) {
2586 tmpValue = eprom_read(dev, (EEPROM_VID>>1));
2587 priv->eeprom_vid = endian_swap(&tmpValue);
2588 priv->eeprom_pid = eprom_read(dev, (EEPROM_PID>>1));
2589 tmpValue = eprom_read(dev, (EEPROM_ChannelPlan>>1));
2590 priv->eeprom_ChannelPlan = ((tmpValue&0xff00)>>8);
2591 priv->btxpowerdata_readfromEEPORM = true;
2592 priv->eeprom_CustomerID = eprom_read(dev, (EEPROM_Customer_ID>>1)) >>8;
2594 priv->eeprom_vid = 0;
2595 priv->eeprom_pid = 0;
2596 priv->card_8192_version = VERSION_819xU_B;
2597 priv->eeprom_ChannelPlan = 0;
2598 priv->eeprom_CustomerID = 0;
2600 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);
2601 //set channelplan from eeprom
2602 priv->ChannelPlan = priv->eeprom_ChannelPlan;
2603 if (bLoad_From_EEPOM) {
2605 for (i = 0; i < 6; i += 2) {
2607 tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i)>>1));
2608 *(u16 *)(&dev->dev_addr[i]) = tmp;
2611 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
2612 //should I set IDR0 here?
2614 RT_TRACE(COMP_EPROM, "MAC addr:%pM\n", dev->dev_addr);
2615 priv->rf_type = RTL819X_DEFAULT_RF_TYPE; //default 1T2R
2616 priv->rf_chip = RF_8256;
2618 if (priv->card_8192_version == (u8)VERSION_819xU_A) {
2619 //read Tx power gain offset of legacy OFDM to HT rate
2620 if (bLoad_From_EEPOM)
2621 priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff>>1))&0xff00) >> 8;
2623 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
2624 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
2625 //read ThermalMeter from EEPROM
2626 if (bLoad_From_EEPOM)
2627 priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter>>1))&0x00ff);
2629 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2630 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
2631 //vivi, for tx power track
2632 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
2633 //read antenna tx power offset of B/C/D to A from EEPROM
2634 if (bLoad_From_EEPOM)
2635 priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff>>1))&0x0f00)>>8;
2637 priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
2638 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
2639 // Read CrystalCap from EEPROM
2640 if (bLoad_From_EEPOM)
2641 priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap>>1))&0x0f);
2643 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
2644 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
2645 //get per-channel Tx power level
2646 if (bLoad_From_EEPOM)
2647 priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver>>1))&0xff00)>>8;
2649 priv->EEPROM_Def_Ver = 1;
2650 RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
2651 if (priv->EEPROM_Def_Ver == 0) { //old eeprom definition
2653 if (bLoad_From_EEPOM)
2654 priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK>>1))&0xff) >> 8;
2656 priv->EEPROMTxPowerLevelCCK = 0x10;
2657 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
2658 for (i = 0; i < 3; i++) {
2659 if (bLoad_From_EEPOM) {
2660 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G+i)>>1);
2661 if (((EEPROM_TxPwIndex_OFDM_24G+i) % 2) == 0)
2662 tmpValue = tmpValue & 0x00ff;
2664 tmpValue = (tmpValue & 0xff00) >> 8;
2668 priv->EEPROMTxPowerLevelOFDM24G[i] = (u8) tmpValue;
2669 RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
2671 } else if (priv->EEPROM_Def_Ver == 1) {
2672 if (bLoad_From_EEPOM) {
2673 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1>>1));
2674 tmpValue = (tmpValue & 0xff00) >> 8;
2678 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
2680 if (bLoad_From_EEPOM)
2681 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2)>>1);
2684 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
2685 if (bLoad_From_EEPOM)
2686 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1>>1));
2689 *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
2690 if (bLoad_From_EEPOM)
2691 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1+2)>>1);
2694 priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
2695 }//endif EEPROM_Def_Ver == 1
2697 //update HAL variables
2699 for (i = 0; i < 14; i++) {
2701 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
2702 else if (i >= 4 && i <= 9)
2703 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
2705 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
2708 for (i = 0; i < 14; i++) {
2709 if (priv->EEPROM_Def_Ver == 0) {
2711 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
2712 else if (i >= 4 && i <= 9)
2713 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
2715 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
2716 } else if (priv->EEPROM_Def_Ver == 1) {
2718 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
2719 else if (i >= 4 && i <= 9)
2720 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
2722 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
2725 priv->TxPowerDiff = priv->EEPROMPwDiff;
2726 // Antenna B gain offset to antenna A, bit0~3
2727 priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
2728 // Antenna C gain offset to antenna A, bit4~7
2729 priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);
2730 // CrystalCap, bit12~15
2731 priv->CrystalCap = priv->EEPROMCrystalCap;
2732 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
2733 // 92U does not enable TX power tracking.
2734 priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
2735 }//end if VersionID == VERSION_819xU_A
2737 //added by vivi, for dlink led, 20080416
2738 switch (priv->eeprom_CustomerID) {
2739 case EEPROM_CID_RUNTOP:
2740 priv->CustomerID = RT_CID_819x_RUNTOP;
2743 case EEPROM_CID_DLINK:
2744 priv->CustomerID = RT_CID_DLINK;
2748 priv->CustomerID = RT_CID_DEFAULT;
2753 switch (priv->CustomerID) {
2754 case RT_CID_819x_RUNTOP:
2755 priv->LedStrategy = SW_LED_MODE2;
2759 priv->LedStrategy = SW_LED_MODE4;
2763 priv->LedStrategy = SW_LED_MODE0;
2769 if (priv->rf_type == RF_1T2R) {
2770 RT_TRACE(COMP_EPROM, "\n1T2R config\n");
2772 RT_TRACE(COMP_EPROM, "\n2T4R config\n");
2775 // 2008/01/16 MH We can only know RF type in the function. So we have to init
2776 // DIG RATR table again.
2777 init_rate_adaptive(dev);
2778 //we need init DIG RATR table here again.
2780 RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
2784 short rtl8192_get_channel_map(struct net_device *dev)
2786 struct r8192_priv *priv = ieee80211_priv(dev);
2787 if (priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN) {
2788 netdev_err(dev, "rtl8180_init: Error channel plan! Set to default.\n");
2789 priv->ChannelPlan = 0;
2791 RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
2793 rtl819x_set_channel_map(priv->ChannelPlan, priv);
2797 short rtl8192_init(struct net_device *dev)
2800 struct r8192_priv *priv = ieee80211_priv(dev);
2802 memset(&(priv->stats), 0, sizeof(struct Stats));
2803 memset(priv->txqueue_to_outpipemap, 0, 9);
2807 u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
2808 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
2812 u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 0, 4, 4};
2813 memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
2816 rtl8192_init_priv_variable(dev);
2817 rtl8192_init_priv_lock(priv);
2818 rtl8192_init_priv_task(dev);
2819 rtl8192_get_eeprom_size(dev);
2820 rtl8192_read_eeprom_info(dev);
2821 rtl8192_get_channel_map(dev);
2823 init_timer(&priv->watch_dog_timer);
2824 priv->watch_dog_timer.data = (unsigned long)dev;
2825 priv->watch_dog_timer.function = watch_dog_timer_callback;
2826 if (rtl8192_usb_initendpoints(dev) != 0) {
2827 DMESG("Endopoints initialization failed");
2837 /******************************************************************************
2838 *function: This function actually only set RRSR, RATR and BW_OPMODE registers
2839 * not to do all the hw config as its name says
2840 * input: net_device dev
2843 * notice: This part need to modified according to the rate set we filtered
2844 * ****************************************************************************/
2845 void rtl8192_hwconfig(struct net_device *dev)
2847 u32 regRATR = 0, regRRSR = 0;
2848 u8 regBwOpMode = 0, regTmp = 0;
2849 struct r8192_priv *priv = ieee80211_priv(dev);
2852 // Set RRSR, RATR, and BW_OPMODE registers
2854 switch (priv->ieee80211->mode) {
2855 case WIRELESS_MODE_B:
2856 regBwOpMode = BW_OPMODE_20MHZ;
2857 regRATR = RATE_ALL_CCK;
2858 regRRSR = RATE_ALL_CCK;
2860 case WIRELESS_MODE_A:
2861 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
2862 regRATR = RATE_ALL_OFDM_AG;
2863 regRRSR = RATE_ALL_OFDM_AG;
2865 case WIRELESS_MODE_G:
2866 regBwOpMode = BW_OPMODE_20MHZ;
2867 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2868 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2870 case WIRELESS_MODE_AUTO:
2872 if (Adapter->bInHctTest) {
2873 regBwOpMode = BW_OPMODE_20MHZ;
2874 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2875 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2880 regBwOpMode = BW_OPMODE_20MHZ;
2881 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2882 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2885 case WIRELESS_MODE_N_24G:
2886 // It support CCK rate by default.
2887 // CCK rate will be filtered out only when associated AP does not support it.
2888 regBwOpMode = BW_OPMODE_20MHZ;
2889 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2890 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
2892 case WIRELESS_MODE_N_5G:
2893 regBwOpMode = BW_OPMODE_5G;
2894 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
2895 regRRSR = RATE_ALL_OFDM_AG;
2899 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
2900 ratr_value = regRATR;
2901 if (priv->rf_type == RF_1T2R)
2902 ratr_value &= ~(RATE_ALL_OFDM_2SS);
2903 write_nic_dword(dev, RATR0, ratr_value);
2904 write_nic_byte(dev, UFWP, 1);
2905 regTmp = read_nic_byte(dev, 0x313);
2906 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
2907 write_nic_dword(dev, RRSR, regRRSR);
2910 // Set Retry Limit here
2912 write_nic_word(dev, RETRY_LIMIT,
2913 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
2914 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
2915 // Set Contention Window here
2919 // Set Tx Antenna including Feedback control
2921 // Set Auto Rate fallback control
2927 //InitializeAdapter and PhyCfg
2928 bool rtl8192_adapter_start(struct net_device *dev)
2930 struct r8192_priv *priv = ieee80211_priv(dev);
2932 bool init_status = true;
2933 u8 SECR_value = 0x0;
2934 RT_TRACE(COMP_INIT, "====>%s()\n", __func__);
2935 priv->Rf_Mode = RF_OP_By_SW_3wire;
2936 //for ASIC power on sequence
2937 write_nic_byte_E(dev, 0x5f, 0x80);
2939 write_nic_byte_E(dev, 0x5f, 0xf0);
2940 write_nic_byte_E(dev, 0x5d, 0x00);
2941 write_nic_byte_E(dev, 0x5e, 0x80);
2942 write_nic_byte(dev, 0x17, 0x37);
2944 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
2945 //config CPUReset Register
2946 //Firmware Reset or not?
2947 dwRegRead = read_nic_dword(dev, CPU_GEN);
2948 if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
2949 dwRegRead |= CPU_GEN_SYSTEM_RESET; //do nothing here?
2950 else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
2951 dwRegRead |= CPU_GEN_FIRMWARE_RESET;
2953 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __func__, priv->pFirmware->firmware_status);
2955 write_nic_dword(dev, CPU_GEN, dwRegRead);
2957 rtl8192_BBConfig(dev);
2959 //Loopback mode or not
2960 priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
2962 dwRegRead = read_nic_dword(dev, CPU_GEN);
2963 if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
2964 dwRegRead = ((dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
2965 else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
2966 dwRegRead |= CPU_CCK_LOOPBACK;
2968 RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __func__, priv->LoopbackMode);
2970 write_nic_dword(dev, CPU_GEN, dwRegRead);
2972 //after reset cpu, we need wait for a seconds to write in register.
2975 //xiong add for new bitfile:usb suspend reset pin set to 1. //do we need?
2976 write_nic_byte_E(dev, 0x5f, (read_nic_byte_E(dev, 0x5f)|0x20));
2979 rtl8192_hwconfig(dev);
2982 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
2985 write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
2986 write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
2989 write_nic_dword(dev, RCR, priv->ReceiveConfig);
2991 //Initialize Number of Reserved Pages in Firmware Queue
2992 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
2993 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
2994 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
2995 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
2996 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
2997 NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
2998 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
2999 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
3000 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
3003 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
3004 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
3006 if (priv->ResetProgress == RESET_TYPE_NORESET)
3007 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
3008 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3009 CamResetAllEntry(dev);
3010 SECR_value |= SCR_TxEncEnable;
3011 SECR_value |= SCR_RxDecEnable;
3012 SECR_value |= SCR_NoSKMC;
3013 write_nic_byte(dev, SECR, SECR_value);
3017 write_nic_word(dev, ATIMWND, 2);
3018 write_nic_word(dev, BCN_INTERVAL, 100);
3020 #define DEFAULT_EDCA 0x005e4332
3023 for (i = 0; i < QOS_QUEUE_NUM; i++)
3024 write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
3026 #ifdef USB_RX_AGGREGATION_SUPPORT
3027 //3 For usb rx firmware aggregation control
3028 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3030 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
3031 ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
3032 (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
3034 * If usb rx firmware aggregation is enabled,
3035 * when anyone of three threshold conditions above is reached,
3036 * firmware will send aggregated packet to driver.
3038 write_nic_dword(dev, 0x1a8, ulValue);
3039 priv->bCurrentRxAggrEnable = true;
3043 rtl8192_phy_configmac(dev);
3045 if (priv->card_8192_version == (u8) VERSION_819xU_A) {
3046 rtl8192_phy_getTxPower(dev);
3047 rtl8192_phy_setTxPower(dev, priv->chan);
3051 init_status = init_firmware(dev);
3053 RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n", __func__);
3056 RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
3059 if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
3060 if (pMgntInfo->RegRfOff == TRUE) { // User disable RF via registry.
3061 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
3062 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
3063 // Those actions will be discard in MgntActSet_RF_State because of the same state
3064 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
3065 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3066 } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) { // H/W or S/W RF OFF before sleep.
3067 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n", pMgntInfo->RfOffReason));
3068 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
3070 pHalData->eRFPowerState = eRfOn;
3071 pMgntInfo->RfOffReason = 0;
3072 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): RF is on ----------\n"));
3075 if (pHalData->eRFPowerState == eRfOff) {
3076 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
3077 // Those actions will be discard in MgntActSet_RF_State because of the same state
3078 for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
3079 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
3084 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3085 rtl8192_phy_RFConfig(dev);
3086 RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __func__);
3090 if (priv->ieee80211->FwRWRF)
3091 // We can force firmware to do RF-R/W
3092 priv->Rf_Mode = RF_OP_By_FW;
3094 priv->Rf_Mode = RF_OP_By_SW_3wire;
3097 rtl8192_phy_updateInitGain(dev);
3098 /*--set CCK and OFDM Block "ON"--*/
3099 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
3100 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
3102 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3104 u8 tmpvalue = read_nic_byte(dev, 0x301);
3105 if (tmpvalue == 0x03) {
3107 RT_TRACE(COMP_POWER_TRACKING, "D-cut\n");
3109 priv->bDcut = FALSE;
3110 RT_TRACE(COMP_POWER_TRACKING, "C-cut\n");
3112 dm_initialize_txpower_tracking(dev);
3114 if (priv->bDcut == TRUE) {
3116 u32 tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
3117 for (i = 0; i < TxBBGainTableLength; i++) {
3118 if (tmpRegA == priv->txbbgain_table[i].txbbgain_value) {
3119 priv->rfa_txpowertrackingindex = (u8)i;
3120 priv->rfa_txpowertrackingindex_real = (u8)i;
3121 priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
3126 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
3128 for (i = 0; i < CCKTxBBGainTableLength; i++) {
3130 if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
3131 priv->cck_present_attentuation_20Mdefault = (u8) i;
3135 priv->cck_present_attentuation_40Mdefault = 0;
3136 priv->cck_present_attentuation_difference = 0;
3137 priv->cck_present_attentuation = priv->cck_present_attentuation_20Mdefault;
3141 write_nic_byte(dev, 0x87, 0x0);
3147 /* this configures registers for beacon tx and enables it via
3148 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
3149 * be used to stop beacon transmission
3151 /***************************************************************************
3152 -------------------------------NET STUFF---------------------------
3153 ***************************************************************************/
3155 static struct net_device_stats *rtl8192_stats(struct net_device *dev)
3157 struct r8192_priv *priv = ieee80211_priv(dev);
3159 return &priv->ieee80211->stats;
3162 bool HalTxCheckStuck819xUsb(struct net_device *dev)
3164 struct r8192_priv *priv = ieee80211_priv(dev);
3165 u16 RegTxCounter = read_nic_word(dev, 0x128);
3166 bool bStuck = FALSE;
3167 RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n", __func__, RegTxCounter, priv->TxCounter);
3168 if (priv->TxCounter == RegTxCounter)
3171 priv->TxCounter = RegTxCounter;
3177 * <Assumption: RT_TX_SPINLOCK is acquired.>
3178 * First added: 2006.11.19 by emily
3180 RESET_TYPE TxCheckStuck(struct net_device *dev)
3182 struct r8192_priv *priv = ieee80211_priv(dev);
3184 bool bCheckFwTxCnt = false;
3187 // Decide such threshold according to current power save mode
3190 for (QueueID = 0; QueueID <= BEACON_QUEUE; QueueID ++) {
3191 if (QueueID == TXCMD_QUEUE)
3193 #ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
3194 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))
3196 if ((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
3200 bCheckFwTxCnt = true;
3202 if (bCheckFwTxCnt) {
3203 if (HalTxCheckStuck819xUsb(dev)) {
3204 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
3205 return RESET_TYPE_SILENT;
3208 return RESET_TYPE_NORESET;
3211 bool HalRxCheckStuck819xUsb(struct net_device *dev)
3213 u16 RegRxCounter = read_nic_word(dev, 0x130);
3214 struct r8192_priv *priv = ieee80211_priv(dev);
3215 bool bStuck = FALSE;
3216 static u8 rx_chk_cnt;
3217 RT_TRACE(COMP_RESET, "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__, RegRxCounter, priv->RxCounter);
3218 // If rssi is small, we should check rx for long time because of bad rx.
3219 // or maybe it will continuous silent reset every 2 seconds.
3221 if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) {
3222 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
3223 } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
3224 ((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_40M) ||
3225 (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_20M))) {
3230 } else if (((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_40M) ||
3231 (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_20M)) &&
3232 priv->undecorated_smoothed_pwdb >= VeryLowRSSI) {
3244 if (priv->RxCounter == RegRxCounter)
3247 priv->RxCounter = RegRxCounter;
3252 RESET_TYPE RxCheckStuck(struct net_device *dev)
3254 struct r8192_priv *priv = ieee80211_priv(dev);
3255 bool bRxCheck = FALSE;
3257 if (priv->IrpPendingCount > 1)
3261 if (HalRxCheckStuck819xUsb(dev)) {
3262 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
3263 return RESET_TYPE_SILENT;
3266 return RESET_TYPE_NORESET;
3271 * This function is called by Checkforhang to check whether we should ask OS to reset driver
3273 * \param pAdapter The adapter context for this miniport
3275 * Note:NIC with USB interface sholud not call this function because we cannot scan descriptor
3276 * to judge whether there is tx stuck.
3277 * Note: This function may be required to be rewrite for Vista OS.
3278 * <<<Assumption: Tx spinlock has been acquired >>>
3280 * 8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
3282 RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
3284 struct r8192_priv *priv = ieee80211_priv(dev);
3285 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
3286 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
3287 RT_RF_POWER_STATE rfState;
3289 rfState = priv->ieee80211->eRFPowerState;
3291 TxResetType = TxCheckStuck(dev);
3292 if (rfState != eRfOff ||
3293 (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
3294 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
3295 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
3296 // if driver is in firmware download failure status, driver should initialize RF in the following
3297 // silent reset procedure Emily, 2008.01.21
3299 // Driver should not check RX stuck in IBSS mode because it is required to
3300 // set Check BSSID in order to send beacon, however, if check BSSID is
3301 // set, STA cannot hear any packet at all. Emily, 2008.04.12
3302 RxResetType = RxCheckStuck(dev);
3304 if (TxResetType == RESET_TYPE_NORMAL || RxResetType == RESET_TYPE_NORMAL) {
3305 return RESET_TYPE_NORMAL;
3306 } else if (TxResetType == RESET_TYPE_SILENT || RxResetType == RESET_TYPE_SILENT) {
3307 RT_TRACE(COMP_RESET, "%s():silent reset\n", __func__);
3308 return RESET_TYPE_SILENT;
3310 return RESET_TYPE_NORESET;
3315 void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
3316 int _rtl8192_up(struct net_device *dev);
3317 int rtl8192_close(struct net_device *dev);
3321 void CamRestoreAllEntry(struct net_device *dev)
3324 struct r8192_priv *priv = ieee80211_priv(dev);
3325 u8 *MacAddr = priv->ieee80211->current_network.bssid;
3327 static u8 CAM_CONST_ADDR[4][6] = {
3328 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
3329 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
3330 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
3331 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} };
3332 static u8 CAM_CONST_BROAD[] = {
3333 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3335 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
3338 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
3339 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) {
3341 for (EntryId = 0; EntryId < 4; EntryId++) {
3342 MacAddr = CAM_CONST_ADDR[EntryId];
3343 setKey(dev, EntryId, EntryId,
3344 priv->ieee80211->pairwise_key_type,
3348 } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
3350 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3351 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3352 (u8 *)dev->dev_addr, 0, NULL);
3354 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3356 } else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
3358 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3359 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3360 (u8 *)dev->dev_addr, 0, NULL);
3362 setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
3368 if (priv->ieee80211->group_key_type == KEY_TYPE_TKIP) {
3369 MacAddr = CAM_CONST_BROAD;
3370 for (EntryId = 1; EntryId < 4; EntryId++) {
3371 setKey(dev, EntryId, EntryId,
3372 priv->ieee80211->group_key_type,
3375 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3376 setKey(dev, 0, 0, priv->ieee80211->group_key_type,
3377 CAM_CONST_ADDR[0], 0, NULL);
3378 } else if (priv->ieee80211->group_key_type == KEY_TYPE_CCMP) {
3379 MacAddr = CAM_CONST_BROAD;
3380 for (EntryId = 1; EntryId < 4; EntryId++) {
3381 setKey(dev, EntryId, EntryId,
3382 priv->ieee80211->group_key_type,
3386 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3387 setKey(dev, 0, 0, priv->ieee80211->group_key_type,
3388 CAM_CONST_ADDR[0], 0, NULL);
3391 //////////////////////////////////////////////////////////////
3392 // This function is used to fix Tx/Rx stop bug temporarily.
3393 // This function will do "system reset" to NIC when Tx or Rx is stuck.
3394 // The method checking Tx/Rx stuck of this function is supported by FW,
3395 // which reports Tx and Rx counter to register 0x128 and 0x130.
3396 //////////////////////////////////////////////////////////////
3397 void rtl819x_ifsilentreset(struct net_device *dev)
3399 struct r8192_priv *priv = ieee80211_priv(dev);
3401 int reset_status = 0;
3402 struct ieee80211_device *ieee = priv->ieee80211;
3405 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
3406 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
3408 if (priv->ResetProgress == RESET_TYPE_NORESET) {
3411 RT_TRACE(COMP_RESET, "=========>Reset progress!! \n");
3413 // Set the variable for reset.
3414 priv->ResetProgress = RESET_TYPE_SILENT;
3415 down(&priv->wx_sem);
3416 if (priv->up == 0) {
3417 RT_TRACE(COMP_ERR, "%s():the driver is not up! return\n", __func__);
3422 RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n", __func__);
3424 rtl8192_rtx_disable(dev);
3425 rtl8192_cancel_deferred_work(priv);
3427 del_timer_sync(&priv->watch_dog_timer);
3429 ieee->sync_scan_hurryup = 1;
3430 if (ieee->state == IEEE80211_LINKED) {
3431 down(&ieee->wx_sem);
3432 netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
3433 ieee80211_stop_send_beacons(priv->ieee80211);
3434 del_timer_sync(&ieee->associate_timer);
3435 cancel_delayed_work(&ieee->associate_retry_wq);
3436 ieee80211_stop_scan(ieee);
3437 netif_carrier_off(dev);
3440 netdev_dbg(dev, "ieee->state is NOT LINKED\n");
3441 ieee80211_softmac_stop_protocol(priv->ieee80211);
3444 RT_TRACE(COMP_RESET, "%s():<==========down process is finished\n", __func__);
3445 RT_TRACE(COMP_RESET, "%s():===========>start up the driver\n", __func__);
3446 reset_status = _rtl8192_up(dev);
3448 RT_TRACE(COMP_RESET, "%s():<===========up process is finished\n", __func__);
3449 if (reset_status == -EAGAIN) {
3450 if (reset_times < 3) {
3454 RT_TRACE(COMP_ERR, " ERR!!! %s(): Reset Failed!!\n", __func__);
3457 ieee->is_silent_reset = 1;
3458 EnableHWSecurityConfig8192(dev);
3459 if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
3460 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3462 queue_work(ieee->wq, &ieee->associate_complete_wq);
3464 } else if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC) {
3465 ieee->set_chan(ieee->dev, ieee->current_network.channel);
3466 ieee->link_change(ieee->dev);
3468 ieee80211_start_send_beacons(ieee);
3470 if (ieee->data_hard_resume)
3471 ieee->data_hard_resume(ieee->dev);
3472 netif_carrier_on(ieee->dev);
3475 CamRestoreAllEntry(dev);
3477 priv->ResetProgress = RESET_TYPE_NORESET;
3478 priv->reset_count++;
3480 priv->bForcedSilentReset = false;
3481 priv->bResetInProgress = false;
3483 // For test --> force write UFWP.
3484 write_nic_byte(dev, UFWP, 1);
3485 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
3489 void CAM_read_entry(struct net_device *dev, u32 iIndex)
3491 u32 target_command = 0;
3492 u32 target_content = 0;
3496 for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {
3497 // polling bit, and No Write enable, and address
3498 target_command = entry_i+CAM_CONTENT_COUNT*iIndex;
3499 target_command = target_command | BIT31;
3501 //Check polling bit is clear
3502 while ((i--) >= 0) {
3503 ulStatus = read_nic_dword(dev, RWCAM);
3504 if (ulStatus & BIT31)
3509 write_nic_dword(dev, RWCAM, target_command);
3510 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A0: %x \n", target_command);
3511 target_content = read_nic_dword(dev, RCAMO);
3512 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n", target_content);
3517 void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
3518 u32 *TotalRxDataNum)
3524 *TotalRxDataNum = 0;
3526 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
3527 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
3528 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
3529 for (i = 0; i < priv->ieee80211->LinkDetectInfo.SlotNum; i++) {
3530 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
3531 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
3536 extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
3538 struct delayed_work *dwork = container_of(work, struct delayed_work, work);
3539 struct r8192_priv *priv = container_of(dwork, struct r8192_priv, watch_dog_wq);
3540 struct net_device *dev = priv->ieee80211->dev;
3541 struct ieee80211_device *ieee = priv->ieee80211;
3542 RESET_TYPE ResetType = RESET_TYPE_NORESET;
3543 static u8 check_reset_cnt;
3544 bool bBusyTraffic = false;
3545 u32 TotalRxBcnNum = 0;
3546 u32 TotalRxDataNum = 0;
3550 hal_dm_watchdog(dev);
3552 //to get busy traffic condition
3553 if (ieee->state == IEEE80211_LINKED) {
3554 if (ieee->LinkDetectInfo.NumRxOkInPeriod > 666 ||
3555 ieee->LinkDetectInfo.NumTxOkInPeriod > 666 ) {
3556 bBusyTraffic = true;
3558 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
3559 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
3560 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
3562 //added by amy for AP roaming
3563 if (priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA) {
3565 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
3566 if ((TotalRxBcnNum+TotalRxDataNum) == 0) {
3568 if (rfState == eRfOff)
3569 RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
3571 netdev_dbg(dev, "===>%s(): AP is power off, connect another one\n", __func__);
3572 priv->ieee80211->state = IEEE80211_ASSOCIATING;
3573 notify_wx_assoc_event(priv->ieee80211);
3574 RemovePeerTS(priv->ieee80211, priv->ieee80211->current_network.bssid);
3575 priv->ieee80211->link_change(dev);
3576 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
3580 priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
3581 priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod = 0;
3582 //check if reset the driver
3583 if (check_reset_cnt++ >= 3) {
3584 ResetType = rtl819x_ifcheck_resetornot(dev);
3585 check_reset_cnt = 3;
3587 if ((priv->force_reset) || (priv->ResetProgress == RESET_TYPE_NORESET &&
3588 (priv->bForcedSilentReset ||
3589 (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) { // This is control by OID set in Pomelo
3590 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);
3591 rtl819x_ifsilentreset(dev);
3593 priv->force_reset = false;
3594 priv->bForcedSilentReset = false;
3595 priv->bResetInProgress = false;
3596 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
3600 void watch_dog_timer_callback(unsigned long data)
3602 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
3603 queue_delayed_work(priv->priv_wq, &priv->watch_dog_wq, 0);
3604 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
3606 int _rtl8192_up(struct net_device *dev)
3608 struct r8192_priv *priv = ieee80211_priv(dev);
3609 int init_status = 0;
3611 priv->ieee80211->ieee_up = 1;
3612 RT_TRACE(COMP_INIT, "Bringing up iface");
3613 init_status = rtl8192_adapter_start(dev);
3615 RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n", __func__);
3616 priv->up = priv->ieee80211->ieee_up = 0;
3619 RT_TRACE(COMP_INIT, "start adapter finished\n");
3620 rtl8192_rx_enable(dev);
3621 if (priv->ieee80211->state != IEEE80211_LINKED)
3622 ieee80211_softmac_start_protocol(priv->ieee80211);
3623 ieee80211_reset_queue(priv->ieee80211);
3624 watch_dog_timer_callback((unsigned long) dev);
3625 if (!netif_queue_stopped(dev))
3626 netif_start_queue(dev);
3628 netif_wake_queue(dev);
3634 int rtl8192_open(struct net_device *dev)
3636 struct r8192_priv *priv = ieee80211_priv(dev);
3638 down(&priv->wx_sem);
3639 ret = rtl8192_up(dev);
3646 int rtl8192_up(struct net_device *dev)
3648 struct r8192_priv *priv = ieee80211_priv(dev);
3650 if (priv->up == 1) return -1;
3652 return _rtl8192_up(dev);
3656 int rtl8192_close(struct net_device *dev)
3658 struct r8192_priv *priv = ieee80211_priv(dev);
3661 down(&priv->wx_sem);
3663 ret = rtl8192_down(dev);
3671 int rtl8192_down(struct net_device *dev)
3673 struct r8192_priv *priv = ieee80211_priv(dev);
3676 if (priv->up == 0) return -1;
3679 priv->ieee80211->ieee_up = 0;
3680 RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__);
3682 if (!netif_queue_stopped(dev))
3683 netif_stop_queue(dev);
3685 rtl8192_rtx_disable(dev);
3687 /* Tx related queue release */
3688 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3689 skb_queue_purge(&priv->ieee80211->skb_waitQ[i]);
3690 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3691 skb_queue_purge(&priv->ieee80211->skb_aggQ[i]);
3693 for (i = 0; i < MAX_QUEUE_SIZE; i++)
3694 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ[i]);
3696 //as cancel_delayed_work will del work->timer, so if work is not defined as struct delayed_work, it will corrupt
3697 rtl8192_cancel_deferred_work(priv);
3699 del_timer_sync(&priv->watch_dog_timer);
3702 ieee80211_softmac_stop_protocol(priv->ieee80211);
3703 memset(&priv->ieee80211->current_network, 0, offsetof(struct ieee80211_network, list));
3704 RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
3710 void rtl8192_commit(struct net_device *dev)
3712 struct r8192_priv *priv = ieee80211_priv(dev);
3713 int reset_status = 0;
3714 if (priv->up == 0) return;
3717 rtl8192_cancel_deferred_work(priv);
3718 del_timer_sync(&priv->watch_dog_timer);
3720 ieee80211_softmac_stop_protocol(priv->ieee80211);
3722 rtl8192_rtx_disable(dev);
3723 reset_status = _rtl8192_up(dev);
3727 void rtl8192_restart(struct work_struct *work)
3729 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
3730 struct net_device *dev = priv->ieee80211->dev;
3732 down(&priv->wx_sem);
3734 rtl8192_commit(dev);
3739 static void r8192_set_multicast(struct net_device *dev)
3741 struct r8192_priv *priv = ieee80211_priv(dev);
3746 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
3748 if (promisc != priv->promisc)
3750 priv->promisc = promisc;
3754 int r8192_set_mac_adr(struct net_device *dev, void *mac)
3756 struct r8192_priv *priv = ieee80211_priv(dev);
3757 struct sockaddr *addr = mac;
3759 down(&priv->wx_sem);
3761 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
3763 schedule_work(&priv->reset_wq);
3769 /* based on ipw2200 driver */
3770 int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3772 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3773 struct iwreq *wrq = (struct iwreq *)rq;
3775 struct ieee80211_device *ieee = priv->ieee80211;
3777 u8 broadcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3778 struct iw_point *p = &wrq->u.data;
3779 struct ieee_param *ipw = NULL;
3781 down(&priv->wx_sem);
3784 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
3789 ipw = kmalloc(p->length, GFP_KERNEL);
3794 if (copy_from_user(ipw, p->pointer, p->length)) {
3801 case RTL_IOCTL_WPA_SUPPLICANT:
3802 //parse here for HW security
3803 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
3804 if (ipw->u.crypt.set_tx) {
3805 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
3806 ieee->pairwise_key_type = KEY_TYPE_CCMP;
3807 } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
3808 ieee->pairwise_key_type = KEY_TYPE_TKIP;
3809 } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
3810 if (ipw->u.crypt.key_len == 13)
3811 ieee->pairwise_key_type = KEY_TYPE_WEP104;
3812 else if (ipw->u.crypt.key_len == 5)
3813 ieee->pairwise_key_type = KEY_TYPE_WEP40;
3815 ieee->pairwise_key_type = KEY_TYPE_NA;
3818 if (ieee->pairwise_key_type) {
3819 memcpy((u8 *)key, ipw->u.crypt.key, 16);
3820 EnableHWSecurityConfig8192(dev);
3821 //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!
3823 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
3824 if (ieee->auth_mode != 2)
3825 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
3828 memcpy((u8 *)key, ipw->u.crypt.key, 16);
3829 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
3830 ieee->group_key_type = KEY_TYPE_CCMP;
3831 } else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) {
3832 ieee->group_key_type = KEY_TYPE_TKIP;
3833 } else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
3834 if (ipw->u.crypt.key_len == 13)
3835 ieee->group_key_type = KEY_TYPE_WEP104;
3836 else if (ipw->u.crypt.key_len == 5)
3837 ieee->group_key_type = KEY_TYPE_WEP40;
3839 ieee->group_key_type = KEY_TYPE_NA;
3842 if (ieee->group_key_type) {
3843 setKey(dev, ipw->u.crypt.idx,
3844 ipw->u.crypt.idx, //KeyIndex
3845 ieee->group_key_type, //KeyType
3846 broadcast_addr, //MacAddr
3852 #ifdef JOHN_HWSEC_DEBUG
3854 printk("@@ wrq->u pointer = ");
3855 for (i = 0; i < wrq->u.data.length; i++) {
3856 if (i%10 == 0) printk("\n");
3857 printk("%8x|", ((u32 *)wrq->u.data.pointer)[i]);
3860 #endif /*JOHN_HWSEC_DEBUG*/
3861 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
3875 u8 HwRateToMRate90(bool bIsHT, u8 rate)
3881 case DESC90_RATE1M: ret_rate = MGN_1M; break;
3882 case DESC90_RATE2M: ret_rate = MGN_2M; break;
3883 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
3884 case DESC90_RATE11M: ret_rate = MGN_11M; break;
3885 case DESC90_RATE6M: ret_rate = MGN_6M; break;
3886 case DESC90_RATE9M: ret_rate = MGN_9M; break;
3887 case DESC90_RATE12M: ret_rate = MGN_12M; break;
3888 case DESC90_RATE18M: ret_rate = MGN_18M; break;
3889 case DESC90_RATE24M: ret_rate = MGN_24M; break;
3890 case DESC90_RATE36M: ret_rate = MGN_36M; break;
3891 case DESC90_RATE48M: ret_rate = MGN_48M; break;
3892 case DESC90_RATE54M: ret_rate = MGN_54M; break;
3896 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
3902 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
3903 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
3904 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
3905 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
3906 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
3907 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
3908 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
3909 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
3910 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
3911 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
3912 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
3913 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
3914 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
3915 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
3916 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
3917 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
3918 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
3922 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
3931 * Function: UpdateRxPktTimeStamp
3932 * Overview: Record the TSF time stamp when receiving a packet
3940 * (pRfd->Status.TimeStampHigh is updated)
3941 * (pRfd->Status.TimeStampLow is updated)
3945 void UpdateRxPktTimeStamp8190(struct net_device *dev, struct ieee80211_rx_stats *stats)
3947 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
3949 if (stats->bIsAMPDU && !stats->bFirstMPDU) {
3950 stats->mac_time[0] = priv->LastRxDescTSFLow;
3951 stats->mac_time[1] = priv->LastRxDescTSFHigh;
3953 priv->LastRxDescTSFLow = stats->mac_time[0];
3954 priv->LastRxDescTSFHigh = stats->mac_time[1];
3960 long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
3962 long signal_power; // in dBm.
3964 // Translate to dBm (x=0.5y-95).
3965 signal_power = (long)((signal_strength_index + 1) >> 1);
3968 return signal_power;
3972 /* 2008/01/22 MH We can not declare RSSI/EVM total value of sliding window to
3973 be a local static. Otherwise, it may increase when we return from S3/S4. The
3974 value will be kept in memory or disk. Declare the value in the adaptor
3975 and it will be reinitialized when returned from S3/S4. */
3976 void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer, struct ieee80211_rx_stats *pprevious_stats, struct ieee80211_rx_stats *pcurrent_stats)
3978 bool bcheck = false;
3980 u32 nspatial_stream, tmp_val;
3981 static u32 slide_rssi_index, slide_rssi_statistics;
3982 static u32 slide_evm_index, slide_evm_statistics;
3983 static u32 last_rssi, last_evm;
3985 static u32 slide_beacon_adc_pwdb_index, slide_beacon_adc_pwdb_statistics;
3986 static u32 last_beacon_adc_pwdb;
3988 struct ieee80211_hdr_3addr *hdr;
3990 unsigned int frag, seq;
3991 hdr = (struct ieee80211_hdr_3addr *)buffer;
3992 sc = le16_to_cpu(hdr->seq_ctl);
3993 frag = WLAN_GET_SEQ_FRAG(sc);
3994 seq = WLAN_GET_SEQ_SEQ(sc);
3995 //cosa add 04292008 to record the sequence number
3996 pcurrent_stats->Seq_Num = seq;
3998 // Check whether we should take the previous packet into accounting
4000 if (!pprevious_stats->bIsAMPDU) {
4001 // if previous packet is not aggregated packet
4005 if (slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
4006 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
4007 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
4008 priv->stats.slide_rssi_total -= last_rssi;
4010 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
4012 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
4013 if (slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
4014 slide_rssi_index = 0;
4016 // <1> Showed on UI for user, in dbm
4017 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
4018 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
4019 pcurrent_stats->rssi = priv->stats.signal_strength;
4021 // If the previous packet does not match the criteria, neglect it
4023 if (!pprevious_stats->bPacketMatchBSSID) {
4024 if (!pprevious_stats->bToSelfBA)
4032 //rtl8190_process_cck_rxpathsel(priv,pprevious_stats);//only rtl8190 supported
4037 priv->stats.num_process_phyinfo++;
4039 /* record the general signal strength to the sliding window. */
4042 // <2> Showed on UI for engineering
4043 // hardware does not provide rssi information for each rf path in CCK
4044 if (!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
4045 for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++) {
4046 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
4049 //Fixed by Jacken 2008-03-20
4050 if (priv->stats.rx_rssi_percentage[rfpath] == 0)
4051 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
4052 if (pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) {
4053 priv->stats.rx_rssi_percentage[rfpath] =
4054 ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
4055 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
4056 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
4058 priv->stats.rx_rssi_percentage[rfpath] =
4059 ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
4060 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
4062 RT_TRACE(COMP_DBG, "priv->stats.rx_rssi_percentage[rfPath] = %d \n", priv->stats.rx_rssi_percentage[rfpath]);
4070 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
4071 pprevious_stats->bIsCCK ? "CCK" : "OFDM",
4072 pprevious_stats->RxPWDBAll);
4074 if (pprevious_stats->bPacketBeacon) {
4075 /* record the beacon pwdb to the sliding window. */
4076 if (slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) {
4077 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
4078 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
4079 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
4081 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
4082 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
4083 slide_beacon_adc_pwdb_index++;
4084 if (slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
4085 slide_beacon_adc_pwdb_index = 0;
4086 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
4087 if (pprevious_stats->RxPWDBAll >= 3)
4088 pprevious_stats->RxPWDBAll -= 3;
4091 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
4092 pprevious_stats->bIsCCK ? "CCK" : "OFDM",
4093 pprevious_stats->RxPWDBAll);
4096 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4097 if (priv->undecorated_smoothed_pwdb < 0) // initialize
4098 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
4099 if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
4100 priv->undecorated_smoothed_pwdb =
4101 (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4102 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4103 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
4105 priv->undecorated_smoothed_pwdb =
4106 (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
4107 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
4115 /* record the general EVM to the sliding window. */
4116 if (pprevious_stats->SignalQuality) {
4117 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4118 if (slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
4119 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
4120 last_evm = priv->stats.slide_evm[slide_evm_index];
4121 priv->stats.slide_evm_total -= last_evm;
4124 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
4126 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
4127 if (slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
4128 slide_evm_index = 0;
4130 // <1> Showed on UI for user, in percentage.
4131 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
4132 priv->stats.signal_quality = tmp_val;
4133 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
4134 priv->stats.last_signal_strength_inpercent = tmp_val;
4137 // <2> Showed on UI for engineering
4138 if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
4139 for (nspatial_stream = 0; nspatial_stream < 2; nspatial_stream++) { // 2 spatial stream
4140 if (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) {
4141 if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
4142 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
4143 priv->stats.rx_evm_percentage[nspatial_stream] =
4144 ((priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
4145 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
4154 /*-----------------------------------------------------------------------------
4155 * Function: rtl819x_query_rxpwrpercentage()
4159 * Input: char antpower
4163 * Return: 0-100 percentage
4167 * 05/26/2008 amy Create Version 0 porting from windows code.
4169 *---------------------------------------------------------------------------*/
4170 static u8 rtl819x_query_rxpwrpercentage(char antpower)
4172 if ((antpower <= -100) || (antpower >= 20))
4174 else if (antpower >= 0)
4177 return 100 + antpower;
4179 } /* QueryRxPwrPercentage */
4181 static u8 rtl819x_evm_dbtopercentage(char value)
4191 ret_val = 0 - ret_val;
4199 // We want good-looking for signal strength/quality
4200 // 2007/7/19 01:09, by cosa.
4202 long rtl819x_signal_scale_mapping(long currsig)
4206 // Step 1. Scale mapping.
4207 if (currsig >= 61 && currsig <= 100)
4208 retsig = 90 + ((currsig - 60) / 4);
4209 else if (currsig >= 41 && currsig <= 60)
4210 retsig = 78 + ((currsig - 40) / 2);
4211 else if (currsig >= 31 && currsig <= 40)
4212 retsig = 66 + (currsig - 30);
4213 else if (currsig >= 21 && currsig <= 30)
4214 retsig = 54 + (currsig - 20);
4215 else if (currsig >= 5 && currsig <= 20)
4216 retsig = 42 + (((currsig - 5) * 2) / 3);
4217 else if (currsig == 4)
4219 else if (currsig == 3)
4221 else if (currsig == 2)
4223 else if (currsig == 1)
4231 static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
4232 struct ieee80211_rx_stats *pstats,
4233 rx_drvinfo_819x_usb *pdrvinfo,
4234 struct ieee80211_rx_stats *precord_stats,
4235 bool bpacket_match_bssid,
4236 bool bpacket_toself,
4240 phy_sts_ofdm_819xusb_t *pofdm_buf;
4241 phy_sts_cck_819xusb_t *pcck_buf;
4242 phy_ofdm_rx_status_rxsc_sgien_exintfflag *prxsc;
4244 u8 i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
4245 char rx_pwr[4], rx_pwr_all = 0;
4246 char rx_snrX, rx_evmX;
4248 u32 RSSI, total_rssi = 0;
4254 priv->stats.numqry_phystatus++;
4256 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
4258 // Record it for next packet processing
4259 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
4260 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
4261 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
4262 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;
4263 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
4264 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
4266 prxpkt = (u8 *)pdrvinfo;
4268 /* Move pointer to the 16th bytes. Phy status start address. */
4269 prxpkt += sizeof(rx_drvinfo_819x_usb);
4271 /* Initial the cck and ofdm buffer pointer */
4272 pcck_buf = (phy_sts_cck_819xusb_t *)prxpkt;
4273 pofdm_buf = (phy_sts_ofdm_819xusb_t *)prxpkt;
4275 pstats->RxMIMOSignalQuality[0] = -1;
4276 pstats->RxMIMOSignalQuality[1] = -1;
4277 precord_stats->RxMIMOSignalQuality[0] = -1;
4278 precord_stats->RxMIMOSignalQuality[1] = -1;
4282 // (1)Hardware does not provide RSSI for CCK
4286 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
4290 priv->stats.numqry_phystatusCCK++;
4292 if (!priv->bCckHighPower) {
4293 report = pcck_buf->cck_agc_rpt & 0xc0;
4296 //Fixed by Jacken from Bryant 2008-03-20
4297 //Original value is -38 , -26 , -14 , -2
4298 //Fixed value is -35 , -23 , -11 , 6
4300 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
4303 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
4306 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
4309 rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
4313 report = pcck_buf->cck_agc_rpt & 0x60;
4317 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4320 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4323 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4326 rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
4331 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
4332 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
4333 pstats->RecvSignalPower = pwdb_all;
4336 // (3) Get Signal Quality (EVM)
4339 if (pstats->RxPWDBAll > 40) {
4342 sq = pcck_buf->sq_rpt;
4344 if (pcck_buf->sq_rpt > 64)
4346 else if (pcck_buf->sq_rpt < 20)
4349 sq = ((64-sq) * 100) / 44;
4351 pstats->SignalQuality = precord_stats->SignalQuality = sq;
4352 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
4353 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
4356 priv->stats.numqry_phystatusHT++;
4358 // (1)Get RSSI for HT rate
4360 for (i = RF90_PATH_A; i < priv->NumTotalRFPath; i++) {
4361 // 2008/01/30 MH we will judge RF RX path now.
4362 if (priv->brfpath_rxenable[i])
4367 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
4370 //Fixed by Jacken from Bryant 2008-03-20
4371 //Original value is 106
4372 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
4374 //Get Rx snr value in DB
4375 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
4376 rx_snrX = (char)(tmp_rxsnr);
4378 priv->stats.rxSNRdB[i] = (long)rx_snrX;
4380 /* Translate DBM to percentage. */
4381 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
4384 /* Record Signal Strength for next packet */
4385 pstats->RxMIMOSignalStrength[i] = (u8) RSSI;
4386 precord_stats->RxMIMOSignalStrength[i] = (u8) RSSI;
4391 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
4393 //Fixed by Jacken from Bryant 2008-03-20
4394 //Original value is 106
4395 rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1)& 0x7f) -106;
4396 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
4398 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
4399 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
4402 // (3)EVM of HT rate
4404 if (pdrvinfo->RxHT && pdrvinfo->RxRate >= DESC90_RATEMCS8 &&
4405 pdrvinfo->RxRate <= DESC90_RATEMCS15)
4406 max_spatial_stream = 2; //both spatial stream make sense
4408 max_spatial_stream = 1; //only spatial stream 1 makes sense
4410 for (i = 0; i < max_spatial_stream; i++) {
4411 tmp_rxevm = pofdm_buf->rxevm_X[i];
4412 rx_evmX = (char)(tmp_rxevm);
4414 // Do not use shift operation like "rx_evmX >>= 1" because the compiler of free build environment
4415 // will set the most significant bit to "zero" when doing shifting operation which may change a negative
4416 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
4419 evm = rtl819x_evm_dbtopercentage(rx_evmX);
4420 if (i == 0) // Fill value in RFD, Get the first spatial stream only
4421 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
4422 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
4426 /* record rx statistics for debug */
4427 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
4428 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
4429 if (pdrvinfo->BW) //40M channel
4430 priv->stats.received_bwtype[1+prxsc->rxsc]++;
4432 priv->stats.received_bwtype[0]++;
4435 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
4436 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
4438 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
4440 // We can judge RX path number now.
4442 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
4444 } /* QueryRxPhyStatus8190Pci */
4446 void rtl8192_record_rxdesc_forlateruse(struct ieee80211_rx_stats *psrc_stats,
4447 struct ieee80211_rx_stats *ptarget_stats)
4449 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
4450 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
4451 ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
4455 void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
4456 struct ieee80211_rx_stats *pstats,
4457 rx_drvinfo_819x_usb *pdrvinfo)
4459 // TODO: We must only check packet for current MAC address. Not finish
4460 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4461 struct net_device *dev = info->dev;
4462 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4463 bool bpacket_match_bssid, bpacket_toself;
4464 bool bPacketBeacon = FALSE, bToSelfBA = FALSE;
4465 static struct ieee80211_rx_stats previous_stats;
4466 struct ieee80211_hdr_3addr *hdr;//by amy
4469 // Get Signal Quality for only RX data queue (but not command queue)
4474 /* Get MAC frame start address. */
4475 tmp_buf = (u8 *)skb->data;
4477 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
4478 fc = le16_to_cpu(hdr->frame_ctl);
4479 type = WLAN_FC_GET_TYPE(fc);
4480 praddr = hdr->addr1;
4482 /* Check if the received packet is acceptable. */
4483 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
4484 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
4485 && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV));
4486 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
4488 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
4489 bPacketBeacon = true;
4490 if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) {
4491 if ((eqMacAddr(praddr, dev->dev_addr)))
4497 if (bpacket_match_bssid)
4498 priv->stats.numpacket_matchbssid++;
4500 priv->stats.numpacket_toself++;
4502 // Process PHY information for previous packet (RSSI/PWDB/EVM)
4504 // Because phy information is contained in the last packet of AMPDU only, so driver
4505 // should process phy information of previous packet
4506 rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
4507 rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid, bpacket_toself, bPacketBeacon, bToSelfBA);
4508 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
4513 * Function: UpdateReceivedRateHistogramStatistics
4514 * Overview: Record the received data rate
4517 * struct net_device *dev
4518 * struct ieee80211_rx_stats *stats
4522 * (priv->stats.ReceivedRateHistogram[] is updated)
4526 void UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
4527 struct ieee80211_rx_stats *stats)
4529 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4530 u32 rcvType = 1; //0: Total, 1:OK, 2:CRC, 3:ICV
4532 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
4537 else if (stats->bICV)
4540 if (stats->bShortPreamble)
4541 preamble_guardinterval = 1;// short
4543 preamble_guardinterval = 0;// long
4545 switch (stats->rate) {
4549 case MGN_1M: rateIndex = 0; break;
4550 case MGN_2M: rateIndex = 1; break;
4551 case MGN_5_5M: rateIndex = 2; break;
4552 case MGN_11M: rateIndex = 3; break;
4556 case MGN_6M: rateIndex = 4; break;
4557 case MGN_9M: rateIndex = 5; break;
4558 case MGN_12M: rateIndex = 6; break;
4559 case MGN_18M: rateIndex = 7; break;
4560 case MGN_24M: rateIndex = 8; break;
4561 case MGN_36M: rateIndex = 9; break;
4562 case MGN_48M: rateIndex = 10; break;
4563 case MGN_54M: rateIndex = 11; break;
4565 // 11n High throughput rate
4567 case MGN_MCS0: rateIndex = 12; break;
4568 case MGN_MCS1: rateIndex = 13; break;
4569 case MGN_MCS2: rateIndex = 14; break;
4570 case MGN_MCS3: rateIndex = 15; break;
4571 case MGN_MCS4: rateIndex = 16; break;
4572 case MGN_MCS5: rateIndex = 17; break;
4573 case MGN_MCS6: rateIndex = 18; break;
4574 case MGN_MCS7: rateIndex = 19; break;
4575 case MGN_MCS8: rateIndex = 20; break;
4576 case MGN_MCS9: rateIndex = 21; break;
4577 case MGN_MCS10: rateIndex = 22; break;
4578 case MGN_MCS11: rateIndex = 23; break;
4579 case MGN_MCS12: rateIndex = 24; break;
4580 case MGN_MCS13: rateIndex = 25; break;
4581 case MGN_MCS14: rateIndex = 26; break;
4582 case MGN_MCS15: rateIndex = 27; break;
4583 default: rateIndex = 28; break;
4585 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
4586 priv->stats.received_rate_histogram[0][rateIndex]++; //total
4587 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
4591 void query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats, bool bIsRxAggrSubframe)
4593 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4594 struct net_device *dev = info->dev;
4595 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4596 rx_drvinfo_819x_usb *driver_info = NULL;
4599 //Get Rx Descriptor Information
4601 #ifdef USB_RX_AGGREGATION_SUPPORT
4602 if (bIsRxAggrSubframe) {
4603 rx_desc_819x_usb_aggr_subframe *desc = (rx_desc_819x_usb_aggr_subframe *)skb->data;
4604 stats->Length = desc->Length;
4605 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
4606 stats->RxBufShift = 0; //RxBufShift = 2 in RxDesc, but usb didn't shift bytes in fact.
4607 stats->bICV = desc->ICV;
4608 stats->bCRC = desc->CRC32;
4609 stats->bHwError = stats->bCRC|stats->bICV;
4610 stats->Decrypted = !desc->SWDec;//RTL8190 set this bit to indicate that Hw does not decrypt packet
4614 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
4616 stats->Length = desc->Length;
4617 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
4618 stats->RxBufShift = 0;
4619 stats->bICV = desc->ICV;
4620 stats->bCRC = desc->CRC32;
4621 stats->bHwError = stats->bCRC|stats->bICV;
4622 //RTL8190 set this bit to indicate that Hw does not decrypt packet
4623 stats->Decrypted = !desc->SWDec;
4626 if ((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
4627 stats->bHwError = false;
4629 stats->bHwError = stats->bCRC|stats->bICV;
4631 if (stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
4632 stats->bHwError |= 1;
4636 // TODO: Need to verify it on FGPA platform
4637 //Driver info are written to the RxBuffer following rx desc
4638 if (stats->RxDrvInfoSize != 0) {
4639 driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) +
4643 if (!stats->bHwError) {
4645 ret_rate = HwRateToMRate90(driver_info->RxHT, driver_info->RxRate);
4646 if (ret_rate == 0xff) {
4647 // Abnormal Case: Receive CRC OK packet with Rx descriptor indicating non supported rate.
4648 // Special Error Handling here, 2008.05.16, by Emily
4650 stats->bHwError = 1;
4651 stats->rate = MGN_1M; //Set 1M rate by default
4653 stats->rate = ret_rate;
4659 stats->bShortPreamble = driver_info->SPLCP;
4662 UpdateReceivedRateHistogramStatistics8190(dev, stats);
4664 stats->bIsAMPDU = (driver_info->PartAggr == 1);
4665 stats->bFirstMPDU = (driver_info->PartAggr == 1) && (driver_info->FirstAGGR == 1);
4666 stats->TimeStampLow = driver_info->TSFL;
4667 // xiong mask it, 070514
4669 UpdateRxPktTimeStamp8190(dev, stats);
4674 if (driver_info->FirstAGGR == 1 || driver_info->PartAggr == 1)
4675 RT_TRACE(COMP_RXDESC, "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
4676 driver_info->FirstAGGR, driver_info->PartAggr);
4680 skb_pull(skb, sizeof(rx_desc_819x_usb));
4682 // Get Total offset of MPDU Frame Body
4684 if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
4686 skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
4689 #ifdef USB_RX_AGGREGATION_SUPPORT
4690 /* for the rx aggregated sub frame, the redundant space truly contained in the packet */
4691 if (bIsRxAggrSubframe)
4694 /* for debug 2008.5.29 */
4696 //added by vivi, for MP, 20080108
4697 stats->RxIs40MHzPacket = driver_info->BW;
4698 if (stats->RxDrvInfoSize != 0)
4699 TranslateRxSignalStuff819xUsb(skb, stats, driver_info);
4703 u32 GetRxPacketShiftBytes819xUsb(struct ieee80211_rx_stats *Status, bool bIsRxAggrSubframe)
4705 #ifdef USB_RX_AGGREGATION_SUPPORT
4706 if (bIsRxAggrSubframe)
4707 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
4708 + Status->RxBufShift + 8);
4711 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
4712 + Status->RxBufShift);
4715 void rtl8192_rx_nomal(struct sk_buff *skb)
4717 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4718 struct net_device *dev = info->dev;
4719 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4720 struct ieee80211_rx_stats stats = {
4724 .freq = IEEE80211_24GHZ_BAND,
4727 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
4728 bool unicast_packet = false;
4729 #ifdef USB_RX_AGGREGATION_SUPPORT
4730 struct sk_buff *agg_skb = NULL;
4731 u32 TotalLength = 0;
4733 u32 PacketLength = 0;
4734 u32 PacketOccupiedLendth = 0;
4736 u32 PacketShiftBytes = 0;
4737 rx_desc_819x_usb_aggr_subframe *RxDescr = NULL;
4738 u8 PaddingBytes = 0;
4739 //add just for testing
4744 /* 20 is for ps-poll */
4745 if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
4746 #ifdef USB_RX_AGGREGATION_SUPPORT
4747 TempByte = *(skb->data + sizeof(rx_desc_819x_usb));
4749 /* first packet should not contain Rx aggregation header */
4750 query_rxdesc_status(skb, &stats, false);
4752 /* hardware related info */
4753 #ifdef USB_RX_AGGREGATION_SUPPORT
4754 if (TempByte & BIT0) {
4756 TotalLength = stats.Length - 4; /*sCrcLng*/
4757 /* though the head pointer has passed this position */
4758 TempDWord = *(u32 *)(agg_skb->data - 4);
4759 PacketLength = (u16)(TempDWord & 0x3FFF); /*sCrcLng*/
4760 skb = dev_alloc_skb(PacketLength);
4761 memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
4762 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false);
4765 /* Process the MPDU received */
4766 skb_trim(skb, skb->len - 4/*sCrcLng*/);
4768 rx_pkt_len = skb->len;
4769 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
4770 unicast_packet = false;
4771 if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
4773 } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
4776 /* unicast packet */
4777 unicast_packet = true;
4780 if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
4781 dev_kfree_skb_any(skb);
4783 priv->stats.rxoktotal++;
4785 priv->stats.rxbytesunicast += rx_pkt_len;
4787 #ifdef USB_RX_AGGREGATION_SUPPORT
4789 if (TotalLength > 0) {
4790 PacketOccupiedLendth = PacketLength + (PacketShiftBytes + 8);
4791 if ((PacketOccupiedLendth & 0xFF) != 0)
4792 PacketOccupiedLendth = (PacketOccupiedLendth & 0xFFFFFF00) + 256;
4793 PacketOccupiedLendth -= 8;
4794 TempDWord = PacketOccupiedLendth - PacketShiftBytes; /*- PacketLength */
4795 if (agg_skb->len > TempDWord)
4796 skb_pull(agg_skb, TempDWord);
4800 while (agg_skb->len >= GetRxPacketShiftBytes819xUsb(&stats, true)) {
4801 u8 tmpCRC = 0, tmpICV = 0;
4802 RxDescr = (rx_desc_819x_usb_aggr_subframe *)(agg_skb->data);
4803 tmpCRC = RxDescr->CRC32;
4804 tmpICV = RxDescr->ICV;
4805 memcpy(agg_skb->data, &agg_skb->data[44], 2);
4806 RxDescr->CRC32 = tmpCRC;
4807 RxDescr->ICV = tmpICV;
4809 memset(&stats, 0, sizeof(struct ieee80211_rx_stats));
4813 stats.freq = IEEE80211_24GHZ_BAND;
4814 query_rxdesc_status(agg_skb, &stats, true);
4815 PacketLength = stats.Length;
4817 if (PacketLength > agg_skb->len)
4819 /* Process the MPDU received */
4820 skb = dev_alloc_skb(PacketLength);
4821 memcpy(skb_put(skb, PacketLength), agg_skb->data, PacketLength);
4822 skb_trim(skb, skb->len - 4/*sCrcLng*/);
4824 rx_pkt_len = skb->len;
4825 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
4826 unicast_packet = false;
4827 if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
4829 } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
4832 /* unicast packet */
4833 unicast_packet = true;
4835 if (!ieee80211_rx(priv->ieee80211, skb, &stats)) {
4836 dev_kfree_skb_any(skb);
4838 priv->stats.rxoktotal++;
4840 priv->stats.rxbytesunicast += rx_pkt_len;
4842 /* should trim the packet which has been copied to target skb */
4843 skb_pull(agg_skb, PacketLength);
4844 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, true);
4845 PacketOccupiedLendth = PacketLength + PacketShiftBytes;
4846 if ((PacketOccupiedLendth & 0xFF) != 0) {
4847 PaddingBytes = 256 - (PacketOccupiedLendth & 0xFF);
4848 if (agg_skb->len > PaddingBytes)
4849 skb_pull(agg_skb, PaddingBytes);
4854 dev_kfree_skb(agg_skb);
4858 priv->stats.rxurberr++;
4859 netdev_dbg(dev, "actual_length: %d\n", skb->len);
4860 dev_kfree_skb_any(skb);
4865 void rtl819xusb_process_received_packet(struct net_device *dev,
4866 struct ieee80211_rx_stats *pstats)
4870 struct r8192_priv *priv = ieee80211_priv(dev);
4872 // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
4873 //porting by amy 080508
4874 pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
4875 frame = pstats->virtual_address;
4876 frame_len = pstats->packetlength;
4877 #ifdef TODO // by amy about HCT
4878 if (!Adapter->bInHctTest)
4879 CountRxErrStatistics(Adapter, pRfd);
4881 #ifdef ENABLE_PS //by amy for adding ps function in future
4882 RT_RF_POWER_STATE rtState;
4883 // When RF is off, we should not count the packet for hw/sw synchronize
4884 // reason, ie. there may be a duration while sw switch is changed and hw
4885 // switch is being changed. 2006.12.04, by shien chang.
4886 Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8 *)(&rtState));
4887 if (rtState == eRfOff)
4890 priv->stats.rxframgment++;
4893 RmMonitorSignalStrength(Adapter, pRfd);
4895 /* 2007/01/16 MH Add RX command packet handle here. */
4896 /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
4897 if (rtl819xusb_rx_command_packet(dev, pstats))
4907 void query_rx_cmdpkt_desc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats)
4909 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
4912 //Get Rx Descriptor Information
4914 stats->virtual_address = (u8 *)skb->data;
4915 stats->Length = desc->Length;
4916 stats->RxDrvInfoSize = 0;
4917 stats->RxBufShift = 0;
4918 stats->packetlength = stats->Length-scrclng;
4919 stats->fraglength = stats->packetlength;
4920 stats->fragoffset = 0;
4921 stats->ntotalfrag = 1;
4925 void rtl8192_rx_cmd(struct sk_buff *skb)
4927 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
4928 struct net_device *dev = info->dev;
4930 struct ieee80211_rx_stats stats = {
4934 .freq = IEEE80211_24GHZ_BAND,
4937 if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
4939 query_rx_cmdpkt_desc_status(skb, &stats);
4940 // this is to be done by amy 080508 prfd->queue_id = 1;
4944 // Process the command packet received.
4947 rtl819xusb_process_received_packet(dev, &stats);
4949 dev_kfree_skb_any(skb);
4953 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
4955 struct sk_buff *skb;
4956 struct rtl8192_rx_info *info;
4958 while (NULL != (skb = skb_dequeue(&priv->skb_queue))) {
4959 info = (struct rtl8192_rx_info *)skb->cb;
4960 switch (info->out_pipe) {
4961 /* Nomal packet pipe */
4963 priv->IrpPendingCount--;
4964 rtl8192_rx_nomal(skb);
4967 /* Command packet pipe */
4969 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",
4972 rtl8192_rx_cmd(skb);
4975 default: /* should never get here! */
4976 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",
4985 static const struct net_device_ops rtl8192_netdev_ops = {
4986 .ndo_open = rtl8192_open,
4987 .ndo_stop = rtl8192_close,
4988 .ndo_get_stats = rtl8192_stats,
4989 .ndo_tx_timeout = tx_timeout,
4990 .ndo_do_ioctl = rtl8192_ioctl,
4991 .ndo_set_rx_mode = r8192_set_multicast,
4992 .ndo_set_mac_address = r8192_set_mac_adr,
4993 .ndo_validate_addr = eth_validate_addr,
4994 .ndo_change_mtu = eth_change_mtu,
4995 .ndo_start_xmit = ieee80211_xmit,
4999 /****************************************************************************
5000 ---------------------------- USB_STUFF---------------------------
5001 *****************************************************************************/
5003 static int rtl8192_usb_probe(struct usb_interface *intf,
5004 const struct usb_device_id *id)
5006 struct net_device *dev = NULL;
5007 struct r8192_priv *priv = NULL;
5008 struct usb_device *udev = interface_to_usbdev(intf);
5010 RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
5012 dev = alloc_ieee80211(sizeof(struct r8192_priv));
5016 usb_set_intfdata(intf, dev);
5017 SET_NETDEV_DEV(dev, &intf->dev);
5018 priv = ieee80211_priv(dev);
5019 priv->ieee80211 = netdev_priv(dev);
5022 dev->netdev_ops = &rtl8192_netdev_ops;
5024 #if WIRELESS_EXT >= 12
5025 #if WIRELESS_EXT < 17
5026 dev->get_wireless_stats = r8192_get_wireless_stats;
5028 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
5030 dev->type = ARPHRD_ETHER;
5032 dev->watchdog_timeo = HZ*3; //modified by john, 0805
5034 if (dev_alloc_name(dev, ifname) < 0) {
5035 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
5037 dev_alloc_name(dev, ifname);
5040 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
5041 if (rtl8192_init(dev) != 0) {
5042 RT_TRACE(COMP_ERR, "Initialization failed");
5046 netif_carrier_off(dev);
5047 netif_stop_queue(dev);
5049 ret = register_netdev(dev);
5053 RT_TRACE(COMP_INIT, "dev name=======> %s\n", dev->name);
5054 rtl8192_proc_init_one(dev);
5057 RT_TRACE(COMP_INIT, "Driver probe completed\n");
5062 kfree(priv->pFirmware);
5063 priv->pFirmware = NULL;
5064 rtl8192_usb_deleteendpoints(dev);
5065 destroy_workqueue(priv->priv_wq);
5068 free_ieee80211(dev);
5070 RT_TRACE(COMP_ERR, "wlan driver load failed\n");
5074 //detach all the work and timer structure declared or inititialize in r8192U_init function.
5075 void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
5078 cancel_work_sync(&priv->reset_wq);
5079 cancel_delayed_work(&priv->watch_dog_wq);
5080 cancel_delayed_work(&priv->update_beacon_wq);
5081 cancel_work_sync(&priv->qos_activate);
5085 static void rtl8192_usb_disconnect(struct usb_interface *intf)
5087 struct net_device *dev = usb_get_intfdata(intf);
5089 struct r8192_priv *priv = ieee80211_priv(dev);
5092 unregister_netdev(dev);
5094 RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
5095 rtl8192_proc_remove_one(dev);
5098 kfree(priv->pFirmware);
5099 priv->pFirmware = NULL;
5100 rtl8192_usb_deleteendpoints(dev);
5101 destroy_workqueue(priv->priv_wq);
5105 free_ieee80211(dev);
5106 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
5109 /* fun with the built-in ieee80211 stack... */
5110 extern int ieee80211_debug_init(void);
5111 extern void ieee80211_debug_exit(void);
5112 extern int ieee80211_crypto_init(void);
5113 extern void ieee80211_crypto_deinit(void);
5114 extern int ieee80211_crypto_tkip_init(void);
5115 extern void ieee80211_crypto_tkip_exit(void);
5116 extern int ieee80211_crypto_ccmp_init(void);
5117 extern void ieee80211_crypto_ccmp_exit(void);
5118 extern int ieee80211_crypto_wep_init(void);
5119 extern void ieee80211_crypto_wep_exit(void);
5121 static int __init rtl8192_usb_module_init(void)
5125 #ifdef CONFIG_IEEE80211_DEBUG
5126 ret = ieee80211_debug_init();
5128 pr_err("ieee80211_debug_init() failed %d\n", ret);
5132 ret = ieee80211_crypto_init();
5134 pr_err("ieee80211_crypto_init() failed %d\n", ret);
5138 ret = ieee80211_crypto_tkip_init();
5140 pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
5144 ret = ieee80211_crypto_ccmp_init();
5146 pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
5150 ret = ieee80211_crypto_wep_init();
5152 pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
5156 pr_info("\nLinux kernel driver for RTL8192 based WLAN cards\n");
5157 pr_info("Copyright (c) 2007-2008, Realsil Wlan\n");
5158 RT_TRACE(COMP_INIT, "Initializing module");
5159 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
5160 rtl8192_proc_module_init();
5161 return usb_register(&rtl8192_usb_driver);
5165 static void __exit rtl8192_usb_module_exit(void)
5167 usb_deregister(&rtl8192_usb_driver);
5169 RT_TRACE(COMP_DOWN, "Exiting");
5173 void rtl8192_try_wake_queue(struct net_device *dev, int pri)
5175 unsigned long flags;
5177 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5179 spin_lock_irqsave(&priv->tx_lock, flags);
5180 enough_desc = check_nic_enough_desc(dev, pri);
5181 spin_unlock_irqrestore(&priv->tx_lock, flags);
5184 ieee80211_wake_queue(priv->ieee80211);
5187 void EnableHWSecurityConfig8192(struct net_device *dev)
5189 u8 SECR_value = 0x0;
5190 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5191 struct ieee80211_device *ieee = priv->ieee80211;
5192 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
5193 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) {
5194 SECR_value |= SCR_RxUseDK;
5195 SECR_value |= SCR_TxUseDK;
5196 } else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) {
5197 SECR_value |= SCR_RxUseDK;
5198 SECR_value |= SCR_TxUseDK;
5200 //add HWSec active enable here.
5201 //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
5203 ieee->hwsec_active = 1;
5205 if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep) { //add hwsec_support flag to totol control hw_sec on/off
5206 ieee->hwsec_active = 0;
5207 SECR_value &= ~SCR_RxDecEnable;
5209 RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __func__,
5210 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
5211 write_nic_byte(dev, SECR, SECR_value);
5215 void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
5216 u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
5218 u32 TargetCommand = 0;
5219 u32 TargetContent = 0;
5222 if (EntryNo >= TOTAL_CAM_ENTRY)
5223 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
5225 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev, EntryNo, KeyIndex, KeyType, MacAddr);
5228 usConfig |= BIT15 | (KeyType<<2);
5230 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
5233 for (i = 0; i < CAM_CONTENT_COUNT; i++) {
5234 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
5235 TargetCommand |= BIT31|BIT16;
5237 if (i == 0) { //MAC|Config
5238 TargetContent = (u32)(*(MacAddr+0)) << 16|
5239 (u32)(*(MacAddr+1)) << 24|
5242 write_nic_dword(dev, WCAMI, TargetContent);
5243 write_nic_dword(dev, RWCAM, TargetCommand);
5244 } else if (i == 1) { //MAC
5245 TargetContent = (u32)(*(MacAddr+2)) |
5246 (u32)(*(MacAddr+3)) << 8|
5247 (u32)(*(MacAddr+4)) << 16|
5248 (u32)(*(MacAddr+5)) << 24;
5249 write_nic_dword(dev, WCAMI, TargetContent);
5250 write_nic_dword(dev, RWCAM, TargetCommand);
5253 if (KeyContent != NULL) {
5254 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)));
5255 write_nic_dword(dev, RWCAM, TargetCommand);
5262 /***************************************************************************
5263 ------------------- module init / exit stubs ----------------
5264 ****************************************************************************/
5265 module_init(rtl8192_usb_module_init);
5266 module_exit(rtl8192_usb_module_exit);