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>
32 #undef RX_DONT_PASS_UL
34 #undef DEBUG_RX_VERBOSE
40 #undef DEBUG_TX_FILLDESC
45 #undef DEBUG_REGISTERS
47 #undef DEBUG_IRQ_TASKLET
51 #define CONFIG_RTL8192_IO_MAP
53 #include <asm/uaccess.h>
55 #include "r8180_93cx6.h" /* Card EEPROM */
56 #include "r8192U_wx.h"
58 #include "r8192S_rtl8225.h"
59 #include "r8192S_hw.h"
60 #include "r8192S_phy.h"
61 #include "r8192S_phyreg.h"
62 #include "r8192S_Efuse.h"
64 #include "r819xU_cmdpkt.h"
65 #include "r8192U_dm.h"
66 //#include "r8192xU_phyreg.h"
67 #include <linux/usb.h>
69 #include "r8192U_pm.h"
71 #include "ieee80211/dot11d.h"
75 u32 rt_global_debug_component = \
107 COMP_ERR; //always open err flags on
109 #define TOTAL_CAM_ENTRY 32
110 #define CAM_CONTENT_COUNT 8
112 static struct usb_device_id rtl8192_usb_id_tbl[] = {
114 {USB_DEVICE(0x0bda, 0x8192)},
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(0x0bda, 0x8172)},
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(hwseqnum,int, S_IRUGO|S_IWUSR);
146 module_param(hwwep,int, S_IRUGO|S_IWUSR);
147 module_param(channels,int, S_IRUGO|S_IWUSR);
149 MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
150 //MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
151 MODULE_PARM_DESC(hwwep," Try to use hardware security support. ");
152 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
154 static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
155 const struct usb_device_id *id);
156 static void __devexit rtl8192_usb_disconnect(struct usb_interface *intf);
158 static struct usb_driver rtl8192_usb_driver = {
159 .name = RTL819xU_MODULE_NAME, /* Driver name */
160 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
161 .probe = rtl8192_usb_probe, /* probe fn */
162 .disconnect = rtl8192_usb_disconnect, /* remove fn */
163 .suspend = rtl8192U_suspend, /* PM suspend fn */
164 .resume = rtl8192U_resume, /* PM resume fn */
165 .reset_resume = rtl8192U_resume, /* PM reset resume fn */
169 static void rtl8192SU_read_eeprom_info(struct net_device *dev);
170 short rtl8192SU_tx(struct net_device *dev, struct sk_buff* skb);
171 void rtl8192SU_rx_nomal(struct sk_buff* skb);
172 void rtl8192SU_rx_cmd(struct sk_buff *skb);
173 bool rtl8192SU_adapter_start(struct net_device *dev);
174 short rtl8192SU_tx_cmd(struct net_device *dev, struct sk_buff *skb);
175 void rtl8192SU_link_change(struct net_device *dev);
176 void InitialGain8192S(struct net_device *dev,u8 Operation);
177 void rtl8192SU_query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats, bool bIsRxAggrSubframe);
179 struct rtl819x_ops rtl8192su_ops = {
180 .nic_type = NIC_8192SU,
181 .rtl819x_read_eeprom_info = rtl8192SU_read_eeprom_info,
182 .rtl819x_tx = rtl8192SU_tx,
183 .rtl819x_tx_cmd = rtl8192SU_tx_cmd,
184 .rtl819x_rx_nomal = rtl8192SU_rx_nomal,
185 .rtl819x_rx_cmd = rtl8192SU_rx_cmd,
186 .rtl819x_adapter_start = rtl8192SU_adapter_start,
187 .rtl819x_link_change = rtl8192SU_link_change,
188 .rtl819x_initial_gain = InitialGain8192S,
189 .rtl819x_query_rxdesc_status = rtl8192SU_query_rxdesc_status,
193 typedef struct _CHANNEL_LIST
197 }CHANNEL_LIST, *PCHANNEL_LIST;
199 static CHANNEL_LIST ChannelPlan[] = {
200 {{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
201 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
202 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
203 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
204 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
205 {{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
206 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
207 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
208 {{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
209 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
210 {{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
213 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
215 int i, max_chan=-1, min_chan=-1;
216 struct ieee80211_device* ieee = priv->ieee80211;
217 switch (channel_plan)
219 case COUNTRY_CODE_FCC:
220 case COUNTRY_CODE_IC:
221 case COUNTRY_CODE_ETSI:
222 case COUNTRY_CODE_SPAIN:
223 case COUNTRY_CODE_FRANCE:
224 case COUNTRY_CODE_MKK:
225 case COUNTRY_CODE_MKK1:
226 case COUNTRY_CODE_ISRAEL:
227 case COUNTRY_CODE_TELEC:
228 case COUNTRY_CODE_MIC:
231 ieee->bGlobalDomain = false;
232 //acturally 8225 & 8256 rf chip only support B,G,24N mode
233 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256) || (priv->rf_chip == RF_6052))
240 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
242 if (ChannelPlan[channel_plan].Len != 0){
243 // Clear old channel map
244 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
245 // Set new channel map
246 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
248 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
250 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
255 case COUNTRY_CODE_GLOBAL_DOMAIN:
257 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
259 ieee->bGlobalDomain = true;
268 #define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 )
270 #define rx_hal_is_cck_rate(_pDesc)\
271 ((_pDesc->RxMCS == DESC92S_RATE1M ||\
272 _pDesc->RxMCS == DESC92S_RATE2M ||\
273 _pDesc->RxMCS == DESC92S_RATE5_5M ||\
274 _pDesc->RxMCS == DESC92S_RATE11M) &&\
277 #define tx_hal_is_cck_rate(_DataRate)\
278 ( _DataRate == MGN_1M ||\
279 _DataRate == MGN_2M ||\
280 _DataRate == MGN_5_5M ||\
281 _DataRate == MGN_11M )
286 void CamResetAllEntry(struct net_device *dev)
290 //2004/02/11 In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
291 // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
292 // In this condition, Cam can not be reset because upper layer will not set this static key again.
293 //if(Adapter->EncAlgorithm == WEP_Encryption)
296 //DbgPrint("========================================\n");
297 //DbgPrint(" Call ResetAllEntry \n");
298 //DbgPrint("========================================\n\n");
299 ulcommand |= BIT31|BIT30;
300 write_nic_dword(dev, RWCAM, ulcommand);
302 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
303 CAM_mark_invalid(dev, ucIndex);
304 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
305 CAM_empty_entry(dev, ucIndex);
311 void write_cam(struct net_device *dev, u8 addr, u32 data)
313 write_nic_dword(dev, WCAMI, data);
314 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
317 u32 read_cam(struct net_device *dev, u8 addr)
319 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
320 return read_nic_dword(dev, 0xa8);
323 void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
326 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
327 struct usb_device *udev = priv->udev;
329 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
330 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
331 indx|0xfe00, 0, &data, 1, HZ / 2);
335 printk("write_nic_byte_E TimeOut! status:%d\n", status);
339 u8 read_nic_byte_E(struct net_device *dev, int indx)
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_rcvctrlpipe(udev, 0),
347 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
348 indx|0xfe00, 0, &data, 1, HZ / 2);
352 printk("read_nic_byte_E TimeOut! status:%d\n", status);
357 //as 92U has extend page from 4 to 16, so modify functions below.
358 void write_nic_byte(struct net_device *dev, int indx, u8 data)
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_sndctrlpipe(udev, 0),
366 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
367 indx, 0, &data, 1, HZ / 2);
371 printk("write_nic_byte TimeOut! status:%d\n", status);
378 void write_nic_word(struct net_device *dev, int indx, u16 data)
383 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
384 struct usb_device *udev = priv->udev;
386 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
387 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
388 indx, 0, &data, 2, HZ / 2);
392 printk("write_nic_word TimeOut! status:%d\n", status);
398 void write_nic_dword(struct net_device *dev, int indx, u32 data)
403 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
404 struct usb_device *udev = priv->udev;
406 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
407 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
408 indx, 0, &data, 4, HZ / 2);
413 printk("write_nic_dword TimeOut! status:%d\n", status);
420 u8 read_nic_byte(struct net_device *dev, int indx)
424 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
425 struct usb_device *udev = priv->udev;
427 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
428 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
429 indx, 0, &data, 1, HZ / 2);
433 printk("read_nic_byte TimeOut! status:%d\n", status);
441 u16 read_nic_word(struct net_device *dev, int indx)
445 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
446 struct usb_device *udev = priv->udev;
448 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
449 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
450 indx, 0, &data, 2, HZ / 2);
454 printk("read_nic_word TimeOut! status:%d\n", status);
461 u16 read_nic_word_E(struct net_device *dev, int indx)
465 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
466 struct usb_device *udev = priv->udev;
468 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
469 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
470 indx|0xfe00, 0, &data, 2, HZ / 2);
474 printk("read_nic_word TimeOut! status:%d\n", status);
481 u32 read_nic_dword(struct net_device *dev, int indx)
487 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
488 struct usb_device *udev = priv->udev;
490 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
491 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
492 indx, 0, &data, 4, HZ / 2);
494 // printk(KERN_WARNING "read size of data = %d\, date = %d\n", result, data);
499 printk("read_nic_dword TimeOut! status:%d\n", status);
500 if(status == -ENODEV) {
501 priv->usb_error = true;
511 //u8 read_phy_cck(struct net_device *dev, u8 adr);
512 //u8 read_phy_ofdm(struct net_device *dev, u8 adr);
513 /* this might still called in what was the PHY rtl8185/rtl8192 common code
514 * plans are to possibilty turn it again in one common code...
516 inline void force_pci_posting(struct net_device *dev)
521 static struct net_device_stats *rtl8192_stats(struct net_device *dev);
522 void rtl8192_commit(struct net_device *dev);
523 //void rtl8192_restart(struct net_device *dev);
524 void rtl8192_restart(struct work_struct *work);
525 //void rtl8192_rq_tx_ack(struct work_struct *work);
527 void watch_dog_timer_callback(unsigned long data);
529 /****************************************************************************
530 -----------------------------PROCFS STUFF-------------------------
531 *****************************************************************************/
533 static struct proc_dir_entry *rtl8192_proc = NULL;
537 static int proc_get_stats_ap(char *page, char **start,
538 off_t offset, int count,
539 int *eof, void *data)
541 struct net_device *dev = data;
542 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
543 struct ieee80211_device *ieee = priv->ieee80211;
544 struct ieee80211_network *target;
548 list_for_each_entry(target, &ieee->network_list, list) {
550 len += snprintf(page + len, count - len,
551 "%s ", target->ssid);
553 if(target->wpa_ie_len>0 || target->rsn_ie_len>0){
554 len += snprintf(page + len, count - len,
558 len += snprintf(page + len, count - len,
568 static int proc_get_registers(char *page, char **start,
569 off_t offset, int count,
570 int *eof, void *data)
572 struct net_device *dev = data;
573 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
576 int i,n,page0,page1,page2;
583 /* This dump the current register page */
584 if(!IS_BB_REG_OFFSET_92S(page0)){
585 len += snprintf(page + len, count - len,
586 "\n####################page %x##################\n ", (page0>>8));
589 len += snprintf(page + len, count - len,
591 for(i=0;i<16 && n<=max;i++,n++)
592 len += snprintf(page + len, count - len,
593 "%2.2x ",read_nic_byte(dev,(page0|n)));
596 len += snprintf(page + len, count - len,
597 "\n####################page %x##################\n ", (page0>>8));
600 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
601 for(i=0;i<4 && n<=max;n+=4,i++)
602 len += snprintf(page + len, count - len,
603 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
606 len += snprintf(page + len, count - len,"\n");
611 static int proc_get_registers_1(char *page, char **start,
612 off_t offset, int count,
613 int *eof, void *data)
615 struct net_device *dev = data;
616 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
624 /* This dump the current register page */
625 len += snprintf(page + len, count - len,
626 "\n####################page %x##################\n ", (page0>>8));
629 len += snprintf(page + len, count - len,
631 for(i=0;i<16 && n<=max;i++,n++)
632 len += snprintf(page + len, count - len,
633 "%2.2x ",read_nic_byte(dev,(page0|n)));
635 len += snprintf(page + len, count - len,"\n");
640 static int proc_get_registers_2(char *page, char **start,
641 off_t offset, int count,
642 int *eof, void *data)
644 struct net_device *dev = data;
645 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
653 /* This dump the current register page */
654 len += snprintf(page + len, count - len,
655 "\n####################page %x##################\n ", (page0>>8));
658 len += snprintf(page + len, count - len,
660 for(i=0;i<16 && n<=max;i++,n++)
661 len += snprintf(page + len, count - len,
662 "%2.2x ",read_nic_byte(dev,(page0|n)));
664 len += snprintf(page + len, count - len,"\n");
669 static int proc_get_registers_8(char *page, char **start,
670 off_t offset, int count,
671 int *eof, void *data)
673 struct net_device *dev = data;
681 /* This dump the current register page */
682 len += snprintf(page + len, count - len,
683 "\n####################page %x##################\n ", (page0>>8));
686 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
687 for(i=0;i<4 && n<=max;n+=4,i++)
688 len += snprintf(page + len, count - len,
689 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
691 len += snprintf(page + len, count - len,"\n");
696 static int proc_get_registers_9(char *page, char **start,
697 off_t offset, int count,
698 int *eof, void *data)
700 struct net_device *dev = data;
701 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
709 /* This dump the current register page */
710 len += snprintf(page + len, count - len,
711 "\n####################page %x##################\n ", (page0>>8));
714 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
715 for(i=0;i<4 && n<=max;n+=4,i++)
716 len += snprintf(page + len, count - len,
717 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
719 len += snprintf(page + len, count - len,"\n");
723 static int proc_get_registers_a(char *page, char **start,
724 off_t offset, int count,
725 int *eof, void *data)
727 struct net_device *dev = data;
728 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
736 /* This dump the current register page */
737 len += snprintf(page + len, count - len,
738 "\n####################page %x##################\n ", (page0>>8));
741 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
742 for(i=0;i<4 && n<=max;n+=4,i++)
743 len += snprintf(page + len, count - len,
744 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
746 len += snprintf(page + len, count - len,"\n");
750 static int proc_get_registers_b(char *page, char **start,
751 off_t offset, int count,
752 int *eof, void *data)
754 struct net_device *dev = data;
755 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
763 /* This dump the current register page */
764 len += snprintf(page + len, count - len,
765 "\n####################page %x##################\n ", (page0>>8));
768 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
769 for(i=0;i<4 && n<=max;n+=4,i++)
770 len += snprintf(page + len, count - len,
771 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
773 len += snprintf(page + len, count - len,"\n");
777 static int proc_get_registers_c(char *page, char **start,
778 off_t offset, int count,
779 int *eof, void *data)
781 struct net_device *dev = data;
782 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
790 /* This dump the current register page */
791 len += snprintf(page + len, count - len,
792 "\n####################page %x##################\n ", (page0>>8));
795 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
796 for(i=0;i<4 && n<=max;n+=4,i++)
797 len += snprintf(page + len, count - len,
798 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
800 len += snprintf(page + len, count - len,"\n");
804 static int proc_get_registers_d(char *page, char **start,
805 off_t offset, int count,
806 int *eof, void *data)
808 struct net_device *dev = data;
809 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
817 /* This dump the current register page */
818 len += snprintf(page + len, count - len,
819 "\n####################page %x##################\n ", (page0>>8));
822 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
823 for(i=0;i<4 && n<=max;n+=4,i++)
824 len += snprintf(page + len, count - len,
825 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
827 len += snprintf(page + len, count - len,"\n");
831 static int proc_get_registers_e(char *page, char **start,
832 off_t offset, int count,
833 int *eof, void *data)
835 struct net_device *dev = data;
836 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
844 /* This dump the current register page */
845 len += snprintf(page + len, count - len,
846 "\n####################page %x##################\n ", (page0>>8));
849 len += snprintf(page + len, count - len, "\nD: %2x > ",n);
850 for(i=0;i<4 && n<=max;n+=4,i++)
851 len += snprintf(page + len, count - len,
852 "%8.8x ",rtl8192_QueryBBReg(dev,(page0|n), bMaskDWord));
854 len += snprintf(page + len, count - len,"\n");
859 static int proc_get_stats_tx(char *page, char **start,
860 off_t offset, int count,
861 int *eof, void *data)
863 struct net_device *dev = data;
864 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
868 len += snprintf(page + len, count - len,
869 "TX VI priority ok int: %lu\n"
870 "TX VI priority error int: %lu\n"
871 "TX VO priority ok int: %lu\n"
872 "TX VO priority error int: %lu\n"
873 "TX BE priority ok int: %lu\n"
874 "TX BE priority error int: %lu\n"
875 "TX BK priority ok int: %lu\n"
876 "TX BK priority error int: %lu\n"
877 "TX MANAGE priority ok int: %lu\n"
878 "TX MANAGE priority error int: %lu\n"
879 "TX BEACON priority ok int: %lu\n"
880 "TX BEACON priority error int: %lu\n"
881 // "TX high priority ok int: %lu\n"
882 // "TX high priority failed error int: %lu\n"
883 "TX queue resume: %lu\n"
884 "TX queue stopped?: %d\n"
885 "TX fifo overflow: %lu\n"
886 // "TX beacon: %lu\n"
891 // "TX HW queue: %d\n"
892 "TX VI dropped: %lu\n"
893 "TX VO dropped: %lu\n"
894 "TX BE dropped: %lu\n"
895 "TX BK dropped: %lu\n"
896 "TX total data packets %lu\n",
897 // "TX beacon aborted: %lu\n",
898 priv->stats.txviokint,
900 priv->stats.txvookint,
902 priv->stats.txbeokint,
904 priv->stats.txbkokint,
906 priv->stats.txmanageokint,
907 priv->stats.txmanageerr,
908 priv->stats.txbeaconokint,
909 priv->stats.txbeaconerr,
910 // priv->stats.txhpokint,
911 // priv->stats.txhperr,
912 priv->stats.txresumed,
913 netif_queue_stopped(dev),
914 priv->stats.txoverflow,
915 // priv->stats.txbeacon,
916 atomic_read(&(priv->tx_pending[VI_PRIORITY])),
917 atomic_read(&(priv->tx_pending[VO_PRIORITY])),
918 atomic_read(&(priv->tx_pending[BE_PRIORITY])),
919 atomic_read(&(priv->tx_pending[BK_PRIORITY])),
920 // read_nic_byte(dev, TXFIFOCOUNT),
921 priv->stats.txvidrop,
922 priv->stats.txvodrop,
923 priv->stats.txbedrop,
924 priv->stats.txbkdrop,
925 priv->stats.txdatapkt
926 // priv->stats.txbeaconerr
935 static int proc_get_stats_rx(char *page, char **start,
936 off_t offset, int count,
937 int *eof, void *data)
939 struct net_device *dev = data;
940 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
944 len += snprintf(page + len, count - len,
946 "RX urb status error: %lu\n"
947 "RX invalid urb error: %lu\n",
948 priv->stats.rxoktotal,
949 priv->stats.rxstaterr,
950 priv->stats.rxurberr);
956 void rtl8192_proc_module_init(void)
958 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
959 rtl8192_proc=create_proc_entry(RTL819xU_MODULE_NAME, S_IFDIR, init_net.proc_net);
963 void rtl8192_proc_module_remove(void)
965 remove_proc_entry(RTL819xU_MODULE_NAME, init_net.proc_net);
969 void rtl8192_proc_remove_one(struct net_device *dev)
971 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
975 // remove_proc_entry("stats-hw", priv->dir_dev);
976 remove_proc_entry("stats-tx", priv->dir_dev);
977 remove_proc_entry("stats-rx", priv->dir_dev);
978 // remove_proc_entry("stats-ieee", priv->dir_dev);
979 remove_proc_entry("stats-ap", priv->dir_dev);
980 remove_proc_entry("registers", priv->dir_dev);
981 remove_proc_entry("registers-1", priv->dir_dev);
982 remove_proc_entry("registers-2", priv->dir_dev);
983 remove_proc_entry("registers-8", priv->dir_dev);
984 remove_proc_entry("registers-9", priv->dir_dev);
985 remove_proc_entry("registers-a", priv->dir_dev);
986 remove_proc_entry("registers-b", priv->dir_dev);
987 remove_proc_entry("registers-c", priv->dir_dev);
988 remove_proc_entry("registers-d", priv->dir_dev);
989 remove_proc_entry("registers-e", priv->dir_dev);
990 // remove_proc_entry("cck-registers",priv->dir_dev);
991 // remove_proc_entry("ofdm-registers",priv->dir_dev);
992 //remove_proc_entry(dev->name, rtl8192_proc);
993 remove_proc_entry("wlan0", rtl8192_proc);
994 priv->dir_dev = NULL;
999 void rtl8192_proc_init_one(struct net_device *dev)
1001 struct proc_dir_entry *e;
1002 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1003 priv->dir_dev = create_proc_entry(dev->name,
1004 S_IFDIR | S_IRUGO | S_IXUGO,
1006 if (!priv->dir_dev) {
1007 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
1011 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
1012 priv->dir_dev, proc_get_stats_rx, dev);
1015 RT_TRACE(COMP_ERR,"Unable to initialize "
1016 "/proc/net/rtl8192/%s/stats-rx\n",
1021 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
1022 priv->dir_dev, proc_get_stats_tx, dev);
1025 RT_TRACE(COMP_ERR, "Unable to initialize "
1026 "/proc/net/rtl8192/%s/stats-tx\n",
1030 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
1031 priv->dir_dev, proc_get_stats_ap, dev);
1034 RT_TRACE(COMP_ERR, "Unable to initialize "
1035 "/proc/net/rtl8192/%s/stats-ap\n",
1039 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
1040 priv->dir_dev, proc_get_registers, dev);
1042 RT_TRACE(COMP_ERR, "Unable to initialize "
1043 "/proc/net/rtl8192/%s/registers\n",
1046 e = create_proc_read_entry("registers-1", S_IFREG | S_IRUGO,
1047 priv->dir_dev, proc_get_registers_1, dev);
1049 RT_TRACE(COMP_ERR, "Unable to initialize "
1050 "/proc/net/rtl8192/%s/registers-1\n",
1053 e = create_proc_read_entry("registers-2", S_IFREG | S_IRUGO,
1054 priv->dir_dev, proc_get_registers_2, dev);
1056 RT_TRACE(COMP_ERR, "Unable to initialize "
1057 "/proc/net/rtl8192/%s/registers-2\n",
1060 e = create_proc_read_entry("registers-8", S_IFREG | S_IRUGO,
1061 priv->dir_dev, proc_get_registers_8, dev);
1063 RT_TRACE(COMP_ERR, "Unable to initialize "
1064 "/proc/net/rtl8192/%s/registers-8\n",
1067 e = create_proc_read_entry("registers-9", S_IFREG | S_IRUGO,
1068 priv->dir_dev, proc_get_registers_9, dev);
1070 RT_TRACE(COMP_ERR, "Unable to initialize "
1071 "/proc/net/rtl8192/%s/registers-9\n",
1074 e = create_proc_read_entry("registers-a", S_IFREG | S_IRUGO,
1075 priv->dir_dev, proc_get_registers_a, dev);
1077 RT_TRACE(COMP_ERR, "Unable to initialize "
1078 "/proc/net/rtl8192/%s/registers-a\n",
1081 e = create_proc_read_entry("registers-b", S_IFREG | S_IRUGO,
1082 priv->dir_dev, proc_get_registers_b, dev);
1084 RT_TRACE(COMP_ERR, "Unable to initialize "
1085 "/proc/net/rtl8192/%s/registers-b\n",
1088 e = create_proc_read_entry("registers-c", S_IFREG | S_IRUGO,
1089 priv->dir_dev, proc_get_registers_c, dev);
1091 RT_TRACE(COMP_ERR, "Unable to initialize "
1092 "/proc/net/rtl8192/%s/registers-c\n",
1095 e = create_proc_read_entry("registers-d", S_IFREG | S_IRUGO,
1096 priv->dir_dev, proc_get_registers_d, dev);
1098 RT_TRACE(COMP_ERR, "Unable to initialize "
1099 "/proc/net/rtl8192/%s/registers-d\n",
1102 e = create_proc_read_entry("registers-e", S_IFREG | S_IRUGO,
1103 priv->dir_dev, proc_get_registers_e, dev);
1105 RT_TRACE(COMP_ERR, "Unable to initialize "
1106 "/proc/net/rtl8192/%s/registers-e\n",
1110 /****************************************************************************
1111 -----------------------------MISC STUFF-------------------------
1112 *****************************************************************************/
1114 /* this is only for debugging */
1115 void print_buffer(u32 *buffer, int len)
1118 u8 *buf =(u8*)buffer;
1120 printk("ASCII BUFFER DUMP (len: %x):\n",len);
1123 printk("%c",buf[i]);
1125 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
1128 printk("%x",buf[i]);
1133 //short check_nic_enough_desc(struct net_device *dev, priority_t priority)
1134 short check_nic_enough_desc(struct net_device *dev,int queue_index)
1136 struct r8192_priv *priv = ieee80211_priv(dev);
1137 int used = atomic_read(&priv->tx_pending[queue_index]);
1139 return (used < MAX_TX_URB);
1142 void tx_timeout(struct net_device *dev)
1144 struct r8192_priv *priv = ieee80211_priv(dev);
1145 //rtl8192_commit(dev);
1147 schedule_work(&priv->reset_wq);
1148 //DMESG("TXTIMEOUT");
1152 /* this is only for debug */
1153 void dump_eprom(struct net_device *dev)
1157 RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev,i));
1160 /* this is only for debug */
1161 void rtl8192_dump_reg(struct net_device *dev)
1167 RT_TRACE(COMP_PHY, "Dumping NIC register map");
1171 printk( "\nD: %2x> ", n);
1172 for(i=0;i<16 && n<=max;i++,n++)
1173 printk("%2x ",read_nic_byte(dev,n));
1178 /****************************************************************************
1179 ------------------------------HW STUFF---------------------------
1180 *****************************************************************************/
1182 void rtl8192_set_mode(struct net_device *dev,int mode)
1185 ecmd=read_nic_byte(dev, EPROM_CMD);
1186 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1187 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1188 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1189 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1190 write_nic_byte(dev, EPROM_CMD, ecmd);
1194 void rtl8192_update_msr(struct net_device *dev)
1196 struct r8192_priv *priv = ieee80211_priv(dev);
1199 msr = read_nic_byte(dev, MSR);
1200 msr &= ~ MSR_LINK_MASK;
1202 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
1203 * msr must be updated if the state is ASSOCIATING.
1204 * this is intentional and make sense for ad-hoc and
1205 * master (see the create BSS/IBSS func)
1207 if (priv->ieee80211->state == IEEE80211_LINKED){
1209 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1210 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1211 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1212 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1213 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1214 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1217 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1219 write_nic_byte(dev, MSR, msr);
1222 void rtl8192_set_chan(struct net_device *dev,short ch)
1224 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1226 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __FUNCTION__, ch);
1227 //printk("=====>%s()====ch:%d\n", __FUNCTION__, ch);
1230 /* this hack should avoid frame TX during channel setting*/
1233 // tx = read_nic_dword(dev,TX_CONF);
1234 // tx &= ~TX_LOOPBACK_MASK;
1237 // write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
1239 //need to implement rf set channel here WB
1241 if (priv->rf_set_chan)
1242 priv->rf_set_chan(dev,priv->chan);
1244 // write_nic_dword(dev,TX_CONF,tx | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT));
1248 static void rtl8192_rx_isr(struct urb *urb);
1250 u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
1253 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
1254 + pstats->RxBufShift);
1257 static int rtl8192_rx_initiate(struct net_device*dev)
1259 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1261 struct sk_buff *skb;
1262 struct rtl8192_rx_info *info;
1264 /* nomal packet rx procedure */
1265 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB) {
1266 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
1269 entry = usb_alloc_urb(0, GFP_KERNEL);
1274 // printk("nomal packet IN request!\n");
1275 usb_fill_bulk_urb(entry, priv->udev,
1276 usb_rcvbulkpipe(priv->udev, 3), skb->tail,
1277 RX_URB_SIZE, rtl8192_rx_isr, skb);
1278 info = (struct rtl8192_rx_info *) skb->cb;
1281 info->out_pipe = 3; //denote rx normal packet queue
1282 skb_queue_tail(&priv->rx_queue, skb);
1283 usb_submit_urb(entry, GFP_KERNEL);
1286 /* command packet rx procedure */
1287 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
1288 // printk("command packet IN request!\n");
1289 skb = __dev_alloc_skb(RX_URB_SIZE ,GFP_KERNEL);
1292 entry = usb_alloc_urb(0, GFP_KERNEL);
1297 usb_fill_bulk_urb(entry, priv->udev,
1298 usb_rcvbulkpipe(priv->udev, 9), skb->tail,
1299 RX_URB_SIZE, rtl8192_rx_isr, skb);
1300 info = (struct rtl8192_rx_info *) skb->cb;
1303 info->out_pipe = 9; //denote rx cmd packet queue
1304 skb_queue_tail(&priv->rx_queue, skb);
1305 usb_submit_urb(entry, GFP_KERNEL);
1311 void rtl8192_set_rxconf(struct net_device *dev)
1313 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1316 rxconf=read_nic_dword(dev,RCR);
1317 rxconf = rxconf &~ MAC_FILTER_MASK;
1318 rxconf = rxconf | RCR_AMF;
1319 rxconf = rxconf | RCR_ADF;
1320 rxconf = rxconf | RCR_AB;
1321 rxconf = rxconf | RCR_AM;
1322 //rxconf = rxconf | RCR_ACF;
1324 if (dev->flags & IFF_PROMISC) {DMESG ("NIC in promisc mode");}
1326 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1327 dev->flags & IFF_PROMISC){
1328 rxconf = rxconf | RCR_AAP;
1329 } /*else if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1330 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1331 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1333 rxconf = rxconf | RCR_APM;
1334 rxconf = rxconf | RCR_CBSSID;
1338 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1339 rxconf = rxconf | RCR_AICV;
1340 rxconf = rxconf | RCR_APWRMGT;
1343 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1344 rxconf = rxconf | RCR_ACRC32;
1347 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1348 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1349 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1350 rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
1352 // rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1353 rxconf = rxconf | RCR_ONLYERLPKT;
1355 // rxconf = rxconf &~ RCR_CS_MASK;
1356 // rxconf = rxconf | (1<<RCR_CS_SHIFT);
1358 write_nic_dword(dev, RCR, rxconf);
1361 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RCR));
1364 //wait to be removed
1365 void rtl8192_rx_enable(struct net_device *dev)
1369 //struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1371 rtl8192_rx_initiate(dev);
1373 // rtl8192_set_rxconf(dev);
1377 void rtl8192_tx_enable(struct net_device *dev)
1381 void rtl8192_rtx_disable(struct net_device *dev)
1384 struct r8192_priv *priv = ieee80211_priv(dev);
1385 struct sk_buff *skb;
1386 struct rtl8192_rx_info *info;
1388 cmd=read_nic_byte(dev,CMDR);
1389 write_nic_byte(dev, CMDR, cmd &~ \
1391 force_pci_posting(dev);
1394 while ((skb = __skb_dequeue(&priv->rx_queue))) {
1395 info = (struct rtl8192_rx_info *) skb->cb;
1399 usb_kill_urb(info->urb);
1403 if (skb_queue_len(&priv->skb_queue)) {
1404 printk(KERN_WARNING "skb_queue not empty\n");
1407 skb_queue_purge(&priv->skb_queue);
1412 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1417 inline u16 ieeerate2rtlrate(int rate)
1449 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
1450 inline u16 rtl8192_rate2rate(short rate)
1452 if (rate >11) return 0;
1453 return rtl_rate[rate];
1456 static void rtl8192_rx_isr(struct urb *urb)
1458 struct sk_buff *skb = (struct sk_buff *) urb->context;
1459 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
1460 struct net_device *dev = info->dev;
1461 struct r8192_priv *priv = ieee80211_priv(dev);
1462 int out_pipe = info->out_pipe;
1466 if (unlikely(urb->status)) {
1468 priv->stats.rxstaterr++;
1469 priv->ieee80211->stats.rx_errors++;
1471 // printk("%s():rx status err\n",__FUNCTION__);
1475 skb_unlink(skb, &priv->rx_queue);
1476 skb_put(skb, urb->actual_length);
1478 skb_queue_tail(&priv->skb_queue, skb);
1479 tasklet_schedule(&priv->irq_rx_tasklet);
1481 skb = dev_alloc_skb(RX_URB_SIZE);
1482 if (unlikely(!skb)) {
1484 printk("%s():can,t alloc skb\n",__FUNCTION__);
1485 /* TODO check rx queue length and refill *somewhere* */
1489 usb_fill_bulk_urb(urb, priv->udev,
1490 usb_rcvbulkpipe(priv->udev, out_pipe), skb->tail,
1491 RX_URB_SIZE, rtl8192_rx_isr, skb);
1493 info = (struct rtl8192_rx_info *) skb->cb;
1496 info->out_pipe = out_pipe;
1498 urb->transfer_buffer = skb->tail;
1500 skb_queue_tail(&priv->rx_queue, skb);
1501 err = usb_submit_urb(urb, GFP_ATOMIC);
1502 if(err && err != EPERM)
1503 printk("can not submit rxurb, err is %x,URB status is %x\n",err,urb->status);
1507 rtl819xusb_rx_command_packet(
1508 struct net_device *dev,
1509 struct ieee80211_rx_stats *pstats
1514 //RT_TRACE(COMP_RECV, DBG_TRACE, ("---> RxCommandPacketHandle819xUsb()\n"));
1516 status = cmpk_message_handle_rx(dev, pstats);
1519 DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
1523 //RT_TRACE(COMP_RECV, DBG_TRACE, ("RxCommandPacketHandle819xUsb: It is not a command packet\n"));
1526 //RT_TRACE(COMP_RECV, DBG_TRACE, ("<--- RxCommandPacketHandle819xUsb()\n"));
1530 void rtl8192_data_hard_stop(struct net_device *dev)
1536 void rtl8192_data_hard_resume(struct net_device *dev)
1541 /* this function TX data frames when the ieee80211 stack requires this.
1542 * It checks also if we need to stop the ieee tx queue, eventually do it
1544 void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1546 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1548 unsigned long flags;
1549 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1550 u8 queue_index = tcb_desc->queue_index;
1552 /* shall not be referred by command packet */
1553 assert(queue_index != TXCMD_QUEUE);
1555 spin_lock_irqsave(&priv->tx_lock,flags);
1557 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1558 // tcb_desc->RATRIndex = 7;
1559 // tcb_desc->bTxDisableRateFallBack = 1;
1560 // tcb_desc->bTxUseDriverAssingedRate = 1;
1561 tcb_desc->bTxEnableFwCalcDur = 1;
1562 skb_push(skb, priv->ieee80211->tx_headroom);
1563 ret = priv->ops->rtl819x_tx(dev, skb);
1565 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1566 //priv->ieee80211->stats.tx_packets++;
1568 spin_unlock_irqrestore(&priv->tx_lock,flags);
1574 /* This is a rough attempt to TX a frame
1575 * This is called by the ieee 80211 stack to TX management frames.
1576 * If the ring is full packet are dropped (for data frame the queue
1577 * is stopped before this can happen).
1579 int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
1581 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1583 unsigned long flags;
1584 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1585 u8 queue_index = tcb_desc->queue_index;
1588 spin_lock_irqsave(&priv->tx_lock,flags);
1590 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1591 if(queue_index == TXCMD_QUEUE) {
1592 skb_push(skb, USB_HWDESC_HEADER_LEN);
1593 priv->ops->rtl819x_tx_cmd(dev, skb);
1595 spin_unlock_irqrestore(&priv->tx_lock,flags);
1598 skb_push(skb, priv->ieee80211->tx_headroom);
1599 ret = priv->ops->rtl819x_tx(dev, skb);
1602 spin_unlock_irqrestore(&priv->tx_lock,flags);
1608 void rtl8192_try_wake_queue(struct net_device *dev, int pri);
1611 static void rtl8192_tx_isr(struct urb *tx_urb)
1613 struct sk_buff *skb = (struct sk_buff*)tx_urb->context;
1614 struct net_device *dev = NULL;
1615 struct r8192_priv *priv = NULL;
1616 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1617 u8 queue_index = tcb_desc->queue_index;
1618 // bool bToSend0Byte;
1619 // u16 BufLen = skb->len;
1621 memcpy(&dev,(struct net_device*)(skb->cb),sizeof(struct net_device*));
1622 priv = ieee80211_priv(dev);
1624 if(tcb_desc->queue_index != TXCMD_QUEUE) {
1625 if(tx_urb->status == 0) {
1626 // dev->trans_start = jiffies;
1627 // As act as station mode, destion shall be unicast address.
1628 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1629 //priv->ieee80211->stats.tx_packets++;
1630 priv->stats.txoktotal++;
1631 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
1632 priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
1634 priv->ieee80211->stats.tx_errors++;
1635 //priv->stats.txmanageerr++;
1640 /* free skb and tx_urb */
1642 dev_kfree_skb_any(skb);
1643 usb_free_urb(tx_urb);
1644 atomic_dec(&priv->tx_pending[queue_index]);
1649 // Handle HW Beacon:
1650 // We had transfer our beacon frame to host controler at this moment.
1654 // Handling the wait queue of command packets.
1655 // For Tx command packets, we must not do TCB fragment because it is not handled right now.
1656 // We must cut the packets to match the size of TX_CMD_PKT before we send it.
1658 if (queue_index == MGNT_QUEUE){
1659 if (priv->ieee80211->ack_tx_to_ieee){
1660 if (rtl8192_is_tx_queue_empty(dev)){
1661 priv->ieee80211->ack_tx_to_ieee = 0;
1662 ieee80211_ps_tx_ack(priv->ieee80211, 1);
1666 /* Handle MPDU in wait queue. */
1667 if(queue_index != BEACON_QUEUE) {
1668 /* Don't send data frame during scanning.*/
1669 if((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0)&&\
1670 (!(priv->ieee80211->queue_stop))) {
1671 if(NULL != (skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]))))
1672 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
1674 return; //modified by david to avoid further processing AMSDU
1680 void rtl8192_beacon_stop(struct net_device *dev)
1683 struct r8192_priv *priv = ieee80211_priv(dev);
1685 msr = read_nic_byte(dev, MSR);
1686 msrm = msr & MSR_LINK_MASK;
1687 msr2 = msr & ~MSR_LINK_MASK;
1689 if(NIC_8192U == priv->card_8192) {
1690 usb_kill_urb(priv->rx_urb[MAX_RX_URB]);
1692 if ((msrm == (MSR_LINK_ADHOC<<MSR_LINK_SHIFT) ||
1693 (msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))){
1694 write_nic_byte(dev, MSR, msr2 | MSR_LINK_NONE);
1695 write_nic_byte(dev, MSR, msr);
1699 void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
1701 struct r8192_priv *priv = ieee80211_priv(dev);
1702 struct ieee80211_network *net;
1703 u8 i=0, basic_rate = 0;
1704 net = & priv->ieee80211->current_network;
1706 for (i=0; i<net->rates_len; i++)
1708 basic_rate = net->rates[i]&0x7f;
1711 case MGN_1M: *rate_config |= RRSR_1M; break;
1712 case MGN_2M: *rate_config |= RRSR_2M; break;
1713 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1714 case MGN_11M: *rate_config |= RRSR_11M; break;
1715 case MGN_6M: *rate_config |= RRSR_6M; break;
1716 case MGN_9M: *rate_config |= RRSR_9M; break;
1717 case MGN_12M: *rate_config |= RRSR_12M; break;
1718 case MGN_18M: *rate_config |= RRSR_18M; break;
1719 case MGN_24M: *rate_config |= RRSR_24M; break;
1720 case MGN_36M: *rate_config |= RRSR_36M; break;
1721 case MGN_48M: *rate_config |= RRSR_48M; break;
1722 case MGN_54M: *rate_config |= RRSR_54M; break;
1725 for (i=0; i<net->rates_ex_len; i++)
1727 basic_rate = net->rates_ex[i]&0x7f;
1730 case MGN_1M: *rate_config |= RRSR_1M; break;
1731 case MGN_2M: *rate_config |= RRSR_2M; break;
1732 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
1733 case MGN_11M: *rate_config |= RRSR_11M; break;
1734 case MGN_6M: *rate_config |= RRSR_6M; break;
1735 case MGN_9M: *rate_config |= RRSR_9M; break;
1736 case MGN_12M: *rate_config |= RRSR_12M; break;
1737 case MGN_18M: *rate_config |= RRSR_18M; break;
1738 case MGN_24M: *rate_config |= RRSR_24M; break;
1739 case MGN_36M: *rate_config |= RRSR_36M; break;
1740 case MGN_48M: *rate_config |= RRSR_48M; break;
1741 case MGN_54M: *rate_config |= RRSR_54M; break;
1747 #define SHORT_SLOT_TIME 9
1748 #define NON_SHORT_SLOT_TIME 20
1750 void rtl8192_update_cap(struct net_device* dev, u16 cap)
1753 struct r8192_priv *priv = ieee80211_priv(dev);
1754 struct ieee80211_network *net = &priv->ieee80211->current_network;
1755 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
1757 //LZM MOD 090303 HW_VAR_ACK_PREAMBLE
1761 tmp = ((priv->nCur40MhzPrimeSC) << 5);
1762 if (priv->short_preamble)
1764 write_nic_byte(dev, RRSR+2, tmp);
1767 if (net->mode & (IEEE_G|IEEE_N_24G))
1770 if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
1772 slot_time = SHORT_SLOT_TIME;
1774 else //long slot time
1775 slot_time = NON_SHORT_SLOT_TIME;
1776 priv->slot_time = slot_time;
1777 write_nic_byte(dev, SLOT_TIME, slot_time);
1781 void rtl8192_net_update(struct net_device *dev)
1784 struct r8192_priv *priv = ieee80211_priv(dev);
1785 struct ieee80211_network *net;
1786 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
1787 u16 rate_config = 0;
1788 net = & priv->ieee80211->current_network;
1790 rtl8192_config_rate(dev, &rate_config);
1791 priv->basic_rate = rate_config &= 0x15f;
1793 write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
1794 write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
1795 //for(i=0;i<ETH_ALEN;i++)
1796 // write_nic_byte(dev,BSSID+i,net->bssid[i]);
1798 rtl8192_update_msr(dev);
1799 // rtl8192_update_cap(dev, net->capability);
1800 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1802 write_nic_word(dev, ATIMWND, 2);
1803 write_nic_word(dev, BCN_DMATIME, 1023);
1804 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
1805 // write_nic_word(dev, BcnIntTime, 100);
1806 write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
1807 write_nic_byte(dev, BCN_ERR_THRESH, 100);
1808 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
1809 // TODO: BcnIFS may required to be changed on ASIC
1810 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
1812 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
1819 //temporary hw beacon is not used any more.
1820 //open it when necessary
1822 void rtl819xusb_beacon_tx(struct net_device *dev,u16 tx_rate)
1826 inline u8 rtl8192_IsWirelessBMode(u16 rate)
1828 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
1833 u16 N_DBPSOfRate(u16 DataRate);
1838 u8 bManagementFrame,
1846 if( rtl8192_IsWirelessBMode(DataRate) )
1848 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
1850 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1854 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1856 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
1858 } else { //802.11g DSSS-OFDM PLCP length field calculation.
1859 N_DBPS = N_DBPSOfRate(DataRate);
1860 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1861 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1862 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1867 u16 N_DBPSOfRate(u16 DataRate)
1912 void rtl819xU_cmd_isr(struct urb *tx_cmd_urb, struct pt_regs *regs)
1914 usb_free_urb(tx_cmd_urb);
1917 unsigned int txqueue2outpipe(struct r8192_priv* priv,unsigned int tx_queue) {
1921 RT_TRACE(COMP_ERR,"%s():Unknown queue ID!!!\n",__FUNCTION__);
1924 return priv->txqueue_to_outpipemap[tx_queue];
1927 short rtl8192SU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1929 struct r8192_priv *priv = ieee80211_priv(dev);
1932 unsigned int idx_pipe;
1933 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
1934 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1935 u8 queue_index = tcb_desc->queue_index;
1938 //printk("\n %s::::::::::::::::::::::queue_index = %d\n",__FUNCTION__, queue_index);
1939 atomic_inc(&priv->tx_pending[queue_index]);
1941 tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
1947 memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
1949 /* Tx descriptor ought to be set according to the skb->cb */
1950 pdesc->LINIP = tcb_desc->bLastIniPkt;
1951 PktSize = (u16)(skb->len - USB_HWDESC_HEADER_LEN);
1952 pdesc->PktSize = PktSize;
1953 //printk("PKTSize = %d %x\n",pdesc->PktSize,pdesc->PktSize);
1954 //----------------------------------------------------------------------------
1955 // Fill up USB_OUT_CONTEXT.
1956 //----------------------------------------------------------------------------
1957 // Get index to out pipe from specified QueueID.
1958 idx_pipe = txqueue2outpipe(priv,queue_index);
1959 //printk("=============>%s queue_index:%d, outpipe:%d\n", __func__,queue_index,priv->RtOutPipes[idx_pipe]);
1961 usb_fill_bulk_urb(tx_urb,
1963 usb_sndbulkpipe(priv->udev,priv->RtOutPipes[idx_pipe]),
1969 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
1973 printk("Error TX CMD URB, error %d",
1980 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
1981 * in TxFwInfo data structure
1982 * 2006.10.30 by Emily
1984 * \param QUEUEID Software Queue
1986 u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1988 u8 QueueSelect = 0x0; //defualt set to
1992 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority;
1996 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority;
2000 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority;
2004 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority;
2007 QueueSelect = QSLT_MGNT;
2011 QueueSelect = QSLT_BEACON;
2014 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
2015 // TODO: Remove Assertions
2016 //#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
2018 QueueSelect = QSLT_CMD;
2022 QueueSelect = QSLT_HIGH;
2026 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
2032 u8 MRateToHwRate8190Pci(u8 rate)
2034 u8 ret = DESC92S_RATE1M;
2038 // CCK and OFDM non-HT rates
2039 case MGN_1M: ret = DESC92S_RATE1M; break;
2040 case MGN_2M: ret = DESC92S_RATE2M; break;
2041 case MGN_5_5M: ret = DESC92S_RATE5_5M; break;
2042 case MGN_11M: ret = DESC92S_RATE11M; break;
2043 case MGN_6M: ret = DESC92S_RATE6M; break;
2044 case MGN_9M: ret = DESC92S_RATE9M; break;
2045 case MGN_12M: ret = DESC92S_RATE12M; break;
2046 case MGN_18M: ret = DESC92S_RATE18M; break;
2047 case MGN_24M: ret = DESC92S_RATE24M; break;
2048 case MGN_36M: ret = DESC92S_RATE36M; break;
2049 case MGN_48M: ret = DESC92S_RATE48M; break;
2050 case MGN_54M: ret = DESC92S_RATE54M; break;
2052 // HT rates since here
2053 case MGN_MCS0: ret = DESC92S_RATEMCS0; break;
2054 case MGN_MCS1: ret = DESC92S_RATEMCS1; break;
2055 case MGN_MCS2: ret = DESC92S_RATEMCS2; break;
2056 case MGN_MCS3: ret = DESC92S_RATEMCS3; break;
2057 case MGN_MCS4: ret = DESC92S_RATEMCS4; break;
2058 case MGN_MCS5: ret = DESC92S_RATEMCS5; break;
2059 case MGN_MCS6: ret = DESC92S_RATEMCS6; break;
2060 case MGN_MCS7: ret = DESC92S_RATEMCS7; break;
2061 case MGN_MCS8: ret = DESC92S_RATEMCS8; break;
2062 case MGN_MCS9: ret = DESC92S_RATEMCS9; break;
2063 case MGN_MCS10: ret = DESC92S_RATEMCS10; break;
2064 case MGN_MCS11: ret = DESC92S_RATEMCS11; break;
2065 case MGN_MCS12: ret = DESC92S_RATEMCS12; break;
2066 case MGN_MCS13: ret = DESC92S_RATEMCS13; break;
2067 case MGN_MCS14: ret = DESC92S_RATEMCS14; break;
2068 case MGN_MCS15: ret = DESC92S_RATEMCS15; break;
2070 // Set the highest SG rate
2088 ret = DESC92S_RATEMCS15_SG;
2097 u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
2101 tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
2103 if(TxHT==1 && TxRate != DESC90_RATEMCS15)
2109 static void tx_zero_isr(struct urb *tx_urb)
2116 * The tx procedure is just as following, skb->cb will contain all the following
2117 *information: * priority, morefrag, rate, &dev.
2119 // <Note> Buffer format for 8192S Usb bulk out:
2121 // --------------------------------------------------
2122 // | 8192S Usb Tx Desc | 802_11_MAC_header | data |
2123 // --------------------------------------------------
2124 // | 32 bytes | 24 bytes |0-2318 bytes|
2125 // --------------------------------------------------
2126 // |<------------ BufferLen ------------------------->|
2128 short rtl8192SU_tx(struct net_device *dev, struct sk_buff* skb)
2130 struct r8192_priv *priv = ieee80211_priv(dev);
2131 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2132 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
2133 //tx_fwinfo_819x_usb *tx_fwinfo = (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);//92su del
2134 struct usb_device *udev = priv->udev;
2137 struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
2139 unsigned int idx_pipe;
2140 u16 MPDUOverhead = 0;
2141 //RT_DEBUG_DATA(COMP_SEND, tcb_desc, sizeof(cb_desc));
2143 pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
2144 /* we are locked here so the two atomic_read and inc are executed
2145 * without interleaves * !!! For debug purpose */
2146 if( pend > MAX_TX_URB){
2147 switch (tcb_desc->queue_index) {
2149 priv->stats.txvodrop++;
2152 priv->stats.txvidrop++;
2155 priv->stats.txbedrop++;
2157 default://BK_PRIORITY
2158 priv->stats.txbkdrop++;
2161 printk("To discard skb packet!\n");
2162 dev_kfree_skb_any(skb);
2166 tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
2168 dev_kfree_skb_any(skb);
2172 memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
2175 tx_desc->NonQos = (IsQoSDataFrame(skb->data)==TRUE)? 0:1;
2177 /* Fill Tx descriptor */
2178 //memset(tx_fwinfo,0,sizeof(tx_fwinfo_819x_usb));
2180 // This part can just fill to the first descriptor of the frame.
2182 tx_desc->TxHT = (tcb_desc->data_rate&0x80)?1:0;
2185 tx_desc->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
2186 //tx_desc->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
2187 tx_desc->TxShort = QueryIsShort(tx_desc->TxHT, tx_desc->TxRate, tcb_desc);
2190 // Aggregation related
2191 if(tcb_desc->bAMPDUEnable) {//AMPDU enabled
2192 tx_desc->AllowAggregation = 1;
2194 //tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
2195 //tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
2197 tx_desc->AllowAggregation = 0;
2199 //tx_fwinfo->RxMF = 0;
2200 //tx_fwinfo->RxAMD = 0;
2204 // <Roger_Notes> For AMPDU case, we must insert SSN into TX_DESC,
2205 // FW according as this SSN to do necessary packet retry.
2211 //pSeq = (u8 *)(VirtualAddress+USB_HWDESC_HEADER_LEN + FRAME_OFFSET_SEQUENCE);
2212 pSeq = (u8 *)(skb->data+USB_HWDESC_HEADER_LEN + 22);
2215 Temp |= (*(u16 *)pSeq)>>4;
2216 tx_desc->Seq = Temp;
2219 /* Protection mode related */
2220 tx_desc->RTSEn = (tcb_desc->bRTSEnable)?1:0;
2221 tx_desc->CTS2Self = (tcb_desc->bCTSEnable)?1:0;
2222 tx_desc->RTSSTBC = (tcb_desc->bRTSSTBC)?1:0;
2223 tx_desc->RTSHT = (tcb_desc->rts_rate&0x80)?1:0;
2224 tx_desc->RTSRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
2225 tx_desc->RTSSubcarrier = (tx_desc->RTSHT==0)?(tcb_desc->RTSSC):0;
2226 tx_desc->RTSBW = (tx_desc->RTSHT==1)?((tcb_desc->bRTSBW)?1:0):0;
2227 tx_desc->RTSShort = (tx_desc->RTSHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):\
2228 (tcb_desc->bRTSUseShortGI?1:0);
2230 tx_desc->DisRTSFB = 0;
2231 tx_desc->RTSRateFBLmt = 0xf;
2233 // <Roger_EXP> 2008.09.22. We disable RTS rate fallback temporarily.
2234 //tx_desc->DisRTSFB = 0x01;
2236 /* Set Bandwidth and sub-channel settings. */
2237 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2239 if(tcb_desc->bPacketBW) {
2240 tx_desc->TxBandwidth = 1;
2241 tx_desc->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
2243 tx_desc->TxBandwidth = 0;
2244 tx_desc->TxSubCarrier = priv->nCur40MhzPrimeSC;
2247 tx_desc->TxBandwidth = 0;
2248 tx_desc->TxSubCarrier = 0;
2252 //memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
2255 //tx_desc->CmdInit = 1; //92su del
2256 tx_desc->Offset = USB_HWDESC_HEADER_LEN;
2259 tx_desc->PktSize = (skb->len - USB_HWDESC_HEADER_LEN) & 0xffff;
2263 //tx_desc->SecCAMID= 0;//92su del
2264 tx_desc->RaBRSRID= tcb_desc->RATRIndex;
2265 //#ifdef RTL8192S_PREPARE_FOR_NORMAL_RELEASE
2269 //tx_desc->NoEnc = 1;//92su del
2272 tx_desc->SecType = 0x0;
2274 if (tcb_desc->bHwSec)
2276 switch (priv->ieee80211->pairwise_key_type)
2278 case KEY_TYPE_WEP40:
2279 case KEY_TYPE_WEP104:
2280 tx_desc->SecType = 0x1;
2281 //tx_desc->NoEnc = 0;//92su del
2284 tx_desc->SecType = 0x2;
2285 //tx_desc->NoEnc = 0;//92su del
2288 tx_desc->SecType = 0x3;
2289 //tx_desc->NoEnc = 0;//92su del
2292 tx_desc->SecType = 0x0;
2293 //tx_desc->NoEnc = 1;//92su del
2296 tx_desc->SecType = 0x0;
2297 //tx_desc->NoEnc = 1;//92su del
2302 //tx_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);//92su del
2305 tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
2306 tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
2307 tx_desc->DataRateFBLmt = 0x1F;// Alwasy enable all rate fallback range
2309 tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
2312 /* Fill fields that are required to be initialized in all of the descriptors */
2314 tx_desc->FirstSeg = 1;
2315 tx_desc->LastSeg = 1;
2320 //tx_desc->TxBufferSize = (u32)(skb->len - USB_HWDESC_HEADER_LEN);
2321 tx_desc->TxBufferSize = (u32)(skb->len);//92su mod FIXLZM
2324 /* Get index to out pipe from specified QueueID */
2325 idx_pipe = txqueue2outpipe(priv,tcb_desc->queue_index);
2326 //printk("=============>%s queue_index:%d, outpipe:%d\n", __func__,tcb_desc->queue_index,priv->RtOutPipes[idx_pipe]);
2328 //RT_DEBUG_DATA(COMP_SEND,tx_fwinfo,sizeof(tx_fwinfo_819x_usb));
2329 //RT_DEBUG_DATA(COMP_SEND,tx_desc,sizeof(tx_desc_819x_usb));
2331 /* To submit bulk urb */
2332 usb_fill_bulk_urb(tx_urb,
2334 usb_sndbulkpipe(udev,priv->RtOutPipes[idx_pipe]),
2336 skb->len, rtl8192_tx_isr, skb);
2338 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
2340 //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
2341 bool bSend0Byte = false;
2343 if(udev->speed == USB_SPEED_HIGH)
2345 if (skb->len > 0 && skb->len % 512 == 0)
2350 if (skb->len > 0 && skb->len % 64 == 0)
2356 tx_urb_zero = usb_alloc_urb(0,GFP_ATOMIC);
2358 RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
2361 usb_fill_bulk_urb(tx_urb_zero,udev,
2362 usb_sndbulkpipe(udev,idx_pipe), &zero,
2363 0, tx_zero_isr, dev);
2364 status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
2366 RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
2371 dev->trans_start = jiffies;
2372 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
2375 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
2381 void rtl8192SU_net_update(struct net_device *dev)
2384 struct r8192_priv *priv = ieee80211_priv(dev);
2385 struct ieee80211_device* ieee = priv->ieee80211;
2386 struct ieee80211_network *net = &priv->ieee80211->current_network;
2387 //u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
2388 u16 rate_config = 0;
2391 u8 retrylimit = 0x30;
2392 u16 cap = net->capability;
2394 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
2397 //update Basic rate: RR, BRSR
2398 rtl8192_config_rate(dev, &rate_config); //HalSetBrateCfg
2400 priv->basic_rate = rate_config = rate_config & 0x15f;
2402 // Set RRSR rate table.
2403 write_nic_byte(dev, RRSR, rate_config&0xff);
2404 write_nic_byte(dev, RRSR+1, (rate_config>>8)&0xff);
2406 // Set RTS initial rate
2407 while(rate_config > 0x1)
2409 rate_config = (rate_config>> 1);
2412 write_nic_byte(dev, INIRTSMCS_SEL, rateIndex);
2416 regTmp = (priv->nCur40MhzPrimeSC) << 5;
2417 if (priv->short_preamble)
2419 write_nic_byte(dev, RRSR+2, regTmp);
2421 write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
2422 write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
2424 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
2425 //2008.10.24 added by tynli for beacon changed.
2426 PHY_SetBeaconHwReg( dev, net->beacon_interval);
2428 rtl8192_update_cap(dev, cap);
2430 if (ieee->iw_mode == IW_MODE_ADHOC){
2432 //we should enable ibss interrupt here, but disable it temporarily
2434 priv->irq_mask |= (IMR_BcnInt | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2435 //rtl8192_irq_disable(dev);
2436 //rtl8192_irq_enable(dev);
2441 priv->irq_mask &= ~(IMR_BcnInt | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
2442 //rtl8192_irq_disable(dev);
2443 //rtl8192_irq_enable(dev);
2447 priv->ShortRetryLimit = priv->LongRetryLimit = retrylimit;
2449 write_nic_word(dev, RETRY_LIMIT,
2450 retrylimit << RETRY_LIMIT_SHORT_SHIFT | \
2451 retrylimit << RETRY_LIMIT_LONG_SHIFT);
2454 void rtl8192SU_update_ratr_table(struct net_device* dev)
2456 struct r8192_priv* priv = ieee80211_priv(dev);
2457 struct ieee80211_device* ieee = priv->ieee80211;
2458 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
2459 //struct ieee80211_network *net = &ieee->current_network;
2463 int WirelessMode = ieee->mode;
2464 u8 MimoPs = ieee->pHTInfo->PeerMimoPs;
2468 rtl8192_config_rate(dev, (u16*)(&ratr_value));
2469 ratr_value |= (*(u16*)(pMcsRate)) << 12;
2471 //switch (ieee->mode)
2472 switch (WirelessMode)
2475 ratr_value &= 0x00000FF0;
2478 ratr_value &= 0x0000000D;
2481 ratr_value &= 0x00000FF5;
2488 if (MimoPs == 0) //MIMO_PS_STATIC
2490 ratr_value &= 0x0007F005;
2493 { // MCS rate only => for 11N mode.
2496 // 1T2R or 1T1R, Spatial Stream 2 should be disabled
2497 if ( priv->rf_type == RF_1T2R ||
2498 priv->rf_type == RF_1T1R ||
2499 (ieee->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_TX_2SS) )
2500 ratr_mask = 0x000ff005;
2502 ratr_mask = 0x0f0ff005;
2504 if((ieee->pHTInfo->bCurTxBW40MHz) &&
2505 !(ieee->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_TX_40_MHZ))
2506 ratr_mask |= 0x00000010; // Set 6MBps
2508 // Select rates for rate adaptive mechanism.
2509 ratr_value &= ratr_mask;
2516 if(priv->rf_type == RF_1T2R) // 1T2R, Spatial Stream 2 should be disabled
2518 ratr_value &= 0x000ff0f5;
2522 ratr_value &= 0x0f0ff0f5;
2525 //printk("====>%s(), mode is not correct:%x\n", __FUNCTION__, ieee->mode);
2529 ratr_value &= 0x0FFFFFFF;
2531 // Get MAX MCS available.
2532 if ( (bNMode && ((ieee->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_SHORT_GI)==0)) &&
2533 ((ieee->pHTInfo->bCurBW40MHz && ieee->pHTInfo->bCurShortGI40MHz) ||
2534 (!ieee->pHTInfo->bCurBW40MHz && ieee->pHTInfo->bCurShortGI20MHz)))
2536 u8 shortGI_rate = 0;
2537 u32 tmp_ratr_value = 0;
2538 ratr_value |= 0x10000000;//???
2539 tmp_ratr_value = (ratr_value>>12);
2540 for(shortGI_rate=15; shortGI_rate>0; shortGI_rate--)
2542 if((1<<shortGI_rate) & tmp_ratr_value)
2545 shortGI_rate = (shortGI_rate<<12)|(shortGI_rate<<8)|(shortGI_rate<<4)|(shortGI_rate);
2546 write_nic_byte(dev, SG_RATE, shortGI_rate);
2547 //printk("==>SG_RATE:%x\n", read_nic_byte(dev, SG_RATE));
2549 write_nic_dword(dev, ARFR0+rate_index*4, ratr_value);
2550 printk("=============>ARFR0+rate_index*4:%#x\n", ratr_value);
2553 if (ratr_value & 0xfffff000){
2554 //printk("===>set to N mode\n");
2555 HalSetFwCmd8192S(dev, FW_CMD_RA_REFRESH_N);
2558 //printk("===>set to B/G mode\n");
2559 HalSetFwCmd8192S(dev, FW_CMD_RA_REFRESH_BG);
2563 void rtl8192SU_link_change(struct net_device *dev)
2565 struct r8192_priv *priv = ieee80211_priv(dev);
2566 struct ieee80211_device* ieee = priv->ieee80211;
2567 //unsigned long flags;
2570 printk("=====>%s 1\n", __func__);
2571 reg = read_nic_dword(dev, RCR);
2573 if (ieee->state == IEEE80211_LINKED)
2576 rtl8192SU_net_update(dev);
2577 rtl8192SU_update_ratr_table(dev);
2578 ieee->SetFwCmdHandler(dev, FW_CMD_HIGH_PWR_ENABLE);
2579 priv->ReceiveConfig = reg |= RCR_CBSSID;
2582 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
2586 write_nic_dword(dev, RCR, reg);
2587 rtl8192_update_msr(dev);
2589 printk("<=====%s 2\n", __func__);
2592 static struct ieee80211_qos_parameters def_qos_parameters = {
2593 {3,3,3,3},/* cw_min */
2594 {7,7,7,7},/* cw_max */
2595 {2,2,2,2},/* aifs */
2596 {0,0,0,0},/* flags */
2597 {0,0,0,0} /* tx_op_limit */
2601 void rtl8192_update_beacon(struct work_struct * work)
2603 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
2604 struct net_device *dev = priv->ieee80211->dev;
2605 struct ieee80211_device* ieee = priv->ieee80211;
2606 struct ieee80211_network* net = &ieee->current_network;
2608 if (ieee->pHTInfo->bCurrentHTSupport)
2609 HTUpdateSelfAndPeerSetting(ieee, net);
2610 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
2611 // Joseph test for turbo mode with AP
2612 ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
2613 rtl8192_update_cap(dev, net->capability);
2616 * background support to run QoS activate functionality
2618 int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
2620 void rtl8192_qos_activate(struct work_struct * work)
2622 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
2623 struct net_device *dev = priv->ieee80211->dev;
2624 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
2625 u8 mode = priv->ieee80211->current_network.mode;
2626 //u32 size = sizeof(struct ieee80211_qos_parameters);
2634 mutex_lock(&priv->mutex);
2636 if(priv->ieee80211->state != IEEE80211_LINKED)
2638 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
2639 /* It better set slot time at first */
2640 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
2641 /* update the ac parameter to related registers */
2642 for(i = 0; i < QOS_QUEUE_NUM; i++) {
2643 //Mode G/A: slotTimeTimer = 9; Mode B: 20
2644 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
2645 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
2646 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
2647 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
2648 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2650 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2651 //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4322);
2655 mutex_unlock(&priv->mutex);
2658 static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
2660 struct ieee80211_network *network)
2663 u32 size = sizeof(struct ieee80211_qos_parameters);
2665 if(priv->ieee80211->state !=IEEE80211_LINKED)
2668 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2671 if (network->flags & NETWORK_HAS_QOS_MASK) {
2672 if (active_network &&
2673 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
2674 network->qos_data.active = network->qos_data.supported;
2676 if ((network->qos_data.active == 1) && (active_network == 1) &&
2677 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
2678 (network->qos_data.old_param_count !=
2679 network->qos_data.param_count)) {
2680 network->qos_data.old_param_count =
2681 network->qos_data.param_count;
2682 queue_work(priv->priv_wq, &priv->qos_activate);
2683 RT_TRACE (COMP_QOS, "QoS parameters change call "
2687 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2688 &def_qos_parameters, size);
2690 if ((network->qos_data.active == 1) && (active_network == 1)) {
2691 queue_work(priv->priv_wq, &priv->qos_activate);
2692 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
2694 network->qos_data.active = 0;
2695 network->qos_data.supported = 0;
2701 /* handle manage frame frame beacon and probe response */
2702 static int rtl8192_handle_beacon(struct net_device * dev,
2703 struct ieee80211_probe_response *beacon,
2704 struct ieee80211_network *network)
2706 struct r8192_priv *priv = ieee80211_priv(dev);
2708 rtl8192_qos_handle_probe_response(priv,1,network);
2709 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
2716 * handling the beaconing responses. if we get different QoS setting
2717 * off the network from the associated setting, adjust the QoS
2720 static int rtl8192_qos_association_resp(struct r8192_priv *priv,
2721 struct ieee80211_network *network)
2724 unsigned long flags;
2725 u32 size = sizeof(struct ieee80211_qos_parameters);
2726 int set_qos_param = 0;
2728 if ((priv == NULL) || (network == NULL))
2731 if(priv->ieee80211->state !=IEEE80211_LINKED)
2734 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
2737 spin_lock_irqsave(&priv->ieee80211->lock, flags);
2738 if(network->flags & NETWORK_HAS_QOS_PARAMETERS) {
2739 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2740 &network->qos_data.parameters,\
2741 sizeof(struct ieee80211_qos_parameters));
2742 priv->ieee80211->current_network.qos_data.active = 1;
2745 /* update qos parameter for current network */
2746 priv->ieee80211->current_network.qos_data.old_param_count = \
2747 priv->ieee80211->current_network.qos_data.param_count;
2748 priv->ieee80211->current_network.qos_data.param_count = \
2749 network->qos_data.param_count;
2752 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
2753 &def_qos_parameters, size);
2754 priv->ieee80211->current_network.qos_data.active = 0;
2755 priv->ieee80211->current_network.qos_data.supported = 0;
2759 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
2761 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active);
2762 if (set_qos_param == 1)
2763 queue_work(priv->priv_wq, &priv->qos_activate);
2769 static int rtl8192_handle_assoc_response(struct net_device *dev,
2770 struct ieee80211_assoc_response_frame *resp,
2771 struct ieee80211_network *network)
2773 struct r8192_priv *priv = ieee80211_priv(dev);
2774 rtl8192_qos_association_resp(priv, network);
2779 void rtl8192_update_ratr_table(struct net_device* dev)
2780 // POCTET_STRING posLegacyRate,
2782 // PRT_WLAN_STA pEntry)
2784 struct r8192_priv* priv = ieee80211_priv(dev);
2785 struct ieee80211_device* ieee = priv->ieee80211;
2786 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
2787 //struct ieee80211_network *net = &ieee->current_network;
2790 rtl8192_config_rate(dev, (u16*)(&ratr_value));
2791 ratr_value |= (*(u16*)(pMcsRate)) << 12;
2792 // switch (net->mode)
2796 ratr_value &= 0x00000FF0;
2799 ratr_value &= 0x0000000F;
2802 ratr_value &= 0x00000FF7;
2806 if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
2807 ratr_value &= 0x0007F007;
2809 if (priv->rf_type == RF_1T2R)
2810 ratr_value &= 0x000FF007;
2812 ratr_value &= 0x0F81F007;
2818 ratr_value &= 0x0FFFFFFF;
2819 if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
2820 ratr_value |= 0x80000000;
2821 }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
2822 ratr_value |= 0x80000000;
2824 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
2825 write_nic_byte(dev, UFWP, 1);
2828 static u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
2829 static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
2830 bool GetNmodeSupportBySecCfg8192(struct net_device*dev)
2833 struct r8192_priv* priv = ieee80211_priv(dev);
2834 struct ieee80211_device* ieee = priv->ieee80211;
2835 struct ieee80211_network * network = &ieee->current_network;
2836 int wpa_ie_len= ieee->wpa_ie_len;
2837 struct ieee80211_crypt_data* crypt;
2841 crypt = ieee->crypt[ieee->tx_keyidx];
2842 //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
2843 encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP")));
2846 if(encrypt && (wpa_ie_len == 0)) {
2847 /* wep encryption, no N mode setting */
2849 // } else if((wpa_ie_len != 0)&&(memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) {
2850 } else if((wpa_ie_len != 0)) {
2851 /* parse pairwise key type */
2852 //if((pairwisekey = WEP40)||(pairwisekey = WEP104)||(pairwisekey = TKIP))
2853 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))))
2865 bool GetHalfNmodeSupportByAPs819xUsb(struct net_device* dev)
2868 struct r8192_priv* priv = ieee80211_priv(dev);
2869 struct ieee80211_device* ieee = priv->ieee80211;
2871 // Added by Roger, 2008.08.29.
2874 if(ieee->bHalfWirelessN24GMode == true)
2882 void rtl8192_refresh_supportrate(struct r8192_priv* priv)
2884 struct ieee80211_device* ieee = priv->ieee80211;
2885 //we donot consider set support rate for ABG mode, only HT MCS rate is set here.
2886 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
2888 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
2889 //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16);
2890 //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16);
2893 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
2897 u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
2899 struct r8192_priv *priv = ieee80211_priv(dev);
2901 switch(priv->rf_chip)
2907 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
2910 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
2913 ret = WIRELESS_MODE_B;
2918 void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
2920 struct r8192_priv *priv = ieee80211_priv(dev);
2921 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
2924 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
2926 if(bSupportMode & WIRELESS_MODE_N_24G)
2928 wireless_mode = WIRELESS_MODE_N_24G;
2930 else if(bSupportMode & WIRELESS_MODE_N_5G)
2932 wireless_mode = WIRELESS_MODE_N_5G;
2934 else if((bSupportMode & WIRELESS_MODE_A))
2936 wireless_mode = WIRELESS_MODE_A;
2938 else if((bSupportMode & WIRELESS_MODE_G))
2940 wireless_mode = WIRELESS_MODE_G;
2942 else if((bSupportMode & WIRELESS_MODE_B))
2944 wireless_mode = WIRELESS_MODE_B;
2947 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
2948 wireless_mode = WIRELESS_MODE_B;
2951 #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we shoud wait for FPGA
2952 ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting );
2954 //LZM 090306 usb crash here, mark it temp
2955 //write_nic_word(dev, SIFS_OFDM, 0x0e0e);
2956 priv->ieee80211->mode = wireless_mode;
2958 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
2959 priv->ieee80211->pHTInfo->bEnableHT = 1;
2961 priv->ieee80211->pHTInfo->bEnableHT = 0;
2962 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
2963 rtl8192_refresh_supportrate(priv);
2969 short rtl8192_is_tx_queue_empty(struct net_device *dev)
2972 struct r8192_priv *priv = ieee80211_priv(dev);
2973 //struct ieee80211_device* ieee = priv->ieee80211;
2974 for (i=0; i<=MGNT_QUEUE; i++)
2976 if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) )
2978 if (atomic_read(&priv->tx_pending[i]))
2980 printk("===>tx queue is not empty:%d, %d\n", i, atomic_read(&priv->tx_pending[i]));
2987 void rtl8192_hw_sleep_down(struct net_device *dev)
2989 RT_TRACE(COMP_POWER, "%s()============>come to sleep down\n", __FUNCTION__);
2991 // MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
2995 void rtl8192_hw_sleep_wq (struct work_struct *work)
2997 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
2998 // struct ieee80211_device * ieee = (struct ieee80211_device*)
2999 // container_of(work, struct ieee80211_device, watch_dog_wq);
3000 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3001 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
3002 struct net_device *dev = ieee->dev;
3004 //printk("=========>%s()\n", __FUNCTION__);
3005 rtl8192_hw_sleep_down(dev);
3007 // printk("dev is %d\n",dev);
3008 // printk("&*&(^*(&(&=========>%s()\n", __FUNCTION__);
3009 void rtl8192_hw_wakeup(struct net_device* dev)
3013 // spin_lock_irqsave(&priv->ps_lock,flags);
3014 RT_TRACE(COMP_POWER, "%s()============>come to wake up\n", __FUNCTION__);
3016 // MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
3018 //FIXME: will we send package stored while nic is sleep?
3019 // spin_unlock_irqrestore(&priv->ps_lock,flags);
3022 void rtl8192_hw_wakeup_wq (struct work_struct *work)
3024 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
3025 // struct ieee80211_device * ieee = (struct ieee80211_device*)
3026 // container_of(work, struct ieee80211_device, watch_dog_wq);
3027 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3028 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
3029 struct net_device *dev = ieee->dev;
3031 rtl8192_hw_wakeup(dev);
3034 #define MIN_SLEEP_TIME 50
3035 #define MAX_SLEEP_TIME 10000
3036 void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
3039 struct r8192_priv *priv = ieee80211_priv(dev);
3042 unsigned long flags;
3044 spin_lock_irqsave(&priv->ps_lock,flags);
3046 /* Writing HW register with 0 equals to disable
3047 * the timer, that is not really what we want
3049 tl -= MSECS(4+16+7);
3051 //if(tl == 0) tl = 1;
3053 /* FIXME HACK FIXME HACK */
3054 // force_pci_posting(dev);
3057 // rb = read_nic_dword(dev, TSFTR);
3059 /* If the interval in witch we are requested to sleep is too
3060 * short then give up and remain awake
3062 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
3063 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
3064 spin_unlock_irqrestore(&priv->ps_lock,flags);
3065 printk("too short to sleep\n");
3069 // write_nic_dword(dev, TimerInt, tl);
3070 // rb = read_nic_dword(dev, TSFTR);
3072 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
3075 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp); //as tl may be less than rb
3077 /* if we suspect the TimerInt is gone beyond tl
3078 * while setting it, then give up
3081 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
3082 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
3083 printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME));
3084 spin_unlock_irqrestore(&priv->ps_lock,flags);
3088 // if(priv->rf_sleep)
3089 // priv->rf_sleep(dev);
3091 //printk("<=========%s()\n", __FUNCTION__);
3092 queue_delayed_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq,0);
3094 spin_unlock_irqrestore(&priv->ps_lock,flags);
3096 //init priv variables here. only non_zero value should be initialized here.
3097 static void rtl8192_init_priv_variable(struct net_device* dev)
3099 struct r8192_priv *priv = ieee80211_priv(dev);
3101 priv->card_8192 = NIC_8192U;
3102 priv->chan = 1; //set to channel 1
3103 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
3104 priv->ieee80211->iw_mode = IW_MODE_INFRA;
3105 priv->ieee80211->ieee_up=0;
3106 priv->retry_rts = DEFAULT_RETRY_RTS;
3107 priv->retry_data = DEFAULT_RETRY_DATA;
3108 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
3109 priv->ieee80211->rate = 110; //11 mbps
3110 priv->ieee80211->short_slot = 1;
3111 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
3114 priv->IrpPendingCount = 1;
3115 priv->ResetProgress = RESET_TYPE_NORESET;
3116 priv->bForcedSilentReset = 0;
3117 priv->bDisableNormalResetCheck = false;
3118 priv->force_reset = false;
3120 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available.
3121 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
3122 priv->ieee80211->iw_mode = IW_MODE_INFRA;
3123 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
3124 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
3125 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
3126 IEEE_SOFTMAC_BEACONS;//added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE;
3128 priv->ieee80211->active_scan = 1;
3129 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
3130 priv->ieee80211->host_encrypt = 1;
3131 priv->ieee80211->host_decrypt = 1;
3132 priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
3133 priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
3134 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
3135 priv->ieee80211->set_chan = rtl8192_set_chan;
3136 priv->ieee80211->link_change = priv->ops->rtl819x_link_change;
3137 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
3138 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
3139 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
3140 priv->ieee80211->init_wmmparam_flag = 0;
3141 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
3142 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
3143 priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
3144 priv->ieee80211->qos_support = 1;
3147 // priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
3148 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
3149 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
3150 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
3152 priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup;
3153 // priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack;
3154 priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep;
3155 priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
3157 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
3158 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xUsb;
3159 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
3161 priv->ieee80211->InitialGainHandler = priv->ops->rtl819x_initial_gain;
3162 priv->card_type = USB;
3165 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
3166 priv->ieee80211->SetFwCmdHandler = HalSetFwCmd8192S;
3167 priv->bRFSiOrPi = 0;//o=si,1=pi;
3169 priv->bInHctTest = false;
3171 priv->MidHighPwrTHR_L1 = 0x3B;
3172 priv->MidHighPwrTHR_L2 = 0x40;
3174 if(priv->bInHctTest)
3176 priv->ShortRetryLimit = HAL_RETRY_LIMIT_AP_ADHOC;
3177 priv->LongRetryLimit = HAL_RETRY_LIMIT_AP_ADHOC;
3181 priv->ShortRetryLimit = HAL_RETRY_LIMIT_INFRA;
3182 priv->LongRetryLimit = HAL_RETRY_LIMIT_INFRA;
3185 priv->SetFwCmdInProgress = false; //is set FW CMD in Progress? 92S only
3186 priv->CurrentFwCmdIO = 0;
3188 priv->MinSpaceCfg = 0;
3190 priv->EarlyRxThreshold = 7;
3191 priv->enable_gpio0 = 0;
3192 priv->TransmitConfig =
3193 ((u32)TCR_MXDMA_2048<<TCR_MXDMA_OFFSET) | // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
3194 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | // Short retry limit
3195 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
3196 (false ? TCR_SAT : 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
3197 if(priv->bInHctTest)
3198 priv->ReceiveConfig = //priv->CSMethod |
3199 RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data
3200 RCR_ACF |RCR_APPFCS| //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
3201 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
3202 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
3203 RCR_APP_PHYST_STAFF | RCR_APP_PHYST_RXFF | // Accept PHY status
3204 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
3205 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
3206 (priv->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0);
3208 priv->ReceiveConfig = //priv->CSMethod |
3209 RCR_AMF | RCR_ADF | RCR_AB |
3210 RCR_AM | RCR_APM |RCR_AAP |RCR_ADD3|RCR_APP_ICV|
3211 RCR_APP_PHYST_STAFF | RCR_APP_PHYST_RXFF | // Accept PHY status
3212 RCR_APP_MIC | RCR_APPFCS;
3214 // <Roger_EXP> 2008.06.16.
3215 priv->IntrMask = (u16)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK | \
3216 IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK | \
3217 IMR_BDOK | IMR_RXCMDOK | /*IMR_TIMEOUT0 |*/ IMR_RDU | IMR_RXFOVW | \
3218 IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
3223 priv->AcmControl = 0;
3224 priv->pFirmware = (rt_firmware*)vmalloc(sizeof(rt_firmware));
3225 if (priv->pFirmware)
3226 memset(priv->pFirmware, 0, sizeof(rt_firmware));
3228 /* rx related queue */
3229 skb_queue_head_init(&priv->rx_queue);
3230 skb_queue_head_init(&priv->skb_queue);
3232 /* Tx related queue */
3233 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3234 skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
3236 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3237 skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
3239 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3240 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ [i]);
3242 priv->rf_set_chan = rtl8192_phy_SwChnl;
3246 static void rtl8192_init_priv_lock(struct r8192_priv* priv)
3248 spin_lock_init(&priv->tx_lock);
3249 spin_lock_init(&priv->irq_lock);//added by thomas
3250 //spin_lock_init(&priv->rf_lock);//use rf_sem, or will crash in some OS.
3251 sema_init(&priv->wx_sem,1);
3252 sema_init(&priv->rf_sem,1);
3253 spin_lock_init(&priv->ps_lock);
3254 mutex_init(&priv->mutex);
3257 extern void rtl819x_watchdog_wqcallback(struct work_struct *work);
3259 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
3260 //init tasklet and wait_queue here. only 2.6 above kernel is considered
3261 #define DRV_NAME "wlan0"
3262 static void rtl8192_init_priv_task(struct net_device* dev)
3264 struct r8192_priv *priv = ieee80211_priv(dev);
3266 #ifdef PF_SYNCTHREAD
3267 priv->priv_wq = create_workqueue(DRV_NAME,0);
3269 priv->priv_wq = create_workqueue(DRV_NAME);
3272 INIT_WORK(&priv->reset_wq, rtl8192_restart);
3274 //INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
3275 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
3276 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
3277 // INIT_DELAYED_WORK(&priv->gpio_change_rf_wq, dm_gpio_change_rf_callback);
3278 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
3279 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
3280 INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
3281 //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem);
3282 //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem);
3283 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
3284 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq);
3285 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq);
3287 tasklet_init(&priv->irq_rx_tasklet,
3288 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
3289 (unsigned long)priv);
3292 static void rtl8192_get_eeprom_size(struct net_device* dev)
3295 struct r8192_priv *priv = ieee80211_priv(dev);
3296 RT_TRACE(COMP_EPROM, "===========>%s()\n", __FUNCTION__);
3297 curCR = read_nic_word_E(dev,EPROM_CMD);
3298 RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
3299 //whether need I consider BIT5?
3300 priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
3301 RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
3304 //used to swap endian. as ntohl & htonl are not neccessary to swap endian, so use this instead.
3305 static inline u16 endian_swap(u16* data)
3308 *data = (tmp >> 8) | (tmp << 8);
3312 u8 rtl8192SU_UsbOptionToEndPointNumber(u8 UsbOption)
3327 RT_TRACE(COMP_INIT, "UsbOptionToEndPointNumber(): Invalid UsbOption(%#x)\n", UsbOption);
3333 u8 rtl8192SU_BoardTypeToRFtype(struct net_device* dev, u8 Boardtype)
3335 u8 RFtype = RF_1T2R;
3349 RFtype = RF_2T2R_GREEN;
3360 // Config HW adapter information into initial value.
3363 // 1. After Auto load fail(i.e, check CR9346 fail)
3365 // Created by Roger, 2008.10.21.
3368 rtl8192SU_ConfigAdapterInfo8192SForAutoLoadFail(struct net_device* dev)
3370 struct r8192_priv *priv = ieee80211_priv(dev);
3372 //u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x92, 0x00};
3373 u8 rf_path, index; // For EEPROM/EFUSE After V0.6_1117
3376 RT_TRACE(COMP_INIT, "====> ConfigAdapterInfo8192SForAutoLoadFail\n");
3378 write_nic_byte(dev, SYS_ISO_CTRL+1, 0xE8); // Isolation signals from Loader
3379 //PlatformStallExecution(10000);
3381 write_nic_byte(dev, PMC_FSM, 0x02); // Enable Loader Data Keep
3383 //RT_ASSERT(priv->AutoloadFailFlag==TRUE, ("ReadAdapterInfo8192SEEPROM(): AutoloadFailFlag !=TRUE\n"));
3385 // Initialize IC Version && Channel Plan
3386 priv->eeprom_vid = 0;
3387 priv->eeprom_pid = 0;
3388 priv->card_8192_version = 0;
3389 priv->eeprom_ChannelPlan = 0;
3390 priv->eeprom_CustomerID = 0;
3391 priv->eeprom_SubCustomerID = 0;
3392 priv->bIgnoreDiffRateTxPowerOffset = false;
3394 RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
3395 RT_TRACE(COMP_INIT, "EEPROM PID = 0x%4x\n", priv->eeprom_pid);
3396 RT_TRACE(COMP_INIT, "EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID);
3397 RT_TRACE(COMP_INIT, "EEPROM SubCustomer ID: 0x%2x\n", priv->eeprom_SubCustomerID);
3398 RT_TRACE(COMP_INIT, "EEPROM ChannelPlan = 0x%4x\n", priv->eeprom_ChannelPlan);
3399 RT_TRACE(COMP_INIT, "IgnoreDiffRateTxPowerOffset = %d\n", priv->bIgnoreDiffRateTxPowerOffset);
3403 priv->EEPROMUsbOption = EEPROM_USB_Default_OPTIONAL_FUNC;
3404 RT_TRACE(COMP_INIT, "USB Option = %#x\n", priv->EEPROMUsbOption);
3407 priv->EEPROMUsbPhyParam[i] = EEPROM_USB_Default_PHY_PARAM;
3409 //RT_PRINT_DATA(COMP_INIT|COMP_EFUSE, DBG_LOUD, ("EFUSE USB PHY Param: \n"), priv->EEPROMUsbPhyParam, 5);
3412 //<Roger_Notes> In this case, we random assigh MAC address here. 2008.10.15.
3413 static u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x92, 0x00};
3416 //sMacAddr[5] = (u8)GetRandomNumber(1, 254);
3418 for(i = 0; i < 6; i++)
3419 dev->dev_addr[i] = sMacAddr[i];
3421 //NicIFSetMacAddress(Adapter, Adapter->PermanentAddress);
3422 write_nic_dword(dev, IDR0, ((u32*)dev->dev_addr)[0]);
3423 write_nic_word(dev, IDR4, ((u16*)(dev->dev_addr + 4))[0]);
3425 RT_TRACE(COMP_INIT, "ReadAdapterInfo8192SEFuse(), Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x\n",
3426 dev->dev_addr[0], dev->dev_addr[1],
3427 dev->dev_addr[2], dev->dev_addr[3],
3428 dev->dev_addr[4], dev->dev_addr[5]);
3430 priv->EEPROMBoardType = EEPROM_Default_BoardType;
3431 priv->rf_type = RF_1T2R; //RF_2T2R
3432 priv->EEPROMTxPowerDiff = EEPROM_Default_PwDiff;
3433 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
3434 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
3435 priv->EEPROMTxPwrBase = EEPROM_Default_TxPowerBase;
3436 priv->EEPROMTSSI_A = EEPROM_Default_TSSI;
3437 priv->EEPROMTSSI_B = EEPROM_Default_TSSI;
3438 priv->EEPROMTxPwrTkMode = EEPROM_Default_TxPwrTkMode;
3442 for (rf_path = 0; rf_path < 2; rf_path++)
3444 for (i = 0; i < 3; i++)
3446 // Read CCK RF A & B Tx power
3447 priv->RfCckChnlAreaTxPwr[rf_path][i] =
3448 priv->RfOfdmChnlAreaTxPwr1T[rf_path][i] =
3449 priv->RfOfdmChnlAreaTxPwr2T[rf_path][i] =
3450 (u8)(EEPROM_Default_TxPower & 0xff);
3454 for (i = 0; i < 3; i++)
3456 //RT_TRACE((COMP_EFUSE), "CCK RF-%d CHan_Area-%d = 0x%x\n", rf_path, i,
3457 //priv->RfCckChnlAreaTxPwr[rf_path][i]);
3458 //RT_TRACE((COMP_EFUSE), "OFDM-1T RF-%d CHan_Area-%d = 0x%x\n", rf_path, i,
3459 //priv->RfOfdmChnlAreaTxPwr1T[rf_path][i]);
3460 //RT_TRACE((COMP_EFUSE), "OFDM-2T RF-%d CHan_Area-%d = 0x%x\n", rf_path, i,
3461 //priv->RfOfdmChnlAreaTxPwr2T[rf_path][i]);
3464 // Assign dedicated channel tx power
3465 for(i=0; i<14; i++) // channel 1~3 use the same Tx Power Level.
3467 if (i < 3) // Cjanel 1-3
3469 else if (i < 9) // Channel 4-9
3471 else // Channel 10-14
3474 // Record A & B CCK /OFDM - 1T/2T Channel area tx power
3475 priv->RfTxPwrLevelCck[rf_path][i] =
3476 priv->RfCckChnlAreaTxPwr[rf_path][index];
3477 priv->RfTxPwrLevelOfdm1T[rf_path][i] =
3478 priv->RfOfdmChnlAreaTxPwr1T[rf_path][index];
3479 priv->RfTxPwrLevelOfdm2T[rf_path][i] =
3480 priv->RfOfdmChnlAreaTxPwr2T[rf_path][index];
3485 //RT_TRACE((COMP_EFUSE), "Rf-%d TxPwr CH-%d CCK OFDM_1T OFDM_2T= 0x%x/0x%x/0x%x\n",
3486 //rf_path, i, priv->RfTxPwrLevelCck[0][i],
3487 //priv->RfTxPwrLevelOfdm1T[0][i] ,
3488 //priv->RfTxPwrLevelOfdm2T[0][i] );
3492 // Update remained HAL variables.
3494 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
3495 priv->LegacyHTTxPowerDiff = priv->EEPROMTxPowerDiff;//new
3496 priv->TxPowerDiff = priv->EEPROMTxPowerDiff;
3497 //priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);// Antenna B gain offset to antenna A, bit0~3
3498 //priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);// Antenna C gain offset to antenna A, bit4~7
3499 priv->CrystalCap = priv->EEPROMCrystalCap; // CrystalCap, bit12~15
3500 priv->ThermalMeter[0] = priv->EEPROMThermalMeter;// ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
3501 priv->LedStrategy = SW_LED_MODE0;
3503 init_rate_adaptive(dev);
3505 RT_TRACE(COMP_INIT, "<==== ConfigAdapterInfo8192SForAutoLoadFail\n");
3511 // Read HW adapter information by E-Fuse or EEPROM according CR9346 reported.
3514 // 1. CR9346 regiser has verified.
3515 // 2. PASSIVE_LEVEL (USB interface)
3517 // Created by Roger, 2008.10.21.
3520 rtl8192SU_ReadAdapterInfo8192SUsb(struct net_device* dev)
3522 struct r8192_priv *priv = ieee80211_priv(dev);
3526 u8 hwinfo[HWSET_MAX_SIZE_92S];
3527 u8 rf_path, index; // For EEPROM/EFUSE After V0.6_1117
3530 RT_TRACE(COMP_INIT, "====> ReadAdapterInfo8192SUsb\n");
3533 // <Roger_Note> The following operation are prevent Efuse leakage by turn on 2.5V.
3536 tmpU1b = read_nic_byte(dev, EFUSE_TEST+3);
3537 write_nic_byte(dev, EFUSE_TEST+3, tmpU1b|0x80);
3538 //PlatformStallExecution(1000);
3540 write_nic_byte(dev, EFUSE_TEST+3, (tmpU1b&(~BIT7)));
3542 // Retrieve Chip version.
3543 priv->card_8192_version = (VERSION_8192S)((read_nic_dword(dev, PMC_FSM)>>16)&0xF);
3544 RT_TRACE(COMP_INIT, "Chip Version ID: 0x%2x\n", priv->card_8192_version);
3546 switch(priv->card_8192_version)
3549 RT_TRACE(COMP_INIT, "Chip Version ID: VERSION_8192S_ACUT.\n");
3552 RT_TRACE(COMP_INIT, "Chip Version ID: VERSION_8192S_BCUT.\n");
3555 RT_TRACE(COMP_INIT, "Chip Version ID: VERSION_8192S_CCUT.\n");
3558 RT_TRACE(COMP_INIT, "Unknown Chip Version!!\n");
3559 priv->card_8192_version = VERSION_8192S_BCUT;
3563 //if (IS_BOOT_FROM_EEPROM(Adapter))
3564 if(priv->EepromOrEfuse)
3565 { // Read frin EEPROM
3566 write_nic_byte(dev, SYS_ISO_CTRL+1, 0xE8); // Isolation signals from Loader
3567 //PlatformStallExecution(10000);
3569 write_nic_byte(dev, PMC_FSM, 0x02); // Enable Loader Data Keep
3570 // Read all Content from EEPROM or EFUSE.
3571 for(i = 0; i < HWSET_MAX_SIZE_92S; i += 2)
3573 usValue = eprom_read(dev, (u16) (i>>1));
3574 *((u16*)(&hwinfo[i])) = usValue;
3577 else if (!(priv->EepromOrEfuse))
3578 { // Read from EFUSE
3581 // <Roger_Notes> We set Isolation signals from Loader and reset EEPROM after system resuming
3582 // from suspend mode.
3585 //PlatformEFIOWrite1Byte(Adapter, SYS_ISO_CTRL+1, 0xE8); // Isolation signals from Loader
3586 //PlatformStallExecution(10000);
3587 //PlatformEFIOWrite1Byte(Adapter, SYS_FUNC_EN+1, 0x40);
3588 //PlatformEFIOWrite1Byte(Adapter, SYS_FUNC_EN+1, 0x50);
3590 //tmpU1b = PlatformEFIORead1Byte(Adapter, EFUSE_TEST+3);
3591 //PlatformEFIOWrite1Byte(Adapter, EFUSE_TEST+3, (tmpU1b | 0x80));
3592 //PlatformEFIOWrite1Byte(Adapter, EFUSE_TEST+3, 0x72);
3593 //PlatformEFIOWrite1Byte(Adapter, EFUSE_CLK, 0x03);
3595 // Read EFUSE real map to shadow.
3596 EFUSE_ShadowMapUpdate(dev);
3597 memcpy(hwinfo, &priv->EfuseMap[EFUSE_INIT_MAP][0], HWSET_MAX_SIZE_92S);
3601 RT_TRACE(COMP_INIT, "ReadAdapterInfo8192SUsb(): Invalid boot type!!\n");
3605 //dump_buf(hwinfo,HWSET_MAX_SIZE_92S);
3607 // <Roger_Notes> The following are EFUSE/EEPROM independent operations!!
3609 //RT_PRINT_DATA(COMP_EFUSE, DBG_LOUD, ("MAP: \n"), hwinfo, HWSET_MAX_SIZE_92S);
3612 // <Roger_Notes> Event though CR9346 regiser can verify whether Autoload is success or not, but we still
3613 // double check ID codes for 92S here(e.g., due to HW GPIO polling fail issue).
3616 EEPROMId = *((u16 *)&hwinfo[0]);
3618 if( EEPROMId != RTL8190_EEPROM_ID )
3620 RT_TRACE(COMP_INIT, "ID(%#x) is invalid!!\n", EEPROMId);
3621 priv->bTXPowerDataReadFromEEPORM = FALSE;
3622 priv->AutoloadFailFlag=TRUE;
3626 priv->AutoloadFailFlag=FALSE;
3627 priv->bTXPowerDataReadFromEEPORM = TRUE;
3629 // Read IC Version && Channel Plan
3630 if(!priv->AutoloadFailFlag)
3633 priv->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
3634 priv->eeprom_pid = *(u16 *)&hwinfo[EEPROM_PID];
3635 priv->bIgnoreDiffRateTxPowerOffset = false; //cosa for test
3638 // EEPROM Version ID, Channel plan
3639 priv->EEPROMVersion = *(u8 *)&hwinfo[EEPROM_Version];
3640 priv->eeprom_ChannelPlan = *(u8 *)&hwinfo[EEPROM_ChannelPlan];
3642 // Customer ID, 0x00 and 0xff are reserved for Realtek.
3643 priv->eeprom_CustomerID = *(u8 *)&hwinfo[EEPROM_CustomID];
3644 priv->eeprom_SubCustomerID = *(u8 *)&hwinfo[EEPROM_SubCustomID];
3648 //priv->eeprom_vid = 0;
3649 //priv->eeprom_pid = 0;
3650 //priv->EEPROMVersion = 0;
3651 //priv->eeprom_ChannelPlan = 0;
3652 //priv->eeprom_CustomerID = 0;
3653 //priv->eeprom_SubCustomerID = 0;
3655 rtl8192SU_ConfigAdapterInfo8192SForAutoLoadFail(dev);
3660 RT_TRACE(COMP_INIT, "EEPROM Id = 0x%4x\n", EEPROMId);
3661 RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
3662 RT_TRACE(COMP_INIT, "EEPROM PID = 0x%4x\n", priv->eeprom_pid);
3663 RT_TRACE(COMP_INIT, "EEPROM Version ID: 0x%2x\n", priv->EEPROMVersion);
3664 RT_TRACE(COMP_INIT, "EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID);
3665 RT_TRACE(COMP_INIT, "EEPROM SubCustomer ID: 0x%2x\n", priv->eeprom_SubCustomerID);
3666 RT_TRACE(COMP_INIT, "EEPROM ChannelPlan = 0x%4x\n", priv->eeprom_ChannelPlan);
3667 RT_TRACE(COMP_INIT, "bIgnoreDiffRateTxPowerOffset = %d\n", priv->bIgnoreDiffRateTxPowerOffset);
3670 // Read USB optional function.
3671 if(!priv->AutoloadFailFlag)
3673 priv->EEPROMUsbOption = *(u8 *)&hwinfo[EEPROM_USB_OPTIONAL];
3677 priv->EEPROMUsbOption = EEPROM_USB_Default_OPTIONAL_FUNC;
3681 priv->EEPROMUsbEndPointNumber = rtl8192SU_UsbOptionToEndPointNumber((priv->EEPROMUsbOption&EEPROM_EP_NUMBER)>>3);
3683 RT_TRACE(COMP_INIT, "USB Option = %#x\n", priv->EEPROMUsbOption);
3684 RT_TRACE(COMP_INIT, "EndPoint Number = %#x\n", priv->EEPROMUsbEndPointNumber);
3688 // Decide CustomerID according to VID/DID or EEPROM
3690 switch(pHalData->EEPROMCustomerID)
3692 case EEPROM_CID_ALPHA:
3693 pMgntInfo->CustomerID = RT_CID_819x_ALPHA;
3696 case EEPROM_CID_CAMEO:
3697 pMgntInfo->CustomerID = RT_CID_819x_CAMEO;
3700 case EEPROM_CID_SITECOM:
3701 pMgntInfo->CustomerID = RT_CID_819x_Sitecom;
3702 RT_TRACE(COMP_INIT, DBG_LOUD, ("CustomerID = 0x%4x\n", pMgntInfo->CustomerID));
3706 case EEPROM_CID_WHQL:
3707 Adapter->bInHctTest = TRUE;
3709 pMgntInfo->bSupportTurboMode = FALSE;
3710 pMgntInfo->bAutoTurboBy8186 = FALSE;
3712 pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
3713 pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
3714 pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
3715 pMgntInfo->keepAliveLevel = 0;
3719 pMgntInfo->CustomerID = RT_CID_DEFAULT;
3727 switch(pMgntInfo->CustomerID)
3729 case RT_CID_DEFAULT:
3730 case RT_CID_819x_ALPHA:
3731 pHalData->LedStrategy = SW_LED_MODE1;
3732 pHalData->bRegUseLed = TRUE;
3733 pHalData->SwLed1.bLedOn = TRUE;
3735 case RT_CID_819x_CAMEO:
3736 pHalData->LedStrategy = SW_LED_MODE1;
3737 pHalData->bRegUseLed = TRUE;
3740 case RT_CID_819x_Sitecom:
3741 pHalData->LedStrategy = SW_LED_MODE2;
3742 pHalData->bRegUseLed = TRUE;
3746 pHalData->LedStrategy = SW_LED_MODE0;
3751 // Read USB PHY parameters.
3753 priv->EEPROMUsbPhyParam[i] = *(u8 *)&hwinfo[EEPROM_USB_PHY_PARA1+i];
3755 //RT_PRINT_DATA(COMP_EFUSE, DBG_LOUD, ("USB PHY Param: \n"), pHalData->EEPROMUsbPhyParam, 5);
3758 //Read Permanent MAC address
3760 dev->dev_addr[i] = *(u8 *)&hwinfo[EEPROM_NODE_ADDRESS_BYTE_0+i];
3762 //NicIFSetMacAddress(Adapter, Adapter->PermanentAddress);
3763 write_nic_dword(dev, IDR0, ((u32*)dev->dev_addr)[0]);
3764 write_nic_word(dev, IDR4, ((u16*)(dev->dev_addr + 4))[0]);
3766 RT_TRACE(COMP_INIT, "ReadAdapterInfo8192SEFuse(), Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x\n",
3767 dev->dev_addr[0], dev->dev_addr[1],
3768 dev->dev_addr[2], dev->dev_addr[3],
3769 dev->dev_addr[4], dev->dev_addr[5]);
3772 // Get CustomerID(Boad Type)
3773 // i.e., 0x0: RTL8188SU, 0x1: RTL8191SU, 0x2: RTL8192SU, 0x3: RTL8191GU.
3774 // Others: Reserved. Default is 0x2: RTL8192SU.
3776 //if(!priv->AutoloadFailFlag)
3778 priv->EEPROMBoardType = *(u8 *)&hwinfo[EEPROM_BoardType];
3779 priv->rf_type = rtl8192SU_BoardTypeToRFtype(dev, priv->EEPROMBoardType);
3783 // priv->EEPROMBoardType = EEPROM_Default_BoardType;
3784 // priv->rf_type = RF_1T2R;
3787 priv->rf_chip = RF_6052;
3789 priv->rf_chip = RF_6052;//lzm test
3790 RT_TRACE(COMP_INIT, "BoardType = 0x%2x\n", priv->EEPROMBoardType);
3791 RT_TRACE(COMP_INIT, "RF_Type = 0x%2x\n", priv->rf_type);
3794 // Read antenna tx power offset of B/C/D to A from EEPROM
3795 // and read ThermalMeter from EEPROM
3797 //if(!priv->AutoloadFailFlag)
3799 priv->EEPROMTxPowerDiff = *(u8 *)&hwinfo[EEPROM_PwDiff];
3800 priv->EEPROMThermalMeter = *(u8 *)&hwinfo[EEPROM_ThermalMeter];
3804 // priv->EEPROMTxPowerDiff = EEPROM_Default_PwDiff;
3805 // priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
3808 RT_TRACE(COMP_INIT, "PwDiff = %#x\n", priv->EEPROMTxPowerDiff);
3809 RT_TRACE(COMP_INIT, "ThermalMeter = %#x\n", priv->EEPROMThermalMeter);
3812 // Read Tx Power gain offset of legacy OFDM to HT rate.
3813 // Read CrystalCap from EEPROM
3815 //if(!priv->AutoloadFailFlag)
3817 priv->EEPROMCrystalCap = *(u8 *)&hwinfo[EEPROM_CrystalCap];
3821 // priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
3824 RT_TRACE(COMP_INIT, "CrystalCap = %#x\n", priv->EEPROMCrystalCap);
3827 // Get Tx Power Base.
3829 //if(!priv->AutoloadFailFlag)
3831 priv->EEPROMTxPwrBase = *(u8 *)&hwinfo[EEPROM_TxPowerBase];
3835 // priv->EEPROMTxPwrBase = EEPROM_Default_TxPowerBase;
3838 RT_TRACE(COMP_INIT, "TxPwrBase = %#x\n", priv->EEPROMTxPwrBase);
3842 // Get TSSI value for each path.
3844 //if(!priv->AutoloadFailFlag)
3846 priv->EEPROMTSSI_A = *(u8 *)&hwinfo[EEPROM_TSSI_A];
3847 priv->EEPROMTSSI_B = *(u8 *)&hwinfo[EEPROM_TSSI_B];
3850 //{ // Default setting for Empty EEPROM
3851 // priv->EEPROMTSSI_A = EEPROM_Default_TSSI;
3852 // priv->EEPROMTSSI_B = EEPROM_Default_TSSI;
3855 RT_TRACE(COMP_INIT, "TSSI_A = %#x, TSSI_B = %#x\n", priv->EEPROMTSSI_A, priv->EEPROMTSSI_B);
3858 // Get Tx Power tracking mode.
3860 //if(!priv->AutoloadFailFlag)
3862 priv->EEPROMTxPwrTkMode = *(u8 *)&hwinfo[EEPROM_TxPwTkMode];
3865 RT_TRACE(COMP_INIT, "TxPwrTkMod = %#x\n", priv->EEPROMTxPwrTkMode);
3870 // Buffer TxPwIdx(i.e., from offset 0x55~0x66, total 18Bytes)
3871 // Update CCK, OFDM (1T/2T)Tx Power Index from above buffer.
3875 // Get Tx Power Level by Channel
3877 //if(!priv->AutoloadFailFlag)
3879 // Read Tx power of Channel 1 ~ 14 from EFUSE.
3880 // 92S suupport RF A & B
3881 for (rf_path = 0; rf_path < 2; rf_path++)
3883 for (i = 0; i < 3; i++)
3885 // Read CCK RF A & B Tx power
3886 priv->RfCckChnlAreaTxPwr[rf_path][i] =
3887 hwinfo[EEPROM_TxPwIndex+rf_path*3+i];
3889 // Read OFDM RF A & B Tx power for 1T
3890 priv->RfOfdmChnlAreaTxPwr1T[rf_path][i] =
3891 hwinfo[EEPROM_TxPwIndex+6+rf_path*3+i];
3893 // Read OFDM RF A & B Tx power for 2T
3894 priv->RfOfdmChnlAreaTxPwr2T[rf_path][i] =
3895 hwinfo[EEPROM_TxPwIndex+12+rf_path*3+i];
3901 // Update Tx Power HAL variables.
3903 for (rf_path = 0; rf_path < 2; rf_path++)
3905 for (i = 0; i < 3; i++)
3907 RT_TRACE((COMP_INIT), "CCK RF-%d CHan_Area-%d = 0x%x\n", rf_path, i,
3908 priv->RfCckChnlAreaTxPwr[rf_path][i]);
3909 RT_TRACE((COMP_INIT), "OFDM-1T RF-%d CHan_Area-%d = 0x%x\n", rf_path, i,
3910 priv->RfOfdmChnlAreaTxPwr1T[rf_path][i]);
3911 RT_TRACE((COMP_INIT), "OFDM-2T RF-%d CHan_Area-%d = 0x%x\n", rf_path, i, priv->RfOfdmChnlAreaTxPwr2T[rf_path][i]);
3914 // Assign dedicated channel tx power
3915 for(i=0; i<14; i++) // channel 1~3 use the same Tx Power Level.
3917 if (i < 3) // Cjanel 1-3
3919 else if (i < 9) // Channel 4-9
3921 else // Channel 10-14
3924 // Record A & B CCK /OFDM - 1T/2T Channel area tx power
3925 priv->RfTxPwrLevelCck[rf_path][i] =
3926 priv->RfCckChnlAreaTxPwr[rf_path][index];
3927 priv->RfTxPwrLevelOfdm1T[rf_path][i] =
3928 priv->RfOfdmChnlAreaTxPwr1T[rf_path][index];
3929 priv->RfTxPwrLevelOfdm2T[rf_path][i] =
3930 priv->RfOfdmChnlAreaTxPwr2T[rf_path][index];
3933 priv->TxPowerLevelOFDM24G[i] = priv->RfTxPwrLevelOfdm1T[rf_path][i] ;
3934 priv->TxPowerLevelCCK[i] = priv->RfTxPwrLevelCck[rf_path][i];
3940 RT_TRACE((COMP_INIT),
3941 "Rf-%d TxPwr CH-%d CCK OFDM_1T OFDM_2T= 0x%x/0x%x/0x%x\n",
3942 rf_path, i, priv->RfTxPwrLevelCck[rf_path][i],
3943 priv->RfTxPwrLevelOfdm1T[rf_path][i] ,
3944 priv->RfTxPwrLevelOfdm2T[rf_path][i] );
3950 // 2009/02/09 Cosa add for new EEPROM format
3952 for(i=0; i<14; i++) // channel 1~3 use the same Tx Power Level.
3954 // Read tx power difference between HT OFDM 20/40 MHZ
3955 if (i < 3) // Cjanel 1-3
3957 else if (i < 9) // Channel 4-9
3959 else // Channel 10-14
3962 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_HT20_DIFF+index])&0xff;
3963 priv->TxPwrHt20Diff[RF90_PATH_A][i] = (tempval&0xF);
3964 priv->TxPwrHt20Diff[RF90_PATH_B][i] = ((tempval>>4)&0xF);
3966 // Read OFDM<->HT tx power diff
3967 if (i < 3) // Cjanel 1-3
3968 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_OFDM_DIFF])&0xff;
3969 else if (i < 9) // Channel 4-9
3970 tempval = (*(u8 *)&hwinfo[EEPROM_PwDiff])&0xff;
3971 else // Channel 10-14
3972 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_OFDM_DIFF+1])&0xff;
3974 //cosa tempval = (*(u1Byte *)&hwinfo[EEPROM_TX_PWR_OFDM_DIFF+index])&0xff;
3975 priv->TxPwrLegacyHtDiff[RF90_PATH_A][i] = (tempval&0xF);
3976 priv->TxPwrLegacyHtDiff[RF90_PATH_B][i] = ((tempval>>4)&0xF);
3979 // Read Band Edge tx power offset and check if user enable the ability
3981 // HT 40 band edge channel
3982 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE])&0xff;
3983 priv->TxPwrbandEdgeHt40[RF90_PATH_A][0] = (tempval&0xF); // Band edge low channel
3984 priv->TxPwrbandEdgeHt40[RF90_PATH_A][1] = ((tempval>>4)&0xF); // Band edge high channel
3985 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE+1])&0xff;
3986 priv->TxPwrbandEdgeHt40[RF90_PATH_B][0] = (tempval&0xF); // Band edge low channel
3987 priv->TxPwrbandEdgeHt40[RF90_PATH_B][1] = ((tempval>>4)&0xF); // Band edge high channel
3988 // HT 20 band edge channel
3989 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE+2])&0xff;
3990 priv->TxPwrbandEdgeHt20[RF90_PATH_A][0] = (tempval&0xF); // Band edge low channel
3991 priv->TxPwrbandEdgeHt20[RF90_PATH_A][1] = ((tempval>>4)&0xF); // Band edge high channel
3992 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE+3])&0xff;
3993 priv->TxPwrbandEdgeHt20[RF90_PATH_B][0] = (tempval&0xF); // Band edge low channel
3994 priv->TxPwrbandEdgeHt20[RF90_PATH_B][1] = ((tempval>>4)&0xF); // Band edge high channel
3995 // OFDM band edge channel
3996 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE+4])&0xff;
3997 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_A][0] = (tempval&0xF); // Band edge low channel
3998 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_A][1] = ((tempval>>4)&0xF); // Band edge high channel
3999 tempval = (*(u8 *)&hwinfo[EEPROM_TX_PWR_BAND_EDGE+5])&0xff;
4000 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_B][0] = (tempval&0xF); // Band edge low channel
4001 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_B][1] = ((tempval>>4)&0xF); // Band edge high channel
4003 priv->TxPwrbandEdgeFlag = (*(u8 *)&hwinfo[TX_PWR_BAND_EDGE_CHK]);
4007 RT_TRACE(COMP_INIT, "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i, priv->TxPwrHt20Diff[RF90_PATH_A][i]);
4009 RT_TRACE(COMP_INIT, "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i, priv->TxPwrLegacyHtDiff[RF90_PATH_A][i]);
4011 RT_TRACE(COMP_INIT, "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i, priv->TxPwrHt20Diff[RF90_PATH_B][i]);
4013 RT_TRACE(COMP_INIT, "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i, priv->TxPwrLegacyHtDiff[RF90_PATH_B][i]);
4014 RT_TRACE(COMP_INIT, "RF-A HT40 band-edge low/high power diff = 0x%x/0x%x\n",
4015 priv->TxPwrbandEdgeHt40[RF90_PATH_A][0],
4016 priv->TxPwrbandEdgeHt40[RF90_PATH_A][1]);
4017 RT_TRACE((COMP_INIT&COMP_DBG), "RF-B HT40 band-edge low/high power diff = 0x%x/0x%x\n",
4018 priv->TxPwrbandEdgeHt40[RF90_PATH_B][0],
4019 priv->TxPwrbandEdgeHt40[RF90_PATH_B][1]);
4021 RT_TRACE((COMP_INIT&COMP_DBG), "RF-A HT20 band-edge low/high power diff = 0x%x/0x%x\n",
4022 priv->TxPwrbandEdgeHt20[RF90_PATH_A][0],
4023 priv->TxPwrbandEdgeHt20[RF90_PATH_A][1]);
4024 RT_TRACE((COMP_INIT&COMP_DBG), "RF-B HT20 band-edge low/high power diff = 0x%x/0x%x\n",
4025 priv->TxPwrbandEdgeHt20[RF90_PATH_B][0],
4026 priv->TxPwrbandEdgeHt20[RF90_PATH_B][1]);
4028 RT_TRACE((COMP_INIT&COMP_DBG), "RF-A OFDM band-edge low/high power diff = 0x%x/0x%x\n",
4029 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_A][0],
4030 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_A][1]);
4031 RT_TRACE((COMP_INIT&COMP_DBG), "RF-B OFDM band-edge low/high power diff = 0x%x/0x%x\n",
4032 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_B][0],
4033 priv->TxPwrbandEdgeLegacyOfdm[RF90_PATH_B][1]);
4034 RT_TRACE((COMP_INIT&COMP_DBG), "Band-edge enable flag = %d\n", priv->TxPwrbandEdgeFlag);
4037 // Update remained HAL variables.
4039 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
4040 priv->LegacyHTTxPowerDiff = priv->EEPROMTxPowerDiff;
4041 priv->TxPowerDiff = priv->EEPROMTxPowerDiff;
4042 //priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);// Antenna B gain offset to antenna A, bit[3:0]
4043 //priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);// Antenna C gain offset to antenna A, bit[7:4]
4044 priv->CrystalCap = priv->EEPROMCrystalCap; // CrystalCap, bit[15:12]
4045 priv->ThermalMeter[0] = (priv->EEPROMThermalMeter&0x1f);// ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
4046 priv->LedStrategy = SW_LED_MODE0;
4048 init_rate_adaptive(dev);
4050 RT_TRACE(COMP_INIT, "<==== ReadAdapterInfo8192SUsb\n");
4052 //return RT_STATUS_SUCCESS;
4058 // Read HW adapter information by E-Fuse or EEPROM according CR9346 reported.
4061 // 1. CR9346 regiser has verified.
4062 // 2. PASSIVE_LEVEL (USB interface)
4064 // Created by Roger, 2008.10.21.
4066 static void rtl8192SU_read_eeprom_info(struct net_device *dev)
4068 struct r8192_priv *priv = ieee80211_priv(dev);
4071 RT_TRACE(COMP_INIT, "====> ReadAdapterInfo8192SUsb\n");
4073 // Retrieve Chip version.
4074 priv->card_8192_version = (VERSION_8192S)((read_nic_dword(dev, PMC_FSM)>>16)&0xF);
4075 RT_TRACE(COMP_INIT, "Chip Version ID: 0x%2x\n", priv->card_8192_version);
4077 tmpU1b = read_nic_byte(dev, EPROM_CMD);//CR9346
4079 // To check system boot selection.
4080 if (tmpU1b & CmdEERPOMSEL)
4082 RT_TRACE(COMP_INIT, "Boot from EEPROM\n");
4083 priv->EepromOrEfuse = TRUE;
4087 RT_TRACE(COMP_INIT, "Boot from EFUSE\n");
4088 priv->EepromOrEfuse = FALSE;
4091 // To check autoload success or not.
4092 if (tmpU1b & CmdEEPROM_En)
4094 RT_TRACE(COMP_INIT, "Autoload OK!!\n");
4095 priv->AutoloadFailFlag=FALSE;
4096 rtl8192SU_ReadAdapterInfo8192SUsb(dev);//eeprom or e-fuse
4099 { // Auto load fail.
4100 RT_TRACE(COMP_INIT, "AutoLoad Fail reported from CR9346!!\n");
4101 priv->AutoloadFailFlag=TRUE;
4102 rtl8192SU_ConfigAdapterInfo8192SForAutoLoadFail(dev);
4104 //if (IS_BOOT_FROM_EFUSE(Adapter))
4105 if(!priv->EepromOrEfuse)
4107 RT_TRACE(COMP_INIT, "Update shadow map for EFuse future use!!\n");
4108 EFUSE_ShadowMapUpdate(dev);
4112 if((priv->RegChannelPlan >= RT_CHANNEL_DOMAIN_MAX) || (pHalData->EEPROMChannelPlan & EEPROM_CHANNEL_PLAN_BY_HW_MASK))
4114 pMgntInfo->ChannelPlan = HalMapChannelPlan8192S(Adapter, (pHalData->EEPROMChannelPlan & (~(EEPROM_CHANNEL_PLAN_BY_HW_MASK))));
4115 pMgntInfo->bChnlPlanFromHW = (pHalData->EEPROMChannelPlan & EEPROM_CHANNEL_PLAN_BY_HW_MASK) ? TRUE : FALSE; // User cannot change channel plan.
4119 pMgntInfo->ChannelPlan = (RT_CHANNEL_DOMAIN)pMgntInfo->RegChannelPlan;
4122 switch(pMgntInfo->ChannelPlan)
4124 case RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN:
4126 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(pMgntInfo);
4128 pDot11dInfo->bEnabled = TRUE;
4130 RT_TRACE(COMP_INIT, DBG_LOUD, ("ReadAdapterInfo8187(): Enable dot11d when RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN!\n"));
4134 RT_TRACE(COMP_INIT, DBG_LOUD, ("RegChannelPlan(%d) EEPROMChannelPlan(%d)", pMgntInfo->RegChannelPlan, pHalData->EEPROMChannelPlan));
4135 RT_TRACE(COMP_INIT, DBG_LOUD, ("ChannelPlan = %d\n" , pMgntInfo->ChannelPlan));
4137 RT_TRACE(COMP_INIT, DBG_LOUD, ("<==== ReadAdapterInfo8192S\n"));
4140 RT_TRACE(COMP_INIT, "<==== ReadAdapterInfo8192SUsb\n");
4142 //return RT_STATUS_SUCCESS;
4145 short rtl8192_get_channel_map(struct net_device * dev)
4147 struct r8192_priv *priv = ieee80211_priv(dev);
4148 if(priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN){
4149 printk("rtl8180_init:Error channel plan! Set to default.\n");
4150 priv->ChannelPlan= 0;
4152 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
4154 rtl819x_set_channel_map(priv->ChannelPlan, priv);
4158 short rtl8192_init(struct net_device *dev)
4161 struct r8192_priv *priv = ieee80211_priv(dev);
4163 rtl8192_init_priv_variable(dev);
4164 rtl8192_init_priv_lock(priv);
4165 rtl8192_init_priv_task(dev);
4166 rtl8192_get_eeprom_size(dev);
4167 priv->ops->rtl819x_read_eeprom_info(dev);
4168 rtl8192_get_channel_map(dev);
4170 init_timer(&priv->watch_dog_timer);
4171 priv->watch_dog_timer.data = (unsigned long)dev;
4172 priv->watch_dog_timer.function = watch_dog_timer_callback;
4174 //rtl8192_adapter_start(dev);
4181 /******************************************************************************
4182 *function: This function actually only set RRSR, RATR and BW_OPMODE registers
4183 * not to do all the hw config as its name says
4184 * input: net_device dev
4187 * notice: This part need to modified according to the rate set we filtered
4188 * ****************************************************************************/
4189 void rtl8192_hwconfig(struct net_device* dev)
4191 u32 regRATR = 0, regRRSR = 0;
4192 u8 regBwOpMode = 0, regTmp = 0;
4193 struct r8192_priv *priv = ieee80211_priv(dev);
4195 // Set RRSR, RATR, and BW_OPMODE registers
4197 switch(priv->ieee80211->mode)
4199 case WIRELESS_MODE_B:
4200 regBwOpMode = BW_OPMODE_20MHZ;
4201 regRATR = RATE_ALL_CCK;
4202 regRRSR = RATE_ALL_CCK;
4204 case WIRELESS_MODE_A:
4205 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
4206 regRATR = RATE_ALL_OFDM_AG;
4207 regRRSR = RATE_ALL_OFDM_AG;
4209 case WIRELESS_MODE_G:
4210 regBwOpMode = BW_OPMODE_20MHZ;
4211 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4212 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4214 case WIRELESS_MODE_AUTO:
4216 if (Adapter->bInHctTest)
4218 regBwOpMode = BW_OPMODE_20MHZ;
4219 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4220 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4225 regBwOpMode = BW_OPMODE_20MHZ;
4226 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4227 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4230 case WIRELESS_MODE_N_24G:
4231 // It support CCK rate by default.
4232 // CCK rate will be filtered out only when associated AP does not support it.
4233 regBwOpMode = BW_OPMODE_20MHZ;
4234 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4235 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4237 case WIRELESS_MODE_N_5G:
4238 regBwOpMode = BW_OPMODE_5G;
4239 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4240 regRRSR = RATE_ALL_OFDM_AG;
4244 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4247 ratr_value = regRATR;
4248 if (priv->rf_type == RF_1T2R)
4250 ratr_value &= ~(RATE_ALL_OFDM_2SS);
4252 write_nic_dword(dev, RATR0, ratr_value);
4253 write_nic_byte(dev, UFWP, 1);
4255 regTmp = read_nic_byte(dev, 0x313);
4256 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
4257 write_nic_dword(dev, RRSR, regRRSR);
4260 // Set Retry Limit here
4262 write_nic_word(dev, RETRY_LIMIT,
4263 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | \
4264 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
4265 // Set Contention Window here
4269 // Set Tx Antenna including Feedback control
4271 // Set Auto Rate fallback control
4279 // Initial HW relted registers.
4282 // Config RTL8192S USB MAC, we should config MAC before download FW.
4284 // 2008.09.03, Added by Roger.
4286 static void rtl8192SU_MacConfigBeforeFwDownloadASIC(struct net_device *dev)
4293 RT_TRACE(COMP_INIT, "--->MacConfigBeforeFwDownloadASIC()\n");
4295 //2MAC Initialization for power on sequence, Revised by Roger. 2008.09.03.
4298 //<Roger_Notes> Set control path switch to HW control and reset Digital Core, CPU Core and
4299 // MAC I/O to solve FW download fail when system from resume sate.
4302 tmpU1b = read_nic_byte(dev, SYS_CLKR+1);
4306 write_nic_byte(dev, SYS_CLKR+1, tmpU1b);
4308 // Clear FW RPWM for FW control LPS. by tynli. 2009.02.23
4309 write_nic_byte(dev, RPWM, 0x0);
4311 tmpU1b = read_nic_byte(dev, SYS_FUNC_EN+1);
4313 write_nic_byte(dev, SYS_FUNC_EN+1, tmpU1b);
4316 //Revised POS, suggested by SD1 Alex, 2008.09.27.
4317 write_nic_byte(dev, SPS0_CTRL+1, 0x53);
4318 write_nic_byte(dev, SPS0_CTRL, 0x57);
4320 //Enable AFE Macro Block's Bandgap adn Enable AFE Macro Block's Mbias
4321 tmpU1b = read_nic_byte(dev, AFE_MISC);
4322 write_nic_byte(dev, AFE_MISC, (tmpU1b|AFE_BGEN|AFE_MBEN));
4324 //Enable PLL Power (LDOA15V)
4325 tmpU1b = read_nic_byte(dev, LDOA15_CTRL);
4326 write_nic_byte(dev, LDOA15_CTRL, (tmpU1b|LDA15_EN));
4328 //Enable LDOV12D block
4329 tmpU1b = read_nic_byte(dev, LDOV12D_CTRL);
4330 write_nic_byte(dev, LDOV12D_CTRL, (tmpU1b|LDV12_EN));
4332 //mpU1b = read_nic_byte(Adapter, SPS1_CTRL);
4333 //write_nic_byte(dev, SPS1_CTRL, (tmpU1b|SPS1_LDEN));
4335 //PlatformSleepUs(2000);
4337 //Enable Switch Regulator Block
4338 //tmpU1b = read_nic_byte(Adapter, SPS1_CTRL);
4339 //write_nic_byte(dev, SPS1_CTRL, (tmpU1b|SPS1_SWEN));
4341 //write_nic_dword(Adapter, SPS1_CTRL, 0x00a7b267);
4343 tmpU1b = read_nic_byte(dev, SYS_ISO_CTRL+1);
4344 write_nic_byte(dev, SYS_ISO_CTRL+1, (tmpU1b|0x08));
4346 //Engineer Packet CP test Enable
4347 tmpU1b = read_nic_byte(dev, SYS_FUNC_EN+1);
4348 write_nic_byte(dev, SYS_FUNC_EN+1, (tmpU1b|0x20));
4350 //Support 64k IMEM, suggested by SD1 Alex.
4351 tmpU1b = read_nic_byte(dev, SYS_ISO_CTRL+1);
4352 write_nic_byte(dev, SYS_ISO_CTRL+1, (tmpU1b& 0x68));
4355 tmpU1b = read_nic_byte(dev, AFE_XTAL_CTRL+1);
4356 write_nic_byte(dev, AFE_XTAL_CTRL+1, (tmpU1b& 0xfb));
4358 //Enable AFE PLL Macro Block
4359 tmpU1b = read_nic_byte(dev, AFE_PLL_CTRL);
4360 write_nic_byte(dev, AFE_PLL_CTRL, (tmpU1b|0x11));
4362 //Attatch AFE PLL to MACTOP/BB/PCIe Digital
4363 tmpU1b = read_nic_byte(dev, SYS_ISO_CTRL);
4364 write_nic_byte(dev, SYS_ISO_CTRL, (tmpU1b&0xEE));
4366 // Switch to 40M clock
4367 write_nic_byte(dev, SYS_CLKR, 0x00);
4370 tmpU1b = read_nic_byte(dev, SYS_CLKR);
4371 //write_nic_byte(dev, SYS_CLKR, (tmpU1b&0x5f));
4372 write_nic_byte(dev, SYS_CLKR, (tmpU1b|0xa0));
4375 tmpU1b = read_nic_byte(dev, SYS_CLKR+1);
4376 write_nic_byte(dev, SYS_CLKR+1, (tmpU1b|0x18));
4378 //Revised POS, suggested by SD1 Alex, 2008.09.27.
4379 write_nic_byte(dev, PMC_FSM, 0x02);
4381 //Enable Core digital and enable IOREG R/W
4382 tmpU1b = read_nic_byte(dev, SYS_FUNC_EN+1);
4383 write_nic_byte(dev, SYS_FUNC_EN+1, (tmpU1b|0x08));
4386 tmpU1b = read_nic_byte(dev, SYS_FUNC_EN+1);
4387 write_nic_byte(dev, SYS_FUNC_EN+1, (tmpU1b|0x80));
4389 //Switch the control path to FW
4390 tmpU1b = read_nic_byte(dev, SYS_CLKR+1);
4391 write_nic_byte(dev, SYS_CLKR+1, (tmpU1b|0x80)& 0xBF);
4393 write_nic_byte(dev, CMDR, 0xFC);
4394 write_nic_byte(dev, CMDR+1, 0x37);
4396 //Fix the RX FIFO issue(usb error), 970410
4397 tmpU1b = read_nic_byte_E(dev, 0x5c);
4398 write_nic_byte_E(dev, 0x5c, (tmpU1b|BIT7));
4400 //For power save, used this in the bit file after 970621
4401 tmpU1b = read_nic_byte(dev, SYS_CLKR);
4402 write_nic_byte(dev, SYS_CLKR, tmpU1b&(~SYS_CPU_CLKSEL));
4404 // Revised for 8051 ROM code wrong operation. Added by Roger. 2008.10.16.
4405 write_nic_byte_E(dev, 0x1c, 0x80);
4408 // <Roger_EXP> To make sure that TxDMA can ready to download FW.
4409 // We should reset TxDMA if IMEM RPT was not ready.
4410 // Suggested by SD1 Alex. 2008.10.23.
4414 tmpU1b = read_nic_byte(dev, TCR);
4415 if((tmpU1b & TXDMA_INIT_VALUE) == TXDMA_INIT_VALUE)
4417 //PlatformStallExecution(5);
4419 }while(PollingCnt--); // Delay 1ms
4421 if(PollingCnt <= 0 )
4423 RT_TRACE(COMP_INIT, "MacConfigBeforeFwDownloadASIC(): Polling TXDMA_INIT_VALUE timeout!! Current TCR(%#x)\n", tmpU1b);
4424 tmpU1b = read_nic_byte(dev, CMDR);
4425 write_nic_byte(dev, CMDR, tmpU1b&(~TXDMA_EN));
4427 write_nic_byte(dev, CMDR, tmpU1b|TXDMA_EN);// Reset TxDMA
4431 RT_TRACE(COMP_INIT, "<---MacConfigBeforeFwDownloadASIC()\n");
4436 // Initial HW relted registers.
4439 // 1. This function is only invoked at driver intialization once.
4440 // 2. PASSIVE LEVEL.
4442 // 2008.06.10, Added by Roger.
4444 static void rtl8192SU_MacConfigAfterFwDownload(struct net_device *dev)
4446 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
4447 //PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
4448 //u8 tmpU1b, RxPageCfg, i;
4453 RT_TRACE(COMP_INIT, "--->MacConfigAfterFwDownload()\n");
4456 tmpU2b = (BBRSTn|BB_GLB_RSTn|SCHEDULE_EN|MACRXEN|MACTXEN|DDMA_EN|
4457 FW2HW_EN|RXDMA_EN|TXDMA_EN|HCI_RXDMA_EN|HCI_TXDMA_EN); //3
4458 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_COMMAND, &tmpU1b );
4459 write_nic_word(dev, CMDR, tmpU2b); //LZM REGISTER COM 090305
4461 // Loopback mode or not
4462 priv->LoopbackMode = RTL8192SU_NO_LOOPBACK; // Set no loopback as default.
4463 if(priv->LoopbackMode == RTL8192SU_NO_LOOPBACK)
4464 tmpU1b = LBK_NORMAL;
4465 else if (priv->LoopbackMode == RTL8192SU_MAC_LOOPBACK )
4466 tmpU1b = LBK_MAC_DLB;
4468 RT_TRACE(COMP_INIT, "Serious error: wrong loopback mode setting\n");
4470 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_LBK_MODE, &tmpU1b);
4471 write_nic_byte(dev, LBKMD_SEL, tmpU1b);
4474 write_nic_dword(dev, RCR, priv->ReceiveConfig);
4475 RT_TRACE(COMP_INIT, "MacConfigAfterFwDownload(): Current RCR settings(%#x)\n", priv->ReceiveConfig);
4480 // <Roger_Notes> 2008.08.18.
4482 // (1) Page number on CMDQ is 0x03.
4483 // (2) Page number on BCNQ, HQ and MGTQ is 0.
4484 // (3) Page number on BKQ, BEQ, VIQ and VOQ are 0x07.
4485 // (4) Page number on PUBQ is 0xdd
4488 // (1) Page number on CMDQ is 0x00.
4489 // (2) Page number on BCNQ is 0x02, HQ and MGTQ are 0x03.
4490 // (3) Page number on BKQ, BEQ, VIQ and VOQ are 0x07.
4491 // (4) Page number on PUBQ is 0xd8
4493 //write_nic_dword(Adapter, 0xa0, 0x07070707); //BKQ, BEQ, VIQ and VOQ
4494 //write_nic_byte(dev, 0xa4, 0x00); // HCCAQ
4496 // Fix the RX FIFO issue(USB error), Rivesed by Roger, 2008-06-14
4497 tmpU1b = read_nic_byte_E(dev, 0x5C);
4498 write_nic_byte_E(dev, 0x5C, tmpU1b|BIT7);
4500 // For EFUSE init configuration.
4501 //if (IS_BOOT_FROM_EFUSE(Adapter)) // We may R/W EFUSE in EFUSE mode
4502 if (priv->bBootFromEfuse)
4506 tempval = read_nic_byte(dev, SYS_ISO_CTRL+1);
4508 write_nic_byte(dev, SYS_ISO_CTRL+1, tempval);
4510 // Enable LDO 2.5V for write action
4511 //tempval = read_nic_byte(Adapter, EFUSE_TEST+3);
4512 //write_nic_byte(Adapter, EFUSE_TEST+3, (tempval | 0x80));
4514 // Change Efuse Clock for write action
4515 //write_nic_byte(Adapter, EFUSE_CLK, 0x03);
4517 // Change Program timing
4518 write_nic_byte(dev, EFUSE_CTRL+3, 0x72);
4519 //printk("!!!!!!!!!!!!!!!!!!!!!%s: write 0x33 with 0x72\n",__FUNCTION__);
4520 RT_TRACE(COMP_INIT, "EFUSE CONFIG OK\n");
4524 RT_TRACE(COMP_INIT, "<---MacConfigAfterFwDownload()\n");
4527 void rtl8192SU_HwConfigureRTL8192SUsb(struct net_device *dev)
4530 struct r8192_priv *priv = ieee80211_priv(dev);
4532 u32 regRATR = 0, regRRSR = 0;
4536 //1 This part need to modified according to the rate set we filtered!!
4538 // Set RRSR, RATR, and BW_OPMODE registers
4540 switch(priv->ieee80211->mode)
4542 case WIRELESS_MODE_B:
4543 regBwOpMode = BW_OPMODE_20MHZ;
4544 regRATR = RATE_ALL_CCK;
4545 regRRSR = RATE_ALL_CCK;
4547 case WIRELESS_MODE_A:
4548 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
4549 regRATR = RATE_ALL_OFDM_AG;
4550 regRRSR = RATE_ALL_OFDM_AG;
4552 case WIRELESS_MODE_G:
4553 regBwOpMode = BW_OPMODE_20MHZ;
4554 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4555 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4557 case WIRELESS_MODE_AUTO:
4558 if (priv->bInHctTest)
4560 regBwOpMode = BW_OPMODE_20MHZ;
4561 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4562 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4566 regBwOpMode = BW_OPMODE_20MHZ;
4567 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4568 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4571 case WIRELESS_MODE_N_24G:
4572 // It support CCK rate by default.
4573 // CCK rate will be filtered out only when associated AP does not support it.
4574 regBwOpMode = BW_OPMODE_20MHZ;
4575 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4576 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4578 case WIRELESS_MODE_N_5G:
4579 regBwOpMode = BW_OPMODE_5G;
4580 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4581 regRRSR = RATE_ALL_OFDM_AG;
4586 // <Roger_Notes> We disable CCK response rate until FIB CCK rate IC's back.
4589 regTmp = read_nic_byte(dev, INIRTSMCS_SEL);
4590 regRRSR = ((regRRSR & 0x000fffff)<<8) | regTmp;
4593 // Update SIFS timing.
4595 //priv->SifsTime = 0x0e0e0a0a;
4596 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_SIFS, (pu1Byte)&pHalData->SifsTime);
4597 { u8 val[4] = {0x0e, 0x0e, 0x0a, 0x0a};
4598 // SIFS for CCK Data ACK
4599 write_nic_byte(dev, SIFS_CCK, val[0]);
4600 // SIFS for CCK consecutive tx like CTS data!
4601 write_nic_byte(dev, SIFS_CCK+1, val[1]);
4603 // SIFS for OFDM Data ACK
4604 write_nic_byte(dev, SIFS_OFDM, val[2]);
4605 // SIFS for OFDM consecutive tx like CTS data!
4606 write_nic_byte(dev, SIFS_OFDM+1, val[3]);
4609 write_nic_dword(dev, INIRTSMCS_SEL, regRRSR);
4610 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4613 // Suggested by SD1 Alex, 2008-06-14.
4615 //PlatformEFIOWrite1Byte(Adapter, TXOP_STALL_CTRL, 0x80);//NAV to protect all TXOP.
4618 // Set Data Auto Rate Fallback Retry Count register.
4620 write_nic_dword(dev, DARFRC, 0x02010000);
4621 write_nic_dword(dev, DARFRC+4, 0x06050403);
4622 write_nic_dword(dev, RARFRC, 0x02010000);
4623 write_nic_dword(dev, RARFRC+4, 0x06050403);
4625 // Set Data Auto Rate Fallback Reg. Added by Roger, 2008.09.22.
4626 for (i = 0; i < 8; i++)
4627 write_nic_dword(dev, ARFR0+i*4, 0x1f0ffff0);
4630 // Aggregation length limit. Revised by Roger. 2008.09.22.
4632 write_nic_byte(dev, AGGLEN_LMT_H, 0x0f); // Set AMPDU length to 12Kbytes for ShortGI case.
4633 write_nic_dword(dev, AGGLEN_LMT_L, 0xddd77442); // Long GI
4634 write_nic_dword(dev, AGGLEN_LMT_L+4, 0xfffdd772);
4636 // Set NAV protection length
4637 write_nic_word(dev, NAV_PROT_LEN, 0x0080);
4639 // Set TXOP stall control for several queue/HI/BCN/MGT/
4640 write_nic_byte(dev, TXOP_STALL_CTRL, 0x00); // NAV Protect next packet.
4642 // Set MSDU lifetime.
4643 write_nic_byte(dev, MLT, 0x8f);
4645 // Set CCK/OFDM SIFS
4646 write_nic_word(dev, SIFS_CCK, 0x0a0a); // CCK SIFS shall always be 10us.
4647 write_nic_word(dev, SIFS_OFDM, 0x0e0e);
4649 write_nic_byte(dev, ACK_TIMEOUT, 0x40);
4652 write_nic_byte(dev, CFEND_TH, 0xFF);
4655 // For Min Spacing configuration.
4657 switch(priv->rf_type)
4661 RT_TRACE(COMP_INIT, "Initializeadapter: RF_Type%s\n", (priv->rf_type==RF_1T1R? "(1T1R)":"(1T2R)"));
4662 priv->MinSpaceCfg = (MAX_MSS_DENSITY_1T<<3);
4666 RT_TRACE(COMP_INIT, "Initializeadapter:RF_Type(2T2R)\n");
4667 priv->MinSpaceCfg = (MAX_MSS_DENSITY_2T<<3);
4670 write_nic_byte(dev, AMPDU_MIN_SPACE, priv->MinSpaceCfg);
4674 // For Min Spacing configuration.
4676 //priv->MinSpaceCfg = 0x00;
4677 //rtl8192SU_SetHwRegAmpduMinSpace(dev, priv->MinSpaceCfg);
4681 // Description: Initial HW relted registers.
4683 // Assumption: This function is only invoked at driver intialization once.
4685 // 2008.06.10, Added by Roger.
4686 bool rtl8192SU_adapter_start(struct net_device *dev)
4688 struct r8192_priv *priv = ieee80211_priv(dev);
4689 //u32 dwRegRead = 0;
4690 //bool init_status = true;
4692 bool rtStatus = true;
4694 //u8 eRFPath, tmpU1b;
4695 u8 fw_download_times = 1;
4698 RT_TRACE(COMP_INIT, "--->InitializeAdapter8192SUsb()\n");
4700 //pHalData->bGPIOChangeRF = FALSE;
4704 // <Roger_Notes> 2008.06.15.
4706 // Initialization Steps on RTL8192SU:
4707 // a. MAC initialization prior to sending down firmware code.
4708 // b. Download firmware code step by step(i.e., IMEM, EMEM, DMEM).
4709 // c. MAC configuration after firmware has been download successfully.
4710 // d. Initialize BB related configurations.
4711 // e. Initialize RF related configurations.
4712 // f. Start to BulkIn transfer.
4716 //a. MAC initialization prior to send down firmware code.
4719 rtl8192SU_MacConfigBeforeFwDownloadASIC(dev);
4722 //b. Download firmware code step by step(i.e., IMEM, EMEM, DMEM).
4724 rtStatus = FirmwareDownload92S(dev);
4725 if(rtStatus != true)
4727 if(fw_download_times == 1){
4728 RT_TRACE(COMP_INIT, "InitializeAdapter8192SUsb(): Download Firmware failed once, Download again!!\n");
4729 fw_download_times = fw_download_times + 1;
4732 RT_TRACE(COMP_INIT, "InitializeAdapter8192SUsb(): Download Firmware failed twice, end!!\n");
4737 //c. MAC configuration after firmware has been download successfully.
4739 rtl8192SU_MacConfigAfterFwDownload(dev);
4741 //priv->bLbusEnable = TRUE;
4742 //if(priv->RegRfOff == TRUE)
4743 // priv->eRFPowerState = eRfOff;
4745 // Save target channel
4746 // <Roger_Notes> Current Channel will be updated again later.
4747 //priv->CurrentChannel = Channel;
4748 rtStatus = PHY_MACConfig8192S(dev);//===>ok
4749 if(rtStatus != true)
4751 RT_TRACE(COMP_INIT, "InitializeAdapter8192SUsb(): Fail to configure MAC!!\n");
4757 write_nic_dword(dev,WDCAPARA_ADD[i], 0x5e4322);
4758 write_nic_byte(dev,AcmHwCtrl, 0x01);
4763 //d. Initialize BB related configurations.
4766 rtStatus = PHY_BBConfig8192S(dev);//===>ok
4767 if(rtStatus != true)
4769 RT_TRACE(COMP_INIT, "InitializeAdapter8192SUsb(): Fail to configure BB!!\n");
4773 rtl8192_setBBreg(dev, rFPGA0_AnalogParameter2, 0xff, 0x58);//===>ok
4776 // e. Initialize RF related configurations.
4778 // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W.
4779 priv->Rf_Mode = RF_OP_By_SW_3wire;
4781 // For RF test only from Scott's suggestion
4782 //write_nic_byte(dev, 0x27, 0xDB);
4783 //write_nic_byte(dev, 0x1B, 0x07);
4786 write_nic_byte(dev, AFE_XTAL_CTRL+1, 0xDB);
4788 // <Roger_Notes> The following IOs are configured for each RF modules.
4789 // Enable RF module and reset RF and SDM module. 2008.11.17.
4790 if(priv->card_8192_version == VERSION_8192S_ACUT)
4791 write_nic_byte(dev, SPS1_CTRL+3, (u8)(RF_EN|RF_RSTB|RF_SDMRSTB)); // Fix A-Cut bug.
4793 write_nic_byte(dev, RF_CTRL, (u8)(RF_EN|RF_RSTB|RF_SDMRSTB));
4795 rtStatus = PHY_RFConfig8192S(dev);//===>ok
4796 if(rtStatus != true)
4798 RT_TRACE(COMP_INIT, "InitializeAdapter8192SUsb(): Fail to configure RF!!\n");
4803 // Set CCK and OFDM Block "ON"
4804 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
4805 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
4808 // Turn off Radio B while RF type is 1T1R by SD3 Wilsion's request.
4809 // Revised by Roger, 2008.12.18.
4811 if(priv->rf_type == RF_1T1R)
4813 // This is needed for PHY_REG after 20081219
4814 rtl8192_setBBreg(dev, rFPGA0_RFMOD, 0xff000000, 0x03);
4815 // This is needed for PHY_REG before 20081219
4816 //PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, bMaskByte0, 0x11);
4821 // Set CCK and OFDM Block "ON"
4822 //rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
4823 //rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
4826 //3//Get hardware version, do it in read eeprom?
4827 //GetHardwareVersion819xUsb(Adapter);
4832 rtl8192SU_HwConfigureRTL8192SUsb(dev);//==>ok
4835 // <Roger_Notes> We set MAC address here if autoload was failed before,
4836 // otherwise IDR0 will NOT contain any value.
4838 write_nic_dword(dev, IDR0, ((u32*)dev->dev_addr)[0]);
4839 write_nic_word(dev, IDR4, ((u16*)(dev->dev_addr + 4))[0]);
4840 if(!priv->bInHctTest)
4842 if(priv->ResetProgress == RESET_TYPE_NORESET)
4844 //RT_TRACE(COMP_MLME, DBG_LOUD, ("Initializeadapter8192SUsb():RegWirelessMode(%#x) \n", Adapter->RegWirelessMode));
4845 //Adapter->HalFunc.SetWirelessModeHandler(Adapter, Adapter->RegWirelessMode);
4846 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);//===>ok
4851 priv->ieee80211->mode = WIRELESS_MODE_G;
4852 rtl8192_SetWirelessMode(dev, WIRELESS_MODE_G);
4856 //-----------------------------------------------------------------------------
4857 // Set up security related. 070106, by rcnjko:
4858 // 1. Clear all H/W keys.
4859 // 2. Enable H/W encryption/decryption.
4860 //-----------------------------------------------------------------------------
4861 //CamResetAllEntry(Adapter);
4862 //Adapter->HalFunc.EnableHWSecCfgHandler(Adapter);
4864 //SecClearAllKeys(Adapter);
4865 CamResetAllEntry(dev);
4868 u8 SECR_value = 0x0;
4869 SECR_value |= SCR_TxEncEnable;
4870 SECR_value |= SCR_RxDecEnable;
4871 SECR_value |= SCR_NoSKMC;
4872 write_nic_byte(dev, SECR, SECR_value);
4877 //PHY_UpdateInitialGain(dev);
4879 if(priv->RegRfOff == true)
4880 { // User disable RF via registry.
4883 RT_TRACE((COMP_INIT|COMP_RF), "InitializeAdapter8192SUsb(): Turn off RF for RegRfOff ----------\n");
4884 MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_SW);
4885 // Those action will be discard in MgntActSet_RF_State because off the same state
4886 for(eRFPath = 0; eRFPath <priv->NumTotalRFPath; eRFPath++)
4887 rtl8192_setBBreg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
4889 else if(priv->RfOffReason > RF_CHANGE_BY_PS)
4890 { // H/W or S/W RF OFF before sleep.
4891 RT_TRACE((COMP_INIT|COMP_RF), "InitializeAdapter8192SUsb(): Turn off RF for RfOffReason(%d) ----------\n", priv->RfOffReason);
4892 MgntActSet_RF_State(dev, eRfOff, priv->RfOffReason);
4896 priv->eRFPowerState = eRfOn;
4897 priv->RfOffReason = 0;
4898 RT_TRACE((COMP_INIT|COMP_RF), "InitializeAdapter8192SUsb(): RF is on ----------\n");
4905 // f. Start to BulkIn transfer.
4912 PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
4914 for(PipeIndex=0; PipeIndex < MAX_RX_QUEUE; PipeIndex++)
4919 HalUsbInMpdu(Adapter, PipeIndex);
4923 //HalUsbInMpdu(Adapter, PipeIndex);
4924 //HalUsbInMpdu(Adapter, PipeIndex);
4925 //HalUsbInMpdu(Adapter, PipeIndex);
4928 PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
4931 // Joseph add to 819X code base for Vista USB platform.
4932 // This part may need to be add to Hal819xU code base. too.
4933 PlatformUsbEnableInPipes(Adapter);
4936 RT_TRACE(COMP_INIT, "HighestOperaRate = %x\n", Adapter->MgntInfo.HighestOperaRate);
4938 PlatformStartWorkItem( &(pHalData->RtUsbCheckForHangWorkItem) );
4941 // <Roger_EXP> The following configurations are for ASIC verification temporally.
4948 // Read EEPROM TX power index and PHY_REG_PG.txt to capture correct
4949 // TX power index for different rate set.
4951 //if(priv->card_8192_version >= VERSION_8192S_ACUT)
4953 // Get original hw reg values
4954 PHY_GetHWRegOriginalValue(dev);
4956 // Write correct tx power index//FIXLZM
4957 PHY_SetTxPowerLevel8192S(dev, priv->chan);
4962 // EEPROM R/W workaround
4963 tmpU1b = read_nic_byte(dev, MAC_PINMUX_CFG);
4964 write_nic_byte(dev, MAC_PINMUX_CFG, tmpU1b&(~GPIOMUX_EN));
4968 //<Roger_Notes> 2008.08.19.
4969 // We return status here for temporal FPGA verification, 2008.08.19.
4971 #ifdef RTL8192SU_FW_IQK
4972 write_nic_dword(dev, WFM5, FW_IQK_ENABLE);
4973 ChkFwCmdIoDone(dev);
4977 // <Roger_Notes> We enable high power mechanism after NIC initialized.
4980 write_nic_dword(dev, WFM5, FW_RA_RESET);
4981 ChkFwCmdIoDone(dev);
4982 write_nic_dword(dev, WFM5, FW_RA_ACTIVE);
4983 ChkFwCmdIoDone(dev);
4984 write_nic_dword(dev, WFM5, FW_RA_REFRESH);
4985 ChkFwCmdIoDone(dev);
4986 write_nic_dword(dev, WFM5, FW_BB_RESET_ENABLE);
4988 // <Roger_Notes> We return status here for temporal FPGA verification. 2008.05.12.
4995 /***************************************************************************
4996 -------------------------------NET STUFF---------------------------
4997 ***************************************************************************/
4999 static struct net_device_stats *rtl8192_stats(struct net_device *dev)
5001 struct r8192_priv *priv = ieee80211_priv(dev);
5003 return &priv->ieee80211->stats;
5007 HalTxCheckStuck819xUsb(
5008 struct net_device *dev
5011 struct r8192_priv *priv = ieee80211_priv(dev);
5012 u16 RegTxCounter = read_nic_word(dev, 0x128);
5013 bool bStuck = FALSE;
5014 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
5015 if(priv->TxCounter==RegTxCounter)
5018 priv->TxCounter = RegTxCounter;
5024 * <Assumption: RT_TX_SPINLOCK is acquired.>
5025 * First added: 2006.11.19 by emily
5028 TxCheckStuck(struct net_device *dev)
5030 struct r8192_priv *priv = ieee80211_priv(dev);
5033 // u8 ResetThreshold;
5034 bool bCheckFwTxCnt = false;
5035 //unsigned long flags;
5038 // Decide Stuch threshold according to current power save mode
5041 // RT_TRACE(COMP_RESET, " ==> TxCheckStuck()\n");
5042 // PlatformAcquireSpinLock(Adapter, RT_TX_SPINLOCK);
5043 // spin_lock_irqsave(&priv->ieee80211->lock,flags);
5044 for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++)
5046 if(QueueID == TXCMD_QUEUE)
5049 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
5053 bCheckFwTxCnt = true;
5055 // PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK);
5056 // spin_unlock_irqrestore(&priv->ieee80211->lock,flags);
5057 // RT_TRACE(COMP_RESET,"bCheckFwTxCnt is %d\n",bCheckFwTxCnt);
5061 if(HalTxCheckStuck819xUsb(dev))
5063 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
5064 return RESET_TYPE_SILENT;
5068 return RESET_TYPE_NORESET;
5072 HalRxCheckStuck819xUsb(struct net_device *dev)
5074 u16 RegRxCounter = read_nic_word(dev, 0x130);
5075 struct r8192_priv *priv = ieee80211_priv(dev);
5076 bool bStuck = FALSE;
5080 static u8 rx_chk_cnt = 0;
5081 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
5082 // If rssi is small, we should check rx for long time because of bad rx.
5083 // or maybe it will continuous silent reset every 2 seconds.
5085 if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
5087 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
5089 else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
5090 ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
5091 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
5102 else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
5103 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
5104 priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
5108 //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
5114 //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
5121 //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI);
5127 //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI);
5132 if(priv->RxCounter==RegRxCounter)
5135 priv->RxCounter = RegRxCounter;
5141 RxCheckStuck(struct net_device *dev)
5143 struct r8192_priv *priv = ieee80211_priv(dev);
5145 bool bRxCheck = FALSE;
5147 // RT_TRACE(COMP_RESET," ==> RxCheckStuck()\n");
5148 //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
5150 if(priv->IrpPendingCount > 1)
5152 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
5154 // RT_TRACE(COMP_RESET,"bRxCheck is %d \n",bRxCheck);
5157 if(HalRxCheckStuck819xUsb(dev))
5159 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
5160 return RESET_TYPE_SILENT;
5163 return RESET_TYPE_NORESET;
5168 * This function is called by Checkforhang to check whether we should ask OS to reset driver
5170 * \param pAdapter The adapter context for this miniport
5172 * Note:NIC with USB interface sholud not call this function because we cannot scan descriptor
5173 * to judge whether there is tx stuck.
5174 * Note: This function may be required to be rewrite for Vista OS.
5175 * <<<Assumption: Tx spinlock has been acquired >>>
5177 * 8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
5180 rtl819x_ifcheck_resetornot(struct net_device *dev)
5182 struct r8192_priv *priv = ieee80211_priv(dev);
5183 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
5184 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
5185 RT_RF_POWER_STATE rfState;
5187 return RESET_TYPE_NORESET;
5189 rfState = priv->ieee80211->eRFPowerState;
5191 TxResetType = TxCheckStuck(dev);
5193 if( rfState != eRfOff ||
5194 /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
5195 (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
5197 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
5198 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
5199 // if driver is in firmware download failure status, driver should initialize RF in the following
5200 // silent reset procedure Emily, 2008.01.21
5202 // Driver should not check RX stuck in IBSS mode because it is required to
5203 // set Check BSSID in order to send beacon, however, if check BSSID is
5204 // set, STA cannot hear any packet a all. Emily, 2008.04.12
5205 RxResetType = RxCheckStuck(dev);
5208 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
5209 return RESET_TYPE_NORMAL;
5210 else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT){
5211 RT_TRACE(COMP_RESET,"%s():silent reset\n",__FUNCTION__);
5212 return RESET_TYPE_SILENT;
5215 return RESET_TYPE_NORESET;
5219 void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
5220 int _rtl8192_up(struct net_device *dev);
5221 int rtl8192_close(struct net_device *dev);
5226 CamRestoreAllEntry( struct net_device *dev)
5229 struct r8192_priv *priv = ieee80211_priv(dev);
5230 u8* MacAddr = priv->ieee80211->current_network.bssid;
5232 static u8 CAM_CONST_ADDR[4][6] = {
5233 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
5234 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
5235 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
5236 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
5237 static u8 CAM_CONST_BROAD[] =
5238 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
5240 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
5243 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
5244 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
5247 for(EntryId=0; EntryId<4; EntryId++)
5250 MacAddr = CAM_CONST_ADDR[EntryId];
5254 priv->ieee80211->pairwise_key_type,
5262 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
5266 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5270 priv->ieee80211->pairwise_key_type,
5278 priv->ieee80211->pairwise_key_type,
5284 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
5288 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5292 priv->ieee80211->pairwise_key_type,
5300 priv->ieee80211->pairwise_key_type,
5309 if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
5311 MacAddr = CAM_CONST_BROAD;
5312 for(EntryId=1 ; EntryId<4 ; EntryId++)
5318 priv->ieee80211->group_key_type,
5324 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5328 priv->ieee80211->group_key_type,
5333 else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
5335 MacAddr = CAM_CONST_BROAD;
5336 for(EntryId=1; EntryId<4 ; EntryId++)
5342 priv->ieee80211->group_key_type,
5349 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5353 priv->ieee80211->group_key_type,
5359 //////////////////////////////////////////////////////////////
5360 // This function is used to fix Tx/Rx stop bug temporarily.
5361 // This function will do "system reset" to NIC when Tx or Rx is stuck.
5362 // The method checking Tx/Rx stuck of this function is supported by FW,
5363 // which reports Tx and Rx counter to register 0x128 and 0x130.
5364 //////////////////////////////////////////////////////////////
5366 rtl819x_ifsilentreset(struct net_device *dev)
5368 //OCTET_STRING asocpdu;
5369 struct r8192_priv *priv = ieee80211_priv(dev);
5371 int reset_status = 0;
5372 struct ieee80211_device *ieee = priv->ieee80211;
5375 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
5376 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
5378 if(priv->ResetProgress==RESET_TYPE_NORESET)
5382 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
5384 // Set the variable for reset.
5385 priv->ResetProgress = RESET_TYPE_SILENT;
5386 // rtl8192_close(dev);
5388 down(&priv->wx_sem);
5391 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
5396 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
5397 // if(!netif_queue_stopped(dev))
5398 // netif_stop_queue(dev);
5400 rtl8192_rtx_disable(dev);
5401 rtl8192_cancel_deferred_work(priv);
5403 del_timer_sync(&priv->watch_dog_timer);
5405 ieee->sync_scan_hurryup = 1;
5406 if(ieee->state == IEEE80211_LINKED)
5408 down(&ieee->wx_sem);
5409 printk("ieee->state is IEEE80211_LINKED\n");
5410 ieee80211_stop_send_beacons(priv->ieee80211);
5411 del_timer_sync(&ieee->associate_timer);
5412 cancel_delayed_work(&ieee->associate_retry_wq);
5413 ieee80211_stop_scan(ieee);
5414 netif_carrier_off(dev);
5418 printk("ieee->state is NOT LINKED\n");
5419 ieee80211_softmac_stop_protocol(priv->ieee80211); }
5421 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
5422 //rtl8192_irq_disable(dev);
5423 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
5424 reset_status = _rtl8192_up(dev);
5426 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
5427 if(reset_status == -EAGAIN)
5436 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n", __FUNCTION__);
5440 ieee->is_silent_reset = 1;
5442 EnableHWSecurityConfig8192(dev);
5444 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
5446 ieee->set_chan(ieee->dev, ieee->current_network.channel);
5449 queue_work(ieee->wq, &ieee->associate_complete_wq);
5453 else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
5455 ieee->set_chan(ieee->dev, ieee->current_network.channel);
5456 ieee->link_change(ieee->dev);
5458 // notify_wx_assoc_event(ieee);
5460 ieee80211_start_send_beacons(ieee);
5462 if (ieee->data_hard_resume)
5463 ieee->data_hard_resume(ieee->dev);
5464 netif_carrier_on(ieee->dev);
5468 CamRestoreAllEntry(dev);
5470 priv->ResetProgress = RESET_TYPE_NORESET;
5471 priv->reset_count++;
5473 priv->bForcedSilentReset =false;
5474 priv->bResetInProgress = false;
5476 // For test --> force write UFWP.
5477 write_nic_byte(dev, UFWP, 1);
5478 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
5483 void CAM_read_entry(
5484 struct net_device *dev,
5488 u32 target_command=0;
5489 u32 target_content=0;
5493 // printk("=======>start read CAM\n");
5494 for(entry_i=0;entry_i<CAM_CONTENT_COUNT;entry_i++)
5496 // polling bit, and No Write enable, and address
5497 target_command= entry_i+CAM_CONTENT_COUNT*iIndex;
5498 target_command= target_command | BIT31;
5500 //Check polling bit is clear
5505 ulStatus = read_nic_dword(dev, RWCAM);
5506 if(ulStatus & BIT31){
5514 write_nic_dword(dev, RWCAM, target_command);
5515 RT_TRACE(COMP_SEC,"CAM_read_entry(): WRITE A0: %x \n",target_command);
5516 // printk("CAM_read_entry(): WRITE A0: %lx \n",target_command);
5517 target_content = read_nic_dword(dev, RCAMO);
5518 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n",target_content);
5519 // printk("CAM_read_entry(): WRITE A8: %lx \n",target_content);
5524 void rtl819x_update_rxcounts(
5525 struct r8192_priv *priv,
5534 *TotalRxDataNum = 0;
5536 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
5537 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
5538 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
5539 for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
5540 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
5541 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
5545 extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
5547 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
5548 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
5549 struct net_device *dev = priv->ieee80211->dev;
5550 struct ieee80211_device* ieee = priv->ieee80211;
5551 RESET_TYPE ResetType = RESET_TYPE_NORESET;
5552 static u8 check_reset_cnt=0;
5553 bool bBusyTraffic = false;
5557 hal_dm_watchdog(dev);
5559 {//to get busy traffic condition
5560 if(ieee->state == IEEE80211_LINKED)
5562 //windows mod 666 to 100.
5563 //if( ieee->LinkDetectInfo.NumRxOkInPeriod> 666 ||
5564 // ieee->LinkDetectInfo.NumTxOkInPeriod> 666 ) {
5565 if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 ||
5566 ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) {
5567 bBusyTraffic = true;
5569 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
5570 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
5571 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
5574 //added by amy for AP roaming
5576 if(priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA)
5578 u32 TotalRxBcnNum = 0;
5579 u32 TotalRxDataNum = 0;
5581 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
5582 if((TotalRxBcnNum+TotalRxDataNum) == 0)
5585 if(rfState == eRfOff)
5586 RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
5588 printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
5589 // Dot11d_Reset(dev);
5590 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5591 notify_wx_assoc_event(priv->ieee80211);
5592 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
5593 ieee->is_roaming = true;
5594 priv->ieee80211->link_change(dev);
5595 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5598 priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod=0;
5599 priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod=0;
5601 // CAM_read_entry(dev,4);
5602 //check if reset the driver
5603 if(check_reset_cnt++ >= 3 && !ieee->is_roaming)
5605 ResetType = rtl819x_ifcheck_resetornot(dev);
5606 check_reset_cnt = 3;
5607 //DbgPrint("Start to check silent reset\n");
5609 // 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",__FUNCTION__,priv->force_reset,priv->ResetProgress,priv->bForcedSilentReset,priv->bDisableNormalResetCheck,ResetType);
5611 if( (priv->force_reset) || (priv->ResetProgress==RESET_TYPE_NORESET &&
5612 (priv->bForcedSilentReset ||
5613 (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT)))) // This is control by OID set in Pomelo
5615 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",__FUNCTION__,priv->force_reset,priv->ResetProgress,priv->bForcedSilentReset,priv->bDisableNormalResetCheck,ResetType);
5616 rtl819x_ifsilentreset(dev);
5619 priv->force_reset = false;
5620 priv->bForcedSilentReset = false;
5621 priv->bResetInProgress = false;
5622 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
5626 void watch_dog_timer_callback(unsigned long data)
5628 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
5629 //printk("===============>watch_dog timer\n");
5630 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq, 0);
5631 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
5633 int _rtl8192_up(struct net_device *dev)
5635 struct r8192_priv *priv = ieee80211_priv(dev);
5637 int init_status = 0;
5639 priv->ieee80211->ieee_up=1;
5640 RT_TRACE(COMP_INIT, "Bringing up iface");
5641 init_status = priv->ops->rtl819x_adapter_start(dev);
5644 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n", __FUNCTION__);
5645 priv->up=priv->ieee80211->ieee_up = 0;
5648 RT_TRACE(COMP_INIT, "start adapter finished\n");
5649 rtl8192_rx_enable(dev);
5650 // rtl8192_tx_enable(dev);
5651 if(priv->ieee80211->state != IEEE80211_LINKED)
5652 ieee80211_softmac_start_protocol(priv->ieee80211);
5653 ieee80211_reset_queue(priv->ieee80211);
5654 watch_dog_timer_callback((unsigned long) dev);
5655 if(!netif_queue_stopped(dev))
5656 netif_start_queue(dev);
5658 netif_wake_queue(dev);
5661 * Make sure that drop_unencrypted is initialized as "0"
5662 * No packets will be sent in non-security mode if we had set drop_unencrypted.
5663 * ex, After kill wpa_supplicant process, make the driver up again.
5664 * drop_unencrypted remains as "1", which is set by wpa_supplicant. 2008/12/04.john
5666 priv->ieee80211->drop_unencrypted = 0;
5672 int rtl8192_open(struct net_device *dev)
5674 struct r8192_priv *priv = ieee80211_priv(dev);
5676 down(&priv->wx_sem);
5677 ret = rtl8192_up(dev);
5684 int rtl8192_up(struct net_device *dev)
5686 struct r8192_priv *priv = ieee80211_priv(dev);
5688 if (priv->up == 1) return -1;
5690 return _rtl8192_up(dev);
5694 int rtl8192_close(struct net_device *dev)
5696 struct r8192_priv *priv = ieee80211_priv(dev);
5699 down(&priv->wx_sem);
5701 ret = rtl8192_down(dev);
5709 int rtl8192_down(struct net_device *dev)
5711 struct r8192_priv *priv = ieee80211_priv(dev);
5714 if (priv->up == 0) return -1;
5717 priv->ieee80211->ieee_up = 0;
5718 RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
5720 if (!netif_queue_stopped(dev))
5721 netif_stop_queue(dev);
5723 rtl8192_rtx_disable(dev);
5724 //rtl8192_irq_disable(dev);
5726 /* Tx related queue release */
5727 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5728 skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
5730 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5731 skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
5734 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5735 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ [i]);
5738 //as cancel_delayed_work will del work->timer, so if work is not definedas struct delayed_work, it will corrupt
5739 // flush_scheduled_work();
5740 rtl8192_cancel_deferred_work(priv);
5742 del_timer_sync(&priv->watch_dog_timer);
5745 ieee80211_softmac_stop_protocol(priv->ieee80211);
5746 memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
5747 RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
5753 void rtl8192_commit(struct net_device *dev)
5755 struct r8192_priv *priv = ieee80211_priv(dev);
5756 int reset_status = 0;
5757 //u8 reset_times = 0;
5758 if (priv->up == 0) return ;
5761 rtl8192_cancel_deferred_work(priv);
5762 del_timer_sync(&priv->watch_dog_timer);
5763 //cancel_delayed_work(&priv->SwChnlWorkItem);
5765 ieee80211_softmac_stop_protocol(priv->ieee80211);
5767 //rtl8192_irq_disable(dev);
5768 rtl8192_rtx_disable(dev);
5769 reset_status = _rtl8192_up(dev);
5774 void rtl8192_restart(struct net_device *dev)
5776 struct r8192_priv *priv = ieee80211_priv(dev);
5778 void rtl8192_restart(struct work_struct *work)
5780 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
5781 struct net_device *dev = priv->ieee80211->dev;
5783 down(&priv->wx_sem);
5785 rtl8192_commit(dev);
5790 static void r8192_set_multicast(struct net_device *dev)
5792 struct r8192_priv *priv = ieee80211_priv(dev);
5795 //down(&priv->wx_sem);
5799 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5801 if (promisc != priv->promisc)
5802 // rtl8192_commit(dev);
5804 priv->promisc = promisc;
5806 //schedule_work(&priv->reset_wq);
5807 //up(&priv->wx_sem);
5811 int r8192_set_mac_adr(struct net_device *dev, void *mac)
5813 struct r8192_priv *priv = ieee80211_priv(dev);
5814 struct sockaddr *addr = mac;
5816 down(&priv->wx_sem);
5818 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5820 schedule_work(&priv->reset_wq);
5827 /* based on ipw2200 driver */
5828 int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5830 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5831 struct iwreq *wrq = (struct iwreq *)rq;
5833 struct ieee80211_device *ieee = priv->ieee80211;
5835 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
5836 u8 zero_addr[6] = {0};
5837 struct iw_point *p = &wrq->u.data;
5838 struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
5840 down(&priv->wx_sem);
5843 if (p->length < sizeof(struct ieee_param) || !p->pointer){
5848 ipw = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
5853 if (copy_from_user(ipw, p->pointer, p->length)) {
5860 case RTL_IOCTL_WPA_SUPPLICANT:
5861 //parse here for HW security
5862 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
5864 if (ipw->u.crypt.set_tx)
5866 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5867 ieee->pairwise_key_type = KEY_TYPE_CCMP;
5868 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5869 ieee->pairwise_key_type = KEY_TYPE_TKIP;
5870 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5872 if (ipw->u.crypt.key_len == 13)
5873 ieee->pairwise_key_type = KEY_TYPE_WEP104;
5874 else if (ipw->u.crypt.key_len == 5)
5875 ieee->pairwise_key_type = KEY_TYPE_WEP40;
5878 ieee->pairwise_key_type = KEY_TYPE_NA;
5880 if (ieee->pairwise_key_type)
5882 // FIXME:these two lines below just to fix ipw interface bug, that is, it will never set mode down to driver. So treat it as ADHOC mode, if no association procedure. WB. 2009.02.04
5883 if (memcmp(ieee->ap_mac_addr, zero_addr, 6) == 0)
5884 ieee->iw_mode = IW_MODE_ADHOC;
5885 memcpy((u8*)key, ipw->u.crypt.key, 16);
5886 EnableHWSecurityConfig8192(dev);
5887 //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!
5889 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5890 if (ieee->iw_mode == IW_MODE_ADHOC)
5891 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5894 else //if (ipw->u.crypt.idx) //group key use idx > 0
5896 memcpy((u8*)key, ipw->u.crypt.key, 16);
5897 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5898 ieee->group_key_type= KEY_TYPE_CCMP;
5899 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5900 ieee->group_key_type = KEY_TYPE_TKIP;
5901 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5903 if (ipw->u.crypt.key_len == 13)
5904 ieee->group_key_type = KEY_TYPE_WEP104;
5905 else if (ipw->u.crypt.key_len == 5)
5906 ieee->group_key_type = KEY_TYPE_WEP40;
5909 ieee->group_key_type = KEY_TYPE_NA;
5911 if (ieee->group_key_type)
5915 ipw->u.crypt.idx, //KeyIndex
5916 ieee->group_key_type, //KeyType
5917 broadcast_addr, //MacAddr
5923 #ifdef JOHN_HWSEC_DEBUG
5925 printk("@@ wrq->u pointer = ");
5926 for(i=0;i<wrq->u.data.length;i++){
5927 if(i%10==0) printk("\n");
5928 printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] );
5931 #endif /*JOHN_HWSEC_DEBUG*/
5932 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5946 u8 rtl8192SU_HwRateToMRate(bool bIsHT, u8 rate,bool bFirstAMPDU)
5958 case DESC92S_RATE1M: ret_rate = MGN_1M; break;
5959 case DESC92S_RATE2M: ret_rate = MGN_2M; break;
5960 case DESC92S_RATE5_5M: ret_rate = MGN_5_5M; break;
5961 case DESC92S_RATE11M: ret_rate = MGN_11M; break;
5962 case DESC92S_RATE6M: ret_rate = MGN_6M; break;
5963 case DESC92S_RATE9M: ret_rate = MGN_9M; break;
5964 case DESC92S_RATE12M: ret_rate = MGN_12M; break;
5965 case DESC92S_RATE18M: ret_rate = MGN_18M; break;
5966 case DESC92S_RATE24M: ret_rate = MGN_24M; break;
5967 case DESC92S_RATE36M: ret_rate = MGN_36M; break;
5968 case DESC92S_RATE48M: ret_rate = MGN_48M; break;
5969 case DESC92S_RATE54M: ret_rate = MGN_54M; break;
5972 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
5981 case DESC92S_RATEMCS0: ret_rate = MGN_MCS0; break;
5982 case DESC92S_RATEMCS1: ret_rate = MGN_MCS1; break;
5983 case DESC92S_RATEMCS2: ret_rate = MGN_MCS2; break;
5984 case DESC92S_RATEMCS3: ret_rate = MGN_MCS3; break;
5985 case DESC92S_RATEMCS4: ret_rate = MGN_MCS4; break;
5986 case DESC92S_RATEMCS5: ret_rate = MGN_MCS5; break;
5987 case DESC92S_RATEMCS6: ret_rate = MGN_MCS6; break;
5988 case DESC92S_RATEMCS7: ret_rate = MGN_MCS7; break;
5989 case DESC92S_RATEMCS8: ret_rate = MGN_MCS8; break;
5990 case DESC92S_RATEMCS9: ret_rate = MGN_MCS9; break;
5991 case DESC92S_RATEMCS10: ret_rate = MGN_MCS10; break;
5992 case DESC92S_RATEMCS11: ret_rate = MGN_MCS11; break;
5993 case DESC92S_RATEMCS12: ret_rate = MGN_MCS12; break;
5994 case DESC92S_RATEMCS13: ret_rate = MGN_MCS13; break;
5995 case DESC92S_RATEMCS14: ret_rate = MGN_MCS14; break;
5996 case DESC92S_RATEMCS15: ret_rate = MGN_MCS15; break;
5997 case DESC92S_RATEMCS32: ret_rate = (0x80|0x20); break;
6000 RT_TRACE(COMP_RECV, "HwRateToMRate92S(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT );
6011 case DESC92S_RATE1M: ret_rate = MGN_1M; break;
6012 case DESC92S_RATE2M: ret_rate = MGN_2M; break;
6013 case DESC92S_RATE5_5M: ret_rate = MGN_5_5M; break;
6014 case DESC92S_RATE11M: ret_rate = MGN_11M; break;
6015 case DESC92S_RATE6M: ret_rate = MGN_6M; break;
6016 case DESC92S_RATE9M: ret_rate = MGN_9M; break;
6017 case DESC92S_RATE12M: ret_rate = MGN_12M; break;
6018 case DESC92S_RATE18M: ret_rate = MGN_18M; break;
6019 case DESC92S_RATE24M: ret_rate = MGN_24M; break;
6020 case DESC92S_RATE36M: ret_rate = MGN_36M; break;
6021 case DESC92S_RATE48M: ret_rate = MGN_48M; break;
6022 case DESC92S_RATE54M: ret_rate = MGN_54M; break;
6023 case DESC92S_RATEMCS0: ret_rate = MGN_MCS0; break;
6024 case DESC92S_RATEMCS1: ret_rate = MGN_MCS1; break;
6025 case DESC92S_RATEMCS2: ret_rate = MGN_MCS2; break;
6026 case DESC92S_RATEMCS3: ret_rate = MGN_MCS3; break;
6027 case DESC92S_RATEMCS4: ret_rate = MGN_MCS4; break;
6028 case DESC92S_RATEMCS5: ret_rate = MGN_MCS5; break;
6029 case DESC92S_RATEMCS6: ret_rate = MGN_MCS6; break;
6030 case DESC92S_RATEMCS7: ret_rate = MGN_MCS7; break;
6031 case DESC92S_RATEMCS8: ret_rate = MGN_MCS8; break;
6032 case DESC92S_RATEMCS9: ret_rate = MGN_MCS9; break;
6033 case DESC92S_RATEMCS10: ret_rate = MGN_MCS10; break;
6034 case DESC92S_RATEMCS11: ret_rate = MGN_MCS11; break;
6035 case DESC92S_RATEMCS12: ret_rate = MGN_MCS12; break;
6036 case DESC92S_RATEMCS13: ret_rate = MGN_MCS13; break;
6037 case DESC92S_RATEMCS14: ret_rate = MGN_MCS14; break;
6038 case DESC92S_RATEMCS15: ret_rate = MGN_MCS15; break;
6039 case DESC92S_RATEMCS32: ret_rate = (0x80|0x20); break;
6042 RT_TRACE(COMP_RECV, "HwRateToMRate92S(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT );
6049 u8 HwRateToMRate90(bool bIsHT, u8 rate)
6055 case DESC90_RATE1M: ret_rate = MGN_1M; break;
6056 case DESC90_RATE2M: ret_rate = MGN_2M; break;
6057 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
6058 case DESC90_RATE11M: ret_rate = MGN_11M; break;
6059 case DESC90_RATE6M: ret_rate = MGN_6M; break;
6060 case DESC90_RATE9M: ret_rate = MGN_9M; break;
6061 case DESC90_RATE12M: ret_rate = MGN_12M; break;
6062 case DESC90_RATE18M: ret_rate = MGN_18M; break;
6063 case DESC90_RATE24M: ret_rate = MGN_24M; break;
6064 case DESC90_RATE36M: ret_rate = MGN_36M; break;
6065 case DESC90_RATE48M: ret_rate = MGN_48M; break;
6066 case DESC90_RATE54M: ret_rate = MGN_54M; break;
6070 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
6076 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
6077 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
6078 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
6079 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
6080 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
6081 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
6082 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
6083 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
6084 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
6085 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
6086 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
6087 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
6088 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
6089 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
6090 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
6091 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
6092 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
6096 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
6105 * Function: UpdateRxPktTimeStamp
6106 * Overview: Recored down the TSF time stamp when receiving a packet
6114 * (pRfd->Status.TimeStampHigh is updated)
6115 * (pRfd->Status.TimeStampLow is updated)
6119 void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
6121 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6123 if(stats->bIsAMPDU && !stats->bFirstMPDU) {
6124 stats->mac_time[0] = priv->LastRxDescTSFLow;
6125 stats->mac_time[1] = priv->LastRxDescTSFHigh;
6127 priv->LastRxDescTSFLow = stats->mac_time[0];
6128 priv->LastRxDescTSFHigh = stats->mac_time[1];
6134 long rtl819x_translate_todbm(u8 signal_strength_index )// 0-100 index.
6136 long signal_power; // in dBm.
6138 // Translate to dBm (x=0.5y-95).
6139 signal_power = (long)((signal_strength_index + 1) >> 1);
6142 return signal_power;
6146 /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to
6147 be a local static. Otherwise, it may increase when we return from S3/S4. The
6148 value will be kept in memory or disk. We must delcare the value in adapter
6149 and it will be reinitialized when return from S3/S4. */
6150 void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
6152 bool bcheck = false;
6154 u32 nspatial_stream, tmp_val;
6156 static u32 slide_rssi_index=0, slide_rssi_statistics=0;
6157 static u32 slide_evm_index=0, slide_evm_statistics=0;
6158 static u32 last_rssi=0, last_evm=0;
6160 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
6161 static u32 last_beacon_adc_pwdb=0;
6163 struct ieee80211_hdr_3addr *hdr;
6165 unsigned int frag,seq;
6166 hdr = (struct ieee80211_hdr_3addr *)buffer;
6167 sc = le16_to_cpu(hdr->seq_ctl);
6168 frag = WLAN_GET_SEQ_FRAG(sc);
6169 seq = WLAN_GET_SEQ_SEQ(sc);
6170 //cosa add 04292008 to record the sequence number
6171 pcurrent_stats->Seq_Num = seq;
6173 // Check whether we should take the previous packet into accounting
6175 if(!pprevious_stats->bIsAMPDU)
6177 // if previous packet is not aggregated packet
6184 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
6186 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
6187 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
6188 priv->stats.slide_rssi_total -= last_rssi;
6190 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
6192 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
6193 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
6194 slide_rssi_index = 0;
6196 // <1> Showed on UI for user, in dbm
6197 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
6198 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
6199 pcurrent_stats->rssi = priv->stats.signal_strength;
6201 // If the previous packet does not match the criteria, neglect it
6203 if(!pprevious_stats->bPacketMatchBSSID)
6205 if(!pprevious_stats->bToSelfBA)
6213 //rtl8190_process_cck_rxpathsel(priv,pprevious_stats);//only rtl8190 supported
6218 priv->stats.num_process_phyinfo++;
6220 /* record the general signal strength to the sliding window. */
6223 // <2> Showed on UI for engineering
6224 // hardware does not provide rssi information for each rf path in CCK
6225 if(!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA))
6227 for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++)
6229 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
6232 //Fixed by Jacken 2008-03-20
6233 if(priv->stats.rx_rssi_percentage[rfpath] == 0)
6235 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
6236 //DbgPrint("MIMO RSSI initialize \n");
6238 if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath])
6240 priv->stats.rx_rssi_percentage[rfpath] =
6241 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
6242 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
6243 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
6247 priv->stats.rx_rssi_percentage[rfpath] =
6248 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
6249 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
6251 RT_TRACE(COMP_DBG,"priv->stats.rx_rssi_percentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
6259 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
6260 pprevious_stats->bIsCCK? "CCK": "OFDM",
6261 pprevious_stats->RxPWDBAll);
6263 if(pprevious_stats->bPacketBeacon)
6265 /* record the beacon pwdb to the sliding window. */
6266 if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
6268 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
6269 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
6270 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
6271 //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n",
6272 // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
6274 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
6275 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
6276 //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll);
6277 slide_beacon_adc_pwdb_index++;
6278 if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
6279 slide_beacon_adc_pwdb_index = 0;
6280 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
6281 if(pprevious_stats->RxPWDBAll >= 3)
6282 pprevious_stats->RxPWDBAll -= 3;
6285 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
6286 pprevious_stats->bIsCCK? "CCK": "OFDM",
6287 pprevious_stats->RxPWDBAll);
6290 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
6292 if(priv->undecorated_smoothed_pwdb < 0) // initialize
6294 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
6295 //DbgPrint("First pwdb initialize \n");
6298 if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
6300 priv->undecorated_smoothed_pwdb =
6301 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
6302 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
6303 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
6307 priv->undecorated_smoothed_pwdb =
6308 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
6309 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
6312 //Fixed by Jacken 2008-03-20
6313 if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB)
6315 pHalData->UndecoratedSmoothedPWDB =
6316 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
6317 pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1;
6321 pHalData->UndecoratedSmoothedPWDB =
6322 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
6331 /* record the general EVM to the sliding window. */
6332 if(pprevious_stats->SignalQuality == 0)
6337 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
6338 if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
6339 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
6340 last_evm = priv->stats.slide_evm[slide_evm_index];
6341 priv->stats.slide_evm_total -= last_evm;
6344 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
6346 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
6347 if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
6348 slide_evm_index = 0;
6350 // <1> Showed on UI for user, in percentage.
6351 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
6352 priv->stats.signal_quality = tmp_val;
6353 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
6354 priv->stats.last_signal_strength_inpercent = tmp_val;
6357 // <2> Showed on UI for engineering
6358 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
6360 for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
6362 if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
6364 if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
6366 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
6368 priv->stats.rx_evm_percentage[nspatial_stream] =
6369 ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
6370 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
6379 /*-----------------------------------------------------------------------------
6380 * Function: rtl819x_query_rxpwrpercentage()
6384 * Input: char antpower
6388 * Return: 0-100 percentage
6392 * 05/26/2008 amy Create Version 0 porting from windows code.
6394 *---------------------------------------------------------------------------*/
6395 static u8 rtl819x_query_rxpwrpercentage(
6399 if ((antpower <= -100) || (antpower >= 20))
6403 else if (antpower >= 0)
6409 return (100+antpower);
6412 } /* QueryRxPwrPercentage */
6415 rtl819x_evm_dbtopercentage(
6427 ret_val = 0 - ret_val;
6435 // We want good-looking for signal strength/quality
6436 // 2007/7/19 01:09, by cosa.
6439 rtl819x_signal_scale_mapping(
6445 // Step 1. Scale mapping.
6446 if(currsig >= 61 && currsig <= 100)
6448 retsig = 90 + ((currsig - 60) / 4);
6450 else if(currsig >= 41 && currsig <= 60)
6452 retsig = 78 + ((currsig - 40) / 2);
6454 else if(currsig >= 31 && currsig <= 40)
6456 retsig = 66 + (currsig - 30);
6458 else if(currsig >= 21 && currsig <= 30)
6460 retsig = 54 + (currsig - 20);
6462 else if(currsig >= 5 && currsig <= 20)
6464 retsig = 42 + (((currsig - 5) * 2) / 3);
6466 else if(currsig == 4)
6470 else if(currsig == 3)
6474 else if(currsig == 2)
6478 else if(currsig == 1)
6490 /*-----------------------------------------------------------------------------
6491 * Function: QueryRxPhyStatus8192S()
6503 * 06/01/2007 MHC Create Version 0.
6504 * 06/05/2007 MHC Accordign to HW's new data sheet, we add CCK and OFDM
6505 * descriptor definition.
6506 * 07/04/2007 MHC According to Jerry and Bryant's document. We read
6507 * ir_isolation and ext_lna for RF's init value and use
6508 * to compensate RSSI after receiving packets.
6509 * 09/10/2008 MHC Modify name and PHY status field for 92SE.
6510 * 09/19/2008 MHC Add CCK/OFDM SS/SQ for 92S series.
6512 *---------------------------------------------------------------------------*/
6513 static void rtl8192SU_query_rxphystatus(
6514 struct r8192_priv * priv,
6515 struct ieee80211_rx_stats * pstats,
6516 rx_desc_819x_usb *pDesc,
6517 rx_drvinfo_819x_usb * pdrvinfo,
6518 struct ieee80211_rx_stats * precord_stats,
6519 bool bpacket_match_bssid,
6520 bool bpacket_toself,
6525 //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status);
6526 //PHY_STS_CCK_8192S_T *pCck_buf;
6527 phy_sts_cck_819xusb_t * pcck_buf;
6528 phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
6530 //u8 i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
6531 u8 i, max_spatial_stream, rxsc_sgien_exflg;
6532 char rx_pwr[4], rx_pwr_all=0;
6533 //long rx_avg_pwr = 0;
6534 //char rx_snrX, rx_evmX;
6536 u32 RSSI, total_rssi=0;//, total_evm=0;
6537 // long signal_strength_index = 0;
6543 priv->stats.numqry_phystatus++;
6545 is_cck_rate = rx_hal_is_cck_rate(pDesc);
6547 // Record it for next packet processing
6548 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
6549 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
6550 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
6551 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
6552 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
6553 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
6556 pstats->RxMIMOSignalQuality[0] = -1;
6557 pstats->RxMIMOSignalQuality[1] = -1;
6558 precord_stats->RxMIMOSignalQuality[0] = -1;
6559 precord_stats->RxMIMOSignalQuality[1] = -1;
6563 u8 report;//, tmp_pwdb;
6564 //char cck_adc_pwdb[4];
6566 // CCK Driver info Structure is not the same as OFDM packet.
6567 pcck_buf = (phy_sts_cck_819xusb_t *)pdrvinfo;
6570 // (1)Hardware does not provide RSSI for CCK
6574 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
6577 priv->stats.numqry_phystatusCCK++;
6579 if(!priv->bCckHighPower)
6581 report = pcck_buf->cck_agc_rpt & 0xc0;
6585 //Fixed by Jacken from Bryant 2008-03-20
6586 //Original value is -38 , -26 , -14 , -2
6587 //Fixed value is -35 , -23 , -11 , 6
6589 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
6592 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
6595 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
6598 rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e);//6->8
6604 report = pdrvinfo->cfosho[0] & 0x60;
6609 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
6612 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
6615 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
6618 rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;//6->-8
6623 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);//check it
6624 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
6625 //pstats->RecvSignalPower = pwdb_all;
6626 pstats->RecvSignalPower = rx_pwr_all;
6629 // (3) Get Signal Quality (EVM)
6631 //if(bpacket_match_bssid)
6635 if(pstats->RxPWDBAll > 40)
6640 sq = pcck_buf->sq_rpt;
6642 if(pcck_buf->sq_rpt > 64)
6644 else if (pcck_buf->sq_rpt < 20)
6647 sq = ((64-sq) * 100) / 44;
6649 pstats->SignalQuality = precord_stats->SignalQuality = sq;
6650 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
6651 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
6656 priv->stats.numqry_phystatusHT++;
6658 // 2008/09/19 MH For 92S debug, RX RF path always enable!!
6659 priv->brfpath_rxenable[0] = priv->brfpath_rxenable[1] = TRUE;
6662 // (1)Get RSSI for HT rate
6664 //for(i=RF90_PATH_A; i<priv->NumTotalRFPath; i++)
6665 for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++)
6667 // 2008/01/30 MH we will judge RF RX path now.
6668 if (priv->brfpath_rxenable[i])
6673 //if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
6676 //Fixed by Jacken from Bryant 2008-03-20
6677 //Original value is 106
6678 //rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
6679 rx_pwr[i] = ((pdrvinfo->gain_trsw[i]&0x3F)*2) - 110;
6681 /* Translate DBM to percentage. */
6682 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]); //check ok
6684 RT_TRACE(COMP_RF, "RF-%d RXPWR=%x RSSI=%d\n", i, rx_pwr[i], RSSI);
6686 //Get Rx snr value in DB
6687 //tmp_rxsnr = pofdm_buf->rxsnr_X[i];
6688 //rx_snrX = (char)(tmp_rxsnr);
6690 //priv->stats.rxSNRdB[i] = (long)rx_snrX;
6691 priv->stats.rxSNRdB[i] = (long)(pdrvinfo->rxsnr[i]/2);
6693 /* Translate DBM to percentage. */
6694 //RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
6695 //total_rssi += RSSI;
6697 /* Record Signal Strength for next packet */
6698 //if(bpacket_match_bssid)
6700 pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
6701 precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
6707 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
6709 //Fixed by Jacken from Bryant 2008-03-20
6710 //Original value is 106
6711 //rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
6712 rx_pwr_all = (((pdrvinfo->pwdb_all ) >> 1 )& 0x7f) -106;
6713 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
6715 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
6716 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
6717 pstats->RecvSignalPower = rx_pwr_all;
6720 // (3)EVM of HT rate
6722 //if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
6723 // pdrvinfo->RxRate<=DESC90_RATEMCS15)
6724 if(pDesc->RxHT && pDesc->RxMCS>=DESC92S_RATEMCS8 &&
6725 pDesc->RxMCS<=DESC92S_RATEMCS15)
6726 max_spatial_stream = 2; //both spatial stream make sense
6728 max_spatial_stream = 1; //only spatial stream 1 makes sense
6730 for(i=0; i<max_spatial_stream; i++)
6732 //tmp_rxevm = pofdm_buf->rxevm_X[i];
6733 //rx_evmX = (char)(tmp_rxevm);
6735 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
6736 // fill most significant bit to "zero" when doing shifting operation which may change a negative
6737 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
6738 //rx_evmX /= 2; //dbm
6740 //evm = rtl819x_evm_dbtopercentage(rx_evmX);
6741 evm = rtl819x_evm_dbtopercentage( (pdrvinfo->rxevm[i] /*/ 2*/)); //dbm
6742 RT_TRACE(COMP_RF, "RXRATE=%x RXEVM=%x EVM=%s%d\n", pDesc->RxMCS, pdrvinfo->rxevm[i], "%", evm);
6744 //if(bpacket_match_bssid)
6746 if(i==0) // Fill value in RFD, Get the first spatial stream only
6747 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
6748 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
6753 /* record rx statistics for debug */
6754 //rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
6755 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
6756 //if(pdrvinfo->BW) //40M channel
6757 if(pDesc->BW) //40M channel
6758 priv->stats.received_bwtype[1+pdrvinfo->rxsc]++;
6760 priv->stats.received_bwtype[0]++;
6763 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
6764 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
6767 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;//check ok
6772 //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u8)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u8)(total_rssi/=RF90_PATH_MAX);
6773 // We can judge RX path number now.
6775 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
6777 }/* QueryRxPhyStatus8192S */
6780 rtl8192_record_rxdesc_forlateruse(
6781 struct ieee80211_rx_stats * psrc_stats,
6782 struct ieee80211_rx_stats * ptarget_stats
6785 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
6786 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
6787 ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
6790 static void rtl8192SU_query_rxphystatus(
6791 struct r8192_priv * priv,
6792 struct ieee80211_rx_stats * pstats,
6793 rx_desc_819x_usb *pDesc,
6794 rx_drvinfo_819x_usb * pdrvinfo,
6795 struct ieee80211_rx_stats * precord_stats,
6796 bool bpacket_match_bssid,
6797 bool bpacket_toself,
6801 void rtl8192SU_TranslateRxSignalStuff(struct sk_buff *skb,
6802 struct ieee80211_rx_stats * pstats,
6803 rx_desc_819x_usb *pDesc,
6804 rx_drvinfo_819x_usb *pdrvinfo)
6806 // TODO: We must only check packet for current MAC address. Not finish
6807 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6808 struct net_device *dev=info->dev;
6809 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6810 bool bpacket_match_bssid, bpacket_toself;
6811 bool bPacketBeacon=FALSE, bToSelfBA=FALSE;
6812 static struct ieee80211_rx_stats previous_stats;
6813 struct ieee80211_hdr_3addr *hdr;//by amy
6816 // Get Signal Quality for only RX data queue (but not command queue)
6819 //u16 tmp_buf_len = 0;
6822 /* Get MAC frame start address. */
6823 tmp_buf = (u8*)skb->data;// + get_rxpacket_shiftbytes_819xusb(pstats);
6825 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
6826 fc = le16_to_cpu(hdr->frame_ctl);
6827 type = WLAN_FC_GET_TYPE(fc);
6828 praddr = hdr->addr1;
6830 /* Check if the received packet is acceptabe. */
6831 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
6832 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
6833 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
6834 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
6837 if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
6839 bPacketBeacon = true;
6840 //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6842 if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
6844 if((eqMacAddr(praddr,dev->dev_addr)))
6846 //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6852 if(bpacket_match_bssid)
6854 priv->stats.numpacket_matchbssid++;
6857 priv->stats.numpacket_toself++;
6860 // Process PHY information for previous packet (RSSI/PWDB/EVM)
6862 // Because phy information is contained in the last packet of AMPDU only, so driver
6863 // should process phy information of previous packet
6864 rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
6865 rtl8192SU_query_rxphystatus(priv, pstats, pDesc, pdrvinfo, &previous_stats, bpacket_match_bssid,bpacket_toself,bPacketBeacon,bToSelfBA);
6866 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
6871 * Function: UpdateReceivedRateHistogramStatistics
6872 * Overview: Recored down the received data rate
6875 * struct net_device *dev
6876 * struct ieee80211_rx_stats *stats
6880 * (priv->stats.ReceivedRateHistogram[] is updated)
6885 UpdateReceivedRateHistogramStatistics8190(
6886 struct net_device *dev,
6887 struct ieee80211_rx_stats *stats
6890 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6891 u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV
6893 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
6898 else if(stats->bICV)
6901 if(stats->bShortPreamble)
6902 preamble_guardinterval = 1;// short
6904 preamble_guardinterval = 0;// long
6911 case MGN_1M: rateIndex = 0; break;
6912 case MGN_2M: rateIndex = 1; break;
6913 case MGN_5_5M: rateIndex = 2; break;
6914 case MGN_11M: rateIndex = 3; break;
6918 case MGN_6M: rateIndex = 4; break;
6919 case MGN_9M: rateIndex = 5; break;
6920 case MGN_12M: rateIndex = 6; break;
6921 case MGN_18M: rateIndex = 7; break;
6922 case MGN_24M: rateIndex = 8; break;
6923 case MGN_36M: rateIndex = 9; break;
6924 case MGN_48M: rateIndex = 10; break;
6925 case MGN_54M: rateIndex = 11; break;
6927 // 11n High throughput rate
6929 case MGN_MCS0: rateIndex = 12; break;
6930 case MGN_MCS1: rateIndex = 13; break;
6931 case MGN_MCS2: rateIndex = 14; break;
6932 case MGN_MCS3: rateIndex = 15; break;
6933 case MGN_MCS4: rateIndex = 16; break;
6934 case MGN_MCS5: rateIndex = 17; break;
6935 case MGN_MCS6: rateIndex = 18; break;
6936 case MGN_MCS7: rateIndex = 19; break;
6937 case MGN_MCS8: rateIndex = 20; break;
6938 case MGN_MCS9: rateIndex = 21; break;
6939 case MGN_MCS10: rateIndex = 22; break;
6940 case MGN_MCS11: rateIndex = 23; break;
6941 case MGN_MCS12: rateIndex = 24; break;
6942 case MGN_MCS13: rateIndex = 25; break;
6943 case MGN_MCS14: rateIndex = 26; break;
6944 case MGN_MCS15: rateIndex = 27; break;
6945 default: rateIndex = 28; break;
6947 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
6948 priv->stats.received_rate_histogram[0][rateIndex]++; //total
6949 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
6952 void rtl8192SU_query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats, bool bIsRxAggrSubframe)
6954 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6955 struct net_device *dev=info->dev;
6956 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6957 //rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
6958 rx_drvinfo_819x_usb *driver_info = NULL;
6960 //PRT_RFD_STATUS pRtRfdStatus = &pRfd->Status;
6961 //PHAL_DATA_8192SUSB pHalData = GET_HAL_DATA(Adapter);
6962 //pu1Byte pDesc = (pu1Byte)pDescIn;
6963 //PRX_DRIVER_INFO_8192S pDrvInfo;
6965 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
6970 printk("========================");
6971 for(m=0; m<skb->len; m++){
6974 printk("%2x ",((u8*)skb->data)[m]);
6976 printk("\n========================\n");
6982 //Get Rx Descriptor Raw Information
6984 stats->Length = desc->Length ;
6985 stats->RxDrvInfoSize = desc->RxDrvInfoSize*RX_DRV_INFO_SIZE_UNIT;
6986 stats->RxBufShift = (desc->Shift)&0x03;
6987 stats->bICV = desc->ICV;
6988 stats->bCRC = desc->CRC32;
6989 stats->bHwError = stats->bCRC|stats->bICV;
6990 stats->Decrypted = !desc->SWDec;//RTL8190 set this bit to indicate that Hw does not decrypt packet
6991 stats->bIsAMPDU = (desc->AMSDU==1);
6992 stats->bFirstMPDU = (desc->PAGGR==1) && (desc->FAGGR==1);
6993 stats->bShortPreamble = desc->SPLCP;
6994 stats->RxIs40MHzPacket = (desc->BW==1);
6995 stats->TimeStampLow = desc->TSFL;
6997 if((desc->FAGGR==1) || (desc->PAGGR==1))
6999 RT_TRACE(COMP_RXDESC, "FirstAGGR = %d, PartAggr = %d\n", desc->FAGGR, desc->PAGGR);
7005 printk("%s: Receive ICV error!!!!!!!!!!!!!!!!!!!!!!\n", __FUNCTION__);
7007 printk("%s: Receive CRC error!!!!!!!!!!!!!!!!!!!!!!\n", __FUNCTION__);
7010 if(IS_UNDER_11N_AES_MODE(priv->ieee80211))
7012 // Always received ICV error packets in AES mode.
7013 // This fixed HW later MIC write bug.
7014 if(stats->bICV && !stats->bCRC)
7016 stats->bICV = FALSE;
7017 stats->bHwError = FALSE;
7021 // Transform HwRate to MRate
7022 if(!stats->bHwError)
7023 //stats->DataRate = HwRateToMRate(
7024 // (BOOLEAN)GET_RX_DESC_RXHT(pDesc),
7025 // (u1Byte)GET_RX_DESC_RXMCS(pDesc),
7026 // (BOOLEAN)GET_RX_DESC_PAGGR(pDesc));
7027 stats->rate = rtl8192SU_HwRateToMRate(desc->RxHT, desc->RxMCS, desc->PAGGR);
7029 stats->rate = MGN_1M;
7032 // Collect Rx rate/AMPDU/TSFL
7034 //UpdateRxdRateHistogramStatistics8192S(Adapter, pRfd);
7035 //UpdateRxAMPDUHistogramStatistics8192S(Adapter, pRfd);
7036 //UpdateRxPktTimeStamp8192S(Adapter, pRfd);
7037 UpdateReceivedRateHistogramStatistics8190(dev, stats);
7038 //UpdateRxAMPDUHistogramStatistics8192S(dev, stats); //FIXLZM
7039 UpdateRxPktTimeStamp8190(dev, stats);
7042 // Get PHY Status and RSVD parts.
7043 // <Roger_Notes> It only appears on last aggregated packet.
7045 if (desc->PHYStatus)
7047 //driver_info = (rx_drvinfo_819x_usb *)(skb->data + RX_DESC_SIZE + stats->RxBufShift);
7048 driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) + \
7053 printk("========================\n");
7054 printk("RX_DESC_SIZE:%d, RxBufShift:%d, RxDrvInfoSize:%d\n",
7055 RX_DESC_SIZE, stats->RxBufShift, stats->RxDrvInfoSize);
7056 for(m=0; m<32; m++){
7057 printk("%2x ",((u8*)driver_info)[m]);
7059 printk("\n========================\n");
7066 skb_pull(skb, sizeof(rx_desc_819x_usb));
7070 // Get Total offset of MPDU Frame Body
7072 if((stats->RxBufShift + stats->RxDrvInfoSize) > 0)
7076 skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
7081 // Get PHY Status and RSVD parts.
7082 // <Roger_Notes> It only appears on last aggregated packet.
7084 if (desc->PHYStatus)
7086 rtl8192SU_TranslateRxSignalStuff(skb, stats, desc, driver_info);
7092 // The strarting address of wireless lan header will shift 1 or 2 or 3 or "more" bytes for the following reason :
7093 // (1) QoS control : shift 2 bytes
7094 // (2) Mesh Network : shift 1 or 3 bytes
7095 // (3) RxDriverInfo occupies the front parts of Rx Packets buffer(shift units is in 8Bytes)
7097 // It is because Lextra CPU used by 8186 or 865x series assert exception if the statrting address
7098 // of IP header is not double word alignment.
7099 // This features is supported in 818xb and 8190 only, but not 818x.
7101 // parameter: PRT_RFD, Pointer of Reeceive frame descriptor which is initialized according to
7103 // return value: unsigned int, number of total shifted bytes
7105 // Notes: 2008/06/28, created by Roger
7107 u32 GetRxPacketShiftBytes8192SU(struct ieee80211_rx_stats *Status, bool bIsRxAggrSubframe)
7109 //PRT_RFD_STATUS pRtRfdStatus = &pRfd->Status;
7111 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize + Status->RxBufShift);
7114 void rtl8192SU_rx_nomal(struct sk_buff* skb)
7116 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
7117 struct net_device *dev=info->dev;
7118 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7119 struct ieee80211_rx_stats stats = {
7123 // .mac_time = jiffies,
7124 .freq = IEEE80211_24GHZ_BAND,
7127 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
7128 bool unicast_packet = false;
7130 //printk("**********skb->len = %d\n", skb->len);
7131 /* 20 is for ps-poll */
7132 if((skb->len >=(20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
7134 /* first packet should not contain Rx aggregation header */
7135 rtl8192SU_query_rxdesc_status(skb, &stats, false);
7138 /* hardware related info */
7139 priv->stats.rxoktotal++; //YJ,test,090108
7141 /* Process the MPDU recevied */
7142 skb_trim(skb, skb->len - 4/*sCrcLng*/);//FIXLZM
7144 rx_pkt_len = skb->len;
7145 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
7146 unicast_packet = false;
7147 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
7149 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
7152 /* unicast packet */
7153 unicast_packet = true;
7156 if(!ieee80211_rx(priv->ieee80211,skb, &stats)) {
7157 dev_kfree_skb_any(skb);
7159 // priv->stats.rxoktotal++; //YJ,test,090108
7160 if(unicast_packet) {
7161 priv->stats.rxbytesunicast += rx_pkt_len;
7165 //up is firs pkt, follow is next and next
7169 priv->stats.rxurberr++;
7170 printk("actual_length:%d\n", skb->len);
7171 dev_kfree_skb_any(skb);
7177 rtl819xusb_process_received_packet(
7178 struct net_device *dev,
7179 struct ieee80211_rx_stats *pstats
7182 // bool bfreerfd=false, bqueued=false;
7185 struct r8192_priv *priv = ieee80211_priv(dev);
7189 //PRX_TS_RECORD pts = NULL;
7191 // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
7192 //porting by amy 080508
7193 pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
7194 frame = pstats->virtual_address;
7195 frame_len = pstats->packetlength;
7196 #ifdef TODO // by amy about HCT
7197 if(!Adapter->bInHctTest)
7198 CountRxErrStatistics(Adapter, pRfd);
7201 #ifdef ENABLE_PS //by amy for adding ps function in future
7202 RT_RF_POWER_STATE rtState;
7203 // When RF is off, we should not count the packet for hw/sw synchronize
7204 // reason, ie. there may be a duration while sw switch is changed and hw
7205 // switch is being changed. 2006.12.04, by shien chang.
7206 Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8* )(&rtState));
7207 if (rtState == eRfOff)
7212 priv->stats.rxframgment++;
7216 RmMonitorSignalStrength(Adapter, pRfd);
7218 /* 2007/01/16 MH Add RX command packet handle here. */
7219 /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
7220 if (rtl819xusb_rx_command_packet(dev, pstats))
7232 void query_rx_cmdpkt_desc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats)
7234 // rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
7235 // struct net_device *dev=info->dev;
7236 // struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7237 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
7238 // rx_drvinfo_819x_usb *driver_info;
7241 //Get Rx Descriptor Information
7243 stats->virtual_address = (u8*)skb->data;
7244 stats->Length = desc->Length;
7245 stats->RxDrvInfoSize = 0;
7246 stats->RxBufShift = 0;
7247 stats->packetlength = stats->Length-scrclng;
7248 stats->fraglength = stats->packetlength;
7249 stats->fragoffset = 0;
7250 stats->ntotalfrag = 1;
7253 void rtl8192SU_rx_cmd(struct sk_buff *skb)
7255 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
7256 struct net_device *dev = info->dev;
7259 struct ieee80211_rx_stats stats = {
7263 // .mac_time = jiffies,
7264 .freq = IEEE80211_24GHZ_BAND,
7268 // Check buffer length to determine if this is a valid MPDU.
7270 if( (skb->len >= sizeof(rx_desc_819x_usb)) && (skb->len <= RX_URB_SIZE) )//&&
7271 //(pHalData->SwChnlInProgress == FALSE))
7274 // Collection information in Rx descriptor.
7276 query_rx_cmdpkt_desc_status(skb,&stats);
7277 // this is to be done by amy 080508 prfd->queue_id = 1;
7280 // Process the MPDU recevied.
7282 rtl819xusb_process_received_packet(dev,&stats);
7284 dev_kfree_skb_any(skb);
7288 //RTInsertTailListWithCnt(&pAdapter->RfdIdleQueue, &pRfd->List, &pAdapter->NumIdleRfd);
7289 //RT_ASSERT(pAdapter->NumIdleRfd <= pAdapter->NumRfd, ("HalUsbInCommandComplete8192SUsb(): Adapter->NumIdleRfd(%d)\n", pAdapter->NumIdleRfd));
7290 //RT_TRACE(COMP_RECV, DBG_LOUD, ("HalUsbInCommandComplete8192SUsb(): NOT enough Resources!! BufLenUsed(%d), NumIdleRfd(%d)\n",
7291 //pContext->BufLenUsed, pAdapter->NumIdleRfd));
7295 // Reuse USB_IN_CONTEXT since we had finished processing the
7296 // buffer in USB_IN_CONTEXT.
7298 //HalUsbReturnInContext(pAdapter, pContext);
7301 // Issue another bulk IN transfer.
7303 //HalUsbInMpdu(pAdapter, PipeIndex);
7305 RT_TRACE(COMP_RECV, "<--- HalUsbInCommandComplete8192SUsb()\n");
7309 void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
7311 struct sk_buff *skb;
7312 struct rtl8192_rx_info *info;
7314 while (NULL != (skb = skb_dequeue(&priv->skb_queue))) {
7315 info = (struct rtl8192_rx_info *)skb->cb;
7316 switch (info->out_pipe) {
7317 /* Nomal packet pipe */
7319 //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe);
7320 priv->IrpPendingCount--;
7321 priv->ops->rtl819x_rx_nomal(skb);
7324 /* Command packet pipe */
7326 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\
7328 priv->ops->rtl819x_rx_cmd(skb);
7331 default: /* should never get here! */
7332 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\
7343 /****************************************************************************
7344 ---------------------------- USB_STUFF---------------------------
7345 *****************************************************************************/
7346 //LZM Merge from windows HalUsbSetQueuePipeMapping8192SUsb 090319
7347 static void HalUsbSetQueuePipeMapping8192SUsb(struct usb_interface *intf, struct net_device *dev)
7349 struct r8192_priv *priv = ieee80211_priv(dev);
7350 struct usb_host_interface *iface_desc;
7351 struct usb_endpoint_descriptor *endpoint;
7354 priv->ep_in_num = 0;
7355 priv->ep_out_num = 0;
7356 memset(priv->RtOutPipes,0,16);
7357 memset(priv->RtInPipes,0,16);
7359 iface_desc = intf->cur_altsetting;
7360 priv->ep_num = iface_desc->desc.bNumEndpoints;
7362 for (i = 0; i < priv->ep_num; ++i) {
7363 endpoint = &iface_desc->endpoint[i].desc;
7364 if (usb_endpoint_is_bulk_in(endpoint)) {
7365 priv->RtInPipes[priv->ep_in_num] = usb_endpoint_num(endpoint);
7367 //printk("in_endpoint_idx = %d\n", usb_endpoint_num(endpoint));
7368 } else if (usb_endpoint_is_bulk_out(endpoint)) {
7369 priv->RtOutPipes[priv->ep_out_num] = usb_endpoint_num(endpoint);
7370 priv->ep_out_num ++;
7371 //printk("out_endpoint_idx = %d\n", usb_endpoint_num(endpoint));
7375 memset(priv->txqueue_to_outpipemap,0,9);
7376 if (priv->ep_num == 6) {
7377 // BK, BE, VI, VO, HCCA, TXCMD, MGNT, HIGH, BEACON
7378 u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 4, 4, 4};
7380 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
7381 } else if (priv->ep_num == 4) {
7382 // BK, BE, VI, VO, HCCA, TXCMD, MGNT, HIGH, BEACON
7383 u8 queuetopipe[] = {1, 1, 0, 0, 2, 2, 2, 2, 2};
7385 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
7386 } else if (priv->ep_num > 9) {
7387 // BK, BE, VI, VO, HCCA, TXCMD, MGNT, HIGH, BEACON
7388 u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
7390 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
7391 } else {//use sigle pipe
7392 // BK, BE, VI, VO, HCCA, TXCMD, MGNT, HIGH, BEACON
7393 u8 queuetopipe[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7394 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
7397 printk("==>ep_num:%d, in_ep_num:%d, out_ep_num:%d\n", priv->ep_num, priv->ep_in_num, priv->ep_out_num);
7399 printk("==>RtInPipes:");
7400 for(i=0; i < priv->ep_in_num; i++)
7401 printk("%d ", priv->RtInPipes[i]);
7404 printk("==>RtOutPipes:");
7405 for(i=0; i < priv->ep_out_num; i++)
7406 printk("%d ", priv->RtOutPipes[i]);
7409 printk("==>txqueue_to_outpipemap for BK, BE, VI, VO, HCCA, TXCMD, MGNT, HIGH, BEACON:\n");
7410 for(i=0; i < 9; i++)
7411 printk("%d ", priv->txqueue_to_outpipemap[i]);
7417 static const struct net_device_ops rtl8192_netdev_ops = {
7418 .ndo_open = rtl8192_open,
7419 .ndo_stop = rtl8192_close,
7420 .ndo_get_stats = rtl8192_stats,
7421 .ndo_tx_timeout = tx_timeout,
7422 .ndo_do_ioctl = rtl8192_ioctl,
7423 .ndo_set_multicast_list = r8192_set_multicast,
7424 .ndo_set_mac_address = r8192_set_mac_adr,
7425 .ndo_validate_addr = eth_validate_addr,
7426 .ndo_change_mtu = eth_change_mtu,
7427 .ndo_start_xmit = rtl8192_ieee80211_xmit,
7430 static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
7431 const struct usb_device_id *id)
7433 // unsigned long ioaddr = 0;
7434 struct net_device *dev = NULL;
7435 struct r8192_priv *priv= NULL;
7436 struct usb_device *udev = interface_to_usbdev(intf);
7438 RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
7440 dev = alloc_ieee80211(sizeof(struct r8192_priv));
7442 usb_set_intfdata(intf, dev);
7443 SET_NETDEV_DEV(dev, &intf->dev);
7444 priv = ieee80211_priv(dev);
7445 priv->ieee80211 = netdev_priv(dev);
7448 HalUsbSetQueuePipeMapping8192SUsb(intf, dev);
7450 //printk("===============>NIC 8192SU\n");
7451 priv->ops = &rtl8192su_ops;
7453 dev->netdev_ops = &rtl8192_netdev_ops;
7455 //DMESG("Oops: i'm coming\n");
7456 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
7458 dev->type=ARPHRD_ETHER;
7460 dev->watchdog_timeo = HZ*3; //modified by john, 0805
7462 if (dev_alloc_name(dev, ifname) < 0){
7463 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
7465 dev_alloc_name(dev, ifname);
7468 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
7470 if(rtl8192_init(dev)!=0){
7471 RT_TRACE(COMP_ERR, "Initialization failed");
7475 netif_carrier_off(dev);
7476 netif_stop_queue(dev);
7478 register_netdev(dev);
7479 RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
7480 rtl8192_proc_init_one(dev);
7483 RT_TRACE(COMP_INIT, "Driver probe completed\n");
7486 free_ieee80211(dev);
7488 RT_TRACE(COMP_ERR, "wlan driver load failed\n");
7492 //detach all the work and timer structure declared or inititialize in r8192U_init function.
7493 void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
7495 cancel_work_sync(&priv->reset_wq);
7496 cancel_work_sync(&priv->qos_activate);
7497 cancel_delayed_work(&priv->watch_dog_wq);
7498 cancel_delayed_work(&priv->update_beacon_wq);
7499 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
7500 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
7501 //cancel_work_sync(&priv->SetBWModeWorkItem);
7502 //cancel_work_sync(&priv->SwChnlWorkItem);
7505 static void __devexit rtl8192_usb_disconnect(struct usb_interface *intf)
7507 struct net_device *dev = usb_get_intfdata(intf);
7508 struct r8192_priv *priv = ieee80211_priv(dev);
7511 unregister_netdev(dev);
7513 RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
7514 rtl8192_proc_remove_one(dev);
7517 if (priv->pFirmware)
7519 vfree(priv->pFirmware);
7520 priv->pFirmware = NULL;
7522 // priv->rf_close(dev);
7523 // rtl8192_SetRFPowerState(dev, eRfOff);
7524 destroy_workqueue(priv->priv_wq);
7525 //rtl8192_irq_disable(dev);
7526 //rtl8192_reset(dev);
7530 free_ieee80211(dev);
7531 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
7534 /* fun with the built-in ieee80211 stack... */
7535 extern int ieee80211_debug_init(void);
7536 extern void ieee80211_debug_exit(void);
7537 extern int ieee80211_crypto_init(void);
7538 extern void ieee80211_crypto_deinit(void);
7539 extern int ieee80211_crypto_tkip_init(void);
7540 extern void ieee80211_crypto_tkip_exit(void);
7541 extern int ieee80211_crypto_ccmp_init(void);
7542 extern void ieee80211_crypto_ccmp_exit(void);
7543 extern int ieee80211_crypto_wep_init(void);
7544 extern void ieee80211_crypto_wep_exit(void);
7546 static int __init rtl8192_usb_module_init(void)
7550 #ifdef CONFIG_IEEE80211_DEBUG
7551 ret = ieee80211_debug_init();
7553 printk(KERN_ERR "ieee80211_debug_init() failed %d\n", ret);
7557 ret = ieee80211_crypto_init();
7559 printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
7563 ret = ieee80211_crypto_tkip_init();
7565 printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n",
7570 ret = ieee80211_crypto_ccmp_init();
7572 printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n",
7577 ret = ieee80211_crypto_wep_init();
7579 printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
7583 printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
7584 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
7585 RT_TRACE(COMP_INIT, "Initializing module");
7586 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
7587 rtl8192_proc_module_init();
7588 return usb_register(&rtl8192_usb_driver);
7592 static void __exit rtl8192_usb_module_exit(void)
7594 usb_deregister(&rtl8192_usb_driver);
7596 RT_TRACE(COMP_DOWN, "Exiting");
7597 rtl8192_proc_module_remove();
7599 ieee80211_crypto_tkip_exit();
7600 ieee80211_crypto_ccmp_exit();
7601 ieee80211_crypto_wep_exit();
7602 ieee80211_crypto_deinit();
7603 #ifdef CONFIG_IEEE80211_DEBUG
7604 ieee80211_debug_exit();
7609 void rtl8192_try_wake_queue(struct net_device *dev, int pri)
7611 unsigned long flags;
7613 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7615 spin_lock_irqsave(&priv->tx_lock,flags);
7616 enough_desc = check_nic_enough_desc(dev,pri);
7617 spin_unlock_irqrestore(&priv->tx_lock,flags);
7620 ieee80211_wake_queue(priv->ieee80211);
7623 void EnableHWSecurityConfig8192(struct net_device *dev)
7625 u8 SECR_value = 0x0;
7626 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7627 struct ieee80211_device* ieee = priv->ieee80211;
7629 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
7631 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
7633 SECR_value |= SCR_RxUseDK;
7634 SECR_value |= SCR_TxUseDK;
7636 else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
7638 SECR_value |= SCR_RxUseDK;
7639 SECR_value |= SCR_TxUseDK;
7642 //add HWSec active enable here.
7643 //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
7645 ieee->hwsec_active = 1;
7647 if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep)//!ieee->hwsec_support) //add hwsec_support flag to totol control hw_sec on/off
7649 ieee->hwsec_active = 0;
7650 SECR_value &= ~SCR_RxDecEnable;
7653 RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, \
7654 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
7656 write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK );
7661 void setKey( struct net_device *dev,
7669 u32 TargetCommand = 0;
7670 u32 TargetContent = 0;
7673 if (EntryNo >= TOTAL_CAM_ENTRY)
7674 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
7676 RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr"MAC_FMT"\n", dev,EntryNo, KeyIndex, KeyType, MAC_ARG(MacAddr));
7679 usConfig |= BIT15 | (KeyType<<2);
7681 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
7682 // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
7685 for(i=0 ; i<CAM_CONTENT_COUNT; i++){
7686 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
7687 TargetCommand |= BIT31|BIT16;
7689 if(i==0){//MAC|Config
7690 TargetContent = (u32)(*(MacAddr+0)) << 16|
7691 (u32)(*(MacAddr+1)) << 24|
7694 write_nic_dword(dev, WCAMI, TargetContent);
7695 write_nic_dword(dev, RWCAM, TargetCommand);
7696 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
7699 TargetContent = (u32)(*(MacAddr+2)) |
7700 (u32)(*(MacAddr+3)) << 8|
7701 (u32)(*(MacAddr+4)) << 16|
7702 (u32)(*(MacAddr+5)) << 24;
7703 write_nic_dword(dev, WCAMI, TargetContent);
7704 write_nic_dword(dev, RWCAM, TargetCommand);
7708 if(KeyContent !=NULL){
7709 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
7710 write_nic_dword(dev, RWCAM, TargetCommand);
7717 /***************************************************************************
7718 ------------------- module init / exit stubs ----------------
7719 ****************************************************************************/
7720 module_init(rtl8192_usb_module_init);
7721 module_exit(rtl8192_usb_module_exit);